@ember-data/model 5.3.3 → 5.3.4

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