@revisium/schema-toolkit 0.2.0

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +184 -0
  3. package/dist/consts/index.cjs +26 -0
  4. package/dist/consts/index.cjs.map +1 -0
  5. package/dist/consts/index.d.cts +17 -0
  6. package/dist/consts/index.d.ts +17 -0
  7. package/dist/consts/index.js +23 -0
  8. package/dist/consts/index.js.map +1 -0
  9. package/dist/index.cjs +1874 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +13 -0
  12. package/dist/index.d.ts +13 -0
  13. package/dist/index.js +1787 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/json-patch.types-DiJBqfxV.d.ts +28 -0
  16. package/dist/json-patch.types-lByaF-OL.d.cts +28 -0
  17. package/dist/json-string.store-O1J0j-a1.d.cts +228 -0
  18. package/dist/json-string.store-S9FXT39Q.d.ts +228 -0
  19. package/dist/json.types-46Cq-WxU.d.cts +8 -0
  20. package/dist/json.types-46Cq-WxU.d.ts +8 -0
  21. package/dist/lib/index.cjs +1346 -0
  22. package/dist/lib/index.cjs.map +1 -0
  23. package/dist/lib/index.d.cts +91 -0
  24. package/dist/lib/index.d.ts +91 -0
  25. package/dist/lib/index.js +1315 -0
  26. package/dist/lib/index.js.map +1 -0
  27. package/dist/mocks/index.cjs +92 -0
  28. package/dist/mocks/index.cjs.map +1 -0
  29. package/dist/mocks/index.d.cts +26 -0
  30. package/dist/mocks/index.d.ts +26 -0
  31. package/dist/mocks/index.js +81 -0
  32. package/dist/mocks/index.js.map +1 -0
  33. package/dist/model/index.cjs +718 -0
  34. package/dist/model/index.cjs.map +1 -0
  35. package/dist/model/index.d.cts +19 -0
  36. package/dist/model/index.d.ts +19 -0
  37. package/dist/model/index.js +697 -0
  38. package/dist/model/index.js.map +1 -0
  39. package/dist/plugins/index.cjs +122 -0
  40. package/dist/plugins/index.cjs.map +1 -0
  41. package/dist/plugins/index.d.cts +21 -0
  42. package/dist/plugins/index.d.ts +21 -0
  43. package/dist/plugins/index.js +112 -0
  44. package/dist/plugins/index.js.map +1 -0
  45. package/dist/schema.types-Q3MYTp8z.d.cts +68 -0
  46. package/dist/schema.types-Q3MYTp8z.d.ts +68 -0
  47. package/dist/types/index.cjs +15 -0
  48. package/dist/types/index.cjs.map +1 -0
  49. package/dist/types/index.d.cts +56 -0
  50. package/dist/types/index.d.ts +56 -0
  51. package/dist/types/index.js +13 -0
  52. package/dist/types/index.js.map +1 -0
  53. package/dist/validation-schemas/index.cjs +380 -0
  54. package/dist/validation-schemas/index.cjs.map +1 -0
  55. package/dist/validation-schemas/index.d.cts +32 -0
  56. package/dist/validation-schemas/index.d.ts +32 -0
  57. package/dist/validation-schemas/index.js +365 -0
  58. package/dist/validation-schemas/index.js.map +1 -0
  59. package/package.json +169 -0
