@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
78 lines • 3.5 kB
JavaScript
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import { jsonlBytesByCreatedAt, jsonBytes } from "../render/json.js";
import { enoent } from "../../errors/fs.js";
import { makeRead } from "../hierarchy/read.js";
import { getBoard, getCard, listBoardLabels, listBoardLists, listBoardMembers, listCardComments, listWorkspaces, } from "./client.js";
import { normalizeBoard, normalizeCard, normalizeComment, normalizeLabel, normalizeList, normalizeMember, normalizeWorkspace, } from "./normalize.js";
import { detectScope } from "./scope.js";
async function readWorkspaceJson(accessor, match, path) {
const workspaceId = match.slots.workspace_id ?? '';
for (const workspace of await listWorkspaces(accessor.transport)) {
if (workspace.id === workspaceId)
return jsonBytes(normalizeWorkspace(workspace));
}
throw enoent(path.virtual);
}
async function readBoardJson(accessor, match) {
const board = await getBoard(accessor.transport, match.slots.board_id ?? '');
return jsonBytes(normalizeBoard(board));
}
async function readMember(accessor, match, path) {
const memberId = match.slots.member_id ?? '';
const members = await listBoardMembers(accessor.transport, match.slots.board_id ?? '');
for (const member of members) {
if (member.id === memberId)
return jsonBytes(normalizeMember(member));
}
throw enoent(path.virtual);
}
async function readLabel(accessor, match, path) {
const labelId = match.slots.label_id ?? '';
const labels = await listBoardLabels(accessor.transport, match.slots.board_id ?? '');
for (const label of labels) {
if (label.id === labelId)
return jsonBytes(normalizeLabel(label));
}
throw enoent(path.virtual);
}
async function readListJson(accessor, match, path) {
const listId = match.slots.list_id ?? '';
const lists = await listBoardLists(accessor.transport, match.slots.board_id ?? '');
for (const lst of lists) {
if (lst.id === listId)
return jsonBytes(normalizeList(lst));
}
throw enoent(path.virtual);
}
async function readCardJson(accessor, match) {
const card = await getCard(accessor.transport, match.slots.card_id ?? '');
return jsonBytes(normalizeCard(card));
}
async function readComments(accessor, match) {
const cardId = match.slots.card_id ?? '';
const comments = await listCardComments(accessor.transport, cardId);
const rows = comments.map((c) => normalizeComment(c, cardId));
return jsonlBytesByCreatedAt(rows);
}
export const read = makeRead(detectScope, {
workspace_json: readWorkspaceJson,
board_json: readBoardJson,
member: readMember,
label: readLabel,
list_json: readListJson,
card_json: readCardJson,
comments_jsonl: readComments,
}, { parented: true });
//# sourceMappingURL=read.js.map