@warp-drive/legacy 5.6.0-alpha.15 → 5.6.0-alpha.18

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