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