@warp-drive/legacy 5.6.0-alpha.15 → 5.6.0-alpha.18

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 (193) 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 +52 -106
  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 -279
  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 +0 -2
  76. package/dist/compat.js +3 -4
  77. package/dist/{errors-_QQ7xpSn.js → errors-BX5wowuz.js} +11 -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 +3 -4
  81. package/dist/model.js +3 -3
  82. package/dist/{schema-provider-D_P8ReX6.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/extensions.d.ts.map +0 -1
  110. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +0 -1
  111. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +0 -1
  112. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +0 -1
  113. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +0 -1
  114. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +0 -1
  115. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +0 -1
  116. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +0 -1
  117. package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +0 -1
  118. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +0 -1
  119. package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +0 -1
  120. package/declarations/compat/utils.d.ts.map +0 -1
  121. package/declarations/compat.d.ts.map +0 -1
  122. package/declarations/model/-private/attr.d.ts.map +0 -1
  123. package/declarations/model/-private/attr.type-test.d.ts +0 -2
  124. package/declarations/model/-private/attr.type-test.d.ts.map +0 -1
  125. package/declarations/model/-private/belongs-to.d.ts.map +0 -1
  126. package/declarations/model/-private/belongs-to.type-test.d.ts +0 -2
  127. package/declarations/model/-private/belongs-to.type-test.d.ts.map +0 -1
  128. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +0 -1
  129. package/declarations/model/-private/errors.d.ts.map +0 -1
  130. package/declarations/model/-private/has-many.d.ts.map +0 -1
  131. package/declarations/model/-private/has-many.type-test.d.ts +0 -2
  132. package/declarations/model/-private/has-many.type-test.d.ts.map +0 -1
  133. package/declarations/model/-private/hooks.d.ts.map +0 -1
  134. package/declarations/model/-private/legacy-relationships-support.d.ts.map +0 -1
  135. package/declarations/model/-private/model-for-mixin.d.ts.map +0 -1
  136. package/declarations/model/-private/model-methods.d.ts.map +0 -1
  137. package/declarations/model/-private/model.d.ts.map +0 -1
  138. package/declarations/model/-private/model.type-test.d.ts +0 -2
  139. package/declarations/model/-private/model.type-test.d.ts.map +0 -1
  140. package/declarations/model/-private/notify-changes.d.ts.map +0 -1
  141. package/declarations/model/-private/promise-belongs-to.d.ts.map +0 -1
  142. package/declarations/model/-private/promise-many-array.d.ts.map +0 -1
  143. package/declarations/model/-private/promise-proxy-base.d.ts +0 -3
  144. package/declarations/model/-private/promise-proxy-base.d.ts.map +0 -1
  145. package/declarations/model/-private/record-state.d.ts.map +0 -1
  146. package/declarations/model/-private/references/belongs-to.d.ts.map +0 -1
  147. package/declarations/model/-private/references/has-many.d.ts.map +0 -1
  148. package/declarations/model/-private/schema-provider.d.ts.map +0 -1
  149. package/declarations/model/-private/type-utils.d.ts.map +0 -1
  150. package/declarations/model/-private/util.d.ts.map +0 -1
  151. package/declarations/model/-private.d.ts.map +0 -1
  152. package/declarations/model/migration-support.d.ts.map +0 -1
  153. package/declarations/model/migration-support.type-test.d.ts +0 -2
  154. package/declarations/model/migration-support.type-test.d.ts.map +0 -1
  155. package/declarations/model.d.ts.map +0 -1
  156. package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +0 -1
  157. package/declarations/serializer/-private/transforms/boolean.d.ts.map +0 -1
  158. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +0 -2
  159. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +0 -1
  160. package/declarations/serializer/-private/transforms/date.d.ts.map +0 -1
  161. package/declarations/serializer/-private/transforms/number.d.ts.map +0 -1
  162. package/declarations/serializer/-private/transforms/string.d.ts.map +0 -1
  163. package/declarations/serializer/-private/transforms/transform.d.ts.map +0 -1
  164. package/declarations/serializer/-private/utils.d.ts.map +0 -1
  165. package/declarations/serializer/json-api.d.ts.map +0 -1
  166. package/declarations/serializer/json.d.ts.map +0 -1
  167. package/declarations/serializer/rest.d.ts.map +0 -1
  168. package/declarations/serializer/transform.d.ts.map +0 -1
  169. package/declarations/serializer.d.ts.map +0 -1
  170. package/dist/-private-DFfBszo5.js.map +0 -1
  171. package/dist/adapter/-private.js.map +0 -1
  172. package/dist/adapter/error.js.map +0 -1
  173. package/dist/adapter/json-api.js.map +0 -1
  174. package/dist/adapter/rest.js.map +0 -1
  175. package/dist/adapter.js.map +0 -1
  176. package/dist/compat/-private.js.map +0 -1
  177. package/dist/compat/builders.js.map +0 -1
  178. package/dist/compat/extensions.js.map +0 -1
  179. package/dist/compat/utils.js.map +0 -1
  180. package/dist/compat.js.map +0 -1
  181. package/dist/errors-_QQ7xpSn.js.map +0 -1
  182. package/dist/json-DSOlH9A8.js.map +0 -1
  183. package/dist/model/-private.js.map +0 -1
  184. package/dist/model/migration-support.js.map +0 -1
  185. package/dist/model.js.map +0 -1
  186. package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +0 -1
  187. package/dist/schema-provider-D_P8ReX6.js.map +0 -1
  188. package/dist/serialize-into-hash-BxfqWC8u.js.map +0 -1
  189. package/dist/serializer/json-api.js.map +0 -1
  190. package/dist/serializer/json.js.map +0 -1
  191. package/dist/serializer/rest.js.map +0 -1
  192. package/dist/serializer/transform.js.map +0 -1
  193. package/dist/serializer.js.map +0 -1
@@ -1,6 +1,17 @@
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';
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
+ /*
5
+ Assert that `addedRecord` has a valid type so it can be added to the
6
+ relationship of the `record`.
7
+
8
+ The assert basically checks if the `addedRecord` can be added to the
9
+ relationship (specified via `relationshipMeta`) of the `record`.
10
+
11
+ This utility should only be used internally, as both record parameters must
12
+ be stable record identifiers and the `relationshipMeta` needs to be the meta
13
+ information about the relationship, retrieved via
14
+ `record.relationshipFor(key)`.
15
+ */
4
16
  declare let assertPolymorphicType: (parentIdentifier: StableRecordIdentifier, parentDefinition: UpgradedMeta, addedIdentifier: StableRecordIdentifier, store: Store) => void;
5
17
  export { assertPolymorphicType };
6
- //# sourceMappingURL=assert-polymorphic-type.d.ts.map
@@ -1,290 +1,295 @@
1
- import { type NativeArray } from '@ember/array';
2
- import ArrayProxy from '@ember/array/proxy';
3
- import type RecordState from './record-state.ts';
1
+ import { type NativeArray } from "@ember/array";
2
+ import ArrayProxy from "@ember/array/proxy";
3
+ import type RecordState from "./record-state.js";
4
4
  type ValidationError = {
5
- attribute: string;
6
- message: string;
5
+ attribute: string;
6
+ message: string;
7
7
  };
8
- interface ArrayProxyWithCustomOverrides<T> extends Omit<ArrayProxy<T>, 'clear' | 'content'> {
9
- content: NativeArray<T>;
10
- clear(): void;
11
- _has(name: string): boolean;
8
+ interface ArrayProxyWithCustomOverrides<T> extends Omit<ArrayProxy<T>, "clear" | "content"> {
9
+ // Omit causes `content` to be merged with the class def for ArrayProxy
10
+ // which then causes it to be seen as a property, disallowing defining it
11
+ // as an accessor. This restores our ability to define it as an accessor.
12
+ content: NativeArray<T>;
13
+ clear(): void;
14
+ _has(name: string): boolean;
12
15
  }
16
+ // we force the type here to our own construct because mixin and extend patterns
17
+ // lose generic signatures. We also do this because we need to Omit `clear` from
18
+ // the type of ArrayProxy as we override it's signature.
13
19
  declare const ArrayProxyWithCustomOverrides: new <T>() => ArrayProxyWithCustomOverrides<T>;
14
20
  /**
15
- Holds validation errors for a given record, organized by attribute names.
21
+ Holds validation errors for a given record, organized by attribute names.
16
22
 
17
- This class is not directly instantiable.
23
+ This class is not directly instantiable.
18
24
 
19
- Every `Model` has an `errors` property that is an instance of
20
- `Errors`. This can be used to display validation error
21
- messages returned from the server when a `record.save()` rejects.
25
+ Every `Model` has an `errors` property that is an instance of
26
+ `Errors`. This can be used to display validation error
27
+ messages returned from the server when a `record.save()` rejects.
22
28
 
23
- For Example, if you had a `User` model that looked like this:
29
+ For Example, if you had a `User` model that looked like this:
24
30
 
25
- ```js [app/models/user.js]
26
- import { Model, attr } from '@warp-drive/legacy/model';
31
+ ```js [app/models/user.js]
32
+ import { Model, attr } from '@warp-drive/legacy/model';
27
33
 
28
- export default class UserModel extends Model {
29
- @attr('string') username;
30
- @attr('string') email;
31
- }
32
- ```
33
- And you attempted to save a record that did not validate on the backend:
34
+ export default class UserModel extends Model {
35
+ @attr('string') username;
36
+ @attr('string') email;
37
+ }
38
+ ```
39
+ And you attempted to save a record that did not validate on the backend:
34
40
 
35
- ```javascript
36
- let user = store.createRecord('user', {
37
- username: 'tomster',
38
- email: 'invalidEmail'
39
- });
40
- user.save();
41
- ```
41
+ ```javascript
42
+ let user = store.createRecord('user', {
43
+ username: 'tomster',
44
+ email: 'invalidEmail'
45
+ });
46
+ user.save();
47
+ ```
42
48
 
43
- Your backend would be expected to return an error response that described
44
- the problem, so that error messages can be generated on the app.
49
+ Your backend would be expected to return an error response that described
50
+ the problem, so that error messages can be generated on the app.
45
51
 
46
- API responses will be translated into instances of `Errors` differently,
47
- depending on the specific combination of adapter and serializer used. You
48
- may want to check the documentation or the source code of the libraries
49
- that you are using, to know how they expect errors to be communicated.
52
+ API responses will be translated into instances of `Errors` differently,
53
+ depending on the specific combination of adapter and serializer used. You
54
+ may want to check the documentation or the source code of the libraries
55
+ that you are using, to know how they expect errors to be communicated.
50
56
 
51
- Errors can be displayed to the user by accessing their property name
52
- to get an array of all the error objects for that property. Each
53
- error object is a JavaScript object with two keys:
57
+ Errors can be displayed to the user by accessing their property name
58
+ to get an array of all the error objects for that property. Each
59
+ error object is a JavaScript object with two keys:
54
60
 
55
- - `message` A string containing the error message from the backend
56
- - `attribute` The name of the property associated with this error message
61
+ - `message` A string containing the error message from the backend
62
+ - `attribute` The name of the property associated with this error message
57
63
 
58
- ```handlebars
59
- <label>Username: <Input @value={{@model.username}} /> </label>
60
- {{#each @model.errors.username as |error|}}
61
- <div class="error">
62
- {{error.message}}
63
- </div>
64
- {{/each}}
64
+ ```handlebars
65
+ <label>Username: <Input @value={{@model.username}} /> </label>
66
+ {{#each @model.errors.username as |error|}}
67
+ <div class="error">
68
+ {{error.message}}
69
+ </div>
70
+ {{/each}}
65
71
 
66
- <label>Email: <Input @value={{@model.email}} /> </label>
67
- {{#each @model.errors.email as |error|}}
68
- <div class="error">
69
- {{error.message}}
70
- </div>
71
- {{/each}}
72
- ```
72
+ <label>Email: <Input @value={{@model.email}} /> </label>
73
+ {{#each @model.errors.email as |error|}}
74
+ <div class="error">
75
+ {{error.message}}
76
+ </div>
77
+ {{/each}}
78
+ ```
73
79
 
74
- You can also access the special `messages` property on the error
75
- object to get an array of all the error strings.
80
+ You can also access the special `messages` property on the error
81
+ object to get an array of all the error strings.
76
82
 
77
- ```handlebars
78
- {{#each @model.errors.messages as |message|}}
79
- <div class="error">
80
- {{message}}
81
- </div>
82
- {{/each}}
83
- ```
83
+ ```handlebars
84
+ {{#each @model.errors.messages as |message|}}
85
+ <div class="error">
86
+ {{message}}
87
+ </div>
88
+ {{/each}}
89
+ ```
84
90
 
85
- @class Errors
86
- @public
87
- */
91
+ @class Errors
92
+ @public
93
+ */
88
94
  export declare class Errors extends ArrayProxyWithCustomOverrides<ValidationError> {
89
- __record: {
90
- currentState: RecordState;
91
- };
92
- /**
93
- @property errorsByAttributeName
94
- @type {MapWithDefault}
95
- @private
96
- */
97
- get errorsByAttributeName(): Map<string, NativeArray<ValidationError>>;
98
- /**
99
- Returns errors for a given attribute
100
-
101
- ```javascript
102
- let user = store.createRecord('user', {
103
- username: 'tomster',
104
- email: 'invalidEmail'
105
- });
106
- user.save().catch(function(){
107
- user.errors.errorsFor('email'); // returns:
108
- // [{attribute: "email", message: "Doesn't look like a valid email."}]
109
- });
110
- ```
111
-
112
- @public
113
- @param {String} attribute
114
- @return {Array}
115
- */
116
- errorsFor(attribute: string): NativeArray<ValidationError>;
117
- /**
118
- An array containing all of the error messages for this
119
- record. This is useful for displaying all errors to the user.
120
-
121
- ```handlebars
122
- {{#each @model.errors.messages as |message|}}
123
- <div class="error">
124
- {{message}}
125
- </div>
126
- {{/each}}
127
- ```
128
-
129
- @property messages
130
- @public
131
- @type {Array}
132
- */
133
- messages: string[];
134
- /**
135
- @property content
136
- @type {Array}
137
- @private
138
- */
139
- get content(): NativeArray<ValidationError>;
140
- /**
141
- @private
142
- */
143
- unknownProperty(attribute: string): NativeArray<ValidationError> | undefined;
144
- /**
145
- Total number of errors.
146
-
147
- @property length
148
- @type {Number}
149
- @public
150
- @readonly
151
- */
152
- /**
153
- `true` if we have no errors.
154
-
155
- @property isEmpty
156
- @type {Boolean}
157
- @public
158
- @readonly
159
- */
160
- isEmpty: boolean;
161
- /**
162
- Manually adds errors to the record. This will trigger the `becameInvalid` event/ lifecycle method on
163
- the record and transition the record into an `invalid` state.
164
-
165
- Example
166
- ```javascript
167
- let errors = user.errors;
168
-
169
- // add multiple errors
170
- errors.add('password', [
171
- 'Must be at least 12 characters',
172
- 'Must contain at least one symbol',
173
- 'Cannot contain your name'
174
- ]);
175
-
176
- errors.errorsFor('password');
177
- // =>
178
- // [
179
- // { attribute: 'password', message: 'Must be at least 12 characters' },
180
- // { attribute: 'password', message: 'Must contain at least one symbol' },
181
- // { attribute: 'password', message: 'Cannot contain your name' },
182
- // ]
183
-
184
- // add a single error
185
- errors.add('username', 'This field is required');
186
-
187
- errors.errorsFor('username');
188
- // =>
189
- // [
190
- // { attribute: 'username', message: 'This field is required' },
191
- // ]
192
- ```
193
- @public
194
- @param {String} attribute - the property name of an attribute or relationship
195
- @param {string[]|string} messages - an error message or array of error messages for the attribute
196
- */
197
- add(attribute: string, messages: string[] | string): void;
198
- /**
199
- @private
200
- */
201
- _findOrCreateMessages(attribute: string, messages: string | string[]): ValidationError[];
202
- /**
203
- Manually removes all errors for a given member from the record.
204
- This will transition the record into a `valid` state, and
205
- triggers the `becameValid` event and lifecycle method.
206
-
207
- Example:
208
-
209
- ```javascript
210
- let errors = user.errors;
211
- errors.add('phone', ['error-1', 'error-2']);
212
-
213
- errors.errorsFor('phone');
214
- // =>
215
- // [
216
- // { attribute: 'phone', message: 'error-1' },
217
- // { attribute: 'phone', message: 'error-2' },
218
- // ]
219
-
220
- errors.remove('phone');
221
-
222
- errors.errorsFor('phone');
223
- // => undefined
224
- ```
225
- @public
226
- @param {String} member - the property name of an attribute or relationship
227
- */
228
- remove(attribute: string): void;
229
- /**
230
- Manually clears all errors for the record.
231
- This will transition the record into a `valid` state, and
232
- will trigger the `becameValid` event and lifecycle method.
233
-
234
- Example:
235
-
236
- ```javascript
237
- let errors = user.errors;
238
- errors.add('username', ['error-a']);
239
- errors.add('phone', ['error-1', 'error-2']);
240
-
241
- errors.errorsFor('username');
242
- // =>
243
- // [
244
- // { attribute: 'username', message: 'error-a' },
245
- // ]
246
-
247
- errors.errorsFor('phone');
248
- // =>
249
- // [
250
- // { attribute: 'phone', message: 'error-1' },
251
- // { attribute: 'phone', message: 'error-2' },
252
- // ]
253
-
254
- errors.clear();
255
-
256
- errors.errorsFor('username');
257
- // => undefined
258
-
259
- errors.errorsFor('phone');
260
- // => undefined
261
-
262
- errors.messages
263
- // => []
264
- ```
265
- @public
266
- */
267
- clear(): void;
268
- /**
269
- Checks if there are error messages for the given attribute.
270
-
271
- ```js [app/controllers/user/edit.js]
272
- export default class UserEditController extends Controller {
273
- @action
274
- save(user) {
275
- if (user.errors.has('email')) {
276
- return alert('Please update your email before attempting to save.');
277
- }
278
- user.save();
279
- }
280
- }
281
- ```
282
-
283
- @public
284
- @param {String} attribute
285
- @return {Boolean} true if there some errors on given attribute
286
- */
287
- has(attribute: string): boolean;
95
+ __record: {
96
+ currentState: RecordState;
97
+ };
98
+ /**
99
+ @property errorsByAttributeName
100
+ @type {MapWithDefault}
101
+ @private
102
+ */
103
+ get errorsByAttributeName(): Map<string, NativeArray<ValidationError>>;
104
+ /**
105
+ Returns errors for a given attribute
106
+
107
+ ```javascript
108
+ let user = store.createRecord('user', {
109
+ username: 'tomster',
110
+ email: 'invalidEmail'
111
+ });
112
+ user.save().catch(function(){
113
+ user.errors.errorsFor('email'); // returns:
114
+ // [{attribute: "email", message: "Doesn't look like a valid email."}]
115
+ });
116
+ ```
117
+
118
+ @public
119
+ @param {String} attribute
120
+ @return {Array}
121
+ */
122
+ errorsFor(attribute: string): NativeArray<ValidationError>;
123
+ /**
124
+ An array containing all of the error messages for this
125
+ record. This is useful for displaying all errors to the user.
126
+
127
+ ```handlebars
128
+ {{#each @model.errors.messages as |message|}}
129
+ <div class="error">
130
+ {{message}}
131
+ </div>
132
+ {{/each}}
133
+ ```
134
+
135
+ @property messages
136
+ @public
137
+ @type {Array}
138
+ */
139
+ messages: string[];
140
+ /**
141
+ @property content
142
+ @type {Array}
143
+ @private
144
+ */
145
+ get content(): NativeArray<ValidationError>;
146
+ /**
147
+ @private
148
+ */
149
+ unknownProperty(attribute: string): NativeArray<ValidationError> | undefined;
150
+ /**
151
+ Total number of errors.
152
+
153
+ @property length
154
+ @type {Number}
155
+ @public
156
+ @readonly
157
+ */
158
+ /**
159
+ `true` if we have no errors.
160
+
161
+ @property isEmpty
162
+ @type {Boolean}
163
+ @public
164
+ @readonly
165
+ */
166
+ isEmpty: boolean;
167
+ /**
168
+ Manually adds errors to the record. This will trigger the `becameInvalid` event/ lifecycle method on
169
+ the record and transition the record into an `invalid` state.
170
+
171
+ Example
172
+ ```javascript
173
+ let errors = user.errors;
174
+
175
+ // add multiple errors
176
+ errors.add('password', [
177
+ 'Must be at least 12 characters',
178
+ 'Must contain at least one symbol',
179
+ 'Cannot contain your name'
180
+ ]);
181
+
182
+ errors.errorsFor('password');
183
+ // =>
184
+ // [
185
+ // { attribute: 'password', message: 'Must be at least 12 characters' },
186
+ // { attribute: 'password', message: 'Must contain at least one symbol' },
187
+ // { attribute: 'password', message: 'Cannot contain your name' },
188
+ // ]
189
+
190
+ // add a single error
191
+ errors.add('username', 'This field is required');
192
+
193
+ errors.errorsFor('username');
194
+ // =>
195
+ // [
196
+ // { attribute: 'username', message: 'This field is required' },
197
+ // ]
198
+ ```
199
+ @public
200
+ @param {String} attribute - the property name of an attribute or relationship
201
+ @param {string[]|string} messages - an error message or array of error messages for the attribute
202
+ */
203
+ add(attribute: string, messages: string[] | string): void;
204
+ /**
205
+ @private
206
+ */
207
+ _findOrCreateMessages(attribute: string, messages: string | string[]): ValidationError[];
208
+ /**
209
+ Manually removes all errors for a given member from the record.
210
+ This will transition the record into a `valid` state, and
211
+ triggers the `becameValid` event and lifecycle method.
212
+
213
+ Example:
214
+
215
+ ```javascript
216
+ let errors = user.errors;
217
+ errors.add('phone', ['error-1', 'error-2']);
218
+
219
+ errors.errorsFor('phone');
220
+ // =>
221
+ // [
222
+ // { attribute: 'phone', message: 'error-1' },
223
+ // { attribute: 'phone', message: 'error-2' },
224
+ // ]
225
+
226
+ errors.remove('phone');
227
+
228
+ errors.errorsFor('phone');
229
+ // => undefined
230
+ ```
231
+ @public
232
+ @param {String} member - the property name of an attribute or relationship
233
+ */
234
+ remove(attribute: string): void;
235
+ /**
236
+ Manually clears all errors for the record.
237
+ This will transition the record into a `valid` state, and
238
+ will trigger the `becameValid` event and lifecycle method.
239
+
240
+ Example:
241
+
242
+ ```javascript
243
+ let errors = user.errors;
244
+ errors.add('username', ['error-a']);
245
+ errors.add('phone', ['error-1', 'error-2']);
246
+
247
+ errors.errorsFor('username');
248
+ // =>
249
+ // [
250
+ // { attribute: 'username', message: 'error-a' },
251
+ // ]
252
+
253
+ errors.errorsFor('phone');
254
+ // =>
255
+ // [
256
+ // { attribute: 'phone', message: 'error-1' },
257
+ // { attribute: 'phone', message: 'error-2' },
258
+ // ]
259
+
260
+ errors.clear();
261
+
262
+ errors.errorsFor('username');
263
+ // => undefined
264
+
265
+ errors.errorsFor('phone');
266
+ // => undefined
267
+
268
+ errors.messages
269
+ // => []
270
+ ```
271
+ @public
272
+ */
273
+ clear(): void;
274
+ /**
275
+ Checks if there are error messages for the given attribute.
276
+
277
+ ```js [app/controllers/user/edit.js]
278
+ export default class UserEditController extends Controller {
279
+ @action
280
+ save(user) {
281
+ if (user.errors.has('email')) {
282
+ return alert('Please update your email before attempting to save.');
283
+ }
284
+ user.save();
285
+ }
286
+ }
287
+ ```
288
+
289
+ @public
290
+ @param {String} attribute
291
+ @return {Boolean} true if there some errors on given attribute
292
+ */
293
+ has(attribute: string): boolean;
288
294
  }
289
295
  export {};
290
- //# sourceMappingURL=errors.d.ts.map