@technicity/data-service-generator 0.11.6 → 0.12.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.
@@ -191,6 +191,21 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
191
191
  .concat(Array.from(set).sort())
192
192
  .join(",\n")} } from "./types";`;
193
193
  }
194
+ function getTypeNullResponses() {
195
+ return `type TNullResponses = { ${Object.entries(_.groupBy((x) => x.table, input))
196
+ .flatMap(([table, xx]) => {
197
+ const name = table;
198
+ return (`${name}: {` +
199
+ xx
200
+ .map(({ kind }) => {
201
+ const operation = mapKindToAction(kind);
202
+ return `${operation}: (input: { args: { select: Fields${table} | undefined, where: Where${table} | undefined }, model: "${table}", operation: "${operation}" }) => Promise<ReturnBase${table}>`;
203
+ })
204
+ .join(",") +
205
+ " } ");
206
+ })
207
+ .join(",")} }`;
208
+ }
194
209
  const src = `import type { IRuntime, TMiddleware, TContext } from "./IRuntime"
195
210
  import { artifacts } from "./artifacts";
196
211
 
@@ -198,16 +213,33 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
198
213
 
199
214
  export class SDK {
200
215
  runtime: IRuntime;
216
+ _nullability: TNullResponses | undefined;
201
217
 
218
+ static create(opts: {
219
+ runtime: any;
220
+ clientOpts: { [k: string]: any; },
221
+ otherOpts?: { [k: string]: any; }
222
+ }) {
223
+ return new this(opts);
224
+ }
225
+
226
+ static createNull(opts: {
227
+ runtime: any;
228
+ query?: TNullResponses
229
+ }) {
230
+ return new this({ runtime: opts.runtime, clientOpts: {}, otherOpts: { nullability: opts.query } });
231
+ }
232
+
202
233
  constructor(opts: {
203
234
  runtime: any;
204
235
  clientOpts: { [k: string]: any; },
205
236
  otherOpts?: { [k: string]: any; }
206
237
  }) {
207
- opts.otherOpts = opts.otherOpts ?? {}
238
+ const { nullability, ...otherOpts } = opts.otherOpts ?? {};
208
239
  this.runtime = new opts.runtime(opts.clientOpts, ${supplementClientOpts === true
209
- ? "{ supplementClientOpts: true, ...opts.otherOpts }"
210
- : "opts.otherOpts"}, artifacts);
240
+ ? "{ supplementClientOpts: true, ...otherOpts }"
241
+ : "otherOpts"}, artifacts);
242
+ this._nullability = nullability;
211
243
  }
212
244
 
213
245
  $use(middleware: TMiddleware) {
@@ -307,6 +339,8 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
307
339
  }
308
340
  }))).join("\n\n")}
309
341
  }
342
+
343
+ ${getTypeNullResponses()}
310
344
  `;
311
345
  return prettier.format(src, { parser: "typescript" });
312
346
  }
@@ -333,12 +367,13 @@ function getMethodSourceGetOne(x, findOnes, isTransaction) {
333
367
  return ${isTransaction ? "runtime" : "this.runtime"}.resolve(
334
368
  {
335
369
  resource: "${x.table}",
336
- action: "findUnique",
370
+ action: "${mapKindToAction(x.kind)}",
337
371
  args: { $where: param1 },
338
372
  fields: param2?.fields,
339
373
  artifacts,
340
374
  context: param2?.context,
341
375
  skipCache: param2?.skipCache,
376
+ nullability: this._nullability,
342
377
  ${isTransaction ? "dbCall" : ""}
343
378
  }
344
379
  );
@@ -352,12 +387,13 @@ function getMethodSourceGetList(x, isTransaction) {
352
387
  return ${isTransaction ? "runtime" : "this.runtime"}.resolve(
353
388
  {
354
389
  resource: "${x.table}",
355
- action: "findMany",
390
+ action: "${mapKindToAction(x.kind)}",
356
391
  args: param1,
357
392
  fields: param2?.fields,
358
393
  artifacts,
359
394
  context: param2?.context,
360
395
  skipCache: param2?.skipCache,
396
+ nullability: this._nullability,
361
397
  ${isTransaction ? "dbCall" : ""}
362
398
  }
363
399
  );
@@ -371,12 +407,13 @@ function getMethodSourceGetListPaginated(x, isTransaction) {
371
407
  return ${isTransaction ? "runtime" : "this.runtime"}.resolve(
372
408
  {
373
409
  resource: "${x.table}",
374
- action: "findManyPaginated",
410
+ action: "${mapKindToAction(x.kind)}",
375
411
  args: param1,
376
412
  fields: param2?.fields,
377
413
  artifacts,
378
414
  context: param2?.context,
379
415
  skipCache: param2?.skipCache,
416
+ nullability: this._nullability,
380
417
  ${isTransaction ? "dbCall" : ""}
381
418
  }
382
419
  );
@@ -389,11 +426,12 @@ function getMethodSourcePostOne(x, specialCaseUuidColumn, isTransaction) {
389
426
  ): Promise<${x.typeReturnBaseName}> {
390
427
  return ${isTransaction ? "runtime" : "this.runtime"}.resolve({
391
428
  resource: "${x.table}",
392
- action: "create",
429
+ action: "${mapKindToAction(x.kind)}",
393
430
  data,
394
431
  artifacts,
395
432
  fields: param2?.fields,
396
433
  context: {...param2?.context, specialCaseUuidColumn: ${JSON.stringify(specialCaseUuidColumn)}},
434
+ nullability: this._nullability,
397
435
  ${isTransaction ? "dbCall" : ""}
398
436
  });
399
437
  }`;
