@technicity/data-service-generator 0.11.4 → 0.11.6

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.
@@ -25,7 +25,7 @@ const MySQL_1 = require("../runtime/lib/MySQL");
25
25
  let query = undefined;
26
26
  let dialect = "mysql";
27
27
  const json2TsOpts = {
28
- bannerComment: "",
28
+ bannerComment: ""
29
29
  };
30
30
  async function generate(input) {
31
31
  if (input.tables != null && input.excludeTables != null) {
@@ -57,7 +57,7 @@ async function generate(input) {
57
57
  getPatchOneData(x, specialCaseUuidColumn, includeMappedFields),
58
58
  getPatchListData(x),
59
59
  getDeleteOneData(x),
60
- getDeleteListData(x),
60
+ getDeleteListData(x)
61
61
  ]));
62
62
  const artifactsSource = await getArtifactsSource(tables, includeMappedFields, specialCaseUuidColumn);
63
63
  const sdkSource = await getSDKSource(data, specialCaseUuidColumn, supplementClientOpts);
@@ -70,9 +70,9 @@ async function generate(input) {
70
70
  moduleResolution: "node",
71
71
  target: "es2020",
72
72
  declaration: true,
73
- outDir: "./sdk-ts",
73
+ outDir: "./sdk-ts"
74
74
  },
75
- include: [sdkFilename, artifactsFilename, IRuntimeFilename],
75
+ include: [sdkFilename, artifactsFilename, IRuntimeFilename]
76
76
  };
77
77
  const packageJSON = {
78
78
  name: "temp",
@@ -81,8 +81,8 @@ async function generate(input) {
81
81
  dependencies: require("../../package.json").dependencies,
82
82
  devDependencies: {
83
83
  "@types/node": require("../../package.json").devDependencies["@types/node"],
84
- typescript: require("../../package.json").devDependencies.typescript,
85
- },
84
+ typescript: require("../../package.json").devDependencies.typescript
85
+ }
86
86
  };
87
87
  const tmpDirPath = path.join(os.tmpdir(), `dsg-${(0, uuid_1.v4)()}`);
88
88
  fse.mkdirpSync(tmpDirPath);
@@ -145,7 +145,7 @@ function init(input) {
145
145
  password,
146
146
  host,
147
147
  port,
148
- database,
148
+ database
149
149
  });
150
150
  query = mysql.query.bind(mysql);
151
151
  }
@@ -155,7 +155,7 @@ function init(input) {
155
155
  user,
156
156
  password,
157
157
  port,
158
- database,
158
+ database
159
159
  });
160
160
  const poolConnect = pool.connect();
