@squidcloud/client 1.0.4 → 1.0.6

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,3 +1,10 @@
1
+ /*!
2
+ * The buffer module from node.js, for the browser.
3
+ *
4
+ * @author Feross Aboukhadijeh <https://feross.org>
5
+ * @license MIT
6
+ */
7
+
1
8
  /*! *****************************************************************************
2
9
  Copyright (c) Microsoft Corporation.
3
10
 
@@ -13,6 +20,8 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
20
  PERFORMANCE OF THIS SOFTWARE.
14
21
  ***************************************************************************** */
15
22
 
23
+ /*! https://mths.be/punycode v1.3.2 by @mathias */
24
+
16
25
  /**
17
26
  * @license
18
27
  * Lodash <https://lodash.com/>
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "A typescript implementation of the Squid client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/typescript-client/src/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
22
22
  "test:e2e": "jest --config ./test/jest-e2e.json",
23
23
  "prepublish": "npm run build",
24
- "publish": "npm publish --access public"
24
+ "publish:npm": "npm publish --access public"
25
25
  },
26
26
  "keywords": [
27
27
  "typescript",
@@ -31,6 +31,11 @@
31
31
  "realtime",
32
32
  "database"
33
33
  ],
34
+ "browser": {
35
+ "fs": false,
36
+ "path": false,
37
+ "os": false
38
+ },
34
39
  "author": "",
35
40
  "license": "ISC",
36
41
  "dependencies": {
@@ -1,4 +1,4 @@
1
- import { DocId, DocIdObj, IntegrationId, UserFacingDocType } from '@squidcloud/common';
1
+ import { DocId, DocIdObj, IdResolutionMap, IntegrationId, UserFacingDocType } from '@squidcloud/common';
2
2
  import { DocumentReference } from './document-reference';
3
3
  import { DocumentReferenceFactory } from './document-reference.factory';
4
4
  import { QueryBuilder, QueryBuilderFactory } from './query/query-builder.factory';
@@ -10,7 +10,8 @@ export declare class CollectionReference<T extends UserFacingDocType> {
10
10
  private readonly queryBuilderFactory;
11
11
  private readonly documents;
12
12
  constructor(collectionName: string, integrationId: IntegrationId, documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory);
13
- doc(docId: DocId | DocIdObj): DocumentReference<T>;
13
+ doc(docId?: DocId | DocIdObj): DocumentReference<T>;
14
14
  query(): Omit<QueryBuilder<T, any, Record<Alias, DocumentReference<T>>, false>, 'join'>;
15
15
  joinQuery<A extends Alias>(alias: A): QueryBuilder<T, A, Record<A, DocumentReference<T>>, true>;
16
+ migrateDocIds(idResolutionMap: IdResolutionMap): void;
16
17
  }
@@ -1,11 +1,14 @@
1
1
  import { CollectionName, IntegrationId, UserFacingDocType } from '@squidcloud/common';
2
2
  import { CollectionReference } from './collection-reference';
3
+ import DocumentIdentityService from './document-identity.service';
3
4
  import { DocumentReferenceFactory } from './document-reference.factory';
4
5
  import { QueryBuilderFactory } from './query/query-builder.factory';
5
6
  export declare class CollectionReferenceFactory {
6
7
  private readonly documentReferenceFactory;
7
8
  private readonly queryBuilderFactory;
9
+ private readonly documentIdentityService;
8
10
  private readonly collections;
9
- constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory);
11
+ constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, documentIdentityService: DocumentIdentityService);
10
12
  get<T extends UserFacingDocType>(collectionName: CollectionName, integrationId: IntegrationId): CollectionReference<T>;
13
+ private migrateDocIds;
11
14
  }
@@ -1,11 +1,16 @@
1
- import { DocType, FullDocIdStr, LockManager, Mutation } from '@squidcloud/common';
1
+ import { DocTimestamp, DocType, FullDocIdStr, LockManager, Mutation } from '@squidcloud/common';
2
2
  import { DbDao } from './db.dao';
3
3
  import { DestructManager } from './destruct.manager';
4
+ import DocumentIdentityService from './document-identity.service';
4
5
  import { MutationSender } from './mutation/mutation-sender';
5
6
  import { QueryBuilderFactory } from './query/query-builder.factory';
6
7
  import { QuerySubscriptionManager } from './query/query-subscription.manager';
7
8
  import { SocketManagerInterface } from './socket.manager';
8
9
  import { TransactionId } from './types';
10
+ export interface DocTimestampMetadata {
11
+ timestamp: DocTimestamp;
12
+ expireTimestamp: number | undefined;
13
+ }
9
14
  export declare class DataManager {
10
15
  private readonly dbDao;
11
16
  private readonly mutationSender;
@@ -14,6 +19,7 @@ export declare class DataManager {
14
19
  private readonly queryBuilderFactory;
15
20
  private readonly lockManager;
16
21
  private readonly destructManager;
22
+ private readonly documentIdentityService;
17
23
  private readonly fullDocIdToLocalTimestamp;
18
24
  private currentTransactionId;
19
25
  /**
@@ -74,7 +80,7 @@ export declare class DataManager {
74
80
  private readonly docsToResync;
75
81
  private deleteExpiredTimestampsInterval;
76
82
  private handleIncomingMessages;
77
- constructor(dbDao: DbDao, mutationSender: MutationSender, socketManager: SocketManagerInterface, querySubscriptionManager: QuerySubscriptionManager, queryBuilderFactory: QueryBuilderFactory, lockManager: LockManager, destructManager: DestructManager);
83
+ constructor(dbDao: DbDao, mutationSender: MutationSender, socketManager: SocketManagerInterface, querySubscriptionManager: QuerySubscriptionManager, queryBuilderFactory: QueryBuilderFactory, lockManager: LockManager, destructManager: DestructManager, documentIdentityService: DocumentIdentityService);
78
84
  getProperties(fullDocIdStr: FullDocIdStr): DocType | undefined;
79
85
  isDirty(fullDocIdStr: FullDocIdStr): boolean;
80
86
  /**
@@ -137,4 +143,5 @@ export declare class DataManager {
137
143
  */
