@warp-drive/legacy 5.6.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +23 -0
- package/README.md +54 -0
- package/addon-main.cjs +5 -0
- package/declarations/adapter/-private/build-url-mixin.d.ts +34 -0
- package/declarations/adapter/-private/build-url-mixin.d.ts.map +1 -0
- package/declarations/adapter/-private/fastboot-interface.d.ts +9 -0
- package/declarations/adapter/-private/fastboot-interface.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts +8 -0
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/determine-body-promise.d.ts +5 -0
- package/declarations/adapter/-private/utils/determine-body-promise.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/fetch.d.ts +9 -0
- package/declarations/adapter/-private/utils/fetch.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/parse-response-headers.d.ts +2 -0
- package/declarations/adapter/-private/utils/parse-response-headers.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +7 -0
- package/declarations/adapter/-private/utils/serialize-into-hash.d.ts.map +1 -0
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts +6 -0
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts.map +1 -0
- package/declarations/adapter/-private.d.ts +6 -0
- package/declarations/adapter/-private.d.ts.map +1 -0
- package/declarations/adapter/error.d.ts +188 -0
- package/declarations/adapter/error.d.ts.map +1 -0
- package/declarations/adapter/json-api.d.ts +234 -0
- package/declarations/adapter/json-api.d.ts.map +1 -0
- package/declarations/adapter/rest.d.ts +823 -0
- package/declarations/adapter/rest.d.ts.map +1 -0
- package/declarations/adapter.d.ts +801 -0
- package/declarations/adapter.d.ts.map +1 -0
- package/declarations/compat/-private.d.ts +14 -0
- package/declarations/compat/-private.d.ts.map +1 -0
- package/declarations/compat/builders/find-all.d.ts +33 -0
- package/declarations/compat/builders/find-all.d.ts.map +1 -0
- package/declarations/compat/builders/find-record.d.ts +54 -0
- package/declarations/compat/builders/find-record.d.ts.map +1 -0
- package/declarations/compat/builders/query.d.ts +61 -0
- package/declarations/compat/builders/query.d.ts.map +1 -0
- package/declarations/compat/builders/save-record.d.ts +32 -0
- package/declarations/compat/builders/save-record.d.ts.map +1 -0
- package/declarations/compat/builders/utils.d.ts +4 -0
- package/declarations/compat/builders/utils.d.ts.map +1 -0
- package/declarations/compat/builders.d.ts +15 -0
- package/declarations/compat/builders.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +47 -0
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +3 -0
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +12 -0
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +6 -0
- package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +3 -0
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +527 -0
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +224 -0
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/serializer-response.d.ts +7 -0
- package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +89 -0
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +1 -0
- package/declarations/compat/legacy-network-handler/snapshot.d.ts +237 -0
- package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +1 -0
- package/declarations/compat/utils.d.ts +138 -0
- package/declarations/compat/utils.d.ts.map +1 -0
- package/declarations/compat.d.ts +134 -0
- package/declarations/compat.d.ts.map +1 -0
- package/declarations/model/-private/attr.d.ts +165 -0
- package/declarations/model/-private/attr.d.ts.map +1 -0
- package/declarations/model/-private/attr.type-test.d.ts +2 -0
- package/declarations/model/-private/attr.type-test.d.ts.map +1 -0
- package/declarations/model/-private/belongs-to.d.ts +173 -0
- package/declarations/model/-private/belongs-to.d.ts.map +1 -0
- package/declarations/model/-private/belongs-to.type-test.d.ts +2 -0
- package/declarations/model/-private/belongs-to.type-test.d.ts.map +1 -0
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +6 -0
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
- package/declarations/model/-private/errors.d.ts +290 -0
- package/declarations/model/-private/errors.d.ts.map +1 -0
- package/declarations/model/-private/has-many.d.ts +164 -0
- package/declarations/model/-private/has-many.d.ts.map +1 -0
- package/declarations/model/-private/has-many.type-test.d.ts +2 -0
- package/declarations/model/-private/has-many.type-test.d.ts.map +1 -0
- package/declarations/model/-private/hooks.d.ts +11 -0
- package/declarations/model/-private/hooks.d.ts.map +1 -0
- package/declarations/model/-private/legacy-relationships-support.d.ts +57 -0
- package/declarations/model/-private/legacy-relationships-support.d.ts.map +1 -0
- package/declarations/model/-private/model-for-mixin.d.ts +4 -0
- package/declarations/model/-private/model-for-mixin.d.ts.map +1 -0
- package/declarations/model/-private/model-methods.d.ts +35 -0
- package/declarations/model/-private/model-methods.d.ts.map +1 -0
- package/declarations/model/-private/model.d.ts +1270 -0
- package/declarations/model/-private/model.d.ts.map +1 -0
- package/declarations/model/-private/model.type-test.d.ts +2 -0
- package/declarations/model/-private/model.type-test.d.ts.map +1 -0
- package/declarations/model/-private/notify-changes.d.ts +5 -0
- package/declarations/model/-private/notify-changes.d.ts.map +1 -0
- package/declarations/model/-private/promise-belongs-to.d.ts +40 -0
- package/declarations/model/-private/promise-belongs-to.d.ts.map +1 -0
- package/declarations/model/-private/promise-many-array.d.ts +126 -0
- package/declarations/model/-private/promise-many-array.d.ts.map +1 -0
- package/declarations/model/-private/promise-proxy-base.d.ts +3 -0
- package/declarations/model/-private/promise-proxy-base.d.ts.map +1 -0
- package/declarations/model/-private/record-state.d.ts +78 -0
- package/declarations/model/-private/record-state.d.ts.map +1 -0
- package/declarations/model/-private/references/belongs-to.d.ts +495 -0
- package/declarations/model/-private/references/belongs-to.d.ts.map +1 -0
- package/declarations/model/-private/references/has-many.d.ts +504 -0
- package/declarations/model/-private/references/has-many.d.ts.map +1 -0
- package/declarations/model/-private/schema-provider.d.ts +63 -0
- package/declarations/model/-private/schema-provider.d.ts.map +1 -0
- package/declarations/model/-private/type-utils.d.ts +57 -0
- package/declarations/model/-private/type-utils.d.ts.map +1 -0
- package/declarations/model/-private/util.d.ts +6 -0
- package/declarations/model/-private/util.d.ts.map +1 -0
- package/declarations/model/-private.d.ts +8 -0
- package/declarations/model/-private.d.ts.map +1 -0
- package/declarations/model/migration-support.d.ts +287 -0
- package/declarations/model/migration-support.d.ts.map +1 -0
- package/declarations/model/migration-support.type-test.d.ts +2 -0
- package/declarations/model/migration-support.type-test.d.ts.map +1 -0
- package/declarations/model.d.ts +50 -0
- package/declarations/model.d.ts.map +1 -0
- package/declarations/serializer/-private/embedded-records-mixin.d.ts +97 -0
- package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
- package/declarations/serializer/-private/transforms/boolean.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +2 -0
- package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/date.d.ts +28 -0
- package/declarations/serializer/-private/transforms/date.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/number.d.ts +29 -0
- package/declarations/serializer/-private/transforms/number.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/string.d.ts +29 -0
- package/declarations/serializer/-private/transforms/string.d.ts.map +1 -0
- package/declarations/serializer/-private/transforms/transform.d.ts +119 -0
- package/declarations/serializer/-private/transforms/transform.d.ts.map +1 -0
- package/declarations/serializer/-private/utils.d.ts +4 -0
- package/declarations/serializer/-private/utils.d.ts.map +1 -0
- package/declarations/serializer/json-api.d.ts +496 -0
- package/declarations/serializer/json-api.d.ts.map +1 -0
- package/declarations/serializer/json.d.ts +1047 -0
- package/declarations/serializer/json.d.ts.map +1 -0
- package/declarations/serializer/rest.d.ts +554 -0
- package/declarations/serializer/rest.d.ts.map +1 -0
- package/declarations/serializer/transform.d.ts +6 -0
- package/declarations/serializer/transform.d.ts.map +1 -0
- package/declarations/serializer.d.ts +258 -0
- package/declarations/serializer.d.ts.map +1 -0
- package/dist/-private-DFfBszo5.js +1182 -0
- package/dist/-private-DFfBszo5.js.map +1 -0
- package/dist/adapter/-private.js +1 -0
- package/dist/adapter/-private.js.map +1 -0
- package/dist/adapter/error.js +254 -0
- package/dist/adapter/error.js.map +1 -0
- package/dist/adapter/json-api.js +129 -0
- package/dist/adapter/json-api.js.map +1 -0
- package/dist/adapter/rest.js +1262 -0
- package/dist/adapter/rest.js.map +1 -0
- package/dist/adapter.js +1284 -0
- package/dist/adapter.js.map +1 -0
- package/dist/compat/-private.js +1 -0
- package/dist/compat/-private.js.map +1 -0
- package/dist/compat/builders.js +292 -0
- package/dist/compat/builders.js.map +1 -0
- package/dist/compat/utils.js +225 -0
- package/dist/compat/utils.js.map +1 -0
- package/dist/compat.js +999 -0
- package/dist/compat.js.map +1 -0
- package/dist/errors-D74uk36r.js +2541 -0
- package/dist/errors-D74uk36r.js.map +1 -0
- package/dist/json-BCH3fil7.js +1349 -0
- package/dist/json-BCH3fil7.js.map +1 -0
- package/dist/model/-private.js +2 -0
- package/dist/model/-private.js.map +1 -0
- package/dist/model/migration-support.js +453 -0
- package/dist/model/migration-support.js.map +1 -0
- package/dist/model.js +736 -0
- package/dist/model.js.map +1 -0
- package/dist/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +1 -0
- package/dist/schema-provider-CXFLTMjg.js +2228 -0
- package/dist/schema-provider-CXFLTMjg.js.map +1 -0
- package/dist/serialize-into-hash-BxfqWC8u.js +260 -0
- package/dist/serialize-into-hash-BxfqWC8u.js.map +1 -0
- package/dist/serializer/json-api.js +514 -0
- package/dist/serializer/json-api.js.map +1 -0
- package/dist/serializer/json.js +6 -0
- package/dist/serializer/json.js.map +1 -0
- package/dist/serializer/rest.js +1245 -0
- package/dist/serializer/rest.js.map +1 -0
- package/dist/serializer/transform.js +313 -0
- package/dist/serializer/transform.js.map +1 -0
- package/dist/serializer.js +252 -0
- package/dist/serializer.js.map +1 -0
- package/logos/NCC-1701-a-blue.svg +4 -0
- package/logos/NCC-1701-a-gold.svg +4 -0
- package/logos/NCC-1701-a-gold_100.svg +1 -0
- package/logos/NCC-1701-a-gold_base-64.txt +1 -0
- package/logos/NCC-1701-a.svg +4 -0
- package/logos/README.md +4 -0
- package/logos/docs-badge.svg +2 -0
- package/logos/ember-data-logo-dark.svg +12 -0
- package/logos/ember-data-logo-light.svg +12 -0
- package/logos/github-header.svg +444 -0
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +4 -0
- package/logos/warp-drive-logo-gold.svg +4 -0
- package/package.json +72 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
type Reporter = (type: 'formatted-id' | 'formatted-type', actual: unknown, expected: unknown) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Configure a function to be called when an id or type
|
|
4
|
+
* changes during normalization. This is useful for instrumenting
|
|
5
|
+
* to discover places where usage in the app is not consistent.
|
|
6
|
+
*
|
|
7
|
+
* @param method a function which takes a mismatch-type ('formatted-id' | 'formatted-type'), actual, and expected value
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare function configureMismatchReporter(fn: Reporter): void;
|
|
11
|
+
/**
|
|
12
|
+
* Configure a function to be called when an id or type
|
|
13
|
+
* fails validation. This is useful for instrumenting
|
|
14
|
+
* to discover places where usage in the app is not consistent.
|
|
15
|
+
*
|
|
16
|
+
* @param method a function which takes a message and a condition
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export declare function configureAssertFn(fn: (message: string, condition: unknown) => void): void;
|
|
20
|
+
/**
|
|
21
|
+
* Configure a function to be called to normalize
|
|
22
|
+
* a resource type string. Used by both formattedType
|
|
23
|
+
* and isEquivType to ensure consistent normalization
|
|
24
|
+
* during comparison.
|
|
25
|
+
*
|
|
26
|
+
* If validation fails or the type turns out be unnormalized
|
|
27
|
+
* the configured mismatch reporter and assert functions will
|
|
28
|
+
* be called.
|
|
29
|
+
*
|
|
30
|
+
* @param method a function which takes a string and returns a string
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export declare function configureTypeNormalization(fn: (type: string) => string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Converts a potentially unnormalized type into the format expected
|
|
36
|
+
* by our EmberData Cache. Currently this is singular-dasherized.
|
|
37
|
+
*
|
|
38
|
+
* you should not rely on this function to give you an exact format
|
|
39
|
+
* for display purposes. Formatting for display should be handled
|
|
40
|
+
* differently if the exact format matters.
|
|
41
|
+
*
|
|
42
|
+
* Asserts invalid types (undefined, null, '') in dev.
|
|
43
|
+
*
|
|
44
|
+
* **Usage**
|
|
45
|
+
*
|
|
46
|
+
* ```js
|
|
47
|
+
* import formattedType from 'soxhub-client/helpers/formatted-type';
|
|
48
|
+
*
|
|
49
|
+
* formattedType('post'); // => 'post'
|
|
50
|
+
* formattedType('posts'); // => 'post'
|
|
51
|
+
* formattedType('Posts'); // => 'post'
|
|
52
|
+
* formattedType('post-comment'); // => 'post-comment'
|
|
53
|
+
* formattedType('post-comments'); // => 'post-comment'
|
|
54
|
+
* formattedType('post_comment'); // => 'post-comment'
|
|
55
|
+
* formattedType('postComment'); // => 'post-comment'
|
|
56
|
+
* formattedType('PostComment'); // => 'post-comment'
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @param {String} type the potentially un-normalized type
|
|
60
|
+
* @return {String} the normalized type
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export declare function formattedType<T extends string>(type: T | string): T;
|
|
64
|
+
/**
|
|
65
|
+
* Format an id to the format expected by the EmberData Cache.
|
|
66
|
+
* Currently this means that id should be `string | null`.
|
|
67
|
+
*
|
|
68
|
+
* Asserts invalid IDs (undefined, '', 0, '0') in dev.
|
|
69
|
+
*
|
|
70
|
+
* **Usage**
|
|
71
|
+
*
|
|
72
|
+
* ```js
|
|
73
|
+
* import formattedId from 'client/utils/formatted-id';
|
|
74
|
+
*
|
|
75
|
+
* formattedId('1'); // => '1'
|
|
76
|
+
* formattedId(1); // => '1'
|
|
77
|
+
* formattedId(null); // => null
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @param {String | Number | null} id the potentially un-normalized id
|
|
81
|
+
* @return {String | null} the normalized id
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export declare function formattedId(id: string | number): string;
|
|
85
|
+
export declare function formattedId(id: null): null;
|
|
86
|
+
export declare function formattedId(id: string | number | null): string | null;
|
|
87
|
+
export declare function expectId(id: string | number): string;
|
|
88
|
+
export declare function expectId(id: null): never;
|
|
89
|
+
/**
|
|
90
|
+
* Compares two types for strict equality, converting them to
|
|
91
|
+
* the format expected by the EmberData Cache to ensure
|
|
92
|
+
* differences in format are accounted for in the comparison.
|
|
93
|
+
*
|
|
94
|
+
* Asserts when expected or actual are invalid types in dev.
|
|
95
|
+
* Expected may never be null.
|
|
96
|
+
*
|
|
97
|
+
* ```js
|
|
98
|
+
* isEquivType('posts', 'post'); // true
|
|
99
|
+
* isEquivType('post', 'post'); // true
|
|
100
|
+
* isEquivType('posts', 'posts'); // true
|
|
101
|
+
* isEquivType('post-comment', 'postComment'); // true
|
|
102
|
+
* isEquivType('post-comment', 'PostComment'); // true
|
|
103
|
+
* isEquivType('post-comment', 'post_comment'); // true
|
|
104
|
+
* isEquivType('post-comment', 'post-comment'); // true
|
|
105
|
+
* isEquivType('post-comment', 'post'); // false
|
|
106
|
+
* isEquivType('posts', null); // false
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @param {String} expected a potentially unnormalized type to match against
|
|
110
|
+
* @param {String} actual a potentially unnormalized type to match against
|
|
111
|
+
* @return {Boolean} true if the types are equivalent
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
export declare function isEquivType(expected: string, actual: string): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Compares two IDs for strict equality, converting them to
|
|
117
|
+
* the format expected by the EmberData Cache to ensure
|
|
118
|
+
* differences in format are accounted for in the comparison.
|
|
119
|
+
*
|
|
120
|
+
* Asserts when expected or actual are invalid IDs in dev.
|
|
121
|
+
* Expected may never be null.
|
|
122
|
+
*
|
|
123
|
+
* ```js
|
|
124
|
+
* isEquivId('1', 1); // true
|
|
125
|
+
* isEquivId('2', '2'); // true
|
|
126
|
+
* isEquivId(3, '3'); // true
|
|
127
|
+
* isEquivId(4, '3'); // false
|
|
128
|
+
* isEquivId(1, null); // false
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @param {string | number} expected a potentially un-normalized id to match against
|
|
132
|
+
* @param {string | number} actual a potentially un-normalized id to match against
|
|
133
|
+
* @return {Boolean} true if the ids are equivalent
|
|
134
|
+
* @public
|
|
135
|
+
*/
|
|
136
|
+
export declare function isEquivId(expected: string | number, actual: string | number | null): boolean;
|
|
137
|
+
export {};
|
|
138
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/compat/utils.ts"],"names":[],"mappings":"AAeA,KAAK,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G,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAyB5F"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { type Store } from '@warp-drive/core';
|
|
2
|
+
import type { ObjectValue } from '@warp-drive/core/types/json/raw';
|
|
3
|
+
import { FetchManager } from './compat/-private.ts';
|
|
4
|
+
import type { AdapterPayload, MinimumAdapterInterface } from './compat/legacy-network-handler/minimum-adapter-interface.ts';
|
|
5
|
+
import type { MinimumSerializerInterface, SerializerOptions } from './compat/legacy-network-handler/minimum-serializer-interface.ts';
|
|
6
|
+
export { LegacyNetworkHandler } from './compat/legacy-network-handler/legacy-network-handler.ts';
|
|
7
|
+
export type { MinimumAdapterInterface, MinimumSerializerInterface, SerializerOptions, AdapterPayload };
|
|
8
|
+
export type LegacyStoreCompat = {
|
|
9
|
+
_fetchManager: FetchManager;
|
|
10
|
+
adapterFor(this: Store, modelName: string): MinimumAdapterInterface;
|
|
11
|
+
adapterFor(this: Store, modelName: string, _allowMissing: true): MinimumAdapterInterface | undefined;
|
|
12
|
+
serializerFor<K extends string>(modelName: K, _allowMissing?: boolean): MinimumSerializerInterface | null;
|
|
13
|
+
normalize(modelName: string, payload: ObjectValue): ObjectValue;
|
|
14
|
+
pushPayload(modelName: string, payload: ObjectValue): void;
|
|
15
|
+
serializeRecord(record: unknown, options?: SerializerOptions): unknown;
|
|
16
|
+
_adapterCache: Record<string, MinimumAdapterInterface & {
|
|
17
|
+
store: Store;
|
|
18
|
+
}>;
|
|
19
|
+
_serializerCache: Record<string, MinimumSerializerInterface & {
|
|
20
|
+
store: Store;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
export type CompatStore = Store & LegacyStoreCompat;
|
|
24
|
+
/**
|
|
25
|
+
Returns an instance of the adapter for a given type. For
|
|
26
|
+
example, `adapterFor('person')` will return an instance of
|
|
27
|
+
the adapter located at `app/adapters/person.js`
|
|
28
|
+
|
|
29
|
+
If no `person` adapter is found, this method will look
|
|
30
|
+
for an `application` adapter (the default adapter for
|
|
31
|
+
your entire application).
|
|
32
|
+
|
|
33
|
+
@public
|
|
34
|
+
@param {String} modelName
|
|
35
|
+
@return {Adapter}
|
|
36
|
+
*/
|
|
37
|
+
export declare function adapterFor(this: Store, modelName: string): MinimumAdapterInterface;
|
|
38
|
+
export declare function adapterFor(this: Store, modelName: string, _allowMissing: true): MinimumAdapterInterface | undefined;
|
|
39
|
+
/**
|
|
40
|
+
Returns an instance of the serializer for a given type. For
|
|
41
|
+
example, `serializerFor('person')` will return an instance of
|
|
42
|
+
`App.PersonSerializer`.
|
|
43
|
+
|
|
44
|
+
If no `App.PersonSerializer` is found, this method will look
|
|
45
|
+
for an `App.ApplicationSerializer` (the default serializer for
|
|
46
|
+
your entire application).
|
|
47
|
+
|
|
48
|
+
If a serializer cannot be found on the adapter, it will fall back
|
|
49
|
+
to an instance of `JSONSerializer`.
|
|
50
|
+
|
|
51
|
+
@public
|
|
52
|
+
@param {String} modelName the record to serialize
|
|
53
|
+
@return {Serializer}
|
|
54
|
+
*/
|
|
55
|
+
export declare function serializerFor(this: Store, modelName: string): MinimumSerializerInterface | null;
|
|
56
|
+
/**
|
|
57
|
+
`normalize` converts a json payload into the normalized form that
|
|
58
|
+
[push](../methods/push?anchor=push) expects.
|
|
59
|
+
|
|
60
|
+
Example
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
socket.on('message', function(message) {
|
|
64
|
+
let modelName = message.model;
|
|
65
|
+
let data = message.data;
|
|
66
|
+
store.push(store.normalize(modelName, data));
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
@public
|
|
71
|
+
@param {String} modelName The name of the model type for this payload
|
|
72
|
+
@param {Object} payload
|
|
73
|
+
@return {Object} The normalized payload
|
|
74
|
+
*/
|
|
75
|
+
export declare function normalize(this: Store, modelName: string, payload: ObjectValue): import("@warp-drive/core/types/spec/json-api-raw.js").SingleResourceDocument;
|
|
76
|
+
/**
|
|
77
|
+
Push some raw data into the store.
|
|
78
|
+
|
|
79
|
+
This method can be used both to push in brand new
|
|
80
|
+
records, as well as to update existing records. You
|
|
81
|
+
can push in more than one type of object at once.
|
|
82
|
+
All objects should be in the format expected by the
|
|
83
|
+
serializer.
|
|
84
|
+
|
|
85
|
+
```js [app/serializers/application.js]
|
|
86
|
+
import RESTSerializer from '@ember-data/serializer/rest';
|
|
87
|
+
|
|
88
|
+
export default class ApplicationSerializer extends RESTSerializer;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
let pushData = {
|
|
93
|
+
posts: [
|
|
94
|
+
{ id: 1, postTitle: "Great post", commentIds: [2] }
|
|
95
|
+
],
|
|
96
|
+
comments: [
|
|
97
|
+
{ id: 2, commentBody: "Insightful comment" }
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
store.pushPayload(pushData);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
By default, the data will be deserialized using a default
|
|
105
|
+
serializer (the application serializer if it exists).
|
|
106
|
+
|
|
107
|
+
Alternatively, `pushPayload` will accept a model type which
|
|
108
|
+
will determine which serializer will process the payload.
|
|
109
|
+
|
|
110
|
+
```js [app/serializers/application.js]
|
|
111
|
+
import RESTSerializer from '@ember-data/serializer/rest';
|
|
112
|
+
|
|
113
|
+
export default class ApplicationSerializer extends RESTSerializer;
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```js [app/serializers/post.js]
|
|
117
|
+
import JSONSerializer from '@ember-data/serializer/json';
|
|
118
|
+
|
|
119
|
+
export default JSONSerializer;
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
store.pushPayload(pushData); // Will use the application serializer
|
|
124
|
+
store.pushPayload('post', pushData); // Will use the post serializer
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
@public
|
|
128
|
+
@param {String} modelName Optionally, a model type used to determine which serializer will be used
|
|
129
|
+
@param {Object} inputPayload
|
|
130
|
+
*/
|
|
131
|
+
export declare function pushPayload(this: Store, modelName: string, inputPayload: ObjectValue): void;
|
|
132
|
+
export declare function serializeRecord(this: Store, record: unknown, options?: SerializerOptions): unknown;
|
|
133
|
+
export declare function cleanup(this: Store): void;
|
|
134
|
+
//# sourceMappingURL=compat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../src/compat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAgB,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EACxB,MAAM,8DAA8D,CAAC;AACtE,OAAO,KAAK,EACV,0BAA0B,EAC1B,iBAAiB,EAClB,MAAM,iEAAiE,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2DAA2D,CAAC;AAEjG,YAAY,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,cAAc,EAAE,CAAC;AAEvG,MAAM,MAAM,iBAAiB,GAAG;IAC9B,aAAa,EAAE,YAAY,CAAC;IAC5B,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,GAAG,uBAAuB,CAAC;IACpE,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,GAAG,uBAAuB,GAAG,SAAS,CAAC;IAErG,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,0BAA0B,GAAG,IAAI,CAAC;IAE1G,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,WAAW,CAAC;IAChE,WAAW,CAAC,S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GAAG,OAAO,CAQlG;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,KAAK,QAgBlC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { ArrayValue, ObjectValue, PrimitiveValue } from '@warp-drive/core/types/json/raw';
|
|
2
|
+
import type { TransformName } from '@warp-drive/core/types/symbols';
|
|
3
|
+
import type { DecoratorPropertyDescriptor } from './util.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Options provided to the attr decorator are
|
|
6
|
+
* supplied to the associated transform. Any
|
|
7
|
+
* key-value pair is valid; however, it is highly
|
|
8
|
+
* recommended to only use statically defined values
|
|
9
|
+
* that could be serialized to JSON.
|
|
10
|
+
*
|
|
11
|
+
* If no transform is provided, the only valid
|
|
12
|
+
* option is `defaultValue`.
|
|
13
|
+
*
|
|
14
|
+
* Examples:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* class User extends Model {
|
|
18
|
+
* @attr('string', { defaultValue: 'Anonymous' }) name;
|
|
19
|
+
* @attr('date', { defaultValue: () => new Date() }) createdAt;
|
|
20
|
+
* @attr({ defaultValue: () => ({}) }) preferences;
|
|
21
|
+
* @attr('boolean') hasVerifiedEmail;
|
|
22
|
+
* @attr address;
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* @class NOTATHING
|
|
26
|
+
*/
|
|
27
|
+
export type AttrOptions<DV = PrimitiveValue | object | unknown[]> = {
|
|
28
|
+
/**
|
|
29
|
+
* The default value for this attribute.
|
|
30
|
+
*
|
|
31
|
+
* Default values can be provided as a value or a function that will be
|
|
32
|
+
* executed to generate the default value.
|
|
33
|
+
*
|
|
34
|
+
* Default values *should not* be stateful (object, arrays, etc.) as
|
|
35
|
+
* they will be shared across all instances of the record.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
defaultValue?: DV extends PrimitiveValue ? DV : () => DV;
|
|
39
|
+
};
|
|
40
|
+
type LooseTransformInstance<V, Raw, Name extends string> = {
|
|
41
|
+
/**
|
|
42
|
+
* value type must match the return type of the deserialize method
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
serialize: (value: V, options: any) => Raw;
|
|
46
|
+
/**
|
|
47
|
+
* defaultValue type must match the return type of the deserialize method
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
deserialize: (value: Raw, options: any) => V;
|
|
51
|
+
[TransformName]: Name;
|
|
52
|
+
};
|
|
53
|
+
export type TransformHasType = {
|
|
54
|
+
[TransformName]: string;
|
|
55
|
+
};
|
|
56
|
+
export type TypedTransformInstance<V, T extends string> = LooseTransformInstance<V, string, T> | LooseTransformInstance<V, number, T> | LooseTransformInstance<V, boolean, T> | LooseTransformInstance<V, null, T> | LooseTransformInstance<V, ObjectValue, T> | LooseTransformInstance<V, ArrayValue, T> | LooseTransformInstance<V, string | null, T> | LooseTransformInstance<V, number | null, T> | LooseTransformInstance<V, boolean | null, T> | LooseTransformInstance<V, ObjectValue | null, T> | LooseTransformInstance<V, ArrayValue | null, T>;
|
|
57
|
+
export type GetMaybeDeserializeValue<T> = T extends {
|
|
58
|
+
deserialize: (...args: any[]) => unknown;
|
|
59
|
+
} ? ReturnType<T['deserialize']> : never;
|
|
60
|
+
export type TypeFromInstance<T> = T extends TransformHasType ? T[typeof TransformName] : never;
|
|
61
|
+
export type ExtractOptions<T extends TypedTransformInstance<GetMaybeDeserializeValue<T>, TypeFromInstance<T>>> = Parameters<T['deserialize']>[1] & Parameters<T['serialize']>[1] & AttrOptions<ReturnType<T['deserialize']>>;
|
|
62
|
+
export type OptionsFromInstance<T> = TypeFromInstance<T> extends never ? never : GetMaybeDeserializeValue<T> extends never ? never : T extends TypedTransformInstance<GetMaybeDeserializeValue<T>, TypeFromInstance<T>> ? Parameters<T['deserialize']>[1] & Parameters<T['serialize']>[1] & AttrOptions<ReturnType<T['deserialize']>> : never;
|
|
63
|
+
/**
|
|
64
|
+
* The return type of `void` is a lie to appease TypeScript. The actual return type
|
|
65
|
+
* is a descriptor, but typescript incorrectly insists that decorator functions return
|
|
66
|
+
* `void` or `any`.
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
export type DataDecorator = (target: object, key: string, desc?: DecoratorPropertyDescriptor) => void;
|
|
70
|
+
/**
|
|
71
|
+
`attr` defines an attribute on a [Model](/ember-data/release/classes/Model).
|
|
72
|
+
By default, attributes are passed through as-is, however you can specify an
|
|
73
|
+
optional type to have the value automatically transformed.
|
|
74
|
+
EmberData ships with four basic transform types: `string`, `number`,
|
|
75
|
+
`boolean` and `date`. You can define your own transforms by subclassing
|
|
76
|
+
[Transform](/ember-data/release/classes/Transform).
|
|
77
|
+
|
|
78
|
+
Note that you cannot use `attr` to define an attribute of `id`.
|
|
79
|
+
|
|
80
|
+
`attr` takes an optional hash as a second parameter, currently
|
|
81
|
+
supported options are:
|
|
82
|
+
|
|
83
|
+
- `defaultValue`: Pass a string or a function to be called to set the attribute
|
|
84
|
+
to a default value if and only if the key is absent from the payload response.
|
|
85
|
+
|
|
86
|
+
Example
|
|
87
|
+
|
|
88
|
+
```js [app/models/user.js]
|
|
89
|
+
import { Model, attr } from '@warp-drive/legacy/model';
|
|
90
|
+
|
|
91
|
+
export default class UserModel extends Model {
|
|
92
|
+
@attr('string') username;
|
|
93
|
+
@attr('string') email;
|
|
94
|
+
@attr('boolean', { defaultValue: false }) verified;
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Default value can also be a function. This is useful it you want to return
|
|
99
|
+
a new object for each attribute.
|
|
100
|
+
|
|
101
|
+
```js [app/models/user.js]
|
|
102
|
+
import { Model, attr } from '@warp-drive/legacy/model';
|
|
103
|
+
|
|
104
|
+
export default class UserModel extends Model {
|
|
105
|
+
@attr('string') username;
|
|
106
|
+
@attr('string') email;
|
|
107
|
+
|
|
108
|
+
@attr({
|
|
109
|
+
defaultValue() {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
settings;
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The `options` hash is passed as second argument to a transforms'
|
|
118
|
+
`serialize` and `deserialize` method. This allows to configure a
|
|
119
|
+
transformation and adapt the corresponding value, based on the config:
|
|
120
|
+
|
|
121
|
+
```js [app/models/post.js]
|
|
122
|
+
import { Model, attr } from '@warp-drive/legacy/model';
|
|
123
|
+
|
|
124
|
+
export default class PostModel extends Model {
|
|
125
|
+
@attr('text', {
|
|
126
|
+
uppercase: true
|
|
127
|
+
})
|
|
128
|
+
text;
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```js [app/transforms/text.js]
|
|
133
|
+
export default class TextTransform {
|
|
134
|
+
serialize(value, options) {
|
|
135
|
+
if (options.uppercase) {
|
|
136
|
+
return value.toUpperCase();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
deserialize(value) {
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static create() {
|
|
147
|
+
return new this();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
@public
|
|
153
|
+
@param {String|Object} type the attribute type
|
|
154
|
+
@param {Object} options a hash of options
|
|
155
|
+
@return {Attribute}
|
|
156
|
+
*/
|
|
157
|
+
export declare function attr(): DataDecorator;
|
|
158
|
+
export declare function attr<T>(type: TypeFromInstance<T>): DataDecorator;
|
|
159
|
+
export declare function attr(type: string): DataDecorator;
|
|
160
|
+
export declare function attr(options: AttrOptions): DataDecorator;
|
|
161
|
+
export declare function attr<T>(type: TypeFromInstance<T>, options?: OptionsFromInstance<T>): DataDecorator;
|
|
162
|
+
export declare function attr(type: string, options?: AttrOptions & object): DataDecorator;
|
|
163
|
+
export declare function attr(target: object, key: string | symbol, desc?: PropertyDescriptor): void;
|
|
164
|
+
export {};
|
|
165
|
+
//# sourceMappingURL=attr.d.ts.map
|
|
@@ -0,0 +1 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G,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attr.type-test.d.ts","sourceRoot":"","sources":["../../../src/model/-private/attr.type-test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { TypeFromInstance } from '@warp-drive/core/types/record';
|
|
2
|
+
export type IsUnknown<T> = unknown extends T ? true : false;
|
|
3
|
+
export type RelationshipOptions<T, Async extends boolean> = {
|
|
4
|
+
async: Async;
|
|
5
|
+
inverse: null | (IsUnknown<T> extends true ? string : keyof NoNull<T> & string);
|
|
6
|
+
polymorphic?: boolean;
|
|
7
|
+
as?: string;
|
|
8
|
+
linksMode?: true;
|
|
9
|
+
resetOnRemoteUpdate?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type NoNull<T> = Exclude<T, null>;
|
|
12
|
+
export type RelationshipDecorator<T> = <This>(target: This, key: string, desc?: PropertyDescriptor) => void;
|
|
13
|
+
/**
|
|
14
|
+
`belongsTo` is used to define One-To-One and One-To-Many, and One-To-None
|
|
15
|
+
relationships on a [Model](/ember-data/release/classes/Model).
|
|
16
|
+
|
|
17
|
+
`belongsTo` takes a configuration hash as a second parameter, currently
|
|
18
|
+
supported options are:
|
|
19
|
+
|
|
20
|
+
- `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.
|
|
21
|
+
- `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.
|
|
22
|
+
- `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic
|
|
23
|
+
- `as`: (*optional*) A string used to declare the abstract type "this" record satisfies for polymorphism.
|
|
24
|
+
|
|
25
|
+
### Examples
|
|
26
|
+
|
|
27
|
+
To declare a **one-to-many** (or many-to-many) relationship, use
|
|
28
|
+
`belongsTo` in combination with `hasMany`:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
// app/models/comment.js
|
|
32
|
+
import { Model, belongsTo } from '@warp-drive/legacy/model';
|
|
33
|
+
|
|
34
|
+
export default class Comment extends Model {
|
|
35
|
+
@belongsTo('post', { async: false, inverse: 'comments' }) post;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// app/models/post.js
|
|
39
|
+
import { Model, hasMany } from '@warp-drive/legacy/model';
|
|
40
|
+
|
|
41
|
+
export default class Post extends Model {
|
|
42
|
+
@hasMany('comment', { async: false, inverse: 'post' }) comments;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
To declare a **one-to-one** relationship with managed inverses, use `belongsTo` for both sides:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
// app/models/author.js
|
|
50
|
+
import { Model, belongsTo } from '@warp-drive/legacy/model';
|
|
51
|
+
|
|
52
|
+
export default class Author extends Model {
|
|
53
|
+
@belongsTo('address', { async: true, inverse: 'owner' }) address;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// app/models/address.js
|
|
57
|
+
import { Model, belongsTo } from '@warp-drive/legacy/model';
|
|
58
|
+
|
|
59
|
+
export default class Address extends Model {
|
|
60
|
+
@belongsTo('author', { async: true, inverse: 'address' }) owner;
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
To declare a **one-to-one** relationship without managed inverses, use `belongsTo` for both sides
|
|
65
|
+
with `null` as the inverse:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
// app/models/author.js
|
|
69
|
+
import { Model, belongsTo } from '@warp-drive/legacy/model';
|
|
70
|
+
|
|
71
|
+
export default class Author extends Model {
|
|
72
|
+
@belongsTo('address', { async: true, inverse: null }) address;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// app/models/address.js
|
|
76
|
+
import { Model, belongsTo } from '@warp-drive/legacy/model';
|
|
77
|
+
|
|
78
|
+
export default class Address extends Model {
|
|
79
|
+
@belongsTo('author', { async: true, inverse: null }) owner;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
To declare a one-to-none relationship between two models, use
|
|
84
|
+
`belongsTo` with inverse set to `null` on just one side::
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
// app/models/person.js
|
|
88
|
+
import { Model, belongsTo } from '@warp-drive/legacy/model';
|
|
89
|
+
|
|
90
|
+
export default class Person extends Model {
|
|
91
|
+
@belongsTo('person', { async: false, inverse: null }) bestFriend;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Sync vs Async Relationships
|
|
96
|
+
|
|
97
|
+
EmberData fulfills relationships using resource data available in
|
|
98
|
+
the cache.
|
|
99
|
+
|
|
100
|
+
Sync relationships point directly to the known related resources.
|
|
101
|
+
|
|
102
|
+
When a relationship is declared as async, if any of the known related
|
|
103
|
+
resources have not been loaded, they will be fetched. The property
|
|
104
|
+
on the record when accessed provides a promise that resolves once
|
|
105
|
+
all resources are loaded.
|
|
106
|
+
|
|
107
|
+
Async relationships may take advantage of links. On access, if the related
|
|
108
|
+
link has not been loaded, or if any known resources are not available in
|
|
109
|
+
the cache, the fresh state will be fetched using the link.
|
|
110
|
+
|
|
111
|
+
In contrast to async relationship, accessing a sync relationship
|
|
112
|
+
will error on access when any of the known related resources have
|
|
113
|
+
not been loaded.
|
|
114
|
+
|
|
115
|
+
If you are using `links` with sync relationships, you have to use
|
|
116
|
+
the BelongsTo reference API to fetch or refresh related resources
|
|
117
|
+
that aren't loaded. For instance, for a `bestFriend` relationship:
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
person.belongsTo('bestFriend').reload();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### Polymorphic Relationships
|
|
124
|
+
|
|
125
|
+
To declare a polymorphic relationship, use `hasMany` with the `polymorphic`
|
|
126
|
+
option set to `true`:
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
// app/models/comment.js
|
|
130
|
+
import { Model, belongsTo } from '@warp-drive/legacy/model';
|
|
131
|
+
|
|
132
|
+
export default class Comment extends Model {
|
|
133
|
+
@belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`'commentable'` here is referred to as the "abstract type" for the polymorphic
|
|
138
|
+
relationship.
|
|
139
|
+
|
|
140
|
+
Polymorphic relationships with `inverse: null` will accept any type of record as their content.
|
|
141
|
+
Polymorphic relationships with `inverse` set to a string will only accept records with a matching
|
|
142
|
+
inverse relationships declaring itself as satisfying the abstract type.
|
|
143
|
+
|
|
144
|
+
Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'
|
|
145
|
+
for this relationship.
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
// app/models/post.js
|
|
149
|
+
import { Model, hasMany } from '@warp-drive/legacy/model';
|
|
150
|
+
|
|
151
|
+
export default class Post extends Model {
|
|
152
|
+
@hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Note: every Model that declares an inverse to a polymorphic relationship must
|
|
157
|
+
declare itself exactly the same. This is because polymorphism is based on structural
|
|
158
|
+
traits.
|
|
159
|
+
|
|
160
|
+
Polymorphic to polymorphic relationships are supported. Both sides of the relationship
|
|
161
|
+
must be declared as polymorphic, and the `as` option must be used to declare the abstract
|
|
162
|
+
type each record satisfies on both sides.
|
|
163
|
+
|
|
164
|
+
@public
|
|
165
|
+
@param {String} type (optional) the name of the related resource
|
|
166
|
+
@param {Object} options (optional) a hash of options
|
|
167
|
+
@return {PropertyDescriptor} relationship
|
|
168
|
+
*/
|
|
169
|
+
export declare function belongsTo(): never;
|
|
170
|
+
export declare function belongsTo(type: string): never;
|
|
171
|
+
export declare function belongsTo<T>(type: TypeFromInstance<NoNull<T>>, options: RelationshipOptions<T, boolean>): RelationshipDecorator<T>;
|
|
172
|
+
export declare function belongsTo(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;
|
|
173
|
+
//# sourceMappingURL=belongs-to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AgB,SAAS,CAAC,CAAC,EACzB,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EACjC,OAAO,EAAE,mBAAmB,CAAC,CAAC,EAAE,OAAO,CAAC,GACvC,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAK5B,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"belongs-to.type-test.d.ts","sourceRoot":"","sources":["../../../src/model/-private/belongs-to.type-test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Store } from '@warp-drive/core';
|
|
2
|
+
import type { UpgradedMeta } from '@warp-drive/core/graph/-private';
|
|
3
|
+
import type { StableRecordIdentifier } from '@warp-drive/core/types/identifier';
|
|
4
|
+
declare let assertPolymorphicType: (parentIdentifier: StableRecordIdentifier, parentDefinition: UpgradedMeta, addedIdentifier: StableRecordIdentifier, store: Store) => void;
|
|
5
|
+
export { assertPolymorphicType };
|
|
6
|
+
//# sourceMappingURL=assert-polymorphic-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-polymorphic-type.d.ts","sourceRoot":"","sources":["../../../../src/model/-private/debug/assert-polymorphic-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAchF,QAAA,IAAI,qBAAqB,EAAE,CACzB,gBAAgB,EAAE,sBAAsB,EACxC,gBAAgB,EAAE,YAAY,EAC9B,eAAe,EAAE,sBAAsB,EACvC,KAAK,EAAE,KAAK,KACT,IAAI,CAAC;AA6BV,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|