@squidcloud/client 1.0.145 → 1.0.146-beta

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 (206) hide show
  1. package/dist/cjs/index.js +1 -53942
  2. package/dist/esm/index.js +1 -0
  3. package/dist/internal-common/src/metric-name.d.ts +9 -0
  4. package/dist/internal-common/src/public-types/ai-agent-integrations.public-types.d.ts +47 -0
  5. package/dist/internal-common/src/public-types/ai-agent.public-types.d.ts +895 -0
  6. package/dist/internal-common/src/public-types/ai-assistant.public-types.d.ts +31 -0
  7. package/dist/internal-common/src/public-types/ai-common.public-types.d.ts +185 -0
  8. package/dist/internal-common/src/public-types/ai-knowledge-base.public-types.d.ts +431 -0
  9. package/dist/internal-common/src/public-types/ai-matchmaking.public-types.d.ts +186 -0
  10. package/dist/internal-common/src/public-types/ai-query.public-types.d.ts +170 -0
  11. package/dist/internal-common/src/public-types/api-client.public-types.d.ts +9 -0
  12. package/dist/internal-common/src/public-types/api.public-types.d.ts +91 -0
  13. package/dist/internal-common/src/public-types/backend.public-types.d.ts +50 -0
  14. package/dist/{common/src/backend-function.schemas.d.ts → internal-common/src/public-types/code-executor.public-types.d.ts} +1 -1
  15. package/dist/internal-common/src/public-types/communication.public-types.d.ts +30 -0
  16. package/dist/internal-common/src/public-types/context.public-types.d.ts +83 -0
  17. package/dist/internal-common/src/public-types/document.public-types.d.ts +71 -0
  18. package/dist/internal-common/src/public-types/external-auth/external-auth.public-types.d.ts +39 -0
  19. package/dist/internal-common/src/public-types/extraction.public-types.d.ts +183 -0
  20. package/dist/internal-common/src/public-types/http-status.public-types.d.ts +415 -0
  21. package/dist/internal-common/src/public-types/integration.public-types.d.ts +51 -0
  22. package/dist/internal-common/src/public-types/job.public-types.d.ts +59 -0
  23. package/dist/internal-common/src/public-types/metric.public-types.d.ts +154 -0
  24. package/dist/internal-common/src/public-types/openapi.public-types.d.ts +9 -0
  25. package/dist/internal-common/src/public-types/query.public-types.d.ts +113 -0
  26. package/dist/internal-common/src/public-types/regions.public-types.d.ts +4 -0
  27. package/dist/internal-common/src/public-types/scheduler.public-types.d.ts +43 -0
  28. package/dist/{common/src/schema/schema.types.d.ts → internal-common/src/public-types/schema.public-types.d.ts} +54 -54
  29. package/dist/internal-common/src/public-types/secret.public-types.d.ts +51 -0
  30. package/dist/internal-common/src/public-types/serialized-query.public-types.d.ts +60 -0
  31. package/dist/internal-common/src/public-types/socket.public-types.d.ts +4 -0
  32. package/dist/{common/src/types.d.ts → internal-common/src/public-types/typescript.public-types.d.ts} +20 -14
  33. package/dist/internal-common/src/public-types/web.public-types.d.ts +93 -0
  34. package/dist/internal-common/src/public-types-backend/api-call.public-context.d.ts +30 -0
  35. package/dist/internal-common/src/public-types-backend/mutation.public-context.d.ts +148 -0
  36. package/dist/internal-common/src/public-types-backend/native-query.public-context.d.ts +72 -0
  37. package/dist/{common/src/query/query-context.d.ts → internal-common/src/public-types-backend/query.public-context.d.ts} +177 -137
  38. package/dist/{common/src/ai-chatbot.schemas.d.ts → internal-common/src/public-utils/context-utils.d.ts} +1 -1
  39. package/dist/internal-common/src/public-utils/id-utils.d.ts +44 -0
  40. package/dist/internal-common/src/types/ai-agent.types.d.ts +199 -0
  41. package/dist/{common/src/mutation.schemas.d.ts → internal-common/src/types/ai-assistant.types.d.ts} +1 -1
  42. package/dist/internal-common/src/types/ai-knowledge-base.types.d.ts +202 -0
  43. package/dist/internal-common/src/types/ai-matchmaking.types.d.ts +59 -0
  44. package/dist/{common/src → internal-common/src/types}/backend-function.types.d.ts +1 -1
  45. package/dist/internal-common/src/types/communication.types.d.ts +1 -0
  46. package/dist/internal-common/src/types/document.types.d.ts +1 -0
  47. package/dist/internal-common/src/types/file.types.d.ts +6 -0
  48. package/dist/internal-common/src/types/headers.types.d.ts +17 -0
  49. package/dist/internal-common/src/types/mutation.types.d.ts +1 -0
  50. package/dist/internal-common/src/types/notification.types.d.ts +5 -0
  51. package/dist/internal-common/src/types/observability.types.d.ts +78 -0
  52. package/dist/internal-common/src/types/query.types.d.ts +13 -0
  53. package/dist/internal-common/src/types/secret.types.d.ts +7 -0
  54. package/dist/internal-common/src/types/socket.types.d.ts +1 -0
  55. package/dist/internal-common/src/types/stage.d.ts +9 -0
  56. package/dist/{common/src → internal-common/src/types}/time-units.d.ts +1 -1
  57. package/dist/internal-common/src/types/url-shortener.types.d.ts +41 -0
  58. package/dist/internal-common/src/utils/array.d.ts +7 -0
  59. package/dist/internal-common/src/utils/e2e-test-utils.d.ts +2 -0
  60. package/dist/{common → internal-common}/src/utils/global.utils.d.ts +1 -1
  61. package/dist/internal-common/src/utils/http.d.ts +5 -0
  62. package/dist/{common → internal-common}/src/utils/lock.manager.d.ts +14 -14
  63. package/dist/internal-common/src/utils/metric-utils.d.ts +4 -0
  64. package/dist/internal-common/src/utils/metrics.types.d.ts +7 -0
  65. package/dist/internal-common/src/utils/object.d.ts +58 -0
  66. package/dist/internal-common/src/utils/serialization.d.ts +17 -0
  67. package/dist/internal-common/src/utils/squid.constants.d.ts +1 -0
  68. package/dist/internal-common/src/utils/trace-id-generator.d.ts +1 -0
  69. package/dist/internal-common/src/utils/validation.d.ts +19 -0
  70. package/dist/{common → internal-common}/src/websocket.impl.d.ts +26 -21
  71. package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -1239
  72. package/dist/typescript-client/src/admin-client.d.ts +23 -0
  73. package/dist/typescript-client/src/agent/ai-agent-client-reference.d.ts +181 -0
  74. package/dist/typescript-client/src/agent/ai-agent-client.d.ts +37 -0
  75. package/dist/typescript-client/src/agent/ai-agent-client.types.d.ts +69 -0
  76. package/dist/typescript-client/src/ai-assistant-client.d.ts +72 -73
  77. package/dist/typescript-client/src/ai-audio-client.d.ts +25 -0
  78. package/dist/typescript-client/src/ai-client.d.ts +129 -0
  79. package/dist/typescript-client/src/ai-files-client.d.ts +33 -0
  80. package/dist/typescript-client/src/ai-image-client.d.ts +25 -0
  81. package/dist/typescript-client/src/ai-knowledge-base/ai-knowledge-base-client-reference.d.ts +86 -0
  82. package/dist/typescript-client/src/ai-knowledge-base/ai-knowledge-base-client.d.ts +28 -0
  83. package/dist/typescript-client/src/ai-matchmaking-client.d.ts +99 -0
  84. package/dist/typescript-client/src/api-client.d.ts +69 -0
  85. package/dist/typescript-client/src/auth.manager.d.ts +11 -26
  86. package/dist/typescript-client/src/backend-function.manager.d.ts +1 -9
  87. package/dist/typescript-client/src/client-customization.utils.d.ts +1 -0
  88. package/dist/typescript-client/src/client-id.service.d.ts +1 -27
  89. package/dist/typescript-client/src/collection-reference.d.ts +105 -80
  90. package/dist/typescript-client/src/collection-reference.factory.d.ts +1 -13
  91. package/dist/typescript-client/src/connection-details.d.ts +24 -23
  92. package/dist/typescript-client/src/console-utils.d.ts +1 -0
  93. package/dist/typescript-client/src/data.manager.d.ts +1 -173
  94. package/dist/typescript-client/src/destruct.manager.d.ts +1 -12
  95. package/dist/typescript-client/src/distributed-lock.manager.d.ts +39 -16
  96. package/dist/typescript-client/src/document-identity.service.d.ts +1 -12
  97. package/dist/typescript-client/src/document-reference.d.ts +151 -140
  98. package/dist/typescript-client/src/document-reference.factory.d.ts +1 -13
  99. package/dist/typescript-client/src/document-store.d.ts +1 -14
  100. package/dist/typescript-client/src/execute-function-options.d.ts +73 -0
  101. package/dist/typescript-client/src/external-auth-client.d.ts +36 -0
  102. package/dist/typescript-client/src/extraction-client.d.ts +32 -0
  103. package/dist/typescript-client/src/file-args-transformer.d.ts +1 -0
  104. package/dist/typescript-client/src/file-utils.d.ts +1 -0
  105. package/dist/typescript-client/src/index.d.ts +63 -9
  106. package/dist/typescript-client/src/integration-client.d.ts +60 -0
  107. package/dist/typescript-client/src/job-client.d.ts +32 -0
  108. package/dist/typescript-client/src/mutation/mutation-sender.d.ts +1 -10
  109. package/dist/typescript-client/src/native-query-manager.d.ts +1 -7
  110. package/dist/typescript-client/src/notification-client.d.ts +20 -0
  111. package/dist/typescript-client/src/observability-client.d.ts +43 -0
  112. package/dist/typescript-client/src/public-types.d.ts +30 -0
  113. package/dist/typescript-client/src/public-utils.d.ts +1 -0
  114. package/dist/typescript-client/src/query/deserializer.d.ts +10 -3
  115. package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +316 -161
  116. package/dist/typescript-client/src/query/local-query-manager.d.ts +1 -9
  117. package/dist/{common → typescript-client}/src/query/pagination.d.ts +65 -62
  118. package/dist/typescript-client/src/query/query-builder.factory.d.ts +228 -77
  119. package/dist/typescript-client/src/query/query-sender.d.ts +1 -33
  120. package/dist/typescript-client/src/query/query-subscription.manager.d.ts +1 -130
  121. package/dist/typescript-client/src/query/query.types.d.ts +16 -49
  122. package/dist/typescript-client/src/query/snapshot-emitter.d.ts +41 -0
  123. package/dist/typescript-client/src/query-utils.d.ts +18 -0
  124. package/dist/typescript-client/src/queue.manager.d.ts +12 -0
  125. package/dist/typescript-client/src/rate-limiter.d.ts +1 -32
  126. package/dist/typescript-client/src/rpc.manager.d.ts +1 -30
  127. package/dist/typescript-client/src/scheduler-client.d.ts +31 -0
  128. package/dist/typescript-client/src/secret.client.d.ts +96 -22
  129. package/dist/typescript-client/src/socket.manager.d.ts +1 -43
  130. package/dist/typescript-client/src/squid-http-client.d.ts +11 -0
  131. package/dist/typescript-client/src/squid.d.ts +378 -269
  132. package/dist/typescript-client/src/state/state.service.spec.d.ts +1 -1
  133. package/dist/typescript-client/src/storage-client.d.ts +145 -0
  134. package/dist/typescript-client/src/types.d.ts +27 -2
  135. package/dist/typescript-client/src/version.d.ts +5 -0
  136. package/dist/typescript-client/src/web-client.d.ts +63 -0
  137. package/dist/typescript-client/src/webhook.manager.d.ts +10 -0
  138. package/package.json +34 -18
  139. package/dist/common/src/ai-assistant.types.d.ts +0 -25
  140. package/dist/common/src/ai-chatbot.context.d.ts +0 -12
  141. package/dist/common/src/ai-chatbot.types.d.ts +0 -27
  142. package/dist/common/src/api-call.context.d.ts +0 -13
  143. package/dist/common/src/api.types.d.ts +0 -4
  144. package/dist/common/src/application.schemas.d.ts +0 -66
  145. package/dist/common/src/application.types.d.ts +0 -143
  146. package/dist/common/src/backend-run.types.d.ts +0 -2
  147. package/dist/common/src/bundle-api.types.d.ts +0 -43
  148. package/dist/common/src/bundle-data.types.d.ts +0 -5
  149. package/dist/common/src/communication.types.d.ts +0 -8
  150. package/dist/common/src/context.types.d.ts +0 -40
  151. package/dist/common/src/distributed-lock.context.d.ts +0 -4
  152. package/dist/common/src/document.types.d.ts +0 -22
  153. package/dist/common/src/graphql.context.d.ts +0 -7
  154. package/dist/common/src/graphql.types.d.ts +0 -9
  155. package/dist/common/src/heartbeat.types.d.ts +0 -1
  156. package/dist/common/src/http-status.enum.d.ts +0 -50
  157. package/dist/common/src/index.d.ts +0 -57
  158. package/dist/common/src/integrations/ai_chatbot.types.d.ts +0 -31
  159. package/dist/common/src/integrations/api.types.d.ts +0 -80
  160. package/dist/common/src/integrations/auth.types.d.ts +0 -47
  161. package/dist/common/src/integrations/database.types.d.ts +0 -274
  162. package/dist/common/src/integrations/index.d.ts +0 -134
  163. package/dist/common/src/integrations/observability.types.d.ts +0 -23
  164. package/dist/common/src/logger.types.d.ts +0 -21
  165. package/dist/common/src/metrics.types.d.ts +0 -1
  166. package/dist/common/src/mutation.context.d.ts +0 -14
  167. package/dist/common/src/mutation.types.d.ts +0 -53
  168. package/dist/common/src/named-query.context.d.ts +0 -4
  169. package/dist/common/src/named-query.schemas.d.ts +0 -1
  170. package/dist/common/src/named-query.types.d.ts +0 -1
  171. package/dist/common/src/native-query.context.d.ts +0 -7
  172. package/dist/common/src/native-query.types.d.ts +0 -16
  173. package/dist/common/src/query/base-query-builder.d.ts +0 -147
  174. package/dist/common/src/query/index.d.ts +0 -4
  175. package/dist/common/src/query/serialized-query.types.d.ts +0 -24
  176. package/dist/common/src/query.types.d.ts +0 -64
  177. package/dist/common/src/regions.d.ts +0 -1
  178. package/dist/common/src/secret.schemas.d.ts +0 -1
  179. package/dist/common/src/secret.types.d.ts +0 -22
  180. package/dist/common/src/security.types.d.ts +0 -1
  181. package/dist/common/src/socket.schemas.d.ts +0 -1
  182. package/dist/common/src/socket.types.d.ts +0 -5
  183. package/dist/common/src/trigger.types.d.ts +0 -1
  184. package/dist/common/src/utils/array.d.ts +0 -1
  185. package/dist/common/src/utils/assert.d.ts +0 -1
  186. package/dist/common/src/utils/error.d.ts +0 -4
  187. package/dist/common/src/utils/http.d.ts +0 -2
  188. package/dist/common/src/utils/id.d.ts +0 -2
  189. package/dist/common/src/utils/object.d.ts +0 -5
  190. package/dist/common/src/utils/serialization.d.ts +0 -6
  191. package/dist/common/src/utils/transforms.d.ts +0 -18
  192. package/dist/common/src/utils/url.d.ts +0 -1
  193. package/dist/common/src/utils/validation.d.ts +0 -25
  194. package/dist/common/src/webhook-response.d.ts +0 -1
  195. package/dist/typescript-client/src/ai-chatbot-client.d.ts +0 -174
  196. package/dist/typescript-client/src/ai-chatbot-client.factory.d.ts +0 -8
  197. package/dist/typescript-client/src/ai.types.d.ts +0 -61
  198. package/dist/typescript-client/src/api.manager.d.ts +0 -11
  199. package/dist/typescript-client/src/graphql-client.d.ts +0 -14
  200. package/dist/typescript-client/src/graphql-client.factory.d.ts +0 -11
  201. package/dist/typescript-client/src/named-query.manager.d.ts +0 -11
  202. package/dist/typescript-client/src/state/action.applier.d.ts +0 -7
  203. package/dist/typescript-client/src/state/actions.d.ts +0 -29
  204. package/dist/typescript-client/src/state/path_trie.d.ts +0 -27
  205. package/dist/typescript-client/src/state/state.service.d.ts +0 -22
  206. package/dist/typescript-client/src/testing/setup-tests.d.ts +0 -1
