@aws-amplify/datastore 4.7.6-api-v6-models.b3abc9b.0 → 5.0.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/README.md +4 -0
- package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
- package/lib/authModeStrategies/index.js +3 -3
- package/lib/authModeStrategies/multiAuthStrategy.js +38 -53
- package/lib/datastore/datastore.d.ts +4 -5
- package/lib/datastore/datastore.js +929 -1284
- package/lib/index.d.ts +1 -1
- package/lib/index.js +26 -13
- package/lib/predicates/index.js +54 -69
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +313 -462
- package/lib/predicates/sort.js +24 -28
- package/lib/ssr/index.js +2 -2
- package/lib/storage/adapter/AsyncStorageAdapter.js +120 -342
- package/lib/storage/adapter/AsyncStorageDatabase.js +217 -421
- package/lib/storage/adapter/InMemoryStore.js +28 -51
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +466 -871
- package/lib/storage/adapter/StorageAdapterBase.js +180 -330
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -10
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +5 -4
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +177 -253
- package/lib/storage/storage.d.ts +4 -4
- package/lib/storage/storage.js +255 -433
- package/lib/sync/datastoreConnectivity.d.ts +2 -2
- package/lib/sync/datastoreConnectivity.js +29 -39
- package/lib/sync/datastoreReachability/index.d.ts +1 -3
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.d.ts +1 -3
- package/lib/sync/datastoreReachability/index.native.js +4 -5
- package/lib/sync/index.d.ts +2 -2
- package/lib/sync/index.js +522 -827
- package/lib/sync/merger.js +31 -63
- package/lib/sync/outbox.js +148 -232
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +30 -47
- package/lib/sync/processors/mutation.d.ts +2 -2
- package/lib/sync/processors/mutation.js +343 -502
- package/lib/sync/processors/subscription.d.ts +5 -2
- package/lib/sync/processors/subscription.js +283 -437
- package/lib/sync/processors/sync.d.ts +2 -2
- package/lib/sync/processors/sync.js +279 -404
- package/lib/sync/utils.d.ts +5 -4
- package/lib/sync/utils.js +267 -320
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +17 -24
- package/lib/util.d.ts +9 -17
- package/lib/util.js +387 -511
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +1 -2
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +35 -52
- package/lib-esm/datastore/datastore.d.ts +4 -5
- package/lib-esm/datastore/datastore.js +888 -1247
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +6 -7
- package/lib-esm/predicates/index.js +53 -70
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +306 -459
- package/lib-esm/predicates/sort.js +23 -28
- package/lib-esm/ssr/index.js +1 -2
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +111 -338
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +212 -416
- package/lib-esm/storage/adapter/InMemoryStore.js +27 -52
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +438 -866
- package/lib-esm/storage/adapter/StorageAdapterBase.js +173 -325
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -6
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +1 -2
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +173 -251
- package/lib-esm/storage/storage.d.ts +4 -4
- package/lib-esm/storage/storage.js +242 -424
- package/lib-esm/sync/datastoreConnectivity.d.ts +2 -2
- package/lib-esm/sync/datastoreConnectivity.js +28 -39
- package/lib-esm/sync/datastoreReachability/index.d.ts +1 -3
- package/lib-esm/sync/datastoreReachability/index.js +2 -3
- package/lib-esm/sync/datastoreReachability/index.native.d.ts +1 -3
- package/lib-esm/sync/datastoreReachability/index.native.js +3 -4
- package/lib-esm/sync/index.d.ts +2 -2
- package/lib-esm/sync/index.js +502 -812
- package/lib-esm/sync/merger.js +28 -61
- package/lib-esm/sync/outbox.js +143 -228
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +32 -50
- package/lib-esm/sync/processors/mutation.d.ts +2 -2
- package/lib-esm/sync/processors/mutation.js +329 -490
- package/lib-esm/sync/processors/subscription.d.ts +5 -2
- package/lib-esm/sync/processors/subscription.js +266 -421
- package/lib-esm/sync/processors/sync.d.ts +2 -2
- package/lib-esm/sync/processors/sync.js +271 -397
- package/lib-esm/sync/utils.d.ts +5 -4
- package/lib-esm/sync/utils.js +252 -307
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +16 -25
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +335 -497
- package/package.json +31 -26
- package/src/authModeStrategies/multiAuthStrategy.ts +15 -12
- package/src/datastore/datastore.ts +36 -35
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +2 -2
- package/src/storage/adapter/StorageAdapterBase.ts +2 -2
- package/src/storage/adapter/getDefaultAdapter/index.ts +1 -4
- package/src/storage/storage.ts +29 -24
- package/src/sync/datastoreConnectivity.ts +6 -6
- package/src/sync/datastoreReachability/index.native.ts +5 -3
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +79 -89
- package/src/sync/processors/errorMaps.ts +7 -7
- package/src/sync/processors/mutation.ts +19 -13
- package/src/sync/processors/subscription.ts +221 -295
- package/src/sync/processors/sync.ts +11 -8
- package/src/sync/utils.ts +30 -15
- package/src/types.ts +4 -8
- package/src/util.ts +46 -9
- package/lib/.tsbuildinfo +0 -3
- package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib/authModeStrategies/index.js.map +0 -1
- package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib/datastore/datastore.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/predicates/index.js.map +0 -1
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.js.map +0 -1
- package/lib/ssr/index.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib/storage/adapter/index.js.map +0 -1
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.js.map +0 -1
- package/lib/sync/datastoreConnectivity.js.map +0 -1
- package/lib/sync/datastoreReachability/index.js.map +0 -1
- package/lib/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib/sync/index.js.map +0 -1
- package/lib/sync/merger.js.map +0 -1
- package/lib/sync/outbox.js.map +0 -1
- package/lib/sync/processors/errorMaps.js.map +0 -1
- package/lib/sync/processors/mutation.js.map +0 -1
- package/lib/sync/processors/subscription.js.map +0 -1
- package/lib/sync/processors/sync.js.map +0 -1
- package/lib/sync/utils.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib-esm/authModeStrategies/index.js.map +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib-esm/datastore/datastore.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/predicates/index.js.map +0 -1
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/predicates/sort.js.map +0 -1
- package/lib-esm/ssr/index.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib-esm/storage/adapter/index.js.map +0 -1
- package/lib-esm/storage/relationship.js.map +0 -1
- package/lib-esm/storage/storage.js.map +0 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib-esm/sync/index.js.map +0 -1
- package/lib-esm/sync/merger.js.map +0 -1
- package/lib-esm/sync/outbox.js.map +0 -1
- package/lib-esm/sync/processors/errorMaps.js.map +0 -1
- package/lib-esm/sync/processors/mutation.js.map +0 -1
- package/lib-esm/sync/processors/subscription.js.map +0 -1
- package/lib-esm/sync/processors/sync.js.map +0 -1
- package/lib-esm/sync/utils.js.map +0 -1
- package/lib-esm/types.js.map +0 -1
- package/lib-esm/util.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __values } from "tslib";
|
|
2
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
3
|
import { isFieldAssociation } from '../types';
|
|
@@ -10,14 +9,14 @@ import { isFieldAssociation } from '../types';
|
|
|
10
9
|
* Because I mean, relationships are tough.
|
|
11
10
|
*
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
export class ModelRelationship {
|
|
14
13
|
/**
|
|
15
14
|
* @param modelDefinition The "local" model.
|
|
16
15
|
* @param field The "local" model field.
|
|
17
16
|
*/
|
|
18
|
-
|
|
17
|
+
constructor(model, field) {
|
|
19
18
|
if (!isFieldAssociation(model.schema, field)) {
|
|
20
|
-
throw new Error(model.schema.name
|
|
19
|
+
throw new Error(`${model.schema.name}.${field} is not a relationship.`);
|
|
21
20
|
}
|
|
22
21
|
this.localModel = model;
|
|
23
22
|
this._field = field;
|
|
@@ -29,263 +28,189 @@ var ModelRelationship = /** @class */ (function () {
|
|
|
29
28
|
* @param model The model the relationship field exists in.
|
|
30
29
|
* @param field The field that may relates the local model to the remote model.
|
|
31
30
|
*/
|
|
32
|
-
|
|
31
|
+
static from(model, field) {
|
|
33
32
|
if (isFieldAssociation(model.schema, field)) {
|
|
34
33
|
return new this(model, field);
|
|
35
34
|
}
|
|
36
35
|
else {
|
|
37
36
|
return null;
|
|
38
37
|
}
|
|
39
|
-
}
|
|
38
|
+
}
|
|
40
39
|
/**
|
|
41
40
|
* Enumerates all valid `ModelRelationship`'s on the given model.
|
|
42
41
|
*
|
|
43
42
|
* @param model The model definition to enumerate relationships of.
|
|
44
43
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var field = _c.value;
|
|
51
|
-
var relationship = ModelRelationship.from(model, field);
|
|
52
|
-
relationship && relationships.push(relationship);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
56
|
-
finally {
|
|
57
|
-
try {
|
|
58
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
59
|
-
}
|
|
60
|
-
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);
|
|
61
49
|
}
|
|
62
50
|
return relationships;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
* Raw details about the local FK as-is from the local model's field definition in
|
|
107
|
-
* the schema. This field requires interpretation.
|
|
108
|
-
*
|
|
109
|
-
* @see localJoinFields
|
|
110
|
-
* @see localAssociatedWith
|
|
111
|
-
*/
|
|
112
|
-
get: function () {
|
|
113
|
-
return this.localDefinition.fields[this.field].association;
|
|
114
|
-
},
|
|
115
|
-
enumerable: true,
|
|
116
|
-
configurable: true
|
|
117
|
-
});
|
|
118
|
-
Object.defineProperty(ModelRelationship.prototype, "localJoinFields", {
|
|
119
|
-
/**
|
|
120
|
-
* The field names on the local model that can be used to query or queried to match
|
|
121
|
-
* with instances of the remote model.
|
|
122
|
-
*
|
|
123
|
-
* Fields are returned in-order to match the order of `this.remoteKeyFields`.
|
|
124
|
-
*/
|
|
125
|
-
get: function () {
|
|
126
|
-
/**
|
|
127
|
-
* This is relatively straightforward, actually.
|
|
128
|
-
*
|
|
129
|
-
* If we have explicitly stated targetNames, codegen is telling us authoritatively
|
|
130
|
-
* to use those fields for this relationship. The local model "points to" fields
|
|
131
|
-
* in the remote one.
|
|
132
|
-
*
|
|
133
|
-
* In other cases, the remote model points to this one's
|
|
134
|
-
*/
|
|
135
|
-
if (this.localAssocation.targetName) {
|
|
136
|
-
// This case is theoretically unnecessary going forward.
|
|
137
|
-
return [this.localAssocation.targetName];
|
|
138
|
-
}
|
|
139
|
-
else if (this.localAssocation.targetNames) {
|
|
140
|
-
return this.localAssocation.targetNames;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
return this.localPKFields;
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
enumerable: true,
|
|
147
|
-
configurable: true
|
|
148
|
-
});
|
|
149
|
-
Object.defineProperty(ModelRelationship.prototype, "localPKFields", {
|
|
150
|
-
/**
|
|
151
|
-
* The field names on the local model that uniquely identify it.
|
|
152
|
-
*
|
|
153
|
-
* These fields may or may not be relevant to the join fields.
|
|
154
|
-
*/
|
|
155
|
-
get: function () {
|
|
156
|
-
return this.localModel.pkField;
|
|
157
|
-
},
|
|
158
|
-
enumerable: true,
|
|
159
|
-
configurable: true
|
|
160
|
-
});
|
|
161
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteDefinition", {
|
|
162
|
-
get: function () {
|
|
163
|
-
var _a;
|
|
164
|
-
return (_a = this.remoteModelType.modelConstructor) === null || _a === void 0 ? void 0 : _a.schema;
|
|
165
|
-
},
|
|
166
|
-
enumerable: true,
|
|
167
|
-
configurable: true
|
|
168
|
-
});
|
|
169
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteModelType", {
|
|
170
|
-
get: function () {
|
|
171
|
-
return this.localDefinition.fields[this.field].type;
|
|
172
|
-
},
|
|
173
|
-
enumerable: true,
|
|
174
|
-
configurable: true
|
|
175
|
-
});
|
|
176
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteModelConstructor", {
|
|
177
|
-
/**
|
|
178
|
-
* Constructor that can be used to query DataStore or create instances for
|
|
179
|
-
* the remote model.
|
|
180
|
-
*/
|
|
181
|
-
get: function () {
|
|
182
|
-
return this.remoteModelType.modelConstructor.builder;
|
|
183
|
-
},
|
|
184
|
-
enumerable: true,
|
|
185
|
-
configurable: true
|
|
186
|
-
});
|
|
187
|
-
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() {
|
|
188
93
|
/**
|
|
189
|
-
*
|
|
94
|
+
* This is relatively straightforward, actually.
|
|
190
95
|
*
|
|
191
|
-
*
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
var _a;
|
|
195
|
-
return ((_a = this.remoteModelType.modelConstructor) === null || _a === void 0 ? void 0 : _a.pkField) || ['id'];
|
|
196
|
-
},
|
|
197
|
-
enumerable: true,
|
|
198
|
-
configurable: true
|
|
199
|
-
});
|
|
200
|
-
Object.defineProperty(ModelRelationship.prototype, "localAssociatedWith", {
|
|
201
|
-
/**
|
|
202
|
-
* 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.
|
|
203
99
|
*
|
|
204
|
-
*
|
|
205
|
-
* when looking for a remote association and/or determining the final remote
|
|
206
|
-
* key fields.
|
|
100
|
+
* In other cases, the remote model points to this one's
|
|
207
101
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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;
|
|
215
175
|
}
|
|
216
176
|
else {
|
|
217
177
|
return undefined;
|
|
218
178
|
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
* This is used when determining if the remote model's associated field
|
|
229
|
-
* specifies which FK fields to use. If this value is `undefined`, the
|
|
230
|
-
* name of the remote field (`this.localAssociatedWith`) *is* the remote
|
|
231
|
-
* key field.
|
|
232
|
-
*/
|
|
233
|
-
get: function () {
|
|
234
|
-
var _a;
|
|
235
|
-
if (this.localAssociatedWith) {
|
|
236
|
-
if (this.localAssociatedWith.length === 1) {
|
|
237
|
-
return (_a = this.remoteDefinition.fields[this.localAssociatedWith[0]]) === null || _a === void 0 ? void 0 : _a.association;
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
return undefined;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
enumerable: true,
|
|
245
|
-
configurable: true
|
|
246
|
-
});
|
|
247
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteJoinFields", {
|
|
248
|
-
/**
|
|
249
|
-
* The field names on the remote model that can used to query or queried to match
|
|
250
|
-
* with instances of the local model.
|
|
251
|
-
*
|
|
252
|
-
* Fields are returned in-order to match the order of `this.localKeyFields`.
|
|
253
|
-
*/
|
|
254
|
-
get: function () {
|
|
255
|
-
/**
|
|
256
|
-
* If the local relationship explicitly names "associated with" fields, we
|
|
257
|
-
* need to see if this points direction to a reciprocating assocation. If it
|
|
258
|
-
* does, the remote assocation indicates what fields to use.
|
|
259
|
-
*/
|
|
260
|
-
var _a, _b, _c;
|
|
261
|
-
if ((_a = this.explicitRemoteAssociation) === null || _a === void 0 ? void 0 : _a.targetName) {
|
|
262
|
-
// This case is theoretically unnecessary going forward.
|
|
263
|
-
return [this.explicitRemoteAssociation.targetName];
|
|
264
|
-
}
|
|
265
|
-
else if ((_b = this.explicitRemoteAssociation) === null || _b === void 0 ? void 0 : _b.targetNames) {
|
|
266
|
-
return (_c = this.explicitRemoteAssociation) === null || _c === void 0 ? void 0 : _c.targetNames;
|
|
267
|
-
}
|
|
268
|
-
else if (this.localAssociatedWith) {
|
|
269
|
-
return this.localAssociatedWith;
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
return this.remotePKFields;
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
enumerable: true,
|
|
276
|
-
configurable: true
|
|
277
|
-
});
|
|
278
|
-
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() {
|
|
279
188
|
/**
|
|
280
|
-
*
|
|
281
|
-
*
|
|
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.
|
|
282
192
|
*/
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
+
}
|
|
289
214
|
/**
|
|
290
215
|
* Creates an FK mapper object with respect to the given related instance.
|
|
291
216
|
*
|
|
@@ -302,13 +227,13 @@ var ModelRelationship = /** @class */ (function () {
|
|
|
302
227
|
*
|
|
303
228
|
* @param remote The remote related instance.
|
|
304
229
|
*/
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
for (
|
|
230
|
+
createLocalFKObject(remote) {
|
|
231
|
+
const fk = {};
|
|
232
|
+
for (let i = 0; i < this.localJoinFields.length; i++) {
|
|
308
233
|
fk[this.localJoinFields[i]] = remote[this.remoteJoinFields[i]];
|
|
309
234
|
}
|
|
310
235
|
return fk;
|
|
311
|
-
}
|
|
236
|
+
}
|
|
312
237
|
/**
|
|
313
238
|
* Creates an query mapper object to help fetch the remote instance(s) or
|
|
314
239
|
* `null` if any of the necessary local fields are `null` or `undefined`.
|
|
@@ -328,17 +253,14 @@ var ModelRelationship = /** @class */ (function () {
|
|
|
328
253
|
*
|
|
329
254
|
* @param local The local instance.
|
|
330
255
|
*/
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
for (
|
|
334
|
-
|
|
256
|
+
createRemoteQueryObject(local) {
|
|
257
|
+
const query = {};
|
|
258
|
+
for (let i = 0; i < this.remoteJoinFields.length; i++) {
|
|
259
|
+
const localValue = local[this.localJoinFields[i]];
|
|
335
260
|
if (localValue === null || localValue === undefined)
|
|
336
261
|
return null;
|
|
337
262
|
query[this.remoteJoinFields[i]] = local[this.localJoinFields[i]];
|
|
338
263
|
}
|
|
339
264
|
return query;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
}());
|
|
343
|
-
export { ModelRelationship };
|
|
344
|
-
//# sourceMappingURL=relationship.js.map
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import Observable from '
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
2
|
import { Patch } from 'immer';
|
|
3
3
|
import { ModelInstanceCreator } from '../datastore/datastore';
|
|
4
4
|
import { InternalSchema, ModelInstanceMetadata, ModelPredicate, NamespaceResolver, OpType, PaginationInput, PersistentModel, PersistentModelConstructor, QueryOne, SchemaNamespace, InternalSubscriptionMessage, SubscriptionMessage } from '../types';
|
|
5
5
|
import { NAMESPACES } from '../util';
|
|
6
6
|
import { Adapter } from './adapter';
|
|
7
|
-
export
|
|
7
|
+
export type StorageSubscriptionMessage<T extends PersistentModel> = InternalSubscriptionMessage<T> & {
|
|
8
8
|
mutator?: Symbol;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
11
|
-
export
|
|
10
|
+
export type StorageFacade = Omit<Adapter, 'setUp'>;
|
|
11
|
+
export type Storage = InstanceType<typeof StorageClass>;
|
|
12
12
|
declare class StorageClass implements StorageFacade {
|
|
13
13
|
private readonly schema;
|
|
14
14
|
private readonly namespaceResolver;
|