Repository navigation
Expand file tree
/
Copy pathprotocol-stored-form-migration.ts
More file actions
1877 lines (1788 loc) · 104 KB
/
Copy pathprotocol-stored-form-migration.ts
File metadata and controls
1877 lines (1788 loc) · 104 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
/**
* # The stored-form ceremony, its read-only half (ADR-0159 D7, card ⑤a)
*
* Major 19 retires the three old shapes of a form (a `view` container's
* `form`, a `formViews` entry, a `viewKind: 'form'` item). A stored row cannot
* change its type in the stored pass, so the rows that hold a form in an old
* shape are moved by a ceremony the major's upgrade command runs: convert,
* then switch, all or nothing (ruling `7142585849` 2 and the addendum
* `7142658348`). This module is the read-only half: the census of what the
* ceremony would do, and the precheck that says whether the upgrade may
* switch. `os migrate stored-forms` (`@objectstack/cli`) prints it; it writes
* nothing. The move, the fold and the removal are the ceremony's write half,
* reached only from the upgrade command.
*
* ## The population
*
* Every active environment row of the `form` and `view` types (both
* spellings), read as the effective `form` read reads them:
* `storedFormPlaces` (`protocol-form-reads.ts`), the one reading. Draft `view`
* rows that carry form content are listed apart (`drafts`) and neither moved
* nor deleted: no read serves them, and after the upgrade they cannot be
* published (maintainer ruling `7250982640`). A move names the drafts of the
* row it moves, left behind (`draftsLeftBehind`).
*
* ## Per form name, per package address
*
* A form name is resolved at each address that can serve it, as D5 asks
* "served": each read-only package that ships the name in either type (the
* base), each writable package that ships it or holds a row of it of its own,
* and, when no package addresses it and no stored row of it is bound to a
* package, the environment's own address. Each row is read at the one address
* its binding names ({@link bindingOf}): a pair's declared override at its
* base, a row bound to a package at that package, a package-less row at every
* address of the name. A pair's declared override of a base that ships no
* form of the name is read at the pair's own address, unless a stored row of
* the name is bound to that base: the read then serves the override at the
* base's address, ahead of the bound row, which it serves nowhere, so the
* override is read there ({@link pairServedAtUnshippedBase}; where two pairs
* of the base each hold one, only the pair the read serves there, and the
* other pair's keeps its own address). A row the read serves at another
* address than the package it is bound to is read at each address that
* serves it, and classed by the base it stands over there
* ({@link servedAtAnotherAddress}; ruling record `7254350842`). The rows at
* an address are taken in
* the served-row order (`orderedFormRowsAt`, the order the read serves): the
* first is the served row; the form rows behind it fold into it, and a row
* behind that holds no form at the name (a list) is left as stored (ruling
* 3). A plan names every row of it another address reads too, with that
* address's outcome (`alsoReadAt`).
*
* What the address gets ({@link StoredFormAddressPlan}):
*
* - `keep` — the served row is already a stored `form` row at the
* destination. The rows behind it fold into it.
* - `move` — the served row holds an old-shape form, or a `form` row bound
* elsewhere, that is not internal: it moves to the destination with its
* body as written (D7-a, D7-b), and the rows behind fold into it. At a
* base the destination is the declared `form` override in the base's pair
* (`overrides: { package, basedOn }`), and a pair's own stored `view`
* override keeps its pair and `basedOn` (nothing to ensure); at a writable
* package, that package's own `form` row; at the environment, a
* package-less `form` row (`form` allows a runtime create). A row bound to
* a read-only package that ships no form of the name, or a pair's override
* of a base that ships none, moves into that package's pair as the pair's
* own `form` item, declaring no `overrides` (maintainer ruling
* `7250977204`, `pair_form`). Where both hold one name, the override is
* the served row at the base's address and the bound row folds behind it
* (D7-d): one move, into the pair the override stands in.
* - `remove` — the served row is an internal record form (ADR-0159 D7, all
* three parts: a record-form slot, no `sharing.publicLink`, no
* `type: 'form'` action target, and not over a base form that declares a
* link). A deletion is per row: a row read at several addresses is removed
* only when it is internal at every one of them, and moves at each of them
* otherwise. The upgrade removes it, in the run that switches (ruling 3),
* with the form rows behind it. A row behind that is the served row at
* another address is not one of them: it is not removed with the form in
* front of it, and gets what that address gives it (`servedElsewhere`;
* D7-e: a row that stands over a linked base is never listed for removal).
* Not counted.
* - `hold` — the move needs the base's pair and the pair cannot be ensured
* (D7-c). Counted: the upgrade does not switch. So does a move whose
* destination row the store seals (ADR-0131 D6): every destination but a
* declared override is written as an edit of the item a package ships at
* the name, and a managed package that ships the name as a `form` item
* seals it, so the census holds the row the run could not write
* ({@link sealedDestinationHold}). The hold names the cause,
* repeats the ensure door's refusal, and gives the action for its cause.
* A slot of a pair that more than one plan claims holds too, at every
* claimant's address, the row named once ({@link holdContestedPairSlots};
* ruling record `7265816895` on #38661). So does a row the read serves at
* more than one address, whatever App each is of, where those addresses
* would not all move it or all remove it: at each of them
* ({@link holdRowsServedApart}); the row behind an internal form left in
* place counts as kept at that address (ruling record 7249158572). A row
* kept as stored under that ruling is folded, moved or removed at no
* address: a plan that would do any of it holds, and lists it apart
* ({@link holdChangesToKeptRows}).
* - `left_in_place` — nothing moves at the address, and nothing is counted:
* the served row carries no form at the name (a list, D7-d: every row of
* the name at the address stays as stored; a list alone over a base that
* ships the form is reported too), or the served row is internal and a row
* behind it declares a link ({@link INTERNAL_AHEAD_OF_LINKED_ROW}), or the
* plan would move a form no door serves today (`served_by_no_door`: the
* effective `form` read lists no form of the name at the address; the
* plan is made first, so a hold it takes part in stands, and its move is
* then left in place, whatever package the row is bound to).
*
* A body the projection cannot read (D6 rule 7) holds the upgrade wherever it
* stands (D7-c, `unreadable`), and an address whose served row is one waits
* on it (`left_in_place`, `served_unreadable`: the hold is counted once, on
* the row). A name no package ships has the environment's own address only
* while no stored row of it is bound to a package.
*
* ## The fold (D7-d)
*
* The body kept is the served one. A folded row carries one thing only: an
* explicit withdrawal (`formExplicitlyWithdraws`), which the destination takes
* by keeping its own link and switching it off. Where the kept body names no link
* there is no switch to carry, and its replacement of the base keeps the
* address closed already. A withdrawal carried from a row that no layer reads
* today closes a form that is open today: the plan names it `newlyClosed`.
*
* Pure over what the host reads ({@link planStoredForms} is pure over its
* input): no write, no registry mutation.
*/
import { pairOf, pairsOf, type InstalledManifestLookup, type PairOfRefusal } from '@objectstack/metadata-core';
import { deriveViewContainerObject } from '@objectstack/spec';
import {
customizationBasePackageId,
customizationDependencyRange,
customizationNamespace,
} from '@objectstack/spec/kernel';
import {
expandViewContainerWithDiagnostics,
formExplicitlyWithdraws,
isAggregatedViewContainer,
projectViewForms,
publicFormSlug,
} from '@objectstack/spec/ui';
import { installedManifestsOfEngine } from './installed-manifests.js';
import { customizationPairEnsureRefusal, kernelPackageScope, type PairRegistry } from './protocol-customization-package.js';
import {
orderedFormRowsAt,
readEffectiveForms,
storedFormPlaces,
type FormReadHost,
type OrderedFormRow,
type StoredFormPlace,
} from './protocol-form-reads.js';
import { protocolHost, type ProtocolHost } from './protocol-host.js';
import type { ShipsName } from './suite-moved-overlay.js';
import type { ObjectStackProtocolImplementation } from './protocol.js';
// ── The report's shapes ─────────────────────────────────────────────────────
/** One stored row, as the report names it. */
export interface StoredFormRowRef {
/** The row's `type` column (`view` or `form`, either spelling). */
readonly type: string;
/** The row's own `name` column: a container's name, for a container's form. */
readonly name: string;
readonly packageId?: string;
/** The form name the row holds here: the name the read serves it under. */
readonly form: string;
/** `expansion` for a container's member, `item` for a row stored under the name. */
readonly grain: 'item' | 'expansion';
/** What the row holds at the name: a form, a list, or a body the projection cannot read. */
readonly holds: 'form' | 'list' | 'unreadable';
/** The slug of the `sharing.publicLink` the row's form declares, if any. */
readonly link?: string;
/** The slug the row's form explicitly withdraws (link kept, a switch `false`), if any. */
readonly withdraws?: string;
/** The base the row declares it overrides, when it is a pair's declared override. */
readonly overrideOf?: string;
}
/** The address a form name is resolved at. */
export type StoredFormAddress =
| { readonly kind: 'base'; readonly packageId: string }
| { readonly kind: 'package'; readonly packageId: string }
| { readonly kind: 'environment' };
/** Where a moved row lands. */
export type StoredFormDestination =
| { readonly kind: 'pair_override'; readonly base: string; readonly pair: string; readonly basedOn: string }
/**
* The pair's own `form` item, declaring no `overrides`: the destination of
* a row bound to a read-only package that ships no form of the name
* (maintainer ruling `7250977204`, ADR-0146's precedent for a member the
* base does not ship).
*/
| { readonly kind: 'pair_form'; readonly base: string; readonly pair: string }
| { readonly kind: 'package_form'; readonly packageId: string }
| { readonly kind: 'environment_form' };
/** Who can remove the cause of a hold (ADR-0159 D7-c). */
export type StoredFormHoldCause =
/** A cause the administrator removes in the deployment, on the pre-upgrade release. */
| 'administrator'
/** A cause only the App's author removes: the deployment stays on the current major until then. */
| 'app_author'
/** A base that has no pair in this version (a kernel package). */
| 'kernel'
/** A body the projection cannot read (D6 rule 7). */
| 'unreadable';
/** Why an address moves nothing and counts nothing. */
export type StoredFormLeftReason =
/** The served row carries no form at the name: every row of the name at the address stays (D7-d). */
| 'served_no_form'
/** {@link INTERNAL_AHEAD_OF_LINKED_ROW}. */
| 'internal_ahead_of_linked_row'
/** The served row is a body the projection cannot read: the address waits on its hold. */
| 'served_unreadable'
/**
* A form no door serves today is left in place by the upgrade: the
* effective `form` read lists no form of the name at the address the plan
* is made at ({@link StoredFormPlanInput.servedToday}). Not a withdrawn
* form, which the read lists switched off and D7 moves with its switch.
*/
| 'served_by_no_door';
/** A folded row's withdrawal the destination carries (D7-d). */
export interface StoredFormCarriedWithdrawal {
/** The kept body's own slug: the address the carried withdrawal switches off. */
readonly slug: string;
readonly from: StoredFormRowRef;
}
/** Another address that reads a row of this plan, and what it does there (a package-less row is read at every address of its name). */
export interface StoredFormElsewhere {
readonly row: StoredFormRowRef;
readonly address: StoredFormAddress;
readonly outcome: StoredFormAddressPlan['outcome'];
/** Whether the row is the served row there. */
readonly served: boolean;
}
interface StoredFormAddressPlanBase {
readonly form: string;
readonly address: StoredFormAddress;
/** The served row: the one whose body the ceremony keeps or removes. */
readonly served: StoredFormRowRef;
/**
* The other rows of the name at the address that hold a form, in the
* served-row order: they fold into the served row, or go with its removal.
* A removal takes no row that is the served row at another address: such
* a row is listed apart (`servedElsewhere`), never here.
*/
readonly behind: readonly StoredFormRowRef[];
/** The rows behind that hold no form at the name (a list, or a body the projection cannot read): the ceremony leaves each as stored (ruling 3). */
readonly untouched: readonly StoredFormRowRef[];
/** The rows of this plan that another address reads too, with what that address does. */
readonly alsoReadAt: readonly StoredFormElsewhere[];
}
/** What the ceremony does with one form name at one address. */
export type StoredFormAddressPlan =
| (StoredFormAddressPlanBase & {
readonly outcome: 'keep' | 'move';
readonly destination: StoredFormDestination;
/** The withdrawal the destination takes from a folded row, if any. */
readonly carries?: StoredFormCarriedWithdrawal;
/** Open today, closed by the carried withdrawal: the administrator switches it on again in Setup. */
readonly newlyClosed: boolean;
/** Drafts of the served row, left behind as stored when it moves. */
readonly draftsLeftBehind?: readonly StoredFormDraft[];
/**
* The form rows behind the served row that hold the upgrade where they
* are served: a held row is folded into no other row (ADR-0159 D7), so
* each is listed here and not in `behind`, and takes no part in the fold.
*/
readonly heldApart?: readonly StoredFormRowRef[];
})
| (StoredFormAddressPlanBase & {
readonly outcome: 'remove';
/** The object the record form is of. */
readonly object?: string;
/** Whether that object declares `fieldGroups` (New and Edit follow them after the removal). */
readonly objectHasFieldGroups: boolean;
/**
* The form rows behind the removed form that are the served row at
* another address. None is removed with it: each gets what that
* address gives it, which `alsoReadAt` names (ADR-0159 D7-e).
*/
readonly servedElsewhere?: readonly StoredFormRowRef[];
})
| (StoredFormAddressPlanBase & {
readonly outcome: 'hold';
readonly cause: StoredFormHoldCause;
/**
* Why the row holds: the ensure door's own refusal, repeated; or, for a
* hold the planner gives, the slot it would claim with another plan or
* the addresses that serve it and what each would do with it.
*/
readonly refusal: string;
/** The action for the cause. */
readonly action: string;
/**
* The form rows behind the served row kept as stored under ruling
* record 7249158572 at another address: listed here and not in
* `behind`, since no plan folds or removes them ({@link holdChangesToKeptRows}).
*/
readonly heldApart?: readonly StoredFormRowRef[];
})
| (StoredFormAddressPlanBase & {
readonly outcome: 'left_in_place';
readonly reason: StoredFormLeftReason;
});
/** A row that holds the upgrade: the precheck's one entry shape. */
export interface StoredFormHold {
readonly row: StoredFormRowRef;
/** The base whose pair the move needs; absent for an unreadable body and for a hold the planner gives (a contested slot, a row served apart). */
readonly base?: string;
readonly cause: StoredFormHoldCause;
readonly refusal: string;
readonly action: string;
}
/** The census `os migrate stored-forms` prints. */
export interface StoredFormCensus {
/** One plan per form name and address, ordered by name then address. */
readonly forms: readonly StoredFormAddressPlan[];
/** Every stored `view` body the projection cannot read, each holding the upgrade. */
readonly unreadable: readonly StoredFormHold[];
/**
* Draft `view` rows that carry form content in an old shape: no read
* serves them, the ceremony neither moves nor deletes them, and after the
* upgrade they cannot be published (maintainer ruling `7250982640`).
*/
readonly drafts: readonly StoredFormDraft[];
/** A public slug declared by more than one form name across the stored rows (a retired form and its successor, say). */
readonly sharedSlugs: readonly { readonly slug: string; readonly forms: readonly string[] }[];
readonly precheck: StoredFormPrecheck;
}
/** A draft row the report names. */
export interface StoredFormDraft {
readonly type: string;
readonly name: string;
readonly packageId?: string;
}
/** Whether the upgrade may switch: it does when no row holds it (ruling 2). */
export interface StoredFormPrecheck {
readonly canSwitch: boolean;
readonly holds: readonly StoredFormHold[];
/** The counts per outcome, for the one-line summary. */
readonly counts: Readonly<Record<StoredFormAddressPlan['outcome'], number>>;
}
// ── The planner's input ─────────────────────────────────────────────────────
/** One package's form of a name, as the registry ships it (either type, through the projection). */
export interface ShippedForm {
readonly packageId: string;
readonly writable: boolean;
readonly form: Record<string, unknown> | undefined;
}
/** Whether the base's pair can be ensured for the move, and if not, why. */
export type PairFixReading =
| { readonly ok: true; readonly pair: string; readonly basedOn: string }
| {
readonly ok: false;
readonly cause: PairHoldCause;
readonly refusal: string;
readonly app?: string;
/** The per-package pair an earlier version created that holds the namespace (ADR-0146 D3, merge question 12). */
readonly earlierPair?: boolean;
/**
* The pair the door would ensure, where the only refusal is the base
* recording no version: a declared override has no `basedOn` to
* declare, while the pair's own `form` item declares none and moves
* (N14).
*/
readonly pairWithoutBasedOn?: string;
};
/** The hold causes the pair door's refusal can carry. */
export type PairHoldCause = Exclude<StoredFormHoldCause, 'unreadable'>;
/** Everything {@link planStoredForms} reads: pure data and pure lookups. */
export interface StoredFormPlanInput {
readonly places: readonly StoredFormPlace[];
readonly installed: InstalledManifestLookup;
/** The packages that ship `name` as a form, in either type. */
readonly shippedForms: (name: string) => readonly ShippedForm[];
readonly isWritable: (packageId: string) => boolean;
/** Every name a `type: 'form'` action opens, anywhere it is declared. */
readonly actionTargets: ReadonlySet<string>;
readonly pairFix: (base: string) => PairFixReading;
/**
* [ADR-0131 D6] The managed packages that ship `name` as a `form` item,
* where the store seals a `form` row of the name against a write as that
* item's edit; `[]` where it does not. Read as the run's write meets it
* ({@link storedFormSealedShippers}).
*/
readonly sealedFormShippers: (name: string) => readonly string[];
/**
* Whether the effective `form` read the doors take their candidates from
* ({@link readEffectiveForms}) lists a form of `name` at `packageId` today
* (`undefined`: the environment's own address).
*/
readonly servedToday: (name: string, packageId: string | undefined) => boolean;
readonly objectHasFieldGroups: (object: string) => boolean;
/** The stored `view` bodies the projection cannot read. */
readonly unreadable: readonly { readonly type: string; readonly name: string; readonly packageId?: string; readonly reason: string; readonly links: readonly string[] }[];
readonly drafts?: readonly StoredFormDraft[];
/**
* The packages that ship an item of `name` in the `view` type, a list or
* a form in the old shape: the reading the served `view` list takes of
* the name, which {@link servedAtAnotherAddress} asks as that list does.
*/
readonly shipsView: (name: string) => readonly string[];
}
// ── The rules ───────────────────────────────────────────────────────────────
const isRecord = (value: unknown): value is Record<string, unknown> =>
!!value && typeof value === 'object' && !Array.isArray(value);
/** The slug of the `sharing.publicLink` a form declares, switched on or off. */
function linkOf(form: unknown): string | undefined {
const sharing = isRecord(form) ? form.sharing : undefined;
const link = isRecord(sharing) ? sharing.publicLink : undefined;
return typeof link === 'string' && link !== '' ? publicFormSlug(link) : undefined;
}
/** The base a stored body declares it overrides. */
function declaredOverrideOf(body: unknown): string | undefined {
const overrides = isRecord(body) ? body.overrides : undefined;
const pkg = isRecord(overrides) ? overrides.package : undefined;
return typeof pkg === 'string' && pkg !== '' ? pkg : undefined;
}
/**
* [ADR-0159 D7] The record-form slots a stored `view` row puts a form in,
* named as the read serves them: the container's default `form`, its
* `formViews.default` and `formViews.create`, an item with `isDefault: true`,
* and any form named `OBJECT.create` — the slots `form-view-internal-not-loaded`
* names. The expansion is the spec's own, so the names are the served ones.
*/
function recordSlotNames(body: unknown): Set<string> {
const out = new Set<string>();
if (!isRecord(body)) return out;
if (isAggregatedViewContainer(body)) {
const object = deriveViewContainerObject(body);
if (object === undefined) return out;
let expanded: ReturnType<typeof expandViewContainerWithDiagnostics>;
try {
expanded = expandViewContainerWithDiagnostics(object, body);
} catch {
return out;
}
for (const item of expanded.items) {
if (item.viewKind !== 'form') continue;
if (item.isDefault === true || item.name === `${object}.create`) out.add(item.name);
}
for (const key of ['default', 'create']) {
const entry = isRecord(body.formViews) ? body.formViews[key] : undefined;
if (!isRecord(entry)) continue;
const renamed = expanded.collisions.find((c) => c.viewKind === 'form' && c.key === key)?.renamedTo;
out.add(renamed ?? `${object}.${key}`);
}
return out;
}
const name = typeof body.name === 'string' ? body.name : undefined;
if (body.viewKind === 'form' && name !== undefined) {
const projected = projectViewForms(body).forms.find((f) => f.name === name);
const object = typeof projected?.object === 'string' ? projected.object : undefined;
if (body.isDefault === true || (object !== undefined && name === `${object}.create`)) out.add(name);
}
return out;
}
function rowRef(row: OrderedFormRow, form: string): StoredFormRowRef {
const { place, holding } = row;
const item = holding.kind === 'form' ? holding.item : undefined;
const link = linkOf(item);
const withdraws = item === undefined ? undefined : formExplicitlyWithdraws(item);
return {
type: place.entry.type,
name: place.entry.name,
...(place.packageId !== undefined ? { packageId: place.packageId } : {}),
form,
grain: place.grain,
holds: holding.kind === 'form' ? 'form' : holding.reason,
...(link !== undefined ? { link } : {}),
...(withdraws !== undefined ? { withdraws } : {}),
...(row.overrideOf !== undefined ? { overrideOf: row.overrideOf } : {}),
};
}
type Binding =
| { readonly kind: 'packageless' }
/**
* `unshipped`: the row is bound to a read-only package that ships no form
* of the name (`packageId` is that package), or is a pair's declared
* override of a base that ships none (`packageId` is the pair). Its
* destination is the pair's own `form` item (maintainer ruling `7250977204`).
*/
| { readonly kind: 'at'; readonly packageId: string; readonly unshipped?: { readonly base: string } }
/** Read at each of `at`, the addresses that serve the row today ({@link servedAtAnotherAddress}). */
| { readonly kind: 'elsewhere'; readonly at: readonly string[] };
/**
* The one address a row of `name` is read at (ADR-0159 D7-d): `packageless`
* for a row bound to no package (read at every address of the name), the
* base for a pair's declared override of a base, the package for a row bound
* to a writable package or to a read-only package that ships the name. A row
* bound to a read-only package that ships no form of the name, or a pair's
* declared override of a base that ships none, is read at the package it is
* bound to (the read seats a slot for every package a stored row is bound
* to), and is marked `unshipped`: its destination is the pair's own `form`
* item (maintainer ruling `7250977204`). One such override is read at its
* base instead, where a stored row seats that address
* ({@link pairServedAtUnshippedBase}, applied over the name's bindings).
*/
function bindingOf(
place: StoredFormPlace,
name: string,
input: Pick<StoredFormPlanInput, 'installed' | 'isWritable'>,
shipsReadOnly: (packageId: string, name: string) => boolean,
): Binding {
if (place.packageId === undefined) return { kind: 'packageless' };
const base = declaredOverrideOf(place.entry.data);
if (base !== undefined && base !== place.packageId && pairsOf(base, input.installed).includes(place.packageId)) {
return shipsReadOnly(base, name) ? { kind: 'at', packageId: base } : { kind: 'at', packageId: place.packageId, unshipped: { base } };
}
if (input.isWritable(place.packageId)) return { kind: 'at', packageId: place.packageId };
return shipsReadOnly(place.packageId, name)
? { kind: 'at', packageId: place.packageId }
: { kind: 'at', packageId: place.packageId, unshipped: { base: place.packageId } };
}
/**
* [ADR-0159 D7; ruling record 7254350842 on #37111] The rows of `name` the
* read serves at another address than the package each is bound to, with
* those addresses: THE one place this case is decided. The question is put
* to the served-row order at every package that ships the form
* (`orderedFormRowsAt` asked with `ships`; `suite-moved-overlay.ts` has the
* rule), so a row two of them serve is read at both, and where the read
* serves neither of two rows that could each follow the name, neither is
* here: each keeps its own address.
*
* Such a row is classed by the base it stands over at each address (D7-b)
* and takes the destination D7 gives a row bound to that base, with D7-c's
* hold where its pair cannot be ensured; D7-e is unchanged, and ruling
* `7250977204` stands for every row its premise holds for.
*/
function servedAtAnotherAddress(
holding: readonly StoredFormPlace[],
name: string,
formShippers: readonly string[],
installed: InstalledManifestLookup,
ships: ShipsName,
): Map<StoredFormPlace, string[]> {
const out = new Map<StoredFormPlace, string[]>();
for (const shipper of formShippers) {
for (const row of orderedFormRowsAt(holding, name, shipper, installed, undefined, ships)) {
if (row.moved !== undefined) out.set(row.place, [...(out.get(row.place) ?? []), shipper]);
}
}
return out;
}
/**
* [ADR-0159 D7-d; maintainer ruling `7250977204`] A pair's declared override
* of a base that ships no form of the name, where a stored row of the name
* is bound to that base: THE one place this case is decided. It answers the
* pair whose overrides are read at the base's address, or `undefined` when
* none is.
*
* The read seats a slot for every package a stored row is bound to
* (`mergePackageAwareOverlay`), and at that slot the served-row order tries
* the pair's declared override first, whether or not the base ships the name
* (`isServedOverrideRowOf` does not ask). So the override is the row served
* at the base's address, and the row bound to the base is served nowhere.
* Read at the base's address, the override is the served row there, the
* bound row folds behind it, and one move goes to the pair's own `form`
* item. Read apart, at two addresses, each row would move there, and the
* ceremony would serve a body the read does not serve today (D7-d).
*
* Only the pair the order serves at the base's address is read there, with
* every override of the base it holds at the name (a `form` row ahead of a
* `view` row, as the order has them). The App's pair and an earlier
* per-package pair can each hold one: the second pair's is not served at the
* base, and stays at its own pair's address, where the read serves it. With
* no stored row bound to the base, nothing seats its address, and every such
* override stays at its own pair's.
*/
function pairServedAtUnshippedBase(
places: readonly StoredFormPlace[],
name: string,
base: string,
installed: InstalledManifestLookup,
): string | undefined {
if (!places.some((place) => place.packageId === base && place.holds.has(name))) return undefined;
// The served-row order at the base's address, over every stored row: the read's own order.
const [first] = orderedFormRowsAt(places, name, base, installed);
return first !== undefined && first.overrideOf === base ? first.place.packageId : undefined;
}
/**
* [ADR-0159 D7-d] The row the read serves at `packageId`'s address, where
* that row is one the plan reads at other addresses and not at this one:
* THE one place this case is decided. It answers that row, or `undefined`
* when the address's served row is one of its own.
*
* The plan keeps each row to the addresses its binding names, so at the
* address of a package a row is bound to it orders the rows bound there
* alone. D7-d finds the served row among every stored row at the address:
* where the read's own order there is headed by a row the plan reads
* elsewhere ({@link servedAtAnotherAddress}), every row bound to this
* address stands behind it and is served nowhere today. Such a row folds
* behind that row where that row is planned, and the address gets no plan
* of its own: a body the read does not serve today is never served by the
* ceremony.
*
* `layer` is the row the package's per-package layer reads today: the first
* row of the order that is not the pair's override. A withdrawal carried
* from it closes its name today ({@link foldOf}); one carried from another
* row bound to the address is read by no layer.
*/
function servedAheadFromElsewhere(
places: readonly StoredFormPlace[],
name: string,
packageId: string,
bindings: ReadonlyMap<StoredFormPlace, Binding>,
installed: InstalledManifestLookup,
ships: ShipsName,
): { readonly at: readonly string[]; readonly layer: StoredFormPlace | undefined } | undefined {
// The served-row order at the address, over every stored row: the read's own order.
const order = orderedFormRowsAt(places, name, packageId, installed, undefined, ships);
const binding = order[0] === undefined ? undefined : bindings.get(order[0].place);
if (binding?.kind !== 'elsewhere' || binding.at.includes(packageId)) return undefined;
return { at: binding.at, layer: order.find((row) => row.overrideOf === undefined)?.place };
}
/**
* [ADR-0159 D7-d; maintainer ruling 「两行都不动,写进报告」, ruling record
* 7249158572 on #37111] An internal record form is the served row, and a row
* behind it at the same address declares a `sharing.publicLink`, switched on
* or off: THE one place this case is decided. Neither row moves and no row of
* the name is deleted; the report names both as left in place (the internal
* form is not removed because a row with a public link stands behind it), and
* the upgrade is not held — a "not counted" kind beside the two of ruling
* 7136809727 and the one ADR-0159 adds, on the same whole-name-left branch.
*
* The ruling answers the package-less row behind; the predicate is wider (any
* linked row behind, e.g. a base-bound one behind an internal pair override),
* which is ADR-0159 D7-d's own reading of that ruling, open to correction.
* Narrowing it would send those shapes to the removal branch, which deletes
* the row that holds the address closed.
*
* Whatever the answer, the address answers `404` on both doors before and
* after the ceremony: the served internal row serves no link, and a body not
* served today is never served by the ceremony.
*/
export const INTERNAL_AHEAD_OF_LINKED_ROW = {
/** Whether the case applies: the served row is internal, and a row behind it declares a link. */
applies: (servedIsInternal: boolean, behind: readonly StoredFormRowRef[]): boolean =>
servedIsInternal && behind.some((row) => row.link !== undefined),
/** What the address gets: option D, left in place and not counted. */
outcome: 'left_in_place' as const,
reason: 'internal_ahead_of_linked_row' as const,
};
/**
* [ADR-0159 D7-c] The action an administrator reads for a hold's cause.
* `contested`: the hold of a pair's slot that more than one plan claims
* ({@link holdContestedPairSlots}), for a row read at two addresses or for
* a slot other rows claim too; `kept`, the hold of a plan that would change a
* row kept as stored at another address ({@link holdChangesToKeptRows}),
* worded as the slot's where `app` is given.
*/
export function storedFormHoldAction(
cause: StoredFormHoldCause,
detail: {
base?: string; pair?: string; app?: string; earlierPair?: boolean; contested?: 'two_addresses' | 'slot' | 'kept';
/**
* Where a held row is served, when that is not packages of one App that
* can be read: the Apps that can be read, the bases whose App cannot be,
* the packages this environment writes, and whether the environment's
* own address is among them.
*/
apps?: StoredFormServedApps;
} = {},
): string {
switch (cause) {
case 'administrator':
// [maintainer ruling 7250982640] The earlier per-package pair: no
// command on this release re-identifies it, so nothing clears it here.
if (detail.earlierPair === true) {
return 'The row holds the upgrade until the paired customization package an earlier version created is re-identified as'
+ ' the App\'s pair (ADR-0146 D3, merge question 12), and no command on this release does that. The row keeps answering'
+ ' as it does today meanwhile.';
}
return `Remove the cause the refusal names on this release, then run the upgrade command again: the row then moves`
+ `${detail.pair !== undefined ? ` into '${detail.pair}'` : ' into the base\'s paired customization package'} with its body as written.`;
case 'app_author':
// The slot case and a row served apart: no exit was measured, so the
// action promises none (step 4 of #38661; ruling 7250982640's precedent).
if (detail.contested === 'kept' && detail.apps !== undefined) {
// The row the precheck names is served at the plan's address only; the kept row is kept at another.
return `The addresses this cause spans are ${servedAppsWords(detail.apps)}, so no one App's author can remove it alone.`
+ ` ${NO_MEASURED_EXIT}`;
}
if (detail.contested !== undefined && detail.apps !== undefined) {
return `This row is served at ${servedAppsWords(detail.apps)}, so no one App's author can remove this cause alone.`
+ ` ${NO_MEASURED_EXIT}`;
}
if (detail.contested === 'slot' || detail.contested === 'kept') {
return `The cause is in the App${detail.app !== undefined ? ` '${detail.app}'` : ''}, its author's to remove. ${NO_MEASURED_EXIT}`;
}
if (detail.contested === 'two_addresses') {
// Measured (step 8 of #38661): a row read at two packages of one App is read at one once only one of them ships the form.
return `Only the author of the App${detail.app !== undefined ? ` '${detail.app}'` : ''} can remove this cause. The deployment stays on`
+ ' the release it is running until the App ships the form from one of these packages only: the row is then read at that'
+ ' address alone and takes what that address gives it. Every address keeps answering as it does today meanwhile.';
}
return `Only the author of the App${detail.app !== undefined ? ` '${detail.app}'` : ''} can remove this cause. The deployment stays on`
+ ' the release it is running until the App ships a version without it; the row keeps closing what it closes today meanwhile.';
case 'kernel':
return `'${detail.base ?? 'The base'}' is a kernel package and has no paired customization package in this version, so no action`
+ ' moves the row: report it to the platform maintainers before upgrading.';
case 'unreadable':
return 'Save the view again on this release with its form content repaired (a `form` or `formViews` entry that is an'
+ ' object), then run the upgrade command again: the row then moves.';
}
}
/** The sentence of an action whose cause has no measured exit. */
const NO_MEASURED_EXIT = 'No action on this release clears it, and no exit from it was measured. The deployment stays on the release it is'
+ ' running, and every address keeps answering as it does today meanwhile.';
/** Where a held row is served, when that is not packages of one App that can be read. */
export interface StoredFormServedApps {
readonly named: readonly string[];
readonly unreadable: readonly string[];
readonly writable: readonly string[];
readonly environment: boolean;
}
function servedAppsWords(apps: StoredFormServedApps): string {
const quoted = (ids: readonly string[]): string => ids.map((id) => `'${id}'`).join(' and ');
return [
...(apps.named.length > 0 ? [`packages of ${apps.named.length > 1 ? 'the Apps' : 'the App'} ${quoted(apps.named)}`] : []),
...(apps.unreadable.length > 0 ? [`${quoted(apps.unreadable)}, whose App cannot be read`] : []),
...(apps.writable.length > 0 ? [`${quoted(apps.writable)}, which this environment writes`] : []),
...(apps.environment ? ['the environment'] : []),
].join(', and ');
}
/** A row as a refusal names it. */
function rowWords(row: StoredFormRowRef): string {
return `${row.type} row '${row.name}'${row.packageId !== undefined ? ` bound to '${row.packageId}'` : ' bound to no package'}`;
}
/** An address as a refusal names it. */
function addressWords(address: StoredFormAddress): string {
return address.kind === 'environment' ? 'the environment' : `'${address.packageId}'`;
}
/** The App a base is of, where its pair id can be read; `undefined` for a base whose App cannot be read. */
function appAt(
address: StoredFormAddress & { kind: 'base' },
pairFix: StoredFormPlanInput['pairFix'],
installed: InstalledManifestLookup,
): string | undefined {
const fix = pairFix(address.packageId);
// A base whose pair the ensure door refuses still has the App's pair id
// where its App can be read: the address is then of that App all the same.
const pair = fix.ok ? fix.pair : (() => { const id = pairOf(address.packageId, installed); return id.ok ? id.value : undefined; })();
return pair === undefined ? undefined : customizationBasePackageId(pair) ?? undefined;
}
/** Turns a plan into a hold, with the refusal and action given (the App author's cause unless another is given). */
function holdPlan(
plans: { plan: StoredFormAddressPlan; rows: readonly OrderedFormRow[] }[],
index: number,
refusal: string,
action: string,
cause: StoredFormHoldCause = 'app_author',
): void {
const { plan, rows } = plans[index]!;
plans[index] = {
plan: {
form: plan.form, address: plan.address, served: plan.served, behind: plan.behind, untouched: plan.untouched, alsoReadAt: plan.alsoReadAt,
outcome: 'hold', cause, refusal, action,
},
rows,
};
}
/**
* [ADR-0159 D7; maintainer ruling 「A 拦住升级·同类全覆盖」, ruling record
* 7265816895 on #38661] A slot of a pair that more than one plan of a name
* claims: THE one place this case is decided. A pair holds one row of a type
* and name, and a row declares one base (ADR-0146 D2), so no claimant has a
* destination. Each claimant's plan holds the upgrade instead, and the
* precheck names each claimant's row once: a row the read serves at two
* addresses of one App (its two plans claim the App's one pair), and two rows
* whose plans each land in one pair. Nothing moves, and every address answers
* as it does today. A row the read serves at two addresses that would treat
* it differently is {@link holdRowsServedApart}'s.
*
* The cause is the App author's (`app_author`): no administrator's exit that
* leaves every address's answer as it is was measured. One exit was measured,
* for one row read at two addresses of one App with no other row at the
* slot: once the App ships the form from one of those packages only, the row
* is read at that address alone and takes what that address gives it. Every
* other slot's action names no exit. A row one of whose plans already holds
* elsewhere is named by that hold, not a second time. No new cause, plan kind
* or "not counted" kind comes with it.
*/
function holdContestedPairSlots(
name: string,
plans: { plan: StoredFormAddressPlan; rows: readonly OrderedFormRow[] }[],
holds: StoredFormHold[],
): void {
// A slot is a pair's one row of the name: a declared override or the pair's
// own `form` item, and the pair's own row read at the pair's own address
// (a writable package's `form` row, declaring no `overrides`) as well.
const slotOf = (plan: StoredFormAddressPlan): string | undefined => {
if (plan.outcome !== 'keep' && plan.outcome !== 'move') return undefined;
const { destination } = plan;
if (destination.kind === 'pair_override' || destination.kind === 'pair_form') return destination.pair;
if (destination.kind === 'package_form' && customizationBasePackageId(destination.packageId) !== null) return destination.packageId;
return undefined;
};
const bySlot = new Map<string, number[]>();
plans.forEach(({ plan }, index) => {
const slot = slotOf(plan);
if (slot !== undefined) bySlot.set(slot, [...(bySlot.get(slot) ?? []), index]);
});
for (const [pair, claimants] of bySlot) {
if (claimants.length < 2) continue;
// The rows held at this slot, each with the plans of it that claim the slot.
const held = new Map<StoredFormPlace, { row: StoredFormRowRef; plans: number[] }>();
for (const index of claimants) {
const { plan, rows } = plans[index]!;
const entry = held.get(rows[0]!.place) ?? { row: plan.served, plans: [] };
entry.plans.push(index);
held.set(rows[0]!.place, entry);
}
for (const [place, { row, plans: served }] of held) {
const at = served.map((index) => plans[index]!.plan.address);
const others = [...held].filter(([other]) => other !== place).map(([, entry]) => entry.row);
const refusal = (at.length > 1
? `The read serves ${rowWords(row)} at ${at.map(addressWords).join(' and ')}, and a move into '${pair}' under the name '${name}' is planned for it at more than one of them.`
: `${rowWords(row)} ${plans[served[0]!]!.plan.outcome === 'keep' ? 'already stands in' : 'would move into'} '${pair}' under the name '${name}'.`)
+ (others.length > 0 ? ` The same slot is claimed for ${others.map(rowWords).join(' and ')}.` : '')
+ ' A pair holds one row of a type and name, and a row declares one base (ADR-0146 D2), so no destination can be given.';
const app = customizationBasePackageId(pair) ?? undefined;
// The two-address exit was measured for one row alone at the slot (step 8 of #38661); with another
// row claiming it too, the slot's sentence, which names no exit.
// ...and only where no address outside the slot serves the row too (then it is not read at one address alone).
const servedOutside = plans.some(({ rows }, index) => !served.includes(index) && rows[0]?.place === place);
const action = storedFormHoldAction('app_author', { contested: at.length > 1 && others.length === 0 && !servedOutside ? 'two_addresses' : 'slot', ...(app !== undefined ? { app } : {}) });
for (const index of served) holdPlan(plans, index, refusal, action);
// A row one of whose plans already holds elsewhere (the pair door) is named by that hold, not a second time.
const namedElsewhere = plans.some(({ plan, rows }, index) => !served.includes(index) && plan.outcome === 'hold' && rows[0]?.place === place);
if (!namedElsewhere) holds.push({ row, cause: 'app_author', refusal, action });
}
}
}
/**
* [ADR-0159 D7, D7-d, D7-e; ruling record 7265816895 on #38661] A stored row
* the read serves at more than one address, where those addresses would not
* all do the same to it: THE one place this case is decided. It is decided
* per stored row over every address that serves it, whatever App each
* address is of: a move or a removal takes the row away from every address
* that serves it, so it is planned only where every such address would move
* the row (each into its own destination) or every one would remove it. Where
* one would move or remove it and another keeps it (an internal form left in
* place ahead of a linked row, ruling record 7249158572; a row already at its
* destination; a plan that holds, a base whose App cannot be read among
* them), or one would move it and another remove it, every plan of the row
* holds the upgrade, nothing is moved or removed, and every address answers
* as it does today. The precheck names the row once, with every address,
* unless one of its plans already holds and names it.
*
* Where a plan of the row already holds (the pair door, or a contested
* slot), the other plans wait on that hold: they take its cause and its
* action, and the refusal names the address it stands at; clearing it is
* what lets the row be planned again. Otherwise the cause is the App
* author's (`app_author`) and no exit was measured: the action names the App
* where every address is a base of one App that can be read, and otherwise
* says where the row is served (each App that can be read, each base whose
* App cannot be, each package this environment writes) and promises nothing.
*/
function holdRowsServedApart(
name: string,
plans: { plan: StoredFormAddressPlan; rows: readonly OrderedFormRow[] }[],
holds: StoredFormHold[],
pairFix: StoredFormPlanInput['pairFix'],
installed: InstalledManifestLookup,
): void {
// Every row of the name with the plans that serve it, and the plans that
// keep it behind an internal form they leave in place (ruling record
// 7249158572, 「两行都不动」: both rows stay, so that address keeps the row
// behind as it keeps the one it serves; the seat's reading, with 7265816895).
const byRow = new Map<StoredFormPlace, { index: number; behind: boolean }[]>();
const add = (place: StoredFormPlace, entry: { index: number; behind: boolean }): void => {
byRow.set(place, [...(byRow.get(place) ?? []), entry]);
};
plans.forEach(({ plan, rows }, index) => {
const place = rows[0]?.place;
if (place !== undefined) add(place, { index, behind: false });
if (plan.outcome === 'left_in_place' && plan.reason === INTERNAL_AHEAD_OF_LINKED_ROW.reason) {
for (const row of rows.slice(1)) if (row.holding.kind === 'form') add(row.place, { index, behind: true });
}
});
const words: Record<StoredFormAddressPlan['outcome'], string> = {
move: 'moved', remove: 'removed', keep: 'kept as it is', left_in_place: 'kept as it is', hold: 'held',
};
// What each plan did before this pass, and the rows each hold is for: a plan
// held here for one row (a row kept behind its internal form, say) is no
// hold of another row's, which waits only on a hold taken for itself.
const before = plans.map(({ plan }) => plan.outcome);
const heldFor = new Map<number, Set<StoredFormPlace>>();
plans.forEach(({ plan, rows }, index) => {
if (plan.outcome === 'hold' && rows[0] !== undefined) heldFor.set(index, new Set([rows[0].place]));
});
for (const [place, entries] of byRow) {
if (entries.length < 2) continue;
// A row kept behind counts as left in place there, whatever that plan serves or holds for.
const outcomeOf = ({ index, behind }: { index: number; behind: boolean }): StoredFormAddressPlan['outcome'] => {
if (heldFor.get(index)?.has(place) === true) return 'hold';
return behind ? 'left_in_place' : before[index]!;
};
const outcomes = entries.map(outcomeOf);
if (!outcomes.some((outcome) => outcome === 'move' || outcome === 'remove')) continue;
if (outcomes.every((outcome) => outcome === 'move') || outcomes.every((outcome) => outcome === 'remove')) continue;
const involved = [...new Set(entries.map((e) => e.index))];
const held = involved.filter((index) => plans[index]!.plan.outcome !== 'hold');
for (const index of involved) heldFor.set(index, new Set([...(heldFor.get(index) ?? []), place]));
const at = entries.map((e) => plans[e.index]!.plan.address);
const servedEntry = entries.find((e) => !e.behind);
const row = servedEntry !== undefined ? plans[servedEntry.index]!.plan.served : rowRefOf(plans[entries[0]!.index]!.rows, place, name);
const keptBehind = entries.filter((e) => e.behind).map((e) => addressWords(plans[e.index]!.plan.address));
const byWord = new Map<string, string[]>();
entries.forEach((entry, i) => {
const word = entry.behind && outcomes[i] === 'left_in_place' ? 'kept as it is behind the internal form left in place' : words[outcomes[i]!];
byWord.set(word, [...(byWord.get(word) ?? []), addressWords(plans[entry.index]!.plan.address)]);
});
const servedAt = entries.filter((e) => !e.behind).map((e) => addressWords(plans[e.index]!.plan.address));
const refusal = `The read serves ${rowWords(row)} at ${servedAt.join(' and ')}`
+ (keptBehind.length > 0 ? `, and keeps it behind the internal form left in place at ${keptBehind.join(' and ')},` : '')
+ ` under the name '${name}': it would be`
+ ` ${[...byWord].map(([word, addresses]) => `${word} at ${addresses.join(' and ')}`).join(', and ')}.`
+ ' A move or a removal takes the row from every address that serves it, so it is planned only where every one of them would do the same.'
+ (keptBehind.length > 0 ? ` Under ruling 7249158572 both rows stay where an internal form is left in place ahead of it, at ${keptBehind.join(' and ')}.` : '');
const waitsOn = entries.find((_entry, i) => outcomes[i] === 'hold');
// Clearing that hold lets the row be planned only where every other address would move it, as the hold's own plan
// would then (measured for two addresses); otherwise the row would still be served apart, and the hold's action
// says more than was measured.
const clearsWithIt = waitsOn !== undefined && entries.every((e, i) => e.index === waitsOn.index || outcomes[i] === 'move');
if (waitsOn !== undefined && clearsWithIt) {
if (held.length === 0) continue;
// Another plan of the row already holds: this one waits on that hold, its cause and its action.
const holding = plans[waitsOn.index]!.plan as StoredFormAddressPlan & { outcome: 'hold' };
const waiting = `${refusal} It holds at ${addressWords(holding.address)}, so it is planned at none of them until that hold is cleared: ${holding.refusal}`;
for (const index of held) holdPlan(plans, index, waiting, holding.action, holding.cause);
continue;
}
const { apps, oneApp } = servedAppsAt(at, pairFix, installed);
// The exit step 8 measured is for a row served (not kept behind) at two packages of one App.
const measured = oneApp !== undefined && outcomes.includes('move') && keptBehind.length === 0 && waitsOn === undefined;
const action = storedFormHoldAction('app_author', oneApp !== undefined
? { contested: measured ? 'two_addresses' : 'slot', app: oneApp }
: { contested: 'slot', apps });
for (const index of held) holdPlan(plans, index, refusal, action);
if (waitsOn === undefined) holds.push({ row, cause: 'app_author', refusal, action });
}
}
/** The Apps, unreadable bases, writable packages and environment among `at`, and the one App where every address is a base or pair of it. */
function servedAppsAt(
at: readonly StoredFormAddress[],
pairFix: StoredFormPlanInput['pairFix'],
installed: InstalledManifestLookup,
): { apps: StoredFormServedApps; oneApp?: string } {
const named = new Set<string>();
const unreadable: string[] = [];
const writable: string[] = [];
let environment = false;
for (const address of at) {
if (address.kind === 'environment') environment = true;
else if (address.kind === 'package') {
const app = customizationBasePackageId(address.packageId);
if (app !== null) named.add(app);
else if (!writable.includes(address.packageId)) writable.push(address.packageId);