138
144
  private handleOrphanDocs;
139
145
  private removeDocumentLocally;
146
+ private migrateDocIds;
140
147
  }
@@ -17,4 +17,5 @@ export declare class DbDao {
17
17
  private getDbIdToDocForCollection;
18
18
  /** Converts multiple == conditions to $in, and multiple != conditions to $nin */
19
19
  private applyEqualityConditions;
20
+ migrateDocId(fullDocIdStr: FullDocIdStr, newFullDocIdStr: FullDocIdStr): void;
20
21
  }
@@ -0,0 +1,12 @@
1
+ import { IdResolutionMap } from '@squidcloud/common';
2
+ import { Observable } from 'rxjs';
3
+ import { DbDao } from './db.dao';
4
+ import { DestructManager } from './destruct.manager';
5
+ export default class DocumentIdentityService {
6
+ private readonly dbDao;
7
+ private readonly destructManager;
8
+ private readonly changeNotifier;
9
+ constructor(dbDao: DbDao, destructManager: DestructManager);
10
+ migrate(idResolutionMap: IdResolutionMap): void;
11
+ observeChanges(): Observable<IdResolutionMap>;
12
+ }
@@ -1,12 +1,13 @@
1
- import { FullDocIdStr, Paths, UserFacingDocType } from '@squidcloud/common';
1
+ import { FullDocIdStr, IdResolutionMap, Paths, UserFacingDocType } from '@squidcloud/common';
2
2
  import { DataManager } from './data.manager';
3
3
  import { QueryBuilderFactory } from './query/query-builder.factory';
4
4
  import { TransactionId } from './types';
