sasat 0.21.21 → 0.22.1

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/dist/index.cjs CHANGED
@@ -1,1065 +1,895 @@
1
- 'use strict';
2
-
3
- const error = require('./shared/sasat.DHiyRw3a.cjs');
4
- require('path');
5
- require('fs-extra');
6
- require('js-yaml');
7
- const SqlString = require('sqlstring');
8
- require('mysql2');
9
- require('util');
10
-
11
- function _interopNamespaceCompat(e) {
12
- if (e && typeof e === 'object' && 'default' in e) return e;
13
- const n = Object.create(null);
14
- if (e) {
15
- for (const k in e) {
16
- n[k] = e[k];
17
- }
18
- }
19
- n.default = e;
20
- return n;
21
- }
22
-
23
- const SqlString__namespace = /*#__PURE__*/_interopNamespaceCompat(SqlString);
24
-
25
- var QueryNodeKind = /* @__PURE__ */ ((QueryNodeKind2) => {
26
- QueryNodeKind2[QueryNodeKind2["Field"] = 0] = "Field";
27
- QueryNodeKind2[QueryNodeKind2["Function"] = 1] = "Function";
28
- QueryNodeKind2[QueryNodeKind2["Table"] = 2] = "Table";
29
- QueryNodeKind2[QueryNodeKind2["Join"] = 3] = "Join";
30
- QueryNodeKind2[QueryNodeKind2["CompoundExpr"] = 4] = "CompoundExpr";
31
- QueryNodeKind2[QueryNodeKind2["ComparisonExpr"] = 5] = "ComparisonExpr";
32
- QueryNodeKind2[QueryNodeKind2["IsNullExpr"] = 6] = "IsNullExpr";
33
- QueryNodeKind2[QueryNodeKind2["Parenthesis"] = 7] = "Parenthesis";
34
- QueryNodeKind2[QueryNodeKind2["InExpr"] = 8] = "InExpr";
35
- QueryNodeKind2[QueryNodeKind2["BetweenExpr"] = 9] = "BetweenExpr";
36
- QueryNodeKind2[QueryNodeKind2["ContainsExpr"] = 10] = "ContainsExpr";
37
- QueryNodeKind2[QueryNodeKind2["Literal"] = 11] = "Literal";
38
- QueryNodeKind2[QueryNodeKind2["Sort"] = 12] = "Sort";
39
- QueryNodeKind2[QueryNodeKind2["Identifier"] = 13] = "Identifier";
40
- QueryNodeKind2[QueryNodeKind2["Exists"] = 14] = "Exists";
41
- QueryNodeKind2[QueryNodeKind2["Raw"] = 15] = "Raw";
42
- QueryNodeKind2[QueryNodeKind2["GroupBy"] = 16] = "GroupBy";
43
- QueryNodeKind2[QueryNodeKind2["Over"] = 17] = "Over";
44
- QueryNodeKind2[QueryNodeKind2["Window"] = 18] = "Window";
45
- return QueryNodeKind2;
46
- })(QueryNodeKind || {});
47
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_migrate = require("./migrate-Cc47Mufl.cjs");
3
+ let sqlstring = require("sqlstring");
4
+ sqlstring = require_migrate.__toESM(sqlstring, 1);
5
+ let mysql2_promise = require("mysql2/promise");
6
+ //#region src/db/connectors/mysql/client.ts
7
+ var MysqlClient = class extends require_migrate.DBClient {
8
+ async release() {}
9
+ constructor(connectionOption, logger) {
10
+ super(logger);
11
+ this.connectionOption = connectionOption;
12
+ }
13
+ getConnection() {
14
+ return (0, mysql2_promise.createConnection)({
15
+ dateStrings: true,
16
+ ...this.connectionOption
17
+ });
18
+ }
19
+ async transaction() {
20
+ const connection = await this.getConnection();
21
+ await connection.beginTransaction();
22
+ return new require_migrate.MySqlTransaction(connection);
23
+ }
24
+ async execSql(sql) {
25
+ const connection = await this.getConnection();
26
+ const r = await connection.query(sql);
27
+ await connection.end();
28
+ return r[0];
29
+ }
30
+ };
31
+ //#endregion
32
+ //#region src/runtime/dsl/query/sql/nodeToSql.ts
48
33
  function partitionBy(ids) {
49
- if (!ids || ids.length === 0) return "";
50
- return `PARTITION BY ${ids.map(Sql.identifier).join(",")} `;
34
+ if (!ids || ids.length === 0) return "";
35
+ return `PARTITION BY ${ids.map(Sql.identifier).join(",")} `;
51
36
  }
52
37
  function orderBy(sorts) {
53
- if (!sorts || sorts.length === 0) return "";
54
- return `ORDER BY ${sorts.map(Sql.sort).join(",")} `;
38
+ if (!sorts || sorts.length === 0) return "";
39
+ return `ORDER BY ${sorts.map(Sql.sort).join(",")} `;
55
40
  }
56
41
  function windowValue(value) {
57
- if (value.type === "FOLLOWING" || value.type === "PRECEDING") {
58
- return `${value.value} ${value.type}`;
59
- }
60
- return value.type;
42
+ if (value.type === "FOLLOWING" || value.type === "PRECEDING") return `${value.value} ${value.type}`;
43
+ return value.type;
61
44
  }