@@ -408,12 +446,13 @@ function getMethodSourcePatchOne(x, findOnes, isTransaction) {
408
446
  ): Promise<${x.typeReturnBaseName}> {
409
447
  return ${isTransaction ? "runtime" : "this.runtime"}.resolve({
410
448
  resource: "${x.table}",
411
- action: "update",
449
+ action: "${mapKindToAction(x.kind)}",
412
450
  args: { $where: param1 },
413
451
  data,
414
452
  artifacts,
415
453
  fields: param2?.fields,
416
454
  context: param2?.context,
455
+ nullability: this._nullability,
417
456
  ${isTransaction ? "dbCall" : ""}
418
457
  });
419
458
  }`;
@@ -426,12 +465,13 @@ function getMethodSourcePatchList(x, isTransaction) {
426
465
  ): Promise<Array<${x.typeReturnBaseName}>> {
427
466
  return ${isTransaction ? "runtime" : "this.runtime"}.resolve({
428
467
  resource: "${x.table}",
429
- action: "updateMany",
468
+ action: "${mapKindToAction(x.kind)}",
430
469
  args: param1,
431
470
  data,
432
471
  artifacts,
433
472
  fields: param2?.fields,
434
473
  context: param2?.context,
474
+ nullability: this._nullability,
435
475
  ${isTransaction ? "dbCall" : ""}
436
476
  });
437
477
  }`;
@@ -445,10 +485,11 @@ function getMethodSourceDeleteOne(x, findOnes, isTransaction) {
445
485
  ): Promise<void> {
446
486
  await ${isTransaction ? "runtime" : "this.runtime"}.resolve({
447
487
  resource: "${x.table}",
448
- action: "delete",
488
+ action: "${mapKindToAction(x.kind)}",
449
489
  args: { $where: param1 },
450
490
  artifacts,
451
491
  context: param2?.context,
492
+ nullability: this._nullability,
452
493
  ${isTransaction ? "dbCall" : ""}
453
494
  });
454
495
  }`;
@@ -460,14 +501,42 @@ function getMethodSourceDeleteList(x, isTransaction) {
460
501
  ): Promise<void> {
461
502
  await ${isTransaction ? "runtime" : "this.runtime"}.resolve({
462
503
  resource: "${x.table}",
463
- action: "deleteMany",
504
+ action: "${mapKindToAction(x.kind)}",
464
505
  args: param1,
465
506
  artifacts,
466
507
  context: param2?.context,
508
+ nullability: this._nullability,
467
509
  ${isTransaction ? "dbCall" : ""}
468
510
  });
469
511
  }`;
470
512
  }
