@warp-drive/legacy 5.6.0-alpha.14 → 5.6.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.
Files changed (191) hide show
  1. package/declarations/adapter/-private/build-url-mixin.d.ts +41 -29
  2. package/declarations/adapter/-private/fastboot-interface.d.ts +4 -5
  3. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +5 -6
  4. package/declarations/adapter/-private/utils/determine-body-promise.d.ts +1 -2
  5. package/declarations/adapter/-private/utils/fetch.d.ts +2 -3
  6. package/declarations/adapter/-private/utils/parse-response-headers.d.ts +0 -1
  7. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +5 -6
  8. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -2
  9. package/declarations/adapter/-private.d.ts +5 -6
  10. package/declarations/adapter/error.d.ts +206 -178
  11. package/declarations/adapter/json-api.d.ts +206 -207
  12. package/declarations/adapter/rest.d.ts +805 -808
  13. package/declarations/adapter.d.ts +742 -766
  14. package/declarations/compat/-private.d.ts +10 -11
  15. package/declarations/compat/builders/find-all.d.ts +26 -24
  16. package/declarations/compat/builders/find-record.d.ts +41 -39
  17. package/declarations/compat/builders/query.d.ts +50 -45
  18. package/declarations/compat/builders/save-record.d.ts +26 -24
  19. package/declarations/compat/builders/utils.d.ts +1 -2
  20. package/declarations/compat/builders.d.ts +10 -11
  21. package/declarations/compat/extensions.d.ts +59 -0
  22. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +39 -38
  23. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +1 -2
  24. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +9 -10
  25. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +1 -2
  26. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +1 -2
  27. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +521 -517
  28. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +214 -215
  29. package/declarations/compat/legacy-network-handler/serializer-response.d.ts +5 -6
  30. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +83 -84
  31. package/declarations/compat/legacy-network-handler/snapshot.d.ts +228 -229
  32. package/declarations/compat/utils.d.ts +118 -119
  33. package/declarations/compat.d.ts +106 -104
  34. package/declarations/model/-private/attr.d.ts +164 -145
  35. package/declarations/model/-private/belongs-to.d.ts +135 -122
  36. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +15 -4
  37. package/declarations/model/-private/errors.d.ts +272 -267
  38. package/declarations/model/-private/has-many.d.ts +119 -116
  39. package/declarations/model/-private/hooks.d.ts +5 -6
  40. package/declarations/model/-private/legacy-relationships-support.d.ts +51 -52
  41. package/declarations/model/-private/model-for-mixin.d.ts +18 -3
  42. package/declarations/model/-private/model-methods.d.ts +29 -24
  43. package/declarations/model/-private/model.d.ts +1306 -1254
  44. package/declarations/model/-private/notify-changes.d.ts +3 -4
  45. package/declarations/model/-private/promise-belongs-to.d.ts +33 -27
  46. package/declarations/model/-private/promise-many-array.d.ts +125 -116
  47. package/declarations/model/-private/record-state.d.ts +63 -60
  48. package/declarations/model/-private/references/belongs-to.d.ts +491 -487
  49. package/declarations/model/-private/references/has-many.d.ts +495 -492
  50. package/declarations/model/-private/schema-provider.d.ts +53 -56
  51. package/declarations/model/-private/type-utils.d.ts +41 -41
  52. package/declarations/model/-private/util.d.ts +1 -2
  53. package/declarations/model/-private.d.ts +8 -8
  54. package/declarations/model/migration-support.d.ts +281 -271
  55. package/declarations/model.d.ts +48 -49
  56. package/declarations/serializer/-private/embedded-records-mixin.d.ts +70 -71
  57. package/declarations/serializer/-private/transforms/boolean.d.ts +37 -37
  58. package/declarations/serializer/-private/transforms/date.d.ts +22 -22
  59. package/declarations/serializer/-private/transforms/number.d.ts +22 -22
  60. package/declarations/serializer/-private/transforms/string.d.ts +22 -22
  61. package/declarations/serializer/-private/transforms/transform.d.ts +109 -110
  62. package/declarations/serializer/-private/utils.d.ts +0 -1
  63. package/declarations/serializer/json-api.d.ts +124 -494
  64. package/declarations/serializer/json.d.ts +62 -1031
  65. package/declarations/serializer/rest.d.ts +52 -552
  66. package/declarations/serializer/transform.d.ts +5 -6
  67. package/declarations/serializer.d.ts +217 -218
  68. package/dist/{-private-DFfBszo5.js → -private-CKrP0ogQ.js} +1 -1
  69. package/dist/adapter/-private.js +1 -1
  70. package/dist/adapter/error.js +17 -0
  71. package/dist/adapter/json-api.js +1 -1
  72. package/dist/adapter/rest.js +5 -7
  73. package/dist/adapter.js +6 -35
  74. package/dist/compat/-private.js +1 -1
  75. package/dist/compat/extensions.js +243 -0
  76. package/dist/compat.js +3 -4
  77. package/dist/{errors-D74uk36r.js → errors-BX5wowuz.js} +12 -10
  78. package/dist/{json-DSOlH9A8.js → json-Et4mt_LM.js} +84 -157
  79. package/dist/model/-private.js +1 -1
  80. package/dist/model/migration-support.js +15 -4
  81. package/dist/model.js +3 -3
  82. package/dist/{schema-provider-CXFLTMjg.js → schema-provider-BdQhkT-Q.js} +20 -13
  83. package/dist/{serialize-into-hash-BxfqWC8u.js → serialize-into-hash-Bp58npke.js} +1 -1
  84. package/dist/serializer/json-api.js +42 -2
  85. package/dist/serializer/json.js +1 -1
  86. package/dist/serializer/rest.js +46 -41
  87. package/dist/serializer/transform.js +0 -44
  88. package/package.json +7 -7
  89. package/declarations/adapter/-private/build-url-mixin.d.ts.map +0 -1
  90. package/declarations/adapter/-private/fastboot-interface.d.ts.map +0 -1
  91. package/declarations/adapter/-private/utils/continue-on-reject.d.ts.map +0 -1
  92. package/declarations/adapter/-private/utils/determine-body-promise.d.ts.map +0 -1
  93. package/declarations/adapter/-private/utils/fetch.d.ts.map +0 -1
  94. package/declarations/adapter/-private/utils/parse-response-headers.d.ts.map +0 -1
  95. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts.map +0 -1
  96. package/declarations/adapter/-private/utils/serialize-query-params.d.ts.map +0 -1
  97. package/declarations/adapter/-private.d.ts.map +0 -1
  98. package/declarations/adapter/error.d.ts.map +0 -1
  99. package/declarations/adapter/json-api.d.ts.map +0 -1
  100. package/declarations/adapter/rest.d.ts.map +0 -1
  101. package/declarations/adapter.d.ts.map +0 -1
  102. package/declarations/compat/-private.d.ts.map +0 -1
  103. package/declarations/compat/builders/find-all.d.ts.map +0 -1
  104. package/declarations/compat/builders/find-record.d.ts.map +0 -1
  105. package/declarations/compat/builders/query.d.ts.map +0 -1
  106. package/declarations/compat/builders/save-record.d.ts.map +0 -1
  107. package/declarations/compat/builders/utils.d.ts.map +0 -1
  108. package/declarations/compat/builders.d.ts.map +0 -1
  109. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +0 -1
  110. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +0 -1
  111. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +0 -1
  112. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +0 -1
  113. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +0 -1
  114. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +0 -1
  115. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +0 -1
  116. package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +0 -1
  117. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +0 -1
  118. package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +0 -1
  119. package/declarations/compat/utils.d.ts.map +0 -1
  120. package/declarations/compat.d.ts.map +0 -1
  121. package/declarations/model/-private/attr.d.ts.map +0 -1
  122. package/declarations/model/-private/attr.type-test.d.ts +0 -2
  123. package/declarations/model/-private/attr.type-test.d.ts.map +0 -1
  124. package/declarations/model/-private/belongs-to.d.ts.map +0 -1
  125. package/declarations/model/-private/belongs-to.type-test.d.ts +0 -2
  126. package/declarations/model/-private/belongs-to.type-test.d.ts.map +0 -1
  127. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +0 -1
  128. package/declarations/model/-private/errors.d.ts.map +0 -1
  129. package/declarations/model/-private/has-many.d.ts.map +0 -1
  130. package/declarations/model/-private/has-many.type-test.d.ts +0 -2
  131. package/declarations/model/-private/has-many.type-test.d.ts.map +0 -1
  132. package/declarations/model/-private/hooks.d.ts.map +0 -1
  133. package/declarations/model/-private/legacy-relationships-support.d.ts.map +0 -1
  134. package/declarations/model/-private/model-for-mixin.d.ts.map +0 -1
  135. package/declarations/model/-private/model-methods.d.ts.map +0 -1
  136. package/declarations/model/-private/model.d.ts.map +0 -1
  137. package/declarations/model/-private/model.type-test.d.ts +0 -2
  138. package/declarations/model/-private/model.type-test.d.ts.map +0 -1
  139. package/declarations/model/-private/notify-changes.d.ts.map +0 -1
  140. package/declarations/model/-private/promise-belongs-to.d.ts.map +0 -1
  141. package/declarations/model/-private/promise-many-array.d.ts.map +0 -1
  142. package/declarations/model/-private/promise-proxy-base.d.ts +0 -3
  143. package/declarations/model/-private/promise-proxy-base.d.ts.map +0 -1
  144. package/declarations/model/-private/record-state.d.ts.map +0 -1
  145. package/declarations/model/-private/references/belongs-to.d.ts.map +0 -1
  146. package/declarations/model/-private/references/has-many.d.ts.map +0 -1
  147. package/declarations/model/-private/schema-provider.d.ts.map +0 -1
  148. package/declarations/model/-private/type-utils.d.ts.map +0 -1
  149. package/declarations/model/-private/util.d.ts.map +0 -1
  150. package/declarations/model/-private.d.ts.map +0 -1
  151. package/declarations/model/migration-support.d.ts.map +0 -1
  152. package/declarations/model/migration-support.type-test.d.ts +0 -2
  153. package/declarations/model/migration-support.type-test.d.ts.map +0 -1
  154. package/declarations/model.d.ts.map +0 -1
  155. package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +0 -1
  156. package/declarations/serializer/-private/transforms/boolean.d.ts.map +0 -1
  157. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +0 -2
  158. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +0 -1
  159. package/declarations/serializer/-private/transforms/date.d.ts.map +0 -1
  160. package/declarations/serializer/-private/transforms/number.d.ts.map +0 -1
  161. package/declarations/serializer/-private/transforms/string.d.ts.map +0 -1
  162. package/declarations/serializer/-private/transforms/transform.d.ts.map +0 -1
  163. package/declarations/serializer/-private/utils.d.ts.map +0 -1
  164. package/declarations/serializer/json-api.d.ts.map +0 -1
  165. package/declarations/serializer/json.d.ts.map +0 -1
  166. package/declarations/serializer/rest.d.ts.map +0 -1
  167. package/declarations/serializer/transform.d.ts.map +0 -1
  168. package/declarations/serializer.d.ts.map +0 -1
  169. package/dist/-private-DFfBszo5.js.map +0 -1
  170. package/dist/adapter/-private.js.map +0 -1
  171. package/dist/adapter/error.js.map +0 -1
  172. package/dist/adapter/json-api.js.map +0 -1
  173. package/dist/adapter/rest.js.map +0 -1
  174. package/dist/adapter.js.map +0 -1
  175. package/dist/compat/-private.js.map +0 -1
  176. package/dist/compat/builders.js.map +0 -1
  177. package/dist/compat/utils.js.map +0 -1
  178. package/dist/compat.js.map +0 -1
  179. package/dist/errors-D74uk36r.js.map +0 -1
  180. package/dist/json-DSOlH9A8.js.map +0 -1
  181. package/dist/model/-private.js.map +0 -1
  182. package/dist/model/migration-support.js.map +0 -1
  183. package/dist/model.js.map +0 -1
  184. package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +0 -1
  185. package/dist/schema-provider-CXFLTMjg.js.map +0 -1
  186. package/dist/serialize-into-hash-BxfqWC8u.js.map +0 -1
  187. package/dist/serializer/json-api.js.map +0 -1
  188. package/dist/serializer/json.js.map +0 -1
  189. package/dist/serializer/rest.js.map +0 -1
  190. package/dist/serializer/transform.js.map +0 -1
  191. package/dist/serializer.js.map +0 -1
