@rljson/io 0.0.62 → 0.0.64

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.
@@ -1,159 +1,5 @@
1
1
  [
2
- {
3
- "_hash": "jERNpYntKnsV66yxoS2xOg",
4
- "key": "tableCfgs",
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 = (await ioTools.tableCfgs()).sort((a, b) =>
158
- (a as any)._hash.localeCompare(b._hash),
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
- actualTableCfgs,
163
+ actualTableCfgsSorted,
163
164
  );
164
165
  });
165
166
  });
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from './io-db-name-mapping.ts';
2
2
  export * from './io-mem.ts';
3
3
  export * from './io-multi.ts';
4
+ export * from './io-peer-bridge.ts';
4
5
  export * from './io-peer.ts';
6
+ export * from './io-server.ts';
5
7
  export * from './io-test-setup.ts';
6
8
  export * from './io-tools.ts';
7
9
  export * from './io.ts';
@@ -6,6 +6,7 @@ import { Io } from './io.ts';
6
6
  */
7
7
  export type IoMultiIo = {
8
8
  io: Io;
9
+ id?: string;
9
10
  priority: number;
10
11
  read: boolean;
11
12
  write: boolean;
@@ -84,7 +85,7 @@ export declare class IoMulti implements Io {
84
85
  data: Rljson;
85
86
  }): Promise<void>;
86
87
  /**
87
- * Reads rows from the first underlying readable Io instance that contains the requested table and has matching rows.
88
+ * Reads rows from a specific table by merging rows from all underlying readable Io instances.
88
89
  * @param request An object containing the table name and where clause.
89
90
  * @returns A promise that resolves to the read rows.
90
91
  */
@@ -103,14 +104,14 @@ export declare class IoMulti implements Io {
103
104
  /**
104
105
  * Gets the list of underlying readable Io instances, sorted by priority.
105
106
  */
106
- get readables(): Array<Io>;
107
+ get readables(): Array<IoMultiIo>;
107
108
  /**
108
109
  * Gets the list of underlying writable Io instances, sorted by priority.
109
110
  */
110
- get writables(): Array<Io>;
111
+ get writables(): Array<IoMultiIo>;
111
112
  /**
112
113
  * Gets the list of underlying dumpable Io instances, sorted by priority.
113
114
  */
114
- get dumpables(): Array<Io>;
115
+ get dumpables(): Array<IoMultiIo>;
115
116
  static example: () => Promise<IoMulti>;
116
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
+ }