@squidcloud/local-backend 1.0.148 → 1.0.151

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 (173) hide show
  1. package/dist/common/src/ai-assistant.types.d.ts +50 -50
  2. package/dist/common/src/ai-assistant.types.js +2 -2
  3. package/dist/common/src/ai-chatbot.context.d.ts +13 -13
  4. package/dist/common/src/ai-chatbot.context.js +19 -19
  5. package/dist/common/src/ai-chatbot.schemas.d.ts +18 -18
  6. package/dist/common/src/ai-chatbot.schemas.js +21 -21
  7. package/dist/common/src/ai-chatbot.types.d.ts +125 -123
  8. package/dist/common/src/ai-chatbot.types.js +18 -18
  9. package/dist/common/src/api-call.context.d.ts +13 -13
  10. package/dist/common/src/api-call.context.js +16 -16
  11. package/dist/common/src/api.types.d.ts +22 -22
  12. package/dist/common/src/api.types.js +2 -2
  13. package/dist/common/src/application.schemas.d.ts +1648 -1648
  14. package/dist/common/src/application.schemas.js +948 -948
  15. package/dist/common/src/application.types.d.ts +193 -193
  16. package/dist/common/src/application.types.js +89 -89
  17. package/dist/common/src/application.types.js.map +1 -1
  18. package/dist/common/src/backend-function.schemas.d.ts +3 -3
  19. package/dist/common/src/backend-function.schemas.js +11 -11
  20. package/dist/common/src/backend-function.types.d.ts +4 -4
  21. package/dist/common/src/backend-function.types.js +2 -2
  22. package/dist/common/src/backend-run.types.d.ts +54 -54
  23. package/dist/common/src/backend-run.types.js +92 -95
  24. package/dist/common/src/backend-run.types.js.map +1 -1
  25. package/dist/common/src/bundle-api.types.d.ts +65 -69
  26. package/dist/common/src/bundle-api.types.js +2 -2
  27. package/dist/common/src/bundle-data.types.d.ts +69 -74
  28. package/dist/common/src/bundle-data.types.js +2 -2
  29. package/dist/common/src/communication.types.d.ts +20 -19
  30. package/dist/common/src/communication.types.js +41 -40
  31. package/dist/common/src/communication.types.js.map +1 -1
  32. package/dist/common/src/context.types.d.ts +24 -24
  33. package/dist/common/src/context.types.js +2 -2
  34. package/dist/common/src/distributed-lock.context.d.ts +4 -4
  35. package/dist/common/src/distributed-lock.context.js +9 -9
  36. package/dist/common/src/document.types.d.ts +32 -32
  37. package/dist/common/src/document.types.js +50 -50
  38. package/dist/common/src/graphql.context.d.ts +14 -14
  39. package/dist/common/src/graphql.context.js +12 -12
  40. package/dist/common/src/graphql.types.d.ts +11 -11
  41. package/dist/common/src/graphql.types.js +34 -34
  42. package/dist/common/src/heartbeat.types.d.ts +4 -4
  43. package/dist/common/src/heartbeat.types.js +16 -16
  44. package/dist/common/src/http-status.enum.d.ts +50 -50
  45. package/dist/common/src/http-status.enum.js +54 -54
  46. package/dist/common/src/http-status.enum.js.map +1 -1
  47. package/dist/common/src/index.d.ts +54 -57
  48. package/dist/common/src/index.js +70 -73
  49. package/dist/common/src/index.js.map +1 -1
  50. package/dist/common/src/integrations/ai_chatbot.types.d.ts +31 -31
  51. package/dist/common/src/integrations/ai_chatbot.types.js +2 -2
  52. package/dist/common/src/integrations/api.types.d.ts +80 -80
  53. package/dist/common/src/integrations/api.types.js +2 -2
  54. package/dist/common/src/integrations/auth.types.d.ts +39 -39
  55. package/dist/common/src/integrations/auth.types.js +2 -2
  56. package/dist/common/src/integrations/database.types.d.ts +274 -274
  57. package/dist/common/src/integrations/database.types.js +2 -2
  58. package/dist/common/src/integrations/index.d.ts +134 -134
  59. package/dist/common/src/integrations/index.js +119 -119
  60. package/dist/common/src/integrations/index.js.map +1 -1
  61. package/dist/common/src/integrations/observability.types.d.ts +23 -23
  62. package/dist/common/src/integrations/observability.types.js +23 -23
  63. package/dist/common/src/logger.types.d.ts +21 -21
  64. package/dist/common/src/logger.types.js +11 -11
  65. package/dist/common/src/logger.types.js.map +1 -1
  66. package/dist/common/src/metrics.types.d.ts +73 -73
  67. package/dist/common/src/metrics.types.js +11 -11
  68. package/dist/common/src/mutation.context.d.ts +13 -13
  69. package/dist/common/src/mutation.context.js +26 -26
  70. package/dist/common/src/mutation.schemas.d.ts +5 -5
  71. package/dist/common/src/mutation.schemas.js +114 -114
  72. package/dist/common/src/mutation.types.d.ts +63 -63
  73. package/dist/common/src/mutation.types.js +142 -142
  74. package/dist/common/src/native-query.context.d.ts +7 -7
  75. package/dist/common/src/native-query.context.js +11 -11
  76. package/dist/common/src/native-query.types.d.ts +16 -16
  77. package/dist/common/src/native-query.types.js +2 -2
  78. package/dist/common/src/query/base-query-builder.d.ts +38 -38
  79. package/dist/common/src/query/base-query-builder.js +39 -39
  80. package/dist/common/src/query/index.d.ts +4 -4
  81. package/dist/common/src/query/index.js +20 -20
  82. package/dist/common/src/query/pagination.d.ts +46 -46
  83. package/dist/common/src/query/pagination.js +211 -211
  84. package/dist/common/src/query/query-context.d.ts +47 -47
  85. package/dist/common/src/query/query-context.js +159 -159
  86. package/dist/common/src/query/serialized-query.types.d.ts +24 -24
  87. package/dist/common/src/query/serialized-query.types.js +2 -2
  88. package/dist/common/src/query.types.d.ts +86 -86
  89. package/dist/common/src/query.types.js +97 -97
  90. package/dist/common/src/regions.d.ts +21 -21
  91. package/dist/common/src/regions.js +46 -46
  92. package/dist/common/src/schema/schema.types.d.ts +30 -30
  93. package/dist/common/src/schema/schema.types.js +173 -173
  94. package/dist/common/src/secret.schemas.d.ts +4 -4
  95. package/dist/common/src/secret.schemas.js +17 -17
  96. package/dist/common/src/secret.types.d.ts +68 -68
  97. package/dist/common/src/secret.types.js +5 -5
  98. package/dist/common/src/security.types.d.ts +3 -3
  99. package/dist/common/src/security.types.js +2 -2
  100. package/dist/common/src/socket.schemas.d.ts +3 -3
  101. package/dist/common/src/socket.schemas.js +57 -57
  102. package/dist/common/src/socket.types.d.ts +126 -126
  103. package/dist/common/src/socket.types.js +9 -9
  104. package/dist/common/src/socket.types.js.map +1 -1
  105. package/dist/common/src/time-units.d.ts +11 -11
  106. package/dist/common/src/time-units.js +14 -14
  107. package/dist/common/src/trigger.types.d.ts +15 -15
  108. package/dist/common/src/trigger.types.js +2 -2
  109. package/dist/common/src/types.d.ts +21 -21
  110. package/dist/common/src/types.js +2 -2
  111. package/dist/common/src/utils/array.d.ts +8 -8
  112. package/dist/common/src/utils/array.js +54 -54
  113. package/dist/common/src/utils/assert.d.ts +3 -3
  114. package/dist/common/src/utils/assert.js +14 -14
  115. package/dist/common/src/utils/error.d.ts +4 -4
  116. package/dist/common/src/utils/error.js +10 -10
  117. package/dist/common/src/utils/global.utils.d.ts +11 -11
  118. package/dist/common/src/utils/global.utils.js +50 -50
  119. package/dist/common/src/utils/http.d.ts +2 -2
  120. package/dist/common/src/utils/http.js +51 -51
  121. package/dist/common/src/utils/id.d.ts +2 -2
  122. package/dist/common/src/utils/id.js +21 -21
  123. package/dist/common/src/utils/lock.manager.d.ts +9 -9
  124. package/dist/common/src/utils/lock.manager.js +39 -39
  125. package/dist/common/src/utils/object.d.ts +5 -5
  126. package/dist/common/src/utils/object.js +75 -75
  127. package/dist/common/src/utils/serialization.d.ts +5 -5
  128. package/dist/common/src/utils/serialization.js +73 -73
  129. package/dist/common/src/utils/transforms.d.ts +18 -18
  130. package/dist/common/src/utils/transforms.js +104 -104
  131. package/dist/common/src/utils/url.d.ts +1 -1
  132. package/dist/common/src/utils/url.js +15 -15
  133. package/dist/common/src/utils/validation.d.ts +17 -17
  134. package/dist/common/src/utils/validation.js +199 -199
  135. package/dist/common/src/webhook-response.d.ts +6 -6
  136. package/dist/common/src/webhook-response.js +2 -2
  137. package/dist/common/src/websocket.impl.d.ts +21 -21
  138. package/dist/common/src/websocket.impl.js +79 -79
  139. package/dist/internal-common/src/code-executor.types.d.ts +13 -13
  140. package/dist/internal-common/src/code-executor.types.js +2 -2
  141. package/dist/internal-common/src/local-dev.types.d.ts +35 -35
  142. package/dist/internal-common/src/local-dev.types.js +2 -2
  143. package/dist/local-backend/package.json +48 -48
  144. package/dist/local-backend/src/index.d.ts +4 -4
  145. package/dist/local-backend/src/index.js +26 -26
  146. package/dist/local-backend/src/local-backend-socket.service.d.ts +18 -18
  147. package/dist/local-backend/src/local-backend-socket.service.js +107 -108
  148. package/dist/local-backend/src/local-backend-socket.service.js.map +1 -1
  149. package/dist/local-backend/src/local-backend.app.d.ts +2 -2
  150. package/dist/local-backend/src/local-backend.app.js +19 -19
  151. package/dist/local-backend/src/local-backend.controller.d.ts +8 -8
  152. package/dist/local-backend/src/local-backend.controller.js +48 -49
  153. package/dist/local-backend/src/local-backend.controller.js.map +1 -1
  154. package/dist/local-backend/src/local-backend.module.d.ts +8 -8
  155. package/dist/local-backend/src/local-backend.module.js +51 -53
  156. package/dist/local-backend/src/local-backend.module.js.map +1 -1
  157. package/dist/local-backend/src/local-backend.service.d.ts +15 -15
  158. package/dist/local-backend/src/local-backend.service.js +173 -176
  159. package/dist/local-backend/src/local-backend.service.js.map +1 -1
  160. package/dist/tsconfig.build.tsbuildinfo +1 -1
  161. package/package.json +1 -1
  162. package/dist/common/src/named-query.context.d.ts +0 -4
  163. package/dist/common/src/named-query.context.js +0 -10
  164. package/dist/common/src/named-query.context.js.map +0 -1
  165. package/dist/common/src/named-query.schemas.d.ts +0 -3
  166. package/dist/common/src/named-query.schemas.js +0 -14
  167. package/dist/common/src/named-query.schemas.js.map +0 -1
  168. package/dist/common/src/named-query.types.d.ts +0 -8
  169. package/dist/common/src/named-query.types.js +0 -3
  170. package/dist/common/src/named-query.types.js.map +0 -1
  171. package/dist/internal-common/src/utils/logger-utils.d.ts +0 -3
  172. package/dist/internal-common/src/utils/logger-utils.js +0 -29
  173. package/dist/internal-common/src/utils/logger-utils.js.map +0 -1
