@rljson/rljson 0.0.31 → 0.0.32

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.
@@ -1,3 +1,11 @@
1
+ <!--
2
+ @license
3
+ Copyright (c) 2025 Rljson
4
+
5
+ Use of this source code is governed by terms that can be
6
+ found in the LICENSE file in the root of this package.
7
+ -->
8
+
1
9
  # Rljson Architecture
2
10
 
3
11
  This document describes the architecture of the Rljson format.
@@ -21,9 +29,9 @@ This document describes the architecture of the Rljson format.
21
29
  - [Hashes](#hashes)
22
30
  - [Linking Tables Using References](#linking-tables-using-references)
23
31
  - [Data Types](#data-types)
24
- - [Properties](#properties)
25
- - [IdSet](#idset)
26
- - [Collection](#collection)
32
+ - [Ingredients](#ingredients)
33
+ - [SliceIds](#sliceids)
34
+ - [Layer](#layer)
27
35
  - [Cake](#cake)
28
36
  - [Buffet](#buffet)
29
37
 
@@ -91,7 +99,7 @@ containing the table rows and a `_type` property describing the table type:
91
99
  ```json
92
100
  {
93
101
  "table0": {
94
- "_type": "properties",
102
+ "_type": "ingredients",
95
103
  "_data": []
96
104
  }
97
105
  }
@@ -129,7 +137,7 @@ Rljson uses hashes to identify and reference data. Using the `hash-in-place`
129
137
  const jsonWithHashes = hip({
130
138
  a: {
131
139
  _data: [{ a: 10 }],
132
- _type: 'properties',
140
+ _type: 'ingredients',
133
141
  },
134
142
  });
135
143
  ```
@@ -147,7 +155,7 @@ This results in:
147
155
  }
148
156
  ],
149
157
  "_hash": "FfCIOVQsrK1g5o5_G-AxP4",
150
- "_type": "properties"
158
+ "_type": "ingredients"
151
159
  }
152
160
  }
153
161
  ```
@@ -161,7 +169,7 @@ table `b` references table `a` using `aRef`:
161
169
  {
162
170
  "b": {
163
171
  "_data": [{ "aRef": "LeFJOCQVgToOfbUuKJQ-GO" }],
164
- "_type": "properties"
172
+ "_type": "ingredients"
165
173
  }
166
174
  }
167
175
  ```
@@ -173,96 +181,153 @@ This reference structure enables automated denormalization of JSON data.
173
181
  Rljson provides several core data structures and table types to manage and
174
182
  synchronize large datasets.
175
183
 
176
- ### Properties
184
+ ### Ingredients
177
185
 
178
- `Properties` are the fundamental data concept. A `PropertiesTable` contains
179
- key-value pairs representing property assignments:
186
+ `Ingredients` are the fundamental data concept. An `IngredientsTable` contains
187
+ key-value pairs assigning values to ingredient names.
180
188
 
181
189
  ```json
182
190
  {
183
- "sizes": {
184
- "_type": "properties",
191
+ "ingredients": {
192
+ "_type": "ingredients",
193
+ "_data": [
194
+ {
195
+ "name": "flour",
196
+ "amountUnit": "g",
197
+ "nutritionalValuesRef": "gZXFSlrl5QAs5hOVsq5sWB"
198
+ }
199
+ ]
200
+ },
201
+
202
+ "nutritionalValues": {
203
+ "_type": "ingredients",
185
204
  "_data": [
186
- { "w": 10, "h": 20 },
187
- { "w": 30, "h": 40 }
205
+ {
206
+ "energy": 364,
207
+ "fat": 0.98,
208
+ "protein": 10.33,
209
+ "carbohydrates": 76.31,
210
+ "_hash": "gZXFSlrl5QAs5hOVsq5sWB"
211
+ }
188
212
  ]
189
213
  }
190
214
  }
191
215
  ```
192
216
 
193
- ### IdSet
217
+ ### SliceIds
194
218
 
195
- For efficient management of large collections, item IDs are separated from their
196
- properties. This allows fetching IDs first and retrieving details later. The
197
- following `IdSet` defines a set of three IDs:
219
+ For efficient management of large layers, slice IDs are separated from their
220
+ ingredients. This allows fetching IDs first and retrieving details later. The
221
+ following `SliceIds` define a set of three slice IDs:
198
222
 
199
223
  ```json
200
224
  {
201
- "add": ["id0", "id1", "id2"],
202
- "_hash": "IDS0"
225
+ "slices": {
226
+ "_type": "sliceIds",
227
+ "_data": [
228
+ {
229
+ "add": ["slice0", "slice1"],
230
+ "remove": [],
231
+ "_hash": "wyYfK5E4ArrMKQ_zvi2-EE"
232
+ }
233
+ ]
234
+ }
203
235
  }
204
236
  ```
205
237
 
206
- Derived `IdSets` can be created by modifying an existing set:
238
+ Derived `SliceIds` can be created by modifying an existing set:
207
239
 
208
240
  ```json
209
241
  {
210
- "base": "IDS0",
211
- "add": ["id3", "id4"],
212
- "remove": ["id0"],
213
- "_hash": "IDS1"
242
+ "slices": {
243
+ "_type": "sliceIds",
244
+ "_data": [
245
+ {
246
+ "add": ["slice0", "slice1"],
247
+ "remove": [],
248
+ "_hash": "wyYfK5E4ArrMKQ_zvi2-EE"
249
+ },
250
+ {
251
+ "base": "wyYfK5E4ArrMKQ_zvi2-EE",
252
+ "add": ["slice2"],
253
+ "remove": []
254
+ }
255
+ ]
256
+ }
214
257
  }
215
258
  ```
216
259
 
217
- ### Collection
260
+ ### Layer
218
261
 
219
- A `Collection` consists of an `IdSet` and a mapping that links item IDs to their
220
- properties:
262
+ Cake layers assign ingredients to slices.
221
263
 
222
264
  ```json
223
265
  {
224
- "idSets": "personIds",
225
- "idSet": "IDS0",
226
- "properties": "addresses",
227
- "assign": {
228
- "id0": "P0HASH",
229
- "id1": "P1HASH"
230
- },
231
- "_hash": "C0HASH"
266
+ "layers": {
267
+ "_type": "layers",
268
+ "_data": [
269
+ {
270
+ "ingredientsTable": "recipes",
271
+ "assign": {
272
+ "slice0": "H8KK9vMjOxxQr_G_9XeDM-",
273
+ "slice1": "H8KK9vMjOxxQr_G_9XeDM-"
274
+ },
275
+ "_hash": "rrFBguLFLhXjrDqAxJx1p-"
276
+ }
277
+ ]
278
+ }
232
279
  }
233
280
  ```
234
281
 
235
282
  ### Cake
236
283
 
237
- Rljson supports `Cake` as a native data structure:
238
-
239
- - A `Cake` consists of layers, each representing a collection of items (slices).
240
- - All layers share the same item IDs (slice structure).
241
- - Each layer assigns different properties to the same items.
284
+ A `Cake` consists of layers of slices.
285
+ All layers share the same slice structure, i.e. the same slice ids.
286
+ Each layer assigns different ingredients to slices.
242
287
 
243
288
  ```json
244
289
  {
245
- "itemIdsTable": "ingredientIds",
246
- "itemIds": "IDS1",
247
- "layersTable": "HASH",
248
- "assign": {
249
- "base": "HASH15",
250
- "cherries": "HASH16",
251
- "creme": "HASH17"
290
+ "cakes": {
291
+ "_type": "cakes",
292
+ "_data": [
293
+ {
294
+ "sliceIdsTable": "slices",
295
+ "idSet": "wyYfK5E4ArrMKQ_zvi2-EE",
296
+ "layersTable": "layers",
297
+ "layers": {
298
+ "flour": "rrFBguLFLhXjrDqAxJx1p-",
299
+ "_hash": "JSoUx1N6lso-18vkzG63Pm"
300
+ },
301
+ "_hash": "bOlQ1lPpZEYB00F14nGvOP"
302
+ }
303
+ ],
304
+ "_hash": "hsL7dD0mFDqmT2i-1fx_1a"
252
305
  }
253
306
  }
254
307
  ```
255
308
 
256
309
  ### Buffet
257
310
 
258
- A `Buffet` is a heterogeneous collection of different but related items, such as
259
- cakes, collections, or properties:
311
+ A `Buffet` is a heterogeneous collection of different but related items,
312
+ such as cakes, layers, or ingredients:
260
313
 
261
314
  ```json
262
315
  {
263
- "items": [
264
- { "table": "drinks", "ref": "HASH20" },
265
- { "table": "cakes", "ref": "HASH21" }
266
- ]
316
+ "buffets": {
317
+ "_type": "buffets",
318
+ "_data": [
319
+ {
320
+ "items": [
321
+ {
322
+ "table": "cakes",
323
+ "ref": "bOlQ1lPpZEYB00F14nGvOP",
324
+ "_hash": "ma47UGAZbu5Ql5yXWFHLAT"
325
+ }
326
+ ],
327
+ "_hash": "jPv5bXjs3XVOLRbQvoWcjw"
328
+ }
329
+ ],
330
+ "_hash": "FYK9ItHMDCe2CnD_TGRs8_"
331
+ }
267
332
  }
268
333
  ```
@@ -1,3 +1,11 @@
1
+ <!--
2
+ @license
3
+ Copyright (c) 2025 Rljson
4
+
5
+ Use of this source code is governed by terms that can be
6
+ found in the LICENSE file in the root of this package.
7
+ -->
8
+
1
9
  # Rljson Architecture
2
10
 
3
11
  This document describes the architecture of the Rljson format.
@@ -21,9 +29,9 @@ This document describes the architecture of the Rljson format.
21
29
  - [Hashes](#hashes)
22
30
  - [Linking Tables Using References](#linking-tables-using-references)
23
31
  - [Data Types](#data-types)
24
- - [Properties](#properties)
25
- - [IdSet](#idset)
26
- - [Collection](#collection)
32
+ - [Ingredients](#ingredients)
33
+ - [SliceIds](#sliceids)
34
+ - [Layer](#layer)
27
35
  - [Cake](#cake)
28
36
  - [Buffet](#buffet)
29
37
 
@@ -91,7 +99,7 @@ containing the table rows and a `_type` property describing the table type:
91
99
  ```json
92
100
  {
93
101
  "table0": {
94
- "_type": "properties",
102
+ "_type": "ingredients",
95
103
  "_data": []
96
104
  }
97
105
  }
@@ -129,7 +137,7 @@ Rljson uses hashes to identify and reference data. Using the `hash-in-place`
129
137
  const jsonWithHashes = hip({
130
138
  a: {
131
139
  _data: [{ a: 10 }],
132
- _type: 'properties',
140
+ _type: 'ingredients',
133
141
  },
134
142
  });
135
143
  ```
@@ -147,7 +155,7 @@ This results in:
147
155
  }
148
156
  ],
149
157
  "_hash": "FfCIOVQsrK1g5o5_G-AxP4",
150
- "_type": "properties"
158
+ "_type": "ingredients"
151
159
  }
152
160
  }
153
161
  ```
@@ -161,7 +169,7 @@ table `b` references table `a` using `aRef`:
161
169
  {
162
170
  "b": {
163
171
  "_data": [{ "aRef": "LeFJOCQVgToOfbUuKJQ-GO" }],
164
- "_type": "properties"
172
+ "_type": "ingredients"
165
173
  }
166
174
  }
167
175
  ```
@@ -173,96 +181,153 @@ This reference structure enables automated denormalization of JSON data.
173
181
  Rljson provides several core data structures and table types to manage and
174
182
  synchronize large datasets.
175
183
 
176
- ### Properties
184
+ ### Ingredients
177
185
 
178
- `Properties` are the fundamental data concept. A `PropertiesTable` contains
179
- key-value pairs representing property assignments:
186
+ `Ingredients` are the fundamental data concept. An `IngredientsTable` contains
187
+ key-value pairs assigning values to ingredient names.
180
188
 
181
189
  ```json
182
190
  {
183
- "sizes": {
184
- "_type": "properties",
191
+ "ingredients": {
192
+ "_type": "ingredients",
193
+ "_data": [
194
+ {
195
+ "name": "flour",
196
+ "amountUnit": "g",
197
+ "nutritionalValuesRef": "gZXFSlrl5QAs5hOVsq5sWB"
198
+ }
199
+ ]
200
+ },
201
+
202
+ "nutritionalValues": {
203
+ "_type": "ingredients",
185
204
  "_data": [
186
- { "w": 10, "h": 20 },
187
- { "w": 30, "h": 40 }
205
+ {
206
+ "energy": 364,
207
+ "fat": 0.98,
208
+ "protein": 10.33,
209
+ "carbohydrates": 76.31,
210
+ "_hash": "gZXFSlrl5QAs5hOVsq5sWB"
211
+ }
188
212
  ]
189
213
  }
190
214
  }
191
215
  ```
192
216
 
193
- ### IdSet
217
+ ### SliceIds
194
218
 
195
- For efficient management of large collections, item IDs are separated from their
196
- properties. This allows fetching IDs first and retrieving details later. The
197
- following `IdSet` defines a set of three IDs:
219
+ For efficient management of large layers, slice IDs are separated from their
220
+ ingredients. This allows fetching IDs first and retrieving details later. The
221
+ following `SliceIds` define a set of three slice IDs:
198
222
 
199
223
  ```json
200
224
  {
201
- "add": ["id0", "id1", "id2"],
202
- "_hash": "IDS0"
225
+ "slices": {
226
+ "_type": "sliceIds",
227
+ "_data": [
228
+ {
229
+ "add": ["slice0", "slice1"],
230
+ "remove": [],
231
+ "_hash": "wyYfK5E4ArrMKQ_zvi2-EE"
232
+ }
233
+ ]
234
+ }
203
235
  }
204
236
  ```
205
237
 
206
- Derived `IdSets` can be created by modifying an existing set:
238
+ Derived `SliceIds` can be created by modifying an existing set:
207
239
 
208
240
  ```json
209
241
  {
210
- "base": "IDS0",
211
- "add": ["id3", "id4"],
212
- "remove": ["id0"],
213
- "_hash": "IDS1"
242
+ "slices": {
243
+ "_type": "sliceIds",
244
+ "_data": [
245
+ {
246
+ "add": ["slice0", "slice1"],
247
+ "remove": [],
248
+ "_hash": "wyYfK5E4ArrMKQ_zvi2-EE"
249
+ },
250
+ {
251
+ "base": "wyYfK5E4ArrMKQ_zvi2-EE",
252
+ "add": ["slice2"],
253
+ "remove": []
254
+ }
255
+ ]
256
+ }
214
257
  }
215
258
  ```
216
259
 
217
- ### Collection
260
+ ### Layer
218
261
 
219
- A `Collection` consists of an `IdSet` and a mapping that links item IDs to their
220
- properties:
262
+ Cake layers assign ingredients to slices.
221
263
 
222
264
  ```json
223
265
  {
224
- "idSets": "personIds",
225
- "idSet": "IDS0",
226
- "properties": "addresses",
227
- "assign": {
228
- "id0": "P0HASH",
229
- "id1": "P1HASH"
230
- },
231
- "_hash": "C0HASH"
266
+ "layers": {
267
+ "_type": "layers",
268
+ "_data": [
269
+ {
270
+ "ingredientsTable": "recipes",
271
+ "assign": {
272
+ "slice0": "H8KK9vMjOxxQr_G_9XeDM-",
273
+ "slice1": "H8KK9vMjOxxQr_G_9XeDM-"
274
+ },
275
+ "_hash": "rrFBguLFLhXjrDqAxJx1p-"
276
+ }
277
+ ]
278
+ }
232
279
  }
233
280
  ```
234
281
 
235
282
  ### Cake
236
283
 
237
- Rljson supports `Cake` as a native data structure:
238
-
239
- - A `Cake` consists of layers, each representing a collection of items (slices).
240
- - All layers share the same item IDs (slice structure).
241
- - Each layer assigns different properties to the same items.
284
+ A `Cake` consists of layers of slices.
285
+ All layers share the same slice structure, i.e. the same slice ids.
286
+ Each layer assigns different ingredients to slices.
242
287
 
243
288
  ```json
244
289
  {
245
- "itemIdsTable": "ingredientIds",
246
- "itemIds": "IDS1",
247
- "layersTable": "HASH",
248
- "assign": {
249
- "base": "HASH15",
250
- "cherries": "HASH16",
251
- "creme": "HASH17"
290
+ "cakes": {
291
+ "_type": "cakes",
292
+ "_data": [
293
+ {
294
+ "sliceIdsTable": "slices",
295
+ "idSet": "wyYfK5E4ArrMKQ_zvi2-EE",
296
+ "layersTable": "layers",
297
+ "layers": {
298
+ "flour": "rrFBguLFLhXjrDqAxJx1p-",
299
+ "_hash": "JSoUx1N6lso-18vkzG63Pm"
300
+ },
301
+ "_hash": "bOlQ1lPpZEYB00F14nGvOP"
302
+ }
303
+ ],
304
+ "_hash": "hsL7dD0mFDqmT2i-1fx_1a"
252
305
  }
253
306
  }
254
307
  ```
255
308
 
256
309
  ### Buffet
257
310
 
258
- A `Buffet` is a heterogeneous collection of different but related items, such as
259
- cakes, collections, or properties:
311
+ A `Buffet` is a heterogeneous collection of different but related items,
312
+ such as cakes, layers, or ingredients:
260
313
 
261
314
  ```json
262
315
  {
263
- "items": [
264
- { "table": "drinks", "ref": "HASH20" },
265
- { "table": "cakes", "ref": "HASH21" }
266
- ]
316
+ "buffets": {
317
+ "_type": "buffets",
318
+ "_data": [
319
+ {
320
+ "items": [
321
+ {
322
+ "table": "cakes",
323
+ "ref": "bOlQ1lPpZEYB00F14nGvOP",
324
+ "_hash": "ma47UGAZbu5Ql5yXWFHLAT"
325
+ }
326
+ ],
327
+ "_hash": "jPv5bXjs3XVOLRbQvoWcjw"
328
+ }
329
+ ],
330
+ "_hash": "FYK9ItHMDCe2CnD_TGRs8_"
331
+ }
267
332
  }
268
333
  ```
@@ -1,25 +1,25 @@
1
1
  import { Json } from '@rljson/json';
2
2
  import { RljsonTable } from '../rljson.ts';
3
- import { ItemId, Ref, TableKey } from '../typedefs.ts';
3
+ import { Ref, TableKey } from '../typedefs.ts';
4
4
  /**
5
5
  * A buffet id is a name or id of a buffet
6
6
  */
7
- export type BuffetId = ItemId;
7
+ export type BuffetId = string;
8
8
  /**
9
9
  * A buffet is a collection of arbitrary but related items, e.g. cakes,
10
- * collections, or items.
10
+ * layers, or slices.
11
11
  */
12
12
  export interface Buffet extends Json {
13
13
  /**
14
- * The items of the buffet
14
+ * The slices of the buffet
15
15
  */
16
16
  items: Array<{
17
17
  /**
18
- * The table the item is taken from
18
+ * The table the slice is taken from
19
19
  */
20
20
  table: TableKey;
21
21
  /**
22
- * The hash of the item in the able
22
+ * The hash of the slice in the able
23
23
  */
24
24
  ref: Ref;
25
25
  }>;
@@ -1,37 +1,38 @@
1
1
  import { Json } from '@rljson/json';
2
2
  import { RljsonTable } from '../rljson.ts';
3
- import { ItemId, TableKey } from '../typedefs.ts';
4
- import { CollectionRef } from './collection.ts';
5
- import { IdSetRef } from './id-set.ts';
3
+ import { TableKey } from '../typedefs.ts';
4
+ import { LayerRef } from './layer.ts';
5
+ import { SliceIdsRef } from './slice-ids.ts';
6
6
  /**
7
7
  * A `CakeLayerId` assigns an id or name to a cake layer
8
8
  */
9
- export type CakeLayerId = ItemId;
9
+ export type CakeLayerId = string;
10
10
  /**
11
11
  * A cake is a collection of layers.
12
12
  *
13
- * A layer is a collection of items.
14
- * All layers of a cake refer to the same items.
13
+ * A layer is a collection of slices.
14
+ * All layers of a cake refer to the same slices.
15
15
  */
16
16
  export interface Cake extends Json {
17
17
  /**
18
- * The item ids of the collection. If present, the item ids in the layers
19
- * must match these ids. The item id sets can be found in the idSets table.
18
+ * The slice ids of the layer. If present, the slice ids of the cake
19
+ * must match these slice ids of the layers.
20
+ * The slice ids can be found in the idSet table.
20
21
  */
21
- idSet?: IdSetRef;
22
+ idSet?: SliceIdsRef;
22
23
  /**
23
- * The table containing the item ids of the collection
24
+ * The table containing the slice ids of the layer
24
25
  */
25
- idSetsTable?: TableKey;
26
+ sliceIdsTable?: TableKey;
26
27
  /**
27
- * The table containing the item collections defining the layers
28
+ * The table containing the slice layers defining the layers
28
29
  */
29
- collectionsTable: TableKey;
30
+ layersTable: TableKey;
30
31
  /**
31
- * Assigns a collection to each layer of the cake.
32
+ * Assigns a layer to each layer of the cake.
32
33
  */
33
34
  layers: {
34
- [layerId: CakeLayerId]: CollectionRef;
35
+ [layerId: CakeLayerId]: LayerRef;
35
36
  };
36
37
  }
37
38
  /**
@@ -39,6 +40,6 @@ export interface Cake extends Json {
39
40
  */
40
41
  export type CakesTable = RljsonTable<Cake, 'cakes'>;
41
42
  /**
42
- * Provides an example collectionsTable for test purposes
43
+ * Provides an example cakes table for test purposes
43
44
  */
44
45
  export declare const exampleCakesTable: () => CakesTable;
@@ -0,0 +1,16 @@
1
+ import { Json } from '@rljson/json';
2
+ import { NutritionalValues } from '../example/bakery-example.ts';
3
+ import { RljsonTable } from '../rljson.ts';
4
+ import { Ref } from '../typedefs.ts';
5
+ /**
6
+ * A reference to a ingredients row in a ingredients table
7
+ */
8
+ export type IngredientsRef = Ref;
9
+ /**
10
+ * A table containing ingredients
11
+ */
12
+ export type IngredientsTable<T extends Json> = RljsonTable<T, 'ingredients'>;
13
+ /**
14
+ * Provides an example ingredients table for test purposes
15
+ */
16
+ export declare const exampleIngredientsTable: () => IngredientsTable<NutritionalValues>;
@@ -0,0 +1,44 @@
1
+ import { Json } from '@rljson/json';
2
+ import { RljsonTable } from '../rljson.ts';
3
+ import { Ref, SliceId, TableKey } from '../typedefs.ts';
4
+ import { IngredientsRef } from './ingredients.ts';
5
+ import { SliceIdsRef } from './slice-ids.ts';
6
+ /**
7
+ * A LayerRef is a hash pointing to a layer
8
+ */
9
+ export type LayerRef = Ref;
10
+ /**
11
+ * A layer assigns ingredients to item ids
12
+ */
13
+ export interface Layer extends Json {
14
+ /**
15
+ * `base` an optional base layer that is extended by this layer
16
+ */
17
+ base?: LayerRef;
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.
21
+ */
22
+ idSet?: SliceIdsRef;
23
+ /**
24
+ * The table containing the item ids of the layer
25
+ */
26
+ sliceIdsTable?: TableKey;
27
+ /**
28
+ * The table containing the ingredients that are assigned to the items
29
+ * with the assign property below
30
+ */
31
+ ingredientsTable: TableKey;
32
+ /**
33
+ * Assign ingredients to each item of the layer.
34
+ */
35
+ assign: Record<SliceId, IngredientsRef>;
36
+ }
37
+ /**
38
+ * A table containing layers
39
+ */
40
+ export type LayersTable = RljsonTable<Layer, 'layers'>;
41
+ /**
42
+ * Provides an example layersTable for test purposes
43
+ */
44
+ export declare const exampleLayersTable: () => LayersTable;