@rljson/io 0.0.17 → 0.0.19

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/io-mem.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { JsonValue } from '@rljson/json';
2
- import { Rljson } from '@rljson/rljson';
2
+ import { Rljson, TableCfg } from '@rljson/rljson';
3
3
  import { Io } from './io.ts';
4
4
  /**
5
5
  * In-Memory implementation of the Rljson Io interface.
@@ -22,9 +22,10 @@ export declare class IoMem implements Io {
22
22
  data: Rljson;
23
23
  }): Promise<void>;
24
24
  createTable(request: {
25
- tableCfg: string;
25
+ tableCfg: TableCfg;
26
26
  }): Promise<void>;
27
- tables(): Promise<Rljson>;
27
+ tableCfgs(): Promise<Rljson>;
28
+ allTableNames(): Promise<string[]>;
28
29
  private _isReady;
29
30
  private _mem;
30
31
  private _init;
package/dist/io.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { JsonValue } from '@rljson/json';
2
- import { Rljson } from '@rljson/rljson';
2
+ import { Rljson, TableCfg } from '@rljson/rljson';
3
3
  export interface Io {
4
4
  /** A promise resolving once the Io interface is ready
5
5
  *
@@ -18,11 +18,17 @@ export interface Io {
18
18
  * The config must be already in the database
19
19
  */
20
20
  createTable(request: {
21
- tableCfg: string;
21
+ tableCfg: TableCfg;
22
22
  }): Promise<void>;
23
- /** Returns the available table names */
24
- tables(): Promise<Rljson>;
25
- /** Writes Rljson data in to the database */
23
+ /**
24
+ * Returns a json structure returning current table configurations
25
+ */
26
+ tableCfgs(): Promise<Rljson>;
27
+ /**
28
+ * Returns an rljson with all available tables without data
29
+ */
30
+ allTableNames(): Promise<string[]>;
31
+ /** Writes Rljson data into the database */
26
32
  write(request: {
27
33
  data: Rljson;
28
34
  }): Promise<void>;
package/dist/io.js CHANGED
@@ -20,9 +20,12 @@ const _IoMem = class _IoMem {
20
20
  version: 1,
21
21
  key: "tableCfgs",
22
22
  type: "ingredients",
23
+ isHead: false,
24
+ isRoot: false,
25
+ isShared: true,
23
26
  columns: {
24
- key: { key: "key", type: "string", previous: "string" },
25
- type: { key: "type", type: "string", previous: "string" }
27
+ key: { type: "string", previous: "string" },
28
+ type: { type: "string", previous: "string" }
26
29
  }
27
30
  };
28
31
  hip(tableCfg);
@@ -31,9 +34,7 @@ const _IoMem = class _IoMem {
31
34
  _type: "ingredients",
32
35
  _tableCfg: tableCfg._hash
33
36
  });
34
- const updateExistingHashes = true;
35
- const throwOnOnWrongHashes = false;
36
- hip(this._mem, updateExistingHashes, throwOnOnWrongHashes);
37
+ hip(this._mem, { updateExistingHashes: true, throwOnWrongHashes: false });
37
38
  });
38
39
  this._init();
39
40
  }
