UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

46 lines • 2.1 kB
// ========= 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 { materialize } from "../../io/types.js"; import { makeRead } from "../hierarchy/read.js"; import { buildCollectionSchemaJson, buildDatabaseJson } from "./_schema_json.js"; import { databaseGuard, entityGuard } from "./readdir.js"; import { detectScope } from "./scope.js"; import { readStream, renderDoc } from "./stream.js"; export async function* streamAny(accessor, path) { const scope = detectScope(path); if (scope.kind === 'documents') { yield* readStream(accessor, path); return; } yield await read(accessor, path); } async function readDocuments(accessor, match, path) { return materialize(readStream(accessor, path)); } async function readSchemaJson(accessor, match, path) { await entityGuard(accessor, match, path.virtual); const payload = await buildCollectionSchemaJson(accessor, match.slots.database ?? '', match.slots.name ?? ''); return new TextEncoder().encode(renderDoc(payload) + '\n'); } async function readDatabaseJson(accessor, match, path) { await databaseGuard(accessor, match, path.virtual); const payload = await buildDatabaseJson(accessor, match.slots.database ?? ''); return new TextEncoder().encode(renderDoc(payload) + '\n'); } export const read = makeRead(detectScope, { documents: readDocuments, schema_json: readSchemaJson, database_json: readDatabaseJson, }); //# sourceMappingURL=read.js.map