diff --git a/package-lock.json b/package-lock.json index acf03a1..5f9094b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/resource", - "version": "5.1.0", + "version": "5.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/resource", - "version": "5.1.0", + "version": "5.2.0", "license": "MIT", "devDependencies": { "@athenna/artisan": "^5.7.0", diff --git a/package.json b/package.json index 8756c0c..8461446 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@athenna/resource", - "version": "5.1.0", - "description": "📩 Add transformation layers between your application data transfer.", + "version": "5.2.0", + "description": "Add transformation layers between your application data transfer.", "license": "MIT", "author": "João Lenon ", "bugs": "https://github.com/AthennaIO/Resource/issues", diff --git a/src/resource/BaseResource.ts b/src/resource/BaseResource.ts index 276fb0b..cf96bbe 100644 --- a/src/resource/BaseResource.ts +++ b/src/resource/BaseResource.ts @@ -16,7 +16,8 @@ export abstract class BaseResource { * with the `schema()` method. We always use array * values to standardize iterations, maps, etc. */ - private readonly items: I[] + // TODO Convert to symbol + private items: I[] /** * Indicates if the item received in the constructor @@ -48,4 +49,25 @@ export abstract class BaseResource { return this.isArray ? transformed : transformed[0] } + + /** + * Change the value of an item inside your resource. + * If your resource is an array, all keys in the array will + * be changed. + */ + public setValue(key: string, value: any) { + if (this.isArray) { + this.items = this.items.map(item => { + item[key] = value + + return item + }) + + return this + } + + this.items[key] = value + + return this + } }