@technicity/data-service-generator 0.11.5 → 0.11.7

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;
@@ -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");
@@ -136,7 +136,6 @@ async function generate(input) {
136
136
  fse.copySync(tmpBuildOutputPath, sdkOutputPath);
137
137
  fse.removeSync(tmpDirPath);
138
138
  }
139
- exports.generate = generate;
140
139
  function init(input) {
141
140
  const { database, user, password, host, port, server } = input;
142
141
  if (dialect === "mysql") {
package/dist/ksql.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare type THeaders = {
1
+ type THeaders = {
2
2
  [k: string]: any;
3
3
  };
4
4
  export declare class KSQL {
@@ -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" | "mssql" | "ksql";
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;
@@ -1,6 +1,6 @@
1
1
  import type { IRuntime, TMiddleware, TResolveParams, IArtifacts, TDbCall } from "./IRuntime";
2
2
  import { KSQL } from "../ksql";
3
- declare type TGetTableName = (table: string) => string;
3
+ type TGetTableName = (table: string) => string;
4
4
  export declare class RuntimeKSQL implements IRuntime {
5
5
  #private;
6
6
  constructor(clientOpts: ConstructorParameters<typeof KSQL>[0], otherOpts: {
@@ -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,6 +1,6 @@
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
6
  const TSqlString = require("tsqlstring");
@@ -183,7 +183,6 @@ function getSqlAst(input) {
183
183
  })),
184
184
  };
185
185
  }
186
- exports.getSqlAst = getSqlAst;
187
186
  function keyToASTChild(key, namespace, fromOtherTable) {
188
187
  if (Array.isArray(key)) {
189
188
  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;
@@ -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;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._prepareWhere = exports.whereNeedsProcessing = exports.postProcess = exports.MiddlewareHandler = exports.resolve = void 0;
3
+ exports.MiddlewareHandler = void 0;
4
+ exports.resolve = resolve;
5
+ exports.postProcess = postProcess;
6
+ exports.whereNeedsProcessing = whereNeedsProcessing;
7
+ exports._prepareWhere = _prepareWhere;
4
8
  // @ts-ignore
5
9
  // import * as queryAST from "join-monster/dist/query-ast-to-sql-ast";
6
10
  // @ts-ignore
@@ -41,7 +45,6 @@ async function resolve(input, dbCall, formatQuery, beginTransaction, dialect, mi
41
45
  }
42
46
  return _resolve(input, dbCall, formatQuery, beginTransaction, dialect, context, cache);
43
47
  }
44
- exports.resolve = resolve;
45
48
  function _resolve(input, dbCall, formatQuery, beginTransaction, dialect, context, cache) {
46
49
  switch (input.action) {
47
50
  case "findMany":
@@ -784,7 +787,6 @@ function postProcess(data, fields, shouldRemoveExtraKeys) {
784
787
  }
785
788
  (0, runTransforms_1.runTransforms)(data, fields);
786
789
  }
787
- exports.postProcess = postProcess;
788
790
  function removeExtraKeys(data, fields) {
789
791
  if (data == null || (Array.isArray(data) && data[0] == null)) {
790
792
  return;
@@ -829,7 +831,6 @@ function removeExtraKeys(data, fields) {
829
831
  function whereNeedsProcessing(where) {
830
832
  return JSON.stringify(where).includes("Uuid");
831
833
  }
832
- exports.whereNeedsProcessing = whereNeedsProcessing;
833
834
  async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
834
835
  const mappedFields = artifacts[table].mappedFields;
835
836
  let out = {};
@@ -925,7 +926,6 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
925
926
  });
926
927
  return out;
927
928
  }
928
- exports._prepareWhere = _prepareWhere;
929
929
  function getPrepareWhereNotFoundMessage(mappedField, value) {
930
930
  return `Not found: unable to map \`${mappedField.referencedTable}\`.\`${mappedField.name}\` to \`${mappedField.referencedTable}\`.\`${mappedField.referencedKey}\` for the value \`${value}\`.`;
931
931
  }
@@ -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: {
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEscape = exports.getEscapeId = exports.stringifyWhere = void 0;
3
+ exports.stringifyWhere = stringifyWhere;
4
+ exports.getEscapeId = getEscapeId;
5
+ exports.getEscape = getEscape;
4
6
  const _ = require("lodash/fp");
5
7
  const MySqlString = require("sqlstring");
6
8
  // @ts-ignore
@@ -26,7 +28,6 @@ function stringifyWhere(input) {
26
28
  }
27
29
  return result;
28
30
  }
29
- exports.stringifyWhere = stringifyWhere;
30
31
  function _stringifyWhere(where, table, escapeId, escape, result) {
31
32
  if (Object.prototype.hasOwnProperty.call(where, "$and")) {
32
33
  if (Object.keys(where).length !== 1) {
@@ -215,7 +216,6 @@ function getEscapeId(dialect) {
215
216
  }
216
217
  throw new Error("Unsupported dialect: " + dialect);
217
218
  }
218
- exports.getEscapeId = getEscapeId;
219
219
  function getEscape(dialect) {
220
220
  if (dialect === "mysql") {
221
221
  return MySqlString.escape.bind(MySqlString);
@@ -225,4 +225,3 @@ function getEscape(dialect) {
225
225
  }
226
226
  throw new Error("Unsupported dialect: " + dialect);
227
227
  }
228
- 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 {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typeCastMSSQL = void 0;
3
+ exports.typeCastMSSQL = typeCastMSSQL;
4
4
  const mssql = require("mssql");
5
5
  // TODO: see https://github.com/tediousjs/node-mssql/pull/1171
6
6
  function typeCastMSSQL(customTypeCast) {
@@ -37,4 +37,3 @@ function typeCastMSSQL(customTypeCast) {
37
37
  });
38
38
  };
39
39
  }
40
- 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
  for (let x of fields) {
6
6
  if (typeof x !== "object") {
@@ -10,4 +10,3 @@ function traverseFieldArgs(fields, cb) {
10
10
  traverseFieldArgs(x.fields, cb);
11
11
  }
12
12
  }
13
- exports.traverseFieldArgs = traverseFieldArgs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.11.5",
3
+ "version": "0.11.7",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -9,7 +9,6 @@
9
9
  "compile": "rm -rf dist && tsc",
10
10
  "publish:next": "npm version prerelease --preid next",
11
11
  "preversion": "npm run compile",
12
- "postversion": "npm publish",
13
12
  "reset": "docker-compose rm -svf mysql57 && docker-compose up -d mysql57",
14
13
  "test:docker": "docker-compose exec test yarn test:sdk",
15
14
  "generate": "npm run compile && concurrently \"node ./test/mysql/generate.js\" \"node ./test/mysql8/generate.js\"",
@@ -47,6 +46,6 @@
47
46
  "env-cmd": "^10.1.0",
48
47
  "mocha": "9.1.3",
49
48
  "sinon": "12.0.1",
50
- "typescript": "4.6.4"
49
+ "typescript": "5.5.2"
51
50
  }
52
51
  }