@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,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
- var ModelRelationship = /** @class */ (function () {
12
+ export class ModelRelationship {
14
13
  /**
15
14
  * @param modelDefinition The "local" model.
16
15
  * @param field The "local" model field.
17
16
  */
18
- function ModelRelationship(model, field) {
17
+ constructor(model, field) {
19
18
  if (!isFieldAssociation(model.schema, field)) {
20
- throw new Error(model.schema.name + "." + field + " is not a relationship.");
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
- ModelRelationship.from = function (model, field) {
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
- ModelRelationship.allFrom = function (model) {
46
- var e_1, _a;
47
- var relationships = [];
48
- try {
49
- for (var _b = __values(Object.keys(model.schema.fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
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
- Object.defineProperty(ModelRelationship.prototype, "localDefinition", {
65
- get: function () {
66
- return this.localModel.schema;
67
- },
68
- enumerable: true,
69
- configurable: true
70
- });
71
- Object.defineProperty(ModelRelationship.prototype, "field", {
72
- /**
73
- * The virtual/computed field on the local model that should contain
74
- * the related model.
75
- */
76
- get: function () {
77
- return this._field;
78
- },
79
- enumerable: true,
80
- configurable: true
81
- });
82
- Object.defineProperty(ModelRelationship.prototype, "localConstructor", {
83
- /**
84
- * The constructor that can be used to query DataStore or create instance for
85
- * the local model.
86
- */
87
- get: function () {
88
- return this.localModel.builder;
89
- },
90
- enumerable: true,
91
- configurable: true
92
- });
93
- Object.defineProperty(ModelRelationship.prototype, "type", {
94
- /**
95
- * The name/type of the relationship the local model has with the remote model
96
- * via the defined local model field.
97
- */
98
- get: function () {
99
- return this.localAssocation.connectionType;
100
- },
101
- enumerable: true,
102
- configurable: true
103
- });
104
- Object.defineProperty(ModelRelationship.prototype, "localAssocation", {
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
- * The field names on the remote model that uniquely identify it.
94
+ * This is relatively straightforward, actually.
190
95
  *
191
- * These fields may or may not be relevant to the join fields.
192
- */
193
- get: function () {
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
- * When present, these fields indicate which fields on the remote model to use
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
- get: function () {
209
- if (this.localAssocation.connectionType === 'HAS_MANY' ||
210
- this.localAssocation.connectionType === 'HAS_ONE') {
211
- // This de-arraying is theoretically unnecessary going forward.
212
- return Array.isArray(this.localAssocation.associatedWith)
213
- ? this.localAssocation.associatedWith
214
- : [this.localAssocation.associatedWith];
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
- enumerable: true,
221
- configurable: true
222
- });
223
- Object.defineProperty(ModelRelationship.prototype, "explicitRemoteAssociation", {
224
- /**
225
- * The `remote` model's associated field's `assocation` metadata, if
226
- * present.
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
- * Whether this relationship everything necessary to get, set, and query from
281
- * the perspective of the local model provided at instantiation.
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
- get: function () {
284
- return this.localJoinFields.length > 0 && this.remoteJoinFields.length > 0;
285
- },
286
- enumerable: true,
287
- configurable: true
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
- ModelRelationship.prototype.createLocalFKObject = function (remote) {
306
- var fk = {};
307
- for (var i = 0; i < this.localJoinFields.length; i++) {
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
- ModelRelationship.prototype.createRemoteQueryObject = function (local) {
332
- var query = {};
333
- for (var i = 0; i < this.remoteJoinFields.length; i++) {
334
- var localValue = local[this.localJoinFields[i]];
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
- return ModelRelationship;
342
- }());
343
- export { ModelRelationship };
344
- //# sourceMappingURL=relationship.js.map
265
+ }
266
+ }
@@ -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;