@warp-drive/legacy 5.6.0-alpha.15 → 5.6.0-alpha.18

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