@squidcloud/backend 1.0.3 → 1.0.5

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.
@@ -1,6 +1,7 @@
1
1
  import { DocId, DocIdObj, DocumentData, IdResolutionMap, IntegrationId } from '@squidcloud/common';
2
2
  import { DocumentReference } from './document-reference';
3
3
  import { DocumentReferenceFactory } from './document-reference.factory';
4
+ import { JoinQueryBuilder, JoinQueryBuilderFactory } from './query/join-query-builder.factory';
4
5
  import { QueryBuilder, QueryBuilderFactory } from './query/query-builder.factory';
5
6
  import { Alias } from './query/query.types';
6
7
  export declare class CollectionReference<T extends DocumentData> {
@@ -8,10 +9,11 @@ export declare class CollectionReference<T extends DocumentData> {
8
9
  private integrationId;
9
10
  private readonly documentReferenceFactory;
10
11
  private readonly queryBuilderFactory;
12
+ private readonly joinQueryBuilderFactory;
11
13
  private readonly documents;
12
- constructor(collectionName: string, integrationId: IntegrationId, documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory);
14
+ constructor(collectionName: string, integrationId: IntegrationId, documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, joinQueryBuilderFactory: JoinQueryBuilderFactory);
13
15
  doc(docId?: DocId | DocIdObj): DocumentReference<T>;
14
- query(): Omit<QueryBuilder<T, any, Record<Alias, DocumentReference<T>>, false>, 'join'>;
15
- joinQuery<A extends Alias>(alias: A): QueryBuilder<T, A, Record<A, DocumentReference<T>>, true>;
16
+ query(): QueryBuilder<T>;
17
+ joinQuery<A extends Alias>(alias: A): JoinQueryBuilder<T, A, Record<A, DocumentReference<T>>>;
16
18
  migrateDocIds(idResolutionMap: IdResolutionMap): void;
17
19
  }
@@ -2,13 +2,15 @@ import { CollectionName, DocumentData, IntegrationId } from '@squidcloud/common'
2
2
  import { CollectionReference } from './collection-reference';
3
3
  import DocumentIdentityService from './document-identity.service';
4
4
  import { DocumentReferenceFactory } from './document-reference.factory';
5
+ import { JoinQueryBuilderFactory } from './query/join-query-builder.factory';
5
6
  import { QueryBuilderFactory } from './query/query-builder.factory';
6
7
  export declare class CollectionReferenceFactory {
7
8
  private readonly documentReferenceFactory;
8
9
  private readonly queryBuilderFactory;
10
+ private readonly joinQueryBuilderFactory;
9
11
  private readonly documentIdentityService;
10
12
  private readonly collections;
11
- constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, documentIdentityService: DocumentIdentityService);
13
+ constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, joinQueryBuilderFactory: JoinQueryBuilderFactory, documentIdentityService: DocumentIdentityService);
12
14
  get<T extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): CollectionReference<T>;
13
15
  private migrateDocIds;
14
16
  }
