@reventlessdev/reventless-core 3.0.0-alpha.215 → 3.0.0-alpha.217

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/package.json +6 -6
  3. package/src/ResourceAttribution.res +60 -4
  4. package/src/ResourceAttribution.res.mjs +26 -0
  5. package/src/adapter/QueryInterception/QueryInterception.res +74 -0
  6. package/src/adapter/QueryInterception/QueryInterception.res.mjs +26 -0
  7. package/src/adapter/ResourceAttribution_Deploytime.res +43 -0
  8. package/src/adapter/ResourceAttribution_Deploytime.res.mjs +20 -0
  9. package/src/admin/Platform_Admin_Structure.res +4 -0
  10. package/src/admin/Platform_Admin_Structure.res.mjs +5 -0
  11. package/src/admin/Platform_ComponentDefinitionsApi.res +16 -1
  12. package/src/admin/Platform_ComponentDefinitionsApi.res.mjs +24 -1
  13. package/src/components/Aggregate/Aggregate_Callback.res +14 -2
  14. package/src/components/Aggregate/Aggregate_Callback.res.mjs +3 -3
  15. package/src/components/Builder_Helpers.res +21 -3
  16. package/src/components/Builder_Helpers.res.mjs +4 -3
  17. package/src/components/CommandTopic/CommandTopic.res.mjs +12 -0
  18. package/src/components/CommandTopic/CommandTopic_Helpers.res +88 -2
  19. package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +48 -2
  20. package/src/components/ExtensionPoint/ExtensionPoint_Builder.res +4 -1
  21. package/src/components/ExtensionPoint/ExtensionPoint_Builder.res.mjs +2 -1
  22. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +13 -1
  23. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +4 -4
  24. package/src/plugin/component/Plugin_Builder.res +6 -1
  25. package/src/plugin/component/Plugin_Builder.res.mjs +4 -2
  26. package/src/plugin/component/Plugin_Helpers.res +7 -2
  27. package/src/plugin/component/Plugin_Helpers.res.mjs +4 -3
  28. package/src/plugin/component/Plugin_Structure.res +66 -51
  29. package/src/plugin/component/Plugin_Structure.res.mjs +61 -46
  30. package/tests/ResourceAttributionTest.res +115 -0
  31. package/tests/ResourceAttributionTest.res.mjs +106 -0
  32. package/tests/adapter/QueryInterceptionTest.res +55 -0
  33. package/tests/adapter/QueryInterceptionTest.res.mjs +49 -0
  34. package/tests/admin/Platform_ComponentDefinitionsApiTest.res +21 -0
  35. package/tests/admin/Platform_ComponentDefinitionsApiTest.res.mjs +21 -0
  36. package/tests/commandtopic/CommandOutcomeHookTest.res +258 -0
  37. package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +372 -0
  38. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res +9 -1
  39. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +3 -3
  40. package/tests/message/MessageTest.res +1 -0
  41. package/tests/message/MessageTest.res.mjs +1 -0
  42. package/tests/plugin/PluginStructureTest.res +27 -0
  43. package/tests/plugin/PluginStructureTest.res.mjs +27 -0
  44. package/tests/plugin/StateChangeSlice/PsShipOrder.res +3 -1
  45. package/tests/plugin/StateChangeSlice/PsShipOrder.res.mjs +7 -1
  46. package/tests/plugin/pluginDefinitionRequiredScalars.txt +8 -0
@@ -245,6 +245,33 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
245
245
  let shipOrder = structure.stateChangeSlices->Array.getUnsafe(1)
246
246
  expect(shipOrder.producedEventTypes)->toEqual(["TestPlugin.OrderShipped"])
247
247
  })
248
+
249
+ // A slice's declared errors are the third family of its contract, beside the
250
+ // commands it accepts and the events it emits — what a caller has to handle
251
+ // when a decision is refused.
252
+ testSync("PlaceOrder: the single payload-less error variant is surfaced", () => {
253
+ let placeOrder = structure.stateChangeSlices->Array.getUnsafe(0)
254
+ expect(placeOrder.errors->Array.map(e => e.name))->toEqual(["AlreadyPlaced"])
255
+ })
256
+
257
+ testSync("ShipOrder: both error variants surface, in declaration order", () => {
258
+ let shipOrder = structure.stateChangeSlices->Array.getUnsafe(1)
259
+ expect(shipOrder.errors->Array.map(e => e.name))->toEqual(["OrderNotFound", "NotShippable"])
260
+ })
261
+
262
+ testSync("ShipOrder: a payload-carrying error carries its field schema", () => {
263
+ let shipOrder = structure.stateChangeSlices->Array.getUnsafe(1)
264
+ let notShippable =
265
+ shipOrder.errors->Array.find(e => e.name == "NotShippable")->Option.getOrThrow
266
+ expect(notShippable.schema->String.includes("\"reason\""))->toBe(true)
267
+ })
268
+
269
+ testSync("ShipOrder: a payload-less error carries no fields and no references", () => {
270
+ let shipOrder = structure.stateChangeSlices->Array.getUnsafe(1)
271
+ let notFound = shipOrder.errors->Array.find(e => e.name == "OrderNotFound")->Option.getOrThrow
272
+ expect((notFound.schema->String.includes("\"reason\""), notFound.references->Array.length))
273
+ ->toEqual((false, 0))
274
+ })
248
275
  })