@@ -1,63 +1,63 @@
1
- import { IntegrationId } from './communication.types';
2
- import { DocTimestamp, FieldName, SquidDocId, SquidDocIdObj, SquidDocument } from './document.types';
3
- export interface MutateRequest<T = any> {
4
- integrationId: IntegrationId;
5
- mutations: Array<Mutation<T>>;
6
- }
7
- export interface ExecuteMutationsResponse {
8
- timestamp: DocTimestamp;
9
- idResolutionMap?: IdResolutionMap;
10
- afterDocs: Record<SquidDocId, SquidDocument>;
11
- }
12
- export interface MutateResponse extends Omit<ExecuteMutationsResponse, 'afterDocs'> {
13
- refreshList: Array<SquidDocId>;
14
- }
15
- export type IdResolutionMap = Record<SquidDocId, SquidDocId>;
16
- export type Mutation<T = any> = UpdateMutation<T> | InsertMutation<T> | DeleteMutation;
17
- export type MutationType = 'insert' | 'update' | 'delete';
18
- interface BaseMutation {
19
- type: MutationType;
20
- squidDocIdObj: SquidDocIdObj;
21
- }
22
- export interface DeleteMutation extends BaseMutation {
23
- type: 'delete';
24
- }
25
- export interface UpdateMutation<T = any> extends BaseMutation {
26
- type: 'update';
27
- properties: {
28
- [key in keyof T & string]?: Array<PropertyMutation<T[key]>>;
29
- };
30
- }
31
- export interface InsertMutation<T = any> extends BaseMutation {
32
- type: 'insert';
33
- properties: T;
34
- }
35
- export type PropertyMutation<Value = any> = ApplyNumericFnPropertyMutation | ApplyStringFnPropertyMutation | ValueUpdatePropertyMutation<Value> | RemovePropertyMutation;
36
- export interface ValueUpdatePropertyMutation<Value = any> {
37
- type: 'update';
38
- value: Value;
39
- }
40
- export interface ApplyNumericFnPropertyMutation {
41
- type: 'applyNumericFn';
42
- fn: 'increment';
43
- value: number;
44
- }
45
- export interface RemovePropertyMutation {
46
- type: 'removeProperty';
47
- }
48
- interface ApplyExtendString {
49
- type: 'applyStringFn';
50
- fn: 'extendString';
51
- value: string;
52
- }
53
- interface ApplyTrimString {
54
- type: 'applyStringFn';
55
- fn: 'trim';
56
- }
57
- export type ApplyStringFnPropertyMutation = ApplyExtendString | ApplyTrimString;
58
- export declare function sortUpdateMutationProperties(updateMutation: UpdateMutation): Array<[FieldName, Array<PropertyMutation>]>;
59
- export declare function mergeMutations(mutationA: Mutation, mutationB: Mutation): Mutation;
60
- export declare function applyUpdateMutation<T extends SquidDocument>(doc: T, updateMutation: UpdateMutation<T>): T | undefined;
61
- export declare function convertInsertToUpdate(insertMutation: InsertMutation): UpdateMutation;
62
- export declare function reduceMutations(mutations: Array<Mutation<unknown>>): Array<Mutation<unknown>>;
63
- export {};
1
+ import { IntegrationId } from './communication.types';
2
+ import { DocTimestamp, FieldName, SquidDocId, SquidDocIdObj, SquidDocument } from './document.types';
3
+ export interface MutateRequest<T = any> {
4
+ integrationId: IntegrationId;
5
+ mutations: Array<Mutation<T>>;
6
+ }
7
+ export interface ExecuteMutationsResponse {
8
+ timestamp: DocTimestamp;
9
+ idResolutionMap?: IdResolutionMap;
10
+ afterDocs: Record<SquidDocId, SquidDocument>;
11
+ }
12
+ export interface MutateResponse extends Omit<ExecuteMutationsResponse, 'afterDocs'> {
13
+ refreshList: Array<SquidDocId>;
14
+ }
15
+ export type IdResolutionMap = Record<SquidDocId, SquidDocId>;
16
+ export type Mutation<T = any> = UpdateMutation<T> | InsertMutation<T> | DeleteMutation;
17
+ export type MutationType = 'insert' | 'update' | 'delete';
18
+ interface BaseMutation {
19
+ type: MutationType;
20
+ squidDocIdObj: SquidDocIdObj;
21
+ }
22
+ export interface DeleteMutation extends BaseMutation {
23
+ type: 'delete';
24
+ }
25
+ export interface UpdateMutation<T = any> extends BaseMutation {
26
+ type: 'update';
27
+ properties: {
28
+ [key in keyof T & string]?: Array<PropertyMutation<T[key]>>;
29
+ };
30
+ }
31
+ export interface InsertMutation<T = any> extends BaseMutation {
32
+ type: 'insert';
33
+ properties: T;
34
+ }
35
+ export type PropertyMutation<Value = any> = ApplyNumericFnPropertyMutation | ApplyStringFnPropertyMutation | ValueUpdatePropertyMutation<Value> | RemovePropertyMutation;
36
+ export interface ValueUpdatePropertyMutation<Value = any> {
37
+ type: 'update';
38
+ value: Value;
39
+ }
40
+ export interface ApplyNumericFnPropertyMutation {
41
+ type: 'applyNumericFn';
42
+ fn: 'increment';
43
+ value: number;
44
+ }
45
+ export interface RemovePropertyMutation {
46
+ type: 'removeProperty';
47
+ }
48
+ interface ApplyExtendString {
49
+ type: 'applyStringFn';
50
+ fn: 'extendString';
51
+ value: string;
52
+ }
53
+ interface ApplyTrimString {
54
+ type: 'applyStringFn';
55
+ fn: 'trim';
56
+ }
57
+ export type ApplyStringFnPropertyMutation = ApplyExtendString | ApplyTrimString;
58
+ export declare function sortUpdateMutationProperties(updateMutation: UpdateMutation): Array<[FieldName, Array<PropertyMutation>]>;
59
+ export declare function mergeMutations(mutationA: Mutation, mutationB: Mutation): Mutation;
60
+ export declare function applyUpdateMutation<T extends SquidDocument>(doc: T, updateMutation: UpdateMutation<T>): T | undefined;
61
+ export declare function convertInsertToUpdate(insertMutation: InsertMutation): UpdateMutation;
62
+ export declare function reduceMutations(mutations: Array<Mutation<unknown>>): Array<Mutation<unknown>>;
63
+ export {};
@@ -1,143 +1,143 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reduceMutations = exports.convertInsertToUpdate = exports.applyUpdateMutation = exports.mergeMutations = exports.sortUpdateMutationProperties = void 0;
4
- const assertic_1 = require("assertic");
5
- const _ = require("lodash");
6
- const rxjs_1 = require("rxjs");
7
- const object_1 = require("./utils/object");
8
- function applyStringFn(initialValue, propertyMutation) {
9
- switch (propertyMutation.fn) {
10
- case 'trim':
11
- if (typeof initialValue !== 'string')
12
- return initialValue;
13
- return initialValue.trim();
14
- case 'extendString':
15
- if (initialValue === null || initialValue === undefined)
16
- return propertyMutation.value;
17
- return initialValue + propertyMutation.value;
18
- default:
19
- throw new Error('Unknown string function: ' + JSON.stringify(propertyMutation));
20
- }
21
- }
22
- function applyNumericFn(initialValue, propertyMutation) {
23
- switch (propertyMutation.fn) {
24
- case 'increment':
25
- if (initialValue === null || initialValue === undefined)
26
- return propertyMutation.value;
27
- return initialValue + propertyMutation.value;
28
- default:
29
- throw new Error('Unknown numeric function: ' + JSON.stringify(propertyMutation));
30
- }
31
- }
32
- function applyPropertyMutation(property, propertyMutation) {
33
- switch (propertyMutation.type) {
34
- case 'applyNumericFn':
35
- return applyNumericFn(property, propertyMutation);
36
- case 'applyStringFn':
37
- return applyStringFn(property, propertyMutation);
38
- case 'update':
39
- return typeof propertyMutation.value === 'object' ? _.cloneDeep(propertyMutation.value) : propertyMutation.value;
40
- case 'removeProperty':
41
- return undefined;
42
- default:
43
- throw new Error('Unknown property mutation type: ' + JSON.stringify(propertyMutation));
44
- }
45
- }
46
- function sortUpdateMutationProperties(updateMutation) {
47
- return Object.entries(updateMutation.properties).sort(([propA], [propB]) => {
48
- const propADots = propA.split('.').length;
49
- const propBDots = propB.split('.').length;
50
- return propADots - propBDots;
51
- });
52
- }
53
- exports.sortUpdateMutationProperties = sortUpdateMutationProperties;
54
- function mergeMutations(mutationA, mutationB) {
55
- if (mutationB.type === 'insert')
56
- return mutationB;
57
- if (mutationB.type === 'delete')
58
- return mutationB;
59
- if (mutationA.type === 'delete')
60
- throw new Error('Cannot delete and then update');
61
- (0, assertic_1.assertTruthy)(mutationB.type === 'update', 'Invalid mutation type');
62
- if (mutationA.type === 'update')
63
- return mergeUpdateMutations(mutationA, mutationB);
64
- const result = _.cloneDeep(mutationA);
65
- for (const [fieldName, propertyMutationsAr] of sortUpdateMutationProperties(mutationB)) {
66
- const propertyMutations = propertyMutationsAr;
67
- for (const propertyMutation of propertyMutations) {
68
- const value = applyPropertyMutation((0, object_1.getInPath)(result.properties, fieldName), propertyMutation);
69
- if (value === undefined) {
70
- (0, object_1.deleteInPath)(result.properties, fieldName);
71
- }
72
- else {
73
- (0, object_1.setInPath)(result.properties, fieldName, value);
74
- }
75
- }
76
- }
77
- return result;
78
- }
79
- exports.mergeMutations = mergeMutations;
80
- function mergeUpdateMutations(mutationA, mutationB) {
81
- const result = _.cloneDeep(mutationA);
82
- mutationB = _.cloneDeep(mutationB);
83
- for (const [aPropName] of sortUpdateMutationProperties(result)) {
84
- const aPropNameDots = aPropName.split('.').length;
85
- const isOverriddenByMutationB = Object.entries(mutationB.properties).some(([bPropName]) => {
86
- return aPropName.startsWith(bPropName + '.') && aPropNameDots > bPropName.split('.').length;
87
- });
88
- if (isOverriddenByMutationB) {
89
- delete result.properties[aPropName];
90
- }
91
- }
92
- for (const [bPropName, bPropValues] of sortUpdateMutationProperties(mutationB)) {
93
- result.properties[bPropName] = [...(result.properties[bPropName] || []), ...bPropValues];
94
- }
95
- return result;
96
- }
97
- function applyUpdateMutation(doc, updateMutation) {
98
- if (!doc)
99
- return undefined;
100
- const result = Object.assign({}, doc);
101
- const entries = sortUpdateMutationProperties(updateMutation);
102
- for (const [fieldName, propertyMutationsAr] of entries) {
103
- const propertyMutations = propertyMutationsAr;
104
- for (const propertyMutation of propertyMutations) {
105
- const value = applyPropertyMutation((0, object_1.getInPath)(result, fieldName), propertyMutation);
106
- if (value === undefined) {
107
- (0, object_1.deleteInPath)(result, fieldName);
108
- }
109
- else {
110
- (0, object_1.setInPath)(result, fieldName, value);
111
- }
112
- }
113
- }
114
- return result;
115
- }
116
- exports.applyUpdateMutation = applyUpdateMutation;
117
- function convertInsertToUpdate(insertMutation) {
118
- const result = {
119
- type: 'update',
120
- squidDocIdObj: insertMutation.squidDocIdObj,
121
- properties: {},
122
- };
123
- for (const [key, value] of Object.entries(insertMutation.properties)) {
124
- result.properties[key] = [{ type: 'update', value }];
125
- }
126
- return result;
127
- }
128
- exports.convertInsertToUpdate = convertInsertToUpdate;
129
- function reduceMutations(mutations) {
130
- let result = [];
131
- (0, rxjs_1.from)(mutations)
132
- .pipe((0, rxjs_1.groupBy)(mutation => {
133
- return `${mutation.squidDocIdObj.integrationId}${mutation.squidDocIdObj.collectionName}/${mutation.squidDocIdObj.docId}`;
134
- }), (0, rxjs_1.mergeMap)(mutationsGroup => mutationsGroup.pipe((0, rxjs_1.reduce)((mutationA, mutationB) => {
135
- return mergeMutations(mutationA, mutationB);
136
- }))), (0, rxjs_1.toArray)())
137
- .subscribe(value => {
138
- result = value;
139
- });
140
- return result;
141
- }
142
- exports.reduceMutations = reduceMutations;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reduceMutations = exports.convertInsertToUpdate = exports.applyUpdateMutation = exports.mergeMutations = exports.sortUpdateMutationProperties = void 0;
4
+ const assertic_1 = require("assertic");
5
+ const _ = require("lodash");
6
+ const rxjs_1 = require("rxjs");
7
+ const object_1 = require("./utils/object");
8
+ function applyStringFn(initialValue, propertyMutation) {
9
+ switch (propertyMutation.fn) {
10
+ case 'trim':
11
+ if (typeof initialValue !== 'string')
12
+ return initialValue;
13
+ return initialValue.trim();
14
+ case 'extendString':
15
+ if (initialValue === null || initialValue === undefined)
16
+ return propertyMutation.value;
17
+ return initialValue + propertyMutation.value;
18
+ default:
19
+ throw new Error('Unknown string function: ' + JSON.stringify(propertyMutation));
20
+ }
21
+ }
22
+ function applyNumericFn(initialValue, propertyMutation) {
23
+ switch (propertyMutation.fn) {
24
+ case 'increment':
25
+ if (initialValue === null || initialValue === undefined)
26
+ return propertyMutation.value;
27
+ return initialValue + propertyMutation.value;
28
+ default:
29
+ throw new Error('Unknown numeric function: ' + JSON.stringify(propertyMutation));
30
+ }
31
+ }
32
+ function applyPropertyMutation(property, propertyMutation) {
33
+ switch (propertyMutation.type) {
34
+ case 'applyNumericFn':
35
+ return applyNumericFn(property, propertyMutation);
36
+ case 'applyStringFn':
37
+ return applyStringFn(property, propertyMutation);
38
+ case 'update':
39
+ return typeof propertyMutation.value === 'object' ? _.cloneDeep(propertyMutation.value) : propertyMutation.value;
40
+ case 'removeProperty':
41
+ return undefined;
42
+ default:
43
+ throw new Error('Unknown property mutation type: ' + JSON.stringify(propertyMutation));
44
+ }
45
+ }
46
+ function sortUpdateMutationProperties(updateMutation) {
47
+ return Object.entries(updateMutation.properties).sort(([propA], [propB]) => {
48
+ const propADots = propA.split('.').length;
49
+ const propBDots = propB.split('.').length;
50
+ return propADots - propBDots;
51
+ });
52
+ }
53
+ exports.sortUpdateMutationProperties = sortUpdateMutationProperties;
54
+ function mergeMutations(mutationA, mutationB) {
55
+ if (mutationB.type === 'insert')
56
+ return mutationB;
57
+ if (mutationB.type === 'delete')
58
+ return mutationB;
59
+ if (mutationA.type === 'delete')
60
+ throw new Error('Cannot delete and then update');
61
+ (0, assertic_1.assertTruthy)(mutationB.type === 'update', 'Invalid mutation type');
62
+ if (mutationA.type === 'update')
63
+ return mergeUpdateMutations(mutationA, mutationB);
64
+ const result = _.cloneDeep(mutationA);
65
+ for (const [fieldName, propertyMutationsAr] of sortUpdateMutationProperties(mutationB)) {
66
+ const propertyMutations = propertyMutationsAr;
67
+ for (const propertyMutation of propertyMutations) {
68
+ const value = applyPropertyMutation((0, object_1.getInPath)(result.properties, fieldName), propertyMutation);
69
+ if (value === undefined) {
70
+ (0, object_1.deleteInPath)(result.properties, fieldName);
71
+ }
72
+ else {
73
+ (0, object_1.setInPath)(result.properties, fieldName, value);
74
+ }
75
+ }
76
+ }
77
+ return result;
78
+ }
79
+ exports.mergeMutations = mergeMutations;
80
+ function mergeUpdateMutations(mutationA, mutationB) {
81
+ const result = _.cloneDeep(mutationA);
82
+ mutationB = _.cloneDeep(mutationB);
83
+ for (const [aPropName] of sortUpdateMutationProperties(result)) {
84
+ const aPropNameDots = aPropName.split('.').length;
85
+ const isOverriddenByMutationB = Object.entries(mutationB.properties).some(([bPropName]) => {
86
+ return aPropName.startsWith(bPropName + '.') && aPropNameDots > bPropName.split('.').length;
87
+ });
88
+ if (isOverriddenByMutationB) {
89
+ delete result.properties[aPropName];
90
+ }
91
+ }
92
+ for (const [bPropName, bPropValues] of sortUpdateMutationProperties(mutationB)) {
93
+ result.properties[bPropName] = [...(result.properties[bPropName] || []), ...bPropValues];
94
+ }
95
+ return result;
96
+ }
97
+ function applyUpdateMutation(doc, updateMutation) {
98
+ if (!doc)
99
+ return undefined;
100
+ const result = Object.assign({}, doc);
101
+ const entries = sortUpdateMutationProperties(updateMutation);
102
+ for (const [fieldName, propertyMutationsAr] of entries) {
103
+ const propertyMutations = propertyMutationsAr;
104
+ for (const propertyMutation of propertyMutations) {
105
+ const value = applyPropertyMutation((0, object_1.getInPath)(result, fieldName), propertyMutation);
106
+ if (value === undefined) {
107
+ (0, object_1.deleteInPath)(result, fieldName);
108
+ }
109
+ else {
110
+ (0, object_1.setInPath)(result, fieldName, value);
111
+ }
112
+ }
113
+ }
114
+ return result;
115
+ }
116
+ exports.applyUpdateMutation = applyUpdateMutation;
117
+ function convertInsertToUpdate(insertMutation) {
118
+ const result = {
119
+ type: 'update',
120
+ squidDocIdObj: insertMutation.squidDocIdObj,
121
+ properties: {},
122
+ };
123
+ for (const [key, value] of Object.entries(insertMutation.properties)) {
124
+ result.properties[key] = [{ type: 'update', value }];
125
+ }
126
+ return result;
127
+ }
128
+ exports.convertInsertToUpdate = convertInsertToUpdate;
129
+ function reduceMutations(mutations) {
130
+ let result = [];
131
+ (0, rxjs_1.from)(mutations)
132
+ .pipe((0, rxjs_1.groupBy)(mutation => {
133
+ return `${mutation.squidDocIdObj.integrationId}${mutation.squidDocIdObj.collectionName}/${mutation.squidDocIdObj.docId}`;
134
+ }), (0, rxjs_1.mergeMap)(mutationsGroup => mutationsGroup.pipe((0, rxjs_1.reduce)((mutationA, mutationB) => {
135
+ return mergeMutations(mutationA, mutationB);
136
+ }))), (0, rxjs_1.toArray)())
137
+ .subscribe(value => {
138
+ result = value;
139
+ });
140
+ return result;
141
+ }
142
+ exports.reduceMutations = reduceMutations;
143
143
  //# sourceMappingURL=mutation.types.js.map
