@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,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.ModelRelationship = void 0;
|
|
4
4
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
5
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
|
|
6
|
+
const types_1 = require("../types");
|
|
7
7
|
/**
|
|
8
8
|
* Defines a relationship from a LOCAL model.field to a REMOTE model.field and helps
|
|
9
9
|
* navigate the relationship, providing a simplified peek at the relationship details
|
|
@@ -12,14 +12,14 @@ var types_1 = require("../types");
|
|
|
12
12
|
* Because I mean, relationships are tough.
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
class ModelRelationship {
|
|
16
16
|
/**
|
|
17
17
|
* @param modelDefinition The "local" model.
|
|
18
18
|
* @param field The "local" model field.
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
if (!types_1.isFieldAssociation(model.schema, field)) {
|
|
22
|
-
throw new Error(model.schema.name
|
|
20
|
+
constructor(model, field) {
|
|
21
|
+
if (!(0, types_1.isFieldAssociation)(model.schema, field)) {
|
|
22
|
+
throw new Error(`${model.schema.name}.${field} is not a relationship.`);
|
|
23
23
|
}
|
|
24
24
|
this.localModel = model;
|
|
25
25
|
this._field = field;
|
|
@@ -31,263 +31,189 @@ var ModelRelationship = /** @class */ (function () {
|
|
|
31
31
|
* @param model The model the relationship field exists in.
|
|
32
32
|
* @param field The field that may relates the local model to the remote model.
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
if (types_1.isFieldAssociation(model.schema, field)) {
|
|
34
|
+
static from(model, field) {
|
|
35
|
+
if ((0, types_1.isFieldAssociation)(model.schema, field)) {
|
|
36
36
|
return new this(model, field);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
return null;
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|
|
42
42
|
/**
|
|
43
43
|
* Enumerates all valid `ModelRelationship`'s on the given model.
|
|
44
44
|
*
|
|
45
45
|
* @param model The model definition to enumerate relationships of.
|
|
46
46
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var field = _c.value;
|
|
53
|
-
var relationship = ModelRelationship.from(model, field);
|
|
54
|
-
relationship && relationships.push(relationship);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
58
|
-
finally {
|
|
59
|
-
try {
|
|
60
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
61
|
-
}
|
|
62
|
-
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);
|
|
63
52
|
}
|
|
64
53
|
return relationships;
|
|
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
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Raw details about the local FK as-is from the local model's field definition in
|
|
109
|
-
* the schema. This field requires interpretation.
|
|
110
|
-
*
|
|
111
|
-
* @see localJoinFields
|
|
112
|
-
* @see localAssociatedWith
|
|
113
|
-
*/
|
|
114
|
-
get: function () {
|
|
115
|
-
return this.localDefinition.fields[this.field].association;
|
|
116
|
-
},
|
|
117
|
-
enumerable: true,
|
|
118
|
-
configurable: true
|
|
119
|
-
});
|
|
120
|
-
Object.defineProperty(ModelRelationship.prototype, "localJoinFields", {
|
|
121
|
-
/**
|
|
122
|
-
* The field names on the local model that can be used to query or queried to match
|
|
123
|
-
* with instances of the remote model.
|
|
124
|
-
*
|
|
125
|
-
* Fields are returned in-order to match the order of `this.remoteKeyFields`.
|
|
126
|
-
*/
|
|
127
|
-
get: function () {
|
|
128
|
-
/**
|
|
129
|
-
* This is relatively straightforward, actually.
|
|
130
|
-
*
|
|
131
|
-
* If we have explicitly stated targetNames, codegen is telling us authoritatively
|
|
132
|
-
* to use those fields for this relationship. The local model "points to" fields
|
|
133
|
-
* in the remote one.
|
|
134
|
-
*
|
|
135
|
-
* In other cases, the remote model points to this one's
|
|
136
|
-
*/
|
|
137
|
-
if (this.localAssocation.targetName) {
|
|
138
|
-
// This case is theoretically unnecessary going forward.
|
|
139
|
-
return [this.localAssocation.targetName];
|
|
140
|
-
}
|
|
141
|
-
else if (this.localAssocation.targetNames) {
|
|
142
|
-
return this.localAssocation.targetNames;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
return this.localPKFields;
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
enumerable: true,
|
|
149
|
-
configurable: true
|
|
150
|
-
});
|
|
151
|
-
Object.defineProperty(ModelRelationship.prototype, "localPKFields", {
|
|
152
|
-
/**
|
|
153
|
-
* The field names on the local model that uniquely identify it.
|
|
154
|
-
*
|
|
155
|
-
* These fields may or may not be relevant to the join fields.
|
|
156
|
-
*/
|
|
157
|
-
get: function () {
|
|
158
|
-
return this.localModel.pkField;
|
|
159
|
-
},
|
|
160
|
-
enumerable: true,
|
|
161
|
-
configurable: true
|
|
162
|
-
});
|
|
163
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteDefinition", {
|
|
164
|
-
get: function () {
|
|
165
|
-
var _a;
|
|
166
|
-
return (_a = this.remoteModelType.modelConstructor) === null || _a === void 0 ? void 0 : _a.schema;
|
|
167
|
-
},
|
|
168
|
-
enumerable: true,
|
|
169
|
-
configurable: true
|
|
170
|
-
});
|
|
171
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteModelType", {
|
|
172
|
-
get: function () {
|
|
173
|
-
return this.localDefinition.fields[this.field].type;
|
|
174
|
-
},
|
|
175
|
-
enumerable: true,
|
|
176
|
-
configurable: true
|
|
177
|
-
});
|
|
178
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteModelConstructor", {
|
|
179
|
-
/**
|
|
180
|
-
* Constructor that can be used to query DataStore or create instances for
|
|
181
|
-
* the remote model.
|
|
182
|
-
*/
|
|
183
|
-
get: function () {
|
|
184
|
-
return this.remoteModelType.modelConstructor.builder;
|
|
185
|
-
},
|
|
186
|
-
enumerable: true,
|
|
187
|
-
configurable: true
|
|
188
|
-
});
|
|
189
|
-
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() {
|
|
190
96
|
/**
|
|
191
|
-
*
|
|
97
|
+
* This is relatively straightforward, actually.
|
|
192
98
|
*
|
|
193
|
-
*
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
var _a;
|
|
197
|
-
return ((_a = this.remoteModelType.modelConstructor) === null || _a === void 0 ? void 0 : _a.pkField) || ['id'];
|
|
198
|
-
},
|
|
199
|
-
enumerable: true,
|
|
200
|
-
configurable: true
|
|
201
|
-
});
|
|
202
|
-
Object.defineProperty(ModelRelationship.prototype, "localAssociatedWith", {
|
|
203
|
-
/**
|
|
204
|
-
* 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.
|
|
205
102
|
*
|
|
206
|
-
*
|
|
207
|
-
* when looking for a remote association and/or determining the final remote
|
|
208
|
-
* key fields.
|
|
103
|
+
* In other cases, the remote model points to this one's
|
|
209
104
|
*/
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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;
|
|
217
178
|
}
|
|
218
179
|
else {
|
|
219
180
|
return undefined;
|
|
220
181
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
* This is used when determining if the remote model's associated field
|
|
231
|
-
* specifies which FK fields to use. If this value is `undefined`, the
|
|
232
|
-
* name of the remote field (`this.localAssociatedWith`) *is* the remote
|
|
233
|
-
* key field.
|
|
234
|
-
*/
|
|
235
|
-
get: function () {
|
|
236
|
-
var _a;
|
|
237
|
-
if (this.localAssociatedWith) {
|
|
238
|
-
if (this.localAssociatedWith.length === 1) {
|
|
239
|
-
return (_a = this.remoteDefinition.fields[this.localAssociatedWith[0]]) === null || _a === void 0 ? void 0 : _a.association;
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
return undefined;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
enumerable: true,
|
|
247
|
-
configurable: true
|
|
248
|
-
});
|
|
249
|
-
Object.defineProperty(ModelRelationship.prototype, "remoteJoinFields", {
|
|
250
|
-
/**
|
|
251
|
-
* The field names on the remote model that can used to query or queried to match
|
|
252
|
-
* with instances of the local model.
|
|
253
|
-
*
|
|
254
|
-
* Fields are returned in-order to match the order of `this.localKeyFields`.
|
|
255
|
-
*/
|
|
256
|
-
get: function () {
|
|
257
|
-
/**
|
|
258
|
-
* If the local relationship explicitly names "associated with" fields, we
|
|
259
|
-
* need to see if this points direction to a reciprocating assocation. If it
|
|
260
|
-
* does, the remote assocation indicates what fields to use.
|
|
261
|
-
*/
|
|
262
|
-
var _a, _b, _c;
|
|
263
|
-
if ((_a = this.explicitRemoteAssociation) === null || _a === void 0 ? void 0 : _a.targetName) {
|
|
264
|
-
// This case is theoretically unnecessary going forward.
|
|
265
|
-
return [this.explicitRemoteAssociation.targetName];
|
|
266
|
-
}
|
|
267
|
-
else if ((_b = this.explicitRemoteAssociation) === null || _b === void 0 ? void 0 : _b.targetNames) {
|
|
268
|
-
return (_c = this.explicitRemoteAssociation) === null || _c === void 0 ? void 0 : _c.targetNames;
|
|
269
|
-
}
|
|
270
|
-
else if (this.localAssociatedWith) {
|
|
271
|
-
return this.localAssociatedWith;
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
return this.remotePKFields;
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
enumerable: true,
|
|
278
|
-
configurable: true
|
|
279
|
-
});
|
|
280
|
-
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() {
|
|
281
191
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
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.
|
|
284
195
|
*/
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
+
}
|
|
291
217
|
/**
|
|
292
218
|
* Creates an FK mapper object with respect to the given related instance.
|
|
293
219
|
*
|
|
@@ -304,13 +230,13 @@ var ModelRelationship = /** @class */ (function () {
|
|
|
304
230
|
*
|
|
305
231
|
* @param remote The remote related instance.
|
|
306
232
|
*/
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
for (
|
|
233
|
+
createLocalFKObject(remote) {
|
|
234
|
+
const fk = {};
|
|
235
|
+
for (let i = 0; i < this.localJoinFields.length; i++) {
|
|
310
236
|
fk[this.localJoinFields[i]] = remote[this.remoteJoinFields[i]];
|
|
311
237
|
}
|
|
312
238
|
return fk;
|
|
313
|
-
}
|
|
239
|
+
}
|
|
314
240
|
/**
|
|
315
241
|
* Creates an query mapper object to help fetch the remote instance(s) or
|
|
316
242
|
* `null` if any of the necessary local fields are `null` or `undefined`.
|
|
@@ -330,17 +256,15 @@ var ModelRelationship = /** @class */ (function () {
|
|
|
330
256
|
*
|
|
331
257
|
* @param local The local instance.
|
|
332
258
|
*/
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
for (
|
|
336
|
-
|
|
259
|
+
createRemoteQueryObject(local) {
|
|
260
|
+
const query = {};
|
|
261
|
+
for (let i = 0; i < this.remoteJoinFields.length; i++) {
|
|
262
|
+
const localValue = local[this.localJoinFields[i]];
|
|
337
263
|
if (localValue === null || localValue === undefined)
|
|
338
264
|
return null;
|
|
339
265
|
query[this.remoteJoinFields[i]] = local[this.localJoinFields[i]];
|
|
340
266
|
}
|
|
341
267
|
return query;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
}());
|
|
268
|
+
}
|
|
269
|
+
}
|
|
345
270
|
exports.ModelRelationship = ModelRelationship;
|
|
346
|
-
//# sourceMappingURL=relationship.js.map
|
package/lib/storage/storage.d.ts
CHANGED
|
@@ -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;
|