@biolibs/bionet 1.8.7 → 1.9.0

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/src/merge.ts CHANGED
@@ -198,6 +198,39 @@ export interface RunState {
198
198
  added: string;
199
199
  }
200
200
 
201
+ /**
202
+ * Something the lab understands the makeup of and has not made.
203
+ *
204
+ * The mirror of a specimen: a specimen is a tube the lab holds and cannot name, this is a thing the
205
+ * lab can name and does not hold. It has no checksum, because there is no sequence to count one
206
+ * over, so like a culture and like a specimen it cannot travel in a method.
207
+ *
208
+ * It exists so that the steps after it can be written down while it is still hypothetical. The chain
209
+ * of work used to stop at a transformation — what that makes is alive and has nothing to point at —
210
+ * and a plan after it could name nothing at all. Now it can name this, and say plainly that it rests
211
+ * on something nobody is holding.
212
+ */
213
+ export interface ProspectState {
214
+ /** Its ID. */
215
+ prospect: string;
216
+ /** What it would be called. */
217
+ name: string;
218
+ /** What kind of thing: `strain`, `culture`, `mixture`, `curd`. */
219
+ kind: string;
220
+ /** What it would be made of, said for a person. */
221
+ madeOf: string;
222
+ /** Anything else said about it. */
223
+ note: string | null;
224
+ /** What it turned out to be once somebody made it, or `null` while it is still in prospect. */
225
+ became: { strain: string | null; item: string | null; by: string; entry: string } | null;
226
+ /** The key that named it. */
227
+ by: string;
228
+ /** Anything else set on it. */
229
+ fields: Record<string, string | number | null>;
230
+ /** The entry that named it. */
231
+ added: string;
232
+ }
233
+
201
234
  /**
202
235
  * What a lab expects to see if a plan worked, and what was seen.
203
236
  *
@@ -247,6 +280,8 @@ export interface PlanState {
247
280
  inputs: PlanInput[];
248
281
  /** What it is expected to make, each with the checksum that would be its identity. */
249
282
  expects: { name: string; sequence: string; circular: boolean; ends: PartEnds; length: number; checksum: string }[];
283
+ /** The prospects it would bring into existence: what it makes that has no sequence to expect. */
284
+ makes: string[];
250
285
  /** How to set it up. */
251
286
  settings: Record<string, string | number>;
252
287
  /** Why, and anything else said about it. */
