@warp-drive/legacy 5.8.0-alpha.16 → 5.8.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/index.d.ts +7 -3
- package/declarations/model/migration-support.d.ts +4 -0
- 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/dist/index.js +25 -5
- package/dist/model/migration-support.js +3 -0
- package/dist/model-for-B0TSd9HU.js +221 -0
- package/dist/model-fragments.js +76 -0
- package/package.json +6 -6
package/declarations/index.d.ts
CHANGED
|
@@ -6,8 +6,12 @@ import { Store, type StoreSetupOptions } from "@warp-drive/core";
|
|
|
6
6
|
import type { ObjectSchema, ResourceSchema } from "@warp-drive/core/types/schema/fields";
|
|
7
7
|
interface _LegacyStoreSetupOptions extends Omit<StoreSetupOptions, "schemas"> {
|
|
8
8
|
schemas?: Array<ResourceSchema | ObjectSchema>;
|
|
9
|
+
/**
|
|
10
|
+
* Whether to include support for ModelFragments migrations.
|
|
11
|
+
*/
|
|
12
|
+
modelFragments?: boolean;
|
|
9
13
|
}
|
|
10
|
-
interface LegacyModelStoreSetupOptions extends _LegacyStoreSetupOptions {
|
|
14
|
+
export interface LegacyModelStoreSetupOptions extends _LegacyStoreSetupOptions {
|
|
11
15
|
/**
|
|
12
16
|
* If true, it is presumed that no requests require use of the LegacyNetworkHandler
|
|
13
17
|
* and associated adapters/serializer methods.
|
|
@@ -19,7 +23,7 @@ interface LegacyModelStoreSetupOptions extends _LegacyStoreSetupOptions {
|
|
|
19
23
|
*/
|
|
20
24
|
legacyRequests?: false;
|
|
21
25
|
}
|
|
22
|
-
interface LegacyModelAndNetworkStoreSetupOptions extends _LegacyStoreSetupOptions {
|
|
26
|
+
export interface LegacyModelAndNetworkStoreSetupOptions extends _LegacyStoreSetupOptions {
|
|
23
27
|
/**
|
|
24
28
|
* If true, it is presumed that no requests require use of the LegacyNetworkHandler
|
|
25
29
|
* and associated adapters/serializer methods.
|
|
@@ -31,7 +35,7 @@ interface LegacyModelAndNetworkStoreSetupOptions extends _LegacyStoreSetupOption
|
|
|
31
35
|
*/
|
|
32
36
|
legacyRequests?: false;
|
|
33
37
|
}
|
|
34
|
-
interface LegacyModelAndNetworkAndRequestStoreSetupOptions extends _LegacyStoreSetupOptions {
|
|
38
|
+
export interface LegacyModelAndNetworkAndRequestStoreSetupOptions extends _LegacyStoreSetupOptions {
|
|
35
39
|
/**
|
|
36
40
|
* If true, it is presumed that no requests require use of the LegacyNetworkHandler
|
|
37
41
|
* and associated adapters/serializer methods.
|
|
@@ -243,6 +243,10 @@ export declare class DelegatingSchemaService implements SchemaService {
|
|
|
243
243
|
FM extends ObjectValue | null
|
|
244
244
|
>(derivation: Derivation<R, T, FM>): void;
|
|
245
245
|
registerHashFn(hashFn: HashFn): void;
|
|
246
|
+
CAUTION_MEGA_DANGER_ZONE_hasExtension(ext: {
|
|
247
|
+
kind: "object" | "array";
|
|
248
|
+
name: string;
|
|
249
|
+
}): boolean;
|
|
246
250
|
CAUTION_MEGA_DANGER_ZONE_registerExtension(extension: CAUTION_MEGA_DANGER_ZONE_Extension): void;
|
|
247
251
|
CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource: ResourceKey | {
|
|
248
252
|
type: string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Fragment } from "./fragment.js";
|
|
2
|
+
export declare class FragmentArray<T extends Fragment> {
|
|
3
|
+
isDestroying: boolean;
|
|
4
|
+
isDestroyed: boolean;
|
|
5
|
+
get hasDirtyAttributes(): boolean;
|
|
6
|
+
addFragment(fragment?: T): Fragment[] | undefined;
|
|
7
|
+
createFragment(fragment?: T): Fragment | undefined;
|
|
8
|
+
removeFragment(fragment?: T): void;
|
|
9
|
+
rollbackAttributes(): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const FragmentArrayExtension: {
|
|
12
|
+
kind: "array";
|
|
13
|
+
name: "fragment-array";
|
|
14
|
+
features: typeof FragmentArray;
|
|
15
|
+
};
|
|
16
|
+
export default FragmentArrayExtension;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PrivateReactiveResource } from "@warp-drive/core/reactive/-private";
|
|
2
|
+
export declare class Fragment {
|
|
3
|
+
isDestroying: boolean;
|
|
4
|
+
isDestroyed: boolean;
|
|
5
|
+
get hasDirtyAttributes(): boolean;
|
|
6
|
+
get isFragment(): boolean;
|
|
7
|
+
get $type(): string | null | undefined;
|
|
8
|
+
rollbackAttributes(this: PrivateReactiveResource): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const FragmentExtension: {
|
|
11
|
+
kind: "object";
|
|
12
|
+
name: "fragment";
|
|
13
|
+
features: typeof Fragment;
|
|
14
|
+
};
|
|
15
|
+
export default FragmentExtension;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Store } from "@warp-drive/core";
|
|
2
|
+
import type { ModelSchema } from "@warp-drive/core/types";
|
|
3
|
+
import type { TypedRecordInstance, TypeFromInstance } from "@warp-drive/core/types/record";
|
|
4
|
+
import type { LegacyAttributeField, LegacyRelationshipField } from "@warp-drive/core/types/schema/fields";
|
|
5
|
+
type KeyOrString<T> = keyof T & string extends never ? string : keyof T & string;
|
|
6
|
+
export declare function getShimClass<T>(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string): ShimModelClass<T>;
|
|
7
|
+
export declare class ShimModelClass<T = unknown> implements ModelSchema<T> {
|
|
8
|
+
__store: Store;
|
|
9
|
+
modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;
|
|
10
|
+
constructor(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string);
|
|
11
|
+
get fields(): Map<KeyOrString<T>, "attribute" | "belongsTo" | "hasMany">;
|
|
12
|
+
get attributes(): Map<KeyOrString<T>, LegacyAttributeField>;
|
|
13
|
+
get relationshipsByName(): Map<KeyOrString<T>, LegacyRelationshipField>;
|
|
14
|
+
eachAttribute<K extends KeyOrString<T>>(callback: (key: K, attribute: LegacyAttributeField) => void, binding?: T): void;
|
|
15
|
+
eachRelationship<K extends KeyOrString<T>>(callback: (key: K, relationship: LegacyRelationshipField) => void, binding?: T): void;
|
|
16
|
+
eachTransformedAttribute<K extends KeyOrString<T>>(callback: (key: K, type: string | null) => void, binding?: T): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function fragmentsModelFor<T extends TypedRecordInstance>(this: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string): ShimModelClass<T>;
|
|
19
|
+
export declare const modelFor: typeof fragmentsModelFor;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { WithArrayLike, WithEmberObject } from "../compat/extensions.js";
|
|
2
|
+
import type { Fragment } from "./extensions/fragment.js";
|
|
3
|
+
import type { FragmentArray } from "./extensions/fragment-array.js";
|
|
4
|
+
export type WithFragment<T> = T & WithEmberObject<T> & Fragment;
|
|
5
|
+
export type WithFragmentArray<T extends Fragment> = T & WithArrayLike<T> & FragmentArray<T>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type ApplicationInstance from "@ember/application/instance";
|
|
2
|
+
import type { SchemaService } from "@warp-drive/core/types";
|
|
3
|
+
export declare function registerFragmentExtensions(schema: SchemaService): void;
|
|
4
|
+
export declare function initialize(application: ApplicationInstance): void;
|
|
5
|
+
declare const _default: {
|
|
6
|
+
name: string;
|
|
7
|
+
initialize: (application: ApplicationInstance) => void;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Used as a helper to setup the relevant parts of an array
|
|
3
|
+
* schema and add extensions etc.
|
|
4
|
+
*
|
|
5
|
+
* @param arrayName The name of the array
|
|
6
|
+
* @returns The schema for an array
|
|
7
|
+
*/
|
|
8
|
+
export declare function withArrayDefaults<ArrayName extends string>(arrayName: ArrayName): {
|
|
9
|
+
kind: "array";
|
|
10
|
+
name: ArrayName;
|
|
11
|
+
type: `array:${string}`;
|
|
12
|
+
options: {
|
|
13
|
+
arrayExtensions: string[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Used as a helper to setup the relevant parts of a fragment-array
|
|
3
|
+
* schema and add extensions etc.
|
|
4
|
+
*
|
|
5
|
+
* @param fragmentArrayType The type of the fragment-array
|
|
6
|
+
* @param fragmentArrayName The name of the fragment-array
|
|
7
|
+
* @returns The schema for a fragment-array
|
|
8
|
+
*/
|
|
9
|
+
export declare function withFragmentArrayDefaults<
|
|
10
|
+
FragmentArrayType extends string,
|
|
11
|
+
FragmentArrayName extends string
|
|
12
|
+
>(fragmentArrayType: FragmentArrayType, fragmentArrayName?: FragmentArrayName): {
|
|
13
|
+
kind: "schema-array";
|
|
14
|
+
type: `fragment:${string}`;
|
|
15
|
+
name: string;
|
|
16
|
+
options: {
|
|
17
|
+
arrayExtensions: string[];
|
|
18
|
+
defaultValue: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Used as a helper to setup the relevant parts of a fragment schema
|
|
3
|
+
* and add extensions etc.
|
|
4
|
+
*
|
|
5
|
+
* @param fragmentType The type of the fragment
|
|
6
|
+
* @param fragmentName The optional name of the fragment. If not provided, it will default to the fragmentType.
|
|
7
|
+
* @returns The schema for a fragment
|
|
8
|
+
*/
|
|
9
|
+
export declare function withFragmentDefaults<
|
|
10
|
+
FragmentType extends string,
|
|
11
|
+
FragmentName extends string
|
|
12
|
+
>(fragmentType: FragmentType, fragmentName?: FragmentName): {
|
|
13
|
+
kind: "schema-object";
|
|
14
|
+
type: `fragment:${FragmentType}`;
|
|
15
|
+
name: FragmentType | FragmentName;
|
|
16
|
+
options: {
|
|
17
|
+
objectExtensions: string[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { LegacyResourceSchema, ResourceSchema } from "@warp-drive/core/types/schema/fields";
|
|
2
|
+
import type { WithPartial } from "@warp-drive/core/types/utils";
|
|
3
|
+
export declare function withLegacy(schema: WithPartial<LegacyResourceSchema, "legacy" | "identity">): ResourceSchema;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { withArrayDefaults } from "./model-fragments/utilities/with-array-defaults.js";
|
|
2
|
+
export { withFragmentDefaults } from "./model-fragments/utilities/with-fragment-defaults.js";
|
|
3
|
+
export { withFragmentArrayDefaults } from "./model-fragments/utilities/with-fragment-array-defaults.js";
|
|
4
|
+
export { withLegacy } from "./model-fragments/utilities/with-legacy.js";
|
|
5
|
+
export { registerFragmentExtensions } from "./model-fragments/instance-initializers/fragment-extensions.js";
|
|
6
|
+
export { modelFor } from "./model-fragments/hooks/model-for.js";
|
|
7
|
+
export { FragmentArray, FragmentArrayExtension } from "./model-fragments/extensions/fragment-array.js";
|
|
8
|
+
export { Fragment, FragmentExtension } from "./model-fragments/extensions/fragment.js";
|
|
9
|
+
export type { WithFragment, WithFragmentArray } from "./model-fragments/index.js";
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import "./errors-COviC59J.js";
|
|
|
13
13
|
import "./schema-provider-JlCneqZH.js";
|
|
14
14
|
import { i as instantiateRecord, t as teardownRecord, m as modelFor } from "./hooks-Bp8SIQBU.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-B0TSd9HU.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,25 @@ 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
|
+
|
|
132
|
+
// eslint-disable-next-line no-console
|
|
133
|
+
console.log(`model for ${type}`, klass);
|
|
134
|
+
return klass;
|
|
115
135
|
}
|
|
116
136
|
adapterFor(modelName, _allowMissing) {
|
|
117
137
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -162,7 +182,7 @@ function useLegacyStore(options, StoreKlass = Store) {
|
|
|
162
182
|
}
|
|
163
183
|
}
|
|
164
184
|
if (options.legacyRequests) {
|
|
165
|
-
restoreDeprecatedStoreBehaviors(
|
|
185
|
+
restoreDeprecatedStoreBehaviors(BaseKlass);
|
|
166
186
|
}
|
|
167
187
|
return LegacyConfiguredStore;
|
|
168
188
|
}
|
|
@@ -484,6 +484,9 @@ class DelegatingSchemaService {
|
|
|
484
484
|
registerHashFn(hashFn) {
|
|
485
485
|
this._preferred.registerHashFn(hashFn);
|
|
486
486
|
}
|
|
487
|
+
CAUTION_MEGA_DANGER_ZONE_hasExtension(ext) {
|
|
488
|
+
return this._preferred.CAUTION_MEGA_DANGER_ZONE_hasExtension(ext);
|
|
489
|
+
}
|
|
487
490
|
CAUTION_MEGA_DANGER_ZONE_registerExtension(extension) {
|
|
488
491
|
this._preferred.CAUTION_MEGA_DANGER_ZONE_registerExtension(extension);
|
|
489
492
|
}
|
|
@@ -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 @ember-data/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-B0TSd9HU.js";
|
|
4
|
+
export { c as Fragment, b as FragmentArray, m as modelFor } from "./model-for-B0TSd9HU.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive/legacy",
|
|
3
|
-
"version": "5.8.0-alpha.
|
|
3
|
+
"version": "5.8.0-alpha.17",
|
|
4
4
|
"description": "Decommissioned Packages for WarpDrive | Things your app might still want to maintain use of for a little longer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@warp-drive/core": "5.8.0-alpha.
|
|
36
|
-
"@warp-drive/utilities": "5.8.0-alpha.
|
|
35
|
+
"@warp-drive/core": "5.8.0-alpha.17",
|
|
36
|
+
"@warp-drive/utilities": "5.8.0-alpha.17"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@embroider/macros": "^1.18.1"
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@babel/plugin-transform-typescript": "^7.28.0",
|
|
44
44
|
"@babel/preset-typescript": "^7.27.1",
|
|
45
45
|
"@types/jquery": "^3.5.33",
|
|
46
|
-
"@warp-drive/internal-config": "5.8.0-alpha.
|
|
47
|
-
"@warp-drive/core": "5.8.0-alpha.
|
|
48
|
-
"@warp-drive/utilities": "5.8.0-alpha.
|
|
46
|
+
"@warp-drive/internal-config": "5.8.0-alpha.17",
|
|
47
|
+
"@warp-drive/core": "5.8.0-alpha.17",
|
|
48
|
+
"@warp-drive/utilities": "5.8.0-alpha.17",
|
|
49
49
|
"ember-source": "~6.6.0",
|
|
50
50
|
"decorator-transforms": "^2.3.0",
|
|
51
51
|
"expect-type": "^1.2.2",
|