@technicity/data-service-generator 0.13.26 → 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/ksql.js CHANGED
@@ -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.KSQL = void 0;
27
- const http2 = __importStar(require("http2"));
4
+ const http2 = require("http2");
28
5
  class KSQL {
29
6
  constructor(options) {
30
7
  this.hostname = options.hostname;
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  const crypto_1 = require("crypto");
7
- const ioredis_1 = __importDefault(require("ioredis"));
8
- const loglevel_1 = __importDefault(require("loglevel"));
4
+ const ioredis_1 = require("ioredis");
5
+ const loglevel_1 = require("loglevel");
9
6
  const utility_1 = require("./lib/utility");
10
- const Stats_1 = __importDefault(require("./Stats"));
7
+ const Stats_1 = require("./Stats");
11
8
  class Cache {
12
9
  constructor(redisConfig, debug) {
13
10
  this.waiting = new Set();
@@ -5,35 +5,28 @@ export interface IRuntime {
5
5
  $whereNeedsProcessing(where: any): boolean;
6
6
  $prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<any>;
7
7
  $shutdown(): Promise<void>;
8
- $startTransaction(input?: {
9
- isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
10
- }): Promise<TBeginTransactionResult>;
11
8
  }
12
- export declare type TAction = "findUnique" | "findMany" | "findManyPaginated" | "create" | "update" | "updateMany" | "delete" | "deleteMany";
13
9
  export declare type TResolveParams = {
14
10
  resource: string;
15
- action: TAction;
11
+ action: "findUnique" | "findMany" | "findManyPaginated" | "create" | "update" | "updateMany" | "delete" | "deleteMany";
16
12
  args?: IArgs | undefined;
17
13
  data?: any;
18
14
  artifacts: IArtifacts;
19
15
  fields?: IField[] | undefined;
20
16
  context?: TContext | undefined;
21
17
  skipCache?: boolean;
22
- dbCall?: TDbCall;
23
18
  };
24
19
  export declare type TContext = {
25
20
  [k: string]: any;
26
21
  };
27
22
  export declare type TMiddleware = (params: TResolveParams, next: (params: TResolveParams) => Promise<any>) => Promise<any>;
28
- export declare type IDialect = "mysql" | "mssql" | "ksql" | "sqlite";
23
+ export declare type IDialect = "mysql" | "mssql" | "ksql";
29
24
  export declare type TDbCall = (q: string) => Promise<any>;
30
25
  export declare type TFormatQuery = (q: string, values: any[]) => string;
31
- export declare type TBeginTransaction = () => Promise<TBeginTransactionResult>;
32
- declare type TBeginTransactionResult = {
26
+ export declare type TBeginTransaction = () => Promise<{
33
27
  dbCall: (q: string) => Promise<any>;
34
28
  commit: () => Promise<void>;
35
- rollback: () => Promise<void>;
36
- };
29
+ }>;
37
30
  export declare type ISupplementClientOpts = boolean;
38
31
  export declare type IOrderBy = {
39
32
  column: string;
@@ -160,28 +153,6 @@ export declare type IArtifacts = {
160
153
  [k: string]: boolean;
161
154
  };
162
155
  dateTimeFieldsCount: number;
163
- fields: TField[];
164
- dump: {
165
- schema: string;
166
- } | null;
167
156
  };
168
157
  };
169
- export declare type TFieldType = "string" | "boolean" | "number" | "integer";
170
- export declare type TField = {
171
- kind: "scalar";
172
- type: TFieldType;
173
- name: string;
174
- nullable: boolean;
175
- hasDefaultValue: boolean;
176
- } | {
177
- kind: "enum";
178
- values: unknown[];
179
- name: string;
180
- nullable: boolean;
181
- } | {
182
- kind: "object";
183
- type: string;
184
- name: string;
185
- isList: boolean;
186
- };
187
158
  export {};
@@ -15,12 +15,5 @@ export declare class RuntimeKSQL implements IRuntime {
15
15
  $whereNeedsProcessing(where: any): boolean;
16
16
  $prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
17
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
18
  }
26
19
  export {};
@@ -1,27 +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
2
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
3
  if (kind === "m") throw new TypeError("Private method is not writable");
27
4
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -36,9 +13,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
13
  var _RuntimeKSQL_ksql, _RuntimeKSQL_middlewareHandler, _RuntimeKSQL_dbCall, _RuntimeKSQL_formatQuery, _RuntimeKSQL_getBaseTableName, _RuntimeKSQL_getMaterializedViewName, _RuntimeKSQL_doNotUseMaterializedViews;
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
15
  exports.RuntimeKSQL = void 0;
39
- const SqlString = __importStar(require("sqlstring"));
16
+ const SqlString = require("sqlstring");
40
17
  const async_hooks_1 = require("async_hooks");
41
- const _ = __importStar(require("lodash"));
18
+ const _ = require("lodash");
42
19
  const graphql_relay_1 = require("graphql-relay");
43
20
  const shared_1 = require("./lib/shared");
44
21
  const ksql_1 = require("../ksql");
@@ -83,14 +60,6 @@ class RuntimeKSQL {
83
60
  async $shutdown() {
84
61
  // Nothing to do here, I think
85
62
  }
86
- async $startTransaction(input) {
87
- throw new Error("Not implemented.");
88
- return {
89
- dbCall: async (q) => "",
90
- commit: async () => { },
91
- rollback: async () => { }
92
- };
93
- }
94
63
  }
95
64
  exports.RuntimeKSQL = RuntimeKSQL;
96
65
  _RuntimeKSQL_ksql = new WeakMap(), _RuntimeKSQL_middlewareHandler = new WeakMap(), _RuntimeKSQL_dbCall = new WeakMap(), _RuntimeKSQL_formatQuery = new WeakMap(), _RuntimeKSQL_getBaseTableName = new WeakMap(), _RuntimeKSQL_getMaterializedViewName = new WeakMap(), _RuntimeKSQL_doNotUseMaterializedViews = new WeakMap();
@@ -182,7 +151,8 @@ async function _getData(input, grabMany, dbCall, formatQuery, getBaseTableName,
182
151
  let where = undefined;
183
152
  if (args?.$where != null) {
184
153
  let argsMapped = args;
185
- if (typeof argsMapped.$where === "object" && argsMapped.$where[table] != null) {
154
+ if (typeof argsMapped.$where === "object" &&
155
+ argsMapped.$where[table] != null) {
186
156
  argsMapped = _.cloneDeep(argsMapped);
187
157
  argsMapped.$where = argsMapped.$where[table];
188
158
  }
@@ -190,7 +160,7 @@ async function _getData(input, grabMany, dbCall, formatQuery, getBaseTableName,
190
160
  where: argsMapped.$where,
191
161
  table: escapeId(getTableName(table)),
192
162
  dialect: "mysql",
193
- args: argsMapped
163
+ args: argsMapped,
194
164
  });
195
165
  if (whereResult) {
196
166
  where = whereResult;
@@ -318,10 +288,10 @@ async function resolveDependentFields(table, parentData, mappedFields, relationF
318
288
  mappedField.name,
319
289
  getBaseTableName(mappedField.referencedTable),
320
290
  mappedField.referencedKey,
321
- parentData?.[mappedField.foreignKey]
291
+ parentData?.[mappedField.foreignKey],
322
292
  ]);
323
293
  return dbCall(s).then((xs) => ({
324
- [x]: xs?.[0]?.[mappedField.name] ?? null
294
+ [x]: xs?.[0]?.[mappedField.name] ?? null,
325
295
  }));
326
296
  }))
327
297
  .concat(relationFields.map((x) => {
@@ -346,8 +316,8 @@ async function resolveDependentFields(table, parentData, mappedFields, relationF
346
316
  whereJunction = {
347
317
  $and: [
348
318
  { [relationField.relations[0].foreignKey]: junctionKeyValue },
349
- whereJunction
350
- ]
319
+ whereJunction,
320
+ ],
351
321
  };
352
322
  const key = relationField.relations[1].foreignKey;
353
323
  const s = formatQuery(`SELECT ?? FROM ?? WHERE ${(0, stringifyWhere_1.stringifyWhere)({
@@ -355,20 +325,20 @@ async function resolveDependentFields(table, parentData, mappedFields, relationF
355
325
  table: escapeId(getBaseTableName(relationField.junctionTable)),
356
326
  dialect: "mysql",
357
327
  // Since we're paginating, empty is fine
358
- args: {}
328
+ args: {},
359
329
  })};`, [key, getBaseTableName(relationField.junctionTable)]);
360
330
  return dbCall(s)
361
331
  .then((xs) => xs.map((x) => x?.[key]))
362
332
  .then((keys) => {
363
333
  const whereDest = {
364
- [relationField.relations[1].referencedKey]: { $in: keys }
334
+ [relationField.relations[1].referencedKey]: { $in: keys },
365
335
  };
366
336
  const argsMapped = x.args == null ? {} : _.cloneDeep(x.args);
367
337
  if (typeof argsMapped?.$where === "object" &&
368
338
  argsMapped.$where != null &&
369
339
  argsMapped.$where[relationField.table] != null) {
370
340
  argsMapped.$where = {
371
- $and: [whereDest, argsMapped.$where[relationField.table]]
341
+ $and: [whereDest, argsMapped.$where[relationField.table]],
372
342
  };
373
343
  }
374
344
  else if (argsMapped.$where != null) {
@@ -382,7 +352,7 @@ async function resolveDependentFields(table, parentData, mappedFields, relationF
382
352
  args: argsMapped,
383
353
  fields: x.fields,
384
354
  artifacts,
385
- action: relationField.grabMany ? "findMany" : "findUnique"
355
+ action: relationField.grabMany ? "findMany" : "findUnique",
386
356
  }, relationField.grabMany, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews).then((xx) => ({ [x.as ?? x.name]: xx }));
387
357
  });
388
358
  }
@@ -405,7 +375,7 @@ async function resolveDependentFields(table, parentData, mappedFields, relationF
405
375
  args: argsMapped,
406
376
  fields: x.fields,
407
377
  artifacts,
408
- action: relationField.grabMany ? "findMany" : "findUnique"
378
+ action: relationField.grabMany ? "findMany" : "findUnique",
409
379
  }, relationField.grabMany, dbCall, formatQuery, getBaseTableName, getMaterializedViewName, doNotUseMaterializedViews).then((xx) => ({ [x.as ?? x.name]: xx }));
410
380
  }
411
381
  throw new Error(`Invalid relationField.type`);
@@ -426,7 +396,7 @@ function paginate(data, args, primaryKey, action) {
426
396
  data = data.slice(offset, offset + limit);
427
397
  return {
428
398
  results: data,
429
- paginationInfo: { totalCount }
399
+ paginationInfo: { totalCount },
430
400
  };
431
401
  }
432
402
  if (typeof args?.$paginate?.first === "number" ||
@@ -457,8 +427,8 @@ function paginate(data, args, primaryKey, action) {
457
427
  ...connection.pageInfo,
458
428
  startCursor,
459
429
  endCursor,
460
- totalCount
461
- }
430
+ totalCount,
431
+ },
462
432
  };
463
433
  }
