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