@volter/world-runtime 3.0.87 → 3.0.88

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.
package/dist/src/init.js CHANGED
@@ -1158,66 +1158,58 @@ export async function seed(): Promise<void> {
1158
1158
  if ((process.env.VOLTER_SEED_SKIP ?? '').split(',').includes('${vendor}')) return;
1159
1159
  const base = process.env.${stem}_TWIN_URL;
1160
1160
  if (!base) throw new Error('${stem}_TWIN_URL is not set — bring the world up and run the seed with its env (volter-world attach/run)');
1161
- <<<<<<< HEAD
1162
- // a call dated before the World's time (\`at\`: state the account made then, through the API as it was) is made with
1163
- // the World's clock frozen at that instant, and the clock is put back as it was found
1161
+ const clients = new Map<string, SeedBrowser>();
1162
+ const snapshots = new Map<string, Awaited<ReturnType<SeedBrowser['state']>>>();
1163
+ let browserHelper: typeof import('@volter/world-core/browser') | undefined;
1164
+ const browserCalls = ('browserSeed' in defaults ? defaults.browserSeed as typeof calls : undefined) ?? [];
1165
+ const requests = [...calls, ...browserCalls];
1164
1166
  const clock = process.env.TWIN_WORLD_CLOCK_FILE;
1165
- const found = clock && existsSync(clock) ? readFileSync(clock, 'utf8') : undefined;
1167
+ const dated = requests.some(call => call.at !== undefined);
1168
+ const found = dated && clock && existsSync(clock) ? readFileSync(clock, 'utf8') : undefined;
1169
+ const restoreClock = (): void => {
1170
+ if (!dated || !clock) return;
1171
+ if (found === undefined) rmSync(clock, { force: true }); else writeFileSync(clock, found);
1172
+ };
1166
1173
  try {
1167
- for (const call of calls) {
1174
+ for (const call of requests) {
1168
1175
  if (call.at !== undefined) {
1169
1176
  if (!clock) throw new Error('${vendor} seed: a dated call needs the World clock (TWIN_WORLD_CLOCK_FILE): run the seed attached to the World');
1170
1177
  writeFileSync(clock, \`\${new Date(call.at).toISOString()}\n\`);
1178
+ } else restoreClock();
1179
+ if (call.browser) {
1180
+ if (!snapshots.has(call.browser)) {
1181
+ const door = process.env.VOLTER_WORLD_BROWSER_DOOR;
1182
+ const token = process.env.VOLTER_WORLD_BROWSER_TOKEN;
1183
+ if (!door || !token) throw new Error('browser defaults run in a World seed with its browsers door and credential');
1184
+ const held = await fetch(\`\${door}/\${encodeURIComponent(call.browser)}\`, { headers: { 'x-volter-token': token } });
1185
+ if (!held.ok && held.status !== 404) throw new Error(\`browser \${call.browser}: \${held.status} \${await held.text()}\`);
1186
+ snapshots.set(call.browser, held.ok ? await held.json() as Awaited<ReturnType<SeedBrowser['state']>> : { storageState: { cookies: [], origins: [] }, context: {} });
1187
+ }
1188
+ browserHelper ??= await import('@volter/world-core/browser').catch(error => {
1189
+ throw new Error('Install @volter/world-core 3.0.37 or later in this project to seed browsers.', { cause: error });
1190
+ });
1191
+ const initial = snapshots.get(call.browser)!;
1192
+ const hostname = new URL(call.path).hostname;
1193
+ if (initial.storageState.cookies.some(cookie => browserHelper!.cookieMatchesHost(cookie, hostname))
1194
+ || initial.storageState.origins.some(origin => new URL(origin.origin).hostname === hostname)) continue;
1195
+ }
1196
+ const headers = { ...(call.body !== undefined ? { 'content-type': 'application/json' } : {}), ...(call.headers ?? {}) };
1197
+ const form = /^application\\/x-www-form-urlencoded\\b/i.test(new Headers(headers).get('content-type') ?? '');
1198
+ const body = call.body === undefined ? undefined : form
1199
+ ? new URLSearchParams(Object.entries(call.body as Record<string, unknown>).map(([key, value]) => [key, String(value)]))
1200
+ : JSON.stringify(call.body);
1201
+ if (call.browser && !clients.has(call.browser)) {
1202
+ clients.set(call.browser, await browserHelper!.browser(call.browser));
1171
1203
  }
1172
- const res = await fetch(\`\${base.replace(/\\/$/, '')}\${call.path}\`, {
1204
+ const client = call.browser ? clients.get(call.browser)! : null;
1205
+ const res = await (client ? client.fetch : fetch)(client ? call.path : \`\${base.replace(/\\/$/, '')}\${call.path}\`, {
1173
1206
  method: call.method,
1174
- headers: { ...(call.body !== undefined ? { 'content-type': 'application/json' } : {}), ...(call.headers ?? {}) },
1175
- ...(call.body !== undefined ? { body: JSON.stringify(call.body) } : {}),
1207
+ headers, ...(body === undefined ? {} : { body }),
1176
1208
  });
1177
1209
  if (!res.ok) throw new Error(\`${vendor} seed: \${call.method} \${call.path}: \${res.status} \${await res.text()}\`);
1178
1210
  }
1179
1211
  } finally {
1180
- if (clock && calls.some((call) => call.at !== undefined)) {
1181
- if (found === undefined) rmSync(clock, { force: true }); else writeFileSync(clock, found);
1182
- }
1183
- =======
1184
- const clients = new Map<string, SeedBrowser>();
1185
- const snapshots = new Map<string, Awaited<ReturnType<SeedBrowser['state']>>>();
1186
- let browserHelper: typeof import('@volter/world-core/browser') | undefined;
1187
- const browserCalls = ('browserSeed' in defaults ? defaults.browserSeed as typeof calls : undefined) ?? [];
1188
- for (const call of [...calls, ...browserCalls]) {
1189
- if (call.browser) {
1190
- if (!snapshots.has(call.browser)) {
1191
- const door = process.env.VOLTER_WORLD_BROWSER_DOOR;
1192
- const token = process.env.VOLTER_WORLD_BROWSER_TOKEN;
1193
- if (!door || !token) throw new Error('browser defaults run in a World seed with its browsers door and credential');
1194
- const held = await fetch(\`\${door}/\${encodeURIComponent(call.browser)}\`, { headers: { 'x-volter-token': token } });
1195
- if (!held.ok && held.status !== 404) throw new Error(\`browser \${call.browser}: \${held.status} \${await held.text()}\`);
1196
- snapshots.set(call.browser, held.ok ? await held.json() as Awaited<ReturnType<SeedBrowser['state']>> : { storageState: { cookies: [], origins: [] }, context: {} });
1197
- }
1198
- browserHelper ??= await import('@volter/world-core/browser').catch(error => {
1199
- throw new Error('Install @volter/world-core 3.0.37 or later in this project to seed browsers.', { cause: error });
1200
- });
1201
- const initial = snapshots.get(call.browser)!;
1202
- const hostname = new URL(call.path).hostname;
1203
- if (initial.storageState.cookies.some(cookie => browserHelper!.cookieMatchesHost(cookie, hostname))
1204
- || initial.storageState.origins.some(origin => new URL(origin.origin).hostname === hostname)) continue;
1205
- }
1206
- const headers = { ...(call.body !== undefined ? { 'content-type': 'application/json' } : {}), ...(call.headers ?? {}) };
1207
- const form = /^application\\/x-www-form-urlencoded\\b/i.test(new Headers(headers).get('content-type') ?? '');
1208
- const body = call.body === undefined ? undefined : form
1209
- ? new URLSearchParams(Object.entries(call.body as Record<string, unknown>).map(([key, value]) => [key, String(value)]))
1210
- : JSON.stringify(call.body);
1211
- if (call.browser && !clients.has(call.browser)) {
1212
- clients.set(call.browser, await browserHelper!.browser(call.browser));
1213
- }
1214
- const client = call.browser ? clients.get(call.browser)! : null;
1215
- const res = await (client ? client.fetch : fetch)(client ? call.path : \`\${base.replace(/\\/$/, '')}\${call.path}\`, {
1216
- method: call.method,
1217
- headers, ...(body === undefined ? {} : { body }),
1218
- });
1219
- if (!res.ok) throw new Error(\`${vendor} seed: \${call.method} \${call.path}: \${res.status} \${await res.text()}\`);
1220
- >>>>>>> origin/main
1212
+ restoreClock();
1221
1213
  }
1222
1214
  }
1223
1215
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/world-runtime",
3
- "version": "3.0.87",
3
+ "version": "3.0.88",
4
4
  "description": "World configs for twins: boot named local runtimes, allocate ports, generate world.env/instance.json, and run apps against fake-key twin worlds.",
5
5
  "keywords": [
6
6
  "twin",
@@ -69,14 +69,14 @@
69
69
  "node": ">=22.3"
70
70
  },
71
71
  "peerDependencies": {
72
- "@volter/world-core": "3.0.87",
73
- "@volter/world-console": "3.0.82"
72
+ "@volter/world-core": "3.0.88",
73
+ "@volter/world-console": "3.0.83"
74
74
  },
75
75
  "dependencies": {
76
76
  "@electric-sql/pglite": "0.5.8",
77
77
  "@electric-sql/pglite-pgvector": "0.0.9",
78
78
  "@volter/world-access": "3.0.1",
79
- "@volter/world-core": "3.0.87",
79
+ "@volter/world-core": "3.0.88",
80
80
  "mongodb": "~6.20.0",
81
81
  "pg-gateway": "0.3.0-beta.4",
82
82
  "smol-toml": "^1.8.0",
package/src/init.ts CHANGED
@@ -1347,66 +1347,58 @@ export async function seed(): Promise<void> {
1347
1347
  if ((process.env.VOLTER_SEED_SKIP ?? '').split(',').includes('${vendor}')) return;
1348
1348
  const base = process.env.${stem}_TWIN_URL;
1349
1349
  if (!base) throw new Error('${stem}_TWIN_URL is not set — bring the world up and run the seed with its env (volter-world attach/run)');
1350
- <<<<<<< HEAD
1351
- // a call dated before the World's time (\`at\`: state the account made then, through the API as it was) is made with
1352
- // the World's clock frozen at that instant, and the clock is put back as it was found
1350
+ const clients = new Map<string, SeedBrowser>();
1351
+ const snapshots = new Map<string, Awaited<ReturnType<SeedBrowser['state']>>>();
1352
+ let browserHelper: typeof import('@volter/world-core/browser') | undefined;
1353
+ const browserCalls = ('browserSeed' in defaults ? defaults.browserSeed as typeof calls : undefined) ?? [];
1354
+ const requests = [...calls, ...browserCalls];
1353
1355
  const clock = process.env.TWIN_WORLD_CLOCK_FILE;
1354
- const found = clock && existsSync(clock) ? readFileSync(clock, 'utf8') : undefined;
1356
+ const dated = requests.some(call => call.at !== undefined);
1357
+ const found = dated && clock && existsSync(clock) ? readFileSync(clock, 'utf8') : undefined;
1358
+ const restoreClock = (): void => {
1359
+ if (!dated || !clock) return;
1360
+ if (found === undefined) rmSync(clock, { force: true }); else writeFileSync(clock, found);
1361
+ };
1355
1362
  try {
1356
- for (const call of calls) {
1363
+ for (const call of requests) {
1357
1364
  if (call.at !== undefined) {
1358
1365
  if (!clock) throw new Error('${vendor} seed: a dated call needs the World clock (TWIN_WORLD_CLOCK_FILE): run the seed attached to the World');
1359
1366
  writeFileSync(clock, \`\${new Date(call.at).toISOString()}\n\`);
1367
+ } else restoreClock();
1368
+ if (call.browser) {
1369
+ if (!snapshots.has(call.browser)) {
1370
+ const door = process.env.VOLTER_WORLD_BROWSER_DOOR;
1371
+ const token = process.env.VOLTER_WORLD_BROWSER_TOKEN;
1372
+ if (!door || !token) throw new Error('browser defaults run in a World seed with its browsers door and credential');
1373
+ const held = await fetch(\`\${door}/\${encodeURIComponent(call.browser)}\`, { headers: { 'x-volter-token': token } });
1374
+ if (!held.ok && held.status !== 404) throw new Error(\`browser \${call.browser}: \${held.status} \${await held.text()}\`);
1375
+ snapshots.set(call.browser, held.ok ? await held.json() as Awaited<ReturnType<SeedBrowser['state']>> : { storageState: { cookies: [], origins: [] }, context: {} });
1376
+ }
1377
+ browserHelper ??= await import('@volter/world-core/browser').catch(error => {
1378
+ throw new Error('Install @volter/world-core 3.0.37 or later in this project to seed browsers.', { cause: error });
1379
+ });
1380
+ const initial = snapshots.get(call.browser)!;
1381
+ const hostname = new URL(call.path).hostname;
1382
+ if (initial.storageState.cookies.some(cookie => browserHelper!.cookieMatchesHost(cookie, hostname))
1383
+ || initial.storageState.origins.some(origin => new URL(origin.origin).hostname === hostname)) continue;
1384
+ }
1385
+ const headers = { ...(call.body !== undefined ? { 'content-type': 'application/json' } : {}), ...(call.headers ?? {}) };
1386
+ const form = /^application\\/x-www-form-urlencoded\\b/i.test(new Headers(headers).get('content-type') ?? '');
1387
+ const body = call.body === undefined ? undefined : form
1388
+ ? new URLSearchParams(Object.entries(call.body as Record<string, unknown>).map(([key, value]) => [key, String(value)]))
1389
+ : JSON.stringify(call.body);
1390
+ if (call.browser && !clients.has(call.browser)) {
1391
+ clients.set(call.browser, await browserHelper!.browser(call.browser));
1360
1392
  }
1361
- const res = await fetch(\`\${base.replace(/\\/$/, '')}\${call.path}\`, {
1393
+ const client = call.browser ? clients.get(call.browser)! : null;
1394
+ const res = await (client ? client.fetch : fetch)(client ? call.path : \`\${base.replace(/\\/$/, '')}\${call.path}\`, {
1362
1395
  method: call.method,
1363
- headers: { ...(call.body !== undefined ? { 'content-type': 'application/json' } : {}), ...(call.headers ?? {}) },
1364
- ...(call.body !== undefined ? { body: JSON.stringify(call.body) } : {}),
1396
+ headers, ...(body === undefined ? {} : { body }),
1365
1397
  });
1366
1398
  if (!res.ok) throw new Error(\`${vendor} seed: \${call.method} \${call.path}: \${res.status} \${await res.text()}\`);
1367
1399
  }
1368
1400
  } finally {
1369
- if (clock && calls.some((call) => call.at !== undefined)) {
1370
- if (found === undefined) rmSync(clock, { force: true }); else writeFileSync(clock, found);
1371
- }
1372
- =======
1373
- const clients = new Map<string, SeedBrowser>();
1374
- const snapshots = new Map<string, Awaited<ReturnType<SeedBrowser['state']>>>();
1375
- let browserHelper: typeof import('@volter/world-core/browser') | undefined;
1376
- const browserCalls = ('browserSeed' in defaults ? defaults.browserSeed as typeof calls : undefined) ?? [];
1377
- for (const call of [...calls, ...browserCalls]) {
1378
- if (call.browser) {
1379
- if (!snapshots.has(call.browser)) {
1380
- const door = process.env.VOLTER_WORLD_BROWSER_DOOR;
1381
- const token = process.env.VOLTER_WORLD_BROWSER_TOKEN;
1382
- if (!door || !token) throw new Error('browser defaults run in a World seed with its browsers door and credential');
1383
- const held = await fetch(\`\${door}/\${encodeURIComponent(call.browser)}\`, { headers: { 'x-volter-token': token } });
1384
- if (!held.ok && held.status !== 404) throw new Error(\`browser \${call.browser}: \${held.status} \${await held.text()}\`);
1385
- snapshots.set(call.browser, held.ok ? await held.json() as Awaited<ReturnType<SeedBrowser['state']>> : { storageState: { cookies: [], origins: [] }, context: {} });
1386
- }
1387
- browserHelper ??= await import('@volter/world-core/browser').catch(error => {
1388
- throw new Error('Install @volter/world-core 3.0.37 or later in this project to seed browsers.', { cause: error });
1389
- });
1390
- const initial = snapshots.get(call.browser)!;
1391
- const hostname = new URL(call.path).hostname;
1392
- if (initial.storageState.cookies.some(cookie => browserHelper!.cookieMatchesHost(cookie, hostname))
1393
- || initial.storageState.origins.some(origin => new URL(origin.origin).hostname === hostname)) continue;
1394
- }
1395
- const headers = { ...(call.body !== undefined ? { 'content-type': 'application/json' } : {}), ...(call.headers ?? {}) };
1396
- const form = /^application\\/x-www-form-urlencoded\\b/i.test(new Headers(headers).get('content-type') ?? '');
1397
- const body = call.body === undefined ? undefined : form
1398
- ? new URLSearchParams(Object.entries(call.body as Record<string, unknown>).map(([key, value]) => [key, String(value)]))
1399
- : JSON.stringify(call.body);
1400
- if (call.browser && !clients.has(call.browser)) {
1401
- clients.set(call.browser, await browserHelper!.browser(call.browser));
1402
- }
1403
- const client = call.browser ? clients.get(call.browser)! : null;
1404
- const res = await (client ? client.fetch : fetch)(client ? call.path : \`\${base.replace(/\\/$/, '')}\${call.path}\`, {
1405
- method: call.method,
1406
- headers, ...(body === undefined ? {} : { body }),
1407
- });
1408
- if (!res.ok) throw new Error(\`${vendor} seed: \${call.method} \${call.path}: \${res.status} \${await res.text()}\`);
1409
- >>>>>>> origin/main
1401
+ restoreClock();
1410
1402
  }
1411
1403
  }
1412
1404
  `;