better-auth 0.0.2-beta.7 → 0.0.2

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 (96) hide show
  1. package/dist/access.d.ts +4 -0
  2. package/dist/access.js +126 -0
  3. package/dist/access.js.map +1 -0
  4. package/dist/cli.d.ts +2 -0
  5. package/dist/cli.js +553 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/client/plugins.d.ts +2436 -0
  8. package/dist/client/plugins.js +411 -0
  9. package/dist/client/plugins.js.map +1 -0
  10. package/dist/client-A2Mt04KQ.d.ts +3503 -0
  11. package/dist/client.d.ts +1433 -0
  12. package/dist/client.js +693 -0
  13. package/dist/client.js.map +1 -0
  14. package/dist/helper-B5_2Vzba.d.ts +14 -0
  15. package/dist/index-Dg4eEXZW.d.ts +24 -0
  16. package/dist/index-W5nXvJ-p.d.ts +1498 -0
  17. package/dist/index.d.ts +6 -4
  18. package/dist/index.js +2195 -1191
  19. package/dist/index.js.map +1 -1
  20. package/dist/next-js.d.ts +14 -0
  21. package/dist/next-js.js +14 -0
  22. package/dist/next-js.js.map +1 -0
  23. package/dist/plugins.d.ts +892 -49
  24. package/dist/plugins.js +3951 -253
  25. package/dist/plugins.js.map +1 -1
  26. package/dist/preact.d.ts +8 -0
  27. package/dist/preact.js +294 -0
  28. package/dist/preact.js.map +1 -0
  29. package/dist/react.d.ts +14 -0
  30. package/dist/react.js +314 -0
  31. package/dist/react.js.map +1 -0
  32. package/dist/schema-BOszzrbQ.d.ts +792 -0
  33. package/dist/social.d.ts +4 -0
  34. package/dist/social.js +509 -0
  35. package/dist/social.js.map +1 -0
  36. package/dist/solid-start.d.ts +18 -0
  37. package/dist/solid-start.js +14 -0
  38. package/dist/solid-start.js.map +1 -0
  39. package/dist/solid.d.ts +2790 -0
  40. package/dist/solid.js +306 -0
  41. package/dist/solid.js.map +1 -0
  42. package/dist/statement-COylZd3J.d.ts +81 -0
  43. package/dist/svelte-kit.d.ts +10 -7
  44. package/dist/svelte-kit.js +12 -17
  45. package/dist/svelte-kit.js.map +1 -1
  46. package/dist/svelte.d.ts +2791 -0
  47. package/dist/svelte.js +304 -0
  48. package/dist/svelte.js.map +1 -0
  49. package/dist/type-DbMyI3b5.d.ts +5724 -0
  50. package/dist/types.d.ts +7 -0
  51. package/dist/types.js +1 -0
  52. package/dist/types.js.map +1 -0
  53. package/dist/vue.d.ts +14 -0
  54. package/dist/vue.js +311 -0
  55. package/dist/vue.js.map +1 -0
  56. package/package.json +80 -54
  57. package/LICENSE +0 -21
  58. package/dist/actions.d.ts +0 -33
  59. package/dist/actions.js +0 -1373
  60. package/dist/actions.js.map +0 -1
  61. package/dist/adapters/drizzle-adapter.d.ts +0 -10
  62. package/dist/adapters/drizzle-adapter.js +0 -1095
  63. package/dist/adapters/drizzle-adapter.js.map +0 -1
  64. package/dist/adapters/memory.d.ts +0 -8
  65. package/dist/adapters/memory.js +0 -136
  66. package/dist/adapters/memory.js.map +0 -1
  67. package/dist/adapters/mongodb-adapter.d.ts +0 -9
  68. package/dist/adapters/mongodb-adapter.js +0 -97
  69. package/dist/adapters/mongodb-adapter.js.map +0 -1
  70. package/dist/adapters/prisma-adapter.d.ts +0 -7
  71. package/dist/adapters/prisma-adapter.js +0 -144
  72. package/dist/adapters/prisma-adapter.js.map +0 -1
  73. package/dist/adapters/redis-adapter.d.ts +0 -7
  74. package/dist/adapters/redis-adapter.js +0 -65
  75. package/dist/adapters/redis-adapter.js.map +0 -1
  76. package/dist/adapters.d.ts +0 -3
  77. package/dist/adapters.js +0 -206
  78. package/dist/adapters.js.map +0 -1
  79. package/dist/h3.d.ts +0 -10
  80. package/dist/h3.js +0 -326
  81. package/dist/h3.js.map +0 -1
  82. package/dist/hono.d.ts +0 -10
  83. package/dist/hono.js +0 -25
  84. package/dist/hono.js.map +0 -1
  85. package/dist/index-UcTu1vUg.d.ts +0 -107
  86. package/dist/next.d.ts +0 -17
  87. package/dist/next.js +0 -26
  88. package/dist/next.js.map +0 -1
  89. package/dist/options-CH15FEBw.d.ts +0 -1562
  90. package/dist/providers.d.ts +0 -3
  91. package/dist/providers.js +0 -653
  92. package/dist/providers.js.map +0 -1
  93. package/dist/routes/session.d.ts +0 -39
  94. package/dist/routes/session.js +0 -128
  95. package/dist/routes/session.js.map +0 -1
  96. package/dist/types-DAxaMWCy.d.ts +0 -136
