@reventlessdev/reventless-spec 3.0.0-alpha.128 → 3.0.0-alpha.130

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.
@@ -8,6 +8,7 @@ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
8
8
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
9
9
  import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
10
10
  import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
11
+ import * as Semantic$Reventless from "../semantic/Semantic.res.mjs";
11
12
  import * as Util_Sury$Reventless from "../util/Util_Sury.res.mjs";
12
13
  import * as DcbScopeInference$Reventless from "./DcbScopeInference.res.mjs";
13
14
 
@@ -86,6 +87,62 @@ function isTaggedArray(fieldSchema) {
86
87
  }
87
88
  }
88
89
 
90
+ function nestedRecordProperties(fieldSchema) {
91
+ let unwrapped = Stdlib_Option.getOr(Semantic$Reventless.unwrapOptional(fieldSchema), fieldSchema);
92
+ let match;
93
+ if (unwrapped.type === "array") {
94
+ let item = unwrapped.additionalItems;
95
+ match = item === "strip" || item === "strict" ? [
96
+ unwrapped,
97
+ false
98
+ ] : [
99
+ Stdlib_Option.getOr(Semantic$Reventless.unwrapOptional(item), item),
100
+ true
101
+ ];
102
+ } else {
103
+ match = [
104
+ unwrapped,
105
+ false
106
+ ];
107
+ }
108
+ let candidate = match[0];
109
+ if (candidate.type === "object") {
110
+ return [
111
+ candidate.properties,
112
+ match[1]
113
+ ];
114
+ }
115
+ }
116
+
117
+ function propertiesCarryTags(properties) {
118
+ return Object.entries(properties).some(param => {
119
+ let s = param[1];
120
+ if (Stdlib_Option.isSome(Sury.$Metadata_get(s, dcbTagId))) {
121
+ return true;
122
+ } else {
123
+ return isTaggedArray(s);
124
+ }
125
+ });
126
+ }
127
+
128
+ function isTaggedRecordArray(fieldSchema) {
129
+ let match = nestedRecordProperties(fieldSchema);
130
+ if (match !== undefined && match[1]) {
131
+ return propertiesCarryTags(match[0]);
132
+ } else {
133
+ return false;
134
+ }
135
+ }
136
+
137
+ function hasNestedTags(fieldSchema) {
138
+ let match = nestedRecordProperties(fieldSchema);
139
+ if (match !== undefined) {
140
+ return propertiesCarryTags(match[0]);
141
+ } else {
142
+ return false;
143
+ }
144
+ }
145
+
89
146
  function isPartitionTag(fieldSchema) {
90
147
  return Stdlib_Option.isSome(Sury.$Metadata_get(fieldSchema, dcbPartitionTagId));
91
148
  }
@@ -139,17 +196,102 @@ function jsonValueToString(json) {
139
196
  }
140
197
  }
141
198
 
