@rljson/rljson 0.0.28 → 0.0.30

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.
@@ -221,7 +221,7 @@ properties:
221
221
 
222
222
  ```json
223
223
  {
224
- "idSetsTable": "personIds",
224
+ "idSets": "personIds",
225
225
  "idSet": "IDS0",
226
226
  "properties": "addresses",
227
227
  "assign": {
@@ -221,7 +221,7 @@ properties:
221
221
 
222
222
  ```json
223
223
  {
224
- "idSetsTable": "personIds",
224
+ "idSets": "personIds",
225
225
  "idSet": "IDS0",
226
226
  "properties": "addresses",
227
227
  "assign": {
@@ -19,6 +19,10 @@ export interface Cake extends Json {
19
19
  * must match these ids. The item id sets can be found in the idSets table.
20
20
  */
21
21
  idSet?: IdSetRef;
22
+ /**
23
+ * The table containing the item ids of the collection
24
+ */
25
+ idSetsTable?: TableKey;
22
26
  /**
23
27
  * The table containing the item collections defining the layers
24
28
  */
@@ -16,10 +16,14 @@ export interface Collection extends Json {
16
16
  */
17
17
  base?: CollectionRef;
18
18
  /**
19
- * The item ids of the collection. If presnet, the item ids in `assign`
19
+ * The item ids of the collection. If present, the item ids in `assign`
20
20
  * must match these ids. The item id sets can be found in the idSets table.
21
21
  */
22
22
  idSet?: IdSetRef;
23
+ /**
24
+ * The table containing the item ids of the collection
25
+ */
26
+ idSetsTable?: TableKey;
23
27
  /**
24
28
  * The table containing the properties that are assigned to the items
25
29
  * with the assign property below
@@ -38,6 +38,11 @@ export interface TableCfg extends Json {
38
38
  * The previous version of the table
39
39
  */
40
40
  previous?: TableCfgRef;
41
+ /**
42
+ * The version of the table.
43
+ * Needs to be increased when new columns are added.
44
+ */
45
+ version: number;
41
46
  }
42
47
  /**
43
48
  * A table containing columns
@@ -1,8 +1,8 @@
1
1
  import { Json } from '@rljson/json';
2
+ import { IdSetsTable } from '../../dist/content/id-set.ts';
2
3
  import { BuffetsTable } from '../content/buffet.ts';
3
4
  import { CakesTable } from '../content/cake.ts';
4
5
  import { CollectionsTable } from '../content/collection.ts';
5
- import { IdSetsTable } from '../content/id-set.ts';
6
6
  import { PropertiesTable } from '../content/properties.ts';
7
7
  import { Rljson } from '../rljson.ts';
8
8
  import { Ref } from '../typedefs.ts';
package/dist/rljson.js CHANGED
@@ -76,21 +76,12 @@ const bakeryExample = () => {
76
76
  ],
77
77
  _hash: ""
78
78
  });
79
- const idSets = hip({
80
- _type: "idSets",
81
- _data: [
82
- {
83
- add: ["slice0", "slice1"],
84
- _hash: ""
85
- }
86
- ],
87
- _hash: ""
88
- });
89
79
  const cakes = hip({
90
80
  _type: "cakes",
91
81
  _data: [
92
82
  {
93
- idSet: idSets._data[0]._hash,
83
+ idSetsTable: "slices",
84
+ idSet: slices._data[0]._hash,
94
85
  collections: "layers",
95
86
  layers: {
96
87
  flour: layers._data[0]._hash
@@ -113,7 +104,6 @@ const bakeryExample = () => {
113
104
  ]
114
105
  });
115
106
  const result = {
116
- idSets,
117
107
  buffets,
118
108
  cakes,
119
109
  slices,
@@ -162,6 +152,7 @@ __publicField(_Example, "ok", {
162
152
  _type: "properties",
163
153
  _data: [
164
154
  {
155
+ version: 0,
165
156
  _hash: "",
166
157
  key: "table",
167
158
  type: "properties",
@@ -267,75 +258,76 @@ __publicField(_Example, "ok", {
267
258
  };
268
259
  },
269
260
  complete: () => {
270
- return {
271
- idSets: {
272
- _type: "idSets",
273
- _data: [
274
- {
275
- add: ["id0", "id1"],
276
- _hash: "MgHRBYSrhpyl4rvsOmAWcQ"
277
- }
278
- ]
279
- },
280
- properties: {
281
- _type: "properties",
282
- _data: [
283
- { a: "0", _hash: "AFhW-fMzdCiz6bUZscp1Lf" },
284
- { a: "1", _hash: "mv6w8rID8lQxLsje1EHQMY" }
285
- ]
286
- },
287
- collections: {
288
- _type: "collections",
289
- _data: [
290
- {
291
- idSet: "MgHRBYSrhpyl4rvsOmAWcQ",
292
- properties: "properties",
293
- _hash: "sxv2NCM6UNOcX-i9FhOs5W",
294
- assign: {}
295
- },
296
- {
297
- base: "sxv2NCM6UNOcX-i9FhOs5W",
298
- idSet: "MgHRBYSrhpyl4rvsOmAWcQ",
299
- properties: "properties",
300
- assign: {
301
- id0: "AFhW-fMzdCiz6bUZscp1Lf",
302
- id1: "mv6w8rID8lQxLsje1EHQMY"
303
- },
304
- _hash: "QB2JC6X_-rUAoixuldzWP-"
305
- }
306
- ]
307
- },
308
- cakes: {
309
- _type: "cakes",
310
- _data: [
311
- {
312
- idSet: "MgHRBYSrhpyl4rvsOmAWcQ",
313
- collections: "collections",
314
- layers: {
315
- layer0: "sxv2NCM6UNOcX-i9FhOs5W",
316
- layer1: "QB2JC6X_-rUAoixuldzWP-"
317
- },
318
- _hash: "QlTVJL3uoXO1L_fw2evLPe"
319
- }
320
- ]
321
- },
322
- buffets: {
323
- _type: "buffets",
324
- _data: [
325
- {
326
- items: [
327
- {
328
- table: "cakes",
329
- ref: "QlTVJL3uoXO1L_fw2evLPe"
330
- },
331
- {
332
- table: "collections",
333
- ref: "QB2JC6X_-rUAoixuldzWP-"
334
- }
335
- ]
336
- }
337
- ]
261
+ const idSets = hip({
262
+ _type: "idSets",
263
+ _data: [
264
+ {
265
+ add: ["id0", "id1"]
266
+ }
267
+ ]
268
+ });
269
+ const properties = hip({
270
+ _type: "properties",
271
+ _data: [{ a: "0" }, { a: "1" }]
272
+ });
273
+ const property0 = properties._data[0];
274
+ const property1 = properties._data[1];
275
+ const collection0 = hip({
276
+ idSetsTable: "idSets",
277
+ idSet: "MgHRBYSrhpyl4rvsOmAWcQ",
278
+ properties: "properties",
279
+ assign: {}
280
+ });
281
+ const collection1 = hip({
282
+ base: collection0._hash,
283
+ idSetsTable: "idSets",
284
+ idSet: "MgHRBYSrhpyl4rvsOmAWcQ",
285
+ properties: "properties",
286
+ assign: {
287
+ id0: property0._hash,
288
+ id1: property1._hash
338
289
  }
290
+ });
291
+ const collections = hip({
292
+ _type: "collections",
293
+ _data: [collection0, collection1]
294
+ });
295
+ const cake = hip({
296
+ idSetsTable: "idSets",
297
+ idSet: idSets._data[0]._hash,
298
+ collections: "collections",
299
+ layers: {
300
+ layer0: collection0._hash,
301
+ layer1: collection1._hash
302
+ }
303
+ });
304
+ const cakes = hip({
305
+ _type: "cakes",
306
+ _data: [cake]
307
+ });
308
+ const buffets = hip({
309
+ _type: "buffets",
310
+ _data: [
311
+ {
312
+ items: [
313
+ {
314
+ table: "cakes",
315
+ ref: cakes._data[0]._hash
316
+ },
317
+ {
318
+ table: "collections",
319
+ ref: collection0._hash
320
+ }
321
+ ]
322
+ }
323
+ ]
324
+ });
325
+ return {
326
+ idSets,
327
+ properties,
328
+ collections,
329
+ cakes,
330
+ buffets
339
331
  };
340
332
  }
341
333
  });
@@ -431,7 +423,7 @@ __publicField(_Example, "broken", {
431
423
  missingAssignedProperty: () => {
432
424
  const result = _Example.ok.complete();
433
425
  result.properties._data.splice(1, 2);
434
- return result;
426
+ return hip(result, true, false);
435
427
  }
436
428
  },
437
429
  cakes: {
@@ -461,7 +453,7 @@ __publicField(_Example, "broken", {
461
453
  const buffet = result.buffets._data[0];
462
454
  buffet.items[0].table = "MISSING0";
463
455
  buffet.items[1].table = "MISSING1";
464
- hip(buffet, true, false);
456
+ hip(result, true, false);
465
457
  return result;
466
458
  },
467
459
  missingItems: () => {
@@ -469,7 +461,7 @@ __publicField(_Example, "broken", {
469
461
  const buffet = result.buffets._data[0];
470
462
  buffet.items[0].ref = "MISSING0";
471
463
  buffet.items[1].ref = "MISSING1";
472
- hip(buffet, true, false);
464
+ hip(result, true, false);
473
465
  return result;
474
466
  }
475
467
  }
@@ -480,6 +472,7 @@ const exampleTableCfgTable = () => Example.ok.singleRow().tableCfgs;
480
472
  const exampleTableCfg = (tableCfg = void 0) => {
481
473
  return {
482
474
  key: (tableCfg == null ? void 0 : tableCfg.key) ?? "table",
475
+ version: 1,
483
476
  columns: (tableCfg == null ? void 0 : tableCfg.columns) ?? {
484
477
  a: {
485
478
  key: "a",
@@ -598,10 +591,12 @@ class _BaseValidator {
598
591
  () => this._refsNotFound(),
599
592
  // Check collections
600
593
  () => this._collectionBasesNotFound(),
601
- () => this._collectionIdSetsExist(),
594
+ () => this._collectionIdSetsTableNotFound(),
595
+ () => this._collectionIdSetNotFound(),
602
596
  () => this._collectionPropertyAssignmentsNotFound(),
603
597
  // Check cakes
604
- () => this._cakeIdSetsNotFound(),
598
+ () => this._cakeIdSetsTableNotFound(),
599
+ () => this._cakeIdSetNotFound(),
605
600
  () => this._cakeCollectionTablesNotFound(),
606
601
  // Check buffets
607
602
  () => this._buffetReferencedTableNotFound()
@@ -1011,20 +1006,50 @@ class _BaseValidator {
1011
1006
  };
1012
1007
  }
1013
1008
  }
1014
- _collectionIdSetsExist() {
1009
+ _collectionIdSetsTableNotFound() {
1010
+ const brokenCollections = [];
1011
+ iterateTables(this.rljson, (tableKey, table) => {
1012
+ if (table._type !== "collections") {
1013
+ return;
1014
+ }
1015
+ const collectionsTable = table;
1016
+ for (const collection of collectionsTable._data) {
1017
+ const idSets = collection.idSetsTable;
1018
+ if (!idSets) {
1019
+ continue;
1020
+ }
1021
+ const idSetsTable = this.rljsonIndexed[idSets];
1022
+ if (!idSetsTable) {
1023
+ brokenCollections.push({
1024
+ collectionsTable: tableKey,
1025
+ collectionHash: collection._hash,
1026
+ missingIdSetsTable: idSets
1027
+ });
1028
+ }
1029
+ }
1030
+ });
1031
+ if (brokenCollections.length > 0) {
1032
+ this.errors.collectionIdSetsTableNotFound = {
1033
+ error: "Id sets tables are missing",
1034
+ brokenCollections
1035
+ };
1036
+ }
1037
+ }
1038
+ _collectionIdSetNotFound() {
1015
1039
  const brokenCollections = [];
1016
1040
  iterateTables(this.rljson, (tableKey, table) => {
1017
1041
  if (table._type !== "collections") {
1018
1042
  return;
1019
1043
  }
1020
- const idSets = this.rljsonIndexed.idSets;
1021
1044
  const collectionsTable = table;
1022
1045
  for (const collection of collectionsTable._data) {
1023
1046
  const idSetRef = collection.idSet;
1024
1047
  if (!idSetRef) {
1025
1048
  continue;
1026
1049
  }
1027
- const idSet = idSets._data[idSetRef];
1050
+ const idSets = collection.idSetsTable;
1051
+ const idSetsTable = this.rljsonIndexed[idSets];
1052
+ const idSet = idSetsTable._data[idSetRef];
1028
1053
  if (!idSet) {
1029
1054
  brokenCollections.push({
1030
1055
  collectionsTable: tableKey,
@@ -1035,7 +1060,7 @@ class _BaseValidator {
1035
1060
  }
1036
1061
  });
1037
1062
  if (brokenCollections.length > 0) {
1038
- this.errors.collectionIdSetsExist = {
1063
+ this.errors.collectionIdSetNotFound = {
1039
1064
  error: "Id sets of collections are missing",
1040
1065
  brokenCollections
1041
1066
  };
@@ -1091,19 +1116,49 @@ class _BaseValidator {
1091
1116
  };
1092
1117
  }
1093
1118
  }
1094
- _cakeIdSetsNotFound() {
1119
+ _cakeIdSetsTableNotFound() {
1120
+ const brokenCakes = [];
1121
+ iterateTables(this.rljson, (tableKey, table) => {
1122
+ if (table._type !== "cakes") {
1123
+ return;
1124
+ }
1125
+ const cakesTable = table;
1126
+ for (const cake of cakesTable._data) {
1127
+ const idSetsRef = cake.idSetsTable;
1128
+ if (!idSetsRef) {
1129
+ continue;
1130
+ }
1131
+ const idSets = this.rljsonIndexed[idSetsRef];
1132
+ if (!idSets) {
1133
+ brokenCakes.push({
1134
+ cakeTable: tableKey,
1135
+ brokenCake: cake._hash,
1136
+ missingIdSets: idSetsRef
1137
+ });
1138
+ }
1139
+ }
1140
+ });
1141
+ if (brokenCakes.length > 0) {
1142
+ this.errors.cakeIdSetsTableNotFound = {
1143
+ error: "Id sets tables referenced by cakes are missing",
1144
+ brokenCakes
1145
+ };
1146
+ }
1147
+ }
1148
+ _cakeIdSetNotFound() {
1095
1149
  const brokenCakes = [];
1096
1150
  iterateTables(this.rljson, (tableKey, table) => {
1097
1151
  if (table._type !== "cakes") {
1098
1152
  return;
1099
1153
  }
1100
- const idSets = this.rljsonIndexed.idSets;
1101
1154
  const cakesTable = table;
1102
1155
  for (const cake of cakesTable._data) {
1103
1156
  const idSetRef = cake.idSet;
1104
1157
  if (!idSetRef) {
1105
1158
  continue;
1106
1159
  }
1160
+ const idSetsRef = cake.idSetsTable;
1161
+ const idSets = this.rljsonIndexed[idSetsRef];
1107
1162
  const idSet = idSets._data[idSetRef];
1108
1163
  if (!idSet) {
1109
1164
  brokenCakes.push({
@@ -1115,7 +1170,7 @@ class _BaseValidator {
1115
1170
  }
1116
1171
  });
1117
1172
  if (brokenCakes.length > 0) {
1118
- this.errors.cakeIdSetsNotFound = {
1173
+ this.errors.cakeIdSetNotFound = {
1119
1174
  error: "Id sets of cakes are missing",
1120
1175
  brokenCakes
1121
1176
  };
@@ -7,6 +7,11 @@
7
7
  import { hip } from '@rljson/hash';
8
8
  import { exampleJsonObject } from '@rljson/json';
9
9
 
10
+ import { BuffetsTable } from './content/buffet.ts';
11
+ import { Cake, CakesTable } from './content/cake.ts';
12
+ import { Collection, CollectionsTable } from './content/collection.ts';
13
+ import { IdSetsTable } from './content/id-set.ts';
14
+ import { PropertiesTable } from './content/properties.ts';
10
15
  import { TablesCfgTable } from './content/table-cfg.ts';
11
16
  import { bakeryExample } from './example/bakery-example.ts';
12
17
  import { Rljson } from './rljson.ts';
@@ -36,9 +41,11 @@ export class Example {
36
41
  singleRow: (): Rljson => {
37
42
  const tableCfgs: TablesCfgTable = hip({
38
43
  _hash: '',
44
+
39
45
  _type: 'properties',
40
46
  _data: [
41
47
  {
48
+ version: 0,
42
49
  _hash: '',
43
50
  key: 'table',
44
51
  type: 'properties',
@@ -149,80 +156,84 @@ export class Example {
149
156
  };
150
157
  },
151
158
  complete: (): Rljson => {
152
- return {
153
- idSets: {
154
- _type: 'idSets',
159
+ const idSets: IdSetsTable = hip({
160
+ _type: 'idSets',
161
+ _data: [
162
+ {
163
+ add: ['id0', 'id1'],
164
+ },
165
+ ],
166
+ });
155
167
 
156
- _data: [
157
- {
158
- add: ['id0', 'id1'],
159
- _hash: 'MgHRBYSrhpyl4rvsOmAWcQ',
160
- },
161
- ],
162
- },
168
+ const properties: PropertiesTable<any> = hip({
169
+ _type: 'properties',
170
+ _data: [{ a: '0' }, { a: '1' }],
171
+ });
172
+ const property0 = properties._data[0];
173
+ const property1 = properties._data[1];
174
+
175
+ const collection0: Collection = hip({
176
+ idSetsTable: 'idSets',
177
+ idSet: 'MgHRBYSrhpyl4rvsOmAWcQ',
178
+ properties: 'properties',
179
+ assign: {},
180
+ });
163
181
 
164
- properties: {
165
- _type: 'properties',
166
- _data: [
167
- { a: '0', _hash: 'AFhW-fMzdCiz6bUZscp1Lf' },
168
- { a: '1', _hash: 'mv6w8rID8lQxLsje1EHQMY' },
169
- ],
182
+ const collection1: Collection = hip({
183
+ base: collection0._hash as string,
184
+ idSetsTable: 'idSets',
185
+ idSet: 'MgHRBYSrhpyl4rvsOmAWcQ',
186
+ properties: 'properties',
187
+ assign: {
188
+ id0: property0._hash,
189
+ id1: property1._hash,
170
190
  },
191
+ });
171
192
 
172
- collections: {
173
- _type: 'collections',
174
- _data: [
175
- {
176
- idSet: 'MgHRBYSrhpyl4rvsOmAWcQ',
177
- properties: 'properties',
178
- _hash: 'sxv2NCM6UNOcX-i9FhOs5W',
179
- assign: {},
180
- },
181
- {
182
- base: 'sxv2NCM6UNOcX-i9FhOs5W',
183
- idSet: 'MgHRBYSrhpyl4rvsOmAWcQ',
184
- properties: 'properties',
185
- assign: {
186
- id0: 'AFhW-fMzdCiz6bUZscp1Lf',
187
- id1: 'mv6w8rID8lQxLsje1EHQMY',
188
- },
189
- _hash: 'QB2JC6X_-rUAoixuldzWP-',
190
- },
191
- ],
193
+ const collections: CollectionsTable = hip({
194
+ _type: 'collections',
195
+ _data: [collection0, collection1],
196
+ } as CollectionsTable);
197
+
198
+ const cake: Cake = hip({
199
+ idSetsTable: 'idSets',
200
+ idSet: idSets._data[0]._hash as string,
201
+ collections: 'collections',
202
+ layers: {
203
+ layer0: collection0._hash as string,
204
+ layer1: collection1._hash as string,
192
205
  },
206
+ });
193
207
 
194
- cakes: {
195
- _type: 'cakes',
196
- _data: [
197
- {
198
- idSet: 'MgHRBYSrhpyl4rvsOmAWcQ',
199
- collections: 'collections',
200
- layers: {
201
- layer0: 'sxv2NCM6UNOcX-i9FhOs5W',
202
- layer1: 'QB2JC6X_-rUAoixuldzWP-',
208
+ const cakes: CakesTable = hip({
209
+ _type: 'cakes',
210
+ _data: [cake],
211
+ });
212
+
213
+ const buffets: BuffetsTable = hip({
214
+ _type: 'buffets',
215
+ _data: [
216
+ {
217
+ items: [
218
+ {
219
+ table: 'cakes',
220
+ ref: cakes._data[0]._hash as string,
203
221
  },
204
- _hash: 'QlTVJL3uoXO1L_fw2evLPe',
205
- },
206
- ],
207
- },
222
+ {
223
+ table: 'collections',
224
+ ref: collection0._hash as string,
225
+ },
226
+ ],
227
+ },
228
+ ],
229
+ });
208
230
 
209
- buffets: {
210
- _type: 'buffets',
211
- _data: [
212
- {
213
- items: [
214
- {
215
- table: 'cakes',
216
- ref: 'QlTVJL3uoXO1L_fw2evLPe',
217
- },
218
- {
219
- table: 'collections',
220
- ref: 'QB2JC6X_-rUAoixuldzWP-',
221
- },
222
- ],
223
- },
224
- ],
225
- },
231
+ return {
232
+ idSets,
233
+ properties,
234
+ collections,
235
+ cakes,
236
+ buffets,
226
237
  };
227
238
  },
228
239
  };
@@ -330,8 +341,8 @@ export class Example {
330
341
 
331
342
  missingAssignedProperty: (): Rljson => {
332
343
  const result = Example.ok.complete();
333
- result.properties._data.splice(1, 2); // Remove an property that is assigne
334
- return result;
344
+ result.properties._data.splice(1, 2); // Remove an property that is assigned
345
+ return hip(result, true, false);
335
346
  },
336
347
  },
337
348
 
@@ -365,7 +376,7 @@ export class Example {
365
376
  const buffet = result.buffets._data[0];
366
377
  buffet.items[0].table = 'MISSING0';
367
378
  buffet.items[1].table = 'MISSING1';
368
- hip(buffet, true, false);
379
+ hip(result, true, false);
369
380
  return result;
370
381
  },
371
382
 
@@ -374,7 +385,7 @@ export class Example {
374
385
  const buffet = result.buffets._data[0];
375
386
  buffet.items[0].ref = 'MISSING0';
376
387
  buffet.items[1].ref = 'MISSING1';
377
- hip(buffet, true, false);
388
+ hip(result, true, false);
378
389
  return result;
379
390
  },
380
391
  },
@@ -18,10 +18,12 @@ export interface BaseErrors extends Errors {
18
18
  tableTypesDoNotMatch?: Json;
19
19
  refsNotFound?: Json;
20
20
  collectionBasesNotFound?: Json;
21
- collectionIdSetsNotFound?: Json;
21
+ collectionIdSetsTableNotFound?: Json;
22
+ collectionIdSetNotFound?: Json;
22
23
  collectionPropertyTablesNotFound?: Json;
23
24
  collectionPropertyAssignmentsNotFound?: Json;
24
- cakeIdSetsNotFound?: Json;
25
+ cakeIdSetsTableNotFound?: Json;
26
+ cakeIdSetNotFound?: Json;
25
27
  cakeCollectionTablesNotFound?: Json;
26
28
  cakeLayerCollectionsNotFound?: Json;
27
29
  buffetReferencedTablesNotFound?: Json;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "packageManager": "pnpm@10.6.3",
5
5
  "description": "The RLJSON data format specification",
6
6
  "homepage": "https://github.com/rljson/rljson",