@koralium/base-client 1.0.5 → 1.3.0-alpha10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
- export interface QueryOptions {
2
- parameters?: {} | null;
3
- headers?: {};
4
- extraData?: {};
5
- }
1
+ export interface QueryOptions {
2
+ parameters?: {} | null;
3
+ headers?: {};
4
+ extraData?: {};
5
+ }
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=queryOptions.js.map
@@ -1,9 +1,16 @@
1
- export declare class Metadata {
2
- customMetadata: {};
3
- constructor(customMetadata: {});
4
- }
5
- export declare class QueryResult {
6
- rows: Array<{}>;
7
- metadata: Metadata;
8
- constructor(rows: Array<{}>, metadata: Metadata);
9
- }
1
+ export declare class Metadata {
2
+ customMetadata: {};
3
+ constructor(customMetadata: {});
4
+ }
5
+ export interface ResultArray<T> extends Iterable<T> {
6
+ length: number;
7
+ get(index: number): T;
8
+ toArray: () => Array<T>;
9
+ }
10
+ export declare class QueryResult<T extends {
11
+ [key: string]: any;
12
+ } = any> {
13
+ rows: ResultArray<T>;
14
+ metadata: Metadata;
15
+ constructor(rows: ResultArray<T>, metadata: Metadata);
16
+ }
@@ -1,30 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryResult = exports.Metadata = void 0;
4
- /*
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- class Metadata {
18
- constructor(customMetadata) {
19
- this.customMetadata = customMetadata;
20
- }
21
- }
22
- exports.Metadata = Metadata;
23
- class QueryResult {
24
- constructor(rows, metadata) {
25
- this.rows = rows;
26
- this.metadata = metadata;
27
- }
28
- }
29
- exports.QueryResult = QueryResult;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryResult = exports.Metadata = void 0;
4
+ /*
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ class Metadata {
18
+ constructor(customMetadata) {
19
+ this.customMetadata = customMetadata;
20
+ }
21
+ }
22
+ exports.Metadata = Metadata;
23
+ class QueryResult {
24
+ constructor(rows, metadata) {
25
+ this.rows = rows;
26
+ this.metadata = metadata;
27
+ }
28
+ }
29
+ exports.QueryResult = QueryResult;
30
30
  //# sourceMappingURL=queryResult.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"queryResult.js","sourceRoot":"","sources":["../src/queryResult.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,MAAa,QAAQ;IAGnB,YAAY,cAAkB;QAC5B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;CACF;AAND,4BAMC;AAED,MAAa,WAAW;IAItB,YAAY,IAAe,EAAE,QAAkB;QAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AARD,kCAQC"}
1
+ {"version":3,"file":"queryResult.js","sourceRoot":"","sources":["../src/queryResult.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,MAAa,QAAQ;IAGnB,YAAY,cAAkB;QAC5B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;CACF;AAND,4BAMC;AAQD,MAAa,WAAW;IAItB,YAAY,IAAoB,EAAE,QAAkB;QAClD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AARD,kCAQC"}
package/package.json CHANGED
@@ -1,31 +1,32 @@
1
- {
2
- "name": "@koralium/base-client",
3
- "version": "1.0.5",
4
- "main": "./lib/index.js",
5
- "license": "MIT",
6
- "scripts": {
7
- "build": "tsc --build",
8
- "clean": "tsc --build --clean",
9
- "test": "jest",
10
- "coverage": "jest --coverage",
11
- "publish-package": "npm publish --access public"
12
- },
13
- "devDependencies": {
14
- "@types/chai": "^4.2.11",
15
- "@types/google-protobuf": "^3.7.2",
16
- "@types/jest": "^26.0.24",
17
- "@types/node": "^14.0.14",
18
- "chai": "4.2.0",
19
- "chai-arrays": "^2.2.0",
20
- "cross-env": "5.2.0",
21
- "jest": "^26.1.0",
22
- "jest-editor-support": "^27.2.0",
23
- "jest-sonar-reporter": "^2.0.0",
24
- "neat-csv": "^5.2.0",
25
- "nyc": "14.1.1",
26
- "testcontainers": "^2.14.0",
27
- "ts-jest": "^26.1.1",
28
- "ts-node": "^8.10.2",
29
- "typescript": "^3.2.2"
30
- }
31
- }
1
+ {
2
+ "name": "@koralium/base-client",
3
+ "version": "1.3.0-alpha10",
4
+ "main": "./lib/index.js",
5
+ "license": "MIT",
6
+ "scripts": {
7
+ "build": "tsc --build",
8
+ "clean": "tsc --build --clean",
9
+ "test": "jest",
10
+ "coverage": "jest --coverage",
11
+ "publish-package": "npm publish --access public"
12
+ },
13
+ "devDependencies": {
14
+ "@types/chai": "^4.2.11",
15
+ "@types/google-protobuf": "^3.7.2",
16
+ "@types/jest": "^26.0.24",
17
+ "@types/node": "^14.0.14",
18
+ "chai": "4.2.0",
19
+ "chai-arrays": "^2.2.0",
20
+ "cross-env": "5.2.0",
21
+ "jest": "^26.1.0",
22
+ "jest-editor-support": "^27.2.0",
23
+ "jest-sonar-reporter": "^2.0.0",
24
+ "neat-csv": "^5.2.0",
25
+ "nyc": "14.1.1",
26
+ "testcontainers": "^2.14.0",
27
+ "ts-jest": "^26.1.1",
28
+ "ts-node": "^8.10.2",
29
+ "typescript": "^3.2.2"
30
+ },
31
+ "gitHead": "f7ad9a5e126086a6a02a2d349f1d2d6546912a25"
32
+ }
@@ -1,200 +1,200 @@
1
- /*
2
- * Licensed under the Apache License, Version 2.0 (the "License");
3
- * you may not use this file except in compliance with the License.
4
- * You may obtain a copy of the License at
5
- *
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
- import { ParameterBuilder } from "./parameterBuilder";
15
-
16
-
17
- function isString(val: any): val is string {
18
- return typeof (val) === "string";
19
- }
20
-
21
- function isNumber(val: any): val is number {
22
- return typeof (val) === "number";
23
- }
24
-
25
- function isBoolean(val: any): val is boolean {
26
- return typeof (val) === 'boolean';
27
- }
28
-
29
- //Check if the value is a FieldQuery type
30
- function isFieldQuery(val: any): val is FieldQuery {
31
- return val.eq !== undefined ||
32
- val.lt !== undefined ||
33
- val.lte !== undefined ||
34
- val.gt !== undefined ||
35
- val.gte !== undefined ||
36
- val.startsWith !== undefined ||
37
- val.endsWith !== undefined ||
38
- val.contains !== undefined ||
39
- val.in !== undefined;
40
- }
41
-
42
-
43
- function writeSingleValue(arr: Array<string>, parameters: ParameterBuilder, val: string | number | boolean | undefined, operation: (string: string) => string): void {
44
- if (val !== undefined) {
45
- if (isString(val)) {
46
- const parameterName = parameters.getParameterName(val);
47
- arr.push(operation(`@${parameterName}`));
48
- }
49
- if (isNumber(val)) {
50
- arr.push(operation(`${val}`));
51
- }
52
- if (isBoolean(val)) {
53
- arr.push(operation(`${val}`));
54
- }
55
- }
56
- }
57
-
58
- function writeArrayValue(arr: Array<string>, parameters: ParameterBuilder, val: Array<string | number | boolean> | undefined, operation: (values: Array<string>) => string) {
59
- if (!!val && val.length > 0) {
60
- const arrayvalues: Array<string> = [];
61
- for(let v of val) {
62
- if (isString(v)) {
63
- const parameterName = parameters.getParameterName(v);
64
- arrayvalues.push(`@${parameterName}`);
65
- }
66
- if (isNumber(v) || isBoolean(v)) {
67
- arrayvalues.push(`${v}`);
68
- }
69
- }
70
- arr.push(operation(arrayvalues));
71
- }
72
- }
73
-
74
- export function writeFilter(filter: {} | FieldQuery): FilterResult {
75
-
76
- const parameters = new ParameterBuilder();
77
-
78
- const result = writeFilterWithParameterBuilder(parameters, filter);
79
-
80
- return new FilterResult(result, parameters.getParameters());
81
- }
82
-
83
- function writeSearchFilter(parameters: ParameterBuilder, value: SearchFilter): string {
84
-
85
- if (value.queryString !== undefined) {
86
-
87
- let output = "CONTAINS(";
88
-
89
- if (value.fields !== undefined) {
90
- output += `(${value.fields.join(', ')})`;
91
- }
92
- else{
93
- output += "*";
94
- }
95
- output += ", ";
96
- output += `@${parameters.getParameterName(value.queryString)}`;
97
- output += ")";
98
-
99
- return output;
100
- }
101
-
102
- return "";
103
- }
104
-
105
- export function writeFilterWithParameterBuilder(parameterBuilder: ParameterBuilder, filter: {} | FieldQuery): string {
106
- let operations: Array<string> = [];
107
- let andOperation = null;
108
- let orOperation = null;
109
-
110
- for (let [key, value] of Object.entries(filter)) {
111
-
112
- if (isFieldQuery(value)) {
113
- operations.push(writeFilterField(key, value, parameterBuilder));
114
- }
115
- if (key === "and") {
116
- andOperation = writeFilterWithParameterBuilder(parameterBuilder, value);
117
- }
118
- if (key === "or") {
119
- orOperation = writeFilterWithParameterBuilder(parameterBuilder, value);
120
- }
121
- if(key === "search") {
122
- operations.push(writeSearchFilter(parameterBuilder, value));
123
- }
124
- }
125
- let query = "";
126
-
127
- operations = operations.filter(x => x !== "");
128
-
129
- if(operations.length > 0) {
130
- query = `(${operations.join(" AND ")})`;
131
- }
132
-
133
- if (andOperation != null) {
134
- if(query !== "") {
135
- query += " AND ";
136
- }
137
- query += andOperation;
138
- }
139
- if (orOperation != null) {
140
- if(query !== "") {
141
- query += " OR ";
142
- }
143
- query += orOperation;
144
- }
145
-
146
- return query;
147
- }
148
-
149
- function writeFilterField(fieldName: string, field: FieldQuery, parameters: ParameterBuilder): string {
150
-
151
- const basicOperations: Array<string> = [];
152
-
153
- writeSingleValue(basicOperations, parameters, field.eq, c => `${fieldName} = ${c}`);
154
- writeSingleValue(basicOperations, parameters, field.gt, c => `${fieldName} > ${c}`);
155
- writeSingleValue(basicOperations, parameters, field.gte, c => `${fieldName} >= ${c}`);
156
- writeSingleValue(basicOperations, parameters, field.lt, c => `${fieldName} < ${c}`);
157
- writeSingleValue(basicOperations, parameters, field.lte, c => `${fieldName} <= ${c}`);
158
-
159
- writeArrayValue(basicOperations, parameters, field.in, c => `${fieldName} IN (${c.join(', ')})`);
160
-
161
- //string specific
162
- writeSingleValue(basicOperations, parameters, field.contains, c => `${fieldName} LIKE '%' + ${c} + '%'`);
163
- writeSingleValue(basicOperations, parameters, field.endsWith, c => `${fieldName} LIKE '%' + ${c}`);
164
- writeSingleValue(basicOperations, parameters, field.startsWith, c => `${fieldName} LIKE ${c} + '%'`);
165
-
166
- let basicQuery = basicOperations.join(" AND ");
167
-
168
- return basicQuery;
169
- }
170
-
171
- export class FilterResult {
172
- filter: string;
173
- parameters: {};
174
-
175
- constructor(filter: string, parameters: {}) {
176
- this.filter = filter;
177
- this.parameters = parameters;
178
- }
179
- }
180
-
181
- export class FieldQuery {
182
- eq: string | number | boolean | undefined;
183
-
184
- lt: string | number | undefined;
185
- lte: string | number | undefined;
186
- gt: string | number | undefined;
187
- gte: string | number | undefined;
188
-
189
- in: Array<string | number | boolean> | undefined;
190
-
191
- //String specific
192
- startsWith: string | number | undefined;
193
- endsWith: string | number | undefined;
194
- contains: string | number | undefined;
195
- }
196
-
197
- export class SearchFilter {
198
- queryString: string | undefined;
199
- fields: Array<string> | undefined;
1
+ /*
2
+ * Licensed under the Apache License, Version 2.0 (the "License");
3
+ * you may not use this file except in compliance with the License.
4
+ * You may obtain a copy of the License at
5
+ *
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software
9
+ * distributed under the License is distributed on an "AS IS" BASIS,
10
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the License for the specific language governing permissions and
12
+ * limitations under the License.
13
+ */
14
+ import { ParameterBuilder } from "./parameterBuilder";
15
+
16
+
17
+ function isString(val: any): val is string {
18
+ return typeof (val) === "string";
19
+ }
20
+
21
+ function isNumber(val: any): val is number {
22
+ return typeof (val) === "number";
23
+ }
24
+
25
+ function isBoolean(val: any): val is boolean {
26
+ return typeof (val) === 'boolean';
27
+ }
28
+
29
+ //Check if the value is a FieldQuery type
30
+ function isFieldQuery(val: any): val is FieldQuery {
31
+ return val.eq !== undefined ||
32
+ val.lt !== undefined ||
33
+ val.lte !== undefined ||
34
+ val.gt !== undefined ||
35
+ val.gte !== undefined ||
36
+ val.startsWith !== undefined ||
37
+ val.endsWith !== undefined ||
38
+ val.contains !== undefined ||
39
+ val.in !== undefined;
40
+ }
41
+
42
+
43
+ function writeSingleValue(arr: Array<string>, parameters: ParameterBuilder, val: string | number | boolean | undefined, operation: (string: string) => string): void {
44
+ if (val !== undefined) {
45
+ if (isString(val)) {
46
+ const parameterName = parameters.getParameterName(val);
47
+ arr.push(operation(`@${parameterName}`));
48
+ }
49
+ if (isNumber(val)) {
50
+ arr.push(operation(`${val}`));
51
+ }
52
+ if (isBoolean(val)) {
53
+ arr.push(operation(`${val}`));
54
+ }
55
+ }
56
+ }
57
+
58
+ function writeArrayValue(arr: Array<string>, parameters: ParameterBuilder, val: Array<string | number | boolean> | undefined, operation: (values: Array<string>) => string) {
59
+ if (!!val && val.length > 0) {
60
+ const arrayvalues: Array<string> = [];
61
+ for(let v of val) {
62
+ if (isString(v)) {
63
+ const parameterName = parameters.getParameterName(v);
64
+ arrayvalues.push(`@${parameterName}`);
65
+ }
66
+ if (isNumber(v) || isBoolean(v)) {
67
+ arrayvalues.push(`${v}`);
68
+ }
69
+ }
70
+ arr.push(operation(arrayvalues));
71
+ }
72
+ }
73
+
74
+ export function writeFilter(filter: {} | FieldQuery): FilterResult {
75
+
76
+ const parameters = new ParameterBuilder();
77
+
78
+ const result = writeFilterWithParameterBuilder(parameters, filter);
79
+
80
+ return new FilterResult(result, parameters.getParameters());
81
+ }
82
+
83
+ function writeSearchFilter(parameters: ParameterBuilder, value: SearchFilter): string {
84
+
85
+ if (value.queryString !== undefined) {
86
+
87
+ let output = "CONTAINS(";
88
+
89
+ if (value.fields !== undefined) {
90
+ output += `(${value.fields.join(', ')})`;
91
+ }
92
+ else{
93
+ output += "*";
94
+ }
95
+ output += ", ";
96
+ output += `@${parameters.getParameterName(value.queryString)}`;
97
+ output += ")";
98
+
99
+ return output;
100
+ }
101
+
102
+ return "";
103
+ }
104
+
105
+ export function writeFilterWithParameterBuilder(parameterBuilder: ParameterBuilder, filter: {} | FieldQuery): string {
106
+ let operations: Array<string> = [];
107
+ let andOperation = null;
108
+ let orOperation = null;
109
+
110
+ for (let [key, value] of Object.entries(filter)) {
111
+
112
+ if (isFieldQuery(value)) {
113
+ operations.push(writeFilterField(key, value, parameterBuilder));
114
+ }
115
+ if (key === "and") {
116
+ andOperation = writeFilterWithParameterBuilder(parameterBuilder, value);
117
+ }
118
+ if (key === "or") {
119
+ orOperation = writeFilterWithParameterBuilder(parameterBuilder, value);
120
+ }
121
+ if(key === "search") {
122
+ operations.push(writeSearchFilter(parameterBuilder, value));
123
+ }
124
+ }
125
+ let query = "";
126
+
127
+ operations = operations.filter(x => x !== "");
128
+
129
+ if(operations.length > 0) {
130
+ query = `(${operations.join(" AND ")})`;
131
+ }
132
+
133
+ if (andOperation != null) {
134
+ if(query !== "") {
135
+ query += " AND ";
136
+ }
137
+ query += andOperation;
138
+ }
139
+ if (orOperation != null) {
140
+ if(query !== "") {
141
+ query += " OR ";
142
+ }
143
+ query += orOperation;
144
+ }
145
+
146
+ return query;
147
+ }
148
+
149
+ function writeFilterField(fieldName: string, field: FieldQuery, parameters: ParameterBuilder): string {
150
+
151
+ const basicOperations: Array<string> = [];
152
+
153
+ writeSingleValue(basicOperations, parameters, field.eq, c => `${fieldName} = ${c}`);
154
+ writeSingleValue(basicOperations, parameters, field.gt, c => `${fieldName} > ${c}`);
155
+ writeSingleValue(basicOperations, parameters, field.gte, c => `${fieldName} >= ${c}`);
156
+ writeSingleValue(basicOperations, parameters, field.lt, c => `${fieldName} < ${c}`);
157
+ writeSingleValue(basicOperations, parameters, field.lte, c => `${fieldName} <= ${c}`);
158
+
159
+ writeArrayValue(basicOperations, parameters, field.in, c => `${fieldName} IN (${c.join(', ')})`);
160
+
161
+ //string specific
162
+ writeSingleValue(basicOperations, parameters, field.contains, c => `${fieldName} LIKE '%' + ${c} + '%'`);
163
+ writeSingleValue(basicOperations, parameters, field.endsWith, c => `${fieldName} LIKE '%' + ${c}`);
164
+ writeSingleValue(basicOperations, parameters, field.startsWith, c => `${fieldName} LIKE ${c} + '%'`);
165
+
166
+ let basicQuery = basicOperations.join(" AND ");
167
+
168
+ return basicQuery;
169
+ }
170
+
171
+ export class FilterResult {
172
+ filter: string;
173
+ parameters: {};
174
+
175
+ constructor(filter: string, parameters: {}) {
176
+ this.filter = filter;
177
+ this.parameters = parameters;
178
+ }
179
+ }
180
+
181
+ export class FieldQuery {
182
+ eq: string | number | boolean | undefined;
183
+
184
+ lt: string | number | undefined;
185
+ lte: string | number | undefined;
186
+ gt: string | number | undefined;
187
+ gte: string | number | undefined;
188
+
189
+ in: Array<string | number | boolean> | undefined;
190
+
191
+ //String specific
192
+ startsWith: string | number | undefined;
193
+ endsWith: string | number | undefined;
194
+ contains: string | number | undefined;
195
+ }
196
+
197
+ export class SearchFilter {
198
+ queryString: string | undefined;
199
+ fields: Array<string> | undefined;
200
200
  }