199
+ function dedupeTags(tags) {
200
+ let seen = new Set();
201
+ return tags.filter(param => {
202
+ let identity = JSON.stringify(param.key) + param.value;
203
+ if (seen.has(identity)) {
204
+ return false;
205
+ } else {
206
+ seen.add(identity);
207
+ return true;
208
+ }
209
+ });
210
+ }
211
+
212
+ function flatFieldTagsExpanded(fieldName, fieldSchema, jsonDict) {
213
+ if (Stdlib_Option.isSome(Sury.$Metadata_get(fieldSchema, dcbTagId))) {
214
+ let jsonValue = jsonDict[fieldName];
215
+ if (jsonValue !== undefined) {
216
+ return [{
217
+ key: resolveTagKey(fieldName, fieldSchema),
218
+ value: jsonValueToString(jsonValue)
219
+ }];
220
+ } else {
221
+ return [];
222
+ }
223
+ }
224
+ if (!isTaggedArray(fieldSchema)) {
225
+ return [];
226
+ }
227
+ let match = jsonDict[fieldName];
228
+ if (match === undefined) {
229
+ return [];
230
+ }
231
+ if (!Array.isArray(match)) {
232
+ return [];
233
+ }
234
+ let tagKey = resolveArrayTagKey(fieldName, fieldSchema);
235
+ return match.map(element => ({
236
+ key: tagKey,
237
+ value: jsonValueToString(element)
238
+ }));
239
+ }
240
+
241
+ function flatTagsExpanded(properties, jsonDict) {
242
+ return Object.entries(properties).flatMap(param => flatFieldTagsExpanded(param[0], param[1], jsonDict));
243
+ }
244
+
245
+ function nestedRecordTags(fieldSchema, jsonValue) {
246
+ let match = nestedRecordProperties(fieldSchema);
247
+ if (match === undefined) {
248
+ return [];
249
+ }
250
+ let properties = match[0];
251
+ let ofObject = json => {
252
+ let elementDict = Stdlib_JSON.Decode.object(json);
253
+ if (elementDict !== undefined) {
254
+ return flatTagsExpanded(properties, elementDict);
255
+ } else {
256
+ return [];
257
+ }
258
+ };
259
+ if (match[1]) {
260
+ if (Array.isArray(jsonValue)) {
261
+ return jsonValue.flatMap(ofObject);
262
+ } else {
263
+ return [];
264
+ }
265
+ } else {
266
+ return ofObject(jsonValue);
267
+ }
268
+ }
269
+
142
270
  function extractTagsFromProperties(properties, jsonDict) {
143
- return Stdlib_Array.filterMap(Object.entries(properties), param => {
271
+ return dedupeTags(Object.entries(properties).flatMap(param => {
144
272
  let fieldSchema = param[1];
145
273
  let fieldName = param[0];
146
274
  if (Stdlib_Option.isSome(Sury.$Metadata_get(fieldSchema, dcbTagId))) {
147
- return Stdlib_Option.map(jsonDict[fieldName], jsonValue => ({
148
- key: resolveTagKey(fieldName, fieldSchema),
149
- value: jsonValueToString(jsonValue)
150
- }));
275
+ let jsonValue = jsonDict[fieldName];
276
+ if (jsonValue !== undefined) {
277
+ return [{
278
+ key: resolveTagKey(fieldName, fieldSchema),
279
+ value: jsonValueToString(jsonValue)
280
+ }];
281
+ } else {
282
+ return [];
283
+ }
151
284
  }
152
- });
285
+ if (!hasNestedTags(fieldSchema)) {
286
+ return [];
287
+ }
288
+ let jsonValue$1 = jsonDict[fieldName];
289
+ if (jsonValue$1 !== undefined) {
290
+ return nestedRecordTags(fieldSchema, jsonValue$1);
291
+ } else {
292
+ return [];
293
+ }
294
+ }));
153
295
  }
154
296
 
