@fireproof/core 0.20.5 → 0.21.0-dev-preview-3
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/commitor.js +3 -3
- package/blockstore/commitor.js.map +1 -1
- package/blockstore/loader.d.ts +2 -1
- package/blockstore/loader.d.ts.map +1 -1
- package/blockstore/loader.js +40 -10
- package/blockstore/loader.js.map +1 -1
- package/blockstore/store.js +1 -1
- package/blockstore/store.js.map +1 -1
- package/crdt.d.ts +1 -1
- package/crdt.d.ts.map +1 -1
- package/crdt.js.map +1 -1
- package/database.d.ts +2 -3
- package/database.d.ts.map +1 -1
- package/database.js +7 -3
- package/database.js.map +1 -1
- package/deno.json +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/indexer-helpers.d.ts +29 -28
- package/indexer-helpers.d.ts.map +1 -1
- package/indexer-helpers.js +21 -3
- package/indexer-helpers.js.map +1 -1
- package/indexer.d.ts +3 -3
- package/indexer.d.ts.map +1 -1
- package/indexer.js +16 -24
- package/indexer.js.map +1 -1
- package/ledger.d.ts +3 -2
- package/ledger.d.ts.map +1 -1
- package/ledger.js +7 -4
- package/ledger.js.map +1 -1
- package/package.json +2 -2
- package/protocols/cloud/http-connection.d.ts +2 -1
- package/protocols/cloud/http-connection.d.ts.map +1 -1
- package/protocols/cloud/http-connection.js +1 -0
- 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 +33 -19
- package/protocols/cloud/msg-types.d.ts.map +1 -1
- package/protocols/cloud/msg-types.js +4 -1
- package/protocols/cloud/msg-types.js.map +1 -1
- package/protocols/cloud/msger.d.ts +47 -38
- package/protocols/cloud/msger.d.ts.map +1 -1
- package/protocols/cloud/msger.js +211 -106
- package/protocols/cloud/msger.js.map +1 -1
- package/protocols/cloud/ws-connection.d.ts +14 -3
- package/protocols/cloud/ws-connection.d.ts.map +1 -1
- package/protocols/cloud/ws-connection.js +73 -34
- package/protocols/cloud/ws-connection.js.map +1 -1
- package/protocols/dashboard/index.d.ts +4 -0
- package/protocols/dashboard/index.d.ts.map +1 -0
- package/protocols/dashboard/index.js +4 -0
- package/protocols/dashboard/index.js.map +1 -0
- package/protocols/dashboard/msg-api.d.ts +11 -0
- package/protocols/dashboard/msg-api.d.ts.map +1 -0
- package/protocols/dashboard/msg-api.js +55 -0
- package/protocols/dashboard/msg-api.js.map +1 -0
- package/protocols/dashboard/msg-is.d.ts +45 -0
- package/protocols/dashboard/msg-is.d.ts.map +1 -0
- package/protocols/dashboard/msg-is.js +63 -0
- package/protocols/dashboard/msg-is.js.map +1 -0
- package/protocols/dashboard/msg-types.d.ts +397 -0
- package/protocols/dashboard/msg-types.d.ts.map +1 -0
- package/protocols/dashboard/msg-types.js +4 -0
- package/protocols/dashboard/msg-types.js.map +1 -0
- package/protocols/index.d.ts +1 -0
- package/protocols/index.d.ts.map +1 -1
- package/protocols/index.js +1 -0
- package/protocols/index.js.map +1 -1
- package/react/img-file.d.ts +2 -2
- package/react/img-file.d.ts.map +1 -1
- package/react/img-file.js +62 -27
- package/react/img-file.js.map +1 -1
- package/react/types.d.ts +29 -9
- package/react/types.d.ts.map +1 -1
- package/react/use-all-docs.d.ts +1 -1
- package/react/use-all-docs.d.ts.map +1 -1
- package/react/use-all-docs.js.map +1 -1
- package/react/use-attach.d.ts +9 -4
- package/react/use-attach.d.ts.map +1 -1
- package/react/use-attach.js +136 -43
- package/react/use-attach.js.map +1 -1
- package/react/use-fireproof.js +2 -2
- package/react/use-fireproof.js.map +1 -1
- package/react/use-live-query.d.ts.map +1 -1
- package/react/use-live-query.js +1 -4
- package/react/use-live-query.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 +17 -15
- package/runtime/gateways/cloud/gateway.js.map +1 -1
- package/runtime/gateways/cloud/to-cloud.d.ts +22 -9
- package/runtime/gateways/cloud/to-cloud.d.ts.map +1 -1
- package/runtime/gateways/cloud/to-cloud.js +75 -59
- package/runtime/gateways/cloud/to-cloud.js.map +1 -1
- package/runtime/gateways/file/key-bag-file.d.ts +1 -0
- package/runtime/gateways/file/key-bag-file.d.ts.map +1 -1
- package/runtime/gateways/file/key-bag-file.js +12 -0
- 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 +1 -0
- package/runtime/gateways/indexeddb/key-bag-indexeddb.d.ts.map +1 -1
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js +6 -0
- package/runtime/gateways/indexeddb/key-bag-indexeddb.js.map +1 -1
- package/runtime/key-bag-memory.d.ts +1 -0
- package/runtime/key-bag-memory.d.ts.map +1 -1
- package/runtime/key-bag-memory.js +7 -0
- package/runtime/key-bag-memory.js.map +1 -1
- package/runtime/key-bag.d.ts +3 -0
- package/runtime/key-bag.d.ts.map +1 -1
- package/runtime/key-bag.js +6 -0
- package/runtime/key-bag.js.map +1 -1
- package/tests/fireproof/attachable.test.ts +1 -1
- package/tests/fireproof/charwise-boolean.test.ts +66 -0
- package/tests/fireproof/crdt.test.ts +3 -3
- package/tests/fireproof/deleted-docs-handling.test.ts +111 -0
- package/tests/fireproof/fireproof.test.ts +10 -10
- package/tests/fireproof/hello.test.ts +1 -1
- package/tests/fireproof/indexer.test.ts +21 -21
- package/tests/fireproof/query-docs.test.ts +42 -7
- package/tests/fireproof/query-limit-issue.test.ts +147 -0
- package/tests/fireproof/query-property-inconsistency.test.ts +89 -0
- package/tests/fireproof/query-result-properties.test.ts +42 -0
- package/tests/protocols/cloud/msger.test.ts +563 -0
- package/types.d.ts +9 -9
- package/types.d.ts.map +1 -1
- package/types.js.map +1 -1
- package/use-fireproof/iframe-strategy.d.ts +6 -4
- package/use-fireproof/iframe-strategy.d.ts.map +1 -1
- package/use-fireproof/iframe-strategy.js +7 -11
- package/use-fireproof/iframe-strategy.js.map +1 -1
- package/use-fireproof/index.d.ts +6 -2
- package/use-fireproof/index.d.ts.map +1 -1
- package/use-fireproof/index.js +23 -3
- package/use-fireproof/index.js.map +1 -1
- package/use-fireproof/redirect-strategy.d.ts +11 -4
- package/use-fireproof/redirect-strategy.d.ts.map +1 -1
- package/use-fireproof/redirect-strategy.js +142 -20
- package/use-fireproof/redirect-strategy.js.map +1 -1
- package/utils.d.ts +3 -0
- package/utils.d.ts.map +1 -1
- package/utils.js.map +1 -1
@@ -0,0 +1,563 @@
|
|
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
|
+
});
|
package/types.d.ts
CHANGED
@@ -195,7 +195,7 @@ export interface IndexRow<K extends IndexKeyType, T extends DocObject, R extends
|
|
195
195
|
readonly value: R;
|
196
196
|
readonly doc?: DocWithId<T>;
|
197
197
|
}
|
198
|
-
export interface IndexRows<
|
198
|
+
export interface IndexRows<T extends DocObject, K extends IndexKeyType = string, R extends DocFragment = T> {
|
199
199
|
readonly rows: IndexRow<K, T, R>[];
|
200
200
|
readonly docs: DocWithId<T>[];
|
201
201
|
}
|
@@ -229,9 +229,10 @@ export interface QueryOpts<K extends IndexKeyType> {
|
|
229
229
|
prefix?: IndexKeyType;
|
230
230
|
}
|
231
231
|
export interface AllDocsQueryOpts extends QueryOpts<string> {
|
232
|
-
readonly key
|
233
|
-
readonly keys
|
234
|
-
prefix
|
232
|
+
readonly key: string;
|
233
|
+
readonly keys: string[];
|
234
|
+
readonly prefix: string;
|
235
|
+
readonly includeDeleted: boolean;
|
235
236
|
}
|
236
237
|
export interface AllDocsResponse<T extends DocTypes> {
|
237
238
|
readonly rows: {
|
@@ -321,7 +322,7 @@ export interface CRDT extends ReadyCloseDestroy, HasLogger, HasSuperThis, HasCRD
|
|
321
322
|
readonly clock: CRDTClock;
|
322
323
|
readonly blockstore: BaseBlockstore;
|
323
324
|
readonly indexBlockstore?: BaseBlockstore;
|
324
|
-
readonly indexers: Map<string, Index<
|
325
|
+
readonly indexers: Map<string, Index<DocTypes, IndexKeyType>>;
|
325
326
|
bulk<T extends DocTypes>(updates: DocUpdate<T>[]): Promise<CRDTMeta>;
|
326
327
|
ready(): Promise<void>;
|
327
328
|
close(): Promise<void>;
|
@@ -401,7 +402,6 @@ export interface Database extends ReadyCloseDestroy, HasLogger, HasSuperThis {
|
|
401
402
|
readonly ledger: Ledger;
|
402
403
|
readonly logger: Logger;
|
403
404
|
readonly sthis: SuperThis;
|
404
|
-
readonly id: string;
|
405
405
|
readonly name: string;
|
406
406
|
onClosed(fn: () => void): void;
|
407
407
|
attach(a: Attachable): Promise<Attached>;
|
@@ -411,7 +411,7 @@ export interface Database extends ReadyCloseDestroy, HasLogger, HasSuperThis {
|
|
411
411
|
del(id: string): Promise<DocResponse>;
|
412
412
|
remove(id: string): Promise<DocResponse>;
|
413
413
|
changes<T extends DocTypes>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
|
414
|
-
allDocs<T extends DocTypes>(opts?: AllDocsQueryOpts): Promise<AllDocsResponse<T>>;
|
414
|
+
allDocs<T extends DocTypes>(opts?: Partial<AllDocsQueryOpts>): Promise<AllDocsResponse<T>>;
|
415
415
|
allDocuments<T extends DocTypes>(): Promise<{
|
416
416
|
rows: {
|
417
417
|
key: string;
|
@@ -420,7 +420,7 @@ export interface Database extends ReadyCloseDestroy, HasLogger, HasSuperThis {
|
|
420
420
|
clock: ClockHead;
|
421
421
|
}>;
|
422
422
|
subscribe<T extends DocTypes>(listener: ListenerFn<T>, updates?: boolean): () => void;
|
423
|
-
query<
|
423
|
+
query<T extends DocTypes, K extends IndexKeyType = string, R extends DocFragment = T>(field: string | MapFn<T>, opts?: QueryOpts<K>): Promise<IndexRows<T, K, R>>;
|
424
424
|
compact(): Promise<void>;
|
425
425
|
}
|
426
426
|
export interface WriteQueue<T extends DocUpdate<S>, S extends DocTypes = DocTypes> {
|
@@ -448,9 +448,9 @@ export interface Ledger extends HasCRDT {
|
|
448
448
|
readonly writeQueue: WriteQueue<DocUpdate<DocTypes>>;
|
449
449
|
readonly logger: Logger;
|
450
450
|
readonly sthis: SuperThis;
|
451
|
-
readonly id: string;
|
452
451
|
readonly name: string;
|
453
452
|
readonly ctx: AppContext;
|
453
|
+
refId(): Promise<string>;
|
454
454
|
onClosed(fn: () => void): () => void;
|
455
455
|
attach(a: Attachable): Promise<Attached>;
|
456
456
|
close(): Promise<void>;
|