@agentuity/drizzle 1.0.4 → 1.0.6

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/index.d.ts CHANGED
@@ -33,7 +33,7 @@
33
33
  export { createPostgresDrizzle } from './postgres';
34
34
  export type { PostgresDrizzleConfig, PostgresDrizzle } from './types';
35
35
  export { postgres, PostgresClient, type CallablePostgresClient, type PostgresConfig, type ReconnectConfig, type ConnectionStats, type TLSConfig, type TransactionOptions, type ReserveOptions, } from '@agentuity/postgres';
36
- export { sql, eq, and, or, not, desc, asc, gt, gte, lt, lte, ne, isNull, isNotNull, inArray, notInArray, between, like, ilike, } from 'drizzle-orm';
37
- export { pgTable, pgSchema, pgEnum, bigint, bigserial, boolean, char, cidr, customType, date, doublePrecision, inet, integer, interval, json, jsonb, macaddr, macaddr8, numeric, real, serial, smallint, smallserial, text, time, timestamp, uuid, varchar, primaryKey, foreignKey, unique, uniqueIndex, index, check, } from 'drizzle-orm/pg-core';
36
+ export { sql, eq, and, or, not, desc, asc, gt, gte, lt, lte, ne, isNull, isNotNull, inArray, notInArray, between, like, ilike, relations, } from 'drizzle-orm';
37
+ export { pgTable, pgSchema, pgEnum, pgView, bigint, bigserial, boolean, vector, char, cidr, customType, date, doublePrecision, inet, integer, interval, json, jsonb, macaddr, macaddr8, numeric, real, serial, smallint, smallserial, text, time, timestamp, uuid, varchar, primaryKey, foreignKey, unique, uniqueIndex, index, check, } from 'drizzle-orm/pg-core';
38
38
  export { drizzleAdapter } from 'better-auth/adapters/drizzle';
39
39
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,S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nB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,cAAc,GACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACN,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,IAAI,EACJ,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,MAAM,EACN,SAAS,EACT,OAAO,EACP,UAAU,EACV,OAAO,EACP,IAAI,EACJ,KAAK,EACL,SAAS,GACT,MAAM,aAAa,CAAC;AAGrB,OAAO,EACN,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EAEN,MAAM,EACN,SAAS,EACT,OAAO,EACP,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,eAAe,EACf,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,OAAO,EAEP,UAAU,EACV,UAAU,EACV,MAAM,EACN,WAAW,EACX,KAAK,EACL,KAAK,GACL,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
package/dist/index.js CHANGED
@@ -35,11 +35,11 @@ export { createPostgresDrizzle } from './postgres';
35
35
  // Re-export from @agentuity/postgres for convenience
36
36
  export { postgres, PostgresClient, } from '@agentuity/postgres';
37
37
  // Re-export common Drizzle utilities for convenience
38
- export { sql, eq, and, or, not, desc, asc, gt, gte, lt, lte, ne, isNull, isNotNull, inArray, notInArray, between, like, ilike, } from 'drizzle-orm';
38
+ export { sql, eq, and, or, not, desc, asc, gt, gte, lt, lte, ne, isNull, isNotNull, inArray, notInArray, between, like, ilike, relations, } from 'drizzle-orm';
39
39
  // Re-export pg-core table and column definitions