161
161
  async function runMSSQLQuery(...input) {
@@ -179,7 +179,7 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
179
179
  "typeReturnBaseName",
180
180
  "typeWhereName",
181
181
  "typeOrderByName",
182
- "typeDataName",
182
+ "typeDataName"
183
183
  ]) {
184
184
  const str = d[k];
185
185
  if (str) {
@@ -233,159 +233,241 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
233
233
  return this.runtime.$shutdown();
234
234
  }
235
235
 
236
+ async $startTransaction(input?: {
237
+ isolationLevel?:
238
+ | "READ UNCOMMITTED"
239
+ | "READ COMMITTED"
240
+ | "REPEATABLE READ"
241
+ | "SERIALIZABLE"
242
+ }) {
243
+ const { dbCall, commit, rollback } = await this.runtime.$startTransaction(input);
244
+ const runtime = this.runtime;
245
+ return {
246
+ $commit: commit,
247
+ $rollback: rollback,
248
+ ${(await Promise.all(input.flatMap(async (x) => {
249
+ if (x.kind === "getOne") {
250
+ const findOnes = await getFindOnes(x, specialCaseUuidColumn);
251
+ return getMethodSourceGetOne(x, findOnes, true);
252
+ }
253
+ if (x.kind === "getList") {
254
+ return getMethodSourceGetList(x, true);
255
+ }
256
+ if (x.kind === "getListPaginated") {
257
+ return getMethodSourceGetListPaginated(x, true);
258
+ }
259
+ if (x.kind === "postOne") {
260
+ return getMethodSourcePostOne(x, specialCaseUuidColumn, true);
261
+ }
262
+ if (x.kind === "patchOne") {
263
+ const findOnes = await getFindOnes(x, specialCaseUuidColumn);
264
+ return getMethodSourcePatchOne(x, findOnes, true);
265
+ }
266
+ if (x.kind === "patchList") {
267
+ return getMethodSourcePatchList(x, true);
268
+ }
269
+ if (x.kind === "deleteOne") {
270
+ const findOnes = await getFindOnes(x, specialCaseUuidColumn);
271
+ return getMethodSourceDeleteOne(x, findOnes, true);
272
+ }
273
+ if (x.kind === "deleteList") {
274
+ return getMethodSourceDeleteList(x, true);
275
+ }
276
+ }))).join(",\n")}
277
+ }
278
+ }
279
+
236
280
  ${(await Promise.all(input.flatMap(async (x) => {
237
- let findOnes = [];
238
- const primaryColumn = await getPrimaryColumn(x.table);
239
- const uniqueColumns = await getUniqueColumns(x.table, specialCaseUuidColumn);
240
- findOnes = findOnes
241
- .concat([primaryColumn])
242
- .concat(uniqueColumns)
243
- .map((x) => ({
244
- ...x,
245
- type: x.type === "integer" ? "number" : x.type,
246
- }));
247
281
  if (x.kind === "getOne") {
248
- return `async ${x.methodName}(
249
- param1: ${findOnes
250
- .map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
251
- .join(" | ")},
252
- param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, skipCache?: boolean, context?: TContext }
253
- ): Promise<${x.typeReturnBaseName}> {
254
- return this.runtime.resolve(
255
- {
256
- resource: "${x.table}",
257
- action: "findUnique",
258
- args: { $where: param1 },
259
- fields: param2?.fields,
260
- artifacts,
261
- context: param2?.context,
262
- skipCache: param2?.skipCache
263
- }
264
- );
265
- }`;
282
+ const findOnes = await getFindOnes(x, specialCaseUuidColumn);
283
+ return getMethodSourceGetOne(x, findOnes, false);
266
284
  }
267
285
  if (x.kind === "getList") {
268
- return `async ${x.methodName}(
269
- param1: { $where?: ${x.typeWhereName}, $orderBy?: ${x.typeOrderByName}, $limit?: number },
270
- param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, skipCache?: boolean, context?: TContext }
271
- ): Promise<Array<${x.typeReturnBaseName}>> {
272
- return this.runtime.resolve(
273
- {
274
- resource: "${x.table}",
275
- action: "findMany",
276
- args: param1,
277
- fields: param2?.fields,
278
- artifacts,
279
- context: param2?.context,
280
- skipCache: param2?.skipCache
281
- }
282
- );
283
- }`;
286
+ return getMethodSourceGetList(x, false);
284
287
  }
285
288
  if (x.kind === "getListPaginated") {
286
- return `async ${x.methodName}(
287
- param1: { $where?: ${x.typeWhereName}, $orderBy?: ${x.typeOrderByName}, $paginate: Paginate },
288
- param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, skipCache?: boolean, context?: TContext }
289
- ): Promise<ListPaginated<${x.typeReturnBaseName}>> {
290
- return this.runtime.resolve(
291
- {
292
- resource: "${x.table}",
293
- action: "findManyPaginated",
294
- args: param1,
295
- fields: param2?.fields,
296
- artifacts,
297
- context: param2?.context,
298
- skipCache: param2?.skipCache
299
- }
300
- );
301
- }`;
289
+ return getMethodSourceGetListPaginated(x, false);
302
290
  }
303
291
  if (x.kind === "postOne") {
304
- return `async ${x.methodName}(
305
- data: ${x.typeDataName},
306
- param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
307
- ): Promise<${x.typeReturnBaseName}> {
308
- return this.runtime.resolve({
309
- resource: "${x.table}",
310
- action: "create",
311
- data,
312
- artifacts,
313
- fields: param2?.fields,
314
- context: {...param2?.context, specialCaseUuidColumn: ${JSON.stringify(specialCaseUuidColumn)}}
315
- });
316
- }`;
292
+ return getMethodSourcePostOne(x, specialCaseUuidColumn, false);
317
293
  }
318
294
  if (x.kind === "patchOne") {
319
- return `async ${x.methodName}(
320
- param1: ${findOnes
321
- .map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
322
- .join(" | ")},
323
- data: ${x.typeDataName},
324
- param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
325
- ): Promise<${x.typeReturnBaseName}> {
326
- return this.runtime.resolve({
327
- resource: "${x.table}",
328
- action: "update",
329
- args: { $where: param1 },
330
- data,
331
- artifacts,
332
- fields: param2?.fields,
333
- context: param2?.context
334
- });
335
- }`;
295
+ const findOnes = await getFindOnes(x, specialCaseUuidColumn);
296
+ return getMethodSourcePatchOne(x, findOnes, false);
336
297
  }
337
298
  if (x.kind === "patchList") {
338
- return `async ${x.methodName}(
339
- param1: { $where?: ${x.typeWhereName} },
340
- data: ${x.typeDataName},
341
- param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
342
- ): Promise<Array<${x.typeReturnBaseName}>> {
343
- return this.runtime.resolve({
344
- resource: "${x.table}",
345
- action: "updateMany",
346
- args: param1,
347
- data,
348
- artifacts,
349
- fields: param2?.fields,
350
- context: param2?.context
351
- });
352
- }`;
299
+ return getMethodSourcePatchList(x, false);
353
300
  }
354
301
  if (x.kind === "deleteOne") {
355
- return `async ${x.methodName}(
356
- param1: ${findOnes
357
- .map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
358
- .join(" | ")},
359
- param2?: { correlationId?: string, context?: TContext }
360
- ): Promise<void> {
361
- await this.runtime.resolve({
362
- resource: "${x.table}",
363
- action: "delete",
364
- args: { $where: param1 },
365
- artifacts,
366
- context: param2?.context
367
- });
368
- }`;
302
+ const findOnes = await getFindOnes(x, specialCaseUuidColumn);
303
+ return getMethodSourceDeleteOne(x, findOnes, false);
369
304
  }
370
305
  if (x.kind === "deleteList") {
371
- return `async ${x.methodName}(
372
- param1: { $where?: ${x.typeWhereName} },
373
- param2?: { correlationId?: string, context?: TContext }
374
- ): Promise<void> {
375
- await this.runtime.resolve({
376
- resource: "${x.table}",
377
- action: "deleteMany",
378
- args: param1,
379
- artifacts,
380
- context: param2?.context
381
- });
382
- }`;
306
+ return getMethodSourceDeleteList(x, false);
383
307
  }
384
308
  }))).join("\n\n")}
385
309
  }
