@volter/world-core 3.0.155 → 3.0.156

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 (101) hide show
  1. package/dist/generated/pack-facts.json +143 -12
  2. package/dist/inject.cjs +150 -86
  3. package/dist/src/actions.d.ts +15 -0
  4. package/dist/src/actions.js +82 -21
  5. package/dist/src/ancestry.d.ts +5 -4
  6. package/dist/src/ancestry.js +53 -28
  7. package/dist/src/changeset.js +1 -1
  8. package/dist/src/clickhouse/compression.d.ts +28 -0
  9. package/dist/src/clickhouse/compression.js +281 -0
  10. package/dist/src/clickhouse/index.d.ts +1 -0
  11. package/dist/src/clickhouse/index.js +1 -0
  12. package/dist/src/derived-core.d.ts +12 -1
  13. package/dist/src/derived-core.js +145 -11
  14. package/dist/src/derived.js +3 -0
  15. package/dist/src/fork.js +1 -1
  16. package/dist/src/grpc-wire.js +2 -1
  17. package/dist/src/h2.js +63 -10
  18. package/dist/src/head.d.ts +3 -0
  19. package/dist/src/head.js +9 -0
  20. package/dist/src/history.d.ts +1 -1
  21. package/dist/src/history.js +7 -7
  22. package/dist/src/index.d.ts +4 -1
  23. package/dist/src/index.js +5 -1
  24. package/dist/src/log.d.ts +23 -3
  25. package/dist/src/log.js +160 -37
  26. package/dist/src/managed-original-inputs.d.ts +101 -0
  27. package/dist/src/managed-original-inputs.js +125 -0
  28. package/dist/src/mongodb/client.d.ts +8 -0
  29. package/dist/src/mongodb/client.js +27 -0
  30. package/dist/src/mongodb/index.d.ts +2 -0
  31. package/dist/src/mongodb/index.js +5 -0
  32. package/dist/src/mongodb/stream.d.ts +74 -0
  33. package/dist/src/mongodb/stream.js +206 -0
  34. package/dist/src/observe.js +1 -1
  35. package/dist/src/pack-fetch.js +20 -8
  36. package/dist/src/packRegistry.d.ts +10 -14
  37. package/dist/src/packRegistry.js +2 -13
  38. package/dist/src/protocol.d.ts +13 -0
  39. package/dist/src/protocol.js +13 -0
  40. package/dist/src/redis/engine.d.ts +10 -4
  41. package/dist/src/redis/engine.js +103 -32
  42. package/dist/src/redis/member-storage.js +20 -8
  43. package/dist/src/redis/service-times.d.ts +25 -0
  44. package/dist/src/redis/service-times.js +87 -0
  45. package/dist/src/redis/stream.d.ts +2 -1
  46. package/dist/src/redis/stream.js +109 -20
  47. package/dist/src/runtime-state.d.ts +11 -0
  48. package/dist/src/runtime-state.js +13 -0
  49. package/dist/src/runtime.d.ts +4 -2
  50. package/dist/src/runtime.js +5 -2
  51. package/dist/src/serve-http.d.ts +2 -0
  52. package/dist/src/serve-http.js +21 -4
  53. package/dist/src/serve.d.ts +10 -0
  54. package/dist/src/serve.js +43 -3
  55. package/dist/src/storage.d.ts +2 -1
  56. package/dist/src/storage.js +6 -3
  57. package/dist/src/world-boot.d.ts +1 -0
  58. package/dist/src/world-boot.js +6 -0
  59. package/dist/src/world-clock.js +6 -2
  60. package/dist/src/world-store.d.ts +108 -7
  61. package/dist/src/world-store.js +883 -103
  62. package/dist/src/xml.d.ts +30 -0
  63. package/dist/src/xml.js +74 -0
  64. package/generated/pack-facts.json +143 -12
  65. package/inject.cjs +150 -86
  66. package/package.json +20 -1
  67. package/src/actions.ts +78 -21
  68. package/src/ancestry.ts +46 -24
  69. package/src/changeset.ts +1 -1
  70. package/src/clickhouse/compression.ts +172 -0
  71. package/src/clickhouse/index.ts +2 -0
  72. package/src/derived-core.ts +142 -11
  73. package/src/derived.ts +3 -0
  74. package/src/fork.ts +1 -1
  75. package/src/grpc-wire.ts +2 -1
  76. package/src/h2.ts +46 -5
  77. package/src/head.ts +9 -0
  78. package/src/history.ts +7 -7
  79. package/src/index.ts +6 -1
  80. package/src/log.ts +147 -32
  81. package/src/managed-original-inputs.ts +163 -0
  82. package/src/mongodb/client.ts +27 -0
  83. package/src/mongodb/index.ts +5 -0
  84. package/src/mongodb/stream.ts +213 -0
  85. package/src/observe.ts +1 -1
  86. package/src/pack-fetch.ts +20 -8
  87. package/src/packRegistry.ts +3 -15
  88. package/src/protocol.ts +13 -0
  89. package/src/redis/engine.ts +100 -57
  90. package/src/redis/member-storage.ts +17 -9
  91. package/src/redis/service-times.ts +81 -0
  92. package/src/redis/stream.ts +66 -14
  93. package/src/runtime-state.ts +14 -0
  94. package/src/runtime.ts +6 -1
  95. package/src/serve-http.ts +23 -4
  96. package/src/serve.ts +45 -3
  97. package/src/storage.ts +5 -3
  98. package/src/world-boot.ts +6 -0
  99. package/src/world-clock.ts +6 -2
  100. package/src/world-store.ts +704 -91
  101. package/src/xml.ts +71 -0
