🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

ember-cp-validations

Package Overview
Dependencies
Maintainers
6
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cp-validations - npm Package Compare versions

Comparing version

to
5.0.0

15

addon/-private/ember-internals.js

@@ -1,16 +0,3 @@

import Ember from 'ember';
import { A } from '@ember/array';
import __EMBER_METAL__ from '@ember/-internals/metal/index';
let __EMBER_METAL__;
let emberMetalPaths = [
'@ember/-internals/metal', // ember-source from 3.10
'@ember/-internals/metal/index', // ember-source from 3.13
];
let metalPath = A(emberMetalPaths).find(
(path) => Ember.__loader.registry[path]
);
if (metalPath) {
__EMBER_METAL__ = Ember.__loader.require(metalPath);
}
export function getDependentKeys(descriptorOrDecorator) {

@@ -17,0 +4,0 @@ if (__EMBER_METAL__ && __EMBER_METAL__.descriptorForDecorator) {

2

addon/-private/ember-validator.js

@@ -6,3 +6,3 @@ import Base from 'ember-cp-validations/validators/base';

validate() {
let result = _validate(this.get('_evType'), ...arguments);
let result = _validate(this._evType, ...arguments);

@@ -9,0 +9,0 @@ if (result && typeof result === 'object') {

@@ -1,2 +0,2 @@

import EmberObject, { computed, set, get } from '@ember/object';
import EmberObject, { computed, set } from '@ember/object';
import { and, not, readOnly } from '@ember/object/computed';

@@ -23,3 +23,3 @@ import { isNone } from '@ember/utils';

if (this.get('isAsync')) {
if (this.isAsync) {
this._handlePromise();

@@ -36,7 +36,7 @@ }

isAsync: computed('_promise', function () {
return isPromise(get(this, '_promise'));
return isPromise(this._promise);
}),
messages: computed('message', function () {
return makeArray(get(this, 'message'));
return makeArray(this.message);
}),

@@ -51,7 +51,7 @@

function () {
if (get(this, 'isInvalid')) {
if (this.isInvalid) {
return ValidationError.create({
type: get(this, '_type'),
message: get(this, 'message'),
attribute: get(this, 'attribute'),
type: this._type,
message: this.message,
attribute: this.attribute,
});

@@ -65,7 +65,7 @@ }

errors: computed('error', function () {
return makeArray(get(this, 'error'));
return makeArray(this.error);
}),
warningMessages: computed('warningMessage', function () {
return makeArray(get(this, 'warningMessage'));
return makeArray(this.warningMessage);
}),

@@ -80,7 +80,7 @@

function () {
if (get(this, 'isWarning') && !isNone(get(this, 'warningMessage'))) {
if (this.isWarning && !isNone(this.warningMessage)) {
return ValidationError.create({
type: get(this, '_type'),
message: get(this, 'warningMessage'),
attribute: get(this, 'attribute'),
type: this._type,
message: this.warningMessage,
attribute: this.attribute,
});

@@ -94,3 +94,3 @@ }

warnings: computed('warning', function () {
return makeArray(get(this, 'warning'));
return makeArray(this.warning);
}),

@@ -101,3 +101,3 @@

get(this, '_promise').finally(() => {
this._promise.finally(() => {
set(this, 'isValidating', false);

@@ -104,0 +104,0 @@ });

import { isNone } from '@ember/utils';
import { isArray } from '@ember/array';
import EmberObject, {
getProperties,
setProperties,
computed,
set,
get,
} from '@ember/object';
import EmberObject, { setProperties, computed, set } from '@ember/object';
import { readOnly } from '@ember/object/computed';

@@ -65,7 +59,4 @@ import ResultCollection from '../validations/result-collection';

_isReadOnly: computed('_result', function () {
let validations = get(this, '_result');
return (
validations instanceof ResultCollection ||
get(validations, 'isValidations')
);
let validations = this._result;
return validations instanceof ResultCollection || validations.isValidations;
}).readOnly(),

@@ -191,7 +182,7 @@

function () {
let { model, attribute, _promise, _validator } = this;
return (
get(this, '_resultOverride') ||
InternalResultObject.create(
getProperties(this, ['model', 'attribute', '_promise', '_validator'])
)
this._resultOverride ||
InternalResultObject.create({ model, attribute, _promise, _validator })
);

@@ -204,3 +195,3 @@ }

if (get(this, 'isAsync') && !get(this, '_isReadOnly')) {
if (this.isAsync && !this._isReadOnly) {
this._handlePromise();

@@ -224,5 +215,5 @@ }

update(value) {
let result = get(this, '_result');
let attribute = get(this, 'attribute');
let isWarning = get(this, 'isWarning');
let result = this._result;
let attribute = this.attribute;
let isWarning = this.isWarning;
let Collection = isWarning ? WarningResultCollection : ResultCollection;

@@ -232,11 +223,11 @@

return this.update(false);
} else if (get(value, 'isValidations')) {
} else if (value.isValidations) {
this._overrideResult(Collection.create({ attribute, content: [value] }));
} else if (isArray(value)) {
this._overrideResult(Collection.create({ attribute, content: value }));
} else if (!get(this, '_isReadOnly')) {
} else if (!this._isReadOnly) {
this._overrideResult(undefined);
if (typeof value === 'string') {
setProperties(get(this, '_result'), {
setProperties(this._result, {
[isWarning ? 'warningMessage' : 'message']: value,

@@ -269,3 +260,3 @@ isValid: isWarning ? true : false,

_handlePromise() {
get(this, '_promise')
this._promise
.then(

@@ -272,0 +263,0 @@ (value) => this.update(value),

@@ -245,6 +245,6 @@ import Factory from './validations/factory';

* max: Ember.computed.readOnly('model.meta.username.maxLength'),
* description: Ember.computed(function() {
* description: Ember.computed('model', 'attribute', function() {
* // CPs have access to the `model` and `attribute`
* return this.get('model').generateDescription(this.get('attribute'));
* }).volatile() // Disable caching and force recompute on every get call
* })
* })

@@ -251,0 +251,0 @@ * });

@@ -1,2 +0,2 @@

import Ember from 'ember';
import { meta } from '@ember/-internals/meta';

@@ -11,3 +11,3 @@ let id = 0;

function getData(obj, s) {
let m = Ember.meta(obj);
let m = meta(obj);
let data = m[dataKey];

@@ -21,3 +21,3 @@

function setData(obj, s, value) {
let m = Ember.meta(obj);
let m = meta(obj);
let data = (m[dataKey] = m[dataKey] || {});

@@ -24,0 +24,0 @@

import ArrayProxy from '@ember/array/proxy';
import ObjectProxy from '@ember/object/proxy';
import { isHTMLSafe } from '@ember/template';
import EmberObject, { get } from '@ember/object';
import EmberObject from '@ember/object';
import { typeOf } from '@ember/utils';
import { A as emberArray, isArray } from '@ember/array';
import require from 'require';
import Ember from 'ember';
import requireModule from 'ember-require-module';
function requireModule(module, exportName = 'default') {
if (require.has(module)) {
return require(module)[exportName];
}
}
const DS = requireModule('ember-data');
const { canInvoke } = Ember;
export { getDependentKeys, isDescriptor } from '../-private/ember-internals';

@@ -26,3 +28,3 @@

export function unwrapProxy(o) {
return isProxy(o) ? unwrapProxy(get(o, 'content')) : o;
return isProxy(o) ? unwrapProxy(o.content) : o;
}

@@ -34,2 +36,8 @@

function canInvoke(obj, methodName) {
return (
obj !== null && obj !== undefined && typeof obj[methodName] === 'function'
);
}
export function isPromise(p) {

@@ -62,3 +70,3 @@ return !!(p && canInvoke(p, 'then'));

let v = unwrapProxy(value);
return isDsModel(v) ? !get(v, 'isDeleted') : true;
return isDsModel(v) ? !v.isDeleted : true;
}

@@ -65,0 +73,0 @@

@@ -10,3 +10,3 @@ import Mixin from '@ember/object/mixin';

import { getOwner } from '@ember/application';
import { deprecate } from '@ember/debug';
import { assert } from '@ember/debug';
import deepSet from '../utils/deep-set';

@@ -131,11 +131,11 @@ import ValidationResult from '../-private/result';

validate() {
return get(this, 'validations').validate(...arguments);
return this.validations.validate(...arguments);
},
validateSync() {
return get(this, 'validations').validateSync(...arguments);
return this.validations.validateSync(...arguments);
},
validateAttribute() {
return get(this, 'validations').validateAttribute(...arguments);
return this.validations.validateAttribute(...arguments);
},

@@ -145,3 +145,3 @@

this._super(...arguments);
get(this, 'validations').destroy();
this.validations.destroy();
},

@@ -266,3 +266,3 @@ });

attrs: AttrsClass.create({
[ATTRS_MODEL]: this.get('model'),
[ATTRS_MODEL]: this.model,
}),

@@ -276,7 +276,7 @@ _validators: {},

this._super(...arguments);
let validatableAttrs = get(this, 'validatableAttributes');
let debouncedValidations = get(this, '_debouncedValidations');
let validatableAttrs = this.validatableAttributes;
let debouncedValidations = this._debouncedValidations;
// Initiate attrs destroy to cleanup any remaining model references
this.get('attrs').destroy();
this.attrs.destroy();

@@ -416,20 +416,10 @@ // Cancel all debounced timers

let isVolatile = hasOption(validations, 'volatile', true);
deprecate(
'[ember-cp-validations] The `volatile` option should no longer be used ' +
assert(
'[ember-cp-validations] The `volatile` option is no longer available ' +
'as it was removed in ember 4.0',
!isVolatile,
{
id: 'ember-cp-validations.volatile',
for: 'ember-cp-validations',
since: '3.1.0',
until: '5.0.0',
}
!isVolatile
);
let dependentKeys = isVolatile
? []
: getCPDependentKeysFor(attribute, model, validations);
let cp = computed(
let dependentKeys = getCPDependentKeysFor(attribute, model, validations);
return computed(
...dependentKeys,

@@ -460,8 +450,2 @@ cycleBreaker(function () {

).readOnly();
if (isVolatile) {
cp = cp.volatile();
}
return cp;
}

@@ -520,3 +504,3 @@

return validators.map((validator) => {
let options = get(validator, 'options').toObject();
let options = validator.options.toObject();
let isWarning = getWithDefault(options, 'isWarning', false);

@@ -540,3 +524,3 @@ let disabled = getWithDefault(options, 'disabled', false);

}).then(() => {
return validate(validator, get(validator, 'options').toObject());
return validate(validator, validator.options.toObject());
});

@@ -553,3 +537,3 @@ } else {

*/
if (!isInvalid && !isWarning && get(result, 'isInvalid')) {
if (!isInvalid && !isWarning && result.isInvalid) {
isInvalid = true;

@@ -647,4 +631,4 @@ }

...extractOptionsDependentKeys(options),
...extractOptionsDependentKeys(get(validation, 'defaultOptions')),
...extractOptionsDependentKeys(get(validation, 'globalOptions')),
...extractOptionsDependentKeys(validation.defaultOptions),
...extractOptionsDependentKeys(validation.globalOptions),
];

@@ -748,3 +732,3 @@ });

function getDebouncedValidationsCacheFor(attribute, model) {
let debouncedValidations = get(model, 'validations._debouncedValidations');
let debouncedValidations = model.validations._debouncedValidations;

@@ -768,7 +752,7 @@ if (isNone(get(debouncedValidations, attribute))) {

function createValidatorsFor(attribute, model) {
let validations = get(model, 'validations');
let validations = model.validations;
let validationRules = makeArray(
get(validations, `_validationRules.${attribute}`)
);
let validatorCache = get(validations, '_validators');
let validatorCache = validations._validators;
let owner = getOwner(model);

@@ -828,30 +812,27 @@ let validators = [];

function validate(options = {}, isAsync = true) {
let model = get(this, 'model');
let model = this.model;
let whiteList = makeArray(options.on);
let blackList = makeArray(options.excludes);
let validationResults = get(this, 'validatableAttributes').reduce(
(v, name) => {
if (!isEmpty(blackList) && blackList.indexOf(name) !== -1) {
return v;
}
let validationResults = this.validatableAttributes.reduce((v, name) => {
if (!isEmpty(blackList) && blackList.indexOf(name) !== -1) {
return v;
}
if (isEmpty(whiteList) || whiteList.indexOf(name) !== -1) {
let validationResult = get(this, `attrs.${name}`);
if (isEmpty(whiteList) || whiteList.indexOf(name) !== -1) {
let validationResult = get(this, `attrs.${name}`);
// If an async validation is found, throw an error
if (!isAsync && get(validationResult, 'isAsync')) {
throw new Error(
`[ember-cp-validations] Synchronous validation failed due to ${name} being an async validation.`
);
}
v.push(validationResult);
// If an async validation is found, throw an error
if (!isAsync && validationResult.isAsync) {
throw new Error(
`[ember-cp-validations] Synchronous validation failed due to ${name} being an async validation.`
);
}
return v;
},
[]
);
v.push(validationResult);
}
return v;
}, []);
let validations = ResultCollection.create({

@@ -865,3 +846,3 @@ attribute: `Validate:${model}`,

if (isAsync) {
return Promise.resolve(get(validations, '_promise')).then(() => {
return Promise.resolve(validations._promise).then(() => {
/*

@@ -872,3 +853,3 @@ NOTE: When dealing with belongsTo and hasMany relationships, there are cases

*/
return get(validations, 'isValidating')
return validations.isValidating
? this.validate(options, isAsync)

@@ -901,3 +882,3 @@ : resultObject;

function validateAttribute(attribute, value) {
let model = get(this, 'model');
let model = this.model;
let validators = !isNone(model) ? getValidatorsFor(attribute, model) : [];

@@ -924,3 +905,3 @@

return Promise.resolve(get(validations, '_promise')).then(() => {
return Promise.resolve(validations._promise).then(() => {
/*

@@ -931,3 +912,3 @@ NOTE: When dealing with belongsTo and hasMany relationships, there are cases

*/
return get(validations, 'isValidating')
return validations.isValidating
? this.validateAttribute(attribute, value)

@@ -934,0 +915,0 @@ : result;

@@ -120,22 +120,2 @@ import { isNone } from '@ember/utils';

*
* ### volatile
*
* Default: __false__
*
* If any validator sets the volatile option to **true** (including options, default options, and global options),
* it will place the entire attribute's CP in a volatile state. This means that it will set it into non-cached mode.
* When in this mode the computed property will not automatically cache the return value.
*
* Dependency keys have no effect on volatile properties as they are for cache invalidation and notification when
* cached value is invalidated. Any changes to the dependents will not refire validations.
*
* __**WARNING: This option should only be used if you know what you're doing**__
*
* ```javascript
* // Examples
* validator('length', {
* volatile: true
* })
* ```
*
* ### value

@@ -142,0 +122,0 @@ *

import { assert } from '@ember/debug';
import { isPresent } from '@ember/utils';
import { getProperties, get } from '@ember/object';
import { get } from '@ember/object';
import Base from 'ember-cp-validations/validators/base';

@@ -67,6 +67,3 @@

validate(value, options, model, attribute) {
let { alias, firstMessageOnly } = getProperties(options, [
'alias',
'firstMessageOnly',
]);
let { alias, firstMessageOnly } = options;

@@ -80,5 +77,3 @@ assert(

return firstMessageOnly
? get(aliasValidation, 'message')
: get(aliasValidation, 'content');
return firstMessageOnly ? aliasValidation.message : aliasValidation.content;
},

@@ -89,3 +84,3 @@ });

getDependentsFor(attribute, options) {
let alias = typeof options === 'string' ? options : get(options, 'alias');
let alias = typeof options === 'string' ? options : options.alias;

@@ -92,0 +87,0 @@ assert(

@@ -0,1 +1,3 @@

// False positive: the native class that exists in the document does not use CPs
/* eslint-disable ember/no-computed-properties-in-native-classes */
import { bool } from '@ember/object/computed';

@@ -95,5 +97,5 @@ import EmberObject, { set, get, computed } from '@ember/object';

this._super(...arguments);
let globalOptions = get(this, 'globalOptions');
let defaultOptions = get(this, 'defaultOptions');
let options = get(this, 'options');
let globalOptions = this.globalOptions;
let defaultOptions = this.defaultOptions;
let options = this.options;
let owner = getOwner(this);

@@ -137,4 +139,4 @@ let errorMessages;

return new Options({
model: get(this, 'model'),
attribute: get(this, 'attribute'),
model: this.model,
attribute: this.attribute,
options: builtOptions,

@@ -166,3 +168,3 @@ });

getValue() {
let value = this.value(get(this, 'model'), get(this, 'attribute'));
let value = this.value(this.model, this.attribute);
return getValidatableValue(value);

@@ -222,4 +224,4 @@ },

createErrorMessage(type, value, options = {}) {
let messages = this.get('errorMessages');
let message = unwrapString(get(options, 'message'));
let messages = this.errorMessages;
let message = unwrapString(options.message);

@@ -229,3 +231,3 @@ set(

'description',
messages.getDescriptionFor(get(this, 'attribute'), options)
messages.getDescriptionFor(this.attribute, options)
);

@@ -290,3 +292,3 @@

test(type, ...args) {
const cache = this.get('_testValidatorCache');
const cache = this._testValidatorCache;
const unsupportedTypes = ['alias', 'belongs-to', 'dependent', 'has-many'];

@@ -471,3 +473,3 @@

* validator.validate('johndoe42').then((message) => {
* assert.equal(message, true);
* assert.strictEqual(message, true);
* done();

@@ -474,0 +476,0 @@ * });

@@ -1,2 +0,1 @@

import { get } from '@ember/object';
import Base from 'ember-cp-validations/validators/base';

@@ -81,3 +80,3 @@ import { isPromise } from 'ember-cp-validations/utils/utils';

return get(value, 'validations');
return value.validations;
}

@@ -84,0 +83,0 @@

@@ -1,2 +0,1 @@

import { get } from '@ember/object';
import EmberValidator from 'ember-cp-validations/-private/ember-validator';

@@ -58,3 +57,3 @@

getDependentsFor(attribute, options) {
return options === true || get(options, 'collection') === true
return options === true || options.collection === true
? [`model.${attribute}.[]`]

@@ -61,0 +60,0 @@ : [];

@@ -1,2 +0,1 @@

import { get } from '@ember/object';
import { assert } from '@ember/debug';

@@ -32,3 +31,3 @@ import EmberValidator from 'ember-cp-validations/-private/ember-validator';

getDependentsFor(attribute, options) {
let on = get(options, 'on');
let on = options.on;

@@ -35,0 +34,0 @@ assert(

@@ -1,2 +0,2 @@

import { getProperties, get } from '@ember/object';
import { get } from '@ember/object';
import { assert } from '@ember/debug';

@@ -36,3 +36,3 @@ import { isPresent, isEmpty, isNone } from '@ember/utils';

validate(value, options, model, attribute) {
let { on, allowBlank } = getProperties(options, ['on', 'allowBlank']);
let { on, allowBlank } = options;

@@ -56,5 +56,3 @@ assert(

if (
!isEmpty(dependentValidations.filter((v) => get(v, 'isTruelyInvalid')))
) {
if (!isEmpty(dependentValidations.filter((v) => v.isTruelyInvalid))) {
return this.createErrorMessage('invalid', value, options);

@@ -69,3 +67,3 @@ }

getDependentsFor(attribute, options) {
let dependents = get(options, 'on');
let dependents = options.on;

@@ -72,0 +70,0 @@ assert(

import Base from 'ember-cp-validations/validators/base';
import { isPromise } from 'ember-cp-validations/utils/utils';
import { get } from '@ember/object';

@@ -59,3 +58,3 @@ /**

return value.map((m) => get(m, 'validations'));
return value.map((m) => m.validations);
}

@@ -62,0 +61,0 @@

# Changelog
## v5.0.0 (2022-10-27)
#### :boom: Breaking Change
* [#717](https://github.com/adopted-ember-addons/ember-cp-validations/pull/717) Ember 4.0 compatibility - drops support for Ember < 3.28 ([@fsmanuel](https://github.com/fsmanuel))
#### Committers: 1
- Manuel Wiedenmann ([@fsmanuel](https://github.com/fsmanuel))
## v4.0.0 (2022-09-21)

@@ -5,0 +14,0 @@

{
"name": "ember-cp-validations",
"version": "4.0.0",
"version": "5.0.0",
"description": "Ember computed property based validation library",

@@ -54,3 +54,2 @@ "keywords": [

"ember-cli-babel": "^7.26.10",
"ember-require-module": "^0.4.0",
"ember-validators": "^4.1.1"

@@ -67,3 +66,3 @@ },

"ember-auto-import": "^2.4.2",
"ember-cli": "~3.28.5",
"ember-cli": "~4.0.1",
"ember-cli-app-version": "^5.0.0",

@@ -73,3 +72,3 @@ "ember-cli-autoprefixer": "^0.7.0",

"ember-cli-github-pages": "^0.2.0",
"ember-cli-htmlbars": "^5.7.2",
"ember-cli-htmlbars": "^6.0.1",
"ember-cli-inject-live-reload": "^2.1.0",

@@ -87,11 +86,10 @@ "ember-cli-moment-shim": "^3.3.3",

"ember-load-initializers": "^2.1.2",
"ember-maybe-import-regenerator": "^1.0.0",
"ember-prism": "0.12.0",
"ember-prism": "^0.12.0",
"ember-qunit": "^5.1.5",
"ember-resolver": "^8.0.3",
"ember-source": "~3.28.8",
"ember-source": "~4.0.1",
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^3.15.0",
"ember-truth-helpers": "3.0.0",
"ember-try": "^1.4.0",
"ember-truth-helpers": "^3.0.0",
"ember-try": "^2.0.0",
"eslint": "^7.32.0",

@@ -101,4 +99,4 @@ "eslint-config-prettier": "^8.3.0",

"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-qunit": "^6.2.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-qunit": "^7.2.0",
"loader.js": "^4.7.0",

@@ -108,7 +106,7 @@ "npm-run-all": "^4.1.5",

"qunit": "^2.17.2",
"qunit-dom": "^1.6.0",
"qunit-dom": "^2.0.0",
"release-it": "^14.2.1",
"release-it-lerna-changelog": "^3.1.0",
"sass": "^1.15.3",
"webpack": "^5.0.0",
"webpack": "^5.65.0",
"yuidoc-ember-theme": "^2.0.1"

@@ -115,0 +113,0 @@ },