@@ -0,0 +1,697 @@
1
+ import { nanoid } from 'nanoid';
2
+ import { EventEmitter } from 'events';
3
+
4
+ // src/model/schema/json-string.store.ts
5
+
6
+ // src/lib/addSharedFieldsFromStore.ts
7
+ var addSharedFieldsFromState = (schema, state) => {
8
+ if (state.title) {
9
+ schema.title = state.title;
10
+ }
11
+ if (state.description) {
12
+ schema.description = state.description;
13
+ }
14
+ if (state.deprecated) {
15
+ schema.deprecated = state.deprecated;
16
+ }
17
+ return schema;
18
+ };
19
+
20
+ // src/model/schema/json-string.store.ts
21
+ var JsonStringStore = class extends EventEmitter {
22
+ constructor(nodeId = nanoid()) {
23
+ super();
24
+ this.nodeId = nodeId;
25
+ }
26
+ type = "string" /* String */;
27
+ $ref = "";
28
+ name = "";
29
+ parent = null;
30
+ default = "";
31
+ readOnly;
32
+ title;
33
+ description;
34
+ deprecated;
35
+ foreignKey;
36
+ pattern;
37
+ enum;
38
+ format;
39
+ contentMediaType;
40
+ valuesMap = /* @__PURE__ */ new Map();
41
+ registerValue(value) {
42
+ const length = this.getOrCreateValues(value.rowId).push(value);
43
+ return length - 1;
44
+ }
45
+ getValue(rowId, index = 0) {
46
+ return this.getOrCreateValues(rowId)[index];
47
+ }
48
+ getPlainSchema(options) {
49
+ if (this.$ref && options?.skip$Ref !== true) {
50
+ return addSharedFieldsFromState({ $ref: this.$ref }, this);
51
+ }
52
+ return addSharedFieldsFromState(
53
+ {
54
+ type: this.type,
55
+ default: this.default,
56
+ ...this.foreignKey ? { foreignKey: this.foreignKey } : {},
57
+ ...this.readOnly ? { readOnly: this.readOnly } : {},
58
+ ...this.pattern ? { pattern: this.pattern } : {},
59
+ ...this.enum ? { enum: this.enum } : {},
60
+ ...this.format ? { format: this.format } : {},
61
+ ...this.contentMediaType ? { contentMediaType: this.contentMediaType } : {}
62
+ },
63
+ this
64
+ );
65
+ }
66
+ getOrCreateValues(rowId) {
67
+ let values = this.valuesMap.get(rowId);
68
+ if (!values) {
69
+ values = [];
70
+ this.valuesMap.set(rowId, values);
71
+ }
72
+ return values;
73
+ }
74
+ };
75
+ var JsonNumberStore = class extends EventEmitter {
76
+ constructor(nodeId = nanoid()) {
77
+ super();
78
+ this.nodeId = nodeId;
79
+ }
80
+ type = "number" /* Number */;
81
+ $ref = "";
82
+ name = "";
83
+ parent = null;
84
+ default = 0;
85
+ readOnly;
86
+ title;
87
+ description;
88
+ deprecated;
89
+ valuesMap = /* @__PURE__ */ new Map();
90
+ registerValue(value) {
91
+ const length = this.getOrCreateValues(value.rowId).push(value);
92
+ return length - 1;
93
+ }
94
+ getValue(rowId, index = 0) {
95
+ return this.getOrCreateValues(rowId)[index];
96
+ }
97
+ getPlainSchema(options) {
98
+ if (this.$ref && options?.skip$Ref !== true) {
99
+ return addSharedFieldsFromState({ $ref: this.$ref }, this);
100
+ }
101
+ return addSharedFieldsFromState(
102
+ {
103
+ type: this.type,
104
+ default: this.default,
105
+ ...this.readOnly ? { readOnly: this.readOnly } : {}
106
+ },
107
+ this
108
+ );
109
+ }
110
+ getOrCreateValues(rowId) {
111
+ let values = this.valuesMap.get(rowId);
112
+ if (!values) {
113
+ values = [];
114
+ this.valuesMap.set(rowId, values);
115
+ }
116
+ return values;
117
+ }
118
+ };
119
+ var JsonBooleanStore = class extends EventEmitter {
120
+ constructor(nodeId = nanoid()) {
121
+ super();
122
+ this.nodeId = nodeId;
123
+ }
124
+ type = "boolean" /* Boolean */;
125
+ $ref = "";
126
+ name = "";
127
+ parent = null;
128
+ default = false;
129
+ readOnly;
130
+ title;
131
+ description;
132
+ deprecated;
133
+ valuesMap = /* @__PURE__ */ new Map();
134
+ registerValue(value) {
135
+ const length = this.getOrCreateValues(value.rowId).push(value);
136
+ return length - 1;
137
+ }
138
+ getValue(rowId, index = 0) {
139
+ return this.getOrCreateValues(rowId)[index];
140
+ }
141
+ getPlainSchema(options) {
142
+ if (this.$ref && options?.skip$Ref !== true) {
143
+ return addSharedFieldsFromState({ $ref: this.$ref }, this);
144
+ }
145
+ return addSharedFieldsFromState(
146
+ {
147
+ type: this.type,
148
+ default: this.default,
149
+ ...this.readOnly ? { readOnly: this.readOnly } : {}
150
+ },
151
+ this
152
+ );
153
+ }
154
+ getOrCreateValues(rowId) {
155
+ let values = this.valuesMap.get(rowId);
156
+ if (!values) {
157
+ values = [];
158
+ this.valuesMap.set(rowId, values);
159
+ }
160
+ return values;
161
+ }
162
+ };
163
+ var JsonObjectStore = class {
164
+ constructor(nodeId = nanoid()) {
165
+ this.nodeId = nodeId;
166
+ }
167
+ type = "object" /* Object */;
168
+ $ref = "";
169
+ name = "";
170
+ parent = null;
171
+ default = {};
172
+ title;
173
+ description;
174
+ deprecated;
175
+ additionalProperties = false;
176
+ required = [];
177
+ properties = {};
178
+ valuesMap = /* @__PURE__ */ new Map();
179
+ get empty() {
180
+ return Object.keys(this.properties).length === 0;
181
+ }
182
+ registerValue(value) {
183
+ const length = this.getOrCreateValues(value.rowId).push(value);
184
+ return length - 1;
185
+ }
186
+ getValue(rowId, index = 0) {
187
+ return this.getOrCreateValues(rowId)[index];
188
+ }
189
+ addPropertyWithStore(name, store) {
190
+ if (this.properties[name] || this.required.includes(name)) {
191
+ throw new Error("this name already exists");
192
+ }
193
+ store.parent = this;
194
+ store.name = name;
195
+ this.required.push(name);
196
+ this.required.sort((a, b) => a.localeCompare(b));
197
+ this.properties[name] = store;
198
+ this.default[name] = store.default;
199
+ const event = { name, property: store };
200
+ for (const value of this.iterValues()) {
201
+ value.addProperty(event);
202
+ }
203
+ return store;
204
+ }
205
+ migratePropertyWithStore(name, store) {
206
+ const item = this.properties[name];
207
+ if (!item) {
208
+ throw new Error("this name does not exist");
209
+ }
210
+ item.parent = null;
211
+ store.parent = this;
212
+ store.name = name;
213
+ this.properties[name] = store;
214
+ this.default[name] = store.default;
215
+ const event = {
216
+ name,
217
+ property: store,
218
+ previousProperty: item
219
+ };
220
+ for (const value of this.iterValues()) {
221
+ value.migrateProperty(event);
222
+ }
223
+ return store;
224
+ }
225
+ changeName(fromName, toName) {
226
+ const item = this.properties[fromName];
227
+ if (!item) {
228
+ throw new Error("this fromName does not exist");
229
+ }
230
+ delete this.properties[fromName];
231
+ delete this.default[fromName];
232
+ const foundRequiredIndex = this.required.findIndex(
233
+ (required) => required === fromName
234
+ );
235
+ if (foundRequiredIndex !== -1) {
236
+ this.required.splice(foundRequiredIndex, 1);
237
+ }
238
+ if (!this.required.includes(toName)) {
239
+ this.required.push(toName);
240
+ this.required.sort((a, b) => a.localeCompare(b));
241
+ }
242
+ this.properties[toName] = item;
243
+ this.default[toName] = item.default;
244
+ const event = {
245
+ fromName,
246
+ toName,
247
+ property: item
248
+ };
249
+ for (const value of this.iterValues()) {
250
+ value.changeName(event);
251
+ }
252
+ }
253
+ removeProperty(name) {
254
+ const item = this.properties[name];
255
+ if (!item) {
256
+ throw new Error("this name does not exist");
257
+ }
258
+ item.parent = null;
259
+ item.name = "";
260
+ delete this.properties[name];
261
+ delete this.default[name];
262
+ const foundRequiredIndex = this.required.findIndex(
263
+ (required) => required === name
264
+ );
265
+ if (foundRequiredIndex !== -1) {
266
+ this.required.splice(foundRequiredIndex, 1);
267
+ }
268
+ const event = {
269
+ name,
270
+ property: item
271
+ };
272
+ for (const value of this.iterValues()) {
273
+ value.removeProperty(event);
274
+ }
275
+ }
276
+ getProperty(name) {
277
+ return this.properties[name];
278
+ }
279
+ getPlainSchema(options) {
280
+ if (this.$ref && options?.skip$Ref !== true) {
281
+ return addSharedFieldsFromState({ $ref: this.$ref }, this);
282
+ }
283
+ return addSharedFieldsFromState(
284
+ {
285
+ type: this.type,
286
+ additionalProperties: this.additionalProperties,
287
+ required: this.required,
288
+ properties: Object.entries(this.properties).reduce((result, [name, store]) => {
289
+ result[name] = store.getPlainSchema(options);
290
+ return result;
291
+ }, {})
292
+ },
293
+ this
294
+ );
295
+ }
296
+ getOrCreateValues(rowId) {
297
+ let values = this.valuesMap.get(rowId);
298
+ if (!values) {
299
+ values = [];
300
+ this.valuesMap.set(rowId, values);
301
+ }
302
+ return values;
303
+ }
304
+ *iterValues() {
305
+ for (const values of this.valuesMap.values()) {
306
+ for (const value of values) {
307
+ yield value;
308
+ }
309
+ }
310
+ }
311
+ };
312
+ var JsonArrayStore = class {
313
+ constructor(_items, nodeId = nanoid()) {
314
+ this._items = _items;
315
+ this.nodeId = nodeId;
316
+ this.items.parent = this;
317
+ }
318
+ type = "array" /* Array */;
319
+ $ref = "";
320
+ name = "";
321
+ parent = null;
322
+ default = [];
323
+ title;
324
+ description;
325
+ deprecated;
326
+ valuesMap = /* @__PURE__ */ new Map();
327
+ get items() {
328
+ return this._items;
329
+ }
330
+ registerValue(value) {
331
+ const length = this.getOrCreateValues(value.rowId).push(value);
332
+ return length - 1;
333
+ }
334
+ getValue(rowId, index = 0) {
335
+ return this.getOrCreateValues(rowId)[index];
336
+ }
337
+ migrateItems(items) {
338
+ const previousItems = this._items;
339
+ previousItems.parent = null;
340
+ this._items = items;
341
+ this._items.parent = this;
342
+ const event = { items, previousItems };
343
+ for (const value of this.iterValues()) {
344
+ value.migrateItems(event);
345
+ }
346
+ }
347
+ replaceItems(items) {
348
+ const previousItems = this._items;
349
+ previousItems.parent = null;
350
+ this._items = items;
351
+ this._items.parent = this;
352
+ const event = { items, previousItems };
353
+ for (const value of this.iterValues()) {
354
+ value.replaceItems(event);
355
+ }
356
+ }
357
+ getPlainSchema(options) {
358
+ if (this.$ref && options?.skip$Ref !== true) {
359
+ return addSharedFieldsFromState({ $ref: this.$ref }, this);
360
+ }
361
+ return addSharedFieldsFromState(
362
+ {
363
+ type: this.type,
364
+ items: this.items.getPlainSchema(options)
365
+ },
366
+ this
367
+ );
368
+ }
369
+ getOrCreateValues(rowId) {
370
+ let values = this.valuesMap.get(rowId);
371
+ if (!values) {
372
+ values = [];
373
+ this.valuesMap.set(rowId, values);
374
+ }
375
+ return values;
376
+ }
377
+ *iterValues() {
378
+ for (const values of this.valuesMap.values()) {
379
+ for (const value of values) {
380
+ yield value;
381
+ }
382
+ }
383
+ }
384
+ };
385
+
386
+ // src/model/value/json-string-value.store.ts
387
+ var JsonStringValueStore = class {
388
+ constructor(schema, rowId, value = null) {
389
+ this.schema = schema;
390
+ this.rowId = rowId;
391
+ this.value = value;
392
+ this.index = this.schema.registerValue(this);
393
+ }
394
+ type = "string" /* String */;
395
+ index;
396
+ parent = null;
397
+ get foreignKey() {
398
+ return this.schema.foreignKey;
399
+ }
400
+ getPlainValue() {
401
+ return this.value ?? this.schema.default;
402
+ }
403
+ };
404
+
405
+ // src/model/value/json-number-value.store.ts
406
+ var JsonNumberValueStore = class {
407
+ constructor(schema, rowId, value = null) {
408
+ this.schema = schema;
409
+ this.rowId = rowId;
410
+ this.value = value;
411
+ this.index = this.schema.registerValue(this);
412
+ }
413
+ type = "number" /* Number */;
414
+ index;
415
+ parent = null;
416
+ getPlainValue() {
417
+ return this.value ?? this.schema.default;
418
+ }
419
+ };
420
+
421
+ // src/model/value/json-boolean-value.store.ts
422
+ var JsonBooleanValueStore = class {
423
+ constructor(schema, rowId, value = null) {
424
+ this.schema = schema;
425
+ this.rowId = rowId;
426
+ this.value = value;
427
+ this.index = this.schema.registerValue(this);
428
+ }
429
+ type = "boolean" /* Boolean */;
430
+ index;
431
+ parent = null;
432
+ getPlainValue() {
433
+ return this.value ?? this.schema.default;
434
+ }
435
+ };
436
+
437
+ // src/model/value/value-transformation.ts
438
+ var equel = (value) => value;
439
+ var fromNumberToString = (value, defaultValue = "") => value.toString() || defaultValue;
440
+ var fromBooleanToString = (value, defaultValue = "") => value.toString() || defaultValue;
441
+ var fromStringToBoolean = (value, defaultValue = false) => {
442
+ if (!value) {
443
+ return defaultValue;
444
+ }
445
+ if (value.toLowerCase() === "false") {
446
+ return false;
447
+ }
448
+ return true;
449
+ };
450
+ var fromStringToNumber = (value, defaultValue = 0) => {
451
+ const number = Number.parseFloat(value);
452
+ if (Number.isNaN(number)) {
453
+ return defaultValue;
454
+ }
455
+ return number;
456
+ };
457
+ var fromBooleanToNumber = (value) => {
458
+ return Number(value);
459
+ };
460
+ var fromNumberToBoolean = (value) => {
461
+ return Boolean(value);
462
+ };
463
+ var toArrayTransformation = (transformation) => (value) => {
464
+ const result = transformation(value);
465
+ return [result];
466
+ };
467
+ var fromArrayTransformation = (transformation) => (value) => {
468
+ if (Array.isArray(value) && value.length) {
469
+ return transformation(value[0]);
470
+ }
471
+ return void 0;
472
+ };
473
+ var replaceTransformationsMapper = [
474
+ {
475
+ fromType: "number" /* Number */,
476
+ toType: "string" /* String */,
477
+ transformation: fromNumberToString
478
+ },
479
+ {
480
+ fromType: "string" /* String */,
481
+ toType: "number" /* Number */,
482
+ transformation: fromStringToNumber
483
+ },
484
+ {
485
+ fromType: "boolean" /* Boolean */,
486
+ toType: "string" /* String */,
487
+ transformation: fromBooleanToString
488
+ },
489
+ {
490
+ fromType: "string" /* String */,
491
+ toType: "boolean" /* Boolean */,
492
+ transformation: fromStringToBoolean
493
+ },
494
+ {
495
+ fromType: "boolean" /* Boolean */,
496
+ toType: "number" /* Number */,
497
+ transformation: fromBooleanToNumber
498
+ },
499
+ {
500
+ fromType: "number" /* Number */,
501
+ toType: "boolean" /* Boolean */,
502
+ transformation: fromNumberToBoolean
503
+ }
504
+ ];
505
+ var getTransformation = (from, to) => {
506
+ if (to instanceof JsonArrayStore) {
507
+ const transformation = findTransformation(from.type, to.items.type);
508
+ if (!transformation) {
509
+ return;
510
+ }
511
+ return toArrayTransformation(transformation);
512
+ } else if (from instanceof JsonArrayStore) {
513
+ const transformation = findTransformation(from.items.type, to.type);
514
+ if (!transformation) {
515
+ return;
516
+ }
517
+ return fromArrayTransformation(transformation);
518
+ }
519
+ return findTransformation(from.type, to.type);
520
+ };
521
+ var findTransformation = (from, to) => {
522
+ if (from === to) {
523
+ return equel;
524
+ }
525
+ for (const item of replaceTransformationsMapper) {
526
+ if (item.fromType === from && item.toType === to) {
527
+ return item.transformation;
528
+ }
529
+ }
530
+ return void 0;
531
+ };
532
+
533
+ // src/model/value/json-array-value.store.ts
534
+ var JsonArrayValueStore = class {
535
+ constructor(schema, rowId, value) {
536
+ this.schema = schema;
537
+ this.rowId = rowId;
538
+ this.value = value;
539
+ this.index = this.schema.registerValue(this);
540
+ this.init();
541
+ }
542
+ type = "array" /* Array */;
543
+ index;
544
+ parent = null;
545
+ getPlainValue() {
546
+ return this.value.map((item) => item.getPlainValue());
547
+ }
548
+ migrateItems(event) {
549
+ const transformation = getTransformation(event.previousItems, event.items);
550
+ this.value = this.value.map((valueItem) => {
551
+ const rawValue = transformation ? transformation(
552
+ valueItem.getPlainValue(),
553
+ event.items.default
554
+ ) : event.items.default;
555
+ return createJsonValueStore(event.items, this.rowId, rawValue);
556
+ });
557
+ }
558
+ replaceItems(event) {
559
+ this.value = this.value.map(() => {
560
+ const rawValue = this.getReplacedValue(event);
561
+ return createJsonValueStore(event.items, this.rowId, rawValue);
562
+ });
563
+ }
564
+ getReplacedValue(event) {
565
+ const previousValue = event.items.getValue(this.rowId);
566
+ if (previousValue) {
567
+ return previousValue.getPlainValue();
568
+ }
569
+ return event.items.default;
570
+ }
571
+ init() {
572
+ for (const value of this.value) {
573
+ value.parent = this;
574
+ }
575
+ }
576
+ };
577
+
578
+ // src/lib/createJsonValueStore.ts
579
+ var createJsonValueStore = (schema, rowId, rawValue) => {
580
+ if (schema.type === "object" /* Object */) {
581
+ return createJsonObjectValueStore(schema, rowId, rawValue);
582
+ } else if (schema.type === "array" /* Array */) {
583
+ return createJsonArrayValueStore(schema, rowId, rawValue);
584
+ } else {
585
+ return createPrimitiveValueStore(schema, rowId, rawValue);
586
+ }
587
+ };
588
+ var createJsonObjectValueStore = (schema, rowId, rawValue) => {
589
+ const value = Object.entries(rawValue).reduce(
590
+ (reduceValue, [key, itemValue]) => {
591
+ const itemSchema = schema.getProperty(key);
592
+ if (itemSchema === void 0 || itemValue === void 0) {
593
+ throw new Error("Invalid item");
594
+ }
595
+ reduceValue[key] = createJsonValueStore(itemSchema, rowId, itemValue);
596
+ return reduceValue;
597
+ },
598
+ {}
599
+ );
600
+ return new JsonObjectValueStore(schema, rowId, value);
601
+ };
602
+ var createJsonArrayValueStore = (schema, rowId, rawValue) => {
603
+ const value = rawValue.map(
604
+ (value2) => createJsonValueStore(schema.items, rowId, value2)
605
+ );
606
+ return new JsonArrayValueStore(schema, rowId, value);
607
+ };
608
+ var createPrimitiveValueStore = (schema, rowId, rawValue) => {
609
+ if (schema.type === "string" /* String */) {
610
+ return new JsonStringValueStore(schema, rowId, rawValue);
611
+ } else if (schema.type === "number" /* Number */) {
612
+ return new JsonNumberValueStore(schema, rowId, rawValue);
613
+ } else if (schema.type === "boolean" /* Boolean */) {
614
+ return new JsonBooleanValueStore(schema, rowId, rawValue);
615
+ } else {
616
+ throw new Error("this type is not allowed");
617
+ }
618
+ };
619
+
620
+ // src/model/value/json-object-value.store.ts
621
+ var JsonObjectValueStore = class {
622
+ constructor(schema, rowId, value) {
623
+ this.schema = schema;
624
+ this.rowId = rowId;
625
+ this.value = value;
626
+ this.index = this.schema.registerValue(this);
627
+ this.init();
628
+ }
629
+ type = "object" /* Object */;
630
+ index;
631
+ parent = null;
632
+ getPlainValue() {
633
+ return Object.entries(this.value).reduce(
634
+ (result, [name, store]) => {
635
+ result[name] = store.getPlainValue();
636
+ return result;
637
+ },
638
+ {}
639
+ );
640
+ }
641
+ migrateProperty(event) {
642
+ const rawValue = this.getMigratedValue(event);
643
+ this.value[event.name] = createJsonValueStore(
644
+ event.property,
645
+ this.rowId,
646
+ rawValue
647
+ );
648
+ }
649
+ addProperty(event) {
650
+ const rawValue = this.getAddedValue(event);
651
+ this.value[event.name] = createJsonValueStore(
652
+ event.property,
653
+ this.rowId,
654
+ rawValue
655
+ );
656
+ }
657
+ removeProperty(event) {
658
+ delete this.value[event.name];
659
+ }
660
+ changeName(event) {
661
+ const itemValue = this.value[event.fromName];
662
+ if (itemValue !== void 0) {
663
+ delete this.value[event.fromName];
664
+ this.value[event.toName] = itemValue;
665
+ }
666
+ }
667
+ getAddedValue(event) {
668
+ const previousValue = event.property.getValue(this.rowId, this.index);
669
+ if (previousValue) {
670
+ return previousValue.getPlainValue();
671
+ }
672
+ return event.property.default;
673
+ }
674
+ getMigratedValue(event) {
675
+ const transformation = getTransformation(
676
+ event.previousProperty,
677
+ event.property
678
+ );
679
+ const valueStore = this.value[event.name];
680
+ if (transformation && valueStore) {
681
+ return transformation(
682
+ valueStore.getPlainValue(),
683
+ event.property.default
684
+ );
685
+ }
686
+ return event.property.default;
687
+ }
688
+ init() {
689
+ for (const value of Object.values(this.value)) {
690
+ value.parent = this;
691
+ }
692
+ }
693
+ };
694
+
695
+ export { JsonArrayStore, JsonArrayValueStore, JsonBooleanStore, JsonBooleanValueStore, JsonNumberStore, JsonNumberValueStore, JsonObjectStore, JsonObjectValueStore, JsonStringStore, JsonStringValueStore, equel, fromArrayTransformation, fromBooleanToNumber, fromBooleanToString, fromNumberToBoolean, fromNumberToString, fromStringToBoolean, fromStringToNumber, getTransformation, toArrayTransformation };
696
+ //# sourceMappingURL=index.js.map
697
+ //# sourceMappingURL=index.js.map