@ember-data/model 5.5.0-alpha.2 → 5.5.0-alpha.21

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 (102) hide show
  1. package/LICENSE.md +19 -7
  2. package/README.md +21 -2
  3. package/addon-main.cjs +5 -0
  4. package/blueprints/model/index.js +18 -5
  5. package/blueprints/model-test/index.js +16 -10
  6. package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +4 -5
  7. package/dist/-private.js +3 -0
  8. package/{addon → dist}/-private.js.map +1 -1
  9. package/dist/has-many-CwEZBhUG.js +682 -0
  10. package/dist/has-many-CwEZBhUG.js.map +1 -0
  11. package/dist/hooks-C6_7V3O3.js +75 -0
  12. package/dist/hooks-C6_7V3O3.js.map +1 -0
  13. package/dist/hooks.js +2 -0
  14. package/{addon → dist}/hooks.js.map +1 -1
  15. package/dist/index.js +5 -0
  16. package/{addon → dist}/index.js.map +1 -1
  17. package/dist/migration-support.js +213 -0
  18. package/dist/migration-support.js.map +1 -0
  19. package/{addon/model-b638e17c.js → dist/model-B9PHp6Pe.js} +2555 -2455
  20. package/dist/model-B9PHp6Pe.js.map +1 -0
  21. package/dist/schema-provider-WdyaNQ3o.js +259 -0
  22. package/dist/schema-provider-WdyaNQ3o.js.map +1 -0
  23. package/logos/NCC-1701-a-blue.svg +4 -0
  24. package/logos/NCC-1701-a-gold.svg +4 -0
  25. package/logos/NCC-1701-a-gold_100.svg +1 -0
  26. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  27. package/logos/NCC-1701-a.svg +4 -0
  28. package/logos/README.md +4 -0
  29. package/logos/docs-badge.svg +2 -0
  30. package/logos/ember-data-logo-dark.svg +12 -0
  31. package/logos/ember-data-logo-light.svg +12 -0
  32. package/logos/github-header.svg +444 -0
  33. package/logos/social1.png +0 -0
  34. package/logos/social2.png +0 -0
  35. package/logos/warp-drive-logo-dark.svg +4 -0
  36. package/logos/warp-drive-logo-gold.svg +4 -0
  37. package/package.json +62 -58
  38. package/unstable-preview-types/-private/attr.d.ts +175 -0
  39. package/unstable-preview-types/-private/attr.d.ts.map +1 -0
  40. package/unstable-preview-types/-private/attr.type-test.d.ts +4 -0
  41. package/unstable-preview-types/-private/attr.type-test.d.ts.map +1 -0
  42. package/unstable-preview-types/-private/belongs-to.d.ts +181 -0
  43. package/unstable-preview-types/-private/belongs-to.d.ts.map +1 -0
  44. package/unstable-preview-types/-private/belongs-to.type-test.d.ts +4 -0
  45. package/unstable-preview-types/-private/belongs-to.type-test.d.ts.map +1 -0
  46. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +8 -0
  47. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
  48. package/unstable-preview-types/-private/errors.d.ts +303 -0
  49. package/unstable-preview-types/-private/errors.d.ts.map +1 -0
  50. package/unstable-preview-types/-private/has-many.d.ts +169 -0
  51. package/unstable-preview-types/-private/has-many.d.ts.map +1 -0
  52. package/unstable-preview-types/-private/has-many.type-test.d.ts +4 -0
  53. package/unstable-preview-types/-private/has-many.type-test.d.ts.map +1 -0
  54. package/unstable-preview-types/-private/hooks.d.ts +13 -0
  55. package/unstable-preview-types/-private/hooks.d.ts.map +1 -0
  56. package/unstable-preview-types/-private/legacy-relationships-support.d.ts +60 -0
  57. package/unstable-preview-types/-private/legacy-relationships-support.d.ts.map +1 -0
  58. package/unstable-preview-types/-private/model-for-mixin.d.ts +6 -0
  59. package/unstable-preview-types/-private/model-for-mixin.d.ts.map +1 -0
  60. package/unstable-preview-types/-private/model-methods.d.ts +37 -0
  61. package/unstable-preview-types/-private/model-methods.d.ts.map +1 -0
  62. package/unstable-preview-types/-private/model.d.ts +1303 -0
  63. package/unstable-preview-types/-private/model.d.ts.map +1 -0
  64. package/unstable-preview-types/-private/model.type-test.d.ts +4 -0
  65. package/unstable-preview-types/-private/model.type-test.d.ts.map +1 -0
  66. package/unstable-preview-types/-private/notify-changes.d.ts +8 -0
  67. package/unstable-preview-types/-private/notify-changes.d.ts.map +1 -0
  68. package/unstable-preview-types/-private/promise-belongs-to.d.ts +46 -0
  69. package/unstable-preview-types/-private/promise-belongs-to.d.ts.map +1 -0
  70. package/unstable-preview-types/-private/promise-many-array.d.ts +132 -0
  71. package/unstable-preview-types/-private/promise-many-array.d.ts.map +1 -0
  72. package/unstable-preview-types/-private/promise-proxy-base.d.ts +5 -0
  73. package/unstable-preview-types/-private/promise-proxy-base.d.ts.map +1 -0
  74. package/unstable-preview-types/-private/record-state.d.ts +80 -0
  75. package/unstable-preview-types/-private/record-state.d.ts.map +1 -0
  76. package/unstable-preview-types/-private/references/belongs-to.d.ts +503 -0
  77. package/unstable-preview-types/-private/references/belongs-to.d.ts.map +1 -0
  78. package/unstable-preview-types/-private/references/has-many.d.ts +515 -0
  79. package/unstable-preview-types/-private/references/has-many.d.ts.map +1 -0
  80. package/unstable-preview-types/-private/schema-provider.d.ts +65 -0
  81. package/unstable-preview-types/-private/schema-provider.d.ts.map +1 -0
  82. package/unstable-preview-types/-private/type-utils.d.ts +64 -0
  83. package/unstable-preview-types/-private/type-utils.d.ts.map +1 -0
  84. package/unstable-preview-types/-private/util.d.ts +8 -0
  85. package/unstable-preview-types/-private/util.d.ts.map +1 -0
  86. package/unstable-preview-types/-private.d.ts +13 -0
  87. package/unstable-preview-types/-private.d.ts.map +1 -0
  88. package/unstable-preview-types/hooks.d.ts +5 -0
  89. package/unstable-preview-types/hooks.d.ts.map +1 -0
  90. package/unstable-preview-types/index.d.ts +76 -0
  91. package/unstable-preview-types/index.d.ts.map +1 -0
  92. package/unstable-preview-types/migration-support.d.ts +64 -0
  93. package/unstable-preview-types/migration-support.d.ts.map +1 -0
  94. package/addon/-private.js +0 -2
  95. package/addon/has-many-774c4c4b.js +0 -507
  96. package/addon/has-many-774c4c4b.js.map +0 -1
  97. package/addon/hooks-6d5c2fc2.js +0 -157
  98. package/addon/hooks-6d5c2fc2.js.map +0 -1
  99. package/addon/hooks.js +0 -1
  100. package/addon/index.js +0 -3
  101. package/addon/model-b638e17c.js.map +0 -1
  102. package/addon-main.js +0 -93
