@reventlessdev/reventless-gwt 1.0.0-alpha.272 → 1.0.0-alpha.273

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/CHANGELOG.md CHANGED
@@ -3,6 +3,13 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 1.0.0-alpha.273 (2026-10-30)
7
+
8
+ ### Features
9
+
10
+ * **spec:** an aggregate keyed by its owner's id refuses other callers ([e05f287](https://github.com/ReventlessDev/reventless-core/commit/e05f287eee959d26190af494691c4fa472797cad))
11
+
12
+
6
13
  # 1.0.0-alpha.272 (2026-10-30)
7
14
 
8
15
  **Note:** Version bump only for package @reventlessdev/reventless-gwt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-gwt",
3
- "version": "1.0.0-alpha.272",
3
+ "version": "1.0.0-alpha.273",
4
4
  "description": "Given-When-Then DSLs and test harness for Reventless slice testing",
5
5
  "license": "Apache-2.0",
6
6
  "jest": {
@@ -15,11 +15,11 @@
15
15
  "dependencies": {
16
16
  "sury": "11.0.0",
17
17
  "@reventlessdev/rescript-effect": "1.0.0-alpha.1",
18
- "@reventlessdev/rescript-node": "2.0.0-alpha.24",
19
- "@reventlessdev/reventless-infra": "3.0.0-alpha.219",
20
18
  "@reventlessdev/rescript-jest": "1.0.0-alpha.13",
21
- "@reventlessdev/reventless-core": "3.0.0-alpha.324",
22
- "@reventlessdev/reventless-spec": "3.0.0-alpha.190"
19
+ "@reventlessdev/rescript-node": "2.0.0-alpha.24",
20
+ "@reventlessdev/reventless-core": "3.0.0-alpha.325",
21
+ "@reventlessdev/reventless-infra": "3.0.0-alpha.220",
22
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.191"
23
23
  },
24
24
  "devDependencies": {
25
25
  "rescript": "12.3.1",
@@ -26,7 +26,8 @@ open ReventlessCore
26
26
  // Who issues the command. `asCaller` names the caller before `whenCmd`; the
27
27
  // command is then checked as production checks it: its `@authorize` rule against
28
28
  // the caller's roles, then — for slices and aggregates that mark `@owner` on the
29
- // events they decide on — against the owners the given events record. Without
29
+ // events they decide on — against the owners the given events record, and for an
30
+ // aggregate owned by its id (`Id.Owned`) against the id `onId` names. Without
30
31
  // `asCaller` the command carries no caller claim, which the handler reads as the
31
32
  // platform acting for itself — so every scenario written before this existed is
32
33
  // unchanged.
@@ -83,6 +84,13 @@ module Caller = {
83
84
  /** A caller exempt from ownership rules, acting on anyone's behalf. Holds no
84
85
  role: elevation does not grant a command whose rule the caller fails. */
85
86
  let operator: t = {claim: Exempt, roles: [], signedIn: true}
87
+ /** An operator holding `roles`: a role the deployment elevates, such as an
88
+ administrator acting on someone's behalf. */
89
+ let operatorIn = (roles: array<'role>): t => {
90
+ claim: Exempt,
91
+ roles: roleNames(roles),
92
+ signedIn: true,
93
+ }
86
94
  /** A caller with no identity. */
87
95
  let anonymous: t = {claim: Unidentified, roles: [], signedIn: false}
88
96
  }
@@ -96,6 +104,7 @@ module type Callers = {
96
104
  let owner: ('id, ~roles: array<role>=?) => t
97
105
  let inRoles: array<role> => t
98
106
  let operator: t
107
+ let operatorIn: array<role> => t
99
108
  let anonymous: t
100
109
  }
101
110
 
@@ -109,6 +118,7 @@ module Callers = (
109
118
  let owner = (id, ~roles: array<role>=[]) => Caller.owner(id, ~roles)
110
119
  let inRoles = (roles: array<role>) => Caller.inRoles(roles)
111
120
  let operator = Caller.operator
121
+ let operatorIn = (roles: array<role>) => Caller.operatorIn(roles)
112
122
  let anonymous = Caller.anonymous
113
123
  }
114
124
 
@@ -120,10 +130,14 @@ module type ActingSpec = {
120
130
  type command
121
131
  type role
122
132
  let authorizationOf: string => Reventless.Authorization.rule<role>
133
+ // The aggregate's id is its owner (`Id.Owned`).
134
+ let ownedById: bool
123
135
  }
124
136
 
125
137
  module Acting = (Spec: ActingSpec) => {
126
138
  let caller: ref<option<Caller.t>> = ref(None)
139
+ // The aggregate the next command acts on, when the scenario names one.
140
+ let streamId: ref<option<string>> = ref(None)
127
141
  let refusal: ref<option<CommandTopic_Helpers.rejectedResult>> = ref(None)
128
142
 
129
143
  let ownerFieldsByEventType = Reventless.Owner.fieldNamesByVariant(
@@ -135,6 +149,11 @@ module Acting = (Spec: ActingSpec) => {
135
149
  history
136
150
  }
137
151
 
152
+ let onId = (history, id: string) => {
153
+ streamId := Some(id)
154
+ history
155
+ }
156
+
138
157
  let commandName = command =>
139
158
  command->Message.encode(Spec.commandSchema)->Message.variantNameOfJson
140
159
 
@@ -164,12 +183,14 @@ module Acting = (Spec: ActingSpec) => {
164
183
  // The caller is consumed: the next scenario starts with no claim.
165
184
  let refuses = (history: array<Spec.history>, command: Spec.command): bool => {
166
185
  let who = caller.contents
186
+ let id = streamId.contents
167
187
  caller := None
188
+ streamId := None
168
189
  refusal := None
169
190
  let claim = who->Option.map(w => w.claim)
170
191
  if who->Option.mapOr(false, refusedByRule(_, command)) {
171
192
  true
172
- } else if ownerFieldsByEventType->Dict.keysToArray->Array.length == 0 {
193
+ } else if ownerFieldsByEventType->Dict.keysToArray->Array.length == 0 && !Spec.ownedById {
173
194
  false
174
195
  } else {
175
196
  let owners = history->Array.reduce([], (owners, event) => {
@@ -179,8 +200,15 @@ module Acting = (Spec: ActingSpec) => {
179
200
  | None => owners
180
201
  }
181
202
  })
203
+ // An aggregate owned by its id, in a scenario that names none: the
204
+ // partition cannot be named, as the handler would say.
205
+ let recordedOwners = switch (Spec.ownedById, id) {
206
+ | (false, _) => Some(owners)
207
+ | (true, Some(id)) => Some(owners->Reventless.Owner.streamOwners(~ownedById=true, ~id))
208
+ | (true, None) => None
209
+ }
182
210
  refusal :=
183
- Reventless.OwnerScope.decideActing(~claim, ~recordedOwners=Some(owners))
211
+ Reventless.OwnerScope.decideActing(~claim, ~recordedOwners)
184
212
  ->CommandTopic_Helpers.ownershipRefusal(~component=Spec.name, ~command=commandName(command))
185
213
  ->Option.map(r => r.rejected)
186
214
  refusal.contents->Option.isSome
@@ -466,6 +494,7 @@ module Make = (Spec: DecisionSpec, Decision: Decision with module Spec := Spec):
466
494
  let commandSchema = Spec.commandSchema
467
495
  type role = Spec.role
468
496
  let authorizationOf = Spec.authorizationOf
497
+ let ownedById = false
469
498
  })
470
499
  let asCaller = Guard.asCaller
471
500
 
@@ -757,7 +786,8 @@ module Make = (Spec: DecisionSpec, Decision: Decision with module Spec := Spec):
757
786
  // only carries the three @schema types — no `name` — and ReScript's
758
787
  // `with module Spec = X` can only equate the inner Spec to a concrete
759
788
  // module, not constrain it to a module type that adds `name`.
760
- module type AggregateSpec = {
789
+ // What a step that only decides needs of an aggregate; `AggregateSpec` adds the id.
790
+ module type AggregateDeciderSpec = {
761
791
  let name: string
762
792
  @schema
763
793
  type command
@@ -769,6 +799,11 @@ module type AggregateSpec = {
769
799
  let authorizationOf: string => Reventless.Authorization.rule<role>
770
800
  }
771
801
 
802
+ module type AggregateSpec = {
803
+ module Id: Reventless.Id.T
804
+ include AggregateDeciderSpec
805
+ }
806
+
772
807
  module type AggregateT = {
773
808
  module Spec: AggregateSpec
774
809
 
@@ -780,6 +815,9 @@ module type AggregateT = {
780
815
  // Who issues the next `whenCmd`; see `Caller`.
781
816
  module Caller: Callers with type role = Spec.role
782
817
  let asCaller: (array<Spec.event>, Caller.t) => array<Spec.event>
818
+ // Which aggregate the next `whenCmd` acts on. Matters only where the id is the
819
+ // owner (`Id.Owned`): there an owner's command on no named id is refused.
820
+ let onId: (array<Spec.event>, Spec.Id.t) => array<Spec.event>
783
821
 
784
822
  let whenCmd: (array<Spec.event>, Spec.command) => array<Spec.event>
785
823
 
@@ -831,8 +869,10 @@ module MakeFromAggregate = (Spec: AggregateSpec, Decision: Decision.T with modul
831
869
  let commandSchema = Spec.commandSchema
832
870
  type role = Spec.role
833
871
  let authorizationOf = Spec.authorizationOf
872
+ let ownedById = Reventless.Owner.isOwnedById(Spec.Id.schema)
834
873
  })
835
874
  let asCaller = Guard.asCaller
875
+ let onId = (history, id) => history->Guard.onId(id->Spec.Id.toString)
836
876
 
837
877
  let exec = (history, command): array<Spec.event> => {
838
878
  errors := []
@@ -64,6 +64,14 @@ let operator = {
64
64
  signedIn: true
65
65
  };
66
66
 
67
+ function operatorIn(roles) {
68
+ return {
69
+ claim: "Exempt",
70
+ roles: roleNames(roles),
71
+ signedIn: true
72
+ };
73
+ }
74
+
67
75
  let anonymous_roles = [];
68
76
 
69
77
  let anonymous = {
@@ -77,6 +85,7 @@ let Caller = {
77
85
  owner: owner,
78
86
  inRoles: inRoles,
79
87
  operator: operator,
88
+ operatorIn: operatorIn,
80
89
  anonymous: anonymous
81
90
  };
82
91
 
@@ -86,10 +95,12 @@ function Callers(R) {
86
95
  return owner(id, roles);
87
96
  };
88
97
  let inRoles$1 = inRoles;
98
+ let operatorIn$1 = operatorIn;
89
99
  return {
90
100
  owner: owner$1,
91
101
  inRoles: inRoles$1,
92
102
  operator: operator,
103
+ operatorIn: operatorIn$1,
93
104
  anonymous: anonymous
94
105
  };
95
106
  }
@@ -98,6 +109,9 @@ function Acting(Spec) {
98
109
  let caller = {
99
110
  contents: undefined
100
111
  };
112
+ let streamId = {
113
+ contents: undefined
114
+ };
101
115
  let refusal = {
102
116
  contents: undefined
103
117
  };
@@ -106,6 +120,10 @@ function Acting(Spec) {
106
120
  caller.contents = who;
107
121
  return history;
108
122
  };
123
+ let onId = (history, id) => {
124
+ streamId.contents = id;
125
+ return history;
126
+ };
109
127
  let commandName = command => Message$ReventlessCore.variantNameOfJson(Message$ReventlessCore.encode(command, Spec.commandSchema));
110
128
  let refusedByRule = (who, command) => {
111
129
  if (Authorization$Reventless.admits(Authorization$Reventless.named(Spec.authorizationOf(Message$ReventlessCore.variantNameOfJson(Message$ReventlessCore.encode(command, Spec.commandSchema)))), who.signedIn, role => who.roles.includes(role))) {
@@ -120,13 +138,15 @@ function Acting(Spec) {
120
138
  };
121
139
  let refuses = (history, command) => {
122
140
  let who = caller.contents;
141
+ let id = streamId.contents;
123
142
  caller.contents = undefined;
143
+ streamId.contents = undefined;
124
144
  refusal.contents = undefined;
125
145
  let claim = Stdlib_Option.map(who, w => w.claim);
126
146
  if (Stdlib_Option.mapOr(who, false, __x => refusedByRule(__x, command))) {
127
147
  return true;
128
148
  }
129
- if (Object.keys(ownerFieldsByEventType).length === 0) {
149
+ if (Object.keys(ownerFieldsByEventType).length === 0 && !Spec.ownedById) {
130
150
  return false;
131
151
  }
132
152
  let owners = Stdlib_Array.reduce(history, [], (owners, event) => {
@@ -138,7 +158,10 @@ function Acting(Spec) {
138
158
  return owners;
139
159
  }
140
160
  });
141
- refusal.contents = Stdlib_Option.map(CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(claim, owners), Spec.name, Message$ReventlessCore.variantNameOfJson(Message$ReventlessCore.encode(command, Spec.commandSchema))), r => r.rejected);
161
+ let recordedOwners = Spec.ownedById ? (
162
+ id !== undefined ? Owner$Reventless.streamOwners(owners, true, id) : undefined
163
+ ) : owners;
164
+ refusal.contents = Stdlib_Option.map(CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(claim, recordedOwners), Spec.name, Message$ReventlessCore.variantNameOfJson(Message$ReventlessCore.encode(command, Spec.commandSchema))), r => r.rejected);
142
165
  return Stdlib_Option.isSome(refusal.contents);
143
166
  };
144
167
  let encRefusal = r => Object.fromEntries([
@@ -175,9 +198,11 @@ function Acting(Spec) {
175
198
  };
176
199
  return {
177
200
  caller: caller,
201
+ streamId: streamId,
178
202
  refusal: refusal,
179
203
  ownerFieldsByEventType: ownerFieldsByEventType,
180
204
  asCaller: asCaller,
205
+ onId: onId,
181
206
  commandName: commandName,
182
207
  refusedByRule: refusedByRule,
183
208
  refuses: refuses,
@@ -369,10 +394,12 @@ function Make(Spec) {
369
394
  return owner(id, roles);
370
395
  };
371
396
  let inRoles$1 = inRoles;
397
+ let operatorIn$1 = operatorIn;
372
398
  let Caller = {
373
399
  owner: owner$1,
374
400
  inRoles: inRoles$1,
375
401
  operator: operator,
402
+ operatorIn: operatorIn$1,
376
403
  anonymous: anonymous
377
404
  };
378
405
  let name = Spec.name;
@@ -382,6 +409,9 @@ function Make(Spec) {
382
409
  let caller = {
383
410
  contents: undefined
384
411
  };
412
+ let streamId = {
413
+ contents: undefined
414
+ };
385
415
  let refusal = {
386
416
  contents: undefined
387
417
  };
@@ -393,6 +423,7 @@ function Make(Spec) {
393
423
  let refuses = (history, command) => {
394
424
  let who = caller.contents;
395
425
  caller.contents = undefined;
426
+ streamId.contents = undefined;
396
427
  refusal.contents = undefined;
397
428
  let claim = Stdlib_Option.map(who, w => w.claim);
398
429
  if (Stdlib_Option.mapOr(who, false, __x => {
@@ -408,7 +439,7 @@ function Make(Spec) {
408
439
  })) {
409
440
  return true;
410
441
  }
411
- if (Object.keys(ownerFieldsByEventType).length === 0) {
442
+ if (Object.keys(ownerFieldsByEventType).length === 0 && true) {
412
443
  return false;
413
444
  }
414
445
  let owners = Stdlib_Array.reduce(history, [], (owners, event) => {
@@ -420,7 +451,8 @@ function Make(Spec) {
420
451
  return owners;
421
452
  }
422
453
  });
423
- refusal.contents = Stdlib_Option.map(CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(claim, owners), name, Message$ReventlessCore.variantNameOfJson(Message$ReventlessCore.encode(command, commandSchema))), r => r.rejected);
454
+ let recordedOwners = owners;
455
+ refusal.contents = Stdlib_Option.map(CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(claim, recordedOwners), name, Message$ReventlessCore.variantNameOfJson(Message$ReventlessCore.encode(command, commandSchema))), r => r.rejected);
424
456
  return Stdlib_Option.isSome(refusal.contents);
425
457
  };
426
458
  let encRefusal = r => Object.fromEntries([
@@ -758,19 +790,25 @@ function MakeFromAggregate(Spec) {
758
790
  return owner(id, roles);
759
791
  };
760
792
  let inRoles$1 = inRoles;
793
+ let operatorIn$1 = operatorIn;
761
794
  let Caller = {
762
795
  owner: owner$1,
763
796
  inRoles: inRoles$1,
764
797
  operator: operator,
798
+ operatorIn: operatorIn$1,
765
799
  anonymous: anonymous
766
800
  };
767
801
  let name = Spec.name;
768
802
  let historySchema = Spec.eventSchema;
769
803
  let commandSchema = Spec.commandSchema;
770
804
  let authorizationOf = Spec.authorizationOf;
805
+ let ownedById = Owner$Reventless.isOwnedById(Spec.Id.schema);
771
806
  let caller = {
772
807
  contents: undefined
773
808
  };
809
+ let streamId = {
810
+ contents: undefined
811
+ };
774
812
  let refusal = {
775
813
  contents: undefined
776
814
  };
@@ -781,7 +819,9 @@ function MakeFromAggregate(Spec) {
781
819
  };
782
820
  let refuses = (history, command) => {
783
821
  let who = caller.contents;
822
+ let id = streamId.contents;
784
823
  caller.contents = undefined;
824
+ streamId.contents = undefined;
785
825
  refusal.contents = undefined;
786
826
  let claim = Stdlib_Option.map(who, w => w.claim);
787
827
  if (Stdlib_Option.mapOr(who, false, __x => {
@@ -797,7 +837,7 @@ function MakeFromAggregate(Spec) {
797
837
  })) {
798
838
  return true;
799
839
  }
800
- if (Object.keys(ownerFieldsByEventType).length === 0) {
840
+ if (Object.keys(ownerFieldsByEventType).length === 0 && !ownedById) {
801
841
  return false;
802
842
  }
803
843
  let owners = Stdlib_Array.reduce(history, [], (owners, event) => {
@@ -809,7 +849,10 @@ function MakeFromAggregate(Spec) {
809
849
  return owners;
810
850
  }
811
851
  });
812
- refusal.contents = Stdlib_Option.map(CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(claim, owners), name, Message$ReventlessCore.variantNameOfJson(Message$ReventlessCore.encode(command, commandSchema))), r => r.rejected);
852
+ let recordedOwners = ownedById ? (
853
+ id !== undefined ? Owner$Reventless.streamOwners(owners, true, id) : undefined
854
+ ) : owners;
855
+ refusal.contents = Stdlib_Option.map(CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(claim, recordedOwners), name, Message$ReventlessCore.variantNameOfJson(Message$ReventlessCore.encode(command, commandSchema))), r => r.rejected);
813
856
  return Stdlib_Option.isSome(refusal.contents);
814
857
  };
815
858
  let encRefusal = r => Object.fromEntries([
@@ -828,6 +871,11 @@ function MakeFromAggregate(Spec) {
828
871
  actual: encRefusal(r),
829
872
  actualEvents: []
830
873
  }));
874
+ let onId = (history, id) => {
875
+ let id$1 = Spec.Id.toString(id);
876
+ streamId.contents = id$1;
877
+ return history;
878
+ };
831
879
  let givenEvents = events => events;
832
880
  let whenCmd = (history, cmd) => {
833
881
  if (ScenarioRecorder$ReventlessGwt.recording()) {
@@ -936,6 +984,7 @@ function MakeFromAggregate(Spec) {
936
984
  givenEvents: givenEvents,
937
985
  Caller: Caller,
938
986
  asCaller: asCaller,
987
+ onId: onId,
939
988
  whenCmd: whenCmd,
940
989
  thenEvent: thenEvent,
941
990
  thenCompareEvent: thenCompareEvent,
package/src/Flow_GWT.res CHANGED
@@ -404,7 +404,7 @@ module CommandStep = (
404
404
  // histories isolated (a `Place` on `o2` does not see the events of `o1`).
405
405
 
406
406
  module AggregateCommandStep = (
407
- Spec: Decision_GWT.AggregateSpec,
407
+ Spec: Decision_GWT.AggregateDeciderSpec,
408
408
  Decision: Reventless.Decision.T with module Spec = Spec,
409
409
  ) => {
410
410
  let aggregateDecoder = Reventless.DcbDecode.makeDecoder(Spec.eventSchema)