@rljson/rljson 0.0.53 → 0.0.55

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/example.d.ts CHANGED
@@ -7,6 +7,10 @@ export declare class Example {
7
7
  singleRow: () => Rljson;
8
8
  multipleRows: () => Rljson;
9
9
  singleRef: () => Rljson;
10
+ singleSliceIdRef: () => Rljson;
11
+ singleNamedRef: () => Rljson;
12
+ multiRef: () => Rljson;
13
+ multiMixedRef: () => Rljson;
10
14
  complete: () => Rljson;
11
15
  };
12
16
  static readonly broken: {
@@ -19,7 +23,11 @@ export declare class Example {
19
23
  missingData: () => Rljson;
20
24
  dataNotBeingAnArray: () => Rljson;
21
25
  missingRef: () => Rljson;
26
+ missingNamedRef: () => Rljson;
27
+ missingMultiRef: () => Rljson;
22
28
  missingReferencedTable: () => Rljson;
29
+ missingSliceId: () => Rljson;
30
+ missingSliceIdTable: () => Rljson;
23
31
  };
24
32
  tableCfg: {
25
33
  wrongType: () => Rljson;
package/dist/rljson.js CHANGED
@@ -1,3 +1,6 @@
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);
1
4
  import { hip, hsh } from "@rljson/hash";
2
5
  import { exampleJsonObject, jsonValueTypes, jsonValueType, jsonValueMatchesType } from "@rljson/json";
3
6
  // @license
@@ -154,117 +157,388 @@ const exampleRevision = () => ({
154
157
  // @license
155
158
  const exampleSliceIdsTable = () => bakeryExample().slices;
156
159
  // @license
157
- class Example {
158
- static ok = {
159
- bakery: () => bakeryExample(),
160
- empty: () => {
161
- return {};
162
- },
163
- binary: () => {
164
- return {
165
- table: {
166
- _type: "components",
167
- _data: [
168
- { a: false, b: false },
169
- { a: false, b: true },
170
- { a: true, b: false },
171
- { a: true, b: true }
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
+ }
172
226
  ]
173
227
  }
174
- };
175
- },
176
- singleRow: () => {
177
- const tableCfgs = hip({
178
- _hash: "",
179
- _type: "tableCfgs",
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",
180
245
  _data: [
181
246
  {
182
- version: 0,
183
- _hash: "",
184
- key: "table",
185
- type: "components",
186
- isHead: false,
187
- isRoot: false,
188
- isShared: true,
189
- columns: [
190
- {
191
- key: "int",
192
- type: "number"
193
- },
194
- {
195
- key: "double",
196
- type: "number"
197
- },
198
- {
199
- key: "string",
200
- type: "string"
201
- },
202
- {
203
- key: "boolean",
204
- type: "boolean"
205
- },
206
- {
207
- key: "null",
208
- type: "string"
209
- },
210
- {
211
- key: "jsonArray",
212
- type: "jsonArray"
213
- },
214
- {
215
- key: "json",
216
- type: "json"
217
- },
218
- {
219
- key: "jsonValue",
220
- type: "jsonValue"
221
- }
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",
386
+ _data: [
387
+ {
388
+ tableRef: [
389
+ { component: "tableA", ref: "KFQrf4mEz0UPmUaFHwH4T6" },
390
+ { component: "tableB", ref: "dXhIygNwNMVPEqFbsFJkn6" }
222
391
  ]
223
392
  }
224
393
  ]
225
- });
226
- const result = {
227
- tableCfgs,
228
- table: {
229
- _tableCfg: tableCfgs._data[0]._hash,
230
- _type: "components",
231
- _data: [exampleJsonObject()],
232
- _hash: ""
394
+ }
395
+ };
396
+ },
397
+ complete: () => {
398
+ const sliceIds = hip({
399
+ _type: "sliceIds",
400
+ _data: [
401
+ {
402
+ add: ["id0", "id1"]
403
+ }
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: [
451
+ {
452
+ table: "cakes",
453
+ ref: cakes._data[0]._hash
454
+ },
455
+ {
456
+ table: "abLayers",
457
+ ref: abLayer0._hash
458
+ }
459
+ ]
460
+ }
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: []
233
478
  }
234
479
  };
235
- return result;
236
480
  },
237
- multipleRows: () => {
481
+ missingData: () => {
482
+ return {
483
+ table: {}
484
+ };
485
+ },
486
+ dataNotBeingAnArray: () => {
238
487
  return {
239
488
  table: {
489
+ _data: {}
490
+ }
491
+ };
492
+ },
493
+ missingRef: () => {
494
+ return {
495
+ tableA: {
240
496
  _type: "components",
241
497
  _data: [
242
498
  {
243
- string: "str0",
244
- boolean: true,
245
- number: 1,
246
- array: [1, "str0", true, { a: { b: "c" } }],
247
- object: { a: { b: "c" } }
499
+ keyA0: "a0"
248
500
  },
249
501
  {
250
- string: "str1",
251
- boolean: true,
252
- number: 1,
253
- array: [1, "str1", true, { a: { b: "c" } }],
254
- object: { a: { b: "c" } }
502
+ keyA1: "a1"
503
+ }
504
+ ]
505
+ },
506
+ tableB: {
507
+ _type: "components",
508
+ _data: [
509
+ {
510
+ tableARef: "MISSINGREF"
511
+ // MISSINGREF does not exist in tableA
512
+ }
513
+ ]
514
+ }
515
+ };
516
+ },
517
+ missingNamedRef: () => {
518
+ return {
519
+ tableA: {
520
+ _type: "components",
521
+ _data: [
522
+ {
523
+ keyA0: "a0"
255
524
  },
256
525
  {
257
- string: "str2",
258
- boolean: false,
259
- number: 1,
260
- array: [1, "str1", true, { a: { b: "c" } }],
261
- object: { d: { e: "f" } }
526
+ keyA1: "a1"
527
+ }
528
+ ]
529
+ },
530
+ tableB: {
531
+ _type: "components",
532
+ _data: [
533
+ {
534
+ namedRef: { component: "tableA", ref: "MISSINGREF" }
535
+ // MISSINGREF does not exist in tableA
262
536
  }
263
537
  ]
264
538
  }
265
539
  };
266
540
  },
267
- singleRef: () => {
541
+ missingMultiRef: () => {
268
542
  return {
269
543
  tableA: {
270
544
  _type: "components",
@@ -281,245 +555,157 @@ class Example {
281
555
  _type: "components",
282
556
  _data: [
283
557
  {
284
- tableARef: "KFQrf4mEz0UPmUaFHwH4T6"
558
+ tableARef: ["KFQrf4mEz0UPmUaFHwH4T6", "MISSING"]
285
559
  }
286
560
  ]
287
561
  }
288
562
  };
289
563
  },
290
- complete: () => {
291
- const sliceIds = hip({
292
- _type: "sliceIds",
293
- _data: [
294
- {
295
- add: ["id0", "id1"]
296
- }
297
- ]
298
- });
299
- const components = hip({
300
- _type: "components",
301
- _data: [{ a: "0" }, { a: "1" }]
302
- });
303
- const component0 = components._data[0];
304
- const component1 = components._data[1];
305
- const abLayer0 = hip({
306
- sliceIdsTable: "sliceIds",
307
- sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
308
- componentsTable: "components",
309
- add: {
310
- id0: component0._hash,
311
- id1: component1._hash
564
+ missingReferencedTable: () => {
565
+ return {
566
+ tableB: {
567
+ _type: "components",
568
+ _data: [
569
+ {
570
+ tableARef: "MISSINGREF"
571
+ // tableA is missing
572
+ }
573
+ ]
312
574
  }
313
- });
314
- const abLayer1 = hip({
315
- base: abLayer0._hash,
316
- sliceIdsTable: "sliceIds",
317
- sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
318
- componentsTable: "components",
319
- add: {
320
- id0: component0._hash,
321
- id1: component1._hash
575
+ };
576
+ },
577
+ missingSliceId: () => {
578
+ return {
579
+ exampleSliceId: {
580
+ _type: "sliceIds",
581
+ _data: [
582
+ {
583
+ add: ["id0", "id1"]
584
+ }
585
+ ]
586
+ },
587
+ exampleComponent: {
588
+ _type: "components",
589
+ _data: [
590
+ {
591
+ exampleSliceId: "id2"
592
+ }
593
+ ]
322
594
  }
323
- });
324
- const abLayers = hip({
325
- _type: "layers",
326
- _data: [abLayer0, abLayer1]
327
- });
328
- const cake = hip({
329
- sliceIdsTable: "sliceIds",
330
- sliceIdsRow: sliceIds._data[0]._hash,
331
- layers: {
332
- abLayers: abLayer1._hash
595
+ };
596
+ },
597
+ missingSliceIdTable: () => {
598
+ return {
599
+ exampleComponent: {
600
+ _type: "components",
601
+ _data: [
602
+ {
603
+ exampleSliceId: "id0"
604
+ }
605
+ ]
333
606
  }
607
+ };
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
334
619
  });
335
- const cakes = hip({
336
- _type: "cakes",
337
- _data: [cake]
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
338
630
  });
339
- const buffets = hip({
340
- _type: "buffets",
341
- _data: [
342
- {
343
- items: [
344
- {
345
- table: "cakes",
346
- ref: cakes._data[0]._hash
347
- },
348
- {
349
- table: "abLayers",
350
- ref: abLayer0._hash
351
- }
352
- ]
353
- }
354
- ]
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
355
639
  });
356
- return {
357
- sliceIds,
358
- components,
359
- abLayers,
360
- cakes,
361
- buffets
362
- };
363
- }
364
- };
365
- static broken = {
366
- base: {
367
- brokenTableKey: () => {
368
- return {
369
- brok$en: {
370
- _data: []
371
- }
372
- };
373
- },
374
- missingData: () => {
375
- return {
376
- table: {}
377
- };
378
- },
379
- dataNotBeingAnArray: () => {
380
- return {
381
- table: {
382
- _data: {}
383
- }
384
- };
385
- },
386
- missingRef: () => {
387
- return {
388
- tableA: {
389
- _type: "components",
390
- _data: [
391
- {
392
- keyA0: "a0"
393
- },
394
- {
395
- keyA1: "a1"
396
- }
397
- ]
398
- },
399
- tableB: {
400
- _type: "components",
401
- _data: [
402
- {
403
- tableARef: "MISSINGREF"
404
- // MISSINGREF does not exist in tableA
405
- }
406
- ]
407
- }
408
- };
409
- },
410
- missingReferencedTable: () => {
411
- return {
412
- tableB: {
413
- _type: "components",
414
- _data: [
415
- {
416
- tableARef: "MISSINGREF"
417
- // tableA is missing
418
- }
419
- ]
420
- }
421
- };
422
- }
423
640
  },
424
- tableCfg: {
425
- wrongType: () => {
426
- const result = Example.ok.singleRow();
427
- const columns = result.tableCfgs._data[0].columns;
428
- const intColumn = columns.find((c) => c.key === "int");
429
- intColumn.type = "numberBroken";
430
- return hip(result, {
431
- updateExistingHashes: true,
432
- throwOnWrongHashes: false
433
- });
434
- }
641
+ missingAssignedComponentTable: () => {
642
+ const result = _Example.ok.complete();
643
+ delete result.components;
644
+ return result;
435
645
  },
436
- layers: {
437
- missingBase: () => {
438
- const result = Example.ok.complete();
439
- const layer1 = result.abLayers._data[1];
440
- layer1.base = "MISSING";
441
- return hip(result, {
442
- updateExistingHashes: true,
443
- throwOnWrongHashes: false
444
- });
445
- },
446
- missingSliceIdSet: () => {
447
- const result = Example.ok.complete();
448
- const layer1 = result.abLayers._data[1];
449
- layer1.sliceIdsTableRow = "MISSING1";
450
- return hip(result, {
451
- updateExistingHashes: true,
452
- throwOnWrongHashes: false
453
- });
454
- },
455
- missingAssignedComponentTable: () => {
456
- const result = Example.ok.complete();
457
- delete result.components;
458
- return result;
459
- },
460
- missingAssignedComponent: () => {
461
- const result = Example.ok.complete();
462
- result.components._data.splice(1, 2);
463
- return hip(result, {
464
- updateExistingHashes: true,
465
- throwOnWrongHashes: false
466
- });
467
- }
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
652
+ });
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
662
+ });
663
+ result.buffets._data[0].items[0].ref = result.cakes._data[0]._hash;
664
+ hip(result.buffets, {
665
+ updateExistingHashes: true,
666
+ throwOnWrongHashes: false
667
+ });
668
+ return result;
468
669
  },
469
- cakes: {
470
- missingSliceIdSet: () => {
471
- const result = Example.ok.complete();
472
- result.cakes._data[0].sliceIdsRow = "MISSING";
473
- hip(result.cakes, {
474
- updateExistingHashes: true,
475
- throwOnWrongHashes: false
476
- });
477
- result.buffets._data[0].items[0].ref = result.cakes._data[0]._hash;
478
- hip(result.buffets, {
479
- updateExistingHashes: true,
480
- throwOnWrongHashes: false
481
- });
482
- return result;
483
- },
484
- missingLayersTable: () => {
485
- const result = Example.ok.complete();
486
- result.cakes._data[0].layers = { MISSING: "HASH" };
487
- hip(result.cakes, {
488
- updateExistingHashes: true,
489
- throwOnWrongHashes: false
490
- });
491
- return result;
492
- },
493
- missingCakeLayer: () => {
494
- const result = Example.ok.complete();
495
- result.cakes._data[0].layers["abLayers"] = "MISSING0";
496
- hip(result.cakes, {
497
- updateExistingHashes: true,
498
- throwOnWrongHashes: false
499
- });
500
- return result;
501
- }
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
676
+ });
677
+ return result;
502
678
  },
503
- buffets: {
504
- missingTable: () => {
505
- const result = Example.ok.complete();
506
- const buffet = result.buffets._data[0];
507
- buffet.items[0].table = "MISSING0";
508
- buffet.items[1].table = "MISSING1";
509
- hip(result, { updateExistingHashes: true, throwOnWrongHashes: false });
510
- return result;
511
- },
512
- missingItems: () => {
513
- const result = Example.ok.complete();
514
- const buffet = result.buffets._data[0];
515
- buffet.items[0].ref = "MISSING0";
516
- buffet.items[1].ref = "MISSING1";
517
- hip(result, { updateExistingHashes: true, throwOnWrongHashes: false });
518
- return result;
519
- }
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
685
+ });
686
+ return result;
520
687
  }
521
- };
522
- }
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;
697
+ },
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;
705
+ }
706
+ }
707
+ });
708
+ let Example = _Example;
523
709
  // @license