40
- export { pgTable, pgSchema, pgEnum,
40
+ export { pgTable, pgSchema, pgEnum, pgView,
41
41
  // Column types
42
- bigint, bigserial, boolean, char, cidr, customType, date, doublePrecision, inet, integer, interval, json, jsonb, macaddr, macaddr8, numeric, real, serial, smallint, smallserial, text, time, timestamp, uuid, varchar,
42
+ bigint, bigserial, boolean, vector, char, cidr, customType, date, doublePrecision, inet, integer, interval, json, jsonb, macaddr, macaddr8, numeric, real, serial, smallint, smallserial, text, time, timestamp, uuid, varchar,
43
43
  // Constraints and indexes
44
44
  primaryKey, foreignKey, unique, uniqueIndex, index, check, } from 'drizzle-orm/pg-core';
45
45
  // Re-export better-auth drizzle adapter for use with @agentuity/auth
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,wBAAwB;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAKnD,qDAAqD;AACrD,OAAO,EACN,QAAQ,EACR,cAAc,GAQd,MAAM,qBAAqB,CAAC;AAE7B,qDAAqD;AACrD,OAAO,EACN,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,IAAI,EACJ,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,MAAM,EACN,SAAS,EACT,OAAO,EACP,UAAU,EACV,OAAO,EACP,IAAI,EACJ,KAAK,GACL,MAAM,aAAa,CAAC;AAErB,iDAAiD;AACjD,OAAO,EACN,OAAO,EACP,QAAQ,EACR,MAAM;AACN,eAAe;AACf,MAAM,EACN,SAAS,EACT,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,eAAe,EACf,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,OAAO;AACP,0BAA0B;AAC1B,UAAU,EACV,UAAU,EACV,MAAM,EACN,WAAW,EACX,KAAK,EACL,KAAK,GACL,MAAM,qBAAqB,CAAC;AAE7B,qEAAqE;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,wBAAwB;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAKnD,qDAAqD;AACrD,OAAO,EACN,QAAQ,EACR,cAAc,GAQd,MAAM,qBAAqB,CAAC;AAE7B,qDAAqD;AACrD,OAAO,EACN,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,IAAI,EACJ,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,MAAM,EACN,SAAS,EACT,OAAO,EACP,UAAU,EACV,OAAO,EACP,IAAI,EACJ,KAAK,EACL,SAAS,GACT,MAAM,aAAa,CAAC;AAErB,iDAAiD;AACjD,OAAO,EACN,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM;AACN,eAAe;AACf,MAAM,EACN,SAAS,EACT,OAAO,EACP,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,eAAe,EACf,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,OAAO;AACP,0BAA0B;AAC1B,UAAU,EACV,UAAU,EACV,MAAM,EACN,WAAW,EACX,KAAK,EACL,KAAK,GACL,MAAM,qBAAqB,CAAC;AAE7B,qEAAqE;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
@@ -1,4 +1,5 @@
1
- import { type PostgresConfig } from '@agentuity/postgres';
1
+ import { SQL as BunSQL } from 'bun';
2
+ import { type CallablePostgresClient, type PostgresConfig } from '@agentuity/postgres';
2
3
  import type { PostgresDrizzleConfig, PostgresDrizzle } from './types';
3
4
  /**
4
5
  * Resolves the PostgreSQL client configuration from Drizzle config options.
@@ -8,6 +9,17 @@ import type { PostgresDrizzleConfig, PostgresDrizzle } from './types';
8
9
  * @internal Exported for testing — not part of the public package API.
9
10
  */
10
11
  export declare function resolvePostgresClientConfig<TSchema extends Record<string, unknown> = Record<string, never>>(config?: PostgresDrizzleConfig<TSchema>): PostgresConfig;
12
+ /**
13
+ * Creates a dynamic SQL proxy that always delegates to the PostgresClient's
14
+ * current raw connection. This ensures that after automatic reconnection,
15
+ * Drizzle ORM uses the fresh connection instead of a stale reference.
16
+ *
17
+ * The proxy also wraps `unsafe()` calls with the client's retry logic,
18
+ * providing automatic retry on transient connection errors.
19
+ *
20
+ * @internal Exported for testing — not part of the public package API.
21
+ */
22
+ export declare function createResilientSQLProxy(client: CallablePostgresClient): InstanceType<typeof BunSQL>;
11
23
  /**
12
24
  * Creates a Drizzle ORM instance with a resilient PostgreSQL connection.
13
25
  *
@@ -1 +1 @@
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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CHANGED
@@ -32,6 +32,50 @@ export function resolvePostgresClientConfig(config) {
32
32
  }
33
33
  return clientConfig;
34
34
  }
35
+ /**
36
+ * Creates a dynamic SQL proxy that always delegates to the PostgresClient's
37
+ * current raw connection. This ensures that after automatic reconnection,
38
+ * Drizzle ORM uses the fresh connection instead of a stale reference.
39
+ *
40
+ * The proxy also wraps `unsafe()` calls with the client's retry logic,
41
+ * providing automatic retry on transient connection errors.
42
+ *
43
+ * @internal Exported for testing — not part of the public package API.
44
+ */
45
+ export function createResilientSQLProxy(client) {
46
+ return new Proxy({}, {
47
+ get(_target, prop, _receiver) {
48
+ // Always resolve from the CURRENT raw connection (changes after reconnect)
49
+ const raw = client.raw;
50
+ if (prop === 'unsafe') {
51
+ // Wrap unsafe() with retry logic for resilient queries.
52
+ // Returns a thenable that also supports .values() chaining,
53
+ // matching the SQLQuery interface that Drizzle expects:
54
+ // client.unsafe(query, params) → Promise<rows>
55
+ // client.unsafe(query, params).values() → Promise<rows>
56
+ return (query, params) => {
57
+ const makeExecutor = (useValues) => client.executeWithRetry(async () => {
58
+ // Re-resolve raw inside retry to get post-reconnect instance
59
+ const currentRaw = client.raw;
60
+ const q = currentRaw.unsafe(query, params);
61
+ return useValues ? q.values() : q;
62
+ });
63
+ // Return a thenable with .values() to match Bun's SQLQuery interface
64
+ const result = makeExecutor(false);
65
+ return Object.assign(result, {
66
+ values: () => makeExecutor(true),
67
+ });
68
+ };
69
+ }
70
+ const value = raw[prop];
71
+ if (typeof value === 'function') {
72
+ // Bind to raw so `this` is correct inside begin(), savepoint(), etc.
73
+ return value.bind(raw);
74
+ }
75
+ return value;
76
+ },
77
+ });
78
+ }
35
79
  /**
36
80
  * Creates a Drizzle ORM instance with a resilient PostgreSQL connection.
37
81
  *
@@ -88,10 +132,14 @@ export function createPostgresDrizzle(config) {
88
132
  config.onConnect();
89
133
  });
90
134
  }
91
- // Create Drizzle instance using the client's raw SQL connection
92
- // The bun-sql driver accepts a client that implements the Bun.SQL interface
135
+ // Create a resilient proxy that always delegates to the current raw SQL
136
+ // connection. This ensures that after reconnection, Drizzle automatically
137
+ // uses the new connection instead of the stale one.
138
+ const resilientSQL = createResilientSQLProxy(client);
139
+ // Create Drizzle instance using the resilient proxy instead of a static
140
+ // reference to client.raw, which would become stale after reconnection.
93
141
  const db = drizzle({
94
- client: client.raw,
142
+ client: resilientSQL,
95
143
  schema: config?.schema,
96
144
  logger: config?.logger,
97
145
  });
@@ -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,QAAQ,EAAoD,MAAM,qBAAqB,CAAC;AAGjG;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CAEzC,MAAuC;IACxC,oEAAoE;IACpE,MAAM,YAAY,GAAmB,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAExF,mCAAmC;IACnC,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC;YACjB,YAAY,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QAC/B,CAAC;aAAM,IAAI,MAAM,EAAE,gBAAgB,EAAE,CAAC;YACrC,YAAY,CAAC,GAAG,GAAG,MAAM,CAAC,gBAAgB,CAAC;QAC5C,CAAC;aAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;YACrC,YAAY,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;QAC7C,CAAC;IACF,CAAC;IAED,iCAAiC;IACjC,IAAI,MAAM,EAAE,SAAS,EAAE,CAAC;QACvB,YAAY,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IAC3C,CAAC;IAED,gBAAgB;IAChB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ACrB,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,wEAAwE;IACxE,0EAA0E;IAC1E,oDAAoD;IACpD,MAAM,YAAY,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAErD,wEAAwE;IACxE,wEAAwE;IACxE,MAAM,EAAE,GAAG,OAAO,CAAC;QAClB,MAAM,EAAE,YAAY;QACpB,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"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @agentuity/drizzle/schema - Node-compatible schema definitions
3
+ *
4
+ * This entry point re-exports only the Drizzle ORM schema utilities
5
+ * (table definitions, column types, operators) without any Bun-specific
6
+ * dependencies. Use this import path in your schema files so that
7
+ * drizzle-kit (which runs under Node) can resolve them.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // schema.ts — works with both Bun runtime AND drizzle-kit (Node)
12
+ * import { pgTable, text, serial, timestamp } from '@agentuity/drizzle/schema';
13
+ *
14
+ * export const users = pgTable('users', {
15
+ * id: serial('id').primaryKey(),
16
+ * name: text('name').notNull(),
17
+ * email: text('email').notNull().unique(),
18
+ * createdAt: timestamp('created_at').defaultNow(),
19
+ * });
20
+ * ```
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ export { sql, eq, and, or, not, desc, asc, gt, gte, lt, lte, ne, isNull, isNotNull, inArray, notInArray, between, like, ilike, relations, } from 'drizzle-orm';
25
+ export { pgTable, pgSchema, pgEnum, pgView, bigint, bigserial, boolean, vector, char, cidr, customType, date, doublePrecision, inet, integer, interval, json, jsonb, macaddr, macaddr8, numeric, real, serial, smallint, smallserial, text, time, timestamp, uuid, varchar, primaryKey, foreignKey, unique, uniqueIndex, index, check, } from 'drizzle-orm/pg-core';
26
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EACN,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,IAAI,EACJ,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,MAAM,EACN,SAAS,EACT,OAAO,EACP,UAAU,EACV,OAAO,EACP,IAAI,EACJ,KAAK,EACL,SAAS,GACT,MAAM,aAAa,CAAC;AAGrB,OAAO,EACN,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EAEN,MAAM,EACN,SAAS,EACT,OAAO,EACP,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,eAAe,EACf,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,OAAO,EAEP,UAAU,EACV,UAAU,EACV,MAAM,EACN,WAAW,EACX,KAAK,EACL,KAAK,GACL,MAAM,qBAAqB,CAAC"}
package/dist/schema.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @agentuity/drizzle/schema - Node-compatible schema definitions
3
+ *
4
+ * This entry point re-exports only the Drizzle ORM schema utilities
5
+ * (table definitions, column types, operators) without any Bun-specific
6
+ * dependencies. Use this import path in your schema files so that
7
+ * drizzle-kit (which runs under Node) can resolve them.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // schema.ts — works with both Bun runtime AND drizzle-kit (Node)
12
+ * import { pgTable, text, serial, timestamp } from '@agentuity/drizzle/schema';
13
+ *
14
+ * export const users = pgTable('users', {
15
+ * id: serial('id').primaryKey(),
16
+ * name: text('name').notNull(),
17
+ * email: text('email').notNull().unique(),
18
+ * createdAt: timestamp('created_at').defaultNow(),
19
+ * });
20
+ * ```
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ // Re-export common Drizzle utilities for convenience
25
+ export { sql, eq, and, or, not, desc, asc, gt, gte, lt, lte, ne, isNull, isNotNull, inArray, notInArray, between, like, ilike, relations, } from 'drizzle-orm';
26
+ // Re-export pg-core table and column definitions
27
+ export { pgTable, pgSchema, pgEnum, pgView,
28
+ // Column types
29
+ bigint, bigserial, boolean, vector, char, cidr, customType, date, doublePrecision, inet, integer, interval, json, jsonb, macaddr, macaddr8, numeric, real, serial, smallint, smallserial, text, time, timestamp, uuid, varchar,
30
+ // Constraints and indexes
31
+ primaryKey, foreignKey, unique, uniqueIndex, index, check, } from 'drizzle-orm/pg-core';
32
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,qDAAqD;AACrD,OAAO,EACN,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,IAAI,EACJ,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,MAAM,EACN,SAAS,EACT,OAAO,EACP,UAAU,EACV,OAAO,EACP,IAAI,EACJ,KAAK,EACL,SAAS,GACT,MAAM,aAAa,CAAC;AAErB,iDAAiD;AACjD,OAAO,EACN,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM;AACN,eAAe;AACf,MAAM,EACN,SAAS,EACT,OAAO,EACP,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,eAAe,EACf,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,OAAO;AACP,0BAA0B;AAC1B,UAAU,EACV,UAAU,EACV,MAAM,EACN,WAAW,EACX,KAAK,EACL,KAAK,GACL,MAAM,qBAAqB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentuity/drizzle",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Agentuity employees and contributors",
6
6
  "type": "module",
@@ -15,12 +15,22 @@
15
15
  "dist"
16
16
  ],
17
17
  "exports": {
18
- ".": "./dist/index.js"
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "./schema": {
23
+ "types": "./dist/schema.d.ts",
24
+ "default": "./dist/schema.js"
25
+ }
19
26
  },
20
27
  "typesVersions": {
21
28
  "*": {
22
29
  ".": [
23
30
  "./dist/index.d.ts"
31
+ ],
32
+ "schema": [
33
+ "./dist/schema.d.ts"
24
34
  ]
25
35
  }
26
36
  },
@@ -31,12 +41,12 @@
31
41
  "prepublishOnly": "bun run clean && bun run build"
32
42
  },
33
43
  "dependencies": {
34
- "@agentuity/postgres": "1.0.4",
44
+ "@agentuity/postgres": "1.0.6",
35
45
  "drizzle-orm": "^0.45.0",
36
46
  "better-auth": "^1.4.9"
37
47
  },
38
48
  "devDependencies": {
39
- "@agentuity/test-utils": "1.0.4",
49
+ "@agentuity/test-utils": "1.0.6",
40
50
  "@types/bun": "latest",
41
51
  "bun-types": "latest",
42
52
  "typescript": "^5.9.0"
package/src/index.ts CHANGED
@@ -71,6 +71,7 @@ export {
71
71
  between,
72
72
  like,
73
73
  ilike,
74
+ relations,
74
75
  } from 'drizzle-orm';
75
76
 
76
77
  // Re-export pg-core table and column definitions
@@ -78,10 +79,12 @@ export {
78
79
  pgTable,
79
80
  pgSchema,
80
81
  pgEnum,
82
+ pgView,
81
83
  // Column types
82
84
  bigint,
83
85
  bigserial,
84
86
  boolean,
87
+ vector,
85
88
  char,
86
89
  cidr,
87
90
  customType,
package/src/postgres.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { SQL as BunSQL } from 'bun';
1
2
  import { drizzle } from 'drizzle-orm/bun-sql';
2
3
  import { postgres, type CallablePostgresClient, type PostgresConfig } from '@agentuity/postgres';
3
4
  import type { PostgresDrizzleConfig, PostgresDrizzle } from './types';
@@ -39,6 +40,57 @@ export function resolvePostgresClientConfig<
39
40
  return clientConfig;
40
41
  }
41
42
 
43
+ /**
44
+ * Creates a dynamic SQL proxy that always delegates to the PostgresClient's
45
+ * current raw connection. This ensures that after automatic reconnection,
46
+ * Drizzle ORM uses the fresh connection instead of a stale reference.
47
+ *
48
+ * The proxy also wraps `unsafe()` calls with the client's retry logic,
49
+ * providing automatic retry on transient connection errors.
50
+ *
51
+ * @internal Exported for testing — not part of the public package API.
52
+ */
53
+ export function createResilientSQLProxy(
54
+ client: CallablePostgresClient
55
+ ): InstanceType<typeof BunSQL> {
56
+ return new Proxy({} as InstanceType<typeof BunSQL>, {
57
+ get(_target, prop, _receiver) {
58
+ // Always resolve from the CURRENT raw connection (changes after reconnect)
59
+ const raw = client.raw;
60
+
61
+ if (prop === 'unsafe') {
62
+ // Wrap unsafe() with retry logic for resilient queries.
63
+ // Returns a thenable that also supports .values() chaining,
64
+ // matching the SQLQuery interface that Drizzle expects:
65
+ // client.unsafe(query, params) → Promise<rows>
66
+ // client.unsafe(query, params).values() → Promise<rows>
67
+ return (query: string, params?: unknown[]) => {
68
+ const makeExecutor = (useValues: boolean) =>
69
+ client.executeWithRetry(async () => {
70
+ // Re-resolve raw inside retry to get post-reconnect instance
71
+ const currentRaw = client.raw;
72
+ const q = currentRaw.unsafe(query, params);
73
+ return useValues ? q.values() : q;
74
+ });
75
+
76
+ // Return a thenable with .values() to match Bun's SQLQuery interface
77
+ const result = makeExecutor(false);
78
+ return Object.assign(result, {
79
+ values: () => makeExecutor(true),
80
+ });
81
+ };
82
+ }
83
+
84
+ const value = (raw as unknown as Record<string | symbol, unknown>)[prop];
85
+ if (typeof value === 'function') {
86
+ // Bind to raw so `this` is correct inside begin(), savepoint(), etc.
87
+ return (value as (...args: unknown[]) => unknown).bind(raw);
88
+ }
89
+ return value;
90
+ },
91
+ });
92
+ }
93
+
42
94
  /**
43
95
  * Creates a Drizzle ORM instance with a resilient PostgreSQL connection.
44
96
  *
@@ -100,10 +152,15 @@ export function createPostgresDrizzle<
100
152
  });
101
153
  }
102
154
 
103
- // Create Drizzle instance using the client's raw SQL connection
104
- // The bun-sql driver accepts a client that implements the Bun.SQL interface
155
+ // Create a resilient proxy that always delegates to the current raw SQL
156
+ // connection. This ensures that after reconnection, Drizzle automatically
157
+ // uses the new connection instead of the stale one.
158
+ const resilientSQL = createResilientSQLProxy(client);
159
+
160
+ // Create Drizzle instance using the resilient proxy instead of a static
161
+ // reference to client.raw, which would become stale after reconnection.
105
162
  const db = drizzle({
106
- client: client.raw,
163
+ client: resilientSQL,
107
164
  schema: config?.schema,
108
165
  logger: config?.logger,
109
166
  });
package/src/schema.ts ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @agentuity/drizzle/schema - Node-compatible schema definitions
3
+ *
4
+ * This entry point re-exports only the Drizzle ORM schema utilities
5
+ * (table definitions, column types, operators) without any Bun-specific
6
+ * dependencies. Use this import path in your schema files so that
7
+ * drizzle-kit (which runs under Node) can resolve them.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // schema.ts — works with both Bun runtime AND drizzle-kit (Node)
12
+ * import { pgTable, text, serial, timestamp } from '@agentuity/drizzle/schema';
13
+ *
14
+ * export const users = pgTable('users', {
15
+ * id: serial('id').primaryKey(),
16
+ * name: text('name').notNull(),
17
+ * email: text('email').notNull().unique(),
18
+ * createdAt: timestamp('created_at').defaultNow(),
19
+ * });
20
+ * ```
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+
25
+ // Re-export common Drizzle utilities for convenience
26
+ export {
27
+ sql,
28
+ eq,
29
+ and,
30
+ or,
31
+ not,
32
+ desc,
33
+ asc,
34
+ gt,
35
+ gte,
36
+ lt,
37
+ lte,
38
+ ne,
39
+ isNull,
40
+ isNotNull,
41
+ inArray,
42
+ notInArray,
43
+ between,
44
+ like,
45
+ ilike,
46
+ relations,
47
+ } from 'drizzle-orm';
48
+
49
+ // Re-export pg-core table and column definitions
50
+ export {
51
+ pgTable,
52
+ pgSchema,
53
+ pgEnum,
54
+ pgView,
55
+ // Column types
56
+ bigint,
57
+ bigserial,
58
+ boolean,
59
+ vector,
60
+ char,
61
+ cidr,
62
+ customType,
63
+ date,
64
+ doublePrecision,
65
+ inet,
66
+ integer,
67
+ interval,
68
+ json,
69
+ jsonb,
70
+ macaddr,
71
+ macaddr8,
72
+ numeric,
73
+ real,
74
+ serial,
75
+ smallint,
76
+ smallserial,
77
+ text,
78
+ time,
79
+ timestamp,
80
+ uuid,
81
+ varchar,
82
+ // Constraints and indexes
83
+ primaryKey,
84
+ foreignKey,
85
+ unique,
86
+ uniqueIndex,
87
+ index,
88
+ check,
89
+ } from 'drizzle-orm/pg-core';