@rljson/rljson 0.0.12 → 0.0.15

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.
@@ -4,147 +4,395 @@
4
4
  // Use of this source code is governed by terms that can be
5
5
  // found in the LICENSE file in the root of this package.
6
6
 
7
+ import { hip } from '@rljson/hash';
7
8
  import { exampleJsonObject } from '@rljson/json';
8
9
 
9
- import { BuffetsTable } from './content/buffet.ts';
10
+ import { TablesCfgTable } from './content/table-cfg.ts';
11
+ import { bakeryExample } from './example/bakery-example.ts';
10
12
  import { Rljson } from './rljson.ts';
11
13
 
12
- /**
13
- * Provides Rljson examples
14
- */
15
14
  export class Example {
16
- /**
17
- * Returns the Rljson bakery example
18
- */
19
- static bakery(): Rljson {
20
- return {
21
- // A bakery is a collection of buffets
22
- bakery: {
23
- name: 'Bakery',
24
- _type: 'buffets',
15
+ static readonly ok = {
16
+ bakery: (): Rljson => bakeryExample(),
17
+
18
+ empty: (): Rljson => {
19
+ return {};
20
+ },
21
+
22
+ binary: (): Rljson => {
23
+ return {
24
+ table: {
25
+ _type: 'properties',
26
+ _data: [
27
+ { a: false, b: false },
28
+ { a: false, b: true },
29
+ { a: true, b: false },
30
+ { a: true, b: true },
31
+ ],
32
+ },
33
+ };
34
+ },
35
+
36
+ singleRow: (): Rljson => {
37
+ const tableCfgs: TablesCfgTable = {
38
+ _hash: '',
39
+ _type: 'properties',
25
40
  _data: [
26
- // Counter
27
41
  {
28
- id: 'counter',
29
- items: [
30
- // Angle pie
31
- {
32
- table: 'cakes',
33
- ref: 'ap',
42
+ _hash: 'R-rCQ4YwYYJAp6uAo6S_6n',
43
+ name: 'Single Row Table',
44
+ jsonKey: 'table',
45
+ columns: {
46
+ int: {
47
+ jsonKey: 'int',
48
+ type: 'number',
49
+ name: 'Integer',
50
+ nameShort: 'Int',
51
+ },
52
+ double: {
53
+ jsonKey: 'double',
54
+ type: 'number',
55
+ name: 'Double',
56
+ nameShort: 'Dbl',
57
+ },
58
+ string: {
59
+ jsonKey: 'string',
60
+ type: 'string',
61
+ name: 'String',
62
+ nameShort: 'Str',
63
+ },
64
+ boolean: {
65
+ jsonKey: 'boolean',
66
+ type: 'boolean',
67
+ name: 'Boolean',
68
+ nameShort: 'Bool',
69
+ },
70
+ null: {
71
+ jsonKey: 'null',
72
+ type: 'null',
73
+ name: 'null',
74
+ nameShort: 'null',
75
+ },
76
+ jsonArray: {
77
+ jsonKey: 'jsonArray',
78
+ type: 'jsonArray',
79
+ name: 'Json Array',
80
+ nameShort: 'Jarray',
81
+ },
82
+ json: {
83
+ jsonKey: 'json',
84
+ type: 'json',
85
+ name: 'Json',
86
+ nameShort: 'Json',
87
+ },
88
+ jsonValue: {
89
+ jsonKey: 'jsonValue',
90
+ type: 'jsonValue',
91
+ name: 'Json Value',
92
+ nameShort: 'Jval',
93
+ },
94
+ },
95
+ },
96
+ ],
97
+ };
98
+
99
+ const result: Rljson = {
100
+ _tableCfgs: tableCfgs,
101
+ table: {
102
+ _type: 'properties',
103
+ _tableCfg: 'R-rCQ4YwYYJAp6uAo6S_6n',
104
+ _data: [exampleJsonObject()],
105
+ _hash: '',
106
+ },
107
+ };
108
+ return result as Rljson;
109
+ },
110
+
111
+ multipleRows: (): Rljson => {
112
+ return {
113
+ table: {
114
+ _type: 'properties',
115
+ _data: [
116
+ {
117
+ string: 'str0',
118
+ boolean: true,
119
+ number: 1,
120
+ array: [1, 'str0', true, { a: { b: 'c' } }],
121
+ object: { a: { b: 'c' } },
122
+ },
123
+
124
+ {
125
+ string: 'str1',
126
+ boolean: true,
127
+ number: 1,
128
+ array: [1, 'str1', true, { a: { b: 'c' } }],
129
+ object: { a: { b: 'c' } },
130
+ },
131
+
132
+ {
133
+ string: 'str2',
134
+ boolean: false,
135
+ number: 1,
136
+ array: [1, 'str1', true, { a: { b: 'c' } }],
137
+ object: { d: { e: 'f' } },
138
+ },
139
+ ],
140
+ },
141
+ };
142
+ },
143
+
144
+ singleRef: (): Rljson => {
145
+ return {
146
+ tableA: {
147
+ _type: 'properties',
148
+ _data: [
149
+ {
150
+ keyA0: 'a0',
151
+ },
152
+ {
153
+ keyA1: 'a1',
154
+ },
155
+ ],
156
+ },
157
+ tableB: {
158
+ _type: 'properties',
159
+ _data: [
160
+ {
161
+ tableARef: 'KFQrf4mEz0UPmUaFHwH4T6',
162
+ },
163
+ ],
164
+ },
165
+ };
166
+ },
167
+ complete: (): Rljson => {
168
+ return {
169
+ _idSets: {
170
+ _type: 'idSets',
171
+
172
+ _data: [
173
+ {
174
+ add: ['id0', 'id1'],
175
+ _hash: 'MgHRBYSrhpyl4rvsOmAWcQ',
176
+ },
177
+ ],
178
+ },
179
+
180
+ properties: {
181
+ _type: 'properties',
182
+ _data: [
183
+ { a: '0', _hash: 'AFhW-fMzdCiz6bUZscp1Lf' },
184
+ { a: '1', _hash: 'mv6w8rID8lQxLsje1EHQMY' },
185
+ ],
186
+ },
187
+
188
+ collections: {
189
+ _type: 'collections',
190
+ _data: [
191
+ {
192
+ idSet: 'MgHRBYSrhpyl4rvsOmAWcQ',
193
+ properties: 'properties',
194
+ _hash: 'sxv2NCM6UNOcX-i9FhOs5W',
195
+ assign: {},
196
+ },
197
+ {
198
+ base: 'sxv2NCM6UNOcX-i9FhOs5W',
199
+ idSet: 'MgHRBYSrhpyl4rvsOmAWcQ',
200
+ properties: 'properties',
201
+ assign: {
202
+ id0: 'AFhW-fMzdCiz6bUZscp1Lf',
203
+ id1: 'mv6w8rID8lQxLsje1EHQMY',
204
+ },
205
+ _hash: 'QB2JC6X_-rUAoixuldzWP-',
206
+ },
207
+ ],
208
+ },
209
+
210
+ cakes: {
211
+ _type: 'cakes',
212
+ _data: [
213
+ {
214
+ idSet: 'MgHRBYSrhpyl4rvsOmAWcQ',
215
+ collections: 'collections',
216
+ layers: {
217
+ layer0: 'sxv2NCM6UNOcX-i9FhOs5W',
218
+ layer1: 'QB2JC6X_-rUAoixuldzWP-',
34
219
  },
220
+ _hash: 'QlTVJL3uoXO1L_fw2evLPe',
221
+ },
222
+ ],
223
+ },
224
+
225
+ buffets: {
226
+ _type: 'buffets',
227
+ _data: [
228
+ {
229
+ items: [
230
+ {
231
+ table: 'cakes',
232
+ ref: 'QlTVJL3uoXO1L_fw2evLPe',
233
+ },
234
+ {
235
+ table: 'collections',
236
+ ref: 'QB2JC6X_-rUAoixuldzWP-',
237
+ },
238
+ ],
239
+ },
240
+ ],
241
+ },
242
+ };
243
+ },
244
+ };
245
+
246
+ static readonly broken = {
247
+ base: {
248
+ brokenTableName: () => {
249
+ return {
250
+ brok$en: {
251
+ _type: 'properties',
252
+ _data: [],
253
+ },
254
+ };
255
+ },
35
256
 
36
- // Cumb cake
257
+ missingData: () => {
258
+ return {
259
+ table: {
260
+ _type: 'properties',
261
+ },
262
+ } as unknown as Rljson;
263
+ },
264
+
265
+ dataNotBeingAnArray: () => {
266
+ return {
267
+ table: {
268
+ _type: 'properties',
269
+ _data: {},
270
+ },
271
+ } as unknown as Rljson;
272
+ },
273
+
274
+ missingRef: (): Rljson => {
275
+ return {
276
+ tableA: {
277
+ _type: 'properties',
278
+ _data: [
279
+ {
280
+ keyA0: 'a0',
281
+ },
37
282
  {
38
- table: 'cakes',
39
- ref: 'cc',
283
+ keyA1: 'a1',
40
284
  },
41
285
  ],
42
286
  },
43
-
44
- // Fridge
45
- {
46
- id: 'fridge',
47
- items: [
48
- // Black forest
287
+ tableB: {
288
+ _type: 'properties',
289
+ _data: [
49
290
  {
50
- table: 'cakes',
51
- ref: 'bf',
291
+ tableARef: 'MISSINGREF', // MISSINGREF does not exist in tableA
52
292
  },
293
+ ],
294
+ },
295
+ };
296
+ },
53
297
 
54
- // Lemon cheese cake
298
+ missingReferencedTable: (): Rljson => {
299
+ return {
300
+ tableB: {
301
+ _type: 'properties',
302
+ _data: [
55
303
  {
56
- table: 'cakes',
57
- ref: 'cc',
304
+ tableARef: 'MISSINGREF', // tableA is missing
58
305
  },
59
306
  ],
60
307
  },
61
- ],
62
- } as BuffetsTable,
63
- };
64
- }
65
-
66
- /**
67
- * Returns an Rljson object with one row containing all JSON types
68
- */
69
- static withAllJsonTypes(): Rljson {
70
- return {
71
- table: {
72
- _type: 'properties',
73
- _data: [exampleJsonObject()],
308
+ };
74
309
  },
75
- };
76
- }
77
-
78
- /**
79
- * Returns an empty Rljson object
80
- */
81
- static empty(): Rljson {
82
- return {};
83
- }
84
-
85
- /**
86
- * Returns an Rljson with a table containing all combinations of true and
87
- * false. This is useful for testing search operators.
88
- */
89
- static binary(): Rljson {
90
- return {
91
- table: {
92
- _type: 'properties',
93
- _data: [
94
- { a: false, b: false },
95
- { a: false, b: true },
96
- { a: true, b: false },
97
- { a: true, b: true },
98
- ],
310
+ },
311
+
312
+ tableCfg: {
313
+ wrongType: () => {
314
+ const result = Example.ok.singleRow();
315
+ const tableCfg = result._tableCfgs._data[0];
316
+ tableCfg.columns['int'].type = 'numberBroken'; // Break one of the types
317
+ return hip(result, true, false);
99
318
  },
100
- };
101
- }
102
-
103
- /**
104
- * An more complex example containing an table with multiple rows
105
- */
106
- static multiRow(): Rljson {
107
- return {
108
- table: {
109
- _type: 'properties',
110
- _data: [
111
- {
112
- string: 'str0',
113
- boolean: true,
114
- number: 1,
115
- array: [1, 'str0', true, { a: { b: 'c' } }],
116
- object: { a: { b: 'c' } },
117
- },
319
+ },
118
320
 
119
- {
120
- string: 'str1',
121
- boolean: true,
122
- number: 1,
123
- array: [1, 'str1', true, { a: { b: 'c' } }],
124
- object: { a: { b: 'c' } },
125
- },
321
+ collections: {
322
+ missingBase: (): Rljson => {
323
+ const result = Example.ok.complete();
324
+ const collection1 = result.collections._data[1];
325
+ collection1.base = 'MISSING'; // Missing base
126
326
 
127
- {
128
- string: 'str2',
129
- boolean: false,
130
- number: 1,
131
- array: [1, 'str1', true, { a: { b: 'c' } }],
132
- object: { d: { e: 'f' } },
133
- },
134
- ],
327
+ // Recalculate hashes
328
+ return hip(result, true, false);
135
329
  },
136
- };
137
- }
138
-
139
- /**
140
- * Returns an Rljson object with a broken table name
141
- */
142
- static withBrokenTableName(): Rljson {
143
- return {
144
- brok$en: {
145
- _type: 'properties',
146
- _data: [],
330
+
331
+ missingIdSet: (): Rljson => {
332
+ const result = Example.ok.complete();
333
+ const collection1 = result.collections._data[1];
334
+
335
+ collection1.idSet = 'MISSING1';
336
+
337
+ // Recalculate hashes
338
+ return hip(result, true, false);
339
+ },
340
+
341
+ missingAssignedPropertyTable: (): Rljson => {
342
+ const result = Example.ok.complete();
343
+ delete result.properties; // Remove properties table
344
+ return result;
345
+ },
346
+
347
+ missingAssignedProperty: (): Rljson => {
348
+ const result = Example.ok.complete();
349
+ result.properties._data.splice(1, 2); // Remove an property that is assigne
350
+ return result;
351
+ },
352
+ },
353
+
354
+ cakes: {
355
+ missingIdSet: (): Rljson => {
356
+ const result = Example.ok.complete();
357
+ result.cakes._data[0].idSet = 'MISSING'; // Missing ID set
358
+ hip(result.cakes, true, false);
359
+ return result;
360
+ },
361
+
362
+ missingCollectionsTable: (): Rljson => {
363
+ const result = Example.ok.complete();
364
+ result.cakes._data[0].collections = 'MISSING'; // Missing collections table
365
+ hip(result.cakes, true, false);
366
+ return result;
367
+ },
368
+
369
+ missingLayerCollection: (): Rljson => {
370
+ const result = Example.ok.complete();
371
+ result.cakes._data[0].layers['layer0'] = 'MISSING0';
372
+ result.cakes._data[0].layers['layer1'] = 'MISSING1';
373
+ hip(result.cakes, true, false);
374
+ return result;
375
+ },
376
+ },
377
+
378
+ buffets: {
379
+ missingTable: (): Rljson => {
380
+ const result = Example.ok.complete();
381
+ const buffet = result.buffets._data[0];
382
+ buffet.items[0].table = 'MISSING0';
383
+ buffet.items[1].table = 'MISSING1';
384
+ hip(buffet, true, false);
385
+ return result;
386
+ },
387
+
388
+ missingItems: (): Rljson => {
389
+ const result = Example.ok.complete();
390
+ const buffet = result.buffets._data[0];
391
+ buffet.items[0].ref = 'MISSING0';
392
+ buffet.items[1].ref = 'MISSING1';
393
+ hip(buffet, true, false);
394
+ return result;
147
395
  },
148
- };
149
- }
396
+ },
397
+ };
150
398
  }
@@ -22,7 +22,10 @@ export type TableName = ItemId;
22
22
  * - `properties` Tables containing item properties
23
23
  */
24
24
  export type ContentType = 'buffets' | 'cakes' | 'collections' | 'idSets' | 'properties';
25
- export declare const exampleTypedefs: {
25
+ /**
26
+ * An example object using the typedefs
27
+ */
28
+ export declare const exampleTypedefs: () => {
26
29
  ref: Ref;
27
30
  itemId: ItemId;
28
31
  tableName: TableName;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.12",
4
- "packageManager": "pnpm@10.6.2",
3
+ "version": "0.0.15",
4
+ "packageManager": "pnpm@10.6.3",
5
5
  "description": "The RLJSON data format specification",
6
6
  "homepage": "https://github.com/rljson/rljson",
7
7
  "bugs": "https://github.com/rljson/rljson/issues",
@@ -32,10 +32,10 @@
32
32
  "@types/node": "^22.13.10",
33
33
  "@typescript-eslint/eslint-plugin": "^8.26.1",
34
34
  "@typescript-eslint/parser": "^8.26.1",
35
- "@vitest/coverage-v8": "^3.0.8",
35
+ "@vitest/coverage-v8": "^3.0.9",
36
36
  "cross-env": "^7.0.3",
37
37
  "eslint": "^9.22.0",
38
- "eslint-plugin-jsdoc": "^50.6.6",
38
+ "eslint-plugin-jsdoc": "^50.6.8",
39
39
  "eslint-plugin-tsdoc": "^0.4.0",
40
40
  "globals": "^16.0.0",
41
41
  "jsdoc": "^4.0.4",
@@ -43,15 +43,15 @@
43
43
  "typescript": "~5.8.2",
44
44
  "typescript-eslint": "^8.26.1",
45
45
  "vite": "^6.2.2",
46
- "vite-node": "^3.0.8",
46
+ "vite-node": "^3.0.9",
47
47
  "vite-plugin-dts": "^4.5.3",
48
48
  "vite-tsconfig-paths": "^5.1.4",
49
- "vitest": "^3.0.8",
49
+ "vitest": "^3.0.9",
50
50
  "vitest-dom": "^0.1.1"
51
51
  },
52
52
  "dependencies": {
53
- "@rljson/hash": "^0.0.11",
54
- "@rljson/json": "^0.0.13"
53
+ "@rljson/hash": "^0.0.12",
54
+ "@rljson/json": "^0.0.18"
55
55
  },
56
56
  "pnpm": {
57
57
  "onlyBuiltDependencies": [