@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.
Files changed (29) hide show
  1. package/package.json +19 -19
  2. package/unstable-preview-types/-private/attr.d.ts +171 -169
  3. package/unstable-preview-types/-private/attr.type-test.d.ts +4 -2
  4. package/unstable-preview-types/-private/belongs-to.d.ts +181 -179
  5. package/unstable-preview-types/-private/belongs-to.type-test.d.ts +4 -2
  6. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +8 -6
  7. package/unstable-preview-types/-private/errors.d.ts +290 -288
  8. package/unstable-preview-types/-private/has-many.d.ts +170 -168
  9. package/unstable-preview-types/-private/has-many.type-test.d.ts +4 -2
  10. package/unstable-preview-types/-private/hooks.d.ts +13 -11
  11. package/unstable-preview-types/-private/legacy-relationships-support.d.ts +62 -60
  12. package/unstable-preview-types/-private/many-array.d.ts +193 -191
  13. package/unstable-preview-types/-private/model-for-mixin.d.ts +6 -4
  14. package/unstable-preview-types/-private/model-methods.d.ts +34 -32
  15. package/unstable-preview-types/-private/model.d.ts +103 -100
  16. package/unstable-preview-types/-private/model.type-test.d.ts +4 -2
  17. package/unstable-preview-types/-private/notify-changes.d.ts +8 -6
  18. package/unstable-preview-types/-private/promise-belongs-to.d.ts +47 -45
  19. package/unstable-preview-types/-private/promise-many-array.d.ts +129 -127
  20. package/unstable-preview-types/-private/promise-proxy-base.d.ts +35 -32
  21. package/unstable-preview-types/-private/record-state.d.ts +88 -86
  22. package/unstable-preview-types/-private/references/belongs-to.d.ts +473 -471
  23. package/unstable-preview-types/-private/references/has-many.d.ts +488 -486
  24. package/unstable-preview-types/-private/schema-provider.d.ts +27 -25
  25. package/unstable-preview-types/-private/util.d.ts +11 -9
  26. package/unstable-preview-types/-private.d.ts +12 -10
  27. package/unstable-preview-types/hooks.d.ts +5 -3
  28. package/unstable-preview-types/index.d.ts +75 -46
  29. 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.32",
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.32",
33
- "@ember-data/graph": "5.4.0-alpha.32",
34
- "@ember-data/json-api": "5.4.0-alpha.32",
35
- "@ember-data/legacy-compat": "5.4.0-alpha.32",
36
- "@ember-data/store": "5.4.0-alpha.32",
37
- "@ember-data/tracking": "5.4.0-alpha.32",
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.18",
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.32",
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.32",
113
- "@ember-data/graph": "5.4.0-alpha.32",
114
- "@ember-data/json-api": "5.4.0-alpha.32",
115
- "@ember-data/legacy-compat": "5.4.0-alpha.32",
116
- "@ember-data/request": "5.4.0-alpha.32",
117
- "@ember-data/request-utils": "5.4.0-alpha.32",
118
- "@ember-data/store": "5.4.0-alpha.32",
119
- "@ember-data/tracking": "5.4.0-alpha.32",
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.18",
126
- "@warp-drive/internal-config": "5.4.0-alpha.32",
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
- 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';
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
- * @typedoc
27
- */
28
- export type AttrOptions<DV = PrimitiveValue | object | unknown[]> = {
29
- /**
30
- * The default value for this attribute.
31
- *
32
- * Default values can be provided as a value or a function that will be
33
- * executed to generate the default value.
34
- *
35
- * Default values *should not* be stateful (object, arrays, etc.) as
36
- * they will be shared across all instances of the record.
37
- *
38
- * @typedoc
39
- */
40
- defaultValue?: DV extends PrimitiveValue ? DV : () => DV;
41
- };
42
- type LooseTransformInstance<V, Raw, Name extends string> = {
43
- /**
44
- * value type must match the return type of the deserialize method
45
- *
46
- * @typedoc
47
- */
48
- serialize: (value: V, options: any) => Raw;
49
- /**
50
- * defaultValue type must match the return type of the deserialize method
51
- *
52
- * @typedoc
53
- */
54
- deserialize: (value: Raw, options: any) => V;
55
- [TransformName]: Name;
56
- };
57
- export type TransformHasType = {
58
- [TransformName]: string;
59
- };
60
- 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>;
61
- export type GetMaybeDeserializeValue<T> = T extends {
62
- deserialize: (...args: any[]) => unknown;
63
- } ? ReturnType<T['deserialize']> : never;
64
- export type TypeFromInstance<T> = T extends TransformHasType ? T[typeof TransformName] : never;
65
- 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;
66
- /**
67
- * The return type of `void` is a lie to appease TypeScript. The actual return type
68
- * is a descriptor, but typescript incorrectly insists that decorator functions return
69
- * `void` or `any`.
70
- *
71
- * @typedoc
72
- */
73
- export type DataDecorator = (target: object, key: string, desc?: DecoratorPropertyDescriptor) => void;
74
- /**
75
- `attr` defines an attribute on a [Model](/ember-data/release/classes/Model).
76
- By default, attributes are passed through as-is, however you can specify an
77
- optional type to have the value automatically transformed.
78
- EmberData ships with four basic transform types: `string`, `number`,
79
- `boolean` and `date`. You can define your own transforms by subclassing
80
- [Transform](/ember-data/release/classes/Transform).
81
-
82
- Note that you cannot use `attr` to define an attribute of `id`.
83
-
84
- `attr` takes an optional hash as a second parameter, currently
85
- supported options are:
86
-
87
- - `defaultValue`: Pass a string or a function to be called to set the attribute
88
- to a default value if and only if the key is absent from the payload response.
89
-
90
- Example
91
-
92
- ```app/models/user.js
93
- import Model, { attr } from '@ember-data/model';
94
-
95
- export default class UserModel extends Model {
96
- @attr('string') username;
97
- @attr('string') email;
98
- @attr('boolean', { defaultValue: false }) verified;
99
- }
100
- ```
101
-
102
- Default value can also be a function. This is useful it you want to return
103
- a new object for each attribute.
104
-
105
- ```app/models/user.js
106
- import Model, { attr } from '@ember-data/model';
107
-
108
- export default class UserModel extends Model {
109
- @attr('string') username;
110
- @attr('string') email;
111
-
112
- @attr({
113
- defaultValue() {
114
- return {};
115
- }
116
- })
117
- settings;
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
- deserialize(value) {
147
- return value;
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
- static create() {
151
- return new this();
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
- @method attr
157
- @public
158
- @static
159
- @for @ember-data/model
160
- @param {String|Object} type the attribute type
161
- @param {Object} options a hash of options
162
- @return {Attribute}
163
- */
164
- export declare function attr(): DataDecorator;
165
- export declare function attr<T>(type: TypeFromInstance<T>): DataDecorator;
166
- export declare function attr(type: string): DataDecorator;
167
- export declare function attr(options: AttrOptions): DataDecorator;
168
- export declare function attr<T>(type: TypeFromInstance<T>, options?: OptionsFromInstance<T>): DataDecorator;
169
- export declare function attr(type: string, options?: AttrOptions & object): DataDecorator;
170
- export declare function attr(target: object, key: string | symbol, desc?: PropertyDescriptor): void;
171
- export {};
172
- //# sourceMappingURL=attr.d.ts.map
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
+ }
@@ -1,2 +1,4 @@
1
- export {};
2
- //# sourceMappingURL=attr.type-test.d.ts.map
1
+ declare module '@ember-data/model/-private/attr.type-test' {
2
+ export {};
3
+ //# sourceMappingURL=attr.type-test.d.ts.map
4
+ }