@reventlessdev/reventless-core 3.0.0-alpha.306 → 3.0.0-alpha.308

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 (78) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/package.json +5 -5
  3. package/src/Projection.res +4 -4
  4. package/src/Projection.res.mjs +11 -9
  5. package/src/ResourceAttribution.res +3 -3
  6. package/src/ResourceAttribution.res.mjs +1 -4
  7. package/src/adapter/Auth/Auth_ActiveRole.res +13 -18
  8. package/src/adapter/Auth/Auth_ActiveRole.res.mjs +4 -9
  9. package/src/adapter/Auth/Auth_UserId.res +24 -0
  10. package/src/adapter/Auth/Auth_UserId.res.mjs +23 -0
  11. package/src/adapter/EventLogProvisioning/EventLogProvisioning.res +1 -1
  12. package/src/adapter/Monitoring/Monitoring.res +5 -5
  13. package/src/adapter/Stash/Stash_Memory_Backend.res +35 -0
  14. package/src/adapter/Stash/Stash_Memory_Backend.res.mjs +44 -0
  15. package/src/adapter/Throttle/AnonymousLimiter.res +37 -0
  16. package/src/adapter/Throttle/AnonymousLimiter.res.mjs +43 -0
  17. package/src/admin/Platform_Admin.res +2 -2
  18. package/src/admin/Platform_Admin_Structure.res +0 -9
  19. package/src/admin/Platform_Admin_Structure.res.mjs +3 -12
  20. package/src/admin/Platform_BakedManifest.res +6 -6
  21. package/src/admin/Platform_BakedManifest.res.mjs +11 -26
  22. package/src/admin/Platform_PluginStructuresApi.res +36 -2
  23. package/src/admin/Platform_PluginStructuresApi.res.mjs +43 -1
  24. package/src/admin/Platform_SelfRegistration.res +54 -0
  25. package/src/admin/Platform_SelfRegistration.res.mjs +77 -0
  26. package/src/components/Api/GraphQL_SchemaInspector.res +3 -3
  27. package/src/components/Api/SuryToJsonSchema.res +3 -3
  28. package/src/components/Dcb/Dcb_Builder.res +6 -9
  29. package/src/components/Dcb/Dcb_Builder.res.mjs +0 -3
  30. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res +14 -1
  31. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res.mjs +3 -3
  32. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +73 -8
  33. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +60 -12
  34. package/src/plugin/component/Plugin.res +2 -0
  35. package/src/plugin/component/Plugin_Builder.res +9 -8
  36. package/src/plugin/component/Plugin_Builder.res.mjs +6 -10
  37. package/src/plugin/component/Plugin_Helpers.res +4 -4
  38. package/src/plugin/component/Plugin_Structure.res +179 -115
  39. package/src/plugin/component/Plugin_Structure.res.mjs +83 -17
  40. package/src/plugin/lifecycle/PluginsProjection.res +10 -6
  41. package/src/plugin/lifecycle/PluginsReadModelSpec.res +8 -8
  42. package/src/util/FTPHandler.res +3 -3
  43. package/src/util/ScheduleTime.res +5 -8
  44. package/src/util/ScheduleTime.res.mjs +0 -3
  45. package/src/util/Util_Promise.res +1 -1
  46. package/tests/AnonymousLimiterTest.res +66 -0
  47. package/tests/AnonymousLimiterTest.res.mjs +89 -0
  48. package/tests/Auth_UserIdTest.res +24 -0
  49. package/tests/Auth_UserIdTest.res.mjs +23 -0
  50. package/tests/ResourceAttributionTest.res +1 -1
  51. package/tests/ResourceAttributionTest.res.mjs +1 -4
  52. package/tests/Stash_Memory_BackendTest.res +63 -0
  53. package/tests/Stash_Memory_BackendTest.res.mjs +98 -0
  54. package/tests/admin/AdminApiSchemaDriftTest.res +72 -44
  55. package/tests/admin/AdminApiSchemaDriftTest.res.mjs +41 -3
  56. package/tests/admin/Platform_Admin_StructureTest.res +1 -1
  57. package/tests/admin/Platform_Admin_StructureTest.res.mjs +4 -22
  58. package/tests/admin/Platform_BakedManifestTest.res +11 -29
  59. package/tests/admin/Platform_BakedManifestTest.res.mjs +8 -39
  60. package/tests/admin/Platform_ComponentDefinitionsApiTest.res +24 -84
  61. package/tests/admin/Platform_ComponentDefinitionsApiTest.res.mjs +36 -169
  62. package/tests/admin/Platform_PluginStructuresApiTest.res +46 -31
  63. package/tests/admin/Platform_PluginStructuresApiTest.res.mjs +37 -34
  64. package/tests/admin/Platform_SelfRegistrationTest.res +70 -0
  65. package/tests/admin/Platform_SelfRegistrationTest.res.mjs +98 -0
  66. package/tests/admin/Platform_UIFragmentsApiTest.res +1 -4
  67. package/tests/admin/Platform_UIFragmentsApiTest.res.mjs +1 -4
  68. package/tests/api/GeocodingTest.res +1 -1
  69. package/tests/logger/LogFormatTest.res +0 -2
  70. package/tests/logger/LogFormatTest.res.mjs +0 -2
  71. package/tests/message/MessageTest.res +0 -13
  72. package/tests/message/MessageTest.res.mjs +2 -15
  73. package/tests/plugin/ManifestVisibilityTest.res.mjs +1 -1
  74. package/tests/plugin/PluginStructureAccessTest.res +6 -1
  75. package/tests/plugin/PluginStructureAccessTest.res.mjs +9 -5
  76. package/tests/plugin/PluginStructureTest.res +99 -23
  77. package/tests/plugin/PluginStructureTest.res.mjs +123 -79
  78. package/tests/plugin/pluginDefinitionRequiredScalars.txt +10 -0
