@reventlessdev/trait-attachments 1.0.0-alpha.8 → 1.0.0-alpha.81

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 CHANGED
@@ -15,7 +15,7 @@ the types are the host's own:
15
15
  behavior change for every host: version it `fix:`/`feat:` accordingly.
16
16
 
17
17
  The graft *is* a StateChangeSlice, so the emitter writes nearly all of it: the slice
18
- spec, its behavior and the conformance binding, whole. Only the view's projection is
18
+ spec, its decision and the conformance binding, whole. Only the view's projection is
19
19
  printed as a patch — the view already exists, and placing an arm in an ordered `switch`
20
20
  is an AST operation a text splice gets silently wrong.
21
21
 
@@ -43,12 +43,14 @@ Unlike the geocoding trait this one writes nothing back into its host: the graft
43
43
  ```sh
44
44
  pnpm exec graft-trait @reventlessdev/trait-attachments \
45
45
  --into src/Product --tests tests/Product \
46
- --entity Product --entityId productId --noun Image \
47
- --file productImage --created ProductAdded --view Products
46
+ --entity Product --entityId productId --entityIdType CatalogSpec.ProductId \
47
+ --noun Image --file productImage --created ProductAdded --view Products
48
48
  ```
49
49
 
50
50
  The field is named for the store it draws from, and `--noun` is what this host calls
51
- one attachment — it runs through every name the graft declares.
51
+ one attachment — it runs through every name the graft declares. `--entityIdType` names
52
+ the host's identity module, so the emitted ids are typed; leave it out for a host that
53
+ keeps its ids as strings.
52
54
 
53
55
  2. Fill the `TODO(graft)` markers. They are the host's own policy: the events its
54
56
  refusal turns on, the error it raises, and the `else if` in `decide` that raises it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reventlessdev/trait-attachments",
3
- "version": "1.0.0-alpha.8",
3
+ "version": "1.0.0-alpha.81",
4
4
  "description": "Attachments domain trait: rules, host contract, conformance suite and emitter for an ordered set of stored files on an entity, with a primary and captions",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
@@ -11,16 +11,16 @@
11
11
  "README.md"
12
12
  ],
13
13
  "dependencies": {
14
- "sury": "11.0.0-rc.2",
15
- "sury-ppx": "11.0.0-rc.2",
16
- "@reventlessdev/reventless-gwt": "1.0.0-alpha.206",
17
- "@reventlessdev/reventless-spec": "3.0.0-alpha.132"
14
+ "sury": "11.0.0",
15
+ "sury-ppx": "11.0.0",
16
+ "@reventlessdev/reventless-gwt": "1.0.0-alpha.279",
17
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.194"
18
18
  },
19
19
  "devDependencies": {
20
- "rescript": "12.3.0"
20
+ "rescript": "12.3.1"
21
21
  },
22
22
  "peerDependencies": {
23
- "rescript": "12.3.0"
23
+ "rescript": "^12.3.1"
24
24
  },
