@vite-hub/workspace 0.0.4 → 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 (137) hide show
  1. package/README.md +339 -115
  2. package/dist/abort-BCwpdrN0.js +32 -0
  3. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  4. package/dist/blob-database.d.ts +474 -0
  5. package/dist/blob-database.js +608 -0
  6. package/dist/checkout.d.ts +128 -0
  7. package/dist/checkout.js +849 -0
  8. package/dist/cloudflare.d.ts +6 -7
  9. package/dist/cloudflare.js +1 -1
  10. package/dist/config-B-863EgC.js +15 -0
  11. package/dist/config-BAgL2dtB.js +1076 -0
  12. package/dist/{config-DE9xlaIw.d.ts → config-BQKcPawI.d.ts} +1 -2
  13. package/dist/discard-CNNtCozM.js +8 -0
  14. package/dist/durability.d.ts +22 -0
  15. package/dist/durability.js +70 -0
  16. package/dist/error-diagnostics-CtKjGtGb.js +188 -0
  17. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  18. package/dist/file-2pFYNtsU.js +22 -0
  19. package/dist/{files-Q6xZjDHA.js → files-BOo4SbwE.js} +3 -3
  20. package/dist/files.d.ts +38 -0
  21. package/dist/files.js +6 -0
  22. package/dist/{github-DHnjxQIX.js → github-CrYp4v8k.js} +44 -24
  23. package/dist/glob-B8YGvTrZ.js +21 -0
  24. package/dist/glob-Cjxms1t7.js +30 -0
  25. package/dist/{host-DJH8cuoU.js → host-BFBpXn0N.js} +144 -77
  26. package/dist/{hosted-RPeJOCFz.js → hosted-KcUR_jPv.js} +303 -97
  27. package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
  28. package/dist/hosted-vercel-blob.d.ts +6 -7
  29. package/dist/hosted-vercel-blob.js +1 -1
  30. package/dist/hosted.d.ts +10 -9
  31. package/dist/hosted.js +2 -2
  32. package/dist/index.d.ts +26 -47
  33. package/dist/index.js +30 -100
  34. package/dist/internal/path.d.ts +2 -0
  35. package/dist/internal/path.js +2 -0
  36. package/dist/lifecycle-B-enk_4A.js +596 -0
  37. package/dist/lineage.d.ts +26 -0
  38. package/dist/lineage.js +76 -0
  39. package/dist/loader.d.ts +5 -6
  40. package/dist/loader.js +3 -2
  41. package/dist/mcp-resources-DF0F5rcL.js +39 -0
  42. package/dist/memory-BOexthyW.js +247 -0
  43. package/dist/metadata-target-CWz6KHKq.js +1589 -0
  44. package/dist/object-Da1zyPCR.js +11 -0
  45. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  46. package/dist/operations-C6FpR8Rr.js +389 -0
  47. package/dist/operations-CE2drFih.js +1234 -0
  48. package/dist/operations.d.ts +90 -0
  49. package/dist/operations.js +3 -0
  50. package/dist/path--wrT_Azm.js +113 -0
  51. package/dist/path-AxMho1wo.d.ts +7 -0
  52. package/dist/path-DrSIenjj.js +59 -0
  53. package/dist/path-zHxQUbqa.d.ts +9 -0
  54. package/dist/plugins-C8C0auoW.d.ts +10 -0
  55. package/dist/provider-9s4Ufkm5.js +1479 -0
  56. package/dist/providers/github/store.d.ts +3 -5
  57. package/dist/providers/github/store.js +1 -1
  58. package/dist/registry-B3BBm4Ts.d.ts +19 -0
  59. package/dist/{registry-D3yzt8HQ.js → registry-CNphafBx.js} +60 -23
  60. package/dist/registry-CYNN623b.d.ts +9 -0
  61. package/dist/request-scope-Dw5n8bMC.js +83 -0
  62. package/dist/results-DgkZUmTL.js +8 -0
  63. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-rQ84J-ij.js} +3 -4
  64. package/dist/runtime/assets.d.ts +3 -5
  65. package/dist/runtime/assets.js +7 -6
  66. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  67. package/dist/runtime/empty-registry.d.ts +2 -2
  68. package/dist/runtime/registry.d.ts +2 -0
  69. package/dist/runtime/registry.js +23 -0
  70. package/dist/runtime/request.d.ts +4 -0
  71. package/dist/runtime/request.js +8 -0
  72. package/dist/runtime/state.d.ts +5 -4
  73. package/dist/runtime/state.js +8 -18
  74. package/dist/runtime/workspace.d.ts +1 -1
  75. package/dist/runtime/workspace.js +1 -1
  76. package/dist/runtime.d.ts +52 -17
  77. package/dist/runtime.js +324 -67
  78. package/dist/{search-BpiCF2Tw.js → search-C_RfoM2j.js} +10 -9
  79. package/dist/server-8tGltlGz.js +303 -0
  80. package/dist/server.d.ts +36 -39
  81. package/dist/server.js +2 -328
  82. package/dist/shared-B3_EUk89.js +848 -0
  83. package/dist/source-metadata.d.ts +10 -7
  84. package/dist/source-metadata.js +12 -12
  85. package/dist/state-BISnUf1s.d.ts +35 -0
  86. package/dist/{ai-BqCC8BpY.js → state-DbrW-njQ.js} +237 -114
  87. package/dist/store-ybhyD38Z.js +1873 -0
  88. package/dist/{sync-DnTQwt8r.js → sync-CCD_VYC8.js} +61 -41
  89. package/dist/target-jWhTdIuF.js +89 -0
  90. package/dist/test.d.ts +1 -1
  91. package/dist/test.js +1 -1
  92. package/dist/{types-CYuwjJ4V.d.ts → types-BbtwmBZ5.d.ts} +321 -35
  93. package/dist/use-C6lV3-wC.d.ts +321 -0
  94. package/dist/{use-BTNDR5Rd.js → use-CSpT5W87.js} +141 -107
  95. package/dist/utils-CgMZCHsX.js +616 -0
  96. package/dist/vite.d.ts +585 -2
  97. package/dist/vite.js +21369 -2
  98. package/dist/workspace-CYB2xZ1T.d.ts +7 -0
  99. package/dist/{workspace-Dq08Yn72.js → workspace-sPWn2Jxj.js} +441 -225
  100. package/package.json +97 -72
  101. package/dist/ai-CjxvGqM0.d.ts +0 -162
  102. package/dist/ai.d.ts +0 -3
  103. package/dist/ai.js +0 -2
  104. package/dist/collections/client.d.ts +0 -39
  105. package/dist/collections/client.js +0 -137
  106. package/dist/collections.d.ts +0 -59
  107. package/dist/collections.js +0 -159
  108. package/dist/config-Bc3c4Su1.js +0 -7904
  109. package/dist/config-CHLLWklZ.js +0 -36
  110. package/dist/file-Bc1X7pco.js +0 -23
  111. package/dist/glob-CEZKeZFC.js +0 -18
  112. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  113. package/dist/lifecycle-LrL3sA4n.js +0 -316
  114. package/dist/metadata-target-B0tOmVW7.js +0 -717
  115. package/dist/mountx.d.ts +0 -10
  116. package/dist/mountx.js +0 -143
  117. package/dist/nitro.d.ts +0 -2
  118. package/dist/nitro.js +0 -2
  119. package/dist/nuxt.d.ts +0 -26
  120. package/dist/nuxt.js +0 -42
  121. package/dist/path-Cp59koVz.js +0 -139
  122. package/dist/provider-B1yLjCJJ.js +0 -746
  123. package/dist/publish.d.ts +0 -35
  124. package/dist/publish.js +0 -112
  125. package/dist/registry-Uj6IVxes.d.ts +0 -11
  126. package/dist/request-execution-B-dSFlGB.js +0 -84
  127. package/dist/runtime-options-BsPSv5O7.js +0 -13
  128. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  129. package/dist/shared-DTR1Hhma.js +0 -331
  130. package/dist/state-tYcRWEh2.d.ts +0 -26
  131. package/dist/store-Dt_Jyys3.js +0 -608
  132. package/dist/target-D4Bqb1eH.js +0 -11
  133. package/dist/token-CVzURBxC.js +0 -61
  134. package/dist/use-BiHzt0xA.d.ts +0 -103
  135. package/dist/vite-BptCrpv2.js +0 -4526
  136. package/dist/vite-CtA9guIM.d.ts +0 -66
  137. package/dist/workspace-Xddf4G1B.d.ts +0 -6
