@technicity/data-service-generator 0.11.6 → 0.11.7-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/generation/generate.d.ts +3 -3
- package/dist/generation/generate.js +6 -122
- package/dist/lib/getDuplicates.js +1 -2
- package/dist/lib/isNotNullOrUndefined.js +1 -2
- package/dist/runtime/Cache.d.ts +1 -1
- package/dist/runtime/IRuntime.d.ts +28 -28
- package/dist/runtime/Stats.d.ts +0 -4
- package/dist/runtime/Stats.js +1 -2
- package/dist/runtime/lib/addNullFallbacks.js +1 -2
- package/dist/runtime/lib/cursor.js +2 -3
- package/dist/runtime/lib/getDateTimeStringMySQL.js +1 -2
- package/dist/runtime/lib/getOrderBy.js +1 -2
- package/dist/runtime/lib/getSqlAst.js +15 -21
- package/dist/runtime/lib/getWhere.js +1 -2
- package/dist/runtime/lib/runTransforms.js +1 -2
- package/dist/runtime/lib/shared.js +38 -101
- package/dist/runtime/lib/stringifyWhere.d.ts +5 -4
- package/dist/runtime/lib/stringifyWhere.js +10 -19
- package/dist/runtime/lib/utility.js +2 -3
- package/dist/traverseFieldArgs.js +1 -2
- package/package.json +5 -8
- package/dist/ksql.d.ts +0 -15
- package/dist/ksql.js +0 -55
- package/dist/runtime/RuntimeKSQL.d.ts +0 -26
- package/dist/runtime/RuntimeKSQL.js +0 -453
- package/dist/runtime/RuntimeMSSQL.d.ts +0 -25
- package/dist/runtime/RuntimeMSSQL.js +0 -58
- package/dist/runtime/lib/MSSQL.d.ts +0 -14
- package/dist/runtime/lib/MSSQL.js +0 -78
- package/dist/runtime/lib/typeCastMSSQL.d.ts +0 -3
- package/dist/runtime/lib/typeCastMSSQL.js +0 -40
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MiddlewareHandler = void 0;
|
|
4
|
+
exports.resolve = resolve;
|
|
5
|
+
exports.postProcess = postProcess;
|
|
6
|
+
exports.whereNeedsProcessing = whereNeedsProcessing;
|
|
7
|
+
exports._prepareWhere = _prepareWhere;
|
|
4
8
|
// @ts-ignore
|
|
5
9
|
// import * as queryAST from "join-monster/dist/query-ast-to-sql-ast";
|
|
6
10
|
// @ts-ignore
|
|
@@ -41,13 +45,12 @@ async function resolve(input, dbCall, formatQuery, beginTransaction, dialect, mi
|
|
|
41
45
|
}
|
|
42
46
|
return _resolve(input, dbCall, formatQuery, beginTransaction, dialect, context, cache);
|
|
43
47
|
}
|
|
44
|
-
exports.resolve = resolve;
|
|
45
48
|
function _resolve(input, dbCall, formatQuery, beginTransaction, dialect, context, cache) {
|
|
46
49
|
switch (input.action) {
|
|
47
50
|
case "findMany":
|
|
48
|
-
return cache && !input.skipCache
|
|
49
|
-
getCached(input, dbCall, formatQuery, dialect, cache)
|
|
50
|
-
getData(input, dbCall, formatQuery, dialect);
|
|
51
|
+
return cache && !input.skipCache
|
|
52
|
+
? getCached(input, dbCall, formatQuery, dialect, cache)
|
|
53
|
+
: getData(input, dbCall, formatQuery, dialect);
|
|
51
54
|
case "findUnique":
|
|
52
55
|
case "findManyPaginated":
|
|
53
56
|
return getData(input, dbCall, formatQuery, dialect);
|
|
@@ -116,7 +119,7 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
116
119
|
rowWithMatchingCursor = await dbCall(formatQuery("SELECT * FROM ?? WHERE ?? = ?", [
|
|
117
120
|
input.resource,
|
|
118
121
|
primaryKey,
|
|
119
|
-
(0, cursor_1.decodeCursor)(cursor)
|
|
122
|
+
(0, cursor_1.decodeCursor)(cursor)
|
|
120
123
|
])).then((xs) => xs[0]);
|
|
121
124
|
if (rowWithMatchingCursor == null) {
|
|
122
125
|
throw new Error(`Invalid cursor: ${cursor}`);
|
|
@@ -135,18 +138,7 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
135
138
|
// we need to read the query AST and build a new "SQL AST" from which the SQL and
|
|
136
139
|
// const sqlAST = queryAST.queryASTToSqlAST(resolveInfo, options, context);
|
|
137
140
|
const fields = input.fields ?? getScalarFields(input.resource, input.artifacts);
|
|
138
|
-
const orderByListPaginatedRootResult =
|
|
139
|
-
// MSSQL's OFFSET and FETCH requires ORDER BY, so we need to provide a fallback
|
|
140
|
-
dialect === "mssql" && paginationType === "limit-offset"
|
|
141
|
-
? {
|
|
142
|
-
orderBy: (0, getOrderBy_1.getOrderBy)(input.args, primaryKey)?.orderBy ?? [
|
|
143
|
-
{ column: primaryKey, direction: "asc" },
|
|
144
|
-
],
|
|
145
|
-
flip: false,
|
|
146
|
-
}
|
|
147
|
-
: action === "findManyPaginated"
|
|
148
|
-
? (0, getOrderBy_1.getOrderBy)(input.args, primaryKey)
|
|
149
|
-
: undefined;
|
|
141
|
+
const orderByListPaginatedRootResult = action === "findManyPaginated" ? (0, getOrderBy_1.getOrderBy)(input.args, primaryKey) : undefined;
|
|
150
142
|
const grabMany = action === "findMany" ||
|
|
151
143
|
action === "findManyPaginated" ||
|
|
152
144
|
action === "updateMany" ||
|
|
@@ -160,7 +152,7 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
160
152
|
orderBy: orderByListPaginatedRootResult?.orderBy,
|
|
161
153
|
rowWithMatchingCursor,
|
|
162
154
|
dialect,
|
|
163
|
-
grabMany
|
|
155
|
+
grabMany
|
|
164
156
|
});
|
|
165
157
|
const options = { dialect };
|
|
166
158
|
let { sql, shapeDefinition } = await (0, util_1.compileSqlAST)(sqlAST, context, options);
|
|
@@ -172,19 +164,9 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
172
164
|
if (action === "findMany" || action === "findManyPaginated") {
|
|
173
165
|
if (typeof limit === "number") {
|
|
174
166
|
const escape = (0, stringifyWhere_1.getEscape)(dialect);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
sql = sql.replace("SELECT", `SELECT TOP ${escape(limit)}`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
sql += ` LIMIT ${escape(limit)}`;
|
|
185
|
-
if (typeof offset === "number") {
|
|
186
|
-
sql += ` OFFSET ${escape(offset)}`;
|
|
187
|
-
}
|
|
167
|
+
sql += ` LIMIT ${escape(limit)}`;
|
|
168
|
+
if (typeof offset === "number") {
|
|
169
|
+
sql += ` OFFSET ${escape(offset)}`;
|
|
188
170
|
}
|
|
189
171
|
}
|
|
190
172
|
}
|
|
@@ -243,7 +225,7 @@ async function getData(input, dbCall, formatQuery, dialect) {
|
|
|
243
225
|
// We don't want the where clause to include cursor-related stuff
|
|
244
226
|
rowWithMatchingCursor: null,
|
|
245
227
|
dialect,
|
|
246
|
-
grabMany: true
|
|
228
|
+
grabMany: true
|
|
247
229
|
});
|
|
248
230
|
// Because orderBy doesn't matter for total count.
|
|
249
231
|
// getOrderBy adds an element if paginating, so deleting args.$orderBy
|
|
@@ -353,9 +335,9 @@ function wrapListPaginationCursor(data, args, flip, cb, primaryKey, totalCount)
|
|
|
353
335
|
hasNextPage,
|
|
354
336
|
startCursor,
|
|
355
337
|
endCursor,
|
|
356
|
-
totalCount
|
|
338
|
+
totalCount
|
|
357
339
|
},
|
|
358
|
-
results: data
|
|
340
|
+
results: data
|
|
359
341
|
};
|
|
360
342
|
}
|
|
361
343
|
async function getTotalCount(sqlASTTotalCount, dbCall, context, options) {
|
|
@@ -366,8 +348,8 @@ async function getTotalCount(sqlASTTotalCount, dbCall, context, options) {
|
|
|
366
348
|
type: "expression",
|
|
367
349
|
sqlExpr: () => "COUNT(*)",
|
|
368
350
|
fieldName: fieldNameTotalCount,
|
|
369
|
-
as: fieldNameTotalCount
|
|
370
|
-
}
|
|
351
|
+
as: fieldNameTotalCount
|
|
352
|
+
}
|
|
371
353
|
];
|
|
372
354
|
const { sql: sqlTotalCount } = await (0, util_1.compileSqlAST)(sqlASTTotalCount, context, options);
|
|
373
355
|
const totalCount = await dbCall(sqlTotalCount).then((xs) => xs[0][fieldNameTotalCount]);
|
|
@@ -384,37 +366,6 @@ const runCreateTreeMySQL = async (table, referencedKey, referencedKeyValue, colu
|
|
|
384
366
|
}
|
|
385
367
|
return Promise.all(allColumns.map((cs, i) => dbCall(formatQuery(`INSERT INTO ?? (??) VALUES (?)`, [table, cs, allValues[i]])).then((x) => x.insertId)));
|
|
386
368
|
};
|
|
387
|
-
// This doesn't use bulk inserts because:
|
|
388
|
-
// 1. columns aren't necessarily uniform
|
|
389
|
-
// 2. We don't want to do backflips to get all the inserted IDs
|
|
390
|
-
const runCreateTreeMSSQL = async (table, referencedKey, referencedKeyValue, columns, values, dbCall, formatQuery) => {
|
|
391
|
-
let allColumns = columns;
|
|
392
|
-
if (typeof referencedKey === "string") {
|
|
393
|
-
allColumns = allColumns.slice().map((xs) => xs.concat(referencedKey));
|
|
394
|
-
}
|
|
395
|
-
let allValues = values;
|
|
396
|
-
if (referencedKeyValue != null) {
|
|
397
|
-
allValues = allValues.slice().map((xs) => xs.concat(referencedKeyValue));
|
|
398
|
-
}
|
|
399
|
-
// https://github.com/tediousjs/node-mssql/issues/302
|
|
400
|
-
// return Promise.all(
|
|
401
|
-
// allColumns.map((cs, i) =>
|
|
402
|
-
// dbCall(
|
|
403
|
-
// formatQuery(
|
|
404
|
-
// `INSERT INTO ?? (??) VALUES (?) SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY]`,
|
|
405
|
-
// [table, cs, allValues[i]]
|
|
406
|
-
// )
|
|
407
|
-
// ).then((xs) => xs[0]["SCOPE_IDENTITY"])
|
|
408
|
-
// )
|
|
409
|
-
// );
|
|
410
|
-
let out = [];
|
|
411
|
-
let i = 0;
|
|
412
|
-
for (let cs of allColumns) {
|
|
413
|
-
out.push(await dbCall(formatQuery(`INSERT INTO ?? (??) VALUES (?) SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY]`, [table, cs, allValues[i]])).then((xs) => xs[0]["SCOPE_IDENTITY"]));
|
|
414
|
-
i += 1;
|
|
415
|
-
}
|
|
416
|
-
return out;
|
|
417
|
-
};
|
|
418
369
|
async function create(input, dbCall, formatQuery, beginTransaction, dialect, context) {
|
|
419
370
|
async function _create() {
|
|
420
371
|
// Shallow clone, as we're going to mutate later
|
|
@@ -436,7 +387,7 @@ async function create(input, dbCall, formatQuery, beginTransaction, dialect, con
|
|
|
436
387
|
});
|
|
437
388
|
if (hasChildren) {
|
|
438
389
|
const { dbCall: dbCallTransaction, commit } = await beginTransaction();
|
|
439
|
-
const id = await runCreateTree(getCreateTree([data], input.resource, null, context?.specialCaseUuidColumn, dialect, input.artifacts), null,
|
|
390
|
+
const id = await runCreateTree(getCreateTree([data], input.resource, null, context?.specialCaseUuidColumn, dialect, input.artifacts), null, runCreateTreeMySQL, dbCallTransaction, formatQuery, dialect).then((xs) => xs[0]);
|
|
440
391
|
await commit();
|
|
441
392
|
return id;
|
|
442
393
|
}
|
|
@@ -483,20 +434,7 @@ function processCreateData(data, tableArtifacts, dialect, specialCaseUuidColumn)
|
|
|
483
434
|
async function runCreateTree(tree, referencedKeyValue, runCreateTreeSQL, dbCall, formatQuery, dialect) {
|
|
484
435
|
const ids = await runCreateTreeSQL(tree.table, tree.referencedKey, referencedKeyValue, tree.columns, tree.values, dbCall, formatQuery);
|
|
485
436
|
if (tree.children?.length > 0) {
|
|
486
|
-
|
|
487
|
-
if (dialect === "mssql") {
|
|
488
|
-
const idIndexes = Array(ids.length)
|
|
489
|
-
.fill(null)
|
|
490
|
-
.map((_, i) => i);
|
|
491
|
-
for (let i of idIndexes) {
|
|
492
|
-
for (let c of tree.children[i]) {
|
|
493
|
-
await runCreateTree(c, ids[i], runCreateTreeSQL, dbCall, formatQuery, dialect);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
await Promise.all(ids.flatMap((id, i) => tree.children[i].map((c) => runCreateTree(c, id, runCreateTreeSQL, dbCall, formatQuery, dialect))));
|
|
499
|
-
}
|
|
437
|
+
await Promise.all(ids.flatMap((id, i) => tree.children[i].map((c) => runCreateTree(c, id, runCreateTreeSQL, dbCall, formatQuery, dialect))));
|
|
500
438
|
}
|
|
501
439
|
return ids;
|
|
502
440
|
}
|
|
@@ -508,7 +446,7 @@ function getCreateTree(data, table, referencedKey, specialCaseUuidColumn, dialec
|
|
|
508
446
|
referencedKey,
|
|
509
447
|
columns: [],
|
|
510
448
|
values: [],
|
|
511
|
-
children: []
|
|
449
|
+
children: []
|
|
512
450
|
};
|
|
513
451
|
for (let i = 0; i < data.length; i++) {
|
|
514
452
|
let d = data[i];
|
|
@@ -641,7 +579,9 @@ async function updateMany(input, dbCall, formatQuery, dialect, cache) {
|
|
|
641
579
|
}
|
|
642
580
|
if (cache)
|
|
643
581
|
try {
|
|
644
|
-
const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [
|
|
582
|
+
const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [
|
|
583
|
+
input.resource
|
|
584
|
+
]);
|
|
645
585
|
const matches = await dbCall(query);
|
|
646
586
|
const uuids = matches.map((x) => x.uuid);
|
|
647
587
|
cache.purge(...uuids);
|
|
@@ -681,7 +621,7 @@ async function deleteOne(input, dbCall, formatQuery, dialect, cache) {
|
|
|
681
621
|
const current = await dbCall(formatQuery("SELECT * FROM ?? WHERE ?? = ?", [
|
|
682
622
|
input.resource,
|
|
683
623
|
findOne.key,
|
|
684
|
-
findOne.value
|
|
624
|
+
findOne.value
|
|
685
625
|
])).then((xs) => xs[0]);
|
|
686
626
|
if (current == null) {
|
|
687
627
|
throw new SDKNotFoundError_1.SDKNotFoundError();
|
|
@@ -691,7 +631,7 @@ async function deleteOne(input, dbCall, formatQuery, dialect, cache) {
|
|
|
691
631
|
await dbCall(formatQuery("DELETE FROM ?? WHERE ?? = ?", [
|
|
692
632
|
input.resource,
|
|
693
633
|
findOne.key,
|
|
694
|
-
findOne.value
|
|
634
|
+
findOne.value
|
|
695
635
|
]));
|
|
696
636
|
return true;
|
|
697
637
|
}
|
|
@@ -703,7 +643,9 @@ async function deleteMany(input, dbCall, formatQuery, dialect, cache) {
|
|
|
703
643
|
}
|
|
704
644
|
if (cache)
|
|
705
645
|
try {
|
|
706
|
-
const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [
|
|
646
|
+
const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [
|
|
647
|
+
input.resource
|
|
648
|
+
]);
|
|
707
649
|
const matches = await dbCall(query);
|
|
708
650
|
const uuids = matches.map((x) => x.uuid);
|
|
709
651
|
cache.purge(...uuids);
|
|
@@ -752,7 +694,7 @@ async function mapMappedFields(artifactsForTable, data, dbCall, formatQuery) {
|
|
|
752
694
|
mappedField.referencedKey,
|
|
753
695
|
mappedField.referencedTable,
|
|
754
696
|
mappedField.name,
|
|
755
|
-
w
|
|
697
|
+
w
|
|
756
698
|
])).then((xs) => xs[0]?.[mappedField.referencedKey]);
|
|
757
699
|
if (result == null) {
|
|
758
700
|
throw new SDKNotFoundError_1.SDKNotFoundError();
|
|
@@ -766,7 +708,7 @@ async function mapMappedFields(artifactsForTable, data, dbCall, formatQuery) {
|
|
|
766
708
|
mappedField.referencedKey,
|
|
767
709
|
mappedField.referencedTable,
|
|
768
710
|
mappedField.name,
|
|
769
|
-
v
|
|
711
|
+
v
|
|
770
712
|
])).then((xs) => xs[0]?.[mappedField.referencedKey]);
|
|
771
713
|
if (result == null) {
|
|
772
714
|
throw new SDKNotFoundError_1.SDKNotFoundError();
|
|
@@ -784,7 +726,6 @@ function postProcess(data, fields, shouldRemoveExtraKeys) {
|
|
|
784
726
|
}
|
|
785
727
|
(0, runTransforms_1.runTransforms)(data, fields);
|
|
786
728
|
}
|
|
787
|
-
exports.postProcess = postProcess;
|
|
788
729
|
function removeExtraKeys(data, fields) {
|
|
789
730
|
if (data == null || (Array.isArray(data) && data[0] == null)) {
|
|
790
731
|
return;
|
|
@@ -798,9 +739,7 @@ function removeExtraKeys(data, fields) {
|
|
|
798
739
|
fieldKeys.push(x.as ?? x.name);
|
|
799
740
|
}
|
|
800
741
|
}
|
|
801
|
-
const dataKeys = Array.isArray(data)
|
|
802
|
-
? Object.keys(data[0])
|
|
803
|
-
: Object.keys(data);
|
|
742
|
+
const dataKeys = Array.isArray(data) ? Object.keys(data[0]) : Object.keys(data);
|
|
804
743
|
const extraDataKeys = _.difference(dataKeys, fieldKeys);
|
|
805
744
|
for (let k of extraDataKeys) {
|
|
806
745
|
if (Array.isArray(data)) {
|
|
@@ -829,7 +768,6 @@ function removeExtraKeys(data, fields) {
|
|
|
829
768
|
function whereNeedsProcessing(where) {
|
|
830
769
|
return JSON.stringify(where).includes("Uuid");
|
|
831
770
|
}
|
|
832
|
-
exports.whereNeedsProcessing = whereNeedsProcessing;
|
|
833
771
|
async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
834
772
|
const mappedFields = artifacts[table].mappedFields;
|
|
835
773
|
let out = {};
|
|
@@ -848,7 +786,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
|
848
786
|
mappedField.referencedKey,
|
|
849
787
|
mappedField.referencedTable,
|
|
850
788
|
mappedField.name,
|
|
851
|
-
v
|
|
789
|
+
v
|
|
852
790
|
])).then((xs) => xs[0]?.[mappedField.referencedKey])));
|
|
853
791
|
if (newVal.some((x) => x == null)) {
|
|
854
792
|
const index = newVal.findIndex((x) => x == null);
|
|
@@ -867,7 +805,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
|
867
805
|
mappedField.referencedKey,
|
|
868
806
|
mappedField.referencedTable,
|
|
869
807
|
mappedField.name,
|
|
870
|
-
where
|
|
808
|
+
where
|
|
871
809
|
])).then((xs) => xs[0]?.[mappedField.referencedKey]);
|
|
872
810
|
if (newVal == null) {
|
|
873
811
|
throw new SDKBadWhereError_1.SDKBadWhereError(getPrepareWhereNotFoundMessage(mappedField, where));
|
|
@@ -890,7 +828,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
|
890
828
|
mappedField.referencedKey,
|
|
891
829
|
mappedField.referencedTable,
|
|
892
830
|
mappedField.name,
|
|
893
|
-
v
|
|
831
|
+
v
|
|
894
832
|
])).then((xs) => xs[0]?.[mappedField.referencedKey])));
|
|
895
833
|
if (newVal.some((x) => x == null)) {
|
|
896
834
|
const index = newVal.findIndex((x) => x == null);
|
|
@@ -909,7 +847,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
|
909
847
|
mappedField.referencedKey,
|
|
910
848
|
mappedField.referencedTable,
|
|
911
849
|
mappedField.name,
|
|
912
|
-
where
|
|
850
|
+
where
|
|
913
851
|
])).then((xs) => xs[0]?.[mappedField.referencedKey]);
|
|
914
852
|
if (newVal == null) {
|
|
915
853
|
throw new SDKBadWhereError_1.SDKBadWhereError(getPrepareWhereNotFoundMessage(mappedField, where));
|
|
@@ -925,7 +863,6 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
|
|
|
925
863
|
});
|
|
926
864
|
return out;
|
|
927
865
|
}
|
|
928
|
-
exports._prepareWhere = _prepareWhere;
|
|
929
866
|
function getPrepareWhereNotFoundMessage(mappedField, value) {
|
|
930
867
|
return `Not found: unable to map \`${mappedField.referencedTable}\`.\`${mappedField.name}\` to \`${mappedField.referencedTable}\`.\`${mappedField.referencedKey}\` for the value \`${value}\`.`;
|
|
931
868
|
}
|
|
@@ -941,7 +878,7 @@ const ops = [
|
|
|
941
878
|
"$like",
|
|
942
879
|
"$nlike",
|
|
943
880
|
"$btwn",
|
|
944
|
-
"$nbtwn"
|
|
881
|
+
"$nbtwn"
|
|
945
882
|
];
|
|
946
883
|
async function traverseWhere(where, cb) {
|
|
947
884
|
return await _traverseWhere(cb, where, "", where);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import * as MySqlString from "sqlstring";
|
|
1
2
|
import type { IOrderBy, IDialect } from "../IRuntime";
|
|
2
|
-
|
|
3
|
+
type IWhere = {
|
|
3
4
|
[k: string]: any;
|
|
4
5
|
};
|
|
5
|
-
|
|
6
|
+
type IArgs = {
|
|
6
7
|
[k: string]: any;
|
|
7
8
|
};
|
|
8
9
|
export declare function stringifyWhere(input: {
|
|
@@ -13,6 +14,6 @@ export declare function stringifyWhere(input: {
|
|
|
13
14
|
orderBy?: IOrderBy | undefined;
|
|
14
15
|
rowWithMatchingCursor?: any;
|
|
15
16
|
}): string;
|
|
16
|
-
export declare function getEscapeId(dialect: IDialect):
|
|
17
|
-
export declare function getEscape(dialect: IDialect):
|
|
17
|
+
export declare function getEscapeId(dialect: IDialect): typeof MySqlString.escapeId;
|
|
18
|
+
export declare function getEscape(dialect: IDialect): typeof MySqlString.escape;
|
|
18
19
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.stringifyWhere = stringifyWhere;
|
|
4
|
+
exports.getEscapeId = getEscapeId;
|
|
5
|
+
exports.getEscape = getEscape;
|
|
4
6
|
const _ = require("lodash/fp");
|
|
5
7
|
const MySqlString = require("sqlstring");
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
const TSqlString = require("tsqlstring");
|
|
8
8
|
function stringifyWhere(input) {
|
|
9
9
|
const { where, table, dialect, args, orderBy, rowWithMatchingCursor } = input;
|
|
10
10
|
const escapeId = getEscapeId(dialect);
|
|
@@ -16,17 +16,14 @@ function stringifyWhere(input) {
|
|
|
16
16
|
orderBy,
|
|
17
17
|
escapeId,
|
|
18
18
|
escape,
|
|
19
|
-
rowWithMatchingCursor
|
|
19
|
+
rowWithMatchingCursor
|
|
20
20
|
});
|
|
21
21
|
if (paginationWhere) {
|
|
22
22
|
result =
|
|
23
|
-
result.length === 0
|
|
24
|
-
? paginationWhere
|
|
25
|
-
: result + " AND " + paginationWhere;
|
|
23
|
+
result.length === 0 ? paginationWhere : result + " AND " + paginationWhere;
|
|
26
24
|
}
|
|
27
25
|
return result;
|
|
28
26
|
}
|
|
29
|
-
exports.stringifyWhere = stringifyWhere;
|
|
30
27
|
function _stringifyWhere(where, table, escapeId, escape, result) {
|
|
31
28
|
if (Object.prototype.hasOwnProperty.call(where, "$and")) {
|
|
32
29
|
if (Object.keys(where).length !== 1) {
|
|
@@ -84,9 +81,7 @@ function _stringifyWhere(where, table, escapeId, escape, result) {
|
|
|
84
81
|
if (v === null) {
|
|
85
82
|
return `${table}.${escapeId(k)} IS NULL`;
|
|
86
83
|
}
|
|
87
|
-
if (typeof v === "string" ||
|
|
88
|
-
typeof v === "number" ||
|
|
89
|
-
typeof v === "boolean") {
|
|
84
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
90
85
|
return `${table}.${escapeId(k)} = ${printValue(v)}`;
|
|
91
86
|
}
|
|
92
87
|
if (_.isPlainObject(v)) {
|
|
@@ -119,6 +114,8 @@ function _stringifyWhere(where, table, escapeId, escape, result) {
|
|
|
119
114
|
}
|
|
120
115
|
if (operator === "$in") {
|
|
121
116
|
if (operand.length === 0) {
|
|
117
|
+
// Edit: no longer relevant, since the MSSQL dialect was
|
|
118
|
+
// removed, but keep the same for stability.
|
|
122
119
|
// Would do "FALSE" instead, as it's more readable, but it
|
|
123
120
|
// causes a RequestError in MSSQL.
|
|
124
121
|
return "(1=0)";
|
|
@@ -129,6 +126,8 @@ function _stringifyWhere(where, table, escapeId, escape, result) {
|
|
|
129
126
|
}
|
|
130
127
|
if (operator === "$nin") {
|
|
131
128
|
if (operand.length === 0) {
|
|
129
|
+
// Edit: no longer relevant, since the MSSQL dialect was
|
|
130
|
+
// removed, but keep the same for stability.
|
|
132
131
|
// Would do "TRUE" instead, as it's more readable, but it
|
|
133
132
|
// causes a RequestError in MSSQL.
|
|
134
133
|
return "(1=1)";
|
|
@@ -210,19 +209,11 @@ function getEscapeId(dialect) {
|
|
|
210
209
|
if (dialect === "mysql") {
|
|
211
210
|
return MySqlString.escapeId.bind(MySqlString);
|
|
212
211
|
}
|
|
213
|
-
if (dialect === "mssql") {
|
|
214
|
-
return TSqlString.escapeId.bind(TSqlString);
|
|
215
|
-
}
|
|
216
212
|
throw new Error("Unsupported dialect: " + dialect);
|
|
217
213
|
}
|
|
218
|
-
exports.getEscapeId = getEscapeId;
|
|
219
214
|
function getEscape(dialect) {
|
|
220
215
|
if (dialect === "mysql") {
|
|
221
216
|
return MySqlString.escape.bind(MySqlString);
|
|
222
217
|
}
|
|
223
|
-
if (dialect === "mssql") {
|
|
224
|
-
return TSqlString.escape.bind(TSqlString);
|
|
225
|
-
}
|
|
226
218
|
throw new Error("Unsupported dialect: " + dialect);
|
|
227
219
|
}
|
|
228
|
-
exports.getEscape = getEscape;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.mapAsync = mapAsync;
|
|
4
|
+
exports.flatten = flatten;
|
|
4
5
|
/**
|
|
5
6
|
* Eagerly resolve and map input values then concatinate.
|
|
6
7
|
*/
|
|
@@ -8,8 +9,6 @@ async function mapAsync(source, mapFunction) {
|
|
|
8
9
|
const output = (await source).map(mapFunction);
|
|
9
10
|
return Promise.all(flatten(output)).then(flatten);
|
|
10
11
|
}
|
|
11
|
-
exports.mapAsync = mapAsync;
|
|
12
12
|
function flatten(array) {
|
|
13
13
|
return [].concat(...array);
|
|
14
14
|
}
|
|
15
|
-
exports.flatten = flatten;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseFieldArgs =
|
|
3
|
+
exports.traverseFieldArgs = traverseFieldArgs;
|
|
4
4
|
function traverseFieldArgs(fields, cb) {
|
|
5
5
|
for (let x of fields) {
|
|
6
6
|
if (typeof x !== "object") {
|
|
@@ -10,4 +10,3 @@ function traverseFieldArgs(fields, cb) {
|
|
|
10
10
|
traverseFieldArgs(x.fields, cb);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
exports.traverseFieldArgs = traverseFieldArgs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@technicity/data-service-generator",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.7-next.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"compile": "rm -rf dist && tsc",
|
|
10
10
|
"publish:next": "npm version prerelease --preid next",
|
|
11
11
|
"preversion": "npm run compile",
|
|
12
|
-
"reset": "docker
|
|
13
|
-
"test:docker": "docker
|
|
12
|
+
"reset": "docker compose rm -svf mysql57 && docker compose up -d mysql57",
|
|
13
|
+
"test:docker": "docker compose exec test yarn test:sdk",
|
|
14
14
|
"generate": "npm run compile && concurrently \"node ./test/mysql/generate.js\" \"node ./test/mysql8/generate.js\"",
|
|
15
15
|
"test": "npm run generate && mocha ./test/addNullFallbacks.test.js && mocha ./test/stringifyWhere.test.js && npm run test:sdk",
|
|
16
|
-
"test:prepare": "docker
|
|
16
|
+
"test:prepare": "docker compose down --volumes && docker compose up -d --build",
|
|
17
17
|
"test:sdk": "mocha --inspect=0.0.0.0:9229 ./test/test.js"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
@@ -27,17 +27,14 @@
|
|
|
27
27
|
"json-schema-to-typescript": "10.1.5",
|
|
28
28
|
"lodash": "^4.17.20",
|
|
29
29
|
"loglevel": "^1.8.1",
|
|
30
|
-
"mssql": "^6.3.1",
|
|
31
30
|
"mysql": "^2.18.1",
|
|
32
31
|
"prettier": "^2.1.2",
|
|
33
32
|
"sqlstring": "^2.3.2",
|
|
34
|
-
"tsqlstring": "^1.0.1",
|
|
35
33
|
"uuid": "^8.3.2"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
36
|
"@types/fs-extra": "9.0.13",
|
|
39
37
|
"@types/lodash": "4.14.177",
|
|
40
|
-
"@types/mssql": "^6.0.7",
|
|
41
38
|
"@types/node": "14.17.9",
|
|
42
39
|
"@types/prettier": "^2.1.5",
|
|
43
40
|
"@types/sqlstring": "^2.2.1",
|
|
@@ -46,6 +43,6 @@
|
|
|
46
43
|
"env-cmd": "^10.1.0",
|
|
47
44
|
"mocha": "9.1.3",
|
|
48
45
|
"sinon": "12.0.1",
|
|
49
|
-
"typescript": "
|
|
46
|
+
"typescript": "5.5.2"
|
|
50
47
|
}
|
|
51
48
|
}
|
package/dist/ksql.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare type THeaders = {
|
|
2
|
-
[k: string]: any;
|
|
3
|
-
};
|
|
4
|
-
export declare class KSQL {
|
|
5
|
-
hostname: string;
|
|
6
|
-
port: number;
|
|
7
|
-
headers?: THeaders;
|
|
8
|
-
constructor(options: {
|
|
9
|
-
hostname: string;
|
|
10
|
-
port: number;
|
|
11
|
-
headers?: THeaders;
|
|
12
|
-
});
|
|
13
|
-
streamQuery(s: string): Promise<any[]>;
|
|
14
|
-
}
|
|
15
|
-
export {};
|
package/dist/ksql.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KSQL = void 0;
|
|
4
|
-
const http2 = require("http2");
|
|
5
|
-
class KSQL {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
this.hostname = options.hostname;
|
|
8
|
-
this.port = options.port;
|
|
9
|
-
this.headers = options.headers;
|
|
10
|
-
}
|
|
11
|
-
async streamQuery(s) {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
const reqBody = JSON.stringify({
|
|
14
|
-
sql: s,
|
|
15
|
-
properties: {
|
|
16
|
-
"ksql.streams.auto.offset.reset": "earliest",
|
|
17
|
-
"ksql.query.pull.table.scan.enabled": true,
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
const client = http2.connect(`https://${this.hostname}:${this.port}`);
|
|
21
|
-
const req = client.request({
|
|
22
|
-
[http2.constants.HTTP2_HEADER_SCHEME]: "https",
|
|
23
|
-
"Content-Type": "application/json",
|
|
24
|
-
"Content-Length": reqBody.length,
|
|
25
|
-
":method": "POST",
|
|
26
|
-
":path": `/query-stream`,
|
|
27
|
-
...this.headers,
|
|
28
|
-
});
|
|
29
|
-
req.setEncoding("utf8");
|
|
30
|
-
let columnNames = [];
|
|
31
|
-
let rows = [];
|
|
32
|
-
req.on("data", (d) => {
|
|
33
|
-
const resData = JSON.parse(d);
|
|
34
|
-
if (resData.error_code) {
|
|
35
|
-
return reject(new Error(resData.message));
|
|
36
|
-
}
|
|
37
|
-
if (resData.columnNames) {
|
|
38
|
-
columnNames = resData.columnNames;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
let out = {};
|
|
42
|
-
resData.forEach((rd, i) => {
|
|
43
|
-
out[columnNames[i]] = rd;
|
|
44
|
-
});
|
|
45
|
-
rows.push(out);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
req.on("close", () => resolve(rows));
|
|
49
|
-
req.on("error", (error) => reject(error));
|
|
50
|
-
req.write(reqBody);
|
|
51
|
-
req.end();
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.KSQL = KSQL;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { IRuntime, TMiddleware, TResolveParams, IArtifacts, TDbCall } from "./IRuntime";
|
|
2
|
-
import { KSQL } from "../ksql";
|
|
3
|
-
declare type TGetTableName = (table: string) => string;
|
|
4
|
-
export declare class RuntimeKSQL implements IRuntime {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(clientOpts: ConstructorParameters<typeof KSQL>[0], otherOpts: {
|
|
7
|
-
getBaseTableName: TGetTableName;
|
|
8
|
-
getMaterializedViewName: TGetTableName;
|
|
9
|
-
doNotUseMaterializedViews?: boolean;
|
|
10
|
-
_dbCall: TDbCall;
|
|
11
|
-
}, artifacts: IArtifacts);
|
|
12
|
-
resolve(input: TResolveParams): Promise<any>;
|
|
13
|
-
$queryRaw(sql: string, values?: any[]): Promise<any>;
|
|
14
|
-
$use(middleware: TMiddleware): Promise<void>;
|
|
15
|
-
$whereNeedsProcessing(where: any): boolean;
|
|
16
|
-
$prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
|
|
17
|
-
$shutdown(): Promise<void>;
|
|
18
|
-
$startTransaction(input?: {
|
|
19
|
-
isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
|
|
20
|
-
}): Promise<{
|
|
21
|
-
dbCall: (q: string) => Promise<string>;
|
|
22
|
-
commit: () => Promise<void>;
|
|
23
|
-
rollback: () => Promise<void>;
|
|
24
|
-
}>;
|
|
25
|
-
}
|
|
26
|
-
export {};
|