@rljson/io 0.0.10 → 0.0.13
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 -4
- package/dist/io.d.ts +8 -5
- package/dist/io.js +39 -17
- package/dist/src/example.ts +19 -3
- package/package.json +3 -3
package/dist/io-mem.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonValue } from '@rljson/json';
|
|
2
|
-
import {
|
|
2
|
+
import { Rljson } from '@rljson/rljson';
|
|
3
3
|
import { Io } from './io.ts';
|
|
4
4
|
/**
|
|
5
5
|
* In-Memory implementation of the Rljson Io interface.
|
|
@@ -10,7 +10,7 @@ export declare class IoMem implements Io {
|
|
|
10
10
|
isReady(): Promise<void>;
|
|
11
11
|
dump(): Promise<Rljson>;
|
|
12
12
|
dumpTable(request: {
|
|
13
|
-
|
|
13
|
+
table: string;
|
|
14
14
|
}): Promise<Rljson>;
|
|
15
15
|
readRow(request: {
|
|
16
16
|
table: string;
|
|
@@ -26,13 +26,13 @@ export declare class IoMem implements Io {
|
|
|
26
26
|
data: Rljson;
|
|
27
27
|
}): Promise<void>;
|
|
28
28
|
createTable(request: {
|
|
29
|
-
|
|
30
|
-
type: ContentType;
|
|
29
|
+
tableCfg: string;
|
|
31
30
|
}): Promise<void>;
|
|
32
31
|
tables(): Promise<string[]>;
|
|
33
32
|
private _isReady;
|
|
34
33
|
private _mem;
|
|
35
34
|
private _init;
|
|
35
|
+
private _initTableCfgs;
|
|
36
36
|
private _createTable;
|
|
37
37
|
private _readRow;
|
|
38
38
|
private _dump;
|
package/dist/io.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonValue } from '@rljson/json';
|
|
2
|
-
import {
|
|
2
|
+
import { Rljson } from '@rljson/rljson';
|
|
3
3
|
export interface Io {
|
|
4
4
|
/** A promise resolving once the Io interface is ready
|
|
5
5
|
*
|
|
@@ -10,12 +10,15 @@ export interface Io {
|
|
|
10
10
|
dump(): Promise<Rljson>;
|
|
11
11
|
/** Returns the dump of a complete table */
|
|
12
12
|
dumpTable(request: {
|
|
13
|
-
|
|
13
|
+
table: string;
|
|
14
14
|
}): Promise<Rljson>;
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Creates a table with a given config
|
|
17
|
+
*
|
|
18
|
+
* The config must be already in the database
|
|
19
|
+
*/
|
|
16
20
|
createTable(request: {
|
|
17
|
-
|
|
18
|
-
type: ContentType;
|
|
21
|
+
tableCfg: string;
|
|
19
22
|
}): Promise<void>;
|
|
20
23
|
/** Returns the available table names */
|
|
21
24
|
tables(): Promise<string[]>;
|
package/dist/io.js
CHANGED
|
@@ -14,6 +14,26 @@ const _IoMem = class _IoMem {
|
|
|
14
14
|
// ######################
|
|
15
15
|
__publicField(this, "_isReady", new IsReady());
|
|
16
16
|
__publicField(this, "_mem", hip({}));
|
|
17
|
+
// ...........................................................................
|
|
18
|
+
__publicField(this, "_initTableCfgs", () => {
|
|
19
|
+
const tableCfg = {
|
|
20
|
+
key: "tableCfgs",
|
|
21
|
+
type: "properties",
|
|
22
|
+
columns: {
|
|
23
|
+
key: { key: "key", type: "string", previous: "string" },
|
|
24
|
+
type: { key: "type", type: "string", previous: "string" }
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
hip(tableCfg);
|
|
28
|
+
this._mem.tableCfgs = hip({
|
|
29
|
+
_data: [tableCfg],
|
|
30
|
+
_type: "properties",
|
|
31
|
+
_tableCfg: tableCfg._hash
|
|
32
|
+
});
|
|
33
|
+
const updateExistingHashes = true;
|
|
34
|
+
const throwOnOnWrongHashes = false;
|
|
35
|
+
hip(this._mem, updateExistingHashes, throwOnOnWrongHashes);
|
|
36
|
+
});
|
|
17
37
|
this._init();
|
|
18
38
|
}
|
|
19
39
|
// ...........................................................................
|
|
@@ -53,27 +73,29 @@ const _IoMem = class _IoMem {
|
|
|
53
73
|
return tables;
|
|
54
74
|
}
|
|
55
75
|
// ...........................................................................
|
|
56
|
-
_init() {
|
|
76
|
+
async _init() {
|
|
77
|
+
this._initTableCfgs();
|
|
57
78
|
this._isReady.resolve();
|
|
58
79
|
}
|
|
59
80
|
// ...........................................................................
|
|
60
81
|
async _createTable(request) {
|
|
61
82
|
var _a;
|
|
62
|
-
const
|
|
63
|
-
|
|
83
|
+
const config = this._mem.tableCfgs._data.find(
|
|
84
|
+
(cfg) => cfg._hash === request.tableCfg
|
|
85
|
+
);
|
|
86
|
+
if (!config) {
|
|
87
|
+
throw new Error(`Table config ${request.tableCfg} not found`);
|
|
88
|
+
}
|
|
89
|
+
const { key, type } = config;
|
|
90
|
+
const existing = this._mem[key];
|
|
64
91
|
if (existing) {
|
|
65
|
-
|
|
66
|
-
throw new Error(
|
|
67
|
-
`Table ${name} already exists with different type: "${existing._type}" vs "${request.type}"`
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
const table = hip({
|
|
72
|
-
_data: [],
|
|
73
|
-
_type: type
|
|
74
|
-
});
|
|
75
|
-
(_a = this._mem)[name] ?? (_a[name] = table);
|
|
92
|
+
throw new Error(`Table ${key} already exists`);
|
|
76
93
|
}
|
|
94
|
+
const table = hip({
|
|
95
|
+
_data: [],
|
|
96
|
+
_type: type
|
|
97
|
+
});
|
|
98
|
+
(_a = this._mem)[key] ?? (_a[key] = table);
|
|
77
99
|
}
|
|
78
100
|
// ...........................................................................
|
|
79
101
|
async _readRow(request) {
|
|
@@ -100,12 +122,12 @@ const _IoMem = class _IoMem {
|
|
|
100
122
|
}
|
|
101
123
|
// ...........................................................................
|
|
102
124
|
async _dumpTable(request) {
|
|
103
|
-
const table = this._mem[request.
|
|
125
|
+
const table = this._mem[request.table];
|
|
104
126
|
if (!table) {
|
|
105
|
-
throw new Error(`Table ${request.
|
|
127
|
+
throw new Error(`Table ${request.table} not found`);
|
|
106
128
|
}
|
|
107
129
|
return {
|
|
108
|
-
[request.
|
|
130
|
+
[request.table]: copy(table)
|
|
109
131
|
};
|
|
110
132
|
}
|
|
111
133
|
// ...........................................................................
|
package/dist/src/example.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// Use of this source code is governed by terms that can be
|
|
5
5
|
// found in the LICENSE file in the root of this package.
|
|
6
6
|
|
|
7
|
-
import { hsh } from '@rljson/hash';
|
|
8
|
-
import { Rljson } from '@rljson/rljson';
|
|
7
|
+
import { hip, hsh } from '@rljson/hash';
|
|
8
|
+
import { Rljson, TableCfg } from '@rljson/rljson';
|
|
9
9
|
|
|
10
10
|
import { IoMem } from './io-mem.ts';
|
|
11
11
|
|
|
@@ -16,8 +16,24 @@ export const example = async () => {
|
|
|
16
16
|
const row = { keyA2: 'a2' };
|
|
17
17
|
const rowWithHash = hsh(row);
|
|
18
18
|
|
|
19
|
+
// Create a table config first
|
|
20
|
+
const tableCfg = hip({
|
|
21
|
+
key: 'tableA',
|
|
22
|
+
type: 'properties',
|
|
23
|
+
columns: {},
|
|
24
|
+
} as TableCfg);
|
|
25
|
+
|
|
26
|
+
await ioMem.write({
|
|
27
|
+
data: {
|
|
28
|
+
tableCfgs: {
|
|
29
|
+
_type: 'properties',
|
|
30
|
+
_data: [tableCfg],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
19
35
|
// Create a table first
|
|
20
|
-
await ioMem.createTable({
|
|
36
|
+
await ioMem.createTable({ tableCfg: tableCfg._hash });
|
|
21
37
|
|
|
22
38
|
// Write data into the table
|
|
23
39
|
await ioMem.write({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rljson/io",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
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",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@rljson/hash": "^0.0.12",
|
|
60
|
-
"@rljson/is-ready": "^0.0.
|
|
60
|
+
"@rljson/is-ready": "^0.0.17",
|
|
61
61
|
"@rljson/json": "^0.0.18",
|
|
62
|
-
"@rljson/rljson": "^0.0.
|
|
62
|
+
"@rljson/rljson": "^0.0.28",
|
|
63
63
|
"@rljson/validate": "^0.0.8"
|
|
64
64
|
}
|
|
65
65
|
}
|