@@ -112,7 +112,7 @@ let PsOrdersViewSlice = {
112
112
  let structure = Plugin_Structure$ReventlessCore.make("AccessPlugin", undefined, undefined, [
113
113
  PsGatedViewSlice,
114
114
  PsOrdersViewSlice
115
- ], [PsGatedCommandsSlice], undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined);
115
+ ], [PsGatedCommandsSlice], undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined);
116
116
 
117
117
  function commandNamed(name) {
118
118
  return Stdlib_Option.flatMap(structure.stateChangeSlices.flatMap(w => w.commands).find(c => c.name === name), c => c.requiredAccess);
@@ -156,7 +156,7 @@ globalThis.describe("requiredAccess derived from the authorization rule", () =>
156
156
  "Ops",
157
157
  "shop-ops"
158
158
  ]]);
159
- let renamed = Plugin_Structure$ReventlessCore.make("AccessPlugin", undefined, undefined, undefined, [PsGatedCommandsSlice], undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined);
159
+ let renamed = Plugin_Structure$ReventlessCore.make("AccessPlugin", undefined, undefined, undefined, [PsGatedCommandsSlice], undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined);
160
160
  Role$Reventless.clearGroups();
161
161
  let restock = renamed.stateChangeSlices.flatMap(w => w.commands).find(c => c.name === "Restock");
