@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.
Files changed (187) hide show
  1. package/README.md +4 -0
  2. package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
  3. package/lib/authModeStrategies/index.js +3 -3
  4. package/lib/authModeStrategies/multiAuthStrategy.js +38 -53
  5. package/lib/datastore/datastore.d.ts +4 -5
  6. package/lib/datastore/datastore.js +929 -1284
  7. package/lib/index.d.ts +1 -1
  8. package/lib/index.js +26 -13
  9. package/lib/predicates/index.js +54 -69
  10. package/lib/predicates/next.d.ts +2 -2
  11. package/lib/predicates/next.js +313 -462
  12. package/lib/predicates/sort.js +24 -28
  13. package/lib/ssr/index.js +2 -2
  14. package/lib/storage/adapter/AsyncStorageAdapter.js +120 -342
  15. package/lib/storage/adapter/AsyncStorageDatabase.js +217 -421
  16. package/lib/storage/adapter/InMemoryStore.js +28 -51
  17. package/lib/storage/adapter/InMemoryStore.native.js +5 -3
  18. package/lib/storage/adapter/IndexedDBAdapter.js +466 -871
  19. package/lib/storage/adapter/StorageAdapterBase.js +180 -330
  20. package/lib/storage/adapter/getDefaultAdapter/index.js +8 -10
  21. package/lib/storage/adapter/getDefaultAdapter/index.native.js +5 -4
  22. package/lib/storage/adapter/index.js +0 -1
  23. package/lib/storage/relationship.js +177 -253
  24. package/lib/storage/storage.d.ts +4 -4
  25. package/lib/storage/storage.js +255 -433
  26. package/lib/sync/datastoreConnectivity.d.ts +2 -2
  27. package/lib/sync/datastoreConnectivity.js +29 -39
  28. package/lib/sync/datastoreReachability/index.d.ts +1 -3
  29. package/lib/sync/datastoreReachability/index.js +3 -3
  30. package/lib/sync/datastoreReachability/index.native.d.ts +1 -3
  31. package/lib/sync/datastoreReachability/index.native.js +4 -5
  32. package/lib/sync/index.d.ts +2 -2
  33. package/lib/sync/index.js +522 -827
  34. package/lib/sync/merger.js +31 -63
  35. package/lib/sync/outbox.js +148 -232
  36. package/lib/sync/processors/errorMaps.d.ts +1 -1
  37. package/lib/sync/processors/errorMaps.js +30 -47
  38. package/lib/sync/processors/mutation.d.ts +2 -2
  39. package/lib/sync/processors/mutation.js +343 -502
  40. package/lib/sync/processors/subscription.d.ts +5 -2
  41. package/lib/sync/processors/subscription.js +283 -437
  42. package/lib/sync/processors/sync.d.ts +2 -2
  43. package/lib/sync/processors/sync.js +279 -404
  44. package/lib/sync/utils.d.ts +5 -4
  45. package/lib/sync/utils.js +267 -320
  46. package/lib/tsconfig.tsbuildinfo +1 -0
  47. package/lib/types.d.ts +138 -140
  48. package/lib/types.js +17 -24
  49. package/lib/util.d.ts +9 -17
  50. package/lib/util.js +387 -511
  51. package/lib-esm/authModeStrategies/defaultAuthStrategy.js +1 -2
  52. package/lib-esm/authModeStrategies/index.js +0 -1
  53. package/lib-esm/authModeStrategies/multiAuthStrategy.js +35 -52
  54. package/lib-esm/datastore/datastore.d.ts +4 -5
  55. package/lib-esm/datastore/datastore.js +888 -1247
  56. package/lib-esm/index.d.ts +1 -1
  57. package/lib-esm/index.js +6 -7
  58. package/lib-esm/predicates/index.js +53 -70
  59. package/lib-esm/predicates/next.d.ts +2 -2
  60. package/lib-esm/predicates/next.js +306 -459
  61. package/lib-esm/predicates/sort.js +23 -28
  62. package/lib-esm/ssr/index.js +1 -2
  63. package/lib-esm/storage/adapter/AsyncStorageAdapter.js +111 -338
  64. package/lib-esm/storage/adapter/AsyncStorageDatabase.js +212 -416
  65. package/lib-esm/storage/adapter/InMemoryStore.js +27 -52
  66. package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
  67. package/lib-esm/storage/adapter/IndexedDBAdapter.js +438 -866
  68. package/lib-esm/storage/adapter/StorageAdapterBase.js +173 -325
  69. package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -6
  70. package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +1 -2
  71. package/lib-esm/storage/adapter/index.js +1 -1
  72. package/lib-esm/storage/relationship.js +173 -251
  73. package/lib-esm/storage/storage.d.ts +4 -4
  74. package/lib-esm/storage/storage.js +242 -424
  75. package/lib-esm/sync/datastoreConnectivity.d.ts +2 -2
  76. package/lib-esm/sync/datastoreConnectivity.js +28 -39
  77. package/lib-esm/sync/datastoreReachability/index.d.ts +1 -3
  78. package/lib-esm/sync/datastoreReachability/index.js +2 -3
  79. package/lib-esm/sync/datastoreReachability/index.native.d.ts +1 -3
  80. package/lib-esm/sync/datastoreReachability/index.native.js +3 -4
  81. package/lib-esm/sync/index.d.ts +2 -2
  82. package/lib-esm/sync/index.js +502 -812
  83. package/lib-esm/sync/merger.js +28 -61
  84. package/lib-esm/sync/outbox.js +143 -228
  85. package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
  86. package/lib-esm/sync/processors/errorMaps.js +32 -50
  87. package/lib-esm/sync/processors/mutation.d.ts +2 -2
  88. package/lib-esm/sync/processors/mutation.js +329 -490
  89. package/lib-esm/sync/processors/subscription.d.ts +5 -2
  90. package/lib-esm/sync/processors/subscription.js +266 -421
  91. package/lib-esm/sync/processors/sync.d.ts +2 -2
  92. package/lib-esm/sync/processors/sync.js +271 -397
  93. package/lib-esm/sync/utils.d.ts +5 -4
  94. package/lib-esm/sync/utils.js +252 -307
  95. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  96. package/lib-esm/types.d.ts +138 -140
  97. package/lib-esm/types.js +16 -25
  98. package/lib-esm/util.d.ts +9 -17
  99. package/lib-esm/util.js +335 -497
  100. package/package.json +31 -26
  101. package/src/authModeStrategies/multiAuthStrategy.ts +15 -12
  102. package/src/datastore/datastore.ts +36 -35
  103. package/src/predicates/sort.ts +3 -1
  104. package/src/storage/adapter/InMemoryStore.ts +1 -1
  105. package/src/storage/adapter/IndexedDBAdapter.ts +2 -2
  106. package/src/storage/adapter/StorageAdapterBase.ts +2 -2
  107. package/src/storage/adapter/getDefaultAdapter/index.ts +1 -4
  108. package/src/storage/storage.ts +29 -24
  109. package/src/sync/datastoreConnectivity.ts +6 -6
  110. package/src/sync/datastoreReachability/index.native.ts +5 -3
  111. package/src/sync/datastoreReachability/index.ts +1 -1
  112. package/src/sync/index.ts +79 -89
  113. package/src/sync/processors/errorMaps.ts +7 -7
  114. package/src/sync/processors/mutation.ts +19 -13
  115. package/src/sync/processors/subscription.ts +221 -295
  116. package/src/sync/processors/sync.ts +11 -8
  117. package/src/sync/utils.ts +30 -15
  118. package/src/types.ts +4 -8
  119. package/src/util.ts +46 -9
  120. package/lib/.tsbuildinfo +0 -3
  121. package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
  122. package/lib/authModeStrategies/index.js.map +0 -1
  123. package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
  124. package/lib/datastore/datastore.js.map +0 -1
  125. package/lib/index.js.map +0 -1
  126. package/lib/predicates/index.js.map +0 -1
  127. package/lib/predicates/next.js.map +0 -1
  128. package/lib/predicates/sort.js.map +0 -1
  129. package/lib/ssr/index.js.map +0 -1
  130. package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
  131. package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
  132. package/lib/storage/adapter/InMemoryStore.js.map +0 -1
  133. package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
  134. package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
  135. package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
  136. package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
  137. package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
  138. package/lib/storage/adapter/index.js.map +0 -1
  139. package/lib/storage/relationship.js.map +0 -1
  140. package/lib/storage/storage.js.map +0 -1
  141. package/lib/sync/datastoreConnectivity.js.map +0 -1
  142. package/lib/sync/datastoreReachability/index.js.map +0 -1
  143. package/lib/sync/datastoreReachability/index.native.js.map +0 -1
  144. package/lib/sync/index.js.map +0 -1
  145. package/lib/sync/merger.js.map +0 -1
  146. package/lib/sync/outbox.js.map +0 -1
  147. package/lib/sync/processors/errorMaps.js.map +0 -1
  148. package/lib/sync/processors/mutation.js.map +0 -1
  149. package/lib/sync/processors/subscription.js.map +0 -1
  150. package/lib/sync/processors/sync.js.map +0 -1
  151. package/lib/sync/utils.js.map +0 -1
  152. package/lib/types.js.map +0 -1
  153. package/lib/util.js.map +0 -1
  154. package/lib-esm/.tsbuildinfo +0 -3
  155. package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
  156. package/lib-esm/authModeStrategies/index.js.map +0 -1
  157. package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
  158. package/lib-esm/datastore/datastore.js.map +0 -1
  159. package/lib-esm/index.js.map +0 -1
  160. package/lib-esm/predicates/index.js.map +0 -1
  161. package/lib-esm/predicates/next.js.map +0 -1
  162. package/lib-esm/predicates/sort.js.map +0 -1
  163. package/lib-esm/ssr/index.js.map +0 -1
  164. package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
  165. package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
  166. package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
  167. package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
  168. package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
  169. package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
  170. package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
  171. package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
  172. package/lib-esm/storage/adapter/index.js.map +0 -1
  173. package/lib-esm/storage/relationship.js.map +0 -1
  174. package/lib-esm/storage/storage.js.map +0 -1
  175. package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
  176. package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
  177. package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
  178. package/lib-esm/sync/index.js.map +0 -1
  179. package/lib-esm/sync/merger.js.map +0 -1
  180. package/lib-esm/sync/outbox.js.map +0 -1
  181. package/lib-esm/sync/processors/errorMaps.js.map +0 -1
  182. package/lib-esm/sync/processors/mutation.js.map +0 -1
  183. package/lib-esm/sync/processors/subscription.js.map +0 -1
  184. package/lib-esm/sync/processors/sync.js.map +0 -1
  185. package/lib-esm/sync/utils.js.map +0 -1
  186. package/lib-esm/types.js.map +0 -1
  187. 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
