@vite-hub/workspace 0.1.0 → 0.3.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.
Files changed (134) hide show
  1. package/README.md +164 -107
  2. package/dist/abort-BCwpdrN0.js +32 -0
  3. package/dist/blob-database.d.ts +70 -117
  4. package/dist/blob-database.js +48 -41
  5. package/dist/checkout.d.ts +128 -0
  6. package/dist/checkout.js +849 -0
  7. package/dist/cloudflare.d.ts +2 -2
  8. package/dist/cloudflare.js +1 -1
  9. package/dist/config-B-863EgC.js +15 -0
  10. package/dist/{config-B7dmzDX3.js → config-BAgL2dtB.js} +48 -84
  11. package/dist/{config-DLKdaFWN.d.ts → config-BQKcPawI.d.ts} +1 -1
  12. package/dist/discard-CNNtCozM.js +8 -0
  13. package/dist/durability.d.ts +22 -0
  14. package/dist/durability.js +70 -0
  15. package/dist/error-diagnostics-CtKjGtGb.js +188 -0
  16. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  17. package/dist/file-2pFYNtsU.js +22 -0
  18. package/dist/{files-C7Px8uaC.js → files-BOo4SbwE.js} +2 -2
  19. package/dist/files.d.ts +38 -0
  20. package/dist/files.js +6 -0
  21. package/dist/{github-CPxHtFB7.js → github-CrYp4v8k.js} +32 -5
  22. package/dist/{glob--XcLlcml.js → glob-B8YGvTrZ.js} +4 -5
  23. package/dist/{glob--kNYDbfU.js → glob-Cjxms1t7.js} +1 -1
  24. package/dist/{host-CFnrTXTK.js → host-BFBpXn0N.js} +58 -47
  25. package/dist/{hosted-acMA5XyL.js → hosted-KcUR_jPv.js} +216 -93
  26. package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
  27. package/dist/hosted-vercel-blob.d.ts +2 -2
  28. package/dist/hosted-vercel-blob.js +1 -1
  29. package/dist/hosted.d.ts +5 -3
  30. package/dist/hosted.js +2 -2
  31. package/dist/index.d.ts +9 -51
  32. package/dist/index.js +21 -91
  33. package/dist/{lifecycle-BwZ7c9hb.js → lifecycle-B-enk_4A.js} +8 -8
  34. package/dist/lineage.d.ts +26 -0
  35. package/dist/lineage.js +76 -0
  36. package/dist/loader.d.ts +1 -1
  37. package/dist/loader.js +2 -2
  38. package/dist/{mcp-resources-BREFCmtn.js → mcp-resources-DF0F5rcL.js} +2 -2
  39. package/dist/{memory-BbwOqDXl.js → memory-BOexthyW.js} +3 -4
  40. package/dist/{metadata-target-DZEZQGHA.js → metadata-target-CWz6KHKq.js} +17 -16
  41. package/dist/object-Da1zyPCR.js +11 -0
  42. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  43. package/dist/operations-C6FpR8Rr.js +389 -0
  44. package/dist/operations-CE2drFih.js +1234 -0
  45. package/dist/operations.d.ts +41 -4
  46. package/dist/operations.js +3 -2
  47. package/dist/{path-CNAwN7pw.js → path--wrT_Azm.js} +2 -3
  48. package/dist/path-AxMho1wo.d.ts +7 -0
  49. package/dist/{plugins-DqQ8b4T5.d.ts → plugins-C8C0auoW.d.ts} +1 -1
  50. package/dist/{provider-kXjfli9u.js → provider-9s4Ufkm5.js} +104 -82
  51. package/dist/providers/github/store.d.ts +1 -1
  52. package/dist/providers/github/store.js +1 -1
  53. package/dist/registry-B3BBm4Ts.d.ts +19 -0
  54. package/dist/{registry-Bp-8UUfG.js → registry-CNphafBx.js} +55 -20
  55. package/dist/registry-CYNN623b.d.ts +9 -0
  56. package/dist/request-scope-Dw5n8bMC.js +83 -0
  57. package/dist/results-DgkZUmTL.js +8 -0
  58. package/dist/{rolldown-runtime-B4iAMlE-.js → rolldown-runtime-rQ84J-ij.js} +2 -3
  59. package/dist/runtime/assets.d.ts +1 -1
  60. package/dist/runtime/assets.js +3 -3
  61. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  62. package/dist/runtime/empty-registry.d.ts +2 -1
  63. package/dist/runtime/registry.d.ts +2 -0
  64. package/dist/runtime/registry.js +23 -0
  65. package/dist/runtime/request.d.ts +4 -0
  66. package/dist/runtime/request.js +8 -0
  67. package/dist/runtime/state.d.ts +5 -4
  68. package/dist/runtime/state.js +8 -18
  69. package/dist/runtime/workspace.d.ts +1 -1
  70. package/dist/runtime/workspace.js +1 -1
  71. package/dist/runtime.d.ts +9 -8
  72. package/dist/runtime.js +23 -26
  73. package/dist/{search-CrTmXj5h.js → search-C_RfoM2j.js} +2 -2
  74. package/dist/{server-BNQ-Nbjj.js → server-8tGltlGz.js} +53 -40
  75. package/dist/server.d.ts +17 -8
  76. package/dist/server.js +1 -1
  77. package/dist/shared-B3_EUk89.js +848 -0
  78. package/dist/source-metadata.d.ts +6 -2
  79. package/dist/source-metadata.js +8 -8
  80. package/dist/state-BISnUf1s.d.ts +35 -0
  81. package/dist/{ai-BZyLwULx.js → state-DbrW-njQ.js} +96 -54
  82. package/dist/{store-CXgmu-uw.js → store-ybhyD38Z.js} +250 -106
  83. package/dist/{sync-CN6ec-5M.js → sync-CCD_VYC8.js} +4 -4
  84. package/dist/target-jWhTdIuF.js +89 -0
  85. package/dist/test.d.ts +1 -1
  86. package/dist/test.js +1 -1
  87. package/dist/{types-DeK9GIxy.d.ts → types-BbtwmBZ5.d.ts} +68 -14
  88. package/dist/use-C6lV3-wC.d.ts +321 -0
  89. package/dist/{use-BQj7nSz6.js → use-CSpT5W87.js} +75 -82
  90. package/dist/{utils-Blrh4N2n.js → utils-CgMZCHsX.js} +112 -41
  91. package/dist/vite.d.ts +585 -2
  92. package/dist/vite.js +21368 -1
  93. package/dist/{workspace-BWJQBK1u.d.ts → workspace-CYB2xZ1T.d.ts} +1 -1
  94. package/dist/{workspace-6pxkOuxr.js → workspace-sPWn2Jxj.js} +125 -40
  95. package/package.json +46 -55
  96. package/dist/ai-BW2ZhizI.d.ts +0 -177
  97. package/dist/ai.d.ts +0 -3
  98. package/dist/ai.js +0 -2
  99. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +0 -19
  100. package/dist/error-diagnostics-A_8Kp-48.js +0 -116
  101. package/dist/error-diagnostics-DY5GP47p.js +0 -96
  102. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +0 -354
  103. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +0 -214
  104. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +0 -527
  105. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +0 -248
  106. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +0 -179
  107. package/dist/file-C0_aPWSS.js +0 -26
  108. package/dist/file-metadata-CxDy-E2H.js +0 -58
  109. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +0 -2278
  110. package/dist/github-DtncTfmv-Du2S8lGF.js +0 -4159
  111. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +0 -2530
  112. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +0 -489
  113. package/dist/hosted-vercel-blob-DKntsHaf.js +0 -12603
  114. package/dist/inspect-BoObD2cJ.js +0 -167
  115. package/dist/mountx.d.ts +0 -8
  116. package/dist/mountx.js +0 -145
  117. package/dist/nitro.d.ts +0 -2
  118. package/dist/nitro.js +0 -2
  119. package/dist/nuxt.d.ts +0 -27
  120. package/dist/nuxt.js +0 -38
  121. package/dist/operations-BcpWr41m.js +0 -159
  122. package/dist/operations-CGqY1XeG.js +0 -965
  123. package/dist/operations-DnOwKsJT.d.ts +0 -136
  124. package/dist/registry-Cg1TJVVZ.d.ts +0 -10
  125. package/dist/request-execution-Dk9rY-Yh.js +0 -84
  126. package/dist/shared-DalXdP0i.js +0 -2158
  127. package/dist/state-B8zbLi5t.d.ts +0 -26
  128. package/dist/target-D4Bqb1eH.js +0 -11
  129. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +0 -125
  130. package/dist/token-CO62GglH.js +0 -61
  131. package/dist/use-DhwhbAVV.d.ts +0 -108
  132. package/dist/vite-BEvgU2GY.js +0 -20909
  133. package/dist/vite-CcZmMQ7S.d.ts +0 -476
  134. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +0 -1565
