entropic-bond 1.50.0 → 1.50.2

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 (111) hide show
  1. package/lib/auth/auth-mock.d.ts +22 -0
  2. package/lib/auth/auth-mock.spec.d.ts +1 -0
  3. package/lib/auth/auth.d.ts +131 -0
  4. package/lib/auth/user-auth-types.d.ts +19 -0
  5. package/lib/cloud-functions/cloud-functions-mock.d.ts +11 -0
  6. package/lib/cloud-functions/cloud-functions-mock.spec.d.ts +1 -0
  7. package/lib/cloud-functions/cloud-functions.d.ts +19 -0
  8. package/lib/cloud-storage/cloud-storage.d.ts +24 -0
  9. package/lib/cloud-storage/cloud-storage.spec.d.ts +1 -0
  10. package/lib/cloud-storage/mock-cloud-storage.d.ts +20 -0
  11. package/lib/cloud-storage/stored-file.d.ts +39 -0
  12. package/lib/entropic-bond.js +1667 -0
  13. package/lib/entropic-bond.umd.cjs +7 -0
  14. package/lib/index.d.ts +19 -0
  15. package/lib/observable/observable.d.ts +52 -0
  16. package/lib/observable/observable.spec.d.ts +1 -0
  17. package/lib/persistent/entropic-component.d.ts +76 -0
  18. package/lib/persistent/entropic-component.spec.d.ts +1 -0
  19. package/lib/persistent/persistent.d.ts +281 -0
  20. package/lib/persistent/persistent.spec.d.ts +67 -0
  21. package/lib/server-auth/server-auth-mock.d.ts +12 -0
  22. package/lib/server-auth/server-auth-mock.spec.d.ts +1 -0
  23. package/lib/server-auth/server-auth.d.ts +24 -0
  24. package/lib/store/data-source.d.ts +137 -0
  25. package/lib/store/json-data-source.d.ts +68 -0
  26. package/lib/store/json-data-source.spec.d.ts +1 -0
  27. package/lib/store/mocks/test-user.d.ts +49 -0
  28. package/lib/store/model.d.ts +238 -0
  29. package/lib/store/model.spec.d.ts +1 -0
  30. package/lib/store/store.d.ts +62 -0
  31. package/lib/store/store.spec.d.ts +1 -0
  32. package/lib/types/utility-types.d.ts +45 -0
  33. package/lib/types/utility-types.spec.d.ts +1 -0
  34. package/lib/utils/test-utils/test-person.d.ts +33 -0
  35. package/{src/utils/utils.ts → lib/utils/utils.d.ts} +10 -34
  36. package/lib/utils/utils.spec.d.ts +1 -0
  37. package/package.json +7 -4
  38. package/.github/workflows/release.yml +0 -26
  39. package/CHANGELOG.md +0 -1151
  40. package/docs/.nojekyll +0 -1
  41. package/docs/README.md +0 -94
  42. package/docs/classes/Auth.md +0 -391
  43. package/docs/classes/AuthMock.md +0 -278
  44. package/docs/classes/AuthService.md +0 -188
  45. package/docs/classes/CloudFunctions.md +0 -123
  46. package/docs/classes/CloudFunctionsMock.md +0 -97
  47. package/docs/classes/CloudStorage.md +0 -215
  48. package/docs/classes/DataSource.md +0 -248
  49. package/docs/classes/EntropicComponent.md +0 -666
  50. package/docs/classes/JsonDataSource.md +0 -328
  51. package/docs/classes/MockCloudStorage.md +0 -279
  52. package/docs/classes/Model.md +0 -274
  53. package/docs/classes/Observable.md +0 -120
  54. package/docs/classes/Persistent.md +0 -420
  55. package/docs/classes/ServerAuth.md +0 -211
  56. package/docs/classes/ServerAuthMock.md +0 -176
  57. package/docs/classes/ServerAuthService.md +0 -130
  58. package/docs/classes/Store.md +0 -218
  59. package/docs/classes/StoredFile.md +0 -636
  60. package/docs/enums/StoredFileEvent.md +0 -41
  61. package/docs/interfaces/AuthError.md +0 -30
  62. package/docs/interfaces/CloudFunctionsService.md +0 -69
  63. package/docs/interfaces/Collection.md +0 -13
  64. package/docs/interfaces/CustomCredentials.md +0 -7
  65. package/docs/interfaces/DocumentReference.md +0 -49
  66. package/docs/interfaces/JsonRawData.md +0 -7
  67. package/docs/interfaces/SignData.md +0 -63
  68. package/docs/interfaces/StoreParams.md +0 -52
  69. package/docs/interfaces/StoredFileChange.md +0 -41
  70. package/docs/interfaces/UploadControl.md +0 -90
  71. package/docs/interfaces/UserCredentials.md +0 -113
  72. package/docs/interfaces/Values.md +0 -17
  73. package/docs/modules.md +0 -1273
  74. package/src/auth/auth-mock.spec.ts +0 -168
  75. package/src/auth/auth-mock.ts +0 -129
  76. package/src/auth/auth.ts +0 -185
  77. package/src/auth/user-auth-types.ts +0 -21
  78. package/src/cloud-functions/cloud-functions-mock.spec.ts +0 -136
  79. package/src/cloud-functions/cloud-functions-mock.ts +0 -23
  80. package/src/cloud-functions/cloud-functions.ts +0 -83
  81. package/src/cloud-storage/cloud-storage.spec.ts +0 -207
  82. package/src/cloud-storage/cloud-storage.ts +0 -60
  83. package/src/cloud-storage/mock-cloud-storage.ts +0 -72
  84. package/src/cloud-storage/stored-file.ts +0 -102
  85. package/src/index.ts +0 -19
  86. package/src/observable/observable.spec.ts +0 -105
  87. package/src/observable/observable.ts +0 -67
  88. package/src/persistent/entropic-component.spec.ts +0 -143
  89. package/src/persistent/entropic-component.ts +0 -135
  90. package/src/persistent/persistent.spec.ts +0 -828
  91. package/src/persistent/persistent.ts +0 -650
  92. package/src/server-auth/server-auth-mock.spec.ts +0 -53
  93. package/src/server-auth/server-auth-mock.ts +0 -45
  94. package/src/server-auth/server-auth.ts +0 -49
  95. package/src/store/data-source.ts +0 -186
  96. package/src/store/json-data-source.spec.ts +0 -100
  97. package/src/store/json-data-source.ts +0 -256
  98. package/src/store/mocks/mock-data.json +0 -155
  99. package/src/store/mocks/test-user.ts +0 -122
  100. package/src/store/model.spec.ts +0 -659
  101. package/src/store/model.ts +0 -462
  102. package/src/store/store.spec.ts +0 -30
  103. package/src/store/store.ts +0 -113
  104. package/src/types/utility-types.spec.ts +0 -117
  105. package/src/types/utility-types.ts +0 -116
  106. package/src/utils/test-utils/test-person.ts +0 -44
  107. package/src/utils/utils.spec.ts +0 -95
  108. package/tsconfig-build.json +0 -7
  109. package/tsconfig-cjs.json +0 -9
  110. package/tsconfig.json +0 -33
  111. package/vite.config.ts +0 -22
