@squidcloud/client 1.0.90 → 1.0.92

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.
@@ -9,4 +9,5 @@ export declare class DocumentReferenceFactory {
9
9
  constructor(documentIdentityService: DocumentIdentityService);
10
10
  create(squidDocId: SquidDocId, queryBuilderFactory: QueryBuilderFactory): DocumentReference;
11
11
  setDataManager(dataManager: DataManager): void;
12
+ private getCollectionKey;
12
13
  }
@@ -1,10 +1,12 @@
1
- import { GraphQLRequest, IntegrationId } from '@squidcloud/common';
1
+ import { GraphQLRequest, IntegrationId, SupportedSquidRegion } from '@squidcloud/common';
2
2
  import { RpcManager } from './rpc.manager';
3
3
  /** A GraphQL client that can be used to query and mutate data. */
4
4
  export declare class GraphQLClient {
5
5
  private readonly rpcManager;
6
+ private readonly region;
7
+ private readonly appId;
6
8
  private readonly client;
7
- constructor(rpcManager: RpcManager, integrationId: IntegrationId);
9
+ constructor(rpcManager: RpcManager, integrationId: IntegrationId, region: SupportedSquidRegion, appId: string);
8
10
  /** Executes a GraphQL query and returns a promise with the result. */
9
11
  query<T = any>(request: GraphQLRequest): Promise<T>;
10
12
  /** Executes a GraphQL mutation and returns a promise with the result. */
@@ -1,9 +1,11 @@
1
- import { IntegrationId } from '@squidcloud/common';
1
+ import { IntegrationId, SupportedSquidRegion } from '@squidcloud/common';
2
2
  import { GraphQLClient } from './graphql-client';
3
3
  import { RpcManager } from './rpc.manager';
4
4
  export declare class GraphQLClientFactory {
5
5
  private readonly rpcManager;
6
+ private readonly region;
7
+ private readonly appId;
6
8
  private readonly clientsMap;
7
- constructor(rpcManager: RpcManager);
9
+ constructor(rpcManager: RpcManager, region: SupportedSquidRegion, appId: string);
8
10
  get(integrationId: IntegrationId): GraphQLClient;
9
11
  }
@@ -0,0 +1,9 @@
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
+ }
@@ -6,6 +6,7 @@ export declare class QueryBuilder<DocumentType extends DocumentData> extends Bas
6
6
  private readonly collectionName;
7
7
  private readonly integrationId;
8
8
  private readonly querySubscriptionManager;
9
+ private readonly localQueryManager;
9
10
  private readonly documentReferenceFactory;
10
11
  private readonly queryBuilderFactory;
11
12
  private readonly documentIdentityService;
@@ -28,6 +29,14 @@ export declare class QueryBuilder<DocumentType extends DocumentData> extends Bas
28
29
  * result.
29
30
  */
30
31
  setForceFetchFromServer(): this;
32
+ /**
33
+ * Returns the results of the query based on the data that is currently available on the client. This method is useful
34
+ * for synchronously accessing data that has already been fetched by another query. The method will return an empty
35
+ * array if data has not yet been populated.
36
+ *
37
+ * @returns An array of query results.
38
+ */
39
+ peek(): Array<DocumentReference<DocumentType>>;
31
40
  /**
32
41
  * @inheritDoc
33
42
  */
@@ -1,10 +1,43 @@
1
1
  import { Alias, ClientRequestId, JoinCondition, Query, QuerySubscriptionId, SquidDocId, SquidDocument } from '@squidcloud/common';
2
- import { BehaviorSubject, Observable, Subject } from 'rxjs';
2
+ import { BehaviorSubject, Observable, ReplaySubject, Subject } from 'rxjs';
3
3
  import { DestructManager } from '../destruct.manager';
4
4
  import DocumentIdentityService from '../document-identity.service';
5
5
  import { DocumentStore } from '../document-store';