@@ -65,26 +66,28 @@ const _IoMem = class _IoMem {
65
66
  createTable(request) {
66
67
  return this._createTable(request);
67
68
  }
68
- async tables() {
69
- const tables = [];
70
- for (const key of Object.keys(this._mem)) {
71
- const table = this._mem[key];
72
- const tableCfgRef = table._tableCfg;
73
- if (tableCfgRef) {
74
- for (const tableCfg of this._mem.tableCfgs._data) {
75
- if (tableCfg._hash === tableCfgRef) {
76
- tables.push(tableCfg);
77
- }
78
- }
69
+ async tableCfgs() {
70
+ const tables = this._mem.tableCfgs._data;
71
+ const newestVersion = {};
72
+ for (const table of tables) {
73
+ const existing = newestVersion[table.key];
74
+ if (!existing) {
75
+ newestVersion[table.key] = table;
76
+ } else if (table.version > existing.version) {
77
+ newestVersion[table.key] = table;
79
78
  }
80
79
  }
81
- const result = {
80
+ const resultData = Object.values(newestVersion);
81
+ return hip({
82
82
  tableCfgs: {
83
83
  _type: "ingredients",
84
- _data: tables
84
+ _data: resultData
85
85
  }
86
- };
87
- return hip(result);
86
+ });
87
+ }
88
+ async allTableNames() {
89
+ const tables = Object.keys(this._mem).filter((key) => !key.startsWith("_"));
90
+ return tables;
88
91
  }
89
92
  // ...........................................................................
90
93
  async _init() {
@@ -94,21 +97,26 @@ const _IoMem = class _IoMem {
94
97
  // ...........................................................................
95
98
  async _createTable(request) {
96
99
  var _a;
97
- const config = this._mem.tableCfgs._data.find(
98
- (cfg) => cfg._hash === request.tableCfg
99
- );
100
- if (!config) {
101
- throw new Error(`Table config ${request.tableCfg} not found`);
102
- }
103
- const { key, type } = config;
100
+ const { key, type } = request.tableCfg;
104
101
  const existing = this._mem[key];
105
102
  if (existing) {
106
103
  throw new Error(`Table ${key} already exists`);
107
104
  }
105
+ const newConfig = hsh(request.tableCfg);
106
+ const existingConfig = this._mem.tableCfgs._data.find(
107
+ (cfg) => cfg._hash === newConfig._hash
108
+ );
109
+ if (!existingConfig) {
110
+ this._mem.tableCfgs._data.push(newConfig);
111
+ this._mem.tableCfgs._hash = "";
112
+ const updateExistingHashes = false;
113
+ const throwOnWrongHashes = false;
114
+ hip(this._mem.tableCfgs, { updateExistingHashes, throwOnWrongHashes });
115
+ }
108
116
  const table = {
109
117
  _data: [],
110
118
  _type: type,
111
- _tableCfg: config._hash
119
+ _tableCfg: newConfig._hash
112
120
  };
113
121
  (_a = this._mem)[key] ?? (_a[key] = hip(table));
114
122
  }
@@ -154,9 +162,7 @@ const _IoMem = class _IoMem {
154
162
  }
155
163
  }
156
164
  this._mem._hash = "";
157
- const updateExistingHashes = false;
158
- const throwIfOnWrongHashes = false;
159
- hip(this._mem, updateExistingHashes, throwIfOnWrongHashes);
165
+ hip(this._mem, { updateExistingHashes: false, throwOnWrongHashes: false });
160
166
  }
161
167
  // ...........................................................................
162
168
  async _readRows(request) {
@@ -0,0 +1,39 @@
1
+ import { Json } from '@rljson/json';
2
+ import { Ref, Rljson, TableKey } from '@rljson/rljson';
3
+ /**
4
+ * Describes a row that references a child table row
5
+ */
6
+ export interface ParentRef {
7
+ /**
8
+ * The parent table that references the child table
9
+ */
10
+ [parentTable: TableKey]: {
11
+ /**
12
+ * The parent row that references the child row
13
+ */
14
+ [parentRow: Ref]: {
15
+ /**
16
+ * Details about the reference, e.g. an array index etc.
17
+ */
18
+ details?: Json;
19
+ };
20
+ };
21
+ }
22
+ /**
23
+ * Describes the parent table rows referencing a child table row
24
+ */
25
+ export interface ReverseRefs {
26
+ /**
27
+ * The child table we need the referencing rows for
28
+ */
29
+ [childTable: TableKey]: {
30
+ /**
31
+ * The row hashwe need the referencing rows for
32
+ */
33
+ [childRow: Ref]: ParentRef;
34
+ };
35
+ }
36
+ /**
37
+ * Calculates the reverse references for a given rljson object
38
+ */
39
+ export declare const calcReverseRefs: (rljson: Rljson) => ReverseRefs;
@@ -33,7 +33,7 @@ export const example = async () => {
33
33
  });
34
34
 
35
35
  // Create a table first
36
- await ioMem.createTable({ tableCfg: tableCfg._hash });
36
+ await ioMem.createTable({ tableCfg: tableCfg });
37
37
 
38
38
  // Write data into the table
39
39
  await ioMem.write({
@@ -48,7 +48,7 @@ export const example = async () => {
48
48
  // Read data from the table
49
49
  const data: Rljson = await ioMem.readRows({
50
50
  table: 'tableA',
51
- where: { _hash: rowWithHash._hash },
51
+ where: { _hash: (rowWithHash as any)._hash },
52
52
  });
53
53
 
54
54
  // Print the return rljson data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/io",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "packageManager": "pnpm@10.6.2",
5
5
  "description": "Low level interface for reading and writing RLJSON data",
6
6
  "homepage": "https://github.com/rljson/io",
@@ -21,18 +21,18 @@
21
21
  ],
22
22
  "type": "module",
23
23
  "scripts": {
24
- "build": "npx vite build && tsc && node scripts/copy-readme-to-dist.js && node scripts/copy-file.js 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"
24
+ "build": "pnpx vite build && tsc && node scripts/copy-readme-to-dist.js && node scripts/copy-file.js src/example.ts dist/src",
25
+ "test": "pnpx vitest run --coverage && pnpm run lint",
26
+ "prebuild": "pnpm run test",
27
+ "prepublishOnly": "pnpm run build && pnpm run test",
28
+ "lint": "pnpx eslint",
29
+ "updateGoldens": "cross-env UPDATE_GOLDENS=true pnpm test"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/node": "^22.13.14",
33
- "@typescript-eslint/eslint-plugin": "^8.28.0",
34
- "@typescript-eslint/parser": "^8.28.0",
35
- "@vitest/coverage-v8": "^3.0.9",
32
+ "@types/node": "^22.13.17",
33
+ "@typescript-eslint/eslint-plugin": "^8.29.0",
34
+ "@typescript-eslint/parser": "^8.29.0",
35
+ "@vitest/coverage-v8": "^3.1.1",
36
36
  "cross-env": "^7.0.3",
37
37
  "eslint": "^9.23.0",
38
38
  "eslint-plugin-jsdoc": "^50.6.9",
@@ -41,12 +41,12 @@
41
41
  "jsdoc": "^4.0.4",
42
42
  "read-pkg": "^9.0.1",
43
43
  "typescript": "~5.8.2",
44
- "typescript-eslint": "^8.28.0",
45
- "vite": "^6.2.3",
46
- "vite-node": "^3.0.9",
44
+ "typescript-eslint": "^8.29.0",
45
+ "vite": "^6.2.4",
46
+ "vite-node": "^3.1.1",
47
47
  "vite-plugin-dts": "^4.5.3",
48
48
  "vite-tsconfig-paths": "^5.1.4",
49
- "vitest": "^3.0.9",
49
+ "vitest": "^3.1.1",
50
50
  "vitest-dom": "^0.1.1"
51
51
  },
52
52
  "pnpm": {
@@ -56,10 +56,10 @@
56
56
  "overrides": {}
57
57
  },
58
58
  "dependencies": {
59
- "@rljson/hash": "^0.0.12",
59
+ "@rljson/hash": "^0.0.13",
60
60
  "@rljson/is-ready": "^0.0.17",
61
61
  "@rljson/json": "^0.0.18",
62
- "@rljson/rljson": "^0.0.32",
62
+ "@rljson/rljson": "^0.0.36",
63
63
  "@rljson/validate": "^0.0.9"
64
64
  }
65
65
  }