62
- function window$1(window2) {
63
- if (!window2) return "";
64
- if (window2.between) {
65
- return `${window2.type} BETWEEN ${windowValue(window2.start)} AND ${window2.end}`;
66
- }
67
- return `${window2.type} ${windowValue(window2.value)}`;
45
+ function window$1(window) {
46
+ if (!window) return "";
47
+ if (window.between) return `${window.type} BETWEEN ${windowValue(window.start)} AND ${window.end}`;
48
+ return `${window.type} ${windowValue(window.value)}`;
68
49
  }
69
50
  function over(v) {
70
- if (!v) return "";
71
- return `OVER (${partitionBy(v.partitionBy)}${orderBy(v.orderBy)}${window$1(v.window)})`;
51
+ if (!v) return "";
52
+ return `OVER (${partitionBy(v.partitionBy)}${orderBy(v.orderBy)}${window$1(v.window)})`;
72
53
  }
73
- const SELECT_ALIAS_SEPARATOR = "__";
74
54
  const Sql = {
75
- select: (expr) => {
76
- switch (expr.kind) {
77
- case QueryNodeKind.Raw:
78
- return expr.expr;
79
- case QueryNodeKind.Field:
80
- return Sql.fieldInSelect(expr);
81
- case QueryNodeKind.Identifier:
82
- return Sql.identifier(expr);
83
- case QueryNodeKind.Function:
84
- return Sql.fn(expr);
85
- }
86
- },
87
- literal: (literal) => error.SqlString.escape(literal.value),
88
- fieldInCondition: (identifier) => error.SqlString.escapeId(identifier.table) + "." + error.SqlString.escapeId(identifier.name),
89
- fieldInSelect: (identifier) => {
90
- const alias = identifier.alias && identifier.name !== identifier.alias ? " AS " + error.SqlString.escapeId(identifier.alias) : "";
91
- return error.SqlString.escapeId(identifier.table) + "." + error.SqlString.escapeId(identifier.name) + alias;
92
- },
93
- identifier: (ident) => {
94
- return error.SqlString.escapeId(ident.identifier);
95
- },
96
- fn: (fn) => `${fn.fnName}(${fn.args.map(Sql.value).join(",")})${over(fn.over)}${fn.alias ? ` AS ${fn.alias}` : ""}`,
97
- value: (v) => {
98
- if (v.kind === QueryNodeKind.Function) return Sql.fn(v);
99
- if (v.kind === QueryNodeKind.Field) return Sql.fieldInCondition(v);
100
- if (v.kind === QueryNodeKind.Identifier) return Sql.identifier(v);
101
- return Sql.literal(v);
102
- },
103
- between: (expr) => `${Sql.value(expr.left)} BETWEEN ${Sql.value(expr.begin)} AND ${Sql.value(
104
- expr.end
105
- )}`,
106
- contains: (expr) => {
107
- const operator = expr.isNot ? "NOT LIKE" : "LIKE";
108
- const val = (value, type) => {
109
- if (type === "contains") return "%" + value + "%";
110
- if (type === "start") return "%" + value;
111
- return value + "%";
112
- };
113
- return `${Sql.value(expr.left)} ${operator} ${error.SqlString.escape(
114
- val(expr.right, expr.type)
115
- )}`;
116
- },
117
- in: (expr) => {
118
- if ("right" in expr)
119
- return `${Sql.value(expr.left)} ${expr.operator} (${expr.right.map(Sql.value).join(", ")})`;
120
- return `${Sql.value(expr.left)} ${expr.operator} (${Sql.queryOrRaw(
121
- expr.query
122
- )})`;
123
- },
124
- comparison: (expr) => `${Sql.value(expr.left)} ${expr.operator} ${Sql.value(expr.right)}`,
125
- compound: (expr) => `${Sql.booleanValue(expr.left)} ${expr.operator} ${Sql.booleanValue(
126
- expr.right
127
- )}`,
128
- isNull: (expr) => `${Sql.value(expr.expr)} ${expr.isNot ? "IS NOT NULL" : "IS NULL"}`,
129
- paren: (expr) => "(" + Sql.booleanValue(expr.expression) + ")",
130
- table: (table) => {
131
- if (!table.subquery) {
132
- if (table.alias === table.name) return error.SqlString.escapeId(table.name);
133
- return error.SqlString.escapeId(table.name) + " AS " + error.SqlString.escapeId(table.alias);
134
- }
135
- return `(${queryToSql(table.query)}) AS ${error.SqlString.escapeId(table.alias)}`;
136
- },
137
- join: (join) => `${join.type ? join.type + " " : ""}JOIN ${Sql.table(join.table)} ON ` + Sql.booleanValue(join.conditions),
138
- booleanValue: (expr) => {
139
- switch (expr.kind) {
140
- case QueryNodeKind.BetweenExpr:
141
- return Sql.between(expr);
142
- case QueryNodeKind.CompoundExpr:
143
- return Sql.compound(expr);
144
- case QueryNodeKind.ComparisonExpr:
145
- return Sql.comparison(expr);
146
- case QueryNodeKind.ContainsExpr:
147
- return Sql.contains(expr);
148
- case QueryNodeKind.Parenthesis:
149
- return Sql.paren(expr);
150
- case QueryNodeKind.InExpr:
151
- return Sql.in(expr);
152
- case QueryNodeKind.IsNullExpr:
153
- return Sql.isNull(expr);
154
- case QueryNodeKind.Exists:
155
- return Sql.exists(expr);
156
- }
157
- },
158
- exists: (expr) => {
159
- return `EXISTS (${Sql.queryOrRaw(expr.query)})`;
160
- },
161
- sort: (expr) => {
162
- const field = () => {
163
- switch (expr.field.kind) {
164
- case QueryNodeKind.Field:
165
- return Sql.fieldInCondition(expr.field);
166
- case QueryNodeKind.Identifier:
167
- return Sql.identifier(expr.field);
168
- default:
169
- return Sql.fn(expr.field);
170
- }
171
- };
172
- if (expr.direction)
173
- return `${field()} ${expr.direction === "DESC" ? "DESC" : "ASC"}`;
174
- return field();
175
- },
176
- sorts: (sorts) => sorts.map(Sql.sort).join(", "),
177
- queryOrRaw: (expr) => {
178
- if ("kind" in expr) {
179
- return expr.expr;
180
- }
181
- return queryToSql(expr);
182
- }
183
- };
184
-
55
+ select: (expr) => {
56
+ switch (expr.kind) {
57
+ case 15: return expr.expr;
58
+ case 0: return Sql.fieldInSelect(expr);
59
+ case 13: return Sql.identifier(expr);
60
+ case 1: return Sql.fn(expr);
61
+ }
62
+ },
63
+ literal: (literal) => require_migrate.SqlString.escape(literal.value),
64
+ fieldInCondition: (identifier) => require_migrate.SqlString.escapeId(identifier.table) + "." + require_migrate.SqlString.escapeId(identifier.name),
65
+ fieldInSelect: (identifier) => {
66
+ const alias = identifier.alias && identifier.name !== identifier.alias ? " AS " + require_migrate.SqlString.escapeId(identifier.alias) : "";
67
+ return require_migrate.SqlString.escapeId(identifier.table) + "." + require_migrate.SqlString.escapeId(identifier.name) + alias;
68
+ },
69
+ identifier: (ident) => {
70
+ return require_migrate.SqlString.escapeId(ident.identifier);
71
+ },
72
+ fn: (fn) => `${fn.fnName}(${fn.args.map(Sql.value).join(",")})${over(fn.over)}${fn.alias ? ` AS ${fn.alias}` : ""}`,
73
+ value: (v) => {
74
+ if (v.kind === 1) return Sql.fn(v);
75
+ if (v.kind === 0) return Sql.fieldInCondition(v);
76
+ if (v.kind === 13) return Sql.identifier(v);
77
+ return Sql.literal(v);
78
+ },
79
+ between: (expr) => `${Sql.value(expr.left)} BETWEEN ${Sql.value(expr.begin)} AND ${Sql.value(expr.end)}`,
80
+ contains: (expr) => {
81
+ const operator = expr.isNot ? "NOT LIKE" : "LIKE";
82
+ const val = (value, type) => {
83
+ if (type === "contains") return "%" + value + "%";
84
+ if (type === "start") return "%" + value;
85
+ return value + "%";
86
+ };
87
+ return `${Sql.value(expr.left)} ${operator} ${require_migrate.SqlString.escape(val(expr.right, expr.type))}`;
88
+ },
89
+ in: (expr) => {
90
+ if ("right" in expr) return `${Sql.value(expr.left)} ${expr.operator} (${expr.right.map(Sql.value).join(", ")})`;
91
+ return `${Sql.value(expr.left)} ${expr.operator} (${Sql.queryOrRaw(expr.query)})`;
92
+ },
93
+ comparison: (expr) => `${Sql.value(expr.left)} ${expr.operator} ${Sql.value(expr.right)}`,
94
+ compound: (expr) => `${Sql.booleanValue(expr.left)} ${expr.operator} ${Sql.booleanValue(expr.right)}`,
95
+ isNull: (expr) => `${Sql.value(expr.expr)} ${expr.isNot ? "IS NOT NULL" : "IS NULL"}`,
96
+ paren: (expr) => "(" + Sql.booleanValue(expr.expression) + ")",
97
+ table: (table) => {
98
+ if (!table.subquery) {
99
+ if (table.alias === table.name) return require_migrate.SqlString.escapeId(table.name);
100
+ return require_migrate.SqlString.escapeId(table.name) + " AS " + require_migrate.SqlString.escapeId(table.alias);
101
+ }
102
+ return `(${queryToSql(table.query)}) AS ${require_migrate.SqlString.escapeId(table.alias)}`;
103
+ },
104
+ join: (join) => `${join.type ? join.type + " " : ""}JOIN ${Sql.table(join.table)} ON ` + Sql.booleanValue(join.conditions),
105
+ booleanValue: (expr) => {
106
+ switch (expr.kind) {
107
+ case 9: return Sql.between(expr);
108
+ case 4: return Sql.compound(expr);
109
+ case 5: return Sql.comparison(expr);
110
+ case 10: return Sql.contains(expr);
111
+ case 7: return Sql.paren(expr);
112
+ case 8: return Sql.in(expr);
113
+ case 6: return Sql.isNull(expr);
114
+ case 14: return Sql.exists(expr);
115
+ }
116
+ },
117
+ exists: (expr) => {
118
+ return `EXISTS (${Sql.queryOrRaw(expr.query)})`;
119
+ },
120
+ sort: (expr) => {
121
+ const field = () => {
122
+ switch (expr.field.kind) {
123
+ case 0: return Sql.fieldInCondition(expr.field);
124
+ case 13: return Sql.identifier(expr.field);
125
+ default: return Sql.fn(expr.field);
126
+ }
127
+ };
128
+ if (expr.direction) return `${field()} ${expr.direction === "DESC" ? "DESC" : "ASC"}`;
129
+ return field();
130
+ },
131
+ sorts: (sorts) => sorts.map(Sql.sort).join(", "),
132
+ queryOrRaw: (expr) => {
133
+ if ("kind" in expr) return expr.expr;
134
+ return queryToSql(expr);
135
+ }
136
+ };
137
+ //#endregion
138
+ //#region src/runtime/dsl/query/sql/queryToSql.ts
185
139
  const getJoin = (from) => {
186
- return from.joins.flatMap((join) => [join, ...getJoin(join.table)]);
140
+ return from.joins.flatMap((join) => [join, ...getJoin(join.table)]);
187
141
  };
188
142
  const getLock = (lock) => {
189
- if (!lock) return "";
190
- if (lock === "FOR UPDATE") return " FOR UPDATE";
191
- return " FOR SHARE";
143
+ if (!lock) return "";
144
+ if (lock === "FOR UPDATE") return " FOR UPDATE";
145
+ return " FOR SHARE";
192
146
  };
