@squidcloud/client 1.0.28 → 1.0.30

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.
Files changed (32) hide show
  1. package/dist/common/src/api-call.context.d.ts +8 -13
  2. package/dist/common/src/api.types.d.ts +14 -1
  3. package/dist/common/src/application.schemas.d.ts +343 -51
  4. package/dist/common/src/application.types.d.ts +10 -4
  5. package/dist/common/src/backend-run.types.d.ts +0 -1
  6. package/dist/common/src/context.types.d.ts +10 -0
  7. package/dist/common/src/graphql.context.d.ts +0 -8
  8. package/dist/common/src/graphql.types.d.ts +8 -0
  9. package/dist/common/src/index.d.ts +1 -1
  10. package/dist/common/src/integration.types.d.ts +102 -22
  11. package/dist/common/src/logger.types.d.ts +0 -1
  12. package/dist/common/src/metrics.types.d.ts +56 -63
  13. package/dist/common/src/mutation.context.d.ts +0 -1
  14. package/dist/common/src/query/query-context.d.ts +0 -1
  15. package/dist/common/src/query/simple-query-builder.d.ts +78 -2
  16. package/dist/common/src/regions.d.ts +1 -0
  17. package/dist/common/src/secret.types.d.ts +2 -0
  18. package/dist/common/src/security.types.d.ts +3 -0
  19. package/dist/common/src/utils/validation.d.ts +1 -1
  20. package/dist/index.js +2 -2
  21. package/dist/package.json +1 -1
  22. package/dist/typescript-client/src/collection-reference.d.ts +38 -6
  23. package/dist/typescript-client/src/destruct.manager.d.ts +1 -1
  24. package/dist/typescript-client/src/document-reference.d.ts +74 -6
  25. package/dist/typescript-client/src/graphql-client.d.ts +3 -0
  26. package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +49 -13
  27. package/dist/typescript-client/src/query/query-builder.factory.d.ts +27 -11
  28. package/dist/typescript-client/src/query/query.types.d.ts +7 -0
  29. package/dist/typescript-client/src/squid.d.ts +132 -12
  30. package/dist/typescript-client/src/types.d.ts +1 -1
  31. package/package.json +1 -1
  32. package/dist/common/src/metrics.schemas.d.ts +0 -3
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
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",
@@ -1,9 +1,16 @@
1
- import { DocId, DocIdObj, DocumentData, IdResolutionMap, IntegrationId } from '@squidcloud/common';
1
+ import { DocId, DocIdObj, DocumentData } from '@squidcloud/common';
2
2
  import { DocumentReference } from './document-reference';
3
- import { DocumentReferenceFactory } from './document-reference.factory';
4
- import { JoinQueryBuilder, JoinQueryBuilderFactory } from './query/join-query-builder.factory';
5
- import { QueryBuilder, QueryBuilderFactory } from './query/query-builder.factory';
3
+ import { JoinQueryBuilder } from './query/join-query-builder.factory';
4
+ import { QueryBuilder } from './query/query-builder.factory';
6
5
  import { Alias } from './query/query.types';