386
310
  `;
387
311
  return prettier.format(src, { parser: "typescript" });
388
312
  }
313
+ async function getFindOnes(x, specialCaseUuidColumn) {
314
+ let findOnes = [];
315
+ const primaryColumn = await getPrimaryColumn(x.table);
316
+ const uniqueColumns = await getUniqueColumns(x.table, specialCaseUuidColumn);
317
+ findOnes = findOnes
318
+ .concat([primaryColumn])
319
+ .concat(uniqueColumns)
320
+ .map((x) => ({
321
+ ...x,
322
+ type: x.type === "integer" ? "number" : x.type
323
+ }));
324
+ return findOnes;
325
+ }
326
+ function getMethodSourceGetOne(x, findOnes, isTransaction) {
327
+ return `async ${x.methodName}(
328
+ param1: ${findOnes
329
+ .map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
330
+ .join(" | ")},
331
+ param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, skipCache?: boolean, context?: TContext }
332
+ ): Promise<${x.typeReturnBaseName}> {
333
+ return ${isTransaction ? "runtime" : "this.runtime"}.resolve(
334
+ {
335
+ resource: "${x.table}",
336
+ action: "findUnique",
337
+ args: { $where: param1 },
338
+ fields: param2?.fields,
339
+ artifacts,
340
+ context: param2?.context,
341
+ skipCache: param2?.skipCache,
342
+ ${isTransaction ? "dbCall" : ""}
343
+ }
344
+ );
345
+ }`;
346
+ }
347
+ function getMethodSourceGetList(x, isTransaction) {
348
+ return `async ${x.methodName}(
349
+ param1: { $where?: ${x.typeWhereName}, $orderBy?: ${x.typeOrderByName}, $limit?: number },
350
+ param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, skipCache?: boolean, context?: TContext }
351
+ ): Promise<Array<${x.typeReturnBaseName}>> {
352
+ return ${isTransaction ? "runtime" : "this.runtime"}.resolve(
353
+ {
354
+ resource: "${x.table}",
355
+ action: "findMany",
356
+ args: param1,
357
+ fields: param2?.fields,
358
+ artifacts,
359
+ context: param2?.context,
360
+ skipCache: param2?.skipCache,
361
+ ${isTransaction ? "dbCall" : ""}
362
+ }
363
+ );
364
+ }`;
365
+ }
366
+ function getMethodSourceGetListPaginated(x, isTransaction) {
367
+ return `async ${x.methodName}(
368
+ param1: { $where?: ${x.typeWhereName}, $orderBy?: ${x.typeOrderByName}, $paginate: Paginate },
369
+ param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, skipCache?: boolean, context?: TContext }
370
+ ): Promise<ListPaginated<${x.typeReturnBaseName}>> {
371
+ return ${isTransaction ? "runtime" : "this.runtime"}.resolve(
372
+ {
373
+ resource: "${x.table}",
374
+ action: "findManyPaginated",
375
+ args: param1,
376
+ fields: param2?.fields,
377
+ artifacts,
378
+ context: param2?.context,
379
+ skipCache: param2?.skipCache,
380
+ ${isTransaction ? "dbCall" : ""}
381
+ }
382
+ );
383
+ }`;
384
+ }
385
+ function getMethodSourcePostOne(x, specialCaseUuidColumn, isTransaction) {
386
+ return `async ${x.methodName}(
387
+ data: ${x.typeDataName},
388
+ param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
389
+ ): Promise<${x.typeReturnBaseName}> {
390
+ return ${isTransaction ? "runtime" : "this.runtime"}.resolve({
391
+ resource: "${x.table}",
392
+ action: "create",
393
+ data,
394
+ artifacts,
395
+ fields: param2?.fields,
396
+ context: {...param2?.context, specialCaseUuidColumn: ${JSON.stringify(specialCaseUuidColumn)}},
397
+ ${isTransaction ? "dbCall" : ""}
398
+ });
399
+ }`;
400
+ }
401
+ function getMethodSourcePatchOne(x, findOnes, isTransaction) {
402
+ return `async ${x.methodName}(
403
+ param1: ${findOnes
404
+ .map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
405
+ .join(" | ")},
406
+ data: ${x.typeDataName},
407
+ param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
408
+ ): Promise<${x.typeReturnBaseName}> {
409
+ return ${isTransaction ? "runtime" : "this.runtime"}.resolve({
410
+ resource: "${x.table}",
411
+ action: "update",
412
+ args: { $where: param1 },
413
+ data,
414
+ artifacts,
415
+ fields: param2?.fields,
416
+ context: param2?.context,
417
+ ${isTransaction ? "dbCall" : ""}
418
+ });
419
+ }`;
420
+ }
421
+ function getMethodSourcePatchList(x, isTransaction) {
422
+ return `async ${x.methodName}(
423
+ param1: { $where?: ${x.typeWhereName} },
424
+ data: ${x.typeDataName},
425
+ param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
426
+ ): Promise<Array<${x.typeReturnBaseName}>> {
427
+ return ${isTransaction ? "runtime" : "this.runtime"}.resolve({
428
+ resource: "${x.table}",
429
+ action: "updateMany",
430
+ args: param1,
431
+ data,
432
+ artifacts,
433
+ fields: param2?.fields,
434
+ context: param2?.context,
435
+ ${isTransaction ? "dbCall" : ""}
436
+ });
437
+ }`;
438
+ }
439
+ function getMethodSourceDeleteOne(x, findOnes, isTransaction) {
440
+ return `async ${x.methodName}(
441
+ param1: ${findOnes
442
+ .map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
443
+ .join(" | ")},
444
+ param2?: { correlationId?: string, context?: TContext }
445
+ ): Promise<void> {
446
+ await ${isTransaction ? "runtime" : "this.runtime"}.resolve({
447
+ resource: "${x.table}",
448
+ action: "delete",
449
+ args: { $where: param1 },
450
+ artifacts,
451
+ context: param2?.context,
452
+ ${isTransaction ? "dbCall" : ""}
453
+ });
454
+ }`;
455
+ }
456
+ function getMethodSourceDeleteList(x, isTransaction) {
457
+ return `async ${x.methodName}(
458
+ param1: { $where?: ${x.typeWhereName} },
459
+ param2?: { correlationId?: string, context?: TContext }
460
+ ): Promise<void> {
461
+ await ${isTransaction ? "runtime" : "this.runtime"}.resolve({
462
+ resource: "${x.table}",
463
+ action: "deleteMany",
464
+ args: param1,
465
+ artifacts,
466
+ context: param2?.context,
467
+ ${isTransaction ? "dbCall" : ""}
468
+ });
469
+ }`;
470
+ }
389
471
  function getTypeReturnBaseName(table) {
390
472
  return "ReturnBase" + changeCase.pascalCase(table);
391
473
  }
@@ -411,7 +493,7 @@ async function getGetOneData(table, includeMappedFields) {
411
493
  typeFields: await getTypeFields(table, typeFieldsName, includeMappedFields),
412
494
  typeFieldsName,
413
495
  typeReturnBase: await getTypeReturnBase(table, typeReturnBaseName, includeMappedFields),
414
- typeReturnBaseName,
496
+ typeReturnBaseName
415
497
  };
416
498
  }
417
499
  async function getGetListData(table) {
@@ -430,7 +512,7 @@ async function getGetListData(table) {
430
512
  typeWhere,
431
513
  typeWhereName,
432
514
  typeOrderBy,
433
- typeOrderByName,
515
+ typeOrderByName
434
516
  };
435
517
  }
436
518
  async function getGetListPaginatedData(table) {
@@ -445,7 +527,7 @@ async function getGetListPaginatedData(table) {
445
527
  typeFieldsName,
446
528
  typeReturnBaseName,
447
529
  typeWhereName,
448
- typeOrderByName,
530
+ typeOrderByName
449
531
  };
450
532
  }
451
533
  async function getPostOneData(table, specialCaseUuidColumn, includeMappedFields) {
@@ -459,7 +541,7 @@ async function getPostOneData(table, specialCaseUuidColumn, includeMappedFields)
459
541
  typeFieldsName,
460
542
  typeReturnBaseName,
461
543
  typeData: await getTypeDataPost(table, typeDataName, specialCaseUuidColumn, includeMappedFields),
462
- typeDataName,
544
+ typeDataName
463
545
  };
464
546
  }
465
547
  async function getPatchOneData(table, specialCaseUuidColumn, includeMappedFields) {
@@ -473,7 +555,7 @@ async function getPatchOneData(table, specialCaseUuidColumn, includeMappedFields
473
555
  typeFieldsName,
474
556
  typeReturnBaseName,
475
557
  typeData: await getTypeDataPatch(table, typeDataName, specialCaseUuidColumn, includeMappedFields),
476
- typeDataName,
558
+ typeDataName
477
559
  };
478
560
  }
479
561
  async function getPatchListData(table) {
@@ -488,14 +570,14 @@ async function getPatchListData(table) {
488
570
  typeFieldsName,
489
571
  typeReturnBaseName,
490
572
  typeWhereName,
491
- typeDataName,
573
+ typeDataName
492
574
  };
493
575
  }
494
576
  function getDeleteOneData(table) {
495
577
  return {
496
578
  kind: "deleteOne",
497
579
  table,
498
- methodName: "delete" + changeCase.pascalCase(table),
580
+ methodName: "delete" + changeCase.pascalCase(table)
499
581
  };
500
582
  }
501
583
  function getDeleteListData(table) {
@@ -504,7 +586,7 @@ function getDeleteListData(table) {
504
586
  kind: "deleteList",
505
587
  table,
506
588
  methodName: "delete" + changeCase.pascalCase(table) + "List",
507
- typeWhereName,
589
+ typeWhereName
508
590
  };
509
591
  }
510
592
  async function getTypeWhere(table, name) {
@@ -516,11 +598,11 @@ async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMapped
516
598
  const tableMeta = (await getTableMeta(table)).filter((x) => x.Field !== primaryColumn.name);
517
599
  const nullable = tableMeta.reduce((acc, m) => ({
518
600
  ...acc,
519
- [m.Field]: m.Null === "YES" ? true : false,
601
+ [m.Field]: m.Null === "YES" ? true : false
520
602
  }), {});
521
603
  const hasDefault = tableMeta.reduce((acc, m) => ({
522
604
  ...acc,
523
- [m.Field]: m.Default == null ? false : true,
605
+ [m.Field]: m.Default == null ? false : true
524
606
  }), {});
525
607
  let properties = getJSONSchemaObjProperties(tableMeta);
526
608
  let notRequiredList = [];
@@ -533,7 +615,7 @@ async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMapped
533
615
  ...mappedFields.reduce((acc, v) => {
534
616
  acc[v.as] = { type: getJSONTypes(v.type, v.nullable) };
535
617
  return acc;
536
- }, {}),
618
+ }, {})
537
619
  };
538
620
  notRequiredList = mappedFields.flatMap((x) => [x.as, x.foreignKey]);
539
621
  for (let r of oneToManyRelations) {
@@ -548,9 +630,7 @@ async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMapped
548
630
  ...oneToManyRelations.reduce((acc, v) => {
549
631
  let tsType = getTypeDataPostName(v.table);
550
632
  const mappedFields = mappedFieldsMap.get(v.table);
551
- if (includeMappedFields &&
552
- mappedFields != null &&
553
- mappedFields.length > 0) {
633
+ if (includeMappedFields && mappedFields != null && mappedFields.length > 0) {
554
634
  tsType = `Omit<${tsType}, ${mappedFields
555
635
  .map((x) => JSON.stringify(x.as))
556
636
  .join(" | ")}>`;
@@ -558,21 +638,19 @@ async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMapped
558
638
  tsType = `{$create: ${tsType}[]}`;
559
639
  acc[v.name] = { tsType };
560
640
  return acc;
561
- }, {}),
641
+ }, {})
562
642
  },
563
643
  additionalProperties: false,
564
644
  required: Object.keys(properties)
565
645
  .filter(
566
646
  // `uuid` should not be required
567
- (x) => !specialCaseUuidColumn || uuidColumn == null
568
- ? true
569
- : x !== uuidColumn.name)
647
+ (x) => !specialCaseUuidColumn || uuidColumn == null ? true : x !== uuidColumn.name)
570
648
  .filter(
571
649
  // Required if column is non-nullable and has no default.
572
650
  (x) => !nullable[x] && !hasDefault[x])
573
651
  // Instead of doing a union with all possible permutations of UUID and IDs,
574
652
  // for simplicity, just make both not required for now.
575
- .filter((x) => !notRequiredList.includes(x)),
653
+ .filter((x) => !notRequiredList.includes(x))
576
654
  };
577
655
  let type = await (0, json_schema_to_typescript_1.compile)(jsonSchema, name, json2TsOpts);
578
656
  const imports = _.uniq(oneToManyRelations
@@ -601,13 +679,13 @@ async function getTypeDataPatch(table, name, specialCaseUuidColumn, includeMappe
601
679
  const type = unwrapJSONType(properties[key].type);
602
680
  if (type === "string") {
603
681
  properties[key] = {
604
- oneOf: [properties[key], { tsType: "TUpdateOperationsString" }],
682
+ oneOf: [properties[key], { tsType: "TUpdateOperationsString" }]
605
683
  };
606
684
  mustImportTUpdateOperationsString = true;
607
685
  }
608
686
  else if (type === "number" || type === "integer") {
609
687
  properties[key] = {
610
- oneOf: [properties[key], { tsType: "TUpdateOperationsNumber" }],
688
+ oneOf: [properties[key], { tsType: "TUpdateOperationsNumber" }]
611
689
  };
612
690
  mustImportTUpdateOperationsNumber = true;
613
691
  }
@@ -619,14 +697,14 @@ async function getTypeDataPatch(table, name, specialCaseUuidColumn, includeMappe
619
697
  ...mappedFields.reduce((acc, v) => {
620
698
  acc[v.as] = { type: getJSONTypes(v.type, v.nullable) };
621
699
  return acc;
622
- }, {}),
700
+ }, {})
623
701
  };
624
702
  }
625
703
  const jsonSchema = {
626
704
  type: "object",
627
705
  properties,
628
706
  additionalProperties: false,
629
- required: [],
707
+ required: []
630
708
  };
631
709
  let type = await (0, json_schema_to_typescript_1.compile)(jsonSchema, name, json2TsOpts);
632
710
  if (mustImportTUpdateOperationsString || mustImportTUpdateOperationsNumber) {
@@ -669,7 +747,7 @@ async function getMappedFields(table) {
669
747
  name: "uuid",
670
748
  // Replace `Id` with `Uuid`
671
749
  as: x.foreignKey.slice(0, -2) + "Uuid",
672
- type: getBaseJSONType(uuidColumn.Type),
750
+ type: getBaseJSONType(uuidColumn.Type)
673
751
  });
674
752
  }
675
753
  return out;
@@ -688,52 +766,52 @@ async function getJSONSchemaWhere(table) {
688
766
  {
689
767
  type: "object",
690
768
  properties: { $eq: v },
691
- additionalProperties: false,
769
+ additionalProperties: false
692
770
  },
693
771
  {
694
772
  type: "object",
695
773
  properties: { $neq: v },
696
- additionalProperties: false,
774
+ additionalProperties: false
697
775
  },
698
776
  {
699
777
  type: "object",
700
778
  properties: { $gt: v },
701
- additionalProperties: false,
779
+ additionalProperties: false
702
780
  },
703
781
  {
704
782
  type: "object",
705
783
  properties: { $gte: v },
706
- additionalProperties: false,
784
+ additionalProperties: false
707
785
  },
708
786
  {
709
787
  type: "object",
710
788
  properties: { $lt: v },
711
- additionalProperties: false,
789
+ additionalProperties: false
712
790
  },
713
791
  {
714
792
  type: "object",
715
793
  properties: { $lte: v },
716
- additionalProperties: false,
794
+ additionalProperties: false
717
795
  },
718
796
  {
719
797
  type: "object",
720
798
  properties: { $like: { type: "string", minLength: 1 } },
721
- additionalProperties: false,
799
+ additionalProperties: false
722
800
  },
723
801
  {
724
802
  type: "object",
725
803
  properties: { $nlike: { type: "string", minLength: 1 } },
726
- additionalProperties: false,
804
+ additionalProperties: false
727
805
  },
728
806
  {
729
807
  type: "object",
730
808
  properties: { $in: { type: "array", items: v } },
731
- additionalProperties: false,
809
+ additionalProperties: false
732
810
  },
733
811
  {
734
812
  type: "object",
735
813
  properties: { $nin: { type: "array", items: v } },
736
- additionalProperties: false,
814
+ additionalProperties: false
737
815
  },
738
816
  {
739
817
  type: "object",
@@ -743,10 +821,10 @@ async function getJSONSchemaWhere(table) {
743
821
  items: v,
744
822
  minItems: 2,
745
823
  maxItems: 2,
746
- uniqueItems: true,
747
- },
824
+ uniqueItems: true
825
+ }
748
826
  },
749
- additionalProperties: false,
827
+ additionalProperties: false
750
828
  },
751
829
  {
752
830
  type: "object",
@@ -756,15 +834,15 @@ async function getJSONSchemaWhere(table) {
756
834
  items: v,
757
835
  minItems: 2,
758
836
  maxItems: 2,
759
- uniqueItems: true,
760
- },
837
+ uniqueItems: true
838
+ }
761
839
  },
762
- additionalProperties: false,
763
- },
764
- ],
765
- },
840
+ additionalProperties: false
841
+ }
842
+ ]
843
+ }
766
844
  }), {}),
767
- additionalProperties: false,
845
+ additionalProperties: false
768
846
  },
769
847
  {
770
848
  type: "object",
@@ -772,17 +850,17 @@ async function getJSONSchemaWhere(table) {
772
850
  $and: {
773
851
  type: "array",
774
852
  items: {
775
- $ref: `#/definitions/${whereSchemaName}`,
853
+ $ref: `#/definitions/${whereSchemaName}`
776
854
  },
