import { Loader, Memory, type Custody, type Module } from '../contract/index.ts'; import { type Defaults, type Harbor } from '../harbor/index.ts'; import { BundleLoader, World } from '../pointer/index.ts'; import type { Expect } from './expect.ts'; export type Bodies = { custody: Custody; memory: Memory; }; export type Terrain = { name: string; make(): Bodies; again(bodies: Bodies): Bodies; loader?: () => Loader; defaults: Defaults; }; export declare const LAW = "import { Being, Dock, Faculty, MemoryFaculty, ownerAsk, Ward } from 'nervur';\n\nexport const module = 'org.example.law';\nexport const version = '1';\n\nclass Echoes extends Faculty {\n static kind = 'org.example.echoes';\n}\nclass Echo extends Echoes {\n static kind = 'org.example.echo';\n static asks = { echo: {} };\n echo(args, asker) {\n return { echoed: args.text ?? null, to: asker.id ?? null };\n }\n}\n\nclass Shop extends Being {\n static kind = 'org.example.shop';\n static cells = { sold: [] };\n static asks = { buy: {}, sold: {} };\n buy(args, asker) {\n this.cells.sold.push(String(args.item) + ' to ' + (asker.id ?? 'nobody'));\n return { bought: args.item ?? null };\n }\n sold() {\n return { sold: this.cells.sold };\n }\n}\n\nclass Customer extends Being {\n static kind = 'org.example.customer';\n static asks = { join: {}, buy: {}, echo: {}, spoil: {} };\n spoil() {\n try {\n this.cells.when = new Date();\n return { kept: true };\n } catch {\n return { refused: true };\n }\n }\n async join(args) {\n return { joined: await this.stance.standings.take('shop', args.invitation) };\n }\n async buy(args) {\n return { said: (await this.stance.standings.get('shop')?.ask('buy', args)) ?? null };\n }\n async echo(args) {\n if (!this.stance.standings.get('echo')) await this.stance.lend(Echoes, 'echo');\n return { said: (await this.stance.standings.get('echo')?.ask('echo', args)) ?? null };\n }\n}\n\n// A being whose fields are her cells, and nothing else.\nclass Profile extends Being {\n static kind = 'org.example.profile';\n static cells = { name: '', age: 0 };\n static asks = { set: {}, get: {} };\n set(args) {\n if (typeof args.name === 'string') this.cells.name = args.name;\n if (typeof args.age === 'number') this.cells.age = args.age;\n return this.get();\n }\n get() {\n return { name: this.cells.name ?? null, age: this.cells.age ?? null };\n }\n}\n\n// A memory faculty a module brings: places on a shelf of this process, by\n// the faculty's key, which outlive a harbor as a database outlives its\n// client.\nconst shelf = (key) => globalThis[Symbol.for('org.example.shelf')](key);\nclass Shelf extends MemoryFaculty {\n static kind = 'org.example.shelf';\n read(place) {\n return shelf(this.stance.key).read(place);\n }\n write(place, entries) {\n return shelf(this.stance.key).write(place, entries);\n }\n places() {\n return shelf(this.stance.key).places();\n }\n forget(place) {\n return shelf(this.stance.key).forget(place);\n }\n}\n\n// A ward and a dock a module brings, each with an ask of her own.\nclass Steward extends Ward {\n static kind = 'org.example.steward';\n static asks = { ...Ward.asks, sign: ownerAsk('a signature of this ward') };\n sign() {\n return { signed: this.steward.pk() };\n }\n}\nclass Quay extends Dock {\n static kind = 'org.example.quay';\n static asks = { ...Dock.asks, moor: ownerAsk('the wards moored here') };\n moor() {\n return { moored: this.hosted.map((h) => h.ward) };\n }\n}\n\nexport const classes = [Echo, Shop, Customer, Profile, Shelf, Steward, Quay];\n"; export declare const law: { readonly module: 'org.example.law'; readonly version: '1'; readonly source: "import { Being, Dock, Faculty, MemoryFaculty, ownerAsk, Ward } from 'nervur';\n\nexport const module = 'org.example.law';\nexport const version = '1';\n\nclass Echoes extends Faculty {\n static kind = 'org.example.echoes';\n}\nclass Echo extends Echoes {\n static kind = 'org.example.echo';\n static asks = { echo: {} };\n echo(args, asker) {\n return { echoed: args.text ?? null, to: asker.id ?? null };\n }\n}\n\nclass Shop extends Being {\n static kind = 'org.example.shop';\n static cells = { sold: [] };\n static asks = { buy: {}, sold: {} };\n buy(args, asker) {\n this.cells.sold.push(String(args.item) + ' to ' + (asker.id ?? 'nobody'));\n return { bought: args.item ?? null };\n }\n sold() {\n return { sold: this.cells.sold };\n }\n}\n\nclass Customer extends Being {\n static kind = 'org.example.customer';\n static asks = { join: {}, buy: {}, echo: {}, spoil: {} };\n spoil() {\n try {\n this.cells.when = new Date();\n return { kept: true };\n } catch {\n return { refused: true };\n }\n }\n async join(args) {\n return { joined: await this.stance.standings.take('shop', args.invitation) };\n }\n async buy(args) {\n return { said: (await this.stance.standings.get('shop')?.ask('buy', args)) ?? null };\n }\n async echo(args) {\n if (!this.stance.standings.get('echo')) await this.stance.lend(Echoes, 'echo');\n return { said: (await this.stance.standings.get('echo')?.ask('echo', args)) ?? null };\n }\n}\n\n// A being whose fields are her cells, and nothing else.\nclass Profile extends Being {\n static kind = 'org.example.profile';\n static cells = { name: '', age: 0 };\n static asks = { set: {}, get: {} };\n set(args) {\n if (typeof args.name === 'string') this.cells.name = args.name;\n if (typeof args.age === 'number') this.cells.age = args.age;\n return this.get();\n }\n get() {\n return { name: this.cells.name ?? null, age: this.cells.age ?? null };\n }\n}\n\n// A memory faculty a module brings: places on a shelf of this process, by\n// the faculty's key, which outlive a harbor as a database outlives its\n// client.\nconst shelf = (key) => globalThis[Symbol.for('org.example.shelf')](key);\nclass Shelf extends MemoryFaculty {\n static kind = 'org.example.shelf';\n read(place) {\n return shelf(this.stance.key).read(place);\n }\n write(place, entries) {\n return shelf(this.stance.key).write(place, entries);\n }\n places() {\n return shelf(this.stance.key).places();\n }\n forget(place) {\n return shelf(this.stance.key).forget(place);\n }\n}\n\n// A ward and a dock a module brings, each with an ask of her own.\nclass Steward extends Ward {\n static kind = 'org.example.steward';\n static asks = { ...Ward.asks, sign: ownerAsk('a signature of this ward') };\n sign() {\n return { signed: this.steward.pk() };\n }\n}\nclass Quay extends Dock {\n static kind = 'org.example.quay';\n static asks = { ...Dock.asks, moor: ownerAsk('the wards moored here') };\n moor() {\n return { moored: this.hosted.map((h) => h.ward) };\n }\n}\n\nexport const classes = [Echo, Shop, Customer, Profile, Shelf, Steward, Quay];\n"; }; export declare const lawBundle: (module: Module) => BundleLoader; export declare const standOne: (world: World, name: string, t: Terrain, parts?: Partial) => Promise; export declare const lawScenes: (t: Terrain, expect: Expect) => [string, () => Promise][]; export declare const keeperScenes: (t: Terrain, expect: Expect) => [string, () => Promise][];