249
276
 
250
277
  describe("stateViewSlices", () => {
@@ -398,6 +398,33 @@ globalThis.describe("Plugin_Structure.make — Phase 2 graph fields", () => {
398
398
  let shipOrder = structure.stateChangeSlices[1];
399
399
  globalThis.expect(shipOrder.producedEventTypes).toEqual(["TestPlugin.OrderShipped"]);
400
400
  });
401
+ globalThis.test("PlaceOrder: the single payload-less error variant is surfaced", () => {
402
+ let placeOrder = structure.stateChangeSlices[0];
403
+ globalThis.expect(placeOrder.errors.map(e => e.name)).toEqual(["AlreadyPlaced"]);
404
+ });
405
+ globalThis.test("ShipOrder: both error variants surface, in declaration order", () => {
406
+ let shipOrder = structure.stateChangeSlices[1];
407
+ globalThis.expect(shipOrder.errors.map(e => e.name)).toEqual([
408
+ "OrderNotFound",
409
+ "NotShippable"
410
+ ]);
411
+ });
412
+ globalThis.test("ShipOrder: a payload-carrying error carries its field schema", () => {
413
+ let shipOrder = structure.stateChangeSlices[1];
414
+ let notShippable = Stdlib_Option.getOrThrow(shipOrder.errors.find(e => e.name === "NotShippable"), undefined);
415
+ globalThis.expect(notShippable.schema.includes("\"reason\"")).toBe(true);
416
+ });
417
+ globalThis.test("ShipOrder: a payload-less error carries no fields and no references", () => {
418
+ let shipOrder = structure.stateChangeSlices[1];
419
+ let notFound = Stdlib_Option.getOrThrow(shipOrder.errors.find(e => e.name === "OrderNotFound"), undefined);
420
+ globalThis.expect([
421
+ notFound.schema.includes("\"reason\""),
422
+ notFound.references.length
423
+ ]).toEqual([
424
+ false,
425
+ 0
426
+ ]);
427
+ });
401
428
  });
402
429
  globalThis.describe("stateViewSlices", () => {
403
430
  globalThis.test("produces four SVS entries in declaration order", () => {
@@ -21,8 +21,10 @@ let evolve = (_state, _event) => true
21
21
  @schema
22
22
  type command = @targetState("Shipped") ShipOrder({orderId: string}) | @noApi CancelShipment
23
23
 
24
+ // Two variants, one payload-less and one carrying a field — the same two branches
25
+ // `events` exercises, so the structure's `errors` list is pinned on both.
24
26
  @schema
25
- type error = OrderNotFound
27
+ type error = OrderNotFound | NotShippable({reason: string})
26
28
 
27
29
  // ShipmentVoided is payload-less — excluded from producedEventTypes (DCB filter),
28
30
  // but still surfaced in `events` (toEventDef's payload-less branch).
@@ -22,7 +22,13 @@ let commandSchema = S.union([
22
22
  S.literal("CancelShipment")
23
23
  ]);
24
24
 
25
- let errorSchema = S.literal("OrderNotFound");
25
+ let errorSchema = S.union([
26
+ S.literal("OrderNotFound"),
27
+ S.schema(s => ({
28
+ TAG: "NotShippable",
29
+ reason: s.m(S.string)
30
+ }))
31
+ ]);
26
32
 
27
33
  let eventSchema = S.union([
28
34
  S.schema(s => ({
@@ -43,6 +43,10 @@
43
43
  .structure.aggregates[].commands[].references[].fieldName: string
44
44
  .structure.aggregates[].commands[].schema: string
45
45
  .structure.aggregates[].consumedEventTypes[]: string
46
+ .structure.aggregates[].errors[].name: string
47
+ .structure.aggregates[].errors[].references[].entity: string
48
+ .structure.aggregates[].errors[].references[].fieldName: string
49
+ .structure.aggregates[].errors[].schema: string
46
50
  .structure.aggregates[].events[].name: string
47
51
  .structure.aggregates[].events[].references[].entity: string
48
52
  .structure.aggregates[].events[].references[].fieldName: string
@@ -86,6 +90,10 @@
86
90
  .structure.stateChangeSlices[].commands[].references[].fieldName: string
87
91
  .structure.stateChangeSlices[].commands[].schema: string
88
92
  .structure.stateChangeSlices[].consumedEventTypes[]: string
93
+ .structure.stateChangeSlices[].errors[].name: string
94
+ .structure.stateChangeSlices[].errors[].references[].entity: string
95
+ .structure.stateChangeSlices[].errors[].references[].fieldName: string
96
+ .structure.stateChangeSlices[].errors[].schema: string
89
97
  .structure.stateChangeSlices[].events[].name: string
90
98
  .structure.stateChangeSlices[].events[].references[].entity: string
91
99
  .structure.stateChangeSlices[].events[].references[].fieldName: string