@technicity/data-service-generator 0.10.0-next.0 → 0.11.0-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/dist/generation/generate.js +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -3
- package/dist/runtime/RuntimeKSQL.d.ts +1 -1
- package/dist/runtime/RuntimeKSQL.js +11 -13
- package/dist/runtime/RuntimeMSSQL.d.ts +14 -18
- package/dist/runtime/RuntimeMSSQL.js +43 -48
- package/dist/runtime/RuntimeMySQL.d.ts +12 -10
- package/dist/runtime/RuntimeMySQL.js +84 -46
- package/dist/runtime/lib/MSSQL.d.ts +13 -0
- package/dist/runtime/lib/MSSQL.js +73 -0
- package/dist/runtime/lib/SDKBadWhereError.d.ts +4 -0
- package/dist/runtime/lib/SDKBadWhereError.js +10 -0
- package/dist/runtime/lib/SDKNotFoundError.d.ts +4 -0
- package/dist/runtime/lib/SDKNotFoundError.js +10 -0
- package/dist/runtime/lib/getDateTimeStringMySQL.d.ts +1 -0
- package/dist/runtime/lib/getDateTimeStringMySQL.js +8 -0
- package/dist/runtime/lib/getSqlAst.js +2 -2
- package/dist/runtime/lib/getWhere.d.ts +0 -17
- package/dist/runtime/lib/getWhere.js +4 -228
- package/dist/runtime/lib/shared.d.ts +13 -22
- package/dist/runtime/lib/shared.js +787 -16
- package/dist/runtime/lib/stringifyWhere.d.ts +18 -0
- package/dist/runtime/lib/stringifyWhere.js +228 -0
- package/dist/runtime/lib/typeCastMSSQL.js +1 -1
- package/package.json +4 -1
- package/dist/runtime/Runtime.d.ts +0 -23
- package/dist/runtime/Runtime.js +0 -29
- package/dist/runtime/lib/create.d.ts +0 -12
- package/dist/runtime/lib/create.js +0 -175
- package/dist/runtime/lib/delete.d.ts +0 -5
- package/dist/runtime/lib/delete.js +0 -43
- package/dist/runtime/lib/error.d.ts +0 -9
- package/dist/runtime/lib/error.js +0 -22
- package/dist/runtime/lib/getData.d.ts +0 -4
- package/dist/runtime/lib/getData.js +0 -227
- package/dist/runtime/lib/prepareWhere.d.ts +0 -2
- package/dist/runtime/lib/prepareWhere.js +0 -158
- package/dist/runtime/lib/resolve.d.ts +0 -10
- package/dist/runtime/lib/resolve.js +0 -66
- package/dist/runtime/lib/update.d.ts +0 -4
- package/dist/runtime/lib/update.js +0 -143
|
@@ -9,6 +9,7 @@ const prettier = require("prettier");
|
|
|
9
9
|
const changeCase = require("change-case");
|
|
10
10
|
const fse = require("fs-extra");
|
|
11
11
|
const _ = require("lodash/fp");
|
|
12
|
+
const uuid_1 = require("uuid");
|
|
12
13
|
const mssql = require("mssql");
|
|
13
14
|
// @ts-ignore
|
|
14
15
|
const TSqlString = require("tsqlstring");
|
|
@@ -83,7 +84,7 @@ async function generate(input) {
|
|
|
83
84
|
typescript: require("../../package.json").devDependencies.typescript,
|
|
84
85
|
},
|
|
85
86
|
};
|
|
86
|
-
const tmpDirPath = path.join(os.tmpdir(), `dsg-${
|
|
87
|
+
const tmpDirPath = path.join(os.tmpdir(), `dsg-${(0, uuid_1.v4)()}`);
|
|
87
88
|
fse.mkdirpSync(tmpDirPath);
|
|
88
89
|
fs.writeFileSync(path.join(tmpDirPath, sdkFilename), sdkSource);
|
|
89
90
|
fs.writeFileSync(path.join(tmpDirPath, artifactsFilename), artifactsSource);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { generate } from "./generation/generate";
|
|
2
|
-
export { SDKNotFoundError
|
|
2
|
+
export { SDKNotFoundError } from "./runtime/lib/SDKNotFoundError";
|
|
3
|
+
export { SDKBadWhereError } from "./runtime/lib/SDKBadWhereError";
|
|
3
4
|
export { traverseFieldArgs } from "./traverseFieldArgs";
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.traverseFieldArgs = exports.SDKBadWhereError = exports.SDKNotFoundError = exports.generate = void 0;
|
|
4
4
|
var generate_1 = require("./generation/generate");
|
|
5
5
|
Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_1.generate; } });
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "SDKNotFoundError", { enumerable: true, get: function () { return
|
|
8
|
-
|
|
6
|
+
var SDKNotFoundError_1 = require("./runtime/lib/SDKNotFoundError");
|
|
7
|
+
Object.defineProperty(exports, "SDKNotFoundError", { enumerable: true, get: function () { return SDKNotFoundError_1.SDKNotFoundError; } });
|
|
8
|
+
var SDKBadWhereError_1 = require("./runtime/lib/SDKBadWhereError");
|
|
9
|
+
Object.defineProperty(exports, "SDKBadWhereError", { enumerable: true, get: function () { return SDKBadWhereError_1.SDKBadWhereError; } });
|
|
9
10
|
var traverseFieldArgs_1 = require("./traverseFieldArgs");
|
|
10
11
|
Object.defineProperty(exports, "traverseFieldArgs", { enumerable: true, get: function () { return traverseFieldArgs_1.traverseFieldArgs; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { KSQL } from '../ksql';
|
|
2
1
|
import type { IRuntime, TMiddleware, TResolveParams, IArtifacts, TDbCall } from "./IRuntime";
|
|
2
|
+
import { KSQL } from "../ksql";
|
|
3
3
|
declare type TGetTableName = (table: string) => string;
|
|
4
4
|
export declare class RuntimeKSQL implements IRuntime {
|
|
5
5
|
#private;
|
|
@@ -13,17 +13,15 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var _RuntimeKSQL_ksql, _RuntimeKSQL_middlewareHandler, _RuntimeKSQL_dbCall, _RuntimeKSQL_formatQuery, _RuntimeKSQL_getBaseTableName, _RuntimeKSQL_getMaterializedViewName, _RuntimeKSQL_doNotUseMaterializedViews;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.RuntimeKSQL = void 0;
|
|
16
|
+
const SqlString = require("sqlstring");
|
|
16
17
|
const async_hooks_1 = require("async_hooks");
|
|
17
|
-
const graphql_relay_1 = require("graphql-relay");
|
|
18
18
|
const _ = require("lodash");
|
|
19
|
-
const
|
|
19
|
+
const graphql_relay_1 = require("graphql-relay");
|
|
20
|
+
const shared_1 = require("./lib/shared");
|
|
20
21
|
const ksql_1 = require("../ksql");
|
|
22
|
+
const SDKNotFoundError_1 = require("./lib/SDKNotFoundError");
|
|
23
|
+
const stringifyWhere_1 = require("./lib/stringifyWhere");
|
|
21
24
|
const cursor_1 = require("./lib/cursor");
|
|
22
|
-
const error_1 = require("./lib/error");
|
|
23
|
-
const getWhere_1 = require("./lib/getWhere");
|
|
24
|
-
const prepareWhere_1 = require("./lib/prepareWhere");
|
|
25
|
-
const resolve_1 = require("./lib/resolve");
|
|
26
|
-
const shared_1 = require("./lib/shared");
|
|
27
25
|
const escapeId = SqlString.escapeId.bind(SqlString);
|
|
28
26
|
class RuntimeKSQL {
|
|
29
27
|
constructor(clientOpts, otherOpts, artifacts) {
|
|
@@ -35,7 +33,7 @@ class RuntimeKSQL {
|
|
|
35
33
|
_RuntimeKSQL_getMaterializedViewName.set(this, void 0);
|
|
36
34
|
_RuntimeKSQL_doNotUseMaterializedViews.set(this, void 0);
|
|
37
35
|
__classPrivateFieldSet(this, _RuntimeKSQL_ksql, new ksql_1.KSQL(clientOpts ?? {}), "f");
|
|
38
|
-
__classPrivateFieldSet(this, _RuntimeKSQL_middlewareHandler, new
|
|
36
|
+
__classPrivateFieldSet(this, _RuntimeKSQL_middlewareHandler, new shared_1.MiddlewareHandler(), "f");
|
|
39
37
|
__classPrivateFieldSet(this, _RuntimeKSQL_dbCall, typeof otherOpts._dbCall === "function"
|
|
40
38
|
? (q) => otherOpts._dbCall(q).then(mapResult)
|
|
41
39
|
: (q) => __classPrivateFieldGet(this, _RuntimeKSQL_ksql, "f").streamQuery(q).then(mapResult), "f");
|
|
@@ -54,10 +52,10 @@ class RuntimeKSQL {
|
|
|
54
52
|
__classPrivateFieldGet(this, _RuntimeKSQL_middlewareHandler, "f").register(middleware);
|
|
55
53
|
}
|
|
56
54
|
$whereNeedsProcessing(where) {
|
|
57
|
-
return
|
|
55
|
+
return (0, shared_1.whereNeedsProcessing)(where);
|
|
58
56
|
}
|
|
59
57
|
async $prepareWhere(artifacts, table, data) {
|
|
60
|
-
return (0,
|
|
58
|
+
return (0, shared_1._prepareWhere)(artifacts, table, data, __classPrivateFieldGet(this, _RuntimeKSQL_dbCall, "f").bind(this), __classPrivateFieldGet(this, _RuntimeKSQL_formatQuery, "f").bind(this));
|
|
61
59
|
}
|
|
62
60
|
async $shutdown() {
|
|
63
61
|
// Nothing to do here, I think
|
|
@@ -118,7 +116,7 @@ async function getData(input, dbCall, formatQuery, getBaseTableName, getMaterial
|
|
|
118
116
|
action === "deleteMany";
|
|
119
117
|
const data = await _getData(input, grabMany, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews);
|
|
120
118
|
if (data == null && !grabMany) {
|
|
121
|
-
throw new
|
|
119
|
+
throw new SDKNotFoundError_1.SDKNotFoundError();
|
|
122
120
|
}
|
|
123
121
|
const scalarFields = input.artifacts[input.resource].scalarFields;
|
|
124
122
|
if (action === "findManyPaginated" && data?.results != null) {
|
|
@@ -158,7 +156,7 @@ async function _getData(input, grabMany, dbCall, formatQuery, getBaseTableName,
|
|
|
158
156
|
argsMapped = _.cloneDeep(argsMapped);
|
|
159
157
|
argsMapped.$where = argsMapped.$where[table];
|
|
160
158
|
}
|
|
161
|
-
const whereResult = (0,
|
|
159
|
+
const whereResult = (0, stringifyWhere_1.stringifyWhere)({
|
|
162
160
|
where: argsMapped.$where,
|
|
163
161
|
table: escapeId(getTableName(table)),
|
|
164
162
|
dialect: "mysql",
|
|
@@ -322,7 +320,7 @@ async function resolveDependentFields(table, parentData, mappedFields, relationF
|
|
|
322
320
|
],
|
|
323
321
|
};
|
|
324
322
|
const key = relationField.relations[1].foreignKey;
|
|
325
|
-
const s = formatQuery(`SELECT ?? FROM ?? WHERE ${(0,
|
|
323
|
+
const s = formatQuery(`SELECT ?? FROM ?? WHERE ${(0, stringifyWhere_1.stringifyWhere)({
|
|
326
324
|
where: whereJunction,
|
|
327
325
|
table: escapeId(getBaseTableName(relationField.junctionTable)),
|
|
328
326
|
dialect: "mysql",
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import * as mssql from
|
|
2
|
-
import { IArtifacts, ISupplementClientOpts } from
|
|
3
|
-
import { typeCastMSSQL } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly $dialect = "mssql";
|
|
7
|
-
private $pool;
|
|
8
|
-
private $poolConnect;
|
|
9
|
-
private $typeCast?;
|
|
1
|
+
import * as mssql from "mssql";
|
|
2
|
+
import type { IRuntime, TMiddleware, TResolveParams, IArtifacts, ISupplementClientOpts } from "./IRuntime";
|
|
3
|
+
import { typeCastMSSQL } from "./lib/typeCastMSSQL";
|
|
4
|
+
export declare class RuntimeMSSQL implements IRuntime {
|
|
5
|
+
#private;
|
|
10
6
|
constructor(clientOpts: mssql.config, otherOpts: {
|
|
11
7
|
supplementClientOpts?: ISupplementClientOpts;
|
|
12
8
|
typeCast?: Parameters<typeof typeCastMSSQL>[0];
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
}, artifacts: IArtifacts);
|
|
10
|
+
resolve(input: TResolveParams): Promise<any>;
|
|
11
|
+
$queryRaw(sql: string, values?: any[]): Promise<any>;
|
|
12
|
+
$use(middleware: TMiddleware): Promise<void>;
|
|
13
|
+
$whereNeedsProcessing(where: any): boolean;
|
|
14
|
+
$prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
|
|
15
15
|
$shutdown(): Promise<void>;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
protected beginTransaction(): Promise<{
|
|
20
|
-
commit: () => Promise<void>;
|
|
21
|
-
dbCall: (q: string) => Promise<any>;
|
|
22
|
-
}>;
|
|
16
|
+
private dbCall;
|
|
17
|
+
private formatQuery;
|
|
18
|
+
private beginTransaction;
|
|
23
19
|
}
|
|
@@ -1,63 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _RuntimeMSSQL_dialect, _RuntimeMSSQL_mssqlClient, _RuntimeMSSQL_middlewareHandler;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.RuntimeMSSQL = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const TSqlString = require("tsqlstring");
|
|
16
|
+
const shared_1 = require("./lib/shared");
|
|
17
|
+
const MSSQL_1 = require("./lib/MSSQL");
|
|
7
18
|
const typeCastMSSQL_1 = require("./lib/typeCastMSSQL");
|
|
8
|
-
|
|
9
|
-
class RuntimeMSSQL extends Runtime_1.default {
|
|
19
|
+
class RuntimeMSSQL {
|
|
10
20
|
constructor(clientOpts, otherOpts, artifacts) {
|
|
11
|
-
|
|
12
|
-
this
|
|
13
|
-
this
|
|
14
|
-
this
|
|
15
|
-
this.$typeCast = otherOpts?.supplementClientOpts
|
|
21
|
+
_RuntimeMSSQL_dialect.set(this, "mssql");
|
|
22
|
+
_RuntimeMSSQL_mssqlClient.set(this, void 0);
|
|
23
|
+
_RuntimeMSSQL_middlewareHandler.set(this, void 0);
|
|
24
|
+
__classPrivateFieldSet(this, _RuntimeMSSQL_mssqlClient, new MSSQL_1.MSSQL(clientOpts, otherOpts?.supplementClientOpts
|
|
16
25
|
? (0, typeCastMSSQL_1.typeCastMSSQL)(otherOpts?.typeCast)
|
|
17
|
-
: undefined;
|
|
26
|
+
: undefined), "f");
|
|
27
|
+
__classPrivateFieldSet(this, _RuntimeMSSQL_middlewareHandler, new shared_1.MiddlewareHandler(), "f");
|
|
28
|
+
}
|
|
29
|
+
async resolve(input) {
|
|
30
|
+
return (0, shared_1.resolve)(input, this.dbCall.bind(this), this.formatQuery.bind(this), this.beginTransaction.bind(this), __classPrivateFieldGet(this, _RuntimeMSSQL_dialect, "f"), __classPrivateFieldGet(this, _RuntimeMSSQL_middlewareHandler, "f"), input.context ?? {});
|
|
31
|
+
}
|
|
32
|
+
async $queryRaw(sql, values) {
|
|
33
|
+
return this.dbCall(this.formatQuery(sql, values ?? []));
|
|
34
|
+
}
|
|
35
|
+
async $use(middleware) {
|
|
36
|
+
__classPrivateFieldGet(this, _RuntimeMSSQL_middlewareHandler, "f").register(middleware);
|
|
37
|
+
}
|
|
38
|
+
$whereNeedsProcessing(where) {
|
|
39
|
+
return (0, shared_1.whereNeedsProcessing)(where);
|
|
40
|
+
}
|
|
41
|
+
async $prepareWhere(artifacts, table, data) {
|
|
42
|
+
return (0, shared_1._prepareWhere)(artifacts, table, data, this.dbCall.bind(this), this.formatQuery.bind(this));
|
|
18
43
|
}
|
|
19
44
|
async $shutdown() {
|
|
20
|
-
await this
|
|
45
|
+
await __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").closePool();
|
|
21
46
|
}
|
|
22
47
|
async dbCall(q) {
|
|
23
|
-
|
|
24
|
-
const request = this.$pool.request();
|
|
25
|
-
const result = await request.query(q);
|
|
26
|
-
return this.mapResult(result);
|
|
48
|
+
return __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").dbCall(q);
|
|
27
49
|
}
|
|
28
50
|
formatQuery(q, values) {
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const meta = result.recordset?.columns;
|
|
34
|
-
if (meta != null && typeof this.$typeCast === "function") {
|
|
35
|
-
return this.$typeCast(result, meta);
|
|
36
|
-
}
|
|
37
|
-
return result.recordset;
|
|
38
|
-
}
|
|
39
|
-
async beginTransaction() {
|
|
40
|
-
const transaction = new mssql.Transaction(this.$pool);
|
|
41
|
-
const mapResult = this.mapResult.bind(this);
|
|
42
|
-
let rolledBack = false;
|
|
43
|
-
transaction.on("rollback", (aborted) => {
|
|
44
|
-
// emited with aborted === true
|
|
45
|
-
rolledBack = true;
|
|
46
|
-
});
|
|
47
|
-
async function handleError(err) {
|
|
48
|
-
if (!rolledBack) {
|
|
49
|
-
await transaction.rollback();
|
|
50
|
-
}
|
|
51
|
-
throw err;
|
|
52
|
-
}
|
|
53
|
-
await transaction.begin();
|
|
54
|
-
return {
|
|
55
|
-
commit: () => transaction.commit().catch(handleError),
|
|
56
|
-
dbCall: (q) => new mssql.Request(transaction)
|
|
57
|
-
.query(q)
|
|
58
|
-
.then(mapResult)
|
|
59
|
-
.catch(handleError),
|
|
60
|
-
};
|
|
51
|
+
return __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").formatQuery(q, values);
|
|
52
|
+
}
|
|
53
|
+
beginTransaction() {
|
|
54
|
+
return __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").beginTransaction();
|
|
61
55
|
}
|
|
62
56
|
}
|
|
63
57
|
exports.RuntimeMSSQL = RuntimeMSSQL;
|
|
58
|
+
_RuntimeMSSQL_dialect = new WeakMap(), _RuntimeMSSQL_mssqlClient = new WeakMap(), _RuntimeMSSQL_middlewareHandler = new WeakMap();
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { IArtifacts, ISupplementClientOpts } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
readonly $dialect = "mysql";
|
|
5
|
-
protected $pool: any;
|
|
1
|
+
import type { IRuntime, TMiddleware, TResolveParams, IArtifacts, ISupplementClientOpts } from "./IRuntime";
|
|
2
|
+
export declare class RuntimeMySQL implements IRuntime {
|
|
3
|
+
#private;
|
|
6
4
|
constructor(clientOpts: {
|
|
7
5
|
[k: string]: any;
|
|
8
6
|
}, otherOpts: {
|
|
9
7
|
supplementClientOpts?: ISupplementClientOpts;
|
|
10
8
|
redisHost?: string;
|
|
11
|
-
}, artifacts
|
|
9
|
+
}, artifacts: IArtifacts);
|
|
10
|
+
resolve(input: TResolveParams): Promise<any>;
|
|
11
|
+
$queryRaw(sql: string, values?: any[]): Promise<any>;
|
|
12
|
+
$use(middleware: TMiddleware): Promise<void>;
|
|
13
|
+
$whereNeedsProcessing(where: any): boolean;
|
|
14
|
+
$prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
|
|
12
15
|
$shutdown(): Promise<void>;
|
|
13
|
-
dbCall
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
protected getConnection(): Promise<any>;
|
|
16
|
+
private dbCall;
|
|
17
|
+
private formatQuery;
|
|
18
|
+
private beginTransaction;
|
|
17
19
|
}
|
|
@@ -1,62 +1,100 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _RuntimeMySQL_dialect, _RuntimeMySQL_mysqlClient, _RuntimeMySQL_clientCache, _RuntimeMySQL_middlewareHandler;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.RuntimeMySQL = void 0;
|
|
4
16
|
const SqlString = require("sqlstring");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
P.promisifyAll(require("mysql/lib/Pool").prototype);
|
|
10
|
-
class RuntimeMySQL extends Runtime_1.default {
|
|
17
|
+
const Cache_1 = require("./Cache");
|
|
18
|
+
const MySQL_1 = require("./lib/MySQL");
|
|
19
|
+
const shared_1 = require("./lib/shared");
|
|
20
|
+
class RuntimeMySQL {
|
|
11
21
|
constructor(clientOpts, otherOpts, artifacts) {
|
|
12
|
-
|
|
13
|
-
this
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
_RuntimeMySQL_dialect.set(this, "mysql");
|
|
23
|
+
_RuntimeMySQL_mysqlClient.set(this, void 0);
|
|
24
|
+
_RuntimeMySQL_clientCache.set(this, void 0);
|
|
25
|
+
_RuntimeMySQL_middlewareHandler.set(this, void 0);
|
|
26
|
+
__classPrivateFieldSet(this, _RuntimeMySQL_middlewareHandler, new shared_1.MiddlewareHandler(), "f");
|
|
27
|
+
const debugCache = clientOpts?.debug?.includes("Cache");
|
|
28
|
+
if (otherOpts.redisHost)
|
|
29
|
+
__classPrivateFieldSet(this, _RuntimeMySQL_clientCache, new Cache_1.default(otherOpts.redisHost, debugCache), "f");
|
|
30
|
+
if (otherOpts.supplementClientOpts) {
|
|
31
|
+
clientOpts = {
|
|
32
|
+
supportBigNumbers: true,
|
|
33
|
+
typeCast: (field, next) => {
|
|
34
|
+
if (field.type == "TINY" && field.length == 1) {
|
|
35
|
+
return field.string() == "1";
|
|
36
|
+
}
|
|
37
|
+
// if (field.type === "DATE") {
|
|
38
|
+
// return field.string();
|
|
39
|
+
// }
|
|
40
|
+
// if (
|
|
41
|
+
// field.type === "TIMESTAMP" ||
|
|
42
|
+
// field.type === "DATE" ||
|
|
43
|
+
// field.type === "DATETIME"
|
|
44
|
+
// ) {
|
|
45
|
+
// return new Date(field.string()).toISOString();
|
|
46
|
+
// }
|
|
47
|
+
if (field.type === "VAR_STRING" || field.type === "STRING") {
|
|
48
|
+
return field.string();
|
|
49
|
+
}
|
|
50
|
+
return next();
|
|
51
|
+
},
|
|
52
|
+
...clientOpts,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
clientOpts = {
|
|
57
|
+
typeCast: (field, next) => {
|
|
58
|
+
if (field.type == "TINY" && field.length == 1) {
|
|
59
|
+
return field.string() == "1";
|
|
60
|
+
}
|
|
61
|
+
if (field.type === "VAR_STRING" || field.type === "STRING") {
|
|
62
|
+
return field.string();
|
|
63
|
+
}
|
|
64
|
+
return next();
|
|
65
|
+
},
|
|
66
|
+
...clientOpts,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
__classPrivateFieldSet(this, _RuntimeMySQL_mysqlClient, new MySQL_1.MySQL(clientOpts), "f");
|
|
70
|
+
}
|
|
71
|
+
async resolve(input) {
|
|
72
|
+
return (0, shared_1.resolve)(input, this.dbCall.bind(this), this.formatQuery.bind(this), this.beginTransaction.bind(this), __classPrivateFieldGet(this, _RuntimeMySQL_dialect, "f"), __classPrivateFieldGet(this, _RuntimeMySQL_middlewareHandler, "f"), input.context ?? {}, __classPrivateFieldGet(this, _RuntimeMySQL_clientCache, "f"));
|
|
73
|
+
}
|
|
74
|
+
async $queryRaw(sql, values) {
|
|
75
|
+
return this.dbCall(this.formatQuery(sql, values ?? []));
|
|
76
|
+
}
|
|
77
|
+
async $use(middleware) {
|
|
78
|
+
__classPrivateFieldGet(this, _RuntimeMySQL_middlewareHandler, "f").register(middleware);
|
|
79
|
+
}
|
|
80
|
+
$whereNeedsProcessing(where) {
|
|
81
|
+
return (0, shared_1.whereNeedsProcessing)(where);
|
|
82
|
+
}
|
|
83
|
+
async $prepareWhere(artifacts, table, data) {
|
|
84
|
+
return (0, shared_1._prepareWhere)(artifacts, table, data, this.dbCall.bind(this), this.formatQuery.bind(this));
|
|
32
85
|
}
|
|
33
86
|
async $shutdown() {
|
|
34
|
-
await this
|
|
87
|
+
await __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").endPool();
|
|
35
88
|
}
|
|
36
|
-
dbCall(q
|
|
37
|
-
return
|
|
89
|
+
dbCall(q) {
|
|
90
|
+
return __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").query(q);
|
|
38
91
|
}
|
|
39
92
|
formatQuery(q, values) {
|
|
40
93
|
return SqlString.format(q, values);
|
|
41
94
|
}
|
|
42
95
|
beginTransaction() {
|
|
43
|
-
return
|
|
44
|
-
async function handleError(err) {
|
|
45
|
-
await connection.rollbackAsync();
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
await connection.beginTransactionAsync();
|
|
49
|
-
return {
|
|
50
|
-
commit: () => connection.commitAsync().catch(handleError),
|
|
51
|
-
dbCall: (q) => connection.queryAsync(q).catch(handleError),
|
|
52
|
-
};
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
// http://bluebirdjs.com/docs/api/disposer.html
|
|
56
|
-
async getConnection() {
|
|
57
|
-
return this.$pool
|
|
58
|
-
.getConnectionAsync()
|
|
59
|
-
.disposer((connection) => connection.release());
|
|
96
|
+
return __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").beginTransaction();
|
|
60
97
|
}
|
|
61
98
|
}
|
|
62
99
|
exports.RuntimeMySQL = RuntimeMySQL;
|
|
100
|
+
_RuntimeMySQL_dialect = new WeakMap(), _RuntimeMySQL_mysqlClient = new WeakMap(), _RuntimeMySQL_clientCache = new WeakMap(), _RuntimeMySQL_middlewareHandler = new WeakMap();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as mssql from "mssql";
|
|
2
|
+
export declare class MSSQL {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(clientOpts: mssql.config, typeCast?: Function);
|
|
5
|
+
dbCall(q: string): Promise<any>;
|
|
6
|
+
private mapResult;
|
|
7
|
+
formatQuery(q: string, values: any[]): any;
|
|
8
|
+
beginTransaction(): Promise<{
|
|
9
|
+
commit: () => Promise<void>;
|
|
10
|
+
dbCall: (q: string) => Promise<any>;
|
|
11
|
+
}>;
|
|
12
|
+
closePool(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _MSSQL_pool, _MSSQL_poolConnect, _MSSQL_typeCast;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MSSQL = void 0;
|
|
16
|
+
const mssql = require("mssql");
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const TSqlString = require("tsqlstring");
|
|
19
|
+
class MSSQL {
|
|
20
|
+
constructor(clientOpts, typeCast) {
|
|
21
|
+
_MSSQL_pool.set(this, void 0);
|
|
22
|
+
_MSSQL_poolConnect.set(this, void 0);
|
|
23
|
+
_MSSQL_typeCast.set(this, void 0);
|
|
24
|
+
__classPrivateFieldSet(this, _MSSQL_typeCast, typeCast, "f");
|
|
25
|
+
__classPrivateFieldSet(this, _MSSQL_pool, new mssql.ConnectionPool(clientOpts), "f");
|
|
26
|
+
__classPrivateFieldSet(this, _MSSQL_poolConnect, __classPrivateFieldGet(this, _MSSQL_pool, "f").connect(), "f");
|
|
27
|
+
}
|
|
28
|
+
async dbCall(q) {
|
|
29
|
+
await __classPrivateFieldGet(this, _MSSQL_poolConnect, "f");
|
|
30
|
+
const request = __classPrivateFieldGet(this, _MSSQL_pool, "f").request();
|
|
31
|
+
const result = await request.query(q);
|
|
32
|
+
return this.mapResult(result);
|
|
33
|
+
}
|
|
34
|
+
mapResult(result) {
|
|
35
|
+
// TODO: see https://github.com/tediousjs/node-mssql/pull/1171
|
|
36
|
+
const meta = result.recordset?.columns;
|
|
37
|
+
if (meta != null && typeof __classPrivateFieldGet(this, _MSSQL_typeCast, "f") === "function") {
|
|
38
|
+
return __classPrivateFieldGet(this, _MSSQL_typeCast, "f").call(this, result, meta);
|
|
39
|
+
}
|
|
40
|
+
return result.recordset;
|
|
41
|
+
}
|
|
42
|
+
formatQuery(q, values) {
|
|
43
|
+
return TSqlString.format(q, values);
|
|
44
|
+
}
|
|
45
|
+
async beginTransaction() {
|
|
46
|
+
const transaction = new mssql.Transaction(__classPrivateFieldGet(this, _MSSQL_pool, "f"));
|
|
47
|
+
let rolledBack = false;
|
|
48
|
+
transaction.on("rollback", (aborted) => {
|
|
49
|
+
// emited with aborted === true
|
|
50
|
+
rolledBack = true;
|
|
51
|
+
});
|
|
52
|
+
async function handleError(err) {
|
|
53
|
+
if (!rolledBack) {
|
|
54
|
+
await transaction.rollback();
|
|
55
|
+
}
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
const mapResult = this.mapResult.bind(this);
|
|
59
|
+
await transaction.begin();
|
|
60
|
+
return {
|
|
61
|
+
commit: () => transaction.commit().catch(handleError),
|
|
62
|
+
dbCall: (q) => new mssql.Request(transaction)
|
|
63
|
+
.query(q)
|
|
64
|
+
.then(mapResult)
|
|
65
|
+
.catch(handleError),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async closePool() {
|
|
69
|
+
await __classPrivateFieldGet(this, _MSSQL_pool, "f").close();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.MSSQL = MSSQL;
|
|
73
|
+
_MSSQL_pool = new WeakMap(), _MSSQL_poolConnect = new WeakMap(), _MSSQL_typeCast = new WeakMap();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDKBadWhereError = void 0;
|
|
4
|
+
const CustomError_1 = require("../../lib/CustomError");
|
|
5
|
+
class SDKBadWhereError extends CustomError_1.CustomError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message || "Invalid $where");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.SDKBadWhereError = SDKBadWhereError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDKNotFoundError = void 0;
|
|
4
|
+
const CustomError_1 = require("../../lib/CustomError");
|
|
5
|
+
class SDKNotFoundError extends CustomError_1.CustomError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super("Not found");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.SDKNotFoundError = SDKNotFoundError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDateTimeStringMySQL(dateTimeString: string): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDateTimeStringMySQL = void 0;
|
|
4
|
+
// Assumes input uses zero offset
|
|
5
|
+
function getDateTimeStringMySQL(dateTimeString) {
|
|
6
|
+
return dateTimeString.replace("T", " ").slice(0, 19);
|
|
7
|
+
}
|
|
8
|
+
exports.getDateTimeStringMySQL = getDateTimeStringMySQL;
|
|
@@ -12,12 +12,12 @@ const namespace = new alias_namespace_1.default(true);
|
|
|
12
12
|
function getSqlAst(input) {
|
|
13
13
|
const { table, fieldName, fields, args, grabMany, sqlJoin, sqlBatch, junction, getWhere, artifacts, rowWithMatchingCursor, dialect, } = input;
|
|
14
14
|
const tableArtifacts = artifacts[table];
|
|
15
|
-
const
|
|
15
|
+
const primaryKey = tableArtifacts.primaryKey;
|
|
16
16
|
const format = dialect === "mysql"
|
|
17
17
|
? SqlString.format.bind(SqlString)
|
|
18
18
|
: TSqlString.format.bind(TSqlString);
|
|
19
19
|
const orderBy = input.orderBy ?? (0, getOrderBy_1.getOrderBy)(args, primaryKey)?.orderBy;
|
|
20
|
-
let
|
|
20
|
+
let where = input.where;
|
|
21
21
|
if (input.where == null) {
|
|
22
22
|
where = (table, args) => {
|
|
23
23
|
let argsMapped = args;
|
|
@@ -1,19 +1,2 @@
|
|
|
1
1
|
import type { IOrderBy, IDialect } from "../IRuntime";
|
|
2
2
|
export declare function getWhere(table: string, args: any, dialect: IDialect, orderBy?: IOrderBy | undefined, rowWithMatchingCursor?: any): string | null;
|
|
3
|
-
declare type IWhere = {
|
|
4
|
-
[k: string]: any;
|
|
5
|
-
};
|
|
6
|
-
declare type IArgs = {
|
|
7
|
-
[k: string]: any;
|
|
8
|
-
};
|
|
9
|
-
export declare function stringifyWhere(input: {
|
|
10
|
-
where: IWhere;
|
|
11
|
-
table: string;
|
|
12
|
-
dialect: IDialect;
|
|
13
|
-
args: IArgs;
|
|
14
|
-
orderBy?: IOrderBy | undefined;
|
|
15
|
-
rowWithMatchingCursor?: any;
|
|
16
|
-
}): string;
|
|
17
|
-
export declare function getEscapeId(dialect: IDialect): any;
|
|
18
|
-
export declare function getEscape(dialect: IDialect): any;
|
|
19
|
-
export {};
|