@squidcloud/client 1.0.79 → 1.0.81
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 +5 -5
- package/dist/common/src/query/{simple-query-builder.d.ts → base-query-builder.d.ts} +23 -18
- package/dist/common/src/query/index.d.ts +1 -1
- package/dist/common/src/query/query-context.d.ts +77 -10
- package/dist/esm/index.js +5 -5
- package/dist/typescript-client/src/collection-reference.d.ts +8 -7
- package/dist/typescript-client/src/collection-reference.factory.d.ts +3 -6
- package/dist/typescript-client/src/data.manager.d.ts +1 -1
- package/dist/typescript-client/src/document-reference.factory.d.ts +3 -0
- package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +62 -24
- package/dist/typescript-client/src/query/query-builder.factory.d.ts +14 -39
- package/dist/typescript-client/src/query/query.types.d.ts +2 -2
- package/dist/typescript-client/src/squid.d.ts +0 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DocId, DocIdObj, DocumentData } from '@squidcloud/common';
|
|
2
2
|
import { DocumentReference } from './document-reference';
|
|
3
3
|
import { JoinQueryBuilder } from './query/join-query-builder.factory';
|
|
4
|
-
import {
|
|
4
|
+
import { QueryBuilder } from './query/query-builder.factory';
|
|
5
5
|
import { Alias } from './query/query.types';
|
|
6
6
|
/**
|
|
7
7
|
* Holds a reference to a data collection. a collection reference is a reference to a collection in a database. You
|
|
@@ -18,10 +18,9 @@ export declare class CollectionReference<T extends DocumentData> {
|
|
|
18
18
|
private integrationId;
|
|
19
19
|
private readonly documentReferenceFactory;
|
|
20
20
|
private readonly queryBuilderFactory;
|
|
21
|
-
private readonly
|
|
21
|
+
private readonly querySubscriptionManager;
|
|
22
22
|
/** A string that uniquely identifies this collection reference. */
|
|
23
23
|
refId: string;
|
|
24
|
-
private readonly documents;
|
|
25
24
|
/**
|
|
26
25
|
* Returns a document reference for the given document id.
|
|
27
26
|
* The document id is an object that maps the primary keys of the collection (as defined in the Squid Cloud Console)
|
|
@@ -38,13 +37,15 @@ export declare class CollectionReference<T extends DocumentData> {
|
|
|
38
37
|
* ```typescript
|
|
39
38
|
* // For a collection in the built_in_db that does not have a schema
|
|
40
39
|
* const docRef = collectionRef.doc('my-doc-id');
|
|
40
|
+
* const docRef = collectionRef.doc({id: my-doc-id'});
|
|
41
41
|
*
|
|
42
42
|
* // For a collection with a single primary key field called "id"
|
|
43
43
|
* const docRef = collectionRef.doc({id: 'my-doc-id'});
|
|
44
44
|
*
|
|
45
45
|
* // For a collection with a composite primary key
|
|
46
46
|
* const docRef = collectionRef.doc({id1: 'my-doc-id1', id2: 'my-doc-id2'});
|
|
47
|
-
* const docRef = collectionRef.doc({id1: 'my-doc-id1'}); // id2 will be generated on the server if the integration
|
|
47
|
+
* const docRef = collectionRef.doc({id1: 'my-doc-id1'}); // id2 will be generated on the server if the integration
|
|
48
|
+
* supports it
|
|
48
49
|
*
|
|
49
50
|
* // For a collection from the `built_in_db` without a defined schema when an id is not provided
|
|
50
51
|
* const docRef = collectionRef.doc(); // The id will be generated on the server
|
|
@@ -68,14 +69,14 @@ export declare class CollectionReference<T extends DocumentData> {
|
|
|
68
69
|
* @param alias The alias for the query.
|
|
69
70
|
* @returns A `JoinQueryBuilder` that can be used to query the collection and joins with other queries.
|
|
70
71
|
*/
|
|
71
|
-
joinQuery<A extends Alias>(alias: A): JoinQueryBuilder<
|
|
72
|
+
joinQuery<A extends Alias>(alias: A): JoinQueryBuilder<Record<A, []>, Record<A, T>, A, A>;
|
|
72
73
|
/**
|
|
73
74
|
* Performs `or` on a list of queries. All the queries need to be on the same collection.
|
|
74
75
|
* The result will be a merge of all the queries sorted by the same sort condition of the first query.
|
|
75
76
|
* Duplicate items will be removed.
|
|
76
77
|
* @param builders The list of query builders to merge. (A query builder can be returned from the {@link query}
|
|
77
|
-
* method.
|
|
78
|
+
* method).
|
|
78
79
|
* @returns A query builder that can be used to perform the `or` operation.
|
|
79
80
|
*/
|
|
80
|
-
or(...builders:
|
|
81
|
+
or(...builders: QueryBuilder<T>[]): MergedQueryBuilder<T>;
|
|
81
82
|
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { CollectionName, DocumentData, IntegrationId } from '@squidcloud/common';
|
|
2
2
|
import { CollectionReference } from './collection-reference';
|
|
3
|
-
import DocumentIdentityService from './document-identity.service';
|
|
4
3
|
import { DocumentReferenceFactory } from './document-reference.factory';
|
|
5
|
-
import { JoinQueryBuilderFactory } from './query/join-query-builder.factory';
|
|
6
4
|
import { QueryBuilderFactory } from './query/query-builder.factory';
|
|
5
|
+
import { QuerySubscriptionManager } from './query/query-subscription.manager';
|
|
7
6
|
export declare class CollectionReferenceFactory {
|
|
8
7
|
private readonly documentReferenceFactory;
|
|
9
8
|
private readonly queryBuilderFactory;
|
|
10
|
-
private readonly
|
|
11
|
-
private readonly documentIdentityService;
|
|
9
|
+
private readonly querySubscriptionManager;
|
|
12
10
|
private readonly collections;
|
|
13
|
-
constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory,
|
|
11
|
+
constructor(documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, querySubscriptionManager: QuerySubscriptionManager);
|
|
14
12
|
get<T extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): CollectionReference<T>;
|
|
15
|
-
private migrateDocIds;
|
|
16
13
|
}
|
|
@@ -5,8 +5,8 @@ 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';
|
|
8
|
-
import { TransactionId } from './types';
|
|
9
8
|
import { SocketManager } from './socket.manager';
|
|
9
|
+
import { TransactionId } from './types';
|
|
10
10
|
export interface DocTimestampMetadata {
|
|
11
11
|
timestamp: DocTimestamp;
|
|
12
12
|
expireTimestamp?: number;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { SquidDocId } from '@squidcloud/common';
|
|
2
2
|
import { DataManager } from './data.manager';
|
|
3
|
+
import DocumentIdentityService from './document-identity.service';
|
|
3
4
|
import { DocumentReference } from './document-reference';
|
|
4
5
|
import { QueryBuilderFactory } from './query/query-builder.factory';
|
|
5
6
|
export declare class DocumentReferenceFactory {
|
|
7
|
+
private readonly documentIdentityService;
|
|
6
8
|
private dataManager;
|
|
9
|
+
constructor(documentIdentityService: DocumentIdentityService);
|
|
7
10
|
create(squidDocId: SquidDocId, queryBuilderFactory: QueryBuilderFactory): DocumentReference;
|
|
8
11
|
setDataManager(dataManager: DataManager): void;
|
|
9
12
|
}
|
|
@@ -1,24 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseQueryBuilder, DocumentData, FieldName, HasDereference, Operator, PrimitiveFieldType, SnapshotEmitter } from '@squidcloud/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { DocumentReference } from '../document-reference';
|
|
4
|
+
import { QueryBuilder } from './query-builder.factory';
|
|
4
5
|
import { Alias } from './query.types';
|
|
6
|
+
type SimpleJoinQueryBuilder<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, LatestAlias extends Alias, RootAlias extends Alias> = Pick<JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>, 'join' | 'snapshot' | 'snapshots' | 'grouped' | 'dereference'>;
|
|
7
|
+
type WithDocumentReferences<T extends Record<any, DocumentData>> = {
|
|
8
|
+
[k in keyof T]: DocumentReference<Required<T>[k]>;
|
|
9
|
+
};
|
|
10
|
+
type Grouped<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, any>, RootAlias extends Alias> = Aliases[RootAlias] extends [] ? Required<ReturnType>[RootAlias] : Record<RootAlias, Required<ReturnType>[RootAlias]> & OtherGroups<Aliases, ReturnType, Aliases[RootAlias]>;
|
|
11
|
+
type OtherGroups<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, any>, ManyRootAliases extends Alias[]> = ManyRootAliases extends [infer First extends Alias, ...infer Rest extends Alias[]] ? Record<First, Array<Grouped<Aliases, ReturnType, First>>> & OtherGroups<Aliases, ReturnType, Rest> : Record<Alias, never>;
|
|
12
|
+
interface HasGrouped {
|
|
13
|
+
/**
|
|
14
|
+
* Transforms this join query result to a nested data structure. For example, a join between teachers and students
|
|
15
|
+
* normally returns a result of the form:
|
|
16
|
+
* [
|
|
17
|
+
* { teacher: {name: 'Mr. Smith'}, student: {name: 'John Doe'} },
|
|
18
|
+
* { teacher: {name: 'Mr. Smith'}, student: {name: 'Jane Smith'} },
|
|
19
|
+
* { teacher: {name: 'Mr. EmptyClass'}, student: undefined },
|
|
20
|
+
* ]
|
|
21
|
+
* into a result of the form:
|
|
22
|
+
* [
|
|
23
|
+
* { teacher: {name: 'Mr. Smith'}, students: [
|
|
24
|
+
* { name: 'John Doe' },
|
|
25
|
+
* { name: 'Jane Smith' },
|
|
26
|
+
* ]},
|
|
27
|
+
* { teacher: {name: 'Mr. EmptyClass'}, students: [] },
|
|
28
|
+
* ]
|
|
29
|
+
*/
|
|
30
|
+
grouped(): any;
|
|
31
|
+
}
|
|
5
32
|
/**
|
|
6
33
|
* A query builder that can participate in a join.
|
|
7
34
|
* To learn more about join queries, see
|
|
8
35
|
* {@link https://docs.squid.cloud/docs/client-sdk/queries#joining-data-across-collections-and-integrations}.
|
|
9
36
|
*/
|
|
10
|
-
export declare class JoinQueryBuilder<
|
|
37
|
+
export declare class JoinQueryBuilder<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, LatestAlias extends Alias, RootAlias extends Alias> extends BaseQueryBuilder<ReturnType> implements SnapshotEmitter<WithDocumentReferences<ReturnType>>, HasGrouped, HasDereference {
|
|
11
38
|
private readonly collectionName;
|
|
12
39
|
private readonly integrationId;
|
|
13
40
|
private readonly querySubscriptionManager;
|
|
14
41
|
private readonly documentReferenceFactory;
|
|
15
|
-
private readonly alias;
|
|
16
|
-
private readonly joinQueryBuilderFactory;
|
|
17
42
|
private readonly queryBuilderFactory;
|
|
18
|
-
private readonly
|
|
43
|
+
private readonly latestAlias;
|
|
19
44
|
private readonly joins;
|
|
20
|
-
/** Record that maps the right alias to the left condition */
|
|
21
45
|
private readonly joinConditions;
|
|
46
|
+
private readonly queryBuilder;
|
|
22
47
|
/**
|
|
23
48
|
* Adds a condition to the query.
|
|
24
49
|
*
|
|
@@ -27,7 +52,7 @@ export declare class JoinQueryBuilder<DocumentType extends DocumentData, MyAlias
|
|
|
27
52
|
* @param value The value to compare against
|
|
28
53
|
* @returns The query builder
|
|
29
54
|
*/
|
|
30
|
-
where(fieldName: (keyof
|
|
55
|
+
where(fieldName: (keyof ReturnType[LatestAlias] & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
|
|
31
56
|
/**
|
|
32
57
|
* Sets a limit to the number of results returned by the query. The maximum limit is 20,000 and the default is 1,000
|
|
33
58
|
* if none is provided.
|
|
@@ -48,25 +73,38 @@ export declare class JoinQueryBuilder<DocumentType extends DocumentData, MyAlias
|
|
|
48
73
|
* Joins this query with another join query and return a new query builder that can be used to query the joined
|
|
49
74
|
* documents.
|
|
50
75
|
* @param queryBuilder The query builder to join with
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
76
|
+
* @param alias TODO
|
|
77
|
+
* @param joinFields TODO
|
|
78
|
+
* @param options TODO
|
|
53
79
|
* @returns A new query builder that can be used to query the joined documents
|
|
54
80
|
*/
|
|
55
|
-
join<
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
join<NewAlias extends string, NewReturnType extends DocumentData, LeftAlias extends Extract<keyof ReturnType, Alias>>(queryBuilder: QueryBuilder<NewReturnType>, alias: Exclude<NewAlias, keyof ReturnType>, joinFields: {
|
|
82
|
+
left: keyof Required<ReturnType>[LeftAlias] & FieldName;
|
|
83
|
+
right: keyof NewReturnType & FieldName;
|
|
84
|
+
}, options: {
|
|
85
|
+
leftAlias: LeftAlias;
|
|
86
|
+
}): SimpleJoinQueryBuilder<Omit<Aliases, LeftAlias> & Record<LeftAlias, [...Aliases[LeftAlias], NewAlias]> & Record<NewAlias, []>, ReturnType & Partial<Record<NewAlias, NewReturnType>>, NewAlias, RootAlias>;
|
|
87
|
+
join<NewAlias extends string, NewReturnType extends DocumentData>(queryBuilder: QueryBuilder<NewReturnType>, alias: Exclude<NewAlias, keyof ReturnType>, joinFields: {
|
|
88
|
+
left: keyof Required<ReturnType>[LatestAlias] & FieldName;
|
|
89
|
+
right: keyof NewReturnType & FieldName;
|
|
90
|
+
}): SimpleJoinQueryBuilder<Omit<Aliases, LatestAlias> & Record<LatestAlias, [...Aliases[LatestAlias], NewAlias]> & Record<NewAlias, []>, ReturnType & Partial<Record<NewAlias, NewReturnType>>, NewAlias, RootAlias>;
|
|
91
|
+
/** @inheritDoc */
|
|
92
|
+
snapshot(): Promise<Array<WithDocumentReferences<ReturnType>>>;
|
|
93
|
+
/** @inheritDoc */
|
|
94
|
+
snapshots(subscribe?: boolean): Observable<Array<WithDocumentReferences<ReturnType>>>;
|
|
95
|
+
/** @inheritDoc */
|
|
96
|
+
grouped(): GroupedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
97
|
+
/** @inheritDoc */
|
|
98
|
+
dereference(): DereferencedJoin<Aliases, ReturnType, RootAlias, LatestAlias>;
|
|
99
|
+
}
|
|
100
|
+
declare class DereferencedJoin<Aliases extends Record<Alias, Alias[]>, ReturnType extends Record<Alias, DocumentData>, RootAlias extends Alias, LatestAlias extends Alias> implements SnapshotEmitter<ReturnType>, HasGrouped {
|
|
101
|
+
private readonly joinQueryBuilder;
|
|
102
|
+
constructor(joinQueryBuilder: JoinQueryBuilder<Aliases, ReturnType, LatestAlias, RootAlias>);
|
|
103
|
+
/** @inheritDoc */
|
|
104
|
+
grouped(): SnapshotEmitter<Grouped<Aliases, ReturnType, RootAlias>>;
|
|
105
|
+
/** @inheritDoc */
|
|
61
106
|
snapshot(): Promise<Array<ReturnType>>;
|
|
62
|
-
/**
|
|
63
|
-
* Returns an observable that emits the query results and updates whenever the query results change unless
|
|
64
|
-
* `subscribe=false` is provided.
|
|
65
|
-
*
|
|
66
|
-
* Important: Make sure to unsubscribe from the observable when you are done with it.
|
|
67
|
-
*
|
|
68
|
-
* @param subscribe Whether to subscribe to the query. Defaults to true.
|
|
69
|
-
* @returns An observable for the query results
|
|
70
|
-
*/
|
|
107
|
+
/** @inheritDoc */
|
|
71
108
|
snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
|
|
72
109
|
}
|
|
110
|
+
export {};
|
|
@@ -1,50 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseQueryBuilder, DocumentData, FieldName, FieldSort, HasDereference, Operator, PrimitiveFieldType, Query, SnapshotEmitter } from '@squidcloud/common';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import DocumentIdentityService from '../document-identity.service';
|
|
4
3
|
import { DocumentReference } from '../document-reference';
|
|
5
|
-
import { DocumentReferenceFactory } from '../document-reference.factory';
|
|
6
|
-
import { QuerySubscriptionManager } from './query-subscription.manager';
|
|
7
|
-
export declare class QueryBuilderFactory {
|
|
8
|
-
private readonly querySubscriptionManager;
|
|
9
|
-
private readonly documentReferenceFactory;
|
|
10
|
-
private readonly documentIdentityService;
|
|
11
|
-
constructor(querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, documentIdentityService: DocumentIdentityService);
|
|
12
|
-
getForDocument<DocumentType extends DocumentData>(squidDocId: SquidDocId): QueryBuilder<DocumentType>;
|
|
13
|
-
get<DocumentType extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): QueryBuilder<DocumentType>;
|
|
14
|
-
}
|
|
15
|
-
/** An interface for the different actions that can be performed on a query. */
|
|
16
|
-
export interface QueryActions<DocumentType extends DocumentData> {
|
|
17
|
-
/**
|
|
18
|
-
* Returns a promise that resolves to the query results.
|
|
19
|
-
*
|
|
20
|
-
* @returns A promise that resolves to the query results.
|
|
21
|
-
*/
|
|
22
|
-
snapshot(): Promise<Array<DocumentReference<DocumentType>>>;
|
|
23
|
-
/**
|
|
24
|
-
* Returns an observable that emits the query results and updates whenever the query results change unless
|
|
25
|
-
* `subscribe=false` is provided.
|
|
26
|
-
*
|
|
27
|
-
* Important: Make sure to unsubscribe from the observable when you are done with it.
|
|
28
|
-
*
|
|
29
|
-
* @param subscribe Whether to subscribe to changes to the query results. Defaults to `true`.
|
|
30
|
-
* @returns An observable for the query results.
|
|
31
|
-
*/
|
|
32
|
-
snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
|
|
33
|
-
/**
|
|
34
|
-
* Similar to `snapshots` but returns an observable that emits the changes to the query results. The first result
|
|
35
|
-
* will contain only inserts.
|
|
36
|
-
*
|
|
37
|
-
* @returns An observable for the query changes.
|
|
38
|
-
*/
|
|
39
|
-
changes(): Observable<Changes<DocumentType>>;
|
|
40
|
-
}
|
|
41
4
|
/** A query builder that can be used to build a query that returns a list of documents. */
|
|
42
|
-
export declare class QueryBuilder<DocumentType extends DocumentData> extends
|
|
5
|
+
export declare class QueryBuilder<DocumentType extends DocumentData> extends BaseQueryBuilder<DocumentType> implements SnapshotEmitter<DocumentReference<DocumentType>>, HasDereference {
|
|
6
|
+
private readonly collectionName;
|
|
7
|
+
private readonly integrationId;
|
|
43
8
|
private readonly querySubscriptionManager;
|
|
44
9
|
private readonly documentReferenceFactory;
|
|
45
10
|
private readonly queryBuilderFactory;
|
|
46
11
|
private readonly documentIdentityService;
|
|
47
12
|
private forceFetchFromServer;
|
|
13
|
+
protected readonly query: Query<DocumentType>;
|
|
14
|
+
/** @inheritDoc */
|
|
15
|
+
where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
|
|
16
|
+
/** @inheritDoc */
|
|
17
|
+
limit(limit: number): this;
|
|
18
|
+
/** @inheritDoc */
|
|
19
|
+
sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
|
|
20
|
+
private mergeConditions;
|
|
48
21
|
getSortOrder(): FieldSort<DocumentType>[];
|
|
49
22
|
/**
|
|
50
23
|
* @inheritDoc
|
|
@@ -70,6 +43,8 @@ export declare class QueryBuilder<DocumentType extends DocumentData> extends Sim
|
|
|
70
43
|
* @returns The query's hash string.
|
|
71
44
|
*/
|
|
72
45
|
get hash(): string;
|
|
46
|
+
/** @inheritDoc */
|
|
47
|
+
dereference(): SnapshotEmitter<DocumentType>;
|
|
73
48
|
}
|
|
74
49
|
/** Describes the changes to a query result. */
|
|
75
50
|
export declare class Changes<DocumentType extends DocumentData> {
|
|
@@ -58,7 +58,6 @@ export declare class Squid {
|
|
|
58
58
|
private readonly lockManager;
|
|
59
59
|
private readonly querySubscriptionManager;
|
|
60
60
|
private readonly queryBuilderFactory;
|
|
61
|
-
private readonly joinQueryBuilderFactory;
|
|
62
61
|
private readonly collectionReferenceFactory;
|
|
63
62
|
private readonly backendFunctionManager;
|
|
64
63
|
private readonly namedQueryManager;
|