@settlemint/sdk-hasura 2.5.11 → 2.5.13-maina48700be
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 +13 -13
- package/dist/postgres.cjs +3 -2
- package/dist/postgres.cjs.map +1 -1
- package/dist/postgres.js +3 -2
- package/dist/postgres.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ The SettleMint Hasura SDK provides a seamless way to interact with Hasura GraphQ
|
|
|
53
53
|
|
|
54
54
|
> **createHasuraClient**\<`Setup`\>(`options`, `clientOptions?`, `logger?`): `object`
|
|
55
55
|
|
|
56
|
-
Defined in: [sdk/hasura/src/hasura.ts:83](https://github.com/settlemint/sdk/blob/v2.5.
|
|
56
|
+
Defined in: [sdk/hasura/src/hasura.ts:83](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L83)
|
|
57
57
|
|
|
58
58
|
Creates a Hasura GraphQL client with proper type safety using gql.tada
|
|
59
59
|
|
|
@@ -85,8 +85,8 @@ An object containing:
|
|
|
85
85
|
|
|
86
86
|
| Name | Type | Defined in |
|
|
87
87
|
| ------ | ------ | ------ |
|
|
88
|
-
| `client` | `GraphQLClient` | [sdk/hasura/src/hasura.ts:88](https://github.com/settlemint/sdk/blob/v2.5.
|
|
89
|
-
| `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/hasura/src/hasura.ts:89](https://github.com/settlemint/sdk/blob/v2.5.
|
|
88
|
+
| `client` | `GraphQLClient` | [sdk/hasura/src/hasura.ts:88](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L88) |
|
|
89
|
+
| `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/hasura/src/hasura.ts:89](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L89) |
|
|
90
90
|
|
|
91
91
|
##### Throws
|
|
92
92
|
|
|
@@ -144,7 +144,7 @@ const result = await client.request(query);
|
|
|
144
144
|
|
|
145
145
|
> **createHasuraMetadataClient**(`options`, `logger?`): \<`T`\>(`query`) => `Promise`\<\{ `data`: `T`; `ok`: `boolean`; \}\>
|
|
146
146
|
|
|
147
|
-
Defined in: [sdk/hasura/src/hasura.ts:132](https://github.com/settlemint/sdk/blob/v2.5.
|
|
147
|
+
Defined in: [sdk/hasura/src/hasura.ts:132](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L132)
|
|
148
148
|
|
|
149
149
|
Creates a Hasura Metadata client
|
|
150
150
|
|
|
@@ -210,7 +210,7 @@ const result = await client({
|
|
|
210
210
|
|
|
211
211
|
> **createPostgresPool**(`databaseUrl`): `Pool`
|
|
212
212
|
|
|
213
|
-
Defined in: [sdk/hasura/src/postgres.ts:107](https://github.com/settlemint/sdk/blob/v2.5.
|
|
213
|
+
Defined in: [sdk/hasura/src/postgres.ts:107](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/postgres.ts#L107)
|
|
214
214
|
|
|
215
215
|
Creates a PostgreSQL connection pool with error handling and retry mechanisms
|
|
216
216
|
|
|
@@ -253,7 +253,7 @@ try {
|
|
|
253
253
|
|
|
254
254
|
> **trackAllTables**(`databaseName`, `client`, `tableOptions`): `Promise`\<\{ `messages`: `string`[]; `result`: `"success"` \| `"no-tables"`; \}\>
|
|
255
255
|
|
|
256
|
-
Defined in: [sdk/hasura/src/utils/track-all-tables.ts:30](https://github.com/settlemint/sdk/blob/v2.5.
|
|
256
|
+
Defined in: [sdk/hasura/src/utils/track-all-tables.ts:30](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/utils/track-all-tables.ts#L30)
|
|
257
257
|
|
|
258
258
|
Track all tables in a database
|
|
259
259
|
|
|
@@ -300,7 +300,7 @@ if (result.result === "success") {
|
|
|
300
300
|
|
|
301
301
|
> **ClientOptions** = `object`
|
|
302
302
|
|
|
303
|
-
Defined in: [sdk/hasura/src/hasura.ts:28](https://github.com/settlemint/sdk/blob/v2.5.
|
|
303
|
+
Defined in: [sdk/hasura/src/hasura.ts:28](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L28)
|
|
304
304
|
|
|
305
305
|
Type definition for client options derived from the ClientOptionsSchema.
|
|
306
306
|
|
|
@@ -308,10 +308,10 @@ Type definition for client options derived from the ClientOptionsSchema.
|
|
|
308
308
|
|
|
309
309
|
| Name | Type | Default value | Defined in |
|
|
310
310
|
| ------ | ------ | ------ | ------ |
|
|
311
|
-
| <a id="accesstoken"></a> `accessToken?` | `string` | - | [sdk/hasura/src/hasura.ts:20](https://github.com/settlemint/sdk/blob/v2.5.
|
|
312
|
-
| <a id="adminsecret"></a> `adminSecret` | `string` | - | [sdk/hasura/src/hasura.ts:21](https://github.com/settlemint/sdk/blob/v2.5.
|
|
313
|
-
| <a id="cache"></a> `cache?` | `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"` | - | [sdk/hasura/src/hasura.ts:22](https://github.com/settlemint/sdk/blob/v2.5.
|
|
314
|
-
| <a id="instance"></a> `instance` | `string` | `UrlOrPathSchema` | [sdk/hasura/src/hasura.ts:19](https://github.com/settlemint/sdk/blob/v2.5.
|
|
311
|
+
| <a id="accesstoken"></a> `accessToken?` | `string` | - | [sdk/hasura/src/hasura.ts:20](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L20) |
|
|
312
|
+
| <a id="adminsecret"></a> `adminSecret` | `string` | - | [sdk/hasura/src/hasura.ts:21](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L21) |
|
|
313
|
+
| <a id="cache"></a> `cache?` | `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"` | - | [sdk/hasura/src/hasura.ts:22](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L22) |
|
|
314
|
+
| <a id="instance"></a> `instance` | `string` | `UrlOrPathSchema` | [sdk/hasura/src/hasura.ts:19](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L19) |
|
|
315
315
|
|
|
316
316
|
***
|
|
317
317
|
|
|
@@ -319,7 +319,7 @@ Type definition for client options derived from the ClientOptionsSchema.
|
|
|
319
319
|
|
|
320
320
|
> **RequestConfig** = `ConstructorParameters`\<*typeof* `GraphQLClient`\>\[`1`\]
|
|
321
321
|
|
|
322
|
-
Defined in: [sdk/hasura/src/hasura.ts:13](https://github.com/settlemint/sdk/blob/v2.5.
|
|
322
|
+
Defined in: [sdk/hasura/src/hasura.ts:13](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L13)
|
|
323
323
|
|
|
324
324
|
Type definition for GraphQL client configuration options
|
|
325
325
|
|
|
@@ -329,7 +329,7 @@ Type definition for GraphQL client configuration options
|
|
|
329
329
|
|
|
330
330
|
> `const` **ClientOptionsSchema**: `ZodObject`\<[`ClientOptions`](#clientoptions)\>
|
|
331
331
|
|
|
332
|
-
Defined in: [sdk/hasura/src/hasura.ts:18](https://github.com/settlemint/sdk/blob/v2.5.
|
|
332
|
+
Defined in: [sdk/hasura/src/hasura.ts:18](https://github.com/settlemint/sdk/blob/v2.5.13/sdk/hasura/src/hasura.ts#L18)
|
|
333
333
|
|
|
334
334
|
Schema for validating client options for the Hasura client.
|
|
335
335
|
|
package/dist/postgres.cjs
CHANGED
|
@@ -114,9 +114,10 @@ function createPostgresPool(databaseUrl) {
|
|
|
114
114
|
}
|
|
115
115
|
const pool = new pg.default.Pool({
|
|
116
116
|
connectionString: databaseUrl,
|
|
117
|
-
max:
|
|
117
|
+
max: 10,
|
|
118
118
|
idleTimeoutMillis: 3e4,
|
|
119
|
-
connectionTimeoutMillis: 5e3
|
|
119
|
+
connectionTimeoutMillis: 5e3,
|
|
120
|
+
maxLifetimeSeconds: 0
|
|
120
121
|
});
|
|
121
122
|
setupErrorHandling(pool);
|
|
122
123
|
return pool;
|
package/dist/postgres.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.cjs","names":["ms: number","pool: pg.Pool","err: Error","client: pg.PoolClient","databaseUrl: string","runsOnServer"],"sources":["../src/postgres.ts"],"sourcesContent":["import { runsOnServer } from \"@settlemint/sdk-utils/runtime\";\nimport pg from \"pg\";\n\n/**\n * Type definition extending the pg.Pool interface to include custom permanent-failure event\n */\ndeclare module \"pg\" {\n interface Pool {\n on(event: \"permanent-failure\", listener: (err: Error) => void): this;\n emit(event: \"permanent-failure\", err: Error): boolean;\n }\n}\n\n/**\n * Utility function to pause execution for a specified duration\n *\n * @param ms - The number of milliseconds to sleep\n * @returns A promise that resolves after the specified duration\n */\nconst sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * Configures error handling and recovery mechanisms for a PostgreSQL connection pool\n *\n * @param pool - The PostgreSQL connection pool to configure\n */\nfunction setupErrorHandling(pool: pg.Pool) {\n let retryCount = 0;\n let isRetrying = false;\n const clientErrorHandlers = new WeakSet<pg.PoolClient>();\n\n const handlePoolError = async (err: Error) => {\n console.error(\"[Drizzle] Pool error occurred:\", err);\n\n // Prevent concurrent retry attempts\n if (isRetrying) {\n console.log(\"[Drizzle] Recovery already in progress, skipping\");\n return;\n }\n\n if (retryCount < 3) {\n isRetrying = true;\n retryCount++;\n console.log(`[Drizzle] Attempting to recover - retry ${retryCount}/3`);\n\n try {\n const client = await pool.connect();\n try {\n // Test the connection with timeout\n await Promise.race([\n client.query(\"SELECT 1\"),\n new Promise((_, reject) => setTimeout(() => reject(new Error(\"Query timeout\")), 5000)),\n ]);\n console.log(\"[Drizzle] Successfully recovered connection\");\n retryCount = 0;\n } finally {\n client.release();\n }\n } catch (retryError) {\n console.error(`[Drizzle] Recovery attempt ${retryCount} failed:`, retryError);\n await sleep(5000 * 2 ** (retryCount - 1));\n } finally {\n isRetrying = false;\n }\n } else {\n console.error(\"[Drizzle] Max retries exceeded - pool is in an error state\");\n pool.emit(\"permanent-failure\", err);\n }\n };\n\n const handleConnect = (client: pg.PoolClient) => {\n // Only add error handler if not already added (prevent memory leaks)\n if (!clientErrorHandlers.has(client)) {\n clientErrorHandlers.add(client);\n client.on(\"error\", (err: Error) => {\n console.error(\"[Drizzle] Database client error:\", err);\n });\n }\n retryCount = 0;\n isRetrying = false;\n };\n\n pool.on(\"error\", handlePoolError);\n pool.on(\"connect\", handleConnect);\n}\n\n/**\n * Creates a PostgreSQL connection pool with error handling and retry mechanisms\n *\n * @param databaseUrl - The PostgreSQL connection URL\n * @returns A configured PostgreSQL connection pool\n * @throws Will throw an error if called from browser runtime\n * @example\n * import { createPostgresPool } from '@settlemint/sdk-hasura';\n *\n * const pool = createPostgresPool(process.env.SETTLEMINT_HASURA_DATABASE_URL);\n *\n * // The pool will automatically handle connection errors and retries\n * const client = await pool.connect();\n * try {\n * const result = await client.query('SELECT NOW()');\n * console.log(result.rows[0]);\n * } finally {\n * client.release();\n * }\n */\nexport function createPostgresPool(databaseUrl: string) {\n if (!databaseUrl?.trim()) {\n throw new Error(\"Database URL is required\");\n }\n\n if (!runsOnServer) {\n throw new Error(\"Drizzle client can only be created on the server side\");\n }\n\n const pool = new pg.Pool({\n connectionString: databaseUrl,\n max:
|
|
1
|
+
{"version":3,"file":"postgres.cjs","names":["ms: number","pool: pg.Pool","err: Error","client: pg.PoolClient","databaseUrl: string","runsOnServer"],"sources":["../src/postgres.ts"],"sourcesContent":["import { runsOnServer } from \"@settlemint/sdk-utils/runtime\";\nimport pg from \"pg\";\n\n/**\n * Type definition extending the pg.Pool interface to include custom permanent-failure event\n */\ndeclare module \"pg\" {\n interface Pool {\n on(event: \"permanent-failure\", listener: (err: Error) => void): this;\n emit(event: \"permanent-failure\", err: Error): boolean;\n }\n}\n\n/**\n * Utility function to pause execution for a specified duration\n *\n * @param ms - The number of milliseconds to sleep\n * @returns A promise that resolves after the specified duration\n */\nconst sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * Configures error handling and recovery mechanisms for a PostgreSQL connection pool\n *\n * @param pool - The PostgreSQL connection pool to configure\n */\nfunction setupErrorHandling(pool: pg.Pool) {\n let retryCount = 0;\n let isRetrying = false;\n const clientErrorHandlers = new WeakSet<pg.PoolClient>();\n\n const handlePoolError = async (err: Error) => {\n console.error(\"[Drizzle] Pool error occurred:\", err);\n\n // Prevent concurrent retry attempts\n if (isRetrying) {\n console.log(\"[Drizzle] Recovery already in progress, skipping\");\n return;\n }\n\n if (retryCount < 3) {\n isRetrying = true;\n retryCount++;\n console.log(`[Drizzle] Attempting to recover - retry ${retryCount}/3`);\n\n try {\n const client = await pool.connect();\n try {\n // Test the connection with timeout\n await Promise.race([\n client.query(\"SELECT 1\"),\n new Promise((_, reject) => setTimeout(() => reject(new Error(\"Query timeout\")), 5000)),\n ]);\n console.log(\"[Drizzle] Successfully recovered connection\");\n retryCount = 0;\n } finally {\n client.release();\n }\n } catch (retryError) {\n console.error(`[Drizzle] Recovery attempt ${retryCount} failed:`, retryError);\n await sleep(5000 * 2 ** (retryCount - 1));\n } finally {\n isRetrying = false;\n }\n } else {\n console.error(\"[Drizzle] Max retries exceeded - pool is in an error state\");\n pool.emit(\"permanent-failure\", err);\n }\n };\n\n const handleConnect = (client: pg.PoolClient) => {\n // Only add error handler if not already added (prevent memory leaks)\n if (!clientErrorHandlers.has(client)) {\n clientErrorHandlers.add(client);\n client.on(\"error\", (err: Error) => {\n console.error(\"[Drizzle] Database client error:\", err);\n });\n }\n retryCount = 0;\n isRetrying = false;\n };\n\n pool.on(\"error\", handlePoolError);\n pool.on(\"connect\", handleConnect);\n}\n\n/**\n * Creates a PostgreSQL connection pool with error handling and retry mechanisms\n *\n * @param databaseUrl - The PostgreSQL connection URL\n * @returns A configured PostgreSQL connection pool\n * @throws Will throw an error if called from browser runtime\n * @example\n * import { createPostgresPool } from '@settlemint/sdk-hasura';\n *\n * const pool = createPostgresPool(process.env.SETTLEMINT_HASURA_DATABASE_URL);\n *\n * // The pool will automatically handle connection errors and retries\n * const client = await pool.connect();\n * try {\n * const result = await client.query('SELECT NOW()');\n * console.log(result.rows[0]);\n * } finally {\n * client.release();\n * }\n */\nexport function createPostgresPool(databaseUrl: string) {\n if (!databaseUrl?.trim()) {\n throw new Error(\"Database URL is required\");\n }\n\n if (!runsOnServer) {\n throw new Error(\"Drizzle client can only be created on the server side\");\n }\n\n const pool = new pg.Pool({\n connectionString: databaseUrl,\n max: 10,\n idleTimeoutMillis: 30000,\n connectionTimeoutMillis: 5000,\n maxLifetimeSeconds: 0,\n });\n\n setupErrorHandling(pool);\n\n return pool;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAM,QAAQ,CAACA,OAAe,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG;;;;;;AAO9E,SAAS,mBAAmBC,MAAe;CACzC,IAAI,aAAa;CACjB,IAAI,aAAa;CACjB,MAAM,sBAAsB,IAAI;CAEhC,MAAM,kBAAkB,OAAOC,QAAe;EAC5C,QAAQ,MAAM,kCAAkC,IAAI;AAGpD,MAAI,YAAY;GACd,QAAQ,IAAI,mDAAmD;AAC/D;EACD;AAED,MAAI,aAAa,GAAG;GAClB,aAAa;GACb;GACA,QAAQ,IAAI,CAAC,wCAAwC,EAAE,WAAW,EAAE,CAAC,CAAC;AAEtE,OAAI;IACF,MAAM,SAAS,MAAM,KAAK,SAAS;AACnC,QAAI;KAEF,MAAM,QAAQ,KAAK,CACjB,OAAO,MAAM,WAAW,EACxB,IAAI,QAAQ,CAAC,GAAG,WAAW,WAAW,MAAM,OAAO,IAAI,MAAM,iBAAiB,EAAE,IAAK,CACtF,EAAC;KACF,QAAQ,IAAI,8CAA8C;KAC1D,aAAa;IACd,UAAS;KACR,OAAO,SAAS;IACjB;GACF,SAAQ,YAAY;IACnB,QAAQ,MAAM,CAAC,2BAA2B,EAAE,WAAW,QAAQ,CAAC,EAAE,WAAW;IAC7E,MAAM,MAAM,MAAO,MAAM,aAAa,GAAG;GAC1C,UAAS;IACR,aAAa;GACd;EACF,OAAM;GACL,QAAQ,MAAM,6DAA6D;GAC3E,KAAK,KAAK,qBAAqB,IAAI;EACpC;CACF;CAED,MAAM,gBAAgB,CAACC,WAA0B;AAE/C,MAAI,CAAC,oBAAoB,IAAI,OAAO,EAAE;GACpC,oBAAoB,IAAI,OAAO;GAC/B,OAAO,GAAG,SAAS,CAACD,QAAe;IACjC,QAAQ,MAAM,oCAAoC,IAAI;GACvD,EAAC;EACH;EACD,aAAa;EACb,aAAa;CACd;CAED,KAAK,GAAG,SAAS,gBAAgB;CACjC,KAAK,GAAG,WAAW,cAAc;AAClC;;;;;;;;;;;;;;;;;;;;;AAsBD,SAAgB,mBAAmBE,aAAqB;AACtD,KAAI,CAAC,aAAa,MAAM,EAAE;AACxB,QAAM,IAAI,MAAM;CACjB;AAED,KAAI,CAACC,6CAAc;AACjB,QAAM,IAAI,MAAM;CACjB;CAED,MAAM,OAAO,IAAI,WAAG,KAAK;EACvB,kBAAkB;EAClB,KAAK;EACL,mBAAmB;EACnB,yBAAyB;EACzB,oBAAoB;CACrB;CAED,mBAAmB,KAAK;AAExB,QAAO;AACR"}
|
package/dist/postgres.js
CHANGED
|
@@ -91,9 +91,10 @@ function createPostgresPool(databaseUrl) {
|
|
|
91
91
|
}
|
|
92
92
|
const pool = new pg.Pool({
|
|
93
93
|
connectionString: databaseUrl,
|
|
94
|
-
max:
|
|
94
|
+
max: 10,
|
|
95
95
|
idleTimeoutMillis: 3e4,
|
|
96
|
-
connectionTimeoutMillis: 5e3
|
|
96
|
+
connectionTimeoutMillis: 5e3,
|
|
97
|
+
maxLifetimeSeconds: 0
|
|
97
98
|
});
|
|
98
99
|
setupErrorHandling(pool);
|
|
99
100
|
return pool;
|
package/dist/postgres.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","names":["ms: number","pool: pg.Pool","err: Error","client: pg.PoolClient","databaseUrl: string"],"sources":["../src/postgres.ts"],"sourcesContent":["import { runsOnServer } from \"@settlemint/sdk-utils/runtime\";\nimport pg from \"pg\";\n\n/**\n * Type definition extending the pg.Pool interface to include custom permanent-failure event\n */\ndeclare module \"pg\" {\n interface Pool {\n on(event: \"permanent-failure\", listener: (err: Error) => void): this;\n emit(event: \"permanent-failure\", err: Error): boolean;\n }\n}\n\n/**\n * Utility function to pause execution for a specified duration\n *\n * @param ms - The number of milliseconds to sleep\n * @returns A promise that resolves after the specified duration\n */\nconst sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * Configures error handling and recovery mechanisms for a PostgreSQL connection pool\n *\n * @param pool - The PostgreSQL connection pool to configure\n */\nfunction setupErrorHandling(pool: pg.Pool) {\n let retryCount = 0;\n let isRetrying = false;\n const clientErrorHandlers = new WeakSet<pg.PoolClient>();\n\n const handlePoolError = async (err: Error) => {\n console.error(\"[Drizzle] Pool error occurred:\", err);\n\n // Prevent concurrent retry attempts\n if (isRetrying) {\n console.log(\"[Drizzle] Recovery already in progress, skipping\");\n return;\n }\n\n if (retryCount < 3) {\n isRetrying = true;\n retryCount++;\n console.log(`[Drizzle] Attempting to recover - retry ${retryCount}/3`);\n\n try {\n const client = await pool.connect();\n try {\n // Test the connection with timeout\n await Promise.race([\n client.query(\"SELECT 1\"),\n new Promise((_, reject) => setTimeout(() => reject(new Error(\"Query timeout\")), 5000)),\n ]);\n console.log(\"[Drizzle] Successfully recovered connection\");\n retryCount = 0;\n } finally {\n client.release();\n }\n } catch (retryError) {\n console.error(`[Drizzle] Recovery attempt ${retryCount} failed:`, retryError);\n await sleep(5000 * 2 ** (retryCount - 1));\n } finally {\n isRetrying = false;\n }\n } else {\n console.error(\"[Drizzle] Max retries exceeded - pool is in an error state\");\n pool.emit(\"permanent-failure\", err);\n }\n };\n\n const handleConnect = (client: pg.PoolClient) => {\n // Only add error handler if not already added (prevent memory leaks)\n if (!clientErrorHandlers.has(client)) {\n clientErrorHandlers.add(client);\n client.on(\"error\", (err: Error) => {\n console.error(\"[Drizzle] Database client error:\", err);\n });\n }\n retryCount = 0;\n isRetrying = false;\n };\n\n pool.on(\"error\", handlePoolError);\n pool.on(\"connect\", handleConnect);\n}\n\n/**\n * Creates a PostgreSQL connection pool with error handling and retry mechanisms\n *\n * @param databaseUrl - The PostgreSQL connection URL\n * @returns A configured PostgreSQL connection pool\n * @throws Will throw an error if called from browser runtime\n * @example\n * import { createPostgresPool } from '@settlemint/sdk-hasura';\n *\n * const pool = createPostgresPool(process.env.SETTLEMINT_HASURA_DATABASE_URL);\n *\n * // The pool will automatically handle connection errors and retries\n * const client = await pool.connect();\n * try {\n * const result = await client.query('SELECT NOW()');\n * console.log(result.rows[0]);\n * } finally {\n * client.release();\n * }\n */\nexport function createPostgresPool(databaseUrl: string) {\n if (!databaseUrl?.trim()) {\n throw new Error(\"Database URL is required\");\n }\n\n if (!runsOnServer) {\n throw new Error(\"Drizzle client can only be created on the server side\");\n }\n\n const pool = new pg.Pool({\n connectionString: databaseUrl,\n max:
|
|
1
|
+
{"version":3,"file":"postgres.js","names":["ms: number","pool: pg.Pool","err: Error","client: pg.PoolClient","databaseUrl: string"],"sources":["../src/postgres.ts"],"sourcesContent":["import { runsOnServer } from \"@settlemint/sdk-utils/runtime\";\nimport pg from \"pg\";\n\n/**\n * Type definition extending the pg.Pool interface to include custom permanent-failure event\n */\ndeclare module \"pg\" {\n interface Pool {\n on(event: \"permanent-failure\", listener: (err: Error) => void): this;\n emit(event: \"permanent-failure\", err: Error): boolean;\n }\n}\n\n/**\n * Utility function to pause execution for a specified duration\n *\n * @param ms - The number of milliseconds to sleep\n * @returns A promise that resolves after the specified duration\n */\nconst sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * Configures error handling and recovery mechanisms for a PostgreSQL connection pool\n *\n * @param pool - The PostgreSQL connection pool to configure\n */\nfunction setupErrorHandling(pool: pg.Pool) {\n let retryCount = 0;\n let isRetrying = false;\n const clientErrorHandlers = new WeakSet<pg.PoolClient>();\n\n const handlePoolError = async (err: Error) => {\n console.error(\"[Drizzle] Pool error occurred:\", err);\n\n // Prevent concurrent retry attempts\n if (isRetrying) {\n console.log(\"[Drizzle] Recovery already in progress, skipping\");\n return;\n }\n\n if (retryCount < 3) {\n isRetrying = true;\n retryCount++;\n console.log(`[Drizzle] Attempting to recover - retry ${retryCount}/3`);\n\n try {\n const client = await pool.connect();\n try {\n // Test the connection with timeout\n await Promise.race([\n client.query(\"SELECT 1\"),\n new Promise((_, reject) => setTimeout(() => reject(new Error(\"Query timeout\")), 5000)),\n ]);\n console.log(\"[Drizzle] Successfully recovered connection\");\n retryCount = 0;\n } finally {\n client.release();\n }\n } catch (retryError) {\n console.error(`[Drizzle] Recovery attempt ${retryCount} failed:`, retryError);\n await sleep(5000 * 2 ** (retryCount - 1));\n } finally {\n isRetrying = false;\n }\n } else {\n console.error(\"[Drizzle] Max retries exceeded - pool is in an error state\");\n pool.emit(\"permanent-failure\", err);\n }\n };\n\n const handleConnect = (client: pg.PoolClient) => {\n // Only add error handler if not already added (prevent memory leaks)\n if (!clientErrorHandlers.has(client)) {\n clientErrorHandlers.add(client);\n client.on(\"error\", (err: Error) => {\n console.error(\"[Drizzle] Database client error:\", err);\n });\n }\n retryCount = 0;\n isRetrying = false;\n };\n\n pool.on(\"error\", handlePoolError);\n pool.on(\"connect\", handleConnect);\n}\n\n/**\n * Creates a PostgreSQL connection pool with error handling and retry mechanisms\n *\n * @param databaseUrl - The PostgreSQL connection URL\n * @returns A configured PostgreSQL connection pool\n * @throws Will throw an error if called from browser runtime\n * @example\n * import { createPostgresPool } from '@settlemint/sdk-hasura';\n *\n * const pool = createPostgresPool(process.env.SETTLEMINT_HASURA_DATABASE_URL);\n *\n * // The pool will automatically handle connection errors and retries\n * const client = await pool.connect();\n * try {\n * const result = await client.query('SELECT NOW()');\n * console.log(result.rows[0]);\n * } finally {\n * client.release();\n * }\n */\nexport function createPostgresPool(databaseUrl: string) {\n if (!databaseUrl?.trim()) {\n throw new Error(\"Database URL is required\");\n }\n\n if (!runsOnServer) {\n throw new Error(\"Drizzle client can only be created on the server side\");\n }\n\n const pool = new pg.Pool({\n connectionString: databaseUrl,\n max: 10,\n idleTimeoutMillis: 30000,\n connectionTimeoutMillis: 5000,\n maxLifetimeSeconds: 0,\n });\n\n setupErrorHandling(pool);\n\n return pool;\n}\n"],"mappings":";;;;;;;;;;;AAmBA,MAAM,QAAQ,CAACA,OAAe,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG;;;;;;AAO9E,SAAS,mBAAmBC,MAAe;CACzC,IAAI,aAAa;CACjB,IAAI,aAAa;CACjB,MAAM,sBAAsB,IAAI;CAEhC,MAAM,kBAAkB,OAAOC,QAAe;EAC5C,QAAQ,MAAM,kCAAkC,IAAI;AAGpD,MAAI,YAAY;GACd,QAAQ,IAAI,mDAAmD;AAC/D;EACD;AAED,MAAI,aAAa,GAAG;GAClB,aAAa;GACb;GACA,QAAQ,IAAI,CAAC,wCAAwC,EAAE,WAAW,EAAE,CAAC,CAAC;AAEtE,OAAI;IACF,MAAM,SAAS,MAAM,KAAK,SAAS;AACnC,QAAI;KAEF,MAAM,QAAQ,KAAK,CACjB,OAAO,MAAM,WAAW,EACxB,IAAI,QAAQ,CAAC,GAAG,WAAW,WAAW,MAAM,OAAO,IAAI,MAAM,iBAAiB,EAAE,IAAK,CACtF,EAAC;KACF,QAAQ,IAAI,8CAA8C;KAC1D,aAAa;IACd,UAAS;KACR,OAAO,SAAS;IACjB;GACF,SAAQ,YAAY;IACnB,QAAQ,MAAM,CAAC,2BAA2B,EAAE,WAAW,QAAQ,CAAC,EAAE,WAAW;IAC7E,MAAM,MAAM,MAAO,MAAM,aAAa,GAAG;GAC1C,UAAS;IACR,aAAa;GACd;EACF,OAAM;GACL,QAAQ,MAAM,6DAA6D;GAC3E,KAAK,KAAK,qBAAqB,IAAI;EACpC;CACF;CAED,MAAM,gBAAgB,CAACC,WAA0B;AAE/C,MAAI,CAAC,oBAAoB,IAAI,OAAO,EAAE;GACpC,oBAAoB,IAAI,OAAO;GAC/B,OAAO,GAAG,SAAS,CAACD,QAAe;IACjC,QAAQ,MAAM,oCAAoC,IAAI;GACvD,EAAC;EACH;EACD,aAAa;EACb,aAAa;CACd;CAED,KAAK,GAAG,SAAS,gBAAgB;CACjC,KAAK,GAAG,WAAW,cAAc;AAClC;;;;;;;;;;;;;;;;;;;;;AAsBD,SAAgB,mBAAmBE,aAAqB;AACtD,KAAI,CAAC,aAAa,MAAM,EAAE;AACxB,QAAM,IAAI,MAAM;CACjB;AAED,KAAI,CAAC,cAAc;AACjB,QAAM,IAAI,MAAM;CACjB;CAED,MAAM,OAAO,IAAI,GAAG,KAAK;EACvB,kBAAkB;EAClB,KAAK;EACL,mBAAmB;EACnB,yBAAyB;EACzB,oBAAoB;CACrB;CAED,mBAAmB,KAAK;AAExB,QAAO;AACR"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@settlemint/sdk-hasura",
|
|
3
3
|
"description": "Hasura and PostgreSQL integration module for SettleMint SDK, enabling database operations and GraphQL queries",
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.13-maina48700be",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"gql.tada": "^1",
|
|
69
|
-
"@settlemint/sdk-utils": "2.5.
|
|
69
|
+
"@settlemint/sdk-utils": "2.5.13-maina48700be",
|
|
70
70
|
"graphql-request": "^7",
|
|
71
71
|
"zod": "^4",
|
|
72
72
|
"drizzle-orm": "^0.44.0",
|