@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.
- package/CHANGELOG.md +27 -0
- package/build.js +5 -0
- package/dist/aws-amplify-datastore.js +92626 -0
- package/dist/aws-amplify-datastore.js.map +1 -0
- package/dist/aws-amplify-datastore.min.js +65 -0
- package/dist/aws-amplify-datastore.min.js.map +1 -0
- package/index.js +7 -0
- package/lib/authModeStrategies/multiAuthStrategy.js +64 -6
- package/lib/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib/datastore/datastore.js +297 -703
- package/lib/datastore/datastore.js.map +1 -1
- package/lib/index.js +4 -6
- package/lib/index.js.map +1 -1
- package/lib/predicates/index.js +6 -127
- package/lib/predicates/index.js.map +1 -1
- package/lib/predicates/sort.js +4 -10
- package/lib/predicates/sort.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +381 -138
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js +98 -37
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.js +67 -16
- package/lib/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib/storage/adapter/InMemoryStore.native.js +4 -2
- package/lib/storage/adapter/InMemoryStore.native.js.map +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +420 -272
- package/lib/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js +5 -3
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -2
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +1 -1
- package/lib/storage/storage.js +143 -72
- package/lib/storage/storage.js.map +1 -1
- package/lib/sync/datastoreConnectivity.js +55 -6
- package/lib/sync/datastoreConnectivity.js.map +1 -1
- package/lib/sync/datastoreReachability/index.native.js +4 -2
- package/lib/sync/datastoreReachability/index.native.js.map +1 -1
- package/lib/sync/index.js +124 -49
- package/lib/sync/index.js.map +1 -1
- package/lib/sync/merger.js +74 -8
- package/lib/sync/merger.js.map +1 -1
- package/lib/sync/outbox.js +97 -24
- package/lib/sync/outbox.js.map +1 -1
- package/lib/sync/processors/errorMaps.js +35 -5
- package/lib/sync/processors/errorMaps.js.map +1 -1
- package/lib/sync/processors/mutation.js +131 -47
- package/lib/sync/processors/mutation.js.map +1 -1
- package/lib/sync/processors/subscription.js +102 -29
- package/lib/sync/processors/subscription.js.map +1 -1
- package/lib/sync/processors/sync.js +102 -26
- package/lib/sync/processors/sync.js.map +1 -1
- package/lib/sync/utils.js +103 -40
- package/lib/sync/utils.js.map +1 -1
- package/lib/types.js +39 -9
- package/lib/types.js.map +1 -1
- package/lib/util.js +188 -192
- package/lib/util.js.map +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +57 -2
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +1 -1
- package/lib-esm/datastore/datastore.d.ts +8 -59
- package/lib-esm/datastore/datastore.js +234 -642
- package/lib-esm/datastore/datastore.js.map +1 -1
- package/lib-esm/index.d.ts +2 -3
- package/lib-esm/index.js +1 -2
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/predicates/index.d.ts +2 -16
- package/lib-esm/predicates/index.js +7 -128
- package/lib-esm/predicates/index.js.map +1 -1
- package/lib-esm/predicates/sort.js +4 -10
- package/lib-esm/predicates/sort.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.d.ts +1 -2
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +349 -109
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +68 -7
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.d.ts +1 -1
- package/lib-esm/storage/adapter/InMemoryStore.js +52 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +1 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.d.ts +2 -4
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +368 -227
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +1 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +1 -1
- package/lib-esm/storage/storage.d.ts +6 -7
- package/lib-esm/storage/storage.js +101 -33
- package/lib-esm/storage/storage.js.map +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +47 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +1 -1
- package/lib-esm/sync/index.js +76 -4
- package/lib-esm/sync/index.js.map +1 -1
- package/lib-esm/sync/merger.js +67 -1
- package/lib-esm/sync/merger.js.map +1 -1
- package/lib-esm/sync/outbox.js +74 -1
- package/lib-esm/sync/outbox.js.map +1 -1
- package/lib-esm/sync/processors/errorMaps.js +32 -2
- package/lib-esm/sync/processors/errorMaps.js.map +1 -1
- package/lib-esm/sync/processors/mutation.js +93 -12
- package/lib-esm/sync/processors/mutation.js.map +1 -1
- package/lib-esm/sync/processors/subscription.js +69 -6
- package/lib-esm/sync/processors/subscription.js.map +1 -1
- package/lib-esm/sync/processors/sync.js +75 -2
- package/lib-esm/sync/processors/sync.js.map +1 -1
- package/lib-esm/sync/utils.d.ts +1 -1
- package/lib-esm/sync/utils.js +95 -32
- package/lib-esm/sync/utils.js.map +1 -1
- package/lib-esm/types.d.ts +10 -63
- package/lib-esm/types.js +38 -7
- package/lib-esm/types.js.map +1 -1
- package/lib-esm/util.d.ts +6 -39
- package/lib-esm/util.js +171 -171
- package/lib-esm/util.js.map +1 -1
- package/package.json +14 -21
- package/src/authModeStrategies/multiAuthStrategy.ts +2 -2
- package/src/datastore/datastore.ts +206 -699
- package/src/index.ts +0 -4
- package/src/predicates/index.ts +17 -143
- package/src/predicates/sort.ts +2 -8
- package/src/storage/adapter/AsyncStorageAdapter.ts +178 -56
- package/src/storage/adapter/AsyncStorageDatabase.ts +15 -16
- package/src/storage/adapter/InMemoryStore.ts +2 -5
- package/src/storage/adapter/IndexedDBAdapter.ts +191 -166
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -2
- package/src/storage/storage.ts +37 -56
- package/src/sync/datastoreConnectivity.ts +4 -4
- package/src/sync/index.ts +28 -22
- package/src/sync/merger.ts +1 -1
- package/src/sync/outbox.ts +6 -6
- package/src/sync/processors/errorMaps.ts +1 -1
- package/src/sync/processors/mutation.ts +19 -23
- package/src/sync/processors/subscription.ts +16 -20
- package/src/sync/processors/sync.ts +17 -17
- package/src/sync/utils.ts +48 -42
- package/src/types.ts +16 -128
- package/src/util.ts +150 -108
- package/webpack.config.dev.js +6 -0
- package/lib/authModeStrategies/defaultAuthStrategy.d.ts +0 -2
- package/lib/authModeStrategies/index.d.ts +0 -2
- package/lib/authModeStrategies/multiAuthStrategy.d.ts +0 -13
- package/lib/datastore/datastore.d.ts +0 -207
- package/lib/index.d.ts +0 -16
- package/lib/predicates/index.d.ts +0 -30
- package/lib/predicates/next.d.ts +0 -301
- package/lib/predicates/next.js +0 -816
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.d.ts +0 -8
- package/lib/ssr/index.d.ts +0 -3
- package/lib/storage/adapter/AsyncStorageAdapter.d.ts +0 -42
- package/lib/storage/adapter/AsyncStorageDatabase.d.ts +0 -39
- package/lib/storage/adapter/InMemoryStore.d.ts +0 -11
- package/lib/storage/adapter/InMemoryStore.native.d.ts +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.d.ts +0 -61
- package/lib/storage/adapter/getDefaultAdapter/index.d.ts +0 -3
- package/lib/storage/adapter/getDefaultAdapter/index.native.d.ts +0 -3
- package/lib/storage/adapter/index.d.ts +0 -9
- package/lib/storage/relationship.d.ts +0 -140
- package/lib/storage/relationship.js +0 -335
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.d.ts +0 -50
- package/lib/sync/datastoreConnectivity.d.ts +0 -16
- package/lib/sync/datastoreReachability/index.d.ts +0 -3
- package/lib/sync/datastoreReachability/index.native.d.ts +0 -3
- package/lib/sync/index.d.ts +0 -89
- package/lib/sync/merger.d.ts +0 -17
- package/lib/sync/outbox.d.ts +0 -27
- package/lib/sync/processors/errorMaps.d.ts +0 -17
- package/lib/sync/processors/mutation.d.ts +0 -58
- package/lib/sync/processors/subscription.d.ts +0 -33
- package/lib/sync/processors/sync.d.ts +0 -28
- package/lib/sync/utils.d.ts +0 -42
- package/lib/types.d.ts +0 -554
- package/lib/util.d.ts +0 -189
- package/lib-esm/predicates/next.d.ts +0 -301
- package/lib-esm/predicates/next.js +0 -812
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/storage/relationship.d.ts +0 -140
- package/lib-esm/storage/relationship.js +0 -333
- package/lib-esm/storage/relationship.js.map +0 -1
- package/src/predicates/next.ts +0 -967
- 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
|
-
}
|