@biolibs/bionet 1.8.1 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/log.d.ts +10 -2
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +9 -1
- package/dist/log.js.map +1 -1
- package/dist/merge.d.ts +2 -0
- package/dist/merge.d.ts.map +1 -1
- package/dist/merge.js +32 -8
- package/dist/merge.js.map +1 -1
- package/dist/method.d.ts +119 -0
- package/dist/method.d.ts.map +1 -0
- package/dist/method.js +287 -0
- package/dist/method.js.map +1 -0
- package/dist/model.d.ts +116 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +2 -0
- package/dist/model.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/log.ts +10 -2
- package/src/merge.ts +32 -9
- package/src/method.ts +295 -0
- package/src/model.ts +109 -0
package/src/method.ts
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
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, type SignatureCheck, type SignOptions, type SigningKey } from "@biolibs/opencloning";
|
|
30
|
+
import { METHOD_VERSION, type LabModel, type MethodDocument, type MethodInput, type MethodStep,
|
|
31
|
+
type SignedMethod } from "./model.js";
|
|
32
|
+
import type { LabState, PlanState } from "./merge.js";
|
|
33
|
+
import type { PartEnds } from "./log.js";
|
|
34
|
+
|
|
35
|
+
/** What the bytes of a signed method are for. */
|
|
36
|
+
export const METHOD_DOMAIN = "biolibs/bionet signed method v1";
|
|
37
|
+
|
|
38
|
+
/** How many steps one method may have. */
|
|
39
|
+
export const MOST_STEPS = 500;
|
|
40
|
+
|
|
41
|
+
/** The longest a method may be, as text. */
|
|
42
|
+
export const LONGEST_METHOD = 4_000_000;
|
|
43
|
+
|
|
44
|
+
/** What `publicMethod` needs to know that the plans cannot say. */
|
|
45
|
+
export interface MethodOptions {
|
|
46
|
+
/** Which plans to publish, by ID. Without it, every plan still open. */
|
|
47
|
+
plans?: readonly string[];
|
|
48
|
+
/** Only the plans filed under this project. */
|
|
49
|
+
project?: string;
|
|
50
|
+
/** What to call it. Without it, the project, or what it ends by making. */
|
|
51
|
+
name?: string;
|
|
52
|
+
/** Anything to say about it as a whole. */
|
|
53
|
+
note?: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Whether to write out the sequence of what the method starts from, as well as of what it makes.
|
|
56
|
+
*
|
|
57
|
+
* On unless a lab says otherwise. Off, the method says which molecules are needed, by checksum,
|
|
58
|
+
* and not what they are: somebody holding the same ones can follow it, and somebody holding none
|
|
59
|
+
* of them learns only that they are missing something.
|
|
60
|
+
*/
|
|
61
|
+
sequences?: boolean;
|
|
62
|
+
/** When to say it was published. Defaults to now. */
|
|
63
|
+
publishedAt?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The field a plan is filed under. */
|
|
67
|
+
const PROJECT = "project";
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Write a lab's plan out as a method another lab could carry out.
|
|
71
|
+
*
|
|
72
|
+
* The order is worked out the same way it is worked out at home: a step that needs what another
|
|
73
|
+
* step makes comes after it. Nothing is asserted that the plans do not already say.
|
|
74
|
+
*
|
|
75
|
+
* @param state - The lab, merged.
|
|
76
|
+
* @param lab - Who is publishing, as an inventory says it.
|
|
77
|
+
* @param options - Which plans, what to call it, and whether to write the starting sequences out.
|
|
78
|
+
* @returns The method, ready to be signed.
|
|
79
|
+
* @throws If no plan was chosen, or there are more steps than one method may carry.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { publicMethod, signMethod } from "@biolibs/bionet";
|
|
84
|
+
*
|
|
85
|
+
* const method = publicMethod(lab, { name: "The Wren Lab", origin: "https://wrenlab.example", contact: null, note: null },
|
|
86
|
+
* { project: "Real Vegan Cheese" });
|
|
87
|
+
* const published = await signMethod(method, adasKey, { signer: "Ada" });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function publicMethod(state: LabState, lab: LabModel, options: MethodOptions = {}): MethodDocument {
|
|
91
|
+
const chosen = state.plans.filter((one) => {
|
|
92
|
+
if (one.settled !== null) return false;
|
|
93
|
+
if (options.plans !== undefined) return options.plans.includes(one.plan);
|
|
94
|
+
if (options.project !== undefined) return one.fields[PROJECT] === options.project;
|
|
95
|
+
return true;
|
|
96
|
+
});
|
|
97
|
+
if (chosen.length === 0) throw new Error("There are no open plans to publish.");
|
|
98
|
+
if (chosen.length > MOST_STEPS) throw new Error(`A method carries at most ${MOST_STEPS} steps; that is ${chosen.length}.`);
|
|
99
|
+
const withSequences = options.sequences !== false;
|
|
100
|
+
|
|
101
|
+
/** What a tube is of, said the way it has to be said to travel. */
|
|
102
|
+
const whatIsIn = (item: string): { part: string | null; name: string; unit: string | null; alive?: MethodInput["alive"] } => {
|
|
103
|
+
const held = state.items.find((one) => one.item === item);
|
|
104
|
+
if (held === undefined) return { part: null, name: "something the lab no longer holds", unit: null };
|
|
105
|
+
if (held.part !== null) {
|
|
106
|
+
const part = state.parts.find((one) => one.checksum === held.part);
|
|
107
|
+
return { part: held.part, name: part?.name ?? "a part", unit: held.unit };
|
|
108
|
+
}
|
|
109
|
+
// A culture. It has no checksum, so what travels is what it would have to be a culture of.
|
|
110
|
+
const strain = state.strains.find((one) => one.strain === held.strain);
|
|
111
|
+
return { part: null, name: strain?.name ?? "a culture", unit: held.unit,
|
|
112
|
+
alive: { carries: [...(strain?.carries ?? [])], host: strain?.host ?? null } };
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// Which step makes what, so that a step using it can point at the step rather than at a freezer.
|
|
116
|
+
const madeBy = new Map<string, string>();
|
|
117
|
+
for (const plan of chosen) for (const made of plan.expects) if (!madeBy.has(made.checksum)) madeBy.set(made.checksum, plan.plan);
|
|
118
|
+
|
|
119
|
+
/** Which plans each waits on, by ID. */
|
|
120
|
+
const after = new Map<string, string[]>();
|
|
121
|
+
for (const plan of chosen) {
|
|
122
|
+
const waits = plan.inputs.flatMap((input) => {
|
|
123
|
+
const checksum = input.part ?? (input.item === undefined ? null : whatIsIn(input.item).part);
|
|
124
|
+
const maker = checksum === null ? undefined : madeBy.get(checksum);
|
|
125
|
+
return maker === undefined || maker === plan.plan ? [] : [maker];
|
|
126
|
+
});
|
|
127
|
+
after.set(plan.plan, [...new Set(waits)]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// The order: everything a step waits on comes before it. A circle, which nothing in a lab should
|
|
131
|
+
// make, is published in the order the plans were proposed rather than refused.
|
|
132
|
+
const left = new Set(chosen.map((one) => one.plan));
|
|
133
|
+
const order: PlanState[] = [];
|
|
134
|
+
for (let guard = 0; left.size > 0 && guard <= chosen.length; guard += 1) {
|
|
135
|
+
const free = chosen.filter((one) => left.has(one.plan) && (after.get(one.plan) ?? []).every((before) => !left.has(before)));
|
|
136
|
+
if (free.length === 0) break;
|
|
137
|
+
for (const one of free) { order.push(one); left.delete(one.plan); }
|
|
138
|
+
}
|
|
139
|
+
for (const one of chosen) if (left.has(one.plan)) order.push(one);
|
|
140
|
+
const numberOf = new Map(order.map((one, at) => [one.plan, at + 1]));
|
|
141
|
+
|
|
142
|
+
// A sequence on its own is not an identity: the same bases as a ring and as a line are two
|
|
143
|
+
// different molecules with two different checksums. So whatever is written out goes with the
|
|
144
|
+
// shape it was written out as, or a lab taking it rebuilds a ring as a line and matches nothing.
|
|
145
|
+
const moleculeOf = (checksum: string): { sequence: string; circular: boolean; ends?: PartEnds } | undefined => {
|
|
146
|
+
if (!withSequences) return undefined;
|
|
147
|
+
const part = state.parts.find((one) => one.checksum === checksum);
|
|
148
|
+
if (part === undefined) return undefined;
|
|
149
|
+
return { sequence: part.sequence, circular: part.circular,
|
|
150
|
+
...(part.ends.left === 0 && part.ends.right === 0 ? {} : { ends: part.ends }) };
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const steps: MethodStep[] = order.map((plan, at) => ({
|
|
154
|
+
step: at + 1,
|
|
155
|
+
kind: plan.kind,
|
|
156
|
+
uses: plan.inputs.map((input): MethodInput => {
|
|
157
|
+
const what = input.item === undefined
|
|
158
|
+
? { part: input.part!, name: state.parts.find((one) => one.checksum === input.part)?.name ?? "a part", unit: null }
|
|
159
|
+
: whatIsIn(input.item);
|
|
160
|
+
const maker = what.part === null ? undefined : madeBy.get(what.part);
|
|
161
|
+
return {
|
|
162
|
+
part: what.part, name: what.name, amount: input.amount, unit: what.unit, role: input.role,
|
|
163
|
+
...(maker === undefined || maker === plan.plan ? {} : { from: numberOf.get(maker)! }),
|
|
164
|
+
...(what.alive === undefined ? {} : { alive: what.alive }),
|
|
165
|
+
};
|
|
166
|
+
}),
|
|
167
|
+
makes: plan.expects.map((made) => ({
|
|
168
|
+
name: made.name, circular: made.circular, ends: made.ends, length: made.length, checksum: made.checksum,
|
|
169
|
+
// What a step makes is always written out: a later step has to be able to name it, and
|
|
170
|
+
// somebody checking their own product against this has nothing to check without it.
|
|
171
|
+
sequence: made.sequence,
|
|
172
|
+
})),
|
|
173
|
+
settings: { ...plan.settings },
|
|
174
|
+
note: plan.note,
|
|
175
|
+
after: (after.get(plan.plan) ?? []).map((one) => numberOf.get(one)!).sort((a, b) => a - b),
|
|
176
|
+
}));
|
|
177
|
+
|
|
178
|
+
// What a lab has to have before it starts: everything used that no step here makes.
|
|
179
|
+
const needs = new Map<string, MethodInput>();
|
|
180
|
+
for (const step of steps) {
|
|
181
|
+
for (const used of step.uses) {
|
|
182
|
+
if (used.from !== undefined) continue;
|
|
183
|
+
const key = used.part ?? `alive:${used.name}`;
|
|
184
|
+
if (needs.has(key)) continue;
|
|
185
|
+
const molecule = used.part === null ? undefined : moleculeOf(used.part);
|
|
186
|
+
needs.set(key, { ...used, ...(molecule === undefined ? {} : molecule) });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const made = new Set(steps.flatMap((one) => one.makes.map((each) => each.checksum)));
|
|
190
|
+
const used = new Set(steps.flatMap((one) => one.uses.flatMap((each) => (each.part === null ? [] : [each.part]))));
|
|
191
|
+
const ends = [...made].filter((checksum) => !used.has(checksum));
|
|
192
|
+
|
|
193
|
+
const names = ends.map((checksum) => steps.flatMap((one) => one.makes).find((each) => each.checksum === checksum)!);
|
|
194
|
+
return {
|
|
195
|
+
bionet_method_version: METHOD_VERSION,
|
|
196
|
+
lab,
|
|
197
|
+
name: options.name?.trim() || options.project
|
|
198
|
+
|| names.map((one) => one.name).join(" and ")
|
|
199
|
+
|| `${steps.length} ${steps.length === 1 ? "step" : "steps"}`,
|
|
200
|
+
makes: names.map((one) => ({ name: one.name, checksum: one.checksum })),
|
|
201
|
+
needs: [...needs.values()],
|
|
202
|
+
steps,
|
|
203
|
+
note: options.note?.trim() || null,
|
|
204
|
+
published_at: options.publishedAt ?? new Date().toISOString(),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Sign a method, or add a signature to one already signed.
|
|
210
|
+
*
|
|
211
|
+
* @param method - The method, or one already signed.
|
|
212
|
+
* @param key - The key to sign with.
|
|
213
|
+
* @param options - What to say about the signer.
|
|
214
|
+
* @returns The method with the signature beside it.
|
|
215
|
+
*/
|
|
216
|
+
export async function signMethod(method: MethodDocument | SignedMethod, key: SigningKey,
|
|
217
|
+
options: SignOptions = {}): Promise<SignedMethod> {
|
|
218
|
+
const held = isSignedMethod(method) ? method.method : method;
|
|
219
|
+
const already = isSignedMethod(method) ? method.signatures : [];
|
|
220
|
+
return { method: held, signatures: [...already, await signUnder(METHOD_DOMAIN, held, key, options)] };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Check every signature on a method.
|
|
225
|
+
*
|
|
226
|
+
* @param signed - The signed method.
|
|
227
|
+
* @returns One check per signature, in the same order. Never throws over a bad one.
|
|
228
|
+
*/
|
|
229
|
+
export function verifyMethod(signed: SignedMethod): Promise<SignatureCheck[]> {
|
|
230
|
+
return verifyUnder(METHOD_DOMAIN, signed.method, signed.signatures);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Whether something is shaped like a signed method. */
|
|
234
|
+
export function isSignedMethod(value: unknown): value is SignedMethod {
|
|
235
|
+
const held = value as Partial<SignedMethod> | null;
|
|
236
|
+
return typeof held === "object" && held !== null && typeof held.method === "object" && held.method !== null && Array.isArray(held.signatures);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const words = (value: unknown, most: number): boolean => typeof value === "string" && value.length <= most;
|
|
240
|
+
const whole = (value: unknown): boolean => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Read a method somebody published, checking its shape before anything else looks at it.
|
|
244
|
+
*
|
|
245
|
+
* What arrives is a file from somewhere else, so this says plainly what is wrong when it is wrong
|
|
246
|
+
* and believes nothing about whose it is: checking the signatures is `verifyMethod`'s, and deciding
|
|
247
|
+
* whether to trust the key is the reader's.
|
|
248
|
+
*
|
|
249
|
+
* @param value - What arrived, parsed from JSON.
|
|
250
|
+
* @returns The signed method.
|
|
251
|
+
* @throws If it is not one, with what is wrong.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* import { readMethod, verifyMethod } from "@biolibs/bionet";
|
|
256
|
+
*
|
|
257
|
+
* const method = readMethod(JSON.parse(text));
|
|
258
|
+
* (await verifyMethod(method)).every((one) => one.ok);
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export function readMethod(value: unknown): SignedMethod {
|
|
262
|
+
if (typeof value === "string") {
|
|
263
|
+
if (value.length > LONGEST_METHOD) throw new Error("That method is longer than one is allowed to be.");
|
|
264
|
+
try { value = JSON.parse(value); } catch { throw new Error("That is not a method: it is not JSON."); }
|
|
265
|
+
}
|
|
266
|
+
if (!isSignedMethod(value)) throw new Error("That is not a method: it has no method and signatures.");
|
|
267
|
+
const method = value.method as Partial<MethodDocument>;
|
|
268
|
+
if (method.bionet_method_version !== METHOD_VERSION) throw new Error(`That method says it is version ${String(method.bionet_method_version)}; this reads version ${METHOD_VERSION}.`);
|
|
269
|
+
const lab = method.lab as Partial<LabModel> | undefined;
|
|
270
|
+
if (typeof lab !== "object" || lab === null || !words(lab.name, 200) || !words(lab.origin, 2_000)) throw new Error("That method does not say which lab published it.");
|
|
271
|
+
if (!words(method.name, 200) || method.name!.trim() === "") throw new Error("That method has no name.");
|
|
272
|
+
if (!words(method.published_at, 40)) throw new Error("That method does not say when it was published.");
|
|
273
|
+
if (!Array.isArray(method.steps) || method.steps.length === 0) throw new Error("That method has no steps.");
|
|
274
|
+
if (method.steps.length > MOST_STEPS) throw new Error(`That method has ${method.steps.length} steps, which is more than one may carry.`);
|
|
275
|
+
for (const [at, step] of (method.steps as Partial<MethodStep>[]).entries()) {
|
|
276
|
+
if (step.step !== at + 1) throw new Error(`Its steps are not numbered from 1 in order: step ${at + 1} says it is ${String(step.step)}.`);
|
|
277
|
+
if (!words(step.kind, 80) || !Array.isArray(step.uses) || !Array.isArray(step.makes) || !Array.isArray(step.after)) {
|
|
278
|
+
throw new Error(`Step ${at + 1} does not say what kind of run it is, what it uses and what it makes.`);
|
|
279
|
+
}
|
|
280
|
+
for (const before of step.after as unknown[]) {
|
|
281
|
+
// A step may only wait on one before it, or the order it claims is not an order.
|
|
282
|
+
if (!whole(before) || (before as number) < 1 || (before as number) > at) throw new Error(`Step ${at + 1} says it comes after step ${String(before)}, which is not a step before it.`);
|
|
283
|
+
}
|
|
284
|
+
for (const used of step.uses as Partial<MethodInput>[]) {
|
|
285
|
+
if (!(used.part === null || words(used.part, 120)) || !words(used.name, 200) || !whole(used.amount) || !words(used.role, 80)) {
|
|
286
|
+
throw new Error(`Step ${at + 1} does not say properly what it uses.`);
|
|
287
|
+
}
|
|
288
|
+
if (used.from !== undefined && (!whole(used.from) || used.from < 1 || used.from > at)) {
|
|
289
|
+
throw new Error(`Step ${at + 1} says something comes from step ${String(used.from)}, which is not a step before it.`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (!Array.isArray(method.needs) || !Array.isArray(method.makes)) throw new Error("That method does not say what it needs and what it makes.");
|
|
294
|
+
return value;
|
|
295
|
+
}
|
package/src/model.ts
CHANGED
|
@@ -19,9 +19,14 @@
|
|
|
19
19
|
* an address by a person. See `PeerModel` and `discover.ts`.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
import type { PartEnds } from "./log.js";
|
|
23
|
+
|
|
22
24
|
/** The version of this document these are written in. */
|
|
23
25
|
export const INVENTORY_VERSION = 1;
|
|
24
26
|
|
|
27
|
+
/** The version every published method carries. */
|
|
28
|
+
export const METHOD_VERSION = 1;
|
|
29
|
+
|
|
25
30
|
/** Who published an inventory. */
|
|
26
31
|
export interface LabModel {
|
|
27
32
|
/** What the lab calls itself. A label, not a verified name. */
|
|
@@ -117,3 +122,107 @@ export interface SignedInventory {
|
|
|
117
122
|
/** The signatures over it. */
|
|
118
123
|
signatures: import("@biolibs/opencloning").DocumentSignature[];
|
|
119
124
|
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* One thing a step of a published method uses.
|
|
128
|
+
*
|
|
129
|
+
* It names a **part** and not a tube, which is the whole of what makes a method travel. A tube's ID
|
|
130
|
+
* means something only in the lab that holds it; a part's checksum means the same molecule
|
|
131
|
+
* everywhere, so a lab reading this can look in its own freezer, or ask the network who has one.
|
|
132
|
+
*/
|
|
133
|
+
export interface MethodInput {
|
|
134
|
+
/** The molecule, by the checksum every lab agrees on, or `null` for something that is alive. */
|
|
135
|
+
part: string | null;
|
|
136
|
+
/** What the publishing lab called it, so that a person can read the step. */
|
|
137
|
+
name: string;
|
|
138
|
+
/** How much of it, in the unit the publishing lab used. */
|
|
139
|
+
amount: number;
|
|
140
|
+
unit: string | null;
|
|
141
|
+
/** What it is there as: a template, a piece, the construct. */
|
|
142
|
+
role: string;
|
|
143
|
+
/**
|
|
144
|
+
* The molecule itself, where it is a starting material and the publisher chose to write it out.
|
|
145
|
+
*
|
|
146
|
+
* A method whose starting materials carry no sequence still tells somebody holding the same
|
|
147
|
+
* molecules exactly what to do with them. It does not tell somebody holding none of them what to
|
|
148
|
+
* order, which is why it is written out unless a lab says otherwise.
|
|
149
|
+
*/
|
|
150
|
+
sequence?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Whether that sequence is a ring, where it was written out.
|
|
153
|
+
*
|
|
154
|
+
* It travels with the sequence because it is part of what the molecule is: the same bases closed
|
|
155
|
+
* into a ring and left as a line are two different molecules with two different checksums. A lab
|
|
156
|
+
* taking a method without it rebuilds every ring as a line, and then matches none of them.
|
|
157
|
+
*/
|
|
158
|
+
circular?: boolean;
|
|
159
|
+
/** What is left overhanging at each end, where that is not blunt and the sequence was written out. */
|
|
160
|
+
ends?: PartEnds;
|
|
161
|
+
/** The step that makes it, counting from 1, where a step of this method does. */
|
|
162
|
+
from?: number;
|
|
163
|
+
/**
|
|
164
|
+
* For something alive, which has no checksum: what it would have to be a culture of.
|
|
165
|
+
*
|
|
166
|
+
* A strain is the lab's own — the same plasmid in the same published host twice is two strains —
|
|
167
|
+
* so it cannot be named across labs the way a molecule can. What can be said is what it carries
|
|
168
|
+
* and what it is, and whoever follows this has to make their own.
|
|
169
|
+
*/
|
|
170
|
+
alive?: { carries: string[]; host: string | null };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** One step of a published method. */
|
|
174
|
+
export interface MethodStep {
|
|
175
|
+
/** Where it comes in the order, counting from 1. */
|
|
176
|
+
step: number;
|
|
177
|
+
/** What kind of run it is: `pcr`, `assembly`, `transformation`. */
|
|
178
|
+
kind: string;
|
|
179
|
+
/** What it uses. */
|
|
180
|
+
uses: MethodInput[];
|
|
181
|
+
/** What it makes, each with the checksum that is its identity. */
|
|
182
|
+
makes: { name: string; sequence?: string; circular: boolean; ends: PartEnds; length: number; checksum: string }[];
|
|
183
|
+
/** How it is set up. */
|
|
184
|
+
settings: Record<string, string | number>;
|
|
185
|
+
/** Why, and anything else said about it. */
|
|
186
|
+
note: string | null;
|
|
187
|
+
/** The steps that have to be carried out before it, by their numbers. */
|
|
188
|
+
after: number[];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* A method: a lab's plan, written so that another lab can carry it out.
|
|
193
|
+
*
|
|
194
|
+
* It is what a plan becomes when it leaves. Inside a lab a plan points at tubes, which is what a
|
|
195
|
+
* person at that bench needs; published, every tube is replaced by the checksum of what is in it,
|
|
196
|
+
* since that is the one name two labs that have never spoken already agree on.
|
|
197
|
+
*/
|
|
198
|
+
export interface MethodDocument {
|
|
199
|
+
/** Always `1`. */
|
|
200
|
+
bionet_method_version: number;
|
|
201
|
+
/** Who published it. */
|
|
202
|
+
lab: LabModel;
|
|
203
|
+
/** What it is called: the project it came from, or what it makes. */
|
|
204
|
+
name: string;
|
|
205
|
+
/** What following it the whole way would leave you with. */
|
|
206
|
+
makes: { name: string; checksum: string }[];
|
|
207
|
+
/**
|
|
208
|
+
* What a lab has to have before it can start: the molecules no step of this makes.
|
|
209
|
+
*
|
|
210
|
+
* Each is a checksum, which is what `whoHas` searches on, so a lab without one can go and find
|
|
211
|
+
* who has it rather than being told only that something is missing.
|
|
212
|
+
*/
|
|
213
|
+
needs: MethodInput[];
|
|
214
|
+
/** The steps, in an order that can be carried out. */
|
|
215
|
+
steps: MethodStep[];
|
|
216
|
+
/** Anything the publishers wanted to say about it as a whole. */
|
|
217
|
+
note: string | null;
|
|
218
|
+
/** When they say they published it, as an ISO 8601 instant. */
|
|
219
|
+
published_at: string;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** A method with signatures beside it, which is how one is published. */
|
|
223
|
+
export interface SignedMethod {
|
|
224
|
+
/** The method, exactly as it was signed. */
|
|
225
|
+
method: MethodDocument;
|
|
226
|
+
/** The signatures over it. */
|
|
227
|
+
signatures: import("@biolibs/opencloning").DocumentSignature[];
|
|
228
|
+
}
|