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

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,504 +1,507 @@
1
- import type { Store } from '@warp-drive/core';
2
- import type { CollectionEdge, Graph } from '@warp-drive/core/graph/-private';
3
- import type { RelatedCollection as ManyArray } from '@warp-drive/core/store/-private';
4
- import type { BaseFinderOptions } from '@warp-drive/core/types';
5
- import type { StableRecordIdentifier } from '@warp-drive/core/types/identifier';
6
- import type { TypeFromInstanceOrString } from '@warp-drive/core/types/record';
7
- import type { CollectionResourceDocument, CollectionResourceRelationship, ExistingResourceObject, LinkObject, Meta, PaginationLinks } from '@warp-drive/core/types/spec/json-api-raw';
8
- import type { IsUnknown } from '../belongs-to.ts';
9
- import type { MaybeHasManyFields } from '../type-utils.ts';
1
+ import type { Store } from "@warp-drive/core";
2
+ import type { CollectionEdge, Graph } from "@warp-drive/core/graph/-private";
3
+ import type { RelatedCollection as ManyArray } from "@warp-drive/core/store/-private";
4
+ import type { BaseFinderOptions } from "@warp-drive/core/types";
5
+ import type { StableRecordIdentifier } from "@warp-drive/core/types/identifier";
6
+ import type { TypeFromInstanceOrString } from "@warp-drive/core/types/record";
7
+ import type { CollectionResourceDocument, CollectionResourceRelationship, ExistingResourceObject, LinkObject, Meta, PaginationLinks } from "@warp-drive/core/types/spec/json-api-raw";
8
+ import type { IsUnknown } from "../belongs-to.js";
9
+ import type { MaybeHasManyFields } from "../type-utils.js";
10
10
  interface ResourceIdentifier {
11
- links?: {
12
- related?: string | LinkObject;
13
- };
14
- meta?: Meta;
11
+ links?: {
12
+ related?: string | LinkObject;
13
+ };
14
+ meta?: Meta;
15
15
  }
16
16
  type ArrayItemType<T> = T extends (infer U)[] ? U : never;
