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