@rljson/rljson 0.0.55 → 0.0.58

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.
package/dist/rljson.js CHANGED
@@ -1,8 +1,17 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
1
  import { hip, hsh } from "@rljson/hash";
5
- import { exampleJsonObject, jsonValueTypes, jsonValueType, jsonValueMatchesType } from "@rljson/json";
2
+ import { exampleJsonObject, jsonValueTypes, jsonValueMatchesType, jsonValueType } from "@rljson/json";
3
+ // @license
4
+ class Route {
5
+ constructor(segments) {
6
+ this.segments = segments;
7
+ }
8
+ static fromFlat(route) {
9
+ return new Route(route.split("/").filter(Boolean));
10
+ }
11
+ get flat() {
12
+ return "/" + this.segments.join("/");
13
+ }
14
+ }
6
15
  // @license
7
16
  const bakeryExample = () => {
8
17
  const nutritionalValues = hip({
@@ -125,6 +134,33 @@ const bakeryExample = () => {
125
134
  }
126
135
  ]
127
136
  });
137
+ const ingredientsEdits = hip({
138
+ _type: "edits",
139
+ _data: [
140
+ {
141
+ value: {
142
+ name: "Flour A",
143
+ amountUnit: "g",
144
+ nutritionalValuesRef: nutritionalValues._data[0]._hash,
145
+ _hash: ""
146
+ },
147
+ route: Route.fromFlat("/ingredients/").flat,
148
+ _hash: ""
149
+ },
150
+ {
151
+ value: {
152
+ name: "Flour B",
153
+ amountUnit: "g",
154
+ nutritionalValuesRef: nutritionalValues._data[0]._hash,
155
+ _hash: ""
156
+ },
157
+ previous: "D2Rp36U1DBa69zAya-16EJ",
158
+ route: Route.fromFlat("/ingredients/").flat,
159
+ _hash: ""
160
+ }
161
+ ],
162
+ _hash: ""
163
+ });
128
164
  const result = {
129
165
  buffets,
130
166
  cakes,
@@ -134,7 +170,8 @@ const bakeryExample = () => {
134
170
  recipes,
135
171
  recipeIngredients,
136
172
  ingredients,
137
- nutritionalValues
173
+ nutritionalValues,
174
+ ingredientsEdits
138
175
  };
139
176
  return result;
140
177
  };
