@fireproof/core 0.21.0-dev-preview-5 → 0.21.0-dev-preview-6
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/blockstore/attachable-store.d.ts.map +1 -1
- package/blockstore/attachable-store.js +5 -4
- package/blockstore/attachable-store.js.map +1 -1
- package/blockstore/loader.d.ts +1 -2
- package/blockstore/loader.d.ts.map +1 -1
- package/blockstore/loader.js +10 -40
- package/blockstore/loader.js.map +1 -1
- package/blockstore/store.js +1 -1
- package/blockstore/store.js.map +1 -1
- package/blockstore/types.d.ts +2 -0
- package/blockstore/types.d.ts.map +1 -1
- package/blockstore/types.js.map +1 -1
- package/database.d.ts +1 -0
- package/database.d.ts.map +1 -1
- package/database.js +1 -0
- package/database.js.map +1 -1
- package/ledger.d.ts +2 -3
- package/ledger.d.ts.map +1 -1
- package/ledger.js +19 -16
- package/ledger.js.map +1 -1
- package/package.json +1 -1
- package/protocols/cloud/http-connection.d.ts +1 -2
- package/protocols/cloud/http-connection.d.ts.map +1 -1
- package/protocols/cloud/http-connection.js +0 -1
- package/protocols/cloud/http-connection.js.map +1 -1
- package/protocols/cloud/msg-types-data.d.ts +4 -4
- package/protocols/cloud/msg-types-data.d.ts.map +1 -1
- package/protocols/cloud/msg-types-data.js.map +1 -1
- package/protocols/cloud/msg-types-meta.d.ts +13 -13
- package/protocols/cloud/msg-types-meta.d.ts.map +1 -1
- package/protocols/cloud/msg-types-meta.js.map +1 -1
- package/protocols/cloud/msg-types-wal.d.ts +4 -4
- package/protocols/cloud/msg-types-wal.d.ts.map +1 -1
- package/protocols/cloud/msg-types-wal.js.map +1 -1
- package/protocols/cloud/msg-types.d.ts +19 -33
- package/protocols/cloud/msg-types.d.ts.map +1 -1
- package/protocols/cloud/msg-types.js +1 -4
- package/protocols/cloud/msg-types.js.map +1 -1
- package/protocols/cloud/msger.d.ts +38 -47
- package/protocols/cloud/msger.d.ts.map +1 -1
- package/protocols/cloud/msger.js +106 -211
- package/protocols/cloud/msger.js.map +1 -1
- package/protocols/cloud/ws-connection.d.ts +3 -14
- package/protocols/cloud/ws-connection.d.ts.map +1 -1
- package/protocols/cloud/ws-connection.js +34 -73
- package/protocols/cloud/ws-connection.js.map +1 -1
- package/protocols/index.d.ts +0 -1
- package/protocols/index.d.ts.map +1 -1
- package/protocols/index.js +0 -1
- package/protocols/index.js.map +1 -1
- package/react/types.d.ts +8 -28
- package/react/types.d.ts.map +1 -1
- package/react/use-attach.d.ts +4 -9
- package/react/use-attach.d.ts.map +1 -1
- package/react/use-attach.js +43 -136
- package/react/use-attach.js.map +1 -1
- package/react/use-fireproof.js +2 -2
- package/react/use-fireproof.js.map +1 -1
- package/runtime/gateways/cloud/gateway.d.ts +8 -8
- package/runtime/gateways/cloud/gateway.d.ts.map +1 -1
- package/runtime/gateways/cloud/gateway.js +15 -17
- package/runtime/gateways/cloud/gateway.js.map +1 -1
- package/runtime/gateways/cloud/to-cloud.d.ts +9 -22
- package/runtime/gateways/cloud/to-cloud.d.ts.map +1 -1
- package/runtime/gateways/cloud/to-cloud.js +59 -75
- package/runtime/gateways/cloud/to-cloud.js.map +1 -1
- package/runtime/gateways/file/key-bag-file.d.ts +0 -1
- package/runtime/gateways/file/key-bag-file.d.ts.map +1 -1
- package/runtime/gateways/file/key-bag-file.js +0 -12
- package/runtime/gateways/file/key-bag-file.js.map +1 -1
- package/runtime/gateways/indexeddb/gateway-impl.d.ts.map +1 -1
- package/runtime/gateways/indexeddb/gateway-impl.js.map +1 -1
- package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts +0 -1
- package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts.map +1 -1
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js +0 -6
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js.map +1 -1
- package/runtime/key-bag-memory.d.ts +0 -1
- package/runtime/key-bag-memory.d.ts.map +1 -1
- package/runtime/key-bag-memory.js +0 -7
- package/runtime/key-bag-memory.js.map +1 -1
- package/runtime/key-bag.d.ts +0 -3
- package/runtime/key-bag.d.ts.map +1 -1
- package/runtime/key-bag.js +0 -6
- package/runtime/key-bag.js.map +1 -1
- package/runtime/keyed-crypto.d.ts.map +1 -1
- package/runtime/keyed-crypto.js +5 -5
- package/runtime/keyed-crypto.js.map +1 -1
- package/tests/blockstore/keyed-crypto.test.ts +150 -0
- package/tests/fireproof/attachable.test.ts +1 -1
- package/tests/utils.test.ts +192 -0
- package/types.d.ts +2 -1
- package/types.d.ts.map +1 -1
- package/use-fireproof/iframe-strategy.d.ts +4 -6
- package/use-fireproof/iframe-strategy.d.ts.map +1 -1
- package/use-fireproof/iframe-strategy.js +11 -7
- package/use-fireproof/iframe-strategy.js.map +1 -1
- package/use-fireproof/index.d.ts +2 -6
- package/use-fireproof/index.d.ts.map +1 -1
- package/use-fireproof/index.js +3 -23
- package/use-fireproof/index.js.map +1 -1
- package/use-fireproof/redirect-strategy.d.ts +4 -11
- package/use-fireproof/redirect-strategy.d.ts.map +1 -1
- package/use-fireproof/redirect-strategy.js +20 -142
- package/use-fireproof/redirect-strategy.js.map +1 -1
- package/utils.d.ts +6 -5
- package/utils.d.ts.map +1 -1
- package/utils.js +67 -19
- package/utils.js.map +1 -1
- package/protocols/dashboard/index.d.ts +0 -4
- package/protocols/dashboard/index.d.ts.map +0 -1
- package/protocols/dashboard/index.js +0 -4
- package/protocols/dashboard/index.js.map +0 -1
- package/protocols/dashboard/msg-api.d.ts +0 -11
- package/protocols/dashboard/msg-api.d.ts.map +0 -1
- package/protocols/dashboard/msg-api.js +0 -55
- package/protocols/dashboard/msg-api.js.map +0 -1
- package/protocols/dashboard/msg-is.d.ts +0 -45
- package/protocols/dashboard/msg-is.d.ts.map +0 -1
- package/protocols/dashboard/msg-is.js +0 -63
- package/protocols/dashboard/msg-is.js.map +0 -1
- package/protocols/dashboard/msg-types.d.ts +0 -397
- package/protocols/dashboard/msg-types.d.ts.map +0 -1
- package/protocols/dashboard/msg-types.js +0 -4
- package/protocols/dashboard/msg-types.js.map +0 -1
- package/tests/protocols/cloud/msger.test.ts +0 -563
@@ -1,563 +0,0 @@
|
|
1
|
-
import { Result, URI } from "@adviser/cement";
|
2
|
-
import { ensureSuperThis, ps, SuperThis } from "@fireproof/core";
|
3
|
-
import {
|
4
|
-
buildResChat,
|
5
|
-
buildResGestalt,
|
6
|
-
buildResOpen,
|
7
|
-
MsgIsError,
|
8
|
-
MsgIsReqChat,
|
9
|
-
MsgIsReqGestalt,
|
10
|
-
MsgIsReqOpen,
|
11
|
-
NotReadyErrorMsg,
|
12
|
-
} from "../../../src/protocols/cloud/msg-types.js";
|
13
|
-
import { VirtualConnected } from "../../../src/protocols/cloud/msger.js";
|
14
|
-
|
15
|
-
const sthis = ensureSuperThis();
|
16
|
-
|
17
|
-
class TestConnection implements ps.cloud.MsgRawConnection {
|
18
|
-
readonly sthis: SuperThis;
|
19
|
-
readonly exchangedGestalt: ps.cloud.ExchangedGestalt;
|
20
|
-
readonly activeBinds: Map<string, ps.cloud.ActiveStream>;
|
21
|
-
readonly id: string;
|
22
|
-
|
23
|
-
isReady = true;
|
24
|
-
|
25
|
-
constructor(sthis: SuperThis, exGestalt: ps.cloud.ExchangedGestalt) {
|
26
|
-
this.sthis = sthis;
|
27
|
-
this.exchangedGestalt = exGestalt;
|
28
|
-
this.activeBinds = new Map();
|
29
|
-
this.id = this.sthis.nextId().str;
|
30
|
-
}
|
31
|
-
|
32
|
-
readonly bindFn = vi.fn();
|
33
|
-
bind<S extends ps.cloud.MsgBase, Q extends ps.cloud.MsgBase>(
|
34
|
-
req: Q,
|
35
|
-
opts: ps.cloud.RequestOpts,
|
36
|
-
): ReadableStream<ps.cloud.MsgWithError<S>> {
|
37
|
-
this.bindFn(req, opts);
|
38
|
-
return new ReadableStream<ps.cloud.MsgWithError<S>>({
|
39
|
-
start: (ctl) => {
|
40
|
-
ctl.enqueue({
|
41
|
-
tid: req.tid,
|
42
|
-
type: req.type,
|
43
|
-
version: req.version,
|
44
|
-
auth: {
|
45
|
-
type: "error",
|
46
|
-
},
|
47
|
-
} as S);
|
48
|
-
},
|
49
|
-
});
|
50
|
-
}
|
51
|
-
readonly requestFn = vi.fn();
|
52
|
-
request<S extends ps.cloud.MsgBase, Q extends ps.cloud.MsgBase>(
|
53
|
-
req: Q,
|
54
|
-
opts: ps.cloud.RequestOpts,
|
55
|
-
): Promise<ps.cloud.MsgWithError<S>> {
|
56
|
-
this.requestFn(req, opts);
|
57
|
-
// console.log("request", req);
|
58
|
-
return Promise.resolve({
|
59
|
-
tid: req.tid,
|
60
|
-
type: req.type,
|
61
|
-
version: req.version,
|
62
|
-
auth: {
|
63
|
-
type: "error",
|
64
|
-
},
|
65
|
-
} as S);
|
66
|
-
}
|
67
|
-
readonly sendFn = vi.fn();
|
68
|
-
send<S extends ps.cloud.MsgBase, Q extends ps.cloud.MsgBase>(msg: Q): Promise<ps.cloud.MsgWithError<S>> {
|
69
|
-
this.sendFn(msg);
|
70
|
-
// console.log("send", msg);
|
71
|
-
return Promise.resolve({
|
72
|
-
tid: msg.tid,
|
73
|
-
type: msg.type,
|
74
|
-
version: msg.version,
|
75
|
-
auth: {
|
76
|
-
type: "error",
|
77
|
-
},
|
78
|
-
} as S);
|
79
|
-
}
|
80
|
-
readonly startFn = vi.fn();
|
81
|
-
start(): Promise<Result<void>> {
|
82
|
-
this.startFn();
|
83
|
-
// console.log("start", this.id); //, this.startFn.mock.calls);
|
84
|
-
return Promise.resolve(Result.Ok(undefined));
|
85
|
-
}
|
86
|
-
readonly closeFn = vi.fn();
|
87
|
-
close(o: ps.cloud.MsgBase): Promise<Result<void>> {
|
88
|
-
this.closeFn(o);
|
89
|
-
// console.log("close", this.id); //, o, this.closeFn.mock.calls);
|
90
|
-
return Promise.resolve(Result.Ok(undefined));
|
91
|
-
}
|
92
|
-
readonly onMsgFn = vi.fn();
|
93
|
-
onMsg(msg: ps.cloud.OnMsgFn<ps.cloud.MsgBase>): ps.cloud.UnReg {
|
94
|
-
this.onMsgFn(msg);
|
95
|
-
return () => {
|
96
|
-
/* no-op */
|
97
|
-
};
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
it("queued-raw-connection", async () => {
|
102
|
-
const msgP = ps.cloud.defaultMsgParams(sthis, { hasPersistent: true });
|
103
|
-
const my = ps.cloud.defaultGestalt(msgP, { id: "FP-Universal-Client" });
|
104
|
-
const realConn = new MockWSConnection(sthis, {
|
105
|
-
my,
|
106
|
-
remote: ps.cloud.defaultGestalt(msgP, { id: "FP-Universal-Server" }),
|
107
|
-
});
|
108
|
-
|
109
|
-
const vconn = new ps.cloud.VirtualConnected(sthis, {
|
110
|
-
curl: "http://localhost:8080",
|
111
|
-
imsgP: msgP,
|
112
|
-
openWSorHttp: {
|
113
|
-
openHttp: async function (): Promise<Result<ps.cloud.MsgRawConnection>> {
|
114
|
-
return Result.Ok(
|
115
|
-
new MockHttpConnection(sthis, {
|
116
|
-
my,
|
117
|
-
remote: ps.cloud.defaultGestalt(msgP, { id: "FP-Universal-Server" }),
|
118
|
-
}),
|
119
|
-
);
|
120
|
-
},
|
121
|
-
openWS: async function (): Promise<Result<ps.cloud.MsgRawConnection>> {
|
122
|
-
return Result.Ok(realConn);
|
123
|
-
},
|
124
|
-
},
|
125
|
-
});
|
126
|
-
|
127
|
-
await vconn.send({
|
128
|
-
tid: "1234",
|
129
|
-
type: "test",
|
130
|
-
version: "1.0",
|
131
|
-
auth: {
|
132
|
-
type: "error",
|
133
|
-
},
|
134
|
-
});
|
135
|
-
|
136
|
-
await vconn.request(
|
137
|
-
{
|
138
|
-
tid: "1234",
|
139
|
-
type: "test",
|
140
|
-
version: "1.0",
|
141
|
-
auth: {
|
142
|
-
type: "error",
|
143
|
-
},
|
144
|
-
},
|
145
|
-
{
|
146
|
-
waitFor: (msg) => {
|
147
|
-
return msg.type === "test" && msg.tid === "1234";
|
148
|
-
},
|
149
|
-
},
|
150
|
-
);
|
151
|
-
|
152
|
-
await vconn.close({
|
153
|
-
tid: "1234",
|
154
|
-
type: "test",
|
155
|
-
version: "1.0",
|
156
|
-
auth: {
|
157
|
-
type: "error",
|
158
|
-
},
|
159
|
-
});
|
160
|
-
|
161
|
-
// await sleep(100);
|
162
|
-
|
163
|
-
expect(realConn.startFn).toHaveBeenCalledTimes(1);
|
164
|
-
expect(realConn.sendFn).toHaveBeenCalledTimes(1);
|
165
|
-
expect(realConn.closeFn).toHaveBeenCalledTimes(1);
|
166
|
-
expect(realConn.requestFn).toHaveBeenCalledTimes(2); // open + test
|
167
|
-
});
|
168
|
-
|
169
|
-
class MockHttpConnection extends TestConnection implements ps.cloud.MsgRawConnection {
|
170
|
-
sthis: SuperThis;
|
171
|
-
exchangedGestalt: ps.cloud.ExchangedGestalt;
|
172
|
-
activeBinds: Map<string, ps.cloud.ActiveStream>;
|
173
|
-
|
174
|
-
readonly isReady = true;
|
175
|
-
|
176
|
-
constructor(sthis: SuperThis, exGestalt: ps.cloud.ExchangedGestalt) {
|
177
|
-
super(sthis, exGestalt);
|
178
|
-
this.sthis = sthis;
|
179
|
-
this.exchangedGestalt = exGestalt;
|
180
|
-
this.activeBinds = new Map();
|
181
|
-
}
|
182
|
-
|
183
|
-
bind<S extends ps.cloud.MsgBase, Q extends ps.cloud.MsgBase>(
|
184
|
-
req: Q,
|
185
|
-
opts: ps.cloud.RequestOpts,
|
186
|
-
): ReadableStream<ps.cloud.MsgWithError<S>> {
|
187
|
-
super.bind(req, opts);
|
188
|
-
// console.log("http-bind", req, opts);
|
189
|
-
return new ReadableStream<ps.cloud.MsgWithError<S>>({
|
190
|
-
start: (ctl) => {
|
191
|
-
ctl.enqueue({
|
192
|
-
tid: req.tid,
|
193
|
-
type: req.type,
|
194
|
-
version: req.version,
|
195
|
-
auth: {
|
196
|
-
type: "error",
|
197
|
-
},
|
198
|
-
} as S);
|
199
|
-
},
|
200
|
-
});
|
201
|
-
}
|
202
|
-
request<S extends ps.cloud.MsgBase, Q extends ps.cloud.MsgBase>(
|
203
|
-
req: Q,
|
204
|
-
opts: ps.cloud.RequestOpts,
|
205
|
-
): Promise<ps.cloud.MsgWithError<S>> {
|
206
|
-
super.request(req, opts);
|
207
|
-
switch (true) {
|
208
|
-
case MsgIsReqGestalt(req):
|
209
|
-
// console.log("http-request-gestalt", req, opts);
|
210
|
-
return Promise.resolve(buildResGestalt(req, this.exchangedGestalt.remote, req.auth) as unknown as S);
|
211
|
-
}
|
212
|
-
// console.log("http-request", req, opts);
|
213
|
-
return Promise.resolve({
|
214
|
-
tid: req.tid,
|
215
|
-
type: req.type,
|
216
|
-
version: req.version,
|
217
|
-
auth: {
|
218
|
-
type: "error",
|
219
|
-
},
|
220
|
-
} as S);
|
221
|
-
}
|
222
|
-
send<S extends ps.cloud.MsgBase, Q extends ps.cloud.MsgBase>(msg: Q): Promise<ps.cloud.MsgWithError<S>> {
|
223
|
-
super.send(msg);
|
224
|
-
// console.log("http-send", msg);
|
225
|
-
return Promise.resolve({
|
226
|
-
tid: msg.tid,
|
227
|
-
type: msg.type,
|
228
|
-
version: msg.version,
|
229
|
-
auth: {
|
230
|
-
type: "error",
|
231
|
-
},
|
232
|
-
} as S);
|
233
|
-
}
|
234
|
-
start(): Promise<Result<void>> {
|
235
|
-
super.start();
|
236
|
-
// console.log("http-start");
|
237
|
-
return Promise.resolve(Result.Ok(undefined));
|
238
|
-
}
|
239
|
-
close(o: ps.cloud.MsgBase): Promise<Result<void>> {
|
240
|
-
// console.log("http-close");
|
241
|
-
super.close(o);
|
242
|
-
return Promise.resolve(Result.Ok(undefined));
|
243
|
-
}
|
244
|
-
onMsg(msg: ps.cloud.OnMsgFn<ps.cloud.MsgBase>): ps.cloud.UnReg {
|
245
|
-
super.onMsg(msg);
|
246
|
-
// console.log("http-onMsg", msg);
|
247
|
-
return () => {
|
248
|
-
/* no-op */
|
249
|
-
};
|
250
|
-
}
|
251
|
-
}
|
252
|
-
|
253
|
-
class MockWSConnection extends TestConnection implements ps.cloud.MsgRawConnection {
|
254
|
-
sthis: SuperThis;
|
255
|
-
exchangedGestalt: ps.cloud.ExchangedGestalt;
|
256
|
-
activeBinds: Map<string, ps.cloud.ActiveStream>;
|
257
|
-
|
258
|
-
isReady = false;
|
259
|
-
|
260
|
-
constructor(sthis: SuperThis, exGestalt: ps.cloud.ExchangedGestalt) {
|
261
|
-
super(sthis, exGestalt);
|
262
|
-
this.sthis = sthis;
|
263
|
-
this.exchangedGestalt = exGestalt;
|
264
|
-
this.activeBinds = new Map();
|
265
|
-
}
|
266
|
-
bind<S extends ps.cloud.MsgBase, Q extends ps.cloud.MsgBase>(
|
267
|
-
req: Q,
|
268
|
-
opts: ps.cloud.RequestOpts,
|
269
|
-
): ReadableStream<ps.cloud.MsgWithError<S>> {
|
270
|
-
super.bind(req, opts);
|
271
|
-
// console.log("ws-bind", req, opts);
|
272
|
-
const id = this.sthis.nextId().str;
|
273
|
-
return new ReadableStream<ps.cloud.MsgWithError<S>>({
|
274
|
-
cancel: () => {
|
275
|
-
// console.log("ws-bind-close");
|
276
|
-
this.activeBinds.delete(id);
|
277
|
-
},
|
278
|
-
start: (controller) => {
|
279
|
-
this.activeBinds.set(id, {
|
280
|
-
id,
|
281
|
-
bind: {
|
282
|
-
msg: req,
|
283
|
-
opts,
|
284
|
-
},
|
285
|
-
controller,
|
286
|
-
});
|
287
|
-
this.send(req).catch((e) => {
|
288
|
-
// eslint-disable-next-line no-console
|
289
|
-
console.error("send-error", e);
|
290
|
-
});
|
291
|
-
},
|
292
|
-
});
|
293
|
-
}
|
294
|
-
request<S extends ps.cloud.MsgBase, Q extends ps.cloud.MsgBase>(
|
295
|
-
req: Q,
|
296
|
-
opts: ps.cloud.RequestOpts,
|
297
|
-
): Promise<ps.cloud.MsgWithError<S>> {
|
298
|
-
super.request(req, opts);
|
299
|
-
if (!this.isReady) {
|
300
|
-
return Promise.resolve({
|
301
|
-
tid: req.tid,
|
302
|
-
type: "error",
|
303
|
-
version: req.version,
|
304
|
-
reason: "not-ready",
|
305
|
-
src: "not-ready",
|
306
|
-
message: "Not Ready",
|
307
|
-
auth: {
|
308
|
-
type: "error",
|
309
|
-
},
|
310
|
-
} satisfies NotReadyErrorMsg);
|
311
|
-
}
|
312
|
-
|
313
|
-
switch (true) {
|
314
|
-
case MsgIsReqOpen(req):
|
315
|
-
// console.log("ws-request-open", req);
|
316
|
-
return Promise.resolve(buildResOpen(this.sthis, req) as unknown as S);
|
317
|
-
}
|
318
|
-
// console.log("ws-request", req, opts);
|
319
|
-
return Promise.resolve({
|
320
|
-
tid: req.tid,
|
321
|
-
type: req.type,
|
322
|
-
version: req.version,
|
323
|
-
auth: {
|
324
|
-
type: "error",
|
325
|
-
},
|
326
|
-
} as S);
|
327
|
-
}
|
328
|
-
send<S extends ps.cloud.MsgBase, Q extends ps.cloud.MsgBase>(msg: Q): Promise<ps.cloud.MsgWithError<S>> {
|
329
|
-
super.send(msg);
|
330
|
-
// console.log("ws-send", msg);
|
331
|
-
if (MsgIsReqChat(msg)) {
|
332
|
-
const res = buildResChat(msg, msg.conn, `got[${msg.message}]`);
|
333
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
334
|
-
for (const [_, bind] of this.activeBinds.entries()) {
|
335
|
-
// console.log("ws-to-bind", res);
|
336
|
-
bind.controller?.enqueue(res);
|
337
|
-
}
|
338
|
-
return Promise.resolve(msg as unknown as S);
|
339
|
-
}
|
340
|
-
return Promise.resolve({
|
341
|
-
tid: msg.tid,
|
342
|
-
type: msg.type,
|
343
|
-
version: msg.version,
|
344
|
-
auth: {
|
345
|
-
type: "error",
|
346
|
-
},
|
347
|
-
} as S);
|
348
|
-
}
|
349
|
-
start(): Promise<Result<void>> {
|
350
|
-
super.start();
|
351
|
-
this.isReady = true;
|
352
|
-
return Promise.resolve(Result.Ok(undefined));
|
353
|
-
}
|
354
|
-
close(o: ps.cloud.MsgBase): Promise<Result<void>> {
|
355
|
-
super.close(o);
|
356
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
357
|
-
for (const [_, bind] of this.activeBinds.entries()) {
|
358
|
-
bind.controller?.close();
|
359
|
-
}
|
360
|
-
if (!this.isReady) {
|
361
|
-
return Promise.resolve(Result.Err("Not ready"));
|
362
|
-
}
|
363
|
-
return Promise.resolve(Result.Ok(undefined));
|
364
|
-
}
|
365
|
-
onMsg(msg: ps.cloud.OnMsgFn<ps.cloud.MsgBase>): ps.cloud.UnReg {
|
366
|
-
super.onMsg(msg);
|
367
|
-
throw new Error("Method not implemented.");
|
368
|
-
}
|
369
|
-
}
|
370
|
-
|
371
|
-
describe("retry-connection", () => {
|
372
|
-
let wsMock: MockWSConnection;
|
373
|
-
let connected: VirtualConnected;
|
374
|
-
beforeEach(async () => {
|
375
|
-
const rMsc = await ps.cloud.Msger.connect(
|
376
|
-
sthis,
|
377
|
-
"http://localhost:8080",
|
378
|
-
{},
|
379
|
-
{},
|
380
|
-
{
|
381
|
-
openHttp: async function (
|
382
|
-
sthis: SuperThis,
|
383
|
-
urls: URI[],
|
384
|
-
msgP: ps.cloud.MsgerParamsWithEnDe,
|
385
|
-
exGestalt: ps.cloud.ExchangedGestalt,
|
386
|
-
): Promise<Result<ps.cloud.MsgRawConnection>> {
|
387
|
-
return Result.Ok(new MockHttpConnection(sthis, exGestalt));
|
388
|
-
},
|
389
|
-
openWS: async function (
|
390
|
-
sthis: SuperThis,
|
391
|
-
url: URI,
|
392
|
-
msgP: ps.cloud.MsgerParamsWithEnDe,
|
393
|
-
exGestalt: ps.cloud.ExchangedGestalt,
|
394
|
-
): Promise<Result<ps.cloud.MsgRawConnection>> {
|
395
|
-
// if (wsMock) {
|
396
|
-
// assert.fail("WS connection already created");
|
397
|
-
// }
|
398
|
-
wsMock = new MockWSConnection(sthis, exGestalt);
|
399
|
-
return Result.Ok(wsMock);
|
400
|
-
},
|
401
|
-
},
|
402
|
-
);
|
403
|
-
|
404
|
-
expect(rMsc.isOk()).toBe(true);
|
405
|
-
connected = rMsc.unwrap();
|
406
|
-
});
|
407
|
-
|
408
|
-
afterEach(async () => {
|
409
|
-
await connected.close({
|
410
|
-
tid: "1234",
|
411
|
-
type: "test",
|
412
|
-
version: "1.0",
|
413
|
-
auth: {
|
414
|
-
type: "error",
|
415
|
-
},
|
416
|
-
});
|
417
|
-
});
|
418
|
-
|
419
|
-
it("bind", async () => {
|
420
|
-
const result = connected.bind(
|
421
|
-
{
|
422
|
-
tid: "1234",
|
423
|
-
type: "reqChat",
|
424
|
-
version: "1.0",
|
425
|
-
message: `ping[i]`,
|
426
|
-
auth: {
|
427
|
-
type: "error",
|
428
|
-
},
|
429
|
-
},
|
430
|
-
{
|
431
|
-
waitFor: (msg) => {
|
432
|
-
return msg.type === "resChat";
|
433
|
-
},
|
434
|
-
},
|
435
|
-
);
|
436
|
-
const reader = result.getReader();
|
437
|
-
|
438
|
-
const { done, value: msg } = await reader.read();
|
439
|
-
expect(done).toBe(false);
|
440
|
-
if (msg && !MsgIsError(msg)) {
|
441
|
-
expect(msg).toEqual({
|
442
|
-
auth: {
|
443
|
-
type: "error",
|
444
|
-
},
|
445
|
-
conn: msg.conn,
|
446
|
-
message: "got[ping[i]]",
|
447
|
-
targets: undefined,
|
448
|
-
tid: "1234",
|
449
|
-
type: "resChat",
|
450
|
-
version: "FP-MSG-1.0",
|
451
|
-
});
|
452
|
-
} else {
|
453
|
-
assert.fail("msg is error");
|
454
|
-
}
|
455
|
-
const refConn = msg.conn;
|
456
|
-
|
457
|
-
for (let i = 0; i < 3; i++) {
|
458
|
-
await connected.send({
|
459
|
-
tid: "1234" + i,
|
460
|
-
type: "reqChat",
|
461
|
-
version: "1.0",
|
462
|
-
message: `ping[${i}]`,
|
463
|
-
auth: {
|
464
|
-
type: "error",
|
465
|
-
},
|
466
|
-
});
|
467
|
-
wsMock.isReady = false; // trigger not-ready error
|
468
|
-
if (i > 0) {
|
469
|
-
const { done, value: msgl } = await reader.read();
|
470
|
-
expect(done).toBe(false);
|
471
|
-
if (msgl && !MsgIsError(msgl)) {
|
472
|
-
expect(msgl).toEqual({
|
473
|
-
auth: {
|
474
|
-
type: "error",
|
475
|
-
},
|
476
|
-
conn: refConn,
|
477
|
-
message: "got[ping[i]]",
|
478
|
-
targets: undefined,
|
479
|
-
tid: "1234",
|
480
|
-
type: "resChat",
|
481
|
-
version: "FP-MSG-1.0",
|
482
|
-
});
|
483
|
-
}
|
484
|
-
}
|
485
|
-
const { done, value: msgl } = await reader.read();
|
486
|
-
expect(done).toBe(false);
|
487
|
-
if (msgl && !MsgIsError(msgl)) {
|
488
|
-
expect(msgl).toEqual({
|
489
|
-
auth: {
|
490
|
-
type: "error",
|
491
|
-
},
|
492
|
-
conn: refConn,
|
493
|
-
message: "got[ping[" + i + "]]",
|
494
|
-
targets: undefined,
|
495
|
-
tid: "1234" + i,
|
496
|
-
type: "resChat",
|
497
|
-
version: "FP-MSG-1.0",
|
498
|
-
});
|
499
|
-
}
|
500
|
-
}
|
501
|
-
|
502
|
-
connected.close({
|
503
|
-
tid: "1234",
|
504
|
-
type: "error",
|
505
|
-
version: "1.0",
|
506
|
-
message: "Not Happy",
|
507
|
-
auth: {
|
508
|
-
type: "error",
|
509
|
-
},
|
510
|
-
} as ps.cloud.MsgBase);
|
511
|
-
});
|
512
|
-
|
513
|
-
it("request", async () => {
|
514
|
-
for (let i = 0; i < 3; i++) {
|
515
|
-
const result = await connected.request(
|
516
|
-
{
|
517
|
-
tid: "1234" + i,
|
518
|
-
type: "test",
|
519
|
-
version: "1.0",
|
520
|
-
auth: {
|
521
|
-
type: "error",
|
522
|
-
},
|
523
|
-
},
|
524
|
-
{
|
525
|
-
waitFor: (msg) => {
|
526
|
-
return msg.type === "test" && msg.tid === "1234";
|
527
|
-
},
|
528
|
-
},
|
529
|
-
);
|
530
|
-
expect(result).toEqual({
|
531
|
-
tid: "1234" + i,
|
532
|
-
type: "test",
|
533
|
-
version: "1.0",
|
534
|
-
auth: {
|
535
|
-
type: "error",
|
536
|
-
},
|
537
|
-
});
|
538
|
-
wsMock.isReady = false; // trigger not-ready error
|
539
|
-
}
|
540
|
-
});
|
541
|
-
|
542
|
-
it("send", async () => {
|
543
|
-
for (let i = 0; i < 3; i++) {
|
544
|
-
const result = await connected.send({
|
545
|
-
tid: "1234" + i,
|
546
|
-
type: "test",
|
547
|
-
version: "1.0",
|
548
|
-
auth: {
|
549
|
-
type: "error",
|
550
|
-
},
|
551
|
-
});
|
552
|
-
expect(result).toEqual({
|
553
|
-
tid: "1234" + i,
|
554
|
-
type: "test",
|
555
|
-
version: "1.0",
|
556
|
-
auth: {
|
557
|
-
type: "error",
|
558
|
-
},
|
559
|
-
});
|
560
|
-
wsMock.isReady = false; // trigger not-ready error
|
561
|
-
}
|
562
|
-
});
|
563
|
-
});
|