@squidcloud/client 1.0.166 → 1.0.168

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 (105) hide show
  1. package/dist/cjs/index.js +35 -16
  2. package/package.json +1 -1
  3. package/dist/internal-common/src/public-types/ai-assistant.public-types.d.ts +0 -25
  4. package/dist/internal-common/src/public-types/ai-chatbot.public-context.d.ts +0 -12
  5. package/dist/internal-common/src/public-types/ai-chatbot.public-types.d.ts +0 -31
  6. package/dist/internal-common/src/public-types/api-call.public-context.d.ts +0 -14
  7. package/dist/internal-common/src/public-types/application.public-types.d.ts +0 -149
  8. package/dist/internal-common/src/public-types/base-query-builder.public-types.d.ts +0 -147
  9. package/dist/internal-common/src/public-types/bundle-api.public-types.d.ts +0 -57
  10. package/dist/internal-common/src/public-types/bundle-data.public-types.d.ts +0 -8
  11. package/dist/internal-common/src/public-types/communication.public-types.d.ts +0 -12
  12. package/dist/internal-common/src/public-types/context.public-types.d.ts +0 -40
  13. package/dist/internal-common/src/public-types/distributed-lock.public-context.d.ts +0 -4
  14. package/dist/internal-common/src/public-types/document.public-types.d.ts +0 -32
  15. package/dist/internal-common/src/public-types/graphql.public-context.d.ts +0 -7
  16. package/dist/internal-common/src/public-types/graphql.public-types.d.ts +0 -9
  17. package/dist/internal-common/src/public-types/http-status.enum.d.ts +0 -50
  18. package/dist/internal-common/src/public-types/integration.public-types.d.ts +0 -61
  19. package/dist/internal-common/src/public-types/integrations/ai_chatbot.types.d.ts +0 -32
  20. package/dist/internal-common/src/public-types/integrations/api.types.d.ts +0 -81
  21. package/dist/internal-common/src/public-types/integrations/auth.types.d.ts +0 -54
  22. package/dist/internal-common/src/public-types/integrations/database.types.d.ts +0 -206
  23. package/dist/internal-common/src/public-types/integrations/observability.types.d.ts +0 -24
  24. package/dist/internal-common/src/public-types/integrations/queue-types.d.ts +0 -40
  25. package/dist/internal-common/src/public-types/integrations/schemas.d.ts +0 -70
  26. package/dist/internal-common/src/public-types/mutation.public-context.d.ts +0 -14
  27. package/dist/internal-common/src/public-types/mutation.public-types.d.ts +0 -53
  28. package/dist/internal-common/src/public-types/native-query.public-context.d.ts +0 -7
  29. package/dist/internal-common/src/public-types/native-query.public-types.d.ts +0 -16
  30. package/dist/internal-common/src/public-types/pagination.public-types.d.ts +0 -62
  31. package/dist/internal-common/src/public-types/query.public-context.d.ts +0 -137
  32. package/dist/internal-common/src/public-types/query.public-types.d.ts +0 -64
  33. package/dist/internal-common/src/public-types/regions.public-types.d.ts +0 -5
  34. package/dist/internal-common/src/public-types/schema.public-types.d.ts +0 -46
  35. package/dist/internal-common/src/public-types/secret.public-types.d.ts +0 -16
  36. package/dist/internal-common/src/public-types/serialized-query.public-types.d.ts +0 -24
  37. package/dist/internal-common/src/public-types/socket.public-types.d.ts +0 -5
  38. package/dist/internal-common/src/public-types/topic.public-context.d.ts +0 -10
  39. package/dist/internal-common/src/public-types/typescript.public-types.d.ts +0 -15
  40. package/dist/internal-common/src/public-utils/id-utils.d.ts +0 -6
  41. package/dist/internal-common/src/types/ai-assistant.types.d.ts +0 -1
  42. package/dist/internal-common/src/types/ai-chatbot.types.d.ts +0 -1
  43. package/dist/internal-common/src/types/api.types.d.ts +0 -2
  44. package/dist/internal-common/src/types/backend-function.types.d.ts +0 -1
  45. package/dist/internal-common/src/types/backend-run.types.d.ts +0 -2
  46. package/dist/internal-common/src/types/bundle-data.types.d.ts +0 -4
  47. package/dist/internal-common/src/types/communication.types.d.ts +0 -1
  48. package/dist/internal-common/src/types/document.types.d.ts +0 -1
  49. package/dist/internal-common/src/types/mutation.types.d.ts +0 -1
  50. package/dist/internal-common/src/types/openapi.types.d.ts +0 -1
  51. package/dist/internal-common/src/types/query.types.d.ts +0 -1
  52. package/dist/internal-common/src/types/secret.types.d.ts +0 -11
  53. package/dist/internal-common/src/types/socket.types.d.ts +0 -7
  54. package/dist/internal-common/src/utils/array.d.ts +0 -1
  55. package/dist/internal-common/src/utils/assert.d.ts +0 -1
  56. package/dist/internal-common/src/utils/global.utils.d.ts +0 -1
  57. package/dist/internal-common/src/utils/http.d.ts +0 -2
  58. package/dist/internal-common/src/utils/lock.manager.d.ts +0 -14
  59. package/dist/internal-common/src/utils/object.d.ts +0 -5
  60. package/dist/internal-common/src/utils/serialization.d.ts +0 -5
  61. package/dist/internal-common/src/utils/validation.d.ts +0 -27
  62. package/dist/internal-common/src/websocket.impl.d.ts +0 -21
  63. package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +0 -1239
  64. package/dist/typescript-client/src/ai-assistant-client.d.ts +0 -73
  65. package/dist/typescript-client/src/ai-chatbot-client.d.ts +0 -174
  66. package/dist/typescript-client/src/ai-chatbot-client.factory.d.ts +0 -8
  67. package/dist/typescript-client/src/ai.types.d.ts +0 -63
  68. package/dist/typescript-client/src/api.manager.d.ts +0 -11
  69. package/dist/typescript-client/src/auth.manager.d.ts +0 -27
  70. package/dist/typescript-client/src/backend-function.manager.d.ts +0 -9
  71. package/dist/typescript-client/src/backend-transforms.d.ts +0 -0
  72. package/dist/typescript-client/src/client-id.service.d.ts +0 -27
  73. package/dist/typescript-client/src/collection-reference.d.ts +0 -80
  74. package/dist/typescript-client/src/collection-reference.factory.d.ts +0 -13
  75. package/dist/typescript-client/src/connection-details.d.ts +0 -23
  76. package/dist/typescript-client/src/data.manager.d.ts +0 -175
  77. package/dist/typescript-client/src/destruct.manager.d.ts +0 -13
  78. package/dist/typescript-client/src/distributed-lock.manager.d.ts +0 -16
  79. package/dist/typescript-client/src/document-identity.service.d.ts +0 -12
  80. package/dist/typescript-client/src/document-reference.d.ts +0 -149
  81. package/dist/typescript-client/src/document-reference.factory.d.ts +0 -13
  82. package/dist/typescript-client/src/document-store.d.ts +0 -14
  83. package/dist/typescript-client/src/graphql-client.d.ts +0 -14
  84. package/dist/typescript-client/src/graphql-client.factory.d.ts +0 -11
  85. package/dist/typescript-client/src/index.d.ts +0 -11
  86. package/dist/typescript-client/src/mutation/mutation-sender.d.ts +0 -12
  87. package/dist/typescript-client/src/native-query-manager.d.ts +0 -7
  88. package/dist/typescript-client/src/public-types.d.ts +0 -37
  89. package/dist/typescript-client/src/public-utils.d.ts +0 -1
  90. package/dist/typescript-client/src/query/deserializer.d.ts +0 -3
  91. package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +0 -161
  92. package/dist/typescript-client/src/query/local-query-manager.d.ts +0 -9
  93. package/dist/typescript-client/src/query/query-builder.factory.d.ts +0 -77
  94. package/dist/typescript-client/src/query/query-sender.d.ts +0 -34
  95. package/dist/typescript-client/src/query/query-subscription.manager.d.ts +0 -133
  96. package/dist/typescript-client/src/query/query.types.d.ts +0 -49
  97. package/dist/typescript-client/src/queue.manager.d.ts +0 -7
  98. package/dist/typescript-client/src/rate-limiter.d.ts +0 -32
  99. package/dist/typescript-client/src/rpc.manager.d.ts +0 -30
  100. package/dist/typescript-client/src/secret.client.d.ts +0 -23
  101. package/dist/typescript-client/src/socket.manager.d.ts +0 -44
  102. package/dist/typescript-client/src/squid.d.ts +0 -245
  103. package/dist/typescript-client/src/state/state.service.spec.d.ts +0 -1
  104. package/dist/typescript-client/src/testing/setup-tests.d.ts +0 -1
  105. package/dist/typescript-client/src/types.d.ts +0 -2
