@ember-data-mirror/serializer 5.6.0-beta.0 → 5.6.0-beta.1

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 (40) hide show
  1. package/addon-main.cjs +1 -1
  2. package/dist/index.js +1 -306
  3. package/dist/json-api.js +1 -531
  4. package/dist/json.js +1 -6
  5. package/dist/rest.js +1 -1274
  6. package/dist/transform.js +1 -336
  7. package/package.json +7 -24
  8. package/unstable-preview-types/index.d.ts +81 -243
  9. package/unstable-preview-types/json-api.d.ts +2 -512
  10. package/unstable-preview-types/json.d.ts +2 -1091
  11. package/unstable-preview-types/rest.d.ts +2 -568
  12. package/unstable-preview-types/transform.d.ts +3 -10
  13. package/dist/index.js.map +0 -1
  14. package/dist/json-CVTR4xWv.js +0 -1396
  15. package/dist/json-CVTR4xWv.js.map +0 -1
  16. package/dist/json-api.js.map +0 -1
  17. package/dist/json.js.map +0 -1
  18. package/dist/rest.js.map +0 -1
  19. package/dist/transform.js.map +0 -1
  20. package/unstable-preview-types/-private/embedded-records-mixin.d.ts +0 -102
  21. package/unstable-preview-types/-private/embedded-records-mixin.d.ts.map +0 -1
  22. package/unstable-preview-types/-private/transforms/boolean.d.ts +0 -52
  23. package/unstable-preview-types/-private/transforms/boolean.d.ts.map +0 -1
  24. package/unstable-preview-types/-private/transforms/boolean.type-test.d.ts +0 -4
  25. package/unstable-preview-types/-private/transforms/boolean.type-test.d.ts.map +0 -1
  26. package/unstable-preview-types/-private/transforms/date.d.ts +0 -33
  27. package/unstable-preview-types/-private/transforms/date.d.ts.map +0 -1
  28. package/unstable-preview-types/-private/transforms/number.d.ts +0 -34
  29. package/unstable-preview-types/-private/transforms/number.d.ts.map +0 -1
  30. package/unstable-preview-types/-private/transforms/string.d.ts +0 -34
  31. package/unstable-preview-types/-private/transforms/string.d.ts.map +0 -1
  32. package/unstable-preview-types/-private/transforms/transform.d.ts +0 -126
  33. package/unstable-preview-types/-private/transforms/transform.d.ts.map +0 -1
  34. package/unstable-preview-types/-private/utils.d.ts +0 -6
  35. package/unstable-preview-types/-private/utils.d.ts.map +0 -1
  36. package/unstable-preview-types/index.d.ts.map +0 -1
  37. package/unstable-preview-types/json-api.d.ts.map +0 -1
  38. package/unstable-preview-types/json.d.ts.map +0 -1
  39. package/unstable-preview-types/rest.d.ts.map +0 -1
  40. package/unstable-preview-types/transform.d.ts.map +0 -1
@@ -1,277 +1,115 @@
1
+ /// <reference path="./json.d.ts" />
2
+ /// <reference path="./transform.d.ts" />
1
3
  /// <reference path="./json-api.d.ts" />
2
4
  /// <reference path="./rest.d.ts" />
