@technicity/data-service-generator 0.11.5 → 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 CHANGED
@@ -22,7 +22,7 @@ async function main() {
22
22
  dialect: "mysql",
23
23
  database: "MY_DATABASE",
24
24
  user: "MY_USER",
25
- password: "MY_PASSWORD",
25
+ password: "MY_PASSWORD"
26
26
  });
27
27
  }
28
28
  ```
@@ -36,7 +36,7 @@ async function main() {
36
36
  | Option | Required | Default | Description |
37
37
  | ------------- | -------- | ------------ | --------------------------------------------------------------- |
38
38
  | outdir | Yes | | The output directory for the SDK. |
39
- | dialect | Yes | | "mysql" \| "mssql" |
39
+ | dialect | Yes | | "mysql" \| |
40
40
  | database | Yes | | Database name |
41
41
  | user | Yes | | Database user |
42
42
  | password | No | | Database password |
@@ -47,7 +47,9 @@ async function main() {
47
47
 
48
48
  ### Running Tests
49
49
 
50
+ - `pyenv shell 3.11` (workaround for `node-sqlite`/`node-gyp` error)
51
+
50
52
  - spin up test environment: `docker-compose up -d`
51
53
  - run tests: `docker-compose exec test yarn test`
52
54
 
53
- - `yarn test:prepare`
55
+ - `yarn test:prepare`
@@ -1,7 +1,7 @@
1
1
  import type { IDialect, ISupplementClientOpts } from "../runtime/IRuntime";
2
- declare type ISpecialCaseUuidColumn = boolean;
3
- declare type IIncludeMappedFields = boolean;
4
- declare type IGenerateInput = {
2
+ type ISpecialCaseUuidColumn = boolean;
3
+ type IIncludeMappedFields = boolean;
4
+ type IGenerateInput = {
5
5
  dialect: IDialect;
6
6
  database: string;
7
7
  user: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generate = void 0;
3
+ exports.generate = generate;
4
4
  const path = require("path");
5
5
  const fs = require("fs");
6
6
  const os = require("os");
@@ -10,9 +10,6 @@ const changeCase = require("change-case");
10
10
  const fse = require("fs-extra");
11
11
  const _ = require("lodash/fp");
12
12
  const uuid_1 = require("uuid");
13
- const mssql = require("mssql");
14
- // @ts-ignore
15
- const TSqlString = require("tsqlstring");
16
13
  const json_schema_to_typescript_1 = require("json-schema-to-typescript");
17
14
  const getDuplicates_1 = require("../lib/getDuplicates");
18
15
  const isNotNullOrUndefined_1 = require("../lib/isNotNullOrUndefined");
@@ -136,7 +133,6 @@ async function generate(input) {
136
133
  fse.copySync(tmpBuildOutputPath, sdkOutputPath);
137
134
  fse.removeSync(tmpDirPath);
138
135
  }
139
- exports.generate = generate;
140
136
  function init(input) {
141
137
  const { database, user, password, host, port, server } = input;
142
138
  if (dialect === "mysql") {
@@ -149,24 +145,6 @@ function init(input) {
149
145
  });
150
146
  query = mysql.query.bind(mysql);
151
147
  }
152
- if (dialect === "mssql" || dialect === "ksql") {
153
- const pool = new mssql.ConnectionPool({
154
- server: server ?? "localhost",
155
- user,
156
- password,
157
- port,
158
- database
159
- });
160
- const poolConnect = pool.connect();
161
- async function runMSSQLQuery(...input) {
162
- const q = TSqlString.format(...input);
163
- await poolConnect;
164
- const request = pool.request();
165
- const result = await request.query(q);
166
- return result.recordset;
167
- }
168
- query = runMSSQLQuery;
169
- }
170
148
  }
171
149
  // It's a bit awkward to put __whereNeedsProcessing, __prepareWhere on the class,
172
150
  // but it allows us to share the same database pool, clientOpts, etc.
@@ -1254,12 +1232,11 @@ async function getJunctionTables() {
1254
1232
  }
1255
1233
  // `from` relations
1256
1234
  // https://stackoverflow.com/a/54732547
1257
- // Memoize because it seems to be expensive for MSSQL. Note: this function
1235
+ // Note: this function
1258
1236
  // isn't pure (because of `dialect`), but that's fine because its value
1259
1237
  // isn't expected to change.
1260
1238
  const getRelationsManyToOne = _.memoize(async function getRelationsManyToOne(table) {
1261
- const sql = dialect === "mysql"
1262
- ? `
1239
+ const sql = `
1263
1240
  SELECT
1264
1241
  TABLE_SCHEMA as db,
1265
1242
  TABLE_NAME as t1,
@@ -1273,26 +1250,7 @@ const getRelationsManyToOne = _.memoize(async function getRelationsManyToOne(tab
1273
1250
  TABLE_SCHEMA = SCHEMA()
1274
1251
  AND REFERENCED_TABLE_NAME IS NOT NULL
1275
1252
  AND (TABLE_NAME = ?);
1276
- `
1277
- : // https://stackoverflow.com/a/3907999
1278
- `
1279
- SELECT
1280
- KCU1.TABLE_NAME AS t1
1281
- ,KCU1.COLUMN_NAME AS t1Field
1282
- ,KCU2.TABLE_NAME AS t2
1283
- ,KCU2.COLUMN_NAME AS t2Field
1284
- FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC
1285
- INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU1
1286
- ON KCU1.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG
1287
- AND KCU1.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA
1288
- AND KCU1.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
1289
- INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU2
1290
- ON KCU2.CONSTRAINT_CATALOG = RC.UNIQUE_CONSTRAINT_CATALOG
1291
- AND KCU2.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA
1292
- AND KCU2.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME
1293
- AND KCU2.ORDINAL_POSITION = KCU1.ORDINAL_POSITION
1294
- WHERE
1295
- KCU1.TABLE_NAME = ?`;
1253
+ `;
1296
1254
  const tableMeta = await getTableMeta(table);
1297
1255
  const rs = await query(sql, [table]);
1298
1256
  const xs = await Promise.all(_.uniqWith(_.isEqual, rs.map(async (v) => {
@@ -1308,8 +1266,7 @@ const getRelationsManyToOne = _.memoize(async function getRelationsManyToOne(tab
1308
1266
  });
1309
1267
  // `to` relations
1310
1268
  const getRelationsOneToMany = _.memoize(async function getRelationsOneToMany(table) {
1311
- const sql = dialect === "mysql"
1312
- ? `
1269
+ const sql = `
1313
1270
  SELECT
1314
1271
  TABLE_SCHEMA as db,
1315
1272
  TABLE_NAME as t1,
@@ -1323,25 +1280,7 @@ const getRelationsOneToMany = _.memoize(async function getRelationsOneToMany(tab
1323
1280
  TABLE_SCHEMA = SCHEMA()
1324
1281
  AND REFERENCED_TABLE_NAME IS NOT NULL
1325
1282
  AND (REFERENCED_TABLE_NAME = ?);
1326
- `
1327
- : `
1328
- SELECT
1329
- KCU1.TABLE_NAME AS t1
1330
- ,KCU1.COLUMN_NAME AS t1Field
1331
- ,KCU2.TABLE_NAME AS t2
1332
- ,KCU2.COLUMN_NAME AS t2Field
1333
- FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC
1334
- INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU1
1335
- ON KCU1.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG
1336
- AND KCU1.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA
1337
- AND KCU1.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
1338
- INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU2
1339
- ON KCU2.CONSTRAINT_CATALOG = RC.UNIQUE_CONSTRAINT_CATALOG
1340
- AND KCU2.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA
1341
- AND KCU2.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME
1342
- AND KCU2.ORDINAL_POSITION = KCU1.ORDINAL_POSITION
1343
- WHERE
1344
- KCU2.TABLE_NAME = ?`;
1283
+ `;
1345
1284
  const rs = await query(sql, [table]);
1346
1285
  const xs = await Promise.all(_.uniqWith(_.isEqual, rs.map(async (v) => {
1347
1286
  return {
@@ -1396,47 +1335,6 @@ const getTableMeta = _.memoize(async function getTableMeta(table) {
1396
1335
  if (dialect === "mysql") {
1397
1336
  return query("DESCRIBE ??", [table]).then((xs) => _.sortBy((x) => x.Field, xs));
1398
1337
  }
1399
- if (dialect === "mssql" || dialect === "ksql") {
1400
- const primaryColumn = await query(`SELECT columns.name as COLUMN_NAME
1401
- FROM sys.tables tables
1402
- JOIN sys.columns columns
1403
- ON tables.object_id=columns.object_id
1404
- WHERE columns.is_identity=1 AND tables.name = ?`, [table]).then((xs) => xs[0]?.["COLUMN_NAME"]);
1405
- const uniqueColumns =
1406
- // https://stackoverflow.com/a/59095477
1407
- await query(`SELECT c.name AS COLUMN_NAME
1408
- FROM sys.indexes i
1409
- INNER JOIN sys.index_columns ic
1410
- ON i.index_id = ic.index_id AND i.object_id = ic.object_id
1411
- INNER JOIN sys.tables AS t
1412
- ON t.object_id = i.object_id
1413
- INNER JOIN sys.columns c
1414
- ON t.object_id = c.object_id AND ic.column_id = c.column_id
1415
- INNER JOIN sys.objects AS syso
1416
- ON syso.object_id = t.object_id AND syso.is_ms_shipped = 0
1417
- INNER JOIN sys.schemas AS sh
1418
- ON sh.schema_id = t.schema_id
1419
- INNER JOIN information_schema.schemata sch
1420
- ON sch.schema_name = sh.name
1421
- WHERE i.is_unique_constraint = 1
1422
- AND t.name = ?
1423
- -- AND sh.name = 'dbo'
1424
- ORDER BY sh.name, i.name, ic.key_ordinal;`, [table]).then((xs) => xs.map((x) => x["COLUMN_NAME"]));
1425
- return query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? ORDER BY ORDINAL_POSITION", [table]).then((xs) => _.sortBy((x) => x.Field, xs.map((x) => {
1426
- const Field = x["COLUMN_NAME"];
1427
- return {
1428
- Field,
1429
- Type: x["DATA_TYPE"],
1430
- Key: Field === primaryColumn
1431
- ? "PRI"
1432
- : uniqueColumns.find((u) => u === Field)
1433
- ? "UNI"
1434
- : "",
1435
- Null: x["IS_NULLABLE"],
1436
- Default: x["COLUMN_DEFAULT"]
1437
- };
1438
- })));
1439
- }
1440
1338
  throw new Error("Unsupported dialect: " + dialect);
1441
1339
  });
1442
1340
  function getJSONSchemaObjProperties(tableMeta) {
@@ -1580,23 +1478,9 @@ function getPropertyFormat(sqlType) {
1580
1478
  }
1581
1479
  return undefined;
1582
1480
  }
1583
- const mssqlTableExcludes = new Set([
1584
- "captured_columns",
1585
- "change_tables",
1586
- "ddl_history",
1587
- "index_columns",
1588
- "lsn_time_mapping",
1589
- "systranschemas"
1590
- ]);
1591
1481
  async function getTableNames() {
1592
1482
  if (dialect === "mysql") {
1593
1483
  return query("SHOW TABLES").then((xs) => xs.flatMap((x) => Object.values(x)).sort());
1594
1484
  }
1595
- if (dialect === "mssql" || dialect === "ksql") {
1596
- return query("SELECT * FROM INFORMATION_SCHEMA.TABLES").then((xs) => xs
1597
- .map((x) => x["TABLE_NAME"])
1598
- .filter((x) => !x.startsWith("dbo_") && !mssqlTableExcludes.has(x))
1599
- .sort());
1600
- }
1601
1485
  throw new Error("Unsupported dialect: " + dialect);
1602
1486
  }
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDuplicates = void 0;
3
+ exports.getDuplicates = getDuplicates;
4
4
  function getDuplicates(arr) {
5
5
  return arr.reduce((agg, col) => {
6
6
  agg.filter[col] = agg.filter[col] ? agg.dup.push(col) : 2;
7
7
  return agg;
8
8
  }, { filter: {}, dup: [] }).dup;
9
9
  }
10
- exports.getDuplicates = getDuplicates;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNotNullOrUndefined = void 0;
3
+ exports.isNotNullOrUndefined = isNotNullOrUndefined;
4
4
  // https://github.com/Microsoft/TypeScript/issues/16069
5
5
  function isNotNullOrUndefined(input) {
6
6
  return input != null;
7
7
  }
8
- exports.isNotNullOrUndefined = isNotNullOrUndefined;
@@ -1,7 +1,7 @@
1
1
  import Redis, { Cluster } from "ioredis";
2
2
  import { TResolveParams } from "./IRuntime";
3
3
  import Stats from "./Stats";
4
- export declare type RedisConfig = {
4
+ export type RedisConfig = {
5
5
  host: string;
6
6
  port: number;
7
7
  tls?: boolean;
@@ -9,7 +9,7 @@ export interface IRuntime {
9
9
  isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
10
10
  }): Promise<TBeginTransactionResult>;
11
11
  }
12
- export declare type TResolveParams = {
12
+ export type TResolveParams = {
13
13
  resource: string;
14
14
  action: "findUnique" | "findMany" | "findManyPaginated" | "create" | "update" | "updateMany" | "delete" | "deleteMany";
15
15
  args?: IArgs | undefined;
@@ -20,55 +20,55 @@ export declare type TResolveParams = {
20
20
  skipCache?: boolean;
21
21
  dbCall?: TDbCall;
22
22
  };
23
- export declare type TContext = {
23
+ export type TContext = {
24
24
  [k: string]: any;
25
25
  };
26
- export declare type TMiddleware = (params: TResolveParams, next: (params: TResolveParams) => Promise<any>) => Promise<any>;
27
- export declare type IDialect = "mysql" | "mssql" | "ksql";
28
- export declare type TDbCall = (q: string) => Promise<any>;
29
- export declare type TFormatQuery = (q: string, values: any[]) => string;
30
- export declare type TBeginTransaction = () => Promise<TBeginTransactionResult>;
31
- declare type TBeginTransactionResult = {
26
+ export type TMiddleware = (params: TResolveParams, next: (params: TResolveParams) => Promise<any>) => Promise<any>;
27
+ export type IDialect = "mysql";
28
+ export type TDbCall = (q: string) => Promise<any>;
29
+ export type TFormatQuery = (q: string, values: any[]) => string;
30
+ export type TBeginTransaction = () => Promise<TBeginTransactionResult>;
31
+ type TBeginTransactionResult = {
32
32
  dbCall: (q: string) => Promise<any>;
33
33
  commit: () => Promise<void>;
34
34
  rollback: () => Promise<void>;
35
35
  };
36
- export declare type ISupplementClientOpts = boolean;
37
- export declare type IOrderBy = {
36
+ export type ISupplementClientOpts = boolean;
37
+ export type IOrderBy = {
38
38
  column: string;
39
39
  direction: any;
40
40
  }[];
41
- export declare type IArgs = {
41
+ export type IArgs = {
42
42
  [k: string]: any;
43
43
  };
44
- export declare type IField = string | {
44
+ export type IField = string | {
45
45
  name: string;
46
46
  as?: string;
47
47
  fields: IField[];
48
48
  args?: IArgs;
49
49
  transform?: (record: any) => any;
50
50
  };
51
- declare type IWhere = (table: string, args: IArgs) => string | undefined;
52
- declare type IASTChildColumn = {
51
+ type IWhere = (table: string, args: IArgs) => string | undefined;
52
+ type IASTChildColumn = {
53
53
  type: "column";
54
54
  name: string;
55
55
  fieldName: string;
56
56
  as: string;
57
57
  fromOtherTable?: string | undefined;
58
58
  };
59
- declare type IASTChildComposite = {
59
+ type IASTChildComposite = {
60
60
  type: "composite";
61
61
  name: string[];
62
62
  fieldName: string;
63
63
  as: string;
64
64
  fromOtherTable?: string | undefined;
65
65
  };
66
- declare type ISqlJoin = (t1: string, t2: string, args: IArgs) => string;
67
- declare type ISqlBatch = {
66
+ type ISqlJoin = (t1: string, t2: string, args: IArgs) => string;
67
+ type ISqlBatch = {
68
68
  thisKey: IASTChildColumn;
69
69
  parentKey: IASTChildColumn;
70
70
  };
71
- declare type IJunction = {
71
+ type IJunction = {
72
72
  sqlTable: string;
73
73
  as: string;
74
74
  uniqueKey: string | string[];
@@ -84,7 +84,7 @@ declare type IJunction = {
84
84
  where?: IWhere;
85
85
  sqlJoins: ISqlJoin[];
86
86
  };
87
- export declare type IGetSQLASTInput = {
87
+ export type IGetSQLASTInput = {
88
88
  table: string;
89
89
  fieldName: string;
90
90
  fields: IField[];
@@ -101,17 +101,17 @@ export declare type IGetSQLASTInput = {
101
101
  dialect: IDialect;
102
102
  firstChild?: IASTChildColumn | IASTChildComposite;
103
103
  };
104
- export declare type IRelation = {
104
+ export type IRelation = {
105
105
  table: string;
106
106
  foreignKey: string;
107
107
  referencedTable: string;
108
108
  referencedKey: string;
109
109
  nullable: boolean;
110
110
  };
111
- declare type IOneToManyOrManyToOne = "one-to-many__many-to-one";
112
- declare type IManyToMany = "many-to-many";
113
- declare type IRelationKind = "one-to-many" | "many-to-one";
114
- export declare type IRelationOneToManyOrManyToOne = {
111
+ type IOneToManyOrManyToOne = "one-to-many__many-to-one";
112
+ type IManyToMany = "many-to-many";
113
+ type IRelationKind = "one-to-many" | "many-to-one";
114
+ export type IRelationOneToManyOrManyToOne = {
115
115
  type: IOneToManyOrManyToOne;
116
116
  kind: IRelationKind;
117
117
  grabMany: boolean;
@@ -120,7 +120,7 @@ export declare type IRelationOneToManyOrManyToOne = {
120
120
  relation: IRelation;
121
121
  nullable: boolean;
122
122
  };
123
- export declare type IRelationManyToMany = {
123
+ export type IRelationManyToMany = {
124
124
  type: IManyToMany;
125
125
  grabMany: boolean;
126
126
  table: string;
@@ -128,8 +128,8 @@ export declare type IRelationManyToMany = {
128
128
  name: string;
129
129
  relations: IRelation[];
130
130
  };
131
- export declare type IRelationField = IRelationOneToManyOrManyToOne | IRelationManyToMany;
132
- export declare type IMappedField = {
131
+ export type IRelationField = IRelationOneToManyOrManyToOne | IRelationManyToMany;
132
+ export type IMappedField = {
133
133
  name: string;
134
134
  as: string;
135
135
  type: string;
@@ -139,7 +139,7 @@ export declare type IMappedField = {
139
139
  referencedTable: string;
140
140
  referencedKey: string;
141
141
  };
142
- export declare type IArtifacts = {
142
+ export type IArtifacts = {
143
143
  [k: string]: {
144
144
  table: string;
145
145
  primaryKey: string;
@@ -4,9 +4,5 @@ declare class Stats {
4
4
  constructor(client: Redis | Cluster);
5
5
  updateStats: (ms: number, category: string) => Promise<void>;
6
6
  }
7
- declare namespace timer {
8
- type Callback = (time: number, ...params: any[]) => void;
9
- type Params<T> = T extends (ms: number, ...params: infer U) => any ? U : never;
10
- }
11
7
  export declare function timer(): <T extends timer.Callback>(callback: T, ...args: timer.Params<T>) => void;
12
8
  export default Stats;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.timer = void 0;
3
+ exports.timer = timer;
4
4
  const perf_hooks_1 = require("perf_hooks");
5
5
  class Stats {
6
6
  constructor(client) {
@@ -28,5 +28,4 @@ function timer() {
28
28
  callback(perf_hooks_1.performance.now() - start, ...args);
29
29
  };
30
30
  }
31
- exports.timer = timer;
32
31
  exports.default = Stats;
@@ -2,7 +2,7 @@
2
2
  // If a many-to-one relation's ID field is null, we want the
3
3
  // relation field to be null as well, not undefined.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.addNullFallbacks = void 0;
5
+ exports.addNullFallbacks = addNullFallbacks;
6
6
  function addNullFallbacks(sqlAST, data) {
7
7
  if (data == null) {
8
8
  return;
@@ -30,4 +30,3 @@ function addNullFallbacks(sqlAST, data) {
30
30
  }
31
31
  }
32
32
  }
33
- exports.addNullFallbacks = addNullFallbacks;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeCursor = exports.encodeCursor = void 0;
3
+ exports.encodeCursor = encodeCursor;
4
+ exports.decodeCursor = decodeCursor;
4
5
  function encodeCursor(cursor) {
5
6
  return Buffer.from(JSON.stringify(cursor)).toString("base64");
6
7
  }
7
- exports.encodeCursor = encodeCursor;
8
8
  function decodeCursor(cursor) {
9
9
  return JSON.parse(Buffer.from(cursor, "base64").toString("utf8"));
10
10
  }
11
- exports.decodeCursor = decodeCursor;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDateTimeStringMySQL = void 0;
3
+ exports.getDateTimeStringMySQL = getDateTimeStringMySQL;
4
4
  // Assumes input uses zero offset
5
5
  function getDateTimeStringMySQL(dateTimeString) {
6
6
  return dateTimeString.replace("T", " ").slice(0, 19);
7
7
  }
8
- exports.getDateTimeStringMySQL = getDateTimeStringMySQL;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOrderBy = void 0;
3
+ exports.getOrderBy = getOrderBy;
4
4
  // https://gist.github.com/pcattori/2bb645d587e45c9fdbcabf5cef7a7106
5
5
  function getOrderBy(args, primaryKey) {
6
6
  let out = undefined;
@@ -41,7 +41,6 @@ function getOrderBy(args, primaryKey) {
41
41
  }
42
42
  return { orderBy: out, flip };
43
43
  }
44
- exports.getOrderBy = getOrderBy;
45
44
  function getFlip(args) {
46
45
  return args?.$paginate?.last != null;
47
46
  }
@@ -1,21 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSqlAst = void 0;
3
+ exports.getSqlAst = getSqlAst;
4
4
  const SqlString = require("sqlstring");
5
5
  // @ts-ignore
6
- const TSqlString = require("tsqlstring");
7
- // @ts-ignore
8
6
  const alias_namespace_1 = require("join-monster/dist/alias-namespace");
9
7
  const _ = require("lodash/fp");
10
8
  const getOrderBy_1 = require("./getOrderBy");
11
9
  const namespace = new alias_namespace_1.default(true);
12
10
  function getSqlAst(input) {
13
- const { table, fieldName, fields, args, grabMany, sqlJoin, sqlBatch, junction, getWhere, artifacts, rowWithMatchingCursor, dialect, } = input;
11
+ const { table, fieldName, fields, args, grabMany, sqlJoin, sqlBatch, junction, getWhere, artifacts, rowWithMatchingCursor, dialect } = input;
14
12
  const tableArtifacts = artifacts[table];
15
13
  const primaryKey = tableArtifacts.primaryKey;
16
- const format = dialect === "mysql"
17
- ? SqlString.format.bind(SqlString)
18
- : TSqlString.format.bind(TSqlString);
14
+ const format = SqlString.format.bind(SqlString);
19
15
  const orderBy = input.orderBy ?? (0, getOrderBy_1.getOrderBy)(args, primaryKey)?.orderBy;
20
16
  let where = input.where;
21
17
  if (input.where == null) {
@@ -74,12 +70,12 @@ function getSqlAst(input) {
74
70
  referencedTableAlias,
75
71
  referencedTableAlias,
76
72
  mappedField.referencedKey,
77
- mappedField.foreignKey,
73
+ mappedField.foreignKey
78
74
  ]);
79
75
  },
80
76
  name: x,
81
77
  fieldName: x,
82
- as: namespace.generate("column", x),
78
+ as: namespace.generate("column", x)
83
79
  };
84
80
  }
85
81
  // TODO - validate in dev?
@@ -105,7 +101,7 @@ function getSqlAst(input) {
105
101
  // Notice the duplicate names in the select. This results in missing rows because the
106
102
  // shape definition passed into NestHydrationJS will only have 1 `id`.
107
103
  fieldName: String(Date.now()),
108
- as: String(Date.now()),
104
+ as: String(Date.now())
109
105
  },
110
106
  junction: {
111
107
  sqlTable: relationField.junctionTable,
@@ -118,8 +114,7 @@ function getSqlAst(input) {
118
114
  return undefined;
119
115
  }
120
116
  const argsMapped = _.cloneDeep(args);
121
- argsMapped.$where =
122
- argsMapped.$where[relationField.junctionTable];
117
+ argsMapped.$where = argsMapped.$where[relationField.junctionTable];
123
118
  const whereResult = getWhere(
124
119
  // table is escaped already
125
120
  table, argsMapped, dialect, orderBy, rowWithMatchingCursor);
@@ -143,12 +138,12 @@ function getSqlAst(input) {
143
138
  sqlBatch: {
144
139
  thisKey: columnToASTChild(relationField.relations[0].foreignKey, namespace, asJunction),
145
140
  parentKey: columnToASTChild(relationField.relations[0].referencedKey, namespace),
146
- sqlJoin: (junctionTable, t, args) => `${junctionTable}.${relationField.relations[1].foreignKey} = ${t}.${relationField.relations[1].referencedKey}`,
147
- },
141
+ sqlJoin: (junctionTable, t, args) => `${junctionTable}.${relationField.relations[1].foreignKey} = ${t}.${relationField.relations[1].referencedKey}`
142
+ }
148
143
  },
149
144
  getWhere,
150
145
  artifacts,
151
- dialect,
146
+ dialect
152
147
  });
153
148
  }
154
149
  return getSqlAst({
@@ -174,16 +169,15 @@ function getSqlAst(input) {
174
169
  // sub lists are limited, too.
175
170
  sqlBatch: {
176
171
  thisKey: columnToASTChild(relationField.relation.referencedKey, namespace),
177
- parentKey: columnToASTChild(relationField.relation.foreignKey, namespace),
172
+ parentKey: columnToASTChild(relationField.relation.foreignKey, namespace)
178
173
  },
179
174
  getWhere,
180
175
  artifacts,
181
- dialect,
176
+ dialect
182
177
  });
183
- })),
178
+ }))
184
179
  };
185
180
  }
186
- exports.getSqlAst = getSqlAst;
187
181
  function keyToASTChild(key, namespace, fromOtherTable) {
188
182
  if (Array.isArray(key)) {
189
183
  const clumsyName = toClumsyName(key);
@@ -192,7 +186,7 @@ function keyToASTChild(key, namespace, fromOtherTable) {
192
186
  name: key,
193
187
  fieldName: clumsyName,
194
188
  as: namespace.generate("column", clumsyName),
195
- fromOtherTable,
189
+ fromOtherTable
196
190
  };
197
191
  }
198
192
  return columnToASTChild(key, namespace, fromOtherTable);
@@ -203,7 +197,7 @@ function columnToASTChild(columnName, namespace, fromOtherTable) {
203
197
  name: columnName,
204
198
  fieldName: columnName,
205
199
  as: namespace.generate("column", columnName),
206
- fromOtherTable,
200
+ fromOtherTable
207
201
  };
208
202
  }
209
203
  function toClumsyName(keyArr) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWhere = void 0;
3
+ exports.getWhere = getWhere;
4
4
  const stringifyWhere_1 = require("./stringifyWhere");
5
5
  function getWhere(
6
6
  // Note: `table` is not escaped in getWhere, so it should be escaped beforehand.
@@ -18,4 +18,3 @@ table, args, dialect, orderBy, rowWithMatchingCursor) {
18
18
  rowWithMatchingCursor,
19
19
  }) || null);
20
20
  }
21
- exports.getWhere = getWhere;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runTransforms = void 0;
3
+ exports.runTransforms = runTransforms;
4
4
  function runTransforms(data, fields) {
5
5
  if (data == null) {
6
6
  return;
@@ -33,4 +33,3 @@ function runTransforms(data, fields) {
33
33
  }
34
34
  }
35
35
  }
36
- exports.runTransforms = runTransforms;