464
434
  }
@@ -13,13 +13,7 @@ export declare class RuntimeMSSQL implements IRuntime {
13
13
  $whereNeedsProcessing(where: any): boolean;
14
14
  $prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
15
15
  $shutdown(): Promise<void>;
16
- $startTransaction(input?: {
17
- isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
18
- }): Promise<{
19
- commit: () => Promise<void>;
20
- rollback: () => Promise<void>;
21
- dbCall: (q: string) => Promise<any>;
22
- }>;
23
16
  private dbCall;
24
17
  private formatQuery;
18
+ private beginTransaction;
25
19
  }
@@ -27,7 +27,7 @@ class RuntimeMSSQL {
27
27
  __classPrivateFieldSet(this, _RuntimeMSSQL_middlewareHandler, new shared_1.MiddlewareHandler(), "f");
28
28
  }
29
29
  async resolve(input) {
30
- return (0, shared_1.resolve)(input, input.dbCall ?? this.dbCall.bind(this), this.formatQuery.bind(this), this.$startTransaction.bind(this), __classPrivateFieldGet(this, _RuntimeMSSQL_dialect, "f"), __classPrivateFieldGet(this, _RuntimeMSSQL_middlewareHandler, "f"), input.context ?? {});
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
31
  }
32
32
  async $queryRaw(sql, values) {
33
33
  return this.dbCall(this.formatQuery(sql, values ?? []));
@@ -44,15 +44,15 @@ class RuntimeMSSQL {
44
44
  async $shutdown() {
45
45
  await __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").closePool();
46
46
  }
47
- async $startTransaction(input) {
48
- return __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").beginTransaction(input?.isolationLevel);
49
- }
50
47
  async dbCall(q) {
51
48
  return __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").dbCall(q);
52
49
  }
53
50
  formatQuery(q, values) {
54
51
  return __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").formatQuery(q, values);
55
52
  }
53
+ beginTransaction() {
54
+ return __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").beginTransaction();
55
+ }
56
56
  }
57
57
  exports.RuntimeMSSQL = RuntimeMSSQL;
58
58
  _RuntimeMSSQL_dialect = new WeakMap(), _RuntimeMSSQL_mssqlClient = new WeakMap(), _RuntimeMSSQL_middlewareHandler = new WeakMap();
@@ -14,9 +14,7 @@ export declare class RuntimeMySQL implements IRuntime {
14
14
  $whereNeedsProcessing(where: any): boolean;
15
15
  $prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
16
16
  $shutdown(): Promise<void>;
17
- $startTransaction(input?: {
18
- isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
19
- }): Promise<any>;
20
17
  private dbCall;
21
18
  private formatQuery;
19
+ private beginTransaction;
22
20
  }
@@ -1,27 +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
2
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
3
  if (kind === "m") throw new TypeError("Private method is not writable");
27
4
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -33,17 +10,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
33
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");
34
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
12
  };
