@replit/river 0.17.3 → 0.18.0
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/README.md +4 -3
- package/dist/{chunk-7WY3Z5ZN.js → chunk-CLY7AQ25.js} +169 -95
- package/dist/{chunk-4C2OXQJB.js → chunk-TIFNW5GQ.js} +62 -65
- package/dist/{chunk-F3LFO3GU.js → chunk-UEKU6XRG.js} +1 -1
- package/dist/chunk-YITXOAPA.js +72 -0
- package/dist/{chunk-Q7OSVPZ5.js → chunk-ZPPKYJI7.js} +1 -1
- package/dist/{connection-713c8c66.d.ts → connection-32bf6608.d.ts} +1 -1
- package/dist/{connection-b79329de.d.ts → connection-df5f32ee.d.ts} +1 -1
- package/dist/{index-80f87385.d.ts → index-314e676a.d.ts} +4 -86
- package/dist/index-6118cd48.d.ts +117 -0
- package/dist/logging/index.cjs +63 -27
- package/dist/logging/index.d.cts +2 -34
- package/dist/logging/index.d.ts +2 -34
- package/dist/logging/index.js +7 -7
- package/dist/{procedures-79a5f07e.d.ts → procedures-74a10937.d.ts} +4 -3
- package/dist/router/index.cjs +63 -66
- package/dist/router/index.d.cts +43 -42
- package/dist/router/index.d.ts +43 -42
- package/dist/router/index.js +2 -2
- package/dist/transport/impls/uds/client.cjs +152 -84
- package/dist/transport/impls/uds/client.d.cts +3 -2
- package/dist/transport/impls/uds/client.d.ts +3 -2
- package/dist/transport/impls/uds/client.js +7 -4
- package/dist/transport/impls/uds/server.cjs +116 -65
- package/dist/transport/impls/uds/server.d.cts +3 -2
- package/dist/transport/impls/uds/server.d.ts +3 -2
- package/dist/transport/impls/uds/server.js +3 -3
- package/dist/transport/impls/ws/client.cjs +156 -87
- package/dist/transport/impls/ws/client.d.cts +3 -2
- package/dist/transport/impls/ws/client.d.ts +3 -2
- package/dist/transport/impls/ws/client.js +11 -7
- package/dist/transport/impls/ws/server.cjs +116 -65
- package/dist/transport/impls/ws/server.d.cts +4 -3
- package/dist/transport/impls/ws/server.d.ts +4 -3
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/index.cjs +170 -96
- package/dist/transport/index.d.cts +2 -1
- package/dist/transport/index.d.ts +2 -1
- package/dist/transport/index.js +2 -2
- package/dist/util/testHelpers.cjs +65 -32
- package/dist/util/testHelpers.d.cts +8 -7
- package/dist/util/testHelpers.d.ts +8 -7
- package/dist/util/testHelpers.js +20 -18
- package/package.json +1 -1
- package/dist/chunk-H4BYJELI.js +0 -37
|
@@ -52,8 +52,8 @@ var import_ws = require("ws");
|
|
|
52
52
|
// transport/transport.ts
|
|
53
53
|
var import_value = require("@sinclair/typebox/value");
|
|
54
54
|
|
|
55
|
-
// logging/
|
|
56
|
-
var log;
|
|
55
|
+
// logging/log.ts
|
|
56
|
+
var log = void 0;
|
|
57
57
|
|
|
58
58
|
// transport/session.ts
|
|
59
59
|
var import_nanoid = require("nanoid");
|
|
@@ -115,6 +115,14 @@ var Session = class {
|
|
|
115
115
|
options.heartbeatIntervalMs
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
|
+
get loggingMetadata() {
|
|
119
|
+
return {
|
|
120
|
+
clientId: this.from,
|
|
121
|
+
connectedTo: this.to,
|
|
122
|
+
sessionId: this.id,
|
|
123
|
+
connId: this.connection?.debugId
|
|
124
|
+
};
|
|
125
|
+
}
|
|
118
126
|
/**
|
|
119
127
|
* Sends a message over the session's connection.
|
|
120
128
|
* If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
|
|
@@ -125,26 +133,37 @@ var Session = class {
|
|
|
125
133
|
*/
|
|
126
134
|
send(msg) {
|
|
127
135
|
const fullMsg = this.constructMsg(msg);
|
|
128
|
-
log?.debug(
|
|
136
|
+
log?.debug(`sending msg`, {
|
|
137
|
+
...this.loggingMetadata,
|
|
138
|
+
fullTransportMessage: fullMsg
|
|
139
|
+
});
|
|
129
140
|
if (this.connection) {
|
|
130
141
|
const ok = this.connection.send(this.codec.toBuffer(fullMsg));
|
|
131
142
|
if (ok)
|
|
132
143
|
return fullMsg.id;
|
|
133
144
|
log?.info(
|
|
134
|
-
|
|
145
|
+
`failed to send msg to ${fullMsg.to}, connection is probably dead`,
|
|
146
|
+
{
|
|
147
|
+
...this.loggingMetadata,
|
|
148
|
+
fullTransportMessage: fullMsg
|
|
149
|
+
}
|
|
135
150
|
);
|
|
136
151
|
} else {
|
|
137
152
|
log?.info(
|
|
138
|
-
|
|
153
|
+
`failed to send msg to ${fullMsg.to}, connection not ready yet`,
|
|
154
|
+
{ ...this.loggingMetadata, fullTransportMessage: fullMsg }
|
|
139
155
|
);
|
|
140
156
|
}
|
|
141
157
|
return fullMsg.id;
|
|
142
158
|
}
|
|
143
159
|
sendHeartbeat() {
|
|
144
|
-
|
|
160
|
+
const misses = this.heartbeatMisses;
|
|
161
|
+
const missDuration = misses * this.options.heartbeatIntervalMs;
|
|
162
|
+
if (misses > this.options.heartbeatsUntilDead) {
|
|
145
163
|
if (this.connection) {
|
|
146
164
|
log?.info(
|
|
147
|
-
|
|
165
|
+
`closing connection to ${this.to} due to inactivity (missed ${misses} heartbeats which is ${missDuration}ms)`,
|
|
166
|
+
this.loggingMetadata
|
|
148
167
|
);
|
|
149
168
|
this.closeStaleConnection();
|
|
150
169
|
}
|
|
@@ -166,26 +185,36 @@ var Session = class {
|
|
|
166
185
|
}
|
|
167
186
|
sendBufferedMessages() {
|
|
168
187
|
if (!this.connection) {
|
|
169
|
-
const msg =
|
|
170
|
-
log?.error(msg);
|
|
188
|
+
const msg = `tried sending buffered messages without a connection (if you hit this code path something is seriously wrong)`;
|
|
189
|
+
log?.error(msg, this.loggingMetadata);
|
|
171
190
|
throw new Error(msg);
|
|
172
191
|
}
|
|
173
192
|
log?.info(
|
|
174
|
-
|
|
193
|
+
`resending ${this.sendBuffer.length} buffered messages`,
|
|
194
|
+
this.loggingMetadata
|
|
175
195
|
);
|
|
176
196
|
for (const msg of this.sendBuffer) {
|
|
177
|
-
log?.debug(
|
|
197
|
+
log?.debug(`resending msg`, {
|
|
198
|
+
...this.loggingMetadata,
|
|
199
|
+
fullTransportMessage: msg
|
|
200
|
+
});
|
|
178
201
|
const ok = this.connection.send(this.codec.toBuffer(msg));
|
|
179
202
|
if (!ok) {
|
|
180
|
-
const
|
|
181
|
-
log?.error(
|
|
182
|
-
|
|
203
|
+
const errMsg = `failed to send buffered message to ${this.to} (if you hit this code path something is seriously wrong)`;
|
|
204
|
+
log?.error(errMsg, {
|
|
205
|
+
...this.loggingMetadata,
|
|
206
|
+
fullTransportMessage: msg
|
|
207
|
+
});
|
|
208
|
+
throw new Error(errMsg);
|
|
183
209
|
}
|
|
184
210
|
}
|
|
185
211
|
}
|
|
186
212
|
updateBookkeeping(ack, seq) {
|
|
187
213
|
if (seq + 1 < this.ack) {
|
|
188
|
-
log?.error(
|
|
214
|
+
log?.error(
|
|
215
|
+
`received stale seq ${seq} + 1 < ${this.ack}`,
|
|
216
|
+
this.loggingMetadata
|
|
217
|
+
);
|
|
189
218
|
return;
|
|
190
219
|
}
|
|
191
220
|
this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq >= ack);
|
|
@@ -195,7 +224,8 @@ var Session = class {
|
|
|
195
224
|
if (this.connection === void 0 || this.connection === conn)
|
|
196
225
|
return;
|
|
197
226
|
log?.info(
|
|
198
|
-
|
|
227
|
+
`closing old inner connection from session to ${this.to}`,
|
|
228
|
+
this.loggingMetadata
|
|
199
229
|
);
|
|
200
230
|
this.connection.close();
|
|
201
231
|
this.connection = void 0;
|
|
@@ -207,7 +237,8 @@ var Session = class {
|
|
|
207
237
|
}
|
|
208
238
|
beginGrace(cb) {
|
|
209
239
|
log?.info(
|
|
210
|
-
|
|
240
|
+
`starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
|
|
241
|
+
this.loggingMetadata
|
|
211
242
|
);
|
|
212
243
|
this.disconnectionGrace = setTimeout(() => {
|
|
213
244
|
this.close();
|
|
@@ -696,28 +727,30 @@ function catchProcError(err) {
|
|
|
696
727
|
};
|
|
697
728
|
}
|
|
698
729
|
var testingSessionOptions = defaultTransportOptions;
|
|
699
|
-
function
|
|
700
|
-
|
|
730
|
+
function dummySession() {
|
|
731
|
+
return new Session(
|
|
701
732
|
void 0,
|
|
702
733
|
"client",
|
|
703
|
-
"
|
|
734
|
+
"server",
|
|
704
735
|
testingSessionOptions
|
|
705
736
|
);
|
|
737
|
+
}
|
|
738
|
+
function dummyCtx(state, session, extendedContext) {
|
|
706
739
|
return {
|
|
707
740
|
...extendedContext,
|
|
708
741
|
state,
|
|
709
|
-
to:
|
|
710
|
-
from:
|
|
742
|
+
to: session.to,
|
|
743
|
+
from: session.from,
|
|
711
744
|
streamId: (0, import_nanoid2.nanoid)(),
|
|
712
745
|
session
|
|
713
746
|
};
|
|
714
747
|
}
|
|
715
|
-
function asClientRpc(state, proc, extendedContext) {
|
|
748
|
+
function asClientRpc(state, proc, extendedContext, session = dummySession()) {
|
|
716
749
|
return async (msg) => {
|
|
717
|
-
return await proc.handler(dummyCtx(state, extendedContext), msg).catch(catchProcError);
|
|
750
|
+
return await proc.handler(dummyCtx(state, session, extendedContext), msg).catch(catchProcError);
|
|
718
751
|
};
|
|
719
752
|
}
|
|
720
|
-
function asClientStream(state, proc, init, extendedContext) {
|
|
753
|
+
function asClientStream(state, proc, init, extendedContext, session = dummySession()) {
|
|
721
754
|
const input = pushable({ objectMode: true });
|
|
722
755
|
const output = pushable({
|
|
723
756
|
objectMode: true
|
|
@@ -725,34 +758,34 @@ function asClientStream(state, proc, init, extendedContext) {
|
|
|
725
758
|
void (async () => {
|
|
726
759
|
if (init) {
|
|
727
760
|
const _proc = proc;
|
|
728
|
-
await _proc.handler(dummyCtx(state, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err)));
|
|
761
|
+
await _proc.handler(dummyCtx(state, session, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err)));
|
|
729
762
|
} else {
|
|
730
763
|
const _proc = proc;
|
|
731
|
-
await _proc.handler(dummyCtx(state, extendedContext), input, output).catch((err) => output.push(catchProcError(err)));
|
|
764
|
+
await _proc.handler(dummyCtx(state, session, extendedContext), input, output).catch((err) => output.push(catchProcError(err)));
|
|
732
765
|
}
|
|
733
766
|
})();
|
|
734
767
|
return [input, output];
|
|
735
768
|
}
|
|
736
|
-
function asClientSubscription(state, proc, extendedContext) {
|
|
769
|
+
function asClientSubscription(state, proc, extendedContext, session = dummySession()) {
|
|
737
770
|
const output = pushable({
|
|
738
771
|
objectMode: true
|
|
739
772
|
});
|
|
740
773
|
return (msg) => {
|
|
741
774
|
void (async () => {
|
|
742
|
-
return await proc.handler(dummyCtx(state, extendedContext), msg, output).catch((err) => output.push(catchProcError(err)));
|
|
775
|
+
return await proc.handler(dummyCtx(state, session, extendedContext), msg, output).catch((err) => output.push(catchProcError(err)));
|
|
743
776
|
})();
|
|
744
777
|
return output;
|
|
745
778
|
};
|
|
746
779
|
}
|
|
747
|
-
function asClientUpload(state, proc, init, extendedContext) {
|
|
780
|
+
function asClientUpload(state, proc, init, extendedContext, session = dummySession()) {
|
|
748
781
|
const input = pushable({ objectMode: true });
|
|
749
782
|
if (init) {
|
|
750
783
|
const _proc = proc;
|
|
751
|
-
const result = _proc.handler(dummyCtx(state, extendedContext), init, input).catch(catchProcError);
|
|
784
|
+
const result = _proc.handler(dummyCtx(state, session, extendedContext), init, input).catch(catchProcError);
|
|
752
785
|
return [input, result];
|
|
753
786
|
} else {
|
|
754
787
|
const _proc = proc;
|
|
755
|
-
const result = _proc.handler(dummyCtx(state, extendedContext), input).catch(catchProcError);
|
|
788
|
+
const result = _proc.handler(dummyCtx(state, session, extendedContext), input).catch(catchProcError);
|
|
756
789
|
return [input, result];
|
|
757
790
|
}
|
|
758
791
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Static } from '@sinclair/typebox';
|
|
2
|
-
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema, d as ProcedureResult } from '../procedures-
|
|
3
|
-
import {
|
|
2
|
+
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema, d as ProcedureResult } from '../procedures-74a10937.js';
|
|
3
|
+
import { T as Transport, C as Connection, S as SessionOptions, a as Session } from '../index-314e676a.js';
|
|
4
4
|
import * as it_pushable from 'it-pushable';
|
|
5
|
+
import { P as PartialTransportMessage, O as OpaqueTransportMessage } from '../index-6118cd48.js';
|
|
5
6
|
import WebSocket from 'isomorphic-ws';
|
|
6
7
|
import http from 'node:http';
|
|
7
8
|
import net from 'node:net';
|
|
@@ -36,7 +37,7 @@ declare function createLocalWebSocketClient(port: number): WebSocket;
|
|
|
36
37
|
* @returns A promise that resolves to the next value from the iterator.
|
|
37
38
|
*/
|
|
38
39
|
declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<T>;
|
|
39
|
-
declare function payloadToTransportMessage<Payload
|
|
40
|
+
declare function payloadToTransportMessage<Payload>(payload: Payload): PartialTransportMessage<Payload>;
|
|
40
41
|
declare function createDummyTransportMessage(): PartialTransportMessage<{
|
|
41
42
|
msg: string;
|
|
42
43
|
test: number;
|
|
@@ -49,10 +50,10 @@ declare function createDummyTransportMessage(): PartialTransportMessage<{
|
|
|
49
50
|
*/
|
|
50
51
|
declare function waitForMessage(t: Transport<Connection>, filter?: (msg: OpaqueTransportMessage) => boolean, rejectMismatch?: boolean): Promise<unknown>;
|
|
51
52
|
declare const testingSessionOptions: SessionOptions;
|
|
52
|
-
declare function asClientRpc<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
|
|
53
|
-
declare function asClientStream<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>];
|
|
54
|
-
declare function asClientSubscription<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>;
|
|
55
|
-
declare function asClientUpload<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
|
|
53
|
+
declare function asClientRpc<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
|
|
54
|
+
declare function asClientStream<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>];
|
|
55
|
+
declare function asClientSubscription<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): (msg: Static<I>) => it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>;
|
|
56
|
+
declare function asClientUpload<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
|
|
56
57
|
ok: boolean;
|
|
57
58
|
payload: {
|
|
58
59
|
code: string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Static } from '@sinclair/typebox';
|
|
2
|
-
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema, d as ProcedureResult } from '../procedures-
|
|
3
|
-
import {
|
|
2
|
+
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema, d as ProcedureResult } from '../procedures-74a10937.js';
|
|
3
|
+
import { T as Transport, C as Connection, S as SessionOptions, a as Session } from '../index-314e676a.js';
|
|
4
4
|
import * as it_pushable from 'it-pushable';
|
|
5
|
+
import { P as PartialTransportMessage, O as OpaqueTransportMessage } from '../index-6118cd48.js';
|
|
5
6
|
import WebSocket from 'isomorphic-ws';
|
|
6
7
|
import http from 'node:http';
|
|
7
8
|
import net from 'node:net';
|
|
@@ -36,7 +37,7 @@ declare function createLocalWebSocketClient(port: number): WebSocket;
|
|
|
36
37
|
* @returns A promise that resolves to the next value from the iterator.
|
|
37
38
|
*/
|
|
38
39
|
declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<T>;
|
|
39
|
-
declare function payloadToTransportMessage<Payload
|
|
40
|
+
declare function payloadToTransportMessage<Payload>(payload: Payload): PartialTransportMessage<Payload>;
|
|
40
41
|
declare function createDummyTransportMessage(): PartialTransportMessage<{
|
|
41
42
|
msg: string;
|
|
42
43
|
test: number;
|
|
@@ -49,10 +50,10 @@ declare function createDummyTransportMessage(): PartialTransportMessage<{
|
|
|
49
50
|
*/
|
|
50
51
|
declare function waitForMessage(t: Transport<Connection>, filter?: (msg: OpaqueTransportMessage) => boolean, rejectMismatch?: boolean): Promise<unknown>;
|
|
51
52
|
declare const testingSessionOptions: SessionOptions;
|
|
52
|
-
declare function asClientRpc<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
|
|
53
|
-
declare function asClientStream<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>];
|
|
54
|
-
declare function asClientSubscription<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>;
|
|
55
|
-
declare function asClientUpload<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
|
|
53
|
+
declare function asClientRpc<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
|
|
54
|
+
declare function asClientStream<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>];
|
|
55
|
+
declare function asClientSubscription<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): (msg: Static<I>) => it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>;
|
|
56
|
+
declare function asClientUpload<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
|
|
56
57
|
ok: boolean;
|
|
57
58
|
payload: {
|
|
58
59
|
code: string;
|
package/dist/util/testHelpers.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UNCAUGHT_ERROR,
|
|
3
3
|
pushable
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-TIFNW5GQ.js";
|
|
5
5
|
import "../chunk-RPIDSIQG.js";
|
|
6
6
|
import {
|
|
7
7
|
Session,
|
|
8
8
|
defaultTransportOptions
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-CLY7AQ25.js";
|
|
10
10
|
import {
|
|
11
11
|
coerceErrorString
|
|
12
12
|
} from "../chunk-VH3NGOXQ.js";
|
|
13
|
-
import "../chunk-
|
|
13
|
+
import "../chunk-YITXOAPA.js";
|
|
14
14
|
import "../chunk-GZ7HCLLM.js";
|
|
15
15
|
|
|
16
16
|
// util/testHelpers.ts
|
|
@@ -86,28 +86,30 @@ function catchProcError(err) {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
var testingSessionOptions = defaultTransportOptions;
|
|
89
|
-
function
|
|
90
|
-
|
|
89
|
+
function dummySession() {
|
|
90
|
+
return new Session(
|
|
91
91
|
void 0,
|
|
92
92
|
"client",
|
|
93
|
-
"
|
|
93
|
+
"server",
|
|
94
94
|
testingSessionOptions
|
|
95
95
|
);
|
|
96
|
+
}
|
|
97
|
+
function dummyCtx(state, session, extendedContext) {
|
|
96
98
|
return {
|
|
97
99
|
...extendedContext,
|
|
98
100
|
state,
|
|
99
|
-
to:
|
|
100
|
-
from:
|
|
101
|
+
to: session.to,
|
|
102
|
+
from: session.from,
|
|
101
103
|
streamId: nanoid(),
|
|
102
104
|
session
|
|
103
105
|
};
|
|
104
106
|
}
|
|
105
|
-
function asClientRpc(state, proc, extendedContext) {
|
|
107
|
+
function asClientRpc(state, proc, extendedContext, session = dummySession()) {
|
|
106
108
|
return async (msg) => {
|
|
107
|
-
return await proc.handler(dummyCtx(state, extendedContext), msg).catch(catchProcError);
|
|
109
|
+
return await proc.handler(dummyCtx(state, session, extendedContext), msg).catch(catchProcError);
|
|
108
110
|
};
|
|
109
111
|
}
|
|
110
|
-
function asClientStream(state, proc, init, extendedContext) {
|
|
112
|
+
function asClientStream(state, proc, init, extendedContext, session = dummySession()) {
|
|
111
113
|
const input = pushable({ objectMode: true });
|
|
112
114
|
const output = pushable({
|
|
113
115
|
objectMode: true
|
|
@@ -115,34 +117,34 @@ function asClientStream(state, proc, init, extendedContext) {
|
|
|
115
117
|
void (async () => {
|
|
116
118
|
if (init) {
|
|
117
119
|
const _proc = proc;
|
|
118
|
-
await _proc.handler(dummyCtx(state, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err)));
|
|
120
|
+
await _proc.handler(dummyCtx(state, session, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err)));
|
|
119
121
|
} else {
|
|
120
122
|
const _proc = proc;
|
|
121
|
-
await _proc.handler(dummyCtx(state, extendedContext), input, output).catch((err) => output.push(catchProcError(err)));
|
|
123
|
+
await _proc.handler(dummyCtx(state, session, extendedContext), input, output).catch((err) => output.push(catchProcError(err)));
|
|
122
124
|
}
|
|
123
125
|
})();
|
|
124
126
|
return [input, output];
|
|
125
127
|
}
|
|
126
|
-
function asClientSubscription(state, proc, extendedContext) {
|
|
128
|
+
function asClientSubscription(state, proc, extendedContext, session = dummySession()) {
|
|
127
129
|
const output = pushable({
|
|
128
130
|
objectMode: true
|
|
129
131
|
});
|
|
130
132
|
return (msg) => {
|
|
131
133
|
void (async () => {
|
|
132
|
-
return await proc.handler(dummyCtx(state, extendedContext), msg, output).catch((err) => output.push(catchProcError(err)));
|
|
134
|
+
return await proc.handler(dummyCtx(state, session, extendedContext), msg, output).catch((err) => output.push(catchProcError(err)));
|
|
133
135
|
})();
|
|
134
136
|
return output;
|
|
135
137
|
};
|
|
136
138
|
}
|
|
137
|
-
function asClientUpload(state, proc, init, extendedContext) {
|
|
139
|
+
function asClientUpload(state, proc, init, extendedContext, session = dummySession()) {
|
|
138
140
|
const input = pushable({ objectMode: true });
|
|
139
141
|
if (init) {
|
|
140
142
|
const _proc = proc;
|
|
141
|
-
const result = _proc.handler(dummyCtx(state, extendedContext), init, input).catch(catchProcError);
|
|
143
|
+
const result = _proc.handler(dummyCtx(state, session, extendedContext), init, input).catch(catchProcError);
|
|
142
144
|
return [input, result];
|
|
143
145
|
} else {
|
|
144
146
|
const _proc = proc;
|
|
145
|
-
const result = _proc.handler(dummyCtx(state, extendedContext), input).catch(catchProcError);
|
|
147
|
+
const result = _proc.handler(dummyCtx(state, session, extendedContext), input).catch(catchProcError);
|
|
146
148
|
return [input, result];
|
|
147
149
|
}
|
|
148
150
|
}
|
package/package.json
CHANGED
package/dist/chunk-H4BYJELI.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// logging/index.ts
|
|
2
|
-
var LoggingLevels = {
|
|
3
|
-
debug: -1,
|
|
4
|
-
info: 0,
|
|
5
|
-
warn: 1,
|
|
6
|
-
error: 2
|
|
7
|
-
};
|
|
8
|
-
var log;
|
|
9
|
-
var defaultLoggingLevel = "info";
|
|
10
|
-
function bindLogger(write, color) {
|
|
11
|
-
const debug = color ? "\x1B[37mdebug\x1B[0m" : "debug";
|
|
12
|
-
const info = color ? "\x1B[37minfo\x1B[0m" : "info";
|
|
13
|
-
const warn = color ? "\x1B[33mwarn\x1B[0m" : "warn";
|
|
14
|
-
const error = color ? "\x1B[31merr\x1B[0m" : "err";
|
|
15
|
-
log = {
|
|
16
|
-
debug: (msg) => log && LoggingLevels[log.minLevel] <= -1 && write(`[river:${debug}] ${msg}`),
|
|
17
|
-
info: (msg) => log && LoggingLevels[log.minLevel] <= 0 && write(`[river:${info}] ${msg}`),
|
|
18
|
-
warn: (msg) => log && LoggingLevels[log.minLevel] <= 1 && write(`[river:${warn}] ${msg}`),
|
|
19
|
-
error: (msg) => log && LoggingLevels[log.minLevel] <= 2 && write(`[river:${error}] ${msg}`),
|
|
20
|
-
minLevel: log?.minLevel ?? defaultLoggingLevel
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function unbindLogger() {
|
|
24
|
-
log = void 0;
|
|
25
|
-
}
|
|
26
|
-
function setLevel(level) {
|
|
27
|
-
if (log) {
|
|
28
|
-
log.minLevel = level;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
log,
|
|
34
|
-
bindLogger,
|
|
35
|
-
unbindLogger,
|
|
36
|
-
setLevel
|
|
37
|
-
};
|