@squidcloud/local-backend 1.0.36 → 1.0.38

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.
Files changed (170) hide show
  1. package/dist/common/src/ai-assistant.context.d.ts +13 -13
  2. package/dist/common/src/ai-assistant.context.js +19 -19
  3. package/dist/common/src/ai-assistant.schemas.d.ts +207 -207
  4. package/dist/common/src/ai-assistant.schemas.js +196 -196
  5. package/dist/common/src/ai-assistant.types.d.ts +80 -80
  6. package/dist/common/src/ai-assistant.types.js +11 -11
  7. package/dist/common/src/api-call.context.d.ts +13 -13
  8. package/dist/common/src/api-call.context.js +16 -16
  9. package/dist/common/src/api.types.d.ts +23 -23
  10. package/dist/common/src/api.types.js +2 -2
  11. package/dist/common/src/application.schemas.d.ts +1168 -1168
  12. package/dist/common/src/application.schemas.js +741 -741
  13. package/dist/common/src/application.types.d.ts +228 -228
  14. package/dist/common/src/application.types.js +89 -89
  15. package/dist/common/src/backend-function.schemas.d.ts +3 -3
  16. package/dist/common/src/backend-function.schemas.js +12 -12
  17. package/dist/common/src/backend-function.types.d.ts +6 -6
  18. package/dist/common/src/backend-function.types.js +2 -2
  19. package/dist/common/src/backend-run.types.d.ts +54 -54
  20. package/dist/common/src/backend-run.types.js +73 -73
  21. package/dist/common/src/bundle-api.types.d.ts +71 -71
  22. package/dist/common/src/bundle-api.types.js +2 -2
  23. package/dist/common/src/bundle-data.types.d.ts +59 -59
  24. package/dist/common/src/bundle-data.types.js +2 -2
  25. package/dist/common/src/communication.types.d.ts +18 -18
  26. package/dist/common/src/communication.types.js +40 -40
  27. package/dist/common/src/context.types.d.ts +24 -24
  28. package/dist/common/src/context.types.js +2 -2
  29. package/dist/common/src/distributed-lock.context.d.ts +5 -5
  30. package/dist/common/src/distributed-lock.context.js +10 -10
  31. package/dist/common/src/document.types.d.ts +31 -31
  32. package/dist/common/src/document.types.js +49 -49
  33. package/dist/common/src/graphql.context.d.ts +14 -14
  34. package/dist/common/src/graphql.context.js +12 -12
  35. package/dist/common/src/graphql.types.d.ts +11 -11
  36. package/dist/common/src/graphql.types.js +34 -34
  37. package/dist/common/src/heartbeat.types.d.ts +4 -4
  38. package/dist/common/src/heartbeat.types.js +16 -16
  39. package/dist/common/src/http-status.enum.d.ts +50 -50
  40. package/dist/common/src/http-status.enum.js +54 -54
  41. package/dist/common/src/index.d.ts +54 -54
  42. package/dist/common/src/index.js +70 -70
  43. package/dist/common/src/integrations/ai_assistant.types.d.ts +30 -30
  44. package/dist/common/src/integrations/ai_assistant.types.js +2 -2
  45. package/dist/common/src/integrations/api.types.d.ts +80 -80
  46. package/dist/common/src/integrations/api.types.js +2 -2
  47. package/dist/common/src/integrations/auth.types.d.ts +39 -39
  48. package/dist/common/src/integrations/auth.types.js +2 -2
  49. package/dist/common/src/integrations/database.types.d.ts +236 -236
  50. package/dist/common/src/integrations/database.types.js +2 -2
  51. package/dist/common/src/integrations/index.d.ts +101 -101
  52. package/dist/common/src/integrations/index.js +105 -105
  53. package/dist/common/src/integrations/observability.types.d.ts +23 -22
  54. package/dist/common/src/integrations/observability.types.js +23 -14
  55. package/dist/common/src/integrations/observability.types.js.map +1 -1
  56. package/dist/common/src/logger.types.d.ts +21 -21
  57. package/dist/common/src/logger.types.js +11 -11
  58. package/dist/common/src/metrics.types.d.ts +73 -58
  59. package/dist/common/src/metrics.types.js +11 -11
  60. package/dist/common/src/mutation.context.d.ts +13 -13
  61. package/dist/common/src/mutation.context.js +26 -26
  62. package/dist/common/src/mutation.schemas.d.ts +5 -5
  63. package/dist/common/src/mutation.schemas.js +114 -114
  64. package/dist/common/src/mutation.types.d.ts +63 -63
  65. package/dist/common/src/mutation.types.js +142 -142
  66. package/dist/common/src/named-query.context.d.ts +4 -4
  67. package/dist/common/src/named-query.context.js +9 -9
  68. package/dist/common/src/named-query.schemas.d.ts +3 -3
  69. package/dist/common/src/named-query.schemas.js +13 -13
  70. package/dist/common/src/named-query.types.d.ts +8 -8
  71. package/dist/common/src/named-query.types.js +2 -2
  72. package/dist/common/src/query/index.d.ts +2 -2
  73. package/dist/common/src/query/index.js +18 -18
  74. package/dist/common/src/query/query-context.d.ts +29 -29
  75. package/dist/common/src/query/query-context.js +185 -185
  76. package/dist/common/src/query/simple-query-builder.d.ts +29 -29
  77. package/dist/common/src/query/simple-query-builder.js +114 -114
  78. package/dist/common/src/query.schemas.d.ts +6 -6
  79. package/dist/common/src/query.schemas.js +96 -96
  80. package/dist/common/src/query.types.d.ts +92 -92
  81. package/dist/common/src/query.types.js +134 -134
  82. package/dist/common/src/regions.d.ts +21 -21
  83. package/dist/common/src/regions.js +46 -46
  84. package/dist/common/src/schema/schema.types.d.ts +30 -30
  85. package/dist/common/src/schema/schema.types.js +172 -172
  86. package/dist/common/src/secret.schemas.d.ts +6 -6
  87. package/dist/common/src/secret.schemas.js +32 -32
  88. package/dist/common/src/secret.types.d.ts +49 -49
  89. package/dist/common/src/secret.types.js +5 -5
  90. package/dist/common/src/security.types.d.ts +3 -3
  91. package/dist/common/src/security.types.js +2 -2
  92. package/dist/common/src/socket.schemas.d.ts +3 -3
  93. package/dist/common/src/socket.schemas.js +58 -58
  94. package/dist/common/src/socket.types.d.ts +108 -108
  95. package/dist/common/src/socket.types.js +2 -2
  96. package/dist/common/src/time-units.d.ts +5 -5
  97. package/dist/common/src/time-units.js +8 -8
  98. package/dist/common/src/trigger.types.d.ts +15 -15
  99. package/dist/common/src/trigger.types.js +2 -2
  100. package/dist/common/src/types.d.ts +15 -15
  101. package/dist/common/src/types.js +2 -2
  102. package/dist/common/src/utils/array.d.ts +8 -8
  103. package/dist/common/src/utils/array.js +51 -51
  104. package/dist/common/src/utils/assert.d.ts +8 -8
  105. package/dist/common/src/utils/assert.js +49 -49
  106. package/dist/common/src/utils/error.d.ts +4 -4
  107. package/dist/common/src/utils/error.js +10 -10
  108. package/dist/common/src/utils/http.d.ts +2 -2
  109. package/dist/common/src/utils/http.js +38 -38
  110. package/dist/common/src/utils/id.d.ts +2 -2
  111. package/dist/common/src/utils/id.js +21 -21
  112. package/dist/common/src/utils/lock.manager.d.ts +9 -9
  113. package/dist/common/src/utils/lock.manager.js +39 -39
  114. package/dist/common/src/utils/nullish.d.ts +1 -1
  115. package/dist/common/src/utils/nullish.js +7 -7
  116. package/dist/common/src/utils/object.d.ts +6 -6
  117. package/dist/common/src/utils/object.js +89 -89
  118. package/dist/common/src/utils/serialization.d.ts +6 -6
  119. package/dist/common/src/utils/serialization.js +54 -54
  120. package/dist/common/src/utils/transforms.d.ts +18 -18
  121. package/dist/common/src/utils/transforms.js +92 -92
  122. package/dist/common/src/utils/url.d.ts +1 -1
  123. package/dist/common/src/utils/url.js +15 -15
  124. package/dist/common/src/utils/validation.d.ts +17 -17
  125. package/dist/common/src/utils/validation.js +209 -209
  126. package/dist/common/src/webhook-response.d.ts +7 -7
  127. package/dist/common/src/webhook-response.js +7 -7
  128. package/dist/internal-common/src/async-queue.d.ts +4 -4
  129. package/dist/internal-common/src/async-queue.js +17 -17
  130. package/dist/internal-common/src/code-executor.types.d.ts +13 -13
  131. package/dist/internal-common/src/code-executor.types.js +2 -2
  132. package/dist/internal-common/src/environment/environment.types.d.ts +74 -71
  133. package/dist/internal-common/src/environment/environment.types.js +2 -2
  134. package/dist/internal-common/src/environment/index.d.ts +6 -6
  135. package/dist/internal-common/src/environment/index.js +25 -25
  136. package/dist/internal-common/src/environment/local.environment.d.ts +2 -2
  137. package/dist/internal-common/src/environment/local.environment.js +62 -59
  138. package/dist/internal-common/src/environment/local.environment.js.map +1 -1
  139. package/dist/internal-common/src/index.d.ts +11 -11
  140. package/dist/internal-common/src/index.js +29 -29
  141. package/dist/internal-common/src/kafka/kafka.manager.d.ts +22 -22
  142. package/dist/internal-common/src/kafka/kafka.manager.js +128 -128
  143. package/dist/internal-common/src/kafka/kafka.types.d.ts +17 -17
  144. package/dist/internal-common/src/kafka/kafka.types.js +2 -2
  145. package/dist/internal-common/src/kafka-observability-publisher.d.ts +11 -11
  146. package/dist/internal-common/src/kafka-observability-publisher.js +20 -20
  147. package/dist/internal-common/src/local-dev.types.d.ts +31 -31
  148. package/dist/internal-common/src/local-dev.types.js +2 -2
  149. package/dist/internal-common/src/observability-publisher.d.ts +9 -9
  150. package/dist/internal-common/src/observability-publisher.js +58 -58
  151. package/dist/internal-common/src/observability.types.d.ts +17 -17
  152. package/dist/internal-common/src/observability.types.js +2 -2
  153. package/dist/internal-common/src/shutdown.manager.d.ts +20 -20
  154. package/dist/internal-common/src/shutdown.manager.js +76 -76
  155. package/dist/internal-common/src/utils.d.ts +5 -5
  156. package/dist/internal-common/src/utils.js +29 -29
  157. package/dist/local-backend/src/index.d.ts +4 -4
  158. package/dist/local-backend/src/index.js +20 -20
  159. package/dist/local-backend/src/local-backend-socket.service.d.ts +18 -18
  160. package/dist/local-backend/src/local-backend-socket.service.js +108 -108
  161. package/dist/local-backend/src/local-backend.app.d.ts +2 -2
  162. package/dist/local-backend/src/local-backend.app.js +19 -19
  163. package/dist/local-backend/src/local-backend.controller.d.ts +8 -8
  164. package/dist/local-backend/src/local-backend.controller.js +49 -49
  165. package/dist/local-backend/src/local-backend.module.d.ts +8 -8
  166. package/dist/local-backend/src/local-backend.module.js +53 -53
  167. package/dist/local-backend/src/local-backend.service.d.ts +15 -15
  168. package/dist/local-backend/src/local-backend.service.js +165 -165
  169. package/dist/tsconfig.build.tsbuildinfo +1 -1
  170. package/package.json +1 -1
