@agentuity/drizzle 1.0.3 → 1.0.4
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/dist/postgres.d.ts +9 -0
- package/dist/postgres.d.ts.map +1 -1
- package/dist/postgres.js +34 -21
- package/dist/postgres.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/postgres.ts +40 -24
- package/src/types.ts +7 -0
package/dist/postgres.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
import { type PostgresConfig } from '@agentuity/postgres';
|
|
1
2
|
import type { PostgresDrizzleConfig, PostgresDrizzle } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the PostgreSQL client configuration from Drizzle config options.
|
|
5
|
+
*
|
|
6
|
+
* URL priority chain: `connection.url` > `url` > `connectionString` > `process.env.DATABASE_URL`
|
|
7
|
+
*
|
|
8
|
+
* @internal Exported for testing — not part of the public package API.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolvePostgresClientConfig<TSchema extends Record<string, unknown> = Record<string, never>>(config?: PostgresDrizzleConfig<TSchema>): PostgresConfig;
|
|
2
11
|
/**
|
|
3
12
|
* Creates a Drizzle ORM instance with a resilient PostgreSQL connection.
|
|
4
13
|
*
|
package/dist/postgres.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AACA,OAAO,EAAyC,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjG,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAC1C,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC9D,MAAM,CAAC,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG,cAAc,CA0BzD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,qBAAqB,CACpC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC9D,MAAM,CAAC,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CA+BnE"}
|
package/dist/postgres.js
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
import { drizzle } from 'drizzle-orm/bun-sql';
|
|
2
2
|
import { postgres } from '@agentuity/postgres';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the PostgreSQL client configuration from Drizzle config options.
|
|
5
|
+
*
|
|
6
|
+
* URL priority chain: `connection.url` > `url` > `connectionString` > `process.env.DATABASE_URL`
|
|
7
|
+
*
|
|
8
|
+
* @internal Exported for testing — not part of the public package API.
|
|
9
|
+
*/
|
|
10
|
+
export function resolvePostgresClientConfig(config) {
|
|
11
|
+
// Clone the connection config to avoid mutating the caller's object
|
|
12
|
+
const clientConfig = config?.connection ? { ...config.connection } : {};
|
|
13
|
+
// Resolve URL using priority chain
|
|
14
|
+
if (!clientConfig.url) {
|
|
15
|
+
if (config?.url) {
|
|
16
|
+
clientConfig.url = config.url;
|
|
17
|
+
}
|
|
18
|
+
else if (config?.connectionString) {
|
|
19
|
+
clientConfig.url = config.connectionString;
|
|
20
|
+
}
|
|
21
|
+
else if (process.env.DATABASE_URL) {
|
|
22
|
+
clientConfig.url = process.env.DATABASE_URL;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Add reconnection configuration
|
|
26
|
+
if (config?.reconnect) {
|
|
27
|
+
clientConfig.reconnect = config.reconnect;
|
|
28
|
+
}
|
|
29
|
+
// Add callbacks
|
|
30
|
+
if (config?.onReconnected) {
|
|
31
|
+
clientConfig.onreconnected = config.onReconnected;
|
|
32
|
+
}
|
|
33
|
+
return clientConfig;
|
|
34
|
+
}
|
|
3
35
|
/**
|
|
4
36
|
* Creates a Drizzle ORM instance with a resilient PostgreSQL connection.
|
|
5
37
|
*
|
|
@@ -45,27 +77,8 @@ import { postgres } from '@agentuity/postgres';
|
|
|
45
77
|
* ```
|
|
46
78
|
*/
|
|
47
79
|
export function createPostgresDrizzle(config) {
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
const clientConfig = config?.connection ? { ...config.connection } : {};
|
|
51
|
-
// Use connectionString only if no url is already present on the cloned config
|
|
52
|
-
// This ensures connection (when provided) keeps precedence over connectionString
|
|
53
|
-
if (!clientConfig.url) {
|
|
54
|
-
if (config?.connectionString) {
|
|
55
|
-
clientConfig.url = config.connectionString;
|
|
56
|
-
}
|
|
57
|
-
else if (process.env.DATABASE_URL) {
|
|
58
|
-
clientConfig.url = process.env.DATABASE_URL;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// Add reconnection configuration
|
|
62
|
-
if (config?.reconnect) {
|
|
63
|
-
clientConfig.reconnect = config.reconnect;
|
|
64
|
-
}
|
|
65
|
-
// Add callbacks
|
|
66
|
-
if (config?.onReconnected) {
|
|
67
|
-
clientConfig.onreconnected = config.onReconnected;
|
|
68
|
-
}
|
|
80
|
+
// Resolve the postgres client configuration
|
|
81
|
+
const clientConfig = resolvePostgresClientConfig(config);
|
|
69
82
|
// Create the postgres client
|
|
70
83
|
const client = postgres(clientConfig);
|
|
71
84
|
// Wait for connection before calling onConnect callback
|
package/dist/postgres.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE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AY,GAAG,2BAA2B,CAAC,MAAM,CAAC,CAAC;IAEzD,6BAA6B;IAC7B,MAAM,MAAM,GAA2B,QAAQ,CAAC,YAAY,CAAC,CAAC;IAE9D,wDAAwD;IACxD,8EAA8E;IAC9E,IAAI,MAAM,EAAE,SAAS,EAAE,CAAC;QACvB,MAAM,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YACpC,MAAM,CAAC,SAAU,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,gEAAgE;IAChE,4EAA4E;IAC5E,MAAM,EAAE,GAAG,OAAO,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC,GAAG;QAClB,MAAM,EAAE,MAAM,EAAE,MAAM;QACtB,MAAM,EAAE,MAAM,EAAE,MAAM;KACtB,CAAC,CAAC;IAEH,gCAAgC;IAChC,OAAO;QACN,EAAE;QACF,MAAM;QACN,KAAK,EAAE,KAAK,IAAI,EAAE;YACjB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ import type { PostgresConfig, ReconnectConfig, CallablePostgresClient } from '@a
|
|
|
7
7
|
* @template TSchema - The Drizzle schema type
|
|
8
8
|
*/
|
|
9
9
|
export interface PostgresDrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> {
|
|
10
|
+
/**
|
|
11
|
+
* PostgreSQL connection URL.
|
|
12
|
+
* Shorthand for `connection.url`.
|
|
13
|
+
* If not provided, falls back to `connectionString`, then `process.env.DATABASE_URL`.
|
|
14
|
+
*/
|
|
15
|
+
url?: string;
|
|
10
16
|
/**
|
|
11
17
|
* PostgreSQL connection string.
|
|
12
18
|
* If not provided, uses `process.env.DATABASE_URL`.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names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AE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAEnG;;;;GAIG;AACH,MAAM,WAAW,qBAAqB,CACrC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAE/D;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAEjC;;OAEG;IACH,SAAS,CAAC,EAAE,eAAe,CAAC;IAE5B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IAEvB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAC/F;;OAEG;IACH,EAAE,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IAE5B;;;OAGG;IACH,MAAM,EAAE,sBAAsB,CAAC;IAE/B;;OAEG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentuity/drizzle",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Agentuity employees and contributors",
|
|
6
6
|
"type": "module",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"prepublishOnly": "bun run clean && bun run build"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@agentuity/postgres": "1.0.
|
|
34
|
+
"@agentuity/postgres": "1.0.4",
|
|
35
35
|
"drizzle-orm": "^0.45.0",
|
|
36
36
|
"better-auth": "^1.4.9"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@agentuity/test-utils": "1.0.
|
|
39
|
+
"@agentuity/test-utils": "1.0.4",
|
|
40
40
|
"@types/bun": "latest",
|
|
41
41
|
"bun-types": "latest",
|
|
42
42
|
"typescript": "^5.9.0"
|
package/src/postgres.ts
CHANGED
|
@@ -1,7 +1,44 @@
|
|
|
1
1
|
import { drizzle } from 'drizzle-orm/bun-sql';
|
|
2
|
-
import { postgres, type CallablePostgresClient } from '@agentuity/postgres';
|
|
2
|
+
import { postgres, type CallablePostgresClient, type PostgresConfig } from '@agentuity/postgres';
|
|
3
3
|
import type { PostgresDrizzleConfig, PostgresDrizzle } from './types';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the PostgreSQL client configuration from Drizzle config options.
|
|
7
|
+
*
|
|
8
|
+
* URL priority chain: `connection.url` > `url` > `connectionString` > `process.env.DATABASE_URL`
|
|
9
|
+
*
|
|
10
|
+
* @internal Exported for testing — not part of the public package API.
|
|
11
|
+
*/
|
|
12
|
+
export function resolvePostgresClientConfig<
|
|
13
|
+
TSchema extends Record<string, unknown> = Record<string, never>,
|
|
14
|
+
>(config?: PostgresDrizzleConfig<TSchema>): PostgresConfig {
|
|
15
|
+
// Clone the connection config to avoid mutating the caller's object
|
|
16
|
+
const clientConfig: PostgresConfig = config?.connection ? { ...config.connection } : {};
|
|
17
|
+
|
|
18
|
+
// Resolve URL using priority chain
|
|
19
|
+
if (!clientConfig.url) {
|
|
20
|
+
if (config?.url) {
|
|
21
|
+
clientConfig.url = config.url;
|
|
22
|
+
} else if (config?.connectionString) {
|
|
23
|
+
clientConfig.url = config.connectionString;
|
|
24
|
+
} else if (process.env.DATABASE_URL) {
|
|
25
|
+
clientConfig.url = process.env.DATABASE_URL;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Add reconnection configuration
|
|
30
|
+
if (config?.reconnect) {
|
|
31
|
+
clientConfig.reconnect = config.reconnect;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Add callbacks
|
|
35
|
+
if (config?.onReconnected) {
|
|
36
|
+
clientConfig.onreconnected = config.onReconnected;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return clientConfig;
|
|
40
|
+
}
|
|
41
|
+
|
|
5
42
|
/**
|
|
6
43
|
* Creates a Drizzle ORM instance with a resilient PostgreSQL connection.
|
|
7
44
|
*
|
|
@@ -49,29 +86,8 @@ import type { PostgresDrizzleConfig, PostgresDrizzle } from './types';
|
|
|
49
86
|
export function createPostgresDrizzle<
|
|
50
87
|
TSchema extends Record<string, unknown> = Record<string, never>,
|
|
51
88
|
>(config?: PostgresDrizzleConfig<TSchema>): PostgresDrizzle<TSchema> {
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
const clientConfig = config?.connection ? { ...config.connection } : {};
|
|
55
|
-
|
|
56
|
-
// Use connectionString only if no url is already present on the cloned config
|
|
57
|
-
// This ensures connection (when provided) keeps precedence over connectionString
|
|
58
|
-
if (!clientConfig.url) {
|
|
59
|
-
if (config?.connectionString) {
|
|
60
|
-
clientConfig.url = config.connectionString;
|
|
61
|
-
} else if (process.env.DATABASE_URL) {
|
|
62
|
-
clientConfig.url = process.env.DATABASE_URL;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Add reconnection configuration
|
|
67
|
-
if (config?.reconnect) {
|
|
68
|
-
clientConfig.reconnect = config.reconnect;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Add callbacks
|
|
72
|
-
if (config?.onReconnected) {
|
|
73
|
-
clientConfig.onreconnected = config.onReconnected;
|
|
74
|
-
}
|
|
89
|
+
// Resolve the postgres client configuration
|
|
90
|
+
const clientConfig = resolvePostgresClientConfig(config);
|
|
75
91
|
|
|
76
92
|
// Create the postgres client
|
|
77
93
|
const client: CallablePostgresClient = postgres(clientConfig);
|
package/src/types.ts
CHANGED
|
@@ -10,6 +10,13 @@ import type { PostgresConfig, ReconnectConfig, CallablePostgresClient } from '@a
|
|
|
10
10
|
export interface PostgresDrizzleConfig<
|
|
11
11
|
TSchema extends Record<string, unknown> = Record<string, never>,
|
|
12
12
|
> {
|
|
13
|
+
/**
|
|
14
|
+
* PostgreSQL connection URL.
|
|
15
|
+
* Shorthand for `connection.url`.
|
|
16
|
+
* If not provided, falls back to `connectionString`, then `process.env.DATABASE_URL`.
|
|
17
|
+
*/
|
|
18
|
+
url?: string;
|
|
19
|
+
|
|
13
20
|
/**
|
|
14
21
|
* PostgreSQL connection string.
|
|
15
22
|
* If not provided, uses `process.env.DATABASE_URL`.
|