@@ -270,9 +270,6 @@
270
270
  {
271
271
  "host": "api.clerk.com"
272
272
  },
273
- {
274
- "host": "dashboard.clerk.com"
275
- },
276
273
  {
277
274
  "suffix": ".clerk.accounts.dev"
278
275
  },
@@ -331,6 +328,65 @@
331
328
  },
332
329
  "serveExport": "createClerkTwinServer"
333
330
  },
331
+ "clickhouse": {
332
+ "adoption": {
333
+ "sdks": [
334
+ "@clickhouse/client",
335
+ "@clickhouse/client-web"
336
+ ],
337
+ "pypi": [
338
+ "clickhouse-driver",
339
+ "clickhouse-connect",
340
+ "infi-clickhouse-orm"
341
+ ],
342
+ "envStems": [
343
+ "CLICKHOUSE"
344
+ ]
345
+ },
346
+ "hostsNone": "Self-hosted database: its own declared host and allocated listener are supplied by managed infrastructure.",
347
+ "archetype": "crud",
348
+ "protocol": {
349
+ "declared": "3",
350
+ "major": 3,
351
+ "standing": "current"
352
+ },
353
+ "transport": "rest",
354
+ "resources": [
355
+ "database",
356
+ "table",
357
+ "row"
358
+ ],
359
+ "endpointEnv": {
360
+ "name": "CLICKHOUSE_URL",
361
+ "note": "HTTP base URL read by the documented JavaScript client."
362
+ },
363
+ "managedService": {
364
+ "kind": "clickhouse",
365
+ "scheme": "http",
366
+ "configurationArg": "--configuration",
367
+ "originalInputs": {
368
+ "version": 1,
369
+ "manifestArg": "--original-inputs",
370
+ "rootArg": "--original-root",
371
+ "digestArg": "--original-inputs-sha256",
372
+ "paths": [
373
+ "/etc/clickhouse-server",
374
+ "/docker-entrypoint-initdb.d",
375
+ "/entrypoint.sh"
376
+ ]
377
+ },
378
+ "note": "One HTTP8123/native9000 process and store; declared operator configuration is installed before listeners."
379
+ },
380
+ "sidePorts": [
381
+ {
382
+ "name": "native",
383
+ "option": "nativePort",
384
+ "flag": "--native-port",
385
+ "note": "ClickHouse native TCP protocol, normally9000, beside HTTP8123."
386
+ }
387
+ ],
388
+ "serveExport": "createClickhouseTwinServer"
389
+ },
334
390
  "cloudflare": {
335
391
  "adoption": {
336
392
  "pypi": [
@@ -1014,6 +1070,55 @@
1014
1070
  "endpointEnvNone": "Google generated clients take rootUrl in code; the World routes the declared Calendar API paths.",
1015
1071
  "serveExport": "createGooglecalendarTwinServer"
1016
1072
  },
1073
+ "googlefonts": {
1074
+ "adoption": {
1075
+ "sdks": [],
1076
+ "envStems": [
1077
+ "GOOGLE_FONTS"
1078
+ ]
1079
+ },
1080
+ "hosts": [
1081
+ {
1082
+ "host": "www.googleapis.com",
1083
+ "pathPattern": "^/webfonts/v1/webfonts$"
1084
+ },
1085
+ {
1086
+ "host": "webfonts.googleapis.com",
1087
+ "pathPattern": "^/v1/webfonts$"
1088
+ },
1089
+ {
1090
+ "host": "fonts.googleapis.com",
1091
+ "pathPattern": "^/css$"
1092
+ },
1093
+ {
1094
+ "host": "fonts.gstatic.com",
1095
+ "pathPattern": "^/(s/|l/font$)"
1096
+ }
1097
+ ],
1098
+ "archetype": "crud",
1099
+ "protocol": {
1100
+ "declared": "3",
1101
+ "major": 3,
1102
+ "standing": "current"
1103
+ },
1104
+ "transport": "rest",
1105
+ "resources": [
1106
+ "webfont",
1107
+ "_api_key",
1108
+ "_font_catalog",
1109
+ "_stylesheet",
1110
+ "_font_file"
1111
+ ],
1112
+ "endpointEnvNone": "Pinned helper hardcodes the vendor API and CSS hosts, then downloads their returned gstatic URLs. Scoped host routing preserves these URLs.",
1113
+ "credentialDoor": {
1114
+ "path": "/_twin/app-credentials",
1115
+ "body": {},
1116
+ "fill": {
1117
+ "GOOGLE_FONTS_API_KEY": "api_key"
1118
+ }
1119
+ },
1120
+ "serveExport": "createGooglefontsTwinServer"
1121
+ },
1017
1122
  "googleoauth": {
1018
1123
  "adoption": {
1019
1124
  "sdks": [
@@ -1312,7 +1417,8 @@
1312
1417
  "host": "api.linear.app"
1313
1418
  },
1314
1419
  {
1315
- "host": "linear.app"
1420
+ "host": "linear.app",
1421
+ "pathPattern": "^/oauth/"
1316
1422
  }
1317
1423
  ],
1318
1424
  "archetype": "crud",
@@ -1332,7 +1438,7 @@
1332
1438
  "comment",
1333
1439
  "issue_label"
1334
1440
  ],
1335
- "endpointEnvNone": "Linear uses api.linear.app/graphql and linear.app for its workspace and OAuth authorize page; the World claims those hosts",
1441
+ "endpointEnvNone": "Linear uses api.linear.app/graphql and linear.app/oauth/authorize; the World claims the documented hosts",
1336
1442
  "credentialDoor": {
1337
1443
  "path": "/_twin/local-credentials",
1338
1444
  "body": {},
@@ -1516,6 +1622,38 @@
1516
1622
  },
1517
1623
  "serveExport": "createMistralTwinServer"
1518
1624
  },
1625
+ "mongodb": {
1626
+ "adoption": {
1627
+ "sdks": [
1628
+ "mongodb",
1629
+ "mongoose"
1630
+ ],
1631
+ "envStems": [
1632
+ "MONGODB",
1633
+ "MONGO"
1634
+ ]
1635
+ },
1636
+ "hosts": [],
1637
+ "archetype": "crud",
1638
+ "protocol": {
1639
+ "declared": "3",
1640
+ "major": 3,
1641
+ "standing": "current"
1642
+ },
1643
+ "transport": "raw-tcp",
1644
+ "resources": [
1645
+ "collection",
1646
+ "index",
1647
+ "document"
1648
+ ],
1649
+ "endpointEnvNone": "Managed infrastructure injects the connection address from the declared mongodb service; it is a TCP endpoint, with no HTTP API host.",
1650
+ "managedService": {
1651
+ "kind": "mongodb",
1652
+ "scheme": "mongodb",
1653
+ "note": "MongoDB 7.0 wire: standalone, or a declared single-member handshake without sessions; state in the World tree"
1654
+ },
1655
+ "serveExport": "createMongodbTwinServer"
1656
+ },
1519
1657
  "npm-registry": {
1520
1658
  "adoption": {
1521
1659
  "envStems": [
@@ -2025,10 +2163,6 @@
2025
2163
  },
2026
2164
  {
2027
2165
  "host": "inbound-cdn.resend.com"
2028
- },
2029
- {
2030
- "host": "resend.com",
2031
- "pathPattern": "^/emails(?:/|$)"
2032
2166
  }
2033
2167
  ],
2034
2168
  "archetype": "crud",
@@ -2185,9 +2319,6 @@
2185
2319
  ]
2186
2320
  },