6
6
  import { RpcManager } from '../rpc.manager';
7
7
  import { ClientIdService } from '../client-id.service';
8
+ interface OngoingQuery {
9
+ clientRequestId: ClientRequestId;
10
+ query: Query;
11
+ supportedQueries: Array<OngoingQuery>;
12
+ supportingOngoingQuery?: OngoingQuery;
13
+ gotInitialResponse: boolean;
14
+ activated: boolean;
15
+ joinCondition?: JoinCondition;
16
+ alias: Alias;
17
+ dataSubject: BehaviorSubject<Array<SquidDocument> | null>;
18
+ queryRegistered: BehaviorSubject<boolean>;
19
+ /**
20
+ * In case that this query is a parent of another query (that is, the other query is a subset of this query), this
21
+ * query should not be unsubscribed from the server until we registered the child query in the server.
22
+ */
23
+ unsubscribeBlockerCount: BehaviorSubject<number>;
24
+ subscribe: boolean;
25
+ /**
26
+ * In case of joins, and if this ongoing query is the root, this field emits all the supported observables
27
+ * for example A.join(B, {..some join condition..}).join(C, {...some join condition}.
28
+ * This field will emit [A.subject.pipe(), B.subject.pipe(), C.subject.pipe()]. Any new supported queries will be
29
+ * added here.
30
+ */
31
+ allObservables?: ReplaySubject<Array<Observable<DocsAndAlias>>>;
32
+ isEmptyForJoin: boolean;
33
+ done: boolean;
34
+ isInFlight: boolean;
35
+ forceFetchFromServer: boolean;
36
+ }
37
+ interface DocsAndAlias {
38
+ docs: Array<SquidDocument>;
39
+ alias: Alias;
40
+ }
8
41
  export declare class QuerySubscriptionManager {
9
42
  private readonly rpcManager;
10
43
  private readonly clientIdService;
@@ -76,13 +109,15 @@ export declare class QuerySubscriptionManager {
76
109
  errorOutAllQueries(squidDocId: SquidDocId, err: any): void;
77
110
  /** Notifies to all the given queries (identified by their clientRequestId) with the updated query result. */
78
111
  notifyAllSubscriptions(clientRequestIds: ClientRequestId[]): void;
112
+ private isValidParent;
79
113
  /**
80
114
  * Given an ongoing query, search for candidate ongoing queries that can serve as a parent.
81
115
  * If there is a parent query, the result of that query can be used for serving the current query.
82
116
  * We will still register the current query on the server, but we do not need to run the query, apply security rules,
83
117
  * etc.
84
118
  */
85
- private findValidParentQuery;
119
+ private findValidParentOfOngoingQuery;
120
+ findValidParentOfQuery(query: Query): OngoingQuery | undefined;
86
121
  processQuery(query: Query, rootAlias: Alias, joins: Record<string, Query>, joinConditions: Record<Alias, JoinCondition>, subscribe: boolean, forceFetchFromServer: boolean): Observable<Array<Record<Alias, SquidDocument | undefined>>>;
87
122
  /**
88
123
  * Returns whether the given document ID has a query that has this document ID as a result.
@@ -132,3 +167,4 @@ export declare class QuerySubscriptionManager {
132
167
  private refreshOngoingQueries;
133
168
  private migrateDocIds;
134
169
  }
170
+ export {};
@@ -1,9 +1,11 @@
1
+ import { SupportedSquidRegion } from '@squidcloud/common';
1
2
  import { AuthManager } from './auth.manager';
2
3
  import { ClientIdService } from './client-id.service';
3
4
  import { DestructManager } from './destruct.manager';
4
5
  import { SocketManager } from './socket.manager';
5
6
  export declare class RpcManager {
6
- private readonly rpcEndpoint;
7
+ private readonly region;
8
+ private readonly appId;
7
9
  private readonly socketManager;
8
10
  private readonly destructManager;
9
11
  private readonly headers;
@@ -11,11 +13,10 @@ export declare class RpcManager {
11
13
  private readonly clientIdService;
12
14
  private readonly staticHeaders;
13
15
  private readonly onGoingRpcCounter;
14
- constructor(rpcEndpoint: string, socketManager: SocketManager, destructManager: DestructManager, headers: Record<string, string>, authManager: AuthManager, clientIdService: ClientIdService);
16
+ constructor(region: SupportedSquidRegion, appId: string, socketManager: SocketManager, destructManager: DestructManager, headers: Record<string, string>, authManager: AuthManager, clientIdService: ClientIdService);
15
17
  awaitAllSettled(): Promise<void>;
16
18
  setStaticHeader(key: string, value: string): void;
17
19
  deleteStaticHeader(key: string): void;
18
- getEndpoint(): string;
19
20
  getStaticHeaders(): Record<string, string>;
20
21
  post<T>(path: string, message: any): Promise<T>;
21
22
  }
@@ -1,11 +1,12 @@
1
- import { MessageFromClient, MessageToClient } from '@squidcloud/common';
1
+ import { MessageFromClient, MessageToClient, SupportedSquidRegion } from '@squidcloud/common';
2
2
  import { Observable } from 'rxjs';
3
3
  import { DestructManager } from './destruct.manager';
4
4
  import { AuthManager } from './auth.manager';
5
5
  import { ClientIdService } from './client-id.service';
6
6
  export declare class SocketManager {
7
7
  private readonly clientIdService;
8
- private readonly socketIoEndpoint;
8
+ private readonly region;
9
+ private readonly appId;
9
10
  private readonly messageNotificationWrapper;
10
11
  private readonly destructManager;
11
12
  private readonly authManager;
@@ -22,7 +23,7 @@ export declare class SocketManager {
22
23
  * Note: we make this a function so that we can easily override it in tests.
23
24
  */
24
25
  private clientTooOldThreshold;
25
- constructor(clientIdService: ClientIdService, socketIoEndpoint: string, messageNotificationWrapper: (fn: () => any) => any, destructManager: DestructManager, extraHeaders: Record<string, string> | undefined, authManager: AuthManager);
26
+ constructor(clientIdService: ClientIdService, region: SupportedSquidRegion, appId: string, messageNotificationWrapper: (fn: () => any) => any, destructManager: DestructManager, extraHeaders: Record<string, string> | undefined, authManager: AuthManager);
26
27
  observeNotifications<T extends MessageToClient>(): Observable<T>;
27
28
  observeConnectionReady(): Observable<boolean>;
28
29
  sendMessage(message: MessageFromClient): void;
@@ -2,10 +2,10 @@ import { ApiEndpointId, ApiKey, AppId, CollectionName, DocumentData, Environment
2
2
  import { Observable } from 'rxjs';
3
3
  import { AiAssistantClient } from './ai-assistant-client';
4
4
  import { CollectionReference } from './collection-reference';
5
+ import { ConnectionDetails } from './connection-details';
5
6
  import { DistributedLock } from './distributed-lock.manager';
6
7
  import { GraphQLClient } from './graphql-client';
7
8
  import { TransactionId } from './types';
8
- import { ConnectionDetails } from './connection-details';
9
9
  /** The different options that can be used to initialize a Squid instance. */
10
10
  export interface SquidOptions {
11
11
  /**
@@ -57,6 +57,7 @@ export declare class Squid {
57
57
  private readonly documentStore;
58
58
  private readonly lockManager;
59
59
  private readonly querySubscriptionManager;
60
+ private readonly localQueryManager;
60
61
  private readonly queryBuilderFactory;
61
62
  private readonly collectionReferenceFactory;
62
63
  private readonly backendFunctionManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.90",
3
+ "version": "1.0.92",
4
4
  "description": "A typescript implementation of the Squid client",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",