@warp-drive/legacy 5.6.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +23 -0
- package/README.md +54 -0
- package/addon-main.cjs +5 -0
- package/declarations/adapter/-private/build-url-mixin.d.ts +34 -0
- package/declarations/adapter/-private/build-url-mixin.d.ts.map +1 -0
- package/declarations/adapter/-private/fastboot-interface.d.ts +9 -0
- package/declarations/adapter/-private/fastboot-interface.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts +8 -0
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/determine-body-promise.d.ts +5 -0
- package/declarations/adapter/-private/utils/determine-body-promise.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/fetch.d.ts +9 -0
- package/declarations/adapter/-private/utils/fetch.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/parse-response-headers.d.ts +2 -0
- package/declarations/adapter/-private/utils/parse-response-headers.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +7 -0
- package/declarations/adapter/-private/utils/serialize-into-hash.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts +6 -0
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts.map +1 -0
- package/declarations/adapter/-private.d.ts +6 -0
- package/declarations/adapter/-private.d.ts.map +1 -0
- package/declarations/adapter/error.d.ts +188 -0
- package/declarations/adapter/error.d.ts.map +1 -0
- package/declarations/adapter/json-api.d.ts +234 -0
- package/declarations/adapter/json-api.d.ts.map +1 -0
- package/declarations/adapter/rest.d.ts +823 -0
- package/declarations/adapter/rest.d.ts.map +1 -0
- package/declarations/adapter.d.ts +801 -0
- package/declarations/adapter.d.ts.map +1 -0
- package/declarations/compat/-private.d.ts +14 -0
- package/declarations/compat/-private.d.ts.map +1 -0
- package/declarations/compat/builders/find-all.d.ts +33 -0
- package/declarations/compat/builders/find-all.d.ts.map +1 -0
- package/declarations/compat/builders/find-record.d.ts +54 -0
- package/declarations/compat/builders/find-record.d.ts.map +1 -0
- package/declarations/compat/builders/query.d.ts +61 -0
- package/declarations/compat/builders/query.d.ts.map +1 -0
- package/declarations/compat/builders/save-record.d.ts +32 -0
- package/declarations/compat/builders/save-record.d.ts.map +1 -0
- package/declarations/compat/builders/utils.d.ts +4 -0
- package/declarations/compat/builders/utils.d.ts.map +1 -0
- package/declarations/compat/builders.d.ts +15 -0
- package/declarations/compat/builders.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +47 -0
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +3 -0
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +12 -0
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +6 -0
- package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +3 -0
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +527 -0
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +224 -0
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/serializer-response.d.ts +7 -0
- package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +89 -0
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/snapshot.d.ts +237 -0
- package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +1 -0
- package/declarations/compat/utils.d.ts +138 -0
- package/declarations/compat/utils.d.ts.map +1 -0
- package/declarations/compat.d.ts +134 -0
- package/declarations/compat.d.ts.map +1 -0
- package/declarations/model/-private/attr.d.ts +165 -0
- package/declarations/model/-private/attr.d.ts.map +1 -0
- package/declarations/model/-private/attr.type-test.d.ts +2 -0
- package/declarations/model/-private/attr.type-test.d.ts.map +1 -0
- package/declarations/model/-private/belongs-to.d.ts +173 -0
- package/declarations/model/-private/belongs-to.d.ts.map +1 -0
- package/declarations/model/-private/belongs-to.type-test.d.ts +2 -0
- package/declarations/model/-private/belongs-to.type-test.d.ts.map +1 -0
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +6 -0
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
- package/declarations/model/-private/errors.d.ts +290 -0
- package/declarations/model/-private/errors.d.ts.map +1 -0
- package/declarations/model/-private/has-many.d.ts +164 -0
- package/declarations/model/-private/has-many.d.ts.map +1 -0
- package/declarations/model/-private/has-many.type-test.d.ts +2 -0
- package/declarations/model/-private/has-many.type-test.d.ts.map +1 -0
- package/declarations/model/-private/hooks.d.ts +11 -0
- package/declarations/model/-private/hooks.d.ts.map +1 -0
- package/declarations/model/-private/legacy-relationships-support.d.ts +57 -0
- package/declarations/model/-private/legacy-relationships-support.d.ts.map +1 -0
- package/declarations/model/-private/model-for-mixin.d.ts +4 -0
- package/declarations/model/-private/model-for-mixin.d.ts.map +1 -0
- package/declarations/model/-private/model-methods.d.ts +35 -0
- package/declarations/model/-private/model-methods.d.ts.map +1 -0
- package/declarations/model/-private/model.d.ts +1270 -0
- package/declarations/model/-private/model.d.ts.map +1 -0
- package/declarations/model/-private/model.type-test.d.ts +2 -0
- package/declarations/model/-private/model.type-test.d.ts.map +1 -0
- package/declarations/model/-private/notify-changes.d.ts +5 -0
- package/declarations/model/-private/notify-changes.d.ts.map +1 -0
- package/declarations/model/-private/promise-belongs-to.d.ts +40 -0
- package/declarations/model/-private/promise-belongs-to.d.ts.map +1 -0
- package/declarations/model/-private/promise-many-array.d.ts +126 -0
- package/declarations/model/-private/promise-many-array.d.ts.map +1 -0
- package/declarations/model/-private/promise-proxy-base.d.ts +3 -0
- package/declarations/model/-private/promise-proxy-base.d.ts.map +1 -0
- package/declarations/model/-private/record-state.d.ts +78 -0
- package/declarations/model/-private/record-state.d.ts.map +1 -0
- package/declarations/model/-private/references/belongs-to.d.ts +495 -0
- package/declarations/model/-private/references/belongs-to.d.ts.map +1 -0
- package/declarations/model/-private/references/has-many.d.ts +504 -0
- package/declarations/model/-private/references/has-many.d.ts.map +1 -0
- package/declarations/model/-private/schema-provider.d.ts +63 -0
- package/declarations/model/-private/schema-provider.d.ts.map +1 -0
- package/declarations/model/-private/type-utils.d.ts +57 -0
- package/declarations/model/-private/type-utils.d.ts.map +1 -0
- package/declarations/model/-private/util.d.ts +6 -0
- package/declarations/model/-private/util.d.ts.map +1 -0
- package/declarations/model/-private.d.ts +8 -0
- package/declarations/model/-private.d.ts.map +1 -0
- package/declarations/model/migration-support.d.ts +287 -0
- package/declarations/model/migration-support.d.ts.map +1 -0
- package/declarations/model/migration-support.type-test.d.ts +2 -0
- package/declarations/model/migration-support.type-test.d.ts.map +1 -0
- package/declarations/model.d.ts +50 -0
- package/declarations/model.d.ts.map +1 -0
- package/declarations/serializer/-private/embedded-records-mixin.d.ts +97 -0
- package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
- package/declarations/serializer/-private/transforms/boolean.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +2 -0
- package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/date.d.ts +28 -0
- package/declarations/serializer/-private/transforms/date.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/number.d.ts +29 -0
- package/declarations/serializer/-private/transforms/number.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/string.d.ts +29 -0
- package/declarations/serializer/-private/transforms/string.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/transform.d.ts +119 -0
- package/declarations/serializer/-private/transforms/transform.d.ts.map +1 -0
- package/declarations/serializer/-private/utils.d.ts +4 -0
- package/declarations/serializer/-private/utils.d.ts.map +1 -0
- package/declarations/serializer/json-api.d.ts +496 -0
- package/declarations/serializer/json-api.d.ts.map +1 -0
- package/declarations/serializer/json.d.ts +1047 -0
- package/declarations/serializer/json.d.ts.map +1 -0
- package/declarations/serializer/rest.d.ts +554 -0
- package/declarations/serializer/rest.d.ts.map +1 -0
- package/declarations/serializer/transform.d.ts +6 -0
- package/declarations/serializer/transform.d.ts.map +1 -0
- package/declarations/serializer.d.ts +258 -0
- package/declarations/serializer.d.ts.map +1 -0
- package/dist/-private-DFfBszo5.js +1182 -0
- package/dist/-private-DFfBszo5.js.map +1 -0
- package/dist/adapter/-private.js +1 -0
- package/dist/adapter/-private.js.map +1 -0
- package/dist/adapter/error.js +254 -0
- package/dist/adapter/error.js.map +1 -0
- package/dist/adapter/json-api.js +129 -0
- package/dist/adapter/json-api.js.map +1 -0
- package/dist/adapter/rest.js +1262 -0
- package/dist/adapter/rest.js.map +1 -0
- package/dist/adapter.js +1284 -0
- package/dist/adapter.js.map +1 -0
- package/dist/compat/-private.js +1 -0
- package/dist/compat/-private.js.map +1 -0
- package/dist/compat/builders.js +292 -0
- package/dist/compat/builders.js.map +1 -0
- package/dist/compat/utils.js +225 -0
- package/dist/compat/utils.js.map +1 -0
- package/dist/compat.js +999 -0
- package/dist/compat.js.map +1 -0
- package/dist/errors-D74uk36r.js +2541 -0
- package/dist/errors-D74uk36r.js.map +1 -0
- package/dist/json-BCH3fil7.js +1349 -0
- package/dist/json-BCH3fil7.js.map +1 -0
- package/dist/model/-private.js +2 -0
- package/dist/model/-private.js.map +1 -0
- package/dist/model/migration-support.js +453 -0
- package/dist/model/migration-support.js.map +1 -0
- package/dist/model.js +736 -0
- package/dist/model.js.map +1 -0
- package/dist/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +1 -0
- package/dist/schema-provider-CXFLTMjg.js +2228 -0
- package/dist/schema-provider-CXFLTMjg.js.map +1 -0
- package/dist/serialize-into-hash-BxfqWC8u.js +260 -0
- package/dist/serialize-into-hash-BxfqWC8u.js.map +1 -0
- package/dist/serializer/json-api.js +514 -0
- package/dist/serializer/json-api.js.map +1 -0
- package/dist/serializer/json.js +6 -0
- package/dist/serializer/json.js.map +1 -0
- package/dist/serializer/rest.js +1245 -0
- package/dist/serializer/rest.js.map +1 -0
- package/dist/serializer/transform.js +313 -0
- package/dist/serializer/transform.js.map +1 -0
- package/dist/serializer.js +252 -0
- package/dist/serializer.js.map +1 -0
- package/logos/NCC-1701-a-blue.svg +4 -0
- package/logos/NCC-1701-a-gold.svg +4 -0
- package/logos/NCC-1701-a-gold_100.svg +1 -0
- package/logos/NCC-1701-a-gold_base-64.txt +1 -0
- package/logos/NCC-1701-a.svg +4 -0
- package/logos/README.md +4 -0
- package/logos/docs-badge.svg +2 -0
- package/logos/ember-data-logo-dark.svg +12 -0
- package/logos/ember-data-logo-light.svg +12 -0
- package/logos/github-header.svg +444 -0
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +4 -0
- package/logos/warp-drive-logo-gold.svg +4 -0
- package/package.json +72 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import type { Store } from '@warp-drive/core';
|
|
2
|
+
import type { ModelSchema } from '@warp-drive/core/types';
|
|
3
|
+
import type { ObjectValue } from '@warp-drive/core/types/json/raw';
|
|
4
|
+
import type { JsonApiDocument, SingleResourceDocument } from '@warp-drive/core/types/spec/json-api-raw';
|
|
5
|
+
import type { AdapterPayload } from './minimum-adapter-interface.ts';
|
|
6
|
+
import type { Snapshot } from './snapshot.ts';
|
|
7
|
+
export type SerializerOptions = {
|
|
8
|
+
includeId?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type RequestType = 'findRecord' | 'queryRecord' | 'findAll' | 'findBelongsTo' | 'findHasMany' | 'findMany' | 'query' | 'createRecord' | 'deleteRecord' | 'updateRecord';
|
|
11
|
+
/**
|
|
12
|
+
* <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
|
|
13
|
+
<p>
|
|
14
|
+
⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
|
|
15
|
+
If starting a new app or thinking of implementing a new adapter, consider writing a
|
|
16
|
+
<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>
|
|
17
|
+
</p>
|
|
18
|
+
</blockquote>
|
|
19
|
+
|
|
20
|
+
The following documentation describes the methods an application
|
|
21
|
+
serializer should implement with descriptions around when an
|
|
22
|
+
application might expect these methods to be called.
|
|
23
|
+
|
|
24
|
+
Methods that are not required are marked as **optional**.
|
|
25
|
+
|
|
26
|
+
@class (Interface) Serializer
|
|
27
|
+
@public
|
|
28
|
+
*/
|
|
29
|
+
export interface MinimumSerializerInterface {
|
|
30
|
+
/**
|
|
31
|
+
* This method is responsible for normalizing the value resolved from the promise returned
|
|
32
|
+
* by an Adapter request into the format expected by the `Store`.
|
|
33
|
+
*
|
|
34
|
+
* The output should be a [JSON:API Document](https://jsonapi.org/format/#document-structure)
|
|
35
|
+
* with the following additional restrictions:
|
|
36
|
+
*
|
|
37
|
+
* - `type` should be formatted in the `singular` `dasherized` `lowercase` form
|
|
38
|
+
* - `members` (the property names of attributes and relationships) should be formatted
|
|
39
|
+
* to match their definition in the corresponding `Model` definition. Typically this
|
|
40
|
+
* will be `camelCase`.
|
|
41
|
+
* - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
|
|
42
|
+
* a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
|
|
43
|
+
* and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
* @param {Store} store The store service that initiated the request being normalized
|
|
47
|
+
* @param {ModelSchema} schema An object with methods for accessing information about
|
|
48
|
+
* the type, attributes and relationships of the primary type associated with the request.
|
|
49
|
+
* @param {JSONObject} rawPayload The raw JSON response data returned from an API request.
|
|
50
|
+
* This correlates to the value the promise returned by the adapter method that performed
|
|
51
|
+
* the request resolved to.
|
|
52
|
+
* @param {string|null} id For a findRecord request, this is the id initially provided
|
|
53
|
+
* in the call to store.findRecord. Else this value is null.
|
|
54
|
+
* @param {'findRecord' | 'queryRecord' | 'findAll' | 'findBelongsTo' | 'findHasMany' | 'findMany' | 'query' | 'createRecord' | 'deleteRecord' | 'updateRecord'} requestType The
|
|
55
|
+
* type of request the Adapter had been asked to perform.
|
|
56
|
+
*
|
|
57
|
+
* @return {JsonApiDocument} a document following the structure of a JSON:API Document.
|
|
58
|
+
*/
|
|
59
|
+
normalizeResponse(store: Store, schema: ModelSchema, rawPayload: AdapterPayload, id: string | null, requestType: 'findRecord' | 'queryRecord' | 'findAll' | 'findBelongsTo' | 'findHasMany' | 'findMany' | 'query' | 'createRecord' | 'deleteRecord' | 'updateRecord'): JsonApiDocument;
|
|
60
|
+
/**
|
|
61
|
+
* This method is responsible for serializing an individual record
|
|
62
|
+
* via a [Snapshot](Snapshot) into the format expected by the API.
|
|
63
|
+
*
|
|
64
|
+
* This method is called by `snapshot.serialize()`.
|
|
65
|
+
*
|
|
66
|
+
* When using `Model`, this method is called by `record.serialize()`.
|
|
67
|
+
*
|
|
68
|
+
* When using `JSONAPIAdapter` or `RESTAdapter` this method is called
|
|
69
|
+
* by `updateRecord` and `createRecord` if `Serializer.serializeIntoHash`
|
|
70
|
+
* is not implemented.
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
* @param {Snapshot} snapshot A Snapshot for the record to serialize
|
|
74
|
+
* @param {Object} [options]
|
|
75
|
+
*/
|
|
76
|
+
serialize(snapshot: Snapshot, options?: SerializerOptions): ObjectValue;
|
|
77
|
+
/**
|
|
78
|
+
* This method is intended to normalize data into a [JSON:API Document](https://jsonapi.org/format/#document-structure)
|
|
79
|
+
* with a data member containing a single [Resource](https://jsonapi.org/format/#document-resource-objects).
|
|
80
|
+
*
|
|
81
|
+
* - `type` should be formatted in the singular, dasherized and lowercase form
|
|
82
|
+
* - `members` (the property names of attributes and relationships) should be formatted
|
|
83
|
+
* to match their definition in the corresponding `Model` definition. Typically this
|
|
84
|
+
* will be `camelCase`.
|
|
85
|
+
* - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
|
|
86
|
+
* a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
|
|
87
|
+
* and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
|
|
88
|
+
*
|
|
89
|
+
* This method is called by the `Store` when `store.normalize(modelName, payload)` is
|
|
90
|
+
* called. It is recommended to use `store.serializerFor(modelName).normalizeResponse`
|
|
91
|
+
* over `store.normalize`.
|
|
92
|
+
*
|
|
93
|
+
* This method may be called when also using the `RESTSerializer`
|
|
94
|
+
* when `serializer.pushPayload` is called by `store.pushPayload`.
|
|
95
|
+
* However, it is recommended to use `store.push` over `store.pushPayload` after normalizing
|
|
96
|
+
* the payload directly.
|
|
97
|
+
*
|
|
98
|
+
* Example:
|
|
99
|
+
* ```js
|
|
100
|
+
* function pushPayload(store, modelName, rawPayload) {
|
|
101
|
+
* const ModelClass = store.modelFor(modelName);
|
|
102
|
+
* const serializer = store.serializerFor(modelName);
|
|
103
|
+
* const jsonApiPayload = serializer.normalizeResponse(store, ModelClass, rawPayload, null, 'query');
|
|
104
|
+
*
|
|
105
|
+
* return store.push(jsonApiPayload);
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* This method may be called when also using the `JSONAPISerializer`
|
|
110
|
+
* when normalizing included records. If mixing serializer usage in this way
|
|
111
|
+
* we recommend implementing this method, but caution that it may lead
|
|
112
|
+
* to unexpected mixing of formats.
|
|
113
|
+
*
|
|
114
|
+
* This method may also be called when normalizing embedded relationships when
|
|
115
|
+
* using the `EmbeddedRecordsMixin`. If using this mixin in a serializer in
|
|
116
|
+
* your application we recommend implementing this method, but caution that
|
|
117
|
+
* it may lead to unexpected mixing of formats.
|
|
118
|
+
*
|
|
119
|
+
* @public
|
|
120
|
+
* @optional
|
|
121
|
+
* @param {ModelSchema} schema An object with methods for accessing information about
|
|
122
|
+
* the type, attributes and relationships of the primary type associated with the request.
|
|
123
|
+
* @param {JSONObject} rawPayload Some raw JSON data to be normalized into a JSON:API Resource.
|
|
124
|
+
* @param {String} [prop] When called by the EmbeddedRecordsMixin this param will be the
|
|
125
|
+
* property at which the object provided as rawPayload was found.
|
|
126
|
+
* @return {SingleResourceDocument} A JSON:API Document
|
|
127
|
+
* containing a single JSON:API Resource
|
|
128
|
+
* as its primary data.
|
|
129
|
+
*/
|
|
130
|
+
normalize?(schema: ModelSchema, rawPayload: ObjectValue, prop?: string): SingleResourceDocument;
|
|
131
|
+
/**
|
|
132
|
+
* When using `JSONAPIAdapter` or `RESTAdapter` this method is called
|
|
133
|
+
* by `adapter.updateRecord` and `adapter.createRecord` if `serializer.serializeIntoHash`
|
|
134
|
+
* is implemented. If this method is not implemented, `serializer.serialize`
|
|
135
|
+
* will be called in this case.
|
|
136
|
+
*
|
|
137
|
+
* You can use this method to customize the root keys serialized into the payload.
|
|
138
|
+
* The hash property should be modified by reference.
|
|
139
|
+
*
|
|
140
|
+
* For instance, your API may expect resources to be keyed by underscored type in the payload:
|
|
141
|
+
*
|
|
142
|
+
* ```js
|
|
143
|
+
* {
|
|
144
|
+
* _user: {
|
|
145
|
+
* type: 'user',
|
|
146
|
+
* id: '1'
|
|
147
|
+
* }
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* Which when using these adapters can be achieved by implementing this method similar
|
|
152
|
+
* to the following:
|
|
153
|
+
*
|
|
154
|
+
* ```js
|
|
155
|
+
* serializeIntoHash(hash, ModelClass, snapshot, options) {
|
|
156
|
+
* hash[`_${snapshot.modelName}`] = this.serialize(snapshot, options).data;
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @public
|
|
161
|
+
* @optional
|
|
162
|
+
* @param hash A top most object of the request payload onto
|
|
163
|
+
* which to append the serialized record
|
|
164
|
+
* @param {ModelSchema} schema An object with methods for accessing information about
|
|
165
|
+
* the type, attributes and relationships of the primary type associated with the request.
|
|
166
|
+
* @param {Snapshot} snapshot A Snapshot for the record to serialize
|
|
167
|
+
* @param [options]
|
|
168
|
+
* @return {void}
|
|
169
|
+
*/
|
|
170
|
+
serializeIntoHash?(hash: object, schema: ModelSchema, snapshot: Snapshot, options?: SerializerOptions): void;
|
|
171
|
+
/**
|
|
172
|
+
* This method allows for normalization of data when `store.pushPayload` is called
|
|
173
|
+
* and should be implemented if you want to use that method.
|
|
174
|
+
*
|
|
175
|
+
* The method is responsible for pushing new data to the store using `store.push`
|
|
176
|
+
* once any necessary normalization has occurred, and no data in the store will be
|
|
177
|
+
* updated unless it does so.
|
|
178
|
+
*
|
|
179
|
+
* The normalized form pushed to the store should be a [JSON:API Document](https://jsonapi.org/format/#document-structure)
|
|
180
|
+
* with the following additional restrictions:
|
|
181
|
+
*
|
|
182
|
+
* - `type` should be formatted in the singular, dasherized and lowercase form
|
|
183
|
+
* - `members` (the property names of attributes and relationships) should be formatted
|
|
184
|
+
* to match their definition in the corresponding `Model` definition. Typically this
|
|
185
|
+
* will be `camelCase`.
|
|
186
|
+
* - [`lid`](https://github.com/emberjs/rfcs/blob/main/text/0403-ember-data-identifiers.md) is
|
|
187
|
+
* a valid optional sibling to `id` and `type` in both [Resources](https://jsonapi.org/format/#document-resource-objects)
|
|
188
|
+
* and [Resource Identifier Objects](https://jsonapi.org/format/#document-resource-identifier-objects)
|
|
189
|
+
*
|
|
190
|
+
* If you need better control over normalization or want access to the records being added or updated
|
|
191
|
+
* in the store, we recommended using `store.push` over `store.pushPayload` after normalizing
|
|
192
|
+
* the payload directly. This can even take advantage of an existing serializer for the format
|
|
193
|
+
* the data is in, for example:
|
|
194
|
+
*
|
|
195
|
+
* ```js
|
|
196
|
+
* function pushPayload(store, modelName, rawPayload) {
|
|
197
|
+
* const ModelClass = store.modelFor(modelName);
|
|
198
|
+
* const serializer = store.serializerFor(modelName);
|
|
199
|
+
* const jsonApiPayload = serializer.normalizeResponse(store, ModelClass, rawPayload, null, 'query');
|
|
200
|
+
*
|
|
201
|
+
* return store.push(jsonApiPayload);
|
|
202
|
+
* }
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @public
|
|
206
|
+
* @optional
|
|
207
|
+
* @param {Store} store The store service that initiated the request being normalized
|
|
208
|
+
* @param {Object} rawPayload The raw JSON response data returned from an API request.
|
|
209
|
+
* This JSON should be in the API format expected by the serializer.
|
|
210
|
+
* @return {void}
|
|
211
|
+
*/
|
|
212
|
+
pushPayload?(store: Store, rawPayload: ObjectValue): void;
|
|
213
|
+
/**
|
|
214
|
+
* In some situations the serializer may need to perform cleanup when destroyed,
|
|
215
|
+
* that cleanup can be done in `destroy`.
|
|
216
|
+
*
|
|
217
|
+
* If not implemented, the store does not inform the serializer of destruction.
|
|
218
|
+
*
|
|
219
|
+
* @public
|
|
220
|
+
* @optional
|
|
221
|
+
*/
|
|
222
|
+
destroy?(): void;
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=minimum-serializer-interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimum-serializer-interface.d.ts","sourceRoot":"","sources":["../../../src/compat/legacy-network-handler/minimum-serializer-interface.ts"],"names":[],"mappings":"AAAA,OAAO,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,CAAC;IAEhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,iBAAiB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAE7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,WAAW,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;IAE1D;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI,IAAI,CAAC;CAClB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Store } from '@warp-drive/core';
|
|
2
|
+
import type { ModelSchema } from '@warp-drive/core/types';
|
|
3
|
+
import type { JsonApiDocument } from '@warp-drive/core/types/spec/json-api-raw';
|
|
4
|
+
import type { AdapterPayload } from './minimum-adapter-interface.ts';
|
|
5
|
+
import type { MinimumSerializerInterface, RequestType } from './minimum-serializer-interface.ts';
|
|
6
|
+
export declare function normalizeResponseHelper(serializer: MinimumSerializerInterface | null, store: Store, modelClass: ModelSchema, payload: AdapterPayload, id: string | null, requestType: RequestType): JsonApiDocument;
|
|
7
|
+
//# sourceMappingURL=serializer-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer-response.d.ts","sourceRoot":"","sources":["../../../src/compat/legacy-network-handler/serializer-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEhF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AA8DjG,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,0BAA0B,GAAG,IAAI,EAC7C,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,cAAc,EACvB,EAAE,EAAE,MAAM,GAAG,IAAI,EACjB,WAAW,EAAE,WAAW,GACvB,eAAe,CAQjB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Store } from '@warp-drive/core';
|
|
2
|
+
import type { LiveArray } from '@warp-drive/core/store/-private';
|
|
3
|
+
import type { FindAllOptions, ModelSchema } from '@warp-drive/core/types';
|
|
4
|
+
import type { Snapshot } from './snapshot.ts';
|
|
5
|
+
/**
|
|
6
|
+
SnapshotRecordArray is not directly instantiable.
|
|
7
|
+
Instances are provided to consuming application's
|
|
8
|
+
adapters for certain `findAll` requests.
|
|
9
|
+
|
|
10
|
+
@class SnapshotRecordArray
|
|
11
|
+
@public
|
|
12
|
+
*/
|
|
13
|
+
export declare class SnapshotRecordArray {
|
|
14
|
+
_snapshots: Snapshot[] | null;
|
|
15
|
+
_type: ModelSchema | null;
|
|
16
|
+
modelName: string;
|
|
17
|
+
__store: Store;
|
|
18
|
+
adapterOptions?: Record<string, unknown>;
|
|
19
|
+
include?: string | string[];
|
|
20
|
+
/**
|
|
21
|
+
SnapshotRecordArray is not directly instantiable.
|
|
22
|
+
Instances are provided to consuming application's
|
|
23
|
+
adapters and serializers for certain requests.
|
|
24
|
+
|
|
25
|
+
@private
|
|
26
|
+
@constructor
|
|
27
|
+
@param {Store} store
|
|
28
|
+
@param {String} type
|
|
29
|
+
@param options
|
|
30
|
+
*/
|
|
31
|
+
constructor(store: Store, type: string, options?: FindAllOptions);
|
|
32
|
+
/**
|
|
33
|
+
An array of records
|
|
34
|
+
|
|
35
|
+
@property _recordArray
|
|
36
|
+
@private
|
|
37
|
+
@type {Array}
|
|
38
|
+
*/
|
|
39
|
+
get _recordArray(): LiveArray;
|
|
40
|
+
/**
|
|
41
|
+
Number of records in the array
|
|
42
|
+
|
|
43
|
+
Example
|
|
44
|
+
|
|
45
|
+
```js [app/adapters/post.js]
|
|
46
|
+
import JSONAPIAdapter from '@ember-data/adapter/json-api';
|
|
47
|
+
|
|
48
|
+
export default class PostAdapter extends JSONAPIAdapter {
|
|
49
|
+
shouldReloadAll(store, snapshotRecordArray) {
|
|
50
|
+
return !snapshotRecordArray.length;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
@property length
|
|
56
|
+
@public
|
|
57
|
+
@type {Number}
|
|
58
|
+
*/
|
|
59
|
+
get length(): number;
|
|
60
|
+
/**
|
|
61
|
+
Get snapshots of the underlying record array
|
|
62
|
+
|
|
63
|
+
Example
|
|
64
|
+
|
|
65
|
+
```js [app/adapters/post.js]
|
|
66
|
+
import JSONAPIAdapter from '@ember-data/adapter/json-api';
|
|
67
|
+
|
|
68
|
+
export default class PostAdapter extends JSONAPIAdapter {
|
|
69
|
+
shouldReloadAll(store, snapshotArray) {
|
|
70
|
+
let snapshots = snapshotArray.snapshots();
|
|
71
|
+
|
|
72
|
+
return snapshots.any(function(ticketSnapshot) {
|
|
73
|
+
let timeDiff = moment().diff(ticketSnapshot.attr('lastAccessedAt'), 'minutes');
|
|
74
|
+
if (timeDiff > 20) {
|
|
75
|
+
return true;
|
|
76
|
+
} else {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
@public
|
|
85
|
+
@return {Array} Array of snapshots
|
|
86
|
+
*/
|
|
87
|
+
snapshots(): Snapshot<unknown>[];
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=snapshot-record-array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-record-array.d.ts","sourceRoot":"","sources":["../../../src/compat/legacy-network-handler/snapshot-record-array.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAI1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C;;;;;;;EAOE;AACF,qBAAa,mBAAmB;IACtB,UAAU,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC9B,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,KAAK,CAAC;IAEf,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEpC;;;;;;;;;;OAUG;gBACS,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAkEpE;;;;;;MAME;IACF,IAAI,YAAY,IAAI,SAAS,CAE5B;IAED;;;;;;;;;;;;;;;;;;QAkBI;IACJ,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;MA0BE;IACF,SAAS;CAaV"}
|
|
@@ -0,0 +1,237 @@
|
|
|
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';
|
|
8
|
+
type RecordId = string | null;
|
|
9
|
+
/**
|
|
10
|
+
Snapshot is not directly instantiable.
|
|
11
|
+
Instances are provided to a consuming application's
|
|
12
|
+
adapters and serializers for certain requests.
|
|
13
|
+
|
|
14
|
+
Snapshots are only available when using `@ember-data/legacy-compat`
|
|
15
|
+
for legacy compatibility with adapters and serializers.
|
|
16
|
+
|
|
17
|
+
@class Snapshot
|
|
18
|
+
@public
|
|
19
|
+
*/
|
|
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;
|
|
235
|
+
}
|
|
236
|
+
export {};
|
|
237
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/compat/legacy-network-handler/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA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