- var tslib_1 = require("tslib");
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
- var types_1 = require("../types");
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
- var ModelRelationship = /** @class */ (function () {
15
+ class ModelRelationship {
16
16
  /**
17
17
  * @param modelDefinition The "local" model.
18
18
  * @param field The "local" model field.
19
19
  */
20
- function ModelRelationship(model, field) {
21
- if (!types_1.isFieldAssociation(model.schema, field)) {
22
- throw new Error(model.schema.name + "." + field + " is not a relationship.");
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
- ModelRelationship.from = function (model, field) {
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
- ModelRelationship.allFrom = function (model) {
48
- var e_1, _a;
49
- var relationships = [];
50
- try {
51
- for (var _b = tslib_1.__values(Object.keys(model.schema.fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
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
- Object.defineProperty(ModelRelationship.prototype, "localDefinition", {
67
- get: function () {
68
- return this.localModel.schema;
69
- },
70
- enumerable: true,
71
- configurable: true
72
- });
73
- Object.defineProperty(ModelRelationship.prototype, "field", {
74
- /**
75
- * The virtual/computed field on the local model that should contain
76
- * the related model.
77
- */
78
- get: function () {
79
- return this._field;
80
- },
81
- enumerable: true,
82
- configurable: true
83
- });
84
- Object.defineProperty(ModelRelationship.prototype, "localConstructor", {
85
- /**
86
- * The constructor that can be used to query DataStore or create instance for
87
- * the local model.
88
- */
89
- get: function () {
90
- return this.localModel.builder;
91
- },
92
- enumerable: true,
93
- configurable: true
94
- });
95
- Object.defineProperty(ModelRelationship.prototype, "type", {
96
- /**
97
- * The name/type of the relationship the local model has with the remote model
98
- * via the defined local model field.
99
- */
100
- get: function () {
101
- return this.localAssocation.connectionType;
102
- },
103
- enumerable: true,
104
- configurable: true
105
- });
106
- Object.defineProperty(ModelRelationship.prototype, "localAssocation", {
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
- * The field names on the remote model that uniquely identify it.
97
+ * This is relatively straightforward, actually.
192
98
  *
193
- * These fields may or may not be relevant to the join fields.
194
- */
195
- get: function () {
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
- * When present, these fields indicate which fields on the remote model to use
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
- get: function () {
211
- if (this.localAssocation.connectionType === 'HAS_MANY' ||
212
- this.localAssocation.connectionType === 'HAS_ONE') {
213
- // This de-arraying is theoretically unnecessary going forward.
214
- return Array.isArray(this.localAssocation.associatedWith)
215
- ? this.localAssocation.associatedWith
216
- : [this.localAssocation.associatedWith];
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
- enumerable: true,
223
- configurable: true
224
- });
225
- Object.defineProperty(ModelRelationship.prototype, "explicitRemoteAssociation", {
226
- /**
227
- * The `remote` model's associated field's `assocation` metadata, if
228
- * present.
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
- * Whether this relationship everything necessary to get, set, and query from
283
- * the perspective of the local model provided at instantiation.
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
- get: function () {
286
- return this.localJoinFields.length > 0 && this.remoteJoinFields.length > 0;
287
- },
288
- enumerable: true,
289
- configurable: true
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
- ModelRelationship.prototype.createLocalFKObject = function (remote) {
308
- var fk = {};
309
- for (var i = 0; i < this.localJoinFields.length; i++) {
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
- ModelRelationship.prototype.createRemoteQueryObject = function (local) {
334
- var query = {};
335
- for (var i = 0; i < this.remoteJoinFields.length; i++) {
336
- var localValue = local[this.localJoinFields[i]];
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
- return ModelRelationship;
344
- }());
268
+ }
269
+ }
345
270
  exports.ModelRelationship = ModelRelationship;
346
- //# sourceMappingURL=relationship.js.map
@@ -1,14 +1,14 @@
1
- import Observable from 'zen-observable-ts';
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 declare type StorageSubscriptionMessage<T extends PersistentModel> = InternalSubscriptionMessage<T> & {
7
+ export type StorageSubscriptionMessage<T extends PersistentModel> = InternalSubscriptionMessage<T> & {
8
8
  mutator?: Symbol;
9
9
  };
10
- export declare type StorageFacade = Omit<Adapter, 'setUp'>;
11
- export declare type Storage = InstanceType<typeof StorageClass>;
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;