@rljson/rljson 0.0.71 → 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.
@@ -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;
@@ -29,6 +29,7 @@ export interface ColumnCfg extends Json {
29
29
  * Defines if the column is reference column to another table (foreign key)
30
30
  */
31
31
  ref?: {
32
+ type: ContentType;
32
33
  tableKey: TableKey;
33
34
  columnKey?: ColumnKey;
34
35
  };
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 [tableKey, refFlat] = segmentFlat.split("@");
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
- return new Route(this._segments.slice(1, this._segments.length));
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
- return new Route(this._segments.slice(steps, this._segments.length));
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 ref = Object.keys(segment).filter((k) => k !== "tableKey")[0];
163
- flat += `/${tableKey}${ref ? `@${segment[ref]}` : ""}`;
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(),
@@ -2615,6 +2666,7 @@ export {
2615
2666
  createInsertHistoryTableCfg,
2616
2667
  createLayerTableCfg,
2617
2668
  createMultiEditTableCfg,
2669
+ createSliceIdsTableCfg,
2618
2670
  exampleBuffetsTable,
2619
2671
  exampleCakesTable,
2620
2672
  exampleComponentsTable,
@@ -2636,6 +2688,9 @@ export {
2636
2688
  removeDuplicates,
2637
2689
  reservedFieldNames,
2638
2690
  reservedTableKeys,
2691
+ routeRefSeperator,
2692
+ routeSliceIdIndicators,
2693
+ routeSliceIdSeperator,
2639
2694
  throwOnInvalidTableCfg,
2640
2695
  timeId,
2641
2696
  validateInsert,
@@ -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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.71",
3
+ "version": "0.0.72",
4
4
  "description": "The RLJSON data format specification",
5
5
  "homepage": "https://github.com/rljson/rljson",
6
6
  "bugs": "https://github.com/rljson/rljson/issues",