@technicity/data-service-generator 0.14.0 → 0.14.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/generation/generate.d.ts +0 -1
- package/dist/generation/generate.js +309 -917
- package/dist/ksql.d.ts +15 -0
- package/dist/ksql.js +55 -0
- package/dist/runtime/Cache.js +3 -6
- package/dist/runtime/IRuntime.d.ts +17 -46
- package/dist/runtime/RuntimeKSQL.d.ts +19 -0
- package/dist/runtime/RuntimeKSQL.js +446 -0
- package/dist/runtime/RuntimeMSSQL.d.ts +1 -7
- package/dist/runtime/RuntimeMSSQL.js +4 -4
- package/dist/runtime/RuntimeMySQL.d.ts +1 -3
- package/dist/runtime/RuntimeMySQL.js +7 -33
- package/dist/runtime/lib/MSSQL.d.ts +1 -2
- package/dist/runtime/lib/MSSQL.js +8 -36
- package/dist/runtime/lib/MySQL.d.ts +1 -1
- package/dist/runtime/lib/MySQL.js +2 -15
- package/dist/runtime/lib/getSqlAst.js +121 -158
- package/dist/runtime/lib/runTransforms.d.ts +2 -0
- package/dist/runtime/lib/runTransforms.js +36 -0
- package/dist/runtime/lib/shared.d.ts +2 -1
- package/dist/runtime/lib/shared.js +71 -180
- package/dist/runtime/lib/stringifyWhere.js +12 -39
- package/dist/runtime/lib/typeCastMSSQL.js +1 -24
- package/dist/traverseFieldArgs.d.ts +2 -2
- package/dist/traverseFieldArgs.js +3 -8
- package/package.json +4 -1
- package/dist/runtime/RuntimeSQLite.d.ts +0 -38
- package/dist/runtime/RuntimeSQLite.js +0 -135
- package/dist/runtime/lib/addNullFallbacks.test.d.ts +0 -1
- package/dist/runtime/lib/addNullFallbacks.test.js +0 -206
- package/dist/runtime/lib/stringifyWhere.test.d.ts +0 -1
- package/dist/runtime/lib/stringifyWhere.test.js +0 -236
- package/dist/traverseFieldArgs.test.d.ts +0 -1
- package/dist/traverseFieldArgs.test.js +0 -56
|
@@ -1,30 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
3
|
exports._prepareWhere = exports.whereNeedsProcessing = exports.postProcess = exports.MiddlewareHandler = exports.resolve = void 0;
|
|
30
4
|
// @ts-ignore
|
|
@@ -32,16 +6,17 @@ exports._prepareWhere = exports.whereNeedsProcessing = exports.postProcess = exp
|
|
|
32
6
|
// @ts-ignore
|
|
33
7
|
// import arrToConnection from "join-monster/dist/array-to-connection";
|
|
34
8
|
// @ts-ignore
|
|
35
|
-
const batch_planner_1 =
|
|
9
|
+
const batch_planner_1 = require("join-monster/dist/batch-planner");
|
|
36
10
|
// @ts-ignore
|
|
37
11
|
const util_1 = require("join-monster/dist/util");
|
|
38
12
|
const async_hooks_1 = require("async_hooks");
|
|
39
|
-
const _ =
|
|
13
|
+
const _ = require("lodash/fp");
|
|
40
14
|
const uuid_1 = require("uuid");
|
|
41
15
|
const getSqlAst_1 = require("./getSqlAst");
|
|
42
16
|
const getWhere_1 = require("./getWhere");
|
|
43
17
|
const getDateTimeStringMySQL_1 = require("./getDateTimeStringMySQL");
|
|
44
18
|
const cursor_1 = require("./cursor");
|
|
19
|
+
const runTransforms_1 = require("./runTransforms");
|
|
45
20
|
const addNullFallbacks_1 = require("./addNullFallbacks");
|
|
46
21
|
const SDKNotFoundError_1 = require("./SDKNotFoundError");
|
|
47
22
|
const SDKBadWhereError_1 = require("./SDKBadWhereError");
|
|
@@ -70,9 +45,9 @@ exports.resolve = resolve;
|
|
|
70
45
|
function _resolve(input, dbCall, formatQuery, beginTransaction, dialect, context, cache) {
|
|
71
46
|
switch (input.action) {
|
|
72
47
|
case "findMany":
|
|
73
|
-
return cache && !input.skipCache
|
|
74
|
-
|
|
75
|
-
|
|
48
|
+
return cache && !input.skipCache ?
|
|
49
|
+
getCached(input, dbCall, formatQuery, dialect, cache) :
|
|
50
|
+
getData(input, dbCall, formatQuery, dialect);
|
|
76
51
|
case "findUnique":
|
|
77
52
|
case "findManyPaginated":
|
|
78
53
|
return getData(input, dbCall, formatQuery, dialect);
|
|
@@ -141,7 +116,7 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
141
116
|
rowWithMatchingCursor = await dbCall(formatQuery("SELECT * FROM ?? WHERE ?? = ?", [
|
|
142
117
|
input.resource,
|
|
143
118
|
primaryKey,
|
|
144
|
-
(0, cursor_1.decodeCursor)(cursor)
|
|
119
|
+
(0, cursor_1.decodeCursor)(cursor),
|
|
145
120
|
])).then((xs) => xs[0]);
|
|
146
121
|
if (rowWithMatchingCursor == null) {
|
|
147
122
|
throw new Error(`Invalid cursor: ${cursor}`);
|
|
@@ -159,19 +134,15 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
159
134
|
}
|
|
160
135
|
// we need to read the query AST and build a new "SQL AST" from which the SQL and
|
|
161
136
|
// const sqlAST = queryAST.queryASTToSqlAST(resolveInfo, options, context);
|
|
162
|
-
const fields = input.fields ??
|
|
163
|
-
getScalarFields(input.resource, input.artifacts).reduce((acc, x) => {
|
|
164
|
-
acc[x] = true;
|
|
165
|
-
return acc;
|
|
166
|
-
}, {});
|
|
137
|
+
const fields = input.fields ?? getScalarFields(input.resource, input.artifacts);
|
|
167
138
|
const orderByListPaginatedRootResult =
|
|
168
139
|
// MSSQL's OFFSET and FETCH requires ORDER BY, so we need to provide a fallback
|
|
169
140
|
dialect === "mssql" && paginationType === "limit-offset"
|
|
170
141
|
? {
|
|
171
142
|
orderBy: (0, getOrderBy_1.getOrderBy)(input.args, primaryKey)?.orderBy ?? [
|
|
172
|
-
{ column: primaryKey, direction: "asc" }
|
|
143
|
+
{ column: primaryKey, direction: "asc" },
|
|
173
144
|
],
|
|
174
|
-
flip: false
|
|
145
|
+
flip: false,
|
|
175
146
|
}
|
|
176
147
|
: action === "findManyPaginated"
|
|
177
148
|
? (0, getOrderBy_1.getOrderBy)(input.args, primaryKey)
|
|
@@ -189,9 +160,9 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
189
160
|
orderBy: orderByListPaginatedRootResult?.orderBy,
|
|
190
161
|
rowWithMatchingCursor,
|
|
191
162
|
dialect,
|
|
192
|
-
grabMany
|
|
163
|
+
grabMany,
|
|
193
164
|
});
|
|
194
|
-
const options = { dialect
|
|
165
|
+
const options = { dialect };
|
|
195
166
|
let { sql, shapeDefinition } = await (0, util_1.compileSqlAST)(sqlAST, context, options);
|
|
196
167
|
if (!sql) {
|
|
197
168
|
// return {};
|
|
@@ -234,9 +205,6 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
234
205
|
// Do later for `listPaginated`, since the `id` is needed for
|
|
235
206
|
// creating the cursor
|
|
236
207
|
postProcess(data, fields, shouldRemoveExtraKeys);
|
|
237
|
-
if (dialect === "sqlite") {
|
|
238
|
-
typeCastSqlite(data, fields, input.resource, input.artifacts);
|
|
239
|
-
}
|
|
240
208
|
}
|
|
241
209
|
// check for batch data
|
|
242
210
|
if (Array.isArray(data)) {
|
|
@@ -270,12 +238,12 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
270
238
|
fieldName: "data",
|
|
271
239
|
args: argsTotalCount,
|
|
272
240
|
// Because we're going to manually set children anyway
|
|
273
|
-
fields:
|
|
241
|
+
fields: [],
|
|
274
242
|
getWhere: getWhere_1.getWhere,
|
|
275
243
|
// We don't want the where clause to include cursor-related stuff
|
|
276
244
|
rowWithMatchingCursor: null,
|
|
277
245
|
dialect,
|
|
278
|
-
grabMany: true
|
|
246
|
+
grabMany: true,
|
|
279
247
|
});
|
|
280
248
|
// Because orderBy doesn't matter for total count.
|
|
281
249
|
// getOrderBy adds an element if paginating, so deleting args.$orderBy
|
|
@@ -285,16 +253,10 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
285
253
|
if (paginationType === "cursor") {
|
|
286
254
|
data = wrapListPaginationCursor(data, input.args, orderByListPaginatedRootResult.flip, (xs) => {
|
|
287
255
|
postProcess(xs, fields, shouldRemoveExtraKeys);
|
|
288
|
-
if (dialect === "sqlite") {
|
|
289
|
-
typeCastSqlite(data, fields, input.resource, input.artifacts);
|
|
290
|
-
}
|
|
291
256
|
}, input.artifacts[input.resource].primaryKey, totalCount);
|
|
292
257
|
}
|
|
293
258
|
else {
|
|
294
259
|
postProcess(data, fields, shouldRemoveExtraKeys);
|
|
295
|
-
if (dialect === "sqlite") {
|
|
296
|
-
typeCastSqlite(data, fields, input.resource, input.artifacts);
|
|
297
|
-
}
|
|
298
260
|
data = wrapListPaginationLimitOffset(data, totalCount);
|
|
299
261
|
}
|
|
300
262
|
}
|
|
@@ -343,23 +305,21 @@ async function getCached(input, dbCall, formatQuery, dialect, cache) {
|
|
|
343
305
|
function ensureUuidSelect(input) {
|
|
344
306
|
const { resource, artifacts } = input;
|
|
345
307
|
const remove = [];
|
|
346
|
-
ensure(resource, input
|
|
308
|
+
ensure(resource, input);
|
|
347
309
|
function ensure(type, input, path = []) {
|
|
348
310
|
const { scalarFields, relationFields } = artifacts[type];
|
|
349
311
|
if (!scalarFields.includes("uuid"))
|
|
350
312
|
return;
|
|
351
|
-
const fields = input ||
|
|
352
|
-
if (!
|
|
313
|
+
const fields = input.fields || [];
|
|
314
|
+
if (!fields.includes("uuid")) {
|
|
353
315
|
remove.push(path);
|
|
354
|
-
fields
|
|
316
|
+
fields.unshift("uuid");
|
|
355
317
|
}
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const table = relationFields[
|
|
360
|
-
|
|
361
|
-
ensure(table, v.$fields, path.concat(k));
|
|
362
|
-
}
|
|
318
|
+
for (const field of fields)
|
|
319
|
+
if (typeof field == "object") {
|
|
320
|
+
const { name } = field;
|
|
321
|
+
const { table } = relationFields[name];
|
|
322
|
+
ensure(table, field, path.concat(name));
|
|
363
323
|
}
|
|
364
324
|
}
|
|
365
325
|
return remove;
|
|
@@ -393,9 +353,9 @@ function wrapListPaginationCursor(data, args, flip, cb, primaryKey, totalCount)
|
|
|
393
353
|
hasNextPage,
|
|
394
354
|
startCursor,
|
|
395
355
|
endCursor,
|
|
396
|
-
totalCount
|
|
356
|
+
totalCount,
|
|
397
357
|
},
|
|
398
|
-
results: data
|
|
358
|
+
results: data,
|
|
399
359
|
};
|
|
400
360
|
}
|
|
401
361
|
async function getTotalCount(sqlASTTotalCount, dbCall, context, options) {
|
|
@@ -406,8 +366,8 @@ async function getTotalCount(sqlASTTotalCount, dbCall, context, options) {
|
|
|
406
366
|
type: "expression",
|
|
407
367
|
sqlExpr: () => "COUNT(*)",
|
|
408
368
|
fieldName: fieldNameTotalCount,
|
|
409
|
-
as: fieldNameTotalCount
|
|
410
|
-
}
|
|
369
|
+
as: fieldNameTotalCount,
|
|
370
|
+
},
|
|
411
371
|
];
|
|
412
372
|
const { sql: sqlTotalCount } = await (0, util_1.compileSqlAST)(sqlASTTotalCount, context, options);
|
|
413
373
|
const totalCount = await dbCall(sqlTotalCount).then((xs) => xs[0][fieldNameTotalCount]);
|
|
@@ -482,21 +442,15 @@ async function create(input, dbCall, formatQuery, beginTransaction, dialect, con
|
|
|
482
442
|
}
|
|
483
443
|
else {
|
|
484
444
|
data = processCreateData(data, tableArtifacts, dialect, context?.specialCaseUuidColumn);
|
|
485
|
-
if (dialect === "
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
const inserted = await dbCall(formatQuery(`INSERT INTO ?? (??) VALUES (?) SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY]`, [input.resource, columns, values]));
|
|
489
|
-
return inserted[0]["SCOPE_IDENTITY"];
|
|
445
|
+
if (dialect === "mysql") {
|
|
446
|
+
const inserted = await dbCall(formatQuery("INSERT INTO ?? SET ?", [input.resource, data]));
|
|
447
|
+
return inserted.insertId;
|
|
490
448
|
}
|
|
491
449
|
else {
|
|
492
450
|
const columns = Object.keys(data);
|
|
493
451
|
const values = Object.values(data);
|
|
494
|
-
const inserted = await dbCall(formatQuery(`INSERT INTO ?? (??) VALUES (?)`, [
|
|
495
|
-
|
|
496
|
-
columns,
|
|
497
|
-
values
|
|
498
|
-
]));
|
|
499
|
-
return inserted.insertId;
|
|
452
|
+
const inserted = await dbCall(formatQuery(`INSERT INTO ?? (??) VALUES (?) SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY]`, [input.resource, columns, values]));
|
|
453
|
+
return inserted[0]["SCOPE_IDENTITY"];
|
|
500
454
|
}
|
|
501
455
|
}
|
|
502
456
|
}
|
|
@@ -554,7 +508,7 @@ function getCreateTree(data, table, referencedKey, specialCaseUuidColumn, dialec
|
|
|
554
508
|
referencedKey,
|
|
555
509
|
columns: [],
|
|
556
510
|
values: [],
|
|
557
|
-
children: []
|
|
511
|
+
children: [],
|
|
558
512
|
};
|
|
559
513
|
for (let i = 0; i < data.length; i++) {
|
|
560
514
|
let d = data[i];
|
|
@@ -643,19 +597,19 @@ function getUpdateQuery(table, data, where, dialect, formatQuery) {
|
|
|
643
597
|
const op = _entries?.[0];
|
|
644
598
|
const vv = _entries?.[1];
|
|
645
599
|
if (op === "$prepend") {
|
|
646
|
-
opsStrs.push(`${escapeId(k)} = CASE WHEN ${escapeId(k)} IS NULL THEN NULL ELSE ${
|
|
600
|
+
opsStrs.push(`${table}.${escapeId(k)} = CASE WHEN ${table}.${escapeId(k)} IS NULL THEN NULL ELSE CONCAT(${escape(vv)}, ${table}.${escapeId(k)}) END`);
|
|
647
601
|
continue;
|
|
648
602
|
}
|
|
649
603
|
if (op === "$append") {
|
|
650
|
-
opsStrs.push(`${escapeId(k)} = CASE WHEN ${escapeId(k)} IS NULL THEN NULL ELSE ${
|
|
604
|
+
opsStrs.push(`${table}.${escapeId(k)} = CASE WHEN ${table}.${escapeId(k)} IS NULL THEN NULL ELSE CONCAT(${table}.${escapeId(k)}, ${escape(vv)}) END`);
|
|
651
605
|
continue;
|
|
652
606
|
}
|
|
653
607
|
if (op === "$increment") {
|
|
654
|
-
opsStrs.push(`${escapeId(k)} = ${escapeId(k)} + ${escape(vv)}`);
|
|
608
|
+
opsStrs.push(`${table}.${escapeId(k)} = ${table}.${escapeId(k)} + ${escape(vv)}`);
|
|
655
609
|
continue;
|
|
656
610
|
}
|
|
657
611
|
if (op === "$decrement") {
|
|
658
|
-
opsStrs.push(`${escapeId(k)} = ${escapeId(k)} - ${escape(vv)}`);
|
|
612
|
+
opsStrs.push(`${table}.${escapeId(k)} = ${table}.${escapeId(k)} - ${escape(vv)}`);
|
|
659
613
|
continue;
|
|
660
614
|
}
|
|
661
615
|
dataRegular[k] = v;
|
|
@@ -665,28 +619,18 @@ function getUpdateQuery(table, data, where, dialect, formatQuery) {
|
|
|
665
619
|
if (opsStrs.length > 0) {
|
|
666
620
|
q += `SET ${opsStrs.join(", ")}`;
|
|
667
621
|
}
|
|
668
|
-
|
|
669
|
-
if (columns.length > 0) {
|
|
622
|
+
if (Object.keys(dataRegular).length > 0) {
|
|
670
623
|
if (opsStrs.length > 0) {
|
|
671
|
-
q += ", ";
|
|
624
|
+
q += ", ?";
|
|
672
625
|
}
|
|
673
626
|
else {
|
|
674
|
-
q += "SET ";
|
|
675
|
-
}
|
|
676
|
-
q += columns.map((x) => `${escapeId(x)} = ?`).join(", ");
|
|
677
|
-
for (let k in dataRegular) {
|
|
678
|
-
values.push(dataRegular[k]);
|
|
627
|
+
q += "SET ?";
|
|
679
628
|
}
|
|
629
|
+
values.push(dataRegular);
|
|
680
630
|
}
|
|
681
631
|
q += ` WHERE ${where}`;
|
|
682
632
|
return formatQuery(q, values);
|
|
683
633
|
}
|
|
684
|
-
function stringifyConcat(operand1, operand2, dialect) {
|
|
685
|
-
if (dialect !== "sqlite") {
|
|
686
|
-
return `CONCAT(${operand1}, ${operand2})`;
|
|
687
|
-
}
|
|
688
|
-
return `(${operand1} || ${operand2})`;
|
|
689
|
-
}
|
|
690
634
|
async function updateMany(input, dbCall, formatQuery, dialect, cache) {
|
|
691
635
|
async function _updateMany() {
|
|
692
636
|
const escapeId = (0, stringifyWhere_1.getEscapeId)(dialect);
|
|
@@ -697,9 +641,7 @@ async function updateMany(input, dbCall, formatQuery, dialect, cache) {
|
|
|
697
641
|
}
|
|
698
642
|
if (cache)
|
|
699
643
|
try {
|
|
700
|
-
const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [
|
|
701
|
-
input.resource
|
|
702
|
-
]);
|
|
644
|
+
const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [input.resource]);
|
|
703
645
|
const matches = await dbCall(query);
|
|
704
646
|
const uuids = matches.map((x) => x.uuid);
|
|
705
647
|
cache.purge(...uuids);
|
|
@@ -739,7 +681,7 @@ async function deleteOne(input, dbCall, formatQuery, dialect, cache) {
|
|
|
739
681
|
const current = await dbCall(formatQuery("SELECT * FROM ?? WHERE ?? = ?", [
|
|
740
682
|
input.resource,
|
|
741
683
|
findOne.key,
|
|
742
|
-
findOne.value
|
|
684
|
+
findOne.value,
|
|
743
685
|
])).then((xs) => xs[0]);
|
|
744
686
|
if (current == null) {
|
|
745
687
|
throw new SDKNotFoundError_1.SDKNotFoundError();
|
|
@@ -749,7 +691,7 @@ async function deleteOne(input, dbCall, formatQuery, dialect, cache) {
|
|
|
749
691
|
await dbCall(formatQuery("DELETE FROM ?? WHERE ?? = ?", [
|
|
750
692
|
input.resource,
|
|
751
693
|
findOne.key,
|
|
752
|
-
findOne.value
|
|
694
|
+
findOne.value,
|
|
753
695
|
]));
|
|
754
696
|
return true;
|
|
755
697
|
}
|
|
@@ -761,9 +703,7 @@ async function deleteMany(input, dbCall, formatQuery, dialect, cache) {
|
|
|
761
703
|
}
|
|
762
704
|
if (cache)
|
|
763
705
|
try {
|
|
764
|
-
const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [
|
|
765
|
-
input.resource
|
|
766
|
-
]);
|
|
706
|
+
const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [input.resource]);
|
|
767
707
|
const matches = await dbCall(query);
|
|
768
708
|
const uuids = matches.map((x) => x.uuid);
|
|
769
709
|
cache.purge(...uuids);
|
|
@@ -812,7 +752,7 @@ async function mapMappedFields(artifactsForTable, data, dbCall, formatQuery) {
|
|
|
812
752
|
mappedField.referencedKey,
|
|
813
753
|
mappedField.referencedTable,
|
|
814
754
|
mappedField.name,
|
|
815
|
-
w
|
|
755
|
+
w,
|
|
816
756
|
])).then((xs) => xs[0]?.[mappedField.referencedKey]);
|
|
817
757
|
if (result == null) {
|
|
818
758
|
throw new SDKNotFoundError_1.SDKNotFoundError();
|
|
@@ -826,7 +766,7 @@ async function mapMappedFields(artifactsForTable, data, dbCall, formatQuery) {
|
|
|
826
766
|
mappedField.referencedKey,
|
|
827
767
|
mappedField.referencedTable,
|
|
828
768
|
mappedField.name,
|
|
829
|
-
v
|
|
769
|
+
v,
|
|
830
770
|
])).then((xs) => xs[0]?.[mappedField.referencedKey]);
|
|
831
771
|
if (result == null) {
|
|
832
772
|
throw new SDKNotFoundError_1.SDKNotFoundError();
|
|
@@ -837,18 +777,30 @@ async function mapMappedFields(artifactsForTable, data, dbCall, formatQuery) {
|
|
|
837
777
|
}
|
|
838
778
|
}
|
|
839
779
|
// 1. Remove additional keys added to data for batches and joins
|
|
780
|
+
// 2. Execute `transform` functions if they exist
|
|
840
781
|
function postProcess(data, fields, shouldRemoveExtraKeys) {
|
|
841
782
|
if (shouldRemoveExtraKeys) {
|
|
842
783
|
removeExtraKeys(data, fields);
|
|
843
784
|
}
|
|
785
|
+
(0, runTransforms_1.runTransforms)(data, fields);
|
|
844
786
|
}
|
|
845
787
|
exports.postProcess = postProcess;
|
|
846
788
|
function removeExtraKeys(data, fields) {
|
|
847
789
|
if (data == null || (Array.isArray(data) && data[0] == null)) {
|
|
848
790
|
return;
|
|
849
791
|
}
|
|
850
|
-
let fieldKeys =
|
|
851
|
-
|
|
792
|
+
let fieldKeys = [];
|
|
793
|
+
for (let x of fields) {
|
|
794
|
+
if (typeof x === "string") {
|
|
795
|
+
fieldKeys.push(x);
|
|
796
|
+
}
|
|
797
|
+
else {
|
|
798
|
+
fieldKeys.push(x.as ?? x.name);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
const dataKeys = Array.isArray(data)
|
|
802
|
+
? Object.keys(data[0])
|
|
803
|
+
: Object.keys(data);
|
|
852
804
|
const extraDataKeys = _.difference(dataKeys, fieldKeys);
|
|
853
805
|
for (let k of extraDataKeys) {
|
|
854
806
|
if (Array.isArray(data)) {
|
|
@@ -860,77 +812,16 @@ function removeExtraKeys(data, fields) {
|
|
|
860
812
|
delete data[k];
|
|
861
813
|
}
|
|
862
814
|
}
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
if (Array.isArray(data)) {
|
|
867
|
-
for (let d of data) {
|
|
868
|
-
removeExtraKeys(d[k], v.$fields);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
else {
|
|
872
|
-
removeExtraKeys(data[k], v.$fields);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
const getTypeCastMap = _.memoize(function getTypeCastMap(artifacts) {
|
|
878
|
-
const typeCastMap = new Map();
|
|
879
|
-
for (let table in artifacts) {
|
|
880
|
-
let booleanColumns = new Set();
|
|
881
|
-
for (let field of artifacts[table].fields) {
|
|
882
|
-
if (field.kind === "scalar" && field.type === "boolean") {
|
|
883
|
-
booleanColumns.add(field.name);
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
typeCastMap.set(table, { boolean: booleanColumns });
|
|
887
|
-
}
|
|
888
|
-
return typeCastMap;
|
|
889
|
-
});
|
|
890
|
-
function typeCastSqlite(data, fields, table, artifacts) {
|
|
891
|
-
if (data == null || (Array.isArray(data) && data[0] == null)) {
|
|
892
|
-
return;
|
|
893
|
-
}
|
|
894
|
-
const typeCastMap = getTypeCastMap(artifacts);
|
|
895
|
-
const booleanColumns = typeCastMap.get(table)?.boolean;
|
|
896
|
-
if (booleanColumns == null) {
|
|
897
|
-
throw new Error(`Failed to resolve typeCastMap for table \`${table}\``);
|
|
898
|
-
}
|
|
899
|
-
if (booleanColumns.size > 0) {
|
|
900
|
-
const keys = Object.keys(fields);
|
|
901
|
-
for (let k of keys) {
|
|
902
|
-
if (booleanColumns.has(k)) {
|
|
903
|
-
if (Array.isArray(data)) {
|
|
904
|
-
for (let d of data) {
|
|
905
|
-
d[k] = !!d[k];
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
else {
|
|
909
|
-
data[k] = !!data[k];
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
const tableArtifacts = artifacts[table];
|
|
915
|
-
const entries = Object.entries(fields);
|
|
916
|
-
for (let [k, v] of entries) {
|
|
917
|
-
if (typeof v === "object") {
|
|
918
|
-
const relationFields = tableArtifacts.relationFields[k];
|
|
919
|
-
if (relationFields == null) {
|
|
920
|
-
throw new Error(`Failed to resolve relationFields for field \`${k}\``);
|
|
921
|
-
}
|
|
922
|
-
const fields = v.$fields ??
|
|
923
|
-
tableArtifacts.scalarFields.reduce((acc, x) => {
|
|
924
|
-
acc[x] = true;
|
|
925
|
-
return acc;
|
|
926
|
-
}, {});
|
|
815
|
+
for (let x of fields) {
|
|
816
|
+
if (typeof x === "object") {
|
|
817
|
+
const k = typeof x === "string" ? x : x.as ?? x.name;
|
|
927
818
|
if (Array.isArray(data)) {
|
|
928
819
|
for (let d of data) {
|
|
929
|
-
|
|
820
|
+
removeExtraKeys(d[k], x.fields);
|
|
930
821
|
}
|
|
931
822
|
}
|
|
932
823
|
else {
|
|
933
|
-
|
|
824
|
+
removeExtraKeys(data[k], x.fields);
|
|
934
825
|
}
|
|
935
826
|
}
|
|
936
827
|
}
|
|
@@ -957,7 +848,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
|
957
848
|
mappedField.referencedKey,
|
|
958
849
|
mappedField.referencedTable,
|
|
959
850
|
mappedField.name,
|
|
960
|
-
v
|
|
851
|
+
v,
|
|
961
852
|
])).then((xs) => xs[0]?.[mappedField.referencedKey])));
|
|
962
853
|
if (newVal.some((x) => x == null)) {
|
|
963
854
|
const index = newVal.findIndex((x) => x == null);
|
|
@@ -976,7 +867,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
|
976
867
|
mappedField.referencedKey,
|
|
977
868
|
mappedField.referencedTable,
|
|
978
869
|
mappedField.name,
|
|
979
|
-
where
|
|
870
|
+
where,
|
|
980
871
|
])).then((xs) => xs[0]?.[mappedField.referencedKey]);
|
|
981
872
|
if (newVal == null) {
|
|
982
873
|
throw new SDKBadWhereError_1.SDKBadWhereError(getPrepareWhereNotFoundMessage(mappedField, where));
|
|
@@ -999,7 +890,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
|
999
890
|
mappedField.referencedKey,
|
|
1000
891
|
mappedField.referencedTable,
|
|
1001
892
|
mappedField.name,
|
|
1002
|
-
v
|
|
893
|
+
v,
|
|
1003
894
|
])).then((xs) => xs[0]?.[mappedField.referencedKey])));
|
|
1004
895
|
if (newVal.some((x) => x == null)) {
|
|
1005
896
|
const index = newVal.findIndex((x) => x == null);
|
|
@@ -1018,7 +909,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
|
1018
909
|
mappedField.referencedKey,
|
|
1019
910
|
mappedField.referencedTable,
|
|
1020
911
|
mappedField.name,
|
|
1021
|
-
where
|
|
912
|
+
where,
|
|
1022
913
|
])).then((xs) => xs[0]?.[mappedField.referencedKey]);
|
|
1023
914
|
if (newVal == null) {
|
|
1024
915
|
throw new SDKBadWhereError_1.SDKBadWhereError(getPrepareWhereNotFoundMessage(mappedField, where));
|
|
@@ -1050,7 +941,7 @@ const ops = [
|
|
|
1050
941
|
"$like",
|
|
1051
942
|
"$nlike",
|
|
1052
943
|
"$btwn",
|
|
1053
|
-
"$nbtwn"
|
|
944
|
+
"$nbtwn",
|
|
1054
945
|
];
|
|
1055
946
|
async function traverseWhere(where, cb) {
|
|
1056
947
|
return await _traverseWhere(cb, where, "", where);
|
|
@@ -1,35 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.getEscape = exports.getEscapeId = exports.stringifyWhere = void 0;
|
|
27
|
-
const _ =
|
|
28
|
-
const MySqlString =
|
|
29
|
-
// @ts-
|
|
30
|
-
const TSqlString =
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
const SqliteString = __importStar(require("sqlstring-sqlite"));
|
|
4
|
+
const _ = require("lodash/fp");
|
|
5
|
+
const MySqlString = require("sqlstring");
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
const TSqlString = require("tsqlstring");
|
|
33
8
|
function stringifyWhere(input) {
|
|
34
9
|
const { where, table, dialect, args, orderBy, rowWithMatchingCursor } = input;
|
|
35
10
|
const escapeId = getEscapeId(dialect);
|
|
@@ -41,11 +16,13 @@ function stringifyWhere(input) {
|
|
|
41
16
|
orderBy,
|
|
42
17
|
escapeId,
|
|
43
18
|
escape,
|
|
44
|
-
rowWithMatchingCursor
|
|
19
|
+
rowWithMatchingCursor,
|
|
45
20
|
});
|
|
46
21
|
if (paginationWhere) {
|
|
47
22
|
result =
|
|
48
|
-
result.length === 0
|
|
23
|
+
result.length === 0
|
|
24
|
+
? paginationWhere
|
|
25
|
+
: result + " AND " + paginationWhere;
|
|
49
26
|
}
|
|
50
27
|
return result;
|
|
51
28
|
}
|
|
@@ -107,7 +84,9 @@ function _stringifyWhere(where, table, escapeId, escape, result) {
|
|
|
107
84
|
if (v === null) {
|
|
108
85
|
return `${table}.${escapeId(k)} IS NULL`;
|
|
109
86
|
}
|
|
110
|
-
if (typeof v === "string" ||
|
|
87
|
+
if (typeof v === "string" ||
|
|
88
|
+
typeof v === "number" ||
|
|
89
|
+
typeof v === "boolean") {
|
|
111
90
|
return `${table}.${escapeId(k)} = ${printValue(v)}`;
|
|
112
91
|
}
|
|
113
92
|
if (_.isPlainObject(v)) {
|
|
@@ -117,7 +96,7 @@ function _stringifyWhere(where, table, escapeId, escape, result) {
|
|
|
117
96
|
}
|
|
118
97
|
const operator = keys[0];
|
|
119
98
|
const operand = v[operator];
|
|
120
|
-
if (operator === "$
|
|
99
|
+
if (operator === "$ne") {
|
|
121
100
|
return `${table}.${escapeId(k)} ${getOperatorNeq(v)} ${printValue(operand)}`;
|
|
122
101
|
}
|
|
123
102
|
if (operator === "$gt") {
|
|
@@ -234,9 +213,6 @@ function getEscapeId(dialect) {
|
|
|
234
213
|
if (dialect === "mssql") {
|
|
235
214
|
return TSqlString.escapeId.bind(TSqlString);
|
|
236
215
|
}
|
|
237
|
-
if (dialect === "sqlite") {
|
|
238
|
-
return SqliteString.escapeId.bind(SqliteString);
|
|
239
|
-
}
|
|
240
216
|
throw new Error("Unsupported dialect: " + dialect);
|
|
241
217
|
}
|
|
242
218
|
exports.getEscapeId = getEscapeId;
|
|
@@ -247,9 +223,6 @@ function getEscape(dialect) {
|
|
|
247
223
|
if (dialect === "mssql") {
|
|
248
224
|
return TSqlString.escape.bind(TSqlString);
|
|
249
225
|
}
|
|
250
|
-
if (dialect === "sqlite") {
|
|
251
|
-
return SqliteString.escape.bind(SqliteString);
|
|
252
|
-
}
|
|
253
226
|
throw new Error("Unsupported dialect: " + dialect);
|
|
254
227
|
}
|
|
255
228
|
exports.getEscape = getEscape;
|
|
@@ -1,30 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.typeCastMSSQL = void 0;
|
|
27
|
-
const mssql =
|
|
4
|
+
const mssql = require("mssql");
|
|
28
5
|
// TODO: see https://github.com/tediousjs/node-mssql/pull/1171
|
|
29
6
|
function typeCastMSSQL(customTypeCast) {
|
|
30
7
|
return function (result, meta) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IArgs,
|
|
2
|
-
export declare function traverseFieldArgs(fields:
|
|
1
|
+
import { IArgs, IField } from "./runtime/IRuntime";
|
|
2
|
+
export declare function traverseFieldArgs(fields: IField[], cb: (args: IArgs | undefined) => IArgs): void;
|
|
@@ -2,17 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.traverseFieldArgs = void 0;
|
|
4
4
|
function traverseFieldArgs(fields, cb) {
|
|
5
|
-
|
|
6
|
-
for (let x of values) {
|
|
5
|
+
for (let x of fields) {
|
|
7
6
|
if (typeof x !== "object") {
|
|
8
7
|
continue;
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
continue;
|
|
13
|
-
}
|
|
14
|
-
cb(x);
|
|
15
|
-
traverseFieldArgs(fields, cb);
|
|
9
|
+
x.args = cb(x.args);
|
|
10
|
+
traverseFieldArgs(x.fields, cb);
|
|
16
11
|
}
|
|
17
12
|
}
|
|
18
13
|
exports.traverseFieldArgs = traverseFieldArgs;
|