@squidcloud/client 1.0.10 → 1.0.11
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/common/src/api-call.context.d.ts +17 -0
- package/dist/common/src/backend-run.types.d.ts +60 -0
- package/dist/common/src/bundle-api.types.d.ts +21 -41
- package/dist/common/src/context.types.d.ts +0 -1
- package/dist/common/src/document.types.d.ts +8 -8
- package/dist/common/src/executable.context.d.ts +4 -0
- package/dist/common/src/graphql.context.d.ts +14 -0
- package/dist/common/src/index.d.ts +14 -7
- package/dist/common/src/metrics.types.d.ts +55 -42
- package/dist/common/src/mutation.context.d.ts +1 -4
- package/dist/common/src/mutation.types.d.ts +5 -5
- package/dist/common/src/named-query.context.d.ts +4 -0
- package/dist/common/src/query/query-context.d.ts +1 -4
- package/dist/common/src/query/simple-query-builder.d.ts +2 -2
- package/dist/common/src/query.types.d.ts +4 -4
- package/dist/common/src/regions.d.ts +4 -0
- package/dist/common/src/schema/schema.types.d.ts +10 -1
- package/dist/common/src/secret.types.d.ts +9 -1
- package/dist/common/src/socket.types.d.ts +4 -4
- package/dist/common/src/trigger.types.d.ts +4 -6
- package/dist/common/src/utils/assert.d.ts +2 -0
- package/dist/common/src/utils/object.d.ts +3 -3
- package/dist/common/src/utils/serialization.d.ts +1 -0
- package/dist/common/src/utils/transforms.d.ts +17 -0
- package/dist/common/src/utils/url.d.ts +2 -1
- package/dist/index.js +6 -6
- package/dist/package.json +1 -3
- package/dist/typescript-client/src/collection-reference.d.ts +2 -2
- package/dist/typescript-client/src/collection-reference.factory.d.ts +2 -2
- package/dist/typescript-client/src/data.manager.d.ts +33 -21
- package/dist/typescript-client/src/destruct.manager.d.ts +3 -1
- package/dist/typescript-client/src/document-identity.service.d.ts +3 -3
- package/dist/typescript-client/src/document-reference.d.ts +5 -5
- package/dist/typescript-client/src/document-reference.factory.d.ts +2 -2
- package/dist/typescript-client/src/document-store.d.ts +11 -0
- package/dist/typescript-client/src/query/query-builder.factory.d.ts +15 -15
- package/dist/typescript-client/src/query/query-subscription.manager.d.ts +11 -11
- package/dist/typescript-client/src/squid.d.ts +4 -4
- package/dist/typescript-client/src/testing/squid-env-setup.d.ts +8 -7
- package/package.json +2 -4
- package/dist/typescript-client/src/db.dao.d.ts +0 -22
package/dist/package.json
CHANGED
|
@@ -37,18 +37,16 @@
|
|
|
37
37
|
"@supercharge/promise-pool": "^2.3.2",
|
|
38
38
|
"cross-fetch": "^3.1.5",
|
|
39
39
|
"lodash": "^4.17.21",
|
|
40
|
-
"lokijs": "^1.5.12",
|
|
41
40
|
"rxjs": "7.5.7",
|
|
42
41
|
"socket.io-client": "^4.5.2"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"cpx": "^1.5.0",
|
|
46
44
|
"@types/lodash": "^4.14.186",
|
|
47
|
-
"@types/lokijs": "^1.5.7",
|
|
48
45
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
49
46
|
"@typescript-eslint/parser": "^5.0.0",
|
|
50
47
|
"@webpack-cli/generators": "^3.0.0",
|
|
51
48
|
"copy-webpack-plugin": "^11.0.0",
|
|
49
|
+
"cpx": "^1.5.0",
|
|
52
50
|
"eslint": "8.22.0",
|
|
53
51
|
"eslint-config-prettier": "^8.3.0",
|
|
54
52
|
"eslint-plugin-prettier": "^4.0.0",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { DocId, DocIdObj, IdResolutionMap, IntegrationId
|
|
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
4
|
import { QueryBuilder, QueryBuilderFactory } from './query/query-builder.factory';
|
|
5
5
|
import { Alias } from './query/query.types';
|
|
6
|
-
export declare class CollectionReference<T extends
|
|
6
|
+
export declare class CollectionReference<T extends DocumentData> {
|
|
7
7
|
private readonly collectionName;
|
|
8
8
|
private integrationId;
|
|
9
9
|
private readonly documentReferenceFactory;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CollectionName,
|
|
1
|
+
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';
|
|
@@ -9,6 +9,6 @@ export declare class CollectionReferenceFactory {
|
|
|
9
9
|
private readonly documentIdentityService;
|
|
10
10
|
private readonly collections;
|
|
11
11
|
constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, documentIdentityService: DocumentIdentityService);
|
|
12
|
-
get<T extends
|
|
12
|
+
get<T extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): CollectionReference<T>;
|
|
13
13
|
private migrateDocIds;
|
|
14
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DocTimestamp,
|
|
2
|
-
import { DbDao } from './db.dao';
|
|
1
|
+
import { DocTimestamp, LockManager, Mutation, SquidDocId, SquidDocument } from '@squidcloud/common';
|
|
3
2
|
import { DestructManager } from './destruct.manager';
|
|
4
3
|
import DocumentIdentityService from './document-identity.service';
|
|
4
|
+
import { DocumentStore } from './document-store';
|
|
5
5
|
import { MutationSender } from './mutation/mutation-sender';
|
|
6
6
|
import { QueryBuilderFactory } from './query/query-builder.factory';
|
|
7
7
|
import { QuerySubscriptionManager } from './query/query-subscription.manager';
|
|
@@ -9,10 +9,10 @@ import { SocketManagerInterface } from './socket.manager';
|
|
|
9
9
|
import { TransactionId } from './types';
|
|
10
10
|
export interface DocTimestampMetadata {
|
|
11
11
|
timestamp: DocTimestamp;
|
|
12
|
-
expireTimestamp
|
|
12
|
+
expireTimestamp?: number;
|
|
13
13
|
}
|
|
14
14
|
export declare class DataManager {
|
|
15
|
-
private readonly
|
|
15
|
+
private readonly documentStore;
|
|
16
16
|
private readonly mutationSender;
|
|
17
17
|
private readonly socketManager;
|
|
18
18
|
private readonly querySubscriptionManager;
|
|
@@ -20,7 +20,7 @@ export declare class DataManager {
|
|
|
20
20
|
private readonly lockManager;
|
|
21
21
|
private readonly destructManager;
|
|
22
22
|
private readonly documentIdentityService;
|
|
23
|
-
private readonly
|
|
23
|
+
private readonly docIdToLocalTimestamp;
|
|
24
24
|
private currentTransactionId;
|
|
25
25
|
/**
|
|
26
26
|
* During a batch, any update to a document that may trigger an update to a query is collected here and once the batch
|
|
@@ -37,7 +37,7 @@ export declare class DataManager {
|
|
|
37
37
|
* Eventually, this map is used as a gatekeeper for preventing old versions of a document (based on timestamp) to
|
|
38
38
|
* appear on the client.
|
|
39
39
|
*/
|
|
40
|
-
private readonly
|
|
40
|
+
private readonly docIdToServerTimestamp;
|
|
41
41
|
/**
|
|
42
42
|
* In the case of a local change (outgoing change) without a server timestamp, an incoming server update cannot be
|
|
43
43
|
* applied and needs to be queued until the local state allows it. In this case the incoming update will be queued in
|
|
@@ -59,7 +59,7 @@ export declare class DataManager {
|
|
|
59
59
|
* cannot accept the server change and will wait for another update from the server. For this purpose, timestamp
|
|
60
60
|
* will be stored in docsToTimestamp for ~20 more seconds.
|
|
61
61
|
*
|
|
62
|
-
* Note: Only one entry per
|
|
62
|
+
* Note: Only one entry per squidDocId can be with sentToServer=false. This is true since all updates to the same doc
|
|
63
63
|
* in the same batch are appended (and reduced) to the same outgoing mutation object.
|
|
64
64
|
*/
|
|
65
65
|
private readonly pendingOutgoingMutations;
|
|
@@ -79,13 +79,11 @@ export declare class DataManager {
|
|
|
79
79
|
private readonly outgoingMutationsEmpty;
|
|
80
80
|
private readonly docsToResync;
|
|
81
81
|
private deleteExpiredTimestampsInterval;
|
|
82
|
-
private
|
|
83
|
-
constructor(
|
|
84
|
-
getProperties(
|
|
82
|
+
private handleIncomingMessagesForTests;
|
|
83
|
+
constructor(documentStore: DocumentStore, mutationSender: MutationSender, socketManager: SocketManagerInterface, querySubscriptionManager: QuerySubscriptionManager, queryBuilderFactory: QueryBuilderFactory, lockManager: LockManager, destructManager: DestructManager, documentIdentityService: DocumentIdentityService);
|
|
84
|
+
getProperties(squidDocId: SquidDocId): SquidDocument | undefined;
|
|
85
85
|
/** Whether a document has changes that are out of sync with the server. */
|
|
86
|
-
isDirty(
|
|
87
|
-
/** Whether the document is tracked by any ongoing queries or outgoing mutations. */
|
|
88
|
-
isTracked(fullDocIdStr: FullDocIdStr): boolean;
|
|
86
|
+
isDirty(squidDocId: SquidDocId): boolean;
|
|
89
87
|
/**
|
|
90
88
|
* Runs the provided function without sending mutations to the server while collecting the updates to the different
|
|
91
89
|
* queries. Local updates will still be applied. Once the batch finishes, all the updates will be sent to the server
|
|
@@ -114,7 +112,7 @@ export declare class DataManager {
|
|
|
114
112
|
private stopDeleteExpiredTimestampsJob;
|
|
115
113
|
/**
|
|
116
114
|
* Removes entries from the docToTimestamp map for all the documents that are no longer relevant for this client.
|
|
117
|
-
* If a document
|
|
115
|
+
* If a document is currently tracked, we forget it.
|
|
118
116
|
* Cases a document is considered not relevant anymore:
|
|
119
117
|
* 1 - There are no outgoing or incoming updates for this document AND:
|
|
120
118
|
* a - The document was deleted on the server and this client already received a notification about it OR
|
|
@@ -122,17 +120,29 @@ export declare class DataManager {
|
|
|
122
120
|
*/
|
|
123
121
|
private startDeleteExpiredTimestampsJob;
|
|
124
122
|
/**
|
|
125
|
-
*
|
|
126
|
-
* 1 - It has no pending incoming mutations
|
|
127
|
-
* 2 - All the outgoing mutations already have timestamp
|
|
128
|
-
* 3 - The document is orphan - there is no outgoing query for it
|
|
123
|
+
* Whether the document is tracked by any pending mutations or ongoing queries.
|
|
129
124
|
*/
|
|
130
|
-
|
|
125
|
+
isTracked(squidDocId: string): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Whether a document exists locally, but is no longer tracked by any mutations or queries. This is often the case
|
|
128
|
+
* for in-memory DocumentReferences that are not part of any query.
|
|
129
|
+
*/
|
|
130
|
+
isForgotten(squidDocId: SquidDocId): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Whether a document only exists locally. This means that the document has never by sent to or received from the
|
|
133
|
+
* server.
|
|
134
|
+
*/
|
|
135
|
+
isLocalOnly(squidDocId: SquidDocId): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Whether the document has even been acknowledged by the server. Acknowledgements occur when an incoming query or
|
|
138
|
+
* mutation is received, and when an outgoing mutation is acknowledged.
|
|
139
|
+
*/
|
|
140
|
+
hasBeenAcknowledged(squidDocId: SquidDocId): boolean;
|
|
131
141
|
/**
|
|
132
142
|
* Updates the document with the new properties, returns true if an update was done or false in case the doc did not
|
|
133
143
|
* change.
|
|
134
144
|
*/
|
|
135
|
-
private
|
|
145
|
+
private updateDocumentFromSnapshot;
|
|
136
146
|
private finishTransaction;
|
|
137
147
|
private sendAllUnsentOutgoingMutations;
|
|
138
148
|
private sendMutationsForIntegration;
|
|
@@ -145,6 +155,8 @@ export declare class DataManager {
|
|
|
145
155
|
* An orphan document should not stay locally since it may be stale after some time.
|
|
146
156
|
*/
|
|
147
157
|
private handleOrphanDocs;
|
|
148
|
-
private
|
|
158
|
+
private acknowledgeDocument;
|
|
159
|
+
private setExpiration;
|
|
160
|
+
private forgetDocument;
|
|
149
161
|
private migrateDocIds;
|
|
150
162
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export type DestructorFn = () => Promise<void> | void;
|
|
2
2
|
export declare class DestructManager {
|
|
3
|
+
private readonly predestructors;
|
|
3
4
|
private readonly destructors;
|
|
4
5
|
private isDestructed;
|
|
5
|
-
|
|
6
|
+
onPreDestruct(fn: DestructorFn): void;
|
|
7
|
+
onDestruct(fn: DestructorFn): void;
|
|
6
8
|
destruct(): Promise<void>;
|
|
7
9
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { IdResolutionMap } from '@squidcloud/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { DbDao } from './db.dao';
|
|
4
3
|
import { DestructManager } from './destruct.manager';
|
|
4
|
+
import { DocumentStore } from './document-store';
|
|
5
5
|
export default class DocumentIdentityService {
|
|
6
|
-
private readonly
|
|
6
|
+
private readonly documentStore;
|
|
7
7
|
private readonly destructManager;
|
|
8
8
|
private readonly changeNotifier;
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(documentStore: DocumentStore, destructManager: DestructManager);
|
|
10
10
|
migrate(idResolutionMap: IdResolutionMap): void;
|
|
11
11
|
observeChanges(): Observable<IdResolutionMap>;
|
|
12
12
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DocumentData, IdResolutionMap, Paths, SquidDocId } 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
|
-
export declare class DocumentReference<T extends
|
|
6
|
-
private
|
|
5
|
+
export declare class DocumentReference<T extends DocumentData = any> {
|
|
6
|
+
private _squidDocId;
|
|
7
7
|
private readonly dataManager;
|
|
8
8
|
private readonly queryBuilderFactory;
|
|
9
|
-
constructor(
|
|
10
|
-
get
|
|
9
|
+
constructor(_squidDocId: SquidDocId, dataManager: DataManager, queryBuilderFactory: QueryBuilderFactory);
|
|
10
|
+
get squidDocId(): SquidDocId;
|
|
11
11
|
data(): T;
|
|
12
12
|
get(): Promise<DocumentReference<T> | undefined>;
|
|
13
13
|
isDirty(): boolean;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SquidDocId } from '@squidcloud/common';
|
|
2
2
|
import { DataManager } from './data.manager';
|
|
3
3
|
import { DocumentReference } from './document-reference';
|
|
4
4
|
import { QueryBuilderFactory } from './query/query-builder.factory';
|
|
5
5
|
export declare class DocumentReferenceFactory {
|
|
6
6
|
private dataManager;
|
|
7
|
-
create(
|
|
7
|
+
create(squidDocId: SquidDocId, queryBuilderFactory: QueryBuilderFactory): DocumentReference;
|
|
8
8
|
setDataManager(dataManager: DataManager): void;
|
|
9
9
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { CollectionName,
|
|
1
|
+
import { CollectionName, DocumentData, FieldName, IntegrationId, Operator, PrimitiveFieldType, Query, SquidDocId } from '@squidcloud/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import DocumentIdentityService from '../document-identity.service';
|
|
4
4
|
import { DocumentReference } from '../document-reference';
|
|
@@ -10,11 +10,11 @@ export declare class QueryBuilderFactory {
|
|
|
10
10
|
private readonly documentReferenceFactory;
|
|
11
11
|
private readonly documentIdentityService;
|
|
12
12
|
constructor(querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, documentIdentityService: DocumentIdentityService);
|
|
13
|
-
getForDocument<
|
|
14
|
-
get<
|
|
15
|
-
getForJoin<
|
|
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>;
|
|
16
16
|
}
|
|
17
|
-
export declare class QueryBuilder<
|
|
17
|
+
export declare class QueryBuilder<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType> | undefined>, SupportsJoin extends boolean> {
|
|
18
18
|
private readonly collectionName;
|
|
19
19
|
private readonly integrationId;
|
|
20
20
|
private readonly querySubscriptionManager;
|
|
@@ -28,17 +28,17 @@ export declare class QueryBuilder<MyDocType extends UserFacingDocType, MyAlias e
|
|
|
28
28
|
/** Record that maps the right alias to the left condition */
|
|
29
29
|
private readonly joinConditions;
|
|
30
30
|
constructor(collectionName: CollectionName, integrationId: IntegrationId, querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, alias: MyAlias, supportsJoin: SupportsJoin, queryBuilderFactory: QueryBuilderFactory, documentIdentityService: DocumentIdentityService);
|
|
31
|
-
where(fieldName: (keyof
|
|
31
|
+
where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): SupportsJoin extends true ? this : Omit<this, 'join'>;
|
|
32
32
|
limit(limit: number): SupportsJoin extends true ? this : Omit<this, 'join'>;
|
|
33
|
-
sortBy(fieldName: keyof
|
|
34
|
-
join<J extends
|
|
35
|
-
snapshot(): SupportsJoin extends true ? Promise<Array<ReturnType>> : Promise<Array<DocumentReference<
|
|
36
|
-
snapshots(subscribe?: boolean): SupportsJoin extends true ? Observable<Array<ReturnType>> : Observable<Array<DocumentReference<
|
|
37
|
-
changes(): Observable<Changes<
|
|
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>>>;
|
|
37
|
+
changes(): Observable<Changes<DocumentType>>;
|
|
38
38
|
build(): Query;
|
|
39
39
|
}
|
|
40
|
-
export interface Changes<
|
|
41
|
-
inserts: Array<DocumentReference<
|
|
42
|
-
updates: Array<DocumentReference<
|
|
43
|
-
deletes: Array<
|
|
40
|
+
export interface Changes<DocumentType extends DocumentData> {
|
|
41
|
+
inserts: Array<DocumentReference<DocumentType>>;
|
|
42
|
+
updates: Array<DocumentReference<DocumentType>>;
|
|
43
|
+
deletes: Array<DocumentType>;
|
|
44
44
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ClientId, ClientRequestId,
|
|
1
|
+
import { ClientId, ClientRequestId, Query, QuerySubscriptionId, SquidDocId, SquidDocument } from '@squidcloud/common';
|
|
2
2
|
import { BehaviorSubject, Observable, Subject } from 'rxjs';
|
|
3
|
-
import { DbDao } from '../db.dao';
|
|
4
3
|
import { DestructManager } from '../destruct.manager';
|
|
5
4
|
import DocumentIdentityService from '../document-identity.service';
|
|
5
|
+
import { DocumentStore } from '../document-store';
|
|
6
6
|
import { RpcManager } from '../rpc.manager';
|
|
7
7
|
import { Alias, JoinCondition } from './query.types';
|
|
8
8
|
export declare class QuerySubscriptionManager {
|
|
9
9
|
private readonly rpcManager;
|
|
10
10
|
private readonly clientId;
|
|
11
|
-
private readonly
|
|
11
|
+
private readonly documentStore;
|
|
12
12
|
private readonly destructManager;
|
|
13
13
|
private readonly documentIdentityService;
|
|
14
14
|
readonly safeToSendQueriesToServer: BehaviorSubject<boolean>;
|
|
@@ -22,22 +22,22 @@ export declare class QuerySubscriptionManager {
|
|
|
22
22
|
private readonly clientRequestIdToLocalDocuments;
|
|
23
23
|
private readonly localDocumentToClientRequestIds;
|
|
24
24
|
private readonly queryMappingManager;
|
|
25
|
-
constructor(rpcManager: RpcManager, clientId: ClientId,
|
|
25
|
+
constructor(rpcManager: RpcManager, clientId: ClientId, documentStore: DocumentStore, destructManager: DestructManager, documentIdentityService: DocumentIdentityService);
|
|
26
26
|
hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
|
|
27
27
|
getQuery(clientRequestId: ClientRequestId): Query;
|
|
28
28
|
setGotResponseFromServer(clientRequestId: ClientRequestId): void;
|
|
29
|
-
findQueriesForDocument(doc:
|
|
29
|
+
findQueriesForDocument(doc: SquidDocument, squidDocId: SquidDocId): Array<QuerySubscriptionId>;
|
|
30
30
|
/**
|
|
31
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 (
|
|
32
|
+
* updates the internal mappings (squidDocId --> client request Ids and, clientRequestId --> squidDocIds).
|
|
33
33
|
* Returns an array with all the previous and current client request ids (basically all the client request ids that
|
|
34
34
|
* will need to be notified due to the change of properties).
|
|
35
35
|
*/
|
|
36
|
-
setClientRequestIdsForLocalDoc(
|
|
37
|
-
errorOutAllQueries(
|
|
36
|
+
setClientRequestIdsForLocalDoc(squidDocId: SquidDocId, properties: SquidDocument | undefined): Array<ClientRequestId>;
|
|
37
|
+
errorOutAllQueries(squidDocId: SquidDocId, err: any): void;
|
|
38
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,
|
|
40
|
-
hasOngoingQueryForDocId(
|
|
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
41
|
private removeClientRequestId;
|
|
42
42
|
waitForAllQueriesToFinish(): Promise<void>;
|
|
43
43
|
private registerQueryFinalizer;
|
|
@@ -50,7 +50,7 @@ export declare class QuerySubscriptionManager {
|
|
|
50
50
|
private updateOngoingQueryWithNewDataFromSupportingQuery;
|
|
51
51
|
private allOngoingQueriesGotServerResult;
|
|
52
52
|
private completeAllSupportedQueries;
|
|
53
|
-
private
|
|
53
|
+
private predestruct;
|
|
54
54
|
hasSubscription(clientRequestId: ClientRequestId): boolean;
|
|
55
55
|
/** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
|
|
56
56
|
private sendQueryToServer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiEndpointId, ApiKey, AppId, CollectionName, IntegrationId, QueryName,
|
|
1
|
+
import { ApiEndpointId, ApiKey, AppId, CollectionName, DocumentData, IntegrationId, QueryName, SquidRegion } from '@squidcloud/common';
|
|
2
2
|
import { CollectionReference } from './collection-reference';
|
|
3
3
|
import { GraphQLClient } from './graphql-client';
|
|
4
4
|
import { TransactionId } from './types';
|
|
@@ -6,7 +6,7 @@ export interface SquidOptions {
|
|
|
6
6
|
messageNotificationWrapper?: (fn: () => any) => any;
|
|
7
7
|
appId: AppId;
|
|
8
8
|
apiKey?: ApiKey;
|
|
9
|
-
|
|
9
|
+
region: SquidRegion;
|
|
10
10
|
apiServerUrlOverrideMapping?: Record<IntegrationId, string>;
|
|
11
11
|
}
|
|
12
12
|
/** Reference to the squid db. Provides all the available actions on the DB. */
|
|
@@ -16,7 +16,7 @@ export declare class Squid {
|
|
|
16
16
|
private readonly rpcManager;
|
|
17
17
|
private readonly dataManager;
|
|
18
18
|
private readonly documentReferenceFactory;
|
|
19
|
-
private readonly
|
|
19
|
+
private readonly documentStore;
|
|
20
20
|
private readonly lockManager;
|
|
21
21
|
private readonly querySubscriptionManager;
|
|
22
22
|
private readonly queryBuilderFactory;
|
|
@@ -39,7 +39,7 @@ export declare class Squid {
|
|
|
39
39
|
* to the security rules.
|
|
40
40
|
*/
|
|
41
41
|
setAuthIdToken(idToken: string | undefined): void;
|
|
42
|
-
collection<T extends
|
|
42
|
+
collection<T extends DocumentData>(collectionName: CollectionName, integrationId?: IntegrationId): CollectionReference<T>;
|
|
43
43
|
runInTransaction(fn: (transactionId: TransactionId) => Promise<void>): Promise<void>;
|
|
44
44
|
executeFunction<T = any>(functionName: string, ...params: any[]): Promise<T>;
|
|
45
45
|
executeNamedQuery<T = any>(integrationId: IntegrationId, queryName: QueryName, params: Record<string, any>): Promise<T>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ClientRequestId, CollectionName, DocId,
|
|
1
|
+
import { ClientRequestId, CollectionName, DocId, IntegrationId, LockManager, MutationType, SquidDocument } from '@squidcloud/common';
|
|
2
2
|
import { Subject, Subscription } from 'rxjs';
|
|
3
3
|
import { CollectionReference } from '../collection-reference';
|
|
4
4
|
import { CollectionReferenceFactory } from '../collection-reference.factory';
|
|
5
5
|
import { DataManager } from '../data.manager';
|
|
6
|
-
import { DbDao } from '../db.dao';
|
|
7
6
|
import { DestructManager } from '../destruct.manager';
|
|
8
7
|
import DocumentIdentityService from '../document-identity.service';
|
|
9
8
|
import { DocumentReferenceFactory } from '../document-reference.factory';
|
|
9
|
+
import { DocumentStore } from '../document-store';
|
|
10
10
|
import { MutationSender } from '../mutation/mutation-sender';
|
|
11
11
|
import { QueryBuilderFactory } from '../query/query-builder.factory';
|
|
12
12
|
import { QuerySubscriptionManager } from '../query/query-subscription.manager';
|
|
@@ -42,7 +42,7 @@ export declare class SquidEnvSetup {
|
|
|
42
42
|
readonly querySubscriptionManager: QuerySubscriptionManager;
|
|
43
43
|
readonly socketManager: FakeSocketManager;
|
|
44
44
|
readonly rpcManager: FakeRpcManager;
|
|
45
|
-
readonly
|
|
45
|
+
readonly documentStore: DocumentStore;
|
|
46
46
|
readonly documentReferenceFactory: DocumentReferenceFactory;
|
|
47
47
|
readonly collectionReferenceFactory: CollectionReferenceFactory;
|
|
48
48
|
readonly queryBuilderFactory: QueryBuilderFactory;
|
|
@@ -55,18 +55,18 @@ export declare class SquidEnvSetup {
|
|
|
55
55
|
readonly collectionA: CollectionReference<TestDocTypeA>;
|
|
56
56
|
readonly collectionB: CollectionReference<TestDocTypeB>;
|
|
57
57
|
constructor();
|
|
58
|
-
simulateQueryResponse(docs: Array<Partial<
|
|
58
|
+
simulateQueryResponse(docs: Array<Partial<SquidDocument>>, collectionName: CollectionName, integrationId?: IntegrationId, clientRequestId?: ClientRequestId): void;
|
|
59
59
|
simulateMutationsResponse(updates: Array<{
|
|
60
60
|
mutationType: MutationType;
|
|
61
61
|
collectionName: CollectionName;
|
|
62
62
|
integrationId?: IntegrationId;
|
|
63
63
|
clientRequestId?: ClientRequestId;
|
|
64
|
-
doc: Partial<
|
|
64
|
+
doc: Partial<SquidDocument> & {
|
|
65
65
|
__docId__: DocId;
|
|
66
66
|
};
|
|
67
|
-
}>, mutationsTimestamp?: number): void
|
|
67
|
+
}>, mutationsTimestamp?: number): Promise<void>;
|
|
68
68
|
simulateErrorResponse(message: string): void;
|
|
69
|
-
runAsync(fn: () => any): void
|
|
69
|
+
runAsync(fn: () => any): Promise<void>;
|
|
70
70
|
getInternalDocId(idValue: string): string;
|
|
71
71
|
executeQueryOnCollectionA(subscribe?: boolean): QueryResponse;
|
|
72
72
|
executeJoinQuery(subscribe?: boolean): JoinQueryResponse;
|
|
@@ -74,3 +74,4 @@ export declare class SquidEnvSetup {
|
|
|
74
74
|
simulateResponseForCollectionB(id: string, b: number): void;
|
|
75
75
|
}
|
|
76
76
|
export declare let squidEnvSetup: SquidEnvSetup;
|
|
77
|
+
export declare function squidEnvSetupBeforeEach(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squidcloud/client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
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",
|
|
@@ -37,18 +37,16 @@
|
|
|
37
37
|
"@supercharge/promise-pool": "^2.3.2",
|
|
38
38
|
"cross-fetch": "^3.1.5",
|
|
39
39
|
"lodash": "^4.17.21",
|
|
40
|
-
"lokijs": "^1.5.12",
|
|
41
40
|
"rxjs": "7.5.7",
|
|
42
41
|
"socket.io-client": "^4.5.2"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"cpx": "^1.5.0",
|
|
46
44
|
"@types/lodash": "^4.14.186",
|
|
47
|
-
"@types/lokijs": "^1.5.7",
|
|
48
45
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
49
46
|
"@typescript-eslint/parser": "^5.0.0",
|
|
50
47
|
"@webpack-cli/generators": "^3.0.0",
|
|
51
48
|
"copy-webpack-plugin": "^11.0.0",
|
|
49
|
+
"cpx": "^1.5.0",
|
|
52
50
|
"eslint": "8.22.0",
|
|
53
51
|
"eslint-config-prettier": "^8.3.0",
|
|
54
52
|
"eslint-plugin-prettier": "^4.0.0",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DocType, FullDocIdStr, Query } from '@squidcloud/common';
|
|
2
|
-
export type DbId = number;
|
|
3
|
-
export declare class DbDao {
|
|
4
|
-
private readonly db;
|
|
5
|
-
private readonly dbIdToDoc;
|
|
6
|
-
private readonly fullDocIdToDbId;
|
|
7
|
-
constructor();
|
|
8
|
-
saveDocument(fullDocIdStr: FullDocIdStr, properties: DocType | undefined): DbId | undefined;
|
|
9
|
-
removeDocumentFromDb(fullDocIdStr: FullDocIdStr): void;
|
|
10
|
-
isInMemory(fullDocIdStr: FullDocIdStr): boolean;
|
|
11
|
-
isInDatabase(fullDocIdStr: FullDocIdStr): boolean;
|
|
12
|
-
getDocumentProperties(fullDocIdStr: FullDocIdStr): DocType;
|
|
13
|
-
getDocumentPropertiesOrUndefined(fullDocIdStr: FullDocIdStr): DocType | undefined;
|
|
14
|
-
executeQuery(query: Query): Array<DocType>;
|
|
15
|
-
private convertToDocType;
|
|
16
|
-
private convertToLokiCondition;
|
|
17
|
-
private getDbCollection;
|
|
18
|
-
private getDbIdToDocForCollection;
|
|
19
|
-
/** Converts multiple == conditions to $in, and multiple != conditions to $nin */
|
|
20
|
-
private applyEqualityConditions;
|
|
21
|
-
migrateDocId(fullDocIdStr: FullDocIdStr, newFullDocIdStr: FullDocIdStr): void;
|
|
22
|
-
}
|