@reventlessdev/reventless-spec 3.0.0-alpha.61

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 (86) hide show
  1. package/CHANGELOG.md +625 -0
  2. package/LICENSE +202 -0
  3. package/README.md +114 -0
  4. package/package.json +34 -0
  5. package/rescript.json +25 -0
  6. package/run-generator.mjs +2 -0
  7. package/src/AnsiStyle.res +40 -0
  8. package/src/AnsiStyle.res.mjs +54 -0
  9. package/src/LogPrefix.res +168 -0
  10. package/src/LogPrefix.res.mjs +148 -0
  11. package/src/PackageVersion.res +73 -0
  12. package/src/PackageVersion.res.mjs +81 -0
  13. package/src/components/Aggregate.res +64 -0
  14. package/src/components/Aggregate.res.mjs +2 -0
  15. package/src/components/AutomationSlice.res +279 -0
  16. package/src/components/AutomationSlice.res.mjs +30 -0
  17. package/src/components/Counter.res +24 -0
  18. package/src/components/Counter.res.mjs +2 -0
  19. package/src/components/DcbDecode.res +128 -0
  20. package/src/components/DcbDecode.res.mjs +117 -0
  21. package/src/components/DcbTag.res +1256 -0
  22. package/src/components/DcbTag.res.mjs +869 -0
  23. package/src/components/DcbValidation.res +362 -0
  24. package/src/components/DcbValidation.res.mjs +360 -0
  25. package/src/components/DisplayName.res +40 -0
  26. package/src/components/DisplayName.res.mjs +26 -0
  27. package/src/components/ExtensionPoint.res +27 -0
  28. package/src/components/ExtensionPoint.res.mjs +2 -0
  29. package/src/components/InboundTranslationSlice.res +79 -0
  30. package/src/components/InboundTranslationSlice.res.mjs +2 -0
  31. package/src/components/OutboundTranslationSlice.res +108 -0
  32. package/src/components/OutboundTranslationSlice.res.mjs +2 -0
  33. package/src/components/Plugin.res +373 -0
  34. package/src/components/Plugin.res.mjs +249 -0
  35. package/src/components/ReadModel.res +199 -0
  36. package/src/components/ReadModel.res.mjs +18 -0
  37. package/src/components/Reference.res +51 -0
  38. package/src/components/Reference.res.mjs +37 -0
  39. package/src/components/StateAnnotations.res +65 -0
  40. package/src/components/StateAnnotations.res.mjs +15 -0
  41. package/src/components/StateChangeSlice.res +131 -0
  42. package/src/components/StateChangeSlice.res.mjs +2 -0
  43. package/src/components/StateViewSlice.res +99 -0
  44. package/src/components/StateViewSlice.res.mjs +2 -0
  45. package/src/components/Task.res +62 -0
  46. package/src/components/Task.res.mjs +2 -0
  47. package/src/generator/Codegen.res +703 -0
  48. package/src/generator/Codegen.res.mjs +485 -0
  49. package/src/generator/Config.res +85 -0
  50. package/src/generator/Config.res.mjs +78 -0
  51. package/src/generator/Discovery.res +204 -0
  52. package/src/generator/Discovery.res.mjs +213 -0
  53. package/src/generator/Generator_Node.res +49 -0
  54. package/src/generator/Generator_Node.res.mjs +18 -0
  55. package/src/generator/Pairing.res +386 -0
  56. package/src/generator/Pairing.res.mjs +353 -0
  57. package/src/generator/PluginGenerator.res +53 -0
  58. package/src/generator/PluginGenerator.res.mjs +70 -0
  59. package/src/types/Authorization.res +23 -0
  60. package/src/types/Authorization.res.mjs +33 -0
  61. package/src/types/Behavior.res +78 -0
  62. package/src/types/Behavior.res.mjs +2 -0
  63. package/src/types/EventMapping.res +100 -0
  64. package/src/types/EventMapping.res.mjs +15 -0
  65. package/src/types/Handler.res +30 -0
  66. package/src/types/Handler.res.mjs +2 -0
  67. package/src/types/Id.res +75 -0
  68. package/src/types/Id.res.mjs +37 -0
  69. package/src/types/Identity.res +46 -0
  70. package/src/types/Identity.res.mjs +51 -0
  71. package/src/types/Message.res +197 -0
  72. package/src/types/Message.res.mjs +108 -0
  73. package/src/types/Projection.res +220 -0
  74. package/src/types/Projection.res.mjs +44 -0
  75. package/src/types/QueryEngine.res +123 -0
  76. package/src/types/QueryEngine.res.mjs +12 -0
  77. package/src/types/ReadConsistency.res +38 -0
  78. package/src/types/ReadConsistency.res.mjs +29 -0
  79. package/src/types/Schedule.res +65 -0
  80. package/src/types/Schedule.res.mjs +68 -0
  81. package/src/types/SideEffect.res +45 -0
  82. package/src/types/SideEffect.res.mjs +2 -0
  83. package/src/types/StoredEvent.res +46 -0
  84. package/src/types/StoredEvent.res.mjs +32 -0
  85. package/src/types/Visibility.res +24 -0
  86. package/src/types/Visibility.res.mjs +25 -0
