yamlite 0.42.0 → 0.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { B as check, I as createHandler, R as isLoopback, a as query, c as exportSite, i as formatTable, n as formatCsv, o as generateConfig, r as formatJson, s as init, t as open, z as loopbackHosts } from "./src-ChJZPkg9.mjs";
3
- import { n as guide, r as envKeys, t as createWorkspace } from "./workspace-D7xHlBPc.mjs";
2
+ import { B as check, I as createHandler, R as isLoopback, a as query, c as exportSite, i as formatTable, n as formatCsv, o as generateConfig, r as formatJson, s as init, t as open, z as loopbackHosts } from "./src-BM2e03Dm.mjs";
3
+ import { n as guide, r as envKeys, t as createWorkspace } from "./workspace-BpOu_Vav.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { relative, resolve } from "node:path";
6
6
  import { homedir } from "node:os";
package/dist/core.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as parseConfig, B as HistoryEntry, C as Decision, D as OpenOptions, E as DeclaredTable, F as ColumnType, G as Rec, H as IndexSpec, I as ConflictInfo, J as ViewRecord, K as SchemaChange, L as DbRow, M as Capture, N as Change, O as TableInput, P as ChangeOp, R as DbValue, S as BaseHashes, T as Config, U as PageAccess, V as HistoryPage, W as PageSpec, _ as check, a as formatCsv, b as Watcher, c as query, d as init, f as ExportOptions, g as CheckTable, h as CheckResult, i as QueryResult, j as readsFile, k as TableLocation, l as InitOptions, m as exportSite, n as open, o as formatJson, p as ExportResult, q as TableSpec, r as QueryOptions, s as formatTable, t as Yamlite, u as generateConfig, v as WatchHandlers, w as CONFIG_NAMES, x as TableResult, y as WatchOptions, z as FieldChange } from "./index-Bd2ctbJm.mjs";
1
+ import { A as parseConfig, B as HistoryEntry, C as Decision, D as OpenOptions, E as DeclaredTable, F as ColumnType, G as Rec, H as IndexSpec, I as ConflictInfo, J as ViewRecord, K as SchemaChange, L as DbRow, M as Capture, N as Change, O as TableInput, P as ChangeOp, R as DbValue, S as BaseHashes, T as Config, U as PageAccess, V as HistoryPage, W as PageSpec, _ as check, a as formatCsv, b as Watcher, c as query, d as init, f as ExportOptions, g as CheckTable, h as CheckResult, i as QueryResult, j as readsFile, k as TableLocation, l as InitOptions, m as exportSite, n as open, o as formatJson, p as ExportResult, q as TableSpec, r as QueryOptions, s as formatTable, t as Yamlite, u as generateConfig, v as WatchHandlers, w as CONFIG_NAMES, x as TableResult, y as WatchOptions, z as FieldChange } from "./index-CDeSOWZt.mjs";
2
2
  import { DatabaseSync } from "node:sqlite";
3
3
  import { LanguageModel, ModelMessage } from "ai";
4
4
  //#region src/store.d.ts
package/dist/core.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { B as check, C as describeChange, K as DENIED_FILES, L as HttpError, T as worthShowing, U as parseConfig, V as CONFIG_NAMES, W as readsFile, X as fileGranted, Z as normalizeFilePath, a as query, c as exportSite, f as ReviewRefused, h as templatePath, i as formatTable, n as formatCsv, o as generateConfig, q as MAX_PAGE_FILE_BYTES, r as formatJson, s as init, t as open, w as fieldChanges } from "./src-ChJZPkg9.mjs";
2
- import { t as createWorkspace } from "./workspace-D7xHlBPc.mjs";
1
+ import { B as check, C as describeChange, K as DENIED_FILES, L as HttpError, T as worthShowing, U as parseConfig, V as CONFIG_NAMES, W as readsFile, X as fileGranted, Z as normalizeFilePath, a as query, c as exportSite, f as ReviewRefused, h as templatePath, i as formatTable, n as formatCsv, o as generateConfig, q as MAX_PAGE_FILE_BYTES, r as formatJson, s as init, t as open, w as fieldChanges } from "./src-BM2e03Dm.mjs";
2
+ import { t as createWorkspace } from "./workspace-BpOu_Vav.mjs";
3
3
  export { CONFIG_NAMES, DENIED_FILES, HttpError, MAX_PAGE_FILE_BYTES, ReviewRefused, check, createWorkspace, describeChange, exportSite, fieldChanges, fileGranted, formatCsv, formatJson, formatTable, generateConfig, init, normalizeFilePath, open, parseConfig, query, readsFile, templatePath, worthShowing };