155
297
  function variantTagName(properties) {
@@ -275,36 +417,22 @@ function isVariantPayloadBearing(schema, name) {
275
417
  }
276
418
 
277
419
  function extractTagsFromPropertiesExpanded(properties, jsonDict) {
278
- return Object.entries(properties).flatMap(param => {
420
+ return dedupeTags(Object.entries(properties).flatMap(param => {
279
421
  let fieldSchema = param[1];
280
422
  let fieldName = param[0];
281
- if (Stdlib_Option.isSome(Sury.$Metadata_get(fieldSchema, dcbTagId))) {
282
- let jsonValue = jsonDict[fieldName];
283
- if (jsonValue !== undefined) {
284
- return [{
285
- key: resolveTagKey(fieldName, fieldSchema),
286
- value: jsonValueToString(jsonValue)
287
- }];
288
- } else {
289
- return [];
290
- }
291
- }
292
- if (!isTaggedArray(fieldSchema)) {
293
- return [];
423
+ if (Stdlib_Option.isSome(Sury.$Metadata_get(fieldSchema, dcbTagId)) || isTaggedArray(fieldSchema)) {
424
+ return flatFieldTagsExpanded(fieldName, fieldSchema, jsonDict);
294
425
  }
295
- let match = jsonDict[fieldName];
296
- if (match === undefined) {
426
+ if (!hasNestedTags(fieldSchema)) {
297
427
  return [];
298
428
  }
299
- if (!Array.isArray(match)) {
429
+ let jsonValue = jsonDict[fieldName];
430
+ if (jsonValue !== undefined) {
431
+ return nestedRecordTags(fieldSchema, jsonValue);
432
+ } else {
300
433
  return [];
301
434
  }
302
- let tagKey = resolveArrayTagKey(fieldName, fieldSchema);
303
- return match.map(element => ({
304
- key: tagKey,
305
- value: jsonValueToString(element)
306
- }));
307
- });
435
+ }));
308
436
  }
309
437
 
310
438
  function extractTagsFromJsonExpanded(schema, json) {
@@ -352,11 +480,25 @@ function extractTagsExpanded(schema, value) {
352
480
  function hasTaggedArrayFields(schema) {
353
481
  switch (schema.type) {
354
482
  case "object" :
355
- return Object.entries(schema.properties).some(param => isTaggedArray(param[1]));
483
+ return Object.entries(schema.properties).some(param => {
484
+ let fieldSchema = param[1];
485
+ if (isTaggedArray(fieldSchema)) {
486
+ return true;
487
+ } else {
488
+ return isTaggedRecordArray(fieldSchema);
489
+ }
490
+ });
356
491
  case "anyOf" :
357
492
  return schema.anyOf.some(variantSchema => {
358
493
  if (variantSchema.type === "object") {
359
- return Object.entries(variantSchema.properties).some(param => isTaggedArray(param[1]));
494
+ return Object.entries(variantSchema.properties).some(param => {
495
+ let fieldSchema = param[1];
496
+ if (isTaggedArray(fieldSchema)) {
497
+ return true;
498
+ } else {
499
+ return isTaggedRecordArray(fieldSchema);
500
+ }
501
+ });
360
502
  } else {
361
503
  return false;
362
504
  }
@@ -366,7 +508,7 @@ function hasTaggedArrayFields(schema) {
366
508
  }
367
509
  }
368
510
 
369
- function tagKeysOfProperties(properties) {
511
+ function flatTagKeysOfProperties(properties) {
370
512
  return Stdlib_Array.filterMap(Object.entries(properties), param => {
371
513
  let fieldSchema = param[1];
372
514
  let fieldName = param[0];
@@ -380,6 +522,25 @@ function tagKeysOfProperties(properties) {
380
522
  });
381
523
  }
382
524
 
525
+ function tagKeysOfProperties(properties) {
526
+ return Object.entries(properties).flatMap(param => {
527
+ let fieldSchema = param[1];
528
+ let fieldName = param[0];
529
+ if (Stdlib_Option.isSome(Sury.$Metadata_get(fieldSchema, dcbTagId))) {
530
+ return [resolveTagKey(fieldName, fieldSchema)];
531
+ }
532
+ if (isTaggedArray(fieldSchema)) {
533
+ return [resolveArrayTagKey(fieldName, fieldSchema)];
534
+ }
535
+ let match = nestedRecordProperties(fieldSchema);
536
+ if (match !== undefined) {
537
+ return flatTagKeysOfProperties(match[0]);
538
+ } else {
539
+ return [];
540
+ }
541
+ });
542
+ }
543
+
383
544
  function extractTagKeysByEventType(schema) {
384
545
  let result = {};
385
546
  let addVariant = variantSchema => {
@@ -530,17 +691,38 @@ function extractCrossPartitionTagKeys(schema) {
530
691
  }
531
692
 
532
693
  function idFieldsOfProperties(properties) {
533
- return Stdlib_Array.filterMap(Object.entries(properties), param => {
694
+ let isIdName = name => {
695
+ if (name.endsWith("Ids")) {
696
+ return true;
697
+ } else {
698
+ return name.endsWith("Id");
699
+ }
700
+ };
701
+ return Object.entries(properties).flatMap(param => {
702
+ let fieldSchema = param[1];
534
703
  let name = param[0];
535
- if (!(name.endsWith("Ids") || name.endsWith("Id"))) {
536
- return;
704
+ if (isIdName(name)) {
705
+ let isList;
706
+ isList = fieldSchema.type === "array";
707
+ return [{
708
+ name: name,
709
+ isList: isList
710
+ }];
537
711
  }
538
- let isList;
539
- isList = param[1].type === "array";
540
- return {
541
- name: name,
542
- isList: isList
543
- };
712
+ let match = nestedRecordProperties(fieldSchema);
713
+ if (match === undefined) {
714
+ return [];
715
+ }
716
+ let nestedIsList = match[1];
717
+ return Stdlib_Array.filterMap(Object.entries(match[0]), param => {
718
+ let nestedName = param[0];
719
+ if (isIdName(nestedName)) {
720
+ return {
721
+ name: nestedName,
722
+ isList: nestedIsList
723
+ };
724
+ }
725
+ });
544
726
  });
545
727
  }
546
728
 
@@ -862,12 +1044,20 @@ export {
862
1044
  derivedPartitionTagSchema,
863
1045
  isTagged,
864
1046
  isTaggedArray,
1047
+ nestedRecordProperties,
1048
+ propertiesCarryTags,
1049
+ isTaggedRecordArray,
1050
+ hasNestedTags,
865
1051
  isPartitionTag,
866
1052
  isCrossPartitionTag,
867
1053
  isCrossPartitionTaggedArray,
868
1054
  resolveTagKey,
869
1055
  resolveArrayTagKey,
870
1056
  jsonValueToString,
1057
+ dedupeTags,
1058
+ flatFieldTagsExpanded,
1059
+ flatTagsExpanded,
1060
+ nestedRecordTags,
871
1061
  extractTagsFromProperties,
872
1062
  variantTagName,
873
1063
  extractTagsFromJson,
@@ -879,6 +1069,7 @@ export {
879
1069
  extractTagsFromJsonExpanded,
880
1070
  extractTagsExpanded,
881
1071
  hasTaggedArrayFields,
1072
+ flatTagKeysOfProperties,
882
1073
  tagKeysOfProperties,
883
1074
  extractTagKeysByEventType,
884
1075
  mergeTagKeysByEventType,