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

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 +27 -0
  2. package/build.js +5 -0
  3. package/dist/aws-amplify-datastore.js +92626 -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,272 +0,0 @@
1
- import { isFieldAssociation, ModelFieldType, ModelMeta } from '../types';
2
-
3
- /**
4
- * Defines a relationship from a LOCAL model.field to a REMOTE model.field and helps
5
- * navigate the relationship, providing a simplified peek at the relationship details
6
- * pertinent to setting FK's and constructing join conditions.
7
- *
8
- * Because I mean, relationships are tough.
9
- *
10
- */
11
- export class ModelRelationship<T> {
12
- private localModel: ModelMeta<T>;
13
- private _field: string;
14
-
15
- /**
16
- * @param modelDefinition The "local" model.
17
- * @param field The "local" model field.
18
- */
19
- constructor(model: ModelMeta<T>, field: string) {
20
- if (!isFieldAssociation(model.schema, field)) {
21
- throw new Error(`${model.schema.name}.${field} is not a relationship.`);
22
- }
23
- this.localModel = model;
24
- this._field = field;
25
- }
26
-
27
- /**
28
- * Returns a ModelRelationship for the the given model and field if the pair
29
- * indicates a relationship to another model. Else, returns `null`.
30
- *
31
- * @param model The model the relationship field exists in.
32
- * @param field The field that may relates the local model to the remote model.
33
- */
34
- static from<T>(model: ModelMeta<T>, field: string) {
35
- if (isFieldAssociation(model.schema, field)) {
36
- return new this(model, field);
37
- } else {
38
- return null;
39
- }
40
- }
41
-
42
- /**
43
- * Enumerates all valid `ModelRelationship`'s on the given model.
44
- *
45
- * @param model The model definition to enumerate relationships of.
46
- */
47
- static allFrom<T>(model: ModelMeta<T>) {
48
- const relationships: ModelRelationship<T>[] = [];
49
- for (const field of Object.keys(model.schema.fields)) {
50
- const relationship = ModelRelationship.from(model, field);
51
- relationship && relationships.push(relationship);
52
- }
53
- return relationships;
54
- }
55
-
56
- private get localDefinition() {
57
- return this.localModel.schema;
58
- }
59
-
60
- /**
61
- * The virtual/computed field on the local model that should contain
62
- * the related model.
63
- */
64
- get field() {
65
- return this._field;
66
- }
67
-
68
- /**
69
- * The constructor that can be used to query DataStore or create instance for
70
- * the local model.
71
- */
72
- get localConstructor() {
73
- return this.localModel.builder;
74
- }
75
-
76
- /**
77
- * The name/type of the relationship the local model has with the remote model
78
- * via the defined local model field.
79
- */
80
- get type() {
81
- return this.localAssocation.connectionType;
82
- }
83
-
84
- /**
85
- * Raw details about the local FK as-is from the local model's field definition in
86
- * the schema. This field requires interpretation.
87
- *
88
- * @see localJoinFields
89
- * @see localAssociatedWith
90
- */
91
- private get localAssocation() {
92
- return this.localDefinition.fields[this.field].association!;
93
- }
94
-
95
- /**
96
- * The field names on the local model that can be used to query or queried to match
97
- * with instances of the remote model.
98
- *
99
- * Fields are returned in-order to match the order of `this.remoteKeyFields`.
100
- */
101
- get localJoinFields() {
102
- /**
103
- * This is relatively straightforward, actually.
104
- *
105
- * If we have explicitly stated targetNames, codegen is telling us authoritatively
106
- * to use those fields for this relationship. The local model "points to" fields
107
- * in the remote one.
108
- *
109
- * In other cases, the remote model points to this one's
110
- */
111
- if (this.localAssocation.targetName) {
112
- // This case is theoretically unnecessary going forward.
113
- return [this.localAssocation.targetName];
114
- } else if (this.localAssocation.targetNames) {
115
- return this.localAssocation.targetNames;
116
- } else {
117
- return this.localPKFields;
118
- }
119
- }
120
-
121
- /**
122
- * The field names on the local model that uniquely identify it.
123
- *
124
- * These fields may or may not be relevant to the join fields.
125
- */
126
- get localPKFields() {
127
- return this.localModel.pkField;
128
- }
129
-
130
- get remoteDefinition() {
131
- return this.remoteModelType.modelConstructor?.schema;
132
- }
133
-
134
- private get remoteModelType() {
135
- return this.localDefinition.fields[this.field].type as ModelFieldType;
136
- }
137
-
138
- /**
139
- * Constructor that can be used to query DataStore or create instances for
140
- * the remote model.
141
- */
142
- get remoteModelConstructor() {
143
- return this.remoteModelType.modelConstructor!.builder!;
144
- }
145
-
146
- /**
147
- * The field names on the remote model that uniquely identify it.
148
- *
149
- * These fields may or may not be relevant to the join fields.
150
- */
151
- get remotePKFields() {
152
- return this.remoteModelType.modelConstructor?.pkField || ['id'];
153
- }
154
-
155
- /**
156
- * The `associatedWith` fields from the local perspective.
157
- *
158
- * When present, these fields indicate which fields on the remote model to use
159
- * when looking for a remote association and/or determining the final remote
160
- * key fields.
161
- */
162
- private get localAssociatedWith() {
163
- if (
164
- this.localAssocation.connectionType === 'HAS_MANY' ||
165
- this.localAssocation.connectionType === 'HAS_ONE'
166
- ) {
167
- // This de-arraying is theoretically unnecessary going forward.
168
- return Array.isArray(this.localAssocation.associatedWith)
169
- ? this.localAssocation.associatedWith
170
- : [this.localAssocation.associatedWith];
171
- } else {
172
- return undefined;
173
- }
174
- }
175
-
176
- private get explicitRemoteAssociation() {
177
- if (this.localAssociatedWith) {
178
- if (this.localAssociatedWith.length === 1) {
179
- return this.remoteDefinition!.fields[this.localAssociatedWith[0]]
180
- ?.association;
181
- } else {
182
- return undefined;
183
- }
184
- }
185
- }
186
-
187
- /**
188
- * The field names on the remote model that can used to query or queried to match
189
- * with instances of the local model.
190
- *
191
- * Fields are returned in-order to match the order of `this.localKeyFields`.
192
- */
193
- get remoteJoinFields() {
194
- /**
195
- * If the local relationship explicitly names "associated with" fields, we
196
- * need to see if this points direction to a reciprocating assocation. If it
197
- * does, the remote assocation indicates what fields to use.
198
- */
199
-
200
- if (this.explicitRemoteAssociation?.targetName) {
201
- // This case is theoretically unnecessary going forward.
202
- return [this.explicitRemoteAssociation.targetName!];
203
- } else if (this.explicitRemoteAssociation?.targetNames) {
204
- return this.explicitRemoteAssociation?.targetNames!;
205
- } else if (this.localAssociatedWith) {
206
- return this.localAssociatedWith;
207
- } else {
208
- return this.remotePKFields;
209
- }
210
- }
211
-
212
- /**
213
- * Whether this relationship everything necessary to get, set, and query from
214
- * the perspective of the local model provided at instantiation.
215
- */
216
- get isComplete() {
217
- return this.localJoinFields.length > 0 && this.remoteJoinFields.length > 0;
218
- }
219
-
220
- /**
221
- * Creates an FK mapper object with respect to the given related instance.
222
- *
223
- * E.g., if the local FK fields are `[parentId, parentName]` and point to
224
- * `[customId, name]` on the remote model, `createLocalFKObject(remote)`
225
- * will return:
226
- *
227
- * ```
228
- * {
229
- * parentId: remote.customId,
230
- * parentName: remote.name
231
- * }
232
- * ```
233
- *
234
- * @param remote The remote related instance.
235
- */
236
- createLocalFKObject(remote: any) {
237
- const fk = {} as Record<string, string>;
238
- for (let i = 0; i < this.localJoinFields.length; i++) {
239
- fk[this.localJoinFields[i]] = remote[this.remoteJoinFields[i]];
240
- }
241
- return fk;
242
- }
243
-
244
- /**
245
- * Creates an query mapper object to help fetch the remote instance(s) or
246
- * `null` if any of the necessary local fields are `null` or `undefined`.
247
- *
248
- * E.g., if the local FK fields are `[parentId, parentName]` and point to
249
- * `[customId, name]` on the remote model, `createLocalFKObject(remote)`
250
- * will return:
251
- *
252
- * ```
253
- * {
254
- * customId: local.parentId
255
- * name: local.parentName
256
- * }
257
- * ```
258
- *
259
- * If the local fields are not populated, returns
260
- *
261
- * @param local The local instance.
262
- */
263
- createRemoteQueryObject(local: T) {
264
- const query = {} as Record<string, string>;
265
- for (let i = 0; i < this.remoteJoinFields.length; i++) {
266
- const localValue = local[this.localJoinFields[i]];
267
- if (localValue === null || localValue === undefined) return null;
268
- query[this.remoteJoinFields[i]] = local[this.localJoinFields[i]];
269
- }
270
- return query;
271
- }
272
- }