@volter/world-core 3.0.38 → 3.0.40

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 (179) hide show
  1. package/app-route.cjs +26 -25
  2. package/app-route.d.cts +1 -0
  3. package/dist/app-route.cjs +26 -25
  4. package/dist/app-route.d.cts +1 -0
  5. package/dist/generated/pack-facts.json +409 -352
  6. package/dist/inject.cjs +474 -95
  7. package/dist/network-policy.cjs +110 -13
  8. package/dist/network-policy.d.cts +8 -3
  9. package/dist/src/actions.js +2 -1
  10. package/dist/src/anthropic-wire.d.ts +2 -0
  11. package/dist/src/anthropic-wire.js +5 -0
  12. package/dist/src/attestation.d.ts +6 -0
  13. package/dist/src/attestation.js +27 -0
  14. package/dist/src/bytes.d.ts +3 -0
  15. package/dist/src/bytes.js +17 -0
  16. package/dist/src/changeset.js +2 -1
  17. package/dist/src/clickhouse/sql.js +73 -14
  18. package/dist/src/derived-core.d.ts +210 -32
  19. package/dist/src/derived-core.js +510 -244
  20. package/dist/src/derived-real.d.ts +1 -1
  21. package/dist/src/derived-real.js +704 -93
  22. package/dist/src/derived.d.ts +18 -2
  23. package/dist/src/derived.js +21 -2
  24. package/dist/src/events.d.ts +28 -45
  25. package/dist/src/events.js +40 -58
  26. package/dist/src/exact-json.d.ts +10 -0
  27. package/dist/src/exact-json.js +98 -0
  28. package/dist/src/executor.d.ts +17 -0
  29. package/dist/src/executor.js +91 -30
  30. package/dist/src/file-response.js +1 -1
  31. package/dist/src/form.d.ts +8 -0
  32. package/dist/src/form.js +76 -0
  33. package/dist/src/git/format.d.ts +16 -0
  34. package/dist/src/git/format.js +110 -0
  35. package/dist/src/git/index.d.ts +1 -0
  36. package/dist/src/git/index.js +1 -0
  37. package/dist/src/git/lfs.d.ts +1 -1
  38. package/dist/src/git/lfs.js +4 -3
  39. package/dist/src/graphql-wire.d.ts +6 -0
  40. package/dist/src/graphql-wire.js +6 -3
  41. package/dist/src/grpc-wire.js +2 -1
  42. package/dist/src/head.d.ts +1 -0
  43. package/dist/src/head.js +15 -4
  44. package/dist/src/held-reads.d.ts +6 -0
  45. package/dist/src/held-reads.js +60 -0
  46. package/dist/src/history.js +5 -4
  47. package/dist/src/host-port.d.ts +5 -0
  48. package/dist/src/host-port.js +14 -0
  49. package/dist/src/index.d.ts +11 -3
  50. package/dist/src/index.js +9 -4
  51. package/dist/src/log.js +12 -7
  52. package/dist/src/machines.d.ts +81 -5
  53. package/dist/src/machines.js +125 -9
  54. package/dist/src/managed-database.d.ts +15 -11
  55. package/dist/src/managed-database.js +38 -37
  56. package/dist/src/multipart.d.ts +21 -3
  57. package/dist/src/multipart.js +112 -38
  58. package/dist/src/observe.d.ts +3 -0
  59. package/dist/src/observe.js +6 -2
  60. package/dist/src/openai-wire.d.ts +16 -0
  61. package/dist/src/openai-wire.js +43 -12
  62. package/dist/src/pack-fetch.d.ts +4 -6
  63. package/dist/src/pack-fetch.js +189 -57
  64. package/dist/src/packRegistry.d.ts +7 -1
  65. package/dist/src/packRegistry.js +20 -3
  66. package/dist/src/private-transport.d.ts +1 -0
  67. package/dist/src/private-transport.js +11 -0
  68. package/dist/src/protobuf.js +10 -4
  69. package/dist/src/rateBudget.d.ts +8 -1
  70. package/dist/src/rateBudget.js +1 -0
  71. package/dist/src/redis/engine.d.ts +14 -5
  72. package/dist/src/redis/engine.js +271 -72
  73. package/dist/src/redis/frames.d.ts +17 -0
  74. package/dist/src/redis/frames.js +123 -0
  75. package/dist/src/redis/index.d.ts +6 -0
  76. package/dist/src/redis/index.js +6 -0
  77. package/dist/src/redis/json.d.ts +2 -0
  78. package/dist/src/redis/json.js +14 -0
  79. package/dist/src/redis/lua-libs.d.ts +4 -0
  80. package/dist/src/redis/lua-libs.js +173 -0
  81. package/dist/src/redis/lua.d.ts +1 -0
  82. package/dist/src/redis/lua.js +36 -0
  83. package/dist/src/redis/member-storage.d.ts +5 -0
  84. package/dist/src/redis/member-storage.js +75 -0
  85. package/dist/src/redis/resp2.d.ts +4 -0
  86. package/dist/src/redis/resp2.js +29 -0
  87. package/dist/src/redis/stream.d.ts +14 -0
  88. package/dist/src/redis/stream.js +335 -0
  89. package/dist/src/remote-execute.d.ts +2 -2
  90. package/dist/src/request-body.d.ts +11 -0
  91. package/dist/src/request-body.js +11 -0
  92. package/dist/src/runtime.d.ts +6 -5
  93. package/dist/src/runtime.js +5 -5
  94. package/dist/src/s3/wire.d.ts +4 -4
  95. package/dist/src/s3/wire.js +5 -3
  96. package/dist/src/scenario.d.ts +22 -0
  97. package/dist/src/scenario.js +35 -31
  98. package/dist/src/serve-http.d.ts +2 -1
  99. package/dist/src/serve-http.js +10 -1
  100. package/dist/src/serve.js +7 -4
  101. package/dist/src/signing.d.ts +23 -5
  102. package/dist/src/signing.js +74 -11
  103. package/dist/src/sigv4.d.ts +3 -1
  104. package/dist/src/sigv4.js +4 -2
  105. package/dist/src/smtp.js +2 -1
  106. package/dist/src/sockets.js +8 -3
  107. package/dist/src/state-system.d.ts +3 -0
  108. package/dist/src/storage.js +5 -2
  109. package/dist/src/twin-fetch.d.ts +3 -1
  110. package/dist/src/twin-fetch.js +3 -2
  111. package/dist/src/vendor-call.d.ts +10 -3
  112. package/dist/src/vendor-call.js +58 -14
  113. package/dist/test-fixtures/attestation.SOURCE.md +1 -0
  114. package/dist/test-fixtures/attestation.json +50 -0
  115. package/generated/pack-facts.json +409 -352
  116. package/inject.cjs +474 -95
  117. package/network-policy.cjs +110 -13
  118. package/network-policy.d.cts +8 -3
  119. package/package.json +11 -4
  120. package/src/actions.ts +2 -1
  121. package/src/anthropic-wire.ts +6 -0
  122. package/src/attestation.ts +23 -0
  123. package/src/bytes.ts +21 -0
  124. package/src/changeset.ts +2 -1
  125. package/src/clickhouse/sql.ts +50 -16
  126. package/src/derived-core.ts +573 -249
  127. package/src/derived-real.ts +552 -42
  128. package/src/derived.ts +23 -4
  129. package/src/events.ts +54 -85
  130. package/src/exact-json.ts +71 -0
  131. package/src/executor.ts +86 -27
  132. package/src/file-response.ts +1 -1
  133. package/src/form.ts +66 -0
  134. package/src/git/format.ts +89 -0
  135. package/src/git/index.ts +1 -0
  136. package/src/git/lfs.ts +5 -4
  137. package/src/graphql-wire.ts +8 -3
  138. package/src/grpc-wire.ts +2 -1
  139. package/src/head.ts +15 -5
  140. package/src/held-reads.ts +54 -0
  141. package/src/history.ts +5 -4
  142. package/src/host-port.ts +9 -0
  143. package/src/index.ts +10 -4
  144. package/src/log.ts +11 -7
  145. package/src/machines.ts +135 -13
  146. package/src/managed-database.ts +48 -40
  147. package/src/multipart.ts +110 -35
  148. package/src/observe.ts +6 -3
  149. package/src/openai-wire.ts +45 -14
  150. package/src/pack-fetch.ts +173 -50
  151. package/src/packRegistry.ts +27 -4
  152. package/src/private-transport.ts +8 -0
  153. package/src/protobuf.ts +8 -4
  154. package/src/rateBudget.ts +6 -1
  155. package/src/redis/engine.ts +168 -63
  156. package/src/redis/frames.ts +53 -0
  157. package/src/redis/index.ts +6 -0
  158. package/src/redis/json.ts +13 -0
  159. package/src/redis/lua-libs.ts +62 -0
  160. package/src/redis/lua.ts +20 -0
  161. package/src/redis/member-storage.ts +58 -0
  162. package/src/redis/resp2.ts +25 -0
  163. package/src/redis/stream.ts +102 -0
  164. package/src/remote-execute.ts +2 -2
  165. package/src/request-body.ts +12 -0
  166. package/src/runtime.ts +6 -5
  167. package/src/s3/wire.ts +8 -5
  168. package/src/scenario.ts +34 -13
  169. package/src/serve-http.ts +11 -2
  170. package/src/serve.ts +4 -3
  171. package/src/signing.ts +71 -17
  172. package/src/sigv4.ts +5 -3
  173. package/src/smtp.ts +3 -2
  174. package/src/sockets.ts +8 -3
  175. package/src/state-system.ts +3 -0
  176. package/src/storage.ts +5 -2
  177. package/src/twin-fetch.ts +4 -3
  178. package/src/vendor-call.ts +59 -12
  179. package/test-fixtures/attestation.json +50 -0
