@warp-drive/legacy 5.8.0-alpha.4 → 5.8.0-alpha.40
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/README.md +14 -27
- package/declarations/adapter/error.d.ts +5 -5
- package/declarations/adapter/json-api.d.ts +6 -8
- package/declarations/adapter/rest.d.ts +5 -8
- package/declarations/adapter.d.ts +4 -6
- package/declarations/compat/-private.d.ts +1 -1
- package/declarations/compat/builders/find-all.d.ts +6 -6
- package/declarations/compat/builders/find-record.d.ts +8 -8
- package/declarations/compat/builders/query.d.ts +12 -12
- package/declarations/compat/extensions.d.ts +1 -1
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +7 -9
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +20 -30
- package/declarations/compat/utils.d.ts +17 -17
- package/declarations/compat.d.ts +35 -11
- package/declarations/index.d.ts +70 -0
- package/declarations/model/-private/attr.d.ts +5 -6
- package/declarations/model/-private/belongs-to.d.ts +4 -5
- package/declarations/model/-private/has-many.d.ts +4 -5
- package/declarations/model/-private/hooks.d.ts +1 -1
- package/declarations/model/-private/legacy-relationships-support.d.ts +2 -2
- package/declarations/model/-private/model.d.ts +8 -8
- package/declarations/model/-private/record-state.d.ts +1 -1
- package/declarations/model/-private/references/belongs-to.d.ts +5 -5
- package/declarations/model/-private/references/has-many.d.ts +3 -3
- package/declarations/model/migration-support.d.ts +46 -21
- package/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
- package/declarations/model-fragments/extensions/fragment.d.ts +15 -0
- package/declarations/model-fragments/hooks/model-for.d.ts +20 -0
- package/declarations/model-fragments/index.d.ts +5 -0
- package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
- package/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
- package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
- package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
- package/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
- package/declarations/model-fragments.d.ts +9 -0
- package/declarations/model.d.ts +2 -2
- package/declarations/serializer/-private/embedded-records-mixin.d.ts +1 -6
- package/declarations/serializer/-private/transforms/boolean.d.ts +2 -2
- package/declarations/serializer/-private/transforms/date.d.ts +2 -2
- package/declarations/serializer/-private/transforms/number.d.ts +1 -1
- package/declarations/serializer/-private/transforms/string.d.ts +1 -1
- package/declarations/serializer/json-api.d.ts +7 -9
- package/declarations/serializer/json.d.ts +7 -9
- package/declarations/serializer/rest.d.ts +4 -6
- package/declarations/serializer.d.ts +9 -12
- package/dist/{-private-8UmnAf9J.js → -private-B1pSSN52.js} +1 -1
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +12 -13
- package/dist/adapter/json-api.js +4 -1
- package/dist/adapter/rest.js +6 -9
- package/dist/adapter.js +4 -6
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.js +26 -26
- package/dist/compat/utils.js +17 -18
- package/dist/compat.js +58 -41
- package/dist/{errors-8kD2mSe_.js → errors-CIGPcDvd.js} +87 -65
- package/dist/hooks-QqRnX108.js +74 -0
- package/dist/index.js +195 -0
- package/dist/{json-DziiodPf.js → json-BNrV8EYG.js} +12 -16
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +54 -24
- package/dist/model-for-CqXsIKws.js +221 -0
- package/dist/model-fragments.js +76 -0
- package/dist/model.js +18 -90
- package/dist/{schema-provider-DQu4Rjco.js → schema-provider-g5MfTj8n.js} +18 -20
- package/dist/{serialize-into-hash-CS0MIv4F.js → serialize-into-hash-BnYvPex3.js} +1 -1
- package/dist/serializer/json-api.js +17 -44
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +14 -21
- package/dist/serializer/transform.js +15 -6
- package/dist/serializer.js +9 -13
- package/dist/store.js +3 -0
- package/dist/unpkg/dev/-private-DbaSCSym.js +1205 -0
- package/dist/unpkg/dev/adapter/-private.js +1 -0
- package/dist/unpkg/dev/adapter/error.js +335 -0
- package/dist/unpkg/dev/adapter/json-api.js +271 -0
- package/dist/unpkg/dev/adapter/rest.js +1255 -0
- package/dist/unpkg/dev/adapter.js +1252 -0
- package/dist/unpkg/dev/compat/-private.js +1 -0
- package/dist/unpkg/dev/compat/builders.js +275 -0
- package/dist/unpkg/dev/compat/extensions.js +242 -0
- package/dist/unpkg/dev/compat/utils.js +223 -0
- package/dist/unpkg/dev/compat.js +1146 -0
- package/dist/unpkg/dev/errors-DD96TBEs.js +2591 -0
- package/dist/unpkg/dev/hooks-CqWjNWeL.js +73 -0
- package/dist/unpkg/dev/index.js +197 -0
- package/dist/unpkg/dev/json-CCU-ZQ4b.js +1269 -0
- package/dist/unpkg/dev/model/-private.js +1 -0
- package/dist/unpkg/dev/model/migration-support.js +551 -0
- package/dist/unpkg/dev/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/dev/model-fragments.js +76 -0
- package/dist/unpkg/dev/model.js +678 -0
- package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/dev/schema-provider-B8jiJOYC.js +2229 -0
- package/dist/unpkg/dev/serialize-into-hash-CPAZXrQU.js +259 -0
- package/dist/unpkg/dev/serializer/json-api.js +648 -0
- package/dist/unpkg/dev/serializer/json.js +4 -0
- package/dist/unpkg/dev/serializer/rest.js +1242 -0
- package/dist/unpkg/dev/serializer/transform.js +278 -0
- package/dist/unpkg/dev/serializer.js +248 -0
- package/dist/unpkg/dev/store.js +636 -0
- package/dist/unpkg/dev/util-DvanW33H.js +20 -0
- package/dist/unpkg/dev/utils-BhvS1iTS.js +8 -0
- package/dist/unpkg/dev-deprecated/-private-DbaSCSym.js +1205 -0
- package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/adapter/error.js +335 -0
- package/dist/unpkg/dev-deprecated/adapter/json-api.js +271 -0
- package/dist/unpkg/dev-deprecated/adapter/rest.js +1255 -0
- package/dist/unpkg/dev-deprecated/adapter.js +1252 -0
- package/dist/unpkg/dev-deprecated/compat/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/compat/builders.js +275 -0
- package/dist/unpkg/dev-deprecated/compat/extensions.js +242 -0
- package/dist/unpkg/dev-deprecated/compat/utils.js +223 -0
- package/dist/unpkg/dev-deprecated/compat.js +1146 -0
- package/dist/unpkg/dev-deprecated/errors-DEnabIZj.js +2594 -0
- package/dist/unpkg/dev-deprecated/hooks-CAll-Ets.js +73 -0
- package/dist/unpkg/dev-deprecated/index.js +196 -0
- package/dist/unpkg/dev-deprecated/json-CCU-ZQ4b.js +1269 -0
- package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/model/migration-support.js +568 -0
- package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/dev-deprecated/model-fragments.js +76 -0
- package/dist/unpkg/dev-deprecated/model.js +682 -0
- package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/dev-deprecated/schema-provider-k2qXQTBg.js +2254 -0
- package/dist/unpkg/dev-deprecated/serialize-into-hash-CPAZXrQU.js +259 -0
- package/dist/unpkg/dev-deprecated/serializer/json-api.js +648 -0
- package/dist/unpkg/dev-deprecated/serializer/json.js +4 -0
- package/dist/unpkg/dev-deprecated/serializer/rest.js +1242 -0
- package/dist/unpkg/dev-deprecated/serializer/transform.js +278 -0
- package/dist/unpkg/dev-deprecated/serializer.js +248 -0
- package/dist/unpkg/dev-deprecated/store.js +636 -0
- package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +24 -0
- package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +12 -0
- package/dist/unpkg/prod/-private-Cvf_97EG.js +970 -0
- package/dist/unpkg/prod/adapter/-private.js +1 -0
- package/dist/unpkg/prod/adapter/error.js +330 -0
- package/dist/unpkg/prod/adapter/json-api.js +266 -0
- package/dist/unpkg/prod/adapter/rest.js +1218 -0
- package/dist/unpkg/prod/adapter.js +1219 -0
- package/dist/unpkg/prod/compat/-private.js +1 -0
- package/dist/unpkg/prod/compat/builders.js +210 -0
- package/dist/unpkg/prod/compat/extensions.js +232 -0
- package/dist/unpkg/prod/compat/utils.js +218 -0
- package/dist/unpkg/prod/compat.js +726 -0
- package/dist/unpkg/prod/errors-CXnfnBfQ.js +2343 -0
- package/dist/unpkg/prod/hooks-DvyWhLNg.js +41 -0
- package/dist/unpkg/prod/index.js +151 -0
- package/dist/unpkg/prod/json-BYrUP8ao.js +1256 -0
- package/dist/unpkg/prod/model/-private.js +1 -0
- package/dist/unpkg/prod/model/migration-support.js +544 -0
- package/dist/unpkg/prod/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/prod/model-fragments.js +76 -0
- package/dist/unpkg/prod/model.js +593 -0
- package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/prod/schema-provider-CHujJvA9.js +1904 -0
- package/dist/unpkg/prod/serialize-into-hash-DYU2egXl.js +215 -0
- package/dist/unpkg/prod/serializer/json-api.js +591 -0
- package/dist/unpkg/prod/serializer/json.js +4 -0
- package/dist/unpkg/prod/serializer/rest.js +1210 -0
- package/dist/unpkg/prod/serializer/transform.js +278 -0
- package/dist/unpkg/prod/serializer.js +248 -0
- package/dist/unpkg/prod/store.js +504 -0
- package/dist/unpkg/prod/util-DvanW33H.js +20 -0
- package/dist/unpkg/prod/utils-BhvS1iTS.js +8 -0
- package/dist/unpkg/prod-deprecated/-private-Cvf_97EG.js +970 -0
- package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/adapter/error.js +330 -0
- package/dist/unpkg/prod-deprecated/adapter/json-api.js +266 -0
- package/dist/unpkg/prod-deprecated/adapter/rest.js +1218 -0
- package/dist/unpkg/prod-deprecated/adapter.js +1219 -0
- package/dist/unpkg/prod-deprecated/compat/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/compat/builders.js +210 -0
- package/dist/unpkg/prod-deprecated/compat/extensions.js +232 -0
- package/dist/unpkg/prod-deprecated/compat/utils.js +218 -0
- package/dist/unpkg/prod-deprecated/compat.js +726 -0
- package/dist/unpkg/prod-deprecated/errors-CG1SPYVg.js +2346 -0
- package/dist/unpkg/prod-deprecated/hooks-BIUBiNGR.js +41 -0
- package/dist/unpkg/prod-deprecated/index.js +150 -0
- package/dist/unpkg/prod-deprecated/json-BYrUP8ao.js +1256 -0
- package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/model/migration-support.js +561 -0
- package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/prod-deprecated/model-fragments.js +76 -0
- package/dist/unpkg/prod-deprecated/model.js +596 -0
- package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/prod-deprecated/schema-provider-BJ4TWnZf.js +1947 -0
- package/dist/unpkg/prod-deprecated/serialize-into-hash-DYU2egXl.js +215 -0
- package/dist/unpkg/prod-deprecated/serializer/json-api.js +591 -0
- package/dist/unpkg/prod-deprecated/serializer/json.js +4 -0
- package/dist/unpkg/prod-deprecated/serializer/rest.js +1210 -0
- package/dist/unpkg/prod-deprecated/serializer/transform.js +278 -0
- package/dist/unpkg/prod-deprecated/serializer.js +248 -0
- package/dist/unpkg/prod-deprecated/store.js +504 -0
- package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +23 -0
- package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +11 -0
- package/logos/README.md +2 -2
- package/logos/logo-yellow-slab.svg +1 -0
- package/logos/word-mark-black.svg +1 -0
- package/logos/word-mark-white.svg +1 -0
- package/package.json +14 -6
- package/logos/NCC-1701-a-blue.svg +0 -4
- package/logos/NCC-1701-a-gold.svg +0 -4
- package/logos/NCC-1701-a-gold_100.svg +0 -1
- package/logos/NCC-1701-a-gold_base-64.txt +0 -1
- package/logos/NCC-1701-a.svg +0 -4
- package/logos/docs-badge.svg +0 -2
- package/logos/ember-data-logo-dark.svg +0 -12
- package/logos/ember-data-logo-light.svg +0 -12
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +0 -4
- package/logos/warp-drive-logo-gold.svg +0 -4
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { singularize, pluralize } from '@warp-drive/utilities/string';
|
|
2
|
+
import { withDefaults } from './model/migration-support.js';
|
|
3
|
+
import { F as FragmentExtension, a as FragmentArrayExtension } from "./model-for-CqXsIKws.js";
|
|
4
|
+
export { c as Fragment, b as FragmentArray, m as modelFor } from "./model-for-CqXsIKws.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Used as a helper to setup the relevant parts of an array
|
|
8
|
+
* schema and add extensions etc.
|
|
9
|
+
*
|
|
10
|
+
* @param arrayName The name of the array
|
|
11
|
+
* @returns The schema for an array
|
|
12
|
+
*/
|
|
13
|
+
function withArrayDefaults(arrayName) {
|
|
14
|
+
return {
|
|
15
|
+
kind: 'array',
|
|
16
|
+
name: arrayName,
|
|
17
|
+
type: `array:${singularize(arrayName)}`,
|
|
18
|
+
options: {
|
|
19
|
+
arrayExtensions: ['ember-object', 'ember-array-like', 'fragment-array']
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Used as a helper to setup the relevant parts of a fragment schema
|
|
26
|
+
* and add extensions etc.
|
|
27
|
+
*
|
|
28
|
+
* @param fragmentType The type of the fragment
|
|
29
|
+
* @param fragmentName The optional name of the fragment. If not provided, it will default to the fragmentType.
|
|
30
|
+
* @returns The schema for a fragment
|
|
31
|
+
*/
|
|
32
|
+
function withFragmentDefaults(fragmentType, fragmentName) {
|
|
33
|
+
return {
|
|
34
|
+
kind: 'schema-object',
|
|
35
|
+
type: `fragment:${fragmentType}`,
|
|
36
|
+
name: fragmentName ?? fragmentType,
|
|
37
|
+
options: {
|
|
38
|
+
objectExtensions: ['ember-object', 'fragment']
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Used as a helper to setup the relevant parts of a fragment-array
|
|
45
|
+
* schema and add extensions etc.
|
|
46
|
+
*
|
|
47
|
+
* @param fragmentArrayType The type of the fragment-array
|
|
48
|
+
* @param fragmentArrayName The name of the fragment-array
|
|
49
|
+
* @returns The schema for a fragment-array
|
|
50
|
+
*/
|
|
51
|
+
function withFragmentArrayDefaults(fragmentArrayType, fragmentArrayName) {
|
|
52
|
+
return {
|
|
53
|
+
kind: 'schema-array',
|
|
54
|
+
type: `fragment:${singularize(fragmentArrayType)}`,
|
|
55
|
+
name: fragmentArrayName ?? pluralize(fragmentArrayType),
|
|
56
|
+
options: {
|
|
57
|
+
arrayExtensions: ['ember-object', 'ember-array-like', 'fragment-array'],
|
|
58
|
+
defaultValue: true
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function withLegacy(schema) {
|
|
63
|
+
return withDefaults({
|
|
64
|
+
...schema,
|
|
65
|
+
identity: {
|
|
66
|
+
kind: '@id',
|
|
67
|
+
name: 'id'
|
|
68
|
+
},
|
|
69
|
+
objectExtensions: ['ember-object', 'fragment']
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function registerFragmentExtensions(schema) {
|
|
73
|
+
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension?.(FragmentExtension);
|
|
74
|
+
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension?.(FragmentArrayExtension);
|
|
75
|
+
}
|
|
76
|
+
export { FragmentArrayExtension, FragmentExtension, registerFragmentExtensions, withArrayDefaults, withFragmentArrayDefaults, withFragmentDefaults, withLegacy };
|
package/dist/model.js
CHANGED
|
@@ -4,12 +4,11 @@ import { RecordStore } from '@warp-drive/core/types/symbols';
|
|
|
4
4
|
import { i as isElementDescriptor, n as normalizeModelName } from "./util-Dul6TZts.js";
|
|
5
5
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
6
6
|
import { warn, deprecate } from '@ember/debug';
|
|
7
|
-
import { assertPrivateStore
|
|
8
|
-
import { l as lookupLegacySupport } from "./errors-
|
|
7
|
+
import { assertPrivateStore } from '@warp-drive/core/store/-private';
|
|
8
|
+
import { l as lookupLegacySupport } from "./errors-CIGPcDvd.js";
|
|
9
9
|
import { singularize, dasherize } from '@warp-drive/utilities/string';
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
import { setOwner, getOwner } from '@ember/application';
|
|
10
|
+
export { M as Model, b as buildSchema, M as default, m as restoreDeprecatedModelRequestBehaviors } from "./schema-provider-g5MfTj8n.js";
|
|
11
|
+
export { i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-QqRnX108.js";
|
|
13
12
|
function _attr(type, options) {
|
|
14
13
|
if (typeof type === 'object') {
|
|
15
14
|
options = type;
|
|
@@ -87,12 +86,12 @@ function _attr(type, options) {
|
|
|
87
86
|
*/
|
|
88
87
|
|
|
89
88
|
/**
|
|
90
|
-
`attr` defines an attribute on a
|
|
89
|
+
`attr` defines an attribute on a {@link Model}.
|
|
91
90
|
By default, attributes are passed through as-is, however you can specify an
|
|
92
91
|
optional type to have the value automatically transformed.
|
|
93
|
-
|
|
92
|
+
WarpDrive ships with four basic transform types: `string`, `number`,
|
|
94
93
|
`boolean` and `date`. You can define your own transforms by subclassing
|
|
95
|
-
|
|
94
|
+
{@link Transform}.
|
|
96
95
|
|
|
97
96
|
Note that you cannot use `attr` to define an attribute of `id`.
|
|
98
97
|
|
|
@@ -169,9 +168,8 @@ function _attr(type, options) {
|
|
|
169
168
|
```
|
|
170
169
|
|
|
171
170
|
@public
|
|
172
|
-
@param
|
|
173
|
-
@param
|
|
174
|
-
@return {Attribute}
|
|
171
|
+
@param type the attribute type
|
|
172
|
+
@param options a hash of options
|
|
175
173
|
*/
|
|
176
174
|
|
|
177
175
|
// see note on DataDecorator for why void
|
|
@@ -258,7 +256,7 @@ function _belongsTo(type, options) {
|
|
|
258
256
|
|
|
259
257
|
/**
|
|
260
258
|
`belongsTo` is used to define One-To-One and One-To-Many, and One-To-None
|
|
261
|
-
relationships on a
|
|
259
|
+
relationships on a {@link Model}.
|
|
262
260
|
|
|
263
261
|
`belongsTo` takes a configuration hash as a second parameter, currently
|
|
264
262
|
supported options are:
|
|
@@ -340,7 +338,7 @@ function _belongsTo(type, options) {
|
|
|
340
338
|
|
|
341
339
|
#### Sync vs Async Relationships
|
|
342
340
|
|
|
343
|
-
|
|
341
|
+
WarpDrive fulfills relationships using resource data available in
|
|
344
342
|
the cache.
|
|
345
343
|
|
|
346
344
|
Sync relationships point directly to the known related resources.
|
|
@@ -408,9 +406,8 @@ function _belongsTo(type, options) {
|
|
|
408
406
|
type each record satisfies on both sides.
|
|
409
407
|
|
|
410
408
|
@public
|
|
411
|
-
@param
|
|
412
|
-
@param
|
|
413
|
-
@return {PropertyDescriptor} relationship
|
|
409
|
+
@param type the name of the related resource
|
|
410
|
+
@param options a hash of options
|
|
414
411
|
*/
|
|
415
412
|
|
|
416
413
|
// export function belongsTo<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(
|
|
@@ -497,7 +494,7 @@ function _hasMany(type, options) {
|
|
|
497
494
|
|
|
498
495
|
/**
|
|
499
496
|
`hasMany` is used to define Many-To-One and Many-To-Many, and Many-To-None
|
|
500
|
-
relationships on a
|
|
497
|
+
relationships on a {@link Model}.
|
|
501
498
|
|
|
502
499
|
`hasMany` takes a configuration hash as a second parameter, currently
|
|
503
500
|
supported options are:
|
|
@@ -580,7 +577,7 @@ function _hasMany(type, options) {
|
|
|
580
577
|
|
|
581
578
|
#### Sync vs Async Relationships
|
|
582
579
|
|
|
583
|
-
|
|
580
|
+
WarpDrive fulfills relationships using resource data available in
|
|
584
581
|
the cache.
|
|
585
582
|
|
|
586
583
|
Sync relationships point directly to the known related resources.
|
|
@@ -648,9 +645,8 @@ function _hasMany(type, options) {
|
|
|
648
645
|
type each record satisfies on both sides.
|
|
649
646
|
|
|
650
647
|
@public
|
|
651
|
-
@param
|
|
652
|
-
@param
|
|
653
|
-
@return {PropertyDescriptor} relationship
|
|
648
|
+
@param type the name of the related resource
|
|
649
|
+
@param options a hash of options
|
|
654
650
|
*/
|
|
655
651
|
|
|
656
652
|
// export function hasMany<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(
|
|
@@ -668,72 +664,4 @@ function hasMany(type, options) {
|
|
|
668
664
|
}
|
|
669
665
|
return _hasMany(type, options);
|
|
670
666
|
}
|
|
671
|
-
|
|
672
|
-
const type = identifier.type;
|
|
673
|
-
|
|
674
|
-
// TODO deprecate allowing unknown args setting
|
|
675
|
-
const createOptions = {
|
|
676
|
-
_createProps: createRecordArgs,
|
|
677
|
-
// TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for
|
|
678
|
-
_secretInit: {
|
|
679
|
-
identifier,
|
|
680
|
-
store: this,
|
|
681
|
-
cb: secretInit
|
|
682
|
-
}
|
|
683
|
-
};
|
|
684
|
-
|
|
685
|
-
// ensure that `getOwner(this)` works inside a model instance
|
|
686
|
-
setOwner(createOptions, getOwner(this));
|
|
687
|
-
const factory = getModelFactory(this, type);
|
|
688
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
689
|
-
if (!test) {
|
|
690
|
-
throw new Error(`No model was found for '${type}'`);
|
|
691
|
-
}
|
|
692
|
-
})(factory) : {};
|
|
693
|
-
return factory.class.create(createOptions);
|
|
694
|
-
}
|
|
695
|
-
function teardownRecord(record) {
|
|
696
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
697
|
-
if (!test) {
|
|
698
|
-
throw new Error(`expected to receive an instance of Model from @ember-data/model. If using a custom model make sure you implement teardownRecord`);
|
|
699
|
-
}
|
|
700
|
-
})('destroy' in record) : {};
|
|
701
|
-
record.destroy();
|
|
702
|
-
}
|
|
703
|
-
function modelFor(modelName) {
|
|
704
|
-
assertPrivateStore(this);
|
|
705
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
706
|
-
if (!test) {
|
|
707
|
-
throw new Error(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`);
|
|
708
|
-
}
|
|
709
|
-
})(!this.isDestroyed && !this.isDestroying) : {};
|
|
710
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
711
|
-
if (!test) {
|
|
712
|
-
throw new Error(`You need to pass a model name to the store's modelFor method`);
|
|
713
|
-
}
|
|
714
|
-
})(modelName) : {};
|
|
715
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
716
|
-
if (!test) {
|
|
717
|
-
throw new Error(`Please pass a proper model name to the store's modelFor method`);
|
|
718
|
-
}
|
|
719
|
-
})(typeof modelName === 'string' && modelName.length) : {};
|
|
720
|
-
const type = normalizeModelName(modelName);
|
|
721
|
-
const maybeFactory = getModelFactory(this, type);
|
|
722
|
-
const klass = maybeFactory && maybeFactory.class ? maybeFactory.class : null;
|
|
723
|
-
const ignoreType = !klass || !klass.isModel || this._forceShim;
|
|
724
|
-
if (!ignoreType) {
|
|
725
|
-
return klass;
|
|
726
|
-
}
|
|
727
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
728
|
-
if (!test) {
|
|
729
|
-
throw new Error(`No model was found for '${type}' and no schema handles the type`);
|
|
730
|
-
}
|
|
731
|
-
})(this.schema.hasResource({
|
|
732
|
-
type
|
|
733
|
-
})) : {};
|
|
734
|
-
}
|
|
735
|
-
function secretInit(record, identifier, store) {
|
|
736
|
-
setRecordIdentifier(record, identifier);
|
|
737
|
-
StoreMap.set(record, store);
|
|
738
|
-
}
|
|
739
|
-
export { attr, belongsTo, hasMany, instantiateRecord, modelFor, teardownRecord };
|
|
667
|
+
export { attr, belongsTo, hasMany };
|
|
@@ -4,8 +4,8 @@ import EmberObject from '@ember/object';
|
|
|
4
4
|
import { recordIdentifierFor, storeFor } from '@warp-drive/core';
|
|
5
5
|
import { assertPrivateStore, notifyInternalSignal, peekInternalSignal, withSignalStore, recordIdentifierFor as recordIdentifierFor$1, gate, memoized, defineSignal, coerceId, entangleSignal, defineGate } from '@warp-drive/core/store/-private';
|
|
6
6
|
import { RecordStore } from '@warp-drive/core/types/symbols';
|
|
7
|
-
import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-
|
|
8
|
-
import { u as upgradeStore, F as FetchManager } from "./-private-
|
|
7
|
+
import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-CIGPcDvd.js";
|
|
8
|
+
import { u as upgradeStore, F as FetchManager } from "./-private-B1pSSN52.js";
|
|
9
9
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
10
10
|
import { cacheFor } from '@ember/object/internals';
|
|
11
11
|
import { Context } from '@warp-drive/core/reactive/-private';
|
|
@@ -254,7 +254,7 @@ function isInvalidError(error) {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
/**
|
|
257
|
-
Historically
|
|
257
|
+
Historically WarpDrive managed a state machine
|
|
258
258
|
for each record, the localState for which
|
|
259
259
|
was reflected onto Model.
|
|
260
260
|
|
|
@@ -680,11 +680,6 @@ function computeOnce(target, propertyName, desc) {
|
|
|
680
680
|
};
|
|
681
681
|
return desc;
|
|
682
682
|
}
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* @noInheritDoc
|
|
686
|
-
*/
|
|
687
|
-
|
|
688
683
|
/**
|
|
689
684
|
* Base class from which Models can be defined.
|
|
690
685
|
*
|
|
@@ -727,7 +722,10 @@ function computeOnce(target, propertyName, desc) {
|
|
|
727
722
|
* the class to use as the reactive object for data of resource
|
|
728
723
|
* of that type.
|
|
729
724
|
*
|
|
725
|
+
* @public
|
|
730
726
|
* @noInheritDoc
|
|
727
|
+
* @hideconstructor
|
|
728
|
+
* @legacy
|
|
731
729
|
*/
|
|
732
730
|
class Model extends EmberObject {
|
|
733
731
|
/** @internal */
|
|
@@ -1255,7 +1253,7 @@ class Model extends EmberObject {
|
|
|
1255
1253
|
/**
|
|
1256
1254
|
Represents the model's class name as a string. This can be used to look up the model's class name through
|
|
1257
1255
|
`Store`'s modelFor method.
|
|
1258
|
-
`modelName` is generated for you by
|
|
1256
|
+
`modelName` is generated for you by WarpDrive. It will be a lowercased, dasherized string.
|
|
1259
1257
|
For example:
|
|
1260
1258
|
```javascript
|
|
1261
1259
|
store.modelFor('post').modelName; // 'post'
|
|
@@ -2114,7 +2112,7 @@ class ModelSchemaProvider {
|
|
|
2114
2112
|
hasTrait(type) {
|
|
2115
2113
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2116
2114
|
{
|
|
2117
|
-
throw new Error(`hasTrait is not available with @
|
|
2115
|
+
throw new Error(`hasTrait is not available with @warp-drive/legacy/model's SchemaService`);
|
|
2118
2116
|
}
|
|
2119
2117
|
})() : {};
|
|
2120
2118
|
return false;
|
|
@@ -2122,7 +2120,7 @@ class ModelSchemaProvider {
|
|
|
2122
2120
|
resourceHasTrait(resource, trait) {
|
|
2123
2121
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2124
2122
|
{
|
|
2125
|
-
throw new Error(`resourceHasTrait is not available with @
|
|
2123
|
+
throw new Error(`resourceHasTrait is not available with @warp-drive/legacy/model's SchemaService`);
|
|
2126
2124
|
}
|
|
2127
2125
|
})() : {};
|
|
2128
2126
|
return false;
|
|
@@ -2130,21 +2128,21 @@ class ModelSchemaProvider {
|
|
|
2130
2128
|
transformation(field) {
|
|
2131
2129
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2132
2130
|
{
|
|
2133
|
-
throw new Error(`transformation is not available with @
|
|
2131
|
+
throw new Error(`transformation is not available with @warp-drive/legacy/model's SchemaService`);
|
|
2134
2132
|
}
|
|
2135
2133
|
})() : {};
|
|
2136
2134
|
}
|
|
2137
2135
|
derivation(field) {
|
|
2138
2136
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2139
2137
|
{
|
|
2140
|
-
throw new Error(`derivation is not available with @
|
|
2138
|
+
throw new Error(`derivation is not available with @warp-drive/legacy/model's SchemaService`);
|
|
2141
2139
|
}
|
|
2142
2140
|
})() : {};
|
|
2143
2141
|
}
|
|
2144
2142
|
hashFn(field) {
|
|
2145
2143
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2146
2144
|
{
|
|
2147
|
-
throw new Error(`hashFn is not available with @
|
|
2145
|
+
throw new Error(`hashFn is not available with @warp-drive/legacy/model's SchemaService`);
|
|
2148
2146
|
}
|
|
2149
2147
|
})() : {};
|
|
2150
2148
|
}
|
|
@@ -2158,35 +2156,35 @@ class ModelSchemaProvider {
|
|
|
2158
2156
|
registerResources(schemas) {
|
|
2159
2157
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2160
2158
|
{
|
|
2161
|
-
throw new Error(`registerResources is not available with @
|
|
2159
|
+
throw new Error(`registerResources is not available with @warp-drive/legacy/model's SchemaService`);
|
|
2162
2160
|
}
|
|
2163
2161
|
})() : {};
|
|
2164
2162
|
}
|
|
2165
2163
|
registerResource(schema) {
|
|
2166
2164
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2167
2165
|
{
|
|
2168
|
-
throw new Error(`registerResource is not available with @
|
|
2166
|
+
throw new Error(`registerResource is not available with @warp-drive/legacy/model's SchemaService`);
|
|
2169
2167
|
}
|
|
2170
2168
|
})() : {};
|
|
2171
2169
|
}
|
|
2172
2170
|
registerTransformation(transform) {
|
|
2173
2171
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2174
2172
|
{
|
|
2175
|
-
throw new Error(`registerTransformation is not available with @
|
|
2173
|
+
throw new Error(`registerTransformation is not available with @warp-drive/legacy/model's SchemaService`);
|
|
2176
2174
|
}
|
|
2177
2175
|
})() : {};
|
|
2178
2176
|
}
|
|
2179
2177
|
registerDerivation(derivation) {
|
|
2180
2178
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2181
2179
|
{
|
|
2182
|
-
throw new Error(`registerDerivation is not available with @
|
|
2180
|
+
throw new Error(`registerDerivation is not available with @warp-drive/legacy/model's SchemaService`);
|
|
2183
2181
|
}
|
|
2184
2182
|
})() : {};
|
|
2185
2183
|
}
|
|
2186
2184
|
registerHashFn(hashFn) {
|
|
2187
2185
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2188
2186
|
{
|
|
2189
|
-
throw new Error(`registerHashFn is not available with @
|
|
2187
|
+
throw new Error(`registerHashFn is not available with @warp-drive/legacy/model's SchemaService`);
|
|
2190
2188
|
}
|
|
2191
2189
|
})() : {};
|
|
2192
2190
|
}
|
|
@@ -2337,4 +2335,4 @@ function getModelFactory(store, type) {
|
|
|
2337
2335
|
}
|
|
2338
2336
|
return factory;
|
|
2339
2337
|
}
|
|
2340
|
-
export { Model as M, RecordState as R, _save as _, save as a, buildSchema as b, _reload as c, reload as d, _destroyRecord as e, destroyRecord as f,
|
|
2338
|
+
export { Model as M, RecordState as R, _save as _, save as a, buildSchema as b, _reload as c, reload as d, _destroyRecord as e, destroyRecord as f, getModelFactory as g, hasMany as h, deleteRecord as i, changedAttributes as j, belongsTo as k, createSnapshot as l, restoreDeprecatedModelRequestBehaviors as m, rollbackAttributes as r, serialize as s, unloadRecord as u };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { warn } from '@ember/debug';
|
|
2
2
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
3
3
|
import '@warp-drive/core/reactive/-private';
|
|
4
|
-
import "./-private-
|
|
4
|
+
import "./-private-B1pSSN52.js";
|
|
5
5
|
import '@warp-drive/core/store/-private';
|
|
6
6
|
const newline = /\r?\n/;
|
|
7
7
|
function parseResponseHeaders(headersString) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { warn } from '@ember/debug';
|
|
2
2
|
import { dasherize, pluralize, singularize } from '@warp-drive/utilities/string';
|
|
3
|
-
import { J as JSONSerializer } from "../json-
|
|
3
|
+
import { J as JSONSerializer } from "../json-BNrV8EYG.js";
|
|
4
4
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
5
5
|
|
|
6
6
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
@@ -10,8 +10,6 @@ import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
|
10
10
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
11
11
|
const JSONAPISerializer = JSONSerializer.extend({
|
|
12
12
|
/**
|
|
13
|
-
@param {Object} documentHash
|
|
14
|
-
@return {Object}
|
|
15
13
|
@private
|
|
16
14
|
*/
|
|
17
15
|
_normalizeDocumentHelper(documentHash) {
|
|
@@ -41,8 +39,6 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
41
39
|
return documentHash;
|
|
42
40
|
},
|
|
43
41
|
/**
|
|
44
|
-
@param {Object} relationshipDataHash
|
|
45
|
-
@return {Object}
|
|
46
42
|
@private
|
|
47
43
|
*/
|
|
48
44
|
_normalizeRelationshipDataHelper(relationshipDataHash) {
|
|
@@ -50,8 +46,6 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
50
46
|
return relationshipDataHash;
|
|
51
47
|
},
|
|
52
48
|
/**
|
|
53
|
-
@param {Object} resourceHash
|
|
54
|
-
@return {Object}
|
|
55
49
|
@private
|
|
56
50
|
*/
|
|
57
51
|
_normalizeResourceHelper(resourceHash) {
|
|
@@ -88,21 +82,13 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
88
82
|
/**
|
|
89
83
|
Normalize some data and push it into the store.
|
|
90
84
|
@public
|
|
91
|
-
@param {Store} store
|
|
92
|
-
@param {Object} payload
|
|
93
85
|
*/
|
|
94
86
|
pushPayload(store, payload) {
|
|
95
87
|
const normalizedPayload = this._normalizeDocumentHelper(payload);
|
|
96
88
|
store.push(normalizedPayload);
|
|
97
89
|
},
|
|
98
90
|
/**
|
|
99
|
-
@
|
|
100
|
-
@param {Model} primaryModelClass
|
|
101
|
-
@param {Object} payload
|
|
102
|
-
@param {String|Number} id
|
|
103
|
-
@param {String} requestType
|
|
104
|
-
@param {Boolean} isSingle
|
|
105
|
-
@return {Object} JSON-API Document
|
|
91
|
+
@return A {json:api} Document
|
|
106
92
|
@private
|
|
107
93
|
*/
|
|
108
94
|
_normalizeResponse(store, primaryModelClass, payload, id, requestType, isSingle) {
|
|
@@ -144,8 +130,6 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
144
130
|
Returns a relationship formatted as a JSON-API "relationship object".
|
|
145
131
|
http://jsonapi.org/format/#document-resource-object-relationships
|
|
146
132
|
@public
|
|
147
|
-
@param {Object} relationshipHash
|
|
148
|
-
@return {Object}
|
|
149
133
|
*/
|
|
150
134
|
extractRelationship(relationshipHash) {
|
|
151
135
|
if (Array.isArray(relationshipHash.data)) {
|
|
@@ -164,9 +148,6 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
164
148
|
Returns the resource's relationships formatted as a JSON-API "relationships object".
|
|
165
149
|
http://jsonapi.org/format/#document-resource-object-relationships
|
|
166
150
|
@public
|
|
167
|
-
@param {Object} modelClass
|
|
168
|
-
@param {Object} resourceHash
|
|
169
|
-
@return {Object}
|
|
170
151
|
*/
|
|
171
152
|
extractRelationships(modelClass, resourceHash) {
|
|
172
153
|
const relationships = {};
|
|
@@ -191,9 +172,6 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
191
172
|
return relationships;
|
|
192
173
|
},
|
|
193
174
|
/**
|
|
194
|
-
@param {Model} modelClass
|
|
195
|
-
@param {Object} resourceHash
|
|
196
|
-
@return {String}
|
|
197
175
|
@private
|
|
198
176
|
*/
|
|
199
177
|
_extractType(modelClass, resourceHash) {
|
|
@@ -205,8 +183,7 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
205
183
|
For example the key `posts` would be converted to `post` and the
|
|
206
184
|
key `studentAssesments` would be converted to `student-assesment`.
|
|
207
185
|
@public
|
|
208
|
-
@
|
|
209
|
-
@return {String} the model's modelName
|
|
186
|
+
@return the model's modelName
|
|
210
187
|
*/
|
|
211
188
|
modelNameFromPayloadKey(key) {
|
|
212
189
|
return dasherize(singularize(key));
|
|
@@ -216,8 +193,6 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
216
193
|
For example `post` would be converted to `posts` and
|
|
217
194
|
`student-assesment` would be converted to `student-assesments`.
|
|
218
195
|
@public
|
|
219
|
-
@param {String} modelName
|
|
220
|
-
@return {String}
|
|
221
196
|
*/
|
|
222
197
|
payloadKeyFromModelName(modelName) {
|
|
223
198
|
return pluralize(modelName);
|
|
@@ -258,7 +233,7 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
258
233
|
This behaviour can be easily customized by extending this method.
|
|
259
234
|
Example
|
|
260
235
|
```js [app/serializers/application.js]
|
|
261
|
-
import JSONAPISerializer from '@
|
|
236
|
+
import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
|
|
262
237
|
import { dasherize } from '<app-name>/utils/string-utils';
|
|
263
238
|
export default class ApplicationSerializer extends JSONAPISerializer {
|
|
264
239
|
keyForAttribute(attr, method) {
|
|
@@ -267,9 +242,7 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
267
242
|
}
|
|
268
243
|
```
|
|
269
244
|
@public
|
|
270
|
-
@
|
|
271
|
-
@param {String} method
|
|
272
|
-
@return {String} normalized key
|
|
245
|
+
@return normalized key
|
|
273
246
|
*/
|
|
274
247
|
keyForAttribute(key, method) {
|
|
275
248
|
return dasherize(key);
|
|
@@ -283,7 +256,7 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
283
256
|
This behaviour can be easily customized by extending this method.
|
|
284
257
|
Example
|
|
285
258
|
```js [app/serializers/post.js]
|
|
286
|
-
import JSONAPISerializer from '@
|
|
259
|
+
import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
|
|
287
260
|
import { underscore } from '<app-name>/utils/string-utils';
|
|
288
261
|
export default class ApplicationSerializer extends JSONAPISerializer {
|
|
289
262
|
keyForRelationship(key, relationship, method) {
|
|
@@ -292,10 +265,7 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
292
265
|
}
|
|
293
266
|
```
|
|
294
267
|
@public
|
|
295
|
-
@
|
|
296
|
-
@param {String} typeClass
|
|
297
|
-
@param {String} method
|
|
298
|
-
@return {String} normalized key
|
|
268
|
+
@return the normalized key
|
|
299
269
|
*/
|
|
300
270
|
keyForRelationship(key, typeClass, method) {
|
|
301
271
|
return dasherize(key);
|
|
@@ -305,7 +275,7 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
305
275
|
record into JSON.
|
|
306
276
|
For example, consider this model:
|
|
307
277
|
```js [app/models/comment.js]
|
|
308
|
-
import Model, { attr, belongsTo } from '@
|
|
278
|
+
import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
|
|
309
279
|
export default class CommentModel extends Model {
|
|
310
280
|
@attr title;
|
|
311
281
|
@attr body;
|
|
@@ -356,7 +326,7 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
356
326
|
consider authoring your own adapter and serializer instead of extending
|
|
357
327
|
this class.
|
|
358
328
|
```js [app/serializers/post.js]
|
|
359
|
-
import JSONAPISerializer from '@
|
|
329
|
+
import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
|
|
360
330
|
export default class PostSerializer extends JSONAPISerializer {
|
|
361
331
|
serialize(snapshot, options) {
|
|
362
332
|
let json = {
|
|
@@ -376,7 +346,7 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
376
346
|
application, you'll probably want to use `eachAttribute`
|
|
377
347
|
and `eachRelationship` on the record.
|
|
378
348
|
```js [app/serializers/application.js]
|
|
379
|
-
import JSONAPISerializer from '@
|
|
349
|
+
import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
|
|
380
350
|
import { underscore, singularize } from '<app-name>/utils/string-utils';
|
|
381
351
|
export default class ApplicationSerializer extends JSONAPISerializer {
|
|
382
352
|
serialize(snapshot, options) {
|
|
@@ -415,7 +385,7 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
415
385
|
you can call `super.serialize` first and make the tweaks
|
|
416
386
|
on the returned object.
|
|
417
387
|
```js [app/serializers/post.js]
|
|
418
|
-
import JSONAPISerializer from '@
|
|
388
|
+
import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
|
|
419
389
|
export default class PostSerializer extends JSONAPISerializer {
|
|
420
390
|
serialize(snapshot, options) {
|
|
421
391
|
let json = super.serialize(...arguments);
|
|
@@ -426,9 +396,6 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
426
396
|
}
|
|
427
397
|
```
|
|
428
398
|
@public
|
|
429
|
-
@param {Snapshot} snapshot
|
|
430
|
-
@param {Object} options
|
|
431
|
-
@return {Object} json
|
|
432
399
|
*/
|
|
433
400
|
serialize(snapshot, options) {
|
|
434
401
|
// @ts-expect-error untyped
|
|
@@ -467,6 +434,7 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
467
434
|
// @ts-expect-error untyped
|
|
468
435
|
if (this._canSerialize(name)) {
|
|
469
436
|
const belongsTo = snapshot.belongsTo(name);
|
|
437
|
+
// @ts-expect-error not narrowed
|
|
470
438
|
const belongsToIsNotNew = belongsTo && !belongsTo.isNew;
|
|
471
439
|
if (belongsTo === null || belongsToIsNotNew) {
|
|
472
440
|
json.relationships = json.relationships || {};
|
|
@@ -480,11 +448,13 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
480
448
|
}
|
|
481
449
|
let data = null;
|
|
482
450
|
if (belongsTo) {
|
|
451
|
+
// @ts-expect-error not narrowed
|
|
483
452
|
const payloadType = this.payloadKeyFromModelName(belongsTo.modelName);
|
|
484
453
|
|
|
485
454
|
// @ts-expect-error untyped
|
|
486
455
|
data = {
|
|
487
456
|
type: payloadType,
|
|
457
|
+
// @ts-expect-error not narrowed
|
|
488
458
|
id: belongsTo.id
|
|
489
459
|
};
|
|
490
460
|
}
|
|
@@ -512,13 +482,16 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
512
482
|
}
|
|
513
483
|
|
|
514
484
|
// only serialize has many relationships that are not new
|
|
485
|
+
// @ts-expect-error not narrowed
|
|
515
486
|
const nonNewHasMany = hasMany.filter(item => !item.isNew);
|
|
516
487
|
const data = new Array(nonNewHasMany.length);
|
|
517
488
|
for (let i = 0; i < nonNewHasMany.length; i++) {
|
|
518
489
|
const item = hasMany[i];
|
|
490
|
+
// @ts-expect-error not narrowed
|
|
519
491
|
const payloadType = this.payloadKeyFromModelName(item.modelName);
|
|
520
492
|
data[i] = {
|
|
521
493
|
type: payloadType,
|
|
494
|
+
// @ts-expect-error not narrowed
|
|
522
495
|
id: item.id
|
|
523
496
|
};
|
|
524
497
|
}
|
package/dist/serializer/json.js
CHANGED
|
@@ -2,5 +2,5 @@ import '@ember/application';
|
|
|
2
2
|
import '@ember/debug';
|
|
3
3
|
import '@warp-drive/utilities/string';
|
|
4
4
|
import '../serializer.js';
|
|
5
|
-
export { J as JSONSerializer } from "../json-
|
|
5
|
+
export { J as JSONSerializer } from "../json-BNrV8EYG.js";
|
|
6
6
|
import '@embroider/macros';
|