162
162
  globalThis.expect(Stdlib_Option.map(restock, c => [
@@ -216,6 +216,8 @@ function authorizationOf(name) {
216
216
  }
217
217
  }
218
218
 
219
+ let capabilityNeeds = [];
220
+
219
221
  let traits = [];
220
222
 
221
223
  let PsTwoRuleFeed = {
@@ -227,10 +229,11 @@ let PsTwoRuleFeed = {
227
229
  externalSystem: undefined,
228
230
  endpoint: undefined,
229
231
  authorizationOf: authorizationOf,
232
+ capabilityNeeds: capabilityNeeds,
230
233
  traits: traits
231
234
  };
232
235
 
233
- function translate(param) {
236
+ async function translate(param, param$1, param$2) {
234
237
  return {
235
238
  TAG: "Ok",
236
239
  _0: []
@@ -254,7 +257,8 @@ let PsTwoRuleFeedSlice_Spec = {
254
257
  targetName: targetName,
255
258
  externalSystem: undefined,
256
259
  authorizationOf: authorizationOf,
257
- endpoint: undefined
260
+ endpoint: undefined,
261
+ capabilityNeeds: capabilityNeeds
258
262
  };
259
263
 
260
264
  let PsTwoRuleFeedSlice = {
@@ -273,7 +277,7 @@ globalThis.describe("an inbound slice's roles", () => {
273
277
  ]);
274
278
  });
275
279
  globalThis.test("requiredRoles are the door's roles", () => {
276
- let inbound = Plugin_Structure$ReventlessCore.make("AccessPlugin", undefined, undefined, undefined, undefined, undefined, undefined, [PsTwoRuleFeedSlice], undefined, undefined, undefined, undefined, undefined).inboundTranslationSlices[0];
280
+ let inbound = Plugin_Structure$ReventlessCore.make("AccessPlugin", undefined, undefined, undefined, undefined, undefined, undefined, [PsTwoRuleFeedSlice], undefined, undefined, undefined, undefined, undefined, undefined, undefined).inboundTranslationSlices[0];
277
281
  let doorRoles = Stdlib_Option.map(door, rule => Authorization$Reventless.rolesOf(rule).map(r => r));
278
282
  globalThis.expect(Stdlib_Option.flatMap(inbound, s => s.requiredRoles)).toEqual(doorRoles);
279
283
  });
@@ -307,24 +307,18 @@ describe("lifecycle topology", () => {
307
307
  producedEventTypes: [],
308
308
  consumedEventTypes: [],
309
309
  linkedViews: ["Orders"],
310
- consistencyRead: None,
311
310
  events: [],
312
311
  errors: [],
313
- chapter: None,
314
312
  }
315
313
  let command = (~name, ~allowedStates=?, ~targetState=?, ()): Reventless.Plugin.commandDef => {
316
314
  name,
317
315
  schema: "",
318
316
  level: Instance,
319
- aggregateIdField: None,
320
317
  mutationField: "",
321
318
  references: [],
322
- allowedStates,
323
- targetState,
319
+ ?allowedStates,
320
+ ?targetState,
324
321
  allowedStatesSource: ?(allowedStates->Option.map(_ => "declared")),
325
- apiExposed: None,
326
- requiredAccess: None,
327
- ownerField: None,
328
322
  }
329
323
 
330
324
  testSync("names a state no command can reach", () => {
@@ -1996,13 +1990,13 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
1996
1990
  store: "TestPlugin.documents",
1997
1991
  component: "AttachInvoice",
1998
1992
  field: "documentUrl",
1999
- annotation: Some("documents"),
1993
+ annotation: "documents",
2000
1994
  },
2001
1995
  {
2002
1996
  store: "branding.logos",
2003
1997
  component: "AttachInvoice",
2004
1998
  field: "logoUrl",
2005
- annotation: Some("branding.logos"),
1999
+ annotation: "branding.logos",
2006
2000
  },
2007
2001
  ]
2008
2002
  expect(withStores.requiredStoreDeclarations)->toEqual(Some(expected))
@@ -2056,7 +2050,7 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
2056
2050
  () => {
2057
2051
  let withCapability = {
2058
2052
  ...structure,
2059
- requiredCapabilities: Some([
2053
+ requiredCapabilities: [
2060
2054
  (
2061
2055
  {
2062
2056
  capability: "Geocoding",
@@ -2064,8 +2058,10 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
2064
2058
  }: Reventless.Plugin.requiredCapabilityDeclaration
2065
2059
  ),
2066
2060
  {capability: "Geocoding", component: "GeocodeDropOff"},
2067
- ]),
2068
- traitDeclarations: None,
2061
+ ],
2062
+ traitDeclarations: ?None,
2063
+ admission: ?None,
2064
+ admissionDoors: ?None,
2069
2065
  }
2070
2066
  let entries = Reventless.CapabilityManifest.fromStructure(withCapability).capabilities
2071
2067
 
@@ -2092,8 +2088,10 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
2092
2088
  expect(
2093
2089
  Reventless.CapabilityManifest.fromStructure({
2094
2090
  ...structure,
2095
- requiredCapabilities: Some([{capability: "Telepathy", component: "Guess"}]),
2096
- traitDeclarations: None,
2091
+ requiredCapabilities: [{capability: "Telepathy", component: "Guess"}],
2092
+ traitDeclarations: ?None,
2093
+ admission: ?None,
2094
+ admissionDoors: ?None,
2097
2095
  }).capabilities,
2098
2096
  )->toEqual([]),
2099
2097
  )
@@ -2184,25 +2182,25 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
2184
2182
  store: "TestPlugin.categoryImages",
2185
2183
  component: "UploadImages",
2186
2184
  field: "categoryImage",
2187
- annotation: Some("categoryImages"),
2185
+ annotation: "categoryImages",
2188
2186
  },
2189
2187
  {
2190
2188
  store: "TestPlugin.datasheets",
2191
2189
  component: "UploadImages",
2192
2190
  field: "datasheets",
2193
- annotation: Some("datasheets"),
2191
+ annotation: "datasheets",
2194
2192
  },
2195
2193
  {
2196
2194
  store: "TestPlugin.productImages",
2197
2195
  component: "UploadImages",
2198
2196
  field: "productImage",
2199
- annotation: Some("productImages"),
2197
+ annotation: "productImages",
2200
2198
  },
2201
2199
  {
2202
2200
  store: "branding.logos",
2203
2201
  component: "UploadImages",
2204
2202
  field: "logo",
2205
- annotation: Some("branding.logos"),
2203
+ annotation: "branding.logos",
2206
2204
  },
2207
2205
  ]
2208
2206
  expect(withUploads.requiredStoreDeclarations)->toEqual(Some(expected))
@@ -2344,7 +2342,7 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
2344
2342
  store: "TestPlugin.avatars",
2345
2343
  component: "UploadAvatar",
2346
2344
  field: "avatarUrl",
2347
- annotation: Some("avatars"),
2345
+ annotation: "avatars",
2348
2346
  },
2349
2347
  ]
2350
2348
  expect(withOptional.requiredStoreDeclarations)->toEqual(Some(expected))
@@ -2356,7 +2354,7 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
2356
2354
  () => {
2357
2355
  let cmd = (withOptional.stateChangeSlices->Array.getUnsafe(0)).commands->Array.getUnsafe(0)
2358
2356
  let expected: array<Reventless.Plugin.fieldReference> = [
2359
- {fieldName: "referredBy", entity: "Customers", plugin: None},
2357
+ {fieldName: "referredBy", entity: "Customers"},
2360
2358
  ]
2361
2359
  expect(cmd.references)->toEqual(expected)
2362
2360
  },
@@ -2523,7 +2521,6 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
2523
2521
  Some({
2524
2522
  Reventless.Plugin.fieldName: "lineItems[].productId",
2525
2523
  entity: "AvailableProducts",
2526
- plugin: None,
2527
2524
  }),
2528
2525
  )
2529
2526
  },