17
17
  /**
18
- A `HasManyReference` is a low-level API that allows access
19
- and manipulation of a hasMany relationship.
18
+ A `HasManyReference` is a low-level API that allows access
19
+ and manipulation of a hasMany relationship.
20
20
 
21
- It is especially useful when you're dealing with `async` relationships
22
- from `@ember-data/model` as it allows synchronous access to
23
- the relationship data if loaded, as well as APIs for loading, reloading
24
- the data or accessing available information without triggering a load.
21
+ It is especially useful when you're dealing with `async` relationships
22
+ from `@ember-data/model` as it allows synchronous access to
23
+ the relationship data if loaded, as well as APIs for loading, reloading
24
+ the data or accessing available information without triggering a load.
25
25
 
26
- It may also be useful when using `sync` relationships with `@ember-data/model`
27
- that need to be loaded/reloaded with more precise timing than marking the
28
- relationship as `async` and relying on autofetch would have allowed.
26
+ It may also be useful when using `sync` relationships with `@ember-data/model`
27
+ that need to be loaded/reloaded with more precise timing than marking the
28
+ relationship as `async` and relying on autofetch would have allowed.
29
29
 
30
- However,keep in mind that marking a relationship as `async: false` will introduce
31
- bugs into your application if the data is not always guaranteed to be available
32
- by the time the relationship is accessed. Ergo, it is recommended when using this
33
- approach to utilize `links` for unloaded relationship state instead of identifiers.
30
+ However,keep in mind that marking a relationship as `async: false` will introduce
31
+ bugs into your application if the data is not always guaranteed to be available
32
+ by the time the relationship is accessed. Ergo, it is recommended when using this
33
+ approach to utilize `links` for unloaded relationship state instead of identifiers.
34
34
 
35
- Reference APIs are entangled with the relationship's underlying state,
36
- thus any getters or cached properties that utilize these will properly
37
- invalidate if the relationship state changes.
35
+ Reference APIs are entangled with the relationship's underlying state,
36
+ thus any getters or cached properties that utilize these will properly
37
+ invalidate if the relationship state changes.
38
38
 
39
- References are "stable", meaning that multiple calls to retrieve the reference
40
- for a given relationship will always return the same HasManyReference.
39
+ References are "stable", meaning that multiple calls to retrieve the reference
40
+ for a given relationship will always return the same HasManyReference.
41
41
 
42
- @class HasManyReference
43
- @public
44
- */
45
- export default class HasManyReference<T = unknown, K extends string = IsUnknown<T> extends true ? string : MaybeHasManyFields<T>, Related = K extends keyof T ? ArrayItemType<Awaited<T[K]>> : unknown> {
46
- graph: Graph;
47
- store: Store;
48
- hasManyRelationship: CollectionEdge;
49
- /**
50
- * The field name on the parent record for this has-many relationship.
51
- *
52
- * @property key
53
- * @type {String}
54
- * @public
55
- */
56
- key: K;
57
- /**
58
- * The type of resource this relationship will contain.
59
- *
60
- * @property type
61
- * @type {String}
62
- * @public
63
- */
64
- type: TypeFromInstanceOrString<Related>;
65
- ___token: object;
66
- ___identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>;
67
- ___relatedTokenMap: Map<StableRecordIdentifier, object>;
68
- _ref: number;
69
- constructor(store: Store, graph: Graph, parentIdentifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>, hasManyRelationship: CollectionEdge, key: K);
70
- /**
71
- * This method should never be called by user code.
72
- *
73
- * @internal
74
- */
75
- destroy(): void;
76
- /**
77
- * An array of identifiers for the records that this reference refers to.
78
- *
79
- * @property identifiers
80
- * @type {StableRecordIdentifier[]}
81
- * @public
82
- */
83
- get identifiers(): StableRecordIdentifier<TypeFromInstanceOrString<Related>>[];
84
- _resource(): CollectionResourceRelationship;
85
- /**
86
- This returns a string that represents how the reference will be
87
- looked up when it is loaded. If the relationship has a link it will
88
- use the "link" otherwise it defaults to "id".
89
-
90
- Example
91
-
92
- ```js [app/models/post.js]
93
- import { Model, hasMany } from '@warp-drive/legacy/model';
94
-
95
- export default class PostModel extends Model {
96
- @hasMany('comment', { async: true, inverse: null }) comments;
97
- }
98
- ```
99
-
100
- ```javascript
101
- let post = store.push({
102
- data: {
103
- type: 'post',
104
- id: 1,
105
- relationships: {
106
- comments: {
107
- data: [{ type: 'comment', id: 1 }]
108
- }
109
- }
110
- }
111
- });
112
-
113
- let commentsRef = post.hasMany('comments');
114
-
115
- // get the identifier of the reference
116
- if (commentsRef.remoteType() === "ids") {
117
- let ids = commentsRef.ids();
118
- } else if (commentsRef.remoteType() === "link") {
119
- let link = commentsRef.link();
120
- }
121
- ```
122
-
123
- @public
124
- @return {String} The name of the remote type. This should either be `link` or `ids`
125
- */
126
- remoteType(): 'link' | 'ids';
127
- /**
128
- `ids()` returns an array of the record IDs in this relationship.
129
-
130
- Example
131
-
132
- ```js [app/models/post.js]
133
- import { Model, hasMany } from '@warp-drive/legacy/model';
134
-
135
- export default class PostModel extends Model {
136
- @hasMany('comment', { async: true, inverse: null }) comments;
137
- }
138
- ```
139
-
140
- ```javascript
141
- let post = store.push({
142
- data: {
143
- type: 'post',
144
- id: 1,
145
- relationships: {
146
- comments: {
147
- data: [{ type: 'comment', id: 1 }]
148
- }
149
- }
150
- }
151
- });
152
-
153
- let commentsRef = post.hasMany('comments');
154
-
155
- commentsRef.ids(); // ['1']
156
- ```
157
-
158
- @public
159
- @return {Array} The ids in this has-many relationship
160
- */
161
- ids(): Array<string | null>;
162
- /**
163
- The link Ember Data will use to fetch or reload this belongs-to
164
- relationship. By default it uses only the "related" resource linkage.
165
-
166
- Example
167
-
168
- ```javascript
169
- // models/blog.js
170
- import { Model, belongsTo } from '@warp-drive/legacy/model';
171
- export default Model.extend({
172
- user: belongsTo('user', { async: true, inverse: null })
173
- });
174
-
175
- let blog = store.push({
176
- data: {
177
- type: 'blog',
178
- id: 1,
179
- relationships: {
180
- user: {
181
- links: {
182
- related: '/articles/1/author'
183
- }
184
- }
185
- }
186
- }
187
- });
188
- let userRef = blog.belongsTo('user');
189
-
190
- // get the identifier of the reference
191
- if (userRef.remoteType() === "link") {
192
- let link = userRef.link();
193
- }
194
- ```
195
-
196
- @public
197
- @return {String} The link Ember Data will use to fetch or reload this belongs-to relationship.
198
- */
199
- link(): string | null;
200
- /**
201
- * any links that have been received for this relationship
202
- *
203
- * @public
204
- * @return
205
- */
206
- links(): PaginationLinks | null;
207
- /**
208
- The meta data for the has-many relationship.
209
-
210
- Example
211
-
212
- ```javascript
213
- // models/blog.js
214
- import { Model, hasMany } from '@warp-drive/legacy/model';
215
- export default Model.extend({
216
- users: hasMany('user', { async: true, inverse: null })
217
- });
218
-
219
- let blog = store.push({
220
- data: {
221
- type: 'blog',
222
- id: 1,
223
- relationships: {
224
- users: {
225
- links: {
226
- related: {
227
- href: '/articles/1/authors'
228
- },
229
- },
230
- meta: {
231
- lastUpdated: 1458014400000
232
- }
233
- }
234
- }
235
- }
236
- });
237
-
238
- let usersRef = blog.hasMany('user');
239
-
240
- usersRef.meta() // { lastUpdated: 1458014400000 }
241
- ```
242
-
243
- @public
244
- @return {Object|null} The meta information for the belongs-to relationship.
245
- */
246
- meta(): Meta | null;
247
- /**
248
- `push` can be used to update the data in the relationship and EmberData
249
- will treat the new data as the canonical value of this relationship on
250
- the backend. An empty array will signify the canonical value should be
251
- empty.
252
-
253
- Example model
254
-
255
- ```js [app/models/post.js]
256
- import { Model, hasMany } from '@warp-drive/legacy/model';
257
-
258
- export default class PostModel extends Model {
259
- @hasMany('comment', { async: true, inverse: null }) comments;
260
- }
261
- ```
262
-
263
- Setup some initial state, note we haven't loaded the comments yet:
264
-
265
- ```js
266
- const post = store.push({
267
- data: {
268
- type: 'post',
269
- id: '1',
270
- relationships: {
271
- comments: {
272
- data: [{ type: 'comment', id: '1' }]
273
- }
274
- }
275
- }
276
- });
277
-
278
- const commentsRef = post.hasMany('comments');
279
- commentsRef.ids(); // ['1']
280
- ```
281
-
282
- Update the state using `push`, note we can do this even without
283
- having loaded these comments yet by providing resource identifiers.
284
-
285
- Both full resources and resource identifiers are supported.
286
-
287
- ```js
288
- await commentsRef.push({
289
- data: [
290
- { type: 'comment', id: '2' },
291
- { type: 'comment', id: '3' },
292
- ]
293
- });
294
-
295
- commentsRef.ids(); // ['2', '3']
296
- ```
297
-
298
- For convenience, you can also pass in an array of resources or resource identifiers
299
- without wrapping them in the `data` property:
300
-
301
- ```js
302
- await commentsRef.push([
303
- { type: 'comment', id: '4' },
304
- { type: 'comment', id: '5' },
305
- ]);
306
-
307
- commentsRef.ids(); // ['4', '5']
308
- ```
309
-
310
- When using the `data` property, you may also include other resource data via included,
311
- as well as provide new links and meta to the relationship.
312
-
313
- ```js
314
- await commentsRef.push({
315
- links: {
316
- related: '/posts/1/comments'
317
- },
318
- meta: {
319
- total: 2
320
- },
321
- data: [
322
- { type: 'comment', id: '4' },
323
- { type: 'comment', id: '5' },
324
- ],
325
- included: [
326
- { type: 'other-thing', id: '1', attributes: { foo: 'bar' },
327
- ]
328
- });
329
- ```
330
-
331
- By default, the store will attempt to fetch any unloaded records before resolving
332
- the returned promise with the ManyArray.
333
-
334
- Alternatively, pass `true` as the second argument to avoid fetching unloaded records
335
- and instead the promise will resolve with void without attempting to fetch. This is
336
- particularly useful if you want to update the state of the relationship without
337
- forcing the load of all of the associated records.
338
-
339
- @public
340
- @param {Array|Object} doc a JSONAPI document object describing the new value of this relationship.
341
- @param {Boolean} [skipFetch] if `true`, do not attempt to fetch unloaded records
342
- @return {Promise<ManyArray | void>}
343
- */
344
- push(doc: ExistingResourceObject[] | CollectionResourceDocument, skipFetch?: boolean): Promise<ManyArray<Related> | void>;
345
- _isLoaded(): boolean | undefined;
346
- /**
347
- `value()` synchronously returns the current value of the has-many
348
- relationship. Unlike `record.relationshipName`, calling
349
- `value()` on a reference does not trigger a fetch if the async
350
- relationship is not yet loaded. If the relationship is not loaded
351
- it will always return `null`.
352
-
353
- Example
354
-
355
- ```js [app/models/post.js]
356
- import { Model, hasMany } from '@warp-drive/legacy/model';
357
-
358
- export default class PostModel extends Model {
359
- @hasMany('comment', { async: true, inverse: null }) comments;
360
- }
361
- ```
362
-
363
- ```javascript
364
- let post = store.push({
365
- data: {
366
- type: 'post',
367
- id: 1,
368
- relationships: {
369
- comments: {
370
- data: [{ type: 'comment', id: 1 }]
371
- }
372
- }
373
- }
374
- });
375
-
376
- let commentsRef = post.hasMany('comments');
377
-
378
- post.comments.then(function(comments) {
379
- commentsRef.value() === comments
380
- })
381
- ```
382
-
383
- @public
384
- @return {ManyArray}
385
- */
386
- value(): ManyArray<Related> | null;
387
- /**
388
- Loads the relationship if it is not already loaded. If the
389
- relationship is already loaded this method does not trigger a new
390
- load. This causes a request to the specified
391
- relationship link or reloads all items currently in the relationship.
392
-
393
- Example
394
-
395
- ```js [app/models/post.js]
396
- import { Model, hasMany } from '@warp-drive/legacy/model';
397
-
398
- export default class PostModel extends Model {
399
- @hasMany('comment', { async: true, inverse: null }) comments;
400
- }
401
- ```
402
-
403
- ```javascript
404
- let post = store.push({
405
- data: {
406
- type: 'post',
407
- id: 1,
408
- relationships: {
409
- comments: {
410
- data: [{ type: 'comment', id: 1 }]
411
- }
412
- }
413
- }
414
- });
415
-
416
- let commentsRef = post.hasMany('comments');
417
-
418
- commentsRef.load().then(function(comments) {
419
- //...
420
- });
421
- ```
422
-
423
- You may also pass in an options object whose properties will be
424
- fed forward. This enables you to pass `adapterOptions` into the
425
- request given to the adapter via the reference.
426
-
427
- Example
428
-
429
- ```javascript
430
- commentsRef.load({ adapterOptions: { isPrivate: true } })
431
- .then(function(comments) {
432
- //...
433
- });
434
- ```
435
-
436
- ```js [app/adapters/comment.js]
437
- export default ApplicationAdapter.extend({
438
- findMany(store, type, id, snapshots) {
439
- // In the adapter you will have access to adapterOptions.
440
- let adapterOptions = snapshots[0].adapterOptions;
441
- }
442
- });
443
- ```
444
-
445
- @public
446
- @param {Object} options the options to pass in.
447
- @return {Promise} a promise that resolves with the ManyArray in
448
- this has-many relationship.
449
- */
450
- load(options?: BaseFinderOptions): Promise<ManyArray<Related>>;
451
- /**
452
- Reloads this has-many relationship. This causes a request to the specified
453
- relationship link or reloads all items currently in the relationship.
454
-
455
- Example
456
-
457
- ```js [app/models/post.js]
458
- import { Model, hasMany } from '@warp-drive/legacy/model';
459
-
460
- export default class PostModel extends Model {
461
- @hasMany('comment', { async: true, inverse: null }) comments;
462
- }
463
- ```
464
-
465
- ```javascript
466
- let post = store.push({
467
- data: {
468
- type: 'post',
469
- id: 1,
470
- relationships: {
471
- comments: {
472
- data: [{ type: 'comment', id: 1 }]
473
- }
474
- }
475
- }
476
- });
477
-
478
- let commentsRef = post.hasMany('comments');
479
-
480
- commentsRef.reload().then(function(comments) {
481
- //...
482
- });
483
- ```
484
-
485
- You may also pass in an options object whose properties will be
486
- fed forward. This enables you to pass `adapterOptions` into the
487
- request given to the adapter via the reference. A full example
488
- can be found in the `load` method.
489
-
490
- Example
491
-
492
- ```javascript
493
- commentsRef.reload({ adapterOptions: { isPrivate: true } })
494
- ```
495
-
496
- @public
497
- @param {Object} options the options to pass in.
498
- @return {Promise} a promise that resolves with the ManyArray in this has-many relationship.
499
- */
500
- reload(options?: BaseFinderOptions): Promise<ManyArray<Related>>;
42
+ @class HasManyReference
43
+ @public
44
+ */
45
+ export default class HasManyReference<
46
+ T = unknown,
47
+ K extends string = IsUnknown<T> extends true ? string : MaybeHasManyFields<T>,
48
+ Related = K extends keyof T ? ArrayItemType<Awaited<T[K]>> : unknown
49
+ > {
50
+ graph: Graph;
51
+ store: Store;
52
+ hasManyRelationship: CollectionEdge;
53
+ /**
54
+ * The field name on the parent record for this has-many relationship.
55
+ *
56
+ * @property key
57
+ * @type {String}
58
+ * @public
59
+ */
60
+ key: K;
61
+ /**
62
+ * The type of resource this relationship will contain.
63
+ *
64
+ * @property type
65
+ * @type {String}
66
+ * @public
67
+ */
68
+ type: TypeFromInstanceOrString<Related>;
69
+ // unsubscribe tokens given to us by the notification manager
70
+ ___token: object;
71
+ ___identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>;
72
+ ___relatedTokenMap: Map<StableRecordIdentifier, object>;
73
+ _ref: number;
74
+ constructor(store: Store, graph: Graph, parentIdentifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>, hasManyRelationship: CollectionEdge, key: K);
75
+ /**
76
+ * This method should never be called by user code.
77
+ *
78
+ * @internal
79
+ */
80
+ destroy(): void;
81
+ /**
82
+ * An array of identifiers for the records that this reference refers to.
83
+ *
84
+ * @property identifiers
85
+ * @type {StableRecordIdentifier[]}
86
+ * @public
87
+ */
88
+ get identifiers(): StableRecordIdentifier<TypeFromInstanceOrString<Related>>[];
89
+ _resource(): CollectionResourceRelationship;
90
+ /**
91
+ This returns a string that represents how the reference will be
92
+ looked up when it is loaded. If the relationship has a link it will
93
+ use the "link" otherwise it defaults to "id".
94
+
95
+ Example
96
+
97
+ ```js [app/models/post.js]
98
+ import { Model, hasMany } from '@warp-drive/legacy/model';
99
+
100
+ export default class PostModel extends Model {
101
+ @hasMany('comment', { async: true, inverse: null }) comments;
102
+ }
103
+ ```
104
+
105
+ ```javascript
106
+ let post = store.push({
107
+ data: {
108
+ type: 'post',
109
+ id: 1,
110
+ relationships: {
111
+ comments: {
112
+ data: [{ type: 'comment', id: 1 }]
113
+ }
114
+ }
115
+ }
116
+ });
117
+
118
+ let commentsRef = post.hasMany('comments');
119
+
120
+ // get the identifier of the reference
121
+ if (commentsRef.remoteType() === "ids") {
122
+ let ids = commentsRef.ids();
123
+ } else if (commentsRef.remoteType() === "link") {
124
+ let link = commentsRef.link();
125
+ }
126
+ ```
127
+
128
+ @public
129
+ @return {String} The name of the remote type. This should either be `link` or `ids`
130
+ */
131
+ remoteType(): "link" | "ids";
132
+ /**
133
+ `ids()` returns an array of the record IDs in this relationship.
134
+
135
+ Example
136
+
137
+ ```js [app/models/post.js]
138
+ import { Model, hasMany } from '@warp-drive/legacy/model';
139
+
140
+ export default class PostModel extends Model {
141
+ @hasMany('comment', { async: true, inverse: null }) comments;
142
+ }
143
+ ```
144
+
145
+ ```javascript
146
+ let post = store.push({
147
+ data: {
148
+ type: 'post',
149
+ id: 1,
150
+ relationships: {
151
+ comments: {
152
+ data: [{ type: 'comment', id: 1 }]
153
+ }
154
+ }
155
+ }
156
+ });
157
+
158
+ let commentsRef = post.hasMany('comments');
159
+
160
+ commentsRef.ids(); // ['1']
161
+ ```
162
+
163
+ @public
164
+ @return {Array} The ids in this has-many relationship
165
+ */
166
+ ids(): Array<string | null>;
167
+ /**
168
+ The link Ember Data will use to fetch or reload this belongs-to
169
+ relationship. By default it uses only the "related" resource linkage.
170
+
171
+ Example
172
+
173
+ ```javascript
174
+ // models/blog.js
175
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
176
+ export default Model.extend({
177
+ user: belongsTo('user', { async: true, inverse: null })
178
+ });
179
+
180
+ let blog = store.push({
181
+ data: {
182
+ type: 'blog',
183
+ id: 1,
184
+ relationships: {
185
+ user: {
186
+ links: {
187
+ related: '/articles/1/author'
188
+ }
189
+ }
190
+ }
191
+ }
192
+ });
193
+ let userRef = blog.belongsTo('user');
194
+
195
+ // get the identifier of the reference
196
+ if (userRef.remoteType() === "link") {
197
+ let link = userRef.link();
198
+ }
199
+ ```
200
+
201
+ @public
202
+ @return {String} The link Ember Data will use to fetch or reload this belongs-to relationship.
203
+ */
204
+ link(): string | null;
205
+ /**
206
+ * any links that have been received for this relationship
207
+ *
208
+ * @public
209
+ * @return
210
+ */
211
+ links(): PaginationLinks | null;
212
+ /**
213
+ The meta data for the has-many relationship.
214
+
215
+ Example
216
+
217
+ ```javascript
218
+ // models/blog.js
219
+ import { Model, hasMany } from '@warp-drive/legacy/model';
220
+ export default Model.extend({
221
+ users: hasMany('user', { async: true, inverse: null })
222
+ });
223
+
224
+ let blog = store.push({
225
+ data: {
226
+ type: 'blog',
227
+ id: 1,
228
+ relationships: {
229
+ users: {
230
+ links: {
231
+ related: {
232
+ href: '/articles/1/authors'
233
+ },
234
+ },
235
+ meta: {
236
+ lastUpdated: 1458014400000
237
+ }
238
+ }
239
+ }
240
+ }
241
+ });
242
+
243
+ let usersRef = blog.hasMany('user');
244
+
245
+ usersRef.meta() // { lastUpdated: 1458014400000 }
246
+ ```
247
+
248
+ @public
249
+ @return {Object|null} The meta information for the belongs-to relationship.
250
+ */
251
+ meta(): Meta | null;
252
+ /**
253
+ `push` can be used to update the data in the relationship and EmberData
254
+ will treat the new data as the canonical value of this relationship on
255
+ the backend. An empty array will signify the canonical value should be
256
+ empty.
257
+
258
+ Example model
259
+
260
+ ```js [app/models/post.js]
261
+ import { Model, hasMany } from '@warp-drive/legacy/model';
262
+
263
+ export default class PostModel extends Model {
264
+ @hasMany('comment', { async: true, inverse: null }) comments;
265
+ }
266
+ ```
267
+
268
+ Setup some initial state, note we haven't loaded the comments yet:
269
+
270
+ ```js
271
+ const post = store.push({
272
+ data: {
273
+ type: 'post',
274
+ id: '1',
275
+ relationships: {
276
+ comments: {
277
+ data: [{ type: 'comment', id: '1' }]
278
+ }
279
+ }
280
+ }
281
+ });
282
+
283
+ const commentsRef = post.hasMany('comments');
284
+ commentsRef.ids(); // ['1']
285
+ ```
286
+
287
+ Update the state using `push`, note we can do this even without
288
+ having loaded these comments yet by providing resource identifiers.
289
+
290
+ Both full resources and resource identifiers are supported.
291
+
292
+ ```js
293
+ await commentsRef.push({
294
+ data: [
295
+ { type: 'comment', id: '2' },
296
+ { type: 'comment', id: '3' },
297
+ ]
298
+ });
299
+
300
+ commentsRef.ids(); // ['2', '3']
301
+ ```
302
+
303
+ For convenience, you can also pass in an array of resources or resource identifiers
304
+ without wrapping them in the `data` property:
305
+
306
+ ```js
307
+ await commentsRef.push([
308
+ { type: 'comment', id: '4' },
309
+ { type: 'comment', id: '5' },
310
+ ]);
311
+
312
+ commentsRef.ids(); // ['4', '5']
313
+ ```
314
+
315
+ When using the `data` property, you may also include other resource data via included,
316
+ as well as provide new links and meta to the relationship.
317
+
318
+ ```js
319
+ await commentsRef.push({
320
+ links: {
321
+ related: '/posts/1/comments'
322
+ },
323
+ meta: {
324
+ total: 2
325
+ },
326
+ data: [
327
+ { type: 'comment', id: '4' },
328
+ { type: 'comment', id: '5' },
329
+ ],
330
+ included: [
331
+ { type: 'other-thing', id: '1', attributes: { foo: 'bar' },
332
+ ]
333
+ });
334
+ ```
335
+
336
+ By default, the store will attempt to fetch any unloaded records before resolving
337
+ the returned promise with the ManyArray.
338
+
339
+ Alternatively, pass `true` as the second argument to avoid fetching unloaded records
340
+ and instead the promise will resolve with void without attempting to fetch. This is
341
+ particularly useful if you want to update the state of the relationship without
342
+ forcing the load of all of the associated records.
343
+
344
+ @public
345
+ @param {Array|Object} doc a JSONAPI document object describing the new value of this relationship.
346
+ @param {Boolean} [skipFetch] if `true`, do not attempt to fetch unloaded records
347
+ @return {Promise<ManyArray | void>}
348
+ */
349
+ push(doc: ExistingResourceObject[] | CollectionResourceDocument, skipFetch?: boolean): Promise<ManyArray<Related> | void>;
350
+ _isLoaded(): boolean;
351
+ /**
352
+ `value()` synchronously returns the current value of the has-many
353
+ relationship. Unlike `record.relationshipName`, calling
354
+ `value()` on a reference does not trigger a fetch if the async
355
+ relationship is not yet loaded. If the relationship is not loaded
356
+ it will always return `null`.
357
+
358
+ Example
359
+
360
+ ```js [app/models/post.js]
361
+ import { Model, hasMany } from '@warp-drive/legacy/model';
362
+
363
+ export default class PostModel extends Model {
364
+ @hasMany('comment', { async: true, inverse: null }) comments;
365
+ }
366
+ ```
367
+
368
+ ```javascript
369
+ let post = store.push({
370
+ data: {
371
+ type: 'post',
372
+ id: 1,
373
+ relationships: {
374
+ comments: {
375
+ data: [{ type: 'comment', id: 1 }]
376
+ }
377
+ }
378
+ }
379
+ });
380
+
381
+ let commentsRef = post.hasMany('comments');
382
+
383
+ post.comments.then(function(comments) {
384
+ commentsRef.value() === comments
385
+ })
386
+ ```
387
+
388
+ @public
389
+ @return {ManyArray}
390
+ */
391
+ value(): ManyArray<Related> | null;
392
+ /**
393
+ Loads the relationship if it is not already loaded. If the
394
+ relationship is already loaded this method does not trigger a new
395
+ load. This causes a request to the specified
396
+ relationship link or reloads all items currently in the relationship.
397
+
398
+ Example
399
+
400
+ ```js [app/models/post.js]
401
+ import { Model, hasMany } from '@warp-drive/legacy/model';
402
+
403
+ export default class PostModel extends Model {
404
+ @hasMany('comment', { async: true, inverse: null }) comments;
405
+ }
406
+ ```
407
+
408
+ ```javascript
409
+ let post = store.push({
410
+ data: {
411
+ type: 'post',
412
+ id: 1,
413
+ relationships: {
414
+ comments: {
415
+ data: [{ type: 'comment', id: 1 }]
416
+ }
417
+ }
418
+ }
419
+ });
420
+
421
+ let commentsRef = post.hasMany('comments');
422
+
423
+ commentsRef.load().then(function(comments) {
424
+ //...
425
+ });
426
+ ```
427
+
428
+ You may also pass in an options object whose properties will be
429
+ fed forward. This enables you to pass `adapterOptions` into the
430
+ request given to the adapter via the reference.
431
+
432
+ Example
433
+
434
+ ```javascript
435
+ commentsRef.load({ adapterOptions: { isPrivate: true } })
436
+ .then(function(comments) {
437
+ //...
438
+ });
439
+ ```
440
+
441
+ ```js [app/adapters/comment.js]
442
+ export default ApplicationAdapter.extend({
443
+ findMany(store, type, id, snapshots) {
444
+ // In the adapter you will have access to adapterOptions.
445
+ let adapterOptions = snapshots[0].adapterOptions;
446
+ }
447
+ });
448
+ ```
449
+
450
+ @public
451
+ @param {Object} options the options to pass in.
452
+ @return {Promise} a promise that resolves with the ManyArray in
453
+ this has-many relationship.
454
+ */
455
+ load(options?: BaseFinderOptions): Promise<ManyArray<Related>>;
456
+ /**
457
+ Reloads this has-many relationship. This causes a request to the specified
458
+ relationship link or reloads all items currently in the relationship.
459
+
460
+ Example
461
+
462
+ ```js [app/models/post.js]
463
+ import { Model, hasMany } from '@warp-drive/legacy/model';
464
+
465
+ export default class PostModel extends Model {
466
+ @hasMany('comment', { async: true, inverse: null }) comments;
467
+ }
468
+ ```
469
+
470
+ ```javascript
471
+ let post = store.push({
472
+ data: {
473
+ type: 'post',
474
+ id: 1,
475
+ relationships: {
476
+ comments: {
477
+ data: [{ type: 'comment', id: 1 }]
478
+ }
479
+ }
480
+ }
481
+ });
482
+
483
+ let commentsRef = post.hasMany('comments');
484
+
485
+ commentsRef.reload().then(function(comments) {
486
+ //...
487
+ });
488
+ ```
489
+
490
+ You may also pass in an options object whose properties will be
491
+ fed forward. This enables you to pass `adapterOptions` into the
492
+ request given to the adapter via the reference. A full example
493
+ can be found in the `load` method.
494
+
495
+ Example
496
+
497
+ ```javascript
498
+ commentsRef.reload({ adapterOptions: { isPrivate: true } })
499
+ ```
500
+
501
+ @public
502
+ @param {Object} options the options to pass in.
503
+ @return {Promise} a promise that resolves with the ManyArray in this has-many relationship.
504
+ */
505
+ reload(options?: BaseFinderOptions): Promise<ManyArray<Related>>;
501
506
  }
502
507
  export declare function isMaybeResource(object: ExistingResourceObject | ResourceIdentifier): object is ExistingResourceObject;
503
- export {};
504
- //# sourceMappingURL=has-many.d.ts.map