Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ module.exports = {
root: true,
parser: '@babel/eslint-parser',
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
requireConfigFile: false,
babelOptions: {
plugins: [
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }],
],
},
},
plugins: ['ember'],
Expand All @@ -19,13 +22,19 @@ module.exports = {
env: {
browser: true,
},
rules: {},
rules: {
'ember/no-classic-classes': 'off',
'ember/no-new-mixins': 'off',
'ember/no-runloop': 'off',
'ember/use-ember-data-rfc-395-imports': 'off',
},
overrides: [
// node files
{
files: [
'./.eslintrc.js',
'./.prettierrc.js',
'./.stylelintrc.js',
'./.template-lintrc.js',
'./ember-cli-build.js',
'./index.js',
Expand All @@ -47,6 +56,10 @@ module.exports = {
// test files
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
rules: {
'qunit/no-conditional-assertions': 'off',
'qunit/require-expect': 'off',
},
},
],
};
21 changes: 11 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
timeout-minutes: 10

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 22.x
cache: npm
- name: Install Dependencies
run: npm ci
Expand All @@ -37,10 +37,10 @@ jobs:
timeout-minutes: 10

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 22.x
cache: npm
- name: Install Dependencies
run: npm install --no-shrinkwrap
Expand All @@ -57,19 +57,20 @@ jobs:
fail-fast: false
matrix:
try-scenario:
- ember-lts-4.8
- ember-lts-5.8
- ember-lts-5.12
- ember-release
- ember-beta
- ember-canary
- embroider-safe
- embroider-optimized

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 22.x
cache: npm
- name: Install Dependencies
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion addon/-private/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class Options {
attribute,
options = {},
defaultOptions = {},
globalOptions = {}
globalOptions = {},
) {
Object.assign(this, {
model,
Expand Down
21 changes: 12 additions & 9 deletions addon/decorators/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function buildValidations(validations = {}, globalOptions = {}) {
this,
createCache(() => {
return new this.__VALIDATIONS_CLASS__(this);
})
}),
);
}

Expand All @@ -105,7 +105,7 @@ export default function buildValidations(validations = {}, globalOptions = {}) {
if (!ValidationsClass) {
ValidationsClass = createValidationsClass(
Object.getPrototypeOf(this)?.__VALIDATIONS_CLASS__,
validations
validations,
);
}
return ValidationsClass;
Expand Down Expand Up @@ -179,12 +179,14 @@ function createValidationsClass(inheritedValidationsClass, validations) {

validationRules = Object.assign(
validationRules,
inheritedValidations._validationRules
inheritedValidations._validationRules,
);

validatableAttributes = [
...new Set(
inheritedValidations.validatableAttributes.concat(validatableAttributes)
inheritedValidations.validatableAttributes.concat(
validatableAttributes,
),
),
];
}
Expand Down Expand Up @@ -365,15 +367,15 @@ function createAttrsClass(validatableAttributes) {
validator.getValue(),
options,
model,
attribute
)
attribute,
),
);

return ResultCollection.create({
attribute,
content: validationResults,
});
})
}),
);
}

