@agentuity/postgres 2.0.8 → 2.0.9-v3.48d5810

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.
@@ -7,8 +7,8 @@
7
7
  * The runtime can use `shutdownAll()` to close all registered clients/pools
8
8
  * during graceful shutdown.
9
9
  *
10
- * When @agentuity/runtime is available, this module automatically registers
11
- * a shutdown hook so all postgres clients/pools are closed during graceful shutdown.
10
+ * Automatically registers process shutdown hooks (beforeExit, SIGTERM, SIGINT)
11
+ * so all postgres clients/pools are closed during graceful shutdown.
12
12
  */
13
13
  /**
14
14
  * Common interface for registrable PostgreSQL connections.
package/dist/registry.js CHANGED
@@ -7,8 +7,8 @@
7
7
  * The runtime can use `shutdownAll()` to close all registered clients/pools
8
8
  * during graceful shutdown.
9
9
  *
10
- * When @agentuity/runtime is available, this module automatically registers
11
- * a shutdown hook so all postgres clients/pools are closed during graceful shutdown.
10
+ * Automatically registers process shutdown hooks (beforeExit, SIGTERM, SIGINT)
11
+ * so all postgres clients/pools are closed during graceful shutdown.
12
12
  */
13
13
  /**
14
14
  * Symbol used to store the registry in globalThis to avoid conflicts.
@@ -141,35 +141,25 @@ export function hasActiveClients() {
141
141
  return false;
142
142
  }
143
143
  /**
144
- * Attempts to register a shutdown hook with @agentuity/runtime if available.
145
- * This is called automatically when the first client is registered.
144
+ * Registers a process shutdown hook to gracefully close all connections.
145
+ * Uses standard Node.js/Bun process events instead of framework-specific hooks.
146
146
  *
147
147
  * @internal
148
148
  */
149
- function tryRegisterRuntimeHook() {
149
+ function registerProcessShutdownHook() {
150
150
  const global = globalThis;
151
- // Only try once
151
+ // Only register once
152
152
  if (global[RUNTIME_HOOK_REGISTERED]) {
153
153
  return;
154
154
  }
155
155
  global[RUNTIME_HOOK_REGISTERED] = true;
156
- // Try to dynamically import the runtime and register our shutdown hook
157
- // This is done asynchronously to avoid blocking client creation
158
- // and to handle the case where runtime is not available
159
- // Using Function constructor to avoid TypeScript trying to resolve the module at build time
160
- const dynamicImport = new Function('specifier', 'return import(specifier)');
161
- dynamicImport('@agentuity/runtime')
162
- .then((runtime) => {
163
- if (typeof runtime.registerShutdownHook === 'function') {
164
- runtime.registerShutdownHook(async () => {
165
- await shutdownAll(5000); // 5 second timeout for graceful shutdown
166
- });
167
- }
168
- })
169
- .catch(() => {
170
- // Runtime not available - that's fine, user can call shutdownAll manually
171
- });
156
+ const shutdown = () => {
157
+ shutdownAll(5000).catch(() => { });
158
+ };
159
+ process.on('beforeExit', shutdown);
160
+ process.on('SIGTERM', shutdown);
161
+ process.on('SIGINT', shutdown);
172
162
  }
173
- // Try to register with runtime when this module is first loaded
174
- tryRegisterRuntimeHook();
163
+ // Register shutdown hook when this module is first loaded
164
+ registerProcessShutdownHook();
175
165
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAuBH;;GAEG;AACH,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAEhE;;GAEG;AACH,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;AAE1F;;GAEG;AACH,SAAS,WAAW;IACnB,MAAM,MAAM,GAAG,UAA8C,CAAC;IAC9D,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3B,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,UAAuB;IACrD,WAAW,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAuB;IACvD,WAAW,EAAE,CAAC,MAAM,CA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d,CAAC;AAED;;;;;GAKG;AACH,SAAS,2BAA2B;IACnC,MAAM,MAAM,GAAG,UAAqC,CAAC;IAErD,qBAAqB;IACrB,IAAI,MAAM,CAAC,uBAAuB,CAAC,EAAE,CAAC;QACrC,OAAO;IACR,CAAC;IACD,MAAM,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC;IAEvC,MAAM,QAAQ,GAAG,GAAG,EAAE;QACrB,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,0DAA0D;AAC1D,2BAA2B,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,58 +1,54 @@
1
1
  {
2
- "name": "@agentuity/postgres",
3
- "version": "2.0.8",
4
- "license": "Apache-2.0",
5
- "author": "Agentuity employees and contributors",
6
- "type": "module",
7
- "description": "Resilient PostgreSQL client with automatic reconnection for Agentuity projects",
8
- "main": "./dist/index.js",
9
- "module": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
11
- "files": [
12
- "AGENTS.md",
13
- "README.md",
14
- "src",
15
- "dist"
16
- ],
17
- "exports": {
18
- ".": "./dist/index.js"
19
- },
20
- "typesVersions": {
21
- "*": {
22
- ".": [
23
- "./dist/index.d.ts"
24
- ]
25
- }
26
- },
27
- "scripts": {
28
- "clean": "rm -rf dist tsconfig.tsbuildinfo",
29
- "build": "bunx tsc --build --force",
30
- "typecheck": "bunx tsc --noEmit",
31
- "prepublishOnly": "bun run clean && bun run build"
32
- },
33
- "dependencies": {
34
- "@agentuity/core": "2.0.8",
35
- "pg": "^8.13.1"
36
- },
37
- "peerDependencies": {
38
- "@agentuity/runtime": "2.0.8"
39
- },
40
- "peerDependenciesMeta": {
41
- "@agentuity/runtime": {
42
- "optional": true
43
- }
44
- },
45
- "devDependencies": {
46
- "@agentuity/runtime": "2.0.8",
47
- "@agentuity/test-utils": "2.0.8",
48
- "@types/bun": "latest",
49
- "@types/pg": "^8.11.14",
50
- "bun-types": "latest",
51
- "kysely": "^0.27.6",
52
- "typescript": "^5.9.0"
53
- },
54
- "publishConfig": {
55
- "access": "public"
56
- },
57
- "sideEffects": false
2
+ "name": "@agentuity/postgres",
3
+ "version": "2.0.9-v3.48d5810",
4
+ "license": "Apache-2.0",
5
+ "author": "Agentuity employees and contributors",
6
+ "type": "module",
7
+ "description": "Resilient PostgreSQL client with automatic reconnection for Agentuity projects",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "AGENTS.md",
13
+ "README.md",
14
+ "src",
15
+ "dist"
16
+ ],
17
+ "exports": {
18
+ ".": "./dist/index.js"
19
+ },
20
+ "typesVersions": {
21
+ "*": {
22
+ ".": [
23
+ "./dist/index.d.ts"
24
+ ]
25
+ }
26
+ },
27
+ "scripts": {
28
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
29
+ "build": "bunx tsc --build --force",
30
+ "typecheck": "bunx tsc --noEmit",
31
+ "prepublishOnly": "bun run clean && bun run build"
32
+ },
33
+ "dependencies": {
34
+ "@agentuity/core": "2.0.9-v3.48d5810",
35
+ "pg": "^8.13.1"
36
+ },
37
+ "devDependencies": {
38
+ "@agentuity/test-utils": "2.0.9-v3.48d5810",
39
+ "@types/bun": "latest",
40
+ "@types/pg": "^8.11.14",
41
+ "bun-types": "latest",
42
+ "kysely": "^0.27.6",
43
+ "typescript": "^5.9.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "sideEffects": false,
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/agentuity/sdk.git",
52
+ "directory": "packages/postgres"
53
+ }
58
54
  }