package/app-route.cjs CHANGED
@@ -222,37 +222,39 @@ async function appFetch(value, init = {}) {
222
222
  if (refusal !== null) throw new TypeError(refusal);
223
223
  return fetch(value, init);
224
224
  }
225
- const mode = init.redirect || 'follow';
226
- const signal = init.signal || undefined;
227
- let at = new URL(String(value));
228
- let method = String(init.method || 'GET').toUpperCase();
229
225
  const headers = {};
230
226
  new Headers(init.headers || {}).forEach((v, k) => { headers[k] = v; });
231
- let body = requestBody(init.body, headers);
232
- for (let hops = 0; ; hops++) {
227
+ const body = requestBody(init.body, headers);
228
+ return followRedirects(value, { ...init, headers, body }, async (at, request) => {
229
+ const method = request.method, signal = request.signal;
230
+ const headers = Object.fromEntries(new Headers(request.headers));
233
231
  const route = appDestination(at);
234
- let res;
235
232
  if (route) {
236
- // the application's own origin is where the request goes: an application recorded outside the World (an app-url
237
- // naming a deployment elsewhere) meets the World's egress rule as any other destination does
238
233
  const originRefusal = require('./network-policy.cjs').worldEgressRefusal(route.origin);
239
234
  if (originRefusal !== null) throw new TypeError(originRefusal);
240
- // fetch's own bound (undici's 300 s headers and body timeouts), whatever signal the caller gives, so a hung
241
- // application never holds a delivery, or the API request awaiting it, for good; a caller's signal may end it sooner
242
- const answer = await deliverToApp(route, at, { method, headers, body, signal, timeoutMs: 300_000 });
235
+ const answer = await deliverToApp(route, at, { method, headers, body: request.body, signal, timeoutMs: 300_000 });
243
236
  const nullBody = NULL_BODY.includes(answer.status) || method === 'HEAD';
244
- // a status fetch resolves with but Response refuses to construct (outside 200-599) is carried as fetch carries it
245
237
  const inRange = answer.status >= 200 && answer.status <= 599;
246
- res = new Response(nullBody ? null : answer.body, { status: inRange ? answer.status : 200, headers: answer.headers });
238
+ const res = new Response(nullBody ? null : answer.body, { status: inRange ? answer.status : 200, headers: answer.headers });
247
239
  if (!inRange) Object.defineProperties(res, { status: { value: answer.status }, ok: { value: false } });
248
240
  Object.defineProperty(res, 'url', { value: at.toString() });
249
- } else {
250
- const refusal = require('./network-policy.cjs').worldEgressRefusal(at);
251
- if (refusal !== null) throw new TypeError(refusal);
252
- // off the application, the World's own headers never go with the request
253
- for (const k of Object.keys(headers)) if (['x-twins-key', 'x-volter-twin-original-host'].includes(k.toLowerCase())) delete headers[k];
254
- res = await fetch(at, { method, headers, ...(body != null && method !== 'GET' && method !== 'HEAD' ? { body } : {}), redirect: 'manual', signal });
241
+ return res;
255
242
  }
243
+ const refusal = require('./network-policy.cjs').worldEgressRefusal(at);
244
+ if (refusal !== null) throw new TypeError(refusal);
245
+ for (const k of Object.keys(headers)) if (['x-twins-key', 'x-volter-twin-original-host'].includes(k.toLowerCase())) { delete headers[k]; request.headers.delete(k); }
246
+ return fetch(at, { ...request, headers, body: method === 'GET' || method === 'HEAD' ? undefined : request.body });
247
+ });
248
+ }
249
+
250
+ /** Shared Fetch redirect semantics. send routes/refuses each hop; no destination is fetched here. */
251
+ async function followRedirects(value, init, send, extraDropped = []) {
252
+ const mode = init.redirect || 'follow';
253
+ let at = new URL(String(value));
254
+ let method = String(init.method || 'GET').toUpperCase(), body = init.body;
255
+ const headers = new Headers(init.headers);
256
+ for (let hops = 0; ; hops++) {
257
+ const res = await send(at, { ...init, method, headers, body, redirect: 'manual' });
256
258
  if (hops > 0) Object.defineProperty(res, 'redirected', { value: true });
257
259
  const location = res.headers.get('location');
258
260
  if (!REDIRECTS.includes(res.status) || location === null || mode === 'manual') return res;
@@ -262,13 +264,12 @@ async function appFetch(value, init = {}) {
262
264
  const next = new URL(location, at);
263
265
  if (next.protocol !== 'http:' && next.protocol !== 'https:') throw new TypeError(`redirect to ${next.protocol} is not followed`);
264
266
  if ((res.status === 303 && method !== 'GET' && method !== 'HEAD') || ((res.status === 301 || res.status === 302) && method === 'POST')) {
265
- method = 'GET';
266
- body = null;
267
- for (const k of Object.keys(headers)) if (/^content-/i.test(k)) delete headers[k];
267
+ method = 'GET'; body = undefined;
268
+ for (const k of [...headers.keys()]) if (/^content-/i.test(k)) headers.delete(k);
268
269
  }
269
- if (next.origin !== at.origin) for (const k of Object.keys(headers)) if (CROSS_ORIGIN_DROPPED.includes(k.toLowerCase())) delete headers[k];
270
+ if (next.origin !== at.origin) for (const k of [...headers.keys()]) if ([...CROSS_ORIGIN_DROPPED, ...extraDropped].includes(k.toLowerCase())) headers.delete(k);
270
271
  at = next;
271
272
  }
272
273
  }
273
274
 
274
- module.exports = { appRouteFor, appHostMatch, appForwardHeaders, appDestination, appRequestOptions, deliverToApp, appFetch, sessionCa };
275
+ module.exports = { appRouteFor, appHostMatch, appForwardHeaders, appDestination, appRequestOptions, deliverToApp, appFetch, followRedirects, sessionCa };
package/app-route.d.cts CHANGED
@@ -6,3 +6,4 @@ export function appForwardHeaders(url: URL): Record<string, string>;
6
6
  export function appDestination(value: string | URL, env?: Readonly<Record<string, string | undefined>>): AppRoute | null;
7
7
  export function deliverToApp(route: AppRoute, value: string | URL, init?: { method?: string; headers?: Record<string, string>; body?: string | Uint8Array | null; /** Infinity: no deadline of its own */ timeoutMs?: number; signal?: AbortSignal }): Promise<AppAnswer>;
8
8
  export function appFetch(value: string | URL, init?: RequestInit): Promise<Response>;
9
+ export function followRedirects(value: string | URL, init: RequestInit, send: (url: URL, init: RequestInit) => Promise<Response>, extraDropped?: string[]): Promise<Response>;
@@ -222,37 +222,39 @@ async function appFetch(value, init = {}) {
222
222
  if (refusal !== null) throw new TypeError(refusal);
223
223
  return fetch(value, init);
224
224
  }
225
- const mode = init.redirect || 'follow';
226
- const signal = init.signal || undefined;
227
- let at = new URL(String(value));
228
- let method = String(init.method || 'GET').toUpperCase();
229
225
  const headers = {};
230
226
  new Headers(init.headers || {}).forEach((v, k) => { headers[k] = v; });
231
- let body = requestBody(init.body, headers);
232
- for (let hops = 0; ; hops++) {
227
+ const body = requestBody(init.body, headers);
228
+ return followRedirects(value, { ...init, headers, body }, async (at, request) => {
229
+ const method = request.method, signal = request.signal;
230
+ const headers = Object.fromEntries(new Headers(request.headers));
233
231
  const route = appDestination(at);
234
- let res;
235
232
  if (route) {
236
- // the application's own origin is where the request goes: an application recorded outside the World (an app-url
237
- // naming a deployment elsewhere) meets the World's egress rule as any other destination does
238
233
  const originRefusal = require('./network-policy.cjs').worldEgressRefusal(route.origin);
239
234
  if (originRefusal !== null) throw new TypeError(originRefusal);
240
- // fetch's own bound (undici's 300 s headers and body timeouts), whatever signal the caller gives, so a hung
241
- // application never holds a delivery, or the API request awaiting it, for good; a caller's signal may end it sooner
242
- const answer = await deliverToApp(route, at, { method, headers, body, signal, timeoutMs: 300_000 });
235
+ const answer = await deliverToApp(route, at, { method, headers, body: request.body, signal, timeoutMs: 300_000 });
243
236
  const nullBody = NULL_BODY.includes(answer.status) || method === 'HEAD';
244
- // a status fetch resolves with but Response refuses to construct (outside 200-599) is carried as fetch carries it
245
237
  const inRange = answer.status >= 200 && answer.status <= 599;
246
- res = new Response(nullBody ? null : answer.body, { status: inRange ? answer.status : 200, headers: answer.headers });
238
+ const res = new Response(nullBody ? null : answer.body, { status: inRange ? answer.status : 200, headers: answer.headers });
247
239
  if (!inRange) Object.defineProperties(res, { status: { value: answer.status }, ok: { value: false } });
248
240
  Object.defineProperty(res, 'url', { value: at.toString() });
249
- } else {
250
- const refusal = require('./network-policy.cjs').worldEgressRefusal(at);
251
- if (refusal !== null) throw new TypeError(refusal);
252
- // off the application, the World's own headers never go with the request
253
- for (const k of Object.keys(headers)) if (['x-twins-key', 'x-volter-twin-original-host'].includes(k.toLowerCase())) delete headers[k];
254
- res = await fetch(at, { method, headers, ...(body != null && method !== 'GET' && method !== 'HEAD' ? { body } : {}), redirect: 'manual', signal });
241
+ return res;
255
242
  }
243
+ const refusal = require('./network-policy.cjs').worldEgressRefusal(at);
244
+ if (refusal !== null) throw new TypeError(refusal);
245
+ for (const k of Object.keys(headers)) if (['x-twins-key', 'x-volter-twin-original-host'].includes(k.toLowerCase())) { delete headers[k]; request.headers.delete(k); }
246
+ return fetch(at, { ...request, headers, body: method === 'GET' || method === 'HEAD' ? undefined : request.body });
247
+ });
248
+ }
249
+
250
+ /** Shared Fetch redirect semantics. send routes/refuses each hop; no destination is fetched here. */
251
+ async function followRedirects(value, init, send, extraDropped = []) {
252
+ const mode = init.redirect || 'follow';
253
+ let at = new URL(String(value));
254
+ let method = String(init.method || 'GET').toUpperCase(), body = init.body;
255
+ const headers = new Headers(init.headers);
256
+ for (let hops = 0; ; hops++) {
257
+ const res = await send(at, { ...init, method, headers, body, redirect: 'manual' });
256
258
  if (hops > 0) Object.defineProperty(res, 'redirected', { value: true });
257
259
  const location = res.headers.get('location');
258
260
  if (!REDIRECTS.includes(res.status) || location === null || mode === 'manual') return res;
@@ -262,13 +264,12 @@ async function appFetch(value, init = {}) {
262
264
  const next = new URL(location, at);
263
265
  if (next.protocol !== 'http:' && next.protocol !== 'https:') throw new TypeError(`redirect to ${next.protocol} is not followed`);
264
266
  if ((res.status === 303 && method !== 'GET' && method !== 'HEAD') || ((res.status === 301 || res.status === 302) && method === 'POST')) {
265
- method = 'GET';
266
- body = null;
267
- for (const k of Object.keys(headers)) if (/^content-/i.test(k)) delete headers[k];
267
+ method = 'GET'; body = undefined;
268
+ for (const k of [...headers.keys()]) if (/^content-/i.test(k)) headers.delete(k);
268
269
  }
269
- if (next.origin !== at.origin) for (const k of Object.keys(headers)) if (CROSS_ORIGIN_DROPPED.includes(k.toLowerCase())) delete headers[k];
270
+ if (next.origin !== at.origin) for (const k of [...headers.keys()]) if ([...CROSS_ORIGIN_DROPPED, ...extraDropped].includes(k.toLowerCase())) headers.delete(k);
270
271
  at = next;
271
272
  }
272
273
  }
273
274
 
274
- module.exports = { appRouteFor, appHostMatch, appForwardHeaders, appDestination, appRequestOptions, deliverToApp, appFetch, sessionCa };
275
+ module.exports = { appRouteFor, appHostMatch, appForwardHeaders, appDestination, appRequestOptions, deliverToApp, appFetch, followRedirects, sessionCa };
@@ -6,3 +6,4 @@ export function appForwardHeaders(url: URL): Record<string, string>;
6
6
  export function appDestination(value: string | URL, env?: Readonly<Record<string, string | undefined>>): AppRoute | null;
7
7
  export function deliverToApp(route: AppRoute, value: string | URL, init?: { method?: string; headers?: Record<string, string>; body?: string | Uint8Array | null; /** Infinity: no deadline of its own */ timeoutMs?: number; signal?: AbortSignal }): Promise<AppAnswer>;
8
8
  export function appFetch(value: string | URL, init?: RequestInit): Promise<Response>;
9
+ export function followRedirects(value: string | URL, init: RequestInit, send: (url: URL, init: RequestInit) => Promise<Response>, extraDropped?: string[]): Promise<Response>;