Expand Down Expand Up @@ -483,7 +485,7 @@ function createValidatorsFor(attribute, model) {
// We must have an owner to be able to lookup our validators
if (isNone(owner)) {
throw new TypeError(
`[@eflexsystems/ember-tracked-validations] ${model.toString()} is missing a container or owner.`
`[@eflexsystems/ember-tracked-validations] ${model.toString()} is missing a container or owner.`,
);
}

Expand Down Expand Up @@ -562,7 +564,8 @@ function validateAttribute(attribute, value) {
attribute,
model,
validators,
(validator, options) => validator.validate(value, options, model, attribute)
(validator, options) =>
validator.validate(value, options, model, attribute),
);

let validations = ResultCollection.create({
Expand Down
4 changes: 2 additions & 2 deletions addon/utils/lookup-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
export default function lookupValidator(owner, type) {
if (!owner) {
throw new Error(
`[@eflexsystems/ember-tracked-validations] \`lookupValidator\` requires owner/container access.`
`[@eflexsystems/ember-tracked-validations] \`lookupValidator\` requires owner/container access.`,
);
}

const validatorClass = owner.factoryFor(`validator:${type}`);

if (!validatorClass) {
throw new Error(
`[@eflexsystems/ember-tracked-validations] Validator not found of type: ${type}.`
`[@eflexsystems/ember-tracked-validations] Validator not found of type: ${type}.`,
);
}

Expand Down
22 changes: 19 additions & 3 deletions addon/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import { isArray } from '@ember/array';
// eslint-disable-next-line ember/use-ember-data-rfc-395-imports
import DS from 'ember-data';
import Model from '@ember-data/model';
import {
macroCondition,
dependencySatisfies,
importSync,
} from '@embroider/macros';

let DS;
if (macroCondition(dependencySatisfies('ember-data', '*'))) {
DS = importSync('ember-data').default;
}

export function isValidatable(value) {
return value && value instanceof Model ? !value.isDeleted : true;
}

export function isDSManyArray(o) {
return !!(
DS &&
o &&
(o instanceof DS.PromiseManyArray || o instanceof DS.ManyArray)
);
}

export function getValidatableValue(value) {
if (!value) {
return value;
}

if (value && isArray(value) && value instanceof DS.ManyArray) {
if (value && isArray(value) && value && isDSManyArray(value)) {
return value.filter((v) => isValidatable(v));
}

Expand Down
4 changes: 2 additions & 2 deletions addon/validations/result-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default class ValidationsResultCollection {
*/
get warnings() {
return this._computeErrorCollection(
this.content.map((item) => item.warnings)
this.content.map((item) => item.warnings),
);
}

Expand Down Expand Up @@ -208,7 +208,7 @@ export default class ValidationsResultCollection {
*/
get errors() {
return this._computeErrorCollection(
this.content.map((item) => item.errors)
this.content.map((item) => item.errors),
);
}

Expand Down
2 changes: 1 addition & 1 deletion addon/validations/warning-result-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class WarningResultCollection extends ResultCollection {
[
this.content.map((item) => item.errors),
this.content.map((item) => item.warnings),
].flat(Infinity)
].flat(Infinity),
);
}
}
6 changes: 3 additions & 3 deletions addon/validators/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class ValidatorsBase {
this.options = this.buildOptions(
props.options,
props.defaultOptions,
props.globalOptions
props.globalOptions,
);
this.errorMessages = (errorMessages ?? Messages).create();
}
Expand Down Expand Up @@ -133,7 +133,7 @@ export default class ValidatorsBase {
this.attribute,
options,
defaultOptions,
globalOptions
globalOptions,
);
}

Expand Down Expand Up @@ -283,7 +283,7 @@ export default class ValidatorsBase {

if (unsupportedTypes.includes(type)) {
throw new Error(
`[@eflexsystems/ember-tracked-validations] The \`test\` API does not support validators of type: ${type}.`
`[@eflexsystems/ember-tracked-validations] The \`test\` API does not support validators of type: ${type}.`,
);
}

Expand Down
4 changes: 2 additions & 2 deletions addon/validators/dependent.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class ValidatorsDependent extends Base {

assert(
`[validator:dependent] [${attribute}] option 'on' is required`,
isPresent(on)
isPresent(on),
);

if (isNone(model)) {
Expand All @@ -46,7 +46,7 @@ export default class ValidatorsDependent extends Base {
}

let dependentValidations = (options.on ?? []).map(
(dependent) => model.validations.attrs[dependent]
(dependent) => model.validations.attrs[dependent],
);

if (!isEmpty(dependentValidations.filter((v) => v.isInvalid))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Unit | Validator | <%= dasherizedModuleName %>', function () {
// Replace this with your real tests.
it('exists', function () {
const validator = this.owner.lookup(
'validator:<%= dasherizedModuleName %>'
'validator:<%= dasherizedModuleName %>',
);
expect(validator).to.be.ok;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module('Unit | Validator | <%= dasherizedModuleName %>', function (hooks) {
// Replace this with your real tests.
test('it exists', function (assert) {
const validator = this.owner.lookup(
'validator:<%= dasherizedModuleName %>'
'validator:<%= dasherizedModuleName %>',
);
assert.ok(validator);
});
Expand Down
12 changes: 10 additions & 2 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ module.exports = async function () {
return {
scenarios: [
{
name: 'ember-lts-4.8',
name: 'ember-lts-5.8',
npm: {
devDependencies: {
'ember-source': '~4.8.4',
'ember-source': '~5.8.0',
},
},
},
{
name: 'ember-lts-5.12',
npm: {
devDependencies: {
'ember-source': '~5.12.0',
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion config/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {

afterPublish: function (project, versions) {
runCommand(
'ember github-pages:commit --message "Released ' + versions.next + '"'
'ember github-pages:commit --message "Released ' + versions.next + '"',
);
runCommand('git push origin gh-pages:gh-pages');
},
Expand Down
8 changes: 7 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ module.exports = function (defaults) {
snippetPaths: ['snippets', 'tests/dummy/snippets'],

'ember-bootstrap': {
bootstrapVersion: 4,
bootstrapVersion: 5,
importBootstrapFont: false,
importBootstrapCSS: false,
},

emberData: {
deprecations: {
DEPRECATE_STORE_EXTENDS_EMBER_OBJECT: false,
},
},
});

/*
Expand Down
Loading