@volter/world-core 2.0.3 → 2.0.5

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.
@@ -614,7 +614,10 @@ async function contextFor(m, call, scope) {
614
614
  // a handler reading the body itself sees the adopted id too (the boundary's one resolution, below)
615
615
  if (body && typeof body === 'object' && !Array.isArray(body))
616
616
  body = adoptedInCall(m.service, body, root);
617
- const params = await boundaryParams(m, call, root);
617
+ // every read of the body is of a copy, so the handler's own `call.request` and the core's answer (`core()`) each
618
+ // still find it unread, whichever of them reads it first
619
+ const pristine = call.request.clone();
620
+ const params = await boundaryParams(m, { ...call, request: call.request.clone() }, root);
618
621
  const paths = expandPaths(m, params);
619
622
  return {
620
623
  call,
@@ -677,7 +680,7 @@ async function contextFor(m, call, scope) {
677
680
  sse: (events) => sse(m, events, call.operation.id),
678
681
  expand: (resource, body) => (paths.length ? expand(m, resource, body, paths, root) : body),
679
682
  at: (when) => contextFor(m, { ...call, request: new Request(call.request.url) }, { ...scope, clock: () => when }),
680
- core: async () => { const out = await serveCore(m, call, { ...scope, clock: () => at }); return 'served' in out ? out.served : undefined; },
683
+ core: async () => { const out = await serveCore(m, { ...call, request: pristine.clone() }, { ...scope, clock: () => at }); return 'served' in out ? out.served : undefined; },
681
684
  own: (row) => ownFields(row),
682
685
  };
683
686
  }
package/dist/src/head.js CHANGED
@@ -206,17 +206,28 @@ export async function performEntries(opts) {
206
206
  queues.set(key, run.catch(() => undefined));
207
207
  return run;
208
208
  }
209
- async function performNow(opts) {
210
- const { service, root } = opts;
209
+ /** The root a perform runs against: the sealed one, or — when the caller brings its own executor (a library holding
210
+ * the person's token in its own process) — the twin's root.json with no credential sealed at all. */
211
+ function performRoot(service, root, callerExecute) {
211
212
  const head = headOf(service, root);
212
- if (head.kind !== 'real')
213
+ if (head.kind === 'real')
214
+ return { sealed: head.root, vendor: vendorOf(head.root) };
215
+ const unsealed = callerExecute ? readRoot(service, root) : null;
216
+ if (!unsealed)
213
217
  throw new Error(`the ${service} twin has no root — nothing to perform against`);
214
- const vendor = vendorOf(head.root);
218
+ return { sealed: null, vendor: service };
219
+ }
220
+ async function performNow(opts) {
221
+ const { service, root } = opts;
222
+ const bound = performRoot(service, root, opts.execute !== undefined);
223
+ const vendor = bound.vendor;
215
224
  const adapters = opts.adapters ?? stateSystemFor(vendor) ?? stateSystemFor(service);
216
225
  if (!adapters?.perform)
217
226
  throw new Error(`the ${vendor} twin has no perform adapter — a protocol 2 pack names one in its descriptor and registers itself (registerPack)`);
218
- const execute = opts.execute ?? buildRemoteExecute(validateRemoteOrigin(head.root.url, { allowInsecureLoopback: true }), await openRootCredential(head.root, vendor), authStrategyFor(vendor), getPack(vendor)?.hosts, { custody: rootCustody(head.root, vendor) });
219
- const checks = opts.checks ?? (await loadChecks(worldRootOf(head.root)));
227
+ // the caller's executor, or the one built over the sealed credential; an unsealed root has no other
228
+ const execute = opts.execute ?? buildRemoteExecute(validateRemoteOrigin(bound.sealed.url, { allowInsecureLoopback: true }), await openRootCredential(bound.sealed, vendor), authStrategyFor(vendor), getPack(vendor)?.hosts, { custody: rootCustody(bound.sealed, vendor) });
229
+ // an unsealed root's World is where its state resolves (the root given, PROJECT_ROOT, or the working directory)
230
+ const checks = opts.checks ?? (await loadChecks(bound.sealed ? worldRootOf(bound.sealed) : worldPaths(service, root).root));
220
231
  const deployable = deployableEntries(service, root);
221
232
  const entries = opts.actionIds === undefined ? deployable : opts.actionIds.map((id) => deployable.find((a) => a.id === id)).filter((a) => a !== undefined);
222
233
  const report = { pushed: 0, deployed: [], skipped: [], replayed: [] };
@@ -244,7 +255,7 @@ async function performNow(opts) {
244
255
  // a declared reference to an adopted id is resolved before the pack sees the entry: the vendor is
245
256
  // asked about #7, never the local #3 (docs/contributing/architecture.md#alias-aware-lookup-at-the-request-boundary)
246
257
  const fields = resolveReferences(service, action.subject.type, action.fields ?? {}, aliasesFrom(parentEntries(service, root)));
247
- const outcome = await adapters.perform(execute, fields === action.fields ? action : { ...action, fields }, performContext(service, root, rootCredentialFingerprint(head.root)));
258
+ const outcome = await adapters.perform(execute, fields === action.fields ? action : { ...action, fields }, performContext(service, root, bound.sealed ? rootCredentialFingerprint(bound.sealed) : undefined));
248
259
  // the vendor's answer, when the adapter returned one as fields, is what the landed copy holds
249
260
  const answered = outcome.data !== null && typeof outcome.data === 'object' && !Array.isArray(outcome.data) ? outcome.data : {};
250
261
  confirmAction({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/world-core",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "The kernel of Volter World: one log per twin, branches as pointers, checkpoints, the fold that keeps a twin current, the head that performs a write against the vendor, references, and the git plane. A twin package builds on it; the runtime serves it.",
5
5
  "keywords": [
6
6
  "twin",
@@ -851,7 +851,10 @@ async function contextFor(m: DerivedManifest, call: DerivedCall, scope: CoreScop
851
851
  try { body = text ? JSON.parse(text) : undefined; } catch { body = text; }
852
852
  // a handler reading the body itself sees the adopted id too (the boundary's one resolution, below)
853
853
  if (body && typeof body === 'object' && !Array.isArray(body)) body = adoptedInCall(m.service, body as Record<string, unknown>, root);
854
- const params = await boundaryParams(m, call, root);
854
+ // every read of the body is of a copy, so the handler's own `call.request` and the core's answer (`core()`) each
855
+ // still find it unread, whichever of them reads it first
856
+ const pristine = call.request.clone();
857
+ const params = await boundaryParams(m, { ...call, request: call.request.clone() }, root);
855
858
  const paths = expandPaths(m, params);
856
859
  return {
857
860
  call,
@@ -913,7 +916,7 @@ async function contextFor(m: DerivedManifest, call: DerivedCall, scope: CoreScop
913
916
  sse: (events) => sse(m, events, call.operation.id),
914
917
  expand: (resource, body) => (paths.length ? expand(m, resource, body, paths, root) : body),
915
918
  at: (when) => contextFor(m, { ...call, request: new Request(call.request.url) }, { ...scope, clock: () => when }),
916
- core: async () => { const out = await serveCore(m, call, { ...scope, clock: () => at }); return 'served' in out ? out.served : undefined; },
919
+ core: async () => { const out = await serveCore(m, { ...call, request: pristine.clone() }, { ...scope, clock: () => at }); return 'served' in out ? out.served : undefined; },
917
920
  own: (row) => ownFields(row as unknown as TwinResource),
918
921
  };
919
922
  }
package/src/head.ts CHANGED
@@ -229,15 +229,26 @@ export async function performEntries(opts: {
229
229
  return run;
230
230
  }
231
231
 
232
+ /** The root a perform runs against: the sealed one, or — when the caller brings its own executor (a library holding
233
+ * the person's token in its own process) — the twin's root.json with no credential sealed at all. */
234
+ function performRoot(service: string, root: string | undefined, callerExecute: boolean): { sealed: BoundRoot | null; vendor: string } {
235
+ const head = headOf(service, root);
236
+ if (head.kind === 'real') return { sealed: head.root, vendor: vendorOf(head.root) };
237
+ const unsealed = callerExecute ? readRoot(service, root) : null;
238
+ if (!unsealed) throw new Error(`the ${service} twin has no root — nothing to perform against`);
239
+ return { sealed: null, vendor: service };
240
+ }
241
+
232
242
  async function performNow(opts: Parameters<typeof performEntries>[0]): Promise<DeployReport> {
233
243
  const { service, root } = opts;
234
- const head = headOf(service, root);
235
- if (head.kind !== 'real') throw new Error(`the ${service} twin has no root — nothing to perform against`);
236
- const vendor = vendorOf(head.root);
244
+ const bound = performRoot(service, root, opts.execute !== undefined);
245
+ const vendor = bound.vendor;
237
246
  const adapters = opts.adapters ?? stateSystemFor(vendor) ?? stateSystemFor(service);
238
247
  if (!adapters?.perform) throw new Error(`the ${vendor} twin has no perform adapter — a protocol 2 pack names one in its descriptor and registers itself (registerPack)`);
239
- const execute = opts.execute ?? buildRemoteExecute(validateRemoteOrigin(head.root.url, { allowInsecureLoopback: true }), await openRootCredential(head.root, vendor), authStrategyFor(vendor), getPack(vendor)?.hosts, { custody: rootCustody(head.root, vendor) });
240
- const checks = opts.checks ?? (await loadChecks(worldRootOf(head.root)));
248
+ // the caller's executor, or the one built over the sealed credential; an unsealed root has no other
249
+ const execute = opts.execute ?? buildRemoteExecute(validateRemoteOrigin(bound.sealed!.url, { allowInsecureLoopback: true }), await openRootCredential(bound.sealed!, vendor), authStrategyFor(vendor), getPack(vendor)?.hosts, { custody: rootCustody(bound.sealed!, vendor) });
250
+ // an unsealed root's World is where its state resolves (the root given, PROJECT_ROOT, or the working directory)
251
+ const checks = opts.checks ?? (await loadChecks(bound.sealed ? worldRootOf(bound.sealed) : worldPaths(service, root).root));
241
252
  const deployable = deployableEntries(service, root);
242
253
  const entries = opts.actionIds === undefined ? deployable : opts.actionIds.map((id) => deployable.find((a) => a.id === id)).filter((a): a is TwinAction => a !== undefined);
243
254
  const report: DeployReport = { pushed: 0, deployed: [], skipped: [], replayed: [] };
@@ -260,7 +271,7 @@ async function performNow(opts: Parameters<typeof performEntries>[0]): Promise<D
260
271
  // a declared reference to an adopted id is resolved before the pack sees the entry: the vendor is
261
272
  // asked about #7, never the local #3 (docs/contributing/architecture.md#alias-aware-lookup-at-the-request-boundary)
262
273
  const fields = resolveReferences(service, action.subject.type, action.fields ?? {}, aliasesFrom(parentEntries(service, root)));
263
- const outcome = await adapters.perform(execute, fields === action.fields ? action : { ...action, fields }, performContext(service, root, rootCredentialFingerprint(head.root)));
274
+ const outcome = await adapters.perform(execute, fields === action.fields ? action : { ...action, fields }, performContext(service, root, bound.sealed ? rootCredentialFingerprint(bound.sealed) : undefined));
264
275
  // the vendor's answer, when the adapter returned one as fields, is what the landed copy holds
265
276
  const answered = outcome.data !== null && typeof outcome.data === 'object' && !Array.isArray(outcome.data) ? (outcome.data as Record<string, unknown>) : {};
266
277
  confirmAction({