@contello/client 1.2.2 → 2.1.0
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-PGYNYGNX.js → generate-FPYYN7UV.js} +434 -37
- package/dist/index.cjs +530 -23
- package/dist/index.d.cts +138 -10
- package/dist/index.d.ts +138 -10
- package/dist/index.js +520 -22
- package/package.json +1 -7
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
1
|
import { ReadableStream as ReadableStream$1 } from 'node:stream/web';
|
|
3
2
|
|
|
4
3
|
type HttpAgentOptions = {
|
|
@@ -31,10 +30,54 @@ type OperationDef<TResult = unknown, TVariables = Record<string, unknown>, TKind
|
|
|
31
30
|
type OperationMap = Record<string, OperationDef>;
|
|
32
31
|
type InferResult<T extends OperationDef> = NonNullable<T['__result']>;
|
|
33
32
|
type InferVariables<T extends OperationDef> = NonNullable<T['__variables']>;
|
|
34
|
-
type RpcMethod<T extends OperationDef> = T['kind'] extends 'subscription' ? InferVariables<T> extends Record<string, never> ? () =>
|
|
33
|
+
type RpcMethod<T extends OperationDef> = T['kind'] extends 'subscription' ? InferVariables<T> extends Record<string, never> ? () => AsyncIterable<InferResult<T>> : (variables: InferVariables<T>) => AsyncIterable<InferResult<T>> : InferVariables<T> extends Record<string, never> ? () => Promise<InferResult<T>> : (variables: InferVariables<T>) => Promise<InferResult<T>>;
|
|
35
34
|
type Rpc<T extends OperationMap> = {
|
|
36
35
|
[K in keyof T]: RpcMethod<T[K]>;
|
|
37
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Discriminator for how a SourceDef binds to a Subscription field:
|
|
39
|
+
* - `entity` — a Contello entity model collection (`categoriesBatch` etc.), accepts optional `{ ids }` filter
|
|
40
|
+
* - `singleton` — a single Contello entity (`config` etc.), no args
|
|
41
|
+
* - `route` — built-in: `contelloRoutesBatch`, no args
|
|
42
|
+
* - `asset` — built-in: `contelloAssetsBatch`, no args
|
|
43
|
+
* - `i18nMessage` — built-in: `contelloI18nMessagesBatch`, requires `{ collection }`
|
|
44
|
+
*/
|
|
45
|
+
type SourceCardinality = 'entity' | 'singleton' | 'route' | 'asset' | 'i18nMessage';
|
|
46
|
+
type SourceDef<TModel extends string = string, TCardinality extends SourceCardinality = SourceCardinality, TResult = unknown> = {
|
|
47
|
+
/** the GQL fragment text — bundled with transitive deps if any */
|
|
48
|
+
document: string;
|
|
49
|
+
/** the fragment name to spread inside the source subscription — e.g. `Category` */
|
|
50
|
+
fragment: string;
|
|
51
|
+
/** the subscription field this fragment is bound to — `categoriesBatch`, `config`, etc */
|
|
52
|
+
subscription: string;
|
|
53
|
+
__model: TModel;
|
|
54
|
+
__cardinality: TCardinality;
|
|
55
|
+
/** phantom type — exists only at the type level */
|
|
56
|
+
__result?: TResult | undefined;
|
|
57
|
+
};
|
|
58
|
+
type SourceMap = Record<string, SourceDef>;
|
|
59
|
+
/**
|
|
60
|
+
* The bundle emitted by `contello-client generate`. Pass to `createContelloClient({ schema })`
|
|
61
|
+
* (and to `createStore`, `createContello`). Each layer reads what it needs:
|
|
62
|
+
* - client uses `operations` (for `client.rpc.*`) and `sources` (for `client.sources.*`).
|
|
63
|
+
* - store uses `models` (for the dependency resolver) on top of what client uses.
|
|
64
|
+
*/
|
|
65
|
+
type Schema<TOps extends OperationMap = OperationMap, TSources extends SourceMap = SourceMap, TModels extends string = string> = {
|
|
66
|
+
operations: TOps;
|
|
67
|
+
sources: TSources;
|
|
68
|
+
models: Record<TModels, string>;
|
|
69
|
+
};
|
|
70
|
+
type SourceFetcherFor<S> = S extends SourceDef<string, 'singleton', infer R> ? () => Promise<R> : S extends SourceDef<string, 'entity', infer R> ? (vars?: {
|
|
71
|
+
ids?: string[];
|
|
72
|
+
}) => Promise<R[]> : S extends SourceDef<string, 'route', infer R> ? () => Promise<R[]> : S extends SourceDef<string, 'asset', infer R> ? () => Promise<R[]> : S extends SourceDef<string, 'i18nMessage', infer R> ? (vars: {
|
|
73
|
+
collection: string;
|
|
74
|
+
}) => Promise<R[]> : never;
|
|
75
|
+
/** Per-source runtime accessor: `client.sources.category.fetch()` → `Promise<CategoryFragment[]>` etc. */
|
|
76
|
+
type SourceAccessors<TSources extends SourceMap> = {
|
|
77
|
+
[K in keyof TSources]: {
|
|
78
|
+
fetch: SourceFetcherFor<TSources[K]>;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
38
81
|
|
|
39
82
|
type UploadMetadata = {
|
|
40
83
|
name: string;
|
|
@@ -62,11 +105,11 @@ type ConnectionEvents = {
|
|
|
62
105
|
onClosed?: ((context: ConnectionContext) => void) | undefined;
|
|
63
106
|
onError?: ((context: ConnectionContext, error: unknown) => void) | undefined;
|
|
64
107
|
};
|
|
65
|
-
type ContelloClientOptions<
|
|
108
|
+
type ContelloClientOptions<TSchema extends Schema | undefined = undefined> = {
|
|
66
109
|
url: string;
|
|
67
110
|
project: string;
|
|
68
111
|
token: string;
|
|
69
|
-
|
|
112
|
+
schema?: TSchema | undefined;
|
|
70
113
|
connections?: number | undefined;
|
|
71
114
|
http?: HttpAgentOptions | undefined;
|
|
72
115
|
onConnected?: (() => void) | undefined;
|
|
@@ -74,24 +117,109 @@ type ContelloClientOptions<T extends OperationMap | undefined = undefined> = {
|
|
|
74
117
|
onError?: ((error: unknown) => void) | undefined;
|
|
75
118
|
connectionEvents?: ConnectionEvents | undefined;
|
|
76
119
|
};
|
|
77
|
-
declare class ContelloClient<
|
|
120
|
+
declare class ContelloClient<TSchema extends Schema | undefined = undefined> {
|
|
78
121
|
private _pool;
|
|
79
122
|
private _rpc;
|
|
123
|
+
private _sources;
|
|
80
124
|
private _url;
|
|
81
125
|
private _project;
|
|
82
126
|
private _token;
|
|
83
127
|
private _agent;
|
|
84
|
-
constructor(options: ContelloClientOptions<
|
|
85
|
-
get rpc():
|
|
128
|
+
constructor(options: ContelloClientOptions<TSchema>);
|
|
129
|
+
get rpc(): TSchema extends Schema<infer TOps, any, any> ? Rpc<TOps> : never;
|
|
130
|
+
get sources(): TSchema extends Schema<any, infer TSources, any> ? SourceAccessors<TSources> : never;
|
|
86
131
|
init(): Promise<void>;
|
|
87
132
|
destroy(): Promise<void>;
|
|
88
133
|
ping(): Promise<void>;
|
|
89
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Open a subscription on the websocket. Each `[Symbol.asyncIterator]()` call (the implicit one
|
|
136
|
+
* from `for await`, or via `rxjs.from(this)`) starts a fresh server subscription and tears it
|
|
137
|
+
* down when the iterator is returned (`break`, error, or explicit stop).
|
|
138
|
+
*/
|
|
139
|
+
subscribe<TData>(query: string, variables?: Record<string, unknown> | undefined): AsyncIterable<TData>;
|
|
90
140
|
download(fileId: string): Promise<DownloadResult>;
|
|
91
141
|
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
92
142
|
upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
|
|
93
143
|
execute<TData>(query: string, variables?: Record<string, unknown> | undefined): Promise<TData>;
|
|
94
144
|
}
|
|
95
|
-
declare function createContelloClient<
|
|
145
|
+
declare function createContelloClient<TSchema extends Schema | undefined = undefined>(options: ContelloClientOptions<TSchema>): ContelloClient<TSchema>;
|
|
146
|
+
|
|
147
|
+
type LocalDateTime = {
|
|
148
|
+
year: number;
|
|
149
|
+
month: number;
|
|
150
|
+
day: number;
|
|
151
|
+
hour: number;
|
|
152
|
+
minute: number;
|
|
153
|
+
second: number;
|
|
154
|
+
};
|
|
155
|
+
type LocalDate = {
|
|
156
|
+
year: number;
|
|
157
|
+
month: number;
|
|
158
|
+
day: number;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
declare function createSourceSubscription(source: SourceDef): string;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Returns the first value yielded by `iter`, then disposes the iterator. Throws if the iterable
|
|
165
|
+
* completes without yielding. Equivalent of rxjs's `firstValueFrom` for AsyncIterables.
|
|
166
|
+
*/
|
|
167
|
+
declare function firstAsync<T>(iter: AsyncIterable<T>): Promise<T>;
|
|
168
|
+
/** Lazy map over an async iterable. Cleanup propagates: breaking the outer iter disposes the inner. */
|
|
169
|
+
declare function mapAsync<T, R>(iter: AsyncIterable<T>, fn: (value: T) => R): AsyncIterable<R>;
|
|
170
|
+
/** Lazy filter over an async iterable. */
|
|
171
|
+
declare function filterAsync<T>(iter: AsyncIterable<T>, predicate: (value: T) => boolean): AsyncIterable<T>;
|
|
172
|
+
/**
|
|
173
|
+
* Concatenates all elements of all arrays yielded by `iter` into a single array. Used to support
|
|
174
|
+
* subscriptions that emit chunks of items before completing.
|
|
175
|
+
*/
|
|
176
|
+
declare function collectAsync<T>(iter: AsyncIterable<T[]>): Promise<T[]>;
|
|
177
|
+
/**
|
|
178
|
+
* Exponential backoff with jitter. `attempt` starts at 0 → ~1s+jitter, 1 → ~2s+jitter, etc.,
|
|
179
|
+
* capped at 30s. Returns a Promise that resolves after the delay.
|
|
180
|
+
*/
|
|
181
|
+
declare function exponentialBackoff(attempt: number): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Runs `fn` with exponential-backoff retry on rejection. Returns once `fn` resolves successfully.
|
|
184
|
+
* `signal` aborts both the in-flight `fn` (if it observes the signal) and the backoff wait.
|
|
185
|
+
*/
|
|
186
|
+
declare function runWithBackoff(fn: () => Promise<unknown>, signal?: AbortSignal | undefined): Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Long-running stream wrapper: subscribes via `factory()`, yields every value, and on error or
|
|
189
|
+
* unexpected completion re-subscribes with exponential backoff. Stops only when `signal` aborts.
|
|
190
|
+
* Designed for subscriptions that should stay open across reconnects (e.g. the watcher).
|
|
191
|
+
*/
|
|
192
|
+
declare function asyncKeepalive<T>(factory: () => AsyncIterable<T>, signal?: AbortSignal | undefined): AsyncIterable<T>;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Multicast event source with `next` / `error` / `complete` (Subject semantics) plus an
|
|
196
|
+
* `AsyncIterable` view. Two consumption modes that fan out from the same source:
|
|
197
|
+
*
|
|
198
|
+
* - `for await (const v of subject)` — iteration. Each `[Symbol.asyncIterator]()` call returns
|
|
199
|
+
* a fresh per-iterator queue. Stop by `break`ing the loop. On `.error(err)` the iterator's
|
|
200
|
+
* pending `next()` rejects, propagating into the for-await as a thrown exception.
|
|
201
|
+
*
|
|
202
|
+
* - `subject.subscribe(observerOrNext)` — observer style. Pass either a full/partial observer
|
|
203
|
+
* `{ next?, error?, complete? }` or just an `(value) => …` function as the `next`-only shortcut.
|
|
204
|
+
* Returns an unsubscribe function. Missing handlers default to no-ops.
|
|
205
|
+
*
|
|
206
|
+
* Producer side: call `.next(value)` to emit, `.error(err)` to fail the subject (all consumers
|
|
207
|
+
* see the error and are detached), `.complete()` to close cleanly (all consumers see done and
|
|
208
|
+
* are detached). After either `error` or `complete`, further `.next()` calls are dropped and
|
|
209
|
+
* new `.subscribe(...)` calls register a no-op unsubscribe.
|
|
210
|
+
*
|
|
211
|
+
* Backpressure: unbounded queue per pending iterator. Intended for low-frequency events.
|
|
212
|
+
*/
|
|
213
|
+
type AsyncIterableSubject<T> = AsyncIterable<T> & {
|
|
214
|
+
next: (value: T) => void;
|
|
215
|
+
error: (err: unknown) => void;
|
|
216
|
+
complete: () => void;
|
|
217
|
+
subscribe: (observerOrNext: {
|
|
218
|
+
next?: (value: T) => void;
|
|
219
|
+
error?: (err: unknown) => void;
|
|
220
|
+
complete?: () => void;
|
|
221
|
+
} | ((value: T) => void)) => () => void;
|
|
222
|
+
};
|
|
223
|
+
declare function createAsyncIterableSubject<T>(): AsyncIterableSubject<T>;
|
|
96
224
|
|
|
97
|
-
export { type ConnectionContext, type ConnectionEvents, ContelloClient, type ContelloClientOptions, type DownloadResult, type HttpAgentOptions, type OperationDef, type OperationKind, type OperationMap, type ProxyResult, type Rpc, type UploadData, type UploadMetadata, type UploadOptions, createContelloClient };
|
|
225
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
1
|
import { ReadableStream as ReadableStream$1 } from 'node:stream/web';
|
|
3
2
|
|
|
4
3
|
type HttpAgentOptions = {
|
|
@@ -31,10 +30,54 @@ type OperationDef<TResult = unknown, TVariables = Record<string, unknown>, TKind
|
|
|
31
30
|
type OperationMap = Record<string, OperationDef>;
|
|
32
31
|
type InferResult<T extends OperationDef> = NonNullable<T['__result']>;
|
|
33
32
|
type InferVariables<T extends OperationDef> = NonNullable<T['__variables']>;
|
|
34
|
-
type RpcMethod<T extends OperationDef> = T['kind'] extends 'subscription' ? InferVariables<T> extends Record<string, never> ? () =>
|
|
33
|
+
type RpcMethod<T extends OperationDef> = T['kind'] extends 'subscription' ? InferVariables<T> extends Record<string, never> ? () => AsyncIterable<InferResult<T>> : (variables: InferVariables<T>) => AsyncIterable<InferResult<T>> : InferVariables<T> extends Record<string, never> ? () => Promise<InferResult<T>> : (variables: InferVariables<T>) => Promise<InferResult<T>>;
|
|
35
34
|
type Rpc<T extends OperationMap> = {
|
|
36
35
|
[K in keyof T]: RpcMethod<T[K]>;
|
|
37
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Discriminator for how a SourceDef binds to a Subscription field:
|
|
39
|
+
* - `entity` — a Contello entity model collection (`categoriesBatch` etc.), accepts optional `{ ids }` filter
|
|
40
|
+
* - `singleton` — a single Contello entity (`config` etc.), no args
|
|
41
|
+
* - `route` — built-in: `contelloRoutesBatch`, no args
|
|
42
|
+
* - `asset` — built-in: `contelloAssetsBatch`, no args
|
|
43
|
+
* - `i18nMessage` — built-in: `contelloI18nMessagesBatch`, requires `{ collection }`
|
|
44
|
+
*/
|
|
45
|
+
type SourceCardinality = 'entity' | 'singleton' | 'route' | 'asset' | 'i18nMessage';
|
|
46
|
+
type SourceDef<TModel extends string = string, TCardinality extends SourceCardinality = SourceCardinality, TResult = unknown> = {
|
|
47
|
+
/** the GQL fragment text — bundled with transitive deps if any */
|
|
48
|
+
document: string;
|
|
49
|
+
/** the fragment name to spread inside the source subscription — e.g. `Category` */
|
|
50
|
+
fragment: string;
|
|
51
|
+
/** the subscription field this fragment is bound to — `categoriesBatch`, `config`, etc */
|
|
52
|
+
subscription: string;
|
|
53
|
+
__model: TModel;
|
|
54
|
+
__cardinality: TCardinality;
|
|
55
|
+
/** phantom type — exists only at the type level */
|
|
56
|
+
__result?: TResult | undefined;
|
|
57
|
+
};
|
|
58
|
+
type SourceMap = Record<string, SourceDef>;
|
|
59
|
+
/**
|
|
60
|
+
* The bundle emitted by `contello-client generate`. Pass to `createContelloClient({ schema })`
|
|
61
|
+
* (and to `createStore`, `createContello`). Each layer reads what it needs:
|
|
62
|
+
* - client uses `operations` (for `client.rpc.*`) and `sources` (for `client.sources.*`).
|
|
63
|
+
* - store uses `models` (for the dependency resolver) on top of what client uses.
|
|
64
|
+
*/
|
|
65
|
+
type Schema<TOps extends OperationMap = OperationMap, TSources extends SourceMap = SourceMap, TModels extends string = string> = {
|
|
66
|
+
operations: TOps;
|
|
67
|
+
sources: TSources;
|
|
68
|
+
models: Record<TModels, string>;
|
|
69
|
+
};
|
|
70
|
+
type SourceFetcherFor<S> = S extends SourceDef<string, 'singleton', infer R> ? () => Promise<R> : S extends SourceDef<string, 'entity', infer R> ? (vars?: {
|
|
71
|
+
ids?: string[];
|
|
72
|
+
}) => Promise<R[]> : S extends SourceDef<string, 'route', infer R> ? () => Promise<R[]> : S extends SourceDef<string, 'asset', infer R> ? () => Promise<R[]> : S extends SourceDef<string, 'i18nMessage', infer R> ? (vars: {
|
|
73
|
+
collection: string;
|
|
74
|
+
}) => Promise<R[]> : never;
|
|
75
|
+
/** Per-source runtime accessor: `client.sources.category.fetch()` → `Promise<CategoryFragment[]>` etc. */
|
|
76
|
+
type SourceAccessors<TSources extends SourceMap> = {
|
|
77
|
+
[K in keyof TSources]: {
|
|
78
|
+
fetch: SourceFetcherFor<TSources[K]>;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
38
81
|
|
|
39
82
|
type UploadMetadata = {
|
|
40
83
|
name: string;
|
|
@@ -62,11 +105,11 @@ type ConnectionEvents = {
|
|
|
62
105
|
onClosed?: ((context: ConnectionContext) => void) | undefined;
|
|
63
106
|
onError?: ((context: ConnectionContext, error: unknown) => void) | undefined;
|
|
64
107
|
};
|
|
65
|
-
type ContelloClientOptions<
|
|
108
|
+
type ContelloClientOptions<TSchema extends Schema | undefined = undefined> = {
|
|
66
109
|
url: string;
|
|
67
110
|
project: string;
|
|
68
111
|
token: string;
|
|
69
|
-
|
|
112
|
+
schema?: TSchema | undefined;
|
|
70
113
|
connections?: number | undefined;
|
|
71
114
|
http?: HttpAgentOptions | undefined;
|
|
72
115
|
onConnected?: (() => void) | undefined;
|
|
@@ -74,24 +117,109 @@ type ContelloClientOptions<T extends OperationMap | undefined = undefined> = {
|
|
|
74
117
|
onError?: ((error: unknown) => void) | undefined;
|
|
75
118
|
connectionEvents?: ConnectionEvents | undefined;
|
|
76
119
|
};
|
|
77
|
-
declare class ContelloClient<
|
|
120
|
+
declare class ContelloClient<TSchema extends Schema | undefined = undefined> {
|
|
78
121
|
private _pool;
|
|
79
122
|
private _rpc;
|
|
123
|
+
private _sources;
|
|
80
124
|
private _url;
|
|
81
125
|
private _project;
|
|
82
126
|
private _token;
|
|
83
127
|
private _agent;
|
|
84
|
-
constructor(options: ContelloClientOptions<
|
|
85
|
-
get rpc():
|
|
128
|
+
constructor(options: ContelloClientOptions<TSchema>);
|
|
129
|
+
get rpc(): TSchema extends Schema<infer TOps, any, any> ? Rpc<TOps> : never;
|
|
130
|
+
get sources(): TSchema extends Schema<any, infer TSources, any> ? SourceAccessors<TSources> : never;
|
|
86
131
|
init(): Promise<void>;
|
|
87
132
|
destroy(): Promise<void>;
|
|
88
133
|
ping(): Promise<void>;
|
|
89
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Open a subscription on the websocket. Each `[Symbol.asyncIterator]()` call (the implicit one
|
|
136
|
+
* from `for await`, or via `rxjs.from(this)`) starts a fresh server subscription and tears it
|
|
137
|
+
* down when the iterator is returned (`break`, error, or explicit stop).
|
|
138
|
+
*/
|
|
139
|
+
subscribe<TData>(query: string, variables?: Record<string, unknown> | undefined): AsyncIterable<TData>;
|
|
90
140
|
download(fileId: string): Promise<DownloadResult>;
|
|
91
141
|
proxyHls(path: string, signal?: AbortSignal | undefined): Promise<ProxyResult>;
|
|
92
142
|
upload(data: UploadData, meta: UploadMetadata, options?: UploadOptions | undefined): Promise<string>;
|
|
93
143
|
execute<TData>(query: string, variables?: Record<string, unknown> | undefined): Promise<TData>;
|
|
94
144
|
}
|
|
95
|
-
declare function createContelloClient<
|
|
145
|
+
declare function createContelloClient<TSchema extends Schema | undefined = undefined>(options: ContelloClientOptions<TSchema>): ContelloClient<TSchema>;
|
|
146
|
+
|
|
147
|
+
type LocalDateTime = {
|
|
148
|
+
year: number;
|
|
149
|
+
month: number;
|
|
150
|
+
day: number;
|
|
151
|
+
hour: number;
|
|
152
|
+
minute: number;
|
|
153
|
+
second: number;
|
|
154
|
+
};
|
|
155
|
+
type LocalDate = {
|
|
156
|
+
year: number;
|
|
157
|
+
month: number;
|
|
158
|
+
day: number;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
declare function createSourceSubscription(source: SourceDef): string;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Returns the first value yielded by `iter`, then disposes the iterator. Throws if the iterable
|
|
165
|
+
* completes without yielding. Equivalent of rxjs's `firstValueFrom` for AsyncIterables.
|
|
166
|
+
*/
|
|
167
|
+
declare function firstAsync<T>(iter: AsyncIterable<T>): Promise<T>;
|
|
168
|
+
/** Lazy map over an async iterable. Cleanup propagates: breaking the outer iter disposes the inner. */
|
|
169
|
+
declare function mapAsync<T, R>(iter: AsyncIterable<T>, fn: (value: T) => R): AsyncIterable<R>;
|
|
170
|
+
/** Lazy filter over an async iterable. */
|
|
171
|
+
declare function filterAsync<T>(iter: AsyncIterable<T>, predicate: (value: T) => boolean): AsyncIterable<T>;
|
|
172
|
+
/**
|
|
173
|
+
* Concatenates all elements of all arrays yielded by `iter` into a single array. Used to support
|
|
174
|
+
* subscriptions that emit chunks of items before completing.
|
|
175
|
+
*/
|
|
176
|
+
declare function collectAsync<T>(iter: AsyncIterable<T[]>): Promise<T[]>;
|
|
177
|
+
/**
|
|
178
|
+
* Exponential backoff with jitter. `attempt` starts at 0 → ~1s+jitter, 1 → ~2s+jitter, etc.,
|
|
179
|
+
* capped at 30s. Returns a Promise that resolves after the delay.
|
|
180
|
+
*/
|
|
181
|
+
declare function exponentialBackoff(attempt: number): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Runs `fn` with exponential-backoff retry on rejection. Returns once `fn` resolves successfully.
|
|
184
|
+
* `signal` aborts both the in-flight `fn` (if it observes the signal) and the backoff wait.
|
|
185
|
+
*/
|
|
186
|
+
declare function runWithBackoff(fn: () => Promise<unknown>, signal?: AbortSignal | undefined): Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Long-running stream wrapper: subscribes via `factory()`, yields every value, and on error or
|
|
189
|
+
* unexpected completion re-subscribes with exponential backoff. Stops only when `signal` aborts.
|
|
190
|
+
* Designed for subscriptions that should stay open across reconnects (e.g. the watcher).
|
|
191
|
+
*/
|
|
192
|
+
declare function asyncKeepalive<T>(factory: () => AsyncIterable<T>, signal?: AbortSignal | undefined): AsyncIterable<T>;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Multicast event source with `next` / `error` / `complete` (Subject semantics) plus an
|
|
196
|
+
* `AsyncIterable` view. Two consumption modes that fan out from the same source:
|
|
197
|
+
*
|
|
198
|
+
* - `for await (const v of subject)` — iteration. Each `[Symbol.asyncIterator]()` call returns
|
|
199
|
+
* a fresh per-iterator queue. Stop by `break`ing the loop. On `.error(err)` the iterator's
|
|
200
|
+
* pending `next()` rejects, propagating into the for-await as a thrown exception.
|
|
201
|
+
*
|
|
202
|
+
* - `subject.subscribe(observerOrNext)` — observer style. Pass either a full/partial observer
|
|
203
|
+
* `{ next?, error?, complete? }` or just an `(value) => …` function as the `next`-only shortcut.
|
|
204
|
+
* Returns an unsubscribe function. Missing handlers default to no-ops.
|
|
205
|
+
*
|
|
206
|
+
* Producer side: call `.next(value)` to emit, `.error(err)` to fail the subject (all consumers
|
|
207
|
+
* see the error and are detached), `.complete()` to close cleanly (all consumers see done and
|
|
208
|
+
* are detached). After either `error` or `complete`, further `.next()` calls are dropped and
|
|
209
|
+
* new `.subscribe(...)` calls register a no-op unsubscribe.
|
|
210
|
+
*
|
|
211
|
+
* Backpressure: unbounded queue per pending iterator. Intended for low-frequency events.
|
|
212
|
+
*/
|
|
213
|
+
type AsyncIterableSubject<T> = AsyncIterable<T> & {
|
|
214
|
+
next: (value: T) => void;
|
|
215
|
+
error: (err: unknown) => void;
|
|
216
|
+
complete: () => void;
|
|
217
|
+
subscribe: (observerOrNext: {
|
|
218
|
+
next?: (value: T) => void;
|
|
219
|
+
error?: (err: unknown) => void;
|
|
220
|
+
complete?: () => void;
|
|
221
|
+
} | ((value: T) => void)) => () => void;
|
|
222
|
+
};
|
|
223
|
+
declare function createAsyncIterableSubject<T>(): AsyncIterableSubject<T>;
|
|
96
224
|
|
|
97
|
-
export { type ConnectionContext, type ConnectionEvents, ContelloClient, type ContelloClientOptions, type DownloadResult, type HttpAgentOptions, type OperationDef, type OperationKind, type OperationMap, type ProxyResult, type Rpc, type UploadData, type UploadMetadata, type UploadOptions, createContelloClient };
|
|
225
|
+
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 };
|