@nervur.org/installer-node 0.37.5 → 0.37.6
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/cargo/worker.js +128 -45
- package/organs/network/node/lines.js +1 -1
- package/package.json +3 -3
- package/src/command/given.js +2 -2
- package/src/fills/keepers.js +1 -1
- package/src/organism/folder.js +2 -2
- package/src/version/version.js +1 -1
- package/src/ws/dialing.js +1 -1
package/cargo/worker.js
CHANGED
|
@@ -2636,7 +2636,7 @@ var checkBlueprint = (value, node2, longest) => {
|
|
|
2636
2636
|
};
|
|
2637
2637
|
};
|
|
2638
2638
|
|
|
2639
|
-
var GENOME_VERSION = "0.37.
|
|
2639
|
+
var GENOME_VERSION = "0.37.6";
|
|
2640
2640
|
|
|
2641
2641
|
var endFrame = (asker, method3) => ({ end: { asker, method: method3 } });
|
|
2642
2642
|
|
|
@@ -3696,7 +3696,7 @@ var keepHalf = (gear, id, host, connected, added3, failed) => {
|
|
|
3696
3696
|
|
|
3697
3697
|
var EAR_BLUEPRINT = {
|
|
3698
3698
|
name: "nervur.ear",
|
|
3699
|
-
version: "0.37.
|
|
3699
|
+
version: "0.37.6",
|
|
3700
3700
|
description: "The ear: it opens and seals the boxes of Quo, and the brain keeps every relation.",
|
|
3701
3701
|
methods: {
|
|
3702
3702
|
arrived: {
|
|
@@ -4265,13 +4265,13 @@ var readFaculty = (engine, crypto2, source, memory) => {
|
|
|
4265
4265
|
};
|
|
4266
4266
|
var facultyReaderOn = (engine, crypto2, memory) => (source) => readFaculty(engine.apart(), crypto2, source, memory);
|
|
4267
4267
|
|
|
4268
|
-
var EAR_TEXT = "class Ear extends Faculty {\n static #bytes = {\n type: 'string',\n contentEncoding: 'base16',\n maxLength: 1048576,\n };\n static #arrival = { ...Ear.#bytes, maxLength: 1048576 + 1 };\n static #text = { type: 'string', minLength: 1 };\n static #name = { type: 'string', pattern: '^[0-9a-f]{128}$' };\n static #reference = { type: 'string', pattern: '^[a-z2-7]{26}$' };\n static #says = {\n anyOf: [{ type: 'object' }, { type: 'array' }, { type: 'string' }, { type: 'number' }, { type: 'boolean' }],\n };\n static #again = {\n type: 'object',\n properties: { node: Ear.#text, far: Ear.#text },\n required: ['node', 'far'],\n additionalProperties: false,\n };\n\n static blueprint = {\n name: 'nervur.ear',\n version: '0.37.5',\n description: 'The ear: it opens and seals the boxes of Quo, and the brain keeps every relation.',\n methods: {\n arrived: {\n description:\n \"A box arrived on an exchange, sent to the ward named, the public ward where none is: opened, judged by Quo and handed on, or replied. Answers `{opened: true}` where it handed on an ask it admitted on a relation, so the carrier counts what that ask came on as carried, and null otherwise. The brain's alone, with `answer`: what a node answered of an ask the ear handed on, sealed and replied on its exchange.\",\n kind: 'reading',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: {\n exchange: { type: 'integer', minimum: 0 },\n bytes: Ear.#arrival,\n ward: Ear.#name,\n },\n required: ['exchange', 'bytes'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n exchange: { type: 'integer', minimum: 0 },\n door: {},\n admitted: {},\n front: { type: 'boolean' },\n answer: {},\n },\n required: ['exchange', 'door', 'admitted', 'answer'],\n additionalProperties: false,\n },\n ],\n },\n result: {\n anyOf: [\n { type: 'null' },\n {\n type: 'object',\n properties: { opened: { const: true } },\n required: ['opened'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n named: {\n description:\n \"The brain's alone, for its owners' `addresses`. Keeps the addresses of the organism's own an owner named, in place of those before, beside what `network` reports.\",\n kind: 'writing',\n askers: ['brain'],\n args: {\n type: 'object',\n properties: { at: { type: 'array', items: Ear.#text } },\n required: ['at'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n addresses: {\n description: 'The addresses `network` last reported.',\n kind: 'writing',\n args: {\n type: 'object',\n properties: { addresses: { type: 'array', items: Ear.#text } },\n required: ['addresses'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n line: {\n description:\n 'A line, accepted at an endpoint or held, that names `wards` came up or went down, told by `network` alone. The ear asks the brain `line {wards, up}`, up and down alike: on up the brain asks each lobe granted a standing on one of them `back`, and either way it asks the lobe that gave an occupant drawn through that line `line {far, up}`.',\n kind: 'reading',\n askers: ['network'],\n args: {\n type: 'object',\n properties: { wards: { type: 'array', items: Ear.#name }, up: { type: 'boolean' } },\n required: ['wards', 'up'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n challenged: {\n description:\n 'A line `network` holds to `address` was challenged by its listener with `nonce` and `identity`, told by `network` alone. The ear asks the brain `lines {}` for the wards drawn through that address and `key` `prove {wards, nonce, identity}`, and answers `{proofs: [{ward, proof}]}`, each ward with its proof under that challenge alone; a line the brain holds no ward on is answered with none. It writes no cell.',\n kind: 'reading',\n askers: ['network'],\n args: {\n type: 'object',\n properties: {\n address: { type: 'string', minLength: 1 },\n nonce: { type: 'string', contentEncoding: 'base16', minLength: 32, maxLength: 32 },\n identity: { type: 'string', contentEncoding: 'base16', minLength: 32, maxLength: 32 },\n },\n required: ['address', 'nonce', 'identity'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: {\n proofs: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n ward: Ear.#name,\n proof: { type: 'string', contentEncoding: 'base16', minLength: 64, maxLength: 64 },\n },\n required: ['ward', 'proof'],\n additionalProperties: false,\n },\n },\n },\n required: ['proofs'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n relisten: {\n description:\n \"The brain's alone, told once a change has landed that moved a line, a relation drawn through an address related or ended (`drop`, `left`, a lapse, a reinvite that replaced its keys). The ear asks the brain `lines {}` and `network` `listen {lines}`, durable, the whole set, which replaces the one kept. It writes no cell; it is writing so that it runs alone, behind the reading asks, and nothing waits on it.\",\n kind: 'writing',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'null' },\n errors: ['refused'],\n },\n invite: {\n description:\n \"Draws an invitation to the asker alone, from a ward drawn fresh for it, or the public ward with `public`, kept by the brain for `waits`, null until it is knocked on or ended, and its relation for `lives`, null for good, each span any the asker names, and answers it beside its far organism's ID; the brain asks it with `anchor` for the next anchor. The invitation's text, which `key` has its ward sign whole, carries the two spans it names, `waits` and `lives`, so the side that accepts lapses it by its own clock, and the anchor's mark, `anchor: true`, where it is the next anchor's or, with `first`, the brain's alone, the first invitation. With `note`, free data of at most 4 KiB as its canonical text by default, `note` an owner's word over it, and never a secret, what the standing is for and to whom it is given: the brain keeps it beside the standing, null where none is named, and it never enters the invitation. With `says`, free data never null and never a secret, at most a quarter of the note's bound, 1 KiB by default, which the brain refuses past that bound: what the invitation says to whoever holds it before the yes, carried in the invitation beside its spans, and kept by neither brain but as the offer of a reference. With `again`, `{node, far}`, the brain's alone, the invitation gives again in its place the standing `node` gave of the far organism `far`: it is drawn as ever, and the brain replaces that standing's relation, keeping its far organism, its wires and its note, so `note` is never sent with it. A ward drawn fresh is reached at the address of its own the lobe wired to `relay` gives it, `address {}` answering `{at}`, and where none is wired, where the organism is. With `through`, the address of the organism always on, the ward is reached at that address alone, `at` is `[through]` and no relay is asked, and the brain is told beside the relation which address it was drawn through, so it alone keeps the lines; `through` is refused with `public` or `anchor`, and the brain's `reinvite` of a standing drawn through a line names that `through` again. With `refer`, the invitation is drawn exactly so, a line's or a relay's address among it, but `key` keeps it sealed behind a reference it draws by chance, 128 bits as twenty-six lowercase base32, which the brain holds for `waits` (null until redeemed or dropped), and the answer is `{link: {card, reference}, far}`, never the invitation: `card` is the ward drawn for it and where that ward is reached, so no two links name one ward. A stranger redeems the reference once, on that ward's zero head, by `#redeem {reference}`, which the ear answers itself, the reply's object the invitation; and while it waits reads its offer there as often as it asks, spending nothing, by `#offer {reference}`, the reply's object `{says, waits, lives}`: what the invitation says, null where nothing, what is left of its wait and how long its relation lives, each null for none. With `public` beside `refer`, as for a link on a domain, the invitation is still drawn on a ward fresh for it, and `card` is what `card` answers, the public ward and its addresses, whose zero head redeems it. `refer` is refused with `anchor` and `first`.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n waits: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'null' }] },\n lives: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'null' }] },\n anchor: { type: 'boolean' },\n first: { type: 'boolean' },\n public: { type: 'boolean' },\n refer: { type: 'boolean' },\n through: Ear.#text,\n note: {},\n says: Ear.#says,\n again: Ear.#again,\n },\n required: ['waits', 'lives'],\n additionalProperties: false,\n },\n result: {\n anyOf: [\n {\n type: 'object',\n properties: { invitation: Ear.#text, far: Ear.#text },\n required: ['invitation', 'far'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n link: {\n type: 'object',\n properties: {\n card: {\n type: 'object',\n properties: { ward: Ear.#name, at: { type: 'array', items: Ear.#text } },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n reference: Ear.#reference,\n },\n required: ['card', 'reference'],\n additionalProperties: false,\n },\n far: Ear.#text,\n },\n required: ['link', 'far'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n card: {\n description:\n \"The brain's alone, for its owners' `card`. Answers `{ward, at}`, the public ward's name and the addresses `network` last reported, empty where none was: the very ward and addresses an invitation drawn with `public` carries. It writes no cell and asks no one.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: {\n type: 'object',\n properties: { ward: Ear.#name, at: { type: 'array', items: Ear.#text } },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n ward: {\n description:\n \"The brain's alone, for its owners' `ward`. `key` draws a new ward, answered as `{name, sealed}`, which the brain lays in the ear's cell: an ask from far runs through the ear, which could write nothing until it ended.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'object' },\n errors: ['refused'],\n },\n drop: {\n irreversible: true,\n description:\n \"Ends the asker's relation with a far organism. One it gave ends here, and an ask arriving while it ends hears `removed`; a standing it holds ends as the mouth's `drop` ends one, its `#leave` sent first. The brain takes a relation given through a line off its line when it ends. With `reference` instead of `far`, the reference the asker minted is taken off, so a `#redeem` or an `#offer` of it is silence; another node's or an unknown one is refused. The relation of its invitation stays, as any unknocked one does, and lapses by its `waits`.\",\n kind: 'reading',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: { far: Ear.#text },\n required: ['far'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: { reference: Ear.#reference },\n required: ['reference'],\n additionalProperties: false,\n },\n ],\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n },\n placeholders: {\n brain: 'nervur.brain',\n network: 'nervur.network',\n front: null,\n key: 'nervur.key',\n relay: null,\n },\n };\n\n static #network = 'network';\n static #silence = { silence: true };\n static #redeem = '#redeem';\n static #offer = '#offer';\n static #handed = { handed: true };\n static #opened = { opened: true };\n static #zeros = '0'.repeat(64);\n static #lid = 32;\n\n static #at(data , key ) {\n return Ear.field(data, key) ?? null;\n }\n\n static #heard(answer ) {\n return 'result' in answer ? answer.result : undefined;\n }\n\n #refused({ code, message } ) {\n return this.error(code === 'busy' ? 'busy' : 'refused', message);\n }\n\n #choice(answer , seen , door ) {\n if (Ear.#at(Ear.#at(answer, 'error'), 'code') === 'silent') return Ear.#silence;\n const at = this.#reachedAt(door.at);\n return { object: this.codec.text(answer), seen, ...(at === undefined ? {} : { at }) };\n }\n\n static #described(admitted , answer ) {\n return Ear.#at(admitted, 'method') === null ? (Ear.#at(answer, 'result') ?? answer) : answer;\n }\n\n #reachedAt(own ) {\n const at = Array.isArray(own) ? own : this.cells.get(['addresses']);\n const named = this.cells.get(['named']);\n if (!Array.isArray(named) || named.length === 0) return Array.isArray(at) ? at : undefined;\n return [...(Array.isArray(at) ? at : []), ...named.filter((one) => !Array.isArray(at) || !at.includes(one))];\n }\n\n *#wired(placeholder ) {\n const read = yield {\n placeholder: 'nerves',\n method: 'read',\n args: {},\n };\n const wires = Ear.#heard(read);\n if (!Array.isArray(wires)) return undefined;\n return wires.some((wire) => Ear.#at(wire, 'placeholder') === placeholder && Ear.#at(wire, 'termination') !== null);\n }\n\n #argsOf(admitted ) {\n const text = Ear.#at(admitted, 'args');\n return typeof text === 'string' ? this.codec.read(text) : { why: 'the args are no text' };\n }\n\n *#lookup(heir , zero , door ) {\n if (door.drawn !== null) {\n const occupant = Ear.#at(door.drawn, 'occupant');\n const held = heir !== null && Ear.#at(occupant, 'heir') === heir;\n return { occupants: held ? { [heir]: occupant } : {}, zero: zero && Ear.#at(door.drawn, 'linked') === true };\n }\n if (heir !== null) {\n const relation = yield {\n placeholder: 'brain',\n method: 'relation',\n args: { heir },\n };\n const found = Ear.#heard(relation);\n if (found === undefined) return undefined;\n const held = found !== null && Ear.#at(found, 'ward') === null;\n return { occupants: held ? { [heir]: Ear.#at(found, 'occupant') } : {}, zero: false };\n }\n return { occupants: {}, zero };\n }\n\n *#doorOf(named , ward ) {\n if (typeof named !== 'string' || named === Ear.#at(ward, 'name')) return { ward, drawn: null, at: undefined };\n const relation = yield {\n placeholder: 'brain',\n method: 'relation',\n args: { ward: named },\n };\n const found = Ear.#heard(relation);\n if (found === undefined || found === null) return found;\n const kept = Ear.#at(found, 'ward');\n const own = { name: Ear.#at(kept, 'name'), sealed: Ear.#at(kept, 'sealed') };\n return { ward: own, drawn: found, at: Ear.field(kept, 'at') };\n }\n\n static #after(exchange , door , admitted ) {\n const { ward, at } = door;\n const kept = ['heir', 'by', 'seq', 'method', 'next', 'sealed'].map((name) => [name, Ear.#at(admitted, name)]);\n return {\n exchange,\n door: { ward, ...(at === undefined ? {} : { at }) },\n admitted: { ...Object.fromEntries(kept), args: '' },\n };\n }\n\n *#passed(heir , admitted , door , exchange ) {\n const args = this.#argsOf(admitted);\n const given = 'data' in args ? { args: args.data } : { args: null, refused: args.why };\n yield {\n placeholder: 'brain',\n method: 'pass',\n args: {\n heir,\n method: Ear.#at(admitted, 'method'),\n ...given,\n next: Ear.#at(admitted, 'next'),\n },\n after: Ear.#after(exchange, door, admitted),\n };\n return Ear.#opened;\n }\n\n *#front(admitted , door , exchange ) {\n const method = Ear.#at(admitted, 'method');\n if (method !== null && typeof method !== 'string') return Ear.#silence;\n if ((yield* this.#wired('front')) !== true) return Ear.#silence;\n const args = this.#argsOf(admitted);\n if ('why' in args) return this.#choice({ error: { code: 'refused', message: args.why } }, null, door);\n yield {\n placeholder: 'front',\n method,\n args: args.data,\n after: { ...Ear.#after(exchange, door, admitted), front: true },\n };\n return Ear.#handed;\n }\n\n #answered(args , door ) {\n const admitted = Ear.#at(args, 'admitted');\n const answer = Ear.#at(args, 'answer');\n if (Ear.#at(args, 'front') === true) return this.#choice(Ear.#described(admitted, answer), null, door);\n const heard = Ear.#at(answer, 'result');\n if (heard === null) return undefined;\n const seen = Ear.#at(heard, 'seen');\n return this.#choice(\n Ear.#described(admitted, Ear.#at(heard, 'answer')),\n typeof seen === 'string' ? seen : null,\n door,\n );\n }\n\n *#told(args ) {\n const kept = Ear.#at(args, 'door');\n const door = { ward: Ear.#at(kept, 'ward'), drawn: null, at: Ear.field(kept, 'at') };\n const choice = this.#answered(args, door);\n const reply = choice === undefined ? null : yield* this.#sealed(door.ward, Ear.#at(args, 'admitted'), choice);\n yield { placeholder: 'network', method: 'reply', args: { exchange: Ear.#at(args, 'exchange'), bytes: reply } };\n return null;\n }\n\n *#redeemed(door , admitted ) {\n const asked = this.#referenceOf(door, admitted);\n if (asked === null) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const { reference } = asked;\n const kept = yield { placeholder: 'brain', method: 'redeem', args: asked };\n const heard = Ear.#heard(kept);\n if (heard === undefined) return undefined;\n const sealed = Ear.#at(heard, 'sealed');\n if (!(sealed instanceof Uint8Array)) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const reply = yield* this.#key('redeem', { ward: door.ward, admitted, reference, sealed });\n const redeemed = Ear.#at(reply, 'reply');\n return redeemed instanceof Uint8Array ? redeemed : yield* this.#sealed(door.ward, admitted, Ear.#silence);\n }\n\n *#offered(door , admitted ) {\n const asked = this.#referenceOf(door, admitted);\n if (asked === null) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const kept = yield { placeholder: 'brain', method: 'offered', args: asked };\n const heard = Ear.#heard(kept);\n if (heard === undefined) return undefined;\n const choice = heard === null ? Ear.#silence : { object: this.codec.text(heard), seen: null };\n return yield* this.#sealed(door.ward, admitted, choice);\n }\n\n #referenceOf(door , admitted ) {\n const args = this.#argsOf(admitted);\n const reference = 'data' in args ? Ear.#at(args.data, 'reference') : null;\n if (typeof reference !== 'string' || !/^[a-z2-7]{26}$/.test(reference)) return null;\n return { reference, ward: door.drawn === null ? null : Ear.#at(door.ward, 'name') };\n }\n\n *#key(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return Ear.#heard(answer);\n }\n\n *#sealed(ward , admitted , choice ) {\n const chosen = yield* this.#key('choose', { ward, admitted, choice });\n const reply = Ear.#at(chosen, 'reply');\n if (reply instanceof Uint8Array) return reply;\n const silence = yield* this.#key('choose', { ward, admitted, choice: Ear.#silence });\n return Ear.#at(silence, 'reply');\n }\n\n #notNetwork(method ) {\n return this.error('refused', `${method} is network's alone, and ${this.stamp.asker} asks it`);\n }\n\n *arrived(args ) {\n if (this.stamp.asker === 'brain' && Ear.field(args, 'answer') !== undefined) return yield* this.#told(args);\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('arrived');\n const exchange = Ear.#at(args, 'exchange');\n const bytes = Ear.#at(args, 'bytes');\n const own = this.cells.get(['ward']);\n if (typeof exchange !== 'number' || !(bytes instanceof Uint8Array))\n return this.error('refused', 'arrived takes an exchange and its bytes');\n if (own === undefined) return this.error('refused', 'the ear holds no ward');\n const door = yield* this.#doorOf(Ear.#at(args, 'ward'), own);\n const box = bytes.length > 1048576 ? bytes.subarray(0, Ear.#lid) : bytes;\n const reply = door === undefined || door === null ? null : yield* this.#door(door, box, exchange);\n if (reply === Ear.#handed) return null;\n if (reply === Ear.#opened) return Ear.#opened;\n yield {\n placeholder: 'network',\n method: 'reply',\n args: { exchange, bytes: reply },\n };\n return null;\n }\n\n *#door(door , bytes , exchange ) {\n const { ward } = door;\n const opened = yield* this.#key('openHead', { ward, box: bytes });\n const named = opened === undefined || opened === null ? null : Ear.hex(Ear.#at(opened, 'head'));\n const zero = named === Ear.#zeros;\n const heir = named === null || zero ? null : named;\n const lookup = opened === undefined ? undefined : yield* this.#lookup(heir, zero, door);\n const arrival =\n lookup === undefined\n ? undefined\n : yield* this.#key('arrive', { ward, box: bytes, lookup, opened: opened ?? null });\n if (arrival === undefined || Ear.#at(arrival, 'refused') === true) return Ear.#at(arrival, 'reply');\n const admitted = Ear.#at(arrival, 'admitted');\n const method = Ear.#at(admitted, 'method');\n if (heir === null && method === Ear.#redeem) return (yield* this.#redeemed(door, admitted)) ?? null;\n if (heir === null && method === Ear.#offer) return (yield* this.#offered(door, admitted)) ?? null;\n if (heir === null && door.drawn !== null) return yield* this.#sealed(ward, admitted, Ear.#silence);\n const choice =\n heir === null\n ? yield* this.#front(admitted, door, exchange)\n : yield* this.#passed(heir, admitted, door, exchange);\n return choice === Ear.#handed || choice === Ear.#opened ? choice : yield* this.#sealed(ward, admitted, choice);\n }\n\n named(args ) {\n this.cells.set(['named'], Ear.#at(args, 'at') ?? []);\n return null;\n }\n\n addresses(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('addresses');\n const addresses = Ear.#at(args, 'addresses');\n if (!Array.isArray(addresses)) return this.error('refused', 'addresses takes a list');\n this.cells.set(['addresses'], addresses);\n return null;\n }\n\n *#reached() {\n const wired = yield* this.#wired('relay');\n if (wired === undefined) return { why: 'the nerves answer no wiring' };\n if (!wired) return null;\n const answer = yield {\n placeholder: 'relay',\n method: 'address',\n args: {},\n };\n const heard = Ear.#heard(answer);\n const at = Ear.#at(heard, 'at');\n const through = Ear.#at(heard, 'through');\n const addresses = Array.isArray(at) && at.length > 0 && at.every((one) => typeof one === 'string' && one !== '');\n if (!addresses) return { why: 'the relay gives the ward no address' };\n if (through === null) return { at };\n return typeof through === 'string' && through !== '' ? { at, through } : { why: 'the relay names no line to hold' };\n }\n\n *#drawn(open , through ) {\n const own = this.cells.get(['ward']);\n if (own === undefined) return { why: 'the ear holds no ward' };\n if (open) return { ward: own, at: this.#reachedAt(undefined), kept: null };\n const drawn = yield* this.#key('draw', {});\n const ward = Ear.#at(drawn, 'ward');\n if (ward === null) return { why: 'key draws no ward' };\n if (through !== null) {\n const at = [through];\n return { ward, at, kept: { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed'), at, through } };\n }\n const reached = yield* this.#reached();\n if (reached !== null && 'why' in reached) return reached;\n const held = reached?.through === undefined ? {} : { through: reached.through };\n const at = reached === null ? {} : { at: reached.at, ...held };\n const kept = { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed'), ...at };\n return { ward, at: this.#reachedAt(reached?.at), kept };\n }\n\n #againRefusal(args , first ) {\n const again = Ear.#at(args, 'again');\n if (again === null) return null;\n if (this.stamp.asker !== 'brain') return \"again is the brain's alone\";\n if (typeof Ear.#at(again, 'node') !== 'string' || typeof Ear.#at(again, 'far') !== 'string')\n return 'again takes the node and the far organism of a standing';\n const open = first || Ear.#at(args, 'anchor') === true || Ear.#at(args, 'public') === true;\n return open ? 'an occupant given again is never an anchor, nor on the public ward' : null;\n }\n\n #holderOf(args ) {\n const again = Ear.#at(args, 'again');\n if (again === null) return { node: this.stamp.asker, note: Ear.#at(args, 'note') };\n return { node: Ear.#at(again, 'node'), again: Ear.#at(again, 'far') };\n }\n\n #lineOf(args , first ) {\n const asked = Ear.#at(args, 'through');\n if (asked === null) return { through: null };\n if (typeof asked !== 'string' || asked === '') return { why: 'through takes an address' };\n if (first || Ear.#at(args, 'anchor') === true || Ear.#at(args, 'public') === true)\n return { why: 'a ward reached through a line is never an anchor, nor the public ward' };\n return { through: asked };\n }\n\n #referRefusal(args , first ) {\n if (Ear.#at(args, 'refer') !== true) return null;\n return first || Ear.#at(args, 'anchor') === true ? \"a reference is never an anchor's\" : null;\n }\n\n *card() {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"card is the brain's alone\");\n const card = yield* this.#cardOf();\n return 'why' in card ? this.error('refused', card.why) : card;\n }\n\n *ward() {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"ward is the brain's alone\");\n const drawn = yield* this.#key('draw', {});\n const ward = Ear.#at(drawn, 'ward');\n if (ward === null) return this.error('refused', 'key draws no ward');\n return { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed') };\n }\n\n *invite(args ) {\n const waits = Ear.#at(args, 'waits');\n const lives = Ear.#at(args, 'lives');\n const marked = Ear.#at(args, 'anchor') === true ? { anchor: true } : {};\n const spans = [waits, lives].every((span) => span === null || typeof span === 'number');\n if (!spans) return this.error('refused', 'invite takes two spans');\n const says = Ear.field(args, 'says');\n if (says === null) return this.error('refused', 'says is never null: an invitation that says nothing names none');\n const first = Ear.#at(args, 'first') === true;\n if (first && this.stamp.asker !== 'brain') return this.error('refused', \"first is the brain's alone\");\n const refusal = this.#againRefusal(args, first);\n if (refusal !== null) return this.error('refused', refusal);\n const line = this.#lineOf(args, first);\n if ('why' in line) return this.error('refused', line.why);\n const barred = this.#referRefusal(args, first);\n if (barred !== null) return this.error('refused', barred);\n const { through } = line;\n const refer = Ear.#at(args, 'refer') === true;\n const open = Ear.#at(args, 'public') === true;\n const drawn = yield* this.#drawn(open && !refer, through);\n if ('why' in drawn) return this.error('refused', drawn.why);\n const at = drawn.at === undefined ? {} : { at: drawn.at };\n const said = says === undefined ? {} : { says };\n const beside = {\n ...(waits === null ? {} : { waits }),\n ...(lives === null ? {} : { lives }),\n ...said,\n ...(first || Ear.#at(args, 'anchor') === true ? { anchor: true } : {}),\n };\n const invited = yield* this.#key('invite', { ward: drawn.ward, ...at, beside });\n const text = Ear.#at(invited, 'invitation');\n const heir = Ear.#at(invited, 'heir');\n if (typeof text !== 'string' || typeof heir !== 'string') return this.error('refused', 'key draws no invitation');\n const ward = drawn.kept === null ? {} : { ward: drawn.kept };\n const kept = this.#holderOf(args);\n const named = first ? { first: true } : {};\n const related = yield {\n placeholder: 'brain',\n method: 'relate',\n args: { ...kept, heir, waits, lives, ...said, ...marked, ...ward, ...named },\n };\n if ('error' in related) return this.#refused(related.error);\n const far = Ear.#at(related.result, 'far');\n if (!refer) return { invitation: text, far };\n const name = Ear.#at(drawn.ward, 'name');\n const door = open ? yield* this.#cardOf() : { ward: name, at: Array.isArray(drawn.at) ? drawn.at : [] };\n if ('why' in door) return this.error('refused', door.why);\n const minted = { node: kept.node, waits, lives, says: says ?? null, far, ward: name, public: open };\n return yield* this.#referred(text, door, minted);\n }\n\n *#referred(\n text ,\n card ,\n minted \n \n \n \n \n \n \n \n ,\n ) {\n const referred = yield* this.#key('refer', { invitation: text });\n const reference = Ear.#at(referred, 'reference');\n const sealed = Ear.#at(referred, 'sealed');\n if (typeof reference !== 'string' || !(sealed instanceof Uint8Array))\n return this.error('refused', 'key keeps no reference');\n const kept = yield {\n placeholder: 'brain',\n method: 'refer',\n args: {\n node: minted.node,\n reference,\n sealed,\n waits: minted.waits,\n ward: minted.ward,\n public: minted.public,\n says: minted.says,\n lives: minted.lives,\n },\n };\n if ('error' in kept) return this.#refused(kept.error);\n return { link: { card, reference }, far: minted.far };\n }\n\n *#cardOf() {\n const drawn = yield* this.#drawn(true, null);\n if ('why' in drawn) return drawn;\n return { ward: Ear.#at(drawn.ward, 'name'), at: Array.isArray(drawn.at) ? drawn.at : [] };\n }\n\n *drop(args ) {\n const far = Ear.#at(args, 'far');\n const reference = Ear.#at(args, 'reference');\n if (typeof reference === 'string' && far === null) {\n const unrefer = yield {\n placeholder: 'brain',\n method: 'unrefer',\n args: { reference, node: this.stamp.asker },\n };\n return 'error' in unrefer ? this.#refused(unrefer.error) : null;\n }\n if (typeof far !== 'string' || reference !== null)\n return this.error('refused', 'drop takes a far organism or a reference');\n const ended = yield {\n placeholder: 'brain',\n method: 'end',\n args: { far, node: this.stamp.asker },\n };\n return 'error' in ended ? this.#refused(ended.error) : null;\n }\n\n *relisten(_args ) {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"relisten is the brain's alone\");\n const held = yield { placeholder: 'brain', method: 'lines', args: {} };\n if ('error' in held) return this.#refused(held.error);\n if (!Array.isArray(held.result)) return this.error('refused', 'the brain answers no lines');\n const lines = held.result.map((line) => {\n const wards = Ear.#at(line, 'wards');\n const names = Array.isArray(wards) ? wards.map((ward) => Ear.#at(ward, 'name')) : [];\n return { address: Ear.#at(line, 'address'), wards: names };\n });\n const listened = yield {\n placeholder: Ear.#network,\n method: 'listen',\n args: { lines },\n durable: true,\n };\n return 'error' in listened ? this.#refused(listened.error) : null;\n }\n\n *challenged(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('challenged');\n const [address, nonce, identity] = [Ear.#at(args, 'address'), Ear.#at(args, 'nonce'), Ear.#at(args, 'identity')];\n const held = yield { placeholder: 'brain', method: 'lines', args: {} };\n if ('error' in held) return this.#refused(held.error);\n const line = Array.isArray(held.result)\n ? held.result.find((one) => Ear.#at(one, 'address') === address)\n : undefined;\n const wards = Ear.#at(line, 'wards');\n if (!Array.isArray(wards) || wards.length === 0) return { proofs: [] };\n const proofs = Ear.#at(yield* this.#key('prove', { wards, nonce, identity }), 'proofs');\n if (!Array.isArray(proofs)) return this.error('refused', 'key proves no ward of the line');\n return { proofs: wards.map((ward, at) => ({ ward: Ear.#at(ward, 'name'), proof: proofs[at] ?? null })) };\n }\n\n *line(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('line');\n const wards = Ear.#at(args, 'wards');\n const up = Ear.#at(args, 'up');\n if (!Array.isArray(wards) || typeof up !== 'boolean') return this.error('refused', 'line takes wards and up');\n const told = yield {\n placeholder: 'brain',\n method: 'line',\n args: { wards, up },\n };\n return 'error' in told ? this.#refused(told.error) : null;\n }\n}";
|
|
4268
|
+
var EAR_TEXT = "class Ear extends Faculty {\n static #bytes = {\n type: 'string',\n contentEncoding: 'base16',\n maxLength: 1048576,\n };\n static #arrival = { ...Ear.#bytes, maxLength: 1048576 + 1 };\n static #text = { type: 'string', minLength: 1 };\n static #name = { type: 'string', pattern: '^[0-9a-f]{128}$' };\n static #reference = { type: 'string', pattern: '^[a-z2-7]{26}$' };\n static #says = {\n anyOf: [{ type: 'object' }, { type: 'array' }, { type: 'string' }, { type: 'number' }, { type: 'boolean' }],\n };\n static #again = {\n type: 'object',\n properties: { node: Ear.#text, far: Ear.#text },\n required: ['node', 'far'],\n additionalProperties: false,\n };\n\n static blueprint = {\n name: 'nervur.ear',\n version: '0.37.6',\n description: 'The ear: it opens and seals the boxes of Quo, and the brain keeps every relation.',\n methods: {\n arrived: {\n description:\n \"A box arrived on an exchange, sent to the ward named, the public ward where none is: opened, judged by Quo and handed on, or replied. Answers `{opened: true}` where it handed on an ask it admitted on a relation, so the carrier counts what that ask came on as carried, and null otherwise. The brain's alone, with `answer`: what a node answered of an ask the ear handed on, sealed and replied on its exchange.\",\n kind: 'reading',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: {\n exchange: { type: 'integer', minimum: 0 },\n bytes: Ear.#arrival,\n ward: Ear.#name,\n },\n required: ['exchange', 'bytes'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n exchange: { type: 'integer', minimum: 0 },\n door: {},\n admitted: {},\n front: { type: 'boolean' },\n answer: {},\n },\n required: ['exchange', 'door', 'admitted', 'answer'],\n additionalProperties: false,\n },\n ],\n },\n result: {\n anyOf: [\n { type: 'null' },\n {\n type: 'object',\n properties: { opened: { const: true } },\n required: ['opened'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n named: {\n description:\n \"The brain's alone, for its owners' `addresses`. Keeps the addresses of the organism's own an owner named, in place of those before, beside what `network` reports.\",\n kind: 'writing',\n askers: ['brain'],\n args: {\n type: 'object',\n properties: { at: { type: 'array', items: Ear.#text } },\n required: ['at'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n addresses: {\n description: 'The addresses `network` last reported.',\n kind: 'writing',\n args: {\n type: 'object',\n properties: { addresses: { type: 'array', items: Ear.#text } },\n required: ['addresses'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n line: {\n description:\n 'A line, accepted at an endpoint or held, that names `wards` came up or went down, told by `network` alone. The ear asks the brain `line {wards, up}`, up and down alike: on up the brain asks each lobe granted a standing on one of them `back`, and either way it asks the lobe that gave an occupant drawn through that line `line {far, up}`.',\n kind: 'reading',\n askers: ['network'],\n args: {\n type: 'object',\n properties: { wards: { type: 'array', items: Ear.#name }, up: { type: 'boolean' } },\n required: ['wards', 'up'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n challenged: {\n description:\n 'A line `network` holds to `address` was challenged by its listener with `nonce` and `identity`, told by `network` alone. The ear asks the brain `lines {}` for the wards drawn through that address and `key` `prove {wards, nonce, identity}`, and answers `{proofs: [{ward, proof}]}`, each ward with its proof under that challenge alone; a line the brain holds no ward on is answered with none. It writes no cell.',\n kind: 'reading',\n askers: ['network'],\n args: {\n type: 'object',\n properties: {\n address: { type: 'string', minLength: 1 },\n nonce: { type: 'string', contentEncoding: 'base16', minLength: 32, maxLength: 32 },\n identity: { type: 'string', contentEncoding: 'base16', minLength: 32, maxLength: 32 },\n },\n required: ['address', 'nonce', 'identity'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: {\n proofs: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n ward: Ear.#name,\n proof: { type: 'string', contentEncoding: 'base16', minLength: 64, maxLength: 64 },\n },\n required: ['ward', 'proof'],\n additionalProperties: false,\n },\n },\n },\n required: ['proofs'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n relisten: {\n description:\n \"The brain's alone, told once a change has landed that moved a line, a relation drawn through an address related or ended (`drop`, `left`, a lapse, a reinvite that replaced its keys). The ear asks the brain `lines {}` and `network` `listen {lines}`, durable, the whole set, which replaces the one kept. It writes no cell; it is writing so that it runs alone, behind the reading asks, and nothing waits on it.\",\n kind: 'writing',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'null' },\n errors: ['refused'],\n },\n invite: {\n description:\n \"Draws an invitation to the asker alone, from a ward drawn fresh for it, or the public ward with `public`, kept by the brain for `waits`, null until it is knocked on or ended, and its relation for `lives`, null for good, each span any the asker names, and answers it beside its far organism's ID; the brain asks it with `anchor` for the next anchor. The invitation's text, which `key` has its ward sign whole, carries the two spans it names, `waits` and `lives`, so the side that accepts lapses it by its own clock, and the anchor's mark, `anchor: true`, where it is the next anchor's or, with `first`, the brain's alone, the first invitation. With `note`, free data of at most 4 KiB as its canonical text by default, `note` an owner's word over it, and never a secret, what the standing is for and to whom it is given: the brain keeps it beside the standing, null where none is named, and it never enters the invitation. With `says`, free data never null and never a secret, at most a quarter of the note's bound, 1 KiB by default, which the brain refuses past that bound: what the invitation says to whoever holds it before the yes, carried in the invitation beside its spans, and kept by neither brain but as the offer of a reference. With `again`, `{node, far}`, the brain's alone, the invitation gives again in its place the standing `node` gave of the far organism `far`: it is drawn as ever, and the brain replaces that standing's relation, keeping its far organism, its wires and its note, so `note` is never sent with it. A ward drawn fresh is reached at the address of its own the lobe wired to `relay` gives it, `address {}` answering `{at}`, and where none is wired, where the organism is. With `through`, the address of the organism always on, the ward is reached at that address alone, `at` is `[through]` and no relay is asked, and the brain is told beside the relation which address it was drawn through, so it alone keeps the lines; `through` is refused with `public` or `anchor`, and the brain's `reinvite` of a standing drawn through a line names that `through` again. With `refer`, the invitation is drawn exactly so, a line's or a relay's address among it, but `key` keeps it sealed behind a reference it draws by chance, 128 bits as twenty-six lowercase base32, which the brain holds for `waits` (null until redeemed or dropped), and the answer is `{link: {card, reference}, far}`, never the invitation: `card` is the ward drawn for it and where that ward is reached, so no two links name one ward. A stranger redeems the reference once, on that ward's zero head, by `#redeem {reference}`, which the ear answers itself, the reply's object the invitation; and while it waits reads its offer there as often as it asks, spending nothing, by `#offer {reference}`, the reply's object `{says, waits, lives}`: what the invitation says, null where nothing, what is left of its wait and how long its relation lives, each null for none. With `public` beside `refer`, as for a link on a domain, the invitation is still drawn on a ward fresh for it, and `card` is what `card` answers, the public ward and its addresses, whose zero head redeems it. `refer` is refused with `anchor` and `first`.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n waits: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'null' }] },\n lives: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'null' }] },\n anchor: { type: 'boolean' },\n first: { type: 'boolean' },\n public: { type: 'boolean' },\n refer: { type: 'boolean' },\n through: Ear.#text,\n note: {},\n says: Ear.#says,\n again: Ear.#again,\n },\n required: ['waits', 'lives'],\n additionalProperties: false,\n },\n result: {\n anyOf: [\n {\n type: 'object',\n properties: { invitation: Ear.#text, far: Ear.#text },\n required: ['invitation', 'far'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n link: {\n type: 'object',\n properties: {\n card: {\n type: 'object',\n properties: { ward: Ear.#name, at: { type: 'array', items: Ear.#text } },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n reference: Ear.#reference,\n },\n required: ['card', 'reference'],\n additionalProperties: false,\n },\n far: Ear.#text,\n },\n required: ['link', 'far'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n card: {\n description:\n \"The brain's alone, for its owners' `card`. Answers `{ward, at}`, the public ward's name and the addresses `network` last reported, empty where none was: the very ward and addresses an invitation drawn with `public` carries. It writes no cell and asks no one.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: {\n type: 'object',\n properties: { ward: Ear.#name, at: { type: 'array', items: Ear.#text } },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n ward: {\n description:\n \"The brain's alone, for its owners' `ward`. `key` draws a new ward, answered as `{name, sealed}`, which the brain lays in the ear's cell: an ask from far runs through the ear, which could write nothing until it ended.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'object' },\n errors: ['refused'],\n },\n drop: {\n irreversible: true,\n description:\n \"Ends the asker's relation with a far organism. One it gave ends here, and an ask arriving while it ends hears `removed`; a standing it holds ends as the mouth's `drop` ends one, its `#leave` sent first. The brain takes a relation given through a line off its line when it ends. With `reference` instead of `far`, the reference the asker minted is taken off, so a `#redeem` or an `#offer` of it is silence; another node's or an unknown one is refused. The relation of its invitation stays, as any unknocked one does, and lapses by its `waits`.\",\n kind: 'reading',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: { far: Ear.#text },\n required: ['far'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: { reference: Ear.#reference },\n required: ['reference'],\n additionalProperties: false,\n },\n ],\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n },\n placeholders: {\n brain: 'nervur.brain',\n network: 'nervur.network',\n front: null,\n key: 'nervur.key',\n relay: null,\n },\n };\n\n static #network = 'network';\n static #silence = { silence: true };\n static #redeem = '#redeem';\n static #offer = '#offer';\n static #handed = { handed: true };\n static #opened = { opened: true };\n static #zeros = '0'.repeat(64);\n static #lid = 32;\n\n static #at(data , key ) {\n return Ear.field(data, key) ?? null;\n }\n\n static #heard(answer ) {\n return 'result' in answer ? answer.result : undefined;\n }\n\n #refused({ code, message } ) {\n return this.error(code === 'busy' ? 'busy' : 'refused', message);\n }\n\n #choice(answer , seen , door ) {\n if (Ear.#at(Ear.#at(answer, 'error'), 'code') === 'silent') return Ear.#silence;\n const at = this.#reachedAt(door.at);\n return { object: this.codec.text(answer), seen, ...(at === undefined ? {} : { at }) };\n }\n\n static #described(admitted , answer ) {\n return Ear.#at(admitted, 'method') === null ? (Ear.#at(answer, 'result') ?? answer) : answer;\n }\n\n #reachedAt(own ) {\n const at = Array.isArray(own) ? own : this.cells.get(['addresses']);\n const named = this.cells.get(['named']);\n if (!Array.isArray(named) || named.length === 0) return Array.isArray(at) ? at : undefined;\n return [...(Array.isArray(at) ? at : []), ...named.filter((one) => !Array.isArray(at) || !at.includes(one))];\n }\n\n *#wired(placeholder ) {\n const read = yield {\n placeholder: 'nerves',\n method: 'read',\n args: {},\n };\n const wires = Ear.#heard(read);\n if (!Array.isArray(wires)) return undefined;\n return wires.some((wire) => Ear.#at(wire, 'placeholder') === placeholder && Ear.#at(wire, 'termination') !== null);\n }\n\n #argsOf(admitted ) {\n const text = Ear.#at(admitted, 'args');\n return typeof text === 'string' ? this.codec.read(text) : { why: 'the args are no text' };\n }\n\n *#lookup(heir , zero , door ) {\n if (door.drawn !== null) {\n const occupant = Ear.#at(door.drawn, 'occupant');\n const held = heir !== null && Ear.#at(occupant, 'heir') === heir;\n return { occupants: held ? { [heir]: occupant } : {}, zero: zero && Ear.#at(door.drawn, 'linked') === true };\n }\n if (heir !== null) {\n const relation = yield {\n placeholder: 'brain',\n method: 'relation',\n args: { heir },\n };\n const found = Ear.#heard(relation);\n if (found === undefined) return undefined;\n const held = found !== null && Ear.#at(found, 'ward') === null;\n return { occupants: held ? { [heir]: Ear.#at(found, 'occupant') } : {}, zero: false };\n }\n return { occupants: {}, zero };\n }\n\n *#doorOf(named , ward ) {\n if (typeof named !== 'string' || named === Ear.#at(ward, 'name')) return { ward, drawn: null, at: undefined };\n const relation = yield {\n placeholder: 'brain',\n method: 'relation',\n args: { ward: named },\n };\n const found = Ear.#heard(relation);\n if (found === undefined || found === null) return found;\n const kept = Ear.#at(found, 'ward');\n const own = { name: Ear.#at(kept, 'name'), sealed: Ear.#at(kept, 'sealed') };\n return { ward: own, drawn: found, at: Ear.field(kept, 'at') };\n }\n\n static #after(exchange , door , admitted ) {\n const { ward, at } = door;\n const kept = ['heir', 'by', 'seq', 'method', 'next', 'sealed'].map((name) => [name, Ear.#at(admitted, name)]);\n return {\n exchange,\n door: { ward, ...(at === undefined ? {} : { at }) },\n admitted: { ...Object.fromEntries(kept), args: '' },\n };\n }\n\n *#passed(heir , admitted , door , exchange ) {\n const args = this.#argsOf(admitted);\n const given = 'data' in args ? { args: args.data } : { args: null, refused: args.why };\n yield {\n placeholder: 'brain',\n method: 'pass',\n args: {\n heir,\n method: Ear.#at(admitted, 'method'),\n ...given,\n next: Ear.#at(admitted, 'next'),\n },\n after: Ear.#after(exchange, door, admitted),\n };\n return Ear.#opened;\n }\n\n *#front(admitted , door , exchange ) {\n const method = Ear.#at(admitted, 'method');\n if (method !== null && typeof method !== 'string') return Ear.#silence;\n if ((yield* this.#wired('front')) !== true) return Ear.#silence;\n const args = this.#argsOf(admitted);\n if ('why' in args) return this.#choice({ error: { code: 'refused', message: args.why } }, null, door);\n yield {\n placeholder: 'front',\n method,\n args: args.data,\n after: { ...Ear.#after(exchange, door, admitted), front: true },\n };\n return Ear.#handed;\n }\n\n #answered(args , door ) {\n const admitted = Ear.#at(args, 'admitted');\n const answer = Ear.#at(args, 'answer');\n if (Ear.#at(args, 'front') === true) return this.#choice(Ear.#described(admitted, answer), null, door);\n const heard = Ear.#at(answer, 'result');\n if (heard === null) return undefined;\n const seen = Ear.#at(heard, 'seen');\n return this.#choice(\n Ear.#described(admitted, Ear.#at(heard, 'answer')),\n typeof seen === 'string' ? seen : null,\n door,\n );\n }\n\n *#told(args ) {\n const kept = Ear.#at(args, 'door');\n const door = { ward: Ear.#at(kept, 'ward'), drawn: null, at: Ear.field(kept, 'at') };\n const choice = this.#answered(args, door);\n const reply = choice === undefined ? null : yield* this.#sealed(door.ward, Ear.#at(args, 'admitted'), choice);\n yield { placeholder: 'network', method: 'reply', args: { exchange: Ear.#at(args, 'exchange'), bytes: reply } };\n return null;\n }\n\n *#redeemed(door , admitted ) {\n const asked = this.#referenceOf(door, admitted);\n if (asked === null) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const { reference } = asked;\n const kept = yield { placeholder: 'brain', method: 'redeem', args: asked };\n const heard = Ear.#heard(kept);\n if (heard === undefined) return undefined;\n const sealed = Ear.#at(heard, 'sealed');\n if (!(sealed instanceof Uint8Array)) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const reply = yield* this.#key('redeem', { ward: door.ward, admitted, reference, sealed });\n const redeemed = Ear.#at(reply, 'reply');\n return redeemed instanceof Uint8Array ? redeemed : yield* this.#sealed(door.ward, admitted, Ear.#silence);\n }\n\n *#offered(door , admitted ) {\n const asked = this.#referenceOf(door, admitted);\n if (asked === null) return yield* this.#sealed(door.ward, admitted, Ear.#silence);\n const kept = yield { placeholder: 'brain', method: 'offered', args: asked };\n const heard = Ear.#heard(kept);\n if (heard === undefined) return undefined;\n const choice = heard === null ? Ear.#silence : { object: this.codec.text(heard), seen: null };\n return yield* this.#sealed(door.ward, admitted, choice);\n }\n\n #referenceOf(door , admitted ) {\n const args = this.#argsOf(admitted);\n const reference = 'data' in args ? Ear.#at(args.data, 'reference') : null;\n if (typeof reference !== 'string' || !/^[a-z2-7]{26}$/.test(reference)) return null;\n return { reference, ward: door.drawn === null ? null : Ear.#at(door.ward, 'name') };\n }\n\n *#key(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return Ear.#heard(answer);\n }\n\n *#sealed(ward , admitted , choice ) {\n const chosen = yield* this.#key('choose', { ward, admitted, choice });\n const reply = Ear.#at(chosen, 'reply');\n if (reply instanceof Uint8Array) return reply;\n const silence = yield* this.#key('choose', { ward, admitted, choice: Ear.#silence });\n return Ear.#at(silence, 'reply');\n }\n\n #notNetwork(method ) {\n return this.error('refused', `${method} is network's alone, and ${this.stamp.asker} asks it`);\n }\n\n *arrived(args ) {\n if (this.stamp.asker === 'brain' && Ear.field(args, 'answer') !== undefined) return yield* this.#told(args);\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('arrived');\n const exchange = Ear.#at(args, 'exchange');\n const bytes = Ear.#at(args, 'bytes');\n const own = this.cells.get(['ward']);\n if (typeof exchange !== 'number' || !(bytes instanceof Uint8Array))\n return this.error('refused', 'arrived takes an exchange and its bytes');\n if (own === undefined) return this.error('refused', 'the ear holds no ward');\n const door = yield* this.#doorOf(Ear.#at(args, 'ward'), own);\n const box = bytes.length > 1048576 ? bytes.subarray(0, Ear.#lid) : bytes;\n const reply = door === undefined || door === null ? null : yield* this.#door(door, box, exchange);\n if (reply === Ear.#handed) return null;\n if (reply === Ear.#opened) return Ear.#opened;\n yield {\n placeholder: 'network',\n method: 'reply',\n args: { exchange, bytes: reply },\n };\n return null;\n }\n\n *#door(door , bytes , exchange ) {\n const { ward } = door;\n const opened = yield* this.#key('openHead', { ward, box: bytes });\n const named = opened === undefined || opened === null ? null : Ear.hex(Ear.#at(opened, 'head'));\n const zero = named === Ear.#zeros;\n const heir = named === null || zero ? null : named;\n const lookup = opened === undefined ? undefined : yield* this.#lookup(heir, zero, door);\n const arrival =\n lookup === undefined\n ? undefined\n : yield* this.#key('arrive', { ward, box: bytes, lookup, opened: opened ?? null });\n if (arrival === undefined || Ear.#at(arrival, 'refused') === true) return Ear.#at(arrival, 'reply');\n const admitted = Ear.#at(arrival, 'admitted');\n const method = Ear.#at(admitted, 'method');\n if (heir === null && method === Ear.#redeem) return (yield* this.#redeemed(door, admitted)) ?? null;\n if (heir === null && method === Ear.#offer) return (yield* this.#offered(door, admitted)) ?? null;\n if (heir === null && door.drawn !== null) return yield* this.#sealed(ward, admitted, Ear.#silence);\n const choice =\n heir === null\n ? yield* this.#front(admitted, door, exchange)\n : yield* this.#passed(heir, admitted, door, exchange);\n return choice === Ear.#handed || choice === Ear.#opened ? choice : yield* this.#sealed(ward, admitted, choice);\n }\n\n named(args ) {\n this.cells.set(['named'], Ear.#at(args, 'at') ?? []);\n return null;\n }\n\n addresses(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('addresses');\n const addresses = Ear.#at(args, 'addresses');\n if (!Array.isArray(addresses)) return this.error('refused', 'addresses takes a list');\n this.cells.set(['addresses'], addresses);\n return null;\n }\n\n *#reached() {\n const wired = yield* this.#wired('relay');\n if (wired === undefined) return { why: 'the nerves answer no wiring' };\n if (!wired) return null;\n const answer = yield {\n placeholder: 'relay',\n method: 'address',\n args: {},\n };\n const heard = Ear.#heard(answer);\n const at = Ear.#at(heard, 'at');\n const through = Ear.#at(heard, 'through');\n const addresses = Array.isArray(at) && at.length > 0 && at.every((one) => typeof one === 'string' && one !== '');\n if (!addresses) return { why: 'the relay gives the ward no address' };\n if (through === null) return { at };\n return typeof through === 'string' && through !== '' ? { at, through } : { why: 'the relay names no line to hold' };\n }\n\n *#drawn(open , through ) {\n const own = this.cells.get(['ward']);\n if (own === undefined) return { why: 'the ear holds no ward' };\n if (open) return { ward: own, at: this.#reachedAt(undefined), kept: null };\n const drawn = yield* this.#key('draw', {});\n const ward = Ear.#at(drawn, 'ward');\n if (ward === null) return { why: 'key draws no ward' };\n if (through !== null) {\n const at = [through];\n return { ward, at, kept: { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed'), at, through } };\n }\n const reached = yield* this.#reached();\n if (reached !== null && 'why' in reached) return reached;\n const held = reached?.through === undefined ? {} : { through: reached.through };\n const at = reached === null ? {} : { at: reached.at, ...held };\n const kept = { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed'), ...at };\n return { ward, at: this.#reachedAt(reached?.at), kept };\n }\n\n #againRefusal(args , first ) {\n const again = Ear.#at(args, 'again');\n if (again === null) return null;\n if (this.stamp.asker !== 'brain') return \"again is the brain's alone\";\n if (typeof Ear.#at(again, 'node') !== 'string' || typeof Ear.#at(again, 'far') !== 'string')\n return 'again takes the node and the far organism of a standing';\n const open = first || Ear.#at(args, 'anchor') === true || Ear.#at(args, 'public') === true;\n return open ? 'an occupant given again is never an anchor, nor on the public ward' : null;\n }\n\n #holderOf(args ) {\n const again = Ear.#at(args, 'again');\n if (again === null) return { node: this.stamp.asker, note: Ear.#at(args, 'note') };\n return { node: Ear.#at(again, 'node'), again: Ear.#at(again, 'far') };\n }\n\n #lineOf(args , first ) {\n const asked = Ear.#at(args, 'through');\n if (asked === null) return { through: null };\n if (typeof asked !== 'string' || asked === '') return { why: 'through takes an address' };\n if (first || Ear.#at(args, 'anchor') === true || Ear.#at(args, 'public') === true)\n return { why: 'a ward reached through a line is never an anchor, nor the public ward' };\n return { through: asked };\n }\n\n #referRefusal(args , first ) {\n if (Ear.#at(args, 'refer') !== true) return null;\n return first || Ear.#at(args, 'anchor') === true ? \"a reference is never an anchor's\" : null;\n }\n\n *card() {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"card is the brain's alone\");\n const card = yield* this.#cardOf();\n return 'why' in card ? this.error('refused', card.why) : card;\n }\n\n *ward() {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"ward is the brain's alone\");\n const drawn = yield* this.#key('draw', {});\n const ward = Ear.#at(drawn, 'ward');\n if (ward === null) return this.error('refused', 'key draws no ward');\n return { name: Ear.#at(ward, 'name'), sealed: Ear.#at(ward, 'sealed') };\n }\n\n *invite(args ) {\n const waits = Ear.#at(args, 'waits');\n const lives = Ear.#at(args, 'lives');\n const marked = Ear.#at(args, 'anchor') === true ? { anchor: true } : {};\n const spans = [waits, lives].every((span) => span === null || typeof span === 'number');\n if (!spans) return this.error('refused', 'invite takes two spans');\n const says = Ear.field(args, 'says');\n if (says === null) return this.error('refused', 'says is never null: an invitation that says nothing names none');\n const first = Ear.#at(args, 'first') === true;\n if (first && this.stamp.asker !== 'brain') return this.error('refused', \"first is the brain's alone\");\n const refusal = this.#againRefusal(args, first);\n if (refusal !== null) return this.error('refused', refusal);\n const line = this.#lineOf(args, first);\n if ('why' in line) return this.error('refused', line.why);\n const barred = this.#referRefusal(args, first);\n if (barred !== null) return this.error('refused', barred);\n const { through } = line;\n const refer = Ear.#at(args, 'refer') === true;\n const open = Ear.#at(args, 'public') === true;\n const drawn = yield* this.#drawn(open && !refer, through);\n if ('why' in drawn) return this.error('refused', drawn.why);\n const at = drawn.at === undefined ? {} : { at: drawn.at };\n const said = says === undefined ? {} : { says };\n const beside = {\n ...(waits === null ? {} : { waits }),\n ...(lives === null ? {} : { lives }),\n ...said,\n ...(first || Ear.#at(args, 'anchor') === true ? { anchor: true } : {}),\n };\n const invited = yield* this.#key('invite', { ward: drawn.ward, ...at, beside });\n const text = Ear.#at(invited, 'invitation');\n const heir = Ear.#at(invited, 'heir');\n if (typeof text !== 'string' || typeof heir !== 'string') return this.error('refused', 'key draws no invitation');\n const ward = drawn.kept === null ? {} : { ward: drawn.kept };\n const kept = this.#holderOf(args);\n const named = first ? { first: true } : {};\n const related = yield {\n placeholder: 'brain',\n method: 'relate',\n args: { ...kept, heir, waits, lives, ...said, ...marked, ...ward, ...named },\n };\n if ('error' in related) return this.#refused(related.error);\n const far = Ear.#at(related.result, 'far');\n if (!refer) return { invitation: text, far };\n const name = Ear.#at(drawn.ward, 'name');\n const door = open ? yield* this.#cardOf() : { ward: name, at: Array.isArray(drawn.at) ? drawn.at : [] };\n if ('why' in door) return this.error('refused', door.why);\n const minted = { node: kept.node, waits, lives, says: says ?? null, far, ward: name, public: open };\n return yield* this.#referred(text, door, minted);\n }\n\n *#referred(\n text ,\n card ,\n minted \n \n \n \n \n \n \n \n ,\n ) {\n const referred = yield* this.#key('refer', { invitation: text });\n const reference = Ear.#at(referred, 'reference');\n const sealed = Ear.#at(referred, 'sealed');\n if (typeof reference !== 'string' || !(sealed instanceof Uint8Array))\n return this.error('refused', 'key keeps no reference');\n const kept = yield {\n placeholder: 'brain',\n method: 'refer',\n args: {\n node: minted.node,\n reference,\n sealed,\n waits: minted.waits,\n ward: minted.ward,\n public: minted.public,\n says: minted.says,\n lives: minted.lives,\n },\n };\n if ('error' in kept) return this.#refused(kept.error);\n return { link: { card, reference }, far: minted.far };\n }\n\n *#cardOf() {\n const drawn = yield* this.#drawn(true, null);\n if ('why' in drawn) return drawn;\n return { ward: Ear.#at(drawn.ward, 'name'), at: Array.isArray(drawn.at) ? drawn.at : [] };\n }\n\n *drop(args ) {\n const far = Ear.#at(args, 'far');\n const reference = Ear.#at(args, 'reference');\n if (typeof reference === 'string' && far === null) {\n const unrefer = yield {\n placeholder: 'brain',\n method: 'unrefer',\n args: { reference, node: this.stamp.asker },\n };\n return 'error' in unrefer ? this.#refused(unrefer.error) : null;\n }\n if (typeof far !== 'string' || reference !== null)\n return this.error('refused', 'drop takes a far organism or a reference');\n const ended = yield {\n placeholder: 'brain',\n method: 'end',\n args: { far, node: this.stamp.asker },\n };\n return 'error' in ended ? this.#refused(ended.error) : null;\n }\n\n *relisten(_args ) {\n if (this.stamp.asker !== 'brain') return this.error('refused', \"relisten is the brain's alone\");\n const held = yield { placeholder: 'brain', method: 'lines', args: {} };\n if ('error' in held) return this.#refused(held.error);\n if (!Array.isArray(held.result)) return this.error('refused', 'the brain answers no lines');\n const lines = held.result.map((line) => {\n const wards = Ear.#at(line, 'wards');\n const names = Array.isArray(wards) ? wards.map((ward) => Ear.#at(ward, 'name')) : [];\n return { address: Ear.#at(line, 'address'), wards: names };\n });\n const listened = yield {\n placeholder: Ear.#network,\n method: 'listen',\n args: { lines },\n durable: true,\n };\n return 'error' in listened ? this.#refused(listened.error) : null;\n }\n\n *challenged(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('challenged');\n const [address, nonce, identity] = [Ear.#at(args, 'address'), Ear.#at(args, 'nonce'), Ear.#at(args, 'identity')];\n const held = yield { placeholder: 'brain', method: 'lines', args: {} };\n if ('error' in held) return this.#refused(held.error);\n const line = Array.isArray(held.result)\n ? held.result.find((one) => Ear.#at(one, 'address') === address)\n : undefined;\n const wards = Ear.#at(line, 'wards');\n if (!Array.isArray(wards) || wards.length === 0) return { proofs: [] };\n const proofs = Ear.#at(yield* this.#key('prove', { wards, nonce, identity }), 'proofs');\n if (!Array.isArray(proofs)) return this.error('refused', 'key proves no ward of the line');\n return { proofs: wards.map((ward, at) => ({ ward: Ear.#at(ward, 'name'), proof: proofs[at] ?? null })) };\n }\n\n *line(args ) {\n if (this.stamp.asker !== Ear.#network) return this.#notNetwork('line');\n const wards = Ear.#at(args, 'wards');\n const up = Ear.#at(args, 'up');\n if (!Array.isArray(wards) || typeof up !== 'boolean') return this.error('refused', 'line takes wards and up');\n const told = yield {\n placeholder: 'brain',\n method: 'line',\n args: { wards, up },\n };\n return 'error' in told ? this.#refused(told.error) : null;\n }\n}";
|
|
4269
4269
|
|
|
4270
4270
|
var EAR_SOURCE = facultySource(EAR_TEXT);
|
|
4271
4271
|
|
|
4272
4272
|
var MOUTH_BLUEPRINT = {
|
|
4273
4273
|
name: "nervur.mouth",
|
|
4274
|
-
version: "0.37.
|
|
4274
|
+
version: "0.37.6",
|
|
4275
4275
|
description: "The mouth: it seals the asks of the relations this organism holds as the standing, and opens their replies; the brain keeps every standing.",
|
|
4276
4276
|
methods: {
|
|
4277
4277
|
accept: {
|
|
@@ -4429,7 +4429,7 @@ var MOUTH_BLUEPRINT = {
|
|
|
4429
4429
|
placeholders: { brain: "nervur.brain", network: "nervur.network", key: "nervur.key" }
|
|
4430
4430
|
};
|
|
4431
4431
|
|
|
4432
|
-
var MOUTH_TEXT = "class Mouth extends Faculty {\n static #text = { type: 'string', minLength: 1 };\n static #named = { type: 'string', pattern: '^[0-9a-f]{2432}$' };\n static #bytes = { type: 'string', contentEncoding: 'base16' };\n\n static blueprint = {\n name: 'nervur.mouth',\n version: '0.37.5',\n description:\n 'The mouth: it seals the asks of the relations this organism holds as the standing, and opens their replies; the brain keeps every standing.',\n methods: {\n accept: {\n description:\n \"The organism accepts an invitation, at the ask of the asker, never the asker: the brain makes a far organism for its relation, keeps the standing as the organism's, and grants it to the asker by wiring the asker's placeholder to it, one wire each; an owner grants it to other lobes by `grant`. Its text is read past every ASCII whitespace, so one a mail wrapped or a hand spaced reads as it was written. The spans the invitation carries go to the brain, so the standing lapses here by this side's clock: unknocked past `waits`, bound past `lives`; and its anchor's mark, so it ends only once the far brain answered its owner's `drop`. With `note`, free data of at most 4 KiB as its canonical text by default and never a secret, what the organism holds, from whom and what for: the brain keeps it beside the standing as its own, null where none is named, and it never travels to the inviter; the asker's own note on it starts empty and is written through its `nerves`. With `node`, asked by the brain alone for an owner from afar, the standing is granted to that lobe rather than to the asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { invitation: Mouth.#text, placeholder: Mouth.#text, note: {}, node: Mouth.#text },\n required: ['invitation', 'placeholder'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { far: Mouth.#text },\n required: ['far'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n carry: {\n askers: ['brain'],\n description:\n \"The brain's alone: seals an ask on a standing, has the brain keep before its box goes what it needs kept, the bound its number lies below or the standing whole with its knock or probe, sends it to the first address that takes it, the same box again after the brain's pause where a door replied nothing, and answers what the asker hears, the standing moved, the being's newest addresses, and `answered` where the being's object came back, so the brain marks a standing fallen silent bound again.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n far: Mouth.#text,\n standing: { type: 'object' },\n at: { anyOf: [{ type: 'array', items: Mouth.#text }, { type: 'null' }] },\n method: { anyOf: [Mouth.#text, { type: 'null' }] },\n args: {},\n timeout: { type: 'number', minimum: 0 },\n room: { type: 'integer', minimum: 1 },\n },\n required: ['far', 'standing', 'at', 'method', 'args', 'timeout', 'room'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: {\n heard: {},\n standing: { type: 'object' },\n at: { anyOf: [{ type: 'array', items: Mouth.#text }, { type: 'null' }] },\n answered: { const: true },\n },\n required: ['heard', 'standing', 'at'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n cede: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` seal a standing whole, its numbers as the brain hands them, with what the brain keeps `beside` it, to `to`, the public half of a key another organism's `taking` drew, and answers `{handed}`, which no lobe reads; refused where `to` is no named key.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { standing: { type: 'object' }, beside: { type: 'object' }, to: Mouth.#named },\n required: ['standing', 'beside', 'to'],\n additionalProperties: false,\n },\n result: { type: 'object' },\n errors: ['refused'],\n },\n drop: {\n irreversible: true,\n description:\n \"The asker gives up the standing of a far organism it is granted, accepted through the mouth: its wire and its note go and it is asked `left`; where it was the last lobe wired, the brain sends the inviting side one last letter, `#leave`, then forgets the standing whatever answers, with its notes, and asks each other lobe that was wired `left`. One its invitation marked an anchor's the brain first asks the far brain its owner's `drop`, and forgets only once it answered or had ended it; refused, with the far brain's why or as unheard, it is kept.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { far: Mouth.#text },\n required: ['far'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n once: {\n description:\n \"Asks once with no relation: the ask goes on the zero head of the card's ward, at the first of its addresses that takes it, and the asker hears what the being answered. No far organism is made.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n card: {\n type: 'object',\n properties: {\n ward: { type: 'string', pattern: '^[0-9a-f]{128}$' },\n at: { type: 'array', items: Mouth.#text },\n },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n method: Mouth.#text,\n args: { type: 'object' },\n },\n required: ['card'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n take: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` open a standing `cede` handed by the key `taking` drew, the secret it sealed named in `taking`, and seal it again under this organism's record key, and answers `{standing, beside}`; refused where it is not sealed to that key.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n taking: {\n type: 'object',\n properties: { key: Mouth.#named, sealed: Mouth.#bytes },\n required: ['key', 'sealed'],\n additionalProperties: false,\n },\n handed: Mouth.#bytes,\n },\n required: ['taking', 'handed'],\n additionalProperties: false,\n },\n result: { type: 'object' },\n errors: ['refused'],\n },\n taking: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` draw a key a standing is handed to, and answers `{key, sealed}`, its public half and its secret sealed, which only that `key` opens.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'object' },\n errors: ['refused'],\n },\n vouch: {\n askers: ['brain'],\n description:\n \"The brain's alone: reads a domain's vouch, `https://<domain>/.well-known/quo`, through `network`, and answers its body as bytes, or null where it answered no 200 or nothing at all.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { domain: Mouth.#text },\n required: ['domain'],\n additionalProperties: false,\n },\n result: { anyOf: [{ type: 'object' }, { type: 'null' }] },\n errors: ['refused'],\n },\n },\n placeholders: { brain: 'nervur.brain', network: 'nervur.network', key: 'nervur.key' },\n };\n\n static #ward = /^[0-9a-f]{128}$/;\n static #code = /^(?=.{1,64}$)[a-z0-9]+(-[a-z0-9]+)*$/;\n static #blank = /[\\t\\n\\f\\r]/gu;\n static #unreached = 'unreached';\n static #in = '#in';\n static #whole = '#whole';\n static #out = '#out';\n\n static #at(data , key ) {\n return Mouth.field(data, key) ?? null;\n }\n\n static #spans(given ) \n \n \n \n {\n let parsed = null;\n try {\n const outer = JSON.parse(given);\n const text = typeof outer === 'object' && outer !== null ? Reflect.get(outer, 'text') : null;\n parsed = typeof text === 'string' ? JSON.parse(text) : null;\n } catch {\n parsed = null;\n }\n const span = (key ) => {\n const value = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, key) : null;\n return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : null;\n };\n const marked = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'anchor') : null;\n return { waits: span('waits'), lives: span('lives'), anchor: marked === true };\n }\n\n static #failed(code , message ) {\n return { error: { code, message } };\n }\n\n *#key(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return 'result' in answer ? answer.result : { why: answer.error.message };\n }\n\n static #nervur(object ) {\n const keys = typeof object === 'object' && object !== null ? Object.keys(object) : [];\n if (keys.length !== 1) return false;\n if (keys[0] === 'result' || (keys[0] === '#pieces' && typeof Mouth.#at(object, '#pieces') === 'number'))\n return true;\n const failed = Mouth.#at(object, 'error');\n const code = Mouth.#at(failed, 'code');\n const whole = typeof failed === 'object' && failed !== null && Object.keys(failed).length === 2;\n return (\n whole && typeof code === 'string' && Mouth.#code.test(code) && typeof Mouth.#at(failed, 'message') === 'string'\n );\n }\n\n static #canonical(value ) {\n if (typeof value === 'number' && !Number.isFinite(value)) throw new TypeError('no data holds this number');\n if (Array.isArray(value)) return `[${value.map((one) => Mouth.#canonical(one)).join(',')}]`;\n if (typeof value !== 'object' || value === null) return JSON.stringify(value);\n const fields = Object.entries(value).toSorted(([one], [other]) => (one < other ? -1 : 1));\n return `{${fields.map(([key, one]) => `${JSON.stringify(key)}:${Mouth.#canonical(one)}`).join(',')}}`;\n }\n\n #read(object ) {\n const read = this.codec.read(object);\n if ('data' in read) return read;\n try {\n return this.codec.read(Mouth.#canonical(JSON.parse(object)));\n } catch {\n return read;\n }\n }\n\n #heard(read ) {\n const object = Mouth.#at(read, 'object');\n if (typeof object === 'string') {\n const answer = this.#read(object);\n if (!('data' in answer)) return Mouth.#failed('unavailable', `the being answered no data: ${answer.why}`);\n return Mouth.#nervur(answer.data) ? answer.data : { result: answer.data };\n }\n if (Mouth.#at(read, 'silence') === true) return Mouth.#failed('silent', 'the being said nothing');\n const word = Mouth.#at(read, 'quo');\n if (word === 'removed' || word === 'repeated') return Mouth.#failed(word, `the being's door said ${word}`);\n if (typeof word === 'string') return Mouth.#failed('unavailable', `the being's door said ${word}`);\n return Mouth.#failed('unavailable', 'no reply came, so the ask may have run');\n }\n\n *#sent(ward , addresses , box , timeout , landed ) {\n let carried = false;\n for (const [at, address] of addresses.entries()) {\n const sent = yield {\n placeholder: 'network',\n method: 'send',\n args: { address, ward, bytes: box },\n timeout,\n };\n const reply = 'result' in sent ? Mouth.#at(sent.result, 'reply') : null;\n if (reply !== null) {\n if (landed !== undefined) landed.at = at;\n return reply;\n }\n if ('error' in sent && sent.error.code === 'timeout') return 'timeout';\n carried ||= 'result' in sent;\n }\n return carried ? null : Mouth.#unreached;\n }\n\n *#kept(far , knock ) {\n const kept = yield {\n placeholder: 'brain',\n method: 'keep',\n args: { far, standing: knock },\n };\n return 'error' in kept ? kept.error.message : null;\n }\n\n *#lapsed(standing , pending ) {\n const lapsed = yield* this.#key('lapsed', { standing, pending });\n return typeof Mouth.#at(lapsed, 'why') === 'string' ? standing : lapsed;\n }\n\n *#past(\n first ,\n on ,\n ) {\n const silent = (read ) => Mouth.#at(Mouth.#at(read, 'read'), 'silence') === true;\n for (let rest = on.addresses; silent(first) && rest.length > 0; rest = rest.slice(1)) {\n const reply = yield* this.#sent(on.ward, rest.slice(0, 1), on.box, on.timeout);\n if (reply === null || reply === Mouth.#unreached || reply === 'timeout') continue;\n const read = yield* this.#key('read', { standing: on.moved, pending: on.pending, reply });\n if (typeof Mouth.#at(read, 'why') !== 'string' && !silent(read)) return read;\n }\n return first;\n }\n\n *#box(far , standing , newest , ask , timeout ) {\n const sealed = yield* this.#key('seal', { standing, ask });\n const why = Mouth.#at(sealed, 'why');\n if (typeof why === 'string') return { heard: Mouth.#failed('refused', why), standing, at: newest };\n const moved = Mouth.#at(sealed, 'standing');\n const pending = Mouth.#at(sealed, 'pending');\n const knock = Mouth.#at(pending, 'kind') === 'knock';\n const again = knock && Mouth.#at(standing, 'phase') === 'uncertain';\n const unkept = !again ? yield* this.#kept(far, moved) : null;\n if (unkept !== null) return { heard: Mouth.#failed('unavailable', unkept), standing, at: newest };\n const invitation = Mouth.#at(moved, 'invitation');\n const offered = Array.isArray(newest) ? newest : Mouth.#at(invitation, 'at');\n const addresses = Array.isArray(offered) ? offered : [];\n const ward = Mouth.#at(invitation, 'ward');\n const box = Mouth.#at(sealed, 'box');\n const landed = { at: 0 };\n let sent = yield* this.#sent(ward, addresses, box, timeout, landed);\n for (let tries = 0; sent === null; tries += 1) {\n const paused = yield { placeholder: 'brain', method: 'pause', args: { far, tries } };\n if ('error' in paused) return { heard: { error: paused.error }, standing: moved, at: newest };\n const left = Mouth.#at(paused.result, 'left');\n if (typeof left !== 'number' || left <= 0) break;\n sent = yield* this.#sent(ward, addresses, box, left, landed);\n }\n const reply = sent === Mouth.#unreached ? null : sent;\n if (reply === 'timeout')\n return {\n heard: Mouth.#failed('timeout', 'no reply came within the timeout'),\n standing: yield* this.#lapsed(moved, pending),\n at: newest,\n };\n const first = yield* this.#key('read', { standing: moved, pending, reply });\n const read = yield* this.#past(first, {\n ward,\n addresses: addresses.slice(landed.at + 1),\n box,\n timeout,\n moved,\n pending,\n });\n const unread = Mouth.#at(read, 'why');\n if (typeof unread === 'string') return { heard: Mouth.#failed('unavailable', unread), standing: moved, at: newest };\n const heard = Mouth.#at(read, 'read');\n const at = Mouth.#at(heard, 'at');\n const kept = Array.isArray(at) && at.length > 0 ? at : newest;\n return { read: heard, standing: Mouth.#at(read, 'standing'), at: kept, again };\n }\n\n #answered(heard ) {\n const failed = Mouth.#at(heard, 'error');\n const code = Mouth.#at(failed, 'code');\n const message = Mouth.#at(failed, 'message');\n if (typeof code === 'string') return this.error(code, typeof message === 'string' ? message : code);\n const plain = typeof heard === 'object' && heard !== null && Object.hasOwn(heard, 'result');\n return plain ? Mouth.#at(heard, 'result') : this.error('unavailable', 'the being answered no answer');\n }\n\n *once(args ) {\n const card = Mouth.#at(args, 'card');\n const ward = Mouth.#at(card, 'ward');\n const at = Mouth.#at(card, 'at');\n const method = Mouth.#at(args, 'method');\n const addresses = Array.isArray(at) ? at.filter((one) => typeof one === 'string') : null;\n if (\n typeof ward !== 'string' ||\n !Mouth.#ward.test(ward) ||\n addresses?.length !== (Array.isArray(at) ? at.length : -1)\n )\n return this.error('refused', 'once takes a card: a ward and its addresses');\n if (method !== null && typeof method !== 'string') return this.error('refused', 'the method of an ask is text');\n const given = method === null ? {} : (Mouth.#at(args, 'args') ?? {});\n const ask = { ...(method === null ? {} : { method }), args: this.codec.text(given) };\n const zero = yield* this.#key('askZero', { ward, ask });\n const why = Mouth.#at(zero, 'why');\n if (typeof why === 'string') return this.error('refused', why);\n const sent = yield* this.#sent(ward, addresses, Mouth.#at(zero, 'box'));\n const reply = sent === Mouth.#unreached ? null : sent;\n if (reply === 'timeout') return this.error('timeout', 'no reply came within the timeout');\n const pending = Mouth.#at(zero, 'pending');\n const read = yield* this.#key('readZero', { ward, pending, reply });\n const unread = Mouth.#at(read, 'why');\n if (typeof unread === 'string') return this.error('unavailable', unread);\n return this.#answered(this.#heard(read));\n }\n\n *accept(args ) {\n const given = Mouth.#at(args, 'invitation');\n const placeholder = Mouth.#at(args, 'placeholder');\n if (typeof given !== 'string' || typeof placeholder !== 'string')\n return this.error('refused', 'accept takes an invitation and a placeholder');\n const text = given.replace(Mouth.#blank, '');\n const named = Mouth.#at(args, 'node');\n if (named !== null && this.stamp.asker !== 'brain') return this.error('refused', \"node is the brain's alone\");\n const node = this.stamp.asker === 'brain' ? named : this.stamp.asker;\n if (typeof node !== 'string') return this.error('refused', 'the brain names the lobe it accepts for');\n const standing = yield* this.#key('standingOn', { invitation: text });\n const unsealed = Mouth.#at(standing, 'why');\n if (typeof unsealed === 'string') return this.error('refused', unsealed);\n const note = Mouth.#at(args, 'note');\n const { waits, lives, anchor } = Mouth.#spans(text);\n const stood = yield {\n placeholder: 'brain',\n method: 'stand',\n args: { node, placeholder, standing, note, waits, lives, anchor },\n };\n if ('error' in stood) return this.error('refused', stood.error.message);\n return { far: Mouth.#at(stood.result, 'far') };\n }\n\n *vouch(args ) {\n const domain = Mouth.#at(args, 'domain');\n if (typeof domain !== 'string') return this.error('refused', 'vouch takes a domain');\n const request = { method: 'GET', url: `https://${domain}/.well-known/quo`, headers: {}, body: new Uint8Array(0) };\n const sent = yield { placeholder: 'network', method: 'send', args: request };\n if ('error' in sent || Mouth.#at(sent.result, 'status') !== 200) return null;\n return { body: Mouth.#at(sent.result, 'body') };\n }\n\n *#handed(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return 'result' in answer ? answer.result : this.error('refused', answer.error.message);\n }\n\n *taking() {\n return yield* this.#handed('taking', {});\n }\n\n *cede(args ) {\n return yield* this.#handed('cede', args);\n }\n\n *take(args ) {\n return yield* this.#handed('take', args);\n }\n\n *drop(args ) {\n const far = Mouth.#at(args, 'far');\n if (typeof far !== 'string') return this.error('refused', 'drop takes a far organism');\n const left = yield {\n placeholder: 'brain',\n method: 'leave',\n args: { node: this.stamp.asker, far },\n };\n return 'error' in left ? this.error('refused', left.error.message) : null;\n }\n\n *carry(args ) {\n const far = Mouth.#at(args, 'far');\n const method = Mouth.#at(args, 'method');\n const timeout = Mouth.#at(args, 'timeout');\n const room = Mouth.#at(args, 'room');\n if (typeof far !== 'string' || typeof timeout !== 'number' || typeof room !== 'number')\n return this.error('refused', 'carry takes a far organism, a timeout and the room of a box');\n const given = method === null ? {} : Mouth.#at(args, 'args');\n const ask = { ...(typeof method === 'string' ? { method } : {}), args: this.codec.text(given) };\n let sent = { standing: Mouth.#at(args, 'standing'), at: Mouth.#at(args, 'at') };\n if (typeof method !== 'string' || this.#cost(ask.args) <= room)\n sent = yield* this.#asked(far, Mouth.#at(sent, 'standing'), Mouth.#at(sent, 'at'), ask, timeout);\n else {\n for (let at = 0, from = 0; from < ask.args.length; at += 1) {\n const end = this.#end(ask.args, from, room);\n sent = yield* this.#next(far, sent, Mouth.#in, { at, part: ask.args.slice(from, end) }, timeout);\n if (Mouth.#broken(sent) && !Mouth.#repeated(sent)) return sent;\n from = end;\n }\n sent = yield* this.#next(far, sent, Mouth.#whole, { method, units: ask.args.length }, timeout);\n if (Mouth.#repeated(sent)) {\n const told = yield* this.#next(far, sent, Mouth.#out, {}, timeout);\n const length = Mouth.#at(Mouth.#at(told, 'heard'), 'result');\n sent = Mouth.#hearing(told, typeof length === 'number' ? { '#pieces': length } : Mouth.#at(sent, 'heard'));\n }\n }\n const units = Mouth.#at(Mouth.#at(sent, 'heard'), '#pieces');\n if (typeof units !== 'number' || Mouth.#broken(sent)) return sent;\n const parts = [];\n for (let from = 0; from < units;) {\n sent = yield* this.#next(far, sent, Mouth.#out, { from }, timeout);\n if (Mouth.#repeated(sent)) continue;\n const part = Mouth.#at(Mouth.#at(sent, 'heard'), 'result');\n if (Mouth.#broken(sent)) return sent;\n if (typeof part !== 'string' || part === '')\n return Mouth.#hearing(sent, Mouth.#failed('unavailable', 'a piece of the answer is no text'));\n parts.push(part);\n from += part.length;\n }\n const whole = parts.join('');\n const read = this.codec.read(whole);\n const heard =\n whole.length === units && 'data' in read\n ? read.data\n : Mouth.#failed('unavailable', 'the answer came back in pieces that make no whole');\n return Mouth.#hearing(sent, heard);\n }\n\n #cost(text ) {\n const bytes = this.codec.utf8(this.codec.text(text));\n if ('why' in bytes) throw new TypeError(bytes.why);\n return bytes.bytes.length - 2;\n }\n\n #end(text , from , room ) {\n let units = Math.min(text.length - from, room);\n for (;;) {\n let end = from + units;\n const last = text.charCodeAt(end - 1);\n if (end < text.length && last >= 0xd800 && last < 0xdc00) end += end - 1 > from ? -1 : 1;\n const cost = this.#cost(text.slice(from, end));\n if (cost <= room || units === 1) return end;\n units = Math.max(1, Math.floor(((end - from) * room) / cost));\n }\n }\n\n static #hearing(sent , heard ) {\n return { heard, standing: Mouth.#at(sent, 'standing'), at: Mouth.#at(sent, 'at'), answered: true };\n }\n\n *#next(far , before , method , args , timeout ) {\n const ask = { method, args: this.codec.text(args) };\n return yield* this.#asked(far, Mouth.#at(before, 'standing'), Mouth.#at(before, 'at'), ask, timeout);\n }\n\n static #broken(sent ) {\n return Mouth.#at(Mouth.#at(sent, 'heard'), 'error') !== null;\n }\n\n static #repeated(sent ) {\n return Mouth.#at(Mouth.#at(Mouth.#at(sent, 'heard'), 'error'), 'code') === 'repeated';\n }\n\n *#asked(far , standing , newest , ask , timeout ) {\n const first = yield* this.#box(far, standing, newest, ask, timeout);\n const read = Mouth.#at(first, 'read');\n const resolved = Mouth.#at(first, 'again') === true && Mouth.#at(read, 'nothing') !== true;\n const moved = Mouth.#at(first, 'standing');\n const last = resolved ? yield* this.#box(far, moved, Mouth.#at(first, 'at'), ask, timeout) : first;\n const heard = Mouth.#at(last, 'heard') ?? this.#heard(Mouth.#at(last, 'read'));\n const answered = typeof Mouth.#at(Mouth.#at(last, 'read'), 'object') === 'string' ? { answered: true } : {};\n return { heard, standing: Mouth.#at(last, 'standing'), at: Mouth.#at(last, 'at'), ...answered };\n }\n}";
|
|
4432
|
+
var MOUTH_TEXT = "class Mouth extends Faculty {\n static #text = { type: 'string', minLength: 1 };\n static #named = { type: 'string', pattern: '^[0-9a-f]{2432}$' };\n static #bytes = { type: 'string', contentEncoding: 'base16' };\n\n static blueprint = {\n name: 'nervur.mouth',\n version: '0.37.6',\n description:\n 'The mouth: it seals the asks of the relations this organism holds as the standing, and opens their replies; the brain keeps every standing.',\n methods: {\n accept: {\n description:\n \"The organism accepts an invitation, at the ask of the asker, never the asker: the brain makes a far organism for its relation, keeps the standing as the organism's, and grants it to the asker by wiring the asker's placeholder to it, one wire each; an owner grants it to other lobes by `grant`. Its text is read past every ASCII whitespace, so one a mail wrapped or a hand spaced reads as it was written. The spans the invitation carries go to the brain, so the standing lapses here by this side's clock: unknocked past `waits`, bound past `lives`; and its anchor's mark, so it ends only once the far brain answered its owner's `drop`. With `note`, free data of at most 4 KiB as its canonical text by default and never a secret, what the organism holds, from whom and what for: the brain keeps it beside the standing as its own, null where none is named, and it never travels to the inviter; the asker's own note on it starts empty and is written through its `nerves`. With `node`, asked by the brain alone for an owner from afar, the standing is granted to that lobe rather than to the asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { invitation: Mouth.#text, placeholder: Mouth.#text, note: {}, node: Mouth.#text },\n required: ['invitation', 'placeholder'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { far: Mouth.#text },\n required: ['far'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n carry: {\n askers: ['brain'],\n description:\n \"The brain's alone: seals an ask on a standing, has the brain keep before its box goes what it needs kept, the bound its number lies below or the standing whole with its knock or probe, sends it to the first address that takes it, the same box again after the brain's pause where a door replied nothing, and answers what the asker hears, the standing moved, the being's newest addresses, and `answered` where the being's object came back, so the brain marks a standing fallen silent bound again.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n far: Mouth.#text,\n standing: { type: 'object' },\n at: { anyOf: [{ type: 'array', items: Mouth.#text }, { type: 'null' }] },\n method: { anyOf: [Mouth.#text, { type: 'null' }] },\n args: {},\n timeout: { type: 'number', minimum: 0 },\n room: { type: 'integer', minimum: 1 },\n },\n required: ['far', 'standing', 'at', 'method', 'args', 'timeout', 'room'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: {\n heard: {},\n standing: { type: 'object' },\n at: { anyOf: [{ type: 'array', items: Mouth.#text }, { type: 'null' }] },\n answered: { const: true },\n },\n required: ['heard', 'standing', 'at'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n cede: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` seal a standing whole, its numbers as the brain hands them, with what the brain keeps `beside` it, to `to`, the public half of a key another organism's `taking` drew, and answers `{handed}`, which no lobe reads; refused where `to` is no named key.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { standing: { type: 'object' }, beside: { type: 'object' }, to: Mouth.#named },\n required: ['standing', 'beside', 'to'],\n additionalProperties: false,\n },\n result: { type: 'object' },\n errors: ['refused'],\n },\n drop: {\n irreversible: true,\n description:\n \"The asker gives up the standing of a far organism it is granted, accepted through the mouth: its wire and its note go and it is asked `left`; where it was the last lobe wired, the brain sends the inviting side one last letter, `#leave`, then forgets the standing whatever answers, with its notes, and asks each other lobe that was wired `left`. One its invitation marked an anchor's the brain first asks the far brain its owner's `drop`, and forgets only once it answered or had ended it; refused, with the far brain's why or as unheard, it is kept.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { far: Mouth.#text },\n required: ['far'],\n additionalProperties: false,\n },\n result: { type: 'null' },\n errors: ['refused'],\n },\n once: {\n description:\n \"Asks once with no relation: the ask goes on the zero head of the card's ward, at the first of its addresses that takes it, and the asker hears what the being answered. No far organism is made.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n card: {\n type: 'object',\n properties: {\n ward: { type: 'string', pattern: '^[0-9a-f]{128}$' },\n at: { type: 'array', items: Mouth.#text },\n },\n required: ['ward', 'at'],\n additionalProperties: false,\n },\n method: Mouth.#text,\n args: { type: 'object' },\n },\n required: ['card'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n take: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` open a standing `cede` handed by the key `taking` drew, the secret it sealed named in `taking`, and seal it again under this organism's record key, and answers `{standing, beside}`; refused where it is not sealed to that key.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n taking: {\n type: 'object',\n properties: { key: Mouth.#named, sealed: Mouth.#bytes },\n required: ['key', 'sealed'],\n additionalProperties: false,\n },\n handed: Mouth.#bytes,\n },\n required: ['taking', 'handed'],\n additionalProperties: false,\n },\n result: { type: 'object' },\n errors: ['refused'],\n },\n taking: {\n askers: ['brain'],\n description:\n \"The brain's alone: has `key` draw a key a standing is handed to, and answers `{key, sealed}`, its public half and its secret sealed, which only that `key` opens.\",\n kind: 'reading',\n args: { type: 'object', properties: {}, additionalProperties: false },\n result: { type: 'object' },\n errors: ['refused'],\n },\n vouch: {\n askers: ['brain'],\n description:\n \"The brain's alone: reads a domain's vouch, `https://<domain>/.well-known/quo`, through `network`, and answers its body as bytes, or null where it answered no 200 or nothing at all.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { domain: Mouth.#text },\n required: ['domain'],\n additionalProperties: false,\n },\n result: { anyOf: [{ type: 'object' }, { type: 'null' }] },\n errors: ['refused'],\n },\n },\n placeholders: { brain: 'nervur.brain', network: 'nervur.network', key: 'nervur.key' },\n };\n\n static #ward = /^[0-9a-f]{128}$/;\n static #code = /^(?=.{1,64}$)[a-z0-9]+(-[a-z0-9]+)*$/;\n static #blank = /[\\t\\n\\f\\r]/gu;\n static #unreached = 'unreached';\n static #in = '#in';\n static #whole = '#whole';\n static #out = '#out';\n\n static #at(data , key ) {\n return Mouth.field(data, key) ?? null;\n }\n\n static #spans(given ) \n \n \n \n {\n let parsed = null;\n try {\n const outer = JSON.parse(given);\n const text = typeof outer === 'object' && outer !== null ? Reflect.get(outer, 'text') : null;\n parsed = typeof text === 'string' ? JSON.parse(text) : null;\n } catch {\n parsed = null;\n }\n const span = (key ) => {\n const value = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, key) : null;\n return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : null;\n };\n const marked = typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'anchor') : null;\n return { waits: span('waits'), lives: span('lives'), anchor: marked === true };\n }\n\n static #failed(code , message ) {\n return { error: { code, message } };\n }\n\n *#key(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return 'result' in answer ? answer.result : { why: answer.error.message };\n }\n\n static #nervur(object ) {\n const keys = typeof object === 'object' && object !== null ? Object.keys(object) : [];\n if (keys.length !== 1) return false;\n if (keys[0] === 'result' || (keys[0] === '#pieces' && typeof Mouth.#at(object, '#pieces') === 'number'))\n return true;\n const failed = Mouth.#at(object, 'error');\n const code = Mouth.#at(failed, 'code');\n const whole = typeof failed === 'object' && failed !== null && Object.keys(failed).length === 2;\n return (\n whole && typeof code === 'string' && Mouth.#code.test(code) && typeof Mouth.#at(failed, 'message') === 'string'\n );\n }\n\n static #canonical(value ) {\n if (typeof value === 'number' && !Number.isFinite(value)) throw new TypeError('no data holds this number');\n if (Array.isArray(value)) return `[${value.map((one) => Mouth.#canonical(one)).join(',')}]`;\n if (typeof value !== 'object' || value === null) return JSON.stringify(value);\n const fields = Object.entries(value).toSorted(([one], [other]) => (one < other ? -1 : 1));\n return `{${fields.map(([key, one]) => `${JSON.stringify(key)}:${Mouth.#canonical(one)}`).join(',')}}`;\n }\n\n #read(object ) {\n const read = this.codec.read(object);\n if ('data' in read) return read;\n try {\n return this.codec.read(Mouth.#canonical(JSON.parse(object)));\n } catch {\n return read;\n }\n }\n\n #heard(read ) {\n const object = Mouth.#at(read, 'object');\n if (typeof object === 'string') {\n const answer = this.#read(object);\n if (!('data' in answer)) return Mouth.#failed('unavailable', `the being answered no data: ${answer.why}`);\n return Mouth.#nervur(answer.data) ? answer.data : { result: answer.data };\n }\n if (Mouth.#at(read, 'silence') === true) return Mouth.#failed('silent', 'the being said nothing');\n const word = Mouth.#at(read, 'quo');\n if (word === 'removed' || word === 'repeated') return Mouth.#failed(word, `the being's door said ${word}`);\n if (typeof word === 'string') return Mouth.#failed('unavailable', `the being's door said ${word}`);\n return Mouth.#failed('unavailable', 'no reply came, so the ask may have run');\n }\n\n *#sent(ward , addresses , box , timeout , landed ) {\n let carried = false;\n for (const [at, address] of addresses.entries()) {\n const sent = yield {\n placeholder: 'network',\n method: 'send',\n args: { address, ward, bytes: box },\n timeout,\n };\n const reply = 'result' in sent ? Mouth.#at(sent.result, 'reply') : null;\n if (reply !== null) {\n if (landed !== undefined) landed.at = at;\n return reply;\n }\n if ('error' in sent && sent.error.code === 'timeout') return 'timeout';\n carried ||= 'result' in sent;\n }\n return carried ? null : Mouth.#unreached;\n }\n\n *#kept(far , knock ) {\n const kept = yield {\n placeholder: 'brain',\n method: 'keep',\n args: { far, standing: knock },\n };\n return 'error' in kept ? kept.error.message : null;\n }\n\n *#lapsed(standing , pending ) {\n const lapsed = yield* this.#key('lapsed', { standing, pending });\n return typeof Mouth.#at(lapsed, 'why') === 'string' ? standing : lapsed;\n }\n\n *#past(\n first ,\n on ,\n ) {\n const silent = (read ) => Mouth.#at(Mouth.#at(read, 'read'), 'silence') === true;\n for (let rest = on.addresses; silent(first) && rest.length > 0; rest = rest.slice(1)) {\n const reply = yield* this.#sent(on.ward, rest.slice(0, 1), on.box, on.timeout);\n if (reply === null || reply === Mouth.#unreached || reply === 'timeout') continue;\n const read = yield* this.#key('read', { standing: on.moved, pending: on.pending, reply });\n if (typeof Mouth.#at(read, 'why') !== 'string' && !silent(read)) return read;\n }\n return first;\n }\n\n *#box(far , standing , newest , ask , timeout ) {\n const sealed = yield* this.#key('seal', { standing, ask });\n const why = Mouth.#at(sealed, 'why');\n if (typeof why === 'string') return { heard: Mouth.#failed('refused', why), standing, at: newest };\n const moved = Mouth.#at(sealed, 'standing');\n const pending = Mouth.#at(sealed, 'pending');\n const knock = Mouth.#at(pending, 'kind') === 'knock';\n const again = knock && Mouth.#at(standing, 'phase') === 'uncertain';\n const unkept = !again ? yield* this.#kept(far, moved) : null;\n if (unkept !== null) return { heard: Mouth.#failed('unavailable', unkept), standing, at: newest };\n const invitation = Mouth.#at(moved, 'invitation');\n const offered = Array.isArray(newest) ? newest : Mouth.#at(invitation, 'at');\n const addresses = Array.isArray(offered) ? offered : [];\n const ward = Mouth.#at(invitation, 'ward');\n const box = Mouth.#at(sealed, 'box');\n const landed = { at: 0 };\n let sent = yield* this.#sent(ward, addresses, box, timeout, landed);\n for (let tries = 0; sent === null; tries += 1) {\n const paused = yield { placeholder: 'brain', method: 'pause', args: { far, tries } };\n if ('error' in paused) return { heard: { error: paused.error }, standing: moved, at: newest };\n const left = Mouth.#at(paused.result, 'left');\n if (typeof left !== 'number' || left <= 0) break;\n sent = yield* this.#sent(ward, addresses, box, left, landed);\n }\n const reply = sent === Mouth.#unreached ? null : sent;\n if (reply === 'timeout')\n return {\n heard: Mouth.#failed('timeout', 'no reply came within the timeout'),\n standing: yield* this.#lapsed(moved, pending),\n at: newest,\n };\n const first = yield* this.#key('read', { standing: moved, pending, reply });\n const read = yield* this.#past(first, {\n ward,\n addresses: addresses.slice(landed.at + 1),\n box,\n timeout,\n moved,\n pending,\n });\n const unread = Mouth.#at(read, 'why');\n if (typeof unread === 'string') return { heard: Mouth.#failed('unavailable', unread), standing: moved, at: newest };\n const heard = Mouth.#at(read, 'read');\n const at = Mouth.#at(heard, 'at');\n const kept = Array.isArray(at) && at.length > 0 ? at : newest;\n return { read: heard, standing: Mouth.#at(read, 'standing'), at: kept, again };\n }\n\n #answered(heard ) {\n const failed = Mouth.#at(heard, 'error');\n const code = Mouth.#at(failed, 'code');\n const message = Mouth.#at(failed, 'message');\n if (typeof code === 'string') return this.error(code, typeof message === 'string' ? message : code);\n const plain = typeof heard === 'object' && heard !== null && Object.hasOwn(heard, 'result');\n return plain ? Mouth.#at(heard, 'result') : this.error('unavailable', 'the being answered no answer');\n }\n\n *once(args ) {\n const card = Mouth.#at(args, 'card');\n const ward = Mouth.#at(card, 'ward');\n const at = Mouth.#at(card, 'at');\n const method = Mouth.#at(args, 'method');\n const addresses = Array.isArray(at) ? at.filter((one) => typeof one === 'string') : null;\n if (\n typeof ward !== 'string' ||\n !Mouth.#ward.test(ward) ||\n addresses?.length !== (Array.isArray(at) ? at.length : -1)\n )\n return this.error('refused', 'once takes a card: a ward and its addresses');\n if (method !== null && typeof method !== 'string') return this.error('refused', 'the method of an ask is text');\n const given = method === null ? {} : (Mouth.#at(args, 'args') ?? {});\n const ask = { ...(method === null ? {} : { method }), args: this.codec.text(given) };\n const zero = yield* this.#key('askZero', { ward, ask });\n const why = Mouth.#at(zero, 'why');\n if (typeof why === 'string') return this.error('refused', why);\n const sent = yield* this.#sent(ward, addresses, Mouth.#at(zero, 'box'));\n const reply = sent === Mouth.#unreached ? null : sent;\n if (reply === 'timeout') return this.error('timeout', 'no reply came within the timeout');\n const pending = Mouth.#at(zero, 'pending');\n const read = yield* this.#key('readZero', { ward, pending, reply });\n const unread = Mouth.#at(read, 'why');\n if (typeof unread === 'string') return this.error('unavailable', unread);\n return this.#answered(this.#heard(read));\n }\n\n *accept(args ) {\n const given = Mouth.#at(args, 'invitation');\n const placeholder = Mouth.#at(args, 'placeholder');\n if (typeof given !== 'string' || typeof placeholder !== 'string')\n return this.error('refused', 'accept takes an invitation and a placeholder');\n const text = given.replace(Mouth.#blank, '');\n const named = Mouth.#at(args, 'node');\n if (named !== null && this.stamp.asker !== 'brain') return this.error('refused', \"node is the brain's alone\");\n const node = this.stamp.asker === 'brain' ? named : this.stamp.asker;\n if (typeof node !== 'string') return this.error('refused', 'the brain names the lobe it accepts for');\n const standing = yield* this.#key('standingOn', { invitation: text });\n const unsealed = Mouth.#at(standing, 'why');\n if (typeof unsealed === 'string') return this.error('refused', unsealed);\n const note = Mouth.#at(args, 'note');\n const { waits, lives, anchor } = Mouth.#spans(text);\n const stood = yield {\n placeholder: 'brain',\n method: 'stand',\n args: { node, placeholder, standing, note, waits, lives, anchor },\n };\n if ('error' in stood) return this.error('refused', stood.error.message);\n return { far: Mouth.#at(stood.result, 'far') };\n }\n\n *vouch(args ) {\n const domain = Mouth.#at(args, 'domain');\n if (typeof domain !== 'string') return this.error('refused', 'vouch takes a domain');\n const request = { method: 'GET', url: `https://${domain}/.well-known/quo`, headers: {}, body: new Uint8Array(0) };\n const sent = yield { placeholder: 'network', method: 'send', args: request };\n if ('error' in sent || Mouth.#at(sent.result, 'status') !== 200) return null;\n return { body: Mouth.#at(sent.result, 'body') };\n }\n\n *#handed(method , args ) {\n const answer = yield { placeholder: 'key', method, args };\n return 'result' in answer ? answer.result : this.error('refused', answer.error.message);\n }\n\n *taking() {\n return yield* this.#handed('taking', {});\n }\n\n *cede(args ) {\n return yield* this.#handed('cede', args);\n }\n\n *take(args ) {\n return yield* this.#handed('take', args);\n }\n\n *drop(args ) {\n const far = Mouth.#at(args, 'far');\n if (typeof far !== 'string') return this.error('refused', 'drop takes a far organism');\n const left = yield {\n placeholder: 'brain',\n method: 'leave',\n args: { node: this.stamp.asker, far },\n };\n return 'error' in left ? this.error('refused', left.error.message) : null;\n }\n\n *carry(args ) {\n const far = Mouth.#at(args, 'far');\n const method = Mouth.#at(args, 'method');\n const timeout = Mouth.#at(args, 'timeout');\n const room = Mouth.#at(args, 'room');\n if (typeof far !== 'string' || typeof timeout !== 'number' || typeof room !== 'number')\n return this.error('refused', 'carry takes a far organism, a timeout and the room of a box');\n const given = method === null ? {} : Mouth.#at(args, 'args');\n const ask = { ...(typeof method === 'string' ? { method } : {}), args: this.codec.text(given) };\n let sent = { standing: Mouth.#at(args, 'standing'), at: Mouth.#at(args, 'at') };\n if (typeof method !== 'string' || this.#cost(ask.args) <= room)\n sent = yield* this.#asked(far, Mouth.#at(sent, 'standing'), Mouth.#at(sent, 'at'), ask, timeout);\n else {\n for (let at = 0, from = 0; from < ask.args.length; at += 1) {\n const end = this.#end(ask.args, from, room);\n sent = yield* this.#next(far, sent, Mouth.#in, { at, part: ask.args.slice(from, end) }, timeout);\n if (Mouth.#broken(sent) && !Mouth.#repeated(sent)) return sent;\n from = end;\n }\n sent = yield* this.#next(far, sent, Mouth.#whole, { method, units: ask.args.length }, timeout);\n if (Mouth.#repeated(sent)) {\n const told = yield* this.#next(far, sent, Mouth.#out, {}, timeout);\n const length = Mouth.#at(Mouth.#at(told, 'heard'), 'result');\n sent = Mouth.#hearing(told, typeof length === 'number' ? { '#pieces': length } : Mouth.#at(sent, 'heard'));\n }\n }\n const units = Mouth.#at(Mouth.#at(sent, 'heard'), '#pieces');\n if (typeof units !== 'number' || Mouth.#broken(sent)) return sent;\n const parts = [];\n for (let from = 0; from < units;) {\n sent = yield* this.#next(far, sent, Mouth.#out, { from }, timeout);\n if (Mouth.#repeated(sent)) continue;\n const part = Mouth.#at(Mouth.#at(sent, 'heard'), 'result');\n if (Mouth.#broken(sent)) return sent;\n if (typeof part !== 'string' || part === '')\n return Mouth.#hearing(sent, Mouth.#failed('unavailable', 'a piece of the answer is no text'));\n parts.push(part);\n from += part.length;\n }\n const whole = parts.join('');\n const read = this.codec.read(whole);\n const heard =\n whole.length === units && 'data' in read\n ? read.data\n : Mouth.#failed('unavailable', 'the answer came back in pieces that make no whole');\n return Mouth.#hearing(sent, heard);\n }\n\n #cost(text ) {\n const bytes = this.codec.utf8(this.codec.text(text));\n if ('why' in bytes) throw new TypeError(bytes.why);\n return bytes.bytes.length - 2;\n }\n\n #end(text , from , room ) {\n let units = Math.min(text.length - from, room);\n for (;;) {\n let end = from + units;\n const last = text.charCodeAt(end - 1);\n if (end < text.length && last >= 0xd800 && last < 0xdc00) end += end - 1 > from ? -1 : 1;\n const cost = this.#cost(text.slice(from, end));\n if (cost <= room || units === 1) return end;\n units = Math.max(1, Math.floor(((end - from) * room) / cost));\n }\n }\n\n static #hearing(sent , heard ) {\n return { heard, standing: Mouth.#at(sent, 'standing'), at: Mouth.#at(sent, 'at'), answered: true };\n }\n\n *#next(far , before , method , args , timeout ) {\n const ask = { method, args: this.codec.text(args) };\n return yield* this.#asked(far, Mouth.#at(before, 'standing'), Mouth.#at(before, 'at'), ask, timeout);\n }\n\n static #broken(sent ) {\n return Mouth.#at(Mouth.#at(sent, 'heard'), 'error') !== null;\n }\n\n static #repeated(sent ) {\n return Mouth.#at(Mouth.#at(Mouth.#at(sent, 'heard'), 'error'), 'code') === 'repeated';\n }\n\n *#asked(far , standing , newest , ask , timeout ) {\n const first = yield* this.#box(far, standing, newest, ask, timeout);\n const read = Mouth.#at(first, 'read');\n const resolved = Mouth.#at(first, 'again') === true && Mouth.#at(read, 'nothing') !== true;\n const moved = Mouth.#at(first, 'standing');\n const last = resolved ? yield* this.#box(far, moved, Mouth.#at(first, 'at'), ask, timeout) : first;\n const heard = Mouth.#at(last, 'heard') ?? this.#heard(Mouth.#at(last, 'read'));\n const answered = typeof Mouth.#at(Mouth.#at(last, 'read'), 'object') === 'string' ? { answered: true } : {};\n return { heard, standing: Mouth.#at(last, 'standing'), at: Mouth.#at(last, 'at'), ...answered };\n }\n}";
|
|
4433
4433
|
|
|
4434
4434
|
var MOUTH_SOURCE = facultySource(MOUTH_TEXT);
|
|
4435
4435
|
|
|
@@ -5494,7 +5494,7 @@ var Library = class _Library extends Faculty {
|
|
|
5494
5494
|
|
|
5495
5495
|
var LIBRARY_BLUEPRINT = {
|
|
5496
5496
|
name: "nervur.library",
|
|
5497
|
-
version: "0.37.
|
|
5497
|
+
version: "0.37.6",
|
|
5498
5498
|
description: "The library: it keeps the organism's faculties with their assets, and its organs, as data, each version by its digest, and the versions its sources told it.",
|
|
5499
5499
|
methods: {
|
|
5500
5500
|
add: {
|
|
@@ -5751,13 +5751,13 @@ var LIBRARY_BLUEPRINT = {
|
|
|
5751
5751
|
placeholders: { brain: "nervur.brain", mouth: "nervur.mouth", ear: "nervur.ear" }
|
|
5752
5752
|
};
|
|
5753
5753
|
|
|
5754
|
-
var LIBRARY_TEXT = "class Library extends Faculty {\n static #digest = { type: 'string', pattern: '^[0-9a-f]{64}$' };\n\n static #road = { type: 'string', minLength: 1, maxLength: 256 };\n\n static #assets = {\n type: 'array',\n items: { type: 'array', items: { type: 'string', minLength: 1 }, minItems: 2, maxItems: 2 },\n };\n\n static #faculty = {\n type: 'object',\n properties: {\n source: { type: 'string', minLength: 1 },\n digest: Library.#digest,\n blueprint: { type: 'object' },\n road: Library.#road,\n label: { type: 'string', minLength: 1, maxLength: 64 },\n assets: Library.#assets,\n },\n required: ['source', 'digest', 'blueprint', 'road'],\n additionalProperties: false,\n };\n\n static #organ = {\n type: 'object',\n properties: {\n id: { type: 'string', minLength: 1, maxLength: 64 },\n digest: Library.#digest,\n graph: { type: 'string', minLength: 1 },\n blueprint: { type: 'object' },\n reach: {},\n half: { anyOf: [Library.#digest, { type: 'null' }] },\n road: Library.#road,\n },\n required: ['id', 'digest', 'graph', 'blueprint', 'half', 'road'],\n additionalProperties: false,\n };\n\n static #asset = {\n type: 'object',\n properties: { digest: Library.#digest, bytes: { type: 'string', contentEncoding: 'base16' } },\n required: ['digest', 'bytes'],\n additionalProperties: false,\n };\n\n static #lobe = { type: 'string', pattern: '^[A-Z][A-Z0-9]*$', maxLength: 64 };\n\n static #given = {\n type: 'object',\n properties: {\n kind: { const: 'faculty' },\n given: {\n type: 'object',\n properties: {\n place: Library.#lobe,\n digest: Library.#digest,\n items: { type: 'array', items: { type: 'object' }, maxItems: 1001 },\n },\n required: ['place', 'digest', 'items'],\n additionalProperties: false,\n },\n },\n required: ['kind', 'given'],\n additionalProperties: false,\n };\n\n static #hand = {\n type: 'object',\n properties: {\n source: { type: 'string', minLength: 1 },\n assets: { type: 'array', items: { type: 'object' } },\n second: { type: 'boolean' },\n },\n required: ['source'],\n additionalProperties: false,\n };\n\n static #version = {\n type: 'string',\n pattern: '^(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)$',\n };\n\n static #named = {\n type: 'string',\n pattern: '^[a-z][a-z0-9]*([.-][a-z0-9]+)*$',\n maxLength: 64,\n };\n\n static #half = {\n type: 'object',\n properties: {\n form: { enum: ['component', 'native'] },\n code: {\n anyOf: [\n { type: 'string', minLength: 1 },\n { type: 'string', contentEncoding: 'base16' },\n ],\n },\n },\n required: ['form', 'code'],\n additionalProperties: false,\n };\n\n static blueprint = {\n name: 'nervur.library',\n version: '0.37.5',\n description:\n \"The library: it keeps the organism's faculties with their assets, and its organs, as data, each version by its digest, and the versions its sources told it.\",\n methods: {\n add: {\n description:\n \"On an owner's ask through the brain alone. From a source, `road`, any lobe of the organism's own whose describe names `get` and `told`: a faculty by its label or an organ by its ID, at a version, read from it over a wire the library orders, its digest checked and its blueprint's version, and kept under the road `<lobe>@<version>`, with that lobe kept as a source of the owners' own where its `state` answers a name, once; a faculty whose blueprint names `assets` has each asset read whole by its path and checked against its SHA-256, and their canonical digest against the blueprint's, or none of it is kept. From a far source, `road`, the library holds a standing on: a faculty or an organ at a version it told, read over the standing, each digest checked against what it told, an organ by its graph.json alone, never its host half, a faculty's assets as from near. Or by an owner's hand, `source`: a faculty's text carried in the ask, with its `assets` where it has any, kept under the road `hand@<version>` by the same walls. Or a host half's form and code under the digest of its code. A code the library keeps already, added from another road, takes that road, all else as it stands; boot's laying changes no road. Answers the digest; refuses a code whose blueprint's name and version the library keeps under another digest, but with `second`, an owner's word on a faculty, which takes it as a name of its own, kept by its source.\",\n kind: 'writing',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: {\n road: Library.#lobe,\n kind: { const: 'faculty' },\n label: Library.#named,\n version: Library.#version,\n second: { type: 'boolean' },\n },\n required: ['road', 'kind', 'label', 'version'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n road: Library.#lobe,\n kind: { const: 'organ' },\n id: Library.#named,\n version: Library.#version,\n },\n required: ['road', 'kind', 'id', 'version'],\n additionalProperties: false,\n },\n Library.#given,\n Library.#hand,\n ],\n },\n result: {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n accept: {\n description:\n \"On an owner's ask through the brain alone: accepts a far source's invitation to a library's standing through the mouth, holding the relation itself on a placeholder of its own. It asks the far lobe at once what it told, `told`, and again at an add of a version not told it yet, since an organism that cannot be dialed can be told nothing. One that can names `tells`: since a relation runs one way, it draws through the ear a standing back on itself for the far lobe, the one before for that far lobe ended, and hands it as `told { tells }`, over which the far lobe tells each version it tells after, `changed`. With `note`, the owner's, which the brain keeps beside the standing, null where none is named. Answers the far organism the brain made up for it, the road an add names it by.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: { invitation: { type: 'string', minLength: 1 }, note: {}, tells: { const: true } },\n required: ['invitation'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { far: Library.#lobe },\n required: ['far'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n changed: {\n description:\n \"A source's word that its `main` holds a faculty or an organ at a version it never told: a near one's over its wire, a far one's over the occupant the library's `accept` gave it, by an ask; kept for the owners to see, by `list` with `told`, never added.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: {\n kind: { enum: ['faculty', 'organ'] },\n label: Library.#named,\n version: Library.#version,\n digest: Library.#digest,\n },\n required: ['kind', 'label', 'version', 'digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n remove: {\n irreversible: true,\n description:\n \"Deletes a version no lobe stands on with its assets no other kept faculty names, an organ's record, or a host half's code no organ names, on the brain's ask alone.\",\n kind: 'writing',\n args: Library.#byDigest(),\n errors: ['refused', 'used'],\n },\n spare: {\n description:\n \"On an owner's ask through the brain alone: keeps a version the library holds from the sweep, or, with `spared: false`, gives it back. An owner may still remove it.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: { digest: Library.#digest, spared: { type: 'boolean' } },\n required: ['digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n evidence: {\n description:\n \"The asset that carries a kept faculty's evidence, `evidence.json`, by its SHA-256, which `get` answers, or null where it carries none; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { faculty: Library.#digest },\n required: ['faculty'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { evidence: { anyOf: [Library.#digest, { type: 'null' }] } },\n required: ['evidence'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n get: {\n description:\n \"The version of a digest with its assets, an organ's record, an asset's bytes, or a host half's form and code, or null; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n },\n result: {\n anyOf: [Library.#faculty, Library.#organ, Library.#asset, Library.#half, { type: 'null' }],\n },\n errors: ['refused'],\n },\n old: {\n description:\n \"The old versions the library keeps, on the brain's ask alone: of each name, a faculty's or an organ's blueprint name, every version but the newest by semver; the brain removes each no lobe stands on.\",\n kind: 'reading',\n args: { type: 'object', additionalProperties: false },\n result: { type: 'object', properties: { digests: { type: 'array', items: { type: 'string' } } } },\n },\n list: {\n description:\n \"The versions kept, by their blueprint's name, each with its road, an organ's marked, one an owner spared marked `spared`, a faculty a source or an owner's hand brought with no evidence marked `unproven`, a page at a time; with `told`, the versions the sources told, each with whether the library keeps it; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n limit: { type: 'integer', minimum: 1 },\n told: { type: 'boolean' },\n },\n additionalProperties: false,\n },\n result: {\n anyOf: [\n {\n type: 'object',\n properties: {\n faculties: { type: 'array', items: { type: 'object' } },\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n },\n required: ['faculties', 'cursor'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n told: { type: 'array', items: { type: 'object' } },\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n },\n required: ['told', 'cursor'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n },\n placeholders: { brain: 'nervur.brain', mouth: 'nervur.mouth', ear: 'nervur.ear' },\n };\n\n static #owner = 'brain';\n\n static #contract = ['get', 'told'];\n\n static #evidence = 'evidence.json';\n\n static #handRoad = 'hand';\n\n static #versionText = /^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$/;\n static #namedText = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;\n static #lobeText = /^[A-Z][A-Z0-9]*$/;\n\n static #sent(value ) {\n if (value === undefined) return 'nothing';\n const read = JSON.stringify(value);\n return read.length > 64 ? `${read.slice(0, 63)}\u2026` : read;\n }\n\n #page() {\n return Math.min(1000, Math.floor(this.memory / 4 / 1024));\n }\n\n static #byDigest() {\n return {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n };\n }\n\n static #digestIn(args ) {\n const digest = Library.field(args, 'digest');\n return typeof digest === 'string' && /^[0-9a-f]{64}$/.test(digest) ? digest : undefined;\n }\n\n static #utf8(text ) {\n const bytes = [];\n for (const char of text) {\n const point = char.codePointAt(0) ?? 0;\n if (point < 0x80) bytes.push(point);\n else if (point < 0x800) bytes.push(0xc0 | (point >> 6), 0x80 | (point & 0x3f));\n else if (point < 0x10000) bytes.push(0xe0 | (point >> 12), 0x80 | ((point >> 6) & 0x3f), 0x80 | (point & 0x3f));\n else\n bytes.push(\n 0xf0 | (point >> 18),\n 0x80 | ((point >> 12) & 0x3f),\n 0x80 | ((point >> 6) & 0x3f),\n 0x80 | (point & 0x3f),\n );\n }\n return new Uint8Array(bytes);\n }\n\n static digestOf(crypto , code ) {\n return Library.hex(crypto.sha256(typeof code === 'string' ? Library.#utf8(code) : code));\n }\n\n static assetsDigest(\n crypto ,\n assets ,\n ) {\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n return Library.digestOf(crypto, JSON.stringify(sorted));\n }\n\n static keep(\n cells ,\n digest ,\n kept ,\n bytes = new Map(),\n ) {\n if (!('source' in kept)) {\n if (cells.get(['half', digest]) === undefined) cells.set(['half', digest], { form: kept.form, code: kept.code });\n return null;\n }\n const { source, blueprint, road, label, assets, second } = kept;\n const name = Library.field(blueprint, 'name');\n if (typeof name !== 'string') throw new TypeError('a version kept is one whose blueprint is named');\n if (cells.get(['faculty', digest]) !== undefined) return null;\n const named = Library.field(blueprint, 'assets') !== undefined;\n if (named !== (assets !== undefined))\n return named\n ? `the blueprint of ${name} names assets the faculty carries not`\n : `${name} carries assets its blueprint names not`;\n for (const [, sha] of assets ?? [])\n if (!bytes.has(sha) && cells.get(['asset', sha]) === undefined)\n return `${name} has no bytes for its asset ${sha}`;\n const indexed = Library.#indexed(cells, name, Library.field(blueprint, 'version'), digest, second);\n if (typeof indexed === 'string') return indexed;\n for (const [, sha] of assets ?? []) {\n const held = bytes.get(sha);\n if (held !== undefined && cells.get(['asset', sha]) === undefined) cells.set(['asset', sha], held);\n }\n cells.set(['faculty', digest], {\n source,\n digest,\n blueprint,\n road,\n ...(label === undefined ? {} : { label }),\n ...(assets === undefined ? {} : { assets: assets.map(([path, sha]) => [path, sha]) }),\n ...(indexed.second === undefined ? {} : { second: indexed.second }),\n });\n cells.set(['name', name, digest], label ?? null);\n return null;\n }\n\n static #indexed(\n cells ,\n name ,\n version ,\n digest ,\n second ,\n ) {\n if (typeof version !== 'string') return `the blueprint of ${name} names no version`;\n const named = cells.get(['version', name, version]);\n if (typeof named !== 'string' || named === digest) {\n cells.set(['version', name, version], digest);\n return {};\n }\n if (second === undefined) return `the library keeps ${name} ${version} under another digest, ${named}`;\n const own = cells.get(['second', name, version, second]);\n if (typeof own === 'string' && own !== digest)\n return `the library keeps ${name} ${version} of ${second} under another digest, ${own}`;\n cells.set(['second', name, version, second], digest);\n return { second };\n }\n\n *add(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library adds on an owner's ask through the brain alone\");\n if (Library.field(args, 'given') !== undefined) return yield* this.#addGiven(args);\n if (Library.field(args, 'source') !== undefined) return yield* this.#addHand(args);\n return yield* this.#addFrom(args);\n }\n\n *#read(source ) {\n const answered = yield { read: source };\n const read = 'result' in answered ? answered.result : undefined;\n const blueprint = Library.field(read, 'blueprint');\n if (blueprint !== undefined && typeof Library.field(blueprint, 'name') === 'string') return blueprint;\n const why = Library.field(read, 'why');\n return `the source is no faculty: ${typeof why === 'string' ? why : 'it declares no blueprint'}`;\n }\n\n static #fromArgs(\n args ,\n ) {\n const kind = Library.field(args, 'kind');\n const key = kind === 'organ' ? 'id' : 'label';\n const [road, named, version] = ['road', key, 'version'].map((one) => Library.field(args, one));\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n const second = Library.field(args, 'second');\n if ((kind !== 'faculty' && kind !== 'organ') || keys !== (second === undefined ? 4 : 5))\n return 'add takes a road, a kind, a faculty or an organ, its label or ID, and a version';\n if (second !== undefined && ((second !== true && second !== false) || kind !== 'faculty'))\n return `\\`second\\` is an owner's word on a faculty, true or false, not ${Library.#sent(second)}`;\n if (typeof road !== 'string' || road.length > 64 || !Library.#lobeText.test(road))\n return `a road is a lobe of this organism, by the ID the brain made up for it, not ${Library.#sent(road)}`;\n if (typeof named !== 'string' || named.length > 64 || !Library.#namedText.test(named))\n return `a ${key} is a folder's name, lowercase, not ${Library.#sent(named)}`;\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`;\n return { road, kind, named, version, second: second === true };\n }\n\n *#addFrom(args ) {\n const asked = Library.#fromArgs(args);\n if (typeof asked === 'string') return this.error('refused', asked);\n if (this.cells.get(['far', asked.road]) !== undefined) return yield* this.#addFar(asked);\n const { road, kind, named, version, second } = asked;\n const unreached = yield* this.#reach(road);\n if (unreached !== null) return this.error('refused', unreached);\n const got = yield {\n placeholder: road,\n method: 'get',\n args: { kind, label: named, version },\n };\n if ('error' in got)\n return this.error('refused', `the source ${road} answers ${got.error.code}: ${got.error.message}`);\n const from = `${road}@${version}`;\n const taken =\n kind === 'organ'\n ? this.#takeOrgan(got.result, named, version, from)\n : yield* this.#takeFaculty(got.result, from, {\n lobe: road,\n label: named,\n version,\n ...(second ? { second: road } : {}),\n });\n if (Library.#added(taken)) yield* this.#kindOf(road);\n return taken;\n }\n\n static #added(taken ) {\n return typeof taken === 'object' && taken !== null && 'digest' in taken;\n }\n\n *#kindOf(lobe ) {\n if (this.cells.get(['source', lobe]) !== undefined) return;\n const state = yield {\n placeholder: lobe,\n method: 'state',\n args: {},\n };\n const name = 'result' in state ? Library.field(state.result, 'name') : undefined;\n if (typeof name === 'string' && name !== '') this.cells.set(['source', lobe], 'owners');\n }\n\n *#reach(lobe ) {\n const order = { termination: lobe };\n const ordered = yield {\n placeholder: 'nerves',\n method: 'order',\n args: { order },\n };\n if ('error' in ordered) return `the library reaches no ${lobe}: ${ordered.error.message}`;\n const described = yield {\n placeholder: lobe,\n method: null,\n args: null,\n };\n const methods = 'result' in described ? Library.field(described.result, 'methods') : undefined;\n const lacking = Library.#contract.filter((method) => Library.field(methods, method) === undefined);\n if (lacking.length === 0) return null;\n yield {\n placeholder: 'nerves',\n method: 'unwire',\n args: { placeholder: lobe },\n };\n return `${lobe} is no source: its describe names no ${lacking.join(' and no ')}`;\n }\n\n *#takeFaculty(answered , road , at ) {\n const { label, version } = at;\n const source = Library.field(answered, 'source');\n const told = Library.field(answered, 'digest');\n if (typeof source !== 'string' || source === '') return this.error('refused', 'the source answered no source');\n const digest = Library.digestOf(this.crypto, source);\n if (told !== digest)\n return this.error('refused', `the source the source answered is not its digest, ${JSON.stringify(told ?? null)}`);\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const named = Library.field(blueprint, 'version');\n if (named !== version)\n return this.error('refused', `the faculty names version ${JSON.stringify(named ?? null)}, not ${version}`);\n const carried = yield* this.#assetsTaken(answered, blueprint, at);\n if (typeof carried === 'string') return this.error('refused', carried);\n const refused = Library.keep(\n this.cells,\n digest,\n { source, blueprint, road, label, ...carried.kept, ...(at.second === undefined ? {} : { second: at.second }) },\n carried.bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n #reroad(digest , road , version ) {\n const kept = this.cells.get(['faculty', digest]);\n const named = Library.field(Library.field(kept, 'blueprint'), 'version');\n if (named !== version)\n return this.error('refused', `the faculty names version ${JSON.stringify(named ?? null)}, not ${version}`);\n if (Library.field(kept, 'road') === road) return { digest };\n const record = {};\n for (const field of ['source', 'digest', 'blueprint', 'label', 'assets', 'second']) {\n const value = Library.field(kept, field);\n if (value !== undefined) record[field] = value;\n }\n this.cells.set(['faculty', digest], { ...record, road });\n return { digest };\n }\n\n *#assetsTaken(\n answered ,\n blueprint ,\n at ,\n ) \n \n \n \n {\n const bytes = new Map ();\n const named = Library.field(blueprint, 'assets');\n const told = Library.field(answered, 'assets');\n if (named === undefined)\n return told === undefined ? { kept: {}, bytes } : 'the source answered assets the blueprint names not';\n const assets = this.#assetsOf(told);\n if (assets === null) return 'the source answered no assets whole: each a path and a SHA-256, one path once';\n if (Library.assetsDigest(this.crypto, assets) !== named)\n return `the assets are not the digest the blueprint names, ${JSON.stringify(named)}`;\n for (const [path, sha] of assets) {\n if (bytes.has(sha) || this.cells.get(['asset', sha]) !== undefined) continue;\n const got = yield {\n placeholder: at.lobe,\n method: 'get',\n args: { kind: 'faculty', label: at.label, version: at.version, path },\n };\n if ('error' in got)\n return `the source ${at.lobe} answers ${got.error.code} for the asset ${path}: ${got.error.message}`;\n const [given, digest, held] = ['path', 'digest', 'bytes'].map((one) => Library.field(got.result, one));\n if (given !== path || digest !== sha || !(held instanceof Uint8Array))\n return `the source answered another asset than ${path}`;\n if (Library.digestOf(this.crypto, held) !== sha) return `the asset ${path} is not its digest, ${sha}`;\n bytes.set(sha, held);\n }\n return { kept: { assets }, bytes };\n }\n\n static #json(text ) {\n try {\n const read = JSON.parse(text);\n return typeof read === 'object' && read !== null && !Array.isArray(read) ? read : null;\n } catch {\n return null;\n }\n }\n\n #takeOrgan(answered , id , version , road ) {\n const graph = Library.field(answered, 'blueprint');\n const half = Library.field(answered, 'half') ?? null;\n if (typeof graph !== 'string') return this.error('refused', \"the source answered no organ's graph.json\");\n if (half !== null && (typeof half !== 'string' || !/^[0-9a-f]{64}$/.test(half)))\n return this.error('refused', 'the source answered a built half that is no digest');\n const read = Library.#json(graph);\n const inner = Library.field(read, 'blueprint');\n const blueprint = inner !== undefined && Library.#json(JSON.stringify(inner)) !== null ? inner : read;\n const name = Library.field(blueprint, 'name');\n const named = Library.field(blueprint, 'version');\n if (blueprint === null || blueprint === undefined || typeof name !== 'string')\n return this.error('refused', 'its graph.json holds no blueprint, named');\n if (named !== version)\n return this.error('refused', `the organ names version ${JSON.stringify(named ?? null)}, not ${version}`);\n const digest = Library.digestOf(this.crypto, graph);\n const kept = this.#organAt(digest);\n if (kept !== undefined) {\n if (half !== null || kept['road'] !== road)\n this.cells.set(['organ', digest], { ...kept, ...(half === null ? {} : { half }), road });\n return { digest };\n }\n const clash = Library.#indexed(this.cells, name, named, digest, undefined);\n if (typeof clash === 'string') return this.error('refused', clash);\n const reach = inner === undefined ? undefined : Library.field(read, 'reach');\n this.cells.set(['organ', digest], {\n id,\n digest,\n graph,\n blueprint,\n ...(reach === undefined ? {} : { reach }),\n half,\n road,\n });\n this.cells.set(['name', name, digest], id);\n return { digest };\n }\n\n #assetsOf(data ) {\n if (!Array.isArray(data) || data.length > this.#page()) return null;\n const assets = [];\n for (const one of data) {\n const [path, sha] = Array.isArray(one) && one.length === 2 ? one : [];\n if (typeof path !== 'string' || path === '') return null;\n if (typeof sha !== 'string' || !/^[0-9a-f]{64}$/.test(sha)) return null;\n assets.push([path, sha]);\n }\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n return sorted.every((one, at) => sorted[at - 1]?.[0] !== one[0]) ? sorted : null;\n }\n\n #assetsNamed() {\n const named = new Set ();\n let cursor = null;\n do {\n const page = this.cells.range({\n prefix: ['faculty'],\n limit: this.#page(),\n ...(cursor === null ? {} : { cursor }),\n });\n for (const { value } of page.cells)\n for (const [, sha] of this.#assetsOf(Library.field(value, 'assets')) ?? []) named.add(sha);\n cursor = page.cursor;\n } while (cursor !== null);\n return named;\n }\n\n *accept(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library accepts a standing on an owner's ask through the brain alone\");\n const invitation = Library.field(args, 'invitation');\n const note = Library.field(args, 'note');\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n const tells = Library.field(args, 'tells');\n const named = 1 + (note === undefined ? 0 : 1) + (tells === undefined ? 0 : 1);\n if (typeof invitation !== 'string' || invitation === '' || keys !== named || (tells ?? true) !== true)\n return this.error(\n 'refused',\n 'accept takes an invitation, a note where one is named, and `tells` where it can be told',\n );\n const held = this.cells.get(['standings']);\n const count = typeof held === 'number' ? held + 1 : 1;\n this.cells.set(['standings'], count);\n const placeholder = `far-${count}`;\n const accepted = yield* this.#accepted({ invitation, placeholder, note: note ?? null });\n if ('error' in accepted) return this.error('refused', `the mouth accepts no standing: ${accepted.error.message}`);\n const far = Library.field(accepted.result, 'far');\n if (typeof far !== 'string' || !Library.#lobeText.test(far))\n return this.error('refused', 'the mouth named no far organism');\n this.cells.set(['far', far], { placeholder });\n this.cells.set(['source', far], 'far');\n yield* this.#untold(far);\n if (tells === true) yield* this.#tellsBack(far, placeholder);\n else yield* this.#asksTold(far, placeholder);\n return { far };\n }\n\n *#accepted(args ) {\n const answer = yield { placeholder: 'mouth', method: 'accept', args };\n return answer;\n }\n\n *#tellsBack(far , placeholder ) {\n const invited = yield {\n placeholder: 'ear',\n method: 'invite',\n args: { waits: null, lives: null, note: { library: far } },\n };\n const tells = 'result' in invited ? Library.field(invited.result, 'invitation') : undefined;\n const back = 'result' in invited ? Library.field(invited.result, 'far') : undefined;\n if (typeof tells !== 'string') return;\n const asked = yield { placeholder, method: 'told', args: { tells } };\n if ('error' in asked) {\n if (typeof back === 'string') yield { placeholder: 'ear', method: 'drop', args: { far: back } };\n return;\n }\n this.#heardAll(far, asked.result);\n }\n\n *#asksTold(far , placeholder ) {\n const asked = yield { placeholder, method: 'told', args: {} };\n if ('result' in asked) this.#heardAll(far, asked.result);\n }\n\n #heardAll(far , answered ) {\n for (const one of Array.isArray(answered) ? answered.slice(0, this.#page()) : []) {\n const told = Library.#toldFar(one);\n if (told !== null) this.#heard(far, told.kind, told.label, told.version, told.digest);\n }\n }\n\n *#untold(far ) {\n let cursor = null;\n const seen = new Set ();\n const given = [];\n do {\n const page = yield {\n placeholder: 'nerves',\n method: 'relations',\n args: cursor === null ? {} : { cursor },\n };\n if ('error' in page) break;\n const relations = Library.field(page.result, 'relations');\n for (const one of Array.isArray(relations) ? relations : []) {\n const back = Library.field(one, 'far');\n const mine = Library.field(Library.field(one, 'note'), 'library') === far;\n if (Library.field(one, 'side') === 'occupant' && mine && typeof back === 'string') given.push(back);\n }\n const next = Library.field(page.result, 'cursor');\n cursor = typeof next === 'string' && !seen.has(next) ? next : null;\n if (cursor !== null) seen.add(cursor);\n } while (cursor !== null);\n for (const back of given) yield { placeholder: 'ear', method: 'drop', args: { far: back } };\n }\n\n #heard(far , kind , label , version , digest ) {\n const key = ['told', far, kind, label, version];\n if (this.cells.get(key) !== undefined) return;\n const telling = this.cells.get(['telling', far]) ?? { first: 0, next: 0 };\n let first = Number(Library.field(telling, 'first'));\n const next = Number(Library.field(telling, 'next'));\n for (; next - first >= this.#page(); first += 1) {\n const oldest = this.cells.get(['telling', far, first]);\n if (Array.isArray(oldest)) this.cells.delete(oldest);\n this.cells.delete(['telling', far, first]);\n }\n this.cells.set(['telling', far, next], key);\n this.cells.set(['telling', far], { first, next: next + 1 });\n this.cells.set(key, { digest, at: this.stamp.time });\n }\n\n static #isDigest(text ) {\n return typeof text === 'string' && /^[0-9a-f]{64}$/.test(text);\n }\n\n static #toldFar(one ) {\n const [kind, label, version, digest] = ['kind', 'label', 'version', 'digest'].map((name) =>\n Library.field(one, name),\n );\n if (kind !== 'faculty' && kind !== 'organ') return null;\n if (typeof label !== 'string' || label.length > 64 || !Library.#namedText.test(label)) return null;\n if (typeof version !== 'string' || !Library.#versionText.test(version)) return null;\n return Library.#isDigest(digest) ? { kind, label, version, digest } : null;\n }\n\n *#addFar(asked \n \n \n \n \n \n ) {\n const { road, kind, named, version, second } = asked;\n const placeholder = Library.field(this.cells.get(['far', road]), 'placeholder');\n if (this.#toldRowOf(road, kind, named, version) === undefined && typeof placeholder === 'string')\n yield* this.#asksTold(road, placeholder);\n const toldAt = this.#toldAt(road, kind, named, version);\n if (typeof toldAt === 'string') return this.error('refused', toldAt);\n const got = yield {\n placeholder: toldAt.placeholder,\n method: 'get',\n args: { kind, label: named, version },\n };\n if ('error' in got)\n return this.error('refused', `the far source ${road} answers ${got.error.code}: ${got.error.message}`);\n const at = { lobe: toldAt.placeholder, label: named, version, ...(second ? { second: road } : {}) };\n return yield* this.#takeFar(got.result, toldAt.told, { road, kind, named, version }, at);\n }\n\n #toldRowOf(road , kind , named , version ) {\n return Library.#toldRow(this.cells.get(['told', road, kind, named, version]));\n }\n\n #toldAt(road , kind , named , version ) {\n const told = this.#toldRowOf(road, kind, named, version);\n const placeholder = Library.field(this.cells.get(['far', road]), 'placeholder');\n if (told === undefined || typeof placeholder !== 'string')\n return `the far source ${road} told no ${kind} ${named} ${version}`;\n return { told, placeholder };\n }\n\n *#takeFar(\n answered ,\n told ,\n at \n \n \n \n \n ,\n asked ,\n ) {\n const { road, kind, named, version } = at;\n const from = `${road}@${version}`;\n const [source, graph] = ['source', 'blueprint'].map((one) => Library.field(answered, one));\n const matches = (code , name ) =>\n typeof code === 'string' && Library.digestOf(this.crypto, code) === Library.field(told, name);\n if (kind === 'faculty')\n return matches(source, 'digest')\n ? yield* this.#takeFaculty(\n { ...Library.#only(answered, 'assets'), source, digest: Library.field(told, 'digest') ?? null },\n from,\n asked,\n )\n : this.error('refused', `the source the far source ${road} answered is not the digest it told`);\n if (!matches(graph, 'digest'))\n return this.error('refused', `the organ the far source ${road} answered is not the digests it told`);\n return this.#takeOrgan({ blueprint: graph, half: null }, named, version, from);\n }\n\n static #only(answered , name ) {\n const found = Library.field(answered, name);\n return found === undefined ? {} : { [name]: found };\n }\n\n *changed(args ) {\n const [kind, label, version, digest] = ['kind', 'label', 'version', 'digest'].map((one) =>\n Library.field(args, one),\n );\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n if (\n (kind !== 'faculty' && kind !== 'organ') ||\n keys !== 4 ||\n typeof label !== 'string' ||\n !Library.#namedText.test(label) ||\n typeof version !== 'string' ||\n !Library.#versionText.test(version) ||\n !Library.#isDigest(digest)\n )\n return this.error('refused', `changed takes a kind, a label, a version and a digest, not ${Library.#sent(args)}`);\n const { asker, occupant } = this.stamp;\n if (occupant !== null && occupant.far === asker) {\n const road = Library.field(occupant.note, 'library');\n if (typeof road !== 'string' || this.cells.get(['far', road]) === undefined)\n return this.error('refused', 'changed comes over an occupant the library gave a far source');\n this.#heard(road, kind, label, version, digest);\n return null;\n }\n if (!Library.#lobeText.test(asker)) return this.error('refused', \"changed is a source's word\");\n const unreached = yield* this.#reach(asker);\n if (unreached !== null) return this.error('refused', unreached);\n this.#heard(asker, kind, label, version, digest);\n return null;\n }\n\n static #unbase64(text ) {\n if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(text)) return null;\n const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n const bytes = [];\n let [word, bits] = [0, 0];\n for (const char of text.replaceAll('=', '')) {\n word = (word << 6) | alphabet.indexOf(char);\n bits += 6;\n if (bits >= 8) {\n bits -= 8;\n bytes.push((word >> bits) & 0xff);\n word &= (1 << bits) - 1;\n }\n }\n return new Uint8Array(bytes);\n }\n\n static #givenAssets(\n crypto ,\n items ,\n ) {\n let source ;\n const bytes = new Map ();\n const assets = [];\n for (const item of items) {\n const sourceText = Library.field(item, 'source');\n if (typeof sourceText === 'string') {\n if (source !== undefined) return 'a faculty given holds one source';\n source = sourceText;\n continue;\n }\n const [path, digest, text, base64] = ['path', 'digest', 'text', 'base64'].map((one) => Library.field(item, one));\n const held =\n typeof text === 'string' ? Library.#utf8(text) : typeof base64 === 'string' ? Library.#unbase64(base64) : null;\n if (typeof path !== 'string' || path === '' || typeof digest !== 'string' || held === null)\n return 'a faculty given holds an asset that is none';\n if (Library.digestOf(crypto, held) !== digest) return `the asset ${path} is not its digest, ${digest}`;\n if (assets.some(([seen]) => seen === path)) return `the asset ${path} is given twice`;\n assets.push([path, digest]);\n bytes.set(digest, held);\n }\n return source === undefined ? 'a faculty given holds its source' : { source, bytes, assets };\n }\n\n *#addGiven(args ) {\n const given = Library.field(args, 'given');\n const [place, digest, items] = ['place', 'digest', 'items'].map((one) => Library.field(given, one));\n if (typeof place !== 'string' || typeof digest !== 'string')\n return this.error('refused', 'a faculty given names its place and its digest');\n const kind = this.cells.get(['source', place]);\n if (kind !== undefined && kind !== 'far')\n return this.error('refused', `the place ${place} is a source of the owners' own, which offers no faculty`);\n if (!Array.isArray(items)) return this.error('refused', 'a faculty given holds its items');\n const taken = Library.#givenAssets(this.crypto, items);\n if (typeof taken === 'string') return this.error('refused', taken);\n const { source, bytes, assets } = taken;\n if (Library.digestOf(this.crypto, source) !== digest)\n return this.error('refused', `the faculty given is not its digest, ${digest}`);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const version = Library.field(blueprint, 'version');\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return this.error('refused', `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`);\n const road = `${place}@${version}`;\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const named = Library.field(blueprint, 'assets');\n if (!(named === undefined && assets.length === 0) && Library.assetsDigest(this.crypto, assets) !== named)\n return this.error('refused', \"the assets given are not the digest the faculty's blueprint names\");\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n const refused = Library.keep(\n this.cells,\n digest,\n { source, blueprint, road, ...(named === undefined ? {} : { assets: sorted }) },\n bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n *#addHand(args ) {\n const [source, assets, second] = ['source', 'assets', 'second'].map((one) => Library.field(args, one));\n if (typeof source !== 'string' || source === '') return this.error('refused', \"an owner's hand carries a source\");\n if (assets !== undefined && (!Array.isArray(assets) || assets.length > this.#page()))\n return this.error(\n 'refused',\n `assets carried are a list, of as many as a faculty holds, not ${Library.#sent(assets)}`,\n );\n if (second !== undefined && typeof second !== 'boolean')\n return this.error('refused', `\\`second\\` is an owner's word, true or false, not ${Library.#sent(second)}`);\n const taken = Library.#givenAssets(this.crypto, [{ source }, ...(assets ?? [])]);\n if (typeof taken === 'string') return this.error('refused', taken);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const version = Library.field(blueprint, 'version');\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return this.error('refused', `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`);\n const road = `${Library.#handRoad}@${version}`;\n const digest = Library.digestOf(this.crypto, source);\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const named = Library.field(blueprint, 'assets');\n if (named !== undefined && Library.assetsDigest(this.crypto, taken.assets) !== named)\n return this.error('refused', \"the assets carried are not the digest the faculty's blueprint names\");\n const refused = Library.keep(\n this.cells,\n digest,\n {\n source,\n blueprint,\n road,\n ...(named === undefined && taken.assets.length === 0\n ? {}\n : { assets: taken.assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1)) }),\n ...(second === true ? { second: Library.#handRoad } : {}),\n },\n taken.bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n *remove(args ) {\n if (this.stamp.asker !== 'brain')\n return this.error('unavailable', \"the library removes a faculty on the brain's ask alone\");\n const digest = Library.#digestIn(args);\n if (digest === undefined) return this.error('refused', 'remove takes a digest');\n const record = this.cells.get(['faculty', digest]) ?? this.#organAt(digest);\n const blueprint = Library.field(record, 'blueprint');\n const name = Library.field(blueprint, 'name');\n const half = this.cells.get(['half', digest]) !== undefined;\n if (typeof name !== 'string' && !half) return this.error('refused', `the library keeps nothing under ${digest}`);\n const uses = yield {\n placeholder: 'brain',\n method: 'uses',\n args: { digest },\n };\n if ('error' in uses) return this.error(uses.error.code, uses.error.message);\n if (uses.result !== false) return this.error('used', `a lobe or an organ stands on ${digest}`);\n if (typeof name !== 'string') this.cells.delete(['half', digest]);\n else {\n this.cells.delete(['faculty', digest]);\n this.cells.delete(['organ', digest]);\n const held = this.#assetsOf(Library.field(record, 'assets')) ?? [];\n const named = held.length === 0 ? new Set () : this.#assetsNamed();\n for (const [, sha] of held) if (!named.has(sha)) this.cells.delete(['asset', sha]);\n this.cells.delete(['name', name, digest]);\n this.cells.delete(['spared', digest]);\n }\n return null;\n }\n\n spare(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library spares a version on an owner's ask through the brain alone\");\n const digest = Library.#digestIn(args);\n const spared = Library.field(args, 'spared') ?? true;\n if (digest === undefined || typeof spared !== 'boolean')\n return this.error('refused', 'spare takes a digest, and `spared` where it gives one back');\n if (!this.#keeps(digest)) return this.error('refused', `the library keeps nothing under ${digest}`);\n if (spared) this.cells.set(['spared', digest], true);\n else this.cells.delete(['spared', digest]);\n return null;\n }\n\n #keeps(digest ) {\n return this.cells.get(['faculty', digest]) !== undefined || this.cells.get(['organ', digest]) !== undefined;\n }\n\n static proven(record ) {\n const road = Library.field(record, 'road');\n const taken = typeof road === 'string' && /^(?:hand|[A-Z][A-Z0-9]*)@/u.test(road);\n const assets = Library.field(record, 'assets');\n return (\n !taken || (Array.isArray(assets) && assets.some((one) => Array.isArray(one) && one[0] === Library.#evidence))\n );\n }\n\n #evidenceOf(record ) {\n const carried = this.#assetsOf(Library.field(record, 'assets')) ?? [];\n return carried.find(([path]) => path === Library.#evidence)?.[1] ?? null;\n }\n\n evidence(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'evidence is kept from a far asker');\n const digest = Library.field(args, 'faculty');\n const record = Library.#isDigest(digest) ? this.cells.get(['faculty', digest]) : undefined;\n if (record === undefined) return this.error('refused', 'evidence takes the digest of a faculty the library keeps');\n return { evidence: this.#evidenceOf(record) };\n }\n\n old() {\n if (this.stamp.asker !== Library.#owner)\n return this.error('unavailable', 'the library names its old versions to the brain alone');\n return { digests: this.#olderIn() };\n }\n\n #olderIn() {\n const newest = new Map ();\n const older = [];\n let cursor = null;\n do {\n const page = this.cells.range({\n prefix: ['version'],\n limit: this.#page(),\n ...(cursor === null ? {} : { cursor }),\n });\n for (const { key, value } of page.cells) {\n const at = Library.#semver(key[2]);\n if (typeof value !== 'string' || at === null || !this.#keeps(value)) continue;\n const name = String(key[1]);\n const top = newest.get(name);\n if (top === undefined) newest.set(name, { at, digest: value });\n else if (Library.#newer(at, top.at)) {\n older.push(top.digest);\n newest.set(name, { at, digest: value });\n } else older.push(value);\n }\n cursor = page.cursor;\n } while (cursor !== null);\n return older.filter((digest) => this.cells.get(['spared', digest]) === undefined);\n }\n\n static #semver(version ) {\n if (typeof version !== 'string' || !Library.#versionText.test(version)) return null;\n return version.split('.').map(Number);\n }\n\n static #newer(one , other ) {\n for (let at = 0; at < 3; at += 1) if ((one[at] ?? 0) !== (other[at] ?? 0)) return (one[at] ?? 0) > (other[at] ?? 0);\n return false;\n }\n\n get(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'get is kept from a far asker');\n const digest = Library.#digestIn(args);\n if (digest === undefined) return this.error('refused', 'get takes a digest');\n return (\n this.cells.get(['faculty', digest]) ??\n this.#organAt(digest) ??\n this.#assetAt(digest) ??\n this.cells.get(['half', digest]) ??\n null\n );\n }\n\n #assetAt(digest ) {\n const kept = this.cells.get(['asset', digest]);\n return kept instanceof Uint8Array ? { digest, bytes: kept } : undefined;\n }\n\n list(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'list is kept from a far asker');\n const cursor = Library.field(args, 'cursor') ?? null;\n const most = this.#page();\n const limit = Library.field(args, 'limit') ?? most;\n const told = Library.field(args, 'told') ?? false;\n if (cursor !== null && typeof cursor !== 'string')\n return this.error('refused', `a cursor is a text, or null, not ${Library.#sent(cursor)}`);\n if (typeof limit !== 'number' || !Number.isInteger(limit) || limit < 1 || limit > most)\n return this.error('refused', `a limit is a whole number from 1 to ${most}, not ${Library.#sent(limit)}`);\n if (typeof told !== 'boolean') return this.error('refused', `told is true or false, not ${Library.#sent(told)}`);\n const page = this.cells.range({\n prefix: [told ? 'told' : 'name'],\n limit,\n ...(cursor === null ? {} : { cursor }),\n });\n if (told) return { told: page.cells.map((cell) => this.#told(cell)), cursor: page.cursor };\n const faculties = page.cells.map(({ key, value }) => {\n const digest = String(key[2]);\n const organ = this.#organAt(digest);\n const record = organ ?? this.cells.get(['faculty', digest]);\n const road = Library.field(record, 'road');\n return {\n name: String(key[1]),\n digest,\n ...(typeof value === 'string' ? { label: value } : {}),\n ...(typeof road === 'string' ? { road } : {}),\n ...(organ === undefined ? {} : { kind: 'organ' }),\n ...(this.cells.get(['spared', digest]) === undefined ? {} : { spared: true }),\n ...(organ === undefined && !Library.proven(record) ? { unproven: true } : {}),\n };\n });\n return { faculties, cursor: page.cursor };\n }\n\n #organAt(digest ) {\n const row = this.cells.get(['organ', digest]);\n if (row === undefined) return undefined;\n const record = {};\n for (const field of ['id', 'digest', 'graph', 'blueprint', 'reach', 'half', 'road']) {\n const value = Library.field(row, field);\n if (value !== undefined) record[field] = value;\n }\n return record;\n }\n\n static #toldRow(row ) {\n if (row === undefined) return undefined;\n const [digest, at] = ['digest', 'at'].map((one) => Library.field(row, one));\n return {\n ...(digest === undefined ? {} : { digest }),\n ...(at === undefined ? {} : { at }),\n };\n }\n\n #told({ key, value } ) {\n const row = Library.#toldRow(value) ?? {};\n const { at } = row;\n const { digest } = row;\n const kept =\n typeof digest === 'string' &&\n (this.cells.get(['faculty', digest]) !== undefined || this.cells.get(['organ', digest]) !== undefined);\n const [lobe = '', kind = '', label = '', version = ''] = key.slice(1).map(String);\n return {\n lobe,\n kind,\n label,\n version,\n digest: digest ?? null,\n at: at ?? null,\n kept,\n };\n }\n}";
|
|
5754
|
+
var LIBRARY_TEXT = "class Library extends Faculty {\n static #digest = { type: 'string', pattern: '^[0-9a-f]{64}$' };\n\n static #road = { type: 'string', minLength: 1, maxLength: 256 };\n\n static #assets = {\n type: 'array',\n items: { type: 'array', items: { type: 'string', minLength: 1 }, minItems: 2, maxItems: 2 },\n };\n\n static #faculty = {\n type: 'object',\n properties: {\n source: { type: 'string', minLength: 1 },\n digest: Library.#digest,\n blueprint: { type: 'object' },\n road: Library.#road,\n label: { type: 'string', minLength: 1, maxLength: 64 },\n assets: Library.#assets,\n },\n required: ['source', 'digest', 'blueprint', 'road'],\n additionalProperties: false,\n };\n\n static #organ = {\n type: 'object',\n properties: {\n id: { type: 'string', minLength: 1, maxLength: 64 },\n digest: Library.#digest,\n graph: { type: 'string', minLength: 1 },\n blueprint: { type: 'object' },\n reach: {},\n half: { anyOf: [Library.#digest, { type: 'null' }] },\n road: Library.#road,\n },\n required: ['id', 'digest', 'graph', 'blueprint', 'half', 'road'],\n additionalProperties: false,\n };\n\n static #asset = {\n type: 'object',\n properties: { digest: Library.#digest, bytes: { type: 'string', contentEncoding: 'base16' } },\n required: ['digest', 'bytes'],\n additionalProperties: false,\n };\n\n static #lobe = { type: 'string', pattern: '^[A-Z][A-Z0-9]*$', maxLength: 64 };\n\n static #given = {\n type: 'object',\n properties: {\n kind: { const: 'faculty' },\n given: {\n type: 'object',\n properties: {\n place: Library.#lobe,\n digest: Library.#digest,\n items: { type: 'array', items: { type: 'object' }, maxItems: 1001 },\n },\n required: ['place', 'digest', 'items'],\n additionalProperties: false,\n },\n },\n required: ['kind', 'given'],\n additionalProperties: false,\n };\n\n static #hand = {\n type: 'object',\n properties: {\n source: { type: 'string', minLength: 1 },\n assets: { type: 'array', items: { type: 'object' } },\n second: { type: 'boolean' },\n },\n required: ['source'],\n additionalProperties: false,\n };\n\n static #version = {\n type: 'string',\n pattern: '^(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)\\\\.(0|[1-9][0-9]*)$',\n };\n\n static #named = {\n type: 'string',\n pattern: '^[a-z][a-z0-9]*([.-][a-z0-9]+)*$',\n maxLength: 64,\n };\n\n static #half = {\n type: 'object',\n properties: {\n form: { enum: ['component', 'native'] },\n code: {\n anyOf: [\n { type: 'string', minLength: 1 },\n { type: 'string', contentEncoding: 'base16' },\n ],\n },\n },\n required: ['form', 'code'],\n additionalProperties: false,\n };\n\n static blueprint = {\n name: 'nervur.library',\n version: '0.37.6',\n description:\n \"The library: it keeps the organism's faculties with their assets, and its organs, as data, each version by its digest, and the versions its sources told it.\",\n methods: {\n add: {\n description:\n \"On an owner's ask through the brain alone. From a source, `road`, any lobe of the organism's own whose describe names `get` and `told`: a faculty by its label or an organ by its ID, at a version, read from it over a wire the library orders, its digest checked and its blueprint's version, and kept under the road `<lobe>@<version>`, with that lobe kept as a source of the owners' own where its `state` answers a name, once; a faculty whose blueprint names `assets` has each asset read whole by its path and checked against its SHA-256, and their canonical digest against the blueprint's, or none of it is kept. From a far source, `road`, the library holds a standing on: a faculty or an organ at a version it told, read over the standing, each digest checked against what it told, an organ by its graph.json alone, never its host half, a faculty's assets as from near. Or by an owner's hand, `source`: a faculty's text carried in the ask, with its `assets` where it has any, kept under the road `hand@<version>` by the same walls. Or a host half's form and code under the digest of its code. A code the library keeps already, added from another road, takes that road, all else as it stands; boot's laying changes no road. Answers the digest; refuses a code whose blueprint's name and version the library keeps under another digest, but with `second`, an owner's word on a faculty, which takes it as a name of its own, kept by its source.\",\n kind: 'writing',\n args: {\n anyOf: [\n {\n type: 'object',\n properties: {\n road: Library.#lobe,\n kind: { const: 'faculty' },\n label: Library.#named,\n version: Library.#version,\n second: { type: 'boolean' },\n },\n required: ['road', 'kind', 'label', 'version'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n road: Library.#lobe,\n kind: { const: 'organ' },\n id: Library.#named,\n version: Library.#version,\n },\n required: ['road', 'kind', 'id', 'version'],\n additionalProperties: false,\n },\n Library.#given,\n Library.#hand,\n ],\n },\n result: {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n accept: {\n description:\n \"On an owner's ask through the brain alone: accepts a far source's invitation to a library's standing through the mouth, holding the relation itself on a placeholder of its own. It asks the far lobe at once what it told, `told`, and again at an add of a version not told it yet, since an organism that cannot be dialed can be told nothing. One that can names `tells`: since a relation runs one way, it draws through the ear a standing back on itself for the far lobe, the one before for that far lobe ended, and hands it as `told { tells }`, over which the far lobe tells each version it tells after, `changed`. With `note`, the owner's, which the brain keeps beside the standing, null where none is named. Answers the far organism the brain made up for it, the road an add names it by.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: { invitation: { type: 'string', minLength: 1 }, note: {}, tells: { const: true } },\n required: ['invitation'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { far: Library.#lobe },\n required: ['far'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n changed: {\n description:\n \"A source's word that its `main` holds a faculty or an organ at a version it never told: a near one's over its wire, a far one's over the occupant the library's `accept` gave it, by an ask; kept for the owners to see, by `list` with `told`, never added.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: {\n kind: { enum: ['faculty', 'organ'] },\n label: Library.#named,\n version: Library.#version,\n digest: Library.#digest,\n },\n required: ['kind', 'label', 'version', 'digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n remove: {\n irreversible: true,\n description:\n \"Deletes a version no lobe stands on with its assets no other kept faculty names, an organ's record, or a host half's code no organ names, on the brain's ask alone.\",\n kind: 'writing',\n args: Library.#byDigest(),\n errors: ['refused', 'used'],\n },\n spare: {\n description:\n \"On an owner's ask through the brain alone: keeps a version the library holds from the sweep, or, with `spared: false`, gives it back. An owner may still remove it.\",\n kind: 'writing',\n args: {\n type: 'object',\n properties: { digest: Library.#digest, spared: { type: 'boolean' } },\n required: ['digest'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n evidence: {\n description:\n \"The asset that carries a kept faculty's evidence, `evidence.json`, by its SHA-256, which `get` answers, or null where it carries none; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { faculty: Library.#digest },\n required: ['faculty'],\n additionalProperties: false,\n },\n result: {\n type: 'object',\n properties: { evidence: { anyOf: [Library.#digest, { type: 'null' }] } },\n required: ['evidence'],\n additionalProperties: false,\n },\n errors: ['refused'],\n },\n get: {\n description:\n \"The version of a digest with its assets, an organ's record, an asset's bytes, or a host half's form and code, or null; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n },\n result: {\n anyOf: [Library.#faculty, Library.#organ, Library.#asset, Library.#half, { type: 'null' }],\n },\n errors: ['refused'],\n },\n old: {\n description:\n \"The old versions the library keeps, on the brain's ask alone: of each name, a faculty's or an organ's blueprint name, every version but the newest by semver; the brain removes each no lobe stands on.\",\n kind: 'reading',\n args: { type: 'object', additionalProperties: false },\n result: { type: 'object', properties: { digests: { type: 'array', items: { type: 'string' } } } },\n },\n list: {\n description:\n \"The versions kept, by their blueprint's name, each with its road, an organ's marked, one an owner spared marked `spared`, a faculty a source or an owner's hand brought with no evidence marked `unproven`, a page at a time; with `told`, the versions the sources told, each with whether the library keeps it; refused to a far asker.\",\n kind: 'reading',\n args: {\n type: 'object',\n properties: {\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n limit: { type: 'integer', minimum: 1 },\n told: { type: 'boolean' },\n },\n additionalProperties: false,\n },\n result: {\n anyOf: [\n {\n type: 'object',\n properties: {\n faculties: { type: 'array', items: { type: 'object' } },\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n },\n required: ['faculties', 'cursor'],\n additionalProperties: false,\n },\n {\n type: 'object',\n properties: {\n told: { type: 'array', items: { type: 'object' } },\n cursor: { anyOf: [{ type: 'string' }, { type: 'null' }] },\n },\n required: ['told', 'cursor'],\n additionalProperties: false,\n },\n ],\n },\n errors: ['refused'],\n },\n },\n placeholders: { brain: 'nervur.brain', mouth: 'nervur.mouth', ear: 'nervur.ear' },\n };\n\n static #owner = 'brain';\n\n static #contract = ['get', 'told'];\n\n static #evidence = 'evidence.json';\n\n static #handRoad = 'hand';\n\n static #versionText = /^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$/;\n static #namedText = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;\n static #lobeText = /^[A-Z][A-Z0-9]*$/;\n\n static #sent(value ) {\n if (value === undefined) return 'nothing';\n const read = JSON.stringify(value);\n return read.length > 64 ? `${read.slice(0, 63)}\u2026` : read;\n }\n\n #page() {\n return Math.min(1000, Math.floor(this.memory / 4 / 1024));\n }\n\n static #byDigest() {\n return {\n type: 'object',\n properties: { digest: Library.#digest },\n required: ['digest'],\n additionalProperties: false,\n };\n }\n\n static #digestIn(args ) {\n const digest = Library.field(args, 'digest');\n return typeof digest === 'string' && /^[0-9a-f]{64}$/.test(digest) ? digest : undefined;\n }\n\n static #utf8(text ) {\n const bytes = [];\n for (const char of text) {\n const point = char.codePointAt(0) ?? 0;\n if (point < 0x80) bytes.push(point);\n else if (point < 0x800) bytes.push(0xc0 | (point >> 6), 0x80 | (point & 0x3f));\n else if (point < 0x10000) bytes.push(0xe0 | (point >> 12), 0x80 | ((point >> 6) & 0x3f), 0x80 | (point & 0x3f));\n else\n bytes.push(\n 0xf0 | (point >> 18),\n 0x80 | ((point >> 12) & 0x3f),\n 0x80 | ((point >> 6) & 0x3f),\n 0x80 | (point & 0x3f),\n );\n }\n return new Uint8Array(bytes);\n }\n\n static digestOf(crypto , code ) {\n return Library.hex(crypto.sha256(typeof code === 'string' ? Library.#utf8(code) : code));\n }\n\n static assetsDigest(\n crypto ,\n assets ,\n ) {\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n return Library.digestOf(crypto, JSON.stringify(sorted));\n }\n\n static keep(\n cells ,\n digest ,\n kept ,\n bytes = new Map(),\n ) {\n if (!('source' in kept)) {\n if (cells.get(['half', digest]) === undefined) cells.set(['half', digest], { form: kept.form, code: kept.code });\n return null;\n }\n const { source, blueprint, road, label, assets, second } = kept;\n const name = Library.field(blueprint, 'name');\n if (typeof name !== 'string') throw new TypeError('a version kept is one whose blueprint is named');\n if (cells.get(['faculty', digest]) !== undefined) return null;\n const named = Library.field(blueprint, 'assets') !== undefined;\n if (named !== (assets !== undefined))\n return named\n ? `the blueprint of ${name} names assets the faculty carries not`\n : `${name} carries assets its blueprint names not`;\n for (const [, sha] of assets ?? [])\n if (!bytes.has(sha) && cells.get(['asset', sha]) === undefined)\n return `${name} has no bytes for its asset ${sha}`;\n const indexed = Library.#indexed(cells, name, Library.field(blueprint, 'version'), digest, second);\n if (typeof indexed === 'string') return indexed;\n for (const [, sha] of assets ?? []) {\n const held = bytes.get(sha);\n if (held !== undefined && cells.get(['asset', sha]) === undefined) cells.set(['asset', sha], held);\n }\n cells.set(['faculty', digest], {\n source,\n digest,\n blueprint,\n road,\n ...(label === undefined ? {} : { label }),\n ...(assets === undefined ? {} : { assets: assets.map(([path, sha]) => [path, sha]) }),\n ...(indexed.second === undefined ? {} : { second: indexed.second }),\n });\n cells.set(['name', name, digest], label ?? null);\n return null;\n }\n\n static #indexed(\n cells ,\n name ,\n version ,\n digest ,\n second ,\n ) {\n if (typeof version !== 'string') return `the blueprint of ${name} names no version`;\n const named = cells.get(['version', name, version]);\n if (typeof named !== 'string' || named === digest) {\n cells.set(['version', name, version], digest);\n return {};\n }\n if (second === undefined) return `the library keeps ${name} ${version} under another digest, ${named}`;\n const own = cells.get(['second', name, version, second]);\n if (typeof own === 'string' && own !== digest)\n return `the library keeps ${name} ${version} of ${second} under another digest, ${own}`;\n cells.set(['second', name, version, second], digest);\n return { second };\n }\n\n *add(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library adds on an owner's ask through the brain alone\");\n if (Library.field(args, 'given') !== undefined) return yield* this.#addGiven(args);\n if (Library.field(args, 'source') !== undefined) return yield* this.#addHand(args);\n return yield* this.#addFrom(args);\n }\n\n *#read(source ) {\n const answered = yield { read: source };\n const read = 'result' in answered ? answered.result : undefined;\n const blueprint = Library.field(read, 'blueprint');\n if (blueprint !== undefined && typeof Library.field(blueprint, 'name') === 'string') return blueprint;\n const why = Library.field(read, 'why');\n return `the source is no faculty: ${typeof why === 'string' ? why : 'it declares no blueprint'}`;\n }\n\n static #fromArgs(\n args ,\n ) {\n const kind = Library.field(args, 'kind');\n const key = kind === 'organ' ? 'id' : 'label';\n const [road, named, version] = ['road', key, 'version'].map((one) => Library.field(args, one));\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n const second = Library.field(args, 'second');\n if ((kind !== 'faculty' && kind !== 'organ') || keys !== (second === undefined ? 4 : 5))\n return 'add takes a road, a kind, a faculty or an organ, its label or ID, and a version';\n if (second !== undefined && ((second !== true && second !== false) || kind !== 'faculty'))\n return `\\`second\\` is an owner's word on a faculty, true or false, not ${Library.#sent(second)}`;\n if (typeof road !== 'string' || road.length > 64 || !Library.#lobeText.test(road))\n return `a road is a lobe of this organism, by the ID the brain made up for it, not ${Library.#sent(road)}`;\n if (typeof named !== 'string' || named.length > 64 || !Library.#namedText.test(named))\n return `a ${key} is a folder's name, lowercase, not ${Library.#sent(named)}`;\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`;\n return { road, kind, named, version, second: second === true };\n }\n\n *#addFrom(args ) {\n const asked = Library.#fromArgs(args);\n if (typeof asked === 'string') return this.error('refused', asked);\n if (this.cells.get(['far', asked.road]) !== undefined) return yield* this.#addFar(asked);\n const { road, kind, named, version, second } = asked;\n const unreached = yield* this.#reach(road);\n if (unreached !== null) return this.error('refused', unreached);\n const got = yield {\n placeholder: road,\n method: 'get',\n args: { kind, label: named, version },\n };\n if ('error' in got)\n return this.error('refused', `the source ${road} answers ${got.error.code}: ${got.error.message}`);\n const from = `${road}@${version}`;\n const taken =\n kind === 'organ'\n ? this.#takeOrgan(got.result, named, version, from)\n : yield* this.#takeFaculty(got.result, from, {\n lobe: road,\n label: named,\n version,\n ...(second ? { second: road } : {}),\n });\n if (Library.#added(taken)) yield* this.#kindOf(road);\n return taken;\n }\n\n static #added(taken ) {\n return typeof taken === 'object' && taken !== null && 'digest' in taken;\n }\n\n *#kindOf(lobe ) {\n if (this.cells.get(['source', lobe]) !== undefined) return;\n const state = yield {\n placeholder: lobe,\n method: 'state',\n args: {},\n };\n const name = 'result' in state ? Library.field(state.result, 'name') : undefined;\n if (typeof name === 'string' && name !== '') this.cells.set(['source', lobe], 'owners');\n }\n\n *#reach(lobe ) {\n const order = { termination: lobe };\n const ordered = yield {\n placeholder: 'nerves',\n method: 'order',\n args: { order },\n };\n if ('error' in ordered) return `the library reaches no ${lobe}: ${ordered.error.message}`;\n const described = yield {\n placeholder: lobe,\n method: null,\n args: null,\n };\n const methods = 'result' in described ? Library.field(described.result, 'methods') : undefined;\n const lacking = Library.#contract.filter((method) => Library.field(methods, method) === undefined);\n if (lacking.length === 0) return null;\n yield {\n placeholder: 'nerves',\n method: 'unwire',\n args: { placeholder: lobe },\n };\n return `${lobe} is no source: its describe names no ${lacking.join(' and no ')}`;\n }\n\n *#takeFaculty(answered , road , at ) {\n const { label, version } = at;\n const source = Library.field(answered, 'source');\n const told = Library.field(answered, 'digest');\n if (typeof source !== 'string' || source === '') return this.error('refused', 'the source answered no source');\n const digest = Library.digestOf(this.crypto, source);\n if (told !== digest)\n return this.error('refused', `the source the source answered is not its digest, ${JSON.stringify(told ?? null)}`);\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const named = Library.field(blueprint, 'version');\n if (named !== version)\n return this.error('refused', `the faculty names version ${JSON.stringify(named ?? null)}, not ${version}`);\n const carried = yield* this.#assetsTaken(answered, blueprint, at);\n if (typeof carried === 'string') return this.error('refused', carried);\n const refused = Library.keep(\n this.cells,\n digest,\n { source, blueprint, road, label, ...carried.kept, ...(at.second === undefined ? {} : { second: at.second }) },\n carried.bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n #reroad(digest , road , version ) {\n const kept = this.cells.get(['faculty', digest]);\n const named = Library.field(Library.field(kept, 'blueprint'), 'version');\n if (named !== version)\n return this.error('refused', `the faculty names version ${JSON.stringify(named ?? null)}, not ${version}`);\n if (Library.field(kept, 'road') === road) return { digest };\n const record = {};\n for (const field of ['source', 'digest', 'blueprint', 'label', 'assets', 'second']) {\n const value = Library.field(kept, field);\n if (value !== undefined) record[field] = value;\n }\n this.cells.set(['faculty', digest], { ...record, road });\n return { digest };\n }\n\n *#assetsTaken(\n answered ,\n blueprint ,\n at ,\n ) \n \n \n \n {\n const bytes = new Map ();\n const named = Library.field(blueprint, 'assets');\n const told = Library.field(answered, 'assets');\n if (named === undefined)\n return told === undefined ? { kept: {}, bytes } : 'the source answered assets the blueprint names not';\n const assets = this.#assetsOf(told);\n if (assets === null) return 'the source answered no assets whole: each a path and a SHA-256, one path once';\n if (Library.assetsDigest(this.crypto, assets) !== named)\n return `the assets are not the digest the blueprint names, ${JSON.stringify(named)}`;\n for (const [path, sha] of assets) {\n if (bytes.has(sha) || this.cells.get(['asset', sha]) !== undefined) continue;\n const got = yield {\n placeholder: at.lobe,\n method: 'get',\n args: { kind: 'faculty', label: at.label, version: at.version, path },\n };\n if ('error' in got)\n return `the source ${at.lobe} answers ${got.error.code} for the asset ${path}: ${got.error.message}`;\n const [given, digest, held] = ['path', 'digest', 'bytes'].map((one) => Library.field(got.result, one));\n if (given !== path || digest !== sha || !(held instanceof Uint8Array))\n return `the source answered another asset than ${path}`;\n if (Library.digestOf(this.crypto, held) !== sha) return `the asset ${path} is not its digest, ${sha}`;\n bytes.set(sha, held);\n }\n return { kept: { assets }, bytes };\n }\n\n static #json(text ) {\n try {\n const read = JSON.parse(text);\n return typeof read === 'object' && read !== null && !Array.isArray(read) ? read : null;\n } catch {\n return null;\n }\n }\n\n #takeOrgan(answered , id , version , road ) {\n const graph = Library.field(answered, 'blueprint');\n const half = Library.field(answered, 'half') ?? null;\n if (typeof graph !== 'string') return this.error('refused', \"the source answered no organ's graph.json\");\n if (half !== null && (typeof half !== 'string' || !/^[0-9a-f]{64}$/.test(half)))\n return this.error('refused', 'the source answered a built half that is no digest');\n const read = Library.#json(graph);\n const inner = Library.field(read, 'blueprint');\n const blueprint = inner !== undefined && Library.#json(JSON.stringify(inner)) !== null ? inner : read;\n const name = Library.field(blueprint, 'name');\n const named = Library.field(blueprint, 'version');\n if (blueprint === null || blueprint === undefined || typeof name !== 'string')\n return this.error('refused', 'its graph.json holds no blueprint, named');\n if (named !== version)\n return this.error('refused', `the organ names version ${JSON.stringify(named ?? null)}, not ${version}`);\n const digest = Library.digestOf(this.crypto, graph);\n const kept = this.#organAt(digest);\n if (kept !== undefined) {\n if (half !== null || kept['road'] !== road)\n this.cells.set(['organ', digest], { ...kept, ...(half === null ? {} : { half }), road });\n return { digest };\n }\n const clash = Library.#indexed(this.cells, name, named, digest, undefined);\n if (typeof clash === 'string') return this.error('refused', clash);\n const reach = inner === undefined ? undefined : Library.field(read, 'reach');\n this.cells.set(['organ', digest], {\n id,\n digest,\n graph,\n blueprint,\n ...(reach === undefined ? {} : { reach }),\n half,\n road,\n });\n this.cells.set(['name', name, digest], id);\n return { digest };\n }\n\n #assetsOf(data ) {\n if (!Array.isArray(data) || data.length > this.#page()) return null;\n const assets = [];\n for (const one of data) {\n const [path, sha] = Array.isArray(one) && one.length === 2 ? one : [];\n if (typeof path !== 'string' || path === '') return null;\n if (typeof sha !== 'string' || !/^[0-9a-f]{64}$/.test(sha)) return null;\n assets.push([path, sha]);\n }\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n return sorted.every((one, at) => sorted[at - 1]?.[0] !== one[0]) ? sorted : null;\n }\n\n #assetsNamed() {\n const named = new Set ();\n let cursor = null;\n do {\n const page = this.cells.range({\n prefix: ['faculty'],\n limit: this.#page(),\n ...(cursor === null ? {} : { cursor }),\n });\n for (const { value } of page.cells)\n for (const [, sha] of this.#assetsOf(Library.field(value, 'assets')) ?? []) named.add(sha);\n cursor = page.cursor;\n } while (cursor !== null);\n return named;\n }\n\n *accept(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library accepts a standing on an owner's ask through the brain alone\");\n const invitation = Library.field(args, 'invitation');\n const note = Library.field(args, 'note');\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n const tells = Library.field(args, 'tells');\n const named = 1 + (note === undefined ? 0 : 1) + (tells === undefined ? 0 : 1);\n if (typeof invitation !== 'string' || invitation === '' || keys !== named || (tells ?? true) !== true)\n return this.error(\n 'refused',\n 'accept takes an invitation, a note where one is named, and `tells` where it can be told',\n );\n const held = this.cells.get(['standings']);\n const count = typeof held === 'number' ? held + 1 : 1;\n this.cells.set(['standings'], count);\n const placeholder = `far-${count}`;\n const accepted = yield* this.#accepted({ invitation, placeholder, note: note ?? null });\n if ('error' in accepted) return this.error('refused', `the mouth accepts no standing: ${accepted.error.message}`);\n const far = Library.field(accepted.result, 'far');\n if (typeof far !== 'string' || !Library.#lobeText.test(far))\n return this.error('refused', 'the mouth named no far organism');\n this.cells.set(['far', far], { placeholder });\n this.cells.set(['source', far], 'far');\n yield* this.#untold(far);\n if (tells === true) yield* this.#tellsBack(far, placeholder);\n else yield* this.#asksTold(far, placeholder);\n return { far };\n }\n\n *#accepted(args ) {\n const answer = yield { placeholder: 'mouth', method: 'accept', args };\n return answer;\n }\n\n *#tellsBack(far , placeholder ) {\n const invited = yield {\n placeholder: 'ear',\n method: 'invite',\n args: { waits: null, lives: null, note: { library: far } },\n };\n const tells = 'result' in invited ? Library.field(invited.result, 'invitation') : undefined;\n const back = 'result' in invited ? Library.field(invited.result, 'far') : undefined;\n if (typeof tells !== 'string') return;\n const asked = yield { placeholder, method: 'told', args: { tells } };\n if ('error' in asked) {\n if (typeof back === 'string') yield { placeholder: 'ear', method: 'drop', args: { far: back } };\n return;\n }\n this.#heardAll(far, asked.result);\n }\n\n *#asksTold(far , placeholder ) {\n const asked = yield { placeholder, method: 'told', args: {} };\n if ('result' in asked) this.#heardAll(far, asked.result);\n }\n\n #heardAll(far , answered ) {\n for (const one of Array.isArray(answered) ? answered.slice(0, this.#page()) : []) {\n const told = Library.#toldFar(one);\n if (told !== null) this.#heard(far, told.kind, told.label, told.version, told.digest);\n }\n }\n\n *#untold(far ) {\n let cursor = null;\n const seen = new Set ();\n const given = [];\n do {\n const page = yield {\n placeholder: 'nerves',\n method: 'relations',\n args: cursor === null ? {} : { cursor },\n };\n if ('error' in page) break;\n const relations = Library.field(page.result, 'relations');\n for (const one of Array.isArray(relations) ? relations : []) {\n const back = Library.field(one, 'far');\n const mine = Library.field(Library.field(one, 'note'), 'library') === far;\n if (Library.field(one, 'side') === 'occupant' && mine && typeof back === 'string') given.push(back);\n }\n const next = Library.field(page.result, 'cursor');\n cursor = typeof next === 'string' && !seen.has(next) ? next : null;\n if (cursor !== null) seen.add(cursor);\n } while (cursor !== null);\n for (const back of given) yield { placeholder: 'ear', method: 'drop', args: { far: back } };\n }\n\n #heard(far , kind , label , version , digest ) {\n const key = ['told', far, kind, label, version];\n if (this.cells.get(key) !== undefined) return;\n const telling = this.cells.get(['telling', far]) ?? { first: 0, next: 0 };\n let first = Number(Library.field(telling, 'first'));\n const next = Number(Library.field(telling, 'next'));\n for (; next - first >= this.#page(); first += 1) {\n const oldest = this.cells.get(['telling', far, first]);\n if (Array.isArray(oldest)) this.cells.delete(oldest);\n this.cells.delete(['telling', far, first]);\n }\n this.cells.set(['telling', far, next], key);\n this.cells.set(['telling', far], { first, next: next + 1 });\n this.cells.set(key, { digest, at: this.stamp.time });\n }\n\n static #isDigest(text ) {\n return typeof text === 'string' && /^[0-9a-f]{64}$/.test(text);\n }\n\n static #toldFar(one ) {\n const [kind, label, version, digest] = ['kind', 'label', 'version', 'digest'].map((name) =>\n Library.field(one, name),\n );\n if (kind !== 'faculty' && kind !== 'organ') return null;\n if (typeof label !== 'string' || label.length > 64 || !Library.#namedText.test(label)) return null;\n if (typeof version !== 'string' || !Library.#versionText.test(version)) return null;\n return Library.#isDigest(digest) ? { kind, label, version, digest } : null;\n }\n\n *#addFar(asked \n \n \n \n \n \n ) {\n const { road, kind, named, version, second } = asked;\n const placeholder = Library.field(this.cells.get(['far', road]), 'placeholder');\n if (this.#toldRowOf(road, kind, named, version) === undefined && typeof placeholder === 'string')\n yield* this.#asksTold(road, placeholder);\n const toldAt = this.#toldAt(road, kind, named, version);\n if (typeof toldAt === 'string') return this.error('refused', toldAt);\n const got = yield {\n placeholder: toldAt.placeholder,\n method: 'get',\n args: { kind, label: named, version },\n };\n if ('error' in got)\n return this.error('refused', `the far source ${road} answers ${got.error.code}: ${got.error.message}`);\n const at = { lobe: toldAt.placeholder, label: named, version, ...(second ? { second: road } : {}) };\n return yield* this.#takeFar(got.result, toldAt.told, { road, kind, named, version }, at);\n }\n\n #toldRowOf(road , kind , named , version ) {\n return Library.#toldRow(this.cells.get(['told', road, kind, named, version]));\n }\n\n #toldAt(road , kind , named , version ) {\n const told = this.#toldRowOf(road, kind, named, version);\n const placeholder = Library.field(this.cells.get(['far', road]), 'placeholder');\n if (told === undefined || typeof placeholder !== 'string')\n return `the far source ${road} told no ${kind} ${named} ${version}`;\n return { told, placeholder };\n }\n\n *#takeFar(\n answered ,\n told ,\n at \n \n \n \n \n ,\n asked ,\n ) {\n const { road, kind, named, version } = at;\n const from = `${road}@${version}`;\n const [source, graph] = ['source', 'blueprint'].map((one) => Library.field(answered, one));\n const matches = (code , name ) =>\n typeof code === 'string' && Library.digestOf(this.crypto, code) === Library.field(told, name);\n if (kind === 'faculty')\n return matches(source, 'digest')\n ? yield* this.#takeFaculty(\n { ...Library.#only(answered, 'assets'), source, digest: Library.field(told, 'digest') ?? null },\n from,\n asked,\n )\n : this.error('refused', `the source the far source ${road} answered is not the digest it told`);\n if (!matches(graph, 'digest'))\n return this.error('refused', `the organ the far source ${road} answered is not the digests it told`);\n return this.#takeOrgan({ blueprint: graph, half: null }, named, version, from);\n }\n\n static #only(answered , name ) {\n const found = Library.field(answered, name);\n return found === undefined ? {} : { [name]: found };\n }\n\n *changed(args ) {\n const [kind, label, version, digest] = ['kind', 'label', 'version', 'digest'].map((one) =>\n Library.field(args, one),\n );\n const keys = typeof args === 'object' && args !== null ? Object.keys(args).length : 0;\n if (\n (kind !== 'faculty' && kind !== 'organ') ||\n keys !== 4 ||\n typeof label !== 'string' ||\n !Library.#namedText.test(label) ||\n typeof version !== 'string' ||\n !Library.#versionText.test(version) ||\n !Library.#isDigest(digest)\n )\n return this.error('refused', `changed takes a kind, a label, a version and a digest, not ${Library.#sent(args)}`);\n const { asker, occupant } = this.stamp;\n if (occupant !== null && occupant.far === asker) {\n const road = Library.field(occupant.note, 'library');\n if (typeof road !== 'string' || this.cells.get(['far', road]) === undefined)\n return this.error('refused', 'changed comes over an occupant the library gave a far source');\n this.#heard(road, kind, label, version, digest);\n return null;\n }\n if (!Library.#lobeText.test(asker)) return this.error('refused', \"changed is a source's word\");\n const unreached = yield* this.#reach(asker);\n if (unreached !== null) return this.error('refused', unreached);\n this.#heard(asker, kind, label, version, digest);\n return null;\n }\n\n static #unbase64(text ) {\n if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(text)) return null;\n const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n const bytes = [];\n let [word, bits] = [0, 0];\n for (const char of text.replaceAll('=', '')) {\n word = (word << 6) | alphabet.indexOf(char);\n bits += 6;\n if (bits >= 8) {\n bits -= 8;\n bytes.push((word >> bits) & 0xff);\n word &= (1 << bits) - 1;\n }\n }\n return new Uint8Array(bytes);\n }\n\n static #givenAssets(\n crypto ,\n items ,\n ) {\n let source ;\n const bytes = new Map ();\n const assets = [];\n for (const item of items) {\n const sourceText = Library.field(item, 'source');\n if (typeof sourceText === 'string') {\n if (source !== undefined) return 'a faculty given holds one source';\n source = sourceText;\n continue;\n }\n const [path, digest, text, base64] = ['path', 'digest', 'text', 'base64'].map((one) => Library.field(item, one));\n const held =\n typeof text === 'string' ? Library.#utf8(text) : typeof base64 === 'string' ? Library.#unbase64(base64) : null;\n if (typeof path !== 'string' || path === '' || typeof digest !== 'string' || held === null)\n return 'a faculty given holds an asset that is none';\n if (Library.digestOf(crypto, held) !== digest) return `the asset ${path} is not its digest, ${digest}`;\n if (assets.some(([seen]) => seen === path)) return `the asset ${path} is given twice`;\n assets.push([path, digest]);\n bytes.set(digest, held);\n }\n return source === undefined ? 'a faculty given holds its source' : { source, bytes, assets };\n }\n\n *#addGiven(args ) {\n const given = Library.field(args, 'given');\n const [place, digest, items] = ['place', 'digest', 'items'].map((one) => Library.field(given, one));\n if (typeof place !== 'string' || typeof digest !== 'string')\n return this.error('refused', 'a faculty given names its place and its digest');\n const kind = this.cells.get(['source', place]);\n if (kind !== undefined && kind !== 'far')\n return this.error('refused', `the place ${place} is a source of the owners' own, which offers no faculty`);\n if (!Array.isArray(items)) return this.error('refused', 'a faculty given holds its items');\n const taken = Library.#givenAssets(this.crypto, items);\n if (typeof taken === 'string') return this.error('refused', taken);\n const { source, bytes, assets } = taken;\n if (Library.digestOf(this.crypto, source) !== digest)\n return this.error('refused', `the faculty given is not its digest, ${digest}`);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const version = Library.field(blueprint, 'version');\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return this.error('refused', `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`);\n const road = `${place}@${version}`;\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const named = Library.field(blueprint, 'assets');\n if (!(named === undefined && assets.length === 0) && Library.assetsDigest(this.crypto, assets) !== named)\n return this.error('refused', \"the assets given are not the digest the faculty's blueprint names\");\n const sorted = assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1));\n const refused = Library.keep(\n this.cells,\n digest,\n { source, blueprint, road, ...(named === undefined ? {} : { assets: sorted }) },\n bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n *#addHand(args ) {\n const [source, assets, second] = ['source', 'assets', 'second'].map((one) => Library.field(args, one));\n if (typeof source !== 'string' || source === '') return this.error('refused', \"an owner's hand carries a source\");\n if (assets !== undefined && (!Array.isArray(assets) || assets.length > this.#page()))\n return this.error(\n 'refused',\n `assets carried are a list, of as many as a faculty holds, not ${Library.#sent(assets)}`,\n );\n if (second !== undefined && typeof second !== 'boolean')\n return this.error('refused', `\\`second\\` is an owner's word, true or false, not ${Library.#sent(second)}`);\n const taken = Library.#givenAssets(this.crypto, [{ source }, ...(assets ?? [])]);\n if (typeof taken === 'string') return this.error('refused', taken);\n const blueprint = yield* this.#read(source);\n if (typeof blueprint === 'string') return this.error('refused', blueprint);\n const version = Library.field(blueprint, 'version');\n if (typeof version !== 'string' || !Library.#versionText.test(version))\n return this.error('refused', `a version is three whole numbers joined by dots, not ${Library.#sent(version)}`);\n const road = `${Library.#handRoad}@${version}`;\n const digest = Library.digestOf(this.crypto, source);\n if (this.cells.get(['faculty', digest]) !== undefined) return this.#reroad(digest, road, version);\n const named = Library.field(blueprint, 'assets');\n if (named !== undefined && Library.assetsDigest(this.crypto, taken.assets) !== named)\n return this.error('refused', \"the assets carried are not the digest the faculty's blueprint names\");\n const refused = Library.keep(\n this.cells,\n digest,\n {\n source,\n blueprint,\n road,\n ...(named === undefined && taken.assets.length === 0\n ? {}\n : { assets: taken.assets.toSorted((one, other) => (one[0] < other[0] ? -1 : 1)) }),\n ...(second === true ? { second: Library.#handRoad } : {}),\n },\n taken.bytes,\n );\n return refused === null ? { digest } : this.error('refused', refused);\n }\n\n *remove(args ) {\n if (this.stamp.asker !== 'brain')\n return this.error('unavailable', \"the library removes a faculty on the brain's ask alone\");\n const digest = Library.#digestIn(args);\n if (digest === undefined) return this.error('refused', 'remove takes a digest');\n const record = this.cells.get(['faculty', digest]) ?? this.#organAt(digest);\n const blueprint = Library.field(record, 'blueprint');\n const name = Library.field(blueprint, 'name');\n const half = this.cells.get(['half', digest]) !== undefined;\n if (typeof name !== 'string' && !half) return this.error('refused', `the library keeps nothing under ${digest}`);\n const uses = yield {\n placeholder: 'brain',\n method: 'uses',\n args: { digest },\n };\n if ('error' in uses) return this.error(uses.error.code, uses.error.message);\n if (uses.result !== false) return this.error('used', `a lobe or an organ stands on ${digest}`);\n if (typeof name !== 'string') this.cells.delete(['half', digest]);\n else {\n this.cells.delete(['faculty', digest]);\n this.cells.delete(['organ', digest]);\n const held = this.#assetsOf(Library.field(record, 'assets')) ?? [];\n const named = held.length === 0 ? new Set () : this.#assetsNamed();\n for (const [, sha] of held) if (!named.has(sha)) this.cells.delete(['asset', sha]);\n this.cells.delete(['name', name, digest]);\n this.cells.delete(['spared', digest]);\n }\n return null;\n }\n\n spare(args ) {\n if (this.stamp.asker !== Library.#owner)\n return this.error('refused', \"the library spares a version on an owner's ask through the brain alone\");\n const digest = Library.#digestIn(args);\n const spared = Library.field(args, 'spared') ?? true;\n if (digest === undefined || typeof spared !== 'boolean')\n return this.error('refused', 'spare takes a digest, and `spared` where it gives one back');\n if (!this.#keeps(digest)) return this.error('refused', `the library keeps nothing under ${digest}`);\n if (spared) this.cells.set(['spared', digest], true);\n else this.cells.delete(['spared', digest]);\n return null;\n }\n\n #keeps(digest ) {\n return this.cells.get(['faculty', digest]) !== undefined || this.cells.get(['organ', digest]) !== undefined;\n }\n\n static proven(record ) {\n const road = Library.field(record, 'road');\n const taken = typeof road === 'string' && /^(?:hand|[A-Z][A-Z0-9]*)@/u.test(road);\n const assets = Library.field(record, 'assets');\n return (\n !taken || (Array.isArray(assets) && assets.some((one) => Array.isArray(one) && one[0] === Library.#evidence))\n );\n }\n\n #evidenceOf(record ) {\n const carried = this.#assetsOf(Library.field(record, 'assets')) ?? [];\n return carried.find(([path]) => path === Library.#evidence)?.[1] ?? null;\n }\n\n evidence(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'evidence is kept from a far asker');\n const digest = Library.field(args, 'faculty');\n const record = Library.#isDigest(digest) ? this.cells.get(['faculty', digest]) : undefined;\n if (record === undefined) return this.error('refused', 'evidence takes the digest of a faculty the library keeps');\n return { evidence: this.#evidenceOf(record) };\n }\n\n old() {\n if (this.stamp.asker !== Library.#owner)\n return this.error('unavailable', 'the library names its old versions to the brain alone');\n return { digests: this.#olderIn() };\n }\n\n #olderIn() {\n const newest = new Map ();\n const older = [];\n let cursor = null;\n do {\n const page = this.cells.range({\n prefix: ['version'],\n limit: this.#page(),\n ...(cursor === null ? {} : { cursor }),\n });\n for (const { key, value } of page.cells) {\n const at = Library.#semver(key[2]);\n if (typeof value !== 'string' || at === null || !this.#keeps(value)) continue;\n const name = String(key[1]);\n const top = newest.get(name);\n if (top === undefined) newest.set(name, { at, digest: value });\n else if (Library.#newer(at, top.at)) {\n older.push(top.digest);\n newest.set(name, { at, digest: value });\n } else older.push(value);\n }\n cursor = page.cursor;\n } while (cursor !== null);\n return older.filter((digest) => this.cells.get(['spared', digest]) === undefined);\n }\n\n static #semver(version ) {\n if (typeof version !== 'string' || !Library.#versionText.test(version)) return null;\n return version.split('.').map(Number);\n }\n\n static #newer(one , other ) {\n for (let at = 0; at < 3; at += 1) if ((one[at] ?? 0) !== (other[at] ?? 0)) return (one[at] ?? 0) > (other[at] ?? 0);\n return false;\n }\n\n get(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'get is kept from a far asker');\n const digest = Library.#digestIn(args);\n if (digest === undefined) return this.error('refused', 'get takes a digest');\n return (\n this.cells.get(['faculty', digest]) ??\n this.#organAt(digest) ??\n this.#assetAt(digest) ??\n this.cells.get(['half', digest]) ??\n null\n );\n }\n\n #assetAt(digest ) {\n const kept = this.cells.get(['asset', digest]);\n return kept instanceof Uint8Array ? { digest, bytes: kept } : undefined;\n }\n\n list(args ) {\n if (this.stamp.occupant !== null) return this.error('refused', 'list is kept from a far asker');\n const cursor = Library.field(args, 'cursor') ?? null;\n const most = this.#page();\n const limit = Library.field(args, 'limit') ?? most;\n const told = Library.field(args, 'told') ?? false;\n if (cursor !== null && typeof cursor !== 'string')\n return this.error('refused', `a cursor is a text, or null, not ${Library.#sent(cursor)}`);\n if (typeof limit !== 'number' || !Number.isInteger(limit) || limit < 1 || limit > most)\n return this.error('refused', `a limit is a whole number from 1 to ${most}, not ${Library.#sent(limit)}`);\n if (typeof told !== 'boolean') return this.error('refused', `told is true or false, not ${Library.#sent(told)}`);\n const page = this.cells.range({\n prefix: [told ? 'told' : 'name'],\n limit,\n ...(cursor === null ? {} : { cursor }),\n });\n if (told) return { told: page.cells.map((cell) => this.#told(cell)), cursor: page.cursor };\n const faculties = page.cells.map(({ key, value }) => {\n const digest = String(key[2]);\n const organ = this.#organAt(digest);\n const record = organ ?? this.cells.get(['faculty', digest]);\n const road = Library.field(record, 'road');\n return {\n name: String(key[1]),\n digest,\n ...(typeof value === 'string' ? { label: value } : {}),\n ...(typeof road === 'string' ? { road } : {}),\n ...(organ === undefined ? {} : { kind: 'organ' }),\n ...(this.cells.get(['spared', digest]) === undefined ? {} : { spared: true }),\n ...(organ === undefined && !Library.proven(record) ? { unproven: true } : {}),\n };\n });\n return { faculties, cursor: page.cursor };\n }\n\n #organAt(digest ) {\n const row = this.cells.get(['organ', digest]);\n if (row === undefined) return undefined;\n const record = {};\n for (const field of ['id', 'digest', 'graph', 'blueprint', 'reach', 'half', 'road']) {\n const value = Library.field(row, field);\n if (value !== undefined) record[field] = value;\n }\n return record;\n }\n\n static #toldRow(row ) {\n if (row === undefined) return undefined;\n const [digest, at] = ['digest', 'at'].map((one) => Library.field(row, one));\n return {\n ...(digest === undefined ? {} : { digest }),\n ...(at === undefined ? {} : { at }),\n };\n }\n\n #told({ key, value } ) {\n const row = Library.#toldRow(value) ?? {};\n const { at } = row;\n const { digest } = row;\n const kept =\n typeof digest === 'string' &&\n (this.cells.get(['faculty', digest]) !== undefined || this.cells.get(['organ', digest]) !== undefined);\n const [lobe = '', kind = '', label = '', version = ''] = key.slice(1).map(String);\n return {\n lobe,\n kind,\n label,\n version,\n digest: digest ?? null,\n at: at ?? null,\n kept,\n };\n }\n}";
|
|
5755
5755
|
|
|
5756
5756
|
var LIBRARY_SOURCE = facultySource(LIBRARY_TEXT);
|
|
5757
5757
|
|
|
5758
5758
|
var SCHEDULER_BLUEPRINT = {
|
|
5759
5759
|
name: "nervur.scheduler",
|
|
5760
|
-
version: "0.37.
|
|
5760
|
+
version: "0.37.6",
|
|
5761
5761
|
description: "The scheduler: every lobe's alarms, over the brain's one durable wake.",
|
|
5762
5762
|
methods: {
|
|
5763
5763
|
set: {
|
|
@@ -5841,7 +5841,7 @@ var SCHEDULER_BLUEPRINT = {
|
|
|
5841
5841
|
placeholders: { brain: "nervur.brain", cage: "nervur.cage" }
|
|
5842
5842
|
};
|
|
5843
5843
|
|
|
5844
|
-
var SCHEDULER_TEXT = "class Scheduler extends Faculty {\n static #count = { type: 'integer', minimum: 0 };\n\n static #cursor = { anyOf: [{ type: 'string' }, { type: 'null' }] };\n\n static #object(properties , required ) {\n return { type: 'object', properties, required, additionalProperties: false };\n }\n\n static blueprint = {\n name: 'nervur.scheduler',\n version: '0.37.5',\n description: \"The scheduler: every lobe's alarms, over the brain's one durable wake.\",\n methods: {\n set: {\n description:\n \"Keeps an alarm of the asker's: when, on the wall clock, which of its methods to ring, and its args. Answers the alarm's ID.\",\n kind: 'writing',\n args: Scheduler.#object({ at: Scheduler.#count, method: { type: 'string', minLength: 1 }, args: {} }, [\n 'at',\n 'method',\n ]),\n result: Scheduler.#object({ id: Scheduler.#count }, ['id']),\n errors: ['refused'],\n },\n cancel: {\n description:\n \"Removes an alarm of the asker's, by its ID; asked by the brain for an owner, an alarm of the lobe it names.\",\n kind: 'writing',\n args: Scheduler.#object({ id: Scheduler.#count, lobe: { type: 'string', minLength: 1 } }, ['id']),\n result: { type: 'null' },\n errors: ['refused'],\n },\n list: {\n description:\n \"The asker's own alarms, never another lobe's, a page at a time: `limit` of them, as many as a part of what this lobe holds at most where it names none, and never more.\",\n kind: 'reading',\n args: Scheduler.#object({ cursor: Scheduler.#cursor, limit: { type: 'integer', minimum: 1 } }, []),\n result: Scheduler.#object(\n {\n alarms: {\n type: 'array',\n items: Scheduler.#object(\n {\n id: Scheduler.#count,\n at: Scheduler.#count,\n method: { type: 'string' },\n args: {},\n },\n ['id', 'at', 'method', 'args'],\n ),\n },\n cursor: Scheduler.#cursor,\n },\n ['alarms', 'cursor'],\n ),\n errors: ['refused'],\n },\n now: {\n description: 'The time, on the wall clock, for a lobe deep in a long ask.',\n kind: 'reading',\n result: { type: 'number' },\n },\n wake: {\n askers: ['brain'],\n args: Scheduler.#object({}, []),\n description:\n \"The brain's alone, when its wake is due: ends every alarm due and posts its ring, a letter to its lobe, in this answer's batch, and waits on no lobe. One whose lobe is torn down ends unrung. Then it asks the brain the next wake.\",\n kind: 'writing',\n result: { type: 'null' },\n },\n },\n placeholders: { brain: 'nervur.brain', cage: 'nervur.cage' },\n };\n\n static #lives = Math.floor(Number.MAX_SAFE_INTEGER / 2);\n\n static #rings = 20;\n\n #page() {\n return Math.min(1000, Math.floor(this.memory / 4 / 1024));\n }\n\n static #sent(value ) {\n if (value === undefined) return 'nothing';\n const read = JSON.stringify(value);\n return read.length > 64 ? `${read.slice(0, 63)}\u2026` : read;\n }\n\n static #isCount(value ) {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;\n }\n\n static #ask(placeholder , method , args ) {\n return { placeholder, method, args };\n }\n\n #earliest(limit ) {\n return this.cells.range({ prefix: ['due'], limit }).cells.map(({ key }) => {\n const [, at, lobe, id] = key;\n if (typeof at !== 'number' || typeof lobe !== 'string' || typeof id !== 'number')\n throw new TypeError(`the row ${JSON.stringify(key)} is no alarm's`);\n const kept = this.cells.get(['alarm', lobe, id]);\n const method = Scheduler.field(kept, 'method');\n if (typeof method !== 'string') throw new TypeError(`the alarm ${id} of ${lobe} is not kept`);\n return { lobe, id, at, method, args: Scheduler.field(kept, 'args') ?? null };\n });\n }\n\n #holds(lobe ) {\n return this.cells.range({ prefix: ['alarm', lobe], limit: 1 }).cells.length > 0;\n }\n\n #remove(lobe , id , at ) {\n this.cells.delete(['alarm', lobe, id]);\n this.cells.delete(['due', at, lobe, id]);\n }\n\n #coming(asked ) {\n return Scheduler.#isCount(asked) && asked > this.stamp.time;\n }\n\n *#wakeAt(at ) {\n const asked = yield Scheduler.#ask('brain', 'wake', { at });\n if ('result' in asked) this.cells.set(['wake'], at);\n return asked;\n }\n\n *#unwire(lobe ) {\n yield Scheduler.#ask('nerves', 'unwire', { placeholder: lobe });\n return null;\n }\n\n *#ring(lobe , method , args ) {\n const ring = { ...Scheduler.#ask(lobe, method, args), letter: { lives: Scheduler.#lives } };\n const rang = yield ring;\n if (!('error' in rang) || rang.error.code !== 'unavailable') return rang;\n const ordered = yield Scheduler.#ask('nerves', 'order', { order: { termination: lobe } });\n return 'error' in ordered ? rang : yield ring;\n }\n\n *set(args ) {\n const { asker } = this.stamp;\n if (asker === 'brain')\n return this.error('refused', 'the scheduler keeps the alarms of lobes, and the brain is none');\n const at = Scheduler.field(args, 'at');\n const method = Scheduler.field(args, 'method');\n if (!Scheduler.#isCount(at))\n return this.error(\n 'refused',\n `at is a time on the wall clock, whole milliseconds from 0, not ${Scheduler.#sent(at)}`,\n );\n if (typeof method !== 'string' || method === '')\n return this.error('refused', `method is the name of one of your methods, not ${Scheduler.#sent(method)}`);\n if (!this.#holds(asker)) {\n const ordered = yield Scheduler.#ask('nerves', 'order', {\n order: { termination: asker },\n });\n if ('error' in ordered) return this.error(ordered.error.code, ordered.error.message);\n }\n const next = this.cells.get(['next']);\n const id = (Scheduler.#isCount(next) ? next : 0) + 1;\n this.cells.set(['next'], id);\n const given = Scheduler.field(args, 'args');\n this.cells.set(['alarm', asker, id], { at, method, args: given === undefined ? {} : given });\n this.cells.set(['due', at, asker, id], null);\n const asked = this.cells.get(['wake']);\n if (this.#coming(asked) && asked <= at) return { id };\n const woken = yield* this.#wakeAt(this.#earliest(1)[0]?.at ?? at);\n return 'error' in woken ? this.error(woken.error.code, woken.error.message) : { id };\n }\n\n *cancel(args ) {\n const { asker } = this.stamp;\n const lobe = asker === 'brain' ? Scheduler.field(args, 'lobe') : asker;\n const id = Scheduler.field(args, 'id');\n if (typeof lobe !== 'string') return this.error('refused', 'an owner names the lobe whose alarm ends');\n const kept = Scheduler.#isCount(id) ? this.cells.get(['alarm', lobe, id]) : undefined;\n const at = Scheduler.field(kept, 'at');\n if (!Scheduler.#isCount(id) || !Scheduler.#isCount(at))\n return this.error('refused', `${lobe} holds no alarm ${JSON.stringify(id ?? null)}`);\n this.#remove(lobe, id, at);\n if (!this.#holds(lobe)) yield* this.#unwire(lobe);\n const first = this.#earliest(1)[0]?.at ?? null;\n const asked = this.cells.get(['wake']);\n if (!Scheduler.#isCount(asked) || (this.#coming(asked) && first !== null && first <= asked)) return null;\n const woken = yield* this.#wakeAt(first);\n return 'error' in woken ? this.error(woken.error.code, woken.error.message) : null;\n }\n\n list(args ) {\n const cursor = Scheduler.field(args, 'cursor') ?? null;\n const most = this.#page();\n const limit = Scheduler.field(args, 'limit') ?? most;\n if (cursor !== null && typeof cursor !== 'string')\n return this.error('refused', `a cursor is a text, or null, not ${Scheduler.#sent(cursor)}`);\n if (!Scheduler.#isCount(limit) || limit < 1 || limit > most)\n return this.error('refused', `a limit is a whole number from 1 to ${most}, not ${Scheduler.#sent(limit)}`);\n const prefix = ['alarm', this.stamp.asker];\n const page = this.cells.range({ prefix, limit, ...(cursor === null ? {} : { cursor }) });\n const alarms = page.cells.map(({ key, value }) => ({\n id: key[2] ?? null,\n at: Scheduler.field(value, 'at') ?? null,\n method: Scheduler.field(value, 'method') ?? null,\n args: Scheduler.field(value, 'args') ?? null,\n }));\n return { alarms, cursor: page.cursor };\n }\n\n now() {\n return this.stamp.time;\n }\n\n *wake() {\n const now = this.stamp.time;\n const due = this.#earliest(Scheduler.#rings + 1).filter((alarm) => alarm.at <= now);\n const ringing = due.slice(0, Scheduler.#rings);\n const touched = new Set ();\n for (const { lobe, id, at, method, args } of ringing) {\n const rang = yield* this.#ring(lobe, method, args);\n if ('error' in rang && rang.error.code !== 'unavailable') continue;\n this.#remove(lobe, id, at);\n touched.add(lobe);\n }\n for (const lobe of touched) if (!this.#holds(lobe)) yield* this.#unwire(lobe);\n const later = this.#earliest(Scheduler.#rings + 1).find((alarm) => alarm.at > now);\n const times = [...(due.length > ringing.length ? [now] : []), ...(later === undefined ? [] : [later.at])];\n yield* this.#wakeAt(times.length === 0 ? null : Math.min(...times));\n return null;\n }\n}";
|
|
5844
|
+
var SCHEDULER_TEXT = "class Scheduler extends Faculty {\n static #count = { type: 'integer', minimum: 0 };\n\n static #cursor = { anyOf: [{ type: 'string' }, { type: 'null' }] };\n\n static #object(properties , required ) {\n return { type: 'object', properties, required, additionalProperties: false };\n }\n\n static blueprint = {\n name: 'nervur.scheduler',\n version: '0.37.6',\n description: \"The scheduler: every lobe's alarms, over the brain's one durable wake.\",\n methods: {\n set: {\n description:\n \"Keeps an alarm of the asker's: when, on the wall clock, which of its methods to ring, and its args. Answers the alarm's ID.\",\n kind: 'writing',\n args: Scheduler.#object({ at: Scheduler.#count, method: { type: 'string', minLength: 1 }, args: {} }, [\n 'at',\n 'method',\n ]),\n result: Scheduler.#object({ id: Scheduler.#count }, ['id']),\n errors: ['refused'],\n },\n cancel: {\n description:\n \"Removes an alarm of the asker's, by its ID; asked by the brain for an owner, an alarm of the lobe it names.\",\n kind: 'writing',\n args: Scheduler.#object({ id: Scheduler.#count, lobe: { type: 'string', minLength: 1 } }, ['id']),\n result: { type: 'null' },\n errors: ['refused'],\n },\n list: {\n description:\n \"The asker's own alarms, never another lobe's, a page at a time: `limit` of them, as many as a part of what this lobe holds at most where it names none, and never more.\",\n kind: 'reading',\n args: Scheduler.#object({ cursor: Scheduler.#cursor, limit: { type: 'integer', minimum: 1 } }, []),\n result: Scheduler.#object(\n {\n alarms: {\n type: 'array',\n items: Scheduler.#object(\n {\n id: Scheduler.#count,\n at: Scheduler.#count,\n method: { type: 'string' },\n args: {},\n },\n ['id', 'at', 'method', 'args'],\n ),\n },\n cursor: Scheduler.#cursor,\n },\n ['alarms', 'cursor'],\n ),\n errors: ['refused'],\n },\n now: {\n description: 'The time, on the wall clock, for a lobe deep in a long ask.',\n kind: 'reading',\n result: { type: 'number' },\n },\n wake: {\n askers: ['brain'],\n args: Scheduler.#object({}, []),\n description:\n \"The brain's alone, when its wake is due: ends every alarm due and posts its ring, a letter to its lobe, in this answer's batch, and waits on no lobe. One whose lobe is torn down ends unrung. Then it asks the brain the next wake.\",\n kind: 'writing',\n result: { type: 'null' },\n },\n },\n placeholders: { brain: 'nervur.brain', cage: 'nervur.cage' },\n };\n\n static #lives = Math.floor(Number.MAX_SAFE_INTEGER / 2);\n\n static #rings = 20;\n\n #page() {\n return Math.min(1000, Math.floor(this.memory / 4 / 1024));\n }\n\n static #sent(value ) {\n if (value === undefined) return 'nothing';\n const read = JSON.stringify(value);\n return read.length > 64 ? `${read.slice(0, 63)}\u2026` : read;\n }\n\n static #isCount(value ) {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;\n }\n\n static #ask(placeholder , method , args ) {\n return { placeholder, method, args };\n }\n\n #earliest(limit ) {\n return this.cells.range({ prefix: ['due'], limit }).cells.map(({ key }) => {\n const [, at, lobe, id] = key;\n if (typeof at !== 'number' || typeof lobe !== 'string' || typeof id !== 'number')\n throw new TypeError(`the row ${JSON.stringify(key)} is no alarm's`);\n const kept = this.cells.get(['alarm', lobe, id]);\n const method = Scheduler.field(kept, 'method');\n if (typeof method !== 'string') throw new TypeError(`the alarm ${id} of ${lobe} is not kept`);\n return { lobe, id, at, method, args: Scheduler.field(kept, 'args') ?? null };\n });\n }\n\n #holds(lobe ) {\n return this.cells.range({ prefix: ['alarm', lobe], limit: 1 }).cells.length > 0;\n }\n\n #remove(lobe , id , at ) {\n this.cells.delete(['alarm', lobe, id]);\n this.cells.delete(['due', at, lobe, id]);\n }\n\n #coming(asked ) {\n return Scheduler.#isCount(asked) && asked > this.stamp.time;\n }\n\n *#wakeAt(at ) {\n const asked = yield Scheduler.#ask('brain', 'wake', { at });\n if ('result' in asked) this.cells.set(['wake'], at);\n return asked;\n }\n\n *#unwire(lobe ) {\n yield Scheduler.#ask('nerves', 'unwire', { placeholder: lobe });\n return null;\n }\n\n *#ring(lobe , method , args ) {\n const ring = { ...Scheduler.#ask(lobe, method, args), letter: { lives: Scheduler.#lives } };\n const rang = yield ring;\n if (!('error' in rang) || rang.error.code !== 'unavailable') return rang;\n const ordered = yield Scheduler.#ask('nerves', 'order', { order: { termination: lobe } });\n return 'error' in ordered ? rang : yield ring;\n }\n\n *set(args ) {\n const { asker } = this.stamp;\n if (asker === 'brain')\n return this.error('refused', 'the scheduler keeps the alarms of lobes, and the brain is none');\n const at = Scheduler.field(args, 'at');\n const method = Scheduler.field(args, 'method');\n if (!Scheduler.#isCount(at))\n return this.error(\n 'refused',\n `at is a time on the wall clock, whole milliseconds from 0, not ${Scheduler.#sent(at)}`,\n );\n if (typeof method !== 'string' || method === '')\n return this.error('refused', `method is the name of one of your methods, not ${Scheduler.#sent(method)}`);\n if (!this.#holds(asker)) {\n const ordered = yield Scheduler.#ask('nerves', 'order', {\n order: { termination: asker },\n });\n if ('error' in ordered) return this.error(ordered.error.code, ordered.error.message);\n }\n const next = this.cells.get(['next']);\n const id = (Scheduler.#isCount(next) ? next : 0) + 1;\n this.cells.set(['next'], id);\n const given = Scheduler.field(args, 'args');\n this.cells.set(['alarm', asker, id], { at, method, args: given === undefined ? {} : given });\n this.cells.set(['due', at, asker, id], null);\n const asked = this.cells.get(['wake']);\n if (this.#coming(asked) && asked <= at) return { id };\n const woken = yield* this.#wakeAt(this.#earliest(1)[0]?.at ?? at);\n return 'error' in woken ? this.error(woken.error.code, woken.error.message) : { id };\n }\n\n *cancel(args ) {\n const { asker } = this.stamp;\n const lobe = asker === 'brain' ? Scheduler.field(args, 'lobe') : asker;\n const id = Scheduler.field(args, 'id');\n if (typeof lobe !== 'string') return this.error('refused', 'an owner names the lobe whose alarm ends');\n const kept = Scheduler.#isCount(id) ? this.cells.get(['alarm', lobe, id]) : undefined;\n const at = Scheduler.field(kept, 'at');\n if (!Scheduler.#isCount(id) || !Scheduler.#isCount(at))\n return this.error('refused', `${lobe} holds no alarm ${JSON.stringify(id ?? null)}`);\n this.#remove(lobe, id, at);\n if (!this.#holds(lobe)) yield* this.#unwire(lobe);\n const first = this.#earliest(1)[0]?.at ?? null;\n const asked = this.cells.get(['wake']);\n if (!Scheduler.#isCount(asked) || (this.#coming(asked) && first !== null && first <= asked)) return null;\n const woken = yield* this.#wakeAt(first);\n return 'error' in woken ? this.error(woken.error.code, woken.error.message) : null;\n }\n\n list(args ) {\n const cursor = Scheduler.field(args, 'cursor') ?? null;\n const most = this.#page();\n const limit = Scheduler.field(args, 'limit') ?? most;\n if (cursor !== null && typeof cursor !== 'string')\n return this.error('refused', `a cursor is a text, or null, not ${Scheduler.#sent(cursor)}`);\n if (!Scheduler.#isCount(limit) || limit < 1 || limit > most)\n return this.error('refused', `a limit is a whole number from 1 to ${most}, not ${Scheduler.#sent(limit)}`);\n const prefix = ['alarm', this.stamp.asker];\n const page = this.cells.range({ prefix, limit, ...(cursor === null ? {} : { cursor }) });\n const alarms = page.cells.map(({ key, value }) => ({\n id: key[2] ?? null,\n at: Scheduler.field(value, 'at') ?? null,\n method: Scheduler.field(value, 'method') ?? null,\n args: Scheduler.field(value, 'args') ?? null,\n }));\n return { alarms, cursor: page.cursor };\n }\n\n now() {\n return this.stamp.time;\n }\n\n *wake() {\n const now = this.stamp.time;\n const due = this.#earliest(Scheduler.#rings + 1).filter((alarm) => alarm.at <= now);\n const ringing = due.slice(0, Scheduler.#rings);\n const touched = new Set ();\n for (const { lobe, id, at, method, args } of ringing) {\n const rang = yield* this.#ring(lobe, method, args);\n if ('error' in rang && rang.error.code !== 'unavailable') continue;\n this.#remove(lobe, id, at);\n touched.add(lobe);\n }\n for (const lobe of touched) if (!this.#holds(lobe)) yield* this.#unwire(lobe);\n const later = this.#earliest(Scheduler.#rings + 1).find((alarm) => alarm.at > now);\n const times = [...(due.length > ringing.length ? [now] : []), ...(later === undefined ? [] : [later.at])];\n yield* this.#wakeAt(times.length === 0 ? null : Math.min(...times));\n return null;\n }\n}";
|
|
5845
5845
|
|
|
5846
5846
|
var SCHEDULER_SOURCE = facultySource(SCHEDULER_TEXT);
|
|
5847
5847
|
|
|
@@ -14477,11 +14477,11 @@ var swept = (outside2, named6) => {
|
|
|
14477
14477
|
if (!named6.has(file) && !outside2.laid.has(file)) outside2.pages.remove(file);
|
|
14478
14478
|
};
|
|
14479
14479
|
|
|
14480
|
-
var PAGE4 = 8192;
|
|
14481
14480
|
var LOG_HEADER = 32;
|
|
14481
|
+
var AT_PAGE_SIZE = 8;
|
|
14482
|
+
var PAGE_SIZES = [512, 1024, 2048, 4096, 8192, 16384, 32768, 65536];
|
|
14482
14483
|
var SUMMED_HEADER = 24;
|
|
14483
14484
|
var FRAME_HEADER = 24;
|
|
14484
|
-
var FRAME = FRAME_HEADER + PAGE4;
|
|
14485
14485
|
var SALTS = 8;
|
|
14486
14486
|
var SALTS_END = 16;
|
|
14487
14487
|
var SUMS_SIZE = 8;
|
|
@@ -14527,8 +14527,12 @@ var oneByteAway = (content, sums, stored) => {
|
|
|
14527
14527
|
}
|
|
14528
14528
|
return false;
|
|
14529
14529
|
};
|
|
14530
|
+
var pageSizeOf = (header) => {
|
|
14531
|
+
const named6 = viewOf(header).getUint32(AT_PAGE_SIZE);
|
|
14532
|
+
return PAGE_SIZES.find((size) => size === named6) ?? null;
|
|
14533
|
+
};
|
|
14530
14534
|
var summedOf = (frame) => {
|
|
14531
|
-
const content = new Uint8Array(
|
|
14535
|
+
const content = new Uint8Array(frame.length - FRAME_HEADER + 8);
|
|
14532
14536
|
content.set(frame.subarray(0, 8));
|
|
14533
14537
|
content.set(frame.subarray(FRAME_HEADER), 8);
|
|
14534
14538
|
return content;
|
|
@@ -14549,14 +14553,21 @@ var damagedLog = (log) => {
|
|
|
14549
14553
|
const sums = summed([0, 0], content);
|
|
14550
14554
|
const whole2 = same(sums, stored);
|
|
14551
14555
|
if (!whole2 && (oneOff(sums, stored) || oneByteAway(content, sums, stored))) return true;
|
|
14556
|
+
if (!whole2) return PAGE_SIZES.some((page2) => damagedFrames(log, header, false, page2));
|
|
14557
|
+
const page = pageSizeOf(header);
|
|
14558
|
+
return page === null || damagedFrames(log, header, true, page);
|
|
14559
|
+
};
|
|
14560
|
+
var damagedFrames = (log, header, whole2, page) => {
|
|
14561
|
+
const stored = header.subarray(SUMMED_HEADER);
|
|
14562
|
+
const size = FRAME_HEADER + page;
|
|
14552
14563
|
let seed = sumsOf(stored);
|
|
14553
14564
|
let salts = whole2 ? header.subarray(16, SUMMED_HEADER) : null;
|
|
14554
14565
|
let past = !whole2;
|
|
14555
14566
|
let ended5 = false;
|
|
14556
14567
|
let pad = false;
|
|
14557
|
-
const frames = Math.floor((log.size() - LOG_HEADER) /
|
|
14568
|
+
const frames = Math.floor((log.size() - LOG_HEADER) / size);
|
|
14558
14569
|
for (let at = 0; at < frames; at += 1) {
|
|
14559
|
-
const frame = log.read(LOG_HEADER + at *
|
|
14570
|
+
const frame = log.read(LOG_HEADER + at * size, size);
|
|
14560
14571
|
salts ??= frame.slice(SALTS, SALTS_END);
|
|
14561
14572
|
const stands2 = differing(salts, frame.subarray(SALTS, SALTS_END)) === 0 && same(summed(seed, summedOf(frame)), frame.subarray(SALTS_END, FRAME_HEADER));
|
|
14562
14573
|
const padding = pad;
|
|
@@ -14573,7 +14584,7 @@ var damagedLog = (log) => {
|
|
|
14573
14584
|
if (!stands2) ended5 = false;
|
|
14574
14585
|
if (commits) {
|
|
14575
14586
|
ended5 = true;
|
|
14576
|
-
pad = (LOG_HEADER + (at + 1) *
|
|
14587
|
+
pad = (LOG_HEADER + (at + 1) * size) % SECTOR !== 0;
|
|
14577
14588
|
}
|
|
14578
14589
|
}
|
|
14579
14590
|
return false;
|
|
@@ -15315,6 +15326,9 @@ var ADDITIONAL = utf8Bytes("nervur log record");
|
|
|
15315
15326
|
|
|
15316
15327
|
var HEAD4 = 1 + 8 + 4;
|
|
15317
15328
|
|
|
15329
|
+
var RESEAL = 2 ** 31;
|
|
15330
|
+
var MOST_SEALED = 2 ** 32 - 2 ** 20;
|
|
15331
|
+
|
|
15318
15332
|
var COMPACT_AT = 1 << 20;
|
|
15319
15333
|
|
|
15320
15334
|
var VITAL = [BRAIN, KEY2, EAR].map((lobe) => prefixRange([lobe]));
|
|
@@ -15345,7 +15359,7 @@ var subtracted = (one, other) => {
|
|
|
15345
15359
|
};
|
|
15346
15360
|
var hexOf = (sum) => sum.map((limb) => limb.toString(16).padStart(4, "0")).join("");
|
|
15347
15361
|
|
|
15348
|
-
var
|
|
15362
|
+
var PAGE4 = 256;
|
|
15349
15363
|
var UNREAD = "f".repeat(64);
|
|
15350
15364
|
var partitionOf = (key2) => {
|
|
15351
15365
|
const first = keyOf2(key2)?.key[0];
|
|
@@ -15363,10 +15377,10 @@ var wholeOf = (reader4, crypto2, partition) => {
|
|
|
15363
15377
|
let sum = ZERO;
|
|
15364
15378
|
let after2 = null;
|
|
15365
15379
|
for (; ; ) {
|
|
15366
|
-
const page = reader4.range(from, to,
|
|
15380
|
+
const page = reader4.range(from, to, PAGE4, after2);
|
|
15367
15381
|
for (const { key: key2, value } of page) sum = added(sum, cellOf2(crypto2, key2, value));
|
|
15368
15382
|
const last = page.at(-1);
|
|
15369
|
-
if (page.length <
|
|
15383
|
+
if (page.length < PAGE4 || last === void 0) return sum;
|
|
15370
15384
|
after2 = last.key;
|
|
15371
15385
|
}
|
|
15372
15386
|
};
|
|
@@ -16892,6 +16906,7 @@ var drawRecordKey = (cells, chance) => {
|
|
|
16892
16906
|
};
|
|
16893
16907
|
|
|
16894
16908
|
var LIFTED = Number.MAX_SAFE_INTEGER;
|
|
16909
|
+
var NOTE_LIMIT = 4096;
|
|
16895
16910
|
var TREE_CAPS = ["nodes", "depth", "key", "text", "sounds"];
|
|
16896
16911
|
var OF_A_LOBE = new Set([
|
|
16897
16912
|
"longestBudget",
|
|
@@ -20115,7 +20130,9 @@ var cutOff2 = (hold5, held2, message2, why) => {
|
|
|
20115
20130
|
var ended2 = (hold5, held2, ending) => {
|
|
20116
20131
|
if ("answered" in ending) {
|
|
20117
20132
|
const writes = held2.cells?.batch() ?? [];
|
|
20118
|
-
const
|
|
20133
|
+
const judged2 = [...writes, ...held2.posted];
|
|
20134
|
+
const posted = held2.posted.reduce((sum, { key: key2, value }) => sum + key2.length + (value?.length ?? 0), 0);
|
|
20135
|
+
const full = judged2.length === 0 ? null : hold5.gear.refused?.(held2.lobe, judged2, (held2.cells?.held() ?? 0) + posted) ?? null;
|
|
20119
20136
|
if (full !== null) return settle4(hold5, held2, error("busy", full), []);
|
|
20120
20137
|
ringAgain(hold5, held2, ending.answered, enqueue(hold5));
|
|
20121
20138
|
settle4(hold5, held2, ending.answered, [...writes, ...held2.taken, ...postedBy(hold5, held2)]);
|
|
@@ -20644,7 +20661,6 @@ var toldSilent = (kit, far, since) => {
|
|
|
20644
20661
|
});
|
|
20645
20662
|
};
|
|
20646
20663
|
|
|
20647
|
-
var NOTE_LIMIT = 4096;
|
|
20648
20664
|
var noteIn = (args) => args["note"] ?? null;
|
|
20649
20665
|
var noteMost = (cells, lobe) => limitIn(cells, "note", lobe) ?? NOTE_LIMIT;
|
|
20650
20666
|
var sizeOf2 = (data) => utf8Bytes(dataText(data)).length;
|
|
@@ -21685,8 +21701,10 @@ var move = (kit, asker, fields, { done: done2, settled: settled3 }) => {
|
|
|
21685
21701
|
void kit.gear.backup(naming, told).then(sealed, (thrown2) => broke2(thrownText2(thrown2)));
|
|
21686
21702
|
});
|
|
21687
21703
|
};
|
|
21688
|
-
var lastPiece = (kit, leaving2, bytes7, { done: done2, joined: joined9 }) => {
|
|
21689
|
-
const heirs = everyRelation(kit.gear.cells()).flatMap(
|
|
21704
|
+
var lastPiece = (kit, asker, leaving2, bytes7, { done: done2, joined: joined9 }) => {
|
|
21705
|
+
const heirs = everyRelation(kit.gear.cells()).flatMap(
|
|
21706
|
+
({ heir, node: node2, far }) => node2 === BRAIN && far === asker ? [heir] : []
|
|
21707
|
+
);
|
|
21690
21708
|
const ending = kit.gear.backupEnd({ bytes: bytes7, heirs, joined: joined9 });
|
|
21691
21709
|
void ending.then(
|
|
21692
21710
|
(ended5) => {
|
|
@@ -21710,7 +21728,7 @@ var lastPiece = (kit, leaving2, bytes7, { done: done2, joined: joined9 }) => {
|
|
|
21710
21728
|
(thrown2) => done2(error("refused", thrownText2(thrown2)))
|
|
21711
21729
|
);
|
|
21712
21730
|
};
|
|
21713
|
-
var backupPiece = (kit, fields, reply2) => {
|
|
21731
|
+
var backupPiece = (kit, asker, fields, reply2) => {
|
|
21714
21732
|
const asked3 = { mark: textAt2(fields, "mark"), at: numberAt2(fields, "at"), length: numberAt2(fields, "length") };
|
|
21715
21733
|
const found = kit.leaving.current;
|
|
21716
21734
|
const leaving2 = found !== null && asked3.mark === found.mark ? found : null;
|
|
@@ -21719,7 +21737,7 @@ var backupPiece = (kit, fields, reply2) => {
|
|
|
21719
21737
|
return kit.gear.leave(NOT_SEALED);
|
|
21720
21738
|
}
|
|
21721
21739
|
if (leaving2 !== null && leaving2.bytes !== null && asked3.at === leaving2.bytes)
|
|
21722
|
-
return lastPiece(kit, leaving2, leaving2.bytes, reply2);
|
|
21740
|
+
return lastPiece(kit, asker, leaving2, leaving2.bytes, reply2);
|
|
21723
21741
|
void kit.gear.backupPiece(asked3).then((taken) => {
|
|
21724
21742
|
if ("why" in taken) return reply2.settled(error("refused", taken.why));
|
|
21725
21743
|
const { piece: piece3, made: made2 } = taken;
|
|
@@ -22182,7 +22200,7 @@ var recoveryKeys = (kit, args, { done: done2, joined: joined9 }) => {
|
|
|
22182
22200
|
kit.change(setChange(kit.gear, listAt2(args, "keys")), done2, joined9);
|
|
22183
22201
|
};
|
|
22184
22202
|
|
|
22185
|
-
var
|
|
22203
|
+
var PAGE5 = 64;
|
|
22186
22204
|
var offsetOf = (cursor) => {
|
|
22187
22205
|
if (cursor === void 0) return 0;
|
|
22188
22206
|
return /^(0|[1-9]\d{0,15})$/.test(cursor) ? Number(cursor) : null;
|
|
@@ -22191,9 +22209,9 @@ var pageOf3 = (sizes, offset) => {
|
|
|
22191
22209
|
const [nodes, letters, durables, alarms] = sizes;
|
|
22192
22210
|
const cut = (size, before4) => {
|
|
22193
22211
|
const from = Math.max(0, offset - before4);
|
|
22194
|
-
return { from, count: Math.max(0, Math.min(size, offset +
|
|
22212
|
+
return { from, count: Math.max(0, Math.min(size, offset + PAGE5 - before4) - from) };
|
|
22195
22213
|
};
|
|
22196
|
-
const next = offset +
|
|
22214
|
+
const next = offset + PAGE5;
|
|
22197
22215
|
return {
|
|
22198
22216
|
cuts: [cut(nodes, 0), cut(letters, nodes), cut(durables, nodes + letters), cut(alarms, nodes + letters + durables)],
|
|
22199
22217
|
cursor: next < nodes + letters + durables + alarms ? String(next) : null
|
|
@@ -24302,7 +24320,7 @@ var HANDLERS = {
|
|
|
24302
24320
|
joined9
|
|
24303
24321
|
),
|
|
24304
24322
|
move: (kit, asker, fields, reply2) => move(kit, asker, fields, reply2),
|
|
24305
|
-
backupPiece: (kit,
|
|
24323
|
+
backupPiece: (kit, asker, fields, reply2) => backupPiece(kit, asker, fields, reply2),
|
|
24306
24324
|
upgrade: (kit, _asker, fields, { settled: settled3 }) => upgrade(kit.gear, fields, settled3),
|
|
24307
24325
|
state: (kit, asker, fields, { settled: settled3, binds }) => {
|
|
24308
24326
|
const cursor = typeof fields["cursor"] === "string" ? fields["cursor"] : void 0;
|
|
@@ -24878,7 +24896,7 @@ var keepGenome = (cells) => {
|
|
|
24878
24896
|
};
|
|
24879
24897
|
if (isLater(FLOOR, kept3))
|
|
24880
24898
|
return {
|
|
24881
|
-
why: `the store was last booted by genome ${kept3}, below ${FLOOR}, the oldest this genome ${GENOME_VERSION} carries forward:
|
|
24899
|
+
why: `the store was last booted by genome ${kept3}, below ${FLOOR}, the oldest this genome ${GENOME_VERSION} carries forward: update it to ${FLOOR} first`
|
|
24882
24900
|
};
|
|
24883
24901
|
if (kept3 !== GENOME_VERSION) putRow(cells, ROW4, GENOME_VERSION, "brain");
|
|
24884
24902
|
return null;
|
|
@@ -24928,7 +24946,24 @@ var makeReflex = (gear, thawed) => {
|
|
|
24928
24946
|
};
|
|
24929
24947
|
};
|
|
24930
24948
|
|
|
24931
|
-
var RELATION =
|
|
24949
|
+
var RELATION = 4096;
|
|
24950
|
+
var chargedRows = {
|
|
24951
|
+
prefixes: [
|
|
24952
|
+
[BRAIN, "holds"],
|
|
24953
|
+
[BRAIN, "grant"],
|
|
24954
|
+
[BRAIN, "letter"],
|
|
24955
|
+
[BRAIN, "dead"]
|
|
24956
|
+
],
|
|
24957
|
+
of: (key2, value) => {
|
|
24958
|
+
const [, row, first, second] = key2;
|
|
24959
|
+
if (row === "holds") return typeof first === "string" ? first : null;
|
|
24960
|
+
if (row === "grant") return typeof second === "string" ? second : null;
|
|
24961
|
+
const read8 = dataOfBytes(value);
|
|
24962
|
+
if ("why" in read8 || !isFields(read8.data)) return null;
|
|
24963
|
+
const { asker } = read8.data;
|
|
24964
|
+
return typeof asker === "string" ? asker : null;
|
|
24965
|
+
}
|
|
24966
|
+
};
|
|
24932
24967
|
var HOLDS2 = "holds";
|
|
24933
24968
|
var INVITED = "invited";
|
|
24934
24969
|
var GRANTED = "granted";
|
|
@@ -24937,7 +24972,7 @@ var FULL = "the lobe holds all its `space` allows: come back once it holds less,
|
|
|
24937
24972
|
var WAITING = "the node holds all the invitations waiting it may: come back once one is knocked, lapses or ends, or an owner's word moves its `invitations`";
|
|
24938
24973
|
var spaceOver = (gear) => {
|
|
24939
24974
|
const { spaces, reader: reader4, limit, room: room2, core } = gear;
|
|
24940
|
-
const held2 = (node2) => spaces.bytes(node2) + (spaces.rows([BRAIN, HOLDS2, node2]) + spaces.rows([BRAIN, GRANTED, node2])) * RELATION;
|
|
24975
|
+
const held2 = (node2) => spaces.bytes(node2) + spaces.charged(node2) + (spaces.rows([BRAIN, HOLDS2, node2]) + spaces.rows([BRAIN, GRANTED, node2])) * RELATION;
|
|
24941
24976
|
const limitOf = (node2) => core(node2) ? LIFTED : limit("space", node2) ?? room2();
|
|
24942
24977
|
const growth = (writes) => writes.reduce(
|
|
24943
24978
|
(sum, { key: key2, value }) => sum + (value === null ? 0 : key2.length + value.length) - weightOver(reader4, key2),
|
|
@@ -25845,15 +25880,40 @@ var makeHistory = () => {
|
|
|
25845
25880
|
};
|
|
25846
25881
|
};
|
|
25847
25882
|
|
|
25883
|
+
var NONE_CHARGED = { prefixes: [], of: () => null };
|
|
25848
25884
|
var lastWrites2 = (batches) => [
|
|
25849
25885
|
...new Map(batches.flat().map((write2) => [hex(write2.key), write2])).values()
|
|
25850
25886
|
];
|
|
25851
25887
|
var added2 = (moved3, name2, by) => {
|
|
25852
25888
|
moved3.set(name2, (moved3.get(name2) ?? 0) + by);
|
|
25853
25889
|
};
|
|
25854
|
-
var
|
|
25890
|
+
var PAGE6 = 256;
|
|
25891
|
+
var spacesOver = (store, counted2, charged2 = NONE_CHARGED) => {
|
|
25855
25892
|
const bytes7 = new Map();
|
|
25856
25893
|
const rows = new Map();
|
|
25894
|
+
let charges = null;
|
|
25895
|
+
const chargesOf = () => {
|
|
25896
|
+
if (charges !== null) return charges;
|
|
25897
|
+
const summed2 = new Map();
|
|
25898
|
+
unlessDamaged(() => {
|
|
25899
|
+
for (const prefix of charged2.prefixes) {
|
|
25900
|
+
const { from, to } = prefixRange(prefix);
|
|
25901
|
+
for (let after2 = null; ; ) {
|
|
25902
|
+
const pairs2 = store.range(from, to, PAGE6, after2);
|
|
25903
|
+
for (const pair2 of pairs2) {
|
|
25904
|
+
const found = keyOf2(pair2.key)?.key;
|
|
25905
|
+
const node2 = found === void 0 ? null : charged2.of(found, pair2.value);
|
|
25906
|
+
if (node2 !== null) added2(summed2, node2, weightOver(store, pair2.key));
|
|
25907
|
+
}
|
|
25908
|
+
if (pairs2.length < PAGE6) break;
|
|
25909
|
+
after2 = pairs2.at(-1)?.key ?? null;
|
|
25910
|
+
}
|
|
25911
|
+
}
|
|
25912
|
+
return null;
|
|
25913
|
+
}, null);
|
|
25914
|
+
charges = summed2;
|
|
25915
|
+
return summed2;
|
|
25916
|
+
};
|
|
25857
25917
|
const bytesOf6 = (partition) => {
|
|
25858
25918
|
const known = bytes7.get(partition);
|
|
25859
25919
|
if (known !== void 0) return known;
|
|
@@ -25874,9 +25934,11 @@ var spacesOver = (store, counted2) => {
|
|
|
25874
25934
|
return {
|
|
25875
25935
|
bytes: bytesOf6,
|
|
25876
25936
|
rows: rowsOf3,
|
|
25937
|
+
charged: (node2) => chargesOf().get(node2) ?? 0,
|
|
25877
25938
|
moving: (batches) => {
|
|
25878
25939
|
const movedBytes = new Map();
|
|
25879
25940
|
const movedRows = new Map();
|
|
25941
|
+
const movedCharged = new Map();
|
|
25880
25942
|
for (const { key: key2, value } of lastWrites2(batches)) {
|
|
25881
25943
|
const found = keyOf2(key2)?.key;
|
|
25882
25944
|
const partition = found?.[0];
|
|
@@ -25884,20 +25946,31 @@ var spacesOver = (store, counted2) => {
|
|
|
25884
25946
|
bytesOf6(partition);
|
|
25885
25947
|
const older = unlessDamaged(() => weightOver(store, key2), 0);
|
|
25886
25948
|
added2(movedBytes, partition, (value === null ? 0 : key2.length + value.length) - older);
|
|
25949
|
+
if (charged2.prefixes.some((prefix2) => prefix2.every((part, at) => found[at] === part))) {
|
|
25950
|
+
chargesOf();
|
|
25951
|
+
const was = older === 0 ? null : unlessDamaged(() => store.get(key2), null);
|
|
25952
|
+
const from = was === null ? null : charged2.of(found, was);
|
|
25953
|
+
const to = value === null ? null : charged2.of(found, value);
|
|
25954
|
+
if (from !== null) added2(movedCharged, from, -older);
|
|
25955
|
+
if (to !== null && value !== null) added2(movedCharged, to, key2.length + value.length);
|
|
25956
|
+
}
|
|
25887
25957
|
const prefix = counted2(found);
|
|
25888
25958
|
if (prefix === null) continue;
|
|
25889
25959
|
rowsOf3(prefix);
|
|
25890
25960
|
added2(movedRows, hex(keyBytes(prefix)), (value === null ? 0 : 1) - (older === 0 ? 0 : 1));
|
|
25891
25961
|
}
|
|
25892
|
-
return { bytes: movedBytes, rows: movedRows };
|
|
25962
|
+
return { bytes: movedBytes, rows: movedRows, charged: movedCharged };
|
|
25893
25963
|
},
|
|
25894
25964
|
landed: (moved3) => {
|
|
25895
25965
|
for (const [partition, by] of moved3.bytes) added2(bytes7, partition, by);
|
|
25896
25966
|
for (const [prefix, by] of moved3.rows) added2(rows, prefix, by);
|
|
25967
|
+
const summed2 = chargesOf();
|
|
25968
|
+
for (const [node2, by] of moved3.charged) added2(summed2, node2, by);
|
|
25897
25969
|
},
|
|
25898
25970
|
forget: () => {
|
|
25899
25971
|
bytes7.clear();
|
|
25900
25972
|
rows.clear();
|
|
25973
|
+
charges = null;
|
|
25901
25974
|
}
|
|
25902
25975
|
};
|
|
25903
25976
|
};
|
|
@@ -26014,7 +26087,7 @@ var commitOnce = async (parts, given2) => {
|
|
|
26014
26087
|
if (!("why" in answer) && landed4.length > 0) parts.watch?.shown(landed4, watched);
|
|
26015
26088
|
return answer;
|
|
26016
26089
|
};
|
|
26017
|
-
var makeCache = (store, bytes7, watch = null, counted2 = () => null) => {
|
|
26090
|
+
var makeCache = (store, bytes7, watch = null, counted2 = () => null, charged2 = NONE_CHARGED) => {
|
|
26018
26091
|
checkLimit2(bytes7);
|
|
26019
26092
|
const heat = { keys: new Map(), ceiling: bytes7, held: 0 };
|
|
26020
26093
|
const history = makeHistory();
|
|
@@ -26024,7 +26097,7 @@ var makeCache = (store, bytes7, watch = null, counted2 = () => null) => {
|
|
|
26024
26097
|
count: (from, to) => countOver(store, from, to),
|
|
26025
26098
|
nth: (from, to, index) => nthOver(store, from, to, index)
|
|
26026
26099
|
};
|
|
26027
|
-
const spaces = spacesOver(store, counted2);
|
|
26100
|
+
const spaces = spacesOver(store, counted2, charged2);
|
|
26028
26101
|
const parts = { store, watch, heat, history, spaces, reader: reader4, stopped: false, flight: null };
|
|
26029
26102
|
let line2 = Promise.resolve();
|
|
26030
26103
|
return {
|
|
@@ -26050,7 +26123,11 @@ var makeCache = (store, bytes7, watch = null, counted2 = () => null) => {
|
|
|
26050
26123
|
},
|
|
26051
26124
|
held: () => heat.held,
|
|
26052
26125
|
kept: () => history.count(),
|
|
26053
|
-
spaces: {
|
|
26126
|
+
spaces: {
|
|
26127
|
+
bytes: (partition) => spaces.bytes(partition),
|
|
26128
|
+
rows: (prefix) => spaces.rows(prefix),
|
|
26129
|
+
charged: (node2) => spaces.charged(node2)
|
|
26130
|
+
}
|
|
26054
26131
|
};
|
|
26055
26132
|
};
|
|
26056
26133
|
|
|
@@ -26637,7 +26714,7 @@ var metered = (store, committed2) => committed2 === void 0 ? store : {
|
|
|
26637
26714
|
var bodyOf2 = (given2, halves, store, thawed) => {
|
|
26638
26715
|
const configuration = worded(given2.configuration, () => reading2());
|
|
26639
26716
|
const told = presenceTold(configuration, given2.fills.crypto);
|
|
26640
|
-
const cache = makeCache(metered(store, given2.variant?.committed), CACHE, told.watch, countedRow);
|
|
26717
|
+
const cache = makeCache(metered(store, given2.variant?.committed), CACHE, told.watch, countedRow, chargedRows);
|
|
26641
26718
|
told.reads(cache);
|
|
26642
26719
|
const reading2 = () => cellsOf2(cache, BRAIN, false);
|
|
26643
26720
|
const clock = clockOver(given2.fills.time, keptIn2(reading2()), () => timer.at(clock.steady(), keepDropped));
|
|
@@ -27219,13 +27296,19 @@ var objectOf5 = (properties) => ({
|
|
|
27219
27296
|
var listOf = (items) => ({ type: "array", items });
|
|
27220
27297
|
var FROZEN = objectOf5({
|
|
27221
27298
|
genome: text6,
|
|
27222
|
-
store:
|
|
27223
|
-
|
|
27224
|
-
|
|
27225
|
-
|
|
27226
|
-
|
|
27227
|
-
|
|
27228
|
-
|
|
27299
|
+
store: {
|
|
27300
|
+
type: "object",
|
|
27301
|
+
properties: {
|
|
27302
|
+
key: bytes6,
|
|
27303
|
+
sequence: count3,
|
|
27304
|
+
end: count3,
|
|
27305
|
+
slot: { enum: [0, 1] },
|
|
27306
|
+
sealed: count3,
|
|
27307
|
+
pairs: listOf(objectOf5({ key: bytes6, value: bytes6 }))
|
|
27308
|
+
},
|
|
27309
|
+
required: ["key", "sequence", "end", "slot", "pairs"],
|
|
27310
|
+
additionalProperties: false
|
|
27311
|
+
},
|
|
27229
27312
|
alarms: listOf(objectOf5({ kind: { enum: ["wake", "booting", "expiry"] }, at: { type: "number", minimum: 0 } })),
|
|
27230
27313
|
bounds: listOf(objectOf5({ far: text6, bound: count3 })),
|
|
27231
27314
|
carry: objectOf5({
|
|
@@ -30327,7 +30410,7 @@ var tried = async (storage, version2, trial2) => {
|
|
|
30327
30410
|
return null;
|
|
30328
30411
|
};
|
|
30329
30412
|
|
|
30330
|
-
var INSTALLER_VERSION = "0.37.
|
|
30413
|
+
var INSTALLER_VERSION = "0.37.6";
|
|
30331
30414
|
|
|
30332
30415
|
var BACKUP2 = "primordial.backup";
|
|
30333
30416
|
var LAID = "nervur_laid";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nervur.org/installer-node",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.6",
|
|
4
4
|
"description": "Nervur's installer for Node: the nervur command, the door, the host's organs (console, shell, disk, network) with their blueprints. 0.x, unstable.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@nervur.org/floor": "0.37.
|
|
40
|
-
"@nervur.org/genome": "0.37.
|
|
39
|
+
"@nervur.org/floor": "0.37.6",
|
|
40
|
+
"@nervur.org/genome": "0.37.6"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=22.23.5"
|
package/src/command/given.js
CHANGED
package/src/fills/keepers.js
CHANGED
package/src/organism/folder.js
CHANGED
package/src/version/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// SPDX-License-Identifier: FSL-1.1-ALv2
|
|
2
|
-
export const INSTALLER_VERSION = '0.37.
|
|
2
|
+
export const INSTALLER_VERSION = '0.37.6';
|