UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

76 lines (75 loc) • 3.25 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 { firstLines as postgresFirstLines, follow as postgresFollow, lastLines as postgresLastLines, lineCount as postgresLineCount, readStream as postgresReadStream, } from "../../core/postgres/read.js"; import { readdir as postgresReaddir } from "../../core/postgres/readdir.js"; import { linesContaining as postgresLinesContaining } from "../../core/postgres/search.js"; import { stat as postgresStat } from "../../core/postgres/stat.js"; import { BaseVFS } from "../base.js"; export const VFS_MD = `\`\`\`text {prefix} database.json # cross-schema graph and sizes <schema>/ # a Postgres schema (namespace) tables/<table>/ schema.json # column types, PK/FK, indexes semantic.json # descriptions, roles, sample values rows.jsonl # data (size-guarded) views/<view>/ schema.json semantic.json rows.jsonl \`\`\` - Read \`database.json\` first to plan joins. - Read \`semantic.json\` to learn what a table means: it splits columns into dimensions (group by), time_dimensions and facts (aggregate), and carries COMMENTs, enum domains and example values. - Reading \`rows.jsonl\` is refused for a table above the configured row or byte threshold. Use \`head\`, \`tail\` or \`wc\`, which ask SQL for only what they need, or \`grep\`, which fetches only the matching rows when SQL can find every match.`; /** * Postgres's functions over its accessor, which the node and browser * packages build over their own transport. */ export class PostgresVFS extends BaseVFS { handed = { read: ['parent'], stat: ['entry'], }; readdir(path) { return postgresReaddir(this.accessor, path); } // eslint-disable-next-line @typescript-eslint/require-await async read(path, handed) { return postgresReadStream(this.accessor, path, handed?.entry ?? null, handed?.parent ?? null); } stat(path, handed) { return postgresStat(this.accessor, path, handed?.entry); } linesContaining(path, text, opts) { return postgresLinesContaining(this.accessor, path, text, opts.ignoreCase); } firstLines(path, n) { return postgresFirstLines(this.accessor, path, n); } lastLines(path, n) { return postgresLastLines(this.accessor, path, n); } lineCount(path) { return postgresLineCount(this.accessor, path); } follow(path, n, interval) { return postgresFollow(this.accessor, path, n, interval); } } //# sourceMappingURL=postgres.js.map