From 2ba977d1adbb0526af9c686f74b6f3489ca0cc09 Mon Sep 17 00:00:00 2001 From: Dan Selman Date: Wed, 13 Sep 2023 12:49:40 -0700 Subject: [PATCH] chore(decoratormanager) API backwards compat (#715) Signed-off-by: Dan Selman --- packages/concerto-core/api.txt | 2 +- packages/concerto-core/changelog.txt | 2 +- packages/concerto-core/lib/decoratormanager.js | 6 ++++-- packages/concerto-core/test/decoratormanager.js | 8 ++++++++ packages/concerto-core/types/lib/decoratormanager.d.ts | 6 +++--- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/concerto-core/api.txt b/packages/concerto-core/api.txt index 668b82c32..9a2f1cc05 100644 --- a/packages/concerto-core/api.txt +++ b/packages/concerto-core/api.txt @@ -57,7 +57,7 @@ class Concerto { class DecoratorManager { + ModelManager decorateModels(ModelManager,decoratorCommandSet,object?,boolean?,boolean?) + void validateCommand(ModelManager,command) - + Boolean falsyOrEqual(string|,string[]) + + Boolean falsyOrEqual(string|,string|) + void applyDecorator(decorated,string,newDecorator) + void executeCommand(string,declaration,command) } diff --git a/packages/concerto-core/changelog.txt b/packages/concerto-core/changelog.txt index 7c1f06288..0f4e3512b 100644 --- a/packages/concerto-core/changelog.txt +++ b/packages/concerto-core/changelog.txt @@ -24,7 +24,7 @@ # Note that the latest public API is documented using JSDocs and is available in api.txt. # -Version 3.12.5 {ea967f943046b2792fe3863943a6b2ba} 2023-09-08 +Version 3.12.5 {ced48c7ab94de207be87584468517f3e} 2023-09-08 - Update DecoratorManager to support multiple value compare Version 3.12.4 {7738d5490ea8438677e1d21d704bb5aa} 2023-08-31 diff --git a/packages/concerto-core/lib/decoratormanager.js b/packages/concerto-core/lib/decoratormanager.js index 38ab0d405..b2fb1678a 100644 --- a/packages/concerto-core/lib/decoratormanager.js +++ b/packages/concerto-core/lib/decoratormanager.js @@ -172,11 +172,13 @@ class DecoratorManager { * Compares two values. If the first argument is falsy * the function returns true. * @param {string | null} test the value to test (lhs) - * @param {string[]} values the values to compare (rhs) + * @param {string|string[]} values the values to compare (rhs) * @returns {Boolean} true if the lhs is falsy or values.includes(test) */ static falsyOrEqual(test, values) { - return test ? values.includes(test) : true; + return test + ? Array.isArray(values) ? values.includes(test) : test === values + : true; } /** diff --git a/packages/concerto-core/test/decoratormanager.js b/packages/concerto-core/test/decoratormanager.js index 7c2d21ca9..68186522f 100644 --- a/packages/concerto-core/test/decoratormanager.js +++ b/packages/concerto-core/test/decoratormanager.js @@ -44,9 +44,17 @@ describe('DecoratorManager', () => { DecoratorManager.falsyOrEqual( 'one', 'one').should.be.true; }); + it('should match token', async function() { + DecoratorManager.falsyOrEqual( 'one', ['one']).should.be.true; + }); + it('should not match token', async function() { DecoratorManager.falsyOrEqual( 'one', 'two').should.be.false; }); + + it('should not match token', async function() { + DecoratorManager.falsyOrEqual( 'one', ['two']).should.be.false; + }); }); describe('#decorateModels', function() { diff --git a/packages/concerto-core/types/lib/decoratormanager.d.ts b/packages/concerto-core/types/lib/decoratormanager.d.ts index 0b7e3d6e1..e881e0932 100644 --- a/packages/concerto-core/types/lib/decoratormanager.d.ts +++ b/packages/concerto-core/types/lib/decoratormanager.d.ts @@ -31,10 +31,10 @@ declare class DecoratorManager { * Compares two values. If the first argument is falsy * the function returns true. * @param {string | null} test the value to test (lhs) - * @param {string} value the value to compare (rhs) - * @returns {Boolean} true if the lhs is falsy or test === value + * @param {string|string[]} values the values to compare (rhs) + * @returns {Boolean} true if the lhs is falsy or values.includes(test) */ - static falsyOrEqual(test: string | null, value: string): boolean; + static falsyOrEqual(test: string | null, values: string | string[]): boolean; /** * Applies a decorator to a decorated model element. * @param {*} decorated the type to apply the decorator to