@technicity/data-service-generator 0.15.0 → 0.16.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.
@@ -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;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.generate = void 0;
29
+ exports.generate = generate;
30
30
  const path = __importStar(require("node:path"));
31
31
  const fs = __importStar(require("node:fs"));
32
32
  const os = __importStar(require("node:os"));
@@ -202,7 +202,6 @@ async function generate(input) {
202
202
  fse.copySync(tmpBuildOutputPath, sdkOutputPath);
203
203
  fse.removeSync(tmpDirPath);
204
204
  }
205
- exports.generate = generate;
206
205
  function init(input) {
207
206
  const { database, user, password, host, port, server } = input;
208
207
  if (dialect === "mysql") {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.capitalizeFirstLetter = void 0;
3
+ exports.capitalizeFirstLetter = capitalizeFirstLetter;
4
4
  function capitalizeFirstLetter(str) {
5
5
  return str.charAt(0).toUpperCase() + str.slice(1);
6
6
  }
7
- exports.capitalizeFirstLetter = capitalizeFirstLetter;
@@ -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;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { AsyncLocalStorage } from "node:async_hooks";
3
2
  export interface IRuntime {
4
3
  resolve(input: TResolveParams): Promise<any>;
@@ -11,8 +10,8 @@ export interface IRuntime {
11
10
  isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
12
11
  }): Promise<TBeginTransactionResult>;
13
12
  }
14
- export declare type TAction = "findUnique" | "findMany" | "findManyPaginated" | "create" | "update" | "updateMany" | "delete" | "deleteMany";
15
- export declare type TResolveParams = {
13
+ export type TAction = "findUnique" | "findMany" | "findManyPaginated" | "create" | "update" | "updateMany" | "delete" | "deleteMany";
14
+ export type TResolveParams = {
16
15
  resource: string;
17
16
  action: TAction;
18
17
  args?: IArgs;
@@ -30,60 +29,60 @@ export declare type TResolveParams = {
30
29
  }>;
31
30
  sdk?: unknown;
32
31
  };
33
- export declare type TOnHandler = (sdk: unknown, input: unknown, output: unknown) => Promise<void>;
32
+ export type TOnHandler = (sdk: unknown, input: unknown, output: unknown) => Promise<void>;
34
33
  export declare class EventOnHandlerError<T> extends Event {
35
34
  error: T;
36
35
  constructor(message: string, data: ConstructorParameters<typeof Event>[1] & {
37
36
  error: T;
38
37
  });
39
38
  }
40
- export declare type TContext = {
39
+ export type TContext = {
41
40
  [k: string]: any;
42
41
  };
43
- export declare type TMiddleware = (params: TResolveParams, next: (params: TResolveParams) => Promise<any>) => Promise<any>;
44
- export declare type IDialect = "mysql" | "mssql" | "sqlite";
45
- export declare type TDbCall = (q: string) => Promise<any>;
46
- export declare type TFormatQuery = (q: string, values: any[]) => string;
47
- export declare type TBeginTransaction = () => Promise<TBeginTransactionResult>;
48
- declare type TBeginTransactionResult = {
42
+ export type TMiddleware = (params: TResolveParams, next: (params: TResolveParams) => Promise<any>) => Promise<any>;
43
+ export type IDialect = "mysql" | "mssql" | "sqlite";
44
+ export type TDbCall = (q: string) => Promise<any>;
45
+ export type TFormatQuery = (q: string, values: any[]) => string;
46
+ export type TBeginTransaction = () => Promise<TBeginTransactionResult>;
47
+ type TBeginTransactionResult = {
49
48
  dbCall: (q: string) => Promise<any>;
50
49
  commit: () => Promise<void>;
51
50
  rollback: () => Promise<void>;
52
51
  };
53
- export declare type ISupplementClientOpts = boolean;
54
- export declare type IOrderBy = {
52
+ export type ISupplementClientOpts = boolean;
53
+ export type IOrderBy = {
55
54
  column: string;
56
55
  direction: any;
57
56
  }[];
58
- export declare type IArgs = {
57
+ export type IArgs = {
59
58
  [k: string]: any;
60
59
  };
61
- export declare type TSelect = {
60
+ export type TSelect = {
62
61
  [k: string]: boolean | {
63
62
  $fields?: TSelect;
64
63
  };
65
64
  };
66
- declare type IWhere = (table: string, args: IArgs) => string | undefined;
67
- declare type IASTChildColumn = {
65
+ type IWhere = (table: string, args: IArgs) => string | undefined;
66
+ type IASTChildColumn = {
68
67
  type: "column";
69
68
  name: string;
70
69
  fieldName: string;
71
70
  as: string;
72
71
  fromOtherTable?: string;
73
72
  };
74
- declare type IASTChildComposite = {
73
+ type IASTChildComposite = {
75
74
  type: "composite";
76
75
  name: string[];
77
76
  fieldName: string;
78
77
  as: string;
79
78
  fromOtherTable?: string;
80
79
  };
81
- declare type ISqlJoin = (t1: string, t2: string, args: IArgs) => string;
82
- declare type ISqlBatch = {
80
+ type ISqlJoin = (t1: string, t2: string, args: IArgs) => string;
81
+ type ISqlBatch = {
83
82
  thisKey: IASTChildColumn;
84
83
  parentKey: IASTChildColumn;
85
84
  };
86
- declare type IJunction = {
85
+ type IJunction = {
87
86
  sqlTable: string;
88
87
  as: string;
89
88
  uniqueKey: string | string[];
@@ -99,7 +98,7 @@ declare type IJunction = {
99
98
  where?: IWhere;
100
99
  sqlJoins: ISqlJoin[];
101
100
  };
102
- export declare type IGetSQLASTInput = {
101
+ export type IGetSQLASTInput = {
103
102
  table: string;
104
103
  fieldName: string;
105
104
  fields: TSelect;
@@ -116,17 +115,17 @@ export declare type IGetSQLASTInput = {
116
115
  dialect: IDialect;
117
116
  firstChild?: IASTChildColumn | IASTChildComposite;
118
117
  };
119
- export declare type IRelation = {
118
+ export type IRelation = {
120
119
  table: string;
121
120
  foreignKey: string;
122
121
  referencedTable: string;
123
122
  referencedKey: string;
124
123
  nullable: boolean;
125
124
  };
126
- declare type IOneToManyOrManyToOne = "one-to-many__many-to-one";
127
- declare type IManyToMany = "many-to-many";
128
- declare type IRelationKind = "one-to-many" | "many-to-one";
129
- export declare type IRelationOneToManyOrManyToOne = {
125
+ type IOneToManyOrManyToOne = "one-to-many__many-to-one";
126
+ type IManyToMany = "many-to-many";
127
+ type IRelationKind = "one-to-many" | "many-to-one";
128
+ export type IRelationOneToManyOrManyToOne = {
130
129
  type: IOneToManyOrManyToOne;
131
130
  kind: IRelationKind;
132
131
  grabMany: boolean;
@@ -135,7 +134,7 @@ export declare type IRelationOneToManyOrManyToOne = {
135
134
  relation: IRelation;
136
135
  nullable: boolean;
137
136
  };
138
- export declare type IRelationManyToMany = {
137
+ export type IRelationManyToMany = {
139
138
  type: IManyToMany;
140
139
  grabMany: boolean;
141
140
  table: string;
@@ -143,8 +142,8 @@ export declare type IRelationManyToMany = {
143
142
  name: string;
144
143
  relations: IRelation[];
145
144
  };
146
- export declare type IRelationField = IRelationOneToManyOrManyToOne | IRelationManyToMany;
147
- export declare type IMappedField = {
145
+ export type IRelationField = IRelationOneToManyOrManyToOne | IRelationManyToMany;
146
+ export type IMappedField = {
148
147
  name: string;
149
148
  as: string;
150
149
  type: string;
@@ -154,7 +153,7 @@ export declare type IMappedField = {
154
153
  referencedTable: string;
155
154
  referencedKey: string;
156
155
  };
157
- export declare type IArtifacts = {
156
+ export type IArtifacts = {
158
157
  [k: string]: {
159
158
  table: string;
160
159
  primaryKey: string;
@@ -180,8 +179,8 @@ export declare type IArtifacts = {
180
179
  } | null;
181
180
  };
182
181
  };
183
- export declare type TFieldType = "string" | "boolean" | "number" | "integer";
184
- export declare type TField = {
182
+ export type TFieldType = "string" | "boolean" | "number" | "integer";
183
+ export type TField = {
185
184
  kind: "scalar";
186
185
  type: TFieldType;
187
186
  name: string;
@@ -1,7 +1,7 @@
1
1
  import Database from "better-sqlite3";
2
2
  import type { IRuntime, TMiddleware, TResolveParams, IArtifacts, ISupplementClientOpts } from "./IRuntime";
3
3
  import { MiddlewareHandler } from "./lib/shared";
4
- declare type TClientOpts = {
4
+ type TClientOpts = {
5
5
  filename: string;
6
6
  } & Parameters<typeof Database>[1];
7
7
  export declare class RuntimeSQLite implements IRuntime {
@@ -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
  }
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getSqlAst = void 0;
29
+ exports.getSqlAst = getSqlAst;
30
30
  const SqlString = __importStar(require("sqlstring"));
31
31
  // @ts-ignore
32
32
  const TSqlString = __importStar(require("tsqlstring"));
@@ -220,7 +220,6 @@ function getSqlAst(input) {
220
220
  }))
221
221
  };
222
222
  }
223
- exports.getSqlAst = getSqlAst;
224
223
  function keyToASTChild(key, namespace, fromOtherTable) {
225
224
  if (Array.isArray(key)) {
226
225
  const clumsyName = toClumsyName(key);
@@ -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;
@@ -26,7 +26,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports._prepareWhere = exports.whereNeedsProcessing = exports.postProcess = exports.MiddlewareHandler = exports.resolve = void 0;
29
+ exports.MiddlewareHandler = void 0;
30
+ exports.resolve = resolve;
31
+ exports.postProcess = postProcess;
32
+ exports.whereNeedsProcessing = whereNeedsProcessing;
33
+ exports._prepareWhere = _prepareWhere;
30
34
  // @ts-ignore
31
35
  // import * as queryAST from "join-monster/dist/query-ast-to-sql-ast";
32
36
  // @ts-ignore
@@ -95,7 +99,6 @@ async function resolve(input, dbCall, formatQuery, beginTransaction, dialect, mi
95
99
  }
96
100
  return p;
97
101
  }
98
- exports.resolve = resolve;
99
102
  function _resolve(input, dbCall, formatQuery, beginTransaction, dialect, context, cache) {
100
103
  switch (input.action) {
101
104
  case "findMany":
@@ -871,7 +874,6 @@ function postProcess(data, fields, shouldRemoveExtraKeys) {
871
874
  removeExtraKeys(data, fields);
872
875
  }
873
876
  }
874
- exports.postProcess = postProcess;
875
877
  function removeExtraKeys(data, fields) {
876
878
  if (data == null || (Array.isArray(data) && data[0] == null)) {
877
879
  return;
@@ -967,7 +969,6 @@ function typeCastSqlite(data, fields, table, artifacts) {
967
969
  function whereNeedsProcessing(where) {
968
970
  return JSON.stringify(where).includes("Uuid");
969
971
  }
970
- exports.whereNeedsProcessing = whereNeedsProcessing;
971
972
  async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
972
973
  const mappedFields = artifacts[table].mappedFields;
973
974
  let out = {};
@@ -1063,7 +1064,6 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
1063
1064
  });
1064
1065
  return out;
1065
1066
  }
1066
- exports._prepareWhere = _prepareWhere;
1067
1067
  function getPrepareWhereNotFoundMessage(mappedField, value) {
1068
1068
  return `Not found: unable to map \`${mappedField.referencedTable}\`.\`${mappedField.name}\` to \`${mappedField.referencedTable}\`.\`${mappedField.referencedKey}\` for the value \`${value}\`.`;
1069
1069
  }
@@ -1,8 +1,8 @@
1
1
  import type { IOrderBy, IDialect } from "../IRuntime";
2
- declare type IWhere = {
2
+ type IWhere = {
3
3
  [k: string]: any;
4
4
  };
5
- declare type IArgs = {
5
+ type IArgs = {
6
6
  [k: string]: any;
7
7
  };
8
8
  export declare function stringifyWhere(input: {
@@ -23,7 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getEscape = exports.getEscapeId = exports.stringifyWhere = void 0;
26
+ exports.stringifyWhere = stringifyWhere;
27
+ exports.getEscapeId = getEscapeId;
28
+ exports.getEscape = getEscape;
27
29
  const _ = __importStar(require("lodash/fp"));
28
30
  const MySqlString = __importStar(require("sqlstring"));
29
31
  // @ts-expect-error
@@ -49,7 +51,6 @@ function stringifyWhere(input) {
49
51
  }
50
52
  return result;
51
53
  }
52
- exports.stringifyWhere = stringifyWhere;
53
54
  function _stringifyWhere(where, table, escapeId, escape, result) {
54
55
  if (Object.prototype.hasOwnProperty.call(where, "$and")) {
55
56
  if (Object.keys(where).length !== 1) {
@@ -239,7 +240,6 @@ function getEscapeId(dialect) {
239
240
  }
240
241
  throw new Error("Unsupported dialect: " + dialect);
241
242
  }
242
- exports.getEscapeId = getEscapeId;
243
243
  function getEscape(dialect) {
244
244
  if (dialect === "mysql") {
245
245
  return MySqlString.escape.bind(MySqlString);
@@ -252,4 +252,3 @@ function getEscape(dialect) {
252
252
  }
253
253
  throw new Error("Unsupported dialect: " + dialect);
254
254
  }
255
- exports.getEscape = getEscape;
@@ -1,3 +1,3 @@
1
- declare type TValueCast = (value: any) => any;
1
+ type TValueCast = (value: any) => any;
2
2
  export declare function typeCastMSSQL(customTypeCast?: (meta: any, mssql: any) => TValueCast): (result: any, meta: any) => any;
3
3
  export {};
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.typeCastMSSQL = void 0;
26
+ exports.typeCastMSSQL = typeCastMSSQL;
27
27
  const mssql = __importStar(require("mssql"));
28
28
  // TODO: see https://github.com/tediousjs/node-mssql/pull/1171
29
29
  function typeCastMSSQL(customTypeCast) {
@@ -60,4 +60,3 @@ function typeCastMSSQL(customTypeCast) {
60
60
  });
61
61
  };
62
62
  }
63
- exports.typeCastMSSQL = typeCastMSSQL;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flatten = exports.mapAsync = void 0;
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 = void 0;
3
+ exports.traverseFieldArgs = traverseFieldArgs;
4
4
  function traverseFieldArgs(fields, cb) {
5
5
  const values = Object.values(fields);
6
6
  for (let x of values) {
@@ -15,4 +15,3 @@ function traverseFieldArgs(fields, cb) {
15
15
  traverseFieldArgs(fields, cb);
16
16
  }
17
17
  }
18
- exports.traverseFieldArgs = traverseFieldArgs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -47,7 +47,7 @@
47
47
  "jest": "^29.4.3",
48
48
  "sinon": "12.0.1",
49
49
  "testcontainers": "^9.1.3",
50
- "typescript": "4.6.4"
50
+ "typescript": "5.5.2"
51
51
  },
52
52
  "resolutions": {
53
53
  "xml2js": "0.5.0",