yamlite 0.44.1 → 0.45.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-c2B3gqup.mjs";
3
- import { n as guide, r as envKeys, t as createWorkspace } from "./workspace-Bi3ZH_Bi.mjs";
2
+ import { B as loopbackHosts, L as createHandler, V as check, 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 isLoopback } from "./src-CAiXSCwK.mjs";
3
+ import { n as guide, r as envKeys, t as createWorkspace } from "./workspace-BFppcWl_.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
@@ -251,6 +251,7 @@ interface Repo {
251
251
  top: string;
252
252
  root: string;
253
253
  prefix: string;
254
+ reaches?: (file: string) => boolean;
254
255
  }
255
256
  //#endregion
256
257
  //#region src/git/review.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-c2B3gqup.mjs";
2
- import { t as createWorkspace } from "./workspace-Bi3ZH_Bi.mjs";
1
+ import { E as worthShowing, G as readsFile, H as CONFIG_NAMES, J as MAX_PAGE_FILE_BYTES, Q as normalizeFilePath, R as HttpError, T as fieldChanges, V as check, W as parseConfig, Z as fileGranted, a as query, c as exportSite, g as templatePath, i as formatTable, n as formatCsv, o as generateConfig, p as ReviewRefused, q as DENIED_FILES, r as formatJson, s as init, t as open, w as describeChange } from "./src-CAiXSCwK.mjs";
2
+ import { t as createWorkspace } from "./workspace-BFppcWl_.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 };
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-c2B3gqup.mjs";
1
+ export { V 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-CAiXSCwK.mjs";
@@ -1,7 +1,7 @@
1
1
  import { basename, delimiter, dirname, extname, isAbsolute, join, matchesGlob, normalize, posix, relative, resolve, sep } from "node:path";
2
2
  import { accessSync, chmodSync, constants, copyFileSync, cpSync, createReadStream, existsSync, linkSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, unlinkSync, writeFileSync } from "node:fs";
3
3
  import { homedir, tmpdir } from "node:os";
4
- import { Document, Scalar, isMap, isNode, isScalar, isSeq, parse, parseDocument, stringify } from "yaml";
4
+ import { Document, Scalar, isMap, isNode, isScalar, isSeq, parse, parseAllDocuments, parseDocument, stringify } from "yaml";
5
5
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
6
6
  import { DatabaseSync, constants as constants$1 } from "node:sqlite";
7
7
  import { watch } from "chokidar";
@@ -1324,6 +1324,8 @@ function notAList(path) {
1324
1324
  } catch {
1325
1325
  return false;
1326
1326
  }
1327
+ const docs = parseAllDocuments(text);
1328
+ if (Array.isArray(docs) && docs.length > 1) return true;
1327
1329
  const doc = parseDocument(text);
1328
1330
  return doc.errors.length === 0 && doc.contents !== null && !isSeq(doc.contents);
1329
1331
  }
@@ -5716,7 +5718,12 @@ async function findRepo(root) {
5716
5718
  return null;
5717
5719
  }
5718
5720
  }
