@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.
- package/declarations/adapter/-private/build-url-mixin.d.ts +41 -29
- package/declarations/adapter/-private/fastboot-interface.d.ts +4 -5
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts +5 -6
- package/declarations/adapter/-private/utils/determine-body-promise.d.ts +1 -2
- package/declarations/adapter/-private/utils/fetch.d.ts +2 -3
- package/declarations/adapter/-private/utils/parse-response-headers.d.ts +0 -1
- package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +5 -6
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts +5 -2
- package/declarations/adapter/-private.d.ts +5 -6
- package/declarations/adapter/error.d.ts +206 -178
- package/declarations/adapter/json-api.d.ts +206 -207
- package/declarations/adapter/rest.d.ts +805 -808
- package/declarations/adapter.d.ts +742 -766
- package/declarations/compat/-private.d.ts +10 -11
- package/declarations/compat/builders/find-all.d.ts +26 -24
- package/declarations/compat/builders/find-record.d.ts +41 -39
- package/declarations/compat/builders/query.d.ts +50 -45
- package/declarations/compat/builders/save-record.d.ts +26 -24
- package/declarations/compat/builders/utils.d.ts +1 -2
- package/declarations/compat/builders.d.ts +10 -11
- package/declarations/compat/extensions.d.ts +52 -106
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +39 -38
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +1 -2
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +9 -10
- package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +1 -2
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +1 -2
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +521 -517
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +214 -215
- package/declarations/compat/legacy-network-handler/serializer-response.d.ts +5 -6
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +83 -84
- package/declarations/compat/legacy-network-handler/snapshot.d.ts +228 -229
- package/declarations/compat/utils.d.ts +118 -119
- package/declarations/compat.d.ts +106 -104
- package/declarations/model/-private/attr.d.ts +164 -145
- package/declarations/model/-private/belongs-to.d.ts +135 -122
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +15 -4
- package/declarations/model/-private/errors.d.ts +272 -267
- package/declarations/model/-private/has-many.d.ts +119 -116
- package/declarations/model/-private/hooks.d.ts +5 -6
- package/declarations/model/-private/legacy-relationships-support.d.ts +51 -52
- package/declarations/model/-private/model-for-mixin.d.ts +18 -3
- package/declarations/model/-private/model-methods.d.ts +29 -24
- package/declarations/model/-private/model.d.ts +1306 -1254
- package/declarations/model/-private/notify-changes.d.ts +3 -4
- package/declarations/model/-private/promise-belongs-to.d.ts +33 -27
- package/declarations/model/-private/promise-many-array.d.ts +125 -116
- package/declarations/model/-private/record-state.d.ts +63 -60
- package/declarations/model/-private/references/belongs-to.d.ts +491 -487
- package/declarations/model/-private/references/has-many.d.ts +495 -492
- package/declarations/model/-private/schema-provider.d.ts +53 -56
- package/declarations/model/-private/type-utils.d.ts +41 -41
- package/declarations/model/-private/util.d.ts +1 -2
- package/declarations/model/-private.d.ts +8 -8
- package/declarations/model/migration-support.d.ts +281 -279
- package/declarations/model.d.ts +48 -49
- package/declarations/serializer/-private/embedded-records-mixin.d.ts +70 -71
- package/declarations/serializer/-private/transforms/boolean.d.ts +37 -37
- package/declarations/serializer/-private/transforms/date.d.ts +22 -22
- package/declarations/serializer/-private/transforms/number.d.ts +22 -22
- package/declarations/serializer/-private/transforms/string.d.ts +22 -22
- package/declarations/serializer/-private/transforms/transform.d.ts +109 -110
- package/declarations/serializer/-private/utils.d.ts +0 -1
- package/declarations/serializer/json-api.d.ts +124 -494
- package/declarations/serializer/json.d.ts +62 -1031
- package/declarations/serializer/rest.d.ts +52 -552
- package/declarations/serializer/transform.d.ts +5 -6
- package/declarations/serializer.d.ts +217 -218
- package/dist/{-private-DFfBszo5.js → -private-CKrP0ogQ.js} +1 -1
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +17 -0
- package/dist/adapter/json-api.js +1 -1
- package/dist/adapter/rest.js +5 -7
- package/dist/adapter.js +6 -35
- package/dist/compat/-private.js +1 -1
- package/dist/compat/extensions.js +0 -2
- package/dist/compat.js +3 -4
- package/dist/{errors-_QQ7xpSn.js → errors-BX5wowuz.js} +11 -10
- package/dist/{json-DSOlH9A8.js → json-Et4mt_LM.js} +84 -157
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +3 -4
- package/dist/model.js +3 -3
- package/dist/{schema-provider-D_P8ReX6.js → schema-provider-BdQhkT-Q.js} +20 -13
- package/dist/{serialize-into-hash-BxfqWC8u.js → serialize-into-hash-Bp58npke.js} +1 -1
- package/dist/serializer/json-api.js +42 -2
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +46 -41
- package/dist/serializer/transform.js +0 -44
- package/package.json +7 -7
- package/declarations/adapter/-private/build-url-mixin.d.ts.map +0 -1
- package/declarations/adapter/-private/fastboot-interface.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/determine-body-promise.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/fetch.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/parse-response-headers.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/serialize-into-hash.d.ts.map +0 -1
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts.map +0 -1
- package/declarations/adapter/-private.d.ts.map +0 -1
- package/declarations/adapter/error.d.ts.map +0 -1
- package/declarations/adapter/json-api.d.ts.map +0 -1
- package/declarations/adapter/rest.d.ts.map +0 -1
- package/declarations/adapter.d.ts.map +0 -1
- package/declarations/compat/-private.d.ts.map +0 -1
- package/declarations/compat/builders/find-all.d.ts.map +0 -1
- package/declarations/compat/builders/find-record.d.ts.map +0 -1
- package/declarations/compat/builders/query.d.ts.map +0 -1
- package/declarations/compat/builders/save-record.d.ts.map +0 -1
- package/declarations/compat/builders/utils.d.ts.map +0 -1
- package/declarations/compat/builders.d.ts.map +0 -1
- package/declarations/compat/extensions.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +0 -1
- package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +0 -1
- package/declarations/compat/utils.d.ts.map +0 -1
- package/declarations/compat.d.ts.map +0 -1
- package/declarations/model/-private/attr.d.ts.map +0 -1
- package/declarations/model/-private/attr.type-test.d.ts +0 -2
- package/declarations/model/-private/attr.type-test.d.ts.map +0 -1
- package/declarations/model/-private/belongs-to.d.ts.map +0 -1
- package/declarations/model/-private/belongs-to.type-test.d.ts +0 -2
- package/declarations/model/-private/belongs-to.type-test.d.ts.map +0 -1
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +0 -1
- package/declarations/model/-private/errors.d.ts.map +0 -1
- package/declarations/model/-private/has-many.d.ts.map +0 -1
- package/declarations/model/-private/has-many.type-test.d.ts +0 -2
- package/declarations/model/-private/has-many.type-test.d.ts.map +0 -1
- package/declarations/model/-private/hooks.d.ts.map +0 -1
- package/declarations/model/-private/legacy-relationships-support.d.ts.map +0 -1
- package/declarations/model/-private/model-for-mixin.d.ts.map +0 -1
- package/declarations/model/-private/model-methods.d.ts.map +0 -1
- package/declarations/model/-private/model.d.ts.map +0 -1
- package/declarations/model/-private/model.type-test.d.ts +0 -2
- package/declarations/model/-private/model.type-test.d.ts.map +0 -1
- package/declarations/model/-private/notify-changes.d.ts.map +0 -1
- package/declarations/model/-private/promise-belongs-to.d.ts.map +0 -1
- package/declarations/model/-private/promise-many-array.d.ts.map +0 -1
- package/declarations/model/-private/promise-proxy-base.d.ts +0 -3
- package/declarations/model/-private/promise-proxy-base.d.ts.map +0 -1
- package/declarations/model/-private/record-state.d.ts.map +0 -1
- package/declarations/model/-private/references/belongs-to.d.ts.map +0 -1
- package/declarations/model/-private/references/has-many.d.ts.map +0 -1
- package/declarations/model/-private/schema-provider.d.ts.map +0 -1
- package/declarations/model/-private/type-utils.d.ts.map +0 -1
- package/declarations/model/-private/util.d.ts.map +0 -1
- package/declarations/model/-private.d.ts.map +0 -1
- package/declarations/model/migration-support.d.ts.map +0 -1
- package/declarations/model/migration-support.type-test.d.ts +0 -2
- package/declarations/model/migration-support.type-test.d.ts.map +0 -1
- package/declarations/model.d.ts.map +0 -1
- package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/boolean.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +0 -2
- package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/date.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/number.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/string.d.ts.map +0 -1
- package/declarations/serializer/-private/transforms/transform.d.ts.map +0 -1
- package/declarations/serializer/-private/utils.d.ts.map +0 -1
- package/declarations/serializer/json-api.d.ts.map +0 -1
- package/declarations/serializer/json.d.ts.map +0 -1
- package/declarations/serializer/rest.d.ts.map +0 -1
- package/declarations/serializer/transform.d.ts.map +0 -1
- package/declarations/serializer.d.ts.map +0 -1
- package/dist/-private-DFfBszo5.js.map +0 -1
- package/dist/adapter/-private.js.map +0 -1
- package/dist/adapter/error.js.map +0 -1
- package/dist/adapter/json-api.js.map +0 -1
- package/dist/adapter/rest.js.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/compat/-private.js.map +0 -1
- package/dist/compat/builders.js.map +0 -1
- package/dist/compat/extensions.js.map +0 -1
- package/dist/compat/utils.js.map +0 -1
- package/dist/compat.js.map +0 -1
- package/dist/errors-_QQ7xpSn.js.map +0 -1
- package/dist/json-DSOlH9A8.js.map +0 -1
- package/dist/model/-private.js.map +0 -1
- package/dist/model/migration-support.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +0 -1
- package/dist/schema-provider-D_P8ReX6.js.map +0 -1
- package/dist/serialize-into-hash-BxfqWC8u.js.map +0 -1
- package/dist/serializer/json-api.js.map +0 -1
- package/dist/serializer/json.js.map +0 -1
- package/dist/serializer/rest.js.map +0 -1
- package/dist/serializer/transform.js.map +0 -1
- package/dist/serializer.js.map +0 -1
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import type { Store } from
|
|
2
|
-
import type { UpgradedMeta } from
|
|
3
|
-
import type { StableRecordIdentifier } from
|
|
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
|
|
2
|
-
import ArrayProxy from
|
|
3
|
-
import type RecordState from
|
|
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
|
-
|
|
6
|
-
|
|
5
|
+
attribute: string;
|
|
6
|
+
message: string;
|
|
7
7
|
};
|
|
8
|
-
interface ArrayProxyWithCustomOverrides<T> extends Omit<ArrayProxy<T>,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
21
|
+
Holds validation errors for a given record, organized by attribute names.
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
This class is not directly instantiable.
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
29
|
+
For Example, if you had a `User` model that looked like this:
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
```js [app/models/user.js]
|
|
32
|
+
import { Model, attr } from '@warp-drive/legacy/model';
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
```javascript
|
|
42
|
+
let user = store.createRecord('user', {
|
|
43
|
+
username: 'tomster',
|
|
44
|
+
email: 'invalidEmail'
|
|
45
|
+
});
|
|
46
|
+
user.save();
|
|
47
|
+
```
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
56
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
75
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
```handlebars
|
|
84
|
+
{{#each @model.errors.messages as |message|}}
|
|
85
|
+
<div class="error">
|
|
86
|
+
{{message}}
|
|
87
|
+
</div>
|
|
88
|
+
{{/each}}
|
|
89
|
+
```
|
|
84
90
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
@class Errors
|
|
92
|
+
@public
|
|
93
|
+
*/
|
|
88
94
|
export declare class Errors extends ArrayProxyWithCustomOverrides<ValidationError> {
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|