@contello/sdk-client 8.14.0-next.1751836134
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 +53 -0
- package/dist/index.js +1009 -0
- package/dist/index.umd.cjs +3 -0
- package/package.json +48 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DocumentNode } from 'graphql';
|
|
2
|
+
import { ExecutionResult } from 'graphql';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
declare type ClientEventContext = {
|
|
6
|
+
connectionId: string;
|
|
7
|
+
websocketUrl: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export declare class ContelloSdkClient<T> {
|
|
11
|
+
private _pool;
|
|
12
|
+
private _sdk;
|
|
13
|
+
constructor(getSdk: <C, E>(requester: Requester<C, E>) => T, params: ContelloSdkClientParams);
|
|
14
|
+
get sdk(): T;
|
|
15
|
+
connect(): Promise<void>;
|
|
16
|
+
disconnect(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export declare type ContelloSdkClientMiddleware = {
|
|
20
|
+
onRequest?: (request: {
|
|
21
|
+
kind: 'query' | 'mutation' | 'subscription';
|
|
22
|
+
operationName: string;
|
|
23
|
+
query: string;
|
|
24
|
+
variables: Record<string, any>;
|
|
25
|
+
}, next: () => Observable<any>) => Observable<any>;
|
|
26
|
+
onOutgoingMessage?: (message: any) => any;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export declare type ContelloSdkClientParams = {
|
|
30
|
+
url: string;
|
|
31
|
+
project: string;
|
|
32
|
+
token: string;
|
|
33
|
+
middlewares?: ContelloSdkClientMiddleware[] | undefined;
|
|
34
|
+
pooling?: {
|
|
35
|
+
enabled?: boolean | undefined;
|
|
36
|
+
size?: number | undefined;
|
|
37
|
+
} | undefined;
|
|
38
|
+
client?: {
|
|
39
|
+
retryAttempts?: number | undefined;
|
|
40
|
+
onError?: (context: ClientEventContext, error: unknown) => void;
|
|
41
|
+
onConnected?: (context: ClientEventContext) => void;
|
|
42
|
+
onClosed?: (context: ClientEventContext) => void;
|
|
43
|
+
onConnecting?: (context: ClientEventContext) => void;
|
|
44
|
+
onOpened?: (context: ClientEventContext) => void;
|
|
45
|
+
onMessage?: (context: ClientEventContext, message: any) => void;
|
|
46
|
+
onPing?: (context: ClientEventContext) => void;
|
|
47
|
+
onPong?: (context: ClientEventContext) => void;
|
|
48
|
+
} | undefined;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
declare type Requester<C = any, E = unknown> = <R, V>(doc: DocumentNode, vars?: V, options?: C) => Promise<ExecutionResult<R, E>> | Observable<ExecutionResult<R, E>>;
|
|
52
|
+
|
|
53
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,1009 @@
|
|
|
1
|
+
function P(e) {
|
|
2
|
+
return e === null ? "null" : Array.isArray(e) ? "array" : typeof e;
|
|
3
|
+
}
|
|
4
|
+
function R(e) {
|
|
5
|
+
return P(e) === "object";
|
|
6
|
+
}
|
|
7
|
+
function be(e) {
|
|
8
|
+
return Array.isArray(e) && // must be at least one error
|
|
9
|
+
e.length > 0 && // error has at least a message
|
|
10
|
+
e.every((t) => "message" in t);
|
|
11
|
+
}
|
|
12
|
+
function re(e, t) {
|
|
13
|
+
return e.length < 124 ? e : t;
|
|
14
|
+
}
|
|
15
|
+
const me = "graphql-transport-ws";
|
|
16
|
+
var _ = /* @__PURE__ */ ((e) => (e[e.InternalServerError = 4500] = "InternalServerError", e[e.InternalClientError = 4005] = "InternalClientError", e[e.BadRequest = 4400] = "BadRequest", e[e.BadResponse = 4004] = "BadResponse", e[e.Unauthorized = 4401] = "Unauthorized", e[e.Forbidden = 4403] = "Forbidden", e[e.SubprotocolNotAcceptable = 4406] = "SubprotocolNotAcceptable", e[e.ConnectionInitialisationTimeout = 4408] = "ConnectionInitialisationTimeout", e[e.ConnectionAcknowledgementTimeout = 4504] = "ConnectionAcknowledgementTimeout", e[e.SubscriberAlreadyExists = 4409] = "SubscriberAlreadyExists", e[e.TooManyInitialisationRequests = 4429] = "TooManyInitialisationRequests", e))(_ || {}), O = /* @__PURE__ */ ((e) => (e.ConnectionInit = "connection_init", e.ConnectionAck = "connection_ack", e.Ping = "ping", e.Pong = "pong", e.Subscribe = "subscribe", e.Next = "next", e.Error = "error", e.Complete = "complete", e))(O || {});
|
|
17
|
+
function ue(e) {
|
|
18
|
+
if (!R(e))
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Message is expected to be an object, but got ${P(e)}`
|
|
21
|
+
);
|
|
22
|
+
if (!e.type)
|
|
23
|
+
throw new Error("Message is missing the 'type' property");
|
|
24
|
+
if (typeof e.type != "string")
|
|
25
|
+
throw new Error(
|
|
26
|
+
`Message is expects the 'type' property to be a string, but got ${P(
|
|
27
|
+
e.type
|
|
28
|
+
)}`
|
|
29
|
+
);
|
|
30
|
+
switch (e.type) {
|
|
31
|
+
case "connection_init":
|
|
32
|
+
case "connection_ack":
|
|
33
|
+
case "ping":
|
|
34
|
+
case "pong": {
|
|
35
|
+
if (e.payload != null && !R(e.payload))
|
|
36
|
+
throw new Error(
|
|
37
|
+
`"${e.type}" message expects the 'payload' property to be an object or nullish or missing, but got "${e.payload}"`
|
|
38
|
+
);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case "subscribe": {
|
|
42
|
+
if (typeof e.id != "string")
|
|
43
|
+
throw new Error(
|
|
44
|
+
`"${e.type}" message expects the 'id' property to be a string, but got ${P(
|
|
45
|
+
e.id
|
|
46
|
+
)}`
|
|
47
|
+
);
|
|
48
|
+
if (!e.id)
|
|
49
|
+
throw new Error(
|
|
50
|
+
`"${e.type}" message requires a non-empty 'id' property`
|
|
51
|
+
);
|
|
52
|
+
if (!R(e.payload))
|
|
53
|
+
throw new Error(
|
|
54
|
+
`"${e.type}" message expects the 'payload' property to be an object, but got ${P(
|
|
55
|
+
e.payload
|
|
56
|
+
)}`
|
|
57
|
+
);
|
|
58
|
+
if (typeof e.payload.query != "string")
|
|
59
|
+
throw new Error(
|
|
60
|
+
`"${e.type}" message payload expects the 'query' property to be a string, but got ${P(
|
|
61
|
+
e.payload.query
|
|
62
|
+
)}`
|
|
63
|
+
);
|
|
64
|
+
if (e.payload.variables != null && !R(e.payload.variables))
|
|
65
|
+
throw new Error(
|
|
66
|
+
`"${e.type}" message payload expects the 'variables' property to be a an object or nullish or missing, but got ${P(
|
|
67
|
+
e.payload.variables
|
|
68
|
+
)}`
|
|
69
|
+
);
|
|
70
|
+
if (e.payload.operationName != null && P(e.payload.operationName) !== "string")
|
|
71
|
+
throw new Error(
|
|
72
|
+
`"${e.type}" message payload expects the 'operationName' property to be a string or nullish or missing, but got ${P(
|
|
73
|
+
e.payload.operationName
|
|
74
|
+
)}`
|
|
75
|
+
);
|
|
76
|
+
if (e.payload.extensions != null && !R(e.payload.extensions))
|
|
77
|
+
throw new Error(
|
|
78
|
+
`"${e.type}" message payload expects the 'extensions' property to be a an object or nullish or missing, but got ${P(
|
|
79
|
+
e.payload.extensions
|
|
80
|
+
)}`
|
|
81
|
+
);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case "next": {
|
|
85
|
+
if (typeof e.id != "string")
|
|
86
|
+
throw new Error(
|
|
87
|
+
`"${e.type}" message expects the 'id' property to be a string, but got ${P(
|
|
88
|
+
e.id
|
|
89
|
+
)}`
|
|
90
|
+
);
|
|
91
|
+
if (!e.id)
|
|
92
|
+
throw new Error(
|
|
93
|
+
`"${e.type}" message requires a non-empty 'id' property`
|
|
94
|
+
);
|
|
95
|
+
if (!R(e.payload))
|
|
96
|
+
throw new Error(
|
|
97
|
+
`"${e.type}" message expects the 'payload' property to be an object, but got ${P(
|
|
98
|
+
e.payload
|
|
99
|
+
)}`
|
|
100
|
+
);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case "error": {
|
|
104
|
+
if (typeof e.id != "string")
|
|
105
|
+
throw new Error(
|
|
106
|
+
`"${e.type}" message expects the 'id' property to be a string, but got ${P(
|
|
107
|
+
e.id
|
|
108
|
+
)}`
|
|
109
|
+
);
|
|
110
|
+
if (!e.id)
|
|
111
|
+
throw new Error(
|
|
112
|
+
`"${e.type}" message requires a non-empty 'id' property`
|
|
113
|
+
);
|
|
114
|
+
if (!be(e.payload))
|
|
115
|
+
throw new Error(
|
|
116
|
+
`"${e.type}" message expects the 'payload' property to be an array of GraphQL errors, but got ${JSON.stringify(
|
|
117
|
+
e.payload
|
|
118
|
+
)}`
|
|
119
|
+
);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case "complete": {
|
|
123
|
+
if (typeof e.id != "string")
|
|
124
|
+
throw new Error(
|
|
125
|
+
`"${e.type}" message expects the 'id' property to be a string, but got ${P(
|
|
126
|
+
e.id
|
|
127
|
+
)}`
|
|
128
|
+
);
|
|
129
|
+
if (!e.id)
|
|
130
|
+
throw new Error(
|
|
131
|
+
`"${e.type}" message requires a non-empty 'id' property`
|
|
132
|
+
);
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
default:
|
|
136
|
+
throw new Error(`Invalid message 'type' property "${e.type}"`);
|
|
137
|
+
}
|
|
138
|
+
return e;
|
|
139
|
+
}
|
|
140
|
+
function ge(e, t) {
|
|
141
|
+
return ue(
|
|
142
|
+
typeof e == "string" ? JSON.parse(e, t) : e
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
function F(e, t) {
|
|
146
|
+
return ue(e), JSON.stringify(e, t);
|
|
147
|
+
}
|
|
148
|
+
function we(e) {
|
|
149
|
+
const {
|
|
150
|
+
url: t,
|
|
151
|
+
connectionParams: r,
|
|
152
|
+
lazy: n = !0,
|
|
153
|
+
onNonLazyError: s = console.error,
|
|
154
|
+
lazyCloseTimeout: i = 0,
|
|
155
|
+
keepAlive: o = 0,
|
|
156
|
+
disablePong: h,
|
|
157
|
+
connectionAckWaitTimeout: b = 0,
|
|
158
|
+
retryAttempts: A = 5,
|
|
159
|
+
retryWait: w = async function(f) {
|
|
160
|
+
const c = Math.pow(2, f);
|
|
161
|
+
await new Promise(
|
|
162
|
+
(u) => setTimeout(
|
|
163
|
+
u,
|
|
164
|
+
c * 1e3 + // add random timeout from 300ms to 3s
|
|
165
|
+
Math.floor(Math.random() * 2700 + 300)
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
},
|
|
169
|
+
shouldRetry: E = G,
|
|
170
|
+
on: l,
|
|
171
|
+
webSocketImpl: d,
|
|
172
|
+
/**
|
|
173
|
+
* Generates a v4 UUID to be used as the ID using `Math`
|
|
174
|
+
* as the random number generator. Supply your own generator
|
|
175
|
+
* in case you need more uniqueness.
|
|
176
|
+
*
|
|
177
|
+
* Reference: https://gist.github.com/jed/982883
|
|
178
|
+
*/
|
|
179
|
+
generateID: v = function() {
|
|
180
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (f) => {
|
|
181
|
+
const c = Math.random() * 16 | 0;
|
|
182
|
+
return (f == "x" ? c : c & 3 | 8).toString(16);
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
jsonMessageReplacer: m,
|
|
186
|
+
jsonMessageReviver: ye
|
|
187
|
+
} = e;
|
|
188
|
+
let N;
|
|
189
|
+
if (d) {
|
|
190
|
+
if (!xe(d))
|
|
191
|
+
throw new Error("Invalid WebSocket implementation provided");
|
|
192
|
+
N = d;
|
|
193
|
+
} else typeof WebSocket < "u" ? N = WebSocket : typeof global < "u" ? N = global.WebSocket || // @ts-expect-error: Support more browsers
|
|
194
|
+
global.MozWebSocket : typeof window < "u" && (N = window.WebSocket || // @ts-expect-error: Support more browsers
|
|
195
|
+
window.MozWebSocket);
|
|
196
|
+
if (!N)
|
|
197
|
+
throw new Error(
|
|
198
|
+
"WebSocket implementation missing; on Node you can `import WebSocket from 'ws';` and pass `webSocketImpl: WebSocket` to `createClient`"
|
|
199
|
+
);
|
|
200
|
+
const q = N, x = (() => {
|
|
201
|
+
const a = /* @__PURE__ */ (() => {
|
|
202
|
+
const c = {};
|
|
203
|
+
return {
|
|
204
|
+
on(u, y) {
|
|
205
|
+
return c[u] = y, () => {
|
|
206
|
+
delete c[u];
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
emit(u) {
|
|
210
|
+
"id" in u && c[u.id]?.(u);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
})(), f = {
|
|
214
|
+
connecting: l?.connecting ? [l.connecting] : [],
|
|
215
|
+
opened: l?.opened ? [l.opened] : [],
|
|
216
|
+
connected: l?.connected ? [l.connected] : [],
|
|
217
|
+
ping: l?.ping ? [l.ping] : [],
|
|
218
|
+
pong: l?.pong ? [l.pong] : [],
|
|
219
|
+
message: l?.message ? [a.emit, l.message] : [a.emit],
|
|
220
|
+
closed: l?.closed ? [l.closed] : [],
|
|
221
|
+
error: l?.error ? [l.error] : []
|
|
222
|
+
};
|
|
223
|
+
return {
|
|
224
|
+
onMessage: a.on,
|
|
225
|
+
on(c, u) {
|
|
226
|
+
const y = f[c];
|
|
227
|
+
return y.push(u), () => {
|
|
228
|
+
y.splice(y.indexOf(u), 1);
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
emit(c, ...u) {
|
|
232
|
+
for (const y of [...f[c]])
|
|
233
|
+
y(...u);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
})();
|
|
237
|
+
function H(a) {
|
|
238
|
+
const f = [
|
|
239
|
+
// errors are fatal and more critical than close events, throw them first
|
|
240
|
+
x.on("error", (c) => {
|
|
241
|
+
f.forEach((u) => u()), a(c);
|
|
242
|
+
}),
|
|
243
|
+
// closes can be graceful and not fatal, throw them second (if error didnt throw)
|
|
244
|
+
x.on("closed", (c) => {
|
|
245
|
+
f.forEach((u) => u()), a(c);
|
|
246
|
+
})
|
|
247
|
+
];
|
|
248
|
+
}
|
|
249
|
+
let $, I = 0, K, W = !1, B = 0, X = !1;
|
|
250
|
+
async function Z() {
|
|
251
|
+
clearTimeout(K);
|
|
252
|
+
const [a, f] = await ($ ?? ($ = new Promise(
|
|
253
|
+
(y, k) => (async () => {
|
|
254
|
+
if (W) {
|
|
255
|
+
if (await w(B), !I)
|
|
256
|
+
return $ = void 0, k({ code: 1e3, reason: "All Subscriptions Gone" });
|
|
257
|
+
B++;
|
|
258
|
+
}
|
|
259
|
+
x.emit("connecting", W);
|
|
260
|
+
const p = new q(
|
|
261
|
+
typeof t == "function" ? await t() : t,
|
|
262
|
+
me
|
|
263
|
+
);
|
|
264
|
+
let M, z;
|
|
265
|
+
function U() {
|
|
266
|
+
isFinite(o) && o > 0 && (clearTimeout(z), z = setTimeout(() => {
|
|
267
|
+
p.readyState === q.OPEN && (p.send(F({ type: O.Ping })), x.emit("ping", !1, void 0));
|
|
268
|
+
}, o));
|
|
269
|
+
}
|
|
270
|
+
H((S) => {
|
|
271
|
+
$ = void 0, clearTimeout(M), clearTimeout(z), k(S), S instanceof ne && (p.close(4499, "Terminated"), p.onerror = null, p.onclose = null);
|
|
272
|
+
}), p.onerror = (S) => x.emit("error", S), p.onclose = (S) => x.emit("closed", S), p.onopen = async () => {
|
|
273
|
+
try {
|
|
274
|
+
x.emit("opened", p);
|
|
275
|
+
const S = typeof r == "function" ? await r() : r;
|
|
276
|
+
if (p.readyState !== q.OPEN) return;
|
|
277
|
+
p.send(
|
|
278
|
+
F(
|
|
279
|
+
S ? {
|
|
280
|
+
type: O.ConnectionInit,
|
|
281
|
+
payload: S
|
|
282
|
+
} : {
|
|
283
|
+
type: O.ConnectionInit
|
|
284
|
+
// payload is completely absent if not provided
|
|
285
|
+
},
|
|
286
|
+
m
|
|
287
|
+
)
|
|
288
|
+
), isFinite(b) && b > 0 && (M = setTimeout(() => {
|
|
289
|
+
p.close(
|
|
290
|
+
_.ConnectionAcknowledgementTimeout,
|
|
291
|
+
"Connection acknowledgement timeout"
|
|
292
|
+
);
|
|
293
|
+
}, b)), U();
|
|
294
|
+
} catch (S) {
|
|
295
|
+
x.emit("error", S), p.close(
|
|
296
|
+
_.InternalClientError,
|
|
297
|
+
re(
|
|
298
|
+
S instanceof Error ? S.message : String(S),
|
|
299
|
+
"Internal client error"
|
|
300
|
+
)
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
let j = !1;
|
|
305
|
+
p.onmessage = ({ data: S }) => {
|
|
306
|
+
try {
|
|
307
|
+
const g = ge(S, ye);
|
|
308
|
+
if (x.emit("message", g), g.type === "ping" || g.type === "pong") {
|
|
309
|
+
x.emit(g.type, !0, g.payload), g.type === "pong" ? U() : h || (p.send(
|
|
310
|
+
F(
|
|
311
|
+
g.payload ? {
|
|
312
|
+
type: O.Pong,
|
|
313
|
+
payload: g.payload
|
|
314
|
+
} : {
|
|
315
|
+
type: O.Pong
|
|
316
|
+
// payload is completely absent if not provided
|
|
317
|
+
}
|
|
318
|
+
)
|
|
319
|
+
), x.emit("pong", !1, g.payload));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (j) return;
|
|
323
|
+
if (g.type !== O.ConnectionAck)
|
|
324
|
+
throw new Error(
|
|
325
|
+
`First message cannot be of type ${g.type}`
|
|
326
|
+
);
|
|
327
|
+
clearTimeout(M), j = !0, x.emit("connected", p, g.payload, W), W = !1, B = 0, y([
|
|
328
|
+
p,
|
|
329
|
+
new Promise((Fe, he) => H(he))
|
|
330
|
+
]);
|
|
331
|
+
} catch (g) {
|
|
332
|
+
p.onmessage = null, x.emit("error", g), p.close(
|
|
333
|
+
_.BadResponse,
|
|
334
|
+
re(
|
|
335
|
+
g instanceof Error ? g.message : String(g),
|
|
336
|
+
"Bad response"
|
|
337
|
+
)
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
})()
|
|
342
|
+
)));
|
|
343
|
+
a.readyState === q.CLOSING && await f;
|
|
344
|
+
let c = () => {
|
|
345
|
+
};
|
|
346
|
+
const u = new Promise((y) => c = y);
|
|
347
|
+
return [
|
|
348
|
+
a,
|
|
349
|
+
c,
|
|
350
|
+
Promise.race([
|
|
351
|
+
// wait for
|
|
352
|
+
u.then(() => {
|
|
353
|
+
if (!I) {
|
|
354
|
+
const y = () => a.close(1e3, "Normal Closure");
|
|
355
|
+
isFinite(i) && i > 0 ? K = setTimeout(() => {
|
|
356
|
+
a.readyState === q.OPEN && y();
|
|
357
|
+
}, i) : y();
|
|
358
|
+
}
|
|
359
|
+
}),
|
|
360
|
+
// or
|
|
361
|
+
f
|
|
362
|
+
])
|
|
363
|
+
];
|
|
364
|
+
}
|
|
365
|
+
function ee(a) {
|
|
366
|
+
if (G(a) && (Ee(a.code) || [
|
|
367
|
+
_.InternalServerError,
|
|
368
|
+
_.InternalClientError,
|
|
369
|
+
_.BadRequest,
|
|
370
|
+
_.BadResponse,
|
|
371
|
+
_.Unauthorized,
|
|
372
|
+
// CloseCode.Forbidden, might grant access out after retry
|
|
373
|
+
_.SubprotocolNotAcceptable,
|
|
374
|
+
// CloseCode.ConnectionInitialisationTimeout, might not time out after retry
|
|
375
|
+
// CloseCode.ConnectionAcknowledgementTimeout, might not time out after retry
|
|
376
|
+
_.SubscriberAlreadyExists,
|
|
377
|
+
_.TooManyInitialisationRequests
|
|
378
|
+
// 4499, // Terminated, probably because the socket froze, we want to retry
|
|
379
|
+
].includes(a.code)))
|
|
380
|
+
throw a;
|
|
381
|
+
if (X) return !1;
|
|
382
|
+
if (G(a) && a.code === 1e3)
|
|
383
|
+
return I > 0;
|
|
384
|
+
if (!A || B >= A || !E(a)) throw a;
|
|
385
|
+
return W = !0;
|
|
386
|
+
}
|
|
387
|
+
n || (async () => {
|
|
388
|
+
for (I++; ; )
|
|
389
|
+
try {
|
|
390
|
+
const [, , a] = await Z();
|
|
391
|
+
await a;
|
|
392
|
+
} catch (a) {
|
|
393
|
+
try {
|
|
394
|
+
if (!ee(a)) return;
|
|
395
|
+
} catch (f) {
|
|
396
|
+
return s?.(f);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
})();
|
|
400
|
+
function te(a, f) {
|
|
401
|
+
const c = v(a);
|
|
402
|
+
let u = !1, y = !1, k = () => {
|
|
403
|
+
I--, u = !0;
|
|
404
|
+
};
|
|
405
|
+
return (async () => {
|
|
406
|
+
for (I++; ; )
|
|
407
|
+
try {
|
|
408
|
+
const [p, M, z] = await Z();
|
|
409
|
+
if (u) return M();
|
|
410
|
+
const U = x.onMessage(c, (j) => {
|
|
411
|
+
switch (j.type) {
|
|
412
|
+
case O.Next: {
|
|
413
|
+
f.next(j.payload);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
case O.Error: {
|
|
417
|
+
y = !0, u = !0, f.error(j.payload), k();
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
case O.Complete: {
|
|
421
|
+
u = !0, k();
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
p.send(
|
|
427
|
+
F(
|
|
428
|
+
{
|
|
429
|
+
id: c,
|
|
430
|
+
type: O.Subscribe,
|
|
431
|
+
payload: a
|
|
432
|
+
},
|
|
433
|
+
m
|
|
434
|
+
)
|
|
435
|
+
), k = () => {
|
|
436
|
+
!u && p.readyState === q.OPEN && p.send(
|
|
437
|
+
F(
|
|
438
|
+
{
|
|
439
|
+
id: c,
|
|
440
|
+
type: O.Complete
|
|
441
|
+
},
|
|
442
|
+
m
|
|
443
|
+
)
|
|
444
|
+
), I--, u = !0, M();
|
|
445
|
+
}, await z.finally(U);
|
|
446
|
+
return;
|
|
447
|
+
} catch (p) {
|
|
448
|
+
if (!ee(p)) return;
|
|
449
|
+
}
|
|
450
|
+
})().then(() => {
|
|
451
|
+
y || f.complete();
|
|
452
|
+
}).catch((p) => {
|
|
453
|
+
f.error(p);
|
|
454
|
+
}), () => {
|
|
455
|
+
u || k();
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
return {
|
|
459
|
+
on: x.on,
|
|
460
|
+
subscribe: te,
|
|
461
|
+
iterate(a) {
|
|
462
|
+
const f = [], c = {
|
|
463
|
+
done: !1,
|
|
464
|
+
error: null,
|
|
465
|
+
resolve: () => {
|
|
466
|
+
}
|
|
467
|
+
}, u = te(a, {
|
|
468
|
+
next(k) {
|
|
469
|
+
f.push(k), c.resolve();
|
|
470
|
+
},
|
|
471
|
+
error(k) {
|
|
472
|
+
c.done = !0, c.error = k, c.resolve();
|
|
473
|
+
},
|
|
474
|
+
complete() {
|
|
475
|
+
c.done = !0, c.resolve();
|
|
476
|
+
}
|
|
477
|
+
}), y = async function* () {
|
|
478
|
+
for (; ; ) {
|
|
479
|
+
for (f.length || await new Promise((p) => c.resolve = p); f.length; )
|
|
480
|
+
yield f.shift();
|
|
481
|
+
if (c.error)
|
|
482
|
+
throw c.error;
|
|
483
|
+
if (c.done)
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
}();
|
|
487
|
+
return y.throw = async (k) => (c.done || (c.done = !0, c.error = k, c.resolve()), { done: !0, value: void 0 }), y.return = async () => (u(), { done: !0, value: void 0 }), y;
|
|
488
|
+
},
|
|
489
|
+
async dispose() {
|
|
490
|
+
if (X = !0, $) {
|
|
491
|
+
const [a] = await $;
|
|
492
|
+
a.close(1e3, "Normal Closure");
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
terminate() {
|
|
496
|
+
$ && x.emit("closed", new ne());
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
class ne extends Error {
|
|
501
|
+
name = "TerminatedCloseEvent";
|
|
502
|
+
message = "4499: Terminated";
|
|
503
|
+
code = 4499;
|
|
504
|
+
reason = "Terminated";
|
|
505
|
+
wasClean = !1;
|
|
506
|
+
}
|
|
507
|
+
function G(e) {
|
|
508
|
+
return R(e) && "code" in e && "reason" in e;
|
|
509
|
+
}
|
|
510
|
+
function Ee(e) {
|
|
511
|
+
return [
|
|
512
|
+
1e3,
|
|
513
|
+
// Normal Closure is not an erroneous close code
|
|
514
|
+
1001,
|
|
515
|
+
// Going Away
|
|
516
|
+
1006,
|
|
517
|
+
// Abnormal Closure
|
|
518
|
+
1005,
|
|
519
|
+
// No Status Received
|
|
520
|
+
1012,
|
|
521
|
+
// Service Restart
|
|
522
|
+
1013,
|
|
523
|
+
// Try Again Later
|
|
524
|
+
1014
|
|
525
|
+
// Bad Gateway
|
|
526
|
+
].includes(e) ? !1 : e >= 1e3 && e <= 1999;
|
|
527
|
+
}
|
|
528
|
+
function xe(e) {
|
|
529
|
+
return typeof e == "function" && "constructor" in e && "CLOSED" in e && "CLOSING" in e && "CONNECTING" in e && "OPEN" in e;
|
|
530
|
+
}
|
|
531
|
+
var J = function(e, t) {
|
|
532
|
+
return J = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(r, n) {
|
|
533
|
+
r.__proto__ = n;
|
|
534
|
+
} || function(r, n) {
|
|
535
|
+
for (var s in n) Object.prototype.hasOwnProperty.call(n, s) && (r[s] = n[s]);
|
|
536
|
+
}, J(e, t);
|
|
537
|
+
};
|
|
538
|
+
function pe(e, t) {
|
|
539
|
+
if (typeof t != "function" && t !== null)
|
|
540
|
+
throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
|
|
541
|
+
J(e, t);
|
|
542
|
+
function r() {
|
|
543
|
+
this.constructor = e;
|
|
544
|
+
}
|
|
545
|
+
e.prototype = t === null ? Object.create(t) : (r.prototype = t.prototype, new r());
|
|
546
|
+
}
|
|
547
|
+
function oe(e) {
|
|
548
|
+
var t = typeof Symbol == "function" && Symbol.iterator, r = t && e[t], n = 0;
|
|
549
|
+
if (r) return r.call(e);
|
|
550
|
+
if (e && typeof e.length == "number") return {
|
|
551
|
+
next: function() {
|
|
552
|
+
return e && n >= e.length && (e = void 0), { value: e && e[n++], done: !e };
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
556
|
+
}
|
|
557
|
+
function Q(e, t) {
|
|
558
|
+
var r = typeof Symbol == "function" && e[Symbol.iterator];
|
|
559
|
+
if (!r) return e;
|
|
560
|
+
var n = r.call(e), s, i = [], o;
|
|
561
|
+
try {
|
|
562
|
+
for (; (t === void 0 || t-- > 0) && !(s = n.next()).done; ) i.push(s.value);
|
|
563
|
+
} catch (h) {
|
|
564
|
+
o = { error: h };
|
|
565
|
+
} finally {
|
|
566
|
+
try {
|
|
567
|
+
s && !s.done && (r = n.return) && r.call(n);
|
|
568
|
+
} finally {
|
|
569
|
+
if (o) throw o.error;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return i;
|
|
573
|
+
}
|
|
574
|
+
function V(e, t, r) {
|
|
575
|
+
if (r || arguments.length === 2) for (var n = 0, s = t.length, i; n < s; n++)
|
|
576
|
+
(i || !(n in t)) && (i || (i = Array.prototype.slice.call(t, 0, n)), i[n] = t[n]);
|
|
577
|
+
return e.concat(i || Array.prototype.slice.call(t));
|
|
578
|
+
}
|
|
579
|
+
function T(e) {
|
|
580
|
+
return typeof e == "function";
|
|
581
|
+
}
|
|
582
|
+
function le(e) {
|
|
583
|
+
var t = function(n) {
|
|
584
|
+
Error.call(n), n.stack = new Error().stack;
|
|
585
|
+
}, r = e(t);
|
|
586
|
+
return r.prototype = Object.create(Error.prototype), r.prototype.constructor = r, r;
|
|
587
|
+
}
|
|
588
|
+
var D = le(function(e) {
|
|
589
|
+
return function(r) {
|
|
590
|
+
e(this), this.message = r ? r.length + ` errors occurred during unsubscription:
|
|
591
|
+
` + r.map(function(n, s) {
|
|
592
|
+
return s + 1 + ") " + n.toString();
|
|
593
|
+
}).join(`
|
|
594
|
+
`) : "", this.name = "UnsubscriptionError", this.errors = r;
|
|
595
|
+
};
|
|
596
|
+
});
|
|
597
|
+
function ie(e, t) {
|
|
598
|
+
if (e) {
|
|
599
|
+
var r = e.indexOf(t);
|
|
600
|
+
0 <= r && e.splice(r, 1);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
var Y = function() {
|
|
604
|
+
function e(t) {
|
|
605
|
+
this.initialTeardown = t, this.closed = !1, this._parentage = null, this._finalizers = null;
|
|
606
|
+
}
|
|
607
|
+
return e.prototype.unsubscribe = function() {
|
|
608
|
+
var t, r, n, s, i;
|
|
609
|
+
if (!this.closed) {
|
|
610
|
+
this.closed = !0;
|
|
611
|
+
var o = this._parentage;
|
|
612
|
+
if (o)
|
|
613
|
+
if (this._parentage = null, Array.isArray(o))
|
|
614
|
+
try {
|
|
615
|
+
for (var h = oe(o), b = h.next(); !b.done; b = h.next()) {
|
|
616
|
+
var A = b.value;
|
|
617
|
+
A.remove(this);
|
|
618
|
+
}
|
|
619
|
+
} catch (m) {
|
|
620
|
+
t = { error: m };
|
|
621
|
+
} finally {
|
|
622
|
+
try {
|
|
623
|
+
b && !b.done && (r = h.return) && r.call(h);
|
|
624
|
+
} finally {
|
|
625
|
+
if (t) throw t.error;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
else
|
|
629
|
+
o.remove(this);
|
|
630
|
+
var w = this.initialTeardown;
|
|
631
|
+
if (T(w))
|
|
632
|
+
try {
|
|
633
|
+
w();
|
|
634
|
+
} catch (m) {
|
|
635
|
+
i = m instanceof D ? m.errors : [m];
|
|
636
|
+
}
|
|
637
|
+
var E = this._finalizers;
|
|
638
|
+
if (E) {
|
|
639
|
+
this._finalizers = null;
|
|
640
|
+
try {
|
|
641
|
+
for (var l = oe(E), d = l.next(); !d.done; d = l.next()) {
|
|
642
|
+
var v = d.value;
|
|
643
|
+
try {
|
|
644
|
+
se(v);
|
|
645
|
+
} catch (m) {
|
|
646
|
+
i = i ?? [], m instanceof D ? i = V(V([], Q(i)), Q(m.errors)) : i.push(m);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
} catch (m) {
|
|
650
|
+
n = { error: m };
|
|
651
|
+
} finally {
|
|
652
|
+
try {
|
|
653
|
+
d && !d.done && (s = l.return) && s.call(l);
|
|
654
|
+
} finally {
|
|
655
|
+
if (n) throw n.error;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (i)
|
|
660
|
+
throw new D(i);
|
|
661
|
+
}
|
|
662
|
+
}, e.prototype.add = function(t) {
|
|
663
|
+
var r;
|
|
664
|
+
if (t && t !== this)
|
|
665
|
+
if (this.closed)
|
|
666
|
+
se(t);
|
|
667
|
+
else {
|
|
668
|
+
if (t instanceof e) {
|
|
669
|
+
if (t.closed || t._hasParent(this))
|
|
670
|
+
return;
|
|
671
|
+
t._addParent(this);
|
|
672
|
+
}
|
|
673
|
+
(this._finalizers = (r = this._finalizers) !== null && r !== void 0 ? r : []).push(t);
|
|
674
|
+
}
|
|
675
|
+
}, e.prototype._hasParent = function(t) {
|
|
676
|
+
var r = this._parentage;
|
|
677
|
+
return r === t || Array.isArray(r) && r.includes(t);
|
|
678
|
+
}, e.prototype._addParent = function(t) {
|
|
679
|
+
var r = this._parentage;
|
|
680
|
+
this._parentage = Array.isArray(r) ? (r.push(t), r) : r ? [r, t] : t;
|
|
681
|
+
}, e.prototype._removeParent = function(t) {
|
|
682
|
+
var r = this._parentage;
|
|
683
|
+
r === t ? this._parentage = null : Array.isArray(r) && ie(r, t);
|
|
684
|
+
}, e.prototype.remove = function(t) {
|
|
685
|
+
var r = this._finalizers;
|
|
686
|
+
r && ie(r, t), t instanceof e && t._removeParent(this);
|
|
687
|
+
}, e.EMPTY = function() {
|
|
688
|
+
var t = new e();
|
|
689
|
+
return t.closed = !0, t;
|
|
690
|
+
}(), e;
|
|
691
|
+
}();
|
|
692
|
+
Y.EMPTY;
|
|
693
|
+
function fe(e) {
|
|
694
|
+
return e instanceof Y || e && "closed" in e && T(e.remove) && T(e.add) && T(e.unsubscribe);
|
|
695
|
+
}
|
|
696
|
+
function se(e) {
|
|
697
|
+
T(e) ? e() : e.unsubscribe();
|
|
698
|
+
}
|
|
699
|
+
var Se = {
|
|
700
|
+
Promise: void 0
|
|
701
|
+
}, ke = {
|
|
702
|
+
setTimeout: function(e, t) {
|
|
703
|
+
for (var r = [], n = 2; n < arguments.length; n++)
|
|
704
|
+
r[n - 2] = arguments[n];
|
|
705
|
+
return setTimeout.apply(void 0, V([e, t], Q(r)));
|
|
706
|
+
},
|
|
707
|
+
clearTimeout: function(e) {
|
|
708
|
+
return clearTimeout(e);
|
|
709
|
+
},
|
|
710
|
+
delegate: void 0
|
|
711
|
+
};
|
|
712
|
+
function Pe(e) {
|
|
713
|
+
ke.setTimeout(function() {
|
|
714
|
+
throw e;
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
function ce() {
|
|
718
|
+
}
|
|
719
|
+
function ve(e) {
|
|
720
|
+
e();
|
|
721
|
+
}
|
|
722
|
+
var de = function(e) {
|
|
723
|
+
pe(t, e);
|
|
724
|
+
function t(r) {
|
|
725
|
+
var n = e.call(this) || this;
|
|
726
|
+
return n.isStopped = !1, r ? (n.destination = r, fe(r) && r.add(n)) : n.destination = Te, n;
|
|
727
|
+
}
|
|
728
|
+
return t.create = function(r, n, s) {
|
|
729
|
+
return new C(r, n, s);
|
|
730
|
+
}, t.prototype.next = function(r) {
|
|
731
|
+
this.isStopped || this._next(r);
|
|
732
|
+
}, t.prototype.error = function(r) {
|
|
733
|
+
this.isStopped || (this.isStopped = !0, this._error(r));
|
|
734
|
+
}, t.prototype.complete = function() {
|
|
735
|
+
this.isStopped || (this.isStopped = !0, this._complete());
|
|
736
|
+
}, t.prototype.unsubscribe = function() {
|
|
737
|
+
this.closed || (this.isStopped = !0, e.prototype.unsubscribe.call(this), this.destination = null);
|
|
738
|
+
}, t.prototype._next = function(r) {
|
|
739
|
+
this.destination.next(r);
|
|
740
|
+
}, t.prototype._error = function(r) {
|
|
741
|
+
try {
|
|
742
|
+
this.destination.error(r);
|
|
743
|
+
} finally {
|
|
744
|
+
this.unsubscribe();
|
|
745
|
+
}
|
|
746
|
+
}, t.prototype._complete = function() {
|
|
747
|
+
try {
|
|
748
|
+
this.destination.complete();
|
|
749
|
+
} finally {
|
|
750
|
+
this.unsubscribe();
|
|
751
|
+
}
|
|
752
|
+
}, t;
|
|
753
|
+
}(Y), _e = function() {
|
|
754
|
+
function e(t) {
|
|
755
|
+
this.partialObserver = t;
|
|
756
|
+
}
|
|
757
|
+
return e.prototype.next = function(t) {
|
|
758
|
+
var r = this.partialObserver;
|
|
759
|
+
if (r.next)
|
|
760
|
+
try {
|
|
761
|
+
r.next(t);
|
|
762
|
+
} catch (n) {
|
|
763
|
+
L(n);
|
|
764
|
+
}
|
|
765
|
+
}, e.prototype.error = function(t) {
|
|
766
|
+
var r = this.partialObserver;
|
|
767
|
+
if (r.error)
|
|
768
|
+
try {
|
|
769
|
+
r.error(t);
|
|
770
|
+
} catch (n) {
|
|
771
|
+
L(n);
|
|
772
|
+
}
|
|
773
|
+
else
|
|
774
|
+
L(t);
|
|
775
|
+
}, e.prototype.complete = function() {
|
|
776
|
+
var t = this.partialObserver;
|
|
777
|
+
if (t.complete)
|
|
778
|
+
try {
|
|
779
|
+
t.complete();
|
|
780
|
+
} catch (r) {
|
|
781
|
+
L(r);
|
|
782
|
+
}
|
|
783
|
+
}, e;
|
|
784
|
+
}(), C = function(e) {
|
|
785
|
+
pe(t, e);
|
|
786
|
+
function t(r, n, s) {
|
|
787
|
+
var i = e.call(this) || this, o;
|
|
788
|
+
return T(r) || !r ? o = {
|
|
789
|
+
next: r ?? void 0,
|
|
790
|
+
error: n ?? void 0,
|
|
791
|
+
complete: s ?? void 0
|
|
792
|
+
} : o = r, i.destination = new _e(o), i;
|
|
793
|
+
}
|
|
794
|
+
return t;
|
|
795
|
+
}(de);
|
|
796
|
+
function L(e) {
|
|
797
|
+
Pe(e);
|
|
798
|
+
}
|
|
799
|
+
function Oe(e) {
|
|
800
|
+
throw e;
|
|
801
|
+
}
|
|
802
|
+
var Te = {
|
|
803
|
+
closed: !0,
|
|
804
|
+
next: ce,
|
|
805
|
+
error: Oe,
|
|
806
|
+
complete: ce
|
|
807
|
+
}, Ae = function() {
|
|
808
|
+
return typeof Symbol == "function" && Symbol.observable || "@@observable";
|
|
809
|
+
}();
|
|
810
|
+
function $e(e) {
|
|
811
|
+
return e;
|
|
812
|
+
}
|
|
813
|
+
function Ie(e) {
|
|
814
|
+
return e.length === 0 ? $e : e.length === 1 ? e[0] : function(r) {
|
|
815
|
+
return e.reduce(function(n, s) {
|
|
816
|
+
return s(n);
|
|
817
|
+
}, r);
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
var Re = function() {
|
|
821
|
+
function e(t) {
|
|
822
|
+
t && (this._subscribe = t);
|
|
823
|
+
}
|
|
824
|
+
return e.prototype.lift = function(t) {
|
|
825
|
+
var r = new e();
|
|
826
|
+
return r.source = this, r.operator = t, r;
|
|
827
|
+
}, e.prototype.subscribe = function(t, r, n) {
|
|
828
|
+
var s = this, i = qe(t) ? t : new C(t, r, n);
|
|
829
|
+
return ve(function() {
|
|
830
|
+
var o = s, h = o.operator, b = o.source;
|
|
831
|
+
i.add(h ? h.call(i, b) : b ? s._subscribe(i) : s._trySubscribe(i));
|
|
832
|
+
}), i;
|
|
833
|
+
}, e.prototype._trySubscribe = function(t) {
|
|
834
|
+
try {
|
|
835
|
+
return this._subscribe(t);
|
|
836
|
+
} catch (r) {
|
|
837
|
+
t.error(r);
|
|
838
|
+
}
|
|
839
|
+
}, e.prototype.forEach = function(t, r) {
|
|
840
|
+
var n = this;
|
|
841
|
+
return r = ae(r), new r(function(s, i) {
|
|
842
|
+
var o = new C({
|
|
843
|
+
next: function(h) {
|
|
844
|
+
try {
|
|
845
|
+
t(h);
|
|
846
|
+
} catch (b) {
|
|
847
|
+
i(b), o.unsubscribe();
|
|
848
|
+
}
|
|
849
|
+
},
|
|
850
|
+
error: i,
|
|
851
|
+
complete: s
|
|
852
|
+
});
|
|
853
|
+
n.subscribe(o);
|
|
854
|
+
});
|
|
855
|
+
}, e.prototype._subscribe = function(t) {
|
|
856
|
+
var r;
|
|
857
|
+
return (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t);
|
|
858
|
+
}, e.prototype[Ae] = function() {
|
|
859
|
+
return this;
|
|
860
|
+
}, e.prototype.pipe = function() {
|
|
861
|
+
for (var t = [], r = 0; r < arguments.length; r++)
|
|
862
|
+
t[r] = arguments[r];
|
|
863
|
+
return Ie(t)(this);
|
|
864
|
+
}, e.prototype.toPromise = function(t) {
|
|
865
|
+
var r = this;
|
|
866
|
+
return t = ae(t), new t(function(n, s) {
|
|
867
|
+
var i;
|
|
868
|
+
r.subscribe(function(o) {
|
|
869
|
+
return i = o;
|
|
870
|
+
}, function(o) {
|
|
871
|
+
return s(o);
|
|
872
|
+
}, function() {
|
|
873
|
+
return n(i);
|
|
874
|
+
});
|
|
875
|
+
});
|
|
876
|
+
}, e.create = function(t) {
|
|
877
|
+
return new e(t);
|
|
878
|
+
}, e;
|
|
879
|
+
}();
|
|
880
|
+
function ae(e) {
|
|
881
|
+
var t;
|
|
882
|
+
return (t = e ?? Se.Promise) !== null && t !== void 0 ? t : Promise;
|
|
883
|
+
}
|
|
884
|
+
function Ne(e) {
|
|
885
|
+
return e && T(e.next) && T(e.error) && T(e.complete);
|
|
886
|
+
}
|
|
887
|
+
function qe(e) {
|
|
888
|
+
return e && e instanceof de || Ne(e) && fe(e);
|
|
889
|
+
}
|
|
890
|
+
var Me = le(function(e) {
|
|
891
|
+
return function() {
|
|
892
|
+
e(this), this.name = "EmptyError", this.message = "no elements in sequence";
|
|
893
|
+
};
|
|
894
|
+
});
|
|
895
|
+
function je(e, t) {
|
|
896
|
+
return new Promise(function(r, n) {
|
|
897
|
+
var s = new C({
|
|
898
|
+
next: function(i) {
|
|
899
|
+
r(i), s.unsubscribe();
|
|
900
|
+
},
|
|
901
|
+
error: n,
|
|
902
|
+
complete: function() {
|
|
903
|
+
n(new Me());
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
e.subscribe(s);
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
class We {
|
|
910
|
+
constructor(t, r) {
|
|
911
|
+
this.createClient = t, this.poolSize = r;
|
|
912
|
+
}
|
|
913
|
+
clients = [];
|
|
914
|
+
currentIndex = 0;
|
|
915
|
+
connect() {
|
|
916
|
+
for (let t = 0; t < this.poolSize; t++)
|
|
917
|
+
this.clients.push(this.createClient(`${t + 1}`));
|
|
918
|
+
}
|
|
919
|
+
get() {
|
|
920
|
+
if (this.clients.length === 0)
|
|
921
|
+
throw new Error("Connection pool is empty. Please call connect() first.");
|
|
922
|
+
const t = this.clients[this.currentIndex];
|
|
923
|
+
if (this.currentIndex = (this.currentIndex + 1) % this.poolSize, !t)
|
|
924
|
+
throw new Error("No available WebSocket client");
|
|
925
|
+
return t;
|
|
926
|
+
}
|
|
927
|
+
disconnect() {
|
|
928
|
+
this.clients.forEach((t) => t.dispose()), this.clients = [];
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
const ze = (e, t, r) => r((n, s, i) => {
|
|
932
|
+
i && console.warn("options are not supported yet");
|
|
933
|
+
const o = n.loc?.source.body;
|
|
934
|
+
if (!o)
|
|
935
|
+
throw new Error("No query provided");
|
|
936
|
+
if (s && typeof s != "object")
|
|
937
|
+
throw new Error("Variables must be an object");
|
|
938
|
+
const h = n.definitions.find((d) => d.kind === "OperationDefinition");
|
|
939
|
+
if (!h)
|
|
940
|
+
throw new Error("No operation definition found");
|
|
941
|
+
const b = h.operation, A = () => {
|
|
942
|
+
const d = e();
|
|
943
|
+
return new Re((v) => d.subscribe({ query: o, variables: s }, v));
|
|
944
|
+
}, w = {
|
|
945
|
+
kind: b,
|
|
946
|
+
operationName: h.name?.value ?? "",
|
|
947
|
+
query: o,
|
|
948
|
+
variables: s || {}
|
|
949
|
+
}, E = (d, v) => {
|
|
950
|
+
if (v >= d.length)
|
|
951
|
+
return A();
|
|
952
|
+
const m = d[v];
|
|
953
|
+
return m?.onRequest ? m.onRequest(w, () => E(d, v + 1)) : E(d, v + 1);
|
|
954
|
+
}, l = E(t, 0);
|
|
955
|
+
return b !== "subscription" ? je(l) : l;
|
|
956
|
+
});
|
|
957
|
+
class Be {
|
|
958
|
+
_pool;
|
|
959
|
+
_sdk;
|
|
960
|
+
constructor(t, r) {
|
|
961
|
+
const { url: n, project: s, token: i, client: o, pooling: h } = r, b = `${n}/graphql/projects/${s}`.replace(/^http/i, "ws");
|
|
962
|
+
this._pool = new We(
|
|
963
|
+
(A) => {
|
|
964
|
+
const w = Object.freeze({ connectionId: A, websocketUrl: b });
|
|
965
|
+
return we({
|
|
966
|
+
url: b,
|
|
967
|
+
connectionParams: { authorization: `Bearer ${i}` },
|
|
968
|
+
lazy: !1,
|
|
969
|
+
keepAlive: 3e4,
|
|
970
|
+
retryAttempts: o?.retryAttempts ?? 3,
|
|
971
|
+
shouldRetry: () => !0,
|
|
972
|
+
jsonMessageReplacer: (E, l) => {
|
|
973
|
+
if (!E) {
|
|
974
|
+
let d = l;
|
|
975
|
+
for (const v of r.middlewares ?? [])
|
|
976
|
+
v.onOutgoingMessage && (d = v.onOutgoingMessage(d));
|
|
977
|
+
return d;
|
|
978
|
+
}
|
|
979
|
+
return l;
|
|
980
|
+
},
|
|
981
|
+
...o?.onError ? { onNonLazyError: (E) => o.onError(w, E) } : {},
|
|
982
|
+
on: {
|
|
983
|
+
...o?.onError ? { error: (E) => o.onError(w, E) } : {},
|
|
984
|
+
...o?.onConnected ? { connected: () => o.onConnected(w) } : {},
|
|
985
|
+
...o?.onClosed ? { closed: () => o.onClosed(w) } : {},
|
|
986
|
+
...o?.onConnecting ? { connecting: () => o.onConnecting(w) } : {},
|
|
987
|
+
...o?.onOpened ? { opened: () => o.onOpened(w) } : {},
|
|
988
|
+
...o?.onMessage ? { message: (E) => o.onMessage(w, E) } : {},
|
|
989
|
+
...o?.onPing ? { ping: () => o.onPing(w) } : {},
|
|
990
|
+
...o?.onPong ? { pong: () => o.onPong(w) } : {}
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
},
|
|
994
|
+
h?.enabled === !1 ? 1 : h?.size ?? 5
|
|
995
|
+
), this._sdk = { sdk: ze(() => this._pool.get(), r.middlewares ?? [], t) };
|
|
996
|
+
}
|
|
997
|
+
get sdk() {
|
|
998
|
+
return this._sdk.sdk;
|
|
999
|
+
}
|
|
1000
|
+
async connect() {
|
|
1001
|
+
this._pool.connect();
|
|
1002
|
+
}
|
|
1003
|
+
async disconnect() {
|
|
1004
|
+
this._pool.disconnect();
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
export {
|
|
1008
|
+
Be as ContelloSdkClient
|
|
1009
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(function(N,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(N=typeof globalThis<"u"?globalThis:N||self,m(N.ContelloSdkClient={}))})(this,function(N){"use strict";function m(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function $(e){return m(e)==="object"}function he(e){return Array.isArray(e)&&e.length>0&&e.every(t=>"message"in t)}function K(e,t){return e.length<124?e:t}const be="graphql-transport-ws";var T=(e=>(e[e.InternalServerError=4500]="InternalServerError",e[e.InternalClientError=4005]="InternalClientError",e[e.BadRequest=4400]="BadRequest",e[e.BadResponse=4004]="BadResponse",e[e.Unauthorized=4401]="Unauthorized",e[e.Forbidden=4403]="Forbidden",e[e.SubprotocolNotAcceptable=4406]="SubprotocolNotAcceptable",e[e.ConnectionInitialisationTimeout=4408]="ConnectionInitialisationTimeout",e[e.ConnectionAcknowledgementTimeout=4504]="ConnectionAcknowledgementTimeout",e[e.SubscriberAlreadyExists=4409]="SubscriberAlreadyExists",e[e.TooManyInitialisationRequests=4429]="TooManyInitialisationRequests",e))(T||{}),O=(e=>(e.ConnectionInit="connection_init",e.ConnectionAck="connection_ack",e.Ping="ping",e.Pong="pong",e.Subscribe="subscribe",e.Next="next",e.Error="error",e.Complete="complete",e))(O||{});function X(e){if(!$(e))throw new Error(`Message is expected to be an object, but got ${m(e)}`);if(!e.type)throw new Error("Message is missing the 'type' property");if(typeof e.type!="string")throw new Error(`Message is expects the 'type' property to be a string, but got ${m(e.type)}`);switch(e.type){case"connection_init":case"connection_ack":case"ping":case"pong":{if(e.payload!=null&&!$(e.payload))throw new Error(`"${e.type}" message expects the 'payload' property to be an object or nullish or missing, but got "${e.payload}"`);break}case"subscribe":{if(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${m(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);if(!$(e.payload))throw new Error(`"${e.type}" message expects the 'payload' property to be an object, but got ${m(e.payload)}`);if(typeof e.payload.query!="string")throw new Error(`"${e.type}" message payload expects the 'query' property to be a string, but got ${m(e.payload.query)}`);if(e.payload.variables!=null&&!$(e.payload.variables))throw new Error(`"${e.type}" message payload expects the 'variables' property to be a an object or nullish or missing, but got ${m(e.payload.variables)}`);if(e.payload.operationName!=null&&m(e.payload.operationName)!=="string")throw new Error(`"${e.type}" message payload expects the 'operationName' property to be a string or nullish or missing, but got ${m(e.payload.operationName)}`);if(e.payload.extensions!=null&&!$(e.payload.extensions))throw new Error(`"${e.type}" message payload expects the 'extensions' property to be a an object or nullish or missing, but got ${m(e.payload.extensions)}`);break}case"next":{if(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${m(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);if(!$(e.payload))throw new Error(`"${e.type}" message expects the 'payload' property to be an object, but got ${m(e.payload)}`);break}case"error":{if(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${m(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);if(!he(e.payload))throw new Error(`"${e.type}" message expects the 'payload' property to be an array of GraphQL errors, but got ${JSON.stringify(e.payload)}`);break}case"complete":{if(typeof e.id!="string")throw new Error(`"${e.type}" message expects the 'id' property to be a string, but got ${m(e.id)}`);if(!e.id)throw new Error(`"${e.type}" message requires a non-empty 'id' property`);break}default:throw new Error(`Invalid message 'type' property "${e.type}"`)}return e}function me(e,t){return X(typeof e=="string"?JSON.parse(e,t):e)}function z(e,t){return X(e),JSON.stringify(e,t)}function ge(e){const{url:t,connectionParams:r,lazy:n=!0,onNonLazyError:s=console.error,lazyCloseTimeout:i=0,keepAlive:o=0,disablePong:h,connectionAckWaitTimeout:b=0,retryAttempts:A=5,retryWait:E=async function(f){const c=Math.pow(2,f);await new Promise(u=>setTimeout(u,c*1e3+Math.floor(Math.random()*2700+300)))},shouldRetry:S=D,on:l,webSocketImpl:d,generateID:v=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,f=>{const c=Math.random()*16|0;return(f=="x"?c:c&3|8).toString(16)})},jsonMessageReplacer:g,jsonMessageReviver:Ce}=e;let q;if(d){if(!Ee(d))throw new Error("Invalid WebSocket implementation provided");q=d}else typeof WebSocket<"u"?q=WebSocket:typeof global<"u"?q=global.WebSocket||global.MozWebSocket:typeof window<"u"&&(q=window.WebSocket||window.MozWebSocket);if(!q)throw new Error("WebSocket implementation missing; on Node you can `import WebSocket from 'ws';` and pass `webSocketImpl: WebSocket` to `createClient`");const M=q,x=(()=>{const a=(()=>{const c={};return{on(u,y){return c[u]=y,()=>{delete c[u]}},emit(u){"id"in u&&c[u.id]?.(u)}}})(),f={connecting:l?.connecting?[l.connecting]:[],opened:l?.opened?[l.opened]:[],connected:l?.connected?[l.connected]:[],ping:l?.ping?[l.ping]:[],pong:l?.pong?[l.pong]:[],message:l?.message?[a.emit,l.message]:[a.emit],closed:l?.closed?[l.closed]:[],error:l?.error?[l.error]:[]};return{onMessage:a.on,on(c,u){const y=f[c];return y.push(u),()=>{y.splice(y.indexOf(u),1)}},emit(c,...u){for(const y of[...f[c]])y(...u)}}})();function ue(a){const f=[x.on("error",c=>{f.forEach(u=>u()),a(c)}),x.on("closed",c=>{f.forEach(u=>u()),a(c)})]}let I,R=0,pe,C=!1,L=0,le=!1;async function fe(){clearTimeout(pe);const[a,f]=await(I??(I=new Promise((y,P)=>(async()=>{if(C){if(await E(L),!R)return I=void 0,P({code:1e3,reason:"All Subscriptions Gone"});L++}x.emit("connecting",C);const p=new M(typeof t=="function"?await t():t,be);let j,F;function G(){isFinite(o)&&o>0&&(clearTimeout(F),F=setTimeout(()=>{p.readyState===M.OPEN&&(p.send(z({type:O.Ping})),x.emit("ping",!1,void 0))},o))}ue(k=>{I=void 0,clearTimeout(j),clearTimeout(F),P(k),k instanceof Z&&(p.close(4499,"Terminated"),p.onerror=null,p.onclose=null)}),p.onerror=k=>x.emit("error",k),p.onclose=k=>x.emit("closed",k),p.onopen=async()=>{try{x.emit("opened",p);const k=typeof r=="function"?await r():r;if(p.readyState!==M.OPEN)return;p.send(z(k?{type:O.ConnectionInit,payload:k}:{type:O.ConnectionInit},g)),isFinite(b)&&b>0&&(j=setTimeout(()=>{p.close(T.ConnectionAcknowledgementTimeout,"Connection acknowledgement timeout")},b)),G()}catch(k){x.emit("error",k),p.close(T.InternalClientError,K(k instanceof Error?k.message:String(k),"Internal client error"))}};let W=!1;p.onmessage=({data:k})=>{try{const w=me(k,Ce);if(x.emit("message",w),w.type==="ping"||w.type==="pong"){x.emit(w.type,!0,w.payload),w.type==="pong"?G():h||(p.send(z(w.payload?{type:O.Pong,payload:w.payload}:{type:O.Pong})),x.emit("pong",!1,w.payload));return}if(W)return;if(w.type!==O.ConnectionAck)throw new Error(`First message cannot be of type ${w.type}`);clearTimeout(j),W=!0,x.emit("connected",p,w.payload,C),C=!1,L=0,y([p,new Promise((Be,Fe)=>ue(Fe))])}catch(w){p.onmessage=null,x.emit("error",w),p.close(T.BadResponse,K(w instanceof Error?w.message:String(w),"Bad response"))}}})())));a.readyState===M.CLOSING&&await f;let c=()=>{};const u=new Promise(y=>c=y);return[a,c,Promise.race([u.then(()=>{if(!R){const y=()=>a.close(1e3,"Normal Closure");isFinite(i)&&i>0?pe=setTimeout(()=>{a.readyState===M.OPEN&&y()},i):y()}}),f])]}function de(a){if(D(a)&&(we(a.code)||[T.InternalServerError,T.InternalClientError,T.BadRequest,T.BadResponse,T.Unauthorized,T.SubprotocolNotAcceptable,T.SubscriberAlreadyExists,T.TooManyInitialisationRequests].includes(a.code)))throw a;if(le)return!1;if(D(a)&&a.code===1e3)return R>0;if(!A||L>=A||!S(a))throw a;return C=!0}n||(async()=>{for(R++;;)try{const[,,a]=await fe();await a}catch(a){try{if(!de(a))return}catch(f){return s?.(f)}}})();function ye(a,f){const c=v(a);let u=!1,y=!1,P=()=>{R--,u=!0};return(async()=>{for(R++;;)try{const[p,j,F]=await fe();if(u)return j();const G=x.onMessage(c,W=>{switch(W.type){case O.Next:{f.next(W.payload);return}case O.Error:{y=!0,u=!0,f.error(W.payload),P();return}case O.Complete:{u=!0,P();return}}});p.send(z({id:c,type:O.Subscribe,payload:a},g)),P=()=>{!u&&p.readyState===M.OPEN&&p.send(z({id:c,type:O.Complete},g)),R--,u=!0,j()},await F.finally(G);return}catch(p){if(!de(p))return}})().then(()=>{y||f.complete()}).catch(p=>{f.error(p)}),()=>{u||P()}}return{on:x.on,subscribe:ye,iterate(a){const f=[],c={done:!1,error:null,resolve:()=>{}},u=ye(a,{next(P){f.push(P),c.resolve()},error(P){c.done=!0,c.error=P,c.resolve()},complete(){c.done=!0,c.resolve()}}),y=async function*(){for(;;){for(f.length||await new Promise(p=>c.resolve=p);f.length;)yield f.shift();if(c.error)throw c.error;if(c.done)return}}();return y.throw=async P=>(c.done||(c.done=!0,c.error=P,c.resolve()),{done:!0,value:void 0}),y.return=async()=>(u(),{done:!0,value:void 0}),y},async dispose(){if(le=!0,I){const[a]=await I;a.close(1e3,"Normal Closure")}},terminate(){I&&x.emit("closed",new Z)}}}class Z extends Error{name="TerminatedCloseEvent";message="4499: Terminated";code=4499;reason="Terminated";wasClean=!1}function D(e){return $(e)&&"code"in e&&"reason"in e}function we(e){return[1e3,1001,1006,1005,1012,1013,1014].includes(e)?!1:e>=1e3&&e<=1999}function Ee(e){return typeof e=="function"&&"constructor"in e&&"CLOSED"in e&&"CLOSING"in e&&"CONNECTING"in e&&"OPEN"in e}var J=function(e,t){return J=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(r[s]=n[s])},J(e,t)};function ee(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");J(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function te(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Q(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),s,i=[],o;try{for(;(t===void 0||t-- >0)&&!(s=n.next()).done;)i.push(s.value)}catch(h){o={error:h}}finally{try{s&&!s.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return i}function V(e,t,r){if(r||arguments.length===2)for(var n=0,s=t.length,i;n<s;n++)(i||!(n in t))&&(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return e.concat(i||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;function _(e){return typeof e=="function"}function re(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var Y=re(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription:
|
|
2
|
+
`+r.map(function(n,s){return s+1+") "+n.toString()}).join(`
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=r}});function ne(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var H=function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,s,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var h=te(o),b=h.next();!b.done;b=h.next()){var A=b.value;A.remove(this)}}catch(g){t={error:g}}finally{try{b&&!b.done&&(r=h.return)&&r.call(h)}finally{if(t)throw t.error}}else o.remove(this);var E=this.initialTeardown;if(_(E))try{E()}catch(g){i=g instanceof Y?g.errors:[g]}var S=this._finalizers;if(S){this._finalizers=null;try{for(var l=te(S),d=l.next();!d.done;d=l.next()){var v=d.value;try{ie(v)}catch(g){i=i??[],g instanceof Y?i=V(V([],Q(i)),Q(g.errors)):i.push(g)}}}catch(g){n={error:g}}finally{try{d&&!d.done&&(s=l.return)&&s.call(l)}finally{if(n)throw n.error}}}if(i)throw new Y(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)ie(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&ne(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&ne(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();H.EMPTY;function oe(e){return e instanceof H||e&&"closed"in e&&_(e.remove)&&_(e.add)&&_(e.unsubscribe)}function ie(e){_(e)?e():e.unsubscribe()}var Se={Promise:void 0},xe={setTimeout:function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];return setTimeout.apply(void 0,V([e,t],Q(r)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function ke(e){xe.setTimeout(function(){throw e})}function se(){}function Pe(e){e()}var ce=function(e){ee(t,e);function t(r){var n=e.call(this)||this;return n.isStopped=!1,r?(n.destination=r,oe(r)&&r.add(n)):n.destination=Oe,n}return t.create=function(r,n,s){return new B(r,n,s)},t.prototype.next=function(r){this.isStopped||this._next(r)},t.prototype.error=function(r){this.isStopped||(this.isStopped=!0,this._error(r))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(r){this.destination.next(r)},t.prototype._error=function(r){try{this.destination.error(r)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(H),ve=function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var r=this.partialObserver;if(r.next)try{r.next(t)}catch(n){U(n)}},e.prototype.error=function(t){var r=this.partialObserver;if(r.error)try{r.error(t)}catch(n){U(n)}else U(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(r){U(r)}},e}(),B=function(e){ee(t,e);function t(r,n,s){var i=e.call(this)||this,o;return _(r)||!r?o={next:r??void 0,error:n??void 0,complete:s??void 0}:o=r,i.destination=new ve(o),i}return t}(ce);function U(e){ke(e)}function Te(e){throw e}var Oe={closed:!0,next:se,error:Te,complete:se},_e=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Ae(e){return e}function $e(e){return e.length===0?Ae:e.length===1?e[0]:function(r){return e.reduce(function(n,s){return s(n)},r)}}var Ie=function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(t,r,n){var s=this,i=Ne(t)?t:new B(t,r,n);return Pe(function(){var o=s,h=o.operator,b=o.source;i.add(h?h.call(i,b):b?s._subscribe(i):s._trySubscribe(i))}),i},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(r){t.error(r)}},e.prototype.forEach=function(t,r){var n=this;return r=ae(r),new r(function(s,i){var o=new B({next:function(h){try{t(h)}catch(b){i(b),o.unsubscribe()}},error:i,complete:s});n.subscribe(o)})},e.prototype._subscribe=function(t){var r;return(r=this.source)===null||r===void 0?void 0:r.subscribe(t)},e.prototype[_e]=function(){return this},e.prototype.pipe=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return $e(t)(this)},e.prototype.toPromise=function(t){var r=this;return t=ae(t),new t(function(n,s){var i;r.subscribe(function(o){return i=o},function(o){return s(o)},function(){return n(i)})})},e.create=function(t){return new e(t)},e}();function ae(e){var t;return(t=e??Se.Promise)!==null&&t!==void 0?t:Promise}function Re(e){return e&&_(e.next)&&_(e.error)&&_(e.complete)}function Ne(e){return e&&e instanceof ce||Re(e)&&oe(e)}var qe=re(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function Me(e,t){return new Promise(function(r,n){var s=new B({next:function(i){r(i),s.unsubscribe()},error:n,complete:function(){n(new qe)}});e.subscribe(s)})}class je{constructor(t,r){this.createClient=t,this.poolSize=r}clients=[];currentIndex=0;connect(){for(let t=0;t<this.poolSize;t++)this.clients.push(this.createClient(`${t+1}`))}get(){if(this.clients.length===0)throw new Error("Connection pool is empty. Please call connect() first.");const t=this.clients[this.currentIndex];if(this.currentIndex=(this.currentIndex+1)%this.poolSize,!t)throw new Error("No available WebSocket client");return t}disconnect(){this.clients.forEach(t=>t.dispose()),this.clients=[]}}const We=(e,t,r)=>r((n,s,i)=>{i&&console.warn("options are not supported yet");const o=n.loc?.source.body;if(!o)throw new Error("No query provided");if(s&&typeof s!="object")throw new Error("Variables must be an object");const h=n.definitions.find(d=>d.kind==="OperationDefinition");if(!h)throw new Error("No operation definition found");const b=h.operation,A=()=>{const d=e();return new Ie(v=>d.subscribe({query:o,variables:s},v))},E={kind:b,operationName:h.name?.value??"",query:o,variables:s||{}},S=(d,v)=>{if(v>=d.length)return A();const g=d[v];return g?.onRequest?g.onRequest(E,()=>S(d,v+1)):S(d,v+1)},l=S(t,0);return b!=="subscription"?Me(l):l});class ze{_pool;_sdk;constructor(t,r){const{url:n,project:s,token:i,client:o,pooling:h}=r,b=`${n}/graphql/projects/${s}`.replace(/^http/i,"ws");this._pool=new je(A=>{const E=Object.freeze({connectionId:A,websocketUrl:b});return ge({url:b,connectionParams:{authorization:`Bearer ${i}`},lazy:!1,keepAlive:3e4,retryAttempts:o?.retryAttempts??3,shouldRetry:()=>!0,jsonMessageReplacer:(S,l)=>{if(!S){let d=l;for(const v of r.middlewares??[])v.onOutgoingMessage&&(d=v.onOutgoingMessage(d));return d}return l},...o?.onError?{onNonLazyError:S=>o.onError(E,S)}:{},on:{...o?.onError?{error:S=>o.onError(E,S)}:{},...o?.onConnected?{connected:()=>o.onConnected(E)}:{},...o?.onClosed?{closed:()=>o.onClosed(E)}:{},...o?.onConnecting?{connecting:()=>o.onConnecting(E)}:{},...o?.onOpened?{opened:()=>o.onOpened(E)}:{},...o?.onMessage?{message:S=>o.onMessage(E,S)}:{},...o?.onPing?{ping:()=>o.onPing(E)}:{},...o?.onPong?{pong:()=>o.onPong(E)}:{}}})},h?.enabled===!1?1:h?.size??5),this._sdk={sdk:We(()=>this._pool.get(),r.middlewares??[],t)}}get sdk(){return this._sdk.sdk}async connect(){this._pool.connect()}async disconnect(){this._pool.disconnect()}}N.ContelloSdkClient=ze,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contello/sdk-client",
|
|
3
|
+
"scripts": {
|
|
4
|
+
"start": "vite build --watch",
|
|
5
|
+
"build": "rm -rf dist/ && vite build",
|
|
6
|
+
"lint": "eslint . --report-unused-disable-directives --max-warnings 0",
|
|
7
|
+
"patch": "node ci/patcher.js"
|
|
8
|
+
},
|
|
9
|
+
"peerDependencies": {
|
|
10
|
+
"rxjs": ">=5.0.0",
|
|
11
|
+
"graphql": ">=16.0.0",
|
|
12
|
+
"graphql-ws": ">=5.0.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"rxjs": "^7.8.2",
|
|
16
|
+
"@types/node": "^24.0.10",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "^8.35.1",
|
|
18
|
+
"eslint": "^9.30.1",
|
|
19
|
+
"eslint-config-prettier": "^10.1.5",
|
|
20
|
+
"eslint-plugin-import": "^2.32.0",
|
|
21
|
+
"eslint-plugin-prettier": "^5.5.1",
|
|
22
|
+
"npm-run-all": "^4.1.5",
|
|
23
|
+
"typescript": "^5.8.3",
|
|
24
|
+
"typescript-eslint": "^8.35.1",
|
|
25
|
+
"graphql": "^16.11.0",
|
|
26
|
+
"graphql-ws": "^6.0.5",
|
|
27
|
+
"vite": "^7.0.2",
|
|
28
|
+
"vite-plugin-dts": "^4.5.4"
|
|
29
|
+
},
|
|
30
|
+
"author": "admin@entwico.com",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"type": "module",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"import": "./dist/index.js",
|
|
40
|
+
"require": "./dist/index.umd.cjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"registry": "https://registry.npmjs.org"
|
|
46
|
+
},
|
|
47
|
+
"version": "8.14.0-next.1751836134"
|
|
48
|
+
}
|