azure-mock 2.22.0 → 2.24.0

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.
Files changed (47) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +15 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +22244 -23627
  5. package/dist/tsconfig.tsbuildinfo +1 -0
  6. package/package.json +9 -8
  7. package/dist/better-sqlite3-CtLaF97z-DWR9uC3b.js +0 -129
  8. package/dist/chunk-2X2C5D2I-dJHtPFe9-DxsO-1YF.js +0 -4026
  9. package/dist/d1-pK2J-_yx-BoQTXsTa.js +0 -185
  10. package/dist/dialect-pBb6Cg_F-xgpUtfmk.js +0 -570
  11. package/dist/dist-C481edUb-CHbOkeXH.js +0 -10131
  12. package/dist/dist-DUzzleZr-DxHmeYjp.js +0 -2
  13. package/dist/libsql-Nq-S0r5x-d2dAzhgO.js +0 -240
  14. package/dist/logger-TIsK7375-CLNNa25D.js +0 -652
  15. package/dist/migrator-B9kYwLqO-4g9JX3_v.js +0 -8
  16. package/dist/migrator-BfTfJctM-DrNlb1BS.js +0 -8
  17. package/dist/migrator-BjoW0_3j-CD-XdZ5a.js +0 -8
  18. package/dist/migrator-CWWlo_Jk-C4Hw4PPN.js +0 -8
  19. package/dist/migrator-CpiXRkls-COYfhljd.js +0 -24
  20. package/dist/migrator-CtqJkLVI-D1lU6ZV0.js +0 -8
  21. package/dist/migrator-CxcBjmET-Dcd21VIf.js +0 -8
  22. package/dist/migrator-Cyhbhxo_-Bh7sF0R3.js +0 -21
  23. package/dist/migrator-DG1mWUoR-DVfkqn_v.js +0 -31
  24. package/dist/migrator-DrWmHwY2-YjAfotd7.js +0 -8
  25. package/dist/migrator-WAPonQxA-CRvJJhKG.js +0 -8
  26. package/dist/migrator-Zdh8WMMx-gsmNXspd.js +0 -8
  27. package/dist/migrator-xRJ6NOTS-SsAuB-Gi.js +0 -24
  28. package/dist/migrator-xbWwvFYF-BjyVdQS8.js +0 -8
  29. package/dist/mysql2-DkoPEsRu-BMwVSCmY.js +0 -251
  30. package/dist/neon-serverless-BEVFA7yv-DGSPAG1z.js +0 -205
  31. package/dist/node-postgres-DQA7bEhW-CkM_cVLD.js +0 -216
  32. package/dist/nodefs-Bc8b83o_-DetP9qUa.js +0 -24
  33. package/dist/opfs-ahp-DbstDvx--CHskKtzG.js +0 -365
  34. package/dist/pg-ylxXyvKj-Hm8vcZoi.js +0 -279
  35. package/dist/pglite-CPs4w-D9-DHOg0D8W.js +0 -179
  36. package/dist/pglite-DMWgTUE6-BOIRUWUT.js +0 -2
  37. package/dist/planetscale-serverless-DUMheN-f-Dyc_W6V_.js +0 -172
  38. package/dist/query-builder-CLJAKedv-DTZiP7B6.js +0 -1715
  39. package/dist/query-builder-CT3_liD0-hhg5kRTk.js +0 -1347
  40. package/dist/session-BOEirggu-DTmpyU_x.js +0 -2485
  41. package/dist/session-CAUQtT0A-BoVK2x7A.js +0 -745
  42. package/dist/session-Cjeygn2Z-BO0mi6pq.js +0 -989
  43. package/dist/singlestore-Cdlo23hW-BuFJ4Zqb.js +0 -1647
  44. package/dist/sql-CNZp2yLp-Bwugq384.js +0 -611
  45. package/dist/sqlite-proxy-BgUfVEbZ-CsSkc-_K.js +0 -190
  46. package/dist/src-LcyXhCXE-C_vKJiLK.js +0 -1920
  47. package/dist/vercel-postgres-BYmFKsTS-CpV2usun.js +0 -203
