@ember-data/model 5.4.0-alpha.3 → 5.4.0-alpha.31

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 (73) hide show
  1. package/addon/-private.js +2 -2
  2. package/addon/has-many-Qm5aUQol.js +645 -0
  3. package/addon/has-many-Qm5aUQol.js.map +1 -0
  4. package/addon/{hooks-0482f3cc.js → hooks-YY4O5eQM.js} +34 -15
  5. package/addon/hooks-YY4O5eQM.js.map +1 -0
  6. package/addon/hooks.js +1 -1
  7. package/addon/index.js +3 -3
  8. package/addon/index.js.map +1 -1
  9. package/addon/migration-support.js +118 -0
  10. package/addon/migration-support.js.map +1 -0
  11. package/addon/{model-48ae96f9.js → model-eXqU5A13.js} +2030 -1876
  12. package/addon/model-eXqU5A13.js.map +1 -0
  13. package/addon/util-Km_Z-hz0.js +35 -0
  14. package/addon/util-Km_Z-hz0.js.map +1 -0
  15. package/package.json +85 -34
  16. package/unstable-preview-types/-private/attr.d.ts +172 -0
  17. package/unstable-preview-types/-private/attr.d.ts.map +1 -0
  18. package/unstable-preview-types/-private/attr.type-test.d.ts +2 -0
  19. package/unstable-preview-types/-private/attr.type-test.d.ts.map +1 -0
  20. package/unstable-preview-types/-private/belongs-to.d.ts +179 -0
  21. package/unstable-preview-types/-private/belongs-to.d.ts.map +1 -0
  22. package/unstable-preview-types/-private/belongs-to.type-test.d.ts +2 -0
  23. package/unstable-preview-types/-private/belongs-to.type-test.d.ts.map +1 -0
  24. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +6 -0
  25. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
  26. package/unstable-preview-types/-private/errors.d.ts +306 -0
  27. package/unstable-preview-types/-private/errors.d.ts.map +1 -0
  28. package/unstable-preview-types/-private/has-many.d.ts +168 -0
  29. package/unstable-preview-types/-private/has-many.d.ts.map +1 -0
  30. package/unstable-preview-types/-private/has-many.type-test.d.ts +2 -0
  31. package/unstable-preview-types/-private/has-many.type-test.d.ts.map +1 -0
  32. package/unstable-preview-types/-private/hooks.d.ts +11 -0
  33. package/unstable-preview-types/-private/hooks.d.ts.map +1 -0
  34. package/unstable-preview-types/-private/legacy-relationships-support.d.ts +60 -0
  35. package/unstable-preview-types/-private/legacy-relationships-support.d.ts.map +1 -0
  36. package/unstable-preview-types/-private/many-array.d.ts +195 -0
  37. package/unstable-preview-types/-private/many-array.d.ts.map +1 -0
  38. package/unstable-preview-types/-private/model-for-mixin.d.ts +4 -0
  39. package/unstable-preview-types/-private/model-for-mixin.d.ts.map +1 -0
  40. package/unstable-preview-types/-private/model-methods.d.ts +32 -0
  41. package/unstable-preview-types/-private/model-methods.d.ts.map +1 -0
  42. package/unstable-preview-types/-private/model.d.ts +101 -0
  43. package/unstable-preview-types/-private/model.type-test.d.ts +2 -0
  44. package/unstable-preview-types/-private/model.type-test.d.ts.map +1 -0
  45. package/unstable-preview-types/-private/notify-changes.d.ts +6 -0
  46. package/unstable-preview-types/-private/notify-changes.d.ts.map +1 -0
  47. package/unstable-preview-types/-private/promise-belongs-to.d.ts +45 -0
  48. package/unstable-preview-types/-private/promise-belongs-to.d.ts.map +1 -0
  49. package/unstable-preview-types/-private/promise-many-array.d.ts +127 -0
  50. package/unstable-preview-types/-private/promise-many-array.d.ts.map +1 -0
  51. package/unstable-preview-types/-private/promise-proxy-base.d.ts +32 -0
  52. package/unstable-preview-types/-private/record-state.d.ts +89 -0
  53. package/unstable-preview-types/-private/record-state.d.ts.map +1 -0
  54. package/unstable-preview-types/-private/references/belongs-to.d.ts +501 -0
  55. package/unstable-preview-types/-private/references/belongs-to.d.ts.map +1 -0
  56. package/unstable-preview-types/-private/references/has-many.d.ts +513 -0
  57. package/unstable-preview-types/-private/references/has-many.d.ts.map +1 -0
  58. package/unstable-preview-types/-private/schema-provider.d.ts +25 -0
  59. package/unstable-preview-types/-private/schema-provider.d.ts.map +1 -0
  60. package/unstable-preview-types/-private/util.d.ts +9 -0
  61. package/unstable-preview-types/-private/util.d.ts.map +1 -0
  62. package/unstable-preview-types/-private.d.ts +10 -0
  63. package/unstable-preview-types/-private.d.ts.map +1 -0
  64. package/unstable-preview-types/hooks.d.ts +3 -0
  65. package/unstable-preview-types/hooks.d.ts.map +1 -0
  66. package/unstable-preview-types/index.d.ts +46 -0
  67. package/unstable-preview-types/index.d.ts.map +1 -0
  68. package/unstable-preview-types/migration-support.d.ts +9 -0
  69. package/unstable-preview-types/migration-support.d.ts.map +1 -0
  70. package/addon/has-many-0759b264.js +0 -507
  71. package/addon/has-many-0759b264.js.map +0 -1
  72. package/addon/hooks-0482f3cc.js.map +0 -1
  73. package/addon/model-48ae96f9.js.map +0 -1
