@rljson/rljson 0.0.51 → 0.0.53

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,11 +1,9 @@
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
2
  import { exampleJsonObject, jsonValueTypes, jsonValueType, jsonValueMatchesType } from "@rljson/json";
6
3
  // @license
7
4
  const bakeryExample = () => {
8
5
  const nutritionalValues = hip({
6
+ _type: "components",
9
7
  _data: [
10
8
  {
11
9
  id: "flour",
@@ -27,6 +25,7 @@ const bakeryExample = () => {
27
25
  _hash: ""
28
26
  });
29
27
  const ingredients = hip({
28
+ _type: "components",
30
29
  _data: [
31
30
  {
32
31
  id: "flour",
@@ -38,6 +37,7 @@ const bakeryExample = () => {
38
37
  _hash: ""
39
38
  });
40
39
  const recipeIngredients = hip({
40
+ _type: "components",
41
41
  _data: [
42
42
  {
43
43
  id: "flour",
@@ -49,6 +49,7 @@ const bakeryExample = () => {
49
49
  _hash: ""
50
50
  });
51
51
  const slices = hip({
52
+ _type: "sliceIds",
52
53
  _data: [
53
54
  {
54
55
  add: ["slice0", "slice1"],
@@ -57,6 +58,7 @@ const bakeryExample = () => {
57
58
  ]
58
59
  });
59
60
  const ingredientTypes = hip({
61
+ _type: "sliceIds",
60
62
  _data: [
61
63
  {
62
64
  add: ["flour"],
@@ -65,26 +67,28 @@ const bakeryExample = () => {
65
67
  ]
66
68
  });
67
69
  const recipes = hip({
70
+ _type: "layers",
68
71
  _data: [
69
72
  {
70
73
  id: "tastyCake",
71
- ingredientsTable: "recipeIngredients",
74
+ componentsTable: "recipeIngredients",
72
75
  sliceIdsTable: "ingredientTypes",
73
76
  sliceIdsTableRow: ingredientTypes._data[0]._hash,
74
- assign: {
77
+ add: {
75
78
  flour: recipeIngredients._data[0]._hash
76
79
  },
77
80
  _hash: ""
78
81
  }
79
82
  ]
80
83
  });
81
- const layers = hip({
84
+ const recipeLayers = hip({
85
+ _type: "layers",
82
86
  _data: [
83
87
  {
84
- ingredientsTable: "recipes",
88
+ componentsTable: "recipes",
85
89
  sliceIdsTable: "slices",
86
90
  sliceIdsTableRow: slices._data[0]._hash,
87
- assign: {
91
+ add: {
88
92
  slice0: recipes._data[0]._hash,
89
93
  slice1: recipes._data[0]._hash
90
94
  }
@@ -92,19 +96,20 @@ const bakeryExample = () => {
92
96
  ]
93
97
  });
94
98
  const cakes = hip({
99
+ _type: "cakes",
95
100
  _data: [
96
101
  {
97
102
  id: "cake1",
98
103
  sliceIdsTable: "slices",
99
104
  sliceIdsRow: slices._data[0]._hash,
100
- layersTable: "layers",
101
105
  layers: {
102
- flour: layers._data[0]._hash
106
+ recipeLayers: recipeLayers._data[0]._hash
103
107
  }
104
108
  }
105
109
  ]
106
110
  });
107
111
  const buffets = hip({
112
+ _type: "buffets",
108
113
  _data: [
109
114
  {
110
115
  id: "salesCounter",
@@ -122,7 +127,7 @@ const bakeryExample = () => {
122
127
  cakes,
123
128
  slices,
124
129
  ingredientTypes,
125
- layers,
130
+ recipeLayers,
126
131
  recipes,
127
132
  recipeIngredients,
128
133
  ingredients,
@@ -135,9 +140,9 @@ const exampleBuffetsTable = () => bakeryExample().buffets;
135
140
  // @license
136
141
  const exampleCakesTable = () => bakeryExample().cakes;
137
142
  // @license
138
- const exampleIngredientsTable = () => bakeryExample().nutritionalValues;
143
+ const exampleComponentsTable = () => bakeryExample().nutritionalValues;
139
144
  // @license
140
- const exampleLayersTable = () => bakeryExample().layers;
145
+ const exampleLayersTable = () => bakeryExample().recipeLayers;
141
146
  // @license
142
147
  const exampleRevision = () => ({
143
148
  table: "nutritionalValues",
@@ -149,230 +154,120 @@ const exampleRevision = () => ({
149
154
  // @license
150
155
  const exampleSliceIdsTable = () => bakeryExample().slices;
151
156
  // @license
152
- const _Example = class _Example {
153
- };
154
- __publicField(_Example, "ok", {
155
- bakery: () => bakeryExample(),
156
- empty: () => {
157
- return {};
158
- },
159
- binary: () => {
160
- return {
161
- table: {
162
- _data: [
163
- { a: false, b: false },
164
- { a: false, b: true },
165
- { a: true, b: false },
166
- { a: true, b: true }
167
- ]
168
- }
169
- };
170
- },
171
- singleRow: () => {
172
- const tableCfgs = hip({
173
- _hash: "",
174
- _data: [
175
- {
176
- version: 0,
177
- _hash: "",
178
- key: "table",
179
- type: "ingredients",
180
- isHead: false,
181
- isRoot: false,
182
- isShared: true,
183
- columns: [
184
- {
185
- key: "int",
186
- type: "number"
187
- },
188
- {
189
- key: "double",
190
- type: "number"
191
- },
192
- {
193
- key: "string",
194
- type: "string"
195
- },
196
- {
197
- key: "boolean",
198
- type: "boolean"
199
- },
200
- {
201
- key: "null",
202
- type: "string"
203
- },
204
- {
205
- key: "jsonArray",
206
- type: "jsonArray"
207
- },
208
- {
209
- key: "json",
210
- type: "json"
211
- },
212
- {
213
- key: "jsonValue",
214
- type: "jsonValue"
215
- }
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 }
216
172
  ]
217
173
  }
218
- ]
219
- });
220
- const result = {
221
- tableCfgs,
222
- table: {
223
- _tableCfg: tableCfgs._data[0]._hash,
224
- _data: [exampleJsonObject()],
225
- _hash: ""
226
- }
227
- };
228
- return result;
229
- },
230
- multipleRows: () => {
231
- return {
232
- table: {
233
- _data: [
234
- {
235
- string: "str0",
236
- boolean: true,
237
- number: 1,
238
- array: [1, "str0", true, { a: { b: "c" } }],
239
- object: { a: { b: "c" } }
240
- },
241
- {
242
- string: "str1",
243
- boolean: true,
244
- number: 1,
245
- array: [1, "str1", true, { a: { b: "c" } }],
246
- object: { a: { b: "c" } }
247
- },
248
- {
249
- string: "str2",
250
- boolean: false,
251
- number: 1,
252
- array: [1, "str1", true, { a: { b: "c" } }],
253
- object: { d: { e: "f" } }
254
- }
255
- ]
256
- }
257
- };
258
- },
259
- singleRef: () => {
260
- return {
261
- tableA: {
262
- _data: [
263
- {
264
- keyA0: "a0"
265
- },
266
- {
267
- keyA1: "a1"
268
- }
269
- ]
270
- },
271
- tableB: {
174
+ };
175
+ },
176
+ singleRow: () => {
177
+ const tableCfgs = hip({
178
+ _hash: "",
179
+ _type: "tableCfgs",
272
180
  _data: [
273
181
  {
274
- tableARef: "KFQrf4mEz0UPmUaFHwH4T6"
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
+ }
222
+ ]
275
223
  }
276
224
  ]
277
- }
278
- };
279
- },
280
- complete: () => {
281
- const sliceIds = hip({
282
- _data: [
283
- {
284
- add: ["id0", "id1"]
225
+ });
226
+ const result = {
227
+ tableCfgs,
228
+ table: {
229
+ _tableCfg: tableCfgs._data[0]._hash,
230
+ _type: "components",
231
+ _data: [exampleJsonObject()],
232
+ _hash: ""
285
233
  }
286
- ]
287
- });
288
- const ingredients = hip({
289
- _data: [{ a: "0" }, { a: "1" }]
290
- });
291
- const ingredient0 = ingredients._data[0];
292
- const ingredient1 = ingredients._data[1];
293
- const layer0 = hip({
294
- sliceIdsTable: "sliceIds",
295
- sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
296
- ingredientsTable: "ingredients",
297
- assign: {
298
- id0: ingredient0._hash,
299
- id1: ingredient1._hash
300
- }
301
- });
302
- const layer1 = hip({
303
- base: layer0._hash,
304
- sliceIdsTable: "sliceIds",
305
- sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
306
- ingredientsTable: "ingredients",
307
- assign: {
308
- id0: ingredient0._hash,
309
- id1: ingredient1._hash
310
- }
311
- });
312
- const layers = hip({
313
- _data: [layer0, layer1]
314
- });
315
- const cake = hip({
316
- sliceIdsTable: "sliceIds",
317
- sliceIdsRow: sliceIds._data[0]._hash,
318
- layersTable: "layers",
319
- layers: {
320
- layer0: layer0._hash,
321
- layer1: layer1._hash
322
- }
323
- });
324
- const cakes = hip({
325
- _data: [cake]
326
- });
327
- const buffets = hip({
328
- _data: [
329
- {
330
- items: [
234
+ };
235
+ return result;
236
+ },
237
+ multipleRows: () => {
238
+ return {
239
+ table: {
240
+ _type: "components",
241
+ _data: [
242
+ {
243
+ string: "str0",
244
+ boolean: true,
245
+ number: 1,
246
+ array: [1, "str0", true, { a: { b: "c" } }],
247
+ object: { a: { b: "c" } }
248
+ },
331
249
  {
332
- table: "cakes",
333
- ref: cakes._data[0]._hash
250
+ string: "str1",
251
+ boolean: true,
252
+ number: 1,
253
+ array: [1, "str1", true, { a: { b: "c" } }],
254
+ object: { a: { b: "c" } }
334
255
  },
335
256
  {
336
- table: "layers",
337
- ref: layer0._hash
257
+ string: "str2",
258
+ boolean: false,
259
+ number: 1,
260
+ array: [1, "str1", true, { a: { b: "c" } }],
261
+ object: { d: { e: "f" } }
338
262
  }
339
263
  ]
340
264
  }
341
- ]
342
- });
343
- return {
344
- sliceIds,
345
- ingredients,
346
- layers,
347
- cakes,
348
- buffets
349
- };
350
- }
351
- });
352
- __publicField(_Example, "broken", {
353
- base: {
354
- brokenTableKey: () => {
355
- return {
356
- brok$en: {
357
- _data: []
358
- }
359
- };
360
- },
361
- missingData: () => {
362
- return {
363
- table: {}
364
265
  };
365
266
  },
366
- dataNotBeingAnArray: () => {
367
- return {
368
- table: {
369
- _data: {}
370
- }
371
- };
372
- },
373
- missingRef: () => {
267
+ singleRef: () => {
374
268
  return {
375
269
  tableA: {
270
+ _type: "components",
376
271
  _data: [
377
272
  {
378
273
  keyA0: "a0"
@@ -383,128 +278,248 @@ __publicField(_Example, "broken", {
383
278
  ]
384
279
  },
385
280
  tableB: {
281
+ _type: "components",
386
282
  _data: [
387
283
  {
388
- tableARef: "MISSINGREF"
389
- // MISSINGREF does not exist in tableA
284
+ tableARef: "KFQrf4mEz0UPmUaFHwH4T6"
390
285
  }
391
286
  ]
392
287
  }
393
288
  };
394
289
  },
395
- missingReferencedTable: () => {
396
- return {
397
- tableB: {
398
- _data: [
399
- {
400
- tableARef: "MISSINGREF"
401
- // tableA is missing
402
- }
403
- ]
404
- }
405
- };
406
- }
407
- },
408
- tableCfg: {
409
- wrongType: () => {
410
- const result = _Example.ok.singleRow();
411
- const columns = result.tableCfgs._data[0].columns;
412
- const intColumn = columns.find((c) => c.key === "int");
413
- intColumn.type = "numberBroken";
414
- return hip(result, {
415
- updateExistingHashes: true,
416
- throwOnWrongHashes: false
290
+ complete: () => {
291
+ const sliceIds = hip({
292
+ _type: "sliceIds",
293
+ _data: [
294
+ {
295
+ add: ["id0", "id1"]
296
+ }
297
+ ]
417
298
  });
418
- }
419
- },
420
- layers: {
421
- missingBase: () => {
422
- const result = _Example.ok.complete();
423
- const layer1 = result.layers._data[1];
424
- layer1.base = "MISSING";
425
- return hip(result, {
426
- updateExistingHashes: true,
427
- throwOnWrongHashes: false
299
+ const components = hip({
300
+ _type: "components",
301
+ _data: [{ a: "0" }, { a: "1" }]
428
302
  });
429
- },
430
- missingSliceIdSet: () => {
431
- const result = _Example.ok.complete();
432
- const layer1 = result.layers._data[1];
433
- layer1.sliceIdsTableRow = "MISSING1";
434
- return hip(result, {
435
- updateExistingHashes: true,
436
- throwOnWrongHashes: false
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
312
+ }
437
313
  });
438
- },
439
- missingAssignedIngredientTable: () => {
440
- const result = _Example.ok.complete();
441
- delete result.ingredients;
442
- return result;
443
- },
444
- missingAssignedIngredient: () => {
445
- const result = _Example.ok.complete();
446
- result.ingredients._data.splice(1, 2);
447
- return hip(result, {
448
- updateExistingHashes: true,
449
- throwOnWrongHashes: false
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
322
+ }
450
323
  });
451
- }
452
- },
453
- cakes: {
454
- missingSliceIdSet: () => {
455
- const result = _Example.ok.complete();
456
- result.cakes._data[0].sliceIdsRow = "MISSING";
457
- hip(result.cakes, {
458
- updateExistingHashes: true,
459
- throwOnWrongHashes: false
324
+ const abLayers = hip({
325
+ _type: "layers",
326
+ _data: [abLayer0, abLayer1]
460
327
  });
461
- result.buffets._data[0].items[0].ref = result.cakes._data[0]._hash;
462
- hip(result.buffets, {
463
- updateExistingHashes: true,
464
- throwOnWrongHashes: false
328
+ const cake = hip({
329
+ sliceIdsTable: "sliceIds",
330
+ sliceIdsRow: sliceIds._data[0]._hash,
331
+ layers: {
332
+ abLayers: abLayer1._hash
333
+ }
465
334
  });
466
- return result;
467
- },
468
- missingLayersTable: () => {
469
- const result = _Example.ok.complete();
470
- result.cakes._data[0].layersTable = "MISSING";
471
- hip(result.cakes, {
472
- updateExistingHashes: true,
473
- throwOnWrongHashes: false
335
+ const cakes = hip({
336
+ _type: "cakes",
337
+ _data: [cake]
474
338
  });
475
- return result;
476
- },
477
- missingCakeLayer: () => {
478
- const result = _Example.ok.complete();
479
- result.cakes._data[0].layers["layer0"] = "MISSING0";
480
- result.cakes._data[0].layers["layer1"] = "MISSING1";
481
- hip(result.cakes, {
482
- updateExistingHashes: true,
483
- throwOnWrongHashes: false
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
+ ]
484
355
  });
485
- return result;
356
+ return {
357
+ sliceIds,
358
+ components,
359
+ abLayers,
360
+ cakes,
361
+ buffets
362
+ };
486
363
  }
487
- },
488
- buffets: {
489
- missingTable: () => {
490
- const result = _Example.ok.complete();
491
- const buffet = result.buffets._data[0];
492
- buffet.items[0].table = "MISSING0";
493
- buffet.items[1].table = "MISSING1";
494
- hip(result, { updateExistingHashes: true, throwOnWrongHashes: false });
495
- return result;
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
+ }
496
423
  },
497
- missingItems: () => {
498
- const result = _Example.ok.complete();
499
- const buffet = result.buffets._data[0];
500
- buffet.items[0].ref = "MISSING0";
501
- buffet.items[1].ref = "MISSING1";
502
- hip(result, { updateExistingHashes: true, throwOnWrongHashes: false });
503
- return result;
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
+ }
435
+ },
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
+ }
468
+ },
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
+ }
502
+ },
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
+ }
504
520
  }
505
- }
506
- });
507
- let Example = _Example;
521
+ };
522
+ }
508
523
  // @license
509
524
  const throwOnInvalidTableCfg = (tableCfg) => {
510
525
  if (tableCfg.columns.length < 2) {
@@ -583,8 +598,8 @@ const addColumnsToTableCfg = (tableCfg, columns) => {
583
598
  const exampleTableCfgTable = () => Example.ok.singleRow().tableCfgs;
584
599
  const exampleTableCfg = (tableCfg = void 0) => {
585
600
  return {
586
- key: (tableCfg == null ? void 0 : tableCfg.key) ?? "table",
587
- columns: (tableCfg == null ? void 0 : tableCfg.columns) ?? [
601
+ key: tableCfg?.key ?? "table",
602
+ columns: tableCfg?.columns ?? [
588
603
  {
589
604
  key: "_hash",
590
605
  type: "string"
@@ -598,36 +613,13 @@ const exampleTableCfg = (tableCfg = void 0) => {
598
613
  type: "number"
599
614
  }
600
615
  ],
601
- type: (tableCfg == null ? void 0 : tableCfg.type) ?? "ingredients",
616
+ type: tableCfg?.type ?? "components",
602
617
  isHead: true,
603
618
  isRoot: true,
604
619
  isShared: false
605
620
  };
606
621
  };
607
622
  // @license
608
- const rljsonIndexed = (rljson) => {
609
- const result = {};
610
- for (const key in rljson) {
611
- const slice = rljson[key];
612
- if (typeof slice != "object") {
613
- result[key] = slice;
614
- continue;
615
- }
616
- const dataIndexed = {};
617
- result[key] = { ...slice };
618
- if (!Array.isArray(slice._data)) {
619
- continue;
620
- }
621
- for (const row of slice._data) {
622
- const hashedRow = row._hash ? row : hsh(row);
623
- const hash = hashedRow._hash;
624
- dataIndexed[hash] = hashedRow;
625
- }
626
- result[key]._data = dataIndexed;
627
- }
628
- return result;
629
- };
630
- // @license
631
623
  const reservedFieldNames = ["_data"];
632
624
  const reservedTableKeys = [
633
625
  "_hash",
@@ -668,12 +660,28 @@ const iterateTables = async (rljson, callback) => {
668
660
  }
669
661
  };
670
662
  // @license
663
+ const removeDuplicates = (rljson) => {
664
+ const result = {};
665
+ for (const key in rljson) {
666
+ if (key.startsWith("_")) continue;
667
+ const table = rljson[key];
668
+ const data = table._data;
669
+ const newData = Array.from(
670
+ new Map(data.map((row) => [row._hash, row])).values()
671
+ );
672
+ result[key] = { ...table, _data: newData };
673
+ }
674
+ return hip(result, { throwOnWrongHashes: false });
675
+ };
676
+ // @license
671
677
  const contentTypes = [
672
678
  "buffets",
673
679
  "cakes",
674
680
  "layers",
675
681
  "sliceIds",
676
- "ingredients"
682
+ "components",
683
+ "revisions",
684
+ "tableCfgs"
677
685
  ];
678
686
  const exampleTypedefs = () => {
679
687
  return {
@@ -684,10 +692,31 @@ const exampleTypedefs = () => {
684
692
  };
685
693
  };
686
694
  // @license
687
- class BaseValidator {
688
- constructor() {
689
- __publicField(this, "name", "base");
695
+ const rljsonIndexed = (rljson) => {
696
+ const result = {};
697
+ for (const key in rljson) {
698
+ const slice = rljson[key];
699
+ if (typeof slice != "object") {
700
+ result[key] = slice;
701
+ continue;
702
+ }
703
+ const dataIndexed = {};
704
+ result[key] = { ...slice };
705
+ if (!Array.isArray(slice._data)) {
706
+ continue;
707
+ }
708
+ for (const row of slice._data) {
709
+ const hashedRow = row._hash ? row : hsh(row);
710
+ const hash = hashedRow._hash;
711
+ dataIndexed[hash] = hashedRow;
712
+ }
713
+ result[key]._data = dataIndexed;
690
714
  }
715
+ return result;
716
+ };
717
+ // @license
718
+ class BaseValidator {
719
+ name = "base";
691
720
  async validate(rljson) {
692
721
  return this.validateSync(rljson);
693
722
  }
@@ -700,18 +729,13 @@ class BaseValidator {
700
729
  }
701
730
  class _BaseValidator {
702
731
  constructor(rljson) {
703
- __publicField(this, "errors", { hasErrors: false });
704
- // ######################
705
- // Private
706
- // ######################
707
- __publicField(this, "tableKeys");
708
- __publicField(this, "rljsonIndexed");
709
732
  this.rljson = rljson;
710
733
  this.tableKeys = Object.keys(this.rljson).filter(
711
734
  (table) => !table.startsWith("_")
712
735
  );
713
736
  this.rljsonIndexed = rljsonIndexed(rljson);
714
737
  }
738
+ errors = { hasErrors: false };
715
739
  get hasErrors() {
716
740
  return Object.keys(this.errors).length > 1;
717
741
  }
@@ -738,7 +762,7 @@ class _BaseValidator {
738
762
  () => this._layerBasesNotFound(),
739
763
  () => this._layerSliceIdsTableNotFound(),
740
764
  () => this._layerSliceIdsRowNotFound(),
741
- () => this._layerIngredientAssignmentsNotFound(),
765
+ () => this._layerComponentAssignmentsNotFound(),
742
766
  () => this._layerAssignmentsDoNotMatchSliceIds(),
743
767
  // Check cakes
744
768
  () => this._cakeSliceIdsTableNotFound(),
@@ -756,6 +780,11 @@ class _BaseValidator {
756
780
  this.errors.hasErrors = this.hasErrors;
757
781
  return this.errors;
758
782
  }
783
+ // ######################
784
+ // Private
785
+ // ######################
786
+ tableKeys;
787
+ rljsonIndexed;
759
788
  _tableKeysNotLowerCamelCase() {
760
789
  const invalidTableKeys = [];
761
790
  for (const tableKey of this.tableKeys) {
@@ -800,7 +829,7 @@ class _BaseValidator {
800
829
  continue;
801
830
  }
802
831
  if (!BaseValidator.isValidFieldName(columnName)) {
803
- invalidColumnNames[tableKey] ?? (invalidColumnNames[tableKey] = []);
832
+ invalidColumnNames[tableKey] ??= [];
804
833
  invalidColumnNames[tableKey].push(columnName);
805
834
  hadErrors = true;
806
835
  }
@@ -1171,7 +1200,6 @@ class _BaseValidator {
1171
1200
  };
1172
1201
  }
1173
1202
  }
1174
- /* v8 ignore start */
1175
1203
  _layerSliceIdsTableNotFound() {
1176
1204
  const brokenLayers = [];
1177
1205
  iterateTablesSync(this.rljson, (tableKey, table) => {
@@ -1224,8 +1252,8 @@ class _BaseValidator {
1224
1252
  };
1225
1253
  }
1226
1254
  }
1227
- _layerIngredientAssignmentsNotFound() {
1228
- const missingIngredientTables = [];
1255
+ _layerComponentAssignmentsNotFound() {
1256
+ const missingComponentTables = [];
1229
1257
  const brokenAssignments = [];
1230
1258
  iterateTablesSync(this.rljson, (tableKey, table) => {
1231
1259
  if (table._type !== "layers") {
@@ -1233,43 +1261,43 @@ class _BaseValidator {
1233
1261
  }
1234
1262
  const layersTable = table;
1235
1263
  for (const layer of layersTable._data) {
1236
- const ingredientTableKey = layer.ingredientsTable;
1237
- const ingredientsTable = this.rljsonIndexed[ingredientTableKey];
1238
- if (!ingredientsTable) {
1239
- missingIngredientTables.push({
1264
+ const componentTableKey = layer.componentsTable;
1265
+ const componentsTable = this.rljsonIndexed[componentTableKey];
1266
+ if (!componentsTable) {
1267
+ missingComponentTables.push({
1240
1268
  brokenLayer: layer._hash,
1241
1269
  layersTable: tableKey,
1242
- missingIngredientTable: ingredientTableKey
1270
+ missingComponentTable: componentTableKey
1243
1271
  });
1244
1272
  continue;
1245
1273
  }
1246
- const assignments = layer.assign;
1274
+ const assignments = layer.add;
1247
1275
  for (const sliceId in assignments) {
1248
1276
  if (sliceId.startsWith("_")) {
1249
1277
  continue;
1250
1278
  }
1251
- const ingredientHash = assignments[sliceId];
1252
- if (!ingredientsTable._data[ingredientHash]) {
1279
+ const componentHash = assignments[sliceId];
1280
+ if (!componentsTable._data[componentHash]) {
1253
1281
  brokenAssignments.push({
1254
1282
  layersTable: tableKey,
1255
1283
  brokenLayer: layer._hash,
1256
- referencedIngredientTable: ingredientTableKey,
1284
+ referencedComponentTable: componentTableKey,
1257
1285
  brokenAssignment: sliceId,
1258
- missingIngredient: ingredientHash
1286
+ missingComponent: componentHash
1259
1287
  });
1260
1288
  }
1261
1289
  }
1262
1290
  }
1263
1291
  });
1264
- if (missingIngredientTables.length > 0) {
1265
- this.errors.layerIngredientTablesNotFound = {
1266
- error: "Layer ingredient tables do not exist",
1267
- layers: missingIngredientTables
1292
+ if (missingComponentTables.length > 0) {
1293
+ this.errors.layerComponentTablesNotFound = {
1294
+ error: "Layer component tables do not exist",
1295
+ layers: missingComponentTables
1268
1296
  };
1269
1297
  }
1270
1298
  if (brokenAssignments.length > 0) {
1271
- this.errors.layerIngredientAssignmentsNotFound = {
1272
- error: "Layer ingredient assignments are broken",
1299
+ this.errors.layerComponentAssignmentsNotFound = {
1300
+ error: "Layer component assignments are broken",
1273
1301
  brokenAssignments
1274
1302
  };
1275
1303
  }
@@ -1285,7 +1313,7 @@ class _BaseValidator {
1285
1313
  const sliceIdsTable = this.rljsonIndexed[layer.sliceIdsTable];
1286
1314
  const sliceIdsRow = sliceIdsTable._data[layer.sliceIdsTableRow];
1287
1315
  const sliceIds = sliceIdsRow.add;
1288
- const sliceIdsInLayer = Object.keys(layer.assign);
1316
+ const sliceIdsInLayer = Object.keys(layer.add);
1289
1317
  const unassignedSliceIds = [];
1290
1318
  for (const expectedSliceId of sliceIds) {
1291
1319
  if (sliceIdsInLayer.indexOf(expectedSliceId) === -1) {
@@ -1370,27 +1398,25 @@ class _BaseValidator {
1370
1398
  }
1371
1399
  const cakesTable = table;
1372
1400
  for (const cake of cakesTable._data) {
1373
- const layersTableKey = cake.layersTable;
1374
- const layersTable = this.rljsonIndexed[layersTableKey];
1375
- if (!layersTable) {
1376
- missingLayerTables.push({
1377
- cakeTable: tableKey,
1378
- brokenCake: cake._hash,
1379
- missingLayersTable: layersTableKey
1380
- });
1381
- continue;
1382
- }
1383
- for (const layerKey in cake.layers) {
1384
- if (layerKey.startsWith("_")) {
1401
+ for (const layersTableKey in cake.layers) {
1402
+ if (layersTableKey.startsWith("_")) {
1385
1403
  continue;
1386
1404
  }
1387
- const layerRef = cake.layers[layerKey];
1405
+ const layersTable = this.rljsonIndexed[layersTableKey];
1406
+ if (!layersTable) {
1407
+ missingLayerTables.push({
1408
+ cakeTable: tableKey,
1409
+ brokenCake: cake._hash,
1410
+ missingLayersTable: layersTableKey
1411
+ });
1412
+ continue;
1413
+ }
1414
+ const layerRef = cake.layers[layersTableKey];
1388
1415
  const layer = layersTable._data[layerRef];
1389
1416
  if (!layer) {
1390
1417
  missingCakeLayers.push({
1391
1418
  cakeTable: tableKey,
1392
1419
  brokenCake: cake._hash,
1393
- brokenLayerName: layerKey,
1394
1420
  layersTable: layersTableKey,
1395
1421
  missingLayer: layerRef
1396
1422
  });
@@ -1457,17 +1483,10 @@ class _BaseValidator {
1457
1483
  };
1458
1484
  }
1459
1485
  }
1460
- /* v8 ignore end */
1461
1486
  }
1462
1487
  const isValidFieldName = (fieldName) => BaseValidator.isValidFieldName(fieldName);
1463
1488
  // @license
1464
1489
  class Validate {
1465
- constructor() {
1466
- // ######################
1467
- // Private
1468
- // ######################
1469
- __publicField(this, "_validators", []);
1470
- }
1471
1490
  addValidator(validator) {
1472
1491
  this._validators.push(validator);
1473
1492
  }
@@ -1496,6 +1515,10 @@ class Validate {
1496
1515
  return acc;
1497
1516
  }, {});
1498
1517
  }
1518
+ // ######################
1519
+ // Private
1520
+ // ######################
1521
+ _validators = [];
1499
1522
  }
1500
1523
  export {
1501
1524
  BaseValidator,
@@ -1506,7 +1529,7 @@ export {
1506
1529
  contentTypes,
1507
1530
  exampleBuffetsTable,
1508
1531
  exampleCakesTable,
1509
- exampleIngredientsTable,
1532
+ exampleComponentsTable,
1510
1533
  exampleLayersTable,
1511
1534
  exampleRevision,
1512
1535
  exampleRljson,
@@ -1517,9 +1540,9 @@ export {
1517
1540
  isValidFieldName,
1518
1541
  iterateTables,
1519
1542
  iterateTablesSync,
1543
+ removeDuplicates,
1520
1544
  reservedFieldNames,
1521
1545
  reservedTableKeys,
1522
- rljsonIndexed,
1523
1546
  throwOnInvalidTableCfg,
1524
1547
  validateRljsonAgainstTableCfg
1525
1548
  };