@@ -1,7 +1,7 @@
1
- import { ClientId } from './communication.types';
2
- export declare class NativeQueryContext {
3
- readonly query: string;
4
- readonly params: Record<string, any>;
5
- readonly clientId: ClientId;
6
- constructor(query: string, params: Record<string, any>, clientId: ClientId);
7
- }
1
+ import { ClientId } from './communication.types';
2
+ export declare class NativeQueryContext {
3
+ readonly query: string;
4
+ readonly params: Record<string, any>;
5
+ readonly clientId: ClientId;
6
+ constructor(query: string, params: Record<string, any>, clientId: ClientId);
7
+ }
@@ -1,12 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NativeQueryContext = void 0;
4
- class NativeQueryContext {
5
- constructor(query, params, clientId) {
6
- this.query = query;
7
- this.params = params;
8
- this.clientId = clientId;
9
- }
10
- }
11
- exports.NativeQueryContext = NativeQueryContext;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NativeQueryContext = void 0;
4
+ class NativeQueryContext {
5
+ constructor(query, params, clientId) {
6
+ this.query = query;
7
+ this.params = params;
8
+ this.clientId = clientId;
9
+ }
10
+ }
11
+ exports.NativeQueryContext = NativeQueryContext;
12
12
  //# sourceMappingURL=native-query.context.js.map