5719
- const toRoot = (repo, topPath) => topPath.startsWith(repo.prefix) ? topPath.slice(repo.prefix.length) : null;
5721
+ function toRoot(repo, topPath) {
5722
+ if (topPath.startsWith(repo.prefix)) return topPath.slice(repo.prefix.length);
5723
+ if (!repo.reaches) return null;
5724
+ const path = posix.relative(repo.prefix.replace(/\/$/, "") || ".", topPath);
5725
+ return repo.reaches(resolve(repo.root, path)) ? path : null;
5726
+ }
5720
5727
  async function currentBranch(repo) {
5721
5728
  try {
5722
5729
  return (await runGit(repo.top, [
@@ -5861,8 +5868,10 @@ async function ghReady(env = process.env) {
5861
5868
  function insideRoot$1(repo, path) {
5862
5869
  const abs = resolve(repo.root, path);
5863
5870
  const rel = relative(repo.root, abs);
5864
- if (rel === "" || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) return null;
5865
- return repo.prefix + rel.split(sep).join(posix.sep);
5871
+ if (rel === "" || isAbsolute(rel)) return null;
5872
+ if (!(rel !== ".." && !rel.startsWith(`..${sep}`)) && !repo.reaches?.(abs)) return null;
5873
+ const top = posix.normalize(repo.prefix + rel.split(sep).join(posix.sep));
5874
+ return top === ".." || top.startsWith("../") ? null : top;
5866
5875
  }
5867
5876
  //#endregion
5868
5877
  //#region src/git/pr.ts
@@ -6303,13 +6312,17 @@ var NoRepository = class extends Error {
6303
6312
  super("the data folder is not in a git repository");
6304
6313
  }
6305
6314
  };
6306
- async function localDriver(root, gh) {
6315
+ async function localDriver(root, gh, reaches) {
6307
6316
  let found = null;
6308
6317
  let base = null;
6309
6318
  const lookup = async () => {
6310
6319
  if (found) return found;
6311
- const repo = await findRepo(root);
6312
- if (!repo) return null;
6320
+ const at = await findRepo(root);
6321
+ if (!at) return null;
6322
+ const repo = reaches ? {
6323
+ ...at,
6324
+ reaches
6325
+ } : at;
6313
6326
  found ??= {
6314
6327
  repo,
6315
6328
  steps: {
@@ -6402,7 +6415,7 @@ async function localDriver(root, gh) {
6402
6415
  "-z",
6403
6416
  `${await defaultRef(f.repo, name)}...HEAD`,
6404
6417
  "--",
6405
- f.repo.prefix || "."
6418
+ f.repo.reaches ? "." : f.repo.prefix || "."
6406
6419
  ])).split("\0");
6407
6420
  const changes = [];
6408
6421
  for (let i = 0; i + 1 < parts.length; i += 2) {
@@ -7111,9 +7124,7 @@ const gitRoutes = (router, ctx) => {
7111
7124
  return ctx.proposals.exclusive(async () => {
7112
7125
  const changed = new Set((await from.changes().catch(notFound)).map((c) => c.path));
7113
7126
  const files = await Promise.all(paths.map(async (path) => {
7114
- const file = resolve(ctx.root, path);
7115
- const rel = relative(ctx.root, file);
7116
- if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) throw new HttpError(400, `${path} is outside the data folder`);
7127
+ const file = dataFile(ctx, path);
7117
7128
  if (!changed.has(path)) throw new HttpError(400, `${path} is the same as on the default branch`);
7118
7129
  const content = await from.file(path).catch(notFound);
7119
7130
  if (content === null && existsSync(file) && lstatSync(file).isDirectory()) throw new HttpError(409, `${path} is a folder; remove it with git`);
@@ -7138,15 +7149,18 @@ const gitRoutes = (router, ctx) => {
7138
7149
  const git = ctx.git;
7139
7150
  if (!git) throw new HttpError(404, "the data folder is not in a git repository");
7140
7151
  const path = query.get("path") ?? "";
7141
- const rel = relative(ctx.root, resolve(ctx.root, path));
7142
- if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) throw new HttpError(400, `${path} is outside the data folder`);
7152
+ dataFile(ctx, path);
7143
7153
  const found = await recordChanges(git, ctx.root, ctx.y.tables, path).catch(notFound);
7144
7154
  if (!found?.records) throw new HttpError(404, `${path} holds no records to compare`);
7145
7155
  return { records: found.records.map((r) => {
7146
7156
  const keyField = ctx.y.tables.find((t) => t.name === found.table)?.key ?? "";
7147
7157
  const before = r.before ? withoutKey(r.before, keyField) : {};
7148
7158
  const after = r.after ? withoutKey(r.after, keyField) : {};
7149
- const fields = [.../* @__PURE__ */ new Set([...Object.keys(after), ...Object.keys(before)])].filter((f) => r.kind !== "modified" || r.fields.includes(f)).map((field) => ({
7159
+ const fields = r.kind === "modified" ? fieldChanges(before, after).map((c) => ({
7160
+ field: c.path,
7161
+ from: wireValue(c.from),
7162
+ to: wireValue(c.to)
7163
+ })) : [.../* @__PURE__ */ new Set([...Object.keys(after), ...Object.keys(before)])].map((field) => ({
7150
7164
  field,
7151
7165
  from: wireValue(own$1(before, field) ?? null),
7152
7166
  to: wireValue(own$1(after, field) ?? null)
@@ -7245,9 +7259,7 @@ const gitRoutes = (router, ctx) => {
7245
7259
  if (items.length === 0 && paths.length === 0) throw new HttpError(400, "choose at least one record or file", { field: "records" });
7246
7260
  const changed = new Map(paths.length > 0 ? (await git.status()).changes.map((c) => [c.path, c.status]) : []);
7247
7261
  const files = await Promise.all(paths.map(async (path) => {
7248
- const file = resolve(ctx.root, path);
7249
- const rel = relative(ctx.root, file);
7250
- if (rel === "" || rel.startsWith("..") || isAbsolute(rel)) throw new HttpError(400, `${path} is outside the data folder`);
7262
+ const file = dataFile(ctx, path);
7251
7263
  const status = changed.get(path);
7252
7264
  if (status === void 0) throw new HttpError(400, `${path} has no changes`);
7253
7265
  const content = await git.baseFile(path).catch(notFound);
@@ -7321,6 +7333,12 @@ function shownFile(file) {
7321
7333
  if (!s.isFile()) return s.isSymbolicLink() ? "(a symbolic link)" : null;
7322
7334
  return s.size > DRAFT_FILE_BYTES ? OMITTED : shownText(readFileSync(file, "utf8"));
7323
7335
  }
7336
+ function dataFile(ctx, path) {
7337
+ const file = resolve(ctx.root, path);
7338
+ const rel = relative(ctx.root, file);
7339
+ if (!(rel !== "" && !rel.startsWith("..") && !isAbsolute(rel)) && ownerOf(ctx.y.tables, file) === null) throw new HttpError(400, `${path} is outside the data folder`);
7340
+ return file;
7341
+ }
7324
7342
  function notFound(e) {
7325
7343
  if (e instanceof NoRepository) throw new HttpError(404, e.message);
7326
7344
  throw e;
@@ -8813,4 +8831,4 @@ async function open(options) {
8813
8831
  };
8814
8832
  }
8815
8833
  //#endregion
8816
- export { Store as $, deniedFiles as A, check as B, describeChange as C, isRead as D, PageSql as E, Router as F, resolveConfig as G, configPath as H, createHandler as I, deniedFile as J, DENIED_FILES as K, HttpError as L, readRecord as M, assertSynced as N, statementCount as O, toWire as P, declaredViews as Q, isLoopback as R, which as S, worthShowing as T, parseConfig as U, CONFIG_NAMES as V, readsFile as W, fileGranted as X, entryCovers as Y, normalizeFilePath as Z, ghReady as _, query as a, gitLog as b, exportSite as c, validateNewTable as d, COLUMN_TYPES as et, ReviewRefused as f, DIFF_LIMIT as g, templatePath as h, formatTable as i, ProposalStore as j, EventHub as k, ROUTES as l, STEP_KINDS as m, formatCsv as n, generateConfig as o, localDriver as p, MAX_PAGE_FILE_BYTES as q, formatJson as r, init as s, open as t, createTable as u, gitBranches as v, fieldChanges as w, gitStatus as x, gitDiff as y, loopbackHosts as z };
8834
+ export { declaredViews as $, EventHub as A, loopbackHosts as B, which as C, PageSql as D, worthShowing as E, toWire as F, readsFile as G, CONFIG_NAMES as H, Router as I, MAX_PAGE_FILE_BYTES as J, resolveConfig as K, createHandler as L, ProposalStore as M, readRecord as N, isRead as O, assertSynced as P, normalizeFilePath as Q, HttpError as R, gitStatus as S, fieldChanges as T, configPath as U, check as V, parseConfig as W, entryCovers as X, deniedFile as Y, fileGranted as Z, DIFF_LIMIT as _, query as a, gitDiff as b, exportSite as c, validateNewTable as d, Store as et, ownerOf as f, templatePath as g, STEP_KINDS as h, formatTable as i, deniedFiles as j, statementCount as k, ROUTES as l, localDriver as m, formatCsv as n, generateConfig as o, ReviewRefused as p, DENIED_FILES as q, formatJson as r, init as s, open as t, COLUMN_TYPES as tt, createTable as u, ghReady as v, describeChange as w, gitLog as x, gitBranches as y, isLoopback as z };
@@ -1,4 +1,4 @@
1
- import { $ as Store, A as deniedFiles, B as check, D as isRead, E as PageSql, F as Router, G as resolveConfig, H as configPath, J as deniedFile, L as HttpError, M as readRecord, N as assertSynced, O as statementCount, P as toWire, Q as declaredViews, S as which, X as fileGranted, Y as entryCovers, _ as ghReady, b as gitLog, d as validateNewTable, et as COLUMN_TYPES, g as DIFF_LIMIT, j as ProposalStore, k as EventHub, l as ROUTES, m as STEP_KINDS, p as localDriver, t as open, u as createTable, v as gitBranches, x as gitStatus, y as gitDiff } from "./src-c2B3gqup.mjs";
1
+ import { $ as declaredViews, A as EventHub, C as which, D as PageSql, F as toWire, I as Router, K as resolveConfig, M as ProposalStore, N as readRecord, O as isRead, P as assertSynced, R as HttpError, S as gitStatus, U as configPath, V as check, X as entryCovers, Y as deniedFile, Z as fileGranted, _ as DIFF_LIMIT, b as gitDiff, d as validateNewTable, et as Store, f as ownerOf, h as STEP_KINDS, j as deniedFiles, k as statementCount, l as ROUTES, m as localDriver, t as open, tt as COLUMN_TYPES, u as createTable, v as ghReady, x as gitLog, y as gitBranches } from "./src-CAiXSCwK.mjs";
2
2
  import { dirname, relative, resolve, sep } from "node:path";
3
3
  import { readFileSync } from "node:fs";
4
4
  import { randomBytes } from "node:crypto";
@@ -885,7 +885,7 @@ async function createWorkspace(o) {
885
885
  dry = new Store(config.db);
886
886
  let probed;
887
887
  const gh = () => probed ??= o.gh !== void 0 ? Promise.resolve(o.gh) : ghReady().then((ok) => ok ? which("gh") : null);
888
- const git = o.git === void 0 ? await localDriver(o.root, gh) : o.git;
888
+ const git = o.git === void 0 ? await localDriver(o.root, gh, (file) => ownerOf(y.tables, file) !== null) : o.git;
889
889
  const proposals = new ProposalStore({
890
890
  store,
891
891
  dry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yamlite",
3
- "version": "0.44.1",
3
+ "version": "0.45.1",
4
4
  "description": "Sync YAML files and SQLite in both directions",
5
5
  "keywords": [
6
6
  "cli",