@aws-amplify/datastore 3.14.5-unstable.4 → 3.14.5

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 (178) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/build.js +5 -0
  3. package/dist/aws-amplify-datastore.js +92853 -0
  4. package/dist/aws-amplify-datastore.js.map +1 -0
  5. package/dist/aws-amplify-datastore.min.js +65 -0
  6. package/dist/aws-amplify-datastore.min.js.map +1 -0
  7. package/index.js +7 -0
  8. package/lib/authModeStrategies/multiAuthStrategy.js +64 -6
  9. package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
  10. package/lib/datastore/datastore.js +297 -703
  11. package/lib/datastore/datastore.js.map +1 -1
  12. package/lib/index.js +4 -6
  13. package/lib/index.js.map +1 -1
  14. package/lib/predicates/index.js +6 -127
  15. package/lib/predicates/index.js.map +1 -1
  16. package/lib/predicates/sort.js +4 -10
  17. package/lib/predicates/sort.js.map +1 -1
  18. package/lib/storage/adapter/AsyncStorageAdapter.js +381 -138
  19. package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
  20. package/lib/storage/adapter/AsyncStorageDatabase.js +98 -37
  21. package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
  22. package/lib/storage/adapter/InMemoryStore.js +67 -16
  23. package/lib/storage/adapter/InMemoryStore.js.map +1 -1
  24. package/lib/storage/adapter/InMemoryStore.native.js +4 -2
  25. package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
  26. package/lib/storage/adapter/IndexedDBAdapter.js +420 -272
  27. package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
  28. package/lib/storage/adapter/getDefaultAdapter/index.js +5 -3
  29. package/lib/storage/adapter/getDefaultAdapter/index.js.map +1 -1
  30. package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -2
  31. package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
  32. package/lib/storage/storage.js +143 -72
  33. package/lib/storage/storage.js.map +1 -1
  34. package/lib/sync/datastoreConnectivity.js +55 -6
  35. package/lib/sync/datastoreConnectivity.js.map +1 -1
  36. package/lib/sync/datastoreReachability/index.native.js +4 -2
  37. package/lib/sync/datastoreReachability/index.native.js.map +1 -1
  38. package/lib/sync/index.js +124 -49
  39. package/lib/sync/index.js.map +1 -1
  40. package/lib/sync/merger.js +74 -8
  41. package/lib/sync/merger.js.map +1 -1
  42. package/lib/sync/outbox.js +97 -24
  43. package/lib/sync/outbox.js.map +1 -1
  44. package/lib/sync/processors/errorMaps.js +35 -5
  45. package/lib/sync/processors/errorMaps.js.map +1 -1
  46. package/lib/sync/processors/mutation.js +131 -47
  47. package/lib/sync/processors/mutation.js.map +1 -1
  48. package/lib/sync/processors/subscription.js +102 -29
  49. package/lib/sync/processors/subscription.js.map +1 -1
  50. package/lib/sync/processors/sync.js +102 -26
  51. package/lib/sync/processors/sync.js.map +1 -1
  52. package/lib/sync/utils.js +103 -40
  53. package/lib/sync/utils.js.map +1 -1
  54. package/lib/types.js +39 -9
  55. package/lib/types.js.map +1 -1
  56. package/lib/util.js +188 -192
  57. package/lib/util.js.map +1 -1
  58. package/lib-esm/authModeStrategies/multiAuthStrategy.js +57 -2
  59. package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
  60. package/lib-esm/datastore/datastore.d.ts +8 -59
  61. package/lib-esm/datastore/datastore.js +234 -642
  62. package/lib-esm/datastore/datastore.js.map +1 -1
  63. package/lib-esm/index.d.ts +2 -3
  64. package/lib-esm/index.js +1 -2
  65. package/lib-esm/index.js.map +1 -1
  66. package/lib-esm/predicates/index.d.ts +2 -16
  67. package/lib-esm/predicates/index.js +7 -128
  68. package/lib-esm/predicates/index.js.map +1 -1
  69. package/lib-esm/predicates/sort.js +4 -10
  70. package/lib-esm/predicates/sort.js.map +1 -1
  71. package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +1 -2
  72. package/lib-esm/storage/adapter/AsyncStorageAdapter.js +349 -109
  73. package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
  74. package/lib-esm/storage/adapter/AsyncStorageDatabase.js +68 -7
  75. package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
  76. package/lib-esm/storage/adapter/InMemoryStore.d.ts +1 -1
  77. package/lib-esm/storage/adapter/InMemoryStore.js +52 -1
  78. package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
  79. package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +2 -4
  80. package/lib-esm/storage/adapter/IndexedDBAdapter.js +368 -227
  81. package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
  82. package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +1 -1
  83. package/lib-esm/storage/storage.d.ts +6 -7
  84. package/lib-esm/storage/storage.js +101 -33
  85. package/lib-esm/storage/storage.js.map +1 -1
  86. package/lib-esm/sync/datastoreConnectivity.js +47 -1
  87. package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
  88. package/lib-esm/sync/index.js +76 -4
  89. package/lib-esm/sync/index.js.map +1 -1
  90. package/lib-esm/sync/merger.js +67 -1
  91. package/lib-esm/sync/merger.js.map +1 -1
  92. package/lib-esm/sync/outbox.js +74 -1
  93. package/lib-esm/sync/outbox.js.map +1 -1
  94. package/lib-esm/sync/processors/errorMaps.js +32 -2
  95. package/lib-esm/sync/processors/errorMaps.js.map +1 -1
  96. package/lib-esm/sync/processors/mutation.js +93 -12
  97. package/lib-esm/sync/processors/mutation.js.map +1 -1
  98. package/lib-esm/sync/processors/subscription.js +69 -6
  99. package/lib-esm/sync/processors/subscription.js.map +1 -1
  100. package/lib-esm/sync/processors/sync.js +75 -2
  101. package/lib-esm/sync/processors/sync.js.map +1 -1
  102. package/lib-esm/sync/utils.d.ts +1 -1
  103. package/lib-esm/sync/utils.js +95 -32
  104. package/lib-esm/sync/utils.js.map +1 -1
  105. package/lib-esm/types.d.ts +10 -63
  106. package/lib-esm/types.js +38 -7
  107. package/lib-esm/types.js.map +1 -1
  108. package/lib-esm/util.d.ts +6 -39
  109. package/lib-esm/util.js +171 -171
  110. package/lib-esm/util.js.map +1 -1
  111. package/package.json +14 -21
  112. package/src/authModeStrategies/multiAuthStrategy.ts +2 -2
  113. package/src/datastore/datastore.ts +206 -699
  114. package/src/index.ts +0 -4
  115. package/src/predicates/index.ts +17 -143
  116. package/src/predicates/sort.ts +2 -8
  117. package/src/storage/adapter/AsyncStorageAdapter.ts +178 -56
  118. package/src/storage/adapter/AsyncStorageDatabase.ts +15 -16
  119. package/src/storage/adapter/InMemoryStore.ts +2 -5
  120. package/src/storage/adapter/IndexedDBAdapter.ts +191 -166
  121. package/src/storage/adapter/getDefaultAdapter/index.ts +2 -2
  122. package/src/storage/storage.ts +37 -56
  123. package/src/sync/datastoreConnectivity.ts +4 -4
  124. package/src/sync/index.ts +28 -22
  125. package/src/sync/merger.ts +1 -1
  126. package/src/sync/outbox.ts +6 -6
  127. package/src/sync/processors/errorMaps.ts +1 -1
  128. package/src/sync/processors/mutation.ts +19 -23
  129. package/src/sync/processors/subscription.ts +16 -20
  130. package/src/sync/processors/sync.ts +17 -17
  131. package/src/sync/utils.ts +48 -42
  132. package/src/types.ts +16 -128
  133. package/src/util.ts +150 -108
  134. package/webpack.config.dev.js +6 -0
  135. package/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
  136. package/lib/authModeStrategies/index.d.ts +0 -2
  137. package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -13
  138. package/lib/datastore/datastore.d.ts +0 -207
  139. package/lib/index.d.ts +0 -16
  140. package/lib/predicates/index.d.ts +0 -30
  141. package/lib/predicates/next.d.ts +0 -301
  142. package/lib/predicates/next.js +0 -816
  143. package/lib/predicates/next.js.map +0 -1
  144. package/lib/predicates/sort.d.ts +0 -8
  145. package/lib/ssr/index.d.ts +0 -3
  146. package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -42
  147. package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -39
  148. package/lib/storage/adapter/InMemoryStore.d.ts +0 -11
  149. package/lib/storage/adapter/InMemoryStore.native.d.ts +0 -1
  150. package/lib/storage/adapter/IndexedDBAdapter.d.ts +0 -61
  151. package/lib/storage/adapter/getDefaultAdapter/index.d.ts +0 -3
  152. package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -3
  153. package/lib/storage/adapter/index.d.ts +0 -9
  154. package/lib/storage/relationship.d.ts +0 -140
  155. package/lib/storage/relationship.js +0 -335
  156. package/lib/storage/relationship.js.map +0 -1
  157. package/lib/storage/storage.d.ts +0 -50
  158. package/lib/sync/datastoreConnectivity.d.ts +0 -16
  159. package/lib/sync/datastoreReachability/index.d.ts +0 -3
  160. package/lib/sync/datastoreReachability/index.native.d.ts +0 -3
  161. package/lib/sync/index.d.ts +0 -89
  162. package/lib/sync/merger.d.ts +0 -17
  163. package/lib/sync/outbox.d.ts +0 -27
  164. package/lib/sync/processors/errorMaps.d.ts +0 -17
  165. package/lib/sync/processors/mutation.d.ts +0 -58
  166. package/lib/sync/processors/subscription.d.ts +0 -33
  167. package/lib/sync/processors/sync.d.ts +0 -28
  168. package/lib/sync/utils.d.ts +0 -42
  169. package/lib/types.d.ts +0 -554
  170. package/lib/util.d.ts +0 -189
  171. package/lib-esm/predicates/next.d.ts +0 -301
  172. package/lib-esm/predicates/next.js +0 -812
  173. package/lib-esm/predicates/next.js.map +0 -1
  174. package/lib-esm/storage/relationship.d.ts +0 -140
  175. package/lib-esm/storage/relationship.js +0 -333
  176. package/lib-esm/storage/relationship.js.map +0 -1
  177. package/src/predicates/next.ts +0 -967
  178. package/src/storage/relationship.ts +0 -272