@@ -178,6 +178,7 @@ interface Config {
178
178
  tables: DeclaredTable[];
179
179
  pages: PageSpec[];
180
180
  ai: AiInstructions;
181
+ ignore: string[];
181
182
  }
182
183
  declare function readsFile(l: TableLocation, file: string): boolean;
183
184
  declare function parseConfig(text: string, name?: string): Config;
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as Decision, D as OpenOptions, F as ColumnType, H as IndexSpec, I as ConflictInfo, K as SchemaChange, N as Change, O as TableInput, P as ChangeOp, W as PageSpec, _ as check, a as formatCsv, b as Watcher, c as query, d as init, f as ExportOptions, g as CheckTable, h as CheckResult, i as QueryResult, l as InitOptions, m as exportSite, n as open, o as formatJson, p as ExportResult, q as TableSpec, r as QueryOptions, s as formatTable, t as Yamlite, u as generateConfig, v as WatchHandlers, x as TableResult, y as WatchOptions } from "./index-Bd2ctbJm.mjs";
1
+ import { C as Decision, D as OpenOptions, F as ColumnType, H as IndexSpec, I as ConflictInfo, K as SchemaChange, N as Change, O as TableInput, P as ChangeOp, W as PageSpec, _ as check, a as formatCsv, b as Watcher, c as query, d as init, f as ExportOptions, g as CheckTable, h as CheckResult, i as QueryResult, l as InitOptions, m as exportSite, n as open, o as formatJson, p as ExportResult, q as TableSpec, r as QueryOptions, s as formatTable, t as Yamlite, u as generateConfig, v as WatchHandlers, x as TableResult, y as WatchOptions } from "./index-CDeSOWZt.mjs";
2
2
  export { type Change, type ChangeOp, type CheckResult, type CheckTable, type ColumnType, type ConflictInfo, type Decision, type ExportOptions, type ExportResult, type IndexSpec, type InitOptions, type OpenOptions, type PageSpec, type QueryOptions, type QueryResult, type SchemaChange, type TableInput, type TableResult, type TableSpec, type WatchHandlers, type WatchOptions, type Watcher, Yamlite, check, exportSite, formatCsv, formatJson, formatTable, generateConfig, init, open, query };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { B as check, c as exportSite, n as formatCsv, r as formatJson, i as formatTable, o as generateConfig, s as init, t as open, a as query } from "./src-ChJZPkg9.mjs";
