@biolibs/bionet 1.8.1 → 1.8.2

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/method.js ADDED
@@ -0,0 +1,280 @@
1
+ /**
2
+ * Writing a lab's plan out so that another lab can carry it out, signing one, and reading one a
3
+ * stranger published.
4
+ *
5
+ * A lab's own inventory says what it *holds*. This says what it *did*, which is the other half of
6
+ * what one lab has to give another and the half that was missing: a lab could publish that it had a
7
+ * molecule, and could not publish how to make one.
8
+ *
9
+ * The whole of the difficulty is in one translation. Inside a lab a plan points at tubes — "use
10
+ * 1 µL of tube abc123" — and a tube's ID means something only in the lab that holds it. Published,
11
+ * every tube is replaced by the checksum of what is in it, which is the one name two labs that have
12
+ * never spoken already agree on: the same molecule gives the same checksum whichever strand it was
13
+ * written from and, for a circle, wherever it was cut open. So a method says "use the molecule whose
14
+ * checksum is this", and the lab reading it looks in its own freezer, or asks the network who has
15
+ * one with `whoHas`.
16
+ *
17
+ * Two things cannot make that crossing, and both are said rather than hidden.
18
+ *
19
+ * **Anything alive.** A strain is the lab's own — the same plasmid in the same published host twice
20
+ * is two strains, deliberately — so a culture has no checksum to travel under. A step that uses one
21
+ * says what it would have to be a culture *of*, and whoever follows the method makes their own.
22
+ *
23
+ * **A starting material's sequence, unless the publisher gives it.** What a method's steps make is
24
+ * written out in full, because a later step has to be able to name it. What it *starts* from is
25
+ * named by checksum, and carries its sequence only if the publisher said to share it. A method
26
+ * without those sequences is still worth having — it tells somebody holding the same molecules
27
+ * exactly what to do with them — but it will not tell somebody who holds none of them what to order.
28
+ */
29
+ import { signUnder, verifyUnder } from "@biolibs/opencloning";
30
+ import { METHOD_VERSION } from "./model.js";
31
+ /** What the bytes of a signed method are for. */
32
+ export const METHOD_DOMAIN = "biolibs/bionet signed method v1";
33
+ /** How many steps one method may have. */
34
+ export const MOST_STEPS = 500;
35
+ /** The longest a method may be, as text. */
36
+ export const LONGEST_METHOD = 4_000_000;
37
+ /** The field a plan is filed under. */
38
+ const PROJECT = "project";
39
+ /**
40
+ * Write a lab's plan out as a method another lab could carry out.
41
+ *
42
+ * The order is worked out the same way it is worked out at home: a step that needs what another
43
+ * step makes comes after it. Nothing is asserted that the plans do not already say.
44
+ *
45
+ * @param state - The lab, merged.
46
+ * @param lab - Who is publishing, as an inventory says it.
47
+ * @param options - Which plans, what to call it, and whether to write the starting sequences out.
48
+ * @returns The method, ready to be signed.
49
+ * @throws If no plan was chosen, or there are more steps than one method may carry.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { publicMethod, signMethod } from "@biolibs/bionet";
54
+ *
55
+ * const method = publicMethod(lab, { name: "The Wren Lab", origin: "https://wrenlab.example", contact: null, note: null },
56
+ * { project: "Real Vegan Cheese" });
57
+ * const published = await signMethod(method, adasKey, { signer: "Ada" });
58
+ * ```
59
+ */
60
+ export function publicMethod(state, lab, options = {}) {
61
+ const chosen = state.plans.filter((one) => {
62
+ if (one.settled !== null)
63
+ return false;
64
+ if (options.plans !== undefined)
65
+ return options.plans.includes(one.plan);
66
+ if (options.project !== undefined)
67
+ return one.fields[PROJECT] === options.project;
68
+ return true;
69
+ });
70
+ if (chosen.length === 0)
71
+ throw new Error("There are no open plans to publish.");
72
+ if (chosen.length > MOST_STEPS)
73
+ throw new Error(`A method carries at most ${MOST_STEPS} steps; that is ${chosen.length}.`);
74
+ const withSequences = options.sequences !== false;
75
+ /** What a tube is of, said the way it has to be said to travel. */
76
+ const whatIsIn = (item) => {
77
+ const held = state.items.find((one) => one.item === item);
78
+ if (held === undefined)
79
+ return { part: null, name: "something the lab no longer holds", unit: null };
80
+ if (held.part !== null) {
81
+ const part = state.parts.find((one) => one.checksum === held.part);
82
+ return { part: held.part, name: part?.name ?? "a part", unit: held.unit };
83
+ }
84
+ // A culture. It has no checksum, so what travels is what it would have to be a culture of.
85
+ const strain = state.strains.find((one) => one.strain === held.strain);
86
+ return { part: null, name: strain?.name ?? "a culture", unit: held.unit,
87
+ alive: { carries: [...(strain?.carries ?? [])], host: strain?.host ?? null } };
88
+ };
89
+ // Which step makes what, so that a step using it can point at the step rather than at a freezer.
90
+ const madeBy = new Map();
91
+ for (const plan of chosen)
92
+ for (const made of plan.expects)
93
+ if (!madeBy.has(made.checksum))
94
+ madeBy.set(made.checksum, plan.plan);
95
+ /** Which plans each waits on, by ID. */
96
+ const after = new Map();
97
+ for (const plan of chosen) {
98
+ const waits = plan.inputs.flatMap((input) => {
99
+ const checksum = input.part ?? (input.item === undefined ? null : whatIsIn(input.item).part);
100
+ const maker = checksum === null ? undefined : madeBy.get(checksum);
101
+ return maker === undefined || maker === plan.plan ? [] : [maker];
102
+ });
103
+ after.set(plan.plan, [...new Set(waits)]);
104
+ }
105
+ // The order: everything a step waits on comes before it. A circle, which nothing in a lab should
106
+ // make, is published in the order the plans were proposed rather than refused.
107
+ const left = new Set(chosen.map((one) => one.plan));
108
+ const order = [];
109
+ for (let guard = 0; left.size > 0 && guard <= chosen.length; guard += 1) {
110
+ const free = chosen.filter((one) => left.has(one.plan) && (after.get(one.plan) ?? []).every((before) => !left.has(before)));
111
+ if (free.length === 0)
112
+ break;
113
+ for (const one of free) {
114
+ order.push(one);
115
+ left.delete(one.plan);
116
+ }
117
+ }
118
+ for (const one of chosen)
119
+ if (left.has(one.plan))
120
+ order.push(one);
121
+ const numberOf = new Map(order.map((one, at) => [one.plan, at + 1]));
122
+ const sequenceOf = (checksum) => {
123
+ if (!withSequences)
124
+ return undefined;
125
+ return state.parts.find((one) => one.checksum === checksum)?.sequence;
126
+ };
127
+ const steps = order.map((plan, at) => ({
128
+ step: at + 1,
129
+ kind: plan.kind,
130
+ uses: plan.inputs.map((input) => {
131
+ const what = input.item === undefined
132
+ ? { part: input.part, name: state.parts.find((one) => one.checksum === input.part)?.name ?? "a part", unit: null }
133
+ : whatIsIn(input.item);
134
+ const maker = what.part === null ? undefined : madeBy.get(what.part);
135
+ return {
136
+ part: what.part, name: what.name, amount: input.amount, unit: what.unit, role: input.role,
137
+ ...(maker === undefined || maker === plan.plan ? {} : { from: numberOf.get(maker) }),
138
+ ...(what.alive === undefined ? {} : { alive: what.alive }),
139
+ };
140
+ }),
141
+ makes: plan.expects.map((made) => ({
142
+ name: made.name, circular: made.circular, ends: made.ends, length: made.length, checksum: made.checksum,
143
+ // What a step makes is always written out: a later step has to be able to name it, and
144
+ // somebody checking their own product against this has nothing to check without it.
145
+ sequence: made.sequence,
146
+ })),
147
+ settings: { ...plan.settings },
148
+ note: plan.note,
149
+ after: (after.get(plan.plan) ?? []).map((one) => numberOf.get(one)).sort((a, b) => a - b),
150
+ }));
151
+ // What a lab has to have before it starts: everything used that no step here makes.
152
+ const needs = new Map();
153
+ for (const step of steps) {
154
+ for (const used of step.uses) {
155
+ if (used.from !== undefined)
156
+ continue;
157
+ const key = used.part ?? `alive:${used.name}`;
158
+ if (needs.has(key))
159
+ continue;
160
+ const sequence = used.part === null ? undefined : sequenceOf(used.part);
161
+ needs.set(key, { ...used, ...(sequence === undefined ? {} : { sequence }) });
162
+ }
163
+ }
164
+ const made = new Set(steps.flatMap((one) => one.makes.map((each) => each.checksum)));
165
+ const used = new Set(steps.flatMap((one) => one.uses.flatMap((each) => (each.part === null ? [] : [each.part]))));
166
+ const ends = [...made].filter((checksum) => !used.has(checksum));
167
+ const names = ends.map((checksum) => steps.flatMap((one) => one.makes).find((each) => each.checksum === checksum));
168
+ return {
169
+ bionet_method_version: METHOD_VERSION,
170
+ lab,
171
+ name: options.name?.trim() || options.project
172
+ || names.map((one) => one.name).join(" and ")
173
+ || `${steps.length} ${steps.length === 1 ? "step" : "steps"}`,
174
+ makes: names.map((one) => ({ name: one.name, checksum: one.checksum })),
175
+ needs: [...needs.values()],
176
+ steps,
177
+ note: options.note?.trim() || null,
178
+ published_at: options.publishedAt ?? new Date().toISOString(),
179
+ };
180
+ }
181
+ /**
182
+ * Sign a method, or add a signature to one already signed.
183
+ *
184
+ * @param method - The method, or one already signed.
185
+ * @param key - The key to sign with.
186
+ * @param options - What to say about the signer.
187
+ * @returns The method with the signature beside it.
188
+ */
189
+ export async function signMethod(method, key, options = {}) {
190
+ const held = isSignedMethod(method) ? method.method : method;
191
+ const already = isSignedMethod(method) ? method.signatures : [];
192
+ return { method: held, signatures: [...already, await signUnder(METHOD_DOMAIN, held, key, options)] };
193
+ }
194
+ /**
195
+ * Check every signature on a method.
196
+ *
197
+ * @param signed - The signed method.
198
+ * @returns One check per signature, in the same order. Never throws over a bad one.
199
+ */
200
+ export function verifyMethod(signed) {
201
+ return verifyUnder(METHOD_DOMAIN, signed.method, signed.signatures);
202
+ }
203
+ /** Whether something is shaped like a signed method. */
204
+ export function isSignedMethod(value) {
205
+ const held = value;
206
+ return typeof held === "object" && held !== null && typeof held.method === "object" && held.method !== null && Array.isArray(held.signatures);
207
+ }
208
+ const words = (value, most) => typeof value === "string" && value.length <= most;
209
+ const whole = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
210
+ /**
211
+ * Read a method somebody published, checking its shape before anything else looks at it.
212
+ *
213
+ * What arrives is a file from somewhere else, so this says plainly what is wrong when it is wrong
214
+ * and believes nothing about whose it is: checking the signatures is `verifyMethod`'s, and deciding
215
+ * whether to trust the key is the reader's.
216
+ *
217
+ * @param value - What arrived, parsed from JSON.
218
+ * @returns The signed method.
219
+ * @throws If it is not one, with what is wrong.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * import { readMethod, verifyMethod } from "@biolibs/bionet";
224
+ *
225
+ * const method = readMethod(JSON.parse(text));
226
+ * (await verifyMethod(method)).every((one) => one.ok);
227
+ * ```
228
+ */
229
+ export function readMethod(value) {
230
+ if (typeof value === "string") {
231
+ if (value.length > LONGEST_METHOD)
232
+ throw new Error("That method is longer than one is allowed to be.");
233
+ try {
234
+ value = JSON.parse(value);
235
+ }
236
+ catch {
237
+ throw new Error("That is not a method: it is not JSON.");
238
+ }
239
+ }
240
+ if (!isSignedMethod(value))
241
+ throw new Error("That is not a method: it has no method and signatures.");
242
+ const method = value.method;
243
+ if (method.bionet_method_version !== METHOD_VERSION)
244
+ throw new Error(`That method says it is version ${String(method.bionet_method_version)}; this reads version ${METHOD_VERSION}.`);
245
+ const lab = method.lab;
246
+ if (typeof lab !== "object" || lab === null || !words(lab.name, 200) || !words(lab.origin, 2_000))
247
+ throw new Error("That method does not say which lab published it.");
248
+ if (!words(method.name, 200) || method.name.trim() === "")
249
+ throw new Error("That method has no name.");
250
+ if (!words(method.published_at, 40))
251
+ throw new Error("That method does not say when it was published.");
252
+ if (!Array.isArray(method.steps) || method.steps.length === 0)
253
+ throw new Error("That method has no steps.");
254
+ if (method.steps.length > MOST_STEPS)
255
+ throw new Error(`That method has ${method.steps.length} steps, which is more than one may carry.`);
256
+ for (const [at, step] of method.steps.entries()) {
257
+ if (step.step !== at + 1)
258
+ throw new Error(`Its steps are not numbered from 1 in order: step ${at + 1} says it is ${String(step.step)}.`);
259
+ if (!words(step.kind, 80) || !Array.isArray(step.uses) || !Array.isArray(step.makes) || !Array.isArray(step.after)) {
260
+ throw new Error(`Step ${at + 1} does not say what kind of run it is, what it uses and what it makes.`);
261
+ }
262
+ for (const before of step.after) {
263
+ // A step may only wait on one before it, or the order it claims is not an order.
264
+ if (!whole(before) || before < 1 || before > at)
265
+ throw new Error(`Step ${at + 1} says it comes after step ${String(before)}, which is not a step before it.`);
266
+ }
267
+ for (const used of step.uses) {
268
+ if (!(used.part === null || words(used.part, 120)) || !words(used.name, 200) || !whole(used.amount) || !words(used.role, 80)) {
269
+ throw new Error(`Step ${at + 1} does not say properly what it uses.`);
270
+ }
271
+ if (used.from !== undefined && (!whole(used.from) || used.from < 1 || used.from > at)) {
272
+ throw new Error(`Step ${at + 1} says something comes from step ${String(used.from)}, which is not a step before it.`);
273
+ }
274
+ }
275
+ }
276
+ if (!Array.isArray(method.needs) || !Array.isArray(method.makes))
277
+ throw new Error("That method does not say what it needs and what it makes.");
278
+ return value;
279
+ }
280
+ //# sourceMappingURL=method.js.map
@@ -0,0 +1 @@
1
+ {"version":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BAC7H,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,sCAAsC,CAAC,CAAC;YACxE,CAAC;YACD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,EAAE,CAAC;gBACtF,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,mCAAmC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;YACxH,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/I,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/model.d.ts CHANGED
@@ -18,8 +18,11 @@
18
18
  * An inventory may also point at other labs, which is the only way anyone is found without being told
19
19
  * an address by a person. See `PeerModel` and `discover.ts`.
20
20
  */
21
+ import type { PartEnds } from "./log.js";
21
22
  /** The version of this document these are written in. */
22
23
  export declare const INVENTORY_VERSION = 1;
24
+ /** The version every published method carries. */
25
+ export declare const METHOD_VERSION = 1;
23
26
  /** Who published an inventory. */
24
27
  export interface LabModel {
25
28
  /** What the lab calls itself. A label, not a verified name. */
@@ -111,4 +114,107 @@ export interface SignedInventory {
111
114
  /** The signatures over it. */
112
115
  signatures: import("@biolibs/opencloning").DocumentSignature[];
113
116
  }
117
+ /**
118
+ * One thing a step of a published method uses.
119
+ *
120
+ * It names a **part** and not a tube, which is the whole of what makes a method travel. A tube's ID
121
+ * means something only in the lab that holds it; a part's checksum means the same molecule
122
+ * everywhere, so a lab reading this can look in its own freezer, or ask the network who has one.
123
+ */
124
+ export interface MethodInput {
125
+ /** The molecule, by the checksum every lab agrees on, or `null` for something that is alive. */
126
+ part: string | null;
127
+ /** What the publishing lab called it, so that a person can read the step. */
128
+ name: string;
129
+ /** How much of it, in the unit the publishing lab used. */
130
+ amount: number;
131
+ unit: string | null;
132
+ /** What it is there as: a template, a piece, the construct. */
133
+ role: string;
134
+ /**
135
+ * The molecule itself, where it is a starting material and the publisher chose to write it out.
136
+ *
137
+ * A method whose starting materials carry no sequence still tells somebody holding the same
138
+ * molecules exactly what to do with them. It does not tell somebody holding none of them what to
139
+ * order, which is why it is written out unless a lab says otherwise.
140
+ */
141
+ sequence?: string;
142
+ /** The step that makes it, counting from 1, where a step of this method does. */
143
+ from?: number;
144
+ /**
145
+ * For something alive, which has no checksum: what it would have to be a culture of.
146
+ *
147
+ * A strain is the lab's own — the same plasmid in the same published host twice is two strains —
148
+ * so it cannot be named across labs the way a molecule can. What can be said is what it carries
149
+ * and what it is, and whoever follows this has to make their own.
150
+ */
151
+ alive?: {
152
+ carries: string[];
153
+ host: string | null;
154
+ };
155
+ }
156
+ /** One step of a published method. */
157
+ export interface MethodStep {
158
+ /** Where it comes in the order, counting from 1. */
159
+ step: number;
160
+ /** What kind of run it is: `pcr`, `assembly`, `transformation`. */
161
+ kind: string;
162
+ /** What it uses. */
163
+ uses: MethodInput[];
164
+ /** What it makes, each with the checksum that is its identity. */
165
+ makes: {
166
+ name: string;
167
+ sequence?: string;
168
+ circular: boolean;
169
+ ends: PartEnds;
170
+ length: number;
171
+ checksum: string;
172
+ }[];
173
+ /** How it is set up. */
174
+ settings: Record<string, string | number>;
175
+ /** Why, and anything else said about it. */
176
+ note: string | null;
177
+ /** The steps that have to be carried out before it, by their numbers. */
178
+ after: number[];
179
+ }
180
+ /**
181
+ * A method: a lab's plan, written so that another lab can carry it out.
182
+ *
183
+ * It is what a plan becomes when it leaves. Inside a lab a plan points at tubes, which is what a
184
+ * person at that bench needs; published, every tube is replaced by the checksum of what is in it,
185
+ * since that is the one name two labs that have never spoken already agree on.
186
+ */
187
+ export interface MethodDocument {
188
+ /** Always `1`. */
189
+ bionet_method_version: number;
190
+ /** Who published it. */
191
+ lab: LabModel;
192
+ /** What it is called: the project it came from, or what it makes. */
193
+ name: string;
194
+ /** What following it the whole way would leave you with. */
195
+ makes: {
196
+ name: string;
197
+ checksum: string;
198
+ }[];
199
+ /**
200
+ * What a lab has to have before it can start: the molecules no step of this makes.
201
+ *
202
+ * Each is a checksum, which is what `whoHas` searches on, so a lab without one can go and find
203
+ * who has it rather than being told only that something is missing.
204
+ */
205
+ needs: MethodInput[];
206
+ /** The steps, in an order that can be carried out. */
207
+ steps: MethodStep[];
208
+ /** Anything the publishers wanted to say about it as a whole. */
209
+ note: string | null;
210
+ /** When they say they published it, as an ISO 8601 instant. */
211
+ published_at: string;
212
+ }
213
+ /** A method with signatures beside it, which is how one is published. */
214
+ export interface SignedMethod {
215
+ /** The method, exactly as it was signed. */
216
+ method: MethodDocument;
217
+ /** The signatures over it. */
218
+ signatures: import("@biolibs/opencloning").DocumentSignature[];
219
+ }
114
220
  //# sourceMappingURL=model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,yDAAyD;AACzD,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,kCAAkC;AAClC,MAAM,WAAW,QAAQ;IACvB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,wCAAwC;IACxC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED,4BAA4B;AAC5B,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,EAAE,EAAE,MAAM,CAAC;IACX,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC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AAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,kBAAkB;IAClB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,wBAAwB;IACxB,GAAG,EAAE,QAAQ,CAAC;IACd,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC5C;;;;;OAKG;IACH,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,sDAAsD;IACtD,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,iEAAiE;IACjE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,+DAA+D;IAC/D,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,yEAAyE;AACzE,MAAM,WAAW,YAAY;IAC3B,4CAA4C;IAC5C,MAAM,EAAE,cAAc,CAAC;IACvB,8BAA8B;IAC9B,UAAU,EAAE,OAAO,sBAAsB,EAAE,iBAAiB,EAAE,CAAC;CAChE"}
package/dist/model.js CHANGED
@@ -20,4 +20,6 @@
20
20
  */
21
21
  /** The version of this document these are written in. */
22
22
  export const INVENTORY_VERSION = 1;
23
+ /** The version every published method carries. */
24
+ export const METHOD_VERSION = 1;
23
25
  //# sourceMappingURL=model.js.map
package/dist/model.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,yDAAyD;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC"}
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,yDAAyD;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAEnC,kDAAkD;AAClD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC"}
package/package.json CHANGED
@@ -47,5 +47,5 @@
47
47
  },
48
48
  "type": "module",
49
49
  "types": "dist/index.d.ts",
50
- "version": "1.8.1"
50
+ "version": "1.8.2"
51
51
  }