@@ -2547,7 +2544,7 @@ describe("Plugin_Structure.make — Phase 2 graph fields", () => {
2547
2544
  () => {
2548
2545
  let cmd = slice.commands->Array.getUnsafe(0)
2549
2546
  expect(cmd.references->Array.find(({fieldName}) => fieldName == "warehouseIds"))->toEqual(
2550
- Some({Reventless.Plugin.fieldName: "warehouseIds", entity: "Warehouses", plugin: None}),
2547
+ Some({Reventless.Plugin.fieldName: "warehouseIds", entity: "Warehouses"}),
2551
2548
  )
2552
2549
  },
2553
2550
  )
@@ -2791,3 +2788,82 @@ describe("duplicate DCB command names", () => {
2791
2788
  )->toBe(true)
2792
2789
  )
2793
2790
  })
2791
+
2792
+ describe("a slice that reads no earlier event about its own identity creates its row", () => {
2793
+ // Events built as a spec's are: a TAG, and fields tagged with the identity they
2794
+ // file the event under.
2795
+ let event = (name, fields: array<(string, bool)>) =>
2796
+ S.object(s => {
2797
+ s.tag("TAG", name)
2798
+ fields->Array.forEach(
2799
+ ((field, tagged)) => s.field(field, tagged ? Reventless.DcbTag.string : S.string)->ignore,
2800
+ )
2801
+ })->S.castToUnknown
2802
+ let union = (variants: array<S.t<unknown>>) => S.union(variants)->S.castToUnknown
2803
+ let commissioned = event("ChargerCommissioned", [("chargerId", true), ("siteId", true)])
2804
+ let retired = event("ChargerRetired", [("chargerId", true)])
2805
+ let siteAdded = event("SiteAdded", [("siteId", true)])
2806
+
2807
+ testSync("by the events it reads besides its own, and whose they are", () => {
2808
+ // Commission: reads its own event only, or a site's besides: creates the charger.
2809
+ let commission = Plugin_Structure.createsBy(
2810
+ ~produced=union([commissioned]),
2811
+ ~consumed=union([commissioned]),
2812
+ )
2813
+ let commissionAtSite = Plugin_Structure.createsBy(
2814
+ ~produced=union([commissioned]),
2815
+ ~consumed=union([commissioned, siteAdded]),
2816
+ )
2817
+ // Retire: reads that the charger was commissioned, which is about the charger.
2818
+ let retire = Plugin_Structure.createsBy(
2819
+ ~produced=union([retired]),
2820
+ ~consumed=union([retired, commissioned]),
2821
+ )
2822
+ // A decision that reads none of its own events: its name decides.
2823
+ let readsOthers = Plugin_Structure.createsBy(
2824
+ ~produced=union([commissioned]),
2825
+ ~consumed=union([siteAdded]),
2826
+ )
2827
+ // Another event whose identity cannot be told (no fields) may be the row's own.
2828
+ let untold = Plugin_Structure.createsBy(
2829
+ ~produced=union([commissioned]),
2830
+ ~consumed=union([commissioned, event("Placed", [])]),
2831
+ )
2832
+ expect((
2833
+ commission("chargerId"),
2834
+ commissionAtSite("chargerId"),
2835
+ retire("chargerId"),
2836
+ readsOthers("chargerId"),
2837
+ untold("chargerId"),
2838
+ ))->toEqual((true, true, false, false, false))
2839
+ })
2840
+
2841
+ // `ShipOrder` carries a tagged `orderId` and no create stem: Instance-level by
2842
+ // its name, Collection-level once its slice creates the order.
2843
+ testSync("as a create-stem name does, keeping its id field", () => {
2844
+ let properties = switch PsShipOrder.commandSchema->S.castToUnknown {
2845
+ | AnyOf({anyOf}) =>
2846
+ anyOf->Array.findMap(
2847
+ v =>
2848
+ switch v {
2849
+ | Object({properties}) if properties->Dict.get("orderId")->Option.isSome =>
2850
+ Some(properties)
2851
+ | _ => None
2852
+ },
2853
+ )
2854
+ | _ => None
2855
+ }->Option.getOrThrow
2856
+ let level = createsFor =>
2857
+ Plugin_Structure.commandLevelAndId(
2858
+ ~isAggregate=false,
2859
+ ~createsFor,
2860
+ ~variantName="ShipOrder",
2861
+ properties,
2862
+ )
2863
+ expect((level(_ => false), level(key => key == "orderId"), level(_ => false)))->toEqual((
2864
+ (Reventless.Plugin.Instance, Some("orderId")),
2865
+ (Reventless.Plugin.Collection, Some("orderId")),
2866
+ (Reventless.Plugin.Instance, Some("orderId")),
2867
+ ))
2868
+ })
2869
+ })