yamlite 0.43.1 → 0.44.0

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-BM2e03Dm.mjs";
3
- import { n as guide, r as envKeys, t as createWorkspace } from "./workspace-BpOu_Vav.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-c2B3gqup.mjs";
3
+ import { n as guide, r as envKeys, t as createWorkspace } from "./workspace-Bi3ZH_Bi.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
@@ -277,16 +277,20 @@ interface GitStatus {
277
277
  status: "added" | "modified" | "deleted";
278
278
  }[];
279
279
  }
280
- interface GitDriver {
281
- hasRemote(): Promise<boolean>;
280
+ interface WorkspaceDriver {
282
281
  status(): Promise<GitStatus>;
283
- defaultBranch(): Promise<string | null>;
284
282
  baseContent(rootPath: string): Promise<string | null>;
285
283
  baseFile(rootPath: string): Promise<Uint8Array | null>;
286
- history(t: HistoryTarget, extract: Extract, o: {
284
+ history?(t: HistoryTarget, extract: Extract, o: {
287
285
  cursor?: string;
288
286
  }): Promise<HistoryPage>;
289
- fileDiff(t: HistoryTarget, rev: string): Promise<DiffResult>;
287
+ fileDiff?(t: HistoryTarget, rev: string): Promise<DiffResult>;
288
+ review?: ReviewCapability;
289
+ readonly steps?: StepRunner;
290
+ }
291
+ interface ReviewCapability {
292
+ available(): Promise<boolean>;
293
+ defaultBranch(): Promise<string | null>;
290
294
  review(req: ReviewRequest & {
291
295
  target: string | null;
292
296
  }, o: {
@@ -296,7 +300,6 @@ interface GitDriver {
296
300
  pullRequestTemplate?(): Promise<string | null>;
297
301
  readonly namesBranch?: boolean;
298
302
  readonly defaultBranchFiles?: DefaultBranchFiles;
299
- readonly steps?: StepRunner;
300
303
  }
301
304
  interface DefaultBranchFiles {
302
305
  changes(): Promise<GitStatus["changes"]>;
@@ -401,7 +404,7 @@ interface ApiContext {
401
404
  hub: EventHub;
402
405
  proposals: ProposalStore;
403
406
  agent: AgentHost | null;
404
- git: GitDriver | null;
407
+ git: WorkspaceDriver | null;
405
408
  reloadConfig: () => void;
406
409
  pageFiles: WorkspaceOptions["pageFiles"] | null;
407
410
  deniedFiles: string[];
@@ -544,7 +547,7 @@ interface WorkspaceOptions {
544
547
  db?: string;
545
548
  watch?: WatchOptions;
546
549
  ai?: AiOptions | null;
547
- git?: GitDriver | null;
550
+ git?: WorkspaceDriver | null;
548
551
  gh?: string | null;
549
552
  pageFiles?: (path: string, signal: AbortSignal) => Promise<PageFileResult>;
550
553
  }
@@ -558,4 +561,4 @@ export declare function createWorkspace(o: WorkspaceOptions): Promise<Workspace>
558
561
  //#region src/git/pr.d.ts
559
562
  export declare function templatePath(paths: readonly string[]): string | null;
560
563
  //#endregion
561
- export { type AiOptions, type ApiContext, CONFIG_NAMES, type Capture, type Change, type ChangeOp, type CheckResult, type CheckTable, type ColumnType, type Config, type ConflictInfo, type Credentials, type Decision, type DeclaredTable, type DefaultBranchFiles, type DiffResult, type ExportOptions, type ExportResult, type Extract, type Extracted, type GitDriver, type GitStatus, type GitStep, type HistoryEntry, type HistoryPage, type HistoryTarget, type IndexSpec, type InitOptions, type OpenOptions, type PageFileResult, type PageSpec, type QueryOptions, type QueryResult, type Repo, type ReviewOutcome, type ReviewRequest, type RunOptions, type SchemaChange, type StepResult, type StepRunner, type TableInput, type TableLocation, type TableResult, type TableSpec, type WatchHandlers, type WatchOptions, type Watcher, type Workspace, type WorkspaceOptions, Yamlite, check, exportSite, formatCsv, formatJson, formatTable, generateConfig, init, open, parseConfig, query, readsFile };
564
+ export { type AiOptions, type ApiContext, CONFIG_NAMES, type Capture, type Change, type ChangeOp, type CheckResult, type CheckTable, type ColumnType, type Config, type ConflictInfo, type Credentials, type Decision, type DeclaredTable, type DefaultBranchFiles, type DiffResult, type ExportOptions, type ExportResult, type Extract, type Extracted, type GitStatus, type GitStep, type HistoryEntry, type HistoryPage, type HistoryTarget, type IndexSpec, type InitOptions, type OpenOptions, type PageFileResult, type PageSpec, type QueryOptions, type QueryResult, type Repo, type ReviewCapability, type ReviewOutcome, type ReviewRequest, type RunOptions, type SchemaChange, type StepResult, type StepRunner, type TableInput, type TableLocation, type TableResult, type TableSpec, type WatchHandlers, type WatchOptions, type Watcher, type Workspace, type WorkspaceDriver, type WorkspaceOptions, Yamlite, check, exportSite, formatCsv, formatJson, formatTable, generateConfig, init, open, parseConfig, query, readsFile };
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-BM2e03Dm.mjs";
2
- import { t as createWorkspace } from "./workspace-BpOu_Vav.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-c2B3gqup.mjs";
2
+ import { t as createWorkspace } from "./workspace-Bi3ZH_Bi.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-BM2e03Dm.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-c2B3gqup.mjs";
@@ -5218,7 +5218,7 @@ const historyRoutes = (router, ctx) => {
5218
5218
  const { spec, key, t } = target(ctx, params);
5219
5219
  const cursor = query.get("cursor") ?? void 0;
5220
5220
  if (cursor !== void 0 && !CURSOR.test(cursor)) throw new HttpError(400, "invalid cursor");
5221
- if (!ctx.git) return { state: "nogit" };
5221
+ if (!ctx.git?.history) return { state: "nogit" };
5222
5222
  const page = await ctx.git.history(t, extractor(spec, key), { cursor });
5223
5223
  if (page.state !== "ok") return page;
5224
5224
  return {
@@ -5240,7 +5240,7 @@ const historyRoutes = (router, ctx) => {
5240
5240
  const rev = params.sha;
5241
5241
  if (!REV.test(rev)) throw new HttpError(400, "invalid commit");
5242
5242
  const { t } = target(ctx, params);
5243
- if (!ctx.git) throw new HttpError(404, "no git history (nogit)");
5243
+ if (!ctx.git?.fileDiff) throw new HttpError(404, "no git history (nogit)");
5244
5244
  const res = await ctx.git.fileDiff(t, rev);
5245
5245
  if (res.state === "ok") return { text: res.text };
5246
5246
  if (res.state === "error") throw new HttpError(500, res.message);
@@ -6336,24 +6336,9 @@ async function localDriver(root, gh) {
6336
6336
  };
6337
6337
  await lookup();
6338
6338
  return {
6339
- namesBranch: true,
6340
6339
  get steps() {
6341
6340
  return found?.steps;
6342
6341
  },
6343
- async hasRemote() {
6344
- const f = await lookup();
6345
- if (!f) return false;
6346
- try {
6347
- await runGit(f.repo.top, [
6348
- "remote",
6349
- "get-url",
6350
- "origin"
6351
- ]);
6352
- return true;
6353
- } catch {
6354
- return false;
6355
- }
6356
- },
6357
6342
  async status() {
6358
6343
  const f = await lookup();
6359
6344
  if (!f) return {
@@ -6372,7 +6357,6 @@ async function localDriver(root, gh) {
6372
6357
  changes
6373
6358
  };
6374
6359
  },
6375
- defaultBranch: defaultName,
6376
6360
  async baseContent(rootPath) {
6377
6361
  const { repo } = await need();
6378
6362
  const top = insideRoot$1(repo, rootPath);
@@ -6386,70 +6370,88 @@ async function localDriver(root, gh) {
6386
6370
  async baseFile(rootPath) {
6387
6371
  return blobAt((await need()).repo, "HEAD", rootPath);
6388
6372
  },
6389
- defaultBranchFiles: {
6390
- async changes() {
6373
+ history: (t, extract, o) => recordHistory(t, extract, o),
6374
+ fileDiff: (t, rev) => fileDiff(t, rev),
6375
+ review: {
6376
+ namesBranch: true,
6377
+ async available() {
6391
6378
  const f = await lookup();
6392
- if (!f) return [];
6393
- const [branch, name] = [await currentBranch(f.repo), await defaultName()];
6394
- if (branch === null || name === null || branch === name) return [];
6395
- const parts = (await runGit(f.repo.top, [
6396
- "diff",
6397
- "--name-status",
6398
- "--no-renames",
6399
- "-z",
6400
- `${await defaultRef(f.repo, name)}...HEAD`,
6401
- "--",
6402
- f.repo.prefix || "."
6403
- ])).split("\0");
6404
- const changes = [];
6405
- for (let i = 0; i + 1 < parts.length; i += 2) {
6406
- const path = toRoot(f.repo, parts[i + 1]);
6407
- if (path === null) continue;
6408
- const code = parts[i];
6409
- changes.push({
6410
- path,
6411
- status: code === "A" ? "added" : code === "D" ? "deleted" : "modified"
6412
- });
6379
+ if (!f) return false;
6380
+ try {
6381
+ await runGit(f.repo.top, [
6382
+ "remote",
6383
+ "get-url",
6384
+ "origin"
6385
+ ]);
6386
+ return true;
6387
+ } catch {
6388
+ return false;
6413
6389
  }
6414
- return changes;
6415
6390
  },
6416
- async file(rootPath) {
6417
- const { repo } = await need();
6418
- const name = await defaultName();
6419
- if (name === null) throw new GitError("the default branch is not known");
6420
- return blobAt(repo, await defaultRef(repo, name), rootPath);
6391
+ defaultBranch: defaultName,
6392
+ defaultBranchFiles: {
6393
+ async changes() {
6394
+ const f = await lookup();
6395
+ if (!f) return [];
6396
+ const [branch, name] = [await currentBranch(f.repo), await defaultName()];
6397
+ if (branch === null || name === null || branch === name) return [];
6398
+ const parts = (await runGit(f.repo.top, [
6399
+ "diff",
6400
+ "--name-status",
6401
+ "--no-renames",
6402
+ "-z",
6403
+ `${await defaultRef(f.repo, name)}...HEAD`,
6404
+ "--",
6405
+ f.repo.prefix || "."
6406
+ ])).split("\0");
6407
+ const changes = [];
6408
+ for (let i = 0; i + 1 < parts.length; i += 2) {
6409
+ const path = toRoot(f.repo, parts[i + 1]);
6410
+ if (path === null) continue;
6411
+ const code = parts[i];
6412
+ changes.push({
6413
+ path,
6414
+ status: code === "A" ? "added" : code === "D" ? "deleted" : "modified"
6415
+ });
6416
+ }
6417
+ return changes;
6418
+ },
6419
+ async file(rootPath) {
6420
+ const { repo } = await need();
6421
+ const name = await defaultName();
6422
+ if (name === null) throw new GitError("the default branch is not known");
6423
+ return blobAt(repo, await defaultRef(repo, name), rootPath);
6424
+ }
6425
+ },
6426
+ async openPr() {
6427
+ const f = await lookup();
6428
+ if (!f) return null;
6429
+ const branch = await currentBranch(f.repo);
6430
+ if (branch === null || branch === await defaultName()) return null;
6431
+ return findOpenPr(f.repo, branch, await gh());
6432
+ },
6433
+ async pullRequestTemplate() {
6434
+ const f = await lookup();
6435
+ if (!f) return null;
6436
+ const path = templatePath((await runGit(f.repo.top, [
6437
+ "ls-tree",
6438
+ "--name-only",
6439
+ "HEAD",
6440
+ "--",
6441
+ ".",
6442
+ ".github/",
6443
+ "docs/"
6444
+ ]).catch(() => "")).split("\n"));
6445
+ return path === null ? null : runGit(f.repo.top, ["show", `HEAD:${path}`]).catch(() => null);
6446
+ },
6447
+ async review(req, o) {
6448
+ if (req.target !== null) throw new ReviewRefused(400, "this server cannot add to an existing pull request");
6449
+ const { repo, steps } = await need();
6450
+ return localReview(steps, req, {
6451
+ ...o,
6452
+ findOpenPr: async (branch) => findOpenPr(repo, branch, await gh())
6453
+ });
6421
6454
  }
6422
- },
6423
- history: (t, extract, o) => recordHistory(t, extract, o),
6424
- fileDiff: (t, rev) => fileDiff(t, rev),
6425
- async openPr() {
6426
- const f = await lookup();
6427
- if (!f) return null;
6428
- const branch = await currentBranch(f.repo);
6429
- if (branch === null || branch === await defaultName()) return null;
6430
- return findOpenPr(f.repo, branch, await gh());
6431
- },
6432
- async pullRequestTemplate() {
6433
- const f = await lookup();
6434
- if (!f) return null;
6435
- const path = templatePath((await runGit(f.repo.top, [
6436
- "ls-tree",
6437
- "--name-only",
6438
- "HEAD",
6439
- "--",
6440
- ".",
6441
- ".github/",
6442
- "docs/"
6443
- ]).catch(() => "")).split("\n"));
6444
- return path === null ? null : runGit(f.repo.top, ["show", `HEAD:${path}`]).catch(() => null);
6445
- },
6446
- async review(req, o) {
6447
- if (req.target !== null) throw new ReviewRefused(400, "this server cannot add to an existing pull request");
6448
- const { repo, steps } = await need();
6449
- return localReview(steps, req, {
6450
- ...o,
6451
- findOpenPr: async (branch) => findOpenPr(repo, branch, await gh())
6452
- });
6453
6455
  }
6454
6456
  };
6455
6457
  }
@@ -7070,7 +7072,8 @@ function reviewBody(body) {
7070
7072
  const gitRoutes = (router, ctx) => {
7071
7073
  router.add("GET", "/api/git", async () => {
7072
7074
  const git = ctx.git;
7073
- if (!git || !await git.hasRemote()) return { git: null };
7075
+ const review = git?.review;
7076
+ if (!git || !review || !await review.available()) return { git: null };
7074
7077
  const status = await git.status();
7075
7078
  const changes = await Promise.all(status.changes.map(async (c) => ({
7076
7079
  path: c.path,
@@ -7078,18 +7081,18 @@ const gitRoutes = (router, ctx) => {
7078
7081
  ...summary(await recordChanges(git, ctx.root, ctx.y.tables, c.path))
7079
7082
  })));
7080
7083
  changes.sort((a, b) => a.path.localeCompare(b.path));
7081
- const defaultBranch = await git.defaultBranch();
7084
+ const defaultBranch = await review.defaultBranch();
7082
7085
  return { git: {
7083
7086
  branch: status.branch,
7084
7087
  defaultBranch,
7085
7088
  upstream: status.upstream,
7086
- namesBranch: git.namesBranch === true,
7087
- restoresDefault: git.defaultBranchFiles !== void 0 && status.branch !== null && defaultBranch !== null && status.branch !== defaultBranch,
7089
+ namesBranch: review.namesBranch === true,
7090
+ restoresDefault: review.defaultBranchFiles !== void 0 && status.branch !== null && defaultBranch !== null && status.branch !== defaultBranch,
7088
7091
  changes
7089
7092
  } };
7090
7093
  });
7091
7094
  router.add("GET", "/api/git/default", async () => {
7092
- const from = ctx.git?.defaultBranchFiles;
7095
+ const from = ctx.git?.review?.defaultBranchFiles;
7093
7096
  if (!from) throw new HttpError(404, "this host cannot read the default branch");
7094
7097
  const [changes, status] = await Promise.all([from.changes().catch(notFound), ctx.git.status()]);
7095
7098
  const unsent = new Set(status.changes.map((c) => c.path));
@@ -7101,7 +7104,7 @@ const gitRoutes = (router, ctx) => {
7101
7104
  })).sort((a, b) => a.path.localeCompare(b.path)) };
7102
7105
  });
7103
7106
  router.add("POST", "/api/git/restore-default", async ({ body }) => {
7104
- const from = ctx.git?.defaultBranchFiles;
7107
+ const from = ctx.git?.review?.defaultBranchFiles;
7105
7108
  if (!from) throw new HttpError(404, "this host cannot read the default branch");
7106
7109
  const paths = objectBody(body, "body").files;
7107
7110
  if (!Array.isArray(paths) || paths.length === 0 || paths.some((p) => typeof p !== "string")) throw new HttpError(400, "choose at least one file", { field: "files" });
@@ -7156,16 +7159,16 @@ const gitRoutes = (router, ctx) => {
7156
7159
  }) };
7157
7160
  });
7158
7161
  router.add("POST", "/api/git/review", async ({ body }) => {
7159
- const git = ctx.git;
7160
- if (!git || !await git.hasRemote()) throw new HttpError(404, "the data folder is not in a git repository with an origin");
7162
+ const review = ctx.git?.review;
7163
+ if (!review || !await review.available()) throw new HttpError(404, "the data folder is not in a git repository with an origin");
7161
7164
  const req = reviewBody(body);
7162
- if (req.branch !== void 0 && !git.namesBranch) throw new HttpError(400, "this host names the branch for a review itself", { field: "branch" });
7165
+ if (req.branch !== void 0 && !review.namesBranch) throw new HttpError(400, "this host names the branch for a review itself", { field: "branch" });
7163
7166
  const target = objectBody(body, "body").target;
7164
7167
  if (target !== void 0 && target !== null && typeof target !== "string") throw new HttpError(400, "target must be a branch name or null", { field: "target" });
7165
7168
  return ctx.proposals.exclusive(async () => {
7166
7169
  assertSynced(await ctx.y.sync(), "could not write the latest edits to files for", "; nothing was sent");
7167
7170
  try {
7168
- return await git.review({
7171
+ return await review.review({
7169
7172
  ...req,
7170
7173
  target: target ?? null
7171
7174
  }, { afterTreeChange: async () => assertSynced(await ctx.y.sync(), "the database could not follow the files for") });
@@ -7179,7 +7182,7 @@ const gitRoutes = (router, ctx) => {
7179
7182
  router.add("GET", "/api/git/pr", async () => {
7180
7183
  const git = ctx.git;
7181
7184
  if (!git) throw new HttpError(404, "the data folder is not in a git repository");
7182
- return { url: await git.openPr?.().catch(notFound) ?? null };
7185
+ return { url: await git.review?.openPr?.().catch(notFound) ?? null };
7183
7186
  });
7184
7187
  router.add("POST", "/api/git/review/draft", async ({ body, signal }) => {
7185
7188
  const git = ctx.git;
@@ -7214,7 +7217,7 @@ const gitRoutes = (router, ctx) => {
7214
7217
  after: shownFile(join(ctx.root, path))
7215
7218
  };
7216
7219
  }));
7217
- const template = b.mode === "pr" ? await git.pullRequestTemplate?.() ?? null : null;
7220
+ const template = b.mode === "pr" ? await git.review?.pullRequestTemplate?.() ?? null : null;
7218
7221
  const release = ctx.agent.pageSlot();
7219
7222
  try {
7220
7223
  return await draftReview(languageModel, {
@@ -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-BM2e03Dm.mjs";
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";
2
2
  import { dirname, relative, resolve, sep } from "node:path";
3
3
  import { readFileSync } from "node:fs";
4
4
  import { randomBytes } from "node:crypto";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yamlite",
3
- "version": "0.43.1",
3
+ "version": "0.44.0",
4
4
  "description": "Sync YAML files and SQLite in both directions",
5
5
  "keywords": [
6
6
  "cli",