@coffre/cli 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1078 @@
1
+ import { n as ROLE_NAMES, r as assignableToEnvironment } from "./access-CO1kGjWW.js";
2
+ import { B as textDecoder, G as sql, J as Table, M as getColumnNameAndConfig, at as TableName, ct as entityKind, ot as ColumnBuilder, st as Column } from "./relations-CJCGPRst.js";
3
+ import { i as relationsOf, r as ACTIVE_SUBJECT, t as asPostgres } from "./portable-CPh2thNN.js";
4
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/checks.js
5
+ var CheckBuilder = class {
6
+ constructor(name, value) {
7
+ this.name = name;
8
+ this.value = value;
9
+ }
10
+ static [entityKind] = "SQLiteCheckBuilder";
11
+ brand;
12
+ build(table) {
13
+ return new Check(table, this);
14
+ }
15
+ };
16
+ var Check = class {
17
+ constructor(table, builder) {
18
+ this.table = table;
19
+ this.name = builder.name;
20
+ this.value = builder.value;
21
+ }
22
+ static [entityKind] = "SQLiteCheck";
23
+ name;
24
+ value;
25
+ };
26
+ function check(name, value) {
27
+ return new CheckBuilder(name, value);
28
+ }
29
+ //#endregion
30
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
31
+ var ForeignKeyBuilder = class {
32
+ static [entityKind] = "SQLiteForeignKeyBuilder";
33
+ /** @internal */
34
+ reference;
35
+ /** @internal */
36
+ _onUpdate;
37
+ /** @internal */
38
+ _onDelete;
39
+ constructor(config, actions) {
40
+ this.reference = () => {
41
+ const { name, columns, foreignColumns } = config();
42
+ return {
43
+ name,
44
+ columns,
45
+ foreignTable: foreignColumns[0].table,
46
+ foreignColumns
47
+ };
48
+ };
49
+ if (actions) {
50
+ this._onUpdate = actions.onUpdate;
51
+ this._onDelete = actions.onDelete;
52
+ }
53
+ }
54
+ onUpdate(action) {
55
+ this._onUpdate = action;
56
+ return this;
57
+ }
58
+ onDelete(action) {
59
+ this._onDelete = action;
60
+ return this;
61
+ }
62
+ /** @internal */
63
+ build(table) {
64
+ return new ForeignKey(table, this);
65
+ }
66
+ };
67
+ var ForeignKey = class {
68
+ constructor(table, builder) {
69
+ this.table = table;
70
+ this.reference = builder.reference;
71
+ this.onUpdate = builder._onUpdate;
72
+ this.onDelete = builder._onDelete;
73
+ }
74
+ static [entityKind] = "SQLiteForeignKey";
75
+ reference;
76
+ onUpdate;
77
+ onDelete;
78
+ getName() {
79
+ const { name, columns, foreignColumns } = this.reference();
80
+ const columnNames = columns.map((column) => column.name);
81
+ const foreignColumnNames = foreignColumns.map((column) => column.name);
82
+ const chunks = [
83
+ this.table[TableName],
84
+ ...columnNames,
85
+ foreignColumns[0].table[TableName],
86
+ ...foreignColumnNames
87
+ ];
88
+ return name ?? `${chunks.join("_")}_fk`;
89
+ }
90
+ };
91
+ function foreignKey(config) {
92
+ function mappedConfig() {
93
+ if (typeof config === "function") {
94
+ const { name, columns, foreignColumns } = config();
95
+ return {
96
+ name,
97
+ columns,
98
+ foreignColumns
99
+ };
100
+ }
101
+ return config;
102
+ }
103
+ return new ForeignKeyBuilder(mappedConfig);
104
+ }
105
+ //#endregion
106
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/unique-constraint.js
107
+ function uniqueKeyName(table, columns) {
108
+ return `${table[TableName]}_${columns.join("_")}_unique`;
109
+ }
110
+ function unique(name) {
111
+ return new UniqueOnConstraintBuilder(name);
112
+ }
113
+ var UniqueConstraintBuilder = class {
114
+ constructor(columns, name) {
115
+ this.name = name;
116
+ this.columns = columns;
117
+ }
118
+ static [entityKind] = "SQLiteUniqueConstraintBuilder";
119
+ /** @internal */
120
+ columns;
121
+ /** @internal */
122
+ build(table) {
123
+ return new UniqueConstraint(table, this.columns, this.name);
124
+ }
125
+ };
126
+ var UniqueOnConstraintBuilder = class {
127
+ static [entityKind] = "SQLiteUniqueOnConstraintBuilder";
128
+ /** @internal */
129
+ name;
130
+ constructor(name) {
131
+ this.name = name;
132
+ }
133
+ on(...columns) {
134
+ return new UniqueConstraintBuilder(columns, this.name);
135
+ }
136
+ };
137
+ var UniqueConstraint = class {
138
+ constructor(table, columns, name) {
139
+ this.table = table;
140
+ this.columns = columns;
141
+ this.name = name ?? uniqueKeyName(this.table, this.columns.map((column) => column.name));
142
+ }
143
+ static [entityKind] = "SQLiteUniqueConstraint";
144
+ columns;
145
+ name;
146
+ getName() {
147
+ return this.name;
148
+ }
149
+ };
150
+ //#endregion
151
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/columns/common.js
152
+ var SQLiteColumnBuilder = class extends ColumnBuilder {
153
+ static [entityKind] = "SQLiteColumnBuilder";
154
+ foreignKeyConfigs = [];
155
+ references(ref, actions = {}) {
156
+ this.foreignKeyConfigs.push({
157
+ ref,
158
+ actions
159
+ });
160
+ return this;
161
+ }
162
+ unique(name) {
163
+ this.config.isUnique = true;
164
+ this.config.uniqueName = name;
165
+ return this;
166
+ }
167
+ generatedAlwaysAs(as, config) {
168
+ this.config.generated = {
169
+ as,
170
+ type: "always",
171
+ mode: config?.mode ?? "virtual"
172
+ };
173
+ return this;
174
+ }
175
+ /** @internal */
176
+ buildForeignKeys(column, table) {
177
+ return this.foreignKeyConfigs.map(({ ref, actions }) => {
178
+ return ((ref2, actions2) => {
179
+ const builder = new ForeignKeyBuilder(() => {
180
+ const foreignColumn = ref2();
181
+ return {
182
+ columns: [column],
183
+ foreignColumns: [foreignColumn]
184
+ };
185
+ });
186
+ if (actions2.onUpdate) builder.onUpdate(actions2.onUpdate);
187
+ if (actions2.onDelete) builder.onDelete(actions2.onDelete);
188
+ return builder.build(table);
189
+ })(ref, actions);
190
+ });
191
+ }
192
+ };
193
+ var SQLiteColumn = class extends Column {
194
+ constructor(table, config) {
195
+ if (!config.uniqueName) config.uniqueName = uniqueKeyName(table, [config.name]);
196
+ super(table, config);
197
+ this.table = table;
198
+ }
199
+ static [entityKind] = "SQLiteColumn";
200
+ };
201
+ //#endregion
202
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/columns/blob.js
203
+ var SQLiteBigIntBuilder = class extends SQLiteColumnBuilder {
204
+ static [entityKind] = "SQLiteBigIntBuilder";
205
+ constructor(name) {
206
+ super(name, "bigint", "SQLiteBigInt");
207
+ }
208
+ /** @internal */
209
+ build(table) {
210
+ return new SQLiteBigInt(table, this.config);
211
+ }
212
+ };
213
+ var SQLiteBigInt = class extends SQLiteColumn {
214
+ static [entityKind] = "SQLiteBigInt";
215
+ getSQLType() {
216
+ return "blob";
217
+ }
218
+ mapFromDriverValue(value) {
219
+ if (typeof Buffer !== "undefined" && Buffer.from) {
220
+ const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
221
+ return BigInt(buf.toString("utf8"));
222
+ }
223
+ return BigInt(textDecoder.decode(value));
224
+ }
225
+ mapToDriverValue(value) {
226
+ return Buffer.from(value.toString());
227
+ }
228
+ };
229
+ var SQLiteBlobJsonBuilder = class extends SQLiteColumnBuilder {
230
+ static [entityKind] = "SQLiteBlobJsonBuilder";
231
+ constructor(name) {
232
+ super(name, "json", "SQLiteBlobJson");
233
+ }
234
+ /** @internal */
235
+ build(table) {
236
+ return new SQLiteBlobJson(table, this.config);
237
+ }
238
+ };
239
+ var SQLiteBlobJson = class extends SQLiteColumn {
240
+ static [entityKind] = "SQLiteBlobJson";
241
+ getSQLType() {
242
+ return "blob";
243
+ }
244
+ mapFromDriverValue(value) {
245
+ if (typeof Buffer !== "undefined" && Buffer.from) {
246
+ const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
247
+ return JSON.parse(buf.toString("utf8"));
248
+ }
249
+ return JSON.parse(textDecoder.decode(value));
250
+ }
251
+ mapToDriverValue(value) {
252
+ return Buffer.from(JSON.stringify(value));
253
+ }
254
+ };
255
+ var SQLiteBlobBufferBuilder = class extends SQLiteColumnBuilder {
256
+ static [entityKind] = "SQLiteBlobBufferBuilder";
257
+ constructor(name) {
258
+ super(name, "buffer", "SQLiteBlobBuffer");
259
+ }
260
+ /** @internal */
261
+ build(table) {
262
+ return new SQLiteBlobBuffer(table, this.config);
263
+ }
264
+ };
265
+ var SQLiteBlobBuffer = class extends SQLiteColumn {
266
+ static [entityKind] = "SQLiteBlobBuffer";
267
+ mapFromDriverValue(value) {
268
+ if (Buffer.isBuffer(value)) return value;
269
+ return Buffer.from(value);
270
+ }
271
+ getSQLType() {
272
+ return "blob";
273
+ }
274
+ };
275
+ function blob(a, b) {
276
+ const { name, config } = getColumnNameAndConfig(a, b);
277
+ if (config?.mode === "json") return new SQLiteBlobJsonBuilder(name);
278
+ if (config?.mode === "bigint") return new SQLiteBigIntBuilder(name);
279
+ return new SQLiteBlobBufferBuilder(name);
280
+ }
281
+ //#endregion
282
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/columns/custom.js
283
+ var SQLiteCustomColumnBuilder = class extends SQLiteColumnBuilder {
284
+ static [entityKind] = "SQLiteCustomColumnBuilder";
285
+ constructor(name, fieldConfig, customTypeParams) {
286
+ super(name, "custom", "SQLiteCustomColumn");
287
+ this.config.fieldConfig = fieldConfig;
288
+ this.config.customTypeParams = customTypeParams;
289
+ }
290
+ /** @internal */
291
+ build(table) {
292
+ return new SQLiteCustomColumn(table, this.config);
293
+ }
294
+ };
295
+ var SQLiteCustomColumn = class extends SQLiteColumn {
296
+ static [entityKind] = "SQLiteCustomColumn";
297
+ sqlName;
298
+ mapTo;
299
+ mapFrom;
300
+ constructor(table, config) {
301
+ super(table, config);
302
+ this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
303
+ this.mapTo = config.customTypeParams.toDriver;
304
+ this.mapFrom = config.customTypeParams.fromDriver;
305
+ }
306
+ getSQLType() {
307
+ return this.sqlName;
308
+ }
309
+ mapFromDriverValue(value) {
310
+ return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
311
+ }
312
+ mapToDriverValue(value) {
313
+ return typeof this.mapTo === "function" ? this.mapTo(value) : value;
314
+ }
315
+ };
316
+ function customType(customTypeParams) {
317
+ return (a, b) => {
318
+ const { name, config } = getColumnNameAndConfig(a, b);
319
+ return new SQLiteCustomColumnBuilder(name, config, customTypeParams);
320
+ };
321
+ }
322
+ //#endregion
323
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/columns/integer.js
324
+ var SQLiteBaseIntegerBuilder = class extends SQLiteColumnBuilder {
325
+ static [entityKind] = "SQLiteBaseIntegerBuilder";
326
+ constructor(name, dataType, columnType) {
327
+ super(name, dataType, columnType);
328
+ this.config.autoIncrement = false;
329
+ }
330
+ primaryKey(config) {
331
+ if (config?.autoIncrement) this.config.autoIncrement = true;
332
+ this.config.hasDefault = true;
333
+ return super.primaryKey();
334
+ }
335
+ };
336
+ var SQLiteBaseInteger = class extends SQLiteColumn {
337
+ static [entityKind] = "SQLiteBaseInteger";
338
+ autoIncrement = this.config.autoIncrement;
339
+ getSQLType() {
340
+ return "integer";
341
+ }
342
+ };
343
+ var SQLiteIntegerBuilder = class extends SQLiteBaseIntegerBuilder {
344
+ static [entityKind] = "SQLiteIntegerBuilder";
345
+ constructor(name) {
346
+ super(name, "number", "SQLiteInteger");
347
+ }
348
+ build(table) {
349
+ return new SQLiteInteger(table, this.config);
350
+ }
351
+ };
352
+ var SQLiteInteger = class extends SQLiteBaseInteger {
353
+ static [entityKind] = "SQLiteInteger";
354
+ };
355
+ var SQLiteTimestampBuilder = class extends SQLiteBaseIntegerBuilder {
356
+ static [entityKind] = "SQLiteTimestampBuilder";
357
+ constructor(name, mode) {
358
+ super(name, "date", "SQLiteTimestamp");
359
+ this.config.mode = mode;
360
+ }
361
+ /**
362
+ * @deprecated Use `default()` with your own expression instead.
363
+ *
364
+ * Adds `DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))` to the column, which is the current epoch timestamp in milliseconds.
365
+ */
366
+ defaultNow() {
367
+ return this.default(sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);
368
+ }
369
+ build(table) {
370
+ return new SQLiteTimestamp(table, this.config);
371
+ }
372
+ };
373
+ var SQLiteTimestamp = class extends SQLiteBaseInteger {
374
+ static [entityKind] = "SQLiteTimestamp";
375
+ mode = this.config.mode;
376
+ mapFromDriverValue(value) {
377
+ if (this.config.mode === "timestamp") return /* @__PURE__ */ new Date(value * 1e3);
378
+ return new Date(value);
379
+ }
380
+ mapToDriverValue(value) {
381
+ const unix = value.getTime();
382
+ if (this.config.mode === "timestamp") return Math.floor(unix / 1e3);
383
+ return unix;
384
+ }
385
+ };
386
+ var SQLiteBooleanBuilder = class extends SQLiteBaseIntegerBuilder {
387
+ static [entityKind] = "SQLiteBooleanBuilder";
388
+ constructor(name, mode) {
389
+ super(name, "boolean", "SQLiteBoolean");
390
+ this.config.mode = mode;
391
+ }
392
+ build(table) {
393
+ return new SQLiteBoolean(table, this.config);
394
+ }
395
+ };
396
+ var SQLiteBoolean = class extends SQLiteBaseInteger {
397
+ static [entityKind] = "SQLiteBoolean";
398
+ mode = this.config.mode;
399
+ mapFromDriverValue(value) {
400
+ return Number(value) === 1;
401
+ }
402
+ mapToDriverValue(value) {
403
+ return value ? 1 : 0;
404
+ }
405
+ };
406
+ function integer(a, b) {
407
+ const { name, config } = getColumnNameAndConfig(a, b);
408
+ if (config?.mode === "timestamp" || config?.mode === "timestamp_ms") return new SQLiteTimestampBuilder(name, config.mode);
409
+ if (config?.mode === "boolean") return new SQLiteBooleanBuilder(name, config.mode);
410
+ return new SQLiteIntegerBuilder(name);
411
+ }
412
+ //#endregion
413
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/columns/numeric.js
414
+ var SQLiteNumericBuilder = class extends SQLiteColumnBuilder {
415
+ static [entityKind] = "SQLiteNumericBuilder";
416
+ constructor(name) {
417
+ super(name, "string", "SQLiteNumeric");
418
+ }
419
+ /** @internal */
420
+ build(table) {
421
+ return new SQLiteNumeric(table, this.config);
422
+ }
423
+ };
424
+ var SQLiteNumeric = class extends SQLiteColumn {
425
+ static [entityKind] = "SQLiteNumeric";
426
+ mapFromDriverValue(value) {
427
+ if (typeof value === "string") return value;
428
+ return String(value);
429
+ }
430
+ getSQLType() {
431
+ return "numeric";
432
+ }
433
+ };
434
+ var SQLiteNumericNumberBuilder = class extends SQLiteColumnBuilder {
435
+ static [entityKind] = "SQLiteNumericNumberBuilder";
436
+ constructor(name) {
437
+ super(name, "number", "SQLiteNumericNumber");
438
+ }
439
+ /** @internal */
440
+ build(table) {
441
+ return new SQLiteNumericNumber(table, this.config);
442
+ }
443
+ };
444
+ var SQLiteNumericNumber = class extends SQLiteColumn {
445
+ static [entityKind] = "SQLiteNumericNumber";
446
+ mapFromDriverValue(value) {
447
+ if (typeof value === "number") return value;
448
+ return Number(value);
449
+ }
450
+ mapToDriverValue = String;
451
+ getSQLType() {
452
+ return "numeric";
453
+ }
454
+ };
455
+ var SQLiteNumericBigIntBuilder = class extends SQLiteColumnBuilder {
456
+ static [entityKind] = "SQLiteNumericBigIntBuilder";
457
+ constructor(name) {
458
+ super(name, "bigint", "SQLiteNumericBigInt");
459
+ }
460
+ /** @internal */
461
+ build(table) {
462
+ return new SQLiteNumericBigInt(table, this.config);
463
+ }
464
+ };
465
+ var SQLiteNumericBigInt = class extends SQLiteColumn {
466
+ static [entityKind] = "SQLiteNumericBigInt";
467
+ mapFromDriverValue = BigInt;
468
+ mapToDriverValue = String;
469
+ getSQLType() {
470
+ return "numeric";
471
+ }
472
+ };
473
+ function numeric(a, b) {
474
+ const { name, config } = getColumnNameAndConfig(a, b);
475
+ const mode = config?.mode;
476
+ return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
477
+ }
478
+ //#endregion
479
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/columns/real.js
480
+ var SQLiteRealBuilder = class extends SQLiteColumnBuilder {
481
+ static [entityKind] = "SQLiteRealBuilder";
482
+ constructor(name) {
483
+ super(name, "number", "SQLiteReal");
484
+ }
485
+ /** @internal */
486
+ build(table) {
487
+ return new SQLiteReal(table, this.config);
488
+ }
489
+ };
490
+ var SQLiteReal = class extends SQLiteColumn {
491
+ static [entityKind] = "SQLiteReal";
492
+ getSQLType() {
493
+ return "real";
494
+ }
495
+ };
496
+ function real(name) {
497
+ return new SQLiteRealBuilder(name ?? "");
498
+ }
499
+ //#endregion
500
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/columns/text.js
501
+ var SQLiteTextBuilder = class extends SQLiteColumnBuilder {
502
+ static [entityKind] = "SQLiteTextBuilder";
503
+ constructor(name, config) {
504
+ super(name, "string", "SQLiteText");
505
+ this.config.enumValues = config.enum;
506
+ this.config.length = config.length;
507
+ }
508
+ /** @internal */
509
+ build(table) {
510
+ return new SQLiteText(table, this.config);
511
+ }
512
+ };
513
+ var SQLiteText = class extends SQLiteColumn {
514
+ static [entityKind] = "SQLiteText";
515
+ enumValues = this.config.enumValues;
516
+ length = this.config.length;
517
+ constructor(table, config) {
518
+ super(table, config);
519
+ }
520
+ getSQLType() {
521
+ return `text${this.config.length ? `(${this.config.length})` : ""}`;
522
+ }
523
+ };
524
+ var SQLiteTextJsonBuilder = class extends SQLiteColumnBuilder {
525
+ static [entityKind] = "SQLiteTextJsonBuilder";
526
+ constructor(name) {
527
+ super(name, "json", "SQLiteTextJson");
528
+ }
529
+ /** @internal */
530
+ build(table) {
531
+ return new SQLiteTextJson(table, this.config);
532
+ }
533
+ };
534
+ var SQLiteTextJson = class extends SQLiteColumn {
535
+ static [entityKind] = "SQLiteTextJson";
536
+ getSQLType() {
537
+ return "text";
538
+ }
539
+ mapFromDriverValue(value) {
540
+ return JSON.parse(value);
541
+ }
542
+ mapToDriverValue(value) {
543
+ return JSON.stringify(value);
544
+ }
545
+ };
546
+ function text(a, b = {}) {
547
+ const { name, config } = getColumnNameAndConfig(a, b);
548
+ if (config.mode === "json") return new SQLiteTextJsonBuilder(name);
549
+ return new SQLiteTextBuilder(name, config);
550
+ }
551
+ //#endregion
552
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/columns/all.js
553
+ function getSQLiteColumnBuilders() {
554
+ return {
555
+ blob,
556
+ customType,
557
+ integer,
558
+ numeric,
559
+ real,
560
+ text
561
+ };
562
+ }
563
+ //#endregion
564
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/table.js
565
+ const InlineForeignKeys = Symbol.for("drizzle:SQLiteInlineForeignKeys");
566
+ var SQLiteTable = class extends Table {
567
+ static [entityKind] = "SQLiteTable";
568
+ /** @internal */
569
+ static Symbol = Object.assign({}, Table.Symbol, { InlineForeignKeys });
570
+ /** @internal */
571
+ [Table.Symbol.Columns];
572
+ /** @internal */
573
+ [InlineForeignKeys] = [];
574
+ /** @internal */
575
+ [Table.Symbol.ExtraConfigBuilder] = void 0;
576
+ };
577
+ function sqliteTableBase(name, columns, extraConfig, schema, baseName = name) {
578
+ const rawTable = new SQLiteTable(name, schema, baseName);
579
+ const parsedColumns = typeof columns === "function" ? columns(getSQLiteColumnBuilders()) : columns;
580
+ const builtColumns = Object.fromEntries(Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
581
+ const colBuilder = colBuilderBase;
582
+ colBuilder.setName(name2);
583
+ const column = colBuilder.build(rawTable);
584
+ rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
585
+ return [name2, column];
586
+ }));
587
+ const table = Object.assign(rawTable, builtColumns);
588
+ table[Table.Symbol.Columns] = builtColumns;
589
+ table[Table.Symbol.ExtraConfigColumns] = builtColumns;
590
+ if (extraConfig) table[SQLiteTable.Symbol.ExtraConfigBuilder] = extraConfig;
591
+ return table;
592
+ }
593
+ const sqliteTable = (name, columns, extraConfig) => {
594
+ return sqliteTableBase(name, columns, extraConfig);
595
+ };
596
+ //#endregion
597
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/indexes.js
598
+ var IndexBuilderOn = class {
599
+ constructor(name, unique) {
600
+ this.name = name;
601
+ this.unique = unique;
602
+ }
603
+ static [entityKind] = "SQLiteIndexBuilderOn";
604
+ on(...columns) {
605
+ return new IndexBuilder(this.name, columns, this.unique);
606
+ }
607
+ };
608
+ var IndexBuilder = class {
609
+ static [entityKind] = "SQLiteIndexBuilder";
610
+ /** @internal */
611
+ config;
612
+ constructor(name, columns, unique) {
613
+ this.config = {
614
+ name,
615
+ columns,
616
+ unique,
617
+ where: void 0
618
+ };
619
+ }
620
+ /**
621
+ * Condition for partial index.
622
+ */
623
+ where(condition) {
624
+ this.config.where = condition;
625
+ return this;
626
+ }
627
+ /** @internal */
628
+ build(table) {
629
+ return new Index(this.config, table);
630
+ }
631
+ };
632
+ var Index = class {
633
+ static [entityKind] = "SQLiteIndex";
634
+ config;
635
+ constructor(config, table) {
636
+ this.config = {
637
+ ...config,
638
+ table
639
+ };
640
+ }
641
+ };
642
+ function index(name) {
643
+ return new IndexBuilderOn(name, false);
644
+ }
645
+ function uniqueIndex(name) {
646
+ return new IndexBuilderOn(name, true);
647
+ }
648
+ //#endregion
649
+ //#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260920.1_@libsql+client@0.18.0_@types+pg@8.20.0_pg@8.16.3/node_modules/drizzle-orm/sqlite-core/primary-keys.js
650
+ function primaryKey(...config) {
651
+ if (config[0].columns) return new PrimaryKeyBuilder(config[0].columns, config[0].name);
652
+ return new PrimaryKeyBuilder(config);
653
+ }
654
+ var PrimaryKeyBuilder = class {
655
+ static [entityKind] = "SQLitePrimaryKeyBuilder";
656
+ /** @internal */
657
+ columns;
658
+ /** @internal */
659
+ name;
660
+ constructor(columns, name) {
661
+ this.columns = columns;
662
+ this.name = name;
663
+ }
664
+ /** @internal */
665
+ build(table) {
666
+ return new PrimaryKey(table, this.columns, this.name);
667
+ }
668
+ };
669
+ var PrimaryKey = class {
670
+ constructor(table, columns, name) {
671
+ this.table = table;
672
+ this.columns = columns;
673
+ this.name = name;
674
+ }
675
+ static [entityKind] = "SQLitePrimaryKey";
676
+ columns;
677
+ name;
678
+ getName() {
679
+ return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
680
+ }
681
+ };
682
+ //#endregion
683
+ //#region ../db/dist/schema-sqlite.js
684
+ /**
685
+ * The schema in schema.ts, for SQLite (through libsql). Same tables,
686
+ * columns, keys and row types (portable.ts checks); only the storage
687
+ * differs:
688
+ *
689
+ * - Ids and strings are `text`, with no default for ids: the application
690
+ * makes every id.
691
+ * - Bytes are `blob`.
692
+ * - Times are integer milliseconds since the epoch.
693
+ * - Patterns are checked with GLOB, which is case-sensitive and needs no
694
+ * extension, rather than a regular expression.
695
+ */
696
+ const bytes = (name) => blob(name, { mode: "buffer" });
697
+ /** A 64-bit integer read as a bigint, like Postgres's bigint in 'bigint' mode. */
698
+ const int64 = customType({
699
+ dataType: () => "integer",
700
+ fromDriver: (value) => BigInt(value)
701
+ });
702
+ const time = (name) => integer(name, { mode: "timestamp_ms" });
703
+ const now = sql`(CAST(unixepoch('subsec') * 1000 AS INTEGER))`;
704
+ const createdAt = () => time("created_at").notNull().default(now);
705
+ const flag = (name) => integer(name, { mode: "boolean" });
706
+ /** `^[a-z0-9][a-z0-9-]{0,max-1}$`, in GLOB. */
707
+ const isSlug = (column, max) => sql`length(${column}) BETWEEN 1 AND ${sql.raw(String(max))} AND ${column} GLOB '[a-z0-9]*' AND ${column} NOT GLOB '*[^a-z0-9-]*'`;
708
+ const projects = sqliteTable("projects", {
709
+ id: text().primaryKey(),
710
+ slug: text().notNull(),
711
+ name: text().notNull(),
712
+ createdAt: createdAt(),
713
+ archivedAt: time("archived_at")
714
+ }, (table) => [unique("projects_slug_key").on(table.slug), check("projects_slug_check", isSlug(table.slug, 63))]);
715
+ const environments = sqliteTable("environments", {
716
+ id: text().primaryKey(),
717
+ projectId: text("project_id").notNull(),
718
+ slug: text().notNull(),
719
+ name: text().notNull(),
720
+ createdAt: createdAt(),
721
+ archivedAt: time("archived_at")
722
+ }, (table) => [
723
+ unique("environments_project_id_slug_key").on(table.projectId, table.slug),
724
+ unique("environments_project_scoped").on(table.id, table.projectId),
725
+ check("environments_slug_check", isSlug(table.slug, 63)),
726
+ foreignKey({
727
+ name: "environments_project_id_fkey",
728
+ columns: [table.projectId],
729
+ foreignColumns: [projects.id]
730
+ }).onDelete("restrict")
731
+ ]);
732
+ const secrets = sqliteTable("secrets", {
733
+ id: text().primaryKey(),
734
+ projectId: text("project_id").notNull(),
735
+ environmentId: text("environment_id").notNull(),
736
+ key: text().notNull(),
737
+ createdAt: createdAt(),
738
+ updatedAt: time("updated_at").notNull().default(now),
739
+ currentVersionId: text("current_version_id").references(() => secretVersions.id, { onDelete: "no action" }),
740
+ currentVersion: integer("current_version").notNull().default(0),
741
+ archivedAt: time("archived_at")
742
+ }, (table) => [
743
+ unique("secrets_project_id_environment_id_key_key").on(table.projectId, table.environmentId, table.key),
744
+ check("secrets_key_check", sql`length(${table.key}) BETWEEN 1 AND 128 AND ${table.key} GLOB '[A-Za-z_]*' AND ${table.key} NOT GLOB '*[^A-Za-z0-9_]*'`),
745
+ foreignKey({
746
+ name: "secrets_project_id_fkey",
747
+ columns: [table.projectId],
748
+ foreignColumns: [projects.id]
749
+ }).onDelete("restrict"),
750
+ foreignKey({
751
+ name: "secrets_environment_id_fkey",
752
+ columns: [table.environmentId],
753
+ foreignColumns: [environments.id]
754
+ }).onDelete("restrict"),
755
+ foreignKey({
756
+ name: "secrets_environment_in_project",
757
+ columns: [table.environmentId, table.projectId],
758
+ foreignColumns: [environments.id, environments.projectId]
759
+ }),
760
+ index("secrets_lookup_idx").on(table.projectId, table.environmentId, table.key)
761
+ ]);
762
+ const secretVersions = sqliteTable("secret_versions", {
763
+ id: text().primaryKey(),
764
+ secretId: text("secret_id").notNull(),
765
+ version: integer().notNull(),
766
+ envelopeVersion: integer("envelope_version").notNull(),
767
+ ciphertext: bytes("ciphertext").notNull(),
768
+ iv: bytes("iv").notNull(),
769
+ authTag: bytes("auth_tag").notNull(),
770
+ wrappedDek: bytes("wrapped_dek").notNull(),
771
+ kekProvider: text("kek_provider").notNull(),
772
+ kekId: text("kek_id").notNull(),
773
+ kekVersion: text("kek_version").notNull(),
774
+ createdAt: createdAt(),
775
+ createdBy: text("created_by").notNull()
776
+ }, (table) => [
777
+ unique("secret_versions_secret_id_version_key").on(table.secretId, table.version),
778
+ check("secret_versions_version_check", sql`${table.version} > 0`),
779
+ check("secret_versions_iv_check", sql`octet_length(${table.iv}) = 12`),
780
+ check("secret_versions_auth_tag_check", sql`octet_length(${table.authTag}) = 16`),
781
+ foreignKey({
782
+ name: "secret_versions_secret_id_fkey",
783
+ columns: [table.secretId],
784
+ foreignColumns: [secrets.id]
785
+ }).onDelete("restrict"),
786
+ index("secret_versions_secret_idx").on(table.secretId, table.version)
787
+ ]);
788
+ const ROLES = sql.raw(ROLE_NAMES.map((role) => `'${role}'`).join(", "));
789
+ const ENVIRONMENT_ROLES = sql.raw(ROLE_NAMES.filter(assignableToEnvironment).map((role) => `'${role}'`).join(", "));
790
+ const vaultMembers = sqliteTable("vault_members", {
791
+ principal: text().primaryKey(),
792
+ status: text().notNull(),
793
+ owner: flag("owner").notNull().default(false),
794
+ generation: integer().notNull().default(0),
795
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
796
+ createdBy: text("created_by").notNull(),
797
+ statusChangedAt: integer("status_changed_at", { mode: "number" }).notNull(),
798
+ statusChangedBy: text("status_changed_by").notNull(),
799
+ accessSeq: int64("access_seq").notNull(),
800
+ mac: bytes("mac").notNull()
801
+ }, (table) => [
802
+ check("vault_members_mac_check", sql`octet_length(${table.mac}) = 32`),
803
+ check("vault_members_principal_check", sql`(${table.principal} GLOB 'user:?*' OR ${table.principal} GLOB 'token:?*' OR ${table.principal} GLOB 'sync:?*')
804
+ AND substr(${table.principal}, instr(${table.principal}, ':') + 1, 1) <> ':'
805
+ AND instr(${table.principal}, ' ') = 0 AND instr(${table.principal}, char(9)) = 0
806
+ AND instr(${table.principal}, char(10)) = 0 AND instr(${table.principal}, char(13)) = 0`),
807
+ check("vault_members_user_lowercase", sql`${table.principal} NOT LIKE 'user:%' OR ${table.principal} = lower(${table.principal})`),
808
+ check("vault_members_status_check", sql`${table.status} IN ('active', 'removed')`),
809
+ check("vault_members_owner_check", sql`NOT ${table.owner} OR (${table.status} = 'active' AND ${table.principal} LIKE 'user:%')`),
810
+ check("vault_members_generation_check", sql`${table.generation} >= 0`)
811
+ ]);
812
+ const vaultGrants = sqliteTable("vault_grants", {
813
+ principal: text().notNull(),
814
+ projectId: text("project_id"),
815
+ environmentId: text("environment_id"),
816
+ role: text().notNull(),
817
+ expiresAt: integer("expires_at", { mode: "number" }),
818
+ grantedAt: integer("granted_at", { mode: "number" }).notNull(),
819
+ grantedBy: text("granted_by").notNull()
820
+ }, (table) => [
821
+ check("vault_grants_one_place", sql`(${table.projectId} IS NULL) <> (${table.environmentId} IS NULL)`),
822
+ check("vault_grants_role_check", sql`${table.role} IN (${ROLES})`),
823
+ check("vault_grants_environment_role_check", sql`${table.environmentId} IS NULL OR ${table.role} IN (${ENVIRONMENT_ROLES})`),
824
+ unique("vault_grants_on_project").on(table.principal, table.projectId),
825
+ unique("vault_grants_on_environment").on(table.principal, table.environmentId),
826
+ foreignKey({
827
+ name: "vault_grants_principal_fkey",
828
+ columns: [table.principal],
829
+ foreignColumns: [vaultMembers.principal]
830
+ }).onDelete("restrict"),
831
+ foreignKey({
832
+ name: "vault_grants_project_id_fkey",
833
+ columns: [table.projectId],
834
+ foreignColumns: [projects.id]
835
+ }).onDelete("restrict"),
836
+ foreignKey({
837
+ name: "vault_grants_environment_id_fkey",
838
+ columns: [table.environmentId],
839
+ foreignColumns: [environments.id]
840
+ }).onDelete("restrict")
841
+ ]);
842
+ const auditLog = sqliteTable("audit_log", {
843
+ seq: int64("seq").primaryKey(),
844
+ author: text().notNull(),
845
+ keyId: text("key_id").notNull(),
846
+ occurredAt: integer("occurred_at", { mode: "number" }).notNull(),
847
+ actor: text().notNull(),
848
+ action: text().notNull(),
849
+ decision: text().notNull(),
850
+ code: text(),
851
+ subjectPrincipal: text("subject_principal"),
852
+ projectId: text("project_id"),
853
+ environmentId: text("environment_id"),
854
+ secretId: text("secret_id"),
855
+ secretVersionId: text("secret_version_id"),
856
+ operationId: text("operation_id"),
857
+ requestId: text("request_id"),
858
+ sourceIp: text("source_ip"),
859
+ relatedSeq: int64("related_seq"),
860
+ metadata: text().notNull().default("{}"),
861
+ prevHash: bytes("prev_hash").notNull(),
862
+ mac: bytes("mac").notNull(),
863
+ hash: bytes("hash").notNull()
864
+ }, (table) => [
865
+ check("audit_log_author_check", sql`${table.author} IN ('app', 'vault')`),
866
+ check("audit_log_actor_check", sql`${table.actor} GLOB 'user:?*' OR ${table.actor} GLOB 'token:?*' OR ${table.actor} GLOB 'sync:?*' OR ${table.actor} GLOB 'system:?*'`),
867
+ check("audit_log_decision_check", sql`${table.decision} IN ('allow', 'deny')`),
868
+ check("audit_log_metadata_check", sql`json_valid(${table.metadata})`),
869
+ check("audit_log_prev_hash_check", sql`octet_length(${table.prevHash}) = 32`),
870
+ check("audit_log_mac_check", sql`octet_length(${table.mac}) = 32`),
871
+ check("audit_log_hash_check", sql`octet_length(${table.hash}) = 32`),
872
+ foreignKey({
873
+ name: "audit_log_project_id_fkey",
874
+ columns: [table.projectId],
875
+ foreignColumns: [projects.id]
876
+ }).onDelete("restrict"),
877
+ foreignKey({
878
+ name: "audit_log_environment_id_fkey",
879
+ columns: [table.environmentId],
880
+ foreignColumns: [environments.id]
881
+ }).onDelete("restrict"),
882
+ foreignKey({
883
+ name: "audit_log_secret_id_fkey",
884
+ columns: [table.secretId],
885
+ foreignColumns: [secrets.id]
886
+ }).onDelete("restrict"),
887
+ foreignKey({
888
+ name: "audit_log_secret_version_id_fkey",
889
+ columns: [table.secretVersionId],
890
+ foreignColumns: [secretVersions.id]
891
+ }).onDelete("restrict"),
892
+ foreignKey({
893
+ name: "audit_log_related_seq_fkey",
894
+ columns: [table.relatedSeq],
895
+ foreignColumns: [table.seq]
896
+ }).onDelete("restrict"),
897
+ index("audit_log_project_idx").on(table.projectId, table.seq),
898
+ index("audit_log_environment_idx").on(table.environmentId, table.seq),
899
+ index("audit_log_secret_idx").on(table.secretId, table.seq),
900
+ index("audit_log_actor_idx").on(table.actor, table.seq),
901
+ index("audit_log_operation_idx").on(table.operationId, table.seq),
902
+ index("audit_log_action_idx").on(table.author, table.action, table.seq),
903
+ index("audit_log_releases_idx").on(table.author, table.actor, table.action, table.decision, table.occurredAt),
904
+ index("audit_log_subject_idx").on(table.author, table.subjectPrincipal, table.seq)
905
+ ]);
906
+ const auditChainHead = sqliteTable("audit_chain_head", {
907
+ onlyRow: flag("only_row").primaryKey().default(true),
908
+ nextSeq: int64("next_seq").notNull().default(sql`0`),
909
+ headHash: bytes("head_hash").notNull()
910
+ }, (table) => [
911
+ check("audit_chain_head_only_row_check", sql`${table.onlyRow}`),
912
+ check("audit_chain_head_next_seq_check", sql`${table.nextSeq} >= 0`),
913
+ check("audit_chain_head_head_hash_check", sql`octet_length(${table.headHash}) = 32`)
914
+ ]);
915
+ const identities = sqliteTable("identities", {
916
+ id: text().primaryKey(),
917
+ provider: text().notNull(),
918
+ authMac: bytes("auth_mac").notNull(),
919
+ subject: text().notNull(),
920
+ issuerHash: text("issuer_hash").notNull(),
921
+ generation: integer().notNull(),
922
+ principal: text().notNull(),
923
+ email: text(),
924
+ createdAt: createdAt(),
925
+ createdBy: text("created_by").notNull(),
926
+ lastSignInAt: time("last_sign_in_at"),
927
+ revokedAt: time("revoked_at"),
928
+ revokedBy: text("revoked_by"),
929
+ activeSubject: text("active_subject").generatedAlwaysAs(ACTIVE_SUBJECT, { mode: "stored" })
930
+ }, (table) => [
931
+ check("identities_principal_check", sql`${table.principal} LIKE 'user:%'`),
932
+ check("identities_provider_check", isSlug(table.provider, 32)),
933
+ check("identities_auth_mac_check", sql`octet_length(${table.authMac}) = 32`),
934
+ unique("identities_member_generation_key").on(table.id, table.principal, table.generation),
935
+ foreignKey({
936
+ name: "identities_principal_fkey",
937
+ columns: [table.principal],
938
+ foreignColumns: [vaultMembers.principal]
939
+ }).onDelete("restrict"),
940
+ uniqueIndex("identities_active_subject").on(table.provider, table.issuerHash, table.activeSubject),
941
+ index("identities_principal_idx").on(table.principal, table.generation)
942
+ ]);
943
+ const credentials = sqliteTable("credentials", {
944
+ id: text().primaryKey(),
945
+ kind: text().notNull(),
946
+ authMac: bytes("auth_mac").notNull(),
947
+ tokenHash: bytes("token_hash").notNull(),
948
+ tokenHint: text("token_hint").notNull(),
949
+ generation: integer().notNull(),
950
+ principal: text().notNull(),
951
+ identityId: text("identity_id"),
952
+ label: text(),
953
+ createdAt: createdAt(),
954
+ createdBy: text("created_by").notNull(),
955
+ expiresAt: time("expires_at").notNull(),
956
+ lastUsedAt: time("last_used_at"),
957
+ lastUsedIp: text("last_used_ip"),
958
+ revokedAt: time("revoked_at"),
959
+ revokedBy: text("revoked_by")
960
+ }, (table) => [
961
+ unique("credentials_token_hash_key").on(table.tokenHash),
962
+ check("credentials_kind_check", sql`${table.kind} IN ('browser', 'cli', 'service')`),
963
+ check("credentials_principal_check", sql`${table.principal} LIKE 'user:%' OR ${table.principal} LIKE 'token:%'`),
964
+ check("credentials_kind_matches_principal", sql`(${table.kind} = 'service') = (${table.principal} LIKE 'token:%')`),
965
+ check("credentials_token_hash_check", sql`octet_length(${table.tokenHash}) = 32`),
966
+ check("credentials_auth_mac_check", sql`octet_length(${table.authMac}) = 32`),
967
+ foreignKey({
968
+ name: "credentials_principal_fkey",
969
+ columns: [table.principal],
970
+ foreignColumns: [vaultMembers.principal]
971
+ }).onDelete("restrict"),
972
+ foreignKey({
973
+ name: "credentials_identity_id_fkey",
974
+ columns: [
975
+ table.identityId,
976
+ table.principal,
977
+ table.generation
978
+ ],
979
+ foreignColumns: [
980
+ identities.id,
981
+ identities.principal,
982
+ identities.generation
983
+ ]
984
+ }).onDelete("restrict"),
985
+ index("credentials_principal_idx").on(table.principal, table.generation)
986
+ ]);
987
+ const deviceAuthorizations = sqliteTable("device_authorizations", {
988
+ id: text().primaryKey(),
989
+ deviceCodeHash: bytes("device_code_hash").notNull(),
990
+ authMac: bytes("auth_mac").notNull(),
991
+ userCode: text("user_code").notNull(),
992
+ clientLabel: text("client_label"),
993
+ clientIp: text("client_ip"),
994
+ createdAt: createdAt(),
995
+ expiresAt: time("expires_at").notNull(),
996
+ decidedAt: time("decided_at"),
997
+ decision: text(),
998
+ generation: integer().notNull().default(0),
999
+ principal: text(),
1000
+ consumedAt: time("consumed_at")
1001
+ }, (table) => [
1002
+ unique("device_authorizations_device_code_hash_key").on(table.deviceCodeHash),
1003
+ unique("device_authorizations_user_code_key").on(table.userCode),
1004
+ check("device_authorizations_auth_mac_check", sql`octet_length(${table.authMac}) = 32`),
1005
+ check("device_authorizations_decision_check", sql`${table.decision} IS NULL OR ${table.decision} IN ('approved', 'denied')`),
1006
+ check("device_authorizations_approval_names_principal", sql`(${table.decision} IS NULL AND ${table.decidedAt} IS NULL AND ${table.principal} IS NULL AND ${table.generation} = 0 AND ${table.consumedAt} IS NULL)
1007
+ OR (${table.decision} IS NOT NULL AND ${table.decidedAt} IS NOT NULL AND (
1008
+ (${table.decision} = 'denied' AND ${table.principal} IS NULL AND ${table.generation} = 0 AND ${table.consumedAt} IS NULL)
1009
+ OR (${table.decision} = 'approved' AND ${table.principal} IS NOT NULL AND ${table.principal} LIKE 'user:%')
1010
+ ))`),
1011
+ foreignKey({
1012
+ name: "device_authorizations_principal_fkey",
1013
+ columns: [table.principal],
1014
+ foreignColumns: [vaultMembers.principal]
1015
+ }).onDelete("restrict")
1016
+ ]);
1017
+ const syncs = sqliteTable("syncs", {
1018
+ id: text().primaryKey(),
1019
+ projectId: text("project_id").notNull(),
1020
+ environmentId: text("environment_id").notNull(),
1021
+ provider: text().notNull(),
1022
+ config: text().notNull(),
1023
+ credentialSecretId: text("credential_secret_id").notNull(),
1024
+ createdAt: createdAt(),
1025
+ createdBy: text("created_by").notNull(),
1026
+ pausedAt: time("paused_at"),
1027
+ archivedAt: time("archived_at"),
1028
+ leaseUntil: time("lease_until"),
1029
+ lastRunAt: time("last_run_at"),
1030
+ lastStatus: text("last_status"),
1031
+ lastError: text("last_error")
1032
+ }, (table) => [
1033
+ check("syncs_config_check", sql`json_valid(${table.config})`),
1034
+ check("syncs_last_status_check", sql`${table.lastStatus} IS NULL OR ${table.lastStatus} IN ('ok', 'partial', 'failed')`),
1035
+ foreignKey({
1036
+ name: "syncs_environment_in_project",
1037
+ columns: [table.environmentId, table.projectId],
1038
+ foreignColumns: [environments.id, environments.projectId]
1039
+ }).onDelete("restrict"),
1040
+ foreignKey({
1041
+ name: "syncs_credential_secret_id_fkey",
1042
+ columns: [table.credentialSecretId],
1043
+ foreignColumns: [secrets.id]
1044
+ }).onDelete("restrict"),
1045
+ index("syncs_environment_idx").on(table.environmentId)
1046
+ ]);
1047
+ const syncKeys = sqliteTable("sync_keys", {
1048
+ syncId: text("sync_id").notNull(),
1049
+ key: text().notNull(),
1050
+ secretVersionId: text("secret_version_id"),
1051
+ pushedAt: time("pushed_at").notNull().default(now),
1052
+ removedAt: time("removed_at")
1053
+ }, (table) => [
1054
+ primaryKey({
1055
+ name: "sync_keys_pkey",
1056
+ columns: [table.syncId, table.key]
1057
+ }),
1058
+ foreignKey({
1059
+ name: "sync_keys_sync_id_fkey",
1060
+ columns: [table.syncId],
1061
+ foreignColumns: [syncs.id]
1062
+ }).onDelete("restrict"),
1063
+ foreignKey({
1064
+ name: "sync_keys_secret_version_id_fkey",
1065
+ columns: [table.secretVersionId],
1066
+ foreignColumns: [secretVersions.id]
1067
+ }).onDelete("restrict")
1068
+ ]);
1069
+ const { environmentsRelations, secretsRelations, syncsRelations, syncKeysRelations } = relationsOf(asPostgres({
1070
+ projects,
1071
+ environments,
1072
+ secrets,
1073
+ secretVersions,
1074
+ syncs,
1075
+ syncKeys
1076
+ }));
1077
+ //#endregion
1078
+ export { auditChainHead, auditLog, credentials, deviceAuthorizations, environments, environmentsRelations, identities, projects, secretVersions, secrets, secretsRelations, syncKeys, syncKeysRelations, syncs, syncsRelations, vaultGrants, vaultMembers };