@warp-drive/legacy 5.9.0-alpha.18 → 5.9.0-alpha.19
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/model/-private/attr.d.ts +21 -0
- package/declarations/model/-private/belongs-to.d.ts +21 -0
- package/declarations/model/-private/schema-provider.d.ts +4 -1
- package/declarations/serializer/-private/utils.d.ts +24 -0
- package/dist/{hooks-CoxuoIfB.js → hooks-DuAlm6Rk.js} +1 -1
- package/dist/index.js +26 -3
- package/dist/json-DR3gUXRl.js +1329 -0
- package/dist/model/migration-support.js +1 -1
- package/dist/model.js +11 -7
- package/dist/{schema-provider-qgBVdfoF.js → schema-provider-y3Wz44Br.js} +19 -1
- package/dist/serializer/json-api.js +1 -1
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +2 -3
- package/dist/unpkg/dev/{hooks-BAeKqW7Q.js → hooks-BEiCsM8w.js} +1 -1
- package/dist/unpkg/dev/index.js +26 -3
- package/dist/unpkg/{prod-deprecated/json-BWrZ5546.js → dev/json-0O0HyAmg.js} +87 -4
- package/dist/unpkg/dev/model/migration-support.js +1 -1
- package/dist/unpkg/dev/model.js +11 -7
- package/dist/unpkg/dev/{schema-provider-CBgMOLPn.js → schema-provider-CkZd1K6p.js} +19 -1
- package/dist/unpkg/dev/serializer/json-api.js +1 -1
- package/dist/unpkg/dev/serializer/json.js +1 -1
- package/dist/unpkg/dev/serializer/rest.js +2 -3
- package/dist/unpkg/dev-deprecated/{hooks-CX2QnOWh.js → hooks-CCFCZJvG.js} +1 -1
- package/dist/unpkg/dev-deprecated/index.js +26 -3
- package/dist/unpkg/{dev/json-Cu1LNgmQ.js → dev-deprecated/json-0O0HyAmg.js} +74 -4
- package/dist/unpkg/dev-deprecated/model/migration-support.js +1 -1
- package/dist/unpkg/dev-deprecated/model.js +11 -7
- package/dist/unpkg/dev-deprecated/{schema-provider-Cby8K0AB.js → schema-provider-Bow8-gvt.js} +19 -1
- package/dist/unpkg/dev-deprecated/serializer/json-api.js +1 -1
- package/dist/unpkg/dev-deprecated/serializer/json.js +1 -1
- package/dist/unpkg/dev-deprecated/serializer/rest.js +2 -3
- package/dist/unpkg/prod/{hooks-BenXLbeb.js → hooks-BLLUOwXG.js} +1 -1
- package/dist/unpkg/prod/index.js +26 -3
- package/dist/{json-ChdEfB0X.js → unpkg/prod/json-C3hcpFmX.js} +54 -20
- package/dist/unpkg/prod/model/migration-support.js +1 -1
- package/dist/unpkg/prod/model.js +11 -7
- package/dist/unpkg/prod/{schema-provider-DHGEb_sz.js → schema-provider-D-l95_QW.js} +14 -1
- package/dist/unpkg/prod/serializer/json-api.js +1 -1
- package/dist/unpkg/prod/serializer/json.js +1 -1
- package/dist/unpkg/prod/serializer/rest.js +2 -3
- package/dist/unpkg/prod-deprecated/{hooks-Ds1PZsBo.js → hooks-p4t9BWeH.js} +1 -1
- package/dist/unpkg/prod-deprecated/index.js +26 -3
- package/dist/unpkg/{dev-deprecated/json-Cu1LNgmQ.js → prod-deprecated/json-C3hcpFmX.js} +54 -17
- package/dist/unpkg/prod-deprecated/model/migration-support.js +1 -1
- package/dist/unpkg/prod-deprecated/model.js +11 -7
- package/dist/unpkg/prod-deprecated/{schema-provider-D6EzGZB-.js → schema-provider-qisHNwCL.js} +14 -1
- package/dist/unpkg/prod-deprecated/serializer/json-api.js +1 -1
- package/dist/unpkg/prod-deprecated/serializer/json.js +1 -1
- package/dist/unpkg/prod-deprecated/serializer/rest.js +2 -3
- package/package.json +6 -6
- package/dist/unpkg/prod/json-BWrZ5546.js +0 -1243
|
@@ -36,6 +36,27 @@ export type AttrOptions<DV = PrimitiveValue | object | unknown[]> = {
|
|
|
36
36
|
*
|
|
37
37
|
*/
|
|
38
38
|
defaultValue?: DV extends PrimitiveValue ? DV : () => DV;
|
|
39
|
+
/**
|
|
40
|
+
* The name of the field as returned by the API and inserted into the
|
|
41
|
+
* cache if it differs from the name of the decorated property.
|
|
42
|
+
*
|
|
43
|
+
* For instance, if the API returns:
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* {
|
|
47
|
+
* attributes: {
|
|
48
|
+
* 'first-name': 'Chris'
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* But the app desires to use `record.firstName; // 'Chris'`, then the
|
|
54
|
+
* property should be named `firstName` and `sourceKey` should be set
|
|
55
|
+
* to `'first-name'`.
|
|
56
|
+
*
|
|
57
|
+
* This option is only needed when the value differs from the property name.
|
|
58
|
+
*/
|
|
59
|
+
sourceKey?: string;
|
|
39
60
|
};
|
|
40
61
|
type LooseTransformInstance<
|
|
41
62
|
V,
|
|
@@ -10,6 +10,27 @@ export type RelationshipOptions<
|
|
|
10
10
|
as?: string;
|
|
11
11
|
linksMode?: true;
|
|
12
12
|
resetOnRemoteUpdate?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The name of the field as returned by the API and inserted into the
|
|
15
|
+
* cache if it differs from the name of the decorated property.
|
|
16
|
+
*
|
|
17
|
+
* For instance, if the API returns:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* {
|
|
21
|
+
* relationships: {
|
|
22
|
+
* 'best-friend': { data: { type: 'user', id: '1' } }
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* But the app desires to use `record.bestFriend`, then the property
|
|
28
|
+
* should be named `bestFriend` and `sourceKey` should be set to
|
|
29
|
+
* `'best-friend'`.
|
|
30
|
+
*
|
|
31
|
+
* This option is only needed when the value differs from the property name.
|
|
32
|
+
*/
|
|
33
|
+
sourceKey?: string;
|
|
13
34
|
};
|
|
14
35
|
export type NoNull<T> = Exclude<T, null>;
|
|
15
36
|
export type RelationshipDecorator<T> = <This>(target: This, key: string, desc?: PropertyDescriptor) => void;
|
|
@@ -3,7 +3,7 @@ import type { SchemaService } from "@warp-drive/core/types";
|
|
|
3
3
|
import type { ResourceKey } from "@warp-drive/core/types/identifier";
|
|
4
4
|
import type { ObjectValue } from "@warp-drive/core/types/json/raw";
|
|
5
5
|
import type { Derivation, HashFn, Transformation } from "@warp-drive/core/types/schema/concepts";
|
|
6
|
-
import type { ArrayField, DerivedField, GenericField, HashField, LegacyField, ObjectField, ObjectSchema, ResourceSchema } from "@warp-drive/core/types/schema/fields";
|
|
6
|
+
import type { ArrayField, CacheableFieldSchema, DerivedField, GenericField, HashField, IdentityField, LegacyField, ObjectField, ObjectSchema, ResourceSchema } from "@warp-drive/core/types/schema/fields";
|
|
7
7
|
import type { ModelFactory, ModelStore } from "./model.js";
|
|
8
8
|
type AttributesSchema = ReturnType<Exclude<SchemaService["attributesDefinitionFor"], undefined>>;
|
|
9
9
|
type RelationshipsSchema = ReturnType<Exclude<SchemaService["relationshipsDefinitionFor"], undefined>>;
|
|
@@ -47,6 +47,9 @@ export declare class ModelSchemaProvider implements SchemaService {
|
|
|
47
47
|
fields(resource: ResourceKey | {
|
|
48
48
|
type: string;
|
|
49
49
|
}): Map<string, LegacyField>;
|
|
50
|
+
cacheFields(resource: ResourceKey | {
|
|
51
|
+
type: string;
|
|
52
|
+
}): Map<string, Exclude<CacheableFieldSchema, IdentityField>>;
|
|
50
53
|
hasResource(resource: {
|
|
51
54
|
type: string;
|
|
52
55
|
}): boolean;
|
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
import type { Store } from "@warp-drive/core";
|
|
2
|
+
import type { LegacyBelongsToField, LegacyHasManyField, LegacyRelationshipField } from "@warp-drive/core/types/schema/fields";
|
|
1
3
|
type Coercable = string | number | boolean | null | undefined | symbol;
|
|
2
4
|
export declare function coerceId(id: Coercable): string | null;
|
|
5
|
+
/**
|
|
6
|
+
Given the name of a relationship on a resource `type`, determines the
|
|
7
|
+
inverse relationship field (if any) using only the schema service.
|
|
8
|
+
|
|
9
|
+
Unlike `Model.inverseFor`, this does not require `type` to be backed by
|
|
10
|
+
a `Model` class, so it works for both `Model`-based and schema-only
|
|
11
|
+
(e.g. `withDefaults` migration-support) resources.
|
|
12
|
+
|
|
13
|
+
@private
|
|
14
|
+
*/
|
|
15
|
+
export declare function inverseForRelationship(store: Store, type: string, name: string): LegacyRelationshipField | null;
|
|
16
|
+
/**
|
|
17
|
+
Given a relationship field on a resource `type`, determines the
|
|
18
|
+
cardinality of the relationship using only the schema service.
|
|
19
|
+
|
|
20
|
+
Unlike `Model.determineRelationshipType`, this does not require `type`
|
|
21
|
+
to be backed by a `Model` class, so it works for both `Model`-based and
|
|
22
|
+
schema-only (e.g. `withDefaults` migration-support) resources.
|
|
23
|
+
|
|
24
|
+
@private
|
|
25
|
+
*/
|
|
26
|
+
export declare function determineRelationshipType(store: Store, type: string, knownSide: LegacyBelongsToField | LegacyHasManyField): "oneToOne" | "oneToMany" | "manyToOne" | "manyToMany" | "oneToNone" | "manyToNone";
|
|
3
27
|
export {};
|
|
@@ -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-y3Wz44Br.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
|
@@ -10,8 +10,8 @@ import '@warp-drive/utilities/string';
|
|
|
10
10
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
11
11
|
import '@warp-drive/core/store/-private';
|
|
12
12
|
import "./errors-Cz5KrzBk.js";
|
|
13
|
-
import "./schema-provider-
|
|
14
|
-
import { i as instantiateRecord, t as teardownRecord, m as modelFor } from "./hooks-
|
|
13
|
+
import "./schema-provider-y3Wz44Br.js";
|
|
14
|
+
import { i as instantiateRecord, t as teardownRecord, m as modelFor } from "./hooks-DuAlm6Rk.js";
|
|
15
15
|
import { registerDerivations as registerDerivations$1, DelegatingSchemaService } from './model/migration-support.js';
|
|
16
16
|
import { F as FragmentExtension, a as FragmentArrayExtension, f as fragmentsModelFor } from "./model-for-DOiIKvY_.js";
|
|
17
17
|
import { restoreDeprecatedStoreBehaviors } from './store.js';
|
|
@@ -43,7 +43,30 @@ function useLegacyStore(options, StoreKlass = Store) {
|
|
|
43
43
|
// we extend the store to ensure we don't leak our prototype overrides to other stores below.
|
|
44
44
|
class BaseKlass extends StoreKlass {}
|
|
45
45
|
class LegacyConfiguredStore extends BaseKlass {
|
|
46
|
-
|
|
46
|
+
constructor(createArgs) {
|
|
47
|
+
super(createArgs);
|
|
48
|
+
// installed via defineProperty (rather than a class field/accessor) so that
|
|
49
|
+
// this lazy override of the inherited `requestManager` field does not
|
|
50
|
+
// conflict with the documented pattern of assigning it directly on
|
|
51
|
+
// consumer-authored Store subclasses. The setter preserves the ability
|
|
52
|
+
// to replace `requestManager` outright after construction.
|
|
53
|
+
let requestManager;
|
|
54
|
+
Object.defineProperty(this, 'requestManager', {
|
|
55
|
+
configurable: true,
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: () => {
|
|
58
|
+
if (!requestManager) {
|
|
59
|
+
const handlersOption = options.handlers;
|
|
60
|
+
const handlers = typeof handlersOption === 'function' ? handlersOption(this) : handlersOption ?? [];
|
|
61
|
+
requestManager = new RequestManager().use([options.linksMode ? null : LegacyNetworkHandler, ...handlers, Fetch].filter(Boolean)).useCache(CacheHandler);
|
|
62
|
+
}
|
|
63
|
+
return requestManager;
|
|
64
|
+
},
|
|
65
|
+
set: value => {
|
|
66
|
+
requestManager = value;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
47
70
|
lifetimes = options.policy ?? new DefaultCachePolicy({
|
|
48
71
|
apiCacheHardExpires: 15 * 60 * 1000,
|
|
49
72
|
// 15 minutes
|