@warp-drive/legacy 5.6.0-alpha.15 → 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.
- package/declarations/adapter/-private/build-url-mixin.d.ts +41 -29
- package/declarations/adapter/-private/fastboot-interface.d.ts +4 -5
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts +5 -6
- package/declarations/adapter/-private/utils/determine-body-promise.d.ts +1 -2
- package/declarations/adapter/-private/utils/fetch.d.ts +2 -3
- package/declarations/adapter/-private/utils/parse-response-headers.d.ts +0 -1
- package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +5 -6
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -2
- package/declarations/adapter/-private.d.ts +5 -6
- package/declarations/adapter/error.d.ts +206 -178
- package/declarations/adapter/json-api.d.ts +206 -207
- package/declarations/adapter/rest.d.ts +805 -808
- package/declarations/adapter.d.ts +742 -766
- package/declarations/compat/-private.d.ts +10 -11
- package/declarations/compat/builders/find-all.d.ts +26 -24
- package/declarations/compat/builders/find-record.d.ts +41 -39
- package/declarations/compat/builders/query.d.ts +50 -45
- package/declarations/compat/builders/save-record.d.ts +26 -24
- package/declarations/compat/builders/utils.d.ts +1 -2
- package/declarations/compat/builders.d.ts +10 -11
- package/declarations/compat/extensions.d.ts +52 -106
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +39 -38
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +1 -2
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +9 -10
- package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +1 -2
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +1 -2
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +521 -517
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +214 -215
- package/declarations/compat/legacy-network-handler/serializer-response.d.ts +5 -6
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +83 -84
- package/declarations/compat/legacy-network-handler/snapshot.d.ts +228 -229
- package/declarations/compat/utils.d.ts +118 -119
- package/declarations/compat.d.ts +106 -104
- package/declarations/model/-private/attr.d.ts +164 -145
- package/declarations/model/-private/belongs-to.d.ts +135 -122
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +15 -4
- package/declarations/model/-private/errors.d.ts +272 -267
- package/declarations/model/-private/has-many.d.ts +119 -116
- package/declarations/model/-private/hooks.d.ts +5 -6
- package/declarations/model/-private/legacy-relationships-support.d.ts +51 -52
- package/declarations/model/-private/model-for-mixin.d.ts +18 -3
- package/declarations/model/-private/model-methods.d.ts +29 -24
- package/declarations/model/-private/model.d.ts +1306 -1254
- package/declarations/model/-private/notify-changes.d.ts +3 -4
- package/declarations/model/-private/promise-belongs-to.d.ts +33 -27
- package/declarations/model/-private/promise-many-array.d.ts +125 -116
- package/declarations/model/-private/record-state.d.ts +63 -60
- package/declarations/model/-private/references/belongs-to.d.ts +491 -487
- package/declarations/model/-private/references/has-many.d.ts +495 -492
- package/declarations/model/-private/schema-provider.d.ts +53 -56
- package/declarations/model/-private/type-utils.d.ts +41 -41
- package/declarations/model/-private/util.d.ts +1 -2
- package/declarations/model/-private.d.ts +8 -8
- package/declarations/model/migration-support.d.ts +281 -279
- package/declarations/model.d.ts +48 -49
- package/declarations/serializer/-private/embedded-records-mixin.d.ts +70 -71
- package/declarations/serializer/-private/transforms/boolean.d.ts +37 -37
- package/declarations/serializer/-private/transforms/date.d.ts +22 -22
- package/declarations/serializer/-private/transforms/number.d.ts +22 -22
- package/declarations/serializer/-private/transforms/string.d.ts +22 -22
- package/declarations/serializer/-private/transforms/transform.d.ts +109 -110
- package/declarations/serializer/-private/utils.d.ts +0 -1
- package/declarations/serializer/json-api.d.ts +124 -494
- package/declarations/serializer/json.d.ts +62 -1031
- package/declarations/serializer/rest.d.ts +52 -552
- package/declarations/serializer/transform.d.ts +5 -6
- package/declarations/serializer.d.ts +217 -218
- package/dist/{-private-DFfBszo5.js → -private-CKrP0ogQ.js} +1 -1
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +17 -0
- package/dist/adapter/json-api.js +1 -1
- package/dist/adapter/rest.js +5 -7
- package/dist/adapter.js +6 -35
- package/dist/compat/-private.js +1 -1
- package/dist/compat/extensions.js +0 -2
- package/dist/compat.js +3 -4
- package/dist/{errors-_QQ7xpSn.js → errors-BX5wowuz.js} +11 -10
- package/dist/{json-DSOlH9A8.js → json-Et4mt_LM.js} +84 -157
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +3 -4
- package/dist/model.js +3 -3
- package/dist/{schema-provider-D_P8ReX6.js → schema-provider-BdQhkT-Q.js} +20 -13
- package/dist/{serialize-into-hash-BxfqWC8u.js → serialize-into-hash-Bp58npke.js} +1 -1
- package/dist/serializer/json-api.js +42 -2
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +46 -41
- package/dist/serializer/transform.js +0 -44
- package/package.json +7 -7
- package/declarations/adapter/-private/build-url-mixin.d.ts.map +0 -1
- package/declarations/adapter/-private/fastboot-interface.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/determine-body-promise.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/fetch.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/parse-response-headers.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/serialize-into-hash.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts.map +0 -1
- package/declarations/adapter/-private.d.ts.map +0 -1
- package/declarations/adapter/error.d.ts.map +0 -1
- package/declarations/adapter/json-api.d.ts.map +0 -1
- package/declarations/adapter/rest.d.ts.map +0 -1
- package/declarations/adapter.d.ts.map +0 -1
- package/declarations/compat/-private.d.ts.map +0 -1
- package/declarations/compat/builders/find-all.d.ts.map +0 -1
- package/declarations/compat/builders/find-record.d.ts.map +0 -1
- package/declarations/compat/builders/query.d.ts.map +0 -1
- package/declarations/compat/builders/save-record.d.ts.map +0 -1
- package/declarations/compat/builders/utils.d.ts.map +0 -1
- package/declarations/compat/builders.d.ts.map +0 -1
- package/declarations/compat/extensions.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +0 -1
- package/declarations/compat/utils.d.ts.map +0 -1
- package/declarations/compat.d.ts.map +0 -1
- package/declarations/model/-private/attr.d.ts.map +0 -1
- package/declarations/model/-private/attr.type-test.d.ts +0 -2
- package/declarations/model/-private/attr.type-test.d.ts.map +0 -1
- package/declarations/model/-private/belongs-to.d.ts.map +0 -1
- package/declarations/model/-private/belongs-to.type-test.d.ts +0 -2
- package/declarations/model/-private/belongs-to.type-test.d.ts.map +0 -1
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +0 -1
- package/declarations/model/-private/errors.d.ts.map +0 -1
- package/declarations/model/-private/has-many.d.ts.map +0 -1
- package/declarations/model/-private/has-many.type-test.d.ts +0 -2
- package/declarations/model/-private/has-many.type-test.d.ts.map +0 -1
- package/declarations/model/-private/hooks.d.ts.map +0 -1
- package/declarations/model/-private/legacy-relationships-support.d.ts.map +0 -1
- package/declarations/model/-private/model-for-mixin.d.ts.map +0 -1
- package/declarations/model/-private/model-methods.d.ts.map +0 -1
- package/declarations/model/-private/model.d.ts.map +0 -1
- package/declarations/model/-private/model.type-test.d.ts +0 -2
- package/declarations/model/-private/model.type-test.d.ts.map +0 -1
- package/declarations/model/-private/notify-changes.d.ts.map +0 -1
- package/declarations/model/-private/promise-belongs-to.d.ts.map +0 -1
- package/declarations/model/-private/promise-many-array.d.ts.map +0 -1
- package/declarations/model/-private/promise-proxy-base.d.ts +0 -3
- package/declarations/model/-private/promise-proxy-base.d.ts.map +0 -1
- package/declarations/model/-private/record-state.d.ts.map +0 -1
- package/declarations/model/-private/references/belongs-to.d.ts.map +0 -1
- package/declarations/model/-private/references/has-many.d.ts.map +0 -1
- package/declarations/model/-private/schema-provider.d.ts.map +0 -1
- package/declarations/model/-private/type-utils.d.ts.map +0 -1
- package/declarations/model/-private/util.d.ts.map +0 -1
- package/declarations/model/-private.d.ts.map +0 -1
- package/declarations/model/migration-support.d.ts.map +0 -1
- package/declarations/model/migration-support.type-test.d.ts +0 -2
- package/declarations/model/migration-support.type-test.d.ts.map +0 -1
- package/declarations/model.d.ts.map +0 -1
- package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/boolean.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +0 -2
- package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/date.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/number.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/string.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/transform.d.ts.map +0 -1
- package/declarations/serializer/-private/utils.d.ts.map +0 -1
- package/declarations/serializer/json-api.d.ts.map +0 -1
- package/declarations/serializer/json.d.ts.map +0 -1
- package/declarations/serializer/rest.d.ts.map +0 -1
- package/declarations/serializer/transform.d.ts.map +0 -1
- package/declarations/serializer.d.ts.map +0 -1
- package/dist/-private-DFfBszo5.js.map +0 -1
- package/dist/adapter/-private.js.map +0 -1
- package/dist/adapter/error.js.map +0 -1
- package/dist/adapter/json-api.js.map +0 -1
- package/dist/adapter/rest.js.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/compat/-private.js.map +0 -1
- package/dist/compat/builders.js.map +0 -1
- package/dist/compat/extensions.js.map +0 -1
- package/dist/compat/utils.js.map +0 -1
- package/dist/compat.js.map +0 -1
- package/dist/errors-_QQ7xpSn.js.map +0 -1
- package/dist/json-DSOlH9A8.js.map +0 -1
- package/dist/model/-private.js.map +0 -1
- package/dist/model/migration-support.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +0 -1
- package/dist/schema-provider-D_P8ReX6.js.map +0 -1
- package/dist/serialize-into-hash-BxfqWC8u.js.map +0 -1
- package/dist/serializer/json-api.js.map +0 -1
- package/dist/serializer/json.js.map +0 -1
- package/dist/serializer/rest.js.map +0 -1
- package/dist/serializer/transform.js.map +0 -1
- package/dist/serializer.js.map +0 -1
|
@@ -1,258 +1,257 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
2
|
+
## Overview
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
<blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
|
|
5
|
+
<p>
|
|
6
|
+
⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
|
|
7
|
+
If starting a new app or thinking of implementing a new serializer, consider writing a
|
|
8
|
+
<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>
|
|
9
|
+
</p>
|
|
10
|
+
</blockquote>
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
In order to properly manage and present your data, WarpDrive
|
|
13
|
+
needs to understand the structure of data it receives.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
`Serializers` convert data between the server's API format and
|
|
16
|
+
the format WarpDrive understands.
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
Data received from an API response is **normalized** into
|
|
19
|
+
[JSON:API](https://jsonapi.org/) (the format used internally
|
|
20
|
+
by WarpDrive), while data sent to an API is **serialized**
|
|
21
|
+
into the format the API expects.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
### Implementing a Serializer
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
There are only two required serializer methods, one for
|
|
26
|
+
normalizing data from the server API format into JSON:API, and
|
|
27
|
+
another for serializing records via `Snapshots` into the expected
|
|
28
|
+
server API format.
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
To implement a serializer, export a class that conforms to the structure
|
|
31
|
+
described by {@link MinimumSerializerInterface}
|
|
32
|
+
from the `app/serializers/` directory. An example is below.
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
```ts
|
|
35
|
+
import EmberObject from '@ember/object';
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
export default class ApplicationSerializer extends EmberObject {
|
|
38
|
+
normalizeResponse(store, schema, rawPayload) {
|
|
39
|
+
return rawPayload;
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
serialize(snapshot, options) {
|
|
43
|
+
const serializedResource = {
|
|
44
|
+
id: snapshot.id,
|
|
45
|
+
type: snapshot.modelName,
|
|
46
|
+
attributes: snapshot.attributes()
|
|
47
|
+
};
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
return serializedResource;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
### Serializer Resolution
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
`store.serializerFor(name)` will lookup serializers defined in
|
|
58
|
+
`app/serializers/` and return an instance. If no serializer is found, an
|
|
59
|
+
error will be thrown.
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
`serializerFor` first attempts to find a serializer with an exact match on `name`,
|
|
62
|
+
then falls back to checking for the presence of a serializer named `application`.
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
```ts
|
|
65
|
+
store.serializerFor('author');
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
// lookup paths (in order) =>
|
|
68
|
+
// app/serializers/author.js
|
|
69
|
+
// app/serializers/application.js
|
|
70
|
+
```
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
Most requests in @warp-drive/legacy are made with respect to a particular `type` (or `modelName`)
|
|
73
|
+
(e.g., "get me the full collection of **books**" or "get me the **employee** whose id is 37"). We
|
|
74
|
+
refer to this as the **primary** resource `type`.
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
Typically `serializerFor` will be used to find a serializer with a name matching that of the primary
|
|
77
|
+
resource `type` for the request, falling back to the `application` serializer for those types that
|
|
78
|
+
do not have a defined serializer. This is often described as a `per-model` or `per-type` strategy
|
|
79
|
+
for defining serializers. However, because APIs rarely format payloads per-type but rather
|
|
80
|
+
per-API-version, this may not be a desired strategy.
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
It is recommended that applications define only a single `application` adapter and serializer
|
|
83
|
+
where possible.
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
If you have multiple API formats and the per-type strategy is not viable, one strategy is to
|
|
86
|
+
write an `application` adapter and serializer that make use of `options` to specify the desired
|
|
87
|
+
format when making a request.
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
### Using a Serializer
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
Any serializer in `app/serializers/` can be looked up by `name` using `store.serializerFor(name)`.
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
### Default Serializers
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
For applications whose APIs are *very close to* or *exactly* the **REST** format or **JSON:API**
|
|
96
|
+
format the `@ember-data/serializer` package contains implementations these applications can
|
|
97
|
+
extend. It also contains a simple `JSONSerializer` for serializing to/from very basic JSON objects.
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
Many applications will find writing their own serializer to be more performant and less
|
|
100
|
+
complex than extending these classes even when their API format is very close to that expected
|
|
101
|
+
by these serializers.
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
It is recommended that apps write their own serializer to best suit the needs of their API and
|
|
104
|
+
application.
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
@module
|
|
107
107
|
*/
|
|
108
|
-
import EmberObject from
|
|
109
|
-
import type { Store } from
|
|
110
|
-
import type { ModelSchema } from
|
|
111
|
-
import type { EmptyResourceDocument, SingleResourceDocument } from
|
|
108
|
+
import EmberObject from "@ember/object";
|
|
109
|
+
import type { Store } from "@warp-drive/core";
|
|
110
|
+
import type { ModelSchema } from "@warp-drive/core/types";
|
|
111
|
+
import type { EmptyResourceDocument, SingleResourceDocument } from "@warp-drive/core/types/spec/json-api-raw";
|
|
112
112
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
> ⚠️ CAUTION you likely want the docs for {@link MinimumSerializerInterface}
|
|
114
|
+
> as extending this abstract class is unnecessary.
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
`Serializer` is an abstract base class that you may override in your
|
|
117
|
+
application to customize it for your backend. The minimum set of methods
|
|
118
|
+
that you should implement is:
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
* `normalizeResponse()`
|
|
121
|
+
* `serialize()`
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
And you can optionally override the following methods:
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
* `normalize()`
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
For an example implementation, see
|
|
128
|
+
[JSONSerializer](JSONSerializer), the included JSON serializer.
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
@class Serializer
|
|
131
|
+
@public
|
|
132
132
|
*/
|
|
133
133
|
export declare class Serializer extends EmberObject {
|
|
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
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
134
|
+
store: Store;
|
|
135
|
+
/**
|
|
136
|
+
The `store` property is the application's `store` that contains
|
|
137
|
+
all records. It can be used to look up serializers for other model
|
|
138
|
+
types that may be nested inside the payload response.
|
|
139
|
+
|
|
140
|
+
Example:
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
Serializer.extend({
|
|
144
|
+
extractRelationship(relationshipModelName, relationshipHash) {
|
|
145
|
+
let modelClass = this.store.modelFor(relationshipModelName);
|
|
146
|
+
let relationshipSerializer = this.store.serializerFor(relationshipModelName);
|
|
147
|
+
return relationshipSerializer.normalize(modelClass, relationshipHash);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
@property store
|
|
153
|
+
@type {Store}
|
|
154
|
+
@public
|
|
155
|
+
*/
|
|
156
|
+
/**
|
|
157
|
+
The `normalizeResponse` method is used to normalize a payload from the
|
|
158
|
+
server to a JSON-API Document.
|
|
159
|
+
|
|
160
|
+
http://jsonapi.org/format/#document-structure
|
|
161
|
+
|
|
162
|
+
Example:
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
Serializer.extend({
|
|
166
|
+
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
|
167
|
+
if (requestType === 'findRecord') {
|
|
168
|
+
return this.normalize(primaryModelClass, payload);
|
|
169
|
+
} else {
|
|
170
|
+
return payload.reduce(function(documentHash, item) {
|
|
171
|
+
let { data, included } = this.normalize(primaryModelClass, item);
|
|
172
|
+
documentHash.included.push(...included);
|
|
173
|
+
documentHash.data.push(data);
|
|
174
|
+
return documentHash;
|
|
175
|
+
}, { data: [], included: [] })
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
@since 1.13.0
|
|
182
|
+
@public
|
|
183
|
+
@param {Store} store
|
|
184
|
+
@param {Model} primaryModelClass
|
|
185
|
+
@param {Object} payload
|
|
186
|
+
@param {String|Number} id
|
|
187
|
+
@param {String} requestType
|
|
188
|
+
@return {Object} JSON-API Document
|
|
189
|
+
*/
|
|
190
|
+
/**
|
|
191
|
+
The `serialize` method is used when a record is saved in order to convert
|
|
192
|
+
the record into the form that your external data source expects.
|
|
193
|
+
|
|
194
|
+
`serialize` takes an optional `options` hash with a single option:
|
|
195
|
+
|
|
196
|
+
- `includeId`: If this is `true`, `serialize` should include the ID
|
|
197
|
+
in the serialized object it builds.
|
|
198
|
+
|
|
199
|
+
Example:
|
|
200
|
+
|
|
201
|
+
```js
|
|
202
|
+
Serializer.extend({
|
|
203
|
+
serialize(snapshot, options) {
|
|
204
|
+
let json = {
|
|
205
|
+
id: snapshot.id
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
snapshot.eachAttribute((key, attribute) => {
|
|
209
|
+
json[key] = snapshot.attr(key);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
snapshot.eachRelationship((key, relationship) => {
|
|
213
|
+
if (relationship.kind === 'belongsTo') {
|
|
214
|
+
json[key] = snapshot.belongsTo(key, { id: true });
|
|
215
|
+
} else if (relationship.kind === 'hasMany') {
|
|
216
|
+
json[key] = snapshot.hasMany(key, { ids: true });
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
return json;
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
@public
|
|
226
|
+
@param {Snapshot} snapshot
|
|
227
|
+
@param {Object} [options]
|
|
228
|
+
@return {Object}
|
|
229
|
+
*/
|
|
230
|
+
/**
|
|
231
|
+
The `normalize` method is used to convert a payload received from your
|
|
232
|
+
external data source into the normalized form `store.push()` expects. You
|
|
233
|
+
should override this method, munge the hash and return the normalized
|
|
234
|
+
payload.
|
|
235
|
+
|
|
236
|
+
Example:
|
|
237
|
+
|
|
238
|
+
```js
|
|
239
|
+
Serializer.extend({
|
|
240
|
+
normalize(modelClass, resourceHash) {
|
|
241
|
+
let data = {
|
|
242
|
+
id: resourceHash.id,
|
|
243
|
+
type: modelClass.modelName,
|
|
244
|
+
attributes: resourceHash
|
|
245
|
+
};
|
|
246
|
+
return { data: data };
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
@public
|
|
252
|
+
@param {Model} typeClass
|
|
253
|
+
@param {Object} hash
|
|
254
|
+
@return {Object}
|
|
255
|
+
*/
|
|
256
|
+
normalize(_typeClass: ModelSchema, hash: Record<string, unknown>): SingleResourceDocument | EmptyResourceDocument;
|
|
257
257
|
}
|
|
258
|
-
//# sourceMappingURL=serializer.d.ts.map
|
package/dist/adapter/-private.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { d as determineBodyPromise, g as fetch, p as parseResponseHeaders, b as serializeIntoHash, s as serializeQueryParams, a as setupFastboot } from "../serialize-into-hash-
|
|
1
|
+
export { d as determineBodyPromise, g as fetch, p as parseResponseHeaders, b as serializeIntoHash, s as serializeQueryParams, a as setupFastboot } from "../serialize-into-hash-Bp58npke.js";
|
package/dist/adapter/error.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { getOrSetGlobal } from '@warp-drive/core/types/-private';
|
|
2
2
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
6
|
+
|
|
3
7
|
function _AdapterError(errors, message = 'Adapter operation failed') {
|
|
4
8
|
this.isAdapterError = true;
|
|
5
9
|
const error = Error.call(this, message);
|
|
6
10
|
if (error) {
|
|
7
11
|
this.stack = error.stack;
|
|
12
|
+
// @ts-expect-error untyped
|
|
8
13
|
this.description = error.description;
|
|
14
|
+
// @ts-expect-error untyped
|
|
9
15
|
this.fileName = error.fileName;
|
|
16
|
+
// @ts-expect-error untyped
|
|
10
17
|
this.lineNumber = error.lineNumber;
|
|
11
18
|
this.message = error.message;
|
|
12
19
|
this.name = error.name;
|
|
20
|
+
// @ts-expect-error untyped
|
|
13
21
|
this.number = error.number;
|
|
14
22
|
}
|
|
15
23
|
this.errors = errors || [{
|
|
@@ -37,6 +45,7 @@ function extend(ParentErrorClass, defaultMessage) {
|
|
|
37
45
|
})(Array.isArray(errors || [])) : {};
|
|
38
46
|
ParentErrorClass.call(this, errors, message || defaultMessage);
|
|
39
47
|
};
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
40
49
|
ErrorClass.prototype = Object.create(ParentErrorClass.prototype);
|
|
41
50
|
ErrorClass.extend = extendFn(ErrorClass);
|
|
42
51
|
return ErrorClass;
|
|
@@ -102,6 +111,7 @@ function extend(ParentErrorClass, defaultMessage) {
|
|
|
102
111
|
@public
|
|
103
112
|
*/
|
|
104
113
|
// TODO @deprecate extractError documentation
|
|
114
|
+
|
|
105
115
|
const InvalidError = getOrSetGlobal('InvalidError', extend(AdapterError, 'The adapter rejected the commit because it was invalid'));
|
|
106
116
|
InvalidError.prototype.code = 'InvalidError';
|
|
107
117
|
|
|
@@ -133,6 +143,7 @@ InvalidError.prototype.code = 'InvalidError';
|
|
|
133
143
|
@class TimeoutError
|
|
134
144
|
@public
|
|
135
145
|
*/
|
|
146
|
+
|
|
136
147
|
const TimeoutError = getOrSetGlobal('TimeoutError', extend(AdapterError, 'The adapter operation timed out'));
|
|
137
148
|
TimeoutError.prototype.code = 'TimeoutError';
|
|
138
149
|
|
|
@@ -145,6 +156,7 @@ TimeoutError.prototype.code = 'TimeoutError';
|
|
|
145
156
|
@class AbortError
|
|
146
157
|
@public
|
|
147
158
|
*/
|
|
159
|
+
|
|
148
160
|
const AbortError = getOrSetGlobal('AbortError', extend(AdapterError, 'The adapter operation was aborted'));
|
|
149
161
|
AbortError.prototype.code = 'AbortError';
|
|
150
162
|
|
|
@@ -177,6 +189,7 @@ AbortError.prototype.code = 'AbortError';
|
|
|
177
189
|
@class UnauthorizedError
|
|
178
190
|
@public
|
|
179
191
|
*/
|
|
192
|
+
|
|
180
193
|
const UnauthorizedError = getOrSetGlobal('UnauthorizedError', extend(AdapterError, 'The adapter operation is unauthorized'));
|
|
181
194
|
UnauthorizedError.prototype.code = 'UnauthorizedError';
|
|
182
195
|
|
|
@@ -190,6 +203,7 @@ UnauthorizedError.prototype.code = 'UnauthorizedError';
|
|
|
190
203
|
@class ForbiddenError
|
|
191
204
|
@public
|
|
192
205
|
*/
|
|
206
|
+
|
|
193
207
|
const ForbiddenError = getOrSetGlobal('ForbiddenError', extend(AdapterError, 'The adapter operation is forbidden'));
|
|
194
208
|
ForbiddenError.prototype.code = 'ForbiddenError';
|
|
195
209
|
|
|
@@ -225,6 +239,7 @@ ForbiddenError.prototype.code = 'ForbiddenError';
|
|
|
225
239
|
@class NotFoundError
|
|
226
240
|
@public
|
|
227
241
|
*/
|
|
242
|
+
|
|
228
243
|
const NotFoundError = getOrSetGlobal('NotFoundError', extend(AdapterError, 'The adapter could not find the resource'));
|
|
229
244
|
NotFoundError.prototype.code = 'NotFoundError';
|
|
230
245
|
|
|
@@ -238,6 +253,7 @@ NotFoundError.prototype.code = 'NotFoundError';
|
|
|
238
253
|
@class ConflictError
|
|
239
254
|
@public
|
|
240
255
|
*/
|
|
256
|
+
|
|
241
257
|
const ConflictError = getOrSetGlobal('ConflictError', extend(AdapterError, 'The adapter operation failed due to a conflict'));
|
|
242
258
|
ConflictError.prototype.code = 'ConflictError';
|
|
243
259
|
|
|
@@ -249,6 +265,7 @@ ConflictError.prototype.code = 'ConflictError';
|
|
|
249
265
|
@class ServerError
|
|
250
266
|
@public
|
|
251
267
|
*/
|
|
268
|
+
|
|
252
269
|
const ServerError = getOrSetGlobal('ServerError', extend(AdapterError, 'The adapter operation failed due to a server error'));
|
|
253
270
|
ServerError.prototype.code = 'ServerError';
|
|
254
271
|
export { AbortError, AdapterError, ConflictError, ForbiddenError, InvalidError, NotFoundError, ServerError, TimeoutError, UnauthorizedError };
|
package/dist/adapter/json-api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { dasherize, pluralize } from '@warp-drive/utilities/string';
|
|
2
2
|
import '@ember/debug';
|
|
3
3
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
4
|
-
import { b as serializeIntoHash } from "../serialize-into-hash-
|
|
4
|
+
import { b as serializeIntoHash } from "../serialize-into-hash-Bp58npke.js";
|
|
5
5
|
import { RESTAdapter } from './rest.js';
|
|
6
6
|
class JSONAPIAdapter extends RESTAdapter {
|
|
7
7
|
_defaultContentType = 'application/vnd.api+json';
|
package/dist/adapter/rest.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getOwner } from '@ember/application';
|
|
|
2
2
|
import { warn } from '@ember/debug';
|
|
3
3
|
import { computed } from '@ember/object';
|
|
4
4
|
import { Adapter, BuildURLMixin } from '../adapter.js';
|
|
5
|
-
import { b as serializeIntoHash, d as determineBodyPromise, g as getFetchFunction, s as serializeQueryParams, p as parseResponseHeaders } from "../serialize-into-hash-
|
|
5
|
+
import { b as serializeIntoHash, d as determineBodyPromise, g as getFetchFunction, s as serializeQueryParams, p as parseResponseHeaders } from "../serialize-into-hash-Bp58npke.js";
|
|
6
6
|
import { InvalidError, ServerError, ConflictError, NotFoundError, ForbiddenError, UnauthorizedError, AdapterError, TimeoutError, AbortError } from './error.js';
|
|
7
7
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
8
8
|
import { d as decorateMethodV2 } from "../runtime-BPCpkOf1-BKOwiRJp.js";
|
|
@@ -11,6 +11,8 @@ import { d as decorateMethodV2 } from "../runtime-BPCpkOf1-BKOwiRJp.js";
|
|
|
11
11
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
12
12
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
13
13
|
|
|
14
|
+
const AdapterWithBuildURLMixin = Adapter.extend(BuildURLMixin);
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
|
|
16
18
|
<p>
|
|
@@ -238,7 +240,7 @@ import { d as decorateMethodV2 } from "../runtime-BPCpkOf1-BKOwiRJp.js";
|
|
|
238
240
|
@constructor
|
|
239
241
|
@uses BuildURLMixin
|
|
240
242
|
*/
|
|
241
|
-
class RESTAdapter extends
|
|
243
|
+
class RESTAdapter extends AdapterWithBuildURLMixin {
|
|
242
244
|
/**
|
|
243
245
|
This property allows ajax to still be used instead when `false`.
|
|
244
246
|
@property useFetch
|
|
@@ -600,11 +602,6 @@ class RESTAdapter extends Adapter.extend(BuildURLMixin) {
|
|
|
600
602
|
* Links beginning with a single `/` will have the current adapter's `host` value prepended to it.
|
|
601
603
|
* Links with no beginning `/` will have a parentURL prepended to it, via the current adapter's `buildURL`.
|
|
602
604
|
@public
|
|
603
|
-
@param {Store} store
|
|
604
|
-
@param {Snapshot} snapshot
|
|
605
|
-
@param {String} url
|
|
606
|
-
@param {Object} relationship meta object describing the relationship
|
|
607
|
-
@return {Promise} promise
|
|
608
605
|
*/
|
|
609
606
|
findBelongsTo(store, snapshot, url, relationship) {
|
|
610
607
|
const id = snapshot.id;
|
|
@@ -779,6 +776,7 @@ class RESTAdapter extends Adapter.extend(BuildURLMixin) {
|
|
|
779
776
|
if (this.isSuccess(status, headers, payload)) {
|
|
780
777
|
return payload;
|
|
781
778
|
} else if (this.isInvalid(status, headers, payload)) {
|
|
779
|
+
// @ts-expect-error needs cast to JsonApiError
|
|
782
780
|
return new InvalidError(typeof payload === 'object' && 'errors' in payload ? payload.errors : undefined);
|
|
783
781
|
}
|
|
784
782
|
const errors = this.normalizeErrorResponse(status, headers, payload);
|