524
710
  const throwOnInvalidTableCfg = (tableCfg) => {
525
711
  if (tableCfg.columns.length < 2) {
@@ -598,8 +784,8 @@ const addColumnsToTableCfg = (tableCfg, columns) => {
598
784
  const exampleTableCfgTable = () => Example.ok.singleRow().tableCfgs;
599
785
  const exampleTableCfg = (tableCfg = void 0) => {
600
786
  return {
601
- key: tableCfg?.key ?? "table",
602
- columns: tableCfg?.columns ?? [
787
+ key: (tableCfg == null ? void 0 : tableCfg.key) ?? "table",
788
+ columns: (tableCfg == null ? void 0 : tableCfg.columns) ?? [
603
789
  {
604
790
  key: "_hash",
605
791
  type: "string"
@@ -613,7 +799,7 @@ const exampleTableCfg = (tableCfg = void 0) => {
613
799
  type: "number"
614
800
  }
615
801
  ],
616
- type: tableCfg?.type ?? "components",
802
+ type: (tableCfg == null ? void 0 : tableCfg.type) ?? "components",
617
803
  isHead: true,
618
804
  isRoot: true,
619
805
  isShared: false
@@ -716,7 +902,9 @@ const rljsonIndexed = (rljson) => {
716
902
  };
717
903
  // @license
718
904
  class BaseValidator {
719
- name = "base";
905
+ constructor() {
906
+ __publicField(this, "name", "base");
907
+ }
720
908
  async validate(rljson) {
721
909
  return this.validateSync(rljson);
722
910
  }
@@ -729,13 +917,18 @@ class BaseValidator {
729
917
  }
730
918
  class _BaseValidator {
731
919
  constructor(rljson) {
920
+ __publicField(this, "errors", { hasErrors: false });
921
+ // ######################
922
+ // Private
923
+ // ######################
924
+ __publicField(this, "tableKeys");
925
+ __publicField(this, "rljsonIndexed");
732
926
  this.rljson = rljson;
733
927
  this.tableKeys = Object.keys(this.rljson).filter(
734
928
  (table) => !table.startsWith("_")
735
929
  );
736
930
  this.rljsonIndexed = rljsonIndexed(rljson);
737
931
  }
738
- errors = { hasErrors: false };
739
932
  get hasErrors() {
740
933
  return Object.keys(this.errors).length > 1;
741
934
  }
@@ -758,6 +951,7 @@ class _BaseValidator {
758
951
  () => this._rootOrHeadTableHasNoIdColumn(),
759
952
  // Check references
760
953
  () => this._refsNotFound(),
954
+ () => this._sliceIdRefsNotFound(),
761
955
  // Check layers
762
956
  () => this._layerBasesNotFound(),
763
957
  () => this._layerSliceIdsTableNotFound(),
@@ -780,11 +974,6 @@ class _BaseValidator {
780
974
  this.errors.hasErrors = this.hasErrors;
781
975
  return this.errors;
782
976
  }
783
- // ######################
784
- // Private
785
- // ######################
786
- tableKeys;
787
- rljsonIndexed;
788
977
  _tableKeysNotLowerCamelCase() {
789
978
  const invalidTableKeys = [];
790
979
  for (const tableKey of this.tableKeys) {
@@ -829,7 +1018,7 @@ class _BaseValidator {
829
1018
  continue;
830
1019
  }
831
1020
  if (!BaseValidator.isValidFieldName(columnName)) {
832
- invalidColumnNames[tableKey] ??= [];
1021
+ invalidColumnNames[tableKey] ?? (invalidColumnNames[tableKey] = []);
833
1022
  invalidColumnNames[tableKey].push(columnName);
834
1023
  hadErrors = true;
835
1024
  }
@@ -1136,43 +1325,89 @@ class _BaseValidator {
1136
1325
  for (const item of tableData) {
1137
1326
  for (const key of Object.keys(item)) {
1138
1327
  if (key.endsWith("Ref")) {
1139
- const targetItemHash = item[key];
1140
- const targetTableKey = key.substring(0, key.length - 3);
1141
- const itemHash = item._hash;
1142
- if (this.tableKeys.indexOf(targetTableKey) === -1) {
1143
- missingRefs.push({
1144
- error: `Target table "${targetTableKey}" not found.`,
1328
+ const targetItemRefs = Array.isArray(item[key]) ? item[key] : [item[key]];
1329
+ for (const targetItemRef of targetItemRefs) {
1330
+ const targetTableKey = typeof targetItemRef !== "string" ? targetItemRef.component : key.substring(0, key.length - 3);
1331
+ const targetItemHash = typeof targetItemRef !== "string" ? targetItemRef.ref : targetItemRef;
1332
+ const itemHash = item._hash;
1333
+ if (this.tableKeys.indexOf(targetTableKey) === -1) {
1334
+ missingRefs.push({
1335
+ error: `Target table "${targetTableKey}" not found.`,
1336
+ sourceTable: tableKey,
1337
+ sourceKey: key,
1338
+ sourceItemHash: itemHash,
1339
+ targetItemHash,
1340
+ targetTable: targetTableKey
1341
+ });
1342
+ continue;
1343
+ }
1344
+ const targetTableIndexed = this.rljsonIndexed[targetTableKey];
1345
+ const referencedItem = targetTableIndexed._data[targetItemHash];
1346
+ if (referencedItem === void 0) {
1347
+ missingRefs.push({
1348
+ sourceTable: tableKey,
1349
+ sourceItemHash: itemHash,
1350
+ sourceKey: key,
1351
+ targetItemHash,
1352
+ targetTable: targetTableKey,
1353
+ error: `Table "${targetTableKey}" has no item with hash "${targetItemHash}"`
1354
+ });
1355
+ }
1356
+ }
1357
+ }
1358
+ }
1359
+ }
1360
+ });
1361
+ if (missingRefs.length > 0) {
1362
+ this.errors.refsNotFound = {
1363
+ error: "Broken references",
1364
+ missingRefs
1365
+ };
1366
+ }
1367
+ }
1368
+ // ...........................................................................
1369
+ _sliceIdRefsNotFound() {
1370
+ const missingSliceIdRefs = [];
1371
+ iterateTablesSync(this.rljson, (tableKey, table) => {
1372
+ const tableData = table._data;
1373
+ for (const item of tableData) {
1374
+ for (const key of Object.keys(item)) {
1375
+ if (key.endsWith("SliceId")) {
1376
+ const targetSliceId = item[key];
1377
+ if (this.tableKeys.indexOf(key) === -1) {
1378
+ missingSliceIdRefs.push({
1145
1379
  sourceTable: tableKey,
1146
- sourceKey: key,
1147
- sourceItemHash: itemHash,
1148
- targetItemHash,
1149
- targetTable: targetTableKey
1380
+ targetSliceId,
1381
+ targetTable: key,
1382
+ error: `Target table "${targetSliceId}" not found.`
1150
1383
  });
1151
1384
  continue;
1152
1385
  }
1153
- const targetTableIndexed = this.rljsonIndexed[targetTableKey];
1154
- const referencedItem = targetTableIndexed._data[targetItemHash];
1155
- if (referencedItem === void 0) {
1156
- missingRefs.push({
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({
1157
1393
  sourceTable: tableKey,
1158
- sourceItemHash: itemHash,
1159
- sourceKey: key,
1160
- targetItemHash,
1161
- targetTable: targetTableKey,
1162
- error: `Table "${targetTableKey}" has no item with hash "${targetItemHash}"`
1394
+ targetSliceId,
1395
+ targetTable: key,
1396
+ error: `Table "${key}" has no sliceId "${targetSliceId}"`
1163
1397
  });
1164
1398
  }
1165
1399
  }
1166
1400
  }
1167
1401
  }
1168
1402
  });
1169
- if (missingRefs.length > 0) {
1403
+ if (missingSliceIdRefs.length > 0) {
1170
1404
  this.errors.refsNotFound = {
1171
1405
  error: "Broken references",
1172
- missingRefs
1406
+ missingRefs: missingSliceIdRefs
1173
1407
  };
1174
1408
  }
1175
1409
  }
1410
+ // ...........................................................................
1176
1411
  _layerBasesNotFound() {
1177
1412
  const brokenLayers = [];
1178
1413
  iterateTablesSync(this.rljson, (tableKey, table) => {
@@ -1487,6 +1722,12 @@ class _BaseValidator {
1487
1722
  const isValidFieldName = (fieldName) => BaseValidator.isValidFieldName(fieldName);
1488
1723
  // @license
1489
1724
  class Validate {
1725
+ constructor() {
1726
+ // ######################
1727
+ // Private
1728
+ // ######################
1729
+ __publicField(this, "_validators", []);
1730
+ }
1490
1731
  addValidator(validator) {
1491
1732
  this._validators.push(validator);
1492
1733
  }
@@ -1515,10 +1756,6 @@ class Validate {
1515
1756
  return acc;
1516
1757
  }, {});
1517
1758
  }
1518
- // ######################
1519
- // Private
1520
- // ######################
1521
- _validators = [];
1522
1759
  }
1523
1760
  export {
1524
1761
  BaseValidator,
@@ -5,7 +5,7 @@
5
5
  // found in the LICENSE file in the root of this package.
6
6
 
7
7
  import { hip } from '@rljson/hash';
8
- import { exampleJsonObject } from '@rljson/json';
8
+ import { exampleJsonObject, Json } from '@rljson/json';
9
9
 
10
10
  import { BuffetsTable } from './content/buffet.ts';
11
11
  import { Cake, CakesTable } from './content/cake.ts';
@@ -157,6 +157,110 @@ export class Example {
157
157
  },
158
158
  };
159
159
  },
160
+ singleSliceIdRef: (): Rljson => {
161
+ return {
162
+ exampleSliceId: {
163
+ _type: 'sliceIds',
164
+ _data: [
165
+ {
166
+ add: ['id0', 'id1'],
167
+ },
168
+ ],
169
+ } as SliceIdsTable,
170
+ exampleComponent: {
171
+ _type: 'components',
172
+ _data: [
173
+ {
174
+ exampleSliceId: 'id0',
175
+ },
176
+ ],
177
+ } as ComponentsTable<Json>,
178
+ };
179
+ },
180
+ singleNamedRef: (): Rljson => {
181
+ return {
182
+ tableA: {
183
+ _type: 'components',
184
+ _data: [
185
+ {
186
+ keyA0: 'a0',
187
+ },
188
+ {
189
+ keyA1: 'a1',
190
+ },
191
+ ],
192
+ },
193
+ tableB: {
194
+ _type: 'components',
195
+ _data: [
196
+ {
197
+ namedRef: { component: 'tableA', ref: 'KFQrf4mEz0UPmUaFHwH4T6' },
198
+ },
199
+ ],
200
+ },
201
+ };
202
+ },
203
+ multiRef: (): Rljson => {
204
+ return {
205
+ tableA: {
206
+ _type: 'components',
207
+ _data: [
208
+ {
209
+ keyA0: 'a0',
210
+ },
211
+ {
212
+ keyA1: 'a1',
213
+ },
214
+ ],
215
+ },
216
+ tableB: {
217
+ _type: 'components',
218
+ _data: [
219
+ {
220
+ tableARef: ['KFQrf4mEz0UPmUaFHwH4T6', 'YPw-pxhqaUOWRFGramr4B1'],
221
+ },
222
+ ],
223
+ },
224
+ };
225
+ },
226
+ multiMixedRef: (): Rljson => {
227
+ return {
228
+ tableA: {
229
+ _type: 'components',
230
+ _data: [
231
+ {
232
+ keyA0: 'a0',
233
+ },
234
+ {
235
+ keyA1: 'a1',
236
+ },
237
+ ],
238
+ },
239
+ tableB: {
240
+ _type: 'components',
241
+ _data: [
242
+ {
243
+ keyB0: 'b0',
244
+ },
245
+ {
246
+ keyB1: 'b1',
247
+ },
248
+ ],
249
+ },
250
+ tableC: {
251
+ _type: 'components',
252
+ _data: [
253
+ {
254
+ tableRef: [
255
+ { component: 'tableA', ref: 'KFQrf4mEz0UPmUaFHwH4T6' },
256
+ { component: 'tableB', ref: 'dXhIygNwNMVPEqFbsFJkn6' },
257
+ ],
258
+ },
259
+ ],
260
+ },
261
+ };
262
+ },
263
+
160
264
  complete: (): Rljson => {
161
265
  const sliceIds = hip<SliceIdsTable>({
162
266
  _type: 'sliceIds',
@@ -289,6 +393,54 @@ export class Example {
289
393
  };
290
394
  },
291
395
 
396
+ missingNamedRef: (): Rljson => {
397
+ return {
398
+ tableA: {
399
+ _type: 'components',
400
+ _data: [
401
+ {
402
+ keyA0: 'a0',
403
+ },
404
+ {
405
+ keyA1: 'a1',
406
+ },
407
+ ],
408
+ },
409
+ tableB: {
410
+ _type: 'components',
411
+ _data: [
412
+ {
413
+ namedRef: { component: 'tableA', ref: 'MISSINGREF' }, // MISSINGREF does not exist in tableA
414
+ },
415
+ ],
416
+ },
417
+ };
418
+ },
419
+
420
+ missingMultiRef: (): Rljson => {
421
+ return {
422
+ tableA: {
423
+ _type: 'components',
424
+ _data: [
425
+ {
426
+ keyA0: 'a0',
427
+ },
428
+ {
429
+ keyA1: 'a1',
430
+ },
431
+ ],
432
+ },
433
+ tableB: {
434
+ _type: 'components',
435
+ _data: [
436
+ {
437
+ tableARef: ['KFQrf4mEz0UPmUaFHwH4T6', 'MISSING'],
438
+ },
439
+ ],
440
+ },
441
+ };
442
+ },
443
+
292
444
  missingReferencedTable: (): Rljson => {
293
445
  return {
294
446
  tableB: {
@@ -301,6 +453,40 @@ export class Example {
301
453
  },
302
454
  };
303
455
  },
456
+
457
+ missingSliceId: (): Rljson => {
458
+ return {
459
+ exampleSliceId: {
460
+ _type: 'sliceIds',
461
+ _data: [
462
+ {
463
+ add: ['id0', 'id1'],
464
+ },
465
+ ],
466
+ } as SliceIdsTable,
467
+ exampleComponent: {
468
+ _type: 'components',
469
+ _data: [
470
+ {
471
+ exampleSliceId: 'id2',
472
+ },
473
+ ],
474
+ } as ComponentsTable<Json>,
475
+ };
476
+ },
477
+
478
+ missingSliceIdTable: (): Rljson => {
479
+ return {
480
+ exampleComponent: {
481
+ _type: 'components',
482
+ _data: [
483
+ {
484
+ exampleSliceId: 'id0',
485
+ },
486
+ ],
487
+ } as ComponentsTable<Json>,
488
+ };
489
+ },
304
490
  },
305
491
 
306
492
  tableCfg: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "description": "The RLJSON data format specification",
5
5
  "homepage": "https://github.com/rljson/rljson",
6
6
  "bugs": "https://github.com/rljson/rljson/issues",