@rljson/io 0.0.61 → 0.0.63
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/conformance-tests/goldens/tableCfgs-1.json +3 -157
- package/dist/conformance-tests/io-conformance.spec.ts +5 -4
- package/dist/index.d.ts +4 -0
- package/dist/io-multi.d.ts +117 -0
- package/dist/io-peer-bridge.d.ts +75 -0
- package/dist/io.js +779 -16
- package/dist/io.js.map +1 -0
- package/dist/peer-socket-mock.d.ts +13 -0
- package/dist/socket.d.ts +3 -1
- package/package.json +10 -10
|
@@ -1,159 +1,5 @@
|
|
|
1
1
|
[
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"type": "tableCfgs",
|
|
6
|
-
"isHead": false,
|
|
7
|
-
"isRoot": false,
|
|
8
|
-
"isShared": true,
|
|
9
|
-
"previous": "",
|
|
10
|
-
"columns": [
|
|
11
|
-
{
|
|
12
|
-
"key": "_hash",
|
|
13
|
-
"type": "string",
|
|
14
|
-
"titleShort": "Hash",
|
|
15
|
-
"titleLong": "Row Hash",
|
|
16
|
-
"_hash": "2QxgcOKzL6zsVCo9Yi_5Ke"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"key": "key",
|
|
20
|
-
"type": "string",
|
|
21
|
-
"titleShort": "Key",
|
|
22
|
-
"titleLong": "Table Key",
|
|
23
|
-
"_hash": "vXW6G031fGusGpEgdnVWmt"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"key": "type",
|
|
27
|
-
"type": "string",
|
|
28
|
-
"titleShort": "Type",
|
|
29
|
-
"titleLong": "Content Type",
|
|
30
|
-
"_hash": "X2upWVtQ02TKW3mj6SqU0c"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"key": "isHead",
|
|
34
|
-
"type": "boolean",
|
|
35
|
-
"titleShort": "Is Head",
|
|
36
|
-
"titleLong": "Is Head Table",
|
|
37
|
-
"_hash": "A-q9m5MVPMRVN6hk4pAMLH"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"key": "isRoot",
|
|
41
|
-
"type": "boolean",
|
|
42
|
-
"titleShort": "Is Root",
|
|
43
|
-
"titleLong": "Is Root Table",
|
|
44
|
-
"_hash": "qYiiwGCxzUtxlqIvZeU1rh"
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"key": "isShared",
|
|
48
|
-
"type": "boolean",
|
|
49
|
-
"titleShort": "Is Shared",
|
|
50
|
-
"titleLong": "Is Shared Table",
|
|
51
|
-
"_hash": "jS9CqQBxXDhz1IB6PET4-P"
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"key": "previous",
|
|
55
|
-
"type": "string",
|
|
56
|
-
"titleShort": "Previous",
|
|
57
|
-
"titleLong": "Previous Table Configuration Hash",
|
|
58
|
-
"_hash": "0EgSa6oJSjOqjUCqlJzb5E"
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
"key": "columns",
|
|
62
|
-
"type": "jsonArray",
|
|
63
|
-
"titleShort": "Columns",
|
|
64
|
-
"titleLong": "Column Configurations",
|
|
65
|
-
"_hash": "GRV_4vc3xouarDpc1ZXE2_"
|
|
66
|
-
}
|
|
67
|
-
]
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"key": "revisions",
|
|
71
|
-
"type": "revisions",
|
|
72
|
-
"isHead": true,
|
|
73
|
-
"isRoot": true,
|
|
74
|
-
"isShared": false,
|
|
75
|
-
"columns": [
|
|
76
|
-
{
|
|
77
|
-
"key": "_hash",
|
|
78
|
-
"type": "string",
|
|
79
|
-
"titleShort": "Hash",
|
|
80
|
-
"titleLong": "Row Hash",
|
|
81
|
-
"_hash": "2QxgcOKzL6zsVCo9Yi_5Ke"
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
"key": "table",
|
|
85
|
-
"type": "string",
|
|
86
|
-
"titleShort": "Table",
|
|
87
|
-
"titleLong": "Table Key",
|
|
88
|
-
"_hash": "dxePvdUNnwg2TdHEAPlzcL"
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
"key": "predecessor",
|
|
92
|
-
"type": "string",
|
|
93
|
-
"titleShort": "Predecessor",
|
|
94
|
-
"titleLong": "Predecessor Revision Hash",
|
|
95
|
-
"_hash": "DX2BPCXbaK-WFn4Oy9hYjg"
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
"key": "successor",
|
|
99
|
-
"type": "string",
|
|
100
|
-
"titleShort": "Successor",
|
|
101
|
-
"titleLong": "Successor Revision Hash",
|
|
102
|
-
"_hash": "w-IMk9JjuBkgt88ddVGV7B"
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
"key": "timestamp",
|
|
106
|
-
"type": "number",
|
|
107
|
-
"titleShort": "Timestamp",
|
|
108
|
-
"titleLong": "Revision Timestamp",
|
|
109
|
-
"_hash": "G9EloAJ1OVidMrffwSVrLt"
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
"key": "id",
|
|
113
|
-
"type": "string",
|
|
114
|
-
"titleShort": "ID",
|
|
115
|
-
"titleLong": "Revision ID",
|
|
116
|
-
"_hash": "gwBBBa7SXFx2Zfz00JYdCR"
|
|
117
|
-
}
|
|
118
|
-
],
|
|
119
|
-
"_hash": "KFWwSAaR3bnqCwesHeAN4k"
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
"key": "table0",
|
|
123
|
-
"type": "components",
|
|
124
|
-
"isHead": false,
|
|
125
|
-
"isRoot": false,
|
|
126
|
-
"isShared": true,
|
|
127
|
-
"columns": [
|
|
128
|
-
{
|
|
129
|
-
"key": "_hash",
|
|
130
|
-
"type": "string",
|
|
131
|
-
"titleShort": "_hash",
|
|
132
|
-
"titleLong": "Hash",
|
|
133
|
-
"_hash": "L9iUlNEZRCGaQQts9mi--U"
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
"key": "col0",
|
|
137
|
-
"type": "string",
|
|
138
|
-
"titleShort": "col0",
|
|
139
|
-
"titleLong": "Col0",
|
|
140
|
-
"_hash": "dCXjY3cV-nGTHT-40a9SLj"
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
"key": "col1",
|
|
144
|
-
"type": "string",
|
|
145
|
-
"titleShort": "col1",
|
|
146
|
-
"titleLong": "Col1",
|
|
147
|
-
"_hash": "FMQLo4Apkp7E3LwlW9Fzuy"
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
"key": "col2",
|
|
151
|
-
"type": "string",
|
|
152
|
-
"titleShort": "col2",
|
|
153
|
-
"titleLong": "Col2",
|
|
154
|
-
"_hash": "jeJdZQXgk22xyinIGX6IeM"
|
|
155
|
-
}
|
|
156
|
-
],
|
|
157
|
-
"_hash": "XyGTK9tL8OKBWGtsV0Ni-6"
|
|
158
|
-
}
|
|
2
|
+
"revisions",
|
|
3
|
+
"table0",
|
|
4
|
+
"tableCfgs"
|
|
159
5
|
]
|
|
@@ -154,12 +154,13 @@ export const runIoConformanceTests = (
|
|
|
154
154
|
|
|
155
155
|
// Check the tableCfgs
|
|
156
156
|
// Sort it in advance to have a stable order for the golden file
|
|
157
|
-
const actualTableCfgs =
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
const actualTableCfgs = await ioTools.tableCfgs();
|
|
158
|
+
const actualTableCfgsSorted = actualTableCfgs
|
|
159
|
+
.sort((a, b) => a.key.localeCompare(b.key))
|
|
160
|
+
.map((cfg) => cfg.key);
|
|
160
161
|
|
|
161
162
|
await expectGolden('io-conformance/tableCfgs-1.json', ego).toBe(
|
|
162
|
-
|
|
163
|
+
actualTableCfgsSorted,
|
|
163
164
|
);
|
|
164
165
|
});
|
|
165
166
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './io-db-name-mapping.ts';
|
|
2
2
|
export * from './io-mem.ts';
|
|
3
|
+
export * from './io-multi.ts';
|
|
4
|
+
export * from './io-peer-bridge.ts';
|
|
5
|
+
export * from './io-peer.ts';
|
|
6
|
+
export * from './io-server.ts';
|
|
3
7
|
export * from './io-test-setup.ts';
|
|
4
8
|
export * from './io-tools.ts';
|
|
5
9
|
export * from './io.ts';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { JsonValue } from '@rljson/json';
|
|
2
|
+
import { ContentType, Rljson, TableCfg, TableKey } from '@rljson/rljson';
|
|
3
|
+
import { Io } from './io.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Type representing an Io instance along with its capabilities and priority.
|
|
6
|
+
*/
|
|
7
|
+
export type IoMultiIo = {
|
|
8
|
+
io: Io;
|
|
9
|
+
id?: string;
|
|
10
|
+
priority: number;
|
|
11
|
+
read: boolean;
|
|
12
|
+
write: boolean;
|
|
13
|
+
dump: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Multi Io implementation that combines multiple underlying Io instances
|
|
17
|
+
* with different capabilities (read, write, dump) and priorities.
|
|
18
|
+
*/
|
|
19
|
+
export declare class IoMulti implements Io {
|
|
20
|
+
private _ios;
|
|
21
|
+
isOpen: boolean;
|
|
22
|
+
constructor(_ios: Array<IoMultiIo>);
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* Initializes all underlying Io instances.
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
init(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Closes all underlying Io instances.
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Returns a promise that resolves once all underlying Io instances are ready.
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
isReady(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Dumps the entire database content by merging dumps from all dumpable underlying Io instances.
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
dump(): Promise<Rljson>;
|
|
44
|
+
/**
|
|
45
|
+
* Dumps a specific table by merging dumps from all dumpable underlying Io instances that contain the table.
|
|
46
|
+
* @param request An object containing the table name to dump.
|
|
47
|
+
* @returns A promise that resolves to the dumped table data.
|
|
48
|
+
*/
|
|
49
|
+
dumpTable(request: {
|
|
50
|
+
table: string;
|
|
51
|
+
}): Promise<Rljson>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the content type of a specific table from the first underlying readable Io instance that contains the table.
|
|
54
|
+
* @param request An object containing the table name.
|
|
55
|
+
* @returns A promise that resolves to the content type of the table.
|
|
56
|
+
*/
|
|
57
|
+
contentType(request: {
|
|
58
|
+
table: string;
|
|
59
|
+
}): Promise<ContentType>;
|
|
60
|
+
/**
|
|
61
|
+
* Checks if a specific table exists in any of the underlying readable Io instances.
|
|
62
|
+
* @param tableKey The key of the table to check.
|
|
63
|
+
* @returns A promise that resolves to true if the table exists in any readable Io, false otherwise.
|
|
64
|
+
*/
|
|
65
|
+
tableExists(tableKey: TableKey): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Creates or extends a table in all underlying writable Io instances.
|
|
68
|
+
* @param request An object containing the table configuration.
|
|
69
|
+
* @returns A promise that resolves once the table has been created or extended in all writable Io instances.
|
|
70
|
+
*/
|
|
71
|
+
createOrExtendTable(request: {
|
|
72
|
+
tableCfg: TableCfg;
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Retrieves the raw table configurations from the highest priority underlying readable Io instance.
|
|
76
|
+
* @returns A promise that resolves to an array of table configurations.
|
|
77
|
+
*/
|
|
78
|
+
rawTableCfgs(): Promise<TableCfg[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Writes data to all underlying writable Io instances.
|
|
81
|
+
* @param request - An object containing the data to write.
|
|
82
|
+
* @returns A promise that resolves once the data has been written to all writable Io instances.
|
|
83
|
+
*/
|
|
84
|
+
write(request: {
|
|
85
|
+
data: Rljson;
|
|
86
|
+
}): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Reads rows from a specific table by merging rows from all underlying readable Io instances.
|
|
89
|
+
* @param request An object containing the table name and where clause.
|
|
90
|
+
* @returns A promise that resolves to the read rows.
|
|
91
|
+
*/
|
|
92
|
+
readRows(request: {
|
|
93
|
+
table: string;
|
|
94
|
+
where: {
|
|
95
|
+
[column: string]: JsonValue | null;
|
|
96
|
+
};
|
|
97
|
+
}): Promise<Rljson>;
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves the row count of a specific table by aggregating row counts from all dumpable underlying Io instances.
|
|
100
|
+
* @param table The name of the table.
|
|
101
|
+
* @returns A promise that resolves to the row count of the table.
|
|
102
|
+
*/
|
|
103
|
+
rowCount(table: string): Promise<number>;
|
|
104
|
+
/**
|
|
105
|
+
* Gets the list of underlying readable Io instances, sorted by priority.
|
|
106
|
+
*/
|
|
107
|
+
get readables(): Array<IoMultiIo>;
|
|
108
|
+
/**
|
|
109
|
+
* Gets the list of underlying writable Io instances, sorted by priority.
|
|
110
|
+
*/
|
|
111
|
+
get writables(): Array<IoMultiIo>;
|
|
112
|
+
/**
|
|
113
|
+
* Gets the list of underlying dumpable Io instances, sorted by priority.
|
|
114
|
+
*/
|
|
115
|
+
get dumpables(): Array<IoMultiIo>;
|
|
116
|
+
static example: () => Promise<IoMulti>;
|
|
117
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Io } from './io.ts';
|
|
2
|
+
import { Socket } from './socket.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Bridges Socket events to Io method calls.
|
|
5
|
+
*
|
|
6
|
+
* This class listens to socket events and translates them into corresponding
|
|
7
|
+
* Io method calls, automatically registering all Io interface methods.
|
|
8
|
+
*/
|
|
9
|
+
export declare class IoPeerBridge {
|
|
10
|
+
private _io;
|
|
11
|
+
private _socket;
|
|
12
|
+
private _eventHandlers;
|
|
13
|
+
constructor(_io: Io, _socket: Socket);
|
|
14
|
+
/**
|
|
15
|
+
* Starts the bridge by setting up connection event handlers and
|
|
16
|
+
* automatically registering all Io methods.
|
|
17
|
+
*/
|
|
18
|
+
start(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Stops the bridge by removing all event handlers.
|
|
21
|
+
*/
|
|
22
|
+
stop(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Automatically registers all Io interface methods as socket event handlers.
|
|
25
|
+
*/
|
|
26
|
+
private _registerIoMethods;
|
|
27
|
+
/**
|
|
28
|
+
* Registers a socket event to be translated to an Io method call.
|
|
29
|
+
*
|
|
30
|
+
* @param eventName - The socket event name (should match an Io method name)
|
|
31
|
+
* @param ioMethodName - (Optional) The Io method name if different from eventName
|
|
32
|
+
*/
|
|
33
|
+
registerEvent(eventName: string, ioMethodName?: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Registers multiple socket events at once.
|
|
36
|
+
*
|
|
37
|
+
* @param eventNames - Array of event names to register
|
|
38
|
+
*/
|
|
39
|
+
registerEvents(eventNames: string[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Unregisters a socket event handler.
|
|
42
|
+
*
|
|
43
|
+
* @param eventName - The event name to unregister
|
|
44
|
+
*/
|
|
45
|
+
unregisterEvent(eventName: string | symbol): void;
|
|
46
|
+
/**
|
|
47
|
+
* Emits a result back through the socket.
|
|
48
|
+
*
|
|
49
|
+
* @param eventName - The event name to emit
|
|
50
|
+
* @param data - The data to send
|
|
51
|
+
*/
|
|
52
|
+
emitToSocket(eventName: string | symbol, ...data: any[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* Calls an Io method directly and emits the result through the socket.
|
|
55
|
+
*
|
|
56
|
+
* @param ioMethodName - The Io method to call
|
|
57
|
+
* @param socketEventName - The socket event to emit with the result
|
|
58
|
+
* @param args - Arguments to pass to the Io method
|
|
59
|
+
*/
|
|
60
|
+
callIoAndEmit(ioMethodName: string, socketEventName: string | symbol, ...args: any[]): Promise<void>;
|
|
61
|
+
private _handleConnect;
|
|
62
|
+
private _handleDisconnect;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the current socket instance.
|
|
65
|
+
*/
|
|
66
|
+
get socket(): Socket;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the current Io instance.
|
|
69
|
+
*/
|
|
70
|
+
get io(): Io;
|
|
71
|
+
/**
|
|
72
|
+
* Returns whether the socket is currently connected.
|
|
73
|
+
*/
|
|
74
|
+
get isConnected(): boolean;
|
|
75
|
+
}
|