@rljson/rljson 0.0.58 → 0.0.60

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.
@@ -3,6 +3,7 @@ import { RljsonTable } from '../rljson.ts';
3
3
  import { TableKey } from '../typedefs.ts';
4
4
  import { LayerRef } from './layer.ts';
5
5
  import { SliceIdsRef } from './slice-ids.ts';
6
+ import { TableCfg } from './table-cfg.ts';
6
7
  /**
7
8
  * A `CakeLayerId` assigns an id or name to a cake layer
8
9
  */
@@ -39,6 +40,14 @@ export interface Cake extends Json {
39
40
  * A table containing cakes
40
41
  */
41
42
  export type CakesTable = RljsonTable<Cake, 'cakes'>;
43
+ /**
44
+ * Sample Table as BoilerPlate for Tests and Examples
45
+ */
46
+ /**
47
+ * Sample Table as BoilerPlate for Tests and Examples
48
+ * @param cakeKey - the key of the cake table cfg
49
+ */
50
+ export declare const createCakeTableCfg: (cakeKey: string) => TableCfg;
42
51
  /**
43
52
  * Provides an example cakes table for test purposes
44
53
  */
@@ -1,6 +1,7 @@
1
+ import { Json } from '@rljson/json';
1
2
  import { NutritionalValues } from '../example/bakery-example.ts';
2
3
  import { RljsonTable } from '../rljson.ts';
3
- import { JsonWithId, Ref } from '../typedefs.ts';
4
+ import { Ref } from '../typedefs.ts';
4
5
  /**
5
6
  * A reference to a components row in a components table
6
7
  */
@@ -8,7 +9,7 @@ export type ComponentRef = Ref;
8
9
  /**
9
10
  * A table containing components
10
11
  */
11
- export type ComponentsTable<T extends JsonWithId> = RljsonTable<T, 'components'>;
12
+ export type ComponentsTable<T extends Json> = RljsonTable<T, 'components'>;
12
13
  /**
13
14
  * Provides an example components table for test purposes
14
15
  */
@@ -3,6 +3,7 @@ import { RljsonTable } from '../rljson.ts';
3
3
  import { Ref, SliceId, TableKey } from '../typedefs.ts';
4
4
  import { ComponentRef } from './components.ts';
5
5
  import { SliceIdsRef } from './slice-ids.ts';
6
+ import { TableCfg } from './table-cfg.ts';
6
7
  /**
7
8
  * A LayerRef is a hash pointing to a layer
8
9
  */
@@ -44,6 +45,11 @@ export interface Layer extends Json {
44
45
  * A table containing layers
45
46
  */
46
47
  export type LayersTable = RljsonTable<Layer, 'layers'>;
48
+ /**
49
+ * Sample Table as BoilerPlate for Tests and Examples
50
+ * @param layerKey - the key of the layer table
51
+ */
52
+ export declare const createLayerTableCfg: (layerKey: string) => TableCfg;
47
53
  /**
48
54
  * Provides an example layersTable for test purposes
49
55
  */
@@ -1,23 +1,29 @@
1
1
  import { Json, JsonH, JsonValueH } from '@rljson/json';
2
- import { Ingredient } from '../example/bakery-example.ts';
3
- import { RljsonTable } from '../rljson.ts';
4
2
  import { Ref } from '../typedefs.ts';
3
+ import { RouteRef } from './route.ts';
4
+ import { RljsonTable } from '../rljson.ts';
5
5
  /**
6
- * A reference to a Edit row in a Edit table
6
+ * An Edit Object describing edits on data basically
7
7
  */
8
8
  export type EditRef = Ref;
9
9
  export type Edit<T extends Json> = {
10
10
  value: T & JsonValueH;
11
- route: string;
11
+ route: RouteRef;
12
12
  origin?: Ref;
13
- previous?: EditRef;
13
+ previous?: EditProtocolTimeId[];
14
14
  acknowledged?: boolean;
15
15
  } & JsonH;
16
- /**
17
- * A table containing components
18
- */
19
- export type EditsTable<T extends Json> = RljsonTable<Edit<T>, 'edits'>;
16
+ export type EditProtocolTimeId = string;
17
+ export type EditProtocolRow<Str extends string> = {
18
+ [key in Str as `${Uncapitalize<string & key>}Ref`]: string;
19
+ } & {
20
+ timeId: EditProtocolTimeId;
21
+ route: RouteRef;
22
+ origin?: Ref;
23
+ previous?: EditProtocolTimeId[];
24
+ };
25
+ export type EditProtocol<Str extends string> = RljsonTable<EditProtocolRow<Str>, 'edits'>;
20
26
  /**
21
27
  * Provides an example Edits table for test purposes
22
28
  */
23
- export declare const exampleEditsTable: () => EditsTable<Ingredient>;
29
+ export declare const exampleEditsTable: () => EditProtocol<any>;
@@ -1,6 +1,13 @@
1
+ export type RouteRef = string;
2
+ /**
3
+ * A class to handle routes in an Rljson object.
4
+ */
1
5
  export declare class Route {
2
6
  private segments;
3
7
  constructor(segments: string[]);
4
8
  static fromFlat(route: string): Route;
9
+ segment(index?: number): string;
10
+ deeper(steps?: number): Route;
11
+ get isRoot(): boolean;
5
12
  get flat(): string;
6
13
  }
@@ -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 { EditsTable } from '../edit/edit.ts';
7
+ import { EditProtocol } from '../edit/edit.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
- ingredientsEdits: EditsTable<Ingredient>;
35
+ ingredientsEdits: EditProtocol<'Ingredients'>;
36
36
  }
37
37
  export declare const bakeryExample: () => Bakery;
package/dist/index.d.ts CHANGED
@@ -6,10 +6,12 @@ export * from './content/revision.ts';
6
6
  export * from './content/slice-ids.ts';
7
7
  export * from './content/table-cfg.ts';
8
8
  export * from './edit/edit.ts';
9
+ export * from './edit/route.ts';
9
10
  export * from './example.ts';
10
11
  export * from './example/bakery-example.ts';
11
12
  export * from './rljson.ts';
12
13
  export * from './tools/remove-duplicates.ts';
14
+ export * from './tools/time-id.ts';
13
15
  export * from './typedefs.ts';
14
16
  export * from './validate/base-validator.ts';
15
17
  export * from './validate/validate.ts';
package/dist/rljson.d.ts CHANGED
@@ -6,14 +6,14 @@ 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 { EditsTable } from './edit/edit.ts';
9
+ import { EditProtocol } from './edit/edit.ts';
10
10
  import { ContentType, Ref, TableKey } from './typedefs.ts';
11
11
  export declare const reservedFieldNames: string[];
12
12
  export declare const reservedTableKeys: string[];
13
13
  /**
14
14
  * One of the supported Rljson table types
15
15
  */
16
- export type TableType = BuffetsTable | ComponentsTable<any> | LayersTable | SliceIdsTable | CakesTable | RevisionsTable | TablesCfgTable | EditsTable<any>;
16
+ export type TableType = BuffetsTable | ComponentsTable<any> | LayersTable | SliceIdsTable | CakesTable | RevisionsTable | TablesCfgTable | EditProtocol<any>;
17
17
  /** The rljson data format */
18
18
  export interface Rljson extends Json {
19
19
  [tableId: TableKey]: TableType;
package/dist/rljson.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { hip, hsh } from "@rljson/hash";
2
2
  import { exampleJsonObject, jsonValueTypes, jsonValueMatchesType, jsonValueType } from "@rljson/json";
3
+ import { nanoid } from "nanoid";
3
4
  // @license
4
5
  class Route {
5
6
  constructor(segments) {
@@ -8,6 +9,28 @@ class Route {
8
9
  static fromFlat(route) {
9
10
  return new Route(route.split("/").filter(Boolean));
10
11
  }
12
+ segment(index) {
13
+ if (index === void 0) {
14
+ return this.segments[this.segments.length - 1];
15
+ }
16
+ return this.segments[index];
17
+ }
18
+ deeper(steps) {
19
+ if (steps === void 0) {
20
+ return new Route(this.segments.slice(1, this.segments.length));
21
+ } else {
22
+ if (steps < 1) {
23
+ throw new Error("Steps must be greater than 0");
24
+ }
25
+ if (steps >= this.segments.length) {
26
+ throw new Error("Cannot go deeper than the root");
27
+ }
28
+ return new Route(this.segments.slice(steps, this.segments.length));
29
+ }
30
+ }
31
+ get isRoot() {
32
+ return this.segments.length === 1;
33
+ }
11
34
  get flat() {
12
35
  return "/" + this.segments.join("/");
13
36
  }
@@ -44,6 +67,12 @@ const bakeryExample = () => {
44
67
  amountUnit: "g",
45
68
  nutritionalValuesRef: nutritionalValues._data[0]._hash,
46
69
  _hash: ""
70
+ },
71
+ {
72
+ id: "flourB",
73
+ amountUnit: "g",
74
+ nutritionalValuesRef: nutritionalValues._data[1]._hash,
75
+ _hash: ""
47
76
  }
48
77
  ],
49
78
  _hash: ""
@@ -138,25 +167,18 @@ const bakeryExample = () => {
138
167
  _type: "edits",
139
168
  _data: [
140
169
  {
141
- value: {
142
- name: "Flour A",
143
- amountUnit: "g",
144
- nutritionalValuesRef: nutritionalValues._data[0]._hash,
145
- _hash: ""
146
- },
170
+ timeId: "de72:1759123957292",
171
+ ingredientsRef: ingredients._data[0]._hash,
147
172
  route: Route.fromFlat("/ingredients/").flat,
148
- _hash: ""
173
+ origin: "H45H",
174
+ previous: []
149
175
  },
150
176
  {
151
- value: {
152
- name: "Flour B",
153
- amountUnit: "g",
154
- nutritionalValuesRef: nutritionalValues._data[0]._hash,
155
- _hash: ""
156
- },
157
- previous: "D2Rp36U1DBa69zAya-16EJ",
177
+ timeId: "a8e0:1759123987505",
178
+ ingredientsRef: ingredients._data[1]._hash,
158
179
  route: Route.fromFlat("/ingredients/").flat,
159
- _hash: ""
180
+ origin: "H45H",
181
+ previous: ["de72:1759123957292"]
160
182
  }
161
183
  ],
162
184
  _hash: ""
@@ -178,10 +200,38 @@ const bakeryExample = () => {
178
200
  // @license
179
201
  const exampleBuffetsTable = () => bakeryExample().buffets;
180
202
  // @license
203
+ const createCakeTableCfg = (cakeKey) => ({
204
+ key: cakeKey,
205
+ type: "cakes",
206
+ columns: [
207
+ { key: "sliceIdsTable", type: "string" },
208
+ { key: "sliceIdsRow", type: "string" },
209
+ { key: "layers", type: "jsonArray" },
210
+ { key: "id", type: "string" }
211
+ ],
212
+ isHead: false,
213
+ isRoot: false,
214
+ isShared: true
215
+ });
181
216
  const exampleCakesTable = () => bakeryExample().cakes;
182
217
  // @license
183
218
  const exampleComponentsTable = () => bakeryExample().nutritionalValues;
184
219
  // @license
220
+ const createLayerTableCfg = (layerKey) => ({
221
+ key: layerKey,
222
+ type: "layers",
223
+ columns: [
224
+ { key: "base", type: "string" },
225
+ { key: "sliceIdsTable", type: "string" },
226
+ { key: "sliceIdsTableRow", type: "string" },
227
+ { key: "componentsTable", type: "string" },
228
+ { key: "add", type: "jsonArray" },
229
+ { key: "remove", type: "jsonArray" }
230
+ ],
231
+ isHead: false,
232
+ isRoot: false,
233
+ isShared: true
234
+ });
185
235
  const exampleLayersTable = () => bakeryExample().recipeLayers;
186
236
  // @license
187
237
  const exampleRevision = () => ({
@@ -924,6 +974,10 @@ const removeDuplicates = (rljson) => {
924
974
  return hip(result, { throwOnWrongHashes: false });
925
975
  };
926
976
  // @license
977
+ const timeId = () => {
978
+ return nanoid(4) + ":" + Date.now();
979
+ };
980
+ // @license
927
981
  const contentTypes = [
928
982
  "buffets",
929
983
  "cakes",
@@ -1448,10 +1502,9 @@ class _BaseValidator {
1448
1502
  continue;
1449
1503
  }
1450
1504
  const targetSliceIdsTable = this.rljson[key];
1451
- const targetSliceIds2 = targetSliceIdsTable._data.flatMap((d) => [
1452
- ...d.add,
1453
- ...d.remove ?? []
1454
- ]);
1505
+ const targetSliceIds2 = targetSliceIdsTable._data.flatMap(
1506
+ (d) => [...d.add, ...d.remove ?? []]
1507
+ );
1455
1508
  if (targetSliceIds2.indexOf(targetSliceId) === -1) {
1456
1509
  missingSliceIdRefs.push({
1457
1510
  sourceTable: tableKey,
@@ -1823,10 +1876,13 @@ class Validate {
1823
1876
  export {
1824
1877
  BaseValidator,
1825
1878
  Example,
1879
+ Route,
1826
1880
  Validate,
1827
1881
  addColumnsToTableCfg,
1828
1882
  bakeryExample,
1829
1883
  contentTypes,
1884
+ createCakeTableCfg,
1885
+ createLayerTableCfg,
1830
1886
  exampleBuffetsTable,
1831
1887
  exampleCakesTable,
1832
1888
  exampleComponentsTable,
@@ -1845,5 +1901,6 @@ export {
1845
1901
  reservedFieldNames,
1846
1902
  reservedTableKeys,
1847
1903
  throwOnInvalidTableCfg,
1904
+ timeId,
1848
1905
  validateRljsonAgainstTableCfg
1849
1906
  };
@@ -0,0 +1 @@
1
+ export declare const timeId: () => string;
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/rljson",
3
- "version": "0.0.58",
4
- "packageManager": "pnpm@10.11.0",
3
+ "version": "0.0.60",
5
4
  "description": "The RLJSON data format specification",
6
5
  "homepage": "https://github.com/rljson/rljson",
7
6
  "bugs": "https://github.com/rljson/rljson/issues",
@@ -20,14 +19,6 @@
20
19
  "dist"
21
20
  ],
22
21
  "type": "module",
23
- "scripts": {
24
- "build": "npx vite build && tsc && cp README* dist && mkdir dist/src && cp src/example.ts dist/src",
25
- "test": "npx vitest run --coverage && npm run lint",
26
- "prebuild": "npm run test",
27
- "prepublishOnly": "npm run build && npm run test",
28
- "lint": "npx eslint",
29
- "updateGoldens": "cross-env UPDATE_GOLDENS=true npm test"
30
- },
31
22
  "devDependencies": {
32
23
  "@types/node": "^24.5.2",
33
24
  "@typescript-eslint/eslint-plugin": "^8.44.1",
@@ -51,12 +42,14 @@
51
42
  },
52
43
  "dependencies": {
53
44
  "@rljson/hash": "^0.0.16",
54
- "@rljson/json": "^0.0.21"
45
+ "@rljson/json": "^0.0.21",
46
+ "nanoid": "^5.1.6"
55
47
  },
56
- "pnpm": {
57
- "onlyBuiltDependencies": [
58
- "esbuild"
59
- ],
60
- "overrides": {}
48
+ "scripts": {
49
+ "build": "npx vite build && tsc && cp README* dist && mkdir dist/src && cp src/example.ts dist/src",
50
+ "test": "npx vitest run --coverage && npm run lint",
51
+ "prebuild": "npm run test",
52
+ "lint": "npx eslint",
53
+ "updateGoldens": "cross-env UPDATE_GOLDENS=true npm test"
61
54
  }
62
- }
55
+ }