@warp-drive/legacy 5.6.0-alpha.11

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 (211) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +23 -0
  3. package/README.md +54 -0
  4. package/addon-main.cjs +5 -0
  5. package/declarations/adapter/-private/build-url-mixin.d.ts +34 -0
  6. package/declarations/adapter/-private/build-url-mixin.d.ts.map +1 -0
  7. package/declarations/adapter/-private/fastboot-interface.d.ts +9 -0
  8. package/declarations/adapter/-private/fastboot-interface.d.ts.map +1 -0
  9. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +8 -0
  10. package/declarations/adapter/-private/utils/continue-on-reject.d.ts.map +1 -0
  11. package/declarations/adapter/-private/utils/determine-body-promise.d.ts +5 -0
  12. package/declarations/adapter/-private/utils/determine-body-promise.d.ts.map +1 -0
  13. package/declarations/adapter/-private/utils/fetch.d.ts +9 -0
  14. package/declarations/adapter/-private/utils/fetch.d.ts.map +1 -0
  15. package/declarations/adapter/-private/utils/parse-response-headers.d.ts +2 -0
  16. package/declarations/adapter/-private/utils/parse-response-headers.d.ts.map +1 -0
  17. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +7 -0
  18. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts.map +1 -0
  19. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +6 -0
  20. package/declarations/adapter/-private/utils/serialize-query-params.d.ts.map +1 -0
  21. package/declarations/adapter/-private.d.ts +6 -0
  22. package/declarations/adapter/-private.d.ts.map +1 -0
  23. package/declarations/adapter/error.d.ts +188 -0
  24. package/declarations/adapter/error.d.ts.map +1 -0
  25. package/declarations/adapter/json-api.d.ts +234 -0
  26. package/declarations/adapter/json-api.d.ts.map +1 -0
  27. package/declarations/adapter/rest.d.ts +823 -0
  28. package/declarations/adapter/rest.d.ts.map +1 -0
  29. package/declarations/adapter.d.ts +801 -0
  30. package/declarations/adapter.d.ts.map +1 -0
  31. package/declarations/compat/-private.d.ts +14 -0
  32. package/declarations/compat/-private.d.ts.map +1 -0
  33. package/declarations/compat/builders/find-all.d.ts +33 -0
  34. package/declarations/compat/builders/find-all.d.ts.map +1 -0
  35. package/declarations/compat/builders/find-record.d.ts +54 -0
  36. package/declarations/compat/builders/find-record.d.ts.map +1 -0
  37. package/declarations/compat/builders/query.d.ts +61 -0
  38. package/declarations/compat/builders/query.d.ts.map +1 -0
  39. package/declarations/compat/builders/save-record.d.ts +32 -0
  40. package/declarations/compat/builders/save-record.d.ts.map +1 -0
  41. package/declarations/compat/builders/utils.d.ts +4 -0
  42. package/declarations/compat/builders/utils.d.ts.map +1 -0
  43. package/declarations/compat/builders.d.ts +15 -0
  44. package/declarations/compat/builders.d.ts.map +1 -0
  45. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +47 -0
  46. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +1 -0
  47. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +3 -0
  48. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +1 -0
  49. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +12 -0
  50. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -0
  51. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +6 -0
  52. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +1 -0
  53. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +3 -0
  54. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +1 -0
  55. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +527 -0
  56. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -0
  57. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +224 -0
  58. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -0
  59. package/declarations/compat/legacy-network-handler/serializer-response.d.ts +7 -0
  60. package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +1 -0
  61. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +89 -0
  62. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +1 -0
  63. package/declarations/compat/legacy-network-handler/snapshot.d.ts +237 -0
  64. package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +1 -0
  65. package/declarations/compat/utils.d.ts +138 -0
  66. package/declarations/compat/utils.d.ts.map +1 -0
  67. package/declarations/compat.d.ts +134 -0
  68. package/declarations/compat.d.ts.map +1 -0
  69. package/declarations/model/-private/attr.d.ts +165 -0
  70. package/declarations/model/-private/attr.d.ts.map +1 -0
  71. package/declarations/model/-private/attr.type-test.d.ts +2 -0
  72. package/declarations/model/-private/attr.type-test.d.ts.map +1 -0
  73. package/declarations/model/-private/belongs-to.d.ts +173 -0
  74. package/declarations/model/-private/belongs-to.d.ts.map +1 -0
  75. package/declarations/model/-private/belongs-to.type-test.d.ts +2 -0
  76. package/declarations/model/-private/belongs-to.type-test.d.ts.map +1 -0
  77. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +6 -0
  78. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
  79. package/declarations/model/-private/errors.d.ts +290 -0
  80. package/declarations/model/-private/errors.d.ts.map +1 -0
  81. package/declarations/model/-private/has-many.d.ts +164 -0
  82. package/declarations/model/-private/has-many.d.ts.map +1 -0
  83. package/declarations/model/-private/has-many.type-test.d.ts +2 -0
  84. package/declarations/model/-private/has-many.type-test.d.ts.map +1 -0
  85. package/declarations/model/-private/hooks.d.ts +11 -0
  86. package/declarations/model/-private/hooks.d.ts.map +1 -0
  87. package/declarations/model/-private/legacy-relationships-support.d.ts +57 -0
  88. package/declarations/model/-private/legacy-relationships-support.d.ts.map +1 -0
  89. package/declarations/model/-private/model-for-mixin.d.ts +4 -0
  90. package/declarations/model/-private/model-for-mixin.d.ts.map +1 -0
  91. package/declarations/model/-private/model-methods.d.ts +35 -0
  92. package/declarations/model/-private/model-methods.d.ts.map +1 -0
  93. package/declarations/model/-private/model.d.ts +1270 -0
  94. package/declarations/model/-private/model.d.ts.map +1 -0
  95. package/declarations/model/-private/model.type-test.d.ts +2 -0
  96. package/declarations/model/-private/model.type-test.d.ts.map +1 -0
  97. package/declarations/model/-private/notify-changes.d.ts +5 -0
  98. package/declarations/model/-private/notify-changes.d.ts.map +1 -0
  99. package/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  100. package/declarations/model/-private/promise-belongs-to.d.ts.map +1 -0
  101. package/declarations/model/-private/promise-many-array.d.ts +126 -0
  102. package/declarations/model/-private/promise-many-array.d.ts.map +1 -0
  103. package/declarations/model/-private/promise-proxy-base.d.ts +3 -0
  104. package/declarations/model/-private/promise-proxy-base.d.ts.map +1 -0
  105. package/declarations/model/-private/record-state.d.ts +78 -0
  106. package/declarations/model/-private/record-state.d.ts.map +1 -0
  107. package/declarations/model/-private/references/belongs-to.d.ts +495 -0
  108. package/declarations/model/-private/references/belongs-to.d.ts.map +1 -0
  109. package/declarations/model/-private/references/has-many.d.ts +504 -0
  110. package/declarations/model/-private/references/has-many.d.ts.map +1 -0
  111. package/declarations/model/-private/schema-provider.d.ts +63 -0
  112. package/declarations/model/-private/schema-provider.d.ts.map +1 -0
  113. package/declarations/model/-private/type-utils.d.ts +57 -0
  114. package/declarations/model/-private/type-utils.d.ts.map +1 -0
  115. package/declarations/model/-private/util.d.ts +6 -0
  116. package/declarations/model/-private/util.d.ts.map +1 -0
  117. package/declarations/model/-private.d.ts +8 -0
  118. package/declarations/model/-private.d.ts.map +1 -0
  119. package/declarations/model/migration-support.d.ts +287 -0
  120. package/declarations/model/migration-support.d.ts.map +1 -0
  121. package/declarations/model/migration-support.type-test.d.ts +2 -0
  122. package/declarations/model/migration-support.type-test.d.ts.map +1 -0
  123. package/declarations/model.d.ts +50 -0
  124. package/declarations/model.d.ts.map +1 -0
  125. package/declarations/serializer/-private/embedded-records-mixin.d.ts +97 -0
  126. package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +1 -0
  127. package/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  128. package/declarations/serializer/-private/transforms/boolean.d.ts.map +1 -0
  129. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +2 -0
  130. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +1 -0
  131. package/declarations/serializer/-private/transforms/date.d.ts +28 -0
  132. package/declarations/serializer/-private/transforms/date.d.ts.map +1 -0
  133. package/declarations/serializer/-private/transforms/number.d.ts +29 -0
  134. package/declarations/serializer/-private/transforms/number.d.ts.map +1 -0
  135. package/declarations/serializer/-private/transforms/string.d.ts +29 -0
  136. package/declarations/serializer/-private/transforms/string.d.ts.map +1 -0
  137. package/declarations/serializer/-private/transforms/transform.d.ts +119 -0
  138. package/declarations/serializer/-private/transforms/transform.d.ts.map +1 -0
  139. package/declarations/serializer/-private/utils.d.ts +4 -0
  140. package/declarations/serializer/-private/utils.d.ts.map +1 -0
  141. package/declarations/serializer/json-api.d.ts +496 -0
  142. package/declarations/serializer/json-api.d.ts.map +1 -0
  143. package/declarations/serializer/json.d.ts +1047 -0
  144. package/declarations/serializer/json.d.ts.map +1 -0
  145. package/declarations/serializer/rest.d.ts +554 -0
  146. package/declarations/serializer/rest.d.ts.map +1 -0
  147. package/declarations/serializer/transform.d.ts +6 -0
  148. package/declarations/serializer/transform.d.ts.map +1 -0
  149. package/declarations/serializer.d.ts +258 -0
  150. package/declarations/serializer.d.ts.map +1 -0
  151. package/dist/-private-DFfBszo5.js +1182 -0
  152. package/dist/-private-DFfBszo5.js.map +1 -0
  153. package/dist/adapter/-private.js +1 -0
  154. package/dist/adapter/-private.js.map +1 -0
  155. package/dist/adapter/error.js +254 -0
  156. package/dist/adapter/error.js.map +1 -0
  157. package/dist/adapter/json-api.js +129 -0
  158. package/dist/adapter/json-api.js.map +1 -0
  159. package/dist/adapter/rest.js +1262 -0
  160. package/dist/adapter/rest.js.map +1 -0
  161. package/dist/adapter.js +1284 -0
  162. package/dist/adapter.js.map +1 -0
  163. package/dist/compat/-private.js +1 -0
  164. package/dist/compat/-private.js.map +1 -0
  165. package/dist/compat/builders.js +292 -0
  166. package/dist/compat/builders.js.map +1 -0
  167. package/dist/compat/utils.js +225 -0
  168. package/dist/compat/utils.js.map +1 -0
  169. package/dist/compat.js +999 -0
  170. package/dist/compat.js.map +1 -0
  171. package/dist/errors-D74uk36r.js +2541 -0
  172. package/dist/errors-D74uk36r.js.map +1 -0
  173. package/dist/json-BCH3fil7.js +1349 -0
  174. package/dist/json-BCH3fil7.js.map +1 -0
  175. package/dist/model/-private.js +2 -0
  176. package/dist/model/-private.js.map +1 -0
  177. package/dist/model/migration-support.js +453 -0
  178. package/dist/model/migration-support.js.map +1 -0
  179. package/dist/model.js +736 -0
  180. package/dist/model.js.map +1 -0
  181. package/dist/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  182. package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +1 -0
  183. package/dist/schema-provider-CXFLTMjg.js +2228 -0
  184. package/dist/schema-provider-CXFLTMjg.js.map +1 -0
  185. package/dist/serialize-into-hash-BxfqWC8u.js +260 -0
  186. package/dist/serialize-into-hash-BxfqWC8u.js.map +1 -0
  187. package/dist/serializer/json-api.js +514 -0
  188. package/dist/serializer/json-api.js.map +1 -0
  189. package/dist/serializer/json.js +6 -0
  190. package/dist/serializer/json.js.map +1 -0
  191. package/dist/serializer/rest.js +1245 -0
  192. package/dist/serializer/rest.js.map +1 -0
  193. package/dist/serializer/transform.js +313 -0
  194. package/dist/serializer/transform.js.map +1 -0
  195. package/dist/serializer.js +252 -0
  196. package/dist/serializer.js.map +1 -0
  197. package/logos/NCC-1701-a-blue.svg +4 -0
  198. package/logos/NCC-1701-a-gold.svg +4 -0
  199. package/logos/NCC-1701-a-gold_100.svg +1 -0
  200. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  201. package/logos/NCC-1701-a.svg +4 -0
  202. package/logos/README.md +4 -0
  203. package/logos/docs-badge.svg +2 -0
  204. package/logos/ember-data-logo-dark.svg +12 -0
  205. package/logos/ember-data-logo-light.svg +12 -0
  206. package/logos/github-header.svg +444 -0
  207. package/logos/social1.png +0 -0
  208. package/logos/social2.png +0 -0
  209. package/logos/warp-drive-logo-dark.svg +4 -0
  210. package/logos/warp-drive-logo-gold.svg +4 -0
  211. package/package.json +72 -0
