@rljson/rljson 0.0.70 → 0.0.72
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/cake.d.ts +10 -1
- package/dist/content/slice-ids.d.ts +7 -0
- package/dist/content/table-cfg.d.ts +1 -0
- package/dist/example/bakery-example.d.ts +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/insertHistory/insertHistory.d.ts +2 -2
- package/dist/rljson.d.ts +3 -2
- package/dist/rljson.js +156 -5
- package/dist/route/route.d.ts +5 -1
- package/package.json +1 -1
package/dist/content/cake.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Json } from '@rljson/json';
|
|
2
2
|
import { RljsonTable } from '../rljson.ts';
|
|
3
|
-
import { TableKey } from '../typedefs.ts';
|
|
3
|
+
import { Ref, SliceId, TableKey } from '../typedefs.ts';
|
|
4
4
|
import { LayerRef } from './layer.ts';
|
|
5
5
|
import { SliceIdsRef } from './slice-ids.ts';
|
|
6
6
|
import { TableCfg } from './table-cfg.ts';
|
|
@@ -8,6 +8,15 @@ import { TableCfg } from './table-cfg.ts';
|
|
|
8
8
|
* A `CakeLayerId` assigns an id or name to a cake layer
|
|
9
9
|
*/
|
|
10
10
|
export type CakeLayerId = string;
|
|
11
|
+
/**
|
|
12
|
+
* A reference to a cake
|
|
13
|
+
*
|
|
14
|
+
* A cake reference can optionally restrict the slice ids that are used in the cake.
|
|
15
|
+
*/
|
|
16
|
+
export interface CakeReference extends Json {
|
|
17
|
+
ref: Ref;
|
|
18
|
+
sliceIds?: SliceId[];
|
|
19
|
+
}
|
|
11
20
|
/**
|
|
12
21
|
* A cake is a collection of layers.
|
|
13
22
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Json } from '@rljson/json';
|
|
2
2
|
import { RljsonTable } from '../rljson.ts';
|
|
3
3
|
import { Ref, SliceId } from '../typedefs.ts';
|
|
4
|
+
import { TableCfg } from './table-cfg.ts';
|
|
4
5
|
/**
|
|
5
6
|
* An SliceIdsRef is a hash pointing to an Ids
|
|
6
7
|
*/
|
|
@@ -30,3 +31,9 @@ export type SliceIdsTable = RljsonTable<SliceIds, 'sliceIds'>;
|
|
|
30
31
|
* Returns one of the layers of the example cake
|
|
31
32
|
*/
|
|
32
33
|
export declare const exampleSliceIdsTable: () => SliceIdsTable;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a table configuration for slice ids table
|
|
36
|
+
* @param tableKey - the table key
|
|
37
|
+
* @returns the table configuration
|
|
38
|
+
*/
|
|
39
|
+
export declare const createSliceIdsTableCfg: (tableKey: string) => TableCfg;
|
|
@@ -4,7 +4,7 @@ import { CakesTable } from '../content/cake.ts';
|
|
|
4
4
|
import { ComponentsTable } from '../content/components.ts';
|
|
5
5
|
import { LayersTable } from '../content/layer.ts';
|
|
6
6
|
import { SliceIdsTable } from '../content/slice-ids.ts';
|
|
7
|
-
import {
|
|
7
|
+
import { InsertHistoryTable } from '../insertHistory/insertHistory.ts';
|
|
8
8
|
import { Rljson } from '../rljson.ts';
|
|
9
9
|
import { Ref } from '../typedefs.ts';
|
|
10
10
|
export interface Ingredient extends Json {
|
|
@@ -32,6 +32,6 @@ export interface Bakery extends Rljson {
|
|
|
32
32
|
recipeIngredients: ComponentsTable<RecipIngredient>;
|
|
33
33
|
ingredients: ComponentsTable<Ingredient>;
|
|
34
34
|
nutritionalValues: ComponentsTable<NutritionalValues>;
|
|
35
|
-
ingredientsInsertHistory:
|
|
35
|
+
ingredientsInsertHistory: InsertHistoryTable<'Ingredients'>;
|
|
36
36
|
}
|
|
37
37
|
export declare const bakeryExample: () => Bakery;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ export * from './content/layer.ts';
|
|
|
5
5
|
export * from './content/revision.ts';
|
|
6
6
|
export * from './content/slice-ids.ts';
|
|
7
7
|
export * from './content/table-cfg.ts';
|
|
8
|
+
export * from './edit/edit-history.ts';
|
|
9
|
+
export * from './edit/edit.ts';
|
|
10
|
+
export * from './edit/multi-edit.ts';
|
|
8
11
|
export * from './example.ts';
|
|
9
12
|
export * from './example/bakery-example.ts';
|
|
10
13
|
export * from './insert/insert-validator.ts';
|
|
@@ -11,7 +11,7 @@ export type InsertHistoryRow<Str extends string> = {
|
|
|
11
11
|
origin?: Ref;
|
|
12
12
|
previous?: InsertHistoryTimeId[];
|
|
13
13
|
};
|
|
14
|
-
export type
|
|
14
|
+
export type InsertHistoryTable<Str extends string> = RljsonTable<InsertHistoryRow<Str>, 'insertHistory'>;
|
|
15
15
|
/**
|
|
16
16
|
* Creates a TableCfg for a InsertHistory table for the given table configuration
|
|
17
17
|
* @param tableCfg - The table configuration to create the InsertHistory table for
|
|
@@ -21,4 +21,4 @@ export declare const createInsertHistoryTableCfg: (tableCfg: TableCfg) => TableC
|
|
|
21
21
|
/**
|
|
22
22
|
* Provides an example insertHistory table for test purposes
|
|
23
23
|
*/
|
|
24
|
-
export declare const exampleInsertHistoryTable: () =>
|
|
24
|
+
export declare const exampleInsertHistoryTable: () => InsertHistoryTable<any>;
|
package/dist/rljson.d.ts
CHANGED
|
@@ -6,16 +6,17 @@ import { LayersTable } from './content/layer.ts';
|
|
|
6
6
|
import { RevisionsTable } from './content/revision.ts';
|
|
7
7
|
import { SliceIdsTable } from './content/slice-ids.ts';
|
|
8
8
|
import { TableCfgRef, TablesCfgTable } from './content/table-cfg.ts';
|
|
9
|
+
import { EditHistoryTable } from './edit/edit-history.ts';
|
|
9
10
|
import { EditsTable } from './edit/edit.ts';
|
|
10
11
|
import { MultiEditsTable } from './edit/multi-edit.ts';
|
|
11
|
-
import {
|
|
12
|
+
import { InsertHistoryTable } from './insertHistory/insertHistory.ts';
|
|
12
13
|
import { ContentType, Ref, TableKey } from './typedefs.ts';
|
|
13
14
|
export declare const reservedFieldNames: string[];
|
|
14
15
|
export declare const reservedTableKeys: string[];
|
|
15
16
|
/**
|
|
16
17
|
* One of the supported Rljson table types
|
|
17
18
|
*/
|
|
18
|
-
export type TableType = BuffetsTable | ComponentsTable<any> | LayersTable | SliceIdsTable | CakesTable | RevisionsTable | TablesCfgTable |
|
|
19
|
+
export type TableType = BuffetsTable | ComponentsTable<any> | LayersTable | SliceIdsTable | CakesTable | RevisionsTable | TablesCfgTable | InsertHistoryTable<any> | EditsTable | MultiEditsTable | EditHistoryTable;
|
|
19
20
|
/** The rljson data format */
|
|
20
21
|
export interface Rljson extends Json {
|
|
21
22
|
[tableId: TableKey]: TableType;
|
package/dist/rljson.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { hip, hsh } from "@rljson/hash";
|
|
2
2
|
import { exampleJsonObject, jsonValueTypes, jsonValueMatchesType, jsonValueType } from "@rljson/json";
|
|
3
3
|
import { nanoid } from "nanoid";
|
|
4
|
+
const routeRefSeperator = "@";
|
|
5
|
+
const routeSliceIdIndicators = ["(", ")"];
|
|
6
|
+
const routeSliceIdSeperator = ",";
|
|
4
7
|
class Route {
|
|
5
8
|
constructor(_segments) {
|
|
6
9
|
this._segments = _segments;
|
|
@@ -16,12 +19,20 @@ class Route {
|
|
|
16
19
|
const segmentsFlat = route.split("/").filter((s) => s.length > 0);
|
|
17
20
|
const segments = [];
|
|
18
21
|
for (const segmentFlat of segmentsFlat) {
|
|
19
|
-
const [
|
|
22
|
+
const [tableKeyAndSliceId, refFlat] = segmentFlat.split(routeRefSeperator);
|
|
23
|
+
const sliceIds = tableKeyAndSliceId.substring(
|
|
24
|
+
tableKeyAndSliceId.indexOf(routeSliceIdIndicators[0]) + 1,
|
|
25
|
+
tableKeyAndSliceId.indexOf(routeSliceIdIndicators[1])
|
|
26
|
+
).split(routeSliceIdSeperator).filter((s) => s.length > 0);
|
|
27
|
+
const tableKey = tableKeyAndSliceId.split(routeSliceIdIndicators[0])[0];
|
|
20
28
|
const ref = !!refFlat ? refFlat.split(":").length == 2 ? { [tableKey + "InsertHistoryRef"]: refFlat } : { [tableKey + "Ref"]: refFlat } : {};
|
|
21
29
|
const segment = {
|
|
22
30
|
tableKey,
|
|
23
31
|
...ref
|
|
24
32
|
};
|
|
33
|
+
if (sliceIds.length > 0) {
|
|
34
|
+
segment.sliceIds = sliceIds;
|
|
35
|
+
}
|
|
25
36
|
segments.push(segment);
|
|
26
37
|
}
|
|
27
38
|
return new Route(segments);
|
|
@@ -46,8 +57,9 @@ class Route {
|
|
|
46
57
|
* @returns A new Route that is one level deeper or 'steps' levels deeper
|
|
47
58
|
*/
|
|
48
59
|
deeper(steps) {
|
|
60
|
+
let deeperRoute;
|
|
49
61
|
if (steps === void 0) {
|
|
50
|
-
|
|
62
|
+
deeperRoute = new Route(this._segments.slice(1, this._segments.length));
|
|
51
63
|
} else {
|
|
52
64
|
if (steps < 1) {
|
|
53
65
|
throw new Error("Steps must be greater than 0");
|
|
@@ -55,8 +67,14 @@ class Route {
|
|
|
55
67
|
if (steps >= this._segments.length) {
|
|
56
68
|
throw new Error("Cannot go deeper than the root");
|
|
57
69
|
}
|
|
58
|
-
|
|
70
|
+
deeperRoute = new Route(
|
|
71
|
+
this._segments.slice(steps, this._segments.length)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if (!!this.propertyKey) {
|
|
75
|
+
deeperRoute.propertyKey = this.propertyKey;
|
|
59
76
|
}
|
|
77
|
+
return deeperRoute;
|
|
60
78
|
}
|
|
61
79
|
// .............................................................................
|
|
62
80
|
/**
|
|
@@ -159,8 +177,13 @@ class Route {
|
|
|
159
177
|
let flat = "";
|
|
160
178
|
for (const segment of this._segments) {
|
|
161
179
|
const tableKey = segment.tableKey;
|
|
162
|
-
const
|
|
163
|
-
|
|
180
|
+
const tableKeyAndSliceId = segment.sliceIds ? `${tableKey}${routeSliceIdIndicators[0]}${segment.sliceIds.join(
|
|
181
|
+
routeSliceIdSeperator
|
|
182
|
+
)}${routeSliceIdIndicators[1]}` : tableKey;
|
|
183
|
+
const ref = Object.keys(segment).filter(
|
|
184
|
+
(k) => ["tableKey", "sliceIds"].indexOf(k) === -1
|
|
185
|
+
)[0];
|
|
186
|
+
flat += `/${tableKeyAndSliceId}${ref ? `${routeRefSeperator}${segment[ref]}` : ""}`;
|
|
164
187
|
}
|
|
165
188
|
return flat;
|
|
166
189
|
}
|
|
@@ -544,6 +567,34 @@ const exampleRevision = () => ({
|
|
|
544
567
|
timestamp: 1743558427
|
|
545
568
|
});
|
|
546
569
|
const exampleSliceIdsTable = () => bakeryExample().slices;
|
|
570
|
+
const createSliceIdsTableCfg = (tableKey) => ({
|
|
571
|
+
key: tableKey,
|
|
572
|
+
type: "sliceIds",
|
|
573
|
+
columns: [
|
|
574
|
+
{ key: "_hash", type: "string", titleLong: "Hash", titleShort: "Hash" },
|
|
575
|
+
{
|
|
576
|
+
key: "base",
|
|
577
|
+
type: "string",
|
|
578
|
+
titleLong: "Base SliceId",
|
|
579
|
+
titleShort: "Base SliceId"
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
key: "add",
|
|
583
|
+
type: "jsonArray",
|
|
584
|
+
titleLong: "Added SliceIds",
|
|
585
|
+
titleShort: "Add"
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
key: "remove",
|
|
589
|
+
type: "jsonArray",
|
|
590
|
+
titleLong: "Removed SliceIds",
|
|
591
|
+
titleShort: "Remove"
|
|
592
|
+
}
|
|
593
|
+
],
|
|
594
|
+
isHead: false,
|
|
595
|
+
isRoot: false,
|
|
596
|
+
isShared: true
|
|
597
|
+
});
|
|
547
598
|
class Example {
|
|
548
599
|
static ok = {
|
|
549
600
|
bakery: () => bakeryExample(),
|
|
@@ -1436,6 +1487,99 @@ const exampleTableCfg = (tableCfg = void 0) => {
|
|
|
1436
1487
|
isShared: false
|
|
1437
1488
|
};
|
|
1438
1489
|
};
|
|
1490
|
+
const createEditHistoryTableCfg = (cakeKey) => ({
|
|
1491
|
+
key: `${cakeKey}EditHistory`,
|
|
1492
|
+
type: "editHistory",
|
|
1493
|
+
columns: [
|
|
1494
|
+
{
|
|
1495
|
+
key: "_hash",
|
|
1496
|
+
type: "string",
|
|
1497
|
+
titleLong: "Hash",
|
|
1498
|
+
titleShort: "Hash"
|
|
1499
|
+
},
|
|
1500
|
+
{
|
|
1501
|
+
key: "timeId",
|
|
1502
|
+
type: "string",
|
|
1503
|
+
titleLong: "Time Identifier",
|
|
1504
|
+
titleShort: "Time ID"
|
|
1505
|
+
},
|
|
1506
|
+
{
|
|
1507
|
+
key: "multiEditRef",
|
|
1508
|
+
type: "string",
|
|
1509
|
+
titleLong: "Multi Edit Reference",
|
|
1510
|
+
titleShort: "Multi Edit Ref",
|
|
1511
|
+
ref: {
|
|
1512
|
+
tableKey: `${cakeKey}MultiEdit`
|
|
1513
|
+
}
|
|
1514
|
+
},
|
|
1515
|
+
{
|
|
1516
|
+
key: "dataRef",
|
|
1517
|
+
type: "string",
|
|
1518
|
+
titleLong: "Data Reference",
|
|
1519
|
+
titleShort: "Data Ref",
|
|
1520
|
+
ref: {
|
|
1521
|
+
tableKey: cakeKey
|
|
1522
|
+
}
|
|
1523
|
+
},
|
|
1524
|
+
{
|
|
1525
|
+
key: "previous",
|
|
1526
|
+
type: "jsonArray",
|
|
1527
|
+
titleLong: "Previous Values",
|
|
1528
|
+
titleShort: "Previous"
|
|
1529
|
+
}
|
|
1530
|
+
]
|
|
1531
|
+
});
|
|
1532
|
+
const createEditTableCfg = (cakeKey) => ({
|
|
1533
|
+
key: `${cakeKey}Edits`,
|
|
1534
|
+
type: "edits",
|
|
1535
|
+
columns: [
|
|
1536
|
+
{
|
|
1537
|
+
key: "_hash",
|
|
1538
|
+
type: "string",
|
|
1539
|
+
titleLong: "Hash",
|
|
1540
|
+
titleShort: "Hash"
|
|
1541
|
+
},
|
|
1542
|
+
{
|
|
1543
|
+
key: "name",
|
|
1544
|
+
type: "string",
|
|
1545
|
+
titleLong: "Name of the Edit",
|
|
1546
|
+
titleShort: "Name"
|
|
1547
|
+
},
|
|
1548
|
+
{
|
|
1549
|
+
key: "action",
|
|
1550
|
+
type: "json",
|
|
1551
|
+
titleLong: "Edit Action Data",
|
|
1552
|
+
titleShort: "Action"
|
|
1553
|
+
}
|
|
1554
|
+
]
|
|
1555
|
+
});
|
|
1556
|
+
const createMultiEditTableCfg = (cakeKey) => ({
|
|
1557
|
+
key: `${cakeKey}MultiEdits`,
|
|
1558
|
+
type: "multiEdits",
|
|
1559
|
+
columns: [
|
|
1560
|
+
{
|
|
1561
|
+
key: "_hash",
|
|
1562
|
+
type: "string",
|
|
1563
|
+
titleLong: "Hash",
|
|
1564
|
+
titleShort: "Hash"
|
|
1565
|
+
},
|
|
1566
|
+
{
|
|
1567
|
+
key: "previous",
|
|
1568
|
+
type: "string",
|
|
1569
|
+
titleLong: "Previous Value",
|
|
1570
|
+
titleShort: "Previous"
|
|
1571
|
+
},
|
|
1572
|
+
{
|
|
1573
|
+
key: "edit",
|
|
1574
|
+
type: "string",
|
|
1575
|
+
titleLong: "Edit Reference",
|
|
1576
|
+
titleShort: "Edit Ref",
|
|
1577
|
+
ref: {
|
|
1578
|
+
tableKey: `${cakeKey}Edits`
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
]
|
|
1582
|
+
});
|
|
1439
1583
|
const objectDepth = (o) => Object(o) === o ? 1 + Math.max(-1, ...Object.values(o).map(objectDepth)) : 0;
|
|
1440
1584
|
class InsertValidator {
|
|
1441
1585
|
constructor(_insert) {
|
|
@@ -2517,8 +2661,12 @@ export {
|
|
|
2517
2661
|
bakeryExample,
|
|
2518
2662
|
contentTypes,
|
|
2519
2663
|
createCakeTableCfg,
|
|
2664
|
+
createEditHistoryTableCfg,
|
|
2665
|
+
createEditTableCfg,
|
|
2520
2666
|
createInsertHistoryTableCfg,
|
|
2521
2667
|
createLayerTableCfg,
|
|
2668
|
+
createMultiEditTableCfg,
|
|
2669
|
+
createSliceIdsTableCfg,
|
|
2522
2670
|
exampleBuffetsTable,
|
|
2523
2671
|
exampleCakesTable,
|
|
2524
2672
|
exampleComponentsTable,
|
|
@@ -2540,6 +2688,9 @@ export {
|
|
|
2540
2688
|
removeDuplicates,
|
|
2541
2689
|
reservedFieldNames,
|
|
2542
2690
|
reservedTableKeys,
|
|
2691
|
+
routeRefSeperator,
|
|
2692
|
+
routeSliceIdIndicators,
|
|
2693
|
+
routeSliceIdSeperator,
|
|
2543
2694
|
throwOnInvalidTableCfg,
|
|
2544
2695
|
timeId,
|
|
2545
2696
|
validateInsert,
|
package/dist/route/route.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { TableKey } from '../typedefs.ts';
|
|
1
|
+
import { SliceId, TableKey } from '../typedefs.ts';
|
|
2
2
|
export type RouteRef = string;
|
|
3
3
|
export type RouteSegment<Str extends string> = {
|
|
4
4
|
[key in Str as `${Uncapitalize<string & key>}Ref`]: string;
|
|
5
5
|
} & {
|
|
6
6
|
tableKey: TableKey;
|
|
7
|
+
sliceIds?: SliceId[];
|
|
7
8
|
};
|
|
9
|
+
export declare const routeRefSeperator = "@";
|
|
10
|
+
export declare const routeSliceIdIndicators: readonly ["(", ")"];
|
|
11
|
+
export declare const routeSliceIdSeperator: ",";
|
|
8
12
|
export type RouteSegmentFlat<N extends string> = `${N}` | `${N}@${string}` | `${N}@${string}:${string}`;
|
|
9
13
|
/**
|
|
10
14
|
* A class to handle routes in an Rljson object.
|