@@ -1,158 +1,178 @@
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';
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.js";
4
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
- */
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
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;
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
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;
40
+ // NOTE: Usage of Explicit ANY
41
+ // -------------------------------------------------------------------
42
+ // any is required here because we are the maximal not the minimal
43
+ // subset of options allowed. If we used unknown, object, or
44
+ // Record<string, unknown> we would get type errors when we try to
45
+ // assert against a more specific implementation with precise options.
46
+ // -------------------------------------------------------------------
47
+ type LooseTransformInstance<
48
+ V,
49
+ Raw,
50
+ Name extends string
51
+ > = {
52
+ /**
53
+ * value type must match the return type of the deserialize method
54
+ *
55
+ */
56
+ // see note on Explicit ANY above
57
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
+ serialize: (value: V, options: any) => Raw;
59
+ /**
60
+ * defaultValue type must match the return type of the deserialize method
61
+ *
62
+ */
63
+ // see note on Explicit ANY above
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ deserialize: (value: Raw, options: any) => V;
66
+ [TransformName]: Name;
52
67
  };
53
68
  export type TransformHasType = {
54
- [TransformName]: string;
69
+ [TransformName]: string;
55
70
  };
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>;
71
+ export type TypedTransformInstance<
72
+ V,
73
+ T extends string
74
+ > = 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>;
75
+ // see note on Explicit ANY above
76
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
77
  export type GetMaybeDeserializeValue<T> = T extends {
58
- deserialize: (...args: any[]) => unknown;
59
- } ? ReturnType<T['deserialize']> : never;
78
+ deserialize: (...args: any[]) => unknown;
79
+ } ? ReturnType<T["deserialize"]> : never;
60
80
  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;
