@reventlessdev/reventless-core 3.0.0-alpha.324 → 3.0.0-alpha.325

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
+ # 3.0.0-alpha.325 (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
  # 3.0.0-alpha.324 (2026-10-30)
7
14
 
8
15
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-core",
3
- "version": "3.0.0-alpha.324",
3
+ "version": "3.0.0-alpha.325",
4
4
  "description": "Core package for Reventless framework",
5
5
  "license": "Apache-2.0",
6
6
  "jest": {
@@ -28,17 +28,17 @@
28
28
  "dependencies": {
29
29
  "sury": "11.0.0",
30
30
  "uuid": "^13.0.0",
31
+ "@reventlessdev/rescript-effect": "1.0.0-alpha.1",
31
32
  "@reventlessdev/rescript-hash-object": "1.2.0-alpha.15",
32
33
  "@reventlessdev/rescript-fast-csv": "2.0.0-alpha.24",
33
- "@reventlessdev/rescript-effect": "1.0.0-alpha.1",
34
34
  "@reventlessdev/rescript-node": "2.0.0-alpha.24",
35
35
  "@reventlessdev/rescript-jest": "1.0.0-alpha.13",
36
36
  "@reventlessdev/rescript-pulumi-pulumi": "3.0.0-alpha.0",
37
37
  "@reventlessdev/rescript-uuid": "2.0.0-alpha.1",
38
38
  "@reventlessdev/rescript-ssh2": "2.0.0-alpha.25",
39
- "@reventlessdev/reventless-spec": "3.0.0-alpha.190",
40
- "@reventlessdev/reventless-interop": "3.0.0-alpha.42",
41
- "@reventlessdev/reventless-infra": "3.0.0-alpha.219"
39
+ "@reventlessdev/reventless-infra": "3.0.0-alpha.220",
40
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.191",
41
+ "@reventlessdev/reventless-interop": "3.0.0-alpha.42"
42
42
  },
43
43
  "devDependencies": {
44
44
  "rescript": "12.3.1",
@@ -63,6 +63,9 @@ module Make = (
63
63
  Spec.eventSchema->S.castToUnknown,
64
64
  )
65
65
  let actsOnOwned = ownerFieldsByEventType->Dict.keysToArray->Array.length > 0
66
+ // An aggregate whose id is its owner (`Id.Owned`) needs no recorded event, so
67
+ // it keeps its snapshots.
68
+ let ownedById = Reventless.Owner.isOwnedById(Spec.Id.schema)
66
69
 
67
70
  let recordEventOwners = (owners, event: Spec.event) =>
68
71
  if actsOnOwned {
@@ -127,11 +130,11 @@ module Make = (
127
130
  // Before `decide`, second: an owner-marked aggregate refuses a caller who
128
131
  // does not own the stream.
129
132
  let refusal =
130
- repeated || !actsOnOwned
133
+ repeated || !(actsOnOwned || ownedById)
131
134
  ? None
132
135
  : Reventless.OwnerScope.decideActing(
133
136
  ~claim=command'.meta.callerClaim,
134
- ~recordedOwners=Some(owners),
137
+ ~recordedOwners=Some(owners->Reventless.Owner.streamOwners(~ownedById, ~id)),
135
138
  )->CommandTopic_Helpers.ownershipRefusal(~component=Spec.name, ~command=cmdVariant)
136
139
  switch refusal {
137
140
  | _ if repeated =>
@@ -34,6 +34,7 @@ function Make(Spec) {
34
34
  ]));
35
35
  let ownerFieldsByEventType = Owner$Reventless.fieldNamesByVariant(Spec.eventSchema);
36
36
  let actsOnOwned = Object.keys(ownerFieldsByEventType).length !== 0;
37
+ let ownedById = Owner$Reventless.isOwnedById(Spec.Id.schema);
37
38
  let recordEventOwners = (owners, event) => {
38
39
  if (!actsOnOwned) {
39
40
  return owners;
@@ -59,7 +60,7 @@ function Make(Spec) {
59
60
  let cmdName = LogFormat$ReventlessCore.bold(cmdVariant);
60
61
  Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, `deciding: id=` + id + ` seq=` + seq.toString() + ` cmd=` + cmdName));
61
62
  let repeated = Message$ReventlessCore.hasStableMsgId(command$p.meta) && causes.includes(command$p.meta.msgId);
62
- let refusal = repeated || !actsOnOwned ? undefined : CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(command$p.meta.callerClaim, owners), Spec.name, cmdVariant);
63
+ let refusal = repeated || !(actsOnOwned || ownedById) ? undefined : CommandTopic_Helpers$ReventlessCore.ownershipRefusal(OwnerScope$Reventless.decideActing(command$p.meta.callerClaim, Owner$Reventless.streamOwners(owners, ownedById, id)), Spec.name, cmdVariant);
63
64
  if (repeated) {
64
65
  Effect.runSync(EffectLogger$ReventlessCore.logInfo(comp, undefined, `repeat dropped: ` + cmdName + `(` + id + `) msgId=` + command$p.meta.msgId + ` already caused events`));
65
66
  return {
@@ -605,3 +605,205 @@ describe("acting on an owned thing — aggregate specifics:", () => {
605
605
  expect(snapshotReads.contents)->toBe(0)
606
606
  })
607
607
  })
608
+
609
+ // ─── An aggregate owned by its id ───────────────────────────────────────────
610
+
611
+ // Keyed by its holder's account id, and records no owner in any event: the id
612
+ // says whose it is, from the first command on.
613
+ module ProfileSpec = {
614
+ module Id = Reventless.Id.Owned(Reventless.Id.StringPure)
615
+ let name = "OwnedProfile"
616
+
617
+ @schema
618
+ type command =
619
+ | Create({name: string})
620
+ | Rename({newName: string})
621
+
622
+ @schema
623
+ type event =
624
+ | Created({name: string})
625
+ | Renamed({newName: string})
626
+
627
+ @schema
628
+ type error =
629
+ | AlreadyCreated
630
+ | NotFound
631
+
632
+ let moduleUrl: string = %raw(`import.meta.url`)
633
+ }
634
+
635
+ module ProfileDecision = {
636
+ module Spec = ProfileSpec
637
+
638
+ @schema
639
+ type state = Absent | Present({name: string})
640
+
641
+ let initialState = Absent
642
+
643
+ // Kept on: the id carries the owner, so a snapshot loses nothing.
644
+ let snapshot = Some({Reventless.Snapshot.interval: 1, stateSchema})
645
+
646
+ let moduleUrl = ProfileSpec.moduleUrl
647
+
648
+ let evolve = (_state, event: ProfileSpec.event) =>
649
+ switch event {
650
+ | Created({name}) => Present({name: name})
651
+ | Renamed({newName}) => Present({name: newName})
652
+ }
653
+
654
+ let decide = (state, command: ProfileSpec.command): result<
655
+ array<ProfileSpec.event>,
656
+ ProfileSpec.error,
657
+ > =>
658
+ switch (state, command) {
659
+ | (Absent, Create({name})) => Ok([ProfileSpec.Created({name: name})])
660
+ | (Absent, Rename(_)) => Error(NotFound)
661
+ | (Present(_), Create(_)) => Error(AlreadyCreated)
662
+ | (Present(_), Rename({newName})) => Ok([ProfileSpec.Renamed({newName: newName})])
663
+ }
664
+ }
665
+
666
+ let profileEvents: ref<array<Message.event'<string, ProfileSpec.event>>> = ref([])
667
+ let profileSnapshotReads = ref(0)
668
+
669
+ module ProfileOps = {
670
+ module Spec = ProfileSpec
671
+ module EventLog = {
672
+ module Spec = {
673
+ module Id = ProfileSpec.Id
674
+ let name = "OwnedProfileEventLog"
675
+ @schema
676
+ type event = ProfileSpec.event
677
+ }
678
+ type operations = {
679
+ append: (
680
+ int,
681
+ string,
682
+ array<Message.event'<string, ProfileSpec.event>>,
683
+ ) => promise<result<unit, OuterEventLog.appendError>>,
684
+ replay: string => promise<array<ProfileSpec.event>>,
685
+ replayStream: (string, ~fromSeq: int=?) => Stream.t<ProfileSpec.event, string, unit>,
686
+ replayEnvelopes: (
687
+ string,
688
+ ~fromSeq: int=?,
689
+ ) => Stream.t<Message.event'<string, ProfileSpec.event>, string, unit>,
690
+ appendStream: (
691
+ int,
692
+ string,
693
+ Stream.t<ProfileSpec.event, string, unit>,
694
+ ) => Effect.t<unit, string, unit>,
695
+ latestSnapshot: string => promise<result<option<OuterEventLog.snapshot>, string>>,
696
+ writeSnapshot: (string, OuterEventLog.snapshot) => promise<result<unit, string>>,
697
+ }
698
+ type component = Component.t<OuterEventLog.t, OuterEventLog.outputs, operations>
699
+ let make = (~name as _: string, ~owner as _=?, ~opts as _=?): component => Obj.magic(0)
700
+ }
701
+ let ofId = id => profileEvents.contents->Array.filter(e => e.id == id)->Array.map(e => e.event)
702
+ let eventLog: EventLog.operations = {
703
+ append: async (_seqNr, _id, newEvents) => {
704
+ profileEvents := profileEvents.contents->Array.concat(newEvents)
705
+ Ok()
706
+ },
707
+ replay: async id => ofId(id),
708
+ replayStream: (id, ~fromSeq as _=?) => ofId(id)->Stream.fromIterable,
709
+ replayEnvelopes: (id, ~fromSeq as _=?) =>
710
+ profileEvents.contents->Array.filter(e => e.id == id)->Stream.fromIterable,
711
+ appendStream: (_seqNr, _id, stream) => stream->Stream.runDrain,
712
+ latestSnapshot: async _ => {
713
+ profileSnapshotReads := profileSnapshotReads.contents + 1
714
+ Ok(None)
715
+ },
716
+ writeSnapshot: async (_, _) => Ok(),
717
+ }
718
+ }
719
+
720
+ module ProfileHandler = Aggregate_Callback.Make(ProfileSpec, ProfileDecision, ProfileOps)
721
+
722
+ let profileGenerate = generator(
723
+ ~serviceName=ProfileSpec.name,
724
+ ~commandSchema=ProfileSpec.commandSchema->S.castToUnknown,
725
+ ~componentKind=CommandGenerator_Callback.Aggregate,
726
+ )
727
+
728
+ let deliverProfile = async (cmd: Message.commandJson) => {
729
+ let item = {
730
+ ReventlessInfra.CommandTopic.command: cross(Inline, cmd)->Message.decodeCommand'(
731
+ ProfileSpec.Id.schema,
732
+ ProfileSpec.commandSchema,
733
+ ),
734
+ reference: cmd.meta.msgId,
735
+ }
736
+ let _ = await ProfileHandler.handleCommands(Stream.fromIterable([item]))->Effect.runPromise
737
+ cmd.meta.msgId
738
+ }
739
+
740
+ let profileCommand = (~command, ~id, ~identity, ~args=[]) =>
741
+ profileGenerate->generateOne(~command, ~args=Array.concat([("id", str(id))], args), ~identity)
742
+
743
+ describe("acting on an aggregate owned by its id:", () => {
744
+ let _ = beforeEach(() => {
745
+ profileEvents := []
746
+ profileSnapshotReads := 0
747
+ ProfileHandler.resetCache()
748
+ })
749
+
750
+ let create = async (~id, ~identity) =>
751
+ await deliverProfile(
752
+ await profileCommand(~command="Create", ~id, ~identity, ~args=[("name", str("Ann"))]),
753
+ )
754
+
755
+ // The creating command is checked too: there is no history to wait for.
756
+ testPromise("only the holder of the id, or an operator, may create it", async () => {
757
+ let mine = await create(~id="cust-A", ~identity=owner)
758
+ let theirs = await create(~id="cust-C", ~identity=stranger)
759
+ let ops = await create(~id="cust-D", ~identity=operator)
760
+ expect((outcomeOf(mine), outcomeOf(theirs), outcomeOf(ops)))->toEqual((
761
+ Accepted,
762
+ forbidden,
763
+ Accepted,
764
+ ))
765
+ })
766
+
767
+ let renameAs = async identity =>
768
+ await deliverProfile(
769
+ await profileCommand(
770
+ ~command="Rename",
771
+ ~id="cust-A",
772
+ ~identity,
773
+ ~args=[("newName", str("Renamed"))],
774
+ ),
775
+ )
776
+
777
+ let table: array<(string, Reventless.Identity.t, outcome)> = [
778
+ ("the holder of the id", owner, Accepted),
779
+ ("another owner", stranger, forbidden),
780
+ ("an operator, on the holder's behalf", operator, Accepted),
781
+ ("the platform's own IAM traffic", iam, Accepted),
782
+ ("an anonymous caller", Reventless.Identity.anonymous, forbidden),
783
+ ]
784
+ table->Array.forEach(((who, identity, expected)) =>
785
+ testPromise(
786
+ `${who}: ${expected == Accepted ? "accepted" : "refused before decide"}`,
787
+ async () => {
788
+ let _ = await create(~id="cust-A", ~identity=owner)
789
+ expect(outcomeOf(await renameAs(identity)))->toEqual(expected)
790
+ },
791
+ )
792
+ )
793
+
794
+ testPromise("an internal route, with no claim, is not checked", async () => {
795
+ let _ = await create(~id="cust-A", ~identity=owner)
796
+ let cmd = await profileCommand(
797
+ ~command="Rename",
798
+ ~id="cust-A",
799
+ ~identity=stranger,
800
+ ~args=[("newName", str("Renamed"))],
801
+ )
802
+ expect(outcomeOf(await deliverProfile(withoutClaim(cmd))))->toEqual(Accepted)
803
+ })
804
+
805
+ testPromise("an aggregate owned by its id keeps its snapshots", async () => {
806
+ let _ = await create(~id="cust-A", ~identity=owner)
807
+ expect(profileSnapshotReads.contents)->toBe(1)
808
+ })
809
+ })
@@ -979,6 +979,358 @@ globalThis.describe("acting on an owned thing — aggregate specifics:", () => {
979
979
  });
980
980
  });
