@projectcaluma/ember-core 10.1.0 → 11.0.0-beta.24

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.
@@ -1,66 +0,0 @@
1
- import { assert } from "@ember/debug";
2
- import Service from "@ember/service";
3
- import { isEmpty } from "@ember/utils";
4
- import { queryManager } from "ember-apollo-client";
5
- import { enqueueTask } from "ember-concurrency-decorators";
6
-
7
- import allFormatValidatorsQuery from "@projectcaluma/ember-core/gql/queries/all-format-validators.graphql";
8
-
9
- export default class ValidatorService extends Service {
10
- @queryManager() apollo;
11
-
12
- /**
13
- * Tests a value against one or multiple regular expressions.
14
- *
15
- * ```js
16
- * await this.validator.validate("foo@example.com", ["email", "lowercase"]);
17
- * ```
18
- *
19
- * @param {String} value The value to be tested.
20
- * @param {String[]} slugs A list of tests (via slug) to run.
21
- * @return {RSVP.Promise}
22
- */
23
- async validate(value, slugs) {
24
- if (isEmpty(value)) {
25
- // empty values should not be validated since they are handled by the
26
- // requiredness validation
27
- return slugs.map(() => true);
28
- }
29
-
30
- const validators =
31
- this.validators.lastSuccessful?.value ||
32
- (await this.validators.last)?.value ||
33
- (await this.validators.perform());
34
-
35
- return slugs.map((slug) => {
36
- const validator = validators.find((validator) => validator.slug === slug);
37
-
38
- assert(`No validator found with the slug "${slug}".`, validator);
39
-
40
- return (
41
- validator.regex.test(value) || {
42
- type: "format",
43
- message: undefined,
44
- context: { errorMsg: validator.errorMsg },
45
- value,
46
- }
47
- );
48
- });
49
- }
50
-
51
- @enqueueTask
52
- *validators() {
53
- const raw = yield this.apollo.watchQuery(
54
- { query: allFormatValidatorsQuery },
55
- "allFormatValidators.edges"
56
- );
57
-
58
- return raw.map((rawValidator) => {
59
- return {
60
- slug: rawValidator.node.slug,
61
- regex: new RegExp(rawValidator.node.regex),
62
- errorMsg: rawValidator.node.errorMsg,
63
- };
64
- });
65
- }
66
- }
@@ -1,47 +0,0 @@
1
- import { typeOf } from "@ember/utils";
2
- import { isPromise } from "validated-changeset";
3
-
4
- function notTrue(value) {
5
- return typeOf(value) !== "boolean" || !value;
6
- }
7
-
8
- function handleResult(result) {
9
- if (notTrue(result)) throw result;
10
- return true;
11
- }
12
-
13
- /**
14
- * Accepts an array of ember-changeset-validations validation functions.
15
- *
16
- * Copied and updated from nucleartide/ember-changeset-hofs
17
- * @module and
18
- */
19
- export default function and(...validators) {
20
- return (key, newValue, oldValue, changes, object) => {
21
- for (let i = 0; i < validators.length; i++) {
22
- const validation = validators[i](
23
- key,
24
- newValue,
25
- oldValue,
26
- changes,
27
- object
28
- );
29
-
30
- if (isPromise(validation)) {
31
- let promise = validation.then(handleResult);
32
-
33
- for (let j = i + 1; j < validators.length; j++) {
34
- promise = promise
35
- .then(() => validators[j](key, newValue, oldValue, changes, object))
36
- .then(handleResult);
37
- }
38
-
39
- return promise.catch((err) => err);
40
- }
41
-
42
- if (notTrue(validation)) return validation;
43
- }
44
-
45
- return true;
46
- };
47
- }
package/addon/utils/or.js DELETED
@@ -1,40 +0,0 @@
1
- import { isPromise } from "validated-changeset";
2
-
3
- function isTrue(value) {
4
- return value === true;
5
- }
6
-
7
- function handleResult(result) {
8
- if (isTrue(result)) throw true;
9
- return result;
10
- }
11
-
12
- /**
13
- * Copied and updated from nucleartide/ember-changeset-hofs
14
- * @module or
15
- */
16
- export default function or(...validators) {
17
- return (key, newValue, oldValue, changes, object) => {
18
- let validation;
19
-
20
- for (let i = 0; i < validators.length; i++) {
21
- validation = validators[i](key, newValue, oldValue, changes, object);
22
-
23
- if (isPromise(validation)) {
24
- let promise = validation.then(handleResult);
25
-
26
- for (let j = i + 1; j < validators.length; j++) {
27
- promise = promise
28
- .then(() => validators[j](key, newValue, oldValue, changes, object))
29
- .then(handleResult);
30
- }
31
-
32
- return promise.catch((err) => err);
33
- }
34
-
35
- if (isTrue(validation)) return true;
36
- }
37
-
38
- return validation;
39
- };
40
- }
@@ -1,4 +0,0 @@
1
- export {
2
- default,
3
- getWidget,
4
- } from "@projectcaluma/ember-core/helpers/get-widget";
@@ -1 +0,0 @@
1
- export { default } from "@projectcaluma/ember-core/services/validator";
package/app/utils/and.js DELETED
@@ -1 +0,0 @@
1
- export { default } from "@projectcaluma/ember-core/utils/and";
package/app/utils/or.js DELETED
@@ -1 +0,0 @@
1
- export { default } from "@projectcaluma/ember-core/utils/or";