@@ -0,0 +1,306 @@
1
+ /// <reference types="ember-source/types" />
2
+ /// <reference types="ember-source/types" />
3
+ import { type NativeArray } from '@ember/array';
4
+ import ArrayProxy from '@ember/array/proxy';
5
+ import type RecordState from './record-state';
6
+ type ValidationError = {
7
+ attribute: string;
8
+ message: string;
9
+ };
10
+ /**
11
+ @module @ember-data/model
12
+ */
13
+ interface ArrayProxyWithCustomOverrides<T> extends Omit<ArrayProxy<T>, 'clear' | 'content'> {
14
+ content: NativeArray<T>;
15
+ clear(): void;
16
+ _has(name: string): boolean;
17
+ }
18
+ declare const ArrayProxyWithCustomOverrides: new <T>() => ArrayProxyWithCustomOverrides<T>;
19
+ /**
20
+ Holds validation errors for a given record, organized by attribute names.
21
+
22
+ This class is not directly instantiable.
23
+
24
+ Every `Model` has an `errors` property that is an instance of
25
+ `Errors`. This can be used to display validation error
26
+ messages returned from the server when a `record.save()` rejects.
27
+
28
+ For Example, if you had a `User` model that looked like this:
29
+
30
+ ```app/models/user.js
31
+ import Model, { attr } from '@ember-data/model';
32
+
33
+ export default class UserModel extends Model {
34
+ @attr('string') username;
35
+ @attr('string') email;
36
+ }
37
+ ```
38
+ And you attempted to save a record that did not validate on the backend:
39
+
40
+ ```javascript
41
+ let user = store.createRecord('user', {
42
+ username: 'tomster',
43
+ email: 'invalidEmail'
44
+ });
45
+ user.save();
46
+ ```
47
+
48
+ Your backend would be expected to return an error response that described
49
+ the problem, so that error messages can be generated on the app.
50
+
51
+ API responses will be translated into instances of `Errors` differently,
52
+ depending on the specific combination of adapter and serializer used. You
53
+ may want to check the documentation or the source code of the libraries
54
+ that you are using, to know how they expect errors to be communicated.
55
+
56
+ Errors can be displayed to the user by accessing their property name
57
+ to get an array of all the error objects for that property. Each
58
+ error object is a JavaScript object with two keys:
59
+
60
+ - `message` A string containing the error message from the backend
61
+ - `attribute` The name of the property associated with this error message
62
+
63
+ ```handlebars
64
+ <label>Username: <Input @value={{@model.username}} /> </label>
65
+ {{#each @model.errors.username as |error|}}
66
+ <div class="error">
67
+ {{error.message}}
68
+ </div>
69
+ {{/each}}
70
+
71
+ <label>Email: <Input @value={{@model.email}} /> </label>
72
+ {{#each @model.errors.email as |error|}}
73
+ <div class="error">
74
+ {{error.message}}
75
+ </div>
76
+ {{/each}}
77
+ ```
78
+
79
+ You can also access the special `messages` property on the error
80
+ object to get an array of all the error strings.
81
+
82
+ ```handlebars
83
+ {{#each @model.errors.messages as |message|}}
84
+ <div class="error">
85
+ {{message}}
86
+ </div>
87
+ {{/each}}
88
+ ```
89
+
90
+ @class Errors
91
+ @public
92
+ @extends Ember.ArrayProxy
93
+ */
94
+ declare class Errors extends ArrayProxyWithCustomOverrides<ValidationError> {
95
+ __record: {
96
+ currentState: RecordState;
97
+ };
98
+ /**
99
+ @property errorsByAttributeName
100
+ @type {MapWithDefault}
101
+ @private
102
+ */
103
+ get errorsByAttributeName(): Map<string, NativeArray<ValidationError>>;
104
+ /**
105
+ Returns errors for a given attribute
106
+
107
+ ```javascript
108
+ let user = store.createRecord('user', {
109
+ username: 'tomster',
110
+ email: 'invalidEmail'
111
+ });
112
+ user.save().catch(function(){
113
+ user.errors.errorsFor('email'); // returns:
114
+ // [{attribute: "email", message: "Doesn't look like a valid email."}]
115
+ });
116
+ ```
117
+
118
+ @method errorsFor
119
+ @public
120
+ @param {String} attribute
121
+ @return {Array}
122
+ */
123
+ errorsFor(attribute: string): NativeArray<ValidationError>;
124
+ /**
125
+ An array containing all of the error messages for this
126
+ record. This is useful for displaying all errors to the user.
127
+
128
+ ```handlebars
129
+ {{#each @model.errors.messages as |message|}}
130
+ <div class="error">
131
+ {{message}}
132
+ </div>
133
+ {{/each}}
134
+ ```
135
+
136
+ @property messages
137
+ @public
138
+ @type {Array}
139
+ */
140
+ messages: string[];
141
+ /**
142
+ @property content
143
+ @type {Array}
144
+ @private
145
+ */
146
+ get content(): NativeArray<ValidationError>;
147
+ /**
148
+ @method unknownProperty
149
+ @private
150
+ */
151
+ unknownProperty(attribute: string): NativeArray<ValidationError> | undefined;
152
+ /**
153
+ Total number of errors.
154
+
155
+ @property length
156
+ @type {Number}
157
+ @public
158
+ @readOnly
159
+ */
160
+ /**
161
+ `true` if we have no errors.
162
+
163
+ @property isEmpty
164
+ @type {Boolean}
165
+ @public
166
+ @readOnly
167
+ */
168
+ isEmpty: boolean;
169
+ /**
170
+ Manually adds errors to the record. This will trigger the `becameInvalid` event/ lifecycle method on
171
+ the record and transition the record into an `invalid` state.
172
+
173
+ Example
174
+ ```javascript
175
+ let errors = user.errors;
176
+
177
+ // add multiple errors
178
+ errors.add('password', [
179
+ 'Must be at least 12 characters',
180
+ 'Must contain at least one symbol',
181
+ 'Cannot contain your name'
182
+ ]);
183
+
184
+ errors.errorsFor('password');
185
+ // =>
186
+ // [
187
+ // { attribute: 'password', message: 'Must be at least 12 characters' },
188
+ // { attribute: 'password', message: 'Must contain at least one symbol' },
189
+ // { attribute: 'password', message: 'Cannot contain your name' },
190
+ // ]
191
+
192
+ // add a single error
193
+ errors.add('username', 'This field is required');
194
+
195
+ errors.errorsFor('username');
196
+ // =>
197
+ // [
198
+ // { attribute: 'username', message: 'This field is required' },
199
+ // ]
200
+ ```
201
+ @method add
202
+ @public
203
+ @param {string} attribute - the property name of an attribute or relationship
204
+ @param {string[]|string} messages - an error message or array of error messages for the attribute
205
+ */
206
+ add(attribute: string, messages: string[] | string): void;
207
+ /**
208
+ @method _findOrCreateMessages
209
+ @private
210
+ */
211
+ _findOrCreateMessages(attribute: string, messages: string | string[]): ValidationError[];
212
+ /**
213
+ Manually removes all errors for a given member from the record.
214
+ This will transition the record into a `valid` state, and
215
+ triggers the `becameValid` event and lifecycle method.
216
+
217
+ Example:
218
+
219
+ ```javascript
220
+ let errors = user.errors;
221
+ errors.add('phone', ['error-1', 'error-2']);
222
+
223
+ errors.errorsFor('phone');
224
+ // =>
225
+ // [
226
+ // { attribute: 'phone', message: 'error-1' },
227
+ // { attribute: 'phone', message: 'error-2' },
228
+ // ]
229
+
230
+ errors.remove('phone');
231
+
232
+ errors.errorsFor('phone');
233
+ // => undefined
234
+ ```
235
+ @method remove
236
+ @public
237
+ @param {string} member - the property name of an attribute or relationship
238
+ */
239
+ remove(attribute: string): void;
240
+ /**
241
+ Manually clears all errors for the record.
242
+ This will transition the record into a `valid` state, and
243
+ will trigger the `becameValid` event and lifecycle method.
244
+
245
+ Example:
246
+
247
+ ```javascript
248
+ let errors = user.errors;
249
+ errors.add('username', ['error-a']);
250
+ errors.add('phone', ['error-1', 'error-2']);
251
+
252
+ errors.errorsFor('username');
253
+ // =>
254
+ // [
255
+ // { attribute: 'username', message: 'error-a' },
256
+ // ]
257
+
258
+ errors.errorsFor('phone');
259
+ // =>
260
+ // [
261
+ // { attribute: 'phone', message: 'error-1' },
262
+ // { attribute: 'phone', message: 'error-2' },
263
+ // ]
264
+
265
+ errors.clear();
266
+
267
+ errors.errorsFor('username');
268
+ // => undefined
269
+
270
+ errors.errorsFor('phone');
271
+ // => undefined
272
+
273
+ errors.messages
274
+ // => []
275
+ ```
276
+ @method clear
277
+ @public
278
+ */
279
+ clear(): void;
280
+ /**
281
+ Checks if there are error messages for the given attribute.
282
+
283
+ ```app/controllers/user/edit.js
284
+ import Controller from '@ember/controller';
285
+ import { action } from '@ember/object';
286
+
287
+ export default class UserEditController extends Controller {
288
+ @action
289
+ save(user) {
290
+ if (user.errors.has('email')) {
291
+ return alert('Please update your email before attempting to save.');
292
+ }
293
+ user.save();
294
+ }
295
+ }
296
+ ```
297
+
298
+ @method has
299
+ @public
300
+ @param {String} attribute
301
+ @return {Boolean} true if there some errors on given attribute
302
+ */
303
+ has(attribute: string): boolean;
304
+ }
305
+ export default Errors;
306
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/-private/errors.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAK,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAI5C,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAE9C,KAAK,eAAe,GAAG;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AACF;;EAEE;AACF,UAAU,6BAA6B,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAIzF,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACxB,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAKD,QAAA,MAAM,6BAA6B,+CAAyE,CAAC;AAE7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,cAAM,MAAO,SAAQ,6BAA6B,CAAC,eAAe,CAAC;IACzD,QAAQ,EAAE;QAAE,YAAY,EAAE,WAAW,CAAA;KAAE,CAAC;IAChD;;;;MAIE;IACF,IACI,qBAAqB,IAAI,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC,CAErE;IAED;;;;;;;;;;;;;;;;;;MAkBE;IACF,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,eAAe,CAAC;IAmB1D;;;;;;;;;;;;;;;MAeE;IAEM,QAAQ,EAAE,MAAM,EAAE,CAAC;IAE3B;;;;MAIE;IACF,IACa,OAAO,IAAI,WAAW,CAAC,eAAe,CAAC,CAEnD;IAED;;;MAGE;IACF,eAAe,CAAC,SAAS,EAAE,MAAM;IAQjC;;;;;;;MAOE;IAEF;;;;;;;MAOE;IAEM,OAAO,EAAE,OAAO,CAAC;IAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI;IAUzD;;;MAGE;IACF,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,eAAe,EAAE;IAqBxF;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM;IAwBxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACM,KAAK,IAAI,IAAI;IAqBtB;;;;;;;;;;;;;;;;;;;;;;MAsBE;IACF,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;CAGhC;AAED,eAAe,MAAM,CAAC"}
@@ -0,0 +1,168 @@
1
+ import type { TypeFromInstance } from '@warp-drive/core-types/record';
2
+ import type { NoNull, RelationshipDecorator, RelationshipOptions } from './belongs-to';
3
+ /**
4
+ `hasMany` is used to define Many-To-One and Many-To-Many, and Many-To-None
5
+ relationships on a [Model](/ember-data/release/classes/Model).
6
+
7
+ `hasMany` takes a configuration hash as a second parameter, currently
8
+ supported options are:
9
+
10
+ - `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.
11
+ - `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.
12
+ - `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic
13
+ - `as`: (*optional*) A string used to declare the abstract type "this" record satisfies for polymorphism.
14
+
15
+ ### Examples
16
+
17
+ To declare a **many-to-one** (or one-to-many) relationship, use
18
+ `belongsTo` in combination with `hasMany`:
19
+
20
+ ```js
21
+ // app/models/post.js
22
+ import Model, { hasMany } from '@ember-data/model';
23
+
24
+ export default class Post extends Model {
25
+ @hasMany('comment', { async: false, inverse: 'post' }) comments;
26
+ }
27
+
28
+
29
+ // app/models/comment.js
30
+ import Model, { belongsTo } from '@ember-data/model';
31
+
32
+ export default class Comment extends Model {
33
+ @belongsTo('post', { async: false, inverse: 'comments' }) post;
34
+ }
35
+ ```
36
+
37
+ To declare a **many-to-many** relationship with managed inverses, use `hasMany` for both sides:
38
+
39
+ ```js
40
+ // app/models/post.js
41
+ import Model, { hasMany } from '@ember-data/model';
42
+
43
+ export default class Post extends Model {
44
+ @hasMany('tag', { async: true, inverse: 'posts' }) tags;
45
+ }
46
+
47
+ // app/models/tag.js
48
+ import Model, { hasMany } from '@ember-data/model';
49
+
50
+ export default class Tag extends Model {
51
+ @hasMany('post', { async: true, inverse: 'tags' }) posts;
52
+ }
53
+ ```
54
+
55
+ To declare a **many-to-many** relationship without managed inverses, use `hasMany` for both sides
56
+ with `null` as the inverse:
57
+
58
+ ```js
59
+ // app/models/post.js
60
+ import Model, { hasMany } from '@ember-data/model';
61
+
62
+ export default class Post extends Model {
63
+ @hasMany('tag', { async: true, inverse: null }) tags;
64
+ }
65
+
66
+ // app/models/tag.js
67
+ import Model, { hasMany } from '@ember-data/model';
68
+
69
+ export default class Tag extends Model {
70
+ @hasMany('post', { async: true, inverse: null }) posts;
71
+ }
72
+ ```
73
+
74
+ To declare a many-to-none relationship between two models, use
75
+ `hasMany` with inverse set to `null` on just one side::
76
+
77
+ ```js
78
+ // app/models/post.js
79
+ import Model, { hasMany } from '@ember-data/model';
80
+
81
+ export default class Post extends Model {
82
+ @hasMany('category', { async: true, inverse: null }) categories;
83
+ }
84
+ ```
85
+
86
+ #### Sync vs Async Relationships
87
+
88
+ EmberData fulfills relationships using resource data available in
89
+ the cache.
90
+
91
+ Sync relationships point directly to the known related resources.
92
+
93
+ When a relationship is declared as async, if any of the known related
94
+ resources have not been loaded, they will be fetched. The property
95
+ on the record when accessed provides a promise that resolves once
96
+ all resources are loaded.
97
+
98
+ Async relationships may take advantage of links. On access, if the related
99
+ link has not been loaded, or if any known resources are not available in
100
+ the cache, the fresh state will be fetched using the link.
101
+
102
+ In contrast to async relationship, accessing a sync relationship
103
+ will error on access when any of the known related resources have
104
+ not been loaded.
105
+
106
+ If you are using `links` with sync relationships, you have to use
107
+ the HasMany reference API to fetch or refresh related resources
108
+ that aren't loaded. For instance, for a `comments` relationship:
109
+
110
+ ```js
111
+ post.hasMany('comments').reload();
112
+ ```
113
+
114
+ #### Polymorphic Relationships
115
+
116
+ To declare a polymorphic relationship, use `hasMany` with the `polymorphic`
117
+ option set to `true`:
118
+
119
+ ```js
120
+ // app/models/comment.js
121
+ import Model, { belongsTo } from '@ember-data/model';
122
+
123
+ export default class Comment extends Model {
124
+ @belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;
125
+ }
126
+ ```
127
+
128
+ `'commentable'` here is referred to as the "abstract type" for the polymorphic
129
+ relationship.
130
+
131
+ Polymorphic relationships with `inverse: null` will accept any type of record as their content.
132
+ Polymorphic relationships with `inverse` set to a string will only accept records with a matching
133
+ inverse relationships declaring itself as satisfying the abstract type.
134
+
135
+ Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'
136
+ for this relationship.
137
+
138
+ ```js
139
+ // app/models/post.js
140
+ import Model, { hasMany } from '@ember-data/model';
141
+
142
+ export default class Post extends Model {
143
+ @hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;
144
+ }
145
+ ```
146
+
147
+ Note: every Model that declares an inverse to a polymorphic relationship must
148
+ declare itself exactly the same. This is because polymorphism is based on structural
149
+ traits.
150
+
151
+ Polymorphic to polymorphic relationships are supported. Both sides of the relationship
152
+ must be declared as polymorphic, and the `as` option must be used to declare the abstract
153
+ type each record satisfies on both sides.
154
+
155
+ @method hasMany
156
+ @public
157
+ @static
158
+ @for @ember-data/model
159
+ @param {string} type (optional) the name of the related resource
160
+ @param {object} options (optional) a hash of options
161
+ @return {PropertyDescriptor} relationship
162
+ */
163
+ export declare function hasMany(): never;
164
+ export declare function hasMany(type: string): never;
165
+ export declare function hasMany<T>(type: TypeFromInstance<NoNull<T>>, options: RelationshipOptions<T, false>): RelationshipDecorator<T>;
166
+ export declare function hasMany<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(type: TypeFromInstance<NoNull<T>>, options: RelationshipOptions<T, true>): RelationshipDecorator<K>;
167
+ export declare function hasMany(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;
168
+ //# sourceMappingURL=has-many.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-many.d.ts","sourceRoot":"","sources":["../../src/-private/has-many.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,OAAO,KAAK,EAAE,MAAM,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAkFvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+JE;AACF,wBAAgB,OAAO,IAAI,KAAK,CAAC;AACjC,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;AAC7C,wBAAgB,OAAO,CAAC,CAAC,EACvB,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EACjC,OAAO,EAAE,mBAAmB,CAAC,CAAC,EAAE,KAAK,CAAC,GACrC,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAC5B,wBAAgB,OAAO,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EACnF,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EACjC,OAAO,EAAE,mBAAmB,CAAC,CAAC,EAAE,IAAI,CAAC,GACpC,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAC5B,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=has-many.type-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-many.type-test.d.ts","sourceRoot":"","sources":["../../src/-private/has-many.type-test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { type Store } from '@ember-data/store/-private';
2
+ import type { StableRecordIdentifier } from '@warp-drive/core-types';
3
+ import type { TypeFromInstance } from '@warp-drive/core-types/record';
4
+ import type { Model } from './model';
5
+ export declare function instantiateRecord(this: Store, identifier: StableRecordIdentifier, createRecordArgs: {
6
+ [key: string]: unknown;
7
+ }): Model;
8
+ export declare function teardownRecord(record: Model): void;
9
+ export declare function modelFor<T>(type: TypeFromInstance<T>): typeof Model | void;
10
+ export declare function modelFor(type: string): typeof Model | void;
11
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/-private/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoC,KAAK,KAAK,EAAY,MAAM,4BAA4B,CAAC;AACpG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,KAAK,EAAE,gBAAgB,EAA4B,MAAM,+BAA+B,CAAC;AAEhG,OAAO,KAAK,EAAE,KAAK,EAAc,MAAM,SAAS,CAAC;AAMjD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,KAAK,EACX,UAAU,EAAE,sBAAsB,EAClC,gBAAgB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,GAC3C,KAAK,CAwBP;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,KAAK,GAAG,IAAI,CAMlD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,GAAG,IAAI,CAAC;AAC5E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,KAAK,GAAG,IAAI,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { UpgradedMeta } from '@ember-data/graph/-private/-edge-definition';
2
+ import type { CollectionEdge } from '@ember-data/graph/-private/edges/collection';
3
+ import type { ResourceEdge } from '@ember-data/graph/-private/edges/resource';
4
+ import type { Graph } from '@ember-data/graph/-private/graph';
5
+ import type Store from '@ember-data/store';
6
+ import type { Cache } from '@ember-data/store/-types/q/cache';
7
+ import type { JsonApiRelationship } from '@ember-data/store/-types/q/record-data-json-api';
8
+ import type { OpaqueRecordInstance } from '@ember-data/store/-types/q/record-instance';
9
+ import type { BaseFinderOptions } from '@ember-data/store/-types/q/store';
10
+ import type { StableRecordIdentifier } from '@warp-drive/core-types';
11
+ import type { CollectionRelationship } from '@warp-drive/core-types/cache/relationship';
12
+ import type { LocalRelationshipOperation } from '@warp-drive/core-types/graph';
13
+ import type { CollectionResourceRelationship, SingleResourceRelationship } from '@warp-drive/core-types/spec/raw';
14
+ import RelatedCollection from './many-array';
15
+ import type { MinimalLegacyRecord } from './model-methods';
16
+ import type { BelongsToProxyCreateArgs } from './promise-belongs-to';
17
+ import { PromiseBelongsTo } from './promise-belongs-to';
18
+ import type { HasManyProxyCreateArgs } from './promise-many-array';
19
+ import PromiseManyArray from './promise-many-array';
20
+ import BelongsToReference from './references/belongs-to';
21
+ import HasManyReference from './references/has-many';
22
+ export declare const LEGACY_SUPPORT: Map<StableRecordIdentifier | MinimalLegacyRecord, LegacySupport>;
23
+ export declare function lookupLegacySupport(record: MinimalLegacyRecord): LegacySupport;
24
+ export declare class LegacySupport {
25
+ record: MinimalLegacyRecord;
26
+ store: Store;
27
+ graph: Graph;
28
+ cache: Cache;
29
+ references: Record<string, BelongsToReference | HasManyReference>;
30
+ identifier: StableRecordIdentifier;
31
+ _manyArrayCache: Record<string, RelatedCollection>;
32
+ _relationshipPromisesCache: Record<string, Promise<RelatedCollection | OpaqueRecordInstance>>;
33
+ _relationshipProxyCache: Record<string, PromiseManyArray | PromiseBelongsTo | undefined>;
34
+ _pending: Record<string, Promise<StableRecordIdentifier | null> | undefined>;
35
+ isDestroying: boolean;
36
+ isDestroyed: boolean;
37
+ constructor(record: MinimalLegacyRecord);
38
+ _syncArray(array: RelatedCollection): void;
39
+ mutate(mutation: LocalRelationshipOperation): void;
40
+ _findBelongsTo(key: string, resource: SingleResourceRelationship, relationship: ResourceEdge, options?: BaseFinderOptions): Promise<OpaqueRecordInstance | null>;
41
+ reloadBelongsTo(key: string, options?: BaseFinderOptions): Promise<OpaqueRecordInstance | null>;
42
+ getBelongsTo(key: string, options?: BaseFinderOptions): PromiseBelongsTo | OpaqueRecordInstance | null;
43
+ setDirtyBelongsTo(key: string, value: OpaqueRecordInstance | null): void;
44
+ _getCurrentState(identifier: StableRecordIdentifier, field: string): [StableRecordIdentifier[], CollectionRelationship];
45
+ getManyArray<T>(key: string, definition?: UpgradedMeta): RelatedCollection<T>;
46
+ fetchAsyncHasMany(key: string, relationship: CollectionEdge, manyArray: RelatedCollection, options?: BaseFinderOptions): Promise<RelatedCollection>;
47
+ reloadHasMany(key: string, options?: BaseFinderOptions): Promise<unknown> | PromiseManyArray<unknown>;
48
+ getHasMany(key: string, options?: BaseFinderOptions): PromiseManyArray | RelatedCollection;
49
+ _updatePromiseProxyFor(kind: 'hasMany', key: string, args: HasManyProxyCreateArgs): PromiseManyArray;
50
+ _updatePromiseProxyFor(kind: 'belongsTo', key: string, args: BelongsToProxyCreateArgs): PromiseBelongsTo;
51
+ _updatePromiseProxyFor(kind: 'belongsTo', key: string, args: {
52
+ promise: Promise<OpaqueRecordInstance | null>;
53
+ }): PromiseBelongsTo;
54
+ referenceFor(kind: string | null, name: string): BelongsToReference<unknown, string, unknown> | HasManyReference<unknown, string, unknown>;
55
+ _findHasManyByJsonApiResource(resource: CollectionResourceRelationship, parentIdentifier: StableRecordIdentifier, relationship: CollectionEdge, options?: BaseFinderOptions): Promise<void | unknown[]> | void;
56
+ _findBelongsToByJsonApiResource(resource: SingleResourceRelationship, parentIdentifier: StableRecordIdentifier, relationship: ResourceEdge, options?: BaseFinderOptions): Promise<StableRecordIdentifier | null>;
57
+ destroy(): void;
58
+ }
59
+ export declare function areAllInverseRecordsLoaded(store: Store, resource: JsonApiRelationship): boolean;
60
+ //# sourceMappingURL=legacy-relationships-support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-relationships-support.d.ts","sourceRoot":"","sources":["../../src/-private/legacy-relationships-support.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAC9E,OAAO,KAAK,EAAE,KAAK,EAAa,MAAM,kCAAkC,CAAC;AAGzE,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAS3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iDAAiD,CAAC;AAC3F,OAAO,KAAK,EA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