@technicity/data-service-generator 0.7.0 → 0.8.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.
@@ -15,7 +15,7 @@ const TSqlString = require("tsqlstring");
15
15
  const json_schema_to_typescript_1 = require("json-schema-to-typescript");
16
16
  const getDuplicates_1 = require("../lib/getDuplicates");
17
17
  const isNotNullOrUndefined_1 = require("../lib/isNotNullOrUndefined");
18
- const mysql_1 = require("../runtime/lib/mysql");
18
+ const MySQL_1 = require("../runtime/lib/MySQL");
19
19
  // json-schema-to-typescript inlines everything. We don't want that,
20
20
  // so use `tsType`, and add imports manually.
21
21
  // https://github.com/bcherny/json-schema-to-typescript#custom-schema-properties
@@ -116,7 +116,7 @@ async function generate(input) {
116
116
  const sdkOutputPath = path.join(outdir, "sdk-ts");
117
117
  const nccVersion = "^0.33.0";
118
118
  child_process.execSync("npm i", { cwd: tmpDirPath, stdio: "inherit" });
119
- child_process.execSync(`npx -p @vercel/ncc@${nccVersion} ncc build ./${sdkFilename} -o ${tmpBuildOutputPath} -e ./artifacts`, { cwd: tmpDirPath, stdio: "inherit" });
119
+ child_process.execSync(`npx --yes -p @vercel/ncc@${nccVersion} ncc build ./${sdkFilename} -o ${tmpBuildOutputPath} -e ./artifacts`, { cwd: tmpDirPath, stdio: "inherit" });
120
120
  // TODO: workaround for artifacts.js not being output by ncc
121
121
  fs.writeFileSync(path.join(tmpBuildOutputPath, "artifacts.js"), artifactsSource
122
122
  .replace("export const artifacts: IArtifacts = ", "module.exports.artifacts = ")
@@ -138,7 +138,7 @@ exports.generate = generate;
138
138
  function init(input) {
139
139
  const { database, user, password, host, port, server } = input;
140
140
  if (dialect === "mysql") {
141
- let mysql = new mysql_1.MySQL({
141
+ let mysql = new MySQL_1.MySQL({
142
142
  user,
143
143
  password,
144
144
  host,
@@ -882,19 +882,14 @@ async function getTypeFields(table, name, includeMappedFields) {
882
882
  const argsProperties = x.type === "many-to-many"
883
883
  ? {
884
884
  [keyWhere]: {
885
- oneOf: [
886
- { tsType: getTypeWhereName(x.table) },
887
- {
888
- type: "array",
889
- items: [
890
- { tsType: getTypeWhereName(x.table) },
891
- { tsType: getTypeWhereName(x.junctionTable) },
892
- ],
893
- additionalItems: false,
894
- minItems: 2,
895
- maxItems: 2,
885
+ type: "object",
886
+ properties: {
887
+ [x.table]: { tsType: getTypeWhereName(x.table) },
888
+ [x.junctionTable]: {
889
+ tsType: getTypeWhereName(x.junctionTable),
896
890
  },
897
- ],
891
+ },
892
+ additionalProperties: false,
898
893
  },
899
894
  }
900
895
  : { [keyWhere]: { tsType: getTypeWhereName(x.table) } };
@@ -148,9 +148,10 @@ async function _getData(input, grabMany, dbCall, formatQuery, getBaseTableName,
148
148
  let where = undefined;
149
149
  if (args?.$where != null) {
150
150
  let argsMapped = args;
151
- if (Array.isArray(argsMapped?.$where)) {
151
+ if (typeof argsMapped.$where === "object" &&
152
+ argsMapped.$where[table] != null) {
152
153
  argsMapped = _.cloneDeep(argsMapped);
153
- argsMapped.$where = argsMapped.$where[0];
154
+ argsMapped.$where = argsMapped.$where[table];
154
155
  }
155
156
  const whereResult = (0, stringifyWhere_1.stringifyWhere)({
156
157
  where: argsMapped.$where,
@@ -304,8 +305,10 @@ async function resolveDependentFields(table, parentData, mappedFields, relationF
304
305
  if (junctionKeyValue == null) {
305
306
  return { [x.as ?? x.name]: [] };
306
307
  }
307
- let whereJunction = x.args != null && Array.isArray(x.args.$where)
308
- ? _.cloneDeep(x.args.$where[1])
308
+ let whereJunction = typeof x?.args?.$where === "object" &&
309
+ x.args.$where != null &&
310
+ x.args.$where[relationField.junctionTable] != null
311
+ ? _.cloneDeep(x.args.$where[relationField.junctionTable])
309
312
  : {};
310
313
  whereJunction = {
311
314
  $and: [
@@ -328,9 +331,11 @@ async function resolveDependentFields(table, parentData, mappedFields, relationF
328
331
  [relationField.relations[1].referencedKey]: { $in: keys },
329
332
  };
330
333
  const argsMapped = x.args == null ? {} : _.cloneDeep(x.args);
331
- if (Array.isArray(argsMapped.$where)) {
334
+ if (typeof argsMapped?.$where === "object" &&
335
+ argsMapped.$where != null &&
336
+ argsMapped.$where[relationField.table] != null) {
332
337
  argsMapped.$where = {
333
- $and: [whereDest, argsMapped.$where[0]],
338
+ $and: [whereDest, argsMapped.$where[relationField.table]],
334
339
  };
335
340
  }
336
341
  else if (argsMapped.$where != null) {
File without changes
File without changes
@@ -21,9 +21,12 @@ function getSqlAst(input) {
21
21
  if (input.where == null) {
22
22
  where = (table, args) => {
23
23
  let argsMapped = args;
24
- if (junction != null && Array.isArray(argsMapped?.$where)) {
24
+ if (junction != null &&
25
+ typeof argsMapped?.$where === "object" &&
26
+ argsMapped.$where != null &&
27
+ argsMapped.$where[input.table] != null) {
25
28
  argsMapped = _.cloneDeep(argsMapped);
26
- argsMapped.$where = argsMapped.$where[0];
29
+ argsMapped.$where = argsMapped.$where[input.table];
27
30
  }
28
31
  const whereResult = getWhere(
29
32
  // table is escaped already
@@ -109,11 +112,14 @@ function getSqlAst(input) {
109
112
  as: asJunction,
110
113
  uniqueKey,
111
114
  where: (table, args) => {
112
- if (!Array.isArray(args?.$where)) {
115
+ if (typeof args?.$where !== "object" ||
116
+ typeof args?.$where == null ||
117
+ args.$where[relationField.junctionTable] == null) {
113
118
  return undefined;
114
119
  }
115
120
  const argsMapped = _.cloneDeep(args);
116
- argsMapped.$where = argsMapped.$where[1];
121
+ argsMapped.$where =
122
+ argsMapped.$where[relationField.junctionTable];
117
123
  const whereResult = getWhere(
118
124
  // table is escaped already
119
125
  table, argsMapped, dialect, orderBy, rowWithMatchingCursor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -17,7 +17,7 @@
17
17
  "fs-extra": "10.0.0",
18
18
  "graphql": "15.8.0",
19
19
  "graphql-relay": "^0.9.0",
20
- "join-monster": "apalm/join-monster#340bcad96da4c268e874d07552d564c98ecf39ea",
20
+ "join-monster": "git+https://github.com/apalm/join-monster.git#3e93d7028ccbf50f728577b2290b5f2638b639cb",
21
21
  "json-schema-to-typescript": "10.1.5",
22
22
  "lodash": "^4.17.20",
23
23
  "mssql": "^6.3.1",
package/CHANGELOG.md DELETED
@@ -1,166 +0,0 @@
1
- # 0.7.0 [2022.01.17]
2
-
3
- - Add support for MySQL 8
4
-
5
- # 0.5.12 [2021.11.18]
6
-
7
- - Add `$queryRaw`
8
-
9
- ```ts
10
- await sdk.$queryRaw("SELECT * FROM Foo WHERE id = ?", [2]);
11
- ```
12
-
13
- Use the `?` character as a placeholder for values that need to be escaped.
14
-
15
- # 0.5.12 [2021.11.18]
16
-
17
- - Add support for nested creates. All of the specified creates are wrapped in a transaction.
18
-
19
- ```ts
20
- await sdk.postFoo({
21
- foo: "blah",
22
- barList: {
23
- $create: [
24
- {
25
- note: "blah",
26
- bazList: { $create: [{ baz: "asdf" }, { baz: "zzz" }] },
27
- },
28
- { note: "blah 2" },
29
- ],
30
- },
31
- });
32
- ```
33
-
34
- In the above example, 5 records are created: 1 `Foo` record, 2 `Bar` records, and 2 `Baz` records.
35
-
36
- # 0.5.7 [2021.10.12]
37
-
38
- - Add `$nlike` operator. Equivalent to SQL's `NOT LIKE` operator.
39
-
40
- ```ts
41
- await sdk.getFooList({
42
- $where: { bar: { $nlike: "%baz%" } },
43
- });
44
- ```
45
-
46
- # 0.5.5 [2021.10.12]
47
-
48
- - Add limit + offset pagination
49
-
50
- ```ts
51
- await sdk.getFooListPaginated({
52
- $paginate: { limit: 5, offset: 2 },
53
- });
54
- ```
55
-
56
- # 0.5.0 [2021.10.08]
57
-
58
- - Add support for middleware
59
-
60
- Generated SDKs now have a `$use` method, which takes a single argument: your middleware function.
61
-
62
- Example middleware that logs the amount of time an operation took:
63
-
64
- ```ts
65
- sdk.$use(async (params, next) => {
66
- const start = process.hrtime();
67
- const result = await next(params);
68
- const end = process.hrtime(start);
69
- console.log(`${params.resource}.${params.action} took ${end[1] / 1000000}ms`);
70
- return result;
71
- });
72
- ```
73
-
74
- ## Migrating from 0.4.x
75
-
76
- 1. `npm install -S @technicity/data-service-generator@0.5.0`
77
- 2. Regenerate SDK
78
-
79
- # 0.4.0 [2021.09.17]
80
-
81
- - Implement operations on update for string, number fields
82
-
83
- ## string
84
-
85
- ### `$prepend`
86
-
87
- Prepend a string to the current value. If the current value is `null`, the value is not updated.
88
-
89
- ```ts
90
- await sdk.patchFoo(
91
- { id: 1 },
92
- { bar: { $prepend: `BAZ_` }
93
- );
94
- ```
95
-
96
- ### `$append`
97
-
98
- Append a string to the current value. If the current value is `null`, the value is not updated.
99
-
100
- ```ts
101
- await sdk.patchFoo(
102
- { id: 1 },
103
- { bar: { $append: `_BAZ` }
104
- );
105
- ```
106
-
107
- ## number
108
-
109
- ### `$increment`
110
-
111
- Increment the current value. If the current value is `null`, the value is not updated.
112
-
113
- ```ts
114
- await sdk.patchBar(
115
- { id: 1 },
116
- { foo: { $increment: 5 }
117
- );
118
- ```
119
-
120
- ### `$decrement`
121
-
122
- Decrement the current value. If the current value is `null`, the value is not updated.
123
-
124
- ```ts
125
- await sdk.patchBar(
126
- { id: 1 },
127
- { foo: { $decrement: 5 }
128
- );
129
- ```
130
-
131
- ## Migrating from 0.3.x
132
-
133
- 1. `npm install -S @technicity/data-service-generator@0.4.0`
134
- 2. Regenerate SDK
135
-
136
- # 0.3.1 [2021.09.09]
137
-
138
- - [MSSQL] Allow passing custom `typeCast`
139
-
140
- # 0.3.0 [2021.09.08]
141
-
142
- - For the generated SDK, instead of specifying a `dialect`, specify a `runtime`. This reduces the need to regenerate SDKs, since updates and bugfixes to the runtime side can be obtained solely by updating the `@technicity/data-service-generator` version, instead of both updating the `@technicity/data-service-generator` version and regenerating the SDK. It also allows for custom runtimes that live outside this package. `@technicity/data-service-generator` ships with 3 runtimes: `RuntimeMySQL`, `RuntimeMSSQL`, `RuntimeKSQL`.
143
- - Add KSQL support
144
- - `driverOpts` -> `clientOpts`
145
- - Add `otherOpts` to allow passing extra runtime-specific options
146
-
147
- ## Migrating from 0.2.x
148
-
149
- 1. `npm install -S @technicity/data-service-generator@0.3.0`
150
- 2. Regenerate SDK
151
- 3. Update SDK instantiation:
152
-
153
- ```diff
154
- + import { RuntimeMySQL } from "@technicity/data-service-generator/dist/runtime/RuntimeMySQL";
155
-
156
- const sdk = new SDK({
157
- - dialect: "mysql",
158
- + runtime: RuntimeMySQL,
159
- - driverOpts: {
160
- + clientOpts: {
161
- database: "MY_DATABASE",
162
- user: "MY_USER",
163
- password: "MY_PASSWORD",
164
- },
165
- });
166
- ```