@@ -77,7 +77,8 @@ export declare class DataManager {
77
77
  * result for document with id='a'.
78
78
  */
79
79
  private readonly outgoingMutationsEmpty;
80
- private readonly docsToResync;
80
+ private readonly failedDocsToResync;
81
+ private readonly refreshDocIdToTimestamp;
81
82
  private deleteExpiredTimestampsInterval;
82
83
  private handleIncomingMessagesForTests;
83
84
  constructor(documentStore: DocumentStore, mutationSender: MutationSender, socketManager: SocketManagerInterface, querySubscriptionManager: QuerySubscriptionManager, queryBuilderFactory: QueryBuilderFactory, lockManager: LockManager, destructManager: DestructManager, documentIdentityService: DocumentIdentityService);
@@ -148,6 +149,7 @@ export declare class DataManager {
148
149
  private sendMutationsForIntegration;
149
150
  private removeOutgoingMutation;
150
151
  private resyncFailedUpdates;
152
+ private refreshUpdatedDocuments;
151
153
  private groupOutgoingMutationsByIntegrationId;
152
154
  /**
153
155
  * Handles the case that due to some change (an incoming or outgoing change to a document), a document becomes orphan.
@@ -1,4 +1,5 @@
1
1
  import { DocumentData, IdResolutionMap, Paths, SquidDocId } from '@squidcloud/common';
2
+ import { Observable } from 'rxjs';
2
3
  import { DataManager } from './data.manager';
3
4
  import { QueryBuilderFactory } from './query/query-builder.factory';
4
5
  import { TransactionId } from './types';
@@ -9,7 +10,8 @@ export declare class DocumentReference<T extends DocumentData = any> {
9
10
  constructor(_squidDocId: SquidDocId, dataManager: DataManager, queryBuilderFactory: QueryBuilderFactory);
10
11
  get squidDocId(): SquidDocId;
11
12
  data(): T;
12
- get(): Promise<DocumentReference<T> | undefined>;
13
+ snapshot(): Promise<DocumentReference<T> | undefined>;
14
+ snapshots(): Observable<DocumentReference<T> | undefined>;
13
15
  isDirty(): boolean;
14
16
  private isTracked;
15
17
  update(data: Partial<Record<Paths<T>, any>>, transactionId?: TransactionId): Promise<void>;
@@ -1,4 +1,7 @@
1
1
  export { CollectionReference } from './collection-reference';
2
2
  export { DocumentReference } from './document-reference';
3
- export { Changes } from './query/query-builder.factory';
4
- export { Squid } from './squid';
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';
@@ -0,0 +1,35 @@
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
+ }
@@ -4,38 +4,31 @@ import DocumentIdentityService from '../document-identity.service';
4
4
  import { DocumentReference } from '../document-reference';
5
5
  import { DocumentReferenceFactory } from '../document-reference.factory';
6
6
  import { QuerySubscriptionManager } from './query-subscription.manager';
7
- import { Alias } from './query.types';
8
7
  export declare class QueryBuilderFactory {
9
8
  private readonly querySubscriptionManager;
10
9
  private readonly documentReferenceFactory;
11
10
  private readonly documentIdentityService;
12
11
  constructor(querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, documentIdentityService: DocumentIdentityService);
13
- getForDocument<DocumentType extends DocumentData, ReturnType extends Record<Alias, DocumentReference<DocumentType>>>(squidDocId: SquidDocId): Omit<QueryBuilder<DocumentType, any, ReturnType, false>, 'join'>;
14
- get<DocumentType extends DocumentData, ReturnType extends Record<Alias, DocumentReference<DocumentType>>>(collectionName: CollectionName, integrationId: IntegrationId): Omit<QueryBuilder<DocumentType, any, ReturnType, false>, 'join'>;
15
- getForJoin<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType>>>(collectionName: CollectionName, integrationId: IntegrationId, alias: MyAlias): QueryBuilder<DocumentType, MyAlias, ReturnType, true>;
12
+ getForDocument<DocumentType extends DocumentData>(squidDocId: SquidDocId): QueryBuilder<DocumentType>;
13
+ get<DocumentType extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): QueryBuilder<DocumentType>;
16
14
  }
17
- export declare class QueryBuilder<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType> | undefined>, SupportsJoin extends boolean> {
15
+ export declare class QueryBuilder<DocumentType extends DocumentData> {
18
16
  private readonly collectionName;
19
17
  private readonly integrationId;
20
18
  private readonly querySubscriptionManager;
21
19
  private readonly documentReferenceFactory;
22
- private readonly alias;
23
- private readonly supportsJoin;
24
20
  private readonly queryBuilderFactory;
25
21
  private readonly documentIdentityService;
26
22
  private readonly simpleQueryBuilder;
27
- private readonly joins;
28
- /** Record that maps the right alias to the left condition */
29
- private readonly joinConditions;
30
- constructor(collectionName: CollectionName, integrationId: IntegrationId, querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, alias: MyAlias, supportsJoin: SupportsJoin, queryBuilderFactory: QueryBuilderFactory, documentIdentityService: DocumentIdentityService);
31
- where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): SupportsJoin extends true ? this : Omit<this, 'join'>;
32
- limit(limit: number): SupportsJoin extends true ? this : Omit<this, 'join'>;
33
- sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): SupportsJoin extends true ? this : Omit<this, 'join'>;
34
- join<J extends DocumentData, RightAlias extends Alias, RightReturnType extends Record<RightAlias, DocumentReference<J> | undefined>>(queryBuilder: QueryBuilder<J, RightAlias, RightReturnType, true>, leftFieldName: keyof DocumentType & FieldName, rightFieldName: keyof J & FieldName): QueryBuilder<DocumentType, MyAlias, ReturnType & Partial<RightReturnType>, true>;
35
- snapshot(): SupportsJoin extends true ? Promise<Array<ReturnType>> : Promise<Array<DocumentReference<DocumentType>>>;
36
- snapshots(subscribe?: boolean): SupportsJoin extends true ? Observable<Array<ReturnType>> : Observable<Array<DocumentReference<DocumentType>>>;
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>>>;
37
29
  changes(): Observable<Changes<DocumentType>>;
38
30
  build(): Query;
31
+ get hash(): string;
39
32
  }
40
33
  export interface Changes<DocumentType extends DocumentData> {
41
34
  inserts: Array<DocumentReference<DocumentType>>;
@@ -51,6 +51,7 @@ export declare class QuerySubscriptionManager {
51
51
  private allOngoingQueriesGotServerResult;
52
52
  private completeAllSupportedQueries;
53
53
  private predestruct;
54
+ unsubscribe(): void;
54
55
  hasSubscription(clientRequestId: ClientRequestId): boolean;
55
56
  /** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
56
57
  private sendQueryToServer;
@@ -7,6 +7,7 @@ export declare class RpcManager {
7
7
  private readonly staticHeaders;
8
8
  private readonly onGoingRpcsCounter;
9
9
  constructor(rpcEndpoint: string, socketManager: SocketManagerInterface, destructManager: DestructManager, apiKey?: ApiKey);
10
+ awaitAllSettled(): Promise<void>;
10
11
  setStaticHeader(key: string, value: string): void;
11
12
  deleteStaticHeader(key: string): void;
12
13
  getEndpoint(): string;
@@ -20,6 +20,7 @@ export declare class Squid {
20
20
  private readonly lockManager;
21
21
  private readonly querySubscriptionManager;
22
22
  private readonly queryBuilderFactory;
23
+ private readonly joinQueryBuilderFactory;
23
24
  private readonly collectionReferenceFactory;
24
25
  private readonly backendFunctionManager;
25
26
  private readonly namedQueryManager;
@@ -46,4 +47,5 @@ export declare class Squid {
46
47
  callApi<T = any>(integrationId: IntegrationId, endpointId: ApiEndpointId, request?: Record<string, any>): Promise<T>;
47
48
  graphql(integrationId: IntegrationId): GraphQLClient;
48
49
  destruct(): Promise<void>;
50
+ unsubscribe(): Promise<void>;
49
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/backend",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Squid Cloud's backend SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/backend/src/index.d.ts",
@@ -1 +0,0 @@
1
- export declare function isDefined<T>(t: T | undefined | null): t is T;