777
855
  // While it makes sense conceptually for $and to have
778
856
  // at least 2 items, in practice, $and could be
779
857
  // generated dynamically and could end up having
780
858
  // less than 2 items, so don't enforce minItems.
781
859
  // minItems: 2,
782
- additionalProperties: false,
783
- },
860
+ additionalProperties: false
861
+ }
784
862
  },
785
- additionalProperties: false,
863
+ additionalProperties: false
786
864
  },
787
865
  {
788
866
  type: "object",
@@ -790,19 +868,19 @@ async function getJSONSchemaWhere(table) {
790
868
  $or: {
791
869
  type: "array",
792
870
  items: {
793
- $ref: `#/definitions/${whereSchemaName}`,
871
+ $ref: `#/definitions/${whereSchemaName}`
794
872
  },
795
873
  // While it makes sense conceptually for $and to have
796
874
  // at least 2 items, in practice, $and could be
797
875
  // generated dynamically and could end up having
798
876
  // less than 2 items, so don't enforce minItems.
799
877
  // minItems: 2,
800
- additionalProperties: false,
801
- },
878
+ additionalProperties: false
879
+ }
802
880
  },
803
- additionalProperties: false,
804
- },
805
- ],
881
+ additionalProperties: false
882
+ }
883
+ ]
806
884
  };
