@technicity/data-service-generator 0.7.3 → 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.
@@ -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 = ")
@@ -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) {
@@ -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.3",
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": "git+https://github.com/apalm/join-monster.git#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",