981
981
 
982
+ let Id = Id$Reventless.Owned({
983
+ schema: Id$Reventless.StringPure.schema,
984
+ make: prim => prim,
985
+ makeFromString: prim => prim,
986
+ toString: prim => prim,
987
+ cmp: Id$Reventless.StringPure.cmp
988
+ });
989
+
990
+ let name$3 = "OwnedProfile";
991
+
992
+ let commandSchema$2 = Sury.union([
993
+ Sury.$schema(s => ({
994
+ TAG: "Create",
995
+ name: s.m(Sury.string)
996
+ })),
997
+ Sury.$schema(s => ({
998
+ TAG: "Rename",
999
+ newName: s.m(Sury.string)
1000
+ }))
1001
+ ]);
1002
+
1003
+ let eventSchema$2 = Sury.union([
1004
+ Sury.$schema(s => ({
1005
+ TAG: "Created",
1006
+ name: s.m(Sury.string)
1007
+ })),
1008
+ Sury.$schema(s => ({
1009
+ TAG: "Renamed",
1010
+ newName: s.m(Sury.string)
1011
+ }))
1012
+ ]);
1013
+
1014
+ let errorSchema$2 = Sury.union([
1015
+ Sury.literal("AlreadyCreated"),
1016
+ Sury.literal("NotFound")
1017
+ ]);
1018
+
1019
+ let moduleUrl$2 = import.meta.url;
1020
+
1021
+ function authorizationOf$2(param) {
1022
+ return "AllowAuthenticated";
1023
+ }
1024
+
1025
+ function commandTransition$2(param) {
1026
+ return "Undeclared";
1027
+ }
1028
+
1029
+ let traits$2 = [];
1030
+
1031
+ let ProfileSpec = {
1032
+ Id: Id,
1033
+ name: name$3,
1034
+ commandSchema: commandSchema$2,
1035
+ eventSchema: eventSchema$2,
1036
+ errorSchema: errorSchema$2,
1037
+ moduleUrl: moduleUrl$2,
1038
+ authorizationOf: authorizationOf$2,
1039
+ commandTransition: commandTransition$2,
1040
+ traits: traits$2
1041
+ };
1042
+
1043
+ let stateSchema$1 = Sury.union([
1044
+ Sury.literal("Absent"),
1045
+ Sury.$schema(s => ({
1046
+ TAG: "Present",
1047
+ name: s.m(Sury.string)
1048
+ }))
1049
+ ]);
1050
+
1051
+ let snapshot$1 = {
1052
+ interval: 1,
1053
+ stateSchema: stateSchema$1
1054
+ };
1055
+
1056
+ function evolve$2(_state, event) {
1057
+ if (event.TAG === "Created") {
1058
+ return {
1059
+ TAG: "Present",
1060
+ name: event.name
1061
+ };
1062
+ } else {
1063
+ return {
1064
+ TAG: "Present",
1065
+ name: event.newName
1066
+ };
1067
+ }
1068
+ }
1069
+
1070
+ function decide$2(state, command) {
1071
+ if (typeof state !== "object") {
1072
+ if (command.TAG === "Create") {
1073
+ return {
1074
+ TAG: "Ok",
1075
+ _0: [{
1076
+ TAG: "Created",
1077
+ name: command.name
1078
+ }]
1079
+ };
1080
+ } else {
1081
+ return {
1082
+ TAG: "Error",
1083
+ _0: "NotFound"
1084
+ };
1085
+ }
1086
+ } else if (command.TAG === "Create") {
1087
+ return {
1088
+ TAG: "Error",
1089
+ _0: "AlreadyCreated"
1090
+ };
1091
+ } else {
1092
+ return {
1093
+ TAG: "Ok",
1094
+ _0: [{
1095
+ TAG: "Renamed",
1096
+ newName: command.newName
1097
+ }]
1098
+ };
1099
+ }
1100
+ }
1101
+
1102
+ let ProfileDecision = {
1103
+ Spec: undefined,
1104
+ stateSchema: stateSchema$1,
1105
+ initialState: "Absent",
1106
+ snapshot: snapshot$1,
1107
+ moduleUrl: moduleUrl$2,
1108
+ evolve: evolve$2,
1109
+ decide: decide$2
1110
+ };
1111
+
1112
+ let profileEvents = {
1113
+ contents: []
1114
+ };
1115
+
1116
+ let profileSnapshotReads = {
1117
+ contents: 0
1118
+ };
1119
+
1120
+ let name$4 = "OwnedProfileEventLog";
1121
+
1122
+ let Spec$1 = {
1123
+ Id: undefined,
1124
+ name: name$4,
1125
+ eventSchema: eventSchema$2
1126
+ };
1127
+
1128
+ function make$1(param, param$1, param$2) {
1129
+ return 0;
1130
+ }
1131
+
1132
+ let EventLog$1 = {
1133
+ Spec: Spec$1,
1134
+ make: make$1
1135
+ };
1136
+
1137
+ function ofId$1(id) {
1138
+ return profileEvents.contents.filter(e => e.id === id).map(e => e.event);
1139
+ }
1140
+
1141
+ async function eventLog_append$1(_seqNr, _id, newEvents) {
1142
+ profileEvents.contents = profileEvents.contents.concat(newEvents);
1143
+ return {
1144
+ TAG: "Ok",
1145
+ _0: undefined
1146
+ };
1147
+ }
1148
+
1149
+ let eventLog_replay$1 = ofId$1;
1150
+
1151
+ function eventLog_replayStream$1(id, param) {
1152
+ return Stream.fromIterable(ofId$1(id));
1153
+ }
1154
+
1155
+ function eventLog_replayEnvelopes$1(id, param) {
1156
+ return Stream.fromIterable(profileEvents.contents.filter(e => e.id === id));
1157
+ }
1158
+
1159
+ function eventLog_appendStream$1(_seqNr, _id, stream) {
1160
+ return Stream.runDrain(stream);
1161
+ }
1162
+
1163
+ async function eventLog_latestSnapshot$1(param) {
1164
+ profileSnapshotReads.contents = profileSnapshotReads.contents + 1 | 0;
1165
+ return {
1166
+ TAG: "Ok",
1167
+ _0: undefined
1168
+ };
1169
+ }
1170
+
1171
+ async function eventLog_writeSnapshot$1(param, param$1) {
1172
+ return {
1173
+ TAG: "Ok",
1174
+ _0: undefined
1175
+ };
1176
+ }
1177
+
1178
+ let eventLog$1 = {
1179
+ append: eventLog_append$1,
1180
+ replay: eventLog_replay$1,
1181
+ replayStream: eventLog_replayStream$1,
1182
+ replayEnvelopes: eventLog_replayEnvelopes$1,
1183
+ appendStream: eventLog_appendStream$1,
1184
+ latestSnapshot: eventLog_latestSnapshot$1,
1185
+ writeSnapshot: eventLog_writeSnapshot$1
1186
+ };
1187
+
1188
+ let ProfileOps = {
1189
+ Spec: undefined,
1190
+ EventLog: EventLog$1,
1191
+ ofId: ofId$1,
1192
+ eventLog: eventLog$1
1193
+ };
1194
+
1195
+ let ProfileHandler = Aggregate_Callback$ReventlessCore.Make({
1196
+ Id: Id,
1197
+ name: name$3,
1198
+ eventSchema: eventSchema$2,
1199
+ errorSchema: errorSchema$2,
1200
+ commandSchema: commandSchema$2,
1201
+ moduleUrl: moduleUrl$2,
1202
+ authorizationOf: authorizationOf$2,
1203
+ commandTransition: commandTransition$2,
1204
+ traits: traits$2
1205
+ })({
1206
+ initialState: "Absent",
1207
+ evolve: evolve$2,
1208
+ decide: decide$2,
1209
+ snapshot: snapshot$1,
1210
+ moduleUrl: moduleUrl$2
1211
+ })({
1212
+ Spec: {
1213
+ Id: Id,
1214
+ name: name$3,
1215
+ eventSchema: eventSchema$2,
1216
+ errorSchema: errorSchema$2,
1217
+ commandSchema: commandSchema$2,
1218
+ moduleUrl: moduleUrl$2,
1219
+ authorizationOf: authorizationOf$2,
1220
+ commandTransition: commandTransition$2,
1221
+ traits: traits$2
1222
+ },
1223
+ EventLog: {
1224
+ Spec: {
1225
+ Id: Id,
1226
+ name: name$4,
1227
+ eventSchema: eventSchema$2
1228
+ },
1229
+ make: make$1
1230
+ },
1231
+ eventLog: eventLog$1
1232
+ });
1233
+
1234
+ let profileGenerate = generator(name$3, commandSchema$2, "Aggregate");
1235
+
1236
+ async function deliverProfile(cmd) {
1237
+ let item_command = Message$ReventlessCore.decodeCommand$p(CommandTopic_Helpers$ReventlessCore.encodeCommandJson(cmd), Id.schema, commandSchema$2);
1238
+ let item_reference = cmd.meta.msgId;
1239
+ let item = {
1240
+ command: item_command,
1241
+ reference: item_reference
1242
+ };
1243
+ await Effect.runPromise(ProfileHandler.handleCommands(Stream.fromIterable([item])));
1244
+ return cmd.meta.msgId;
1245
+ }
1246
+
1247
+ function profileCommand(command, id, identity, argsOpt) {
1248
+ let args = argsOpt !== undefined ? argsOpt : [];
1249
+ return generateOne(profileGenerate, command, [[
1250
+ "id",
1251
+ id
1252
+ ]].concat(args), identity);
1253
+ }
1254
+
1255
+ globalThis.describe("acting on an aggregate owned by its id:", () => {
1256
+ globalThis.beforeEach(() => {
1257
+ profileEvents.contents = [];
1258
+ profileSnapshotReads.contents = 0;
1259
+ ProfileHandler.resetCache();
1260
+ });
1261
+ let create = async (id, identity) => await deliverProfile(await profileCommand("Create", id, identity, [[
1262
+ "name",
1263
+ "Ann"
1264
+ ]]));
1265
+ globalThis.test("only the holder of the id, or an operator, may create it", async () => {
1266
+ let mine = await create("cust-A", owner);
1267
+ let theirs = await create("cust-C", stranger);
1268
+ let ops = await create("cust-D", operator);
1269
+ globalThis.expect([
1270
+ outcomeOf(mine),
1271
+ outcomeOf(theirs),
1272
+ outcomeOf(ops)
1273
+ ]).toEqual([
1274
+ "Accepted",
1275
+ forbidden,
1276
+ "Accepted"
1277
+ ]);
1278
+ });
1279
+ let renameAs = async identity => await deliverProfile(await profileCommand("Rename", "cust-A", identity, [[
1280
+ "newName",
1281
+ "Renamed"
1282
+ ]]));
1283
+ let table = [
1284
+ [
1285
+ "the holder of the id",
1286
+ owner,
1287
+ "Accepted"
1288
+ ],
1289
+ [
1290
+ "another owner",
1291
+ stranger,
1292
+ forbidden
1293
+ ],
1294
+ [
1295
+ "an operator, on the holder's behalf",
1296
+ operator,
1297
+ "Accepted"
1298
+ ],
1299
+ [
1300
+ "the platform's own IAM traffic",
1301
+ iam,
1302
+ "Accepted"
1303
+ ],
1304
+ [
1305
+ "an anonymous caller",
1306
+ Identity$Reventless.anonymous,
1307
+ forbidden
1308
+ ]
1309
+ ];
1310
+ table.forEach(param => {
1311
+ let expected = param[2];
1312
+ let identity = param[1];
1313
+ globalThis.test(param[0] + `: ` + (
1314
+ expected === "Accepted" ? "accepted" : "refused before decide"
1315
+ ), async () => {
1316
+ await create("cust-A", owner);
1317
+ globalThis.expect(outcomeOf(await renameAs(identity))).toEqual(expected);
1318
+ });
1319
+ });
1320
+ globalThis.test("an internal route, with no claim, is not checked", async () => {
1321
+ await create("cust-A", owner);
1322
+ let cmd = await profileCommand("Rename", "cust-A", stranger, [[
1323
+ "newName",
1324
+ "Renamed"
1325
+ ]]);
1326
+ globalThis.expect(outcomeOf(await deliverProfile(withoutClaim(cmd)))).toEqual("Accepted");
1327
+ });
1328
+ globalThis.test("an aggregate owned by its id keeps its snapshots", async () => {
1329
+ await create("cust-A", owner);
1330
+ globalThis.expect(profileSnapshotReads.contents).toBe(1);
1331
+ });
1332
+ });
1333
+
982
1334
  let OuterEventLog;
983
1335
 
984
1336
  export {
@@ -1019,5 +1371,14 @@ export {
1019
1371
  paths,
1020
1372
  forbidden,
1021
1373
  table,
1374
+ ProfileSpec,
1375
+ ProfileDecision,
1376
+ profileEvents,
1377
+ profileSnapshotReads,
1378
+ ProfileOps,
1379
+ ProfileHandler,
1380
+ profileGenerate,
1381
+ deliverProfile,
1382
+ profileCommand,
1022
1383
  }
1023
1384
  /* moduleUrl Not a pure module */