@xmtp/browser-sdk 1.1.4 → 2.0.1
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/dist/index.d.ts +776 -27
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/dist/workers/utils.js +1 -1
- package/dist/workers/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/AsyncStream.ts +38 -8
- package/src/Client.ts +351 -72
- package/src/Conversation.ts +104 -13
- package/src/Conversations.ts +130 -0
- package/src/DecodedMessage.ts +20 -12
- package/src/Dm.ts +17 -1
- package/src/Group.ts +124 -9
- package/src/Preferences.ts +54 -0
- package/src/Utils.ts +21 -4
- package/src/UtilsWorkerClass.ts +7 -0
- package/src/WorkerClient.ts +18 -2
- package/src/WorkerConversation.ts +5 -0
- package/src/constants.ts +16 -0
- package/src/index.ts +0 -1
- package/src/types/clientEvents.ts +26 -2
- package/src/types/options.ts +5 -1
- package/src/types/utilsEvents.ts +8 -2
- package/src/utils/conversions.ts +21 -0
- package/src/utils/createClient.ts +4 -3
- package/src/utils/errors.ts +86 -0
- package/src/workers/client.ts +40 -8
- package/src/workers/utils.ts +12 -2
package/src/AsyncStream.ts
CHANGED
|
@@ -13,23 +13,44 @@ export type StreamCallback<T> = (
|
|
|
13
13
|
export class AsyncStream<T> {
|
|
14
14
|
#done = false;
|
|
15
15
|
#resolveNext: ResolveNext<T> | null;
|
|
16
|
+
#rejectNext: ((error: Error) => void) | null;
|
|
16
17
|
#queue: (T | undefined)[];
|
|
17
|
-
|
|
18
|
+
#error: Error | null;
|
|
18
19
|
onReturn: (() => void) | undefined = undefined;
|
|
20
|
+
onError: ((error: Error) => void) | undefined = undefined;
|
|
19
21
|
|
|
20
22
|
constructor() {
|
|
21
23
|
this.#queue = [];
|
|
22
24
|
this.#resolveNext = null;
|
|
25
|
+
this.#rejectNext = null;
|
|
26
|
+
this.#error = null;
|
|
23
27
|
this.#done = false;
|
|
24
28
|
}
|
|
25
29
|
|
|
30
|
+
#endStream() {
|
|
31
|
+
this.#queue = [];
|
|
32
|
+
this.#resolveNext = null;
|
|
33
|
+
this.#rejectNext = null;
|
|
34
|
+
this.#done = true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get error() {
|
|
38
|
+
return this.#error;
|
|
39
|
+
}
|
|
40
|
+
|
|
26
41
|
get isDone() {
|
|
27
42
|
return this.#done;
|
|
28
43
|
}
|
|
29
44
|
|
|
30
45
|
callback: StreamCallback<T> = (error, value) => {
|
|
31
46
|
if (error) {
|
|
32
|
-
|
|
47
|
+
this.#error = error;
|
|
48
|
+
if (this.#rejectNext) {
|
|
49
|
+
this.#rejectNext(error);
|
|
50
|
+
this.#endStream();
|
|
51
|
+
this.onError?.(error);
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
33
54
|
}
|
|
34
55
|
|
|
35
56
|
if (this.#done) {
|
|
@@ -48,25 +69,34 @@ export class AsyncStream<T> {
|
|
|
48
69
|
};
|
|
49
70
|
|
|
50
71
|
next = (): Promise<ResolveValue<T>> => {
|
|
72
|
+
if (this.#error) {
|
|
73
|
+
this.#endStream();
|
|
74
|
+
this.onError?.(this.#error);
|
|
75
|
+
return Promise.reject(this.#error);
|
|
76
|
+
}
|
|
77
|
+
|
|
51
78
|
if (this.#queue.length > 0) {
|
|
52
79
|
return Promise.resolve({
|
|
53
80
|
done: false,
|
|
54
81
|
value: this.#queue.shift(),
|
|
55
82
|
});
|
|
56
|
-
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (this.#done) {
|
|
57
86
|
return Promise.resolve({
|
|
58
87
|
done: true,
|
|
59
88
|
value: undefined,
|
|
60
89
|
});
|
|
61
|
-
} else {
|
|
62
|
-
return new Promise((resolve) => {
|
|
63
|
-
this.#resolveNext = resolve;
|
|
64
|
-
});
|
|
65
90
|
}
|
|
91
|
+
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
this.#resolveNext = resolve;
|
|
94
|
+
this.#rejectNext = reject;
|
|
95
|
+
});
|
|
66
96
|
};
|
|
67
97
|
|
|
68
98
|
return = (value: T | undefined) => {
|
|
69
|
-
this.#
|
|
99
|
+
this.#endStream();
|
|
70
100
|
this.onReturn?.();
|
|
71
101
|
return Promise.resolve({
|
|
72
102
|
done: true,
|