@ember-data/model 5.4.0-alpha.4 → 5.4.0-alpha.43
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.
- package/addon/-private.js +2 -2
- package/addon/has-many-B3FpdTTp.js +655 -0
- package/addon/has-many-B3FpdTTp.js.map +1 -0
- package/addon/{hooks-62d36619.js → hooks-CHMQx9Ce.js} +34 -15
- package/addon/hooks-CHMQx9Ce.js.map +1 -0
- package/addon/hooks.js +1 -1
- package/addon/index.js +3 -3
- package/addon/index.js.map +1 -1
- package/addon/migration-support.js +118 -0
- package/addon/migration-support.js.map +1 -0
- package/addon/{model-e642556d.js → model-DvL_NWQw.js} +2035 -1881
- package/addon/model-DvL_NWQw.js.map +1 -0
- package/addon/util-CSYkrwfb.js +35 -0
- package/addon/util-CSYkrwfb.js.map +1 -0
- package/addon-main.js +1 -0
- package/package.json +88 -37
- package/unstable-preview-types/-private/attr.d.ts +174 -0
- package/unstable-preview-types/-private/attr.d.ts.map +1 -0
- package/unstable-preview-types/-private/attr.type-test.d.ts +4 -0
- package/unstable-preview-types/-private/attr.type-test.d.ts.map +1 -0
- package/unstable-preview-types/-private/belongs-to.d.ts +180 -0
- package/unstable-preview-types/-private/belongs-to.d.ts.map +1 -0
- package/unstable-preview-types/-private/belongs-to.type-test.d.ts +4 -0
- package/unstable-preview-types/-private/belongs-to.type-test.d.ts.map +1 -0
- package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +8 -0
- package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
- package/unstable-preview-types/-private/errors.d.ts +308 -0
- package/unstable-preview-types/-private/errors.d.ts.map +1 -0
- package/unstable-preview-types/-private/has-many.d.ts +169 -0
- package/unstable-preview-types/-private/has-many.d.ts.map +1 -0
- package/unstable-preview-types/-private/has-many.type-test.d.ts +4 -0
- package/unstable-preview-types/-private/has-many.type-test.d.ts.map +1 -0
- package/unstable-preview-types/-private/hooks.d.ts +13 -0
- package/unstable-preview-types/-private/hooks.d.ts.map +1 -0
- package/unstable-preview-types/-private/legacy-relationships-support.d.ts +64 -0
- package/unstable-preview-types/-private/legacy-relationships-support.d.ts.map +1 -0
- package/unstable-preview-types/-private/many-array.d.ts +198 -0
- package/unstable-preview-types/-private/many-array.d.ts.map +1 -0
- package/unstable-preview-types/-private/model-for-mixin.d.ts +6 -0
- package/unstable-preview-types/-private/model-for-mixin.d.ts.map +1 -0
- package/unstable-preview-types/-private/model-methods.d.ts +36 -0
- package/unstable-preview-types/-private/model-methods.d.ts.map +1 -0
- package/unstable-preview-types/-private/model.d.ts +108 -0
- package/unstable-preview-types/-private/model.type-test.d.ts +4 -0
- package/unstable-preview-types/-private/model.type-test.d.ts.map +1 -0
- package/unstable-preview-types/-private/notify-changes.d.ts +8 -0
- package/unstable-preview-types/-private/notify-changes.d.ts.map +1 -0
- package/unstable-preview-types/-private/promise-belongs-to.d.ts +47 -0
- package/unstable-preview-types/-private/promise-belongs-to.d.ts.map +1 -0
- package/unstable-preview-types/-private/promise-many-array.d.ts +129 -0
- package/unstable-preview-types/-private/promise-many-array.d.ts.map +1 -0
- package/unstable-preview-types/-private/promise-proxy-base.d.ts +35 -0
- package/unstable-preview-types/-private/record-state.d.ts +91 -0
- package/unstable-preview-types/-private/record-state.d.ts.map +1 -0
- package/unstable-preview-types/-private/references/belongs-to.d.ts +503 -0
- package/unstable-preview-types/-private/references/belongs-to.d.ts.map +1 -0
- package/unstable-preview-types/-private/references/has-many.d.ts +515 -0
- package/unstable-preview-types/-private/references/has-many.d.ts.map +1 -0
- package/unstable-preview-types/-private/schema-provider.d.ts +27 -0
- package/unstable-preview-types/-private/schema-provider.d.ts.map +1 -0
- package/unstable-preview-types/-private/util.d.ts +11 -0
- package/unstable-preview-types/-private/util.d.ts.map +1 -0
- package/unstable-preview-types/-private.d.ts +12 -0
- package/unstable-preview-types/-private.d.ts.map +1 -0
- package/unstable-preview-types/hooks.d.ts +5 -0
- package/unstable-preview-types/hooks.d.ts.map +1 -0
- package/unstable-preview-types/index.d.ts +75 -0
- package/unstable-preview-types/index.d.ts.map +1 -0
- package/unstable-preview-types/migration-support.d.ts +11 -0
- package/unstable-preview-types/migration-support.d.ts.map +1 -0
- package/addon/has-many-d1ca9997.js +0 -507
- package/addon/has-many-d1ca9997.js.map +0 -1
- package/addon/hooks-62d36619.js.map +0 -1
- package/addon/model-e642556d.js.map +0 -1
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
declare module '@ember-data/model/-private/references/has-many' {
|
|
2
|
+
import type { CollectionEdge } from '@ember-data/graph/-private/edges/collection';
|
|
3
|
+
import type { Graph } from '@ember-data/graph/-private/graph';
|
|
4
|
+
import type Store from '@ember-data/store';
|
|
5
|
+
import type { BaseFinderOptions } from '@ember-data/store/-types/q/store';
|
|
6
|
+
import type { StableRecordIdentifier } from '@warp-drive/core-types';
|
|
7
|
+
import type { TypeFromInstanceOrString } from '@warp-drive/core-types/record';
|
|
8
|
+
import type { CollectionResourceDocument, CollectionResourceRelationship, ExistingResourceObject, LinkObject, Meta, PaginationLinks } from '@warp-drive/core-types/spec/raw';
|
|
9
|
+
import type { IsUnknown } from '@ember-data/model/-private/belongs-to';
|
|
10
|
+
import type ManyArray from '@ember-data/model/-private/many-array';
|
|
11
|
+
/**
|
|
12
|
+
@module @ember-data/model
|
|
13
|
+
*/
|
|
14
|
+
interface ResourceIdentifier {
|
|
15
|
+
links?: {
|
|
16
|
+
related?: string | LinkObject;
|
|
17
|
+
};
|
|
18
|
+
meta?: Meta;
|
|
19
|
+
}
|
|
20
|
+
type ArrayItemType<T> = T extends (infer U)[] ? U : never;
|
|
21
|
+
/**
|
|
22
|
+
A `HasManyReference` is a low-level API that allows access
|
|
23
|
+
and manipulation of a hasMany relationship.
|
|
24
|
+
|
|
25
|
+
It is especially useful when you're dealing with `async` relationships
|
|
26
|
+
from `@ember-data/model` as it allows synchronous access to
|
|
27
|
+
the relationship data if loaded, as well as APIs for loading, reloading
|
|
28
|
+
the data or accessing available information without triggering a load.
|
|
29
|
+
|
|
30
|
+
It may also be useful when using `sync` relationships with `@ember-data/model`
|
|
31
|
+
that need to be loaded/reloaded with more precise timing than marking the
|
|
32
|
+
relationship as `async` and relying on autofetch would have allowed.
|
|
33
|
+
|
|
34
|
+
However,keep in mind that marking a relationship as `async: false` will introduce
|
|
35
|
+
bugs into your application if the data is not always guaranteed to be available
|
|
36
|
+
by the time the relationship is accessed. Ergo, it is recommended when using this
|
|
37
|
+
approach to utilize `links` for unloaded relationship state instead of identifiers.
|
|
38
|
+
|
|
39
|
+
Reference APIs are entangled with the relationship's underlying state,
|
|
40
|
+
thus any getters or cached properties that utilize these will properly
|
|
41
|
+
invalidate if the relationship state changes.
|
|
42
|
+
|
|
43
|
+
References are "stable", meaning that multiple calls to retrieve the reference
|
|
44
|
+
for a given relationship will always return the same HasManyReference.
|
|
45
|
+
|
|
46
|
+
@class HasManyReference
|
|
47
|
+
@public
|
|
48
|
+
*/
|
|
49
|
+
export default class HasManyReference<T = unknown, K extends string = IsUnknown<T> extends true ? string : keyof T & string, Related = K extends keyof T ? ArrayItemType<Awaited<T[K]>> : unknown> {
|
|
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 {String} key
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
key: K;
|
|
60
|
+
/**
|
|
61
|
+
* The type of resource this relationship will contain.
|
|
62
|
+
*
|
|
63
|
+
* @property {String} type
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
type: TypeFromInstanceOrString<Related>;
|
|
67
|
+
___token: object;
|
|
68
|
+
___identifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>;
|
|
69
|
+
___relatedTokenMap: Map<StableRecordIdentifier, object>;
|
|
70
|
+
_ref: number;
|
|
71
|
+
constructor(store: Store, graph: Graph, parentIdentifier: StableRecordIdentifier<TypeFromInstanceOrString<T>>, hasManyRelationship: CollectionEdge, key: K);
|
|
72
|
+
/**
|
|
73
|
+
* This method should never be called by user code.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
destroy(): void;
|
|
78
|
+
/**
|
|
79
|
+
* An array of identifiers for the records that this reference refers to.
|
|
80
|
+
*
|
|
81
|
+
* @property {StableRecordIdentifier[]} identifiers
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
get identifiers(): StableRecordIdentifier<TypeFromInstanceOrString<Related>>[];
|
|
85
|
+
_resource(): CollectionResourceRelationship<import("@warp-drive/core-types/spec/raw").ExistingResourceIdentifierObject<string> | import("@warp-drive/core-types/spec/raw").NewResourceIdentifierObject<string>>;
|
|
86
|
+
/**
|
|
87
|
+
This returns a string that represents how the reference will be
|
|
88
|
+
looked up when it is loaded. If the relationship has a link it will
|
|
89
|
+
use the "link" otherwise it defaults to "id".
|
|
90
|
+
|
|
91
|
+
Example
|
|
92
|
+
|
|
93
|
+
```app/models/post.js
|
|
94
|
+
import Model, { hasMany } from '@ember-data/model';
|
|
95
|
+
|
|
96
|
+
export default class PostModel extends Model {
|
|
97
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
let post = store.push({
|
|
103
|
+
data: {
|
|
104
|
+
type: 'post',
|
|
105
|
+
id: 1,
|
|
106
|
+
relationships: {
|
|
107
|
+
comments: {
|
|
108
|
+
data: [{ type: 'comment', id: 1 }]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
let commentsRef = post.hasMany('comments');
|
|
115
|
+
|
|
116
|
+
// get the identifier of the reference
|
|
117
|
+
if (commentsRef.remoteType() === "ids") {
|
|
118
|
+
let ids = commentsRef.ids();
|
|
119
|
+
} else if (commentsRef.remoteType() === "link") {
|
|
120
|
+
let link = commentsRef.link();
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
@method remoteType
|
|
125
|
+
@public
|
|
126
|
+
@return {String} The name of the remote type. This should either be `link` or `ids`
|
|
127
|
+
*/
|
|
128
|
+
remoteType(): 'link' | 'ids';
|
|
129
|
+
/**
|
|
130
|
+
`ids()` returns an array of the record IDs in this relationship.
|
|
131
|
+
|
|
132
|
+
Example
|
|
133
|
+
|
|
134
|
+
```app/models/post.js
|
|
135
|
+
import Model, { hasMany } from '@ember-data/model';
|
|
136
|
+
|
|
137
|
+
export default class PostModel extends Model {
|
|
138
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
let post = store.push({
|
|
144
|
+
data: {
|
|
145
|
+
type: 'post',
|
|
146
|
+
id: 1,
|
|
147
|
+
relationships: {
|
|
148
|
+
comments: {
|
|
149
|
+
data: [{ type: 'comment', id: 1 }]
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
let commentsRef = post.hasMany('comments');
|
|
156
|
+
|
|
157
|
+
commentsRef.ids(); // ['1']
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
@method ids
|
|
161
|
+
@public
|
|
162
|
+
@return {Array} The ids in this has-many relationship
|
|
163
|
+
*/
|
|
164
|
+
ids(): Array<string | null>;
|
|
165
|
+
/**
|
|
166
|
+
The link Ember Data will use to fetch or reload this belongs-to
|
|
167
|
+
relationship. By default it uses only the "related" resource linkage.
|
|
168
|
+
|
|
169
|
+
Example
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
// models/blog.js
|
|
173
|
+
import Model, { belongsTo } from '@ember-data/model';
|
|
174
|
+
export default Model.extend({
|
|
175
|
+
user: belongsTo('user', { async: true, inverse: null })
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
let blog = store.push({
|
|
179
|
+
data: {
|
|
180
|
+
type: 'blog',
|
|
181
|
+
id: 1,
|
|
182
|
+
relationships: {
|
|
183
|
+
user: {
|
|
184
|
+
links: {
|
|
185
|
+
related: '/articles/1/author'
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
let userRef = blog.belongsTo('user');
|
|
192
|
+
|
|
193
|
+
// get the identifier of the reference
|
|
194
|
+
if (userRef.remoteType() === "link") {
|
|
195
|
+
let link = userRef.link();
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
@method link
|
|
200
|
+
@public
|
|
201
|
+
@return {String} The link Ember Data will use to fetch or reload this belongs-to relationship.
|
|
202
|
+
*/
|
|
203
|
+
link(): string | null;
|
|
204
|
+
/**
|
|
205
|
+
* any links that have been received for this relationship
|
|
206
|
+
*
|
|
207
|
+
* @method links
|
|
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 '@ember-data/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
|
+
@method meta
|
|
249
|
+
@public
|
|
250
|
+
@return {Object|null} The meta information for the belongs-to relationship.
|
|
251
|
+
*/
|
|
252
|
+
meta(): Meta | null;
|
|
253
|
+
/**
|
|
254
|
+
`push` can be used to update the data in the relationship and EmberData
|
|
255
|
+
will treat the new data as the canonical value of this relationship on
|
|
256
|
+
the backend. An empty array will signify the canonical value should be
|
|
257
|
+
empty.
|
|
258
|
+
|
|
259
|
+
Example model
|
|
260
|
+
|
|
261
|
+
```app/models/post.js
|
|
262
|
+
import Model, { hasMany } from '@ember-data/model';
|
|
263
|
+
|
|
264
|
+
export default class PostModel extends Model {
|
|
265
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Setup some initial state, note we haven't loaded the comments yet:
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
const post = store.push({
|
|
273
|
+
data: {
|
|
274
|
+
type: 'post',
|
|
275
|
+
id: '1',
|
|
276
|
+
relationships: {
|
|
277
|
+
comments: {
|
|
278
|
+
data: [{ type: 'comment', id: '1' }]
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const commentsRef = post.hasMany('comments');
|
|
285
|
+
commentsRef.ids(); // ['1']
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Update the state using `push`, note we can do this even without
|
|
289
|
+
having loaded these comments yet by providing resource identifiers.
|
|
290
|
+
|
|
291
|
+
Both full resources and resource identifiers are supported.
|
|
292
|
+
|
|
293
|
+
```js
|
|
294
|
+
await commentsRef.push({
|
|
295
|
+
data: [
|
|
296
|
+
{ type: 'comment', id: '2' },
|
|
297
|
+
{ type: 'comment', id: '3' },
|
|
298
|
+
]
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
commentsRef.ids(); // ['2', '3']
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
For convenience, you can also pass in an array of resources or resource identifiers
|
|
305
|
+
without wrapping them in the `data` property:
|
|
306
|
+
|
|
307
|
+
```js
|
|
308
|
+
await commentsRef.push([
|
|
309
|
+
{ type: 'comment', id: '4' },
|
|
310
|
+
{ type: 'comment', id: '5' },
|
|
311
|
+
]);
|
|
312
|
+
|
|
313
|
+
commentsRef.ids(); // ['4', '5']
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
When using the `data` property, you may also include other resource data via included,
|
|
317
|
+
as well as provide new links and meta to the relationship.
|
|
318
|
+
|
|
319
|
+
```js
|
|
320
|
+
await commentsRef.push({
|
|
321
|
+
links: {
|
|
322
|
+
related: '/posts/1/comments'
|
|
323
|
+
},
|
|
324
|
+
meta: {
|
|
325
|
+
total: 2
|
|
326
|
+
},
|
|
327
|
+
data: [
|
|
328
|
+
{ type: 'comment', id: '4' },
|
|
329
|
+
{ type: 'comment', id: '5' },
|
|
330
|
+
],
|
|
331
|
+
included: [
|
|
332
|
+
{ type: 'other-thing', id: '1', attributes: { foo: 'bar' },
|
|
333
|
+
]
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
By default, the store will attempt to fetch any unloaded records before resolving
|
|
338
|
+
the returned promise with the ManyArray.
|
|
339
|
+
|
|
340
|
+
Alternatively, pass `true` as the second argument to avoid fetching unloaded records
|
|
341
|
+
and instead the promise will resolve with void without attempting to fetch. This is
|
|
342
|
+
particularly useful if you want to update the state of the relationship without
|
|
343
|
+
forcing the load of all of the associated records.
|
|
344
|
+
|
|
345
|
+
@method push
|
|
346
|
+
@public
|
|
347
|
+
@param {Array|Object} doc a JSONAPI document object describing the new value of this relationship.
|
|
348
|
+
@param {Boolean} [skipFetch] if `true`, do not attempt to fetch unloaded records
|
|
349
|
+
@return {Promise<ManyArray | void>}
|
|
350
|
+
*/
|
|
351
|
+
push(doc: ExistingResourceObject[] | CollectionResourceDocument, skipFetch?: boolean): Promise<ManyArray<Related> | void>;
|
|
352
|
+
_isLoaded(): boolean | undefined;
|
|
353
|
+
/**
|
|
354
|
+
`value()` synchronously returns the current value of the has-many
|
|
355
|
+
relationship. Unlike `record.relationshipName`, calling
|
|
356
|
+
`value()` on a reference does not trigger a fetch if the async
|
|
357
|
+
relationship is not yet loaded. If the relationship is not loaded
|
|
358
|
+
it will always return `null`.
|
|
359
|
+
|
|
360
|
+
Example
|
|
361
|
+
|
|
362
|
+
```app/models/post.js
|
|
363
|
+
import Model, { hasMany } from '@ember-data/model';
|
|
364
|
+
|
|
365
|
+
export default class PostModel extends Model {
|
|
366
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
```javascript
|
|
371
|
+
let post = store.push({
|
|
372
|
+
data: {
|
|
373
|
+
type: 'post',
|
|
374
|
+
id: 1,
|
|
375
|
+
relationships: {
|
|
376
|
+
comments: {
|
|
377
|
+
data: [{ type: 'comment', id: 1 }]
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
let commentsRef = post.hasMany('comments');
|
|
384
|
+
|
|
385
|
+
post.comments.then(function(comments) {
|
|
386
|
+
commentsRef.value() === comments
|
|
387
|
+
})
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
@method value
|
|
391
|
+
@public
|
|
392
|
+
@return {ManyArray}
|
|
393
|
+
*/
|
|
394
|
+
value(): ManyArray<Related> | null;
|
|
395
|
+
/**
|
|
396
|
+
Loads the relationship if it is not already loaded. If the
|
|
397
|
+
relationship is already loaded this method does not trigger a new
|
|
398
|
+
load. This causes a request to the specified
|
|
399
|
+
relationship link or reloads all items currently in the relationship.
|
|
400
|
+
|
|
401
|
+
Example
|
|
402
|
+
|
|
403
|
+
```app/models/post.js
|
|
404
|
+
import Model, { hasMany } from '@ember-data/model';
|
|
405
|
+
|
|
406
|
+
export default class PostModel extends Model {
|
|
407
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
```javascript
|
|
412
|
+
let post = store.push({
|
|
413
|
+
data: {
|
|
414
|
+
type: 'post',
|
|
415
|
+
id: 1,
|
|
416
|
+
relationships: {
|
|
417
|
+
comments: {
|
|
418
|
+
data: [{ type: 'comment', id: 1 }]
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
let commentsRef = post.hasMany('comments');
|
|
425
|
+
|
|
426
|
+
commentsRef.load().then(function(comments) {
|
|
427
|
+
//...
|
|
428
|
+
});
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
You may also pass in an options object whose properties will be
|
|
432
|
+
fed forward. This enables you to pass `adapterOptions` into the
|
|
433
|
+
request given to the adapter via the reference.
|
|
434
|
+
|
|
435
|
+
Example
|
|
436
|
+
|
|
437
|
+
```javascript
|
|
438
|
+
commentsRef.load({ adapterOptions: { isPrivate: true } })
|
|
439
|
+
.then(function(comments) {
|
|
440
|
+
//...
|
|
441
|
+
});
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
```app/adapters/comment.js
|
|
445
|
+
export default ApplicationAdapter.extend({
|
|
446
|
+
findMany(store, type, id, snapshots) {
|
|
447
|
+
// In the adapter you will have access to adapterOptions.
|
|
448
|
+
let adapterOptions = snapshots[0].adapterOptions;
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
@method load
|
|
454
|
+
@public
|
|
455
|
+
@param {Object} options the options to pass in.
|
|
456
|
+
@return {Promise} a promise that resolves with the ManyArray in
|
|
457
|
+
this has-many relationship.
|
|
458
|
+
*/
|
|
459
|
+
load(options?: BaseFinderOptions): Promise<ManyArray<Related>>;
|
|
460
|
+
/**
|
|
461
|
+
Reloads this has-many relationship. This causes a request to the specified
|
|
462
|
+
relationship link or reloads all items currently in the relationship.
|
|
463
|
+
|
|
464
|
+
Example
|
|
465
|
+
|
|
466
|
+
```app/models/post.js
|
|
467
|
+
import Model, { hasMany } from '@ember-data/model';
|
|
468
|
+
|
|
469
|
+
export default class PostModel extends Model {
|
|
470
|
+
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
```javascript
|
|
475
|
+
let post = store.push({
|
|
476
|
+
data: {
|
|
477
|
+
type: 'post',
|
|
478
|
+
id: 1,
|
|
479
|
+
relationships: {
|
|
480
|
+
comments: {
|
|
481
|
+
data: [{ type: 'comment', id: 1 }]
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
let commentsRef = post.hasMany('comments');
|
|
488
|
+
|
|
489
|
+
commentsRef.reload().then(function(comments) {
|
|
490
|
+
//...
|
|
491
|
+
});
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
You may also pass in an options object whose properties will be
|
|
495
|
+
fed forward. This enables you to pass `adapterOptions` into the
|
|
496
|
+
request given to the adapter via the reference. A full example
|
|
497
|
+
can be found in the `load` method.
|
|
498
|
+
|
|
499
|
+
Example
|
|
500
|
+
|
|
501
|
+
```javascript
|
|
502
|
+
commentsRef.reload({ adapterOptions: { isPrivate: true } })
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
@method reload
|
|
506
|
+
@public
|
|
507
|
+
@param {Object} options the options to pass in.
|
|
508
|
+
@return {Promise} a promise that resolves with the ManyArray in this has-many relationship.
|
|
509
|
+
*/
|
|
510
|
+
reload(options?: BaseFinderOptions): Promise<ManyArray<Related>>;
|
|
511
|
+
}
|
|
512
|
+
export function isMaybeResource(object: ExistingResourceObject | ResourceIdentifier): object is ExistingResourceObject;
|
|
513
|
+
export {};
|
|
514
|
+
}
|
|
515
|
+
//# sourceMappingURL=has-many.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-many.d.ts","sourceRoot":"","sources":["../../../src/-private/references/has-many.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare module '@ember-data/model/-private/schema-provider' {
|
|
2
|
+
import type Store from '@ember-data/store';
|
|
3
|
+
import type { FieldSchema } from '@ember-data/store/-types/q/schema-service';
|
|
4
|
+
import type { RecordIdentifier } from '@warp-drive/core-types/identifier';
|
|
5
|
+
import type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema';
|
|
6
|
+
import type { ModelFactory, ModelStore } from '@ember-data/model/-private/model';
|
|
7
|
+
export class ModelSchemaProvider {
|
|
8
|
+
store: ModelStore;
|
|
9
|
+
_relationshipsDefCache: Record<string, RelationshipsSchema>;
|
|
10
|
+
_attributesDefCache: Record<string, AttributesSchema>;
|
|
11
|
+
_fieldsDefCache: Record<string, Map<string, FieldSchema>>;
|
|
12
|
+
constructor(store: ModelStore);
|
|
13
|
+
fields(identifier: RecordIdentifier | {
|
|
14
|
+
type: string;
|
|
15
|
+
}): Map<string, FieldSchema>;
|
|
16
|
+
attributesDefinitionFor(identifier: RecordIdentifier | {
|
|
17
|
+
type: string;
|
|
18
|
+
}): AttributesSchema;
|
|
19
|
+
relationshipsDefinitionFor(identifier: RecordIdentifier | {
|
|
20
|
+
type: string;
|
|
21
|
+
}): RelationshipsSchema;
|
|
22
|
+
doesTypeExist(modelName: string): boolean;
|
|
23
|
+
}
|
|
24
|
+
export function buildSchema(store: Store): ModelSchemaProvider;
|
|
25
|
+
export function getModelFactory(store: ModelStore, type: string): ModelFactory | null;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=schema-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-provider.d.ts","sourceRoot":"","sources":["../../src/-private/schema-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAE3F,OAAO,KAAK,EAAuB,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAI7E,qBAAa,mBAAmB;IACtB,KAAK,EAAE,UAAU,CAAC;IAClB,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC5D,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACtD,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;gBAEtD,KAAK,EAAE,UAAU;IAO7B,MAAM,CAAC,UAAU,EAAE,gBAAgB,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC;IAwBjF,uBAAuB,CAAC,UAAU,EAAE,gBAAgB,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,gBAAgB;IAmB1F,0BAA0B,CAAC,UAAU,EAAE,gBAAgB,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,mBAAmB;IAehG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;CAM1C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,uBAEvC;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAkCpF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare module '@ember-data/model/-private/util' {
|
|
2
|
+
export type DecoratorPropertyDescriptor = (PropertyDescriptor & {
|
|
3
|
+
initializer?: () => unknown;
|
|
4
|
+
}) | undefined;
|
|
5
|
+
export function isElementDescriptor(args: unknown[]): args is [object, string, DecoratorPropertyDescriptor];
|
|
6
|
+
export type DataDecorator = (target: object, key: string, desc?: DecoratorPropertyDescriptor) => DecoratorPropertyDescriptor;
|
|
7
|
+
export type DataDecoratorFactory = (...args: unknown[]) => DataDecorator;
|
|
8
|
+
export function computedMacroWithOptionalParams(fn: DataDecorator | DataDecoratorFactory): (...maybeDesc: unknown[]) => DecoratorPropertyDescriptor | DataDecorator;
|
|
9
|
+
export function normalizeModelName(type: string): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/-private/util.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,2BAA2B,GAAG,CAAC,kBAAkB,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,OAAO,CAAA;CAAE,CAAC,GAAG,SAAS,CAAC;AAE7G,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,2BAA2B,CAAC,CAkB1G;AAED,MAAM,MAAM,aAAa,GAAG,CAC1B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,2BAA2B,KAC/B,2BAA2B,CAAC;AACjC,MAAM,MAAM,oBAAoB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,aAAa,CAAC;AAEzE,wBAAgB,+BAA+B,CAAC,EAAE,EAAE,aAAa,GAAG,oBAAoB,kBAChE,OAAO,EAAE,iDAIhC;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAsBvD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare module '@ember-data/model/-private' {
|
|
2
|
+
export { attr } from '@ember-data/model/-private/attr';
|
|
3
|
+
export { belongsTo } from '@ember-data/model/-private/belongs-to';
|
|
4
|
+
export { hasMany } from '@ember-data/model/-private/has-many';
|
|
5
|
+
export { Model } from '@ember-data/model/-private/model';
|
|
6
|
+
export { default as Errors } from '@ember-data/model/-private/errors';
|
|
7
|
+
export { default as ManyArray } from '@ember-data/model/-private/many-array';
|
|
8
|
+
export { PromiseBelongsTo } from '@ember-data/model/-private/promise-belongs-to';
|
|
9
|
+
export { default as PromiseManyArray } from '@ember-data/model/-private/promise-many-array';
|
|
10
|
+
export { lookupLegacySupport, LEGACY_SUPPORT } from '@ember-data/model/-private/legacy-relationships-support';
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=-private.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"-private.d.ts","sourceRoot":"","sources":["../src/-private.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAG5E,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/// <reference path="./migration-support.d.ts" />
|
|
2
|
+
/// <reference path="./hooks.d.ts" />
|
|
3
|
+
/// <reference path="./-private.d.ts" />
|
|
4
|
+
/// <reference path="./-private/record-state.d.ts" />
|
|
5
|
+
/// <reference path="./-private/model.d.ts" />
|
|
6
|
+
/// <reference path="./-private/model-methods.d.ts" />
|
|
7
|
+
/// <reference path="./-private/promise-many-array.d.ts" />
|
|
8
|
+
/// <reference path="./-private/util.d.ts" />
|
|
9
|
+
/// <reference path="./-private/has-many.d.ts" />
|
|
10
|
+
/// <reference path="./-private/belongs-to.d.ts" />
|
|
11
|
+
/// <reference path="./-private/attr.type-test.d.ts" />
|
|
12
|
+
/// <reference path="./-private/legacy-relationships-support.d.ts" />
|
|
13
|
+
/// <reference path="./-private/many-array.d.ts" />
|
|
14
|
+
/// <reference path="./-private/attr.d.ts" />
|
|
15
|
+
/// <reference path="./-private/promise-belongs-to.d.ts" />
|
|
16
|
+
/// <reference path="./-private/hooks.d.ts" />
|
|
17
|
+
/// <reference path="./-private/notify-changes.d.ts" />
|
|
18
|
+
/// <reference path="./-private/schema-provider.d.ts" />
|
|
19
|
+
/// <reference path="./-private/has-many.type-test.d.ts" />
|
|
20
|
+
/// <reference path="./-private/belongs-to.type-test.d.ts" />
|
|
21
|
+
/// <reference path="./-private/model.type-test.d.ts" />
|
|
22
|
+
/// <reference path="./-private/model-for-mixin.d.ts" />
|
|
23
|
+
/// <reference path="./-private/promise-proxy-base.d.ts" />
|
|
24
|
+
/// <reference path="./-private/errors.d.ts" />
|
|
25
|
+
/// <reference path="./-private/debug/assert-polymorphic-type.d.ts" />
|
|
26
|
+
/// <reference path="./-private/references/has-many.d.ts" />
|
|
27
|
+
/// <reference path="./-private/references/belongs-to.d.ts" />
|
|
28
|
+
declare module '@ember-data/model' {
|
|
29
|
+
/**
|
|
30
|
+
* This package provides a Presentation Model for resource data in an EmberData Cache.
|
|
31
|
+
*
|
|
32
|
+
* Models are defined as classes extending from `import Model from '@ember-data/model';` and the
|
|
33
|
+
* attributes and relationships on these classes are parsed at runtime to supply static "schema"
|
|
34
|
+
* to EmberData's SchemaService.
|
|
35
|
+
*
|
|
36
|
+
* Resource data for individual resources fetched from your API is presented to the UI via instances
|
|
37
|
+
* of the `Model`s you define. An instantiated `Model` is referred to as a `record`.
|
|
38
|
+
|
|
39
|
+
When we refer to the `ModelClass` as opposed to a `Model` or `Record` we are referring
|
|
40
|
+
specifically to the class definition and the static schema methods present on it.
|
|
41
|
+
|
|
42
|
+
When we refer to a `record` we refer to a specific class instance presenting
|
|
43
|
+
the resource data for a given `type` and `id`.
|
|
44
|
+
|
|
45
|
+
### Defining a Model
|
|
46
|
+
|
|
47
|
+
```app/models/person.js
|
|
48
|
+
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
|
|
49
|
+
|
|
50
|
+
export default class PersonModel extends Model {
|
|
51
|
+
@attr name;
|
|
52
|
+
|
|
53
|
+
@belongsTo('pet', { inverse: 'owners', async: false }) dog;
|
|
54
|
+
|
|
55
|
+
@hasMany('person', { inverse: 'friends', async: true }) friends;
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### modelName convention
|
|
60
|
+
|
|
61
|
+
By convention, the name of a given model (its `type`) matches the name
|
|
62
|
+
of the file in the `app/models` folder and should be lowercase, singular
|
|
63
|
+
and dasherized.
|
|
64
|
+
|
|
65
|
+
@module @ember-data/model
|
|
66
|
+
@main @ember-data/model
|
|
67
|
+
*/
|
|
68
|
+
export { Model as default, attr, belongsTo, hasMany } from '@ember-data/model/-private';
|
|
69
|
+
export type { PromiseBelongsTo as AsyncBelongsTo } from './-private/promise-belongs-to';
|
|
70
|
+
export type { default as AsyncHasMany } from './-private/promise-many-array';
|
|
71
|
+
export type { default as ManyArray } from './-private/many-array';
|
|
72
|
+
export { instantiateRecord, teardownRecord, modelFor } from '@ember-data/model/-private/hooks';
|
|
73
|
+
export { ModelSchemaProvider } from '@ember-data/model/-private/schema-provider';
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAExE,YAAY,EAAE,gBAAgB,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACxF,YAAY,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7E,YAAY,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
|