@@ -1,186 +1,186 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryContext = void 0;
4
- const _ = require("lodash");
5
- const lodash_1 = require("lodash");
6
- const query_types_1 = require("../query.types");
7
- const CompareTable = {
8
- 'in:in': (a, b) => a.every((c) => b.includes(c)),
9
- 'in:not in': (a, b) => a.every((c) => !b.includes(c)),
10
- 'not in:not in': (a, b) => b.every((c) => a.includes(c)),
11
- '>:not in': (a, b) => b.every((c) => a >= c),
12
- '>=:not in': (a, b) => b.every((c) => a > c),
13
- '<:not in': (a, b) => b.every((c) => a <= c),
14
- '<=:not in': (a, b) => b.every((c) => a < c),
15
- '>:>': (a, b) => a >= b,
16
- '>=:>': (a, b) => a > b,
17
- 'in:>': (a, b) => a.every((c) => c > b),
18
- '>:>=': (a, b) => a >= b,
19
- '>=:>=': (a, b) => a >= b,
20
- 'in:>=': (a, b) => a.every((c) => c >= b),
21
- '<:<': (a, b) => a <= b,
22
- '<=:<': (a, b) => a < b,
23
- 'in:<': (a, b) => a.every((c) => c < b),
24
- '<:<=': (a, b) => a <= b,
25
- '<=:<=': (a, b) => a <= b,
26
- 'in:<=': (a, b) => a.every((c) => c <= b),
27
- };
28
- class QueryContext {
29
- constructor(query) {
30
- this.query = query;
31
- this.query = query;
32
- this.parsedConditions = this.parseConditions(this.query.conditions);
33
- }
34
- get integrationId() {
35
- return this.query.integrationId;
36
- }
37
- get collectionName() {
38
- return this.query.collectionName;
39
- }
40
- get limit() {
41
- return this.query.limit;
42
- }
43
- sortedBy(sorts) {
44
- const mismatch = sorts.find((fieldSort, index) => {
45
- var _a;
46
- return !(0, lodash_1.isEqual)(this.query.sortOrder[index], Object.assign(Object.assign({}, fieldSort), { asc: (_a = fieldSort.asc) !== null && _a !== void 0 ? _a : true }));
47
- });
48
- return !mismatch;
49
- }
50
- sortedByExact(sorts) {
51
- if (sorts.length !== this.query.sortOrder.length)
52
- return false;
53
- return this.sortedBy(sorts);
54
- }
55
- includes(fieldName, operator, value) {
56
- return this.includesCondition({ fieldName, operator, value });
57
- }
58
- includesCondition(condition) {
59
- const conditions = this.parsedConditions.filter((c) => c.fieldName === condition.fieldName);
60
- if (!conditions.length)
61
- return false;
62
- return !!conditions.find((c) => this.evaluateIncludes(c, condition));
63
- }
64
- includesConditions(conditions) {
65
- const parsedConditions = this.parseConditions(conditions);
66
- return parsedConditions.every((c) => this.includesCondition(c));
67
- }
68
- matchesConditions(conditions) {
69
- const parsedConditions = this.parseConditions(conditions);
70
- if (this.parsedConditions.length !== parsedConditions.length)
71
- return false;
72
- return parsedConditions.every((c) => this.includesCondition(c));
73
- }
74
- matchesQuery(query) {
75
- if (query.collectionName !== this.collectionName || query.integrationId !== this.integrationId)
76
- return false;
77
- const matchesConditions = this.matchesConditions(query.conditions);
78
- const matchesOrder = this.sortedByExact(query.sortOrder);
79
- const matchesLimit = this.limit === query.limit;
80
- return matchesConditions && matchesOrder && matchesLimit;
81
- }
82
- isSubsetOf(fieldName, operator, value) {
83
- return this.isSubsetOfCondition({
84
- fieldName,
85
- operator,
86
- value,
87
- });
88
- }
89
- isSubsetOfCondition(condition) {
90
- const conditions = this.parsedConditions.filter((c) => c.fieldName === condition.fieldName);
91
- return !!conditions.find((c) => this.evaluateSubset(c, condition));
92
- }
93
- isSubsetOfConditions(conditions) {
94
- const parsedConditions = this.parseConditions(conditions);
95
- return parsedConditions.every((c) => this.isSubsetOfCondition(c));
96
- }
97
- isSubsetOfQuery(query) {
98
- if (query.collectionName !== this.collectionName || query.integrationId !== this.integrationId)
99
- return false;
100
- const subsetOfConditions = this.isSubsetOfConditions(query.conditions);
101
- const subsetOfOrder = this.sortedBy(query.sortOrder);
102
- const withinLimit = query.limit === -1 || (this.limit > -1 && this.limit < query.limit);
103
- return subsetOfConditions && subsetOfOrder && withinLimit;
104
- }
105
- getConditionsFor(...fieldNames) {
106
- return this.parsedConditions.filter((cond) => fieldNames.includes(cond.fieldName));
107
- }
108
- getConditionsForField(fieldName) {
109
- return this.parsedConditions.filter((cond) => cond.fieldName === fieldName);
110
- }
111
- documentMatchesQuery(doc) {
112
- for (const contextCondition of this.parsedConditions) {
113
- const fieldNameOrPath = contextCondition.fieldName;
114
- const operator = contextCondition.operator;
115
- const valueInDoc = _.get(doc, fieldNameOrPath);
116
- if (operator === 'in') {
117
- if (contextCondition.value.includes(valueInDoc)) {
118
- continue;
119
- }
120
- return false;
121
- }
122
- else if (operator === 'not in') {
123
- if (contextCondition.value.includes(valueInDoc)) {
124
- return false;
125
- }
126
- continue;
127
- }
128
- if (!(0, query_types_1.compareOperator)(contextCondition.value, valueInDoc, operator)) {
129
- return false;
130
- }
131
- }
132
- return true;
133
- }
134
- evaluateSubset(queryCondition, testCondition) {
135
- const { operator: queryOperator, value: queryValue } = queryCondition;
136
- const { operator, value } = this.parseConditions([testCondition])[0];
137
- const compareFunction = CompareTable[`${queryOperator}:${operator}`];
138
- if (!compareFunction)
139
- return false;
140
- return compareFunction(queryValue, value);
141
- }
142
- evaluateIncludes(queryCondition, testCondition) {
143
- const { operator: queryOperator, value: queryValue } = queryCondition;
144
- const { operator, value } = this.parseConditions([testCondition])[0];
145
- const sortedQueryValue = Array.isArray(queryValue) ? queryValue.sort() : queryValue;
146
- const sortedValue = Array.isArray(value) ? value.sort() : value;
147
- return operator === queryOperator && (0, lodash_1.isEqual)(sortedValue, sortedQueryValue);
148
- }
149
- parseConditions(conditions) {
150
- const parsedConditions = [];
151
- const inMap = new Map();
152
- const notInMap = new Map();
153
- conditions.forEach((c) => {
154
- switch (c.operator) {
155
- case '==':
156
- case 'in':
157
- inMap.set(c.fieldName, (inMap.get(c.fieldName) || []).concat(c.value));
158
- break;
159
- case '!=':
160
- case 'not in':
161
- notInMap.set(c.fieldName, (notInMap.get(c.fieldName) || []).concat(c.value));
162
- break;
163
- default:
164
- parsedConditions.push(c);
165
- break;
166
- }
167
- });
168
- inMap.forEach((value, fieldName) => {
169
- parsedConditions.push({
170
- fieldName,
171
- operator: 'in',
172
- value: value,
173
- });
174
- });
175
- notInMap.forEach((value, fieldName) => {
176
- parsedConditions.push({
177
- fieldName,
178
- operator: 'not in',
179
- value: value,
180
- });
181
- });
182
- return parsedConditions;
183
- }
184
- }
185
- exports.QueryContext = QueryContext;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryContext = void 0;
4
+ const _ = require("lodash");
5
+ const lodash_1 = require("lodash");
6
+ const query_types_1 = require("../query.types");
7
+ const CompareTable = {
8
+ 'in:in': (a, b) => a.every((c) => b.includes(c)),
9
+ 'in:not in': (a, b) => a.every((c) => !b.includes(c)),
10
+ 'not in:not in': (a, b) => b.every((c) => a.includes(c)),
11
+ '>:not in': (a, b) => b.every((c) => a >= c),
12
+ '>=:not in': (a, b) => b.every((c) => a > c),
13
+ '<:not in': (a, b) => b.every((c) => a <= c),
14
+ '<=:not in': (a, b) => b.every((c) => a < c),
15
+ '>:>': (a, b) => a >= b,
16
+ '>=:>': (a, b) => a > b,
17
+ 'in:>': (a, b) => a.every((c) => c > b),
18
+ '>:>=': (a, b) => a >= b,
19
+ '>=:>=': (a, b) => a >= b,
20
+ 'in:>=': (a, b) => a.every((c) => c >= b),
21
+ '<:<': (a, b) => a <= b,
22
+ '<=:<': (a, b) => a < b,
23
+ 'in:<': (a, b) => a.every((c) => c < b),
24
+ '<:<=': (a, b) => a <= b,
25
+ '<=:<=': (a, b) => a <= b,
26
+ 'in:<=': (a, b) => a.every((c) => c <= b),
27
+ };
28
+ class QueryContext {
29
+ constructor(query) {
30
+ this.query = query;
31
+ this.query = query;
32
+ this.parsedConditions = this.parseConditions(this.query.conditions);
33
+ }
34
+ get integrationId() {
35
+ return this.query.integrationId;
36
+ }
37
+ get collectionName() {
38
+ return this.query.collectionName;
39
+ }
40
+ get limit() {
41
+ return this.query.limit;
42
+ }
43
+ sortedBy(sorts) {
44
+ const mismatch = sorts.find((fieldSort, index) => {
45
+ var _a;
46
+ return !(0, lodash_1.isEqual)(this.query.sortOrder[index], Object.assign(Object.assign({}, fieldSort), { asc: (_a = fieldSort.asc) !== null && _a !== void 0 ? _a : true }));
47
+ });
48
+ return !mismatch;
49
+ }
50
+ sortedByExact(sorts) {
51
+ if (sorts.length !== this.query.sortOrder.length)
52
+ return false;
53
+ return this.sortedBy(sorts);
54
+ }
55
+ includes(fieldName, operator, value) {
56
+ return this.includesCondition({ fieldName, operator, value });
57
+ }
58
+ includesCondition(condition) {
59
+ const conditions = this.parsedConditions.filter((c) => c.fieldName === condition.fieldName);
60
+ if (!conditions.length)
61
+ return false;
62
+ return !!conditions.find((c) => this.evaluateIncludes(c, condition));
63
+ }
64
+ includesConditions(conditions) {
65
+ const parsedConditions = this.parseConditions(conditions);
66
+ return parsedConditions.every((c) => this.includesCondition(c));
67
+ }
68
+ matchesConditions(conditions) {
69
+ const parsedConditions = this.parseConditions(conditions);
70
+ if (this.parsedConditions.length !== parsedConditions.length)
71
+ return false;
72
+ return parsedConditions.every((c) => this.includesCondition(c));
73
+ }
74
+ matchesQuery(query) {
75
+ if (query.collectionName !== this.collectionName || query.integrationId !== this.integrationId)
76
+ return false;
77
+ const matchesConditions = this.matchesConditions(query.conditions);
78
+ const matchesOrder = this.sortedByExact(query.sortOrder);
79
+ const matchesLimit = this.limit === query.limit;
80
+ return matchesConditions && matchesOrder && matchesLimit;
81
+ }
82
+ isSubsetOf(fieldName, operator, value) {
83
+ return this.isSubsetOfCondition({
84
+ fieldName,
85
+ operator,
86
+ value,
87
+ });
88
+ }
89
+ isSubsetOfCondition(condition) {
90
+ const conditions = this.parsedConditions.filter((c) => c.fieldName === condition.fieldName);
91
+ return !!conditions.find((c) => this.evaluateSubset(c, condition));
92
+ }
93
+ isSubsetOfConditions(conditions) {
94
+ const parsedConditions = this.parseConditions(conditions);
95
+ return parsedConditions.every((c) => this.isSubsetOfCondition(c));
96
+ }
97
+ isSubsetOfQuery(query) {
98
+ if (query.collectionName !== this.collectionName || query.integrationId !== this.integrationId)
99
+ return false;
100
+ const subsetOfConditions = this.isSubsetOfConditions(query.conditions);
101
+ const subsetOfOrder = this.sortedBy(query.sortOrder);
102
+ const withinLimit = query.limit === -1 || (this.limit > -1 && this.limit < query.limit);
103
+ return subsetOfConditions && subsetOfOrder && withinLimit;
104
+ }
105
+ getConditionsFor(...fieldNames) {
106
+ return this.parsedConditions.filter((cond) => fieldNames.includes(cond.fieldName));
107
+ }
108
+ getConditionsForField(fieldName) {
109
+ return this.parsedConditions.filter((cond) => cond.fieldName === fieldName);
110
+ }
111
+ documentMatchesQuery(doc) {
112
+ for (const contextCondition of this.parsedConditions) {
113
+ const fieldNameOrPath = contextCondition.fieldName;
114
+ const operator = contextCondition.operator;
115
+ const valueInDoc = _.get(doc, fieldNameOrPath);
116
+ if (operator === 'in') {
117
+ if (contextCondition.value.includes(valueInDoc)) {
118
+ continue;
119
+ }
120
+ return false;
121
+ }
122
+ else if (operator === 'not in') {
123
+ if (contextCondition.value.includes(valueInDoc)) {
124
+ return false;
125
+ }
126
+ continue;
127
+ }
128
+ if (!(0, query_types_1.compareOperator)(contextCondition.value, valueInDoc, operator)) {
129
+ return false;
130
+ }
131
+ }
132
+ return true;
133
+ }
134
+ evaluateSubset(queryCondition, testCondition) {
135
+ const { operator: queryOperator, value: queryValue } = queryCondition;
136
+ const { operator, value } = this.parseConditions([testCondition])[0];
137
+ const compareFunction = CompareTable[`${queryOperator}:${operator}`];
138
+ if (!compareFunction)
139
+ return false;
140
+ return compareFunction(queryValue, value);
141
+ }
142
+ evaluateIncludes(queryCondition, testCondition) {
143
+ const { operator: queryOperator, value: queryValue } = queryCondition;
144
+ const { operator, value } = this.parseConditions([testCondition])[0];
145
+ const sortedQueryValue = Array.isArray(queryValue) ? queryValue.sort() : queryValue;
146
+ const sortedValue = Array.isArray(value) ? value.sort() : value;
147
+ return operator === queryOperator && (0, lodash_1.isEqual)(sortedValue, sortedQueryValue);
148
+ }
149
+ parseConditions(conditions) {
150
+ const parsedConditions = [];
151
+ const inMap = new Map();
152
+ const notInMap = new Map();
153
+ conditions.forEach((c) => {
154
+ switch (c.operator) {
155
+ case '==':
156
+ case 'in':
157
+ inMap.set(c.fieldName, (inMap.get(c.fieldName) || []).concat(c.value));
158
+ break;
159
+ case '!=':
160
+ case 'not in':
161
+ notInMap.set(c.fieldName, (notInMap.get(c.fieldName) || []).concat(c.value));
162
+ break;
163
+ default:
164
+ parsedConditions.push(c);
165
+ break;
166
+ }
167
+ });
168
+ inMap.forEach((value, fieldName) => {
169
+ parsedConditions.push({
170
+ fieldName,
171
+ operator: 'in',
172
+ value: value,
173
+ });
174
+ });
175
+ notInMap.forEach((value, fieldName) => {
176
+ parsedConditions.push({
177
+ fieldName,
178
+ operator: 'not in',
179
+ value: value,
180
+ });
181
+ });
182
+ return parsedConditions;
183
+ }
184
+ }
185
+ exports.QueryContext = QueryContext;
186
186
  //# sourceMappingURL=query-context.js.map