6
+ /**
7
+ * Holds a reference to a data collection. a collection reference is a reference to a collection in a database. You can
8
+ * use it to read or write data to the collection. A collection can refer to a table in a relational database or a
9
+ * collection in a NoSQL database.
10
+ *
11
+ * Read more about collection references in the [documentation]{@link https://docs.squid.cloud/docs/client-sdk/collection-reference}.
12
+ * @typeParam T The type of the document data.
13
+ */
7
14
  export declare class CollectionReference<T extends DocumentData> {
8
15
  private readonly collectionName;
9
16
  private integrationId;
@@ -11,9 +18,34 @@ export declare class CollectionReference<T extends DocumentData> {
11
18
  private readonly queryBuilderFactory;
12
19
  private readonly joinQueryBuilderFactory;
13
20
  private readonly documents;
14
- constructor(collectionName: string, integrationId: IntegrationId, documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, joinQueryBuilderFactory: JoinQueryBuilderFactory);
21
+ /**
22
+ * Returns a document reference for the given document id.
23
+ * The document id is an object that maps the primary keys of the collection (as defined in the Squid Cloud Console)
24
+ * to their values. There are two exceptions:
25
+ * 1 - If no document id is provided, a new document id will be generated on the server once the document is created.
26
+ * This is true only if the underlying datasource for this collection supports id generation.
27
+ * 2 - If the integration id is `built_in_db`, the document id may be a string unless a primary key was provided for
28
+ * this collection in the Squid Cloud Console.
29
+ *
30
+ * @param docId The document id as an object for the different fields in the primary key or a string. If none is provided,
31
+ * a new document id will be generated on the server once the document is created (if the integration supports it).
32
+ *
33
+ * @returns A document reference for the given document id.
34
+ */
15
35
  doc(docId?: DocId | DocIdObj): DocumentReference<T>;
36
+ /**
37
+ * Creates a `QueryBuilder` that can be used to query the collection.
38
+ *
39
+ * @returns A `QueryBuilder` that can be used to query the collection.
40
+ */
16
41
  query(): QueryBuilder<T>;
42
+ /**
43
+ * Creates a `JoinQueryBuilder` that can be used to query the collection
44
+ * Note that when using a join query, you have to provide an alias for the query and for every other query
45
+ * participating in the join.
46
+ *
47
+ * @param alias The alias for the query.
48
+ * @returns A `JoinQueryBuilder` that can be used to query the collection and joins with other queries.
49
+ */
17
50
  joinQuery<A extends Alias>(alias: A): JoinQueryBuilder<T, A, Record<A, DocumentReference<T>>>;
18
- migrateDocIds(idResolutionMap: IdResolutionMap): void;
19
51
  }
@@ -2,7 +2,7 @@ export type DestructorFn = () => Promise<void> | void;
2
2
  export declare class DestructManager {
3
3
  private readonly predestructors;
4
4
  private readonly destructors;
5
- private isDestructed;
5
+ isDestructed: boolean;
6
6
  onPreDestruct(fn: DestructorFn): void;
7
7
  onDestruct(fn: DestructorFn): void;
8
8
  destruct(): Promise<void>;
@@ -1,23 +1,91 @@
1
- import { DocumentData, IdResolutionMap, Paths, SquidDocId } from '@squidcloud/common';
1
+ import { DocumentData, IdResolutionMap, Paths } from '@squidcloud/common';
2
2
  import { Observable } from 'rxjs';
3
- import { DataManager } from './data.manager';
4
- import { QueryBuilderFactory } from './query/query-builder.factory';
5
3
  import { TransactionId } from './types';
4
+ /**
5
+ * Holds a reference to a document. A document reference is a reference to a specific record in a collection. You can
6
+ * use it to read or write data to the document. A document can refer to a row in a table in a relational database or a
7
+ * document in a NoSQL database. Additionally, a document reference can refer to a non-existent document, which you can
8
+ * use to create a new document.
9
+ *
10
+ * Read more about document references in the
11
+ * [documentation]{@link https://docs.squid.cloud/docs/client-sdk/document-reference}.
12
+ * @typeParam T The type of the document data.
13
+ */
6
14
  export declare class DocumentReference<T extends DocumentData = any> {
7
15
  private _squidDocId;
8
16
  private readonly dataManager;
9
17
  private readonly queryBuilderFactory;
10
- constructor(_squidDocId: SquidDocId, dataManager: DataManager, queryBuilderFactory: QueryBuilderFactory);
11
- get squidDocId(): SquidDocId;
12
- data(): T;
18
+ /**
19
+ * Returns the document data. Throws an error if the document does not exist.
20
+ *
21
+ * @returns The document data.
22
+ * @throws Error if the document does not exist.
23
+ */
24
+ get data(): T;
25
+ /**
26
+ * Returns a document reference with the latest data from the server or undefined if the document does not exist on
27
+ * the server.
28
+ *
29
+ * @returns A document reference with the latest data from the server or undefined if the document does not exist on
30
+ * the server.
31
+ */
13
32
  snapshot(): Promise<DocumentReference<T> | undefined>;
33
+ /**
34
+ * Returns an observable that emits a document reference with the latest data from the server or undefined if the
35
+ * document is deleted or does not exist on the server.
36
+ *
37
+ * @returns An observable that emits a document reference with the latest data from the server or undefined if the
38
+ * document is deleted or does not exist on the server.
39
+ */
14
40
  snapshots(): Observable<DocumentReference<T> | undefined>;
41
+ /**
42
+ * Returns whether the locally available version of the document may not be the latest version on the server.
43
+ *
44
+ * @returns Whether the locally available version of the document may not be the latest version on the server.
45
+ */
15
46
  isDirty(): boolean;
16
47
  private isTracked;
48
+ /**
49
+ * Updates the document with the given data.
50
+ * The `update` will be reflected optimistically locally and will be applied to the server later.
51
+ * If a transactionId is provided, the `update` will be applied to the server as an atomic operation together with
52
+ * the rest of the operations in the transaction and the `update` will not reflect locally until the transaction is
53
+ * completed locally.
54
+ *
55
+ * The returned promise will resolve once the `update` has been applied to the server or immediately if the `update`
56
+ * is part of a transaction.
57
+ *
58
+ * @param data The data to update - can be partial.
59
+ */
17
60
  update(data: Partial<Record<Paths<T>, any>>, transactionId?: TransactionId): Promise<void>;
61
+ /**
62
+ * Similar to {@link update}, but only updates the given path.
63
+ */
18
64
  setInPath(path: Paths<T>, value: any, transactionId?: TransactionId): Promise<void>;
65
+ /** Similar to `update`, but only deletes the given path. */
19
66
  deleteInPath(path: Paths<T>, transactionId?: TransactionId): Promise<void>;
67
+ /**
68
+ * Inserts the document with the given data. If the document already exists, the operation will be treated as
69
+ * `upsert`. The `insert` will be reflected optimistically locally and will be applied to the server later. If a
70
+ * transactionId is provided, the `insert` will be applied to the server as an atomic operation together with the
71
+ * rest
72
+ * of the operations in the transaction and the `insert` will not reflect locally until the transaction is completed
73
+ * locally.
74
+ *
75
+ * The returned promise will resolve once the `insert` has been applied to the server or immediately if the `insert`
76
+ * is part of a transaction.
77
+ */
20
78
  insert(data: T, transactionId?: TransactionId): Promise<void>;
79
+ /**
80
+ * Deletes the document.
81
+ * The `delete` will be reflected optimistically locally and will be applied to the server later.
82
+ * If a transactionId is provided, the `delete` will be applied to the server as an atomic operation together with
83
+ * the rest of the operations in the transaction and the `delete` will not reflect locally until the transaction is
84
+ * completed locally.
85
+ *
86
+ * The returned promise will resolve once the `delete` has been applied to the server or immediately if the `delete`
87
+ * is part of a transaction.
88
+ */
21
89
  delete(transactionId?: TransactionId): Promise<void>;
22
90
  migrateDocIds(idResolutionMap: IdResolutionMap): void;
23
91
  }
@@ -1,9 +1,12 @@
1
1
  import { GraphQLRequest, IntegrationId } from '@squidcloud/common';
2
2
  import { RpcManager } from './rpc.manager';
3
+ /** A GraphQL client that can be used to query and mutate data. */
3
4
  export declare class GraphQLClient {
4
5
  private readonly rpcManager;
5
6
  private readonly client;
6
7
  constructor(rpcManager: RpcManager, integrationId: IntegrationId);
8
+ /** Executes a GraphQL query and returns a promise with the result. */
7
9
  query<T = any>(request: GraphQLRequest): Promise<T>;
10
+ /** Executes a GraphQL mutation and returns a promise with the result. */
8
11
  mutate<T = Record<string, any>>(request: GraphQLRequest): Promise<T | null | undefined>;
9
12
  }
@@ -1,17 +1,11 @@
1
- import { CollectionName, DocumentData, FieldName, IntegrationId, Operator, PrimitiveFieldType, Query } from '@squidcloud/common';
1
+ import { DocumentData, FieldName, Operator, PrimitiveFieldType } from '@squidcloud/common';
2
2
  import { Observable } from 'rxjs';
3
3
  import { DocumentReference } from '../document-reference';
4
- import { DocumentReferenceFactory } from '../document-reference.factory';
5
- import { QueryBuilderFactory } from './query-builder.factory';
6
- import { QuerySubscriptionManager } from './query-subscription.manager';
7
4
  import { Alias } from './query.types';
8
- export declare class JoinQueryBuilderFactory {
9
- private readonly querySubscriptionManager;
10
- private readonly documentReferenceFactory;
11
- private readonly queryBuilderFactory;
12
- constructor(querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory);
13
- getForJoin<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType>>>(collectionName: CollectionName, integrationId: IntegrationId, alias: MyAlias): JoinQueryBuilder<DocumentType, MyAlias, ReturnType>;
14
- }
5
+ /**
6
+ * A query builder that can participate in a join.
7
+ * To learn more about join queries, see {@link https://docs.squid.cloud/docs/client-sdk/queries#joining-data-across-collections-and-integrations}.
8
+ */
15
9
  export declare class JoinQueryBuilder<DocumentType extends DocumentData, MyAlias extends Alias, ReturnType extends Record<MyAlias, DocumentReference<DocumentType> | undefined>> {
16
10
  private readonly collectionName;
17
11
  private readonly integrationId;
@@ -24,12 +18,54 @@ export declare class JoinQueryBuilder<DocumentType extends DocumentData, MyAlias
24
18
  private readonly joins;
25
19
  /** Record that maps the right alias to the left condition */
26
20
  private readonly joinConditions;
27
- constructor(collectionName: CollectionName, integrationId: IntegrationId, querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, alias: MyAlias, joinQueryBuilderFactory: JoinQueryBuilderFactory, queryBuilderFactory: QueryBuilderFactory);
21
+ /**
22
+ * Adds a condition to the query.
23
+ *
24
+ * @param fieldName The name of the field to query
25
+ * @param operator The operator to use
26
+ * @param value The value to compare against
27
+ * @returns The query builder
28
+ */
28
29
  where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
30
+ /**
31
+ * Sets a limit to the number of results returned by the query. The maximum limit is 1000 and this is the default if
32
+ * none is provided.
33
+ *
34
+ * @param limit The maximum number of results to return
35
+ * @returns The query builder
36
+ */
29
37
  limit(limit: number): this;
38
+ /**
39
+ * Adds a sort order to the query. You can add multiple sort orders to the query. The order in which you add them
40
+ * determines the order in which they are applied.
41
+ * @param fieldName The name of the field to sort by
42
+ * @param asc Whether to sort in ascending order. Defaults to true.
43
+ * @returns The query builder
44
+ */
30
45
  sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
46
+ /**
47
+ * Joins this query with another join query and return a new query builder that can be used to query the joined
48
+ * documents.
49
+ * @param queryBuilder The query builder to join with
50
+ * @param leftFieldName The name of the field on the left side of the join
51
+ * @param rightFieldName The name of the field on the right side of the join
52
+ * @returns A new query builder that can be used to query the joined documents
53
+ */
31
54
  join<J extends DocumentData, RightAlias extends Alias, RightReturnType extends Record<RightAlias, DocumentReference<J> | undefined>>(queryBuilder: JoinQueryBuilder<J, RightAlias, RightReturnType>, leftFieldName: keyof DocumentType & FieldName, rightFieldName: keyof J & FieldName): JoinQueryBuilder<DocumentType, MyAlias, ReturnType & Partial<RightReturnType>>;
55
+ /**
56
+ * Returns a promise that resolves to the query results.
57
+ *
58
+ * @returns A promise that resolves to the query results
59
+ */
32
60
  snapshot(): Promise<Array<ReturnType>>;
61
+ /**
62
+ * Returns an observable that emits the query results and updates whenever the query results change unless
63
+ * `subscribe=false` is provided.
64
+ *
65
+ * Important: Make sure to unsubscribe from the observable when you are done with it.
66
+ *
67
+ * @param subscribe Whether to subscribe to the query. Defaults to true.
68
+ * @returns An observable for the query results
69
+ */
33
70
  snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
34
- build(): Query;
35
71
  }
@@ -1,4 +1,4 @@
1
- import { CollectionName, DocumentData, FieldName, IntegrationId, Operator, PrimitiveFieldType, Query, SquidDocId } from '@squidcloud/common';
1
+ import { CollectionName, DocumentData, IntegrationId, SimpleQueryBuilder, 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';
@@ -12,26 +12,42 @@ export declare class QueryBuilderFactory {
12
12
  getForDocument<DocumentType extends DocumentData>(squidDocId: SquidDocId): QueryBuilder<DocumentType>;
13
13
  get<DocumentType extends DocumentData>(collectionName: CollectionName, integrationId: IntegrationId): QueryBuilder<DocumentType>;
14
14
  }
15
- export declare class QueryBuilder<DocumentType extends DocumentData> {
16
- private readonly collectionName;
17
- private readonly integrationId;
15
+ /** A query builder that can be used to build a query that returns a list of documents. */
16
+ export declare class QueryBuilder<DocumentType extends DocumentData> extends SimpleQueryBuilder<DocumentType> {
18
17
  private readonly querySubscriptionManager;
19
18
  private readonly documentReferenceFactory;
20
19
  private readonly queryBuilderFactory;
21
20
  private readonly documentIdentityService;
22
- private readonly simpleQueryBuilder;
23
- constructor(collectionName: CollectionName, integrationId: IntegrationId, querySubscriptionManager: QuerySubscriptionManager, documentReferenceFactory: DocumentReferenceFactory, queryBuilderFactory: QueryBuilderFactory, documentIdentityService: DocumentIdentityService);
24
- where(fieldName: (keyof DocumentType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
25
- limit(limit: number): this;
26
- sortBy(fieldName: keyof DocumentType & FieldName, asc?: boolean): this;
21
+ /**
22
+ * Returns a promise that resolves to the query results.
23
+ *
24
+ * @returns A promise that resolves to the query results.
25
+ */
27
26
  snapshot(): Promise<Array<DocumentReference<DocumentType>>>;
27
+ /**
28
+ * Returns an observable that emits the query results and updates whenever the query results change unless
29
+ * `subscribe=false` is provided.
30
+ *
31
+ * Important: Make sure to unsubscribe from the observable when you are done with it.
32
+ *
33
+ * @param subscribe Whether to subscribe to changes to the query results. Defaults to `true`.
34
+ * @returns An observable for the query results.
35
+ */
28
36
  snapshots(subscribe?: boolean): Observable<Array<DocumentReference<DocumentType>>>;
37
+ /**
38
+ * Similar to `snapshots` but returns an observable that emits the changes to the query results. The first result
39
+ * will contain only inserts.
40
+ *
41
+ * @returns An observable for the query changes.
42
+ */
29
43
  changes(): Observable<Changes<DocumentType>>;
30
- build(): Query;
31
- get hash(): string;
32
44
  }
45
+ /** Describes the changes to a query result. */
33
46
  export interface Changes<DocumentType extends DocumentData> {
47
+ /** The newly inserted documents to the query result */
34
48
  inserts: Array<DocumentReference<DocumentType>>;
49
+ /** The documents that were updated in the query result */
35
50
  updates: Array<DocumentReference<DocumentType>>;
51
+ /** The actual document data that was deleted from the query result */
36
52
  deletes: Array<DocumentType>;
37
53
  }
@@ -1,5 +1,12 @@
1
1
  import { FieldName } from '@squidcloud/common';
2
+ /**
3
+ * An alias for a join result. This is used to disambiguate fields in the result.
4
+ */
2
5
  export type Alias = string;
6
+ /**
7
+ * A join condition.
8
+ * The join conditions defines the alias for the left side of the join and the field names to join on.
9
+ */
3
10
  export interface JoinCondition {
4
11
  leftAlias: Alias;
5
12
  leftFieldName: FieldName;
@@ -2,14 +2,41 @@ import { ApiEndpointId, ApiKey, AppId, CollectionName, DocumentData, Integration
2
2
  import { CollectionReference } from './collection-reference';
3
3
  import { GraphQLClient } from './graphql-client';
4
4
  import { TransactionId } from './types';
5
+ /** The different options that can be used to initialize a Squid instance. */
5
6
  export interface SquidOptions {
7
+ /**
8
+ * A function that can be used to wrap messages coming from Squid to the application. This is useful for
9
+ * different frameworks that need to wrap messages in order to detect changes (like Angular).
10
+ * @param fn The function to wrap.
11
+ */
6
12
  messageNotificationWrapper?: (fn: () => any) => any;
13
+ /**
14
+ * The application ID that is used to identify the application in Squid. The ID can be found in the Squid Cloud
15
+ * Console.
16
+ */
7
17
  appId: AppId;
18
+ /**
19
+ * The application API key, using the API key can be used to bypass security rules and other restrictions.
20
+ * The API key can be found in the Squid Cloud Console.
21
+ */
8
22
  apiKey?: ApiKey;
23
+ /**
24
+ * The region that the application is running in. This is used to determine the URL of the Squid Cloud API.
25
+ */
9
26
  region: SupportedSquidRegion;
27
+ /**
28
+ * A list of API endpoints that can be used for overriding the default API endpoints for the different integrations.
29
+ * This is useful for APIs that have multiple base urls hosted in different regions.
30
+ */
10
31
  apiServerUrlOverrideMapping?: Record<IntegrationId, string>;
11
32
  }
12
- /** Reference to the squid db. Provides all the available actions on the DB. */
33
+ /**
34
+ * The main entry point to the Squid Client SDK.
35
+ *
36
+ * The Squid class provides a comprehensive array of functionality for accessing the different integrations, executing
37
+ * backend functions, managing data, and more. Upon instantiating the Squid class, you will have access to all of these
38
+ * capabilities.
39
+ */
13
40
  export declare class Squid {
14
41
  private readonly socketManager;
15
42
  private readonly clientId;
@@ -29,23 +56,116 @@ export declare class Squid {
29
56
  private readonly destructManager;
30
57
  private readonly documentIdentityService;
31
58
  private static readonly squidInstancesMap;
59
+ /**
60
+ * Creates a new instance of Squid with the given options.
61
+ *
62
+ * @param options The options for initializing the Squid instance.
63
+ */
32
64
  constructor(options: SquidOptions);
33
65
  /**
34
- * This method is a factory method for creating a Squid instance
66
+ * Returns the global Squid instance with the given options, creating a new instance if one with the same options
67
+ * does not exist.
68
+ *
69
+ * @param options The options for initializing the Squid instance.
70
+ * @returns A global Squid instance with the given options.
35
71
  */
36
72
  static getInstance(options: SquidOptions): Squid;
73
+ /**
74
+ * Returns all the global Squid instances.
75
+ *
76
+ * @returns An array of all the global Squid instances.
77
+ */
37
78
  static getInstances(): Array<Squid>;
38
79
  /**
39
- * Sets the auth id token (OpenId) that will be sent to the server and will be used for providing the Auth object
80
+ * Sets the auth id token (OpenId) that will be sent to the server and will be used for providing the `auth` object
40
81
  * to the security rules.
82
+ *
83
+ * @param idToken The auth id token.
84
+ * @returns void
85
+ */
86
+ setAuthIdToken: (idToken: string | undefined) => void;
87
+ /**
88
+ * Returns a reference to the collection in the provided integration.
89
+ *
90
+ * If the integrationId is not provided, the `built_in_db` integration id will be used.
91
+ *
92
+ * For more information on the CollectionReference object, please refer to the
93
+ * documentation at {@link https://docs.squid.cloud/docs/client-sdk/collection-reference}.
94
+ *
95
+ * @param collectionName The name of the collection.
96
+ * @param integrationId The id of the integration, default to `built_in_db`.
97
+ * @returns A reference to the collection in the provided integration.
98
+ * @typeParam T The type of the documents in the collection.
99
+ */
100
+ collection: <T extends DocumentData>(collectionName: CollectionName, integrationId?: IntegrationId) => CollectionReference<T>;
101
+ /**
102
+ * Runs the given callback as an atomic change. All the mutations that are executed using the provided transactionId
103
+ * will be atomic. Note that mutations for different integrations will not be atomic.
104
+ *
105
+ * For more information about transactions in Squid, please refer to the
106
+ * documentation at {@link https://docs.squid.cloud/docs/client-sdk/transactions}.
107
+ *
108
+ * @param fn The callback to run as an atomic change. The function receives a transactionId that should be used for
109
+ * all the mutations that should be atomic. The function should return a promise.
110
+ *
111
+ * @returns A promise that resolves when the transactions is committed on the server.
112
+ */
113
+ runInTransaction: (fn: (transactionId: TransactionId) => Promise<void>) => Promise<void>;
114
+ /**
115
+ * Executes the given backend function with the given parameters and returns a promise with the result.
116
+ *
117
+ * For more information about backend functions in Squid, please refer to the
118
+ * documentation at {@link https://docs.squid.cloud/docs/backend/executables}.
119
+ *
120
+ * @param functionName The name of the function to execute on the server.
121
+ * @param params The parameters to pass to the function.
122
+ * @returns A promise that resolves with the result of the function.
123
+ * @typeParam T The type of the result of the function.
124
+ */
125
+ executeFunction: <T = any>(functionName: string, ...params: any[]) => Promise<T>;
126
+ /**
127
+ * Executes the given named query with the given parameters and returns a promise with the result.
128
+ *
129
+ * For more information about named queries in Squid, please refer to the
130
+ * documentation at {@link https://docs.squid.cloud/docs/backend/named-queries}.
131
+ *
132
+ * @param integrationId The id of the integration that the named query is defined with.
133
+ * @param queryName The name of the named query.
134
+ * @param params The parameters to pass to the named query.
135
+ * @returns A promise that resolves with the result of the named query.
136
+ * @typeParam T The type of the result of the named query.
137
+ */
138
+ executeNamedQuery: <T = any>(integrationId: IntegrationId, queryName: QueryName, params: Record<string, any>) => Promise<T>;
139
+ /**
140
+ * Invokes the given HTTP API (defined by the integration ID and the endpoint ID) with the given request parameters
141
+ * and returns a promise with the response. The structure of the request and the response is defined in the
142
+ * integration's schema page.
143
+ *
144
+ * For more information about API integrations in Squid, please refer to the
145
+ * documentation at {@link https://docs.squid.cloud/docs/integrations/httpapi}.
146
+ *
147
+ * @param integrationId The id of the integration that the API is defined with.
148
+ * @param endpointId The id of the endpoint in the API integration.
149
+ * @param request The request parameters to pass to the API.
150
+ * @returns A promise that resolves with the response of the API.
151
+ * @typeParam T The type of the response of the API.
152
+ */
153
+ callApi: <T = any>(integrationId: IntegrationId, endpointId: ApiEndpointId, request?: Record<string, any>) => Promise<T>;
154
+ /**
155
+ * Returns a GraphQL client for the given integration. The GraphQL client can be used to execute GraphQL queries and
156
+ * mutations. For more information about GraphQL in Squid, please refer to the documentation at
157
+ * {@link https://docs.squid.cloud/docs/integrations/graphql}.
158
+ *
159
+ * @param integrationId The id of the integration that the GraphQL API is defined with.
160
+ * @returns A GraphQL client for the given integration.
161
+ */
162
+ graphql: (integrationId: IntegrationId) => GraphQLClient;
163
+ /**
164
+ * Destructs the Squid Client. Unsubscribes from all ongoing queries or requests, and clears the local data.
165
+ * After invoking this method, the Squid client will not be usable.
166
+ *
167
+ * @returns A promise that resolves when the destruct process is complete.
41
168
  */
42
- setAuthIdToken(idToken: string | undefined): void;
43
- collection<T extends DocumentData>(collectionName: CollectionName, integrationId?: IntegrationId): CollectionReference<T>;
44
- runInTransaction(fn: (transactionId: TransactionId) => Promise<void>): Promise<void>;
45
- executeFunction<T = any>(functionName: string, ...params: any[]): Promise<T>;
46
- executeNamedQuery<T = any>(integrationId: IntegrationId, queryName: QueryName, params: Record<string, any>): Promise<T>;
47
- callApi<T = any>(integrationId: IntegrationId, endpointId: ApiEndpointId, request?: Record<string, any>): Promise<T>;
48
- graphql(integrationId: IntegrationId): GraphQLClient;
49
- destruct(): Promise<void>;
50
- unsubscribe(): Promise<void>;
169
+ destruct: () => Promise<void>;
170
+ private validateNotDestructed;
51
171
  }
@@ -1,2 +1,2 @@
1
+ /** A transactionId - alias for string */
1
2
  export type TransactionId = string;
2
- export declare const NOOP_FN: (fn: () => any) => any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
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",
@@ -1,3 +0,0 @@
1
- import { JSONSchemaType } from 'ajv';
2
- import { GetMetricDataRequest } from './metrics.types';
3
- export declare const GetMetricDataRequestSchema: JSONSchemaType<GetMetricDataRequest>;