@rljson/rljson 0.0.11 → 0.0.14
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/README.contributors.md +106 -49
- package/dist/README.contributors.md +106 -49
- package/dist/example.d.ts +39 -4
- package/dist/index.d.ts +8 -0
- package/dist/rljson-indexed.d.ts +19 -0
- package/dist/rljson.d.ts +35 -160
- package/dist/rljson.js +464 -50
- package/dist/src/example.ts +314 -12
- package/dist/typedefs.d.ts +33 -0
- package/package.json +9 -9
package/dist/rljson.js
CHANGED
|
@@ -1,61 +1,475 @@
|
|
|
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
|
+
import { hip, hsh } from "@rljson/hash";
|
|
1
5
|
import { exampleJsonObject } from "@rljson/json";
|
|
2
6
|
// @license
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
const bakeryExample = () => {
|
|
8
|
+
return {
|
|
9
|
+
// Every rljson object has a list of id-sets other objects can refer to
|
|
10
|
+
_idSets: {
|
|
11
|
+
_type: "idSets",
|
|
12
|
+
_data: [
|
|
13
|
+
{
|
|
14
|
+
add: ["slice0", "slice1"],
|
|
15
|
+
_hash: "KAwCRFD4mdx8b1bzxBb2_O"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
// A bakery offers a variety of buffets containing different pastries
|
|
20
|
+
buffets: {
|
|
21
|
+
_type: "buffets",
|
|
22
|
+
_data: [
|
|
23
|
+
{
|
|
24
|
+
items: [{ table: "cakes", ref: "fw8IrV05Z1ZekPXTdUdmt8" }]
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
// A cake is a collection of layers, i.e. a base, a filling and a topping.
|
|
29
|
+
// Each layer of the cake has the same slice structure.
|
|
30
|
+
cakes: {
|
|
31
|
+
_type: "cakes",
|
|
32
|
+
_data: [
|
|
33
|
+
{
|
|
34
|
+
idSet: "KAwCRFD4mdx8b1bzxBb2_O",
|
|
35
|
+
collections: "layers",
|
|
36
|
+
layers: {
|
|
37
|
+
_hash: "50ZHxZ8KeUYJ3NC7ax5CbR"
|
|
38
|
+
},
|
|
39
|
+
_hash: "gMqFPTkYU66L32jDYZiZ79"
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
_hash: "fw8IrV05Z1ZekPXTdUdmt8"
|
|
43
|
+
},
|
|
44
|
+
// Cakes are cut into slices. The cake layers are shared among the slices.
|
|
45
|
+
slices: {
|
|
46
|
+
_type: "idSets",
|
|
47
|
+
_data: [
|
|
48
|
+
{
|
|
49
|
+
add: ["slice0", "slice1"],
|
|
50
|
+
remove: []
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
// A layer is a collection of ingredients described by a recipe
|
|
55
|
+
layers: {
|
|
56
|
+
_type: "collections",
|
|
57
|
+
_data: [
|
|
58
|
+
{
|
|
59
|
+
properties: "recipes",
|
|
60
|
+
assign: {
|
|
61
|
+
slice0: "VXUW79JrkOAG_pQ-75ahH5",
|
|
62
|
+
slice1: "VXUW79JrkOAG_pQ-75ahH5",
|
|
63
|
+
_hash: "Di4uG3-DHSq3_ArFu0V68m"
|
|
64
|
+
},
|
|
65
|
+
_hash: "IIg0e-6Qr73s7sNZe0RhKs"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
_hash: "e3utfEf_VS1-ljAMgqesua"
|
|
69
|
+
},
|
|
70
|
+
// Recipes are sets of ingredients
|
|
71
|
+
recipes: {
|
|
72
|
+
_type: "collections",
|
|
73
|
+
_data: [
|
|
74
|
+
{
|
|
75
|
+
properties: "recipeIngredients",
|
|
76
|
+
assign: {
|
|
77
|
+
flour: "mqLl7Q44V1t2MotJvaVRM_",
|
|
78
|
+
_hash: "UImWlyWZTSGhNAMC1JUzF1"
|
|
79
|
+
},
|
|
80
|
+
_hash: "G1YV_P8-_vTxtkXXHJeNBI"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
_hash: "r3lw7VsnywyasRmtynZqIt"
|
|
84
|
+
},
|
|
85
|
+
// A recipe ingredient combines an ingredient type with a quantity
|
|
86
|
+
recipeIngredients: {
|
|
87
|
+
_type: "properties",
|
|
88
|
+
_data: [
|
|
89
|
+
{
|
|
90
|
+
ingredientTypesRef: "WOfnFT1svec3iJ6x",
|
|
91
|
+
quantity: 500,
|
|
92
|
+
_hash: "mqLl7Q44V1t2MotJvaVRM_"
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
_hash: "J7GJEjCRXLNfdAHARg_fzx"
|
|
96
|
+
},
|
|
97
|
+
// A table describing basic properties of ingredients
|
|
98
|
+
ingredients: {
|
|
99
|
+
_type: "properties",
|
|
100
|
+
_data: [
|
|
101
|
+
{
|
|
102
|
+
name: "flour",
|
|
103
|
+
amountUnit: "g",
|
|
104
|
+
nutritiveValuesRef: "gZXFSlrl5QAs5hOVsq5sWB",
|
|
105
|
+
_hash: "CdSJV-WOfnFT1svec3iJ6x"
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
_hash: "FgJeTM0NcZvXwFcU-PD8Jf"
|
|
109
|
+
},
|
|
110
|
+
// A table with nutritive values of ingredients
|
|
111
|
+
nutritiveValues: {
|
|
112
|
+
_type: "properties",
|
|
113
|
+
_data: [
|
|
114
|
+
{
|
|
115
|
+
energy: 364,
|
|
116
|
+
fat: 0.98,
|
|
117
|
+
protein: 10.33,
|
|
118
|
+
carbohydrates: 76.31,
|
|
119
|
+
_hash: "gZXFSlrl5QAs5hOVsq5sWB"
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
_hash: "7k4OqQtk71w3yVGMoA9F6p"
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
// @license
|
|
127
|
+
const exampleBuffetsTable = () => bakeryExample().buffets;
|
|
128
|
+
// @license
|
|
129
|
+
const exampleCakesTable = () => bakeryExample().cakes;
|
|
130
|
+
// @license
|
|
131
|
+
const exampleCollectionsTable = () => bakeryExample().layers;
|
|
132
|
+
// @license
|
|
133
|
+
const exampleIdSetsTable = () => bakeryExample().slices;
|
|
134
|
+
// @license
|
|
135
|
+
const examplePropertiesTable = () => bakeryExample().nutritiveValues;
|
|
136
|
+
// @license
|
|
137
|
+
const _Example = class _Example {
|
|
138
|
+
};
|
|
139
|
+
__publicField(_Example, "ok", {
|
|
140
|
+
bakery: () => bakeryExample(),
|
|
141
|
+
empty: () => {
|
|
142
|
+
return {};
|
|
143
|
+
},
|
|
144
|
+
binary: () => {
|
|
145
|
+
return {
|
|
146
|
+
table: {
|
|
147
|
+
_type: "properties",
|
|
148
|
+
_data: [
|
|
149
|
+
{ a: false, b: false },
|
|
150
|
+
{ a: false, b: true },
|
|
151
|
+
{ a: true, b: false },
|
|
152
|
+
{ a: true, b: true }
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
singleRow: () => {
|
|
158
|
+
return {
|
|
159
|
+
table: {
|
|
160
|
+
_type: "properties",
|
|
161
|
+
_data: [exampleJsonObject()]
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
},
|
|
165
|
+
multipleRows: () => {
|
|
166
|
+
return {
|
|
167
|
+
table: {
|
|
168
|
+
_type: "properties",
|
|
169
|
+
_data: [
|
|
170
|
+
{
|
|
171
|
+
string: "str0",
|
|
172
|
+
boolean: true,
|
|
173
|
+
number: 1,
|
|
174
|
+
array: [1, "str0", true, { a: { b: "c" } }],
|
|
175
|
+
object: { a: { b: "c" } }
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
string: "str1",
|
|
179
|
+
boolean: true,
|
|
180
|
+
number: 1,
|
|
181
|
+
array: [1, "str1", true, { a: { b: "c" } }],
|
|
182
|
+
object: { a: { b: "c" } }
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
string: "str2",
|
|
186
|
+
boolean: false,
|
|
187
|
+
number: 1,
|
|
188
|
+
array: [1, "str1", true, { a: { b: "c" } }],
|
|
189
|
+
object: { d: { e: "f" } }
|
|
190
|
+
}
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
singleRef: () => {
|
|
196
|
+
return {
|
|
197
|
+
tableA: {
|
|
198
|
+
_type: "properties",
|
|
199
|
+
_data: [
|
|
200
|
+
{
|
|
201
|
+
keyA0: "a0"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
keyA1: "a1"
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
},
|
|
208
|
+
tableB: {
|
|
209
|
+
_type: "properties",
|
|
210
|
+
_data: [
|
|
211
|
+
{
|
|
212
|
+
tableARef: "KFQrf4mEz0UPmUaFHwH4T6"
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
complete: () => {
|
|
219
|
+
return {
|
|
220
|
+
_idSets: {
|
|
221
|
+
_type: "idSets",
|
|
222
|
+
_data: [
|
|
223
|
+
{
|
|
224
|
+
add: ["id0", "id1"],
|
|
225
|
+
_hash: "MgHRBYSrhpyl4rvsOmAWcQ"
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
},
|
|
229
|
+
properties: {
|
|
230
|
+
_type: "properties",
|
|
231
|
+
_data: [
|
|
232
|
+
{ a: "0", _hash: "AFhW-fMzdCiz6bUZscp1Lf" },
|
|
233
|
+
{ a: "1", _hash: "mv6w8rID8lQxLsje1EHQMY" }
|
|
234
|
+
]
|
|
235
|
+
},
|
|
236
|
+
collections: {
|
|
237
|
+
_type: "collections",
|
|
238
|
+
_data: [
|
|
239
|
+
{
|
|
240
|
+
idSet: "MgHRBYSrhpyl4rvsOmAWcQ",
|
|
241
|
+
properties: "properties",
|
|
242
|
+
_hash: "sxv2NCM6UNOcX-i9FhOs5W",
|
|
243
|
+
assign: {}
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
base: "sxv2NCM6UNOcX-i9FhOs5W",
|
|
247
|
+
idSet: "MgHRBYSrhpyl4rvsOmAWcQ",
|
|
248
|
+
properties: "properties",
|
|
249
|
+
assign: {
|
|
250
|
+
id0: "AFhW-fMzdCiz6bUZscp1Lf",
|
|
251
|
+
id1: "mv6w8rID8lQxLsje1EHQMY"
|
|
252
|
+
},
|
|
253
|
+
_hash: "QB2JC6X_-rUAoixuldzWP-"
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
},
|
|
257
|
+
cakes: {
|
|
258
|
+
_type: "cakes",
|
|
259
|
+
_data: [
|
|
260
|
+
{
|
|
261
|
+
idSet: "MgHRBYSrhpyl4rvsOmAWcQ",
|
|
262
|
+
collections: "collections",
|
|
263
|
+
layers: {
|
|
264
|
+
layer0: "sxv2NCM6UNOcX-i9FhOs5W",
|
|
265
|
+
layer1: "QB2JC6X_-rUAoixuldzWP-"
|
|
266
|
+
},
|
|
267
|
+
_hash: "QlTVJL3uoXO1L_fw2evLPe"
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
},
|
|
271
|
+
buffets: {
|
|
272
|
+
_type: "buffets",
|
|
273
|
+
_data: [
|
|
274
|
+
{
|
|
275
|
+
items: [
|
|
276
|
+
{
|
|
277
|
+
table: "cakes",
|
|
278
|
+
ref: "QlTVJL3uoXO1L_fw2evLPe"
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
table: "collections",
|
|
282
|
+
ref: "QB2JC6X_-rUAoixuldzWP-"
|
|
283
|
+
}
|
|
284
|
+
]
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
}
|
|
288
|
+
};
|
|
7
289
|
}
|
|
8
290
|
});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
291
|
+
__publicField(_Example, "broken", {
|
|
292
|
+
brokenTableName: () => {
|
|
293
|
+
return {
|
|
294
|
+
brok$en: {
|
|
295
|
+
_type: "properties",
|
|
296
|
+
_data: []
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
},
|
|
300
|
+
missingData: () => {
|
|
301
|
+
return {
|
|
302
|
+
table: {
|
|
303
|
+
_type: "properties"
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
dataNotBeingAnArray: () => {
|
|
308
|
+
return {
|
|
309
|
+
table: {
|
|
310
|
+
_type: "properties",
|
|
311
|
+
_data: {}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
},
|
|
315
|
+
missingRef: () => {
|
|
316
|
+
return {
|
|
317
|
+
tableA: {
|
|
318
|
+
_type: "properties",
|
|
319
|
+
_data: [
|
|
320
|
+
{
|
|
321
|
+
keyA0: "a0"
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
keyA1: "a1"
|
|
325
|
+
}
|
|
326
|
+
]
|
|
327
|
+
},
|
|
328
|
+
tableB: {
|
|
329
|
+
_type: "properties",
|
|
330
|
+
_data: [
|
|
331
|
+
{
|
|
332
|
+
tableARef: "MISSINGREF"
|
|
333
|
+
// MISSINGREF does not exist in tableA
|
|
334
|
+
}
|
|
335
|
+
]
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
},
|
|
339
|
+
missingReferencedTable: () => {
|
|
340
|
+
return {
|
|
341
|
+
tableB: {
|
|
342
|
+
_type: "properties",
|
|
343
|
+
_data: [
|
|
344
|
+
{
|
|
345
|
+
tableARef: "MISSINGREF"
|
|
346
|
+
// tableA is missing
|
|
347
|
+
}
|
|
348
|
+
]
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
},
|
|
352
|
+
collections: {
|
|
353
|
+
missingBase: () => {
|
|
354
|
+
const result = _Example.ok.complete();
|
|
355
|
+
const collection1 = result.collections._data[1];
|
|
356
|
+
collection1.base = "MISSING";
|
|
357
|
+
return hip(result, true, false);
|
|
358
|
+
},
|
|
359
|
+
missingIdSet: () => {
|
|
360
|
+
const result = _Example.ok.complete();
|
|
361
|
+
const collection1 = result.collections._data[1];
|
|
362
|
+
collection1.idSet = "MISSING1";
|
|
363
|
+
return hip(result, true, false);
|
|
364
|
+
},
|
|
365
|
+
missingAssignedPropertyTable: () => {
|
|
366
|
+
const result = _Example.ok.complete();
|
|
367
|
+
delete result.properties;
|
|
368
|
+
return result;
|
|
369
|
+
},
|
|
370
|
+
missingAssignedProperty: () => {
|
|
371
|
+
const result = _Example.ok.complete();
|
|
372
|
+
result.properties._data.splice(1, 2);
|
|
373
|
+
return result;
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
cakes: {
|
|
377
|
+
missingIdSet: () => {
|
|
378
|
+
const result = _Example.ok.complete();
|
|
379
|
+
result.cakes._data[0].idSet = "MISSING";
|
|
380
|
+
hip(result.cakes, true, false);
|
|
381
|
+
return result;
|
|
382
|
+
},
|
|
383
|
+
missingCollectionsTable: () => {
|
|
384
|
+
const result = _Example.ok.complete();
|
|
385
|
+
result.cakes._data[0].collections = "MISSING";
|
|
386
|
+
hip(result.cakes, true, false);
|
|
387
|
+
return result;
|
|
388
|
+
},
|
|
389
|
+
missingLayerCollection: () => {
|
|
390
|
+
const result = _Example.ok.complete();
|
|
391
|
+
result.cakes._data[0].layers["layer0"] = "MISSING0";
|
|
392
|
+
result.cakes._data[0].layers["layer1"] = "MISSING1";
|
|
393
|
+
hip(result.cakes, true, false);
|
|
394
|
+
return result;
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
buffets: {
|
|
398
|
+
missingTable: () => {
|
|
399
|
+
const result = _Example.ok.complete();
|
|
400
|
+
const buffet = result.buffets._data[0];
|
|
401
|
+
buffet.items[0].table = "MISSING0";
|
|
402
|
+
buffet.items[1].table = "MISSING1";
|
|
403
|
+
hip(buffet, true, false);
|
|
404
|
+
return result;
|
|
405
|
+
},
|
|
406
|
+
missingItems: () => {
|
|
407
|
+
const result = _Example.ok.complete();
|
|
408
|
+
const buffet = result.buffets._data[0];
|
|
409
|
+
buffet.items[0].ref = "MISSING0";
|
|
410
|
+
buffet.items[1].ref = "MISSING1";
|
|
411
|
+
hip(buffet, true, false);
|
|
412
|
+
return result;
|
|
413
|
+
}
|
|
18
414
|
}
|
|
19
415
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
416
|
+
let Example = _Example;
|
|
417
|
+
// @license
|
|
418
|
+
const rljsonIndexed = (rljson) => {
|
|
419
|
+
const result = {};
|
|
420
|
+
for (const key in rljson) {
|
|
421
|
+
const item = rljson[key];
|
|
422
|
+
if (typeof item != "object") {
|
|
423
|
+
result[key] = item;
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
const dataIndexed = {};
|
|
427
|
+
result[key] = { ...item };
|
|
428
|
+
if (!Array.isArray(item._data)) {
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
for (const row of item._data) {
|
|
432
|
+
const hashedRow = row._hash ? row : hsh(row);
|
|
433
|
+
const hash = hashedRow._hash;
|
|
434
|
+
dataIndexed[hash] = hashedRow;
|
|
435
|
+
}
|
|
436
|
+
result[key]._data = dataIndexed;
|
|
25
437
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
string: "str1",
|
|
40
|
-
boolean: true,
|
|
41
|
-
number: 1,
|
|
42
|
-
array: [1, "str1", true, { a: { b: "c" } }],
|
|
43
|
-
object: { a: { b: "c" } }
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
string: "str2",
|
|
47
|
-
boolean: false,
|
|
48
|
-
number: 1,
|
|
49
|
-
array: [1, "str1", true, { a: { b: "c" } }],
|
|
50
|
-
object: { d: { e: "f" } }
|
|
51
|
-
}
|
|
52
|
-
]
|
|
438
|
+
return result;
|
|
439
|
+
};
|
|
440
|
+
// @license
|
|
441
|
+
const reservedFieldNames = ["_type", "_data"];
|
|
442
|
+
const reservedTableNames = ["_hash", "_tables", "_columns"];
|
|
443
|
+
const exampleRljson = () => Example.ok.singleRow();
|
|
444
|
+
const iterateTables = (rljson, callback) => {
|
|
445
|
+
for (const tableName in rljson) {
|
|
446
|
+
const value = rljson[tableName];
|
|
447
|
+
if (typeof value !== "object" || !Array.isArray(value._data)) {
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
callback(tableName, rljson[tableName]);
|
|
53
451
|
}
|
|
54
|
-
}
|
|
452
|
+
};
|
|
453
|
+
// @license
|
|
454
|
+
const exampleTypedefs = () => {
|
|
455
|
+
return {
|
|
456
|
+
ref: "ref",
|
|
457
|
+
itemId: "itemId",
|
|
458
|
+
tableName: "tableName",
|
|
459
|
+
contentType: "collections"
|
|
460
|
+
};
|
|
461
|
+
};
|
|
55
462
|
export {
|
|
56
|
-
|
|
463
|
+
Example,
|
|
464
|
+
exampleBuffetsTable,
|
|
465
|
+
exampleCakesTable,
|
|
466
|
+
exampleCollectionsTable,
|
|
467
|
+
exampleIdSetsTable,
|
|
468
|
+
examplePropertiesTable,
|
|
57
469
|
exampleRljson,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
470
|
+
exampleTypedefs,
|
|
471
|
+
iterateTables,
|
|
472
|
+
reservedFieldNames,
|
|
473
|
+
reservedTableNames,
|
|
474
|
+
rljsonIndexed
|
|
61
475
|
};
|