@@ -1,29 +1,29 @@
1
- import { IntegrationId } from '../communication.types';
2
- import { CollectionName, DocumentData, FieldName, PrimitiveFieldType } from '../document.types';
3
- import { Operator, Query } from '../query.types';
4
- export declare abstract class BaseQueryBuilderInterface<MyDocType extends DocumentData> {
5
- abstract where(fieldName: (keyof MyDocType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
6
- eq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
7
- neq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
8
- in(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
9
- nin(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
10
- gt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
11
- gte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
12
- lt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
13
- lte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
14
- like(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
15
- notLike(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
16
- abstract limit(limit: number): this;
17
- abstract sortBy(fieldName: keyof MyDocType & FieldName, asc?: boolean): this;
18
- }
19
- export declare class SimpleQueryBuilder<MyDocType extends DocumentData> extends BaseQueryBuilderInterface<MyDocType> {
20
- protected readonly collectionName: CollectionName;
21
- protected readonly integrationId: IntegrationId;
22
- protected readonly query: Query<MyDocType>;
23
- constructor(collectionName: CollectionName, integrationId: IntegrationId);
24
- where(fieldName: (keyof MyDocType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
25
- limit(limit: number): this;
26
- sortBy(fieldName: keyof MyDocType & FieldName, asc?: boolean): this;
27
- build(): Query;
28
- private mergeConditions;
29
- }
1
+ import { IntegrationId } from '../communication.types';
2
+ import { CollectionName, DocumentData, FieldName, PrimitiveFieldType } from '../document.types';
3
+ import { Operator, Query } from '../query.types';
4
+ export declare abstract class BaseQueryBuilderInterface<MyDocType extends DocumentData> {
5
+ abstract where(fieldName: (keyof MyDocType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
6
+ eq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
7
+ neq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
8
+ in(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
9
+ nin(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
10
+ gt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
11
+ gte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
12
+ lt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
13
+ lte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
14
+ like(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
15
+ notLike(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
16
+ abstract limit(limit: number): this;
17
+ abstract sortBy(fieldName: keyof MyDocType & FieldName, asc?: boolean): this;
18
+ }
19
+ export declare class SimpleQueryBuilder<MyDocType extends DocumentData> extends BaseQueryBuilderInterface<MyDocType> {
20
+ protected readonly collectionName: CollectionName;
21
+ protected readonly integrationId: IntegrationId;
22
+ protected readonly query: Query<MyDocType>;
23
+ constructor(collectionName: CollectionName, integrationId: IntegrationId);
24
+ where(fieldName: (keyof MyDocType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
25
+ limit(limit: number): this;
26
+ sortBy(fieldName: keyof MyDocType & FieldName, asc?: boolean): this;
27
+ build(): Query;
28
+ private mergeConditions;
29
+ }