@elizaos/plugin-todos 2.0.0-beta.1 → 2.0.3-beta.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.
- package/LICENSE +21 -0
- package/README.md +69 -0
- package/assets/hero.svg +67 -0
- package/package.json +47 -7
- package/dist/actions/todo.d.ts +0 -3
- package/dist/actions/todo.d.ts.map +0 -1
- package/dist/db/index.d.ts +0 -2
- package/dist/db/index.d.ts.map +0 -1
- package/dist/db/schema.d.ts +0 -249
- package/dist/db/schema.d.ts.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -4991
- package/dist/index.js.map +0 -88
- package/dist/providers/current-todos.d.ts +0 -11
- package/dist/providers/current-todos.d.ts.map +0 -1
- package/dist/service.d.ts +0 -70
- package/dist/service.d.ts.map +0 -1
- package/dist/types.d.ts +0 -33
- package/dist/types.d.ts.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,4991 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __returnValue = (v) => v;
|
|
3
|
-
function __exportSetter(name, newValue) {
|
|
4
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
5
|
-
}
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
set: __exportSetter.bind(all, name)
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// src/service.ts
|
|
17
|
-
import { logger, Service } from "@elizaos/core";
|
|
18
|
-
|
|
19
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/entity.js
|
|
20
|
-
var entityKind = Symbol.for("drizzle:entityKind");
|
|
21
|
-
var hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
|
|
22
|
-
function is(value, type) {
|
|
23
|
-
if (!value || typeof value !== "object") {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
if (value instanceof type) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
|
|
30
|
-
throw new Error(`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.`);
|
|
31
|
-
}
|
|
32
|
-
let cls = Object.getPrototypeOf(value).constructor;
|
|
33
|
-
if (cls) {
|
|
34
|
-
while (cls) {
|
|
35
|
-
if (entityKind in cls && cls[entityKind] === type[entityKind]) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
cls = Object.getPrototypeOf(cls);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/column.js
|
|
45
|
-
class Column {
|
|
46
|
-
constructor(table, config) {
|
|
47
|
-
this.table = table;
|
|
48
|
-
this.config = config;
|
|
49
|
-
this.name = config.name;
|
|
50
|
-
this.keyAsName = config.keyAsName;
|
|
51
|
-
this.notNull = config.notNull;
|
|
52
|
-
this.default = config.default;
|
|
53
|
-
this.defaultFn = config.defaultFn;
|
|
54
|
-
this.onUpdateFn = config.onUpdateFn;
|
|
55
|
-
this.hasDefault = config.hasDefault;
|
|
56
|
-
this.primary = config.primaryKey;
|
|
57
|
-
this.isUnique = config.isUnique;
|
|
58
|
-
this.uniqueName = config.uniqueName;
|
|
59
|
-
this.uniqueType = config.uniqueType;
|
|
60
|
-
this.dataType = config.dataType;
|
|
61
|
-
this.columnType = config.columnType;
|
|
62
|
-
this.generated = config.generated;
|
|
63
|
-
this.generatedIdentity = config.generatedIdentity;
|
|
64
|
-
}
|
|
65
|
-
static [entityKind] = "Column";
|
|
66
|
-
name;
|
|
67
|
-
keyAsName;
|
|
68
|
-
primary;
|
|
69
|
-
notNull;
|
|
70
|
-
default;
|
|
71
|
-
defaultFn;
|
|
72
|
-
onUpdateFn;
|
|
73
|
-
hasDefault;
|
|
74
|
-
isUnique;
|
|
75
|
-
uniqueName;
|
|
76
|
-
uniqueType;
|
|
77
|
-
dataType;
|
|
78
|
-
columnType;
|
|
79
|
-
enumValues = undefined;
|
|
80
|
-
generated = undefined;
|
|
81
|
-
generatedIdentity = undefined;
|
|
82
|
-
config;
|
|
83
|
-
mapFromDriverValue(value) {
|
|
84
|
-
return value;
|
|
85
|
-
}
|
|
86
|
-
mapToDriverValue(value) {
|
|
87
|
-
return value;
|
|
88
|
-
}
|
|
89
|
-
shouldDisableInsert() {
|
|
90
|
-
return this.config.generated !== undefined && this.config.generated.type !== "byDefault";
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/column-builder.js
|
|
95
|
-
class ColumnBuilder {
|
|
96
|
-
static [entityKind] = "ColumnBuilder";
|
|
97
|
-
config;
|
|
98
|
-
constructor(name, dataType, columnType) {
|
|
99
|
-
this.config = {
|
|
100
|
-
name,
|
|
101
|
-
keyAsName: name === "",
|
|
102
|
-
notNull: false,
|
|
103
|
-
default: undefined,
|
|
104
|
-
hasDefault: false,
|
|
105
|
-
primaryKey: false,
|
|
106
|
-
isUnique: false,
|
|
107
|
-
uniqueName: undefined,
|
|
108
|
-
uniqueType: undefined,
|
|
109
|
-
dataType,
|
|
110
|
-
columnType,
|
|
111
|
-
generated: undefined
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
$type() {
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
notNull() {
|
|
118
|
-
this.config.notNull = true;
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
default(value) {
|
|
122
|
-
this.config.default = value;
|
|
123
|
-
this.config.hasDefault = true;
|
|
124
|
-
return this;
|
|
125
|
-
}
|
|
126
|
-
$defaultFn(fn) {
|
|
127
|
-
this.config.defaultFn = fn;
|
|
128
|
-
this.config.hasDefault = true;
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
$default = this.$defaultFn;
|
|
132
|
-
$onUpdateFn(fn) {
|
|
133
|
-
this.config.onUpdateFn = fn;
|
|
134
|
-
this.config.hasDefault = true;
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
$onUpdate = this.$onUpdateFn;
|
|
138
|
-
primaryKey() {
|
|
139
|
-
this.config.primaryKey = true;
|
|
140
|
-
this.config.notNull = true;
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
setName(name) {
|
|
144
|
-
if (this.config.name !== "")
|
|
145
|
-
return;
|
|
146
|
-
this.config.name = name;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/table.utils.js
|
|
151
|
-
var TableName = Symbol.for("drizzle:Name");
|
|
152
|
-
|
|
153
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/foreign-keys.js
|
|
154
|
-
class ForeignKeyBuilder {
|
|
155
|
-
static [entityKind] = "PgForeignKeyBuilder";
|
|
156
|
-
reference;
|
|
157
|
-
_onUpdate = "no action";
|
|
158
|
-
_onDelete = "no action";
|
|
159
|
-
constructor(config, actions) {
|
|
160
|
-
this.reference = () => {
|
|
161
|
-
const { name, columns, foreignColumns } = config();
|
|
162
|
-
return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
|
|
163
|
-
};
|
|
164
|
-
if (actions) {
|
|
165
|
-
this._onUpdate = actions.onUpdate;
|
|
166
|
-
this._onDelete = actions.onDelete;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
onUpdate(action) {
|
|
170
|
-
this._onUpdate = action === undefined ? "no action" : action;
|
|
171
|
-
return this;
|
|
172
|
-
}
|
|
173
|
-
onDelete(action) {
|
|
174
|
-
this._onDelete = action === undefined ? "no action" : action;
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
build(table) {
|
|
178
|
-
return new ForeignKey(table, this);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
class ForeignKey {
|
|
183
|
-
constructor(table, builder) {
|
|
184
|
-
this.table = table;
|
|
185
|
-
this.reference = builder.reference;
|
|
186
|
-
this.onUpdate = builder._onUpdate;
|
|
187
|
-
this.onDelete = builder._onDelete;
|
|
188
|
-
}
|
|
189
|
-
static [entityKind] = "PgForeignKey";
|
|
190
|
-
reference;
|
|
191
|
-
onUpdate;
|
|
192
|
-
onDelete;
|
|
193
|
-
getName() {
|
|
194
|
-
const { name, columns, foreignColumns } = this.reference();
|
|
195
|
-
const columnNames = columns.map((column) => column.name);
|
|
196
|
-
const foreignColumnNames = foreignColumns.map((column) => column.name);
|
|
197
|
-
const chunks = [
|
|
198
|
-
this.table[TableName],
|
|
199
|
-
...columnNames,
|
|
200
|
-
foreignColumns[0].table[TableName],
|
|
201
|
-
...foreignColumnNames
|
|
202
|
-
];
|
|
203
|
-
return name ?? `${chunks.join("_")}_fk`;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/tracing-utils.js
|
|
208
|
-
function iife(fn, ...args) {
|
|
209
|
-
return fn(...args);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/unique-constraint.js
|
|
213
|
-
function uniqueKeyName(table, columns) {
|
|
214
|
-
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/utils/array.js
|
|
218
|
-
function parsePgArrayValue(arrayString, startFrom, inQuotes) {
|
|
219
|
-
for (let i = startFrom;i < arrayString.length; i++) {
|
|
220
|
-
const char = arrayString[i];
|
|
221
|
-
if (char === "\\") {
|
|
222
|
-
i++;
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
if (char === '"') {
|
|
226
|
-
return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i + 1];
|
|
227
|
-
}
|
|
228
|
-
if (inQuotes) {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
if (char === "," || char === "}") {
|
|
232
|
-
return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i];
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return [arrayString.slice(startFrom).replace(/\\/g, ""), arrayString.length];
|
|
236
|
-
}
|
|
237
|
-
function parsePgNestedArray(arrayString, startFrom = 0) {
|
|
238
|
-
const result = [];
|
|
239
|
-
let i = startFrom;
|
|
240
|
-
let lastCharIsComma = false;
|
|
241
|
-
while (i < arrayString.length) {
|
|
242
|
-
const char = arrayString[i];
|
|
243
|
-
if (char === ",") {
|
|
244
|
-
if (lastCharIsComma || i === startFrom) {
|
|
245
|
-
result.push("");
|
|
246
|
-
}
|
|
247
|
-
lastCharIsComma = true;
|
|
248
|
-
i++;
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
lastCharIsComma = false;
|
|
252
|
-
if (char === "\\") {
|
|
253
|
-
i += 2;
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
if (char === '"') {
|
|
257
|
-
const [value2, startFrom2] = parsePgArrayValue(arrayString, i + 1, true);
|
|
258
|
-
result.push(value2);
|
|
259
|
-
i = startFrom2;
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
if (char === "}") {
|
|
263
|
-
return [result, i + 1];
|
|
264
|
-
}
|
|
265
|
-
if (char === "{") {
|
|
266
|
-
const [value2, startFrom2] = parsePgNestedArray(arrayString, i + 1);
|
|
267
|
-
result.push(value2);
|
|
268
|
-
i = startFrom2;
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
const [value, newStartFrom] = parsePgArrayValue(arrayString, i, false);
|
|
272
|
-
result.push(value);
|
|
273
|
-
i = newStartFrom;
|
|
274
|
-
}
|
|
275
|
-
return [result, i];
|
|
276
|
-
}
|
|
277
|
-
function parsePgArray(arrayString) {
|
|
278
|
-
const [result] = parsePgNestedArray(arrayString, 1);
|
|
279
|
-
return result;
|
|
280
|
-
}
|
|
281
|
-
function makePgArray(array) {
|
|
282
|
-
return `{${array.map((item) => {
|
|
283
|
-
if (Array.isArray(item)) {
|
|
284
|
-
return makePgArray(item);
|
|
285
|
-
}
|
|
286
|
-
if (typeof item === "string") {
|
|
287
|
-
return `"${item.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
288
|
-
}
|
|
289
|
-
return `${item}`;
|
|
290
|
-
}).join(",")}}`;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/common.js
|
|
294
|
-
class PgColumnBuilder extends ColumnBuilder {
|
|
295
|
-
foreignKeyConfigs = [];
|
|
296
|
-
static [entityKind] = "PgColumnBuilder";
|
|
297
|
-
array(size) {
|
|
298
|
-
return new PgArrayBuilder(this.config.name, this, size);
|
|
299
|
-
}
|
|
300
|
-
references(ref, actions = {}) {
|
|
301
|
-
this.foreignKeyConfigs.push({ ref, actions });
|
|
302
|
-
return this;
|
|
303
|
-
}
|
|
304
|
-
unique(name, config) {
|
|
305
|
-
this.config.isUnique = true;
|
|
306
|
-
this.config.uniqueName = name;
|
|
307
|
-
this.config.uniqueType = config?.nulls;
|
|
308
|
-
return this;
|
|
309
|
-
}
|
|
310
|
-
generatedAlwaysAs(as) {
|
|
311
|
-
this.config.generated = {
|
|
312
|
-
as,
|
|
313
|
-
type: "always",
|
|
314
|
-
mode: "stored"
|
|
315
|
-
};
|
|
316
|
-
return this;
|
|
317
|
-
}
|
|
318
|
-
buildForeignKeys(column, table) {
|
|
319
|
-
return this.foreignKeyConfigs.map(({ ref, actions }) => {
|
|
320
|
-
return iife((ref2, actions2) => {
|
|
321
|
-
const builder = new ForeignKeyBuilder(() => {
|
|
322
|
-
const foreignColumn = ref2();
|
|
323
|
-
return { columns: [column], foreignColumns: [foreignColumn] };
|
|
324
|
-
});
|
|
325
|
-
if (actions2.onUpdate) {
|
|
326
|
-
builder.onUpdate(actions2.onUpdate);
|
|
327
|
-
}
|
|
328
|
-
if (actions2.onDelete) {
|
|
329
|
-
builder.onDelete(actions2.onDelete);
|
|
330
|
-
}
|
|
331
|
-
return builder.build(table);
|
|
332
|
-
}, ref, actions);
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
buildExtraConfigColumn(table) {
|
|
336
|
-
return new ExtraConfigColumn(table, this.config);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
class PgColumn extends Column {
|
|
341
|
-
constructor(table, config) {
|
|
342
|
-
if (!config.uniqueName) {
|
|
343
|
-
config.uniqueName = uniqueKeyName(table, [config.name]);
|
|
344
|
-
}
|
|
345
|
-
super(table, config);
|
|
346
|
-
this.table = table;
|
|
347
|
-
}
|
|
348
|
-
static [entityKind] = "PgColumn";
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
class ExtraConfigColumn extends PgColumn {
|
|
352
|
-
static [entityKind] = "ExtraConfigColumn";
|
|
353
|
-
getSQLType() {
|
|
354
|
-
return this.getSQLType();
|
|
355
|
-
}
|
|
356
|
-
indexConfig = {
|
|
357
|
-
order: this.config.order ?? "asc",
|
|
358
|
-
nulls: this.config.nulls ?? "last",
|
|
359
|
-
opClass: this.config.opClass
|
|
360
|
-
};
|
|
361
|
-
defaultConfig = {
|
|
362
|
-
order: "asc",
|
|
363
|
-
nulls: "last",
|
|
364
|
-
opClass: undefined
|
|
365
|
-
};
|
|
366
|
-
asc() {
|
|
367
|
-
this.indexConfig.order = "asc";
|
|
368
|
-
return this;
|
|
369
|
-
}
|
|
370
|
-
desc() {
|
|
371
|
-
this.indexConfig.order = "desc";
|
|
372
|
-
return this;
|
|
373
|
-
}
|
|
374
|
-
nullsFirst() {
|
|
375
|
-
this.indexConfig.nulls = "first";
|
|
376
|
-
return this;
|
|
377
|
-
}
|
|
378
|
-
nullsLast() {
|
|
379
|
-
this.indexConfig.nulls = "last";
|
|
380
|
-
return this;
|
|
381
|
-
}
|
|
382
|
-
op(opClass) {
|
|
383
|
-
this.indexConfig.opClass = opClass;
|
|
384
|
-
return this;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
class IndexedColumn {
|
|
389
|
-
static [entityKind] = "IndexedColumn";
|
|
390
|
-
constructor(name, keyAsName, type, indexConfig) {
|
|
391
|
-
this.name = name;
|
|
392
|
-
this.keyAsName = keyAsName;
|
|
393
|
-
this.type = type;
|
|
394
|
-
this.indexConfig = indexConfig;
|
|
395
|
-
}
|
|
396
|
-
name;
|
|
397
|
-
keyAsName;
|
|
398
|
-
type;
|
|
399
|
-
indexConfig;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
class PgArrayBuilder extends PgColumnBuilder {
|
|
403
|
-
static [entityKind] = "PgArrayBuilder";
|
|
404
|
-
constructor(name, baseBuilder, size) {
|
|
405
|
-
super(name, "array", "PgArray");
|
|
406
|
-
this.config.baseBuilder = baseBuilder;
|
|
407
|
-
this.config.size = size;
|
|
408
|
-
}
|
|
409
|
-
build(table) {
|
|
410
|
-
const baseColumn = this.config.baseBuilder.build(table);
|
|
411
|
-
return new PgArray(table, this.config, baseColumn);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
class PgArray extends PgColumn {
|
|
416
|
-
constructor(table, config, baseColumn, range) {
|
|
417
|
-
super(table, config);
|
|
418
|
-
this.baseColumn = baseColumn;
|
|
419
|
-
this.range = range;
|
|
420
|
-
this.size = config.size;
|
|
421
|
-
}
|
|
422
|
-
size;
|
|
423
|
-
static [entityKind] = "PgArray";
|
|
424
|
-
getSQLType() {
|
|
425
|
-
return `${this.baseColumn.getSQLType()}[${typeof this.size === "number" ? this.size : ""}]`;
|
|
426
|
-
}
|
|
427
|
-
mapFromDriverValue(value) {
|
|
428
|
-
if (typeof value === "string") {
|
|
429
|
-
value = parsePgArray(value);
|
|
430
|
-
}
|
|
431
|
-
return value.map((v) => this.baseColumn.mapFromDriverValue(v));
|
|
432
|
-
}
|
|
433
|
-
mapToDriverValue(value, isNestedArray = false) {
|
|
434
|
-
const a = value.map((v) => v === null ? null : is(this.baseColumn, PgArray) ? this.baseColumn.mapToDriverValue(v, true) : this.baseColumn.mapToDriverValue(v));
|
|
435
|
-
if (isNestedArray)
|
|
436
|
-
return a;
|
|
437
|
-
return makePgArray(a);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/enum.js
|
|
442
|
-
class PgEnumObjectColumnBuilder extends PgColumnBuilder {
|
|
443
|
-
static [entityKind] = "PgEnumObjectColumnBuilder";
|
|
444
|
-
constructor(name, enumInstance) {
|
|
445
|
-
super(name, "string", "PgEnumObjectColumn");
|
|
446
|
-
this.config.enum = enumInstance;
|
|
447
|
-
}
|
|
448
|
-
build(table) {
|
|
449
|
-
return new PgEnumObjectColumn(table, this.config);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
class PgEnumObjectColumn extends PgColumn {
|
|
454
|
-
static [entityKind] = "PgEnumObjectColumn";
|
|
455
|
-
enum;
|
|
456
|
-
enumValues = this.config.enum.enumValues;
|
|
457
|
-
constructor(table, config) {
|
|
458
|
-
super(table, config);
|
|
459
|
-
this.enum = config.enum;
|
|
460
|
-
}
|
|
461
|
-
getSQLType() {
|
|
462
|
-
return this.enum.enumName;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
var isPgEnumSym = Symbol.for("drizzle:isPgEnum");
|
|
466
|
-
function isPgEnum(obj) {
|
|
467
|
-
return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
class PgEnumColumnBuilder extends PgColumnBuilder {
|
|
471
|
-
static [entityKind] = "PgEnumColumnBuilder";
|
|
472
|
-
constructor(name, enumInstance) {
|
|
473
|
-
super(name, "string", "PgEnumColumn");
|
|
474
|
-
this.config.enum = enumInstance;
|
|
475
|
-
}
|
|
476
|
-
build(table) {
|
|
477
|
-
return new PgEnumColumn(table, this.config);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
class PgEnumColumn extends PgColumn {
|
|
482
|
-
static [entityKind] = "PgEnumColumn";
|
|
483
|
-
enum = this.config.enum;
|
|
484
|
-
enumValues = this.config.enum.enumValues;
|
|
485
|
-
constructor(table, config) {
|
|
486
|
-
super(table, config);
|
|
487
|
-
this.enum = config.enum;
|
|
488
|
-
}
|
|
489
|
-
getSQLType() {
|
|
490
|
-
return this.enum.enumName;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
function pgEnumWithSchema(enumName, values, schema) {
|
|
494
|
-
const enumInstance = Object.assign((name) => new PgEnumColumnBuilder(name ?? "", enumInstance), {
|
|
495
|
-
enumName,
|
|
496
|
-
enumValues: values,
|
|
497
|
-
schema,
|
|
498
|
-
[isPgEnumSym]: true
|
|
499
|
-
});
|
|
500
|
-
return enumInstance;
|
|
501
|
-
}
|
|
502
|
-
function pgEnumObjectWithSchema(enumName, values, schema) {
|
|
503
|
-
const enumInstance = Object.assign((name) => new PgEnumObjectColumnBuilder(name ?? "", enumInstance), {
|
|
504
|
-
enumName,
|
|
505
|
-
enumValues: Object.values(values),
|
|
506
|
-
schema,
|
|
507
|
-
[isPgEnumSym]: true
|
|
508
|
-
});
|
|
509
|
-
return enumInstance;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/subquery.js
|
|
513
|
-
class Subquery {
|
|
514
|
-
static [entityKind] = "Subquery";
|
|
515
|
-
constructor(sql, fields, alias, isWith = false, usedTables = []) {
|
|
516
|
-
this._ = {
|
|
517
|
-
brand: "Subquery",
|
|
518
|
-
sql,
|
|
519
|
-
selectedFields: fields,
|
|
520
|
-
alias,
|
|
521
|
-
isWith,
|
|
522
|
-
usedTables
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
class WithSubquery extends Subquery {
|
|
528
|
-
static [entityKind] = "WithSubquery";
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/version.js
|
|
532
|
-
var version = "0.45.2";
|
|
533
|
-
|
|
534
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/tracing.js
|
|
535
|
-
var otel;
|
|
536
|
-
var rawTracer;
|
|
537
|
-
var tracer = {
|
|
538
|
-
startActiveSpan(name, fn) {
|
|
539
|
-
if (!otel) {
|
|
540
|
-
return fn();
|
|
541
|
-
}
|
|
542
|
-
if (!rawTracer) {
|
|
543
|
-
rawTracer = otel.trace.getTracer("drizzle-orm", version);
|
|
544
|
-
}
|
|
545
|
-
return iife((otel2, rawTracer2) => rawTracer2.startActiveSpan(name, (span) => {
|
|
546
|
-
try {
|
|
547
|
-
return fn(span);
|
|
548
|
-
} catch (e) {
|
|
549
|
-
span.setStatus({
|
|
550
|
-
code: otel2.SpanStatusCode.ERROR,
|
|
551
|
-
message: e instanceof Error ? e.message : "Unknown error"
|
|
552
|
-
});
|
|
553
|
-
throw e;
|
|
554
|
-
} finally {
|
|
555
|
-
span.end();
|
|
556
|
-
}
|
|
557
|
-
}), otel, rawTracer);
|
|
558
|
-
}
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/view-common.js
|
|
562
|
-
var ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
|
|
563
|
-
|
|
564
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/table.js
|
|
565
|
-
var Schema = Symbol.for("drizzle:Schema");
|
|
566
|
-
var Columns = Symbol.for("drizzle:Columns");
|
|
567
|
-
var ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
|
|
568
|
-
var OriginalName = Symbol.for("drizzle:OriginalName");
|
|
569
|
-
var BaseName = Symbol.for("drizzle:BaseName");
|
|
570
|
-
var IsAlias = Symbol.for("drizzle:IsAlias");
|
|
571
|
-
var ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
|
|
572
|
-
var IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
|
|
573
|
-
|
|
574
|
-
class Table {
|
|
575
|
-
static [entityKind] = "Table";
|
|
576
|
-
static Symbol = {
|
|
577
|
-
Name: TableName,
|
|
578
|
-
Schema,
|
|
579
|
-
OriginalName,
|
|
580
|
-
Columns,
|
|
581
|
-
ExtraConfigColumns,
|
|
582
|
-
BaseName,
|
|
583
|
-
IsAlias,
|
|
584
|
-
ExtraConfigBuilder
|
|
585
|
-
};
|
|
586
|
-
[TableName];
|
|
587
|
-
[OriginalName];
|
|
588
|
-
[Schema];
|
|
589
|
-
[Columns];
|
|
590
|
-
[ExtraConfigColumns];
|
|
591
|
-
[BaseName];
|
|
592
|
-
[IsAlias] = false;
|
|
593
|
-
[IsDrizzleTable] = true;
|
|
594
|
-
[ExtraConfigBuilder] = undefined;
|
|
595
|
-
constructor(name, schema, baseName) {
|
|
596
|
-
this[TableName] = this[OriginalName] = name;
|
|
597
|
-
this[Schema] = schema;
|
|
598
|
-
this[BaseName] = baseName;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
function getTableName(table) {
|
|
602
|
-
return table[TableName];
|
|
603
|
-
}
|
|
604
|
-
function getTableUniqueName(table) {
|
|
605
|
-
return `${table[Schema] ?? "public"}.${table[TableName]}`;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/sql/sql.js
|
|
609
|
-
function isSQLWrapper(value) {
|
|
610
|
-
return value !== null && value !== undefined && typeof value.getSQL === "function";
|
|
611
|
-
}
|
|
612
|
-
function mergeQueries(queries) {
|
|
613
|
-
const result = { sql: "", params: [] };
|
|
614
|
-
for (const query of queries) {
|
|
615
|
-
result.sql += query.sql;
|
|
616
|
-
result.params.push(...query.params);
|
|
617
|
-
if (query.typings?.length) {
|
|
618
|
-
if (!result.typings) {
|
|
619
|
-
result.typings = [];
|
|
620
|
-
}
|
|
621
|
-
result.typings.push(...query.typings);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
return result;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
class StringChunk {
|
|
628
|
-
static [entityKind] = "StringChunk";
|
|
629
|
-
value;
|
|
630
|
-
constructor(value) {
|
|
631
|
-
this.value = Array.isArray(value) ? value : [value];
|
|
632
|
-
}
|
|
633
|
-
getSQL() {
|
|
634
|
-
return new SQL([this]);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
class SQL {
|
|
639
|
-
constructor(queryChunks) {
|
|
640
|
-
this.queryChunks = queryChunks;
|
|
641
|
-
for (const chunk of queryChunks) {
|
|
642
|
-
if (is(chunk, Table)) {
|
|
643
|
-
const schemaName = chunk[Table.Symbol.Schema];
|
|
644
|
-
this.usedTables.push(schemaName === undefined ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
static [entityKind] = "SQL";
|
|
649
|
-
decoder = noopDecoder;
|
|
650
|
-
shouldInlineParams = false;
|
|
651
|
-
usedTables = [];
|
|
652
|
-
append(query) {
|
|
653
|
-
this.queryChunks.push(...query.queryChunks);
|
|
654
|
-
return this;
|
|
655
|
-
}
|
|
656
|
-
toQuery(config) {
|
|
657
|
-
return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
|
|
658
|
-
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
659
|
-
span?.setAttributes({
|
|
660
|
-
"drizzle.query.text": query.sql,
|
|
661
|
-
"drizzle.query.params": JSON.stringify(query.params)
|
|
662
|
-
});
|
|
663
|
-
return query;
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
buildQueryFromSourceParams(chunks, _config) {
|
|
667
|
-
const config = Object.assign({}, _config, {
|
|
668
|
-
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
669
|
-
paramStartIndex: _config.paramStartIndex || { value: 0 }
|
|
670
|
-
});
|
|
671
|
-
const {
|
|
672
|
-
casing,
|
|
673
|
-
escapeName,
|
|
674
|
-
escapeParam,
|
|
675
|
-
prepareTyping,
|
|
676
|
-
inlineParams,
|
|
677
|
-
paramStartIndex
|
|
678
|
-
} = config;
|
|
679
|
-
return mergeQueries(chunks.map((chunk) => {
|
|
680
|
-
if (is(chunk, StringChunk)) {
|
|
681
|
-
return { sql: chunk.value.join(""), params: [] };
|
|
682
|
-
}
|
|
683
|
-
if (is(chunk, Name)) {
|
|
684
|
-
return { sql: escapeName(chunk.value), params: [] };
|
|
685
|
-
}
|
|
686
|
-
if (chunk === undefined) {
|
|
687
|
-
return { sql: "", params: [] };
|
|
688
|
-
}
|
|
689
|
-
if (Array.isArray(chunk)) {
|
|
690
|
-
const result = [new StringChunk("(")];
|
|
691
|
-
for (const [i, p] of chunk.entries()) {
|
|
692
|
-
result.push(p);
|
|
693
|
-
if (i < chunk.length - 1) {
|
|
694
|
-
result.push(new StringChunk(", "));
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
result.push(new StringChunk(")"));
|
|
698
|
-
return this.buildQueryFromSourceParams(result, config);
|
|
699
|
-
}
|
|
700
|
-
if (is(chunk, SQL)) {
|
|
701
|
-
return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
702
|
-
...config,
|
|
703
|
-
inlineParams: inlineParams || chunk.shouldInlineParams
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
if (is(chunk, Table)) {
|
|
707
|
-
const schemaName = chunk[Table.Symbol.Schema];
|
|
708
|
-
const tableName = chunk[Table.Symbol.Name];
|
|
709
|
-
return {
|
|
710
|
-
sql: schemaName === undefined || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
|
|
711
|
-
params: []
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
if (is(chunk, Column)) {
|
|
715
|
-
const columnName = casing.getColumnCasing(chunk);
|
|
716
|
-
if (_config.invokeSource === "indexes") {
|
|
717
|
-
return { sql: escapeName(columnName), params: [] };
|
|
718
|
-
}
|
|
719
|
-
const schemaName = chunk.table[Table.Symbol.Schema];
|
|
720
|
-
return {
|
|
721
|
-
sql: chunk.table[IsAlias] || schemaName === undefined ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
|
|
722
|
-
params: []
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
if (is(chunk, View)) {
|
|
726
|
-
const schemaName = chunk[ViewBaseConfig].schema;
|
|
727
|
-
const viewName = chunk[ViewBaseConfig].name;
|
|
728
|
-
return {
|
|
729
|
-
sql: schemaName === undefined || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
|
|
730
|
-
params: []
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
if (is(chunk, Param)) {
|
|
734
|
-
if (is(chunk.value, Placeholder)) {
|
|
735
|
-
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
736
|
-
}
|
|
737
|
-
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
|
738
|
-
if (is(mappedValue, SQL)) {
|
|
739
|
-
return this.buildQueryFromSourceParams([mappedValue], config);
|
|
740
|
-
}
|
|
741
|
-
if (inlineParams) {
|
|
742
|
-
return { sql: this.mapInlineParam(mappedValue, config), params: [] };
|
|
743
|
-
}
|
|
744
|
-
let typings = ["none"];
|
|
745
|
-
if (prepareTyping) {
|
|
746
|
-
typings = [prepareTyping(chunk.encoder)];
|
|
747
|
-
}
|
|
748
|
-
return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
|
|
749
|
-
}
|
|
750
|
-
if (is(chunk, Placeholder)) {
|
|
751
|
-
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
752
|
-
}
|
|
753
|
-
if (is(chunk, SQL.Aliased) && chunk.fieldAlias !== undefined) {
|
|
754
|
-
return { sql: escapeName(chunk.fieldAlias), params: [] };
|
|
755
|
-
}
|
|
756
|
-
if (is(chunk, Subquery)) {
|
|
757
|
-
if (chunk._.isWith) {
|
|
758
|
-
return { sql: escapeName(chunk._.alias), params: [] };
|
|
759
|
-
}
|
|
760
|
-
return this.buildQueryFromSourceParams([
|
|
761
|
-
new StringChunk("("),
|
|
762
|
-
chunk._.sql,
|
|
763
|
-
new StringChunk(") "),
|
|
764
|
-
new Name(chunk._.alias)
|
|
765
|
-
], config);
|
|
766
|
-
}
|
|
767
|
-
if (isPgEnum(chunk)) {
|
|
768
|
-
if (chunk.schema) {
|
|
769
|
-
return { sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName), params: [] };
|
|
770
|
-
}
|
|
771
|
-
return { sql: escapeName(chunk.enumName), params: [] };
|
|
772
|
-
}
|
|
773
|
-
if (isSQLWrapper(chunk)) {
|
|
774
|
-
if (chunk.shouldOmitSQLParens?.()) {
|
|
775
|
-
return this.buildQueryFromSourceParams([chunk.getSQL()], config);
|
|
776
|
-
}
|
|
777
|
-
return this.buildQueryFromSourceParams([
|
|
778
|
-
new StringChunk("("),
|
|
779
|
-
chunk.getSQL(),
|
|
780
|
-
new StringChunk(")")
|
|
781
|
-
], config);
|
|
782
|
-
}
|
|
783
|
-
if (inlineParams) {
|
|
784
|
-
return { sql: this.mapInlineParam(chunk, config), params: [] };
|
|
785
|
-
}
|
|
786
|
-
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
787
|
-
}));
|
|
788
|
-
}
|
|
789
|
-
mapInlineParam(chunk, { escapeString }) {
|
|
790
|
-
if (chunk === null) {
|
|
791
|
-
return "null";
|
|
792
|
-
}
|
|
793
|
-
if (typeof chunk === "number" || typeof chunk === "boolean") {
|
|
794
|
-
return chunk.toString();
|
|
795
|
-
}
|
|
796
|
-
if (typeof chunk === "string") {
|
|
797
|
-
return escapeString(chunk);
|
|
798
|
-
}
|
|
799
|
-
if (typeof chunk === "object") {
|
|
800
|
-
const mappedValueAsString = chunk.toString();
|
|
801
|
-
if (mappedValueAsString === "[object Object]") {
|
|
802
|
-
return escapeString(JSON.stringify(chunk));
|
|
803
|
-
}
|
|
804
|
-
return escapeString(mappedValueAsString);
|
|
805
|
-
}
|
|
806
|
-
throw new Error("Unexpected param value: " + chunk);
|
|
807
|
-
}
|
|
808
|
-
getSQL() {
|
|
809
|
-
return this;
|
|
810
|
-
}
|
|
811
|
-
as(alias) {
|
|
812
|
-
if (alias === undefined) {
|
|
813
|
-
return this;
|
|
814
|
-
}
|
|
815
|
-
return new SQL.Aliased(this, alias);
|
|
816
|
-
}
|
|
817
|
-
mapWith(decoder) {
|
|
818
|
-
this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
|
|
819
|
-
return this;
|
|
820
|
-
}
|
|
821
|
-
inlineParams() {
|
|
822
|
-
this.shouldInlineParams = true;
|
|
823
|
-
return this;
|
|
824
|
-
}
|
|
825
|
-
if(condition) {
|
|
826
|
-
return condition ? this : undefined;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
class Name {
|
|
831
|
-
constructor(value) {
|
|
832
|
-
this.value = value;
|
|
833
|
-
}
|
|
834
|
-
static [entityKind] = "Name";
|
|
835
|
-
brand;
|
|
836
|
-
getSQL() {
|
|
837
|
-
return new SQL([this]);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
function isDriverValueEncoder(value) {
|
|
841
|
-
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
|
|
842
|
-
}
|
|
843
|
-
var noopDecoder = {
|
|
844
|
-
mapFromDriverValue: (value) => value
|
|
845
|
-
};
|
|
846
|
-
var noopEncoder = {
|
|
847
|
-
mapToDriverValue: (value) => value
|
|
848
|
-
};
|
|
849
|
-
var noopMapper = {
|
|
850
|
-
...noopDecoder,
|
|
851
|
-
...noopEncoder
|
|
852
|
-
};
|
|
853
|
-
|
|
854
|
-
class Param {
|
|
855
|
-
constructor(value, encoder = noopEncoder) {
|
|
856
|
-
this.value = value;
|
|
857
|
-
this.encoder = encoder;
|
|
858
|
-
}
|
|
859
|
-
static [entityKind] = "Param";
|
|
860
|
-
brand;
|
|
861
|
-
getSQL() {
|
|
862
|
-
return new SQL([this]);
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
function sql(strings, ...params) {
|
|
866
|
-
const queryChunks = [];
|
|
867
|
-
if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
|
|
868
|
-
queryChunks.push(new StringChunk(strings[0]));
|
|
869
|
-
}
|
|
870
|
-
for (const [paramIndex, param2] of params.entries()) {
|
|
871
|
-
queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
|
|
872
|
-
}
|
|
873
|
-
return new SQL(queryChunks);
|
|
874
|
-
}
|
|
875
|
-
((sql2) => {
|
|
876
|
-
function empty() {
|
|
877
|
-
return new SQL([]);
|
|
878
|
-
}
|
|
879
|
-
sql2.empty = empty;
|
|
880
|
-
function fromList(list) {
|
|
881
|
-
return new SQL(list);
|
|
882
|
-
}
|
|
883
|
-
sql2.fromList = fromList;
|
|
884
|
-
function raw(str) {
|
|
885
|
-
return new SQL([new StringChunk(str)]);
|
|
886
|
-
}
|
|
887
|
-
sql2.raw = raw;
|
|
888
|
-
function join(chunks, separator) {
|
|
889
|
-
const result = [];
|
|
890
|
-
for (const [i, chunk] of chunks.entries()) {
|
|
891
|
-
if (i > 0 && separator !== undefined) {
|
|
892
|
-
result.push(separator);
|
|
893
|
-
}
|
|
894
|
-
result.push(chunk);
|
|
895
|
-
}
|
|
896
|
-
return new SQL(result);
|
|
897
|
-
}
|
|
898
|
-
sql2.join = join;
|
|
899
|
-
function identifier(value) {
|
|
900
|
-
return new Name(value);
|
|
901
|
-
}
|
|
902
|
-
sql2.identifier = identifier;
|
|
903
|
-
function placeholder2(name2) {
|
|
904
|
-
return new Placeholder(name2);
|
|
905
|
-
}
|
|
906
|
-
sql2.placeholder = placeholder2;
|
|
907
|
-
function param2(value, encoder) {
|
|
908
|
-
return new Param(value, encoder);
|
|
909
|
-
}
|
|
910
|
-
sql2.param = param2;
|
|
911
|
-
})(sql || (sql = {}));
|
|
912
|
-
((SQL2) => {
|
|
913
|
-
|
|
914
|
-
class Aliased {
|
|
915
|
-
constructor(sql2, fieldAlias) {
|
|
916
|
-
this.sql = sql2;
|
|
917
|
-
this.fieldAlias = fieldAlias;
|
|
918
|
-
}
|
|
919
|
-
static [entityKind] = "SQL.Aliased";
|
|
920
|
-
isSelectionField = false;
|
|
921
|
-
getSQL() {
|
|
922
|
-
return this.sql;
|
|
923
|
-
}
|
|
924
|
-
clone() {
|
|
925
|
-
return new Aliased(this.sql, this.fieldAlias);
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
SQL2.Aliased = Aliased;
|
|
929
|
-
})(SQL || (SQL = {}));
|
|
930
|
-
|
|
931
|
-
class Placeholder {
|
|
932
|
-
constructor(name2) {
|
|
933
|
-
this.name = name2;
|
|
934
|
-
}
|
|
935
|
-
static [entityKind] = "Placeholder";
|
|
936
|
-
getSQL() {
|
|
937
|
-
return new SQL([this]);
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
var IsDrizzleView = Symbol.for("drizzle:IsDrizzleView");
|
|
941
|
-
|
|
942
|
-
class View {
|
|
943
|
-
static [entityKind] = "View";
|
|
944
|
-
[ViewBaseConfig];
|
|
945
|
-
[IsDrizzleView] = true;
|
|
946
|
-
constructor({ name: name2, schema, selectedFields, query }) {
|
|
947
|
-
this[ViewBaseConfig] = {
|
|
948
|
-
name: name2,
|
|
949
|
-
originalName: name2,
|
|
950
|
-
schema,
|
|
951
|
-
selectedFields,
|
|
952
|
-
query,
|
|
953
|
-
isExisting: !query,
|
|
954
|
-
isAlias: false
|
|
955
|
-
};
|
|
956
|
-
}
|
|
957
|
-
getSQL() {
|
|
958
|
-
return new SQL([this]);
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
Column.prototype.getSQL = function() {
|
|
962
|
-
return new SQL([this]);
|
|
963
|
-
};
|
|
964
|
-
Table.prototype.getSQL = function() {
|
|
965
|
-
return new SQL([this]);
|
|
966
|
-
};
|
|
967
|
-
Subquery.prototype.getSQL = function() {
|
|
968
|
-
return new SQL([this]);
|
|
969
|
-
};
|
|
970
|
-
|
|
971
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/alias.js
|
|
972
|
-
class ColumnAliasProxyHandler {
|
|
973
|
-
constructor(table) {
|
|
974
|
-
this.table = table;
|
|
975
|
-
}
|
|
976
|
-
static [entityKind] = "ColumnAliasProxyHandler";
|
|
977
|
-
get(columnObj, prop) {
|
|
978
|
-
if (prop === "table") {
|
|
979
|
-
return this.table;
|
|
980
|
-
}
|
|
981
|
-
return columnObj[prop];
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
class TableAliasProxyHandler {
|
|
986
|
-
constructor(alias, replaceOriginalName) {
|
|
987
|
-
this.alias = alias;
|
|
988
|
-
this.replaceOriginalName = replaceOriginalName;
|
|
989
|
-
}
|
|
990
|
-
static [entityKind] = "TableAliasProxyHandler";
|
|
991
|
-
get(target, prop) {
|
|
992
|
-
if (prop === Table.Symbol.IsAlias) {
|
|
993
|
-
return true;
|
|
994
|
-
}
|
|
995
|
-
if (prop === Table.Symbol.Name) {
|
|
996
|
-
return this.alias;
|
|
997
|
-
}
|
|
998
|
-
if (this.replaceOriginalName && prop === Table.Symbol.OriginalName) {
|
|
999
|
-
return this.alias;
|
|
1000
|
-
}
|
|
1001
|
-
if (prop === ViewBaseConfig) {
|
|
1002
|
-
return {
|
|
1003
|
-
...target[ViewBaseConfig],
|
|
1004
|
-
name: this.alias,
|
|
1005
|
-
isAlias: true
|
|
1006
|
-
};
|
|
1007
|
-
}
|
|
1008
|
-
if (prop === Table.Symbol.Columns) {
|
|
1009
|
-
const columns = target[Table.Symbol.Columns];
|
|
1010
|
-
if (!columns) {
|
|
1011
|
-
return columns;
|
|
1012
|
-
}
|
|
1013
|
-
const proxiedColumns = {};
|
|
1014
|
-
Object.keys(columns).map((key) => {
|
|
1015
|
-
proxiedColumns[key] = new Proxy(columns[key], new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
1016
|
-
});
|
|
1017
|
-
return proxiedColumns;
|
|
1018
|
-
}
|
|
1019
|
-
const value = target[prop];
|
|
1020
|
-
if (is(value, Column)) {
|
|
1021
|
-
return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
1022
|
-
}
|
|
1023
|
-
return value;
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
function aliasedTable(table, tableAlias) {
|
|
1027
|
-
return new Proxy(table, new TableAliasProxyHandler(tableAlias, false));
|
|
1028
|
-
}
|
|
1029
|
-
function aliasedTableColumn(column, tableAlias) {
|
|
1030
|
-
return new Proxy(column, new ColumnAliasProxyHandler(new Proxy(column.table, new TableAliasProxyHandler(tableAlias, false))));
|
|
1031
|
-
}
|
|
1032
|
-
function mapColumnsInAliasedSQLToAlias(query, alias) {
|
|
1033
|
-
return new SQL.Aliased(mapColumnsInSQLToAlias(query.sql, alias), query.fieldAlias);
|
|
1034
|
-
}
|
|
1035
|
-
function mapColumnsInSQLToAlias(query, alias) {
|
|
1036
|
-
return sql.join(query.queryChunks.map((c) => {
|
|
1037
|
-
if (is(c, Column)) {
|
|
1038
|
-
return aliasedTableColumn(c, alias);
|
|
1039
|
-
}
|
|
1040
|
-
if (is(c, SQL)) {
|
|
1041
|
-
return mapColumnsInSQLToAlias(c, alias);
|
|
1042
|
-
}
|
|
1043
|
-
if (is(c, SQL.Aliased)) {
|
|
1044
|
-
return mapColumnsInAliasedSQLToAlias(c, alias);
|
|
1045
|
-
}
|
|
1046
|
-
return c;
|
|
1047
|
-
}));
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/errors.js
|
|
1051
|
-
class DrizzleError extends Error {
|
|
1052
|
-
static [entityKind] = "DrizzleError";
|
|
1053
|
-
constructor({ message, cause }) {
|
|
1054
|
-
super(message);
|
|
1055
|
-
this.name = "DrizzleError";
|
|
1056
|
-
this.cause = cause;
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/query-promise.js
|
|
1061
|
-
class QueryPromise {
|
|
1062
|
-
static [entityKind] = "QueryPromise";
|
|
1063
|
-
[Symbol.toStringTag] = "QueryPromise";
|
|
1064
|
-
catch(onRejected) {
|
|
1065
|
-
return this.then(undefined, onRejected);
|
|
1066
|
-
}
|
|
1067
|
-
finally(onFinally) {
|
|
1068
|
-
return this.then((value) => {
|
|
1069
|
-
onFinally?.();
|
|
1070
|
-
return value;
|
|
1071
|
-
}, (reason) => {
|
|
1072
|
-
onFinally?.();
|
|
1073
|
-
throw reason;
|
|
1074
|
-
});
|
|
1075
|
-
}
|
|
1076
|
-
then(onFulfilled, onRejected) {
|
|
1077
|
-
return this.execute().then(onFulfilled, onRejected);
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/utils.js
|
|
1082
|
-
function orderSelectedFields(fields, pathPrefix) {
|
|
1083
|
-
return Object.entries(fields).reduce((result, [name, field]) => {
|
|
1084
|
-
if (typeof name !== "string") {
|
|
1085
|
-
return result;
|
|
1086
|
-
}
|
|
1087
|
-
const newPath = pathPrefix ? [...pathPrefix, name] : [name];
|
|
1088
|
-
if (is(field, Column) || is(field, SQL) || is(field, SQL.Aliased) || is(field, Subquery)) {
|
|
1089
|
-
result.push({ path: newPath, field });
|
|
1090
|
-
} else if (is(field, Table)) {
|
|
1091
|
-
result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));
|
|
1092
|
-
} else {
|
|
1093
|
-
result.push(...orderSelectedFields(field, newPath));
|
|
1094
|
-
}
|
|
1095
|
-
return result;
|
|
1096
|
-
}, []);
|
|
1097
|
-
}
|
|
1098
|
-
function haveSameKeys(left, right) {
|
|
1099
|
-
const leftKeys = Object.keys(left);
|
|
1100
|
-
const rightKeys = Object.keys(right);
|
|
1101
|
-
if (leftKeys.length !== rightKeys.length) {
|
|
1102
|
-
return false;
|
|
1103
|
-
}
|
|
1104
|
-
for (const [index, key] of leftKeys.entries()) {
|
|
1105
|
-
if (key !== rightKeys[index]) {
|
|
1106
|
-
return false;
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
return true;
|
|
1110
|
-
}
|
|
1111
|
-
function applyMixins(baseClass, extendedClasses) {
|
|
1112
|
-
for (const extendedClass of extendedClasses) {
|
|
1113
|
-
for (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {
|
|
1114
|
-
if (name === "constructor")
|
|
1115
|
-
continue;
|
|
1116
|
-
Object.defineProperty(baseClass.prototype, name, Object.getOwnPropertyDescriptor(extendedClass.prototype, name) || /* @__PURE__ */ Object.create(null));
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
function getTableColumns(table) {
|
|
1121
|
-
return table[Table.Symbol.Columns];
|
|
1122
|
-
}
|
|
1123
|
-
function getTableLikeName(table) {
|
|
1124
|
-
return is(table, Subquery) ? table._.alias : is(table, View) ? table[ViewBaseConfig].name : is(table, SQL) ? undefined : table[Table.Symbol.IsAlias] ? table[Table.Symbol.Name] : table[Table.Symbol.BaseName];
|
|
1125
|
-
}
|
|
1126
|
-
function getColumnNameAndConfig(a, b) {
|
|
1127
|
-
return {
|
|
1128
|
-
name: typeof a === "string" && a.length > 0 ? a : "",
|
|
1129
|
-
config: typeof a === "object" ? a : b
|
|
1130
|
-
};
|
|
1131
|
-
}
|
|
1132
|
-
var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder;
|
|
1133
|
-
|
|
1134
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/int.common.js
|
|
1135
|
-
class PgIntColumnBaseBuilder extends PgColumnBuilder {
|
|
1136
|
-
static [entityKind] = "PgIntColumnBaseBuilder";
|
|
1137
|
-
generatedAlwaysAsIdentity(sequence) {
|
|
1138
|
-
if (sequence) {
|
|
1139
|
-
const { name, ...options } = sequence;
|
|
1140
|
-
this.config.generatedIdentity = {
|
|
1141
|
-
type: "always",
|
|
1142
|
-
sequenceName: name,
|
|
1143
|
-
sequenceOptions: options
|
|
1144
|
-
};
|
|
1145
|
-
} else {
|
|
1146
|
-
this.config.generatedIdentity = {
|
|
1147
|
-
type: "always"
|
|
1148
|
-
};
|
|
1149
|
-
}
|
|
1150
|
-
this.config.hasDefault = true;
|
|
1151
|
-
this.config.notNull = true;
|
|
1152
|
-
return this;
|
|
1153
|
-
}
|
|
1154
|
-
generatedByDefaultAsIdentity(sequence) {
|
|
1155
|
-
if (sequence) {
|
|
1156
|
-
const { name, ...options } = sequence;
|
|
1157
|
-
this.config.generatedIdentity = {
|
|
1158
|
-
type: "byDefault",
|
|
1159
|
-
sequenceName: name,
|
|
1160
|
-
sequenceOptions: options
|
|
1161
|
-
};
|
|
1162
|
-
} else {
|
|
1163
|
-
this.config.generatedIdentity = {
|
|
1164
|
-
type: "byDefault"
|
|
1165
|
-
};
|
|
1166
|
-
}
|
|
1167
|
-
this.config.hasDefault = true;
|
|
1168
|
-
this.config.notNull = true;
|
|
1169
|
-
return this;
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/bigint.js
|
|
1174
|
-
class PgBigInt53Builder extends PgIntColumnBaseBuilder {
|
|
1175
|
-
static [entityKind] = "PgBigInt53Builder";
|
|
1176
|
-
constructor(name) {
|
|
1177
|
-
super(name, "number", "PgBigInt53");
|
|
1178
|
-
}
|
|
1179
|
-
build(table) {
|
|
1180
|
-
return new PgBigInt53(table, this.config);
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
class PgBigInt53 extends PgColumn {
|
|
1185
|
-
static [entityKind] = "PgBigInt53";
|
|
1186
|
-
getSQLType() {
|
|
1187
|
-
return "bigint";
|
|
1188
|
-
}
|
|
1189
|
-
mapFromDriverValue(value) {
|
|
1190
|
-
if (typeof value === "number") {
|
|
1191
|
-
return value;
|
|
1192
|
-
}
|
|
1193
|
-
return Number(value);
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
class PgBigInt64Builder extends PgIntColumnBaseBuilder {
|
|
1198
|
-
static [entityKind] = "PgBigInt64Builder";
|
|
1199
|
-
constructor(name) {
|
|
1200
|
-
super(name, "bigint", "PgBigInt64");
|
|
1201
|
-
}
|
|
1202
|
-
build(table) {
|
|
1203
|
-
return new PgBigInt64(table, this.config);
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
class PgBigInt64 extends PgColumn {
|
|
1208
|
-
static [entityKind] = "PgBigInt64";
|
|
1209
|
-
getSQLType() {
|
|
1210
|
-
return "bigint";
|
|
1211
|
-
}
|
|
1212
|
-
mapFromDriverValue(value) {
|
|
1213
|
-
return BigInt(value);
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
function bigint(a, b) {
|
|
1217
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1218
|
-
if (config.mode === "number") {
|
|
1219
|
-
return new PgBigInt53Builder(name);
|
|
1220
|
-
}
|
|
1221
|
-
return new PgBigInt64Builder(name);
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/bigserial.js
|
|
1225
|
-
class PgBigSerial53Builder extends PgColumnBuilder {
|
|
1226
|
-
static [entityKind] = "PgBigSerial53Builder";
|
|
1227
|
-
constructor(name) {
|
|
1228
|
-
super(name, "number", "PgBigSerial53");
|
|
1229
|
-
this.config.hasDefault = true;
|
|
1230
|
-
this.config.notNull = true;
|
|
1231
|
-
}
|
|
1232
|
-
build(table) {
|
|
1233
|
-
return new PgBigSerial53(table, this.config);
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
class PgBigSerial53 extends PgColumn {
|
|
1238
|
-
static [entityKind] = "PgBigSerial53";
|
|
1239
|
-
getSQLType() {
|
|
1240
|
-
return "bigserial";
|
|
1241
|
-
}
|
|
1242
|
-
mapFromDriverValue(value) {
|
|
1243
|
-
if (typeof value === "number") {
|
|
1244
|
-
return value;
|
|
1245
|
-
}
|
|
1246
|
-
return Number(value);
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
class PgBigSerial64Builder extends PgColumnBuilder {
|
|
1251
|
-
static [entityKind] = "PgBigSerial64Builder";
|
|
1252
|
-
constructor(name) {
|
|
1253
|
-
super(name, "bigint", "PgBigSerial64");
|
|
1254
|
-
this.config.hasDefault = true;
|
|
1255
|
-
}
|
|
1256
|
-
build(table) {
|
|
1257
|
-
return new PgBigSerial64(table, this.config);
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
class PgBigSerial64 extends PgColumn {
|
|
1262
|
-
static [entityKind] = "PgBigSerial64";
|
|
1263
|
-
getSQLType() {
|
|
1264
|
-
return "bigserial";
|
|
1265
|
-
}
|
|
1266
|
-
mapFromDriverValue(value) {
|
|
1267
|
-
return BigInt(value);
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
function bigserial(a, b) {
|
|
1271
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1272
|
-
if (config.mode === "number") {
|
|
1273
|
-
return new PgBigSerial53Builder(name);
|
|
1274
|
-
}
|
|
1275
|
-
return new PgBigSerial64Builder(name);
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/boolean.js
|
|
1279
|
-
class PgBooleanBuilder extends PgColumnBuilder {
|
|
1280
|
-
static [entityKind] = "PgBooleanBuilder";
|
|
1281
|
-
constructor(name) {
|
|
1282
|
-
super(name, "boolean", "PgBoolean");
|
|
1283
|
-
}
|
|
1284
|
-
build(table) {
|
|
1285
|
-
return new PgBoolean(table, this.config);
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
class PgBoolean extends PgColumn {
|
|
1290
|
-
static [entityKind] = "PgBoolean";
|
|
1291
|
-
getSQLType() {
|
|
1292
|
-
return "boolean";
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
function boolean(name) {
|
|
1296
|
-
return new PgBooleanBuilder(name ?? "");
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/char.js
|
|
1300
|
-
class PgCharBuilder extends PgColumnBuilder {
|
|
1301
|
-
static [entityKind] = "PgCharBuilder";
|
|
1302
|
-
constructor(name, config) {
|
|
1303
|
-
super(name, "string", "PgChar");
|
|
1304
|
-
this.config.length = config.length;
|
|
1305
|
-
this.config.enumValues = config.enum;
|
|
1306
|
-
}
|
|
1307
|
-
build(table) {
|
|
1308
|
-
return new PgChar(table, this.config);
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
class PgChar extends PgColumn {
|
|
1313
|
-
static [entityKind] = "PgChar";
|
|
1314
|
-
length = this.config.length;
|
|
1315
|
-
enumValues = this.config.enumValues;
|
|
1316
|
-
getSQLType() {
|
|
1317
|
-
return this.length === undefined ? `char` : `char(${this.length})`;
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
function char(a, b = {}) {
|
|
1321
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1322
|
-
return new PgCharBuilder(name, config);
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/cidr.js
|
|
1326
|
-
class PgCidrBuilder extends PgColumnBuilder {
|
|
1327
|
-
static [entityKind] = "PgCidrBuilder";
|
|
1328
|
-
constructor(name) {
|
|
1329
|
-
super(name, "string", "PgCidr");
|
|
1330
|
-
}
|
|
1331
|
-
build(table) {
|
|
1332
|
-
return new PgCidr(table, this.config);
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
class PgCidr extends PgColumn {
|
|
1337
|
-
static [entityKind] = "PgCidr";
|
|
1338
|
-
getSQLType() {
|
|
1339
|
-
return "cidr";
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
function cidr(name) {
|
|
1343
|
-
return new PgCidrBuilder(name ?? "");
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/custom.js
|
|
1347
|
-
class PgCustomColumnBuilder extends PgColumnBuilder {
|
|
1348
|
-
static [entityKind] = "PgCustomColumnBuilder";
|
|
1349
|
-
constructor(name, fieldConfig, customTypeParams) {
|
|
1350
|
-
super(name, "custom", "PgCustomColumn");
|
|
1351
|
-
this.config.fieldConfig = fieldConfig;
|
|
1352
|
-
this.config.customTypeParams = customTypeParams;
|
|
1353
|
-
}
|
|
1354
|
-
build(table) {
|
|
1355
|
-
return new PgCustomColumn(table, this.config);
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
class PgCustomColumn extends PgColumn {
|
|
1360
|
-
static [entityKind] = "PgCustomColumn";
|
|
1361
|
-
sqlName;
|
|
1362
|
-
mapTo;
|
|
1363
|
-
mapFrom;
|
|
1364
|
-
constructor(table, config) {
|
|
1365
|
-
super(table, config);
|
|
1366
|
-
this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
|
|
1367
|
-
this.mapTo = config.customTypeParams.toDriver;
|
|
1368
|
-
this.mapFrom = config.customTypeParams.fromDriver;
|
|
1369
|
-
}
|
|
1370
|
-
getSQLType() {
|
|
1371
|
-
return this.sqlName;
|
|
1372
|
-
}
|
|
1373
|
-
mapFromDriverValue(value) {
|
|
1374
|
-
return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
|
|
1375
|
-
}
|
|
1376
|
-
mapToDriverValue(value) {
|
|
1377
|
-
return typeof this.mapTo === "function" ? this.mapTo(value) : value;
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
function customType(customTypeParams) {
|
|
1381
|
-
return (a, b) => {
|
|
1382
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1383
|
-
return new PgCustomColumnBuilder(name, config, customTypeParams);
|
|
1384
|
-
};
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/date.common.js
|
|
1388
|
-
class PgDateColumnBaseBuilder extends PgColumnBuilder {
|
|
1389
|
-
static [entityKind] = "PgDateColumnBaseBuilder";
|
|
1390
|
-
defaultNow() {
|
|
1391
|
-
return this.default(sql`now()`);
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/date.js
|
|
1396
|
-
class PgDateBuilder extends PgDateColumnBaseBuilder {
|
|
1397
|
-
static [entityKind] = "PgDateBuilder";
|
|
1398
|
-
constructor(name) {
|
|
1399
|
-
super(name, "date", "PgDate");
|
|
1400
|
-
}
|
|
1401
|
-
build(table) {
|
|
1402
|
-
return new PgDate(table, this.config);
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
class PgDate extends PgColumn {
|
|
1407
|
-
static [entityKind] = "PgDate";
|
|
1408
|
-
getSQLType() {
|
|
1409
|
-
return "date";
|
|
1410
|
-
}
|
|
1411
|
-
mapFromDriverValue(value) {
|
|
1412
|
-
if (typeof value === "string")
|
|
1413
|
-
return new Date(value);
|
|
1414
|
-
return value;
|
|
1415
|
-
}
|
|
1416
|
-
mapToDriverValue(value) {
|
|
1417
|
-
return value.toISOString();
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
class PgDateStringBuilder extends PgDateColumnBaseBuilder {
|
|
1422
|
-
static [entityKind] = "PgDateStringBuilder";
|
|
1423
|
-
constructor(name) {
|
|
1424
|
-
super(name, "string", "PgDateString");
|
|
1425
|
-
}
|
|
1426
|
-
build(table) {
|
|
1427
|
-
return new PgDateString(table, this.config);
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
class PgDateString extends PgColumn {
|
|
1432
|
-
static [entityKind] = "PgDateString";
|
|
1433
|
-
getSQLType() {
|
|
1434
|
-
return "date";
|
|
1435
|
-
}
|
|
1436
|
-
mapFromDriverValue(value) {
|
|
1437
|
-
if (typeof value === "string")
|
|
1438
|
-
return value;
|
|
1439
|
-
return value.toISOString().slice(0, -14);
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
function date(a, b) {
|
|
1443
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1444
|
-
if (config?.mode === "date") {
|
|
1445
|
-
return new PgDateBuilder(name);
|
|
1446
|
-
}
|
|
1447
|
-
return new PgDateStringBuilder(name);
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/double-precision.js
|
|
1451
|
-
class PgDoublePrecisionBuilder extends PgColumnBuilder {
|
|
1452
|
-
static [entityKind] = "PgDoublePrecisionBuilder";
|
|
1453
|
-
constructor(name) {
|
|
1454
|
-
super(name, "number", "PgDoublePrecision");
|
|
1455
|
-
}
|
|
1456
|
-
build(table) {
|
|
1457
|
-
return new PgDoublePrecision(table, this.config);
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
class PgDoublePrecision extends PgColumn {
|
|
1462
|
-
static [entityKind] = "PgDoublePrecision";
|
|
1463
|
-
getSQLType() {
|
|
1464
|
-
return "double precision";
|
|
1465
|
-
}
|
|
1466
|
-
mapFromDriverValue(value) {
|
|
1467
|
-
if (typeof value === "string") {
|
|
1468
|
-
return Number.parseFloat(value);
|
|
1469
|
-
}
|
|
1470
|
-
return value;
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
function doublePrecision(name) {
|
|
1474
|
-
return new PgDoublePrecisionBuilder(name ?? "");
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/inet.js
|
|
1478
|
-
class PgInetBuilder extends PgColumnBuilder {
|
|
1479
|
-
static [entityKind] = "PgInetBuilder";
|
|
1480
|
-
constructor(name) {
|
|
1481
|
-
super(name, "string", "PgInet");
|
|
1482
|
-
}
|
|
1483
|
-
build(table) {
|
|
1484
|
-
return new PgInet(table, this.config);
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
class PgInet extends PgColumn {
|
|
1489
|
-
static [entityKind] = "PgInet";
|
|
1490
|
-
getSQLType() {
|
|
1491
|
-
return "inet";
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
function inet(name) {
|
|
1495
|
-
return new PgInetBuilder(name ?? "");
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/integer.js
|
|
1499
|
-
class PgIntegerBuilder extends PgIntColumnBaseBuilder {
|
|
1500
|
-
static [entityKind] = "PgIntegerBuilder";
|
|
1501
|
-
constructor(name) {
|
|
1502
|
-
super(name, "number", "PgInteger");
|
|
1503
|
-
}
|
|
1504
|
-
build(table) {
|
|
1505
|
-
return new PgInteger(table, this.config);
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
class PgInteger extends PgColumn {
|
|
1510
|
-
static [entityKind] = "PgInteger";
|
|
1511
|
-
getSQLType() {
|
|
1512
|
-
return "integer";
|
|
1513
|
-
}
|
|
1514
|
-
mapFromDriverValue(value) {
|
|
1515
|
-
if (typeof value === "string") {
|
|
1516
|
-
return Number.parseInt(value);
|
|
1517
|
-
}
|
|
1518
|
-
return value;
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
function integer(name) {
|
|
1522
|
-
return new PgIntegerBuilder(name ?? "");
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/interval.js
|
|
1526
|
-
class PgIntervalBuilder extends PgColumnBuilder {
|
|
1527
|
-
static [entityKind] = "PgIntervalBuilder";
|
|
1528
|
-
constructor(name, intervalConfig) {
|
|
1529
|
-
super(name, "string", "PgInterval");
|
|
1530
|
-
this.config.intervalConfig = intervalConfig;
|
|
1531
|
-
}
|
|
1532
|
-
build(table) {
|
|
1533
|
-
return new PgInterval(table, this.config);
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
class PgInterval extends PgColumn {
|
|
1538
|
-
static [entityKind] = "PgInterval";
|
|
1539
|
-
fields = this.config.intervalConfig.fields;
|
|
1540
|
-
precision = this.config.intervalConfig.precision;
|
|
1541
|
-
getSQLType() {
|
|
1542
|
-
const fields = this.fields ? ` ${this.fields}` : "";
|
|
1543
|
-
const precision = this.precision ? `(${this.precision})` : "";
|
|
1544
|
-
return `interval${fields}${precision}`;
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
function interval(a, b = {}) {
|
|
1548
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1549
|
-
return new PgIntervalBuilder(name, config);
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/json.js
|
|
1553
|
-
class PgJsonBuilder extends PgColumnBuilder {
|
|
1554
|
-
static [entityKind] = "PgJsonBuilder";
|
|
1555
|
-
constructor(name) {
|
|
1556
|
-
super(name, "json", "PgJson");
|
|
1557
|
-
}
|
|
1558
|
-
build(table) {
|
|
1559
|
-
return new PgJson(table, this.config);
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
class PgJson extends PgColumn {
|
|
1564
|
-
static [entityKind] = "PgJson";
|
|
1565
|
-
constructor(table, config) {
|
|
1566
|
-
super(table, config);
|
|
1567
|
-
}
|
|
1568
|
-
getSQLType() {
|
|
1569
|
-
return "json";
|
|
1570
|
-
}
|
|
1571
|
-
mapToDriverValue(value) {
|
|
1572
|
-
return JSON.stringify(value);
|
|
1573
|
-
}
|
|
1574
|
-
mapFromDriverValue(value) {
|
|
1575
|
-
if (typeof value === "string") {
|
|
1576
|
-
try {
|
|
1577
|
-
return JSON.parse(value);
|
|
1578
|
-
} catch {
|
|
1579
|
-
return value;
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
return value;
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
function json(name) {
|
|
1586
|
-
return new PgJsonBuilder(name ?? "");
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/jsonb.js
|
|
1590
|
-
class PgJsonbBuilder extends PgColumnBuilder {
|
|
1591
|
-
static [entityKind] = "PgJsonbBuilder";
|
|
1592
|
-
constructor(name) {
|
|
1593
|
-
super(name, "json", "PgJsonb");
|
|
1594
|
-
}
|
|
1595
|
-
build(table) {
|
|
1596
|
-
return new PgJsonb(table, this.config);
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
class PgJsonb extends PgColumn {
|
|
1601
|
-
static [entityKind] = "PgJsonb";
|
|
1602
|
-
constructor(table, config) {
|
|
1603
|
-
super(table, config);
|
|
1604
|
-
}
|
|
1605
|
-
getSQLType() {
|
|
1606
|
-
return "jsonb";
|
|
1607
|
-
}
|
|
1608
|
-
mapToDriverValue(value) {
|
|
1609
|
-
return JSON.stringify(value);
|
|
1610
|
-
}
|
|
1611
|
-
mapFromDriverValue(value) {
|
|
1612
|
-
if (typeof value === "string") {
|
|
1613
|
-
try {
|
|
1614
|
-
return JSON.parse(value);
|
|
1615
|
-
} catch {
|
|
1616
|
-
return value;
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
return value;
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
function jsonb(name) {
|
|
1623
|
-
return new PgJsonbBuilder(name ?? "");
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/line.js
|
|
1627
|
-
class PgLineBuilder extends PgColumnBuilder {
|
|
1628
|
-
static [entityKind] = "PgLineBuilder";
|
|
1629
|
-
constructor(name) {
|
|
1630
|
-
super(name, "array", "PgLine");
|
|
1631
|
-
}
|
|
1632
|
-
build(table) {
|
|
1633
|
-
return new PgLineTuple(table, this.config);
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
class PgLineTuple extends PgColumn {
|
|
1638
|
-
static [entityKind] = "PgLine";
|
|
1639
|
-
getSQLType() {
|
|
1640
|
-
return "line";
|
|
1641
|
-
}
|
|
1642
|
-
mapFromDriverValue(value) {
|
|
1643
|
-
const [a, b, c] = value.slice(1, -1).split(",");
|
|
1644
|
-
return [Number.parseFloat(a), Number.parseFloat(b), Number.parseFloat(c)];
|
|
1645
|
-
}
|
|
1646
|
-
mapToDriverValue(value) {
|
|
1647
|
-
return `{${value[0]},${value[1]},${value[2]}}`;
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
|
|
1651
|
-
class PgLineABCBuilder extends PgColumnBuilder {
|
|
1652
|
-
static [entityKind] = "PgLineABCBuilder";
|
|
1653
|
-
constructor(name) {
|
|
1654
|
-
super(name, "json", "PgLineABC");
|
|
1655
|
-
}
|
|
1656
|
-
build(table) {
|
|
1657
|
-
return new PgLineABC(table, this.config);
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
|
-
class PgLineABC extends PgColumn {
|
|
1662
|
-
static [entityKind] = "PgLineABC";
|
|
1663
|
-
getSQLType() {
|
|
1664
|
-
return "line";
|
|
1665
|
-
}
|
|
1666
|
-
mapFromDriverValue(value) {
|
|
1667
|
-
const [a, b, c] = value.slice(1, -1).split(",");
|
|
1668
|
-
return { a: Number.parseFloat(a), b: Number.parseFloat(b), c: Number.parseFloat(c) };
|
|
1669
|
-
}
|
|
1670
|
-
mapToDriverValue(value) {
|
|
1671
|
-
return `{${value.a},${value.b},${value.c}}`;
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
function line(a, b) {
|
|
1675
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1676
|
-
if (!config?.mode || config.mode === "tuple") {
|
|
1677
|
-
return new PgLineBuilder(name);
|
|
1678
|
-
}
|
|
1679
|
-
return new PgLineABCBuilder(name);
|
|
1680
|
-
}
|
|
1681
|
-
|
|
1682
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/macaddr.js
|
|
1683
|
-
class PgMacaddrBuilder extends PgColumnBuilder {
|
|
1684
|
-
static [entityKind] = "PgMacaddrBuilder";
|
|
1685
|
-
constructor(name) {
|
|
1686
|
-
super(name, "string", "PgMacaddr");
|
|
1687
|
-
}
|
|
1688
|
-
build(table) {
|
|
1689
|
-
return new PgMacaddr(table, this.config);
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
|
-
class PgMacaddr extends PgColumn {
|
|
1694
|
-
static [entityKind] = "PgMacaddr";
|
|
1695
|
-
getSQLType() {
|
|
1696
|
-
return "macaddr";
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
function macaddr(name) {
|
|
1700
|
-
return new PgMacaddrBuilder(name ?? "");
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/macaddr8.js
|
|
1704
|
-
class PgMacaddr8Builder extends PgColumnBuilder {
|
|
1705
|
-
static [entityKind] = "PgMacaddr8Builder";
|
|
1706
|
-
constructor(name) {
|
|
1707
|
-
super(name, "string", "PgMacaddr8");
|
|
1708
|
-
}
|
|
1709
|
-
build(table) {
|
|
1710
|
-
return new PgMacaddr8(table, this.config);
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
|
-
class PgMacaddr8 extends PgColumn {
|
|
1715
|
-
static [entityKind] = "PgMacaddr8";
|
|
1716
|
-
getSQLType() {
|
|
1717
|
-
return "macaddr8";
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
function macaddr8(name) {
|
|
1721
|
-
return new PgMacaddr8Builder(name ?? "");
|
|
1722
|
-
}
|
|
1723
|
-
|
|
1724
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/numeric.js
|
|
1725
|
-
class PgNumericBuilder extends PgColumnBuilder {
|
|
1726
|
-
static [entityKind] = "PgNumericBuilder";
|
|
1727
|
-
constructor(name, precision, scale) {
|
|
1728
|
-
super(name, "string", "PgNumeric");
|
|
1729
|
-
this.config.precision = precision;
|
|
1730
|
-
this.config.scale = scale;
|
|
1731
|
-
}
|
|
1732
|
-
build(table) {
|
|
1733
|
-
return new PgNumeric(table, this.config);
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
|
|
1737
|
-
class PgNumeric extends PgColumn {
|
|
1738
|
-
static [entityKind] = "PgNumeric";
|
|
1739
|
-
precision;
|
|
1740
|
-
scale;
|
|
1741
|
-
constructor(table, config) {
|
|
1742
|
-
super(table, config);
|
|
1743
|
-
this.precision = config.precision;
|
|
1744
|
-
this.scale = config.scale;
|
|
1745
|
-
}
|
|
1746
|
-
mapFromDriverValue(value) {
|
|
1747
|
-
if (typeof value === "string")
|
|
1748
|
-
return value;
|
|
1749
|
-
return String(value);
|
|
1750
|
-
}
|
|
1751
|
-
getSQLType() {
|
|
1752
|
-
if (this.precision !== undefined && this.scale !== undefined) {
|
|
1753
|
-
return `numeric(${this.precision}, ${this.scale})`;
|
|
1754
|
-
} else if (this.precision === undefined) {
|
|
1755
|
-
return "numeric";
|
|
1756
|
-
} else {
|
|
1757
|
-
return `numeric(${this.precision})`;
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
class PgNumericNumberBuilder extends PgColumnBuilder {
|
|
1763
|
-
static [entityKind] = "PgNumericNumberBuilder";
|
|
1764
|
-
constructor(name, precision, scale) {
|
|
1765
|
-
super(name, "number", "PgNumericNumber");
|
|
1766
|
-
this.config.precision = precision;
|
|
1767
|
-
this.config.scale = scale;
|
|
1768
|
-
}
|
|
1769
|
-
build(table) {
|
|
1770
|
-
return new PgNumericNumber(table, this.config);
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
class PgNumericNumber extends PgColumn {
|
|
1775
|
-
static [entityKind] = "PgNumericNumber";
|
|
1776
|
-
precision;
|
|
1777
|
-
scale;
|
|
1778
|
-
constructor(table, config) {
|
|
1779
|
-
super(table, config);
|
|
1780
|
-
this.precision = config.precision;
|
|
1781
|
-
this.scale = config.scale;
|
|
1782
|
-
}
|
|
1783
|
-
mapFromDriverValue(value) {
|
|
1784
|
-
if (typeof value === "number")
|
|
1785
|
-
return value;
|
|
1786
|
-
return Number(value);
|
|
1787
|
-
}
|
|
1788
|
-
mapToDriverValue = String;
|
|
1789
|
-
getSQLType() {
|
|
1790
|
-
if (this.precision !== undefined && this.scale !== undefined) {
|
|
1791
|
-
return `numeric(${this.precision}, ${this.scale})`;
|
|
1792
|
-
} else if (this.precision === undefined) {
|
|
1793
|
-
return "numeric";
|
|
1794
|
-
} else {
|
|
1795
|
-
return `numeric(${this.precision})`;
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
class PgNumericBigIntBuilder extends PgColumnBuilder {
|
|
1801
|
-
static [entityKind] = "PgNumericBigIntBuilder";
|
|
1802
|
-
constructor(name, precision, scale) {
|
|
1803
|
-
super(name, "bigint", "PgNumericBigInt");
|
|
1804
|
-
this.config.precision = precision;
|
|
1805
|
-
this.config.scale = scale;
|
|
1806
|
-
}
|
|
1807
|
-
build(table) {
|
|
1808
|
-
return new PgNumericBigInt(table, this.config);
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
class PgNumericBigInt extends PgColumn {
|
|
1813
|
-
static [entityKind] = "PgNumericBigInt";
|
|
1814
|
-
precision;
|
|
1815
|
-
scale;
|
|
1816
|
-
constructor(table, config) {
|
|
1817
|
-
super(table, config);
|
|
1818
|
-
this.precision = config.precision;
|
|
1819
|
-
this.scale = config.scale;
|
|
1820
|
-
}
|
|
1821
|
-
mapFromDriverValue = BigInt;
|
|
1822
|
-
mapToDriverValue = String;
|
|
1823
|
-
getSQLType() {
|
|
1824
|
-
if (this.precision !== undefined && this.scale !== undefined) {
|
|
1825
|
-
return `numeric(${this.precision}, ${this.scale})`;
|
|
1826
|
-
} else if (this.precision === undefined) {
|
|
1827
|
-
return "numeric";
|
|
1828
|
-
} else {
|
|
1829
|
-
return `numeric(${this.precision})`;
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
function numeric(a, b) {
|
|
1834
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1835
|
-
const mode = config?.mode;
|
|
1836
|
-
return mode === "number" ? new PgNumericNumberBuilder(name, config?.precision, config?.scale) : mode === "bigint" ? new PgNumericBigIntBuilder(name, config?.precision, config?.scale) : new PgNumericBuilder(name, config?.precision, config?.scale);
|
|
1837
|
-
}
|
|
1838
|
-
|
|
1839
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/point.js
|
|
1840
|
-
class PgPointTupleBuilder extends PgColumnBuilder {
|
|
1841
|
-
static [entityKind] = "PgPointTupleBuilder";
|
|
1842
|
-
constructor(name) {
|
|
1843
|
-
super(name, "array", "PgPointTuple");
|
|
1844
|
-
}
|
|
1845
|
-
build(table) {
|
|
1846
|
-
return new PgPointTuple(table, this.config);
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
class PgPointTuple extends PgColumn {
|
|
1851
|
-
static [entityKind] = "PgPointTuple";
|
|
1852
|
-
getSQLType() {
|
|
1853
|
-
return "point";
|
|
1854
|
-
}
|
|
1855
|
-
mapFromDriverValue(value) {
|
|
1856
|
-
if (typeof value === "string") {
|
|
1857
|
-
const [x, y] = value.slice(1, -1).split(",");
|
|
1858
|
-
return [Number.parseFloat(x), Number.parseFloat(y)];
|
|
1859
|
-
}
|
|
1860
|
-
return [value.x, value.y];
|
|
1861
|
-
}
|
|
1862
|
-
mapToDriverValue(value) {
|
|
1863
|
-
return `(${value[0]},${value[1]})`;
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
|
|
1867
|
-
class PgPointObjectBuilder extends PgColumnBuilder {
|
|
1868
|
-
static [entityKind] = "PgPointObjectBuilder";
|
|
1869
|
-
constructor(name) {
|
|
1870
|
-
super(name, "json", "PgPointObject");
|
|
1871
|
-
}
|
|
1872
|
-
build(table) {
|
|
1873
|
-
return new PgPointObject(table, this.config);
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
class PgPointObject extends PgColumn {
|
|
1878
|
-
static [entityKind] = "PgPointObject";
|
|
1879
|
-
getSQLType() {
|
|
1880
|
-
return "point";
|
|
1881
|
-
}
|
|
1882
|
-
mapFromDriverValue(value) {
|
|
1883
|
-
if (typeof value === "string") {
|
|
1884
|
-
const [x, y] = value.slice(1, -1).split(",");
|
|
1885
|
-
return { x: Number.parseFloat(x), y: Number.parseFloat(y) };
|
|
1886
|
-
}
|
|
1887
|
-
return value;
|
|
1888
|
-
}
|
|
1889
|
-
mapToDriverValue(value) {
|
|
1890
|
-
return `(${value.x},${value.y})`;
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
function point(a, b) {
|
|
1894
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1895
|
-
if (!config?.mode || config.mode === "tuple") {
|
|
1896
|
-
return new PgPointTupleBuilder(name);
|
|
1897
|
-
}
|
|
1898
|
-
return new PgPointObjectBuilder(name);
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/postgis_extension/utils.js
|
|
1902
|
-
function hexToBytes(hex) {
|
|
1903
|
-
const bytes = [];
|
|
1904
|
-
for (let c = 0;c < hex.length; c += 2) {
|
|
1905
|
-
bytes.push(Number.parseInt(hex.slice(c, c + 2), 16));
|
|
1906
|
-
}
|
|
1907
|
-
return new Uint8Array(bytes);
|
|
1908
|
-
}
|
|
1909
|
-
function bytesToFloat64(bytes, offset) {
|
|
1910
|
-
const buffer = new ArrayBuffer(8);
|
|
1911
|
-
const view = new DataView(buffer);
|
|
1912
|
-
for (let i = 0;i < 8; i++) {
|
|
1913
|
-
view.setUint8(i, bytes[offset + i]);
|
|
1914
|
-
}
|
|
1915
|
-
return view.getFloat64(0, true);
|
|
1916
|
-
}
|
|
1917
|
-
function parseEWKB(hex) {
|
|
1918
|
-
const bytes = hexToBytes(hex);
|
|
1919
|
-
let offset = 0;
|
|
1920
|
-
const byteOrder = bytes[offset];
|
|
1921
|
-
offset += 1;
|
|
1922
|
-
const view = new DataView(bytes.buffer);
|
|
1923
|
-
const geomType = view.getUint32(offset, byteOrder === 1);
|
|
1924
|
-
offset += 4;
|
|
1925
|
-
let _srid;
|
|
1926
|
-
if (geomType & 536870912) {
|
|
1927
|
-
_srid = view.getUint32(offset, byteOrder === 1);
|
|
1928
|
-
offset += 4;
|
|
1929
|
-
}
|
|
1930
|
-
if ((geomType & 65535) === 1) {
|
|
1931
|
-
const x = bytesToFloat64(bytes, offset);
|
|
1932
|
-
offset += 8;
|
|
1933
|
-
const y = bytesToFloat64(bytes, offset);
|
|
1934
|
-
offset += 8;
|
|
1935
|
-
return [x, y];
|
|
1936
|
-
}
|
|
1937
|
-
throw new Error("Unsupported geometry type");
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/postgis_extension/geometry.js
|
|
1941
|
-
class PgGeometryBuilder extends PgColumnBuilder {
|
|
1942
|
-
static [entityKind] = "PgGeometryBuilder";
|
|
1943
|
-
constructor(name) {
|
|
1944
|
-
super(name, "array", "PgGeometry");
|
|
1945
|
-
}
|
|
1946
|
-
build(table) {
|
|
1947
|
-
return new PgGeometry(table, this.config);
|
|
1948
|
-
}
|
|
1949
|
-
}
|
|
1950
|
-
|
|
1951
|
-
class PgGeometry extends PgColumn {
|
|
1952
|
-
static [entityKind] = "PgGeometry";
|
|
1953
|
-
getSQLType() {
|
|
1954
|
-
return "geometry(point)";
|
|
1955
|
-
}
|
|
1956
|
-
mapFromDriverValue(value) {
|
|
1957
|
-
return parseEWKB(value);
|
|
1958
|
-
}
|
|
1959
|
-
mapToDriverValue(value) {
|
|
1960
|
-
return `point(${value[0]} ${value[1]})`;
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
|
-
class PgGeometryObjectBuilder extends PgColumnBuilder {
|
|
1965
|
-
static [entityKind] = "PgGeometryObjectBuilder";
|
|
1966
|
-
constructor(name) {
|
|
1967
|
-
super(name, "json", "PgGeometryObject");
|
|
1968
|
-
}
|
|
1969
|
-
build(table) {
|
|
1970
|
-
return new PgGeometryObject(table, this.config);
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
|
|
1974
|
-
class PgGeometryObject extends PgColumn {
|
|
1975
|
-
static [entityKind] = "PgGeometryObject";
|
|
1976
|
-
getSQLType() {
|
|
1977
|
-
return "geometry(point)";
|
|
1978
|
-
}
|
|
1979
|
-
mapFromDriverValue(value) {
|
|
1980
|
-
const parsed = parseEWKB(value);
|
|
1981
|
-
return { x: parsed[0], y: parsed[1] };
|
|
1982
|
-
}
|
|
1983
|
-
mapToDriverValue(value) {
|
|
1984
|
-
return `point(${value.x} ${value.y})`;
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
function geometry(a, b) {
|
|
1988
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1989
|
-
if (!config?.mode || config.mode === "tuple") {
|
|
1990
|
-
return new PgGeometryBuilder(name);
|
|
1991
|
-
}
|
|
1992
|
-
return new PgGeometryObjectBuilder(name);
|
|
1993
|
-
}
|
|
1994
|
-
|
|
1995
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/real.js
|
|
1996
|
-
class PgRealBuilder extends PgColumnBuilder {
|
|
1997
|
-
static [entityKind] = "PgRealBuilder";
|
|
1998
|
-
constructor(name, length) {
|
|
1999
|
-
super(name, "number", "PgReal");
|
|
2000
|
-
this.config.length = length;
|
|
2001
|
-
}
|
|
2002
|
-
build(table) {
|
|
2003
|
-
return new PgReal(table, this.config);
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
|
|
2007
|
-
class PgReal extends PgColumn {
|
|
2008
|
-
static [entityKind] = "PgReal";
|
|
2009
|
-
constructor(table, config) {
|
|
2010
|
-
super(table, config);
|
|
2011
|
-
}
|
|
2012
|
-
getSQLType() {
|
|
2013
|
-
return "real";
|
|
2014
|
-
}
|
|
2015
|
-
mapFromDriverValue = (value) => {
|
|
2016
|
-
if (typeof value === "string") {
|
|
2017
|
-
return Number.parseFloat(value);
|
|
2018
|
-
}
|
|
2019
|
-
return value;
|
|
2020
|
-
};
|
|
2021
|
-
}
|
|
2022
|
-
function real(name) {
|
|
2023
|
-
return new PgRealBuilder(name ?? "");
|
|
2024
|
-
}
|
|
2025
|
-
|
|
2026
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/serial.js
|
|
2027
|
-
class PgSerialBuilder extends PgColumnBuilder {
|
|
2028
|
-
static [entityKind] = "PgSerialBuilder";
|
|
2029
|
-
constructor(name) {
|
|
2030
|
-
super(name, "number", "PgSerial");
|
|
2031
|
-
this.config.hasDefault = true;
|
|
2032
|
-
this.config.notNull = true;
|
|
2033
|
-
}
|
|
2034
|
-
build(table) {
|
|
2035
|
-
return new PgSerial(table, this.config);
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
class PgSerial extends PgColumn {
|
|
2040
|
-
static [entityKind] = "PgSerial";
|
|
2041
|
-
getSQLType() {
|
|
2042
|
-
return "serial";
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
function serial(name) {
|
|
2046
|
-
return new PgSerialBuilder(name ?? "");
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/smallint.js
|
|
2050
|
-
class PgSmallIntBuilder extends PgIntColumnBaseBuilder {
|
|
2051
|
-
static [entityKind] = "PgSmallIntBuilder";
|
|
2052
|
-
constructor(name) {
|
|
2053
|
-
super(name, "number", "PgSmallInt");
|
|
2054
|
-
}
|
|
2055
|
-
build(table) {
|
|
2056
|
-
return new PgSmallInt(table, this.config);
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
|
|
2060
|
-
class PgSmallInt extends PgColumn {
|
|
2061
|
-
static [entityKind] = "PgSmallInt";
|
|
2062
|
-
getSQLType() {
|
|
2063
|
-
return "smallint";
|
|
2064
|
-
}
|
|
2065
|
-
mapFromDriverValue = (value) => {
|
|
2066
|
-
if (typeof value === "string") {
|
|
2067
|
-
return Number(value);
|
|
2068
|
-
}
|
|
2069
|
-
return value;
|
|
2070
|
-
};
|
|
2071
|
-
}
|
|
2072
|
-
function smallint(name) {
|
|
2073
|
-
return new PgSmallIntBuilder(name ?? "");
|
|
2074
|
-
}
|
|
2075
|
-
|
|
2076
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/smallserial.js
|
|
2077
|
-
class PgSmallSerialBuilder extends PgColumnBuilder {
|
|
2078
|
-
static [entityKind] = "PgSmallSerialBuilder";
|
|
2079
|
-
constructor(name) {
|
|
2080
|
-
super(name, "number", "PgSmallSerial");
|
|
2081
|
-
this.config.hasDefault = true;
|
|
2082
|
-
this.config.notNull = true;
|
|
2083
|
-
}
|
|
2084
|
-
build(table) {
|
|
2085
|
-
return new PgSmallSerial(table, this.config);
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
|
|
2089
|
-
class PgSmallSerial extends PgColumn {
|
|
2090
|
-
static [entityKind] = "PgSmallSerial";
|
|
2091
|
-
getSQLType() {
|
|
2092
|
-
return "smallserial";
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
function smallserial(name) {
|
|
2096
|
-
return new PgSmallSerialBuilder(name ?? "");
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/text.js
|
|
2100
|
-
class PgTextBuilder extends PgColumnBuilder {
|
|
2101
|
-
static [entityKind] = "PgTextBuilder";
|
|
2102
|
-
constructor(name, config) {
|
|
2103
|
-
super(name, "string", "PgText");
|
|
2104
|
-
this.config.enumValues = config.enum;
|
|
2105
|
-
}
|
|
2106
|
-
build(table) {
|
|
2107
|
-
return new PgText(table, this.config);
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
|
-
class PgText extends PgColumn {
|
|
2112
|
-
static [entityKind] = "PgText";
|
|
2113
|
-
enumValues = this.config.enumValues;
|
|
2114
|
-
getSQLType() {
|
|
2115
|
-
return "text";
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
function text(a, b = {}) {
|
|
2119
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
2120
|
-
return new PgTextBuilder(name, config);
|
|
2121
|
-
}
|
|
2122
|
-
|
|
2123
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/time.js
|
|
2124
|
-
class PgTimeBuilder extends PgDateColumnBaseBuilder {
|
|
2125
|
-
constructor(name, withTimezone, precision) {
|
|
2126
|
-
super(name, "string", "PgTime");
|
|
2127
|
-
this.withTimezone = withTimezone;
|
|
2128
|
-
this.precision = precision;
|
|
2129
|
-
this.config.withTimezone = withTimezone;
|
|
2130
|
-
this.config.precision = precision;
|
|
2131
|
-
}
|
|
2132
|
-
static [entityKind] = "PgTimeBuilder";
|
|
2133
|
-
build(table) {
|
|
2134
|
-
return new PgTime(table, this.config);
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
|
|
2138
|
-
class PgTime extends PgColumn {
|
|
2139
|
-
static [entityKind] = "PgTime";
|
|
2140
|
-
withTimezone;
|
|
2141
|
-
precision;
|
|
2142
|
-
constructor(table, config) {
|
|
2143
|
-
super(table, config);
|
|
2144
|
-
this.withTimezone = config.withTimezone;
|
|
2145
|
-
this.precision = config.precision;
|
|
2146
|
-
}
|
|
2147
|
-
getSQLType() {
|
|
2148
|
-
const precision = this.precision === undefined ? "" : `(${this.precision})`;
|
|
2149
|
-
return `time${precision}${this.withTimezone ? " with time zone" : ""}`;
|
|
2150
|
-
}
|
|
2151
|
-
}
|
|
2152
|
-
function time(a, b = {}) {
|
|
2153
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
2154
|
-
return new PgTimeBuilder(name, config.withTimezone ?? false, config.precision);
|
|
2155
|
-
}
|
|
2156
|
-
|
|
2157
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/timestamp.js
|
|
2158
|
-
class PgTimestampBuilder extends PgDateColumnBaseBuilder {
|
|
2159
|
-
static [entityKind] = "PgTimestampBuilder";
|
|
2160
|
-
constructor(name, withTimezone, precision) {
|
|
2161
|
-
super(name, "date", "PgTimestamp");
|
|
2162
|
-
this.config.withTimezone = withTimezone;
|
|
2163
|
-
this.config.precision = precision;
|
|
2164
|
-
}
|
|
2165
|
-
build(table) {
|
|
2166
|
-
return new PgTimestamp(table, this.config);
|
|
2167
|
-
}
|
|
2168
|
-
}
|
|
2169
|
-
|
|
2170
|
-
class PgTimestamp extends PgColumn {
|
|
2171
|
-
static [entityKind] = "PgTimestamp";
|
|
2172
|
-
withTimezone;
|
|
2173
|
-
precision;
|
|
2174
|
-
constructor(table, config) {
|
|
2175
|
-
super(table, config);
|
|
2176
|
-
this.withTimezone = config.withTimezone;
|
|
2177
|
-
this.precision = config.precision;
|
|
2178
|
-
}
|
|
2179
|
-
getSQLType() {
|
|
2180
|
-
const precision = this.precision === undefined ? "" : ` (${this.precision})`;
|
|
2181
|
-
return `timestamp${precision}${this.withTimezone ? " with time zone" : ""}`;
|
|
2182
|
-
}
|
|
2183
|
-
mapFromDriverValue(value) {
|
|
2184
|
-
if (typeof value === "string")
|
|
2185
|
-
return new Date(this.withTimezone ? value : value + "+0000");
|
|
2186
|
-
return value;
|
|
2187
|
-
}
|
|
2188
|
-
mapToDriverValue = (value) => {
|
|
2189
|
-
return value.toISOString();
|
|
2190
|
-
};
|
|
2191
|
-
}
|
|
2192
|
-
|
|
2193
|
-
class PgTimestampStringBuilder extends PgDateColumnBaseBuilder {
|
|
2194
|
-
static [entityKind] = "PgTimestampStringBuilder";
|
|
2195
|
-
constructor(name, withTimezone, precision) {
|
|
2196
|
-
super(name, "string", "PgTimestampString");
|
|
2197
|
-
this.config.withTimezone = withTimezone;
|
|
2198
|
-
this.config.precision = precision;
|
|
2199
|
-
}
|
|
2200
|
-
build(table) {
|
|
2201
|
-
return new PgTimestampString(table, this.config);
|
|
2202
|
-
}
|
|
2203
|
-
}
|
|
2204
|
-
|
|
2205
|
-
class PgTimestampString extends PgColumn {
|
|
2206
|
-
static [entityKind] = "PgTimestampString";
|
|
2207
|
-
withTimezone;
|
|
2208
|
-
precision;
|
|
2209
|
-
constructor(table, config) {
|
|
2210
|
-
super(table, config);
|
|
2211
|
-
this.withTimezone = config.withTimezone;
|
|
2212
|
-
this.precision = config.precision;
|
|
2213
|
-
}
|
|
2214
|
-
getSQLType() {
|
|
2215
|
-
const precision = this.precision === undefined ? "" : `(${this.precision})`;
|
|
2216
|
-
return `timestamp${precision}${this.withTimezone ? " with time zone" : ""}`;
|
|
2217
|
-
}
|
|
2218
|
-
mapFromDriverValue(value) {
|
|
2219
|
-
if (typeof value === "string")
|
|
2220
|
-
return value;
|
|
2221
|
-
const shortened = value.toISOString().slice(0, -1).replace("T", " ");
|
|
2222
|
-
if (this.withTimezone) {
|
|
2223
|
-
const offset = value.getTimezoneOffset();
|
|
2224
|
-
const sign = offset <= 0 ? "+" : "-";
|
|
2225
|
-
return `${shortened}${sign}${Math.floor(Math.abs(offset) / 60).toString().padStart(2, "0")}`;
|
|
2226
|
-
}
|
|
2227
|
-
return shortened;
|
|
2228
|
-
}
|
|
2229
|
-
}
|
|
2230
|
-
function timestamp(a, b = {}) {
|
|
2231
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
2232
|
-
if (config?.mode === "string") {
|
|
2233
|
-
return new PgTimestampStringBuilder(name, config.withTimezone ?? false, config.precision);
|
|
2234
|
-
}
|
|
2235
|
-
return new PgTimestampBuilder(name, config?.withTimezone ?? false, config?.precision);
|
|
2236
|
-
}
|
|
2237
|
-
|
|
2238
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/uuid.js
|
|
2239
|
-
class PgUUIDBuilder extends PgColumnBuilder {
|
|
2240
|
-
static [entityKind] = "PgUUIDBuilder";
|
|
2241
|
-
constructor(name) {
|
|
2242
|
-
super(name, "string", "PgUUID");
|
|
2243
|
-
}
|
|
2244
|
-
defaultRandom() {
|
|
2245
|
-
return this.default(sql`gen_random_uuid()`);
|
|
2246
|
-
}
|
|
2247
|
-
build(table) {
|
|
2248
|
-
return new PgUUID(table, this.config);
|
|
2249
|
-
}
|
|
2250
|
-
}
|
|
2251
|
-
|
|
2252
|
-
class PgUUID extends PgColumn {
|
|
2253
|
-
static [entityKind] = "PgUUID";
|
|
2254
|
-
getSQLType() {
|
|
2255
|
-
return "uuid";
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
function uuid(name) {
|
|
2259
|
-
return new PgUUIDBuilder(name ?? "");
|
|
2260
|
-
}
|
|
2261
|
-
|
|
2262
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/varchar.js
|
|
2263
|
-
class PgVarcharBuilder extends PgColumnBuilder {
|
|
2264
|
-
static [entityKind] = "PgVarcharBuilder";
|
|
2265
|
-
constructor(name, config) {
|
|
2266
|
-
super(name, "string", "PgVarchar");
|
|
2267
|
-
this.config.length = config.length;
|
|
2268
|
-
this.config.enumValues = config.enum;
|
|
2269
|
-
}
|
|
2270
|
-
build(table) {
|
|
2271
|
-
return new PgVarchar(table, this.config);
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
|
|
2275
|
-
class PgVarchar extends PgColumn {
|
|
2276
|
-
static [entityKind] = "PgVarchar";
|
|
2277
|
-
length = this.config.length;
|
|
2278
|
-
enumValues = this.config.enumValues;
|
|
2279
|
-
getSQLType() {
|
|
2280
|
-
return this.length === undefined ? `varchar` : `varchar(${this.length})`;
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
function varchar(a, b = {}) {
|
|
2284
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
2285
|
-
return new PgVarcharBuilder(name, config);
|
|
2286
|
-
}
|
|
2287
|
-
|
|
2288
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/vector_extension/bit.js
|
|
2289
|
-
class PgBinaryVectorBuilder extends PgColumnBuilder {
|
|
2290
|
-
static [entityKind] = "PgBinaryVectorBuilder";
|
|
2291
|
-
constructor(name, config) {
|
|
2292
|
-
super(name, "string", "PgBinaryVector");
|
|
2293
|
-
this.config.dimensions = config.dimensions;
|
|
2294
|
-
}
|
|
2295
|
-
build(table) {
|
|
2296
|
-
return new PgBinaryVector(table, this.config);
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
|
|
2300
|
-
class PgBinaryVector extends PgColumn {
|
|
2301
|
-
static [entityKind] = "PgBinaryVector";
|
|
2302
|
-
dimensions = this.config.dimensions;
|
|
2303
|
-
getSQLType() {
|
|
2304
|
-
return `bit(${this.dimensions})`;
|
|
2305
|
-
}
|
|
2306
|
-
}
|
|
2307
|
-
function bit(a, b) {
|
|
2308
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
2309
|
-
return new PgBinaryVectorBuilder(name, config);
|
|
2310
|
-
}
|
|
2311
|
-
|
|
2312
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/vector_extension/halfvec.js
|
|
2313
|
-
class PgHalfVectorBuilder extends PgColumnBuilder {
|
|
2314
|
-
static [entityKind] = "PgHalfVectorBuilder";
|
|
2315
|
-
constructor(name, config) {
|
|
2316
|
-
super(name, "array", "PgHalfVector");
|
|
2317
|
-
this.config.dimensions = config.dimensions;
|
|
2318
|
-
}
|
|
2319
|
-
build(table) {
|
|
2320
|
-
return new PgHalfVector(table, this.config);
|
|
2321
|
-
}
|
|
2322
|
-
}
|
|
2323
|
-
|
|
2324
|
-
class PgHalfVector extends PgColumn {
|
|
2325
|
-
static [entityKind] = "PgHalfVector";
|
|
2326
|
-
dimensions = this.config.dimensions;
|
|
2327
|
-
getSQLType() {
|
|
2328
|
-
return `halfvec(${this.dimensions})`;
|
|
2329
|
-
}
|
|
2330
|
-
mapToDriverValue(value) {
|
|
2331
|
-
return JSON.stringify(value);
|
|
2332
|
-
}
|
|
2333
|
-
mapFromDriverValue(value) {
|
|
2334
|
-
return value.slice(1, -1).split(",").map((v) => Number.parseFloat(v));
|
|
2335
|
-
}
|
|
2336
|
-
}
|
|
2337
|
-
function halfvec(a, b) {
|
|
2338
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
2339
|
-
return new PgHalfVectorBuilder(name, config);
|
|
2340
|
-
}
|
|
2341
|
-
|
|
2342
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/vector_extension/sparsevec.js
|
|
2343
|
-
class PgSparseVectorBuilder extends PgColumnBuilder {
|
|
2344
|
-
static [entityKind] = "PgSparseVectorBuilder";
|
|
2345
|
-
constructor(name, config) {
|
|
2346
|
-
super(name, "string", "PgSparseVector");
|
|
2347
|
-
this.config.dimensions = config.dimensions;
|
|
2348
|
-
}
|
|
2349
|
-
build(table) {
|
|
2350
|
-
return new PgSparseVector(table, this.config);
|
|
2351
|
-
}
|
|
2352
|
-
}
|
|
2353
|
-
|
|
2354
|
-
class PgSparseVector extends PgColumn {
|
|
2355
|
-
static [entityKind] = "PgSparseVector";
|
|
2356
|
-
dimensions = this.config.dimensions;
|
|
2357
|
-
getSQLType() {
|
|
2358
|
-
return `sparsevec(${this.dimensions})`;
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
function sparsevec(a, b) {
|
|
2362
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
2363
|
-
return new PgSparseVectorBuilder(name, config);
|
|
2364
|
-
}
|
|
2365
|
-
|
|
2366
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/vector_extension/vector.js
|
|
2367
|
-
class PgVectorBuilder extends PgColumnBuilder {
|
|
2368
|
-
static [entityKind] = "PgVectorBuilder";
|
|
2369
|
-
constructor(name, config) {
|
|
2370
|
-
super(name, "array", "PgVector");
|
|
2371
|
-
this.config.dimensions = config.dimensions;
|
|
2372
|
-
}
|
|
2373
|
-
build(table) {
|
|
2374
|
-
return new PgVector(table, this.config);
|
|
2375
|
-
}
|
|
2376
|
-
}
|
|
2377
|
-
|
|
2378
|
-
class PgVector extends PgColumn {
|
|
2379
|
-
static [entityKind] = "PgVector";
|
|
2380
|
-
dimensions = this.config.dimensions;
|
|
2381
|
-
getSQLType() {
|
|
2382
|
-
return `vector(${this.dimensions})`;
|
|
2383
|
-
}
|
|
2384
|
-
mapToDriverValue(value) {
|
|
2385
|
-
return JSON.stringify(value);
|
|
2386
|
-
}
|
|
2387
|
-
mapFromDriverValue(value) {
|
|
2388
|
-
return value.slice(1, -1).split(",").map((v) => Number.parseFloat(v));
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
function vector(a, b) {
|
|
2392
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
2393
|
-
return new PgVectorBuilder(name, config);
|
|
2394
|
-
}
|
|
2395
|
-
|
|
2396
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/columns/all.js
|
|
2397
|
-
function getPgColumnBuilders() {
|
|
2398
|
-
return {
|
|
2399
|
-
bigint,
|
|
2400
|
-
bigserial,
|
|
2401
|
-
boolean,
|
|
2402
|
-
char,
|
|
2403
|
-
cidr,
|
|
2404
|
-
customType,
|
|
2405
|
-
date,
|
|
2406
|
-
doublePrecision,
|
|
2407
|
-
inet,
|
|
2408
|
-
integer,
|
|
2409
|
-
interval,
|
|
2410
|
-
json,
|
|
2411
|
-
jsonb,
|
|
2412
|
-
line,
|
|
2413
|
-
macaddr,
|
|
2414
|
-
macaddr8,
|
|
2415
|
-
numeric,
|
|
2416
|
-
point,
|
|
2417
|
-
geometry,
|
|
2418
|
-
real,
|
|
2419
|
-
serial,
|
|
2420
|
-
smallint,
|
|
2421
|
-
smallserial,
|
|
2422
|
-
text,
|
|
2423
|
-
time,
|
|
2424
|
-
timestamp,
|
|
2425
|
-
uuid,
|
|
2426
|
-
varchar,
|
|
2427
|
-
bit,
|
|
2428
|
-
halfvec,
|
|
2429
|
-
sparsevec,
|
|
2430
|
-
vector
|
|
2431
|
-
};
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/table.js
|
|
2435
|
-
var InlineForeignKeys = Symbol.for("drizzle:PgInlineForeignKeys");
|
|
2436
|
-
var EnableRLS = Symbol.for("drizzle:EnableRLS");
|
|
2437
|
-
|
|
2438
|
-
class PgTable extends Table {
|
|
2439
|
-
static [entityKind] = "PgTable";
|
|
2440
|
-
static Symbol = Object.assign({}, Table.Symbol, {
|
|
2441
|
-
InlineForeignKeys,
|
|
2442
|
-
EnableRLS
|
|
2443
|
-
});
|
|
2444
|
-
[InlineForeignKeys] = [];
|
|
2445
|
-
[EnableRLS] = false;
|
|
2446
|
-
[Table.Symbol.ExtraConfigBuilder] = undefined;
|
|
2447
|
-
[Table.Symbol.ExtraConfigColumns] = {};
|
|
2448
|
-
}
|
|
2449
|
-
function pgTableWithSchema(name, columns, extraConfig, schema, baseName = name) {
|
|
2450
|
-
const rawTable = new PgTable(name, schema, baseName);
|
|
2451
|
-
const parsedColumns = typeof columns === "function" ? columns(getPgColumnBuilders()) : columns;
|
|
2452
|
-
const builtColumns = Object.fromEntries(Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
|
|
2453
|
-
const colBuilder = colBuilderBase;
|
|
2454
|
-
colBuilder.setName(name2);
|
|
2455
|
-
const column = colBuilder.build(rawTable);
|
|
2456
|
-
rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
|
|
2457
|
-
return [name2, column];
|
|
2458
|
-
}));
|
|
2459
|
-
const builtColumnsForExtraConfig = Object.fromEntries(Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
|
|
2460
|
-
const colBuilder = colBuilderBase;
|
|
2461
|
-
colBuilder.setName(name2);
|
|
2462
|
-
const column = colBuilder.buildExtraConfigColumn(rawTable);
|
|
2463
|
-
return [name2, column];
|
|
2464
|
-
}));
|
|
2465
|
-
const table = Object.assign(rawTable, builtColumns);
|
|
2466
|
-
table[Table.Symbol.Columns] = builtColumns;
|
|
2467
|
-
table[Table.Symbol.ExtraConfigColumns] = builtColumnsForExtraConfig;
|
|
2468
|
-
if (extraConfig) {
|
|
2469
|
-
table[PgTable.Symbol.ExtraConfigBuilder] = extraConfig;
|
|
2470
|
-
}
|
|
2471
|
-
return Object.assign(table, {
|
|
2472
|
-
enableRLS: () => {
|
|
2473
|
-
table[PgTable.Symbol.EnableRLS] = true;
|
|
2474
|
-
return table;
|
|
2475
|
-
}
|
|
2476
|
-
});
|
|
2477
|
-
}
|
|
2478
|
-
var pgTable = (name, columns, extraConfig) => {
|
|
2479
|
-
return pgTableWithSchema(name, columns, extraConfig, undefined);
|
|
2480
|
-
};
|
|
2481
|
-
|
|
2482
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
2483
|
-
function bindIfParam(value, column) {
|
|
2484
|
-
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
|
|
2485
|
-
return new Param(value, column);
|
|
2486
|
-
}
|
|
2487
|
-
return value;
|
|
2488
|
-
}
|
|
2489
|
-
var eq = (left, right) => {
|
|
2490
|
-
return sql`${left} = ${bindIfParam(right, left)}`;
|
|
2491
|
-
};
|
|
2492
|
-
var ne = (left, right) => {
|
|
2493
|
-
return sql`${left} <> ${bindIfParam(right, left)}`;
|
|
2494
|
-
};
|
|
2495
|
-
function and(...unfilteredConditions) {
|
|
2496
|
-
const conditions = unfilteredConditions.filter((c) => c !== undefined);
|
|
2497
|
-
if (conditions.length === 0) {
|
|
2498
|
-
return;
|
|
2499
|
-
}
|
|
2500
|
-
if (conditions.length === 1) {
|
|
2501
|
-
return new SQL(conditions);
|
|
2502
|
-
}
|
|
2503
|
-
return new SQL([
|
|
2504
|
-
new StringChunk("("),
|
|
2505
|
-
sql.join(conditions, new StringChunk(" and ")),
|
|
2506
|
-
new StringChunk(")")
|
|
2507
|
-
]);
|
|
2508
|
-
}
|
|
2509
|
-
function or(...unfilteredConditions) {
|
|
2510
|
-
const conditions = unfilteredConditions.filter((c) => c !== undefined);
|
|
2511
|
-
if (conditions.length === 0) {
|
|
2512
|
-
return;
|
|
2513
|
-
}
|
|
2514
|
-
if (conditions.length === 1) {
|
|
2515
|
-
return new SQL(conditions);
|
|
2516
|
-
}
|
|
2517
|
-
return new SQL([
|
|
2518
|
-
new StringChunk("("),
|
|
2519
|
-
sql.join(conditions, new StringChunk(" or ")),
|
|
2520
|
-
new StringChunk(")")
|
|
2521
|
-
]);
|
|
2522
|
-
}
|
|
2523
|
-
function not(condition) {
|
|
2524
|
-
return sql`not ${condition}`;
|
|
2525
|
-
}
|
|
2526
|
-
var gt = (left, right) => {
|
|
2527
|
-
return sql`${left} > ${bindIfParam(right, left)}`;
|
|
2528
|
-
};
|
|
2529
|
-
var gte = (left, right) => {
|
|
2530
|
-
return sql`${left} >= ${bindIfParam(right, left)}`;
|
|
2531
|
-
};
|
|
2532
|
-
var lt = (left, right) => {
|
|
2533
|
-
return sql`${left} < ${bindIfParam(right, left)}`;
|
|
2534
|
-
};
|
|
2535
|
-
var lte = (left, right) => {
|
|
2536
|
-
return sql`${left} <= ${bindIfParam(right, left)}`;
|
|
2537
|
-
};
|
|
2538
|
-
function inArray(column, values) {
|
|
2539
|
-
if (Array.isArray(values)) {
|
|
2540
|
-
if (values.length === 0) {
|
|
2541
|
-
return sql`false`;
|
|
2542
|
-
}
|
|
2543
|
-
return sql`${column} in ${values.map((v) => bindIfParam(v, column))}`;
|
|
2544
|
-
}
|
|
2545
|
-
return sql`${column} in ${bindIfParam(values, column)}`;
|
|
2546
|
-
}
|
|
2547
|
-
function notInArray(column, values) {
|
|
2548
|
-
if (Array.isArray(values)) {
|
|
2549
|
-
if (values.length === 0) {
|
|
2550
|
-
return sql`true`;
|
|
2551
|
-
}
|
|
2552
|
-
return sql`${column} not in ${values.map((v) => bindIfParam(v, column))}`;
|
|
2553
|
-
}
|
|
2554
|
-
return sql`${column} not in ${bindIfParam(values, column)}`;
|
|
2555
|
-
}
|
|
2556
|
-
function isNull(value) {
|
|
2557
|
-
return sql`${value} is null`;
|
|
2558
|
-
}
|
|
2559
|
-
function isNotNull(value) {
|
|
2560
|
-
return sql`${value} is not null`;
|
|
2561
|
-
}
|
|
2562
|
-
function exists(subquery) {
|
|
2563
|
-
return sql`exists ${subquery}`;
|
|
2564
|
-
}
|
|
2565
|
-
function notExists(subquery) {
|
|
2566
|
-
return sql`not exists ${subquery}`;
|
|
2567
|
-
}
|
|
2568
|
-
function between(column, min, max) {
|
|
2569
|
-
return sql`${column} between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
2570
|
-
}
|
|
2571
|
-
function notBetween(column, min, max) {
|
|
2572
|
-
return sql`${column} not between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
2573
|
-
}
|
|
2574
|
-
function like(column, value) {
|
|
2575
|
-
return sql`${column} like ${value}`;
|
|
2576
|
-
}
|
|
2577
|
-
function notLike(column, value) {
|
|
2578
|
-
return sql`${column} not like ${value}`;
|
|
2579
|
-
}
|
|
2580
|
-
function ilike(column, value) {
|
|
2581
|
-
return sql`${column} ilike ${value}`;
|
|
2582
|
-
}
|
|
2583
|
-
function notIlike(column, value) {
|
|
2584
|
-
return sql`${column} not ilike ${value}`;
|
|
2585
|
-
}
|
|
2586
|
-
|
|
2587
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/sql/expressions/select.js
|
|
2588
|
-
function asc(column) {
|
|
2589
|
-
return sql`${column} asc`;
|
|
2590
|
-
}
|
|
2591
|
-
function desc(column) {
|
|
2592
|
-
return sql`${column} desc`;
|
|
2593
|
-
}
|
|
2594
|
-
|
|
2595
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/relations.js
|
|
2596
|
-
class Relation {
|
|
2597
|
-
constructor(sourceTable, referencedTable, relationName) {
|
|
2598
|
-
this.sourceTable = sourceTable;
|
|
2599
|
-
this.referencedTable = referencedTable;
|
|
2600
|
-
this.relationName = relationName;
|
|
2601
|
-
this.referencedTableName = referencedTable[Table.Symbol.Name];
|
|
2602
|
-
}
|
|
2603
|
-
static [entityKind] = "Relation";
|
|
2604
|
-
referencedTableName;
|
|
2605
|
-
fieldName;
|
|
2606
|
-
}
|
|
2607
|
-
class One extends Relation {
|
|
2608
|
-
constructor(sourceTable, referencedTable, config, isNullable) {
|
|
2609
|
-
super(sourceTable, referencedTable, config?.relationName);
|
|
2610
|
-
this.config = config;
|
|
2611
|
-
this.isNullable = isNullable;
|
|
2612
|
-
}
|
|
2613
|
-
static [entityKind] = "One";
|
|
2614
|
-
withFieldName(fieldName) {
|
|
2615
|
-
const relation = new One(this.sourceTable, this.referencedTable, this.config, this.isNullable);
|
|
2616
|
-
relation.fieldName = fieldName;
|
|
2617
|
-
return relation;
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
|
|
2621
|
-
class Many extends Relation {
|
|
2622
|
-
constructor(sourceTable, referencedTable, config) {
|
|
2623
|
-
super(sourceTable, referencedTable, config?.relationName);
|
|
2624
|
-
this.config = config;
|
|
2625
|
-
}
|
|
2626
|
-
static [entityKind] = "Many";
|
|
2627
|
-
withFieldName(fieldName) {
|
|
2628
|
-
const relation = new Many(this.sourceTable, this.referencedTable, this.config);
|
|
2629
|
-
relation.fieldName = fieldName;
|
|
2630
|
-
return relation;
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
function getOperators() {
|
|
2634
|
-
return {
|
|
2635
|
-
and,
|
|
2636
|
-
between,
|
|
2637
|
-
eq,
|
|
2638
|
-
exists,
|
|
2639
|
-
gt,
|
|
2640
|
-
gte,
|
|
2641
|
-
ilike,
|
|
2642
|
-
inArray,
|
|
2643
|
-
isNull,
|
|
2644
|
-
isNotNull,
|
|
2645
|
-
like,
|
|
2646
|
-
lt,
|
|
2647
|
-
lte,
|
|
2648
|
-
ne,
|
|
2649
|
-
not,
|
|
2650
|
-
notBetween,
|
|
2651
|
-
notExists,
|
|
2652
|
-
notLike,
|
|
2653
|
-
notIlike,
|
|
2654
|
-
notInArray,
|
|
2655
|
-
or,
|
|
2656
|
-
sql
|
|
2657
|
-
};
|
|
2658
|
-
}
|
|
2659
|
-
function getOrderByOperators() {
|
|
2660
|
-
return {
|
|
2661
|
-
sql,
|
|
2662
|
-
asc,
|
|
2663
|
-
desc
|
|
2664
|
-
};
|
|
2665
|
-
}
|
|
2666
|
-
function normalizeRelation(schema, tableNamesMap, relation) {
|
|
2667
|
-
if (is(relation, One) && relation.config) {
|
|
2668
|
-
return {
|
|
2669
|
-
fields: relation.config.fields,
|
|
2670
|
-
references: relation.config.references
|
|
2671
|
-
};
|
|
2672
|
-
}
|
|
2673
|
-
const referencedTableTsName = tableNamesMap[getTableUniqueName(relation.referencedTable)];
|
|
2674
|
-
if (!referencedTableTsName) {
|
|
2675
|
-
throw new Error(`Table "${relation.referencedTable[Table.Symbol.Name]}" not found in schema`);
|
|
2676
|
-
}
|
|
2677
|
-
const referencedTableConfig = schema[referencedTableTsName];
|
|
2678
|
-
if (!referencedTableConfig) {
|
|
2679
|
-
throw new Error(`Table "${referencedTableTsName}" not found in schema`);
|
|
2680
|
-
}
|
|
2681
|
-
const sourceTable = relation.sourceTable;
|
|
2682
|
-
const sourceTableTsName = tableNamesMap[getTableUniqueName(sourceTable)];
|
|
2683
|
-
if (!sourceTableTsName) {
|
|
2684
|
-
throw new Error(`Table "${sourceTable[Table.Symbol.Name]}" not found in schema`);
|
|
2685
|
-
}
|
|
2686
|
-
const reverseRelations = [];
|
|
2687
|
-
for (const referencedTableRelation of Object.values(referencedTableConfig.relations)) {
|
|
2688
|
-
if (relation.relationName && relation !== referencedTableRelation && referencedTableRelation.relationName === relation.relationName || !relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) {
|
|
2689
|
-
reverseRelations.push(referencedTableRelation);
|
|
2690
|
-
}
|
|
2691
|
-
}
|
|
2692
|
-
if (reverseRelations.length > 1) {
|
|
2693
|
-
throw relation.relationName ? new Error(`There are multiple relations with name "${relation.relationName}" in table "${referencedTableTsName}"`) : new Error(`There are multiple relations between "${referencedTableTsName}" and "${relation.sourceTable[Table.Symbol.Name]}". Please specify relation name`);
|
|
2694
|
-
}
|
|
2695
|
-
if (reverseRelations[0] && is(reverseRelations[0], One) && reverseRelations[0].config) {
|
|
2696
|
-
return {
|
|
2697
|
-
fields: reverseRelations[0].config.references,
|
|
2698
|
-
references: reverseRelations[0].config.fields
|
|
2699
|
-
};
|
|
2700
|
-
}
|
|
2701
|
-
throw new Error(`There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`);
|
|
2702
|
-
}
|
|
2703
|
-
|
|
2704
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/selection-proxy.js
|
|
2705
|
-
class SelectionProxyHandler {
|
|
2706
|
-
static [entityKind] = "SelectionProxyHandler";
|
|
2707
|
-
config;
|
|
2708
|
-
constructor(config) {
|
|
2709
|
-
this.config = { ...config };
|
|
2710
|
-
}
|
|
2711
|
-
get(subquery, prop) {
|
|
2712
|
-
if (prop === "_") {
|
|
2713
|
-
return {
|
|
2714
|
-
...subquery["_"],
|
|
2715
|
-
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
2716
|
-
};
|
|
2717
|
-
}
|
|
2718
|
-
if (prop === ViewBaseConfig) {
|
|
2719
|
-
return {
|
|
2720
|
-
...subquery[ViewBaseConfig],
|
|
2721
|
-
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
2722
|
-
};
|
|
2723
|
-
}
|
|
2724
|
-
if (typeof prop === "symbol") {
|
|
2725
|
-
return subquery[prop];
|
|
2726
|
-
}
|
|
2727
|
-
const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery;
|
|
2728
|
-
const value = columns[prop];
|
|
2729
|
-
if (is(value, SQL.Aliased)) {
|
|
2730
|
-
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
|
|
2731
|
-
return value.sql;
|
|
2732
|
-
}
|
|
2733
|
-
const newValue = value.clone();
|
|
2734
|
-
newValue.isSelectionField = true;
|
|
2735
|
-
return newValue;
|
|
2736
|
-
}
|
|
2737
|
-
if (is(value, SQL)) {
|
|
2738
|
-
if (this.config.sqlBehavior === "sql") {
|
|
2739
|
-
return value;
|
|
2740
|
-
}
|
|
2741
|
-
throw new Error(`You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`);
|
|
2742
|
-
}
|
|
2743
|
-
if (is(value, Column)) {
|
|
2744
|
-
if (this.config.alias) {
|
|
2745
|
-
return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(value.table, new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false))));
|
|
2746
|
-
}
|
|
2747
|
-
return value;
|
|
2748
|
-
}
|
|
2749
|
-
if (typeof value !== "object" || value === null) {
|
|
2750
|
-
return value;
|
|
2751
|
-
}
|
|
2752
|
-
return new Proxy(value, new SelectionProxyHandler(this.config));
|
|
2753
|
-
}
|
|
2754
|
-
}
|
|
2755
|
-
|
|
2756
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/indexes.js
|
|
2757
|
-
class IndexBuilderOn {
|
|
2758
|
-
constructor(unique, name) {
|
|
2759
|
-
this.unique = unique;
|
|
2760
|
-
this.name = name;
|
|
2761
|
-
}
|
|
2762
|
-
static [entityKind] = "PgIndexBuilderOn";
|
|
2763
|
-
on(...columns) {
|
|
2764
|
-
return new IndexBuilder(columns.map((it) => {
|
|
2765
|
-
if (is(it, SQL)) {
|
|
2766
|
-
return it;
|
|
2767
|
-
}
|
|
2768
|
-
it = it;
|
|
2769
|
-
const clonedIndexedColumn = new IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);
|
|
2770
|
-
it.indexConfig = JSON.parse(JSON.stringify(it.defaultConfig));
|
|
2771
|
-
return clonedIndexedColumn;
|
|
2772
|
-
}), this.unique, false, this.name);
|
|
2773
|
-
}
|
|
2774
|
-
onOnly(...columns) {
|
|
2775
|
-
return new IndexBuilder(columns.map((it) => {
|
|
2776
|
-
if (is(it, SQL)) {
|
|
2777
|
-
return it;
|
|
2778
|
-
}
|
|
2779
|
-
it = it;
|
|
2780
|
-
const clonedIndexedColumn = new IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);
|
|
2781
|
-
it.indexConfig = it.defaultConfig;
|
|
2782
|
-
return clonedIndexedColumn;
|
|
2783
|
-
}), this.unique, true, this.name);
|
|
2784
|
-
}
|
|
2785
|
-
using(method, ...columns) {
|
|
2786
|
-
return new IndexBuilder(columns.map((it) => {
|
|
2787
|
-
if (is(it, SQL)) {
|
|
2788
|
-
return it;
|
|
2789
|
-
}
|
|
2790
|
-
it = it;
|
|
2791
|
-
const clonedIndexedColumn = new IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);
|
|
2792
|
-
it.indexConfig = JSON.parse(JSON.stringify(it.defaultConfig));
|
|
2793
|
-
return clonedIndexedColumn;
|
|
2794
|
-
}), this.unique, true, this.name, method);
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
|
|
2798
|
-
class IndexBuilder {
|
|
2799
|
-
static [entityKind] = "PgIndexBuilder";
|
|
2800
|
-
config;
|
|
2801
|
-
constructor(columns, unique, only, name, method = "btree") {
|
|
2802
|
-
this.config = {
|
|
2803
|
-
name,
|
|
2804
|
-
columns,
|
|
2805
|
-
unique,
|
|
2806
|
-
only,
|
|
2807
|
-
method
|
|
2808
|
-
};
|
|
2809
|
-
}
|
|
2810
|
-
concurrently() {
|
|
2811
|
-
this.config.concurrently = true;
|
|
2812
|
-
return this;
|
|
2813
|
-
}
|
|
2814
|
-
with(obj) {
|
|
2815
|
-
this.config.with = obj;
|
|
2816
|
-
return this;
|
|
2817
|
-
}
|
|
2818
|
-
where(condition) {
|
|
2819
|
-
this.config.where = condition;
|
|
2820
|
-
return this;
|
|
2821
|
-
}
|
|
2822
|
-
build(table) {
|
|
2823
|
-
return new Index(this.config, table);
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
|
|
2827
|
-
class Index {
|
|
2828
|
-
static [entityKind] = "PgIndex";
|
|
2829
|
-
config;
|
|
2830
|
-
constructor(config, table) {
|
|
2831
|
-
this.config = { ...config, table };
|
|
2832
|
-
}
|
|
2833
|
-
}
|
|
2834
|
-
function index(name) {
|
|
2835
|
-
return new IndexBuilderOn(false, name);
|
|
2836
|
-
}
|
|
2837
|
-
|
|
2838
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/view-common.js
|
|
2839
|
-
var PgViewConfig = Symbol.for("drizzle:PgViewConfig");
|
|
2840
|
-
|
|
2841
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/casing.js
|
|
2842
|
-
function toSnakeCase(input) {
|
|
2843
|
-
const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
|
|
2844
|
-
return words.map((word) => word.toLowerCase()).join("_");
|
|
2845
|
-
}
|
|
2846
|
-
function toCamelCase(input) {
|
|
2847
|
-
const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
|
|
2848
|
-
return words.reduce((acc, word, i) => {
|
|
2849
|
-
const formattedWord = i === 0 ? word.toLowerCase() : `${word[0].toUpperCase()}${word.slice(1)}`;
|
|
2850
|
-
return acc + formattedWord;
|
|
2851
|
-
}, "");
|
|
2852
|
-
}
|
|
2853
|
-
function noopCase(input) {
|
|
2854
|
-
return input;
|
|
2855
|
-
}
|
|
2856
|
-
|
|
2857
|
-
class CasingCache {
|
|
2858
|
-
static [entityKind] = "CasingCache";
|
|
2859
|
-
cache = {};
|
|
2860
|
-
cachedTables = {};
|
|
2861
|
-
convert;
|
|
2862
|
-
constructor(casing) {
|
|
2863
|
-
this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase;
|
|
2864
|
-
}
|
|
2865
|
-
getColumnCasing(column) {
|
|
2866
|
-
if (!column.keyAsName)
|
|
2867
|
-
return column.name;
|
|
2868
|
-
const schema = column.table[Table.Symbol.Schema] ?? "public";
|
|
2869
|
-
const tableName = column.table[Table.Symbol.OriginalName];
|
|
2870
|
-
const key = `${schema}.${tableName}.${column.name}`;
|
|
2871
|
-
if (!this.cache[key]) {
|
|
2872
|
-
this.cacheTable(column.table);
|
|
2873
|
-
}
|
|
2874
|
-
return this.cache[key];
|
|
2875
|
-
}
|
|
2876
|
-
cacheTable(table) {
|
|
2877
|
-
const schema = table[Table.Symbol.Schema] ?? "public";
|
|
2878
|
-
const tableName = table[Table.Symbol.OriginalName];
|
|
2879
|
-
const tableKey = `${schema}.${tableName}`;
|
|
2880
|
-
if (!this.cachedTables[tableKey]) {
|
|
2881
|
-
for (const column of Object.values(table[Table.Symbol.Columns])) {
|
|
2882
|
-
const columnKey = `${tableKey}.${column.name}`;
|
|
2883
|
-
this.cache[columnKey] = this.convert(column.name);
|
|
2884
|
-
}
|
|
2885
|
-
this.cachedTables[tableKey] = true;
|
|
2886
|
-
}
|
|
2887
|
-
}
|
|
2888
|
-
clearCache() {
|
|
2889
|
-
this.cache = {};
|
|
2890
|
-
this.cachedTables = {};
|
|
2891
|
-
}
|
|
2892
|
-
}
|
|
2893
|
-
|
|
2894
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/view-base.js
|
|
2895
|
-
class PgViewBase extends View {
|
|
2896
|
-
static [entityKind] = "PgViewBase";
|
|
2897
|
-
}
|
|
2898
|
-
|
|
2899
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/dialect.js
|
|
2900
|
-
class PgDialect {
|
|
2901
|
-
static [entityKind] = "PgDialect";
|
|
2902
|
-
casing;
|
|
2903
|
-
constructor(config) {
|
|
2904
|
-
this.casing = new CasingCache(config?.casing);
|
|
2905
|
-
}
|
|
2906
|
-
async migrate(migrations, session, config) {
|
|
2907
|
-
const migrationsTable = typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
2908
|
-
const migrationsSchema = typeof config === "string" ? "drizzle" : config.migrationsSchema ?? "drizzle";
|
|
2909
|
-
const migrationTableCreate = sql`
|
|
2910
|
-
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} (
|
|
2911
|
-
id SERIAL PRIMARY KEY,
|
|
2912
|
-
hash text NOT NULL,
|
|
2913
|
-
created_at bigint
|
|
2914
|
-
)
|
|
2915
|
-
`;
|
|
2916
|
-
await session.execute(sql`CREATE SCHEMA IF NOT EXISTS ${sql.identifier(migrationsSchema)}`);
|
|
2917
|
-
await session.execute(migrationTableCreate);
|
|
2918
|
-
const dbMigrations = await session.all(sql`select id, hash, created_at from ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} order by created_at desc limit 1`);
|
|
2919
|
-
const lastDbMigration = dbMigrations[0];
|
|
2920
|
-
await session.transaction(async (tx) => {
|
|
2921
|
-
for await (const migration of migrations) {
|
|
2922
|
-
if (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {
|
|
2923
|
-
for (const stmt of migration.sql) {
|
|
2924
|
-
await tx.execute(sql.raw(stmt));
|
|
2925
|
-
}
|
|
2926
|
-
await tx.execute(sql`insert into ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} ("hash", "created_at") values(${migration.hash}, ${migration.folderMillis})`);
|
|
2927
|
-
}
|
|
2928
|
-
}
|
|
2929
|
-
});
|
|
2930
|
-
}
|
|
2931
|
-
escapeName(name) {
|
|
2932
|
-
return `"${name.replace(/"/g, '""')}"`;
|
|
2933
|
-
}
|
|
2934
|
-
escapeParam(num) {
|
|
2935
|
-
return `$${num + 1}`;
|
|
2936
|
-
}
|
|
2937
|
-
escapeString(str) {
|
|
2938
|
-
return `'${str.replace(/'/g, "''")}'`;
|
|
2939
|
-
}
|
|
2940
|
-
buildWithCTE(queries) {
|
|
2941
|
-
if (!queries?.length)
|
|
2942
|
-
return;
|
|
2943
|
-
const withSqlChunks = [sql`with `];
|
|
2944
|
-
for (const [i, w] of queries.entries()) {
|
|
2945
|
-
withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
|
|
2946
|
-
if (i < queries.length - 1) {
|
|
2947
|
-
withSqlChunks.push(sql`, `);
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
withSqlChunks.push(sql` `);
|
|
2951
|
-
return sql.join(withSqlChunks);
|
|
2952
|
-
}
|
|
2953
|
-
buildDeleteQuery({ table, where, returning, withList }) {
|
|
2954
|
-
const withSql = this.buildWithCTE(withList);
|
|
2955
|
-
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : undefined;
|
|
2956
|
-
const whereSql = where ? sql` where ${where}` : undefined;
|
|
2957
|
-
return sql`${withSql}delete from ${table}${whereSql}${returningSql}`;
|
|
2958
|
-
}
|
|
2959
|
-
buildUpdateSet(table, set) {
|
|
2960
|
-
const tableColumns = table[Table.Symbol.Columns];
|
|
2961
|
-
const columnNames = Object.keys(tableColumns).filter((colName) => set[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined);
|
|
2962
|
-
const setSize = columnNames.length;
|
|
2963
|
-
return sql.join(columnNames.flatMap((colName, i) => {
|
|
2964
|
-
const col = tableColumns[colName];
|
|
2965
|
-
const onUpdateFnResult = col.onUpdateFn?.();
|
|
2966
|
-
const value = set[colName] ?? (is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col));
|
|
2967
|
-
const res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;
|
|
2968
|
-
if (i < setSize - 1) {
|
|
2969
|
-
return [res, sql.raw(", ")];
|
|
2970
|
-
}
|
|
2971
|
-
return [res];
|
|
2972
|
-
}));
|
|
2973
|
-
}
|
|
2974
|
-
buildUpdateQuery({ table, set, where, returning, withList, from, joins }) {
|
|
2975
|
-
const withSql = this.buildWithCTE(withList);
|
|
2976
|
-
const tableName = table[PgTable.Symbol.Name];
|
|
2977
|
-
const tableSchema = table[PgTable.Symbol.Schema];
|
|
2978
|
-
const origTableName = table[PgTable.Symbol.OriginalName];
|
|
2979
|
-
const alias = tableName === origTableName ? undefined : tableName;
|
|
2980
|
-
const tableSql = sql`${tableSchema ? sql`${sql.identifier(tableSchema)}.` : undefined}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}`;
|
|
2981
|
-
const setSql = this.buildUpdateSet(table, set);
|
|
2982
|
-
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
|
2983
|
-
const joinsSql = this.buildJoins(joins);
|
|
2984
|
-
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: !from })}` : undefined;
|
|
2985
|
-
const whereSql = where ? sql` where ${where}` : undefined;
|
|
2986
|
-
return sql`${withSql}update ${tableSql} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}`;
|
|
2987
|
-
}
|
|
2988
|
-
buildSelection(fields, { isSingleTable = false } = {}) {
|
|
2989
|
-
const columnsLen = fields.length;
|
|
2990
|
-
const chunks = fields.flatMap(({ field }, i) => {
|
|
2991
|
-
const chunk = [];
|
|
2992
|
-
if (is(field, SQL.Aliased) && field.isSelectionField) {
|
|
2993
|
-
chunk.push(sql.identifier(field.fieldAlias));
|
|
2994
|
-
} else if (is(field, SQL.Aliased) || is(field, SQL)) {
|
|
2995
|
-
const query = is(field, SQL.Aliased) ? field.sql : field;
|
|
2996
|
-
if (isSingleTable) {
|
|
2997
|
-
chunk.push(new SQL(query.queryChunks.map((c) => {
|
|
2998
|
-
if (is(c, PgColumn)) {
|
|
2999
|
-
return sql.identifier(this.casing.getColumnCasing(c));
|
|
3000
|
-
}
|
|
3001
|
-
return c;
|
|
3002
|
-
})));
|
|
3003
|
-
} else {
|
|
3004
|
-
chunk.push(query);
|
|
3005
|
-
}
|
|
3006
|
-
if (is(field, SQL.Aliased)) {
|
|
3007
|
-
chunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);
|
|
3008
|
-
}
|
|
3009
|
-
} else if (is(field, Column)) {
|
|
3010
|
-
if (isSingleTable) {
|
|
3011
|
-
chunk.push(sql.identifier(this.casing.getColumnCasing(field)));
|
|
3012
|
-
} else {
|
|
3013
|
-
chunk.push(field);
|
|
3014
|
-
}
|
|
3015
|
-
} else if (is(field, Subquery)) {
|
|
3016
|
-
const entries = Object.entries(field._.selectedFields);
|
|
3017
|
-
if (entries.length === 1) {
|
|
3018
|
-
const entry = entries[0][1];
|
|
3019
|
-
const fieldDecoder = is(entry, SQL) ? entry.decoder : is(entry, Column) ? { mapFromDriverValue: (v) => entry.mapFromDriverValue(v) } : entry.sql.decoder;
|
|
3020
|
-
if (fieldDecoder) {
|
|
3021
|
-
field._.sql.decoder = fieldDecoder;
|
|
3022
|
-
}
|
|
3023
|
-
}
|
|
3024
|
-
chunk.push(field);
|
|
3025
|
-
}
|
|
3026
|
-
if (i < columnsLen - 1) {
|
|
3027
|
-
chunk.push(sql`, `);
|
|
3028
|
-
}
|
|
3029
|
-
return chunk;
|
|
3030
|
-
});
|
|
3031
|
-
return sql.join(chunks);
|
|
3032
|
-
}
|
|
3033
|
-
buildJoins(joins) {
|
|
3034
|
-
if (!joins || joins.length === 0) {
|
|
3035
|
-
return;
|
|
3036
|
-
}
|
|
3037
|
-
const joinsArray = [];
|
|
3038
|
-
for (const [index2, joinMeta] of joins.entries()) {
|
|
3039
|
-
if (index2 === 0) {
|
|
3040
|
-
joinsArray.push(sql` `);
|
|
3041
|
-
}
|
|
3042
|
-
const table = joinMeta.table;
|
|
3043
|
-
const lateralSql = joinMeta.lateral ? sql` lateral` : undefined;
|
|
3044
|
-
const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : undefined;
|
|
3045
|
-
if (is(table, PgTable)) {
|
|
3046
|
-
const tableName = table[PgTable.Symbol.Name];
|
|
3047
|
-
const tableSchema = table[PgTable.Symbol.Schema];
|
|
3048
|
-
const origTableName = table[PgTable.Symbol.OriginalName];
|
|
3049
|
-
const alias = tableName === origTableName ? undefined : joinMeta.alias;
|
|
3050
|
-
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : undefined}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
|
|
3051
|
-
} else if (is(table, View)) {
|
|
3052
|
-
const viewName = table[ViewBaseConfig].name;
|
|
3053
|
-
const viewSchema = table[ViewBaseConfig].schema;
|
|
3054
|
-
const origViewName = table[ViewBaseConfig].originalName;
|
|
3055
|
-
const alias = viewName === origViewName ? undefined : joinMeta.alias;
|
|
3056
|
-
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${viewSchema ? sql`${sql.identifier(viewSchema)}.` : undefined}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
|
|
3057
|
-
} else {
|
|
3058
|
-
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table}${onSql}`);
|
|
3059
|
-
}
|
|
3060
|
-
if (index2 < joins.length - 1) {
|
|
3061
|
-
joinsArray.push(sql` `);
|
|
3062
|
-
}
|
|
3063
|
-
}
|
|
3064
|
-
return sql.join(joinsArray);
|
|
3065
|
-
}
|
|
3066
|
-
buildFromTable(table) {
|
|
3067
|
-
if (is(table, Table) && table[Table.Symbol.IsAlias]) {
|
|
3068
|
-
let fullName = sql`${sql.identifier(table[Table.Symbol.OriginalName])}`;
|
|
3069
|
-
if (table[Table.Symbol.Schema]) {
|
|
3070
|
-
fullName = sql`${sql.identifier(table[Table.Symbol.Schema])}.${fullName}`;
|
|
3071
|
-
}
|
|
3072
|
-
return sql`${fullName} ${sql.identifier(table[Table.Symbol.Name])}`;
|
|
3073
|
-
}
|
|
3074
|
-
return table;
|
|
3075
|
-
}
|
|
3076
|
-
buildSelectQuery({
|
|
3077
|
-
withList,
|
|
3078
|
-
fields,
|
|
3079
|
-
fieldsFlat,
|
|
3080
|
-
where,
|
|
3081
|
-
having,
|
|
3082
|
-
table,
|
|
3083
|
-
joins,
|
|
3084
|
-
orderBy,
|
|
3085
|
-
groupBy,
|
|
3086
|
-
limit,
|
|
3087
|
-
offset,
|
|
3088
|
-
lockingClause,
|
|
3089
|
-
distinct,
|
|
3090
|
-
setOperators
|
|
3091
|
-
}) {
|
|
3092
|
-
const fieldsList = fieldsFlat ?? orderSelectedFields(fields);
|
|
3093
|
-
for (const f of fieldsList) {
|
|
3094
|
-
if (is(f.field, Column) && getTableName(f.field.table) !== (is(table, Subquery) ? table._.alias : is(table, PgViewBase) ? table[ViewBaseConfig].name : is(table, SQL) ? undefined : getTableName(table)) && !((table2) => joins?.some(({ alias }) => alias === (table2[Table.Symbol.IsAlias] ? getTableName(table2) : table2[Table.Symbol.BaseName])))(f.field.table)) {
|
|
3095
|
-
const tableName = getTableName(f.field.table);
|
|
3096
|
-
throw new Error(`Your "${f.path.join("->")}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?`);
|
|
3097
|
-
}
|
|
3098
|
-
}
|
|
3099
|
-
const isSingleTable = !joins || joins.length === 0;
|
|
3100
|
-
const withSql = this.buildWithCTE(withList);
|
|
3101
|
-
let distinctSql;
|
|
3102
|
-
if (distinct) {
|
|
3103
|
-
distinctSql = distinct === true ? sql` distinct` : sql` distinct on (${sql.join(distinct.on, sql`, `)})`;
|
|
3104
|
-
}
|
|
3105
|
-
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
|
3106
|
-
const tableSql = this.buildFromTable(table);
|
|
3107
|
-
const joinsSql = this.buildJoins(joins);
|
|
3108
|
-
const whereSql = where ? sql` where ${where}` : undefined;
|
|
3109
|
-
const havingSql = having ? sql` having ${having}` : undefined;
|
|
3110
|
-
let orderBySql;
|
|
3111
|
-
if (orderBy && orderBy.length > 0) {
|
|
3112
|
-
orderBySql = sql` order by ${sql.join(orderBy, sql`, `)}`;
|
|
3113
|
-
}
|
|
3114
|
-
let groupBySql;
|
|
3115
|
-
if (groupBy && groupBy.length > 0) {
|
|
3116
|
-
groupBySql = sql` group by ${sql.join(groupBy, sql`, `)}`;
|
|
3117
|
-
}
|
|
3118
|
-
const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : undefined;
|
|
3119
|
-
const offsetSql = offset ? sql` offset ${offset}` : undefined;
|
|
3120
|
-
const lockingClauseSql = sql.empty();
|
|
3121
|
-
if (lockingClause) {
|
|
3122
|
-
const clauseSql = sql` for ${sql.raw(lockingClause.strength)}`;
|
|
3123
|
-
if (lockingClause.config.of) {
|
|
3124
|
-
clauseSql.append(sql` of ${sql.join(Array.isArray(lockingClause.config.of) ? lockingClause.config.of : [lockingClause.config.of], sql`, `)}`);
|
|
3125
|
-
}
|
|
3126
|
-
if (lockingClause.config.noWait) {
|
|
3127
|
-
clauseSql.append(sql` nowait`);
|
|
3128
|
-
} else if (lockingClause.config.skipLocked) {
|
|
3129
|
-
clauseSql.append(sql` skip locked`);
|
|
3130
|
-
}
|
|
3131
|
-
lockingClauseSql.append(clauseSql);
|
|
3132
|
-
}
|
|
3133
|
-
const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClauseSql}`;
|
|
3134
|
-
if (setOperators.length > 0) {
|
|
3135
|
-
return this.buildSetOperations(finalQuery, setOperators);
|
|
3136
|
-
}
|
|
3137
|
-
return finalQuery;
|
|
3138
|
-
}
|
|
3139
|
-
buildSetOperations(leftSelect, setOperators) {
|
|
3140
|
-
const [setOperator, ...rest] = setOperators;
|
|
3141
|
-
if (!setOperator) {
|
|
3142
|
-
throw new Error("Cannot pass undefined values to any set operator");
|
|
3143
|
-
}
|
|
3144
|
-
if (rest.length === 0) {
|
|
3145
|
-
return this.buildSetOperationQuery({ leftSelect, setOperator });
|
|
3146
|
-
}
|
|
3147
|
-
return this.buildSetOperations(this.buildSetOperationQuery({ leftSelect, setOperator }), rest);
|
|
3148
|
-
}
|
|
3149
|
-
buildSetOperationQuery({
|
|
3150
|
-
leftSelect,
|
|
3151
|
-
setOperator: { type, isAll, rightSelect, limit, orderBy, offset }
|
|
3152
|
-
}) {
|
|
3153
|
-
const leftChunk = sql`(${leftSelect.getSQL()}) `;
|
|
3154
|
-
const rightChunk = sql`(${rightSelect.getSQL()})`;
|
|
3155
|
-
let orderBySql;
|
|
3156
|
-
if (orderBy && orderBy.length > 0) {
|
|
3157
|
-
const orderByValues = [];
|
|
3158
|
-
for (const singleOrderBy of orderBy) {
|
|
3159
|
-
if (is(singleOrderBy, PgColumn)) {
|
|
3160
|
-
orderByValues.push(sql.identifier(singleOrderBy.name));
|
|
3161
|
-
} else if (is(singleOrderBy, SQL)) {
|
|
3162
|
-
for (let i = 0;i < singleOrderBy.queryChunks.length; i++) {
|
|
3163
|
-
const chunk = singleOrderBy.queryChunks[i];
|
|
3164
|
-
if (is(chunk, PgColumn)) {
|
|
3165
|
-
singleOrderBy.queryChunks[i] = sql.identifier(chunk.name);
|
|
3166
|
-
}
|
|
3167
|
-
}
|
|
3168
|
-
orderByValues.push(sql`${singleOrderBy}`);
|
|
3169
|
-
} else {
|
|
3170
|
-
orderByValues.push(sql`${singleOrderBy}`);
|
|
3171
|
-
}
|
|
3172
|
-
}
|
|
3173
|
-
orderBySql = sql` order by ${sql.join(orderByValues, sql`, `)} `;
|
|
3174
|
-
}
|
|
3175
|
-
const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : undefined;
|
|
3176
|
-
const operatorChunk = sql.raw(`${type} ${isAll ? "all " : ""}`);
|
|
3177
|
-
const offsetSql = offset ? sql` offset ${offset}` : undefined;
|
|
3178
|
-
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
|
3179
|
-
}
|
|
3180
|
-
buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select, overridingSystemValue_ }) {
|
|
3181
|
-
const valuesSqlList = [];
|
|
3182
|
-
const columns = table[Table.Symbol.Columns];
|
|
3183
|
-
const colEntries = Object.entries(columns).filter(([_, col]) => !col.shouldDisableInsert());
|
|
3184
|
-
const insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));
|
|
3185
|
-
if (select) {
|
|
3186
|
-
const select2 = valuesOrSelect;
|
|
3187
|
-
if (is(select2, SQL)) {
|
|
3188
|
-
valuesSqlList.push(select2);
|
|
3189
|
-
} else {
|
|
3190
|
-
valuesSqlList.push(select2.getSQL());
|
|
3191
|
-
}
|
|
3192
|
-
} else {
|
|
3193
|
-
const values = valuesOrSelect;
|
|
3194
|
-
valuesSqlList.push(sql.raw("values "));
|
|
3195
|
-
for (const [valueIndex, value] of values.entries()) {
|
|
3196
|
-
const valueList = [];
|
|
3197
|
-
for (const [fieldName, col] of colEntries) {
|
|
3198
|
-
const colValue = value[fieldName];
|
|
3199
|
-
if (colValue === undefined || is(colValue, Param) && colValue.value === undefined) {
|
|
3200
|
-
if (col.defaultFn !== undefined) {
|
|
3201
|
-
const defaultFnResult = col.defaultFn();
|
|
3202
|
-
const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
|
3203
|
-
valueList.push(defaultValue);
|
|
3204
|
-
} else if (!col.default && col.onUpdateFn !== undefined) {
|
|
3205
|
-
const onUpdateFnResult = col.onUpdateFn();
|
|
3206
|
-
const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
|
3207
|
-
valueList.push(newValue);
|
|
3208
|
-
} else {
|
|
3209
|
-
valueList.push(sql`default`);
|
|
3210
|
-
}
|
|
3211
|
-
} else {
|
|
3212
|
-
valueList.push(colValue);
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
valuesSqlList.push(valueList);
|
|
3216
|
-
if (valueIndex < values.length - 1) {
|
|
3217
|
-
valuesSqlList.push(sql`, `);
|
|
3218
|
-
}
|
|
3219
|
-
}
|
|
3220
|
-
}
|
|
3221
|
-
const withSql = this.buildWithCTE(withList);
|
|
3222
|
-
const valuesSql = sql.join(valuesSqlList);
|
|
3223
|
-
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : undefined;
|
|
3224
|
-
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : undefined;
|
|
3225
|
-
const overridingSql = overridingSystemValue_ === true ? sql`overriding system value ` : undefined;
|
|
3226
|
-
return sql`${withSql}insert into ${table} ${insertOrder} ${overridingSql}${valuesSql}${onConflictSql}${returningSql}`;
|
|
3227
|
-
}
|
|
3228
|
-
buildRefreshMaterializedViewQuery({ view, concurrently, withNoData }) {
|
|
3229
|
-
const concurrentlySql = concurrently ? sql` concurrently` : undefined;
|
|
3230
|
-
const withNoDataSql = withNoData ? sql` with no data` : undefined;
|
|
3231
|
-
return sql`refresh materialized view${concurrentlySql} ${view}${withNoDataSql}`;
|
|
3232
|
-
}
|
|
3233
|
-
prepareTyping(encoder) {
|
|
3234
|
-
if (is(encoder, PgJsonb) || is(encoder, PgJson)) {
|
|
3235
|
-
return "json";
|
|
3236
|
-
} else if (is(encoder, PgNumeric)) {
|
|
3237
|
-
return "decimal";
|
|
3238
|
-
} else if (is(encoder, PgTime)) {
|
|
3239
|
-
return "time";
|
|
3240
|
-
} else if (is(encoder, PgTimestamp) || is(encoder, PgTimestampString)) {
|
|
3241
|
-
return "timestamp";
|
|
3242
|
-
} else if (is(encoder, PgDate) || is(encoder, PgDateString)) {
|
|
3243
|
-
return "date";
|
|
3244
|
-
} else if (is(encoder, PgUUID)) {
|
|
3245
|
-
return "uuid";
|
|
3246
|
-
} else {
|
|
3247
|
-
return "none";
|
|
3248
|
-
}
|
|
3249
|
-
}
|
|
3250
|
-
sqlToQuery(sql2, invokeSource) {
|
|
3251
|
-
return sql2.toQuery({
|
|
3252
|
-
casing: this.casing,
|
|
3253
|
-
escapeName: this.escapeName,
|
|
3254
|
-
escapeParam: this.escapeParam,
|
|
3255
|
-
escapeString: this.escapeString,
|
|
3256
|
-
prepareTyping: this.prepareTyping,
|
|
3257
|
-
invokeSource
|
|
3258
|
-
});
|
|
3259
|
-
}
|
|
3260
|
-
buildRelationalQueryWithoutPK({
|
|
3261
|
-
fullSchema,
|
|
3262
|
-
schema,
|
|
3263
|
-
tableNamesMap,
|
|
3264
|
-
table,
|
|
3265
|
-
tableConfig,
|
|
3266
|
-
queryConfig: config,
|
|
3267
|
-
tableAlias,
|
|
3268
|
-
nestedQueryRelation,
|
|
3269
|
-
joinOn
|
|
3270
|
-
}) {
|
|
3271
|
-
let selection = [];
|
|
3272
|
-
let limit, offset, orderBy = [], where;
|
|
3273
|
-
const joins = [];
|
|
3274
|
-
if (config === true) {
|
|
3275
|
-
const selectionEntries = Object.entries(tableConfig.columns);
|
|
3276
|
-
selection = selectionEntries.map(([key, value]) => ({
|
|
3277
|
-
dbKey: value.name,
|
|
3278
|
-
tsKey: key,
|
|
3279
|
-
field: aliasedTableColumn(value, tableAlias),
|
|
3280
|
-
relationTableTsKey: undefined,
|
|
3281
|
-
isJson: false,
|
|
3282
|
-
selection: []
|
|
3283
|
-
}));
|
|
3284
|
-
} else {
|
|
3285
|
-
const aliasedColumns = Object.fromEntries(Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]));
|
|
3286
|
-
if (config.where) {
|
|
3287
|
-
const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, getOperators()) : config.where;
|
|
3288
|
-
where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
|
|
3289
|
-
}
|
|
3290
|
-
const fieldsSelection = [];
|
|
3291
|
-
let selectedColumns = [];
|
|
3292
|
-
if (config.columns) {
|
|
3293
|
-
let isIncludeMode = false;
|
|
3294
|
-
for (const [field, value] of Object.entries(config.columns)) {
|
|
3295
|
-
if (value === undefined) {
|
|
3296
|
-
continue;
|
|
3297
|
-
}
|
|
3298
|
-
if (field in tableConfig.columns) {
|
|
3299
|
-
if (!isIncludeMode && value === true) {
|
|
3300
|
-
isIncludeMode = true;
|
|
3301
|
-
}
|
|
3302
|
-
selectedColumns.push(field);
|
|
3303
|
-
}
|
|
3304
|
-
}
|
|
3305
|
-
if (selectedColumns.length > 0) {
|
|
3306
|
-
selectedColumns = isIncludeMode ? selectedColumns.filter((c) => config.columns?.[c] === true) : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
|
|
3307
|
-
}
|
|
3308
|
-
} else {
|
|
3309
|
-
selectedColumns = Object.keys(tableConfig.columns);
|
|
3310
|
-
}
|
|
3311
|
-
for (const field of selectedColumns) {
|
|
3312
|
-
const column = tableConfig.columns[field];
|
|
3313
|
-
fieldsSelection.push({ tsKey: field, value: column });
|
|
3314
|
-
}
|
|
3315
|
-
let selectedRelations = [];
|
|
3316
|
-
if (config.with) {
|
|
3317
|
-
selectedRelations = Object.entries(config.with).filter((entry) => !!entry[1]).map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey] }));
|
|
3318
|
-
}
|
|
3319
|
-
let extras;
|
|
3320
|
-
if (config.extras) {
|
|
3321
|
-
extras = typeof config.extras === "function" ? config.extras(aliasedColumns, { sql }) : config.extras;
|
|
3322
|
-
for (const [tsKey, value] of Object.entries(extras)) {
|
|
3323
|
-
fieldsSelection.push({
|
|
3324
|
-
tsKey,
|
|
3325
|
-
value: mapColumnsInAliasedSQLToAlias(value, tableAlias)
|
|
3326
|
-
});
|
|
3327
|
-
}
|
|
3328
|
-
}
|
|
3329
|
-
for (const { tsKey, value } of fieldsSelection) {
|
|
3330
|
-
selection.push({
|
|
3331
|
-
dbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey].name,
|
|
3332
|
-
tsKey,
|
|
3333
|
-
field: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,
|
|
3334
|
-
relationTableTsKey: undefined,
|
|
3335
|
-
isJson: false,
|
|
3336
|
-
selection: []
|
|
3337
|
-
});
|
|
3338
|
-
}
|
|
3339
|
-
let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, getOrderByOperators()) : config.orderBy ?? [];
|
|
3340
|
-
if (!Array.isArray(orderByOrig)) {
|
|
3341
|
-
orderByOrig = [orderByOrig];
|
|
3342
|
-
}
|
|
3343
|
-
orderBy = orderByOrig.map((orderByValue) => {
|
|
3344
|
-
if (is(orderByValue, Column)) {
|
|
3345
|
-
return aliasedTableColumn(orderByValue, tableAlias);
|
|
3346
|
-
}
|
|
3347
|
-
return mapColumnsInSQLToAlias(orderByValue, tableAlias);
|
|
3348
|
-
});
|
|
3349
|
-
limit = config.limit;
|
|
3350
|
-
offset = config.offset;
|
|
3351
|
-
for (const {
|
|
3352
|
-
tsKey: selectedRelationTsKey,
|
|
3353
|
-
queryConfig: selectedRelationConfigValue,
|
|
3354
|
-
relation
|
|
3355
|
-
} of selectedRelations) {
|
|
3356
|
-
const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
|
|
3357
|
-
const relationTableName = getTableUniqueName(relation.referencedTable);
|
|
3358
|
-
const relationTableTsName = tableNamesMap[relationTableName];
|
|
3359
|
-
const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
|
|
3360
|
-
const joinOn2 = and(...normalizedRelation.fields.map((field2, i) => eq(aliasedTableColumn(normalizedRelation.references[i], relationTableAlias), aliasedTableColumn(field2, tableAlias))));
|
|
3361
|
-
const builtRelation = this.buildRelationalQueryWithoutPK({
|
|
3362
|
-
fullSchema,
|
|
3363
|
-
schema,
|
|
3364
|
-
tableNamesMap,
|
|
3365
|
-
table: fullSchema[relationTableTsName],
|
|
3366
|
-
tableConfig: schema[relationTableTsName],
|
|
3367
|
-
queryConfig: is(relation, One) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue,
|
|
3368
|
-
tableAlias: relationTableAlias,
|
|
3369
|
-
joinOn: joinOn2,
|
|
3370
|
-
nestedQueryRelation: relation
|
|
3371
|
-
});
|
|
3372
|
-
const field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier("data")}`.as(selectedRelationTsKey);
|
|
3373
|
-
joins.push({
|
|
3374
|
-
on: sql`true`,
|
|
3375
|
-
table: new Subquery(builtRelation.sql, {}, relationTableAlias),
|
|
3376
|
-
alias: relationTableAlias,
|
|
3377
|
-
joinType: "left",
|
|
3378
|
-
lateral: true
|
|
3379
|
-
});
|
|
3380
|
-
selection.push({
|
|
3381
|
-
dbKey: selectedRelationTsKey,
|
|
3382
|
-
tsKey: selectedRelationTsKey,
|
|
3383
|
-
field,
|
|
3384
|
-
relationTableTsKey: relationTableTsName,
|
|
3385
|
-
isJson: true,
|
|
3386
|
-
selection: builtRelation.selection
|
|
3387
|
-
});
|
|
3388
|
-
}
|
|
3389
|
-
}
|
|
3390
|
-
if (selection.length === 0) {
|
|
3391
|
-
throw new DrizzleError({ message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")` });
|
|
3392
|
-
}
|
|
3393
|
-
let result;
|
|
3394
|
-
where = and(joinOn, where);
|
|
3395
|
-
if (nestedQueryRelation) {
|
|
3396
|
-
let field = sql`json_build_array(${sql.join(selection.map(({ field: field2, tsKey, isJson }) => isJson ? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier("data")}` : is(field2, SQL.Aliased) ? field2.sql : field2), sql`, `)})`;
|
|
3397
|
-
if (is(nestedQueryRelation, Many)) {
|
|
3398
|
-
field = sql`coalesce(json_agg(${field}${orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : undefined}), '[]'::json)`;
|
|
3399
|
-
}
|
|
3400
|
-
const nestedSelection = [{
|
|
3401
|
-
dbKey: "data",
|
|
3402
|
-
tsKey: "data",
|
|
3403
|
-
field: field.as("data"),
|
|
3404
|
-
isJson: true,
|
|
3405
|
-
relationTableTsKey: tableConfig.tsName,
|
|
3406
|
-
selection
|
|
3407
|
-
}];
|
|
3408
|
-
const needsSubquery = limit !== undefined || offset !== undefined || orderBy.length > 0;
|
|
3409
|
-
if (needsSubquery) {
|
|
3410
|
-
result = this.buildSelectQuery({
|
|
3411
|
-
table: aliasedTable(table, tableAlias),
|
|
3412
|
-
fields: {},
|
|
3413
|
-
fieldsFlat: [{
|
|
3414
|
-
path: [],
|
|
3415
|
-
field: sql.raw("*")
|
|
3416
|
-
}],
|
|
3417
|
-
where,
|
|
3418
|
-
limit,
|
|
3419
|
-
offset,
|
|
3420
|
-
orderBy,
|
|
3421
|
-
setOperators: []
|
|
3422
|
-
});
|
|
3423
|
-
where = undefined;
|
|
3424
|
-
limit = undefined;
|
|
3425
|
-
offset = undefined;
|
|
3426
|
-
orderBy = [];
|
|
3427
|
-
} else {
|
|
3428
|
-
result = aliasedTable(table, tableAlias);
|
|
3429
|
-
}
|
|
3430
|
-
result = this.buildSelectQuery({
|
|
3431
|
-
table: is(result, PgTable) ? result : new Subquery(result, {}, tableAlias),
|
|
3432
|
-
fields: {},
|
|
3433
|
-
fieldsFlat: nestedSelection.map(({ field: field2 }) => ({
|
|
3434
|
-
path: [],
|
|
3435
|
-
field: is(field2, Column) ? aliasedTableColumn(field2, tableAlias) : field2
|
|
3436
|
-
})),
|
|
3437
|
-
joins,
|
|
3438
|
-
where,
|
|
3439
|
-
limit,
|
|
3440
|
-
offset,
|
|
3441
|
-
orderBy,
|
|
3442
|
-
setOperators: []
|
|
3443
|
-
});
|
|
3444
|
-
} else {
|
|
3445
|
-
result = this.buildSelectQuery({
|
|
3446
|
-
table: aliasedTable(table, tableAlias),
|
|
3447
|
-
fields: {},
|
|
3448
|
-
fieldsFlat: selection.map(({ field }) => ({
|
|
3449
|
-
path: [],
|
|
3450
|
-
field: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field
|
|
3451
|
-
})),
|
|
3452
|
-
joins,
|
|
3453
|
-
where,
|
|
3454
|
-
limit,
|
|
3455
|
-
offset,
|
|
3456
|
-
orderBy,
|
|
3457
|
-
setOperators: []
|
|
3458
|
-
});
|
|
3459
|
-
}
|
|
3460
|
-
return {
|
|
3461
|
-
tableTsKey: tableConfig.tsName,
|
|
3462
|
-
sql: result,
|
|
3463
|
-
selection
|
|
3464
|
-
};
|
|
3465
|
-
}
|
|
3466
|
-
}
|
|
3467
|
-
|
|
3468
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/query-builders/query-builder.js
|
|
3469
|
-
class TypedQueryBuilder {
|
|
3470
|
-
static [entityKind] = "TypedQueryBuilder";
|
|
3471
|
-
getSelectedFields() {
|
|
3472
|
-
return this._.selectedFields;
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
|
|
3476
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/query-builders/select.js
|
|
3477
|
-
class PgSelectBuilder {
|
|
3478
|
-
static [entityKind] = "PgSelectBuilder";
|
|
3479
|
-
fields;
|
|
3480
|
-
session;
|
|
3481
|
-
dialect;
|
|
3482
|
-
withList = [];
|
|
3483
|
-
distinct;
|
|
3484
|
-
constructor(config) {
|
|
3485
|
-
this.fields = config.fields;
|
|
3486
|
-
this.session = config.session;
|
|
3487
|
-
this.dialect = config.dialect;
|
|
3488
|
-
if (config.withList) {
|
|
3489
|
-
this.withList = config.withList;
|
|
3490
|
-
}
|
|
3491
|
-
this.distinct = config.distinct;
|
|
3492
|
-
}
|
|
3493
|
-
authToken;
|
|
3494
|
-
setToken(token) {
|
|
3495
|
-
this.authToken = token;
|
|
3496
|
-
return this;
|
|
3497
|
-
}
|
|
3498
|
-
from(source) {
|
|
3499
|
-
const isPartialSelect = !!this.fields;
|
|
3500
|
-
const src = source;
|
|
3501
|
-
let fields;
|
|
3502
|
-
if (this.fields) {
|
|
3503
|
-
fields = this.fields;
|
|
3504
|
-
} else if (is(src, Subquery)) {
|
|
3505
|
-
fields = Object.fromEntries(Object.keys(src._.selectedFields).map((key) => [key, src[key]]));
|
|
3506
|
-
} else if (is(src, PgViewBase)) {
|
|
3507
|
-
fields = src[ViewBaseConfig].selectedFields;
|
|
3508
|
-
} else if (is(src, SQL)) {
|
|
3509
|
-
fields = {};
|
|
3510
|
-
} else {
|
|
3511
|
-
fields = getTableColumns(src);
|
|
3512
|
-
}
|
|
3513
|
-
return new PgSelectBase({
|
|
3514
|
-
table: src,
|
|
3515
|
-
fields,
|
|
3516
|
-
isPartialSelect,
|
|
3517
|
-
session: this.session,
|
|
3518
|
-
dialect: this.dialect,
|
|
3519
|
-
withList: this.withList,
|
|
3520
|
-
distinct: this.distinct
|
|
3521
|
-
}).setToken(this.authToken);
|
|
3522
|
-
}
|
|
3523
|
-
}
|
|
3524
|
-
|
|
3525
|
-
class PgSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
3526
|
-
static [entityKind] = "PgSelectQueryBuilder";
|
|
3527
|
-
_;
|
|
3528
|
-
config;
|
|
3529
|
-
joinsNotNullableMap;
|
|
3530
|
-
tableName;
|
|
3531
|
-
isPartialSelect;
|
|
3532
|
-
session;
|
|
3533
|
-
dialect;
|
|
3534
|
-
cacheConfig = undefined;
|
|
3535
|
-
usedTables = /* @__PURE__ */ new Set;
|
|
3536
|
-
constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
|
|
3537
|
-
super();
|
|
3538
|
-
this.config = {
|
|
3539
|
-
withList,
|
|
3540
|
-
table,
|
|
3541
|
-
fields: { ...fields },
|
|
3542
|
-
distinct,
|
|
3543
|
-
setOperators: []
|
|
3544
|
-
};
|
|
3545
|
-
this.isPartialSelect = isPartialSelect;
|
|
3546
|
-
this.session = session;
|
|
3547
|
-
this.dialect = dialect;
|
|
3548
|
-
this._ = {
|
|
3549
|
-
selectedFields: fields,
|
|
3550
|
-
config: this.config
|
|
3551
|
-
};
|
|
3552
|
-
this.tableName = getTableLikeName(table);
|
|
3553
|
-
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
|
3554
|
-
for (const item of extractUsedTable(table))
|
|
3555
|
-
this.usedTables.add(item);
|
|
3556
|
-
}
|
|
3557
|
-
getUsedTables() {
|
|
3558
|
-
return [...this.usedTables];
|
|
3559
|
-
}
|
|
3560
|
-
createJoin(joinType, lateral) {
|
|
3561
|
-
return (table, on) => {
|
|
3562
|
-
const baseTableName = this.tableName;
|
|
3563
|
-
const tableName = getTableLikeName(table);
|
|
3564
|
-
for (const item of extractUsedTable(table))
|
|
3565
|
-
this.usedTables.add(item);
|
|
3566
|
-
if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
|
|
3567
|
-
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
3568
|
-
}
|
|
3569
|
-
if (!this.isPartialSelect) {
|
|
3570
|
-
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") {
|
|
3571
|
-
this.config.fields = {
|
|
3572
|
-
[baseTableName]: this.config.fields
|
|
3573
|
-
};
|
|
3574
|
-
}
|
|
3575
|
-
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
3576
|
-
const selection = is(table, Subquery) ? table._.selectedFields : is(table, View) ? table[ViewBaseConfig].selectedFields : table[Table.Symbol.Columns];
|
|
3577
|
-
this.config.fields[tableName] = selection;
|
|
3578
|
-
}
|
|
3579
|
-
}
|
|
3580
|
-
if (typeof on === "function") {
|
|
3581
|
-
on = on(new Proxy(this.config.fields, new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })));
|
|
3582
|
-
}
|
|
3583
|
-
if (!this.config.joins) {
|
|
3584
|
-
this.config.joins = [];
|
|
3585
|
-
}
|
|
3586
|
-
this.config.joins.push({ on, table, joinType, alias: tableName, lateral });
|
|
3587
|
-
if (typeof tableName === "string") {
|
|
3588
|
-
switch (joinType) {
|
|
3589
|
-
case "left": {
|
|
3590
|
-
this.joinsNotNullableMap[tableName] = false;
|
|
3591
|
-
break;
|
|
3592
|
-
}
|
|
3593
|
-
case "right": {
|
|
3594
|
-
this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
|
|
3595
|
-
this.joinsNotNullableMap[tableName] = true;
|
|
3596
|
-
break;
|
|
3597
|
-
}
|
|
3598
|
-
case "cross":
|
|
3599
|
-
case "inner": {
|
|
3600
|
-
this.joinsNotNullableMap[tableName] = true;
|
|
3601
|
-
break;
|
|
3602
|
-
}
|
|
3603
|
-
case "full": {
|
|
3604
|
-
this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
|
|
3605
|
-
this.joinsNotNullableMap[tableName] = false;
|
|
3606
|
-
break;
|
|
3607
|
-
}
|
|
3608
|
-
}
|
|
3609
|
-
}
|
|
3610
|
-
return this;
|
|
3611
|
-
};
|
|
3612
|
-
}
|
|
3613
|
-
leftJoin = this.createJoin("left", false);
|
|
3614
|
-
leftJoinLateral = this.createJoin("left", true);
|
|
3615
|
-
rightJoin = this.createJoin("right", false);
|
|
3616
|
-
innerJoin = this.createJoin("inner", false);
|
|
3617
|
-
innerJoinLateral = this.createJoin("inner", true);
|
|
3618
|
-
fullJoin = this.createJoin("full", false);
|
|
3619
|
-
crossJoin = this.createJoin("cross", false);
|
|
3620
|
-
crossJoinLateral = this.createJoin("cross", true);
|
|
3621
|
-
createSetOperator(type, isAll) {
|
|
3622
|
-
return (rightSelection) => {
|
|
3623
|
-
const rightSelect = typeof rightSelection === "function" ? rightSelection(getPgSetOperators()) : rightSelection;
|
|
3624
|
-
if (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {
|
|
3625
|
-
throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");
|
|
3626
|
-
}
|
|
3627
|
-
this.config.setOperators.push({ type, isAll, rightSelect });
|
|
3628
|
-
return this;
|
|
3629
|
-
};
|
|
3630
|
-
}
|
|
3631
|
-
union = this.createSetOperator("union", false);
|
|
3632
|
-
unionAll = this.createSetOperator("union", true);
|
|
3633
|
-
intersect = this.createSetOperator("intersect", false);
|
|
3634
|
-
intersectAll = this.createSetOperator("intersect", true);
|
|
3635
|
-
except = this.createSetOperator("except", false);
|
|
3636
|
-
exceptAll = this.createSetOperator("except", true);
|
|
3637
|
-
addSetOperators(setOperators) {
|
|
3638
|
-
this.config.setOperators.push(...setOperators);
|
|
3639
|
-
return this;
|
|
3640
|
-
}
|
|
3641
|
-
where(where) {
|
|
3642
|
-
if (typeof where === "function") {
|
|
3643
|
-
where = where(new Proxy(this.config.fields, new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })));
|
|
3644
|
-
}
|
|
3645
|
-
this.config.where = where;
|
|
3646
|
-
return this;
|
|
3647
|
-
}
|
|
3648
|
-
having(having) {
|
|
3649
|
-
if (typeof having === "function") {
|
|
3650
|
-
having = having(new Proxy(this.config.fields, new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })));
|
|
3651
|
-
}
|
|
3652
|
-
this.config.having = having;
|
|
3653
|
-
return this;
|
|
3654
|
-
}
|
|
3655
|
-
groupBy(...columns) {
|
|
3656
|
-
if (typeof columns[0] === "function") {
|
|
3657
|
-
const groupBy = columns[0](new Proxy(this.config.fields, new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })));
|
|
3658
|
-
this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
|
|
3659
|
-
} else {
|
|
3660
|
-
this.config.groupBy = columns;
|
|
3661
|
-
}
|
|
3662
|
-
return this;
|
|
3663
|
-
}
|
|
3664
|
-
orderBy(...columns) {
|
|
3665
|
-
if (typeof columns[0] === "function") {
|
|
3666
|
-
const orderBy = columns[0](new Proxy(this.config.fields, new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })));
|
|
3667
|
-
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
3668
|
-
if (this.config.setOperators.length > 0) {
|
|
3669
|
-
this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
3670
|
-
} else {
|
|
3671
|
-
this.config.orderBy = orderByArray;
|
|
3672
|
-
}
|
|
3673
|
-
} else {
|
|
3674
|
-
const orderByArray = columns;
|
|
3675
|
-
if (this.config.setOperators.length > 0) {
|
|
3676
|
-
this.config.setOperators.at(-1).orderBy = orderByArray;
|
|
3677
|
-
} else {
|
|
3678
|
-
this.config.orderBy = orderByArray;
|
|
3679
|
-
}
|
|
3680
|
-
}
|
|
3681
|
-
return this;
|
|
3682
|
-
}
|
|
3683
|
-
limit(limit) {
|
|
3684
|
-
if (this.config.setOperators.length > 0) {
|
|
3685
|
-
this.config.setOperators.at(-1).limit = limit;
|
|
3686
|
-
} else {
|
|
3687
|
-
this.config.limit = limit;
|
|
3688
|
-
}
|
|
3689
|
-
return this;
|
|
3690
|
-
}
|
|
3691
|
-
offset(offset) {
|
|
3692
|
-
if (this.config.setOperators.length > 0) {
|
|
3693
|
-
this.config.setOperators.at(-1).offset = offset;
|
|
3694
|
-
} else {
|
|
3695
|
-
this.config.offset = offset;
|
|
3696
|
-
}
|
|
3697
|
-
return this;
|
|
3698
|
-
}
|
|
3699
|
-
for(strength, config = {}) {
|
|
3700
|
-
this.config.lockingClause = { strength, config };
|
|
3701
|
-
return this;
|
|
3702
|
-
}
|
|
3703
|
-
getSQL() {
|
|
3704
|
-
return this.dialect.buildSelectQuery(this.config);
|
|
3705
|
-
}
|
|
3706
|
-
toSQL() {
|
|
3707
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
3708
|
-
return rest;
|
|
3709
|
-
}
|
|
3710
|
-
as(alias) {
|
|
3711
|
-
const usedTables = [];
|
|
3712
|
-
usedTables.push(...extractUsedTable(this.config.table));
|
|
3713
|
-
if (this.config.joins) {
|
|
3714
|
-
for (const it of this.config.joins)
|
|
3715
|
-
usedTables.push(...extractUsedTable(it.table));
|
|
3716
|
-
}
|
|
3717
|
-
return new Proxy(new Subquery(this.getSQL(), this.config.fields, alias, false, [...new Set(usedTables)]), new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" }));
|
|
3718
|
-
}
|
|
3719
|
-
getSelectedFields() {
|
|
3720
|
-
return new Proxy(this.config.fields, new SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: "alias", sqlBehavior: "error" }));
|
|
3721
|
-
}
|
|
3722
|
-
$dynamic() {
|
|
3723
|
-
return this;
|
|
3724
|
-
}
|
|
3725
|
-
$withCache(config) {
|
|
3726
|
-
this.cacheConfig = config === undefined ? { config: {}, enable: true, autoInvalidate: true } : config === false ? { enable: false } : { enable: true, autoInvalidate: true, ...config };
|
|
3727
|
-
return this;
|
|
3728
|
-
}
|
|
3729
|
-
}
|
|
3730
|
-
|
|
3731
|
-
class PgSelectBase extends PgSelectQueryBuilderBase {
|
|
3732
|
-
static [entityKind] = "PgSelect";
|
|
3733
|
-
_prepare(name) {
|
|
3734
|
-
const { session, config, dialect, joinsNotNullableMap, authToken, cacheConfig, usedTables } = this;
|
|
3735
|
-
if (!session) {
|
|
3736
|
-
throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
|
3737
|
-
}
|
|
3738
|
-
const { fields } = config;
|
|
3739
|
-
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
|
3740
|
-
const fieldsList = orderSelectedFields(fields);
|
|
3741
|
-
const query = session.prepareQuery(dialect.sqlToQuery(this.getSQL()), fieldsList, name, true, undefined, {
|
|
3742
|
-
type: "select",
|
|
3743
|
-
tables: [...usedTables]
|
|
3744
|
-
}, cacheConfig);
|
|
3745
|
-
query.joinsNotNullableMap = joinsNotNullableMap;
|
|
3746
|
-
return query.setToken(authToken);
|
|
3747
|
-
});
|
|
3748
|
-
}
|
|
3749
|
-
prepare(name) {
|
|
3750
|
-
return this._prepare(name);
|
|
3751
|
-
}
|
|
3752
|
-
authToken;
|
|
3753
|
-
setToken(token) {
|
|
3754
|
-
this.authToken = token;
|
|
3755
|
-
return this;
|
|
3756
|
-
}
|
|
3757
|
-
execute = (placeholderValues) => {
|
|
3758
|
-
return tracer.startActiveSpan("drizzle.operation", () => {
|
|
3759
|
-
return this._prepare().execute(placeholderValues, this.authToken);
|
|
3760
|
-
});
|
|
3761
|
-
};
|
|
3762
|
-
}
|
|
3763
|
-
applyMixins(PgSelectBase, [QueryPromise]);
|
|
3764
|
-
function createSetOperator(type, isAll) {
|
|
3765
|
-
return (leftSelect, rightSelect, ...restSelects) => {
|
|
3766
|
-
const setOperators = [rightSelect, ...restSelects].map((select) => ({
|
|
3767
|
-
type,
|
|
3768
|
-
isAll,
|
|
3769
|
-
rightSelect: select
|
|
3770
|
-
}));
|
|
3771
|
-
for (const setOperator of setOperators) {
|
|
3772
|
-
if (!haveSameKeys(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {
|
|
3773
|
-
throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");
|
|
3774
|
-
}
|
|
3775
|
-
}
|
|
3776
|
-
return leftSelect.addSetOperators(setOperators);
|
|
3777
|
-
};
|
|
3778
|
-
}
|
|
3779
|
-
var getPgSetOperators = () => ({
|
|
3780
|
-
union,
|
|
3781
|
-
unionAll,
|
|
3782
|
-
intersect,
|
|
3783
|
-
intersectAll,
|
|
3784
|
-
except,
|
|
3785
|
-
exceptAll
|
|
3786
|
-
});
|
|
3787
|
-
var union = createSetOperator("union", false);
|
|
3788
|
-
var unionAll = createSetOperator("union", true);
|
|
3789
|
-
var intersect = createSetOperator("intersect", false);
|
|
3790
|
-
var intersectAll = createSetOperator("intersect", true);
|
|
3791
|
-
var except = createSetOperator("except", false);
|
|
3792
|
-
var exceptAll = createSetOperator("except", true);
|
|
3793
|
-
|
|
3794
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/query-builders/query-builder.js
|
|
3795
|
-
class QueryBuilder {
|
|
3796
|
-
static [entityKind] = "PgQueryBuilder";
|
|
3797
|
-
dialect;
|
|
3798
|
-
dialectConfig;
|
|
3799
|
-
constructor(dialect) {
|
|
3800
|
-
this.dialect = is(dialect, PgDialect) ? dialect : undefined;
|
|
3801
|
-
this.dialectConfig = is(dialect, PgDialect) ? undefined : dialect;
|
|
3802
|
-
}
|
|
3803
|
-
$with = (alias, selection) => {
|
|
3804
|
-
const queryBuilder = this;
|
|
3805
|
-
const as = (qb) => {
|
|
3806
|
-
if (typeof qb === "function") {
|
|
3807
|
-
qb = qb(queryBuilder);
|
|
3808
|
-
}
|
|
3809
|
-
return new Proxy(new WithSubquery(qb.getSQL(), selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({ alias, sqlAliasedBehavior: "alias", sqlBehavior: "error" }));
|
|
3810
|
-
};
|
|
3811
|
-
return { as };
|
|
3812
|
-
};
|
|
3813
|
-
with(...queries) {
|
|
3814
|
-
const self = this;
|
|
3815
|
-
function select(fields) {
|
|
3816
|
-
return new PgSelectBuilder({
|
|
3817
|
-
fields: fields ?? undefined,
|
|
3818
|
-
session: undefined,
|
|
3819
|
-
dialect: self.getDialect(),
|
|
3820
|
-
withList: queries
|
|
3821
|
-
});
|
|
3822
|
-
}
|
|
3823
|
-
function selectDistinct(fields) {
|
|
3824
|
-
return new PgSelectBuilder({
|
|
3825
|
-
fields: fields ?? undefined,
|
|
3826
|
-
session: undefined,
|
|
3827
|
-
dialect: self.getDialect(),
|
|
3828
|
-
distinct: true
|
|
3829
|
-
});
|
|
3830
|
-
}
|
|
3831
|
-
function selectDistinctOn(on, fields) {
|
|
3832
|
-
return new PgSelectBuilder({
|
|
3833
|
-
fields: fields ?? undefined,
|
|
3834
|
-
session: undefined,
|
|
3835
|
-
dialect: self.getDialect(),
|
|
3836
|
-
distinct: { on }
|
|
3837
|
-
});
|
|
3838
|
-
}
|
|
3839
|
-
return { select, selectDistinct, selectDistinctOn };
|
|
3840
|
-
}
|
|
3841
|
-
select(fields) {
|
|
3842
|
-
return new PgSelectBuilder({
|
|
3843
|
-
fields: fields ?? undefined,
|
|
3844
|
-
session: undefined,
|
|
3845
|
-
dialect: this.getDialect()
|
|
3846
|
-
});
|
|
3847
|
-
}
|
|
3848
|
-
selectDistinct(fields) {
|
|
3849
|
-
return new PgSelectBuilder({
|
|
3850
|
-
fields: fields ?? undefined,
|
|
3851
|
-
session: undefined,
|
|
3852
|
-
dialect: this.getDialect(),
|
|
3853
|
-
distinct: true
|
|
3854
|
-
});
|
|
3855
|
-
}
|
|
3856
|
-
selectDistinctOn(on, fields) {
|
|
3857
|
-
return new PgSelectBuilder({
|
|
3858
|
-
fields: fields ?? undefined,
|
|
3859
|
-
session: undefined,
|
|
3860
|
-
dialect: this.getDialect(),
|
|
3861
|
-
distinct: { on }
|
|
3862
|
-
});
|
|
3863
|
-
}
|
|
3864
|
-
getDialect() {
|
|
3865
|
-
if (!this.dialect) {
|
|
3866
|
-
this.dialect = new PgDialect(this.dialectConfig);
|
|
3867
|
-
}
|
|
3868
|
-
return this.dialect;
|
|
3869
|
-
}
|
|
3870
|
-
}
|
|
3871
|
-
|
|
3872
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/view.js
|
|
3873
|
-
class DefaultViewBuilderCore {
|
|
3874
|
-
constructor(name, schema) {
|
|
3875
|
-
this.name = name;
|
|
3876
|
-
this.schema = schema;
|
|
3877
|
-
}
|
|
3878
|
-
static [entityKind] = "PgDefaultViewBuilderCore";
|
|
3879
|
-
config = {};
|
|
3880
|
-
with(config) {
|
|
3881
|
-
this.config.with = config;
|
|
3882
|
-
return this;
|
|
3883
|
-
}
|
|
3884
|
-
}
|
|
3885
|
-
|
|
3886
|
-
class ViewBuilder extends DefaultViewBuilderCore {
|
|
3887
|
-
static [entityKind] = "PgViewBuilder";
|
|
3888
|
-
as(qb) {
|
|
3889
|
-
if (typeof qb === "function") {
|
|
3890
|
-
qb = qb(new QueryBuilder);
|
|
3891
|
-
}
|
|
3892
|
-
const selectionProxy = new SelectionProxyHandler({
|
|
3893
|
-
alias: this.name,
|
|
3894
|
-
sqlBehavior: "error",
|
|
3895
|
-
sqlAliasedBehavior: "alias",
|
|
3896
|
-
replaceOriginalName: true
|
|
3897
|
-
});
|
|
3898
|
-
const aliasedSelection = new Proxy(qb.getSelectedFields(), selectionProxy);
|
|
3899
|
-
return new Proxy(new PgView({
|
|
3900
|
-
pgConfig: this.config,
|
|
3901
|
-
config: {
|
|
3902
|
-
name: this.name,
|
|
3903
|
-
schema: this.schema,
|
|
3904
|
-
selectedFields: aliasedSelection,
|
|
3905
|
-
query: qb.getSQL().inlineParams()
|
|
3906
|
-
}
|
|
3907
|
-
}), selectionProxy);
|
|
3908
|
-
}
|
|
3909
|
-
}
|
|
3910
|
-
|
|
3911
|
-
class ManualViewBuilder extends DefaultViewBuilderCore {
|
|
3912
|
-
static [entityKind] = "PgManualViewBuilder";
|
|
3913
|
-
columns;
|
|
3914
|
-
constructor(name, columns, schema) {
|
|
3915
|
-
super(name, schema);
|
|
3916
|
-
this.columns = getTableColumns(pgTable(name, columns));
|
|
3917
|
-
}
|
|
3918
|
-
existing() {
|
|
3919
|
-
return new Proxy(new PgView({
|
|
3920
|
-
pgConfig: undefined,
|
|
3921
|
-
config: {
|
|
3922
|
-
name: this.name,
|
|
3923
|
-
schema: this.schema,
|
|
3924
|
-
selectedFields: this.columns,
|
|
3925
|
-
query: undefined
|
|
3926
|
-
}
|
|
3927
|
-
}), new SelectionProxyHandler({
|
|
3928
|
-
alias: this.name,
|
|
3929
|
-
sqlBehavior: "error",
|
|
3930
|
-
sqlAliasedBehavior: "alias",
|
|
3931
|
-
replaceOriginalName: true
|
|
3932
|
-
}));
|
|
3933
|
-
}
|
|
3934
|
-
as(query) {
|
|
3935
|
-
return new Proxy(new PgView({
|
|
3936
|
-
pgConfig: this.config,
|
|
3937
|
-
config: {
|
|
3938
|
-
name: this.name,
|
|
3939
|
-
schema: this.schema,
|
|
3940
|
-
selectedFields: this.columns,
|
|
3941
|
-
query: query.inlineParams()
|
|
3942
|
-
}
|
|
3943
|
-
}), new SelectionProxyHandler({
|
|
3944
|
-
alias: this.name,
|
|
3945
|
-
sqlBehavior: "error",
|
|
3946
|
-
sqlAliasedBehavior: "alias",
|
|
3947
|
-
replaceOriginalName: true
|
|
3948
|
-
}));
|
|
3949
|
-
}
|
|
3950
|
-
}
|
|
3951
|
-
|
|
3952
|
-
class MaterializedViewBuilderCore {
|
|
3953
|
-
constructor(name, schema) {
|
|
3954
|
-
this.name = name;
|
|
3955
|
-
this.schema = schema;
|
|
3956
|
-
}
|
|
3957
|
-
static [entityKind] = "PgMaterializedViewBuilderCore";
|
|
3958
|
-
config = {};
|
|
3959
|
-
using(using) {
|
|
3960
|
-
this.config.using = using;
|
|
3961
|
-
return this;
|
|
3962
|
-
}
|
|
3963
|
-
with(config) {
|
|
3964
|
-
this.config.with = config;
|
|
3965
|
-
return this;
|
|
3966
|
-
}
|
|
3967
|
-
tablespace(tablespace) {
|
|
3968
|
-
this.config.tablespace = tablespace;
|
|
3969
|
-
return this;
|
|
3970
|
-
}
|
|
3971
|
-
withNoData() {
|
|
3972
|
-
this.config.withNoData = true;
|
|
3973
|
-
return this;
|
|
3974
|
-
}
|
|
3975
|
-
}
|
|
3976
|
-
|
|
3977
|
-
class MaterializedViewBuilder extends MaterializedViewBuilderCore {
|
|
3978
|
-
static [entityKind] = "PgMaterializedViewBuilder";
|
|
3979
|
-
as(qb) {
|
|
3980
|
-
if (typeof qb === "function") {
|
|
3981
|
-
qb = qb(new QueryBuilder);
|
|
3982
|
-
}
|
|
3983
|
-
const selectionProxy = new SelectionProxyHandler({
|
|
3984
|
-
alias: this.name,
|
|
3985
|
-
sqlBehavior: "error",
|
|
3986
|
-
sqlAliasedBehavior: "alias",
|
|
3987
|
-
replaceOriginalName: true
|
|
3988
|
-
});
|
|
3989
|
-
const aliasedSelection = new Proxy(qb.getSelectedFields(), selectionProxy);
|
|
3990
|
-
return new Proxy(new PgMaterializedView({
|
|
3991
|
-
pgConfig: {
|
|
3992
|
-
with: this.config.with,
|
|
3993
|
-
using: this.config.using,
|
|
3994
|
-
tablespace: this.config.tablespace,
|
|
3995
|
-
withNoData: this.config.withNoData
|
|
3996
|
-
},
|
|
3997
|
-
config: {
|
|
3998
|
-
name: this.name,
|
|
3999
|
-
schema: this.schema,
|
|
4000
|
-
selectedFields: aliasedSelection,
|
|
4001
|
-
query: qb.getSQL().inlineParams()
|
|
4002
|
-
}
|
|
4003
|
-
}), selectionProxy);
|
|
4004
|
-
}
|
|
4005
|
-
}
|
|
4006
|
-
|
|
4007
|
-
class ManualMaterializedViewBuilder extends MaterializedViewBuilderCore {
|
|
4008
|
-
static [entityKind] = "PgManualMaterializedViewBuilder";
|
|
4009
|
-
columns;
|
|
4010
|
-
constructor(name, columns, schema) {
|
|
4011
|
-
super(name, schema);
|
|
4012
|
-
this.columns = getTableColumns(pgTable(name, columns));
|
|
4013
|
-
}
|
|
4014
|
-
existing() {
|
|
4015
|
-
return new Proxy(new PgMaterializedView({
|
|
4016
|
-
pgConfig: {
|
|
4017
|
-
tablespace: this.config.tablespace,
|
|
4018
|
-
using: this.config.using,
|
|
4019
|
-
with: this.config.with,
|
|
4020
|
-
withNoData: this.config.withNoData
|
|
4021
|
-
},
|
|
4022
|
-
config: {
|
|
4023
|
-
name: this.name,
|
|
4024
|
-
schema: this.schema,
|
|
4025
|
-
selectedFields: this.columns,
|
|
4026
|
-
query: undefined
|
|
4027
|
-
}
|
|
4028
|
-
}), new SelectionProxyHandler({
|
|
4029
|
-
alias: this.name,
|
|
4030
|
-
sqlBehavior: "error",
|
|
4031
|
-
sqlAliasedBehavior: "alias",
|
|
4032
|
-
replaceOriginalName: true
|
|
4033
|
-
}));
|
|
4034
|
-
}
|
|
4035
|
-
as(query) {
|
|
4036
|
-
return new Proxy(new PgMaterializedView({
|
|
4037
|
-
pgConfig: {
|
|
4038
|
-
tablespace: this.config.tablespace,
|
|
4039
|
-
using: this.config.using,
|
|
4040
|
-
with: this.config.with,
|
|
4041
|
-
withNoData: this.config.withNoData
|
|
4042
|
-
},
|
|
4043
|
-
config: {
|
|
4044
|
-
name: this.name,
|
|
4045
|
-
schema: this.schema,
|
|
4046
|
-
selectedFields: this.columns,
|
|
4047
|
-
query: query.inlineParams()
|
|
4048
|
-
}
|
|
4049
|
-
}), new SelectionProxyHandler({
|
|
4050
|
-
alias: this.name,
|
|
4051
|
-
sqlBehavior: "error",
|
|
4052
|
-
sqlAliasedBehavior: "alias",
|
|
4053
|
-
replaceOriginalName: true
|
|
4054
|
-
}));
|
|
4055
|
-
}
|
|
4056
|
-
}
|
|
4057
|
-
|
|
4058
|
-
class PgView extends PgViewBase {
|
|
4059
|
-
static [entityKind] = "PgView";
|
|
4060
|
-
[PgViewConfig];
|
|
4061
|
-
constructor({ pgConfig, config }) {
|
|
4062
|
-
super(config);
|
|
4063
|
-
if (pgConfig) {
|
|
4064
|
-
this[PgViewConfig] = {
|
|
4065
|
-
with: pgConfig.with
|
|
4066
|
-
};
|
|
4067
|
-
}
|
|
4068
|
-
}
|
|
4069
|
-
}
|
|
4070
|
-
var PgMaterializedViewConfig = Symbol.for("drizzle:PgMaterializedViewConfig");
|
|
4071
|
-
|
|
4072
|
-
class PgMaterializedView extends PgViewBase {
|
|
4073
|
-
static [entityKind] = "PgMaterializedView";
|
|
4074
|
-
[PgMaterializedViewConfig];
|
|
4075
|
-
constructor({ pgConfig, config }) {
|
|
4076
|
-
super(config);
|
|
4077
|
-
this[PgMaterializedViewConfig] = {
|
|
4078
|
-
with: pgConfig?.with,
|
|
4079
|
-
using: pgConfig?.using,
|
|
4080
|
-
tablespace: pgConfig?.tablespace,
|
|
4081
|
-
withNoData: pgConfig?.withNoData
|
|
4082
|
-
};
|
|
4083
|
-
}
|
|
4084
|
-
}
|
|
4085
|
-
function pgViewWithSchema(name, selection, schema) {
|
|
4086
|
-
if (selection) {
|
|
4087
|
-
return new ManualViewBuilder(name, selection, schema);
|
|
4088
|
-
}
|
|
4089
|
-
return new ViewBuilder(name, schema);
|
|
4090
|
-
}
|
|
4091
|
-
function pgMaterializedViewWithSchema(name, selection, schema) {
|
|
4092
|
-
if (selection) {
|
|
4093
|
-
return new ManualMaterializedViewBuilder(name, selection, schema);
|
|
4094
|
-
}
|
|
4095
|
-
return new MaterializedViewBuilder(name, schema);
|
|
4096
|
-
}
|
|
4097
|
-
|
|
4098
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/utils.js
|
|
4099
|
-
function extractUsedTable(table) {
|
|
4100
|
-
if (is(table, PgTable)) {
|
|
4101
|
-
return [table[Schema] ? `${table[Schema]}.${table[Table.Symbol.BaseName]}` : table[Table.Symbol.BaseName]];
|
|
4102
|
-
}
|
|
4103
|
-
if (is(table, Subquery)) {
|
|
4104
|
-
return table._.usedTables ?? [];
|
|
4105
|
-
}
|
|
4106
|
-
if (is(table, SQL)) {
|
|
4107
|
-
return table.usedTables ?? [];
|
|
4108
|
-
}
|
|
4109
|
-
return [];
|
|
4110
|
-
}
|
|
4111
|
-
|
|
4112
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/sequence.js
|
|
4113
|
-
class PgSequence {
|
|
4114
|
-
constructor(seqName, seqOptions, schema) {
|
|
4115
|
-
this.seqName = seqName;
|
|
4116
|
-
this.seqOptions = seqOptions;
|
|
4117
|
-
this.schema = schema;
|
|
4118
|
-
}
|
|
4119
|
-
static [entityKind] = "PgSequence";
|
|
4120
|
-
}
|
|
4121
|
-
function pgSequenceWithSchema(name, options, schema) {
|
|
4122
|
-
return new PgSequence(name, options, schema);
|
|
4123
|
-
}
|
|
4124
|
-
|
|
4125
|
-
// ../../node_modules/.bun/drizzle-orm@0.45.2+fc0f68b157690761/node_modules/drizzle-orm/pg-core/schema.js
|
|
4126
|
-
class PgSchema {
|
|
4127
|
-
constructor(schemaName) {
|
|
4128
|
-
this.schemaName = schemaName;
|
|
4129
|
-
}
|
|
4130
|
-
static [entityKind] = "PgSchema";
|
|
4131
|
-
table = (name, columns, extraConfig) => {
|
|
4132
|
-
return pgTableWithSchema(name, columns, extraConfig, this.schemaName);
|
|
4133
|
-
};
|
|
4134
|
-
view = (name, columns) => {
|
|
4135
|
-
return pgViewWithSchema(name, columns, this.schemaName);
|
|
4136
|
-
};
|
|
4137
|
-
materializedView = (name, columns) => {
|
|
4138
|
-
return pgMaterializedViewWithSchema(name, columns, this.schemaName);
|
|
4139
|
-
};
|
|
4140
|
-
enum(enumName, input) {
|
|
4141
|
-
return Array.isArray(input) ? pgEnumWithSchema(enumName, [...input], this.schemaName) : pgEnumObjectWithSchema(enumName, input, this.schemaName);
|
|
4142
|
-
}
|
|
4143
|
-
sequence = (name, options) => {
|
|
4144
|
-
return pgSequenceWithSchema(name, options, this.schemaName);
|
|
4145
|
-
};
|
|
4146
|
-
getSQL() {
|
|
4147
|
-
return new SQL([sql.identifier(this.schemaName)]);
|
|
4148
|
-
}
|
|
4149
|
-
shouldOmitSQLParens() {
|
|
4150
|
-
return true;
|
|
4151
|
-
}
|
|
4152
|
-
}
|
|
4153
|
-
function pgSchema(name) {
|
|
4154
|
-
if (name === "public") {
|
|
4155
|
-
throw new Error(`You can't specify 'public' as schema name. Postgres is using public schema by default. If you want to use 'public' schema, just use pgTable() instead of creating a schema`);
|
|
4156
|
-
}
|
|
4157
|
-
return new PgSchema(name);
|
|
4158
|
-
}
|
|
4159
|
-
|
|
4160
|
-
// src/db/schema.ts
|
|
4161
|
-
var todosSchema = pgSchema("todos");
|
|
4162
|
-
var todosTable = todosSchema.table("todos", {
|
|
4163
|
-
id: uuid("id").primaryKey().defaultRandom(),
|
|
4164
|
-
agentId: uuid("agent_id").notNull(),
|
|
4165
|
-
entityId: uuid("entity_id").notNull(),
|
|
4166
|
-
roomId: uuid("room_id"),
|
|
4167
|
-
worldId: uuid("world_id"),
|
|
4168
|
-
content: text("content").notNull(),
|
|
4169
|
-
activeForm: text("active_form").notNull(),
|
|
4170
|
-
status: text("status").notNull(),
|
|
4171
|
-
parentTodoId: uuid("parent_todo_id"),
|
|
4172
|
-
parentTrajectoryStepId: text("parent_trajectory_step_id"),
|
|
4173
|
-
metadata: jsonb("metadata").default("{}").notNull(),
|
|
4174
|
-
createdAt: timestamp("created_at").default(sql`now()`).notNull(),
|
|
4175
|
-
updatedAt: timestamp("updated_at").default(sql`now()`).notNull(),
|
|
4176
|
-
completedAt: timestamp("completed_at")
|
|
4177
|
-
}, (table) => ({
|
|
4178
|
-
entityStatusIdx: index("idx_todos_entity_status").on(table.entityId, table.status),
|
|
4179
|
-
agentEntityIdx: index("idx_todos_agent_entity").on(table.agentId, table.entityId),
|
|
4180
|
-
roomIdx: index("idx_todos_room").on(table.roomId)
|
|
4181
|
-
}));
|
|
4182
|
-
|
|
4183
|
-
// src/types.ts
|
|
4184
|
-
var TODOS_LOG_PREFIX = "[Todos]";
|
|
4185
|
-
var TODOS_SERVICE_TYPE = "todos";
|
|
4186
|
-
var TODO_STATUSES = [
|
|
4187
|
-
"pending",
|
|
4188
|
-
"in_progress",
|
|
4189
|
-
"completed",
|
|
4190
|
-
"cancelled"
|
|
4191
|
-
];
|
|
4192
|
-
var TODO_OPS = [
|
|
4193
|
-
"write",
|
|
4194
|
-
"create",
|
|
4195
|
-
"update",
|
|
4196
|
-
"complete",
|
|
4197
|
-
"cancel",
|
|
4198
|
-
"delete",
|
|
4199
|
-
"list",
|
|
4200
|
-
"clear"
|
|
4201
|
-
];
|
|
4202
|
-
var TODOS_CONTEXTS = ["tasks", "todos", "automation"];
|
|
4203
|
-
var TODO_FAILURE_TEXT_PREFIX = "[Todos]";
|
|
4204
|
-
|
|
4205
|
-
// src/service.ts
|
|
4206
|
-
function rowToTodo(row) {
|
|
4207
|
-
const metadata = row.metadata && typeof row.metadata === "object" && !Array.isArray(row.metadata) ? row.metadata : {};
|
|
4208
|
-
return {
|
|
4209
|
-
id: row.id,
|
|
4210
|
-
entityId: row.entityId,
|
|
4211
|
-
agentId: row.agentId,
|
|
4212
|
-
roomId: row.roomId ?? null,
|
|
4213
|
-
worldId: row.worldId ?? null,
|
|
4214
|
-
content: row.content,
|
|
4215
|
-
activeForm: row.activeForm,
|
|
4216
|
-
status: row.status,
|
|
4217
|
-
parentTodoId: row.parentTodoId ?? null,
|
|
4218
|
-
parentTrajectoryStepId: row.parentTrajectoryStepId ?? null,
|
|
4219
|
-
metadata,
|
|
4220
|
-
createdAt: row.createdAt,
|
|
4221
|
-
updatedAt: row.updatedAt,
|
|
4222
|
-
completedAt: row.completedAt ?? null
|
|
4223
|
-
};
|
|
4224
|
-
}
|
|
4225
|
-
|
|
4226
|
-
class TodosService extends Service {
|
|
4227
|
-
static serviceType = TODOS_SERVICE_TYPE;
|
|
4228
|
-
capabilityDescription = "User-scoped todo CRUD. Persistent (drizzle/postgres), keyed by (agentId, entityId).";
|
|
4229
|
-
getDb() {
|
|
4230
|
-
const db = this.runtime.db;
|
|
4231
|
-
if (!db) {
|
|
4232
|
-
throw new Error(`${TODOS_LOG_PREFIX} runtime.db is not available — @elizaos/plugin-sql must be installed and initialized.`);
|
|
4233
|
-
}
|
|
4234
|
-
return db;
|
|
4235
|
-
}
|
|
4236
|
-
static async start(runtime) {
|
|
4237
|
-
logger.info(`${TODOS_LOG_PREFIX} starting TodosService`);
|
|
4238
|
-
return new TodosService(runtime);
|
|
4239
|
-
}
|
|
4240
|
-
async stop() {
|
|
4241
|
-
logger.info(`${TODOS_LOG_PREFIX} stopping TodosService`);
|
|
4242
|
-
}
|
|
4243
|
-
async create(input) {
|
|
4244
|
-
const db = this.getDb();
|
|
4245
|
-
const [row] = await db.insert(todosTable).values({
|
|
4246
|
-
agentId: input.agentId,
|
|
4247
|
-
entityId: input.entityId,
|
|
4248
|
-
roomId: input.roomId ?? null,
|
|
4249
|
-
worldId: input.worldId ?? null,
|
|
4250
|
-
content: input.content,
|
|
4251
|
-
activeForm: input.activeForm ?? input.content,
|
|
4252
|
-
status: input.status ?? "pending",
|
|
4253
|
-
parentTodoId: input.parentTodoId ?? null,
|
|
4254
|
-
parentTrajectoryStepId: input.parentTrajectoryStepId ?? null,
|
|
4255
|
-
metadata: input.metadata ?? {}
|
|
4256
|
-
}).returning();
|
|
4257
|
-
if (!row)
|
|
4258
|
-
throw new Error(`${TODOS_LOG_PREFIX} insert returned no row`);
|
|
4259
|
-
return rowToTodo(row);
|
|
4260
|
-
}
|
|
4261
|
-
async get(id) {
|
|
4262
|
-
const db = this.getDb();
|
|
4263
|
-
const [row] = await db.select().from(todosTable).where(eq(todosTable.id, id)).limit(1);
|
|
4264
|
-
return row ? rowToTodo(row) : null;
|
|
4265
|
-
}
|
|
4266
|
-
async list(filter) {
|
|
4267
|
-
const db = this.getDb();
|
|
4268
|
-
const conditions = [eq(todosTable.entityId, filter.entityId)];
|
|
4269
|
-
if (filter.agentId) {
|
|
4270
|
-
conditions.push(eq(todosTable.agentId, filter.agentId));
|
|
4271
|
-
}
|
|
4272
|
-
if (filter.roomId !== undefined && filter.roomId !== null) {
|
|
4273
|
-
conditions.push(eq(todosTable.roomId, filter.roomId));
|
|
4274
|
-
}
|
|
4275
|
-
if (filter.status) {
|
|
4276
|
-
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
4277
|
-
conditions.push(inArray(todosTable.status, statuses));
|
|
4278
|
-
} else if (filter.includeCompleted === false) {
|
|
4279
|
-
conditions.push(inArray(todosTable.status, ["pending", "in_progress"]));
|
|
4280
|
-
}
|
|
4281
|
-
const query = db.select().from(todosTable).where(and(...conditions)).orderBy(desc(todosTable.updatedAt));
|
|
4282
|
-
const rows = filter.limit ? await query.limit(filter.limit) : await query;
|
|
4283
|
-
return rows.map(rowToTodo);
|
|
4284
|
-
}
|
|
4285
|
-
async update(id, patch) {
|
|
4286
|
-
const db = this.getDb();
|
|
4287
|
-
const set = { updatedAt: new Date };
|
|
4288
|
-
if (patch.content !== undefined)
|
|
4289
|
-
set.content = patch.content;
|
|
4290
|
-
if (patch.activeForm !== undefined)
|
|
4291
|
-
set.activeForm = patch.activeForm;
|
|
4292
|
-
if (patch.status !== undefined) {
|
|
4293
|
-
set.status = patch.status;
|
|
4294
|
-
set.completedAt = patch.status === "completed" ? new Date : null;
|
|
4295
|
-
}
|
|
4296
|
-
if (patch.parentTodoId !== undefined)
|
|
4297
|
-
set.parentTodoId = patch.parentTodoId;
|
|
4298
|
-
if (patch.metadata !== undefined)
|
|
4299
|
-
set.metadata = patch.metadata;
|
|
4300
|
-
const [row] = await db.update(todosTable).set(set).where(eq(todosTable.id, id)).returning();
|
|
4301
|
-
return row ? rowToTodo(row) : null;
|
|
4302
|
-
}
|
|
4303
|
-
async delete(id) {
|
|
4304
|
-
const db = this.getDb();
|
|
4305
|
-
const rows = await db.delete(todosTable).where(eq(todosTable.id, id)).returning({ id: todosTable.id });
|
|
4306
|
-
return rows.length > 0;
|
|
4307
|
-
}
|
|
4308
|
-
async writeList(args) {
|
|
4309
|
-
const db = this.getDb();
|
|
4310
|
-
const before = await this.list({
|
|
4311
|
-
entityId: args.entityId,
|
|
4312
|
-
agentId: args.agentId,
|
|
4313
|
-
roomId: args.roomId ?? undefined
|
|
4314
|
-
});
|
|
4315
|
-
const beforeById = new Map(before.map((t) => [t.id, t]));
|
|
4316
|
-
const keepIds = new Set;
|
|
4317
|
-
const after = [];
|
|
4318
|
-
for (const item of args.todos) {
|
|
4319
|
-
const existing = item.id ? beforeById.get(item.id) : undefined;
|
|
4320
|
-
if (existing) {
|
|
4321
|
-
keepIds.add(existing.id);
|
|
4322
|
-
const needsUpdate = existing.content !== item.content || existing.status !== item.status || existing.activeForm !== (item.activeForm ?? item.content);
|
|
4323
|
-
if (needsUpdate) {
|
|
4324
|
-
const updated = await this.update(existing.id, {
|
|
4325
|
-
content: item.content,
|
|
4326
|
-
activeForm: item.activeForm ?? item.content,
|
|
4327
|
-
status: item.status
|
|
4328
|
-
});
|
|
4329
|
-
if (updated)
|
|
4330
|
-
after.push(updated);
|
|
4331
|
-
} else {
|
|
4332
|
-
after.push(existing);
|
|
4333
|
-
}
|
|
4334
|
-
} else {
|
|
4335
|
-
const created = await this.create({
|
|
4336
|
-
entityId: args.entityId,
|
|
4337
|
-
agentId: args.agentId,
|
|
4338
|
-
roomId: args.roomId,
|
|
4339
|
-
worldId: args.worldId,
|
|
4340
|
-
content: item.content,
|
|
4341
|
-
activeForm: item.activeForm ?? item.content,
|
|
4342
|
-
status: item.status,
|
|
4343
|
-
parentTrajectoryStepId: args.parentTrajectoryStepId
|
|
4344
|
-
});
|
|
4345
|
-
keepIds.add(created.id);
|
|
4346
|
-
after.push(created);
|
|
4347
|
-
}
|
|
4348
|
-
}
|
|
4349
|
-
const toDelete = before.filter((t) => !keepIds.has(t.id)).map((t) => t.id);
|
|
4350
|
-
if (toDelete.length > 0) {
|
|
4351
|
-
await db.delete(todosTable).where(inArray(todosTable.id, toDelete));
|
|
4352
|
-
}
|
|
4353
|
-
return { before, after };
|
|
4354
|
-
}
|
|
4355
|
-
async clear(filter) {
|
|
4356
|
-
const db = this.getDb();
|
|
4357
|
-
const conditions = [eq(todosTable.entityId, filter.entityId)];
|
|
4358
|
-
if (filter.agentId) {
|
|
4359
|
-
conditions.push(eq(todosTable.agentId, filter.agentId));
|
|
4360
|
-
}
|
|
4361
|
-
if (filter.roomId) {
|
|
4362
|
-
conditions.push(eq(todosTable.roomId, filter.roomId));
|
|
4363
|
-
}
|
|
4364
|
-
const rows = await db.delete(todosTable).where(and(...conditions)).returning({ id: todosTable.id });
|
|
4365
|
-
return rows.length;
|
|
4366
|
-
}
|
|
4367
|
-
}
|
|
4368
|
-
function getTodosService(runtime) {
|
|
4369
|
-
const service = runtime.getService(TODOS_SERVICE_TYPE);
|
|
4370
|
-
if (!service) {
|
|
4371
|
-
throw new Error(`${TODOS_LOG_PREFIX} TodosService is not registered — ensure @elizaos/plugin-todos is enabled.`);
|
|
4372
|
-
}
|
|
4373
|
-
return service;
|
|
4374
|
-
}
|
|
4375
|
-
|
|
4376
|
-
// src/actions/todo.ts
|
|
4377
|
-
var PARENT_TRAJECTORY_STEP_ENV_KEY = "MILADY_PARENT_TRAJECTORY_STEP_ID";
|
|
4378
|
-
function checkboxFor(status) {
|
|
4379
|
-
switch (status) {
|
|
4380
|
-
case "completed":
|
|
4381
|
-
return "[x]";
|
|
4382
|
-
case "in_progress":
|
|
4383
|
-
return "[→]";
|
|
4384
|
-
case "cancelled":
|
|
4385
|
-
return "[-]";
|
|
4386
|
-
default:
|
|
4387
|
-
return "[ ]";
|
|
4388
|
-
}
|
|
4389
|
-
}
|
|
4390
|
-
function renderMarkdown(todos) {
|
|
4391
|
-
if (todos.length === 0)
|
|
4392
|
-
return "(no todos)";
|
|
4393
|
-
return todos.map((t) => `- ${checkboxFor(t.status)} ${t.content}`).join(`
|
|
4394
|
-
`);
|
|
4395
|
-
}
|
|
4396
|
-
function failure(reason, message) {
|
|
4397
|
-
const text2 = `${TODO_FAILURE_TEXT_PREFIX} ${reason}: ${message}`;
|
|
4398
|
-
return { success: false, text: text2, error: new Error(text2) };
|
|
4399
|
-
}
|
|
4400
|
-
function readString(value) {
|
|
4401
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
4402
|
-
}
|
|
4403
|
-
function readBoolean(value) {
|
|
4404
|
-
if (typeof value === "boolean")
|
|
4405
|
-
return value;
|
|
4406
|
-
if (typeof value === "string") {
|
|
4407
|
-
const v = value.trim().toLowerCase();
|
|
4408
|
-
if (v === "true" || v === "1" || v === "yes")
|
|
4409
|
-
return true;
|
|
4410
|
-
if (v === "false" || v === "0" || v === "no")
|
|
4411
|
-
return false;
|
|
4412
|
-
}
|
|
4413
|
-
return;
|
|
4414
|
-
}
|
|
4415
|
-
function readNumber(value) {
|
|
4416
|
-
if (typeof value === "number" && Number.isFinite(value))
|
|
4417
|
-
return value;
|
|
4418
|
-
if (typeof value === "string" && value.trim()) {
|
|
4419
|
-
const n = Number(value);
|
|
4420
|
-
if (Number.isFinite(n))
|
|
4421
|
-
return n;
|
|
4422
|
-
}
|
|
4423
|
-
return;
|
|
4424
|
-
}
|
|
4425
|
-
function readStatus(value) {
|
|
4426
|
-
const s = readString(value)?.toLowerCase();
|
|
4427
|
-
if (!s)
|
|
4428
|
-
return;
|
|
4429
|
-
if (TODO_STATUSES.includes(s)) {
|
|
4430
|
-
return s;
|
|
4431
|
-
}
|
|
4432
|
-
return;
|
|
4433
|
-
}
|
|
4434
|
-
function readOp(value) {
|
|
4435
|
-
const s = readString(value)?.toLowerCase();
|
|
4436
|
-
if (!s)
|
|
4437
|
-
return;
|
|
4438
|
-
if (TODO_OPS.includes(s))
|
|
4439
|
-
return s;
|
|
4440
|
-
return;
|
|
4441
|
-
}
|
|
4442
|
-
function parseTodoList(raw) {
|
|
4443
|
-
if (!Array.isArray(raw)) {
|
|
4444
|
-
return { ok: false, message: "todos must be an array" };
|
|
4445
|
-
}
|
|
4446
|
-
const items = [];
|
|
4447
|
-
for (let i = 0;i < raw.length; i++) {
|
|
4448
|
-
const entry = raw[i];
|
|
4449
|
-
if (!entry || typeof entry !== "object") {
|
|
4450
|
-
return { ok: false, message: `todos[${i}] is not an object` };
|
|
4451
|
-
}
|
|
4452
|
-
const e = entry;
|
|
4453
|
-
const content = readString(e.content);
|
|
4454
|
-
if (!content) {
|
|
4455
|
-
return {
|
|
4456
|
-
ok: false,
|
|
4457
|
-
message: `todos[${i}].content must be a non-empty string`
|
|
4458
|
-
};
|
|
4459
|
-
}
|
|
4460
|
-
const status = readStatus(e.status);
|
|
4461
|
-
if (!status) {
|
|
4462
|
-
return {
|
|
4463
|
-
ok: false,
|
|
4464
|
-
message: `todos[${i}].status must be one of ${TODO_STATUSES.join(", ")}`
|
|
4465
|
-
};
|
|
4466
|
-
}
|
|
4467
|
-
const item = { content, status };
|
|
4468
|
-
const id = readString(e.id);
|
|
4469
|
-
if (id)
|
|
4470
|
-
item.id = id;
|
|
4471
|
-
const activeForm = readString(e.activeForm);
|
|
4472
|
-
if (activeForm)
|
|
4473
|
-
item.activeForm = activeForm;
|
|
4474
|
-
items.push(item);
|
|
4475
|
-
}
|
|
4476
|
-
return { ok: true, items };
|
|
4477
|
-
}
|
|
4478
|
-
function readScope(runtime, message) {
|
|
4479
|
-
const entityId = readString(message.entityId);
|
|
4480
|
-
if (!entityId) {
|
|
4481
|
-
return { error: "message has no entityId" };
|
|
4482
|
-
}
|
|
4483
|
-
const agentId = readString(runtime.agentId);
|
|
4484
|
-
if (!agentId) {
|
|
4485
|
-
return { error: "runtime has no agentId" };
|
|
4486
|
-
}
|
|
4487
|
-
const parentStepFromEnv = readString(process.env[PARENT_TRAJECTORY_STEP_ENV_KEY]);
|
|
4488
|
-
return {
|
|
4489
|
-
entityId,
|
|
4490
|
-
agentId,
|
|
4491
|
-
roomId: readString(message.roomId) ?? null,
|
|
4492
|
-
worldId: readString(message.worldId) ?? null,
|
|
4493
|
-
parentTrajectoryStepId: parentStepFromEnv ?? null
|
|
4494
|
-
};
|
|
4495
|
-
}
|
|
4496
|
-
async function emit(callback, text2) {
|
|
4497
|
-
if (callback) {
|
|
4498
|
-
await callback({ text: text2, source: "todos" });
|
|
4499
|
-
}
|
|
4500
|
-
}
|
|
4501
|
-
async function opWrite({
|
|
4502
|
-
service,
|
|
4503
|
-
scope,
|
|
4504
|
-
params,
|
|
4505
|
-
callback
|
|
4506
|
-
}) {
|
|
4507
|
-
const parsed = parseTodoList(params.todos);
|
|
4508
|
-
if (!parsed.ok) {
|
|
4509
|
-
return failure("invalid_param", parsed.message);
|
|
4510
|
-
}
|
|
4511
|
-
const result = await service.writeList({
|
|
4512
|
-
entityId: scope.entityId,
|
|
4513
|
-
agentId: scope.agentId,
|
|
4514
|
-
roomId: scope.roomId,
|
|
4515
|
-
worldId: scope.worldId,
|
|
4516
|
-
parentTrajectoryStepId: scope.parentTrajectoryStepId,
|
|
4517
|
-
todos: parsed.items
|
|
4518
|
-
});
|
|
4519
|
-
let pending = 0;
|
|
4520
|
-
let inProgress = 0;
|
|
4521
|
-
let completed = 0;
|
|
4522
|
-
let cancelled = 0;
|
|
4523
|
-
for (const t of result.after) {
|
|
4524
|
-
if (t.status === "completed")
|
|
4525
|
-
completed++;
|
|
4526
|
-
else if (t.status === "in_progress")
|
|
4527
|
-
inProgress++;
|
|
4528
|
-
else if (t.status === "cancelled")
|
|
4529
|
-
cancelled++;
|
|
4530
|
-
else
|
|
4531
|
-
pending++;
|
|
4532
|
-
}
|
|
4533
|
-
const text2 = renderMarkdown(result.after);
|
|
4534
|
-
await emit(callback, text2);
|
|
4535
|
-
return {
|
|
4536
|
-
success: true,
|
|
4537
|
-
text: text2,
|
|
4538
|
-
data: {
|
|
4539
|
-
op: "write",
|
|
4540
|
-
entityId: scope.entityId,
|
|
4541
|
-
todos: result.after,
|
|
4542
|
-
oldTodos: result.before,
|
|
4543
|
-
pendingCount: pending,
|
|
4544
|
-
inProgressCount: inProgress,
|
|
4545
|
-
completedCount: completed,
|
|
4546
|
-
cancelledCount: cancelled
|
|
4547
|
-
}
|
|
4548
|
-
};
|
|
4549
|
-
}
|
|
4550
|
-
async function opCreate({
|
|
4551
|
-
service,
|
|
4552
|
-
scope,
|
|
4553
|
-
params,
|
|
4554
|
-
callback
|
|
4555
|
-
}) {
|
|
4556
|
-
const content = readString(params.content);
|
|
4557
|
-
if (!content) {
|
|
4558
|
-
return failure("missing_param", "content is required for op=create");
|
|
4559
|
-
}
|
|
4560
|
-
const status = readStatus(params.status) ?? "pending";
|
|
4561
|
-
const activeForm = readString(params.activeForm);
|
|
4562
|
-
const parentTodoId = readString(params.parentTodoId);
|
|
4563
|
-
const input = {
|
|
4564
|
-
entityId: scope.entityId,
|
|
4565
|
-
agentId: scope.agentId,
|
|
4566
|
-
roomId: scope.roomId,
|
|
4567
|
-
worldId: scope.worldId,
|
|
4568
|
-
content,
|
|
4569
|
-
status,
|
|
4570
|
-
parentTrajectoryStepId: scope.parentTrajectoryStepId
|
|
4571
|
-
};
|
|
4572
|
-
if (activeForm !== undefined)
|
|
4573
|
-
input.activeForm = activeForm;
|
|
4574
|
-
if (parentTodoId !== undefined)
|
|
4575
|
-
input.parentTodoId = parentTodoId;
|
|
4576
|
-
const todo = await service.create(input);
|
|
4577
|
-
const text2 = `Created: ${checkboxFor(todo.status)} ${todo.content}`;
|
|
4578
|
-
await emit(callback, text2);
|
|
4579
|
-
return {
|
|
4580
|
-
success: true,
|
|
4581
|
-
text: text2,
|
|
4582
|
-
data: { op: "create", entityId: scope.entityId, todo }
|
|
4583
|
-
};
|
|
4584
|
-
}
|
|
4585
|
-
async function opUpdate({
|
|
4586
|
-
service,
|
|
4587
|
-
scope,
|
|
4588
|
-
params,
|
|
4589
|
-
callback
|
|
4590
|
-
}) {
|
|
4591
|
-
const id = readString(params.id);
|
|
4592
|
-
if (!id) {
|
|
4593
|
-
return failure("missing_param", "id is required for op=update");
|
|
4594
|
-
}
|
|
4595
|
-
const existing = await service.get(id);
|
|
4596
|
-
if (!existing || existing.entityId !== scope.entityId) {
|
|
4597
|
-
return failure("not_found", `todo ${id} not found for this user`);
|
|
4598
|
-
}
|
|
4599
|
-
const patch = {};
|
|
4600
|
-
const content = readString(params.content);
|
|
4601
|
-
if (content !== undefined)
|
|
4602
|
-
patch.content = content;
|
|
4603
|
-
const activeForm = readString(params.activeForm);
|
|
4604
|
-
if (activeForm !== undefined)
|
|
4605
|
-
patch.activeForm = activeForm;
|
|
4606
|
-
const status = readStatus(params.status);
|
|
4607
|
-
if (status !== undefined)
|
|
4608
|
-
patch.status = status;
|
|
4609
|
-
const parentTodoId = readString(params.parentTodoId);
|
|
4610
|
-
if (parentTodoId !== undefined)
|
|
4611
|
-
patch.parentTodoId = parentTodoId;
|
|
4612
|
-
if (Object.keys(patch).length === 0) {
|
|
4613
|
-
return failure("missing_param", "at least one field is required for op=update");
|
|
4614
|
-
}
|
|
4615
|
-
const todo = await service.update(id, patch);
|
|
4616
|
-
if (!todo) {
|
|
4617
|
-
return failure("not_found", `todo ${id} not found`);
|
|
4618
|
-
}
|
|
4619
|
-
const text2 = `Updated: ${checkboxFor(todo.status)} ${todo.content}`;
|
|
4620
|
-
await emit(callback, text2);
|
|
4621
|
-
return {
|
|
4622
|
-
success: true,
|
|
4623
|
-
text: text2,
|
|
4624
|
-
data: { op: "update", entityId: scope.entityId, todo }
|
|
4625
|
-
};
|
|
4626
|
-
}
|
|
4627
|
-
async function opSetStatus(args, status, verb) {
|
|
4628
|
-
const { service, scope, params, callback } = args;
|
|
4629
|
-
const id = readString(params.id);
|
|
4630
|
-
if (!id) {
|
|
4631
|
-
return failure("missing_param", `id is required for op=${verb}`);
|
|
4632
|
-
}
|
|
4633
|
-
const existing = await service.get(id);
|
|
4634
|
-
if (!existing || existing.entityId !== scope.entityId) {
|
|
4635
|
-
return failure("not_found", `todo ${id} not found for this user`);
|
|
4636
|
-
}
|
|
4637
|
-
const todo = await service.update(id, { status });
|
|
4638
|
-
if (!todo) {
|
|
4639
|
-
return failure("not_found", `todo ${id} not found`);
|
|
4640
|
-
}
|
|
4641
|
-
const text2 = `${verb}: ${checkboxFor(todo.status)} ${todo.content}`;
|
|
4642
|
-
await emit(callback, text2);
|
|
4643
|
-
return {
|
|
4644
|
-
success: true,
|
|
4645
|
-
text: text2,
|
|
4646
|
-
data: { op: verb, entityId: scope.entityId, todo }
|
|
4647
|
-
};
|
|
4648
|
-
}
|
|
4649
|
-
async function opDelete({
|
|
4650
|
-
service,
|
|
4651
|
-
scope,
|
|
4652
|
-
params,
|
|
4653
|
-
callback
|
|
4654
|
-
}) {
|
|
4655
|
-
const id = readString(params.id);
|
|
4656
|
-
if (!id) {
|
|
4657
|
-
return failure("missing_param", "id is required for op=delete");
|
|
4658
|
-
}
|
|
4659
|
-
const existing = await service.get(id);
|
|
4660
|
-
if (!existing || existing.entityId !== scope.entityId) {
|
|
4661
|
-
return failure("not_found", `todo ${id} not found for this user`);
|
|
4662
|
-
}
|
|
4663
|
-
const ok = await service.delete(id);
|
|
4664
|
-
if (!ok) {
|
|
4665
|
-
return failure("not_found", `todo ${id} not found`);
|
|
4666
|
-
}
|
|
4667
|
-
const text2 = `Deleted: ${existing.content}`;
|
|
4668
|
-
await emit(callback, text2);
|
|
4669
|
-
return {
|
|
4670
|
-
success: true,
|
|
4671
|
-
text: text2,
|
|
4672
|
-
data: { op: "delete", entityId: scope.entityId, id }
|
|
4673
|
-
};
|
|
4674
|
-
}
|
|
4675
|
-
async function opList({
|
|
4676
|
-
service,
|
|
4677
|
-
scope,
|
|
4678
|
-
params,
|
|
4679
|
-
callback
|
|
4680
|
-
}) {
|
|
4681
|
-
const includeCompleted = readBoolean(params.includeCompleted) ?? false;
|
|
4682
|
-
const limit = readNumber(params.limit);
|
|
4683
|
-
const filter = {
|
|
4684
|
-
entityId: scope.entityId,
|
|
4685
|
-
agentId: scope.agentId,
|
|
4686
|
-
includeCompleted
|
|
4687
|
-
};
|
|
4688
|
-
if (limit !== undefined)
|
|
4689
|
-
filter.limit = limit;
|
|
4690
|
-
const todos = await service.list(filter);
|
|
4691
|
-
const text2 = renderMarkdown(todos);
|
|
4692
|
-
await emit(callback, text2);
|
|
4693
|
-
return {
|
|
4694
|
-
success: true,
|
|
4695
|
-
text: text2,
|
|
4696
|
-
data: { op: "list", entityId: scope.entityId, todos }
|
|
4697
|
-
};
|
|
4698
|
-
}
|
|
4699
|
-
async function opClear({
|
|
4700
|
-
service,
|
|
4701
|
-
scope,
|
|
4702
|
-
callback
|
|
4703
|
-
}) {
|
|
4704
|
-
const filter = {
|
|
4705
|
-
entityId: scope.entityId,
|
|
4706
|
-
agentId: scope.agentId
|
|
4707
|
-
};
|
|
4708
|
-
if (scope.roomId)
|
|
4709
|
-
filter.roomId = scope.roomId;
|
|
4710
|
-
const count = await service.clear(filter);
|
|
4711
|
-
const text2 = `Cleared ${count} todo${count === 1 ? "" : "s"}.`;
|
|
4712
|
-
await emit(callback, text2);
|
|
4713
|
-
return {
|
|
4714
|
-
success: true,
|
|
4715
|
-
text: text2,
|
|
4716
|
-
data: { op: "clear", entityId: scope.entityId, count }
|
|
4717
|
-
};
|
|
4718
|
-
}
|
|
4719
|
-
var todoAction = {
|
|
4720
|
-
name: "TODO",
|
|
4721
|
-
contexts: [...TODOS_CONTEXTS],
|
|
4722
|
-
roleGate: { minRole: "ADMIN" },
|
|
4723
|
-
contextGate: { anyOf: [...TODOS_CONTEXTS] },
|
|
4724
|
-
tags: [
|
|
4725
|
-
"domain:reminders",
|
|
4726
|
-
"capability:read",
|
|
4727
|
-
"capability:write",
|
|
4728
|
-
"capability:update",
|
|
4729
|
-
"capability:delete",
|
|
4730
|
-
"surface:internal"
|
|
4731
|
-
],
|
|
4732
|
-
similes: [
|
|
4733
|
-
"TODO_WRITE",
|
|
4734
|
-
"WRITE_TODOS",
|
|
4735
|
-
"SET_TODOS",
|
|
4736
|
-
"UPDATE_TODOS",
|
|
4737
|
-
"TODO_CREATE",
|
|
4738
|
-
"CREATE_TODO",
|
|
4739
|
-
"TODO_UPDATE",
|
|
4740
|
-
"UPDATE_TODO",
|
|
4741
|
-
"TODO_COMPLETE",
|
|
4742
|
-
"COMPLETE_TODO",
|
|
4743
|
-
"FINISH_TODO",
|
|
4744
|
-
"TODO_CANCEL",
|
|
4745
|
-
"CANCEL_TODO",
|
|
4746
|
-
"TODO_DELETE",
|
|
4747
|
-
"DELETE_TODO",
|
|
4748
|
-
"REMOVE_TODO",
|
|
4749
|
-
"TODO_LIST",
|
|
4750
|
-
"LIST_TODOS",
|
|
4751
|
-
"GET_TODOS",
|
|
4752
|
-
"SHOW_TODOS",
|
|
4753
|
-
"TODO_CLEAR",
|
|
4754
|
-
"CLEAR_TODOS"
|
|
4755
|
-
],
|
|
4756
|
-
description: "Manage the user's todo list. Actions: write (replace the list with `todos:[{id?, content, status, activeForm?}]`), create (add one), update (change by id), complete, cancel, delete, list, clear. Todos are user-scoped (entityId), persistent, and shared across rooms for the same user.",
|
|
4757
|
-
descriptionCompressed: "todos: write|create|update|complete|cancel|delete|list|clear; user-scoped (entityId)",
|
|
4758
|
-
parameters: [
|
|
4759
|
-
{
|
|
4760
|
-
name: "action",
|
|
4761
|
-
description: "Action: write, create, update, complete, cancel, delete, list, clear.",
|
|
4762
|
-
required: true,
|
|
4763
|
-
schema: { type: "string", enum: [...TODO_OPS] }
|
|
4764
|
-
},
|
|
4765
|
-
{
|
|
4766
|
-
name: "subaction",
|
|
4767
|
-
description: "Legacy alias for action.",
|
|
4768
|
-
required: false,
|
|
4769
|
-
schema: { type: "string" }
|
|
4770
|
-
},
|
|
4771
|
-
{
|
|
4772
|
-
name: "id",
|
|
4773
|
-
description: "Todo id (update/complete/cancel/delete).",
|
|
4774
|
-
required: false,
|
|
4775
|
-
schema: { type: "string" }
|
|
4776
|
-
},
|
|
4777
|
-
{
|
|
4778
|
-
name: "content",
|
|
4779
|
-
description: "Imperative form, e.g. 'Add tests' (create/update).",
|
|
4780
|
-
required: false,
|
|
4781
|
-
schema: { type: "string" }
|
|
4782
|
-
},
|
|
4783
|
-
{
|
|
4784
|
-
name: "activeForm",
|
|
4785
|
-
description: "Present-continuous form, e.g. 'Adding tests' (create/update).",
|
|
4786
|
-
required: false,
|
|
4787
|
-
schema: { type: "string" }
|
|
4788
|
-
},
|
|
4789
|
-
{
|
|
4790
|
-
name: "status",
|
|
4791
|
-
description: "pending | in_progress | completed | cancelled.",
|
|
4792
|
-
required: false,
|
|
4793
|
-
schema: { type: "string", enum: [...TODO_STATUSES] }
|
|
4794
|
-
},
|
|
4795
|
-
{
|
|
4796
|
-
name: "parentTodoId",
|
|
4797
|
-
description: "Parent todo id for sub-tasks (create/update).",
|
|
4798
|
-
required: false,
|
|
4799
|
-
schema: { type: "string" }
|
|
4800
|
-
},
|
|
4801
|
-
{
|
|
4802
|
-
name: "todos",
|
|
4803
|
-
description: "Array of {id?, content, status, activeForm?} for action=write. Replaces the user's list for this conversation.",
|
|
4804
|
-
required: false,
|
|
4805
|
-
schema: {
|
|
4806
|
-
type: "array",
|
|
4807
|
-
items: {
|
|
4808
|
-
type: "object",
|
|
4809
|
-
properties: {
|
|
4810
|
-
id: { type: "string" },
|
|
4811
|
-
content: { type: "string" },
|
|
4812
|
-
status: { type: "string", enum: [...TODO_STATUSES] },
|
|
4813
|
-
activeForm: { type: "string" }
|
|
4814
|
-
},
|
|
4815
|
-
required: ["content", "status"]
|
|
4816
|
-
}
|
|
4817
|
-
}
|
|
4818
|
-
},
|
|
4819
|
-
{
|
|
4820
|
-
name: "includeCompleted",
|
|
4821
|
-
description: "Include completed/cancelled todos in action=list output.",
|
|
4822
|
-
required: false,
|
|
4823
|
-
schema: { type: "boolean" }
|
|
4824
|
-
},
|
|
4825
|
-
{
|
|
4826
|
-
name: "limit",
|
|
4827
|
-
description: "Max rows to return for action=list.",
|
|
4828
|
-
required: false,
|
|
4829
|
-
schema: { type: "number" }
|
|
4830
|
-
}
|
|
4831
|
-
],
|
|
4832
|
-
validate: async (runtime) => Boolean(getTodosService(runtime)),
|
|
4833
|
-
handler: async (runtime, message, _state, options, callback) => {
|
|
4834
|
-
const params = options?.parameters ?? {};
|
|
4835
|
-
const op = readOp(params.action ?? params.subaction ?? params.op);
|
|
4836
|
-
if (!op) {
|
|
4837
|
-
return failure("missing_param", `action is required (one of: ${TODO_OPS.join(", ")})`);
|
|
4838
|
-
}
|
|
4839
|
-
const scope = readScope(runtime, message);
|
|
4840
|
-
if ("error" in scope) {
|
|
4841
|
-
return failure("missing_param", scope.error);
|
|
4842
|
-
}
|
|
4843
|
-
const service = getTodosService(runtime);
|
|
4844
|
-
const args = { service, scope, params, callback };
|
|
4845
|
-
switch (op) {
|
|
4846
|
-
case "write":
|
|
4847
|
-
return opWrite(args);
|
|
4848
|
-
case "create":
|
|
4849
|
-
return opCreate(args);
|
|
4850
|
-
case "update":
|
|
4851
|
-
return opUpdate(args);
|
|
4852
|
-
case "complete":
|
|
4853
|
-
return opSetStatus(args, "completed", "complete");
|
|
4854
|
-
case "cancel":
|
|
4855
|
-
return opSetStatus(args, "cancelled", "cancel");
|
|
4856
|
-
case "delete":
|
|
4857
|
-
return opDelete(args);
|
|
4858
|
-
case "list":
|
|
4859
|
-
return opList(args);
|
|
4860
|
-
case "clear":
|
|
4861
|
-
return opClear(args);
|
|
4862
|
-
}
|
|
4863
|
-
},
|
|
4864
|
-
examples: [
|
|
4865
|
-
[
|
|
4866
|
-
{
|
|
4867
|
-
name: "{{name1}}",
|
|
4868
|
-
content: { text: "Add 'review PR feedback' to my todo list.", source: "chat" }
|
|
4869
|
-
},
|
|
4870
|
-
{
|
|
4871
|
-
name: "{{agentName}}",
|
|
4872
|
-
content: {
|
|
4873
|
-
text: "Adding the todo.",
|
|
4874
|
-
actions: ["TODO"],
|
|
4875
|
-
thought: "Single-todo creation maps to TODO subaction=create with content set."
|
|
4876
|
-
}
|
|
4877
|
-
}
|
|
4878
|
-
],
|
|
4879
|
-
[
|
|
4880
|
-
{
|
|
4881
|
-
name: "{{name1}}",
|
|
4882
|
-
content: { text: "Show my todos that are still pending.", source: "chat" }
|
|
4883
|
-
},
|
|
4884
|
-
{
|
|
4885
|
-
name: "{{agentName}}",
|
|
4886
|
-
content: {
|
|
4887
|
-
text: "Listing your pending todos.",
|
|
4888
|
-
actions: ["TODO"],
|
|
4889
|
-
thought: "List query maps to TODO subaction=list with includeCompleted=false."
|
|
4890
|
-
}
|
|
4891
|
-
}
|
|
4892
|
-
],
|
|
4893
|
-
[
|
|
4894
|
-
{
|
|
4895
|
-
name: "{{name1}}",
|
|
4896
|
-
content: { text: "Cancel todo abc-123.", source: "chat" }
|
|
4897
|
-
},
|
|
4898
|
-
{
|
|
4899
|
-
name: "{{agentName}}",
|
|
4900
|
-
content: {
|
|
4901
|
-
text: "Cancelling that todo.",
|
|
4902
|
-
actions: ["TODO"],
|
|
4903
|
-
thought: "Cancel intent on a specific id maps to TODO subaction=cancel with id=abc-123."
|
|
4904
|
-
}
|
|
4905
|
-
}
|
|
4906
|
-
]
|
|
4907
|
-
]
|
|
4908
|
-
};
|
|
4909
|
-
|
|
4910
|
-
// src/db/index.ts
|
|
4911
|
-
var exports_db = {};
|
|
4912
|
-
__export(exports_db, {
|
|
4913
|
-
todosTable: () => todosTable,
|
|
4914
|
-
todosSchema: () => todosSchema
|
|
4915
|
-
});
|
|
4916
|
-
|
|
4917
|
-
// src/providers/current-todos.ts
|
|
4918
|
-
function checkboxFor2(status) {
|
|
4919
|
-
switch (status) {
|
|
4920
|
-
case "completed":
|
|
4921
|
-
return "[x]";
|
|
4922
|
-
case "in_progress":
|
|
4923
|
-
return "[→]";
|
|
4924
|
-
case "cancelled":
|
|
4925
|
-
return "[-]";
|
|
4926
|
-
default:
|
|
4927
|
-
return "[ ]";
|
|
4928
|
-
}
|
|
4929
|
-
}
|
|
4930
|
-
var currentTodosProvider = {
|
|
4931
|
-
name: "CURRENT_TODOS",
|
|
4932
|
-
description: "The user's current pending and in-progress todos.",
|
|
4933
|
-
position: -5,
|
|
4934
|
-
contexts: [...TODOS_CONTEXTS],
|
|
4935
|
-
contextGate: { anyOf: [...TODOS_CONTEXTS] },
|
|
4936
|
-
get: async (runtime, message, _state) => {
|
|
4937
|
-
const entityId = message.entityId;
|
|
4938
|
-
if (!entityId)
|
|
4939
|
-
return { text: "", data: { todos: [] } };
|
|
4940
|
-
const service = runtime.getService(TODOS_SERVICE_TYPE);
|
|
4941
|
-
if (!service)
|
|
4942
|
-
return { text: "", data: { todos: [] } };
|
|
4943
|
-
const todos = await service.list({
|
|
4944
|
-
entityId: String(entityId),
|
|
4945
|
-
agentId: String(runtime.agentId),
|
|
4946
|
-
includeCompleted: false
|
|
4947
|
-
});
|
|
4948
|
-
if (todos.length === 0)
|
|
4949
|
-
return { text: "", data: { todos: [] } };
|
|
4950
|
-
const lines = [
|
|
4951
|
-
"# Current todos",
|
|
4952
|
-
"",
|
|
4953
|
-
...todos.map((t) => `- ${checkboxFor2(t.status)} ${t.content}`)
|
|
4954
|
-
];
|
|
4955
|
-
return {
|
|
4956
|
-
text: lines.join(`
|
|
4957
|
-
`),
|
|
4958
|
-
data: { todos }
|
|
4959
|
-
};
|
|
4960
|
-
}
|
|
4961
|
-
};
|
|
4962
|
-
|
|
4963
|
-
// src/index.ts
|
|
4964
|
-
var todosPlugin = {
|
|
4965
|
-
name: "todos",
|
|
4966
|
-
description: "User-scoped persistent todos with CRUD. Single `TODO` umbrella action with op-based dispatch (write/create/update/complete/cancel/delete/list/clear). The currentTodosProvider surfaces the user's pending + in-progress todos to the planner each turn. Backed by a drizzle pgSchema('todos') table; requires @elizaos/plugin-sql.",
|
|
4967
|
-
dependencies: ["@elizaos/plugin-sql"],
|
|
4968
|
-
actions: [todoAction],
|
|
4969
|
-
providers: [currentTodosProvider],
|
|
4970
|
-
services: [TodosService],
|
|
4971
|
-
schema: exports_db
|
|
4972
|
-
};
|
|
4973
|
-
var src_default = todosPlugin;
|
|
4974
|
-
export {
|
|
4975
|
-
todosTable,
|
|
4976
|
-
todosSchema,
|
|
4977
|
-
todosPlugin,
|
|
4978
|
-
todoAction,
|
|
4979
|
-
getTodosService,
|
|
4980
|
-
src_default as default,
|
|
4981
|
-
currentTodosProvider,
|
|
4982
|
-
TodosService,
|
|
4983
|
-
TODO_STATUSES,
|
|
4984
|
-
TODO_OPS,
|
|
4985
|
-
TODO_FAILURE_TEXT_PREFIX,
|
|
4986
|
-
TODOS_SERVICE_TYPE,
|
|
4987
|
-
TODOS_LOG_PREFIX,
|
|
4988
|
-
TODOS_CONTEXTS
|
|
4989
|
-
};
|
|
4990
|
-
|
|
4991
|
-
//# debugId=ACA6192F9EC0C45364756E2164756E21
|