@@ -157,340 +194,121 @@ const exampleRevision = () => ({
157
194
  // @license
158
195
  const exampleSliceIdsTable = () => bakeryExample().slices;
159
196
  // @license
160
- const _Example = class _Example {
161
- };
162
- __publicField(_Example, "ok", {
163
- bakery: () => bakeryExample(),
164
- empty: () => {
165
- return {};
166
- },
167
- binary: () => {
168
- return {
169
- table: {
170
- _type: "components",
171
- _data: [
172
- { a: false, b: false },
173
- { a: false, b: true },
174
- { a: true, b: false },
175
- { a: true, b: true }
176
- ]
177
- }
178
- };
179
- },
180
- singleRow: () => {
181
- const tableCfgs = hip({
182
- _hash: "",
183
- _type: "tableCfgs",
184
- _data: [
185
- {
186
- version: 0,
187
- _hash: "",
188
- key: "table",
189
- type: "components",
190
- isHead: false,
191
- isRoot: false,
192
- isShared: true,
193
- columns: [
194
- {
195
- key: "int",
196
- type: "number"
197
- },
198
- {
199
- key: "double",
200
- type: "number"
201
- },
202
- {
203
- key: "string",
204
- type: "string"
205
- },
206
- {
207
- key: "boolean",
208
- type: "boolean"
209
- },
210
- {
211
- key: "null",
212
- type: "string"
213
- },
214
- {
215
- key: "jsonArray",
216
- type: "jsonArray"
217
- },
218
- {
219
- key: "json",
220
- type: "json"
221
- },
222
- {
223
- key: "jsonValue",
224
- type: "jsonValue"
225
- }
197
+ class Example {
198
+ static ok = {
199
+ bakery: () => bakeryExample(),
200
+ empty: () => {
201
+ return {};
202
+ },
203
+ binary: () => {
204
+ return {
205
+ table: {
206
+ _type: "components",
207
+ _data: [
208
+ { a: false, b: false },
209
+ { a: false, b: true },
210
+ { a: true, b: false },
211
+ { a: true, b: true }
226
212
  ]
227
213
  }
228
- ]
229
- });
230
- const result = {
231
- tableCfgs,
232
- table: {
233
- _tableCfg: tableCfgs._data[0]._hash,
234
- _type: "components",
235
- _data: [exampleJsonObject()],
236
- _hash: ""
237
- }
238
- };
239
- return result;
240
- },
241
- multipleRows: () => {
242
- return {
243
- table: {
244
- _type: "components",
245
- _data: [
246
- {
247
- string: "str0",
248
- boolean: true,
249
- number: 1,
250
- array: [1, "str0", true, { a: { b: "c" } }],
251
- object: { a: { b: "c" } }
252
- },
253
- {
254
- string: "str1",
255
- boolean: true,
256
- number: 1,
257
- array: [1, "str1", true, { a: { b: "c" } }],
258
- object: { a: { b: "c" } }
259
- },
260
- {
261
- string: "str2",
262
- boolean: false,
263
- number: 1,
264
- array: [1, "str1", true, { a: { b: "c" } }],
265
- object: { d: { e: "f" } }
266
- }
267
- ]
268
- }
269
- };
270
- },
271
- singleRef: () => {
272
- return {
273
- tableA: {
274
- _type: "components",
275
- _data: [
276
- {
277
- keyA0: "a0"
278
- },
279
- {
280
- keyA1: "a1"
281
- }
282
- ]
283
- },
284
- tableB: {
285
- _type: "components",
286
- _data: [
287
- {
288
- tableARef: "KFQrf4mEz0UPmUaFHwH4T6"
289
- }
290
- ]
291
- }
292
- };
293
- },
294
- singleSliceIdRef: () => {
295
- return {
296
- exampleSliceId: {
297
- _type: "sliceIds",
298
- _data: [
299
- {
300
- add: ["id0", "id1"]
301
- }
302
- ]
303
- },
304
- exampleComponent: {
305
- _type: "components",
306
- _data: [
307
- {
308
- exampleSliceId: "id0"
309
- }
310
- ]
311
- }
312
- };
313
- },
314
- singleNamedRef: () => {
315
- return {
316
- tableA: {
317
- _type: "components",
318
- _data: [
319
- {
320
- keyA0: "a0"
321
- },
322
- {
323
- keyA1: "a1"
324
- }
325
- ]
326
- },
327
- tableB: {
328
- _type: "components",
329
- _data: [
330
- {
331
- namedRef: { component: "tableA", ref: "KFQrf4mEz0UPmUaFHwH4T6" }
332
- }
333
- ]
334
- }
335
- };
336
- },
337
- multiRef: () => {
338
- return {
339
- tableA: {
340
- _type: "components",
341
- _data: [
342
- {
343
- keyA0: "a0"
344
- },
345
- {
346
- keyA1: "a1"
347
- }
348
- ]
349
- },
350
- tableB: {
351
- _type: "components",
352
- _data: [
353
- {
354
- tableARef: ["KFQrf4mEz0UPmUaFHwH4T6", "YPw-pxhqaUOWRFGramr4B1"]
355
- }
356
- ]
357
- }
358
- };
359
- },
360
- multiMixedRef: () => {
361
- return {
362
- tableA: {
363
- _type: "components",
364
- _data: [
365
- {
366
- keyA0: "a0"
367
- },
368
- {
369
- keyA1: "a1"
370
- }
371
- ]
372
- },
373
- tableB: {
374
- _type: "components",
375
- _data: [
376
- {
377
- keyB0: "b0"
378
- },
379
- {
380
- keyB1: "b1"
381
- }
382
- ]
383
- },
384
- tableC: {
385
- _type: "components",
214
+ };
215
+ },
216
+ singleRow: () => {
217
+ const tableCfgs = hip({
218
+ _hash: "",
219
+ _type: "tableCfgs",
386
220
  _data: [
387
221
  {
388
- tableRef: [
389
- { component: "tableA", ref: "KFQrf4mEz0UPmUaFHwH4T6" },
390
- { component: "tableB", ref: "dXhIygNwNMVPEqFbsFJkn6" }
222
+ version: 0,
223
+ _hash: "",
224
+ key: "table",
225
+ type: "components",
226
+ isHead: false,
227
+ isRoot: false,
228
+ isShared: true,
229
+ columns: [
230
+ {
231
+ key: "_hash",
232
+ type: "string"
233
+ },
234
+ {
235
+ key: "int",
236
+ type: "number"
237
+ },
238
+ {
239
+ key: "double",
240
+ type: "number"
241
+ },
242
+ {
243
+ key: "string",
244
+ type: "string"
245
+ },
246
+ {
247
+ key: "boolean",
248
+ type: "boolean"
249
+ },
250
+ {
251
+ key: "null",
252
+ type: "string"
253
+ },
254
+ {
255
+ key: "jsonArray",
256
+ type: "jsonArray"
257
+ },
258
+ {
259
+ key: "json",
260
+ type: "json"
261
+ },
262
+ {
263
+ key: "jsonValue",
264
+ type: "jsonValue"
265
+ }
391
266
  ]
392
267
  }
393
268
  ]
394
- }
395
- };
396
- },
397
- complete: () => {
398
- const sliceIds = hip({
399
- _type: "sliceIds",
400
- _data: [
401
- {
402
- add: ["id0", "id1"]
269
+ });
270
+ const result = {
271
+ tableCfgs,
272
+ table: {
273
+ _tableCfg: tableCfgs._data[0]._hash,
274
+ _type: "components",
275
+ _data: [hip(exampleJsonObject())],
276
+ _hash: ""
403
277
  }
404
- ]
405
- });
406
- const components = hip({
407
- _type: "components",
408
- _data: [{ a: "0" }, { a: "1" }]
409
- });
410
- const component0 = components._data[0];
411
- const component1 = components._data[1];
412
- const abLayer0 = hip({
413
- sliceIdsTable: "sliceIds",
414
- sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
415
- componentsTable: "components",
416
- add: {
417
- id0: component0._hash,
418
- id1: component1._hash
419
- }
420
- });
421
- const abLayer1 = hip({
422
- base: abLayer0._hash,
423
- sliceIdsTable: "sliceIds",
424
- sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
425
- componentsTable: "components",
426
- add: {
427
- id0: component0._hash,
428
- id1: component1._hash
429
- }
430
- });
431
- const abLayers = hip({
432
- _type: "layers",
433
- _data: [abLayer0, abLayer1]
434
- });
435
- const cake = hip({
436
- sliceIdsTable: "sliceIds",
437
- sliceIdsRow: sliceIds._data[0]._hash,
438
- layers: {
439
- abLayers: abLayer1._hash
440
- }
441
- });
442
- const cakes = hip({
443
- _type: "cakes",
444
- _data: [cake]
445
- });
446
- const buffets = hip({
447
- _type: "buffets",
448
- _data: [
449
- {
450
- items: [
278
+ };
279
+ return result;
280
+ },
281
+ multipleRows: () => {
282
+ return {
283
+ table: {
284
+ _type: "components",
285
+ _data: [
451
286
  {
452
- table: "cakes",
453
- ref: cakes._data[0]._hash
287
+ string: "str0",
288
+ boolean: true,
289
+ number: 1,
290
+ array: [1, "str0", true, { a: { b: "c" } }],
291
+ object: { a: { b: "c" } }
454
292
  },
455
293
  {
456
- table: "abLayers",
457
- ref: abLayer0._hash
294
+ string: "str1",
295
+ boolean: true,
296
+ number: 1,
297
+ array: [1, "str1", true, { a: { b: "c" } }],
298
+ object: { a: { b: "c" } }
299
+ },
300
+ {
301
+ string: "str2",
302
+ boolean: false,
303
+ number: 1,
304
+ array: [1, "str1", true, { a: { b: "c" } }],
305
+ object: { d: { e: "f" } }
458
306
  }
459
307
  ]
460
308
  }
461
- ]
462
- });
463
- return {
464
- sliceIds,
465
- components,
466
- abLayers,
467
- cakes,
468
- buffets
469
- };
470
- }
471
- });
472
- __publicField(_Example, "broken", {
473
- base: {
474
- brokenTableKey: () => {
475
- return {
476
- brok$en: {
477
- _data: []
478
- }
479
309
  };
480
310
  },
481
- missingData: () => {
482
- return {
483
- table: {}
484
- };
485
- },
486
- dataNotBeingAnArray: () => {
487
- return {
488
- table: {
489
- _data: {}
490
- }
491
- };
492
- },
493
- missingRef: () => {
311
+ singleRef: () => {
494
312
  return {
495
313
  tableA: {
496
314
  _type: "components",
@@ -507,38 +325,53 @@ __publicField(_Example, "broken", {
507
325
  _type: "components",
508
326
  _data: [
509
327
  {
510
- tableARef: "MISSINGREF"
511
- // MISSINGREF does not exist in tableA
328
+ tableARef: "KFQrf4mEz0UPmUaFHwH4T6"
512
329
  }
513
330
  ]
514
331
  }
515
332
  };
516
333
  },
517
- missingNamedRef: () => {
334
+ singleSliceIdRef: () => {
518
335
  return {
519
- tableA: {
336
+ exampleSliceId: {
337
+ _type: "sliceIds",
338
+ _data: [
339
+ {
340
+ add: ["id0", "id1"]
341
+ }
342
+ ]
343
+ },
344
+ exampleComponent: {
520
345
  _type: "components",
521
346
  _data: [
522
347
  {
523
- keyA0: "a0"
524
- },
348
+ exampleSliceId: "id0"
349
+ }
350
+ ]
351
+ }
352
+ };
353
+ },
354
+ multiSliceIdRef: () => {
355
+ return {
356
+ exampleSliceId: {
357
+ _type: "sliceIds",
358
+ _data: [
525
359
  {
526
- keyA1: "a1"
360
+ add: ["id0", "id1"]
527
361
  }
528
362
  ]
529
363
  },
530
- tableB: {
364
+ exampleComponent: {
531
365
  _type: "components",
532
366
  _data: [
533
367
  {
534
- namedRef: { component: "tableA", ref: "MISSINGREF" }
535
- // MISSINGREF does not exist in tableA
368
+ exampleSliceId: ["id0", "id1"]
536
369
  }
537
370
  ]
538
371
  }
539
372
  };
540
373
  },
541
- missingMultiRef: () => {
374
+ singleNamedRef: () => {
542
375
  return {
543
376
  tableA: {
544
377
  _type: "components",
@@ -555,157 +388,384 @@ __publicField(_Example, "broken", {
555
388
  _type: "components",
556
389
  _data: [
557
390
  {
558
- tableARef: ["KFQrf4mEz0UPmUaFHwH4T6", "MISSING"]
391
+ namedRef: { component: "tableA", ref: "KFQrf4mEz0UPmUaFHwH4T6" }
559
392
  }
560
393
  ]
561
394
  }
562
395
  };
563
396
  },
564
- missingReferencedTable: () => {
397
+ multiRef: () => {
565
398
  return {
399
+ tableA: {
400
+ _type: "components",
401
+ _data: [
402
+ {
403
+ keyA0: "a0"
404
+ },
405
+ {
406
+ keyA1: "a1"
407
+ }
408
+ ]
409
+ },
566
410
  tableB: {
567
411
  _type: "components",
568
412
  _data: [
569
413
  {
570
- tableARef: "MISSINGREF"
571
- // tableA is missing
414
+ tableARef: ["KFQrf4mEz0UPmUaFHwH4T6", "YPw-pxhqaUOWRFGramr4B1"]
572
415
  }
573
416
  ]
574
417
  }
575
418
  };
576
419
  },
577
- missingSliceId: () => {
420
+ multiMixedRef: () => {
578
421
  return {
579
- exampleSliceId: {
580
- _type: "sliceIds",
422
+ tableA: {
423
+ _type: "components",
581
424
  _data: [
582
425
  {
583
- add: ["id0", "id1"]
426
+ keyA0: "a0"
427
+ },
428
+ {
429
+ keyA1: "a1"
584
430
  }
585
431
  ]
586
432
  },
587
- exampleComponent: {
433
+ tableB: {
588
434
  _type: "components",
589
435
  _data: [
590
436
  {
591
- exampleSliceId: "id2"
437
+ keyB0: "b0"
438
+ },
439
+ {
440
+ keyB1: "b1"
592
441
  }
593
442
  ]
594
- }
595
- };
596
- },
597
- missingSliceIdTable: () => {
598
- return {
599
- exampleComponent: {
443
+ },
444
+ tableC: {
600
445
  _type: "components",
601
446
  _data: [
602
447
  {
603
- exampleSliceId: "id0"
448
+ tableRef: [
449
+ { component: "tableA", ref: "KFQrf4mEz0UPmUaFHwH4T6" },
450
+ { component: "tableB", ref: "dXhIygNwNMVPEqFbsFJkn6" }
451
+ ]
604
452
  }
605
453
  ]
606
454
  }
607
455
  };
608
- }
609
- },
610
- tableCfg: {
611
- wrongType: () => {
612
- const result = _Example.ok.singleRow();
613
- const columns = result.tableCfgs._data[0].columns;
614
- const intColumn = columns.find((c) => c.key === "int");
615
- intColumn.type = "numberBroken";
616
- return hip(result, {
617
- updateExistingHashes: true,
618
- throwOnWrongHashes: false
456
+ },
457
+ complete: () => {
458
+ const sliceIds = hip({
459
+ _type: "sliceIds",
460
+ _data: [
461
+ {
462
+ add: ["id0", "id1"]
463
+ }
464
+ ]
619
465
  });
620
- }
621
- },
622
- layers: {
623
- missingBase: () => {
624
- const result = _Example.ok.complete();
625
- const layer1 = result.abLayers._data[1];
626
- layer1.base = "MISSING";
627
- return hip(result, {
628
- updateExistingHashes: true,
629
- throwOnWrongHashes: false
466
+ const components = hip({
467
+ _type: "components",
468
+ _data: [{ a: "0" }, { a: "1" }]
630
469
  });
631
- },
632
- missingSliceIdSet: () => {
633
- const result = _Example.ok.complete();
634
- const layer1 = result.abLayers._data[1];
635
- layer1.sliceIdsTableRow = "MISSING1";
636
- return hip(result, {
637
- updateExistingHashes: true,
638
- throwOnWrongHashes: false
470
+ const component0 = components._data[0];
471
+ const component1 = components._data[1];
472
+ const abLayer0 = hip({
473
+ sliceIdsTable: "sliceIds",
474
+ sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
475
+ componentsTable: "components",
476
+ add: {
477
+ id0: component0._hash,
478
+ id1: component1._hash
479
+ }
639
480
  });
640
- },
641
- missingAssignedComponentTable: () => {
642
- const result = _Example.ok.complete();
643
- delete result.components;
644
- return result;
645
- },
646
- missingAssignedComponent: () => {
647
- const result = _Example.ok.complete();
648
- result.components._data.splice(1, 2);
649
- return hip(result, {
650
- updateExistingHashes: true,
651
- throwOnWrongHashes: false
481
+ const abLayer1 = hip({
482
+ base: abLayer0._hash,
483
+ sliceIdsTable: "sliceIds",
484
+ sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
485
+ componentsTable: "components",
486
+ add: {
487
+ id0: component0._hash,
488
+ id1: component1._hash
489
+ }
652
490
  });
653
- }
654
- },
655
- cakes: {
656
- missingSliceIdSet: () => {
657
- const result = _Example.ok.complete();
658
- result.cakes._data[0].sliceIdsRow = "MISSING";
659
- hip(result.cakes, {
660
- updateExistingHashes: true,
661
- throwOnWrongHashes: false
491
+ const abLayers = hip({
492
+ _type: "layers",
493
+ _data: [abLayer0, abLayer1]
662
494
  });
663
- result.buffets._data[0].items[0].ref = result.cakes._data[0]._hash;
664
- hip(result.buffets, {
665
- updateExistingHashes: true,
666
- throwOnWrongHashes: false
495
+ const cake = hip({
496
+ sliceIdsTable: "sliceIds",
497
+ sliceIdsRow: sliceIds._data[0]._hash,
498
+ layers: {
499
+ abLayers: abLayer1._hash
500
+ }
667
501
  });
668
- return result;
669
- },
670
- missingLayersTable: () => {
671
- const result = _Example.ok.complete();
672
- result.cakes._data[0].layers = { MISSING: "HASH" };
673
- hip(result.cakes, {
674
- updateExistingHashes: true,
675
- throwOnWrongHashes: false
502
+ const cakes = hip({
503
+ _type: "cakes",
504
+ _data: [cake]
676
505
  });
677
- return result;
678
- },
679
- missingCakeLayer: () => {
680
- const result = _Example.ok.complete();
681
- result.cakes._data[0].layers["abLayers"] = "MISSING0";
682
- hip(result.cakes, {
683
- updateExistingHashes: true,
684
- throwOnWrongHashes: false
506
+ const buffets = hip({
507
+ _type: "buffets",
508
+ _data: [
509
+ {
510
+ items: [
511
+ {
512
+ table: "cakes",
513
+ ref: cakes._data[0]._hash
514
+ },
515
+ {
516
+ table: "abLayers",
517
+ ref: abLayer0._hash
518
+ }
519
+ ]
520
+ }
521
+ ]
685
522
  });
686
- return result;
523
+ return {
524
+ sliceIds,
525
+ components,
526
+ abLayers,
527
+ cakes,
528
+ buffets
529
+ };
687
530
  }
688
- },
689
- buffets: {
690
- missingTable: () => {
691
- const result = _Example.ok.complete();
692
- const buffet = result.buffets._data[0];
693
- buffet.items[0].table = "MISSING0";
694
- buffet.items[1].table = "MISSING1";
695
- hip(result, { updateExistingHashes: true, throwOnWrongHashes: false });
696
- return result;
531
+ };
532
+ static broken = {
533
+ base: {
534
+ brokenTableKey: () => {
535
+ return {
536
+ brok$en: {
537
+ _data: []
538
+ }
539
+ };
540
+ },
541
+ missingData: () => {
542
+ return {
543
+ table: {}
544
+ };
545
+ },
546
+ dataNotBeingAnArray: () => {
547
+ return {
548
+ table: {
549
+ _data: {}
550
+ }
551
+ };
552
+ },
553
+ missingRef: () => {
554
+ return {
555
+ tableA: {
556
+ _type: "components",
557
+ _data: [
558
+ {
559
+ keyA0: "a0"
560
+ },
561
+ {
562
+ keyA1: "a1"
563
+ }
564
+ ]
565
+ },
566
+ tableB: {
567
+ _type: "components",
568
+ _data: [
569
+ {
570
+ tableARef: "MISSINGREF"
571
+ // MISSINGREF does not exist in tableA
572
+ }
573
+ ]
574
+ }
575
+ };
576
+ },
577
+ missingNamedRef: () => {
578
+ return {
579
+ tableA: {
580
+ _type: "components",
581
+ _data: [
582
+ {
583
+ keyA0: "a0"
584
+ },
585
+ {
586
+ keyA1: "a1"
587
+ }
588
+ ]
589
+ },
590
+ tableB: {
591
+ _type: "components",
592
+ _data: [
593
+ {
594
+ namedRef: { component: "tableA", ref: "MISSINGREF" }
595
+ // MISSINGREF does not exist in tableA
596
+ }
597
+ ]
598
+ }
599
+ };
600
+ },
601
+ missingMultiRef: () => {
602
+ return {
603
+ tableA: {
604
+ _type: "components",
605
+ _data: [
606
+ {
607
+ keyA0: "a0"
608
+ },
609
+ {
610
+ keyA1: "a1"
611
+ }
612
+ ]
613
+ },
614
+ tableB: {
615
+ _type: "components",
616
+ _data: [
617
+ {
618
+ tableARef: ["KFQrf4mEz0UPmUaFHwH4T6", "MISSING"]
619
+ }
620
+ ]
621
+ }
622
+ };
623
+ },
624
+ missingReferencedTable: () => {
625
+ return {
626
+ tableB: {
627
+ _type: "components",
628
+ _data: [
629
+ {
630
+ tableARef: "MISSINGREF"
631
+ // tableA is missing
632
+ }
633
+ ]
634
+ }
635
+ };
636
+ },
637
+ missingSliceId: () => {
638
+ return {
639
+ exampleSliceId: {
640
+ _type: "sliceIds",
641
+ _data: [
642
+ {
643
+ add: ["id0", "id1"]
644
+ }
645
+ ]
646
+ },
647
+ exampleComponent: {
648
+ _type: "components",
649
+ _data: [
650
+ {
651
+ exampleSliceId: "id2"
652
+ }
653
+ ]
654
+ }
655
+ };
656
+ },
657
+ missingSliceIdTable: () => {
658
+ return {
659
+ exampleComponent: {
660
+ _type: "components",
661
+ _data: [
662
+ {
663
+ exampleSliceId: "id0"
664
+ }
665
+ ]
666
+ }
667
+ };
668
+ }
697
669
  },
698
- missingItems: () => {
699
- const result = _Example.ok.complete();
700
- const buffet = result.buffets._data[0];
701
- buffet.items[0].ref = "MISSING0";
702
- buffet.items[1].ref = "MISSING1";
703
- hip(result, { updateExistingHashes: true, throwOnWrongHashes: false });
704
- return result;
670
+ tableCfg: {
671
+ wrongType: () => {
672
+ const result = Example.ok.singleRow();
673
+ const columns = result.tableCfgs._data[0].columns;
674
+ const intColumn = columns.find((c) => c.key === "int");
675
+ intColumn.type = "numberBroken";
676
+ return hip(result, {
677
+ updateExistingHashes: true,
678
+ throwOnWrongHashes: false
679
+ });
680
+ }
681
+ },
682
+ layers: {
683
+ missingBase: () => {
684
+ const result = Example.ok.complete();
685
+ const layer1 = result.abLayers._data[1];
686
+ layer1.base = "MISSING";
687
+ return hip(result, {
688
+ updateExistingHashes: true,
689
+ throwOnWrongHashes: false
690
+ });
691
+ },
692
+ missingSliceIdSet: () => {
693
+ const result = Example.ok.complete();
694
+ const layer1 = result.abLayers._data[1];
695
+ layer1.sliceIdsTableRow = "MISSING1";
696
+ return hip(result, {
697
+ updateExistingHashes: true,
698
+ throwOnWrongHashes: false
699
+ });
700
+ },
701
+ missingAssignedComponentTable: () => {
702
+ const result = Example.ok.complete();
703
+ delete result.components;
704
+ return result;
705
+ },
706
+ missingAssignedComponent: () => {
707
+ const result = Example.ok.complete();
708
+ result.components._data.splice(1, 2);
709
+ return hip(result, {
710
+ updateExistingHashes: true,
711
+ throwOnWrongHashes: false
712
+ });
713
+ }
714
+ },
715
+ cakes: {
716
+ missingSliceIdSet: () => {
717
+ const result = Example.ok.complete();
718
+ result.cakes._data[0].sliceIdsRow = "MISSING";
719
+ hip(result.cakes, {
720
+ updateExistingHashes: true,
721
+ throwOnWrongHashes: false
722
+ });
723
+ result.buffets._data[0].items[0].ref = result.cakes._data[0]._hash;
724
+ hip(result.buffets, {
725
+ updateExistingHashes: true,
726
+ throwOnWrongHashes: false
727
+ });
728
+ return result;
729
+ },
730
+ missingLayersTable: () => {
731
+ const result = Example.ok.complete();
732
+ result.cakes._data[0].layers = { MISSING: "HASH" };
733
+ hip(result.cakes, {
734
+ updateExistingHashes: true,
735
+ throwOnWrongHashes: false
736
+ });
737
+ return result;
738
+ },
739
+ missingCakeLayer: () => {
740
+ const result = Example.ok.complete();
741
+ result.cakes._data[0].layers["abLayers"] = "MISSING0";
742
+ hip(result.cakes, {
743
+ updateExistingHashes: true,
744
+ throwOnWrongHashes: false
745
+ });
746
+ return result;
747
+ }
748
+ },
749
+ buffets: {
750
+ missingTable: () => {
751
+ const result = Example.ok.complete();
752
+ const buffet = result.buffets._data[0];
753
+ buffet.items[0].table = "MISSING0";
754
+ buffet.items[1].table = "MISSING1";
755
+ hip(result, { updateExistingHashes: true, throwOnWrongHashes: false });
756
+ return result;
757
+ },
758
+ missingItems: () => {
759
+ const result = Example.ok.complete();
760
+ const buffet = result.buffets._data[0];
761
+ buffet.items[0].ref = "MISSING0";
762
+ buffet.items[1].ref = "MISSING1";
763
+ hip(result, { updateExistingHashes: true, throwOnWrongHashes: false });
764
+ return result;
765
+ }
705
766
  }
706
- }
707
- });
708
- let Example = _Example;
767
+ };
768
+ }
709
769
  // @license
710
770
  const throwOnInvalidTableCfg = (tableCfg) => {
711
771
  if (tableCfg.columns.length < 2) {
@@ -751,10 +811,12 @@ const validateRljsonAgainstTableCfg = (rows, tableCfg) => {
751
811
  if (value === void 0 || value === null) {
752
812
  continue;
753
813
  }
754
- const actualType = jsonValueType(row[columnKey]);
755
- if (expectedType !== actualType) {
814
+ const typesMatched = jsonValueMatchesType(row[columnKey], expectedType);
815
+ if (!typesMatched) {
756
816
  errors.push(
757
- `Column "${columnKey}" in row ${i} of "${tableKey}" has type "${actualType}", but expected "${expectedType}"`
817
+ `Column "${columnKey}" in row ${i} of "${tableKey}" has type "${jsonValueType(
818
+ row[columnKey]
819
+ )}", but expected "${expectedType}"`
758
820
  );
759
821
  }
760
822
  }
@@ -784,8 +846,8 @@ const addColumnsToTableCfg = (tableCfg, columns) => {
784
846
  const exampleTableCfgTable = () => Example.ok.singleRow().tableCfgs;
785
847
  const exampleTableCfg = (tableCfg = void 0) => {
786
848
  return {
787
- key: (tableCfg == null ? void 0 : tableCfg.key) ?? "table",
788
- columns: (tableCfg == null ? void 0 : tableCfg.columns) ?? [
849
+ key: tableCfg?.key ?? "table",
850
+ columns: tableCfg?.columns ?? [
789
851
  {
790
852
  key: "_hash",
791
853
  type: "string"
@@ -799,13 +861,15 @@ const exampleTableCfg = (tableCfg = void 0) => {
799
861
  type: "number"
800
862
  }
801
863
  ],
802
- type: (tableCfg == null ? void 0 : tableCfg.type) ?? "components",
864
+ type: tableCfg?.type ?? "components",
803
865
  isHead: true,
804
866
  isRoot: true,
805
867
  isShared: false
806
868
  };
807
869
  };
808
870
  // @license
871
+ const exampleEditsTable = () => bakeryExample().ingredientsEdits;
872
+ // @license
809
873
  const reservedFieldNames = ["_data"];
810
874
  const reservedTableKeys = [
811
875
  "_hash",
@@ -867,7 +931,8 @@ const contentTypes = [
867
931
  "sliceIds",
868
932
  "components",
869
933
  "revisions",
870
- "tableCfgs"
934
+ "tableCfgs",
935
+ "edits"
871
936
  ];
872
937
  const exampleTypedefs = () => {
873
938
  return {
@@ -902,9 +967,7 @@ const rljsonIndexed = (rljson) => {
902
967
  };
903
968
  // @license
904
969
  class BaseValidator {
905
- constructor() {
906
- __publicField(this, "name", "base");
907
- }
970
+ name = "base";
908
971
  async validate(rljson) {
909
972
  return this.validateSync(rljson);
910
973
  }
@@ -917,18 +980,13 @@ class BaseValidator {
917
980
  }
918
981
  class _BaseValidator {
919
982
  constructor(rljson) {
920
- __publicField(this, "errors", { hasErrors: false });
921
- // ######################
922
- // Private
923
- // ######################
924
- __publicField(this, "tableKeys");
925
- __publicField(this, "rljsonIndexed");
926
983
  this.rljson = rljson;
927
984
  this.tableKeys = Object.keys(this.rljson).filter(
928
985
  (table) => !table.startsWith("_")
929
986
  );
930
987
  this.rljsonIndexed = rljsonIndexed(rljson);
931
988
  }
989
+ errors = { hasErrors: false };
932
990
  get hasErrors() {
933
991
  return Object.keys(this.errors).length > 1;
934
992
  }
@@ -974,6 +1032,11 @@ class _BaseValidator {
974
1032
  this.errors.hasErrors = this.hasErrors;
975
1033
  return this.errors;
976
1034
  }
1035
+ // ######################
1036
+ // Private
1037
+ // ######################
1038
+ tableKeys;
1039
+ rljsonIndexed;
977
1040
  _tableKeysNotLowerCamelCase() {
978
1041
  const invalidTableKeys = [];
979
1042
  for (const tableKey of this.tableKeys) {
@@ -1018,7 +1081,7 @@ class _BaseValidator {
1018
1081
  continue;
1019
1082
  }
1020
1083
  if (!BaseValidator.isValidFieldName(columnName)) {
1021
- invalidColumnNames[tableKey] ?? (invalidColumnNames[tableKey] = []);
1084
+ invalidColumnNames[tableKey] ??= [];
1022
1085
  invalidColumnNames[tableKey].push(columnName);
1023
1086
  hadErrors = true;
1024
1087
  }
@@ -1373,28 +1436,30 @@ class _BaseValidator {
1373
1436
  for (const item of tableData) {
1374
1437
  for (const key of Object.keys(item)) {
1375
1438
  if (key.endsWith("SliceId")) {
1376
- const targetSliceId = item[key];
1377
- if (this.tableKeys.indexOf(key) === -1) {
1378
- missingSliceIdRefs.push({
1379
- sourceTable: tableKey,
1380
- targetSliceId,
1381
- targetTable: key,
1382
- error: `Target table "${targetSliceId}" not found.`
1383
- });
1384
- continue;
1385
- }
1386
- const targetSliceIdsTable = this.rljson[key];
1387
- const targetSliceIds = targetSliceIdsTable._data.flatMap((d) => [
1388
- ...d.add,
1389
- ...d.remove ?? []
1390
- ]);
1391
- if (targetSliceIds.indexOf(targetSliceId) === -1) {
1392
- missingSliceIdRefs.push({
1393
- sourceTable: tableKey,
1394
- targetSliceId,
1395
- targetTable: key,
1396
- error: `Table "${key}" has no sliceId "${targetSliceId}"`
1397
- });
1439
+ const targetSliceIds = Array.isArray(item[key]) ? item[key] : [item[key]];
1440
+ for (const targetSliceId of targetSliceIds) {
1441
+ if (this.tableKeys.indexOf(key) === -1) {
1442
+ missingSliceIdRefs.push({
1443
+ sourceTable: tableKey,
1444
+ targetSliceId,
1445
+ targetTable: key,
1446
+ error: `Target table "${targetSliceId}" not found.`
1447
+ });
1448
+ continue;
1449
+ }
1450
+ const targetSliceIdsTable = this.rljson[key];
1451
+ const targetSliceIds2 = targetSliceIdsTable._data.flatMap((d) => [
1452
+ ...d.add,
1453
+ ...d.remove ?? []
1454
+ ]);
1455
+ if (targetSliceIds2.indexOf(targetSliceId) === -1) {
1456
+ missingSliceIdRefs.push({
1457
+ sourceTable: tableKey,
1458
+ targetSliceId,
1459
+ targetTable: key,
1460
+ error: `Table "${key}" has no sliceId "${targetSliceId}"`
1461
+ });
1462
+ }
1398
1463
  }
1399
1464
  }
1400
1465
  }
@@ -1722,12 +1787,6 @@ class _BaseValidator {
1722
1787
  const isValidFieldName = (fieldName) => BaseValidator.isValidFieldName(fieldName);
1723
1788
  // @license
1724
1789
  class Validate {
1725
- constructor() {
1726
- // ######################
1727
- // Private
1728
- // ######################
1729
- __publicField(this, "_validators", []);
1730
- }
1731
1790
  addValidator(validator) {
1732
1791
  this._validators.push(validator);
1733
1792
  }
@@ -1756,6 +1815,10 @@ class Validate {
1756
1815
  return acc;
1757
1816
  }, {});
1758
1817
  }
1818
+ // ######################
1819
+ // Private
1820
+ // ######################
1821
+ _validators = [];
1759
1822
  }
1760
1823
  export {
1761
1824
  BaseValidator,
@@ -1767,6 +1830,7 @@ export {
1767
1830
  exampleBuffetsTable,
1768
1831
  exampleCakesTable,
1769
1832
  exampleComponentsTable,
1833
+ exampleEditsTable,
1770
1834
  exampleLayersTable,
1771
1835
  exampleRevision,
1772
1836
  exampleRljson,