@bobbykim/manguito-cms-cli 0.3.0 → 0.4.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.
@@ -0,0 +1,1527 @@
1
+ import { createRequire as __cjsRequire } from 'module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __esm = (fn, res) => function __init() {
16
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
17
+ };
18
+ var __commonJS = (cb, mod) => function __require2() {
19
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
+ // If the importer is in node compatibility mode or this is not an ESM
35
+ // file that has been converted to a CommonJS file using a Babel-
36
+ // compatible transform (i.e. "__esModule" has not been set), then set
37
+ // "default" to the CommonJS "module.exports" for node compatibility.
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
+ mod
40
+ ));
41
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
+
43
+ // ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.7.0_postcss@8.5.16_tsx@4.23.0_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/esm_shims.js
44
+ import path from "path";
45
+ import { fileURLToPath } from "url";
46
+ var init_esm_shims = __esm({
47
+ "../../node_modules/.pnpm/tsup@8.5.1_jiti@2.7.0_postcss@8.5.16_tsx@4.23.0_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/esm_shims.js"() {
48
+ "use strict";
49
+ }
50
+ });
51
+
52
+ // ../api/dist/chunk-TK4DNRFF.mjs
53
+ init_esm_shims();
54
+ import crypto from "crypto";
55
+
56
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/column.js
57
+ init_esm_shims();
58
+
59
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/entity.js
60
+ init_esm_shims();
61
+ var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
62
+ function is(value, type) {
63
+ if (!value || typeof value !== "object") {
64
+ return false;
65
+ }
66
+ if (value instanceof type) {
67
+ return true;
68
+ }
69
+ if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
70
+ throw new Error(
71
+ `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.`
72
+ );
73
+ }
74
+ let cls = Object.getPrototypeOf(value).constructor;
75
+ if (cls) {
76
+ while (cls) {
77
+ if (entityKind in cls && cls[entityKind] === type[entityKind]) {
78
+ return true;
79
+ }
80
+ cls = Object.getPrototypeOf(cls);
81
+ }
82
+ }
83
+ return false;
84
+ }
85
+
86
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/column.js
87
+ var Column = class {
88
+ constructor(table, config) {
89
+ this.table = table;
90
+ this.config = config;
91
+ this.name = config.name;
92
+ this.keyAsName = config.keyAsName;
93
+ this.notNull = config.notNull;
94
+ this.default = config.default;
95
+ this.defaultFn = config.defaultFn;
96
+ this.onUpdateFn = config.onUpdateFn;
97
+ this.hasDefault = config.hasDefault;
98
+ this.primary = config.primaryKey;
99
+ this.isUnique = config.isUnique;
100
+ this.uniqueName = config.uniqueName;
101
+ this.uniqueType = config.uniqueType;
102
+ this.dataType = config.dataType;
103
+ this.columnType = config.columnType;
104
+ this.generated = config.generated;
105
+ this.generatedIdentity = config.generatedIdentity;
106
+ }
107
+ static [entityKind] = "Column";
108
+ name;
109
+ keyAsName;
110
+ primary;
111
+ notNull;
112
+ default;
113
+ defaultFn;
114
+ onUpdateFn;
115
+ hasDefault;
116
+ isUnique;
117
+ uniqueName;
118
+ uniqueType;
119
+ dataType;
120
+ columnType;
121
+ enumValues = void 0;
122
+ generated = void 0;
123
+ generatedIdentity = void 0;
124
+ config;
125
+ mapFromDriverValue(value) {
126
+ return value;
127
+ }
128
+ mapToDriverValue(value) {
129
+ return value;
130
+ }
131
+ // ** @internal */
132
+ shouldDisableInsert() {
133
+ return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
134
+ }
135
+ };
136
+
137
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/sql/sql.js
138
+ init_esm_shims();
139
+
140
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/pg-core/columns/enum.js
141
+ init_esm_shims();
142
+
143
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/pg-core/columns/common.js
144
+ init_esm_shims();
145
+
146
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/column-builder.js
147
+ init_esm_shims();
148
+ var ColumnBuilder = class {
149
+ static [entityKind] = "ColumnBuilder";
150
+ config;
151
+ constructor(name, dataType, columnType) {
152
+ this.config = {
153
+ name,
154
+ keyAsName: name === "",
155
+ notNull: false,
156
+ default: void 0,
157
+ hasDefault: false,
158
+ primaryKey: false,
159
+ isUnique: false,
160
+ uniqueName: void 0,
161
+ uniqueType: void 0,
162
+ dataType,
163
+ columnType,
164
+ generated: void 0
165
+ };
166
+ }
167
+ /**
168
+ * Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * const users = pgTable('users', {
173
+ * id: integer('id').$type<UserId>().primaryKey(),
174
+ * details: json('details').$type<UserDetails>().notNull(),
175
+ * });
176
+ * ```
177
+ */
178
+ $type() {
179
+ return this;
180
+ }
181
+ /**
182
+ * Adds a `not null` clause to the column definition.
183
+ *
184
+ * Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
185
+ */
186
+ notNull() {
187
+ this.config.notNull = true;
188
+ return this;
189
+ }
190
+ /**
191
+ * Adds a `default <value>` clause to the column definition.
192
+ *
193
+ * Affects the `insert` model of the table - columns *with* `default` are optional on insert.
194
+ *
195
+ * If you need to set a dynamic default value, use {@link $defaultFn} instead.
196
+ */
197
+ default(value) {
198
+ this.config.default = value;
199
+ this.config.hasDefault = true;
200
+ return this;
201
+ }
202
+ /**
203
+ * Adds a dynamic default value to the column.
204
+ * The function will be called when the row is inserted, and the returned value will be used as the column value.
205
+ *
206
+ * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
207
+ */
208
+ $defaultFn(fn) {
209
+ this.config.defaultFn = fn;
210
+ this.config.hasDefault = true;
211
+ return this;
212
+ }
213
+ /**
214
+ * Alias for {@link $defaultFn}.
215
+ */
216
+ $default = this.$defaultFn;
217
+ /**
218
+ * Adds a dynamic update value to the column.
219
+ * 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.
220
+ * 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.
221
+ *
222
+ * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
223
+ */
224
+ $onUpdateFn(fn) {
225
+ this.config.onUpdateFn = fn;
226
+ this.config.hasDefault = true;
227
+ return this;
228
+ }
229
+ /**
230
+ * Alias for {@link $onUpdateFn}.
231
+ */
232
+ $onUpdate = this.$onUpdateFn;
233
+ /**
234
+ * Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
235
+ *
236
+ * In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
237
+ */
238
+ primaryKey() {
239
+ this.config.primaryKey = true;
240
+ this.config.notNull = true;
241
+ return this;
242
+ }
243
+ /** @internal Sets the name of the column to the key within the table definition if a name was not given. */
244
+ setName(name) {
245
+ if (this.config.name !== "") return;
246
+ this.config.name = name;
247
+ }
248
+ };
249
+
250
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/pg-core/foreign-keys.js
251
+ init_esm_shims();
252
+
253
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/table.utils.js
254
+ init_esm_shims();
255
+ var TableName = /* @__PURE__ */ Symbol.for("drizzle:Name");
256
+
257
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/pg-core/foreign-keys.js
258
+ var ForeignKeyBuilder = class {
259
+ static [entityKind] = "PgForeignKeyBuilder";
260
+ /** @internal */
261
+ reference;
262
+ /** @internal */
263
+ _onUpdate = "no action";
264
+ /** @internal */
265
+ _onDelete = "no action";
266
+ constructor(config, actions) {
267
+ this.reference = () => {
268
+ const { name, columns, foreignColumns } = config();
269
+ return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
270
+ };
271
+ if (actions) {
272
+ this._onUpdate = actions.onUpdate;
273
+ this._onDelete = actions.onDelete;
274
+ }
275
+ }
276
+ onUpdate(action) {
277
+ this._onUpdate = action === void 0 ? "no action" : action;
278
+ return this;
279
+ }
280
+ onDelete(action) {
281
+ this._onDelete = action === void 0 ? "no action" : action;
282
+ return this;
283
+ }
284
+ /** @internal */
285
+ build(table) {
286
+ return new ForeignKey(table, this);
287
+ }
288
+ };
289
+ var ForeignKey = class {
290
+ constructor(table, builder) {
291
+ this.table = table;
292
+ this.reference = builder.reference;
293
+ this.onUpdate = builder._onUpdate;
294
+ this.onDelete = builder._onDelete;
295
+ }
296
+ static [entityKind] = "PgForeignKey";
297
+ reference;
298
+ onUpdate;
299
+ onDelete;
300
+ getName() {
301
+ const { name, columns, foreignColumns } = this.reference();
302
+ const columnNames = columns.map((column) => column.name);
303
+ const foreignColumnNames = foreignColumns.map((column) => column.name);
304
+ const chunks = [
305
+ this.table[TableName],
306
+ ...columnNames,
307
+ foreignColumns[0].table[TableName],
308
+ ...foreignColumnNames
309
+ ];
310
+ return name ?? `${chunks.join("_")}_fk`;
311
+ }
312
+ };
313
+
314
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/tracing-utils.js
315
+ init_esm_shims();
316
+ function iife(fn, ...args) {
317
+ return fn(...args);
318
+ }
319
+
320
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/pg-core/unique-constraint.js
321
+ init_esm_shims();
322
+ function uniqueKeyName(table, columns) {
323
+ return `${table[TableName]}_${columns.join("_")}_unique`;
324
+ }
325
+ var UniqueConstraintBuilder = class {
326
+ constructor(columns, name) {
327
+ this.name = name;
328
+ this.columns = columns;
329
+ }
330
+ static [entityKind] = "PgUniqueConstraintBuilder";
331
+ /** @internal */
332
+ columns;
333
+ /** @internal */
334
+ nullsNotDistinctConfig = false;
335
+ nullsNotDistinct() {
336
+ this.nullsNotDistinctConfig = true;
337
+ return this;
338
+ }
339
+ /** @internal */
340
+ build(table) {
341
+ return new UniqueConstraint(table, this.columns, this.nullsNotDistinctConfig, this.name);
342
+ }
343
+ };
344
+ var UniqueOnConstraintBuilder = class {
345
+ static [entityKind] = "PgUniqueOnConstraintBuilder";
346
+ /** @internal */
347
+ name;
348
+ constructor(name) {
349
+ this.name = name;
350
+ }
351
+ on(...columns) {
352
+ return new UniqueConstraintBuilder(columns, this.name);
353
+ }
354
+ };
355
+ var UniqueConstraint = class {
356
+ constructor(table, columns, nullsNotDistinct, name) {
357
+ this.table = table;
358
+ this.columns = columns;
359
+ this.name = name ?? uniqueKeyName(this.table, this.columns.map((column) => column.name));
360
+ this.nullsNotDistinct = nullsNotDistinct;
361
+ }
362
+ static [entityKind] = "PgUniqueConstraint";
363
+ columns;
364
+ name;
365
+ nullsNotDistinct = false;
366
+ getName() {
367
+ return this.name;
368
+ }
369
+ };
370
+
371
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/pg-core/utils/array.js
372
+ init_esm_shims();
373
+ function parsePgArrayValue(arrayString, startFrom, inQuotes) {
374
+ for (let i = startFrom; i < arrayString.length; i++) {
375
+ const char = arrayString[i];
376
+ if (char === "\\") {
377
+ i++;
378
+ continue;
379
+ }
380
+ if (char === '"') {
381
+ return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i + 1];
382
+ }
383
+ if (inQuotes) {
384
+ continue;
385
+ }
386
+ if (char === "," || char === "}") {
387
+ return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i];
388
+ }
389
+ }
390
+ return [arrayString.slice(startFrom).replace(/\\/g, ""), arrayString.length];
391
+ }
392
+ function parsePgNestedArray(arrayString, startFrom = 0) {
393
+ const result = [];
394
+ let i = startFrom;
395
+ let lastCharIsComma = false;
396
+ while (i < arrayString.length) {
397
+ const char = arrayString[i];
398
+ if (char === ",") {
399
+ if (lastCharIsComma || i === startFrom) {
400
+ result.push("");
401
+ }
402
+ lastCharIsComma = true;
403
+ i++;
404
+ continue;
405
+ }
406
+ lastCharIsComma = false;
407
+ if (char === "\\") {
408
+ i += 2;
409
+ continue;
410
+ }
411
+ if (char === '"') {
412
+ const [value2, startFrom2] = parsePgArrayValue(arrayString, i + 1, true);
413
+ result.push(value2);
414
+ i = startFrom2;
415
+ continue;
416
+ }
417
+ if (char === "}") {
418
+ return [result, i + 1];
419
+ }
420
+ if (char === "{") {
421
+ const [value2, startFrom2] = parsePgNestedArray(arrayString, i + 1);
422
+ result.push(value2);
423
+ i = startFrom2;
424
+ continue;
425
+ }
426
+ const [value, newStartFrom] = parsePgArrayValue(arrayString, i, false);
427
+ result.push(value);
428
+ i = newStartFrom;
429
+ }
430
+ return [result, i];
431
+ }
432
+ function parsePgArray(arrayString) {
433
+ const [result] = parsePgNestedArray(arrayString, 1);
434
+ return result;
435
+ }
436
+ function makePgArray(array) {
437
+ return `{${array.map((item) => {
438
+ if (Array.isArray(item)) {
439
+ return makePgArray(item);
440
+ }
441
+ if (typeof item === "string") {
442
+ return `"${item.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
443
+ }
444
+ return `${item}`;
445
+ }).join(",")}}`;
446
+ }
447
+
448
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/pg-core/columns/common.js
449
+ var PgColumnBuilder = class extends ColumnBuilder {
450
+ foreignKeyConfigs = [];
451
+ static [entityKind] = "PgColumnBuilder";
452
+ array(size) {
453
+ return new PgArrayBuilder(this.config.name, this, size);
454
+ }
455
+ references(ref, actions = {}) {
456
+ this.foreignKeyConfigs.push({ ref, actions });
457
+ return this;
458
+ }
459
+ unique(name, config) {
460
+ this.config.isUnique = true;
461
+ this.config.uniqueName = name;
462
+ this.config.uniqueType = config?.nulls;
463
+ return this;
464
+ }
465
+ generatedAlwaysAs(as) {
466
+ this.config.generated = {
467
+ as,
468
+ type: "always",
469
+ mode: "stored"
470
+ };
471
+ return this;
472
+ }
473
+ /** @internal */
474
+ buildForeignKeys(column, table) {
475
+ return this.foreignKeyConfigs.map(({ ref, actions }) => {
476
+ return iife(
477
+ (ref2, actions2) => {
478
+ const builder = new ForeignKeyBuilder(() => {
479
+ const foreignColumn = ref2();
480
+ return { columns: [column], foreignColumns: [foreignColumn] };
481
+ });
482
+ if (actions2.onUpdate) {
483
+ builder.onUpdate(actions2.onUpdate);
484
+ }
485
+ if (actions2.onDelete) {
486
+ builder.onDelete(actions2.onDelete);
487
+ }
488
+ return builder.build(table);
489
+ },
490
+ ref,
491
+ actions
492
+ );
493
+ });
494
+ }
495
+ /** @internal */
496
+ buildExtraConfigColumn(table) {
497
+ return new ExtraConfigColumn(table, this.config);
498
+ }
499
+ };
500
+ var PgColumn = class extends Column {
501
+ constructor(table, config) {
502
+ if (!config.uniqueName) {
503
+ config.uniqueName = uniqueKeyName(table, [config.name]);
504
+ }
505
+ super(table, config);
506
+ this.table = table;
507
+ }
508
+ static [entityKind] = "PgColumn";
509
+ };
510
+ var ExtraConfigColumn = class extends PgColumn {
511
+ static [entityKind] = "ExtraConfigColumn";
512
+ getSQLType() {
513
+ return this.getSQLType();
514
+ }
515
+ indexConfig = {
516
+ order: this.config.order ?? "asc",
517
+ nulls: this.config.nulls ?? "last",
518
+ opClass: this.config.opClass
519
+ };
520
+ defaultConfig = {
521
+ order: "asc",
522
+ nulls: "last",
523
+ opClass: void 0
524
+ };
525
+ asc() {
526
+ this.indexConfig.order = "asc";
527
+ return this;
528
+ }
529
+ desc() {
530
+ this.indexConfig.order = "desc";
531
+ return this;
532
+ }
533
+ nullsFirst() {
534
+ this.indexConfig.nulls = "first";
535
+ return this;
536
+ }
537
+ nullsLast() {
538
+ this.indexConfig.nulls = "last";
539
+ return this;
540
+ }
541
+ /**
542
+ * ### PostgreSQL documentation quote
543
+ *
544
+ * > An operator class with optional parameters can be specified for each column of an index.
545
+ * The operator class identifies the operators to be used by the index for that column.
546
+ * For example, a B-tree index on four-byte integers would use the int4_ops class;
547
+ * this operator class includes comparison functions for four-byte integers.
548
+ * In practice the default operator class for the column's data type is usually sufficient.
549
+ * The main point of having operator classes is that for some data types, there could be more than one meaningful ordering.
550
+ * For example, we might want to sort a complex-number data type either by absolute value or by real part.
551
+ * We could do this by defining two operator classes for the data type and then selecting the proper class when creating an index.
552
+ * More information about operator classes check:
553
+ *
554
+ * ### Useful links
555
+ * https://www.postgresql.org/docs/current/sql-createindex.html
556
+ *
557
+ * https://www.postgresql.org/docs/current/indexes-opclass.html
558
+ *
559
+ * https://www.postgresql.org/docs/current/xindex.html
560
+ *
561
+ * ### Additional types
562
+ * If you have the `pg_vector` extension installed in your database, you can use the
563
+ * `vector_l2_ops`, `vector_ip_ops`, `vector_cosine_ops`, `vector_l1_ops`, `bit_hamming_ops`, `bit_jaccard_ops`, `halfvec_l2_ops`, `sparsevec_l2_ops` options, which are predefined types.
564
+ *
565
+ * **You can always specify any string you want in the operator class, in case Drizzle doesn't have it natively in its types**
566
+ *
567
+ * @param opClass
568
+ * @returns
569
+ */
570
+ op(opClass) {
571
+ this.indexConfig.opClass = opClass;
572
+ return this;
573
+ }
574
+ };
575
+ var IndexedColumn = class {
576
+ static [entityKind] = "IndexedColumn";
577
+ constructor(name, keyAsName, type, indexConfig) {
578
+ this.name = name;
579
+ this.keyAsName = keyAsName;
580
+ this.type = type;
581
+ this.indexConfig = indexConfig;
582
+ }
583
+ name;
584
+ keyAsName;
585
+ type;
586
+ indexConfig;
587
+ };
588
+ var PgArrayBuilder = class extends PgColumnBuilder {
589
+ static [entityKind] = "PgArrayBuilder";
590
+ constructor(name, baseBuilder, size) {
591
+ super(name, "array", "PgArray");
592
+ this.config.baseBuilder = baseBuilder;
593
+ this.config.size = size;
594
+ }
595
+ /** @internal */
596
+ build(table) {
597
+ const baseColumn = this.config.baseBuilder.build(table);
598
+ return new PgArray(
599
+ table,
600
+ this.config,
601
+ baseColumn
602
+ );
603
+ }
604
+ };
605
+ var PgArray = class _PgArray extends PgColumn {
606
+ constructor(table, config, baseColumn, range) {
607
+ super(table, config);
608
+ this.baseColumn = baseColumn;
609
+ this.range = range;
610
+ this.size = config.size;
611
+ }
612
+ size;
613
+ static [entityKind] = "PgArray";
614
+ getSQLType() {
615
+ return `${this.baseColumn.getSQLType()}[${typeof this.size === "number" ? this.size : ""}]`;
616
+ }
617
+ mapFromDriverValue(value) {
618
+ if (typeof value === "string") {
619
+ value = parsePgArray(value);
620
+ }
621
+ return value.map((v) => this.baseColumn.mapFromDriverValue(v));
622
+ }
623
+ mapToDriverValue(value, isNestedArray = false) {
624
+ const a = value.map(
625
+ (v) => v === null ? null : is(this.baseColumn, _PgArray) ? this.baseColumn.mapToDriverValue(v, true) : this.baseColumn.mapToDriverValue(v)
626
+ );
627
+ if (isNestedArray) return a;
628
+ return makePgArray(a);
629
+ }
630
+ };
631
+
632
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/pg-core/columns/enum.js
633
+ var PgEnumObjectColumnBuilder = class extends PgColumnBuilder {
634
+ static [entityKind] = "PgEnumObjectColumnBuilder";
635
+ constructor(name, enumInstance) {
636
+ super(name, "string", "PgEnumObjectColumn");
637
+ this.config.enum = enumInstance;
638
+ }
639
+ /** @internal */
640
+ build(table) {
641
+ return new PgEnumObjectColumn(
642
+ table,
643
+ this.config
644
+ );
645
+ }
646
+ };
647
+ var PgEnumObjectColumn = class extends PgColumn {
648
+ static [entityKind] = "PgEnumObjectColumn";
649
+ enum;
650
+ enumValues = this.config.enum.enumValues;
651
+ constructor(table, config) {
652
+ super(table, config);
653
+ this.enum = config.enum;
654
+ }
655
+ getSQLType() {
656
+ return this.enum.enumName;
657
+ }
658
+ };
659
+ var isPgEnumSym = /* @__PURE__ */ Symbol.for("drizzle:isPgEnum");
660
+ function isPgEnum(obj) {
661
+ return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
662
+ }
663
+ var PgEnumColumnBuilder = class extends PgColumnBuilder {
664
+ static [entityKind] = "PgEnumColumnBuilder";
665
+ constructor(name, enumInstance) {
666
+ super(name, "string", "PgEnumColumn");
667
+ this.config.enum = enumInstance;
668
+ }
669
+ /** @internal */
670
+ build(table) {
671
+ return new PgEnumColumn(
672
+ table,
673
+ this.config
674
+ );
675
+ }
676
+ };
677
+ var PgEnumColumn = class extends PgColumn {
678
+ static [entityKind] = "PgEnumColumn";
679
+ enum = this.config.enum;
680
+ enumValues = this.config.enum.enumValues;
681
+ constructor(table, config) {
682
+ super(table, config);
683
+ this.enum = config.enum;
684
+ }
685
+ getSQLType() {
686
+ return this.enum.enumName;
687
+ }
688
+ };
689
+
690
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/subquery.js
691
+ init_esm_shims();
692
+ var Subquery = class {
693
+ static [entityKind] = "Subquery";
694
+ constructor(sql2, fields, alias, isWith = false, usedTables = []) {
695
+ this._ = {
696
+ brand: "Subquery",
697
+ sql: sql2,
698
+ selectedFields: fields,
699
+ alias,
700
+ isWith,
701
+ usedTables
702
+ };
703
+ }
704
+ // getSQL(): SQL<unknown> {
705
+ // return new SQL([this]);
706
+ // }
707
+ };
708
+ var WithSubquery = class extends Subquery {
709
+ static [entityKind] = "WithSubquery";
710
+ };
711
+
712
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/tracing.js
713
+ init_esm_shims();
714
+
715
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/version.js
716
+ init_esm_shims();
717
+ var version = "0.45.2";
718
+
719
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/tracing.js
720
+ var otel;
721
+ var rawTracer;
722
+ var tracer = {
723
+ startActiveSpan(name, fn) {
724
+ if (!otel) {
725
+ return fn();
726
+ }
727
+ if (!rawTracer) {
728
+ rawTracer = otel.trace.getTracer("drizzle-orm", version);
729
+ }
730
+ return iife(
731
+ (otel2, rawTracer2) => rawTracer2.startActiveSpan(
732
+ name,
733
+ (span) => {
734
+ try {
735
+ return fn(span);
736
+ } catch (e) {
737
+ span.setStatus({
738
+ code: otel2.SpanStatusCode.ERROR,
739
+ message: e instanceof Error ? e.message : "Unknown error"
740
+ // eslint-disable-line no-instanceof/no-instanceof
741
+ });
742
+ throw e;
743
+ } finally {
744
+ span.end();
745
+ }
746
+ }
747
+ ),
748
+ otel,
749
+ rawTracer
750
+ );
751
+ }
752
+ };
753
+
754
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/view-common.js
755
+ init_esm_shims();
756
+ var ViewBaseConfig = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig");
757
+
758
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/table.js
759
+ init_esm_shims();
760
+ var Schema = /* @__PURE__ */ Symbol.for("drizzle:Schema");
761
+ var Columns = /* @__PURE__ */ Symbol.for("drizzle:Columns");
762
+ var ExtraConfigColumns = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigColumns");
763
+ var OriginalName = /* @__PURE__ */ Symbol.for("drizzle:OriginalName");
764
+ var BaseName = /* @__PURE__ */ Symbol.for("drizzle:BaseName");
765
+ var IsAlias = /* @__PURE__ */ Symbol.for("drizzle:IsAlias");
766
+ var ExtraConfigBuilder = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder");
767
+ var IsDrizzleTable = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
768
+ var Table = class {
769
+ static [entityKind] = "Table";
770
+ /** @internal */
771
+ static Symbol = {
772
+ Name: TableName,
773
+ Schema,
774
+ OriginalName,
775
+ Columns,
776
+ ExtraConfigColumns,
777
+ BaseName,
778
+ IsAlias,
779
+ ExtraConfigBuilder
780
+ };
781
+ /**
782
+ * @internal
783
+ * Can be changed if the table is aliased.
784
+ */
785
+ [TableName];
786
+ /**
787
+ * @internal
788
+ * Used to store the original name of the table, before any aliasing.
789
+ */
790
+ [OriginalName];
791
+ /** @internal */
792
+ [Schema];
793
+ /** @internal */
794
+ [Columns];
795
+ /** @internal */
796
+ [ExtraConfigColumns];
797
+ /**
798
+ * @internal
799
+ * Used to store the table name before the transformation via the `tableCreator` functions.
800
+ */
801
+ [BaseName];
802
+ /** @internal */
803
+ [IsAlias] = false;
804
+ /** @internal */
805
+ [IsDrizzleTable] = true;
806
+ /** @internal */
807
+ [ExtraConfigBuilder] = void 0;
808
+ constructor(name, schema, baseName) {
809
+ this[TableName] = this[OriginalName] = name;
810
+ this[Schema] = schema;
811
+ this[BaseName] = baseName;
812
+ }
813
+ };
814
+ function getTableName(table) {
815
+ return table[TableName];
816
+ }
817
+ function getTableUniqueName(table) {
818
+ return `${table[Schema] ?? "public"}.${table[TableName]}`;
819
+ }
820
+
821
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@neondatabase+serverless@1.1.0_@opentelemetry+api@1.9.1_@types+pg@8.20.0_kysely@0.28.16_pg@8.22.0/node_modules/drizzle-orm/sql/sql.js
822
+ var FakePrimitiveParam = class {
823
+ static [entityKind] = "FakePrimitiveParam";
824
+ };
825
+ function isSQLWrapper(value) {
826
+ return value !== null && value !== void 0 && typeof value.getSQL === "function";
827
+ }
828
+ function mergeQueries(queries) {
829
+ const result = { sql: "", params: [] };
830
+ for (const query of queries) {
831
+ result.sql += query.sql;
832
+ result.params.push(...query.params);
833
+ if (query.typings?.length) {
834
+ if (!result.typings) {
835
+ result.typings = [];
836
+ }
837
+ result.typings.push(...query.typings);
838
+ }
839
+ }
840
+ return result;
841
+ }
842
+ var StringChunk = class {
843
+ static [entityKind] = "StringChunk";
844
+ value;
845
+ constructor(value) {
846
+ this.value = Array.isArray(value) ? value : [value];
847
+ }
848
+ getSQL() {
849
+ return new SQL([this]);
850
+ }
851
+ };
852
+ var SQL = class _SQL {
853
+ constructor(queryChunks) {
854
+ this.queryChunks = queryChunks;
855
+ for (const chunk of queryChunks) {
856
+ if (is(chunk, Table)) {
857
+ const schemaName = chunk[Table.Symbol.Schema];
858
+ this.usedTables.push(
859
+ schemaName === void 0 ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]
860
+ );
861
+ }
862
+ }
863
+ }
864
+ static [entityKind] = "SQL";
865
+ /** @internal */
866
+ decoder = noopDecoder;
867
+ shouldInlineParams = false;
868
+ /** @internal */
869
+ usedTables = [];
870
+ append(query) {
871
+ this.queryChunks.push(...query.queryChunks);
872
+ return this;
873
+ }
874
+ toQuery(config) {
875
+ return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
876
+ const query = this.buildQueryFromSourceParams(this.queryChunks, config);
877
+ span?.setAttributes({
878
+ "drizzle.query.text": query.sql,
879
+ "drizzle.query.params": JSON.stringify(query.params)
880
+ });
881
+ return query;
882
+ });
883
+ }
884
+ buildQueryFromSourceParams(chunks, _config) {
885
+ const config = Object.assign({}, _config, {
886
+ inlineParams: _config.inlineParams || this.shouldInlineParams,
887
+ paramStartIndex: _config.paramStartIndex || { value: 0 }
888
+ });
889
+ const {
890
+ casing,
891
+ escapeName,
892
+ escapeParam,
893
+ prepareTyping,
894
+ inlineParams,
895
+ paramStartIndex
896
+ } = config;
897
+ return mergeQueries(chunks.map((chunk) => {
898
+ if (is(chunk, StringChunk)) {
899
+ return { sql: chunk.value.join(""), params: [] };
900
+ }
901
+ if (is(chunk, Name)) {
902
+ return { sql: escapeName(chunk.value), params: [] };
903
+ }
904
+ if (chunk === void 0) {
905
+ return { sql: "", params: [] };
906
+ }
907
+ if (Array.isArray(chunk)) {
908
+ const result = [new StringChunk("(")];
909
+ for (const [i, p] of chunk.entries()) {
910
+ result.push(p);
911
+ if (i < chunk.length - 1) {
912
+ result.push(new StringChunk(", "));
913
+ }
914
+ }
915
+ result.push(new StringChunk(")"));
916
+ return this.buildQueryFromSourceParams(result, config);
917
+ }
918
+ if (is(chunk, _SQL)) {
919
+ return this.buildQueryFromSourceParams(chunk.queryChunks, {
920
+ ...config,
921
+ inlineParams: inlineParams || chunk.shouldInlineParams
922
+ });
923
+ }
924
+ if (is(chunk, Table)) {
925
+ const schemaName = chunk[Table.Symbol.Schema];
926
+ const tableName = chunk[Table.Symbol.Name];
927
+ return {
928
+ sql: schemaName === void 0 || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
929
+ params: []
930
+ };
931
+ }
932
+ if (is(chunk, Column)) {
933
+ const columnName = casing.getColumnCasing(chunk);
934
+ if (_config.invokeSource === "indexes") {
935
+ return { sql: escapeName(columnName), params: [] };
936
+ }
937
+ const schemaName = chunk.table[Table.Symbol.Schema];
938
+ return {
939
+ sql: chunk.table[IsAlias] || schemaName === void 0 ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
940
+ params: []
941
+ };
942
+ }
943
+ if (is(chunk, View)) {
944
+ const schemaName = chunk[ViewBaseConfig].schema;
945
+ const viewName = chunk[ViewBaseConfig].name;
946
+ return {
947
+ sql: schemaName === void 0 || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
948
+ params: []
949
+ };
950
+ }
951
+ if (is(chunk, Param)) {
952
+ if (is(chunk.value, Placeholder)) {
953
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
954
+ }
955
+ const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
956
+ if (is(mappedValue, _SQL)) {
957
+ return this.buildQueryFromSourceParams([mappedValue], config);
958
+ }
959
+ if (inlineParams) {
960
+ return { sql: this.mapInlineParam(mappedValue, config), params: [] };
961
+ }
962
+ let typings = ["none"];
963
+ if (prepareTyping) {
964
+ typings = [prepareTyping(chunk.encoder)];
965
+ }
966
+ return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
967
+ }
968
+ if (is(chunk, Placeholder)) {
969
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
970
+ }
971
+ if (is(chunk, _SQL.Aliased) && chunk.fieldAlias !== void 0) {
972
+ return { sql: escapeName(chunk.fieldAlias), params: [] };
973
+ }
974
+ if (is(chunk, Subquery)) {
975
+ if (chunk._.isWith) {
976
+ return { sql: escapeName(chunk._.alias), params: [] };
977
+ }
978
+ return this.buildQueryFromSourceParams([
979
+ new StringChunk("("),
980
+ chunk._.sql,
981
+ new StringChunk(") "),
982
+ new Name(chunk._.alias)
983
+ ], config);
984
+ }
985
+ if (isPgEnum(chunk)) {
986
+ if (chunk.schema) {
987
+ return { sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName), params: [] };
988
+ }
989
+ return { sql: escapeName(chunk.enumName), params: [] };
990
+ }
991
+ if (isSQLWrapper(chunk)) {
992
+ if (chunk.shouldOmitSQLParens?.()) {
993
+ return this.buildQueryFromSourceParams([chunk.getSQL()], config);
994
+ }
995
+ return this.buildQueryFromSourceParams([
996
+ new StringChunk("("),
997
+ chunk.getSQL(),
998
+ new StringChunk(")")
999
+ ], config);
1000
+ }
1001
+ if (inlineParams) {
1002
+ return { sql: this.mapInlineParam(chunk, config), params: [] };
1003
+ }
1004
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
1005
+ }));
1006
+ }
1007
+ mapInlineParam(chunk, { escapeString }) {
1008
+ if (chunk === null) {
1009
+ return "null";
1010
+ }
1011
+ if (typeof chunk === "number" || typeof chunk === "boolean") {
1012
+ return chunk.toString();
1013
+ }
1014
+ if (typeof chunk === "string") {
1015
+ return escapeString(chunk);
1016
+ }
1017
+ if (typeof chunk === "object") {
1018
+ const mappedValueAsString = chunk.toString();
1019
+ if (mappedValueAsString === "[object Object]") {
1020
+ return escapeString(JSON.stringify(chunk));
1021
+ }
1022
+ return escapeString(mappedValueAsString);
1023
+ }
1024
+ throw new Error("Unexpected param value: " + chunk);
1025
+ }
1026
+ getSQL() {
1027
+ return this;
1028
+ }
1029
+ as(alias) {
1030
+ if (alias === void 0) {
1031
+ return this;
1032
+ }
1033
+ return new _SQL.Aliased(this, alias);
1034
+ }
1035
+ mapWith(decoder) {
1036
+ this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
1037
+ return this;
1038
+ }
1039
+ inlineParams() {
1040
+ this.shouldInlineParams = true;
1041
+ return this;
1042
+ }
1043
+ /**
1044
+ * This method is used to conditionally include a part of the query.
1045
+ *
1046
+ * @param condition - Condition to check
1047
+ * @returns itself if the condition is `true`, otherwise `undefined`
1048
+ */
1049
+ if(condition) {
1050
+ return condition ? this : void 0;
1051
+ }
1052
+ };
1053
+ var Name = class {
1054
+ constructor(value) {
1055
+ this.value = value;
1056
+ }
1057
+ static [entityKind] = "Name";
1058
+ brand;
1059
+ getSQL() {
1060
+ return new SQL([this]);
1061
+ }
1062
+ };
1063
+ function isDriverValueEncoder(value) {
1064
+ return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
1065
+ }
1066
+ var noopDecoder = {
1067
+ mapFromDriverValue: (value) => value
1068
+ };
1069
+ var noopEncoder = {
1070
+ mapToDriverValue: (value) => value
1071
+ };
1072
+ var noopMapper = {
1073
+ ...noopDecoder,
1074
+ ...noopEncoder
1075
+ };
1076
+ var Param = class {
1077
+ /**
1078
+ * @param value - Parameter value
1079
+ * @param encoder - Encoder to convert the value to a driver parameter
1080
+ */
1081
+ constructor(value, encoder = noopEncoder) {
1082
+ this.value = value;
1083
+ this.encoder = encoder;
1084
+ }
1085
+ static [entityKind] = "Param";
1086
+ brand;
1087
+ getSQL() {
1088
+ return new SQL([this]);
1089
+ }
1090
+ };
1091
+ function sql(strings, ...params) {
1092
+ const queryChunks = [];
1093
+ if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
1094
+ queryChunks.push(new StringChunk(strings[0]));
1095
+ }
1096
+ for (const [paramIndex, param2] of params.entries()) {
1097
+ queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
1098
+ }
1099
+ return new SQL(queryChunks);
1100
+ }
1101
+ ((sql2) => {
1102
+ function empty() {
1103
+ return new SQL([]);
1104
+ }
1105
+ sql2.empty = empty;
1106
+ function fromList(list) {
1107
+ return new SQL(list);
1108
+ }
1109
+ sql2.fromList = fromList;
1110
+ function raw(str) {
1111
+ return new SQL([new StringChunk(str)]);
1112
+ }
1113
+ sql2.raw = raw;
1114
+ function join(chunks, separator) {
1115
+ const result = [];
1116
+ for (const [i, chunk] of chunks.entries()) {
1117
+ if (i > 0 && separator !== void 0) {
1118
+ result.push(separator);
1119
+ }
1120
+ result.push(chunk);
1121
+ }
1122
+ return new SQL(result);
1123
+ }
1124
+ sql2.join = join;
1125
+ function identifier(value) {
1126
+ return new Name(value);
1127
+ }
1128
+ sql2.identifier = identifier;
1129
+ function placeholder2(name2) {
1130
+ return new Placeholder(name2);
1131
+ }
1132
+ sql2.placeholder = placeholder2;
1133
+ function param2(value, encoder) {
1134
+ return new Param(value, encoder);
1135
+ }
1136
+ sql2.param = param2;
1137
+ })(sql || (sql = {}));
1138
+ ((SQL2) => {
1139
+ class Aliased {
1140
+ constructor(sql2, fieldAlias) {
1141
+ this.sql = sql2;
1142
+ this.fieldAlias = fieldAlias;
1143
+ }
1144
+ static [entityKind] = "SQL.Aliased";
1145
+ /** @internal */
1146
+ isSelectionField = false;
1147
+ getSQL() {
1148
+ return this.sql;
1149
+ }
1150
+ /** @internal */
1151
+ clone() {
1152
+ return new Aliased(this.sql, this.fieldAlias);
1153
+ }
1154
+ }
1155
+ SQL2.Aliased = Aliased;
1156
+ })(SQL || (SQL = {}));
1157
+ var Placeholder = class {
1158
+ constructor(name2) {
1159
+ this.name = name2;
1160
+ }
1161
+ static [entityKind] = "Placeholder";
1162
+ getSQL() {
1163
+ return new SQL([this]);
1164
+ }
1165
+ };
1166
+ function fillPlaceholders(params, values) {
1167
+ return params.map((p) => {
1168
+ if (is(p, Placeholder)) {
1169
+ if (!(p.name in values)) {
1170
+ throw new Error(`No value for placeholder "${p.name}" was provided`);
1171
+ }
1172
+ return values[p.name];
1173
+ }
1174
+ if (is(p, Param) && is(p.value, Placeholder)) {
1175
+ if (!(p.value.name in values)) {
1176
+ throw new Error(`No value for placeholder "${p.value.name}" was provided`);
1177
+ }
1178
+ return p.encoder.mapToDriverValue(values[p.value.name]);
1179
+ }
1180
+ return p;
1181
+ });
1182
+ }
1183
+ var IsDrizzleView = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
1184
+ var View = class {
1185
+ static [entityKind] = "View";
1186
+ /** @internal */
1187
+ [ViewBaseConfig];
1188
+ /** @internal */
1189
+ [IsDrizzleView] = true;
1190
+ constructor({ name: name2, schema, selectedFields, query }) {
1191
+ this[ViewBaseConfig] = {
1192
+ name: name2,
1193
+ originalName: name2,
1194
+ schema,
1195
+ selectedFields,
1196
+ query,
1197
+ isExisting: !query,
1198
+ isAlias: false
1199
+ };
1200
+ }
1201
+ getSQL() {
1202
+ return new SQL([this]);
1203
+ }
1204
+ };
1205
+ Column.prototype.getSQL = function() {
1206
+ return new SQL([this]);
1207
+ };
1208
+ Table.prototype.getSQL = function() {
1209
+ return new SQL([this]);
1210
+ };
1211
+ Subquery.prototype.getSQL = function() {
1212
+ return new SQL([this]);
1213
+ };
1214
+
1215
+ // ../api/dist/chunk-TK4DNRFF.mjs
1216
+ function quoteIdent(name) {
1217
+ if (!/^[a-z][a-z0-9_-]*$/.test(name)) throw new Error(`Unsafe identifier: ${name}`);
1218
+ return `"${name}"`;
1219
+ }
1220
+ function paragraphMediaFieldNames(pType) {
1221
+ return new Set(
1222
+ pType.fields.filter((f) => f.field_type === "image" || f.field_type === "video" || f.field_type === "file").map((f) => f.name)
1223
+ );
1224
+ }
1225
+ async function fetchParagraphMediaIds(db, pType, itemId, fieldName) {
1226
+ const mediaColumns = pType.fields.filter((f) => f.field_type === "image" || f.field_type === "video" || f.field_type === "file").map((f) => f.db_column.column_name);
1227
+ if (mediaColumns.length === 0) return [];
1228
+ const tbl = sql.raw(quoteIdent(pType.db.table_name));
1229
+ const cols = sql.join(mediaColumns.map((c) => sql.raw(quoteIdent(c))), sql`, `);
1230
+ const result = await db.execute(
1231
+ sql`SELECT ${cols} FROM ${tbl} WHERE parent_id = ${itemId} AND parent_field = ${fieldName}`
1232
+ );
1233
+ const ids = [];
1234
+ for (const row of result.rows) {
1235
+ for (const col of mediaColumns) {
1236
+ const v = row[col];
1237
+ if (typeof v === "string" && v !== "") ids.push(v);
1238
+ }
1239
+ }
1240
+ return ids;
1241
+ }
1242
+ function nestedParagraphFields(pType, registry) {
1243
+ if (!registry) return [];
1244
+ const out = [];
1245
+ for (const f of pType.fields) {
1246
+ if (f.db_column !== null) continue;
1247
+ const comp = f.ui_component;
1248
+ if (comp.component !== "paragraph-embed" || !comp.ref) continue;
1249
+ const nType = registry.paragraph_types[comp.ref];
1250
+ if (nType) out.push({ fieldName: f.name, nType });
1251
+ }
1252
+ return out;
1253
+ }
1254
+ async function fetchParagraphRowIds(db, pType, itemId, fieldName) {
1255
+ const tbl = sql.raw(quoteIdent(pType.db.table_name));
1256
+ const result = await db.execute(
1257
+ sql`SELECT id FROM ${tbl} WHERE parent_id = ${itemId} AND parent_field = ${fieldName}`
1258
+ );
1259
+ return result.rows.map((r) => r["id"]).filter((id) => typeof id === "string");
1260
+ }
1261
+ async function persistParagraphField(db, itemId, parentType, fieldName, pType, items, registry) {
1262
+ const removed = await fetchParagraphMediaIds(db, pType, itemId, fieldName);
1263
+ const nested = nestedParagraphFields(pType, registry);
1264
+ if (nested.length > 0) {
1265
+ const staleIds = await fetchParagraphRowIds(db, pType, itemId, fieldName);
1266
+ for (const rowId of staleIds) {
1267
+ for (const n of nested) {
1268
+ const d = await deleteParagraphField(db, rowId, n.fieldName, n.nType, registry);
1269
+ removed.push(...d.removed);
1270
+ }
1271
+ }
1272
+ }
1273
+ const tbl = sql.raw(quoteIdent(pType.db.table_name));
1274
+ await db.execute(sql`DELETE FROM ${tbl} WHERE parent_id = ${itemId} AND parent_field = ${fieldName}`);
1275
+ const mediaFieldNames = paragraphMediaFieldNames(pType);
1276
+ const added = [];
1277
+ for (let i = 0; i < items.length; i++) {
1278
+ const pItem = items[i];
1279
+ const rowId = crypto.randomUUID();
1280
+ const data = {
1281
+ id: rowId,
1282
+ parent_id: itemId,
1283
+ parent_type: parentType,
1284
+ parent_field: fieldName,
1285
+ order: i,
1286
+ created_at: /* @__PURE__ */ new Date(),
1287
+ updated_at: /* @__PURE__ */ new Date()
1288
+ };
1289
+ for (const pf of pType.fields) {
1290
+ if (!pf.db_column || pf.db_column.junction) continue;
1291
+ data[pf.db_column.column_name] = pItem[pf.name] ?? null;
1292
+ }
1293
+ const cols = sql.join(Object.keys(data).map((k) => sql.raw(quoteIdent(k))), sql`, `);
1294
+ const vals = sql.join(Object.values(data).map((v) => sql`${v}`), sql`, `);
1295
+ await db.execute(sql`INSERT INTO ${tbl} (${cols}) VALUES (${vals})`);
1296
+ for (const name of mediaFieldNames) {
1297
+ const val = pItem[name];
1298
+ if (typeof val === "string" && val !== "") added.push(val);
1299
+ }
1300
+ for (const n of nested) {
1301
+ const nestedItems = Array.isArray(pItem[n.fieldName]) ? pItem[n.fieldName] : [];
1302
+ const d = await persistParagraphField(
1303
+ db,
1304
+ rowId,
1305
+ pType.db.table_name,
1306
+ n.fieldName,
1307
+ n.nType,
1308
+ nestedItems,
1309
+ registry
1310
+ );
1311
+ added.push(...d.added);
1312
+ removed.push(...d.removed);
1313
+ }
1314
+ }
1315
+ return { added, removed };
1316
+ }
1317
+ async function deleteParagraphField(db, itemId, fieldName, pType, registry) {
1318
+ const removed = await fetchParagraphMediaIds(db, pType, itemId, fieldName);
1319
+ const nested = nestedParagraphFields(pType, registry);
1320
+ if (nested.length > 0) {
1321
+ const rowIds = await fetchParagraphRowIds(db, pType, itemId, fieldName);
1322
+ for (const rowId of rowIds) {
1323
+ for (const n of nested) {
1324
+ const d = await deleteParagraphField(db, rowId, n.fieldName, n.nType, registry);
1325
+ removed.push(...d.removed);
1326
+ }
1327
+ }
1328
+ }
1329
+ const tbl = sql.raw(quoteIdent(pType.db.table_name));
1330
+ await db.execute(sql`DELETE FROM ${tbl} WHERE parent_id = ${itemId} AND parent_field = ${fieldName}`);
1331
+ return { added: [], removed };
1332
+ }
1333
+ async function persistJunctionField(db, itemId, junction, relatedIds) {
1334
+ const tbl = sql.raw(quoteIdent(junction.table_name));
1335
+ const left = sql.raw(quoteIdent(junction.left_column));
1336
+ const right = sql.raw(quoteIdent(junction.right_column));
1337
+ await db.execute(sql`DELETE FROM ${tbl} WHERE ${left} = ${itemId}`);
1338
+ for (const rid of relatedIds) {
1339
+ await db.execute(sql`INSERT INTO ${tbl} (${left}, ${right}) VALUES (${itemId}, ${rid})`);
1340
+ }
1341
+ }
1342
+ function buildRelationsMap(fields, registry) {
1343
+ const relations = {};
1344
+ for (const field of fields) {
1345
+ if (field.field_type === "image" || field.field_type === "video" || field.field_type === "file") {
1346
+ if (!field.db_column) continue;
1347
+ relations[field.name] = { type: "media", fk_column: field.db_column.column_name };
1348
+ } else if (field.field_type === "paragraph") {
1349
+ const ref = field.ui_component.ref;
1350
+ const pType = ref ? registry.paragraph_types[ref] : void 0;
1351
+ if (!pType) continue;
1352
+ relations[field.name] = { type: "paragraph", table: pType.db.table_name };
1353
+ } else if (field.field_type === "reference") {
1354
+ if (!field.db_column) continue;
1355
+ if (field.db_column.junction) {
1356
+ const j = field.db_column.junction;
1357
+ relations[field.name] = {
1358
+ type: "junction",
1359
+ table: j.right_table,
1360
+ junction_table: j.table_name,
1361
+ left_column: j.left_column,
1362
+ right_column: j.right_column,
1363
+ order_column: j.order_column
1364
+ };
1365
+ } else if (field.db_column.foreign_key) {
1366
+ relations[field.name] = {
1367
+ type: "reference",
1368
+ table: field.db_column.foreign_key.table,
1369
+ fk_column: field.db_column.column_name
1370
+ };
1371
+ }
1372
+ }
1373
+ }
1374
+ return relations;
1375
+ }
1376
+ function groupBy(items, key) {
1377
+ const result = {};
1378
+ for (const item of items) {
1379
+ const k = String(item[key]);
1380
+ if (!result[k]) result[k] = [];
1381
+ result[k].push(item);
1382
+ }
1383
+ return result;
1384
+ }
1385
+ async function resolveRelationField(db, rows, fieldName, rel, cache, publishedOnly = false) {
1386
+ if (rows.length === 0) return;
1387
+ if (rel.type === "paragraph") {
1388
+ const parentIds = rows.map((r) => r["id"]);
1389
+ const inList = sql.join(parentIds.map((id) => sql`${id}`), sql`, `);
1390
+ const result = await db.execute(
1391
+ sql`SELECT * FROM ${sql.raw(quoteIdent(rel.table))} WHERE parent_id IN (${inList}) AND parent_field = ${fieldName} ORDER BY "order" ASC`
1392
+ );
1393
+ const byParent = groupBy(result.rows, "parent_id");
1394
+ for (const row of rows) {
1395
+ row[fieldName] = byParent[row["id"]] ?? [];
1396
+ }
1397
+ } else if (rel.type === "reference") {
1398
+ const fkValues = rows.map((r) => r[rel.fk_column]).filter(Boolean);
1399
+ if (fkValues.length === 0) {
1400
+ for (const row of rows) row[fieldName] = null;
1401
+ return;
1402
+ }
1403
+ const unique = [...new Set(fkValues)];
1404
+ const uncached = unique.filter((id) => !cache.has(`${rel.table}:${id}`));
1405
+ if (uncached.length > 0) {
1406
+ const inList = sql.join(uncached.map((id) => sql`${id}`), sql`, `);
1407
+ const publishedCond = publishedOnly ? sql` AND published = true` : sql``;
1408
+ const result = await db.execute(
1409
+ sql`SELECT * FROM ${sql.raw(quoteIdent(rel.table))} WHERE id IN (${inList})${publishedCond}`
1410
+ );
1411
+ for (const item of result.rows) {
1412
+ cache.set(`${rel.table}:${item["id"]}`, item);
1413
+ }
1414
+ }
1415
+ for (const row of rows) {
1416
+ const fkVal = row[rel.fk_column];
1417
+ row[fieldName] = fkVal ? cache.get(`${rel.table}:${fkVal}`) ?? null : null;
1418
+ }
1419
+ } else if (rel.type === "junction") {
1420
+ const parentIds = rows.map((r) => r["id"]);
1421
+ const inList = sql.join(parentIds.map((id) => sql`${id}`), sql`, `);
1422
+ const orderBy = rel.order_column ? sql` ORDER BY "order" ASC` : sql``;
1423
+ const junctionResult = await db.execute(
1424
+ sql`SELECT * FROM ${sql.raw(quoteIdent(rel.junction_table))} WHERE ${sql.raw(quoteIdent(rel.left_column))} IN (${inList})${orderBy}`
1425
+ );
1426
+ const jRows = junctionResult.rows;
1427
+ const rightIds = [...new Set(jRows.map((r) => r[rel.right_column]))];
1428
+ const uncached = rightIds.filter((id) => !cache.has(`${rel.table}:${id}`));
1429
+ if (uncached.length > 0) {
1430
+ const rightInList = sql.join(uncached.map((id) => sql`${id}`), sql`, `);
1431
+ const publishedCond = publishedOnly ? sql` AND published = true` : sql``;
1432
+ const entitiesResult = await db.execute(
1433
+ sql`SELECT * FROM ${sql.raw(quoteIdent(rel.table))} WHERE id IN (${rightInList})${publishedCond}`
1434
+ );
1435
+ for (const item of entitiesResult.rows) {
1436
+ cache.set(`${rel.table}:${item["id"]}`, item);
1437
+ }
1438
+ }
1439
+ const byLeft = groupBy(jRows, rel.left_column);
1440
+ for (const row of rows) {
1441
+ const jEntries = byLeft[row["id"]] ?? [];
1442
+ row[fieldName] = jEntries.map((jr) => cache.get(`${rel.table}:${jr[rel.right_column]}`)).filter(Boolean);
1443
+ }
1444
+ } else if (rel.type === "media") {
1445
+ const fkValues = rows.map((r) => r[rel.fk_column]).filter(Boolean);
1446
+ if (fkValues.length === 0) {
1447
+ for (const row of rows) row[fieldName] = null;
1448
+ return;
1449
+ }
1450
+ const unique = [...new Set(fkValues)];
1451
+ const uncached = unique.filter((id) => !cache.has(`media:${id}`));
1452
+ if (uncached.length > 0) {
1453
+ const inList = sql.join(uncached.map((id) => sql`${id}`), sql`, `);
1454
+ const result = await db.execute(sql`SELECT * FROM "media" WHERE id IN (${inList})`);
1455
+ for (const item of result.rows) {
1456
+ cache.set(`media:${item["id"]}`, item);
1457
+ }
1458
+ }
1459
+ for (const row of rows) {
1460
+ const fkVal = row[rel.fk_column];
1461
+ row[fieldName] = fkVal ? cache.get(`media:${fkVal}`) ?? null : null;
1462
+ }
1463
+ }
1464
+ }
1465
+ async function resolveRelationBareIds(db, rows, fieldName, rel) {
1466
+ if (rows.length === 0) return;
1467
+ if (rel.type === "paragraph") {
1468
+ const parentIds = rows.map((r) => r["id"]);
1469
+ const inList = sql.join(parentIds.map((id) => sql`${id}`), sql`, `);
1470
+ const result = await db.execute(
1471
+ sql`SELECT id, parent_id FROM ${sql.raw(quoteIdent(rel.table))} WHERE parent_id IN (${inList}) AND parent_field = ${fieldName} ORDER BY "order" ASC`
1472
+ );
1473
+ const byParent = groupBy(result.rows, "parent_id");
1474
+ for (const row of rows) {
1475
+ row[fieldName] = (byParent[row["id"]] ?? []).map((r) => r["id"]);
1476
+ }
1477
+ } else if (rel.type === "junction") {
1478
+ const parentIds = rows.map((r) => r["id"]);
1479
+ const inList = sql.join(parentIds.map((id) => sql`${id}`), sql`, `);
1480
+ const result = await db.execute(
1481
+ sql`SELECT ${sql.raw(quoteIdent(rel.left_column))} AS left_id, ${sql.raw(quoteIdent(rel.right_column))} AS right_id FROM ${sql.raw(quoteIdent(rel.junction_table))} WHERE ${sql.raw(quoteIdent(rel.left_column))} IN (${inList})`
1482
+ );
1483
+ const byLeft = groupBy(result.rows, "left_id");
1484
+ for (const row of rows) {
1485
+ row[fieldName] = (byLeft[row["id"]] ?? []).map((r) => r["right_id"]);
1486
+ }
1487
+ }
1488
+ }
1489
+
1490
+ export {
1491
+ __require,
1492
+ __esm,
1493
+ __commonJS,
1494
+ __export,
1495
+ __toESM,
1496
+ __toCommonJS,
1497
+ init_esm_shims,
1498
+ entityKind,
1499
+ is,
1500
+ Column,
1501
+ PgColumnBuilder,
1502
+ PgColumn,
1503
+ Subquery,
1504
+ WithSubquery,
1505
+ tracer,
1506
+ ViewBaseConfig,
1507
+ Schema,
1508
+ Columns,
1509
+ Table,
1510
+ getTableName,
1511
+ getTableUniqueName,
1512
+ isSQLWrapper,
1513
+ StringChunk,
1514
+ SQL,
1515
+ isDriverValueEncoder,
1516
+ Param,
1517
+ sql,
1518
+ Placeholder,
1519
+ fillPlaceholders,
1520
+ View,
1521
+ persistParagraphField,
1522
+ deleteParagraphField,
1523
+ persistJunctionField,
1524
+ buildRelationsMap,
1525
+ resolveRelationField,
1526
+ resolveRelationBareIds
1527
+ };