@ember-data/model 5.4.0-alpha.32 → 5.4.0-alpha.33
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/package.json +19 -19
- package/unstable-preview-types/-private/attr.d.ts +171 -169
- package/unstable-preview-types/-private/attr.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/belongs-to.d.ts +181 -179
- package/unstable-preview-types/-private/belongs-to.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +8 -6
- package/unstable-preview-types/-private/errors.d.ts +290 -288
- package/unstable-preview-types/-private/has-many.d.ts +170 -168
- package/unstable-preview-types/-private/has-many.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/hooks.d.ts +13 -11
- package/unstable-preview-types/-private/legacy-relationships-support.d.ts +62 -60
- package/unstable-preview-types/-private/many-array.d.ts +193 -191
- package/unstable-preview-types/-private/model-for-mixin.d.ts +6 -4
- package/unstable-preview-types/-private/model-methods.d.ts +34 -32
- package/unstable-preview-types/-private/model.d.ts +103 -100
- package/unstable-preview-types/-private/model.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/notify-changes.d.ts +8 -6
- package/unstable-preview-types/-private/promise-belongs-to.d.ts +47 -45
- package/unstable-preview-types/-private/promise-many-array.d.ts +129 -127
- package/unstable-preview-types/-private/promise-proxy-base.d.ts +35 -32
- package/unstable-preview-types/-private/record-state.d.ts +88 -86
- package/unstable-preview-types/-private/references/belongs-to.d.ts +473 -471
- package/unstable-preview-types/-private/references/has-many.d.ts +488 -486
- package/unstable-preview-types/-private/schema-provider.d.ts +27 -25
- package/unstable-preview-types/-private/util.d.ts +11 -9
- package/unstable-preview-types/-private.d.ts +12 -10
- package/unstable-preview-types/hooks.d.ts +5 -3
- package/unstable-preview-types/index.d.ts +75 -46
- package/unstable-preview-types/migration-support.d.ts +11 -9
|
@@ -1,179 +1,181 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
export declare function belongsTo(
|
|
176
|
-
export declare function belongsTo
|
|
177
|
-
export declare function belongsTo<
|
|
178
|
-
export declare function belongsTo(type:
|
|
179
|
-
|
|
1
|
+
declare module '@ember-data/model/-private/belongs-to' {
|
|
2
|
+
import type { TypeFromInstance } from '@warp-drive/core-types/record';
|
|
3
|
+
/**
|
|
4
|
+
@module @ember-data/model
|
|
5
|
+
*/
|
|
6
|
+
export type IsUnknown<T> = unknown extends T ? true : false;
|
|
7
|
+
export type RelationshipOptions<T, Async extends boolean> = {
|
|
8
|
+
async: Async;
|
|
9
|
+
inverse: null | (IsUnknown<T> extends true ? string : keyof NoNull<T> & string);
|
|
10
|
+
polymorphic?: boolean;
|
|
11
|
+
as?: string;
|
|
12
|
+
resetOnRemoteUpdate?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type NoNull<T> = Exclude<T, null>;
|
|
15
|
+
export type RelationshipDecorator<T> = <This>(target: This, key: string, desc?: PropertyDescriptor) => void;
|
|
16
|
+
/**
|
|
17
|
+
`belongsTo` is used to define One-To-One and One-To-Many, and One-To-None
|
|
18
|
+
relationships on a [Model](/ember-data/release/classes/Model).
|
|
19
|
+
|
|
20
|
+
`belongsTo` takes a configuration hash as a second parameter, currently
|
|
21
|
+
supported options are:
|
|
22
|
+
|
|
23
|
+
- `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.
|
|
24
|
+
- `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.
|
|
25
|
+
- `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic
|
|
26
|
+
- `as`: (*optional*) A string used to declare the abstract type "this" record satisfies for polymorphism.
|
|
27
|
+
|
|
28
|
+
### Examples
|
|
29
|
+
|
|
30
|
+
To declare a **one-to-many** (or many-to-many) relationship, use
|
|
31
|
+
`belongsTo` in combination with `hasMany`:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
// app/models/comment.js
|
|
35
|
+
import Model, { belongsTo } from '@ember-data/model';
|
|
36
|
+
|
|
37
|
+
export default class Comment extends Model {
|
|
38
|
+
@belongsTo('post', { async: false, inverse: 'comments' }) post;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// app/models/post.js
|
|
42
|
+
import Model, { hasMany } from '@ember-data/model';
|
|
43
|
+
|
|
44
|
+
export default class Post extends Model {
|
|
45
|
+
@hasMany('comment', { async: false, inverse: 'post' }) comments;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
To declare a **one-to-one** relationship with managed inverses, use `belongsTo` for both sides:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
// app/models/author.js
|
|
53
|
+
import Model, { belongsTo } from '@ember-data/model';
|
|
54
|
+
|
|
55
|
+
export default class Author extends Model {
|
|
56
|
+
@belongsTo('address', { async: true, inverse: 'owner' }) address;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// app/models/address.js
|
|
60
|
+
import Model, { belongsTo } from '@ember-data/model';
|
|
61
|
+
|
|
62
|
+
export default class Address extends Model {
|
|
63
|
+
@belongsTo('author', { async: true, inverse: 'address' }) owner;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
To declare a **one-to-one** relationship without managed inverses, use `belongsTo` for both sides
|
|
68
|
+
with `null` as the inverse:
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
// app/models/author.js
|
|
72
|
+
import Model, { belongsTo } from '@ember-data/model';
|
|
73
|
+
|
|
74
|
+
export default class Author extends Model {
|
|
75
|
+
@belongsTo('address', { async: true, inverse: null }) address;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// app/models/address.js
|
|
79
|
+
import Model, { belongsTo } from '@ember-data/model';
|
|
80
|
+
|
|
81
|
+
export default class Address extends Model {
|
|
82
|
+
@belongsTo('author', { async: true, inverse: null }) owner;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
To declare a one-to-none relationship between two models, use
|
|
87
|
+
`belongsTo` with inverse set to `null` on just one side::
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
// app/models/person.js
|
|
91
|
+
import Model, { belongsTo } from '@ember-data/model';
|
|
92
|
+
|
|
93
|
+
export default class Person extends Model {
|
|
94
|
+
@belongsTo('person', { async: false, inverse: null }) bestFriend;
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Sync vs Async Relationships
|
|
99
|
+
|
|
100
|
+
EmberData fulfills relationships using resource data available in
|
|
101
|
+
the cache.
|
|
102
|
+
|
|
103
|
+
Sync relationships point directly to the known related resources.
|
|
104
|
+
|
|
105
|
+
When a relationship is declared as async, if any of the known related
|
|
106
|
+
resources have not been loaded, they will be fetched. The property
|
|
107
|
+
on the record when accessed provides a promise that resolves once
|
|
108
|
+
all resources are loaded.
|
|
109
|
+
|
|
110
|
+
Async relationships may take advantage of links. On access, if the related
|
|
111
|
+
link has not been loaded, or if any known resources are not available in
|
|
112
|
+
the cache, the fresh state will be fetched using the link.
|
|
113
|
+
|
|
114
|
+
In contrast to async relationship, accessing a sync relationship
|
|
115
|
+
will error on access when any of the known related resources have
|
|
116
|
+
not been loaded.
|
|
117
|
+
|
|
118
|
+
If you are using `links` with sync relationships, you have to use
|
|
119
|
+
the BelongsTo reference API to fetch or refresh related resources
|
|
120
|
+
that aren't loaded. For instance, for a `bestFriend` relationship:
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
person.belongsTo('bestFriend').reload();
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Polymorphic Relationships
|
|
127
|
+
|
|
128
|
+
To declare a polymorphic relationship, use `hasMany` with the `polymorphic`
|
|
129
|
+
option set to `true`:
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
// app/models/comment.js
|
|
133
|
+
import Model, { belongsTo } from '@ember-data/model';
|
|
134
|
+
|
|
135
|
+
export default class Comment extends Model {
|
|
136
|
+
@belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`'commentable'` here is referred to as the "abstract type" for the polymorphic
|
|
141
|
+
relationship.
|
|
142
|
+
|
|
143
|
+
Polymorphic relationships with `inverse: null` will accept any type of record as their content.
|
|
144
|
+
Polymorphic relationships with `inverse` set to a string will only accept records with a matching
|
|
145
|
+
inverse relationships declaring itself as satisfying the abstract type.
|
|
146
|
+
|
|
147
|
+
Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'
|
|
148
|
+
for this relationship.
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
// app/models/post.js
|
|
152
|
+
import Model, { hasMany } from '@ember-data/model';
|
|
153
|
+
|
|
154
|
+
export default class Post extends Model {
|
|
155
|
+
@hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Note: every Model that declares an inverse to a polymorphic relationship must
|
|
160
|
+
declare itself exactly the same. This is because polymorphism is based on structural
|
|
161
|
+
traits.
|
|
162
|
+
|
|
163
|
+
Polymorphic to polymorphic relationships are supported. Both sides of the relationship
|
|
164
|
+
must be declared as polymorphic, and the `as` option must be used to declare the abstract
|
|
165
|
+
type each record satisfies on both sides.
|
|
166
|
+
|
|
167
|
+
@method belongsTo
|
|
168
|
+
@public
|
|
169
|
+
@static
|
|
170
|
+
@for @ember-data/model
|
|
171
|
+
@param {string} type (optional) the name of the related resource
|
|
172
|
+
@param {object} options (optional) a hash of options
|
|
173
|
+
@return {PropertyDescriptor} relationship
|
|
174
|
+
*/
|
|
175
|
+
export declare function belongsTo(): never;
|
|
176
|
+
export declare function belongsTo(type: string): never;
|
|
177
|
+
export declare function belongsTo<T>(type: TypeFromInstance<NoNull<T>>, options: RelationshipOptions<T, false>): RelationshipDecorator<T>;
|
|
178
|
+
export declare function belongsTo<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(type: TypeFromInstance<NoNull<T>>, options: RelationshipOptions<T, true>): RelationshipDecorator<K>;
|
|
179
|
+
export declare function belongsTo(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;
|
|
180
|
+
//# sourceMappingURL=belongs-to.d.ts.map
|
|
181
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
declare module '@ember-data/model/-private/debug/assert-polymorphic-type' {
|
|
2
|
+
import type { StableRecordIdentifier } from '@warp-drive/core-types';
|
|
3
|
+
import type Store from '@ember-data/store';
|
|
4
|
+
import type { UpgradedMeta } from '@ember-data/graph/-private/-edge-definition';
|
|
5
|
+
declare let assertPolymorphicType: (parentIdentifier: StableRecordIdentifier, parentDefinition: UpgradedMeta, addedIdentifier: StableRecordIdentifier, store: Store) => void;
|
|
6
|
+
export { assertPolymorphicType };
|
|
7
|
+
//# sourceMappingURL=assert-polymorphic-type.d.ts.map
|
|
8
|
+
}
|