@technicity/data-service-generator 0.4.4 → 0.5.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/dist/{generate.d.ts → generation/generate.d.ts} +1 -1
- package/dist/{generate.js → generation/generate.js} +82 -63
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{CustomError.d.ts → lib/CustomError.d.ts} +0 -0
- package/dist/{CustomError.js → lib/CustomError.js} +0 -0
- package/dist/{getDuplicates.d.ts → lib/getDuplicates.d.ts} +0 -0
- package/dist/{getDuplicates.js → lib/getDuplicates.js} +0 -0
- package/dist/{isNotNullOrUndefined.d.ts → lib/isNotNullOrUndefined.d.ts} +0 -0
- package/dist/{isNotNullOrUndefined.js → lib/isNotNullOrUndefined.js} +0 -0
- package/dist/runtime/IRuntime.d.ts +156 -43
- package/dist/runtime/RuntimeKSQL.d.ts +11 -11
- package/dist/runtime/RuntimeKSQL.js +29 -24
- package/dist/runtime/RuntimeMSSQL.d.ts +6 -11
- package/dist/runtime/RuntimeMSSQL.js +16 -53
- package/dist/runtime/RuntimeMySQL.d.ts +5 -10
- package/dist/runtime/RuntimeMySQL.js +19 -49
- package/dist/runtime/{__MSSQL.d.ts → lib/MSSQL.d.ts} +0 -0
- package/dist/runtime/{__MSSQL.js → lib/MSSQL.js} +0 -0
- package/dist/{SDKNotFoundError.d.ts → runtime/lib/SDKNotFoundError.d.ts} +1 -1
- package/dist/{SDKNotFoundError.js → runtime/lib/SDKNotFoundError.js} +1 -1
- package/dist/{addNullFallbacks.d.ts → runtime/lib/addNullFallbacks.d.ts} +0 -0
- package/dist/{addNullFallbacks.js → runtime/lib/addNullFallbacks.js} +0 -0
- package/dist/{cursor.d.ts → runtime/lib/cursor.d.ts} +0 -0
- package/dist/{cursor.js → runtime/lib/cursor.js} +0 -0
- package/dist/{getDateTimeStringMySQL.d.ts → runtime/lib/getDateTimeStringMySQL.d.ts} +0 -0
- package/dist/{getDateTimeStringMySQL.js → runtime/lib/getDateTimeStringMySQL.js} +0 -0
- package/dist/{getOrderBy.d.ts → runtime/lib/getOrderBy.d.ts} +1 -1
- package/dist/{getOrderBy.js → runtime/lib/getOrderBy.js} +3 -7
- package/dist/{getSqlAst.d.ts → runtime/lib/getSqlAst.d.ts} +1 -1
- package/dist/{getSqlAst.js → runtime/lib/getSqlAst.js} +6 -2
- package/dist/{getWhere.d.ts → runtime/lib/getWhere.d.ts} +1 -1
- package/dist/{getWhere.js → runtime/lib/getWhere.js} +3 -1
- package/dist/{runTransforms.d.ts → runtime/lib/runTransforms.d.ts} +1 -1
- package/dist/{runTransforms.js → runtime/lib/runTransforms.js} +0 -0
- package/dist/runtime/lib/shared.d.ts +12 -0
- package/dist/runtime/{__shared.js → lib/shared.js} +167 -104
- package/dist/{stringifyWhere.d.ts → runtime/lib/stringifyWhere.d.ts} +1 -1
- package/dist/{stringifyWhere.js → runtime/lib/stringifyWhere.js} +0 -0
- package/dist/runtime/{__typeCastMSSQL.d.ts → lib/typeCastMSSQL.d.ts} +0 -0
- package/dist/runtime/{__typeCastMSSQL.js → lib/typeCastMSSQL.js} +0 -0
- package/package.json +2 -1
- package/dist/runtime/__shared.d.ts +0 -32
- package/dist/types.d.ts +0 -142
- package/dist/types.js +0 -2
|
@@ -13,9 +13,9 @@ const mssql = require("mssql");
|
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
const TSqlString = require("tsqlstring");
|
|
15
15
|
const json_schema_to_typescript_1 = require("json-schema-to-typescript");
|
|
16
|
-
const getDuplicates_1 = require("
|
|
17
|
-
const isNotNullOrUndefined_1 = require("
|
|
18
|
-
const mysql = require("
|
|
16
|
+
const getDuplicates_1 = require("../lib/getDuplicates");
|
|
17
|
+
const isNotNullOrUndefined_1 = require("../lib/isNotNullOrUndefined");
|
|
18
|
+
const mysql = require("../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
|
|
@@ -23,6 +23,9 @@ const mysql = require("./mysql");
|
|
|
23
23
|
// Meh
|
|
24
24
|
let query = undefined;
|
|
25
25
|
let dialect = "mysql";
|
|
26
|
+
const json2TsOpts = {
|
|
27
|
+
bannerComment: "",
|
|
28
|
+
};
|
|
26
29
|
async function generate(input) {
|
|
27
30
|
if (input.tables != null && input.excludeTables != null) {
|
|
28
31
|
throw new Error("Must specify either `tables` or `excludeTables`, not both");
|
|
@@ -59,6 +62,7 @@ async function generate(input) {
|
|
|
59
62
|
const sdkSource = await getSDKSource(data, specialCaseUuidColumn, supplementClientOpts);
|
|
60
63
|
const sdkFilename = "index.ts";
|
|
61
64
|
const artifactsFilename = "artifacts.ts";
|
|
65
|
+
const IRuntimeFilename = "IRuntime.d.ts";
|
|
62
66
|
const tsConfigJSON = {
|
|
63
67
|
compilerOptions: {
|
|
64
68
|
module: "commonjs",
|
|
@@ -67,25 +71,27 @@ async function generate(input) {
|
|
|
67
71
|
declaration: true,
|
|
68
72
|
outDir: "./sdk-ts",
|
|
69
73
|
},
|
|
70
|
-
include: [sdkFilename, artifactsFilename],
|
|
74
|
+
include: [sdkFilename, artifactsFilename, IRuntimeFilename],
|
|
71
75
|
};
|
|
72
76
|
const packageJSON = {
|
|
73
77
|
name: "temp",
|
|
74
78
|
version: "1.0.0",
|
|
75
79
|
// Deps need to be included so that they're inlined by ncc
|
|
76
80
|
dependencies: {
|
|
77
|
-
...require("
|
|
81
|
+
...require("../../package.json").dependencies,
|
|
78
82
|
uuid: "8.3.2",
|
|
79
83
|
},
|
|
80
84
|
devDependencies: {
|
|
81
|
-
"@types/node": require("
|
|
82
|
-
typescript: require("
|
|
85
|
+
"@types/node": require("../../package.json").devDependencies["@types/node"],
|
|
86
|
+
typescript: require("../../package.json").devDependencies.typescript,
|
|
83
87
|
},
|
|
84
88
|
};
|
|
85
89
|
const tmpDirPath = path.join(os.tmpdir(), `dsg-${Date.now()}`);
|
|
86
90
|
fse.mkdirpSync(tmpDirPath);
|
|
87
91
|
fs.writeFileSync(path.join(tmpDirPath, sdkFilename), sdkSource);
|
|
88
92
|
fs.writeFileSync(path.join(tmpDirPath, artifactsFilename), artifactsSource);
|
|
93
|
+
const sourceIRuntimeFilePath = path.join(__dirname, "../runtime", IRuntimeFilename);
|
|
94
|
+
fse.copyFileSync(sourceIRuntimeFilePath, path.join(tmpDirPath, IRuntimeFilename));
|
|
89
95
|
const typesDirPath = path.join(tmpDirPath, "types");
|
|
90
96
|
fse.mkdirpSync(typesDirPath);
|
|
91
97
|
fs.writeFileSync(path.join(typesDirPath, "_shared.ts"), getTypeShared());
|
|
@@ -115,7 +121,14 @@ async function generate(input) {
|
|
|
115
121
|
child_process.execSync("npm i", { cwd: tmpDirPath, stdio: "inherit" });
|
|
116
122
|
child_process.execSync(`npx -p @vercel/ncc@${nccVersion} ncc build ./${sdkFilename} -o ${tmpBuildOutputPath} -e ./artifacts`, { cwd: tmpDirPath, stdio: "inherit" });
|
|
117
123
|
// TODO: workaround for artifacts.js not being output by ncc
|
|
118
|
-
fs.writeFileSync(path.join(tmpBuildOutputPath, "artifacts.js"), artifactsSource
|
|
124
|
+
fs.writeFileSync(path.join(tmpBuildOutputPath, "artifacts.js"), artifactsSource
|
|
125
|
+
.replace("export const artifacts: IArtifacts = ", "module.exports.artifacts = ")
|
|
126
|
+
.split("\n")
|
|
127
|
+
// Remove import
|
|
128
|
+
.slice(2)
|
|
129
|
+
.join("\n"));
|
|
130
|
+
// TODO: workaround for IRuntime.d.ts not being included
|
|
131
|
+
fse.copyFileSync(sourceIRuntimeFilePath, path.join(tmpBuildOutputPath, IRuntimeFilename));
|
|
119
132
|
if (!fs.existsSync(outdir)) {
|
|
120
133
|
fse.mkdirpSync(outdir);
|
|
121
134
|
}
|
|
@@ -158,8 +171,8 @@ function init(input) {
|
|
|
158
171
|
// It's a bit awkward to put __whereNeedsProcessing, __prepareWhere on the class,
|
|
159
172
|
// but it allows us to share the same database pool, clientOpts, etc.
|
|
160
173
|
async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts) {
|
|
161
|
-
// TODO: runtime: IRuntime
|
|
162
174
|
const src = `import { v4 as uuidv4 } from "uuid";
|
|
175
|
+
import type { IRuntime, TMiddleware, TContext } from "./IRuntime"
|
|
163
176
|
import { artifacts } from "./artifacts";
|
|
164
177
|
import type { Paginate, ListPaginated } from "./types/_shared";
|
|
165
178
|
${input.reduce((acc, x) => {
|
|
@@ -181,7 +194,7 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
|
|
|
181
194
|
}, "")}
|
|
182
195
|
|
|
183
196
|
export class SDK {
|
|
184
|
-
runtime:
|
|
197
|
+
runtime: IRuntime;
|
|
185
198
|
|
|
186
199
|
constructor(opts: {
|
|
187
200
|
runtime: any;
|
|
@@ -194,15 +207,19 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
|
|
|
194
207
|
: "opts.otherOpts"}, artifacts);
|
|
195
208
|
}
|
|
196
209
|
|
|
197
|
-
|
|
198
|
-
return this.runtime
|
|
210
|
+
$use(middleware: TMiddleware) {
|
|
211
|
+
return this.runtime.$use(middleware);
|
|
199
212
|
}
|
|
200
213
|
|
|
201
|
-
|
|
214
|
+
$whereNeedsProcessing(where: any) {
|
|
215
|
+
return this.runtime.$whereNeedsProcessing(where);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async $prepareWhere(
|
|
202
219
|
table: string,
|
|
203
220
|
where: any
|
|
204
221
|
) {
|
|
205
|
-
return this.runtime
|
|
222
|
+
return this.runtime.$prepareWhere(artifacts, table, where);
|
|
206
223
|
}
|
|
207
224
|
|
|
208
225
|
${(await Promise.all(input.flatMap(async (x) => {
|
|
@@ -221,16 +238,16 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
|
|
|
221
238
|
param1: ${findOnes
|
|
222
239
|
.map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
|
|
223
240
|
.join(" | ")},
|
|
224
|
-
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string }
|
|
241
|
+
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
|
|
225
242
|
): Promise<${x.typeReturnBaseName}> {
|
|
226
243
|
return this.runtime.resolve(
|
|
227
244
|
{
|
|
228
|
-
|
|
229
|
-
|
|
245
|
+
resource: "${x.table}",
|
|
246
|
+
action: "findUnique",
|
|
230
247
|
args: { $where: param1 },
|
|
231
248
|
fields: param2?.fields,
|
|
232
|
-
|
|
233
|
-
|
|
249
|
+
artifacts,
|
|
250
|
+
context: param2?.context
|
|
234
251
|
}
|
|
235
252
|
);
|
|
236
253
|
}`;
|
|
@@ -238,17 +255,16 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
|
|
|
238
255
|
if (x.kind === "getList") {
|
|
239
256
|
return `async ${x.methodName}(
|
|
240
257
|
param1: { $where?: ${x.typeWhereName}, $orderBy?: ${x.typeOrderByName}, $limit?: number },
|
|
241
|
-
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string }
|
|
258
|
+
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
|
|
242
259
|
): Promise<Array<${x.typeReturnBaseName}>> {
|
|
243
260
|
return this.runtime.resolve(
|
|
244
261
|
{
|
|
245
|
-
|
|
246
|
-
|
|
262
|
+
resource: "${x.table}",
|
|
263
|
+
action: "findMany",
|
|
247
264
|
args: param1,
|
|
248
265
|
fields: param2?.fields,
|
|
249
|
-
grabMany: true,
|
|
250
266
|
artifacts,
|
|
251
|
-
|
|
267
|
+
context: param2?.context
|
|
252
268
|
}
|
|
253
269
|
);
|
|
254
270
|
}`;
|
|
@@ -256,17 +272,16 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
|
|
|
256
272
|
if (x.kind === "getListPaginated") {
|
|
257
273
|
return `async ${x.methodName}(
|
|
258
274
|
param1: { $where?: ${x.typeWhereName}, $orderBy?: ${x.typeOrderByName}, $paginate: Paginate },
|
|
259
|
-
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string }
|
|
275
|
+
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
|
|
260
276
|
): Promise<ListPaginated<${x.typeReturnBaseName}>> {
|
|
261
277
|
return this.runtime.resolve(
|
|
262
278
|
{
|
|
263
|
-
|
|
264
|
-
|
|
279
|
+
resource: "${x.table}",
|
|
280
|
+
action: "findManyPaginated",
|
|
265
281
|
args: param1,
|
|
266
282
|
fields: param2?.fields,
|
|
267
|
-
grabMany: true,
|
|
268
283
|
artifacts,
|
|
269
|
-
|
|
284
|
+
context: param2?.context
|
|
270
285
|
}
|
|
271
286
|
);
|
|
272
287
|
}`;
|
|
@@ -274,19 +289,20 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
|
|
|
274
289
|
if (x.kind === "postOne") {
|
|
275
290
|
return `async ${x.methodName}(
|
|
276
291
|
data: ${x.typeDataName},
|
|
277
|
-
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string }
|
|
292
|
+
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
|
|
278
293
|
): Promise<${x.typeReturnBaseName}> {
|
|
279
294
|
let payload = data;
|
|
280
295
|
${specialCaseUuidColumn &&
|
|
281
296
|
uniqueColumns.find((x) => x.name === "uuid")
|
|
282
297
|
? `if (!Object.prototype.hasOwnProperty.call(payload, "uuid")) { payload = {...payload, uuid: uuidv4()} }`
|
|
283
298
|
: ""}
|
|
284
|
-
return this.runtime.
|
|
285
|
-
|
|
299
|
+
return this.runtime.resolve({
|
|
300
|
+
resource: "${x.table}",
|
|
301
|
+
action: "create",
|
|
286
302
|
data: payload,
|
|
287
303
|
artifacts,
|
|
288
|
-
fieldName: "${x.fieldName}",
|
|
289
304
|
fields: param2?.fields,
|
|
305
|
+
context: param2?.context
|
|
290
306
|
});
|
|
291
307
|
}`;
|
|
292
308
|
}
|
|
@@ -296,15 +312,16 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
|
|
|
296
312
|
.map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
|
|
297
313
|
.join(" | ")},
|
|
298
314
|
data: ${x.typeDataName},
|
|
299
|
-
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string }
|
|
315
|
+
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
|
|
300
316
|
): Promise<${x.typeReturnBaseName}> {
|
|
301
|
-
return this.runtime.
|
|
302
|
-
|
|
317
|
+
return this.runtime.resolve({
|
|
318
|
+
resource: "${x.table}",
|
|
319
|
+
action: "update",
|
|
303
320
|
args: { $where: param1 },
|
|
304
321
|
data,
|
|
305
322
|
artifacts,
|
|
306
|
-
fieldName: "${x.fieldName}",
|
|
307
323
|
fields: param2?.fields,
|
|
324
|
+
context: param2?.context
|
|
308
325
|
});
|
|
309
326
|
}`;
|
|
310
327
|
}
|
|
@@ -312,15 +329,16 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
|
|
|
312
329
|
return `async ${x.methodName}(
|
|
313
330
|
param1: { $where?: ${x.typeWhereName} },
|
|
314
331
|
data: ${x.typeDataName},
|
|
315
|
-
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string }
|
|
332
|
+
param2?: { fields?: ${x.typeFieldsName}, correlationId?: string, context?: TContext }
|
|
316
333
|
): Promise<Array<${x.typeReturnBaseName}>> {
|
|
317
|
-
return this.runtime.
|
|
318
|
-
|
|
334
|
+
return this.runtime.resolve({
|
|
335
|
+
resource: "${x.table}",
|
|
336
|
+
action: "updateMany",
|
|
319
337
|
args: param1,
|
|
320
338
|
data,
|
|
321
339
|
artifacts,
|
|
322
|
-
fieldName: "${x.fieldName}",
|
|
323
340
|
fields: param2?.fields,
|
|
341
|
+
context: param2?.context
|
|
324
342
|
});
|
|
325
343
|
}`;
|
|
326
344
|
}
|
|
@@ -329,23 +347,28 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
|
|
|
329
347
|
param1: ${findOnes
|
|
330
348
|
.map((findOne) => `{ ${findOne.name}: ${findOne.type}${findOne.nullable ? " | null" : ""} }`)
|
|
331
349
|
.join(" | ")},
|
|
332
|
-
param2?: { correlationId?: string }
|
|
350
|
+
param2?: { correlationId?: string, context?: TContext }
|
|
333
351
|
): Promise<void> {
|
|
334
|
-
await this.runtime.
|
|
335
|
-
|
|
352
|
+
await this.runtime.resolve({
|
|
353
|
+
resource: "${x.table}",
|
|
354
|
+
action: "delete",
|
|
336
355
|
args: { $where: param1 },
|
|
356
|
+
artifacts,
|
|
357
|
+
context: param2?.context
|
|
337
358
|
});
|
|
338
359
|
}`;
|
|
339
360
|
}
|
|
340
361
|
if (x.kind === "deleteList") {
|
|
341
362
|
return `async ${x.methodName}(
|
|
342
363
|
param1: { $where?: ${x.typeWhereName} },
|
|
343
|
-
param2?: { correlationId?: string }
|
|
364
|
+
param2?: { correlationId?: string, context?: TContext }
|
|
344
365
|
): Promise<void> {
|
|
345
|
-
await this.runtime.
|
|
346
|
-
|
|
366
|
+
await this.runtime.resolve({
|
|
367
|
+
resource: "${x.table}",
|
|
368
|
+
action: "deleteMany",
|
|
347
369
|
args: param1,
|
|
348
|
-
artifacts
|
|
370
|
+
artifacts,
|
|
371
|
+
context: param2?.context
|
|
349
372
|
});
|
|
350
373
|
}`;
|
|
351
374
|
}
|
|
@@ -373,7 +396,6 @@ async function getGetOneData(table, includeMappedFields) {
|
|
|
373
396
|
kind: "getOne",
|
|
374
397
|
table,
|
|
375
398
|
methodName: "get" + changeCase.pascalCase(table),
|
|
376
|
-
fieldName: changeCase.camelCase(table),
|
|
377
399
|
typeFields: await getTypeFields(table, typeFieldsName, includeMappedFields),
|
|
378
400
|
typeFieldsName,
|
|
379
401
|
typeReturnBase: await getTypeReturnBase(table, typeReturnBaseName, includeMappedFields),
|
|
@@ -391,7 +413,6 @@ async function getGetListData(table) {
|
|
|
391
413
|
kind: "getList",
|
|
392
414
|
table,
|
|
393
415
|
methodName: "get" + changeCase.pascalCase(table) + "List",
|
|
394
|
-
fieldName: changeCase.camelCase(table) + "List",
|
|
395
416
|
typeFieldsName,
|
|
396
417
|
typeReturnBaseName,
|
|
397
418
|
typeWhere,
|
|
@@ -409,7 +430,6 @@ async function getGetListPaginatedData(table) {
|
|
|
409
430
|
kind: "getListPaginated",
|
|
410
431
|
table,
|
|
411
432
|
methodName: "get" + changeCase.pascalCase(table) + "ListPaginated",
|
|
412
|
-
fieldName: changeCase.camelCase(table) + "ListPaginated",
|
|
413
433
|
typeFieldsName,
|
|
414
434
|
typeReturnBaseName,
|
|
415
435
|
typeWhereName,
|
|
@@ -424,7 +444,6 @@ async function getPostOneData(table, specialCaseUuidColumn, includeMappedFields)
|
|
|
424
444
|
kind: "postOne",
|
|
425
445
|
table,
|
|
426
446
|
methodName: "post" + changeCase.pascalCase(table),
|
|
427
|
-
fieldName: changeCase.camelCase(table),
|
|
428
447
|
typeFieldsName,
|
|
429
448
|
typeReturnBaseName,
|
|
430
449
|
typeData: await getTypeDataPost(table, typeDataName, specialCaseUuidColumn, includeMappedFields),
|
|
@@ -439,7 +458,6 @@ async function getPatchOneData(table, specialCaseUuidColumn, includeMappedFields
|
|
|
439
458
|
kind: "patchOne",
|
|
440
459
|
table,
|
|
441
460
|
methodName: "patch" + changeCase.pascalCase(table),
|
|
442
|
-
fieldName: changeCase.camelCase(table),
|
|
443
461
|
typeFieldsName,
|
|
444
462
|
typeReturnBaseName,
|
|
445
463
|
typeData: await getTypeDataPatch(table, typeDataName, specialCaseUuidColumn, includeMappedFields),
|
|
@@ -455,7 +473,6 @@ async function getPatchListData(table) {
|
|
|
455
473
|
kind: "patchList",
|
|
456
474
|
table,
|
|
457
475
|
methodName: "patch" + changeCase.pascalCase(table) + "List",
|
|
458
|
-
fieldName: changeCase.camelCase(table) + "List",
|
|
459
476
|
typeFieldsName,
|
|
460
477
|
typeReturnBaseName,
|
|
461
478
|
typeWhereName,
|
|
@@ -467,7 +484,6 @@ function getDeleteOneData(table) {
|
|
|
467
484
|
kind: "deleteOne",
|
|
468
485
|
table,
|
|
469
486
|
methodName: "delete" + changeCase.pascalCase(table),
|
|
470
|
-
fieldName: changeCase.camelCase(table),
|
|
471
487
|
};
|
|
472
488
|
}
|
|
473
489
|
function getDeleteListData(table) {
|
|
@@ -476,13 +492,12 @@ function getDeleteListData(table) {
|
|
|
476
492
|
kind: "deleteList",
|
|
477
493
|
table,
|
|
478
494
|
methodName: "delete" + changeCase.pascalCase(table) + "List",
|
|
479
|
-
fieldName: changeCase.camelCase(table) + "List",
|
|
480
495
|
typeWhereName,
|
|
481
496
|
};
|
|
482
497
|
}
|
|
483
498
|
async function getTypeWhere(table, name) {
|
|
484
499
|
const jsonSchemaWhere = await getJSONSchemaWhere(table);
|
|
485
|
-
return json_schema_to_typescript_1.compile(jsonSchemaWhere, name);
|
|
500
|
+
return json_schema_to_typescript_1.compile(jsonSchemaWhere, name, json2TsOpts);
|
|
486
501
|
}
|
|
487
502
|
async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMappedFields) {
|
|
488
503
|
const primaryColumn = await getPrimaryColumn(table);
|
|
@@ -526,7 +541,7 @@ async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMapped
|
|
|
526
541
|
// for simplicity, just make both not required for now.
|
|
527
542
|
.filter((x) => !notRequiredList.includes(x)),
|
|
528
543
|
};
|
|
529
|
-
return json_schema_to_typescript_1.compile(jsonSchema, name);
|
|
544
|
+
return json_schema_to_typescript_1.compile(jsonSchema, name, json2TsOpts);
|
|
530
545
|
}
|
|
531
546
|
async function getTypeDataPatch(table, name, specialCaseUuidColumn, includeMappedFields) {
|
|
532
547
|
const primaryColumn = await getPrimaryColumn(table);
|
|
@@ -571,7 +586,7 @@ async function getTypeDataPatch(table, name, specialCaseUuidColumn, includeMappe
|
|
|
571
586
|
additionalProperties: false,
|
|
572
587
|
required: [],
|
|
573
588
|
};
|
|
574
|
-
let type = await json_schema_to_typescript_1.compile(jsonSchema, name);
|
|
589
|
+
let type = await json_schema_to_typescript_1.compile(jsonSchema, name, json2TsOpts);
|
|
575
590
|
if (mustImportTUpdateOperationsString || mustImportTUpdateOperationsNumber) {
|
|
576
591
|
const imports = [];
|
|
577
592
|
if (mustImportTUpdateOperationsString) {
|
|
@@ -766,7 +781,7 @@ async function getJSONSchemaWhere(table) {
|
|
|
766
781
|
};
|
|
767
782
|
}
|
|
768
783
|
async function getTypeOrderBy(table, name) {
|
|
769
|
-
return json_schema_to_typescript_1.compile((await getJSONSchemaOrderBy(table)), name);
|
|
784
|
+
return json_schema_to_typescript_1.compile((await getJSONSchemaOrderBy(table)), name, json2TsOpts);
|
|
770
785
|
}
|
|
771
786
|
async function getJSONSchemaOrderBy(table) {
|
|
772
787
|
const fieldNames = await getTableMeta(table).then((xs) => xs.map((x) => x.Field));
|
|
@@ -876,7 +891,7 @@ async function getTypeFields(table, name, includeMappedFields) {
|
|
|
876
891
|
],
|
|
877
892
|
},
|
|
878
893
|
};
|
|
879
|
-
let type = await json_schema_to_typescript_1.compile(jsonSchemaFields, name);
|
|
894
|
+
let type = await json_schema_to_typescript_1.compile(jsonSchemaFields, name, json2TsOpts);
|
|
880
895
|
const fieldImports = _.uniq(relations
|
|
881
896
|
.filter((x) => x.table !== table)
|
|
882
897
|
.map((x) => getTypeFieldsName(x.table)));
|
|
@@ -924,7 +939,7 @@ async function getTypeReturnBase(table, name, includeMappedFields) {
|
|
|
924
939
|
// Because of aliases
|
|
925
940
|
additionalProperties: true,
|
|
926
941
|
};
|
|
927
|
-
let type = await json_schema_to_typescript_1.compile(jsonSchemaReturn, name);
|
|
942
|
+
let type = await json_schema_to_typescript_1.compile(jsonSchemaReturn, name, json2TsOpts);
|
|
928
943
|
const imports = _.uniq(relations.map((x) => getTypeReturnBaseName(x.table)))
|
|
929
944
|
.filter((x) => x !== name)
|
|
930
945
|
.map((x) => `import type { ${x} } from "./${x}";`)
|
|
@@ -998,7 +1013,11 @@ async function getArtifactsSource(tables, includeMappedFields) {
|
|
|
998
1013
|
acc[x.table] = x;
|
|
999
1014
|
return acc;
|
|
1000
1015
|
}, {});
|
|
1001
|
-
const src = `
|
|
1016
|
+
const src = `
|
|
1017
|
+
import type {IArtifacts} from "./IRuntime";
|
|
1018
|
+
|
|
1019
|
+
export const artifacts: IArtifacts = ${JSON.stringify(artifacts)};
|
|
1020
|
+
`;
|
|
1002
1021
|
return prettier.format(src, { parser: "typescript" });
|
|
1003
1022
|
}
|
|
1004
1023
|
const getRelationInfo = _.memoize(async function getRelationInfo(table) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { generate } from "./generate";
|
|
2
|
-
export { SDKNotFoundError } from "./SDKNotFoundError";
|
|
1
|
+
export { generate } from "./generation/generate";
|
|
2
|
+
export { SDKNotFoundError } from "./runtime/lib/SDKNotFoundError";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SDKNotFoundError = exports.generate = void 0;
|
|
4
|
-
var generate_1 = require("./generate");
|
|
4
|
+
var generate_1 = require("./generation/generate");
|
|
5
5
|
Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_1.generate; } });
|
|
6
|
-
var SDKNotFoundError_1 = require("./SDKNotFoundError");
|
|
6
|
+
var SDKNotFoundError_1 = require("./runtime/lib/SDKNotFoundError");
|
|
7
7
|
Object.defineProperty(exports, "SDKNotFoundError", { enumerable: true, get: function () { return SDKNotFoundError_1.SDKNotFoundError; } });
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,47 +1,160 @@
|
|
|
1
|
-
import { IArtifacts, IGetSQLASTInput } from "../types";
|
|
2
1
|
export interface IRuntime {
|
|
3
|
-
resolve(input:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
del(input: TDelInput): Promise<any>;
|
|
8
|
-
deleteList(input: TDeleteListInput): Promise<any>;
|
|
9
|
-
whereNeedsProcessing(where: any): boolean;
|
|
10
|
-
_prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<any>;
|
|
2
|
+
resolve(input: TResolveParams): Promise<any>;
|
|
3
|
+
$use: (middleware: TMiddleware) => void;
|
|
4
|
+
$whereNeedsProcessing(where: any): boolean;
|
|
5
|
+
$prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<any>;
|
|
11
6
|
}
|
|
12
|
-
export declare type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
table: TResolveInput["table"];
|
|
18
|
-
data: any;
|
|
19
|
-
artifacts: TResolveInput["artifacts"];
|
|
20
|
-
fields: TResolveInput["fields"];
|
|
21
|
-
fieldName: TResolveInput["fieldName"];
|
|
22
|
-
};
|
|
23
|
-
export declare type TPatchInput = {
|
|
24
|
-
table: TResolveInput["table"];
|
|
25
|
-
args: TResolveInput["args"];
|
|
26
|
-
data: any;
|
|
27
|
-
artifacts: TResolveInput["artifacts"];
|
|
28
|
-
fields: TResolveInput["fields"];
|
|
29
|
-
fieldName: TResolveInput["fieldName"];
|
|
30
|
-
};
|
|
31
|
-
export declare type TPatchListInput = {
|
|
32
|
-
table: TResolveInput["table"];
|
|
33
|
-
args: TResolveInput["args"];
|
|
34
|
-
data: any;
|
|
35
|
-
artifacts: TResolveInput["artifacts"];
|
|
36
|
-
fields: TResolveInput["fields"];
|
|
37
|
-
fieldName: TResolveInput["fieldName"];
|
|
38
|
-
};
|
|
39
|
-
export declare type TDelInput = {
|
|
40
|
-
table: TResolveInput["table"];
|
|
41
|
-
args: TResolveInput["args"];
|
|
42
|
-
};
|
|
43
|
-
export declare type TDeleteListInput = {
|
|
44
|
-
table: TResolveInput["table"];
|
|
45
|
-
args: TResolveInput["args"];
|
|
7
|
+
export declare type TResolveParams = {
|
|
8
|
+
resource: string;
|
|
9
|
+
action: "findUnique" | "findMany" | "findManyPaginated" | "create" | "update" | "updateMany" | "delete" | "deleteMany";
|
|
10
|
+
args?: IArgs | undefined;
|
|
11
|
+
data?: any;
|
|
46
12
|
artifacts: IArtifacts;
|
|
13
|
+
fields?: IField[] | undefined;
|
|
14
|
+
context?: TContext | undefined;
|
|
47
15
|
};
|
|
16
|
+
export declare type TContext = {
|
|
17
|
+
[k: string]: any;
|
|
18
|
+
};
|
|
19
|
+
export declare type TMiddleware = (params: TResolveParams, next: (params: TResolveParams) => Promise<any>) => Promise<any>;
|
|
20
|
+
export declare type IDialect = "mysql" | "mssql" | "ksql";
|
|
21
|
+
export declare type TDbCall = (q: string) => Promise<any>;
|
|
22
|
+
export declare type TFormatQuery = (q: string, values: any[]) => string;
|
|
23
|
+
export declare type ISupplementClientOpts = boolean;
|
|
24
|
+
export declare type IOrderBy = Array<{
|
|
25
|
+
column: string;
|
|
26
|
+
direction: any;
|
|
27
|
+
}>;
|
|
28
|
+
export declare type IArgs = {
|
|
29
|
+
[k: string]: any;
|
|
30
|
+
};
|
|
31
|
+
export declare type IField = string | {
|
|
32
|
+
name: string;
|
|
33
|
+
as?: string;
|
|
34
|
+
fields: IField[];
|
|
35
|
+
args?: IArgs;
|
|
36
|
+
transform?: (record: any) => any;
|
|
37
|
+
};
|
|
38
|
+
declare type IWhere = (table: string, args: IArgs) => string | undefined;
|
|
39
|
+
declare type IASTChildColumn = {
|
|
40
|
+
type: "column";
|
|
41
|
+
name: string;
|
|
42
|
+
fieldName: string;
|
|
43
|
+
as: string;
|
|
44
|
+
fromOtherTable?: string | undefined;
|
|
45
|
+
};
|
|
46
|
+
declare type IASTChildComposite = {
|
|
47
|
+
type: "composite";
|
|
48
|
+
name: string[];
|
|
49
|
+
fieldName: string;
|
|
50
|
+
as: string;
|
|
51
|
+
fromOtherTable?: string | undefined;
|
|
52
|
+
};
|
|
53
|
+
declare type ISqlJoin = (t1: string, t2: string, args: IArgs) => string;
|
|
54
|
+
declare type ISqlBatch = {
|
|
55
|
+
thisKey: IASTChildColumn;
|
|
56
|
+
parentKey: IASTChildColumn;
|
|
57
|
+
};
|
|
58
|
+
declare type IJunction = {
|
|
59
|
+
sqlTable: string;
|
|
60
|
+
as: string;
|
|
61
|
+
uniqueKey: string | string[];
|
|
62
|
+
where?: IWhere;
|
|
63
|
+
sqlBatch: {
|
|
64
|
+
thisKey: IASTChildColumn;
|
|
65
|
+
parentKey: IASTChildColumn;
|
|
66
|
+
sqlJoin: ISqlJoin;
|
|
67
|
+
};
|
|
68
|
+
} | {
|
|
69
|
+
sqlTable: string;
|
|
70
|
+
as: string;
|
|
71
|
+
where?: IWhere;
|
|
72
|
+
sqlJoins: Array<ISqlJoin>;
|
|
73
|
+
};
|
|
74
|
+
export declare type IGetSQLASTInput = {
|
|
75
|
+
table: string;
|
|
76
|
+
fieldName: string;
|
|
77
|
+
fields: IField[];
|
|
78
|
+
args?: IArgs;
|
|
79
|
+
where?: IWhere;
|
|
80
|
+
sqlJoin?: ISqlJoin;
|
|
81
|
+
sqlBatch?: ISqlBatch;
|
|
82
|
+
junction?: IJunction;
|
|
83
|
+
grabMany: boolean;
|
|
84
|
+
getWhere: (table: string, args: any, dialect: IDialect, orderBy?: IOrderBy | undefined, rowWithMatchingCursor?: any) => string | null;
|
|
85
|
+
orderBy?: IOrderBy | undefined;
|
|
86
|
+
rowWithMatchingCursor?: any;
|
|
87
|
+
artifacts: IArtifacts;
|
|
88
|
+
dialect: IDialect;
|
|
89
|
+
firstChild?: IASTChildColumn | IASTChildComposite;
|
|
90
|
+
};
|
|
91
|
+
export declare type IRelation = {
|
|
92
|
+
table: string;
|
|
93
|
+
foreignKey: string;
|
|
94
|
+
referencedTable: string;
|
|
95
|
+
referencedKey: string;
|
|
96
|
+
nullable: boolean;
|
|
97
|
+
};
|
|
98
|
+
declare type IOneToManyOrManyToOne = "one-to-many__many-to-one";
|
|
99
|
+
declare type IManyToMany = "many-to-many";
|
|
100
|
+
declare type IRelationKind = "one-to-many" | "many-to-one";
|
|
101
|
+
export declare type IRelationOneToManyOrManyToOne = {
|
|
102
|
+
type: IOneToManyOrManyToOne;
|
|
103
|
+
kind: IRelationKind;
|
|
104
|
+
grabMany: boolean;
|
|
105
|
+
table: string;
|
|
106
|
+
name: string;
|
|
107
|
+
relation: IRelation;
|
|
108
|
+
nullable: boolean;
|
|
109
|
+
};
|
|
110
|
+
export declare type IRelationManyToMany = {
|
|
111
|
+
type: IManyToMany;
|
|
112
|
+
grabMany: boolean;
|
|
113
|
+
table: string;
|
|
114
|
+
junctionTable: string;
|
|
115
|
+
name: string;
|
|
116
|
+
relations: Array<IRelation>;
|
|
117
|
+
};
|
|
118
|
+
export declare type IRelationField = {
|
|
119
|
+
name: string;
|
|
120
|
+
type: IOneToManyOrManyToOne;
|
|
121
|
+
kind: IRelationKind;
|
|
122
|
+
table: string;
|
|
123
|
+
grabMany: boolean;
|
|
124
|
+
relation: IRelation;
|
|
125
|
+
} | {
|
|
126
|
+
name: string;
|
|
127
|
+
type: IManyToMany;
|
|
128
|
+
table: string;
|
|
129
|
+
junctionTable: string;
|
|
130
|
+
grabMany: boolean;
|
|
131
|
+
relations: Array<IRelation>;
|
|
132
|
+
};
|
|
133
|
+
export declare type IMappedField = {
|
|
134
|
+
name: string;
|
|
135
|
+
as: string;
|
|
136
|
+
type: string;
|
|
137
|
+
nullable: boolean;
|
|
138
|
+
table: string;
|
|
139
|
+
foreignKey: string;
|
|
140
|
+
referencedTable: string;
|
|
141
|
+
referencedKey: string;
|
|
142
|
+
};
|
|
143
|
+
export declare type IArtifacts = {
|
|
144
|
+
[k: string]: {
|
|
145
|
+
table: string;
|
|
146
|
+
primaryKey: string;
|
|
147
|
+
scalarFields: Array<string>;
|
|
148
|
+
relationFields: {
|
|
149
|
+
[k: string]: IRelationField;
|
|
150
|
+
};
|
|
151
|
+
mappedFields: {
|
|
152
|
+
[k: string]: IMappedField;
|
|
153
|
+
} | null;
|
|
154
|
+
dateTimeFields: {
|
|
155
|
+
[k: string]: boolean;
|
|
156
|
+
};
|
|
157
|
+
dateTimeFieldsCount: number;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
export {};
|