193
147
  const queryToSql = (query) => {
194
- const select = query.select.map(Sql.select).join(", ");
195
- const join = getJoin(query.from).map(Sql.join).join(" ");
196
- const where = query.where ? " WHERE " + Sql.booleanValue(query.where) : "";
197
- const groupBy = query.groupBy ? " GROUP BY" + query.groupBy.cols.map(Sql.value).join(",") : "";
198
- const having = query.having ? "HAVING " + Sql.booleanValue(query.having) : "";
199
- const sort = query.sort && query.sort.length !== 0 ? " ORDER BY " + Sql.sorts(query.sort) : "";
200
- const limit = query.limit ? " LIMIT " + query.limit : "";
201
- const offset = query.offset ? " OFFSET " + query.offset : "";
202
- if (offset && !limit) throw new Error("LIMIT is required to use OFFSET.");
203
- return `SELECT ${select} FROM ${Sql.table(query.from)}` + join + where + groupBy + having + sort + limit + offset + getLock(query.lock);
204
- };
205
-
206
- const makeParamsMiddleware = (update) => {
207
- return (args) => {
208
- args[1] = update(args[1]);
209
- return args;
210
- };
148
+ const select = query.select.map(Sql.select).join(", ");
149
+ const join = getJoin(query.from).map(Sql.join).join(" ");
150
+ const where = query.where ? " WHERE " + Sql.booleanValue(query.where) : "";
151
+ const groupBy = query.groupBy ? " GROUP BY" + query.groupBy.cols.map(Sql.value).join(",") : "";
152
+ const having = query.having ? "HAVING " + Sql.booleanValue(query.having) : "";
153
+ const sort = query.sort && query.sort.length !== 0 ? " ORDER BY " + Sql.sorts(query.sort) : "";
154
+ const limit = query.limit ? " LIMIT " + query.limit : "";
155
+ const offset = query.offset ? " OFFSET " + query.offset : "";
156
+ if (offset && !limit) throw new Error("LIMIT is required to use OFFSET.");
157
+ return `SELECT ${select} FROM ${Sql.table(query.from)}` + join + where + groupBy + having + sort + limit + offset + getLock(query.lock);
158
+ };
159
+ //#endregion
160
+ //#region src/db/sql/expression/comparison.ts
161
+ let Comparison = /* @__PURE__ */ function(Comparison) {
162
+ Comparison["eq"] = "=";
163
+ Comparison["gt"] = ">";
164
+ Comparison["lt"] = "<";
165
+ Comparison["gte"] = ">=";
166
+ Comparison["lte"] = "<=";
167
+ Comparison["neq"] = "<>";
168
+ Comparison["like"] = "LIKE";
169
+ Comparison["notLike"] = "NOT LIKE";
170
+ return Comparison;
171
+ }({});
172
+ const comparisonExpressionToSql = (exp) => {
173
+ const type = Object.hasOwn(exp, "__type") ? exp.__type || "AND" : "AND";
174
+ return Object.entries(exp).map(([key, value]) => {
175
+ const column = sqlstring.escapeId(key);
176
+ if (!Array.isArray(value)) return `${column} = ${sqlstring.escape(value)}`;
177
+ if (value[0] === "IS NULL") return `${column} IS NULL`;
178
+ if (value[0] === "IS NOT NULL") return `${column} IS NOT NULL`;
179
+ if (value[0] === "IN") {
180
+ const [, ...columns] = value;
181
+ return `${column} IN (${[columns.map((column) => sqlstring.escape(column)).join(", ")]})`;
182
+ }
183
+ if (value[0] === "BETWEEN") return `${column} BETWEEN ${sqlstring.escape(value[1])} AND ${sqlstring.escape(value[2])}`;
184
+ if (Object.keys(Comparison).includes(value[0])) return `${column} ${value[0]} ${sqlstring.escape(value[1])}`;
185
+ throw new require_migrate.SasatError("SQL PARSE ERROR");
186
+ }).join(` ${type} `);
187
+ };
188
+ //#endregion
189
+ //#region src/db/sql/expression/conditionExpression.ts
190
+ const conditionExpressionToSql = (exp) => {
191
+ if (Array.isArray(exp)) return CompositeCondition.and(exp).toSQL();
192
+ if (exp instanceof CompositeCondition) return exp.toSQL();
193
+ return comparisonExpressionToSql(exp);
194
+ };
195
+ //#endregion
196
+ //#region src/db/sql/expression/compositeCondition.ts
197
+ var CompositeCondition = class CompositeCondition {
198
+ constructor(type, conditions) {
199
+ this.type = type;
200
+ this.conditions = conditions;
201
+ }
202
+ static or(conditions) {
203
+ return new CompositeCondition("OR", conditions);
204
+ }
205
+ static and(conditions) {
206
+ return new CompositeCondition("AND", conditions);
207
+ }
208
+ toSQL() {
209
+ return "(" + this.conditions.map(conditionExpressionToSql).join(this.type) + ")";
210
+ }
211
+ };
212
+ //#endregion
213
+ //#region src/migration/makeMutaion.ts
214
+ const formatSubscription = (subscription) => {
215
+ if (subscription === void 0 || subscription === false) return {
216
+ enabled: false,
217
+ subscriptionFilter: []
218
+ };
219
+ if (subscription === true) return {
220
+ enabled: true,
221
+ subscriptionFilter: []
222
+ };
223
+ return {
224
+ enabled: subscription.enabled,
225
+ subscriptionFilter: subscription.subscriptionFilter || []
226
+ };
211
227
  };
