@volter/twin-standard 1.0.135 → 1.0.136

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/README.md CHANGED
@@ -20,6 +20,10 @@ twin-standard assess <pack dir> --prepared-consumer <json> [--browser] [--out <f
20
20
  twin-standard --version # this package's version and each standard's
21
21
  ```
22
22
 
23
+ The commands run with this package and its `@volter/world-core` peer installed. `@volter/world-runtime` is an
24
+ optional peer, needed only to serve or walk a pack whose descriptor declares a `managedDatabase` (`conform`, `assess`):
25
+ install it beside this package for those, which name it when it is absent.
26
+
23
27
  What each criterion asks, and the rules for changing one, are twin-world's
24
28
  [architecture, "The grade"](https://github.com/volter-ai/twin-world/blob/main/docs/contributing/architecture.md#the-grade).
25
29
  A changed criterion is a release of this package: a criterion's id never changes meaning; a changed criterion takes a
@@ -5,10 +5,18 @@ import { createServer } from 'node:net';
5
5
  import { tmpdir } from 'node:os';
6
6
  import { createRequire } from 'node:module';
7
7
  import { dirname, extname, join } from 'node:path';
8
- import { runWorld, setWorldClock, worldConfigDocument } from '@volter/world-runtime';
9
8
  import { worldNow } from '@volter/world-core/runtime';
10
- const runtimeEntry = createRequire(import.meta.url).resolve('@volter/world-runtime');
11
- const infrastructureCli = join(dirname(runtimeEntry), `infra-cli${extname(runtimeEntry)}`);
9
+ let loaded;
10
+ const worldRuntime = () => loaded ??= (async () => {
11
+ let entry;
12
+ try {
13
+ entry = createRequire(import.meta.url).resolve('@volter/world-runtime');
14
+ }
15
+ catch {
16
+ throw new Error('A managed database walk needs @volter/world-runtime installed beside @volter/twin-standard: npm i @volter/world-runtime');
17
+ }
18
+ return { runtime: await import('@volter/world-runtime'), infrastructureCli: join(dirname(entry), `infra-cli${extname(entry)}`) };
19
+ })();
12
20
  async function freePort() {
13
21
  return new Promise((done, fail) => {
14
22
  const server = createServer();
@@ -26,6 +34,7 @@ let declaredHeld = false;
26
34
  export async function startPgliteHost() {
27
35
  if (!process.env.VOLTER_WORLD)
28
36
  throw new Error('A managed database walk requires its enclosing World');
37
+ const { runtime: { runWorld, setWorldClock, worldConfigDocument }, infrastructureCli } = await worldRuntime();
29
38
  const root = mkdtempSync(join(tmpdir(), 'walk-database-world-'));
30
39
  const name = 'pack-walk-postgres';
31
40
  const port = declaredPort !== undefined && !declaredHeld ? declaredPort : await freePort();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/twin-standard",
3
- "version": "1.0.135",
3
+ "version": "1.0.136",
4
4
  "description": "The Protocol 3 standard for Volter twin packs: the criteria a pack is graded by, the grader, the gate a pack repository and the twin catalog run on every change and submission, and the spec derivation the grade checks against. Pin a version: every place a pack is judged judges by that standard.",
5
5
  "keywords": [
6
6
  "twin",
@@ -75,7 +75,7 @@
75
75
  "yaml": "2.9.0"
76
76
  },
77
77
  "peerDependencies": {
78
- "@volter/world-core": "3.0.143",
78
+ "@volter/world-core": "3.0.144",
79
79
  "@volter/world-runtime": "*",
80
80
  "playwright": "^1.63.0"
81
81
  },
@@ -5,11 +5,18 @@ import { createServer } from 'node:net';
5
5
  import { tmpdir } from 'node:os';
6
6
  import { createRequire } from 'node:module';
7
7
  import { dirname, extname, join } from 'node:path';
8
- import { runWorld, setWorldClock, worldConfigDocument } from '@volter/world-runtime';
9
8
  import { worldNow } from '@volter/world-core/runtime';
10
9
 
11
- const runtimeEntry = createRequire(import.meta.url).resolve('@volter/world-runtime');
12
- const infrastructureCli = join(dirname(runtimeEntry), `infra-cli${extname(runtimeEntry)}`);
10
+ // The runtime is this package's optional peer: only a walk over a managed database needs it, so it is loaded here, on
11
+ // that walk's first database, and every command that starts none runs with the standard alone installed.
12
+ type Runtime = typeof import('@volter/world-runtime');
13
+ let loaded: Promise<{ runtime: Runtime; infrastructureCli: string }> | undefined;
14
+ const worldRuntime = () => loaded ??= (async () => {
15
+ let entry: string;
16
+ try { entry = createRequire(import.meta.url).resolve('@volter/world-runtime'); }
17
+ catch { throw new Error('A managed database walk needs @volter/world-runtime installed beside @volter/twin-standard: npm i @volter/world-runtime'); }
18
+ return { runtime: await import('@volter/world-runtime'), infrastructureCli: join(dirname(entry), `infra-cli${extname(entry)}`) };
19
+ })();
13
20
 
14
21
  async function freePort(): Promise<number> {
15
22
  return new Promise((done, fail) => {
@@ -31,6 +38,7 @@ let declaredHeld = false;
31
38
 
32
39
  export async function startPgliteHost(): Promise<PgliteHost> {
33
40
  if (!process.env.VOLTER_WORLD) throw new Error('A managed database walk requires its enclosing World');
41
+ const { runtime: { runWorld, setWorldClock, worldConfigDocument }, infrastructureCli } = await worldRuntime();
34
42
  const root = mkdtempSync(join(tmpdir(), 'walk-database-world-'));
35
43
  const name = 'pack-walk-postgres';
36
44
  const port = declaredPort !== undefined && !declaredHeld ? declaredPort : await freePort();
@@ -67,7 +75,7 @@ export async function startPgliteHost(): Promise<PgliteHost> {
67
75
  writeFileSync(ready + '.tmp', JSON.stringify({ url: process.env.DATABASE_URL }));
68
76
  renameSync(ready + '.tmp', ready);
69
77
  done();`;
70
- let finished: { result?: Awaited<ReturnType<typeof runWorld>>; error?: unknown; failed: boolean } | undefined;
78
+ let finished: { result?: Awaited<ReturnType<Runtime['runWorld']>>; error?: unknown; failed: boolean } | undefined;
71
79
  const task = runWorld(config, [process.execPath, '--input-type=module', '-e', hold, readyFile, releaseFile], {
72
80
  root, cwd: root, owner: 'pack-walk-managed-database',
73
81
  }).then(result => { finished = { result, failed: false }; return result; }, error => {