@quillsql/node 0.3.5 → 0.3.6

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/index.js CHANGED
@@ -32,6 +32,7 @@ class QuillClass {
32
32
  this.targetPool = new CachedPools_1.CachedPool({ connectionString: this.connectionString, ssl: this.ssl }, cache);
33
33
  }
34
34
  query({ orgId, metadata }) {
35
+ var _a, _b;
35
36
  return __awaiter(this, void 0, void 0, function* () {
36
37
  this.targetPool.orgId = orgId;
37
38
  try {
@@ -39,11 +40,21 @@ class QuillClass {
39
40
  const preQueryResults = yield this.runQueries(metadata.preQueries);
40
41
  const response = yield this.postQuill(metadata.task, Object.assign(Object.assign({}, metadata), { orgId,
41
42
  preQueryResults }));
42
- const results = yield this.runQueries(response.queries, response.runQueryConfig);
43
43
  // if there is no metadata object in the response, create one
44
44
  if (!response.metadata) {
45
45
  response.metadata = {};
46
46
  }
47
+ const results = yield this.runQueries(response.queries, response.metadata.runQueryConfig);
48
+ // QUICK JANKY FIX TO UPDATE METADATA AFTER GETTING MAPPED ARRAYS
49
+ if (results.mappedArray &&
50
+ ((_b = (_a = response.metadata) === null || _a === void 0 ? void 0 : _a.runQueryConfig) === null || _b === void 0 ? void 0 : _b.arrayToMap)) {
51
+ const arrayToMap = response.metadata.runQueryConfig.arrayToMap;
52
+ results.mappedArray.forEach((array, index) => {
53
+ response.metadata[arrayToMap.arrayName][index][arrayToMap.field] =
54
+ array;
55
+ });
56
+ delete results.mappedArray;
57
+ }
47
58
  // if there is a single query array in queryResults and the rows and field objects to metadata
48
59
  if ((results === null || results === void 0 ? void 0 : results.queryResults.length) === 1) {
49
60
  const queryResults = results.queryResults[0];
@@ -71,7 +82,8 @@ class QuillClass {
71
82
  if (!queries)
72
83
  return Object.assign(Object.assign({}, results), { queryResults: [] });
73
84
  if (runQueryConfig === null || runQueryConfig === void 0 ? void 0 : runQueryConfig.arrayToMap) {
74
- return Object.assign(Object.assign({}, results), { mappedQueries: yield (0, RunQueryProcesses_1.mapQueries)(queries, runQueryConfig.arrayToMap, this.targetPool) });
85
+ const mappedArray = yield (0, RunQueryProcesses_1.mapQueries)(queries, runQueryConfig.arrayToMap, this.targetPool);
86
+ return Object.assign(Object.assign({}, results), { queryResults: [], mappedArray });
75
87
  }
76
88
  else {
77
89
  const queryResults = yield Promise.all(queries.map((query) => __awaiter(this, void 0, void 0, function* () {
@@ -37,12 +37,12 @@ function removeFields(queryResults, fieldsToRemove) {
37
37
  exports.removeFields = removeFields;
38
38
  function mapQueries(queries, arrayToMap, targetPool) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
- let arrayToMapResult = [];
40
+ const mappedArray = [];
41
41
  for (let i = 0; i < queries.length; i++) {
42
42
  const queryResult = yield targetPool.query(queries[i]);
43
- arrayToMapResult.push(Object.assign(Object.assign({}, arrayToMap.arr[i]), { [arrayToMap.field]: queryResult.rows }));
43
+ mappedArray.push(queryResult.rows);
44
44
  }
45
- return arrayToMapResult;
45
+ return mappedArray;
46
46
  });
47
47
  }
48
48
  exports.mapQueries = mapQueries;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/node",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Quill's client SDK for node backends.",
5
5
  "main": "dist/index.js",
6
6
  "module": "./dist/index.js",
package/src/index.ts CHANGED
@@ -61,14 +61,26 @@ export default class QuillClass {
61
61
  orgId,
62
62
  preQueryResults,
63
63
  });
64
- const results = await this.runQueries(
65
- response.queries,
66
- response.runQueryConfig
67
- );
68
64
  // if there is no metadata object in the response, create one
69
65
  if (!response.metadata) {
70
66
  response.metadata = {};
71
67
  }
68
+ const results = await this.runQueries(
69
+ response.queries,
70
+ response.metadata.runQueryConfig
71
+ );
72
+ // QUICK JANKY FIX TO UPDATE METADATA AFTER GETTING MAPPED ARRAYS
73
+ if (
74
+ results.mappedArray &&
75
+ response.metadata?.runQueryConfig?.arrayToMap
76
+ ) {
77
+ const arrayToMap = response.metadata.runQueryConfig.arrayToMap;
78
+ results.mappedArray.forEach((array: any, index: number) => {
79
+ response.metadata[arrayToMap.arrayName][index][arrayToMap.field] =
80
+ array;
81
+ });
82
+ delete results.mappedArray;
83
+ }
72
84
  // if there is a single query array in queryResults and the rows and field objects to metadata
73
85
  if (results?.queryResults.length === 1) {
74
86
  const queryResults = results.queryResults[0];
@@ -96,14 +108,12 @@ export default class QuillClass {
96
108
  let results: any;
97
109
  if (!queries) return { ...results, queryResults: [] };
98
110
  if (runQueryConfig?.arrayToMap) {
99
- return {
100
- ...results,
101
- mappedQueries: await mapQueries(
102
- queries,
103
- runQueryConfig.arrayToMap,
104
- this.targetPool
105
- ),
106
- };
111
+ const mappedArray = await mapQueries(
112
+ queries,
113
+ runQueryConfig.arrayToMap,
114
+ this.targetPool
115
+ );
116
+ return { ...results, queryResults: [], mappedArray };
107
117
  } else {
108
118
  const queryResults = await Promise.all(
109
119
  queries.map(async (query) => {
@@ -58,7 +58,7 @@ export interface QuillConfig {
58
58
  export interface AdditionalProcessing {
59
59
  getSchema?: boolean;
60
60
  removeFields?: string[];
61
- arrayToMap?: { arr: any; field: string };
61
+ arrayToMap?: { arrayName: string; field: string };
62
62
  }
63
63
 
64
64
  export interface QuillClientResponse {
@@ -43,16 +43,13 @@ export function removeFields(queryResults: any, fieldsToRemove: string[]): any {
43
43
 
44
44
  export async function mapQueries(
45
45
  queries: string[],
46
- arrayToMap: { arr: any; field: string },
46
+ arrayToMap: { arrayName: string; field: string },
47
47
  targetPool: CachedPool
48
- ) {
49
- let arrayToMapResult = [];
48
+ ): Promise<any[]> {
49
+ const mappedArray = [];
50
50
  for (let i = 0; i < queries.length; i++) {
51
51
  const queryResult = await targetPool.query(queries[i]);
52
- arrayToMapResult.push({
53
- ...arrayToMap.arr[i],
54
- [arrayToMap.field]: queryResult.rows,
55
- });
52
+ mappedArray.push(queryResult.rows);
56
53
  }
57
- return arrayToMapResult;
54
+ return mappedArray;
58
55
  }