@technicity/data-service-generator 0.23.0-next.10 → 0.23.0-next.11
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 +17 -18
- package/package.json +1 -1
|
@@ -107,10 +107,10 @@ async function generate(input) {
|
|
|
107
107
|
}
|
|
108
108
|
ctx.log.debug({ tableCount: tables.length, tables }, "tables after filter");
|
|
109
109
|
const data = await Promise.all(tables.flatMap((x) => [
|
|
110
|
-
getGetOneData(x, includeMappedFields),
|
|
110
|
+
getGetOneData(x, includeMappedFields, tables),
|
|
111
111
|
getGetListData(x),
|
|
112
112
|
getGetListPaginatedData(x),
|
|
113
|
-
getPostOneData(x, specialCaseUuidColumn, includeMappedFields),
|
|
113
|
+
getPostOneData(x, specialCaseUuidColumn, includeMappedFields, tables),
|
|
114
114
|
getPatchOneData(x, specialCaseUuidColumn, includeMappedFields),
|
|
115
115
|
getPatchListData(x),
|
|
116
116
|
getDeleteOneData(x),
|
|
@@ -884,16 +884,16 @@ function getTypeOrderByName(table) {
|
|
|
884
884
|
function getTypeDataPostName(table) {
|
|
885
885
|
return "DataPost" + changeCase.pascalCase(table);
|
|
886
886
|
}
|
|
887
|
-
async function getGetOneData(table, includeMappedFields) {
|
|
887
|
+
async function getGetOneData(table, includeMappedFields, tables) {
|
|
888
888
|
const typeFieldsName = getTypeFieldsName(table);
|
|
889
889
|
const typeReturnBaseName = getTypeReturnBaseName(table);
|
|
890
890
|
return {
|
|
891
891
|
kind: "getOne",
|
|
892
892
|
table,
|
|
893
893
|
methodName: "get" + changeCase.pascalCase(table),
|
|
894
|
-
typeFields: await getTypeFields(table, typeFieldsName, includeMappedFields),
|
|
894
|
+
typeFields: await getTypeFields(table, typeFieldsName, includeMappedFields, tables),
|
|
895
895
|
typeFieldsName,
|
|
896
|
-
typeReturnBase: await getTypeReturnBase(table, typeReturnBaseName, includeMappedFields),
|
|
896
|
+
typeReturnBase: await getTypeReturnBase(table, typeReturnBaseName, includeMappedFields, tables),
|
|
897
897
|
typeReturnBaseName
|
|
898
898
|
};
|
|
899
899
|
}
|
|
@@ -931,7 +931,7 @@ async function getGetListPaginatedData(table) {
|
|
|
931
931
|
typeOrderByName
|
|
932
932
|
};
|
|
933
933
|
}
|
|
934
|
-
async function getPostOneData(table, specialCaseUuidColumn, includeMappedFields) {
|
|
934
|
+
async function getPostOneData(table, specialCaseUuidColumn, includeMappedFields, tables) {
|
|
935
935
|
const typeFieldsName = getTypeFieldsName(table);
|
|
936
936
|
const typeReturnBaseName = getTypeReturnBaseName(table);
|
|
937
937
|
const typeDataName = getTypeDataPostName(table);
|
|
@@ -941,7 +941,7 @@ async function getPostOneData(table, specialCaseUuidColumn, includeMappedFields)
|
|
|
941
941
|
methodName: "post" + changeCase.pascalCase(table),
|
|
942
942
|
typeFieldsName,
|
|
943
943
|
typeReturnBaseName,
|
|
944
|
-
typeData: await getTypeDataPost(table, typeDataName, specialCaseUuidColumn, includeMappedFields),
|
|
944
|
+
typeData: await getTypeDataPost(table, typeDataName, specialCaseUuidColumn, includeMappedFields, tables),
|
|
945
945
|
typeDataName
|
|
946
946
|
};
|
|
947
947
|
}
|
|
@@ -996,7 +996,7 @@ async function getTypeWhere(table, name) {
|
|
|
996
996
|
const jsonSchemaWhere = await getJSONSchemaWhere(table);
|
|
997
997
|
return (0, json_schema_to_typescript_1.compile)(jsonSchemaWhere, name, json2TsOpts);
|
|
998
998
|
}
|
|
999
|
-
async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMappedFields) {
|
|
999
|
+
async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMappedFields, tables) {
|
|
1000
1000
|
const primaryColumn = await getPrimaryColumn(table);
|
|
1001
1001
|
const tableMeta = (await getTableMeta(table)).filter((x) => x.Field !== primaryColumn.name);
|
|
1002
1002
|
const nullable = tableMeta.reduce((acc, m) => ({
|
|
@@ -1009,7 +1009,7 @@ async function getTypeDataPost(table, name, specialCaseUuidColumn, includeMapped
|
|
|
1009
1009
|
}), {});
|
|
1010
1010
|
let properties = getJSONSchemaObjProperties(tableMeta);
|
|
1011
1011
|
let notRequiredList = [];
|
|
1012
|
-
const oneToManyRelations = (await getRelationInfo(table)).filter((x) => x.type === "one-to-many__many-to-one" && x.kind === "one-to-many");
|
|
1012
|
+
const oneToManyRelations = (await getRelationInfo(table, tables)).filter((x) => x.type === "one-to-many__many-to-one" && x.kind === "one-to-many");
|
|
1013
1013
|
const mappedFields = includeMappedFields ? await getMappedFields(table) : [];
|
|
1014
1014
|
let mappedFieldsMap = new Map();
|
|
1015
1015
|
if (includeMappedFields) {
|
|
@@ -1390,9 +1390,9 @@ export type TUpdateOperationsNumber = {$increment: number} | {$decrement: number
|
|
|
1390
1390
|
`;
|
|
1391
1391
|
return prettier.format(src, { parser: "typescript" });
|
|
1392
1392
|
}
|
|
1393
|
-
async function getTypeFields(table, name, includeMappedFields) {
|
|
1393
|
+
async function getTypeFields(table, name, includeMappedFields, tables) {
|
|
1394
1394
|
const scalarKeys = Object.keys(getJSONSchemaObjProperties(await getTableMeta(table)));
|
|
1395
|
-
const relations = await getRelationInfo(table);
|
|
1395
|
+
const relations = await getRelationInfo(table, tables);
|
|
1396
1396
|
const mappedFields = includeMappedFields ? await getMappedFields(table) : [];
|
|
1397
1397
|
const keyWhere = "$where";
|
|
1398
1398
|
const keyOrderBy = "$orderBy";
|
|
@@ -1452,10 +1452,10 @@ async function getTypeFields(table, name, includeMappedFields) {
|
|
|
1452
1452
|
type = imports + "\n\n" + type;
|
|
1453
1453
|
return type;
|
|
1454
1454
|
}
|
|
1455
|
-
async function getTypeReturnBase(table, name, includeMappedFields) {
|
|
1455
|
+
async function getTypeReturnBase(table, name, includeMappedFields, tables) {
|
|
1456
1456
|
const tableMeta = await getTableMeta(table);
|
|
1457
1457
|
const scalarProperties = getJSONSchemaObjProperties(tableMeta);
|
|
1458
|
-
const relations = await getRelationInfo(table);
|
|
1458
|
+
const relations = await getRelationInfo(table, tables);
|
|
1459
1459
|
const mappedFields = includeMappedFields ? await getMappedFields(table) : [];
|
|
1460
1460
|
const jsonSchemaReturn = {
|
|
1461
1461
|
type: "object",
|
|
@@ -1514,7 +1514,7 @@ async function getArtifacts(tables, includeMappedFields, specialCaseUuidColumn)
|
|
|
1514
1514
|
getShowCreateTable(table)
|
|
1515
1515
|
]);
|
|
1516
1516
|
const scalarFields = tableMeta.map((x) => x.Field);
|
|
1517
|
-
const relationInfo = await getRelationInfo(table);
|
|
1517
|
+
const relationInfo = await getRelationInfo(table, tables);
|
|
1518
1518
|
const relationFields = relationInfo.reduce((acc, x) => {
|
|
1519
1519
|
if (x.type === "one-to-many__many-to-one") {
|
|
1520
1520
|
acc[x.name] = {
|
|
@@ -1617,7 +1617,7 @@ async function getArtifacts(tables, includeMappedFields, specialCaseUuidColumn)
|
|
|
1617
1617
|
}, {});
|
|
1618
1618
|
return artifacts;
|
|
1619
1619
|
}
|
|
1620
|
-
const getRelationInfo = (0, memoize_1.default)(async function getRelationInfo(table) {
|
|
1620
|
+
const getRelationInfo = (0, memoize_1.default)(async function getRelationInfo(table, tables) {
|
|
1621
1621
|
const relationsManyToOne = await getRelationsManyToOne(table);
|
|
1622
1622
|
const relationsOneToMany = await getRelationsOneToMany(table);
|
|
1623
1623
|
let out = [];
|
|
@@ -1664,7 +1664,7 @@ const getRelationInfo = (0, memoize_1.default)(async function getRelationInfo(ta
|
|
|
1664
1664
|
});
|
|
1665
1665
|
return acc;
|
|
1666
1666
|
}, []));
|
|
1667
|
-
const relationsManyToMany = (await getJunctionTables()).reduce((acc, x) => {
|
|
1667
|
+
const relationsManyToMany = (await getJunctionTables(tables)).reduce((acc, x) => {
|
|
1668
1668
|
const dataForParentTable = x.relations.find((r) => r.referencedTable === table);
|
|
1669
1669
|
if (dataForParentTable == null) {
|
|
1670
1670
|
return acc;
|
|
@@ -1692,8 +1692,7 @@ function getRelationManyToOneFieldName(x) {
|
|
|
1692
1692
|
return changeCase.camelCase(x.foreignKey.replace(new RegExp(x.referencedKey + "$", "i"), ""));
|
|
1693
1693
|
}
|
|
1694
1694
|
// TODO: not sure if this logic is correct
|
|
1695
|
-
const getJunctionTables = (0, memoize_1.default)(async function getJunctionTables() {
|
|
1696
|
-
const tables = await getTableNames();
|
|
1695
|
+
const getJunctionTables = (0, memoize_1.default)(async function getJunctionTables(tables) {
|
|
1697
1696
|
return (await Promise.all(tables.map(async (table) => {
|
|
1698
1697
|
const relations = await getRelationsManyToOne(table);
|
|
1699
1698
|
if (relations.length === 2 &&
|