3
- /// <reference path="./transform.d.ts" />
4
- /// <reference path="./json.d.ts" />
5
- /// <reference path="./-private/utils.d.ts" />
6
- /// <reference path="./-private/embedded-records-mixin.d.ts" />
7
- /// <reference path="./-private/transforms/number.d.ts" />
8
- /// <reference path="./-private/transforms/boolean.d.ts" />
9
- /// <reference path="./-private/transforms/boolean.type-test.d.ts" />
10
- /// <reference path="./-private/transforms/date.d.ts" />
11
- /// <reference path="./-private/transforms/string.d.ts" />
12
- /// <reference path="./-private/transforms/transform.d.ts" />
13
5
  declare module '@ember-data-mirror/serializer' {
14
6
  /**
15
- ## Overview
7
+ ## Overview
16
8
 
17
- <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
18
- <p>
19
- ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
20
- If starting a new app or thinking of implementing a new serializer, consider writing a
21
- <a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
22
- </p>
23
- </blockquote>
9
+ <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
10
+ <p>
11
+ ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
12
+ If starting a new app or thinking of implementing a new serializer, consider writing a
13
+ <a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
14
+ </p>
15
+ </blockquote>
24
16
 
25
- In order to properly manage and present your data, EmberData
26
- needs to understand the structure of data it receives.
17
+ In order to properly manage and present your data, EmberData
18
+ needs to understand the structure of data it receives.
27
19
 
28
- `Serializers` convert data between the server's API format and
29
- the format EmberData understands.
20
+ `Serializers` convert data between the server's API format and
21
+ the format EmberData understands.
30
22
 
31
- Data received from an API response is **normalized** into
32
- [JSON:API](https://jsonapi.org/) (the format used internally
33
- by EmberData), while data sent to an API is **serialized**
34
- into the format the API expects.
23
+ Data received from an API response is **normalized** into
24
+ [JSON:API](https://jsonapi.org/) (the format used internally
25
+ by EmberData), while data sent to an API is **serialized**
26
+ into the format the API expects.
35
27
 
36
- ### Implementing a Serializer
28
+ ### Implementing a Serializer
37
29
 
38
- There are only two required serializer methods, one for
39
- normalizing data from the server API format into JSON:API, and
40
- another for serializing records via `Snapshots` into the expected
41
- server API format.
30
+ There are only two required serializer methods, one for
31
+ normalizing data from the server API format into JSON:API, and
32
+ another for serializing records via `Snapshots` into the expected
33
+ server API format.
42
34
 
43
- To implement a serializer, export a class that conforms to the structure
44
- described by [<Interface> Serializer](/ember-data/release/classes/%3CInterface%3E%20Serializer)
45
- from the `app/serializers/` directory. An example is below.
35
+ To implement a serializer, export a class that conforms to the structure
36
+ described by {@link MinimumSerializerInterface}
37
+ from the `app/serializers/` directory. An example is below.
46
38
 
47
- ```ts
48
- import EmberObject from '@ember/object';
39
+ ```ts
40
+ import EmberObject from '@ember/object';
49
41
 
50
- export default class ApplicationSerializer extends EmberObject {
51
- normalizeResponse(store, schema, rawPayload) {
52
- return rawPayload;
53
- }
42
+ export default class ApplicationSerializer extends EmberObject {
43
+ normalizeResponse(store, schema, rawPayload) {
44
+ return rawPayload;
45
+ }
54
46
 
55
- serialize(snapshot, options) {
56
- const serializedResource = {
57
- id: snapshot.id,
58
- type: snapshot.modelName,
59
- attributes: snapshot.attributes()
60
- };
47
+ serialize(snapshot, options) {
48
+ const serializedResource = {
49
+ id: snapshot.id,
50
+ type: snapshot.modelName,
51
+ attributes: snapshot.attributes()
52
+ };
61
53
 
62
- return serializedResource;
63
- }
64
- }
65
- ```
54
+ return serializedResource;
55
+ }
56
+ }
57
+ ```
66
58
 
67
59
 
68
- ### Serializer Resolution
60
+ ### Serializer Resolution
69
61
 
70
- `store.serializerFor(name)` will lookup serializers defined in
71
- `app/serializers/` and return an instance. If no serializer is found, an
72
- error will be thrown.
62
+ `store.serializerFor(name)` will lookup serializers defined in
63
+ `app/serializers/` and return an instance. If no serializer is found, an
64
+ error will be thrown.
73
65
 
74
- `serializerFor` first attempts to find a serializer with an exact match on `name`,
75
- then falls back to checking for the presence of a serializer named `application`.
66
+ `serializerFor` first attempts to find a serializer with an exact match on `name`,
67
+ then falls back to checking for the presence of a serializer named `application`.
76
68
 
77
- ```ts
78
- store.serializerFor('author');
69
+ ```ts
70
+ store.serializerFor('author');
79
71
 
80
- // lookup paths (in order) =>
81
- // app/serializers/author.js
82
- // app/serializers/application.js
83
- ```
72
+ // lookup paths (in order) =>
73
+ // app/serializers/author.js
74
+ // app/serializers/application.js
75
+ ```
84
76
 
85
- Most requests in EmberData are made with respect to a particular `type` (or `modelName`)
86
- (e.g., "get me the full collection of **books**" or "get me the **employee** whose id is 37"). We
87
- refer to this as the **primary** resource `type`.
77
+ Most requests in EmberData are made with respect to a particular `type` (or `modelName`)
78
+ (e.g., "get me the full collection of **books**" or "get me the **employee** whose id is 37"). We
79
+ refer to this as the **primary** resource `type`.
88
80
 
89
- Typically `serializerFor` will be used to find a serializer with a name matching that of the primary
90
- resource `type` for the request, falling back to the `application` serializer for those types that
91
- do not have a defined serializer. This is often described as a `per-model` or `per-type` strategy
92
- for defining serializers. However, because APIs rarely format payloads per-type but rather
93
- per-API-version, this may not be a desired strategy.
81
+ Typically `serializerFor` will be used to find a serializer with a name matching that of the primary
82
+ resource `type` for the request, falling back to the `application` serializer for those types that
83
+ do not have a defined serializer. This is often described as a `per-model` or `per-type` strategy
84
+ for defining serializers. However, because APIs rarely format payloads per-type but rather
85
+ per-API-version, this may not be a desired strategy.
94
86
 
95
- It is recommended that applications define only a single `application` adapter and serializer
96
- where possible.
87
+ It is recommended that applications define only a single `application` adapter and serializer
88
+ where possible.
97
89
 
98
- If you have multiple API formats and the per-type strategy is not viable, one strategy is to
99
- write an `application` adapter and serializer that make use of `options` to specify the desired
100
- format when making a request.
90
+ If you have multiple API formats and the per-type strategy is not viable, one strategy is to
91
+ write an `application` adapter and serializer that make use of `options` to specify the desired
92
+ format when making a request.
101
93
 
102
- ### Using a Serializer
94
+ ### Using a Serializer
103
95
 
104
- Any serializer in `app/serializers/` can be looked up by `name` using `store.serializerFor(name)`.
96
+ Any serializer in `app/serializers/` can be looked up by `name` using `store.serializerFor(name)`.
105
97
 
106
- ### Default Serializers
98
+ ### Default Serializers
107
99
 
108
- For applications whose APIs are *very close to* or *exactly* the **REST** format or **JSON:API**
109
- format the `@ember-data-mirror/serializer` package contains implementations these applications can
110
- extend. It also contains a simple `JSONSerializer` for serializing to/from very basic JSON objects.
100
+ For applications whose APIs are *very close to* or *exactly* the **REST** format or **JSON:API**
101
+ format the `@ember-data-mirror/serializer` package contains implementations these applications can
102
+ extend. It also contains a simple `JSONSerializer` for serializing to/from very basic JSON objects.
111
103
 
112
- Many applications will find writing their own serializer to be more performant and less
113
- complex than extending these classes even when their API format is very close to that expected
114
- by these serializers.
104
+ Many applications will find writing their own serializer to be more performant and less
105
+ complex than extending these classes even when their API format is very close to that expected
106
+ by these serializers.
115
107
 
116
- It is recommended that apps write their own serializer to best suit the needs of their API and
117
- application.
108
+ It is recommended that apps write their own serializer to best suit the needs of their API and
109
+ application.
118
110
 
119
- @module @ember-data-mirror/serializer
120
- @main @ember-data-mirror/serializer
111
+ @module
121
112
  */
122
- import EmberObject from '@ember/object';
123
- import type Store from '@ember-data-mirror/store';
124
- import type { ModelSchema } from '@ember-data-mirror/store/types';
125
- import type { EmptyResourceDocument, SingleResourceDocument } from '@warp-drive-mirror/core-types/spec/json-api-raw';
126
- /**
127
- > ⚠️ CAUTION you likely want the docs for [<Interface> Serializer](/ember-data/release/classes/%3CInterface%3E%20Serializer)
128
- > as extending this abstract class is unnecessary.
129
-
130
- `Serializer` is an abstract base class that you may override in your
131
- application to customize it for your backend. The minimum set of methods
132
- that you should implement is:
133
-
134
- * `normalizeResponse()`
135
- * `serialize()`
136
-
137
- And you can optionally override the following methods:
113
+ export { Serializer as default } from "@warp-drive-mirror/legacy/serializer";
138
114
 
139
- * `normalize()`
140
-
141
- For an example implementation, see
142
- [JSONSerializer](JSONSerializer), the included JSON serializer.
143
-
144
- @class Serializer
145
- @public
146
- @extends Ember.EmberObject
147
- */
148
- export default class extends EmberObject {
149
- store: Store;
150
- /**
151
- The `store` property is the application's `store` that contains
152
- all records. It can be used to look up serializers for other model
153
- types that may be nested inside the payload response.
154
-
155
- Example:
156
-
157
- ```js
158
- Serializer.extend({
159
- extractRelationship(relationshipModelName, relationshipHash) {
160
- let modelClass = this.store.modelFor(relationshipModelName);
161
- let relationshipSerializer = this.store.serializerFor(relationshipModelName);
162
- return relationshipSerializer.normalize(modelClass, relationshipHash);
163
- }
164
- });
165
- ```
166
-
167
- @property store
168
- @type {Store}
169
- @public
170
- */
171
- /**
172
- The `normalizeResponse` method is used to normalize a payload from the
173
- server to a JSON-API Document.
174
-
175
- http://jsonapi.org/format/#document-structure
176
-
177
- Example:
178
-
179
- ```js
180
- Serializer.extend({
181
- normalizeResponse(store, primaryModelClass, payload, id, requestType) {
182
- if (requestType === 'findRecord') {
183
- return this.normalize(primaryModelClass, payload);
184
- } else {
185
- return payload.reduce(function(documentHash, item) {
186
- let { data, included } = this.normalize(primaryModelClass, item);
187
- documentHash.included.push(...included);
188
- documentHash.data.push(data);
189
- return documentHash;
190
- }, { data: [], included: [] })
191
- }
192
- }
193
- });
194
- ```
195
-
196
- @since 1.13.0
197
- @method normalizeResponse
198
- @public
199
- @param {Store} store
200
- @param {Model} primaryModelClass
201
- @param {Object} payload
202
- @param {String|Number} id
203
- @param {String} requestType
204
- @return {Object} JSON-API Document
205
- */
206
- /**
207
- The `serialize` method is used when a record is saved in order to convert
208
- the record into the form that your external data source expects.
209
-
210
- `serialize` takes an optional `options` hash with a single option:
211
-
212
- - `includeId`: If this is `true`, `serialize` should include the ID
213
- in the serialized object it builds.
214
-
215
- Example:
216
-
217
- ```js
218
- Serializer.extend({
219
- serialize(snapshot, options) {
220
- let json = {
221
- id: snapshot.id
222
- };
223
-
224
- snapshot.eachAttribute((key, attribute) => {
225
- json[key] = snapshot.attr(key);
226
- });
227
-
228
- snapshot.eachRelationship((key, relationship) => {
229
- if (relationship.kind === 'belongsTo') {
230
- json[key] = snapshot.belongsTo(key, { id: true });
231
- } else if (relationship.kind === 'hasMany') {
232
- json[key] = snapshot.hasMany(key, { ids: true });
233
- }
234
- });
235
-
236
- return json;
237
- },
238
- });
239
- ```
240
-
241
- @method serialize
242
- @public
243
- @param {Snapshot} snapshot
244
- @param {Object} [options]
245
- @return {Object}
246
- */
247
- /**
248
- The `normalize` method is used to convert a payload received from your
249
- external data source into the normalized form `store.push()` expects. You
250
- should override this method, munge the hash and return the normalized
251
- payload.
252
-
253
- Example:
254
-
255
- ```js
256
- Serializer.extend({
257
- normalize(modelClass, resourceHash) {
258
- let data = {
259
- id: resourceHash.id,
260
- type: modelClass.modelName,
261
- attributes: resourceHash
262
- };
263
- return { data: data };
264
- }
265
- })
266
- ```
267
-
268
- @method normalize
269
- @public
270
- @param {Model} typeClass
271
- @param {Object} hash
272
- @return {Object}
273
- */
274
- normalize(_typeClass: ModelSchema, hash: Record<string, unknown>): SingleResourceDocument | EmptyResourceDocument;
275
- }
276
- }
277
- //# sourceMappingURL=index.d.ts.map
115
+ }