@rljson/rljson 0.0.34 → 0.0.36
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/content/cake.d.ts +10 -5
- package/dist/content/layer.d.ts +10 -9
- package/dist/rljson.js +115 -42
- package/dist/src/example.ts +27 -9
- package/dist/validate/base-validator.d.ts +3 -1
- package/package.json +1 -1
package/dist/content/cake.d.ts
CHANGED
|
@@ -19,11 +19,16 @@ export interface Cake extends Json {
|
|
|
19
19
|
* must match these slice ids of the layers.
|
|
20
20
|
* The slice ids can be found in the idSet table.
|
|
21
21
|
*/
|
|
22
|
-
sliceIds:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
sliceIds: {
|
|
23
|
+
/**
|
|
24
|
+
* The table containing the item ids of the layer
|
|
25
|
+
*/
|
|
26
|
+
table: TableKey;
|
|
27
|
+
/**
|
|
28
|
+
* A row in table, that contains the slice ids of the layer
|
|
29
|
+
*/
|
|
30
|
+
row: SliceIdsRef;
|
|
31
|
+
};
|
|
27
32
|
/**
|
|
28
33
|
* The table containing the slice layers defining the layers
|
|
29
34
|
*/
|
package/dist/content/layer.d.ts
CHANGED
|
@@ -15,15 +15,16 @@ export interface Layer extends Json {
|
|
|
15
15
|
* `base` an optional base layer that is extended by this layer
|
|
16
16
|
*/
|
|
17
17
|
base?: LayerRef;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
sliceIds: {
|
|
19
|
+
/**
|
|
20
|
+
* The table containing the item ids of the layer
|
|
21
|
+
*/
|
|
22
|
+
table: TableKey;
|
|
23
|
+
/**
|
|
24
|
+
* A row in table, that contains the slice ids of the layer
|
|
25
|
+
*/
|
|
26
|
+
row: SliceIdsRef;
|
|
27
|
+
};
|
|
27
28
|
/**
|
|
28
29
|
* The table containing the ingredients that are assigned to the items
|
|
29
30
|
* with the assign property below
|
package/dist/rljson.js
CHANGED
|
@@ -51,12 +51,34 @@ const bakeryExample = () => {
|
|
|
51
51
|
],
|
|
52
52
|
_hash: ""
|
|
53
53
|
});
|
|
54
|
+
const slices = hip({
|
|
55
|
+
_type: "sliceIds",
|
|
56
|
+
_data: [
|
|
57
|
+
{
|
|
58
|
+
add: ["slice0", "slice1"],
|
|
59
|
+
remove: []
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
const ingredientTypes = hip({
|
|
64
|
+
_type: "sliceIds",
|
|
65
|
+
_data: [
|
|
66
|
+
{
|
|
67
|
+
add: ["flour"],
|
|
68
|
+
remove: []
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
});
|
|
54
72
|
const recipes = hip({
|
|
55
73
|
_type: "layers",
|
|
56
74
|
_data: [
|
|
57
75
|
{
|
|
58
76
|
id: "tastyCake",
|
|
59
77
|
ingredientsTable: "recipeIngredients",
|
|
78
|
+
sliceIds: {
|
|
79
|
+
table: "ingredientTypes",
|
|
80
|
+
row: ingredientTypes._data[0]._hash
|
|
81
|
+
},
|
|
60
82
|
assign: {
|
|
61
83
|
flour: recipeIngredients._data[0]._hash
|
|
62
84
|
},
|
|
@@ -69,6 +91,10 @@ const bakeryExample = () => {
|
|
|
69
91
|
_data: [
|
|
70
92
|
{
|
|
71
93
|
ingredientsTable: "recipes",
|
|
94
|
+
sliceIds: {
|
|
95
|
+
table: "slices",
|
|
96
|
+
row: slices._data[0]._hash
|
|
97
|
+
},
|
|
72
98
|
assign: {
|
|
73
99
|
slice0: recipes._data[0]._hash,
|
|
74
100
|
slice1: recipes._data[0]._hash
|
|
@@ -76,22 +102,15 @@ const bakeryExample = () => {
|
|
|
76
102
|
}
|
|
77
103
|
]
|
|
78
104
|
});
|
|
79
|
-
const slices = hip({
|
|
80
|
-
_type: "sliceIds",
|
|
81
|
-
_data: [
|
|
82
|
-
{
|
|
83
|
-
add: ["slice0", "slice1"],
|
|
84
|
-
remove: []
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
});
|
|
88
105
|
const cakes = hip({
|
|
89
106
|
_type: "cakes",
|
|
90
107
|
_data: [
|
|
91
108
|
{
|
|
92
109
|
id: "cake1",
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
sliceIds: {
|
|
111
|
+
table: "slices",
|
|
112
|
+
row: slices._data[0]._hash
|
|
113
|
+
},
|
|
95
114
|
layersTable: "layers",
|
|
96
115
|
layers: {
|
|
97
116
|
flour: layers._data[0]._hash
|
|
@@ -117,6 +136,7 @@ const bakeryExample = () => {
|
|
|
117
136
|
buffets,
|
|
118
137
|
cakes,
|
|
119
138
|
slices,
|
|
139
|
+
ingredientTypes,
|
|
120
140
|
layers,
|
|
121
141
|
recipes,
|
|
122
142
|
recipeIngredients,
|
|
@@ -278,15 +298,22 @@ __publicField(_Example, "ok", {
|
|
|
278
298
|
const ingredient0 = ingredients._data[0];
|
|
279
299
|
const ingredient1 = ingredients._data[1];
|
|
280
300
|
const layer0 = hip({
|
|
281
|
-
|
|
282
|
-
|
|
301
|
+
sliceIds: {
|
|
302
|
+
table: "sliceIds",
|
|
303
|
+
row: "MgHRBYSrhpyl4rvsOmAWcQ"
|
|
304
|
+
},
|
|
283
305
|
ingredientsTable: "ingredients",
|
|
284
|
-
assign: {
|
|
306
|
+
assign: {
|
|
307
|
+
id0: ingredient0._hash,
|
|
308
|
+
id1: ingredient1._hash
|
|
309
|
+
}
|
|
285
310
|
});
|
|
286
311
|
const layer1 = hip({
|
|
287
312
|
base: layer0._hash,
|
|
288
|
-
|
|
289
|
-
|
|
313
|
+
sliceIds: {
|
|
314
|
+
table: "sliceIds",
|
|
315
|
+
row: "MgHRBYSrhpyl4rvsOmAWcQ"
|
|
316
|
+
},
|
|
290
317
|
ingredientsTable: "ingredients",
|
|
291
318
|
assign: {
|
|
292
319
|
id0: ingredient0._hash,
|
|
@@ -298,8 +325,10 @@ __publicField(_Example, "ok", {
|
|
|
298
325
|
_data: [layer0, layer1]
|
|
299
326
|
});
|
|
300
327
|
const cake = hip({
|
|
301
|
-
|
|
302
|
-
|
|
328
|
+
sliceIds: {
|
|
329
|
+
table: "sliceIds",
|
|
330
|
+
row: sliceIds._data[0]._hash
|
|
331
|
+
},
|
|
303
332
|
layersTable: "layers",
|
|
304
333
|
layers: {
|
|
305
334
|
layer0: layer0._hash,
|
|
@@ -423,7 +452,7 @@ __publicField(_Example, "broken", {
|
|
|
423
452
|
missingSliceIdSet: () => {
|
|
424
453
|
const result = _Example.ok.complete();
|
|
425
454
|
const layer1 = result.layers._data[1];
|
|
426
|
-
layer1.sliceIds = "MISSING1";
|
|
455
|
+
layer1.sliceIds.row = "MISSING1";
|
|
427
456
|
return hip(result, {
|
|
428
457
|
updateExistingHashes: true,
|
|
429
458
|
throwOnWrongHashes: false
|
|
@@ -446,11 +475,16 @@ __publicField(_Example, "broken", {
|
|
|
446
475
|
cakes: {
|
|
447
476
|
missingSliceIdSet: () => {
|
|
448
477
|
const result = _Example.ok.complete();
|
|
449
|
-
result.cakes._data[0].sliceIds = "MISSING";
|
|
478
|
+
result.cakes._data[0].sliceIds.row = "MISSING";
|
|
450
479
|
hip(result.cakes, {
|
|
451
480
|
updateExistingHashes: true,
|
|
452
481
|
throwOnWrongHashes: false
|
|
453
482
|
});
|
|
483
|
+
result.buffets._data[0].items[0].ref = result.cakes._data[0]._hash;
|
|
484
|
+
hip(result.buffets, {
|
|
485
|
+
updateExistingHashes: true,
|
|
486
|
+
throwOnWrongHashes: false
|
|
487
|
+
});
|
|
454
488
|
return result;
|
|
455
489
|
},
|
|
456
490
|
missingLayersTable: () => {
|
|
@@ -627,8 +661,9 @@ class _BaseValidator {
|
|
|
627
661
|
// Check layers
|
|
628
662
|
() => this._layerBasesNotFound(),
|
|
629
663
|
() => this._layerSliceIdsTableNotFound(),
|
|
630
|
-
() => this.
|
|
664
|
+
() => this._layerSliceIdsRowNotFound(),
|
|
631
665
|
() => this._layerIngredientAssignmentsNotFound(),
|
|
666
|
+
() => this._layerAssignmentsDoNotMatchSliceIds(),
|
|
632
667
|
// Check cakes
|
|
633
668
|
() => this._cakeSliceIdsTableNotFound(),
|
|
634
669
|
() => this._cakeSliceIdsNotFound(),
|
|
@@ -1119,16 +1154,16 @@ class _BaseValidator {
|
|
|
1119
1154
|
}
|
|
1120
1155
|
const layersTable = table;
|
|
1121
1156
|
for (const layer of layersTable._data) {
|
|
1122
|
-
const sliceIds = layer.
|
|
1157
|
+
const sliceIds = layer.sliceIds;
|
|
1123
1158
|
if (!sliceIds) {
|
|
1124
1159
|
continue;
|
|
1125
1160
|
}
|
|
1126
|
-
const sliceIdsTable = this.rljsonIndexed[sliceIds];
|
|
1161
|
+
const sliceIdsTable = this.rljsonIndexed[sliceIds.table];
|
|
1127
1162
|
if (!sliceIdsTable) {
|
|
1128
1163
|
brokenLayers.push({
|
|
1129
1164
|
layersTable: tableKey,
|
|
1130
1165
|
layerHash: layer._hash,
|
|
1131
|
-
missingSliceIdsTable: sliceIds
|
|
1166
|
+
missingSliceIdsTable: sliceIds.table
|
|
1132
1167
|
});
|
|
1133
1168
|
}
|
|
1134
1169
|
}
|
|
@@ -1140,7 +1175,7 @@ class _BaseValidator {
|
|
|
1140
1175
|
};
|
|
1141
1176
|
}
|
|
1142
1177
|
}
|
|
1143
|
-
|
|
1178
|
+
_layerSliceIdsRowNotFound() {
|
|
1144
1179
|
const brokenLayers = [];
|
|
1145
1180
|
iterateTables(this.rljson, (tableKey, table) => {
|
|
1146
1181
|
if (table._type !== "layers") {
|
|
@@ -1148,24 +1183,24 @@ class _BaseValidator {
|
|
|
1148
1183
|
}
|
|
1149
1184
|
const layersTable = table;
|
|
1150
1185
|
for (const layer of layersTable._data) {
|
|
1151
|
-
const
|
|
1152
|
-
if (!
|
|
1186
|
+
const sliceIds = layer.sliceIds;
|
|
1187
|
+
if (!sliceIds) {
|
|
1153
1188
|
continue;
|
|
1154
1189
|
}
|
|
1155
|
-
const
|
|
1156
|
-
const sliceIdsTable = this.rljsonIndexed[
|
|
1157
|
-
const idSet = sliceIdsTable._data[
|
|
1190
|
+
const sliceIdsTableName = sliceIds.table;
|
|
1191
|
+
const sliceIdsTable = this.rljsonIndexed[sliceIdsTableName];
|
|
1192
|
+
const idSet = sliceIdsTable._data[sliceIds.row];
|
|
1158
1193
|
if (!idSet) {
|
|
1159
1194
|
brokenLayers.push({
|
|
1160
1195
|
layersTable: tableKey,
|
|
1161
1196
|
layerHash: layer._hash,
|
|
1162
|
-
|
|
1197
|
+
missingSliceIdsRow: sliceIds.row
|
|
1163
1198
|
});
|
|
1164
1199
|
}
|
|
1165
1200
|
}
|
|
1166
1201
|
});
|
|
1167
1202
|
if (brokenLayers.length > 0) {
|
|
1168
|
-
this.errors.
|
|
1203
|
+
this.errors.layerSliceIdsRowNotFound = {
|
|
1169
1204
|
error: "Id sets of layers are missing",
|
|
1170
1205
|
brokenLayers
|
|
1171
1206
|
};
|
|
@@ -1221,6 +1256,44 @@ class _BaseValidator {
|
|
|
1221
1256
|
};
|
|
1222
1257
|
}
|
|
1223
1258
|
}
|
|
1259
|
+
_layerAssignmentsDoNotMatchSliceIds() {
|
|
1260
|
+
const layersWithMissingAssignments = [];
|
|
1261
|
+
iterateTables(this.rljson, (tableKey, table) => {
|
|
1262
|
+
if (table._type !== "layers") {
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
const layersTable = table;
|
|
1266
|
+
for (const layer of layersTable._data) {
|
|
1267
|
+
if (!layer.sliceIds) {
|
|
1268
|
+
continue;
|
|
1269
|
+
}
|
|
1270
|
+
const sliceIdsTable = this.rljsonIndexed[layer.sliceIds.table];
|
|
1271
|
+
const sliceIdsRow = sliceIdsTable._data[layer.sliceIds.row];
|
|
1272
|
+
const sliceIds = sliceIdsRow.add;
|
|
1273
|
+
const sliceIdsInLayer = Object.keys(layer.assign);
|
|
1274
|
+
const unassignedSliceIds = [];
|
|
1275
|
+
for (const expectedSliceId of sliceIds) {
|
|
1276
|
+
if (sliceIdsInLayer.indexOf(expectedSliceId) === -1) {
|
|
1277
|
+
unassignedSliceIds.push(expectedSliceId);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
if (unassignedSliceIds.length) {
|
|
1281
|
+
layersWithMissingAssignments.push({
|
|
1282
|
+
brokenLayer: layer._hash,
|
|
1283
|
+
layersTable: tableKey,
|
|
1284
|
+
unassignedSliceIds
|
|
1285
|
+
});
|
|
1286
|
+
continue;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
if (layersWithMissingAssignments.length > 0) {
|
|
1291
|
+
this.errors.layerAssignmentsDoNotMatchSliceIds = {
|
|
1292
|
+
error: "Layers have missing assignments",
|
|
1293
|
+
layers: layersWithMissingAssignments
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1224
1297
|
_cakeSliceIdsTableNotFound() {
|
|
1225
1298
|
const brokenCakes = [];
|
|
1226
1299
|
iterateTables(this.rljson, (tableKey, table) => {
|
|
@@ -1229,16 +1302,16 @@ class _BaseValidator {
|
|
|
1229
1302
|
}
|
|
1230
1303
|
const cakesTable = table;
|
|
1231
1304
|
for (const cake of cakesTable._data) {
|
|
1232
|
-
const
|
|
1233
|
-
if (!
|
|
1305
|
+
const sliceIds = cake.sliceIds;
|
|
1306
|
+
if (!sliceIds) {
|
|
1234
1307
|
continue;
|
|
1235
1308
|
}
|
|
1236
|
-
const sliceIdsTable = this.rljsonIndexed[
|
|
1309
|
+
const sliceIdsTable = this.rljsonIndexed[sliceIds.table];
|
|
1237
1310
|
if (!sliceIdsTable) {
|
|
1238
1311
|
brokenCakes.push({
|
|
1239
1312
|
cakeTable: tableKey,
|
|
1240
1313
|
brokenCake: cake._hash,
|
|
1241
|
-
missingSliceIdsTable:
|
|
1314
|
+
missingSliceIdsTable: sliceIds.table
|
|
1242
1315
|
});
|
|
1243
1316
|
}
|
|
1244
1317
|
}
|
|
@@ -1258,18 +1331,18 @@ class _BaseValidator {
|
|
|
1258
1331
|
}
|
|
1259
1332
|
const cakesTable = table;
|
|
1260
1333
|
for (const cake of cakesTable._data) {
|
|
1261
|
-
const
|
|
1262
|
-
if (!
|
|
1334
|
+
const sliceIds = cake.sliceIds;
|
|
1335
|
+
if (!sliceIds) {
|
|
1263
1336
|
continue;
|
|
1264
1337
|
}
|
|
1265
|
-
const sliceIdsTableName = cake.
|
|
1338
|
+
const sliceIdsTableName = cake.sliceIds.table;
|
|
1266
1339
|
const sliceIdsTable = this.rljsonIndexed[sliceIdsTableName];
|
|
1267
|
-
const
|
|
1268
|
-
if (!
|
|
1340
|
+
const sliceIdValues = sliceIdsTable._data[sliceIds.row];
|
|
1341
|
+
if (!sliceIdValues) {
|
|
1269
1342
|
brokenCakes.push({
|
|
1270
1343
|
cakeTable: tableKey,
|
|
1271
1344
|
brokenCake: cake._hash,
|
|
1272
|
-
|
|
1345
|
+
missingSliceIdsRow: sliceIds.row
|
|
1273
1346
|
});
|
|
1274
1347
|
}
|
|
1275
1348
|
}
|
package/dist/src/example.ts
CHANGED
|
@@ -168,16 +168,23 @@ export class Example {
|
|
|
168
168
|
const ingredient1 = ingredients._data[1];
|
|
169
169
|
|
|
170
170
|
const layer0: Layer = hip({
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
sliceIds: {
|
|
172
|
+
table: 'sliceIds',
|
|
173
|
+
row: 'MgHRBYSrhpyl4rvsOmAWcQ',
|
|
174
|
+
},
|
|
173
175
|
ingredientsTable: 'ingredients',
|
|
174
|
-
assign: {
|
|
176
|
+
assign: {
|
|
177
|
+
id0: ingredient0._hash,
|
|
178
|
+
id1: ingredient1._hash,
|
|
179
|
+
},
|
|
175
180
|
});
|
|
176
181
|
|
|
177
182
|
const layer1: Layer = hip({
|
|
178
183
|
base: layer0._hash as string,
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
sliceIds: {
|
|
185
|
+
table: 'sliceIds',
|
|
186
|
+
row: 'MgHRBYSrhpyl4rvsOmAWcQ',
|
|
187
|
+
},
|
|
181
188
|
ingredientsTable: 'ingredients',
|
|
182
189
|
assign: {
|
|
183
190
|
id0: ingredient0._hash,
|
|
@@ -191,8 +198,10 @@ export class Example {
|
|
|
191
198
|
} as LayersTable);
|
|
192
199
|
|
|
193
200
|
const cake: Cake = hip({
|
|
194
|
-
|
|
195
|
-
|
|
201
|
+
sliceIds: {
|
|
202
|
+
table: 'sliceIds',
|
|
203
|
+
row: sliceIds._data[0]._hash as string,
|
|
204
|
+
},
|
|
196
205
|
layersTable: 'layers',
|
|
197
206
|
layers: {
|
|
198
207
|
layer0: layer0._hash as string,
|
|
@@ -328,7 +337,7 @@ export class Example {
|
|
|
328
337
|
const result = Example.ok.complete();
|
|
329
338
|
const layer1 = result.layers._data[1];
|
|
330
339
|
|
|
331
|
-
layer1.sliceIds = 'MISSING1';
|
|
340
|
+
layer1.sliceIds.row = 'MISSING1';
|
|
332
341
|
|
|
333
342
|
// Recalculate hashes
|
|
334
343
|
return hip(result, {
|
|
@@ -356,11 +365,20 @@ export class Example {
|
|
|
356
365
|
cakes: {
|
|
357
366
|
missingSliceIdSet: (): Rljson => {
|
|
358
367
|
const result = Example.ok.complete();
|
|
359
|
-
result.cakes._data[0].sliceIds = 'MISSING'; // Missing ID set
|
|
368
|
+
result.cakes._data[0].sliceIds.row = 'MISSING'; // Missing ID set
|
|
360
369
|
hip(result.cakes, {
|
|
361
370
|
updateExistingHashes: true,
|
|
362
371
|
throwOnWrongHashes: false,
|
|
363
372
|
});
|
|
373
|
+
|
|
374
|
+
result.buffets._data[0].items[0].ref = result.cakes._data[0]
|
|
375
|
+
._hash as string; // Update buffet reference
|
|
376
|
+
|
|
377
|
+
hip(result.buffets, {
|
|
378
|
+
updateExistingHashes: true,
|
|
379
|
+
throwOnWrongHashes: false,
|
|
380
|
+
});
|
|
381
|
+
|
|
364
382
|
return result;
|
|
365
383
|
},
|
|
366
384
|
|
|
@@ -20,10 +20,12 @@ export interface BaseErrors extends Errors {
|
|
|
20
20
|
tableCfgHasRootHeadSharedError?: Json;
|
|
21
21
|
refsNotFound?: Json;
|
|
22
22
|
layerBasesNotFound?: Json;
|
|
23
|
+
layerSliceIdsGivenButNoTable?: Json;
|
|
23
24
|
layerSliceIdsTableNotFound?: Json;
|
|
24
|
-
|
|
25
|
+
layerSliceIdsRowNotFound?: Json;
|
|
25
26
|
layerIngredientTablesNotFound?: Json;
|
|
26
27
|
layerIngredientAssignmentsNotFound?: Json;
|
|
28
|
+
layerAssignmentsDoNotMatchSliceIds?: Json;
|
|
27
29
|
cakeSliceIdsTableNotFound?: Json;
|
|
28
30
|
cakeSliceIdsNotFound?: Json;
|
|
29
31
|
cakeLayerTablesNotFound?: Json;
|