@reventlessdev/reventless-core 3.0.0-alpha.239 → 3.0.0-alpha.240

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 (170) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/package.json +9 -9
  3. package/src/Message.res +11 -11
  4. package/src/Message.res.mjs +15 -14
  5. package/src/Projection.res +2 -2
  6. package/src/Projection.res.mjs +5 -4
  7. package/src/adapter/Monitoring/Monitoring.res +24 -2
  8. package/src/adapter/Monitoring/Monitoring.res.mjs +3 -3
  9. package/src/admin/Platform_AdminApi.res.mjs +3 -3
  10. package/src/admin/Platform_Admin_Structure.res +33 -113
  11. package/src/admin/Platform_Admin_Structure.res.mjs +8 -139
  12. package/src/admin/UiFragmentRegistry/StateChangeSlice/UiFragmentRegistry.res.mjs +12 -12
  13. package/src/admin/UiFragmentRegistry/StateViewSlice/UiFragments.res.mjs +14 -14
  14. package/src/components/Aggregate/Aggregate_Callback.res +2 -2
  15. package/src/components/Aggregate/Aggregate_Callback.res.mjs +4 -4
  16. package/src/components/Api/ApiAllowedStatesHelpers.res.mjs +3 -3
  17. package/src/components/Api/ApiNoApiHelpers.res.mjs +5 -5
  18. package/src/components/Api/ApiTargetStateHelpers.res.mjs +3 -3
  19. package/src/components/Api/GraphQL_FragmentGenerator.res +18 -12
  20. package/src/components/Api/GraphQL_FragmentGenerator.res.mjs +7 -13
  21. package/src/components/Api/GraphQL_SchemaInspector.res +1 -1
  22. package/src/components/Api/GraphQL_SchemaInspector.res.mjs +1 -1
  23. package/src/components/Api/MCP_SchemaGenerator.res +1 -1
  24. package/src/components/Api/MCP_SchemaGenerator.res.mjs +1 -1
  25. package/src/components/Api/SchemaType.res +6 -10
  26. package/src/components/Api/SchemaType.res.mjs +4 -4
  27. package/src/components/Api/StorageRefFields.res +1 -1
  28. package/src/components/Api/StorageRefFields.res.mjs +1 -1
  29. package/src/components/Api/SuryToJsonSchema.res +11 -0
  30. package/src/components/Api/SuryToJsonSchema.res.mjs +2 -1
  31. package/src/components/AutomationSlice/AutomationSlice_Callback.res +3 -4
  32. package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +22 -23
  33. package/src/components/CommandTopic/CommandTopic_Callback.res +1 -2
  34. package/src/components/CommandTopic/CommandTopic_Callback.res.mjs +3 -4
  35. package/src/components/CommandTopic/CommandTopic_Helpers.res +1 -1
  36. package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +3 -3
  37. package/src/components/Counter/Counter.res.mjs +2 -2
  38. package/src/components/Counter/Counter_Callback.res.mjs +4 -4
  39. package/src/components/Counter/Counter_Operations.res.mjs +4 -4
  40. package/src/components/Dcb/Dcb_Builder.res +1 -1
  41. package/src/components/Dcb/Dcb_Builder.res.mjs +8 -6
  42. package/src/components/DcbEventLog/DcbEventLog_Builder.res.mjs +4 -3
  43. package/src/components/EventCollector/EventCollector_Builder.res +1 -1
  44. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +1 -2
  45. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +11 -12
  46. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +3 -4
  47. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +24 -25
  48. package/src/components/SideEffectHandler/SideEffectHandler_Callback.res +1 -1
  49. package/src/components/SideEffectHandler/SideEffectHandler_Callback.res.mjs +3 -3
  50. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +2 -2
  51. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +4 -4
  52. package/src/components/StateViewSlice/StateViewSlice_Builder.res +1 -1
  53. package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +3 -3
  54. package/src/plugin/api/PluginBaseFragment.res +12 -29
  55. package/src/plugin/api/PluginBaseFragment.res.mjs +3 -22
  56. package/src/plugin/component/Capability_Inference.res +118 -1
  57. package/src/plugin/component/Capability_Inference.res.mjs +128 -1
  58. package/src/plugin/component/Plugin_Builder.res +2 -2
  59. package/src/plugin/component/Plugin_Builder.res.mjs +2 -1
  60. package/src/plugin/component/Plugin_Helpers.res +11 -11
  61. package/src/plugin/component/Plugin_Helpers.res.mjs +11 -10
  62. package/src/plugin/component/Plugin_Structure.res +349 -274
  63. package/src/plugin/component/Plugin_Structure.res.mjs +212 -175
  64. package/src/plugin/component/Plugin_SubscriptionSchema.res +1 -1
  65. package/src/plugin/component/Plugin_SubscriptionSchema.res.mjs +1 -1
  66. package/src/plugin/component/SchemaWalker.res +11 -11
  67. package/src/plugin/component/SchemaWalker.res.mjs +8 -9
  68. package/src/plugin/connect/PluginExtensionPoint_Plugin.res.mjs +15 -15
  69. package/src/plugin/lifecycle/PluginBehavior.res.mjs +55 -55
  70. package/src/plugin/lifecycle/PluginSpec.res +22 -7
  71. package/src/plugin/lifecycle/PluginSpec.res.mjs +91 -36
  72. package/src/plugin/lifecycle/PluginsReadModelSpec.res +36 -9
  73. package/src/plugin/lifecycle/PluginsReadModelSpec.res.mjs +33 -22
  74. package/src/util/Interstack.res +3 -3
  75. package/src/util/LogFormat.res +1 -2
  76. package/src/util/LogFormat.res.mjs +2 -2
  77. package/tests/IdentityTest.res +6 -7
  78. package/tests/IdentityTest.res.mjs +7 -9
  79. package/tests/adapter/MonitoringTest.res +30 -3
  80. package/tests/adapter/MonitoringTest.res.mjs +31 -12
  81. package/tests/adapter/RuntimeExtensionHookReachTest.res +0 -1
  82. package/tests/adapter/RuntimeExtensionHookReachTest.res.mjs +5 -7
  83. package/tests/admin/Platform_Admin_StructureTest.res +254 -0
  84. package/tests/admin/Platform_Admin_StructureTest.res.mjs +219 -0
  85. package/tests/aggregate/AggregateCacheTest.res +0 -1
  86. package/tests/aggregate/AggregateCacheTest.res.mjs +13 -15
  87. package/tests/aggregate/AggregateConflictTest.res +0 -1
  88. package/tests/aggregate/AggregateConflictTest.res.mjs +7 -9
  89. package/tests/aggregate/AggregateFixtures.res +0 -1
  90. package/tests/aggregate/AggregateFixtures.res.mjs +19 -21
  91. package/tests/aggregate/AggregateSnapshotTest.res +1 -2
  92. package/tests/aggregate/AggregateSnapshotTest.res.mjs +15 -16
  93. package/tests/api/ApiNoApiTest.res.mjs +17 -9
  94. package/tests/api/GraphQL_FragmentGeneratorTest.res +62 -1
  95. package/tests/api/GraphQL_FragmentGeneratorTest.res.mjs +102 -58
  96. package/tests/api/PsInternalFieldsReadModel.res +21 -0
  97. package/tests/api/PsInternalFieldsReadModel.res.mjs +74 -0
  98. package/tests/api/StorageRefFieldsTest.res.mjs +13 -13
  99. package/tests/api/SuryToJsonSchemaTest.res +43 -0
  100. package/tests/api/SuryToJsonSchemaTest.res.mjs +352 -849
  101. package/tests/commandgenerator/CommandGeneratorFixtures.res +0 -1
  102. package/tests/commandgenerator/CommandGeneratorFixtures.res.mjs +19 -21
  103. package/tests/commandgenerator/OwnerStampingTest.res +0 -1
  104. package/tests/commandgenerator/OwnerStampingTest.res.mjs +9 -11
  105. package/tests/commandtopic/CommandTopicCallbackFixtures.res +0 -1
  106. package/tests/commandtopic/CommandTopicCallbackFixtures.res.mjs +7 -9
  107. package/tests/counter/CounterFixtures.res +0 -1
  108. package/tests/counter/CounterFixtures.res.mjs +1 -4
  109. package/tests/dcb/DcbDecodeTest.res.mjs +24 -24
  110. package/tests/dcb/DcbEventLogOperationsTest.res +2 -2
  111. package/tests/dcb/DcbEventLogOperationsTest.res.mjs +3 -3
  112. package/tests/dcb/DcbEventLogSchemaTest.res.mjs +7 -7
  113. package/tests/dcb/DcbFixtures.res +0 -1
  114. package/tests/dcb/DcbFixtures.res.mjs +87 -89
  115. package/tests/dcb/DcbTagTest.res.mjs +6 -6
  116. package/tests/dcb/DcbValidationTest.res.mjs +52 -52
  117. package/tests/eventlog/EventLogFixtures.res +0 -1
  118. package/tests/eventlog/EventLogFixtures.res.mjs +7 -9
  119. package/tests/eventmapper/EventMapperFixtures.res +0 -1
  120. package/tests/eventmapper/EventMapperFixtures.res.mjs +24 -26
  121. package/tests/eventtopic/EventTopicFixtures.res +0 -1
  122. package/tests/eventtopic/EventTopicFixtures.res.mjs +7 -9
  123. package/tests/extensionpoint/ExtensionPointFixtures.res +0 -1
  124. package/tests/extensionpoint/ExtensionPointFixtures.res.mjs +10 -12
  125. package/tests/extensionpoint/ExtensionPointOperationsTest.res +1 -2
  126. package/tests/extensionpoint/ExtensionPointOperationsTest.res.mjs +9 -10
  127. package/tests/logger/LogFormatTest.res +3 -2
  128. package/tests/logger/LogFormatTest.res.mjs +7 -9
  129. package/tests/message/MessageTest.res +2 -2
  130. package/tests/message/MessageTest.res.mjs +8 -7
  131. package/tests/message/MetaEnvelopeTest.res +5 -5
  132. package/tests/message/MetaEnvelopeTest.res.mjs +12 -11
  133. package/tests/plugin/ManifestVisibilityTest.res.mjs +7 -7
  134. package/tests/plugin/PluginDefinitionScalars.res +5 -3
  135. package/tests/plugin/PluginDefinitionScalars.res.mjs +2 -2
  136. package/tests/plugin/PluginLifecycleCorpusTest.res +4 -3
  137. package/tests/plugin/PluginLifecycleCorpusTest.res.mjs +3 -6
  138. package/tests/plugin/PluginSpecExperiment.res +0 -1
  139. package/tests/plugin/PluginSpecExperiment.res.mjs +12 -14
  140. package/tests/plugin/PluginStructureTest.res +188 -1
  141. package/tests/plugin/PluginStructureTest.res.mjs +293 -102
  142. package/tests/plugin/Plugin_EventQuerySchemaTest.res.mjs +3 -3
  143. package/tests/plugin/SchemaWalkerTest.res +0 -1
  144. package/tests/plugin/SchemaWalkerTest.res.mjs +17 -19
  145. package/tests/plugin/StateChangeSlice/PsAttachInvoice.res.mjs +5 -5
  146. package/tests/plugin/StateChangeSlice/PsChangePhoto.res.mjs +8 -8
  147. package/tests/plugin/StateChangeSlice/PsDispatchShipment.res.mjs +5 -5
  148. package/tests/plugin/StateChangeSlice/PsGatedCommands.res.mjs +9 -9
  149. package/tests/plugin/StateChangeSlice/PsPlaceOrder.res.mjs +5 -5
  150. package/tests/plugin/StateChangeSlice/PsReserveStock.res.mjs +8 -8
  151. package/tests/plugin/StateChangeSlice/PsShipOrder.res.mjs +15 -15
  152. package/tests/plugin/StateChangeSlice/PsTypoStore.res +31 -0
  153. package/tests/plugin/StateChangeSlice/PsTypoStore.res.mjs +62 -0
  154. package/tests/plugin/StateChangeSlice/PsUploadAvatar.res.mjs +8 -8
  155. package/tests/plugin/StateChangeSlice/PsUploadImages.res +40 -0
  156. package/tests/plugin/StateChangeSlice/PsUploadImages.res.mjs +66 -0
  157. package/tests/plugin/StateViewSlice/PsAnnotatedView.res.mjs +13 -12
  158. package/tests/plugin/StateViewSlice/PsAvailableProductsView.res.mjs +8 -8
  159. package/tests/plugin/StateViewSlice/PsCategoriesView.res.mjs +6 -6
  160. package/tests/plugin/StateViewSlice/PsCustomersView.res.mjs +10 -10
  161. package/tests/plugin/StateViewSlice/PsGatedView.res.mjs +6 -6
  162. package/tests/plugin/StateViewSlice/PsOrdersView.res.mjs +9 -9
  163. package/tests/plugin/StateViewSlice/PsShipmentsView.res.mjs +11 -10
  164. package/tests/plugin/pluginDefinitionRequiredScalars.txt +15 -0
  165. package/tests/querydb/QueryDbFixtures.res +0 -1
  166. package/tests/querydb/QueryDbFixtures.res.mjs +5 -7
  167. package/tests/sideeffecthandler/SideEffectHandlerFixtures.res +0 -1
  168. package/tests/sideeffecthandler/SideEffectHandlerFixtures.res.mjs +4 -6
  169. package/tests/util/CommandPublisherTest.res +0 -1
  170. package/tests/util/CommandPublisherTest.res.mjs +4 -6