@@ -1,13 +1,11 @@
1
+ import { n as forkMemoryWorkspaceStore, r as vitehubOwnedPrefix, t as createMemoryWorkspaceStore } from "./memory-BOexthyW.js";
1
2
  import { s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
2
- import { a as isExcludedWorkspacePath, f as sha256, i as decodeFile, o as isWorkspaceBytes, r as contentToBytes } from "./path-CNAwN7pw.js";
3
- import { r as workspaceStoreTarget } from "./target-D4Bqb1eH.js";
4
- import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
5
- import { n as forkMemoryWorkspaceStore, r as vitehubOwnedPrefix, t as createMemoryWorkspaceStore } from "./memory-BbwOqDXl.js";
6
- import { n as copyJsonWorkspaceMetadata, t as copyJsonFileMetadata } from "./file-metadata-CxDy-E2H.js";
7
- import { d as normalizeHistoryRef, l as historyConflict, n as createSnapshotFromEntries, p as validateHistoryMessage, r as diffSnapshots, u as normalizeHistoryPath } from "./utils-Blrh4N2n.js";
8
- import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
9
- import { ViteHubError } from "@vite-hub/runtime";
3
+ import { o as copyJsonFileMetadata, r as workspaceStoreTarget, s as copyJsonWorkspaceMetadata } from "./target-jWhTdIuF.js";
4
+ import { a as isExcludedWorkspacePath, f as sha256, i as decodeFile, o as isWorkspaceBytes, r as contentToBytes } from "./path--wrT_Azm.js";
5
+ import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CtKjGtGb.js";
6
+ import { d as normalizeHistoryRef, l as historyConflict, n as createSnapshotFromEntries, p as validateHistoryMessage, r as diffSnapshots, u as normalizeHistoryPath } from "./utils-CgMZCHsX.js";
10
7
  import { and, desc, eq, inArray, isNotNull, lt, sql } from "drizzle-orm";
8
+ import { ViteHubError } from "@vite-hub/runtime";
11
9
  import { index, integer, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
12
10
  /** Include these tables in a Database Definition and apply its migrations. */
13
11
  const workspaceHistorySchema = {
@@ -70,9 +68,10 @@ var ContentAddressedWorkspaceStore = class {
70
68
  #dirty = false;
71
69
  #baseline;
72
70
  #queue = Promise.resolve();
71
+ #database;
73
72
  constructor(options) {
74
73
  this.options = options;
75
- if (!hasRuntimeType(options.workspace, "string") || !options.workspace) throw workspaceError("[vitehub] Blob + Database Store requires a workspace identity.");
74
+ if (typeof options.workspace !== "string" || !options.workspace) throw workspaceError("[vitehub] Blob + Database Store requires a workspace identity.");
76
75
  if (options.prefix !== void 0 && !/^[a-zA-Z0-9_-]+(?:\/[a-zA-Z0-9_-]+)*$/.test(options.prefix)) throw workspaceError("[vitehub] History Blob prefix must contain only letters, numbers, underscores, dashes, and single slashes.");
77
76
  const root = `${vitehubOwnedPrefix}workspace-history`;
78
77
  const prefix = options.prefix === void 0 ? root : `${root}/${options.prefix}`;
@@ -87,9 +86,16 @@ var ContentAddressedWorkspaceStore = class {
87
86
  return {
88
87
  provider: "blob-database",
89
88
  workspace: this.options.workspace,
90
- database: this.options.database
89
+ database: this.#db
91
90
  };
92
91
  }
92
+ get #db() {
93
+ if (this.#database) return this.#database;
94
+ const { database } = this.options;
95
+ const resolved = typeof database === "function" ? database() : database;
96
+ if (typeof resolved?.batch !== "function") throw workspaceErrorDiagnostics.WORKSPACE_R0077({ message: `[vitehub] The \`database\` of the Blob + Database Store for workspace "${this.options.workspace}" is not a Drizzle database.` });
97
+ return this.#database = resolved;
98
+ }
93
99
  history = {
94
100
  head: async (options) => await this.#head(normalizeHistoryRef(options?.ref)),
95
101
  list: async (options) => await this.#listHistory(options),
@@ -97,7 +103,7 @@ var ContentAddressedWorkspaceStore = class {
97
103
  open: async (id) => await this.#open(id),
98
104
  usage: async () => {
99
105
  const workspace = await this.#key();
100
- const [result] = await this.options.database.values(sql`
106
+ const [result] = await this.#db.values(sql`
101
107
  select coalesce(sum(size), 0) as bytes, count(*) as objects from (
102
108
  select distinct json_extract(file.value, '$.digest') as digest,
103
109
  json_extract(file.value, '$.size') as size
@@ -123,10 +129,10 @@ var ContentAddressedWorkspaceStore = class {
123
129
  };
124
130
  async #key() {
125
131
  const candidates = await this.#namespace;
126
- this.#ready ??= this.options.database.batch([
127
- this.options.database.select({ workspace: workspaces.workspace }).from(workspaces).where(eq(workspaces.workspace, candidates[0])),
128
- this.options.database.select({ workspace: workspaces.workspace }).from(workspaces).where(eq(workspaces.workspace, candidates[1] ?? candidates[0])),
129
- this.options.database.insert(workspaces).select(sql`
132
+ this.#ready ??= this.#db.batch([
133
+ this.#db.select({ workspace: workspaces.workspace }).from(workspaces).where(eq(workspaces.workspace, candidates[0])),
134
+ this.#db.select({ workspace: workspaces.workspace }).from(workspaces).where(eq(workspaces.workspace, candidates[1] ?? candidates[0])),
135
+ this.#db.insert(workspaces).select(sql`
130
136
  select ${candidates[0]}, 0
131
137
  where not exists (
132
138
  select 1 from ${workspaces} where ${workspaces.workspace} = ${candidates[1] ?? candidates[0]}
@@ -146,12 +152,12 @@ var ContentAddressedWorkspaceStore = class {
146
152
  }
147
153
  async #isDeleted() {
148
154
  const workspace = await this.#key();
149
- const [row] = await this.options.database.select({ deleted: workspaces.deleted }).from(workspaces).where(eq(workspaces.workspace, workspace));
155
+ const [row] = await this.#db.select({ deleted: workspaces.deleted }).from(workspaces).where(eq(workspaces.workspace, workspace));
150
156
  if (!row) throw workspaceError("[vitehub] Workspace history identity is missing.");
151
157
  return row.deleted;
152
158
  }
153
159
  async #ref(workspace, ref) {
154
- const [row] = await this.options.database.select().from(refs).where(and(eq(refs.workspace, workspace), eq(refs.ref, ref), this.#active(workspace)));
160
+ const [row] = await this.#db.select().from(refs).where(and(eq(refs.workspace, workspace), eq(refs.ref, ref), this.#active(workspace)));
155
161
  return row;
156
162
  }
157
163
  async #head(ref) {
@@ -161,12 +167,12 @@ var ContentAddressedWorkspaceStore = class {
161
167
  }
162
168
  async #refs() {
163
169
  const workspace = await this.#key();
164
- const heads = await this.options.database.select({
170
+ const heads = await this.#db.select({
165
171
  ref: refs.ref,
166
172
  head: refs.head
167
173
  }).from(refs).where(and(eq(refs.workspace, workspace), isNotNull(refs.head), this.#active(workspace)));
168
174
  if (!heads.length) return [];
169
- const rows = await this.options.database.select().from(revisions).where(and(eq(revisions.workspace, workspace), eq(revisions.committed, true), inArray(revisions.id, heads.map((row) => row.head)), this.#active(workspace)));
175
+ const rows = await this.#db.select().from(revisions).where(and(eq(revisions.workspace, workspace), eq(revisions.committed, true), inArray(revisions.id, heads.map((row) => row.head)), this.#active(workspace)));
170
176
  const byId = new Map(rows.map((row) => [row.id, row]));
171
177
  return heads.flatMap(({ ref, head }) => {
172
178
  const row = byId.get(head);
@@ -184,7 +190,7 @@ var ContentAddressedWorkspaceStore = class {
184
190
  }
185
191
  async #revision(id) {
186
192
  const workspace = await this.#key();
187
- const [row] = await this.options.database.select().from(revisions).where(and(eq(revisions.workspace, workspace), eq(revisions.id, id), eq(revisions.committed, true), this.#active(workspace)));
193
+ const [row] = await this.#db.select().from(revisions).where(and(eq(revisions.workspace, workspace), eq(revisions.id, id), eq(revisions.committed, true), this.#active(workspace)));
188
194
  if (!row) throw new ViteHubError("WORKSPACE_NOT_FOUND", `[vitehub] Workspace revision does not exist: ${id}.`);
189
195
  return row;
190
196
  }
@@ -229,7 +235,7 @@ var ContentAddressedWorkspaceStore = class {
229
235
  and current_file.key is null
230
236
  )
231
237
  )`;
232
- const rows = await this.options.database.select().from(revisions).where(and(eq(revisions.workspace, workspace), eq(revisions.ref, ref), eq(revisions.committed, true), cursor ? lt(revisions.sequence, cursor.sequence) : void 0, pathFilter, this.#active(workspace))).orderBy(desc(revisions.sequence)).limit(limit + 1);
238
+ const rows = await this.#db.select().from(revisions).where(and(eq(revisions.workspace, workspace), eq(revisions.ref, ref), eq(revisions.committed, true), cursor ? lt(revisions.sequence, cursor.sequence) : void 0, pathFilter, this.#active(workspace))).orderBy(desc(revisions.sequence)).limit(limit + 1);
233
239
  const result = { revisions: rows.slice(0, limit).map(publicRevision) };
234
240
  if (rows.length > limit) result.cursor = rows[limit - 1].id;
235
241
  return result;
@@ -294,7 +300,7 @@ var ContentAddressedWorkspaceStore = class {
294
300
  const ref = normalizeHistoryRef(options.ref);
295
301
  if (options.files === void 0 === (options.changes === void 0)) throw workspaceError("[vitehub] History commit requires exactly one of files or changes.");
296
302
  const expectedHeads = Object.entries(options.ifHeads ?? {}).map(([name, head]) => {
297
- if (head !== null && (!hasRuntimeType(head, "string") || !head)) throw workspaceError("[vitehub] History ifHeads values must be revision ids or null.");
303
+ if (head !== null && (typeof head !== "string" || !head)) throw workspaceError("[vitehub] History ifHeads values must be revision ids or null.");
298
304
  return [normalizeHistoryRef(name), head];
299
305
  });
300
306
  const workspace = await this.#key();
@@ -316,7 +322,7 @@ var ContentAddressedWorkspaceStore = class {
316
322
  const normalized = normalizeHistoryPath(path);
317
323
  if (puts.has(normalized) || removed.has(normalized)) throw workspaceError(`[vitehub] Duplicate history file path: ${normalized}.`);
318
324
  puts.add(normalized);
319
- if (!hasRuntimeType(file.content, "string") && !isWorkspaceBytes(file.content)) throw workspaceError(`[vitehub] Invalid history file content: ${normalized}.`);
325
+ if (typeof file.content !== "string" && !isWorkspaceBytes(file.content)) throw workspaceError(`[vitehub] Invalid history file content: ${normalized}.`);
320
326
  const bytes = new Uint8Array(contentToBytes(file.content));
321
327
  const digest = await sha256(bytes);
322
328
  const entry = {
@@ -347,7 +353,7 @@ var ContentAddressedWorkspaceStore = class {
347
353
  digest,
348
354
  size: bytes.byteLength
349
355
  }));
350
- await this.options.database.insert(objects).select(sql`
356
+ await this.#db.insert(objects).select(sql`
351
357
  select ${workspaces.workspace}, json_extract(object.value, '$.digest'), json_extract(object.value, '$.size')
352
358
  from ${workspaces}, json_each(${JSON.stringify(registry)}) as object
353
359
  where ${workspaces.workspace} = ${workspace} and ${workspaces.deleted} = 0
@@ -387,22 +393,22 @@ var ContentAddressedWorkspaceStore = class {
387
393
  bytes: Object.values(sorted).reduce((total, entry) => total + entry.size, 0)
388
394
  };
389
395
  expectedHeads.map(([name, head]) => sql`(select expected.head from ${refs} as expected where expected.workspace = ${workspace} and expected.ref = ${name}) is ${head}`);
390
- const [, , changed] = await this.options.database.batch([
391
- this.options.database.insert(refs).select(sql`
396
+ const [, , changed] = await this.#db.batch([
397
+ this.#db.insert(refs).select(sql`
392
398
  select ${workspaces.workspace}, ${ref}, null, 0
393
399
  from ${workspaces} where ${workspaces.workspace} = ${workspace} and ${workspaces.deleted} = 0
394
400
  `).onConflictDoNothing(),
395
- this.options.database.insert(revisions).select(sql`
401
+ this.#db.insert(revisions).select(sql`
396
402
  select ${row.workspace}, ${row.id}, ${row.ref}, ${row.parentId}, ${row.sequence}, ${row.createdAt},
397
403
  ${row.message}, ${row.metadata === null ? null : JSON.stringify(row.metadata)},
398
404
  ${row.files}, ${row.bytes}, ${JSON.stringify(row.entries)}, 0
399
405
  from ${workspaces} where ${workspaces.workspace} = ${workspace} and ${workspaces.deleted} = 0
400
406
  `).onConflictDoNothing(),
401
- this.options.database.update(refs).set({
407
+ this.#db.update(refs).set({
402
408
  head: id,
403
409
  sequence: sql`${refs.sequence} + 1`
404
410
  }).where(and(eq(refs.workspace, workspace), eq(refs.ref, ref), sql`${refs.head} is ${options.ifHead}`, ...Object.entries(options.ifHeads ?? {}).map(([expectedRef, expectedHead]) => expectedHead === null ? sql`(not exists (select 1 from ${refs} as cross_ref where cross_ref.workspace = ${workspace} and cross_ref.ref = ${expectedRef}) or exists (select 1 from ${refs} as cross_ref where cross_ref.workspace = ${workspace} and cross_ref.ref = ${expectedRef} and cross_ref.head is null))` : sql`exists (select 1 from ${refs} as cross_ref where cross_ref.workspace = ${workspace} and cross_ref.ref = ${expectedRef} and cross_ref.head is ${expectedHead})`), this.#active(workspace))).returning({ head: refs.head }),
405
- this.options.database.update(revisions).set({ committed: true }).where(and(eq(revisions.workspace, workspace), eq(revisions.id, id), sql`exists (select 1 from ${refs} where ${refs.workspace} = ${workspace} and ${refs.ref} = ${ref} and ${refs.head} = ${id})`, this.#active(workspace)))
411
+ this.#db.update(revisions).set({ committed: true }).where(and(eq(revisions.workspace, workspace), eq(revisions.id, id), sql`exists (select 1 from ${refs} where ${refs.workspace} = ${workspace} and ${refs.ref} = ${ref} and ${refs.head} = ${id})`, this.#active(workspace)))
406
412
  ]);
407
413
  if (!changed.length) {
408
414
  if (await this.#isDeleted()) this.#deleted();
@@ -425,7 +431,7 @@ var ContentAddressedWorkspaceStore = class {
425
431
  if (headError?.code === "BLOB_NOT_FOUND") return;
426
432
  if (headError) throw headError;
427
433
  if (!object) return;
428
- const [error] = await this.options.blob.del(key);
434
+ const [error] = await this.options.blob.delete(key);
429
435
  if (error && error.code !== "BLOB_NOT_FOUND") throw error;
430
436
  }
431
437
  async delete() {
@@ -433,8 +439,8 @@ var ContentAddressedWorkspaceStore = class {
433
439
  }
434
440
  async #delete() {
435
441
  const workspace = await this.#key();
436
- await this.options.database.batch([this.options.database.update(workspaces).set({ deleted: true }).where(eq(workspaces.workspace, workspace)), this.options.database.delete(refs).where(eq(refs.workspace, workspace))]);
437
- const catalog = await this.options.database.select().from(objects).where(eq(objects.workspace, workspace));
442
+ await this.#db.batch([this.#db.update(workspaces).set({ deleted: true }).where(eq(workspaces.workspace, workspace)), this.#db.delete(refs).where(eq(refs.workspace, workspace))]);
443
+ const catalog = await this.#db.select().from(objects).where(eq(objects.workspace, workspace));
438
444
  for (const object of catalog) await this.#removeObject(`${workspace}/sha256/${object.digest}`);
439
445
  let cursor;
440
446
  const cursors = /* @__PURE__ */ new Set();
@@ -452,13 +458,13 @@ var ContentAddressedWorkspaceStore = class {
452
458
  if (cursor) cursors.add(cursor);
453
459
  } while (cursor);
454
460
  for (let offset = 0; offset < remaining.length; offset += 1e3) {
455
- const [error] = await this.options.blob.del(remaining.slice(offset, offset + 1e3));
461
+ const [error] = await this.options.blob.delete(remaining.slice(offset, offset + 1e3));
456
462
  if (error) throw error;
457
463
  }
458
- await this.options.database.batch([
459
- this.options.database.delete(revisions).where(eq(revisions.workspace, workspace)),
460
- this.options.database.delete(objects).where(eq(objects.workspace, workspace)),
461
- this.options.database.delete(metadata).where(eq(metadata.workspace, workspace))
464
+ await this.#db.batch([
465
+ this.#db.delete(revisions).where(eq(revisions.workspace, workspace)),
466
+ this.#db.delete(objects).where(eq(objects.workspace, workspace)),
467
+ this.#db.delete(metadata).where(eq(metadata.workspace, workspace))
462
468
  ]);
463
469
  this.#draft = void 0;
464
470
  this.#dirty = false;
@@ -548,7 +554,8 @@ var ContentAddressedWorkspaceStore = class {
548
554
  const revision = await this.#commit({
549
555
  ifHead: draft.head?.id ?? null,
550
556
  files,
551
- message: options.name
557
+ message: options.name,
558
+ ...options.author ? { metadata: { author: options.author } } : {}
552
559
  });
553
560
  this.#dirty = false;
554
561
  this.#draft = void 0;
@@ -573,17 +580,17 @@ var ContentAddressedWorkspaceStore = class {
573
580
  }
574
581
  async getMeta(key) {
575
582
  const workspace = await this.#key();
576
- const [row] = await this.options.database.select().from(metadata).where(and(eq(metadata.workspace, workspace), eq(metadata.key, key), this.#active(workspace)));
583
+ const [row] = await this.#db.select().from(metadata).where(and(eq(metadata.workspace, workspace), eq(metadata.key, key), this.#active(workspace)));
577
584
  return row?.value;
578
585
  }
579
586
  async setMeta(key, value) {
580
587
  await this.#assertActive();
581
588
  const workspace = await this.#key();
582
589
  if (value === void 0) {
583
- await this.options.database.delete(metadata).where(and(eq(metadata.workspace, workspace), eq(metadata.key, key)));
590
+ await this.#db.delete(metadata).where(and(eq(metadata.workspace, workspace), eq(metadata.key, key)));
584
591
  return;
585
592
  }
586
- await this.options.database.insert(metadata).select(this.options.database.select({
593
+ await this.#db.insert(metadata).select(this.#db.select({
587
594
  workspace: sql`${workspace}`.as("workspace"),
588
595
  key: sql`${key}`.as("key"),
589
596
  value: sql`${JSON.stringify(value)}`.as("value")
@@ -0,0 +1,128 @@
1
+ import { WorkspaceStaleFile } from "./lineage.js";
2
+ //#region src/checkout.d.ts
3
+ /** The lock file at the project root. Commit it: it records the remote revision that each checkout folder matches. */
4
+ export declare const workspaceLockFile = "vitehub.lock";
5
+ /** Calls one operation of the app, as `callOperationFromCli()` does. Tests pass a direct call. */
6
+ export type WorkspaceCheckoutCall = (operation: string, input: unknown, remote: string | undefined) => Promise<{
7
+ ok: true;
8
+ value: unknown;
9
+ } | {
10
+ ok: false;
11
+ code?: string;
12
+ message: string;
13
+ fix?: string;
14
+ status?: number;
15
+ }>;
16
+ /** The code, message, and fix that the checkout commands print for a failure. */
17
+ export declare function checkoutFailure(error: unknown): {
18
+ code: string;
19
+ fix?: string;
20
+ message: string;
21
+ };
22
+ /** Line patterns shared by working-tree scans and Git index searches. */
23
+ export declare const conflictMarkerPatterns: string[];
24
+ /** True for a file or folder name that a checkout skips, such as `node_modules`, `.GIT`, or a leftover temporary file. */
25
+ export declare function ignoredName(name: string): boolean;
26
+ interface WorkspaceMergeResult {
27
+ text: string;
28
+ conflicts: number;
29
+ }
30
+ /**
31
+ * A three-way merge by line, as `git merge-file` does. A region that only one side changed takes that side. In a region
32
+ * that both sides changed, lines that each side replaced one for one merge line by line. Other lines that both sides
33
+ * changed in different ways get Git conflict markers, with the local lines first.
34
+ */
35
+ export declare function mergeText(base: string, local: string, remote: string, labels?: {
36
+ local: string;
37
+ remote: string;
38
+ }): WorkspaceMergeResult;
39
+ /** The absolute checkout folder of a lock `dir`. Fails unless it is a folder inside the project. */
40
+ export declare function folderOf(rootDir: string, dir: string): string;
41
+ /** Checks every existing path component inside the project before a checkout reads or writes it. */
42
+ export declare function assertNoSymlinks(rootDir: string, target: string): Promise<void>;
43
+ interface WorkspaceLocalChanges {
44
+ added: string[];
45
+ modified: string[];
46
+ deleted: string[];
47
+ /** Text files with conflict markers, and paths in `conflicts` of the lock. */
48
+ conflicted: string[];
49
+ }
50
+ /** What happened to one path in a pull. */
51
+ interface WorkspacePullFile {
52
+ path: string;
53
+ action: "added" | "updated" | "deleted" | "merged" | "conflict" | "kept";
54
+ /** Why a path was kept or conflicts, for the person who resolves it. */
55
+ note?: string;
56
+ }
57
+ export interface WorkspacePullResult {
58
+ workspace: string;
59
+ ref: string;
60
+ from: string | null;
61
+ head: string | null;
62
+ files: WorkspacePullFile[];
63
+ }
64
+ export interface WorkspacePushResult {
65
+ workspace: string;
66
+ ref: string;
67
+ /** The new head. Undefined when nothing changed locally. */
68
+ revision?: string;
69
+ pushed: string[];
70
+ pull: WorkspacePullResult;
71
+ /** The pull after the first push to a new ref that the remote started with the files of another ref. */
72
+ after?: WorkspacePullResult;
73
+ }
74
+ export interface WorkspaceStatus {
75
+ workspace: string;
76
+ dir: string;
77
+ ref: string;
78
+ remote?: string;
79
+ head: string | null;
80
+ local: WorkspaceLocalChanges;
81
+ /** Local derived files, such as translations, whose `derivedFrom` source changed or is gone. */
82
+ stale: WorkspaceStaleFile[];
83
+ /** Paths that changed on the remote ref since `head`. Set when the status asked the remote. */
84
+ remoteChanges?: Array<{
85
+ path: string;
86
+ change: "added" | "changed" | "deleted";
87
+ }>;
88
+ remoteHead?: string | null;
89
+ }
90
+ interface WorkspaceCheckoutContext {
91
+ call: WorkspaceCheckoutCall;
92
+ rootDir: string;
93
+ }
94
+ interface WorkspacePullOptions {
95
+ workspace?: string;
96
+ dir?: string;
97
+ ref?: string;
98
+ remote?: string;
99
+ /** Paths that take the remote version, also when you changed them. */
100
+ theirs?: string[];
101
+ }
102
+ /** Merges the remote changes into each checkout folder and updates the lock file. */
103
+ export declare function pullWorkspaces(context: WorkspaceCheckoutContext, options?: WorkspacePullOptions): Promise<WorkspacePullResult[]>;
104
+ interface WorkspacePushOptions {
105
+ workspace?: string;
106
+ message?: string;
107
+ /** Write files that someone else holds an edit lease on, such as a Content document open in the Console. */
108
+ overrideLease?: boolean;
109
+ }
110
+ /** Pulls, then commits the local changes of each checkout folder to its ref. Refuses while a conflict is open. */
111
+ export declare function pushWorkspaces(context: WorkspaceCheckoutContext, options?: WorkspacePushOptions): Promise<WorkspacePushResult[]>;
112
+ interface WorkspaceStatusOptions {
113
+ workspace?: string;
114
+ /** Also ask the remote which files changed since the last pull. */
115
+ remote?: boolean;
116
+ }
117
+ /** The local changes of each checkout folder, and with `remote`, the remote changes since the last pull. */
118
+ export declare function workspaceStatus(context: WorkspaceCheckoutContext, options?: WorkspaceStatusOptions): Promise<WorkspaceStatus[]>;
119
+ /** The state of one checkout as text: its ref and head, local changes and conflicts, and remote changes when read. */
120
+ export declare function formatWorkspaceStatus(status: WorkspaceStatus): string;
121
+ /**
122
+ * The local state of every checkout of `vitehub.lock`, without asking the remote, or undefined when the project has no
123
+ * lock file. `vitehub status` shows it.
124
+ */
125
+ export declare function localCheckoutStatus(rootDir: string): Promise<WorkspaceStatus[] | undefined>;
126
+ /** Marks conflicts without markers, such as binary files, as resolved: the local file is what the next push sends. */
127
+ export declare function resolveWorkspaceConflicts(rootDir: string, workspace: string, paths: readonly string[]): Promise<string[]>;
128
+ //#endregion