807
885
  return {
808
886
  definitions: { [whereSchemaName]: defWhere },
@@ -819,12 +897,12 @@ async function getJSONSchemaWhere(table) {
819
897
  // generated dynamically and could end up having
820
898
  // less than 2 items, so don't enforce minItems.
821
899
  // minItems: 2,
822
- additionalProperties: false,
823
- },
900
+ additionalProperties: false
901
+ }
824
902
  },
825
- additionalProperties: false,
826
- })),
827
- ],
903
+ additionalProperties: false
904
+ }))
905
+ ]
828
906
  };
829
907
  }
830
908
  async function getTypeOrderBy(table, name) {
@@ -837,14 +915,14 @@ async function getJSONSchemaOrderBy(table, name) {
837
915
  type: "object",
838
916
  properties: { [k]: { enum: ["asc", "desc"] } },
839
917
  required: [k],
840
- additionalProperties: false,
841
- })),
918
+ additionalProperties: false
919
+ }))
842
920
  };
843
921
  const defName = `_${name}`;
844
922
  const _schema = { $ref: `#/definitions/${defName}` };
845
923
  return {
846
924
  definitions: { [defName]: def },
847
- oneOf: [_schema, { type: "array", items: _schema }],
925
+ oneOf: [_schema, { type: "array", items: _schema }]
848
926
  };