@@ -1,9 +1,11 @@
1
- import { _ as workspaceError, f as sha256, n as contentStreamToBytes } from "./path-Cp59koVz.js";
2
- import { a as normalizeWorkspaceSources, n as createSourceContext, s as sourceMountContainsPath, u as prepareWorkspaceSource } from "./config-Bc3c4Su1.js";
3
- import { c as workspaceSourceSyncStateEquals, o as readWorkspaceSourceSyncState, s as sourceSyncMetaKey } from "./workspace-Dq08Yn72.js";
4
- import { m as normalizeSourceItemPath } from "./metadata-target-B0tOmVW7.js";
1
+ import { s as workspaceError } from "./path-DrSIenjj.js";
2
+ import { f as sha256, n as contentStreamToBytes } from "./path--wrT_Azm.js";
3
+ import { d as sourceSyncPathClaims, f as workspaceSourceSyncStateEquals, l as readWorkspaceSourceSyncState, u as sourceSyncMetaKey } from "./workspace-sPWn2Jxj.js";
4
+ import { a as normalizeWorkspaceSources, f as prepareWorkspaceSource, n as createSourceContext, s as sourceMountContainsPath } from "./config-BAgL2dtB.js";
5
+ import { C as withWorkspaceStoreMutation, E as normalizeSourceFileMetadata, S as sourceMountOwnsPath, T as normalizeMetadataValue, w as normalizeSourceItemPath, x as createWorkspaceSourceMountAuthority } from "./metadata-target-CWz6KHKq.js";
5
6
  //#region src/sources/sync.ts