2187
2321
  "hosts": [
2188
- {
2189
- "host": "app.slack.com"
2190
- },
2191
2322
  {
2192
2323
  "host": "slack.com"
2193
2324
  },
package/dist/inject.cjs CHANGED
@@ -146,32 +146,61 @@ function installPrismaAdapterShim() {
146
146
  if (candidates.length === 0) return;
147
147
  Module.__volterPrismaAdapterShimInstalled = true;
148
148
  const path = require('path');
149
- const originalLoad = Module._load;
150
- Module._load = function volterPrismaLoad(request, parent, isMain) {
151
- const exports = originalLoad.apply(this, arguments);
152
- if (request !== '@prisma/client' || !exports || typeof exports.PrismaClient !== 'function' || exports.PrismaClient.__volterAdapted) return exports;
149
+ // The package's own entry (its `main`, `default.js`; `index.js` before Prisma 5), patched as it loads (PACKAGE ENTRIES).
150
+ patchPackageEntry(/[\\/]node_modules[\\/]@prisma[\\/]client[\\/](default|index)\.js$/, (module) => {
151
+ const exports = module.exports;
152
+ if (!exports || typeof exports.PrismaClient !== 'function' || exports.PrismaClient.__volterAdapted) return;
153
153
  const vendor = candidates.find((candidate) => MAP[candidate] && process.env[packs[candidate].prismaAdapter.urlEnv]);
154
- if (!vendor) return exports;
154
+ if (!vendor) return;
155
155
  const facts = packs[vendor].prismaAdapter;
156
- // From the requiring module first (a library that constructs the client), then the
157
- // application itself, whose dependency the adapter is under pnpm's isolated layout.
158
- const from = parent && parent.filename ? path.dirname(parent.filename) : process.cwd();
159
- let adapterModule;
160
- try {
161
- adapterModule = originalLoad.call(this, require.resolve(facts.adapter, { paths: [from, process.cwd()] }), parent, false);
162
- } catch {
156
+ // THE ADAPTER IS FOUND WHERE THE CLIENT IS USED, AT ITS FIRST CONSTRUCTION WITHOUT ONE (review of the World 2209
157
+ // integration, 75f6a1dd). The entry's own parent is the first module that loaded it. For a copy cached before this
158
+ // prelude ran, that is not the library that later constructs the client, and an early miss there was final.
159
+ // At each construction without an adapter, until one is found, these places are asked in turn:
160
+ // - the directory of each CommonJS module that lists the entry among its children, most recently loaded first, by
161
+ // Module._cache's insertion order, with the entry's module.parent last of them. Node's updateChildren records a
162
+ // cached require too, so a consumer that requires the client later is found at the next construction;
163
+ // - the main module's directory and that of process.argv[1];
164
+ // - the working directory.
165
+ // An ES module that imports the client is never its parent or one of the cached modules that list it, so an ESM
166
+ // consumer is reached only through those last places. A found adapter is kept, and said once if a miss was said
167
+ // before it. A place that missed is not asked again (`missedPlaces`): a new consumer brings a new place, and no
168
+ // resolve is repeated. A miss is said once, and the construction is left as it was. Module._cache is read at each
169
+ // construction without an adapter until one is found, a walk of the cache's entries and no file system work.
170
+ let Adapter;
171
+ let missSaid = false;
172
+ const missedPlaces = new Set();
173
+ const adapterFor = () => {
174
+ if (Adapter) return Adapter;
175
+ const consumers = [module.parent, ...Object.values(Module._cache).filter((other) => other && other !== module.parent && Array.isArray(other.children) && other.children.includes(module))]
176
+ .filter((consumer) => consumer && consumer.filename).reverse();
177
+ // Each place with the module it is asked for, so the adapter loads as that module's child (Node's bookkeeping
178
+ // of parent and children only; resolution is by `paths`).
179
+ const places = new Map();
180
+ for (const consumer of consumers) if (!places.has(path.dirname(consumer.filename))) places.set(path.dirname(consumer.filename), consumer);
181
+ if (require.main && require.main.filename && !places.has(path.dirname(require.main.filename))) places.set(path.dirname(require.main.filename), require.main);
182
+ if (typeof process.argv[1] === 'string' && process.argv[1] && !places.has(path.dirname(path.resolve(process.argv[1])))) places.set(path.dirname(path.resolve(process.argv[1])), null);
183
+ if (!places.has(process.cwd())) places.set(process.cwd(), null);
184
+ let reason = `${facts.adapter} is not installed in this application`;
185
+ for (const [from, consumer] of places) {
186
+ if (missedPlaces.has(from)) continue;
187
+ let loaded;
188
+ try { loaded = Module._load(require.resolve(facts.adapter, { paths: [from] }), consumer, false); }
189
+ catch { missedPlaces.add(from); continue; }
190
+ const found = loaded && loaded[facts.export];
191
+ if (typeof found === 'function') {
192
+ Adapter = found;
193
+ if (missSaid) process.stderr.write(`[twin-inject] ${vendor}: ${facts.adapter} found from ${from}; a Prisma client constructed without an adapter from now on gets it\n`);
194
+ return Adapter;
195
+ }
196
+ missedPlaces.add(from);
197
+ reason = `${facts.adapter} exports no ${facts.export}`;
198
+ }
163
199
  // Left as it was, said once: on the client engine Prisma refuses the construction itself;
164
200
  // on the library engine the client reaches the twin over the vendor's own wire.
165
- process.stderr.write(`[twin-inject] ${vendor}: ${facts.adapter} is not installed in this application, so a Prisma client constructed without an adapter is left as it was\n`);
166
- exports.PrismaClient.__volterAdapted = true;
167
- return exports;
168
- }
169
- const Adapter = adapterModule && adapterModule[facts.export];
170
- if (typeof Adapter !== 'function') {
171
- process.stderr.write(`[twin-inject] ${vendor}: ${facts.adapter} exports no ${facts.export}; a Prisma client constructed without an adapter is left as it was\n`);
172
- exports.PrismaClient.__volterAdapted = true;
173
- return exports;
174
- }
201
+ if (!missSaid) { missSaid = true; process.stderr.write(`[twin-inject] ${vendor}: ${reason}, so a Prisma client constructed without an adapter is left as it was until it is found\n`); }
202
+ return undefined;
203
+ };
175
204
  const Base = exports.PrismaClient;
176
205
  class PrismaClient extends Base {
177
206
  constructor(options) {
@@ -180,16 +209,18 @@ function installPrismaAdapterShim() {
180
209
  // decision. The URL is the application's where it names one (its host is twinned by the
181
210
  // injector's own host rules), else the endpoint template's variable.
182
211
  if ('adapter' in given) { super(given); return; }
212
+ const Found = adapterFor();
213
+ // Left as it was: Prisma is given exactly what the application passed (`new PrismaClient()` is no options).
214
+ if (!Found) { super(...arguments); return; }
183
215
  const named = given.datasources && typeof given.datasources === 'object'
184
216
  ? Object.values(given.datasources).map((source) => source && source.url).find((value) => typeof value === 'string') : undefined;
185
217
  const url = given.datasourceUrl || named || process.env[facts.urlEnv];
186
- super({ ...given, adapter: new Adapter({ url, fetch: (...args) => globalThis.fetch(...args) }) });
218
+ super({ ...given, adapter: new Found({ url, fetch: (...args) => globalThis.fetch(...args) }) });
187
219
  }
188
220
  }
189
221
  PrismaClient.__volterAdapted = true;
190
222
  exports.PrismaClient = PrismaClient;
191
- return exports;
192
- };
223
+ });
193
224
  }
194
225
 
195
226
  // The exact inverse of readMap's env lookup: which vendor (if any) would the injector read
@@ -647,50 +678,77 @@ function routedTwin(url) {
647
678
  }
648
679
  // Imported Undici APIs may hold a dispatcher obtained before the global view was installed.
649
680
  // Rewrite their public HTTP doors as well; an independent connector still faces the socket guards.
650
- let UNDICI_LOAD = null;
681
+ // PACKAGE ENTRIES, TAKEN WHEN THEY LOAD (S2): the preludes that act on one package (undici, @prisma/client, miniflare)
682
+ // wrapped Module._load and ran on every load of the process to compare one name (LibreChat's server: 20,228 loads,
683
+ // ~20 ms in the tab, none of it in native's path), and a wrapped Module._load kept the tab's engine on its slower
684
+ // replaced-load route for every require. Each is now a patch of the package's entry module, made when that file is
685
+ // loaded (Module._extensions['.js'], once per new module): the entry is loaded once per copy (every version, every
686
+ // root, late or early) and cached, so the exports the patch leaves are what every later require of that copy is
687
+ // answered, and an `import` of it loads it the same way. A copy loaded before this prelude ran is patched where it is
688
+ // cached: its exports object is patched in place, so later requires and imports, and a module that holds that exports
689
+ // object, see the patch; only a binding taken from it before the prelude ran (a destructured PrismaClient, an ES
690
+ // module's namespace already linked) keeps the original. Known limits: a '.js' handler installed later that does not call the one it replaced hides the entries
691
+ // loaded through it; an entry outside a node_modules directory (a linked checkout of the package) is not recognized.
692
+ const ENTRY_PATCHES = [];
693
+ let ENTRY_LOAD = null;
694
+ function patchPackageEntry(pattern, patch) {
695
+ ENTRY_PATCHES.push({ pattern, patch });
696
+ for (const [filename, module] of Object.entries(Module._cache)) {
697
+ if (pattern.test(filename) && module && module.loaded) patch(module, filename);
698
+ }
699
+ if (ENTRY_LOAD) return;
700
+ const original = ENTRY_LOAD = Module._extensions['.js'];
701
+ Module._extensions['.js'] = function volterPackageEntry(module, filename) {
702
+ const result = original.apply(this, arguments);
703
+ for (const entry of ENTRY_PATCHES) if (entry.pattern.test(filename)) entry.patch(module, filename);
704
+ return result;
705
+ };
706
+ }
707
+
708
+ let UNDICI_ROUTED = false;
651
709
  function routeImportedUndici() {
652
- if (UNDICI_LOAD) return;
653
- const original = UNDICI_LOAD = Module._load;
654
- const seen = new WeakMap();
655
- Module._load = function volterUndiciLoad(request, parent, isMain) {
656
- const exports = original.apply(this, arguments);
657
- if (request !== 'undici' || !exports || typeof exports.request !== 'function') return exports;
658
- if (seen.has(exports)) return seen.get(exports);
659
- const view = Object.assign({}, exports);
660
- view.fetch = function routedUndiciFetch(input, init) {
661
- if (!installed) return exports.fetch(input, init);
662
- let url; try { url = new URL(typeof input === 'object' && input?.url ? input.url : String(input)); } catch {}
663
- const twin = routedTwin(url);
664
- // Local control planes may use their own Request class and dispatcher. Preserve both;
665
- // connections still pass the socket guards, and claimed vendor hops still enter routing.
666
- if (url && isLocalOrPrivateHost(url.hostname) && (!twin || twin.vendor === 'app')) return exports.fetch(input, init);
667
- if (input && typeof input === 'object' && typeof input.url === 'string' && !(input instanceof globalThis.Request)) {
668
- const options = {};
669
- for (const name of ['method', 'signal', 'redirect', 'cache', 'credentials', 'integrity', 'keepalive', 'referrer', 'referrerPolicy']) {
670
- if (input[name] !== undefined) options[name] = input[name];
671
- }
672
- options.headers = Array.from(input.headers);
673
- if (input.body !== null && input.body !== undefined) { options.body = input.body; options.duplex = 'half'; }
674
- return globalThis.fetch(input.url, { ...options, ...init });
710
+ if (UNDICI_ROUTED) return;
711
+ UNDICI_ROUTED = true;
712
+ patchPackageEntry(/[\\/]node_modules[\\/]undici[\\/]index\.js$/, (module) => {
713
+ if (module.exports && typeof module.exports.request === 'function' && !ROUTED_UNDICI.has(module.exports)) module.exports = routedUndici(module.exports);
714
+ });
715
+ }
716
+ const ROUTED_UNDICI = new WeakSet();
717
+ function routedUndici(exports) {
718
+ const view = Object.assign({}, exports);
719
+ view.fetch = function routedUndiciFetch(input, init) {
720
+ if (!installed) return exports.fetch(input, init);
721
+ let url; try { url = new URL(typeof input === 'object' && input?.url ? input.url : String(input)); } catch {}
722
+ const twin = routedTwin(url);
723
+ // Local control planes may use their own Request class and dispatcher. Preserve both;
724
+ // connections still pass the socket guards, and claimed vendor hops still enter routing.
725
+ if (url && isLocalOrPrivateHost(url.hostname) && (!twin || twin.vendor === 'app')) return exports.fetch(input, init);
726
+ if (input && typeof input === 'object' && typeof input.url === 'string' && !(input instanceof globalThis.Request)) {
727
+ const options = {};
728
+ for (const name of ['method', 'signal', 'redirect', 'cache', 'credentials', 'integrity', 'keepalive', 'referrer', 'referrerPolicy']) {
729
+ if (input[name] !== undefined) options[name] = input[name];
675
730
  }
676
- return globalThis.fetch(input, init);
677
- };
678
- view.request = function routedUndiciRequest(input, options, callback) {
679
- if (!installed) return exports.request.apply(exports, arguments);
680
- const opts = typeof options === 'function' ? {} : options ?? {};
681
- let url; try { url = new URL(String(input)); if (opts.path !== undefined) url = new URL(url.origin + String(opts.path)); } catch {}
682
- const twin = routedTwin(url);
683
- if (!twin || twin.vendor === 'app') return exports.request.apply(exports, arguments);
684
- const headers = undiciHeaderObject(opts.headers);
685
- headers.host = url.host; headers['x-volter-twin-original-host'] = url.host;
686
- const key = twinsKey(); if (key) headers['x-twins-key'] = key;
687
- const target = twin.origin.replace(/\/$/, '') + url.pathname + url.search;
688
- const { path: _path, ...requestOptions } = opts; // target already carries the effective path and endpoint prefix
689
- return exports.request(target, { ...requestOptions, headers, maxRedirections: 0 }, typeof options === 'function' ? options : callback);
690
- };
691
- seen.set(exports, view);
692
- return view;
731
+ options.headers = Array.from(input.headers);
732
+ if (input.body !== null && input.body !== undefined) { options.body = input.body; options.duplex = 'half'; }
733
+ return globalThis.fetch(input.url, { ...options, ...init });
734
+ }
735
+ return globalThis.fetch(input, init);
736
+ };
737
+ view.request = function routedUndiciRequest(input, options, callback) {
738
+ if (!installed) return exports.request.apply(exports, arguments);
739
+ const opts = typeof options === 'function' ? {} : options ?? {};
740
+ let url; try { url = new URL(String(input)); if (opts.path !== undefined) url = new URL(url.origin + String(opts.path)); } catch {}
741
+ const twin = routedTwin(url);
742
+ if (!twin || twin.vendor === 'app') return exports.request.apply(exports, arguments);
743
+ const headers = undiciHeaderObject(opts.headers);
744
+ headers.host = url.host; headers['x-volter-twin-original-host'] = url.host;
745
+ const key = twinsKey(); if (key) headers['x-twins-key'] = key;
746
+ const target = twin.origin.replace(/\/$/, '') + url.pathname + url.search;
747
+ const { path: _path, ...requestOptions } = opts; // target already carries the effective path and endpoint prefix
748
+ return exports.request(target, { ...requestOptions, headers, maxRedirections: 0 }, typeof options === 'function' ? options : callback);
693
749
  };
750
+ ROUTED_UNDICI.add(view);
751
+ return view;
694
752
  }
695
753
  function unkeyUndiciDispatches() {
696
754
  if (!ORIGINAL_DEFINE_PROPERTY) return;
@@ -1712,12 +1770,25 @@ function installWorldTime() {
1712
1770
  const worldMs = () => { const c = clock(); return c ? clockNowMs(c, machineNow()) : machineNow(); };
1713
1771
  // the machine's own Date, wrapped rather than subclassed, so identity holds everywhere: dates Node makes itself
1714
1772
  // (a file's mtime, structuredClone, a worker's message) are `instanceof Date`, `d.constructor === Date` stays true,
1715
- // and Date.prototype is the machine's; only now() and argument-less construction read the World's time
1716
- const WorldDate = new Proxy(MachineDate, {
1717
- construct: (target, args, newTarget) => Reflect.construct(target, args.length ? args : [worldMs()], newTarget === WorldDate ? target : newTarget),
1773
+ // and Date.prototype is the machine's; only now() and argument-less construction read the World's time. A bound
1774
+ // function, not a Proxy: every `new Date(x)` of the app (a driver decoding dates) ran the Proxy's construct trap,
1775
+ // ~15 ms of self time on LibreChat's server start in the tab (S2). Bound, so Function.prototype.toString of Date
1776
+ // says "function () { [native code] }", as the Proxy's did; a bound function constructs its target with the target
1777
+ // as new.target, and a subclass's own new.target passes through. Its prototype is the machine's; its own keys are
1778
+ // the machine's Date's (length, name, prototype, now, parse, UTC), `now` the World's.
1779
+ const worldDate = function Date(...args) {
1718
1780
  // called as a function, Date() answers the current time's string, as the machine's does
1719
- apply: () => new MachineDate(worldMs()).toString(),
1720
- });
1781
+ if (new.target === undefined) return new MachineDate(worldMs()).toString();
1782
+ return Reflect.construct(MachineDate, args.length ? args : [worldMs()], new.target === worldDate ? MachineDate : new.target);
1783
+ };
1784
+ worldDate.prototype = MachineDate.prototype;
1785
+ const WorldDate = worldDate.bind(undefined);
1786
+ Object.defineProperty(WorldDate, 'name', { value: 'Date', configurable: true });
1787
+ Object.defineProperty(WorldDate, 'length', { value: MachineDate.length, configurable: true });
1788
+ Object.defineProperty(WorldDate, 'prototype', { value: MachineDate.prototype });
1789
+ for (const [key, value] of [['now', worldMs], ['parse', MachineDate.parse], ['UTC', MachineDate.UTC]]) {
1790
+ Object.defineProperty(WorldDate, key, { value, writable: true, configurable: true, enumerable: false });
1791
+ }
1721
1792
  Object.defineProperty(globalThis, Symbol.for('volter.machineDateNow'), { value: machineNow, enumerable: false });
1722
1793
  MachineDate.now = worldMs;
1723
1794
  Object.defineProperty(MachineDate.prototype, 'constructor', { value: WorldDate, writable: true, configurable: true, enumerable: false });
@@ -1780,17 +1851,12 @@ function installMiniflareOutbound() {
1780
1851
  };
1781
1852
  return Array.isArray(options.workers) ? { ...options, workers: options.workers.map(worker) } : worker(options);
1782
1853
  };
1783
- const originalLoad = Module._load;
1784
- const seen = new WeakMap();
1785
- Module._load = function volterMiniflareLoad(request, parent) {
1786
- const exports = originalLoad.apply(this, arguments);
1787
- if (request !== 'miniflare' || !exports || typeof exports.Miniflare !== 'function' || exports.Miniflare.__volterRouted) return exports;
1788
- if (seen.has(exports)) return seen.get(exports);
1789
- if (!outbound) {
1790
- let at = null;
1791
- try { at = Module._resolveFilename(request, parent); } catch { at = null; }
1792
- outbound = outboundFor(at, exports.fetch);
1793
- }
1854
+ // The package's own entry (miniflare's `main`, dist/src/index.js), patched as it loads (PACKAGE ENTRIES).
1855
+ patchPackageEntry(/[\\/]node_modules[\\/]miniflare[\\/]dist[\\/]src[\\/]index\.js$/, (module, filename) => {
1856
+ const exports = module.exports;
1857
+ if (!exports || typeof exports.Miniflare !== 'function' || exports.Miniflare.__volterRouted) return;
1858
+ // the entry is the file `require('miniflare')` resolved to: its undici is the one beside it
1859
+ if (!outbound) outbound = outboundFor(filename, exports.fetch);
1794
1860
  const Original = exports.Miniflare;
1795
1861
  class Miniflare extends Original {
1796
1862
  constructor(options) { super(routed(options)); }
@@ -1799,10 +1865,8 @@ function installMiniflareOutbound() {
1799
1865
  Miniflare.__volterRouted = true;
1800
1866
  // miniflare's build exports `Miniflare` as a getter that can be neither assigned nor redefined: its importer is given
1801
1867
  // a view of the module whose `Miniflare` is this one, the same view each time it is required.
1802
- const view = new Proxy(exports, { get: (target, key, receiver) => (key === 'Miniflare' ? Miniflare : Reflect.get(target, key, receiver)) });
1803
- seen.set(exports, view);
1804
- return view;
1805
- };
1868
+ module.exports = new Proxy(exports, { get: (target, key, receiver) => (key === 'Miniflare' ? Miniflare : Reflect.get(target, key, receiver)) });
1869
+ });
1806
1870
  }
1807
1871
 
1808
1872
  // Auto-install as a preload (`--require`); strict refusal also applies without twin URLs.
@@ -141,6 +141,21 @@ export declare function appendActionOccurrence(base: TwinAction, root?: string):
141
141
  appended: boolean;
142
142
  placeholder?: true;
143
143
  };
144
+ /**
145
+ * Append several writes of ONE service as occurrences, in order, under one projection + actions lock and as one store
146
+ * append: each lands with the id, ordinal and correlation `appendActionOccurrence` would give it called once per write
147
+ * in the same order (a write's ordinal counts the batch's earlier writes as taken). A Redis run's flush made one
148
+ * append per changed member and key, each taking the history, projection and actions locks and appending alone, one
149
+ * after another under the twin's single command queue (S2 R19: Twenty's queue scripts spent up to 2.1 s of a 2 s
150
+ * window in flush while 38 commands waited). A write carrying preconditions is not taken here: each is checked against
151
+ * the state the earlier ones made, which only the one-at-a-time path sees. While a placeholder pull is open a write
152
+ * lands as observed events, as `appendActionOccurrence`'s does.
153
+ */
154
+ export declare function appendActionOccurrences(bases: readonly TwinAction[], root?: string): Array<{
155
+ action: TwinAction;
156
+ appended: boolean;
157
+ placeholder?: true;
158
+ }>;
144
159
  /** Occurrence 0 IS the base id — so nothing that exists today changes shape. The appender owns
145
160
  * this math; a caller passing an already-ordinalled id would stack them (`…#1#1`). */
146
161
  export declare function occurrenceId(base: string, ordinal: number): string;