@@ -0,0 +1,137 @@
1
+ import { Persistent, PersistentObject, Collections } from '../persistent/persistent';
2
+ import { ClassPropNames } from '../types/utility-types';
3
+ export type DocumentObject = PersistentObject<Persistent>;
4
+ /**
5
+ * The query operators
6
+ * @param == equal
7
+ * @param != not equal
8
+ * @param < less than
9
+ * @param <= less than or equal
10
+ * @param > greater than
11
+ * @param >= greater than or equal
12
+ * @param contains array contains
13
+ * @param containsAny array contains any
14
+ * @param in in
15
+ * @param !in not in
16
+ */
17
+ export type QueryOperator = '==' | '!=' | '<' | '<=' | '>' | '>=' | 'contains' | 'containsAny';
18
+ /**
19
+ * A representation of a query operation
20
+ * @param property the name of the property to be used in the query
21
+ * @param operator the operator to be used in the query
22
+ * @param value the value to be used in the query
23
+ * @param aggregate if true, the query results will be aggregated using an `or` operator
24
+ */
25
+ export type QueryOperation<T> = {
26
+ property: ClassPropNames<T>;
27
+ operator: QueryOperator;
28
+ value: Partial<T[ClassPropNames<T>]> | {
29
+ [key: string]: unknown;
30
+ };
31
+ aggregate?: boolean;
32
+ };
33
+ /**
34
+ * The sort order
35
+ * @param asc ascending order
36
+ * @param desc descending order
37
+ */
38
+ export type QueryOrder = 'asc' | 'desc';
39
+ /**
40
+ * A representation of a full query
41
+ * @param operations the query operations to be performed
42
+ * @param limit the maximum number of items to be retrieved
43
+ * @param sort sort info
44
+ * @param sort.order the sort order
45
+ * @param sort.propertyName the name of the property to be used for sorting
46
+ */
47
+ export type QueryObject<T> = {
48
+ operations?: QueryOperation<T>[];
49
+ limit?: number;
50
+ sort?: {
51
+ order: QueryOrder;
52
+ propertyName: ClassPropNames<T> | string;
53
+ };
54
+ };
55
+ /**
56
+ * The data source interface.
57
+ * It defines the methods that must be implemented by a data source
58
+ * A data source is able to retrieve and save data i.e: from a database, a file, a RestAPI, etc.
59
+ * You can derive from this class to implement your own data source with the
60
+ * A data source is used by the store to retrieve and save data.
61
+ */
62
+ export declare abstract class DataSource {
63
+ /**
64
+ * Retrieves a document by id
65
+ * Implement the required logic to retrieve a document by id from your concrete
66
+ * the data source
67
+ * @param id the id of the document to be retrieved
68
+ * @param collectionName the name of the collection where the document is stored
69
+ * @returns a promise resolving to the document object. The document object is
70
+ * a plain object with the properties of the document class.
71
+ */
72
+ abstract findById(id: string, collectionName: string): Promise<DocumentObject>;
73
+ /**
74
+ * Retrieves all documents matching the query stored in the query object
75
+ * Implement the required logic to retrieve the documents that match the
76
+ * requirements in the query object from your concrete the data source
77
+ * @param queryObject the query object containing the query operations
78
+ * @param collectionName the name of the collection where the documents are stored
79
+ * @returns a promise resolving to an array of document objects. The document object is
80
+ * a plain object with the properties of the document class.
81
+ * @see QueryObject
82
+ * @see QueryOperation
83
+ * @see QueryOperator
84
+ * @see QueryOrder
85
+ * @see DocumentObject
86
+ */
87
+ abstract find(queryObject: QueryObject<DocumentObject>, collectionName: string): Promise<DocumentObject[]>;
88
+ /**
89
+ * Saves a document
90
+ * Implement the required logic to save the document in your concrete the data source
91
+ * @param object A collection of documents to be saved
92
+ * @returns a promise
93
+ */
94
+ abstract save(object: Collections): Promise<void>;
95
+ /**
96
+ * Deletes a document by id
97
+ * Implement the required logic to delete a document by id from your concrete
98
+ * data source
99
+ * @param id the id of the document to be deleted
100
+ * @param collectionName the name of the collection where the document is stored
101
+ * @returns a promise
102
+ */
103
+ abstract delete(id: string, collectionName: string): Promise<void>;
104
+ /**
105
+ * Retrieves the next bunch of documents matching the query stored in the query object
106
+ * Implement the required logic to retrieve the next bunch of documents that match the
107
+ * requirements in the query object from your concrete the data source
108
+ * @param limit the maximum number of items to be retrieved
109
+ * @returns a promise resolving to an array representing the next bunch of document objects
110
+ */
111
+ abstract next(limit?: number): Promise<DocumentObject[]>;
112
+ /**
113
+ * Retrieves the number of documents matching the query stored in the query object
114
+ * Implement the required logic to retrieve the number of documents that match the
115
+ * requirements in the query object from your concrete the data source
116
+ * @param queryObject the query object containing the query operations
117
+ * @param collectionName the name of the collection where the documents are stored
118
+ * @returns a promise resolving to the number of documents matching the query
119
+ * @see QueryObject
120
+ */
121
+ abstract count(queryObject: QueryObject<DocumentObject>, collectionName: string): Promise<number>;
122
+ /**
123
+ * Utility method to convert a query object to a property path query object
124
+ *
125
+ * @param queryObject the query object to be converted
126
+ * @returns a property path query object
127
+ * @example
128
+ * const queryObject = {
129
+ * operations: [{ property: 'name', operator: '==', value: { ancestorName: { father: 'Felipe' }}]
130
+ * }
131
+ * const propPathQueryObject = DataSource.toPropertyPathQueryObject( queryObject )
132
+ * // returned value: [{ property: 'name.ancestorName.father', operator: '==', value: 'Felipe' }]
133
+ */
134
+ static toPropertyPathOperations<T extends Persistent>(operations: QueryOperation<T>[]): QueryOperation<T>[];
135
+ static isArrayOperator(operator: QueryOperator): boolean;
136
+ private static toPropertyPathValue;
137
+ }
@@ -0,0 +1,68 @@
1
+ import { Collections, Persistent, PersistentObject } from '../persistent/persistent';
2
+ import { DataSource, DocumentObject, QueryObject } from "./data-source";
3
+ export interface JsonRawData {
4
+ [collection: string]: {
5
+ [documentId: string]: PersistentObject<Persistent>;
6
+ };
7
+ }
8
+ export interface ErrorOnOperation {
9
+ store: string;
10
+ find: string;
11
+ findById: string;
12
+ delete: string;
13
+ }
14
+ /**
15
+ * A concrete implementation of the DataSource interface uses an in-memory data store
16
+ * initialized by a JSON object.
17
+ * It is useful for testing purposes.
18
+ * The data in the JSON object is not persisted.
19
+ */
20
+ export declare class JsonDataSource implements DataSource {
21
+ /**
22
+ * @param jsonRawData the JSON object to be used as data store
23
+ */
24
+ constructor(jsonRawData?: JsonRawData);
25
+ /**
26
+ * Set the JSON object to initialize the data store. Use to set the it after
27
+ * the constructor has been called.
28
+ * @param jsonRawData the JSON object to be used as data store
29
+ */
30
+ setDataStore(rawDataStore: JsonRawData): this;
31
+ /**
32
+ * Introduce a delay in the execution of operations to simulate a real data source
33
+ * @param miliSeconds the number of milliseconds to delay the execution of operations
34
+ * @returns a chainable reference to this object
35
+ */
36
+ simulateDelay(miliSeconds: number): this;
37
+ findById(id: string, collectionName: string): Promise<DocumentObject>;
38
+ save(collections: Collections): Promise<void>;
39
+ find(queryObject: QueryObject<DocumentObject>, collectionName: string): Promise<DocumentObject[]>;
40
+ delete(id: string, collectionName: string): Promise<void>;
41
+ next(limit?: number): Promise<DocumentObject[]>;
42
+ count(queryObject: QueryObject<DocumentObject>, collectionName: string): Promise<number>;
43
+ /**
44
+ * @returns the raw data store data as a JSON object
45
+ */
46
+ get rawData(): JsonRawData;
47
+ /**
48
+ * Wait for all pending promises to be resolved
49
+ * @returns a promise that resolves when all pending promises are resolved
50
+ */
51
+ wait(): Promise<any[]>;
52
+ private incCursor;
53
+ simulateError(error: string | ErrorOnOperation | undefined): this;
54
+ private decCursor;
55
+ private queryProcessor;
56
+ private retrieveQueryDocs;
57
+ private deepValue;
58
+ private isQueryMatched;
59
+ private retrieveValuesToCompare;
60
+ private resolveWithDelay;
61
+ private _jsonRawData;
62
+ private _lastMatchingDocs;
63
+ private _lastLimit;
64
+ private _cursor;
65
+ private _simulateDelay;
66
+ private _pendingPromises;
67
+ private _simulateError;
68
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ import { Persistent } from '../../persistent/persistent';
2
+ interface Name {
3
+ firstName: string;
4
+ lastName: string;
5
+ ancestorName: {
6
+ father?: string;
7
+ mother?: string;
8
+ };
9
+ }
10
+ export declare class SubClass extends Persistent {
11
+ set year(value: number | undefined);
12
+ get year(): number | undefined;
13
+ private _year;
14
+ }
15
+ export declare class TestUser extends Persistent {
16
+ set name(value: Name | undefined);
17
+ get name(): Name | undefined;
18
+ set age(value: number | undefined);
19
+ get age(): number | undefined;
20
+ set admin(value: boolean | undefined);
21
+ get admin(): boolean | undefined;
22
+ set skills(value: string[] | undefined);
23
+ get skills(): string[] | undefined;
24
+ set documentRef(value: SubClass | undefined);
25
+ get documentRef(): SubClass | undefined;
26
+ set manyRefs(value: SubClass[]);
27
+ get manyRefs(): SubClass[];
28
+ set derived(value: DerivedUser | undefined);
29
+ get derived(): DerivedUser | undefined;
30
+ set manyDerived(value: DerivedUser[]);
31
+ get manyDerived(): DerivedUser[];
32
+ set colleagues(value: TestUser[]);
33
+ get colleagues(): TestUser[];
34
+ private _colleagues;
35
+ private _name;
36
+ private _age;
37
+ private _admin;
38
+ private _skills;
39
+ private _documentRef;
40
+ private _manyRefs;
41
+ private _derived;
42
+ private _manyDerived;
43
+ }
44
+ export declare class DerivedUser extends TestUser {
45
+ set salary(value: number | undefined);
46
+ get salary(): number | undefined;
47
+ private _salary;
48
+ }
49
+ export {};
@@ -0,0 +1,238 @@
1
+ import { Persistent } from '../persistent/persistent';
2
+ import { ClassPropNames, PropPath, PropPathType } from '../types/utility-types';
3
+ import { DataSource, QueryOperator, QueryObject, QueryOrder } from './data-source';
4
+ /**
5
+ * Provides abstraction to the database access. You should gain access to a Model
6
+ * object through the Store.getModel method instead of its constructor.
7
+ */
8
+ export declare class Model<T extends Persistent> {
9
+ static error: {
10
+ persistentNeedForSubCollection: string;
11
+ invalidQueryOrder: string;
12
+ };
13
+ constructor(stream: DataSource, persistentClass: Persistent | string, subCollection?: string);
14
+ /**
15
+ * Finds an stored object in the database by its id. The field id is provided
16
+ * by the Persistent parent class and it is automatically managed. Therefore,
17
+ * you should obtain the id by looking at the id field of the object.
18
+ *
19
+ * @param id the id to look for
20
+ * @param instance you can pass an instace that will be filled with the found data
21
+ * @returns a promise resolving to an instance with the found data
22
+ */
23
+ findById<D extends T>(id: string, instance?: D): Promise<D | undefined>;
24
+ /**
25
+ * Stores an object in the database
26
+ *
27
+ * @param instance the object instance to store
28
+ * @returns a promise
29
+ */
30
+ save(instance: T): Promise<void>;
31
+ /**
32
+ * Removes an element from the database by id
33
+ * @param id the id of the element to be removed
34
+ * @returns a promise
35
+ */
36
+ delete(id: string): Promise<void>;
37
+ /**
38
+ * Call find to retrieve a Query object used to define the search conditions
39
+ * @returns a Query object
40
+ */
41
+ find<U extends T>(): Query<U>;
42
+ /**
43
+ * Define the search conditions. You pass query operations and how the query
44
+ * results are returned to the QueryObject
45
+ * @param queryObject the QueryObject with the search constrains
46
+ * @param objectType Deprecated! - restricts the search to a specific instances of the class type
47
+ * @returns a promise resolving to a collection of matched documents
48
+ */
49
+ query<U extends T>(queryObject?: QueryObject<U>, /** @deprecated */ objectType?: U | string): Promise<U[]>;
50
+ /**
51
+ * Get the amount of documents matching the query
52
+ * @param queryObject the QueryObject with the search constrains
53
+ * @returns a promise resolving to the amount of matched documents
54
+ */
55
+ count(queryObject: QueryObject<T>): Promise<number>;
56
+ /**
57
+ * Get the next bunch of documents matching the last query
58
+ * @param limit the max amount of documents to retrieve. If not set, uses the
59
+ * last limit set
60
+ * @returns a promise resolving to a collection of matched documents
61
+ */
62
+ next<U extends T>(limit?: number): Promise<U[]>;
63
+ private mapToInstance;
64
+ /**
65
+ * Normalizes the query object to match the data source requirements.
66
+ * Call this method before you do any query operation on the concrete data source
67
+ * @param queryObject the query object containing the query operations
68
+ * @param operatorConversor a function that converts the query operators to the
69
+ * operators supported by the concrete data source
70
+ * @returns the normalized query object
71
+ */
72
+ private preprocessQueryObject;
73
+ readonly collectionName: string;
74
+ private _stream;
75
+ }
76
+ /**
77
+ * The Query class is used to define the search conditions. You can chain
78
+ * where operations to define the search conditions. The where operations
79
+ * are stored in a QueryObject that is passed to the query method of the
80
+ * Model class.
81
+ */
82
+ export declare class Query<T extends Persistent> {
83
+ constructor(model: Model<T>);
84
+ /**
85
+ * Matches all documents that the value of the property satisfies the condition
86
+ * in the operator parameter. Subsequent `where` calls will be operated to the
87
+ * previous ones using the AND operator
88
+ * @param property the property to be compared
89
+ * @param operator the operator to be used in the comparison. The available
90
+ * operators are: ==, !=, >, >=, < and <=
91
+ * @param value the value to be compared
92
+ * @param aggregate if true, the query will use the logical or operator and
93
+ * aggregate the results to the previous query
94
+ * @returns this Query object to make chained calls possible
95
+ * @example
96
+ * query.where( 'name', '==', 'John' )
97
+ * query.where( 'age', '>', 18 )
98
+ * query.where( 'age', '==', 18 ).where( 'name', '==', 'John' )
99
+ * @see whereDeepProp
100
+ * @see or
101
+ * @see orDeepProp
102
+ */
103
+ where<P extends ClassPropNames<T>>(property: P, operator: QueryOperator, value: Partial<T[P]> | Persistent, aggregate?: boolean): this;
104
+ /**
105
+ * Matches all documents that the value of the deep property satisfies the condition
106
+ * in the operator parameter
107
+ * @param propertyPath the path to the property to be compared
108
+ * @param operator the operator to be used in the comparison. The available
109
+ * operators are: ==, !=, >, >=, < and <=
110
+ * @param value the value to be compared
111
+ * @returns this Query object to make chained calls possible
112
+ * @example
113
+ * query.whereDeepProp( 'address.street', '==', 'Main Street' )
114
+ * @see where
115
+ * @see or
116
+ * @see orDeepProp
117
+ */
118
+ whereDeepProp(propertyPath: PropPath<T>, operator: QueryOperator, value: PropPathType<T, typeof propertyPath>, aggregate?: boolean): this;
119
+ /**
120
+ * Matches all documents that the value of the property satisfies the condition
121
+ * in the operator parameter and aggregates the results to the previous query
122
+ * @param property the property to be compared
123
+ * @param operator the operator to be used in the comparison. The available
124
+ * operators are: ==, !=, >, >=, < and <=
125
+ * @returns this Query object to make chained calls possible
126
+ * @example
127
+ * query.where( 'name', '==', 'John' ).and( 'age', '>', 18 )
128
+ * @see andDeepProp
129
+ * @see where
130
+ * @see whereDeepProp
131
+ * @see or
132
+ * @see orDeepProp
133
+ */
134
+ and<P extends ClassPropNames<T>>(property: P, operator: QueryOperator, value: Partial<T[P]> | Persistent): this;
135
+ /**
136
+ * Matches all documents that the value of the deep property satisfies the condition
137
+ * in the operator parameter and aggregates the results to the previous query
138
+ * @param propertyPath the path to the property to be compared
139
+ * @param operator the operator to be used in the comparison. The available
140
+ * operators are: ==, !=, >, >=, < and <=
141
+ * @param value the value to be compared
142
+ * @returns this Query object to make chained calls possible
143
+ * @example
144
+ * query.whereDeepProp( 'address.street', '==', 'Main Street' ).andDeepProp( 'address.city', '==', 'New York' )
145
+ * @see and
146
+ * @see where
147
+ * @see whereDeepProp
148
+ * @see or
149
+ * @see orDeepProp
150
+ */
151
+ andDeepProp(propertyPath: PropPath<T>, operator: QueryOperator, value: PropPathType<T, typeof propertyPath>): this;
152
+ /**
153
+ * Matches all documents that the value of the property satisfies the condition
154
+ * in the operator parameter and aggregates the results to the previous query
155
+ * @param property the property to be compared
156
+ * @param operator the operator to be used in the comparison. The available
157
+ * operators are: ==, !=, >, >=, < and <=
158
+ * @returns this Query object to make chained calls possible
159
+ * @example
160
+ * query.or( 'name', '==', 'John' )
161
+ * query.or( 'age', '>', 18 )
162
+ * @see orDeepProp
163
+ * @see where
164
+ * @see whereDeepProp
165
+ */
166
+ or<P extends ClassPropNames<T>>(property: P, operator: QueryOperator, value: Partial<T[P]> | Persistent): this;
167
+ /**
168
+ * Matches all documents that the value of the deep property satisfies the condition
169
+ * in the operator parameter and aggregates the results to the previous query
170
+ * @param propertyPath the path to the property to be compared
171
+ * @param operator the operator to be used in the comparison. The available
172
+ * operators are: ==, !=, >, >=, < and <=
173
+ * @param value the value to be compared
174
+ * @returns this Query object to make chained calls possible
175
+ * @example
176
+ * query.orDeepProp( 'address.street', '==', 'Main Street' )
177
+ * @see or
178
+ * @see where
179
+ * @see whereDeepProp
180
+ */
181
+ orDeepProp(propertyPath: PropPath<T>, operator: QueryOperator, value: PropPathType<T, typeof propertyPath>): this;
182
+ /**
183
+ * Defines a where condition to match documents that are instances of the
184
+ * given class
185
+ * @param classId the class name or an instance to match
186
+ * @returns this Query object to make chained calls possible
187
+ * @example
188
+ * query.instanceOf( 'Person' )
189
+ * query.instanceOf( Person )
190
+ * query.instanceOf( Person ).where( 'age', '>', 18 )
191
+ */
192
+ instanceOf<U extends T>(classId: U | string): this;
193
+ /**
194
+ * Executes the query and returns the result
195
+ * @param limit the max amount of documents to retrieve. If not set, uses the
196
+ * last limit set or all the matching documents
197
+ * @returns a promise resolving to a collection of matched documents
198
+ * @example
199
+ * const namedJohn = await query.where( 'name', '==', 'John' ).get()
200
+ */
201
+ get<U extends T>(limit?: number): Promise<U[]>;
202
+ /**
203
+ * Limits the number of documents to retrieve
204
+ * @param maxDocs the max amount of documents to retrieve
205
+ * @returns this Query object to make chained calls possible
206
+ * @example
207
+ * query.where( 'name', '==', 'John' ).limit( 10 )
208
+ */
209
+ limit(maxDocs: number): this;
210
+ /**
211
+ * Orders the result set by a property.
212
+ * @param propertyName The name of the property to order by
213
+ * @param order The sort direction. Possible values are 'asc' and 'desc'
214
+ * @returns a chainable query object
215
+ * @example
216
+ * query.orderBy( 'name', 'asc' )
217
+ * query.orderBy( 'age', 'desc' )
218
+ */
219
+ orderBy<P extends ClassPropNames<T>>(propertyName: P, order?: QueryOrder): this;
220
+ /**
221
+ * Orders the result set by a deep property
222
+ *
223
+ * @param propertyPath The full path of the deep property. It should be
224
+ * separated by dots like person.name.firstName.
225
+ * @param order The sort direction. Possible values are 'asc' and 'desc'
226
+ * @returns a chainable query object
227
+ */
228
+ orderByDeepProp(propertyPath: string, order?: QueryOrder): this;
229
+ /**
230
+ * Returns the number of documents that match the query
231
+ * @returns a promise resolving to the number of documents that match the query
232
+ * @example
233
+ * const count = await query.where( 'name', '==', 'John' ).count()
234
+ */
235
+ count(): Promise<number>;
236
+ private queryObject;
237
+ private model;
238
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ import { Persistent } from '../persistent/persistent';
2
+ import { DataSource } from './data-source';
3
+ import { Model } from './model';
4
+ /**
5
+ * The store is the main entry point for the data access layer.
6
+ * It provides methods to retrieve models for collections and subcollections.
7
+ * It also provides methods to populate property references with actual data from the store.
8
+ * You need to register a data source before using the store.
9
+ * @example
10
+ * // Register a data source
11
+ * Store.useDataSource( new FirestoreDataSource( firebase.firestore() ) )
12
+ * // Retrieve a model for a collection
13
+ * const model = Store.getModel( 'User' )
14
+ * // Retrieve a model for a subcollection
15
+ * const model = Store.getModelForSubCollection( user, 'Posts' )
16
+ * // Populate property references
17
+ * const user = await Store.populate( user )
18
+ */
19
+ export declare class Store {
20
+ private constructor();
21
+ static error: {
22
+ shouldBeRegistered: string;
23
+ };
24
+ /**
25
+ * Registers a data source to be used by the store.
26
+ * You need to register a data source before using the store.
27
+ * @param dataSource the data source to be used by the store
28
+ */
29
+ static useDataSource(dataSource: DataSource): void;
30
+ /**
31
+ * The data source currently used by the store
32
+ * @returns the data source
33
+ */
34
+ static get dataSource(): DataSource;
35
+ /**
36
+ * Retrieves a model for a collection
37
+ * @param classId the class name or an instance of the document type stored in the collection
38
+ * @returns the model for the collection
39
+ */
40
+ static getModel<T extends Persistent>(classId: T | string): Model<T>;
41
+ /**
42
+ * Retrieves a model for a subcollection
43
+ * @param document the persistent object that owns the subcollection
44
+ * @param subCollection the name of the subcollection
45
+ * @returns the model for the subcollection
46
+ */
47
+ static getModelForSubCollection<T extends Persistent>(document: Persistent, subCollection: string): Model<T>;
48
+ /**
49
+ * Populates property references with actual data from the store.
50
+ * It will not retrieve data if the instance is already populated
51
+ * @param instance the data to be populated.
52
+ * @returns the populated instance
53
+ */
54
+ static populate<T extends Persistent | Persistent[]>(instance: T): Promise<T>;
55
+ /**
56
+ * Checks if an instance is populated
57
+ * @param instance the instance or array of instances to be checked
58
+ * @returns true if the instance is populated
59
+ */
60
+ static isPopulated<T extends Persistent>(instance: T | readonly T[]): boolean;
61
+ private static _dataSource;
62
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ export type ClassMethodNames<T> = {
2
+ [K in keyof T]: T[K] extends Function ? K : never;
3
+ }[keyof T];
4
+ export type ClassMethods<T> = Pick<T, ClassMethodNames<T>>;
5
+ export type ClassPropNames<T> = {
6
+ [K in keyof T]: T[K] extends Function ? never : K;
7
+ }[keyof T];
8
+ export type ClassProps<T> = Pick<T, ClassPropNames<T>>;
9
+ export type SomeClassProps<T> = Partial<ClassProps<T>>;
10
+ export type SomeClassPropNames<T> = Partial<ClassPropNames<T>>;
11
+ export type ClassArrayPropNames<T> = {
12
+ [K in keyof T]: T[K] extends unknown[] | Readonly<unknown[]> ? K : never;
13
+ }[keyof T];
14
+ export type ClassArrayProps<T> = Pick<T, ClassArrayPropNames<T>>;
15
+ export type Elements<T extends ReadonlyArray<any> | ArrayLike<any> | Record<any, any> | any> = T extends ReadonlyArray<any> ? T[number] : T extends ArrayLike<any> ? T[number] : T extends object ? T[keyof T] : never;
16
+ export type UnderscoredProp<T> = `_${T & string}`;
17
+ export interface Collection<T> {
18
+ [key: string | symbol]: T;
19
+ }
20
+ export declare type ClassPropNamesOfType<T, U> = {
21
+ [K in keyof T]: T[K] extends Function ? never : T[K] extends U ? K : never;
22
+ }[keyof T];
23
+ /**
24
+ * Makes K properties of T required and keeps the rest untouched
25
+ * @example
26
+ * type T = { a?: number, b?: string, c?: boolean, d: number }
27
+ * type R = Require<T, 'a' | 'b'>
28
+ * // R = { a: number, b: string, c?: boolean, d: number }
29
+ */
30
+ export type Require<T, K extends keyof T> = T & {
31
+ [P in K]-?: T[P];
32
+ };
33
+ /*******************************************************************************
34
+ *
35
+ * SUB-PROPERTIES
36
+ *
37
+ *******************************************************************************/
38
+ export type Primitive = string | number | bigint | boolean | undefined | symbol;
39
+ type Decr = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
40
+ type Concat<T, U> = `${string & T}${string & U}`;
41
+ export type PropPath<T extends {}, AllowedTypes = any, MaxDepth extends number = 3, Prefix = ''> = MaxDepth extends number ? {
42
+ [P in keyof T]: T[P] extends Function ? never : T[P] extends AllowedTypes ? T[P] extends Primitive | ArrayLike<any> ? Concat<Prefix, P> : Concat<Prefix, P> | PropPath<T[P] & {}, AllowedTypes, Decr[MaxDepth], `${Concat<Prefix, P>}.`> : never;
43
+ }[keyof T] & string : never;
44
+ export type PropPathType<T, Path, MaxDepth extends number = 2> = MaxDepth extends number ? Path extends keyof T ? T[Path] : Path extends `${infer PropName}.${infer SubPropName}` ? PropName extends keyof T ? PropPathType<T[PropName], SubPropName, Decr[MaxDepth]> : never : never : never;
45
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ export interface Name {
2
+ firstName: string;
3
+ secondName: string;
4
+ }
5
+ export interface Coordinates {
6
+ x: number;
7
+ y: number;
8
+ }
9
+ export interface TestPerson {
10
+ id: string;
11
+ name: Name;
12
+ age: number;
13
+ address: {
14
+ coordinates: Coordinates;
15
+ postalAddress: string;
16
+ senderMethod: () => void;
17
+ };
18
+ testMethod: () => void;
19
+ deepProp: {
20
+ l1: {
21
+ l2: {
22
+ l3: {
23
+ l4: {
24
+ l5: {
25
+ l6: {};
26
+ };
27
+ };
28
+ };
29
+ };
30
+ };
31
+ };
32
+ }
33
+ export declare function samplePerson(): TestPerson;