@ember-data/model 5.4.0-alpha.32 → 5.4.0-alpha.33
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/package.json +19 -19
- package/unstable-preview-types/-private/attr.d.ts +171 -169
- package/unstable-preview-types/-private/attr.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/belongs-to.d.ts +181 -179
- package/unstable-preview-types/-private/belongs-to.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +8 -6
- package/unstable-preview-types/-private/errors.d.ts +290 -288
- package/unstable-preview-types/-private/has-many.d.ts +170 -168
- package/unstable-preview-types/-private/has-many.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/hooks.d.ts +13 -11
- package/unstable-preview-types/-private/legacy-relationships-support.d.ts +62 -60
- package/unstable-preview-types/-private/many-array.d.ts +193 -191
- package/unstable-preview-types/-private/model-for-mixin.d.ts +6 -4
- package/unstable-preview-types/-private/model-methods.d.ts +34 -32
- package/unstable-preview-types/-private/model.d.ts +103 -100
- package/unstable-preview-types/-private/model.type-test.d.ts +4 -2
- package/unstable-preview-types/-private/notify-changes.d.ts +8 -6
- package/unstable-preview-types/-private/promise-belongs-to.d.ts +47 -45
- package/unstable-preview-types/-private/promise-many-array.d.ts +129 -127
- package/unstable-preview-types/-private/promise-proxy-base.d.ts +35 -32
- package/unstable-preview-types/-private/record-state.d.ts +88 -86
- package/unstable-preview-types/-private/references/belongs-to.d.ts +473 -471
- package/unstable-preview-types/-private/references/has-many.d.ts +488 -486
- package/unstable-preview-types/-private/schema-provider.d.ts +27 -25
- package/unstable-preview-types/-private/util.d.ts +11 -9
- package/unstable-preview-types/-private.d.ts +12 -10
- package/unstable-preview-types/hooks.d.ts +5 -3
- package/unstable-preview-types/index.d.ts +75 -46
- package/unstable-preview-types/migration-support.d.ts +11 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-data/model",
|
|
3
|
-
"version": "5.4.0-alpha.
|
|
3
|
+
"version": "5.4.0-alpha.33",
|
|
4
4
|
"description": "A basic Ember implementation of a resource presentation layer for use with @ember-data/store",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"ember-data-logo-light.svg"
|
|
30
30
|
],
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@ember-data/debug": "5.4.0-alpha.
|
|
33
|
-
"@ember-data/graph": "5.4.0-alpha.
|
|
34
|
-
"@ember-data/json-api": "5.4.0-alpha.
|
|
35
|
-
"@ember-data/legacy-compat": "5.4.0-alpha.
|
|
36
|
-
"@ember-data/store": "5.4.0-alpha.
|
|
37
|
-
"@ember-data/tracking": "5.4.0-alpha.
|
|
32
|
+
"@ember-data/debug": "5.4.0-alpha.33",
|
|
33
|
+
"@ember-data/graph": "5.4.0-alpha.33",
|
|
34
|
+
"@ember-data/json-api": "5.4.0-alpha.33",
|
|
35
|
+
"@ember-data/legacy-compat": "5.4.0-alpha.33",
|
|
36
|
+
"@ember-data/store": "5.4.0-alpha.33",
|
|
37
|
+
"@ember-data/tracking": "5.4.0-alpha.33",
|
|
38
38
|
"@ember/string": "^3.1.1",
|
|
39
|
-
"@warp-drive/core-types": "0.0.0-alpha.
|
|
39
|
+
"@warp-drive/core-types": "0.0.0-alpha.19",
|
|
40
40
|
"ember-inflector": "^4.0.2"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"@ember-data/private-build-infra": "5.4.0-alpha.
|
|
92
|
+
"@ember-data/private-build-infra": "5.4.0-alpha.33",
|
|
93
93
|
"@ember/edition-utils": "^1.2.0",
|
|
94
94
|
"@embroider/macros": "^1.13.5",
|
|
95
95
|
"ember-cli-babel": "^8.2.0",
|
|
@@ -109,21 +109,21 @@
|
|
|
109
109
|
"@babel/preset-env": "^7.23.9",
|
|
110
110
|
"@babel/preset-typescript": "^7.23.3",
|
|
111
111
|
"@babel/runtime": "^7.23.9",
|
|
112
|
-
"@ember-data/debug": "5.4.0-alpha.
|
|
113
|
-
"@ember-data/graph": "5.4.0-alpha.
|
|
114
|
-
"@ember-data/json-api": "5.4.0-alpha.
|
|
115
|
-
"@ember-data/legacy-compat": "5.4.0-alpha.
|
|
116
|
-
"@ember-data/request": "5.4.0-alpha.
|
|
117
|
-
"@ember-data/request-utils": "5.4.0-alpha.
|
|
118
|
-
"@ember-data/store": "5.4.0-alpha.
|
|
119
|
-
"@ember-data/tracking": "5.4.0-alpha.
|
|
112
|
+
"@ember-data/debug": "5.4.0-alpha.33",
|
|
113
|
+
"@ember-data/graph": "5.4.0-alpha.33",
|
|
114
|
+
"@ember-data/json-api": "5.4.0-alpha.33",
|
|
115
|
+
"@ember-data/legacy-compat": "5.4.0-alpha.33",
|
|
116
|
+
"@ember-data/request": "5.4.0-alpha.33",
|
|
117
|
+
"@ember-data/request-utils": "5.4.0-alpha.33",
|
|
118
|
+
"@ember-data/store": "5.4.0-alpha.33",
|
|
119
|
+
"@ember-data/tracking": "5.4.0-alpha.33",
|
|
120
120
|
"@ember/string": "^3.1.1",
|
|
121
121
|
"@embroider/addon-dev": "^4.1.2",
|
|
122
122
|
"@glimmer/component": "^1.1.2",
|
|
123
123
|
"@rollup/plugin-babel": "^6.0.4",
|
|
124
124
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
125
|
-
"@warp-drive/core-types": "0.0.0-alpha.
|
|
126
|
-
"@warp-drive/internal-config": "5.4.0-alpha.
|
|
125
|
+
"@warp-drive/core-types": "0.0.0-alpha.19",
|
|
126
|
+
"@warp-drive/internal-config": "5.4.0-alpha.33",
|
|
127
127
|
"ember-inflector": "^4.0.2",
|
|
128
128
|
"ember-source": "~5.6.0",
|
|
129
129
|
"expect-type": "^0.18.0",
|
|
@@ -1,172 +1,174 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
export type
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export type
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
The `options` hash is passed as second argument to a transforms'
|
|
122
|
-
`serialize` and `deserialize` method. This allows to configure a
|
|
123
|
-
transformation and adapt the corresponding value, based on the config:
|
|
124
|
-
|
|
125
|
-
```app/models/post.js
|
|
126
|
-
import Model, { attr } from '@ember-data/model';
|
|
127
|
-
|
|
128
|
-
export default class PostModel extends Model {
|
|
129
|
-
@attr('text', {
|
|
130
|
-
uppercase: true
|
|
131
|
-
})
|
|
132
|
-
text;
|
|
133
|
-
}
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
```app/transforms/text.js
|
|
137
|
-
export default class TextTransform {
|
|
138
|
-
serialize(value, options) {
|
|
139
|
-
if (options.uppercase) {
|
|
140
|
-
return value.toUpperCase();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return value;
|
|
1
|
+
declare module '@ember-data/model/-private/attr' {
|
|
2
|
+
import type { ArrayValue, ObjectValue, PrimitiveValue } from '@warp-drive/core-types/json/raw';
|
|
3
|
+
import type { TransformName } from '@warp-drive/core-types/symbols';
|
|
4
|
+
import type { DecoratorPropertyDescriptor } from '@ember-data/model/-private/util';
|
|
5
|
+
/**
|
|
6
|
+
* Options provided to the attr decorator are
|
|
7
|
+
* supplied to the associated transform. Any
|
|
8
|
+
* key-value pair is valid; however, it is highly
|
|
9
|
+
* recommended to only use statically defined values
|
|
10
|
+
* that could be serialized to JSON.
|
|
11
|
+
*
|
|
12
|
+
* If no transform is provided, the only valid
|
|
13
|
+
* option is `defaultValue`.
|
|
14
|
+
*
|
|
15
|
+
* Examples:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* class User extends Model {
|
|
19
|
+
* @attr('string', { defaultValue: 'Anonymous' }) name;
|
|
20
|
+
* @attr('date', { defaultValue: () => new Date() }) createdAt;
|
|
21
|
+
* @attr({ defaultValue: () => ({}) }) preferences;
|
|
22
|
+
* @attr('boolean') hasVerifiedEmail;
|
|
23
|
+
* @attr address;
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* @class NOTATHING
|
|
27
|
+
* @typedoc
|
|
28
|
+
*/
|
|
29
|
+
export type AttrOptions<DV = PrimitiveValue | object | unknown[]> = {
|
|
30
|
+
/**
|
|
31
|
+
* The default value for this attribute.
|
|
32
|
+
*
|
|
33
|
+
* Default values can be provided as a value or a function that will be
|
|
34
|
+
* executed to generate the default value.
|
|
35
|
+
*
|
|
36
|
+
* Default values *should not* be stateful (object, arrays, etc.) as
|
|
37
|
+
* they will be shared across all instances of the record.
|
|
38
|
+
*
|
|
39
|
+
* @typedoc
|
|
40
|
+
*/
|
|
41
|
+
defaultValue?: DV extends PrimitiveValue ? DV : () => DV;
|
|
42
|
+
};
|
|
43
|
+
type LooseTransformInstance<V, Raw, Name extends string> = {
|
|
44
|
+
/**
|
|
45
|
+
* value type must match the return type of the deserialize method
|
|
46
|
+
*
|
|
47
|
+
* @typedoc
|
|
48
|
+
*/
|
|
49
|
+
serialize: (value: V, options: any) => Raw;
|
|
50
|
+
/**
|
|
51
|
+
* defaultValue type must match the return type of the deserialize method
|
|
52
|
+
*
|
|
53
|
+
* @typedoc
|
|
54
|
+
*/
|
|
55
|
+
deserialize: (value: Raw, options: any) => V;
|
|
56
|
+
[TransformName]: Name;
|
|
57
|
+
};
|
|
58
|
+
export type TransformHasType = {
|
|
59
|
+
[TransformName]: string;
|
|
60
|
+
};
|
|
61
|
+
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>;
|
|
62
|
+
export type GetMaybeDeserializeValue<T> = T extends {
|
|
63
|
+
deserialize: (...args: any[]) => unknown;
|
|
64
|
+
} ? ReturnType<T['deserialize']> : never;
|
|
65
|
+
export type TypeFromInstance<T> = T extends TransformHasType ? T[typeof TransformName] : never;
|
|
66
|
+
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;
|
|
67
|
+
/**
|
|
68
|
+
* The return type of `void` is a lie to appease TypeScript. The actual return type
|
|
69
|
+
* is a descriptor, but typescript incorrectly insists that decorator functions return
|
|
70
|
+
* `void` or `any`.
|
|
71
|
+
*
|
|
72
|
+
* @typedoc
|
|
73
|
+
*/
|
|
74
|
+
export type DataDecorator = (target: object, key: string, desc?: DecoratorPropertyDescriptor) => void;
|
|
75
|
+
/**
|
|
76
|
+
`attr` defines an attribute on a [Model](/ember-data/release/classes/Model).
|
|
77
|
+
By default, attributes are passed through as-is, however you can specify an
|
|
78
|
+
optional type to have the value automatically transformed.
|
|
79
|
+
EmberData ships with four basic transform types: `string`, `number`,
|
|
80
|
+
`boolean` and `date`. You can define your own transforms by subclassing
|
|
81
|
+
[Transform](/ember-data/release/classes/Transform).
|
|
82
|
+
|
|
83
|
+
Note that you cannot use `attr` to define an attribute of `id`.
|
|
84
|
+
|
|
85
|
+
`attr` takes an optional hash as a second parameter, currently
|
|
86
|
+
supported options are:
|
|
87
|
+
|
|
88
|
+
- `defaultValue`: Pass a string or a function to be called to set the attribute
|
|
89
|
+
to a default value if and only if the key is absent from the payload response.
|
|
90
|
+
|
|
91
|
+
Example
|
|
92
|
+
|
|
93
|
+
```app/models/user.js
|
|
94
|
+
import Model, { attr } from '@ember-data/model';
|
|
95
|
+
|
|
96
|
+
export default class UserModel extends Model {
|
|
97
|
+
@attr('string') username;
|
|
98
|
+
@attr('string') email;
|
|
99
|
+
@attr('boolean', { defaultValue: false }) verified;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Default value can also be a function. This is useful it you want to return
|
|
104
|
+
a new object for each attribute.
|
|
105
|
+
|
|
106
|
+
```app/models/user.js
|
|
107
|
+
import Model, { attr } from '@ember-data/model';
|
|
108
|
+
|
|
109
|
+
export default class UserModel extends Model {
|
|
110
|
+
@attr('string') username;
|
|
111
|
+
@attr('string') email;
|
|
112
|
+
|
|
113
|
+
@attr({
|
|
114
|
+
defaultValue() {
|
|
115
|
+
return {};
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
settings;
|
|
144
119
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The `options` hash is passed as second argument to a transforms'
|
|
123
|
+
`serialize` and `deserialize` method. This allows to configure a
|
|
124
|
+
transformation and adapt the corresponding value, based on the config:
|
|
125
|
+
|
|
126
|
+
```app/models/post.js
|
|
127
|
+
import Model, { attr } from '@ember-data/model';
|
|
128
|
+
|
|
129
|
+
export default class PostModel extends Model {
|
|
130
|
+
@attr('text', {
|
|
131
|
+
uppercase: true
|
|
132
|
+
})
|
|
133
|
+
text;
|
|
148
134
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
```app/transforms/text.js
|
|
138
|
+
export default class TextTransform {
|
|
139
|
+
serialize(value, options) {
|
|
140
|
+
if (options.uppercase) {
|
|
141
|
+
return value.toUpperCase();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
deserialize(value) {
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static create() {
|
|
152
|
+
return new this();
|
|
153
|
+
}
|
|
152
154
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
export declare function attr(): DataDecorator;
|
|
165
|
-
export declare function attr
|
|
166
|
-
export declare function attr(
|
|
167
|
-
export declare function attr(
|
|
168
|
-
export declare function attr
|
|
169
|
-
export declare function attr(
|
|
170
|
-
export
|
|
171
|
-
|
|
172
|
-
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
@method attr
|
|
158
|
+
@public
|
|
159
|
+
@static
|
|
160
|
+
@for @ember-data/model
|
|
161
|
+
@param {String|Object} type the attribute type
|
|
162
|
+
@param {Object} options a hash of options
|
|
163
|
+
@return {Attribute}
|
|
164
|
+
*/
|
|
165
|
+
export declare function attr(): DataDecorator;
|
|
166
|
+
export declare function attr<T>(type: TypeFromInstance<T>): DataDecorator;
|
|
167
|
+
export declare function attr(type: string): DataDecorator;
|
|
168
|
+
export declare function attr(options: AttrOptions): DataDecorator;
|
|
169
|
+
export declare function attr<T>(type: TypeFromInstance<T>, options?: OptionsFromInstance<T>): DataDecorator;
|
|
170
|
+
export declare function attr(type: string, options?: AttrOptions & object): DataDecorator;
|
|
171
|
+
export declare function attr(target: object, key: string | symbol, desc?: PropertyDescriptor): void;
|
|
172
|
+
export {};
|
|
173
|
+
//# sourceMappingURL=attr.d.ts.map
|
|
174
|
+
}
|