@contello/client 2.3.0 → 3.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/cli.js +1 -1
- package/dist/{generate-DIoN94iO.js → generate-D_j088z7.js} +10 -3
- package/dist/generate-D_j088z7.js.map +1 -0
- package/dist/index.cjs +10 -250
- package/dist/index.d.cts +1 -65
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +1 -65
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -239
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/dist/generate-DIoN94iO.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -162,69 +162,5 @@ type LocalDate = {
|
|
|
162
162
|
//#region src/source-subscription.d.ts
|
|
163
163
|
declare function createSourceSubscription(source: SourceDef): string;
|
|
164
164
|
//#endregion
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Returns the first value yielded by `iter`, then disposes the iterator. Throws if the iterable
|
|
168
|
-
* completes without yielding. Equivalent of rxjs's `firstValueFrom` for AsyncIterables.
|
|
169
|
-
*/
|
|
170
|
-
declare function firstAsync<T>(iter: AsyncIterable<T>): Promise<T>;
|
|
171
|
-
/** Lazy map over an async iterable. Cleanup propagates: breaking the outer iter disposes the inner. */
|
|
172
|
-
declare function mapAsync<T, R>(iter: AsyncIterable<T>, fn: (value: T) => R): AsyncIterable<R>;
|
|
173
|
-
/** Lazy filter over an async iterable. */
|
|
174
|
-
declare function filterAsync<T>(iter: AsyncIterable<T>, predicate: (value: T) => boolean): AsyncIterable<T>;
|
|
175
|
-
/**
|
|
176
|
-
* Concatenates all elements of all arrays yielded by `iter` into a single array. Used to support
|
|
177
|
-
* subscriptions that emit chunks of items before completing.
|
|
178
|
-
*/
|
|
179
|
-
declare function collectAsync<T>(iter: AsyncIterable<T[]>): Promise<T[]>;
|
|
180
|
-
/**
|
|
181
|
-
* Exponential backoff with jitter. `attempt` starts at 0 → ~1s+jitter, 1 → ~2s+jitter, etc.,
|
|
182
|
-
* capped at 30s. Returns a Promise that resolves after the delay.
|
|
183
|
-
*/
|
|
184
|
-
declare function exponentialBackoff(attempt: number): Promise<void>;
|
|
185
|
-
/**
|
|
186
|
-
* Runs `fn` with exponential-backoff retry on rejection. Returns once `fn` resolves successfully.
|
|
187
|
-
* `signal` aborts both the in-flight `fn` (if it observes the signal) and the backoff wait.
|
|
188
|
-
*/
|
|
189
|
-
declare function runWithBackoff(fn: () => Promise<unknown>, signal?: AbortSignal | undefined): Promise<void>;
|
|
190
|
-
/**
|
|
191
|
-
* Long-running stream wrapper: subscribes via `factory()`, yields every value, and on error or
|
|
192
|
-
* unexpected completion re-subscribes with exponential backoff. Stops only when `signal` aborts.
|
|
193
|
-
* Designed for subscriptions that should stay open across reconnects (e.g. the watcher).
|
|
194
|
-
*/
|
|
195
|
-
declare function asyncKeepalive<T>(factory: () => AsyncIterable<T>, signal?: AbortSignal | undefined): AsyncIterable<T>;
|
|
196
|
-
//#endregion
|
|
197
|
-
//#region src/async-iterable-subject.d.ts
|
|
198
|
-
/**
|
|
199
|
-
* Multicast event source with `next` / `error` / `complete` (Subject semantics) plus an
|
|
200
|
-
* `AsyncIterable` view. Two consumption modes that fan out from the same source:
|
|
201
|
-
*
|
|
202
|
-
* - `for await (const v of subject)` — iteration. Each `[Symbol.asyncIterator]()` call returns
|
|
203
|
-
* a fresh per-iterator queue. Stop by `break`ing the loop. On `.error(err)` the iterator's
|
|
204
|
-
* pending `next()` rejects, propagating into the for-await as a thrown exception.
|
|
205
|
-
*
|
|
206
|
-
* - `subject.subscribe(observerOrNext)` — observer style. Pass either a full/partial observer
|
|
207
|
-
* `{ next?, error?, complete? }` or just an `(value) => …` function as the `next`-only shortcut.
|
|
208
|
-
* Returns an unsubscribe function. Missing handlers default to no-ops.
|
|
209
|
-
*
|
|
210
|
-
* Producer side: call `.next(value)` to emit, `.error(err)` to fail the subject (all consumers
|
|
211
|
-
* see the error and are detached), `.complete()` to close cleanly (all consumers see done and
|
|
212
|
-
* are detached). After either `error` or `complete`, further `.next()` calls are dropped and
|
|
213
|
-
* new `.subscribe(...)` calls register a no-op unsubscribe.
|
|
214
|
-
*
|
|
215
|
-
* Backpressure: unbounded queue per pending iterator. Intended for low-frequency events.
|
|
216
|
-
*/
|
|
217
|
-
type AsyncIterableSubject<T> = AsyncIterable<T> & {
|
|
218
|
-
next: (value: T) => void;
|
|
219
|
-
error: (err: unknown) => void;
|
|
220
|
-
complete: () => void;
|
|
221
|
-
subscribe: (observerOrNext: ((value: T) => void) | {
|
|
222
|
-
next?: (value: T) => void;
|
|
223
|
-
error?: (err: unknown) => void;
|
|
224
|
-
complete?: () => void;
|
|
225
|
-
}) => () => void;
|
|
226
|
-
};
|
|
227
|
-
declare function createAsyncIterableSubject<T>(): AsyncIterableSubject<T>;
|
|
228
|
-
//#endregion
|
|
229
|
-
export { type AsyncIterableSubject, type ConnectionContext, type ConnectionEvents, ContelloClient, type ContelloClientOptions, type DownloadResult, type HttpAgentOptions, type LocalDate, type LocalDateTime, type OperationDef, type OperationKind, type OperationMap, type ProxyResult, type Rpc, type Schema, type SourceAccessors, type SourceCardinality, type SourceDef, type SourceMap, type UploadData, type UploadMetadata, type UploadOptions, asyncKeepalive, collectAsync, createAsyncIterableSubject, createContelloClient, createSourceSubscription, exponentialBackoff, filterAsync, firstAsync, mapAsync, runWithBackoff };
|
|
165
|
+
export { type ConnectionContext, type ConnectionEvents, ContelloClient, type ContelloClientOptions, type DownloadResult, type HttpAgentOptions, type LocalDate, type LocalDateTime, type OperationDef, type OperationKind, type OperationMap, type ProxyResult, type Rpc, type Schema, type SourceAccessors, type SourceCardinality, type SourceDef, type SourceMap, type UploadData, type UploadMetadata, type UploadOptions, createContelloClient, createSourceSubscription };
|
|
230
166
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/http.ts","../src/types.ts","../src/upload.ts","../src/client.ts","../src/scalars.ts","../src/source-subscription.ts"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/http.ts","../src/types.ts","../src/upload.ts","../src/client.ts","../src/scalars.ts","../src/source-subscription.ts"],"mappings":";;;KAiCY,gBAAA;EACV,UAAA;EACA,OAAA;EACA,oBAAA;EACA,gBAAA;AAAA;AAAA,KAcU,cAAA;EACV,QAAA;EACA,IAAA;EACA,KAAA,IAAS,OAAA,CAAQ,UAAA;EACjB,MAAA,IAAU,cAAA,CAAe,UAAA;AAAA;AAAA,KAiCf,WAAA;EACV,MAAA;EACA,OAAA,EAAS,OAAA;EACT,MAAA,IAAU,cAAA,CAAe,UAAA;AAAA;;;KC3Ff,aAAA;AAAA,KAEA,YAAA,iCAEG,MAAA,iCACC,aAAA,GAAgB,aAAA;EAE9B,QAAA;EACA,IAAA,EAAM,KAAA,EDyBI;ECvBV,QAAA,GAAW,OAAA;EAEX,WAAA,GAAc,UAAA;AAAA;AAAA,KAGJ,YAAA,GAAe,MAAM,SAAS,YAAA;AAAA,KAE9B,WAAA,WAAsB,YAAA,IAAgB,WAAA,CAAY,CAAA;AAAA,KAClD,cAAA,WAAyB,YAAA,IAAgB,WAAA,CAAY,CAAA;AAAA,KAErD,SAAA,WAAoB,YAAA,IAAgB,CAAA,kCAC5C,cAAA,CAAe,CAAA,UAAW,MAAA,wBAClB,aAAA,CAAc,WAAA,CAAY,CAAA,MAC/B,SAAA,EAAW,cAAA,CAAe,CAAA,MAAO,aAAA,CAAc,WAAA,CAAY,CAAA,KAC9D,cAAA,CAAe,CAAA,UAAW,MAAA,wBAClB,OAAA,CAAQ,WAAA,CAAY,CAAA,MACzB,SAAA,EAAW,cAAA,CAAe,CAAA,MAAO,OAAA,CAAQ,WAAA,CAAY,CAAA;AAAA,KAEhD,GAAA,WAAc,YAAA,kBACZ,CAAA,GAAI,SAAA,CAAU,CAAA,CAAE,CAAA;;;;;;;;;KAWlB,iB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,OAAA,EAAS,qBAAA,CAAsB,OAAA,IAC9B,cAAA,CAAe,OAAA;;;KChSN,aAAA;EACV,IAAA;EACA,KAAA;EACA,GAAA;EACA,IAAA;EACA,MAAA;EACA,MAAA;AAAA;AAAA,KAGU,SAAA;EACV,IAAA;EACA,KAAA;EACA,GAAA;AAAA;;;iBCcc,wBAAA,CAAyB,MAAiB,EAAT,SAAS"}
|
package/dist/index.d.ts
CHANGED
|
@@ -163,69 +163,5 @@ type LocalDate = {
|
|
|
163
163
|
//#region src/source-subscription.d.ts
|
|
164
164
|
declare function createSourceSubscription(source: SourceDef): string;
|
|
165
165
|
//#endregion
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Returns the first value yielded by `iter`, then disposes the iterator. Throws if the iterable
|
|
169
|
-
* completes without yielding. Equivalent of rxjs's `firstValueFrom` for AsyncIterables.
|
|
170
|
-
*/
|
|
171
|
-
declare function firstAsync<T>(iter: AsyncIterable<T>): Promise<T>;
|
|
172
|
-
/** Lazy map over an async iterable. Cleanup propagates: breaking the outer iter disposes the inner. */
|
|
173
|
-
declare function mapAsync<T, R>(iter: AsyncIterable<T>, fn: (value: T) => R): AsyncIterable<R>;
|
|
174
|
-
/** Lazy filter over an async iterable. */
|
|
175
|
-
declare function filterAsync<T>(iter: AsyncIterable<T>, predicate: (value: T) => boolean): AsyncIterable<T>;
|
|
176
|
-
/**
|
|
177
|
-
* Concatenates all elements of all arrays yielded by `iter` into a single array. Used to support
|
|
178
|
-
* subscriptions that emit chunks of items before completing.
|
|
179
|
-
*/
|
|
180
|
-
declare function collectAsync<T>(iter: AsyncIterable<T[]>): Promise<T[]>;
|
|
181
|
-
/**
|
|
182
|
-
* Exponential backoff with jitter. `attempt` starts at 0 → ~1s+jitter, 1 → ~2s+jitter, etc.,
|
|
183
|
-
* capped at 30s. Returns a Promise that resolves after the delay.
|
|
184
|
-
*/
|
|
185
|
-
declare function exponentialBackoff(attempt: number): Promise<void>;
|
|
186
|
-
/**
|
|
187
|
-
* Runs `fn` with exponential-backoff retry on rejection. Returns once `fn` resolves successfully.
|
|
188
|
-
* `signal` aborts both the in-flight `fn` (if it observes the signal) and the backoff wait.
|
|
189
|
-
*/
|
|
190
|
-
declare function runWithBackoff(fn: () => Promise<unknown>, signal?: AbortSignal | undefined): Promise<void>;
|
|
191
|
-
/**
|
|
192
|
-
* Long-running stream wrapper: subscribes via `factory()`, yields every value, and on error or
|
|
193
|
-
* unexpected completion re-subscribes with exponential backoff. Stops only when `signal` aborts.
|
|
194
|
-
* Designed for subscriptions that should stay open across reconnects (e.g. the watcher).
|
|
195
|
-
*/
|
|
196
|
-
declare function asyncKeepalive<T>(factory: () => AsyncIterable<T>, signal?: AbortSignal | undefined): AsyncIterable<T>;
|
|
197
|
-
//#endregion
|
|
198
|
-
//#region src/async-iterable-subject.d.ts
|
|
199
|
-
/**
|
|
200
|
-
* Multicast event source with `next` / `error` / `complete` (Subject semantics) plus an
|
|
201
|
-
* `AsyncIterable` view. Two consumption modes that fan out from the same source:
|
|
202
|
-
*
|
|
203
|
-
* - `for await (const v of subject)` — iteration. Each `[Symbol.asyncIterator]()` call returns
|
|
204
|
-
* a fresh per-iterator queue. Stop by `break`ing the loop. On `.error(err)` the iterator's
|
|
205
|
-
* pending `next()` rejects, propagating into the for-await as a thrown exception.
|
|
206
|
-
*
|
|
207
|
-
* - `subject.subscribe(observerOrNext)` — observer style. Pass either a full/partial observer
|
|
208
|
-
* `{ next?, error?, complete? }` or just an `(value) => …` function as the `next`-only shortcut.
|
|
209
|
-
* Returns an unsubscribe function. Missing handlers default to no-ops.
|
|
210
|
-
*
|
|
211
|
-
* Producer side: call `.next(value)` to emit, `.error(err)` to fail the subject (all consumers
|
|
212
|
-
* see the error and are detached), `.complete()` to close cleanly (all consumers see done and
|
|
213
|
-
* are detached). After either `error` or `complete`, further `.next()` calls are dropped and
|
|
214
|
-
* new `.subscribe(...)` calls register a no-op unsubscribe.
|
|
215
|
-
*
|
|
216
|
-
* Backpressure: unbounded queue per pending iterator. Intended for low-frequency events.
|
|
217
|
-
*/
|
|
218
|
-
type AsyncIterableSubject<T> = AsyncIterable<T> & {
|
|
219
|
-
next: (value: T) => void;
|
|
220
|
-
error: (err: unknown) => void;
|
|
221
|
-
complete: () => void;
|
|
222
|
-
subscribe: (observerOrNext: ((value: T) => void) | {
|
|
223
|
-
next?: (value: T) => void;
|
|
224
|
-
error?: (err: unknown) => void;
|
|
225
|
-
complete?: () => void;
|
|
226
|
-
}) => () => void;
|
|
227
|
-
};
|
|
228
|
-
declare function createAsyncIterableSubject<T>(): AsyncIterableSubject<T>;
|
|
229
|
-
//#endregion
|
|
230
|
-
export { type AsyncIterableSubject, type ConnectionContext, type ConnectionEvents, ContelloClient, type ContelloClientOptions, type DownloadResult, type HttpAgentOptions, type LocalDate, type LocalDateTime, type OperationDef, type OperationKind, type OperationMap, type ProxyResult, type Rpc, type Schema, type SourceAccessors, type SourceCardinality, type SourceDef, type SourceMap, type UploadData, type UploadMetadata, type UploadOptions, asyncKeepalive, collectAsync, createAsyncIterableSubject, createContelloClient, createSourceSubscription, exponentialBackoff, filterAsync, firstAsync, mapAsync, runWithBackoff };
|
|
166
|
+
export { type ConnectionContext, type ConnectionEvents, ContelloClient, type ContelloClientOptions, type DownloadResult, type HttpAgentOptions, type LocalDate, type LocalDateTime, type OperationDef, type OperationKind, type OperationMap, type ProxyResult, type Rpc, type Schema, type SourceAccessors, type SourceCardinality, type SourceDef, type SourceMap, type UploadData, type UploadMetadata, type UploadOptions, createContelloClient, createSourceSubscription };
|
|
231
167
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/http.ts","../src/types.ts","../src/upload.ts","../src/client.ts","../src/scalars.ts","../src/source-subscription.ts"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/http.ts","../src/types.ts","../src/upload.ts","../src/client.ts","../src/sc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A,KAGU,SAAA;EACV,IAAA;EACA,KAAA;EACA,GAAA;AAAA;;;iBCcc,wBAAA,CAAyB,MAAiB,EAAT,SAAS"}
|
package/dist/index.js
CHANGED
|
@@ -1,103 +1,7 @@
|
|
|
1
1
|
import { createOperationTelemetry, graphqlOperationAttributes, injectTraceContext } from "@contello/opentelemetry";
|
|
2
|
+
import { concatAsync, exponentialBackoff, firstAsync, mapAsync } from "@entwico/dash/async";
|
|
2
3
|
import { createClient } from "graphql-ws";
|
|
3
4
|
import { Agent, request } from "undici";
|
|
4
|
-
//#region src/async-iterable-utils.ts
|
|
5
|
-
const MAX_BACKOFF_MS = 3e4;
|
|
6
|
-
const JITTER_MIN_MS$1 = 300;
|
|
7
|
-
const JITTER_MAX_MS$1 = 3e3;
|
|
8
|
-
/**
|
|
9
|
-
* Returns the first value yielded by `iter`, then disposes the iterator. Throws if the iterable
|
|
10
|
-
* completes without yielding. Equivalent of rxjs's `firstValueFrom` for AsyncIterables.
|
|
11
|
-
*/
|
|
12
|
-
async function firstAsync(iter) {
|
|
13
|
-
const it = iter[Symbol.asyncIterator]();
|
|
14
|
-
try {
|
|
15
|
-
const result = await it.next();
|
|
16
|
-
if (result.done) throw new Error("firstAsync: async iterable completed without yielding a value");
|
|
17
|
-
return result.value;
|
|
18
|
-
} finally {
|
|
19
|
-
await it.return?.();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/** Lazy map over an async iterable. Cleanup propagates: breaking the outer iter disposes the inner. */
|
|
23
|
-
async function* mapAsync(iter, fn) {
|
|
24
|
-
for await (const value of iter) yield fn(value);
|
|
25
|
-
}
|
|
26
|
-
/** Lazy filter over an async iterable. */
|
|
27
|
-
async function* filterAsync(iter, predicate) {
|
|
28
|
-
for await (const value of iter) if (predicate(value)) yield value;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Concatenates all elements of all arrays yielded by `iter` into a single array. Used to support
|
|
32
|
-
* subscriptions that emit chunks of items before completing.
|
|
33
|
-
*/
|
|
34
|
-
async function collectAsync(iter) {
|
|
35
|
-
const out = [];
|
|
36
|
-
for await (const chunk of iter) out.push(...chunk);
|
|
37
|
-
return out;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Exponential backoff with jitter. `attempt` starts at 0 → ~1s+jitter, 1 → ~2s+jitter, etc.,
|
|
41
|
-
* capped at 30s. Returns a Promise that resolves after the delay.
|
|
42
|
-
*/
|
|
43
|
-
function exponentialBackoff(attempt) {
|
|
44
|
-
return delay(Math.min(Math.pow(2, attempt) * 1e3, MAX_BACKOFF_MS) + Math.floor(Math.random() * (JITTER_MAX_MS$1 - JITTER_MIN_MS$1) + JITTER_MIN_MS$1));
|
|
45
|
-
}
|
|
46
|
-
function delay(ms, signal) {
|
|
47
|
-
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
48
|
-
return new Promise((resolve, reject) => {
|
|
49
|
-
const timer = setTimeout(() => {
|
|
50
|
-
signal?.removeEventListener("abort", onAbort);
|
|
51
|
-
resolve();
|
|
52
|
-
}, ms);
|
|
53
|
-
const onAbort = () => {
|
|
54
|
-
clearTimeout(timer);
|
|
55
|
-
reject(signal.reason);
|
|
56
|
-
};
|
|
57
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Runs `fn` with exponential-backoff retry on rejection. Returns once `fn` resolves successfully.
|
|
62
|
-
* `signal` aborts both the in-flight `fn` (if it observes the signal) and the backoff wait.
|
|
63
|
-
*/
|
|
64
|
-
async function runWithBackoff(fn, signal) {
|
|
65
|
-
let attempt = 0;
|
|
66
|
-
for (;;) {
|
|
67
|
-
if (signal?.aborted) throw signal.reason;
|
|
68
|
-
try {
|
|
69
|
-
await fn();
|
|
70
|
-
return;
|
|
71
|
-
} catch {
|
|
72
|
-
await exponentialBackoffWithSignal(attempt, signal);
|
|
73
|
-
attempt++;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function exponentialBackoffWithSignal(attempt, signal) {
|
|
78
|
-
return delay(Math.min(Math.pow(2, attempt) * 1e3, MAX_BACKOFF_MS) + Math.floor(Math.random() * (JITTER_MAX_MS$1 - JITTER_MIN_MS$1) + JITTER_MIN_MS$1), signal);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Long-running stream wrapper: subscribes via `factory()`, yields every value, and on error or
|
|
82
|
-
* unexpected completion re-subscribes with exponential backoff. Stops only when `signal` aborts.
|
|
83
|
-
* Designed for subscriptions that should stay open across reconnects (e.g. the watcher).
|
|
84
|
-
*/
|
|
85
|
-
async function* asyncKeepalive(factory, signal) {
|
|
86
|
-
let attempt = 0;
|
|
87
|
-
while (!signal?.aborted) try {
|
|
88
|
-
for await (const value of factory()) {
|
|
89
|
-
if (signal?.aborted) return;
|
|
90
|
-
yield value;
|
|
91
|
-
attempt = 0;
|
|
92
|
-
}
|
|
93
|
-
attempt = 0;
|
|
94
|
-
} catch (error) {
|
|
95
|
-
if (signal?.aborted) return;
|
|
96
|
-
await exponentialBackoffWithSignal(attempt, signal);
|
|
97
|
-
attempt++;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
//#endregion
|
|
101
5
|
//#region src/http.ts
|
|
102
6
|
const SAFE_SEGMENT = /^[A-Za-z0-9._-]+$/;
|
|
103
7
|
const FORWARDED_PROXY_HEADERS = /* @__PURE__ */ new Set([
|
|
@@ -433,25 +337,25 @@ function createSourceAccessor(name, def, doc, subscribe) {
|
|
|
433
337
|
case "singleton": return { fetch: () => wrap(`source:${name}`, () => firstAsync(mapAsync(subscribe(doc), (r) => r.source)), graphqlOperationAttributes(doc)) };
|
|
434
338
|
case "entity": return { fetch: (vars) => {
|
|
435
339
|
const variables = transformVariables({ ids: vars?.ids });
|
|
436
|
-
return wrap(`source:${name}`, () =>
|
|
340
|
+
return wrap(`source:${name}`, () => concatAsync(mapAsync(subscribe(doc, variables), (r) => r.source)), graphqlOperationAttributes(doc, variables));
|
|
437
341
|
} };
|
|
438
342
|
case "route": return { fetch: (vars) => {
|
|
439
343
|
const variables = transformVariables({
|
|
440
344
|
ids: vars?.ids,
|
|
441
345
|
paths: vars?.paths
|
|
442
346
|
});
|
|
443
|
-
return wrap(`source:${name}`, () =>
|
|
347
|
+
return wrap(`source:${name}`, () => concatAsync(mapAsync(subscribe(doc, variables), (r) => r.source)), graphqlOperationAttributes(doc, variables));
|
|
444
348
|
} };
|
|
445
349
|
case "asset": return { fetch: (vars) => {
|
|
446
350
|
const variables = transformVariables({ ids: vars?.ids });
|
|
447
|
-
return wrap(`source:${name}`, () =>
|
|
351
|
+
return wrap(`source:${name}`, () => concatAsync(mapAsync(subscribe(doc, variables), (r) => r.source)), graphqlOperationAttributes(doc, variables));
|
|
448
352
|
} };
|
|
449
353
|
case "i18nMessage": return { fetch: (vars) => {
|
|
450
354
|
const variables = transformVariables({
|
|
451
355
|
collection: vars.collection,
|
|
452
356
|
ids: vars.ids
|
|
453
357
|
});
|
|
454
|
-
return wrap(`source:${name}`, () =>
|
|
358
|
+
return wrap(`source:${name}`, () => concatAsync(mapAsync(subscribe(doc, variables), (r) => r.source)), graphqlOperationAttributes(doc, variables));
|
|
455
359
|
} };
|
|
456
360
|
}
|
|
457
361
|
}
|
|
@@ -637,15 +541,6 @@ function upload(url, project, token, data, meta, options) {
|
|
|
637
541
|
});
|
|
638
542
|
}
|
|
639
543
|
//#endregion
|
|
640
|
-
//#region src/utils.ts
|
|
641
|
-
const MAX_DELAY_MS = 3e4;
|
|
642
|
-
const JITTER_MIN_MS = 300;
|
|
643
|
-
const JITTER_MAX_MS = 3e3;
|
|
644
|
-
function wsRetryWait(retries) {
|
|
645
|
-
const delay = Math.min(Math.pow(2, retries) * 1e3, MAX_DELAY_MS) + Math.floor(Math.random() * (JITTER_MAX_MS - JITTER_MIN_MS) + JITTER_MIN_MS);
|
|
646
|
-
return new Promise((resolve) => setTimeout(resolve, delay));
|
|
647
|
-
}
|
|
648
|
-
//#endregion
|
|
649
544
|
//#region src/client.ts
|
|
650
545
|
var ContelloClient = class {
|
|
651
546
|
_pool;
|
|
@@ -689,7 +584,7 @@ var ContelloClient = class {
|
|
|
689
584
|
lazy: false,
|
|
690
585
|
keepAlive: 3e4,
|
|
691
586
|
retryAttempts: Infinity,
|
|
692
|
-
retryWait:
|
|
587
|
+
retryWait: exponentialBackoff,
|
|
693
588
|
shouldRetry: () => true,
|
|
694
589
|
jsonMessageReplacer: (key, value) => {
|
|
695
590
|
if (!key) return injectTraceContext(value);
|
|
@@ -835,133 +730,6 @@ function createContelloClient(options) {
|
|
|
835
730
|
return new ContelloClient(options);
|
|
836
731
|
}
|
|
837
732
|
//#endregion
|
|
838
|
-
|
|
839
|
-
function createAsyncIterableSubject() {
|
|
840
|
-
const consumers = /* @__PURE__ */ new Set();
|
|
841
|
-
let status = { state: "open" };
|
|
842
|
-
const next = (value) => {
|
|
843
|
-
if (status.state !== "open") return;
|
|
844
|
-
for (const consumer of consumers) if (consumer.kind === "listener") consumer.next?.(value);
|
|
845
|
-
else if (consumer.pending) {
|
|
846
|
-
const p = consumer.pending;
|
|
847
|
-
consumer.pending = void 0;
|
|
848
|
-
p.resolve({
|
|
849
|
-
value,
|
|
850
|
-
done: false
|
|
851
|
-
});
|
|
852
|
-
} else consumer.queue.push(value);
|
|
853
|
-
};
|
|
854
|
-
const error = (err) => {
|
|
855
|
-
if (status.state !== "open") return;
|
|
856
|
-
status = {
|
|
857
|
-
state: "errored",
|
|
858
|
-
err
|
|
859
|
-
};
|
|
860
|
-
for (const consumer of consumers) if (consumer.kind === "listener") consumer.error?.(err);
|
|
861
|
-
else if (consumer.pending) {
|
|
862
|
-
const p = consumer.pending;
|
|
863
|
-
consumer.pending = void 0;
|
|
864
|
-
p.reject(err);
|
|
865
|
-
}
|
|
866
|
-
consumers.clear();
|
|
867
|
-
};
|
|
868
|
-
const complete = () => {
|
|
869
|
-
if (status.state !== "open") return;
|
|
870
|
-
status = { state: "completed" };
|
|
871
|
-
for (const consumer of consumers) if (consumer.kind === "listener") consumer.complete?.();
|
|
872
|
-
else if (consumer.pending) {
|
|
873
|
-
const p = consumer.pending;
|
|
874
|
-
consumer.pending = void 0;
|
|
875
|
-
p.resolve({
|
|
876
|
-
value: void 0,
|
|
877
|
-
done: true
|
|
878
|
-
});
|
|
879
|
-
}
|
|
880
|
-
consumers.clear();
|
|
881
|
-
};
|
|
882
|
-
const subscribe = (observerOrNext) => {
|
|
883
|
-
if (status.state !== "open") return () => {};
|
|
884
|
-
const consumer = {
|
|
885
|
-
kind: "listener",
|
|
886
|
-
...typeof observerOrNext === "function" ? { next: observerOrNext } : observerOrNext
|
|
887
|
-
};
|
|
888
|
-
consumers.add(consumer);
|
|
889
|
-
return () => {
|
|
890
|
-
consumers.delete(consumer);
|
|
891
|
-
};
|
|
892
|
-
};
|
|
893
|
-
return Object.assign({ [Symbol.asyncIterator]() {
|
|
894
|
-
if (status.state === "errored") {
|
|
895
|
-
const err = status.err;
|
|
896
|
-
return {
|
|
897
|
-
next: () => Promise.reject(err),
|
|
898
|
-
return: () => Promise.resolve({
|
|
899
|
-
value: void 0,
|
|
900
|
-
done: true
|
|
901
|
-
})
|
|
902
|
-
};
|
|
903
|
-
}
|
|
904
|
-
if (status.state === "completed") return {
|
|
905
|
-
next: () => Promise.resolve({
|
|
906
|
-
value: void 0,
|
|
907
|
-
done: true
|
|
908
|
-
}),
|
|
909
|
-
return: () => Promise.resolve({
|
|
910
|
-
value: void 0,
|
|
911
|
-
done: true
|
|
912
|
-
})
|
|
913
|
-
};
|
|
914
|
-
const consumer = {
|
|
915
|
-
kind: "iterator",
|
|
916
|
-
queue: []
|
|
917
|
-
};
|
|
918
|
-
consumers.add(consumer);
|
|
919
|
-
return {
|
|
920
|
-
next() {
|
|
921
|
-
if (consumer.queue.length > 0) return Promise.resolve({
|
|
922
|
-
value: consumer.queue.shift(),
|
|
923
|
-
done: false
|
|
924
|
-
});
|
|
925
|
-
if (status.state === "errored") return Promise.reject(status.err);
|
|
926
|
-
if (status.state === "completed") return Promise.resolve({
|
|
927
|
-
value: void 0,
|
|
928
|
-
done: true
|
|
929
|
-
});
|
|
930
|
-
return new Promise((resolve, reject) => {
|
|
931
|
-
consumer.pending = {
|
|
932
|
-
resolve,
|
|
933
|
-
reject
|
|
934
|
-
};
|
|
935
|
-
});
|
|
936
|
-
},
|
|
937
|
-
return() {
|
|
938
|
-
consumers.delete(consumer);
|
|
939
|
-
if (consumer.pending) {
|
|
940
|
-
const p = consumer.pending;
|
|
941
|
-
consumer.pending = void 0;
|
|
942
|
-
p.resolve({
|
|
943
|
-
value: void 0,
|
|
944
|
-
done: true
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
return Promise.resolve({
|
|
948
|
-
value: void 0,
|
|
949
|
-
done: true
|
|
950
|
-
});
|
|
951
|
-
},
|
|
952
|
-
throw(err) {
|
|
953
|
-
consumers.delete(consumer);
|
|
954
|
-
return Promise.reject(err);
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
|
-
} }, {
|
|
958
|
-
next,
|
|
959
|
-
error,
|
|
960
|
-
complete,
|
|
961
|
-
subscribe
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
//#endregion
|
|
965
|
-
export { ContelloClient, asyncKeepalive, collectAsync, createAsyncIterableSubject, createContelloClient, createSourceSubscription, exponentialBackoff, filterAsync, firstAsync, mapAsync, runWithBackoff };
|
|
733
|
+
export { ContelloClient, createContelloClient, createSourceSubscription };
|
|
966
734
|
|
|
967
735
|
//# sourceMappingURL=index.js.map
|