@@ -0,0 +1,869 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as S from "sury/src/S.res.mjs";
4
+ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
5
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
6
+ import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
7
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
8
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
9
+ import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
10
+ import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
11
+
12
+ let tagSchema = S.schema(s => ({
13
+ key: s.m(S.string),
14
+ value: s.m(S.string)
15
+ }));
16
+
17
+ let dcbTagId = S.Metadata.Id.make("dcb", "tag");
18
+
19
+ let dcbPartitionTagId = S.Metadata.Id.make("dcb", "partitionTag");
20
+
21
+ let dcbCrossPartitionId = S.Metadata.Id.make("dcb", "crossPartition");
22
+
23
+ let dcbCompositePartitionMemberId = S.Metadata.Id.make("dcb", "compositePartitionMember");
24
+
25
+ let dcbTagKeyOverrideId = S.Metadata.Id.make("dcb", "tagKeyOverride");
26
+
27
+ let string = S.Metadata.set(S.string, dcbTagId, true);
28
+
29
+ function stringForKey(key) {
30
+ return S.Metadata.set(S.Metadata.set(S.string, dcbTagId, true), dcbTagKeyOverrideId, key);
31
+ }
32
+
33
+ let int = S.Metadata.set(S.int, dcbTagId, true);
34
+
35
+ let partition = S.Metadata.set(S.Metadata.set(S.string, dcbTagId, true), dcbPartitionTagId, true);
36
+
37
+ let crossPartition = S.Metadata.set(S.Metadata.set(S.string, dcbTagId, true), dcbCrossPartitionId, true);
38
+
39
+ function compositePartitionMember(position, sepOpt) {
40
+ let sep = sepOpt !== undefined ? sepOpt : "/";
41
+ return S.Metadata.set(S.Metadata.set(S.string, dcbTagId, true), dcbCompositePartitionMemberId, {
42
+ position: position,
43
+ sep: sep
44
+ });
45
+ }
46
+
47
+ function isCompositePartitionMember(fieldSchema) {
48
+ return Stdlib_Option.isSome(S.Metadata.get(fieldSchema, dcbCompositePartitionMemberId));
49
+ }
50
+
51
+ function isTagged(fieldSchema) {
52
+ return Stdlib_Option.isSome(S.Metadata.get(fieldSchema, dcbTagId));
53
+ }
54
+
55
+ function isTaggedArray(fieldSchema) {
56
+ if (fieldSchema.type !== "array") {
57
+ return false;
58
+ }
59
+ let itemSchema = fieldSchema.additionalItems;
60
+ if (itemSchema === "strip" || itemSchema === "strict") {
61
+ return false;
62
+ } else {
63
+ return isTagged(itemSchema);
64
+ }
65
+ }
66
+
67
+ function isPartitionTag(fieldSchema) {
68
+ return Stdlib_Option.isSome(S.Metadata.get(fieldSchema, dcbPartitionTagId));
69
+ }
70
+
71
+ function isCrossPartitionTag(fieldSchema) {
72
+ return Stdlib_Option.isSome(S.Metadata.get(fieldSchema, dcbCrossPartitionId));
73
+ }
74
+
75
+ function isCrossPartitionTaggedArray(fieldSchema) {
76
+ if (fieldSchema.type !== "array") {
77
+ return false;
78
+ }
79
+ let itemSchema = fieldSchema.additionalItems;
80
+ if (itemSchema === "strip" || itemSchema === "strict") {
81
+ return false;
82
+ } else {
83
+ return isCrossPartitionTag(itemSchema);
84
+ }
85
+ }
86
+
87
+ function resolveTagKey(fieldName, fieldSchema) {
88
+ return Stdlib_Option.getOr(S.Metadata.get(fieldSchema, dcbTagKeyOverrideId), fieldName);
89
+ }
90
+
91
+ function resolveArrayTagKey(fieldName, fieldSchema) {
92
+ if (fieldSchema.type !== "array") {
93
+ return fieldName;
94
+ }
95
+ let itemSchema = fieldSchema.additionalItems;
96
+ if (itemSchema === "strip" || itemSchema === "strict") {
97
+ return fieldName;
98
+ } else {
99
+ return Stdlib_Option.getOr(S.Metadata.get(itemSchema, dcbTagKeyOverrideId), fieldName);
100
+ }
101
+ }
102
+
103
+ function jsonValueToString(json) {
104
+ switch (typeof json) {
105
+ case "boolean" :
106
+ if (json) {
107
+ return "true";
108
+ } else {
109
+ return "false";
110
+ }
111
+ case "string" :
112
+ return json;
113
+ case "number" :
114
+ return json.toString();
115
+ default:
116
+ return JSON.stringify(json);
117
+ }
118
+ }
119
+
120
+ function extractTagsFromProperties(properties, jsonDict) {
121
+ return Stdlib_Array.filterMap(Object.entries(properties), param => {
122
+ let fieldSchema = param[1];
123
+ let fieldName = param[0];
124
+ if (isTagged(fieldSchema)) {
125
+ return Stdlib_Option.map(jsonDict[fieldName], jsonValue => ({
126
+ key: resolveTagKey(fieldName, fieldSchema),
127
+ value: jsonValueToString(jsonValue)
128
+ }));
129
+ }
130
+ });
131
+ }
132
+
133
+ function extractTagsFromJson(schema, json) {
134
+ switch (schema.type) {
135
+ case "object" :
136
+ let jsonDict = Stdlib_JSON.Decode.object(json);
137
+ if (jsonDict !== undefined) {
138
+ return extractTagsFromProperties(schema.properties, jsonDict);
139
+ } else {
140
+ return [];
141
+ }
142
+ case "union" :
143
+ let jsonDict$1 = Stdlib_JSON.Decode.object(json);
144
+ if (jsonDict$1 === undefined) {
145
+ return [];
146
+ }
147
+ let jsonTag = Stdlib_Option.flatMap(jsonDict$1["TAG"], j => {
148
+ if (typeof j === "string") {
149
+ return j;
150
+ }
151
+ });
152
+ return Stdlib_Array.reduce(schema.anyOf, [], (acc, variantSchema) => {
153
+ if (acc.length !== 0) {
154
+ return acc;
155
+ }
156
+ if (variantSchema.type !== "object") {
157
+ return [];
158
+ }
159
+ let variantTag = Stdlib_Option.flatMap(variantSchema.items.find(item => item.location === "TAG"), item => {
160
+ let match = item.schema;
161
+ if (match.type !== "string") {
162
+ return;
163
+ }
164
+ let $$const = match.const;
165
+ if ($$const !== undefined) {
166
+ return $$const;
167
+ }
168
+ });
169
+ if (Primitive_object.equal(variantTag, jsonTag)) {
170
+ return extractTagsFromProperties(variantSchema.properties, jsonDict$1);
171
+ } else {
172
+ return [];
173
+ }
174
+ });
175
+ default:
176
+ return [];
177
+ }
178
+ }
179
+
180
+ function extractTags(schema, value) {
181
+ let json = JSON.parse(Stdlib_Option.getOrThrow(JSON.stringify(value), undefined));
182
+ return extractTagsFromJson(schema, json);
183
+ }
184
+
185
+ function extractVariantNames(schema) {
186
+ switch (schema.type) {
187
+ case "object" :
188
+ return Stdlib_Option.getOr(Stdlib_Option.flatMap(schema.items.find(item => item.location === "TAG"), item => {
189
+ let match = item.schema;
190
+ if (match.type !== "string") {
191
+ return;
192
+ }
193
+ let $$const = match.const;
194
+ if ($$const !== undefined) {
195
+ return [$$const];
196
+ }
197
+ }), []);
198
+ case "union" :
199
+ return Stdlib_Array.filterMap(schema.anyOf, variantSchema => {
200
+ if (variantSchema.type === "object") {
201
+ return Stdlib_Option.flatMap(variantSchema.items.find(item => item.location === "TAG"), item => {
202
+ let match = item.schema;
203
+ if (match.type !== "string") {
204
+ return;
205
+ }
206
+ let $$const = match.const;
207
+ if ($$const !== undefined) {
208
+ return $$const;
209
+ }
210
+ });
211
+ }
212
+ });
213
+ default:
214
+ return [];
215
+ }
216
+ }
217
+
218
+ function extractAllVariantNames(schema) {
219
+ switch (schema.type) {
220
+ case "string" :
221
+ let name = schema.const;
222
+ if (name !== undefined) {
223
+ return [name];
224
+ } else {
225
+ return [];
226
+ }
227
+ case "object" :
228
+ return Stdlib_Option.getOr(Stdlib_Option.flatMap(schema.items.find(item => item.location === "TAG"), item => {
229
+ let match = item.schema;
230
+ if (match.type !== "string") {
231
+ return;
232
+ }
233
+ let $$const = match.const;
234
+ if ($$const !== undefined) {
235
+ return [$$const];
236
+ }
237
+ }), []);
238
+ case "union" :
239
+ return Stdlib_Array.filterMap(schema.anyOf, variantSchema => {
240
+ switch (variantSchema.type) {
241
+ case "string" :
242
+ let $$const = variantSchema.const;
243
+ if ($$const !== undefined) {
244
+ return $$const;
245
+ } else {
246
+ return;
247
+ }
248
+ case "object" :
249
+ return Stdlib_Option.flatMap(variantSchema.items.find(item => item.location === "TAG"), item => {
250
+ let match = item.schema;
251
+ if (match.type !== "string") {
252
+ return;
253
+ }
254
+ let $$const = match.const;
255
+ if ($$const !== undefined) {
256
+ return $$const;
257
+ }
258
+ });
259
+ default:
260
+ return;
261
+ }
262
+ });
263
+ default:
264
+ return [];
265
+ }
266
+ }
267
+
268
+ function isVariantPayloadBearing(schema, name) {
269
+ let names = extractAllVariantNames(schema);
270
+ if (!names.includes(name)) {
271
+ return false;
272
+ }
273
+ switch (schema.type) {
274
+ case "object" :
275
+ return Stdlib_Option.getOr(Stdlib_Option.flatMap(schema.items.find(item => item.location === "TAG"), item => {
276
+ let match = item.schema;
277
+ if (match.type !== "string") {
278
+ return;
279
+ }
280
+ let $$const = match.const;
281
+ if ($$const !== undefined) {
282
+ return $$const === name;
283
+ }
284
+ }), false);
285
+ case "union" :
286
+ return schema.anyOf.some(variantSchema => {
287
+ if (variantSchema.type === "object") {
288
+ return Stdlib_Option.getOr(Stdlib_Option.flatMap(variantSchema.items.find(item => item.location === "TAG"), item => {
289
+ let match = item.schema;
290
+ if (match.type !== "string") {
291
+ return;
292
+ }
293
+ let $$const = match.const;
294
+ if ($$const !== undefined) {
295
+ return $$const === name;
296
+ }
297
+ }), false);
298
+ } else {
299
+ return false;
300
+ }
301
+ });
302
+ default:
303
+ return false;
304
+ }
305
+ }
306
+
307
+ function extractTagsFromPropertiesExpanded(properties, jsonDict) {
308
+ return Object.entries(properties).flatMap(param => {
309
+ let fieldSchema = param[1];
310
+ let fieldName = param[0];
311
+ if (isTagged(fieldSchema)) {
312
+ let jsonValue = jsonDict[fieldName];
313
+ if (jsonValue !== undefined) {
314
+ return [{
315
+ key: resolveTagKey(fieldName, fieldSchema),
316
+ value: jsonValueToString(jsonValue)
317
+ }];
318
+ } else {
319
+ return [];
320
+ }
321
+ }
322
+ if (!isTaggedArray(fieldSchema)) {
323
+ return [];
324
+ }
325
+ let match = jsonDict[fieldName];
326
+ if (match === undefined) {
327
+ return [];
328
+ }
329
+ if (!Array.isArray(match)) {
330
+ return [];
331
+ }
332
+ let tagKey = resolveArrayTagKey(fieldName, fieldSchema);
333
+ return match.map(element => ({
334
+ key: tagKey,
335
+ value: jsonValueToString(element)
336
+ }));
337
+ });
338
+ }
339
+
340
+ function extractTagsFromJsonExpanded(schema, json) {
341
+ switch (schema.type) {
342
+ case "object" :
343
+ let jsonDict = Stdlib_JSON.Decode.object(json);
344
+ if (jsonDict !== undefined) {
345
+ return extractTagsFromPropertiesExpanded(schema.properties, jsonDict);
346
+ } else {
347
+ return [];
348
+ }
349
+ case "union" :
350
+ let jsonDict$1 = Stdlib_JSON.Decode.object(json);
351
+ if (jsonDict$1 === undefined) {
352
+ return [];
353
+ }
354
+ let jsonTag = Stdlib_Option.flatMap(jsonDict$1["TAG"], j => {
355
+ if (typeof j === "string") {
356
+ return j;
357
+ }
358
+ });
359
+ return Stdlib_Array.reduce(schema.anyOf, [], (acc, variantSchema) => {
360
+ if (acc.length !== 0) {
361
+ return acc;
362
+ }
363
+ if (variantSchema.type !== "object") {
364
+ return [];
365
+ }
366
+ let variantTag = Stdlib_Option.flatMap(variantSchema.items.find(item => item.location === "TAG"), item => {
367
+ let match = item.schema;
368
+ if (match.type !== "string") {
369
+ return;
370
+ }
371
+ let $$const = match.const;
372
+ if ($$const !== undefined) {
373
+ return $$const;
374
+ }
375
+ });
376
+ if (Primitive_object.equal(variantTag, jsonTag)) {
377
+ return extractTagsFromPropertiesExpanded(variantSchema.properties, jsonDict$1);
378
+ } else {
379
+ return [];
380
+ }
381
+ });
382
+ default:
383
+ return [];
384
+ }
385
+ }
386
+
387
+ function extractTagsExpanded(schema, value) {
388
+ let json = JSON.parse(Stdlib_Option.getOrThrow(JSON.stringify(value), undefined));
389
+ return extractTagsFromJsonExpanded(schema, json);
390
+ }
391
+
392
+ function hasTaggedArrayFields(schema) {
393
+ switch (schema.type) {
394
+ case "object" :
395
+ return Object.entries(schema.properties).some(param => isTaggedArray(param[1]));
396
+ case "union" :
397
+ return schema.anyOf.some(variantSchema => {
398
+ if (variantSchema.type === "object") {
399
+ return Object.entries(variantSchema.properties).some(param => isTaggedArray(param[1]));
400
+ } else {
401
+ return false;
402
+ }
403
+ });
404
+ default:
405
+ return false;
406
+ }
407
+ }
408
+
409
+ function tagKeysOfProperties(properties) {
410
+ return Stdlib_Array.filterMap(Object.entries(properties), param => {
411
+ let fieldSchema = param[1];
412
+ let fieldName = param[0];
413
+ if (isTagged(fieldSchema)) {
414
+ return resolveTagKey(fieldName, fieldSchema);
415
+ } else if (isTaggedArray(fieldSchema)) {
416
+ return resolveArrayTagKey(fieldName, fieldSchema);
417
+ } else {
418
+ return;
419
+ }
420
+ });
421
+ }
422
+
423
+ function extractTagKeysByEventType(schema) {
424
+ let result = {};
425
+ let addVariant = variantSchema => {
426
+ if (variantSchema.type !== "object") {
427
+ return;
428
+ }
429
+ let properties = variantSchema.properties;
430
+ Stdlib_Option.forEach(Stdlib_Option.flatMap(variantSchema.items.find(item => item.location === "TAG"), item => {
431
+ let match = item.schema;
432
+ if (match.type !== "string") {
433
+ return;
434
+ }
435
+ let $$const = match.const;
436
+ if ($$const !== undefined) {
437
+ return $$const;
438
+ }
439
+ }), eventType => {
440
+ result[eventType] = tagKeysOfProperties(properties);
441
+ });
442
+ };
443
+ switch (schema.type) {
444
+ case "object" :
445
+ addVariant(schema);
446
+ break;
447
+ case "union" :
448
+ schema.anyOf.forEach(addVariant);
449
+ break;
450
+ }
451
+ return result;
452
+ }
453
+
454
+ function mergeTagKeysByEventType(maps) {
455
+ let merged = {};
456
+ maps.forEach(m => {
457
+ Object.entries(m).forEach(param => {
458
+ merged[param[0]] = param[1];
459
+ });
460
+ });
461
+ return merged;
462
+ }
463
+
464
+ function narrowEventTypesForTags(eventTypes, tags, tagKeysByEventType) {
465
+ return eventTypes.filter(eventType => {
466
+ let producedKeys = tagKeysByEventType[eventType];
467
+ if (producedKeys !== undefined) {
468
+ return tags.every(tag => producedKeys.includes(tag.key));
469
+ } else {
470
+ return true;
471
+ }
472
+ });
473
+ }
474
+
475
+ function buildQueryFromCommand(eventTypes, schema, value, tagKeysByEventTypeOpt, crossPartitionTagKeysOpt) {
476
+ let tagKeysByEventType = tagKeysByEventTypeOpt !== undefined ? tagKeysByEventTypeOpt : ({});
477
+ let crossPartitionTagKeys = crossPartitionTagKeysOpt !== undefined ? crossPartitionTagKeysOpt : [];
478
+ if (hasTaggedArrayFields(schema)) {
479
+ let tags = extractTagsExpanded(schema, value);
480
+ return tags.map(tag => {
481
+ let clauseTags = [{
482
+ key: tag.key,
483
+ value: tag.value
484
+ }];
485
+ return {
486
+ eventTypes: narrowEventTypesForTags(eventTypes, clauseTags, tagKeysByEventType),
487
+ tags: clauseTags
488
+ };
489
+ });
490
+ }
491
+ let tags$1 = extractTags(schema, value);
492
+ let hasCrossPartition = tags$1.some(tag => crossPartitionTagKeys.includes(tag.key));
493
+ if (hasCrossPartition && tags$1.length > 1) {
494
+ return tags$1.map(tag => {
495
+ let clauseTags = [{
496
+ key: tag.key,
497
+ value: tag.value
498
+ }];
499
+ return {
500
+ eventTypes: narrowEventTypesForTags(eventTypes, clauseTags, tagKeysByEventType),
501
+ tags: clauseTags
502
+ };
503
+ });
504
+ } else {
505
+ return [{
506
+ eventTypes: narrowEventTypesForTags(eventTypes, tags$1, tagKeysByEventType),
507
+ tags: tags$1
508
+ }];
509
+ }
510
+ }
511
+
512
+ function extractTaggedFields(schema) {
513
+ switch (schema.type) {
514
+ case "object" :
515
+ return Stdlib_Array.filterMap(Object.entries(schema.properties), param => {
516
+ if (isTagged(param[1])) {
517
+ return param[0];
518
+ }
519
+ }).toSorted(Primitive_string.compare);
520
+ case "union" :
521
+ let allFields = schema.anyOf.flatMap(variantSchema => {
522
+ if (variantSchema.type === "object") {
523
+ return Stdlib_Array.filterMap(Object.entries(variantSchema.properties), param => {
524
+ if (isTagged(param[1])) {
525
+ return param[0];
526
+ }
527
+ });
528
+ } else {
529
+ return [];
530
+ }
531
+ });
532
+ let fieldSet = new Set();
533
+ allFields.forEach(field => {
534
+ fieldSet.add(field);
535
+ });
536
+ return Array.from(fieldSet.values()).toSorted(Primitive_string.compare);
537
+ default:
538
+ return [];
539
+ }
540
+ }
541
+
542
+ function crossPartitionKeysOfProperties(properties) {
543
+ return Stdlib_Array.filterMap(Object.entries(properties), param => {
544
+ let fieldSchema = param[1];
545
+ let fieldName = param[0];
546
+ if (isTagged(fieldSchema) && isCrossPartitionTag(fieldSchema)) {
547
+ return resolveTagKey(fieldName, fieldSchema);
548
+ } else if (isCrossPartitionTaggedArray(fieldSchema)) {
549
+ return resolveArrayTagKey(fieldName, fieldSchema);
550
+ } else {
551
+ return;
552
+ }
553
+ });
554
+ }
555
+
556
+ function extractCrossPartitionTagKeys(schema) {
557
+ let keys;
558
+ switch (schema.type) {
559
+ case "object" :
560
+ keys = crossPartitionKeysOfProperties(schema.properties);
561
+ break;
562
+ case "union" :
563
+ keys = schema.anyOf.flatMap(variantSchema => {
564
+ if (variantSchema.type === "object") {
565
+ return crossPartitionKeysOfProperties(variantSchema.properties);
566
+ } else {
567
+ return [];
568
+ }
569
+ });
570
+ break;
571
+ default:
572
+ keys = [];
573
+ }
574
+ let seen = new Set();
575
+ keys.forEach(k => {
576
+ seen.add(k);
577
+ });
578
+ return Array.from(seen.values()).toSorted(Primitive_string.compare);
579
+ }
580
+
581
+ function extractPartitionTagFields(schema) {
582
+ switch (schema.type) {
583
+ case "object" :
584
+ return Stdlib_Array.filterMap(Object.entries(schema.properties), param => {
585
+ if (isPartitionTag(param[1])) {
586
+ return param[0];
587
+ }
588
+ });
589
+ case "union" :
590
+ let allFields = schema.anyOf.flatMap(variantSchema => {
591
+ if (variantSchema.type === "object") {
592
+ return Stdlib_Array.filterMap(Object.entries(variantSchema.properties), param => {
593
+ if (isPartitionTag(param[1])) {
594
+ return param[0];
595
+ }
596
+ });
597
+ } else {
598
+ return [];
599
+ }
600
+ });
601
+ let fieldSet = new Set();
602
+ allFields.forEach(field => {
603
+ fieldSet.add(field);
604
+ });
605
+ return Array.from(fieldSet.values());
606
+ default:
607
+ return [];
608
+ }
609
+ }
610
+
611
+ function hasMultiTagVariant(schema) {
612
+ switch (schema.type) {
613
+ case "object" :
614
+ let tagCount = Object.entries(schema.properties).filter(param => isTagged(param[1])).length;
615
+ return tagCount > 1;
616
+ case "union" :
617
+ return schema.anyOf.some(variantSchema => {
618
+ if (variantSchema.type !== "object") {
619
+ return false;
620
+ }
621
+ let tagCount = Object.entries(variantSchema.properties).filter(param => isTagged(param[1])).length;
622
+ return tagCount > 1;
623
+ });
624
+ default:
625
+ return false;
626
+ }
627
+ }
628
+
629
+ function findMultiTagVariantNames(schema) {
630
+ let variantName = variantSchema => {
631
+ if (variantSchema.type !== "object") {
632
+ return;
633
+ }
634
+ let tagCount = Object.entries(variantSchema.properties).filter(param => isTagged(param[1])).length;
635
+ if (tagCount > 1) {
636
+ return Stdlib_Option.getOr(Stdlib_Option.flatMap(variantSchema.items.find(item => item.location === "TAG"), item => {
637
+ let match = item.schema;
638
+ if (match.type !== "string") {
639
+ return;
640
+ }
641
+ let $$const = match.const;
642
+ if ($$const !== undefined) {
643
+ return $$const;
644
+ }
645
+ }), "(unknown)");
646
+ }
647
+ };
648
+ if (schema.type === "union") {
649
+ return Stdlib_Array.filterMap(schema.anyOf, variantName);
650
+ }
651
+ let name = variantName(schema);
652
+ if (name !== undefined) {
653
+ return [name];
654
+ } else {
655
+ return [];
656
+ }
657
+ }
658
+
659
+ function extractCompositePartitionFieldsFromProperties(properties) {
660
+ return Stdlib_Array.filterMap(Object.entries(properties), param => {
661
+ let meta = S.Metadata.get(param[1], dcbCompositePartitionMemberId);
662
+ if (meta !== undefined) {
663
+ return {
664
+ name: param[0],
665
+ position: meta.position,
666
+ sep: meta.sep
667
+ };
668
+ }
669
+ }).toSorted((a, b) => Primitive_int.compare(a.position, b.position));
670
+ }
671
+
672
+ function extractCompositePartitionFields(schema) {
673
+ let seen = new Set();
674
+ let collect = properties => extractCompositePartitionFieldsFromProperties(properties).filter(info => {
675
+ if (seen.has(info.name)) {
676
+ return false;
677
+ } else {
678
+ seen.add(info.name);
679
+ return true;
680
+ }
681
+ });
682
+ switch (schema.type) {
683
+ case "object" :
684
+ return collect(schema.properties);
685
+ case "union" :
686
+ return schema.anyOf.flatMap(variantSchema => {
687
+ if (variantSchema.type === "object") {
688
+ return collect(variantSchema.properties);
689
+ } else {
690
+ return [];
691
+ }
692
+ });
693
+ default:
694
+ return [];
695
+ }
696
+ }
697
+
698
+ function getCompositePartitionKeyValue(tags, spec) {
699
+ return spec.keys.map((fieldName, i) => {
700
+ let v = Stdlib_Option.getOr(Stdlib_Array.findMap(tags, t => {
701
+ if (t.key === fieldName) {
702
+ return t.value;
703
+ }
704
+ }), "");
705
+ if (i === 0) {
706
+ return v;
707
+ } else {
708
+ return spec.seps[i - 1 | 0] + v;
709
+ }
710
+ }).join("");
711
+ }
712
+
713
+ function derivePartitionTag(namedSchemas) {
714
+ let schemas = namedSchemas.map(param => param[2]);
715
+ let seen = new Set();
716
+ let allCompositeFields = schemas.flatMap(extractCompositePartitionFields).filter(info => {
717
+ if (seen.has(info.name)) {
718
+ return false;
719
+ } else {
720
+ seen.add(info.name);
721
+ return true;
722
+ }
723
+ });
724
+ let hasComposite = allCompositeFields.length !== 0;
725
+ let seen$1 = new Set();
726
+ let allPartitionFields = schemas.flatMap(extractPartitionTagFields).filter(f => {
727
+ if (seen$1.has(f)) {
728
+ return false;
729
+ } else {
730
+ seen$1.add(f);
731
+ return true;
732
+ }
733
+ });
734
+ if (hasComposite && allPartitionFields.length !== 0) {
735
+ Stdlib_JsError.throwWithMessage(`DCB spec mixes @compositePartitionTag and @partitionTag — use one strategy per schema`);
736
+ }
737
+ if (hasComposite) {
738
+ if (allCompositeFields.length < 2) {
739
+ Stdlib_JsError.throwWithMessage(`@compositePartitionTag requires at least 2 annotated fields — only ` + allCompositeFields.length.toString() + ` found`);
740
+ }
741
+ let sorted = allCompositeFields.toSorted((a, b) => Primitive_int.compare(a.position, b.position));
742
+ let keys = sorted.map(info => info.name);
743
+ let seps = sorted.slice(0, sorted.length - 1 | 0).map(info => info.sep);
744
+ return {
745
+ TAG: "Composite",
746
+ _0: {
747
+ keys: keys,
748
+ seps: seps
749
+ }
750
+ };
751
+ }
752
+ let seen$2 = new Set();
753
+ let allTaggedFields = schemas.flatMap(extractTaggedFields).filter(f => {
754
+ if (seen$2.has(f)) {
755
+ return false;
756
+ } else {
757
+ seen$2.add(f);
758
+ return true;
759
+ }
760
+ });
761
+ let len = allTaggedFields.length;
762
+ if (len !== 1) {
763
+ if (len === 0) {
764
+ return Stdlib_JsError.throwWithMessage("DCB spec has no tagged fields — cannot derive partition tag");
765
+ }
766
+ let needsExplicitPartition = schemas.some(hasMultiTagVariant);
767
+ if (needsExplicitPartition) {
768
+ let context = Stdlib_Array.filterMap(namedSchemas, param => {
769
+ let variantNames = findMultiTagVariantNames(param[2]);
770
+ if (variantNames.length !== 0) {
771
+ return param[0] + ` (` + variantNames.join(", ") + `) @ ` + param[1];
772
+ }
773
+ }).join(", ");
774
+ let len$1 = allPartitionFields.length;
775
+ if (len$1 !== 1) {
776
+ if (len$1 !== 0) {
777
+ return Stdlib_JsError.throwWithMessage(`DCB spec has multiple fields annotated with @partitionTag (` + allPartitionFields.join(", ") + `) — only one is allowed — affected: ` + context);
778
+ } else {
779
+ return Stdlib_JsError.throwWithMessage(`DCB spec has variants with multiple tagged fields (` + allTaggedFields.join(", ") + `) but none is annotated with @partitionTag — affected: ` + context + ` — mark one field as the partition key`);
780
+ }
781
+ }
782
+ let singlePartition = allPartitionFields[0];
783
+ return {
784
+ TAG: "Simple",
785
+ _0: {
786
+ key: singlePartition
787
+ }
788
+ };
789
+ }
790
+ let sorted$1 = allTaggedFields.toSorted(Primitive_string.compare);
791
+ return {
792
+ TAG: "Simple",
793
+ _0: {
794
+ key: sorted$1[0]
795
+ }
796
+ };
797
+ }
798
+ let singleField = allTaggedFields[0];
799
+ return {
800
+ TAG: "Simple",
801
+ _0: {
802
+ key: singleField
803
+ }
804
+ };
805
+ }
806
+
807
+ function getPartitionTagValue(query, pt) {
808
+ return Stdlib_Array.filterMap(query, queryItem => {
809
+ let tags = queryItem.tags;
810
+ if (tags !== undefined) {
811
+ return Stdlib_Array.findMap(tags, tag => {
812
+ if (tag.key === pt.key) {
813
+ return tag.value;
814
+ }
815
+ });
816
+ }
817
+ })[0];
818
+ }
819
+
820
+ export {
821
+ tagSchema,
822
+ dcbTagId,
823
+ dcbPartitionTagId,
824
+ dcbCrossPartitionId,
825
+ dcbCompositePartitionMemberId,
826
+ dcbTagKeyOverrideId,
827
+ string,
828
+ stringForKey,
829
+ int,
830
+ partition,
831
+ crossPartition,
832
+ compositePartitionMember,
833
+ isCompositePartitionMember,
834
+ isTagged,
835
+ isTaggedArray,
836
+ isPartitionTag,
837
+ isCrossPartitionTag,
838
+ isCrossPartitionTaggedArray,
839
+ resolveTagKey,
840
+ resolveArrayTagKey,
841
+ jsonValueToString,
842
+ extractTagsFromProperties,
843
+ extractTagsFromJson,
844
+ extractTags,
845
+ extractVariantNames,
846
+ extractAllVariantNames,
847
+ isVariantPayloadBearing,
848
+ extractTagsFromPropertiesExpanded,
849
+ extractTagsFromJsonExpanded,
850
+ extractTagsExpanded,
851
+ hasTaggedArrayFields,
852
+ tagKeysOfProperties,
853
+ extractTagKeysByEventType,
854
+ mergeTagKeysByEventType,
855
+ narrowEventTypesForTags,
856
+ buildQueryFromCommand,
857
+ extractTaggedFields,
858
+ crossPartitionKeysOfProperties,
859
+ extractCrossPartitionTagKeys,
860
+ extractPartitionTagFields,
861
+ hasMultiTagVariant,
862
+ findMultiTagVariantNames,
863
+ extractCompositePartitionFieldsFromProperties,
864
+ extractCompositePartitionFields,
865
+ getCompositePartitionKeyValue,
866
+ derivePartitionTag,
867
+ getPartitionTagValue,
868
+ }
869
+ /* tagSchema Not a pure module */