513
+ function mapKindToAction(kind) {
514
+ if (kind === "getOne") {
515
+ return "findUnique";
516
+ }
517
+ if (kind === "getList") {
518
+ return "findMany";
519
+ }
520
+ if (kind === "getListPaginated") {
521
+ return "findManyPaginated";
522
+ }
523
+ if (kind === "postOne") {
524
+ return "create";
525
+ }
526
+ if (kind === "patchOne") {
527
+ return "update";
528
+ }
529
+ if (kind === "patchList") {
530
+ return "updateMany";
531
+ }
532
+ if (kind === "deleteOne") {
533
+ return "delete";
534
+ }
535
+ if (kind === "deleteList") {
536
+ return "deleteMany";
537
+ }
538
+ throw new Error(`Unhandled kind: ${kind}`);
539
+ }
471
540
  function getTypeReturnBaseName(table) {
472
541
  return "ReturnBase" + changeCase.pascalCase(table);
473
542
  }
@@ -1147,6 +1216,47 @@ async function getArtifactsSource(tables, includeMappedFields, specialCaseUuidCo
1147
1216
  return acc;
1148
1217
  }, {});
1149
1218
  const uniqueFields = await getUniqueColumns(table, specialCaseUuidColumn);
1219
+ let fields = tableMeta.map((t) => {
1220
+ const nullable = t.Null === "YES";
1221
+ const isEnum = t.Type.startsWith("enum");
1222
+ if (isEnum) {
1223
+ const values = getPropertyEnum(t.Type);
1224
+ if (values && nullable) {
1225
+ values.push(null);
1226
+ }
1227
+ return {
1228
+ kind: "enum",
1229
+ values,
1230
+ name: t.Field,
1231
+ nullable
1232
+ };
1233
+ }
1234
+ return {
1235
+ kind: "scalar",
1236
+ type: getBaseJSONType(t.Type),
1237
+ name: t.Field,
1238
+ nullable,
1239
+ hasDefaultValue: !!t.Default
1240
+ };
1241
+ });
1242
+ for (let x of _mappedFields) {
1243
+ fields.push({
1244
+ kind: "scalar",
1245
+ type: x.type,
1246
+ name: x.as,
1247
+ nullable: x.nullable,
1248
+ // TODO
1249
+ hasDefaultValue: false
1250
+ });
1251
+ }
1252
+ for (let x of relationInfo) {
1253
+ fields.push({
1254
+ kind: "object",
1255
+ type: x.table,
1256
+ name: x.name,
1257
+ isList: x.grabMany
1258
+ });
1259
+ }
1150
1260
  return {
1151
1261
  table,
1152
1262
  primaryKey,
@@ -1155,7 +1265,8 @@ async function getArtifactsSource(tables, includeMappedFields, specialCaseUuidCo
1155
1265
  mappedFields,
1156
1266
  uniqueFields,
1157
1267
  dateTimeFields,
1158
- dateTimeFieldsCount: Object.keys(dateTimeFields).length
1268
+ dateTimeFieldsCount: Object.keys(dateTimeFields).length,
1269
+ fields
1159
1270
  };
1160
1271
  }));
