@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 +4 -3
- package/dist/io.d.ts +11 -5
- package/dist/io.js +37 -31
- package/dist/reverse-ref.d.ts +39 -0
- package/dist/src/example.ts +2 -2
- package/package.json +17 -17
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:
|
|
25
|
+
tableCfg: TableCfg;
|
|
26
26
|
}): Promise<void>;
|
|
27
|
-
|
|
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:
|
|
21
|
+
tableCfg: TableCfg;
|
|
22
22
|
}): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
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: {
|
|
25
|
-
type: {
|
|
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
|
-
|
|
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
|
|
69
|
-
const tables =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
|
80
|
+
const resultData = Object.values(newestVersion);
|
|
81
|
+
return hip({
|
|
82
82
|
tableCfgs: {
|
|
83
83
|
_type: "ingredients",
|
|
84
|
-
_data:
|
|
84
|
+
_data: resultData
|
|
85
85
|
}
|
|
86
|
-
};
|
|
87
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
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;
|
package/dist/src/example.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const example = async () => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// Create a table first
|
|
36
|
-
await ioMem.createTable({ tableCfg: tableCfg
|
|
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.
|
|
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": "
|
|
25
|
-
"test": "
|
|
26
|
-
"prebuild": "
|
|
27
|
-
"prepublishOnly": "
|
|
28
|
-
"lint": "
|
|
29
|
-
"updateGoldens": "cross-env UPDATE_GOLDENS=true
|
|
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.
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
34
|
-
"@typescript-eslint/parser": "^8.
|
|
35
|
-
"@vitest/coverage-v8": "^3.
|
|
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.
|
|
45
|
-
"vite": "^6.2.
|
|
46
|
-
"vite-node": "^3.
|
|
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.
|
|
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.
|
|
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.
|
|
62
|
+
"@rljson/rljson": "^0.0.36",
|
|
63
63
|
"@rljson/validate": "^0.0.9"
|
|
64
64
|
}
|
|
65
65
|
}
|