@squidcloud/backend 1.0.8 → 1.0.9

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 (89) hide show
  1. package/dist/index.js +6 -10
  2. package/package.json +2 -2
  3. package/dist/backend/src/actions.d.ts +0 -13
  4. package/dist/backend/src/index.d.ts +0 -3
  5. package/dist/backend/src/metadata.d.ts +0 -234
  6. package/dist/backend/src/project.d.ts +0 -4
  7. package/dist/backend/src/service.d.ts +0 -18
  8. package/dist/common/src/api-call.context.d.ts +0 -17
  9. package/dist/common/src/api.types.d.ts +0 -10
  10. package/dist/common/src/application.schemas.d.ts +0 -608
  11. package/dist/common/src/application.types.d.ts +0 -197
  12. package/dist/common/src/backend-function.schemas.d.ts +0 -3
  13. package/dist/common/src/backend-function.types.d.ts +0 -7
  14. package/dist/common/src/backend-run.types.d.ts +0 -60
  15. package/dist/common/src/bundle-api.types.d.ts +0 -66
  16. package/dist/common/src/bundle-data.types.d.ts +0 -47
  17. package/dist/common/src/communication.types.d.ts +0 -4
  18. package/dist/common/src/context.types.d.ts +0 -21
  19. package/dist/common/src/document.types.d.ts +0 -35
  20. package/dist/common/src/executable.context.d.ts +0 -4
  21. package/dist/common/src/graphql.context.d.ts +0 -14
  22. package/dist/common/src/graphql.types.d.ts +0 -8
  23. package/dist/common/src/http-status.enum.d.ts +0 -50
  24. package/dist/common/src/index.d.ts +0 -50
  25. package/dist/common/src/integration.types.d.ts +0 -249
  26. package/dist/common/src/logger.types.d.ts +0 -22
  27. package/dist/common/src/metrics.schemas.d.ts +0 -3
  28. package/dist/common/src/metrics.types.d.ts +0 -65
  29. package/dist/common/src/mutation.context.d.ts +0 -11
  30. package/dist/common/src/mutation.schemas.d.ts +0 -5
  31. package/dist/common/src/mutation.types.d.ts +0 -72
  32. package/dist/common/src/named-query.context.d.ts +0 -4
  33. package/dist/common/src/named-query.schemas.d.ts +0 -3
  34. package/dist/common/src/named-query.types.d.ts +0 -9
  35. package/dist/common/src/query/index.d.ts +0 -2
  36. package/dist/common/src/query/query-context.d.ts +0 -38
  37. package/dist/common/src/query/simple-query-builder.d.ts +0 -14
  38. package/dist/common/src/query.schemas.d.ts +0 -5
  39. package/dist/common/src/query.types.d.ts +0 -118
  40. package/dist/common/src/regions.d.ts +0 -17
  41. package/dist/common/src/schema/schema.types.d.ts +0 -54
  42. package/dist/common/src/secret.schemas.d.ts +0 -6
  43. package/dist/common/src/secret.types.d.ts +0 -38
  44. package/dist/common/src/socket.schemas.d.ts +0 -3
  45. package/dist/common/src/socket.types.d.ts +0 -68
  46. package/dist/common/src/time-units.d.ts +0 -5
  47. package/dist/common/src/trigger.types.d.ts +0 -15
  48. package/dist/common/src/types.d.ts +0 -15
  49. package/dist/common/src/utils/array.d.ts +0 -8
  50. package/dist/common/src/utils/assert.d.ts +0 -8
  51. package/dist/common/src/utils/error.d.ts +0 -4
  52. package/dist/common/src/utils/id.d.ts +0 -1
  53. package/dist/common/src/utils/lock.manager.d.ts +0 -14
  54. package/dist/common/src/utils/nullish.d.ts +0 -1
  55. package/dist/common/src/utils/object.d.ts +0 -6
  56. package/dist/common/src/utils/serialization.d.ts +0 -6
  57. package/dist/common/src/utils/transforms.d.ts +0 -18
  58. package/dist/common/src/utils/url.d.ts +0 -1
  59. package/dist/common/src/utils/validation.d.ts +0 -30
  60. package/dist/common/src/webhook-response.d.ts +0 -7
  61. package/dist/index.js.LICENSE.txt +0 -38
  62. package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +0 -1239
  63. package/dist/typescript-client/src/api.manager.d.ts +0 -14
  64. package/dist/typescript-client/src/backend-function.manager.d.ts +0 -13
  65. package/dist/typescript-client/src/collection-reference.d.ts +0 -19
  66. package/dist/typescript-client/src/collection-reference.factory.d.ts +0 -16
  67. package/dist/typescript-client/src/data.manager.d.ts +0 -164
  68. package/dist/typescript-client/src/destruct.manager.d.ts +0 -9
  69. package/dist/typescript-client/src/document-identity.service.d.ts +0 -12
  70. package/dist/typescript-client/src/document-reference.d.ts +0 -23
  71. package/dist/typescript-client/src/document-reference.factory.d.ts +0 -9
  72. package/dist/typescript-client/src/document-store.d.ts +0 -11
  73. package/dist/typescript-client/src/graphql-client.d.ts +0 -9
  74. package/dist/typescript-client/src/graphql-client.factory.d.ts +0 -9
  75. package/dist/typescript-client/src/index.d.ts +0 -7
  76. package/dist/typescript-client/src/mutation/mutation-sender.d.ts +0 -11
  77. package/dist/typescript-client/src/named-query.manager.d.ts +0 -13
  78. package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +0 -35
  79. package/dist/typescript-client/src/query/query-builder.factory.d.ts +0 -37
  80. package/dist/typescript-client/src/query/query-subscription.manager.d.ts +0 -59
  81. package/dist/typescript-client/src/query/query.types.d.ts +0 -7
  82. package/dist/typescript-client/src/rpc.manager.d.ts +0 -24
  83. package/dist/typescript-client/src/socket.manager.d.ts +0 -27
  84. package/dist/typescript-client/src/squid.d.ts +0 -51
  85. package/dist/typescript-client/src/state/action.applier.d.ts +0 -7
  86. package/dist/typescript-client/src/state/actions.d.ts +0 -29
  87. package/dist/typescript-client/src/state/path_trie.d.ts +0 -27
  88. package/dist/typescript-client/src/state/state.service.d.ts +0 -22
  89. package/dist/typescript-client/src/types.d.ts +0 -2
