@danceroutine/tango-orm 1.11.1 → 1.11.3
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/Adapter-DKxAaL4l.d.ts +73 -0
- package/dist/DBClient-DuYcXolQ.d.ts +27 -0
- package/dist/{InternalDialect-ClSaUNso.js → InternalDialect-U3mwJjKA.js} +3 -4
- package/dist/InternalDialect-U3mwJjKA.js.map +1 -0
- package/dist/QuerySetState-CjyvAUBs.d.ts +1310 -0
- package/dist/SqliteAdapter-6oyUmoJf.js +279 -0
- package/dist/SqliteAdapter-6oyUmoJf.js.map +1 -0
- package/dist/chunk-8H4AJuhK.js +14 -0
- package/dist/connection/index.d.ts +4 -11
- package/dist/connection/index.js +3 -6
- package/dist/{connection-Dmhgx31M.js → connection-D-E6_Yf1.js} +28 -30
- package/dist/connection-D-E6_Yf1.js.map +1 -0
- package/dist/{defaultRuntime-DzqBQ9Hb.js → defaultRuntime-CdTX8cXm.js} +41 -35
- package/dist/defaultRuntime-CdTX8cXm.js.map +1 -0
- package/dist/index-B-aibguC.d.ts +226 -0
- package/dist/index-D9B6gKez.d.ts +70 -0
- package/dist/index-rjKca3U_.d.ts +31 -0
- package/dist/index-uuG57Y7C.d.ts +97 -0
- package/dist/index.d.ts +9 -22
- package/dist/index.js +9 -12
- package/dist/manager/index.d.ts +4 -12
- package/dist/manager/index.js +3 -9
- package/dist/{manager-DrDTiCAz.js → manager-CiYqAYpn.js} +7 -11
- package/dist/{manager-DrDTiCAz.js.map → manager-CiYqAYpn.js.map} +1 -1
- package/dist/query/index.d.ts +3 -14
- package/dist/query/index.js +2 -4
- package/dist/{query-DUZnBFhf.js → query-CP1UMIX6.js} +163 -121
- package/dist/query-CP1UMIX6.js.map +1 -0
- package/dist/registerModelObjects-C-MliIiM.d.ts +229 -0
- package/dist/{registerModelObjects-22ZJKoit.js → registerModelObjects-DZfZ20fa.js} +119 -69
- package/dist/registerModelObjects-DZfZ20fa.js.map +1 -0
- package/dist/runtime/index.d.ts +3 -15
- package/dist/runtime/index.js +15 -8
- package/dist/runtime/index.js.map +1 -0
- package/dist/transaction/index.d.ts +2 -6
- package/dist/transaction/index.js +2 -7
- package/dist/{transaction-ZhfDf-f8.js → transaction-2_2m7VUo.js} +26 -10
- package/dist/transaction-2_2m7VUo.js.map +1 -0
- package/package.json +7 -7
- package/dist/InternalDialect-ClSaUNso.js.map +0 -1
- package/dist/PostgresAdapter-CXKdKBG-.js +0 -4
- package/dist/PostgresAdapter-DySFW6vy.js +0 -128
- package/dist/PostgresAdapter-DySFW6vy.js.map +0 -1
- package/dist/SqliteAdapter-CDdOjRmW.js +0 -151
- package/dist/SqliteAdapter-CDdOjRmW.js.map +0 -1
- package/dist/SqliteAdapter-mjtXuVTg.js +0 -4
- package/dist/chunk-DLY2FNSh.js +0 -12
- package/dist/connection/adapters/Adapter.d.ts +0 -60
- package/dist/connection/adapters/AdapterRegistry.d.ts +0 -44
- package/dist/connection/adapters/dialects/PostgresAdapter.d.ts +0 -30
- package/dist/connection/adapters/dialects/SqliteAdapter.d.ts +0 -22
- package/dist/connection/adapters/dialects/index.d.ts +0 -5
- package/dist/connection/adapters/index.d.ts +0 -8
- package/dist/connection/clients/DBClient.d.ts +0 -23
- package/dist/connection/clients/dialects/PostgresClient.d.ts +0 -54
- package/dist/connection/clients/dialects/SqliteClient.d.ts +0 -54
- package/dist/connection/clients/dialects/index.d.ts +0 -5
- package/dist/connection/clients/index.d.ts +0 -7
- package/dist/connection-Dmhgx31M.js.map +0 -1
- package/dist/defaultRuntime-DzqBQ9Hb.js.map +0 -1
- package/dist/manager/ManagerLike.d.ts +0 -34
- package/dist/manager/ModelManager.d.ts +0 -106
- package/dist/manager/internal/MutationCompiler.d.ts +0 -23
- package/dist/manager/internal/RuntimeBoundClient.d.ts +0 -20
- package/dist/manager/registerModelObjects.d.ts +0 -5
- package/dist/manager/relations/ManyToManyRelatedManager.d.ts +0 -181
- package/dist/manager/relations/ManyToManyRelatedQuerySet.d.ts +0 -62
- package/dist/manager/relations/MaterializedModelRecord.d.ts +0 -28
- package/dist/manager/relations/index.d.ts +0 -9
- package/dist/manager/relations/internal/ThroughTableManager.d.ts +0 -85
- package/dist/query/ModelQuerySet.d.ts +0 -20
- package/dist/query/QBuilder.d.ts +0 -29
- package/dist/query/QuerySet.d.ts +0 -215
- package/dist/query/compiler/QueryCompiler.d.ts +0 -49
- package/dist/query/compiler/index.d.ts +0 -4
- package/dist/query/domain/CompiledQuery.d.ts +0 -209
- package/dist/query/domain/Dialect.d.ts +0 -2
- package/dist/query/domain/Direction.d.ts +0 -2
- package/dist/query/domain/FilterInput.d.ts +0 -3
- package/dist/query/domain/FilterKey.d.ts +0 -4
- package/dist/query/domain/FilterValue.d.ts +0 -1
- package/dist/query/domain/LookupType.d.ts +0 -2
- package/dist/query/domain/OrderSpec.d.ts +0 -5
- package/dist/query/domain/OrderToken.d.ts +0 -1
- package/dist/query/domain/QNode.d.ts +0 -9
- package/dist/query/domain/QueryResult.d.ts +0 -35
- package/dist/query/domain/QuerySetState.d.ts +0 -13
- package/dist/query/domain/RelationMeta.d.ts +0 -56
- package/dist/query/domain/RelationTyping.d.ts +0 -163
- package/dist/query/domain/TableMeta.d.ts +0 -16
- package/dist/query/domain/TableMetaFactory.d.ts +0 -10
- package/dist/query/domain/WhereClause.d.ts +0 -4
- package/dist/query/domain/index.d.ts +0 -21
- package/dist/query/domain/internal/InternalDialect.d.ts +0 -4
- package/dist/query/domain/internal/InternalDirection.d.ts +0 -4
- package/dist/query/domain/internal/InternalLookupType.d.ts +0 -15
- package/dist/query/domain/internal/InternalPrefetchQueryKind.d.ts +0 -20
- package/dist/query/domain/internal/InternalQNodeType.d.ts +0 -6
- package/dist/query/domain/internal/InternalRelationKind.d.ts +0 -6
- package/dist/query/internal/isQNodeLike.d.ts +0 -3
- package/dist/query/planning/QueryPlanner.d.ts +0 -16
- package/dist/query/planning/domain/QueryHydrationPlan.d.ts +0 -20
- package/dist/query/planning/index.d.ts +0 -2
- package/dist/query-DUZnBFhf.js.map +0 -1
- package/dist/registerModelObjects-22ZJKoit.js.map +0 -1
- package/dist/runtime/TangoRuntime.d.ts +0 -56
- package/dist/runtime/defaultRuntime.d.ts +0 -13
- package/dist/runtime/internal/DBClientProvider.d.ts +0 -12
- package/dist/runtime/internal/PostgresDBClientProvider.d.ts +0 -12
- package/dist/runtime/internal/SqliteDBClientProvider.d.ts +0 -19
- package/dist/runtime/internal/createDBClientProvider.d.ts +0 -5
- package/dist/runtime-1H88J3nN.js +0 -18
- package/dist/runtime-1H88J3nN.js.map +0 -1
- package/dist/transaction/AtomicTransaction.d.ts +0 -32
- package/dist/transaction/UnitOfWork.d.ts +0 -52
- package/dist/transaction/atomic.d.ts +0 -2
- package/dist/transaction/internal/context/AsyncLocalTransactionEngine.d.ts +0 -21
- package/dist/transaction/internal/context/CallbackRecord.d.ts +0 -5
- package/dist/transaction/internal/context/FrameBoundTransaction.d.ts +0 -20
- package/dist/transaction/internal/context/FrameTransactionHandle.d.ts +0 -4
- package/dist/transaction/internal/context/TransactionEngine.d.ts +0 -16
- package/dist/transaction/internal/context/TransactionFrame.d.ts +0 -7
- package/dist/transaction/internal/context/TransactionState.d.ts +0 -10
- package/dist/transaction/internal/context/index.d.ts +0 -1
- package/dist/transaction-ZhfDf-f8.js.map +0 -1
- package/dist/validation/OrmSqlSafetyAdapter.d.ts +0 -22
- package/dist/validation/SQLValidationEngine.d.ts +0 -68
- package/dist/validation/SqlValidationPlan.d.ts +0 -43
- package/dist/validation/index.d.ts +0 -3
- package/dist/validation/internal/InternalSqlValidationPlanKind.d.ts +0 -25
- package/dist/validation/internal/InternalValidatedFilterDescriptorKind.d.ts +0 -4
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-8H4AJuhK.js";
|
|
2
|
+
import { t as InternalDialect } from "./InternalDialect-U3mwJjKA.js";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import pg from "pg";
|
|
5
|
+
//#region src/connection/clients/dialects/PostgresClient.ts
|
|
6
|
+
/**
|
|
7
|
+
* Transaction-capable client backed by a PostgreSQL pool client.
|
|
8
|
+
*/
|
|
9
|
+
var PostgresClient = class PostgresClient {
|
|
10
|
+
client;
|
|
11
|
+
static BRAND = "tango.orm.postgres_client";
|
|
12
|
+
__tangoBrand = PostgresClient.BRAND;
|
|
13
|
+
constructor(client) {
|
|
14
|
+
this.client = client;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Narrow an unknown value to `PostgresClient`.
|
|
18
|
+
*/
|
|
19
|
+
static isPostgresClient(value) {
|
|
20
|
+
return typeof value === "object" && value !== null && value.__tangoBrand === PostgresClient.BRAND;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Execute a SQL statement with optional bound parameters.
|
|
24
|
+
*/
|
|
25
|
+
async query(sql, params) {
|
|
26
|
+
return { rows: (await this.client.query(sql, params)).rows };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Begin a database transaction.
|
|
30
|
+
*/
|
|
31
|
+
async begin() {
|
|
32
|
+
await this.client.query("BEGIN");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Commit the active transaction.
|
|
36
|
+
*/
|
|
37
|
+
async commit() {
|
|
38
|
+
await this.client.query("COMMIT");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Roll back the active transaction.
|
|
42
|
+
*/
|
|
43
|
+
async rollback() {
|
|
44
|
+
await this.client.query("ROLLBACK");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a savepoint inside the active transaction.
|
|
48
|
+
*/
|
|
49
|
+
async createSavepoint(name) {
|
|
50
|
+
await this.client.query(`SAVEPOINT ${name}`);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Release a previously-created savepoint.
|
|
54
|
+
*/
|
|
55
|
+
async releaseSavepoint(name) {
|
|
56
|
+
await this.client.query(`RELEASE SAVEPOINT ${name}`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Roll back the active transaction to a savepoint.
|
|
60
|
+
*/
|
|
61
|
+
async rollbackToSavepoint(name) {
|
|
62
|
+
await this.client.query(`ROLLBACK TO SAVEPOINT ${name}`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Release the leased PostgreSQL client back to its owning pool.
|
|
66
|
+
*/
|
|
67
|
+
async close() {
|
|
68
|
+
this.client.release();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/connection/adapters/dialects/PostgresAdapter.ts
|
|
73
|
+
var PostgresAdapter_exports = /* @__PURE__ */ __exportAll({ PostgresAdapter: () => PostgresAdapter });
|
|
74
|
+
const { Pool } = pg;
|
|
75
|
+
/**
|
|
76
|
+
* Postgres adapter that turns adapter config into a transactional `DBClient`.
|
|
77
|
+
*/
|
|
78
|
+
var PostgresAdapter = class PostgresAdapter {
|
|
79
|
+
static BRAND = "tango.orm.postgres_adapter";
|
|
80
|
+
__tangoBrand = PostgresAdapter.BRAND;
|
|
81
|
+
name = "postgres";
|
|
82
|
+
dialect = InternalDialect.POSTGRES;
|
|
83
|
+
/**
|
|
84
|
+
* Declares capabilities of this database adapter.
|
|
85
|
+
* Used by the migration runner and query compiler to determine which
|
|
86
|
+
* SQL features can be safely used:
|
|
87
|
+
* - transactionalDDL: Postgres supports DDL inside transactions (safe rollback of schema changes)
|
|
88
|
+
* - concurrentIndex: Supports CREATE INDEX CONCURRENTLY (non-blocking index builds)
|
|
89
|
+
* - validateForeignKeys: Supports deferred FK validation via NOT VALID + VALIDATE CONSTRAINT
|
|
90
|
+
* - ignoreDuplicateInsert: Supports duplicate-safe insert semantics for manager-owned link writes
|
|
91
|
+
*/
|
|
92
|
+
features = {
|
|
93
|
+
transactionalDDL: true,
|
|
94
|
+
concurrentIndex: true,
|
|
95
|
+
validateForeignKeys: true,
|
|
96
|
+
ignoreDuplicateInsert: true
|
|
97
|
+
};
|
|
98
|
+
placeholders = {
|
|
99
|
+
at(index) {
|
|
100
|
+
return `$${index}`;
|
|
101
|
+
},
|
|
102
|
+
list(count) {
|
|
103
|
+
return this.listFromOffset(count, 0);
|
|
104
|
+
},
|
|
105
|
+
listFromOffset(count, startOffset) {
|
|
106
|
+
return Array.from({ length: count }, (_value, index) => `$${startOffset + index + 1}`).join(", ");
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Narrow an unknown value to `PostgresAdapter`.
|
|
111
|
+
*/
|
|
112
|
+
static isPostgresAdapter(value) {
|
|
113
|
+
return typeof value === "object" && value !== null && value.__tangoBrand === PostgresAdapter.BRAND;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Open a Postgres connection pool and return a client-backed DB abstraction.
|
|
117
|
+
*/
|
|
118
|
+
async connect(config) {
|
|
119
|
+
return new PostgresClient(await new Pool({
|
|
120
|
+
connectionString: config.url,
|
|
121
|
+
host: config.host,
|
|
122
|
+
port: config.port,
|
|
123
|
+
database: config.database,
|
|
124
|
+
user: config.user,
|
|
125
|
+
password: config.password,
|
|
126
|
+
max: config.maxConnections || 10
|
|
127
|
+
}).connect());
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/connection/clients/dialects/SqliteClient.ts
|
|
132
|
+
/**
|
|
133
|
+
* Transaction-capable client backed by a synchronous `better-sqlite3` handle.
|
|
134
|
+
*/
|
|
135
|
+
var SqliteClient = class SqliteClient {
|
|
136
|
+
db;
|
|
137
|
+
static BRAND = "tango.orm.sqlite_client";
|
|
138
|
+
__tangoBrand = SqliteClient.BRAND;
|
|
139
|
+
inTransaction = false;
|
|
140
|
+
constructor(db) {
|
|
141
|
+
this.db = db;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Narrow an unknown value to `SqliteClient`.
|
|
145
|
+
*/
|
|
146
|
+
static isSqliteClient(value) {
|
|
147
|
+
return typeof value === "object" && value !== null && value.__tangoBrand === SqliteClient.BRAND;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Execute a SQL statement with optional parameters.
|
|
151
|
+
*
|
|
152
|
+
* `SELECT`/`PRAGMA` statements return row data; write statements return
|
|
153
|
+
* an empty row list.
|
|
154
|
+
*/
|
|
155
|
+
async query(sql, params) {
|
|
156
|
+
const stmt = this.db.prepare(sql);
|
|
157
|
+
const isPragmaWrite = /^\s*PRAGMA\b/i.test(sql) && /=/.test(sql);
|
|
158
|
+
const normalizedParams = params?.map((param) => this.normalizeParam(param));
|
|
159
|
+
if (!isPragmaWrite && stmt.reader) return { rows: normalizedParams ? stmt.all(...normalizedParams) : stmt.all() };
|
|
160
|
+
if (normalizedParams) stmt.run(...normalizedParams);
|
|
161
|
+
else stmt.run();
|
|
162
|
+
return { rows: [] };
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Begin a transaction if one is not already active.
|
|
166
|
+
*/
|
|
167
|
+
async begin() {
|
|
168
|
+
if (!this.inTransaction) {
|
|
169
|
+
this.db.prepare("BEGIN IMMEDIATE").run();
|
|
170
|
+
this.inTransaction = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Commit the active transaction.
|
|
175
|
+
*/
|
|
176
|
+
async commit() {
|
|
177
|
+
if (this.inTransaction) {
|
|
178
|
+
this.db.prepare("COMMIT").run();
|
|
179
|
+
this.inTransaction = false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Roll back the active transaction.
|
|
184
|
+
*/
|
|
185
|
+
async rollback() {
|
|
186
|
+
if (this.inTransaction) {
|
|
187
|
+
this.db.prepare("ROLLBACK").run();
|
|
188
|
+
this.inTransaction = false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Create a savepoint inside the active transaction.
|
|
193
|
+
*/
|
|
194
|
+
async createSavepoint(name) {
|
|
195
|
+
this.db.prepare(`SAVEPOINT ${name}`).run();
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Release a previously-created savepoint.
|
|
199
|
+
*/
|
|
200
|
+
async releaseSavepoint(name) {
|
|
201
|
+
this.db.prepare(`RELEASE SAVEPOINT ${name}`).run();
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Roll back the active transaction to a savepoint.
|
|
205
|
+
*/
|
|
206
|
+
async rollbackToSavepoint(name) {
|
|
207
|
+
this.db.prepare(`ROLLBACK TO SAVEPOINT ${name}`).run();
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Close the underlying SQLite handle.
|
|
211
|
+
*/
|
|
212
|
+
async close() {
|
|
213
|
+
this.db.close();
|
|
214
|
+
}
|
|
215
|
+
normalizeParam(value) {
|
|
216
|
+
if (isDateValue(value)) return value.toISOString();
|
|
217
|
+
if (typeof value === "boolean") return value ? 1 : 0;
|
|
218
|
+
return value;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
function isDateValue(value) {
|
|
222
|
+
return typeof value === "object" && value !== null && typeof value.getTime === "function" && typeof value.toISOString === "function";
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/connection/adapters/dialects/SqliteAdapter.ts
|
|
226
|
+
var SqliteAdapter_exports = /* @__PURE__ */ __exportAll({ SqliteAdapter: () => SqliteAdapter });
|
|
227
|
+
/**
|
|
228
|
+
* SQLite adapter that creates a `better-sqlite3` backed `DBClient`.
|
|
229
|
+
*/
|
|
230
|
+
var SqliteAdapter = class SqliteAdapter {
|
|
231
|
+
static BRAND = "tango.orm.sqlite_adapter";
|
|
232
|
+
__tangoBrand = SqliteAdapter.BRAND;
|
|
233
|
+
name = "sqlite";
|
|
234
|
+
dialect = InternalDialect.SQLITE;
|
|
235
|
+
features = {
|
|
236
|
+
transactionalDDL: true,
|
|
237
|
+
concurrentIndex: false,
|
|
238
|
+
validateForeignKeys: false,
|
|
239
|
+
ignoreDuplicateInsert: true
|
|
240
|
+
};
|
|
241
|
+
placeholders = {
|
|
242
|
+
at() {
|
|
243
|
+
return "?";
|
|
244
|
+
},
|
|
245
|
+
list(count) {
|
|
246
|
+
return Array.from({ length: count }, () => "?").join(", ");
|
|
247
|
+
},
|
|
248
|
+
listFromOffset(count) {
|
|
249
|
+
return this.list(count);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* Narrow an unknown value to `SqliteAdapter`.
|
|
254
|
+
*/
|
|
255
|
+
static isSqliteAdapter(value) {
|
|
256
|
+
return typeof value === "object" && value !== null && value.__tangoBrand === SqliteAdapter.BRAND;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Open a SQLite database and apply baseline pragmas for durability/safety.
|
|
260
|
+
*/
|
|
261
|
+
async connect(config = {}) {
|
|
262
|
+
const db = new (this.getDatabaseCtor())(typeof config.filename === "string" && config.filename.length > 0 ? config.filename : ":memory:");
|
|
263
|
+
db.pragma("journal_mode = WAL");
|
|
264
|
+
db.pragma("foreign_keys = ON");
|
|
265
|
+
db.pragma("busy_timeout = 5000");
|
|
266
|
+
return new SqliteClient(db);
|
|
267
|
+
}
|
|
268
|
+
getDatabaseCtor() {
|
|
269
|
+
const moduleValue = createRequire(import.meta.url)("better-sqlite3");
|
|
270
|
+
if (typeof moduleValue === "function") return moduleValue;
|
|
271
|
+
const defaultExport = moduleValue.default;
|
|
272
|
+
if (typeof defaultExport === "function") return defaultExport;
|
|
273
|
+
throw new TypeError("Failed to load better-sqlite3 constructor.");
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
//#endregion
|
|
277
|
+
export { PostgresAdapter_exports as a, PostgresAdapter as i, SqliteAdapter_exports as n, PostgresClient as o, SqliteClient as r, SqliteAdapter as t };
|
|
278
|
+
|
|
279
|
+
//# sourceMappingURL=SqliteAdapter-6oyUmoJf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqliteAdapter-6oyUmoJf.js","names":[],"sources":["../src/connection/clients/dialects/PostgresClient.ts","../src/connection/adapters/dialects/PostgresAdapter.ts","../src/connection/clients/dialects/SqliteClient.ts","../src/connection/adapters/dialects/SqliteAdapter.ts"],"sourcesContent":["import type { DBClient } from '../DBClient';\n\nexport interface PostgresPoolClientLike {\n query(sql: string, params?: readonly unknown[]): Promise<{ rows: unknown[] }>;\n release(): void;\n}\n\n/**\n * Transaction-capable client backed by a PostgreSQL pool client.\n */\nexport class PostgresClient implements DBClient {\n static readonly BRAND = 'tango.orm.postgres_client' as const;\n readonly __tangoBrand: typeof PostgresClient.BRAND = PostgresClient.BRAND;\n\n constructor(private client: PostgresPoolClientLike) {}\n\n /**\n * Narrow an unknown value to `PostgresClient`.\n */\n static isPostgresClient(value: unknown): value is PostgresClient {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === PostgresClient.BRAND\n );\n }\n\n /**\n * Execute a SQL statement with optional bound parameters.\n */\n async query<T = unknown>(sql: string, params?: readonly unknown[]): Promise<{ rows: T[] }> {\n const result = await this.client.query(sql, params as unknown[]);\n return { rows: result.rows as T[] };\n }\n\n /**\n * Begin a database transaction.\n */\n async begin(): Promise<void> {\n await this.client.query('BEGIN');\n }\n\n /**\n * Commit the active transaction.\n */\n async commit(): Promise<void> {\n await this.client.query('COMMIT');\n }\n\n /**\n * Roll back the active transaction.\n */\n async rollback(): Promise<void> {\n await this.client.query('ROLLBACK');\n }\n\n /**\n * Create a savepoint inside the active transaction.\n */\n async createSavepoint(name: string): Promise<void> {\n await this.client.query(`SAVEPOINT ${name}`);\n }\n\n /**\n * Release a previously-created savepoint.\n */\n async releaseSavepoint(name: string): Promise<void> {\n await this.client.query(`RELEASE SAVEPOINT ${name}`);\n }\n\n /**\n * Roll back the active transaction to a savepoint.\n */\n async rollbackToSavepoint(name: string): Promise<void> {\n await this.client.query(`ROLLBACK TO SAVEPOINT ${name}`);\n }\n\n /**\n * Release the leased PostgreSQL client back to its owning pool.\n */\n async close(): Promise<void> {\n this.client.release();\n }\n}\n","import pg from 'pg';\nimport type { Adapter, AdapterConfig, SqlPlaceholders } from '../Adapter';\nimport type { DBClient } from '../../clients/DBClient';\nimport { PostgresClient } from '../../clients/dialects/PostgresClient';\nimport { InternalDialect } from '../../../query/domain/internal/InternalDialect';\n\nconst { Pool } = pg;\n\n/**\n * Postgres adapter that turns adapter config into a transactional `DBClient`.\n */\nexport class PostgresAdapter implements Adapter {\n static readonly BRAND = 'tango.orm.postgres_adapter' as const;\n readonly __tangoBrand: typeof PostgresAdapter.BRAND = PostgresAdapter.BRAND;\n readonly name = 'postgres';\n readonly dialect: Adapter['dialect'] = InternalDialect.POSTGRES;\n /**\n * Declares capabilities of this database adapter.\n * Used by the migration runner and query compiler to determine which\n * SQL features can be safely used:\n * - transactionalDDL: Postgres supports DDL inside transactions (safe rollback of schema changes)\n * - concurrentIndex: Supports CREATE INDEX CONCURRENTLY (non-blocking index builds)\n * - validateForeignKeys: Supports deferred FK validation via NOT VALID + VALIDATE CONSTRAINT\n * - ignoreDuplicateInsert: Supports duplicate-safe insert semantics for manager-owned link writes\n */\n readonly features: Adapter['features'] = {\n transactionalDDL: true,\n concurrentIndex: true,\n validateForeignKeys: true,\n ignoreDuplicateInsert: true,\n };\n readonly placeholders: SqlPlaceholders = {\n at(index: number): string {\n return `$${index}`;\n },\n list(count: number): string {\n return this.listFromOffset(count, 0);\n },\n listFromOffset(count: number, startOffset: number): string {\n return Array.from({ length: count }, (_value, index) => `$${startOffset + index + 1}`).join(', ');\n },\n };\n\n /**\n * Narrow an unknown value to `PostgresAdapter`.\n */\n static isPostgresAdapter(value: unknown): value is PostgresAdapter {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === PostgresAdapter.BRAND\n );\n }\n\n /**\n * Open a Postgres connection pool and return a client-backed DB abstraction.\n */\n async connect(config: AdapterConfig): Promise<DBClient> {\n const pool = new Pool({\n connectionString: config.url,\n host: config.host,\n port: config.port,\n database: config.database,\n user: config.user,\n password: config.password,\n max: config.maxConnections || 10,\n });\n\n const client = await pool.connect();\n return new PostgresClient(client);\n }\n}\n","import type Database from 'better-sqlite3';\nimport type { DBClient } from '../DBClient';\n\n/**\n * Transaction-capable client backed by a synchronous `better-sqlite3` handle.\n */\nexport class SqliteClient implements DBClient {\n static readonly BRAND = 'tango.orm.sqlite_client' as const;\n readonly __tangoBrand: typeof SqliteClient.BRAND = SqliteClient.BRAND;\n private inTransaction = false;\n\n constructor(private db: Database.Database) {}\n\n /**\n * Narrow an unknown value to `SqliteClient`.\n */\n static isSqliteClient(value: unknown): value is SqliteClient {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === SqliteClient.BRAND\n );\n }\n\n /**\n * Execute a SQL statement with optional parameters.\n *\n * `SELECT`/`PRAGMA` statements return row data; write statements return\n * an empty row list.\n */\n async query<T = unknown>(sql: string, params?: readonly unknown[]): Promise<{ rows: T[] }> {\n const stmt = this.db.prepare(sql);\n const isPragmaWrite = /^\\s*PRAGMA\\b/i.test(sql) && /=/.test(sql);\n\n const normalizedParams = params?.map((param) => this.normalizeParam(param));\n\n if (!isPragmaWrite && stmt.reader) {\n const rows = normalizedParams ? stmt.all(...(normalizedParams as unknown[])) : stmt.all();\n return { rows: rows as T[] };\n }\n\n if (normalizedParams) {\n stmt.run(...(normalizedParams as unknown[]));\n } else {\n stmt.run();\n }\n return { rows: [] };\n }\n\n /**\n * Begin a transaction if one is not already active.\n */\n async begin(): Promise<void> {\n if (!this.inTransaction) {\n this.db.prepare('BEGIN IMMEDIATE').run();\n this.inTransaction = true;\n }\n }\n\n /**\n * Commit the active transaction.\n */\n async commit(): Promise<void> {\n if (this.inTransaction) {\n this.db.prepare('COMMIT').run();\n this.inTransaction = false;\n }\n }\n\n /**\n * Roll back the active transaction.\n */\n async rollback(): Promise<void> {\n if (this.inTransaction) {\n this.db.prepare('ROLLBACK').run();\n this.inTransaction = false;\n }\n }\n\n /**\n * Create a savepoint inside the active transaction.\n */\n async createSavepoint(name: string): Promise<void> {\n this.db.prepare(`SAVEPOINT ${name}`).run();\n }\n\n /**\n * Release a previously-created savepoint.\n */\n async releaseSavepoint(name: string): Promise<void> {\n this.db.prepare(`RELEASE SAVEPOINT ${name}`).run();\n }\n\n /**\n * Roll back the active transaction to a savepoint.\n */\n async rollbackToSavepoint(name: string): Promise<void> {\n this.db.prepare(`ROLLBACK TO SAVEPOINT ${name}`).run();\n }\n\n /**\n * Close the underlying SQLite handle.\n */\n async close(): Promise<void> {\n this.db.close();\n }\n\n private normalizeParam(value: unknown): unknown {\n if (isDateValue(value)) {\n return value.toISOString();\n }\n if (typeof value === 'boolean') {\n return value ? 1 : 0;\n }\n return value;\n }\n}\n\nfunction isDateValue(value: unknown): value is Date {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { getTime?: unknown }).getTime === 'function' &&\n typeof (value as { toISOString?: unknown }).toISOString === 'function'\n );\n}\n","import { createRequire } from 'node:module';\nimport type { Database as BetterSqliteDatabase } from 'better-sqlite3';\nimport type { Adapter, AdapterConfig, SqlPlaceholders } from '../Adapter';\nimport type { DBClient } from '../../clients/DBClient';\nimport { SqliteClient } from '../../clients/dialects/SqliteClient';\nimport { InternalDialect } from '../../../query/domain/internal/InternalDialect';\n\ntype BetterSqliteCtor = new (filename: string, options?: unknown) => BetterSqliteDatabase;\n\n/**\n * SQLite adapter that creates a `better-sqlite3` backed `DBClient`.\n */\nexport class SqliteAdapter implements Adapter {\n static readonly BRAND = 'tango.orm.sqlite_adapter' as const;\n readonly __tangoBrand: typeof SqliteAdapter.BRAND = SqliteAdapter.BRAND;\n readonly name = 'sqlite';\n readonly dialect: Adapter['dialect'] = InternalDialect.SQLITE;\n readonly features: Adapter['features'] = {\n transactionalDDL: true,\n concurrentIndex: false,\n validateForeignKeys: false,\n ignoreDuplicateInsert: true,\n };\n readonly placeholders: SqlPlaceholders = {\n at(): string {\n return '?';\n },\n list(count: number): string {\n return Array.from({ length: count }, () => '?').join(', ');\n },\n listFromOffset(count: number): string {\n return this.list(count);\n },\n };\n\n /**\n * Narrow an unknown value to `SqliteAdapter`.\n */\n static isSqliteAdapter(value: unknown): value is SqliteAdapter {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === SqliteAdapter.BRAND\n );\n }\n\n /**\n * Open a SQLite database and apply baseline pragmas for durability/safety.\n */\n async connect(config: AdapterConfig = {}): Promise<DBClient> {\n const Database = this.getDatabaseCtor();\n const filename =\n typeof config.filename === 'string' && config.filename.length > 0 ? config.filename : ':memory:';\n const db = new Database(filename);\n db.pragma('journal_mode = WAL');\n db.pragma('foreign_keys = ON');\n db.pragma('busy_timeout = 5000');\n\n return new SqliteClient(db);\n }\n\n private getDatabaseCtor(): BetterSqliteCtor {\n const require = createRequire(import.meta.url);\n const moduleValue = require('better-sqlite3') as unknown;\n if (typeof moduleValue === 'function') {\n return moduleValue as BetterSqliteCtor;\n }\n\n const defaultExport = (moduleValue as { default?: unknown }).default;\n if (typeof defaultExport === 'function') {\n return defaultExport as BetterSqliteCtor;\n }\n\n throw new TypeError('Failed to load better-sqlite3 constructor.');\n }\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,iBAAb,MAAa,eAAmC;CAIxB;CAHpB,OAAgB,QAAQ;CACxB,eAAqD,eAAe;CAEpE,YAAY,QAAwC;EAAhC,KAAA,SAAA;CAAiC;;;;CAKrD,OAAO,iBAAiB,OAAyC;EAC7D,OACI,OAAO,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB,eAAe;CAE9E;;;;CAKA,MAAM,MAAmB,KAAa,QAAqD;EAEvF,OAAO,EAAE,OAAM,MADM,KAAK,OAAO,MAAM,KAAK,MAAmB,GACzC,KAAY;CACtC;;;;CAKA,MAAM,QAAuB;EACzB,MAAM,KAAK,OAAO,MAAM,OAAO;CACnC;;;;CAKA,MA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CAEA,kBAA4C;EAExC,MAAM,cADU,cAAc,OAAO,KAAK,GAChB,EAAE,gBAAgB;EAC5C,IAAI,OAAO,gBAAgB,YACvB,OAAO;EAGX,MAAM,gBAAiB,YAAsC;EAC7D,IAAI,OAAO,kBAAkB,YACzB,OAAO;EAGX,MAAM,IAAI,UAAU,4CAA4C;CACpE;AACJ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __exportAll = (all, no_symbols) => {
|
|
5
|
+
let target = {};
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
11
|
+
return target;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { __exportAll as t };
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export * as adapters from './adapters/index';
|
|
6
|
-
export * as clients from './clients/index';
|
|
7
|
-
export { AdapterRegistry, connectDB, getDefaultAdapterRegistry } from './adapters/index';
|
|
8
|
-
export type { Adapter, AdapterConfig, SqlPlaceholders } from './adapters/index';
|
|
9
|
-
export type { DBClient } from './clients/DBClient';
|
|
10
|
-
export { PostgresAdapter, SqliteAdapter } from './adapters/index';
|
|
11
|
-
export { PostgresClient, SqliteClient } from './clients/index';
|
|
1
|
+
import { t as DBClient } from "../DBClient-DuYcXolQ.js";
|
|
2
|
+
import { n as AdapterConfig, r as SqlPlaceholders, t as Adapter } from "../Adapter-DKxAaL4l.js";
|
|
3
|
+
import { a as index_d_exports, c as getDefaultAdapterRegistry, i as PostgresClient, l as SqliteAdapter, n as index_d_exports$1, o as AdapterRegistry, r as SqliteClient, s as connectDB, u as PostgresAdapter } from "../index-B-aibguC.js";
|
|
4
|
+
export { type Adapter, type AdapterConfig, AdapterRegistry, type DBClient, PostgresAdapter, PostgresClient, type SqlPlaceholders, SqliteAdapter, SqliteClient, index_d_exports as adapters, index_d_exports$1 as clients, connectDB, getDefaultAdapterRegistry };
|
package/dist/connection/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { PostgresAdapter, PostgresClient } from "../
|
|
2
|
-
import "../
|
|
3
|
-
|
|
4
|
-
import { AdapterRegistry, adapters_exports, clients_exports, connectDB, getDefaultAdapterRegistry } from "../connection-Dmhgx31M.js";
|
|
5
|
-
|
|
6
|
-
export { AdapterRegistry, PostgresAdapter, PostgresClient, SqliteAdapter, SqliteClient, adapters_exports as adapters, clients_exports as clients, connectDB, getDefaultAdapterRegistry };
|
|
1
|
+
import { i as PostgresAdapter, o as PostgresClient, r as SqliteClient, t as SqliteAdapter } from "../SqliteAdapter-6oyUmoJf.js";
|
|
2
|
+
import { a as connectDB, i as AdapterRegistry, n as clients_exports, o as getDefaultAdapterRegistry, r as adapters_exports } from "../connection-D-E6_Yf1.js";
|
|
3
|
+
export { AdapterRegistry, PostgresAdapter, PostgresClient, SqliteAdapter, SqliteClient, adapters_exports as adapters, clients_exports as clients, connectDB, getDefaultAdapterRegistry };
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PostgresAdapter, PostgresClient } from "./
|
|
3
|
-
import { SqliteAdapter, SqliteClient } from "./SqliteAdapter-CDdOjRmW.js";
|
|
4
|
-
|
|
1
|
+
import { t as __exportAll } from "./chunk-8H4AJuhK.js";
|
|
2
|
+
import { i as PostgresAdapter, o as PostgresClient, r as SqliteClient, t as SqliteAdapter } from "./SqliteAdapter-6oyUmoJf.js";
|
|
5
3
|
//#region src/connection/adapters/dialects/index.ts
|
|
6
|
-
var dialects_exports$1 = {
|
|
7
|
-
__export(dialects_exports$1, {
|
|
4
|
+
var dialects_exports$1 = /* @__PURE__ */ __exportAll({
|
|
8
5
|
PostgresAdapter: () => PostgresAdapter,
|
|
9
6
|
SqliteAdapter: () => SqliteAdapter
|
|
10
7
|
});
|
|
11
|
-
|
|
12
8
|
//#endregion
|
|
13
9
|
//#region src/connection/adapters/AdapterRegistry.ts
|
|
10
|
+
/**
|
|
11
|
+
* Runtime registry for database adapters.
|
|
12
|
+
*
|
|
13
|
+
* Use a custom instance when tests or applications need explicit control
|
|
14
|
+
* over supported adapters; use `getDefaultRegistry()` for the built-in set.
|
|
15
|
+
*/
|
|
14
16
|
var AdapterRegistry = class AdapterRegistry {
|
|
15
17
|
static BRAND = "tango.orm.adapter_registry";
|
|
16
18
|
static defaultRegistryInstance;
|
|
17
19
|
__tangoBrand = AdapterRegistry.BRAND;
|
|
18
|
-
adapters = new Map();
|
|
20
|
+
adapters = /* @__PURE__ */ new Map();
|
|
19
21
|
/**
|
|
20
22
|
* Narrow an unknown value to `AdapterRegistry`.
|
|
21
23
|
*/
|
|
@@ -28,10 +30,10 @@ var AdapterRegistry = class AdapterRegistry {
|
|
|
28
30
|
static async getDefaultRegistry() {
|
|
29
31
|
if (AdapterRegistry.defaultRegistryInstance) return AdapterRegistry.defaultRegistryInstance;
|
|
30
32
|
AdapterRegistry.defaultRegistryInstance = new AdapterRegistry();
|
|
31
|
-
const { PostgresAdapter
|
|
32
|
-
const { SqliteAdapter
|
|
33
|
-
AdapterRegistry.defaultRegistryInstance.register(new PostgresAdapter
|
|
34
|
-
AdapterRegistry.defaultRegistryInstance.register(new SqliteAdapter
|
|
33
|
+
const { PostgresAdapter } = await import("./SqliteAdapter-6oyUmoJf.js").then((n) => n.a);
|
|
34
|
+
const { SqliteAdapter } = await import("./SqliteAdapter-6oyUmoJf.js").then((n) => n.n);
|
|
35
|
+
AdapterRegistry.defaultRegistryInstance.register(new PostgresAdapter());
|
|
36
|
+
AdapterRegistry.defaultRegistryInstance.register(new SqliteAdapter());
|
|
35
37
|
return AdapterRegistry.defaultRegistryInstance;
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
@@ -59,19 +61,21 @@ var AdapterRegistry = class AdapterRegistry {
|
|
|
59
61
|
return this.adapters.has(name);
|
|
60
62
|
}
|
|
61
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Connect to a database by adapter name using the provided (or default) registry.
|
|
66
|
+
*/
|
|
62
67
|
async function connectDB(config, registry) {
|
|
63
|
-
|
|
64
|
-
const adapter = effectiveRegistry.get(config.adapter);
|
|
65
|
-
return adapter.connect(config);
|
|
68
|
+
return (registry ?? await AdapterRegistry.getDefaultRegistry()).get(config.adapter).connect(config);
|
|
66
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Convenience helper that exposes the singleton default adapter registry.
|
|
72
|
+
*/
|
|
67
73
|
async function getDefaultAdapterRegistry() {
|
|
68
74
|
return AdapterRegistry.getDefaultRegistry();
|
|
69
75
|
}
|
|
70
|
-
|
|
71
76
|
//#endregion
|
|
72
77
|
//#region src/connection/adapters/index.ts
|
|
73
|
-
var adapters_exports = {
|
|
74
|
-
__export(adapters_exports, {
|
|
78
|
+
var adapters_exports = /* @__PURE__ */ __exportAll({
|
|
75
79
|
AdapterRegistry: () => AdapterRegistry,
|
|
76
80
|
PostgresAdapter: () => PostgresAdapter,
|
|
77
81
|
SqliteAdapter: () => SqliteAdapter,
|
|
@@ -79,28 +83,22 @@ __export(adapters_exports, {
|
|
|
79
83
|
dialects: () => dialects_exports$1,
|
|
80
84
|
getDefaultAdapterRegistry: () => getDefaultAdapterRegistry
|
|
81
85
|
});
|
|
82
|
-
|
|
83
86
|
//#endregion
|
|
84
87
|
//#region src/connection/clients/dialects/index.ts
|
|
85
|
-
var dialects_exports = {
|
|
86
|
-
__export(dialects_exports, {
|
|
88
|
+
var dialects_exports = /* @__PURE__ */ __exportAll({
|
|
87
89
|
PostgresClient: () => PostgresClient,
|
|
88
90
|
SqliteClient: () => SqliteClient
|
|
89
91
|
});
|
|
90
|
-
|
|
91
92
|
//#endregion
|
|
92
93
|
//#region src/connection/clients/index.ts
|
|
93
|
-
var clients_exports = {
|
|
94
|
-
__export(clients_exports, {
|
|
94
|
+
var clients_exports = /* @__PURE__ */ __exportAll({
|
|
95
95
|
PostgresClient: () => PostgresClient,
|
|
96
96
|
SqliteClient: () => SqliteClient,
|
|
97
97
|
dialects: () => dialects_exports
|
|
98
98
|
});
|
|
99
|
-
|
|
100
99
|
//#endregion
|
|
101
100
|
//#region src/connection/index.ts
|
|
102
|
-
var connection_exports = {
|
|
103
|
-
__export(connection_exports, {
|
|
101
|
+
var connection_exports = /* @__PURE__ */ __exportAll({
|
|
104
102
|
AdapterRegistry: () => AdapterRegistry,
|
|
105
103
|
PostgresAdapter: () => PostgresAdapter,
|
|
106
104
|
PostgresClient: () => PostgresClient,
|
|
@@ -111,7 +109,7 @@ __export(connection_exports, {
|
|
|
111
109
|
connectDB: () => connectDB,
|
|
112
110
|
getDefaultAdapterRegistry: () => getDefaultAdapterRegistry
|
|
113
111
|
});
|
|
114
|
-
|
|
115
112
|
//#endregion
|
|
116
|
-
export {
|
|
117
|
-
|
|
113
|
+
export { connectDB as a, AdapterRegistry as i, clients_exports as n, getDefaultAdapterRegistry as o, adapters_exports as r, connection_exports as t };
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=connection-D-E6_Yf1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-D-E6_Yf1.js","names":[],"sources":["../src/connection/adapters/dialects/index.ts","../src/connection/adapters/AdapterRegistry.ts","../src/connection/adapters/index.ts","../src/connection/clients/dialects/index.ts","../src/connection/clients/index.ts","../src/connection/index.ts"],"sourcesContent":["/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport { PostgresAdapter } from './PostgresAdapter';\nexport { SqliteAdapter } from './SqliteAdapter';\n","import type { Adapter, AdapterConfig } from './Adapter';\nimport type { DBClient } from '../clients/DBClient';\n\n/**\n * Runtime registry for database adapters.\n *\n * Use a custom instance when tests or applications need explicit control\n * over supported adapters; use `getDefaultRegistry()` for the built-in set.\n */\nexport class AdapterRegistry {\n static readonly BRAND = 'tango.orm.adapter_registry' as const;\n private static defaultRegistryInstance: AdapterRegistry | undefined;\n readonly __tangoBrand: typeof AdapterRegistry.BRAND = AdapterRegistry.BRAND;\n private adapters = new Map<string, Adapter>();\n\n /**\n * Narrow an unknown value to `AdapterRegistry`.\n */\n static isAdapterRegistry(value: unknown): value is AdapterRegistry {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === AdapterRegistry.BRAND\n );\n }\n\n /**\n * Return a lazily-initialized registry preloaded with built-in adapters.\n */\n static async getDefaultRegistry(): Promise<AdapterRegistry> {\n if (AdapterRegistry.defaultRegistryInstance) {\n return AdapterRegistry.defaultRegistryInstance;\n }\n\n AdapterRegistry.defaultRegistryInstance = new AdapterRegistry();\n\n const { PostgresAdapter } = await import('./dialects/PostgresAdapter');\n const { SqliteAdapter } = await import('./dialects/SqliteAdapter');\n\n AdapterRegistry.defaultRegistryInstance.register(new PostgresAdapter());\n AdapterRegistry.defaultRegistryInstance.register(new SqliteAdapter());\n\n return AdapterRegistry.defaultRegistryInstance;\n }\n\n /**\n * Register an adapter under its declared `name`.\n */\n register(adapter: Adapter): this {\n this.adapters.set(adapter.name, adapter);\n return this;\n }\n\n /**\n * Resolve an adapter by name, or throw a descriptive error.\n */\n get(name: string): Adapter {\n const adapter = this.adapters.get(name);\n if (!adapter) {\n const available = [...this.adapters.keys()].join(', ');\n throw new Error(`Unknown adapter: ${name}. Available adapters: ${available || 'none'}`);\n }\n return adapter;\n }\n\n /**\n * Check whether an adapter has been registered.\n */\n has(name: string): boolean {\n return this.adapters.has(name);\n }\n}\n\n/**\n * Connect to a database by adapter name using the provided (or default) registry.\n */\nexport async function connectDB(\n config: AdapterConfig & { adapter: string },\n registry?: AdapterRegistry\n): Promise<DBClient> {\n const effectiveRegistry = registry ?? (await AdapterRegistry.getDefaultRegistry());\n const adapter = effectiveRegistry.get(config.adapter);\n return adapter.connect(config);\n}\n\n/**\n * Convenience helper that exposes the singleton default adapter registry.\n */\nexport async function getDefaultAdapterRegistry(): Promise<AdapterRegistry> {\n return AdapterRegistry.getDefaultRegistry();\n}\n","/**\n * Domain boundary barrel: exposes namespaced exports for Django-style drill-down\n * imports and curated flat exports for TS-native ergonomics.\n */\n\nexport * as dialects from './dialects/index';\n\nexport { AdapterRegistry, connectDB, getDefaultAdapterRegistry } from './AdapterRegistry';\nexport type { Adapter, AdapterConfig, SqlPlaceholders } from './Adapter';\nexport { PostgresAdapter, SqliteAdapter } from './dialects/index';\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport { PostgresClient } from './PostgresClient';\nexport { SqliteClient } from './SqliteClient';\n","/**\n * Domain boundary barrel: exposes namespaced exports for Django-style drill-down\n * imports and curated flat exports for TS-native ergonomics.\n */\n\nexport * as dialects from './dialects/index';\n\nexport type { DBClient } from './DBClient';\nexport { PostgresClient, SqliteClient } from './dialects/index';\n","/**\n * Domain boundary barrel: exposes namespaced exports for Django-style drill-down\n * imports and curated flat exports for TS-native ergonomics.\n */\n\nexport * as adapters from './adapters/index';\nexport * as clients from './clients/index';\n\nexport { AdapterRegistry, connectDB, getDefaultAdapterRegistry } from './adapters/index';\nexport type { Adapter, AdapterConfig, SqlPlaceholders } from './adapters/index';\nexport type { DBClient } from './clients/DBClient';\nexport { PostgresAdapter, SqliteAdapter } from './adapters/index';\nexport { PostgresClient, SqliteClient } from './clients/index';\n"],"mappings":";;;;;;;;;;;;;;;ACSA,IAAa,kBAAb,MAAa,gBAAgB;CACzB,OAAgB,QAAQ;CACxB,OAAe;CACf,eAAsD,gBAAgB;CACtE,2BAAmB,IAAI,IAAqB;;;;CAK5C,OAAO,kBAAkB,OAA0C;EAC/D,OACI,OAAO,UAAU,YACjB,UAAU,QACT,MAAqC,iBAAiB,gBAAgB;CAE/E;;;;CAKA,aAAa,qBAA+C;EACxD,IAAI,gBAAgB,yBAChB,OAAO,gBAAgB;EAG3B,g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