@settlemint/sdk-thegraph 2.5.3 → 2.5.4-pr0ee48561

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/README.md CHANGED
@@ -52,7 +52,7 @@ The SDK offers a type-safe interface for all TheGraph operations, with comprehen
52
52
 
53
53
  > **createTheGraphClient**\<`Setup`\>(`options`, `clientOptions?`): `object`
54
54
 
55
- Defined in: [sdk/thegraph/src/thegraph.ts:91](https://github.com/settlemint/sdk/blob/v2.5.3/sdk/thegraph/src/thegraph.ts#L91)
55
+ Defined in: [sdk/thegraph/src/thegraph.ts:92](https://github.com/settlemint/sdk/blob/v2.5.4/sdk/thegraph/src/thegraph.ts#L92)
56
56
 
57
57
  Creates a TheGraph GraphQL client with proper type safety using gql.tada
58
58
 
@@ -83,8 +83,8 @@ An object containing:
83
83
 
84
84
  | Name | Type | Defined in |
85
85
  | ------ | ------ | ------ |
86
- | `client` | `GraphQLClient` | [sdk/thegraph/src/thegraph.ts:95](https://github.com/settlemint/sdk/blob/v2.5.3/sdk/thegraph/src/thegraph.ts#L95) |
87
- | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/thegraph/src/thegraph.ts:96](https://github.com/settlemint/sdk/blob/v2.5.3/sdk/thegraph/src/thegraph.ts#L96) |
86
+ | `client` | `GraphQLClient` | [sdk/thegraph/src/thegraph.ts:96](https://github.com/settlemint/sdk/blob/v2.5.4/sdk/thegraph/src/thegraph.ts#L96) |
87
+ | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/thegraph/src/thegraph.ts:97](https://github.com/settlemint/sdk/blob/v2.5.4/sdk/thegraph/src/thegraph.ts#L97) |
88
88
 
89
89
  ##### Throws
90
90
 
@@ -120,7 +120,7 @@ const { client, graphql } = createTheGraphClient<{
120
120
  // Making GraphQL queries
121
121
  const query = graphql(`
122
122
  query SearchAssets {
123
- assets {
123
+ assets @fetchAll {
124
124
  id
125
125
  name
126
126
  symbol
@@ -137,7 +137,7 @@ const result = await client.request(query);
137
137
 
138
138
  > **ClientOptions** = `object`
139
139
 
140
- Defined in: [sdk/thegraph/src/thegraph.ts:26](https://github.com/settlemint/sdk/blob/v2.5.3/sdk/thegraph/src/thegraph.ts#L26)
140
+ Defined in: [sdk/thegraph/src/thegraph.ts:27](https://github.com/settlemint/sdk/blob/v2.5.4/sdk/thegraph/src/thegraph.ts#L27)
141
141
 
142
142
  Type definition for client options derived from the ClientOptionsSchema
143
143
 
@@ -145,10 +145,10 @@ Type definition for client options derived from the ClientOptionsSchema
145
145
 
146
146
  | Name | Type | Defined in |
147
147
  | ------ | ------ | ------ |
148
- | <a id="accesstoken"></a> `accessToken?` | `string` | [sdk/thegraph/src/thegraph.ts:18](https://github.com/settlemint/sdk/blob/v2.5.3/sdk/thegraph/src/thegraph.ts#L18) |
149
- | <a id="cache"></a> `cache?` | `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"` | [sdk/thegraph/src/thegraph.ts:20](https://github.com/settlemint/sdk/blob/v2.5.3/sdk/thegraph/src/thegraph.ts#L20) |
150
- | <a id="instances"></a> `instances` | `string`[] | [sdk/thegraph/src/thegraph.ts:17](https://github.com/settlemint/sdk/blob/v2.5.3/sdk/thegraph/src/thegraph.ts#L17) |
151
- | <a id="subgraphname"></a> `subgraphName` | `string` | [sdk/thegraph/src/thegraph.ts:19](https://github.com/settlemint/sdk/blob/v2.5.3/sdk/thegraph/src/thegraph.ts#L19) |
148
+ | <a id="accesstoken"></a> `accessToken?` | `string` | [sdk/thegraph/src/thegraph.ts:19](https://github.com/settlemint/sdk/blob/v2.5.4/sdk/thegraph/src/thegraph.ts#L19) |
149
+ | <a id="cache"></a> `cache?` | `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"` | [sdk/thegraph/src/thegraph.ts:21](https://github.com/settlemint/sdk/blob/v2.5.4/sdk/thegraph/src/thegraph.ts#L21) |
150
+ | <a id="instances"></a> `instances` | `string`[] | [sdk/thegraph/src/thegraph.ts:18](https://github.com/settlemint/sdk/blob/v2.5.4/sdk/thegraph/src/thegraph.ts#L18) |
151
+ | <a id="subgraphname"></a> `subgraphName` | `string` | [sdk/thegraph/src/thegraph.ts:20](https://github.com/settlemint/sdk/blob/v2.5.4/sdk/thegraph/src/thegraph.ts#L20) |
152
152
 
153
153
  ***
154
154
 
@@ -156,7 +156,7 @@ Type definition for client options derived from the ClientOptionsSchema
156
156
 
157
157
  > **RequestConfig** = `ConstructorParameters`\<*typeof* `GraphQLClient`\>\[`1`\]
158
158
 
159
- Defined in: [sdk/thegraph/src/thegraph.ts:11](https://github.com/settlemint/sdk/blob/v2.5.3/sdk/thegraph/src/thegraph.ts#L11)
159
+ Defined in: [sdk/thegraph/src/thegraph.ts:12](https://github.com/settlemint/sdk/blob/v2.5.4/sdk/thegraph/src/thegraph.ts#L12)
160
160
 
161
161
  Type definition for GraphQL client configuration options
162
162
 
@@ -166,7 +166,7 @@ Type definition for GraphQL client configuration options
166
166
 
167
167
  > `const` **ClientOptionsSchema**: `ZodObject`\<[`ClientOptions`](#clientoptions)\>
168
168
 
169
- Defined in: [sdk/thegraph/src/thegraph.ts:16](https://github.com/settlemint/sdk/blob/v2.5.3/sdk/thegraph/src/thegraph.ts#L16)
169
+ Defined in: [sdk/thegraph/src/thegraph.ts:17](https://github.com/settlemint/sdk/blob/v2.5.4/sdk/thegraph/src/thegraph.ts#L17)
170
170
 
171
171
  Schema for validating client options for the TheGraph client.
172
172
 
@@ -1,8 +1,21 @@
1
1
  /* SettleMint The Graph SDK - Indexing Protocol */
2
- import { AbstractSetupSchema, FragmentOf, ResultOf, VariablesOf, initGraphQLTada, readFragment } from "gql.tada";
3
- import { GraphQLClient } from "graphql-request";
2
+ import { AbstractSetupSchema, FragmentOf, ResultOf, TadaDocumentNode, VariablesOf, initGraphQLTada, readFragment } from "gql.tada";
3
+ import { GraphQLClient, RequestDocument, RequestOptions, Variables } from "graphql-request";
4
4
  import { z } from "zod";
5
5
 
6
+ //#region src/utils/pagination.d.ts
7
+
8
+ /**
9
+ * Creates a TheGraph client that supports pagination for list fields
10
+ *
11
+ * @param theGraphClient - The GraphQL client to use for requests
12
+ * @returns A TheGraph client that supports pagination for list fields
13
+ * @internal Used internally by createTheGraphClient
14
+ */
15
+ declare function createTheGraphClientWithPagination(theGraphClient: Pick<GraphQLClient, "request">): {
16
+ readonly query: <TResult, TVariables extends Variables>(documentOrOptions: TadaDocumentNode<TResult, TVariables> | RequestDocument | RequestOptions<TVariables, TResult>, variablesRaw?: Omit<TVariables, "skip" | "first">) => Promise<TResult>;
17
+ };
18
+ //#endregion
6
19
  //#region src/thegraph.d.ts
7
20
  /**
8
21
  * Type definition for GraphQL client configuration options
@@ -66,7 +79,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
66
79
  * // Making GraphQL queries
67
80
  * const query = graphql(`
68
81
  * query SearchAssets {
69
- * assets {
82
+ * assets @fetchAll {
70
83
  * id
71
84
  * name
72
85
  * symbol
@@ -81,5 +94,5 @@ declare function createTheGraphClient<const Setup extends AbstractSetupSchema>(o
81
94
  graphql: initGraphQLTada<Setup>;
82
95
  };
83
96
  //#endregion
84
- export { ClientOptions, ClientOptionsSchema, type FragmentOf, RequestConfig, type ResultOf, type VariablesOf, createTheGraphClient, readFragment };
97
+ export { ClientOptions, ClientOptionsSchema, type FragmentOf, RequestConfig, type ResultOf, type VariablesOf, createTheGraphClient, createTheGraphClientWithPagination, readFragment };
85
98
  //# sourceMappingURL=thegraph.d.ts.map
@@ -5,7 +5,311 @@ import { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from "@settle
5
5
  import { initGraphQLTada, readFragment } from "gql.tada";
6
6
  import { GraphQLClient } from "graphql-request";
7
7
  import { z } from "zod";
8
+ import { sortBy } from "es-toolkit";
9
+ import { get, isArray, isEmpty, set } from "es-toolkit/compat";
10
+ import { Kind, parse, visit } from "graphql";
8
11
 
12
+ //#region src/utils/pagination.ts
13
+ const THE_GRAPH_LIMIT = 500;
14
+ const FIRST_ARG = "first";
15
+ const SKIP_ARG = "skip";
16
+ const FETCH_ALL_DIRECTIVE = "fetchAll";
17
+ /**
18
+ * Detects and strips @fetchAll directives from a GraphQL document
19
+ *
20
+ * @param {DocumentNode} document - The GraphQL document to process
21
+ * @returns {Object} Processed document and list of fields with @fetchAll
22
+ *
23
+ * @remarks
24
+ * This function:
25
+ * - Identifies fields decorated with @fetchAll directive
26
+ * - Removes the directive from the AST (The Graph doesn't recognize it)
27
+ * - Returns both the cleaned document and a list of fields to auto-paginate
28
+ */
29
+ function stripFetchAllDirective(document) {
30
+ const fetchAllFields = new Set();
31
+ const documentNode = typeof document === "string" ? parse(document) : document;
32
+ const strippedDocument = visit(documentNode, { Field(node) {
33
+ if (node.directives && node.directives.length > 0) {
34
+ const hasFetchAll = node.directives.some((dir) => dir.name.value === FETCH_ALL_DIRECTIVE);
35
+ if (hasFetchAll) {
36
+ const fieldIdentifier = node.alias?.value || node.name.value;
37
+ fetchAllFields.add(fieldIdentifier);
38
+ return {
39
+ ...node,
40
+ directives: node.directives.filter((dir) => dir.name.value !== FETCH_ALL_DIRECTIVE)
41
+ };
42
+ }
43
+ }
44
+ return node;
45
+ } });
46
+ return {
47
+ document: strippedDocument,
48
+ fetchAllFields
49
+ };
50
+ }
51
+ /**
52
+ * Custom merge function for deep object merging with special handling for lists
53
+ *
54
+ * @param {unknown} target - The target object or value to merge into
55
+ * @param {unknown} source - The source object or value to merge from
56
+ * @returns {unknown} Merged result with preservation of arrays and specific merge logic
57
+ *
58
+ * @remarks
59
+ * Key behaviors:
60
+ * - Preserves existing arrays without merging
61
+ * - Handles null and undefined values
62
+ * - Performs deep merge for nested objects
63
+ * - Prioritizes source values for primitives
64
+ *
65
+ */
66
+ function customMerge(target, source) {
67
+ if (source == null) return target;
68
+ if (target == null) return source;
69
+ if (isArray(source)) {
70
+ return source;
71
+ }
72
+ if (typeof target !== "object" || typeof source !== "object") {
73
+ return source;
74
+ }
75
+ const targetObj = target;
76
+ const sourceObj = source;
77
+ const result = { ...targetObj };
78
+ for (const key in sourceObj) {
79
+ if (Object.hasOwn(sourceObj, key)) {
80
+ result[key] = key in result ? customMerge(result[key], sourceObj[key]) : sourceObj[key];
81
+ }
82
+ }
83
+ return result;
84
+ }
85
+ function extractFetchAllFields(document, variables, fetchAllFields) {
86
+ const fields = [];
87
+ const pathStack = [];
88
+ visit(document, { Field: {
89
+ enter: (node) => {
90
+ const fieldIdentifier = node.alias?.value || node.name.value;
91
+ pathStack.push(fieldIdentifier);
92
+ if (node.name.value.startsWith("__")) {
93
+ return;
94
+ }
95
+ let firstValue;
96
+ let skipValue;
97
+ const otherArgs = [];
98
+ if (node.arguments) {
99
+ for (const arg of node.arguments) {
100
+ if (arg.name.value === FIRST_ARG) {
101
+ if (arg.value.kind === Kind.INT) {
102
+ firstValue = Number.parseInt(arg.value.value);
103
+ } else if (arg.value.kind === Kind.VARIABLE && variables) {
104
+ const varName = arg.value.name.value;
105
+ const varValue = variables[varName];
106
+ firstValue = typeof varValue === "number" ? varValue : undefined;
107
+ }
108
+ } else if (arg.name.value === SKIP_ARG) {
109
+ if (arg.value.kind === Kind.INT) {
110
+ skipValue = Number.parseInt(arg.value.value);
111
+ } else if (arg.value.kind === Kind.VARIABLE && variables) {
112
+ const varName = arg.value.name.value;
113
+ const varValue = variables[varName];
114
+ skipValue = typeof varValue === "number" ? varValue : undefined;
115
+ }
116
+ } else {
117
+ otherArgs.push(arg);
118
+ }
119
+ }
120
+ }
121
+ const fieldIdentifierForDirective = node.alias?.value || node.name.value;
122
+ const hasFetchAllDirective = fetchAllFields?.has(fieldIdentifierForDirective);
123
+ if (hasFetchAllDirective) {
124
+ const parentFetchAllField = fields.find((field) => pathStack.join(",").startsWith(field.path.join(",")));
125
+ if (parentFetchAllField) {
126
+ throw new Error(`Nesting of @fetchAll directive is not supported: ${pathStack.join(".")} is a child of ${parentFetchAllField.path.join(".")}`);
127
+ }
128
+ fields.push({
129
+ path: [...pathStack],
130
+ fieldName: node.name.value,
131
+ alias: node.alias?.value,
132
+ firstValue: hasFetchAllDirective && (firstValue ?? THE_GRAPH_LIMIT),
133
+ skipValue: hasFetchAllDirective && (skipValue ?? 0),
134
+ otherArgs,
135
+ selections: node.selectionSet?.selections,
136
+ hasFetchAllDirective,
137
+ firstValueIsDefault: hasFetchAllDirective ? firstValue === undefined : false
138
+ });
139
+ }
140
+ },
141
+ leave: () => {
142
+ pathStack.pop();
143
+ }
144
+ } });
145
+ return fields;
146
+ }
147
+ function createSingleFieldQuery(document, targetField, skip, first) {
148
+ const targetPath = [...targetField.path];
149
+ const pathStack = [];
150
+ return visit(document, { Field: {
151
+ enter: (node) => {
152
+ const fieldIdentifier = node.alias?.value || node.name.value;
153
+ pathStack.push(fieldIdentifier);
154
+ const onPath = pathStack.every((segment, i) => i >= targetPath.length || segment === targetPath[i]);
155
+ if (!onPath) {
156
+ pathStack.pop();
157
+ return null;
158
+ }
159
+ const isTarget = pathStack.length === targetPath.length && pathStack.every((segment, i) => segment === targetPath[i]);
160
+ if (isTarget) {
161
+ const newArgs = [...targetField.otherArgs];
162
+ newArgs.push({
163
+ kind: Kind.ARGUMENT,
164
+ name: {
165
+ kind: Kind.NAME,
166
+ value: FIRST_ARG
167
+ },
168
+ value: {
169
+ kind: Kind.INT,
170
+ value: first.toString()
171
+ }
172
+ }, {
173
+ kind: Kind.ARGUMENT,
174
+ name: {
175
+ kind: Kind.NAME,
176
+ value: SKIP_ARG
177
+ },
178
+ value: {
179
+ kind: Kind.INT,
180
+ value: skip.toString()
181
+ }
182
+ });
183
+ return {
184
+ ...node,
185
+ arguments: newArgs
186
+ };
187
+ }
188
+ return undefined;
189
+ },
190
+ leave: () => {
191
+ pathStack.pop();
192
+ }
193
+ } });
194
+ }
195
+ function createNonListQuery(document, listFields) {
196
+ let hasFields = false;
197
+ const pathStack = [];
198
+ const filtered = visit(document, { Field: {
199
+ enter: (node) => {
200
+ const fieldIdentifier = node.alias?.value || node.name.value;
201
+ pathStack.push(fieldIdentifier);
202
+ const isList = listFields.some((field) => field.path.length === pathStack.length && field.path.every((segment, i) => segment === pathStack[i]));
203
+ if (isList) {
204
+ pathStack.pop();
205
+ return null;
206
+ }
207
+ hasFields = true;
208
+ return undefined;
209
+ },
210
+ leave: () => {
211
+ pathStack.pop();
212
+ }
213
+ } });
214
+ return hasFields ? filtered : null;
215
+ }
216
+ function filterVariables(variables, document) {
217
+ if (!variables) return undefined;
218
+ const usedVariables = new Set();
219
+ visit(document, { Variable: (node) => {
220
+ usedVariables.add(node.name.value);
221
+ } });
222
+ const filtered = {};
223
+ const varsObj = variables;
224
+ for (const key of usedVariables) {
225
+ if (key in varsObj) {
226
+ filtered[key] = varsObj[key];
227
+ }
228
+ }
229
+ return isEmpty(filtered) ? undefined : filtered;
230
+ }
231
+ /**
232
+ * Creates a TheGraph client that supports pagination for list fields
233
+ *
234
+ * @param theGraphClient - The GraphQL client to use for requests
235
+ * @returns A TheGraph client that supports pagination for list fields
236
+ * @internal Used internally by createTheGraphClient
237
+ */
238
+ function createTheGraphClientWithPagination(theGraphClient) {
239
+ async function executeListFieldPagination(document, variables, field) {
240
+ const results = [];
241
+ let currentSkip = field.skipValue || 0;
242
+ let hasMore = true;
243
+ const batchSize = Math.min(field.firstValue || THE_GRAPH_LIMIT, THE_GRAPH_LIMIT);
244
+ while (hasMore) {
245
+ const query = createSingleFieldQuery(document, field, currentSkip, batchSize);
246
+ const existingVariables = filterVariables(variables, query) ?? {};
247
+ const response = await theGraphClient.request(query, {
248
+ ...existingVariables,
249
+ first: batchSize,
250
+ skip: currentSkip
251
+ });
252
+ const data = get(response, field.path) ?? get(response, field.fieldName);
253
+ const parentPath = field.path.slice(0, -1);
254
+ const parentData = get(response, parentPath);
255
+ if (isArray(parentData) && parentData.length > 0) {
256
+ throw new Error(`Response is an array, but expected a single object for field ${parentPath.join(".")}. The @fetchAll directive is not supported inside a query that returns a list of items.`);
257
+ }
258
+ if (isArray(data) && data.length > 0) {
259
+ results.push(...data);
260
+ if (field.hasFetchAllDirective) {
261
+ hasMore = data.length === batchSize;
262
+ } else if (field.firstValue && !field.firstValueIsDefault) {
263
+ hasMore = data.length === batchSize && results.length < field.firstValue;
264
+ } else {
265
+ hasMore = data.length === batchSize;
266
+ }
267
+ } else {
268
+ hasMore = false;
269
+ }
270
+ currentSkip += batchSize;
271
+ }
272
+ return results;
273
+ }
274
+ return { async query(documentOrOptions, variablesRaw) {
275
+ let document;
276
+ let variables;
277
+ if (isRequestOptions(documentOrOptions)) {
278
+ document = documentOrOptions.document;
279
+ variables = documentOrOptions.variables;
280
+ } else {
281
+ document = documentOrOptions;
282
+ variables = variablesRaw ?? {};
283
+ }
284
+ const { document: processedDocument, fetchAllFields } = stripFetchAllDirective(document);
285
+ const listFields = extractFetchAllFields(processedDocument, variables, fetchAllFields);
286
+ if (listFields.length === 0) {
287
+ return theGraphClient.request(processedDocument, variables);
288
+ }
289
+ const result = {};
290
+ const sortedFields = sortBy(listFields, [(field) => field.path.length]);
291
+ const fieldDataPromises = sortedFields.map(async (field) => ({
292
+ field,
293
+ data: await executeListFieldPagination(processedDocument, variables, field)
294
+ }));
295
+ const fieldResults = await Promise.all(fieldDataPromises);
296
+ for (const { field, data } of fieldResults) {
297
+ set(result, field.path, data);
298
+ }
299
+ const nonListQuery = createNonListQuery(processedDocument, listFields);
300
+ if (nonListQuery) {
301
+ const nonListResult = await theGraphClient.request(nonListQuery, filterVariables(variables, nonListQuery) ?? {});
302
+ const merged = customMerge(nonListResult, result);
303
+ return merged;
304
+ }
305
+ return result;
306
+ } };
307
+ }
308
+ function isRequestOptions(args) {
309
+ return typeof args === "object" && args !== null && "document" in args && "variables" in args;
310
+ }
311
+
312
+ //#endregion
9
313
  //#region src/thegraph.ts
10
314
  /**
11
315
  * Schema for validating client options for the TheGraph client.
@@ -75,7 +379,7 @@ function getFullUrl(options) {
75
379
  * // Making GraphQL queries
76
380
  * const query = graphql(`
77
381
  * query SearchAssets {
78
- * assets {
382
+ * assets @fetchAll {
79
383
  * id
80
384
  * name
81
385
  * symbol
@@ -90,15 +394,19 @@ function createTheGraphClient(options, clientOptions) {
90
394
  const validatedOptions = validate(ClientOptionsSchema, options);
91
395
  const graphql = initGraphQLTada();
92
396
  const fullUrl = getFullUrl(validatedOptions);
397
+ const client = new GraphQLClient(fullUrl, {
398
+ ...clientOptions,
399
+ headers: appendHeaders(clientOptions?.headers, { "x-auth-token": validatedOptions.accessToken })
400
+ });
401
+ const originalRequest = client.request.bind(client);
402
+ const paginatedClient = createTheGraphClientWithPagination({ request: originalRequest });
403
+ client.request = paginatedClient.query;
93
404
  return {
94
- client: new GraphQLClient(fullUrl, {
95
- ...clientOptions,
96
- headers: appendHeaders(clientOptions?.headers, { "x-auth-token": validatedOptions.accessToken })
97
- }),
405
+ client,
98
406
  graphql
99
407
  };
100
408
  }
101
409
 
102
410
  //#endregion
103
- export { ClientOptionsSchema, createTheGraphClient, readFragment };
411
+ export { ClientOptionsSchema, createTheGraphClient, createTheGraphClientWithPagination, readFragment };
104
412
  //# sourceMappingURL=thegraph.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"thegraph.js","names":["options: ClientOptions","instance","clientOptions?: RequestConfig"],"sources":["../../src/thegraph.ts"],"sourcesContent":["import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport { type AbstractSetupSchema, initGraphQLTada } from \"gql.tada\";\nimport { GraphQLClient } from \"graphql-request\";\nimport { z } from \"zod\";\n\n/**\n * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the TheGraph client.\n */\nexport const ClientOptionsSchema = z.object({\n instances: z.array(UrlOrPathSchema),\n accessToken: ApplicationAccessTokenSchema.optional(),\n subgraphName: z.string(),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the full URL for TheGraph GraphQL API based on the provided options\n *\n * @param options - The client options for configuring TheGraph client\n * @returns The complete GraphQL API URL as a string\n * @throws Will throw an error if no matching instance is found for the specified subgraph\n */\nfunction getFullUrl(options: ClientOptions): string {\n const instance = options.instances.find((instance) => instance.endsWith(`/${options.subgraphName}`));\n if (!instance) {\n throw new Error(`Instance for subgraph ${options.subgraphName} not found`);\n }\n return new URL(instance).toString();\n}\n\n/**\n * Creates a TheGraph GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client including instance URLs,\n * access token and subgraph name\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing:\n * - client: The configured GraphQL client instance\n * - graphql: The initialized gql.tada function for type-safe queries\n * @throws Will throw an error if the options fail validation against ClientOptionsSchema\n * @example\n * import { createTheGraphClient } from '@settlemint/sdk-thegraph';\n * import type { introspection } from '@schemas/the-graph-env-kits';\n * import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';\n *\n * const logger = createLogger();\n *\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: string;\n * };\n * }>({\n * instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * subgraphName: 'kits'\n * }, {\n * fetch: requestLogger(logger, \"the-graph-kits\", fetch) as typeof fetch,\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query SearchAssets {\n * assets {\n * id\n * name\n * symbol\n * }\n * }\n * `);\n *\n * const result = await client.request(query);\n */\nexport function createTheGraphClient<const Setup extends AbstractSetupSchema>(\n options: ClientOptions,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n ensureServer();\n const validatedOptions = validate(ClientOptionsSchema, options);\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n headers: appendHeaders(clientOptions?.headers, { \"x-auth-token\": validatedOptions.accessToken }),\n }),\n graphql,\n };\n}\n\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\nexport { readFragment } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,sBAAsB,EAAE,OAAO;CAC1C,WAAW,EAAE,MAAM,gBAAgB;CACnC,aAAa,6BAA6B,UAAU;CACpD,cAAc,EAAE,QAAQ;CACxB,OAAO,EAAE,KAAK;EAAC;EAAW;EAAe;EAAY;EAAY;EAAkB;CAAS,EAAC,CAAC,UAAU;AACzG,EAAC;;;;;;;;AAcF,SAAS,WAAWA,SAAgC;CAClD,MAAM,WAAW,QAAQ,UAAU,KAAK,CAACC,eAAa,WAAS,UAAU,GAAG,QAAQ,aAAa,EAAE,CAAC;AACpG,MAAK,UAAU;AACb,QAAM,IAAI,OAAO,wBAAwB,QAAQ,aAAa;CAC/D;AACD,QAAO,IAAI,IAAI,UAAU,UAAU;AACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDD,SAAgB,qBACdD,SACAE,eAIA;AACA,eAAc;CACd,MAAM,mBAAmB,SAAS,qBAAqB,QAAQ;CAC/D,MAAM,UAAU,iBAAwB;CACxC,MAAM,UAAU,WAAW,iBAAiB;AAE5C,QAAO;EACL,QAAQ,IAAI,cAAc,SAAS;GACjC,GAAG;GACH,SAAS,cAAc,eAAe,SAAS,EAAE,gBAAgB,iBAAiB,YAAa,EAAC;EACjG;EACD;CACD;AACF"}
1
+ {"version":3,"file":"thegraph.js","names":["document: DocumentNode | RequestDocument","target: unknown","source: unknown","result: Record<string, unknown>","document: DocumentNode","variables?: Variables","fetchAllFields?: Set<string>","fields: ListField[]","pathStack: string[]","firstValue: number | undefined","skipValue: number | undefined","otherArgs: ArgumentNode[]","targetField: ListField","skip: number","first: number","newArgs: ArgumentNode[]","listFields: ListField[]","variables: Variables | undefined","filtered: Variables","theGraphClient: Pick<GraphQLClient, \"request\">","field: ListField","results: unknown[]","documentOrOptions: TadaDocumentNode<TResult, TVariables> | RequestDocument | RequestOptions<TVariables, TResult>","variablesRaw?: Omit<TVariables, \"skip\" | \"first\">","document: TadaDocumentNode<TResult, TVariables> | RequestDocument","variables: Omit<TVariables, \"skip\" | \"first\">","args: unknown","options: ClientOptions","instance","clientOptions?: RequestConfig"],"sources":["../../src/utils/pagination.ts","../../src/thegraph.ts"],"sourcesContent":["import { sortBy } from \"es-toolkit\";\nimport { get, isArray, isEmpty, set } from \"es-toolkit/compat\";\nimport type { TadaDocumentNode } from \"gql.tada\";\nimport { type ArgumentNode, type DocumentNode, Kind, parse, type SelectionNode, visit } from \"graphql\";\nimport type { GraphQLClient, RequestDocument, RequestOptions, Variables } from \"graphql-request\";\n\n// Constants for TheGraph limits\nconst THE_GRAPH_LIMIT = 500;\nconst FIRST_ARG = \"first\";\nconst SKIP_ARG = \"skip\";\nconst FETCH_ALL_DIRECTIVE = \"fetchAll\";\n\ninterface ListField {\n path: string[];\n fieldName: string;\n alias?: string;\n firstValue?: number;\n skipValue?: number;\n otherArgs: ArgumentNode[];\n selections?: ReadonlyArray<SelectionNode>;\n hasFetchAllDirective?: boolean;\n firstValueIsDefault?: boolean; // Track if first value was defaulted\n}\n\n/**\n * Detects and strips @fetchAll directives from a GraphQL document\n *\n * @param {DocumentNode} document - The GraphQL document to process\n * @returns {Object} Processed document and list of fields with @fetchAll\n *\n * @remarks\n * This function:\n * - Identifies fields decorated with @fetchAll directive\n * - Removes the directive from the AST (The Graph doesn't recognize it)\n * - Returns both the cleaned document and a list of fields to auto-paginate\n */\nfunction stripFetchAllDirective(document: DocumentNode | RequestDocument): {\n document: DocumentNode;\n fetchAllFields: Set<string>;\n} {\n const fetchAllFields = new Set<string>();\n const documentNode = typeof document === \"string\" ? parse(document) : document;\n const strippedDocument = visit(documentNode, {\n Field(node) {\n // Check if this field has the @fetchAll directive\n if (node.directives && node.directives.length > 0) {\n const hasFetchAll = node.directives.some((dir) => dir.name.value === FETCH_ALL_DIRECTIVE);\n\n if (hasFetchAll) {\n const fieldIdentifier = node.alias?.value || node.name.value;\n fetchAllFields.add(fieldIdentifier);\n\n // Return a new node without the @fetchAll directive\n return {\n ...node,\n directives: node.directives.filter((dir) => dir.name.value !== FETCH_ALL_DIRECTIVE),\n };\n }\n }\n\n return node;\n },\n });\n\n return {\n document: strippedDocument,\n fetchAllFields,\n };\n}\n\n/**\n * Custom merge function for deep object merging with special handling for lists\n *\n * @param {unknown} target - The target object or value to merge into\n * @param {unknown} source - The source object or value to merge from\n * @returns {unknown} Merged result with preservation of arrays and specific merge logic\n *\n * @remarks\n * Key behaviors:\n * - Preserves existing arrays without merging\n * - Handles null and undefined values\n * - Performs deep merge for nested objects\n * - Prioritizes source values for primitives\n *\n */\nfunction customMerge(target: unknown, source: unknown): unknown {\n if (source == null) return target;\n if (target == null) return source;\n\n // If source is an array, return it, don't merge arrays\n if (isArray(source)) {\n return source;\n }\n\n if (typeof target !== \"object\" || typeof source !== \"object\") {\n return source;\n }\n\n // Manually merge objects to ensure arrays are preserved\n const targetObj = target as Record<string, unknown>;\n const sourceObj = source as Record<string, unknown>;\n const result: Record<string, unknown> = { ...targetObj };\n\n for (const key in sourceObj) {\n if (Object.hasOwn(sourceObj, key)) {\n result[key] = key in result ? customMerge(result[key], sourceObj[key]) : sourceObj[key];\n }\n }\n\n return result;\n}\n\n// Extract all fields that have @fetchAll directive\nfunction extractFetchAllFields(\n document: DocumentNode,\n variables?: Variables,\n fetchAllFields?: Set<string>,\n): ListField[] {\n const fields: ListField[] = [];\n const pathStack: string[] = [];\n\n visit(document, {\n Field: {\n enter: (node) => {\n const fieldIdentifier = node.alias?.value || node.name.value;\n pathStack.push(fieldIdentifier);\n\n // Skip meta fields\n if (node.name.value.startsWith(\"__\")) {\n return;\n }\n\n // Check if this field has pagination arguments (first or skip)\n let firstValue: number | undefined;\n let skipValue: number | undefined;\n const otherArgs: ArgumentNode[] = [];\n\n if (node.arguments) {\n for (const arg of node.arguments) {\n if (arg.name.value === FIRST_ARG) {\n if (arg.value.kind === Kind.INT) {\n firstValue = Number.parseInt(arg.value.value);\n } else if (arg.value.kind === Kind.VARIABLE && variables) {\n const varName = arg.value.name.value;\n const varValue = (variables as Record<string, unknown>)[varName];\n firstValue = typeof varValue === \"number\" ? varValue : undefined;\n }\n } else if (arg.name.value === SKIP_ARG) {\n if (arg.value.kind === Kind.INT) {\n skipValue = Number.parseInt(arg.value.value);\n } else if (arg.value.kind === Kind.VARIABLE && variables) {\n const varName = arg.value.name.value;\n const varValue = (variables as Record<string, unknown>)[varName];\n skipValue = typeof varValue === \"number\" ? varValue : undefined;\n }\n } else {\n otherArgs.push(arg);\n }\n }\n }\n\n // Check if this field has @fetchAll directive\n const fieldIdentifierForDirective = node.alias?.value || node.name.value;\n const hasFetchAllDirective = fetchAllFields?.has(fieldIdentifierForDirective);\n\n if (hasFetchAllDirective) {\n // Do not allow nesting @fetchAll fields\n const parentFetchAllField = fields.find((field) => pathStack.join(\",\").startsWith(field.path.join(\",\")));\n if (parentFetchAllField) {\n throw new Error(\n `Nesting of @fetchAll directive is not supported: ${pathStack.join(\".\")} is a child of ${parentFetchAllField.path.join(\".\")}`,\n );\n }\n fields.push({\n path: [...pathStack],\n fieldName: node.name.value,\n alias: node.alias?.value,\n firstValue: hasFetchAllDirective && (firstValue ?? THE_GRAPH_LIMIT),\n skipValue: hasFetchAllDirective && (skipValue ?? 0),\n otherArgs,\n selections: node.selectionSet?.selections,\n hasFetchAllDirective,\n firstValueIsDefault: hasFetchAllDirective ? firstValue === undefined : false,\n });\n }\n },\n leave: () => {\n pathStack.pop();\n },\n },\n });\n\n return fields;\n}\n\n// Create a query for a single field with specific pagination\nfunction createSingleFieldQuery(\n document: DocumentNode,\n targetField: ListField,\n skip: number,\n first: number,\n): DocumentNode {\n const targetPath = [...targetField.path];\n const pathStack: string[] = [];\n\n return visit(document, {\n Field: {\n enter: (node) => {\n const fieldIdentifier = node.alias?.value || node.name.value;\n pathStack.push(fieldIdentifier);\n\n // Check if we're on the path to target field\n const onPath = pathStack.every((segment, i) => i >= targetPath.length || segment === targetPath[i]);\n\n if (!onPath) {\n pathStack.pop();\n return null; // Remove fields not on path\n }\n\n // If this is our target field, update pagination\n const isTarget =\n pathStack.length === targetPath.length && pathStack.every((segment, i) => segment === targetPath[i]);\n\n if (isTarget) {\n const newArgs: ArgumentNode[] = [...targetField.otherArgs];\n\n // Add pagination arguments\n newArgs.push(\n {\n kind: Kind.ARGUMENT,\n name: { kind: Kind.NAME, value: FIRST_ARG },\n value: { kind: Kind.INT, value: first.toString() },\n },\n {\n kind: Kind.ARGUMENT,\n name: { kind: Kind.NAME, value: SKIP_ARG },\n value: { kind: Kind.INT, value: skip.toString() },\n },\n );\n\n return { ...node, arguments: newArgs };\n }\n\n return undefined;\n },\n leave: () => {\n pathStack.pop();\n },\n },\n });\n}\n\n// Create query without list fields\nfunction createNonListQuery(document: DocumentNode, listFields: ListField[]): DocumentNode | null {\n let hasFields = false;\n const pathStack: string[] = [];\n\n const filtered = visit(document, {\n Field: {\n enter: (node) => {\n const fieldIdentifier = node.alias?.value || node.name.value;\n pathStack.push(fieldIdentifier);\n\n // Check if this field is a list field\n const isList = listFields.some(\n (field) =>\n field.path.length === pathStack.length && field.path.every((segment, i) => segment === pathStack[i]),\n );\n\n if (isList) {\n pathStack.pop();\n return null;\n }\n\n hasFields = true;\n return undefined;\n },\n leave: () => {\n pathStack.pop();\n },\n },\n });\n\n return hasFields ? filtered : null;\n}\n\n// Filter variables to only include used ones\nfunction filterVariables(variables: Variables | undefined, document: DocumentNode): Variables | undefined {\n if (!variables) return undefined;\n\n const usedVariables = new Set<string>();\n\n visit(document, {\n Variable: (node) => {\n usedVariables.add(node.name.value);\n },\n });\n\n const filtered: Variables = {};\n const varsObj = variables as Record<string, unknown>;\n for (const key of usedVariables) {\n if (key in varsObj) {\n (filtered as Record<string, unknown>)[key] = varsObj[key];\n }\n }\n\n return isEmpty(filtered) ? undefined : filtered;\n}\n\n/**\n * Creates a TheGraph client that supports pagination for list fields\n *\n * @param theGraphClient - The GraphQL client to use for requests\n * @returns A TheGraph client that supports pagination for list fields\n * @internal Used internally by createTheGraphClient\n */\nexport function createTheGraphClientWithPagination(theGraphClient: Pick<GraphQLClient, \"request\">) {\n // Execute pagination for a list field\n async function executeListFieldPagination(\n document: DocumentNode,\n variables: Variables | undefined,\n field: ListField,\n ): Promise<unknown[]> {\n const results: unknown[] = [];\n let currentSkip = field.skipValue || 0;\n let hasMore = true;\n\n // For fields with pagination arguments, always attempt to fetch data\n // and continue if we get a full page (indicating more data might exist)\n const batchSize = Math.min(field.firstValue || THE_GRAPH_LIMIT, THE_GRAPH_LIMIT);\n\n while (hasMore) {\n const query = createSingleFieldQuery(document, field, currentSkip, batchSize);\n const existingVariables = filterVariables(variables, query) ?? {};\n const response = await theGraphClient.request(query, {\n ...existingVariables,\n first: batchSize,\n skip: currentSkip,\n });\n\n // Use array path format for es-toolkit's get function\n const data = get(response, field.path) ?? get(response, field.fieldName);\n\n const parentPath = field.path.slice(0, -1);\n const parentData = get(response, parentPath);\n if (isArray(parentData) && parentData.length > 0) {\n throw new Error(\n `Response is an array, but expected a single object for field ${parentPath.join(\".\")}. The @fetchAll directive is not supported inside a query that returns a list of items.`,\n );\n }\n\n if (isArray(data) && data.length > 0) {\n results.push(...data);\n\n // Continue fetching if:\n // 1. We have @fetchAll directive (fetch everything)\n // 2. We have an explicit first value > THE_GRAPH_LIMIT and haven't reached it\n // 3. We have a defaulted first value and got a full batch (treating it as \"no explicit value\")\n // 4. We have no first value and got a full batch\n if (field.hasFetchAllDirective) {\n // With @fetchAll, continue if we got a full batch\n hasMore = data.length === batchSize;\n } else if (field.firstValue && !field.firstValueIsDefault) {\n // With explicit first value (not defaulted), only continue if:\n // - We haven't reached the requested amount yet\n // - We got a full batch (indicating more data might exist)\n hasMore = data.length === batchSize && results.length < field.firstValue;\n } else {\n // When first is not specified or was defaulted (using default batch size),\n // continue if we got a full batch (standard TheGraph pagination behavior)\n hasMore = data.length === batchSize;\n }\n } else {\n hasMore = false;\n }\n\n currentSkip += batchSize;\n }\n\n return results;\n }\n\n return {\n async query<TResult, TVariables extends Variables>(\n documentOrOptions: TadaDocumentNode<TResult, TVariables> | RequestDocument | RequestOptions<TVariables, TResult>,\n variablesRaw?: Omit<TVariables, \"skip\" | \"first\">,\n ): Promise<TResult> {\n let document: TadaDocumentNode<TResult, TVariables> | RequestDocument;\n let variables: Omit<TVariables, \"skip\" | \"first\">;\n\n if (isRequestOptions(documentOrOptions)) {\n document = documentOrOptions.document;\n variables = documentOrOptions.variables as TVariables;\n } else {\n document = documentOrOptions;\n variables = variablesRaw ?? ({} as TVariables);\n }\n\n // First, detect and strip @fetchAll directives\n const { document: processedDocument, fetchAllFields } = stripFetchAllDirective(document);\n\n // Extract all list fields (including those with @fetchAll)\n const listFields = extractFetchAllFields(processedDocument, variables, fetchAllFields);\n\n // If no list fields, execute normally\n if (listFields.length === 0) {\n return theGraphClient.request(processedDocument, variables as Variables);\n }\n\n // Execute paginated queries for all list fields\n const result: Record<string, unknown> = {};\n\n // Sort fields by depth to handle nested fields correctly\n const sortedFields = sortBy(listFields, [(field) => field.path.length]);\n\n // Process list fields in parallel for better performance\n const fieldDataPromises = sortedFields.map(async (field) => ({\n field,\n data: await executeListFieldPagination(processedDocument, variables, field),\n }));\n\n const fieldResults = await Promise.all(fieldDataPromises);\n\n // Set results in order\n for (const { field, data } of fieldResults) {\n // Use array path format for es-toolkit's set function\n set(result, field.path, data);\n }\n\n // Execute non-list fields (single entity queries)\n const nonListQuery = createNonListQuery(processedDocument, listFields);\n\n if (nonListQuery) {\n const nonListResult = await theGraphClient.request(\n nonListQuery,\n filterVariables(variables, nonListQuery) ?? {},\n );\n\n // Merge results, preserving list data\n const merged = customMerge(nonListResult, result);\n return merged as TResult;\n }\n\n return result as TResult;\n },\n } as const;\n}\n\nfunction isRequestOptions(args: unknown): args is RequestOptions<Variables, unknown> {\n return typeof args === \"object\" && args !== null && \"document\" in args && \"variables\" in args;\n}\n","import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport { type AbstractSetupSchema, initGraphQLTada } from \"gql.tada\";\nimport { GraphQLClient } from \"graphql-request\";\nimport { z } from \"zod\";\nimport { createTheGraphClientWithPagination } from \"./utils/pagination.js\";\n\n/**\n * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the TheGraph client.\n */\nexport const ClientOptionsSchema = z.object({\n instances: z.array(UrlOrPathSchema),\n accessToken: ApplicationAccessTokenSchema.optional(),\n subgraphName: z.string(),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the full URL for TheGraph GraphQL API based on the provided options\n *\n * @param options - The client options for configuring TheGraph client\n * @returns The complete GraphQL API URL as a string\n * @throws Will throw an error if no matching instance is found for the specified subgraph\n */\nfunction getFullUrl(options: ClientOptions): string {\n const instance = options.instances.find((instance) => instance.endsWith(`/${options.subgraphName}`));\n if (!instance) {\n throw new Error(`Instance for subgraph ${options.subgraphName} not found`);\n }\n return new URL(instance).toString();\n}\n\n/**\n * Creates a TheGraph GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client including instance URLs,\n * access token and subgraph name\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing:\n * - client: The configured GraphQL client instance\n * - graphql: The initialized gql.tada function for type-safe queries\n * @throws Will throw an error if the options fail validation against ClientOptionsSchema\n * @example\n * import { createTheGraphClient } from '@settlemint/sdk-thegraph';\n * import type { introspection } from '@schemas/the-graph-env-kits';\n * import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';\n *\n * const logger = createLogger();\n *\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: string;\n * };\n * }>({\n * instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * subgraphName: 'kits'\n * }, {\n * fetch: requestLogger(logger, \"the-graph-kits\", fetch) as typeof fetch,\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query SearchAssets {\n * assets @fetchAll {\n * id\n * name\n * symbol\n * }\n * }\n * `);\n *\n * const result = await client.request(query);\n */\nexport function createTheGraphClient<const Setup extends AbstractSetupSchema>(\n options: ClientOptions,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n ensureServer();\n const validatedOptions = validate(ClientOptionsSchema, options);\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n const client = new GraphQLClient(fullUrl, {\n ...clientOptions,\n headers: appendHeaders(clientOptions?.headers, { \"x-auth-token\": validatedOptions.accessToken }),\n });\n const originalRequest = client.request.bind(client);\n const paginatedClient = createTheGraphClientWithPagination({\n request: originalRequest,\n });\n client.request = paginatedClient.query;\n return {\n client,\n graphql,\n };\n}\n\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\nexport { readFragment } from \"gql.tada\";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