81
+ export type ExtractOptions<T extends TypedTransformInstance<GetMaybeDeserializeValue<T>, TypeFromInstance<T>>> = Parameters<T["deserialize"]>[1] & Parameters<T["serialize"]>[1] & AttrOptions<ReturnType<T["deserialize"]>>;
82
+ 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
83
  /**
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
- */
84
+ * The return type of `void` is a lie to appease TypeScript. The actual return type
85
+ * is a descriptor, but typescript incorrectly insists that decorator functions return
86
+ * `void` or `any`.
87
+ *
88
+ */
69
89
  export type DataDecorator = (target: object, key: string, desc?: DecoratorPropertyDescriptor) => void;
70
90
  /**
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}
91
+ `attr` defines an attribute on a [Model](/ember-data/release/classes/Model).
92
+ By default, attributes are passed through as-is, however you can specify an
93
+ optional type to have the value automatically transformed.
94
+ EmberData ships with four basic transform types: `string`, `number`,
95
+ `boolean` and `date`. You can define your own transforms by subclassing
96
+ [Transform](/ember-data/release/classes/Transform).
97
+
98
+ Note that you cannot use `attr` to define an attribute of `id`.
99
+
100
+ `attr` takes an optional hash as a second parameter, currently
101
+ supported options are:
102
+
103
+ - `defaultValue`: Pass a string or a function to be called to set the attribute
104
+ to a default value if and only if the key is absent from the payload response.
105
+
106
+ Example
107
+
108
+ ```js [app/models/user.js]
109
+ import { Model, attr } from '@warp-drive/legacy/model';
110
+
111
+ export default class UserModel extends Model {
112
+ @attr('string') username;
113
+ @attr('string') email;
114
+ @attr('boolean', { defaultValue: false }) verified;
115
+ }
116
+ ```
117
+
118
+ Default value can also be a function. This is useful it you want to return
119
+ a new object for each attribute.
120
+
121
+ ```js [app/models/user.js]
122
+ import { Model, attr } from '@warp-drive/legacy/model';
123
+
124
+ export default class UserModel extends Model {
125
+ @attr('string') username;
126
+ @attr('string') email;
127
+
128
+ @attr({
129
+ defaultValue() {
130
+ return {};
131
+ }
132
+ })
133
+ settings;
134
+ }
135
+ ```
136
+
137
+ The `options` hash is passed as second argument to a transforms'
138
+ `serialize` and `deserialize` method. This allows to configure a
139
+ transformation and adapt the corresponding value, based on the config:
140
+
141
+ ```js [app/models/post.js]
142
+ import { Model, attr } from '@warp-drive/legacy/model';
143
+
144
+ export default class PostModel extends Model {
145
+ @attr('text', {
146
+ uppercase: true
147
+ })
148
+ text;
149
+ }
150
+ ```
151
+
152
+ ```js [app/transforms/text.js]
153
+ export default class TextTransform {
154
+ serialize(value, options) {
155
+ if (options.uppercase) {
156
+ return value.toUpperCase();
157
+ }
158
+
159
+ return value;
160
+ }
161
+
162
+ deserialize(value) {
163
+ return value;
164
+ }
165
+
166
+ static create() {
167
+ return new this();
168
+ }
169
+ }
170
+ ```
171
+
172
+ @public
173
+ @param {String|Object} type the attribute type
174
+ @param {Object} options a hash of options
175
+ @return {Attribute}
156
176
  */