36
- var __importDefault = (this && this.__importDefault) || function (mod) {
37
- return (mod && mod.__esModule) ? mod : { "default": mod };
38
- };
39
13
  var _RuntimeMySQL_dialect, _RuntimeMySQL_mysqlClient, _RuntimeMySQL_clientCache, _RuntimeMySQL_middlewareHandler;
40
14
  Object.defineProperty(exports, "__esModule", { value: true });
41
15
  exports.RuntimeMySQL = void 0;
42
- const SqlString = __importStar(require("sqlstring"));
43
- const Cache_1 = __importDefault(require("./Cache"));
16
+ const SqlString = require("sqlstring");
17
+ const Cache_1 = require("./Cache");
44
18
  const MySQL_1 = require("./lib/MySQL");
45
19
  const shared_1 = require("./lib/shared");
46
- const loglevel_1 = __importDefault(require("loglevel"));
20
+ const loglevel_1 = require("loglevel");
47
21
  loglevel_1.default.setDefaultLevel("INFO");
48
22
  class RuntimeMySQL {
49
23
  constructor(clientOpts, otherOpts, artifacts) {
@@ -96,7 +70,7 @@ class RuntimeMySQL {
96
70
  __classPrivateFieldSet(this, _RuntimeMySQL_mysqlClient, new MySQL_1.MySQL(clientOpts), "f");
97
71
  }
98
72
  async resolve(input) {
99
- return (0, shared_1.resolve)(input, input.dbCall ?? this.dbCall.bind(this), this.formatQuery.bind(this), this.$startTransaction.bind(this), __classPrivateFieldGet(this, _RuntimeMySQL_dialect, "f"), __classPrivateFieldGet(this, _RuntimeMySQL_middlewareHandler, "f"), input.context ?? {}, __classPrivateFieldGet(this, _RuntimeMySQL_clientCache, "f"));
73
+ 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"));
100
74
  }
101
75
  async $queryRaw(sql, values) {
102
76
  return this.dbCall(this.formatQuery(sql, values ?? []));
@@ -116,15 +90,15 @@ class RuntimeMySQL {
116
90
  }
117
91
  await __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").endPool();
118
92
  }
119
- async $startTransaction(input) {
120
- return __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").beginTransaction(input?.isolationLevel);
121
- }
122
93
  dbCall(q) {
123
94
  return __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").query(q);
124
95
  }
125
96
  formatQuery(q, values) {
126
97
  return SqlString.format(q, values);
127
98
  }
99
+ beginTransaction() {
100
+ return __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").beginTransaction();
101
+ }
128
102
  }
129
103
  exports.RuntimeMySQL = RuntimeMySQL;
130
104
  _RuntimeMySQL_dialect = new WeakMap(), _RuntimeMySQL_mysqlClient = new WeakMap(), _RuntimeMySQL_clientCache = new WeakMap(), _RuntimeMySQL_middlewareHandler = new WeakMap();
@@ -5,9 +5,8 @@ export declare class MSSQL {
5
5
  dbCall(q: string): Promise<any>;
6
6
  private mapResult;
7
7
  formatQuery(q: string, values: any[]): any;
8
- beginTransaction(isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE"): Promise<{
8
+ beginTransaction(): Promise<{
9
9
  commit: () => Promise<void>;
10
- rollback: () => Promise<void>;
11
10
  dbCall: (q: string) => Promise<any>;
12
11
  }>;
13
12
  closePool(): Promise<void>;
@@ -1,27 +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
2
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
3
  if (kind === "m") throw new TypeError("Private method is not writable");
27
4
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -36,9 +13,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
13
  var _MSSQL_pool, _MSSQL_poolConnect, _MSSQL_typeCast;
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
15
  exports.MSSQL = void 0;
39
- const mssql = __importStar(require("mssql"));
16
+ const mssql = require("mssql");
40
17
  // @ts-ignore
41
- const TSqlString = __importStar(require("tsqlstring"));
18
+ const TSqlString = require("tsqlstring");
42
19
  class MSSQL {
43
20
  constructor(clientOpts, typeCast) {
44
21
  _MSSQL_pool.set(this, void 0);
@@ -65,7 +42,7 @@ class MSSQL {
65
42
  formatQuery(q, values) {
66
43
  return TSqlString.format(q, values);
67
44
  }
68
- async beginTransaction(isolationLevel) {
45
+ async beginTransaction() {
69
46
  const transaction = new mssql.Transaction(__classPrivateFieldGet(this, _MSSQL_pool, "f"));
70
47
  let rolledBack = false;
71
48
  transaction.on("rollback", (aborted) => {
@@ -79,18 +56,13 @@ class MSSQL {
79
56
  throw err;
80
57
  }
81
58
  const mapResult = this.mapResult.bind(this);
82
- let isolationLevelNumber;
83
- if (isolationLevel) {
84
- isolationLevelNumber = mssql.ISOLATION_LEVEL[isolationLevel.replace(" ", "_")];
85
- if (isolationLevelNumber == null) {
86
- throw new Error(`Invalid isolationLevel: ${isolationLevel}`);
87
- }
88
- }
89
- await transaction.begin(isolationLevelNumber);
59
+ await transaction.begin();
90
60
  return {
91
61
  commit: () => transaction.commit().catch(handleError),
92
- rollback: () => transaction.rollback(),
93
- dbCall: (q) => new mssql.Request(transaction).query(q).then(mapResult).catch(handleError)
62
+ dbCall: (q) => new mssql.Request(transaction)
63
+ .query(q)
64
+ .then(mapResult)
65
+ .catch(handleError),
94
66
  };
95
67
  }
96
68
  async closePool() {
@@ -2,7 +2,7 @@ export declare class MySQL {
2
2
  pool: any;
3
3
  constructor(opts: any);
4
4
  query(...args: any[]): any;
5
- beginTransaction(isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE"): Promise<any>;
5
+ beginTransaction(): Promise<any>;
6
6
  getConnection(): Promise<any>;
7
7
  endPool(): Promise<void>;
8
8
  }
@@ -13,29 +13,16 @@ class MySQL {
13
13
  query(...args) {
14
14
  return P.using(this.getConnection(), (connection) => connection.queryAsync(...args));
15
15
  }
16
- async beginTransaction(isolationLevel) {
16
+ async beginTransaction() {
17
17
  return P.using(this.getConnection(), async (connection) => {
18
18
  async function handleError(err) {
19
19
  await connection.rollbackAsync();
20
20
  throw err;
21
21
  }
22
- // https://dev.mysql.com/doc/refman/8.0/en/set-transaction.html#set-transaction-isolation-level
23
- // Without any SESSION or GLOBAL keyword:
24
- // The statement applies only to the next single transaction performed within the session.
25
- if (isolationLevel != null) {
26
- if (isolationLevel !== "READ UNCOMMITTED" &&
27
- isolationLevel !== "READ COMMITTED" &&
28
- isolationLevel !== "REPEATABLE READ" &&
29
- isolationLevel !== "SERIALIZABLE") {
30
- throw new Error(`Invalid isolationLevel: ${isolationLevel}`);
31
- }
32
- await connection.queryAsync(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel};`);
33
- }
34
22
  await connection.beginTransactionAsync();
35
23
  return {
36
24
  commit: () => connection.commitAsync().catch(handleError),
37
- rollback: () => connection.rollbackAsync(),
38
- dbCall: (q) => connection.queryAsync(q).catch(handleError)
25
+ dbCall: (q) => connection.queryAsync(q).catch(handleError),
39
26
  };
40
27
  });
41
28
  }