@@ -1,207 +0,0 @@
1
- import Observable from 'zen-observable-ts';
2
- import { PredicateAll } from '../predicates';
3
- import { ConflictHandler, DataStoreConfig, NonModelTypeConstructor, ProducerPaginationInput, PersistentModel, PersistentModelConstructor, Schema, SubscriptionMessage, DataStoreSnapshot, TypeConstructorMap, ErrorHandler, ObserveQueryOptions, PersistentModelMetaData, IdentifierFieldOrIdentifierObject } from '../types';
4
- import { RecursiveModelPredicateExtender, ModelPredicateExtender } from '../predicates/next';
5
- export declare let syncClasses: TypeConstructorMap;
6
- /**
7
- * Describes whether and to what a model is attached for lazy loading purposes.
8
- */
9
- declare enum ModelAttachment {
10
- /**
11
- * Model doesn't lazy load from any data source.
12
- *
13
- * Related entity properties provided at instantiation are returned
14
- * via the respective lazy interfaces when their properties are invoked.
15
- */
16
- Detached = "Detached",
17
- /**
18
- * Model lazy loads from the global DataStore.
19
- */
20
- DataStore = "DataStore",
21
- /**
22
- * Demonstrative. Not yet implemented.
23
- */
24
- API = "API"
25
- }
26
- /**
27
- * Registers a model instance against a data source (DataStore, API, or
28
- * Detached/None).
29
- *
30
- * The API option is demonstrative. Lazy loading against API is not yet
31
- * implemented.
32
- *
33
- * @param result A model instance or array of instances
34
- * @param attachment A ModelAttachment data source
35
- * @returns passes the `result` back through after attachment
36
- */
37
- export declare function attached<T extends PersistentModel | PersistentModel[]>(result: T, attachment: ModelAttachment): T;
38
- /**
39
- * Determines what source a model instance should lazy load from.
40
- *
41
- * If the instace was never explicitly registered, it is detached by default.
42
- *
43
- * @param instance A model instance
44
- */
45
- export declare const getAttachment: (instance: Readonly<Record<string, any>>) => ModelAttachment.Detached | ModelAttachment;
46
- declare const initSchema: (userSchema: Schema) => Record<string, PersistentModelConstructor<any> | NonModelTypeConstructor<unknown>>;
47
- /**
48
- * Constructs a model and records it with its metadata in a weakset. Allows for
49
- * the separate storage of core model fields and Amplify/DataStore metadata
50
- * fields that the customer app does not want exposed.
51
- *
52
- * @param modelConstructor The model constructor.
53
- * @param init Init data that would normally be passed to the constructor.
54
- * @returns The initialized model.
55
- */
56
- export declare type ModelInstanceCreator = typeof modelInstanceCreator;
57
- declare function modelInstanceCreator<T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, init: Partial<T>): T;
58
- export declare class AsyncItem<T> extends Promise<T> {
59
- }
60
- export declare class AsyncCollection<T> implements AsyncIterable<T> {
61
- private values;
62
- constructor(values: Array<any> | Promise<Array<any>>);
63
- [Symbol.asyncIterator](): AsyncIterator<T>;
64
- toArray({ max, }?: {
65
- max?: number;
66
- }): Promise<T[]>;
67
- }
68
- declare class DataStore {
69
- private Auth;
70
- private API;
71
- private Cache;
72
- private amplifyConfig;
73
- private authModeStrategy;
74
- private conflictHandler;
75
- private errorHandler;
76
- private fullSyncInterval;
77
- private initialized?;
78
- private initReject;
79
- private initResolve;
80
- private maxRecordsToSync;
81
- private storage?;
82
- private sync?;
83
- private syncPageSize;
84
- private syncExpressions;
85
- private syncPredicates;
86
- private sessionId?;
87
- private storageAdapter;
88
- private amplifyContext;
89
- private connectivityMonitor?;
90
- /**
91
- * **IMPORTANT!**
92
- *
93
- * Accumulator for background things that can **and MUST** be called when
94
- * DataStore stops.
95
- *
96
- * These jobs **MUST** be *idempotent promises* that resolve ONLY
97
- * once the intended jobs are completely finished and/or otherwise destroyed
98
- * and cleaned up with ZERO outstanding:
99
- *
100
- * 1. side effects (e.g., state changes)
101
- * 1. callbacks
102
- * 1. subscriptions
103
- * 1. calls to storage
104
- * 1. *etc.*
105
- *
106
- * Methods that create pending promises, subscriptions, callbacks, or any
107
- * type of side effect **MUST** be registered with the manager. And, a new
108
- * manager must be created after each `exit()`.
109
- *
110
- * Failure to comply will put DataStore into a highly unpredictable state
111
- * when it needs to stop or clear -- which occurs when restarting with new
112
- * sync expressions, during testing, and potentially during app code
113
- * recovery handling, etc..
114
- *
115
- * It is up to the discretion of each disposer whether to wait for job
116
- * completion or to cancel operations and issue failures *as long as the
117
- * disposer returns in a reasonable amount of time.*
118
- *
119
- * (Reasonable = *seconds*, not minutes.)
120
- */
121
- private runningProcesses;
122
- /**
123
- * Indicates what state DataStore is in.
124
- *
125
- * Not [yet?] used for actual state management; but for messaging
126
- * when errors occur, to help troubleshoot.
127
- */
128
- private state;
129
- getModuleName(): string;
130
- /**
131
- * Builds a function to capture `BackgroundManagerNotOpenError`'s to produce friendlier,
132
- * more instructive errors for customers.
133
- *
134
- * @param operation The name of the operation (usually a Datastore method) the customer
135
- * tried to call.
136
- */
137
- handleAddProcError(operation: string): (err: Error) => never;
138
- /**
139
- * If not already done:
140
- * 1. Attaches and initializes storage.
141
- * 1. Loads the schema and records metadata.
142
- * 1. If `this.amplifyConfig.aws_appsync_graphqlEndpoint` contains a URL,
143
- * attaches a sync engine, starts it, and subscribes.
144
- */
145
- start: () => Promise<void>;
146
- query: {
147
- <T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, identifier: IdentifierFieldOrIdentifierObject<T, PersistentModelMetaData<T>>): Promise<T | undefined>;
148
- <T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, criteria?: RecursiveModelPredicateExtender<T> | typeof PredicateAll | null, paginationProducer?: ProducerPaginationInput<T>): Promise<T[]>;
149
- };
150
- save: <T extends Readonly<Record<string, any>>>(model: T, condition?: ModelPredicateExtender<T>) => Promise<T>;
151
- setConflictHandler: (config: DataStoreConfig) => ConflictHandler;
152
- setErrorHandler: (config: DataStoreConfig) => ErrorHandler;
153
- delete: {
154
- <T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, identifier: IdentifierFieldOrIdentifierObject<T, PersistentModelMetaData<T>>): Promise<T[]>;
155
- <T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, condition: ModelPredicateExtender<T> | typeof PredicateAll): Promise<T[]>;
156
- <T extends PersistentModel>(model: T, condition?: ModelPredicateExtender<T>): Promise<T>;
157
- };
158
- observe: {
159
- (): Observable<SubscriptionMessage<PersistentModel>>;
160
- <T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, identifier: string): Observable<SubscriptionMessage<T>>;
161
- <T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, criteria?: RecursiveModelPredicateExtender<T> | typeof PredicateAll): Observable<SubscriptionMessage<T>>;
162
- <T extends PersistentModel>(model: T): Observable<SubscriptionMessage<T>>;
163
- };
164
- observeQuery: {
165
- <T extends PersistentModel>(modelConstructor: PersistentModelConstructor<T>, criteria?: RecursiveModelPredicateExtender<T> | typeof PredicateAll, paginationProducer?: ObserveQueryOptions<T>): Observable<DataStoreSnapshot<T>>;
166
- };
167
- configure: (config?: DataStoreConfig) => void;
168
- /**
169
- * Clears all data from storage and removes all data, schema info, other
170
- * initialization details, and then stops DataStore.
171
- *
172
- * That said, reinitialization is required after clearing. This can be done
173
- * by explicitiliy calling `start()` or any method that implicitly starts
174
- * DataStore, such as `query()`, `save()`, or `delete()`.
175
- */
176
- clear(): Promise<void>;
177
- /**
178
- * Stops all DataStore sync activities.
179
- *
180
- * TODO: "Waits for graceful termination of
181
- * running queries and terminates subscriptions."
182
- */
183
- stop(this: InstanceType<typeof DataStore>): Promise<void>;
184
- /**
185
- * Validates given pagination input from a query and creates a pagination
186
- * argument for use against the storage layer.
187
- *
188
- * @param modelDefinition
189
- * @param paginationProducer
190
- */
191
- private processPagination;
192
- /**
193
- * Examines the configured `syncExpressions` and produces a WeakMap of
194
- * SchemaModel -> predicate to use during sync.
195
- */
196
- private processSyncExpressions;
197
- private createFromCondition;
198
- private unwrapPromise;
199
- private weakMapFromEntries;
200
- /**
201
- * A session ID to allow CMS to open databases against multiple apps.
202
- * This session ID is only expected be set by AWS Amplify Studio.
203
- */
204
- private retrieveSessionId;
205
- }
206
- declare const instance: DataStore;
207
- export { DataStore as DataStoreClass, initSchema, instance as DataStore };
package/lib/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- export { DataStore, DataStoreClass, initSchema, ModelInstanceCreator, AsyncCollection, AsyncItem, } from './datastore/datastore';
2
- export { Predicates, ModelPredicateCreator, ModelSortPredicateCreator, } from './predicates';
3
- export { Adapter as StorageAdapter } from './storage/adapter';
4
- export { NAMESPACES } from './util';
5
- export declare const utils: {
6
- USER: import("./util").NAMESPACES;
7
- traverseModel: <T extends Readonly<Record<string, any>>>(srcModelName: string, instance: T, namespace: import("./types").SchemaNamespace, modelInstanceCreator: <T_1 extends Readonly<Record<string, any>>>(modelConstructor: import("./types").PersistentModelConstructor<T_1>, init: Partial<T_1>) => T_1, getModelConstructorByModelName: (namsespaceName: import("./util").NAMESPACES, modelName: string) => import("./types").PersistentModelConstructor<any>) => {
8
- modelName: string;
9
- item: T;
10
- instance: T;
11
- }[];
12
- validatePredicate: <T_2 extends Readonly<Record<string, any>>>(model: T_2, groupType: "and" | "or" | "not", predicatesOrGroups: (import("./types").PredicateObject<T_2> | import("./types").PredicatesGroup<T_2>)[]) => any;
13
- isNonModelConstructor: (obj: any) => obj is import("./types").NonModelTypeConstructor<any>;
14
- isModelConstructor: <T_3 extends Readonly<Record<string, any>>>(obj: any) => obj is import("./types").PersistentModelConstructor<T_3>;
15
- };
16
- export * from './types';
@@ -1,30 +0,0 @@
1
- import { ModelPredicate, PersistentModel, PredicatesGroup, ProducerModelPredicate, SchemaModel } from '../types';
2
- export { ModelSortPredicateCreator } from './sort';
3
- export declare function isPredicatesAll(predicate: any): predicate is typeof PredicateAll;
4
- export declare const comparisonKeys: Set<string>;
5
- export declare const PredicateAll: unique symbol;
6
- export declare class Predicates {
7
- static get ALL(): typeof PredicateAll;
8
- }
9
- export declare class ModelPredicateCreator {
10
- private static predicateGroupsMap;
11
- static createPredicateBuilder<T extends PersistentModel>(modelDefinition: SchemaModel): ModelPredicate<T>;
12
- static isValidPredicate<T extends PersistentModel>(predicate: any): predicate is ModelPredicate<T>;
13
- static getPredicates<T extends PersistentModel>(predicate: ModelPredicate<T>, throwOnInvalid?: boolean): PredicatesGroup<any>;
14
- static createFromExisting<T extends PersistentModel>(modelDefinition?: SchemaModel, existing?: ProducerModelPredicate<T>): ModelPredicate<T>;
15
- static createForSingleField<T extends PersistentModel>(modelDefinition: SchemaModel, fieldName: string, value: string): ModelPredicate<T>;
16
- static createForPk<T extends PersistentModel>(modelDefinition: SchemaModel, model: T): ModelPredicate<T>;
17
- /**
18
- * Searches a `Model` table for records matching the given equalities object.
19
- *
20
- * This only matches against fields given in the equalities object. No other
21
- * fields are tested by the predicate.
22
- *
23
- * @param modelDefinition The model we need a predicate for.
24
- * @param flatEqualities An object holding field equalities to search for.
25
- */
26
- static createFromFlatEqualities<T extends PersistentModel>(modelDefinition: SchemaModel, flatEqualities: Record<string, any>): ModelPredicate<T>;
27
- static createGroupFromExisting<T extends PersistentModel>(modelDefinition: SchemaModel, group: 'and' | 'or' | 'not', existingPredicates: (ProducerModelPredicate<T> | ModelPredicate<T>)[]): ModelPredicate<T>;
28
- static transformGraphQLtoPredicateAST(gql: any): any;
29
- static createFromAST(modelDefinition: SchemaModel, ast: any): ModelPredicate<any>;
30
- }
@@ -1,301 +0,0 @@
1
- import { Scalar, PersistentModel, ModelMeta, AllOperators, PredicateFieldType, ModelPredicate as StoragePredicate } from '../types';
2
- import { ExclusiveStorage as StorageAdapter } from '../storage/storage';
3
- declare type MatchableTypes = string | string[] | number | number[] | boolean | boolean[];
4
- declare type AllFieldOperators = keyof AllOperators;
5
- declare type NonNeverKeys<T> = {
6
- [K in keyof T]: T[K] extends never ? never : K;
7
- }[keyof T];
8
- declare type WithoutNevers<T> = Pick<T, NonNeverKeys<T>>;
9
- /**
10
- * A function that accepts a RecursiveModelPrecicate<T>, which it must use to
11
- * return a final condition.
12
- *
13
- * This is used in `DataStore.query()`, `DataStore.observe()`, and
14
- * `DataStore.observeQuery()` as the second argument. E.g.,
15
- *
16
- * ```
17
- * DataStore.query(MyModel, model => model.field.eq('some value'))
18
- * ```
19
- *
20
- * More complex queries should also be supported. E.g.,
21
- *
22
- * ```
23
- * DataStore.query(MyModel, model => model.and(m => [
24
- * m.relatedEntity.or(relative => [
25
- * relative.relativeField.eq('whatever'),
26
- * relative.relativeField.eq('whatever else')
27
- * ]),
28
- * m.myModelField.ne('something')
29
- * ]))
30
- * ```
31
- */
32
- export declare type RecursiveModelPredicateExtender<RT extends PersistentModel> = (lambda: RecursiveModelPredicate<RT>) => PredicateInternalsKey;
33
- export declare type RecursiveModelPredicateAggregateExtender<RT extends PersistentModel> = (lambda: RecursiveModelPredicate<RT>) => PredicateInternalsKey[];
34
- declare type RecursiveModelPredicateOperator<RT extends PersistentModel> = (predicates: RecursiveModelPredicateAggregateExtender<RT>) => PredicateInternalsKey;
35
- declare type RecursiveModelPredicateNegation<RT extends PersistentModel> = (predicate: RecursiveModelPredicateExtender<RT>) => PredicateInternalsKey;
36
- export declare type RecursiveModelPredicate<RT extends PersistentModel> = {
37
- [K in keyof RT]-?: PredicateFieldType<RT[K]> extends PersistentModel ? RecursiveModelPredicate<PredicateFieldType<RT[K]>> : ValuePredicate<RT, RT[K]>;
38
- } & {
39
- or: RecursiveModelPredicateOperator<RT>;
40
- and: RecursiveModelPredicateOperator<RT>;
41
- not: RecursiveModelPredicateNegation<RT>;
42
- } & PredicateInternalsKey;
43
- /**
44
- * A function that accepts a ModelPrecicate<T>, which it must use to return a
45
- * final condition.
46
- *
47
- * This is used as predicates in `DataStore.save()`, `DataStore.delete()`, and
48
- * DataStore sync expressions.
49
- *
50
- * ```
51
- * DataStore.save(record, model => model.field.eq('some value'))
52
- * ```
53
- *
54
- * Logical operators are supported. But, condtiions are related records are
55
- * NOT supported. E.g.,
56
- *
57
- * ```
58
- * DataStore.delete(record, model => model.or(m => [
59
- * m.field.eq('whatever'),
60
- * m.field.eq('whatever else')
61
- * ]))
62
- * ```
63
- */
64
- export declare type ModelPredicateExtender<RT extends PersistentModel> = (lambda: ModelPredicate<RT>) => PredicateInternalsKey;
65
- export declare type ModelPredicateAggregateExtender<RT extends PersistentModel> = (lambda: ModelPredicate<RT>) => PredicateInternalsKey[];
66
- declare type ValuePredicate<RT extends PersistentModel, MT extends MatchableTypes> = {
67
- [K in AllFieldOperators]: K extends 'between' ? (inclusiveLowerBound: Scalar<MT>, inclusiveUpperBound: Scalar<MT>) => PredicateInternalsKey : (operand: Scalar<MT>) => PredicateInternalsKey;
68
- };
69
- export declare type ModelPredicate<RT extends PersistentModel> = WithoutNevers<{
70
- [K in keyof RT]-?: PredicateFieldType<RT[K]> extends PersistentModel ? never : ValuePredicate<RT, RT[K]>;
71
- }> & {
72
- or: ModelPredicateOperator<RT>;
73
- and: ModelPredicateOperator<RT>;
74
- not: ModelPredicateNegation<RT>;
75
- } & PredicateInternalsKey;
76
- declare type ModelPredicateOperator<RT extends PersistentModel> = (predicates: ModelPredicateAggregateExtender<RT>) => PredicateInternalsKey;
77
- declare type ModelPredicateNegation<RT extends PersistentModel> = (predicate: ModelPredicateExtender<RT>) => PredicateInternalsKey;
78
- declare type GroupOperator = 'and' | 'or' | 'not';
79
- declare type UntypedCondition = {
80
- fetch: (storage: StorageAdapter) => Promise<Record<string, any>[]>;
81
- matches: (item: Record<string, any>) => Promise<boolean>;
82
- copy(extract: GroupCondition): [UntypedCondition, GroupCondition | undefined];
83
- toAST(): any;
84
- };
85
- /**
86
- * A pointer used by DataStore internally to lookup predicate details
87
- * that should not be exposed on public customer interfaces.
88
- */
89
- export declare class PredicateInternalsKey {
90
- private __isPredicateInternalsKeySentinel;
91
- }
92
- /**
93
- * Takes a key object from `registerPredicateInternals()` to fetch an internal
94
- * `GroupCondition` object, which can then be used to query storage or
95
- * test/match objects.
96
- *
97
- * This indirection exists to hide `GroupCondition` from public interfaces, since
98
- * `GroupCondition` contains extra methods and properties that public callers
99
- * should not use.
100
- *
101
- * @param key A key object previously returned by `registerPredicateInternals()`
102
- */
103
- export declare const internals: (key: any) => GroupCondition;
104
- /**
105
- * A condition that can operate against a single "primitive" field of a model or item.
106
- * @member field The field of *some record* to test against.
107
- * @member operator The equality or comparison operator to use.
108
- * @member operands The operands for the equality/comparison check.
109
- */
110
- export declare class FieldCondition {
111
- field: string;
112
- operator: string;
113
- operands: string[];
114
- constructor(field: string, operator: string, operands: string[]);
115
- /**
116
- * Creates a copy of self.
117
- * @param extract Not used. Present only to fulfill the `UntypedCondition` interface.
118
- * @returns A new, identitical `FieldCondition`.
119
- */
120
- copy(extract: GroupCondition): [FieldCondition, GroupCondition | undefined];
121
- toAST(): {
122
- [x: string]: {
123
- [x: string]: string | string[];
124
- };
125
- };
126
- /**
127
- * Not implemented. Not needed. GroupCondition instead consumes FieldConditions and
128
- * transforms them into legacy predicates. (*For now.*)
129
- * @param storage N/A. If ever implemented, the storage adapter to query.
130
- * @returns N/A. If ever implemented, return items from `storage` that match.
131
- */
132
- fetch(storage: StorageAdapter): Promise<Record<string, any>[]>;
133
- /**
134
- * Determins whether a given item matches the expressed condition.
135
- * @param item The item to test.
136
- * @returns `Promise<boolean>`, `true` if matches; `false` otherwise.
137
- */
138
- matches(item: Record<string, any>): Promise<boolean>;
139
- /**
140
- * Checks `this.operands` for compatibility with `this.operator`.
141
- */
142
- validate(): void;
143
- }
144
- /**
145
- * A set of sub-conditions to operate against a model, optionally scoped to
146
- * a specific field, combined with the given operator (one of `and`, `or`, or `not`).
147
- * @member groupId Used to distinguish between GroupCondition instances for
148
- * debugging and troublehsooting.
149
- * @member model A metadata object that tells GroupCondition what to query and how.
150
- * @member field The field on the model that the sub-conditions apply to.
151
- * @member operator How to group child conditions together.
152
- * @member operands The child conditions.
153
- */
154
- export declare class GroupCondition {
155
- /**
156
- * The `ModelMeta` of the model to query and/or filter against.
157
- * Expected to contain:
158
- *
159
- * ```js
160
- * {
161
- * builder: ModelConstructor,
162
- * schema: SchemaModel,
163
- * pkField: string[]
164
- * }
165
- * ```
166
- */
167
- model: ModelMeta<any>;
168
- /**
169
- * If populated, this group specifices a condition on a relationship.
170
- *
171
- * If `field` does *not* point to a related model, that's an error. It
172
- * could indicate that the `GroupCondition` was instantiated with bad
173
- * data, or that the model metadata is incorrect.
174
- */
175
- field: string | undefined;
176
- /**
177
- * If a `field` is given, whether the relationship is a `HAS_ONE`,
178
- * 'HAS_MANY`, or `BELONGS_TO`.
179
- *
180
- * TODO: Remove this and replace with derivation using
181
- * `ModelRelationship.from(this.model, this.field).relationship`;
182
- */
183
- relationshipType: string | undefined;
184
- /**
185
- *
186
- */
187
- operator: GroupOperator;
188
- /**
189
- *
190
- */
191
- operands: UntypedCondition[];
192
- groupId: string;
193
- constructor(
194
- /**
195
- * The `ModelMeta` of the model to query and/or filter against.
196
- * Expected to contain:
197
- *
198
- * ```js
199
- * {
200
- * builder: ModelConstructor,
201
- * schema: SchemaModel,
202
- * pkField: string[]
203
- * }
204
- * ```
205
- */
206
- model: ModelMeta<any>,
207
- /**
208
- * If populated, this group specifices a condition on a relationship.
209
- *
210
- * If `field` does *not* point to a related model, that's an error. It
211
- * could indicate that the `GroupCondition` was instantiated with bad
212
- * data, or that the model metadata is incorrect.
213
- */
214
- field: string | undefined,
215
- /**
216
- * If a `field` is given, whether the relationship is a `HAS_ONE`,
217
- * 'HAS_MANY`, or `BELONGS_TO`.
218
- *
219
- * TODO: Remove this and replace with derivation using
220
- * `ModelRelationship.from(this.model, this.field).relationship`;
221
- */
222
- relationshipType: string | undefined,
223
- /**
224
- *
225
- */
226
- operator: GroupOperator,
227
- /**
228
- *
229
- */
230
- operands: UntypedCondition[]);
231
- /**
232
- * Returns a copy of a GroupCondition, which also returns the copy of a
233
- * given reference node to "extract".
234
- * @param extract A node of interest. Its copy will *also* be returned if the node exists.
235
- * @returns [The full copy, the copy of `extract` | undefined]
236
- */
237
- copy(extract: GroupCondition): [GroupCondition, GroupCondition | undefined];
238
- /**
239
- * Fetches matching records from a given storage adapter using legacy predicates (for now).
240
- * @param storage The storage adapter this predicate will query against.
241
- * @param breadcrumb For debugging/troubleshooting. A list of the `groupId`'s this
242
- * GroupdCondition.fetch is nested within.
243
- * @param negate Whether to match on the `NOT` of `this`.
244
- * @returns An `Promise` of `any[]` from `storage` matching the child conditions.
245
- */
246
- fetch(storage: StorageAdapter, breadcrumb?: string[], negate?: boolean): Promise<Record<string, any>[]>;
247
- /**
248
- * Determines whether a single item matches the conditions of `this`.
249
- * When checking the target `item`'s properties, each property will be `await`'d
250
- * to ensure lazy-loading is respected where applicable.
251
- * @param item The item to match against.
252
- * @param ignoreFieldName Tells `match()` that the field name has already been dereferenced.
253
- * (Used for iterating over children on HAS_MANY checks.)
254
- * @returns A boolean (promise): `true` if matched, `false` otherwise.
255
- */
256
- matches(item: Record<string, any>, ignoreFieldName?: boolean): Promise<boolean>;
257
- /**
258
- * Tranfsorm to a AppSync GraphQL compatible AST.
259
- * (Does not support filtering in nested types.)
260
- */
261
- toAST(): {
262
- [x: string]: any[];
263
- };
264
- toStoragePredicate<T>(baseCondition?: StoragePredicate<T>): StoragePredicate<T>;
265
- }
266
- /**
267
- * Creates a "seed" predicate that can be used to build an executable condition.
268
- * This is used in `query()`, for example, to seed customer- E.g.,
269
- *
270
- * ```
271
- * const p = predicateFor({builder: modelConstructor, schema: modelSchema, pkField: string[]});
272
- * p.and(child => [
273
- * child.field.eq('whatever'),
274
- * child.childModel.childField.eq('whatever else'),
275
- * child.childModel.or(child => [
276
- * child.otherField.contains('x'),
277
- * child.otherField.contains('y'),
278
- * child.otherField.contains('z'),
279
- * ])
280
- * ])
281
- * ```
282
- *
283
- * `predicateFor()` returns objecst with recursive getters. To facilitate this,
284
- * a `query` and `tail` can be provided to "accumulate" nested conditions.
285
- *
286
- * TODO: the sortof-immutable algorithm was originally done to support legacy style
287
- * predicate branching (`p => p.x.eq(value).y.eq(value)`). i'm not sure this is
288
- * necessary or beneficial at this point, since we decided that each field condition
289
- * must flly terminate a branch. is the strong mutation barrier between chain links
290
- * still necessary or helpful?
291
- *
292
- * @param ModelType The ModelMeta used to build child properties.
293
- * @param field Scopes the query branch to a field.
294
- * @param query A base query to build on. Omit to start a new query.
295
- * @param tail The point in an existing `query` to attach new conditions to.
296
- * @returns A ModelPredicate (builder) that customers can create queries with.
297
- * (As shown in function description.)
298
- */
299
- export declare function recursivePredicateFor<T extends PersistentModel>(ModelType: ModelMeta<T>, allowRecursion?: boolean, field?: string, query?: GroupCondition, tail?: GroupCondition): RecursiveModelPredicate<T> & PredicateInternalsKey;
300
- export declare function predicateFor<T extends PersistentModel>(ModelType: ModelMeta<T>): ModelPredicate<T> & PredicateInternalsKey;
301
- export {};