1161
1272
  const artifacts = tableMetaList.reduce((acc, x) => {
@@ -0,0 +1,11 @@
1
+ import { type IArtifacts } from "./runtime/IRuntime";
2
+ export declare function getFakeData(input: {
3
+ model: string;
4
+ select?: unknown[];
5
+ isList: boolean;
6
+ artifacts: IArtifacts;
7
+ }): {
8
+ [k: string]: unknown;
9
+ } | {
10
+ [k: string]: unknown;
11
+ }[];
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFakeData = void 0;
4
+ function getFakeData(input) {
5
+ const { model, select, isList, artifacts } = input;
6
+ const tableMeta = artifacts[model];
7
+ if (tableMeta === void 0) {
8
+ throw new Error(`Model ${model} not found.`);
9
+ }
10
+ const { fields } = tableMeta;
11
+ let data = {};
12
+ if (select == null) {
13
+ data = fields.reduce((acc, x) => {
14
+ if (x.kind === "scalar") {
15
+ acc[x.name] = getValue(x.type);
16
+ return acc;
17
+ }
18
+ else if (x.kind === "enum") {
19
+ acc[x.name] = x.values[0];
20
+ return acc;
21
+ }
22
+ return acc;
23
+ }, data);
24
+ }
25
+ else {
26
+ for (let x of select) {
27
+ if (!(typeof x === "string" || (typeof x === "object" && x != null))) {
28
+ throw new Error(`Invalid select: ${x}`);
29
+ }
30
+ const name = typeof x === "string" ? x : x.name;
31
+ const fieldName = x.as ?? name;
32
+ const field = fields.find((x) => x.name === name);
33
+ if (field == null) {
34
+ throw new Error(`Field not found: ${name}`);
35
+ }
36
+ if (field.kind === "scalar") {
37
+ data[fieldName] = getValue(field.type);
38
+ }
39
+ else if (field.kind === "enum") {
40
+ data[fieldName] = field.values[0];
41
+ }
42
+ else if (field.kind === "object") {
43
+ if (!(typeof x === "object" && x != null)) {
44
+ throw new Error(`Invalid select: ${x}`);
45
+ }
46
+ data[fieldName] = getFakeData({
47
+ model: field.type,
48
+ select: x.fields,
49
+ artifacts,
50
+ isList: field.isList
51
+ });
52
+ }
53
+ else {
54
+ throw new Error(`Unhandled kind: ${field?.kind}`);
55
+ }
56
+ }
57
+ }
58
+ if (isList) {
59
+ return [data];
60
+ }
61
+ return data;
62
+ }
63
+ exports.getFakeData = getFakeData;
64
+ function getValue(type) {
65
+ if (type === "boolean") {
66
+ return true;
67
+ }
68
+ if (type === "number") {
69
+ return 54.9434;
70
+ }
71
+ if (type === "integer") {
72
+ return 4;
73
+ }
74
+ if (type === "string") {
75
+ return "foo";
76
+ }
77
+ throw new Error(`Unhandled type: ${type}`);
78
+ }
@@ -0,0 +1 @@
1
+ export declare function getIsList(operation: string): boolean;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIsList = void 0;
4
+ function getIsList(operation) {
5
+ return operation.endsWith("Paginated") || operation.endsWith("Many");
6
+ }
7
+ exports.getIsList = getIsList;
package/dist/index.d.ts CHANGED
@@ -2,3 +2,5 @@ export { generate } from "./generation/generate";
2
2
  export { SDKNotFoundError } from "./runtime/lib/SDKNotFoundError";
3
3
  export { SDKBadWhereError } from "./runtime/lib/SDKBadWhereError";
4
4
  export { traverseFieldArgs } from "./traverseFieldArgs";
5
+ export { getFakeData } from "./getFakeData";
6
+ export { getIsList } from "./getIsList";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseFieldArgs = exports.SDKBadWhereError = exports.SDKNotFoundError = exports.generate = void 0;
3
+ exports.getIsList = exports.getFakeData = exports.traverseFieldArgs = exports.SDKBadWhereError = exports.SDKNotFoundError = exports.generate = void 0;
4
4
  var generate_1 = require("./generation/generate");
5
5
  Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_1.generate; } });
6
6
  var SDKNotFoundError_1 = require("./runtime/lib/SDKNotFoundError");
@@ -9,3 +9,7 @@ var SDKBadWhereError_1 = require("./runtime/lib/SDKBadWhereError");
9
9
  Object.defineProperty(exports, "SDKBadWhereError", { enumerable: true, get: function () { return SDKBadWhereError_1.SDKBadWhereError; } });
10
10
  var traverseFieldArgs_1 = require("./traverseFieldArgs");
11
11
  Object.defineProperty(exports, "traverseFieldArgs", { enumerable: true, get: function () { return traverseFieldArgs_1.traverseFieldArgs; } });
12
+ var getFakeData_1 = require("./getFakeData");
13
+ Object.defineProperty(exports, "getFakeData", { enumerable: true, get: function () { return getFakeData_1.getFakeData; } });
14
+ var getIsList_1 = require("./getIsList");
15
+ Object.defineProperty(exports, "getIsList", { enumerable: true, get: function () { return getIsList_1.getIsList; } });
@@ -9,9 +9,10 @@ export interface IRuntime {
9
9
  isolationLevel?: "READ UNCOMMITTED" | "READ COMMITTED" | "REPEATABLE READ" | "SERIALIZABLE";
10
10
  }): Promise<TBeginTransactionResult>;
11
11
  }