@@ -0,0 +1,495 @@
1
+ import type { Store } from '@warp-drive/core';
2
+ import type { Graph, ResourceEdge } from '@warp-drive/core/graph/-private';
3
+ import type { StableRecordIdentifier } from '@warp-drive/core/types/identifier';
4
+ import type { TypeFromInstance, TypeFromInstanceOrString } from '@warp-drive/core/types/record';
5
+ import type { Links, Meta, SingleResourceDocument, SingleResourceRelationship } from '@warp-drive/core/types/spec/json-api-raw';
6
+ import type { IsUnknown } from '../belongs-to.ts';
7
+ import type { MaybeBelongsToFields } from '../type-utils.ts';
8
+ /**
9
+ A `BelongsToReference` is a low-level API that allows access
10
+ and manipulation of a belongsTo relationship.
11
+
12
+ It is especially useful when you're dealing with `async` relationships
13
+ from `@ember-data/model` as it allows synchronous access to
14
+ the relationship data if loaded, as well as APIs for loading, reloading
15
+ the data or accessing available information without triggering a load.
16
+
17
+ It may also be useful when using `sync` relationships with `@ember-data/model`
18
+ that need to be loaded/reloaded with more precise timing than marking the
19
+ relationship as `async` and relying on autofetch would have allowed.
20
+
21
+ However,keep in mind that marking a relationship as `async: false` will introduce
22
+ bugs into your application if the data is not always guaranteed to be available
23
+ by the time the relationship is accessed. Ergo, it is recommended when using this
24
+ approach to utilize `links` for unloaded relationship state instead of identifiers.
25
+
26
+ Reference APIs are entangled with the relationship's underlying state,
27
+ thus any getters or cached properties that utilize these will properly
28
+ invalidate if the relationship state changes.
29
+
30
+ References are "stable", meaning that multiple calls to retrieve the reference
31
+ for a given relationship will always return the same HasManyReference.
32
+
33
+ @class BelongsToReference
34
+ @public
35
+ */
36
+ export default class BelongsToReference<T = unknown, K extends string = IsUnknown<T> extends true ? string : MaybeBelongsToFields<T>, Related = K extends keyof T ? Exclude<Awaited<T[K]>, null> : unknown> {
37
+ graph: Graph;
38
+ store: Store;
39
+ belongsToRelationship: ResourceEdge;
40
+ /**
41
+ * The field name on the parent record for this has-many relationship.
42
+ *
43
+ * @property key
44
+ * @type {String}
45
+ * @public
46
+ */
47
+ key: K;
48
+ /**
49
+ * The type of resource this relationship will contain.
50
+ *
51
+ * @property type
52
+ * @type {String}
53
+ * @public
54
+ */
55
+ type: TypeFromInstanceOrString<Related>;
56
+ ___token: object;
57
+ ___identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>;
58
+ ___relatedToken: object | null;
59
+ _ref: number;
60
+ constructor(store: Store, graph: Graph, parentIdentifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>, belongsToRelationship: ResourceEdge, key: K);
61
+ destroy(): void;
62
+ /**
63
+ * The identifier of the record that this reference refers to.
64
+ * `null` if no related record is known.
65
+ *
66
+ * @property identifier
67
+ * @type {StableRecordIdentifier | null}
68
+ * @public
69
+ */
70
+ get identifier(): StableRecordIdentifier<TypeFromInstanceOrString<Related>> | null;
71
+ /**
72
+ The `id` of the record that this reference refers to. Together, the
73
+ `type()` and `id()` methods form a composite key for the identity
74
+ map. This can be used to access the id of an async relationship
75
+ without triggering a fetch that would normally happen if you
76
+ attempted to use `record.relationship.id`.
77
+
78
+ Example
79
+
80
+ ```javascript
81
+ // models/blog.js
82
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
83
+
84
+ export default class BlogModel extends Model {
85
+ @belongsTo('user', { async: true, inverse: null }) user;
86
+ }
87
+
88
+ let blog = store.push({
89
+ data: {
90
+ type: 'blog',
91
+ id: 1,
92
+ relationships: {
93
+ user: {
94
+ data: { type: 'user', id: 1 }
95
+ }
96
+ }
97
+ }
98
+ });
99
+ let userRef = blog.belongsTo('user');
100
+
101
+ // get the identifier of the reference
102
+ if (userRef.remoteType() === "id") {
103
+ let id = userRef.id();
104
+ }
105
+ ```
106
+
107
+ @public
108
+ @return {String} The id of the record in this belongsTo relationship.
109
+ */
110
+ id(): string | null;
111
+ /**
112
+ The link Ember Data will use to fetch or reload this belongs-to
113
+ relationship. By default it uses only the "related" resource linkage.
114
+
115
+ Example
116
+
117
+ ```javascript
118
+ // models/blog.js
119
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
120
+ export default Model.extend({
121
+ user: belongsTo('user', { async: true, inverse: null })
122
+ });
123
+
124
+ let blog = store.push({
125
+ data: {
126
+ type: 'blog',
127
+ id: 1,
128
+ relationships: {
129
+ user: {
130
+ links: {
131
+ related: '/articles/1/author'
132
+ }
133
+ }
134
+ }
135
+ }
136
+ });
137
+ let userRef = blog.belongsTo('user');
138
+
139
+ // get the identifier of the reference
140
+ if (userRef.remoteType() === "link") {
141
+ let link = userRef.link();
142
+ }
143
+ ```
144
+
145
+ @public
146
+ @return {String} The link Ember Data will use to fetch or reload this belongs-to relationship.
147
+ */
148
+ link(): string | null;
149
+ /**
150
+ * any links that have been received for this relationship
151
+ *
152
+ * @public
153
+ * @return
154
+ */
155
+ links(): Links | null;
156
+ /**
157
+ The meta data for the belongs-to relationship.
158
+
159
+ Example
160
+
161
+ ```javascript
162
+ // models/blog.js
163
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
164
+ export default Model.extend({
165
+ user: belongsTo('user', { async: true, inverse: null })
166
+ });
167
+
168
+ let blog = store.push({
169
+ data: {
170
+ type: 'blog',
171
+ id: 1,
172
+ relationships: {
173
+ user: {
174
+ links: {
175
+ related: {
176
+ href: '/articles/1/author'
177
+ },
178
+ },
179
+ meta: {
180
+ lastUpdated: 1458014400000
181
+ }
182
+ }
183
+ }
184
+ }
185
+ });
186
+
187
+ let userRef = blog.belongsTo('user');
188
+
189
+ userRef.meta() // { lastUpdated: 1458014400000 }
190
+ ```
191
+
192
+ @public
193
+ @return {Object} The meta information for the belongs-to relationship.
194
+ */
195
+ meta(): Meta | null;
196
+ _resource(): SingleResourceRelationship<StableRecordIdentifier<TypeFromInstance<Related>>>;
197
+ /**
198
+ This returns a string that represents how the reference will be
199
+ looked up when it is loaded. If the relationship has a link it will
200
+ use the "link" otherwise it defaults to "id".
201
+
202
+ Example
203
+
204
+ ```js [app/models/post.js]
205
+ import Model, { hasMany } from '@ember-data/model';
206
+
207
+ export default class PostModel extends Model {
208
+ @hasMany('comment', { async: true, inverse: null }) comments;
209
+ }
210
+ ```
211
+
212
+ ```javascript
213
+ let post = store.push({
214
+ data: {
215
+ type: 'post',
216
+ id: 1,
217
+ relationships: {
218
+ comments: {
219
+ data: [{ type: 'comment', id: 1 }]
220
+ }
221
+ }
222
+ }
223
+ });
224
+
225
+ let commentsRef = post.hasMany('comments');
226
+
227
+ // get the identifier of the reference
228
+ if (commentsRef.remoteType() === "ids") {
229
+ let ids = commentsRef.ids();
230
+ } else if (commentsRef.remoteType() === "link") {
231
+ let link = commentsRef.link();
232
+ }
233
+ ```
234
+
235
+ @public
236
+ @return {String} The name of the remote type. This should either be `link` or `id`
237
+ */
238
+ remoteType(): 'link' | 'id';
239
+ /**
240
+ `push` can be used to update the data in the relationship and EmberData
241
+ will treat the new data as the canonical value of this relationship on
242
+ the backend. A value of `null` (e.g. `{ data: null }`) can be passed to
243
+ clear the relationship.
244
+
245
+ Example model
246
+
247
+ ```js [app/models/blog.js]
248
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
249
+
250
+ export default class BlogModel extends Model {
251
+ @belongsTo('user', { async: true, inverse: null }) user;
252
+ }
253
+ ```
254
+
255
+ Setup some initial state, note we haven't loaded the user yet:
256
+
257
+ ```js
258
+ const blog = store.push({
259
+ data: {
260
+ type: 'blog',
261
+ id: '1',
262
+ relationships: {
263
+ user: {
264
+ data: { type: 'user', id: '1' }
265
+ }
266
+ }
267
+ }
268
+ });
269
+
270
+ const userRef = blog.belongsTo('user');
271
+ userRef.id(); // '1'
272
+ ```
273
+
274
+ Update the state using `push`, note we can do this even without
275
+ having loaded the user yet by providing a resource-identifier.
276
+
277
+ Both full a resource and a resource-identifier are supported.
278
+
279
+ ```js
280
+ await userRef.push({
281
+ data: {
282
+ type: 'user',
283
+ id: '2',
284
+ }
285
+ });
286
+
287
+ userRef.id(); // '2'
288
+ ```
289
+
290
+ You may also pass in links and meta fore the relationship, and sideload
291
+ additional resources that might be required.
292
+
293
+ ```js
294
+ await userRef.push({
295
+ data: {
296
+ type: 'user',
297
+ id: '2',
298
+ },
299
+ links: {
300
+ related: '/articles/1/author'
301
+ },
302
+ meta: {
303
+ lastUpdated: Date.now()
304
+ },
305
+ included: [
306
+ {
307
+ type: 'user-preview',
308
+ id: '2',
309
+ attributes: {
310
+ username: '@runspired'
311
+ }
312
+ }
313
+ ]
314
+ });
315
+ ```
316
+
317
+ By default, the store will attempt to fetch the record if it is not loaded or its
318
+ resource data is not included in the call to `push` before resolving the returned
319
+ promise with the new state..
320
+
321
+ Alternatively, pass `true` as the second argument to avoid fetching unloaded records
322
+ and instead the promise will resolve with void without attempting to fetch. This is
323
+ particularly useful if you want to update the state of the relationship without
324
+ forcing the load of all of the associated record.
325
+
326
+ @public
327
+ @param {Object} doc a JSONAPI document object describing the new value of this relationship.
328
+ @param {Boolean} [skipFetch] if `true`, do not attempt to fetch unloaded records
329
+ @return {Promise<OpaqueRecordInstance | null | void>}
330
+ */
331
+ push(doc: SingleResourceDocument, skipFetch?: boolean): Promise<Related | null | void>;
332
+ /**
333
+ `value()` synchronously returns the current value of the belongs-to
334
+ relationship. Unlike `record.relationshipName`, calling
335
+ `value()` on a reference does not trigger a fetch if the async
336
+ relationship is not yet loaded. If the relationship is not loaded
337
+ it will always return `null`.
338
+
339
+ Example
340
+
341
+ ```javascript
342
+ // models/blog.js
343
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
344
+
345
+ export default class BlogModel extends Model {
346
+ @belongsTo('user', { async: true, inverse: null }) user;
347
+ }
348
+
349
+ let blog = store.push({
350
+ data: {
351
+ type: 'blog',
352
+ id: 1,
353
+ relationships: {
354
+ user: {
355
+ data: { type: 'user', id: 1 }
356
+ }
357
+ }
358
+ }
359
+ });
360
+ let userRef = blog.belongsTo('user');
361
+
362
+ userRef.value(); // null
363
+
364
+ // provide data for reference
365
+ userRef.push({
366
+ data: {
367
+ type: 'user',
368
+ id: 1,
369
+ attributes: {
370
+ username: "@user"
371
+ }
372
+ }
373
+ }).then(function(user) {
374
+ userRef.value(); // user
375
+ });
376
+ ```
377
+
378
+ @public
379
+ @return {Model} the record in this relationship
380
+ */
381
+ value(): Related | null;
382
+ /**
383
+ Loads a record in a belongs-to relationship if it is not already
384
+ loaded. If the relationship is already loaded this method does not
385
+ trigger a new load.
386
+
387
+ Example
388
+
389
+ ```javascript
390
+ // models/blog.js
391
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
392
+
393
+ export default class BlogModel extends Model {
394
+ @belongsTo('user', { async: true, inverse: null }) user;
395
+ }
396
+
397
+ let blog = store.push({
398
+ data: {
399
+ type: 'blog',
400
+ id: 1,
401
+ relationships: {
402
+ user: {
403
+ data: { type: 'user', id: 1 }
404
+ }
405
+ }
406
+ }
407
+ });
408
+ let userRef = blog.belongsTo('user');
409
+
410
+ userRef.value(); // null
411
+
412
+ userRef.load().then(function(user) {
413
+ userRef.value() === user
414
+ });
415
+ ```
416
+
417
+ You may also pass in an options object whose properties will be
418
+ fed forward. This enables you to pass `adapterOptions` into the
419
+ request given to the adapter via the reference.
420
+
421
+ Example
422
+
423
+ ```javascript
424
+ userRef.load({ adapterOptions: { isPrivate: true } }).then(function(user) {
425
+ userRef.value() === user;
426
+ });
427
+ ```
428
+ ```js [app/adapters/user.js]
429
+ import Adapter from '@ember-data/adapter';
430
+
431
+ export default class UserAdapter extends Adapter {
432
+ findRecord(store, type, id, snapshot) {
433
+ // In the adapter you will have access to adapterOptions.
434
+ let adapterOptions = snapshot.adapterOptions;
435
+ }
436
+ });
437
+ ```
438
+
439
+ @public
440
+ @param {Object} options the options to pass in.
441
+ @return {Promise} a promise that resolves with the record in this belongs-to relationship.
442
+ */
443
+ load(options?: Record<string, unknown>): Promise<Related | null>;
444
+ /**
445
+ Triggers a reload of the value in this relationship. If the
446
+ remoteType is `"link"` Ember Data will use the relationship link to
447
+ reload the relationship. Otherwise it will reload the record by its
448
+ id.
449
+
450
+ Example
451
+
452
+ ```javascript
453
+ // models/blog.js
454
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
455
+
456
+ export default class BlogModel extends Model {
457
+ @belongsTo('user', { async: true, inverse: null }) user;
458
+ }
459
+
460
+ let blog = store.push({
461
+ data: {
462
+ type: 'blog',
463
+ id: 1,
464
+ relationships: {
465
+ user: {
466
+ data: { type: 'user', id: 1 }
467
+ }
468
+ }
469
+ }
470
+ });
471
+ let userRef = blog.belongsTo('user');
472
+
473
+ userRef.reload().then(function(user) {
474
+ userRef.value() === user
475
+ });
476
+ ```
477
+
478
+ You may also pass in an options object whose properties will be
479
+ fed forward. This enables you to pass `adapterOptions` into the
480
+ request given to the adapter via the reference. A full example
481
+ can be found in the `load` method.
482
+
483
+ Example
484
+
485
+ ```javascript
486
+ userRef.reload({ adapterOptions: { isPrivate: true } })
487
+ ```
488
+
489
+ @public
490
+ @param {Object} options the options to pass in.
491
+ @return {Promise} a promise that resolves with the record in this belongs-to relationship after the reload has completed.
492
+ */
493
+ reload(options?: Record<string, unknown>): Promise<Related | null>;
494
+ }
495
+ //# sourceMappingURL=belongs-to.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"belongs-to.d.ts","sourceRoot":"","sources":["../../../../src/model/-private/references/belongs-to.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE3E,OAAO,KAAK,EAAkC,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAChH,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAChG,OAAO,KAAK,EAEV,KAAK,EACL,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