6
7
  const sourceSyncLocks = /* @__PURE__ */ new Map();
8
+ const sourceSyncGrants = createWorkspaceSourceMountAuthority("Source Sync");
7
9
  function zeroCounts() {
8
10
  return {
9
11
  added: 0,
@@ -51,7 +53,10 @@ function selectedSyncSources(definition, options) {
51
53
  if (options.sources === "all") return sources;
52
54
  return [...new Set(options.sources)].map((key) => {
53
55
  const source = sources.find((item) => item.key === key);
54
- if (!source) throw workspaceError(normalizeWorkspaceSources(definition.sources).some((item) => item.key === key) ? `[vitehub] Workspace source ${JSON.stringify(key)} is not configured for Source Sync. Add sync: true to the source binding.` : `[vitehub] Workspace source ${JSON.stringify(key)} does not exist.`);
56
+ if (!source) {
57
+ const defined = normalizeWorkspaceSources(definition.sources).some((item) => item.key === key);
58
+ throw workspaceError(defined ? `[vitehub] Workspace source ${JSON.stringify(key)} is not configured for Source Sync. Add sync: true to the source binding.` : `[vitehub] Workspace source ${JSON.stringify(key)} does not exist.`);
59
+ }
55
60
  return source;
56
61
  });
57
62
  }
@@ -68,7 +73,7 @@ async function shouldRemoveStalePath(store, path, metadata) {
68
73
  async function planSourceSync(definition, store, source) {
69
74
  const ctx = createSourceContext(definition, source);
70
75
  const [previousState, configHash, items] = await Promise.all([
71
- store.getMeta?.(sourceSyncMetaKey(source.key)).then(readWorkspaceSourceSyncState),
76
+ store.getMeta?.(sourceSyncMetaKey(source.key, definition.name)).then(readWorkspaceSourceSyncState),
72
77
  sourceConfigHash(source),
73
78
  getSourceItems(source, ctx)
74
79
  ]);
@@ -81,9 +86,14 @@ async function planSourceSync(definition, store, source) {
81
86
  if (nextPaths[path]) throw workspaceError(`[vitehub] Workspace Source Sync produced duplicate path: ${path}.`);
82
87
  const content = await contentFromItem(item);
83
88
  const digest = await sha256(content);
89
+ const metadata = normalizeSourceFileMetadata({
90
+ ...normalizeSourceFileMetadata(item.metadata || {}),
91
+ source: source.key,
92
+ sourcePath
93
+ });
84
94
  const existing = await store.readFile(path);
85
- const existingDigest = existing ? await sha256(existing.content) : void 0;
86
- const status = existing ? existingDigest === digest ? "unchanged" : "updated" : "added";
95
+ const unchanged = (existing ? await sha256(existing.content) : void 0) === digest && existing?.mediaType === item.mediaType && JSON.stringify(normalizeMetadataValue(existing?.metadata)) === JSON.stringify(normalizeMetadataValue(metadata));
96
+ const status = existing ? unchanged ? "unchanged" : "updated" : "added";
87
97
  countPath(counts, status);
88
98
  paths.push({
89
99
  path,
@@ -93,22 +103,23 @@ async function planSourceSync(definition, store, source) {
93
103
  nextPaths[path] = {
94
104
  digest,
95
105
  mediaType: item.mediaType,
106
+ mountPath: source.mountPath,
96
107
  sourcePath
97
108
  };
98
109
  files.push({
99
110
  path,
100
111
  content,
101
112
  mediaType: item.mediaType,
102
- metadata: {
103
- ...item.metadata,
104
- source: source.key,
105
- sourcePath
106
- }
113
+ metadata
107
114
  });
108
115
  }
109
116
  const removals = [];
110
- if (source.sync && source.sync.stale === "remove" && previousState) for (const [path, metadata] of Object.entries(previousState.paths)) {
117
+ if (source.sync && source.sync.stale === "remove" && previousState) for (const path of Object.keys(previousState.paths)) {
111
118
  if (nextPaths[path]) continue;
119
+ const claims = sourceSyncPathClaims(previousState, path);
120
+ const metadata = claims.find((claim) => claim.mountPath === source.mountPath);
121
+ if (!metadata || claims.length > 1) continue;
122
+ if (!sourceMountOwnsPath(source, path)) continue;
112
123
  if (!await shouldRemoveStalePath(store, path, metadata)) continue;
113
124
  const removal = {
114
125
  path,
@@ -119,28 +130,46 @@ async function planSourceSync(definition, store, source) {
119
130
  paths.push(removal);
120
131
  countPath(counts, "removed");
121
132
  }
122
- const nextState = {
123
- configHash,
124
- mountPath: source.mountPath,
125
- paths: nextPaths,
126
- source: source.key
127
- };
128
133
  return {
129
134
  counts,
130
135
  files,
131
- nextState,
136
+ nextState: {
137
+ configHash,
138
+ mountPath: source.mountPath,
139
+ paths: nextPaths,
140
+ source: source.key
141
+ },
132
142
  paths,
133
143
  removals,
134
144
  source,
135
- stateChanged: !workspaceSourceSyncStateEquals(previousState, nextState)
145
+ definitionName: definition.name
136
146
  };
137
147
  }
138
148
  async function applySourceSyncPlan(store, plan) {
139
- if (plan.source.mountPath) await store.mkdir(plan.source.mountPath, { recursive: true });
140
- for (const file of plan.files) await store.writeFile(file.path, file);
141
- for (const removal of plan.removals) await store.rm(removal.path, { force: true });
142
- await pruneEmptySourceDirectories(store, plan.source, plan.removals);
143
- if (plan.stateChanged) await store.setMeta?.(sourceSyncMetaKey(plan.source.key), plan.nextState);
149
+ const sourceStore = sourceSyncGrants.store(sourceSyncGrants.grant(plan.source), store);
150
+ const current = await store.getMeta?.(sourceSyncMetaKey(plan.source.key, plan.definitionName)).then(readWorkspaceSourceSyncState);
151
+ if (plan.source.mountPath) await sourceStore.mkdir(plan.source.mountPath, { recursive: true });
152
+ for (const file of plan.files) await sourceStore.writeFile(file.path, file);
153
+ for (const removal of plan.removals) await sourceStore.rm(removal.path, { force: true });
154
+ await pruneEmptySourceDirectories(sourceStore, plan.source, plan.removals);
155
+ const paths = {};
156
+ const claims = {};
157
+ for (const path of /* @__PURE__ */ new Set([...Object.keys(current?.paths ?? {}), ...Object.keys(plan.nextState.paths)])) {
158
+ const retained = current?.paths[path] ? sourceSyncPathClaims(current, path).filter((claim) => claim.mountPath !== plan.source.mountPath).map((claim) => ({ ...claim })) : [];
159
+ const next = plan.nextState.paths[path];
160
+ if (next) retained.push(next);
161
+ if (retained.length === 0) continue;
162
+ const digest = next?.digest ?? current.paths[path].digest;
163
+ for (const claim of retained) claim.digest = digest;
164
+ paths[path] = retained[retained.length - 1];
165
+ if (retained.length > 1) claims[path] = retained.sort((left, right) => left.mountPath.localeCompare(right.mountPath));
166
+ }
167
+ const nextState = {
168
+ ...plan.nextState,
169
+ paths
170
+ };
171
+ if (Object.keys(claims).length) nextState.claims = claims;
172
+ if (!workspaceSourceSyncStateEquals(current, nextState)) await store.setMeta?.(sourceSyncMetaKey(plan.source.key, plan.definitionName), nextState);
144
173
  }
145
174
  async function pruneEmptySourceDirectories(store, source, removals) {
146
175
  const directories = /* @__PURE__ */ new Set();
@@ -173,15 +202,10 @@ function statusFromPlan(plan, details) {
173
202
  status: "ready"
174
203
  };
175
204
  }
176
- async function snapshotSyncedWorkspace(definition, store, options) {
177
- if (!(!!options.snapshot || !!options.publish)) return;
205
+ async function snapshotSyncedWorkspace(store, options) {
206
+ if (!options.snapshot) return;
178
207
  const snapshotOptions = typeof options.snapshot === "object" ? options.snapshot : {};
179
- const snapshot = await store.snapshot(normalizeSnapshotOptions(snapshotOptions));
180
- if (options.publish) {
181
- const { publishWorkspaceSnapshot } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
182
- await publishWorkspaceSnapshot(definition, store, snapshot);
183
- }
184
- return snapshot;
208
+ return await store.snapshot(normalizeSnapshotOptions(snapshotOptions));
185
209
  }
186
210
  function normalizeSnapshotOptions(options) {
187
211
  if (!options || typeof options !== "object") return { name: "source-sync" };
@@ -203,7 +227,6 @@ async function syncWorkspaceSourcesUnlocked(definition, store, options, sources,
203
227
  }
204
228
  if (statuses.some((status) => status.status === "error") && !options.publishPartial) return {
205
229
  durationMs: Date.now() - started,
206
- published: false,
207
230
  sources: [...statuses, ...plans.map((plan) => ({
208
231
  counts: plan.counts,
209
232
  mountPath: plan.source.mountPath,
@@ -216,10 +239,9 @@ async function syncWorkspaceSourcesUnlocked(definition, store, options, sources,
216
239
  for (const plan of plans) await applySourceSyncPlan(store, plan);
217
240
  const planStatuses = plans.map((plan) => statusFromPlan(plan, options.details));
218
241
  const resultSources = [...statuses, ...planStatuses];
219
- const snapshot = resultStatus(resultSources) === "ready" || options.publishPartial && planStatuses.length > 0 ? await snapshotSyncedWorkspace(definition, store, options) : void 0;
242
+ const snapshot = resultStatus(resultSources) === "ready" || options.publishPartial && planStatuses.length > 0 ? await snapshotSyncedWorkspace(store, options) : void 0;
220
243
  return {
221
244
  durationMs: Date.now() - started,
222
- published: !!options.publish && !!snapshot,
223
245
  snapshot,
224
246
  sources: resultSources,
225
247
  status: resultStatus(resultSources)
@@ -232,7 +254,6 @@ async function syncWorkspaceSources(definition, store, options) {
232
254
  const sources = selectedSyncSources(definition, options);
233
255
  if (sources.length === 0) return {
234
256
  durationMs: 0,
235
- published: false,
236
257
  sources: [],
237
258
  status: "skipped"
238
259
  };
@@ -253,12 +274,11 @@ async function syncWorkspaceSources(definition, store, options) {
253
274
  }
254
275
  if (runnableSources.length === 0) return {
255
276
  durationMs: Date.now() - started,
256
- published: false,
257
277
  sources: statuses,
258
278
  status: resultStatus(statuses)
259
279
  };
260
280
  const lockKeys = runnableSources.map((source) => sourceLockKey(definition, source)).sort();
261
- const promise = syncWorkspaceSourcesUnlocked(definition, store, options, runnableSources, statuses, started);
281
+ const promise = withWorkspaceStoreMutation(store, () => syncWorkspaceSourcesUnlocked(definition, store, options, runnableSources, statuses, started));
262
282
  for (const key of lockKeys) sourceSyncLocks.set(key, promise);
263
283
  try {
264
284
  return await promise;
@@ -0,0 +1,89 @@
1
+ import { s as workspaceError } from "./path-DrSIenjj.js";
2
+ import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CtKjGtGb.js";
3
+ //#region src/core/file-metadata.ts
4
+ function invalidMetadata(path) {
5
+ return workspaceError(`[vitehub] Invalid Workspace metadata for ${path}. Metadata must contain only JSON-safe plain objects, dense arrays, strings, booleans, null, and finite numbers other than negative zero.`);
6
+ }
7
+ function copyJsonValue(path, value, ancestors, normalizeOptional = false) {
8
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
9
+ if (typeof value === "number" && Number.isFinite(value) && !Object.is(value, -0)) return value;
10
+ if (typeof value !== "object" || ancestors.has(value)) throw invalidMetadata(path);
11
+ const array = Array.isArray(value);
12
+ const prototype = Object.getPrototypeOf(value);
13
+ if (!array && prototype !== Object.prototype && prototype !== null) throw invalidMetadata(path);
14
+ ancestors.add(value);
15
+ try {
16
+ const descriptors = Object.getOwnPropertyDescriptors(value);
17
+ const keys = Reflect.ownKeys(descriptors).filter((key) => !array || key !== "length");
18
+ if (array && !normalizeOptional && keys.length !== descriptors.length?.value) throw invalidMetadata(path);
19
+ const copy = array ? [] : {};
20
+ for (const [index, key] of keys.entries()) {
21
+ if (typeof key !== "string" || array && (normalizeOptional ? !/^(0|[1-9]\d*)$/.test(key) || Number(key) >= descriptors.length?.value : key !== String(index))) throw invalidMetadata(path);
22
+ const descriptor = descriptors[key];
23
+ if (!descriptor.enumerable || !("value" in descriptor)) throw invalidMetadata(path);
24
+ if (normalizeOptional && descriptor.value === void 0 && !array) continue;
25
+ Object.defineProperty(copy, key, {
26
+ value: normalizeOptional && descriptor.value === void 0 ? null : copyJsonValue(path, descriptor.value, ancestors, normalizeOptional),
27
+ enumerable: true,
28
+ writable: true,
29
+ configurable: true
30
+ });
31
+ }
32
+ if (array && normalizeOptional) {
33
+ for (let index = 0; index < descriptors.length?.value; index++) if (!Object.hasOwn(copy, index)) Object.defineProperty(copy, index, {
34
+ value: null,
35
+ enumerable: true,
36
+ writable: true,
37
+ configurable: true
38
+ });
39
+ }
40
+ return copy;
41
+ } finally {
42
+ ancestors.delete(value);
43
+ }
44
+ }
45
+ function copyJsonWorkspaceMetadata(path, metadata, normalizeOptional = false) {
46
+ if (metadata === void 0) return;
47
+ let copy;
48
+ try {
49
+ if (typeof metadata === "object" && metadata !== null && !Array.isArray(metadata)) copy = copyJsonValue(path, metadata, /* @__PURE__ */ new Set(), normalizeOptional);
50
+ } catch {}
51
+ if (!copy) throw invalidMetadata(path);
52
+ return copy;
53
+ }
54
+ function copyJsonFileMetadata(path, metadata, normalizeOptional = false) {
55
+ const copy = copyJsonWorkspaceMetadata(path, metadata, normalizeOptional);
56
+ if (!copy) return;
57
+ const source = Object.getOwnPropertyDescriptor(copy, "source");
58
+ if (source && typeof source.value !== "string") throw workspaceError(`[vitehub] Invalid Workspace metadata for ${path}. metadata.source must be a string when provided.`);
59
+ return copy;
60
+ }
61
+ //#endregion
62
+ //#region src/core/rule-keys.ts
63
+ /** The rule fields that a more specific rule replaces only when it sets them. */
64
+ const cascadingRuleKeys = [
65
+ "commit",
66
+ "maxBytes",
67
+ "mediaType",
68
+ "write"
69
+ ];
70
+ const workspaceRuleKeys = /* @__PURE__ */ new Set([...cascadingRuleKeys, "validate"]);
71
+ /** Rejects rule keys that ViteHub does not enforce, such as `read`, so that a rule never looks like a protection it is not. */
72
+ function assertWorkspaceRules(rules) {
73
+ for (const [pattern, rule] of Object.entries(rules ?? {})) for (const key of Object.keys(rule ?? {})) {
74
+ if (key === "read") throw workspaceErrorDiagnostics.WORKSPACE_R0075({ message: `[vitehub] Workspace rule "${pattern}" sets read. Workspace rules do not limit reads.` });
75
+ if (!workspaceRuleKeys.has(key)) throw workspaceErrorDiagnostics.WORKSPACE_R0076({ message: `[vitehub] Workspace rule "${pattern}" does not support option "${key}".` });
76
+ }
77
+ }
78
+ //#endregion
79
+ //#region src/storage/target.ts
80
+ const workspaceStoreTarget = Symbol.for("vitehub.workspace.storeTarget");
81
+ function forwardWorkspaceStoreTarget(source, target) {
82
+ const resolveTarget = source[workspaceStoreTarget];
83
+ if (resolveTarget) target[workspaceStoreTarget] = resolveTarget.bind(source);
84
+ }
85
+ async function resolveWorkspaceStoreTarget(source) {
86
+ return await source[workspaceStoreTarget]?.();
87
+ }
88
+ //#endregion
89
+ export { cascadingRuleKeys as a, assertWorkspaceRules as i, resolveWorkspaceStoreTarget as n, copyJsonFileMetadata as o, workspaceStoreTarget as r, copyJsonWorkspaceMetadata as s, forwardWorkspaceStoreTarget as t };
package/dist/test.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as registerWorkspace } from "./registry-Uj6IVxes.js";
1
+ import { t as registerWorkspace } from "./registry-CYNN623b.js";
2
2
  export { registerWorkspace };
package/dist/test.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as registerWorkspace } from "./registry-D3yzt8HQ.js";
1
+ import { n as registerWorkspace } from "./registry-CNphafBx.js";
2
2
  export { registerWorkspace };