12
+ export declare type TAction = "findUnique" | "findMany" | "findManyPaginated" | "create" | "update" | "updateMany" | "delete" | "deleteMany";
12
13
  export declare type TResolveParams = {
13
14
  resource: string;
14
- action: "findUnique" | "findMany" | "findManyPaginated" | "create" | "update" | "updateMany" | "delete" | "deleteMany";
15
+ action: TAction;
15
16
  args?: IArgs | undefined;
16
17
  data?: any;
17
18
  artifacts: IArtifacts;
@@ -19,6 +20,7 @@ export declare type TResolveParams = {
19
20
  context?: TContext | undefined;
20
21
  skipCache?: boolean;
21
22
  dbCall?: TDbCall;
23
+ nullability?: unknown;
22
24
  };
23
25
  export declare type TContext = {
24
26
  [k: string]: any;
@@ -159,6 +161,25 @@ export declare type IArtifacts = {
159
161
  [k: string]: boolean;
160
162
  };
161
163
  dateTimeFieldsCount: number;
164
+ fields: TField[];
162
165
  };
163
166
  };
167
+ export declare type TFieldType = "string" | "boolean" | "number" | "integer";
168
+ export declare type TField = {
169
+ kind: "scalar";
170
+ type: TFieldType;
171
+ name: string;
172
+ nullable: boolean;
173
+ hasDefaultValue: boolean;
174
+ } | {
175
+ kind: "enum";
176
+ values: unknown[];
177
+ name: string;
178
+ nullable: boolean;
179
+ } | {
180
+ kind: "object";
181
+ type: string;
182
+ name: string;
183
+ isList: boolean;
184
+ };
164
185
  export {};
@@ -39,15 +39,42 @@ async function resolve(input, dbCall, formatQuery, beginTransaction, dialect, mi
39
39
  };
40
40
  return resource.runInAsyncScope(() => consumer(params));
41
41
  }
42
+ if (input?.nullability) {
43
+ return _nullResolve(input);
44
+ }
42
45
  return _resolve(input, dbCall, formatQuery, beginTransaction, dialect, context, cache);
43
46
  }
44
47
  exports.resolve = resolve;
48
+ async function _nullResolve(input) {
49
+ const { nullability } = input;
50
+ if (typeof nullability !== "object" || nullability == null) {
51
+ throw new Error("Invalid nullability");
52
+ }
53
+ const table = input.resource;
54
+ const tableConfig = nullability[table];
55
+ if (tableConfig == null) {
56
+ throw new Error(`Response not configured for \`${table}\`.`);
57
+ }
58
+ const { action } = input;
59
+ const responseFn = tableConfig[action];
60
+ if (responseFn == null) {
61
+ throw new Error(`Response not configured for \`${action}\`, \`${table}\`.`);
62
+ }
63
+ if (typeof responseFn !== "function") {
64
+ throw new Error(`Invalid configured response for \`${action}\`, \`${table}\`: not a function.`);
65
+ }
66
+ return responseFn({
67
+ operation: action,
68
+ model: table,
69
+ args: { select: input.fields, where: input.args?.$where }
70
+ });
71
+ }
45
72
  function _resolve(input, dbCall, formatQuery, beginTransaction, dialect, context, cache) {
46
73
  switch (input.action) {
47
74
  case "findMany":
48
- return cache && !input.skipCache ?
49
- getCached(input, dbCall, formatQuery, dialect, cache) :
50
- getData(input, dbCall, formatQuery, dialect);
75
+ return cache && !input.skipCache
76
+ ? getCached(input, dbCall, formatQuery, dialect, cache)
77
+ : getData(input, dbCall, formatQuery, dialect);
51
78
  case "findUnique":
52
79
  case "findManyPaginated":
53
80
  return getData(input, dbCall, formatQuery, dialect);
@@ -116,7 +143,7 @@ async function getData(input, dbCall, formatQuery, dialect) {
116
143
  rowWithMatchingCursor = await dbCall(formatQuery("SELECT * FROM ?? WHERE ?? = ?", [
117
144
  input.resource,
118
145
  primaryKey,
119
- (0, cursor_1.decodeCursor)(cursor),
146
+ (0, cursor_1.decodeCursor)(cursor)
120
147
  ])).then((xs) => xs[0]);
121
148
  if (rowWithMatchingCursor == null) {
122
149
  throw new Error(`Invalid cursor: ${cursor}`);
@@ -140,9 +167,9 @@ async function getData(input, dbCall, formatQuery, dialect) {
140
167
  dialect === "mssql" && paginationType === "limit-offset"
141
168
  ? {
142
169
  orderBy: (0, getOrderBy_1.getOrderBy)(input.args, primaryKey)?.orderBy ?? [
143
- { column: primaryKey, direction: "asc" },
170
+ { column: primaryKey, direction: "asc" }
144
171
  ],
145
- flip: false,
172
+ flip: false
146
173
  }
147
174
  : action === "findManyPaginated"
148
175
  ? (0, getOrderBy_1.getOrderBy)(input.args, primaryKey)
@@ -160,7 +187,7 @@ async function getData(input, dbCall, formatQuery, dialect) {
160
187
  orderBy: orderByListPaginatedRootResult?.orderBy,
161
188
  rowWithMatchingCursor,
162
189
  dialect,
163
- grabMany,
190
+ grabMany
164
191
  });
165
192
  const options = { dialect };
166
193
  let { sql, shapeDefinition } = await (0, util_1.compileSqlAST)(sqlAST, context, options);
@@ -243,7 +270,7 @@ async function getData(input, dbCall, formatQuery, dialect) {
243
270
  // We don't want the where clause to include cursor-related stuff
244
271
  rowWithMatchingCursor: null,
245
272
  dialect,
246
- grabMany: true,
273
+ grabMany: true
247
274
  });
248
275
  // Because orderBy doesn't matter for total count.
249
276
  // getOrderBy adds an element if paginating, so deleting args.$orderBy
@@ -353,9 +380,9 @@ function wrapListPaginationCursor(data, args, flip, cb, primaryKey, totalCount)
353
380
  hasNextPage,
354
381
  startCursor,
355
382
  endCursor,
356
- totalCount,
383
+ totalCount
357
384
  },
358
- results: data,
385
+ results: data
359
386
  };
360
387
  }
