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