@mearie/core 0.0.0-next-20260228035926
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/LICENSE +20 -0
- package/README.md +10 -0
- package/dist/index.cjs +1410 -0
- package/dist/index.d.cts +348 -0
- package/dist/index.d.mts +348 -0
- package/dist/index.mjs +1393 -0
- package/dist/make-BhxZYW3l.d.cts +405 -0
- package/dist/make-C7I1YIXm.mjs +712 -0
- package/dist/make-DxW2Pxe-.cjs +856 -0
- package/dist/make-Ve8TkMHJ.d.mts +405 -0
- package/dist/stream/index.cjs +27 -0
- package/dist/stream/index.d.cts +2 -0
- package/dist/stream/index.d.mts +2 -0
- package/dist/stream/index.mjs +3 -0
- package/package.json +79 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { k as Source } from "./make-BhxZYW3l.cjs";
|
|
2
|
+
import { Artifact, Artifact as Artifact$1, ArtifactKind, ArtifactKind as ArtifactKind$1, DataOf, DataOf as DataOf$1, FragmentRefs, FragmentRefs as FragmentRefs$1, SchemaMeta, SchemaMeta as SchemaMeta$1, VariablesOf, VariablesOf as VariablesOf$1 } from "@mearie/shared";
|
|
3
|
+
|
|
4
|
+
//#region src/errors.d.ts
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
declare class GraphQLError extends Error {
|
|
9
|
+
readonly path?: readonly (string | number)[];
|
|
10
|
+
readonly locations?: readonly {
|
|
11
|
+
line: number;
|
|
12
|
+
column: number;
|
|
13
|
+
}[];
|
|
14
|
+
readonly extensions?: Record<string, unknown>;
|
|
15
|
+
constructor(message: string, options?: {
|
|
16
|
+
path?: readonly (string | number)[];
|
|
17
|
+
locations?: readonly {
|
|
18
|
+
line: number;
|
|
19
|
+
column: number;
|
|
20
|
+
}[];
|
|
21
|
+
extensions?: Record<string, unknown>;
|
|
22
|
+
cause?: unknown;
|
|
23
|
+
});
|
|
24
|
+
toJSON(): Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
interface ExchangeErrorExtensionsMap {}
|
|
27
|
+
type OperationError = GraphQLError | ExchangeError<string>;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
declare class ExchangeError<const TName extends keyof ExchangeErrorExtensionsMap | (string & {}) = string> extends Error {
|
|
32
|
+
readonly exchangeName: TName;
|
|
33
|
+
readonly extensions: TName extends keyof ExchangeErrorExtensionsMap ? ExchangeErrorExtensionsMap[TName] : Record<string, unknown> | undefined;
|
|
34
|
+
constructor(message: string, options: {
|
|
35
|
+
exchangeName: TName;
|
|
36
|
+
cause?: unknown;
|
|
37
|
+
} & (TName extends keyof ExchangeErrorExtensionsMap ? undefined extends ExchangeErrorExtensionsMap[TName] ? {
|
|
38
|
+
extensions?: Exclude<ExchangeErrorExtensionsMap[TName], undefined>;
|
|
39
|
+
} : {
|
|
40
|
+
extensions: ExchangeErrorExtensionsMap[TName];
|
|
41
|
+
} : {
|
|
42
|
+
extensions?: Record<string, unknown>;
|
|
43
|
+
}));
|
|
44
|
+
toJSON(): Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
declare class AggregatedError extends AggregateError {
|
|
50
|
+
readonly errors: OperationError[];
|
|
51
|
+
constructor(errors: readonly OperationError[], message?: string);
|
|
52
|
+
toJSON(): Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
declare const isGraphQLError: (error: unknown) => error is GraphQLError;
|
|
55
|
+
declare function isExchangeError(error: unknown): error is ExchangeError<string>;
|
|
56
|
+
declare function isExchangeError<const TName extends keyof ExchangeErrorExtensionsMap | (string & {})>(error: unknown, exchangeName: TName): error is ExchangeError<TName>;
|
|
57
|
+
declare const isAggregatedError: (error: unknown) => error is AggregatedError;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/scalars.d.ts
|
|
60
|
+
type ScalarTransformer<TExternal = unknown, TInternal = unknown> = {
|
|
61
|
+
parse: (value: TInternal) => TExternal;
|
|
62
|
+
serialize: (value: TExternal) => TInternal;
|
|
63
|
+
};
|
|
64
|
+
type ScalarsConfig<TMeta extends SchemaMeta$1 = SchemaMeta$1> = { [K in keyof TMeta['scalars']]: ScalarTransformer<TMeta['scalars'][K], unknown> };
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/client.d.ts
|
|
67
|
+
type QueryOptions<T extends Artifact$1<'query'> = Artifact$1<'query'>> = {
|
|
68
|
+
initialData?: DataOf$1<T>;
|
|
69
|
+
metadata?: OperationMetadata;
|
|
70
|
+
};
|
|
71
|
+
type MutationOptions = {
|
|
72
|
+
metadata?: OperationMetadata;
|
|
73
|
+
};
|
|
74
|
+
type SubscriptionOptions = {
|
|
75
|
+
metadata?: OperationMetadata;
|
|
76
|
+
};
|
|
77
|
+
type FragmentOptions = {
|
|
78
|
+
metadata?: OperationMetadata;
|
|
79
|
+
};
|
|
80
|
+
type ClientOptions<T extends SchemaMeta$1> = {
|
|
81
|
+
schema: T;
|
|
82
|
+
exchanges: Exchange[];
|
|
83
|
+
} & (T['scalars'] extends Record<string, never> ? {
|
|
84
|
+
scalars?: undefined;
|
|
85
|
+
} : {
|
|
86
|
+
scalars: ScalarsConfig<T>;
|
|
87
|
+
});
|
|
88
|
+
declare class Client<TMeta extends SchemaMeta$1 = SchemaMeta$1> {
|
|
89
|
+
#private;
|
|
90
|
+
private operations$;
|
|
91
|
+
private results$;
|
|
92
|
+
constructor(config: ClientOptions<TMeta>);
|
|
93
|
+
get schema(): TMeta;
|
|
94
|
+
get scalars(): ScalarsConfig<TMeta> | undefined;
|
|
95
|
+
private createOperationKey;
|
|
96
|
+
createOperation(artifact: Artifact$1, variables?: unknown, metadata?: OperationMetadata): Operation;
|
|
97
|
+
executeOperation(operation: Operation): Source<OperationResult>;
|
|
98
|
+
executeQuery<T extends Artifact$1<'query'>>(artifact: T, ...[variables, options]: VariablesOf$1<T> extends undefined ? [undefined?, QueryOptions<T>?] : [VariablesOf$1<T>, QueryOptions<T>?]): Source<OperationResult>;
|
|
99
|
+
executeMutation<T extends Artifact$1<'mutation'>>(artifact: T, ...[variables, options]: VariablesOf$1<T> extends undefined ? [undefined?, MutationOptions?] : [VariablesOf$1<T>, MutationOptions?]): Source<OperationResult>;
|
|
100
|
+
executeSubscription<T extends Artifact$1<'subscription'>>(artifact: T, ...[variables, options]: VariablesOf$1<T> extends undefined ? [undefined?, SubscriptionOptions?] : [VariablesOf$1<T>, SubscriptionOptions?]): Source<OperationResult>;
|
|
101
|
+
executeFragment<T extends Artifact$1<'fragment'>>(artifact: T, fragmentRef: FragmentRefs$1<T['name']> | FragmentRefs$1<T['name']>[], options?: FragmentOptions): Source<OperationResult>;
|
|
102
|
+
query<T extends Artifact$1<'query'>>(artifact: T, ...[variables, options]: VariablesOf$1<T> extends undefined ? [undefined?, QueryOptions<T>?] : [VariablesOf$1<T>, QueryOptions<T>?]): Promise<DataOf$1<T>>;
|
|
103
|
+
mutation<T extends Artifact$1<'mutation'>>(artifact: T, ...[variables, options]: VariablesOf$1<T> extends undefined ? [undefined?, MutationOptions?] : [VariablesOf$1<T>, MutationOptions?]): Promise<DataOf$1<T>>;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the extension registered by a named exchange.
|
|
106
|
+
* @param name - The exchange name.
|
|
107
|
+
* @returns The extension object provided by the exchange.
|
|
108
|
+
*/
|
|
109
|
+
extension<TName extends keyof ExchangeExtensionMap>(name: TName): ExchangeExtensionMap[TName];
|
|
110
|
+
extension(name: string): unknown;
|
|
111
|
+
maybeExtension<TName extends keyof ExchangeExtensionMap>(name: TName): ExchangeExtensionMap[TName] | undefined;
|
|
112
|
+
maybeExtension(name: string): unknown;
|
|
113
|
+
dispose(): void;
|
|
114
|
+
}
|
|
115
|
+
declare const createClient: <T extends SchemaMeta$1>(config: ClientOptions<T>) => Client<T>;
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/exchange.d.ts
|
|
118
|
+
interface OperationMetadataMap {}
|
|
119
|
+
type OperationMetadata = { [K in keyof OperationMetadataMap]?: OperationMetadataMap[K] } & Record<string, unknown>;
|
|
120
|
+
type BaseOperation = {
|
|
121
|
+
key: string;
|
|
122
|
+
metadata: OperationMetadataMap & Record<string, unknown>;
|
|
123
|
+
};
|
|
124
|
+
type RequestOperation<K extends ArtifactKind$1 = ArtifactKind$1> = BaseOperation & {
|
|
125
|
+
variant: 'request';
|
|
126
|
+
artifact: Artifact$1<K>;
|
|
127
|
+
variables: VariablesOf$1<Artifact$1<K>>;
|
|
128
|
+
};
|
|
129
|
+
type TeardownOperation = BaseOperation & {
|
|
130
|
+
variant: 'teardown';
|
|
131
|
+
};
|
|
132
|
+
type Operation<K extends ArtifactKind$1 = ArtifactKind$1> = RequestOperation<K> | TeardownOperation;
|
|
133
|
+
type OperationResult = {
|
|
134
|
+
operation: Operation;
|
|
135
|
+
data?: unknown;
|
|
136
|
+
errors?: readonly OperationError[];
|
|
137
|
+
extensions?: Record<string, unknown>;
|
|
138
|
+
stale?: boolean;
|
|
139
|
+
};
|
|
140
|
+
type ExchangeInput<TMeta extends SchemaMeta$1 = SchemaMeta$1> = {
|
|
141
|
+
forward: ExchangeIO;
|
|
142
|
+
client: Client<TMeta>;
|
|
143
|
+
};
|
|
144
|
+
type ExchangeIO = (operations: Source<Operation>) => Source<OperationResult>;
|
|
145
|
+
interface ExchangeExtensionMap {}
|
|
146
|
+
type ExchangeResult<TName extends keyof ExchangeExtensionMap | (string & {}) = string> = {
|
|
147
|
+
name: TName;
|
|
148
|
+
io: ExchangeIO;
|
|
149
|
+
} & (TName extends keyof ExchangeExtensionMap ? {
|
|
150
|
+
extension: ExchangeExtensionMap[TName];
|
|
151
|
+
} : {});
|
|
152
|
+
type Exchange<TName extends keyof ExchangeExtensionMap | (string & {}) = string> = <TMeta extends SchemaMeta$1 = SchemaMeta$1>(input: ExchangeInput<TMeta>) => ExchangeResult<TName>;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/exchanges/http.d.ts
|
|
155
|
+
declare module '@mearie/core' {
|
|
156
|
+
interface ExchangeErrorExtensionsMap {
|
|
157
|
+
http?: {
|
|
158
|
+
statusCode?: number;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
type HttpOptions = {
|
|
163
|
+
url: string;
|
|
164
|
+
headers?: HeadersInit;
|
|
165
|
+
mode?: RequestMode;
|
|
166
|
+
credentials?: RequestCredentials;
|
|
167
|
+
fetch?: typeof globalThis.fetch;
|
|
168
|
+
};
|
|
169
|
+
declare const httpExchange: (options: HttpOptions) => Exchange;
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/exchanges/dedup.d.ts
|
|
172
|
+
declare module '@mearie/core' {
|
|
173
|
+
interface OperationMetadataMap {
|
|
174
|
+
dedup?: {
|
|
175
|
+
skip?: boolean;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Prevents duplicate in-flight operations by deduplicating requests with identical artifact names and variables.
|
|
181
|
+
*
|
|
182
|
+
* Operations are considered identical if they have the same artifact name and serialized variables.
|
|
183
|
+
* Mutations are never deduplicated. An operation is "in-flight" from when it's first seen until all subscribers tear down.
|
|
184
|
+
*
|
|
185
|
+
* Caveats:
|
|
186
|
+
*
|
|
187
|
+
* 1. Upstream metadata is lost when operations are deduplicated. The result will contain the metadata
|
|
188
|
+
* from the operation that actually went through the pipeline, not from deduplicated operations.
|
|
189
|
+
* This preserves downstream metadata (retry attempts, cache status) but means custom upstream metadata
|
|
190
|
+
* from deduplicated operations will not appear in results.
|
|
191
|
+
* @internal
|
|
192
|
+
* @returns An exchange that deduplicates in-flight operations.
|
|
193
|
+
*/
|
|
194
|
+
declare const dedupExchange: () => Exchange;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/cache/types.d.ts
|
|
197
|
+
/**
|
|
198
|
+
* Identifier for a single entity, supporting simple or composite keys.
|
|
199
|
+
*/
|
|
200
|
+
type EntityId = string | number | Record<string, string | number>;
|
|
201
|
+
/**
|
|
202
|
+
* Target specification for cache invalidation operations.
|
|
203
|
+
*/
|
|
204
|
+
type InvalidateTarget = {
|
|
205
|
+
__typename: string;
|
|
206
|
+
id: EntityId;
|
|
207
|
+
} | {
|
|
208
|
+
__typename: string;
|
|
209
|
+
id: EntityId;
|
|
210
|
+
field: string;
|
|
211
|
+
args?: Record<string, unknown>;
|
|
212
|
+
} | {
|
|
213
|
+
__typename: 'Query';
|
|
214
|
+
} | {
|
|
215
|
+
__typename: 'Query';
|
|
216
|
+
field: string;
|
|
217
|
+
args?: Record<string, unknown>;
|
|
218
|
+
} | {
|
|
219
|
+
__typename: string;
|
|
220
|
+
} | {
|
|
221
|
+
__typename: string;
|
|
222
|
+
field: string;
|
|
223
|
+
args?: Record<string, unknown>;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Opaque type representing a serializable cache snapshot.
|
|
227
|
+
*/
|
|
228
|
+
type CacheSnapshot = {
|
|
229
|
+
readonly __brand: unique symbol;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Operations available for programmatic cache manipulation.
|
|
233
|
+
*/
|
|
234
|
+
type CacheOperations = {
|
|
235
|
+
extract(): CacheSnapshot;
|
|
236
|
+
hydrate(data: CacheSnapshot): void;
|
|
237
|
+
invalidate(...targets: InvalidateTarget[]): void;
|
|
238
|
+
clear(): void;
|
|
239
|
+
};
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/exchanges/cache.d.ts
|
|
242
|
+
declare module '@mearie/core' {
|
|
243
|
+
interface ExchangeExtensionMap {
|
|
244
|
+
cache: CacheOperations;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
type CacheOptions = {
|
|
248
|
+
fetchPolicy?: 'cache-first' | 'cache-and-network' | 'network-only' | 'cache-only';
|
|
249
|
+
};
|
|
250
|
+
declare const cacheExchange: (options?: CacheOptions) => Exchange<"cache">;
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/exchanges/retry.d.ts
|
|
253
|
+
declare module '@mearie/core' {
|
|
254
|
+
interface OperationMetadataMap {
|
|
255
|
+
retry?: {
|
|
256
|
+
attempt: number;
|
|
257
|
+
delay: number;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
type RetryOptions = {
|
|
262
|
+
maxAttempts?: number;
|
|
263
|
+
backoff?: (attempt: number) => number;
|
|
264
|
+
shouldRetry?: (error: OperationError) => boolean;
|
|
265
|
+
};
|
|
266
|
+
declare const retryExchange: (options?: RetryOptions) => Exchange;
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/exchanges/fragment.d.ts
|
|
269
|
+
declare module '@mearie/core' {
|
|
270
|
+
interface OperationMetadataMap {
|
|
271
|
+
fragmentRef?: unknown;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
declare const fragmentExchange: () => Exchange;
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/exchanges/required.d.ts
|
|
277
|
+
declare const requiredExchange: () => Exchange;
|
|
278
|
+
//#endregion
|
|
279
|
+
//#region src/exchanges/subscription.d.ts
|
|
280
|
+
interface SubscriptionClient {
|
|
281
|
+
subscribe(payload: {
|
|
282
|
+
operationName?: string;
|
|
283
|
+
query: string;
|
|
284
|
+
variables?: Record<string, unknown>;
|
|
285
|
+
}, sink: {
|
|
286
|
+
next: (result: unknown) => void;
|
|
287
|
+
error: (error: unknown) => void;
|
|
288
|
+
complete: () => void;
|
|
289
|
+
}): () => void;
|
|
290
|
+
}
|
|
291
|
+
type SubscriptionExchangeOptions = {
|
|
292
|
+
client: SubscriptionClient;
|
|
293
|
+
};
|
|
294
|
+
declare module '@mearie/core' {
|
|
295
|
+
interface OperationMetadataMap {
|
|
296
|
+
subscription?: {
|
|
297
|
+
transport?: boolean;
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Creates an exchange for handling GraphQL subscriptions using a subscription client.
|
|
303
|
+
*
|
|
304
|
+
* This exchange accepts subscription clients from graphql-ws, graphql-sse, or any client
|
|
305
|
+
* implementing the Observer pattern.
|
|
306
|
+
* @internal
|
|
307
|
+
* @param options - Configuration options for the subscription exchange.
|
|
308
|
+
* @returns An exchange that handles subscription operations.
|
|
309
|
+
* @example
|
|
310
|
+
* // With graphql-ws
|
|
311
|
+
* import { createClient } from 'graphql-ws';
|
|
312
|
+
*
|
|
313
|
+
* const wsClient = createClient({
|
|
314
|
+
* url: 'ws://localhost:4000/graphql',
|
|
315
|
+
* });
|
|
316
|
+
*
|
|
317
|
+
* subscriptionExchange({ client: wsClient })
|
|
318
|
+
* @example
|
|
319
|
+
* // With graphql-sse
|
|
320
|
+
* import { createClient } from 'graphql-sse';
|
|
321
|
+
*
|
|
322
|
+
* const sseClient = createClient({
|
|
323
|
+
* url: 'http://localhost:4000/graphql/stream',
|
|
324
|
+
* });
|
|
325
|
+
*
|
|
326
|
+
* subscriptionExchange({ client: sseClient })
|
|
327
|
+
*/
|
|
328
|
+
declare const subscriptionExchange: (options: SubscriptionExchangeOptions) => Exchange;
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/required.d.ts
|
|
331
|
+
type RequiredAction = 'THROW' | 'CASCADE';
|
|
332
|
+
declare class RequiredFieldError extends Error {
|
|
333
|
+
fieldPath: string[];
|
|
334
|
+
fieldName: string;
|
|
335
|
+
constructor(fieldPath: string[], fieldName: string);
|
|
336
|
+
}
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/utils.d.ts
|
|
339
|
+
/**
|
|
340
|
+
* Stable JSON serialization with sorted keys.
|
|
341
|
+
* Used for both variables and field arguments.
|
|
342
|
+
* @internal
|
|
343
|
+
* @param value - The value to stringify.
|
|
344
|
+
* @returns The stable JSON string.
|
|
345
|
+
*/
|
|
346
|
+
declare const stringify: (value: unknown) => string;
|
|
347
|
+
//#endregion
|
|
348
|
+
export { AggregatedError, type Artifact, type ArtifactKind, type CacheOptions, type CacheSnapshot, Client, type ClientOptions, type DataOf, type Exchange, ExchangeError, type ExchangeErrorExtensionsMap, type ExchangeExtensionMap, type ExchangeIO, type ExchangeResult, type FragmentOptions, type FragmentRefs, GraphQLError, type HttpOptions, type MutationOptions, type Operation, type OperationError, type OperationMetadata, type OperationMetadataMap, type OperationResult, type QueryOptions, type RequiredAction, RequiredFieldError, type RetryOptions, type SchemaMeta, type SubscriptionClient, type SubscriptionExchangeOptions, type SubscriptionOptions, type VariablesOf, cacheExchange, createClient, dedupExchange, fragmentExchange, httpExchange, isAggregatedError, isExchangeError, isGraphQLError, requiredExchange, retryExchange, stringify, subscriptionExchange };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { k as Source } from "./make-Ve8TkMHJ.mjs";
|
|
2
|
+
import { Artifact, Artifact as Artifact$1, ArtifactKind, ArtifactKind as ArtifactKind$1, DataOf, DataOf as DataOf$1, FragmentRefs, FragmentRefs as FragmentRefs$1, SchemaMeta, SchemaMeta as SchemaMeta$1, VariablesOf, VariablesOf as VariablesOf$1 } from "@mearie/shared";
|
|
3
|
+
|
|
4
|
+
//#region src/errors.d.ts
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
declare class GraphQLError extends Error {
|
|
9
|
+
readonly path?: readonly (string | number)[];
|
|
10
|
+
readonly locations?: readonly {
|
|
11
|
+
line: number;
|
|
12
|
+
column: number;
|
|
13
|
+
}[];
|
|
14
|
+
readonly extensions?: Record<string, unknown>;
|
|
15
|
+
constructor(message: string, options?: {
|
|
16
|
+
path?: readonly (string | number)[];
|
|
17
|
+
locations?: readonly {
|
|
18
|
+
line: number;
|
|
19
|
+
column: number;
|
|
20
|
+
}[];
|
|
21
|
+
extensions?: Record<string, unknown>;
|
|
22
|
+
cause?: unknown;
|
|
23
|
+
});
|
|
24
|
+
toJSON(): Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
interface ExchangeErrorExtensionsMap {}
|
|
27
|
+
type OperationError = GraphQLError | ExchangeError<string>;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
declare class ExchangeError<const TName extends keyof ExchangeErrorExtensionsMap | (string & {}) = string> extends Error {
|
|
32
|
+
readonly exchangeName: TName;
|
|
33
|
+
readonly extensions: TName extends keyof ExchangeErrorExtensionsMap ? ExchangeErrorExtensionsMap[TName] : Record<string, unknown> | undefined;
|
|
34
|
+
constructor(message: string, options: {
|
|
35
|
+
exchangeName: TName;
|
|
36
|
+
cause?: unknown;
|
|
37
|
+
} & (TName extends keyof ExchangeErrorExtensionsMap ? undefined extends ExchangeErrorExtensionsMap[TName] ? {
|
|
38
|
+
extensions?: Exclude<ExchangeErrorExtensionsMap[TName], undefined>;
|
|
39
|
+
} : {
|
|
40
|
+
extensions: ExchangeErrorExtensionsMap[TName];
|
|
41
|
+
} : {
|
|
42
|
+
extensions?: Record<string, unknown>;
|
|
43
|
+
}));
|
|
44
|
+
toJSON(): Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
declare class AggregatedError extends AggregateError {
|
|
50
|
+
readonly errors: OperationError[];
|
|
51
|
+
constructor(errors: readonly OperationError[], message?: string);
|
|
52
|
+
toJSON(): Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
declare const isGraphQLError: (error: unknown) => error is GraphQLError;
|
|
55
|
+
declare function isExchangeError(error: unknown): error is ExchangeError<string>;
|
|
56
|
+
declare function isExchangeError<const TName extends keyof ExchangeErrorExtensionsMap | (string & {})>(error: unknown, exchangeName: TName): error is ExchangeError<TName>;
|
|
57
|
+
declare const isAggregatedError: (error: unknown) => error is AggregatedError;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/scalars.d.ts
|
|
60
|
+
type ScalarTransformer<TExternal = unknown, TInternal = unknown> = {
|
|
61
|
+
parse: (value: TInternal) => TExternal;
|
|
62
|
+
serialize: (value: TExternal) => TInternal;
|
|
63
|
+
};
|
|
64
|
+
type ScalarsConfig<TMeta extends SchemaMeta$1 = SchemaMeta$1> = { [K in keyof TMeta['scalars']]: ScalarTransformer<TMeta['scalars'][K], unknown> };
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/client.d.ts
|
|
67
|
+
type QueryOptions<T extends Artifact$1<'query'> = Artifact$1<'query'>> = {
|
|
68
|
+
initialData?: DataOf$1<T>;
|
|
69
|
+
metadata?: OperationMetadata;
|
|
70
|
+
};
|
|
71
|
+
type MutationOptions = {
|
|
72
|
+
metadata?: OperationMetadata;
|
|
73
|
+
};
|
|
74
|
+
type SubscriptionOptions = {
|
|
75
|
+
metadata?: OperationMetadata;
|
|
76
|
+
};
|
|
77
|
+
type FragmentOptions = {
|
|
78
|
+
metadata?: OperationMetadata;
|
|
79
|
+
};
|
|
80
|
+
type ClientOptions<T extends SchemaMeta$1> = {
|
|
81
|
+
schema: T;
|
|
82
|
+
exchanges: Exchange[];
|
|
83
|
+
} & (T['scalars'] extends Record<string, never> ? {
|
|
84
|
+
scalars?: undefined;
|
|
85
|
+
} : {
|
|
86
|
+
scalars: ScalarsConfig<T>;
|
|
87
|
+
});
|
|
88
|
+
declare class Client<TMeta extends SchemaMeta$1 = SchemaMeta$1> {
|
|
89
|
+
#private;
|
|
90
|
+
private operations$;
|
|
91
|
+
private results$;
|
|
92
|
+
constructor(config: ClientOptions<TMeta>);
|
|
93
|
+
get schema(): TMeta;
|
|
94
|
+
get scalars(): ScalarsConfig<TMeta> | undefined;
|
|
95
|
+
private createOperationKey;
|
|
96
|
+
createOperation(artifact: Artifact$1, variables?: unknown, metadata?: OperationMetadata): Operation;
|
|
97
|
+
executeOperation(operation: Operation): Source<OperationResult>;
|
|
98
|
+
executeQuery<T extends Artifact$1<'query'>>(artifact: T, ...[variables, options]: VariablesOf$1<T> extends undefined ? [undefined?, QueryOptions<T>?] : [VariablesOf$1<T>, QueryOptions<T>?]): Source<OperationResult>;
|
|
99
|
+
executeMutation<T extends Artifact$1<'mutation'>>(artifact: T, ...[variables, options]: VariablesOf$1<T> extends undefined ? [undefined?, MutationOptions?] : [VariablesOf$1<T>, MutationOptions?]): Source<OperationResult>;
|
|
100
|
+
executeSubscription<T extends Artifact$1<'subscription'>>(artifact: T, ...[variables, options]: VariablesOf$1<T> extends undefined ? [undefined?, SubscriptionOptions?] : [VariablesOf$1<T>, SubscriptionOptions?]): Source<OperationResult>;
|
|
101
|
+
executeFragment<T extends Artifact$1<'fragment'>>(artifact: T, fragmentRef: FragmentRefs$1<T['name']> | FragmentRefs$1<T['name']>[], options?: FragmentOptions): Source<OperationResult>;
|
|
102
|
+
query<T extends Artifact$1<'query'>>(artifact: T, ...[variables, options]: VariablesOf$1<T> extends undefined ? [undefined?, QueryOptions<T>?] : [VariablesOf$1<T>, QueryOptions<T>?]): Promise<DataOf$1<T>>;
|
|
103
|
+
mutation<T extends Artifact$1<'mutation'>>(artifact: T, ...[variables, options]: VariablesOf$1<T> extends undefined ? [undefined?, MutationOptions?] : [VariablesOf$1<T>, MutationOptions?]): Promise<DataOf$1<T>>;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the extension registered by a named exchange.
|
|
106
|
+
* @param name - The exchange name.
|
|
107
|
+
* @returns The extension object provided by the exchange.
|
|
108
|
+
*/
|
|
109
|
+
extension<TName extends keyof ExchangeExtensionMap>(name: TName): ExchangeExtensionMap[TName];
|
|
110
|
+
extension(name: string): unknown;
|
|
111
|
+
maybeExtension<TName extends keyof ExchangeExtensionMap>(name: TName): ExchangeExtensionMap[TName] | undefined;
|
|
112
|
+
maybeExtension(name: string): unknown;
|
|
113
|
+
dispose(): void;
|
|
114
|
+
}
|
|
115
|
+
declare const createClient: <T extends SchemaMeta$1>(config: ClientOptions<T>) => Client<T>;
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/exchange.d.ts
|
|
118
|
+
interface OperationMetadataMap {}
|
|
119
|
+
type OperationMetadata = { [K in keyof OperationMetadataMap]?: OperationMetadataMap[K] } & Record<string, unknown>;
|
|
120
|
+
type BaseOperation = {
|
|
121
|
+
key: string;
|
|
122
|
+
metadata: OperationMetadataMap & Record<string, unknown>;
|
|
123
|
+
};
|
|
124
|
+
type RequestOperation<K extends ArtifactKind$1 = ArtifactKind$1> = BaseOperation & {
|
|
125
|
+
variant: 'request';
|
|
126
|
+
artifact: Artifact$1<K>;
|
|
127
|
+
variables: VariablesOf$1<Artifact$1<K>>;
|
|
128
|
+
};
|
|
129
|
+
type TeardownOperation = BaseOperation & {
|
|
130
|
+
variant: 'teardown';
|
|
131
|
+
};
|
|
132
|
+
type Operation<K extends ArtifactKind$1 = ArtifactKind$1> = RequestOperation<K> | TeardownOperation;
|
|
133
|
+
type OperationResult = {
|
|
134
|
+
operation: Operation;
|
|
135
|
+
data?: unknown;
|
|
136
|
+
errors?: readonly OperationError[];
|
|
137
|
+
extensions?: Record<string, unknown>;
|
|
138
|
+
stale?: boolean;
|
|
139
|
+
};
|
|
140
|
+
type ExchangeInput<TMeta extends SchemaMeta$1 = SchemaMeta$1> = {
|
|
141
|
+
forward: ExchangeIO;
|
|
142
|
+
client: Client<TMeta>;
|
|
143
|
+
};
|
|
144
|
+
type ExchangeIO = (operations: Source<Operation>) => Source<OperationResult>;
|
|
145
|
+
interface ExchangeExtensionMap {}
|
|
146
|
+
type ExchangeResult<TName extends keyof ExchangeExtensionMap | (string & {}) = string> = {
|
|
147
|
+
name: TName;
|
|
148
|
+
io: ExchangeIO;
|
|
149
|
+
} & (TName extends keyof ExchangeExtensionMap ? {
|
|
150
|
+
extension: ExchangeExtensionMap[TName];
|
|
151
|
+
} : {});
|
|
152
|
+
type Exchange<TName extends keyof ExchangeExtensionMap | (string & {}) = string> = <TMeta extends SchemaMeta$1 = SchemaMeta$1>(input: ExchangeInput<TMeta>) => ExchangeResult<TName>;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/exchanges/http.d.ts
|
|
155
|
+
declare module '@mearie/core' {
|
|
156
|
+
interface ExchangeErrorExtensionsMap {
|
|
157
|
+
http?: {
|
|
158
|
+
statusCode?: number;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
type HttpOptions = {
|
|
163
|
+
url: string;
|
|
164
|
+
headers?: HeadersInit;
|
|
165
|
+
mode?: RequestMode;
|
|
166
|
+
credentials?: RequestCredentials;
|
|
167
|
+
fetch?: typeof globalThis.fetch;
|
|
168
|
+
};
|
|
169
|
+
declare const httpExchange: (options: HttpOptions) => Exchange;
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/exchanges/dedup.d.ts
|
|
172
|
+
declare module '@mearie/core' {
|
|
173
|
+
interface OperationMetadataMap {
|
|
174
|
+
dedup?: {
|
|
175
|
+
skip?: boolean;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Prevents duplicate in-flight operations by deduplicating requests with identical artifact names and variables.
|
|
181
|
+
*
|
|
182
|
+
* Operations are considered identical if they have the same artifact name and serialized variables.
|
|
183
|
+
* Mutations are never deduplicated. An operation is "in-flight" from when it's first seen until all subscribers tear down.
|
|
184
|
+
*
|
|
185
|
+
* Caveats:
|
|
186
|
+
*
|
|
187
|
+
* 1. Upstream metadata is lost when operations are deduplicated. The result will contain the metadata
|
|
188
|
+
* from the operation that actually went through the pipeline, not from deduplicated operations.
|
|
189
|
+
* This preserves downstream metadata (retry attempts, cache status) but means custom upstream metadata
|
|
190
|
+
* from deduplicated operations will not appear in results.
|
|
191
|
+
* @internal
|
|
192
|
+
* @returns An exchange that deduplicates in-flight operations.
|
|
193
|
+
*/
|
|
194
|
+
declare const dedupExchange: () => Exchange;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/cache/types.d.ts
|
|
197
|
+
/**
|
|
198
|
+
* Identifier for a single entity, supporting simple or composite keys.
|
|
199
|
+
*/
|
|
200
|
+
type EntityId = string | number | Record<string, string | number>;
|
|
201
|
+
/**
|
|
202
|
+
* Target specification for cache invalidation operations.
|
|
203
|
+
*/
|
|
204
|
+
type InvalidateTarget = {
|
|
205
|
+
__typename: string;
|
|
206
|
+
id: EntityId;
|
|
207
|
+
} | {
|
|
208
|
+
__typename: string;
|
|
209
|
+
id: EntityId;
|
|
210
|
+
field: string;
|
|
211
|
+
args?: Record<string, unknown>;
|
|
212
|
+
} | {
|
|
213
|
+
__typename: 'Query';
|
|
214
|
+
} | {
|
|
215
|
+
__typename: 'Query';
|
|
216
|
+
field: string;
|
|
217
|
+
args?: Record<string, unknown>;
|
|
218
|
+
} | {
|
|
219
|
+
__typename: string;
|
|
220
|
+
} | {
|
|
221
|
+
__typename: string;
|
|
222
|
+
field: string;
|
|
223
|
+
args?: Record<string, unknown>;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Opaque type representing a serializable cache snapshot.
|
|
227
|
+
*/
|
|
228
|
+
type CacheSnapshot = {
|
|
229
|
+
readonly __brand: unique symbol;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Operations available for programmatic cache manipulation.
|
|
233
|
+
*/
|
|
234
|
+
type CacheOperations = {
|
|
235
|
+
extract(): CacheSnapshot;
|
|
236
|
+
hydrate(data: CacheSnapshot): void;
|
|
237
|
+
invalidate(...targets: InvalidateTarget[]): void;
|
|
238
|
+
clear(): void;
|
|
239
|
+
};
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/exchanges/cache.d.ts
|
|
242
|
+
declare module '@mearie/core' {
|
|
243
|
+
interface ExchangeExtensionMap {
|
|
244
|
+
cache: CacheOperations;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
type CacheOptions = {
|
|
248
|
+
fetchPolicy?: 'cache-first' | 'cache-and-network' | 'network-only' | 'cache-only';
|
|
249
|
+
};
|
|
250
|
+
declare const cacheExchange: (options?: CacheOptions) => Exchange<"cache">;
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/exchanges/retry.d.ts
|
|
253
|
+
declare module '@mearie/core' {
|
|
254
|
+
interface OperationMetadataMap {
|
|
255
|
+
retry?: {
|
|
256
|
+
attempt: number;
|
|
257
|
+
delay: number;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
type RetryOptions = {
|
|
262
|
+
maxAttempts?: number;
|
|
263
|
+
backoff?: (attempt: number) => number;
|
|
264
|
+
shouldRetry?: (error: OperationError) => boolean;
|
|
265
|
+
};
|
|
266
|
+
declare const retryExchange: (options?: RetryOptions) => Exchange;
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/exchanges/fragment.d.ts
|
|
269
|
+
declare module '@mearie/core' {
|
|
270
|
+
interface OperationMetadataMap {
|
|
271
|
+
fragmentRef?: unknown;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
declare const fragmentExchange: () => Exchange;
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/exchanges/required.d.ts
|
|
277
|
+
declare const requiredExchange: () => Exchange;
|
|
278
|
+
//#endregion
|
|
279
|
+
//#region src/exchanges/subscription.d.ts
|
|
280
|
+
interface SubscriptionClient {
|
|
281
|
+
subscribe(payload: {
|
|
282
|
+
operationName?: string;
|
|
283
|
+
query: string;
|
|
284
|
+
variables?: Record<string, unknown>;
|
|
285
|
+
}, sink: {
|
|
286
|
+
next: (result: unknown) => void;
|
|
287
|
+
error: (error: unknown) => void;
|
|
288
|
+
complete: () => void;
|
|
289
|
+
}): () => void;
|
|
290
|
+
}
|
|
291
|
+
type SubscriptionExchangeOptions = {
|
|
292
|
+
client: SubscriptionClient;
|
|
293
|
+
};
|
|
294
|
+
declare module '@mearie/core' {
|
|
295
|
+
interface OperationMetadataMap {
|
|
296
|
+
subscription?: {
|
|
297
|
+
transport?: boolean;
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Creates an exchange for handling GraphQL subscriptions using a subscription client.
|
|
303
|
+
*
|
|
304
|
+
* This exchange accepts subscription clients from graphql-ws, graphql-sse, or any client
|
|
305
|
+
* implementing the Observer pattern.
|
|
306
|
+
* @internal
|
|
307
|
+
* @param options - Configuration options for the subscription exchange.
|
|
308
|
+
* @returns An exchange that handles subscription operations.
|
|
309
|
+
* @example
|
|
310
|
+
* // With graphql-ws
|
|
311
|
+
* import { createClient } from 'graphql-ws';
|
|
312
|
+
*
|
|
313
|
+
* const wsClient = createClient({
|
|
314
|
+
* url: 'ws://localhost:4000/graphql',
|
|
315
|
+
* });
|
|
316
|
+
*
|
|
317
|
+
* subscriptionExchange({ client: wsClient })
|
|
318
|
+
* @example
|
|
319
|
+
* // With graphql-sse
|
|
320
|
+
* import { createClient } from 'graphql-sse';
|
|
321
|
+
*
|
|
322
|
+
* const sseClient = createClient({
|
|
323
|
+
* url: 'http://localhost:4000/graphql/stream',
|
|
324
|
+
* });
|
|
325
|
+
*
|
|
326
|
+
* subscriptionExchange({ client: sseClient })
|
|
327
|
+
*/
|
|
328
|
+
declare const subscriptionExchange: (options: SubscriptionExchangeOptions) => Exchange;
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/required.d.ts
|
|
331
|
+
type RequiredAction = 'THROW' | 'CASCADE';
|
|
332
|
+
declare class RequiredFieldError extends Error {
|
|
333
|
+
fieldPath: string[];
|
|
334
|
+
fieldName: string;
|
|
335
|
+
constructor(fieldPath: string[], fieldName: string);
|
|
336
|
+
}
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/utils.d.ts
|
|
339
|
+
/**
|
|
340
|
+
* Stable JSON serialization with sorted keys.
|
|
341
|
+
* Used for both variables and field arguments.
|
|
342
|
+
* @internal
|
|
343
|
+
* @param value - The value to stringify.
|
|
344
|
+
* @returns The stable JSON string.
|
|
345
|
+
*/
|
|
346
|
+
declare const stringify: (value: unknown) => string;
|
|
347
|
+
//#endregion
|
|
348
|
+
export { AggregatedError, type Artifact, type ArtifactKind, type CacheOptions, type CacheSnapshot, Client, type ClientOptions, type DataOf, type Exchange, ExchangeError, type ExchangeErrorExtensionsMap, type ExchangeExtensionMap, type ExchangeIO, type ExchangeResult, type FragmentOptions, type FragmentRefs, GraphQLError, type HttpOptions, type MutationOptions, type Operation, type OperationError, type OperationMetadata, type OperationMetadataMap, type OperationResult, type QueryOptions, type RequiredAction, RequiredFieldError, type RetryOptions, type SchemaMeta, type SubscriptionClient, type SubscriptionExchangeOptions, type SubscriptionOptions, type VariablesOf, cacheExchange, createClient, dedupExchange, fragmentExchange, httpExchange, isAggregatedError, isExchangeError, isGraphQLError, requiredExchange, retryExchange, stringify, subscriptionExchange };
|