@settlemint/sdk-thegraph 1.1.9 → 1.1.11-main56875e3c

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
@@ -54,7 +54,7 @@ For detailed information about using TheGraph with the SettleMint platform, chec
54
54
 
55
55
  > **createTheGraphClient**\<`Setup`\>(`options`, `clientOptions`?): `object`
56
56
 
57
- Defined in: [sdk/thegraph/src/thegraph.ts:121](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/thegraph/src/thegraph.ts#L121)
57
+ Defined in: [sdk/thegraph/src/thegraph.ts:117](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/thegraph/src/thegraph.ts#L117)
58
58
 
59
59
  Creates a TheGraph GraphQL client with proper type safety using gql.tada
60
60
 
@@ -81,8 +81,8 @@ An object containing:
81
81
 
82
82
  | Name | Type | Defined in |
83
83
  | ------ | ------ | ------ |
84
- | `client` | `GraphQLClient` | [sdk/thegraph/src/thegraph.ts:125](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/thegraph/src/thegraph.ts#L125) |
85
- | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/thegraph/src/thegraph.ts:126](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/thegraph/src/thegraph.ts#L126) |
84
+ | `client` | `GraphQLClient` | [sdk/thegraph/src/thegraph.ts:121](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/thegraph/src/thegraph.ts#L121) |
85
+ | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/thegraph/src/thegraph.ts:122](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/thegraph/src/thegraph.ts#L122) |
86
86
 
87
87
  ##### Throws
88
88
 
@@ -99,8 +99,6 @@ const { client, graphql } = createTheGraphClient<{
99
99
  introspection: introspection;
100
100
  disableMasking: true;
101
101
  scalars: {
102
- DateTime: Date;
103
- JSON: Record<string, unknown>;
104
102
  Bytes: string;
105
103
  Int8: string;
106
104
  BigInt: string;
@@ -118,8 +116,6 @@ const { client, graphql } = createTheGraphClient<{
118
116
  introspection: introspection;
119
117
  disableMasking: true;
120
118
  scalars: {
121
- DateTime: Date;
122
- JSON: Record<string, unknown>;
123
119
  Bytes: string;
124
120
  Int8: string;
125
121
  BigInt: string;
@@ -150,7 +146,7 @@ const result = await client.request(query);
150
146
 
151
147
  > **ClientOptions**: \{ `accessToken`: `string`; `instances`: `string`[]; `runtime`: `"server"`; `subgraphName`: `string`; \} \| \{ `runtime`: `"browser"`; `subgraphName`: `string`; \}
152
148
 
153
- Defined in: [sdk/thegraph/src/thegraph.ts:34](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/thegraph/src/thegraph.ts#L34)
149
+ Defined in: [sdk/thegraph/src/thegraph.ts:34](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/thegraph/src/thegraph.ts#L34)
154
150
 
155
151
  Type definition for client options derived from the ClientOptionsSchema
156
152
 
@@ -160,7 +156,7 @@ Type definition for client options derived from the ClientOptionsSchema
160
156
 
161
157
  > **RequestConfig**: `ConstructorParameters`\<*typeof* `GraphQLClient`\>\[`1`\]
162
158
 
163
- Defined in: [sdk/thegraph/src/thegraph.ts:10](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/thegraph/src/thegraph.ts#L10)
159
+ Defined in: [sdk/thegraph/src/thegraph.ts:10](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/thegraph/src/thegraph.ts#L10)
164
160
 
165
161
  Type definition for GraphQL client configuration options
166
162
 
@@ -170,7 +166,7 @@ Type definition for GraphQL client configuration options
170
166
 
171
167
  > `const` **ClientOptionsSchema**: `ZodDiscriminatedUnion`\<[`ClientOptions`](README.md#clientoptions)\>
172
168
 
173
- Defined in: [sdk/thegraph/src/thegraph.ts:18](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/thegraph/src/thegraph.ts#L18)
169
+ Defined in: [sdk/thegraph/src/thegraph.ts:18](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/thegraph/src/thegraph.ts#L18)
174
170
 
175
171
  Schema for validating client options for the TheGraph client.
176
172
  Defines two possible runtime configurations:
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/thegraph.ts"],"sourcesContent":["import { runsOnServer } 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 * Defines two possible runtime configurations:\n * 1. Server-side with instance URLs, access token and subgraph name\n * 2. Browser-side with just subgraph name\n */\nexport const ClientOptionsSchema = z.discriminatedUnion(\"runtime\", [\n z.object({\n instances: z.array(UrlOrPathSchema),\n runtime: z.literal(\"server\"),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n }),\n z.object({\n runtime: z.literal(\"browser\"),\n subgraphName: z.string(),\n }),\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 if (options.runtime === \"server\") {\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 return new URL(\n `/proxy/thegraph/graphql/${encodeURIComponent(options.subgraphName)}`,\n window?.location?.origin ?? \"http://localhost:3000\",\n ).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:\n * - For server-side: instance URLs, access token and subgraph name\n * - For browser-side: just 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-starterkits';\n *\n * // Server-side usage\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * DateTime: Date;\n * JSON: Record<string, unknown>;\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: 'starterkits'\n * });\n *\n * // Browser-side usage\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * DateTime: Date;\n * JSON: Record<string, unknown>;\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: string;\n * };\n * }>({\n * subgraphName: 'starterkits'\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: Omit<ClientOptions, \"runtime\"> & Record<string, unknown>,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n const validatedOptions = validate(ClientOptionsSchema, {\n ...options,\n runtime: runsOnServer ? \"server\" : \"browser\",\n });\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n ...(validatedOptions.runtime === \"server\" && {\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,wBAAwE;AACxE,iBAA0D;AAC1D,6BAA8B;AAC9B,iBAAkB;AA+IlB,IAAAA,cAA6B;AAlItB,IAAM,sBAAsB,aAAE,mBAAmB,WAAW;AAAA,EACjE,aAAE,OAAO;AAAA,IACP,WAAW,aAAE,MAAM,iCAAe;AAAA,IAClC,SAAS,aAAE,QAAQ,QAAQ;AAAA,IAC3B,aAAa;AAAA,IACb,cAAc,aAAE,OAAO;AAAA,EACzB,CAAC;AAAA,EACD,aAAE,OAAO;AAAA,IACP,SAAS,aAAE,QAAQ,SAAS;AAAA,IAC5B,cAAc,aAAE,OAAO;AAAA,EACzB,CAAC;AACH,CAAC;AAcD,SAAS,WAAW,SAAgC;AAClD,MAAI,QAAQ,YAAY,UAAU;AAChC,UAAM,WAAW,QAAQ,UAAU,KAAK,CAACC,cAAaA,UAAS,SAAS,IAAI,QAAQ,YAAY,EAAE,CAAC;AACnG,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,yBAAyB,QAAQ,YAAY,YAAY;AAAA,IAC3E;AACA,WAAO,IAAI,IAAI,QAAQ,EAAE,SAAS;AAAA,EACpC;AACA,SAAO,IAAI;AAAA,IACT,2BAA2B,mBAAmB,QAAQ,YAAY,CAAC;AAAA,IACnE,QAAQ,UAAU,UAAU;AAAA,EAC9B,EAAE,SAAS;AACb;AAkEO,SAAS,qBACd,SACA,eAIA;AACA,QAAM,uBAAmB,4BAAS,qBAAqB;AAAA,IACrD,GAAG;AAAA,IACH,SAAS,8BAAe,WAAW;AAAA,EACrC,CAAC;AACD,QAAM,cAAU,4BAAuB;AACvC,QAAM,UAAU,WAAW,gBAAgB;AAE3C,SAAO;AAAA,IACL,QAAQ,IAAI,qCAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,GAAI,iBAAiB,YAAY,YAAY;AAAA,QAC3C,SAAS;AAAA,UACP,gBAAgB,iBAAiB;AAAA,QACnC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["import_gql","instance"]}
1
+ {"version":3,"sources":["../src/thegraph.ts"],"sourcesContent":["import { runsOnServer } 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 * Defines two possible runtime configurations:\n * 1. Server-side with instance URLs, access token and subgraph name\n * 2. Browser-side with just subgraph name\n */\nexport const ClientOptionsSchema = z.discriminatedUnion(\"runtime\", [\n z.object({\n instances: z.array(UrlOrPathSchema),\n runtime: z.literal(\"server\"),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n }),\n z.object({\n runtime: z.literal(\"browser\"),\n subgraphName: z.string(),\n }),\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 if (options.runtime === \"server\") {\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 return new URL(\n `/proxy/thegraph/graphql/${encodeURIComponent(options.subgraphName)}`,\n window?.location?.origin ?? \"http://localhost:3000\",\n ).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:\n * - For server-side: instance URLs, access token and subgraph name\n * - For browser-side: just 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-starterkits';\n *\n * // Server-side usage\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: 'starterkits'\n * });\n *\n * // Browser-side usage\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 * subgraphName: 'starterkits'\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: Omit<ClientOptions, \"runtime\"> & Record<string, unknown>,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n const validatedOptions = validate(ClientOptionsSchema, {\n ...options,\n runtime: runsOnServer ? \"server\" : \"browser\",\n });\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n ...(validatedOptions.runtime === \"server\" && {\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,wBAAwE;AACxE,iBAA0D;AAC1D,6BAA8B;AAC9B,iBAAkB;AA2IlB,IAAAA,cAA6B;AA9HtB,IAAM,sBAAsB,aAAE,mBAAmB,WAAW;AAAA,EACjE,aAAE,OAAO;AAAA,IACP,WAAW,aAAE,MAAM,iCAAe;AAAA,IAClC,SAAS,aAAE,QAAQ,QAAQ;AAAA,IAC3B,aAAa;AAAA,IACb,cAAc,aAAE,OAAO;AAAA,EACzB,CAAC;AAAA,EACD,aAAE,OAAO;AAAA,IACP,SAAS,aAAE,QAAQ,SAAS;AAAA,IAC5B,cAAc,aAAE,OAAO;AAAA,EACzB,CAAC;AACH,CAAC;AAcD,SAAS,WAAW,SAAgC;AAClD,MAAI,QAAQ,YAAY,UAAU;AAChC,UAAM,WAAW,QAAQ,UAAU,KAAK,CAACC,cAAaA,UAAS,SAAS,IAAI,QAAQ,YAAY,EAAE,CAAC;AACnG,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,yBAAyB,QAAQ,YAAY,YAAY;AAAA,IAC3E;AACA,WAAO,IAAI,IAAI,QAAQ,EAAE,SAAS;AAAA,EACpC;AACA,SAAO,IAAI;AAAA,IACT,2BAA2B,mBAAmB,QAAQ,YAAY,CAAC;AAAA,IACnE,QAAQ,UAAU,UAAU;AAAA,EAC9B,EAAE,SAAS;AACb;AA8DO,SAAS,qBACd,SACA,eAIA;AACA,QAAM,uBAAmB,4BAAS,qBAAqB;AAAA,IACrD,GAAG;AAAA,IACH,SAAS,8BAAe,WAAW;AAAA,EACrC,CAAC;AACD,QAAM,cAAU,4BAAuB;AACvC,QAAM,UAAU,WAAW,gBAAgB;AAE3C,SAAO;AAAA,IACL,QAAQ,IAAI,qCAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,GAAI,iBAAiB,YAAY,YAAY;AAAA,QAC3C,SAAS;AAAA,UACP,gBAAgB,iBAAiB;AAAA,QACnC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["import_gql","instance"]}
@@ -62,8 +62,6 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
62
62
  * introspection: introspection;
63
63
  * disableMasking: true;
64
64
  * scalars: {
65
- * DateTime: Date;
66
- * JSON: Record<string, unknown>;
67
65
  * Bytes: string;
68
66
  * Int8: string;
69
67
  * BigInt: string;
@@ -81,8 +79,6 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
81
79
  * introspection: introspection;
82
80
  * disableMasking: true;
83
81
  * scalars: {
84
- * DateTime: Date;
85
- * JSON: Record<string, unknown>;
86
82
  * Bytes: string;
87
83
  * Int8: string;
88
84
  * BigInt: string;
@@ -62,8 +62,6 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
62
62
  * introspection: introspection;
63
63
  * disableMasking: true;
64
64
  * scalars: {
65
- * DateTime: Date;
66
- * JSON: Record<string, unknown>;
67
65
  * Bytes: string;
68
66
  * Int8: string;
69
67
  * BigInt: string;
@@ -81,8 +79,6 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
81
79
  * introspection: introspection;
82
80
  * disableMasking: true;
83
81
  * scalars: {
84
- * DateTime: Date;
85
- * JSON: Record<string, unknown>;
86
82
  * Bytes: string;
87
83
  * Int8: string;
88
84
  * BigInt: string;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/thegraph.ts"],"sourcesContent":["import { runsOnServer } 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 * Defines two possible runtime configurations:\n * 1. Server-side with instance URLs, access token and subgraph name\n * 2. Browser-side with just subgraph name\n */\nexport const ClientOptionsSchema = z.discriminatedUnion(\"runtime\", [\n z.object({\n instances: z.array(UrlOrPathSchema),\n runtime: z.literal(\"server\"),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n }),\n z.object({\n runtime: z.literal(\"browser\"),\n subgraphName: z.string(),\n }),\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 if (options.runtime === \"server\") {\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 return new URL(\n `/proxy/thegraph/graphql/${encodeURIComponent(options.subgraphName)}`,\n window?.location?.origin ?? \"http://localhost:3000\",\n ).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:\n * - For server-side: instance URLs, access token and subgraph name\n * - For browser-side: just 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-starterkits';\n *\n * // Server-side usage\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * DateTime: Date;\n * JSON: Record<string, unknown>;\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: 'starterkits'\n * });\n *\n * // Browser-side usage\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * DateTime: Date;\n * JSON: Record<string, unknown>;\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: string;\n * };\n * }>({\n * subgraphName: 'starterkits'\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: Omit<ClientOptions, \"runtime\"> & Record<string, unknown>,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n const validatedOptions = validate(ClientOptionsSchema, {\n ...options,\n runtime: runsOnServer ? \"server\" : \"browser\",\n });\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n ...(validatedOptions.runtime === \"server\" && {\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B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D;AAAA,EACF;AACF;","names":["instance"]}
1
+ {"version":3,"sources":["../src/thegraph.ts"],"sourcesContent":["import { runsOnServer } 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 * Defines two possible runtime configurations:\n * 1. Server-side with instance URLs, access token and subgraph name\n * 2. Browser-side with just subgraph name\n */\nexport const ClientOptionsSchema = z.discriminatedUnion(\"runtime\", [\n z.object({\n instances: z.array(UrlOrPathSchema),\n runtime: z.literal(\"server\"),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n }),\n z.object({\n runtime: z.literal(\"browser\"),\n subgraphName: z.string(),\n }),\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 if (options.runtime === \"server\") {\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 return new URL(\n `/proxy/thegraph/graphql/${encodeURIComponent(options.subgraphName)}`,\n window?.location?.origin ?? \"http://localhost:3000\",\n ).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:\n * - For server-side: instance URLs, access token and subgraph name\n * - For browser-side: just 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-starterkits';\n *\n * // Server-side usage\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: 'starterkits'\n * });\n *\n * // Browser-side usage\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 * subgraphName: 'starterkits'\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: Omit<ClientOptions, \"runtime\"> & Record<string, unknown>,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n const validatedOptions = validate(ClientOptionsSchema, {\n ...options,\n runtime: runsOnServer ? \"server\" : \"browser\",\n });\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n ...(validatedOptions.runtime === \"server\" && {\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf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P,gBAAgB,iBAAiB;AAAA,QACnC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["instance"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@settlemint/sdk-thegraph",
3
3
  "description": "TheGraph integration module for SettleMint SDK, enabling querying and indexing of blockchain data through subgraphs",
4
- "version": "1.1.9",
4
+ "version": "1.1.11-main56875e3c",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "license": "FSL-1.1-MIT",
@@ -52,7 +52,7 @@
52
52
  "devDependencies": {},
53
53
  "dependencies": {
54
54
  "gql.tada": "^1",
55
- "@settlemint/sdk-utils": "1.1.9",
55
+ "@settlemint/sdk-utils": "1.1.11-main56875e3c",
56
56
  "graphql-request": "^7",
57
57
  "zod": "^3"
58
58
  },