@agentuity/drizzle 1.0.5 → 1.0.7
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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/postgres.d.ts.map +1 -1
- package/dist/postgres.js +96 -0
- package/dist/postgres.js.map +1 -1
- package/dist/schema.d.ts +26 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +32 -0
- package/dist/schema.js.map +1 -0
- package/package.json +14 -4
- package/src/index.ts +3 -0
- package/src/postgres.ts +111 -0
- package/src/schema.ts +89 -0
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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,SAAS,CAAC;AAGtE,OAAO,EACN,QAAQ,EACR,cAAc,EACd,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,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,
|
|
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,SAAS,CAAC;AAGtE,OAAO,EACN,QAAQ,EACR,cAAc,EACd,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,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,
|
|
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"}
|
package/dist/postgres.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAY,KAAK,sBAAsB,EAAE,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;
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAY,KAAK,sBAAsB,EAAE,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;AA8FD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,sBAAsB,GAC5B,YAAY,CAAC,OAAO,MAAM,CAAC,CAwD7B;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,CAoCnE"}
|
package/dist/postgres.js
CHANGED
|
@@ -32,6 +32,85 @@ export function resolvePostgresClientConfig(config) {
|
|
|
32
32
|
}
|
|
33
33
|
return clientConfig;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Strips leading whitespace and SQL comments (block and line) from a query string.
|
|
37
|
+
* Returns the remaining query text starting at the first non-comment token.
|
|
38
|
+
*/
|
|
39
|
+
const LEADING_COMMENTS_RE = /^(?:\s+|\/\*[\s\S]*?\*\/|--[^\n]*\n)*/;
|
|
40
|
+
/**
|
|
41
|
+
* Determines whether a SQL query is a non-retryable INSERT statement.
|
|
42
|
+
*
|
|
43
|
+
* Handles two patterns:
|
|
44
|
+
* 1. Direct INSERT: `INSERT INTO ...` (with optional leading comments/whitespace)
|
|
45
|
+
* 2. CTE INSERT: `WITH cte AS (...) INSERT INTO ...` — scans past the WITH clause
|
|
46
|
+
* by tracking parenthesis depth to skip CTE subexpressions, then checks
|
|
47
|
+
* if the first top-level DML keyword is INSERT.
|
|
48
|
+
*
|
|
49
|
+
* @see https://github.com/agentuity/sdk/issues/911
|
|
50
|
+
*/
|
|
51
|
+
function isNonRetryableInsert(query) {
|
|
52
|
+
// Strip leading whitespace and SQL comments
|
|
53
|
+
const stripped = query.replace(LEADING_COMMENTS_RE, '');
|
|
54
|
+
// Fast path: direct INSERT statement
|
|
55
|
+
if (/^INSERT\s/i.test(stripped)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
// Check for WITH (CTE) prefix
|
|
59
|
+
if (!/^WITH\s/i.test(stripped)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
// Scan past the CTE clause to find the first top-level DML keyword.
|
|
63
|
+
// We track parenthesis depth so we skip CTE subexpressions like
|
|
64
|
+
// "WITH cte AS (SELECT ... INSERT ...)" without false-matching the
|
|
65
|
+
// INSERT inside the parens.
|
|
66
|
+
let depth = 0;
|
|
67
|
+
let i = 4; // skip past "WITH"
|
|
68
|
+
const len = stripped.length;
|
|
69
|
+
while (i < len) {
|
|
70
|
+
const ch = stripped[i];
|
|
71
|
+
if (ch === '(') {
|
|
72
|
+
depth++;
|
|
73
|
+
i++;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (ch === ')') {
|
|
77
|
+
depth--;
|
|
78
|
+
i++;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
// Only inspect keywords at top level (depth === 0)
|
|
82
|
+
if (depth === 0) {
|
|
83
|
+
// Skip whitespace at top level
|
|
84
|
+
if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') {
|
|
85
|
+
i++;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
// Skip commas between CTEs: WITH a AS (...), b AS (...)
|
|
89
|
+
if (ch === ',') {
|
|
90
|
+
i++;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
// Check for DML keywords at this position.
|
|
94
|
+
// We look for INSERT, UPDATE, DELETE, or SELECT — the first one
|
|
95
|
+
// we find at top level determines whether this is retryable.
|
|
96
|
+
const rest = stripped.substring(i);
|
|
97
|
+
const dmlMatch = /^(INSERT|UPDATE|DELETE|SELECT)\s/i.exec(rest);
|
|
98
|
+
if (dmlMatch) {
|
|
99
|
+
return dmlMatch[1].toUpperCase() === 'INSERT';
|
|
100
|
+
}
|
|
101
|
+
// Skip over any other word (e.g., CTE names, AS keyword, RECURSIVE)
|
|
102
|
+
// by advancing past alphanumeric/underscore characters
|
|
103
|
+
if (/\w/.test(ch)) {
|
|
104
|
+
while (i < len && /\w/.test(stripped[i])) {
|
|
105
|
+
i++;
|
|
106
|
+
}
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
i++;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
35
114
|
/**
|
|
36
115
|
* Creates a dynamic SQL proxy that always delegates to the PostgresClient's
|
|
37
116
|
* current raw connection. This ensures that after automatic reconnection,
|
|
@@ -54,6 +133,23 @@ export function createResilientSQLProxy(client) {
|
|
|
54
133
|
// client.unsafe(query, params) → Promise<rows>
|
|
55
134
|
// client.unsafe(query, params).values() → Promise<rows>
|
|
56
135
|
return (query, params) => {
|
|
136
|
+
// INSERT statements (including CTE-based) are NOT retried to prevent
|
|
137
|
+
// duplicate rows. If an INSERT succeeds on the server but the connection
|
|
138
|
+
// drops before the response, retrying would re-execute it — creating a
|
|
139
|
+
// duplicate row when the primary key is server-generated.
|
|
140
|
+
// See: https://github.com/agentuity/sdk/issues/911
|
|
141
|
+
const isInsert = isNonRetryableInsert(query);
|
|
142
|
+
if (isInsert) {
|
|
143
|
+
const makeDirectExecutor = (useValues) => {
|
|
144
|
+
const currentRaw = client.raw;
|
|
145
|
+
const q = currentRaw.unsafe(query, params);
|
|
146
|
+
return useValues ? q.values() : q;
|
|
147
|
+
};
|
|
148
|
+
const result = makeDirectExecutor(false);
|
|
149
|
+
return Object.assign(result, {
|
|
150
|
+
values: () => makeDirectExecutor(true),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
57
153
|
const makeExecutor = (useValues) => client.executeWithRetry(async () => {
|
|
58
154
|
// Re-resolve raw inside retry to get post-reconnect instance
|
|
59
155
|
const currentRaw = client.raw;
|
package/dist/postgres.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AACA,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;YACr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U,EAAE,CAAC;gBACjC,qEAAqE;gBACrE,OAAQ,KAAyC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC7D,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,UAAU,qBAAqB,CAEnC,MAAuC;IACxC,4CAA4C;IAC5C,MAAM,YAAY,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,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"}
|
package/dist/schema.d.ts
ADDED
|
@@ -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.
|
|
3
|
+
"version": "1.0.7",
|
|
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
|
-
".":
|
|
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.
|
|
44
|
+
"@agentuity/postgres": "1.0.7",
|
|
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.
|
|
49
|
+
"@agentuity/test-utils": "1.0.7",
|
|
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
|
@@ -40,6 +40,98 @@ export function resolvePostgresClientConfig<
|
|
|
40
40
|
return clientConfig;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Strips leading whitespace and SQL comments (block and line) from a query string.
|
|
45
|
+
* Returns the remaining query text starting at the first non-comment token.
|
|
46
|
+
*/
|
|
47
|
+
const LEADING_COMMENTS_RE = /^(?:\s+|\/\*[\s\S]*?\*\/|--[^\n]*\n)*/;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Determines whether a SQL query is a non-retryable INSERT statement.
|
|
51
|
+
*
|
|
52
|
+
* Handles two patterns:
|
|
53
|
+
* 1. Direct INSERT: `INSERT INTO ...` (with optional leading comments/whitespace)
|
|
54
|
+
* 2. CTE INSERT: `WITH cte AS (...) INSERT INTO ...` — scans past the WITH clause
|
|
55
|
+
* by tracking parenthesis depth to skip CTE subexpressions, then checks
|
|
56
|
+
* if the first top-level DML keyword is INSERT.
|
|
57
|
+
*
|
|
58
|
+
* @see https://github.com/agentuity/sdk/issues/911
|
|
59
|
+
*/
|
|
60
|
+
function isNonRetryableInsert(query: string): boolean {
|
|
61
|
+
// Strip leading whitespace and SQL comments
|
|
62
|
+
const stripped = query.replace(LEADING_COMMENTS_RE, '');
|
|
63
|
+
|
|
64
|
+
// Fast path: direct INSERT statement
|
|
65
|
+
if (/^INSERT\s/i.test(stripped)) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Check for WITH (CTE) prefix
|
|
70
|
+
if (!/^WITH\s/i.test(stripped)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Scan past the CTE clause to find the first top-level DML keyword.
|
|
75
|
+
// We track parenthesis depth so we skip CTE subexpressions like
|
|
76
|
+
// "WITH cte AS (SELECT ... INSERT ...)" without false-matching the
|
|
77
|
+
// INSERT inside the parens.
|
|
78
|
+
let depth = 0;
|
|
79
|
+
let i = 4; // skip past "WITH"
|
|
80
|
+
const len = stripped.length;
|
|
81
|
+
|
|
82
|
+
while (i < len) {
|
|
83
|
+
const ch = stripped[i]!;
|
|
84
|
+
|
|
85
|
+
if (ch === '(') {
|
|
86
|
+
depth++;
|
|
87
|
+
i++;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (ch === ')') {
|
|
91
|
+
depth--;
|
|
92
|
+
i++;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Only inspect keywords at top level (depth === 0)
|
|
97
|
+
if (depth === 0) {
|
|
98
|
+
// Skip whitespace at top level
|
|
99
|
+
if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') {
|
|
100
|
+
i++;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Skip commas between CTEs: WITH a AS (...), b AS (...)
|
|
105
|
+
if (ch === ',') {
|
|
106
|
+
i++;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Check for DML keywords at this position.
|
|
111
|
+
// We look for INSERT, UPDATE, DELETE, or SELECT — the first one
|
|
112
|
+
// we find at top level determines whether this is retryable.
|
|
113
|
+
const rest = stripped.substring(i);
|
|
114
|
+
const dmlMatch = /^(INSERT|UPDATE|DELETE|SELECT)\s/i.exec(rest);
|
|
115
|
+
if (dmlMatch) {
|
|
116
|
+
return dmlMatch[1]!.toUpperCase() === 'INSERT';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Skip over any other word (e.g., CTE names, AS keyword, RECURSIVE)
|
|
120
|
+
// by advancing past alphanumeric/underscore characters
|
|
121
|
+
if (/\w/.test(ch)) {
|
|
122
|
+
while (i < len && /\w/.test(stripped[i]!)) {
|
|
123
|
+
i++;
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
i++;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
43
135
|
/**
|
|
44
136
|
* Creates a dynamic SQL proxy that always delegates to the PostgresClient's
|
|
45
137
|
* current raw connection. This ensures that after automatic reconnection,
|
|
@@ -65,6 +157,25 @@ export function createResilientSQLProxy(
|
|
|
65
157
|
// client.unsafe(query, params) → Promise<rows>
|
|
66
158
|
// client.unsafe(query, params).values() → Promise<rows>
|
|
67
159
|
return (query: string, params?: unknown[]) => {
|
|
160
|
+
// INSERT statements (including CTE-based) are NOT retried to prevent
|
|
161
|
+
// duplicate rows. If an INSERT succeeds on the server but the connection
|
|
162
|
+
// drops before the response, retrying would re-execute it — creating a
|
|
163
|
+
// duplicate row when the primary key is server-generated.
|
|
164
|
+
// See: https://github.com/agentuity/sdk/issues/911
|
|
165
|
+
const isInsert = isNonRetryableInsert(query);
|
|
166
|
+
|
|
167
|
+
if (isInsert) {
|
|
168
|
+
const makeDirectExecutor = (useValues: boolean) => {
|
|
169
|
+
const currentRaw = client.raw;
|
|
170
|
+
const q = currentRaw.unsafe(query, params);
|
|
171
|
+
return useValues ? q.values() : q;
|
|
172
|
+
};
|
|
173
|
+
const result = makeDirectExecutor(false);
|
|
174
|
+
return Object.assign(result, {
|
|
175
|
+
values: () => makeDirectExecutor(true),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
68
179
|
const makeExecutor = (useValues: boolean) =>
|
|
69
180
|
client.executeWithRetry(async () => {
|
|
70
181
|
// Re-resolve raw inside retry to get post-reconnect instance
|
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';
|