@rljson/rljson 0.0.82 → 0.0.83
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/dist/content/slice-ids.d.ts +23 -8
- package/dist/index.d.ts +1 -0
- package/dist/rljson.js +41 -3
- package/dist/rljson_version.d.ts +1 -1
- package/dist/tools/resolve-slice-ids.d.ts +22 -0
- package/dist/typedefs.d.ts +1 -1
- package/package.json +10 -8
|
@@ -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/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
|
*/
|
|
@@ -2052,6 +2052,44 @@ var rowOf = (table, hash) => {
|
|
|
2052
2052
|
return row;
|
|
2053
2053
|
};
|
|
2054
2054
|
//#endregion
|
|
2055
|
+
//#region src/tools/resolve-slice-ids.ts
|
|
2056
|
+
// @license
|
|
2057
|
+
/**
|
|
2058
|
+
* Merges a row of slice ids with the resolved slice ids of its base.
|
|
2059
|
+
*
|
|
2060
|
+
* Starts with the slice ids of the base, adds the slice ids of the row and
|
|
2061
|
+
* drops the removed ones. Each slice id appears once, in the order it was
|
|
2062
|
+
* added first.
|
|
2063
|
+
* @param base - The resolved slice ids of `row.base`, or [] without a base
|
|
2064
|
+
* @param row - The row of slice ids
|
|
2065
|
+
* @returns The slice ids of the row
|
|
2066
|
+
*/
|
|
2067
|
+
var mergeSliceIds = (base, row) => {
|
|
2068
|
+
const result = /* @__PURE__ */ new Set([...base, ...row.add]);
|
|
2069
|
+
for (const sliceId of row.remove ?? []) result.delete(sliceId);
|
|
2070
|
+
return Array.from(result);
|
|
2071
|
+
};
|
|
2072
|
+
/**
|
|
2073
|
+
* Resolves a row of slice ids: follows its `base` chain within the table
|
|
2074
|
+
* and merges each row with its base.
|
|
2075
|
+
* @param table - The table that holds the row and its bases
|
|
2076
|
+
* @param row - The row of slice ids, e.g. a derived catalog
|
|
2077
|
+
* @returns The slice ids of the row
|
|
2078
|
+
* @throws Error if a base is not in the table, or if the bases form a cycle
|
|
2079
|
+
*/
|
|
2080
|
+
var resolveSliceIds = (table, row) => {
|
|
2081
|
+
const chain = [row];
|
|
2082
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2083
|
+
let current = row;
|
|
2084
|
+
while (current.base) {
|
|
2085
|
+
if (visited.has(current.base)) throw new Error(`resolveSliceIds: The bases of the row form a cycle at "${current.base}".`);
|
|
2086
|
+
visited.add(current.base);
|
|
2087
|
+
current = rowOf(table, current.base);
|
|
2088
|
+
chain.push(current);
|
|
2089
|
+
}
|
|
2090
|
+
return chain.reduceRight(mergeSliceIds, []);
|
|
2091
|
+
};
|
|
2092
|
+
//#endregion
|
|
2055
2093
|
//#region src/tools/remove-duplicates.ts
|
|
2056
2094
|
// @license
|
|
2057
2095
|
var removeDuplicates = (rljson) => {
|
|
@@ -2842,4 +2880,4 @@ var Validate = class {
|
|
|
2842
2880
|
//#region src/index.ts
|
|
2843
2881
|
// @license
|
|
2844
2882
|
//#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 };
|
|
2883
|
+
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.83";
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rljson/rljson",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.83",
|
|
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
|
+
}
|