@rljson/io 0.0.13 → 0.0.15
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 +1 -6
- package/dist/io.d.ts +1 -6
- package/dist/io.js +26 -30
- package/dist/src/example.ts +5 -5
- package/package.json +9 -9
package/dist/io-mem.d.ts
CHANGED
|
@@ -12,10 +12,6 @@ export declare class IoMem implements Io {
|
|
|
12
12
|
dumpTable(request: {
|
|
13
13
|
table: string;
|
|
14
14
|
}): Promise<Rljson>;
|
|
15
|
-
readRow(request: {
|
|
16
|
-
table: string;
|
|
17
|
-
rowHash: string;
|
|
18
|
-
}): Promise<Rljson>;
|
|
19
15
|
readRows(request: {
|
|
20
16
|
table: string;
|
|
21
17
|
where: {
|
|
@@ -28,13 +24,12 @@ export declare class IoMem implements Io {
|
|
|
28
24
|
createTable(request: {
|
|
29
25
|
tableCfg: string;
|
|
30
26
|
}): Promise<void>;
|
|
31
|
-
tables(): Promise<
|
|
27
|
+
tables(): Promise<Rljson>;
|
|
32
28
|
private _isReady;
|
|
33
29
|
private _mem;
|
|
34
30
|
private _init;
|
|
35
31
|
private _initTableCfgs;
|
|
36
32
|
private _createTable;
|
|
37
|
-
private _readRow;
|
|
38
33
|
private _dump;
|
|
39
34
|
private _dumpTable;
|
|
40
35
|
private _write;
|
package/dist/io.d.ts
CHANGED
|
@@ -21,16 +21,11 @@ export interface Io {
|
|
|
21
21
|
tableCfg: string;
|
|
22
22
|
}): Promise<void>;
|
|
23
23
|
/** Returns the available table names */
|
|
24
|
-
tables(): Promise<
|
|
24
|
+
tables(): Promise<Rljson>;
|
|
25
25
|
/** Writes Rljson data in to the database */
|
|
26
26
|
write(request: {
|
|
27
27
|
data: Rljson;
|
|
28
28
|
}): Promise<void>;
|
|
29
|
-
/** Reads a specific row from a database table */
|
|
30
|
-
readRow(request: {
|
|
31
|
-
table: string;
|
|
32
|
-
rowHash: string;
|
|
33
|
-
}): Promise<Rljson>;
|
|
34
29
|
/** Queries a list of rows */
|
|
35
30
|
readRows(request: {
|
|
36
31
|
table: string;
|
package/dist/io.js
CHANGED
|
@@ -17,8 +17,9 @@ const _IoMem = class _IoMem {
|
|
|
17
17
|
// ...........................................................................
|
|
18
18
|
__publicField(this, "_initTableCfgs", () => {
|
|
19
19
|
const tableCfg = {
|
|
20
|
+
version: 1,
|
|
20
21
|
key: "tableCfgs",
|
|
21
|
-
type: "
|
|
22
|
+
type: "ingredients",
|
|
22
23
|
columns: {
|
|
23
24
|
key: { key: "key", type: "string", previous: "string" },
|
|
24
25
|
type: { key: "type", type: "string", previous: "string" }
|
|
@@ -27,7 +28,7 @@ const _IoMem = class _IoMem {
|
|
|
27
28
|
hip(tableCfg);
|
|
28
29
|
this._mem.tableCfgs = hip({
|
|
29
30
|
_data: [tableCfg],
|
|
30
|
-
_type: "
|
|
31
|
+
_type: "ingredients",
|
|
31
32
|
_tableCfg: tableCfg._hash
|
|
32
33
|
});
|
|
33
34
|
const updateExistingHashes = true;
|
|
@@ -51,9 +52,6 @@ const _IoMem = class _IoMem {
|
|
|
51
52
|
}
|
|
52
53
|
// ...........................................................................
|
|
53
54
|
// Rows
|
|
54
|
-
readRow(request) {
|
|
55
|
-
return this._readRow(request);
|
|
56
|
-
}
|
|
57
55
|
readRows(request) {
|
|
58
56
|
return this._readRows(request);
|
|
59
57
|
}
|
|
@@ -68,9 +66,25 @@ const _IoMem = class _IoMem {
|
|
|
68
66
|
return this._createTable(request);
|
|
69
67
|
}
|
|
70
68
|
async tables() {
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
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
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const result = {
|
|
82
|
+
tableCfgs: {
|
|
83
|
+
_type: "ingredients",
|
|
84
|
+
_data: tables
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return hip(result);
|
|
74
88
|
}
|
|
75
89
|
// ...........................................................................
|
|
76
90
|
async _init() {
|
|
@@ -91,30 +105,12 @@ const _IoMem = class _IoMem {
|
|
|
91
105
|
if (existing) {
|
|
92
106
|
throw new Error(`Table ${key} already exists`);
|
|
93
107
|
}
|
|
94
|
-
const table =
|
|
108
|
+
const table = {
|
|
95
109
|
_data: [],
|
|
96
|
-
_type: type
|
|
97
|
-
|
|
98
|
-
(_a = this._mem)[key] ?? (_a[key] = table);
|
|
99
|
-
}
|
|
100
|
-
// ...........................................................................
|
|
101
|
-
async _readRow(request) {
|
|
102
|
-
const table = this._mem[request.table];
|
|
103
|
-
if (!table) {
|
|
104
|
-
throw new Error(`Table ${request.table} not found`);
|
|
105
|
-
}
|
|
106
|
-
const row = table._data.find((row2) => row2._hash === request.rowHash);
|
|
107
|
-
if (!row) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
`Row "${request.rowHash}" not found in table ${request.table}`
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
const result = {
|
|
113
|
-
[request.table]: {
|
|
114
|
-
_data: [row]
|
|
115
|
-
}
|
|
110
|
+
_type: type,
|
|
111
|
+
_tableCfg: config._hash
|
|
116
112
|
};
|
|
117
|
-
|
|
113
|
+
(_a = this._mem)[key] ?? (_a[key] = hip(table));
|
|
118
114
|
}
|
|
119
115
|
// ...........................................................................
|
|
120
116
|
async _dump() {
|
package/dist/src/example.ts
CHANGED
|
@@ -19,14 +19,14 @@ export const example = async () => {
|
|
|
19
19
|
// Create a table config first
|
|
20
20
|
const tableCfg = hip({
|
|
21
21
|
key: 'tableA',
|
|
22
|
-
type: '
|
|
22
|
+
type: 'ingredients',
|
|
23
23
|
columns: {},
|
|
24
24
|
} as TableCfg);
|
|
25
25
|
|
|
26
26
|
await ioMem.write({
|
|
27
27
|
data: {
|
|
28
28
|
tableCfgs: {
|
|
29
|
-
_type: '
|
|
29
|
+
_type: 'ingredients',
|
|
30
30
|
_data: [tableCfg],
|
|
31
31
|
},
|
|
32
32
|
},
|
|
@@ -39,16 +39,16 @@ export const example = async () => {
|
|
|
39
39
|
await ioMem.write({
|
|
40
40
|
data: {
|
|
41
41
|
tableA: {
|
|
42
|
-
_type: '
|
|
42
|
+
_type: 'ingredients',
|
|
43
43
|
_data: [row],
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
// Read data from the table
|
|
49
|
-
const data: Rljson = await ioMem.
|
|
49
|
+
const data: Rljson = await ioMem.readRows({
|
|
50
50
|
table: 'tableA',
|
|
51
|
-
|
|
51
|
+
where: { _hash: rowWithHash._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.15",
|
|
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",
|
|
@@ -29,20 +29,20 @@
|
|
|
29
29
|
"updateGoldens": "cross-env UPDATE_GOLDENS=true npm test"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^22.13.
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
34
|
-
"@typescript-eslint/parser": "^8.
|
|
32
|
+
"@types/node": "^22.13.13",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^8.28.0",
|
|
34
|
+
"@typescript-eslint/parser": "^8.28.0",
|
|
35
35
|
"@vitest/coverage-v8": "^3.0.9",
|
|
36
36
|
"cross-env": "^7.0.3",
|
|
37
37
|
"eslint": "^9.23.0",
|
|
38
|
-
"eslint-plugin-jsdoc": "^50.6.
|
|
38
|
+
"eslint-plugin-jsdoc": "^50.6.9",
|
|
39
39
|
"eslint-plugin-tsdoc": "^0.4.0",
|
|
40
40
|
"globals": "^16.0.0",
|
|
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.
|
|
44
|
+
"typescript-eslint": "^8.28.0",
|
|
45
|
+
"vite": "^6.2.3",
|
|
46
46
|
"vite-node": "^3.0.9",
|
|
47
47
|
"vite-plugin-dts": "^4.5.3",
|
|
48
48
|
"vite-tsconfig-paths": "^5.1.4",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@rljson/hash": "^0.0.12",
|
|
60
60
|
"@rljson/is-ready": "^0.0.17",
|
|
61
61
|
"@rljson/json": "^0.0.18",
|
|
62
|
-
"@rljson/rljson": "^0.0.
|
|
63
|
-
"@rljson/validate": "^0.0.
|
|
62
|
+
"@rljson/rljson": "^0.0.32",
|
|
63
|
+
"@rljson/validate": "^0.0.9"
|
|
64
64
|
}
|
|
65
65
|
}
|