@quillsql/node 0.5.9 → 0.6.0

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/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- import QuillServerClient from "./clients/QuillServerClient";
2
1
  import { CacheCredentials } from "./models/Cache";
3
2
  import {
4
3
  AdditionalProcessing,
@@ -92,6 +91,11 @@ export class Quill {
92
91
  }: QuillQueryParams): Promise<QuillQueryResult> {
93
92
  this.targetConnection.orgId = orgId;
94
93
  let responseMetadata: any = {};
94
+
95
+ if (!metadata.task) {
96
+ return { error: "Missing task.", status: "error", data: {} };
97
+ }
98
+
95
99
  try {
96
100
  const preQueryResults = metadata.preQueries
97
101
  ? await this.runQueries(
@@ -114,7 +118,11 @@ export class Quill {
114
118
  viewQuery: metadata.preQueries ? metadata.preQueries[0] : undefined,
115
119
  });
116
120
  if (response.error) {
117
- return { status: "error", error: response.error };
121
+ return {
122
+ status: "error",
123
+ error: response.error,
124
+ data: response.metadata || {},
125
+ };
118
126
  }
119
127
  // if there is no metadata object in the response, create one
120
128
  if (response.metadata) {
@@ -153,8 +161,8 @@ export class Quill {
153
161
  } catch (err) {
154
162
  return {
155
163
  status: "error",
156
- error: (err as any).message,
157
- data: responseMetadata,
164
+ error: (err as any).response?.data?.error ?? (err as any).message,
165
+ data: responseMetadata || {},
158
166
  };
159
167
  }
160
168
  }
@@ -177,6 +185,7 @@ export class Quill {
177
185
  queryResults: [],
178
186
  };
179
187
  }
188
+
180
189
  if (runQueryConfig?.arrayToMap) {
181
190
  const mappedArray = await mapQueries(queries, this.targetConnection);
182
191
  return { ...results, queryResults: [], mappedArray };
@@ -221,8 +230,13 @@ export class Quill {
221
230
  };
222
231
  });
223
232
  return { ...table, columns: columns, rows: queryResult.rows };
224
- } catch (err) {
225
- return { ...table, error: "Error fetching columns" };
233
+ } catch (err: any) {
234
+ return {
235
+ ...table,
236
+ error: err.message
237
+ ? `Error fetching columns: ${err.message}`
238
+ : "Error fetching columns",
239
+ };
226
240
  }
227
241
  }),
228
242
  );
@@ -4,7 +4,7 @@ export interface Mapable {
4
4
  key: string,
5
5
  value: string,
6
6
  type?: string,
7
- ttl?: number
7
+ ttl?: number,
8
8
  ): Promise<string | null>;
9
9
  }
10
10
 
@@ -15,4 +15,4 @@ export interface CacheCredentials {
15
15
  port: string;
16
16
  cacheType: string;
17
17
  ttl?: number;
18
- }
18
+ }
@@ -4,18 +4,32 @@ export class PgError extends Error {
4
4
  hint?: string;
5
5
  position?: string;
6
6
  // Add other properties if needed
7
+ constructor(
8
+ message: string,
9
+ detail?: string,
10
+ hint?: string,
11
+ position?: string,
12
+ code?: string,
13
+ ) {
14
+ super(message);
15
+ this.code = code;
16
+ this.detail = detail;
17
+ this.hint = hint;
18
+ this.position = position;
19
+ }
7
20
  }
8
21
 
9
22
  export function isSuperset(obj: any, baseClass: any): boolean {
10
- // Get the property names of the base class
11
- const baseProps = Object.getOwnPropertyNames(baseClass.prototype);
23
+ // Get the property names of the base class instance
24
+ const baseInstance = new baseClass();
25
+ const baseProps = Object.keys(baseInstance);
12
26
 
13
27
  // Check if the object has all the properties of the base class
14
28
  for (const prop of baseProps) {
15
- if (!obj.hasOwnProperty(prop)) {
29
+ if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
16
30
  return false;
17
31
  }
18
32
  }
19
33
 
20
34
  return true;
21
- }
35
+ }
@@ -1,6 +1,6 @@
1
1
  import { CachedConnection } from "../db/CachedConnection";
2
2
 
3
- interface TableSchemaInfo {
3
+ export interface TableSchemaInfo {
4
4
  fieldType: string;
5
5
  name: string;
6
6
  displayName: string;
@@ -9,7 +9,7 @@ interface TableSchemaInfo {
9
9
 
10
10
  export function removeFields(queryResults: any, fieldsToRemove: string[]): any {
11
11
  const fields = queryResults.fields.filter(
12
- (field: { name: any }) => !fieldsToRemove.includes(field.name)
12
+ (field: { name: any }) => !fieldsToRemove.includes(field.name),
13
13
  );
14
14
  const rows = queryResults.rows.map((row: any) => {
15
15
  fieldsToRemove.forEach((field) => {
@@ -22,7 +22,7 @@ export function removeFields(queryResults: any, fieldsToRemove: string[]): any {
22
22
 
23
23
  export async function mapQueries(
24
24
  queries: string[],
25
- targetConnection: CachedConnection
25
+ targetConnection: CachedConnection,
26
26
  ): Promise<any[]> {
27
27
  const mappedArray = [];
28
28
  for (let i = 0; i < queries.length; i++) {
@@ -10,4 +10,4 @@ export function depluralize(text: string): string {
10
10
  return text.slice(0, -1);
11
11
  }
12
12
  return text;
13
- }
13
+ }