849
927
  }
850
928
  function getTypeTypesIndex(data) {
@@ -858,7 +936,7 @@ function getTypeTypesIndex(data) {
858
936
  "typeReturnBaseName",
859
937
  "typeWhereName",
860
938
  "typeOrderByName",
861
- "typeDataName",
939
+ "typeDataName"
862
940
  ]) {
863
941
  const str = d[k];
864
942
  if (str) {
@@ -870,7 +948,7 @@ function getTypeTypesIndex(data) {
870
948
  "Paginate",
871
949
  "ListPaginated",
872
950
  "TUpdateOperationsString",
873
- "TUpdateOperationsNumber",
951
+ "TUpdateOperationsNumber"
874
952
  ].join(",")} } from "./_shared";\n\n`;
875
953
  let arr = Array.from(set).sort();
876
954
  for (let x of arr) {
@@ -920,7 +998,7 @@ async function getTypeFields(table, name, includeMappedFields) {
920
998
  items: {
921
999
  anyOf: [
922
1000
  {
923
- enum: scalarKeys.concat(mappedFields.map((x) => x.as)),
1001
+ enum: scalarKeys.concat(mappedFields.map((x) => x.as))
924
1002
  },
925
1003
  ...relations.map((x) => {
926
1004
  const argsProperties = x.type === "many-to-many"
@@ -930,17 +1008,17 @@ async function getTypeFields(table, name, includeMappedFields) {
930
1008
  properties: {
931
1009
  [x.table]: { tsType: getTypeWhereName(x.table) },
932
1010
  [x.junctionTable]: {
933
- tsType: getTypeWhereName(x.junctionTable),
934
- },
1011
+ tsType: getTypeWhereName(x.junctionTable)
1012
+ }
935
1013
  },
936
- additionalProperties: false,
937
- },
1014
+ additionalProperties: false
1015
+ }
938
1016
  }
939
1017
  : { [keyWhere]: { tsType: getTypeWhereName(x.table) } };
940
1018
  // $orderBy only makes sense for a list
941
1019
  if (x.grabMany) {
942
1020
  argsProperties[keyOrderBy] = {
943
- tsType: getTypeOrderByName(x.table),
1021
+ tsType: getTypeOrderByName(x.table)
944
1022
  };
945
1023
  }
946
1024
  return {
@@ -952,21 +1030,19 @@ async function getTypeFields(table, name, includeMappedFields) {
952
1030
  args: {
953
1031
  type: "object",
954
1032
  properties: argsProperties,
955
- additionalProperties: false,
1033
+ additionalProperties: false
956
1034
  },
957
- transform: { tsType: `(x: any) => any` },
1035
+ transform: { tsType: `(x: any) => any` }
958
1036
  },
959
1037
  additionalProperties: false,
960
- required: ["name", "fields"],
1038
+ required: ["name", "fields"]
961
1039
  };
962
- }),
963
- ],
964
- },
1040
+ })
1041
+ ]
1042
+ }
965
1043
  };
966
1044
  let type = await (0, json_schema_to_typescript_1.compile)(jsonSchemaFields, name, json2TsOpts);
967
- const fieldImports = _.uniq(relations
968
- .filter((x) => x.table !== table)
969
- .map((x) => getTypeFieldsName(x.table)));
1045
+ const fieldImports = _.uniq(relations.filter((x) => x.table !== table).map((x) => getTypeFieldsName(x.table)));
970
1046
  const whereImports = _.uniq(relations.flatMap((x) => x.type === "many-to-many"
971
1047
  ? [getTypeWhereName(x.table), getTypeWhereName(x.junctionTable)]
972
1048
  : getTypeWhereName(x.table)));
@@ -1006,10 +1082,10 @@ async function getTypeReturnBase(table, name, includeMappedFields) {
1006
1082
  acc[key] = { tsType };
1007
1083
  }
1008
1084
  return acc;
1009
- }, {}),
1085
+ }, {})
1010
1086
  },
1011
1087
  // Because of aliases
1012
- additionalProperties: true,
1088
+ additionalProperties: true
1013
1089
  };
1014
1090
  let type = await (0, json_schema_to_typescript_1.compile)(jsonSchemaReturn, name, json2TsOpts);
1015
1091
  const imports = _.uniq(relations.map((x) => getTypeReturnBaseName(x.table)))
@@ -1040,7 +1116,7 @@ async function getArtifactsSource(tables, includeMappedFields, specialCaseUuidCo
1040
1116
  table: x.table,
1041
1117
  grabMany: x.grabMany,
1042
1118
  nullable: x.nullable,
1043
- relation: x.relation,
1119
+ relation: x.relation
1044
1120
  };
1045
1121
  }
1046
1122
  else {
@@ -1050,14 +1126,12 @@ async function getArtifactsSource(tables, includeMappedFields, specialCaseUuidCo
1050
1126
  table: x.table,
1051
1127
  junctionTable: x.junctionTable,
1052
1128
  grabMany: x.grabMany,
1053
- relations: x.relations,
1129
+ relations: x.relations
1054
1130
  };
1055
1131
  }
1056
1132
  return acc;
1057
1133
  }, {});
1058
- const _mappedFields = includeMappedFields
1059
- ? await getMappedFields(table)
1060
- : [];
1134
+ const _mappedFields = includeMappedFields ? await getMappedFields(table) : [];
1061
1135
  const mappedFields = _mappedFields.length === 0
1062
1136
  ? null
1063
1137
  : _mappedFields.reduce((acc, v) => {
@@ -1081,7 +1155,7 @@ async function getArtifactsSource(tables, includeMappedFields, specialCaseUuidCo
1081
1155
  mappedFields,
1082
1156
  uniqueFields,
1083
1157
  dateTimeFields,
1084
- dateTimeFieldsCount: Object.keys(dateTimeFields).length,
1158
+ dateTimeFieldsCount: Object.keys(dateTimeFields).length
1085
1159
  };
1086
1160
  }));
1087
1161
  const artifacts = tableMetaList.reduce((acc, x) => {
@@ -1108,7 +1182,7 @@ const getRelationInfo = _.memoize(async function getRelationInfo(table) {
1108
1182
  table: x.referencedTable,
1109
1183
  name,
1110
1184
  relation: x,
1111
- nullable: x.nullable,
1185
+ nullable: x.nullable
1112
1186
  };
1113
1187
  }));
1114
1188
  const relationsOneToManyDuplicates = (0, getDuplicates_1.getDuplicates)(relationsOneToMany.map((x) => x.referencedTable));
@@ -1131,7 +1205,7 @@ const getRelationInfo = _.memoize(async function getRelationInfo(table) {
1131
1205
  table: x.referencedTable,
1132
1206
  name,
1133
1207
  relation: x,
1134
- nullable: x.nullable,
1208
+ nullable: x.nullable
1135
1209
  };
1136
1210
  }));
1137
1211
  const relationsManyToMany = (await getJunctionTables()).reduce((acc, x) => {
@@ -1150,7 +1224,7 @@ const getRelationInfo = _.memoize(async function getRelationInfo(table) {
1150
1224
  name: changeCase.camelCase(dataForChildTable.referencedTable) + "List",
1151
1225
  // Ensure parent comes before child
1152
1226
  relations: [dataForParentTable, dataForChildTable],
1153
- grabMany: true,
1227
+ grabMany: true
1154
1228
  });
1155
1229
  return acc;
1156
1230
  }, []);
@@ -1171,7 +1245,7 @@ async function getJunctionTables() {
1171
1245
  // e.g. junction of Foo, Bar must be FooBar or BarFoo
1172
1246
  [
1173
1247
  relations[0].referencedTable + relations[1].referencedTable,
1174
- relations[1].referencedTable + relations[0].referencedTable,
1248
+ relations[1].referencedTable + relations[0].referencedTable
1175
1249
  ].includes(table)) {
1176
1250
  return { table, relations };
1177
1251
  }
@@ -1227,7 +1301,7 @@ const getRelationsManyToOne = _.memoize(async function getRelationsManyToOne(tab
1227
1301
  foreignKey: v.t1Field,
1228
1302
  referencedTable: v.t2,
1229
1303
  referencedKey: v.t2Field,
1230
- nullable: tableMeta.find((m) => m.Field === v.t1Field)?.Null === "YES",
1304
+ nullable: tableMeta.find((m) => m.Field === v.t1Field)?.Null === "YES"
1231
1305
  };
1232
1306
  })));
1233
1307
  return _.sortBy((x) => x.referencedTable, xs);
@@ -1276,7 +1350,7 @@ const getRelationsOneToMany = _.memoize(async function getRelationsOneToMany(tab
1276
1350
  referencedTable: v.t1,
1277
1351
  referencedKey: v.t1Field,
1278
1352
  // TODO? I think this is right, since it's one-to-many, so a list
1279
- nullable: false,
1353
+ nullable: false
1280
1354
  };
1281
1355
  })));
1282
1356
  return _.sortBy((x) => x.referencedKey, _.sortBy((x) => x.referencedTable, xs));
@@ -1291,7 +1365,7 @@ async function getPrimaryColumn(table) {
1291
1365
  return {
1292
1366
  name: column.Field,
1293
1367
  type: getBaseJSONType(column.Type),
1294
- nullable: column.Null === "YES",
1368
+ nullable: column.Null === "YES"
1295
1369
  };
1296
1370
  }
1297
1371
  async function getUniqueColumns(table, specialCaseUuidColumn) {
@@ -1303,7 +1377,7 @@ async function getUniqueColumns(table, specialCaseUuidColumn) {
1303
1377
  .map((x) => ({
1304
1378
  name: x.Field,
1305
1379
  type: getBaseJSONType(x.Type),
1306
- nullable: x.Null === "YES",
1380
+ nullable: x.Null === "YES"
1307
1381
  }));
1308
1382
  }
1309
1383
  async function getUuidColumn(table) {
@@ -1315,7 +1389,7 @@ async function getUuidColumn(table) {
1315
1389
  return {
1316
1390
  name: column.Field,
1317
1391
  type: column.Type,
1318
- nullable: column.Null === "YES",
1392
+ nullable: column.Null === "YES"
1319
1393
  };
1320
1394
  }
1321
1395
  const getTableMeta = _.memoize(async function getTableMeta(table) {
@@ -1359,7 +1433,7 @@ const getTableMeta = _.memoize(async function getTableMeta(table) {
1359
1433
  ? "UNI"
1360
1434
  : "",
1361
1435
  Null: x["IS_NULLABLE"],
1362
- Default: x["COLUMN_DEFAULT"],
1436
+ Default: x["COLUMN_DEFAULT"]
1363
1437
  };
1364
1438
  })));
1365
1439
  }
@@ -1378,7 +1452,7 @@ function getJSONSchemaObjProperties(tableMeta) {
1378
1452
  _enum.push(null);
1379
1453
  }
1380
1454
  acc[m.Field] = {
1381
- type: getJSONTypes(baseType, nullable),
1455
+ type: getJSONTypes(baseType, nullable)
1382
1456
  // maxLength:
1383
1457
  // baseType === "string" && format == null && isEnum == null
1384
1458
  // ? getPropertyMaxLength(m.Type)
@@ -1488,9 +1562,7 @@ function getPropertyEnum(sqlType) {
1488
1562
  return c;
1489
1563
  }
1490
1564
  function getPropertyFormat(sqlType) {
1491
- if (sqlType === "datetime" ||
1492
- sqlType === "datetime2" ||
1493
- sqlType === "timestamp") {
1565
+ if (sqlType === "datetime" || sqlType === "datetime2" || sqlType === "timestamp") {
1494
1566
  // TODO: not sure this is correct for `timestamp`
1495
1567
  return "date-time";
1496
1568
  }
@@ -1514,7 +1586,7 @@ const mssqlTableExcludes = new Set([
1514
1586
  "ddl_history",
1515
1587
  "index_columns",
1516
1588
  "lsn_time_mapping",
1517
- "systranschemas",
1589
+ "systranschemas"
1518
1590
  ]);
1519
1591
  async function getTableNames() {
1520
1592
  if (dialect === "mysql") {