@@ -1,14 +0,0 @@
1
- import { ApiEndpointId, ClientId, IntegrationId } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import { RpcManager } from './rpc.manager';
4
- import { SocketManager } from './socket.manager';
5
- export declare class ApiManager {
6
- private readonly clientId;
7
- private readonly rpcManager;
8
- private readonly socketManager;
9
- private readonly apiServerUrlOverrideMapping;
10
- private readonly ongoingApiExecutions;
11
- constructor(clientId: ClientId, rpcManager: RpcManager, socketManager: SocketManager, apiServerUrlOverrideMapping?: Record<IntegrationId, string>);
12
- callApiAndSubscribe<T>(integrationId: IntegrationId, endpointId: ApiEndpointId, request: Record<string, any>): Observable<T>;
13
- private handleApiResponse;
14
- }
@@ -1,13 +0,0 @@
1
- import { ClientId } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import { RpcManager } from './rpc.manager';
4
- import { SocketManager } from './socket.manager';
5
- export declare class BackendFunctionManager {
6
- private readonly clientId;
7
- private readonly rpcManager;
8
- private readonly socketManager;
9
- private readonly ongoingFunctionExecutions;
10
- constructor(clientId: ClientId, rpcManager: RpcManager, socketManager: SocketManager);
11
- executeFunctionAndSubscribe<T>(functionName: string, ...params: any[]): Observable<T>;
12
- private handleFunctionResponse;
13
- }
@@ -1,19 +0,0 @@
1
- import { DocId, DocIdObj, DocumentData, IdResolutionMap, IntegrationId } from '@squidcloud/common';
2
- import { DocumentReference } from './document-reference';
3
- import { DocumentReferenceFactory } from './document-reference.factory';
4
- import { JoinQueryBuilder, JoinQueryBuilderFactory } from './query/join-query-builder.factory';
5
- import { QueryBuilder, QueryBuilderFactory } from './query/query-builder.factory';
6
- import { Alias } from './query/query.types';
7
- export declare class CollectionReference<T extends DocumentData> {
8
- private readonly collectionName;
9
- private integrationId;
10
- private readonly documentReferenceFactory;
11
- private readonly queryBuilderFactory;
12
- private readonly joinQueryBuilderFactory;
13
- private readonly documents;
14
- constructor(collectionName: string, integrationId: IntegrationId, documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, joinQueryBuilderFactory: JoinQueryBuilderFactory);
15
- doc(docId?: DocId | DocIdObj): DocumentReference<T>;
16
- query(): QueryBuilder<T>;
17
- joinQuery<A extends Alias>(alias: A): JoinQueryBuilder<T, A, Record<A, DocumentReference<T>>>;
18
- migrateDocIds(idResolutionMap: IdResolutionMap): void;
19
- }
@@ -1,16 +0,0 @@
1
- import { CollectionName, DocumentData, IntegrationId } from '@squidcloud/common';
2
- import { CollectionReference } from './collection-reference';
3
- import DocumentIdentityService from './document-identity.service';
4
- import { DocumentReferenceFactory } from './document-reference.factory';
5
- import { JoinQueryBuilderFactory } from './query/join-query-builder.factory';
6
- import { QueryBuilderFactory } from './query/query-builder.factory';
7
- export declare class CollectionReferenceFactory {
8
- private readonly documentReferenceFactory;
9
- private readonly queryBuilderFactory;
10
- private readonly joinQueryBuilderFactory;
11
- private readonly documentIdentityService;
12
- private readonly collections;
13
- constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, joinQueryBuilderFactory: JoinQueryBuilderFactory, documentIdentityService: DocumentIdentityService);
14
- get<T extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): CollectionReference<T>;
15
- private migrateDocIds;
16
- }
@@ -1,164 +0,0 @@
1
- import { DocTimestamp, LockManager, Mutation, SquidDocId, SquidDocument } from '@squidcloud/common';
2
- import { DestructManager } from './destruct.manager';
3
- import DocumentIdentityService from './document-identity.service';
4
- import { DocumentStore } from './document-store';
5
- import { MutationSender } from './mutation/mutation-sender';
6
- import { QueryBuilderFactory } from './query/query-builder.factory';
7
- import { QuerySubscriptionManager } from './query/query-subscription.manager';
8
- import { SocketManagerInterface } from './socket.manager';
9
- import { TransactionId } from './types';
10
- export interface DocTimestampMetadata {
11
- timestamp: DocTimestamp;
12
- expireTimestamp?: number;
13
- }
14
- export declare class DataManager {
15
- private readonly documentStore;
16
- private readonly mutationSender;
17
- private readonly socketManager;
18
- private readonly querySubscriptionManager;
19
- private readonly queryBuilderFactory;
20
- private readonly lockManager;
21
- private readonly destructManager;
22
- private readonly documentIdentityService;
23
- private readonly docIdToLocalTimestamp;
24
- private currentTransactionId;
25
- /**
26
- * During a batch, any update to a document that may trigger an update to a query is collected here and once the batch
27
- * ends, the relevant subscribes to these queries will be updated.
28
- */
29
- private readonly batchClientRequestIds;
30
- /**
31
- * In this map we save timestamps for documents that are available locally or recently deleted but need to remain
32
- * here so if a mutation comes from the server we know whether to apply it or not based on the timestamp. For
33
- * example, if a document is removed locally and immediately after, an update is received from the server - In that
34
- * case, it may be the update pre-dates the data that was available locally a second ago. For that reason, the
35
- * timestamp needs to be kept and even for removed documents it will be kept for ~20 seconds more.
36
- *
37
- * Eventually, this map is used as a gatekeeper for preventing old versions of a document (based on timestamp) to
38
- * appear on the client.
39
- */
40
- private readonly docIdToServerTimestamp;
41
- /**
42
- * In the case of a local change (outgoing change) without a server timestamp, an incoming server update cannot be
43
- * applied and needs to be queued until the local state allows it. In this case the incoming update will be queued in
44
- * this map. Any future incoming server update to the same document will override the previous update in case it has
45
- * a later timestamp.
46
- */
47
- private readonly pendingIncomingUpdates;
48
- /**
49
- * A mutation sent to the server will be stored in this map until it receives a timestamp from the server. These
50
- * mutations were already applied locally and were sent to the server or about to be sent if sentToServer=false
51
- * (or are queued in the MutationSender due to a lock). The existence of these pending mutations indicates the data
52
- * manager to:
53
- * 1 - Not apply any incoming server mutation while there are outgoing mutations without a timestamp
54
- * 2 - Not delete the local document even if there are no queries related to this document - there is a chance
55
- * that there will be a future query that will need this document and the query needs to return the local version
56
- * of the document.
57
- * 3 - Even when all outgoing mutations have a timestamp, it may be that there is a pending query in flight that will
58
- * need to return the document. In this case, the local document may be different from the server. Hence, it
59
- * cannot accept the server change and will wait for another update from the server. For this purpose, timestamp
60
- * will be stored in docsToTimestamp for ~20 more seconds.
61
- *
62
- * Note: Only one entry per squidDocId can be with sentToServer=false. This is true since all updates to the same doc
63
- * in the same batch are appended (and reduced) to the same outgoing mutation object.
64
- */
65
- private readonly pendingOutgoingMutations;
66
- /**
67
- * A subject for whether there are outgoing mutations. If there are outgoing mutations, any incoming update from the
68
- * server will be delayed until all the outgoing mutations will be acknowledged by the server.
69
- * This mechanism is needed to avoid this case:
70
- *
71
- * collection.docRef('a').delete();
72
- * collection.snapshots().subscribe((res) => {
73
- * // The result here may include doc with id='a' since the delete mutation was not acknowledged.
74
- * });
75
- *
76
- * If we wait for the acknowledgment message, we will have a server timestamp and will be able to ignore the incoming
77
- * result for document with id='a'.
78
- */
79
- private readonly outgoingMutationsEmpty;
80
- private readonly failedDocsToResync;
81
- private readonly refreshDocIdToTimestamp;
82
- private deleteExpiredTimestampsInterval;
83
- private handleIncomingMessagesForTests;
84
- constructor(documentStore: DocumentStore, mutationSender: MutationSender, socketManager: SocketManagerInterface, querySubscriptionManager: QuerySubscriptionManager, queryBuilderFactory: QueryBuilderFactory, lockManager: LockManager, destructManager: DestructManager, documentIdentityService: DocumentIdentityService);
85
- getProperties(squidDocId: SquidDocId): SquidDocument | undefined;
86
- /** Whether a document has changes that are out of sync with the server. */
87
- isDirty(squidDocId: SquidDocId): boolean;
88
- /**
89
- * Runs the provided function without sending mutations to the server while collecting the updates to the different
90
- * queries. Local updates will still be applied. Once the batch finishes, all the updates will be sent to the server
91
- * and the different queries will be notified. runInTransaction may be invoked inside another runInTransaction, only
92
- * the top level batch will trigger updates to the server.
93
- */
94
- runInTransaction(fn: (transactionId: TransactionId) => Promise<void>, transactionId?: TransactionId): Promise<void>;
95
- /** Applies a mutation done from the client (from DocumentReference) and sends it to the server. */
96
- applyOutgoingMutation(mutation: Mutation, transactionId: TransactionId | undefined): Promise<void>;
97
- /** Same as runInTransaction with the exception that the passed function runs synchronously. */
98
- private runInTransactionSync;
99
- /** Remove properties from the document record that should not be sent to the server. */
100
- private removeInternalProperties;
101
- /** Listens and handles mutations and snapshots notifications from the socketManager. */
102
- private handleNotifications;
103
- private handleIncomingMutations;
104
- private handleIncomingQuerySnapshots;
105
- /**
106
- * Returns a boolean for whether some updates were ignored because the client knows of a later timestamp for those
107
- * documents.
108
- */
109
- private applyIncomingUpdates;
110
- private addPendingIncomingUpdate;
111
- private maybeApplyIncomingUpdate;
112
- private destruct;
113
- private stopDeleteExpiredTimestampsJob;
114
- /**
115
- * Removes entries from the docToTimestamp map for all the documents that are no longer relevant for this client.
116
- * If a document is currently tracked, we forget it.
117
- * Cases a document is considered not relevant anymore:
118
- * 1 - There are no outgoing or incoming updates for this document AND:
119
- * a - The document was deleted on the server and this client already received a notification about it OR
120
- * b - The document no longer has a query that will keep it up-to-date
121
- */
122
- private startDeleteExpiredTimestampsJob;
123
- /**
124
- * Whether the document is tracked by any pending mutations or ongoing queries.
125
- */
126
- isTracked(squidDocId: string): boolean;
127
- /**
128
- * Whether a document exists locally, but is no longer tracked by any mutations or queries. This is often the case
129
- * for in-memory DocumentReferences that are not part of any query.
130
- */
131
- isForgotten(squidDocId: SquidDocId): boolean;
132
- /**
133
- * Whether a document only exists locally. This means that the document has never by sent to or received from the
134
- * server.
135
- */
136
- isLocalOnly(squidDocId: SquidDocId): boolean;
137
- /**
138
- * Whether the document has even been acknowledged by the server. Acknowledgements occur when an incoming query or
139
- * mutation is received, and when an outgoing mutation is acknowledged.
140
- */
141
- hasBeenAcknowledged(squidDocId: SquidDocId): boolean;
142
- /**
143
- * Updates the document with the new properties, returns true if an update was done or false in case the doc did not
144
- * change.
145
- */
146
- private updateDocumentFromSnapshot;
147
- private finishTransaction;
148
- private sendAllUnsentOutgoingMutations;
149
- private sendMutationsForIntegration;
150
- private removeOutgoingMutation;
151
- private resyncFailedUpdates;
152
- private refreshUpdatedDocuments;
153
- private groupOutgoingMutationsByIntegrationId;
154
- /**
155
- * Handles the case that due to some change (an incoming or outgoing change to a document), a document becomes orphan.
156
- * That is, there are no ongoing queries that will keep it up-to-date.
157
- * An orphan document should not stay locally since it may be stale after some time.
158
- */
159
- private handleOrphanDocs;
160
- private acknowledgeDocument;
161
- private setExpiration;
162
- private forgetDocument;
163
- private migrateDocIds;
164
- }
@@ -1,9 +0,0 @@
1
- export type DestructorFn = () => Promise<void> | void;
2
- export declare class DestructManager {
3
- private readonly predestructors;
4
- private readonly destructors;
5
- private isDestructed;
6
- onPreDestruct(fn: DestructorFn): void;
7
- onDestruct(fn: DestructorFn): void;
8
- destruct(): Promise<void>;
9
- }
@@ -1,12 +0,0 @@
1
- import { IdResolutionMap } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import { DestructManager } from './destruct.manager';
4
- import { DocumentStore } from './document-store';
5
- export default class DocumentIdentityService {
6
- private readonly documentStore;
7
- private readonly destructManager;
8
- private readonly changeNotifier;
9
- constructor(documentStore: DocumentStore, destructManager: DestructManager);
10
- migrate(idResolutionMap: IdResolutionMap): void;
11
- observeChanges(): Observable<IdResolutionMap>;
12
- }
@@ -1,23 +0,0 @@
1
- import { DocumentData, IdResolutionMap, Paths, SquidDocId } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import { DataManager } from './data.manager';
4
- import { QueryBuilderFactory } from './query/query-builder.factory';
5
- import { TransactionId } from './types';
6
- export declare class DocumentReference<T extends DocumentData = any> {
7
- private _squidDocId;
8
- private readonly dataManager;
9
- private readonly queryBuilderFactory;
10
- constructor(_squidDocId: SquidDocId, dataManager: DataManager, queryBuilderFactory: QueryBuilderFactory);
11
- get squidDocId(): SquidDocId;
12
- data(): T;
13
- snapshot(): Promise<DocumentReference<T> | undefined>;
14
- snapshots(): Observable<DocumentReference<T> | undefined>;
15
- isDirty(): boolean;
16
- private isTracked;
17
- update(data: Partial<Record<Paths<T>, any>>, transactionId?: TransactionId): Promise<void>;
18
- setInPath(path: Paths<T>, value: any, transactionId?: TransactionId): Promise<void>;
19
- deleteInPath(path: Paths<T>, transactionId?: TransactionId): Promise<void>;
20
- insert(data: T, transactionId?: TransactionId): Promise<void>;
21
- delete(transactionId?: TransactionId): Promise<void>;
22
- migrateDocIds(idResolutionMap: IdResolutionMap): void;
23
- }
@@ -1,9 +0,0 @@
1
- import { SquidDocId } from '@squidcloud/common';
2
- import { DataManager } from './data.manager';
3
- import { DocumentReference } from './document-reference';
4
- import { QueryBuilderFactory } from './query/query-builder.factory';
5
- export declare class DocumentReferenceFactory {
6
- private dataManager;
7
- create(squidDocId: SquidDocId, queryBuilderFactory: QueryBuilderFactory): DocumentReference;
8
- setDataManager(dataManager: DataManager): void;
9
- }
@@ -1,11 +0,0 @@
1
- import { Query, SquidDocId, SquidDocument } from '@squidcloud/common';
2
- export declare class DocumentStore {
3
- private readonly squidDocIdToDoc;
4
- saveDocument(squidDocId: SquidDocId, properties: SquidDocument | undefined): SquidDocument | undefined;
5
- hasData(squidDocId: SquidDocId): boolean;
6
- getDocument(squidDocId: SquidDocId): SquidDocument;
7
- getDocumentOrUndefined(squidDocId: SquidDocId): SquidDocument | undefined;
8
- sortAndLimitDocs(docIdSet: Set<SquidDocId> | undefined, query: Query): Array<SquidDocument>;
9
- private removeInternalProperties;
10
- migrateDocId(squidDocId: SquidDocId, newSquidDocId: SquidDocId): void;
11
- }
@@ -1,9 +0,0 @@
1
- import { GraphQLRequest, IntegrationId } from '@squidcloud/common';
2
- import { RpcManager } from './rpc.manager';
3
- export declare class GraphQLClient {
4
- private readonly rpcManager;
5
- private readonly client;
6
- constructor(rpcManager: RpcManager, integrationId: IntegrationId);
7
- query<T = any>(request: GraphQLRequest): Promise<T>;
8
- mutate<T = Record<string, any>>(request: GraphQLRequest): Promise<T | null | undefined>;
9
- }
@@ -1,9 +0,0 @@
1
- import { IntegrationId } from '@squidcloud/common';
2
- import { GraphQLClient } from './graphql-client';
3
- import { RpcManager } from './rpc.manager';
4
- export declare class GraphQLClientFactory {
5
- private readonly rpcManager;
6
- private readonly clientsMap;
7
- constructor(rpcManager: RpcManager);
8
- get(integrationId: IntegrationId): GraphQLClient;
9
- }
@@ -1,7 +0,0 @@
1
- export { CollectionReference } from './collection-reference';
2
- export { DocumentReference } from './document-reference';
3
- export { JoinQueryBuilder } from './query/join-query-builder.factory';
4
- export { Changes, QueryBuilder } from './query/query-builder.factory';
5
- export { Alias, JoinCondition } from './query/query.types';
6
- export { Squid, SquidOptions } from './squid';
7
- export { TransactionId } from './types';
@@ -1,11 +0,0 @@
1
- import { ClientId, IntegrationId, LockManager, MutateResponse, Mutation } from '@squidcloud/common';
2
- import { QuerySubscriptionManager } from '../query/query-subscription.manager';
3
- import { RpcManager } from '../rpc.manager';
4
- export declare class MutationSender {
5
- private readonly clientId;
6
- private readonly rpcManager;
7
- private readonly lockManager;
8
- private readonly querySubscriptionManager;
9
- constructor(clientId: ClientId, rpcManager: RpcManager, lockManager: LockManager, querySubscriptionManager: QuerySubscriptionManager);
10
- sendMutations(mutations: Array<Mutation>, integrationId: IntegrationId): Promise<MutateResponse>;
11
- }
@@ -1,13 +0,0 @@
1
- import { ClientId, IntegrationId, QueryName } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import { RpcManager } from './rpc.manager';
4
- import { SocketManager } from './socket.manager';
5
- export declare class NamedQueryManager {
6
- private readonly clientId;
7
- private readonly rpcManager;
8
- private readonly socketManager;
9
- private readonly ongoingNamedQueryExecutions;
10
- constructor(clientId: ClientId, rpcManager: RpcManager, socketManager: SocketManager);
11
- executeNamedQueryAndSubscribe<T>(integrationId: IntegrationId, queryName: QueryName, params: Record<string, any>): Observable<T>;
12
- private handleNamedQueryResponse;
13
- }
@@ -1,35 +0,0 @@
1
- import { CollectionName, DocumentData, FieldName, IntegrationId, Operator, PrimitiveFieldType, Query } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import { DocumentReference } from '../document-reference';
4
- import { DocumentReferenceFactory } from '../document-reference.factory';
5
- import { QueryBuilderFactory } from './query-builder.factory';
6
- import { QuerySubscriptionManager } from './query-subscription.manager';
7
- import { Alias } from './query.types';
8
- export declare class JoinQueryBuilderFactory {
9
- private readonly querySubscriptionManager;
10
- private readonly documentReferenceFactory;
11
- private readonly queryBuilderFactory;
12
- constructor(querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory);
13
- getForJoin<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType>>>(collectionName: CollectionName, integrationId: IntegrationId, alias: MyAlias): JoinQueryBuilder<DocumentType, MyAlias, ReturnType>;
14
- }
15
- export declare class JoinQueryBuilder<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType> | undefined>> {
16
- private readonly collectionName;
17
- private readonly integrationId;
18
- private readonly querySubscriptionManager;
19
- private readonly documentReferenceFactory;
20
- private readonly alias;
21
- private readonly joinQueryBuilderFactory;
22
- private readonly queryBuilderFactory;
23
- private readonly simpleQueryBuilder;
24
- private readonly joins;
25
- /** Record that maps the right alias to the left condition */
26
- private readonly joinConditions;
27
- constructor(collectionName: CollectionName, integrationId: IntegrationId, querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, alias: MyAlias, joinQueryBuilderFactory: JoinQueryBuilderFactory, queryBuilderFactory: QueryBuilderFactory);
28
- where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
29
- limit(limit: number): this;
30
- sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
31
- join<J extends DocumentData, RightAlias extends Alias, RightReturnType extends Record<RightAlias, DocumentReference<J> | undefined>>(queryBuilder: JoinQueryBuilder<J, RightAlias, RightReturnType>, leftFieldName: keyof DocumentType & FieldName, rightFieldName: keyof J & FieldName): JoinQueryBuilder<DocumentType, MyAlias, ReturnType & Partial<RightReturnType>>;
32
- snapshot(): Promise<Array<ReturnType>>;
33
- snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
34
- build(): Query;
35
- }
@@ -1,37 +0,0 @@
1
- import { CollectionName, DocumentData, FieldName, IntegrationId, Operator, PrimitiveFieldType, Query, SquidDocId } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import DocumentIdentityService from '../document-identity.service';
4
- import { DocumentReference } from '../document-reference';
5
- import { DocumentReferenceFactory } from '../document-reference.factory';
6
- import { QuerySubscriptionManager } from './query-subscription.manager';
7
- export declare class QueryBuilderFactory {
8
- private readonly querySubscriptionManager;
9
- private readonly documentReferenceFactory;
10
- private readonly documentIdentityService;
11
- constructor(querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, documentIdentityService: DocumentIdentityService);
12
- getForDocument<DocumentType extends DocumentData>(squidDocId: SquidDocId): QueryBuilder<DocumentType>;
13
- get<DocumentType extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): QueryBuilder<DocumentType>;
14
- }
15
- export declare class QueryBuilder<DocumentType extends DocumentData> {
16
- private readonly collectionName;
17
- private readonly integrationId;
18
- private readonly querySubscriptionManager;
19
- private readonly documentReferenceFactory;
20
- private readonly queryBuilderFactory;
21
- private readonly documentIdentityService;
22
- private readonly simpleQueryBuilder;
23
- constructor(collectionName: CollectionName, integrationId: IntegrationId, querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, documentIdentityService: DocumentIdentityService);
24
- where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
25
- limit(limit: number): this;
26
- sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
27
- snapshot(): Promise<Array<DocumentReference<DocumentType>>>;
28
- snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
29
- changes(): Observable<Changes<DocumentType>>;
30
- build(): Query;
31
- get hash(): string;
32
- }
33
- export interface Changes<DocumentType extends DocumentData> {
34
- inserts: Array<DocumentReference<DocumentType>>;
35
- updates: Array<DocumentReference<DocumentType>>;
36
- deletes: Array<DocumentType>;
37
- }
@@ -1,59 +0,0 @@
1
- import { ClientId, ClientRequestId, Query, QuerySubscriptionId, SquidDocId, SquidDocument } from '@squidcloud/common';
2
- import { BehaviorSubject, Observable, Subject } from 'rxjs';
3
- import { DestructManager } from '../destruct.manager';
4
- import DocumentIdentityService from '../document-identity.service';
5
- import { DocumentStore } from '../document-store';
6
- import { RpcManager } from '../rpc.manager';
7
- import { Alias, JoinCondition } from './query.types';
8
- export declare class QuerySubscriptionManager {
9
- private readonly rpcManager;
10
- private readonly clientId;
11
- private readonly documentStore;
12
- private readonly destructManager;
13
- private readonly documentIdentityService;
14
- readonly safeToSendQueriesToServer: BehaviorSubject<boolean>;
15
- onOrphanDocuments: Subject<string[]>;
16
- private readonly ongoingQueries;
17
- private readonly inflightQueriesCount;
18
- /**
19
- * The two maps below maintain the relation between document ids we know about locally to clientRequestIds (queries).
20
- * This relation is used for determining whether a document can be safely removed.
21
- */
22
- private readonly clientRequestIdToLocalDocuments;
23
- private readonly localDocumentToClientRequestIds;
24
- private readonly queryMappingManager;
25
- constructor(rpcManager: RpcManager, clientId: ClientId, documentStore: DocumentStore, destructManager: DestructManager, documentIdentityService: DocumentIdentityService);
26
- hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
27
- getQuery(clientRequestId: ClientRequestId): Query;
28
- setGotResponseFromServer(clientRequestId: ClientRequestId): void;
29
- findQueriesForDocument(doc: SquidDocument, squidDocId: SquidDocId): Array<QuerySubscriptionId>;
30
- /**
31
- * Given the new document's properties, finds all the queries that should be notified with the new properties and
32
- * updates the internal mappings (squidDocId --> client request Ids and, clientRequestId --> squidDocIds).
33
- * Returns an array with all the previous and current client request ids (basically all the client request ids that
34
- * will need to be notified due to the change of properties).
35
- */
36
- setClientRequestIdsForLocalDoc(squidDocId: SquidDocId, properties: SquidDocument | undefined): Array<ClientRequestId>;
37
- errorOutAllQueries(squidDocId: SquidDocId, err: any): void;
38
- notifyAllSubscriptions(clientRequestIds: ClientRequestId[]): void;
39
- processQuery(query: Query, rootAlias: Alias, joins: Record<string, Query>, joinConditions: Record<Alias, JoinCondition>, subscribe: boolean): Observable<Array<Record<Alias, SquidDocument | undefined>>>;
40
- hasOngoingQueryForDocId(squidDocId: string): boolean;
41
- private removeClientRequestId;
42
- waitForAllQueriesToFinish(): Promise<void>;
43
- private registerQueryFinalizer;
44
- /** Creates a graph of ongoing queries and returns the root of the graph. */
45
- private createOngoingQueryGraph;
46
- private collectAllObservables;
47
- private joinResults;
48
- private join;
49
- private getOngoingQueriesBfs;
50
- private updateOngoingQueryWithNewDataFromSupportingQuery;
51
- private allOngoingQueriesGotServerResult;
52
- private completeAllSupportedQueries;
53
- private predestruct;
54
- unsubscribe(): void;
55
- hasSubscription(clientRequestId: ClientRequestId): boolean;
56
- /** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
57
- private sendQueryToServer;
58
- private migrateDocIds;
59
- }
@@ -1,7 +0,0 @@
1
- import { FieldName } from '@squidcloud/common';
2
- export type Alias = string;
3
- export interface JoinCondition {
4
- leftAlias: Alias;
5
- leftFieldName: FieldName;
6
- rightFieldName: FieldName;
7
- }
@@ -1,24 +0,0 @@
1
- import { ApiKey } from '@squidcloud/common';
2
- import { DestructManager } from './destruct.manager';
3
- import { SocketManagerInterface } from './socket.manager';
4
- export declare class RpcManager {
5
- private readonly rpcEndpoint;
6
- private readonly socketManager;
7
- private readonly staticHeaders;
8
- private readonly onGoingRpcsCounter;
9
- constructor(rpcEndpoint: string, socketManager: SocketManagerInterface, destructManager: DestructManager, apiKey?: ApiKey);
10
- awaitAllSettled(): Promise<void>;
11
- setStaticHeader(key: string, value: string): void;
12
- deleteStaticHeader(key: string): void;
13
- getEndpoint(): string;
14
- getStaticHeaders(): Record<string, string>;
15
- post<T>(path: string, message: any): Promise<T>;
16
- }
17
- export declare class RpcError extends Error {
18
- readonly statusCode: number;
19
- readonly statusText: string;
20
- readonly headers: Headers;
21
- readonly url: string;
22
- readonly body: string;
23
- constructor(statusCode: number, statusText: string, headers: Headers, url: string, body: string);
24
- }
@@ -1,27 +0,0 @@
1
- import { ClientId, MessageFromClient, MessageToClient } from '@squidcloud/common';
2
- import { Observable } from 'rxjs';
3
- import { DestructManager } from './destruct.manager';
4
- export interface SocketManagerInterface {
5
- observeNotifications(): Observable<MessageToClient>;
6
- observeConnectionReady(): Observable<boolean>;
7
- sendMessage(message: MessageFromClient): void;
8
- }
9
- export declare class SocketManager implements SocketManagerInterface {
10
- private readonly clientId;
11
- private readonly socketIoEndpoint;
12
- private readonly messageNotificationWrapper;
13
- private readonly destructManager;
14
- private readonly webSocketObserver;
15
- private readonly allMessagesObserver;
16
- private readonly connectionReady;
17
- private readonly seenMessageIds;
18
- private socket;
19
- private firstConnection;
20
- constructor(clientId: ClientId, socketIoEndpoint: string, messageNotificationWrapper: (fn: () => any) => any, destructManager: DestructManager);
21
- observeNotifications(): Observable<MessageToClient>;
22
- observeConnectionReady(): Observable<boolean>;
23
- sendMessage(message: MessageFromClient): void;
24
- private connect;
25
- private setupMessageAcknowledgments;
26
- private destruct;
27
- }
@@ -1,51 +0,0 @@
1
- import { ApiEndpointId, ApiKey, AppId, CollectionName, DocumentData, IntegrationId, QueryName, SupportedSquidRegion } from '@squidcloud/common';
2
- import { CollectionReference } from './collection-reference';
3
- import { GraphQLClient } from './graphql-client';
4
- import { TransactionId } from './types';
5
- export interface SquidOptions {
6
- messageNotificationWrapper?: (fn: () => any) => any;
7
- appId: AppId;
8
- apiKey?: ApiKey;
9
- region: SupportedSquidRegion;
10
- apiServerUrlOverrideMapping?: Record<IntegrationId, string>;
11
- }
12
- /** Reference to the squid db. Provides all the available actions on the DB. */
13
- export declare class Squid {
14
- private readonly socketManager;
15
- private readonly clientId;
16
- private readonly rpcManager;
17
- private readonly dataManager;
18
- private readonly documentReferenceFactory;
19
- private readonly documentStore;
20
- private readonly lockManager;
21
- private readonly querySubscriptionManager;
22
- private readonly queryBuilderFactory;
23
- private readonly joinQueryBuilderFactory;
24
- private readonly collectionReferenceFactory;
25
- private readonly backendFunctionManager;
26
- private readonly namedQueryManager;
27
- private readonly apiManager;
28
- private readonly graphqlClientFactory;
29
- private readonly destructManager;
30
- private readonly documentIdentityService;
31
- private static readonly squidInstancesMap;
32
- constructor(options: SquidOptions);
33
- /**
34
- * This method is a factory method for creating a Squid instance
35
- */
36
- static getInstance(options: SquidOptions): Squid;
37
- static getInstances(): Array<Squid>;
38
- /**
39
- * Sets the auth id token (OpenId) that will be sent to the server and will be used for providing the Auth object
40
- * to the security rules.
41
- */
42
- setAuthIdToken(idToken: string | undefined): void;
43
- collection<T extends DocumentData>(collectionName: CollectionName, integrationId?: IntegrationId): CollectionReference<T>;
44
- runInTransaction(fn: (transactionId: TransactionId) => Promise<void>): Promise<void>;
45
- executeFunction<T = any>(functionName: string, ...params: any[]): Promise<T>;
46
- executeNamedQuery<T = any>(integrationId: IntegrationId, queryName: QueryName, params: Record<string, any>): Promise<T>;
47
- callApi<T = any>(integrationId: IntegrationId, endpointId: ApiEndpointId, request?: Record<string, any>): Promise<T>;
48
- graphql(integrationId: IntegrationId): GraphQLClient;
49
- destruct(): Promise<void>;
50
- unsubscribe(): Promise<void>;
51
- }
@@ -1,7 +0,0 @@
1
- import { BaseAction } from './actions';
2
- export type StateLeafNode = string | boolean | number | null | undefined | object | Array<StateLeafNode> | State;
3
- export type State = {
4
- [key: string]: StateLeafNode;
5
- };
6
- export declare function apply(state: State, action: BaseAction): State;
7
- export declare function isStateObject(state: StateLeafNode): state is State;