212
-
213
- const makeNumberIdEncoder = (hashId) => {
214
- return {
215
- encode: (id) => hashId.encode(id),
216
- decode: (id) => hashId.decode(id)[0]
217
- };
228
+ const formatOptions = (type, option) => ({
229
+ type,
230
+ noReFetch: option?.noRefetch || false,
231
+ middlewares: option?.middlewares || [],
232
+ contextFields: option?.contextFields || [],
233
+ subscription: formatSubscription(option?.subscription)
234
+ });
235
+ const Mutations = {
236
+ create: (options) => formatOptions("create", options),
237
+ update: (options) => formatOptions("update", options),
238
+ delete: (options) => formatOptions("delete", options)
218
239
  };
219
-
240
+ //#endregion
241
+ //#region src/migration/makeQuery.ts
220
242
  const single = (name, options) => ({
221
- type: "single",
222
- name,
223
- conditions: options?.conditions || [],
224
- middlewares: options?.middlewares || []
243
+ type: "single",
244
+ name,
245
+ conditions: options?.conditions || [],
246
+ middlewares: options?.middlewares || []
225
247
  });
226
248
  const listAll = (name, options) => ({
227
- type: "list-all",
228
- name,
229
- conditions: options?.conditions || [],
230
- middlewares: options?.middlewares || []
249
+ type: "list-all",
250
+ name,
251
+ conditions: options?.conditions || [],
252
+ middlewares: options?.middlewares || []
231
253
  });
232
254
  const paging = (name, options) => ({
233
- type: "list-paging",
234
- name,
235
- conditions: options?.conditions || [],
236
- middlewares: options?.middlewares || []
255
+ type: "list-paging",
256
+ name,
257
+ conditions: options?.conditions || [],
258
+ middlewares: options?.middlewares || []
237
259
  });
238
260
  const primary = (middlewares = []) => ({
239
- type: "primary",
240
- conditions: [],
241
- middlewares
261
+ type: "primary",
262
+ conditions: [],
263
+ middlewares
242
264
  });
243
265
  const Queries = {
244
- single,
245
- listAll,
246
- paging,
247
- primary
266
+ single,
267
+ listAll,
268
+ paging,
269
+ primary
248
270
  };
249
-
250
- const formatSubscription = (subscription) => {
251
- if (subscription === void 0 || subscription === false) {
252
- return {
253
- enabled: false,
254
- subscriptionFilter: []
255
- };
256
- }
257
- if (subscription === true)
258
- return {
259
- enabled: true,
260
- subscriptionFilter: []
261
- };
262
- return {
263
- enabled: subscription.enabled,
264
- subscriptionFilter: subscription.subscriptionFilter || []
265
- };
271
+ //#endregion
272
+ //#region src/runtime/createTypeDef.ts
273
+ const makeArgs = (args) => {
274
+ if (!args || args.length === 0) return "";
275
+ return `(${args.map((arg) => `${arg.name}: ${arg.type}`).join(", ")})`;
266
276
  };
267
- const formatOptions = (type, option) => ({
268
- type,
269
- noReFetch: option?.noRefetch || false,
270
- middlewares: option?.middlewares || [],
271
- contextFields: option?.contextFields || [],
272
- subscription: formatSubscription(option?.subscription)
273
- });
274
- const Mutations = {
275
- create: (options) => formatOptions("create", options),
276
- update: (options) => formatOptions("update", options),
277
- delete: (options) => formatOptions("delete", options)
277
+ const makeTypedefString = (typeName, typedef, type) => {
278
+ const entries = Object.entries(typedef);
279
+ if (entries.length === 0) return "";
280
+ return `\
281
+ ${type} ${typeName} {
282
+ ${entries.map(([field, value]) => {
283
+ if (!value.return) throw new Error(`Return type required: ${typeName}.${field}`);
284
+ return ` ${field}${makeArgs(value.args)}: ${value.return}`;
285
+ }).join("\n")}
286
+ }
287
+ `;
278
288
  };
279
-
289
+ const createTypeDef = (typeDefs, inputs) => {
290
+ const types = Object.entries(typeDefs).map(([type, fields]) => makeTypedefString(type, fields, "type"));
291
+ const input = Object.entries(inputs).map(([type, fields]) => makeTypedefString(type, fields, "input"));
292
+ return types.join("\n") + input.join("\n");
293
+ };
294
+ //#endregion
295
+ //#region src/runtime/dsl/factory.ts
280
296
  const compound = (expr, operator) => {
281
- const active = expr.filter(error.nonNullable);
282
- if (active.length === 0) return conditions.eq(literal(1), literal(1));
283
- return active.reduce((acc, current) => ({
284
- kind: QueryNodeKind.CompoundExpr,
285
- left: acc,
286
- operator,
287
- right: current
288
- }));
297
+ const active = expr.filter(require_migrate.nonNullable);
298
+ if (active.length === 0) return conditions.eq(literal(1), literal(1));
299
+ return active.reduce((acc, current) => ({
300
+ kind: 4,
301
+ left: acc,
302
+ operator,
303
+ right: current
304
+ }));
289
305
  };
290
306
  const containsExpr = (isNot, type) => (left, right) => ({
291
- kind: QueryNodeKind.ContainsExpr,
292
- type,
293
- left,
294
- isNot,
295
- right
307
+ kind: 10,
308
+ type,
309
+ left,
310
+ isNot,
311
+ right
296
312
  });
297
313
  const comparison = (operator) => (left, right) => ({
298
- kind: QueryNodeKind.ComparisonExpr,
299
- left,
300
- operator,
301
- right
314
+ kind: 5,
315
+ left,
316
+ operator,
317
+ right
302
318
  });
303
319
  const and = (...expr) => compound(expr, "AND");
304
320
  const or = (...expr) => compound(expr, "OR");
305
- const field = (table2, name, alias) => ({
306
- kind: QueryNodeKind.Field,
307
- table: table2,
308
- name,
309
- alias
321
+ const field = (table, name, alias) => ({
322
+ kind: 0,
323
+ table,
324
+ name,
325
+ alias
310
326
  });
311
327
  const fn = (fnName, args, alias) => ({
312
- kind: QueryNodeKind.Function,
313
- fnName,
314
- args,
315
- alias
328
+ kind: 1,
329
+ fnName,
330
+ args,
331
+ alias
316
332
  });
317
333
  const window = (type, value) => ({
318
- kind: QueryNodeKind.Window,
319
- type,
320
- between: false,
321
- value
334
+ kind: 18,
335
+ type,
336
+ between: false,
337
+ value
322
338
  });
323
339
  const windowBetween = (type, start, end) => ({
324
- kind: QueryNodeKind.Window,
325
- type,
326
- between: true,
327
- start,
328
- end
340
+ kind: 18,
341
+ type,
342
+ between: true,
343
+ start,
344
+ end
329
345
  });
330
346
  const paren = (expression) => ({
331
- kind: QueryNodeKind.Parenthesis,
332
- expression
347
+ kind: 7,
348
+ expression
333
349
  });
334
350
  const In = (left, right) => {
335
- if (Array.isArray(right)) {
336
- if (right.length === 0) return conditions.eq(literal(0), literal(1));
337
- return {
338
- kind: QueryNodeKind.InExpr,
339
- left,
340
- operator: "IN",
341
- right: right.map(literal)
342
- };
343
- }
344
- return {
345
- kind: QueryNodeKind.InExpr,
346
- left,
347
- operator: "IN",
348
- query: right
349
- };
351
+ if (Array.isArray(right)) {
352
+ if (right.length === 0) return conditions.eq(literal(0), literal(1));
353
+ return {
354
+ kind: 8,
355
+ left,
356
+ operator: "IN",
357
+ right: right.map(literal)
358
+ };
359
+ }
360
+ return {
361
+ kind: 8,
362
+ left,
363
+ operator: "IN",
364
+ query: right
365
+ };
350
366
  };
351
367
  const notIn = (left, values) => ({
352
- kind: QueryNodeKind.InExpr,
353
- left,
354
- operator: "NOT IN",
355
- right: values.map(literal)
368
+ kind: 8,
369
+ left,
370
+ operator: "NOT IN",
371
+ right: values.map(literal)
356
372
  });
357
373
  const between = (left, begin, end) => ({
358
- kind: QueryNodeKind.BetweenExpr,
359
- left,
360
- begin,
361
- end
374
+ kind: 9,
375
+ left,
376
+ begin,
377
+ end
362
378
  });
363
379
  const isNull = (isNot) => (expr) => ({
364
- kind: QueryNodeKind.IsNullExpr,
365
- expr,
366
- isNot
380
+ kind: 6,
381
+ expr,
382
+ isNot
367
383
  });
368
384
  const simpleWhere = (tableNameOrAlias, where, isOr = false) => {
369
- const compound2 = isOr ? or : and;
370
- return compound2(
371
- ...Object.entries(where).map(([f, value]) => {
372
- const fe = field(tableNameOrAlias, f);
373
- if (Array.isArray(value))
374
- return comparison(value[0])(fe, literal(value[1]));
375
- return conditions.eq(fe, literal(value));
376
- })
377
- );
385
+ return (isOr ? or : and)(...Object.entries(where).map(([f, value]) => {
386
+ const fe = field(tableNameOrAlias, f);
387
+ if (Array.isArray(value)) return comparison(value[0])(fe, literal(value[1]));
388
+ return conditions.eq(fe, literal(value));
389
+ }));
378
390
  };
379
391
  const exists = (query) => ({
380
- kind: QueryNodeKind.Exists,
381
- query
392
+ kind: 14,
393
+ query
382
394
  });
383
395
  const raw = (sql) => ({
384
- kind: QueryNodeKind.Raw,
385
- expr: sql
396
+ kind: 15,
397
+ expr: sql
386
398
  });
387
399
  const conditions = {
388
- simpleWhere,
389
- and,
390
- or,
391
- eq: comparison("="),
392
- neq: comparison("<>"),
393
- gt: comparison(">"),
394
- gte: comparison(">="),
395
- lt: comparison("<"),
396
- lte: comparison("<="),
397
- comparison: (left, operator, right) => comparison(operator)(left, right),
398
- contains: containsExpr(false, "contains"),
399
- notContains: containsExpr(true, "contains"),
400
- startsWith: containsExpr(false, "start"),
401
- notStartsWith: containsExpr(true, "start"),
402
- endsWith: containsExpr(false, "end"),
403
- notEndsWith: containsExpr(true, "end"),
404
- in: In,
405
- notIn,
406
- between,
407
- isNull: isNull(false),
408
- isNotNull: isNull(true),
409
- exists
400
+ simpleWhere,
401
+ and,
402
+ or,
403
+ eq: comparison("="),
404
+ neq: comparison("<>"),
405
+ gt: comparison(">"),
406
+ gte: comparison(">="),
407
+ lt: comparison("<"),
408
+ lte: comparison("<="),
409
+ comparison: (left, operator, right) => comparison(operator)(left, right),
410
+ contains: containsExpr(false, "contains"),
411
+ notContains: containsExpr(true, "contains"),
412
+ startsWith: containsExpr(false, "start"),
413
+ notStartsWith: containsExpr(true, "start"),
414
+ endsWith: containsExpr(false, "end"),
415
+ notEndsWith: containsExpr(true, "end"),
416
+ in: In,
417
+ notIn,
418
+ between,
419
+ isNull: isNull(false),
420
+ isNotNull: isNull(true),
421
+ exists
410
422
  };
411
423
  const table = (name, joins, alias) => ({
412
- kind: QueryNodeKind.Table,
413
- subquery: false,
414
- name,
415
- alias,
416
- joins
424
+ kind: 2,
425
+ subquery: false,
426
+ name,
427
+ alias,
428
+ joins
417
429
  });
418
430
  const subQueryTable = (query, joins, alias) => ({
419
- kind: QueryNodeKind.Table,
420
- subquery: true,
421
- query,
422
- alias,
423
- joins
431
+ kind: 2,
432
+ subquery: true,
433
+ query,
434
+ alias,
435
+ joins
424
436
  });
425
- const join = (table2, conditions2, type) => ({
426
- kind: QueryNodeKind.Join,
427
- type,
428
- table: table2,
429
- conditions: conditions2
437
+ const join = (table, conditions, type) => ({
438
+ kind: 3,
439
+ type,
440
+ table,
441
+ conditions
430
442
  });
431
443
  const literal = (value) => ({
432
- kind: QueryNodeKind.Literal,
433
- value
444
+ kind: 11,
445
+ value
434
446
  });
435
- const sort = (field2, direction) => ({
436
- kind: QueryNodeKind.Sort,
437
- field: field2,
438
- direction
447
+ const sort = (field, direction) => ({
448
+ kind: 12,
449
+ field,
450
+ direction
439
451
  });
440
452
  const ident = (identifier) => ({
441
- kind: QueryNodeKind.Identifier,
442
- identifier
453
+ kind: 13,
454
+ identifier
443
455
  });
444
456
  const QExpr = {
445
- conditions,
446
- ...conditions,
447
- field,
448
- fn,
449
- window,
450
- windowBetween,
451
- paren,
452
- table,
453
- subQueryTable,
454
- join,
455
- value: literal,
456
- sort,
457
- order: sort,
458
- ident,
459
- id: ident,
460
- raw
457
+ conditions,
458
+ ...conditions,
459
+ field,
460
+ fn,
461
+ window,
462
+ windowBetween,
463
+ paren,
464
+ table,
465
+ subQueryTable,
466
+ join,
467
+ value: literal,
468
+ sort,
469
+ order: sort,
470
+ ident,
471
+ id: ident,
472
+ raw
473
+ };
474
+ //#endregion
475
+ //#region src/runtime/date.ts
476
+ const dateOffset = (date, timeZoneHour) => {
477
+ const offset = timeZoneHour ? timeZoneHour * 60 * 60 * 1e3 : date.getTimezoneOffset() * 6e4;
478
+ return new Date(date.getTime() + offset);
479
+ };
480
+ const zeroPad = (v, len) => v.toString().padStart(len, "0");
481
+ const dateToDatetimeString = (d) => {
482
+ const year = d.getUTCFullYear();
483
+ const month = d.getUTCMonth() + 1;
484
+ const day = d.getUTCDate();
485
+ const hour = d.getUTCHours();
486
+ const minute = d.getUTCMinutes();
487
+ const second = d.getUTCSeconds();
488
+ const millisecond = d.getUTCMilliseconds();
489
+ return zeroPad(year, 4) + "-" + zeroPad(month, 2) + "-" + zeroPad(day, 2) + " " + zeroPad(hour, 2) + ":" + zeroPad(minute, 2) + ":" + zeroPad(second, 2) + "." + zeroPad(millisecond, 3);
490
+ };
491
+ const dateToDateString = (d) => {
492
+ const year = d.getUTCFullYear();
493
+ const month = d.getUTCMonth() + 1;
494
+ const day = d.getUTCDate();
495
+ return zeroPad(year, 4) + "-" + zeroPad(month, 2) + "-" + zeroPad(day, 2);
496
+ };
497
+ const getTodayDateString = (timeZoneHour) => {
498
+ const date = /* @__PURE__ */ new Date();
499
+ date.setHours(0, 0, 0, 0);
500
+ return dateToDateString(dateOffset(date, timeZoneHour));
461
501
  };
462
-
502
+ const getTodayDateTimeString = (timeZoneHour) => {
503
+ const date = /* @__PURE__ */ new Date();
504
+ date.setHours(0, 0, 0, 0);
505
+ return dateToDatetimeString(dateOffset(date, timeZoneHour));
506
+ };
507
+ const getDayRange = (date, timeZoneHour) => {
508
+ date.setHours(0, 0, 0, 0);
509
+ const d = dateOffset(date, timeZoneHour || 0);
510
+ const begin = dateToDatetimeString(d);
511
+ d.setDate(d.getDate() + 1);
512
+ return [begin, dateToDatetimeString(d)];
513
+ };
514
+ const getDayRangeQExpr = (date, timeZoneHour) => {
515
+ return getDayRange(date, timeZoneHour).map(QExpr.value);
516
+ };
517
+ //#endregion
518
+ //#region src/runtime/gqlResolveInfoToField.ts
463
519
  const selectionSetToField = (selections, number) => {
464
- const result = {
465
- fields: [],
466
- relations: {},
467
- tableAlias: "t" + number
468
- };
469
- let num = number;
470
- for (const it of selections) {
471
- if (it.kind !== "Field") continue;
472
- if (it.selectionSet) {
473
- num += 1;
474
- const field = selectionSetToField(it.selectionSet.selections, num);
475
- result.relations[it.name.value] = field[0];
476
- num = field[1];
477
- } else {
478
- if (it.name.value !== "__typename") result.fields.push(it.name.value);
479
- }
480
- }
481
- return [result, num];
520
+ const result = {
521
+ fields: [],
522
+ relations: {},
523
+ tableAlias: "t" + number
524
+ };
525
+ let num = number;
526
+ for (const it of selections) {
527
+ if (it.kind !== "Field") continue;
528
+ if (it.selectionSet) {
529
+ num += 1;
530
+ const field = selectionSetToField(it.selectionSet.selections, num);
531
+ result.relations[it.name.value] = field[0];
532
+ num = field[1];
533
+ } else if (it.name.value !== "__typename") result.fields.push(it.name.value);
534
+ }
535
+ return [result, num];
482
536
  };
483
537
  const gqlResolveInfoToField = (info) => {
484
- return selectionSetToField(
485
- info.fieldNodes[0].selectionSet.selections,
486
- 0
487
- )[0];
538
+ return selectionSetToField(info.fieldNodes[0].selectionSet.selections, 0)[0];
539
+ };
540
+ //#endregion
541
+ //#region src/runtime/id.ts
542
+ const makeNumberIdEncoder = (hashId) => {
543
+ return {
544
+ encode: (id) => hashId.encode(id),
545
+ decode: (id) => hashId.decode(id)[0]
546
+ };
488
547
  };
489
-
490
- const escape = error.SqlString.escape;
491
- const escapeId = error.SqlString.escapeId;
548
+ //#endregion
549
+ //#region src/runtime/makeResolver.ts
550
+ const makeResolver = (resolver, middlewares = []) => {
551
+ return (...args) => {
552
+ return resolver(...middlewares.reduce((args, middleware) => {
553
+ return middleware(args);
554
+ }, args));
555
+ };
556
+ };
557
+ //#endregion
558
+ //#region src/runtime/resolverMiddleware.ts
559
+ const makeParamsMiddleware = (update) => {
560
+ return (args) => {
561
+ args[1] = update(args[1]);
562
+ return args;
563
+ };
564
+ };
565
+ //#endregion
566
+ //#region src/runtime/dsl/mutation/mutation.ts
567
+ const escapeId = require_migrate.SqlString.escapeId;
492
568
  const onDuplicateKeyUpdate = (columns) => {
493
- if (!columns || columns.length === 0) return "";
494
- return " ON DUPLICATE KEY UPDATE " + columns.map(escapeId).map((it) => `${it} = VALUES(${it})`).join(",");
569
+ if (!columns || columns.length === 0) return "";
570
+ return " ON DUPLICATE KEY UPDATE " + columns.map(escapeId).map((it) => `${it} = VALUES(${it})`).join(",");
495
571
  };
496
572
  const createToSql = (dsl, tableInfo) => {
497
- const map = tableInfo[dsl.table].columnMap;
498
- const values = dsl.entities.map((it) => `(${it.map((it2) => escape(it2)).join(",")})`).join(",");
499
- return `INSERT ${dsl.ignore ? "IGNORE " : ""}INTO ${escapeId(
500
- dsl.table
501
- )}(${dsl.fields.map((it) => escapeId(map[it]))}) VALUES ${values} ${onDuplicateKeyUpdate(dsl.upsert)}`;
573
+ const map = tableInfo[dsl.table].columnMap;
574
+ const values = dsl.entities.map((it) => `(${it.map((it) => require_migrate.SqlString.escape(it)).join(",")})`).join(",");
575
+ return `INSERT ${dsl.ignore ? "IGNORE " : ""}INTO ${escapeId(dsl.table)}(${dsl.fields.map((it) => escapeId(map[it]))}) VALUES ${values} ${onDuplicateKeyUpdate(dsl.upsert)}`;
502
576
  };
503
577
  const updateToSql = (dsl, tableInfo) => {
504
- const map = tableInfo[dsl.table].columnMap;
505
- return `UPDATE ${escapeId(dsl.table)} SET ${dsl.values.map((it) => escapeId(map[it.field]) + " = " + escape(it.value)).join(", ")} WHERE ${Sql.booleanValue(dsl.where)}`;
578
+ const map = tableInfo[dsl.table].columnMap;
579
+ return `UPDATE ${escapeId(dsl.table)} SET ${dsl.values.map((it) => escapeId(map[it.field]) + " = " + require_migrate.SqlString.escape(it.value)).join(", ")} WHERE ${Sql.booleanValue(dsl.where)}`;
506
580
  };
507
581
  const deleteToSql = (dsl) => {
508
- return `DELETE FROM ${escapeId(dsl.table)} WHERE ${Sql.booleanValue(
509
- dsl.where
510
- )}`;
582
+ return `DELETE FROM ${escapeId(dsl.table)} WHERE ${Sql.booleanValue(dsl.where)}`;
511
583
  };
512
-
584
+ //#endregion
585
+ //#region src/runtime/dsl/query/createQueryResolveInfo.ts
513
586
  const joinToQueryResolveInfo = (parentTableAlias, property, fields, map, tableInfo) => {
514
- const info = map[parentTableAlias][property];
515
- if (!info) return void 0;
516
- const tableAlias = fields.tableAlias || info.table;
517
- return {
518
- tableAlias,
519
- isArray: info.array,
520
- keyAliases: tableInfo[info.table].identifiableFields,
521
- joins: Object.entries(fields.relations || {}).filter(([, value]) => value).map(
522
- ([key, value]) => joinToQueryResolveInfo(
523
- info.table,
524
- key,
525
- value,
526
- map,
527
- tableInfo
528
- )
529
- ).filter(error.nonNullable),
530
- property
531
- };
587
+ const info = map[parentTableAlias][property];
588
+ if (!info) return void 0;
589
+ return {
590
+ tableAlias: fields.tableAlias || info.table,
591
+ isArray: info.array,
592
+ keyAliases: tableInfo[info.table].identifiableFields,
593
+ joins: Object.entries(fields.relations || {}).filter(([, value]) => value).map(([key, value]) => joinToQueryResolveInfo(info.table, key, value, map, tableInfo)).filter(require_migrate.nonNullable),
594
+ property
595
+ };
532
596
  };
533
597
  const createQueryResolveInfo = (tableName, fields, map, tableInfo) => {
534
- const tableAlias = fields.tableAlias || tableName;
535
- return {
536
- tableAlias,
537
- isArray: true,
538
- keyAliases: tableInfo[tableName].identifiableFields,
539
- joins: Object.entries(fields.relations || {}).filter(([, value]) => value).map(
540
- ([key, value]) => joinToQueryResolveInfo(
541
- tableName,
542
- key,
543
- value,
544
- map,
545
- tableInfo
546
- )
547
- ).filter(error.nonNullable),
548
- property: ""
549
- };
550
- };
551
-
598
+ return {
599
+ tableAlias: fields.tableAlias || tableName,
600
+ isArray: true,
601
+ keyAliases: tableInfo[tableName].identifiableFields,
602
+ joins: Object.entries(fields.relations || {}).filter(([, value]) => value).map(([key, value]) => joinToQueryResolveInfo(tableName, key, value, map, tableInfo)).filter(require_migrate.nonNullable),
603
+ property: ""
604
+ };
605
+ };
606
+ //#endregion
607
+ //#region src/runtime/dsl/query/sql/hydrate.ts
552
608
  const rowToObjs = (row) => {
553
- const objs = {};
554
- for (const [key, value] of Object.entries(row)) {
555
- const [table, column] = key.split(SELECT_ALIAS_SEPARATOR);
556
- if (!objs[table]) {
557
- objs[table] = {};
558
- }
559
- objs[table][column] = value;
560
- }
561
- return objs;
609
+ const objs = {};
610
+ for (const [key, value] of Object.entries(row)) {
611
+ const [table, column] = key.split("__");
612
+ if (!objs[table]) objs[table] = {};
613
+ objs[table][column] = value;
614
+ }
615
+ return objs;
562
616
  };
563
617
  const getUnique = (obj, info) => info.keyAliases.map((it) => obj[it]).join("_~_");
564
618
  const execTable = (info, objs, current) => {
565
- let entity = objs[info.tableAlias];
566
- if (entity[info.keyAliases[0]] == null) entity = null;
567
- let result;
568
- let currentTarget;
569
- if (info.isArray) {
570
- if (!current) {
571
- result = entity == null ? [] : [entity];
572
- currentTarget = entity;
573
- } else {
574
- currentTarget = entity == null ? null : current.find(
575
- (item) => item && info.keyAliases.every((key) => item[key] === entity[key])
576
- );
577
- if (currentTarget) {
578
- result = current;
579
- } else {
580
- currentTarget = entity;
581
- result = current;
582
- if (currentTarget) result.push(currentTarget);
583
- }
584
- }
585
- } else {
586
- currentTarget = current || entity;
587
- result = currentTarget;
588
- }
589
- if (currentTarget !== null) {
590
- for (const it of info.joins) {
591
- currentTarget[it.property] = execTable(
592
- it,
593
- objs,
594
- currentTarget[it.property]
595
- );
596
- }
597
- }
598
- return result;
599
- };
619
+ let entity = objs[info.tableAlias];
620
+ if (entity[info.keyAliases[0]] == null) entity = null;
621
+ let result;
622
+ let currentTarget;
623
+ if (info.isArray) if (!current) {
624
+ result = entity == null ? [] : [entity];
625
+ currentTarget = entity;
626
+ } else {
627
+ currentTarget = entity == null ? null : current.find((item) => item && info.keyAliases.every((key) => item[key] === entity[key]));
628
+ if (currentTarget) result = current;
629
+ else {
630
+ currentTarget = entity;
631
+ result = current;
632
+ if (currentTarget) result.push(currentTarget);
633
+ }
634
+ }
635
+ else {
636
+ currentTarget = current || entity;
637
+ result = currentTarget;
638
+ }
639
+ if (currentTarget !== null) for (const it of info.joins) currentTarget[it.property] = execTable(it, objs, currentTarget[it.property]);
640
+ return result;
641
+ };
642
+ /**
643
+ * to use this function require to select primary keys for every table
644
+ */
600
645
  const hydrate = (data, info) => {
601
- const result = [];
602
- const t0mapper = {};
603
- info.isArray = false;
604
- for (const row of data) {
605
- const objs = rowToObjs(row);
606
- const currentObj = objs[info.tableAlias];
607
- const unique = getUnique(currentObj, info);
608
- if (t0mapper[unique] === void 0) {
609
- t0mapper[unique] = result.length;
610
- result.push(execTable(info, objs, currentObj));
611
- continue;
612
- }
613
- const base = result[t0mapper[unique]];
614
- execTable(info, objs, base);
615
- }
616
- return result;
617
- };
618
-
646
+ const result = [];
647
+ const t0mapper = {};
648
+ info.isArray = false;
649
+ for (const row of data) {
650
+ const objs = rowToObjs(row);
651
+ const currentObj = objs[info.tableAlias];
652
+ const unique = getUnique(currentObj, info);
653
+ if (t0mapper[unique] === void 0) {
654
+ t0mapper[unique] = result.length;
655
+ result.push(execTable(info, objs, currentObj));
656
+ continue;
657
+ }
658
+ const base = result[t0mapper[unique]];
659
+ execTable(info, objs, base);
660
+ }
661
+ return result;
662
+ };
663
+ //#endregion
664
+ //#region src/runtime/sql/runQuery.ts
619
665
  const notTypeName = (fieldName) => fieldName !== "__typename";
620
666
  const createQuery = (baseTableName, fields, options, tableInfo, relationMap, context) => {
621
- let tableCount = 0;
622
- const select = [];
623
- const resolveFields = (tableName, table) => {
624
- const tableAlias = table.tableAlias || "t" + tableCount;
625
- table.tableAlias = tableAlias;
626
- tableCount++;
627
- const info = tableInfo[tableName];
628
- select.push(
629
- ...error.unique([
630
- ...table.fields.filter((it) => {
631
- return notTypeName(it) && info.columnMap[it];
632
- }),
633
- ...info.identifiableFields
634
- ]).map((it) => {
635
- const realName = info.columnMap[it] || it;
636
- return QExpr.field(
637
- tableAlias,
638
- realName,
639
- tableAlias + SELECT_ALIAS_SEPARATOR + it
640
- );
641
- })
642
- );
643
- return QExpr.table(
644
- tableName,
645
- Object.entries(table.relations || {}).map(([relationName, table2]) => {
646
- const current = tableCount;
647
- const rel = relationMap[tableName][relationName];
648
- if (!rel) return void 0;
649
- return QExpr.join(
650
- resolveFields(rel.table, table2),
651
- QExpr.and(
652
- rel.condition({
653
- parentTableAlias: tableAlias,
654
- childTableAlias: table2.tableAlias || "t" + current,
655
- context
656
- }),
657
- table2.joinOn
658
- ),
659
- "LEFT"
660
- );
661
- }).filter(error.nonNullable),
662
- tableAlias
663
- );
664
- };
665
- const from = resolveFields(baseTableName, fields);
666
- return {
667
- select,
668
- from,
669
- ...options
670
- };
667
+ let tableCount = 0;
668
+ const select = [];
669
+ const resolveFields = (tableName, table) => {
670
+ const tableAlias = table.tableAlias || "t" + tableCount;
671
+ table.tableAlias = tableAlias;
672
+ tableCount++;
673
+ const info = tableInfo[tableName];
674
+ select.push(...require_migrate.unique([...table.fields.filter((it) => {
675
+ return notTypeName(it) && info.columnMap[it];
676
+ }), ...info.identifiableFields]).map((it) => {
677
+ const realName = info.columnMap[it] || it;
678
+ return QExpr.field(tableAlias, realName, tableAlias + "__" + it);
679
+ }));
680
+ return QExpr.table(tableName, Object.entries(table.relations || {}).map(([relationName, table]) => {
681
+ const current = tableCount;
682
+ const rel = relationMap[tableName][relationName];
683
+ if (!rel) return void 0;
684
+ return QExpr.join(resolveFields(rel.table, table), QExpr.and(rel.condition({
685
+ parentTableAlias: tableAlias,
686
+ childTableAlias: table.tableAlias || "t" + current,
687
+ context
688
+ }), table.joinOn), "LEFT");
689
+ }).filter(require_migrate.nonNullable), tableAlias);
690
+ };
691
+ return {
692
+ select,
693
+ from: resolveFields(baseTableName, fields),
694
+ ...options
695
+ };
671
696
  };
672
697
  const createPagingInnerQuery = (tableName, tableAlias, fields, option, tableInfo, relationMap) => {
673
- const map = tableInfo[tableName].columnMap;
674
- return {
675
- select: error.unique([
676
- ...tableInfo[tableName].identifiableKeys,
677
- ...Object.keys(fields.relations || {}).flatMap((key) => {
678
- return relationMap[tableName][key]?.requiredColumns || [];
679
- }),
680
- ...fields.fields.filter((it) => notTypeName(it) && map[it]).map((it) => map[it] || it)
681
- ]).map((it) => QExpr.field(tableAlias, it)),
682
- from: QExpr.table(tableName, option.join || [], tableAlias),
683
- limit: option.numberOfItem,
684
- offset: option.offset,
685
- where: option.where,
686
- sort: option.sort
687
- };
688
- };
689
- const createPagingFieldQuery = ({
690
- baseTableName,
691
- fields,
692
- queryOption,
693
- pagingOption,
694
- tableInfo,
695
- relationMap,
696
- context
697
- }) => {
698
- const tableAlias = fields.tableAlias || "t0";
699
- const innerQuery = createPagingInnerQuery(
700
- baseTableName,
701
- tableAlias,
702
- fields,
703
- pagingOption,
704
- tableInfo,
705
- relationMap
706
- );
707
- const main = createQuery(
708
- baseTableName,
709
- fields,
710
- queryOption,
711
- tableInfo,
712
- relationMap,
713
- context
714
- );
715
- return {
716
- select: main.select,
717
- from: {
718
- ...main.from,
719
- subquery: true,
720
- query: innerQuery
721
- }
722
- };
723
- };
724
-
725
- class SasatDBDatasource {
726
- constructor(client = error.getDbClient()) {
727
- this.client = client;
728
- }
729
- queryLogger = noop;
730
- commandLogger = noop;
731
- async create(entity, option) {
732
- const obj = {
733
- ...this.getDefaultValueString(),
734
- ...entity
735
- };
736
- const fields = Object.keys(obj);
737
- const dsl = {
738
- table: this.tableName,
739
- fields,
740
- entities: [fields.map((key) => obj[key])],
741
- upsert: option?.upsert?.updateColumns,
742
- ignore: option?.ignore
743
- };
744
- const sql = createToSql(dsl, this.tableInfo);
745
- this.commandLogger(sql);
746
- const response = await this.client.rawCommand(sql);
747
- if (!this.autoIncrementColumn) return obj;
748
- return {
749
- ...obj,
750
- [this.autoIncrementColumn]: response.insertId
751
- };
752
- }
753
- async createBulk(entities, option) {
754
- const objects = entities.map((it) => ({
755
- ...this.getDefaultValueString(),
756
- ...it
757
- }));
758
- const keys = Object.keys(objects[0]);
759
- const values = objects.map((it) => keys.map((key) => it[key]));
760
- const dsl = {
761
- table: this.tableName,
762
- fields: keys,
763
- entities: values,
764
- upsert: option?.upsert?.updateColumns,
765
- ignore: option?.ignore
766
- };
767
- const sql = createToSql(dsl, this.tableInfo);
768
- this.commandLogger(sql);
769
- return await this.client.rawCommand(sql);
770
- }
771
- async upsert(entity, updateFields = this.primaryKeys) {
772
- return this.create(entity, {
773
- upsert: {
774
- updateColumns: this.fieldToColumn(updateFields)
775
- }
776
- });
777
- }
778
- update(entity) {
779
- const dsl = {
780
- table: this.tableName,
781
- values: Object.entries(entity).filter(([, value]) => value !== void 0).map(([column, value]) => ({
782
- field: column,
783
- value
784
- })),
785
- where: this.createIdentifiableExpression(entity)
786
- };
787
- const sql = updateToSql(dsl, this.tableInfo);
788
- this.commandLogger(sql);
789
- return this.client.rawCommand(sql);
790
- }
791
- updateWhere(update, condition) {
792
- const dsl = {
793
- table: this.tableName,
794
- values: Object.entries(update).filter(([, value]) => value !== void 0).map(([column, value]) => ({
795
- field: column,
796
- value
797
- })),
798
- where: condition
799
- };
800
- const sql = updateToSql(dsl, this.tableInfo);
801
- this.commandLogger(sql);
802
- return this.client.rawCommand(sql);
803
- }
804
- async delete(entity) {
805
- return this.deleteWhere(this.createIdentifiableExpression(entity));
806
- }
807
- async deleteWhere(condition) {
808
- const dsl = {
809
- table: this.tableName,
810
- where: condition
811
- };
812
- const sql = deleteToSql(dsl);
813
- this.commandLogger(sql);
814
- return this.client.rawCommand(sql);
815
- }
816
- async first(fields, option, context) {
817
- const result = await this.find(fields, option, context);
818
- if (result.length !== 0) return result[0];
819
- return null;
820
- }
821
- async find(fields = { fields: this.fields }, options, context) {
822
- const query = createQuery(
823
- this.tableName,
824
- fields,
825
- options,
826
- this.tableInfo,
827
- this.relationMap,
828
- context
829
- );
830
- return this.executeQuery(query, fields);
831
- }
832
- async findPageable(paging, fields = { fields: this.fields }, options, context) {
833
- const query = createPagingFieldQuery({
834
- baseTableName: this.tableName,
835
- fields,
836
- tableInfo: this.tableInfo,
837
- relationMap: this.relationMap,
838
- pagingOption: paging,
839
- queryOption: options,
840
- context
841
- });
842
- return this.executeQuery(query, fields);
843
- }
844
- async executeQuery(query, fields) {
845
- const info = createQueryResolveInfo(
846
- this.tableName,
847
- fields,
848
- this.relationMap,
849
- this.tableInfo
850
- );
851
- const sql = queryToSql(query);
852
- this.queryLogger(sql);
853
- const resultRows = await this.client.rawQuery(sql);
854
- return hydrate(resultRows, info);
855
- }
856
- createIdentifiableExpression(entity) {
857
- const expr = this.identifyFields.map((it) => {
858
- const value = entity[it];
859
- if (!value) throw new Error(`field ${it} is required`);
860
- return QExpr.eq(
861
- QExpr.field(this.tableName, this.tableInfo[this.tableName].columnMap[it]),
862
- QExpr.value(value)
863
- );
864
- });
865
- return QExpr.and(...expr);
866
- }
867
- getRelationMap() {
868
- return this.relationMap[this.tableName];
869
- }
870
- fieldToColumn(fields) {
871
- return fields.map((it) => this.tableInfo[this.tableName].columnMap[it] || it);
872
- }
873
- }
874
- const noop = () => {
875
- };
876
-
698
+ const map = tableInfo[tableName].columnMap;
699
+ return {
700
+ select: require_migrate.unique([
701
+ ...tableInfo[tableName].identifiableKeys,
702
+ ...Object.keys(fields.relations || {}).flatMap((key) => {
703
+ return relationMap[tableName][key]?.requiredColumns || [];
704
+ }),
705
+ ...fields.fields.filter((it) => notTypeName(it) && map[it]).map((it) => map[it] || it)
706
+ ]).map((it) => QExpr.field(tableAlias, it)),
707
+ from: QExpr.table(tableName, option.join || [], tableAlias),
708
+ limit: option.numberOfItem,
709
+ offset: option.offset,
710
+ where: option.where,
711
+ sort: option.sort
712
+ };
713
+ };
714
+ const createPagingFieldQuery = ({ baseTableName, fields, queryOption, pagingOption, tableInfo, relationMap, context }) => {
715
+ const innerQuery = createPagingInnerQuery(baseTableName, fields.tableAlias || "t0", fields, pagingOption, tableInfo, relationMap);
716
+ const main = createQuery(baseTableName, fields, queryOption, tableInfo, relationMap, context);
717
+ return {
718
+ select: main.select,
719
+ from: {
720
+ ...main.from,
721
+ subquery: true,
722
+ query: innerQuery
723
+ }
724
+ };
725
+ };
726
+ //#endregion
727
+ //#region src/runtime/sasatDBDatasource.ts
728
+ var SasatDBDatasource = class {
729
+ constructor(client = require_migrate.getDbClient()) {
730
+ this.client = client;
731
+ }
732
+ async create(entity, option) {
733
+ const obj = {
734
+ ...this.getDefaultValueString(),
735
+ ...entity
736
+ };
737
+ const fields = Object.keys(obj);
738
+ const sql = createToSql({
739
+ table: this.tableName,
740
+ fields,
741
+ entities: [fields.map((key) => obj[key])],
742
+ upsert: option?.upsert?.updateColumns,
743
+ ignore: option?.ignore
744
+ }, this.tableInfo);
745
+ const response = await this.client.rawCommand(sql);
746
+ if (!this.autoIncrementColumn) return obj;
747
+ return {
748
+ ...obj,
749
+ [this.autoIncrementColumn]: response.insertId
750
+ };
751
+ }
752
+ async createBulk(entities, option) {
753
+ const objects = entities.map((it) => ({
754
+ ...this.getDefaultValueString(),
755
+ ...it
756
+ }));
757
+ const keys = Object.keys(objects[0]);
758
+ const values = objects.map((it) => keys.map((key) => it[key]));
759
+ const sql = createToSql({
760
+ table: this.tableName,
761
+ fields: keys,
762
+ entities: values,
763
+ upsert: option?.upsert?.updateColumns,
764
+ ignore: option?.ignore
765
+ }, this.tableInfo);
766
+ return await this.client.rawCommand(sql);
767
+ }
768
+ async upsert(entity, updateFields = this.primaryKeys) {
769
+ return this.create(entity, { upsert: { updateColumns: this.fieldToColumn(updateFields) } });
770
+ }
771
+ update(entity) {
772
+ const sql = updateToSql({
773
+ table: this.tableName,
774
+ values: Object.entries(entity).filter(([, value]) => value !== void 0).map(([column, value]) => ({
775
+ field: column,
776
+ value
777
+ })),
778
+ where: this.createIdentifiableExpression(entity)
779
+ }, this.tableInfo);
780
+ return this.client.rawCommand(sql);
781
+ }
782
+ updateWhere(update, condition) {
783
+ const sql = updateToSql({
784
+ table: this.tableName,
785
+ values: Object.entries(update).filter(([, value]) => value !== void 0).map(([column, value]) => ({
786
+ field: column,
787
+ value
788
+ })),
789
+ where: condition
790
+ }, this.tableInfo);
791
+ return this.client.rawCommand(sql);
792
+ }
793
+ async delete(entity) {
794
+ return this.deleteWhere(this.createIdentifiableExpression(entity));
795
+ }
796
+ async deleteWhere(condition) {
797
+ const sql = deleteToSql({
798
+ table: this.tableName,
799
+ where: condition
800
+ });
801
+ return this.client.rawCommand(sql);
802
+ }
803
+ async first(fields, option, context) {
804
+ const result = await this.find(fields, option, context);
805
+ if (result.length !== 0) return result[0];
806
+ return null;
807
+ }
808
+ async find(fields = { fields: this.fields }, options, context) {
809
+ const query = createQuery(this.tableName, fields, options, this.tableInfo, this.relationMap, context);
810
+ return this.executeQuery(query, fields);
811
+ }
812
+ async findPageable(paging, fields = { fields: this.fields }, options, context) {
813
+ const query = createPagingFieldQuery({
814
+ baseTableName: this.tableName,
815
+ fields,
816
+ tableInfo: this.tableInfo,
817
+ relationMap: this.relationMap,
818
+ pagingOption: paging,
819
+ queryOption: options,
820
+ context
821
+ });
822
+ return this.executeQuery(query, fields);
823
+ }
824
+ async executeQuery(query, fields) {
825
+ const info = createQueryResolveInfo(this.tableName, fields, this.relationMap, this.tableInfo);
826
+ const sql = queryToSql(query);
827
+ return hydrate(await this.client.rawQuery(sql), info);
828
+ }
829
+ createIdentifiableExpression(entity) {
830
+ const expr = this.identifyFields.map((it) => {
831
+ const value = entity[it];
832
+ if (!value) throw new Error(`field ${it} is required`);
833
+ return QExpr.eq(QExpr.field(this.tableName, this.tableInfo[this.tableName].columnMap[it]), QExpr.value(value));
834
+ });
835
+ return QExpr.and(...expr);
836
+ }
837
+ getRelationMap() {
838
+ return this.relationMap[this.tableName];
839
+ }
840
+ fieldToColumn(fields) {
841
+ return fields.map((it) => this.tableInfo[this.tableName].columnMap[it] || it);
842
+ }
843
+ };
844
+ //#endregion
845
+ //#region src/util/dateUtil.ts
877
846
  const getCurrentDateTimeString = () => {
878
- const pad = (number) => {
879
- if (number < 10) {
880
- return "0" + number;
881
- }
882
- return number;
883
- };
884
- const date = /* @__PURE__ */ new Date();
885
- return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + " " + pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds());
886
- };
887
-
888
- const makeArgs = (args) => {
889
- if (!args || args.length === 0) return "";
890
- return `(${args.map((arg) => `${arg.name}: ${arg.type}`).join(", ")})`;
891
- };
892
- const makeTypedefString = (typeName, typedef, type) => {
893
- const entries = Object.entries(typedef);
894
- if (entries.length === 0) return "";
895
- return `${type} ${typeName} {
896
- ${entries.map(([field, value]) => {
897
- if (!value.return)
898
- throw new Error(`Return type required: ${typeName}.${field}`);
899
- return ` ${field}${makeArgs(value.args)}: ${value.return}`;
900
- }).join("\n")}
901
- }
902
- `;
903
- };
904
- const createTypeDef = (typeDefs, inputs) => {
905
- const types = Object.entries(typeDefs).map(
906
- ([type, fields]) => makeTypedefString(type, fields, "type")
907
- );
908
- const input = Object.entries(inputs).map(
909
- ([type, fields]) => makeTypedefString(type, fields, "input")
910
- );
911
- return types.join("\n") + input.join("\n");
912
- };
913
-
914
- var Comparison = /* @__PURE__ */ ((Comparison2) => {
915
- Comparison2["eq"] = "=";
916
- Comparison2["gt"] = ">";
917
- Comparison2["lt"] = "<";
918
- Comparison2["gte"] = ">=";
919
- Comparison2["lte"] = "<=";
920
- Comparison2["neq"] = "<>";
921
- Comparison2["like"] = "LIKE";
922
- Comparison2["notLike"] = "NOT LIKE";
923
- return Comparison2;
924
- })(Comparison || {});
925
- const comparisonExpressionToSql = (exp) => {
926
- const type = Object.prototype.hasOwnProperty.call(exp, "__type") ? exp.__type || "AND" : "AND";
927
- return Object.entries(exp).map(([key, value]) => {
928
- const column = SqlString__namespace.escapeId(key);
929
- if (!Array.isArray(value))
930
- return `${column} = ${SqlString__namespace.escape(value)}`;
931
- if (value[0] === "IS NULL") return `${column} IS NULL`;
932
- if (value[0] === "IS NOT NULL") return `${column} IS NOT NULL`;
933
- if (value[0] === "IN") {
934
- const [, ...columns] = value;
935
- return `${column} IN (${[
936
- columns.map((column2) => SqlString__namespace.escape(column2)).join(", ")
937
- ]})`;
938
- }
939
- if (value[0] === "BETWEEN")
940
- return `${column} BETWEEN ${SqlString__namespace.escape(
941
- value[1]
942
- )} AND ${SqlString__namespace.escape(value[2])}`;
943
- if (Object.keys(Comparison).includes(value[0]))
944
- return `${column} ${value[0]} ${SqlString__namespace.escape(value[1])}`;
945
- throw new error.SasatError("SQL PARSE ERROR");
946
- }).join(` ${type} `);
947
- };
948
-
949
- const conditionExpressionToSql = (exp) => {
950
- if (Array.isArray(exp)) {
951
- return CompositeCondition.and(exp).toSQL();
952
- }
953
- if (exp instanceof CompositeCondition) return exp.toSQL();
954
- return comparisonExpressionToSql(exp);
955
- };
956
-
957
- class CompositeCondition {
958
- constructor(type, conditions) {
959
- this.type = type;
960
- this.conditions = conditions;
961
- }
962
- static or(conditions) {
963
- return new CompositeCondition("OR", conditions);
964
- }
965
- static and(conditions) {
966
- return new CompositeCondition("AND", conditions);
967
- }
968
- toSQL() {
969
- return "(" + this.conditions.map(conditionExpressionToSql).join(this.type) + ")";
970
- }
971
- }
972
-
973
- const dateOffset = (date, timeZoneHour) => {
974
- const offset = timeZoneHour ? timeZoneHour * 60 * 60 * 1e3 : date.getTimezoneOffset() * 6e4;
975
- return new Date(date.getTime() + offset);
976
- };
977
- const zeroPad = (v, len) => v.toString().padStart(len, "0");
978
- const dateToDatetimeString = (d) => {
979
- const year = d.getUTCFullYear();
980
- const month = d.getUTCMonth() + 1;
981
- const day = d.getUTCDate();
982
- const hour = d.getUTCHours();
983
- const minute = d.getUTCMinutes();
984
- const second = d.getUTCSeconds();
985
- const millisecond = d.getUTCMilliseconds();
986
- return zeroPad(year, 4) + "-" + zeroPad(month, 2) + "-" + zeroPad(day, 2) + " " + zeroPad(hour, 2) + ":" + zeroPad(minute, 2) + ":" + zeroPad(second, 2) + "." + zeroPad(millisecond, 3);
987
- };
988
- const dateToDateString = (d) => {
989
- const year = d.getUTCFullYear();
990
- const month = d.getUTCMonth() + 1;
991
- const day = d.getUTCDate();
992
- return zeroPad(year, 4) + "-" + zeroPad(month, 2) + "-" + zeroPad(day, 2);
993
- };
994
- const getTodayDateString = (timeZoneHour) => {
995
- const date = /* @__PURE__ */ new Date();
996
- date.setHours(0, 0, 0, 0);
997
- return dateToDateString(dateOffset(date, timeZoneHour));
998
- };
999
- const getTodayDateTimeString = (timeZoneHour) => {
1000
- const date = /* @__PURE__ */ new Date();
1001
- date.setHours(0, 0, 0, 0);
1002
- return dateToDatetimeString(dateOffset(date, timeZoneHour));
1003
- };
1004
- const getDayRange = (date, timeZoneHour) => {
1005
- date.setHours(0, 0, 0, 0);
1006
- const d = dateOffset(date, timeZoneHour || 0);
1007
- const begin = dateToDatetimeString(d);
1008
- d.setDate(d.getDate() + 1);
1009
- return [begin, dateToDatetimeString(d)];
1010
- };
1011
- const getDayRangeQExpr = (date, timeZoneHour) => {
1012
- return getDayRange(date, timeZoneHour).map(QExpr.value);
1013
- };
1014
-
1015
- const makeResolver = (resolver, middlewares = []) => {
1016
- return (...args) => {
1017
- const newArgs = middlewares.reduce(
1018
- (args2, middleware) => {
1019
- return middleware(args2);
1020
- },
1021
- args
1022
- );
1023
- return resolver(...newArgs);
1024
- };
1025
- };
1026
-
847
+ const pad = (number) => {
848
+ if (number < 10) return "0" + number;
849
+ return number;
850
+ };
851
+ const date = /* @__PURE__ */ new Date();
852
+ return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + " " + pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds());
853
+ };
854
+ //#endregion
855
+ //#region src/runtime/pagingOption.ts
1027
856
  const pagingOption = (option) => {
1028
- const sort = option.order ? [
1029
- QExpr.sort(
1030
- QExpr.field("t1", option.order),
1031
- option?.asc === false ? "DESC" : "ASC"
1032
- )
1033
- ] : [];
1034
- return { numberOfItem: option.numberOfItem, offset: option.offset, sort };
1035
- };
1036
-
1037
- exports.Conditions = error.Conditions;
1038
- exports.SqlString = error.SqlString;
1039
- exports.assignDeep = error.assignDeep;
1040
- exports.formatQuery = error.formatQuery;
1041
- exports.getDbClient = error.getDbClient;
1042
- exports.pick = error.pick;
1043
- exports.setConfig = error.setConfig;
857
+ const sort = option.order ? [QExpr.sort(QExpr.field("t1", option.order), option?.asc === false ? "DESC" : "ASC")] : [];
858
+ return {
859
+ numberOfItem: option.numberOfItem,
860
+ offset: option.offset,
861
+ sort
862
+ };
863
+ };
864
+ //#endregion
1044
865
  exports.CompositeCondition = CompositeCondition;
866
+ exports.Conditions = require_migrate.Conditions;
1045
867
  exports.Mutations = Mutations;
868
+ exports.MysqlClient = MysqlClient;
1046
869
  exports.QExpr = QExpr;
1047
870
  exports.Queries = Queries;
1048
871
  exports.SasatDBDatasource = SasatDBDatasource;
1049
872
  exports.Sql = Sql;
873
+ exports.SqlString = require_migrate.SqlString;
874
+ exports.assignDeep = require_migrate.assignDeep;
1050
875
  exports.createTypeDef = createTypeDef;
1051
876
  exports.dateOffset = dateOffset;
1052
877
  exports.dateToDateString = dateToDateString;
1053
878
  exports.dateToDatetimeString = dateToDatetimeString;
879
+ exports.formatQuery = require_migrate.formatQuery;
1054
880
  exports.getCurrentDateTimeString = getCurrentDateTimeString;
1055
881
  exports.getDayRange = getDayRange;
1056
882
  exports.getDayRangeQExpr = getDayRangeQExpr;
883
+ exports.getDbClient = require_migrate.getDbClient;
1057
884
  exports.getTodayDateString = getTodayDateString;
1058
885
  exports.getTodayDateTimeString = getTodayDateTimeString;
1059
886
  exports.gqlResolveInfoToField = gqlResolveInfoToField;
1060
887
  exports.makeNumberIdEncoder = makeNumberIdEncoder;
1061
888
  exports.makeParamsMiddleware = makeParamsMiddleware;
1062
889
  exports.makeResolver = makeResolver;
890
+ exports.migrate = require_migrate.migrate;
1063
891
  exports.pagingOption = pagingOption;
892
+ exports.pick = require_migrate.pick;
1064
893
  exports.qe = QExpr;
1065
894
  exports.queryToSql = queryToSql;
895
+ exports.setConfig = require_migrate.setConfig;