@@ -0,0 +1,1303 @@
1
+ declare module '@ember-data/model/-private/model' {
2
+ /**
3
+ @module @ember-data/model
4
+ */
5
+ import EmberObject from '@ember/object';
6
+ import type { Snapshot } from '@ember-data/legacy-compat/-private';
7
+ import type Store from '@ember-data/store';
8
+ import type { StableRecordIdentifier } from '@warp-drive/core-types';
9
+ import type { Cache, ChangedAttributesHash } from '@warp-drive/core-types/cache';
10
+ import type { LegacyAttributeField, LegacyRelationshipField } from '@warp-drive/core-types/schema/fields';
11
+ import { RecordStore } from '@warp-drive/core-types/symbols';
12
+ import { Errors } from '@ember-data/model/-private/errors';
13
+ import type { MinimalLegacyRecord } from '@ember-data/model/-private/model-methods';
14
+ import RecordState from '@ember-data/model/-private/record-state';
15
+ import type BelongsToReference from '@ember-data/model/-private/references/belongs-to';
16
+ import type HasManyReference from '@ember-data/model/-private/references/has-many';
17
+ import type { _MaybeBelongsToFields, isSubClass, MaybeAttrFields, MaybeHasManyFields, MaybeRelationshipFields } from '@ember-data/model/-private/type-utils';
18
+ export type ModelCreateArgs = {
19
+ _createProps: Record<string, unknown>;
20
+ _secretInit: {
21
+ identifier: StableRecordIdentifier;
22
+ cache: Cache;
23
+ store: Store;
24
+ cb: (record: Model, cache: Cache, identifier: StableRecordIdentifier, store: Store) => void;
25
+ };
26
+ };
27
+ export type StaticModel = typeof Model & {
28
+ create(options: ModelCreateArgs): Model;
29
+ };
30
+ export type ModelFactory = {
31
+ class: StaticModel;
32
+ };
33
+ export type FactoryCache = Record<string, ModelFactory>;
34
+ export type ModelStore = Store & {
35
+ _modelFactoryCache: FactoryCache;
36
+ };
37
+ /**
38
+ Base class from which Models can be defined.
39
+
40
+ ```js
41
+ import Model, { attr } from '@ember-data/model';
42
+
43
+ export default class User extends Model {
44
+ @attr name;
45
+ }
46
+ ```
47
+
48
+ Models are used both to define the static schema for a
49
+ particular resource type as well as the class to instantiate
50
+ to present that data from cache.
51
+
52
+ @class Model
53
+ @public
54
+ @extends Ember.EmberObject
55
+ */
56
+ interface Model {
57
+ serialize<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): unknown;
58
+ destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<this>;
59
+ unloadRecord<T extends MinimalLegacyRecord>(this: T): void;
60
+ changedAttributes<T extends MinimalLegacyRecord>(this: T): ChangedAttributesHash;
61
+ rollbackAttributes<T extends MinimalLegacyRecord>(this: T): void;
62
+ _createSnapshot<T extends MinimalLegacyRecord>(this: T): Snapshot<T>;
63
+ save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<this>;
64
+ reload<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;
65
+ belongsTo<T extends Model, K extends keyof T & string>(this: T, prop: K & (K extends _MaybeBelongsToFields<T> ? K : never)): BelongsToReference<T, K>;
66
+ hasMany<T extends MinimalLegacyRecord, K extends MaybeHasManyFields<T>>(this: T, prop: K): HasManyReference<T, K>;
67
+ deleteRecord<T extends MinimalLegacyRecord>(this: T): void;
68
+ }
69
+ class Model extends EmberObject implements MinimalLegacyRecord {
70
+ store: Store;
71
+ ___recordState: RecordState;
72
+ ___private_notifications: object;
73
+ [RecordStore]: Store;
74
+ init(options: ModelCreateArgs): void;
75
+ destroy(): this;
76
+ /**
77
+ If this property is `true` the record is in the `empty`
78
+ state. Empty is the first state all records enter after they have
79
+ been created. Most records created by the store will quickly
80
+ transition to the `loading` state if data needs to be fetched from
81
+ the server or the `created` state if the record is created on the
82
+ client. A record can also enter the empty state if the adapter is
83
+ unable to locate the record.
84
+
85
+ @property isEmpty
86
+ @public
87
+ @type {Boolean}
88
+ @readOnly
89
+ */
90
+ get isEmpty(): boolean;
91
+ /**
92
+ If this property is `true` the record is in the `loading` state. A
93
+ record enters this state when the store asks the adapter for its
94
+ data. It remains in this state until the adapter provides the
95
+ requested data.
96
+
97
+ @property isLoading
98
+ @public
99
+ @type {Boolean}
100
+ @readOnly
101
+ */
102
+ get isLoading(): boolean;
103
+ /**
104
+ If this property is `true` the record is in the `loaded` state. A
105
+ record enters this state when its data is populated. Most of a
106
+ record's lifecycle is spent inside substates of the `loaded`
107
+ state.
108
+
109
+ Example
110
+
111
+ ```javascript
112
+ let record = store.createRecord('model');
113
+ record.isLoaded; // true
114
+
115
+ const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
116
+ model.isLoaded;
117
+ ```
118
+
119
+ @property isLoaded
120
+ @public
121
+ @type {Boolean}
122
+ @readOnly
123
+ */
124
+ get isLoaded(): boolean;
125
+ /**
126
+ If this property is `true` the record is in the `dirty` state. The
127
+ record has local changes that have not yet been saved by the
128
+ adapter. This includes records that have been created (but not yet
129
+ saved) or deleted.
130
+
131
+ Example
132
+
133
+ ```javascript
134
+ let record = store.createRecord('model');
135
+ record.hasDirtyAttributes; // true
136
+
137
+ const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
138
+
139
+ model.hasDirtyAttributes; // false
140
+ model.foo = 'some value';
141
+ model.hasDirtyAttributes; // true
142
+ ```
143
+
144
+ @since 1.13.0
145
+ @property hasDirtyAttributes
146
+ @public
147
+ @type {Boolean}
148
+ @readOnly
149
+ */
150
+ get hasDirtyAttributes(): boolean;
151
+ /**
152
+ If this property is `true` the record is in the `saving` state. A
153
+ record enters the saving state when `save` is called, but the
154
+ adapter has not yet acknowledged that the changes have been
155
+ persisted to the backend.
156
+
157
+ Example
158
+
159
+ ```javascript
160
+ let record = store.createRecord('model');
161
+ record.isSaving; // false
162
+ let promise = record.save();
163
+ record.isSaving; // true
164
+ promise.then(function() {
165
+ record.isSaving; // false
166
+ });
167
+ ```
168
+
169
+ @property isSaving
170
+ @public
171
+ @type {Boolean}
172
+ @readOnly
173
+ */
174
+ get isSaving(): boolean;
175
+ /**
176
+ If this property is `true` the record is in the `deleted` state
177
+ and has been marked for deletion. When `isDeleted` is true and
178
+ `hasDirtyAttributes` is true, the record is deleted locally but the deletion
179
+ was not yet persisted. When `isSaving` is true, the change is
180
+ in-flight. When both `hasDirtyAttributes` and `isSaving` are false, the
181
+ change has persisted.
182
+
183
+ Example
184
+
185
+ ```javascript
186
+ let record = store.createRecord('model');
187
+ record.isDeleted; // false
188
+ record.deleteRecord();
189
+
190
+ // Locally deleted
191
+ record.isDeleted; // true
192
+ record.hasDirtyAttributes; // true
193
+ record.isSaving; // false
194
+
195
+ // Persisting the deletion
196
+ let promise = record.save();
197
+ record.isDeleted; // true
198
+ record.isSaving; // true
199
+
200
+ // Deletion Persisted
201
+ promise.then(function() {
202
+ record.isDeleted; // true
203
+ record.isSaving; // false
204
+ record.hasDirtyAttributes; // false
205
+ });
206
+ ```
207
+
208
+ @property isDeleted
209
+ @public
210
+ @type {Boolean}
211
+ @readOnly
212
+ */
213
+ get isDeleted(): boolean;
214
+ /**
215
+ If this property is `true` the record is in the `new` state. A
216
+ record will be in the `new` state when it has been created on the
217
+ client and the adapter has not yet report that it was successfully
218
+ saved.
219
+
220
+ Example
221
+
222
+ ```javascript
223
+ let record = store.createRecord('model');
224
+ record.isNew; // true
225
+
226
+ record.save().then(function(model) {
227
+ model.isNew; // false
228
+ });
229
+ ```
230
+
231
+ @property isNew
232
+ @public
233
+ @type {Boolean}
234
+ @readOnly
235
+ */
236
+ get isNew(): boolean;
237
+ /**
238
+ If this property is `true` the record is in the `valid` state.
239
+
240
+ A record will be in the `valid` state when the adapter did not report any
241
+ server-side validation failures.
242
+
243
+ @property isValid
244
+ @public
245
+ @type {Boolean}
246
+ @readOnly
247
+ */
248
+ get isValid(): boolean;
249
+ /**
250
+ If the record is in the dirty state this property will report what
251
+ kind of change has caused it to move into the dirty
252
+ state. Possible values are:
253
+
254
+ - `created` The record has been created by the client and not yet saved to the adapter.
255
+ - `updated` The record has been updated by the client and not yet saved to the adapter.
256
+ - `deleted` The record has been deleted by the client and not yet saved to the adapter.
257
+
258
+ Example
259
+
260
+ ```javascript
261
+ let record = store.createRecord('model');
262
+ record.dirtyType; // 'created'
263
+ ```
264
+
265
+ @property dirtyType
266
+ @public
267
+ @type {String}
268
+ @readOnly
269
+ */
270
+ get dirtyType(): 'created' | 'updated' | 'deleted' | '';
271
+ /**
272
+ If `true` the adapter reported that it was unable to save local
273
+ changes to the backend for any reason other than a server-side
274
+ validation error.
275
+
276
+ Example
277
+
278
+ ```javascript
279
+ record.isError; // false
280
+ record.set('foo', 'valid value');
281
+ record.save().then(null, function() {
282
+ record.isError; // true
283
+ });
284
+ ```
285
+
286
+ @property isError
287
+ @public
288
+ @type {Boolean}
289
+ @readOnly
290
+ */
291
+ get isError(): boolean;
292
+ set isError(v: boolean);
293
+ /**
294
+ If `true` the store is attempting to reload the record from the adapter.
295
+
296
+ Example
297
+
298
+ ```javascript
299
+ record.isReloading; // false
300
+ record.reload();
301
+ record.isReloading; // true
302
+ ```
303
+
304
+ @property isReloading
305
+ @public
306
+ @type {Boolean}
307
+ @readOnly
308
+ */
309
+ isReloading: boolean;
310
+ /**
311
+ All ember models have an id property. This is an identifier
312
+ managed by an external source. These are always coerced to be
313
+ strings before being used internally. Note when declaring the
314
+ attributes for a model it is an error to an id
315
+ attribute.
316
+
317
+ ```javascript
318
+ let record = store.createRecord('model');
319
+ record.id; // null
320
+
321
+ const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));
322
+ model.id; // '1'
323
+ ```
324
+
325
+ @property id
326
+ @public
327
+ @type {String}
328
+ */
329
+ get id(): string | null;
330
+ set id(id: string | null);
331
+ toString(): string;
332
+ /**
333
+ @property currentState
334
+ @private
335
+ @type {Object}
336
+ */
337
+ get currentState(): RecordState;
338
+ set currentState(_v: RecordState);
339
+ /**
340
+ The store service instance which created this record instance
341
+
342
+ @property store
343
+ @public
344
+ */
345
+ /**
346
+ When the record is in the `invalid` state this object will contain
347
+ any errors returned by the adapter. When present the errors hash
348
+ contains keys corresponding to the invalid property names
349
+ and values which are arrays of Javascript objects with two keys:
350
+
351
+ - `message` A string containing the error message from the backend
352
+ - `attribute` The name of the property associated with this error message
353
+
354
+ ```javascript
355
+ record.errors.length; // 0
356
+ record.set('foo', 'invalid value');
357
+ record.save().catch(function() {
358
+ record.errors.foo;
359
+ // [{message: 'foo should be a number.', attribute: 'foo'}]
360
+ });
361
+ ```
362
+
363
+ The `errors` property is useful for displaying error messages to
364
+ the user.
365
+
366
+ ```handlebars
367
+ <label>Username: <Input @value={{@model.username}} /> </label>
368
+ {{#each @model.errors.username as |error|}}
369
+ <div class="error">
370
+ {{error.message}}
371
+ </div>
372
+ {{/each}}
373
+ <label>Email: <Input @value={{@model.email}} /> </label>
374
+ {{#each @model.errors.email as |error|}}
375
+ <div class="error">
376
+ {{error.message}}
377
+ </div>
378
+ {{/each}}
379
+ ```
380
+
381
+
382
+ You can also access the special `messages` property on the error
383
+ object to get an array of all the error strings.
384
+
385
+ ```handlebars
386
+ {{#each @model.errors.messages as |message|}}
387
+ <div class="error">
388
+ {{message}}
389
+ </div>
390
+ {{/each}}
391
+ ```
392
+
393
+ @property errors
394
+ @public
395
+ @type {Errors}
396
+ */
397
+ get errors(): Errors;
398
+ /**
399
+ This property holds the `AdapterError` object with which
400
+ last adapter operation was rejected.
401
+
402
+ @property adapterError
403
+ @public
404
+ @type {AdapterError}
405
+ */
406
+ get adapterError(): unknown;
407
+ set adapterError(v: unknown);
408
+ /**
409
+ Create a JSON representation of the record, using the serialization
410
+ strategy of the store's adapter.
411
+
412
+ `serialize` takes an optional hash as a parameter, currently
413
+ supported options are:
414
+
415
+ - `includeId`: `true` if the record's ID should be included in the
416
+ JSON representation.
417
+
418
+ @method serialize
419
+ @public
420
+ @param {Object} options
421
+ @return {Object} an object whose values are primitive JSON values only
422
+ */
423
+ notifyPropertyChange(prop: string): this;
424
+ /**
425
+ Marks the record as deleted but does not save it. You must call
426
+ `save` afterwards if you want to persist it. You might use this
427
+ method if you want to allow the user to still `rollbackAttributes()`
428
+ after a delete was made.
429
+
430
+ Example
431
+
432
+ ```js
433
+ import Component from '@glimmer/component';
434
+
435
+ export default class extends Component {
436
+ softDelete = () => {
437
+ this.args.model.deleteRecord();
438
+ }
439
+
440
+ confirm = () => {
441
+ this.args.model.save();
442
+ }
443
+
444
+ undo = () => {
445
+ this.args.model.rollbackAttributes();
446
+ }
447
+ }
448
+ ```
449
+
450
+ @method deleteRecord
451
+ @public
452
+ */
453
+ /**
454
+ Same as `deleteRecord`, but saves the record immediately.
455
+
456
+ Example
457
+
458
+ ```js
459
+ import Component from '@glimmer/component';
460
+
461
+ export default class extends Component {
462
+ delete = () => {
463
+ this.args.model.destroyRecord().then(function() {
464
+ this.transitionToRoute('model.index');
465
+ });
466
+ }
467
+ }
468
+ ```
469
+
470
+ If you pass an object on the `adapterOptions` property of the options
471
+ argument it will be passed to your adapter via the snapshot
472
+
473
+ ```js
474
+ record.destroyRecord({ adapterOptions: { subscribe: false } });
475
+ ```
476
+
477
+ ```app/adapters/post.js
478
+ import MyCustomAdapter from './custom-adapter';
479
+
480
+ export default class PostAdapter extends MyCustomAdapter {
481
+ deleteRecord(store, type, snapshot) {
482
+ if (snapshot.adapterOptions.subscribe) {
483
+ // ...
484
+ }
485
+ // ...
486
+ }
487
+ }
488
+ ```
489
+
490
+ @method destroyRecord
491
+ @public
492
+ @param {Object} options
493
+ @return {Promise} a promise that will be resolved when the adapter returns
494
+ successfully or rejected if the adapter returns with an error.
495
+ */
496
+ /**
497
+ Unloads the record from the store. This will not send a delete request
498
+ to your server, it just unloads the record from memory.
499
+
500
+ @method unloadRecord
501
+ @public
502
+ */
503
+ /**
504
+ Returns an object, whose keys are changed properties, and value is
505
+ an [oldProp, newProp] array.
506
+
507
+ The array represents the diff of the canonical state with the local state
508
+ of the model. Note: if the model is created locally, the canonical state is
509
+ empty since the adapter hasn't acknowledged the attributes yet:
510
+
511
+ Example
512
+
513
+ ```app/models/mascot.js
514
+ import Model, { attr } from '@ember-data/model';
515
+
516
+ export default class MascotModel extends Model {
517
+ @attr('string') name;
518
+ @attr('boolean', {
519
+ defaultValue: false
520
+ })
521
+ isAdmin;
522
+ }
523
+ ```
524
+
525
+ ```javascript
526
+ let mascot = store.createRecord('mascot');
527
+
528
+ mascot.changedAttributes(); // {}
529
+
530
+ mascot.set('name', 'Tomster');
531
+ mascot.changedAttributes(); // { name: [undefined, 'Tomster'] }
532
+
533
+ mascot.set('isAdmin', true);
534
+ mascot.changedAttributes(); // { isAdmin: [undefined, true], name: [undefined, 'Tomster'] }
535
+
536
+ mascot.save().then(function() {
537
+ mascot.changedAttributes(); // {}
538
+
539
+ mascot.set('isAdmin', false);
540
+ mascot.changedAttributes(); // { isAdmin: [true, false] }
541
+ });
542
+ ```
543
+
544
+ @method changedAttributes
545
+ @public
546
+ @return {Object} an object, whose keys are changed properties,
547
+ and value is an [oldProp, newProp] array.
548
+ */
549
+ /**
550
+ If the model `hasDirtyAttributes` this function will discard any unsaved
551
+ changes. If the model `isNew` it will be removed from the store.
552
+
553
+ Example
554
+
555
+ ```javascript
556
+ record.name; // 'Untitled Document'
557
+ record.set('name', 'Doc 1');
558
+ record.name; // 'Doc 1'
559
+ record.rollbackAttributes();
560
+ record.name; // 'Untitled Document'
561
+ ```
562
+
563
+ @since 1.13.0
564
+ @method rollbackAttributes
565
+ @public
566
+ */
567
+ /**
568
+ @method _createSnapshot
569
+ @private
570
+ */
571
+ /**
572
+ Save the record and persist any changes to the record to an
573
+ external source via the adapter.
574
+
575
+ Example
576
+
577
+ ```javascript
578
+ record.set('name', 'Tomster');
579
+ record.save().then(function() {
580
+ // Success callback
581
+ }, function() {
582
+ // Error callback
583
+ });
584
+ ```
585
+
586
+ If you pass an object using the `adapterOptions` property of the options
587
+ argument it will be passed to your adapter via the snapshot.
588
+
589
+ ```js
590
+ record.save({ adapterOptions: { subscribe: false } });
591
+ ```
592
+
593
+ ```app/adapters/post.js
594
+ import MyCustomAdapter from './custom-adapter';
595
+
596
+ export default class PostAdapter extends MyCustomAdapter {
597
+ updateRecord(store, type, snapshot) {
598
+ if (snapshot.adapterOptions.subscribe) {
599
+ // ...
600
+ }
601
+ // ...
602
+ }
603
+ }
604
+ ```
605
+
606
+ @method save
607
+ @public
608
+ @param {Object} options
609
+ @return {Promise} a promise that will be resolved when the adapter returns
610
+ successfully or rejected if the adapter returns with an error.
611
+ */
612
+ /**
613
+ Reload the record from the adapter.
614
+
615
+ This will only work if the record has already finished loading.
616
+
617
+ Example
618
+
619
+ ```js
620
+ import Component from '@glimmer/component';
621
+
622
+ export default class extends Component {
623
+ async reload = () => {
624
+ await this.args.model.reload();
625
+ // do something with the reloaded model
626
+ }
627
+ }
628
+ ```
629
+
630
+ @method reload
631
+ @public
632
+ @param {Object} options optional, may include `adapterOptions` hash which will be passed to adapter request
633
+
634
+ @return {Promise} a promise that will be resolved with the record when the
635
+ adapter returns successfully or rejected if the adapter returns
636
+ with an error.
637
+ */
638
+ attr(): void;
639
+ /**
640
+ Get the reference for the specified belongsTo relationship.
641
+
642
+ For instance, given the following model
643
+
644
+ ```app/models/blog-post.js
645
+ import Model, { belongsTo } from '@ember-data/model';
646
+
647
+ export default class BlogPost extends Model {
648
+ @belongsTo('user', { async: true, inverse: null }) author;
649
+ }
650
+ ```
651
+
652
+ Then the reference for the author relationship would be
653
+ retrieved from a record instance like so:
654
+
655
+ ```js
656
+ blogPost.belongsTo('author');
657
+ ```
658
+
659
+ A `BelongsToReference` is a low-level API that allows access
660
+ and manipulation of a belongsTo relationship.
661
+
662
+ It is especially useful when you're dealing with `async` relationships
663
+ as it allows synchronous access to the relationship data if loaded, as
664
+ well as APIs for loading, reloading the data or accessing available
665
+ information without triggering a load.
666
+
667
+ It may also be useful when using `sync` relationships that need to be
668
+ loaded/reloaded with more precise timing than marking the
669
+ relationship as `async` and relying on autofetch would have allowed.
670
+
671
+ However,keep in mind that marking a relationship as `async: false` will introduce
672
+ bugs into your application if the data is not always guaranteed to be available
673
+ by the time the relationship is accessed. Ergo, it is recommended when using this
674
+ approach to utilize `links` for unloaded relationship state instead of identifiers.
675
+
676
+ Reference APIs are entangled with the relationship's underlying state,
677
+ thus any getters or cached properties that utilize these will properly
678
+ invalidate if the relationship state changes.
679
+
680
+ References are "stable", meaning that multiple calls to retrieve the reference
681
+ for a given relationship will always return the same HasManyReference.
682
+
683
+ @method belongsTo
684
+ @public
685
+ @param {String} name of the relationship
686
+ @since 2.5.0
687
+ @return {BelongsToReference} reference for this relationship
688
+ */
689
+ /**
690
+ Get the reference for the specified hasMany relationship.
691
+
692
+ For instance, given the following model
693
+
694
+ ```app/models/blog-post.js
695
+ import Model, { hasMany } from '@ember-data/model';
696
+
697
+ export default class BlogPost extends Model {
698
+ @hasMany('comment', { async: true, inverse: null }) comments;
699
+ }
700
+ ```
701
+
702
+ Then the reference for the comments relationship would be
703
+ retrieved from a record instance like so:
704
+
705
+ ```js
706
+ blogPost.hasMany('comments');
707
+ ```
708
+
709
+ A `HasManyReference` is a low-level API that allows access
710
+ and manipulation of a hasMany relationship.
711
+
712
+ It is especially useful when you are dealing with `async` relationships
713
+ as it allows synchronous access to the relationship data if loaded, as
714
+ well as APIs for loading, reloading the data or accessing available
715
+ information without triggering a load.
716
+
717
+ It may also be useful when using `sync` relationships with `@ember-data/model`
718
+ that need to be loaded/reloaded with more precise timing than marking the
719
+ relationship as `async` and relying on autofetch would have allowed.
720
+
721
+ However,keep in mind that marking a relationship as `async: false` will introduce
722
+ bugs into your application if the data is not always guaranteed to be available
723
+ by the time the relationship is accessed. Ergo, it is recommended when using this
724
+ approach to utilize `links` for unloaded relationship state instead of identifiers.
725
+
726
+ Reference APIs are entangled with the relationship's underlying state,
727
+ thus any getters or cached properties that utilize these will properly
728
+ invalidate if the relationship state changes.
729
+
730
+ References are "stable", meaning that multiple calls to retrieve the reference
731
+ for a given relationship will always return the same HasManyReference.
732
+
733
+ @method hasMany
734
+ @public
735
+ @param {String} name of the relationship
736
+ @since 2.5.0
737
+ @return {HasManyReference} reference for this relationship
738
+ */
739
+ /**
740
+ Given a callback, iterates over each of the relationships in the model,
741
+ invoking the callback with the name of each relationship and its relationship
742
+ descriptor.
743
+
744
+
745
+ The callback method you provide should have the following signature (all
746
+ parameters are optional):
747
+
748
+ ```javascript
749
+ function(name, descriptor);
750
+ ```
751
+
752
+ - `name` the name of the current property in the iteration
753
+ - `descriptor` the meta object that describes this relationship
754
+
755
+ The relationship descriptor argument is an object with the following properties.
756
+
757
+ - **name** <span class="type">String</span> the name of this relationship on the Model
758
+ - **kind** <span class="type">String</span> "hasMany" or "belongsTo"
759
+ - **options** <span class="type">Object</span> the original options hash passed when the relationship was declared
760
+ - **parentType** <span class="type">Model</span> the type of the Model that owns this relationship
761
+ - **type** <span class="type">String</span> the type name of the related Model
762
+
763
+ Note that in addition to a callback, you can also pass an optional target
764
+ object that will be set as `this` on the context.
765
+
766
+ Example
767
+
768
+ ```app/serializers/application.js
769
+ import JSONSerializer from '@ember-data/serializer/json';
770
+
771
+ export default class ApplicationSerializer extends JSONSerializer {
772
+ serialize(record, options) {
773
+ let json = {};
774
+
775
+ record.eachRelationship(function(name, descriptor) {
776
+ if (descriptor.kind === 'hasMany') {
777
+ let serializedHasManyName = name.toUpperCase() + '_IDS';
778
+ json[serializedHasManyName] = record.get(name).map(r => r.id);
779
+ }
780
+ });
781
+
782
+ return json;
783
+ }
784
+ }
785
+ ```
786
+
787
+ @method eachRelationship
788
+ @public
789
+ @param {Function} callback the callback to invoke
790
+ @param {any} binding the value to which the callback's `this` should be bound
791
+ */
792
+ eachRelationship<T>(callback: (this: NoInfer<T> | undefined, key: MaybeRelationshipFields<this>, meta: LegacyRelationshipField) => void, binding?: T): void;
793
+ relationshipFor(name: string): LegacyRelationshipField | undefined;
794
+ inverseFor(name: string): LegacyRelationshipField | null;
795
+ eachAttribute<T>(callback: (this: NoInfer<T> | undefined, key: isSubClass<this> extends true ? MaybeAttrFields<this> : string, meta: LegacyAttributeField) => void, binding?: T): void;
796
+ static isModel: boolean;
797
+ /**
798
+ Create should only ever be called by the store. To create an instance of a
799
+ `Model` in a dirty state use `store.createRecord`.
800
+
801
+ To create instances of `Model` in a clean state, use `store.push`
802
+
803
+ @method create
804
+ @private
805
+ @static
806
+ */
807
+ /**
808
+ Represents the model's class name as a string. This can be used to look up the model's class name through
809
+ `Store`'s modelFor method.
810
+
811
+ `modelName` is generated for you by EmberData. It will be a lowercased, dasherized string.
812
+ For example:
813
+
814
+ ```javascript
815
+ store.modelFor('post').modelName; // 'post'
816
+ store.modelFor('blog-post').modelName; // 'blog-post'
817
+ ```
818
+
819
+ The most common place you'll want to access `modelName` is in your serializer's `payloadKeyFromModelName` method. For example, to change payload
820
+ keys to underscore (instead of dasherized), you might use the following code:
821
+
822
+ ```javascript
823
+ import RESTSerializer from '@ember-data/serializer/rest';
824
+ import { underscore } from '<app-name>/utils/string-utils';
825
+
826
+ export default const PostSerializer = RESTSerializer.extend({
827
+ payloadKeyFromModelName(modelName) {
828
+ return underscore(modelName);
829
+ }
830
+ });
831
+ ```
832
+ @property modelName
833
+ @public
834
+ @type String
835
+ @readonly
836
+ @static
837
+ */
838
+ static modelName: string;
839
+ /**
840
+ For a given relationship name, returns the model type of the relationship.
841
+
842
+ For example, if you define a model like this:
843
+
844
+ ```app/models/post.js
845
+ import Model, { hasMany } from '@ember-data/model';
846
+
847
+ export default class PostModel extends Model {
848
+ @hasMany('comment') comments;
849
+ }
850
+ ```
851
+
852
+ Calling `store.modelFor('post').typeForRelationship('comments', store)` will return `Comment`.
853
+
854
+ @method typeForRelationship
855
+ @public
856
+ @static
857
+ @param {String} name the name of the relationship
858
+ @param {store} store an instance of Store
859
+ @return {Model} the type of the relationship, or undefined
860
+ */
861
+ static typeForRelationship(name: string, store: Store): import("@ember-data/store/types").ModelSchema<unknown> | undefined;
862
+ static get inverseMap(): Record<string, LegacyRelationshipField | null>;
863
+ /**
864
+ Find the relationship which is the inverse of the one asked for.
865
+
866
+ For example, if you define models like this:
867
+
868
+ ```app/models/post.js
869
+ import Model, { hasMany } from '@ember-data/model';
870
+
871
+ export default class PostModel extends Model {
872
+ @hasMany('message') comments;
873
+ }
874
+ ```
875
+
876
+ ```app/models/message.js
877
+ import Model, { belongsTo } from '@ember-data/model';
878
+
879
+ export default class MessageModel extends Model {
880
+ @belongsTo('post') owner;
881
+ }
882
+ ```
883
+
884
+ ``` js
885
+ store.modelFor('post').inverseFor('comments', store) // { type: 'message', name: 'owner', kind: 'belongsTo' }
886
+ store.modelFor('message').inverseFor('owner', store) // { type: 'post', name: 'comments', kind: 'hasMany' }
887
+ ```
888
+
889
+ @method inverseFor
890
+ @public
891
+ @static
892
+ @param {String} name the name of the relationship
893
+ @param {Store} store
894
+ @return {Object} the inverse relationship, or null
895
+ */
896
+ static inverseFor(name: string, store: Store): LegacyRelationshipField | null;
897
+ static _findInverseFor(name: string, store: Store): LegacyRelationshipField | null;
898
+ /**
899
+ The model's relationships as a map, keyed on the type of the
900
+ relationship. The value of each entry is an array containing a descriptor
901
+ for each relationship with that type, describing the name of the relationship
902
+ as well as the type.
903
+
904
+ For example, given the following model definition:
905
+
906
+ ```app/models/blog.js
907
+ import Model, { belongsTo, hasMany } from '@ember-data/model';
908
+
909
+ export default class BlogModel extends Model {
910
+ @hasMany('user') users;
911
+ @belongsTo('user') owner;
912
+ @hasMany('post') posts;
913
+ }
914
+ ```
915
+
916
+ This computed property would return a map describing these
917
+ relationships, like this:
918
+
919
+ ```javascript
920
+ import Blog from 'app/models/blog';
921
+ import User from 'app/models/user';
922
+ import Post from 'app/models/post';
923
+
924
+ let relationships = Blog.relationships;
925
+ relationships.user;
926
+ //=> [ { name: 'users', kind: 'hasMany' },
927
+ // { name: 'owner', kind: 'belongsTo' } ]
928
+ relationships.post;
929
+ //=> [ { name: 'posts', kind: 'hasMany' } ]
930
+ ```
931
+
932
+ @property relationships
933
+ @public
934
+ @static
935
+ @type Map
936
+ @readOnly
937
+ */
938
+ static get relationships(): Map<string, LegacyRelationshipField[]>;
939
+ /**
940
+ A hash containing lists of the model's relationships, grouped
941
+ by the relationship kind. For example, given a model with this
942
+ definition:
943
+
944
+ ```app/models/blog.js
945
+ import Model, { belongsTo, hasMany } from '@ember-data/model';
946
+
947
+ export default class BlogModel extends Model {
948
+ @hasMany('user') users;
949
+ @belongsTo('user') owner;
950
+
951
+ @hasMany('post') posts;
952
+ }
953
+ ```
954
+
955
+ This property would contain the following:
956
+
957
+ ```javascript
958
+ import Blog from 'app/models/blog';
959
+
960
+ let relationshipNames = Blog.relationshipNames;
961
+ relationshipNames.hasMany;
962
+ //=> ['users', 'posts']
963
+ relationshipNames.belongsTo;
964
+ //=> ['owner']
965
+ ```
966
+
967
+ @property relationshipNames
968
+ @public
969
+ @static
970
+ @type Object
971
+ @readOnly
972
+ */
973
+ static get relationshipNames(): {
974
+ hasMany: string[];
975
+ belongsTo: string[];
976
+ };
977
+ /**
978
+ An array of types directly related to a model. Each type will be
979
+ included once, regardless of the number of relationships it has with
980
+ the model.
981
+
982
+ For example, given a model with this definition:
983
+
984
+ ```app/models/blog.js
985
+ import Model, { belongsTo, hasMany } from '@ember-data/model';
986
+
987
+ export default class BlogModel extends Model {
988
+ @hasMany('user') users;
989
+ @belongsTo('user') owner;
990
+
991
+ @hasMany('post') posts;
992
+ }
993
+ ```
994
+
995
+ This property would contain the following:
996
+
997
+ ```javascript
998
+ import Blog from 'app/models/blog';
999
+
1000
+ let relatedTypes = Blog.relatedTypes');
1001
+ //=> ['user', 'post']
1002
+ ```
1003
+
1004
+ @property relatedTypes
1005
+ @public
1006
+ @static
1007
+ @type Array
1008
+ @readOnly
1009
+ */
1010
+ static get relatedTypes(): string[];
1011
+ /**
1012
+ A map whose keys are the relationships of a model and whose values are
1013
+ relationship descriptors.
1014
+
1015
+ For example, given a model with this
1016
+ definition:
1017
+
1018
+ ```app/models/blog.js
1019
+ import Model, { belongsTo, hasMany } from '@ember-data/model';
1020
+
1021
+ export default class BlogModel extends Model {
1022
+ @hasMany('user') users;
1023
+ @belongsTo('user') owner;
1024
+
1025
+ @hasMany('post') posts;
1026
+ }
1027
+ ```
1028
+
1029
+ This property would contain the following:
1030
+
1031
+ ```javascript
1032
+ import Blog from 'app/models/blog';
1033
+
1034
+ let relationshipsByName = Blog.relationshipsByName;
1035
+ relationshipsByName.users;
1036
+ //=> { name: 'users', kind: 'hasMany', type: 'user', options: Object }
1037
+ relationshipsByName.owner;
1038
+ //=> { name: 'owner', kind: 'belongsTo', type: 'user', options: Object }
1039
+ ```
1040
+
1041
+ @property relationshipsByName
1042
+ @public
1043
+ @static
1044
+ @type Map
1045
+ @readOnly
1046
+ */
1047
+ static get relationshipsByName(): Map<string, LegacyRelationshipField>;
1048
+ static get relationshipsObject(): Record<string, LegacyRelationshipField>;
1049
+ /**
1050
+ A map whose keys are the fields of the model and whose values are strings
1051
+ describing the kind of the field. A model's fields are the union of all of its
1052
+ attributes and relationships.
1053
+
1054
+ For example:
1055
+
1056
+ ```app/models/blog.js
1057
+ import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
1058
+
1059
+ export default class BlogModel extends Model {
1060
+ @hasMany('user') users;
1061
+ @belongsTo('user') owner;
1062
+
1063
+ @hasMany('post') posts;
1064
+
1065
+ @attr('string') title;
1066
+ }
1067
+ ```
1068
+
1069
+ ```js
1070
+ import Blog from 'app/models/blog'
1071
+
1072
+ let fields = Blog.fields;
1073
+ fields.forEach(function(kind, field) {
1074
+ // do thing
1075
+ });
1076
+
1077
+ // prints:
1078
+ // users, hasMany
1079
+ // owner, belongsTo
1080
+ // posts, hasMany
1081
+ // title, attribute
1082
+ ```
1083
+
1084
+ @property fields
1085
+ @public
1086
+ @static
1087
+ @type Map
1088
+ @readOnly
1089
+ */
1090
+ static get fields(): Map<string, 'attribute' | 'belongsTo' | 'hasMany'>;
1091
+ /**
1092
+ Given a callback, iterates over each of the relationships in the model,
1093
+ invoking the callback with the name of each relationship and its relationship
1094
+ descriptor.
1095
+
1096
+ @method eachRelationship
1097
+ @public
1098
+ @static
1099
+ @param {Function} callback the callback to invoke
1100
+ @param {any} binding the value to which the callback's `this` should be bound
1101
+ */
1102
+ static eachRelationship<T, Schema extends Model>(callback: (this: T | undefined, key: MaybeRelationshipFields<Schema>, relationship: LegacyRelationshipField) => void, binding?: T): void;
1103
+ /**
1104
+ Given a callback, iterates over each of the types related to a model,
1105
+ invoking the callback with the related type's class. Each type will be
1106
+ returned just once, regardless of how many different relationships it has
1107
+ with a model.
1108
+
1109
+ @method eachRelatedType
1110
+ @public
1111
+ @static
1112
+ @param {Function} callback the callback to invoke
1113
+ @param {any} binding the value to which the callback's `this` should be bound
1114
+ */
1115
+ static eachRelatedType<T>(callback: (this: T | undefined, type: string) => void, binding?: T): void;
1116
+ /**
1117
+ *
1118
+ * @method determineRelationshipType
1119
+ * @private
1120
+ * @deprecated
1121
+ */
1122
+ static determineRelationshipType(knownSide: LegacyRelationshipField, store: Store): 'oneToOne' | 'oneToMany' | 'manyToOne' | 'manyToMany' | 'oneToNone' | 'manyToNone';
1123
+ /**
1124
+ A map whose keys are the attributes of the model (properties
1125
+ described by attr) and whose values are the meta object for the
1126
+ property.
1127
+
1128
+ Example
1129
+
1130
+ ```app/models/person.js
1131
+ import Model, { attr } from '@ember-data/model';
1132
+
1133
+ export default class PersonModel extends Model {
1134
+ @attr('string') firstName;
1135
+ @attr('string') lastName;
1136
+ @attr('date') birthday;
1137
+ }
1138
+ ```
1139
+
1140
+ ```javascript
1141
+ import Person from 'app/models/person'
1142
+
1143
+ let attributes = Person.attributes
1144
+
1145
+ attributes.forEach(function(meta, name) {
1146
+ // do thing
1147
+ });
1148
+
1149
+ // prints:
1150
+ // firstName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "firstName"}
1151
+ // lastName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "lastName"}
1152
+ // birthday {type: "date", kind: 'attribute', options: Object, parentType: function, name: "birthday"}
1153
+ ```
1154
+
1155
+ @property attributes
1156
+ @public
1157
+ @static
1158
+ @type {Map}
1159
+ @readOnly
1160
+ */
1161
+ static get attributes(): Map<string, LegacyAttributeField>;
1162
+ /**
1163
+ A map whose keys are the attributes of the model (properties
1164
+ described by attr) and whose values are type of transformation
1165
+ applied to each attribute. This map does not include any
1166
+ attributes that do not have an transformation type.
1167
+
1168
+ Example
1169
+
1170
+ ```app/models/person.js
1171
+ import Model, { attr } from '@ember-data/model';
1172
+
1173
+ export default class PersonModel extends Model {
1174
+ @attr firstName;
1175
+ @attr('string') lastName;
1176
+ @attr('date') birthday;
1177
+ }
1178
+ ```
1179
+
1180
+ ```javascript
1181
+ import Person from 'app/models/person';
1182
+
1183
+ let transformedAttributes = Person.transformedAttributes
1184
+
1185
+ transformedAttributes.forEach(function(field, type) {
1186
+ // do thing
1187
+ });
1188
+
1189
+ // prints:
1190
+ // lastName string
1191
+ // birthday date
1192
+ ```
1193
+
1194
+ @property transformedAttributes
1195
+ @public
1196
+ @static
1197
+ @type {Map}
1198
+ @readOnly
1199
+ */
1200
+ static get transformedAttributes(): Map<string, string>;
1201
+ /**
1202
+ Iterates through the attributes of the model, calling the passed function on each
1203
+ attribute.
1204
+
1205
+ The callback method you provide should have the following signature (all
1206
+ parameters are optional):
1207
+
1208
+ ```javascript
1209
+ function(name, meta);
1210
+ ```
1211
+
1212
+ - `name` the name of the current property in the iteration
1213
+ - `meta` the meta object for the attribute property in the iteration
1214
+
1215
+ Note that in addition to a callback, you can also pass an optional target
1216
+ object that will be set as `this` on the context.
1217
+
1218
+ Example
1219
+
1220
+ ```javascript
1221
+ import Model, { attr } from '@ember-data/model';
1222
+
1223
+ class PersonModel extends Model {
1224
+ @attr('string') firstName;
1225
+ @attr('string') lastName;
1226
+ @attr('date') birthday;
1227
+ }
1228
+
1229
+ PersonModel.eachAttribute(function(name, meta) {
1230
+ // do thing
1231
+ });
1232
+
1233
+ // prints:
1234
+ // firstName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "firstName"}
1235
+ // lastName {type: "string", kind: 'attribute', options: Object, parentType: function, name: "lastName"}
1236
+ // birthday {type: "date", kind: 'attribute', options: Object, parentType: function, name: "birthday"}
1237
+ ```
1238
+
1239
+ @method eachAttribute
1240
+ @public
1241
+ @param {Function} callback The callback to execute
1242
+ @param {Object} [binding] the value to which the callback's `this` should be bound
1243
+ @static
1244
+ */
1245
+ static eachAttribute<T, Schema extends Model>(callback: (this: T | undefined, key: MaybeAttrFields<Schema>, attribute: LegacyAttributeField) => void, binding?: T): void;
1246
+ /**
1247
+ Iterates through the transformedAttributes of the model, calling
1248
+ the passed function on each attribute. Note the callback will not be
1249
+ called for any attributes that do not have an transformation type.
1250
+
1251
+ The callback method you provide should have the following signature (all
1252
+ parameters are optional):
1253
+
1254
+ ```javascript
1255
+ function(name, type);
1256
+ ```
1257
+
1258
+ - `name` the name of the current property in the iteration
1259
+ - `type` a string containing the name of the type of transformed
1260
+ applied to the attribute
1261
+
1262
+ Note that in addition to a callback, you can also pass an optional target
1263
+ object that will be set as `this` on the context.
1264
+
1265
+ Example
1266
+
1267
+ ```javascript
1268
+ import Model, { attr } from '@ember-data/model';
1269
+
1270
+ let Person = Model.extend({
1271
+ firstName: attr(),
1272
+ lastName: attr('string'),
1273
+ birthday: attr('date')
1274
+ });
1275
+
1276
+ Person.eachTransformedAttribute(function(name, type) {
1277
+ // do thing
1278
+ });
1279
+
1280
+ // prints:
1281
+ // lastName string
1282
+ // birthday date
1283
+ ```
1284
+
1285
+ @method eachTransformedAttribute
1286
+ @public
1287
+ @param {Function} callback The callback to execute
1288
+ @param {Object} [binding] the value to which the callback's `this` should be bound
1289
+ @static
1290
+ */
1291
+ static eachTransformedAttribute<T, Schema extends Model>(callback: (this: T | undefined, key: Exclude<keyof Schema & string, keyof Model & string>, type: string) => void, binding?: T): void;
1292
+ /**
1293
+ Returns the name of the model class.
1294
+
1295
+ @method toString
1296
+ @public
1297
+ @static
1298
+ */
1299
+ static toString(): string;
1300
+ }
1301
+ export { Model };
1302
+ }
1303
+ //# sourceMappingURL=model.d.ts.map