25
25
  "publishConfig": {
26
26
  "registry": "https://registry.npmjs.org"
@@ -6,7 +6,6 @@ contract is over that slice. The rules live in `Attachments_Rules` and are asser
6
6
  through a host by `Attachments_Conformance`; the spec surface the host maps onto
7
7
  them is written by `Attachments_Scaffold`.
8
8
  */
9
-
10
9
  /**
11
10
  This trait's own account of itself — see `AddressGeocoding.declaration` for why the
12
11
  version is read rather than written.
@@ -40,8 +39,8 @@ module type Binding = {
40
39
  let refA: ref
41
40
  let refB: ref
42
41
 
43
- module Spec: ReventlessGwt.Behavior_GWT.BehaviorSpec
44
- module Behavior: ReventlessGwt.Behavior_GWT.Behavior with module Spec = Spec
42
+ module Spec: ReventlessGwt.Decision_GWT.DecisionSpec
43
+ module Decision: ReventlessGwt.Decision_GWT.Decision with module Spec = Spec
45
44
 
46
45
  /** The same facts as the slice **consumes** them, for building history.
47
46
 
@@ -104,8 +103,8 @@ module type SingleBinding = {
104
103
  let refA: ref
105
104
  let refB: ref
106
105
 
107
- module Spec: ReventlessGwt.Behavior_GWT.BehaviorSpec
108
- module Behavior: ReventlessGwt.Behavior_GWT.Behavior with module Spec = Spec
106
+ module Spec: ReventlessGwt.Decision_GWT.DecisionSpec
107
+ module Decision: ReventlessGwt.Decision_GWT.Decision with module Spec = Spec
109
108
 
110
109
  /** The facts as the slice **consumes** them — see `Binding.Consumed`. No
111
110
  `primarySet`: at this cardinality nothing emits one. */
@@ -2,7 +2,6 @@
2
2
  The conformance suite, run by a host against its own graft. `Make(Binding).register()`
3
3
  inside a Jest test file registers one `describe` block over the binding.
4
4
  */
5
-
6
5
  /** The suite's title, composed once and read twice: the suite registers it,
7
6
  and `certify-trait` computes the same string to find the run's assertions in
8
7
  a test report. Exported rather than inlined so neither side parses the
@@ -15,7 +14,7 @@ inside a Jest test file registers one `describe` block over the binding.
15
14
  let suiteName = (host: string) => `${host} conforms to the attachments trait`
16
15
 
17
16
  module Make = (B: Attachments.Binding) => {
18
- module G = ReventlessGwt.Behavior_GWT.Make(B.Spec, B.Behavior)
17
+ module G = ReventlessGwt.Decision_GWT.Make(B.Spec, B.Decision)
19
18
 
20
19
  let withA = Array.concat(B.Consumed.created, [B.Consumed.attached(B.refA)])
21
20
  let withAB = Array.concat(withA, [B.Consumed.attached(B.refB)])
@@ -73,7 +72,9 @@ module Make = (B: Attachments.Binding) => {
73
72
  )
74
73
 
75
74
  G.test("removing the chosen primary lets the first remaining stand in", () =>
76
- G.givenEvents(Array.concat(withAB, [B.Consumed.primarySet(B.refB), B.Consumed.removed(B.refB)]))
75
+ G.givenEvents(
76
+ Array.concat(withAB, [B.Consumed.primarySet(B.refB), B.Consumed.removed(B.refB)]),
77
+ )
77
78
  ->G.whenCmd(B.setPrimary(B.refA))
78
79
  ->G.thenNoEvent
79
80
  )
@@ -131,7 +132,7 @@ replaces rather than joins — plus the ref-less remove and the captions, which
131
132
  single image wants exactly as much as a gallery member does.
132
133
  */
133
134
  module MakeSingle = (B: Attachments.SingleBinding) => {
134
- module G = ReventlessGwt.Behavior_GWT.Make(B.Spec, B.Behavior)
135
+ module G = ReventlessGwt.Decision_GWT.Make(B.Spec, B.Decision)
135
136
 
136
137
  let withA = Array.concat(B.Consumed.created, [B.Consumed.attached(B.refA)])
137
138
 
@@ -153,11 +154,7 @@ module MakeSingle = (B: Attachments.SingleBinding) => {
153
154
  G.test("a second ref replaces the first rather than joining it", () =>
154
155
  G.givenEvents(withA)
155
156
  ->G.whenCmd(B.attach(B.refB))
156
- ->G.thenEvents([
157
- B.removed(B.refA),
158
- B.attached(B.refB),
159
- B.effectiveChanged(Some(B.refB)),
160
- ])
157
+ ->G.thenEvents([B.removed(B.refA), B.attached(B.refB), B.effectiveChanged(Some(B.refB))])
161
158
  )
162
159
 
163
160
  G.test("clearing a held set removes what it holds", () =>
@@ -171,13 +168,11 @@ module MakeSingle = (B: Attachments.SingleBinding) => {
171
168
  )
172
169
 
173
170
  G.test("a replaced ref can be attached again", () =>
174
- G.givenEvents(Array.concat(withA, [B.Consumed.removed(B.refA), B.Consumed.attached(B.refB)]))
171
+ G.givenEvents(
172
+ Array.concat(withA, [B.Consumed.removed(B.refA), B.Consumed.attached(B.refB)]),
173
+ )
175
174
  ->G.whenCmd(B.attach(B.refA))
176
- ->G.thenEvents([
177
- B.removed(B.refB),
178
- B.attached(B.refA),
179
- B.effectiveChanged(Some(B.refA)),
180
- ])
175
+ ->G.thenEvents([B.removed(B.refB), B.attached(B.refA), B.effectiveChanged(Some(B.refA))])
181
176
  )
182
177
 
183
178
  // The caption names no ref either, so what it lands on is whatever is
@@ -190,13 +185,17 @@ module MakeSingle = (B: Attachments.SingleBinding) => {
190
185
  )
191
186
 
192
187
  G.test("a caption follows a replacement onto the new ref", () =>
193
- G.givenEvents(Array.concat(withA, [B.Consumed.removed(B.refA), B.Consumed.attached(B.refB)]))
188
+ G.givenEvents(
189
+ Array.concat(withA, [B.Consumed.removed(B.refA), B.Consumed.attached(B.refB)]),
190
+ )
194
191
  ->G.whenCmd(B.setAltText("side"))
195
192
  ->G.thenEvent(B.altTextSet(B.refB, "side"))
196
193
  )
197
194
 
198
195
  G.test("captioning an empty set is refused", () =>
199
- G.givenEvents(B.Consumed.created)->G.whenCmd(B.setAltText("front"))->G.thenError(B.notAttached)
196
+ G.givenEvents(B.Consumed.created)
197
+ ->G.whenCmd(B.setAltText("front"))
198
+ ->G.thenError(B.notAttached)
200
199
  )
201
200
 
202
201
  G.test("repeating the caption is a no-op", () =>
@@ -1,15 +1,15 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
4
- import * as Behavior_GWT$ReventlessGwt from "@reventlessdev/reventless-gwt/src/Behavior_GWT.res.mjs";
4
+ import * as Decision_GWT$ReventlessGwt from "@reventlessdev/reventless-gwt/src/Decision_GWT.res.mjs";
5
5
 
6
6
  function suiteName(host) {
7
7
  return host + ` conforms to the attachments trait`;
8
8
  }
9
9
 
10
10
  function Make(B) {
11
- let $$let = B.Behavior;
12
- let G = Behavior_GWT$ReventlessGwt.Make(B.Spec)({
11
+ let $$let = B.Decision;
12
+ let G = Decision_GWT$ReventlessGwt.Make(B.Spec)({
13
13
  initialState: $$let.initialState,
14
14
  evolve: $$let.evolve,
15
15
  decide: $$let.decide
@@ -64,8 +64,8 @@ function Make(B) {
64
64
  }
65
65
 
66
66
  function MakeSingle(B) {
67
- let $$let = B.Behavior;
68
- let G = Behavior_GWT$ReventlessGwt.Make(B.Spec)({
67
+ let $$let = B.Decision;
68
+ let G = Decision_GWT$ReventlessGwt.Make(B.Spec)({
69
69
  initialState: $$let.initialState,
70
70
  evolve: $$let.evolve,
71
71
  decide: $$let.decide
@@ -115,4 +115,4 @@ export {
115
115
  Make,
116
116
  MakeSingle,
117
117
  }
118
- /* Behavior_GWT-ReventlessGwt Not a pure module */
118
+ /* Decision_GWT-ReventlessGwt Not a pure module */
@@ -7,18 +7,22 @@ A host maps its own constructors onto `op` and `fact` and keeps the spec surface
7
7
  the variants, their annotations, its own refusals. Nothing here knows what an
8
8
  entity is. `Attachments_Conformance` asserts these rules through a host.
9
9
  */
10
-
11
10
  /** The stored file's reference. A `StorageRef` path today, so `string` carries it
12
11
  without a wrapper the host would have to unwrap on every arm. */
13
12
  type ref = string
14
13
 
14
+ // `@schema` so `Attachments_Scaffold`'s config can take this very type rather
15
+ // than a second spelling of it. A graft's config and the rule it selects being
16
+ // the same value is the point: a config that could say `"single"` where the
17
+ // rules say `Single` is a config that can be misspelled.
18
+
15
19
  /**
16
20
  How many members a host's set may hold.
17
21
 
18
22
  Not a runtime variation: a graft fixes this once, and every command the graft
19
23
  emits is shaped by the answer. It reaches `decide` as an argument rather than
20
24
  sitting on `t` so that `empty` stays one value and a host that never mentions
21
- cardinality gets the behaviour it has today.
25
+ cardinality gets the behavior it has today.
22
26
 
23
27
  Exactly one rule reads it — `Attach` — and that is the whole of the difference:
24
28
  a bounded set replaces its member where an unbounded one appends beside it.
@@ -27,14 +31,12 @@ resolves to a no-op through the rules it already has (the only member is already
27
31
  the effective primary), which is why `Single` needs no branch for it and why the
28
32
  scaffold simply declines to emit the command rather than the rules refusing it.
29
33
  */
30
- // `@schema` so `Attachments_Scaffold`'s config can take this very type rather
31
- // than a second spelling of it. A graft's config and the rule it selects being
32
- // the same value is the point: a config that could say `"single"` where the
33
- // rules say `Single` is a config that can be misspelled.
34
34
  @schema
35
35
  type cardinality =
36
- | /** An unbounded, ordered set: a gallery. */ Many
37
- | /** At most one member, replaced rather than added to. */ Single
36
+ /** An unbounded, ordered set: a gallery. */
37
+ | Many
38
+ /** At most one member, replaced rather than added to. */
39
+ | Single
38
40
 
39
41
  /** Refolded per decision, never stored — a StateChangeSlice's state is. */
40
42
  type t = {
@@ -48,20 +50,20 @@ let empty = {attached: [], primary: None, altTexts: []}
48
50
 
49
51
  /** What a host asks the set to do. */
50
52
  type op =
51
- | /** `altText` is the caption a host may supply with the file itself. */
52
- Attach({ref: ref, altText: option<string>})
53
+ /** `altText` is the caption a host may supply with the file itself. */
54
+ | Attach({ref: ref, altText: option<string>})
53
55
  | Remove({ref: ref})
54
- | /** Empty the set, whatever it holds.
56
+ /** Empty the set, whatever it holds.
55
57
 
56
58
  The op a bounded set's remove command maps onto: with one member there is
57
59
  no ref for the caller to name, and naming it would be asking them to
58
60
  repeat what the row already says. Well defined at either cardinality —
59
61
  an unbounded host that wants a "remove them all" command gets it here
60
62
  rather than by looping its own remove. */
61
- Clear
63
+ | Clear
62
64
  | SetPrimary({ref: ref})
63
65
  | SetAltText({ref: ref, altText: string})
64
- | /** Caption whichever member is the primary, without naming it.
66
+ /** Caption whichever member is the primary, without naming it.
65
67
 
66
68
  The counterpart of `Clear`, and the op a bounded set's caption command
67
69
  maps onto — with one member there is nothing to name. It is not
@@ -69,7 +71,7 @@ type op =
69
71
  sees, so "caption the hero" is a command an unbounded host wants too,
70
72
  and resolving it here through `effectivePrimary` is what keeps the
71
73
  answer the same as the member a projection puts first. */
72
- SetPrimaryAltText({altText: string})
74
+ | SetPrimaryAltText({altText: string})
73
75
 
74
76
  /** What the set decided, for the host to name in its own event. */
75
77
  type fact =
@@ -77,7 +79,7 @@ type fact =
77
79
  | Removed({ref: ref})
78
80
  | PrimarySet({ref: ref})
79
81
  | AltTextSet({ref: ref, altText: string})
80
- | /** The member a reader should now show, or `None` where the set has none.
82
+ /** The member a reader should now show, or `None` where the set has none.
81
83
 
82
84
  **A conclusion, not a decision.** `PrimarySet` records that somebody
83
85
  chose; this records what the set resolved to, however it got there —
@@ -95,7 +97,7 @@ type fact =
95
97
  Optional because "there is no longer one to show" is as much a change as
96
98
  any other, and a subscriber that cannot be told it keeps showing a file
97
99
  the set no longer holds. */
98
- EffectiveChanged({ref: option<ref>})
100
+ | EffectiveChanged({ref: option<ref>})
99
101
 
100
102
  /** The primary a reader should show: the one chosen, else the first attached, so
101
103
  a set never shows no file while it holds one. The read model applies the same
@@ -202,12 +204,7 @@ let decideFacts = (t, ~cardinality: cardinality=Many, op): result<array<fact>, [
202
204
  // individually rather than through `Clear` so the facts read the same
203
205
  // whether one was there or (through some history nothing produces) more.
204
206
  | Single =>
205
- Ok(
206
- Array.concat(
207
- t.attached->Array.map(r => Removed({ref: r})),
208
- [Attached({ref, altText})],
209
- ),
210
- )
207
+ Ok(Array.concat(t.attached->Array.map(r => Removed({ref: r})), [Attached({ref, altText})]))
211
208
  }
212
209
  }
213
210
  | Remove({ref}) => t.attached->Array.includes(ref) ? Ok([Removed({ref: ref})]) : Ok([])
@@ -25,7 +25,6 @@ is how a scaffolder acquires a policy language nobody asked for. They are left
25
25
  as `TODO(graft)` markers, and the developer writes ReScript, which is better at
26
26
  this than any config could be.
27
27
  */
28
-
29
28
  /**
30
29
  The names a graft needs, and nothing else.
31
30
 
@@ -39,6 +38,9 @@ type config = {
39
38
  entity: string,
40
39
  /** Its id field: `"productId"`. */
41
40
  entityId: string,
41
+ /** The host's identity module for that id: `"ProductId"`. Absent ⇒ `string`,
42
+ for a host that has not declared one. */
43
+ entityIdType?: string,
42
44
  /**
43
45
  What this host calls one attachment, capitalised and singular: `"Image"`,
44
46
  `"Document"`, `"Attachment"`.
@@ -132,8 +134,7 @@ type names = {
132
134
  notAttached: string,
133
135
  }
134
136
 
135
- let cardinalityOf = (c: config): Attachments_Rules.cardinality =>
136
- c.cardinality->Option.getOr(Many)
137
+ let cardinalityOf = (c: config): Attachments_Rules.cardinality => c.cardinality->Option.getOr(Many)
137
138
 
138
139
  let isSingle = (c: config): bool => cardinalityOf(c) == Single
139
140
 
@@ -163,6 +164,15 @@ let namesOf = (c: config): names => {
163
164
 
164
165
  let refTypeOf = (c: config) => c.refType->Option.getOr("Reventless.UploadableImage.t")
165
166
 
167
+ // The entity id's type, and a fixture value of it.
168
+ let idTypeOf = (c: config) => c.entityIdType->Option.mapOr("string", t => t ++ ".t")
169
+
170
+ let idValueOf = (c: config, literal: string) =>
171
+ switch c.entityIdType {
172
+ | Some(t) => `${t}.make("${literal}")`
173
+ | None => `"${literal}"`
174
+ }
175
+
166
176
  // What the VIEW holds, as against what an event's reference field holds. An
167
177
  // event names a file; a view holds that file together with the text that goes
168
178
  // with it, because a cell renderer is handed a field and a value and never the
@@ -306,227 +316,236 @@ let sliceSpec = (c: config): string => {
306
316
  let attrs = commandAttributes(c)
307
317
  let createdArm =
308
318
  c.createdCarriesEntityId->Option.getOr(true)
309
- ? ` | ${c.created}({ ${c.entityId}: string})`
319
+ ? ` | ${c.created}({ ${c.entityId}: ${idTypeOf(c)}})`
310
320
  : ` | ${c.created}`
311
321
  // Present only where a choice exists. A bounded set has one member, so
312
322
  // nothing consumes or emits a primary — and the trait's rules never produce
313
323
  // the fact, so listing the event would declare one nothing can write.
314
324
  let primaryArm = (prefix: string) =>
315
325
  single ? [] : [` | ${n.primarySet}({ ${prefix}${c.file}: ${ref}})`]
316
- let headline =
317
- single
318
- ? [
319
- `// ${n.slice} StateChangeSlice: ${c.entity}'s single attachment — set it, remove`,
320
- `// it, caption it. A graft of the Attachments trait; the set's rules are the`,
321
- ]
322
- : [
323
- `// ${n.slice} StateChangeSlice: ${c.entity}'s attachment set — attach, remove,`,
324
- `// choose the primary, caption. A graft of the Attachments trait; the rules are`,
325
- ]
326
- lines([
327
- ...headline,
328
- `// trait's and are asserted by its conformance suite, bound in the tests.`,
329
- `//`,
330
- `// Emitted by the trait. Everything below is this host's own vocabulary, so it is`,
331
- `// ordinary source from here on — edit it freely.`,
332
- ``,
333
- `@@reventless.spec`,
334
- ``,
335
- `@schema`,
336
- `type consumedEvent =`,
337
- createdArm,
338
- ` | ${n.attached}({ ${c.file}: ${ref}})`,
339
- ` | ${n.removed}({ ${c.file}: ${ref}})`,
340
- ...primaryArm(""),
341
- ` | ${n.altTextSet}({ ${c.file}: ${ref}, altText: string})`,
342
- ` | ${n.effectiveChanged}({ ${c.file}?: ${ref}})`,
343
- ` // TODO(graft): add the events this host's own refusal turns on — whatever`,
344
- ` // moves it into a state where attachments may not be changed.`,
345
- ``,
346
- ...(single
347
- ? [
348
- `// One reference field, on ${n.attachCmd}, and it accepts a new file — so`,
349
- `// it is typed as the uploadable it is and a form binds an upload input to it.`,
350
- `// Neither other command names a reference: with one attachment there is`,
351
- `// nothing to choose between, and asking a caller to name it would be asking`,
352
- `// them to repeat what the row already says.`,
353
- ]
354
- : [
355
- `// The reference fields divide into two kinds, and the division is the point.`,
356
- `// The one on ${n.attachCmd} accepts a new file, so it is typed as the`,
357
- `// uploadable it is and a form binds an upload input to it. The others name a`,
358
- `// file the row ALREADY holds, so they are typed as selections out of`,
359
- `// \`${setFieldOf(c)}\` and a form offers those instead of an uploader.`,
360
- `//`,
361
- `// Bound once rather than spelled three times: the collection is one answer,`,
362
- `// and three copies are three chances for one to name a field that has moved.`,
363
- `let ${selectionBinding} = Reventless.MemberRef.of_(~view="${c.view}", ${contentArgOf(
326
+ let headline = single
327
+ ? [
328
+ `// ${n.slice} StateChangeSlice: ${c.entity}'s single attachment — set it, remove`,
329
+ `// it, caption it. A graft of the Attachments trait; the set's rules are the`,
330
+ ]
331
+ : [
332
+ `// ${n.slice} StateChangeSlice: ${c.entity}'s attachment set — attach, remove,`,
333
+ `// choose the primary, caption. A graft of the Attachments trait; the rules are`,
334
+ ]
335
+ lines(
336
+ [
337
+ ...headline,
338
+ `// trait's and are asserted by its conformance suite, bound in the tests.`,
339
+ `//`,
340
+ `// Emitted by the trait. Everything below is this host's own vocabulary, so it is`,
341
+ `// ordinary source from here on — edit it freely.`,
342
+ ``,
343
+ `@@reventless.spec`,
344
+ ``,
345
+ `@schema`,
346
+ `type consumedEvent =`,
347
+ createdArm,
348
+ ` | ${n.attached}({ ${c.file}: ${ref}})`,
349
+ ` | ${n.removed}({ ${c.file}: ${ref}})`,
350
+ ...primaryArm(""),
351
+ ` | ${n.altTextSet}({ ${c.file}: ${ref}, altText: string})`,
352
+ ` | ${n.effectiveChanged}({ ${c.file}?: ${ref}})`,
353
+ ` // TODO(graft): add the events this host's own refusal turns on — whatever`,
354
+ ` // moves it into a state where attachments may not be changed.`,
355
+ ``,
356
+ ...single
357
+ ? [
358
+ `// One reference field, on ${n.attachCmd}, and it accepts a new file — so`,
359
+ `// it is typed as the uploadable it is and a form binds an upload input to it.`,
360
+ `// Neither other command names a reference: with one attachment there is`,
361
+ `// nothing to choose between, and asking a caller to name it would be asking`,
362
+ `// them to repeat what the row already says.`,
363
+ ]
364
+ : [
365
+ `// The reference fields divide into two kinds, and the division is the point.`,
366
+ `// The one on ${n.attachCmd} accepts a new file, so it is typed as the`,
367
+ `// uploadable it is and a form binds an upload input to it. The others name a`,
368
+ `// file the row ALREADY holds, so they are typed as selections out of`,
369
+ `// \`${setFieldOf(c)}\` and a form offers those instead of an uploader.`,
370
+ `//`,
371
+ `// Bound once rather than spelled three times: the collection is one answer,`,
372
+ `// and three copies are three chances for one to name a field that has moved.`,
373
+ `let ${selectionBinding} = Reventless.MemberRef.of_(~view="${c.view}", ${contentArgOf(
374
+ c,
375
+ )}~field="${setFieldOf(c)}")`,
376
+ ``,
377
+ ],
378
+ `@schema`,
379
+ `type command =`,
380
+ `${attrs}${n.attachCmd}({ ${c.entityId}: ${idTypeOf(
381
+ c,
382
+ )}, ${c.file}: ${ref}, altText?: string})`,
383
+ // The bounded set's remove names nothing. This is the reported defect in its
384
+ // purest form — the old command asked for an upload in order to delete.
385
+ single
386
+ ? `${attrs}${n.removeCmd}({ ${c.entityId}: ${idTypeOf(c)}})`
387
+ : `${attrs}${n.removeCmd}({ ${c.entityId}: ${idTypeOf(c)}, ${c.file}: ${sel}})`,
388
+ ...single
389
+ ? []
390
+ : [`${attrs}${n.setPrimaryCmd}({ ${c.entityId}: ${idTypeOf(c)}, ${c.file}: ${sel}})`],
391
+ single
392
+ ? `${attrs}${n.setAltTextCmd}({ ${c.entityId}: ${idTypeOf(c)}, altText: string})`
393
+ : `${attrs}${n.setAltTextCmd}({ ${c.entityId}: ${idTypeOf(
364
394
  c,
365
- )}~field="${setFieldOf(c)}")`,
366
- ``,
367
- ]),
368
- `@schema`,
369
- `type command =`,
370
- `${attrs}${n.attachCmd}({ ${c.entityId}: string, ${c.file}: ${ref}, altText?: string})`,
371
- // The bounded set's remove names nothing. This is the reported defect in its
372
- // purest form — the old command asked for an upload in order to delete.
373
- single
374
- ? `${attrs}${n.removeCmd}({ ${c.entityId}: string})`
375
- : `${attrs}${n.removeCmd}({ ${c.entityId}: string, ${c.file}: ${sel}})`,
376
- ...(single ? [] : [`${attrs}${n.setPrimaryCmd}({ ${c.entityId}: string, ${c.file}: ${sel}})`]),
377
- single
378
- ? `${attrs}${n.setAltTextCmd}({ ${c.entityId}: string, altText: string})`
379
- : `${attrs}${n.setAltTextCmd}({ ${c.entityId}: string, ${c.file}: ${sel}, altText: string})`,
380
- ``,
381
- `@schema`,
382
- `type error =`,
383
- ` | ${n.notFound}`,
384
- ` | ${n.notAttached}`,
385
- ` // TODO(graft): add this host's own refusal.`,
386
- ``,
387
- `@schema`,
388
- `type event =`,
389
- ` | ${n.attached}({ ${c.entityId}: string, ${c.file}: ${ref}, altText?: string})`,
390
- ` | ${n.removed}({ ${c.entityId}: string, ${c.file}: ${ref}})`,
391
- ...primaryArm(`${c.entityId}: string, `),
392
- ` | ${n.altTextSet}({ ${c.entityId}: string, ${c.file}: ${ref}, altText: string})`,
393
- ` // The member a reader should now show, or none. A conclusion rather than a`,
394
- ` // decision: most of the moves that change it — a first attachment, a removal`,
395
- ` // promoting the next — are nobody's choice, so nothing else announces them.`,
396
- ` | ${n.effectiveChanged}({ ${c.entityId}: string, ${c.file}?: ${ref}})`,
397
- ``,
398
- ...commandTransitionBinding(c),
399
- `// The graft's own record of itself. Nothing else survives into a deployed`,
400
- `// plugin — the dependency and the rules alias are source-side — so without`,
401
- `// this a running estate cannot say where this slice came from.`,
402
- `let traits = [TraitAttachments.Attachments.declaration]`,
403
- ``,
404
- ])
395
+ )}, ${c.file}: ${sel}, altText: string})`,
396
+ ``,
397
+ `@schema`,
398
+ `type error =`,
399
+ ` | ${n.notFound}`,
400
+ ` | ${n.notAttached}`,
401
+ ` // TODO(graft): add this host's own refusal.`,
402
+ ``,
403
+ `@schema`,
404
+ `type event =`,
405
+ ` | ${n.attached}({ ${c.entityId}: ${idTypeOf(c)}, ${c.file}: ${ref}, altText?: string})`,
406
+ ` | ${n.removed}({ ${c.entityId}: ${idTypeOf(c)}, ${c.file}: ${ref}})`,
407
+ ...primaryArm(`${c.entityId}: ${idTypeOf(c)}, `),
408
+ ` | ${n.altTextSet}({ ${c.entityId}: ${idTypeOf(c)}, ${c.file}: ${ref}, altText: string})`,
409
+ ` // The member a reader should now show, or none. A conclusion rather than a`,
410
+ ` // decision: most of the moves that change it — a first attachment, a removal`,
411
+ ` // promoting the next — are nobody's choice, so nothing else announces them.`,
412
+ ` | ${n.effectiveChanged}({ ${c.entityId}: ${idTypeOf(c)}, ${c.file}?: ${ref}})`,
413
+ ``,
414
+ ...commandTransitionBinding(c),
415
+ `// The graft's own record of itself. Nothing else survives into a deployed`,
416
+ `// plugin — the dependency and the rules alias are source-side — so without`,
417
+ `// this a running estate cannot say where this slice came from.`,
418
+ `let traits = [TraitAttachments.Attachments.declaration]`,
419
+ ``,
420
+ ],
421
+ )
405
422
  }
406
423
 
407
424
  // ── The slice body ───────────────────────────────────────────────────────────
408
425
 
409
- let sliceBehavior = (c: config): string => {
426
+ let sliceDecision = (c: config): string => {
410
427
  let n = namesOf(c)
411
428
  let single = isSingle(c)
412
- lines([
413
- `@@reventless.behavior`,
414
- ``,
415
- `// The set's rules are the trait's. What is left here is this host's own refusal`,
416
- `// and the mapping between its constructors and the trait's ops and facts.`,
417
- `module Attachments = TraitAttachments.Attachments_Rules`,
418
- ``,
419
- `type state = {exists: bool, attachments: Attachments.t}`,
420
- ``,
421
- `let initialState = {exists: false, attachments: Attachments.empty}`,
422
- ``,
423
- `let evolve = (state, event) => {`,
424
- ` let fold = fact => {...state, attachments: state.attachments->Attachments.evolve(fact)}`,
425
- ` switch event {`,
426
- // A creation event that carries no id is a bare constructor, so a wildcard
427
- // payload does not compile against it. The spec above already branches on
428
- // this; the fold has to branch with it.
429
- c.createdCarriesEntityId->Option.getOr(true)
430
- ? ` | ${c.created}(_) => {...state, exists: true}`
431
- : ` | ${c.created} => {...state, exists: true}`,
432
- ` | ${n.attached}({${c.file}}) => fold(Attached({ref: ${c.file}, altText: None}))`,
433
- ` | ${n.removed}({${c.file}}) => fold(Removed({ref: ${c.file}}))`,
434
- ...(single
435
- ? []
436
- : [` | ${n.primarySet}({${c.file}}) => fold(PrimarySet({ref: ${c.file}}))`]),
437
- ` | ${n.altTextSet}({${c.file}, altText}) => fold(AltTextSet({ref: ${c.file}, altText}))`,
438
- ` | ${n.effectiveChanged}({${c.file}: ?ref}) => fold(EffectiveChanged({ref: ref}))`,
439
- ` // TODO(graft): fold this host's own events into its own state.`,
440
- ` }`,
441
- `}`,
442
- ``,
443
- `let toOp = command =>`,
444
- ` switch command {`,
445
- ` | ${n.attachCmd}({${c.entityId}, ${c.file}, altText: ?altText}) => (`,
446
- ` ${c.entityId},`,
447
- ` Attachments.Attach({ref: ${c.file}, altText}),`,
448
- ` )`,
449
- // `Clear` is what a ref-less remove maps onto: the op that empties the set,
450
- // whatever it holds. Nothing here has to look the member up.
451
- ...(single
452
- ? [` | ${n.removeCmd}({${c.entityId}}) => (${c.entityId}, Attachments.Clear)`]
453
- : [
454
- ` | ${n.removeCmd}({${c.entityId}, ${c.file}}) => (`,
455
- ` ${c.entityId},`,
456
- ` Attachments.Remove({ref: ${c.file}}),`,
457
- ` )`,
458
- ` | ${n.setPrimaryCmd}({${c.entityId}, ${c.file}}) => (`,
459
- ` ${c.entityId},`,
460
- ` Attachments.SetPrimary({ref: ${c.file}}),`,
461
- ` )`,
462
- ]),
463
- ...(single
464
- ? [
465
- ` | ${n.setAltTextCmd}({${c.entityId}, altText}) => (`,
466
- ` ${c.entityId},`,
467
- // Not punned: a single-field inline record whose field shares its name
468
- // with the variable filling it is read as a record copy, and the
469
- // anonymous type then escapes its constructor.
470
- ` Attachments.SetPrimaryAltText({altText: altText}),`,
471
- ` )`,
472
- ]
473
- : [
474
- ` | ${n.setAltTextCmd}({${c.entityId}, ${c.file}, altText}) => (`,
475
- ` ${c.entityId},`,
476
- ` Attachments.SetAltText({ref: ${c.file}, altText}),`,
477
- ` )`,
478
- ]),
479
- ` }`,
480
- ``,
481
- // `Some`/`None` for a bounded set only. `fact` is the trait's type and so
482
- // lists a primary at both cardinalities, but a graft with no primary command
483
- // can never decide one — and an arm that fabricated some other event to keep
484
- // the switch total would be writing a fact nothing happened.
485
- `let toEvent = (${c.entityId}, fact) =>`,
486
- ` switch fact {`,
487
- ` | Attachments.Attached({ref, altText}) =>`,
488
- ` ${single ? "Some(" : ""}${n.attached}({${c.entityId}, ${c.file}: ref, altText: ?altText})${single
489
- ? ")"
490
- : ""}`,
491
- ` | Attachments.Removed({ref}) => ${single
492
- ? `Some(${n.removed}({${c.entityId}, ${c.file}: ref}))`
493
- : `${n.removed}({${c.entityId}, ${c.file}: ref})`}`,
494
- ...(single
495
- ? [
496
- ` // Unreachable: no command of this graft chooses a primary, because a set`,
497
- ` // of one has nothing to choose between. It contributes no event.`,
498
- ` | Attachments.PrimarySet(_) => None`,
499
- ]
500
- : [` | Attachments.PrimarySet({ref}) => ${n.primarySet}({${c.entityId}, ${c.file}: ref})`]),
501
- ` | Attachments.AltTextSet({ref, altText}) =>`,
502
- ` ${single ? "Some(" : ""}${n.altTextSet}({${c.entityId}, ${c.file}: ref, altText})${single
503
- ? ")"
504
- : ""}`,
505
- ` | Attachments.EffectiveChanged({ref}) =>`,
506
- ` ${single ? "Some(" : ""}${n.effectiveChanged}({${c.entityId}, ${c.file}: ?ref})${single
507
- ? ")"
508
- : ""}`,
509
- ` }`,
510
- ``,
511
- `let decide = (state, command) =>`,
512
- ` if !state.exists {`,
513
- ` Error(${n.notFound})`,
514
- ` } else {`,
515
- ` // TODO(graft): this host's own refusal goes here, ahead of the set's rules —`,
516
- ` // an \`else if\` returning the error added above. A graft with no extra refusal`,
517
- ` // is a complete graft, so leaving this is legitimate.`,
518
- ` let (${c.entityId}, op) = toOp(command)`,
519
- single
520
- ? ` switch state.attachments->Attachments.decide(~cardinality=Single, op) {`
521
- : ` switch state.attachments->Attachments.decide(op) {`,
522
- ` | Error(#NotAttached) => Error(${n.notAttached})`,
523
- single
524
- ? ` | Ok(facts) => Ok(facts->Array.filterMap(toEvent(${c.entityId}, _)))`
525
- : ` | Ok(facts) => Ok(facts->Array.map(toEvent(${c.entityId}, _)))`,
526
- ` }`,
527
- ` }`,
528
- ``,
529
- ])
429
+ lines(
430
+ [
431
+ `@@reventless.decision`,
432
+ ``,
433
+ `// The set's rules are the trait's. What is left here is this host's own refusal`,
434
+ `// and the mapping between its constructors and the trait's ops and facts.`,
435
+ `module Attachments = TraitAttachments.Attachments_Rules`,
436
+ ``,
437
+ `type state = {exists: bool, attachments: Attachments.t}`,
438
+ ``,
439
+ `let initialState = {exists: false, attachments: Attachments.empty}`,
440
+ ``,
441
+ `let evolve = (state, event) => {`,
442
+ ` let fold = fact => {...state, attachments: state.attachments->Attachments.evolve(fact)}`,
443
+ ` switch event {`,
444
+ // A creation event that carries no id is a bare constructor, so a wildcard
445
+ // payload does not compile against it. The spec above already branches on
446
+ // this; the fold has to branch with it.
447
+ c.createdCarriesEntityId->Option.getOr(true)
448
+ ? ` | ${c.created}(_) => {...state, exists: true}`
449
+ : ` | ${c.created} => {...state, exists: true}`,
450
+ ` | ${n.attached}({${c.file}}) => fold(Attached({ref: ${c.file}, altText: None}))`,
451
+ ` | ${n.removed}({${c.file}}) => fold(Removed({ref: ${c.file}}))`,
452
+ ...single ? [] : [` | ${n.primarySet}({${c.file}}) => fold(PrimarySet({ref: ${c.file}}))`],
453
+ ` | ${n.altTextSet}({${c.file}, altText}) => fold(AltTextSet({ref: ${c.file}, altText}))`,
454
+ ` | ${n.effectiveChanged}({${c.file}: ?ref}) => fold(EffectiveChanged({ref: ref}))`,
455
+ ` // TODO(graft): fold this host's own events into its own state.`,
456
+ ` }`,
457
+ `}`,
458
+ ``,
459
+ `let toOp = command =>`,
460
+ ` switch command {`,
461
+ ` | ${n.attachCmd}({${c.entityId}, ${c.file}, altText: ?altText}) => (`,
462
+ ` ${c.entityId},`,
463
+ ` Attachments.Attach({ref: ${c.file}, altText}),`,
464
+ ` )`,
465
+ // `Clear` is what a ref-less remove maps onto: the op that empties the set,
466
+ // whatever it holds. Nothing here has to look the member up.
467
+ ...single
468
+ ? [` | ${n.removeCmd}({${c.entityId}}) => (${c.entityId}, Attachments.Clear)`]
469
+ : [
470
+ ` | ${n.removeCmd}({${c.entityId}, ${c.file}}) => (`,
471
+ ` ${c.entityId},`,
472
+ ` Attachments.Remove({ref: ${c.file}}),`,
473
+ ` )`,
474
+ ` | ${n.setPrimaryCmd}({${c.entityId}, ${c.file}}) => (`,
475
+ ` ${c.entityId},`,
476
+ ` Attachments.SetPrimary({ref: ${c.file}}),`,
477
+ ` )`,
478
+ ],
479
+ ...single
480
+ ? [
481
+ ` | ${n.setAltTextCmd}({${c.entityId}, altText}) => (`,
482
+ ` ${c.entityId},`,
483
+ // Not punned: a single-field inline record whose field shares its name
484
+ // with the variable filling it is read as a record copy, and the
485
+ // anonymous type then escapes its constructor.
486
+ ` Attachments.SetPrimaryAltText({altText: altText}),`,
487
+ ` )`,
488
+ ]
489
+ : [
490
+ ` | ${n.setAltTextCmd}({${c.entityId}, ${c.file}, altText}) => (`,
491
+ ` ${c.entityId},`,
492
+ ` Attachments.SetAltText({ref: ${c.file}, altText}),`,
493
+ ` )`,
494
+ ],
495
+ ` }`,
496
+ ``,
497
+ // `Some`/`None` for a bounded set only. `fact` is the trait's type and so
498
+ // lists a primary at both cardinalities, but a graft with no primary command
499
+ // can never decide one — and an arm that fabricated some other event to keep
500
+ // the switch total would be writing a fact nothing happened.
501
+ `let toEvent = (${c.entityId}, fact) =>`,
502
+ ` switch fact {`,
503
+ ` | Attachments.Attached({ref, altText}) =>`,
504
+ ` ${single
505
+ ? "Some("
506
+ : ""}${n.attached}({${c.entityId}, ${c.file}: ref, altText: ?altText})${single
507
+ ? ")"
508
+ : ""}`,
509
+ ` | Attachments.Removed({ref}) => ${single
510
+ ? `Some(${n.removed}({${c.entityId}, ${c.file}: ref}))`
511
+ : `${n.removed}({${c.entityId}, ${c.file}: ref})`}`,
512
+ ...single
513
+ ? [
514
+ ` // Unreachable: no command of this graft chooses a primary, because a set`,
515
+ ` // of one has nothing to choose between. It contributes no event.`,
516
+ ` | Attachments.PrimarySet(_) => None`,
517
+ ]
518
+ : [` | Attachments.PrimarySet({ref}) => ${n.primarySet}({${c.entityId}, ${c.file}: ref})`],
519
+ ` | Attachments.AltTextSet({ref, altText}) =>`,
520
+ ` ${single ? "Some(" : ""}${n.altTextSet}({${c.entityId}, ${c.file}: ref, altText})${single
521
+ ? ")"
522
+ : ""}`,
523
+ ` | Attachments.EffectiveChanged({ref}) =>`,
524
+ ` ${single ? "Some(" : ""}${n.effectiveChanged}({${c.entityId}, ${c.file}: ?ref})${single
525
+ ? ")"
526
+ : ""}`,
527
+ ` }`,
528
+ ``,
529
+ `let decide = (state, command) =>`,
530
+ ` if !state.exists {`,
531
+ ` Error(${n.notFound})`,
532
+ ` } else {`,
533
+ ` // TODO(graft): this host's own refusal goes here, ahead of the set's rules —`,
534
+ ` // an \`else if\` returning the error added above. A graft with no extra refusal`,
535
+ ` // is a complete graft, so leaving this is legitimate.`,
536
+ ` let (${c.entityId}, op) = toOp(command)`,
537
+ single
538
+ ? ` switch state.attachments->Attachments.decide(~cardinality=Single, op) {`
539
+ : ` switch state.attachments->Attachments.decide(op) {`,
540
+ ` | Error(#NotAttached) => Error(${n.notAttached})`,
541
+ single
542
+ ? ` | Ok(facts) => Ok(facts->Array.filterMap(toEvent(${c.entityId}, _)))`
543
+ : ` | Ok(facts) => Ok(facts->Array.map(toEvent(${c.entityId}, _)))`,
544
+ ` }`,
545
+ ` }`,
546
+ ``,
547
+ ],
548
+ )
530
549
  }
531
550
 
532
551
  // ── The conformance binding ──────────────────────────────────────────────────
@@ -543,72 +562,101 @@ let conformanceBinding = (c: config): string => {
543
562
  let refB = c.refB->Option.getOr(`/uploads/00000000-0000-4000-8000-000000000002/b`)
544
563
  let createdValue =
545
564
  c.createdCarriesEntityId->Option.getOr(true)
546
- ? `${c.created}({ ${c.entityId}: "${id}"})`
565
+ ? `${c.created}({ ${c.entityId}: ${idValueOf(c, id)}})`
547
566
  : c.created
548
- lines([
549
- `// The Attachments trait's conformance suite, bound to \`${n.slice}\`.`,
550
- `// Emitted whole: every name here is one the graft already declared.`,
551
- ``,
552
- `module Binding = {`,
553
- ` type ref = string`,
554
- ` let refA = "${refA}"`,
555
- ` let refB = "${refB}"`,
556
- ``,
557
- ` module Spec = ${n.slice}`,
558
- ` module Behavior = ${n.slice}_Behavior`,
559
- ``,
560
- ` // Annotated: the slice consumes and emits same-named constructors.`,
561
- ` // The same facts as the slice consumes them: no ${c.entityId}, because the`,
562
- ` // partition already says which entity they belong to.`,
563
- ` module Consumed = {`,
564
- ` let created: array<${n.slice}.consumedEvent> = [${createdValue}]`,
565
- ` let attached = (ref): ${n.slice}.consumedEvent => ${n.attached}({ ${c.file}: ref})`,
566
- ` let removed = (ref): ${n.slice}.consumedEvent => ${n.removed}({ ${c.file}: ref})`,
567
- ...(single
568
- ? []
569
- : [
570
- ` let primarySet = (ref): ${n.slice}.consumedEvent => ${n.primarySet}({ ${c.file}: ref})`,
571
- ]),
572
- ` let altTextSet = (ref, altText): ${n.slice}.consumedEvent =>`,
573
- ` ${n.altTextSet}({ ${c.file}: ref, altText})`,
574
- ` let effectiveChanged = (ref): ${n.slice}.consumedEvent =>`,
575
- ` ${n.effectiveChanged}({ ${c.file}: ?ref})`,
576
- ` }`,
577
- ``,
578
- ` let attach = ref => ${n.slice}.${n.attachCmd}({ ${c.entityId}: "${id}", ${c.file}: ref})`,
579
- ...(single
580
- ? [` let clear = ${n.slice}.${n.removeCmd}({ ${c.entityId}: "${id}"})`]
581
- : [
582
- ` let remove = ref => ${n.slice}.${n.removeCmd}({ ${c.entityId}: "${id}", ${c.file}: ref})`,
583
- ` let setPrimary = ref =>`,
584
- ` ${n.slice}.${n.setPrimaryCmd}({ ${c.entityId}: "${id}", ${c.file}: ref})`,
585
- ]),
586
- single
587
- ? ` let setAltText = altText => ${n.slice}.${n.setAltTextCmd}({ ${c.entityId}: "${id}", altText})`
588
- : ` let setAltText = (ref, altText) =>\n ${n.slice}.${n.setAltTextCmd}({ ${c.entityId}: "${id}", ${c.file}: ref, altText})`,
589
- ``,
590
- ` let attached = ref => ${n.slice}.${n.attached}({ ${c.entityId}: "${id}", ${c.file}: ref})`,
591
- ` let removed = ref => ${n.slice}.${n.removed}({ ${c.entityId}: "${id}", ${c.file}: ref})`,
592
- ...(single
593
- ? []
594
- : [
595
- ` let primarySet = ref =>`,
596
- ` ${n.slice}.${n.primarySet}({ ${c.entityId}: "${id}", ${c.file}: ref})`,
597
- ]),
598
- ` let altTextSet = (ref, altText) =>`,
599
- ` ${n.slice}.${n.altTextSet}({ ${c.entityId}: "${id}", ${c.file}: ref, altText})`,
600
- ` let effectiveChanged = ref =>`,
601
- ` ${n.slice}.${n.effectiveChanged}({ ${c.entityId}: "${id}", ${c.file}: ?ref})`,
602
- ` let notAttached = ${n.slice}.${n.notAttached}`,
603
- `}`,
604
- ``,
605
- single
606
- ? `module Conformance = TraitAttachments.Attachments_Conformance.MakeSingle(Binding)`
607
- : `module Conformance = TraitAttachments.Attachments_Conformance.Make(Binding)`,
608
- ``,
609
- `Conformance.register()`,
610
- ``,
611
- ])
567
+ lines(
568
+ [
569
+ `// The Attachments trait's conformance suite, bound to \`${n.slice}\`.`,
570
+ `// Emitted whole: every name here is one the graft already declared.`,
571
+ ``,
572
+ `module Binding = {`,
573
+ ` type ref = string`,
574
+ ` let refA = "${refA}"`,
575
+ ` let refB = "${refB}"`,
576
+ ``,
577
+ ` module Spec = ${n.slice}`,
578
+ ` module Decision = ${n.slice}_Decision`,
579
+ ``,
580
+ ` // Annotated: the slice consumes and emits same-named constructors.`,
581
+ ` // The same facts as the slice consumes them: no ${c.entityId}, because the`,
582
+ ` // partition already says which entity they belong to.`,
583
+ ` module Consumed = {`,
584
+ ` let created: array<${n.slice}.consumedEvent> = [${createdValue}]`,
585
+ ` let attached = (ref): ${n.slice}.consumedEvent => ${n.attached}({ ${c.file}: ref})`,
586
+ ` let removed = (ref): ${n.slice}.consumedEvent => ${n.removed}({ ${c.file}: ref})`,
587
+ ...single
588
+ ? []
589
+ : [
590
+ ` let primarySet = (ref): ${n.slice}.consumedEvent => ${n.primarySet}({ ${c.file}: ref})`,
591
+ ],
592
+ ` let altTextSet = (ref, altText): ${n.slice}.consumedEvent =>`,
593
+ ` ${n.altTextSet}({ ${c.file}: ref, altText})`,
594
+ ` let effectiveChanged = (ref): ${n.slice}.consumedEvent =>`,
595
+ ` ${n.effectiveChanged}({ ${c.file}: ?ref})`,
596
+ ` }`,
597
+ ``,
598
+ ` let attach = ref => ${n.slice}.${n.attachCmd}({ ${c.entityId}: ${idValueOf(
599
+ c,
600
+ id,
601
+ )}, ${c.file}: ref})`,
602
+ ...single
603
+ ? [` let clear = ${n.slice}.${n.removeCmd}({ ${c.entityId}: ${idValueOf(c, id)}})`]
604
+ : [
605
+ ` let remove = ref => ${n.slice}.${n.removeCmd}({ ${c.entityId}: ${idValueOf(
606
+ c,
607
+ id,
608
+ )}, ${c.file}: ref})`,
609
+ ` let setPrimary = ref =>`,
610
+ ` ${n.slice}.${n.setPrimaryCmd}({ ${c.entityId}: ${idValueOf(
611
+ c,
612
+ id,
613
+ )}, ${c.file}: ref})`,
614
+ ],
615
+ single
616
+ ? ` let setAltText = altText => ${n.slice}.${n.setAltTextCmd}({ ${c.entityId}: ${idValueOf(
617
+ c,
618
+ id,
619
+ )}, altText})`
620
+ : ` let setAltText = (ref, altText) =>\n ${n.slice}.${n.setAltTextCmd}({ ${c.entityId}: ${idValueOf(
621
+ c,
622
+ id,
623
+ )}, ${c.file}: ref, altText})`,
624
+ ``,
625
+ ` let attached = ref => ${n.slice}.${n.attached}({ ${c.entityId}: ${idValueOf(
626
+ c,
627
+ id,
628
+ )}, ${c.file}: ref})`,
629
+ ` let removed = ref => ${n.slice}.${n.removed}({ ${c.entityId}: ${idValueOf(
630
+ c,
631
+ id,
632
+ )}, ${c.file}: ref})`,
633
+ ...single
634
+ ? []
635
+ : [
636
+ ` let primarySet = ref =>`,
637
+ ` ${n.slice}.${n.primarySet}({ ${c.entityId}: ${idValueOf(c, id)}, ${c.file}: ref})`,
638
+ ],
639
+ ` let altTextSet = (ref, altText) =>`,
640
+ ` ${n.slice}.${n.altTextSet}({ ${c.entityId}: ${idValueOf(
641
+ c,
642
+ id,
643
+ )}, ${c.file}: ref, altText})`,
644
+ ` let effectiveChanged = ref =>`,
645
+ ` ${n.slice}.${n.effectiveChanged}({ ${c.entityId}: ${idValueOf(
646
+ c,
647
+ id,
648
+ )}, ${c.file}: ?ref})`,
649
+ ` let notAttached = ${n.slice}.${n.notAttached}`,
650
+ `}`,
651
+ ``,
652
+ single
653
+ ? `module Conformance = TraitAttachments.Attachments_Conformance.MakeSingle(Binding)`
654
+ : `module Conformance = TraitAttachments.Attachments_Conformance.Make(Binding)`,
655
+ ``,
656
+ `Conformance.register()`,
657
+ ``,
658
+ ],
659
+ )
612
660
  }
613
661
 
614
662
  // ── The projection patch ─────────────────────────────────────────────────────
@@ -740,8 +788,8 @@ let emit = (~config: config, ~into: string, ~tests: string): output => {
740
788
  files: [
741
789
  {path: `${into}/StateChange/${n.slice}.res`, contents: sliceSpec(config)},
742
790
  {
743
- path: `${into}/StateChange/${n.slice}_Behavior.res`,
744
- contents: sliceBehavior(config),
791
+ path: `${into}/StateChange/${n.slice}_Decision.res`,
792
+ contents: sliceDecision(config),
745
793
  },
746
794
  {
747
795
  path: `${tests}/${n.slice}Conformance_GWT.res`,
@@ -8,11 +8,12 @@ import * as Attachments_Rules$TraitAttachments from "./Attachments_Rules.res.mjs
8
8
  let configSchema = Sury.$schema(s => ({
9
9
  entity: s.m(Sury.string),
10
10
  entityId: s.m(Sury.string),
11
+ entityIdType: s.m(Sury.$option(Sury.string)),
11
12
  noun: s.m(Sury.string),
12
13
  file: s.m(Sury.string),
13
14
  cardinality: s.m(Sury.$option(Attachments_Rules$TraitAttachments.cardinalitySchema)),
14
15
  created: s.m(Sury.string),
15
- createdCarriesEntityId: s.m(Sury.$option(Sury.bool)),
16
+ createdCarriesEntityId: s.m(Sury.$option(Sury.boolean)),
16
17
  view: s.m(Sury.string),
17
18
  lifecycleType: s.m(Sury.$option(Sury.string)),
18
19
  refType: s.m(Sury.$option(Sury.string)),
@@ -54,6 +55,19 @@ function refTypeOf(c) {
54
55
  return Stdlib_Option.getOr(c.refType, "Reventless.UploadableImage.t");
55
56
  }
56
57
 
58
+ function idTypeOf(c) {
59
+ return Stdlib_Option.mapOr(c.entityIdType, "string", t => t + ".t");
60
+ }
61
+
62
+ function idValueOf(c, literal) {
63
+ let t = c.entityIdType;
64
+ if (t !== undefined) {
65
+ return t + `.make("` + literal + `")`;
66
+ } else {
67
+ return `"` + literal + `"`;
68
+ }
69
+ }
70
+
57
71
  function viewTypeOf(c) {
58
72
  if (Stdlib_Option.getOr(c.refType, "Reventless.UploadableImage.t").includes("Image")) {
59
73
  return "Reventless.CaptionedImage.t";
@@ -156,7 +170,7 @@ function sliceSpec(c) {
156
170
  let sel = selectionTypeOf(c);
157
171
  let single = Stdlib_Option.getOr(c.cardinality, "Many") === "Single";
158
172
  let attrs = commandAttributes(c);
159
- let createdArm = Stdlib_Option.getOr(c.createdCarriesEntityId, true) ? ` | ` + c.created + `({ ` + c.entityId + `: string})` : ` | ` + c.created;
173
+ let createdArm = Stdlib_Option.getOr(c.createdCarriesEntityId, true) ? ` | ` + c.created + `({ ` + c.entityId + `: ` + idTypeOf(c) + `})` : ` | ` + c.created;
160
174
  let primaryArm = prefix => {
161
175
  if (single) {
162
176
  return [];
@@ -216,12 +230,12 @@ function sliceSpec(c) {
216
230
  [
217
231
  `@schema`,
218
232
  `type command =`,
219
- attrs + n.attachCmd + `({ ` + c.entityId + `: string, ` + c.file + `: ` + ref + `, altText?: string})`,
220
- single ? attrs + n.removeCmd + `({ ` + c.entityId + `: string})` : attrs + n.removeCmd + `({ ` + c.entityId + `: string, ` + c.file + `: ` + sel + `})`
233
+ attrs + n.attachCmd + `({ ` + c.entityId + `: ` + idTypeOf(c) + `, ` + c.file + `: ` + ref + `, altText?: string})`,
234
+ single ? attrs + n.removeCmd + `({ ` + c.entityId + `: ` + idTypeOf(c) + `})` : attrs + n.removeCmd + `({ ` + c.entityId + `: ` + idTypeOf(c) + `, ` + c.file + `: ` + sel + `})`
221
235
  ],
222
- single ? [] : [attrs + n.setPrimaryCmd + `({ ` + c.entityId + `: string, ` + c.file + `: ` + sel + `})`],
236
+ single ? [] : [attrs + n.setPrimaryCmd + `({ ` + c.entityId + `: ` + idTypeOf(c) + `, ` + c.file + `: ` + sel + `})`],
223
237
  [
224
- single ? attrs + n.setAltTextCmd + `({ ` + c.entityId + `: string, altText: string})` : attrs + n.setAltTextCmd + `({ ` + c.entityId + `: string, ` + c.file + `: ` + sel + `, altText: string})`,
238
+ single ? attrs + n.setAltTextCmd + `({ ` + c.entityId + `: ` + idTypeOf(c) + `, altText: string})` : attrs + n.setAltTextCmd + `({ ` + c.entityId + `: ` + idTypeOf(c) + `, ` + c.file + `: ` + sel + `, altText: string})`,
225
239
  ``,
226
240
  `@schema`,
227
241
  `type error =`,
@@ -231,16 +245,16 @@ function sliceSpec(c) {
231
245
  ``,
232
246
  `@schema`,
233
247
  `type event =`,
234
- ` | ` + n.attached + `({ ` + c.entityId + `: string, ` + c.file + `: ` + ref + `, altText?: string})`,
235
- ` | ` + n.removed + `({ ` + c.entityId + `: string, ` + c.file + `: ` + ref + `})`
248
+ ` | ` + n.attached + `({ ` + c.entityId + `: ` + idTypeOf(c) + `, ` + c.file + `: ` + ref + `, altText?: string})`,
249
+ ` | ` + n.removed + `({ ` + c.entityId + `: ` + idTypeOf(c) + `, ` + c.file + `: ` + ref + `})`
236
250
  ],
237
- primaryArm(c.entityId + `: string, `),
251
+ primaryArm(c.entityId + `: ` + idTypeOf(c) + `, `),
238
252
  [
239
- ` | ` + n.altTextSet + `({ ` + c.entityId + `: string, ` + c.file + `: ` + ref + `, altText: string})`,
253
+ ` | ` + n.altTextSet + `({ ` + c.entityId + `: ` + idTypeOf(c) + `, ` + c.file + `: ` + ref + `, altText: string})`,
240
254
  ` // The member a reader should now show, or none. A conclusion rather than a`,
241
255
  ` // decision: most of the moves that change it — a first attachment, a removal`,
242
256
  ` // promoting the next — are nobody's choice, so nothing else announces them.`,
243
- ` | ` + n.effectiveChanged + `({ ` + c.entityId + `: string, ` + c.file + `?: ` + ref + `})`,
257
+ ` | ` + n.effectiveChanged + `({ ` + c.entityId + `: ` + idTypeOf(c) + `, ` + c.file + `?: ` + ref + `})`,
244
258
  ``
245
259
  ],
246
260
  commandTransitionBinding(c),
@@ -254,12 +268,12 @@ function sliceSpec(c) {
254
268
  ]).join("\n");
255
269
  }
256
270
 
257
- function sliceBehavior(c) {
271
+ function sliceDecision(c) {
258
272
  let n = namesOf(c);
259
273
  let single = Stdlib_Option.getOr(c.cardinality, "Many") === "Single";
260
274
  return Belt_Array.concatMany([
261
275
  [
262
- `@@reventless.behavior`,
276
+ `@@reventless.decision`,
263
277
  ``,
264
278
  `// The set's rules are the trait's. What is left here is this host's own refusal`,
265
279
  `// and the mapping between its constructors and the trait's ops and facts.`,
@@ -371,7 +385,7 @@ function conformanceBinding(c) {
371
385
  let id = "e1";
372
386
  let refA = Stdlib_Option.getOr(c.refA, `/uploads/00000000-0000-4000-8000-000000000001/a`);
373
387
  let refB = Stdlib_Option.getOr(c.refB, `/uploads/00000000-0000-4000-8000-000000000002/b`);
374
- let createdValue = Stdlib_Option.getOr(c.createdCarriesEntityId, true) ? c.created + `({ ` + c.entityId + `: "` + id + `"})` : c.created;
388
+ let createdValue = Stdlib_Option.getOr(c.createdCarriesEntityId, true) ? c.created + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `})` : c.created;
375
389
  return Belt_Array.concatMany([
376
390
  [
377
391
  `// The Attachments trait's conformance suite, bound to \`` + n.slice + `\`.`,
@@ -383,7 +397,7 @@ function conformanceBinding(c) {
383
397
  ` let refB = "` + refB + `"`,
384
398
  ``,
385
399
  ` module Spec = ` + n.slice,
386
- ` module Behavior = ` + n.slice + `_Behavior`,
400
+ ` module Decision = ` + n.slice + `_Decision`,
387
401
  ``,
388
402
  ` // Annotated: the slice consumes and emits same-named constructors.`,
389
403
  ` // The same facts as the slice consumes them: no ` + c.entityId + `, because the`,
@@ -401,28 +415,28 @@ function conformanceBinding(c) {
401
415
  ` ` + n.effectiveChanged + `({ ` + c.file + `: ?ref})`,
402
416
  ` }`,
403
417
  ``,
404
- ` let attach = ref => ` + n.slice + `.` + n.attachCmd + `({ ` + c.entityId + `: "` + id + `", ` + c.file + `: ref})`
418
+ ` let attach = ref => ` + n.slice + `.` + n.attachCmd + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `, ` + c.file + `: ref})`
405
419
  ],
406
- single ? [` let clear = ` + n.slice + `.` + n.removeCmd + `({ ` + c.entityId + `: "` + id + `"})`] : [
407
- ` let remove = ref => ` + n.slice + `.` + n.removeCmd + `({ ` + c.entityId + `: "` + id + `", ` + c.file + `: ref})`,
420
+ single ? [` let clear = ` + n.slice + `.` + n.removeCmd + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `})`] : [
421
+ ` let remove = ref => ` + n.slice + `.` + n.removeCmd + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `, ` + c.file + `: ref})`,
408
422
  ` let setPrimary = ref =>`,
409
- ` ` + n.slice + `.` + n.setPrimaryCmd + `({ ` + c.entityId + `: "` + id + `", ` + c.file + `: ref})`
423
+ ` ` + n.slice + `.` + n.setPrimaryCmd + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `, ` + c.file + `: ref})`
410
424
  ],
411
425
  [
412
- single ? ` let setAltText = altText => ` + n.slice + `.` + n.setAltTextCmd + `({ ` + c.entityId + `: "` + id + `", altText})` : ` let setAltText = (ref, altText) =>\n ` + n.slice + `.` + n.setAltTextCmd + `({ ` + c.entityId + `: "` + id + `", ` + c.file + `: ref, altText})`,
426
+ single ? ` let setAltText = altText => ` + n.slice + `.` + n.setAltTextCmd + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `, altText})` : ` let setAltText = (ref, altText) =>\n ` + n.slice + `.` + n.setAltTextCmd + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `, ` + c.file + `: ref, altText})`,
413
427
  ``,
414
- ` let attached = ref => ` + n.slice + `.` + n.attached + `({ ` + c.entityId + `: "` + id + `", ` + c.file + `: ref})`,
415
- ` let removed = ref => ` + n.slice + `.` + n.removed + `({ ` + c.entityId + `: "` + id + `", ` + c.file + `: ref})`
428
+ ` let attached = ref => ` + n.slice + `.` + n.attached + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `, ` + c.file + `: ref})`,
429
+ ` let removed = ref => ` + n.slice + `.` + n.removed + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `, ` + c.file + `: ref})`
416
430
  ],
417
431
  single ? [] : [
418
432
  ` let primarySet = ref =>`,
419
- ` ` + n.slice + `.` + n.primarySet + `({ ` + c.entityId + `: "` + id + `", ` + c.file + `: ref})`
433
+ ` ` + n.slice + `.` + n.primarySet + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `, ` + c.file + `: ref})`
420
434
  ],
421
435
  [
422
436
  ` let altTextSet = (ref, altText) =>`,
423
- ` ` + n.slice + `.` + n.altTextSet + `({ ` + c.entityId + `: "` + id + `", ` + c.file + `: ref, altText})`,
437
+ ` ` + n.slice + `.` + n.altTextSet + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `, ` + c.file + `: ref, altText})`,
424
438
  ` let effectiveChanged = ref =>`,
425
- ` ` + n.slice + `.` + n.effectiveChanged + `({ ` + c.entityId + `: "` + id + `", ` + c.file + `: ?ref})`,
439
+ ` ` + n.slice + `.` + n.effectiveChanged + `({ ` + c.entityId + `: ` + idValueOf(c, id) + `, ` + c.file + `: ?ref})`,
426
440
  ` let notAttached = ` + n.slice + `.` + n.notAttached,
427
441
  `}`,
428
442
  ``,
@@ -550,8 +564,8 @@ function emit(config, into, tests) {
550
564
  contents: sliceSpec(config)
551
565
  },
552
566
  {
553
- path: into + `/StateChange/` + n.slice + `_Behavior.res`,
554
- contents: sliceBehavior(config)
567
+ path: into + `/StateChange/` + n.slice + `_Decision.res`,
568
+ contents: sliceDecision(config)
555
569
  },
556
570
  {
557
571
  path: tests + `/` + n.slice + `Conformance_GWT.res`,
@@ -568,6 +582,8 @@ export {
568
582
  isSingle,
569
583
  namesOf,
570
584
  refTypeOf,
585
+ idTypeOf,
586
+ idValueOf,
571
587
  viewTypeOf,
572
588
  setFieldOf,
573
589
  selectionBinding,
@@ -578,7 +594,7 @@ export {
578
594
  commandTransitionBinding,
579
595
  lines,
580
596
  sliceSpec,
581
- sliceBehavior,
597
+ sliceDecision,
582
598
  conformanceBinding,
583
599
  singleProjectionPatch,
584
600
  manyProjectionPatch,