@technicity/data-service-generator 0.23.0-next.12 → 0.23.0-next.13

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