package/src/index.ts CHANGED
@@ -39,6 +39,7 @@
39
39
 
40
40
  export * from "./model.js";
41
41
  export * from "./inventory.js";
42
+ export * from "./method.js";
42
43
  export * from "./origin.js";
43
44
  export * from "./fetch.js";
44
45
  export * from "./discover.js";
package/src/log.ts CHANGED
@@ -552,8 +552,16 @@ export const addStrain = (strain: StrainRecord): Operation => ({ type: "strain.a
552
552
  /** @returns A new ID for a strain, made the way an item's is. */
553
553
  export const newStrainId = (): string => newItemId();
554
554
 
555
- /** @returns The change that sets one field on a part (by checksum), or an item, a place or a strain (by ID). */
556
- export const setField = (on: "part" | "item" | "place" | "strain", id: string, field: string, value: string | number | null): Operation =>
555
+ /**
556
+ * @returns The change that sets one field on a part (by checksum), or an item, a place, a strain or
557
+ * a plan (by ID).
558
+ *
559
+ * A plan can carry one because a lab's proposals are not one undifferentiated pile: a lab with
560
+ * several projects on at once needs to know which is which, and that is a thing people decide
561
+ * rather than something the molecules say. A device too old to know a plan can be filed refuses
562
+ * the entry and still reads the plan itself, so it loses the label and nothing else.
563
+ */
564
+ export const setField = (on: "part" | "item" | "place" | "strain" | "plan", id: string, field: string, value: string | number | null): Operation =>
557
565
  ({ type: "field.set", on, id, field, value });
558
566
 
559
567
  /** @returns A new ID for a place, made the way an item's is. */
package/src/merge.ts CHANGED
@@ -204,6 +204,8 @@ export interface PlanState {
204
204
  * would use. The plan is kept and shown; somebody has to look before carrying it out.
205
205
  */
206
206
  wanting: string[];
207
+ /** Anything else set on it, such as which project it is part of. */
208
+ fields: Record<string, string | number | null>;
207
209
  /** The entry that proposed it. */
208
210
  added: string;
209
211
  }
@@ -313,6 +315,16 @@ const PLACE_RESERVED = new Set(["place", "kind", "parent", "grid", "standing", "
313
315
  /** The same, for a strain: what it is and came from is fixed when it is added. */
314
316
  const STRAIN_RESERVED = new Set(["strain", "host", "carries", "parent", "from"]);
315
317
 
318
+ /**
319
+ * What a plan's fields may not be called.
320
+ *
321
+ * A plan is a proposal somebody made, and what it would do is not a label on it: letting a field
322
+ * rewrite the kind of run, what it would use or what it expects would turn a proposal into
323
+ * something nobody proposed. A field says what a plan is *about* — which project it is part of,
324
+ * say — and nothing about what carrying it out would do.
325
+ */
326
+ const PLAN_RESERVED = new Set(["plan", "kind", "instrument", "inputs", "expects", "settings", "note", "by", "settled", "wanting", "added"]);
327
+
316
328
  /** The most positions a box may have along one side, and the farthest a place may stand or reach, in millimetres. */
317
329
  const MOST_SIDE = 100;
318
330
  const FARTHEST = 1_000_000;
@@ -469,7 +481,7 @@ const KNOWN: Readonly<Record<string, Readonly<Record<string, Known>>>> = {
469
481
  * the parts are known: an adviser may say what is on a part that nothing is marked on, and may not
470
482
  * change what somebody has already marked.
471
483
  */
472
- const ADVISER_MAY = new Set(["part.add", "part.annotate", "plan.add", "plan.settle"]);
484
+ const ADVISER_MAY = new Set(["part.add", "part.annotate", "plan.add", "plan.settle", "field.set"]);
473
485
 
474
486
  /**
475
487
  * The first field in a change that this version does not know, if there is one.
@@ -809,7 +821,7 @@ function walk(founding: Node, chains: Map<string, Node[]>, chained: Map<string,
809
821
  // An adviser proposes and describes. It is turned away here, where the roster is known as it
810
822
  // stood when the entry was written, from anything that would change what the lab holds.
811
823
  if (author.role === "adviser") {
812
- if (!ADVISER_MAY.has(op.type)) { say("refused", "Its key is an adviser, which may add and describe parts and propose runs, and nothing else."); continue; }
824
+ if (!ADVISER_MAY.has(op.type)) { say("refused", "Its key is an adviser, which may add and describe parts, propose runs and file its own proposals, and nothing else."); continue; }
813
825
  node.adviser = true;
814
826
  }
815
827
  say("applied"); // whether the change itself makes sense is settled when the inventory is folded
@@ -886,8 +898,8 @@ function fold(state: LabState, placed: Placed[], chained: Map<string, Node>): vo
886
898
 
887
899
  const places = new Map<string, { place: PlaceState; set: Map<string, Register> }>();
888
900
  const strains = new Map<string, { strain: StrainState; set: Map<string, Register> }>();
889
- /** Each plan, with the entry that settled it, if one has. */
890
- const plans = new Map<string, { plan: PlanState; settled: Node | null }>();
901
+ /** Each plan, with the entry that settled it, if one has, and anything set on it. */
902
+ const plans = new Map<string, { plan: PlanState; settled: Node | null; set: Map<string, Register> }>();
891
903
  /** Where each item was last put. */
892
904
  const put = new Map<string, Map<string, Register>>();
893
905
 
@@ -1099,12 +1111,12 @@ function fold(state: LabState, placed: Placed[], chained: Map<string, Node>): vo
1099
1111
  continue;
1100
1112
  }
1101
1113
  plans.set(op["plan"] as string, {
1102
- settled: null,
1114
+ settled: null, set: new Map(),
1103
1115
  plan: {
1104
1116
  plan: op["plan"] as string, kind: op["kind"] as string, instrument: op["instrument"] as string | null,
1105
1117
  inputs: (op["inputs"] as PlanInput[]).map((input) => ({ ...(input.item === undefined ? { part: input.part! } : { item: input.item }), amount: input.amount, role: input.role })),
1106
1118
  expects, settings: { ...(op["settings"] as Record<string, string | number>) }, note: op["note"] as string | null,
1107
- by: node.author, settled: null, wanting: [], added: node.id,
1119
+ by: node.author, settled: null, wanting: [], fields: {}, added: node.id,
1108
1120
  },
1109
1121
  });
1110
1122
  } else if (op.type === "plan.settle") {
@@ -1129,10 +1141,20 @@ function fold(state: LabState, placed: Placed[], chained: Map<string, Node>): vo
1129
1141
  const target = op["on"] === "part" && typeof op["id"] === "string" ? parts.get(op["id"])
1130
1142
  : op["on"] === "item" && typeof op["id"] === "string" ? items.get(op["id"])
1131
1143
  : op["on"] === "place" && typeof op["id"] === "string" ? places.get(op["id"])
1132
- : op["on"] === "strain" && typeof op["id"] === "string" ? strains.get(op["id"]) : undefined;
1133
- if (target === undefined) { refuse("It does not name a part, an item, a place or a strain the lab has."); continue; }
1144
+ : op["on"] === "strain" && typeof op["id"] === "string" ? strains.get(op["id"])
1145
+ : op["on"] === "plan" && typeof op["id"] === "string" ? plans.get(op["id"]) : undefined;
1146
+ if (target === undefined) { refuse("It does not name a part, an item, a place, a strain or a plan the lab has."); continue; }
1134
1147
  if (op["on"] === "place" && typeof field === "string" && PLACE_RESERVED.has(field)) { refuse("It does not name a field that can be set."); continue; }
1135
1148
  if (op["on"] === "strain" && typeof field === "string" && STRAIN_RESERVED.has(field)) { refuse("It does not name a field that can be set."); continue; }
1149
+ if (op["on"] === "plan" && typeof field === "string" && PLAN_RESERVED.has(field)) { refuse("It does not name a field that can be set."); continue; }
1150
+ // An adviser may file its own proposals and nothing else. It proposes the work, so leaving it
1151
+ // unable to say which project the work is for would have a person filing every step by hand;
1152
+ // letting it set any field at all would let it rename the lab's parts. This is the same line
1153
+ // `plan.settle` draws: a plan of its own, and no further.
1154
+ if (node.adviser === true && !(op["on"] === "plan" && (target as { plan: PlanState }).plan.by === node.author)) {
1155
+ refuse("An adviser may only set a field on a plan of its own.");
1156
+ continue;
1157
+ }
1136
1158
  if (field === "name" && (op["on"] === "place" || op["on"] === "strain") && !text(value, 200)) { refuse("A name has to be some text."); continue; }
1137
1159
  if (typeof field !== "string" || !FIELD.test(field) || RESERVED.has(field)) { refuse("It does not name a field that can be set."); continue; }
1138
1160
  if (!(value === null || amountOf(value) || (typeof value === "string" && value.length <= 2_000))) { refuse("Its value is not text, a whole number or nothing."); continue; }
@@ -1171,7 +1193,8 @@ function fold(state: LabState, placed: Placed[], chained: Map<string, Node>): vo
1171
1193
  }
1172
1194
  // A plan counts on tubes that go on being used after it is written. It is not refused for that:
1173
1195
  // it is kept, and says which of them are no longer what it needs.
1174
- for (const { plan } of plans.values()) {
1196
+ for (const { plan, set } of plans.values()) {
1197
+ for (const [field, held] of set) plan.fields[field] = held.value as string | number | null;
1175
1198
  if (plan.settled === null) {
1176
1199
  plan.wanting = plan.inputs.flatMap((input) => {
1177
1200
  const held = input.item === undefined ? undefined : items.get(input.item)?.item;