zen-code 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,592 @@
1
+ import { N as v, Q as u } from "./kysely-Bchvsze0.mjs";
2
+ import { bb as p, aN as h, ai as N, a_ as c, aS as n, b8 as d, l as m, bc as o, bd as l, aF as b, be as y, bf as g, bg as C, bh as L, c as O } from "./sql-CJsUpKEQ.mjs";
3
+ class x {
4
+ nodeStack = [];
5
+ get parentNode() {
6
+ return this.nodeStack[this.nodeStack.length - 2];
7
+ }
8
+ #i = p({
9
+ AliasNode: this.visitAlias.bind(this),
10
+ ColumnNode: this.visitColumn.bind(this),
11
+ IdentifierNode: this.visitIdentifier.bind(this),
12
+ SchemableIdentifierNode: this.visitSchemableIdentifier.bind(this),
13
+ RawNode: this.visitRaw.bind(this),
14
+ ReferenceNode: this.visitReference.bind(this),
15
+ SelectQueryNode: this.visitSelectQuery.bind(this),
16
+ SelectionNode: this.visitSelection.bind(this),
17
+ TableNode: this.visitTable.bind(this),
18
+ FromNode: this.visitFrom.bind(this),
19
+ SelectAllNode: this.visitSelectAll.bind(this),
20
+ AndNode: this.visitAnd.bind(this),
21
+ OrNode: this.visitOr.bind(this),
22
+ ValueNode: this.visitValue.bind(this),
23
+ ValueListNode: this.visitValueList.bind(this),
24
+ PrimitiveValueListNode: this.visitPrimitiveValueList.bind(this),
25
+ ParensNode: this.visitParens.bind(this),
26
+ JoinNode: this.visitJoin.bind(this),
27
+ OperatorNode: this.visitOperator.bind(this),
28
+ WhereNode: this.visitWhere.bind(this),
29
+ InsertQueryNode: this.visitInsertQuery.bind(this),
30
+ DeleteQueryNode: this.visitDeleteQuery.bind(this),
31
+ ReturningNode: this.visitReturning.bind(this),
32
+ CreateTableNode: this.visitCreateTable.bind(this),
33
+ AddColumnNode: this.visitAddColumn.bind(this),
34
+ ColumnDefinitionNode: this.visitColumnDefinition.bind(this),
35
+ DropTableNode: this.visitDropTable.bind(this),
36
+ DataTypeNode: this.visitDataType.bind(this),
37
+ OrderByNode: this.visitOrderBy.bind(this),
38
+ OrderByItemNode: this.visitOrderByItem.bind(this),
39
+ GroupByNode: this.visitGroupBy.bind(this),
40
+ GroupByItemNode: this.visitGroupByItem.bind(this),
41
+ UpdateQueryNode: this.visitUpdateQuery.bind(this),
42
+ ColumnUpdateNode: this.visitColumnUpdate.bind(this),
43
+ LimitNode: this.visitLimit.bind(this),
44
+ OffsetNode: this.visitOffset.bind(this),
45
+ OnConflictNode: this.visitOnConflict.bind(this),
46
+ OnDuplicateKeyNode: this.visitOnDuplicateKey.bind(this),
47
+ CreateIndexNode: this.visitCreateIndex.bind(this),
48
+ DropIndexNode: this.visitDropIndex.bind(this),
49
+ ListNode: this.visitList.bind(this),
50
+ PrimaryKeyConstraintNode: this.visitPrimaryKeyConstraint.bind(this),
51
+ UniqueConstraintNode: this.visitUniqueConstraint.bind(this),
52
+ ReferencesNode: this.visitReferences.bind(this),
53
+ CheckConstraintNode: this.visitCheckConstraint.bind(this),
54
+ WithNode: this.visitWith.bind(this),
55
+ CommonTableExpressionNode: this.visitCommonTableExpression.bind(this),
56
+ CommonTableExpressionNameNode: this.visitCommonTableExpressionName.bind(this),
57
+ HavingNode: this.visitHaving.bind(this),
58
+ CreateSchemaNode: this.visitCreateSchema.bind(this),
59
+ DropSchemaNode: this.visitDropSchema.bind(this),
60
+ AlterTableNode: this.visitAlterTable.bind(this),
61
+ DropColumnNode: this.visitDropColumn.bind(this),
62
+ RenameColumnNode: this.visitRenameColumn.bind(this),
63
+ AlterColumnNode: this.visitAlterColumn.bind(this),
64
+ ModifyColumnNode: this.visitModifyColumn.bind(this),
65
+ AddConstraintNode: this.visitAddConstraint.bind(this),
66
+ DropConstraintNode: this.visitDropConstraint.bind(this),
67
+ RenameConstraintNode: this.visitRenameConstraint.bind(this),
68
+ ForeignKeyConstraintNode: this.visitForeignKeyConstraint.bind(this),
69
+ CreateViewNode: this.visitCreateView.bind(this),
70
+ RefreshMaterializedViewNode: this.visitRefreshMaterializedView.bind(this),
71
+ DropViewNode: this.visitDropView.bind(this),
72
+ GeneratedNode: this.visitGenerated.bind(this),
73
+ DefaultValueNode: this.visitDefaultValue.bind(this),
74
+ OnNode: this.visitOn.bind(this),
75
+ ValuesNode: this.visitValues.bind(this),
76
+ SelectModifierNode: this.visitSelectModifier.bind(this),
77
+ CreateTypeNode: this.visitCreateType.bind(this),
78
+ DropTypeNode: this.visitDropType.bind(this),
79
+ ExplainNode: this.visitExplain.bind(this),
80
+ DefaultInsertValueNode: this.visitDefaultInsertValue.bind(this),
81
+ AggregateFunctionNode: this.visitAggregateFunction.bind(this),
82
+ OverNode: this.visitOver.bind(this),
83
+ PartitionByNode: this.visitPartitionBy.bind(this),
84
+ PartitionByItemNode: this.visitPartitionByItem.bind(this),
85
+ SetOperationNode: this.visitSetOperation.bind(this),
86
+ BinaryOperationNode: this.visitBinaryOperation.bind(this),
87
+ UnaryOperationNode: this.visitUnaryOperation.bind(this),
88
+ UsingNode: this.visitUsing.bind(this),
89
+ FunctionNode: this.visitFunction.bind(this),
90
+ CaseNode: this.visitCase.bind(this),
91
+ WhenNode: this.visitWhen.bind(this),
92
+ JSONReferenceNode: this.visitJSONReference.bind(this),
93
+ JSONPathNode: this.visitJSONPath.bind(this),
94
+ JSONPathLegNode: this.visitJSONPathLeg.bind(this),
95
+ JSONOperatorChainNode: this.visitJSONOperatorChain.bind(this),
96
+ TupleNode: this.visitTuple.bind(this),
97
+ MergeQueryNode: this.visitMergeQuery.bind(this),
98
+ MatchedNode: this.visitMatched.bind(this),
99
+ AddIndexNode: this.visitAddIndex.bind(this),
100
+ CastNode: this.visitCast.bind(this),
101
+ FetchNode: this.visitFetch.bind(this),
102
+ TopNode: this.visitTop.bind(this),
103
+ OutputNode: this.visitOutput.bind(this),
104
+ OrActionNode: this.visitOrAction.bind(this),
105
+ CollateNode: this.visitCollate.bind(this)
106
+ });
107
+ visitNode = (i) => {
108
+ this.nodeStack.push(i), this.#i[i.kind](i), this.nodeStack.pop();
109
+ };
110
+ }
111
+ const I = /'/g;
112
+ class A extends x {
113
+ #i = "";
114
+ #t = [];
115
+ get numParameters() {
116
+ return this.#t.length;
117
+ }
118
+ compileQuery(i, t) {
119
+ return this.#i = "", this.#t = [], this.nodeStack.splice(0, this.nodeStack.length), this.visitNode(i), p({
120
+ query: i,
121
+ queryId: t,
122
+ sql: this.getSql(),
123
+ parameters: [...this.#t]
124
+ });
125
+ }
126
+ getSql() {
127
+ return this.#i;
128
+ }
129
+ visitSelectQuery(i) {
130
+ const t = this.parentNode !== void 0 && !h.is(this.parentNode) && !N.is(this.parentNode) && !v.is(this.parentNode) && !u.is(this.parentNode) && !c.is(this.parentNode);
131
+ this.parentNode === void 0 && i.explain && (this.visitNode(i.explain), this.append(" ")), t && this.append("("), i.with && (this.visitNode(i.with), this.append(" ")), this.append("select"), i.distinctOn && (this.append(" "), this.compileDistinctOn(i.distinctOn)), i.frontModifiers?.length && (this.append(" "), this.compileList(i.frontModifiers, " ")), i.top && (this.append(" "), this.visitNode(i.top)), i.selections && (this.append(" "), this.compileList(i.selections)), i.from && (this.append(" "), this.visitNode(i.from)), i.joins && (this.append(" "), this.compileList(i.joins, " ")), i.where && (this.append(" "), this.visitNode(i.where)), i.groupBy && (this.append(" "), this.visitNode(i.groupBy)), i.having && (this.append(" "), this.visitNode(i.having)), i.setOperations && (this.append(" "), this.compileList(i.setOperations, " ")), i.orderBy && (this.append(" "), this.visitNode(i.orderBy)), i.limit && (this.append(" "), this.visitNode(i.limit)), i.offset && (this.append(" "), this.visitNode(i.offset)), i.fetch && (this.append(" "), this.visitNode(i.fetch)), i.endModifiers?.length && (this.append(" "), this.compileList(this.sortSelectModifiers([...i.endModifiers]), " ")), t && this.append(")");
132
+ }
133
+ visitFrom(i) {
134
+ this.append("from "), this.compileList(i.froms);
135
+ }
136
+ visitSelection(i) {
137
+ this.visitNode(i.selection);
138
+ }
139
+ visitColumn(i) {
140
+ this.visitNode(i.column);
141
+ }
142
+ compileDistinctOn(i) {
143
+ this.append("distinct on ("), this.compileList(i), this.append(")");
144
+ }
145
+ compileList(i, t = ", ") {
146
+ const s = i.length - 1;
147
+ for (let e = 0; e <= s; e++)
148
+ this.visitNode(i[e]), e < s && this.append(t);
149
+ }
150
+ visitWhere(i) {
151
+ this.append("where "), this.visitNode(i.where);
152
+ }
153
+ visitHaving(i) {
154
+ this.append("having "), this.visitNode(i.having);
155
+ }
156
+ visitInsertQuery(i) {
157
+ const t = this.parentNode !== void 0 && !h.is(this.parentNode) && !n.is(this.parentNode) && !d.is(this.parentNode);
158
+ this.parentNode === void 0 && i.explain && (this.visitNode(i.explain), this.append(" ")), t && this.append("("), i.with && (this.visitNode(i.with), this.append(" ")), this.append(i.replace ? "replace" : "insert"), i.ignore && (m("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."), this.append(" ignore")), i.orAction && (this.append(" "), this.visitNode(i.orAction)), i.top && (this.append(" "), this.visitNode(i.top)), i.into && (this.append(" into "), this.visitNode(i.into)), i.columns && (this.append(" ("), this.compileList(i.columns), this.append(")")), i.output && (this.append(" "), this.visitNode(i.output)), i.values && (this.append(" "), this.visitNode(i.values)), i.defaultValues && (this.append(" "), this.append("default values")), i.onConflict && (this.append(" "), this.visitNode(i.onConflict)), i.onDuplicateKey && (this.append(" "), this.visitNode(i.onDuplicateKey)), i.returning && (this.append(" "), this.visitNode(i.returning)), t && this.append(")"), i.endModifiers?.length && (this.append(" "), this.compileList(i.endModifiers, " "));
159
+ }
160
+ visitValues(i) {
161
+ this.append("values "), this.compileList(i.values);
162
+ }
163
+ visitDeleteQuery(i) {
164
+ const t = this.parentNode !== void 0 && !h.is(this.parentNode) && !n.is(this.parentNode);
165
+ this.parentNode === void 0 && i.explain && (this.visitNode(i.explain), this.append(" ")), t && this.append("("), i.with && (this.visitNode(i.with), this.append(" ")), this.append("delete "), i.top && (this.visitNode(i.top), this.append(" ")), this.visitNode(i.from), i.output && (this.append(" "), this.visitNode(i.output)), i.using && (this.append(" "), this.visitNode(i.using)), i.joins && (this.append(" "), this.compileList(i.joins, " ")), i.where && (this.append(" "), this.visitNode(i.where)), i.orderBy && (this.append(" "), this.visitNode(i.orderBy)), i.limit && (this.append(" "), this.visitNode(i.limit)), i.returning && (this.append(" "), this.visitNode(i.returning)), t && this.append(")"), i.endModifiers?.length && (this.append(" "), this.compileList(i.endModifiers, " "));
166
+ }
167
+ visitReturning(i) {
168
+ this.append("returning "), this.compileList(i.selections);
169
+ }
170
+ visitAlias(i) {
171
+ this.visitNode(i.node), this.append(" as "), this.visitNode(i.alias);
172
+ }
173
+ visitReference(i) {
174
+ i.table && (this.visitNode(i.table), this.append(".")), this.visitNode(i.column);
175
+ }
176
+ visitSelectAll(i) {
177
+ this.append("*");
178
+ }
179
+ visitIdentifier(i) {
180
+ this.append(this.getLeftIdentifierWrapper()), this.compileUnwrappedIdentifier(i), this.append(this.getRightIdentifierWrapper());
181
+ }
182
+ compileUnwrappedIdentifier(i) {
183
+ if (!o(i.name))
184
+ throw new Error("a non-string identifier was passed to compileUnwrappedIdentifier.");
185
+ this.append(this.sanitizeIdentifier(i.name));
186
+ }
187
+ visitAnd(i) {
188
+ this.visitNode(i.left), this.append(" and "), this.visitNode(i.right);
189
+ }
190
+ visitOr(i) {
191
+ this.visitNode(i.left), this.append(" or "), this.visitNode(i.right);
192
+ }
193
+ visitValue(i) {
194
+ i.immediate ? this.appendImmediateValue(i.value) : this.appendValue(i.value);
195
+ }
196
+ visitValueList(i) {
197
+ this.append("("), this.compileList(i.values), this.append(")");
198
+ }
199
+ visitTuple(i) {
200
+ this.append("("), this.compileList(i.values), this.append(")");
201
+ }
202
+ visitPrimitiveValueList(i) {
203
+ this.append("(");
204
+ const { values: t } = i;
205
+ for (let s = 0; s < t.length; ++s)
206
+ this.appendValue(t[s]), s !== t.length - 1 && this.append(", ");
207
+ this.append(")");
208
+ }
209
+ visitParens(i) {
210
+ this.append("("), this.visitNode(i.node), this.append(")");
211
+ }
212
+ visitJoin(i) {
213
+ this.append(w[i.joinType]), this.append(" "), this.visitNode(i.table), i.on && (this.append(" "), this.visitNode(i.on));
214
+ }
215
+ visitOn(i) {
216
+ this.append("on "), this.visitNode(i.on);
217
+ }
218
+ visitRaw(i) {
219
+ const { sqlFragments: t, parameters: s } = i;
220
+ for (let e = 0; e < t.length; ++e)
221
+ this.append(t[e]), s.length > e && this.visitNode(s[e]);
222
+ }
223
+ visitOperator(i) {
224
+ this.append(i.operator);
225
+ }
226
+ visitTable(i) {
227
+ this.visitNode(i.table);
228
+ }
229
+ visitSchemableIdentifier(i) {
230
+ i.schema && (this.visitNode(i.schema), this.append(".")), this.visitNode(i.identifier);
231
+ }
232
+ visitCreateTable(i) {
233
+ this.append("create "), i.frontModifiers && i.frontModifiers.length > 0 && (this.compileList(i.frontModifiers, " "), this.append(" ")), i.temporary && this.append("temporary "), this.append("table "), i.ifNotExists && this.append("if not exists "), this.visitNode(i.table), i.selectQuery ? (this.append(" as "), this.visitNode(i.selectQuery)) : (this.append(" ("), this.compileList([...i.columns, ...i.constraints ?? []]), this.append(")"), i.onCommit && (this.append(" on commit "), this.append(i.onCommit)), i.endModifiers && i.endModifiers.length > 0 && (this.append(" "), this.compileList(i.endModifiers, " ")));
234
+ }
235
+ visitColumnDefinition(i) {
236
+ i.ifNotExists && this.append("if not exists "), this.visitNode(i.column), this.append(" "), this.visitNode(i.dataType), i.unsigned && this.append(" unsigned"), i.frontModifiers && i.frontModifiers.length > 0 && (this.append(" "), this.compileList(i.frontModifiers, " ")), i.generated && (this.append(" "), this.visitNode(i.generated)), i.identity && this.append(" identity"), i.defaultTo && (this.append(" "), this.visitNode(i.defaultTo)), i.notNull && this.append(" not null"), i.unique && this.append(" unique"), i.nullsNotDistinct && this.append(" nulls not distinct"), i.primaryKey && this.append(" primary key"), i.autoIncrement && (this.append(" "), this.append(this.getAutoIncrement())), i.references && (this.append(" "), this.visitNode(i.references)), i.check && (this.append(" "), this.visitNode(i.check)), i.endModifiers && i.endModifiers.length > 0 && (this.append(" "), this.compileList(i.endModifiers, " "));
237
+ }
238
+ getAutoIncrement() {
239
+ return "auto_increment";
240
+ }
241
+ visitReferences(i) {
242
+ this.append("references "), this.visitNode(i.table), this.append(" ("), this.compileList(i.columns), this.append(")"), i.onDelete && (this.append(" on delete "), this.append(i.onDelete)), i.onUpdate && (this.append(" on update "), this.append(i.onUpdate));
243
+ }
244
+ visitDropTable(i) {
245
+ this.append("drop table "), i.ifExists && this.append("if exists "), this.visitNode(i.table), i.cascade && this.append(" cascade");
246
+ }
247
+ visitDataType(i) {
248
+ this.append(i.dataType);
249
+ }
250
+ visitOrderBy(i) {
251
+ this.append("order by "), this.compileList(i.items);
252
+ }
253
+ visitOrderByItem(i) {
254
+ this.visitNode(i.orderBy), i.collation && (this.append(" "), this.visitNode(i.collation)), i.direction && (this.append(" "), this.visitNode(i.direction)), i.nulls && (this.append(" nulls "), this.append(i.nulls));
255
+ }
256
+ visitGroupBy(i) {
257
+ this.append("group by "), this.compileList(i.items);
258
+ }
259
+ visitGroupByItem(i) {
260
+ this.visitNode(i.groupBy);
261
+ }
262
+ visitUpdateQuery(i) {
263
+ const t = this.parentNode !== void 0 && !h.is(this.parentNode) && !n.is(this.parentNode) && !d.is(this.parentNode);
264
+ if (this.parentNode === void 0 && i.explain && (this.visitNode(i.explain), this.append(" ")), t && this.append("("), i.with && (this.visitNode(i.with), this.append(" ")), this.append("update "), i.top && (this.visitNode(i.top), this.append(" ")), i.table && (this.visitNode(i.table), this.append(" ")), this.append("set "), i.updates && this.compileList(i.updates), i.output && (this.append(" "), this.visitNode(i.output)), i.from && (this.append(" "), this.visitNode(i.from)), i.joins) {
265
+ if (!i.from)
266
+ throw new Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");
267
+ this.append(" "), this.compileList(i.joins, " ");
268
+ }
269
+ i.where && (this.append(" "), this.visitNode(i.where)), i.orderBy && (this.append(" "), this.visitNode(i.orderBy)), i.limit && (this.append(" "), this.visitNode(i.limit)), i.returning && (this.append(" "), this.visitNode(i.returning)), t && this.append(")"), i.endModifiers?.length && (this.append(" "), this.compileList(i.endModifiers, " "));
270
+ }
271
+ visitColumnUpdate(i) {
272
+ this.visitNode(i.column), this.append(" = "), this.visitNode(i.value);
273
+ }
274
+ visitLimit(i) {
275
+ this.append("limit "), this.visitNode(i.limit);
276
+ }
277
+ visitOffset(i) {
278
+ this.append("offset "), this.visitNode(i.offset);
279
+ }
280
+ visitOnConflict(i) {
281
+ this.append("on conflict"), i.columns ? (this.append(" ("), this.compileList(i.columns), this.append(")")) : i.constraint ? (this.append(" on constraint "), this.visitNode(i.constraint)) : i.indexExpression && (this.append(" ("), this.visitNode(i.indexExpression), this.append(")")), i.indexWhere && (this.append(" "), this.visitNode(i.indexWhere)), i.doNothing === !0 ? this.append(" do nothing") : i.updates && (this.append(" do update set "), this.compileList(i.updates), i.updateWhere && (this.append(" "), this.visitNode(i.updateWhere)));
282
+ }
283
+ visitOnDuplicateKey(i) {
284
+ this.append("on duplicate key update "), this.compileList(i.updates);
285
+ }
286
+ visitCreateIndex(i) {
287
+ this.append("create "), i.unique && this.append("unique "), this.append("index "), i.ifNotExists && this.append("if not exists "), this.visitNode(i.name), i.table && (this.append(" on "), this.visitNode(i.table)), i.using && (this.append(" using "), this.visitNode(i.using)), i.columns && (this.append(" ("), this.compileList(i.columns), this.append(")")), i.nullsNotDistinct && this.append(" nulls not distinct"), i.where && (this.append(" "), this.visitNode(i.where));
288
+ }
289
+ visitDropIndex(i) {
290
+ this.append("drop index "), i.ifExists && this.append("if exists "), this.visitNode(i.name), i.table && (this.append(" on "), this.visitNode(i.table)), i.cascade && this.append(" cascade");
291
+ }
292
+ visitCreateSchema(i) {
293
+ this.append("create schema "), i.ifNotExists && this.append("if not exists "), this.visitNode(i.schema);
294
+ }
295
+ visitDropSchema(i) {
296
+ this.append("drop schema "), i.ifExists && this.append("if exists "), this.visitNode(i.schema), i.cascade && this.append(" cascade");
297
+ }
298
+ visitPrimaryKeyConstraint(i) {
299
+ i.name && (this.append("constraint "), this.visitNode(i.name), this.append(" ")), this.append("primary key ("), this.compileList(i.columns), this.append(")"), this.buildDeferrable(i);
300
+ }
301
+ buildDeferrable(i) {
302
+ i.deferrable !== void 0 && (i.deferrable ? this.append(" deferrable") : this.append(" not deferrable")), i.initiallyDeferred !== void 0 && (i.initiallyDeferred ? this.append(" initially deferred") : this.append(" initially immediate"));
303
+ }
304
+ visitUniqueConstraint(i) {
305
+ i.name && (this.append("constraint "), this.visitNode(i.name), this.append(" ")), this.append("unique"), i.nullsNotDistinct && this.append(" nulls not distinct"), this.append(" ("), this.compileList(i.columns), this.append(")"), this.buildDeferrable(i);
306
+ }
307
+ visitCheckConstraint(i) {
308
+ i.name && (this.append("constraint "), this.visitNode(i.name), this.append(" ")), this.append("check ("), this.visitNode(i.expression), this.append(")");
309
+ }
310
+ visitForeignKeyConstraint(i) {
311
+ i.name && (this.append("constraint "), this.visitNode(i.name), this.append(" ")), this.append("foreign key ("), this.compileList(i.columns), this.append(") "), this.visitNode(i.references), i.onDelete && (this.append(" on delete "), this.append(i.onDelete)), i.onUpdate && (this.append(" on update "), this.append(i.onUpdate)), this.buildDeferrable(i);
312
+ }
313
+ visitList(i) {
314
+ this.compileList(i.items);
315
+ }
316
+ visitWith(i) {
317
+ this.append("with "), i.recursive && this.append("recursive "), this.compileList(i.expressions);
318
+ }
319
+ visitCommonTableExpression(i) {
320
+ this.visitNode(i.name), this.append(" as "), l(i.materialized) && (i.materialized || this.append("not "), this.append("materialized ")), this.visitNode(i.expression);
321
+ }
322
+ visitCommonTableExpressionName(i) {
323
+ this.visitNode(i.table), i.columns && (this.append("("), this.compileList(i.columns), this.append(")"));
324
+ }
325
+ visitAlterTable(i) {
326
+ this.append("alter table "), this.visitNode(i.table), this.append(" "), i.renameTo && (this.append("rename to "), this.visitNode(i.renameTo)), i.setSchema && (this.append("set schema "), this.visitNode(i.setSchema)), i.addConstraint && this.visitNode(i.addConstraint), i.dropConstraint && this.visitNode(i.dropConstraint), i.renameConstraint && this.visitNode(i.renameConstraint), i.columnAlterations && this.compileColumnAlterations(i.columnAlterations), i.addIndex && this.visitNode(i.addIndex), i.dropIndex && this.visitNode(i.dropIndex);
327
+ }
328
+ visitAddColumn(i) {
329
+ this.append("add column "), this.visitNode(i.column);
330
+ }
331
+ visitRenameColumn(i) {
332
+ this.append("rename column "), this.visitNode(i.column), this.append(" to "), this.visitNode(i.renameTo);
333
+ }
334
+ visitDropColumn(i) {
335
+ this.append("drop column "), this.visitNode(i.column);
336
+ }
337
+ visitAlterColumn(i) {
338
+ this.append("alter column "), this.visitNode(i.column), this.append(" "), i.dataType && (this.announcesNewColumnDataType() && this.append("type "), this.visitNode(i.dataType), i.dataTypeExpression && (this.append("using "), this.visitNode(i.dataTypeExpression))), i.setDefault && (this.append("set default "), this.visitNode(i.setDefault)), i.dropDefault && this.append("drop default"), i.setNotNull && this.append("set not null"), i.dropNotNull && this.append("drop not null");
339
+ }
340
+ visitModifyColumn(i) {
341
+ this.append("modify column "), this.visitNode(i.column);
342
+ }
343
+ visitAddConstraint(i) {
344
+ this.append("add "), this.visitNode(i.constraint);
345
+ }
346
+ visitDropConstraint(i) {
347
+ this.append("drop constraint "), i.ifExists && this.append("if exists "), this.visitNode(i.constraintName), i.modifier === "cascade" ? this.append(" cascade") : i.modifier === "restrict" && this.append(" restrict");
348
+ }
349
+ visitRenameConstraint(i) {
350
+ this.append("rename constraint "), this.visitNode(i.oldName), this.append(" to "), this.visitNode(i.newName);
351
+ }
352
+ visitSetOperation(i) {
353
+ this.append(i.operator), this.append(" "), i.all && this.append("all "), this.visitNode(i.expression);
354
+ }
355
+ visitCreateView(i) {
356
+ this.append("create "), i.orReplace && this.append("or replace "), i.materialized && this.append("materialized "), i.temporary && this.append("temporary "), this.append("view "), i.ifNotExists && this.append("if not exists "), this.visitNode(i.name), this.append(" "), i.columns && (this.append("("), this.compileList(i.columns), this.append(") ")), i.as && (this.append("as "), this.visitNode(i.as));
357
+ }
358
+ visitRefreshMaterializedView(i) {
359
+ this.append("refresh materialized view "), i.concurrently && this.append("concurrently "), this.visitNode(i.name), i.withNoData ? this.append(" with no data") : this.append(" with data");
360
+ }
361
+ visitDropView(i) {
362
+ this.append("drop "), i.materialized && this.append("materialized "), this.append("view "), i.ifExists && this.append("if exists "), this.visitNode(i.name), i.cascade && this.append(" cascade");
363
+ }
364
+ visitGenerated(i) {
365
+ this.append("generated "), i.always && this.append("always "), i.byDefault && this.append("by default "), this.append("as "), i.identity && this.append("identity"), i.expression && (this.append("("), this.visitNode(i.expression), this.append(")")), i.stored && this.append(" stored");
366
+ }
367
+ visitDefaultValue(i) {
368
+ this.append("default "), this.visitNode(i.defaultValue);
369
+ }
370
+ visitSelectModifier(i) {
371
+ i.rawModifier ? this.visitNode(i.rawModifier) : this.append(D[i.modifier]), i.of && (this.append(" of "), this.compileList(i.of, ", "));
372
+ }
373
+ visitCreateType(i) {
374
+ this.append("create type "), this.visitNode(i.name), i.enum && (this.append(" as enum "), this.visitNode(i.enum));
375
+ }
376
+ visitDropType(i) {
377
+ this.append("drop type "), i.ifExists && this.append("if exists "), this.visitNode(i.name);
378
+ }
379
+ visitExplain(i) {
380
+ this.append("explain"), (i.options || i.format) && (this.append(" "), this.append(this.getLeftExplainOptionsWrapper()), i.options && (this.visitNode(i.options), i.format && this.append(this.getExplainOptionsDelimiter())), i.format && (this.append("format"), this.append(this.getExplainOptionAssignment()), this.append(i.format)), this.append(this.getRightExplainOptionsWrapper()));
381
+ }
382
+ visitDefaultInsertValue(i) {
383
+ this.append("default");
384
+ }
385
+ visitAggregateFunction(i) {
386
+ this.append(i.func), this.append("("), i.distinct && this.append("distinct "), this.compileList(i.aggregated), i.orderBy && (this.append(" "), this.visitNode(i.orderBy)), this.append(")"), i.withinGroup && (this.append(" within group ("), this.visitNode(i.withinGroup), this.append(")")), i.filter && (this.append(" filter("), this.visitNode(i.filter), this.append(")")), i.over && (this.append(" "), this.visitNode(i.over));
387
+ }
388
+ visitOver(i) {
389
+ this.append("over("), i.partitionBy && (this.visitNode(i.partitionBy), i.orderBy && this.append(" ")), i.orderBy && this.visitNode(i.orderBy), this.append(")");
390
+ }
391
+ visitPartitionBy(i) {
392
+ this.append("partition by "), this.compileList(i.items);
393
+ }
394
+ visitPartitionByItem(i) {
395
+ this.visitNode(i.partitionBy);
396
+ }
397
+ visitBinaryOperation(i) {
398
+ this.visitNode(i.leftOperand), this.append(" "), this.visitNode(i.operator), this.append(" "), this.visitNode(i.rightOperand);
399
+ }
400
+ visitUnaryOperation(i) {
401
+ this.visitNode(i.operator), this.isMinusOperator(i.operator) || this.append(" "), this.visitNode(i.operand);
402
+ }
403
+ isMinusOperator(i) {
404
+ return b.is(i) && i.operator === "-";
405
+ }
406
+ visitUsing(i) {
407
+ this.append("using "), this.compileList(i.tables);
408
+ }
409
+ visitFunction(i) {
410
+ this.append(i.func), this.append("("), this.compileList(i.arguments), this.append(")");
411
+ }
412
+ visitCase(i) {
413
+ this.append("case"), i.value && (this.append(" "), this.visitNode(i.value)), i.when && (this.append(" "), this.compileList(i.when, " ")), i.else && (this.append(" else "), this.visitNode(i.else)), this.append(" end"), i.isStatement && this.append(" case");
414
+ }
415
+ visitWhen(i) {
416
+ this.append("when "), this.visitNode(i.condition), i.result && (this.append(" then "), this.visitNode(i.result));
417
+ }
418
+ visitJSONReference(i) {
419
+ this.visitNode(i.reference), this.visitNode(i.traversal);
420
+ }
421
+ visitJSONPath(i) {
422
+ i.inOperator && this.visitNode(i.inOperator), this.append("'$");
423
+ for (const t of i.pathLegs)
424
+ this.visitNode(t);
425
+ this.append("'");
426
+ }
427
+ visitJSONPathLeg(i) {
428
+ const t = i.type === "ArrayLocation";
429
+ this.append(t ? "[" : "."), this.append(String(i.value)), t && this.append("]");
430
+ }
431
+ visitJSONOperatorChain(i) {
432
+ for (let t = 0, s = i.values.length; t < s; t++)
433
+ t === s - 1 ? this.visitNode(i.operator) : this.append("->"), this.visitNode(i.values[t]);
434
+ }
435
+ visitMergeQuery(i) {
436
+ i.with && (this.visitNode(i.with), this.append(" ")), this.append("merge "), i.top && (this.visitNode(i.top), this.append(" ")), this.append("into "), this.visitNode(i.into), i.using && (this.append(" "), this.visitNode(i.using)), i.whens && (this.append(" "), this.compileList(i.whens, " ")), i.returning && (this.append(" "), this.visitNode(i.returning)), i.output && (this.append(" "), this.visitNode(i.output)), i.endModifiers?.length && (this.append(" "), this.compileList(i.endModifiers, " "));
437
+ }
438
+ visitMatched(i) {
439
+ i.not && this.append("not "), this.append("matched"), i.bySource && this.append(" by source");
440
+ }
441
+ visitAddIndex(i) {
442
+ this.append("add "), i.unique && this.append("unique "), this.append("index "), this.visitNode(i.name), i.columns && (this.append(" ("), this.compileList(i.columns), this.append(")")), i.using && (this.append(" using "), this.visitNode(i.using));
443
+ }
444
+ visitCast(i) {
445
+ this.append("cast("), this.visitNode(i.expression), this.append(" as "), this.visitNode(i.dataType), this.append(")");
446
+ }
447
+ visitFetch(i) {
448
+ this.append("fetch next "), this.visitNode(i.rowCount), this.append(` rows ${i.modifier}`);
449
+ }
450
+ visitOutput(i) {
451
+ this.append("output "), this.compileList(i.selections);
452
+ }
453
+ visitTop(i) {
454
+ this.append(`top(${i.expression})`), i.modifiers && this.append(` ${i.modifiers}`);
455
+ }
456
+ visitOrAction(i) {
457
+ this.append(i.action);
458
+ }
459
+ visitCollate(i) {
460
+ this.append("collate "), this.visitNode(i.collation);
461
+ }
462
+ append(i) {
463
+ this.#i += i;
464
+ }
465
+ appendValue(i) {
466
+ this.addParameter(i), this.append(this.getCurrentParameterPlaceholder());
467
+ }
468
+ getLeftIdentifierWrapper() {
469
+ return '"';
470
+ }
471
+ getRightIdentifierWrapper() {
472
+ return '"';
473
+ }
474
+ getCurrentParameterPlaceholder() {
475
+ return "$" + this.numParameters;
476
+ }
477
+ getLeftExplainOptionsWrapper() {
478
+ return "(";
479
+ }
480
+ getExplainOptionAssignment() {
481
+ return " ";
482
+ }
483
+ getExplainOptionsDelimiter() {
484
+ return ", ";
485
+ }
486
+ getRightExplainOptionsWrapper() {
487
+ return ")";
488
+ }
489
+ sanitizeIdentifier(i) {
490
+ const t = this.getLeftIdentifierWrapper(), s = this.getRightIdentifierWrapper();
491
+ let e = "";
492
+ for (const r of i)
493
+ e += r, r === t ? e += t : r === s && (e += s);
494
+ return e;
495
+ }
496
+ sanitizeStringLiteral(i) {
497
+ return i.replace(I, "''");
498
+ }
499
+ addParameter(i) {
500
+ this.#t.push(i);
501
+ }
502
+ appendImmediateValue(i) {
503
+ if (o(i))
504
+ this.appendStringLiteral(i);
505
+ else if (y(i) || l(i) || g(i))
506
+ this.append(i.toString());
507
+ else if (C(i))
508
+ this.append("null");
509
+ else if (L(i))
510
+ this.appendImmediateValue(i.toISOString());
511
+ else
512
+ throw new Error(`invalid immediate value ${i}`);
513
+ }
514
+ appendStringLiteral(i) {
515
+ this.append("'"), this.append(this.sanitizeStringLiteral(i)), this.append("'");
516
+ }
517
+ sortSelectModifiers(i) {
518
+ return i.sort((t, s) => t.modifier && s.modifier ? f[t.modifier] - f[s.modifier] : 1), p(i);
519
+ }
520
+ compileColumnAlterations(i) {
521
+ this.compileList(i);
522
+ }
523
+ /**
524
+ * controls whether the dialect adds a "type" keyword before a column's new data
525
+ * type in an ALTER TABLE statement.
526
+ */
527
+ announcesNewColumnDataType() {
528
+ return !0;
529
+ }
530
+ }
531
+ const D = p({
532
+ ForKeyShare: "for key share",
533
+ ForNoKeyUpdate: "for no key update",
534
+ ForUpdate: "for update",
535
+ ForShare: "for share",
536
+ NoWait: "nowait",
537
+ SkipLocked: "skip locked",
538
+ Distinct: "distinct"
539
+ }), f = p({
540
+ ForKeyShare: 1,
541
+ ForNoKeyUpdate: 1,
542
+ ForUpdate: 1,
543
+ ForShare: 1,
544
+ NoWait: 2,
545
+ SkipLocked: 2,
546
+ Distinct: 0
547
+ }), w = p({
548
+ InnerJoin: "inner join",
549
+ LeftJoin: "left join",
550
+ RightJoin: "right join",
551
+ FullJoin: "full join",
552
+ CrossJoin: "cross join",
553
+ LateralInnerJoin: "inner join lateral",
554
+ LateralLeftJoin: "left join lateral",
555
+ LateralCrossJoin: "cross join lateral",
556
+ OuterApply: "outer apply",
557
+ CrossApply: "cross apply",
558
+ Using: "using"
559
+ }), M = p({
560
+ raw(a, i = []) {
561
+ return p({
562
+ sql: a,
563
+ query: n.createWithSql(a),
564
+ parameters: p(i),
565
+ queryId: O()
566
+ });
567
+ }
568
+ });
569
+ class E {
570
+ get supportsCreateIfNotExists() {
571
+ return !0;
572
+ }
573
+ get supportsTransactionalDdl() {
574
+ return !1;
575
+ }
576
+ get supportsReturning() {
577
+ return !1;
578
+ }
579
+ get supportsOutput() {
580
+ return !1;
581
+ }
582
+ }
583
+ const B = "kysely_migration", R = "kysely_migration_lock";
584
+ p({ __noMigrations__: !0 });
585
+ export {
586
+ M as C,
587
+ A as D,
588
+ x as O,
589
+ E as a,
590
+ B as b,
591
+ R as c
592
+ };
@@ -0,0 +1,62 @@
1
+ import { K as E } from "./kysely-Bchvsze0.mjs";
2
+ import { F as e } from "./sql-CJsUpKEQ.mjs";
3
+ import { d as s } from "./postgres-dialect-DaHvQ_AZ.mjs";
4
+ class L {
5
+ constructor(t) {
6
+ this.pool = t, this.db = new E({
7
+ dialect: new s({
8
+ pool: t
9
+ })
10
+ });
11
+ }
12
+ db;
13
+ dateToDb(t) {
14
+ return t;
15
+ }
16
+ dbToDate(t) {
17
+ return t instanceof Date ? t : new Date(t);
18
+ }
19
+ jsonToDb(t) {
20
+ return t;
21
+ }
22
+ dbToJson(t) {
23
+ return t;
24
+ }
25
+ buildJsonQuery(t, a, T, r) {
26
+ return e`${e.ref(a)}->>${e.lit(T)} = ${e.lit(JSON.stringify(r))}`;
27
+ }
28
+ now() {
29
+ return /* @__PURE__ */ new Date();
30
+ }
31
+ async createTables(t) {
32
+ await e`
33
+ CREATE TABLE IF NOT EXISTS threads (
34
+ thread_id TEXT PRIMARY KEY,
35
+ created_at TIMESTAMP NOT NULL,
36
+ updated_at TIMESTAMP NOT NULL,
37
+ metadata JSONB NOT NULL DEFAULT '{}',
38
+ status TEXT NOT NULL DEFAULT 'idle',
39
+ values JSONB,
40
+ interrupts JSONB NOT NULL DEFAULT '{}'
41
+ )
42
+ `.execute(t), await e`
43
+ CREATE TABLE IF NOT EXISTS runs (
44
+ run_id TEXT PRIMARY KEY,
45
+ thread_id TEXT NOT NULL,
46
+ assistant_id TEXT NOT NULL,
47
+ created_at TIMESTAMP NOT NULL,
48
+ updated_at TIMESTAMP NOT NULL,
49
+ status TEXT NOT NULL DEFAULT 'pending',
50
+ metadata JSONB NOT NULL DEFAULT '{}',
51
+ multitask_strategy TEXT NOT NULL DEFAULT 'reject',
52
+ FOREIGN KEY (thread_id) REFERENCES threads(thread_id) ON DELETE CASCADE
53
+ )
54
+ `.execute(t);
55
+ }
56
+ async createIndexes(t) {
57
+ await e`CREATE INDEX IF NOT EXISTS idx_threads_status ON threads(status)`.execute(t), await e`CREATE INDEX IF NOT EXISTS idx_threads_created_at ON threads(created_at)`.execute(t), await e`CREATE INDEX IF NOT EXISTS idx_threads_updated_at ON threads(updated_at)`.execute(t), await e`CREATE INDEX IF NOT EXISTS idx_runs_thread_id ON runs(thread_id)`.execute(t), await e`CREATE INDEX IF NOT EXISTS idx_runs_status ON runs(status)`.execute(t);
58
+ }
59
+ }
60
+ export {
61
+ L as PostgresAdapter
62
+ };