@nervur.org/installer-browser 0.37.5 → 0.37.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{dd4624a345fac21d4ead32dece3b2ef0b3cbec65dd20c7324b415094861265b5 → 9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c}/page.js +3 -3
- package/dist/{dd4624a345fac21d4ead32dece3b2ef0b3cbec65dd20c7324b415094861265b5 → 9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c}/worker.js +120 -42
- package/dist/keeper.js +1 -1
- package/dist/manifest.json +11 -11
- package/dist/page.js +1 -1
- package/dist/quo.json +5 -5
- package/package.json +1 -1
- /package/dist/{dd4624a345fac21d4ead32dece3b2ef0b3cbec65dd20c7324b415094861265b5 → 9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c}/emscripten-module.wasm +0 -0
- /package/dist/{dd4624a345fac21d4ead32dece3b2ef0b3cbec65dd20c7324b415094861265b5 → 9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c}/sqlite3.wasm +0 -0
|
@@ -2628,7 +2628,7 @@ const sharedPort = (tabs ) => {
|
|
|
2628
2628
|
|
|
2629
2629
|
|
|
2630
2630
|
|
|
2631
|
-
|
|
2631
|
+
|
|
2632
2632
|
|
|
2633
2633
|
|
|
2634
2634
|
|
|
@@ -2981,7 +2981,7 @@ const stagedIn = async (made , target )
|
|
|
2981
2981
|
|
|
2982
2982
|
|
|
2983
2983
|
|
|
2984
|
-
|
|
2984
|
+
|
|
2985
2985
|
|
|
2986
2986
|
|
|
2987
2987
|
|
|
@@ -3158,7 +3158,7 @@ const SAID = 'store';
|
|
|
3158
3158
|
|
|
3159
3159
|
|
|
3160
3160
|
|
|
3161
|
-
|
|
3161
|
+
|
|
3162
3162
|
|
|
3163
3163
|
|
|
3164
3164
|
|
|
@@ -2620,7 +2620,7 @@ var checkBlueprint = (value, node2, longest) => {
|
|
|
2620
2620
|
};
|
|
2621
2621
|
};
|
|
2622
2622
|
|
|
2623
|
-
var GENOME_VERSION = "0.37.
|
|
2623
|
+
var GENOME_VERSION = "0.37.7";
|
|
2624
2624
|
|
|
2625
2625
|
var endFrame = (asker, method3) => ({ end: { asker, method: method3 } });
|
|
2626
2626
|
|
|
@@ -3577,7 +3577,7 @@ var keepHalf = (gear, id, host, connected, added3, failed2) => {
|
|
|
3577
3577
|
|
|
3578
3578
|
var EAR_BLUEPRINT = {
|
|
3579
3579
|
name: "nervur.ear",
|
|
3580
|
-
version: "0.37.
|
|
3580
|
+
version: "0.37.7",
|
|
3581
3581
|
description: "The ear: it opens and seals the boxes of Quo, and the brain keeps every relation.",
|
|
3582
3582
|
methods: {
|
|
3583
3583
|
arrived: {
|
|
@@ -4146,13 +4146,13 @@ var readFaculty = (engine, crypto2, source, memory) => {
|
|
|
4146
4146
|
};
|
|
4147
4147
|
var facultyReaderOn = (engine, crypto2, memory) => (source) => readFaculty(engine.apart(), crypto2, source, memory);
|
|
4148
4148
|
|
|
4149
|
-
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}";
|
|
4149
|
+
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.7',\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}";
|
|
4150
4150
|
|
|
4151
4151
|
var EAR_SOURCE = facultySource(EAR_TEXT);
|
|
4152
4152
|
|
|
4153
4153
|
var MOUTH_BLUEPRINT = {
|
|
4154
4154
|
name: "nervur.mouth",
|
|
4155
|
-
version: "0.37.
|
|
4155
|
+
version: "0.37.7",
|
|
4156
4156
|
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.",
|
|
4157
4157
|
methods: {
|
|
4158
4158
|
accept: {
|
|
@@ -4310,7 +4310,7 @@ var MOUTH_BLUEPRINT = {
|
|
|
4310
4310
|
placeholders: { brain: "nervur.brain", network: "nervur.network", key: "nervur.key" }
|
|
4311
4311
|
};
|
|
4312
4312
|
|
|
4313
|
-
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}";
|
|
4313
|
+
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.7',\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}";
|
|
4314
4314
|
|
|
4315
4315
|
var MOUTH_SOURCE = facultySource(MOUTH_TEXT);
|
|
4316
4316
|
|
|
@@ -5614,7 +5614,7 @@ var Library = class _Library extends Faculty {
|
|
|
5614
5614
|
|
|
5615
5615
|
var LIBRARY_BLUEPRINT = {
|
|
5616
5616
|
name: "nervur.library",
|
|
5617
|
-
version: "0.37.
|
|
5617
|
+
version: "0.37.7",
|
|
5618
5618
|
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.",
|
|
5619
5619
|
methods: {
|
|
5620
5620
|
add: {
|
|
@@ -5871,13 +5871,13 @@ var LIBRARY_BLUEPRINT = {
|
|
|
5871
5871
|
placeholders: { brain: "nervur.brain", mouth: "nervur.mouth", ear: "nervur.ear" }
|
|
5872
5872
|
};
|
|
5873
5873
|
|
|
5874
|
-
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}";
|
|
5874
|
+
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.7',\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}";
|
|
5875
5875
|
|
|
5876
5876
|
var LIBRARY_SOURCE = facultySource(LIBRARY_TEXT);
|
|
5877
5877
|
|
|
5878
5878
|
var SCHEDULER_BLUEPRINT = {
|
|
5879
5879
|
name: "nervur.scheduler",
|
|
5880
|
-
version: "0.37.
|
|
5880
|
+
version: "0.37.7",
|
|
5881
5881
|
description: "The scheduler: every lobe's alarms, over the brain's one durable wake.",
|
|
5882
5882
|
methods: {
|
|
5883
5883
|
set: {
|
|
@@ -5961,7 +5961,7 @@ var SCHEDULER_BLUEPRINT = {
|
|
|
5961
5961
|
placeholders: { brain: "nervur.brain", cage: "nervur.cage" }
|
|
5962
5962
|
};
|
|
5963
5963
|
|
|
5964
|
-
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}";
|
|
5964
|
+
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.7',\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}";
|
|
5965
5965
|
|
|
5966
5966
|
var SCHEDULER_SOURCE = facultySource(SCHEDULER_TEXT);
|
|
5967
5967
|
|
|
@@ -14595,11 +14595,11 @@ var swept = (outside2, named7) => {
|
|
|
14595
14595
|
if (!named7.has(file) && !outside2.laid.has(file)) outside2.pages.remove(file);
|
|
14596
14596
|
};
|
|
14597
14597
|
|
|
14598
|
-
var PAGE4 = 8192;
|
|
14599
14598
|
var LOG_HEADER = 32;
|
|
14599
|
+
var AT_PAGE_SIZE = 8;
|
|
14600
|
+
var PAGE_SIZES = [512, 1024, 2048, 4096, 8192, 16384, 32768, 65536];
|
|
14600
14601
|
var SUMMED_HEADER = 24;
|
|
14601
14602
|
var FRAME_HEADER = 24;
|
|
14602
|
-
var FRAME = FRAME_HEADER + PAGE4;
|
|
14603
14603
|
var SALTS = 8;
|
|
14604
14604
|
var SALTS_END = 16;
|
|
14605
14605
|
var SUMS_SIZE = 8;
|
|
@@ -14645,8 +14645,12 @@ var oneByteAway = (content, sums, stored) => {
|
|
|
14645
14645
|
}
|
|
14646
14646
|
return false;
|
|
14647
14647
|
};
|
|
14648
|
+
var pageSizeOf = (header) => {
|
|
14649
|
+
const named7 = viewOf(header).getUint32(AT_PAGE_SIZE);
|
|
14650
|
+
return PAGE_SIZES.find((size) => size === named7) ?? null;
|
|
14651
|
+
};
|
|
14648
14652
|
var summedOf = (frame) => {
|
|
14649
|
-
const content = new Uint8Array(
|
|
14653
|
+
const content = new Uint8Array(frame.length - FRAME_HEADER + 8);
|
|
14650
14654
|
content.set(frame.subarray(0, 8));
|
|
14651
14655
|
content.set(frame.subarray(FRAME_HEADER), 8);
|
|
14652
14656
|
return content;
|
|
@@ -14667,14 +14671,21 @@ var damagedLog = (log) => {
|
|
|
14667
14671
|
const sums = summed([0, 0], content);
|
|
14668
14672
|
const whole2 = same(sums, stored);
|
|
14669
14673
|
if (!whole2 && (oneOff(sums, stored) || oneByteAway(content, sums, stored))) return true;
|
|
14674
|
+
if (!whole2) return PAGE_SIZES.some((page2) => damagedFrames(log, header, false, page2));
|
|
14675
|
+
const page = pageSizeOf(header);
|
|
14676
|
+
return page === null || damagedFrames(log, header, true, page);
|
|
14677
|
+
};
|
|
14678
|
+
var damagedFrames = (log, header, whole2, page) => {
|
|
14679
|
+
const stored = header.subarray(SUMMED_HEADER);
|
|
14680
|
+
const size = FRAME_HEADER + page;
|
|
14670
14681
|
let seed = sumsOf(stored);
|
|
14671
14682
|
let salts = whole2 ? header.subarray(16, SUMMED_HEADER) : null;
|
|
14672
14683
|
let past = !whole2;
|
|
14673
14684
|
let ended5 = false;
|
|
14674
14685
|
let pad = false;
|
|
14675
|
-
const frames = Math.floor((log.size() - LOG_HEADER) /
|
|
14686
|
+
const frames = Math.floor((log.size() - LOG_HEADER) / size);
|
|
14676
14687
|
for (let at2 = 0; at2 < frames; at2 += 1) {
|
|
14677
|
-
const frame = log.read(LOG_HEADER + at2 *
|
|
14688
|
+
const frame = log.read(LOG_HEADER + at2 * size, size);
|
|
14678
14689
|
salts ??= frame.slice(SALTS, SALTS_END);
|
|
14679
14690
|
const stands3 = differing(salts, frame.subarray(SALTS, SALTS_END)) === 0 && same(summed(seed, summedOf(frame)), frame.subarray(SALTS_END, FRAME_HEADER));
|
|
14680
14691
|
const padding = pad;
|
|
@@ -14691,7 +14702,7 @@ var damagedLog = (log) => {
|
|
|
14691
14702
|
if (!stands3) ended5 = false;
|
|
14692
14703
|
if (commits) {
|
|
14693
14704
|
ended5 = true;
|
|
14694
|
-
pad = (LOG_HEADER + (at2 + 1) *
|
|
14705
|
+
pad = (LOG_HEADER + (at2 + 1) * size) % SECTOR !== 0;
|
|
14695
14706
|
}
|
|
14696
14707
|
}
|
|
14697
14708
|
return false;
|
|
@@ -15433,6 +15444,9 @@ var ADDITIONAL = utf8Bytes("nervur log record");
|
|
|
15433
15444
|
|
|
15434
15445
|
var HEAD2 = 1 + 8 + 4;
|
|
15435
15446
|
|
|
15447
|
+
var RESEAL = 2 ** 31;
|
|
15448
|
+
var MOST_SEALED = 2 ** 32 - 2 ** 20;
|
|
15449
|
+
|
|
15436
15450
|
var COMPACT_AT = 1 << 20;
|
|
15437
15451
|
|
|
15438
15452
|
var VITAL = [BRAIN, KEY2, EAR].map((lobe) => prefixRange([lobe]));
|
|
@@ -15463,7 +15477,7 @@ var subtracted = (one, other) => {
|
|
|
15463
15477
|
};
|
|
15464
15478
|
var hexOf = (sum) => sum.map((limb) => limb.toString(16).padStart(4, "0")).join("");
|
|
15465
15479
|
|
|
15466
|
-
var
|
|
15480
|
+
var PAGE4 = 256;
|
|
15467
15481
|
var UNREAD = "f".repeat(64);
|
|
15468
15482
|
var partitionOf = (key2) => {
|
|
15469
15483
|
const first = keyOf2(key2)?.key[0];
|
|
@@ -15481,10 +15495,10 @@ var wholeOf = (reader3, crypto2, partition) => {
|
|
|
15481
15495
|
let sum = ZERO;
|
|
15482
15496
|
let after2 = null;
|
|
15483
15497
|
for (; ; ) {
|
|
15484
|
-
const page = reader3.range(from, to,
|
|
15498
|
+
const page = reader3.range(from, to, PAGE4, after2);
|
|
15485
15499
|
for (const { key: key2, value } of page) sum = added(sum, cellOf2(crypto2, key2, value));
|
|
15486
15500
|
const last = page.at(-1);
|
|
15487
|
-
if (page.length <
|
|
15501
|
+
if (page.length < PAGE4 || last === void 0) return sum;
|
|
15488
15502
|
after2 = last.key;
|
|
15489
15503
|
}
|
|
15490
15504
|
};
|
|
@@ -17009,6 +17023,7 @@ var drawRecordKey = (cells, chance) => {
|
|
|
17009
17023
|
};
|
|
17010
17024
|
|
|
17011
17025
|
var LIFTED = Number.MAX_SAFE_INTEGER;
|
|
17026
|
+
var NOTE_LIMIT = 4096;
|
|
17012
17027
|
var TREE_CAPS = ["nodes", "depth", "key", "text", "sounds"];
|
|
17013
17028
|
var OF_A_LOBE = new Set([
|
|
17014
17029
|
"longestBudget",
|
|
@@ -20232,7 +20247,9 @@ var cutOff2 = (hold4, held, message, why) => {
|
|
|
20232
20247
|
var ended2 = (hold4, held, ending) => {
|
|
20233
20248
|
if ("answered" in ending) {
|
|
20234
20249
|
const writes = held.cells?.batch() ?? [];
|
|
20235
|
-
const
|
|
20250
|
+
const judged2 = [...writes, ...held.posted];
|
|
20251
|
+
const posted2 = held.posted.reduce((sum, { key: key2, value }) => sum + key2.length + (value?.length ?? 0), 0);
|
|
20252
|
+
const full = judged2.length === 0 ? null : hold4.gear.refused?.(held.lobe, judged2, (held.cells?.held() ?? 0) + posted2) ?? null;
|
|
20236
20253
|
if (full !== null) return settle4(hold4, held, error("busy", full), []);
|
|
20237
20254
|
ringAgain(hold4, held, ending.answered, enqueue(hold4));
|
|
20238
20255
|
settle4(hold4, held, ending.answered, [...writes, ...held.taken, ...postedBy(hold4, held)]);
|
|
@@ -20761,7 +20778,6 @@ var toldSilent = (kit, far, since) => {
|
|
|
20761
20778
|
});
|
|
20762
20779
|
};
|
|
20763
20780
|
|
|
20764
|
-
var NOTE_LIMIT = 4096;
|
|
20765
20781
|
var noteIn = (args) => args["note"] ?? null;
|
|
20766
20782
|
var noteMost = (cells, lobe) => limitIn(cells, "note", lobe) ?? NOTE_LIMIT;
|
|
20767
20783
|
var sizeOf2 = (data) => utf8Bytes(dataText(data)).length;
|
|
@@ -21802,8 +21818,10 @@ var move = (kit, asker, fields, { done: done2, settled: settled3 }) => {
|
|
|
21802
21818
|
void kit.gear.backup(naming, told2).then(sealed, (thrown2) => broke2(thrownText2(thrown2)));
|
|
21803
21819
|
});
|
|
21804
21820
|
};
|
|
21805
|
-
var lastPiece = (kit, leaving2, bytes7, { done: done2, joined: joined10 }) => {
|
|
21806
|
-
const heirs = everyRelation(kit.gear.cells()).flatMap(
|
|
21821
|
+
var lastPiece = (kit, asker, leaving2, bytes7, { done: done2, joined: joined10 }) => {
|
|
21822
|
+
const heirs = everyRelation(kit.gear.cells()).flatMap(
|
|
21823
|
+
({ heir, node: node2, far }) => node2 === BRAIN && far === asker ? [heir] : []
|
|
21824
|
+
);
|
|
21807
21825
|
const ending = kit.gear.backupEnd({ bytes: bytes7, heirs, joined: joined10 });
|
|
21808
21826
|
void ending.then(
|
|
21809
21827
|
(ended5) => {
|
|
@@ -21827,7 +21845,7 @@ var lastPiece = (kit, leaving2, bytes7, { done: done2, joined: joined10 }) => {
|
|
|
21827
21845
|
(thrown2) => done2(error("refused", thrownText2(thrown2)))
|
|
21828
21846
|
);
|
|
21829
21847
|
};
|
|
21830
|
-
var backupPiece = (kit, fields, reply2) => {
|
|
21848
|
+
var backupPiece = (kit, asker, fields, reply2) => {
|
|
21831
21849
|
const asked3 = { mark: textAt2(fields, "mark"), at: numberAt2(fields, "at"), length: numberAt2(fields, "length") };
|
|
21832
21850
|
const found = kit.leaving.current;
|
|
21833
21851
|
const leaving2 = found !== null && asked3.mark === found.mark ? found : null;
|
|
@@ -21836,7 +21854,7 @@ var backupPiece = (kit, fields, reply2) => {
|
|
|
21836
21854
|
return kit.gear.leave(NOT_SEALED);
|
|
21837
21855
|
}
|
|
21838
21856
|
if (leaving2 !== null && leaving2.bytes !== null && asked3.at === leaving2.bytes)
|
|
21839
|
-
return lastPiece(kit, leaving2, leaving2.bytes, reply2);
|
|
21857
|
+
return lastPiece(kit, asker, leaving2, leaving2.bytes, reply2);
|
|
21840
21858
|
void kit.gear.backupPiece(asked3).then((taken2) => {
|
|
21841
21859
|
if ("why" in taken2) return reply2.settled(error("refused", taken2.why));
|
|
21842
21860
|
const { piece: piece3, made: made2 } = taken2;
|
|
@@ -22299,7 +22317,7 @@ var recoveryKeys = (kit, args, { done: done2, joined: joined10 }) => {
|
|
|
22299
22317
|
kit.change(setChange(kit.gear, listAt2(args, "keys")), done2, joined10);
|
|
22300
22318
|
};
|
|
22301
22319
|
|
|
22302
|
-
var
|
|
22320
|
+
var PAGE5 = 64;
|
|
22303
22321
|
var offsetOf = (cursor) => {
|
|
22304
22322
|
if (cursor === void 0) return 0;
|
|
22305
22323
|
return /^(0|[1-9]\d{0,15})$/.test(cursor) ? Number(cursor) : null;
|
|
@@ -22308,9 +22326,9 @@ var pageOf3 = (sizes, offset) => {
|
|
|
22308
22326
|
const [nodes, letters, durables, alarms] = sizes;
|
|
22309
22327
|
const cut = (size, before4) => {
|
|
22310
22328
|
const from = Math.max(0, offset - before4);
|
|
22311
|
-
return { from, count: Math.max(0, Math.min(size, offset +
|
|
22329
|
+
return { from, count: Math.max(0, Math.min(size, offset + PAGE5 - before4) - from) };
|
|
22312
22330
|
};
|
|
22313
|
-
const next = offset +
|
|
22331
|
+
const next = offset + PAGE5;
|
|
22314
22332
|
return {
|
|
22315
22333
|
cuts: [cut(nodes, 0), cut(letters, nodes), cut(durables, nodes + letters), cut(alarms, nodes + letters + durables)],
|
|
22316
22334
|
cursor: next < nodes + letters + durables + alarms ? String(next) : null
|
|
@@ -24419,7 +24437,7 @@ var HANDLERS = {
|
|
|
24419
24437
|
joined10
|
|
24420
24438
|
),
|
|
24421
24439
|
move: (kit, asker, fields, reply2) => move(kit, asker, fields, reply2),
|
|
24422
|
-
backupPiece: (kit,
|
|
24440
|
+
backupPiece: (kit, asker, fields, reply2) => backupPiece(kit, asker, fields, reply2),
|
|
24423
24441
|
upgrade: (kit, _asker, fields, { settled: settled3 }) => upgrade(kit.gear, fields, settled3),
|
|
24424
24442
|
state: (kit, asker, fields, { settled: settled3, binds }) => {
|
|
24425
24443
|
const cursor = typeof fields["cursor"] === "string" ? fields["cursor"] : void 0;
|
|
@@ -24995,7 +25013,7 @@ var keepGenome = (cells) => {
|
|
|
24995
25013
|
};
|
|
24996
25014
|
if (isLater(FLOOR, kept3))
|
|
24997
25015
|
return {
|
|
24998
|
-
why: `the store was last booted by genome ${kept3}, below ${FLOOR}, the oldest this genome ${GENOME_VERSION} carries forward:
|
|
25016
|
+
why: `the store was last booted by genome ${kept3}, below ${FLOOR}, the oldest this genome ${GENOME_VERSION} carries forward: update it to ${FLOOR} first`
|
|
24999
25017
|
};
|
|
25000
25018
|
if (kept3 !== GENOME_VERSION) putRow(cells, ROW4, GENOME_VERSION, "brain");
|
|
25001
25019
|
return null;
|
|
@@ -25045,7 +25063,24 @@ var makeReflex = (gear, thawed) => {
|
|
|
25045
25063
|
};
|
|
25046
25064
|
};
|
|
25047
25065
|
|
|
25048
|
-
var RELATION =
|
|
25066
|
+
var RELATION = 4096;
|
|
25067
|
+
var chargedRows = {
|
|
25068
|
+
prefixes: [
|
|
25069
|
+
[BRAIN, "holds"],
|
|
25070
|
+
[BRAIN, "grant"],
|
|
25071
|
+
[BRAIN, "letter"],
|
|
25072
|
+
[BRAIN, "dead"]
|
|
25073
|
+
],
|
|
25074
|
+
of: (key2, value) => {
|
|
25075
|
+
const [, row, first, second] = key2;
|
|
25076
|
+
if (row === "holds") return typeof first === "string" ? first : null;
|
|
25077
|
+
if (row === "grant") return typeof second === "string" ? second : null;
|
|
25078
|
+
const read9 = dataOfBytes(value);
|
|
25079
|
+
if ("why" in read9 || !isFields(read9.data)) return null;
|
|
25080
|
+
const { asker } = read9.data;
|
|
25081
|
+
return typeof asker === "string" ? asker : null;
|
|
25082
|
+
}
|
|
25083
|
+
};
|
|
25049
25084
|
var HOLDS2 = "holds";
|
|
25050
25085
|
var INVITED = "invited";
|
|
25051
25086
|
var GRANTED = "granted";
|
|
@@ -25054,7 +25089,7 @@ var FULL = "the lobe holds all its `space` allows: come back once it holds less,
|
|
|
25054
25089
|
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`";
|
|
25055
25090
|
var spaceOver = (gear) => {
|
|
25056
25091
|
const { spaces, reader: reader3, limit, room: room2, core } = gear;
|
|
25057
|
-
const held = (node2) => spaces.bytes(node2) + (spaces.rows([BRAIN, HOLDS2, node2]) + spaces.rows([BRAIN, GRANTED, node2])) * RELATION;
|
|
25092
|
+
const held = (node2) => spaces.bytes(node2) + spaces.charged(node2) + (spaces.rows([BRAIN, HOLDS2, node2]) + spaces.rows([BRAIN, GRANTED, node2])) * RELATION;
|
|
25058
25093
|
const limitOf = (node2) => core(node2) ? LIFTED : limit("space", node2) ?? room2();
|
|
25059
25094
|
const growth = (writes) => writes.reduce(
|
|
25060
25095
|
(sum, { key: key2, value }) => sum + (value === null ? 0 : key2.length + value.length) - weightOver(reader3, key2),
|
|
@@ -25962,15 +25997,40 @@ var makeHistory = () => {
|
|
|
25962
25997
|
};
|
|
25963
25998
|
};
|
|
25964
25999
|
|
|
26000
|
+
var NONE_CHARGED = { prefixes: [], of: () => null };
|
|
25965
26001
|
var lastWrites2 = (batches) => [
|
|
25966
26002
|
...new Map(batches.flat().map((write2) => [hex(write2.key), write2])).values()
|
|
25967
26003
|
];
|
|
25968
26004
|
var added2 = (moved3, name2, by) => {
|
|
25969
26005
|
moved3.set(name2, (moved3.get(name2) ?? 0) + by);
|
|
25970
26006
|
};
|
|
25971
|
-
var
|
|
26007
|
+
var PAGE6 = 256;
|
|
26008
|
+
var spacesOver = (store, counted2, charged2 = NONE_CHARGED) => {
|
|
25972
26009
|
const bytes7 = new Map();
|
|
25973
26010
|
const rows = new Map();
|
|
26011
|
+
let charges = null;
|
|
26012
|
+
const chargesOf = () => {
|
|
26013
|
+
if (charges !== null) return charges;
|
|
26014
|
+
const summed2 = new Map();
|
|
26015
|
+
unlessDamaged(() => {
|
|
26016
|
+
for (const prefix of charged2.prefixes) {
|
|
26017
|
+
const { from, to } = prefixRange(prefix);
|
|
26018
|
+
for (let after2 = null; ; ) {
|
|
26019
|
+
const pairs2 = store.range(from, to, PAGE6, after2);
|
|
26020
|
+
for (const pair of pairs2) {
|
|
26021
|
+
const found = keyOf2(pair.key)?.key;
|
|
26022
|
+
const node2 = found === void 0 ? null : charged2.of(found, pair.value);
|
|
26023
|
+
if (node2 !== null) added2(summed2, node2, weightOver(store, pair.key));
|
|
26024
|
+
}
|
|
26025
|
+
if (pairs2.length < PAGE6) break;
|
|
26026
|
+
after2 = pairs2.at(-1)?.key ?? null;
|
|
26027
|
+
}
|
|
26028
|
+
}
|
|
26029
|
+
return null;
|
|
26030
|
+
}, null);
|
|
26031
|
+
charges = summed2;
|
|
26032
|
+
return summed2;
|
|
26033
|
+
};
|
|
25974
26034
|
const bytesOf7 = (partition) => {
|
|
25975
26035
|
const known = bytes7.get(partition);
|
|
25976
26036
|
if (known !== void 0) return known;
|
|
@@ -25991,9 +26051,11 @@ var spacesOver = (store, counted2) => {
|
|
|
25991
26051
|
return {
|
|
25992
26052
|
bytes: bytesOf7,
|
|
25993
26053
|
rows: rowsOf3,
|
|
26054
|
+
charged: (node2) => chargesOf().get(node2) ?? 0,
|
|
25994
26055
|
moving: (batches) => {
|
|
25995
26056
|
const movedBytes = new Map();
|
|
25996
26057
|
const movedRows = new Map();
|
|
26058
|
+
const movedCharged = new Map();
|
|
25997
26059
|
for (const { key: key2, value } of lastWrites2(batches)) {
|
|
25998
26060
|
const found = keyOf2(key2)?.key;
|
|
25999
26061
|
const partition = found?.[0];
|
|
@@ -26001,20 +26063,31 @@ var spacesOver = (store, counted2) => {
|
|
|
26001
26063
|
bytesOf7(partition);
|
|
26002
26064
|
const older = unlessDamaged(() => weightOver(store, key2), 0);
|
|
26003
26065
|
added2(movedBytes, partition, (value === null ? 0 : key2.length + value.length) - older);
|
|
26066
|
+
if (charged2.prefixes.some((prefix2) => prefix2.every((part, at2) => found[at2] === part))) {
|
|
26067
|
+
chargesOf();
|
|
26068
|
+
const was = older === 0 ? null : unlessDamaged(() => store.get(key2), null);
|
|
26069
|
+
const from = was === null ? null : charged2.of(found, was);
|
|
26070
|
+
const to = value === null ? null : charged2.of(found, value);
|
|
26071
|
+
if (from !== null) added2(movedCharged, from, -older);
|
|
26072
|
+
if (to !== null && value !== null) added2(movedCharged, to, key2.length + value.length);
|
|
26073
|
+
}
|
|
26004
26074
|
const prefix = counted2(found);
|
|
26005
26075
|
if (prefix === null) continue;
|
|
26006
26076
|
rowsOf3(prefix);
|
|
26007
26077
|
added2(movedRows, hex(keyBytes(prefix)), (value === null ? 0 : 1) - (older === 0 ? 0 : 1));
|
|
26008
26078
|
}
|
|
26009
|
-
return { bytes: movedBytes, rows: movedRows };
|
|
26079
|
+
return { bytes: movedBytes, rows: movedRows, charged: movedCharged };
|
|
26010
26080
|
},
|
|
26011
26081
|
landed: (moved3) => {
|
|
26012
26082
|
for (const [partition, by] of moved3.bytes) added2(bytes7, partition, by);
|
|
26013
26083
|
for (const [prefix, by] of moved3.rows) added2(rows, prefix, by);
|
|
26084
|
+
const summed2 = chargesOf();
|
|
26085
|
+
for (const [node2, by] of moved3.charged) added2(summed2, node2, by);
|
|
26014
26086
|
},
|
|
26015
26087
|
forget: () => {
|
|
26016
26088
|
bytes7.clear();
|
|
26017
26089
|
rows.clear();
|
|
26090
|
+
charges = null;
|
|
26018
26091
|
}
|
|
26019
26092
|
};
|
|
26020
26093
|
};
|
|
@@ -26131,7 +26204,7 @@ var commitOnce = async (parts, given2) => {
|
|
|
26131
26204
|
if (!("why" in answer) && landed5.length > 0) parts.watch?.shown(landed5, watched);
|
|
26132
26205
|
return answer;
|
|
26133
26206
|
};
|
|
26134
|
-
var makeCache = (store, bytes7, watch = null, counted2 = () => null) => {
|
|
26207
|
+
var makeCache = (store, bytes7, watch = null, counted2 = () => null, charged2 = NONE_CHARGED) => {
|
|
26135
26208
|
checkLimit2(bytes7);
|
|
26136
26209
|
const heat = { keys: new Map(), ceiling: bytes7, held: 0 };
|
|
26137
26210
|
const history = makeHistory();
|
|
@@ -26141,7 +26214,7 @@ var makeCache = (store, bytes7, watch = null, counted2 = () => null) => {
|
|
|
26141
26214
|
count: (from, to) => countOver(store, from, to),
|
|
26142
26215
|
nth: (from, to, index) => nthOver(store, from, to, index)
|
|
26143
26216
|
};
|
|
26144
|
-
const spaces = spacesOver(store, counted2);
|
|
26217
|
+
const spaces = spacesOver(store, counted2, charged2);
|
|
26145
26218
|
const parts = { store, watch, heat, history, spaces, reader: reader3, stopped: false, flight: null };
|
|
26146
26219
|
let line2 = Promise.resolve();
|
|
26147
26220
|
return {
|
|
@@ -26167,7 +26240,11 @@ var makeCache = (store, bytes7, watch = null, counted2 = () => null) => {
|
|
|
26167
26240
|
},
|
|
26168
26241
|
held: () => heat.held,
|
|
26169
26242
|
kept: () => history.count(),
|
|
26170
|
-
spaces: {
|
|
26243
|
+
spaces: {
|
|
26244
|
+
bytes: (partition) => spaces.bytes(partition),
|
|
26245
|
+
rows: (prefix) => spaces.rows(prefix),
|
|
26246
|
+
charged: (node2) => spaces.charged(node2)
|
|
26247
|
+
}
|
|
26171
26248
|
};
|
|
26172
26249
|
};
|
|
26173
26250
|
|
|
@@ -26754,7 +26831,7 @@ var metered = (store, committed2) => committed2 === void 0 ? store : {
|
|
|
26754
26831
|
var bodyOf = (given2, halves, store, thawed) => {
|
|
26755
26832
|
const configuration = worded(given2.configuration, () => reading3());
|
|
26756
26833
|
const told2 = presenceTold(configuration, given2.fills.crypto);
|
|
26757
|
-
const cache = makeCache(metered(store, given2.variant?.committed), CACHE, told2.watch, countedRow);
|
|
26834
|
+
const cache = makeCache(metered(store, given2.variant?.committed), CACHE, told2.watch, countedRow, chargedRows);
|
|
26758
26835
|
told2.reads(cache);
|
|
26759
26836
|
const reading3 = () => cellsOf2(cache, BRAIN, false);
|
|
26760
26837
|
const clock = clockOver(given2.fills.time, keptIn2(reading3()), () => timer.at(clock.steady(), keepDropped));
|
|
@@ -27342,6 +27419,7 @@ var FROZEN = objectOf5({
|
|
|
27342
27419
|
sequence: count3,
|
|
27343
27420
|
end: count3,
|
|
27344
27421
|
slot: { enum: [0, 1] },
|
|
27422
|
+
sealed: count3,
|
|
27345
27423
|
pairs: listOf(objectOf5({ key: bytes6, value: bytes6 }))
|
|
27346
27424
|
}),
|
|
27347
27425
|
alarms: listOf(objectOf5({ kind: { enum: ["wake", "booting", "expiry"] }, at: { type: "number", minimum: 0 } })),
|
|
@@ -27409,7 +27487,7 @@ var FLOOR_FILES = [
|
|
|
27409
27487
|
"design.json",
|
|
27410
27488
|
`{
|
|
27411
27489
|
"name": "floor",
|
|
27412
|
-
"version": "0.37.
|
|
27490
|
+
"version": "0.37.7",
|
|
27413
27491
|
"publisher": "nervur",
|
|
27414
27492
|
"description": "The genome's one design: plain, clean and accessible, host-agnostic, given away with the packages. Its look is the describe look.",
|
|
27415
27493
|
"languages": [
|
|
@@ -27542,7 +27620,7 @@ var FLOOR_FILES = [
|
|
|
27542
27620
|
|
|
27543
27621
|
var FLOOR_LOOK_SOURCE = `import { Faculty } from 'nervur:faculty';
|
|
27544
27622
|
export default class FloorLook extends Faculty {
|
|
27545
|
-
static #identity = {"design":"floor","name":"nervur.floor-look","version":"0.37.
|
|
27623
|
+
static #identity = {"design":"floor","name":"nervur.floor-look","version":"0.37.7","description":"The genome's one design: plain, clean and accessible, host-agnostic, given away with the packages. Its look is the describe look.","components":["lobe","organism","surround"],"tints":["blue"],"densities":["compact","regular","roomy"]};
|
|
27546
27624
|
static #components = (() => {
|
|
27547
27625
|
const $m = {};
|
|
27548
27626
|
$m["_tree.ts"] = (() => {
|
|
@@ -28007,8 +28085,8 @@ return { "lobe": $m["lobe.ts"].default, "organism": $m["organism.ts"].default, "
|
|
|
28007
28085
|
|
|
28008
28086
|
static blueprint = {
|
|
28009
28087
|
name: "nervur.floor-look",
|
|
28010
|
-
version: "0.37.
|
|
28011
|
-
assets: "
|
|
28088
|
+
version: "0.37.7",
|
|
28089
|
+
assets: "8bab2d2df29126150f5d451bb6c2126510ce9fd42ba9d623cc2c8ac36dee5e4f",
|
|
28012
28090
|
...FloorLook.#rest(),
|
|
28013
28091
|
};
|
|
28014
28092
|
|
|
@@ -28638,7 +28716,7 @@ var WINDOW2 = {
|
|
|
28638
28716
|
|
|
28639
28717
|
var LONGEST_TIMEOUT = 1e4;
|
|
28640
28718
|
|
|
28641
|
-
var INSTALLER_VERSION = "0.37.
|
|
28719
|
+
var INSTALLER_VERSION = "0.37.7";
|
|
28642
28720
|
|
|
28643
28721
|
var ROAD = `installers@${INSTALLER_VERSION}`;
|
|
28644
28722
|
var SKIN = { ...WINDOW2, road: ROAD };
|
package/dist/keeper.js
CHANGED
|
@@ -109,4 +109,4 @@ var keeping = (scope, keeps) => {
|
|
|
109
109
|
});
|
|
110
110
|
};
|
|
111
111
|
|
|
112
|
-
keeping(self, { "digest": "
|
|
112
|
+
keeping(self, { "digest": "9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c", "files": { "9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/worker.js": "dc50444e1f3e83774f7ab32046c0ecd2cb7fe6a29402512d1fc87958975b6451", "9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/emscripten-module.wasm": "4e6fabc85e6760aaab5ab10d425d09dfd46ce4a655b553bb7724f647113c2cc0", "9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/sqlite3.wasm": "0b5a4bfff35f1ec87bf6f68ea293f425b86cbd661b77628a955cb827c9fbf524", "9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/page.js": "d128b8af98e71065e9ba041e59d40bb6ced3c53a7efd09360e0dad9457143822", "page.js": "55f3321e219391b3269bf5f0be23355634013b7f36a8c5f8654bb5c7621802f8" } });
|
package/dist/manifest.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"installer": "0.37.
|
|
3
|
-
"genome": "0.37.
|
|
4
|
-
"digest": "
|
|
5
|
-
"worker": "
|
|
2
|
+
"installer": "0.37.7",
|
|
3
|
+
"genome": "0.37.7",
|
|
4
|
+
"digest": "9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c",
|
|
5
|
+
"worker": "9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/worker.js",
|
|
6
6
|
"files": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"keeper.js": "
|
|
12
|
-
"page.js": "
|
|
13
|
-
"quo.json": "
|
|
7
|
+
"9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/emscripten-module.wasm": "4e6fabc85e6760aaab5ab10d425d09dfd46ce4a655b553bb7724f647113c2cc0",
|
|
8
|
+
"9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/page.js": "d128b8af98e71065e9ba041e59d40bb6ced3c53a7efd09360e0dad9457143822",
|
|
9
|
+
"9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/sqlite3.wasm": "0b5a4bfff35f1ec87bf6f68ea293f425b86cbd661b77628a955cb827c9fbf524",
|
|
10
|
+
"9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/worker.js": "dc50444e1f3e83774f7ab32046c0ecd2cb7fe6a29402512d1fc87958975b6451",
|
|
11
|
+
"keeper.js": "bbdb935a5776328e05f99b73c92b5d10f8fa7e196a19147f2bc0b298313900ff",
|
|
12
|
+
"page.js": "55f3321e219391b3269bf5f0be23355634013b7f36a8c5f8654bb5c7621802f8",
|
|
13
|
+
"quo.json": "7b46d18b8b3547c18821451a42c5556de6317bbd38eab64f1aff96bd40008ecb"
|
|
14
14
|
}
|
|
15
15
|
}
|
package/dist/page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/page.js';
|
package/dist/quo.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"installer": "0.37.
|
|
3
|
-
"digest": "
|
|
2
|
+
"installer": "0.37.7",
|
|
3
|
+
"digest": "9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c",
|
|
4
4
|
"page": {
|
|
5
5
|
"path": "page.js",
|
|
6
|
-
"digest": "
|
|
6
|
+
"digest": "55f3321e219391b3269bf5f0be23355634013b7f36a8c5f8654bb5c7621802f8"
|
|
7
7
|
},
|
|
8
8
|
"worker": {
|
|
9
|
-
"path": "
|
|
10
|
-
"digest": "
|
|
9
|
+
"path": "9779fbc3c4cf354167d9b860ecce4115859a87be71471e6a322ece9f6850dc8c/worker.js",
|
|
10
|
+
"digest": "dc50444e1f3e83774f7ab32046c0ecd2cb7fe6a29402512d1fc87958975b6451"
|
|
11
11
|
}
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nervur.org/installer-browser",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.7",
|
|
4
4
|
"description": "Nervur's installer for a browser: the organism of a website's visitor, in a dedicated worker, its store in the site's private files. 0.x, unstable.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser",
|
|
File without changes
|