@@ -1,161 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { DocumentReference } from '../document-reference';
3
- import { QueryBuilder } from './query-builder.factory';
4
- import { Alias, BaseQueryBuilder, DocumentData, FieldName, FieldSort, HasDereference, Operator, Pagination, PaginationOptions, PrimitiveFieldType, SerializedJoinQuery, SimpleCondition, SnapshotEmitter } from '../public-types';
5
- type WithDocumentReferences<T extends Record<any, DocumentData>> = {
6
- [k in keyof T]: DocumentReference<Required<T>[k]>;
7
- };
8
- type Grouped<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, any>, RootAlias extends Alias> = Aliases[RootAlias] extends [] ? Required<ReturnType>[RootAlias] : Record<RootAlias, Required<ReturnType>[RootAlias]> & OtherGroups<Aliases, ReturnType, Aliases[RootAlias]>;
9
- type OtherGroups<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, any>, ManyRootAliases extends Alias[]> = ManyRootAliases extends [infer First extends Alias, ...infer Rest extends Alias[]] ? Record<First, Array<Grouped<Aliases, ReturnType, First>>> & OtherGroups<Aliases, ReturnType, Rest> : Record<Alias, never>;
10
- interface HasGrouped {
11
- /**
12
- * Transforms this join query result to a nested data structure. For example, a join between teachers and students
13
- * normally returns a result of the form:
14
- * [
15
- * { teacher: {name: 'Mr. Smith'}, student: {name: 'John Doe'} },
16
- * { teacher: {name: 'Mr. Smith'}, student: {name: 'Jane Smith'} },
17
- * { teacher: {name: 'Mr. EmptyClass'}, student: undefined },
18
- * ]
19
- * into a result of the form:
20
- * [
21
- * { teacher: {name: 'Mr. Smith'}, students: [
22
- * { name: 'John Doe' },
23
- * { name: 'Jane Smith' },
24
- * ]},
25
- * { teacher: {name: 'Mr. EmptyClass'}, students: [] },
26
- * ]
27
- */
28
- grouped(): any;
29
- }
30
- /**
31
- * A query builder that can participate in a join.
32
- * To learn more about join queries, see the
33
- * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/queries#joining-data-across-collections-and-integrations documentation}.
34
- */
35
- export declare class JoinQueryBuilder<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, LatestAlias extends Alias, RootAlias extends Alias> extends BaseQueryBuilder<ReturnType> implements SnapshotEmitter<WithDocumentReferences<ReturnType>>, HasGrouped, HasDereference {
36
- private readonly collectionName;
37
- private readonly integrationId;
38
- private readonly querySubscriptionManager;
39
- private readonly documentReferenceFactory;
40
- private readonly queryBuilderFactory;
41
- private readonly latestAlias;
42
- private readonly joins;
43
- private readonly joinConditions;
44
- private readonly queryBuilder;
45
- /**
46
- * Adds a condition to the query.
47
- *
48
- * @param fieldName The name of the field to query
49
- * @param operator The operator to use
50
- * @param value The value to compare against
51
- * @returns The query builder
52
- */
53
- where(fieldName: (keyof ReturnType[LatestAlias] & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
54
- /**
55
- * Sets a limit to the number of results returned by the query. The maximum limit is 20,000 and the default is 1,000
56
- * if none is provided.
57
- *
58
- * @param limit The maximum number of results to return
59
- * @returns The query builder
60
- */
61
- limit(limit: number): this;
62
- getLimit(): number;
63
- /**
64
- * Adds a sort order to the query. You can add multiple sort orders to the query. The order in which you add them
65
- * determines the order in which they are applied.
66
- * @param fieldName The name of the field to sort by
67
- * @param asc Whether to sort in ascending order. Defaults to true.
68
- * @returns The query builder
69
- */
70
- sortBy(fieldName: keyof ReturnType[RootAlias] & FieldName, asc?: boolean): this;
71
- /**
72
- * Joins this query with another join query and return a new query builder that can be used to query the joined
73
- * documents.
74
- * @param queryBuilder The query builder to join with
75
- * @param alias TODO
76
- * @param joinFields TODO
77
- * @param options TODO
78
- * @returns A new query builder that can be used to query the joined documents
79
- */
80
- join<NewAlias extends string, NewReturnType extends DocumentData, LeftAlias extends Extract<keyof ReturnType, Alias>, IsInner extends boolean = false>(queryBuilder: QueryBuilder<NewReturnType>, alias: Exclude<NewAlias, keyof ReturnType>, joinFields: {
81
- left: keyof Required<ReturnType>[LeftAlias] & FieldName;
82
- right: keyof NewReturnType & FieldName;
83
- }, options: {
84
- leftAlias: LeftAlias;
85
- isInner?: IsInner;
86
- }): JoinQueryBuilder<Omit<Aliases, LeftAlias> & Record<LeftAlias, [...Aliases[LeftAlias], NewAlias]> & Record<NewAlias, []>, ReturnType & (IsInner extends true ? Record<NewAlias, NewReturnType> : Partial<Record<NewAlias, NewReturnType>>), NewAlias, RootAlias>;
87
- join<NewAlias extends string, NewReturnType extends DocumentData, IsInner extends boolean = false>(queryBuilder: QueryBuilder<NewReturnType>, alias: Exclude<NewAlias, keyof ReturnType>, joinFields: {
88
- left: keyof Required<ReturnType>[LatestAlias] & FieldName;
89
- right: keyof NewReturnType & FieldName;
90
- }, options?: {
91
- isInner?: IsInner;
92
- }): JoinQueryBuilder<Omit<Aliases, LatestAlias> & Record<LatestAlias, [...Aliases[LatestAlias], NewAlias]> & Record<NewAlias, []>, ReturnType & (IsInner extends true ? Record<NewAlias, NewReturnType> : Partial<Record<NewAlias, NewReturnType>>), NewAlias, RootAlias>;
93
- /** @inheritDoc */
94
- snapshot(): Promise<Array<WithDocumentReferences<ReturnType>>>;
95
- /** @inheritDoc */
96
- snapshots(subscribe?: boolean): Observable<Array<WithDocumentReferences<ReturnType>>>;
97
- /**
98
- * @inheritDoc
99
- */
100
- peek(): Array<WithDocumentReferences<ReturnType>>;
101
- /** @inheritDoc */
102
- grouped(): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
103
- /** @inheritDoc */
104
- dereference(): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
105
- getSortOrders(): Array<FieldSort<any>>;
106
- clone(): JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>;
107
- addCompositeCondition(conditions: Array<SimpleCondition>): JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>;
108
- flipSortOrder(): JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>;
109
- extractData(data: WithDocumentReferences<ReturnType>): Required<ReturnType>[RootAlias];
110
- serialize(): SerializedJoinQuery;
111
- paginate(options?: Partial<PaginationOptions>): Pagination<WithDocumentReferences<ReturnType>>;
112
- }
113
- declare class DereferencedJoin<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, RootAlias extends Alias, LatestAlias extends Alias> implements SnapshotEmitter<ReturnType>, HasGrouped {
114
- private readonly joinQueryBuilder;
115
- constructor(joinQueryBuilder: JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>);
116
- /** @inheritDoc */
117
- grouped(): SnapshotEmitter<Grouped<Aliases, ReturnType, RootAlias>>;
118
- /** @inheritDoc */
119
- snapshot(): Promise<Array<ReturnType>>;
120
- /** @inheritDoc */
121
- snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
122
- /**
123
- * @inheritDoc
124
- */
125
- peek(): Array<ReturnType>;
126
- getSortOrders(): Array<FieldSort<any>>;
127
- clone(): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
128
- addCompositeCondition(conditions: Array<SimpleCondition>): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
129
- flipSortOrder(): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
130
- limit(limit: number): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
131
- extractData(data: ReturnType): any;
132
- paginate(options?: Partial<PaginationOptions>): Pagination<ReturnType>;
133
- serialize(): SerializedJoinQuery;
134
- getLimit(): number;
135
- }
136
- declare class GroupedJoin<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, RootAlias extends Alias, LatestAlias extends Alias> implements SnapshotEmitter<Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>>, HasDereference {
137
- readonly joinQueryBuilder: JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>;
138
- /** internal */
139
- constructor(joinQueryBuilder: JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>);
140
- /** @inheritDoc */
141
- snapshot(): Promise<Array<Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>>>;
142
- /** @inheritDoc */
143
- snapshots(subscribe?: boolean): Observable<Array<Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>>>;
144
- /**
145
- * @inheritDoc
146
- */
147
- peek(): Array<Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>>;
148
- /** @inheritDoc */
149
- dereference(): SnapshotEmitter<Grouped<Aliases, ReturnType, RootAlias>>;
150
- private groupData;
151
- getSortOrders(): Array<FieldSort<any>>;
152
- clone(): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
153
- addCompositeCondition(conditions: Array<SimpleCondition>): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
154
- flipSortOrder(): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
155
- limit(limit: number): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
156
- getLimit(): number;
157
- extractData(data: Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>): any;
158
- serialize(): SerializedJoinQuery;
159
- paginate(options?: Partial<PaginationOptions>): Pagination<Grouped<Aliases, WithDocumentReferences<ReturnType>, RootAlias>>;
160
- }
161
- export {};
@@ -1,9 +0,0 @@
1
- import { DocumentReferenceFactory } from '../document-reference.factory';
2
- import { DocumentStore } from '../document-store';
3
- import { QuerySubscriptionManager } from './query-subscription.manager';
4
- export declare class LocalQueryManager {
5
- private readonly documentStore;
6
- private readonly documentReferenceFactory;
7
- private readonly querySubscriptionManager;
8
- constructor(documentStore: DocumentStore, documentReferenceFactory: DocumentReferenceFactory, querySubscriptionManager: QuerySubscriptionManager);
9
- }
@@ -1,77 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { DocumentReference } from '../document-reference';
3
- import { BaseQueryBuilder, DocumentData, FieldName, FieldSort, HasDereference, Operator, Pagination, PaginationOptions, PrimitiveFieldType, SerializedSimpleQuery, SimpleCondition, SnapshotEmitter } from '../public-types';
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,34 +0,0 @@
1
- import { RpcManager } from '../rpc.manager';
2
- import { BehaviorSubject } from 'rxjs';
3
- import { DestructManager } from '../destruct.manager';
4
- import { QueryRequest } from '../../../internal-common/src/types/query.types';
5
- import { QueryResultData } from '../../../internal-common/src/types/socket.types';
6
- export declare class QuerySender {
7
- private readonly rpcManager;
8
- private readonly destructManager;
9
- /**
10
- * A collection of query requests awaiting batch dispatch.
11
- */
12
- private readonly pendingQueryRequests;
13
- /**
14
- * A timeout identifier used to ensure that only the last query in rapid succession triggers the batch send process.
15
- */
16
- private pendingQueryBatchTimeout?;
17
- /**
18
- * As long as there are mutations in flight we do not want to send queries because it causes race conditions,
19
- * preventing parallel queries and mutations simplifies the mental model.
20
- */
21
- readonly safeToSendQueriesToServer: BehaviorSubject<boolean>;
22
- /**
23
- * The number of queries that are currently in-flight (about to be sent to the server or sent but did not get a
24
- * response yet). This is used by the data manager to prevent it from sending mutations while there are in-flight
25
- * queries.
26
- */
27
- private readonly inflightQueriesCount;
28
- constructor(rpcManager: RpcManager, destructManager: DestructManager);
29
- sendQuery(queryRequest: QueryRequest): Promise<QueryResultData>;
30
- private processQueryBatch;
31
- /** Will resolve once all the in-flight queries are done. */
32
- waitForAllQueriesToFinish(): Promise<void>;
33
- private preDestruct;
34
- }
@@ -1,133 +0,0 @@
1
- import { Observable, Subject } from 'rxjs';
2
- import { RpcManager } from '../rpc.manager';
3
- import { QuerySender } from './query-sender';
4
- import { OngoingQuery } from './query.types';
5
- import { Alias, ClientRequestId, JoinCondition, Query, SquidDocId, SquidDocument } from '../public-types';
6
- import { ClientIdService } from '../client-id.service';
7
- import { DocumentStore } from '../document-store';
8
- import { DestructManager } from '../destruct.manager';
9
- import DocumentIdentityService from '../document-identity.service';
10
- import { QueryResultData } from '../../../internal-common/src/types/socket.types';
11
- import { QuerySubscriptionId } from '../../../internal-common/src/types/query.types';
12
- export declare const FETCH_BEYOND_LIMIT = 100;
13
- export declare const LIMIT_UNDERFLOW_TRIGGER = 20;
14
- export declare class QuerySubscriptionManager {
15
- private readonly rpcManager;
16
- private readonly clientIdService;
17
- private readonly documentStore;
18
- private readonly destructManager;
19
- private readonly documentIdentityService;
20
- private readonly querySender;
21
- /**
22
- * An observable used by the data manager, the query subscription manager (this class) identifies when a document no
23
- * longer has queries that it is part of their result, such document is considered orphan. The data manager will mark
24
- * as orphan.
25
- */
26
- onOrphanDocuments: Subject<string[]>;
27
- /** All the currently running queries with their full state. */
28
- private readonly ongoingQueries;
29
- /**
30
- * The two maps below maintain the relation between document ids we know about locally to clientRequestIds (queries).
31
- * This relation is used for determining whether a document can be safely removed.
32
- */
33
- private readonly clientRequestIdToLocalDocuments;
34
- private readonly localDocumentToClientRequestIds;
35
- /**
36
- * A data structure for mapping queries to allow reverse queries search (given a document, find all the matching
37
- * queries)
38
- */
39
- private readonly queryMappingManager;
40
- private readonly queryResultsSubject;
41
- constructor(rpcManager: RpcManager, clientIdService: ClientIdService, documentStore: DocumentStore, destructManager: DestructManager, documentIdentityService: DocumentIdentityService, querySender: QuerySender);
42
- observeQueryResults(): Observable<QueryResultData>;
43
- /**
44
- * Returns true if the client knows about this clientRequestId. It may happen that it will return false in the case
45
- * that the client unsubscribed from a query but the server sent a mutation update for this clientRequestId.
46
- */
47
- hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
48
- /**
49
- * Returns the query associated with the given clientRequestId. Throws error if the clientRequestId is not known.
50
- */
51
- getQuery(clientRequestId: ClientRequestId): Query;
52
- /**
53
- * A query receives updates from three different sources:
54
- * 1 - An initial snapshot from the server or from a parent query
55
- * 2 - Incremental updates from the server (or from a parent query before the query is registered)
56
- * 3 - A new snapshot if the query is refreshed after connection has been lost.
57
- *
58
- * If an incremental update is received before the snapshot was received, we cannot process it for this query.
59
- * This boolean indicates whether the initial snapshot was received.
60
- */
61
- setGotInitialResult(clientRequestId: ClientRequestId): void;
62
- /** Given a document, returns all the queries that should be notified with the new document properties. */
63
- findQueriesForDocument(doc: SquidDocument, squidDocId: SquidDocId): Array<QuerySubscriptionId>;
64
- /**
65
- * Given the new document's properties, finds all the queries that should be notified with the new properties and
66
- * updates the internal mappings (squidDocId --> client request Ids and, clientRequestId --> squidDocIds).
67
- * Returns an array with all the previous and current client request ids (basically all the client request ids that
68
- * will need to be notified due to the change of properties).
69
- */
70
- setClientRequestIdsForLocalDoc(squidDocId: SquidDocId, properties: SquidDocument | undefined): Array<ClientRequestId>;
71
- /**
72
- * Due to an error when syncing a document, all the queries that are subscribed to this document should be notified
73
- * and error out.
74
- */
75
- errorOutAllQueries(squidDocId: SquidDocId, err: unknown): void;
76
- /** Notifies to all the given queries (identified by their clientRequestId) with the updated query result. */
77
- notifyAllSubscriptions(clientRequestIds: ClientRequestId[]): void;
78
- private isValidParent;
79
- /**
80
- * Given an ongoing query, search for candidate ongoing queries that can serve as a parent.
81
- * If there is a parent query, the result of that query can be used for serving the current query.
82
- * We will still register the current query on the server, but we do not need to run the query, apply security rules,
83
- * etc.
84
- */
85
- private findValidParentOfOngoingQuery;
86
- findValidParentOfQuery(query: Query): OngoingQuery | undefined;
87
- processQuery(query: Query, rootAlias: Alias, joins: Record<string, Query>, joinConditions: Record<Alias, JoinCondition>, subscribe: boolean, forceFetchFromServer: boolean): Observable<Array<Record<Alias, SquidDocument | undefined>>>;
88
- /**
89
- * Returns whether the given document ID has a query that has this document ID as a result.
90
- * A document without a query is considered "un-tracked".
91
- */
92
- hasOngoingQueryForDocId(squidDocId: string): boolean;
93
- /**
94
- * Removes a query from the mapping and updates the orphan documents as needed.
95
- */
96
- private removeClientRequestIdMapping;
97
- /** Register logic for cleaning up the query when it is unsubscribed. */
98
- private registerQueryFinalizer;
99
- /** Creates a graph of ongoing queries and returns the root of the graph. */
100
- private createOngoingQueryGraph;
101
- private collectAllObservables;
102
- private joinResults;
103
- private join;
104
- private getOngoingQueriesBfs;
105
- private updateOngoingQueryWithNewDataFromSupportingQuery;
106
- private allOngoingQueriesGotInitialResult;
107
- private completeAllSupportedQueries;
108
- private preDestruct;
109
- unsubscribe(): void;
110
- hasSubscription(clientRequestId: ClientRequestId): boolean;
111
- /** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
112
- private sendQueryToServerOrUseParentQuery;
113
- /**
114
- * Uses the parent query as the source of data for the given ongoing query until the ongoing query is registered on
115
- * the server. It prevents the parent query from being unsubscribed until the query is registered on the server and
116
- * the first snapshot is received from the parent query.
117
- * 1 - Prevents the parent query from being unsubscribed
118
- * 2 - Connects the results of the parent query to the result of the current ongoing query
119
- * 3 - Registers the query on the server
120
- */
121
- private useParentOngoingQuery;
122
- /**
123
- * Sends the /query request to the server. It:
124
- * 1 - Waits for when it is safe to send a query to the server (no in-flight mutations)
125
- * 2 - Increments the number of inflightQueriesCount to prevent parallel mutations
126
- * 3 - Handles errors
127
- * 4 - Marks the query as registered
128
- */
129
- private sendQueryToServer;
130
- /** naive way to refresh queries/subscriptions when we have a new client id */
131
- private refreshOngoingQueries;
132
- private migrateDocIds;
133
- }
@@ -1,49 +0,0 @@
1
- import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs';
2
- import { Alias, ClientRequestId, JoinCondition, Query, SquidDocument } from '../public-types';
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,7 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- export interface QueueManager {
3
- /** Publish messages to the queue */
4
- produce(messages: string[]): Promise<void>;
5
- /** Consume messages from the queue */
6
- consume(): Observable<string>;
7
- }
@@ -1,32 +0,0 @@
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,30 +0,0 @@
1
- import { AuthManager } from './auth.manager';
2
- import { ClientIdService } from './client-id.service';
3
- import { DestructManager } from './destruct.manager';
4
- import { BlobAndFilename } from './types';
5
- import { SupportedSquidRegion } from './public-types';
6
- export declare class RpcManager {
7
- private readonly region;
8
- private readonly appId;
9
- private readonly authManager;
10
- private readonly clientIdService;
11
- private readonly staticHeaders;
12
- private readonly onGoingRpcCounter;
13
- private readonly rateLimiters;
14
- constructor(region: SupportedSquidRegion, appId: string, destructManager: DestructManager, headers: Record<string, string> | undefined, authManager: AuthManager, clientIdService: ClientIdService);
15
- private getAuthHeaders;
16
- awaitAllSettled(): Promise<void>;
17
- setStaticHeader(key: string, value: string): void;
18
- deleteStaticHeader(key: string): void;
19
- getStaticHeaders(): Record<string, string>;
20
- post<T>(path: string, message: unknown, files?: Array<File | BlobAndFilename>, filesFieldName?: string): Promise<T>;
21
- private tryDeserializing;
22
- private getRateLimiterBucket;
23
- }
24
- export declare class RpcError extends Error {
25
- readonly statusCode: number;
26
- readonly statusText: string;
27
- readonly headers: Headers;
28
- readonly url: string;
29
- constructor(statusCode: number, statusText: string, headers: Headers, url: string, message?: string);
30
- }
@@ -1,23 +0,0 @@
1
- import { SetSecretRequestEntry } from '../../internal-common/src/types/secret.types';
2
- import { SecretEntry, SecretKey, SecretValue } from './public-types';
3
- import { RpcManager } from './rpc.manager';
4
- export declare class SecretClient {
5
- private readonly rpcManager;
6
- constructor(rpcManager: RpcManager);
7
- get(key: SecretKey): Promise<SecretEntry | undefined>;
8
- getAll(): Promise<Record<SecretKey, SecretEntry>>;
9
- upsert(key: SecretKey, value: SecretValue): Promise<SecretEntry>;
10
- upsertMany(entries: Array<SetSecretRequestEntry>): Promise<Array<SecretEntry>>;
11
- delete(key: SecretKey): Promise<void>;
12
- deleteMany(keys: Array<SecretKey>): Promise<void>;
13
- get apiKeys(): ApiKeysSecretClient;
14
- }
15
- declare class ApiKeysSecretClient {
16
- private readonly rpcManager;
17
- constructor(rpcManager: RpcManager);
18
- get(key: SecretKey): Promise<SecretEntry | undefined>;
19
- getAll(): Promise<Record<SecretKey, SecretEntry>>;
20
- upsert(key: SecretKey): Promise<SecretEntry>;
21
- delete(key: SecretKey): Promise<void>;
22
- }
23
- export {};
@@ -1,44 +0,0 @@
1
- import { SupportedSquidRegion } from './public-types';
2
- import { Observable } from 'rxjs';
3
- import { AuthManager } from './auth.manager';
4
- import { ClientIdService } from './client-id.service';
5
- import { DestructManager } from './destruct.manager';
6
- import { MessageFromClient, MessageToClient } from '../../internal-common/src/types/socket.types';
7
- export declare class SocketManager {
8
- private readonly clientIdService;
9
- private readonly region;
10
- private readonly appId;
11
- private readonly messageNotificationWrapper;
12
- private readonly destructManager;
13
- private readonly authManager;
14
- private readonly webSocketObserver;
15
- private readonly allMessagesObserver;
16
- private readonly connectionReady;
17
- private readonly seenMessageIds;
18
- private socket;
19
- private destructSubject;
20
- private lastTick;
21
- /**
22
- * On a client disconnecting, we wait for a bit to see if the client reconnects,
23
- * if no reconnect happens within the timeout, we consider the client to be too old.
24
- * This value means we wait for 5 minutes before considering the client to be too old.
25
- * Note: we make this a function so that we can easily override it in tests.
26
- */
27
- private clientTooOldThreshold;
28
- private tickInterval;
29
- constructor(clientIdService: ClientIdService, region: SupportedSquidRegion, appId: string, messageNotificationWrapper: (fn: () => any) => any, destructManager: DestructManager, authManager: AuthManager);
30
- refreshClient(): void;
31
- tick(): void;
32
- observeNotifications<T extends MessageToClient>(): Observable<T>;
33
- observeConnectionReady(): Observable<boolean>;
34
- sendMessage(message: MessageFromClient): void;
35
- private sendMessageAsync;
36
- /** Sends 'kill' message ignoring 'connectionReady' observable. */
37
- private sendKillMessage;
38
- private connect;
39
- disconnect(): void;
40
- private onConnectionReady;
41
- private onMessage;
42
- private setupMessageAcknowledgments;
43
- private destruct;
44
- }