@@ -1,77 +1,228 @@
1
- import { BaseQueryBuilder, DocumentData, FieldName, FieldSort, HasDereference, Operator, Pagination, PaginationOptions, PrimitiveFieldType, SerializedSimpleQuery, SimpleCondition, SnapshotEmitter } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import { DocumentReference } from '../document-reference';
4
- /** A query builder that can be used to build a query that returns a list of documents. */
5
- export declare class QueryBuilder<DocumentType extends DocumentData> extends BaseQueryBuilder<DocumentType> implements SnapshotEmitter<DocumentReference<DocumentType>>, HasDereference {
6
- private readonly collectionName;
7
- private readonly integrationId;
8
- private readonly querySubscriptionManager;
9
- private readonly localQueryManager;
10
- private readonly documentReferenceFactory;
11
- private readonly queryBuilderFactory;
12
- private readonly documentIdentityService;
13
- private forceFetchFromServer;
14
- /** @inheritDoc */
15
- where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
16
- /** @inheritDoc */
17
- limit(limit: number): this;
18
- getLimit(): number;
19
- limitBy(limit: number, ...fields: FieldName[]): this;
20
- /** @inheritDoc */
21
- sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
22
- private mergeConditions;
23
- getSortOrder(): FieldSort<DocumentType>[];
24
- /**
25
- * @inheritDoc
26
- */
27
- snapshot(): Promise<Array<DocumentReference<DocumentType>>>;
28
- /**
29
- * Forces the query to return data from the server even if there is a query that already returned the requested
30
- * result.
31
- */
32
- setForceFetchFromServer(): this;
33
- /**
34
- * @inheritDoc
35
- */
36
- peek(): Array<DocumentReference<DocumentType>>;
37
- /**
38
- * @inheritDoc
39
- */
40
- snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
41
- /**
42
- * @inheritDoc
43
- */
44
- changes(): Observable<Changes<DocumentType>>;
45
- /**
46
- * A unique hash for the query. Identical queries should return the same hash
47
- * value.
48
- *
49
- * @returns The query's hash string.
50
- */
51
- get hash(): string;
52
- /** @inheritDoc */
53
- dereference(): SnapshotEmitter<DocumentType>;
54
- getSortOrders(): Array<FieldSort<any>>;
55
- clone(): QueryBuilder<DocumentType>;
56
- addCompositeCondition(conditions: Array<SimpleCondition>): QueryBuilder<DocumentType>;
57
- flipSortOrder(): QueryBuilder<DocumentType>;
58
- serialize(): SerializedSimpleQuery;
59
- extractData(data: DocumentReference<DocumentType>): DocumentType;
60
- paginate(options?: Partial<PaginationOptions>): Pagination<DocumentReference<DocumentType>>;
61
- }
62
- /** Describes the changes to a query result. */
63
- export declare class Changes<DocumentType extends DocumentData> {
64
- /** The newly inserted documents to the query result */
65
- readonly inserts: Array<DocumentReference<DocumentType>>;
66
- /** The documents that were updated in the query result */
67
- readonly updates: Array<DocumentReference<DocumentType>>;
68
- /** The actual document data that was deleted from the query result */
69
- readonly deletes: Array<DocumentType>;
70
- constructor(
71
- /** The newly inserted documents to the query result */
72
- inserts: Array<DocumentReference<DocumentType>>,
73
- /** The documents that were updated in the query result */
74
- updates: Array<DocumentReference<DocumentType>>,
75
- /** The actual document data that was deleted from the query result */
76
- deletes: Array<DocumentType>);
77
- }
1
+ import { Observable } from 'rxjs';
2
+ import { DocumentReference } from '../document-reference';
3
+ import { DocumentData, FieldName, FieldSort, Operator, PrimitiveFieldType, Query, SerializedSimpleQuery, SimpleCondition } from '../public-types';
4
+ import { Pagination, PaginationOptions } from './pagination';
5
+ import { SnapshotEmitter } from './snapshot-emitter';
6
+ /**
7
+ * Interface used solely for inheritDoc
8
+ * @category Database
9
+ */
10
+ export interface HasDereference {
11
+ /**
12
+ * Dereferences the document references in the result of this query. For example, collection.query().snapshot()
13
+ * returns an array of DocumentReference objects, but collection.query().dereference().snapshot() returns an array of
14
+ * the actual document data.
15
+ */
16
+ dereference(): any;
17
+ }
18
+ /**
19
+ * Query builder base class.
20
+ * @category Database
21
+ */
22
+ export declare abstract class BaseQueryBuilder<MyDocType extends DocumentData> {
23
+ /**
24
+ * A shortcut for `where(fieldName, '==', value)`
25
+ *
26
+ * @param fieldName The name of the field to query.
27
+ * @param value The value to compare against.
28
+ * @returns The query builder.
29
+ */
30
+ eq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
31
+ /**
32
+ * A shortcut for `where(fieldName, '!=', value)`
33
+ * @param fieldName The name of the field to query.
34
+ * @param value The value to compare against.
35
+ * @returns The query builder.
36
+ */
37
+ neq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
38
+ /**
39
+ * A shortcut for `where(fieldName, 'in', value)`
40
+ * @param fieldName The name of the field to query.
41
+ * @param value An array of values to compare against.
42
+ * @returns The query builder.
43
+ */
44
+ in(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
45
+ /**
46
+ * A shortcut for `where(fieldName, 'not in', value)`
47
+ * @param fieldName The name of the field to query.
48
+ * @param value An array of values to compare against.
49
+ * @returns The query builder.
50
+ */
51
+ nin(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
52
+ /**
53
+ * A shortcut for `where(fieldName, '>', value)`
54
+ * @param fieldName The name of the field to query.
55
+ * @param value The value to compare against.
56
+ * @returns The query builder.
57
+ */
58
+ gt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
59
+ /**
60
+ * A shortcut for `where(fieldName, '>=', value)`
61
+ * @param fieldName The name of the field to query.
62
+ * @param value The value to compare against.
63
+ * @returns The query builder.
64
+ */
65
+ gte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
66
+ /**
67
+ * A shortcut for `where(fieldName, '<', value)`
68
+ * @param fieldName The name of the field to query.
69
+ * @param value The value to compare against.
70
+ * @returns The query builder.
71
+ */
72
+ lt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
73
+ /**
74
+ * A shortcut for `where(fieldName, '<=', value)`
75
+ * @param fieldName The name of the field to query.
76
+ * @param value The value to compare against.
77
+ * @returns The query builder.
78
+ */
79
+ lte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
80
+ /**
81
+ * A shortcut for `where(fieldName, 'like', pattern).`
82
+ *
83
+ * @param fieldName The name of the field to query.
84
+ * @param pattern The pattern to compare against. '%' matches 0 or more characters. '_' matches exactly one
85
+ * character. '\' can be used to escape '%', '_'. or another '\'. Note that any '\' that is not followed by '%',
86
+ * '_', or '\' is invalid.
87
+ * @param caseSensitive Whether to use case-sensitive comparison. Defaults to true.
88
+ * @returns The query builder.
89
+ */
90
+ like(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
91
+ /**
92
+ * A shortcut for `where(fieldName, 'not like', pattern).`
93
+ *
94
+ * @param fieldName The name of the field to query.
95
+ * @param pattern The pattern to compare against. '%' matches 0 or more characters. '_' matches exactly one
96
+ * character. '\' can be used to escape '%', '_'. or another '\'. Note that any '\' that is not followed by '%',
97
+ * '_', or '\' is invalid.
98
+ * @param caseSensitive Whether to use case-sensitive comparison. Defaults to true.
99
+ * @returns The query builder.
100
+ */
101
+ notLike(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
102
+ /**
103
+ * Adds a condition to the query to check if the specified field includes any of the given values.
104
+ *
105
+ * @param fieldName The name of the field to query.
106
+ * @param values The values to check for inclusion in the field array.
107
+ * @returns The query builder.
108
+ */
109
+ arrayIncludesSome(fieldName: (keyof MyDocType & FieldName) | string, values: Array<PrimitiveFieldType>): this;
110
+ /**
111
+ * Adds a condition to the query to check if the specified field includes all the given values.
112
+ *
113
+ * @param fieldName The name of the field to query.
114
+ * @param values The values to check for inclusion in the field array.
115
+ * @returns The query builder.
116
+ */
117
+ arrayIncludesAll(fieldName: (keyof MyDocType & FieldName) | string, values: Array<PrimitiveFieldType>): this;
118
+ /**
119
+ * Adds a condition to the query to check if the specified field does not include any of the given values.
120
+ *
121
+ * @param fieldName The name of the field to query.
122
+ * @param values The values to check for non-inclusion in the field array.
123
+ * @returns The query builder.
124
+ */
125
+ arrayNotIncludes(fieldName: (keyof MyDocType & FieldName) | string, values: Array<PrimitiveFieldType>): this;
126
+ /**
127
+ * Adds a condition to the query.
128
+ * @param fieldName The name of the field to query.
129
+ * @param operator The operator to use.
130
+ * @param value The value to compare against.
131
+ * @returns The query builder.
132
+ */
133
+ abstract where(fieldName: (keyof MyDocType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
134
+ /**
135
+ * Sets a limit to the number of results returned by the query. The maximum limit is 20,000 and the default is 1,000
136
+ * if none is provided.
137
+ * @param limit The limit to set.
138
+ * @returns The query builder.
139
+ */
140
+ abstract limit(limit: number): this;
141
+ /**
142
+ * Adds a sort order to the query. You can add multiple sort orders to the query. The order in which you add them
143
+ * determines the order in which they are applied.
144
+ * @param fieldName The name of the field to sort by.
145
+ * @param asc Whether to sort in ascending order. Defaults to true.
146
+ * @returns The query builder.
147
+ */
148
+ abstract sortBy(fieldName: (keyof MyDocType & FieldName) | string, asc?: boolean): this;
149
+ /**
150
+ * Returns the query object built by this query builder.
151
+ */
152
+ abstract build(): Query;
153
+ private throwIfInvalidLikePattern;
154
+ }
155
+ /**
156
+ * A query builder that can be used to build a query that returns a list of documents.
157
+ * @category Database
158
+ */
159
+ export declare class QueryBuilder<DocumentType extends DocumentData> extends BaseQueryBuilder<DocumentType> implements SnapshotEmitter<DocumentReference<DocumentType>>, HasDereference {
160
+ private readonly collectionName;
161
+ private readonly integrationId;
162
+ private readonly querySubscriptionManager;
163
+ private readonly localQueryManager;
164
+ private readonly documentReferenceFactory;
165
+ private readonly queryBuilderFactory;
166
+ private readonly documentIdentityService;
167
+ private forceFetchFromServer;
168
+ /**
169
+ * A unique hash for the query. Identical queries should return the same hash
170
+ * value.
171
+ *
172
+ * @returns The query's hash string.
173
+ */
174
+ get hash(): string;
175
+ /** @inheritDoc */
176
+ where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator, value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
177
+ /** @inheritDoc */
178
+ limit(limit: number): this;
179
+ getLimit(): number;
180
+ limitBy(limit: number, ...fields: FieldName[]): this;
181
+ /** @inheritDoc */
182
+ sortBy(fieldName: (keyof DocumentType & FieldName) | string, asc?: boolean): this;
183
+ /** @inheritDoc */
184
+ build(): Query;
185
+ getSortOrder(): FieldSort<DocumentType>[];
186
+ /**
187
+ * @inheritDoc
188
+ */
189
+ snapshot(): Promise<Array<DocumentReference<DocumentType>>>;
190
+ /**
191
+ * Forces the query to return data from the server even if there is a query that already returned the requested
192
+ * result.
193
+ */
194
+ setForceFetchFromServer(): this;
195
+ /**
196
+ * @inheritDoc
197
+ */
198
+ peek(): Array<DocumentReference<DocumentType>>;
199
+ /**
200
+ * @inheritDoc
201
+ */
202
+ snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
203
+ /**
204
+ * @inheritDoc
205
+ */
206
+ changes(): Observable<Changes<DocumentType>>;
207
+ /** @inheritDoc */
208
+ dereference(): SnapshotEmitter<DocumentType>;
209
+ getSortOrders(): Array<FieldSort<any>>;
210
+ clone(): QueryBuilder<DocumentType>;
211
+ addCompositeCondition(conditions: Array<SimpleCondition>): QueryBuilder<DocumentType>;
212
+ flipSortOrder(): QueryBuilder<DocumentType>;
213
+ serialize(): SerializedSimpleQuery;
214
+ paginate(options?: Partial<PaginationOptions>): Pagination<DocumentReference<DocumentType>>;
215
+ private mergeConditions;
216
+ }
217
+ /**
218
+ * Describes the changes to a query result.
219
+ * @category Database
220
+ */
221
+ export declare class Changes<DocumentType extends DocumentData> {
222
+ /** The newly inserted documents to the query result */
223
+ readonly inserts: Array<DocumentReference<DocumentType>>;
224
+ /** The documents that were updated in the query result */
225
+ readonly updates: Array<DocumentReference<DocumentType>>;
226
+ /** The actual document data that was deleted from the query result */
227
+ readonly deletes: Array<DocumentType>;
228
+ }
@@ -1,33 +1 @@
1
- import { RpcManager } from '../rpc.manager';
2
- import { QueryRequest, QueryResultData } from '@squidcloud/common';
3
- import { BehaviorSubject } from 'rxjs';
4
- import { DestructManager } from '../destruct.manager';
5
- export declare class QuerySender {
6
- private readonly rpcManager;
7
- private readonly destructManager;
8
- /**
9
- * A collection of query requests awaiting batch dispatch.
10
- */
11
- private readonly pendingQueryRequests;
12
- /**
13
- * A timeout identifier used to ensure that only the last query in rapid succession triggers the batch send process.
14
- */
15
- private pendingQueryBatchTimeout?;
16
- /**
17
- * As long as there are mutations in flight we do not want to send queries because it causes race conditions,
18
- * preventing parallel queries and mutations simplifies the mental model.
19
- */
20
- readonly safeToSendQueriesToServer: BehaviorSubject<boolean>;
21
- /**
22
- * The number of queries that are currently in-flight (about to be sent to the server or sent but did not get a
23
- * response yet). This is used by the data manager to prevent it from sending mutations while there are in-flight
24
- * queries.
25
- */
26
- private readonly inflightQueriesCount;
27
- constructor(rpcManager: RpcManager, destructManager: DestructManager);
28
- sendQuery(queryRequest: QueryRequest): Promise<QueryResultData>;
29
- private processQueryBatch;
30
- /** Will resolve once all the in-flight queries are done. */
31
- waitForAllQueriesToFinish(): Promise<void>;
32
- private preDestruct;
33
- }
1
+ export {};
@@ -1,130 +1 @@
1
- import { Alias, ClientRequestId, JoinCondition, Query, QueryResultData, QuerySubscriptionId, SquidDocId, SquidDocument } from '@squidcloud/common';
2
- import { Observable, Subject } from 'rxjs';
3
- import { ClientIdService } from '../client-id.service';
4
- import { DestructManager } from '../destruct.manager';
5
- import DocumentIdentityService from '../document-identity.service';
6
- import { DocumentStore } from '../document-store';
7
- import { RpcManager } from '../rpc.manager';
8
- import { QuerySender } from './query-sender';
9
- import { OngoingQuery } from './query.types';
10
- export declare const FETCH_BEYOND_LIMIT = 100;
11
- export declare const LIMIT_UNDERFLOW_TRIGGER = 20;
12
- export declare class QuerySubscriptionManager {
13
- private readonly rpcManager;
14
- private readonly clientIdService;
15
- private readonly documentStore;
16
- private readonly destructManager;
17
- private readonly documentIdentityService;
18
- private readonly querySender;
19
- /**
20
- * An observable used by the data manager, the query subscription manager (this class) identifies when a document no
21
- * longer has queries that it is part of their result, such document is considered orphan. The data manager will mark
22
- * as orphan.
23
- */
24
- onOrphanDocuments: Subject<string[]>;
25
- /** All the currently running queries with their full state. */
26
- private readonly ongoingQueries;
27
- /**
28
- * The two maps below maintain the relation between document ids we know about locally to clientRequestIds (queries).
29
- * This relation is used for determining whether a document can be safely removed.
30
- */
31
- private readonly clientRequestIdToLocalDocuments;
32
- private readonly localDocumentToClientRequestIds;
33
- /**
34
- * A data structure for mapping queries to allow reverse queries search (given a document, find all the matching
35
- * queries)
36
- */
37
- private readonly queryMappingManager;
38
- private readonly queryResultsSubject;
39
- constructor(rpcManager: RpcManager, clientIdService: ClientIdService, documentStore: DocumentStore, destructManager: DestructManager, documentIdentityService: DocumentIdentityService, querySender: QuerySender);
40
- observeQueryResults(): Observable<QueryResultData>;
41
- /**
42
- * Returns true if the client knows about this clientRequestId. It may happen that it will return false in the case
43
- * that the client unsubscribed from a query but the server sent a mutation update for this clientRequestId.
44
- */
45
- hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
46
- /**
47
- * Returns the query associated with the given clientRequestId. Throws error if the clientRequestId is not known.
48
- */
49
- getQuery(clientRequestId: ClientRequestId): Query;
50
- /**
51
- * A query receives updates from two different sources:
52
- * 1 - An initial snapshot from the server or from a parent query
53
- * 2 - Incremental updates from the server (or from a parent query before the query is registered)
54
- *
55
- * If an incremental update is received before the snapshot was received, we cannot process it for this query.
56
- * This boolean indicates whether the initial snapshot was received.
57
- */
58
- setGotInitialResult(clientRequestId: ClientRequestId): void;
59
- /** Given a document, returns all the queries that should be notified with the new document properties. */
60
- findQueriesForDocument(doc: SquidDocument, squidDocId: SquidDocId): Array<QuerySubscriptionId>;
61
- /**
62
- * Given the new document's properties, finds all the queries that should be notified with the new properties and
63
- * updates the internal mappings (squidDocId --> client request Ids and, clientRequestId --> squidDocIds).
64
- * Returns an array with all the previous and current client request ids (basically all the client request ids that
65
- * will need to be notified due to the change of properties).
66
- */
67
- setClientRequestIdsForLocalDoc(squidDocId: SquidDocId, properties: SquidDocument | undefined): Array<ClientRequestId>;
68
- /**
69
- * Due to an error when syncing a document, all the queries that are subscribed to this document should be notified
70
- * and error out.
71
- */
72
- errorOutAllQueries(squidDocId: SquidDocId, err: any): void;
73
- /** Notifies to all the given queries (identified by their clientRequestId) with the updated query result. */
74
- notifyAllSubscriptions(clientRequestIds: ClientRequestId[]): void;
75
- private isValidParent;
76
- /**
77
- * Given an ongoing query, search for candidate ongoing queries that can serve as a parent.
78
- * If there is a parent query, the result of that query can be used for serving the current query.
79
- * We will still register the current query on the server, but we do not need to run the query, apply security rules,
80
- * etc.
81
- */
82
- private findValidParentOfOngoingQuery;
83
- findValidParentOfQuery(query: Query): OngoingQuery | undefined;
84
- processQuery(query: Query, rootAlias: Alias, joins: Record<string, Query>, joinConditions: Record<Alias, JoinCondition>, subscribe: boolean, forceFetchFromServer: boolean): Observable<Array<Record<Alias, SquidDocument | undefined>>>;
85
- /**
86
- * Returns whether the given document ID has a query that has this document ID as a result.
87
- * A document without a query is considered "un-tracked".
88
- */
89
- hasOngoingQueryForDocId(squidDocId: string): boolean;
90
- /**
91
- * Removes a query from the mapping and updates the orphan documents as needed.
92
- */
93
- private removeClientRequestIdMapping;
94
- /** Register logic for cleaning up the query when it is unsubscribed. */
95
- private registerQueryFinalizer;
96
- /** Creates a graph of ongoing queries and returns the root of the graph. */
97
- private createOngoingQueryGraph;
98
- private collectAllObservables;
99
- private joinResults;
100
- private join;
101
- private getOngoingQueriesBfs;
102
- private updateOngoingQueryWithNewDataFromSupportingQuery;
103
- private allOngoingQueriesGotInitialResult;
104
- private completeAllSupportedQueries;
105
- private preDestruct;
106
- unsubscribe(): void;
107
- hasSubscription(clientRequestId: ClientRequestId): boolean;
108
- /** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
109
- private sendQueryToServerOrUseParentQuery;
110
- /**
111
- * Uses the parent query as the source of data for the given ongoing query until the ongoing query is registered on
112
- * the server. It prevents the parent query from being unsubscribed until the query is registered on the server and
113
- * the first snapshot is received from the parent query.
114
- * 1 - Prevents the parent query from being unsubscribed
115
- * 2 - Connects the results of the parent query to the result of the current ongoing query
116
- * 3 - Registers the query on the server
117
- */
118
- private useParentOngoingQuery;
119
- /**
120
- * Sends the /query request to the server. It:
121
- * 1 - Waits for when it is safe to send a query to the server (no in-flight mutations)
122
- * 2 - Increments the number of inflightQueriesCount to prevent parallel mutations
123
- * 3 - Handles errors
124
- * 4 - Marks the query as registered
125
- */
126
- private sendQueryToServer;
127
- /** naive way to refresh queries/subscriptions when we have a new client id */
128
- private refreshOngoingQueries;
129
- private migrateDocIds;
130
- }
1
+ export {};
@@ -1,49 +1,16 @@
1
- import { Alias, ClientRequestId, JoinCondition, Query, SquidDocument } from '@squidcloud/common';
2
- import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs';
3
- export interface OngoingQuery {
4
- clientRequestId: ClientRequestId;
5
- query: Query;
6
- supportedQueries: Array<OngoingQuery>;
7
- supportingOngoingQuery?: OngoingQuery;
8
- gotInitialResponse: boolean;
9
- activated: boolean;
10
- joinCondition?: JoinCondition;
11
- alias: Alias;
12
- dataSubject: BehaviorSubject<Array<SquidDocument> | null>;
13
- queryRegistered: BehaviorSubject<boolean>;
14
- /**
15
- * In case that this query is a parent of another query (that is, the other query is a subset of this query), this
16
- * query should not be unsubscribed from the server until we registered the child query in the server.
17
- */
18
- unsubscribeBlockerCount: BehaviorSubject<number>;
19
- subscribe: boolean;
20
- /**
21
- * In case of joins, and if this ongoing query is the root, this field emits all the supported observables
22
- * for example A.join(B, {...some join condition...}).join(C, {...some join condition}.
23
- * This field will emit [A.subject.pipe(), B.subject.pipe(), C.subject.pipe()]. Any new supported queries will be
24
- * added here.
25
- */
26
- allObservables?: ReplaySubject<Array<Observable<DocsAndAlias>>>;
27
- isEmptyForJoin: boolean;
28
- done: boolean;
29
- isInFlight: boolean;
30
- forceFetchFromServer: boolean;
31
- /**
32
- * If there's a limit, we request `limit + FETCH_BEYOND_LIMIT` documents from the server.
33
- * If we got that many documents, that means there may be even more. In that case, if our result set goes below
34
- * `limit + LIMIT_UNDERFLOW_TRIGGER` documents (due to local or remote deletions), we need to resend the query to the
35
- * server to potentially get more documents.
36
- * If the number of documents is less than `limit + FETCH_BEYOND_LIMIT`, that means there are not that many documents
37
- * on the server, so we don't need to resend the query regardless of how small our result size is or becomes.
38
- */
39
- limitUnderflowState: LimitUnderflowState;
40
- }
41
- export declare enum LimitUnderflowState {
42
- UNKNOWN = 0,
43
- DISABLED = 1,
44
- ENABLED = 2
45
- }
46
- export interface DocsAndAlias {
47
- docs: Array<SquidDocument>;
48
- alias: Alias;
49
- }
1
+ import { Alias, SquidDocument } from '../public-types';
2
+ /**
3
+ * Represents a collection of documents associated with a specific alias
4
+ * in a query, typically used in joined query results.
5
+ * @category Database
6
+ */
7
+ export interface DocsAndAlias {
8
+ /**
9
+ * An array of documents retrieved as part of the query.
10
+ */
11
+ docs: Array<SquidDocument>;
12
+ /**
13
+ * The alias associated with the documents in a joined query context.
14
+ */
15
+ alias: Alias;
16
+ }
@@ -0,0 +1,41 @@
1
+ import { Observable } from 'rxjs';
2
+ import { SerializedQuery } from '../../../internal-common/src/public-types/serialized-query.public-types';
3
+ import { Pagination, PaginationOptions } from './pagination';
4
+ /**
5
+ * Interface for emitting query results in a reactive manner,
6
+ * supporting both synchronous and asynchronous access.
7
+ * @category Database
8
+ */
9
+ export interface SnapshotEmitter<ReturnType> {
10
+ /**
11
+ * Returns a promise that resolves to the query results.
12
+ *
13
+ * @returns A promise that resolves to the query results.
14
+ */
15
+ snapshot(): Promise<Array<ReturnType>>;
16
+ /**
17
+ * Returns an observable that emits the query results and updates whenever the query results change unless
18
+ * `subscribe=false` is provided.
19
+ *
20
+ * Important: Make sure to unsubscribe from the observable when you are done with it.
21
+ *
22
+ * @param subscribe Whether to subscribe to changes to the query results. Defaults to `true`.
23
+ * @returns An observable for the query results.
24
+ */
25
+ snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
26
+ /**
27
+ * Returns the results of the query based on the data that is currently available on the client. This method is useful
28
+ * for synchronously accessing data that has already been fetched by another query. The method will return an empty
29
+ * array if data has not yet been populated.
30
+ *
31
+ * @returns An array of query results.
32
+ */
33
+ peek(): Array<ReturnType>;
34
+ /**
35
+ * Returns a pagination wrapper for this query.
36
+ * @param options The pagination options. Defaults to `{ subscribe: true, pageSize: 100 }`.
37
+ */
38
+ paginate(options?: Partial<PaginationOptions>): Pagination<ReturnType>;
39
+ /** Serializes the active query used by the emitter. */
40
+ serialize(): SerializedQuery;
41
+ }
@@ -0,0 +1,18 @@
1
+ import { DocumentData } from '../../internal-common/src/public-types/document.public-types';
2
+ import { QueryBuilder } from './query/query-builder.factory';
3
+ /**
4
+ * Result of the `visitQueryResults` function.
5
+ * @category Database
6
+ */
7
+ export interface VisitQueryResultsStats {
8
+ /** Count of documents visited. */
9
+ count: number;
10
+ /** Time in millis spent in the function. */
11
+ time: number;
12
+ }
13
+ /**
14
+ * Reads all objects from the query in a safe way (with pagination) and calls callback() on every object.
15
+ * The iteration is interrupted if error is thrown.
16
+ * @category Database
17
+ */
18
+ export declare function visitQueryResults<T extends DocumentData>(query: QueryBuilder<T>, callback: (t: T) => Promise<unknown>, pageSize?: number): Promise<VisitQueryResultsStats>;
@@ -0,0 +1,12 @@
1
+ import { Observable } from 'rxjs';
2
+ /**
3
+ * Interface defining the operations available for a queue manager.
4
+ * Allows producing and consuming messages from a queue.
5
+ * @category Queue
6
+ */
7
+ export interface QueueManager<T> {
8
+ /** Publish messages to the queue */
9
+ produce(messages: T[]): Promise<void>;
10
+ /** Consume messages from the queue */
11
+ consume(): Observable<T>;
12
+ }
@@ -1,32 +1 @@
1
- export declare class RateLimiter {
2
- private readonly capacity;
3
- private readonly seconds;
4
- private tokens;
5
- private lastRefillTimestamp;
6
- private readonly refillRatePerMs;
7
- /**
8
- * Creates a new rate limiter. It limits the number of requests using two parameters:
9
- * - capacity: the maximum number of tokens (actions) that can be stored at any given time
10
- * - seconds: the number of seconds it takes to refill the bucket to its maximum capacity
11
- *
12
- * We then can calculate the refillRatePerMs: the number of tokens (actions) that are added to the bucket every
13
- * millisecond
14
- *
15
- * Example:
16
- * Say we want to allow maximum 60 requests in a period of 5 seconds. We can create a rate limiter with:
17
- * - capacity: 60
18
- * - seconds: 5
19
- * And we will get refillRatePerMs: 60 / (5 * 1000) = 0.012
20
- *
21
- * To use:
22
- * const rateLimiter = new RateLimiter(60, 5);
23
- * await rateLimiter.consume();
24
- *
25
- * @param capacity
26
- * @param refillRatePerMs
27
- */
28
- constructor(capacity: number, seconds: number);
29
- consume(): Promise<void>;
30
- private attemptConsume;
31
- private refill;
32
- }
1
+ export {};