@@ -1,652 +0,0 @@
1
- import { C as sql, S as isSQLWrapper, b as is, d as Table, g as entityKind, l as StringChunk, m as ViewBaseConfig, o as Placeholder, p as View, r as Param, s as SQL, t as Column, u as Subquery, v as getTableName, x as isDriverValueEncoder, y as getTableUniqueName } from "./sql-CNZp2yLp-Bwugq384.js";
2
- //#region ../db/dist/logger-TIsK7375.js
3
- function toSnakeCase(input) {
4
- return (input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? []).map((word) => word.toLowerCase()).join("_");
5
- }
6
- function toCamelCase(input) {
7
- return (input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? []).reduce((acc, word, i) => {
8
- return acc + (i === 0 ? word.toLowerCase() : `${word[0].toUpperCase()}${word.slice(1)}`);
9
- }, "");
10
- }
11
- function noopCase(input) {
12
- return input;
13
- }
14
- var CasingCache = class {
15
- static [entityKind] = "CasingCache";
16
- /** @internal */
17
- cache = {};
18
- cachedTables = {};
19
- convert;
20
- constructor(casing) {
21
- this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase;
22
- }
23
- getColumnCasing(column) {
24
- if (!column.keyAsName) return column.name;
25
- const key = `${column.table[Table.Symbol.Schema] ?? "public"}.${column.table[Table.Symbol.OriginalName]}.${column.name}`;
26
- if (!this.cache[key]) this.cacheTable(column.table);
27
- return this.cache[key];
28
- }
29
- cacheTable(table) {
30
- const tableKey = `${table[Table.Symbol.Schema] ?? "public"}.${table[Table.Symbol.OriginalName]}`;
31
- if (!this.cachedTables[tableKey]) {
32
- for (const column of Object.values(table[Table.Symbol.Columns])) {
33
- const columnKey = `${tableKey}.${column.name}`;
34
- this.cache[columnKey] = this.convert(column.name);
35
- }
36
- this.cachedTables[tableKey] = true;
37
- }
38
- }
39
- clearCache() {
40
- this.cache = {};
41
- this.cachedTables = {};
42
- }
43
- };
44
- var ColumnAliasProxyHandler = class {
45
- constructor(table) {
46
- this.table = table;
47
- }
48
- static [entityKind] = "ColumnAliasProxyHandler";
49
- get(columnObj, prop) {
50
- if (prop === "table") return this.table;
51
- return columnObj[prop];
52
- }
53
- };
54
- var TableAliasProxyHandler = class {
55
- constructor(alias, replaceOriginalName) {
56
- this.alias = alias;
57
- this.replaceOriginalName = replaceOriginalName;
58
- }
59
- static [entityKind] = "TableAliasProxyHandler";
60
- get(target, prop) {
61
- if (prop === Table.Symbol.IsAlias) return true;
62
- if (prop === Table.Symbol.Name) return this.alias;
63
- if (this.replaceOriginalName && prop === Table.Symbol.OriginalName) return this.alias;
64
- if (prop === ViewBaseConfig) return {
65
- ...target[ViewBaseConfig],
66
- name: this.alias,
67
- isAlias: true
68
- };
69
- if (prop === Table.Symbol.Columns) {
70
- const columns = target[Table.Symbol.Columns];
71
- if (!columns) return columns;
72
- const proxiedColumns = {};
73
- Object.keys(columns).map((key) => {
74
- proxiedColumns[key] = new Proxy(columns[key], new ColumnAliasProxyHandler(new Proxy(target, this)));
75
- });
76
- return proxiedColumns;
77
- }
78
- const value = target[prop];
79
- if (is(value, Column)) return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(target, this)));
80
- return value;
81
- }
82
- };
83
- function aliasedTable(table, tableAlias) {
84
- return new Proxy(table, new TableAliasProxyHandler(tableAlias, false));
85
- }
86
- function aliasedTableColumn(column, tableAlias) {
87
- return new Proxy(column, new ColumnAliasProxyHandler(new Proxy(column.table, new TableAliasProxyHandler(tableAlias, false))));
88
- }
89
- function mapColumnsInAliasedSQLToAlias(query, alias) {
90
- return new SQL.Aliased(mapColumnsInSQLToAlias(query.sql, alias), query.fieldAlias);
91
- }
92
- function mapColumnsInSQLToAlias(query, alias) {
93
- return sql.join(query.queryChunks.map((c) => {
94
- if (is(c, Column)) return aliasedTableColumn(c, alias);
95
- if (is(c, SQL)) return mapColumnsInSQLToAlias(c, alias);
96
- if (is(c, SQL.Aliased)) return mapColumnsInAliasedSQLToAlias(c, alias);
97
- return c;
98
- }));
99
- }
100
- function mapResultRow(columns, row, joinsNotNullableMap) {
101
- const nullifyMap = {};
102
- const result = columns.reduce((result2, { path, field }, columnIndex) => {
103
- let decoder;
104
- if (is(field, Column)) decoder = field;
105
- else if (is(field, SQL)) decoder = field.decoder;
106
- else if (is(field, Subquery)) decoder = field._.sql.decoder;
107
- else decoder = field.sql.decoder;
108
- let node = result2;
109
- for (const [pathChunkIndex, pathChunk] of path.entries()) if (pathChunkIndex < path.length - 1) {
110
- if (!(pathChunk in node)) node[pathChunk] = {};
111
- node = node[pathChunk];
112
- } else {
113
- const rawValue = row[columnIndex];
114
- const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
115
- if (joinsNotNullableMap && is(field, Column) && path.length === 2) {
116
- const objectName = path[0];
117
- if (!(objectName in nullifyMap)) nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
118
- else if (typeof nullifyMap[objectName] === "string" && nullifyMap[objectName] !== getTableName(field.table)) nullifyMap[objectName] = false;
119
- }
120
- }
121
- return result2;
122
- }, {});
123
- if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
124
- for (const [objectName, tableName] of Object.entries(nullifyMap)) if (typeof tableName === "string" && !joinsNotNullableMap[tableName]) result[objectName] = null;
125
- }
126
- return result;
127
- }
128
- function orderSelectedFields(fields, pathPrefix) {
129
- return Object.entries(fields).reduce((result, [name, field]) => {
130
- if (typeof name !== "string") return result;
131
- const newPath = pathPrefix ? [...pathPrefix, name] : [name];
132
- if (is(field, Column) || is(field, SQL) || is(field, SQL.Aliased) || is(field, Subquery)) result.push({
133
- path: newPath,
134
- field
135
- });
136
- else if (is(field, Table)) result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));
137
- else result.push(...orderSelectedFields(field, newPath));
138
- return result;
139
- }, []);
140
- }
141
- function haveSameKeys(left, right) {
142
- const leftKeys = Object.keys(left);
143
- const rightKeys = Object.keys(right);
144
- if (leftKeys.length !== rightKeys.length) return false;
145
- for (const [index, key] of leftKeys.entries()) if (key !== rightKeys[index]) return false;
146
- return true;
147
- }
148
- function mapUpdateSet(table, values) {
149
- const entries = Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => {
150
- if (is(value, SQL) || is(value, Column)) return [key, value];
151
- else return [key, new Param(value, table[Table.Symbol.Columns][key])];
152
- });
153
- if (entries.length === 0) throw new Error("No values to set");
154
- return Object.fromEntries(entries);
155
- }
156
- function applyMixins(baseClass, extendedClasses) {
157
- for (const extendedClass of extendedClasses) for (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {
158
- if (name === "constructor") continue;
159
- Object.defineProperty(baseClass.prototype, name, Object.getOwnPropertyDescriptor(extendedClass.prototype, name) || /* @__PURE__ */ Object.create(null));
160
- }
161
- }
162
- function getTableColumns(table) {
163
- return table[Table.Symbol.Columns];
164
- }
165
- function getTableLikeName(table) {
166
- return is(table, Subquery) ? table._.alias : is(table, View) ? table[ViewBaseConfig].name : is(table, SQL) ? void 0 : table[Table.Symbol.IsAlias] ? table[Table.Symbol.Name] : table[Table.Symbol.BaseName];
167
- }
168
- function isConfig(data) {
169
- if (typeof data !== "object" || data === null) return false;
170
- if (data.constructor.name !== "Object") return false;
171
- if ("logger" in data) {
172
- const type = typeof data["logger"];
173
- if (type !== "boolean" && (type !== "object" || typeof data["logger"]["logQuery"] !== "function") && type !== "undefined") return false;
174
- return true;
175
- }
176
- if ("schema" in data) {
177
- const type = typeof data["schema"];
178
- if (type !== "object" && type !== "undefined") return false;
179
- return true;
180
- }
181
- if ("casing" in data) {
182
- const type = typeof data["casing"];
183
- if (type !== "string" && type !== "undefined") return false;
184
- return true;
185
- }
186
- if ("mode" in data) {
187
- if (data["mode"] !== "default" || data["mode"] !== "planetscale" || data["mode"] !== void 0) return false;
188
- return true;
189
- }
190
- if ("connection" in data) {
191
- const type = typeof data["connection"];
192
- if (type !== "string" && type !== "object" && type !== "undefined") return false;
193
- return true;
194
- }
195
- if ("client" in data) {
196
- const type = typeof data["client"];
197
- if (type !== "object" && type !== "function" && type !== "undefined") return false;
198
- return true;
199
- }
200
- if (Object.keys(data).length === 0) return true;
201
- return false;
202
- }
203
- typeof TextDecoder === "undefined" || new TextDecoder();
204
- var SelectionProxyHandler = class SelectionProxyHandler {
205
- static [entityKind] = "SelectionProxyHandler";
206
- config;
207
- constructor(config) {
208
- this.config = { ...config };
209
- }
210
- get(subquery, prop) {
211
- if (prop === "_") return {
212
- ...subquery["_"],
213
- selectedFields: new Proxy(subquery._.selectedFields, this)
214
- };
215
- if (prop === ViewBaseConfig) return {
216
- ...subquery[ViewBaseConfig],
217
- selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
218
- };
219
- if (typeof prop === "symbol") return subquery[prop];
220
- const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
221
- if (is(value, SQL.Aliased)) {
222
- if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
223
- const newValue = value.clone();
224
- newValue.isSelectionField = true;
225
- return newValue;
226
- }
227
- if (is(value, SQL)) {
228
- if (this.config.sqlBehavior === "sql") return value;
229
- throw new Error(`You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`);
230
- }
231
- if (is(value, Column)) {
232
- if (this.config.alias) return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(value.table, new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false))));
233
- return value;
234
- }
235
- if (typeof value !== "object" || value === null) return value;
236
- return new Proxy(value, new SelectionProxyHandler(this.config));
237
- }
238
- };
239
- var QueryPromise = class {
240
- static [entityKind] = "QueryPromise";
241
- [Symbol.toStringTag] = "QueryPromise";
242
- catch(onRejected) {
243
- return this.then(void 0, onRejected);
244
- }
245
- finally(onFinally) {
246
- return this.then((value) => {
247
- onFinally?.();
248
- return value;
249
- }, (reason) => {
250
- onFinally?.();
251
- throw reason;
252
- });
253
- }
254
- then(onFulfilled, onRejected) {
255
- return this.execute().then(onFulfilled, onRejected);
256
- }
257
- };
258
- var DrizzleError = class extends Error {
259
- static [entityKind] = "DrizzleError";
260
- constructor({ message, cause }) {
261
- super(message);
262
- this.name = "DrizzleError";
263
- this.cause = cause;
264
- }
265
- };
266
- var DrizzleQueryError = class DrizzleQueryError extends Error {
267
- constructor(query, params, cause) {
268
- super(`Failed query: ${query}
269
- params: ${params}`);
270
- this.query = query;
271
- this.params = params;
272
- this.cause = cause;
273
- Error.captureStackTrace(this, DrizzleQueryError);
274
- if (cause) this.cause = cause;
275
- }
276
- };
277
- var TransactionRollbackError = class extends DrizzleError {
278
- static [entityKind] = "TransactionRollbackError";
279
- constructor() {
280
- super({ message: "Rollback" });
281
- }
282
- };
283
- const InlineForeignKeys = Symbol.for("drizzle:PgInlineForeignKeys");
284
- const EnableRLS = Symbol.for("drizzle:EnableRLS");
285
- var PgTable = class extends Table {
286
- static [entityKind] = "PgTable";
287
- /** @internal */
288
- static Symbol = Object.assign({}, Table.Symbol, {
289
- InlineForeignKeys,
290
- EnableRLS
291
- });
292
- /**@internal */
293
- [InlineForeignKeys] = [];
294
- /** @internal */
295
- [EnableRLS] = false;
296
- /** @internal */
297
- [Table.Symbol.ExtraConfigBuilder] = void 0;
298
- /** @internal */
299
- [Table.Symbol.ExtraConfigColumns] = {};
300
- };
301
- var PrimaryKeyBuilder = class {
302
- static [entityKind] = "PgPrimaryKeyBuilder";
303
- /** @internal */
304
- columns;
305
- /** @internal */
306
- name;
307
- constructor(columns, name) {
308
- this.columns = columns;
309
- this.name = name;
310
- }
311
- /** @internal */
312
- build(table) {
313
- return new PrimaryKey(table, this.columns, this.name);
314
- }
315
- };
316
- var PrimaryKey = class {
317
- constructor(table, columns, name) {
318
- this.table = table;
319
- this.columns = columns;
320
- this.name = name;
321
- }
322
- static [entityKind] = "PgPrimaryKey";
323
- columns;
324
- name;
325
- getName() {
326
- return this.name ?? `${this.table[PgTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
327
- }
328
- };
329
- function bindIfParam(value, column) {
330
- if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) return new Param(value, column);
331
- return value;
332
- }
333
- const eq = (left, right) => {
334
- return sql`${left} = ${bindIfParam(right, left)}`;
335
- };
336
- const ne = (left, right) => {
337
- return sql`${left} <> ${bindIfParam(right, left)}`;
338
- };
339
- function and(...unfilteredConditions) {
340
- const conditions = unfilteredConditions.filter((c) => c !== void 0);
341
- if (conditions.length === 0) return;
342
- if (conditions.length === 1) return new SQL(conditions);
343
- return new SQL([
344
- new StringChunk("("),
345
- sql.join(conditions, new StringChunk(" and ")),
346
- new StringChunk(")")
347
- ]);
348
- }
349
- function or(...unfilteredConditions) {
350
- const conditions = unfilteredConditions.filter((c) => c !== void 0);
351
- if (conditions.length === 0) return;
352
- if (conditions.length === 1) return new SQL(conditions);
353
- return new SQL([
354
- new StringChunk("("),
355
- sql.join(conditions, new StringChunk(" or ")),
356
- new StringChunk(")")
357
- ]);
358
- }
359
- function not(condition) {
360
- return sql`not ${condition}`;
361
- }
362
- const gt = (left, right) => {
363
- return sql`${left} > ${bindIfParam(right, left)}`;
364
- };
365
- const gte = (left, right) => {
366
- return sql`${left} >= ${bindIfParam(right, left)}`;
367
- };
368
- const lt = (left, right) => {
369
- return sql`${left} < ${bindIfParam(right, left)}`;
370
- };
371
- const lte = (left, right) => {
372
- return sql`${left} <= ${bindIfParam(right, left)}`;
373
- };
374
- function inArray(column, values) {
375
- if (Array.isArray(values)) {
376
- if (values.length === 0) return sql`false`;
377
- return sql`${column} in ${values.map((v) => bindIfParam(v, column))}`;
378
- }
379
- return sql`${column} in ${bindIfParam(values, column)}`;
380
- }
381
- function notInArray(column, values) {
382
- if (Array.isArray(values)) {
383
- if (values.length === 0) return sql`true`;
384
- return sql`${column} not in ${values.map((v) => bindIfParam(v, column))}`;
385
- }
386
- return sql`${column} not in ${bindIfParam(values, column)}`;
387
- }
388
- function isNull(value) {
389
- return sql`${value} is null`;
390
- }
391
- function isNotNull(value) {
392
- return sql`${value} is not null`;
393
- }
394
- function exists(subquery) {
395
- return sql`exists ${subquery}`;
396
- }
397
- function notExists(subquery) {
398
- return sql`not exists ${subquery}`;
399
- }
400
- function between(column, min, max) {
401
- return sql`${column} between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
402
- }
403
- function notBetween(column, min, max) {
404
- return sql`${column} not between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
405
- }
406
- function like(column, value) {
407
- return sql`${column} like ${value}`;
408
- }
409
- function notLike(column, value) {
410
- return sql`${column} not like ${value}`;
411
- }
412
- function ilike(column, value) {
413
- return sql`${column} ilike ${value}`;
414
- }
415
- function notIlike(column, value) {
416
- return sql`${column} not ilike ${value}`;
417
- }
418
- function asc(column) {
419
- return sql`${column} asc`;
420
- }
421
- function desc(column) {
422
- return sql`${column} desc`;
423
- }
424
- var Relation = class {
425
- constructor(sourceTable, referencedTable, relationName) {
426
- this.sourceTable = sourceTable;
427
- this.referencedTable = referencedTable;
428
- this.relationName = relationName;
429
- this.referencedTableName = referencedTable[Table.Symbol.Name];
430
- }
431
- static [entityKind] = "Relation";
432
- referencedTableName;
433
- fieldName;
434
- };
435
- var Relations = class {
436
- constructor(table, config) {
437
- this.table = table;
438
- this.config = config;
439
- }
440
- static [entityKind] = "Relations";
441
- };
442
- var One = class One extends Relation {
443
- constructor(sourceTable, referencedTable, config, isNullable) {
444
- super(sourceTable, referencedTable, config?.relationName);
445
- this.config = config;
446
- this.isNullable = isNullable;
447
- }
448
- static [entityKind] = "One";
449
- withFieldName(fieldName) {
450
- const relation = new One(this.sourceTable, this.referencedTable, this.config, this.isNullable);
451
- relation.fieldName = fieldName;
452
- return relation;
453
- }
454
- };
455
- var Many = class Many extends Relation {
456
- constructor(sourceTable, referencedTable, config) {
457
- super(sourceTable, referencedTable, config?.relationName);
458
- this.config = config;
459
- }
460
- static [entityKind] = "Many";
461
- withFieldName(fieldName) {
462
- const relation = new Many(this.sourceTable, this.referencedTable, this.config);
463
- relation.fieldName = fieldName;
464
- return relation;
465
- }
466
- };
467
- function getOperators() {
468
- return {
469
- and,
470
- between,
471
- eq,
472
- exists,
473
- gt,
474
- gte,
475
- ilike,
476
- inArray,
477
- isNull,
478
- isNotNull,
479
- like,
480
- lt,
481
- lte,
482
- ne,
483
- not,
484
- notBetween,
485
- notExists,
486
- notLike,
487
- notIlike,
488
- notInArray,
489
- or,
490
- sql
491
- };
492
- }
493
- function getOrderByOperators() {
494
- return {
495
- sql,
496
- asc,
497
- desc
498
- };
499
- }
500
- function extractTablesRelationalConfig(schema, configHelpers) {
501
- if (Object.keys(schema).length === 1 && "default" in schema && !is(schema["default"], Table)) schema = schema["default"];
502
- const tableNamesMap = {};
503
- const relationsBuffer = {};
504
- const tablesConfig = {};
505
- for (const [key, value] of Object.entries(schema)) if (is(value, Table)) {
506
- const dbName = getTableUniqueName(value);
507
- const bufferedRelations = relationsBuffer[dbName];
508
- tableNamesMap[dbName] = key;
509
- tablesConfig[key] = {
510
- tsName: key,
511
- dbName: value[Table.Symbol.Name],
512
- schema: value[Table.Symbol.Schema],
513
- columns: value[Table.Symbol.Columns],
514
- relations: bufferedRelations?.relations ?? {},
515
- primaryKey: bufferedRelations?.primaryKey ?? []
516
- };
517
- for (const column of Object.values(value[Table.Symbol.Columns])) if (column.primary) tablesConfig[key].primaryKey.push(column);
518
- const extraConfig = value[Table.Symbol.ExtraConfigBuilder]?.(value[Table.Symbol.ExtraConfigColumns]);
519
- if (extraConfig) {
520
- for (const configEntry of Object.values(extraConfig)) if (is(configEntry, PrimaryKeyBuilder)) tablesConfig[key].primaryKey.push(...configEntry.columns);
521
- }
522
- } else if (is(value, Relations)) {
523
- const dbName = getTableUniqueName(value.table);
524
- const tableName = tableNamesMap[dbName];
525
- const relations2 = value.config(configHelpers(value.table));
526
- let primaryKey;
527
- for (const [relationName, relation] of Object.entries(relations2)) if (tableName) {
528
- const tableConfig = tablesConfig[tableName];
529
- tableConfig.relations[relationName] = relation;
530
- } else {
531
- if (!(dbName in relationsBuffer)) relationsBuffer[dbName] = {
532
- relations: {},
533
- primaryKey
534
- };
535
- relationsBuffer[dbName].relations[relationName] = relation;
536
- }
537
- }
538
- return {
539
- tables: tablesConfig,
540
- tableNamesMap
541
- };
542
- }
543
- function createOne(sourceTable) {
544
- return function one(table, config) {
545
- return new One(sourceTable, table, config, config?.fields.reduce((res, f) => res && f.notNull, true) ?? false);
546
- };
547
- }
548
- function createMany(sourceTable) {
549
- return function many(referencedTable, config) {
550
- return new Many(sourceTable, referencedTable, config);
551
- };
552
- }
553
- function normalizeRelation(schema, tableNamesMap, relation) {
554
- if (is(relation, One) && relation.config) return {
555
- fields: relation.config.fields,
556
- references: relation.config.references
557
- };
558
- const referencedTableTsName = tableNamesMap[getTableUniqueName(relation.referencedTable)];
559
- if (!referencedTableTsName) throw new Error(`Table "${relation.referencedTable[Table.Symbol.Name]}" not found in schema`);
560
- const referencedTableConfig = schema[referencedTableTsName];
561
- if (!referencedTableConfig) throw new Error(`Table "${referencedTableTsName}" not found in schema`);
562
- const sourceTable = relation.sourceTable;
563
- const sourceTableTsName = tableNamesMap[getTableUniqueName(sourceTable)];
564
- if (!sourceTableTsName) throw new Error(`Table "${sourceTable[Table.Symbol.Name]}" not found in schema`);
565
- const reverseRelations = [];
566
- for (const referencedTableRelation of Object.values(referencedTableConfig.relations)) if (relation.relationName && relation !== referencedTableRelation && referencedTableRelation.relationName === relation.relationName || !relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) reverseRelations.push(referencedTableRelation);
567
- if (reverseRelations.length > 1) throw relation.relationName ? /* @__PURE__ */ new Error(`There are multiple relations with name "${relation.relationName}" in table "${referencedTableTsName}"`) : /* @__PURE__ */ new Error(`There are multiple relations between "${referencedTableTsName}" and "${relation.sourceTable[Table.Symbol.Name]}". Please specify relation name`);
568
- if (reverseRelations[0] && is(reverseRelations[0], One) && reverseRelations[0].config) return {
569
- fields: reverseRelations[0].config.references,
570
- references: reverseRelations[0].config.fields
571
- };
572
- throw new Error(`There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`);
573
- }
574
- function createTableRelationsHelpers(sourceTable) {
575
- return {
576
- one: createOne(sourceTable),
577
- many: createMany(sourceTable)
578
- };
579
- }
580
- function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelection, mapColumnValue = (value) => value) {
581
- const result = {};
582
- for (const [selectionItemIndex, selectionItem] of buildQueryResultSelection.entries()) if (selectionItem.isJson) {
583
- const relation = tableConfig.relations[selectionItem.tsKey];
584
- const rawSubRows = row[selectionItemIndex];
585
- const subRows = typeof rawSubRows === "string" ? JSON.parse(rawSubRows) : rawSubRows;
586
- result[selectionItem.tsKey] = is(relation, One) ? subRows && mapRelationalRow(tablesConfig, tablesConfig[selectionItem.relationTableTsKey], subRows, selectionItem.selection, mapColumnValue) : subRows.map((subRow) => mapRelationalRow(tablesConfig, tablesConfig[selectionItem.relationTableTsKey], subRow, selectionItem.selection, mapColumnValue));
587
- } else {
588
- const value = mapColumnValue(row[selectionItemIndex]);
589
- const field = selectionItem.field;
590
- let decoder;
591
- if (is(field, Column)) decoder = field;
592
- else if (is(field, SQL)) decoder = field.decoder;
593
- else decoder = field.sql.decoder;
594
- result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
595
- }
596
- return result;
597
- }
598
- var TypedQueryBuilder = class {
599
- static [entityKind] = "TypedQueryBuilder";
600
- /** @internal */
601
- getSelectedFields() {
602
- return this._.selectedFields;
603
- }
604
- };
605
- var Cache = class {
606
- static [entityKind] = "Cache";
607
- };
608
- var NoopCache = class extends Cache {
609
- strategy() {
610
- return "all";
611
- }
612
- static [entityKind] = "NoopCache";
613
- async get(_key) {}
614
- async put(_hashedQuery, _response, _tables, _config) {}
615
- async onMutate(_params) {}
616
- };
617
- async function hashQuery(sql, params) {
618
- const dataToHash = `${sql}-${JSON.stringify(params)}`;
619
- const data = new TextEncoder().encode(dataToHash);
620
- const hashBuffer = await crypto.subtle.digest("SHA-256", data);
621
- return [...new Uint8Array(hashBuffer)].map((b) => b.toString(16).padStart(2, "0")).join("");
622
- }
623
- var ConsoleLogWriter = class {
624
- static [entityKind] = "ConsoleLogWriter";
625
- write(message) {
626
- console.log(message);
627
- }
628
- };
629
- var DefaultLogger = class {
630
- static [entityKind] = "DefaultLogger";
631
- writer;
632
- constructor(config) {
633
- this.writer = config?.writer ?? new ConsoleLogWriter();
634
- }
635
- logQuery(query, params) {
636
- const stringifiedParams = params.map((p) => {
637
- try {
638
- return JSON.stringify(p);
639
- } catch {
640
- return String(p);
641
- }
642
- });
643
- const paramsStr = stringifiedParams.length ? ` -- params: [${stringifiedParams.join(", ")}]` : "";
644
- this.writer.write(`Query: ${query}${paramsStr}`);
645
- }
646
- };
647
- var NoopLogger = class {
648
- static [entityKind] = "NoopLogger";
649
- logQuery() {}
650
- };
651
- //#endregion
652
- export { mapColumnsInSQLToAlias as A, getOrderByOperators as C, haveSameKeys as D, hashQuery as E, orderSelectedFields as F, toCamelCase as I, toSnakeCase as L, mapResultRow as M, mapUpdateSet as N, isConfig as O, normalizeRelation as P, getOperators as S, getTableLikeName as T, and as _, Many as a, eq as b, One as c, Relations as d, SelectionProxyHandler as f, aliasedTableColumn as g, aliasedTable as h, DrizzleQueryError as i, mapRelationalRow as j, mapColumnsInAliasedSQLToAlias as k, PgTable as l, TypedQueryBuilder as m, DefaultLogger as n, NoopCache as o, TransactionRollbackError as p, DrizzleError as r, NoopLogger as s, CasingCache as t, QueryPromise as u, applyMixins as v, getTableColumns as w, extractTablesRelationalConfig as x, createTableRelationsHelpers as y };
@@ -1,8 +0,0 @@
1
- import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
2
- //#region ../db/dist/migrator-B9kYwLqO.js
3
- async function migrate(db, config) {
4
- const migrations = readMigrationFiles(config);
5
- await db.dialect.migrate(migrations, db.session, config);
6
- }
7
- //#endregion
8
- export { migrate };
@@ -1,8 +0,0 @@
1
- import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
2
- //#region ../db/dist/migrator-BfTfJctM.js
3
- function migrate(db, config) {
4
- const migrations = readMigrationFiles(config);
5
- db.dialect.migrate(migrations, db.session, config);
6
- }
7
- //#endregion
8
- export { migrate };
@@ -1,8 +0,0 @@
1
- import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
2
- //#region ../db/dist/migrator-BjoW0_3j.js
3
- async function migrate(db, config) {
4
- const migrations = readMigrationFiles(config);
5
- await db.dialect.migrate(migrations, db.session, config);
6
- }
7
- //#endregion
8
- export { migrate };
@@ -1,8 +0,0 @@
1
- import { t as readMigrationFiles } from "./migrator-DG1mWUoR-DVfkqn_v.js";
2
- //#region ../db/dist/migrator-CWWlo_Jk.js
3
- async function migrate(db, config) {
4
- const migrations = readMigrationFiles(config);
5
- await db.dialect.migrate(migrations, db.session, config);
6
- }
7
- //#endregion
8
- export { migrate };