@technicity/data-service-generator 0.11.0-next.2 → 0.11.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
@@ -44,3 +44,10 @@ async function main() {
44
44
  | port | No | 3306 \| 1433 | Database port. Defaults to 3306 for MySQL, 1433 for SQL Server. |
45
45
  | tables | No | | An array of database tables to process (allowlist). |
46
46
  | excludeTables | No | | An array of database tables to not process (denylist). |
47
+
48
+ ### Running Tests
49
+
50
+ - spin up test environment: `docker-compose up -d`
51
+ - run tests: `docker-compose exec test yarn test`
52
+
53
+ - `yarn test:prepare`
@@ -16,5 +16,6 @@ declare class Cache {
16
16
  insert(key: string, payload: any): Promise<void>;
17
17
  read(key: string): Promise<any>;
18
18
  purge(...uuids: string[]): Promise<void>;
19
+ shutdown(): Promise<void>;
19
20
  }
20
21
  export default Cache;
@@ -91,5 +91,8 @@ class Cache {
91
91
  ];
92
92
  });
93
93
  }
94
+ async shutdown() {
95
+ await this.client.disconnect();
96
+ }
94
97
  }
95
98
  exports.default = Cache;
@@ -83,6 +83,9 @@ class RuntimeMySQL {
83
83
  return (0, shared_1._prepareWhere)(artifacts, table, data, this.dbCall.bind(this), this.formatQuery.bind(this));
84
84
  }
85
85
  async $shutdown() {
86
+ if (__classPrivateFieldGet(this, _RuntimeMySQL_clientCache, "f")) {
87
+ await __classPrivateFieldGet(this, _RuntimeMySQL_clientCache, "f").shutdown();
88
+ }
86
89
  await __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").endPool();
87
90
  }
88
91
  dbCall(q) {
@@ -44,12 +44,13 @@ async function resolve(input, dbCall, formatQuery, beginTransaction, dialect, mi
44
44
  exports.resolve = resolve;
45
45
  function _resolve(input, dbCall, formatQuery, beginTransaction, dialect, context, cache) {
46
46
  switch (input.action) {
47
- case "findUnique":
48
47
  case "findMany":
49
- case "findManyPaginated":
50
48
  return cache && !input.skipCache ?
51
49
  getCached(input, dbCall, formatQuery, dialect, cache) :
52
50
  getData(input, dbCall, formatQuery, dialect);
51
+ case "findUnique":
52
+ case "findManyPaginated":
53
+ return getData(input, dbCall, formatQuery, dialect);
53
54
  case "create":
54
55
  return create(input, dbCall, formatQuery, beginTransaction, dialect, context);
55
56
  case "update":
@@ -274,11 +275,25 @@ async function getCached(input, dbCall, formatQuery, dialect, cache) {
274
275
  if (cached) {
275
276
  if (stats)
276
277
  done(stats.updateStats, "get_redis");
277
- results = cache;
278
+ results = cached;
278
279
  }
279
280
  else {
280
- ensureUuidSelect(input);
281
+ const remove = ensureUuidSelect(input);
281
282
  results = await getData(input, dbCall, formatQuery, dialect);
283
+ if (!Array.isArray(results)) {
284
+ if ("results" in results)
285
+ results = results.results;
286
+ else {
287
+ throw new Error("Bad result returned by getData in SDK.");
288
+ }
289
+ }
290
+ for (const result of results)
291
+ for (const path of remove) {
292
+ let data = result;
293
+ for (const key of path)
294
+ data = data[key];
295
+ // delete data.uuid;
296
+ }
282
297
  cache.insert(request, results);
283
298
  if (stats)
284
299
  done(stats.updateStats, "get_mysql");
@@ -289,20 +304,25 @@ async function getCached(input, dbCall, formatQuery, dialect, cache) {
289
304
  }
290
305
  function ensureUuidSelect(input) {
291
306
  const { resource, artifacts } = input;
307
+ const remove = [];
292
308
  ensure(resource, input);
293
- function ensure(type, input) {
309
+ function ensure(type, input, path = []) {
294
310
  const { scalarFields, relationFields } = artifacts[type];
295
311
  if (!scalarFields.includes("uuid"))
296
312
  return;
297
- const fields = input.fields;
298
- if (!fields.includes("uuid"))
313
+ const fields = input.fields || [];
314
+ if (!fields.includes("uuid")) {
315
+ remove.push(path);
299
316
  fields.unshift("uuid");
317
+ }
300
318
  for (const field of fields)
301
319
  if (typeof field == "object") {
302
- const { table } = relationFields[field.name];
303
- ensure(table, field);
320
+ const { name } = field;
321
+ const { table } = relationFields[name];
322
+ ensure(table, field, path.concat(name));
304
323
  }
305
324
  }
325
+ return remove;
306
326
  }
307
327
  function wrapListPaginationLimitOffset(data, totalCount) {
308
328
  return { paginationInfo: { totalCount }, results: data };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.11.0-next.2",
3
+ "version": "0.11.0",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -9,10 +9,13 @@
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
+ "reset": "docker-compose rm -svf mysql57 && docker-compose up -d mysql57",
14
+ "test:docker": "docker-compose exec test yarn test:sdk",
12
15
  "generate": "npm run compile && concurrently \"node ./test/mysql/generate.js\" \"node ./test/mysql8/generate.js\"",
13
16
  "test": "npm run generate && mocha ./test/addNullFallbacks.test.js && mocha ./test/stringifyWhere.test.js && npm run test:sdk",
14
17
  "test:prepare": "docker-compose down --volumes && docker-compose up -d --build",
15
- "test:sdk": "mocha ./test/test.js"
18
+ "test:sdk": "mocha --inspect=0.0.0.0:9229 ./test/test.js"
16
19
  },
17
20
  "dependencies": {
18
21
  "bluebird": "^3.7.2",