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

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