361
388
  async function getTotalCount(sqlASTTotalCount, dbCall, context, options) {
@@ -366,8 +393,8 @@ async function getTotalCount(sqlASTTotalCount, dbCall, context, options) {
366
393
  type: "expression",
367
394
  sqlExpr: () => "COUNT(*)",
368
395
  fieldName: fieldNameTotalCount,
369
- as: fieldNameTotalCount,
370
- },
396
+ as: fieldNameTotalCount
397
+ }
371
398
  ];
372
399
  const { sql: sqlTotalCount } = await (0, util_1.compileSqlAST)(sqlASTTotalCount, context, options);
373
400
  const totalCount = await dbCall(sqlTotalCount).then((xs) => xs[0][fieldNameTotalCount]);
@@ -508,7 +535,7 @@ function getCreateTree(data, table, referencedKey, specialCaseUuidColumn, dialec
508
535
  referencedKey,
509
536
  columns: [],
510
537
  values: [],
511
- children: [],
538
+ children: []
512
539
  };
513
540
  for (let i = 0; i < data.length; i++) {
514
541
  let d = data[i];
@@ -641,7 +668,9 @@ async function updateMany(input, dbCall, formatQuery, dialect, cache) {
641
668
  }
642
669
  if (cache)
643
670
  try {
644
- const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [input.resource]);
671
+ const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [
672
+ input.resource
673
+ ]);
645
674
  const matches = await dbCall(query);
646
675
  const uuids = matches.map((x) => x.uuid);
647
676
  cache.purge(...uuids);
@@ -681,7 +710,7 @@ async function deleteOne(input, dbCall, formatQuery, dialect, cache) {
681
710
  const current = await dbCall(formatQuery("SELECT * FROM ?? WHERE ?? = ?", [
682
711
  input.resource,
683
712
  findOne.key,
684
- findOne.value,
713
+ findOne.value
685
714
  ])).then((xs) => xs[0]);
686
715
  if (current == null) {
687
716
  throw new SDKNotFoundError_1.SDKNotFoundError();
@@ -691,7 +720,7 @@ async function deleteOne(input, dbCall, formatQuery, dialect, cache) {
691
720
  await dbCall(formatQuery("DELETE FROM ?? WHERE ?? = ?", [
692
721
  input.resource,
693
722
  findOne.key,
694
- findOne.value,
723
+ findOne.value
695
724
  ]));
696
725
  return true;
697
726
  }
@@ -703,7 +732,9 @@ async function deleteMany(input, dbCall, formatQuery, dialect, cache) {
703
732
  }
704
733
  if (cache)
705
734
  try {
706
- const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [input.resource]);
735
+ const query = formatQuery(`SELECT uuid FROM ?? WHERE ${where}`, [
736
+ input.resource
737
+ ]);
707
738
  const matches = await dbCall(query);
708
739
  const uuids = matches.map((x) => x.uuid);
709
740
  cache.purge(...uuids);
@@ -752,7 +783,7 @@ async function mapMappedFields(artifactsForTable, data, dbCall, formatQuery) {
752
783
  mappedField.referencedKey,
753
784
  mappedField.referencedTable,
754
785
  mappedField.name,
755
- w,
786
+ w
756
787
  ])).then((xs) => xs[0]?.[mappedField.referencedKey]);