@@ -1,1095 +0,0 @@
1
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/entity.js
2
- var entityKind = Symbol.for("drizzle:entityKind");
3
- var hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
4
- function is(value, type) {
5
- if (!value || typeof value !== "object") {
6
- return false;
7
- }
8
- if (value instanceof type) {
9
- return true;
10
- }
11
- if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
12
- throw new Error(
13
- `Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`
14
- );
15
- }
16
- let cls = value.constructor;
17
- if (cls) {
18
- while (cls) {
19
- if (entityKind in cls && cls[entityKind] === type[entityKind]) {
20
- return true;
21
- }
22
- cls = Object.getPrototypeOf(cls);
23
- }
24
- }
25
- return false;
26
- }
27
-
28
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/column.js
29
- var Column = class {
30
- constructor(table, config) {
31
- this.table = table;
32
- this.config = config;
33
- this.name = config.name;
34
- this.notNull = config.notNull;
35
- this.default = config.default;
36
- this.defaultFn = config.defaultFn;
37
- this.onUpdateFn = config.onUpdateFn;
38
- this.hasDefault = config.hasDefault;
39
- this.primary = config.primaryKey;
40
- this.isUnique = config.isUnique;
41
- this.uniqueName = config.uniqueName;
42
- this.uniqueType = config.uniqueType;
43
- this.dataType = config.dataType;
44
- this.columnType = config.columnType;
45
- }
46
- static [entityKind] = "Column";
47
- name;
48
- primary;
49
- notNull;
50
- default;
51
- defaultFn;
52
- onUpdateFn;
53
- hasDefault;
54
- isUnique;
55
- uniqueName;
56
- uniqueType;
57
- dataType;
58
- columnType;
59
- enumValues = void 0;
60
- config;
61
- mapFromDriverValue(value) {
62
- return value;
63
- }
64
- mapToDriverValue(value) {
65
- return value;
66
- }
67
- };
68
-
69
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/column-builder.js
70
- var ColumnBuilder = class {
71
- static [entityKind] = "ColumnBuilder";
72
- config;
73
- constructor(name, dataType, columnType) {
74
- this.config = {
75
- name,
76
- notNull: false,
77
- default: void 0,
78
- hasDefault: false,
79
- primaryKey: false,
80
- isUnique: false,
81
- uniqueName: void 0,
82
- uniqueType: void 0,
83
- dataType,
84
- columnType
85
- };
86
- }
87
- /**
88
- * Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
89
- *
90
- * @example
91
- * ```ts
92
- * const users = pgTable('users', {
93
- * id: integer('id').$type<UserId>().primaryKey(),
94
- * details: json('details').$type<UserDetails>().notNull(),
95
- * });
96
- * ```
97
- */
98
- $type() {
99
- return this;
100
- }
101
- /**
102
- * Adds a `not null` clause to the column definition.
103
- *
104
- * Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
105
- */
106
- notNull() {
107
- this.config.notNull = true;
108
- return this;
109
- }
110
- /**
111
- * Adds a `default <value>` clause to the column definition.
112
- *
113
- * Affects the `insert` model of the table - columns *with* `default` are optional on insert.
114
- *
115
- * If you need to set a dynamic default value, use {@link $defaultFn} instead.
116
- */
117
- default(value) {
118
- this.config.default = value;
119
- this.config.hasDefault = true;
120
- return this;
121
- }
122
- /**
123
- * Adds a dynamic default value to the column.
124
- * The function will be called when the row is inserted, and the returned value will be used as the column value.
125
- *
126
- * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
127
- */
128
- $defaultFn(fn) {
129
- this.config.defaultFn = fn;
130
- this.config.hasDefault = true;
131
- return this;
132
- }
133
- /**
134
- * Alias for {@link $defaultFn}.
135
- */
136
- $default = this.$defaultFn;
137
- /**
138
- * Adds a dynamic update value to the column.
139
- * The function will be called when the row is updated, and the returned value will be used as the column value if none is provided.
140
- * If no `default` (or `$defaultFn`) value is provided, the function will be called when the row is inserted as well, and the returned value will be used as the column value.
141
- *
142
- * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
143
- */
144
- $onUpdateFn(fn) {
145
- this.config.onUpdateFn = fn;
146
- this.config.hasDefault = true;
147
- return this;
148
- }
149
- /**
150
- * Alias for {@link $onUpdateFn}.
151
- */
152
- $onUpdate = this.$onUpdateFn;
153
- /**
154
- * Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
155
- *
156
- * In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
157
- */
158
- primaryKey() {
159
- this.config.primaryKey = true;
160
- this.config.notNull = true;
161
- return this;
162
- }
163
- };
164
-
165
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/table.js
166
- var TableName = Symbol.for("drizzle:Name");
167
- var Schema = Symbol.for("drizzle:Schema");
168
- var Columns = Symbol.for("drizzle:Columns");
169
- var OriginalName = Symbol.for("drizzle:OriginalName");
170
- var BaseName = Symbol.for("drizzle:BaseName");
171
- var IsAlias = Symbol.for("drizzle:IsAlias");
172
- var ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
173
- var IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
174
- var Table = class {
175
- static [entityKind] = "Table";
176
- /** @internal */
177
- static Symbol = {
178
- Name: TableName,
179
- Schema,
180
- OriginalName,
181
- Columns,
182
- BaseName,
183
- IsAlias,
184
- ExtraConfigBuilder
185
- };
186
- /**
187
- * @internal
188
- * Can be changed if the table is aliased.
189
- */
190
- [TableName];
191
- /**
192
- * @internal
193
- * Used to store the original name of the table, before any aliasing.
194
- */
195
- [OriginalName];
196
- /** @internal */
197
- [Schema];
198
- /** @internal */
199
- [Columns];
200
- /**
201
- * @internal
202
- * Used to store the table name before the transformation via the `tableCreator` functions.
203
- */
204
- [BaseName];
205
- /** @internal */
206
- [IsAlias] = false;
207
- /** @internal */
208
- [ExtraConfigBuilder] = void 0;
209
- [IsDrizzleTable] = true;
210
- constructor(name, schema, baseName) {
211
- this[TableName] = this[OriginalName] = name;
212
- this[Schema] = schema;
213
- this[BaseName] = baseName;
214
- }
215
- };
216
-
217
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/pg-core/table.js
218
- var InlineForeignKeys = Symbol.for("drizzle:PgInlineForeignKeys");
219
- var PgTable = class extends Table {
220
- static [entityKind] = "PgTable";
221
- /** @internal */
222
- static Symbol = Object.assign({}, Table.Symbol, {
223
- InlineForeignKeys
224
- });
225
- /**@internal */
226
- [InlineForeignKeys] = [];
227
- /** @internal */
228
- [Table.Symbol.ExtraConfigBuilder] = void 0;
229
- };
230
-
231
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/pg-core/foreign-keys.js
232
- var ForeignKeyBuilder = class {
233
- static [entityKind] = "PgForeignKeyBuilder";
234
- /** @internal */
235
- reference;
236
- /** @internal */
237
- _onUpdate = "no action";
238
- /** @internal */
239
- _onDelete = "no action";
240
- constructor(config, actions) {
241
- this.reference = () => {
242
- const { name, columns, foreignColumns } = config();
243
- return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
244
- };
245
- if (actions) {
246
- this._onUpdate = actions.onUpdate;
247
- this._onDelete = actions.onDelete;
248
- }
249
- }
250
- onUpdate(action) {
251
- this._onUpdate = action === void 0 ? "no action" : action;
252
- return this;
253
- }
254
- onDelete(action) {
255
- this._onDelete = action === void 0 ? "no action" : action;
256
- return this;
257
- }
258
- /** @internal */
259
- build(table) {
260
- return new ForeignKey(table, this);
261
- }
262
- };
263
- var ForeignKey = class {
264
- constructor(table, builder) {
265
- this.table = table;
266
- this.reference = builder.reference;
267
- this.onUpdate = builder._onUpdate;
268
- this.onDelete = builder._onDelete;
269
- }
270
- static [entityKind] = "PgForeignKey";
271
- reference;
272
- onUpdate;
273
- onDelete;
274
- getName() {
275
- const { name, columns, foreignColumns } = this.reference();
276
- const columnNames = columns.map((column) => column.name);
277
- const foreignColumnNames = foreignColumns.map((column) => column.name);
278
- const chunks = [
279
- this.table[PgTable.Symbol.Name],
280
- ...columnNames,
281
- foreignColumns[0].table[PgTable.Symbol.Name],
282
- ...foreignColumnNames
283
- ];
284
- return name ?? `${chunks.join("_")}_fk`;
285
- }
286
- };
287
-
288
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/tracing-utils.js
289
- function iife(fn, ...args) {
290
- return fn(...args);
291
- }
292
-
293
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/pg-core/unique-constraint.js
294
- function uniqueKeyName(table, columns) {
295
- return `${table[PgTable.Symbol.Name]}_${columns.join("_")}_unique`;
296
- }
297
- var UniqueConstraintBuilder = class {
298
- constructor(columns, name) {
299
- this.name = name;
300
- this.columns = columns;
301
- }
302
- static [entityKind] = "PgUniqueConstraintBuilder";
303
- /** @internal */
304
- columns;
305
- /** @internal */
306
- nullsNotDistinctConfig = false;
307
- nullsNotDistinct() {
308
- this.nullsNotDistinctConfig = true;
309
- return this;
310
- }
311
- /** @internal */
312
- build(table) {
313
- return new UniqueConstraint(table, this.columns, this.nullsNotDistinctConfig, this.name);
314
- }
315
- };
316
- var UniqueOnConstraintBuilder = class {
317
- static [entityKind] = "PgUniqueOnConstraintBuilder";
318
- /** @internal */
319
- name;
320
- constructor(name) {
321
- this.name = name;
322
- }
323
- on(...columns) {
324
- return new UniqueConstraintBuilder(columns, this.name);
325
- }
326
- };
327
- var UniqueConstraint = class {
328
- constructor(table, columns, nullsNotDistinct, name) {
329
- this.table = table;
330
- this.columns = columns;
331
- this.name = name ?? uniqueKeyName(this.table, this.columns.map((column) => column.name));
332
- this.nullsNotDistinct = nullsNotDistinct;
333
- }
334
- static [entityKind] = "PgUniqueConstraint";
335
- columns;
336
- name;
337
- nullsNotDistinct = false;
338
- getName() {
339
- return this.name;
340
- }
341
- };
342
-
343
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/pg-core/utils/array.js
344
- function parsePgArrayValue(arrayString, startFrom, inQuotes) {
345
- for (let i = startFrom; i < arrayString.length; i++) {
346
- const char = arrayString[i];
347
- if (char === "\\") {
348
- i++;
349
- continue;
350
- }
351
- if (char === '"') {
352
- return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i + 1];
353
- }
354
- if (inQuotes) {
355
- continue;
356
- }
357
- if (char === "," || char === "}") {
358
- return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i];
359
- }
360
- }
361
- return [arrayString.slice(startFrom).replace(/\\/g, ""), arrayString.length];
362
- }
363
- function parsePgNestedArray(arrayString, startFrom = 0) {
364
- const result = [];
365
- let i = startFrom;
366
- let lastCharIsComma = false;
367
- while (i < arrayString.length) {
368
- const char = arrayString[i];
369
- if (char === ",") {
370
- if (lastCharIsComma || i === startFrom) {
371
- result.push("");
372
- }
373
- lastCharIsComma = true;
374
- i++;
375
- continue;
376
- }
377
- lastCharIsComma = false;
378
- if (char === "\\") {
379
- i += 2;
380
- continue;
381
- }
382
- if (char === '"') {
383
- const [value2, startFrom2] = parsePgArrayValue(arrayString, i + 1, true);
384
- result.push(value2);
385
- i = startFrom2;
386
- continue;
387
- }
388
- if (char === "}") {
389
- return [result, i + 1];
390
- }
391
- if (char === "{") {
392
- const [value2, startFrom2] = parsePgNestedArray(arrayString, i + 1);
393
- result.push(value2);
394
- i = startFrom2;
395
- continue;
396
- }
397
- const [value, newStartFrom] = parsePgArrayValue(arrayString, i, false);
398
- result.push(value);
399
- i = newStartFrom;
400
- }
401
- return [result, i];
402
- }
403
- function parsePgArray(arrayString) {
404
- const [result] = parsePgNestedArray(arrayString, 1);
405
- return result;
406
- }
407
- function makePgArray(array) {
408
- return `{${array.map((item) => {
409
- if (Array.isArray(item)) {
410
- return makePgArray(item);
411
- }
412
- if (typeof item === "string") {
413
- return `"${item.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
414
- }
415
- return `${item}`;
416
- }).join(",")}}`;
417
- }
418
-
419
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/common.js
420
- var PgColumnBuilder = class extends ColumnBuilder {
421
- foreignKeyConfigs = [];
422
- static [entityKind] = "PgColumnBuilder";
423
- array(size) {
424
- return new PgArrayBuilder(this.config.name, this, size);
425
- }
426
- references(ref, actions = {}) {
427
- this.foreignKeyConfigs.push({ ref, actions });
428
- return this;
429
- }
430
- unique(name, config) {
431
- this.config.isUnique = true;
432
- this.config.uniqueName = name;
433
- this.config.uniqueType = config?.nulls;
434
- return this;
435
- }
436
- /** @internal */
437
- buildForeignKeys(column, table) {
438
- return this.foreignKeyConfigs.map(({ ref, actions }) => {
439
- return iife(
440
- (ref2, actions2) => {
441
- const builder = new ForeignKeyBuilder(() => {
442
- const foreignColumn = ref2();
443
- return { columns: [column], foreignColumns: [foreignColumn] };
444
- });
445
- if (actions2.onUpdate) {
446
- builder.onUpdate(actions2.onUpdate);
447
- }
448
- if (actions2.onDelete) {
449
- builder.onDelete(actions2.onDelete);
450
- }
451
- return builder.build(table);
452
- },
453
- ref,
454
- actions
455
- );
456
- });
457
- }
458
- };
459
- var PgColumn = class extends Column {
460
- constructor(table, config) {
461
- if (!config.uniqueName) {
462
- config.uniqueName = uniqueKeyName(table, [config.name]);
463
- }
464
- super(table, config);
465
- this.table = table;
466
- }
467
- static [entityKind] = "PgColumn";
468
- };
469
- var PgArrayBuilder = class extends PgColumnBuilder {
470
- static [entityKind] = "PgArrayBuilder";
471
- constructor(name, baseBuilder, size) {
472
- super(name, "array", "PgArray");
473
- this.config.baseBuilder = baseBuilder;
474
- this.config.size = size;
475
- }
476
- /** @internal */
477
- build(table) {
478
- const baseColumn = this.config.baseBuilder.build(table);
479
- return new PgArray(
480
- table,
481
- this.config,
482
- baseColumn
483
- );
484
- }
485
- };
486
- var PgArray = class _PgArray extends PgColumn {
487
- constructor(table, config, baseColumn, range) {
488
- super(table, config);
489
- this.baseColumn = baseColumn;
490
- this.range = range;
491
- this.size = config.size;
492
- }
493
- size;
494
- static [entityKind] = "PgArray";
495
- getSQLType() {
496
- return `${this.baseColumn.getSQLType()}[${typeof this.size === "number" ? this.size : ""}]`;
497
- }
498
- mapFromDriverValue(value) {
499
- if (typeof value === "string") {
500
- value = parsePgArray(value);
501
- }
502
- return value.map((v) => this.baseColumn.mapFromDriverValue(v));
503
- }
504
- mapToDriverValue(value, isNestedArray = false) {
505
- const a = value.map(
506
- (v) => v === null ? null : is(this.baseColumn, _PgArray) ? this.baseColumn.mapToDriverValue(v, true) : this.baseColumn.mapToDriverValue(v)
507
- );
508
- if (isNestedArray)
509
- return a;
510
- return makePgArray(a);
511
- }
512
- };
513
-
514
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/pg-core/columns/enum.js
515
- var isPgEnumSym = Symbol.for("drizzle:isPgEnum");
516
- function isPgEnum(obj) {
517
- return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
518
- }
519
- var PgEnumColumnBuilder = class extends PgColumnBuilder {
520
- static [entityKind] = "PgEnumColumnBuilder";
521
- constructor(name, enumInstance) {
522
- super(name, "string", "PgEnumColumn");
523
- this.config.enum = enumInstance;
524
- }
525
- /** @internal */
526
- build(table) {
527
- return new PgEnumColumn(
528
- table,
529
- this.config
530
- );
531
- }
532
- };
533
- var PgEnumColumn = class extends PgColumn {
534
- static [entityKind] = "PgEnumColumn";
535
- enum = this.config.enum;
536
- enumValues = this.config.enum.enumValues;
537
- constructor(table, config) {
538
- super(table, config);
539
- this.enum = config.enum;
540
- }
541
- getSQLType() {
542
- return this.enum.enumName;
543
- }
544
- };
545
-
546
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/subquery.js
547
- var Subquery = class {
548
- static [entityKind] = "Subquery";
549
- constructor(sql2, selection, alias, isWith = false) {
550
- this._ = {
551
- brand: "Subquery",
552
- sql: sql2,
553
- selectedFields: selection,
554
- alias,
555
- isWith
556
- };
557
- }
558
- // getSQL(): SQL<unknown> {
559
- // return new SQL([this]);
560
- // }
561
- };
562
- var WithSubquery = class extends Subquery {
563
- static [entityKind] = "WithSubquery";
564
- };
565
-
566
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/version.js
567
- var version = "0.30.10";
568
-
569
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/tracing.js
570
- var otel;
571
- var rawTracer;
572
- var tracer = {
573
- startActiveSpan(name, fn) {
574
- if (!otel) {
575
- return fn();
576
- }
577
- if (!rawTracer) {
578
- rawTracer = otel.trace.getTracer("drizzle-orm", version);
579
- }
580
- return iife(
581
- (otel2, rawTracer2) => rawTracer2.startActiveSpan(
582
- name,
583
- (span) => {
584
- try {
585
- return fn(span);
586
- } catch (e) {
587
- span.setStatus({
588
- code: otel2.SpanStatusCode.ERROR,
589
- message: e instanceof Error ? e.message : "Unknown error"
590
- // eslint-disable-line no-instanceof/no-instanceof
591
- });
592
- throw e;
593
- } finally {
594
- span.end();
595
- }
596
- }
597
- ),
598
- otel,
599
- rawTracer
600
- );
601
- }
602
- };
603
-
604
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/view-common.js
605
- var ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
606
-
607
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/sql/sql.js
608
- var FakePrimitiveParam = class {
609
- static [entityKind] = "FakePrimitiveParam";
610
- };
611
- function isSQLWrapper(value) {
612
- return value !== null && value !== void 0 && typeof value.getSQL === "function";
613
- }
614
- function mergeQueries(queries) {
615
- const result = { sql: "", params: [] };
616
- for (const query of queries) {
617
- result.sql += query.sql;
618
- result.params.push(...query.params);
619
- if (query.typings?.length) {
620
- if (!result.typings) {
621
- result.typings = [];
622
- }
623
- result.typings.push(...query.typings);
624
- }
625
- }
626
- return result;
627
- }
628
- var StringChunk = class {
629
- static [entityKind] = "StringChunk";
630
- value;
631
- constructor(value) {
632
- this.value = Array.isArray(value) ? value : [value];
633
- }
634
- getSQL() {
635
- return new SQL([this]);
636
- }
637
- };
638
- var SQL = class _SQL {
639
- constructor(queryChunks) {
640
- this.queryChunks = queryChunks;
641
- }
642
- static [entityKind] = "SQL";
643
- /** @internal */
644
- decoder = noopDecoder;
645
- shouldInlineParams = false;
646
- append(query) {
647
- this.queryChunks.push(...query.queryChunks);
648
- return this;
649
- }
650
- toQuery(config) {
651
- return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
652
- const query = this.buildQueryFromSourceParams(this.queryChunks, config);
653
- span?.setAttributes({
654
- "drizzle.query.text": query.sql,
655
- "drizzle.query.params": JSON.stringify(query.params)
656
- });
657
- return query;
658
- });
659
- }
660
- buildQueryFromSourceParams(chunks, _config) {
661
- const config = Object.assign({}, _config, {
662
- inlineParams: _config.inlineParams || this.shouldInlineParams,
663
- paramStartIndex: _config.paramStartIndex || { value: 0 }
664
- });
665
- const {
666
- escapeName,
667
- escapeParam,
668
- prepareTyping,
669
- inlineParams,
670
- paramStartIndex
671
- } = config;
672
- return mergeQueries(chunks.map((chunk) => {
673
- if (is(chunk, StringChunk)) {
674
- return { sql: chunk.value.join(""), params: [] };
675
- }
676
- if (is(chunk, Name)) {
677
- return { sql: escapeName(chunk.value), params: [] };
678
- }
679
- if (chunk === void 0) {
680
- return { sql: "", params: [] };
681
- }
682
- if (Array.isArray(chunk)) {
683
- const result = [new StringChunk("(")];
684
- for (const [i, p] of chunk.entries()) {
685
- result.push(p);
686
- if (i < chunk.length - 1) {
687
- result.push(new StringChunk(", "));
688
- }
689
- }
690
- result.push(new StringChunk(")"));
691
- return this.buildQueryFromSourceParams(result, config);
692
- }
693
- if (is(chunk, _SQL)) {
694
- return this.buildQueryFromSourceParams(chunk.queryChunks, {
695
- ...config,
696
- inlineParams: inlineParams || chunk.shouldInlineParams
697
- });
698
- }
699
- if (is(chunk, Table)) {
700
- const schemaName = chunk[Table.Symbol.Schema];
701
- const tableName = chunk[Table.Symbol.Name];
702
- return {
703
- sql: schemaName === void 0 ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
704
- params: []
705
- };
706
- }
707
- if (is(chunk, Column)) {
708
- return { sql: escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(chunk.name), params: [] };
709
- }
710
- if (is(chunk, View)) {
711
- const schemaName = chunk[ViewBaseConfig].schema;
712
- const viewName = chunk[ViewBaseConfig].name;
713
- return {
714
- sql: schemaName === void 0 ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
715
- params: []
716
- };
717
- }
718
- if (is(chunk, Param)) {
719
- const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
720
- if (is(mappedValue, _SQL)) {
721
- return this.buildQueryFromSourceParams([mappedValue], config);
722
- }
723
- if (inlineParams) {
724
- return { sql: this.mapInlineParam(mappedValue, config), params: [] };
725
- }
726
- let typings;
727
- if (prepareTyping !== void 0) {
728
- typings = [prepareTyping(chunk.encoder)];
729
- }
730
- return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
731
- }
732
- if (is(chunk, Placeholder)) {
733
- return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk] };
734
- }
735
- if (is(chunk, _SQL.Aliased) && chunk.fieldAlias !== void 0) {
736
- return { sql: escapeName(chunk.fieldAlias), params: [] };
737
- }
738
- if (is(chunk, Subquery)) {
739
- if (chunk._.isWith) {
740
- return { sql: escapeName(chunk._.alias), params: [] };
741
- }
742
- return this.buildQueryFromSourceParams([
743
- new StringChunk("("),
744
- chunk._.sql,
745
- new StringChunk(") "),
746
- new Name(chunk._.alias)
747
- ], config);
748
- }
749
- if (isPgEnum(chunk)) {
750
- if (chunk.schema) {
751
- return { sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName), params: [] };
752
- }
753
- return { sql: escapeName(chunk.enumName), params: [] };
754
- }
755
- if (isSQLWrapper(chunk)) {
756
- return this.buildQueryFromSourceParams([
757
- new StringChunk("("),
758
- chunk.getSQL(),
759
- new StringChunk(")")
760
- ], config);
761
- }
762
- if (inlineParams) {
763
- return { sql: this.mapInlineParam(chunk, config), params: [] };
764
- }
765
- return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk] };
766
- }));
767
- }
768
- mapInlineParam(chunk, { escapeString }) {
769
- if (chunk === null) {
770
- return "null";
771
- }
772
- if (typeof chunk === "number" || typeof chunk === "boolean") {
773
- return chunk.toString();
774
- }
775
- if (typeof chunk === "string") {
776
- return escapeString(chunk);
777
- }
778
- if (typeof chunk === "object") {
779
- const mappedValueAsString = chunk.toString();
780
- if (mappedValueAsString === "[object Object]") {
781
- return escapeString(JSON.stringify(chunk));
782
- }
783
- return escapeString(mappedValueAsString);
784
- }
785
- throw new Error("Unexpected param value: " + chunk);
786
- }
787
- getSQL() {
788
- return this;
789
- }
790
- as(alias) {
791
- if (alias === void 0) {
792
- return this;
793
- }
794
- return new _SQL.Aliased(this, alias);
795
- }
796
- mapWith(decoder) {
797
- this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
798
- return this;
799
- }
800
- inlineParams() {
801
- this.shouldInlineParams = true;
802
- return this;
803
- }
804
- /**
805
- * This method is used to conditionally include a part of the query.
806
- *
807
- * @param condition - Condition to check
808
- * @returns itself if the condition is `true`, otherwise `undefined`
809
- */
810
- if(condition) {
811
- return condition ? this : void 0;
812
- }
813
- };
814
- var Name = class {
815
- constructor(value) {
816
- this.value = value;
817
- }
818
- static [entityKind] = "Name";
819
- brand;
820
- getSQL() {
821
- return new SQL([this]);
822
- }
823
- };
824
- function isDriverValueEncoder(value) {
825
- return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
826
- }
827
- var noopDecoder = {
828
- mapFromDriverValue: (value) => value
829
- };
830
- var noopEncoder = {
831
- mapToDriverValue: (value) => value
832
- };
833
- var noopMapper = {
834
- ...noopDecoder,
835
- ...noopEncoder
836
- };
837
- var Param = class {
838
- /**
839
- * @param value - Parameter value
840
- * @param encoder - Encoder to convert the value to a driver parameter
841
- */
842
- constructor(value, encoder = noopEncoder) {
843
- this.value = value;
844
- this.encoder = encoder;
845
- }
846
- static [entityKind] = "Param";
847
- brand;
848
- getSQL() {
849
- return new SQL([this]);
850
- }
851
- };
852
- function sql(strings, ...params) {
853
- const queryChunks = [];
854
- if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
855
- queryChunks.push(new StringChunk(strings[0]));
856
- }
857
- for (const [paramIndex, param2] of params.entries()) {
858
- queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
859
- }
860
- return new SQL(queryChunks);
861
- }
862
- ((sql2) => {
863
- function empty() {
864
- return new SQL([]);
865
- }
866
- sql2.empty = empty;
867
- function fromList(list) {
868
- return new SQL(list);
869
- }
870
- sql2.fromList = fromList;
871
- function raw(str) {
872
- return new SQL([new StringChunk(str)]);
873
- }
874
- sql2.raw = raw;
875
- function join(chunks, separator) {
876
- const result = [];
877
- for (const [i, chunk] of chunks.entries()) {
878
- if (i > 0 && separator !== void 0) {
879
- result.push(separator);
880
- }
881
- result.push(chunk);
882
- }
883
- return new SQL(result);
884
- }
885
- sql2.join = join;
886
- function identifier(value) {
887
- return new Name(value);
888
- }
889
- sql2.identifier = identifier;
890
- function placeholder2(name2) {
891
- return new Placeholder(name2);
892
- }
893
- sql2.placeholder = placeholder2;
894
- function param2(value, encoder) {
895
- return new Param(value, encoder);
896
- }
897
- sql2.param = param2;
898
- })(sql || (sql = {}));
899
- ((SQL2) => {
900
- class Aliased {
901
- constructor(sql2, fieldAlias) {
902
- this.sql = sql2;
903
- this.fieldAlias = fieldAlias;
904
- }
905
- static [entityKind] = "SQL.Aliased";
906
- /** @internal */
907
- isSelectionField = false;
908
- getSQL() {
909
- return this.sql;
910
- }
911
- /** @internal */
912
- clone() {
913
- return new Aliased(this.sql, this.fieldAlias);
914
- }
915
- }
916
- SQL2.Aliased = Aliased;
917
- })(SQL || (SQL = {}));
918
- var Placeholder = class {
919
- constructor(name2) {
920
- this.name = name2;
921
- }
922
- static [entityKind] = "Placeholder";
923
- getSQL() {
924
- return new SQL([this]);
925
- }
926
- };
927
- var View = class {
928
- static [entityKind] = "View";
929
- /** @internal */
930
- [ViewBaseConfig];
931
- constructor({ name: name2, schema, selectedFields, query }) {
932
- this[ViewBaseConfig] = {
933
- name: name2,
934
- originalName: name2,
935
- schema,
936
- selectedFields,
937
- query,
938
- isExisting: !query,
939
- isAlias: false
940
- };
941
- }
942
- getSQL() {
943
- return new SQL([this]);
944
- }
945
- };
946
- Column.prototype.getSQL = function() {
947
- return new SQL([this]);
948
- };
949
- Table.prototype.getSQL = function() {
950
- return new SQL([this]);
951
- };
952
- Subquery.prototype.getSQL = function() {
953
- return new SQL([this]);
954
- };
955
-
956
- // ../../node_modules/.pnpm/drizzle-orm@0.30.10_@types+better-sqlite3@7.6.10_@types+react@18.3.2_better-sqlite3@10.0.0_react@18.3.1/node_modules/drizzle-orm/sql/expressions/conditions.js
957
- function bindIfParam(value, column) {
958
- if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
959
- return new Param(value, column);
960
- }
961
- return value;
962
- }
963
- var eq = (left, right) => {
964
- return sql`${left} = ${bindIfParam(right, left)}`;
965
- };
966
- function and(...unfilteredConditions) {
967
- const conditions = unfilteredConditions.filter(
968
- (c) => c !== void 0
969
- );
970
- if (conditions.length === 0) {
971
- return void 0;
972
- }
973
- if (conditions.length === 1) {
974
- return new SQL(conditions);
975
- }
976
- return new SQL([
977
- new StringChunk("("),
978
- sql.join(conditions, new StringChunk(" and ")),
979
- new StringChunk(")")
980
- ]);
981
- }
982
- function or(...unfilteredConditions) {
983
- const conditions = unfilteredConditions.filter(
984
- (c) => c !== void 0
985
- );
986
- if (conditions.length === 0) {
987
- return void 0;
988
- }
989
- if (conditions.length === 1) {
990
- return new SQL(conditions);
991
- }
992
- return new SQL([
993
- new StringChunk("("),
994
- sql.join(conditions, new StringChunk(" or ")),
995
- new StringChunk(")")
996
- ]);
997
- }
998
-
999
- // src/adapters/drizzle.ts
1000
- function getSchema(modelName, schema) {
1001
- const key = Object.keys(schema).find((key2) => {
1002
- const modelName2 = schema[key2].name;
1003
- return modelName2;
1004
- });
1005
- if (!key) {
1006
- throw new Error("Model not found");
1007
- }
1008
- return schema[key];
1009
- }
1010
- function whereConvertor(schemaModel, where) {
1011
- if (!where)
1012
- return [];
1013
- if (where.length === 1) {
1014
- const w = where[0];
1015
- if (!w) {
1016
- return [];
1017
- }
1018
- return [eq(schemaModel[w.field], w.value)];
1019
- }
1020
- const andGroup = where.filter((w) => w.connector === "AND" || !w.connector);
1021
- const orGroup = where.filter((w) => w.connector === "OR");
1022
- const andClause = and(
1023
- ...andGroup.map((w) => {
1024
- return eq(schemaModel[w.field], w.value);
1025
- })
1026
- );
1027
- const orClause = or(
1028
- ...orGroup.map((w) => {
1029
- return eq(schemaModel[w.field], w.value);
1030
- })
1031
- );
1032
- const clause = [];
1033
- if (andGroup.length)
1034
- clause.push(andClause);
1035
- if (orGroup.length)
1036
- clause.push(orClause);
1037
- return clause;
1038
- }
1039
- var drizzleAdapter = ({
1040
- db,
1041
- schema
1042
- }) => {
1043
- return {
1044
- async create(data) {
1045
- const { model, data: val } = data;
1046
- const schemaModel = getSchema(model, schema);
1047
- const res = await db.insert(schemaModel).values(val).returning();
1048
- return res[0];
1049
- },
1050
- async findOne(data) {
1051
- const { model, where, select: included } = data;
1052
- const schemaModel = getSchema(model, schema);
1053
- const wheres = whereConvertor(schemaModel, where);
1054
- let res = null;
1055
- if (included?.length) {
1056
- res = await db.select(
1057
- ...included.map((include) => {
1058
- return {
1059
- [include]: schemaModel[include]
1060
- };
1061
- })
1062
- ).from(schemaModel).where(...wheres);
1063
- } else {
1064
- res = await db.select().from(schemaModel).where(...wheres);
1065
- }
1066
- if (res.length)
1067
- return res[0];
1068
- return null;
1069
- },
1070
- async findMany(data) {
1071
- const { model, where } = data;
1072
- const schemaModel = getSchema(model, schema);
1073
- const wheres = whereConvertor(schemaModel, where);
1074
- return await db.select().from(schemaModel).findMany(...wheres);
1075
- },
1076
- async update(data) {
1077
- const { model, where, update } = data;
1078
- const schemaModel = getSchema(model, schema);
1079
- const wheres = whereConvertor(schemaModel, where);
1080
- const res = await db.update(schemaModel).set(update).where(...wheres).returning();
1081
- return res[0];
1082
- },
1083
- async delete(data) {
1084
- const { model, where } = data;
1085
- const schemaModel = getSchema(model, schema);
1086
- const wheres = whereConvertor(schemaModel, where);
1087
- const res = await db.delete(schemaModel).where(...wheres);
1088
- return res[0];
1089
- }
1090
- };
1091
- };
1092
- export {
1093
- drizzleAdapter
1094
- };
1095
- //# sourceMappingURL=drizzle-adapter.js.map