@rljson/rljson 0.0.82 → 0.0.84
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.architecture.md +2 -1
- package/dist/README.architecture.md +2 -1
- package/dist/content/slice-ids.d.ts +23 -8
- package/dist/example.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/rljson.js +93 -3
- package/dist/rljson_version.d.ts +1 -1
- package/dist/src/example.ts +26 -1
- package/dist/tools/resolve-slice-ids.d.ts +22 -0
- package/dist/typedefs.d.ts +1 -1
- package/dist/validate/base-validator.d.ts +1 -0
- package/package.json +10 -8
package/README.architecture.md
CHANGED
|
@@ -504,7 +504,8 @@ objects:
|
|
|
504
504
|
- **References**: All `*Ref` columns must point to existing rows
|
|
505
505
|
- **Trees**: No cycles, all child hashes must resolve, correct node types
|
|
506
506
|
- **Layers**: Component and SliceId tables must exist
|
|
507
|
-
- **Cakes**: Layer tables must exist and
|
|
507
|
+
- **Cakes**: Layer tables and layers must exist, and every layer must use the
|
|
508
|
+
slice ids table and row of its cake
|
|
508
509
|
- **Buffets**: Referenced items must exist in their declared tables
|
|
509
510
|
|
|
510
511
|
The `BaseValidator` provides an extensible validator framework — multiple
|
|
@@ -504,7 +504,8 @@ objects:
|
|
|
504
504
|
- **References**: All `*Ref` columns must point to existing rows
|
|
505
505
|
- **Trees**: No cycles, all child hashes must resolve, correct node types
|
|
506
506
|
- **Layers**: Component and SliceId tables must exist
|
|
507
|
-
- **Cakes**: Layer tables must exist and
|
|
507
|
+
- **Cakes**: Layer tables and layers must exist, and every layer must use the
|
|
508
|
+
slice ids table and row of its cake
|
|
508
509
|
- **Buffets**: Referenced items must exist in their declared tables
|
|
509
510
|
|
|
510
511
|
The `BaseValidator` provides an extensible validator framework — multiple
|
|
@@ -3,36 +3,51 @@ import { RljsonTable } from '../rljson.ts';
|
|
|
3
3
|
import { Ref, SliceId } from '../typedefs.ts';
|
|
4
4
|
import { TableCfg } from './table-cfg.ts';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* A reference to a row of type `SliceIds`: the hash of that row
|
|
7
7
|
*/
|
|
8
8
|
export type SliceIdsRef = Ref;
|
|
9
9
|
/**
|
|
10
|
-
* A
|
|
10
|
+
* A set of slice ids, e.g. the cars of a catalog.
|
|
11
|
+
*
|
|
12
|
+
* A row can extend a base row. Its slice ids are then the slice ids of the
|
|
13
|
+
* base, plus `add`, minus `remove`. So a derived row stores only the
|
|
14
|
+
* difference.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const cars2025 = hip<SliceIds>({ add: ['taycan', 'macan', 'ex30'] });
|
|
18
|
+
*
|
|
19
|
+
* // The cars of 2026: taycan, ex30, ex90
|
|
20
|
+
* const cars2026 = hip<SliceIds>({
|
|
21
|
+
* base: ref(cars2025),
|
|
22
|
+
* add: ['ex90'],
|
|
23
|
+
* remove: ['macan'],
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
11
26
|
*/
|
|
12
27
|
export interface SliceIds extends Json {
|
|
13
28
|
/**
|
|
14
|
-
*
|
|
29
|
+
* Optional: the reference to the row of slice ids that this row extends
|
|
15
30
|
*/
|
|
16
31
|
base?: SliceIdsRef;
|
|
17
32
|
/**
|
|
18
|
-
* The slice ids added to base
|
|
33
|
+
* The slice ids added to the base
|
|
19
34
|
*/
|
|
20
35
|
add: SliceId[];
|
|
21
36
|
/**
|
|
22
|
-
*
|
|
37
|
+
* Optional: the slice ids removed from the base
|
|
23
38
|
*/
|
|
24
39
|
remove?: SliceId[];
|
|
25
40
|
}
|
|
26
41
|
/**
|
|
27
|
-
* A table
|
|
42
|
+
* A table of type `sliceIds` whose rows are sets of slice ids
|
|
28
43
|
*/
|
|
29
44
|
export type SliceIdsTable = RljsonTable<SliceIds, 'sliceIds'>;
|
|
30
45
|
/**
|
|
31
|
-
* Returns
|
|
46
|
+
* Returns the slice ids table of the bakery example
|
|
32
47
|
*/
|
|
33
48
|
export declare const exampleSliceIdsTable: () => SliceIdsTable;
|
|
34
49
|
/**
|
|
35
|
-
* Creates
|
|
50
|
+
* Creates the table configuration of a slice ids table
|
|
36
51
|
* @param tableKey - the table key
|
|
37
52
|
* @returns the table configuration
|
|
38
53
|
*/
|
package/dist/example.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export * from './sync/gap-fill.ts';
|
|
|
24
24
|
export * from './sync/sync-config.ts';
|
|
25
25
|
export * from './sync/sync-events.ts';
|
|
26
26
|
export * from './tools/ref.ts';
|
|
27
|
+
export * from './tools/resolve-slice-ids.ts';
|
|
27
28
|
export * from './tools/remove-duplicates.ts';
|
|
28
29
|
export * from './tools/time-id.ts';
|
|
29
30
|
export * from './typedefs.ts';
|
package/dist/rljson.js
CHANGED
|
@@ -572,11 +572,11 @@ var exampleRevision = () => ({
|
|
|
572
572
|
//#region src/content/slice-ids.ts
|
|
573
573
|
// @license
|
|
574
574
|
/**
|
|
575
|
-
* Returns
|
|
575
|
+
* Returns the slice ids table of the bakery example
|
|
576
576
|
*/
|
|
577
577
|
var exampleSliceIdsTable = () => bakeryExample().slices;
|
|
578
578
|
/**
|
|
579
|
-
* Creates
|
|
579
|
+
* Creates the table configuration of a slice ids table
|
|
580
580
|
* @param tableKey - the table key
|
|
581
581
|
* @returns the table configuration
|
|
582
582
|
*/
|
|
@@ -1435,6 +1435,30 @@ var Example = class Example {
|
|
|
1435
1435
|
throwOnWrongHashes: false
|
|
1436
1436
|
});
|
|
1437
1437
|
return result;
|
|
1438
|
+
},
|
|
1439
|
+
layerWithOtherSliceIds: () => {
|
|
1440
|
+
const result = Example.ok.complete();
|
|
1441
|
+
result.sliceIds._data.push({ add: [
|
|
1442
|
+
"id0",
|
|
1443
|
+
"id1",
|
|
1444
|
+
"id2"
|
|
1445
|
+
] });
|
|
1446
|
+
hip(result.sliceIds, {
|
|
1447
|
+
updateExistingHashes: true,
|
|
1448
|
+
throwOnWrongHashes: false
|
|
1449
|
+
});
|
|
1450
|
+
const cake = result.cakes._data[0];
|
|
1451
|
+
cake.sliceIdsRow = result.sliceIds._data[1]._hash;
|
|
1452
|
+
hip(result.cakes, {
|
|
1453
|
+
updateExistingHashes: true,
|
|
1454
|
+
throwOnWrongHashes: false
|
|
1455
|
+
});
|
|
1456
|
+
result.buffets._data[0].items[0].ref = cake._hash;
|
|
1457
|
+
hip(result.buffets, {
|
|
1458
|
+
updateExistingHashes: true,
|
|
1459
|
+
throwOnWrongHashes: false
|
|
1460
|
+
});
|
|
1461
|
+
return result;
|
|
1438
1462
|
}
|
|
1439
1463
|
},
|
|
1440
1464
|
buffets: {
|
|
@@ -2052,6 +2076,44 @@ var rowOf = (table, hash) => {
|
|
|
2052
2076
|
return row;
|
|
2053
2077
|
};
|
|
2054
2078
|
//#endregion
|
|
2079
|
+
//#region src/tools/resolve-slice-ids.ts
|
|
2080
|
+
// @license
|
|
2081
|
+
/**
|
|
2082
|
+
* Merges a row of slice ids with the resolved slice ids of its base.
|
|
2083
|
+
*
|
|
2084
|
+
* Starts with the slice ids of the base, adds the slice ids of the row and
|
|
2085
|
+
* drops the removed ones. Each slice id appears once, in the order it was
|
|
2086
|
+
* added first.
|
|
2087
|
+
* @param base - The resolved slice ids of `row.base`, or [] without a base
|
|
2088
|
+
* @param row - The row of slice ids
|
|
2089
|
+
* @returns The slice ids of the row
|
|
2090
|
+
*/
|
|
2091
|
+
var mergeSliceIds = (base, row) => {
|
|
2092
|
+
const result = /* @__PURE__ */ new Set([...base, ...row.add]);
|
|
2093
|
+
for (const sliceId of row.remove ?? []) result.delete(sliceId);
|
|
2094
|
+
return Array.from(result);
|
|
2095
|
+
};
|
|
2096
|
+
/**
|
|
2097
|
+
* Resolves a row of slice ids: follows its `base` chain within the table
|
|
2098
|
+
* and merges each row with its base.
|
|
2099
|
+
* @param table - The table that holds the row and its bases
|
|
2100
|
+
* @param row - The row of slice ids, e.g. a derived catalog
|
|
2101
|
+
* @returns The slice ids of the row
|
|
2102
|
+
* @throws Error if a base is not in the table, or if the bases form a cycle
|
|
2103
|
+
*/
|
|
2104
|
+
var resolveSliceIds = (table, row) => {
|
|
2105
|
+
const chain = [row];
|
|
2106
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2107
|
+
let current = row;
|
|
2108
|
+
while (current.base) {
|
|
2109
|
+
if (visited.has(current.base)) throw new Error(`resolveSliceIds: The bases of the row form a cycle at "${current.base}".`);
|
|
2110
|
+
visited.add(current.base);
|
|
2111
|
+
current = rowOf(table, current.base);
|
|
2112
|
+
chain.push(current);
|
|
2113
|
+
}
|
|
2114
|
+
return chain.reduceRight(mergeSliceIds, []);
|
|
2115
|
+
};
|
|
2116
|
+
//#endregion
|
|
2055
2117
|
//#region src/tools/remove-duplicates.ts
|
|
2056
2118
|
// @license
|
|
2057
2119
|
var removeDuplicates = (rljson) => {
|
|
@@ -2235,6 +2297,7 @@ var _BaseValidator = class {
|
|
|
2235
2297
|
() => this._cakeSliceIdsTableNotFound(),
|
|
2236
2298
|
() => this._cakeSliceIdsNotFound(),
|
|
2237
2299
|
() => this._cakeLayerTablesNotFound(),
|
|
2300
|
+
() => this._cakeLayerSliceIdsDoNotMatch(),
|
|
2238
2301
|
() => this._buffetReferencedTableNotFound()
|
|
2239
2302
|
];
|
|
2240
2303
|
for (const step of steps) {
|
|
@@ -2770,6 +2833,33 @@ var _BaseValidator = class {
|
|
|
2770
2833
|
brokenCakes: missingCakeLayers
|
|
2771
2834
|
};
|
|
2772
2835
|
}
|
|
2836
|
+
_cakeLayerSliceIdsDoNotMatch() {
|
|
2837
|
+
const brokenCakes = [];
|
|
2838
|
+
iterateTablesSync(this.rljson, (tableKey, table) => {
|
|
2839
|
+
if (table._type !== "cakes") return;
|
|
2840
|
+
const cakesTable = table;
|
|
2841
|
+
for (const cake of cakesTable._data) for (const layersTableKey in cake.layers) {
|
|
2842
|
+
if (layersTableKey.startsWith("_")) continue;
|
|
2843
|
+
const layersTable = this.rljsonIndexed[layersTableKey];
|
|
2844
|
+
const layerRef = cake.layers[layersTableKey];
|
|
2845
|
+
const layer = layersTable._data[layerRef];
|
|
2846
|
+
if (layer.sliceIdsTable !== cake.sliceIdsTable || layer.sliceIdsTableRow !== cake.sliceIdsRow) brokenCakes.push({
|
|
2847
|
+
cakeTable: tableKey,
|
|
2848
|
+
brokenCake: cake._hash,
|
|
2849
|
+
layersTable: layersTableKey,
|
|
2850
|
+
brokenLayer: layerRef,
|
|
2851
|
+
cakeSliceIdsTable: cake.sliceIdsTable,
|
|
2852
|
+
cakeSliceIdsRow: cake.sliceIdsRow,
|
|
2853
|
+
layerSliceIdsTable: layer.sliceIdsTable,
|
|
2854
|
+
layerSliceIdsRow: layer.sliceIdsTableRow
|
|
2855
|
+
});
|
|
2856
|
+
}
|
|
2857
|
+
});
|
|
2858
|
+
if (brokenCakes.length > 0) this.errors.cakeLayerSliceIdsDoNotMatch = {
|
|
2859
|
+
error: "Layers of cakes do not use the slice ids of the cake",
|
|
2860
|
+
brokenCakes
|
|
2861
|
+
};
|
|
2862
|
+
}
|
|
2773
2863
|
_buffetReferencedTableNotFound() {
|
|
2774
2864
|
const missingTables = [];
|
|
2775
2865
|
const missingItems = [];
|
|
@@ -2842,4 +2932,4 @@ var Validate = class {
|
|
|
2842
2932
|
//#region src/index.ts
|
|
2843
2933
|
// @license
|
|
2844
2934
|
//#endregion
|
|
2845
|
-
export { BaseValidator, Example, InsertValidator, Route, Validate, ackPayloadExample, ackPayloadPartialExample, addColumnsToTableCfg, bakeryExample, clientId, clientIdExample, connectorPayloadExample, connectorPayloadFullExample, contentTypes, createCakeTableCfg, createEditHistoryTableCfg, createEditTableCfg, createInsertHistoryTableCfg, createLayerTableCfg, createMultiEditTableCfg, createSliceIdsTableCfg, createTreesTableCfg, exampleBuffetsTable, exampleCakesTable, exampleComponentsTable, exampleInsert, exampleInsertHistoryTable, exampleLayersTable, exampleRevision, exampleRljson, exampleSliceIdsTable, exampleTableCfg, exampleTableCfgTable, exampleTreesTable, exampleTypedefs, gapFillRequestExample, gapFillResponseExample, getTimeIdTimestamp, getTimeIdUniquePart, isClientId, isTimeId, isValidFieldName, iterateTables, iterateTablesSync, ref, removeDuplicates, reservedFieldNames, reservedTableKeys, routeRefSeperator, routeSliceIdIndicators, routeSliceIdSeperator, rowOf, syncConfigCausalOnlyExample, syncConfigDefault, syncConfigFullExample, syncEvents, throwOnInvalidTableCfg, timeId, treeFromObject, validateInsert, validateRljsonAgainstTableCfg };
|
|
2935
|
+
export { BaseValidator, Example, InsertValidator, Route, Validate, ackPayloadExample, ackPayloadPartialExample, addColumnsToTableCfg, bakeryExample, clientId, clientIdExample, connectorPayloadExample, connectorPayloadFullExample, contentTypes, createCakeTableCfg, createEditHistoryTableCfg, createEditTableCfg, createInsertHistoryTableCfg, createLayerTableCfg, createMultiEditTableCfg, createSliceIdsTableCfg, createTreesTableCfg, exampleBuffetsTable, exampleCakesTable, exampleComponentsTable, exampleInsert, exampleInsertHistoryTable, exampleLayersTable, exampleRevision, exampleRljson, exampleSliceIdsTable, exampleTableCfg, exampleTableCfgTable, exampleTreesTable, exampleTypedefs, gapFillRequestExample, gapFillResponseExample, getTimeIdTimestamp, getTimeIdUniquePart, isClientId, isTimeId, isValidFieldName, iterateTables, iterateTablesSync, mergeSliceIds, ref, removeDuplicates, reservedFieldNames, reservedTableKeys, resolveSliceIds, routeRefSeperator, routeSliceIdIndicators, routeSliceIdSeperator, rowOf, syncConfigCausalOnlyExample, syncConfigDefault, syncConfigFullExample, syncEvents, throwOnInvalidTableCfg, timeId, treeFromObject, validateInsert, validateRljsonAgainstTableCfg };
|
package/dist/rljson_version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The version of the `@rljson/rljson` package. */
|
|
2
|
-
export declare const rljsonVersion = "0.0.
|
|
2
|
+
export declare const rljsonVersion = "0.0.84";
|
package/dist/src/example.ts
CHANGED
|
@@ -17,7 +17,6 @@ import { exampleTreesTable, TreesTable } from './content/tree.ts';
|
|
|
17
17
|
import { bakeryExample } from './example/bakery-example.ts';
|
|
18
18
|
import { Rljson } from './rljson.ts';
|
|
19
19
|
|
|
20
|
-
|
|
21
20
|
export class Example {
|
|
22
21
|
static readonly ok = {
|
|
23
22
|
bakery: (): Rljson => bakeryExample(),
|
|
@@ -890,6 +889,32 @@ export class Example {
|
|
|
890
889
|
});
|
|
891
890
|
return result;
|
|
892
891
|
},
|
|
892
|
+
|
|
893
|
+
layerWithOtherSliceIds: (): Rljson => {
|
|
894
|
+
const result = Example.ok.complete();
|
|
895
|
+
|
|
896
|
+
// Let the cake use another row of slice ids than its layers
|
|
897
|
+
result.sliceIds._data.push({ add: ['id0', 'id1', 'id2'] });
|
|
898
|
+
hip(result.sliceIds, {
|
|
899
|
+
updateExistingHashes: true,
|
|
900
|
+
throwOnWrongHashes: false,
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
const cake = result.cakes._data[0];
|
|
904
|
+
cake.sliceIdsRow = result.sliceIds._data[1]._hash;
|
|
905
|
+
hip(result.cakes, {
|
|
906
|
+
updateExistingHashes: true,
|
|
907
|
+
throwOnWrongHashes: false,
|
|
908
|
+
});
|
|
909
|
+
|
|
910
|
+
// Let the buffet refer to the changed cake
|
|
911
|
+
result.buffets._data[0].items[0].ref = cake._hash;
|
|
912
|
+
hip(result.buffets, {
|
|
913
|
+
updateExistingHashes: true,
|
|
914
|
+
throwOnWrongHashes: false,
|
|
915
|
+
});
|
|
916
|
+
return result;
|
|
917
|
+
},
|
|
893
918
|
},
|
|
894
919
|
|
|
895
920
|
buffets: {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SliceIds, SliceIdsTable } from '../content/slice-ids.ts';
|
|
2
|
+
import { SliceId } from '../typedefs.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Merges a row of slice ids with the resolved slice ids of its base.
|
|
5
|
+
*
|
|
6
|
+
* Starts with the slice ids of the base, adds the slice ids of the row and
|
|
7
|
+
* drops the removed ones. Each slice id appears once, in the order it was
|
|
8
|
+
* added first.
|
|
9
|
+
* @param base - The resolved slice ids of `row.base`, or [] without a base
|
|
10
|
+
* @param row - The row of slice ids
|
|
11
|
+
* @returns The slice ids of the row
|
|
12
|
+
*/
|
|
13
|
+
export declare const mergeSliceIds: (base: SliceId[], row: SliceIds) => SliceId[];
|
|
14
|
+
/**
|
|
15
|
+
* Resolves a row of slice ids: follows its `base` chain within the table
|
|
16
|
+
* and merges each row with its base.
|
|
17
|
+
* @param table - The table that holds the row and its bases
|
|
18
|
+
* @param row - The row of slice ids, e.g. a derived catalog
|
|
19
|
+
* @returns The slice ids of the row
|
|
20
|
+
* @throws Error if a base is not in the table, or if the bases form a cycle
|
|
21
|
+
*/
|
|
22
|
+
export declare const resolveSliceIds: (table: SliceIdsTable, row: SliceIds) => SliceId[];
|
package/dist/typedefs.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface Row extends Json {
|
|
|
15
15
|
_hash?: Ref;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* An `id` is a *user defined* name or identifier of
|
|
18
|
+
* An `id` is a *user defined* name or identifier of a slice.
|
|
19
19
|
* It exists in parallel with the auto generated `_hash`.
|
|
20
20
|
*/
|
|
21
21
|
export type SliceId = string;
|
|
@@ -32,6 +32,7 @@ export interface BaseErrors extends Errors {
|
|
|
32
32
|
cakeSliceIdsNotFound?: Json;
|
|
33
33
|
cakeLayerTablesNotFound?: Json;
|
|
34
34
|
cakeLayersNotFound?: Json;
|
|
35
|
+
cakeLayerSliceIdsDoNotMatch?: Json;
|
|
35
36
|
buffetReferencedTablesNotFound?: Json;
|
|
36
37
|
buffetReferencedItemsNotFound?: Json;
|
|
37
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rljson/rljson",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.84",
|
|
4
|
+
"packageManager": "pnpm@11.10.0+sha512.0b7f8b98060031904c017e3a41eb187a16d40eeb829b95c4f8cb03681761fc4ab53dd219115b9b447f4dce1a05a214764461e7d3703392a9f32f9511ce8c86c8",
|
|
4
5
|
"description": "The RLJSON data format specification",
|
|
5
6
|
"homepage": "https://github.com/rljson/rljson",
|
|
6
7
|
"bugs": "https://github.com/rljson/rljson/issues",
|
|
@@ -19,6 +20,13 @@
|
|
|
19
20
|
"dist"
|
|
20
21
|
],
|
|
21
22
|
"type": "module",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "pnpm test && vite build && tsc && cp README* dist && mkdir dist/src && cp src/example.ts dist/src",
|
|
25
|
+
"test": "vitest run --coverage && npm run lint",
|
|
26
|
+
"prepublishOnly": "npm run build",
|
|
27
|
+
"lint": "eslint",
|
|
28
|
+
"updateGoldens": "cross-env UPDATE_GOLDENS=true npm test"
|
|
29
|
+
},
|
|
22
30
|
"devDependencies": {
|
|
23
31
|
"@types/node": "^26.6.3",
|
|
24
32
|
"@typescript-eslint/eslint-plugin": "^8.70.1",
|
|
@@ -44,11 +52,5 @@
|
|
|
44
52
|
"@rljson/hash": "0.0.19",
|
|
45
53
|
"@rljson/json": "0.0.23",
|
|
46
54
|
"nanoid": "^6.0.1"
|
|
47
|
-
},
|
|
48
|
-
"scripts": {
|
|
49
|
-
"build": "pnpm test && vite build && tsc && cp README* dist && mkdir dist/src && cp src/example.ts dist/src",
|
|
50
|
-
"test": "vitest run --coverage && npm run lint",
|
|
51
|
-
"lint": "eslint",
|
|
52
|
-
"updateGoldens": "cross-env UPDATE_GOLDENS=true npm test"
|
|
53
55
|
}
|
|
54
|
-
}
|
|
56
|
+
}
|