5
5
  export declare class DocumentReference<T extends UserFacingDocType = any> {
6
- readonly fullDocId: FullDocIdStr;
6
+ private _fullDocId;
7
7
  private readonly dataManager;
8
8
  private readonly queryBuilderFactory;
9
- constructor(fullDocId: FullDocIdStr, dataManager: DataManager, queryBuilderFactory: QueryBuilderFactory);
9
+ constructor(_fullDocId: FullDocIdStr, dataManager: DataManager, queryBuilderFactory: QueryBuilderFactory);
10
+ get fullDocId(): FullDocIdStr;
10
11
  data(): T;
11
12
  get(): Promise<DocumentReference<T> | undefined>;
12
13
  isDirty(): boolean;
@@ -15,4 +16,5 @@ export declare class DocumentReference<T extends UserFacingDocType = any> {
15
16
  deleteInPath(path: Paths<T>, transactionId?: TransactionId): Promise<void>;
16
17
  insert(data: T, transactionId?: TransactionId): Promise<void>;
17
18
  delete(transactionId?: TransactionId): Promise<void>;
19
+ migrateDocIds(idResolutionMap: IdResolutionMap): void;
18
20
  }
@@ -1,11 +1,11 @@
1
- import { ClientId, DocTimestamp, IntegrationId, LockManager, Mutation } from '@squidcloud/common';
2
- import { RpcManager } from '../rpc.manager';
1
+ import { ClientId, IntegrationId, LockManager, MutateResponse, Mutation } from '@squidcloud/common';
3
2
  import { QuerySubscriptionManager } from '../query/query-subscription.manager';
3
+ import { RpcManager } from '../rpc.manager';
4
4
  export declare class MutationSender {
5
5
  private readonly clientId;
6
6
  private readonly rpcManager;
7
7
  private readonly lockManager;
8
8
  private readonly querySubscriptionManager;
9
9
  constructor(clientId: ClientId, rpcManager: RpcManager, lockManager: LockManager, querySubscriptionManager: QuerySubscriptionManager);
10
- sendMutations(mutations: Array<Mutation>, integrationId: IntegrationId): Promise<DocTimestamp>;
10
+ sendMutations(mutations: Array<Mutation>, integrationId: IntegrationId): Promise<MutateResponse>;
11
11
  }
@@ -1,5 +1,6 @@
1
1
  import { CollectionName, FieldName, FullDocIdStr, IntegrationId, Operator, PrimitiveFieldType, Query, UserFacingDocType } from '@squidcloud/common';
2
2
  import { Observable } from 'rxjs';
3
+ import DocumentIdentityService from '../document-identity.service';
3
4
  import { DocumentReference } from '../document-reference';
4
5
  import { DocumentReferenceFactory } from '../document-reference.factory';
5
6
  import { QuerySubscriptionManager } from './query-subscription.manager';
@@ -7,7 +8,8 @@ import { Alias } from './query.types';
7
8
  export declare class QueryBuilderFactory {
8
9
  private readonly querySubscriptionManager;
9
10
  private readonly documentReferenceFactory;
10
- constructor(querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory);
11
+ private readonly documentIdentityService;
12
+ constructor(querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, documentIdentityService: DocumentIdentityService);
11
13
  getForDocument<MyDocType extends UserFacingDocType, ReturnType extends Record<Alias, DocumentReference<MyDocType>>>(fullDocId: FullDocIdStr): Omit<QueryBuilder<MyDocType, any, ReturnType, false>, 'join'>;
12
14
  get<MyDocType extends UserFacingDocType, ReturnType extends Record<Alias, DocumentReference<MyDocType>>>(collectionName: CollectionName, integrationId: IntegrationId): Omit<QueryBuilder<MyDocType, any, ReturnType, false>, 'join'>;
13
15
  getForJoin<MyDocType extends UserFacingDocType, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<MyDocType>>>(collectionName: CollectionName, integrationId: IntegrationId, alias: MyAlias): QueryBuilder<MyDocType, MyAlias, ReturnType, true>;
@@ -20,11 +22,12 @@ export declare class QueryBuilder<MyDocType extends UserFacingDocType, MyAlias e
20
22
  private readonly alias;
21
23
  private readonly supportsJoin;
22
24
  private readonly queryBuilderFactory;
25
+ private readonly documentIdentityService;
23
26
  private readonly simpleQueryBuilder;
24
27
  private readonly joins;
25
28
  /** Record that maps the right alias to the left condition */
26
29
  private readonly joinConditions;
27
- constructor(collectionName: CollectionName, integrationId: IntegrationId, querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, alias: MyAlias, supportsJoin: SupportsJoin, queryBuilderFactory: QueryBuilderFactory);
30
+ constructor(collectionName: CollectionName, integrationId: IntegrationId, querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, alias: MyAlias, supportsJoin: SupportsJoin, queryBuilderFactory: QueryBuilderFactory, documentIdentityService: DocumentIdentityService);
28
31
  where(fieldName: (keyof MyDocType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): SupportsJoin extends true ? this : Omit<this, 'join'>;
29
32
  limit(limit: number): SupportsJoin extends true ? this : Omit<this, 'join'>;
30
33
  sortBy(fieldName: keyof MyDocType & FieldName, asc?: boolean): SupportsJoin extends true ? this : Omit<this, 'join'>;
@@ -2,6 +2,7 @@ import { ClientId, ClientRequestId, DocType, FullDocIdStr, Query, QuerySubscript
2
2
  import { BehaviorSubject, Observable, Subject } from 'rxjs';
3
3
  import { DbDao } from '../db.dao';
4
4
  import { DestructManager } from '../destruct.manager';
5
+ import DocumentIdentityService from '../document-identity.service';
5
6
  import { RpcManager } from '../rpc.manager';
6
7
  import { Alias, JoinCondition } from './query.types';
7
8
  export declare class QuerySubscriptionManager {
@@ -9,6 +10,7 @@ export declare class QuerySubscriptionManager {
9
10
  private readonly clientId;
10
11
  private readonly dbDao;
11
12
  private readonly destructManager;
13
+ private readonly documentIdentityService;
12
14
  readonly safeToSendQueriesToServer: BehaviorSubject<boolean>;
13
15
  onOrphanDocuments: Subject<string[]>;
14
16
  private readonly ongoingQueries;
@@ -20,7 +22,7 @@ export declare class QuerySubscriptionManager {
20
22
  private readonly clientRequestIdToLocalDocuments;
21
23
  private readonly localDocumentToClientRequestIds;
22
24
  private readonly queryMappingManager;
23
- constructor(rpcManager: RpcManager, clientId: ClientId, dbDao: DbDao, destructManager: DestructManager);
25
+ constructor(rpcManager: RpcManager, clientId: ClientId, dbDao: DbDao, destructManager: DestructManager, documentIdentityService: DocumentIdentityService);
24
26
  hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
25
27
  getQuery(clientRequestId: ClientRequestId): Query;
26
28
  setGotResponseFromServer(clientRequestId: ClientRequestId): void;
@@ -52,4 +54,5 @@ export declare class QuerySubscriptionManager {
52
54
  hasSubscription(clientRequestId: ClientRequestId): boolean;
53
55
  /** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
54
56
  private sendQueryToServer;
57
+ private migrateDocIds;
55
58
  }
@@ -1,7 +1,7 @@
1
1
  import { ApiEndpointId, ApiKey, AppId, CollectionName, IntegrationId, QueryName, UserFacingDocType } from '@squidcloud/common';
2
2
  import { CollectionReference } from './collection-reference';
3
- import { TransactionId } from './types';
4
3
  import { GraphQLClient } from './graphql-client';
4
+ import { TransactionId } from './types';
5
5
  export interface SquidOptions {
6
6
  messageNotificationWrapper?: (fn: () => any) => any;
7
7
  appId: AppId;
@@ -26,6 +26,7 @@ export declare class Squid {
26
26
  private readonly apiManager;
27
27
  private readonly graphqlClientFactory;
28
28
  private readonly destructManager;
29
+ private readonly documentIdentityService;
29
30
  private static readonly squidInstancesMap;
30
31
  constructor(options: SquidOptions);
31
32
  /**
@@ -5,6 +5,7 @@ import { CollectionReferenceFactory } from '../collection-reference.factory';
5
5
  import { DataManager } from '../data.manager';
6
6
  import { DbDao } from '../db.dao';
7
7
  import { DestructManager } from '../destruct.manager';
8
+ import DocumentIdentityService from '../document-identity.service';
8
9
  import { DocumentReferenceFactory } from '../document-reference.factory';
9
10
  import { MutationSender } from '../mutation/mutation-sender';
10
11
  import { QueryBuilderFactory } from '../query/query-builder.factory';
@@ -50,6 +51,7 @@ export declare class SquidEnvSetup {
50
51
  readonly dataManager: DataManager;
51
52
  readonly clientId = "fakeClientId";
52
53
  readonly destructManager: DestructManager;
54
+ readonly documentIdentityService: DocumentIdentityService;
53
55
  readonly collectionA: CollectionReference<TestDocTypeA>;
54
56
  readonly collectionB: CollectionReference<TestDocTypeB>;
55
57
  constructor();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A typescript implementation of the Squid client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/typescript-client/src/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
22
22
  "test:e2e": "jest --config ./test/jest-e2e.json",
23
23
  "prepublish": "npm run build",
24
- "publish": "npm publish --access public"
24
+ "publish:npm": "npm publish --access public"
25
25
  },
26
26
  "keywords": [
27
27
  "typescript",
@@ -31,6 +31,11 @@
31
31
  "realtime",
32
32
  "database"
33
33
  ],
34
+ "browser": {
35
+ "fs": false,
36
+ "path": false,
37
+ "os": false
38
+ },
34
39
  "author": "",
35
40
  "license": "ISC",
36
41
  "dependencies": {
@@ -40,7 +45,12 @@
40
45
  "lodash": "^4.17.21",
41
46
  "lokijs": "^1.5.12",
42
47
  "rxjs": "7.5.7",
43
- "socket.io-client": "^4.5.2"
48
+ "socket.io-client": "^4.5.2",
49
+ "browserify-zlib": "^0.2.0",
50
+ "stream-browserify": "^3.0.0",
51
+ "https-browserify": "^1.0.0",
52
+ "stream-http": "^3.2.0",
53
+ "tty-browserify": "^0.0.1"
44
54
  },
45
55
  "devDependencies": {
46
56
  "cpx": "^1.5.0",