@technicity/data-service-generator 0.19.0 → 0.20.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/generation/generate.js +21 -11
- package/package.json +1 -1
|
@@ -86,7 +86,7 @@ async function generate(input) {
|
|
|
86
86
|
]));
|
|
87
87
|
const artifacts = await getArtifacts(tables, includeMappedFields, specialCaseUuidColumn);
|
|
88
88
|
const artifactsSource = getArtifactsSource(artifacts);
|
|
89
|
-
const sdkSource = await getSDKSource(data, specialCaseUuidColumn, supplementClientOpts, artifacts);
|
|
89
|
+
const sdkSource = await getSDKSource(data, specialCaseUuidColumn, supplementClientOpts, artifacts, input.outputSqliteSchema);
|
|
90
90
|
const sdkFilename = "index.ts";
|
|
91
91
|
const sourceIRuntimeFilePath = fs.existsSync(path.join(__dirname, "../runtime", "IRuntime.ts"))
|
|
92
92
|
? path.join(__dirname, "../runtime", "IRuntime.ts")
|
|
@@ -214,7 +214,7 @@ function init(input) {
|
|
|
214
214
|
}
|
|
215
215
|
// It's a bit awkward to put __whereNeedsProcessing, __prepareWhere on the class,
|
|
216
216
|
// but it allows us to share the same database pool, clientOpts, etc.
|
|
217
|
-
async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts, artifacts) {
|
|
217
|
+
async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts, artifacts, outputSqliteSchema) {
|
|
218
218
|
function getTypeImports() {
|
|
219
219
|
let set = new Set();
|
|
220
220
|
for (let d of input) {
|
|
@@ -255,7 +255,9 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts,
|
|
|
255
255
|
}) {
|
|
256
256
|
let otherOpts = opts.otherOpts ?? {};
|
|
257
257
|
if (opts.clientOpts.filename === ":memory:") {
|
|
258
|
-
|
|
258
|
+
${outputSqliteSchema === true
|
|
259
|
+
? `otherOpts = { ...otherOpts, createTablesString: require("./artifacts.sqlite").schema }`
|
|
260
|
+
: `throw new Error("SQLite artifacts not available. Please regenerate the SDK with \`outputSqliteSchema: true\`.")`}
|
|
259
261
|
}
|
|
260
262
|
this.runtime = new opts.runtime(opts.clientOpts, ${supplementClientOpts === true
|
|
261
263
|
? "{ supplementClientOpts: true, ...otherOpts }"
|
|
@@ -1443,9 +1445,12 @@ const getRelationInfo = _.memoize(async function getRelationInfo(table) {
|
|
|
1443
1445
|
const relationsManyToOne = await getRelationsManyToOne(table);
|
|
1444
1446
|
const relationsOneToMany = await getRelationsOneToMany(table);
|
|
1445
1447
|
let out = [];
|
|
1446
|
-
out = out.concat(relationsManyToOne.
|
|
1448
|
+
out = out.concat(relationsManyToOne.reduce((acc, x) => {
|
|
1449
|
+
if (!x.foreignKey.endsWith("Id")) {
|
|
1450
|
+
return acc;
|
|
1451
|
+
}
|
|
1447
1452
|
const name = getRelationManyToOneFieldName(x);
|
|
1448
|
-
|
|
1453
|
+
acc.push({
|
|
1449
1454
|
type: "one-to-many__many-to-one",
|
|
1450
1455
|
kind: "many-to-one",
|
|
1451
1456
|
grabMany: false,
|
|
@@ -1453,10 +1458,14 @@ const getRelationInfo = _.memoize(async function getRelationInfo(table) {
|
|
|
1453
1458
|
name,
|
|
1454
1459
|
relation: x,
|
|
1455
1460
|
nullable: x.nullable
|
|
1456
|
-
};
|
|
1457
|
-
|
|
1461
|
+
});
|
|
1462
|
+
return acc;
|
|
1463
|
+
}, []));
|
|
1458
1464
|
const relationsOneToManyDuplicates = (0, getDuplicates_1.getDuplicates)(relationsOneToMany.map((x) => x.referencedTable));
|
|
1459
|
-
out = out.concat(relationsOneToMany.
|
|
1465
|
+
out = out.concat(relationsOneToMany.reduce((acc, x) => {
|
|
1466
|
+
if (!x.referencedKey.endsWith("Id")) {
|
|
1467
|
+
return acc;
|
|
1468
|
+
}
|
|
1460
1469
|
let name = changeCase.camelCase(x.referencedTable) + "List";
|
|
1461
1470
|
if (relationsOneToManyDuplicates.includes(x.referencedTable)) {
|
|
1462
1471
|
// Examples:
|
|
@@ -1468,7 +1477,7 @@ const getRelationInfo = _.memoize(async function getRelationInfo(table) {
|
|
|
1468
1477
|
changeCase.pascalCase(x.referencedKey.replace(new RegExp(x.foreignKey + "$", "i"), "")) +
|
|
1469
1478
|
"List";
|
|
1470
1479
|
}
|
|
1471
|
-
|
|
1480
|
+
acc.push({
|
|
1472
1481
|
type: "one-to-many__many-to-one",
|
|
1473
1482
|
kind: "one-to-many",
|
|
1474
1483
|
grabMany: true,
|
|
@@ -1476,8 +1485,9 @@ const getRelationInfo = _.memoize(async function getRelationInfo(table) {
|
|
|
1476
1485
|
name,
|
|
1477
1486
|
relation: x,
|
|
1478
1487
|
nullable: x.nullable
|
|
1479
|
-
};
|
|
1480
|
-
|
|
1488
|
+
});
|
|
1489
|
+
return acc;
|
|
1490
|
+
}, []));
|
|
1481
1491
|
const relationsManyToMany = (await getJunctionTables()).reduce((acc, x) => {
|
|
1482
1492
|
const dataForParentTable = x.relations.find((r) => r.referencedTable === table);
|
|
1483
1493
|
if (dataForParentTable == null) {
|