@squidcloud/client 1.0.167 → 1.0.169

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.
package/dist/cjs/index.js CHANGED
@@ -30353,6 +30353,7 @@ function map(project, thisArg) {
30353
30353
 
30354
30354
 
30355
30355
  class AiChatbotClient {
30356
+ /** @internal */
30356
30357
  constructor(rpcManager, socketManager, integrationId) {
30357
30358
  this.rpcManager = rpcManager;
30358
30359
  this.socketManager = socketManager;
@@ -30446,6 +30447,7 @@ class AiChatbotClient {
30446
30447
  }
30447
30448
  }
30448
30449
  class AiChatbotProfileReference {
30450
+ /** @internal */
30449
30451
  constructor(client, integrationId, profileId) {
30450
30452
  this.client = client;
30451
30453
  this.integrationId = integrationId;
@@ -30550,6 +30552,7 @@ class AiChatbotProfileReference {
30550
30552
  }
30551
30553
  }
30552
30554
  class AiChatbotContextReference {
30555
+ /** @internal */
30553
30556
  constructor(client, integrationId, profileId, id) {
30554
30557
  this.client = client;
30555
30558
  this.integrationId = integrationId;
@@ -30625,6 +30628,7 @@ class AiChatbotContextReference {
30625
30628
  }
30626
30629
  }
30627
30630
  class AiChatbotInstructionReference {
30631
+ /** @internal */
30628
30632
  constructor(client, integrationId, profileId, id) {
30629
30633
  this.client = client;
30630
30634
  this.integrationId = integrationId;
@@ -30764,6 +30768,7 @@ function validateFieldSort(fieldSort) {
30764
30768
  (0,dist.assertTruthy)(isRightType(safeFieldSort.asc, 'boolean'), 'Asc needs to be boolean');
30765
30769
  validateFieldName(safeFieldSort.fieldName);
30766
30770
  }
30771
+ /** @internal */
30767
30772
  function validateOpenIdProvider(openIdProvider) {
30768
30773
  assertTruthy(openIdProvider, 'INVALID_PROVIDER');
30769
30774
  validateOpenIdProviderType(openIdProvider.providerType);
@@ -30772,6 +30777,7 @@ function validateOpenIdProvider(openIdProvider) {
30772
30777
  assertTruthy(openIdProvider.domain, 'INVALID_DOMAIN');
30773
30778
  return openIdProvider;
30774
30779
  }
30780
+ /** @internal */
30775
30781
  function validateOpenIdProviderType(providerType) {
30776
30782
  const providerArray = ['auth0'];
30777
30783
  assertTruthy(providerArray.includes(providerType), 'INVALID_OPEN_ID_PROVIDER_TYPE');
@@ -48197,13 +48203,13 @@ class GraphQLClient {
48197
48203
 
48198
48204
  ;// CONCATENATED MODULE: ./src/ai-chatbot-client.factory.ts
48199
48205
 
48206
+ /** @internal */
48200
48207
  class AiChatbotClientFactory {
48201
48208
  constructor(rpcManager, socketManager) {
48202
48209
  this.rpcManager = rpcManager;
48203
48210
  this.socketManager = socketManager;
48204
48211
  this.chatbotsMap = new Map();
48205
48212
  }
48206
- /** @internal */
48207
48213
  getChatbot(aiIntegrationId) {
48208
48214
  let client = this.chatbotsMap.get(aiIntegrationId);
48209
48215
  if (client)
@@ -48422,6 +48428,7 @@ class ClientIdService {
48422
48428
 
48423
48429
  ;// CONCATENATED MODULE: ./src/collection-reference.factory.ts
48424
48430
 
48431
+ /** @internal */
48425
48432
  class CollectionReferenceFactory {
48426
48433
  constructor(documentReferenceFactory, queryBuilderFactory, querySubscriptionManager) {
48427
48434
  this.documentReferenceFactory = documentReferenceFactory;
@@ -48643,6 +48650,7 @@ function reduceMutations(mutations) {
48643
48650
 
48644
48651
  /** Two transactions cannot run in parallel - this mutex is used for blocking a second transaction. */
48645
48652
  const RUN_IN_TRANSACTION_MUTEX = 'dataManager_runInTransaction';
48653
+ /** @internal */
48646
48654
  class DataManager {
48647
48655
  constructor(documentStore, mutationSender, socketManager, querySubscriptionManager, queryBuilderFactory, lockManager, destructManager, documentIdentityService, querySender) {
48648
48656
  this.documentStore = documentStore;
@@ -49472,6 +49480,7 @@ class DistributedLockImpl {
49472
49480
 
49473
49481
  ;// CONCATENATED MODULE: ./src/document-identity.service.ts
49474
49482
 
49483
+ /** @internal */
49475
49484
  class DocumentIdentityService {
49476
49485
  constructor(documentStore, destructManager) {
49477
49486
  this.documentStore = documentStore;
@@ -49498,12 +49507,11 @@ class DocumentIdentityService {
49498
49507
 
49499
49508
 
49500
49509
 
49510
+ /** @internal */
49501
49511
  class DocumentReferenceFactory {
49502
49512
  constructor(documentIdentityService) {
49503
49513
  this.documentIdentityService = documentIdentityService;
49504
- /** @internal */
49505
49514
  this.documents = new Map();
49506
- /** @internal */
49507
49515
  this.documentsForCollection = new Map();
49508
49516
  this.documentIdentityService.observeChanges().subscribe(this.migrateDocIds.bind(this));
49509
49517
  }
@@ -49522,16 +49530,10 @@ class DocumentReferenceFactory {
49522
49530
  setDataManager(dataManager) {
49523
49531
  this.dataManager = dataManager;
49524
49532
  }
49525
- /**
49526
- * @internal
49527
- */
49528
49533
  getDocumentsForCollection(integrationId, collectionName) {
49529
49534
  const collectionKey = this.getCollectionKey(integrationId, collectionName);
49530
49535
  return (this.documentsForCollection.get(collectionKey) || []).filter(d => d.hasData);
49531
49536
  }
49532
- /**
49533
- * @internal
49534
- */
49535
49537
  migrateDocIds(idResolutionMap) {
49536
49538
  for (const [, reference] of this.documents) {
49537
49539
  reference.migrateDocIds(idResolutionMap);
@@ -49679,6 +49681,7 @@ class GraphQLClientFactory {
49679
49681
 
49680
49682
 
49681
49683
 
49684
+ /** @internal */
49682
49685
  class MutationSender {
49683
49686
  constructor(rpcManager, lockManager, querySender) {
49684
49687
  this.rpcManager = rpcManager;
@@ -49713,13 +49716,13 @@ class MutationSender {
49713
49716
  ;// CONCATENATED MODULE: ./src/query/local-query-manager.ts
49714
49717
 
49715
49718
 
49719
+ /** @internal */
49716
49720
  class LocalQueryManager {
49717
49721
  constructor(documentStore, documentReferenceFactory, querySubscriptionManager) {
49718
49722
  this.documentStore = documentStore;
49719
49723
  this.documentReferenceFactory = documentReferenceFactory;
49720
49724
  this.querySubscriptionManager = querySubscriptionManager;
49721
49725
  }
49722
- /** @internal */
49723
49726
  peek(query) {
49724
49727
  if (!this.querySubscriptionManager.findValidParentOfQuery(query))
49725
49728
  return [];
@@ -49829,6 +49832,7 @@ const arrayMergeCustomizer = (a, b) => {
49829
49832
  // Exported only for tests
49830
49833
  const FETCH_BEYOND_LIMIT = 100;
49831
49834
  const LIMIT_UNDERFLOW_TRIGGER = 20;
49835
+ /** @internal */
49832
49836
  class QuerySubscriptionManager {
49833
49837
  constructor(rpcManager, clientIdService, documentStore, destructManager, documentIdentityService, querySender) {
49834
49838
  this.rpcManager = rpcManager;
@@ -51037,6 +51041,7 @@ function createWebSocketWrapper(url, opts = {}) {
51037
51041
 
51038
51042
 
51039
51043
 
51044
+ /** @internal */
51040
51045
  class SocketManager {
51041
51046
  constructor(clientIdService, region, appId, messageNotificationWrapper = NOOP_FN, destructManager, authManager) {
51042
51047
  this.clientIdService = clientIdService;
@@ -51233,6 +51238,7 @@ class SocketManager {
51233
51238
  ;// CONCATENATED MODULE: ./src/query/query-sender.ts
51234
51239
 
51235
51240
 
51241
+ /** @internal */
51236
51242
  class QuerySender {
51237
51243
  constructor(rpcManager, destructManager) {
51238
51244
  this.rpcManager = rpcManager;
@@ -51462,6 +51468,7 @@ class AiAssistantClient {
51462
51468
  * through its methods.
51463
51469
  */
51464
51470
  class AiClient {
51471
+ /** @internal */
51465
51472
  constructor(aiChatbotClientFactory, rpcManager) {
51466
51473
  this.aiChatbotClientFactory = aiChatbotClientFactory;
51467
51474
  this.rpcManager = rpcManager;
@@ -51556,6 +51563,7 @@ class LockManager {
51556
51563
 
51557
51564
  ;// CONCATENATED MODULE: ./src/queue.manager.ts
51558
51565
 
51566
+
51559
51567
  /** @internal */
51560
51568
  class QueueManagerFactory {
51561
51569
  constructor(rpcManager, socketManager, destructManager) {
@@ -51595,6 +51603,7 @@ class QueueManagerFactory {
51595
51603
  return (_a = this.queueManagers.get(integrationId)) === null || _a === void 0 ? void 0 : _a.get(topicName);
51596
51604
  }
51597
51605
  }
51606
+ const SUBSCRIPTION_MUTEX = 'subscriptionMutex';
51598
51607
  /** @internal */
51599
51608
  class QueueManagerImpl {
51600
51609
  constructor(integrationId, topicName, rpcManager) {
@@ -51603,6 +51612,7 @@ class QueueManagerImpl {
51603
51612
  this.rpcManager = rpcManager;
51604
51613
  this.messagesSubject = new external_rxjs_.Subject();
51605
51614
  this.subscriberCount = 0;
51615
+ this.lockManager = new LockManager();
51606
51616
  }
51607
51617
  async produce(messages) {
51608
51618
  await this.rpcManager.post('queue/produceMessages', {
@@ -51613,32 +51623,48 @@ class QueueManagerImpl {
51613
51623
  }
51614
51624
  consume() {
51615
51625
  return (0,external_rxjs_.defer)(() => {
51616
- // Code to run when the observable is subscribed
51617
51626
  this.subscriberCount++;
51618
51627
  if (this.subscriberCount === 1) {
51619
- this.rpcManager
51620
- .post('queue/subscribe', {
51621
- integrationId: this.integrationId,
51622
- topicName: this.topicName,
51623
- })
51624
- .catch(e => {
51625
- this.messagesSubject.error(e);
51626
- this.messagesSubject.complete();
51627
- this.subscriberCount = 0;
51628
- this.messagesSubject = new external_rxjs_.Subject();
51629
- });
51628
+ void this.performSubscribe();
51630
51629
  }
51631
51630
  return this.messagesSubject.asObservable().pipe((0,external_rxjs_.finalize)(() => {
51632
51631
  this.subscriberCount--;
51633
51632
  if (this.subscriberCount === 0) {
51634
- this.rpcManager.post('queue/unsubscribe', {
51635
- integrationId: this.integrationId,
51636
- topicName: this.topicName,
51637
- });
51633
+ void this.performUnsubscribe();
51638
51634
  }
51639
51635
  }));
51640
51636
  });
51641
51637
  }
51638
+ async performSubscribe() {
51639
+ await this.lockManager.lock(SUBSCRIPTION_MUTEX);
51640
+ try {
51641
+ await this.rpcManager.post('queue/subscribe', {
51642
+ integrationId: this.integrationId,
51643
+ topicName: this.topicName,
51644
+ });
51645
+ }
51646
+ catch (e) {
51647
+ this.messagesSubject.error(e);
51648
+ this.messagesSubject.complete();
51649
+ this.subscriberCount = 0;
51650
+ this.messagesSubject = new external_rxjs_.Subject();
51651
+ }
51652
+ finally {
51653
+ this.lockManager.release(SUBSCRIPTION_MUTEX);
51654
+ }
51655
+ }
51656
+ async performUnsubscribe() {
51657
+ await this.lockManager.lock(SUBSCRIPTION_MUTEX);
51658
+ try {
51659
+ await this.rpcManager.post('queue/unsubscribe', {
51660
+ integrationId: this.integrationId,
51661
+ topicName: this.topicName,
51662
+ });
51663
+ }
51664
+ finally {
51665
+ this.lockManager.release(SUBSCRIPTION_MUTEX);
51666
+ }
51667
+ }
51642
51668
  onMessages(payload) {
51643
51669
  for (const message of payload) {
51644
51670
  this.messagesSubject.next(message);
@@ -1,2 +1 @@
1
- import { ApplicationSecrets } from './secret.types';
2
- export declare function convertToRunSecrets(appSecrets: ApplicationSecrets): RunSecrets;
1
+ export {};
@@ -1,4 +1 @@
1
- export interface LocalBackendData {
2
- applicationBundleData: ApplicationBundleData;
3
- openApiSpecStr?: string;
4
- }
1
+ export {};
@@ -1,7 +1 @@
1
- import { IntegrationId } from '../public-types/communication.public-types';
2
- export interface QueueMessageToClient extends BaseMessageToClient {
3
- type: 'queue';
4
- integrationId: IntegrationId;
5
- topicName: string;
6
- payload: string[];
7
- }
1
+ export {};
@@ -1,5 +1,4 @@
1
1
  import { HttpStatus } from '../public-types/http-status.enum';
2
- import { OpenIdProvider } from '../public-types/application.public-types';
3
2
  export type StatusCode = HttpStatus.BAD_REQUEST | HttpStatus.NOT_FOUND | HttpStatus.FORBIDDEN | HttpStatus.UNAUTHORIZED | HttpStatus.CONFLICT;
4
3
  export declare class ValidationError extends Error {
5
4
  readonly statusCode: StatusCode;
@@ -9,8 +8,6 @@ export declare class ValidationError extends Error {
9
8
  export declare function isValidId(id: unknown): boolean;
10
9
  export declare function validateId(id: unknown, message: string): void;
11
10
  export declare function validateFieldSort(fieldSort: unknown): void;
12
- export declare function validateOpenIdProvider(openIdProvider: OpenIdProvider | undefined): OpenIdProvider;
13
- export declare function validateOpenIdProviderType(providerType: unknown): void;
14
11
  export declare function validateMutations(mutations: unknown): void;
15
12
  export declare function validateQueryLimit(limit: unknown): void;
16
13
  /** Returns true if the value is not an empty string (undefined/null are considered empty). */
@@ -1,13 +1,10 @@
1
- import { AiChatbotChatOptions, AiChatbotContext, AiModelName, IntegrationId } from './public-types';
1
+ import { AiChatbotChatOptions, AiChatbotContext, AiModelName } from './public-types';
2
2
  import { Observable } from 'rxjs';
3
- import { RpcManager } from './rpc.manager';
4
- import { SocketManager } from './socket.manager';
5
3
  export declare class AiChatbotClient {
6
4
  private readonly rpcManager;
7
5
  private readonly socketManager;
8
6
  private readonly integrationId;
9
7
  private readonly ongoingChatSequences;
10
- constructor(rpcManager: RpcManager, socketManager: SocketManager, integrationId: IntegrationId);
11
8
  /**
12
9
  * Retrieves a profile reference for the provided id. A profile reference
13
10
  * can be used to create and update profiles, add instructions and context
@@ -33,7 +30,6 @@ export declare class AiChatbotProfileReference {
33
30
  private readonly client;
34
31
  private readonly integrationId;
35
32
  private readonly profileId;
36
- constructor(client: AiChatbotClient, integrationId: IntegrationId, profileId: string);
37
33
  /**
38
34
  * Sends a prompt to the current profile.
39
35
  *
@@ -99,7 +95,6 @@ declare class AiChatbotContextReference {
99
95
  private readonly integrationId;
100
96
  private readonly profileId;
101
97
  private readonly id;
102
- constructor(client: AiChatbotClient, integrationId: IntegrationId, profileId: string, id?: string);
103
98
  /**
104
99
  * Adds a new context entry to the chatbot profile. This will result in an error if an entry already exists with
105
100
  * the same id.
@@ -140,7 +135,6 @@ declare class AiChatbotInstructionReference {
140
135
  private readonly integrationId;
141
136
  private readonly profileId;
142
137
  private readonly id;
143
- constructor(client: AiChatbotClient, integrationId: IntegrationId, profileId: string, id?: string);
144
138
  /**
145
139
  * Adds a new instruction entry to the chatbot profile. This will result in an error if an entry already exists with
146
140
  * the same id.
@@ -1,8 +1 @@
1
- import { RpcManager } from './rpc.manager';
2
- import { SocketManager } from './socket.manager';
3
- export declare class AiChatbotClientFactory {
4
- private readonly rpcManager;
5
- private readonly socketManager;
6
- private readonly chatbotsMap;
7
- constructor(rpcManager: RpcManager, socketManager: SocketManager);
8
- }
1
+ export {};
@@ -1,6 +1,4 @@
1
1
  import { AiChatbotClient } from './ai-chatbot-client';
2
- import { AiChatbotClientFactory } from './ai-chatbot-client.factory';
3
- import { RpcManager } from './rpc.manager';
4
2
  import { AiAssistantClient } from './ai-assistant-client';
5
3
  import { IntegrationId } from './public-types';
6
4
  export interface ExecuteAiQueryRequest {
@@ -23,7 +21,6 @@ export declare class AiClient {
23
21
  private readonly aiChatbotClientFactory;
24
22
  private readonly rpcManager;
25
23
  private readonly aiAssistantClient;
26
- constructor(aiChatbotClientFactory: AiChatbotClientFactory, rpcManager: RpcManager);
27
24
  /**
28
25
  * Retrieves an AI chatbot client for a specific AI integration.
29
26
  * @param aiIntegrationId - The identifier for the AI integration.
@@ -1,13 +1 @@
1
- import { CollectionReference } from './collection-reference';
2
- import { DocumentReferenceFactory } from './document-reference.factory';
3
- import { QueryBuilderFactory } from './query/query-builder.factory';
4
- import { QuerySubscriptionManager } from './query/query-subscription.manager';
5
- import { CollectionName, DocumentData, IntegrationId } from './public-types';
6
- export declare class CollectionReferenceFactory {
7
- private readonly documentReferenceFactory;
8
- private readonly queryBuilderFactory;
9
- private readonly querySubscriptionManager;
10
- private readonly collections;
11
- constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, querySubscriptionManager: QuerySubscriptionManager);
12
- get<T extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): CollectionReference<T>;
13
- }
1
+ export {};
@@ -1,175 +1,5 @@
1
- import { DocTimestamp, Mutation, SquidDocId, SquidDocument } from './public-types';
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 { QuerySender } from './query/query-sender';
8
- import { QuerySubscriptionManager } from './query/query-subscription.manager';
9
- import { SocketManager } from './socket.manager';
10
- import { TransactionId } from './types';
11
- import { LockManager } from '../../internal-common/src/utils/lock.manager';
1
+ import { DocTimestamp } from './public-types';
12
2
  export interface DocTimestampMetadata {
13
3
  timestamp: DocTimestamp;
14
4
  expireTimestamp?: number;
15
5
  }
16
- export declare class DataManager {
17
- private readonly documentStore;
18
- private readonly mutationSender;
19
- private readonly socketManager;
20
- private readonly querySubscriptionManager;
21
- private readonly queryBuilderFactory;
22
- private readonly lockManager;
23
- private readonly destructManager;
24
- private readonly documentIdentityService;
25
- private readonly querySender;
26
- private readonly docIdToLocalTimestamp;
27
- private currentTransactionId;
28
- /**
29
- * During a batch, any update to a document that may trigger an update to a query is collected here and once the batch
30
- * ends, the relevant subscribes to these queries will be updated.
31
- */
32
- private readonly batchClientRequestIds;
33
- /**
34
- * In this map we save timestamps for documents that are available locally or recently deleted but need to remain
35
- * here so if a mutation comes from the server we know whether to apply it or not based on the timestamp. For
36
- * example, if a document is removed locally and immediately after, an update is received from the server - In that
37
- * case, it may be the update pre-dates the data that was available locally a second ago. For that reason, the
38
- * timestamp needs to be kept and even for removed documents it will be kept for ~20 seconds more.
39
- *
40
- * Eventually, this map is used as a gatekeeper for preventing old versions of a document (based on timestamp) to
41
- * appear on the client.
42
- */
43
- private readonly docIdToServerTimestamp;
44
- /**
45
- * In the case of a local change (outgoing change) without a server timestamp, an incoming server update cannot be
46
- * applied and needs to be queued until the local state allows it. In this case the incoming update will be queued in
47
- * this map. Any future incoming server update to the same document will override the previous update in case it has
48
- * a later timestamp.
49
- */
50
- private readonly pendingIncomingUpdates;
51
- /**
52
- * A mutation sent to the server will be stored in this map until it receives a timestamp from the server. These
53
- * mutations were already applied locally and were sent to the server or about to be sent if sentToServer=false
54
- * (or are queued in the MutationSender due to a lock). The existence of these pending mutations indicates the data
55
- * manager to:
56
- * 1 - Not apply any incoming server mutation while there are outgoing mutations without a timestamp
57
- * 2 - Not delete the local document even if there are no queries related to this document - there is a chance
58
- * that there will be a future query that will need this document and the query needs to return the local version
59
- * of the document.
60
- * 3 - Even when all outgoing mutations have a timestamp, it may be that there is a pending query in flight that will
61
- * need to return the document. In this case, the local document may be different from the server. Hence, it
62
- * cannot accept the server change and will wait for another update from the server. For this purpose, timestamp
63
- * will be stored in docsToTimestamp for ~20 more seconds.
64
- *
65
- * Note: Only one entry per squidDocId can be with sentToServer=false. This is true since all updates to the same doc
66
- * in the same batch are appended (and reduced) to the same outgoing mutation object.
67
- */
68
- private readonly pendingOutgoingMutations;
69
- private readonly pendingOutgoingMutationsChanged;
70
- /**
71
- * A subject for whether there are outgoing mutations. If there are outgoing mutations, any incoming update from the
72
- * server will be delayed until all the outgoing mutations will be acknowledged by the server.
73
- * This mechanism is needed to avoid this case:
74
- *
75
- * collection.docRef('a').delete();
76
- * collection.snapshots().subscribe((res) => {
77
- * // The result here may include doc with id='a' since the delete mutation was not acknowledged.
78
- * });
79
- *
80
- * If we wait for the acknowledgment message, we will have a server timestamp and will be able to ignore the incoming
81
- * result for document with id='a'.
82
- */
83
- private readonly outgoingMutationsEmpty;
84
- /**
85
- * When applying an outgoing mutation, there may be a short time that the mutation is not yet inserted into the
86
- * pending outgoing mutations map. In this case, we mark the document id as known to be dirty and remove it from the
87
- * set once the pending outgoing mutations map is updated.
88
- */
89
- private readonly knownDirtyDocs;
90
- private readonly failedDocsToResync;
91
- private readonly refreshDocIdToTimestamp;
92
- private deleteExpiredTimestampsInterval;
93
- private handleIncomingMessagesForTests;
94
- constructor(documentStore: DocumentStore, mutationSender: MutationSender, socketManager: SocketManager, querySubscriptionManager: QuerySubscriptionManager, queryBuilderFactory: QueryBuilderFactory, lockManager: LockManager, destructManager: DestructManager, documentIdentityService: DocumentIdentityService, querySender: QuerySender);
95
- getProperties(squidDocId: SquidDocId): SquidDocument | undefined;
96
- /** Whether a document has changes that are out of sync with the server. */
97
- isDirty(squidDocId: SquidDocId): boolean;
98
- /**
99
- * Runs the provided function without sending mutations to the server while collecting the updates to the different
100
- * queries. Local updates will still be applied. Once the batch finishes, all the updates will be sent to the server
101
- * and the different queries will be notified. runInTransaction may be invoked inside another runInTransaction, only
102
- * the top level batch will trigger updates to the server.
103
- */
104
- runInTransaction<T = any>(fn: (transactionId: TransactionId) => Promise<T>, transactionId?: TransactionId): Promise<T>;
105
- /** Applies a mutation done from the client (from DocumentReference) and sends it to the server. */
106
- applyOutgoingMutation(mutation: Mutation, transactionId: TransactionId | undefined): Promise<void>;
107
- /** Same as runInTransaction with the exception that the passed function runs synchronously. */
108
- private runInTransactionSync;
109
- /** Remove properties from the document record that should not be sent to the server. */
110
- private removeInternalProperties;
111
- /** Listens and handles mutations and snapshots notifications from the socketManager. */
112
- private handleNotifications;
113
- private handleIncomingMutations;
114
- private handleIncomingQuerySnapshots;
115
- /**
116
- * Returns a boolean for whether some updates were ignored because the client knows of a later timestamp for those
117
- * documents.
118
- */
119
- private applyIncomingUpdates;
120
- private maybeApplyIncomingUpdate;
121
- private refreshQueryMapping;
122
- private destruct;
123
- private stopDeleteExpiredTimestampsJob;
124
- /**
125
- * Removes entries from the docToTimestamp map for all the documents that are no longer relevant for this client.
126
- * If a document is currently tracked, we forget it.
127
- * Cases a document is considered not relevant anymore:
128
- * 1 - There are no outgoing or incoming updates for this document AND:
129
- * a - The document was deleted on the server and this client already received a notification about it OR
130
- * b - The document no longer has a query that will keep it up-to-date
131
- */
132
- private startDeleteExpiredTimestampsJob;
133
- /**
134
- * Whether the document is tracked by any pending mutations or ongoing queries.
135
- */
136
- isTracked(squidDocId: string): boolean;
137
- /**
138
- * Whether a document exists locally, but is no longer tracked by any mutations or queries. This is often the case
139
- * for in-memory DocumentReferences that are not part of any query.
140
- */
141
- isForgotten(squidDocId: SquidDocId): boolean;
142
- /**
143
- * Whether a document only exists locally. This means that the document has never by sent to or received from the
144
- * server.
145
- */
146
- isLocalOnly(squidDocId: SquidDocId): boolean;
147
- /**
148
- * Whether the document has even been acknowledged by the server. Acknowledgements occur when an incoming query or
149
- * mutation is received, and when an outgoing mutation is acknowledged.
150
- */
151
- hasBeenAcknowledged(squidDocId: SquidDocId): boolean;
152
- /**
153
- * Updates the document with the new properties, returns true if an update was done or false in case the doc did not
154
- * change.
155
- */
156
- private updateDocumentFromSnapshot;
157
- private finishTransaction;
158
- private sendAllUnsentOutgoingMutations;
159
- private sendMutationsForIntegration;
160
- private removeOutgoingMutation;
161
- private resyncFailedUpdates;
162
- private refreshUpdatedDocuments;
163
- private groupOutgoingMutationsByIntegrationId;
164
- /**
165
- * Handles the case that due to some change (an incoming or outgoing change to a document), a document becomes orphan.
166
- * That is, there are no ongoing queries that will keep it up-to-date.
167
- * An orphan document should not stay locally since it may be stale after some time.
168
- */
169
- private handleOrphanDocs;
170
- private acknowledgeDocument;
171
- private setExpiration;
172
- private forgetDocument;
173
- private migrateDocIds;
174
- private hasPendingSentMutations;
175
- }
@@ -1,12 +1 @@
1
- import { Observable } from 'rxjs';
2
- import { DestructManager } from './destruct.manager';
3
- import { DocumentStore } from './document-store';
4
- import { IdResolutionMap } from '../../internal-common/src/types/mutation.types';
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
+ export {};
@@ -1,13 +1 @@
1
- import { SquidDocId } from './public-types';
2
- import { DataManager } from './data.manager';
3
- import DocumentIdentityService from './document-identity.service';
4
- import { DocumentReference } from './document-reference';
5
- import { QueryBuilderFactory } from './query/query-builder.factory';
6
- export declare class DocumentReferenceFactory {
7
- private readonly documentIdentityService;
8
- private dataManager;
9
- constructor(documentIdentityService: DocumentIdentityService);
10
- create(squidDocId: SquidDocId, queryBuilderFactory: QueryBuilderFactory): DocumentReference;
11
- setDataManager(dataManager: DataManager): void;
12
- private getCollectionKey;
13
- }
1
+ export {};
@@ -1,12 +1 @@
1
- import { RpcManager } from '../rpc.manager';
2
- import { QuerySender } from '../query/query-sender';
3
- import { LockManager } from '../../../internal-common/src/utils/lock.manager';
4
- import { IntegrationId, Mutation } from '../public-types';
5
- import { MutateResponse } from '../../../internal-common/src/types/mutation.types';
6
- export declare class MutationSender {
7
- private readonly rpcManager;
8
- private readonly lockManager;
9
- private readonly querySender;
10
- constructor(rpcManager: RpcManager, lockManager: LockManager, querySender: QuerySender);
11
- sendMutations(mutations: Array<Mutation>, integrationId: IntegrationId): Promise<MutateResponse>;
12
- }
1
+ export {};
@@ -1,9 +1 @@
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
+ export {};
@@ -1,34 +1 @@
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
+ export {};
@@ -1,133 +1,2 @@
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
1
  export declare const FETCH_BEYOND_LIMIT = 100;
13
2
  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,44 +1 @@
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
- }
1
+ export {};
@@ -1,2 +1,6 @@
1
1
  /** A transactionId - alias for string */
2
2
  export type TransactionId = string;
3
+ export interface BlobAndFilename {
4
+ blob: Blob;
5
+ name: string;
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.167",
3
+ "version": "1.0.169",
4
4
  "description": "A typescript implementation of the Squid client",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/typescript-client/src/index.d.ts",
@@ -14,6 +14,8 @@
14
14
  "build:prod": "webpack --mode=production",
15
15
  "watch": "webpack --watch",
16
16
  "lint": "eslint . --ext .ts",
17
+ "build-and-check-public-types": "npm run prebuild && npm run build && npm run check-public-types",
18
+ "check-public-types": "tsc -p tsconfig.types.json",
17
19
  "test": "jest --detectOpenHandles",
18
20
  "test:watch": "jest --watch",
19
21
  "test:cov": "jest --coverage",