@zukhruf/rpc 0.0.0-stage → 0.8.181
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/LICENSE +21 -0
- package/README.md +202 -2
- package/dist/call/client.d.ts +34 -0
- package/dist/call/client.d.ts.map +1 -0
- package/dist/call/client.js +114 -0
- package/dist/call/client.js.map +1 -0
- package/dist/call/methods.d.ts +20 -0
- package/dist/call/methods.d.ts.map +1 -0
- package/dist/call/methods.js +2 -0
- package/dist/call/methods.js.map +1 -0
- package/dist/call/pending-calls.d.ts +66 -0
- package/dist/call/pending-calls.d.ts.map +1 -0
- package/dist/call/pending-calls.js +105 -0
- package/dist/call/pending-calls.js.map +1 -0
- package/dist/call/rpc-message.d.ts +30 -0
- package/dist/call/rpc-message.d.ts.map +1 -0
- package/dist/call/rpc-message.js +17 -0
- package/dist/call/rpc-message.js.map +1 -0
- package/dist/call/server.d.ts +24 -0
- package/dist/call/server.d.ts.map +1 -0
- package/dist/call/server.js +67 -0
- package/dist/call/server.js.map +1 -0
- package/dist/channel/child-process-connection.d.ts +17 -0
- package/dist/channel/child-process-connection.d.ts.map +1 -0
- package/dist/channel/child-process-connection.js +39 -0
- package/dist/channel/child-process-connection.js.map +1 -0
- package/dist/channel/envelope.d.ts +18 -0
- package/dist/channel/envelope.d.ts.map +1 -0
- package/dist/channel/envelope.js +18 -0
- package/dist/channel/envelope.js.map +1 -0
- package/dist/channel/parent-port-connection.d.ts +20 -0
- package/dist/channel/parent-port-connection.d.ts.map +1 -0
- package/dist/channel/parent-port-connection.js +30 -0
- package/dist/channel/parent-port-connection.js.map +1 -0
- package/dist/channel/process-channel-connection.d.ts +19 -0
- package/dist/channel/process-channel-connection.d.ts.map +1 -0
- package/dist/channel/process-channel-connection.js +31 -0
- package/dist/channel/process-channel-connection.js.map +1 -0
- package/dist/channel/shared-channel-connection.d.ts +29 -0
- package/dist/channel/shared-channel-connection.d.ts.map +1 -0
- package/dist/channel/shared-channel-connection.js +43 -0
- package/dist/channel/shared-channel-connection.js.map +1 -0
- package/dist/channel/worker-connection.d.ts +18 -0
- package/dist/channel/worker-connection.d.ts.map +1 -0
- package/dist/channel/worker-connection.js +31 -0
- package/dist/channel/worker-connection.js.map +1 -0
- package/dist/connection/connection-closed-error.d.ts +5 -0
- package/dist/connection/connection-closed-error.d.ts.map +1 -0
- package/dist/connection/connection-closed-error.js +8 -0
- package/dist/connection/connection-closed-error.js.map +1 -0
- package/dist/connection/connection-supervisor.d.ts +40 -0
- package/dist/connection/connection-supervisor.d.ts.map +1 -0
- package/dist/connection/connection-supervisor.js +202 -0
- package/dist/connection/connection-supervisor.js.map +1 -0
- package/dist/connection/connection.d.ts +27 -0
- package/dist/connection/connection.d.ts.map +1 -0
- package/dist/connection/connection.js +2 -0
- package/dist/connection/connection.js.map +1 -0
- package/dist/connection/connector.d.ts +11 -0
- package/dist/connection/connector.d.ts.map +1 -0
- package/dist/connection/connector.js +2 -0
- package/dist/connection/connector.js.map +1 -0
- package/dist/error/connection-lost-error.d.ts +10 -0
- package/dist/error/connection-lost-error.d.ts.map +1 -0
- package/dist/error/connection-lost-error.js +13 -0
- package/dist/error/connection-lost-error.js.map +1 -0
- package/dist/error/error-codec.d.ts +37 -0
- package/dist/error/error-codec.d.ts.map +1 -0
- package/dist/error/error-codec.js +120 -0
- package/dist/error/error-codec.js.map +1 -0
- package/dist/error/server-error.d.ts +9 -0
- package/dist/error/server-error.d.ts.map +1 -0
- package/dist/error/server-error.js +12 -0
- package/dist/error/server-error.js.map +1 -0
- package/dist/error/server-warning.d.ts +9 -0
- package/dist/error/server-warning.d.ts.map +1 -0
- package/dist/error/server-warning.js +11 -0
- package/dist/error/server-warning.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/is-record.d.ts +3 -0
- package/dist/shared/is-record.d.ts.map +1 -0
- package/dist/shared/is-record.js +3 -0
- package/dist/shared/is-record.js.map +1 -0
- package/package.json +48 -4
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { Latch } from '@zukhruf/async';
|
|
3
|
+
/**
|
|
4
|
+
* Keeps one connection open at a time. It connects on `open`, replaces a
|
|
5
|
+
* connection that is lost, and stops for good when its connector has no peer
|
|
6
|
+
* left. It never reads the messages it carries: what a replacement must be
|
|
7
|
+
* told again is for its listener to decide.
|
|
8
|
+
*/
|
|
9
|
+
export class ConnectionSupervisor extends EventEmitter {
|
|
10
|
+
#supervision;
|
|
11
|
+
constructor(connector) {
|
|
12
|
+
super();
|
|
13
|
+
this.#supervision = new Supervision(connector, this);
|
|
14
|
+
}
|
|
15
|
+
get status() {
|
|
16
|
+
return this.#supervision.state.status;
|
|
17
|
+
}
|
|
18
|
+
/** Starts connecting, unless a connection is open, on its way, or never coming. */
|
|
19
|
+
open() {
|
|
20
|
+
this.#supervision.state.open();
|
|
21
|
+
}
|
|
22
|
+
/** Whether `message` was handed to an open connection. A failed delivery is reported as a loss. */
|
|
23
|
+
send(message) {
|
|
24
|
+
return this.#supervision.state.send(message);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Keeps the process alive through the open connection and each one that
|
|
28
|
+
* replaces it, until `unref`. A new supervisor keeps the process alive, as a
|
|
29
|
+
* new socket does.
|
|
30
|
+
*/
|
|
31
|
+
ref() {
|
|
32
|
+
this.#supervision.refer(keepAlive);
|
|
33
|
+
}
|
|
34
|
+
/** Lets the process exit while the open connection, or one that replaces it, waits. */
|
|
35
|
+
unref() {
|
|
36
|
+
this.#supervision.refer(letExit);
|
|
37
|
+
}
|
|
38
|
+
/** Closes for good, after any connect still on its way has stopped. */
|
|
39
|
+
close() {
|
|
40
|
+
return this.#supervision.state.close();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const keepAlive = (connection) => connection.ref();
|
|
44
|
+
const letExit = (connection) => connection.unref();
|
|
45
|
+
/** What the states share: the current state, the last reference asked, and how to move to the next state. */
|
|
46
|
+
class Supervision {
|
|
47
|
+
connector;
|
|
48
|
+
events;
|
|
49
|
+
state;
|
|
50
|
+
/** The last `ref` or `unref` asked. Each new connection takes it on, whatever its adapter starts with. */
|
|
51
|
+
reference = keepAlive;
|
|
52
|
+
constructor(connector, events) {
|
|
53
|
+
this.connector = connector;
|
|
54
|
+
this.events = events;
|
|
55
|
+
this.state = new Idle(this);
|
|
56
|
+
}
|
|
57
|
+
/** A state that stopped being current must not act on what it started. */
|
|
58
|
+
isCurrent(state) {
|
|
59
|
+
return this.state === state;
|
|
60
|
+
}
|
|
61
|
+
become(state) {
|
|
62
|
+
this.state = state;
|
|
63
|
+
state.enter();
|
|
64
|
+
}
|
|
65
|
+
refer(reference) {
|
|
66
|
+
this.reference = reference;
|
|
67
|
+
this.state.reference();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
class Idle {
|
|
71
|
+
status = 'idle';
|
|
72
|
+
#supervision;
|
|
73
|
+
constructor(supervision) {
|
|
74
|
+
this.#supervision = supervision;
|
|
75
|
+
}
|
|
76
|
+
enter() { }
|
|
77
|
+
open() {
|
|
78
|
+
this.#supervision.become(new Connecting(this.#supervision));
|
|
79
|
+
}
|
|
80
|
+
send() {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
reference() { }
|
|
84
|
+
async close() {
|
|
85
|
+
this.#supervision.become(new Closed());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
class Connecting {
|
|
89
|
+
status = 'connecting';
|
|
90
|
+
#supervision;
|
|
91
|
+
#abort = new AbortController();
|
|
92
|
+
/** Opens when the connect ends, so `close` can wait for it. */
|
|
93
|
+
#ended = new Latch();
|
|
94
|
+
constructor(supervision) {
|
|
95
|
+
this.#supervision = supervision;
|
|
96
|
+
}
|
|
97
|
+
enter() {
|
|
98
|
+
void this.#connect().finally(() => this.#ended.open());
|
|
99
|
+
}
|
|
100
|
+
async #connect() {
|
|
101
|
+
const supervision = this.#supervision;
|
|
102
|
+
let connection;
|
|
103
|
+
try {
|
|
104
|
+
connection = await Promise.try(() => supervision.connector.connect(this.#abort.signal));
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (!supervision.isCurrent(this))
|
|
108
|
+
return;
|
|
109
|
+
supervision.become(new Idle(supervision));
|
|
110
|
+
supervision.events.emit('failed', error);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!supervision.isCurrent(this)) {
|
|
114
|
+
void connection?.close();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
supervision.become(connection
|
|
118
|
+
? new Connected(supervision, connection)
|
|
119
|
+
: new Unavailable(supervision));
|
|
120
|
+
}
|
|
121
|
+
open() { }
|
|
122
|
+
send() {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
reference() { }
|
|
126
|
+
async close() {
|
|
127
|
+
this.#supervision.become(new Closed());
|
|
128
|
+
this.#abort.abort();
|
|
129
|
+
await this.#ended.wait();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
class Connected {
|
|
133
|
+
status = 'connected';
|
|
134
|
+
#supervision;
|
|
135
|
+
#connection;
|
|
136
|
+
constructor(supervision, connection) {
|
|
137
|
+
this.#supervision = supervision;
|
|
138
|
+
this.#connection = connection;
|
|
139
|
+
}
|
|
140
|
+
enter() {
|
|
141
|
+
const supervision = this.#supervision;
|
|
142
|
+
this.#connection.on('message', (message) => {
|
|
143
|
+
if (supervision.isCurrent(this))
|
|
144
|
+
supervision.events.emit('message', message);
|
|
145
|
+
});
|
|
146
|
+
this.#connection.once('close', () => this.#lose());
|
|
147
|
+
this.reference();
|
|
148
|
+
supervision.events.emit('connected');
|
|
149
|
+
}
|
|
150
|
+
open() { }
|
|
151
|
+
/** The connection may report its loss while it sends, so the state is checked after the call. */
|
|
152
|
+
send(message) {
|
|
153
|
+
this.#connection.send(message).catch(() => this.#lose());
|
|
154
|
+
return this.#supervision.isCurrent(this);
|
|
155
|
+
}
|
|
156
|
+
reference() {
|
|
157
|
+
this.#supervision.reference(this.#connection);
|
|
158
|
+
}
|
|
159
|
+
async close() {
|
|
160
|
+
this.#supervision.become(new Closed());
|
|
161
|
+
await this.#connection.close();
|
|
162
|
+
}
|
|
163
|
+
/** A close event and a failed send can both report one loss; only the first counts. */
|
|
164
|
+
#lose() {
|
|
165
|
+
const supervision = this.#supervision;
|
|
166
|
+
if (!supervision.isCurrent(this))
|
|
167
|
+
return;
|
|
168
|
+
void this.#connection.close();
|
|
169
|
+
// Leave this state before the listener hears of the loss, so its sends wait for the replacement.
|
|
170
|
+
supervision.become(new Connecting(supervision));
|
|
171
|
+
supervision.events.emit('disconnected');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
class Unavailable {
|
|
175
|
+
status = 'unavailable';
|
|
176
|
+
#supervision;
|
|
177
|
+
constructor(supervision) {
|
|
178
|
+
this.#supervision = supervision;
|
|
179
|
+
}
|
|
180
|
+
enter() {
|
|
181
|
+
this.#supervision.events.emit('unavailable');
|
|
182
|
+
}
|
|
183
|
+
open() { }
|
|
184
|
+
send() {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
reference() { }
|
|
188
|
+
async close() {
|
|
189
|
+
this.#supervision.become(new Closed());
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
class Closed {
|
|
193
|
+
status = 'closed';
|
|
194
|
+
enter() { }
|
|
195
|
+
open() { }
|
|
196
|
+
send() {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
reference() { }
|
|
200
|
+
async close() { }
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=connection-supervisor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-supervisor.js","sourceRoot":"","sources":["../../src/connection/connection-supervisor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,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,CAAC;IACjC,CAAC;IAED,uFAAuF;IACvF,KAAK;QACH,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC;YAAE,OAAO;QACzC,KAAK,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QAC9B,iGAAiG;QACjG,WAAW,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;QAChD,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,WAAW;IACN,MAAM,GAAG,aAAa,CAAC;IACvB,YAAY,CAAwB;IAE7C,YAAY,WAAkC;QAC5C,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,KAAI,CAAC;IAET,IAAI;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,SAAS,KAAI,CAAC;IAEd,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;CACF;AAED,MAAM,MAAM;IACD,MAAM,GAAG,QAAQ,CAAC;IAE3B,KAAK,KAAI,CAAC;IAEV,IAAI,KAAI,CAAC;IAET,IAAI;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,SAAS,KAAI,CAAC;IAEd,KAAK,CAAC,KAAK,KAAI,CAAC;CACjB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { EventEmitter } from 'node:events';
|
|
2
|
+
export interface ConnectionEvents {
|
|
3
|
+
/** Unchecked: the protocol owner that listens checks each message before it reads it. */
|
|
4
|
+
message: [message: unknown];
|
|
5
|
+
/** Emitted once, when the peer is gone. */
|
|
6
|
+
close: [];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A message channel to one peer. Adapters wrap IPC channels and sockets.
|
|
10
|
+
* Subscribe in the task that receives the connection: a message that arrives
|
|
11
|
+
* while nobody listens is not kept.
|
|
12
|
+
*/
|
|
13
|
+
export interface Connection<Outgoing> extends EventEmitter<ConnectionEvents> {
|
|
14
|
+
/**
|
|
15
|
+
* Rejects when the message cannot be delivered because the peer is gone.
|
|
16
|
+
* The adapters that a coordinator answers through reject with
|
|
17
|
+
* `ConnectionClosedError` then.
|
|
18
|
+
*/
|
|
19
|
+
send(message: Outgoing): Promise<void>;
|
|
20
|
+
/** Keeps the process alive while its owner waits for a message. */
|
|
21
|
+
ref(): void;
|
|
22
|
+
/** Lets the process exit; messages and closure are still reported while it runs. */
|
|
23
|
+
unref(): void;
|
|
24
|
+
/** Resolves once this end let the connection go. */
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/connection/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,yFAAyF;IACzF,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5B,2CAA2C;IAC3C,KAAK,EAAE,EAAE,CAAC;CACX;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU,CAAC,QAAQ,CAAE,SAAQ,YAAY,CAAC,gBAAgB,CAAC;IAC1E;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,mEAAmE;IACnE,GAAG,IAAI,IAAI,CAAC;IACZ,oFAAoF;IACpF,KAAK,IAAI,IAAI,CAAC;IACd,oDAAoD;IACpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection/connection.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Connection } from './connection.ts';
|
|
2
|
+
/** Decides how a client reaches its peer, and whether it can again after losing it. */
|
|
3
|
+
export interface Connector<Outgoing> {
|
|
4
|
+
/**
|
|
5
|
+
* Resolves to `undefined` when the peer is gone for good and nothing can
|
|
6
|
+
* replace it. Rejects when this attempt failed and a later one may succeed.
|
|
7
|
+
* Once `signal` aborts, rejects with its reason and leaves nothing started.
|
|
8
|
+
*/
|
|
9
|
+
connect(signal: AbortSignal): Promise<Connection<Outgoing> | undefined>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=connector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/connection/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,uFAAuF;AACvF,MAAM,WAAW,SAAS,CAAC,QAAQ;IACjC;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,CAAC;CACzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector.js","sourceRoot":"","sources":["../../src/connection/connector.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A call that gets no answer, because the connection it went out on is gone:
|
|
3
|
+
* the peer stopped, or this client closed. The peer may have run the call, so
|
|
4
|
+
* the caller decides whether to make it again (StreamJsonRpc's
|
|
5
|
+
* `ConnectionLostException`).
|
|
6
|
+
*/
|
|
7
|
+
export declare class ConnectionLostError extends Error {
|
|
8
|
+
constructor(options?: ErrorOptions);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=connection-lost-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-lost-error.d.ts","sourceRoot":"","sources":["../../src/error/connection-lost-error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAO,CAAC,EAAE,YAAY,EAGjC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A call that gets no answer, because the connection it went out on is gone:
|
|
3
|
+
* the peer stopped, or this client closed. The peer may have run the call, so
|
|
4
|
+
* the caller decides whether to make it again (StreamJsonRpc's
|
|
5
|
+
* `ConnectionLostException`).
|
|
6
|
+
*/
|
|
7
|
+
export class ConnectionLostError extends Error {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super('The connection was lost before the call was answered.', options);
|
|
10
|
+
this.name = 'ConnectionLostError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=connection-lost-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-lost-error.js","sourceRoot":"","sources":["../../src/error/connection-lost-error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAsB;QAChC,KAAK,CAAC,uDAAuD,EAAE,OAAO,CAAC,CAAC;QACxE,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** A class whose instances the codec rebuilds. Its constructor never runs on the decoding end. */
|
|
2
|
+
export type ErrorClass = abstract new (...args: never[]) => Error;
|
|
3
|
+
/** An error as it crosses: its class, its text and its own fields; `cause` crosses the same way. */
|
|
4
|
+
export interface EncodedError {
|
|
5
|
+
/** The name of the error's own class: the `name` of its constructor. */
|
|
6
|
+
name: string;
|
|
7
|
+
message: string;
|
|
8
|
+
stack: string | undefined;
|
|
9
|
+
/** The error's own properties other than `message`, `stack` and `cause`, such as `code`. */
|
|
10
|
+
fields: Record<string, unknown>;
|
|
11
|
+
cause?: EncodedReason;
|
|
12
|
+
}
|
|
13
|
+
/** A thrown value that is not an error crosses as it is. */
|
|
14
|
+
export interface EncodedValue {
|
|
15
|
+
value: unknown;
|
|
16
|
+
}
|
|
17
|
+
export type EncodedReason = EncodedError | EncodedValue;
|
|
18
|
+
/**
|
|
19
|
+
* Turns a thrown value into data that a message channel or a JSON line can
|
|
20
|
+
* carry, and back. `structuredClone` and `v8.serialize` rebuild every error as
|
|
21
|
+
* its native base class and drop own fields such as `code`; this codec keeps
|
|
22
|
+
* them. It rebuilds an error of a listed class, or of a native class, as an
|
|
23
|
+
* instance of that class, with the peer's message, stack, cause and own
|
|
24
|
+
* fields. It never runs the class's constructor, so a constructor's arguments
|
|
25
|
+
* and side effects do not matter. An error of any other class arrives as a
|
|
26
|
+
* `ServerError` that keeps the peer's name and fields.
|
|
27
|
+
*/
|
|
28
|
+
export declare class ErrorCodec {
|
|
29
|
+
#private;
|
|
30
|
+
/** Throws a `RangeError` when two classes have one name, because the name is what crosses. */
|
|
31
|
+
constructor(classes: readonly ErrorClass[]);
|
|
32
|
+
encode(reason: unknown): EncodedReason;
|
|
33
|
+
decode(encoded: EncodedReason): unknown;
|
|
34
|
+
}
|
|
35
|
+
/** Whether `value` has the shape that `encode` gives, checked before a received reason is decoded. */
|
|
36
|
+
export declare function isEncodedReason(value: unknown): value is EncodedReason;
|
|
37
|
+
//# sourceMappingURL=error-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codec.d.ts","sourceRoot":"","sources":["../../src/error/error-codec.ts"],"names":[],"mappings":"AAGA,kGAAkG;AAClG,MAAM,MAAM,UAAU,GAAG,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,CAAC;AAElE,oGAAoG;AACpG,MAAM,WAAW,YAAY;IAC3B,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,4FAA4F;IAC5F,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,4DAA4D;AAC5D,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,YAAY,CAAC;AAoBxD;;;;;;;;;GASG;AACH,qBAAa,UAAU;;IAGrB,8FAA8F;IAC9F,YAAY,OAAO,EAAE,SAAS,UAAU,EAAE,EAWzC;IAED,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,CAgBrC;IAED,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CActC;CACF;AAED,sGAAsG;AACtG,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAUtE"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { isRecord } from '../shared/is-record.js';
|
|
2
|
+
import { ServerError } from './server-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* The native error classes, which the structured clone of HTML keeps by name
|
|
5
|
+
* (HTML, "StructuredSerializeInternal", step for [[ErrorData]]). The codec
|
|
6
|
+
* knows them without a list.
|
|
7
|
+
*/
|
|
8
|
+
const natives = [
|
|
9
|
+
Error,
|
|
10
|
+
EvalError,
|
|
11
|
+
RangeError,
|
|
12
|
+
ReferenceError,
|
|
13
|
+
SyntaxError,
|
|
14
|
+
TypeError,
|
|
15
|
+
URIError,
|
|
16
|
+
];
|
|
17
|
+
/** The own properties that the codec carries apart from `fields`. */
|
|
18
|
+
const carried = new Set(['message', 'stack', 'cause']);
|
|
19
|
+
/**
|
|
20
|
+
* Turns a thrown value into data that a message channel or a JSON line can
|
|
21
|
+
* carry, and back. `structuredClone` and `v8.serialize` rebuild every error as
|
|
22
|
+
* its native base class and drop own fields such as `code`; this codec keeps
|
|
23
|
+
* them. It rebuilds an error of a listed class, or of a native class, as an
|
|
24
|
+
* instance of that class, with the peer's message, stack, cause and own
|
|
25
|
+
* fields. It never runs the class's constructor, so a constructor's arguments
|
|
26
|
+
* and side effects do not matter. An error of any other class arrives as a
|
|
27
|
+
* `ServerError` that keeps the peer's name and fields.
|
|
28
|
+
*/
|
|
29
|
+
export class ErrorCodec {
|
|
30
|
+
#classes = new Map();
|
|
31
|
+
/** Throws a `RangeError` when two classes have one name, because the name is what crosses. */
|
|
32
|
+
constructor(classes) {
|
|
33
|
+
for (const errorClass of [...natives, ...classes]) {
|
|
34
|
+
const known = this.#classes.get(errorClass.name);
|
|
35
|
+
if (known === errorClass)
|
|
36
|
+
continue;
|
|
37
|
+
if (known) {
|
|
38
|
+
throw new RangeError(`Two error classes are named "${errorClass.name}": the codec tells them apart by name only.`);
|
|
39
|
+
}
|
|
40
|
+
this.#classes.set(errorClass.name, errorClass);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
encode(reason) {
|
|
44
|
+
if (!Error.isError(reason))
|
|
45
|
+
return { value: reason };
|
|
46
|
+
const fields = {};
|
|
47
|
+
for (const key of Object.getOwnPropertyNames(reason)) {
|
|
48
|
+
if (!carried.has(key))
|
|
49
|
+
fields[key] = Reflect.get(reason, key);
|
|
50
|
+
}
|
|
51
|
+
const encoded = {
|
|
52
|
+
name: classNameOf(reason),
|
|
53
|
+
message: reason.message,
|
|
54
|
+
stack: reason.stack,
|
|
55
|
+
fields,
|
|
56
|
+
};
|
|
57
|
+
if (Object.hasOwn(reason, 'cause')) {
|
|
58
|
+
encoded.cause = this.encode(reason.cause);
|
|
59
|
+
}
|
|
60
|
+
return encoded;
|
|
61
|
+
}
|
|
62
|
+
decode(encoded) {
|
|
63
|
+
if ('value' in encoded)
|
|
64
|
+
return encoded.value;
|
|
65
|
+
const known = this.#classes.get(encoded.name);
|
|
66
|
+
const error = known
|
|
67
|
+
? Reflect.construct(nativeBaseOf(known), [encoded.message], known)
|
|
68
|
+
: Reflect.construct(Error, [encoded.message], ServerError);
|
|
69
|
+
if (!known)
|
|
70
|
+
define(error, 'name', encoded.name, false);
|
|
71
|
+
define(error, 'stack', encoded.stack, false);
|
|
72
|
+
if (encoded.cause)
|
|
73
|
+
define(error, 'cause', this.decode(encoded.cause), false);
|
|
74
|
+
for (const [key, value] of Object.entries(encoded.fields)) {
|
|
75
|
+
define(error, key, value, true);
|
|
76
|
+
}
|
|
77
|
+
return error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Whether `value` has the shape that `encode` gives, checked before a received reason is decoded. */
|
|
81
|
+
export function isEncodedReason(value) {
|
|
82
|
+
if (!isRecord(value))
|
|
83
|
+
return false;
|
|
84
|
+
if (Object.hasOwn(value, 'value'))
|
|
85
|
+
return true;
|
|
86
|
+
return (typeof value.name === 'string' &&
|
|
87
|
+
typeof value.message === 'string' &&
|
|
88
|
+
(value.stack === undefined || typeof value.stack === 'string') &&
|
|
89
|
+
isRecord(value.fields) &&
|
|
90
|
+
(value.cause === undefined || isEncodedReason(value.cause)));
|
|
91
|
+
}
|
|
92
|
+
/** The name of the error's own class, or its `name` when its class has none. */
|
|
93
|
+
function classNameOf(error) {
|
|
94
|
+
const prototype = Object.getPrototypeOf(error);
|
|
95
|
+
const constructor = isRecord(prototype)
|
|
96
|
+
? prototype.constructor
|
|
97
|
+
: undefined;
|
|
98
|
+
return typeof constructor === 'function' && constructor.name !== ''
|
|
99
|
+
? constructor.name
|
|
100
|
+
: error.name;
|
|
101
|
+
}
|
|
102
|
+
/** The native class that `errorClass` extends, so the rebuilt error is a native error, as `Error.isError` checks. */
|
|
103
|
+
function nativeBaseOf(errorClass) {
|
|
104
|
+
for (let current = errorClass; typeof current === 'function'; current = Object.getPrototypeOf(current)) {
|
|
105
|
+
const native = natives.find((candidate) => candidate === current);
|
|
106
|
+
if (native)
|
|
107
|
+
return native;
|
|
108
|
+
}
|
|
109
|
+
return Error;
|
|
110
|
+
}
|
|
111
|
+
/** An own data property, also for a key such as `__proto__`, which an assignment would not make. */
|
|
112
|
+
function define(error, key, value, enumerable) {
|
|
113
|
+
Object.defineProperty(error, key, {
|
|
114
|
+
value,
|
|
115
|
+
enumerable,
|
|
116
|
+
writable: true,
|
|
117
|
+
configurable: true,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=error-codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codec.js","sourceRoot":"","sources":["../../src/error/error-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAuBhD;;;;GAIG;AACH,MAAM,OAAO,GAA0B;IACrC,KAAK;IACL,SAAS;IACT,UAAU;IACV,cAAc;IACd,WAAW;IACX,SAAS;IACT,QAAQ;CACT,CAAC;AAEF,qEAAqE;AACrE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAEvD;;;;;;;;;GASG;AACH,MAAM,OAAO,UAAU;IACZ,QAAQ,GAAG,IAAI,GAAG,EAAsB,CAAC;IAElD,8FAA8F;IAC9F,YAAY,OAA8B;QACxC,KAAK,MAAM,UAAU,IAAI,CAAC,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;YAClD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YACjD,IAAI,KAAK,KAAK,UAAU;gBAAE,SAAS;YACnC,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,IAAI,UAAU,CAClB,gCAAgC,UAAU,CA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AC,CAC5D,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,SAAS,WAAW,CAAC,KAAY;IAC/B,MAAM,SAAS,GAAY,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACxD,MAAM,WAAW,GAAY,QAAQ,CAAC,SAAS,CAAC;QAC9C,CAAC,CAAC,SAAS,CAAC,WAAW;QACvB,CAAC,CAAC,SAAS,CAAC;IACd,OAAO,OAAO,WAAW,KAAK,UAAU,IAAI,WAAW,CAAC,IAAI,KAAK,EAAE;QACjE,CAAC,CAAC,WAAW,CAAC,IAAI;QAClB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;AACjB,CAAC;AAED,qHAAqH;AACrH,SAAS,YAAY,CAAC,UAAsB;IAC1C,KACE,IAAI,OAAO,GAAY,UAAU,EACjC,OAAO,OAAO,KAAK,UAAU,EAC7B,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EACxC,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,OAAO,CAAC,CAAC;QAClE,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;IAC5B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,oGAAoG;AACpG,SAAS,MAAM,CACb,KAAY,EACZ,GAAW,EACX,KAAc,EACd,UAAmB;IAEnB,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE;QAChC,KAAK;QACL,UAAU;QACV,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An error that the peer threw, of a class that this end's `ErrorCodec` does
|
|
3
|
+
* not list. It keeps the peer's `name`, `message`, `stack` and own fields, as
|
|
4
|
+
* Go's `rpc.ServerError` keeps the text of a remote error.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ServerError extends Error {
|
|
7
|
+
constructor(name: string, message: string);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=server-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-error.d.ts","sourceRoot":"","sources":["../../src/error/server-error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAGxC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An error that the peer threw, of a class that this end's `ErrorCodec` does
|
|
3
|
+
* not list. It keeps the peer's `name`, `message`, `stack` and own fields, as
|
|
4
|
+
* Go's `rpc.ServerError` keeps the text of a remote error.
|
|
5
|
+
*/
|
|
6
|
+
export class ServerError extends Error {
|
|
7
|
+
constructor(name, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = name;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=server-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-error.js","sourceRoot":"","sources":["../../src/error/server-error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** A notification's method failed on this end. Nothing answers a notification, so the failure goes to the process. */
|
|
2
|
+
export declare class ServerWarning extends Error {
|
|
3
|
+
readonly code = "ZUKHRUF_RPC_NOTIFICATION_FAILED";
|
|
4
|
+
readonly detail: string;
|
|
5
|
+
constructor(failure: unknown, { method }: {
|
|
6
|
+
method: string;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=server-warning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-warning.d.ts","sourceRoot":"","sources":["../../src/error/server-warning.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,qCAAqC;IAClD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,YAAY,OAAO,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,EAO3D;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A notification's method failed on this end. Nothing answers a notification, so the failure goes to the process. */
|
|
2
|
+
export class ServerWarning extends Error {
|
|
3
|
+
code = 'ZUKHRUF_RPC_NOTIFICATION_FAILED';
|
|
4
|
+
detail;
|
|
5
|
+
constructor(failure, { method }) {
|
|
6
|
+
super(`A notification's method failed, and the server goes on: ${Error.isError(failure) ? failure.message : String(failure)}`, { cause: failure });
|
|
7
|
+
this.name = 'ServerWarning';
|
|
8
|
+
this.detail = `method: ${method}`;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=server-warning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-warning.js","sourceRoot":"","sources":["../../src/error/server-warning.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,GAAG,iCAAiC,CAAC;IACzC,MAAM,CAAS;IAExB,YAAY,OAAgB,EAAE,EAAE,MAAM,EAAsB;QAC1D,KAAK,CACH,2DAA2D,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EACvH,EAAE,KAAK,EAAE,OAAO,EAAE,CACnB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,WAAW,MAAM,EAAE,CAAC;IACpC,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { ChildProcessConnection } from './channel/child-process-connection.ts';
|
|
2
|
+
export { type ChannelOptions } from './channel/envelope.ts';
|
|
3
|
+
export { ParentPortConnection } from './channel/parent-port-connection.ts';
|
|
4
|
+
export { ProcessChannelConnection } from './channel/process-channel-connection.ts';
|
|
5
|
+
export { WorkerConnection } from './channel/worker-connection.ts';
|
|
6
|
+
export { type CallOptions, Client, type ClientOptions } from './call/client.ts';
|
|
7
|
+
export { type AnswerChecks, type Methods, type ParamChecks, } from './call/methods.ts';
|
|
8
|
+
export { type LostCallPolicy, PendingCalls, type Settler, type TakenCall, } from './call/pending-calls.ts';
|
|
9
|
+
export { type RpcMessage, type RpcNotification, type RpcRequest, type RpcResponse, } from './call/rpc-message.ts';
|
|
10
|
+
export { Server, type ServerOptions } from './call/server.ts';
|
|
11
|
+
export { type Connection, type ConnectionEvents, } from './connection/connection.ts';
|
|
12
|
+
export { ConnectionClosedError } from './connection/connection-closed-error.ts';
|
|
13
|
+
export { ConnectionSupervisor, type SupervisorEvents, type SupervisorStatus, } from './connection/connection-supervisor.ts';
|
|
14
|
+
export { type Connector } from './connection/connector.ts';
|
|
15
|
+
export { ConnectionLostError } from './error/connection-lost-error.ts';
|
|
16
|
+
export { type EncodedError, type EncodedReason, type EncodedValue, type ErrorClass, ErrorCodec, } from './error/error-codec.ts';
|
|
17
|
+
export { ServerError } from './error/server-error.ts';
|
|
18
|
+
export { ServerWarning } from './error/server-warning.ts';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;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
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { ChildProcessConnection } from './channel/child-process-connection.js';
|
|
2
|
+
export {} from './channel/envelope.js';
|
|
3
|
+
export { ParentPortConnection } from './channel/parent-port-connection.js';
|
|
4
|
+
export { ProcessChannelConnection } from './channel/process-channel-connection.js';
|
|
5
|
+
export { WorkerConnection } from './channel/worker-connection.js';
|
|
6
|
+
export { Client } from './call/client.js';
|
|
7
|
+
export {} from './call/methods.js';
|
|
8
|
+
export { PendingCalls, } from './call/pending-calls.js';
|
|
9
|
+
export {} from './call/rpc-message.js';
|
|
10
|
+
export { Server } from './call/server.js';
|
|
11
|
+
export {} from './connection/connection.js';
|
|
12
|
+
export { ConnectionClosedError } from './connection/connection-closed-error.js';
|
|
13
|
+
export { ConnectionSupervisor, } from './connection/connection-supervisor.js';
|
|
14
|
+
export {} from './connection/connector.js';
|
|
15
|
+
export { ConnectionLostError } from './error/connection-lost-error.js';
|
|
16
|
+
export { ErrorCodec, } from './error/error-codec.js';
|
|
17
|
+
export { ServerError } from './error/server-error.js';
|
|
18
|
+
export { ServerWarning } from './error/server-warning.js';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAuB,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAoB,MAAM,EAAsB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAIN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,YAAY,GAGb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAKN,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAsB,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAGN,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAChF,OAAO,EACL,oBAAoB,GAGrB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAkB,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAKL,UAAU,GACX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-record.d.ts","sourceRoot":"","sources":["../../src/shared/is-record.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,eAAO,MAAM,QAAQ,UACZ,OAAO,KACb,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-record.js","sourceRoot":"","sources":["../../src/shared/is-record.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,KAAc,EAC8B,EAAE,CAC9C,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC"}
|