@@ -332,6 +367,8 @@ export interface LabState {
332
367
  specimens: SpecimenState[];
333
368
  /** What the lab expects to see of its plans, and what was seen. */
334
369
  expectations: ExpectationState[];
370
+ /** Things the lab means to have and has not made. */
371
+ prospects: ProspectState[];
335
372
  /** Every item. */
336
373
  items: ItemState[];
337
374
  /** Every place. */
@@ -382,6 +419,7 @@ const PLACE_RESERVED = new Set(["place", "kind", "parent", "grid", "standing", "
382
419
  /** The same, for a strain: what it is and came from is fixed when it is added. */
383
420
  const STRAIN_RESERVED = new Set(["strain", "host", "carries", "parent", "from"]);
384
421
  const SPECIMEN_RESERVED = new Set(["specimen", "note", "is", "added"]);
422
+ const PROSPECT_RESERVED = new Set(["prospect", "name", "kind", "madeOf", "note", "became", "by", "added"]);
385
423
  const EXPECT_RESERVED = new Set(["expect", "plan", "kind", "says", "numbers", "settings", "note", "by", "met", "withdrawn", "added"]);
386
424
 
387
425
  /**
@@ -526,6 +564,8 @@ const KNOWN: Readonly<Record<string, Readonly<Record<string, Known>>>> = {
526
564
  "expect.add": { expect: true, plan: true, kind: true, says: true, numbers: true, settings: true, note: true },
527
565
  "expect.meet": { expect: true, met: true, saw: true, run: true, note: true },
528
566
  "expect.withdraw": { expect: true, note: true },
567
+ "prospect.add": { prospect: true, name: true, kind: true, madeOf: true, note: true },
568
+ "prospect.realise": { prospect: true, strain: true, item: true },
529
569
  "item.adjust": { item: true, by: true },
530
570
  "item.recount": { item: true, amount: true },
531
571
  "item.retire": { item: true },
@@ -540,8 +580,8 @@ const KNOWN: Readonly<Record<string, Readonly<Record<string, Known>>>> = {
540
580
  outputs: [{ item: true, sequence: true, circular: true, ends: { left: true, right: true }, name: true, amount: true, unit: true }],
541
581
  },
542
582
  "plan.add": {
543
- plan: true, kind: true, instrument: true, settings: true, note: true,
544
- inputs: [{ item: true, part: true, amount: true, role: true }],
583
+ plan: true, kind: true, instrument: true, settings: true, note: true, makes: true,
584
+ inputs: [{ item: true, part: true, prospect: true, amount: true, role: true }],
545
585
  expects: [{ sequence: true, circular: true, ends: { left: true, right: true }, name: true }],
546
586
  },
547
587
  "plan.settle": { plan: true, run: true },
@@ -620,7 +660,7 @@ const areSettings = (settings: unknown): settings is Record<string, string | num
620
660
  * tools work it out again, which is why the plan carries its claim and not its working.
621
661
  */
622
662
  function planProblem(op: Operation, items: ReadonlyMap<string, unknown>, parts: ReadonlyMap<string, unknown>, places: ReadonlyMap<string, unknown>,
623
- plans: ReadonlyMap<string, unknown>): string | null {
663
+ plans: ReadonlyMap<string, unknown>, prospects: ReadonlyMap<string, unknown>): string | null {
624
664
  if (!(typeof op["plan"] === "string" && ITEM_ID.test(op["plan"])) || !text(op["kind"], 40)) return "It does not carry a plan ID and what kind of run it would be.";
625
665
  if (plans.has(op["plan"])) return "A plan with that ID already exists.";
626
666
  if (!(op["instrument"] === null || (typeof op["instrument"] === "string" && places.has(op["instrument"])))) return "The place it would be done at is not one the lab has.";
@@ -630,9 +670,12 @@ function planProblem(op: Operation, items: ReadonlyMap<string, unknown>, parts:
630
670
  if (!Array.isArray(inputs) || inputs.length > MOST_IN_A_RUN) return "It does not list what it would use.";
631
671
  for (const input of inputs as Partial<PlanInput>[]) {
632
672
  if (typeof input !== "object" || input === null || !amountOf(input.amount) || input.amount < 0 || !text(input.role, 40)) return "It does not say how many whole units of each thing it would use, and as what.";
633
- if ((input.item === undefined) === (input.part === undefined)) return "Each thing it would use has to be a tube or a part, and not both.";
673
+ if ([input.item, input.part, input.prospect].filter((one) => one !== undefined).length !== 1) {
674
+ return "Each thing it would use has to be a tube, a part or a prospect, and only one of those.";
675
+ }
634
676
  if (input.item !== undefined && !(typeof input.item === "string" && items.has(input.item))) return "A tube it would use is not an item the lab has.";
635
677
  if (input.part !== undefined && !(typeof input.part === "string" && parts.has(input.part))) return "A part it would use is not one the lab has.";
678
+ if (input.prospect !== undefined && !(typeof input.prospect === "string" && prospects.has(input.prospect))) return "A prospect it would use is not one the lab has.";
636
679
  }
637
680
  const expects = op["expects"];
638
681
  if (!Array.isArray(expects) || expects.length > MOST_IN_A_RUN) return "It does not list what it expects to make.";
@@ -641,6 +684,15 @@ function planProblem(op: Operation, items: ReadonlyMap<string, unknown>, parts:
641
684
  return "It does not give each thing it expects a sequence, a name and whether it is a circle.";
642
685
  }
643
686
  }
687
+ // What a run makes that has no sequence — a strain, a culture, a curd — is named as a prospect
688
+ // instead, so that the step after it has something to point at.
689
+ const makes = op["makes"];
690
+ if (makes !== undefined) {
691
+ if (!Array.isArray(makes) || makes.length > MOST_IN_A_RUN) return "It does not list what it would bring into existence.";
692
+ for (const one of makes as unknown[]) {
693
+ if (!(typeof one === "string" && prospects.has(one))) return "Something it would bring into existence is not a prospect the lab has.";
694
+ }
695
+ }
644
696
  return null;
645
697
  }
646
698
 
@@ -709,7 +761,7 @@ const hadSeen = (later: Node, earlier: Node): boolean => (later.vc.get(earlier.a
709
761
  * ```
710
762
  */
711
763
  export async function mergeLog(entries: readonly unknown[], options: { lab?: string } = {}): Promise<LabState> {
712
- const state: LabState = { lab: options.lab ?? null, name: null, roster: [], parts: [], items: [], places: [], crowded: [], runs: [], plans: [], strains: [], specimens: [], expectations: [], entries: [],
764
+ const state: LabState = { lab: options.lab ?? null, name: null, roster: [], parts: [], items: [], places: [], crowded: [], runs: [], plans: [], strains: [], specimens: [], expectations: [], prospects: [], entries: [],
713
765
  waiting: [], discarded: [], overlaps: [], heads: {}, knows: {} };
714
766
 
715
767
  // Read and check every entry on its own, before any of them is believed about the others.
@@ -976,6 +1028,7 @@ function fold(state: LabState, placed: Placed[], chained: Map<string, Node>): vo
976
1028
  const strains = new Map<string, { strain: StrainState; set: Map<string, Register> }>();
977
1029
  const specimens = new Map<string, { specimen: SpecimenState; set: Map<string, Register> }>();
978
1030
  const expectations = new Map<string, { expectation: ExpectationState; seen: Node | null; set: Map<string, Register> }>();
1031
+ const prospects = new Map<string, { prospect: ProspectState; set: Map<string, Register> }>();
979
1032
  /** Each plan, with the entry that settled it, if one has, and anything set on it. */
980
1033
  const plans = new Map<string, { plan: PlanState; settled: Node | null; set: Map<string, Register> }>();
981
1034
  /** Where each item was last put. */
@@ -1201,6 +1254,39 @@ function fold(state: LabState, placed: Placed[], chained: Map<string, Node>): vo
1201
1254
  // like any other, so the same rule settles it and every lab reads the same answer.
1202
1255
  write(held.set, "is", node, op["part"], `what specimen ${op["specimen"]} is`);
1203
1256
  }
1257
+ } else if (op.type === "prospect.add") {
1258
+ if (!(typeof op["prospect"] === "string" && ITEM_ID.test(op["prospect"])) || !text(op["name"], 200)
1259
+ || !text(op["kind"], 40) || !text(op["madeOf"], 2_000)
1260
+ || !(op["note"] === null || text(op["note"], 2_000))) {
1261
+ refuse("It does not carry a prospect ID, what to call it, what kind of thing it is, what it would be made of, and a note or nothing.");
1262
+ } else if (prospects.has(op["prospect"])) {
1263
+ refuse("A prospect with that ID already exists.");
1264
+ } else {
1265
+ prospects.set(op["prospect"], {
1266
+ prospect: { prospect: op["prospect"], name: op["name"], kind: op["kind"], madeOf: op["madeOf"],
1267
+ note: op["note"] as string | null, became: null, by: node.author, fields: {}, added: node.id },
1268
+ set: new Map([["name", { node, value: op["name"] }]]),
1269
+ });
1270
+ }
1271
+ } else if (op.type === "prospect.realise") {
1272
+ const held = typeof op["prospect"] === "string" ? prospects.get(op["prospect"]) : undefined;
1273
+ const strain = op["strain"], item = op["item"];
1274
+ if (held === undefined) {
1275
+ refuse("The prospect it says was made is not one the lab has.");
1276
+ } else if ([strain, item].filter((one) => one !== null && one !== undefined).length !== 1) {
1277
+ refuse("A prospect becomes a strain or an item, and only one of those.");
1278
+ } else if (strain !== null && strain !== undefined && !(typeof strain === "string" && strains.has(strain))) {
1279
+ refuse("The strain it says the prospect became is not one the lab has.");
1280
+ } else if (item !== null && item !== undefined && !(typeof item === "string" && items.has(item))) {
1281
+ refuse("The item it says the prospect became is not one the lab has.");
1282
+ } else {
1283
+ // Two people may make the same thing and say so without knowing of each other. It is a
1284
+ // register like any other, so the same rule settles it and every lab reads the same answer.
1285
+ // What it became and which kind of thing that is are one fact and go in one register: two
1286
+ // registers could be won by different writers, and leave a strain's ID labelled an item.
1287
+ const became = strain !== null && strain !== undefined ? `strain:${strain}` : `item:${item}`;
1288
+ write(held.set, "became", node, became, `what prospect ${op["prospect"]} became`);
1289
+ }
1204
1290
  } else if (op.type === "expect.add") {
1205
1291
  const numbers = op["numbers"], settings = op["settings"];
1206
1292
  if (!(typeof op["expect"] === "string" && ITEM_ID.test(op["expect"])) || !text(op["kind"], 40) || !text(op["says"], 2_000)
@@ -1275,7 +1361,7 @@ function fold(state: LabState, placed: Placed[], chained: Map<string, Node>): vo
1275
1361
  held.expectation.withdrawn = { note: op["note"] as string | null, by: node.author, entry: node.id };
1276
1362
  }
1277
1363
  } else if (op.type === "plan.add") {
1278
- const problem = planProblem(op, items, parts, places, plans);
1364
+ const problem = planProblem(op, items, parts, places, plans, prospects);
1279
1365
  if (problem !== null) { refuse(problem); continue; }
1280
1366
  const expects: PlanState["expects"] = [];
1281
1367
  try {
@@ -1291,7 +1377,10 @@ function fold(state: LabState, placed: Placed[], chained: Map<string, Node>): vo
1291
1377
  settled: null, set: new Map(),
1292
1378
  plan: {
1293
1379
  plan: op["plan"] as string, kind: op["kind"] as string, instrument: op["instrument"] as string | null,
1294
- inputs: (op["inputs"] as PlanInput[]).map((input) => ({ ...(input.item === undefined ? { part: input.part! } : { item: input.item }), amount: input.amount, role: input.role })),
1380
+ inputs: (op["inputs"] as PlanInput[]).map((input) => ({
1381
+ ...(input.item !== undefined ? { item: input.item } : input.part !== undefined ? { part: input.part } : { prospect: input.prospect! }),
1382
+ amount: input.amount, role: input.role })),
1383
+ makes: [...((op["makes"] as string[] | undefined) ?? [])],
1295
1384
  expects, settings: { ...(op["settings"] as Record<string, string | number>) }, note: op["note"] as string | null,
1296
1385
  by: node.author, settled: null, wanting: [], orphaned: [], fields: {}, added: node.id,
1297
1386
  },
@@ -1321,13 +1410,15 @@ function fold(state: LabState, placed: Placed[], chained: Map<string, Node>): vo
1321
1410
  : op["on"] === "strain" && typeof op["id"] === "string" ? strains.get(op["id"])
1322
1411
  : op["on"] === "specimen" && typeof op["id"] === "string" ? specimens.get(op["id"])
1323
1412
  : op["on"] === "plan" && typeof op["id"] === "string" ? plans.get(op["id"])
1324
- : op["on"] === "expectation" && typeof op["id"] === "string" ? expectations.get(op["id"]) : undefined;
1325
- if (target === undefined) { refuse("It does not name a part, an item, a place, a strain, a specimen, a plan or an expectation the lab has."); continue; }
1413
+ : op["on"] === "expectation" && typeof op["id"] === "string" ? expectations.get(op["id"])
1414
+ : op["on"] === "prospect" && typeof op["id"] === "string" ? prospects.get(op["id"]) : undefined;
1415
+ if (target === undefined) { refuse("It does not name a part, an item, a place, a strain, a specimen, a plan, an expectation or a prospect the lab has."); continue; }
1326
1416
  if (op["on"] === "place" && typeof field === "string" && PLACE_RESERVED.has(field)) { refuse("It does not name a field that can be set."); continue; }
1327
1417
  if (op["on"] === "strain" && typeof field === "string" && STRAIN_RESERVED.has(field)) { refuse("It does not name a field that can be set."); continue; }
1328
1418
  if (op["on"] === "specimen" && typeof field === "string" && SPECIMEN_RESERVED.has(field)) { refuse("It does not name a field that can be set."); continue; }
1329
1419
  if (op["on"] === "plan" && typeof field === "string" && PLAN_RESERVED.has(field)) { refuse("It does not name a field that can be set."); continue; }
1330
1420
  if (op["on"] === "expectation" && typeof field === "string" && EXPECT_RESERVED.has(field)) { refuse("It does not name a field that can be set."); continue; }
1421
+ if (op["on"] === "prospect" && typeof field === "string" && PROSPECT_RESERVED.has(field)) { refuse("It does not name a field that can be set."); continue; }
1331
1422
  // An adviser may file its own proposals and nothing else. It proposes the work, so leaving it
1332
1423
  // unable to say which project the work is for would have a person filing every step by hand;
1333
1424
  // letting it set any field at all would let it rename the lab's parts. This is the same line
@@ -1371,6 +1462,21 @@ function fold(state: LabState, placed: Placed[], chained: Map<string, Node>): vo
1371
1462
  }
1372
1463
  state.specimens.push(specimen);
1373
1464
  }
1465
+ for (const { prospect, set } of prospects.values()) {
1466
+ for (const [field, held] of set) {
1467
+ if (field === "name") prospect.name = held.value as string;
1468
+ else if (field === "became") { /* read below, as one value */ }
1469
+ else prospect.fields[field] = held.value as string | number | null;
1470
+ }
1471
+ const became = set.get("became");
1472
+ if (became !== undefined) {
1473
+ const [kind, ...rest] = String(became.value).split(":");
1474
+ const id = rest.join(":");
1475
+ prospect.became = { strain: kind === "strain" ? id : null, item: kind === "item" ? id : null,
1476
+ by: became.node.author, entry: became.node.id };
1477
+ }
1478
+ state.prospects.push(prospect);
1479
+ }
1374
1480
  for (const { expectation, set } of expectations.values()) {
1375
1481
  for (const [field, held] of set) expectation.fields[field] = held.value as string | number | null;
1376
1482
  state.expectations.push(expectation);
package/src/method.ts CHANGED
@@ -161,7 +161,13 @@ export function publicMethod(state: LabState, lab: LabModel, options: MethodOpti
161
161
  step: at + 1,
162
162
  kind: plan.kind,
163
163
  uses: plan.inputs.map((input): MethodInput => {
164
- const what = input.item === undefined
164
+ // A prospect has no checksum, for the same reason a culture and a specimen have none: there
165
+ // is no sequence to count one over. So it cannot travel either. What is honest to say is that
166
+ // the step rests on something nobody had made, and what kind of thing that was — a taking lab
167
+ // can then see where the method stops being something it can follow.
168
+ const what = input.prospect !== undefined
169
+ ? { part: null, name: `something the publishing lab had not made: a ${state.prospects.find((one) => one.prospect === input.prospect)?.kind ?? "thing"}`, unit: null }
170
+ : input.item === undefined
165
171
  ? { part: input.part!, name: state.parts.find((one) => one.checksum === input.part)?.name ?? "a part", unit: null }
166
172
  : whatIsIn(input.item);
167
173
  const maker = what.part === null ? undefined : madeBy.get(what.part);