@rljson/rljson 0.0.34 → 0.0.37

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.
@@ -19,11 +19,11 @@ 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: SliceIdsRef;
22
+ sliceIdsTable: TableKey;
23
23
  /**
24
- * The table containing the slice ids of the layer
24
+ * A row in table, that contains the slice ids of the layer
25
25
  */
26
- sliceIdsTable: TableKey;
26
+ sliceIdsRow: SliceIdsRef;
27
27
  /**
28
28
  * The table containing the slice layers defining the layers
29
29
  */
@@ -16,14 +16,13 @@ export interface Layer extends Json {
16
16
  */
17
17
  base?: LayerRef;
18
18
  /**
19
- * The item ids of the layer. If present, the item ids in `assign`
20
- * must match these ids. The item id sets can be found in the sliceIds table.
19
+ * The table containing the item ids of the layer
21
20
  */
22
- sliceIds?: SliceIdsRef;
21
+ sliceIdsTable: TableKey;
23
22
  /**
24
- * The table containing the item ids of the layer
23
+ * A row in table, that contains the slice ids of the layer
25
24
  */
26
- sliceIdsTable?: TableKey;
25
+ sliceIdsTableRow: SliceIdsRef;
27
26
  /**
28
27
  * The table containing the ingredients that are assigned to the items
29
28
  * with the assign property below
package/dist/rljson.js CHANGED
@@ -51,12 +51,32 @@ 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
+ sliceIdsTable: "ingredientTypes",
79
+ sliceIdsTableRow: ingredientTypes._data[0]._hash,
60
80
  assign: {
61
81
  flour: recipeIngredients._data[0]._hash
62
82
  },
@@ -69,6 +89,8 @@ const bakeryExample = () => {
69
89
  _data: [
70
90
  {
71
91
  ingredientsTable: "recipes",
92
+ sliceIdsTable: "slices",
93
+ sliceIdsTableRow: slices._data[0]._hash,
72
94
  assign: {
73
95
  slice0: recipes._data[0]._hash,
74
96
  slice1: recipes._data[0]._hash
@@ -76,22 +98,13 @@ const bakeryExample = () => {
76
98
  }
77
99
  ]
78
100
  });
79
- const slices = hip({
80
- _type: "sliceIds",
81
- _data: [
82
- {
83
- add: ["slice0", "slice1"],
84
- remove: []
85
- }
86
- ]
87
- });
88
101
  const cakes = hip({
89
102
  _type: "cakes",
90
103
  _data: [
91
104
  {
92
105
  id: "cake1",
93
106
  sliceIdsTable: "slices",
94
- sliceIds: slices._data[0]._hash,
107
+ sliceIdsRow: slices._data[0]._hash,
95
108
  layersTable: "layers",
96
109
  layers: {
97
110
  flour: layers._data[0]._hash
@@ -117,6 +130,7 @@ const bakeryExample = () => {
117
130
  buffets,
118
131
  cakes,
119
132
  slices,
133
+ ingredientTypes,
120
134
  layers,
121
135
  recipes,
122
136
  recipeIngredients,
@@ -279,14 +293,17 @@ __publicField(_Example, "ok", {
279
293
  const ingredient1 = ingredients._data[1];
280
294
  const layer0 = hip({
281
295
  sliceIdsTable: "sliceIds",
282
- sliceIds: "MgHRBYSrhpyl4rvsOmAWcQ",
296
+ sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
283
297
  ingredientsTable: "ingredients",
284
- assign: {}
298
+ assign: {
299
+ id0: ingredient0._hash,
300
+ id1: ingredient1._hash
301
+ }
285
302
  });
286
303
  const layer1 = hip({
287
304
  base: layer0._hash,
288
305
  sliceIdsTable: "sliceIds",
289
- sliceIds: "MgHRBYSrhpyl4rvsOmAWcQ",
306
+ sliceIdsTableRow: "MgHRBYSrhpyl4rvsOmAWcQ",
290
307
  ingredientsTable: "ingredients",
291
308
  assign: {
292
309
  id0: ingredient0._hash,
@@ -299,7 +316,7 @@ __publicField(_Example, "ok", {
299
316
  });
300
317
  const cake = hip({
301
318
  sliceIdsTable: "sliceIds",
302
- sliceIds: sliceIds._data[0]._hash,
319
+ sliceIdsRow: sliceIds._data[0]._hash,
303
320
  layersTable: "layers",
304
321
  layers: {
305
322
  layer0: layer0._hash,
@@ -423,7 +440,7 @@ __publicField(_Example, "broken", {
423
440
  missingSliceIdSet: () => {
424
441
  const result = _Example.ok.complete();
425
442
  const layer1 = result.layers._data[1];
426
- layer1.sliceIds = "MISSING1";
443
+ layer1.sliceIdsTableRow = "MISSING1";
427
444
  return hip(result, {
428
445
  updateExistingHashes: true,
429
446
  throwOnWrongHashes: false
@@ -446,11 +463,16 @@ __publicField(_Example, "broken", {
446
463
  cakes: {
447
464
  missingSliceIdSet: () => {
448
465
  const result = _Example.ok.complete();
449
- result.cakes._data[0].sliceIds = "MISSING";
466
+ result.cakes._data[0].sliceIdsRow = "MISSING";
450
467
  hip(result.cakes, {
451
468
  updateExistingHashes: true,
452
469
  throwOnWrongHashes: false
453
470
  });
471
+ result.buffets._data[0].items[0].ref = result.cakes._data[0]._hash;
472
+ hip(result.buffets, {
473
+ updateExistingHashes: true,
474
+ throwOnWrongHashes: false
475
+ });
454
476
  return result;
455
477
  },
456
478
  missingLayersTable: () => {
@@ -627,8 +649,9 @@ class _BaseValidator {
627
649
  // Check layers
628
650
  () => this._layerBasesNotFound(),
629
651
  () => this._layerSliceIdsTableNotFound(),
630
- () => this._layerSliceIdsNotFound(),
652
+ () => this._layerSliceIdsRowNotFound(),
631
653
  () => this._layerIngredientAssignmentsNotFound(),
654
+ () => this._layerAssignmentsDoNotMatchSliceIds(),
632
655
  // Check cakes
633
656
  () => this._cakeSliceIdsTableNotFound(),
634
657
  () => this._cakeSliceIdsNotFound(),
@@ -1119,16 +1142,12 @@ class _BaseValidator {
1119
1142
  }
1120
1143
  const layersTable = table;
1121
1144
  for (const layer of layersTable._data) {
1122
- const sliceIds = layer.sliceIdsTable;
1123
- if (!sliceIds) {
1124
- continue;
1125
- }
1126
- const sliceIdsTable = this.rljsonIndexed[sliceIds];
1145
+ const sliceIdsTable = this.rljsonIndexed[layer.sliceIdsTable];
1127
1146
  if (!sliceIdsTable) {
1128
1147
  brokenLayers.push({
1129
1148
  layersTable: tableKey,
1130
1149
  layerHash: layer._hash,
1131
- missingSliceIdsTable: sliceIds
1150
+ missingSliceIdsTable: layer.sliceIdsTable
1132
1151
  });
1133
1152
  }
1134
1153
  }
@@ -1140,7 +1159,7 @@ class _BaseValidator {
1140
1159
  };
1141
1160
  }
1142
1161
  }
1143
- _layerSliceIdsNotFound() {
1162
+ _layerSliceIdsRowNotFound() {
1144
1163
  const brokenLayers = [];
1145
1164
  iterateTables(this.rljson, (tableKey, table) => {
1146
1165
  if (table._type !== "layers") {
@@ -1148,24 +1167,20 @@ class _BaseValidator {
1148
1167
  }
1149
1168
  const layersTable = table;
1150
1169
  for (const layer of layersTable._data) {
1151
- const idSetRef = layer.sliceIds;
1152
- if (!idSetRef) {
1153
- continue;
1154
- }
1155
- const sliceIds = layer.sliceIdsTable;
1156
- const sliceIdsTable = this.rljsonIndexed[sliceIds];
1157
- const idSet = sliceIdsTable._data[idSetRef];
1170
+ const sliceIdsTableName = layer.sliceIdsTable;
1171
+ const sliceIdsTable = this.rljsonIndexed[sliceIdsTableName];
1172
+ const idSet = sliceIdsTable._data[layer.sliceIdsTableRow];
1158
1173
  if (!idSet) {
1159
1174
  brokenLayers.push({
1160
1175
  layersTable: tableKey,
1161
1176
  layerHash: layer._hash,
1162
- missingSliceIds: idSetRef
1177
+ missingSliceIdsRow: layer.sliceIdsTableRow
1163
1178
  });
1164
1179
  }
1165
1180
  }
1166
1181
  });
1167
1182
  if (brokenLayers.length > 0) {
1168
- this.errors.layerSliceIdsNotFound = {
1183
+ this.errors.layerSliceIdsRowNotFound = {
1169
1184
  error: "Id sets of layers are missing",
1170
1185
  brokenLayers
1171
1186
  };
@@ -1221,6 +1236,41 @@ class _BaseValidator {
1221
1236
  };
1222
1237
  }
1223
1238
  }
1239
+ _layerAssignmentsDoNotMatchSliceIds() {
1240
+ const layersWithMissingAssignments = [];
1241
+ iterateTables(this.rljson, (tableKey, table) => {
1242
+ if (table._type !== "layers") {
1243
+ return;
1244
+ }
1245
+ const layersTable = table;
1246
+ for (const layer of layersTable._data) {
1247
+ const sliceIdsTable = this.rljsonIndexed[layer.sliceIdsTable];
1248
+ const sliceIdsRow = sliceIdsTable._data[layer.sliceIdsTableRow];
1249
+ const sliceIds = sliceIdsRow.add;
1250
+ const sliceIdsInLayer = Object.keys(layer.assign);
1251
+ const unassignedSliceIds = [];
1252
+ for (const expectedSliceId of sliceIds) {
1253
+ if (sliceIdsInLayer.indexOf(expectedSliceId) === -1) {
1254
+ unassignedSliceIds.push(expectedSliceId);
1255
+ }
1256
+ }
1257
+ if (unassignedSliceIds.length) {
1258
+ layersWithMissingAssignments.push({
1259
+ brokenLayer: layer._hash,
1260
+ layersTable: tableKey,
1261
+ unassignedSliceIds
1262
+ });
1263
+ continue;
1264
+ }
1265
+ }
1266
+ });
1267
+ if (layersWithMissingAssignments.length > 0) {
1268
+ this.errors.layerAssignmentsDoNotMatchSliceIds = {
1269
+ error: "Layers have missing assignments",
1270
+ layers: layersWithMissingAssignments
1271
+ };
1272
+ }
1273
+ }
1224
1274
  _cakeSliceIdsTableNotFound() {
1225
1275
  const brokenCakes = [];
1226
1276
  iterateTables(this.rljson, (tableKey, table) => {
@@ -1229,16 +1279,12 @@ class _BaseValidator {
1229
1279
  }
1230
1280
  const cakesTable = table;
1231
1281
  for (const cake of cakesTable._data) {
1232
- const sliceIdsTableName = cake.sliceIdsTable;
1233
- if (!sliceIdsTableName) {
1234
- continue;
1235
- }
1236
- const sliceIdsTable = this.rljsonIndexed[sliceIdsTableName];
1282
+ const sliceIdsTable = this.rljsonIndexed[cake.sliceIdsTable];
1237
1283
  if (!sliceIdsTable) {
1238
1284
  brokenCakes.push({
1239
1285
  cakeTable: tableKey,
1240
1286
  brokenCake: cake._hash,
1241
- missingSliceIdsTable: sliceIdsTableName
1287
+ missingSliceIdsTable: cake.sliceIdsTable
1242
1288
  });
1243
1289
  }
1244
1290
  }
@@ -1258,18 +1304,14 @@ class _BaseValidator {
1258
1304
  }
1259
1305
  const cakesTable = table;
1260
1306
  for (const cake of cakesTable._data) {
1261
- const sliceIdsRef = cake.sliceIds;
1262
- if (!sliceIdsRef) {
1263
- continue;
1264
- }
1265
1307
  const sliceIdsTableName = cake.sliceIdsTable;
1266
1308
  const sliceIdsTable = this.rljsonIndexed[sliceIdsTableName];
1267
- const sliceIds = sliceIdsTable._data[sliceIdsRef];
1268
- if (!sliceIds) {
1309
+ const sliceIdValues = sliceIdsTable._data[cake.sliceIdsRow];
1310
+ if (!sliceIdValues) {
1269
1311
  brokenCakes.push({
1270
1312
  cakeTable: tableKey,
1271
1313
  brokenCake: cake._hash,
1272
- missingSliceIds: sliceIdsRef
1314
+ missingSliceIdsRow: cake.sliceIdsRow
1273
1315
  });
1274
1316
  }
1275
1317
  }
@@ -39,7 +39,7 @@ export class Example {
39
39
  },
40
40
 
41
41
  singleRow: (): Rljson => {
42
- const tableCfgs: TablesCfgTable = hip({
42
+ const tableCfgs = hip<TablesCfgTable>({
43
43
  _hash: '',
44
44
 
45
45
  _type: 'ingredients',
@@ -151,7 +151,7 @@ export class Example {
151
151
  };
152
152
  },
153
153
  complete: (): Rljson => {
154
- const sliceIds: SliceIdsTable = hip({
154
+ const sliceIds = hip<SliceIdsTable>({
155
155
  _type: 'sliceIds',
156
156
  _data: [
157
157
  {
@@ -160,24 +160,27 @@ export class Example {
160
160
  ],
161
161
  });
162
162
 
163
- const ingredients: IngredientsTable<any> = hip({
163
+ const ingredients = hip<IngredientsTable<any>>({
164
164
  _type: 'ingredients',
165
165
  _data: [{ a: '0' }, { a: '1' }],
166
166
  });
167
167
  const ingredient0 = ingredients._data[0];
168
168
  const ingredient1 = ingredients._data[1];
169
169
 
170
- const layer0: Layer = hip({
170
+ const layer0 = hip<Layer>({
171
171
  sliceIdsTable: 'sliceIds',
172
- sliceIds: 'MgHRBYSrhpyl4rvsOmAWcQ',
172
+ sliceIdsTableRow: 'MgHRBYSrhpyl4rvsOmAWcQ',
173
173
  ingredientsTable: 'ingredients',
174
- assign: {},
174
+ assign: {
175
+ id0: ingredient0._hash,
176
+ id1: ingredient1._hash,
177
+ },
175
178
  });
176
179
 
177
- const layer1: Layer = hip({
180
+ const layer1 = hip<Layer>({
178
181
  base: layer0._hash as string,
179
182
  sliceIdsTable: 'sliceIds',
180
- sliceIds: 'MgHRBYSrhpyl4rvsOmAWcQ',
183
+ sliceIdsTableRow: 'MgHRBYSrhpyl4rvsOmAWcQ',
181
184
  ingredientsTable: 'ingredients',
182
185
  assign: {
183
186
  id0: ingredient0._hash,
@@ -185,14 +188,14 @@ export class Example {
185
188
  },
186
189
  });
187
190
 
188
- const layers: LayersTable = hip({
191
+ const layers = hip<LayersTable>({
189
192
  _type: 'layers',
190
193
  _data: [layer0, layer1],
191
194
  } as LayersTable);
192
195
 
193
- const cake: Cake = hip({
196
+ const cake = hip<Cake>({
194
197
  sliceIdsTable: 'sliceIds',
195
- sliceIds: sliceIds._data[0]._hash as string,
198
+ sliceIdsRow: sliceIds._data[0]._hash as string,
196
199
  layersTable: 'layers',
197
200
  layers: {
198
201
  layer0: layer0._hash as string,
@@ -200,12 +203,12 @@ export class Example {
200
203
  },
201
204
  });
202
205
 
203
- const cakes: CakesTable = hip({
206
+ const cakes = hip<CakesTable>({
204
207
  _type: 'cakes',
205
208
  _data: [cake],
206
209
  });
207
210
 
208
- const buffets: BuffetsTable = hip({
211
+ const buffets = hip<BuffetsTable>({
209
212
  _type: 'buffets',
210
213
  _data: [
211
214
  {
@@ -326,9 +329,9 @@ export class Example {
326
329
 
327
330
  missingSliceIdSet: (): Rljson => {
328
331
  const result = Example.ok.complete();
329
- const layer1 = result.layers._data[1];
332
+ const layer1 = (result.layers as LayersTable)._data[1];
330
333
 
331
- layer1.sliceIds = 'MISSING1';
334
+ layer1.sliceIdsTableRow = 'MISSING1';
332
335
 
333
336
  // Recalculate hashes
334
337
  return hip(result, {
@@ -356,11 +359,21 @@ export class Example {
356
359
  cakes: {
357
360
  missingSliceIdSet: (): Rljson => {
358
361
  const result = Example.ok.complete();
359
- result.cakes._data[0].sliceIds = 'MISSING'; // Missing ID set
362
+ (result.cakes as CakesTable)._data[0].sliceIdsRow = 'MISSING'; // Missing ID set
363
+
360
364
  hip(result.cakes, {
361
365
  updateExistingHashes: true,
362
366
  throwOnWrongHashes: false,
363
367
  });
368
+
369
+ (result.buffets as BuffetsTable)._data[0].items[0].ref = result.cakes
370
+ ._data[0]._hash as string; // Update buffet reference
371
+
372
+ hip(result.buffets, {
373
+ updateExistingHashes: true,
374
+ throwOnWrongHashes: false,
375
+ });
376
+
364
377
  return result;
365
378
  },
366
379
 
@@ -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
- layerSliceIdsNotFound?: Json;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.34",
3
+ "version": "0.0.37",
4
4
  "packageManager": "pnpm@10.6.3",
5
5
  "description": "The RLJSON data format specification",
6
6
  "homepage": "https://github.com/rljson/rljson",