@technicity/data-service-generator 0.23.0-next.12 → 0.23.0-next.14
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 +34 -4
- package/package.json +1 -1
|
@@ -106,8 +106,7 @@ async function generate(input) {
|
|
|
106
106
|
tables = tables.filter((x) => !input.excludeTables?.includes(x));
|
|
107
107
|
}
|
|
108
108
|
ctx.log.debug({ tableCount: tables.length, tables }, "tables after filter");
|
|
109
|
-
|
|
110
|
-
const data = (await Promise.all(tables.map((x) => Promise.all([
|
|
109
|
+
const data = await Promise.all(tables.flatMap((x) => [
|
|
111
110
|
getGetOneData(x, includeMappedFields),
|
|
112
111
|
getGetListData(x),
|
|
113
112
|
getGetListPaginatedData(x),
|
|
@@ -116,7 +115,7 @@ async function generate(input) {
|
|
|
116
115
|
getPatchListData(x),
|
|
117
116
|
getDeleteOneData(x),
|
|
118
117
|
getDeleteListData(x)
|
|
119
|
-
]))
|
|
118
|
+
]));
|
|
120
119
|
ctx.log.debug({ inputLength: data.length }, "SDK input data collected");
|
|
121
120
|
const artifacts = await getArtifacts(tables, includeMappedFields, specialCaseUuidColumn);
|
|
122
121
|
ctx.log.debug("getArtifacts() completed");
|
|
@@ -886,6 +885,7 @@ function getTypeDataPostName(table) {
|
|
|
886
885
|
return "DataPost" + changeCase.pascalCase(table);
|
|
887
886
|
}
|
|
888
887
|
async function getGetOneData(table, includeMappedFields) {
|
|
888
|
+
getCtx().log.debug({ table }, "getGetOneData() start");
|
|
889
889
|
const typeFieldsName = getTypeFieldsName(table);
|
|
890
890
|
const typeReturnBaseName = getTypeReturnBaseName(table);
|
|
891
891
|
return {
|
|
@@ -899,6 +899,7 @@ async function getGetOneData(table, includeMappedFields) {
|
|
|
899
899
|
};
|
|
900
900
|
}
|
|
901
901
|
async function getGetListData(table) {
|
|
902
|
+
getCtx().log.debug({ table }, "getGetListData() start");
|
|
902
903
|
const typeFieldsName = getTypeFieldsName(table);
|
|
903
904
|
const typeReturnBaseName = getTypeReturnBaseName(table);
|
|
904
905
|
const typeWhereName = getTypeWhereName(table);
|
|
@@ -918,6 +919,7 @@ async function getGetListData(table) {
|
|
|
918
919
|
};
|
|
919
920
|
}
|
|
920
921
|
async function getGetListPaginatedData(table) {
|
|
922
|
+
getCtx().log.debug({ table }, "getGetListPaginatedData() start");
|
|
921
923
|
const typeFieldsName = getTypeFieldsName(table);
|
|
922
924
|
const typeReturnBaseName = getTypeReturnBaseName(table);
|
|
923
925
|
const typeWhereName = getTypeWhereName(table);
|
|
@@ -933,6 +935,7 @@ async function getGetListPaginatedData(table) {
|
|
|
933
935
|
};
|
|
934
936
|
}
|
|
935
937
|
async function getPostOneData(table, specialCaseUuidColumn, includeMappedFields) {
|
|
938
|
+
getCtx().log.debug({ table }, "getPostOneData() start");
|
|
936
939
|
const typeFieldsName = getTypeFieldsName(table);
|
|
937
940
|
const typeReturnBaseName = getTypeReturnBaseName(table);
|
|
938
941
|
const typeDataName = getTypeDataPostName(table);
|
|
@@ -947,6 +950,7 @@ async function getPostOneData(table, specialCaseUuidColumn, includeMappedFields)
|
|
|
947
950
|
};
|
|
948
951
|
}
|
|
949
952
|
async function getPatchOneData(table, specialCaseUuidColumn, includeMappedFields) {
|
|
953
|
+
getCtx().log.debug({ table }, "getPatchOneData() start");
|
|
950
954
|
const typeFieldsName = getTypeFieldsName(table);
|
|
951
955
|
const typeReturnBaseName = getTypeReturnBaseName(table);
|
|
952
956
|
const typeDataName = "DataPatch" + changeCase.pascalCase(table);
|
|
@@ -961,6 +965,7 @@ async function getPatchOneData(table, specialCaseUuidColumn, includeMappedFields
|
|
|
961
965
|
};
|
|
962
966
|
}
|
|
963
967
|
async function getPatchListData(table) {
|
|
968
|
+
getCtx().log.debug({ table }, "getPatchListData() start");
|
|
964
969
|
const typeFieldsName = getTypeFieldsName(table);
|
|
965
970
|
const typeReturnBaseName = getTypeReturnBaseName(table);
|
|
966
971
|
const typeWhereName = getTypeWhereName(table);
|
|
@@ -978,6 +983,7 @@ async function getPatchListData(table) {
|
|
|
978
983
|
};
|
|
979
984
|
}
|
|
980
985
|
function getDeleteOneData(table) {
|
|
986
|
+
getCtx().log.debug({ table }, "getDeleteOneData() start");
|
|
981
987
|
return {
|
|
982
988
|
kind: "deleteOne",
|
|
983
989
|
table,
|
|
@@ -985,6 +991,7 @@ function getDeleteOneData(table) {
|
|
|
985
991
|
};
|
|
986
992
|
}
|
|
987
993
|
function getDeleteListData(table) {
|
|
994
|
+
getCtx().log.debug({ table }, "getDeleteListData() start");
|
|
988
995
|
const typeWhereName = getTypeWhereName(table);
|
|
989
996
|
return {
|
|
990
997
|
kind: "deleteList",
|
|
@@ -994,10 +1001,12 @@ function getDeleteListData(table) {
|
|
|
994
1001
|
};
|
|
995
1002
|
}
|
|
996
1003
|
async function getTypeWhere(table, name) {
|
|
1004
|
+
getCtx().log.debug({ table, name }, "getTypeWhere() start");
|
|
997
1005
|
const jsonSchemaWhere = await getJSONSchemaWhere(table);
|
|
998
1006
|
return (0, json_schema_to_typescript_1.compile)(jsonSchemaWhere, name, json2TsOpts);
|
|
999
1007
|
}
|
|
1000
1008
|
async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMappedFields) {
|
|
1009
|
+
getCtx().log.debug({ table, name }, "getTypeDataPost() start");
|
|
1001
1010
|
const primaryColumn = await getPrimaryColumn(table);
|
|
1002
1011
|
const tableMeta = (await getTableMeta(table)).filter((x) => x.Field !== primaryColumn.name);
|
|
1003
1012
|
const nullable = tableMeta.reduce((acc, m) => ({
|
|
@@ -1068,6 +1077,7 @@ async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMapped
|
|
|
1068
1077
|
return type;
|
|
1069
1078
|
}
|
|
1070
1079
|
async function getTypeDataPatch(table, name, specialCaseUuidColumn, includeMappedFields) {
|
|
1080
|
+
getCtx().log.debug({ table, name }, "getTypeDataPatch() start");
|
|
1071
1081
|
const primaryColumn = await getPrimaryColumn(table);
|
|
1072
1082
|
let tableMeta = (await getTableMeta(table)).filter((x) => x.Field !== primaryColumn.name);
|
|
1073
1083
|
if (specialCaseUuidColumn) {
|
|
@@ -1134,6 +1144,7 @@ function unwrapJSONType(type) {
|
|
|
1134
1144
|
return type;
|
|
1135
1145
|
}
|
|
1136
1146
|
async function getMappedFields(table) {
|
|
1147
|
+
getCtx().log.debug({ table }, "getMappedFields() start");
|
|
1137
1148
|
const relationsManyToOne = await getRelationsManyToOne(table).then((xs) => xs.filter((x) => x.foreignKey.endsWith("Id")));
|
|
1138
1149
|
let out = [];
|
|
1139
1150
|
for (let x of relationsManyToOne) {
|
|
@@ -1157,6 +1168,7 @@ async function getMappedFields(table) {
|
|
|
1157
1168
|
return out;
|
|
1158
1169
|
}
|
|
1159
1170
|
async function getJSONSchemaWhere(table) {
|
|
1171
|
+
getCtx().log.debug({ table }, "getJSONSchemaWhere() start");
|
|
1160
1172
|
const whereSchemaName = `_Where${changeCase.pascalCase(table)}`;
|
|
1161
1173
|
const defWhere = {
|
|
1162
1174
|
oneOf: [
|
|
@@ -1310,9 +1322,11 @@ async function getJSONSchemaWhere(table) {
|
|
|
1310
1322
|
};
|
|
1311
1323
|
}
|
|
1312
1324
|
async function getTypeOrderBy(table, name) {
|
|
1325
|
+
getCtx().log.debug({ table, name }, "getTypeOrderBy() start");
|
|
1313
1326
|
return (0, json_schema_to_typescript_1.compile)((await getJSONSchemaOrderBy(table, name)), name, json2TsOpts);
|
|
1314
1327
|
}
|
|
1315
1328
|
async function getJSONSchemaOrderBy(table, name) {
|
|
1329
|
+
getCtx().log.debug({ table, name }, "getJSONSchemaOrderBy() start");
|
|
1316
1330
|
const fieldNames = await getTableMeta(table).then((xs) => xs.map((x) => x.Field));
|
|
1317
1331
|
const def = {
|
|
1318
1332
|
oneOf: fieldNames.map((k) => ({
|
|
@@ -1392,6 +1406,7 @@ export type TUpdateOperationsNumber = {$increment: number} | {$decrement: number
|
|
|
1392
1406
|
return prettier.format(src, { parser: "typescript" });
|
|
1393
1407
|
}
|
|
1394
1408
|
async function getTypeFields(table, name, includeMappedFields) {
|
|
1409
|
+
getCtx().log.debug({ table, name }, "getTypeFields() start");
|
|
1395
1410
|
const scalarKeys = Object.keys(getJSONSchemaObjProperties(await getTableMeta(table)));
|
|
1396
1411
|
const relations = await getRelationInfo(table);
|
|
1397
1412
|
const mappedFields = includeMappedFields ? await getMappedFields(table) : [];
|
|
@@ -1454,6 +1469,7 @@ async function getTypeFields(table, name, includeMappedFields) {
|
|
|
1454
1469
|
return type;
|
|
1455
1470
|
}
|
|
1456
1471
|
async function getTypeReturnBase(table, name, includeMappedFields) {
|
|
1472
|
+
getCtx().log.debug({ table, name }, "getTypeReturnBase() start");
|
|
1457
1473
|
const tableMeta = await getTableMeta(table);
|
|
1458
1474
|
const scalarProperties = getJSONSchemaObjProperties(tableMeta);
|
|
1459
1475
|
const relations = await getRelationInfo(table);
|
|
@@ -1619,8 +1635,12 @@ async function getArtifacts(tables, includeMappedFields, specialCaseUuidColumn)
|
|
|
1619
1635
|
return artifacts;
|
|
1620
1636
|
}
|
|
1621
1637
|
const getRelationInfo = (0, memoize_1.default)(async function getRelationInfo(table) {
|
|
1638
|
+
const ctx = getCtx();
|
|
1639
|
+
ctx.log.debug({ table }, "getRelationInfo() start");
|
|
1622
1640
|
const relationsManyToOne = await getRelationsManyToOne(table);
|
|
1641
|
+
ctx.log.debug({ table, count: relationsManyToOne.length }, "getRelationInfo() getRelationsManyToOne done");
|
|
1623
1642
|
const relationsOneToMany = await getRelationsOneToMany(table);
|
|
1643
|
+
ctx.log.debug({ table, count: relationsOneToMany.length }, "getRelationInfo() getRelationsOneToMany done");
|
|
1624
1644
|
let out = [];
|
|
1625
1645
|
out = out.concat(relationsManyToOne.reduce((acc, x) => {
|
|
1626
1646
|
if (!x.foreignKey.endsWith("Id")) {
|
|
@@ -1638,6 +1658,7 @@ const getRelationInfo = (0, memoize_1.default)(async function getRelationInfo(ta
|
|
|
1638
1658
|
});
|
|
1639
1659
|
return acc;
|
|
1640
1660
|
}, []));
|
|
1661
|
+
ctx.log.debug({ table, manyToOneOutCount: out.length }, "getRelationInfo() many-to-one concat done");
|
|
1641
1662
|
const relationsOneToManyDuplicates = (0, getDuplicates_1.getDuplicates)(relationsOneToMany.map((x) => x.referencedTable));
|
|
1642
1663
|
out = out.concat(relationsOneToMany.reduce((acc, x) => {
|
|
1643
1664
|
if (!x.referencedKey.endsWith("Id")) {
|
|
@@ -1665,7 +1686,11 @@ const getRelationInfo = (0, memoize_1.default)(async function getRelationInfo(ta
|
|
|
1665
1686
|
});
|
|
1666
1687
|
return acc;
|
|
1667
1688
|
}, []));
|
|
1668
|
-
|
|
1689
|
+
ctx.log.debug({ table, afterOneToManyCount: out.length }, "getRelationInfo() one-to-many concat done");
|
|
1690
|
+
ctx.log.debug({ table }, "getRelationInfo() getJunctionTables() calling");
|
|
1691
|
+
const junctionTables = await getJunctionTables();
|
|
1692
|
+
ctx.log.debug({ table, junctionTableCount: junctionTables.length }, "getRelationInfo() getJunctionTables() done");
|
|
1693
|
+
const relationsManyToMany = junctionTables.reduce((acc, x) => {
|
|
1669
1694
|
const dataForParentTable = x.relations.find((r) => r.referencedTable === table);
|
|
1670
1695
|
if (dataForParentTable == null) {
|
|
1671
1696
|
return acc;
|
|
@@ -1685,8 +1710,10 @@ const getRelationInfo = (0, memoize_1.default)(async function getRelationInfo(ta
|
|
|
1685
1710
|
});
|
|
1686
1711
|
return acc;
|
|
1687
1712
|
}, []);
|
|
1713
|
+
ctx.log.debug({ table, manyToManyCount: relationsManyToMany.length }, "getRelationInfo() many-to-many reduce done");
|
|
1688
1714
|
out = out.concat(relationsManyToMany);
|
|
1689
1715
|
out = _.sortBy([(x) => x.table, (x) => x.name], out);
|
|
1716
|
+
ctx.log.debug({ table, totalCount: out.length }, "getRelationInfo() done");
|
|
1690
1717
|
return out;
|
|
1691
1718
|
}, (table) => getCtx().runId + ":" + table);
|
|
1692
1719
|
function getRelationManyToOneFieldName(x) {
|
|
@@ -1713,6 +1740,7 @@ const getJunctionTables = (0, memoize_1.default)(async function getJunctionTable
|
|
|
1713
1740
|
// `from` relations
|
|
1714
1741
|
// https://stackoverflow.com/a/54732547
|
|
1715
1742
|
const getRelationsManyToOne = (0, memoize_1.default)(async function getRelationsManyToOne(table) {
|
|
1743
|
+
getCtx().log.debug({ table }, "getRelationsManyToOne() start");
|
|
1716
1744
|
const { dialect, query } = getCtx();
|
|
1717
1745
|
const tableMeta = await getTableMeta(table);
|
|
1718
1746
|
let rs;
|
|
@@ -1758,6 +1786,7 @@ const getRelationsManyToOne = (0, memoize_1.default)(async function getRelations
|
|
|
1758
1786
|
}, (table) => getCtx().runId + ":" + table);
|
|
1759
1787
|
// `to` relations
|
|
1760
1788
|
const getRelationsOneToMany = (0, memoize_1.default)(async function getRelationsOneToMany(table) {
|
|
1789
|
+
getCtx().log.debug({ table }, "getRelationsOneToMany() start");
|
|
1761
1790
|
const { dialect, query } = getCtx();
|
|
1762
1791
|
let rs;
|
|
1763
1792
|
if (dialect === "mysql") {
|
|
@@ -1801,6 +1830,7 @@ const getRelationsOneToMany = (0, memoize_1.default)(async function getRelations
|
|
|
1801
1830
|
return _.sortBy([(x) => x.referencedTable, (x) => x.referencedKey, (x) => x.foreignKey], xs);
|
|
1802
1831
|
}, (table) => getCtx().runId + ":" + table);
|
|
1803
1832
|
async function getPrimaryColumn(table) {
|
|
1833
|
+
getCtx().log.debug({ table }, "getPrimaryColumn() start");
|
|
1804
1834
|
const tableMeta = await getTableMeta(table);
|
|
1805
1835
|
const columns = tableMeta.filter((x) => x.Key === "PRI");
|
|
1806
1836
|
if (columns.length !== 1) {
|