757
788
  if (result == null) {
758
789
  throw new SDKNotFoundError_1.SDKNotFoundError();
@@ -766,7 +797,7 @@ async function mapMappedFields(artifactsForTable, data, dbCall, formatQuery) {
766
797
  mappedField.referencedKey,
767
798
  mappedField.referencedTable,
768
799
  mappedField.name,
769
- v,
800
+ v
770
801
  ])).then((xs) => xs[0]?.[mappedField.referencedKey]);
771
802
  if (result == null) {
772
803
  throw new SDKNotFoundError_1.SDKNotFoundError();
@@ -798,9 +829,7 @@ function removeExtraKeys(data, fields) {
798
829
  fieldKeys.push(x.as ?? x.name);
799
830
  }
800
831
  }
801
- const dataKeys = Array.isArray(data)
802
- ? Object.keys(data[0])
803
- : Object.keys(data);
832
+ const dataKeys = Array.isArray(data) ? Object.keys(data[0]) : Object.keys(data);
804
833
  const extraDataKeys = _.difference(dataKeys, fieldKeys);
805
834
  for (let k of extraDataKeys) {
806
835
  if (Array.isArray(data)) {
@@ -848,7 +877,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
848
877
  mappedField.referencedKey,
849
878
  mappedField.referencedTable,
850
879
  mappedField.name,
851
- v,
880
+ v
852
881
  ])).then((xs) => xs[0]?.[mappedField.referencedKey])));
853
882
  if (newVal.some((x) => x == null)) {
854
883
  const index = newVal.findIndex((x) => x == null);
@@ -867,7 +896,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
867
896
  mappedField.referencedKey,
868
897
  mappedField.referencedTable,
869
898
  mappedField.name,
870
- where,
899
+ where
871
900
  ])).then((xs) => xs[0]?.[mappedField.referencedKey]);
872
901
  if (newVal == null) {
873
902
  throw new SDKBadWhereError_1.SDKBadWhereError(getPrepareWhereNotFoundMessage(mappedField, where));
@@ -890,7 +919,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
890
919
  mappedField.referencedKey,
891
920
  mappedField.referencedTable,
892
921
  mappedField.name,
893
- v,
922
+ v
894
923
  ])).then((xs) => xs[0]?.[mappedField.referencedKey])));
895
924
  if (newVal.some((x) => x == null)) {
896
925
  const index = newVal.findIndex((x) => x == null);
@@ -909,7 +938,7 @@ async function _prepareWhere(artifacts, table, data, dbCall, formatQuery) {
909
938
  mappedField.referencedKey,
910
939
  mappedField.referencedTable,
911
940
  mappedField.name,
912
- where,
941
+ where
913
942
  ])).then((xs) => xs[0]?.[mappedField.referencedKey]);
914
943
  if (newVal == null) {
915
944
  throw new SDKBadWhereError_1.SDKBadWhereError(getPrepareWhereNotFoundMessage(mappedField, where));
@@ -941,7 +970,7 @@ const ops = [
941
970
  "$like",
942
971
  "$nlike",
943
972
  "$btwn",
944
- "$nbtwn",
973
+ "$nbtwn"
945
974
  ];
946
975
  async function traverseWhere(where, cb) {
947
976
  return await _traverseWhere(cb, where, "", where);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technicity/data-service-generator",
3
- "version": "0.11.6",
3
+ "version": "0.12.0",
4
4
  "main": "./dist/index.js",
5
5
  "files": [
6
6
  "dist"