@projectcaluma/ember-core 10.0.2 → 11.0.0-beta.3
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/CHANGELOG.md +1069 -0
- package/addon/caluma-query/index.js +10 -0
- package/addon/caluma-query/queries/base.js +1 -1
- package/addon/caluma-query/resource.js +71 -0
- package/addon/helpers/has-question-type.js +3 -1
- package/addon/services/-scheduler.js +12 -0
- package/addon/{mixins/caluma-apollo-service-mixin.js → services/apollo.js} +8 -8
- package/addon/services/caluma-options.js +10 -0
- package/app/services/apollo.js +1 -0
- package/app/utils/jexl.js +1 -0
- package/index.js +0 -25
- package/package.json +21 -22
- package/addon/gql/queries/all-format-validators.graphql +0 -12
- package/addon/helpers/get-widget.js +0 -50
- package/addon/services/validator.js +0 -66
- package/addon/utils/and.js +0 -47
- package/addon/utils/or.js +0 -40
- package/app/helpers/get-widget.js +0 -4
- package/app/services/validator.js +0 -1
- package/app/utils/and.js +0 -1
- package/app/utils/or.js +0 -1
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { getOwner, setOwner } from "@ember/application";
|
|
2
|
+
import { useResource } from "ember-resources";
|
|
3
|
+
|
|
4
|
+
import CalumaQueryResource from "@projectcaluma/ember-core/caluma-query/resource";
|
|
5
|
+
|
|
6
|
+
export function useCalumaQuery(destroyable, query, thunk) {
|
|
7
|
+
return useResource(destroyable, CalumaQueryResource, () => ({
|
|
8
|
+
query,
|
|
9
|
+
...thunk(),
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
2
12
|
|
|
3
13
|
export default function calumaQuery({ query, options = {} }) {
|
|
4
14
|
return function (_, name) {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { getOwner, setOwner } from "@ember/application";
|
|
2
|
+
import { destroy } from "@ember/destroyable";
|
|
3
|
+
import { action } from "@ember/object";
|
|
4
|
+
import { tracked } from "@glimmer/tracking";
|
|
5
|
+
import { LifecycleResource } from "ember-resources";
|
|
6
|
+
|
|
7
|
+
export default class CalumaQueryResource extends LifecycleResource {
|
|
8
|
+
@tracked query;
|
|
9
|
+
|
|
10
|
+
setup() {
|
|
11
|
+
const { query, options, queryArgs } = this._parsedArgs;
|
|
12
|
+
|
|
13
|
+
this.query = query(options);
|
|
14
|
+
setOwner(this.query, getOwner(this));
|
|
15
|
+
|
|
16
|
+
this.query.fetch(queryArgs);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
update() {
|
|
20
|
+
this._updateOptions();
|
|
21
|
+
|
|
22
|
+
this.query.fetch(this._parsedArgs.queryArgs);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
teardown() {
|
|
26
|
+
destroy(this.query);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get _parsedArgs() {
|
|
30
|
+
const { query, options = {}, ...queryArgs } = this.args.named;
|
|
31
|
+
|
|
32
|
+
return { query, options, queryArgs };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_updateOptions() {
|
|
36
|
+
["pageSize", "processAll", "processNew", "queryOptions"].forEach(
|
|
37
|
+
(optionKey) => {
|
|
38
|
+
const option = this._parsedArgs.options[optionKey];
|
|
39
|
+
|
|
40
|
+
if (option !== undefined && option !== this.query[optionKey]) {
|
|
41
|
+
this.query[optionKey] = option;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@action
|
|
48
|
+
fetchMore(event) {
|
|
49
|
+
if (event instanceof Event) {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.query.fetchMore();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get value() {
|
|
57
|
+
return this.query.value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get hasNextPage() {
|
|
61
|
+
return this.query.hasNextPage;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get totalCount() {
|
|
65
|
+
return this.query.totalCount;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get isLoading() {
|
|
69
|
+
return this.query.isLoading;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -7,7 +7,9 @@ import { dasherize } from "@ember/string";
|
|
|
7
7
|
const parse = (raw) => dasherize(raw.replace("Question", ""));
|
|
8
8
|
|
|
9
9
|
export function hasQuestionType(obj, ...expected) {
|
|
10
|
-
return expected
|
|
10
|
+
return expected
|
|
11
|
+
.map(parse)
|
|
12
|
+
.includes(parse((obj?.raw?.__typename ?? obj?.__typename) || ""));
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export default helper(([obj, ...expected]) =>
|
|
@@ -76,4 +76,16 @@ export default class PrivateSchedulerService extends Service {
|
|
|
76
76
|
|
|
77
77
|
once(this[typeResolverName], "perform");
|
|
78
78
|
}
|
|
79
|
+
|
|
80
|
+
resolve(identifiers, type) {
|
|
81
|
+
const typeResolverName = camelize(`resolve-${type}`);
|
|
82
|
+
|
|
83
|
+
if (!this[type]) {
|
|
84
|
+
this[type] = { identifiers: new Set(), callbacks: new Set() };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
identifiers.forEach((identifier) => this[type].identifiers.add(identifier));
|
|
88
|
+
|
|
89
|
+
return this[typeResolverName]?.perform();
|
|
90
|
+
}
|
|
79
91
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { InMemoryCache, defaultDataIdFromObject } from "@apollo/client/cache";
|
|
2
2
|
import { setContext } from "@apollo/client/link/context";
|
|
3
|
-
import Mixin from "@ember/object/mixin";
|
|
4
3
|
import { inject as service } from "@ember/service";
|
|
4
|
+
import ApolloService from "ember-apollo-client/services/apollo";
|
|
5
5
|
|
|
6
6
|
import possibleTypes from "@projectcaluma/ember-core/-private/possible-types";
|
|
7
7
|
|
|
8
|
-
export default
|
|
9
|
-
intl
|
|
8
|
+
export default class CalumaApolloService extends ApolloService {
|
|
9
|
+
@service intl;
|
|
10
10
|
|
|
11
11
|
cache() {
|
|
12
12
|
return new InMemoryCache({
|
|
@@ -17,10 +17,10 @@ export default Mixin.create({
|
|
|
17
17
|
_id: obj.slug || obj._id,
|
|
18
18
|
}),
|
|
19
19
|
});
|
|
20
|
-
}
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
link(
|
|
23
|
-
const httpLink =
|
|
22
|
+
link() {
|
|
23
|
+
const httpLink = super.link();
|
|
24
24
|
|
|
25
25
|
const localeLink = setContext((request, context) => ({
|
|
26
26
|
...context,
|
|
@@ -32,5 +32,5 @@ export default Mixin.create({
|
|
|
32
32
|
}));
|
|
33
33
|
|
|
34
34
|
return localeLink.concat(httpLink);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { assert } from "@ember/debug";
|
|
1
2
|
import Service, { inject as service } from "@ember/service";
|
|
3
|
+
import { tracked } from "@glimmer/tracking";
|
|
2
4
|
|
|
3
5
|
import slugify from "@projectcaluma/ember-core/utils/slugify";
|
|
4
6
|
|
|
@@ -14,6 +16,8 @@ import slugify from "@projectcaluma/ember-core/utils/slugify";
|
|
|
14
16
|
export default class CalumaOptionsService extends Service {
|
|
15
17
|
@service intl;
|
|
16
18
|
|
|
19
|
+
@tracked currentGroupId;
|
|
20
|
+
|
|
17
21
|
constructor(...args) {
|
|
18
22
|
super(...args);
|
|
19
23
|
|
|
@@ -106,4 +110,10 @@ export default class CalumaOptionsService extends Service {
|
|
|
106
110
|
[this.userNameProperty]: identifier,
|
|
107
111
|
}));
|
|
108
112
|
}
|
|
113
|
+
|
|
114
|
+
fetchTypedGroups(/* types, search */) {
|
|
115
|
+
assert(
|
|
116
|
+
"`fetchTypedGroups` must be implemented on the Caluma options service"
|
|
117
|
+
);
|
|
118
|
+
}
|
|
109
119
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "@projectcaluma/ember-core/services/apollo";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "@projectcaluma/ember-core/utils/jexl";
|
package/index.js
CHANGED
|
@@ -1,30 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const DEFAULT_OPTIONS = {
|
|
4
|
-
includeProxyPolyfill: true,
|
|
5
|
-
includeIntersectionObserverPolyfill: true,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
3
|
module.exports = {
|
|
9
4
|
name: require("./package").name,
|
|
10
|
-
|
|
11
|
-
_getOptions() {
|
|
12
|
-
const app = this._findHost();
|
|
13
|
-
|
|
14
|
-
return Object.assign({}, DEFAULT_OPTIONS, app.options["ember-caluma"]);
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
included(...args) {
|
|
18
|
-
this._super.included.apply(this, args);
|
|
19
|
-
|
|
20
|
-
if (this._getOptions().includeProxyPolyfill) {
|
|
21
|
-
this.import("node_modules/proxy-polyfill/proxy.min.js");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (this._getOptions().includeIntersectionObserverPolyfill) {
|
|
25
|
-
this.import(
|
|
26
|
-
"node_modules/intersection-observer/intersection-observer.js"
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
5
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectcaluma/ember-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0-beta.3",
|
|
4
4
|
"description": "Ember core addon for working with Caluma.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -14,39 +14,38 @@
|
|
|
14
14
|
"test:ember-compatibility": "ember try:each"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@apollo/client": "^3.
|
|
17
|
+
"@apollo/client": "^3.5.8",
|
|
18
18
|
"@glimmer/tracking": "^1.0.4",
|
|
19
19
|
"ember-apollo-client": "^3.2.0",
|
|
20
|
-
"ember-auto-import": "^2.
|
|
21
|
-
"ember-
|
|
22
|
-
"ember-cli-
|
|
23
|
-
"ember-cli-htmlbars": "^6.0.0",
|
|
20
|
+
"ember-auto-import": "^2.4.0",
|
|
21
|
+
"ember-cli-babel": "^7.26.11",
|
|
22
|
+
"ember-cli-htmlbars": "^6.0.1",
|
|
24
23
|
"ember-concurrency": "^2.2.0",
|
|
25
|
-
"ember-
|
|
26
|
-
"ember-
|
|
27
|
-
"ember-intl": "^5.7.
|
|
28
|
-
"
|
|
24
|
+
"ember-fetch": "^8.1.1",
|
|
25
|
+
"ember-inflector": "^4.0.2",
|
|
26
|
+
"ember-intl": "^5.7.2",
|
|
27
|
+
"ember-resources": "^4.2.0",
|
|
28
|
+
"graphql": "^15.8.0",
|
|
29
29
|
"graphql-tag": "^2.12.6",
|
|
30
|
-
"intersection-observer": "^0.12.0",
|
|
31
30
|
"jexl": "^2.3.0",
|
|
32
31
|
"lodash.clonedeep": "^4.5.0",
|
|
33
32
|
"moment": "^2.29.1",
|
|
34
|
-
"
|
|
35
|
-
"slugify": "^1.6.2"
|
|
33
|
+
"slugify": "^1.6.5"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
36
|
"@ember/optional-features": "2.0.0",
|
|
39
|
-
"@ember/render-modifiers": "2.0.
|
|
37
|
+
"@ember/render-modifiers": "2.0.4",
|
|
40
38
|
"@ember/test-helpers": "2.6.0",
|
|
41
|
-
"@embroider/test-setup": "0.
|
|
39
|
+
"@embroider/test-setup": "1.0.0",
|
|
40
|
+
"@faker-js/faker": "6.0.0-alpha.5",
|
|
42
41
|
"@glimmer/component": "1.0.4",
|
|
43
|
-
"@projectcaluma/ember-testing": "
|
|
42
|
+
"@projectcaluma/ember-testing": "11.0.0-beta.1",
|
|
44
43
|
"broccoli-asset-rev": "3.0.0",
|
|
45
|
-
"ember-cli": "3.28.
|
|
44
|
+
"ember-cli": "3.28.5",
|
|
46
45
|
"ember-cli-code-coverage": "1.0.3",
|
|
47
46
|
"ember-cli-dependency-checker": "3.2.0",
|
|
48
47
|
"ember-cli-inject-live-reload": "2.1.0",
|
|
49
|
-
"ember-cli-mirage": "2.
|
|
48
|
+
"ember-cli-mirage": "2.4.0",
|
|
50
49
|
"ember-cli-sri": "2.1.1",
|
|
51
50
|
"ember-cli-terser": "4.0.2",
|
|
52
51
|
"ember-disable-prototype-extensions": "1.1.3",
|
|
@@ -55,15 +54,14 @@
|
|
|
55
54
|
"ember-maybe-import-regenerator": "1.0.0",
|
|
56
55
|
"ember-qunit": "5.1.5",
|
|
57
56
|
"ember-resolver": "8.0.3",
|
|
58
|
-
"ember-source": "3.28.
|
|
57
|
+
"ember-source": "3.28.8",
|
|
59
58
|
"ember-source-channel-url": "3.0.0",
|
|
60
59
|
"ember-try": "2.0.0",
|
|
61
|
-
"faker": "5.5.3",
|
|
62
60
|
"loader.js": "4.7.0",
|
|
63
61
|
"npm-run-all": "4.1.5",
|
|
64
62
|
"qunit": "2.17.2",
|
|
65
63
|
"qunit-dom": "2.0.0",
|
|
66
|
-
"webpack": "5.
|
|
64
|
+
"webpack": "5.68.0"
|
|
67
65
|
},
|
|
68
66
|
"engines": {
|
|
69
67
|
"node": "12.* || 14.* || >= 16"
|
|
@@ -72,6 +70,7 @@
|
|
|
72
70
|
"edition": "octane"
|
|
73
71
|
},
|
|
74
72
|
"ember-addon": {
|
|
75
|
-
"configPath": "tests/dummy/config"
|
|
73
|
+
"configPath": "tests/dummy/config",
|
|
74
|
+
"after": "ember-apollo-client"
|
|
76
75
|
}
|
|
77
76
|
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import Helper from "@ember/component/helper";
|
|
2
|
-
import { warn } from "@ember/debug";
|
|
3
|
-
import { inject as service } from "@ember/service";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Helper for getting the right widget.
|
|
7
|
-
*
|
|
8
|
-
* This helper expects n objects as positional parameters. It checks if the
|
|
9
|
-
* object has a widget override in it's metadata. If one exists it checks if
|
|
10
|
-
* said widget was registered in the caluma options service and then returns
|
|
11
|
-
* the widget name. If it doesn't have a valid widget, the next object will be
|
|
12
|
-
* checked. If no object returns a valid widget, the passed default widget will
|
|
13
|
-
* be used.
|
|
14
|
-
*
|
|
15
|
-
* ```hbs
|
|
16
|
-
* {{component (get-widget field.question someobject default="cf-form") foo=bar}}
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @function getWidget
|
|
20
|
-
* @param {Array} params
|
|
21
|
-
* @param {Object} [options]
|
|
22
|
-
* @param {String} [options.default]
|
|
23
|
-
*/
|
|
24
|
-
export default class GetWidgetHelper extends Helper {
|
|
25
|
-
@service calumaOptions;
|
|
26
|
-
|
|
27
|
-
compute(params, { default: defaultWidget = "cf-field/input" }) {
|
|
28
|
-
for (const obj of params) {
|
|
29
|
-
const widget = obj?.meta?.widgetOverride;
|
|
30
|
-
if (!widget) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
const override =
|
|
34
|
-
widget &&
|
|
35
|
-
this.calumaOptions
|
|
36
|
-
.getComponentOverrides()
|
|
37
|
-
.find(({ component }) => component === widget);
|
|
38
|
-
|
|
39
|
-
warn(
|
|
40
|
-
`Widget override "${widget}" is not registered. Please register it by calling \`calumaOptions.registerComponentOverride\``,
|
|
41
|
-
override,
|
|
42
|
-
{ id: "ember-caluma.unregistered-override" }
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (override) return widget;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return defaultWidget;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -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
|
-
}
|
package/addon/utils/and.js
DELETED
|
@@ -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 +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";
|