@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
78 lines • 4.03 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 { jsonBytes } from "../../../../core/render/json.js";
import { getBoard, getCard, listBoardLabels, listBoardLists, listBoardMembers, listCardComments, listListCards, } from "../../../../core/trello/client.js";
import { filteredBoards, filteredWorkspaces } from "../../../../core/trello/readdir.js";
import { normalizeBoard, normalizeCard, normalizeComment, normalizeLabel, normalizeList, normalizeMember, } from "../../../../core/trello/normalize.js";
import { IOResult } from "../../../../io/types.js";
import { requireBoard, requireCard, requireList } from "./scope.js";
function first(texts, label) {
const value = texts[0];
if (value === undefined || value === '')
throw new Error(`${label} is required`);
return value;
}
export async function boardList(accessor, _paths, _texts, _ctx) {
const boards = [];
for (const workspace of await filteredWorkspaces(accessor)) {
const workspaceId = typeof workspace.id === 'string' ? workspace.id : '';
for (const board of await filteredBoards(accessor, workspaceId)) {
boards.push(normalizeBoard(board));
}
}
return [jsonBytes(boards), new IOResult()];
}
export async function boardShow(accessor, _paths, texts, _ctx) {
const boardId = first(texts, 'board id');
await requireBoard(accessor, boardId);
const board = await getBoard(accessor.transport, boardId);
return [jsonBytes(normalizeBoard(board)), new IOResult()];
}
export async function boardMembers(accessor, _paths, texts, _ctx) {
const boardId = first(texts, 'board id');
await requireBoard(accessor, boardId);
const members = await listBoardMembers(accessor.transport, boardId);
return [jsonBytes(members.map((member) => normalizeMember(member))), new IOResult()];
}
export async function listList(accessor, _paths, texts, _ctx) {
const boardId = first(texts, 'board id');
await requireBoard(accessor, boardId);
const lists = await listBoardLists(accessor.transport, boardId);
return [jsonBytes(lists.map((lst) => normalizeList(lst))), new IOResult()];
}
export async function labelList(accessor, _paths, texts, _ctx) {
const boardId = first(texts, 'board id');
await requireBoard(accessor, boardId);
const labels = await listBoardLabels(accessor.transport, boardId);
return [jsonBytes(labels.map((label) => normalizeLabel(label))), new IOResult()];
}
export async function cardList(accessor, _paths, texts, _ctx) {
const listId = first(texts, 'list id');
await requireList(accessor, listId);
const cards = await listListCards(accessor.transport, listId);
return [jsonBytes(cards.map((card) => normalizeCard(card))), new IOResult()];
}
export async function cardShow(accessor, _paths, texts, _ctx) {
const cardId = first(texts, 'card id');
await requireCard(accessor, cardId);
const card = await getCard(accessor.transport, cardId);
return [jsonBytes(normalizeCard(card)), new IOResult()];
}
export async function cardComments(accessor, _paths, texts, _ctx) {
const cardId = first(texts, 'card id');
await requireCard(accessor, cardId);
const comments = await listCardComments(accessor.transport, cardId);
return [jsonBytes(comments.map((comment) => normalizeComment(comment, cardId))), new IOResult()];
}
//# sourceMappingURL=reads.js.map