1
+ export { B as check, c as exportSite, n as formatCsv, r as formatJson, i as formatTable, o as generateConfig, s as init, t as open, a as query } from "./src-BM2e03Dm.mjs";
@@ -654,7 +654,7 @@ function logicalType(declared) {
654
654
  function isStructured(value) {
655
655
  return value !== null && typeof value === "object" && !(value instanceof Uint8Array);
656
656
  }
657
- function checkShapes(records, existing, overrides) {
657
+ function checkShapes$1(records, existing, overrides) {
658
658
  const skip = /* @__PURE__ */ new Map();
659
659
  const byField = /* @__PURE__ */ new Map();
660
660
  for (const [key, record] of records) for (const [field, value] of Object.entries(record)) {
@@ -1327,11 +1327,13 @@ function notAList(path) {
1327
1327
  const doc = parseDocument(text);
1328
1328
  return doc.errors.length === 0 && doc.contents !== null && !isSeq(doc.contents);
1329
1329
  }
1330
- function scanRoot(root) {
1330
+ const ignoredEntry = (name, ignore) => ignore.some((p) => matchesGlob(name, p) || matchesGlob(`${name}/`, p));
1331
+ function scanRoot(root, ignore) {
1331
1332
  const out = [];
1332
1333
  for (const entry of readdirSync(root, { withFileTypes: true })) {
1333
1334
  const name = entry.name;
1334
1335
  if (name.startsWith(".") || name === "node_modules" || CONFIG_NAMES.includes(name)) continue;
1336
+ if (ignoredEntry(name, ignore)) continue;
1335
1337
  const path = join(root, name);
1336
1338
  let kind = entry;
1337
1339
  if (entry.isSymbolicLink()) try {
@@ -1403,7 +1405,8 @@ function readRootConfig(root, text) {
1403
1405
  if (path === null) return {
1404
1406
  tables: [],
1405
1407
  pages: [],
1406
- ai: NO_AI
1408
+ ai: NO_AI,
1409
+ ignore: []
1407
1410
  };
1408
1411
  return parseConfig(text ?? readFileSync(path, "utf8"), basename(path));
1409
1412
  }
@@ -1441,9 +1444,20 @@ function parseConfig(text, name = "yamlite.yaml") {
1441
1444
  return {
1442
1445
  tables,
1443
1446
  pages: toPages(raw?.pages, (p) => p),
1444
- ai: toAi(raw?.ai)
1447
+ ai: toAi(raw?.ai),
1448
+ ignore: toIgnore(raw?.ignore)
1445
1449
  };
1446
1450
  }
1451
+ function toIgnore(raw) {
1452
+ if (raw === void 0 || raw === null) return [];
1453
+ if (!isStringList(raw)) throw new Error("ignore must be a list of globs");
1454
+ return raw.map((entry) => {
1455
+ if (entry.startsWith("!")) throw new Error(`ignore entry "${entry}" cannot start with !`);
1456
+ const glob = entry.replace(/^(\.\/)+/, "").replace(/\/+$/, "");
1457
+ if (isAbsolute(glob) || glob.startsWith("~") || glob.split("/").some((s) => s === ".." || s === ".") || glob === "") throw new Error(`ignore entry "${entry}" must be relative to the root`);
1458
+ return glob;
1459
+ });
1460
+ }
1447
1461
  const AI_INSTRUCTIONS_MAX = 4e3;
1448
1462
  const NO_AI = {
1449
1463
  instructions: null,
@@ -1541,7 +1555,7 @@ function toSpec(t, persisted) {
1541
1555
  captures
1542
1556
  };
1543
1557
  }
1544
- function withClaims(tables, configFiles) {
1558
+ function withClaims(tables, configFiles, ignored = []) {
1545
1559
  return tables.map((t) => {
1546
1560
  if (t.mode !== "files") return t;
1547
1561
  const inside = (o) => o !== t && (o.mode === "files" && o.path === t.path ? true : o.path.startsWith(t.path + sep));
@@ -1559,7 +1573,7 @@ function withClaims(tables, configFiles) {
1559
1573
  });
1560
1574
  return {
1561
1575
  ...t,
1562
- exclude
1576
+ exclude: [...exclude, ...ignored]
1563
1577
  };
1564
1578
  });
1565
1579
  }
@@ -1830,8 +1844,8 @@ function resolveConfig(opts, { requireConfig = true } = {}) {
1830
1844
  const root = resolve(opts.root);
1831
1845
  if (!existsSync(root) || !statSync(root).isDirectory()) throw new Error(`root is not a directory: ${root}`);
1832
1846
  if (requireConfig && configPath(root) === null) throw new Error(`no yamlite.yaml in ${root}; run "yamlite init" to create it`);
1833
- const scanned = scanRoot(root);
1834
1847
  const config = readRootConfig(root, opts.configText);
1848
+ const scanned = scanRoot(root, config.ignore);
1835
1849
  const declared = /* @__PURE__ */ new Map();
1836
1850
  const pathErrors = [];
1837
1851
  for (const t of config.tables) {
@@ -1878,7 +1892,13 @@ function resolveConfig(opts, { requireConfig = true } = {}) {
1878
1892
  }
1879
1893
  for (const [name, d] of declared) if (!merged.has(name)) merged.set(name, d);
1880
1894
  const configFiles = CONFIG_NAMES.map((name) => join(root, name));
1881
- const tables = checkViewNames(withClaims([...merged.values()].map((t) => "mode" in t ? t : toSpec(t, true)), configFiles));
1895
+ const ignored = config.ignore.flatMap((glob) => [glob, `${glob}/**`].map((g) => ({
1896
+ owner: `ignore entry "${glob}"`,
1897
+ path: root,
1898
+ glob: g,
1899
+ tie: false
1900
+ })));
1901
+ const tables = checkViewNames(withClaims([...merged.values()].map((t) => "mode" in t ? t : toSpec(t, true)), configFiles, ignored));
1882
1902
  return {
1883
1903
  db: opts.db ? expandPath(opts.db, process.cwd()) : join(root, ".yamlite", "db.sqlite"),
1884
1904
  stateDir: opts.stateDir ? expandPath(opts.stateDir, process.cwd()) : join(root, ".yamlite"),
@@ -2641,7 +2661,7 @@ function planTable(store, spec, files, schema, opts) {
2641
2661
  };
2642
2662
  if (db.nullKeys > 0) warnings.push(`${db.nullKeys} rows with NULL "${spec.key}" are ignored`);
2643
2663
  for (const key of db.skip) warnings.push(`duplicate "${spec.key}" = "${key}" in the table; skipped`);
2644
- const shapes = checkShapes(files.records, existing, spec.columns);
2664
+ const shapes = checkShapes$1(files.records, existing, spec.columns);
2645
2665
  if (shapes.error) return {
2646
2666
  ok: false,
2647
2667
  error: shapes.error,
@@ -2829,9 +2849,15 @@ var ListSource = class {
2829
2849
  };
2830
2850
  //#endregion
2831
2851
  //#region src/engine.ts
2852
+ function mdExt(spec) {
2853
+ return markdownExt(spec.glob) ?? ".md";
2854
+ }
2855
+ function recordExt(spec) {
2856
+ return spec.codec === "markdown" ? mdExt(spec) : yamlCodec.ext;
2857
+ }
2832
2858
  function makeSource(spec) {
2833
2859
  if (spec.mode === "list") return new ListSource(spec.path, spec.key);
2834
- const codec = spec.codec === "markdown" ? markdownCodec(spec.body ?? "body", markdownExt(spec.glob) ?? ".md") : yamlCodec;
2860
+ const codec = spec.codec === "markdown" ? markdownCodec(spec.body ?? "body", mdExt(spec)) : yamlCodec;
2835
2861
  return new FilesSource(spec.path, spec.glob ?? "**/*.{yaml,yml}", spec.key, spec.exclude, codec, spec.captures);
2836
2862
  }
2837
2863
  function emptyResult(table) {
@@ -3980,11 +4006,25 @@ function assertSynced(results, prefix, suffix = "") {
3980
4006
  function checkKey(spec, key) {
3981
4007
  if (typeof key !== "string" || key === "") throw new HttpError(400, "key is required", { field: "key" });
3982
4008
  if (spec.mode === "files") {
3983
- const reason = invalidKey(key);
4009
+ const reason = invalidKey(key) ?? unmatchedKey(spec, key);
3984
4010
  if (reason) throw new HttpError(400, reason, { field: "key" });
3985
4011
  }
3986
4012
  return key;
3987
4013
  }
4014
+ function unmatchedKey(spec, key) {
4015
+ const glob = spec.glob ?? "**/*.{yaml,yml}";
4016
+ if (matchesFiles(`${key}${recordExt(spec)}`, glob)) return null;
4017
+ if (spec.captures.length === 0) return `key does not match files "${glob}"`;
4018
+ const segments = glob.split("/");
4019
+ return `key must look like "${segments.map((s, i) => {
4020
+ if (i === segments.length - 1) return "<name>";
4021
+ const capture = spec.captures.find((c) => c.segment === i);
4022
+ return capture ? `<${capture.column}>` : s;
4023
+ }).join("/")}" to match files "${glob}"`;
4024
+ }
4025
+ function checkShapes(record, types) {
4026
+ for (const [column, value] of Object.entries(record)) if (types.get(column) === "JSON" && value !== null && !isStructured(value)) throw new HttpError(400, `"${column}" must be a JSON map or list`, { field: column });
4027
+ }
3988
4028
  function noKeyIn(spec, values, hint) {
3989
4029
  if (spec.key in values) throw new HttpError(400, `"${spec.key}" is the key; ${hint}`, { field: spec.key });
3990
4030
  }
@@ -3996,7 +4036,9 @@ function readRecord(store, spec, key) {
3996
4036
  function insertRecord(store, spec, key, values) {
3997
4037
  checkKey(spec, key);
3998
4038
  noKeyIn(spec, values, "send it as \"key\"");
3999
- const record = fromWireRecord(values, store.tableExists(spec.name) ? store.columns(spec.name) : /* @__PURE__ */ new Map());
4039
+ const before = store.tableExists(spec.name) ? store.columns(spec.name) : /* @__PURE__ */ new Map();
4040
+ const record = fromWireRecord(values, before);
4041
+ checkShapes(record, declaredTypes(spec, before));
4000
4042
  const keyValue = encode(fromWire(key, ensureColumns(store, spec, record).get(spec.key)));
4001
4043
  if (store.readRow(spec.name, spec.key, keyValue)) throw new HttpError(409, `"${key}" already exists in ${spec.name}`, { field: "key" });
4002
4044
  const row = {
@@ -4009,7 +4051,9 @@ function updateRecord(store, spec, key, values) {
4009
4051
  noKeyIn(spec, values, "rename the record instead");
4010
4052
  const row = store.tableExists(spec.name) ? store.readRow(spec.name, spec.key, key) : void 0;
4011
4053
  if (!row) throw new HttpError(404, `no record "${key}" in ${spec.name}`);
4012
- const record = fromWireRecord(values, store.columns(spec.name));
4054
+ const types = store.columns(spec.name);
4055
+ const record = fromWireRecord(values, types);
4056
+ checkShapes(record, declaredTypes(spec, types));
4013
4057
  ensureColumns(store, spec, record);
4014
4058
  const update = {
4015
4059
  ...recordToRow(record),
@@ -4017,6 +4061,9 @@ function updateRecord(store, spec, key, values) {
4017
4061
  };
4018
4062
  store.upsert(spec.name, spec.key, update, Object.keys(update));
4019
4063
  }
4064
+ function declaredTypes(spec, existing) {
4065
+ return new Map([...Object.entries(spec.columns), ...existing]);
4066
+ }
4020
4067
  function deleteRecord(store, spec, key) {
4021
4068
  const row = store.tableExists(spec.name) ? store.readRow(spec.name, spec.key, key) : void 0;
4022
4069
  if (!row) throw new HttpError(404, `no record "${key}" in ${spec.name}`);
@@ -8376,7 +8423,7 @@ function inferKey(spec) {
8376
8423
  function columnsFor(spec, existing) {
8377
8424
  const files = makeSource(spec).read();
8378
8425
  if (files.tableError) throw new Error(`${spec.name}: ${files.tableError}`);
8379
- const shapes = checkShapes(files.records, existing ?? /* @__PURE__ */ new Map(), spec.columns);
8426
+ const shapes = checkShapes$1(files.records, existing ?? /* @__PURE__ */ new Map(), spec.columns);
8380
8427
  if (shapes.error) throw new Error(`${spec.name}: ${shapes.error}`);
8381
8428
  const columns = new Map(existing ?? []);
8382
8429
  for (const [column, type] of inferColumns(files.records.values())) if (!columns.has(column)) columns.set(column, spec.columns[column] ?? type);