@rljson/rljson 0.0.52 → 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/index.d.ts +1 -0
- package/dist/rljson.js +349 -342
- package/dist/tools/remove-duplicates.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './content/table-cfg.ts';
|
|
|
8
8
|
export * from './example.ts';
|
|
9
9
|
export * from './example/bakery-example.ts';
|
|
10
10
|
export * from './rljson.ts';
|
|
11
|
+
export * from './tools/remove-duplicates.ts';
|
|
11
12
|
export * from './typedefs.ts';
|
|
12
13
|
export * from './validate/base-validator.ts';
|
|
13
14
|
export * from './validate/validate.ts';
|
package/dist/rljson.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
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
|
|
@@ -157,237 +154,117 @@ const exampleRevision = () => ({
|
|
|
157
154
|
// @license
|
|
158
155
|
const exampleSliceIdsTable = () => bakeryExample().slices;
|
|
159
156
|
// @license
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
}
|
|
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 }
|
|
226
172
|
]
|
|
227
173
|
}
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
tableCfgs
|
|
232
|
-
|
|
233
|
-
|
|
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",
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
singleRow: () => {
|
|
177
|
+
const tableCfgs = hip({
|
|
178
|
+
_hash: "",
|
|
179
|
+
_type: "tableCfgs",
|
|
286
180
|
_data: [
|
|
287
181
|
{
|
|
288
|
-
|
|
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
|
+
]
|
|
289
223
|
}
|
|
290
224
|
]
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
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: ""
|
|
300
233
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const abLayer0 = hip({
|
|
310
|
-
sliceIdsTable: "sliceIds",
|
|
311
|
-
sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
|
|
312
|
-
componentsTable: "components",
|
|
313
|
-
add: {
|
|
314
|
-
id0: component0._hash,
|
|
315
|
-
id1: component1._hash
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
const abLayer1 = hip({
|
|
319
|
-
base: abLayer0._hash,
|
|
320
|
-
sliceIdsTable: "sliceIds",
|
|
321
|
-
sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
|
|
322
|
-
componentsTable: "components",
|
|
323
|
-
add: {
|
|
324
|
-
id0: component0._hash,
|
|
325
|
-
id1: component1._hash
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
const abLayers = hip({
|
|
329
|
-
_type: "layers",
|
|
330
|
-
_data: [abLayer0, abLayer1]
|
|
331
|
-
});
|
|
332
|
-
const cake = hip({
|
|
333
|
-
sliceIdsTable: "sliceIds",
|
|
334
|
-
sliceIdsRow: sliceIds._data[0]._hash,
|
|
335
|
-
layers: {
|
|
336
|
-
abLayers: abLayer1._hash
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
const cakes = hip({
|
|
340
|
-
_type: "cakes",
|
|
341
|
-
_data: [cake]
|
|
342
|
-
});
|
|
343
|
-
const buffets = hip({
|
|
344
|
-
_type: "buffets",
|
|
345
|
-
_data: [
|
|
346
|
-
{
|
|
347
|
-
items: [
|
|
234
|
+
};
|
|
235
|
+
return result;
|
|
236
|
+
},
|
|
237
|
+
multipleRows: () => {
|
|
238
|
+
return {
|
|
239
|
+
table: {
|
|
240
|
+
_type: "components",
|
|
241
|
+
_data: [
|
|
348
242
|
{
|
|
349
|
-
|
|
350
|
-
|
|
243
|
+
string: "str0",
|
|
244
|
+
boolean: true,
|
|
245
|
+
number: 1,
|
|
246
|
+
array: [1, "str0", true, { a: { b: "c" } }],
|
|
247
|
+
object: { a: { b: "c" } }
|
|
351
248
|
},
|
|
352
249
|
{
|
|
353
|
-
|
|
354
|
-
|
|
250
|
+
string: "str1",
|
|
251
|
+
boolean: true,
|
|
252
|
+
number: 1,
|
|
253
|
+
array: [1, "str1", true, { a: { b: "c" } }],
|
|
254
|
+
object: { a: { b: "c" } }
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
string: "str2",
|
|
258
|
+
boolean: false,
|
|
259
|
+
number: 1,
|
|
260
|
+
array: [1, "str1", true, { a: { b: "c" } }],
|
|
261
|
+
object: { d: { e: "f" } }
|
|
355
262
|
}
|
|
356
263
|
]
|
|
357
264
|
}
|
|
358
|
-
]
|
|
359
|
-
});
|
|
360
|
-
return {
|
|
361
|
-
sliceIds,
|
|
362
|
-
components,
|
|
363
|
-
abLayers,
|
|
364
|
-
cakes,
|
|
365
|
-
buffets
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
__publicField(_Example, "broken", {
|
|
370
|
-
base: {
|
|
371
|
-
brokenTableKey: () => {
|
|
372
|
-
return {
|
|
373
|
-
brok$en: {
|
|
374
|
-
_data: []
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
},
|
|
378
|
-
missingData: () => {
|
|
379
|
-
return {
|
|
380
|
-
table: {}
|
|
381
265
|
};
|
|
382
266
|
},
|
|
383
|
-
|
|
384
|
-
return {
|
|
385
|
-
table: {
|
|
386
|
-
_data: {}
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
},
|
|
390
|
-
missingRef: () => {
|
|
267
|
+
singleRef: () => {
|
|
391
268
|
return {
|
|
392
269
|
tableA: {
|
|
393
270
|
_type: "components",
|
|
@@ -404,126 +281,245 @@ __publicField(_Example, "broken", {
|
|
|
404
281
|
_type: "components",
|
|
405
282
|
_data: [
|
|
406
283
|
{
|
|
407
|
-
tableARef: "
|
|
408
|
-
// MISSINGREF does not exist in tableA
|
|
284
|
+
tableARef: "KFQrf4mEz0UPmUaFHwH4T6"
|
|
409
285
|
}
|
|
410
286
|
]
|
|
411
287
|
}
|
|
412
288
|
};
|
|
413
289
|
},
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
]
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
},
|
|
428
|
-
tableCfg: {
|
|
429
|
-
wrongType: () => {
|
|
430
|
-
const result = _Example.ok.singleRow();
|
|
431
|
-
const columns = result.tableCfgs._data[0].columns;
|
|
432
|
-
const intColumn = columns.find((c) => c.key === "int");
|
|
433
|
-
intColumn.type = "numberBroken";
|
|
434
|
-
return hip(result, {
|
|
435
|
-
updateExistingHashes: true,
|
|
436
|
-
throwOnWrongHashes: false
|
|
290
|
+
complete: () => {
|
|
291
|
+
const sliceIds = hip({
|
|
292
|
+
_type: "sliceIds",
|
|
293
|
+
_data: [
|
|
294
|
+
{
|
|
295
|
+
add: ["id0", "id1"]
|
|
296
|
+
}
|
|
297
|
+
]
|
|
437
298
|
});
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
missingBase: () => {
|
|
442
|
-
const result = _Example.ok.complete();
|
|
443
|
-
const layer1 = result.abLayers._data[1];
|
|
444
|
-
layer1.base = "MISSING";
|
|
445
|
-
return hip(result, {
|
|
446
|
-
updateExistingHashes: true,
|
|
447
|
-
throwOnWrongHashes: false
|
|
299
|
+
const components = hip({
|
|
300
|
+
_type: "components",
|
|
301
|
+
_data: [{ a: "0" }, { a: "1" }]
|
|
448
302
|
});
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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
|
+
}
|
|
457
313
|
});
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
return hip(result, {
|
|
468
|
-
updateExistingHashes: true,
|
|
469
|
-
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
|
+
}
|
|
470
323
|
});
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
missingSliceIdSet: () => {
|
|
475
|
-
const result = _Example.ok.complete();
|
|
476
|
-
result.cakes._data[0].sliceIdsRow = "MISSING";
|
|
477
|
-
hip(result.cakes, {
|
|
478
|
-
updateExistingHashes: true,
|
|
479
|
-
throwOnWrongHashes: false
|
|
324
|
+
const abLayers = hip({
|
|
325
|
+
_type: "layers",
|
|
326
|
+
_data: [abLayer0, abLayer1]
|
|
480
327
|
});
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
328
|
+
const cake = hip({
|
|
329
|
+
sliceIdsTable: "sliceIds",
|
|
330
|
+
sliceIdsRow: sliceIds._data[0]._hash,
|
|
331
|
+
layers: {
|
|
332
|
+
abLayers: abLayer1._hash
|
|
333
|
+
}
|
|
485
334
|
});
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
const result = _Example.ok.complete();
|
|
490
|
-
result.cakes._data[0].layers = { MISSING: "HASH" };
|
|
491
|
-
hip(result.cakes, {
|
|
492
|
-
updateExistingHashes: true,
|
|
493
|
-
throwOnWrongHashes: false
|
|
335
|
+
const cakes = hip({
|
|
336
|
+
_type: "cakes",
|
|
337
|
+
_data: [cake]
|
|
494
338
|
});
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
+
]
|
|
503
355
|
});
|
|
504
|
-
return
|
|
356
|
+
return {
|
|
357
|
+
sliceIds,
|
|
358
|
+
components,
|
|
359
|
+
abLayers,
|
|
360
|
+
cakes,
|
|
361
|
+
buffets
|
|
362
|
+
};
|
|
505
363
|
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
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
|
+
}
|
|
515
423
|
},
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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
|
+
}
|
|
523
520
|
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
let Example = _Example;
|
|
521
|
+
};
|
|
522
|
+
}
|
|
527
523
|
// @license
|
|
528
524
|
const throwOnInvalidTableCfg = (tableCfg) => {
|
|
529
525
|
if (tableCfg.columns.length < 2) {
|
|
@@ -602,8 +598,8 @@ const addColumnsToTableCfg = (tableCfg, columns) => {
|
|
|
602
598
|
const exampleTableCfgTable = () => Example.ok.singleRow().tableCfgs;
|
|
603
599
|
const exampleTableCfg = (tableCfg = void 0) => {
|
|
604
600
|
return {
|
|
605
|
-
key:
|
|
606
|
-
columns:
|
|
601
|
+
key: tableCfg?.key ?? "table",
|
|
602
|
+
columns: tableCfg?.columns ?? [
|
|
607
603
|
{
|
|
608
604
|
key: "_hash",
|
|
609
605
|
type: "string"
|
|
@@ -617,7 +613,7 @@ const exampleTableCfg = (tableCfg = void 0) => {
|
|
|
617
613
|
type: "number"
|
|
618
614
|
}
|
|
619
615
|
],
|
|
620
|
-
type:
|
|
616
|
+
type: tableCfg?.type ?? "components",
|
|
621
617
|
isHead: true,
|
|
622
618
|
isRoot: true,
|
|
623
619
|
isShared: false
|
|
@@ -664,6 +660,20 @@ const iterateTables = async (rljson, callback) => {
|
|
|
664
660
|
}
|
|
665
661
|
};
|
|
666
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
|
|
667
677
|
const contentTypes = [
|
|
668
678
|
"buffets",
|
|
669
679
|
"cakes",
|
|
@@ -706,9 +716,7 @@ const rljsonIndexed = (rljson) => {
|
|
|
706
716
|
};
|
|
707
717
|
// @license
|
|
708
718
|
class BaseValidator {
|
|
709
|
-
|
|
710
|
-
__publicField(this, "name", "base");
|
|
711
|
-
}
|
|
719
|
+
name = "base";
|
|
712
720
|
async validate(rljson) {
|
|
713
721
|
return this.validateSync(rljson);
|
|
714
722
|
}
|
|
@@ -721,18 +729,13 @@ class BaseValidator {
|
|
|
721
729
|
}
|
|
722
730
|
class _BaseValidator {
|
|
723
731
|
constructor(rljson) {
|
|
724
|
-
__publicField(this, "errors", { hasErrors: false });
|
|
725
|
-
// ######################
|
|
726
|
-
// Private
|
|
727
|
-
// ######################
|
|
728
|
-
__publicField(this, "tableKeys");
|
|
729
|
-
__publicField(this, "rljsonIndexed");
|
|
730
732
|
this.rljson = rljson;
|
|
731
733
|
this.tableKeys = Object.keys(this.rljson).filter(
|
|
732
734
|
(table) => !table.startsWith("_")
|
|
733
735
|
);
|
|
734
736
|
this.rljsonIndexed = rljsonIndexed(rljson);
|
|
735
737
|
}
|
|
738
|
+
errors = { hasErrors: false };
|
|
736
739
|
get hasErrors() {
|
|
737
740
|
return Object.keys(this.errors).length > 1;
|
|
738
741
|
}
|
|
@@ -777,6 +780,11 @@ class _BaseValidator {
|
|
|
777
780
|
this.errors.hasErrors = this.hasErrors;
|
|
778
781
|
return this.errors;
|
|
779
782
|
}
|
|
783
|
+
// ######################
|
|
784
|
+
// Private
|
|
785
|
+
// ######################
|
|
786
|
+
tableKeys;
|
|
787
|
+
rljsonIndexed;
|
|
780
788
|
_tableKeysNotLowerCamelCase() {
|
|
781
789
|
const invalidTableKeys = [];
|
|
782
790
|
for (const tableKey of this.tableKeys) {
|
|
@@ -821,7 +829,7 @@ class _BaseValidator {
|
|
|
821
829
|
continue;
|
|
822
830
|
}
|
|
823
831
|
if (!BaseValidator.isValidFieldName(columnName)) {
|
|
824
|
-
invalidColumnNames[tableKey]
|
|
832
|
+
invalidColumnNames[tableKey] ??= [];
|
|
825
833
|
invalidColumnNames[tableKey].push(columnName);
|
|
826
834
|
hadErrors = true;
|
|
827
835
|
}
|
|
@@ -1479,12 +1487,6 @@ class _BaseValidator {
|
|
|
1479
1487
|
const isValidFieldName = (fieldName) => BaseValidator.isValidFieldName(fieldName);
|
|
1480
1488
|
// @license
|
|
1481
1489
|
class Validate {
|
|
1482
|
-
constructor() {
|
|
1483
|
-
// ######################
|
|
1484
|
-
// Private
|
|
1485
|
-
// ######################
|
|
1486
|
-
__publicField(this, "_validators", []);
|
|
1487
|
-
}
|
|
1488
1490
|
addValidator(validator) {
|
|
1489
1491
|
this._validators.push(validator);
|
|
1490
1492
|
}
|
|
@@ -1513,6 +1515,10 @@ class Validate {
|
|
|
1513
1515
|
return acc;
|
|
1514
1516
|
}, {});
|
|
1515
1517
|
}
|
|
1518
|
+
// ######################
|
|
1519
|
+
// Private
|
|
1520
|
+
// ######################
|
|
1521
|
+
_validators = [];
|
|
1516
1522
|
}
|
|
1517
1523
|
export {
|
|
1518
1524
|
BaseValidator,
|
|
@@ -1534,6 +1540,7 @@ export {
|
|
|
1534
1540
|
isValidFieldName,
|
|
1535
1541
|
iterateTables,
|
|
1536
1542
|
iterateTablesSync,
|
|
1543
|
+
removeDuplicates,
|
|
1537
1544
|
reservedFieldNames,
|
|
1538
1545
|
reservedTableKeys,
|
|
1539
1546
|
throwOnInvalidTableCfg,
|