@aws-amplify/datastore 5.0.1-api-v6-models.c1977f8.0 → 5.0.1-api-v6-models.891fe0d.0
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/lib/authModeStrategies/defaultAuthStrategy.js +1 -1
- package/lib/authModeStrategies/multiAuthStrategy.js +29 -105
- package/lib/datastore/datastore.js +887 -1370
- package/lib/index.js +1 -1
- package/lib/predicates/index.js +53 -102
- package/lib/predicates/next.js +310 -557
- package/lib/predicates/sort.js +24 -27
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +115 -449
- package/lib/storage/adapter/AsyncStorageDatabase.js +215 -480
- package/lib/storage/adapter/InMemoryStore.js +27 -101
- package/lib/storage/adapter/InMemoryStore.native.js +1 -1
- package/lib/storage/adapter/IndexedDBAdapter.js +441 -1002
- package/lib/storage/adapter/StorageAdapterBase.js +177 -396
- package/lib/storage/adapter/getDefaultAdapter/index.js +5 -6
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +2 -2
- package/lib/storage/relationship.js +174 -260
- package/lib/storage/storage.js +244 -507
- package/lib/sync/datastoreConnectivity.js +29 -84
- package/lib/sync/datastoreReachability/index.js +1 -1
- package/lib/sync/datastoreReachability/index.native.js +2 -2
- package/lib/sync/index.js +512 -885
- package/lib/sync/merger.js +30 -133
- package/lib/sync/outbox.js +147 -302
- package/lib/sync/processors/errorMaps.js +30 -80
- package/lib/sync/processors/mutation.js +331 -579
- package/lib/sync/processors/subscription.js +268 -428
- package/lib/sync/processors/sync.js +276 -464
- package/lib/sync/utils.js +248 -393
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.js +16 -58
- package/lib/util.js +335 -575
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +1 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +27 -103
- package/lib-esm/datastore/datastore.js +874 -1359
- package/lib-esm/index.js +6 -6
- package/lib-esm/predicates/index.js +54 -104
- package/lib-esm/predicates/next.js +306 -555
- package/lib-esm/predicates/sort.js +24 -27
- package/lib-esm/ssr/index.js +1 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +111 -446
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +212 -477
- package/lib-esm/storage/adapter/InMemoryStore.js +27 -102
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +436 -997
- package/lib-esm/storage/adapter/StorageAdapterBase.js +172 -392
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -3
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +1 -1
- package/lib-esm/storage/relationship.js +173 -260
- package/lib-esm/storage/storage.js +236 -499
- package/lib-esm/sync/datastoreConnectivity.js +26 -82
- package/lib-esm/sync/datastoreReachability/index.js +1 -1
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -1
- package/lib-esm/sync/index.js +498 -872
- package/lib-esm/sync/merger.js +28 -131
- package/lib-esm/sync/outbox.js +143 -298
- package/lib-esm/sync/processors/errorMaps.js +32 -82
- package/lib-esm/sync/processors/mutation.js +324 -572
- package/lib-esm/sync/processors/subscription.js +258 -418
- package/lib-esm/sync/processors/sync.js +269 -457
- package/lib-esm/sync/utils.js +245 -390
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types.js +16 -59
- package/lib-esm/util.js +335 -577
- package/package.json +12 -12
- package/src/datastore/datastore.ts +4 -3
- package/src/storage/adapter/getDefaultAdapter/index.ts +1 -3
- package/src/sync/processors/mutation.ts +1 -1
- package/src/sync/processors/sync.ts +1 -1
- package/src/sync/utils.ts +1 -1
- package/src/util.ts +44 -6
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import IndexedDBAdapter from '../IndexedDBAdapter';
|
|
2
2
|
import AsyncStorageAdapter from '../AsyncStorageAdapter';
|
|
3
|
-
import { isWebWorker } from '@aws-amplify/core/internals/utils';
|
|
4
|
-
|
|
5
|
-
var isBrowser = true; // TODO(v6): Update this for SSR
|
|
3
|
+
import { isWebWorker, isBrowser } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
const getDefaultAdapter = () => {
|
|
6
5
|
if ((isBrowser && window.indexedDB) || (isWebWorker() && self.indexedDB)) {
|
|
7
6
|
return IndexedDBAdapter;
|
|
8
7
|
}
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __values = (this && this.__values) || function(o) {
|
|
2
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
3
|
-
if (m) return m.call(o);
|
|
4
|
-
if (o && typeof o.length === "number") return {
|
|
5
|
-
next: function () {
|
|
6
|
-
if (o && i >= o.length) o = void 0;
|
|
7
|
-
return { value: o && o[i++], done: !o };
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
-
};
|
|
12
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
13
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
3
|
import { isFieldAssociation } from '../types';
|
|
@@ -20,14 +9,14 @@ import { isFieldAssociation } from '../types';
|
|
|
20
9
|
* Because I mean, relationships are tough.
|
|
21
10
|
*
|
|
22
11
|
*/
|
|
23
|
-
|
|
12
|
+
export class ModelRelationship {
|
|
24
13
|
/**
|
|
25
14
|
* @param modelDefinition The "local" model.
|
|
26
15
|
* @param field The "local" model field.
|
|
27
16
|
*/
|
|
28
|
-
|
|
17
|
+
constructor(model, field) {
|
|
29
18
|
if (!isFieldAssociation(model.schema, field)) {
|
|
30
|
-
throw new Error(
|
|
19
|
+
throw new Error(`${model.schema.name}.${field} is not a relationship.`);
|
|
31
20
|
}
|
|
32
21
|
this.localModel = model;
|
|
33
22
|
this._field = field;
|
|
@@ -39,263 +28,189 @@ var ModelRelationship = /** @class */ (function () {
|
|
|
39
28
|
* @param model The model the relationship field exists in.
|
|
40
29
|
* @param field The field that may relates the local model to the remote model.
|
|
41
30
|
*/
|
|
42
|
-
|
|
31
|
+
static from(model, field) {
|
|
43
32
|
if (isFieldAssociation(model.schema, field)) {
|
|
44
33
|
return new this(model, field);
|
|
45
34
|
}
|
|
46
35
|
else {
|
|
47
36
|
return null;
|
|
48
37
|
}
|
|
49
|
-
}
|
|
38
|
+
}
|
|
50
39
|
/**
|
|
51
40
|
* Enumerates all valid `ModelRelationship`'s on the given model.
|
|
52
41
|
*
|
|
53
42
|
* @param model The model definition to enumerate relationships of.
|
|
54
43
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var field = _c.value;
|
|
61
|
-
var relationship = ModelRelationship.from(model, field);
|
|
62
|
-
relationship && relationships.push(relationship);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
66
|
-
finally {
|
|
67
|
-
try {
|
|
68
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
69
|
-
}
|
|
70
|
-
finally { if (e_1) throw e_1.error; }
|
|
44
|
+
static allFrom(model) {
|
|
45
|
+
const relationships = [];
|
|
46
|
+
for (const field of Object.keys(model.schema.fields)) {
|
|
47
|
+
const relationship = ModelRelationship.from(model, field);
|
|
48
|
+
relationship && relationships.push(relationship);
|
|
71
49
|
}
|
|
72
50
|
return relationships;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Raw details about the local FK as-is from the local model's field definition in
|
|
117
|
-
* the schema. This field requires interpretation.
|
|
118
|
-
*
|
|
119
|
-
* @see localJoinFields
|
|
120
|
-
* @see localAssociatedWith
|
|
121
|
-
*/
|
|
122
|
-
get: function () {
|
|
123
|
-
return this.localDefinition.fields[this.field].association;
|
|
124
|
-
},
|
|
125
|
-
enumerable: false,
|
|
126
|
-
configurable: true
|
|
127
|
-
});
|
|
128
|
-
Object.defineProperty(ModelRelationship.prototype, "localJoinFields", {
|
|
129
|
-
/**
|
|
130
|
-
* The field names on the local model that can be used to query or queried to match
|
|
131
|
-
* with instances of the remote model.
|
|
132
|
-
*
|
|
133
|
-
* Fields are returned in-order to match the order of `this.remoteKeyFields`.
|
|
134
|
-
*/
|
|
135
|
-
get: function () {
|
|
136
|
-
/**
|
|
137
|
-
* This is relatively straightforward, actually.
|
|
138
|
-
*
|
|
139
|
-
* If we have explicitly stated targetNames, codegen is telling us authoritatively
|
|
140
|
-
* to use those fields for this relationship. The local model "points to" fields
|
|
141
|
-
* in the remote one.
|
|
142
|
-
*
|
|
143
|
-
* In other cases, the remote model points to this one's
|
|
144
|
-
*/
|
|
145
|
-
if (this.localAssocation.targetName) {
|
|
146
|
-
// This case is theoretically unnecessary going forward.
|
|
147
|
-
return [this.localAssocation.targetName];
|
|
148
|
-
}
|
|
149
|
-
else if (this.localAssocation.targetNames) {
|
|
150
|
-
return this.localAssocation.targetNames;
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
return this.localPKFields;
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
enumerable: false,
|
|
157
|
-
configurable: true
|
|
158
|
-
});
|
|
159
|
-
Object.defineProperty(ModelRelationship.prototype, "localPKFields", {
|
|
160
|
-
/**
|
|
161
|
-
* The field names on the local model that uniquely identify it.
|
|
162
|
-
*
|
|
163
|
-
* These fields may or may not be relevant to the join fields.
|
|
164
|
-
*/
|
|
165
|
-
get: function () {
|
|
166
|
-
return this.localModel.pkField;
|
|
167
|
-
},
|
|
168
|
-
enumerable: false,
|
|
169
|
-
configurable: true
|
|
170
|
-
});
|
|
171
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteDefinition", {
|
|
172
|
-
get: function () {
|
|
173
|
-
var _a;
|
|
174
|
-
return (_a = this.remoteModelType.modelConstructor) === null || _a === void 0 ? void 0 : _a.schema;
|
|
175
|
-
},
|
|
176
|
-
enumerable: false,
|
|
177
|
-
configurable: true
|
|
178
|
-
});
|
|
179
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteModelType", {
|
|
180
|
-
get: function () {
|
|
181
|
-
return this.localDefinition.fields[this.field].type;
|
|
182
|
-
},
|
|
183
|
-
enumerable: false,
|
|
184
|
-
configurable: true
|
|
185
|
-
});
|
|
186
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteModelConstructor", {
|
|
187
|
-
/**
|
|
188
|
-
* Constructor that can be used to query DataStore or create instances for
|
|
189
|
-
* the remote model.
|
|
190
|
-
*/
|
|
191
|
-
get: function () {
|
|
192
|
-
return this.remoteModelType.modelConstructor.builder;
|
|
193
|
-
},
|
|
194
|
-
enumerable: false,
|
|
195
|
-
configurable: true
|
|
196
|
-
});
|
|
197
|
-
Object.defineProperty(ModelRelationship.prototype, "remotePKFields", {
|
|
51
|
+
}
|
|
52
|
+
get localDefinition() {
|
|
53
|
+
return this.localModel.schema;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The virtual/computed field on the local model that should contain
|
|
57
|
+
* the related model.
|
|
58
|
+
*/
|
|
59
|
+
get field() {
|
|
60
|
+
return this._field;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The constructor that can be used to query DataStore or create instance for
|
|
64
|
+
* the local model.
|
|
65
|
+
*/
|
|
66
|
+
get localConstructor() {
|
|
67
|
+
return this.localModel.builder;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The name/type of the relationship the local model has with the remote model
|
|
71
|
+
* via the defined local model field.
|
|
72
|
+
*/
|
|
73
|
+
get type() {
|
|
74
|
+
return this.localAssocation.connectionType;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Raw details about the local FK as-is from the local model's field definition in
|
|
78
|
+
* the schema. This field requires interpretation.
|
|
79
|
+
*
|
|
80
|
+
* @see localJoinFields
|
|
81
|
+
* @see localAssociatedWith
|
|
82
|
+
*/
|
|
83
|
+
get localAssocation() {
|
|
84
|
+
return this.localDefinition.fields[this.field].association;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The field names on the local model that can be used to query or queried to match
|
|
88
|
+
* with instances of the remote model.
|
|
89
|
+
*
|
|
90
|
+
* Fields are returned in-order to match the order of `this.remoteKeyFields`.
|
|
91
|
+
*/
|
|
92
|
+
get localJoinFields() {
|
|
198
93
|
/**
|
|
199
|
-
*
|
|
94
|
+
* This is relatively straightforward, actually.
|
|
200
95
|
*
|
|
201
|
-
*
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
var _a;
|
|
205
|
-
return ((_a = this.remoteModelType.modelConstructor) === null || _a === void 0 ? void 0 : _a.pkField) || ['id'];
|
|
206
|
-
},
|
|
207
|
-
enumerable: false,
|
|
208
|
-
configurable: true
|
|
209
|
-
});
|
|
210
|
-
Object.defineProperty(ModelRelationship.prototype, "localAssociatedWith", {
|
|
211
|
-
/**
|
|
212
|
-
* The `associatedWith` fields from the local perspective.
|
|
96
|
+
* If we have explicitly stated targetNames, codegen is telling us authoritatively
|
|
97
|
+
* to use those fields for this relationship. The local model "points to" fields
|
|
98
|
+
* in the remote one.
|
|
213
99
|
*
|
|
214
|
-
*
|
|
215
|
-
* when looking for a remote association and/or determining the final remote
|
|
216
|
-
* key fields.
|
|
100
|
+
* In other cases, the remote model points to this one's
|
|
217
101
|
*/
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
102
|
+
if (this.localAssocation.targetName) {
|
|
103
|
+
// This case is theoretically unnecessary going forward.
|
|
104
|
+
return [this.localAssocation.targetName];
|
|
105
|
+
}
|
|
106
|
+
else if (this.localAssocation.targetNames) {
|
|
107
|
+
return this.localAssocation.targetNames;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return this.localPKFields;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The field names on the local model that uniquely identify it.
|
|
115
|
+
*
|
|
116
|
+
* These fields may or may not be relevant to the join fields.
|
|
117
|
+
*/
|
|
118
|
+
get localPKFields() {
|
|
119
|
+
return this.localModel.pkField;
|
|
120
|
+
}
|
|
121
|
+
get remoteDefinition() {
|
|
122
|
+
return this.remoteModelType.modelConstructor?.schema;
|
|
123
|
+
}
|
|
124
|
+
get remoteModelType() {
|
|
125
|
+
return this.localDefinition.fields[this.field].type;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Constructor that can be used to query DataStore or create instances for
|
|
129
|
+
* the remote model.
|
|
130
|
+
*/
|
|
131
|
+
get remoteModelConstructor() {
|
|
132
|
+
return this.remoteModelType.modelConstructor.builder;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The field names on the remote model that uniquely identify it.
|
|
136
|
+
*
|
|
137
|
+
* These fields may or may not be relevant to the join fields.
|
|
138
|
+
*/
|
|
139
|
+
get remotePKFields() {
|
|
140
|
+
return this.remoteModelType.modelConstructor?.pkField || ['id'];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The `associatedWith` fields from the local perspective.
|
|
144
|
+
*
|
|
145
|
+
* When present, these fields indicate which fields on the remote model to use
|
|
146
|
+
* when looking for a remote association and/or determining the final remote
|
|
147
|
+
* key fields.
|
|
148
|
+
*/
|
|
149
|
+
get localAssociatedWith() {
|
|
150
|
+
if (this.localAssocation.connectionType === 'HAS_MANY' ||
|
|
151
|
+
this.localAssocation.connectionType === 'HAS_ONE') {
|
|
152
|
+
// This de-arraying is theoretically unnecessary going forward.
|
|
153
|
+
return Array.isArray(this.localAssocation.associatedWith)
|
|
154
|
+
? this.localAssocation.associatedWith
|
|
155
|
+
: [this.localAssocation.associatedWith];
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The `remote` model's associated field's `assocation` metadata, if
|
|
163
|
+
* present.
|
|
164
|
+
*
|
|
165
|
+
* This is used when determining if the remote model's associated field
|
|
166
|
+
* specifies which FK fields to use. If this value is `undefined`, the
|
|
167
|
+
* name of the remote field (`this.localAssociatedWith`) *is* the remote
|
|
168
|
+
* key field.
|
|
169
|
+
*/
|
|
170
|
+
get explicitRemoteAssociation() {
|
|
171
|
+
if (this.localAssociatedWith) {
|
|
172
|
+
if (this.localAssociatedWith.length === 1) {
|
|
173
|
+
return this.remoteDefinition.fields[this.localAssociatedWith[0]]
|
|
174
|
+
?.association;
|
|
225
175
|
}
|
|
226
176
|
else {
|
|
227
177
|
return undefined;
|
|
228
178
|
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
* This is used when determining if the remote model's associated field
|
|
239
|
-
* specifies which FK fields to use. If this value is `undefined`, the
|
|
240
|
-
* name of the remote field (`this.localAssociatedWith`) *is* the remote
|
|
241
|
-
* key field.
|
|
242
|
-
*/
|
|
243
|
-
get: function () {
|
|
244
|
-
var _a;
|
|
245
|
-
if (this.localAssociatedWith) {
|
|
246
|
-
if (this.localAssociatedWith.length === 1) {
|
|
247
|
-
return (_a = this.remoteDefinition.fields[this.localAssociatedWith[0]]) === null || _a === void 0 ? void 0 : _a.association;
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
return undefined;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
enumerable: false,
|
|
255
|
-
configurable: true
|
|
256
|
-
});
|
|
257
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteJoinFields", {
|
|
258
|
-
/**
|
|
259
|
-
* The field names on the remote model that can used to query or queried to match
|
|
260
|
-
* with instances of the local model.
|
|
261
|
-
*
|
|
262
|
-
* Fields are returned in-order to match the order of `this.localKeyFields`.
|
|
263
|
-
*/
|
|
264
|
-
get: function () {
|
|
265
|
-
/**
|
|
266
|
-
* If the local relationship explicitly names "associated with" fields, we
|
|
267
|
-
* need to see if this points direction to a reciprocating assocation. If it
|
|
268
|
-
* does, the remote assocation indicates what fields to use.
|
|
269
|
-
*/
|
|
270
|
-
var _a, _b, _c;
|
|
271
|
-
if ((_a = this.explicitRemoteAssociation) === null || _a === void 0 ? void 0 : _a.targetName) {
|
|
272
|
-
// This case is theoretically unnecessary going forward.
|
|
273
|
-
return [this.explicitRemoteAssociation.targetName];
|
|
274
|
-
}
|
|
275
|
-
else if ((_b = this.explicitRemoteAssociation) === null || _b === void 0 ? void 0 : _b.targetNames) {
|
|
276
|
-
return (_c = this.explicitRemoteAssociation) === null || _c === void 0 ? void 0 : _c.targetNames;
|
|
277
|
-
}
|
|
278
|
-
else if (this.localAssociatedWith) {
|
|
279
|
-
return this.localAssociatedWith;
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
return this.remotePKFields;
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
enumerable: false,
|
|
286
|
-
configurable: true
|
|
287
|
-
});
|
|
288
|
-
Object.defineProperty(ModelRelationship.prototype, "isComplete", {
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The field names on the remote model that can used to query or queried to match
|
|
183
|
+
* with instances of the local model.
|
|
184
|
+
*
|
|
185
|
+
* Fields are returned in-order to match the order of `this.localKeyFields`.
|
|
186
|
+
*/
|
|
187
|
+
get remoteJoinFields() {
|
|
289
188
|
/**
|
|
290
|
-
*
|
|
291
|
-
*
|
|
189
|
+
* If the local relationship explicitly names "associated with" fields, we
|
|
190
|
+
* need to see if this points direction to a reciprocating assocation. If it
|
|
191
|
+
* does, the remote assocation indicates what fields to use.
|
|
292
192
|
*/
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
193
|
+
if (this.explicitRemoteAssociation?.targetName) {
|
|
194
|
+
// This case is theoretically unnecessary going forward.
|
|
195
|
+
return [this.explicitRemoteAssociation.targetName];
|
|
196
|
+
}
|
|
197
|
+
else if (this.explicitRemoteAssociation?.targetNames) {
|
|
198
|
+
return this.explicitRemoteAssociation?.targetNames;
|
|
199
|
+
}
|
|
200
|
+
else if (this.localAssociatedWith) {
|
|
201
|
+
return this.localAssociatedWith;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return this.remotePKFields;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Whether this relationship everything necessary to get, set, and query from
|
|
209
|
+
* the perspective of the local model provided at instantiation.
|
|
210
|
+
*/
|
|
211
|
+
get isComplete() {
|
|
212
|
+
return this.localJoinFields.length > 0 && this.remoteJoinFields.length > 0;
|
|
213
|
+
}
|
|
299
214
|
/**
|
|
300
215
|
* Creates an FK mapper object with respect to the given related instance.
|
|
301
216
|
*
|
|
@@ -312,13 +227,13 @@ var ModelRelationship = /** @class */ (function () {
|
|
|
312
227
|
*
|
|
313
228
|
* @param remote The remote related instance.
|
|
314
229
|
*/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
for (
|
|
230
|
+
createLocalFKObject(remote) {
|
|
231
|
+
const fk = {};
|
|
232
|
+
for (let i = 0; i < this.localJoinFields.length; i++) {
|
|
318
233
|
fk[this.localJoinFields[i]] = remote[this.remoteJoinFields[i]];
|
|
319
234
|
}
|
|
320
235
|
return fk;
|
|
321
|
-
}
|
|
236
|
+
}
|
|
322
237
|
/**
|
|
323
238
|
* Creates an query mapper object to help fetch the remote instance(s) or
|
|
324
239
|
* `null` if any of the necessary local fields are `null` or `undefined`.
|
|
@@ -338,16 +253,14 @@ var ModelRelationship = /** @class */ (function () {
|
|
|
338
253
|
*
|
|
339
254
|
* @param local The local instance.
|
|
340
255
|
*/
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
for (
|
|
344
|
-
|
|
256
|
+
createRemoteQueryObject(local) {
|
|
257
|
+
const query = {};
|
|
258
|
+
for (let i = 0; i < this.remoteJoinFields.length; i++) {
|
|
259
|
+
const localValue = local[this.localJoinFields[i]];
|
|
345
260
|
if (localValue === null || localValue === undefined)
|
|
346
261
|
return null;
|
|
347
262
|
query[this.remoteJoinFields[i]] = local[this.localJoinFields[i]];
|
|
348
263
|
}
|
|
349
264
|
return query;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
}());
|
|
353
|
-
export { ModelRelationship };
|
|
265
|
+
}
|
|
266
|
+
}
|