@warp-drive/legacy 5.6.0-alpha.14 → 5.6.0-alpha.17

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 (191) 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 +59 -0
  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 -271
  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 +243 -0
  76. package/dist/compat.js +3 -4
  77. package/dist/{errors-D74uk36r.js → errors-BX5wowuz.js} +12 -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 +15 -4
  81. package/dist/model.js +3 -3
  82. package/dist/{schema-provider-CXFLTMjg.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/legacy-network-handler/fetch-manager.d.ts.map +0 -1
  110. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +0 -1
  111. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +0 -1
  112. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +0 -1
  113. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +0 -1
  114. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +0 -1
  115. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +0 -1
  116. package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +0 -1
  117. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +0 -1
  118. package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +0 -1
  119. package/declarations/compat/utils.d.ts.map +0 -1
  120. package/declarations/compat.d.ts.map +0 -1
  121. package/declarations/model/-private/attr.d.ts.map +0 -1
  122. package/declarations/model/-private/attr.type-test.d.ts +0 -2
  123. package/declarations/model/-private/attr.type-test.d.ts.map +0 -1
  124. package/declarations/model/-private/belongs-to.d.ts.map +0 -1
  125. package/declarations/model/-private/belongs-to.type-test.d.ts +0 -2
  126. package/declarations/model/-private/belongs-to.type-test.d.ts.map +0 -1
  127. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +0 -1
  128. package/declarations/model/-private/errors.d.ts.map +0 -1
  129. package/declarations/model/-private/has-many.d.ts.map +0 -1
  130. package/declarations/model/-private/has-many.type-test.d.ts +0 -2
  131. package/declarations/model/-private/has-many.type-test.d.ts.map +0 -1
  132. package/declarations/model/-private/hooks.d.ts.map +0 -1
  133. package/declarations/model/-private/legacy-relationships-support.d.ts.map +0 -1
  134. package/declarations/model/-private/model-for-mixin.d.ts.map +0 -1
  135. package/declarations/model/-private/model-methods.d.ts.map +0 -1
  136. package/declarations/model/-private/model.d.ts.map +0 -1
  137. package/declarations/model/-private/model.type-test.d.ts +0 -2
  138. package/declarations/model/-private/model.type-test.d.ts.map +0 -1
  139. package/declarations/model/-private/notify-changes.d.ts.map +0 -1
  140. package/declarations/model/-private/promise-belongs-to.d.ts.map +0 -1
  141. package/declarations/model/-private/promise-many-array.d.ts.map +0 -1
  142. package/declarations/model/-private/promise-proxy-base.d.ts +0 -3
  143. package/declarations/model/-private/promise-proxy-base.d.ts.map +0 -1
  144. package/declarations/model/-private/record-state.d.ts.map +0 -1
  145. package/declarations/model/-private/references/belongs-to.d.ts.map +0 -1
  146. package/declarations/model/-private/references/has-many.d.ts.map +0 -1
  147. package/declarations/model/-private/schema-provider.d.ts.map +0 -1
  148. package/declarations/model/-private/type-utils.d.ts.map +0 -1
  149. package/declarations/model/-private/util.d.ts.map +0 -1
  150. package/declarations/model/-private.d.ts.map +0 -1
  151. package/declarations/model/migration-support.d.ts.map +0 -1
  152. package/declarations/model/migration-support.type-test.d.ts +0 -2
  153. package/declarations/model/migration-support.type-test.d.ts.map +0 -1
  154. package/declarations/model.d.ts.map +0 -1
  155. package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +0 -1
  156. package/declarations/serializer/-private/transforms/boolean.d.ts.map +0 -1
  157. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +0 -2
  158. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +0 -1
  159. package/declarations/serializer/-private/transforms/date.d.ts.map +0 -1
  160. package/declarations/serializer/-private/transforms/number.d.ts.map +0 -1
  161. package/declarations/serializer/-private/transforms/string.d.ts.map +0 -1
  162. package/declarations/serializer/-private/transforms/transform.d.ts.map +0 -1
  163. package/declarations/serializer/-private/utils.d.ts.map +0 -1
  164. package/declarations/serializer/json-api.d.ts.map +0 -1
  165. package/declarations/serializer/json.d.ts.map +0 -1
  166. package/declarations/serializer/rest.d.ts.map +0 -1
  167. package/declarations/serializer/transform.d.ts.map +0 -1
  168. package/declarations/serializer.d.ts.map +0 -1
  169. package/dist/-private-DFfBszo5.js.map +0 -1
  170. package/dist/adapter/-private.js.map +0 -1
  171. package/dist/adapter/error.js.map +0 -1
  172. package/dist/adapter/json-api.js.map +0 -1
  173. package/dist/adapter/rest.js.map +0 -1
  174. package/dist/adapter.js.map +0 -1
  175. package/dist/compat/-private.js.map +0 -1
  176. package/dist/compat/builders.js.map +0 -1
  177. package/dist/compat/utils.js.map +0 -1
  178. package/dist/compat.js.map +0 -1
  179. package/dist/errors-D74uk36r.js.map +0 -1
  180. package/dist/json-DSOlH9A8.js.map +0 -1
  181. package/dist/model/-private.js.map +0 -1
  182. package/dist/model/migration-support.js.map +0 -1
  183. package/dist/model.js.map +0 -1
  184. package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +0 -1
  185. package/dist/schema-provider-CXFLTMjg.js.map +0 -1
  186. package/dist/serialize-into-hash-BxfqWC8u.js.map +0 -1
  187. package/dist/serializer/json-api.js.map +0 -1
  188. package/dist/serializer/json.js.map +0 -1
  189. package/dist/serializer/rest.js.map +0 -1
  190. package/dist/serializer/transform.js.map +0 -1
  191. package/dist/serializer.js.map +0 -1
@@ -1,237 +1,236 @@
1
- import type { Store } from '@warp-drive/core';
2
- import type { FindRecordOptions } from '@warp-drive/core/types';
3
- import type { ChangedAttributesHash } from '@warp-drive/core/types/cache';
4
- import type { StableRecordIdentifier } from '@warp-drive/core/types/identifier';
5
- import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';
6
- import type { LegacyAttributeField, LegacyRelationshipField } from '@warp-drive/core/types/schema/fields';
7
- import type { SerializerOptions } from './minimum-serializer-interface';
1
+ import type { Store } from "@warp-drive/core";
2
+ import type { FindRecordOptions } from "@warp-drive/core/types";
3
+ import type { ChangedAttributesHash } from "@warp-drive/core/types/cache";
4
+ import type { StableRecordIdentifier } from "@warp-drive/core/types/identifier";
5
+ import type { TypedRecordInstance, TypeFromInstance } from "@warp-drive/core/types/record";
6
+ import type { LegacyAttributeField, LegacyRelationshipField } from "@warp-drive/core/types/schema/fields";
7
+ import type { SerializerOptions } from "./minimum-serializer-interface.js";
8
8
  type RecordId = string | null;
9
9
  /**
10
- Snapshot is not directly instantiable.
11
- Instances are provided to a consuming application's
12
- adapters and serializers for certain requests.
10
+ Snapshot is not directly instantiable.
11
+ Instances are provided to a consuming application's
12
+ adapters and serializers for certain requests.
13
13
 
14
- Snapshots are only available when using `@ember-data/legacy-compat`
15
- for legacy compatibility with adapters and serializers.
14
+ Snapshots are only available when using `@ember-data/legacy-compat`
15
+ for legacy compatibility with adapters and serializers.
16
16
 
17
- @class Snapshot
18
- @public
17
+ @class Snapshot
18
+ @public
19
19
  */
20
20
  export declare class Snapshot<R = unknown> {
21
- __attributes: Record<keyof R & string, unknown> | null;
22
- _belongsToRelationships: Record<string, Snapshot>;
23
- _belongsToIds: Record<string, RecordId>;
24
- _hasManyRelationships: Record<string, Snapshot[]>;
25
- _hasManyIds: Record<string, RecordId[]>;
26
- _changedAttributes: ChangedAttributesHash;
27
- identifier: StableRecordIdentifier<R extends TypedRecordInstance ? TypeFromInstance<R> : string>;
28
- modelName: R extends TypedRecordInstance ? TypeFromInstance<R> : string;
29
- id: string | null;
30
- include?: string | string[];
31
- adapterOptions?: Record<string, unknown>;
32
- _store: Store;
33
- /**
34
- * @constructor
35
- * @private
36
- * @param options
37
- * @param identifier
38
- * @param _store
39
- */
40
- constructor(options: FindRecordOptions, identifier: StableRecordIdentifier<R extends TypedRecordInstance ? TypeFromInstance<R> : string>, store: Store);
41
- /**
42
- The underlying record for this snapshot. Can be used to access methods and
43
- properties defined on the record.
44
-
45
- Example
46
-
47
- ```javascript
48
- let json = snapshot.record.toJSON();
49
- ```
50
-
51
- @property record
52
- @type {Model}
53
- @public
54
- */
55
- get record(): R | null;
56
- get _attributes(): Record<keyof R & string, unknown>;
57
- get isNew(): boolean;
58
- /**
59
- Returns the value of an attribute.
60
-
61
- Example
62
-
63
- ```javascript
64
- // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
65
- postSnapshot.attr('author'); // => 'Tomster'
66
- postSnapshot.attr('title'); // => 'Ember.js rocks'
67
- ```
68
-
69
- Note: Values are loaded eagerly and cached when the snapshot is created.
70
-
71
- @param {String} keyName
72
- @return {Object} The attribute value or undefined
73
- @public
74
- */
75
- attr(keyName: keyof R & string): unknown;
76
- /**
77
- Returns all attributes and their corresponding values.
78
-
79
- Example
80
-
81
- ```javascript
82
- // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
83
- postSnapshot.attributes(); // => { author: 'Tomster', title: 'Ember.js rocks' }
84
- ```
85
-
86
- @return {Object} All attributes of the current snapshot
87
- @public
88
- */
89
- attributes(): Record<keyof R & string, unknown>;
90
- /**
91
- Returns all changed attributes and their old and new values.
92
-
93
- Example
94
-
95
- ```javascript
96
- // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
97
- postModel.set('title', 'Ember.js rocks!');
98
- postSnapshot.changedAttributes(); // => { title: ['Ember.js rocks', 'Ember.js rocks!'] }
99
- ```
100
-
101
- @return {Object} All changed attributes of the current snapshot
102
- @public
103
- */
104
- changedAttributes(): ChangedAttributesHash;
105
- /**
106
- Returns the current value of a belongsTo relationship.
107
-
108
- `belongsTo` takes an optional hash of options as a second parameter,
109
- currently supported options are:
110
-
111
- - `id`: set to `true` if you only want the ID of the related record to be
112
- returned.
113
-
114
- Example
115
-
116
- ```javascript
117
- // store.push('post', { id: 1, title: 'Hello World' });
118
- // store.createRecord('comment', { body: 'Lorem ipsum', post: post });
119
- commentSnapshot.belongsTo('post'); // => Snapshot
120
- commentSnapshot.belongsTo('post', { id: true }); // => '1'
121
-
122
- // store.push('comment', { id: 1, body: 'Lorem ipsum' });
123
- commentSnapshot.belongsTo('post'); // => undefined
124
- ```
125
-
126
- Calling `belongsTo` will return a new Snapshot as long as there's any known
127
- data for the relationship available, such as an ID. If the relationship is
128
- known but unset, `belongsTo` will return `null`. If the contents of the
129
- relationship is unknown `belongsTo` will return `undefined`.
130
-
131
- Note: Relationships are loaded lazily and cached upon first access.
132
-
133
- @param {String} keyName
134
- @param {Object} [options]
135
- @public
136
- @return {(Snapshot|String|null|undefined)} A snapshot or ID of a known
137
- relationship or null if the relationship is known but unset. undefined
138
- will be returned if the contents of the relationship is unknown.
139
- */
140
- belongsTo(keyName: string, options?: {
141
- id?: boolean;
142
- }): Snapshot | RecordId | undefined;
143
- /**
144
- Returns the current value of a hasMany relationship.
145
-
146
- `hasMany` takes an optional hash of options as a second parameter,
147
- currently supported options are:
148
-
149
- - `ids`: set to `true` if you only want the IDs of the related records to be
150
- returned.
151
-
152
- Example
153
-
154
- ```javascript
155
- // store.push('post', { id: 1, title: 'Hello World', comments: [2, 3] });
156
- postSnapshot.hasMany('comments'); // => [Snapshot, Snapshot]
157
- postSnapshot.hasMany('comments', { ids: true }); // => ['2', '3']
158
-
159
- // store.push('post', { id: 1, title: 'Hello World' });
160
- postSnapshot.hasMany('comments'); // => undefined
161
- ```
162
-
163
- Note: Relationships are loaded lazily and cached upon first access.
164
-
165
- @param {String} keyName
166
- @param {Object} [options]
167
- @public
168
- @return {(Array|undefined)} An array of snapshots or IDs of a known
169
- relationship or an empty array if the relationship is known but unset.
170
- undefined will be returned if the contents of the relationship is unknown.
171
- */
172
- hasMany(keyName: string, options?: {
173
- ids?: boolean;
174
- }): RecordId[] | Snapshot[] | undefined;
175
- /**
176
- Iterates through all the attributes of the model, calling the passed
177
- function on each attribute.
178
-
179
- Example
180
-
181
- ```javascript
182
- snapshot.eachAttribute(function(name, meta) {
183
- // ...
184
- });
185
- ```
186
-
187
- @param {Function} callback the callback to execute
188
- @param {Object} [binding] the value to which the callback's `this` should be bound
189
- @public
190
- */
191
- eachAttribute(callback: (key: string, meta: LegacyAttributeField) => void, binding?: unknown): void;
192
- /**
193
- Iterates through all the relationships of the model, calling the passed
194
- function on each relationship.
195
-
196
- Example
197
-
198
- ```javascript
199
- snapshot.eachRelationship(function(name, relationship) {
200
- // ...
201
- });
202
- ```
203
-
204
- @param {Function} callback the callback to execute
205
- @param {Object} [binding] the value to which the callback's `this` should be bound
206
- @public
207
- */
208
- eachRelationship(callback: (key: string, meta: LegacyRelationshipField) => void, binding?: unknown): void;
209
- /**
210
- Serializes the snapshot using the serializer for the model.
211
-
212
- Example
213
-
214
- ```js [app/adapters/application.js]
215
- import Adapter from '@ember-data/adapter';
216
-
217
- export default Adapter.extend({
218
- createRecord(store, type, snapshot) {
219
- let data = snapshot.serialize({ includeId: true });
220
- let url = `/${type.modelName}`;
221
-
222
- return fetch(url, {
223
- method: 'POST',
224
- body: data,
225
- }).then((response) => response.json())
226
- }
227
- });
228
- ```
229
-
230
- @param {Object} options
231
- @return {Object} an object whose values are primitive JSON values only
232
- @public
233
- */
234
- serialize(options?: SerializerOptions): unknown;
21
+ __attributes: Record<keyof R & string, unknown> | null;
22
+ _belongsToRelationships: Record<string, Snapshot>;
23
+ _belongsToIds: Record<string, RecordId>;
24
+ _hasManyRelationships: Record<string, Snapshot[]>;
25
+ _hasManyIds: Record<string, RecordId[]>;
26
+ _changedAttributes: ChangedAttributesHash;
27
+ identifier: StableRecordIdentifier<R extends TypedRecordInstance ? TypeFromInstance<R> : string>;
28
+ modelName: R extends TypedRecordInstance ? TypeFromInstance<R> : string;
29
+ id: string | null;
30
+ include?: string | string[];
31
+ adapterOptions?: Record<string, unknown>;
32
+ _store: Store;
33
+ /**
34
+ * @constructor
35
+ * @private
36
+ * @param options
37
+ * @param identifier
38
+ * @param _store
39
+ */
40
+ constructor(options: FindRecordOptions, identifier: StableRecordIdentifier<R extends TypedRecordInstance ? TypeFromInstance<R> : string>, store: Store);
41
+ /**
42
+ The underlying record for this snapshot. Can be used to access methods and
43
+ properties defined on the record.
44
+
45
+ Example
46
+
47
+ ```javascript
48
+ let json = snapshot.record.toJSON();
49
+ ```
50
+
51
+ @property record
52
+ @type {Model}
53
+ @public
54
+ */
55
+ get record(): R | null;
56
+ get _attributes(): Record<keyof R & string, unknown>;
57
+ get isNew(): boolean;
58
+ /**
59
+ Returns the value of an attribute.
60
+
61
+ Example
62
+
63
+ ```javascript
64
+ // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
65
+ postSnapshot.attr('author'); // => 'Tomster'
66
+ postSnapshot.attr('title'); // => 'Ember.js rocks'
67
+ ```
68
+
69
+ Note: Values are loaded eagerly and cached when the snapshot is created.
70
+
71
+ @param {String} keyName
72
+ @return {Object} The attribute value or undefined
73
+ @public
74
+ */
75
+ attr(keyName: keyof R & string): unknown;
76
+ /**
77
+ Returns all attributes and their corresponding values.
78
+
79
+ Example
80
+
81
+ ```javascript
82
+ // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
83
+ postSnapshot.attributes(); // => { author: 'Tomster', title: 'Ember.js rocks' }
84
+ ```
85
+
86
+ @return {Object} All attributes of the current snapshot
87
+ @public
88
+ */
89
+ attributes(): Record<keyof R & string, unknown>;
90
+ /**
91
+ Returns all changed attributes and their old and new values.
92
+
93
+ Example
94
+
95
+ ```javascript
96
+ // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
97
+ postModel.set('title', 'Ember.js rocks!');
98
+ postSnapshot.changedAttributes(); // => { title: ['Ember.js rocks', 'Ember.js rocks!'] }
99
+ ```
100
+
101
+ @return {Object} All changed attributes of the current snapshot
102
+ @public
103
+ */
104
+ changedAttributes(): ChangedAttributesHash;
105
+ /**
106
+ Returns the current value of a belongsTo relationship.
107
+
108
+ `belongsTo` takes an optional hash of options as a second parameter,
109
+ currently supported options are:
110
+
111
+ - `id`: set to `true` if you only want the ID of the related record to be
112
+ returned.
113
+
114
+ Example
115
+
116
+ ```javascript
117
+ // store.push('post', { id: 1, title: 'Hello World' });
118
+ // store.createRecord('comment', { body: 'Lorem ipsum', post: post });
119
+ commentSnapshot.belongsTo('post'); // => Snapshot
120
+ commentSnapshot.belongsTo('post', { id: true }); // => '1'
121
+
122
+ // store.push('comment', { id: 1, body: 'Lorem ipsum' });
123
+ commentSnapshot.belongsTo('post'); // => undefined
124
+ ```
125
+
126
+ Calling `belongsTo` will return a new Snapshot as long as there's any known
127
+ data for the relationship available, such as an ID. If the relationship is
128
+ known but unset, `belongsTo` will return `null`. If the contents of the
129
+ relationship is unknown `belongsTo` will return `undefined`.
130
+
131
+ Note: Relationships are loaded lazily and cached upon first access.
132
+
133
+ @param {String} keyName
134
+ @param {Object} [options]
135
+ @public
136
+ @return {(Snapshot|String|null|undefined)} A snapshot or ID of a known
137
+ relationship or null if the relationship is known but unset. undefined
138
+ will be returned if the contents of the relationship is unknown.
139
+ */
140
+ belongsTo(keyName: string, options?: {
141
+ id?: boolean;
142
+ }): Snapshot | RecordId | undefined;
143
+ /**
144
+ Returns the current value of a hasMany relationship.
145
+
146
+ `hasMany` takes an optional hash of options as a second parameter,
147
+ currently supported options are:
148
+
149
+ - `ids`: set to `true` if you only want the IDs of the related records to be
150
+ returned.
151
+
152
+ Example
153
+
154
+ ```javascript
155
+ // store.push('post', { id: 1, title: 'Hello World', comments: [2, 3] });
156
+ postSnapshot.hasMany('comments'); // => [Snapshot, Snapshot]
157
+ postSnapshot.hasMany('comments', { ids: true }); // => ['2', '3']
158
+
159
+ // store.push('post', { id: 1, title: 'Hello World' });
160
+ postSnapshot.hasMany('comments'); // => undefined
161
+ ```
162
+
163
+ Note: Relationships are loaded lazily and cached upon first access.
164
+
165
+ @param {String} keyName
166
+ @param {Object} [options]
167
+ @public
168
+ @return {(Array|undefined)} An array of snapshots or IDs of a known
169
+ relationship or an empty array if the relationship is known but unset.
170
+ undefined will be returned if the contents of the relationship is unknown.
171
+ */
172
+ hasMany(keyName: string, options?: {
173
+ ids?: boolean;
174
+ }): RecordId[] | Snapshot[] | undefined;
175
+ /**
176
+ Iterates through all the attributes of the model, calling the passed
177
+ function on each attribute.
178
+
179
+ Example
180
+
181
+ ```javascript
182
+ snapshot.eachAttribute(function(name, meta) {
183
+ // ...
184
+ });
185
+ ```
186
+
187
+ @param {Function} callback the callback to execute
188
+ @param {Object} [binding] the value to which the callback's `this` should be bound
189
+ @public
190
+ */
191
+ eachAttribute(callback: (key: string, meta: LegacyAttributeField) => void, binding?: unknown): void;
192
+ /**
193
+ Iterates through all the relationships of the model, calling the passed
194
+ function on each relationship.
195
+
196
+ Example
197
+
198
+ ```javascript
199
+ snapshot.eachRelationship(function(name, relationship) {
200
+ // ...
201
+ });
202
+ ```
203
+
204
+ @param {Function} callback the callback to execute
205
+ @param {Object} [binding] the value to which the callback's `this` should be bound
206
+ @public
207
+ */
208
+ eachRelationship(callback: (key: string, meta: LegacyRelationshipField) => void, binding?: unknown): void;
209
+ /**
210
+ Serializes the snapshot using the serializer for the model.
211
+
212
+ Example
213
+
214
+ ```js [app/adapters/application.js]
215
+ import Adapter from '@ember-data/adapter';
216
+
217
+ export default Adapter.extend({
218
+ createRecord(store, type, snapshot) {
219
+ let data = snapshot.serialize({ includeId: true });
220
+ let url = `/${type.modelName}`;
221
+
222
+ return fetch(url, {
223
+ method: 'POST',
224
+ body: data,
225
+ }).then((response) => response.json())
226
+ }
227
+ });
228
+ ```
229
+
230
+ @param {Object} options
231
+ @return {Object} an object whose values are primitive JSON values only
232
+ @public
233
+ */
234
+ serialize(options?: SerializerOptions): unknown;
235
235
  }
236
236
  export {};
237
- //# sourceMappingURL=snapshot.d.ts.map