@@ -65,9 +65,7 @@ let conventionalLabelNames = [
65
65
  "displayname"
66
66
  ];
67
67
 
68
- function shapeOfItem(entityName, item) {
69
- return SchemaType$ReventlessCore.fromSury(entityName, item.location, item.schema);
70
- }
68
+ let shapeOfField = SchemaType$ReventlessCore.fromSury;
71
69
 
72
70
  function lifecycleFieldFromStateSchema(entityName, stateSchema) {
73
71
  let spec = StateAnnotations$Reventless.getSpec(stateSchema);
@@ -75,13 +73,11 @@ function lifecycleFieldFromStateSchema(entityName, stateSchema) {
75
73
  if (annotated !== undefined) {
76
74
  return annotated;
77
75
  } else if (stateSchema.type === "object") {
78
- return Stdlib_Option.map(stateSchema.items.find(item => {
79
- if (item.location === "lifecycle") {
80
- return isLifecycleShape(shapeOfItem(entityName, item));
81
- } else {
82
- return false;
76
+ return Stdlib_Option.flatMap(stateSchema.properties["lifecycle"], schema => {
77
+ if (isLifecycleShape(SchemaType$ReventlessCore.fromSury(entityName, "lifecycle", schema))) {
78
+ return "lifecycle";
83
79
  }
84
- }), item => item.location);
80
+ });
85
81
  } else {
86
82
  return;
87
83
  }
@@ -122,8 +118,8 @@ function checkRetiredValue(entityName, stateSchema) {
122
118
  log.warn("Plugin_Structure", undefined, entityName + `: @retired(` + named + `) is on "` + field + `", which is not this record's lifecycle field` + Stdlib_Option.getOr(Stdlib_Option.map(lifecycle, f => ` (that is "` + f + `")`), " (it declares none)") + `. A retirement state no command's @transition can name loses the command filtering the state form exists for.`);
123
119
  }
124
120
  let declared;
125
- declared = stateSchema.type === "object" ? Stdlib_Option.getOr(Stdlib_Option.map(stateSchema.items.find(item => item.location === field), item => {
126
- let match = shapeOfItem(entityName, item);
121
+ declared = stateSchema.type === "object" ? Stdlib_Option.getOr(Stdlib_Option.map(stateSchema.properties[field], schema => {
122
+ let match = SchemaType$ReventlessCore.fromSury(entityName, field, schema);
127
123
  if (typeof match !== "object") {
128
124
  return [];
129
125
  }
@@ -168,8 +164,8 @@ function reportRetiredStates(pluginName, failures, unchecked) {
168
164
  function lifecycleStatesFromStateSchema(entityName, stateSchema) {
169
165
  return Stdlib_Option.flatMap(lifecycleFieldFromStateSchema(entityName, stateSchema), field => {
170
166
  if (stateSchema.type === "object") {
171
- return Stdlib_Option.map(stateSchema.items.find(item => item.location === field), item => {
172
- let match = shapeOfItem(entityName, item);
167
+ return Stdlib_Option.map(stateSchema.properties[field], schema => {
168
+ let match = SchemaType$ReventlessCore.fromSury(entityName, field, schema);
173
169
  if (typeof match !== "object") {
174
170
  return [];
175
171
  }
@@ -235,29 +231,17 @@ function lifecycleTopologyFindings(writables, lifecycleStatesByView) {
235
231
  Object.entries(lifecycleStatesByView).forEach(param => {
236
232
  let states = param[1];
237
233
  let view = param[0];
238
- let edges = Stdlib_Array.reduce(writables, [], (acc, w) => {
234
+ let reachable = Stdlib_Array.reduce(writables, [], (acc, w) => {
239
235
  if (w.linkedViews.includes(view)) {
240
- return acc.concat(Stdlib_Array.reduce(w.commands, [], (inner, cmd) => {
241
- let match = cmd.allowedStates;
242
- let match$1 = cmd.targetState;
243
- if (match !== undefined && match$1 !== undefined) {
244
- return inner.concat(match.map(from => [
245
- from,
246
- match$1
247
- ]));
248
- } else {
249
- return inner;
250
- }
251
- }));
236
+ return acc.concat(Stdlib_Array.filterMap(w.commands, cmd => cmd.targetState));
252
237
  } else {
253
238
  return acc;
254
239
  }
255
240
  });
256
- if (edges.length === 0) {
241
+ if (reachable.length === 0) {
257
242
  return;
258
243
  }
259
244
  let initial = states[0];
260
- let reachable = edges.map(param => param[1]);
261
245
  states.forEach(state => {
262
246
  if (!reachable.includes(state) && Primitive_object.notequal(state, initial)) {
263
247
  findings.push([
@@ -298,29 +282,30 @@ function labelFieldsFromStateSchema(entityName, stateSchema) {
298
282
  };
299
283
  }
300
284
  let candidates;
301
- candidates = stateSchema.type === "object" ? stateSchema.items.filter(item => {
302
- if (item.location !== "TAG" && item.location !== "id") {
303
- return isLabelShape(shapeOfItem(entityName, item));
285
+ candidates = stateSchema.type === "object" ? Object.entries(stateSchema.properties).filter(param => {
286
+ let name = param[0];
287
+ if (name !== "TAG" && name !== "id") {
288
+ return isLabelShape(SchemaType$ReventlessCore.fromSury(entityName, name, param[1]));
304
289
  } else {
305
290
  return false;
306
291
  }
307
292
  }) : [];
308
- let conventional = candidates.find(item => {
309
- let lower = item.location.toLowerCase();
293
+ let conventional = candidates.find(param => {
294
+ let lower = param[0].toLowerCase();
310
295
  return conventionalLabelNames.some(n => n === lower);
311
296
  });
312
297
  let picked = conventional !== undefined ? [
313
- conventional,
298
+ conventional[0],
314
299
  "Convention"
315
- ] : Stdlib_Option.map(candidates[0], item => [
316
- item,
300
+ ] : Stdlib_Option.map(candidates[0], param => [
301
+ param[0],
317
302
  "Position"
318
303
  ]);
319
304
  if (picked !== undefined) {
320
- let item = picked[0];
305
+ let name = picked[0];
321
306
  return {
322
- field: item.location,
323
- searchableFields: [item.location],
307
+ field: name,
308
+ searchableFields: [name],
324
309
  source: picked[1]
325
310
  };
326
311
  }
@@ -377,7 +362,7 @@ function toEventDef(v) {
377
362
  }
378
363
 
379
364
  function extractEventDefs(eventSchema) {
380
- if (eventSchema.type === "union") {
365
+ if (eventSchema.type === "anyOf") {
381
366
  return Stdlib_Array.filterMap(eventSchema.anyOf, toEventDef);
382
367
  } else {
383
368
  return Stdlib_Option.mapOr(toEventDef(eventSchema), [], def => [def]);
@@ -392,19 +377,8 @@ function extractErrorDefs(errorSchema) {
392
377
  }));
393
378
  }
394
379
 
395
- function make(name, aggregatesOpt, readModelsOpt, stateViewSlicesOpt, stateChangeSlicesOpt, automationSlicesOpt, outboundTranslationSlicesOpt, inboundTranslationSlicesOpt, extensionsOpt, extensionPointsOpt, componentChaptersOpt) {
396
- let aggregates = aggregatesOpt !== undefined ? aggregatesOpt : [];
397
- let readModels = readModelsOpt !== undefined ? readModelsOpt : [];
398
- let stateViewSlices = stateViewSlicesOpt !== undefined ? stateViewSlicesOpt : [];
399
- let stateChangeSlices = stateChangeSlicesOpt !== undefined ? stateChangeSlicesOpt : [];
400
- let automationSlices = automationSlicesOpt !== undefined ? automationSlicesOpt : [];
401
- let outboundTranslationSlices = outboundTranslationSlicesOpt !== undefined ? outboundTranslationSlicesOpt : [];
402
- let inboundTranslationSlices = inboundTranslationSlicesOpt !== undefined ? inboundTranslationSlicesOpt : [];
403
- let extensions = extensionsOpt !== undefined ? extensionsOpt : [];
404
- let extensionPoints = extensionPointsOpt !== undefined ? extensionPointsOpt : [];
405
- let componentChapters = componentChaptersOpt !== undefined ? componentChaptersOpt : ({});
406
- let qualify = (prefix, names) => names.map(n => prefix + "." + n);
407
- let isCreateCommandName = name => [
380
+ function isCreateCommandName(name) {
381
+ return [
408
382
  "Add",
409
383
  "Create",
410
384
  "Register",
@@ -414,135 +388,193 @@ function make(name, aggregatesOpt, readModelsOpt, stateViewSlicesOpt, stateChang
414
388
  "Start",
415
389
  "Place"
416
390
  ].some(p => name.startsWith(p));
417
- let commandLevelAndId = (isAggregate, variantName, properties) => {
418
- if (isAggregate) {
419
- if (isCreateCommandName(variantName)) {
420
- return [
421
- "Collection",
422
- undefined
423
- ];
424
- } else {
425
- return [
426
- "Instance",
427
- undefined
428
- ];
429
- }
430
- }
431
- let taggedFields = Object.entries(properties).filter(param => {
432
- let fieldSchema = param[1];
433
- if (param[0] !== "TAG") {
434
- if (DcbTag$Reventless.isTagged(fieldSchema)) {
435
- return true;
436
- } else {
437
- return DcbTag$Reventless.isTaggedArray(fieldSchema);
438
- }
439
- } else {
440
- return false;
441
- }
442
- });
443
- let taggedField = Stdlib_Option.orElse(taggedFields.find(param => DcbTag$Reventless.isPartitionTag(param[1])), taggedFields[0]);
444
- if (taggedField === undefined) {
445
- return [
446
- "Collection",
447
- undefined
448
- ];
449
- }
450
- let fieldName = taggedField[0];
391
+ }
392
+
393
+ function commandLevelAndId(isAggregate, variantName, properties) {
394
+ if (isAggregate) {
451
395
  if (isCreateCommandName(variantName)) {
452
396
  return [
453
397
  "Collection",
454
- fieldName
398
+ undefined
455
399
  ];
456
400
  } else {
457
401
  return [
458
402
  "Instance",
459
- fieldName
403
+ undefined
460
404
  ];
461
405
  }
462
- };
463
- let accessKeysFor = rule => {
464
- if (typeof rule !== "object") {
465
- return;
406
+ }
407
+ let taggedFields = Object.entries(properties).filter(param => {
408
+ let fieldSchema = param[1];
409
+ if (param[0] !== "TAG") {
410
+ if (DcbTag$Reventless.isTagged(fieldSchema)) {
411
+ return true;
412
+ } else {
413
+ return DcbTag$Reventless.isTaggedArray(fieldSchema);
414
+ }
415
+ } else {
416
+ return false;
466
417
  }
467
- let groups = rule._0;
468
- if (groups.length !== 0) {
469
- return groups;
418
+ });
419
+ let taggedField = Stdlib_Option.orElse(taggedFields.find(param => DcbTag$Reventless.isPartitionTag(param[1])), taggedFields[0]);
420
+ if (taggedField === undefined) {
421
+ return [
422
+ "Collection",
423
+ undefined
424
+ ];
425
+ }
426
+ let fieldName = taggedField[0];
427
+ if (isCreateCommandName(variantName)) {
428
+ return [
429
+ "Collection",
430
+ fieldName
431
+ ];
432
+ } else {
433
+ return [
434
+ "Instance",
435
+ fieldName
436
+ ];
437
+ }
438
+ }
439
+
440
+ function accessKeysFor(rule) {
441
+ if (typeof rule !== "object") {
442
+ return;
443
+ }
444
+ let groups = rule._0;
445
+ if (groups.length !== 0) {
446
+ return groups;
447
+ }
448
+ }
449
+
450
+ function annotateArgTypes(schema, argTypes) {
451
+ Stdlib_Option.forEach(Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(schema), o => o["properties"]), Stdlib_JSON.Decode.object), props => {
452
+ Object.entries(props).forEach(param => {
453
+ let match = argTypes[param[0]];
454
+ let match$1 = Stdlib_JSON.Decode.object(param[1]);
455
+ if (match !== undefined && match$1 !== undefined) {
456
+ match$1["x-reventless-graphql-type"] = match;
457
+ return;
458
+ }
459
+ });
460
+ });
461
+ return schema;
462
+ }
463
+
464
+ function toCommandDef(isAggregate, mutationFieldFor, parentSchema, commandAuthorization, v) {
465
+ let mkDef = (variantName, properties) => {
466
+ let match = commandLevelAndId(isAggregate, variantName, properties);
467
+ let references = extractReferences(properties);
468
+ let allowedStates = ApiAllowedStatesHelpers$ReventlessCore.getAllowedStates(parentSchema, variantName);
469
+ let targetState = ApiTargetStateHelpers$ReventlessCore.getTargetState(parentSchema, variantName);
470
+ let apiExposed = false;
471
+ if (!ApiNoApiHelpers$ReventlessCore.isNoApi(parentSchema)) {
472
+ let excluded = ApiNoApiHelpers$ReventlessCore.getExcludedVariants(parentSchema);
473
+ apiExposed = excluded !== undefined ? !excluded.has(variantName) : true;
470
474
  }
475
+ let syntheticCommand = DcbTag$Reventless.isVariantPayloadBearing(parentSchema, variantName) ? ({
476
+ TAG: variantName
477
+ }) : variantName;
478
+ let requiredAccess = accessKeysFor(commandAuthorization(syntheticCommand));
479
+ let mutationField = apiExposed ? mutationFieldFor(variantName) : "";
480
+ let jsonSchema = SuryToJsonSchema$ReventlessCore.deriveObjectSchema(v);
481
+ let annotatedSchema = apiExposed ? Stdlib_Option.mapOr(GraphQL_FragmentGenerator$ReventlessCore.mutationArgTypes(mutationField, v), jsonSchema, __x => annotateArgTypes(jsonSchema, __x)) : jsonSchema;
482
+ return {
483
+ name: variantName,
484
+ schema: JSON.stringify(annotatedSchema),
485
+ level: match[0],
486
+ aggregateIdField: match[1],
487
+ mutationField: mutationField,
488
+ references: references,
489
+ allowedStates: allowedStates,
490
+ targetState: targetState,
491
+ apiExposed: apiExposed,
492
+ requiredAccess: requiredAccess,
493
+ ownerField: Owner$Reventless.fieldNamesOfProperties(properties)[0]
494
+ };
471
495
  };
472
- let toCommandDef = (isAggregate, mutationFieldFor, parentSchema, commandAuthorization, v) => {
473
- let mkDef = (variantName, properties) => {
474
- let match = commandLevelAndId(isAggregate, variantName, properties);
475
- let references = extractReferences(properties);
476
- let allowedStates = ApiAllowedStatesHelpers$ReventlessCore.getAllowedStates(parentSchema, variantName);
477
- let targetState = ApiTargetStateHelpers$ReventlessCore.getTargetState(parentSchema, variantName);
478
- let apiExposed = false;
479
- if (!ApiNoApiHelpers$ReventlessCore.isNoApi(parentSchema)) {
480
- let excluded = ApiNoApiHelpers$ReventlessCore.getExcludedVariants(parentSchema);
481
- apiExposed = excluded !== undefined ? !excluded.has(variantName) : true;
496
+ switch (v.type) {
497
+ case "string" :
498
+ let variantName = v.const;
499
+ if (variantName !== undefined) {
500
+ return mkDef(variantName, {});
501
+ } else {
502
+ return;
482
503
  }
483
- let syntheticCommand = DcbTag$Reventless.isVariantPayloadBearing(parentSchema, variantName) ? ({
484
- TAG: variantName
485
- }) : variantName;
486
- let requiredAccess = accessKeysFor(commandAuthorization(syntheticCommand));
487
- let mutationField = apiExposed ? mutationFieldFor(variantName) : "";
488
- let jsonSchema = SuryToJsonSchema$ReventlessCore.deriveObjectSchema(v);
489
- let annotatedSchema = apiExposed ? Stdlib_Option.mapOr(GraphQL_FragmentGenerator$ReventlessCore.mutationArgTypes(mutationField, v), jsonSchema, __x => {
490
- Stdlib_Option.forEach(Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(jsonSchema), o => o["properties"]), Stdlib_JSON.Decode.object), props => {
491
- Object.entries(props).forEach(param => {
492
- let match = __x[param[0]];
493
- let match$1 = Stdlib_JSON.Decode.object(param[1]);
494
- if (match !== undefined && match$1 !== undefined) {
495
- match$1["x-reventless-graphql-type"] = match;
496
- return;
497
- }
498
- });
499
- });
500
- return jsonSchema;
501
- }) : jsonSchema;
502
- return {
503
- name: variantName,
504
- schema: JSON.stringify(annotatedSchema),
505
- level: match[0],
506
- aggregateIdField: match[1],
507
- mutationField: mutationField,
508
- references: references,
509
- allowedStates: allowedStates,
510
- targetState: targetState,
511
- apiExposed: apiExposed,
512
- requiredAccess: requiredAccess,
513
- ownerField: Owner$Reventless.fieldNamesOfProperties(properties)[0]
514
- };
515
- };
516
- switch (v.type) {
517
- case "string" :
518
- let variantName = v.const;
519
- if (variantName !== undefined) {
520
- return mkDef(variantName, {});
521
- } else {
504
+ case "object" :
505
+ let properties = v.properties;
506
+ return Stdlib_Option.flatMap(properties["TAG"], tagSchema => {
507
+ if (tagSchema.type !== "string") {
522
508
  return;
523
509
  }
524
- case "object" :
525
- let properties = v.properties;
526
- return Stdlib_Option.flatMap(properties["TAG"], tagSchema => {
527
- if (tagSchema.type !== "string") {
528
- return;
529
- }
530
- let variantName = tagSchema.const;
531
- if (variantName !== undefined) {
532
- return mkDef(variantName, properties);
533
- }
534
- });
535
- default:
536
- return;
537
- }
538
- };
539
- let extractCommandDefs = (isAggregate, mutationFieldFor, commandAuthorization, commandSchema) => {
540
- if (commandSchema.type === "union") {
541
- return Stdlib_Array.filterMap(commandSchema.anyOf, v => toCommandDef(isAggregate, mutationFieldFor, commandSchema, commandAuthorization, v));
542
- } else {
543
- return Stdlib_Option.mapOr(toCommandDef(isAggregate, mutationFieldFor, commandSchema, commandAuthorization, commandSchema), [], def => [def]);
544
- }
510
+ let variantName = tagSchema.const;
511
+ if (variantName !== undefined) {
512
+ return mkDef(variantName, properties);
513
+ }
514
+ });
515
+ default:
516
+ return;
517
+ }
518
+ }
519
+
520
+ function extractCommandDefs(isAggregate, mutationFieldFor, commandAuthorization, commandSchema) {
521
+ if (commandSchema.type === "anyOf") {
522
+ return Stdlib_Array.filterMap(commandSchema.anyOf, v => toCommandDef(isAggregate, mutationFieldFor, commandSchema, commandAuthorization, v));
523
+ } else {
524
+ return Stdlib_Option.mapOr(toCommandDef(isAggregate, mutationFieldFor, commandSchema, commandAuthorization, commandSchema), [], def => [def]);
525
+ }
526
+ }
527
+
528
+ function visibilityTag(v) {
529
+ if (v === "Public") {
530
+ return;
531
+ } else {
532
+ return "Internal";
533
+ }
534
+ }
535
+
536
+ function queryableDefFromSpec(plugin, name, stateSchema, authorization, visibilityOpt, consumedEventTypesOpt, linkedWriteSideOpt, chapter) {
537
+ let visibility = visibilityOpt !== undefined ? visibilityOpt : "Public";
538
+ let consumedEventTypes = consumedEventTypesOpt !== undefined ? consumedEventTypesOpt : [];
539
+ let linkedWriteSide = linkedWriteSideOpt !== undefined ? linkedWriteSideOpt : [];
540
+ let qf = Api_Naming$ReventlessCore.queryFieldNamesForReadModel(plugin, name, undefined);
541
+ let label = labelFieldsFromStateSchema(name, stateSchema);
542
+ let keyField = GraphQL_FragmentGenerator$ReventlessCore.resolveKeyField(name, stateSchema);
543
+ return {
544
+ name: name,
545
+ queryField: qf.listFieldName,
546
+ schema: JSON.stringify(SuryToJsonSchema$ReventlessCore.deriveObjectSchema(stateSchema)),
547
+ consumedEventTypes: consumedEventTypes,
548
+ linkedWriteSide: linkedWriteSide,
549
+ labelField: label.field,
550
+ searchableFields: label.searchableFields,
551
+ labelFieldSource: labelFieldSourceToString(label.source),
552
+ lifecycleField: lifecycleFieldFromStateSchema(name, stateSchema),
553
+ ownerField: Owner$Reventless.fieldNames(stateSchema)[0],
554
+ retiredField: retiredFieldFromStateSchema(stateSchema),
555
+ retiredValues: retiredValuesFromStateSchema(stateSchema),
556
+ namedWhenRetired: namedWhenRetiredFromStateSchema(stateSchema),
557
+ visibility: visibilityTag(visibility),
558
+ chapter: chapter,
559
+ singleQueryField: qf.singleFieldName,
560
+ idField: Stdlib_Option.map(keyField, param => param[0]),
561
+ idFieldSource: Stdlib_Option.map(keyField, param => param[1]),
562
+ requiredAccess: accessKeysFor(authorization)
545
563
  };
564
+ }
565
+
566
+ function make(name, aggregatesOpt, readModelsOpt, stateViewSlicesOpt, stateChangeSlicesOpt, automationSlicesOpt, outboundTranslationSlicesOpt, inboundTranslationSlicesOpt, extensionsOpt, extensionPointsOpt, componentChaptersOpt) {
567
+ let aggregates = aggregatesOpt !== undefined ? aggregatesOpt : [];
568
+ let readModels = readModelsOpt !== undefined ? readModelsOpt : [];
569
+ let stateViewSlices = stateViewSlicesOpt !== undefined ? stateViewSlicesOpt : [];
570
+ let stateChangeSlices = stateChangeSlicesOpt !== undefined ? stateChangeSlicesOpt : [];
571
+ let automationSlices = automationSlicesOpt !== undefined ? automationSlicesOpt : [];
572
+ let outboundTranslationSlices = outboundTranslationSlicesOpt !== undefined ? outboundTranslationSlicesOpt : [];
573
+ let inboundTranslationSlices = inboundTranslationSlicesOpt !== undefined ? inboundTranslationSlicesOpt : [];
574
+ let extensions = extensionsOpt !== undefined ? extensionsOpt : [];
575
+ let extensionPoints = extensionPointsOpt !== undefined ? extensionPointsOpt : [];
576
+ let componentChapters = componentChaptersOpt !== undefined ? componentChaptersOpt : ({});
577
+ let qualify = (prefix, names) => names.map(n => prefix + "." + n);
546
578
  let scsProduced = stateChangeSlices.map(SCS => [
547
579
  SCS.Spec.name,
548
580
  qualify(name, DcbTag$Reventless.extractVariantNames(SCS.Spec.eventSchema))
@@ -690,7 +722,7 @@ function make(name, aggregatesOpt, readModelsOpt, stateViewSlicesOpt, stateChang
690
722
  return [];
691
723
  }
692
724
  };
693
- if (schema.type === "union") {
725
+ if (schema.type === "anyOf") {
694
726
  return schema.anyOf.flatMap(fromVariant);
695
727
  } else {
696
728
  return fromVariant(schema);
@@ -708,16 +740,13 @@ function make(name, aggregatesOpt, readModelsOpt, stateViewSlicesOpt, stateChang
708
740
  }
709
741
  });
710
742
  let requiredStores = Belt_SetString.toArray(Belt_SetString.fromArray(requiredStoreDeclarations.map(d => d.store)));
743
+ let found = Capability_Inference$ReventlessCore.collisions(requiredStoreDeclarations);
744
+ if (found.length !== 0) {
745
+ Stdlib_JsError.throwWithMessage(name + `: two declared object stores look like one store misspelled.\n` + found.map(Capability_Inference$ReventlessCore.collisionMessage).join("\n"));
746
+ }
711
747
  storeDeclarationSites.forEach(param => {
712
748
  Capability_Inference$ReventlessCore.scanSchema(param[0], param[1]).forEach(w => log.warn("Plugin_Structure", undefined, Capability_Inference$ReventlessCore.message(w)));
713
749
  });
714
- let visibilityTag = v => {
715
- if (v === "Public") {
716
- return;
717
- } else {
718
- return "Internal";
719
- }
720
- };
721
750
  let lifecycleStatesByView = {};
722
751
  let recordLifecycle = (entityName, stateSchema) => {
723
752
  let states = lifecycleStatesFromStateSchema(entityName, stateSchema);
@@ -916,7 +945,7 @@ export {
916
945
  isLabelShape,
917
946
  isLifecycleShape,
918
947
  conventionalLabelNames,
919
- shapeOfItem,
948
+ shapeOfField,
920
949
  lifecycleFieldFromStateSchema,
921
950
  retiredFromStateSchema,
922
951
  retiredFieldFromStateSchema,
@@ -934,6 +963,14 @@ export {
934
963
  toEventDef,
935
964
  extractEventDefs,
936
965
  extractErrorDefs,
966
+ isCreateCommandName,
967
+ commandLevelAndId,
968
+ accessKeysFor,
969
+ annotateArgTypes,
970
+ toCommandDef,
971
+ extractCommandDefs,
972
+ visibilityTag,
973
+ queryableDefFromSpec,
937
974
  make,
938
975
  }
939
976
  /* log Not a pure module */
@@ -44,7 +44,7 @@ let sourceCFields = (
44
44
  mutationEntries->Array.forEach(entry => {
45
45
  let schema = entry.commandSchema
46
46
  switch schema {
47
- | Union({anyOf}) =>
47
+ | AnyOf({anyOf}) =>
48
48
  anyOf->Array.forEachWithIndex((_, i) => {
49
49
  let fieldName = entry.fieldNames->Array.get(i)->Option.getOr("")
50
50
  if fieldName->String.length > 0 {
@@ -26,7 +26,7 @@ function sourceCFields(mutationEntries) {
26
26
  } else {
27
27
  return;
28
28
  }
29
- case "union" :
29
+ case "anyOf" :
30
30
  schema.anyOf.forEach((param, i) => {
31
31
  let fieldName = Stdlib_Option.getOr(entry.fieldNames[i], "");
32
32
  if (fieldName.length > 0) {
@@ -10,7 +10,7 @@ open Plugin_BuiltHook
10
10
 
11
11
  // ---------------------------------------------------------------------------
12
12
  // Type description — maps a sury schema node to a human-readable string.
13
- // Optional fields in sury are Union({anyOf}) containing Null or Undefined.
13
+ // Optional fields in sury are AnyOf({anyOf}) containing Null or Undefined.
14
14
  // ---------------------------------------------------------------------------
15
15
  let rec describeSchema = (schema: S.t<unknown>): string =>
16
16
  switch schema {
@@ -20,7 +20,7 @@ let rec describeSchema = (schema: S.t<unknown>): string =>
20
20
  | Boolean(_) => "bool"
21
21
  | BigInt(_) => "bigint"
22
22
  | Null(_) => "null"
23
- | Union({anyOf}) =>
23
+ | AnyOf({anyOf}) =>
24
24
  // Nullable/optional field: Union of Null/Undefined + one real type.
25
25
  let nonNull = anyOf->Array.filter(v =>
26
26
  switch v {
@@ -58,7 +58,7 @@ let rec describeSchema = (schema: S.t<unknown>): string =>
58
58
  // (Union containing Null or Undefined).
59
59
  let isOptionalSchema = (schema: S.t<unknown>): bool =>
60
60
  switch schema {
61
- | Union({anyOf}) =>
61
+ | AnyOf({anyOf}) =>
62
62
  anyOf->Array.some(v =>
63
63
  switch v {
64
64
  | Null(_) | Undefined(_) => true
@@ -112,11 +112,11 @@ let hashConstructors = (ctors: array<constructorSchema>): string => {
112
112
  // ---------------------------------------------------------------------------
113
113
  // TAG item helper — extracts the const string value from a TAG schema item.
114
114
  // ---------------------------------------------------------------------------
115
- let tagConstOf = (items: array<S.item>): option<string> =>
116
- items
117
- ->Array.find(item => item.location == "TAG")
118
- ->Option.flatMap(item =>
119
- switch item.schema {
115
+ let tagConstOf = (properties: dict<S.t<unknown>>): option<string> =>
116
+ properties
117
+ ->Dict.get("TAG")
118
+ ->Option.flatMap(schema =>
119
+ switch schema {
120
120
  | String({const: ?Some(v)}) => Some(v)
121
121
  | _ => None
122
122
  }
@@ -135,7 +135,7 @@ let walkSchema = (typeName: string, schema: S.t<unknown>): typeSchema =>
135
135
  fields,
136
136
  structuralHash: hashFields(fields),
137
137
  }
138
- | Union({anyOf}) =>
138
+ | AnyOf({anyOf}) =>
139
139
  // Check if this is a nullable scalar vs. a true variant union.
140
140
  let hasNullLike = anyOf->Array.some(v =>
141
141
  switch v {
@@ -150,8 +150,8 @@ let walkSchema = (typeName: string, schema: S.t<unknown>): typeSchema =>
150
150
  let constructors =
151
151
  anyOf->Array.filterMap(variantSchema =>
152
152
  switch variantSchema {
153
- | Object({items, properties}) =>
154
- tagConstOf(items)->Option.map(name => {
153
+ | Object({properties}) =>
154
+ tagConstOf(properties)->Option.map(name => {
155
155
  name,
156
156
  fields: extractFields(properties),
157
157
  })
@@ -25,7 +25,7 @@ function describeSchema(schema) {
25
25
  case "object" :
26
26
  let inner = Object.entries(schema.properties).filter(param => param[0] !== "TAG").toSorted((param, param$1) => Primitive_string.compare(param[0], param$1[0])).map(param => param[0] + ":" + describeSchema(param[1])).join(",");
27
27
  return "{" + inner + "}";
28
- case "union" :
28
+ case "anyOf" :
29
29
  let nonNull = schema.anyOf.filter(v => {
30
30
  switch (v.type) {
31
31
  case "null" :
@@ -47,7 +47,7 @@ function describeSchema(schema) {
47
47
  }
48
48
 
49
49
  function isOptionalSchema(schema) {
50
- if (schema.type === "union") {
50
+ if (schema.type === "anyOf") {
51
51
  return schema.anyOf.some(v => {
52
52
  switch (v.type) {
53
53
  case "null" :
@@ -100,13 +100,12 @@ function hashConstructors(ctors) {
100
100
  });
101
101
  }
102
102
 
103
- function tagConstOf(items) {
104
- return Stdlib_Option.flatMap(items.find(item => item.location === "TAG"), item => {
105
- let match = item.schema;
106
- if (match.type !== "string") {
103
+ function tagConstOf(properties) {
104
+ return Stdlib_Option.flatMap(properties["TAG"], schema => {
105
+ if (schema.type !== "string") {
107
106
  return;
108
107
  }
109
- let v = match.const;
108
+ let v = schema.const;
110
109
  if (v !== undefined) {
111
110
  return v;
112
111
  }
@@ -123,7 +122,7 @@ function walkSchema(typeName, schema) {
123
122
  fields: fields,
124
123
  structuralHash: hashFields(fields)
125
124
  };
126
- case "union" :
125
+ case "anyOf" :
127
126
  let anyOf = schema.anyOf;
128
127
  let hasNullLike = anyOf.some(v => {
129
128
  switch (v.type) {
@@ -147,7 +146,7 @@ function walkSchema(typeName, schema) {
147
146
  return;
148
147
  }
149
148
  let properties = variantSchema.properties;
150
- return Stdlib_Option.map(tagConstOf(variantSchema.items), name => ({
149
+ return Stdlib_Option.map(tagConstOf(properties), name => ({
151
150
  name: name,
152
151
  fields: extractFields(properties)
153
152
  }));