@warp-drive/legacy 5.8.0-alpha.9 → 5.8.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -27
- package/declarations/adapter/error.d.ts +7 -7
- package/declarations/adapter/json-api.d.ts +2 -2
- package/declarations/adapter/rest.d.ts +21 -104
- package/declarations/adapter.d.ts +2 -2
- 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/legacy-network-handler/minimum-serializer-interface.d.ts +16 -24
- package/declarations/compat/utils.d.ts +13 -13
- package/declarations/compat.d.ts +31 -5
- package/declarations/index.d.ts +25 -8
- package/declarations/model/-private/legacy-relationships-support.d.ts +2 -2
- package/declarations/model/-private/model.d.ts +10 -51
- package/declarations/model/-private/promise-many-array.d.ts +0 -18
- package/declarations/model/-private/references/belongs-to.d.ts +18 -28
- package/declarations/model/-private/references/has-many.d.ts +13 -15
- package/declarations/model/migration-support.d.ts +42 -19
- 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 -1
- package/declarations/serializer/json-api.d.ts +7 -6
- package/declarations/serializer/json.d.ts +3 -3
- package/declarations/serializer.d.ts +5 -6
- package/dist/{-private-B1pSSN52.js → -private-BG3bMiKp.js} +2 -1
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +9 -9
- package/dist/adapter/json-api.js +1 -1
- package/dist/adapter/rest.js +33 -117
- package/dist/adapter.js +2 -2
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.js +26 -26
- package/dist/compat/utils.js +13 -14
- package/dist/compat.js +28 -8
- package/dist/{errors-COviC59J.js → errors-Cz5KrzBk.js} +113 -120
- package/dist/{hooks-Bp8SIQBU.js → hooks-D6diaM34.js} +1 -1
- package/dist/index.js +25 -8
- package/dist/{json-ksWOHRfq.js → json-ChdEfB0X.js} +12 -27
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +55 -25
- package/dist/model-for-CqXsIKws.js +221 -0
- package/dist/model-fragments.js +76 -0
- package/dist/model.js +3 -3
- package/dist/{schema-provider-JlCneqZH.js → schema-provider-DJCV_6AF.js} +44 -87
- package/dist/{serialize-into-hash-BnYvPex3.js → serialize-into-hash-DPZYoF-i.js} +1 -1
- package/dist/serializer/json-api.js +18 -45
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +10 -10
- package/dist/serializer.js +5 -6
- package/dist/store.js +2 -1
- package/dist/unpkg/dev/-private-DtjBbEgy.js +1206 -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 +1171 -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 +1147 -0
- package/dist/unpkg/dev/errors-DmGGJr3T.js +2562 -0
- package/dist/unpkg/dev/hooks-CkYiE6Ud.js +73 -0
- package/dist/unpkg/dev/index.js +197 -0
- package/dist/unpkg/dev/json-Cu1LNgmQ.js +1256 -0
- package/dist/unpkg/dev/model/-private.js +1 -0
- package/dist/unpkg/dev/model/migration-support.js +553 -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-DDVYxmUV.js +2186 -0
- package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +259 -0
- package/dist/unpkg/dev/serializer/json-api.js +649 -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 +637 -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-DtjBbEgy.js +1206 -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 +1171 -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 +1147 -0
- package/dist/unpkg/dev-deprecated/errors-Spt6ubMd.js +2565 -0
- package/dist/unpkg/dev-deprecated/hooks-DOXegvhL.js +73 -0
- package/dist/unpkg/dev-deprecated/index.js +196 -0
- package/dist/unpkg/dev-deprecated/json-Cu1LNgmQ.js +1256 -0
- package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/model/migration-support.js +570 -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-BP6_8N-V.js +2211 -0
- package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +259 -0
- package/dist/unpkg/dev-deprecated/serializer/json-api.js +649 -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 +637 -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-BdyZaGEh.js +971 -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 +1134 -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 +727 -0
- package/dist/unpkg/prod/errors-BGVFCBmi.js +2314 -0
- package/dist/unpkg/prod/hooks-BztVA_x0.js +41 -0
- package/dist/unpkg/prod/index.js +151 -0
- package/dist/unpkg/prod/json-BWrZ5546.js +1243 -0
- package/dist/unpkg/prod/model/-private.js +1 -0
- package/dist/unpkg/prod/model/migration-support.js +546 -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-DJtD_8jZ.js +1861 -0
- package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +215 -0
- package/dist/unpkg/prod/serializer/json-api.js +592 -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 +505 -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-BdyZaGEh.js +971 -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 +1134 -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 +727 -0
- package/dist/unpkg/prod-deprecated/errors-CdDaK81x.js +2317 -0
- package/dist/unpkg/prod-deprecated/hooks-yId87yyG.js +41 -0
- package/dist/unpkg/prod-deprecated/index.js +150 -0
- package/dist/unpkg/prod-deprecated/json-BWrZ5546.js +1243 -0
- package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/model/migration-support.js +563 -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-CjX55uSY.js +1904 -0
- package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +215 -0
- package/dist/unpkg/prod-deprecated/serializer/json-api.js +592 -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 +505 -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setOwner, getOwner } from '@ember/application';
|
|
2
2
|
import { assertPrivateStore, setRecordIdentifier, StoreMap } from '@warp-drive/core/store/-private';
|
|
3
|
-
import { g as getModelFactory } from "./schema-provider-
|
|
3
|
+
import { g as getModelFactory } from "./schema-provider-DJCV_6AF.js";
|
|
4
4
|
import { n as normalizeModelName } from "./util-Dul6TZts.js";
|
|
5
5
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
6
6
|
function instantiateRecord(identifier, createRecordArgs) {
|
package/dist/index.js
CHANGED
|
@@ -9,10 +9,11 @@ import '@ember/debug';
|
|
|
9
9
|
import '@warp-drive/utilities/string';
|
|
10
10
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
11
11
|
import '@warp-drive/core/store/-private';
|
|
12
|
-
import "./errors-
|
|
13
|
-
import "./schema-provider-
|
|
14
|
-
import { i as instantiateRecord, t as teardownRecord, m as modelFor } from "./hooks-
|
|
12
|
+
import "./errors-Cz5KrzBk.js";
|
|
13
|
+
import "./schema-provider-DJCV_6AF.js";
|
|
14
|
+
import { i as instantiateRecord, t as teardownRecord, m as modelFor } from "./hooks-D6diaM34.js";
|
|
15
15
|
import { registerDerivations as registerDerivations$1, DelegatingSchemaService } from './model/migration-support.js';
|
|
16
|
+
import { F as FragmentExtension, a as FragmentArrayExtension, f as fragmentsModelFor } from "./model-for-CqXsIKws.js";
|
|
16
17
|
import { restoreDeprecatedStoreBehaviors } from './store.js';
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -29,7 +30,9 @@ function useLegacyStore(options, StoreKlass = Store) {
|
|
|
29
30
|
throw new Error(`If legacyRequests is true, linksMode must be false`);
|
|
30
31
|
}
|
|
31
32
|
})(!(options.linksMode && options.legacyRequests)) : {};
|
|
32
|
-
|
|
33
|
+
// we extend the store to ensure we don't leak our prototype overrides to other stores below.
|
|
34
|
+
class BaseKlass extends StoreKlass {}
|
|
35
|
+
class LegacyConfiguredStore extends BaseKlass {
|
|
33
36
|
requestManager = new RequestManager().use([options.linksMode ? null : LegacyNetworkHandler, ...(options.handlers ?? []), Fetch].filter(Boolean)).useCache(CacheHandler);
|
|
34
37
|
lifetimes = options.policy ?? new DefaultCachePolicy({
|
|
35
38
|
apiCacheHardExpires: 15 * 60 * 1000,
|
|
@@ -82,6 +85,12 @@ function useLegacyStore(options, StoreKlass = Store) {
|
|
|
82
85
|
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension(EmberObjectArrayExtension);
|
|
83
86
|
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension(EmberObjectExtension);
|
|
84
87
|
|
|
88
|
+
// add support for fragments
|
|
89
|
+
if (options.modelFragments) {
|
|
90
|
+
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension?.(FragmentExtension);
|
|
91
|
+
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension?.(FragmentArrayExtension);
|
|
92
|
+
}
|
|
93
|
+
|
|
85
94
|
// Add fallback for Models
|
|
86
95
|
return new DelegatingSchemaService(this, schema);
|
|
87
96
|
}
|
|
@@ -104,14 +113,22 @@ function useLegacyStore(options, StoreKlass = Store) {
|
|
|
104
113
|
}
|
|
105
114
|
modelFor(type) {
|
|
106
115
|
assertType(this.schema, type);
|
|
116
|
+
// TODO I'm not sure this is right
|
|
107
117
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
108
118
|
if (!test) {
|
|
109
|
-
throw new Error(`modelFor should only be used to lookup legacy models when in linksMode`);
|
|
119
|
+
throw new Error(`modelFor should only be used to lookup legacy models when in linksMode: false`);
|
|
110
120
|
}
|
|
111
|
-
})(!options.linksMode || this.schema.isDelegated({
|
|
121
|
+
})(!options.linksMode || !this.schema.isDelegated({
|
|
112
122
|
type
|
|
113
123
|
})) : {};
|
|
114
|
-
|
|
124
|
+
const klass =
|
|
125
|
+
// prefer real models if present
|
|
126
|
+
modelFor.call(this, type) || (
|
|
127
|
+
// fallback to ShimModelClass specific to fragments if fragments support in use
|
|
128
|
+
options.modelFragments ? fragmentsModelFor.call(this, type) : false) ||
|
|
129
|
+
// fallback to ShimModelClass
|
|
130
|
+
super.modelFor(type);
|
|
131
|
+
return klass;
|
|
115
132
|
}
|
|
116
133
|
adapterFor(modelName, _allowMissing) {
|
|
117
134
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -162,7 +179,7 @@ function useLegacyStore(options, StoreKlass = Store) {
|
|
|
162
179
|
}
|
|
163
180
|
}
|
|
164
181
|
if (options.legacyRequests) {
|
|
165
|
-
restoreDeprecatedStoreBehaviors(
|
|
182
|
+
restoreDeprecatedStoreBehaviors(BaseKlass);
|
|
166
183
|
}
|
|
167
184
|
return LegacyConfiguredStore;
|
|
168
185
|
}
|
|
@@ -44,7 +44,7 @@ const PRIMARY_ATTRIBUTE_KEY = 'base';
|
|
|
44
44
|
For example, given the following `User` model and JSON payload:
|
|
45
45
|
|
|
46
46
|
```js [app/models/user.js]
|
|
47
|
-
import Model, { attr, belongsTo, hasMany } from '@
|
|
47
|
+
import Model, { attr, belongsTo, hasMany } from '@warp-drive/legacy/model';
|
|
48
48
|
|
|
49
49
|
export default class UserModel extends Model {
|
|
50
50
|
@hasMany('user') friends;
|
|
@@ -65,8 +65,8 @@ const PRIMARY_ATTRIBUTE_KEY = 'base';
|
|
|
65
65
|
}
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
`JSONSerializer` will normalize the JSON payload to the
|
|
69
|
-
|
|
68
|
+
`JSONSerializer` will normalize the JSON payload to the {json:api} format that the
|
|
69
|
+
JSONAPICache uses to cache data in the Store.
|
|
70
70
|
|
|
71
71
|
You can customize how JSONSerializer processes its payload by passing options in
|
|
72
72
|
the `attrs` hash or by subclassing the `JSONSerializer` and overriding hooks:
|
|
@@ -101,7 +101,7 @@ const PRIMARY_ATTRIBUTE_KEY = 'base';
|
|
|
101
101
|
const JSONSerializer = Serializer.extend({
|
|
102
102
|
/**
|
|
103
103
|
The `primaryKey` is used when serializing and deserializing
|
|
104
|
-
data.
|
|
104
|
+
data. WarpDrive always uses the `id` property to store the id of
|
|
105
105
|
the record. The external source may not always follow this
|
|
106
106
|
convention. In these cases it is useful to override the
|
|
107
107
|
`primaryKey` property to match the `primaryKey` of your external
|
|
@@ -113,9 +113,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
113
113
|
primaryKey = '_id'
|
|
114
114
|
}
|
|
115
115
|
```
|
|
116
|
-
@
|
|
117
|
-
@type {String}
|
|
118
|
-
@public
|
|
116
|
+
@public
|
|
119
117
|
@default 'id'
|
|
120
118
|
*/
|
|
121
119
|
primaryKey: 'id',
|
|
@@ -127,7 +125,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
127
125
|
the response payload.
|
|
128
126
|
Example
|
|
129
127
|
```js [app/models/person.js]
|
|
130
|
-
import Model, { attr } from '@
|
|
128
|
+
import Model, { attr } from '@warp-drive/legacy/model';
|
|
131
129
|
export default class PersonModel extends Model {
|
|
132
130
|
@attr('string') firstName;
|
|
133
131
|
@attr('string') lastName;
|
|
@@ -157,7 +155,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
157
155
|
}
|
|
158
156
|
```
|
|
159
157
|
When serialized:
|
|
160
|
-
```
|
|
158
|
+
```js
|
|
161
159
|
{
|
|
162
160
|
"firstName": "Harry",
|
|
163
161
|
"lastName": "Houdini",
|
|
@@ -168,9 +166,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
168
166
|
Setting `serialize` to `true` enforces serialization for hasMany
|
|
169
167
|
relationships even if it's neither a many-to-many nor many-to-none
|
|
170
168
|
relationship.
|
|
171
|
-
@
|
|
172
|
-
@public
|
|
173
|
-
@type {Object}
|
|
169
|
+
@public
|
|
174
170
|
*/
|
|
175
171
|
mergedProperties: ['attrs'],
|
|
176
172
|
/**
|
|
@@ -455,9 +451,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
455
451
|
}
|
|
456
452
|
```
|
|
457
453
|
@public
|
|
458
|
-
@param {Model} typeClass
|
|
459
|
-
@param {Object} hash
|
|
460
|
-
@return {Object}
|
|
461
454
|
*/
|
|
462
455
|
normalize(modelClass, resourceHash) {
|
|
463
456
|
let data = null;
|
|
@@ -503,9 +496,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
503
496
|
Returns the resource's attributes formatted as a JSON-API "attributes object".
|
|
504
497
|
http://jsonapi.org/format/#document-resource-object-attributes
|
|
505
498
|
@public
|
|
506
|
-
@param {Object} modelClass
|
|
507
|
-
@param {Object} resourceHash
|
|
508
|
-
@return {Object}
|
|
509
499
|
*/
|
|
510
500
|
extractAttributes(modelClass, resourceHash) {
|
|
511
501
|
let attributeKey;
|
|
@@ -646,8 +636,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
646
636
|
/**
|
|
647
637
|
Dasherizes the model name in the payload
|
|
648
638
|
@public
|
|
649
|
-
@
|
|
650
|
-
@return {String} the model's modelName
|
|
639
|
+
@return the model's modelName
|
|
651
640
|
*/
|
|
652
641
|
modelNameFromPayloadKey(key) {
|
|
653
642
|
return dasherize(singularize(key));
|
|
@@ -771,7 +760,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
771
760
|
each attribute and belongsTo relationship.
|
|
772
761
|
For example, consider this model:
|
|
773
762
|
```js [app/models/comment.js]
|
|
774
|
-
import Model, { attr, belongsTo } from '@
|
|
763
|
+
import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
|
|
775
764
|
export default class CommentModel extends Model {
|
|
776
765
|
@attr title;
|
|
777
766
|
@attr body;
|
|
@@ -906,7 +895,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
906
895
|
The hash property should be modified by reference.
|
|
907
896
|
For example, your server may expect underscored root objects.
|
|
908
897
|
```js [app/serializers/application.js]
|
|
909
|
-
import RESTSerializer from '@
|
|
898
|
+
import RESTSerializer from '@warp-drive/legacy/serializer/rest';
|
|
910
899
|
import { underscoren} from '<app-name>/utils/string-utils';
|
|
911
900
|
export default class ApplicationSerializer extends RESTSerializer {
|
|
912
901
|
serializeIntoHash(data, type, snapshot, options) {
|
|
@@ -1160,11 +1149,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1160
1149
|
}
|
|
1161
1150
|
```
|
|
1162
1151
|
@public
|
|
1163
|
-
@
|
|
1164
|
-
@param {Model} typeClass
|
|
1165
|
-
@param {Object} payload
|
|
1166
|
-
@param {(String|Number)} id
|
|
1167
|
-
@return {Object} json The deserialized errors
|
|
1152
|
+
@return json The deserialized errors
|
|
1168
1153
|
*/
|
|
1169
1154
|
extractErrors(store, typeClass, payload, id) {
|
|
1170
1155
|
// @ts-expect-error
|
package/dist/model/-private.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { E as Errors, L as LEGACY_SUPPORT, P as PromiseBelongsTo, a as PromiseManyArray, l as lookupLegacySupport } from "../errors-
|
|
1
|
+
export { E as Errors, L as LEGACY_SUPPORT, P as PromiseBelongsTo, a as PromiseManyArray, l as lookupLegacySupport } from "../errors-Cz5KrzBk.js";
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { deprecate } from '@ember/debug';
|
|
2
2
|
import { recordIdentifierFor } from '@warp-drive/core';
|
|
3
3
|
import { Context } from '@warp-drive/core/reactive/-private';
|
|
4
|
-
import { notifyInternalSignal
|
|
4
|
+
import { notifyInternalSignal } from '@warp-drive/core/signals/-leaked';
|
|
5
|
+
import { assertPrivateStore } from '@warp-drive/core/store/-private';
|
|
5
6
|
import { getOrSetGlobal } from '@warp-drive/core/types/-private';
|
|
6
7
|
import { Type } from '@warp-drive/core/types/symbols';
|
|
7
|
-
import { l as lookupLegacySupport, E as Errors } from "../errors-
|
|
8
|
-
import { b as buildSchema, u as unloadRecord, s as serialize, _ as _save, a as save, r as rollbackAttributes, c as _reload, d as reload, h as hasMany, e as _destroyRecord, f as destroyRecord, i as deleteRecord, R as RecordState, j as changedAttributes, k as belongsTo, l as createSnapshot } from "../schema-provider-
|
|
8
|
+
import { l as lookupLegacySupport, E as Errors } from "../errors-Cz5KrzBk.js";
|
|
9
|
+
import { b as buildSchema, u as unloadRecord, s as serialize, _ as _save, a as save, r as rollbackAttributes, c as _reload, d as reload, h as hasMany, e as _destroyRecord, f as destroyRecord, i as deleteRecord, R as RecordState, j as changedAttributes, k as belongsTo, l as createSnapshot } from "../schema-provider-DJCV_6AF.js";
|
|
9
10
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* This module provides support for migrating away from @
|
|
13
|
-
* to @warp-drive/
|
|
13
|
+
* This module provides support for migrating away from @warp-drive/legacy/model
|
|
14
|
+
* to ReactiveResource from @warp-drive/core/reactive.
|
|
14
15
|
*
|
|
15
16
|
* It includes:
|
|
16
17
|
*
|
|
17
18
|
* - A `withDefaults` function to assist in creating a schema in LegacyMode
|
|
18
19
|
* - A `registerDerivations` function to register the derivations necessary to support LegacyMode
|
|
19
20
|
* - A `DelegatingSchemaService` that can be used to provide a schema service that works with both
|
|
20
|
-
* @
|
|
21
|
+
* @warp-drive/legacy/model and @warp-drive/core/reactive simultaneously for migration purposes.
|
|
21
22
|
* - A `WithLegacy` type util that can be used to create a type that includes the legacy
|
|
22
23
|
* properties and methods of a record.
|
|
23
24
|
*
|
|
@@ -32,14 +33,14 @@ const LegacyFields = ['_createSnapshot', 'adapterError', 'belongsTo', 'changedAt
|
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* A Type utility that enables quickly adding type information for the fields
|
|
35
|
-
* defined by `import { withDefaults } from '@
|
|
36
|
+
* defined by `import { withDefaults } from '@warp-drive/legacy/model/migration-support'`.
|
|
36
37
|
*
|
|
37
38
|
* Example:
|
|
38
39
|
*
|
|
39
40
|
* ```ts
|
|
40
|
-
* import { withDefaults, WithLegacy } from '@
|
|
41
|
-
* import { Type } from '@warp-drive/core
|
|
42
|
-
* import type { HasMany } from '
|
|
41
|
+
* import { withDefaults, WithLegacy } from '@warp-drive/legacy/model/migration-support';
|
|
42
|
+
* import { Type } from '@warp-drive/core/types/symbols';
|
|
43
|
+
* import type { HasMany } from '@@warp-drive/legacy/model';
|
|
43
44
|
*
|
|
44
45
|
* export const UserSchema = withDefaults({
|
|
45
46
|
* type: 'user',
|
|
@@ -156,14 +157,14 @@ legacySupport[Type] = '@legacy';
|
|
|
156
157
|
/**
|
|
157
158
|
* A function which adds the necessary fields to a schema and marks it as
|
|
158
159
|
* being in LegacyMode. This is used to support the legacy features of
|
|
159
|
-
* @
|
|
160
|
+
* @warp-drive/legacy/model while migrating to WarpDrive.
|
|
160
161
|
*
|
|
161
162
|
* Example:
|
|
162
163
|
*
|
|
163
164
|
* ```ts
|
|
164
|
-
* import { withDefaults, WithLegacy } from '@
|
|
165
|
-
* import { Type } from '@warp-drive/core
|
|
166
|
-
* import type { HasMany } from '@
|
|
165
|
+
* import { withDefaults, WithLegacy } from '@warp-drive/legacy/model/migration-support';
|
|
166
|
+
* import { Type } from '@warp-drive/core/types/symbols';
|
|
167
|
+
* import type { HasMany } from '@warp-drive/legacy/model';
|
|
167
168
|
*
|
|
168
169
|
* export const UserSchema = withDefaults({
|
|
169
170
|
* type: 'user',
|
|
@@ -198,13 +199,13 @@ legacySupport[Type] = '@legacy';
|
|
|
198
199
|
* it requires with the schema service.
|
|
199
200
|
*
|
|
200
201
|
* ```ts
|
|
201
|
-
* import { registerDerivations } from '@
|
|
202
|
+
* import { registerDerivations } from '@warp-drive/legacy/model/migration-support';
|
|
202
203
|
*
|
|
203
204
|
* registerDerivations(schema);
|
|
204
205
|
* ```
|
|
205
206
|
*
|
|
206
|
-
* @param
|
|
207
|
-
* @return
|
|
207
|
+
* @param schema The schema to add legacy support to.
|
|
208
|
+
* @return The schema with legacy support added.
|
|
208
209
|
* @public
|
|
209
210
|
*/
|
|
210
211
|
function withDefaults(schema) {
|
|
@@ -248,6 +249,26 @@ function withDefaults(schema) {
|
|
|
248
249
|
schema.objectExtensions.push('deprecated-model-behaviors');
|
|
249
250
|
return schema;
|
|
250
251
|
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Adds the necessasary fields to the schema for supporting
|
|
255
|
+
* the deprecated request methods on LegacyMode schemas.
|
|
256
|
+
*
|
|
257
|
+
* Use this instead of `withDefaults` to add the fields
|
|
258
|
+
* and behaviors necessary to support Model-Like capabilities.
|
|
259
|
+
*
|
|
260
|
+
* ```ts
|
|
261
|
+
* import { withRestoredDeprecatedModelRequestBehaviors } from '@warp-drive/legacy/model/migration-support';
|
|
262
|
+
*
|
|
263
|
+
* export const UserSchema = withRestoredDeprecatedModelRequestBehaviors({
|
|
264
|
+
* type: 'user',
|
|
265
|
+
* fields: [
|
|
266
|
+
* { name: 'firstName', kind: 'attribute' },
|
|
267
|
+
* { name: 'lastName', kind: 'attribute' },
|
|
268
|
+
* ]
|
|
269
|
+
* });
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
251
272
|
function withRestoredDeprecatedModelRequestBehaviors(schema) {
|
|
252
273
|
schema.legacy = true;
|
|
253
274
|
schema.identity = {
|
|
@@ -293,13 +314,10 @@ function withRestoredDeprecatedModelRequestBehaviors(schema) {
|
|
|
293
314
|
|
|
294
315
|
/**
|
|
295
316
|
* A function which registers the necessary derivations to support
|
|
296
|
-
* the LegacyMode features of @
|
|
297
|
-
*
|
|
298
|
-
* This must be called in order to use the fields added by:
|
|
317
|
+
* the LegacyMode features of @warp-drive/legacy/model while migrating to WarpDrive.
|
|
299
318
|
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* ```
|
|
319
|
+
* This must be called in order to use the fields added by {@link withDefaults} or
|
|
320
|
+
* {@link withRestoredDeprecatedModelRequestBehaviors}.
|
|
303
321
|
*
|
|
304
322
|
* @param schema The schema service to register the derivations with.
|
|
305
323
|
* @public
|
|
@@ -398,8 +416,8 @@ function registerDerivations(schema) {
|
|
|
398
416
|
* provide their own schema information to the application.
|
|
399
417
|
*
|
|
400
418
|
* ```ts
|
|
401
|
-
* import { DelegatingSchemaService } from '@
|
|
402
|
-
* import { SchemaService } from '@warp-drive/
|
|
419
|
+
* import { DelegatingSchemaService } from '@warp-drive/legacy/model/migration-support';
|
|
420
|
+
* import { SchemaService } from '@warp-drive/core/reactive';
|
|
403
421
|
*
|
|
404
422
|
* class AppStore extends Store {
|
|
405
423
|
* createSchemaService() {
|
|
@@ -454,6 +472,15 @@ class DelegatingSchemaService {
|
|
|
454
472
|
}
|
|
455
473
|
return this._secondary.fields(resource);
|
|
456
474
|
}
|
|
475
|
+
cacheFields(resource) {
|
|
476
|
+
if (this._preferred.hasResource?.(resource)) {
|
|
477
|
+
// @ts-expect-error
|
|
478
|
+
return this._preferred.cacheFields?.(resource);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// @ts-expect-error
|
|
482
|
+
return this._secondary.cacheFields?.(resource);
|
|
483
|
+
}
|
|
457
484
|
transformation(field) {
|
|
458
485
|
return this._preferred.transformation(field);
|
|
459
486
|
}
|
|
@@ -484,6 +511,9 @@ class DelegatingSchemaService {
|
|
|
484
511
|
registerHashFn(hashFn) {
|
|
485
512
|
this._preferred.registerHashFn(hashFn);
|
|
486
513
|
}
|
|
514
|
+
CAUTION_MEGA_DANGER_ZONE_hasExtension(ext) {
|
|
515
|
+
return this._preferred.CAUTION_MEGA_DANGER_ZONE_hasExtension(ext);
|
|
516
|
+
}
|
|
487
517
|
CAUTION_MEGA_DANGER_ZONE_registerExtension(extension) {
|
|
488
518
|
this._preferred.CAUTION_MEGA_DANGER_ZONE_registerExtension(extension);
|
|
489
519
|
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { tracked, cached } from '@glimmer/tracking';
|
|
2
|
+
import { Context } from '@warp-drive/core/reactive/-private';
|
|
3
|
+
import { a as decorateFieldV2, i as initializeDeferredDecorator, d as decorateMethodV2 } from "./runtime-BPCpkOf1-BKOwiRJp.js";
|
|
4
|
+
class Fragment {
|
|
5
|
+
static {
|
|
6
|
+
decorateFieldV2(this.prototype, "isDestroying", [tracked], function () {
|
|
7
|
+
return false;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
#isDestroying = (initializeDeferredDecorator(this, "isDestroying"), void 0); // We might want to check the parent values once we move this code to warp-drive.
|
|
11
|
+
static {
|
|
12
|
+
decorateFieldV2(this.prototype, "isDestroyed", [tracked], function () {
|
|
13
|
+
return false;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
#isDestroyed = (initializeDeferredDecorator(this, "isDestroyed"), void 0);
|
|
17
|
+
get hasDirtyAttributes() {
|
|
18
|
+
const {
|
|
19
|
+
path,
|
|
20
|
+
resourceKey,
|
|
21
|
+
store
|
|
22
|
+
} = this[Context];
|
|
23
|
+
const record = store.peekRecord(resourceKey);
|
|
24
|
+
if (record.hasDirtyAttributes && path) {
|
|
25
|
+
const root = path.at(0);
|
|
26
|
+
return root in record.changedAttributes();
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
static {
|
|
31
|
+
decorateMethodV2(this.prototype, "hasDirtyAttributes", [cached]);
|
|
32
|
+
}
|
|
33
|
+
get isFragment() {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
get $type() {
|
|
37
|
+
const {
|
|
38
|
+
field
|
|
39
|
+
} = this[Context];
|
|
40
|
+
return field?.type;
|
|
41
|
+
}
|
|
42
|
+
rollbackAttributes() {
|
|
43
|
+
const {
|
|
44
|
+
path,
|
|
45
|
+
resourceKey,
|
|
46
|
+
store
|
|
47
|
+
} = this[Context];
|
|
48
|
+
if (path) {
|
|
49
|
+
const oldValue = store.cache.getRemoteAttr(resourceKey, path);
|
|
50
|
+
store.cache.setAttr(resourceKey, path, oldValue);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const FragmentExtension = {
|
|
55
|
+
kind: 'object',
|
|
56
|
+
name: 'fragment',
|
|
57
|
+
features: Fragment
|
|
58
|
+
};
|
|
59
|
+
class FragmentArray {
|
|
60
|
+
static {
|
|
61
|
+
decorateFieldV2(this.prototype, "isDestroying", [tracked], function () {
|
|
62
|
+
return false;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
#isDestroying = (initializeDeferredDecorator(this, "isDestroying"), void 0); // We might want to check the parent values once we move this code to warp-drive.
|
|
66
|
+
static {
|
|
67
|
+
decorateFieldV2(this.prototype, "isDestroyed", [tracked], function () {
|
|
68
|
+
return false;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
#isDestroyed = (initializeDeferredDecorator(this, "isDestroyed"), void 0);
|
|
72
|
+
get hasDirtyAttributes() {
|
|
73
|
+
const {
|
|
74
|
+
path,
|
|
75
|
+
resourceKey,
|
|
76
|
+
store
|
|
77
|
+
} = this[Context];
|
|
78
|
+
const record = store.peekRecord(resourceKey);
|
|
79
|
+
if (record.hasDirtyAttributes && path) {
|
|
80
|
+
const root = path.at(0);
|
|
81
|
+
return root in record.changedAttributes();
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
static {
|
|
86
|
+
decorateMethodV2(this.prototype, "hasDirtyAttributes", [cached]);
|
|
87
|
+
}
|
|
88
|
+
addFragment(fragment) {
|
|
89
|
+
if (!fragment) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
return this.addObject(fragment);
|
|
93
|
+
}
|
|
94
|
+
createFragment(fragment) {
|
|
95
|
+
if (!fragment) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
return this.pushObject(fragment);
|
|
99
|
+
}
|
|
100
|
+
removeFragment(fragment) {
|
|
101
|
+
if (!fragment) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const index = this.indexOf(fragment);
|
|
105
|
+
if (index !== -1) {
|
|
106
|
+
this.splice(index, 1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
rollbackAttributes() {
|
|
110
|
+
for (const fragment of this) {
|
|
111
|
+
// @ts-expect-error TODO: fix these types
|
|
112
|
+
fragment?.rollbackAttributes?.();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const FragmentArrayExtension = {
|
|
117
|
+
kind: 'array',
|
|
118
|
+
name: 'fragment-array',
|
|
119
|
+
features: FragmentArray
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// if modelFor turns out to be a bottleneck we should replace with a Map
|
|
123
|
+
// and clear it during store teardown.
|
|
124
|
+
const AvailableShims = new WeakMap();
|
|
125
|
+
function getShimClass(store, modelName) {
|
|
126
|
+
let shims = AvailableShims.get(store);
|
|
127
|
+
if (!shims) {
|
|
128
|
+
shims = Object.create(null);
|
|
129
|
+
AvailableShims.set(store, shims);
|
|
130
|
+
}
|
|
131
|
+
let shim = shims[modelName];
|
|
132
|
+
if (shim === undefined) {
|
|
133
|
+
shim = shims[modelName] = new ShimModelClass(store, modelName);
|
|
134
|
+
}
|
|
135
|
+
return shim;
|
|
136
|
+
}
|
|
137
|
+
const AttributeKinds = ['field', 'attribute', 'object', 'array', 'schema-object', 'schema-array'];
|
|
138
|
+
|
|
139
|
+
// Mimics the static apis of @warp-drive/legacy/model
|
|
140
|
+
class ShimModelClass {
|
|
141
|
+
constructor(store, modelName) {
|
|
142
|
+
this.__store = store;
|
|
143
|
+
this.modelName = modelName;
|
|
144
|
+
}
|
|
145
|
+
get fields() {
|
|
146
|
+
const fields = new Map();
|
|
147
|
+
const fieldSchemas = this.__store.schema.fields({
|
|
148
|
+
type: this.modelName
|
|
149
|
+
});
|
|
150
|
+
fieldSchemas.forEach((schema, key) => {
|
|
151
|
+
// @ts-expect-error checking if a string is a valid string
|
|
152
|
+
if (AttributeKinds.includes(schema.kind)) {
|
|
153
|
+
fields.set(key, 'attribute');
|
|
154
|
+
} else if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {
|
|
155
|
+
fields.set(key, schema.kind);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return fields;
|
|
159
|
+
}
|
|
160
|
+
get attributes() {
|
|
161
|
+
const attrs = new Map();
|
|
162
|
+
const fields = this.__store.schema.fields({
|
|
163
|
+
type: this.modelName
|
|
164
|
+
});
|
|
165
|
+
fields.forEach((schema, key) => {
|
|
166
|
+
if (schema.kind === 'attribute') {
|
|
167
|
+
attrs.set(key, schema);
|
|
168
|
+
// @ts-expect-error checking if a string is a valid string
|
|
169
|
+
} else if (AttributeKinds.includes(schema.kind)) {
|
|
170
|
+
attrs.set(key, {
|
|
171
|
+
kind: 'attribute',
|
|
172
|
+
name: key,
|
|
173
|
+
type: null,
|
|
174
|
+
options: schema.options ?? {}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return attrs;
|
|
179
|
+
}
|
|
180
|
+
get relationshipsByName() {
|
|
181
|
+
const rels = new Map();
|
|
182
|
+
const fields = this.__store.schema.fields({
|
|
183
|
+
type: this.modelName
|
|
184
|
+
});
|
|
185
|
+
fields.forEach((schema, key) => {
|
|
186
|
+
if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {
|
|
187
|
+
rels.set(key, schema);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return rels;
|
|
191
|
+
}
|
|
192
|
+
eachAttribute(callback, binding) {
|
|
193
|
+
this.attributes.forEach((schema, key) => {
|
|
194
|
+
callback.call(binding, key, schema);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
eachRelationship(callback, binding) {
|
|
198
|
+
this.__store.schema.fields({
|
|
199
|
+
type: this.modelName
|
|
200
|
+
}).forEach((schema, key) => {
|
|
201
|
+
if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {
|
|
202
|
+
callback.call(binding, key, schema);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
eachTransformedAttribute(callback, binding) {
|
|
207
|
+
this.__store.schema.fields({
|
|
208
|
+
type: this.modelName
|
|
209
|
+
}).forEach((schema, key) => {
|
|
210
|
+
if (schema.kind === 'attribute') {
|
|
211
|
+
const type = schema.type;
|
|
212
|
+
if (type) callback.call(binding, key, type);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function fragmentsModelFor(modelName) {
|
|
218
|
+
return getShimClass(this, modelName);
|
|
219
|
+
}
|
|
220
|
+
const modelFor = fragmentsModelFor;
|
|
221
|
+
export { FragmentExtension as F, FragmentArrayExtension as a, FragmentArray as b, Fragment as c, fragmentsModelFor as f, modelFor as m };
|
|
@@ -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 };
|