157
177
  export declare function attr(): DataDecorator;
158
178
  export declare function attr<T>(type: TypeFromInstance<T>): DataDecorator;
@@ -162,4 +182,3 @@ export declare function attr<T>(type: TypeFromInstance<T>, options?: OptionsFrom
162
182
  export declare function attr(type: string, options?: AttrOptions & object): DataDecorator;
163
183
  export declare function attr(target: object, key: string | symbol, desc?: PropertyDescriptor): void;
164
184
  export {};
165
- //# sourceMappingURL=attr.d.ts.map
@@ -1,173 +1,186 @@
1
- import type { TypeFromInstance } from '@warp-drive/core/types/record';
1
+ import type { TypeFromInstance } from "@warp-drive/core/types/record";
2
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;
3
+ export type RelationshipOptions<
4
+ T,
5
+ Async extends boolean
6
+ > = {
7
+ async: Async;
8
+ inverse: null | (IsUnknown<T> extends true ? string : keyof NoNull<T> & string);
9
+ polymorphic?: boolean;
10
+ as?: string;
11
+ linksMode?: true;
12
+ resetOnRemoteUpdate?: boolean;
10
13
  };
11
14
  export type NoNull<T> = Exclude<T, null>;
15
+ // type BelongsToDecoratorObject<getT> = {
16
+ // get: () => getT;
17
+ // // set: (value: Awaited<getT>) => void;
18
+ // set: (value: getT) => void;
19
+ // // init: () => getT;
20
+ // };
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
22
  export type RelationshipDecorator<T> = <This>(target: This, key: string, desc?: PropertyDescriptor) => void;
13
23
  /**
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).
24
+ `belongsTo` is used to define One-To-One and One-To-Many, and One-To-None
25
+ relationships on a [Model](/ember-data/release/classes/Model).
16
26
 
17
- `belongsTo` takes a configuration hash as a second parameter, currently
18
- supported options are:
27
+ `belongsTo` takes a configuration hash as a second parameter, currently
28
+ supported options are:
19
29
 
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.
30
+ - `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.
31
+ - `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.
32
+ - `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic
33
+ - `as`: (*optional*) A string used to declare the abstract type "this" record satisfies for polymorphism.
24
34
 
25
- ### Examples
35
+ ### Examples
26
36
 
27
- To declare a **one-to-many** (or many-to-many) relationship, use
28
- `belongsTo` in combination with `hasMany`:
37
+ To declare a **one-to-many** (or many-to-many) relationship, use
38
+ `belongsTo` in combination with `hasMany`:
29
39
 
30
- ```js
31
- // app/models/comment.js
32
- import { Model, belongsTo } from '@warp-drive/legacy/model';
40
+ ```js
41
+ // app/models/comment.js
42
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
33
43
 
34
- export default class Comment extends Model {
35
- @belongsTo('post', { async: false, inverse: 'comments' }) post;
36
- }
44
+ export default class Comment extends Model {
45
+ @belongsTo('post', { async: false, inverse: 'comments' }) post;
46
+ }
37
47
 
38
- // app/models/post.js
39
- import { Model, hasMany } from '@warp-drive/legacy/model';
48
+ // app/models/post.js
49
+ import { Model, hasMany } from '@warp-drive/legacy/model';
40
50
 
41
- export default class Post extends Model {
42
- @hasMany('comment', { async: false, inverse: 'post' }) comments;
43
- }
44
- ```
51
+ export default class Post extends Model {
52
+ @hasMany('comment', { async: false, inverse: 'post' }) comments;
53
+ }
54
+ ```
45
55
 
46
- To declare a **one-to-one** relationship with managed inverses, use `belongsTo` for both sides:
56
+ To declare a **one-to-one** relationship with managed inverses, use `belongsTo` for both sides:
47
57
 
48
- ```js
49
- // app/models/author.js
50
- import { Model, belongsTo } from '@warp-drive/legacy/model';
58
+ ```js
59
+ // app/models/author.js
60
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
51
61
 
52
- export default class Author extends Model {
53
- @belongsTo('address', { async: true, inverse: 'owner' }) address;
54
- }
62
+ export default class Author extends Model {
63
+ @belongsTo('address', { async: true, inverse: 'owner' }) address;
64
+ }
55
65
 
56
- // app/models/address.js
57
- import { Model, belongsTo } from '@warp-drive/legacy/model';
66
+ // app/models/address.js
67
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
58
68
 
59
- export default class Address extends Model {
60
- @belongsTo('author', { async: true, inverse: 'address' }) owner;
61
- }
62
- ```
69
+ export default class Address extends Model {
70
+ @belongsTo('author', { async: true, inverse: 'address' }) owner;
71
+ }
72
+ ```
63
73
 
64
- To declare a **one-to-one** relationship without managed inverses, use `belongsTo` for both sides
65
- with `null` as the inverse:
74
+ To declare a **one-to-one** relationship without managed inverses, use `belongsTo` for both sides
75
+ with `null` as the inverse:
66
76
 
67
- ```js
68
- // app/models/author.js
69
- import { Model, belongsTo } from '@warp-drive/legacy/model';
77
+ ```js
78
+ // app/models/author.js
79
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
70
80
 
71
- export default class Author extends Model {
72
- @belongsTo('address', { async: true, inverse: null }) address;
73
- }
81
+ export default class Author extends Model {
82
+ @belongsTo('address', { async: true, inverse: null }) address;
83
+ }
74
84
 
75
- // app/models/address.js
76
- import { Model, belongsTo } from '@warp-drive/legacy/model';
85
+ // app/models/address.js
86
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
77
87
 
78
- export default class Address extends Model {
79
- @belongsTo('author', { async: true, inverse: null }) owner;
80
- }
81
- ```
88
+ export default class Address extends Model {
89
+ @belongsTo('author', { async: true, inverse: null }) owner;
90
+ }
91
+ ```
82
92
 
83
- To declare a one-to-none relationship between two models, use
84
- `belongsTo` with inverse set to `null` on just one side::
93
+ To declare a one-to-none relationship between two models, use
94
+ `belongsTo` with inverse set to `null` on just one side::
85
95
 
86
- ```js
87
- // app/models/person.js
88
- import { Model, belongsTo } from '@warp-drive/legacy/model';
96
+ ```js
97
+ // app/models/person.js
98
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
89
99
 
90
- export default class Person extends Model {
91
- @belongsTo('person', { async: false, inverse: null }) bestFriend;
92
- }
93
- ```
100
+ export default class Person extends Model {
101
+ @belongsTo('person', { async: false, inverse: null }) bestFriend;
102
+ }
103
+ ```
94
104
 
95
- #### Sync vs Async Relationships
105
+ #### Sync vs Async Relationships
96
106
 
97
- EmberData fulfills relationships using resource data available in
98
- the cache.
107
+ EmberData fulfills relationships using resource data available in
108
+ the cache.
99
109
 
100
- Sync relationships point directly to the known related resources.
110
+ Sync relationships point directly to the known related resources.
101
111
 
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.
112
+ When a relationship is declared as async, if any of the known related
113
+ resources have not been loaded, they will be fetched. The property
114
+ on the record when accessed provides a promise that resolves once
115
+ all resources are loaded.
106
116
 
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.
117
+ Async relationships may take advantage of links. On access, if the related
118
+ link has not been loaded, or if any known resources are not available in
119
+ the cache, the fresh state will be fetched using the link.
110
120
 
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.
121
+ In contrast to async relationship, accessing a sync relationship
122
+ will error on access when any of the known related resources have
123
+ not been loaded.
114
124
 
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:
125
+ If you are using `links` with sync relationships, you have to use
126
+ the BelongsTo reference API to fetch or refresh related resources
127
+ that aren't loaded. For instance, for a `bestFriend` relationship:
118
128
 
119
- ```js
120
- person.belongsTo('bestFriend').reload();
121
- ```
129
+ ```js
130
+ person.belongsTo('bestFriend').reload();
131
+ ```
122
132
 
123
- #### Polymorphic Relationships
133
+ #### Polymorphic Relationships
124
134
 
125
- To declare a polymorphic relationship, use `hasMany` with the `polymorphic`
126
- option set to `true`:
135
+ To declare a polymorphic relationship, use `hasMany` with the `polymorphic`
136
+ option set to `true`:
127
137
 
128
- ```js
129
- // app/models/comment.js
130
- import { Model, belongsTo } from '@warp-drive/legacy/model';
138
+ ```js
139
+ // app/models/comment.js
140
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
131
141
 
132
- export default class Comment extends Model {
133
- @belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;
134
- }
135
- ```
142
+ export default class Comment extends Model {
143
+ @belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;
144
+ }
145
+ ```
136
146
 
137
- `'commentable'` here is referred to as the "abstract type" for the polymorphic
138
- relationship.
147
+ `'commentable'` here is referred to as the "abstract type" for the polymorphic
148
+ relationship.
139
149
 
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.
150
+ Polymorphic relationships with `inverse: null` will accept any type of record as their content.
151
+ Polymorphic relationships with `inverse` set to a string will only accept records with a matching
152
+ inverse relationships declaring itself as satisfying the abstract type.
143
153
 
144
- Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'
145
- for this relationship.
154
+ Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'
155
+ for this relationship.
146
156
 
147
- ```js
148
- // app/models/post.js
149
- import { Model, hasMany } from '@warp-drive/legacy/model';
157
+ ```js
158
+ // app/models/post.js
159
+ import { Model, hasMany } from '@warp-drive/legacy/model';
150
160
 
151
- export default class Post extends Model {
152
- @hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;
153
- }
154
- ```
161
+ export default class Post extends Model {
162
+ @hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;
163
+ }
164
+ ```
155
165
 
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.
166
+ Note: every Model that declares an inverse to a polymorphic relationship must
167
+ declare itself exactly the same. This is because polymorphism is based on structural
168
+ traits.
159
169
 
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.
170
+ Polymorphic to polymorphic relationships are supported. Both sides of the relationship
171
+ must be declared as polymorphic, and the `as` option must be used to declare the abstract
172
+ type each record satisfies on both sides.
163
173
 
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
174
+ @public
175
+ @param {String} type (optional) the name of the related resource
176
+ @param {Object} options (optional) a hash of options
177
+ @return {PropertyDescriptor} relationship
168
178
  */
169
179
  export declare function belongsTo(): never;
170
180
  export declare function belongsTo(type: string): never;
171
181
  export declare function belongsTo<T>(type: TypeFromInstance<NoNull<T>>, options: RelationshipOptions<T, boolean>): RelationshipDecorator<T>;
182
+ // export function belongsTo<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(
183
+ // type: TypeFromInstance<NoNull<T>>,
184
+ // options: RelationshipOptions<T, true>
185
+ // ): RelationshipDecorator<K>;
172
186
  export declare function belongsTo(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;
173
- //# sourceMappingURL=belongs-to.d.ts.map