@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.
package/jest.config.js CHANGED
@@ -1,11 +1,11 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'node',
4
- testResultsProcessor: 'jest-sonar-reporter',
5
- coveragePathIgnorePatterns: [
6
- "/node_modules/",
7
- "/test/",
8
- "/generated/"
9
- ],
10
- testPathIgnorePatterns: ["lib"]
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ testResultsProcessor: 'jest-sonar-reporter',
5
+ coveragePathIgnorePatterns: [
6
+ "/node_modules/",
7
+ "/test/",
8
+ "/generated/"
9
+ ],
10
+ testPathIgnorePatterns: ["lib"]
11
11
  };
@@ -1,23 +1,23 @@
1
- import { ParameterBuilder } from "./parameterBuilder";
2
- export declare function writeFilter(filter: {} | FieldQuery): FilterResult;
3
- export declare function writeFilterWithParameterBuilder(parameterBuilder: ParameterBuilder, filter: {} | FieldQuery): string;
4
- export declare class FilterResult {
5
- filter: string;
6
- parameters: {};
7
- constructor(filter: string, parameters: {});
8
- }
9
- export declare class FieldQuery {
10
- eq: string | number | boolean | undefined;
11
- lt: string | number | undefined;
12
- lte: string | number | undefined;
13
- gt: string | number | undefined;
14
- gte: string | number | undefined;
15
- in: Array<string | number | boolean> | undefined;
16
- startsWith: string | number | undefined;
17
- endsWith: string | number | undefined;
18
- contains: string | number | undefined;
19
- }
20
- export declare class SearchFilter {
21
- queryString: string | undefined;
22
- fields: Array<string> | undefined;
23
- }
1
+ import { ParameterBuilder } from "./parameterBuilder";
2
+ export declare function writeFilter(filter: {} | FieldQuery): FilterResult;
3
+ export declare function writeFilterWithParameterBuilder(parameterBuilder: ParameterBuilder, filter: {} | FieldQuery): string;
4
+ export declare class FilterResult {
5
+ filter: string;
6
+ parameters: {};
7
+ constructor(filter: string, parameters: {});
8
+ }
9
+ export declare class FieldQuery {
10
+ eq: string | number | boolean | undefined;
11
+ lt: string | number | undefined;
12
+ lte: string | number | undefined;
13
+ gt: string | number | undefined;
14
+ gte: string | number | undefined;
15
+ in: Array<string | number | boolean> | undefined;
16
+ startsWith: string | number | undefined;
17
+ endsWith: string | number | undefined;
18
+ contains: string | number | undefined;
19
+ }
20
+ export declare class SearchFilter {
21
+ queryString: string | undefined;
22
+ fields: Array<string> | undefined;
23
+ }
@@ -1,156 +1,156 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SearchFilter = exports.FieldQuery = exports.FilterResult = exports.writeFilterWithParameterBuilder = exports.writeFilter = 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
- const parameterBuilder_1 = require("./parameterBuilder");
18
- function isString(val) {
19
- return typeof (val) === "string";
20
- }
21
- function isNumber(val) {
22
- return typeof (val) === "number";
23
- }
24
- function isBoolean(val) {
25
- return typeof (val) === 'boolean';
26
- }
27
- //Check if the value is a FieldQuery type
28
- function isFieldQuery(val) {
29
- return val.eq !== undefined ||
30
- val.lt !== undefined ||
31
- val.lte !== undefined ||
32
- val.gt !== undefined ||
33
- val.gte !== undefined ||
34
- val.startsWith !== undefined ||
35
- val.endsWith !== undefined ||
36
- val.contains !== undefined ||
37
- val.in !== undefined;
38
- }
39
- function writeSingleValue(arr, parameters, val, operation) {
40
- if (val !== undefined) {
41
- if (isString(val)) {
42
- const parameterName = parameters.getParameterName(val);
43
- arr.push(operation(`@${parameterName}`));
44
- }
45
- if (isNumber(val)) {
46
- arr.push(operation(`${val}`));
47
- }
48
- if (isBoolean(val)) {
49
- arr.push(operation(`${val}`));
50
- }
51
- }
52
- }
53
- function writeArrayValue(arr, parameters, val, operation) {
54
- if (!!val && val.length > 0) {
55
- const arrayvalues = [];
56
- for (let v of val) {
57
- if (isString(v)) {
58
- const parameterName = parameters.getParameterName(v);
59
- arrayvalues.push(`@${parameterName}`);
60
- }
61
- if (isNumber(v) || isBoolean(v)) {
62
- arrayvalues.push(`${v}`);
63
- }
64
- }
65
- arr.push(operation(arrayvalues));
66
- }
67
- }
68
- function writeFilter(filter) {
69
- const parameters = new parameterBuilder_1.ParameterBuilder();
70
- const result = writeFilterWithParameterBuilder(parameters, filter);
71
- return new FilterResult(result, parameters.getParameters());
72
- }
73
- exports.writeFilter = writeFilter;
74
- function writeSearchFilter(parameters, value) {
75
- if (value.queryString !== undefined) {
76
- let output = "CONTAINS(";
77
- if (value.fields !== undefined) {
78
- output += `(${value.fields.join(', ')})`;
79
- }
80
- else {
81
- output += "*";
82
- }
83
- output += ", ";
84
- output += `@${parameters.getParameterName(value.queryString)}`;
85
- output += ")";
86
- return output;
87
- }
88
- return "";
89
- }
90
- function writeFilterWithParameterBuilder(parameterBuilder, filter) {
91
- let operations = [];
92
- let andOperation = null;
93
- let orOperation = null;
94
- for (let [key, value] of Object.entries(filter)) {
95
- if (isFieldQuery(value)) {
96
- operations.push(writeFilterField(key, value, parameterBuilder));
97
- }
98
- if (key === "and") {
99
- andOperation = writeFilterWithParameterBuilder(parameterBuilder, value);
100
- }
101
- if (key === "or") {
102
- orOperation = writeFilterWithParameterBuilder(parameterBuilder, value);
103
- }
104
- if (key === "search") {
105
- operations.push(writeSearchFilter(parameterBuilder, value));
106
- }
107
- }
108
- let query = "";
109
- operations = operations.filter(x => x !== "");
110
- if (operations.length > 0) {
111
- query = `(${operations.join(" AND ")})`;
112
- }
113
- if (andOperation != null) {
114
- if (query !== "") {
115
- query += " AND ";
116
- }
117
- query += andOperation;
118
- }
119
- if (orOperation != null) {
120
- if (query !== "") {
121
- query += " OR ";
122
- }
123
- query += orOperation;
124
- }
125
- return query;
126
- }
127
- exports.writeFilterWithParameterBuilder = writeFilterWithParameterBuilder;
128
- function writeFilterField(fieldName, field, parameters) {
129
- const basicOperations = [];
130
- writeSingleValue(basicOperations, parameters, field.eq, c => `${fieldName} = ${c}`);
131
- writeSingleValue(basicOperations, parameters, field.gt, c => `${fieldName} > ${c}`);
132
- writeSingleValue(basicOperations, parameters, field.gte, c => `${fieldName} >= ${c}`);
133
- writeSingleValue(basicOperations, parameters, field.lt, c => `${fieldName} < ${c}`);
134
- writeSingleValue(basicOperations, parameters, field.lte, c => `${fieldName} <= ${c}`);
135
- writeArrayValue(basicOperations, parameters, field.in, c => `${fieldName} IN (${c.join(', ')})`);
136
- //string specific
137
- writeSingleValue(basicOperations, parameters, field.contains, c => `${fieldName} LIKE '%' + ${c} + '%'`);
138
- writeSingleValue(basicOperations, parameters, field.endsWith, c => `${fieldName} LIKE '%' + ${c}`);
139
- writeSingleValue(basicOperations, parameters, field.startsWith, c => `${fieldName} LIKE ${c} + '%'`);
140
- let basicQuery = basicOperations.join(" AND ");
141
- return basicQuery;
142
- }
143
- class FilterResult {
144
- constructor(filter, parameters) {
145
- this.filter = filter;
146
- this.parameters = parameters;
147
- }
148
- }
149
- exports.FilterResult = FilterResult;
150
- class FieldQuery {
151
- }
152
- exports.FieldQuery = FieldQuery;
153
- class SearchFilter {
154
- }
155
- exports.SearchFilter = SearchFilter;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchFilter = exports.FieldQuery = exports.FilterResult = exports.writeFilterWithParameterBuilder = exports.writeFilter = 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
+ const parameterBuilder_1 = require("./parameterBuilder");
18
+ function isString(val) {
19
+ return typeof (val) === "string";
20
+ }
21
+ function isNumber(val) {
22
+ return typeof (val) === "number";
23
+ }
24
+ function isBoolean(val) {
25
+ return typeof (val) === 'boolean';
26
+ }
27
+ //Check if the value is a FieldQuery type
28
+ function isFieldQuery(val) {
29
+ return val.eq !== undefined ||
30
+ val.lt !== undefined ||
31
+ val.lte !== undefined ||
32
+ val.gt !== undefined ||
33
+ val.gte !== undefined ||
34
+ val.startsWith !== undefined ||
35
+ val.endsWith !== undefined ||
36
+ val.contains !== undefined ||
37
+ val.in !== undefined;
38
+ }
39
+ function writeSingleValue(arr, parameters, val, operation) {
40
+ if (val !== undefined) {
41
+ if (isString(val)) {
42
+ const parameterName = parameters.getParameterName(val);
43
+ arr.push(operation(`@${parameterName}`));
44
+ }
45
+ if (isNumber(val)) {
46
+ arr.push(operation(`${val}`));
47
+ }
48
+ if (isBoolean(val)) {
49
+ arr.push(operation(`${val}`));
50
+ }
51
+ }
52
+ }
53
+ function writeArrayValue(arr, parameters, val, operation) {
54
+ if (!!val && val.length > 0) {
55
+ const arrayvalues = [];
56
+ for (let v of val) {
57
+ if (isString(v)) {
58
+ const parameterName = parameters.getParameterName(v);
59
+ arrayvalues.push(`@${parameterName}`);
60
+ }
61
+ if (isNumber(v) || isBoolean(v)) {
62
+ arrayvalues.push(`${v}`);
63
+ }
64
+ }
65
+ arr.push(operation(arrayvalues));
66
+ }
67
+ }
68
+ function writeFilter(filter) {
69
+ const parameters = new parameterBuilder_1.ParameterBuilder();
70
+ const result = writeFilterWithParameterBuilder(parameters, filter);
71
+ return new FilterResult(result, parameters.getParameters());
72
+ }
73
+ exports.writeFilter = writeFilter;
74
+ function writeSearchFilter(parameters, value) {
75
+ if (value.queryString !== undefined) {
76
+ let output = "CONTAINS(";
77
+ if (value.fields !== undefined) {
78
+ output += `(${value.fields.join(', ')})`;
79
+ }
80
+ else {
81
+ output += "*";
82
+ }
83
+ output += ", ";
84
+ output += `@${parameters.getParameterName(value.queryString)}`;
85
+ output += ")";
86
+ return output;
87
+ }
88
+ return "";
89
+ }
90
+ function writeFilterWithParameterBuilder(parameterBuilder, filter) {
91
+ let operations = [];
92
+ let andOperation = null;
93
+ let orOperation = null;
94
+ for (let [key, value] of Object.entries(filter)) {
95
+ if (isFieldQuery(value)) {
96
+ operations.push(writeFilterField(key, value, parameterBuilder));
97
+ }
98
+ if (key === "and") {
99
+ andOperation = writeFilterWithParameterBuilder(parameterBuilder, value);
100
+ }
101
+ if (key === "or") {
102
+ orOperation = writeFilterWithParameterBuilder(parameterBuilder, value);
103
+ }
104
+ if (key === "search") {
105
+ operations.push(writeSearchFilter(parameterBuilder, value));
106
+ }
107
+ }
108
+ let query = "";
109
+ operations = operations.filter(x => x !== "");
110
+ if (operations.length > 0) {
111
+ query = `(${operations.join(" AND ")})`;
112
+ }
113
+ if (andOperation != null) {
114
+ if (query !== "") {
115
+ query += " AND ";
116
+ }
117
+ query += andOperation;
118
+ }
119
+ if (orOperation != null) {
120
+ if (query !== "") {
121
+ query += " OR ";
122
+ }
123
+ query += orOperation;
124
+ }
125
+ return query;
126
+ }
127
+ exports.writeFilterWithParameterBuilder = writeFilterWithParameterBuilder;
128
+ function writeFilterField(fieldName, field, parameters) {
129
+ const basicOperations = [];
130
+ writeSingleValue(basicOperations, parameters, field.eq, c => `${fieldName} = ${c}`);
131
+ writeSingleValue(basicOperations, parameters, field.gt, c => `${fieldName} > ${c}`);
132
+ writeSingleValue(basicOperations, parameters, field.gte, c => `${fieldName} >= ${c}`);
133
+ writeSingleValue(basicOperations, parameters, field.lt, c => `${fieldName} < ${c}`);
134
+ writeSingleValue(basicOperations, parameters, field.lte, c => `${fieldName} <= ${c}`);
135
+ writeArrayValue(basicOperations, parameters, field.in, c => `${fieldName} IN (${c.join(', ')})`);
136
+ //string specific
137
+ writeSingleValue(basicOperations, parameters, field.contains, c => `${fieldName} LIKE '%' + ${c} + '%'`);
138
+ writeSingleValue(basicOperations, parameters, field.endsWith, c => `${fieldName} LIKE '%' + ${c}`);
139
+ writeSingleValue(basicOperations, parameters, field.startsWith, c => `${fieldName} LIKE ${c} + '%'`);
140
+ let basicQuery = basicOperations.join(" AND ");
141
+ return basicQuery;
142
+ }
143
+ class FilterResult {
144
+ constructor(filter, parameters) {
145
+ this.filter = filter;
146
+ this.parameters = parameters;
147
+ }
148
+ }
149
+ exports.FilterResult = FilterResult;
150
+ class FieldQuery {
151
+ }
152
+ exports.FieldQuery = FieldQuery;
153
+ class SearchFilter {
154
+ }
155
+ exports.SearchFilter = SearchFilter;
156
156
  //# sourceMappingURL=filterBuilder.js.map
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from "./queryBuilder";
2
- export * from "./objectToSelectMapper";
3
- export * from "./queryOptions";
4
- export * from "./queryResult";
5
- export * from "./koraliumClient";
1
+ export * from "./queryBuilder";
2
+ export * from "./objectToSelectMapper";
3
+ export * from "./queryOptions";
4
+ export * from "./queryResult";
5
+ export * from "./koraliumClient";
package/lib/index.js CHANGED
@@ -1,31 +1,31 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- /*
14
- * Licensed under the Apache License, Version 2.0 (the "License");
15
- * you may not use this file except in compliance with the License.
16
- * You may obtain a copy of the License at
17
- *
18
- * http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- */
26
- __exportStar(require("./queryBuilder"), exports);
27
- __exportStar(require("./objectToSelectMapper"), exports);
28
- __exportStar(require("./queryOptions"), exports);
29
- __exportStar(require("./queryResult"), exports);
30
- __exportStar(require("./koraliumClient"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ /*
14
+ * Licensed under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License.
16
+ * You may obtain a copy of the License at
17
+ *
18
+ * http://www.apache.org/licenses/LICENSE-2.0
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ */
26
+ __exportStar(require("./queryBuilder"), exports);
27
+ __exportStar(require("./objectToSelectMapper"), exports);
28
+ __exportStar(require("./queryOptions"), exports);
29
+ __exportStar(require("./queryResult"), exports);
30
+ __exportStar(require("./koraliumClient"), exports);
31
31
  //# sourceMappingURL=index.js.map