@warp-drive/legacy 5.6.0-alpha.11

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 (211) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +23 -0
  3. package/README.md +54 -0
  4. package/addon-main.cjs +5 -0
  5. package/declarations/adapter/-private/build-url-mixin.d.ts +34 -0
  6. package/declarations/adapter/-private/build-url-mixin.d.ts.map +1 -0
  7. package/declarations/adapter/-private/fastboot-interface.d.ts +9 -0
  8. package/declarations/adapter/-private/fastboot-interface.d.ts.map +1 -0
  9. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +8 -0
  10. package/declarations/adapter/-private/utils/continue-on-reject.d.ts.map +1 -0
  11. package/declarations/adapter/-private/utils/determine-body-promise.d.ts +5 -0
  12. package/declarations/adapter/-private/utils/determine-body-promise.d.ts.map +1 -0
  13. package/declarations/adapter/-private/utils/fetch.d.ts +9 -0
  14. package/declarations/adapter/-private/utils/fetch.d.ts.map +1 -0
  15. package/declarations/adapter/-private/utils/parse-response-headers.d.ts +2 -0
  16. package/declarations/adapter/-private/utils/parse-response-headers.d.ts.map +1 -0
  17. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +7 -0
  18. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts.map +1 -0
  19. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +6 -0
  20. package/declarations/adapter/-private/utils/serialize-query-params.d.ts.map +1 -0
  21. package/declarations/adapter/-private.d.ts +6 -0
  22. package/declarations/adapter/-private.d.ts.map +1 -0
  23. package/declarations/adapter/error.d.ts +188 -0
  24. package/declarations/adapter/error.d.ts.map +1 -0
  25. package/declarations/adapter/json-api.d.ts +234 -0
  26. package/declarations/adapter/json-api.d.ts.map +1 -0
  27. package/declarations/adapter/rest.d.ts +823 -0
  28. package/declarations/adapter/rest.d.ts.map +1 -0
  29. package/declarations/adapter.d.ts +801 -0
  30. package/declarations/adapter.d.ts.map +1 -0
  31. package/declarations/compat/-private.d.ts +14 -0
  32. package/declarations/compat/-private.d.ts.map +1 -0
  33. package/declarations/compat/builders/find-all.d.ts +33 -0
  34. package/declarations/compat/builders/find-all.d.ts.map +1 -0
  35. package/declarations/compat/builders/find-record.d.ts +54 -0
  36. package/declarations/compat/builders/find-record.d.ts.map +1 -0
  37. package/declarations/compat/builders/query.d.ts +61 -0
  38. package/declarations/compat/builders/query.d.ts.map +1 -0
  39. package/declarations/compat/builders/save-record.d.ts +32 -0
  40. package/declarations/compat/builders/save-record.d.ts.map +1 -0
  41. package/declarations/compat/builders/utils.d.ts +4 -0
  42. package/declarations/compat/builders/utils.d.ts.map +1 -0
  43. package/declarations/compat/builders.d.ts +15 -0
  44. package/declarations/compat/builders.d.ts.map +1 -0
  45. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +47 -0
  46. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +1 -0
  47. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +3 -0
  48. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +1 -0
  49. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +12 -0
  50. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -0
  51. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +6 -0
  52. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +1 -0
  53. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +3 -0
  54. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +1 -0
  55. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +527 -0
  56. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -0
  57. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +224 -0
  58. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -0
  59. package/declarations/compat/legacy-network-handler/serializer-response.d.ts +7 -0
  60. package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +1 -0
  61. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +89 -0
  62. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +1 -0
  63. package/declarations/compat/legacy-network-handler/snapshot.d.ts +237 -0
  64. package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +1 -0
  65. package/declarations/compat/utils.d.ts +138 -0
  66. package/declarations/compat/utils.d.ts.map +1 -0
  67. package/declarations/compat.d.ts +134 -0
  68. package/declarations/compat.d.ts.map +1 -0
  69. package/declarations/model/-private/attr.d.ts +165 -0
  70. package/declarations/model/-private/attr.d.ts.map +1 -0
  71. package/declarations/model/-private/attr.type-test.d.ts +2 -0
  72. package/declarations/model/-private/attr.type-test.d.ts.map +1 -0
  73. package/declarations/model/-private/belongs-to.d.ts +173 -0
  74. package/declarations/model/-private/belongs-to.d.ts.map +1 -0
  75. package/declarations/model/-private/belongs-to.type-test.d.ts +2 -0
  76. package/declarations/model/-private/belongs-to.type-test.d.ts.map +1 -0
  77. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +6 -0
  78. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
  79. package/declarations/model/-private/errors.d.ts +290 -0
  80. package/declarations/model/-private/errors.d.ts.map +1 -0
  81. package/declarations/model/-private/has-many.d.ts +164 -0
  82. package/declarations/model/-private/has-many.d.ts.map +1 -0
  83. package/declarations/model/-private/has-many.type-test.d.ts +2 -0
  84. package/declarations/model/-private/has-many.type-test.d.ts.map +1 -0
  85. package/declarations/model/-private/hooks.d.ts +11 -0
  86. package/declarations/model/-private/hooks.d.ts.map +1 -0
  87. package/declarations/model/-private/legacy-relationships-support.d.ts +57 -0
  88. package/declarations/model/-private/legacy-relationships-support.d.ts.map +1 -0
  89. package/declarations/model/-private/model-for-mixin.d.ts +4 -0
  90. package/declarations/model/-private/model-for-mixin.d.ts.map +1 -0
  91. package/declarations/model/-private/model-methods.d.ts +35 -0
  92. package/declarations/model/-private/model-methods.d.ts.map +1 -0
  93. package/declarations/model/-private/model.d.ts +1270 -0
  94. package/declarations/model/-private/model.d.ts.map +1 -0
  95. package/declarations/model/-private/model.type-test.d.ts +2 -0
  96. package/declarations/model/-private/model.type-test.d.ts.map +1 -0
  97. package/declarations/model/-private/notify-changes.d.ts +5 -0
  98. package/declarations/model/-private/notify-changes.d.ts.map +1 -0
  99. package/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  100. package/declarations/model/-private/promise-belongs-to.d.ts.map +1 -0
  101. package/declarations/model/-private/promise-many-array.d.ts +126 -0
  102. package/declarations/model/-private/promise-many-array.d.ts.map +1 -0
  103. package/declarations/model/-private/promise-proxy-base.d.ts +3 -0
  104. package/declarations/model/-private/promise-proxy-base.d.ts.map +1 -0
  105. package/declarations/model/-private/record-state.d.ts +78 -0
  106. package/declarations/model/-private/record-state.d.ts.map +1 -0
  107. package/declarations/model/-private/references/belongs-to.d.ts +495 -0
  108. package/declarations/model/-private/references/belongs-to.d.ts.map +1 -0
  109. package/declarations/model/-private/references/has-many.d.ts +504 -0
  110. package/declarations/model/-private/references/has-many.d.ts.map +1 -0
  111. package/declarations/model/-private/schema-provider.d.ts +63 -0
  112. package/declarations/model/-private/schema-provider.d.ts.map +1 -0
  113. package/declarations/model/-private/type-utils.d.ts +57 -0
  114. package/declarations/model/-private/type-utils.d.ts.map +1 -0
  115. package/declarations/model/-private/util.d.ts +6 -0
  116. package/declarations/model/-private/util.d.ts.map +1 -0
  117. package/declarations/model/-private.d.ts +8 -0
  118. package/declarations/model/-private.d.ts.map +1 -0
  119. package/declarations/model/migration-support.d.ts +287 -0
  120. package/declarations/model/migration-support.d.ts.map +1 -0
  121. package/declarations/model/migration-support.type-test.d.ts +2 -0
  122. package/declarations/model/migration-support.type-test.d.ts.map +1 -0
  123. package/declarations/model.d.ts +50 -0
  124. package/declarations/model.d.ts.map +1 -0
  125. package/declarations/serializer/-private/embedded-records-mixin.d.ts +97 -0
  126. package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +1 -0
  127. package/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  128. package/declarations/serializer/-private/transforms/boolean.d.ts.map +1 -0
  129. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +2 -0
  130. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +1 -0
  131. package/declarations/serializer/-private/transforms/date.d.ts +28 -0
  132. package/declarations/serializer/-private/transforms/date.d.ts.map +1 -0
  133. package/declarations/serializer/-private/transforms/number.d.ts +29 -0
  134. package/declarations/serializer/-private/transforms/number.d.ts.map +1 -0
  135. package/declarations/serializer/-private/transforms/string.d.ts +29 -0
  136. package/declarations/serializer/-private/transforms/string.d.ts.map +1 -0
  137. package/declarations/serializer/-private/transforms/transform.d.ts +119 -0
  138. package/declarations/serializer/-private/transforms/transform.d.ts.map +1 -0
  139. package/declarations/serializer/-private/utils.d.ts +4 -0
  140. package/declarations/serializer/-private/utils.d.ts.map +1 -0
  141. package/declarations/serializer/json-api.d.ts +496 -0
  142. package/declarations/serializer/json-api.d.ts.map +1 -0
  143. package/declarations/serializer/json.d.ts +1047 -0
  144. package/declarations/serializer/json.d.ts.map +1 -0
  145. package/declarations/serializer/rest.d.ts +554 -0
  146. package/declarations/serializer/rest.d.ts.map +1 -0
  147. package/declarations/serializer/transform.d.ts +6 -0
  148. package/declarations/serializer/transform.d.ts.map +1 -0
  149. package/declarations/serializer.d.ts +258 -0
  150. package/declarations/serializer.d.ts.map +1 -0
  151. package/dist/-private-DFfBszo5.js +1182 -0
  152. package/dist/-private-DFfBszo5.js.map +1 -0
  153. package/dist/adapter/-private.js +1 -0
  154. package/dist/adapter/-private.js.map +1 -0
  155. package/dist/adapter/error.js +254 -0
  156. package/dist/adapter/error.js.map +1 -0
  157. package/dist/adapter/json-api.js +129 -0
  158. package/dist/adapter/json-api.js.map +1 -0
  159. package/dist/adapter/rest.js +1262 -0
  160. package/dist/adapter/rest.js.map +1 -0
  161. package/dist/adapter.js +1284 -0
  162. package/dist/adapter.js.map +1 -0
  163. package/dist/compat/-private.js +1 -0
  164. package/dist/compat/-private.js.map +1 -0
  165. package/dist/compat/builders.js +292 -0
  166. package/dist/compat/builders.js.map +1 -0
  167. package/dist/compat/utils.js +225 -0
  168. package/dist/compat/utils.js.map +1 -0
  169. package/dist/compat.js +999 -0
  170. package/dist/compat.js.map +1 -0
  171. package/dist/errors-D74uk36r.js +2541 -0
  172. package/dist/errors-D74uk36r.js.map +1 -0
  173. package/dist/json-BCH3fil7.js +1349 -0
  174. package/dist/json-BCH3fil7.js.map +1 -0
  175. package/dist/model/-private.js +2 -0
  176. package/dist/model/-private.js.map +1 -0
  177. package/dist/model/migration-support.js +453 -0
  178. package/dist/model/migration-support.js.map +1 -0
  179. package/dist/model.js +736 -0
  180. package/dist/model.js.map +1 -0
  181. package/dist/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  182. package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +1 -0
  183. package/dist/schema-provider-CXFLTMjg.js +2228 -0
  184. package/dist/schema-provider-CXFLTMjg.js.map +1 -0
  185. package/dist/serialize-into-hash-BxfqWC8u.js +260 -0
  186. package/dist/serialize-into-hash-BxfqWC8u.js.map +1 -0
  187. package/dist/serializer/json-api.js +514 -0
  188. package/dist/serializer/json-api.js.map +1 -0
  189. package/dist/serializer/json.js +6 -0
  190. package/dist/serializer/json.js.map +1 -0
  191. package/dist/serializer/rest.js +1245 -0
  192. package/dist/serializer/rest.js.map +1 -0
  193. package/dist/serializer/transform.js +313 -0
  194. package/dist/serializer/transform.js.map +1 -0
  195. package/dist/serializer.js +252 -0
  196. package/dist/serializer.js.map +1 -0
  197. package/logos/NCC-1701-a-blue.svg +4 -0
  198. package/logos/NCC-1701-a-gold.svg +4 -0
  199. package/logos/NCC-1701-a-gold_100.svg +1 -0
  200. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  201. package/logos/NCC-1701-a.svg +4 -0
  202. package/logos/README.md +4 -0
  203. package/logos/docs-badge.svg +2 -0
  204. package/logos/ember-data-logo-dark.svg +12 -0
  205. package/logos/ember-data-logo-light.svg +12 -0
  206. package/logos/github-header.svg +444 -0
  207. package/logos/social1.png +0 -0
  208. package/logos/social2.png +0 -0
  209. package/logos/warp-drive-logo-dark.svg +4 -0
  210. package/logos/warp-drive-logo-gold.svg +4 -0
  211. package/package.json +72 -0
@@ -0,0 +1,1270 @@
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';
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
+ };
22
+ };
23
+ export type StaticModel = typeof Model & {
24
+ create(options: ModelCreateArgs): Model;
25
+ };
26
+ export type ModelFactory = {
27
+ class: StaticModel;
28
+ };
29
+ export type FactoryCache = Record<string, ModelFactory>;
30
+ export type ModelStore = Store & {
31
+ _modelFactoryCache: FactoryCache;
32
+ };
33
+ /**
34
+ * @noInheritDoc
35
+ */
36
+ 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;
366
+ }
367
+ /**
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
+ */
411
+ 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;
1268
+ }
1269
+ export { Model };
1270
+ //# sourceMappingURL=model.d.ts.map