package/src/registry.ts CHANGED
@@ -7,8 +7,8 @@
7
7
  * The runtime can use `shutdownAll()` to close all registered clients/pools
8
8
  * during graceful shutdown.
9
9
  *
10
- * When @agentuity/runtime is available, this module automatically registers
11
- * a shutdown hook so all postgres clients/pools are closed during graceful shutdown.
10
+ * Automatically registers process shutdown hooks (beforeExit, SIGTERM, SIGINT)
11
+ * so all postgres clients/pools are closed during graceful shutdown.
12
12
  */
13
13
 
14
14
  /**
@@ -174,40 +174,28 @@ export function hasActiveClients(): boolean {
174
174
  }
175
175
 
176
176
  /**
177
- * Attempts to register a shutdown hook with @agentuity/runtime if available.
178
- * This is called automatically when the first client is registered.
177
+ * Registers a process shutdown hook to gracefully close all connections.
178
+ * Uses standard Node.js/Bun process events instead of framework-specific hooks.
179
179
  *
180
180
  * @internal
181
181
  */
182
- function tryRegisterRuntimeHook(): void {
182
+ function registerProcessShutdownHook(): void {
183
183
  const global = globalThis as Record<symbol, boolean>;
184
184
 
185
- // Only try once
185
+ // Only register once
186
186
  if (global[RUNTIME_HOOK_REGISTERED]) {
187
187
  return;
188
188
  }
189
189
  global[RUNTIME_HOOK_REGISTERED] = true;
190
190
 
191
- // Try to dynamically import the runtime and register our shutdown hook
192
- // This is done asynchronously to avoid blocking client creation
193
- // and to handle the case where runtime is not available
194
- // Using Function constructor to avoid TypeScript trying to resolve the module at build time
195
- const dynamicImport = new Function('specifier', 'return import(specifier)') as (
196
- specifier: string
197
- ) => Promise<{ registerShutdownHook?: (hook: () => Promise<void> | void) => void }>;
198
-
199
- dynamicImport('@agentuity/runtime')
200
- .then((runtime) => {
201
- if (typeof runtime.registerShutdownHook === 'function') {
202
- runtime.registerShutdownHook(async () => {
203
- await shutdownAll(5000); // 5 second timeout for graceful shutdown
204
- });
205
- }
206
- })
207
- .catch(() => {
208
- // Runtime not available - that's fine, user can call shutdownAll manually
209
- });
191
+ const shutdown = () => {
192
+ shutdownAll(5000).catch(() => {});
193
+ };
194
+
195
+ process.on('beforeExit', shutdown);
196
+ process.on('SIGTERM', shutdown);
197
+ process.on('SIGINT', shutdown);
210
198
  }
211
199
 
212
- // Try to register with runtime when this module is first loaded
213
- tryRegisterRuntimeHook();
200
+ // Register shutdown hook when this module is first loaded
201
+ registerProcessShutdownHook();