@@ -1,16 +1,16 @@
1
- export type NativeQueryRequestType = 'relational' | 'mongo';
2
- interface BaseNativeQueryRequest {
3
- type: NativeQueryRequestType;
4
- }
5
- export interface RelationalNativeQueryRequest extends BaseNativeQueryRequest {
6
- type: 'relational';
7
- query: string;
8
- params: Record<string, any>;
9
- }
10
- export interface MongoNativeQueryRequest extends BaseNativeQueryRequest {
11
- type: 'mongo';
12
- collectionName: string;
13
- aggregationPipeline: Array<any | undefined>;
14
- }
15
- export type NativeQueryRequest = RelationalNativeQueryRequest | MongoNativeQueryRequest;
16
- export {};
1
+ export type NativeQueryRequestType = 'relational' | 'mongo';
2
+ interface BaseNativeQueryRequest {
3
+ type: NativeQueryRequestType;
4
+ }
5
+ export interface RelationalNativeQueryRequest extends BaseNativeQueryRequest {
6
+ type: 'relational';
7
+ query: string;
8
+ params: Record<string, any>;
9
+ }
10
+ export interface MongoNativeQueryRequest extends BaseNativeQueryRequest {
11
+ type: 'mongo';
12
+ collectionName: string;
13
+ aggregationPipeline: Array<any | undefined>;
14
+ }
15
+ export type NativeQueryRequest = RelationalNativeQueryRequest | MongoNativeQueryRequest;
16
+ export {};
@@ -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=native-query.types.js.map
@@ -1,38 +1,38 @@
1
- import { Observable } from 'rxjs';
2
- import { DocumentData, FieldName, PrimitiveFieldType } from '../document.types';
3
- import { FieldSort, Operator, SimpleCondition } from '../query.types';
4
- import { SerializedQuery } from './serialized-query.types';
5
- import { PaginationOptions, Pagination } from './pagination';
6
- export interface SnapshotEmitter<ReturnType> {
7
- snapshot(): Promise<Array<ReturnType>>;
8
- snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
9
- peek(): Array<ReturnType>;
10
- clone(): SnapshotEmitter<ReturnType>;
11
- getSortOrders(): Array<FieldSort<any>>;
12
- addCompositeCondition(conditions: Array<SimpleCondition>): SnapshotEmitter<ReturnType>;
13
- limit(limit: number): SnapshotEmitter<ReturnType>;
14
- getLimit(): number;
15
- flipSortOrder(): SnapshotEmitter<ReturnType>;
16
- extractData(data: ReturnType): any;
17
- paginate(options?: Partial<PaginationOptions>): Pagination<ReturnType>;
18
- serialize(): SerializedQuery;
19
- }
20
- export declare abstract class BaseQueryBuilder<MyDocType extends DocumentData> {
21
- protected containsEmptyInCondition: boolean;
22
- abstract where(fieldName: (keyof MyDocType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
23
- eq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
24
- neq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
25
- in(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
26
- nin(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
27
- gt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
28
- gte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
29
- lt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
30
- lte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
31
- like(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
32
- notLike(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
33
- abstract limit(limit: number): this;
34
- abstract sortBy(fieldName: keyof MyDocType & FieldName, asc?: boolean): this;
35
- }
36
- export interface HasDereference {
37
- dereference(): any;
38
- }
1
+ import { Observable } from 'rxjs';
2
+ import { DocumentData, FieldName, PrimitiveFieldType } from '../document.types';
3
+ import { FieldSort, Operator, SimpleCondition } from '../query.types';
4
+ import { SerializedQuery } from './serialized-query.types';
5
+ import { PaginationOptions, Pagination } from './pagination';
6
+ export interface SnapshotEmitter<ReturnType> {
7
+ snapshot(): Promise<Array<ReturnType>>;
8
+ snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
9
+ peek(): Array<ReturnType>;
10
+ clone(): SnapshotEmitter<ReturnType>;
11
+ getSortOrders(): Array<FieldSort<any>>;
12
+ addCompositeCondition(conditions: Array<SimpleCondition>): SnapshotEmitter<ReturnType>;
13
+ limit(limit: number): SnapshotEmitter<ReturnType>;
14
+ getLimit(): number;
15
+ flipSortOrder(): SnapshotEmitter<ReturnType>;
16
+ extractData(data: ReturnType): any;
17
+ paginate(options?: Partial<PaginationOptions>): Pagination<ReturnType>;
18
+ serialize(): SerializedQuery;
19
+ }
20
+ export declare abstract class BaseQueryBuilder<MyDocType extends DocumentData> {
21
+ protected containsEmptyInCondition: boolean;
22
+ abstract where(fieldName: (keyof MyDocType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
23
+ eq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
24
+ neq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
25
+ in(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
26
+ nin(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
27
+ gt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
28
+ gte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
29
+ lt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
30
+ lte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
31
+ like(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
32
+ notLike(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
33
+ abstract limit(limit: number): this;
34
+ abstract sortBy(fieldName: keyof MyDocType & FieldName, asc?: boolean): this;
35
+ }
36
+ export interface HasDereference {
37
+ dereference(): any;
38
+ }
@@ -1,40 +1,40 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseQueryBuilder = void 0;
4
- class BaseQueryBuilder {
5
- constructor() {
6
- this.containsEmptyInCondition = false;
7
- }
8
- eq(fieldName, value) {
9
- return this.where(fieldName, '==', value);
10
- }
11
- neq(fieldName, value) {
12
- return this.where(fieldName, '!=', value);
13
- }
14
- in(fieldName, value) {
15
- return this.where(fieldName, 'in', value);
16
- }
17
- nin(fieldName, value) {
18
- return this.where(fieldName, 'not in', value);
19
- }
20
- gt(fieldName, value) {
21
- return this.where(fieldName, '>', value);
22
- }
23
- gte(fieldName, value) {
24
- return this.where(fieldName, '>=', value);
25
- }
26
- lt(fieldName, value) {
27
- return this.where(fieldName, '<', value);
28
- }
29
- lte(fieldName, value) {
30
- return this.where(fieldName, '<=', value);
31
- }
32
- like(fieldName, pattern, caseSensitive) {
33
- return this.where(fieldName, caseSensitive ? 'like_cs' : 'like', pattern);
34
- }
35
- notLike(fieldName, pattern, caseSensitive) {
36
- return this.where(fieldName, caseSensitive ? 'not like_cs' : 'not like', pattern);
37
- }
38
- }
39
- exports.BaseQueryBuilder = BaseQueryBuilder;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseQueryBuilder = void 0;
4
+ class BaseQueryBuilder {
5
+ constructor() {
6
+ this.containsEmptyInCondition = false;
7
+ }
8
+ eq(fieldName, value) {
9
+ return this.where(fieldName, '==', value);
10
+ }
11
+ neq(fieldName, value) {
12
+ return this.where(fieldName, '!=', value);
13
+ }
14
+ in(fieldName, value) {
15
+ return this.where(fieldName, 'in', value);
16
+ }
17
+ nin(fieldName, value) {
18
+ return this.where(fieldName, 'not in', value);
19
+ }
20
+ gt(fieldName, value) {
21
+ return this.where(fieldName, '>', value);
22
+ }
23
+ gte(fieldName, value) {
24
+ return this.where(fieldName, '>=', value);
25
+ }
26
+ lt(fieldName, value) {
27
+ return this.where(fieldName, '<', value);
28
+ }
29
+ lte(fieldName, value) {
30
+ return this.where(fieldName, '<=', value);
31
+ }
32
+ like(fieldName, pattern, caseSensitive) {
33
+ return this.where(fieldName, caseSensitive ? 'like_cs' : 'like', pattern);
34
+ }
35
+ notLike(fieldName, pattern, caseSensitive) {
36
+ return this.where(fieldName, caseSensitive ? 'not like_cs' : 'not like', pattern);
37
+ }
38
+ }
39
+ exports.BaseQueryBuilder = BaseQueryBuilder;
40
40
  //# sourceMappingURL=base-query-builder.js.map