@piggly/ddd-toolkit
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -7,7 +7,7 @@ import BaseEntity from './Entity'; | ||
*/ | ||
export default class CollectionOfEntity<Entity extends BaseEntity<any, any>> { | ||
export default class CollectionOfEntity<Entity extends BaseEntity<any, any>, ID extends EntityID<any> = EntityID<any>> { | ||
/** | ||
* An array of entities. | ||
* | ||
* @type {Entity[]} | ||
* @type {Array<Entity>} | ||
* @private | ||
@@ -22,3 +22,3 @@ * @memberof CollectionOfEntity | ||
* | ||
* @param {Map<EntityID<any>, Entity>} [initial] | ||
* @param {Map<ID, Entity>} [initial] | ||
* @public | ||
@@ -30,7 +30,7 @@ * @constructor | ||
*/ | ||
constructor(initial?: Map<EntityID<any>, Entity>); | ||
constructor(initial?: Map<ID, Entity>); | ||
/** | ||
* Add an array of entities to the collection. | ||
* | ||
* @param {Entity[]} entities | ||
* @param {Array<Entity>} entities | ||
* @returns {this} | ||
@@ -43,3 +43,3 @@ * @public | ||
*/ | ||
addMany(entities: Entity[]): this; | ||
addMany(entities: Array<Entity>): this; | ||
/** | ||
@@ -66,3 +66,3 @@ * Add an entity to the collection. | ||
*/ | ||
remove(id: EntityID<any>): this; | ||
remove(id: ID): this; | ||
/** | ||
@@ -78,3 +78,3 @@ * Check if the collection has an entity by its id. | ||
*/ | ||
has(id: EntityID<any>): boolean; | ||
has(id: ID): boolean; | ||
/** | ||
@@ -90,3 +90,3 @@ * Check if the collection has all entities. | ||
*/ | ||
hasAll(ids: EntityID<any>[]): boolean; | ||
hasAll(ids: Array<ID>): boolean; | ||
/** | ||
@@ -102,3 +102,3 @@ * Check if the collection has any of entities. | ||
*/ | ||
hasAny(ids: EntityID<any>[]): boolean; | ||
hasAny(ids: Array<ID>): boolean; | ||
/** | ||
@@ -114,3 +114,3 @@ * Get an entity by its id from the collection. | ||
*/ | ||
get(id: EntityID<any>): Entity | undefined; | ||
get(id: ID): Entity | undefined; | ||
/** | ||
@@ -126,7 +126,7 @@ * Find an entity by its content from the collection. | ||
*/ | ||
find(id: EntityID<any>): Entity | undefined; | ||
find(id: ID): Entity | undefined; | ||
/** | ||
* Return the entities as an array. | ||
* | ||
* @returns {Entity[]} | ||
* @returns {Array<Entity>} | ||
* @public | ||
@@ -137,4 +137,25 @@ * @memberof CollectionOfEntity | ||
*/ | ||
get arrayOf(): Entity[]; | ||
get arrayOf(): Array<Entity>; | ||
/** | ||
* Return the entities as an array. | ||
* Alias to `arrayOf`. | ||
* | ||
* @returns {Array<Entity>} | ||
* @public | ||
* @memberof CollectionOfEntity | ||
* @since 2.1.0 | ||
* @author Caique Araujo <caique@piggly.com.br> | ||
*/ | ||
get entities(): Array<Entity>; | ||
/** | ||
* Return the ids as an array. | ||
* | ||
* @returns {Array<ID>} | ||
* @public | ||
* @memberof CollectionOfEntity | ||
* @since 2.1.0 | ||
* @author Caique Araujo <caique@piggly.com.br> | ||
*/ | ||
get ids(): Array<ID>; | ||
/** | ||
* Return the number of entities. | ||
@@ -141,0 +162,0 @@ * |
@@ -11,3 +11,3 @@ "use strict"; | ||
* | ||
* @type {Entity[]} | ||
* @type {Array<Entity>} | ||
* @private | ||
@@ -22,3 +22,3 @@ * @memberof CollectionOfEntity | ||
* | ||
* @param {Map<EntityID<any>, Entity>} [initial] | ||
* @param {Map<ID, Entity>} [initial] | ||
* @public | ||
@@ -36,3 +36,3 @@ * @constructor | ||
* | ||
* @param {Entity[]} entities | ||
* @param {Array<Entity>} entities | ||
* @returns {this} | ||
@@ -148,3 +148,3 @@ * @public | ||
* | ||
* @returns {Entity[]} | ||
* @returns {Array<Entity>} | ||
* @public | ||
@@ -159,2 +159,27 @@ * @memberof CollectionOfEntity | ||
/** | ||
* Return the entities as an array. | ||
* Alias to `arrayOf`. | ||
* | ||
* @returns {Array<Entity>} | ||
* @public | ||
* @memberof CollectionOfEntity | ||
* @since 2.1.0 | ||
* @author Caique Araujo <caique@piggly.com.br> | ||
*/ | ||
get entities() { | ||
return this.arrayOf; | ||
} | ||
/** | ||
* Return the ids as an array. | ||
* | ||
* @returns {Array<ID>} | ||
* @public | ||
* @memberof CollectionOfEntity | ||
* @since 2.1.0 | ||
* @author Caique Araujo <caique@piggly.com.br> | ||
*/ | ||
get ids() { | ||
return Array.from(this._items.keys()); | ||
} | ||
/** | ||
* Return the number of entities. | ||
@@ -161,0 +186,0 @@ * |
@@ -8,2 +8,3 @@ export { default as Entity } from './Entity'; | ||
export { default as CollectionOfValueObjects } from './CollectionOfValueObjects'; | ||
export { default as CollectionOfRelatedEntity } from './CollectionOfRelatedEntity'; | ||
export { default as SchemaValidator } from './SchemaValidator'; | ||
@@ -10,0 +11,0 @@ export { default as Adapter } from './Adapter'; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InvalidSchemaError = exports.UseCase = exports.ServiceProvider = exports.InfraService = exports.ApplicationService = exports.DomainService = exports.Service = exports.DomainError = exports.DomainEvent = exports.Adapter = exports.SchemaValidator = exports.CollectionOfValueObjects = exports.CollectionOfEntity = exports.AggregateRoot = exports.Result = exports.ValueObject = exports.EntityID = exports.Entity = void 0; | ||
exports.InvalidSchemaError = exports.UseCase = exports.ServiceProvider = exports.InfraService = exports.ApplicationService = exports.DomainService = exports.Service = exports.DomainError = exports.DomainEvent = exports.Adapter = exports.SchemaValidator = exports.CollectionOfRelatedEntity = exports.CollectionOfValueObjects = exports.CollectionOfEntity = exports.AggregateRoot = exports.Result = exports.ValueObject = exports.EntityID = exports.Entity = void 0; | ||
var Entity_1 = require("./Entity"); | ||
@@ -22,2 +22,4 @@ Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return __importDefault(Entity_1).default; } }); | ||
Object.defineProperty(exports, "CollectionOfValueObjects", { enumerable: true, get: function () { return __importDefault(CollectionOfValueObjects_1).default; } }); | ||
var CollectionOfRelatedEntity_1 = require("./CollectionOfRelatedEntity"); | ||
Object.defineProperty(exports, "CollectionOfRelatedEntity", { enumerable: true, get: function () { return __importDefault(CollectionOfRelatedEntity_1).default; } }); | ||
var SchemaValidator_1 = require("./SchemaValidator"); | ||
@@ -24,0 +26,0 @@ Object.defineProperty(exports, "SchemaValidator", { enumerable: true, get: function () { return __importDefault(SchemaValidator_1).default; } }); |
@@ -0,1 +1,2 @@ | ||
import type { Entity as BaseEntity, EntityID } from '../core'; | ||
export type PaginateQuery = { | ||
@@ -17,1 +18,5 @@ page: number; | ||
} | ||
export type RelatedEntity<ID extends EntityID<any>, Entity extends BaseEntity<any, any>> = { | ||
id: ID; | ||
entity: Entity | null; | ||
}; |
@@ -7,7 +7,7 @@ import BaseEntity from './Entity'; | ||
*/ | ||
export default class CollectionOfEntity<Entity extends BaseEntity<any, any>> { | ||
export default class CollectionOfEntity<Entity extends BaseEntity<any, any>, ID extends EntityID<any> = EntityID<any>> { | ||
/** | ||
* An array of entities. | ||
* | ||
* @type {Entity[]} | ||
* @type {Array<Entity>} | ||
* @private | ||
@@ -22,3 +22,3 @@ * @memberof CollectionOfEntity | ||
* | ||
* @param {Map<EntityID<any>, Entity>} [initial] | ||
* @param {Map<ID, Entity>} [initial] | ||
* @public | ||
@@ -30,7 +30,7 @@ * @constructor | ||
*/ | ||
constructor(initial?: Map<EntityID<any>, Entity>); | ||
constructor(initial?: Map<ID, Entity>); | ||
/** | ||
* Add an array of entities to the collection. | ||
* | ||
* @param {Entity[]} entities | ||
* @param {Array<Entity>} entities | ||
* @returns {this} | ||
@@ -43,3 +43,3 @@ * @public | ||
*/ | ||
addMany(entities: Entity[]): this; | ||
addMany(entities: Array<Entity>): this; | ||
/** | ||
@@ -66,3 +66,3 @@ * Add an entity to the collection. | ||
*/ | ||
remove(id: EntityID<any>): this; | ||
remove(id: ID): this; | ||
/** | ||
@@ -78,3 +78,3 @@ * Check if the collection has an entity by its id. | ||
*/ | ||
has(id: EntityID<any>): boolean; | ||
has(id: ID): boolean; | ||
/** | ||
@@ -90,3 +90,3 @@ * Check if the collection has all entities. | ||
*/ | ||
hasAll(ids: EntityID<any>[]): boolean; | ||
hasAll(ids: Array<ID>): boolean; | ||
/** | ||
@@ -102,3 +102,3 @@ * Check if the collection has any of entities. | ||
*/ | ||
hasAny(ids: EntityID<any>[]): boolean; | ||
hasAny(ids: Array<ID>): boolean; | ||
/** | ||
@@ -114,3 +114,3 @@ * Get an entity by its id from the collection. | ||
*/ | ||
get(id: EntityID<any>): Entity | undefined; | ||
get(id: ID): Entity | undefined; | ||
/** | ||
@@ -126,7 +126,7 @@ * Find an entity by its content from the collection. | ||
*/ | ||
find(id: EntityID<any>): Entity | undefined; | ||
find(id: ID): Entity | undefined; | ||
/** | ||
* Return the entities as an array. | ||
* | ||
* @returns {Entity[]} | ||
* @returns {Array<Entity>} | ||
* @public | ||
@@ -137,4 +137,25 @@ * @memberof CollectionOfEntity | ||
*/ | ||
get arrayOf(): Entity[]; | ||
get arrayOf(): Array<Entity>; | ||
/** | ||
* Return the entities as an array. | ||
* Alias to `arrayOf`. | ||
* | ||
* @returns {Array<Entity>} | ||
* @public | ||
* @memberof CollectionOfEntity | ||
* @since 2.1.0 | ||
* @author Caique Araujo <caique@piggly.com.br> | ||
*/ | ||
get entities(): Array<Entity>; | ||
/** | ||
* Return the ids as an array. | ||
* | ||
* @returns {Array<ID>} | ||
* @public | ||
* @memberof CollectionOfEntity | ||
* @since 2.1.0 | ||
* @author Caique Araujo <caique@piggly.com.br> | ||
*/ | ||
get ids(): Array<ID>; | ||
/** | ||
* Return the number of entities. | ||
@@ -141,0 +162,0 @@ * |
@@ -9,3 +9,3 @@ /** | ||
* | ||
* @type {Entity[]} | ||
* @type {Array<Entity>} | ||
* @private | ||
@@ -20,3 +20,3 @@ * @memberof CollectionOfEntity | ||
* | ||
* @param {Map<EntityID<any>, Entity>} [initial] | ||
* @param {Map<ID, Entity>} [initial] | ||
* @public | ||
@@ -34,3 +34,3 @@ * @constructor | ||
* | ||
* @param {Entity[]} entities | ||
* @param {Array<Entity>} entities | ||
* @returns {this} | ||
@@ -146,3 +146,3 @@ * @public | ||
* | ||
* @returns {Entity[]} | ||
* @returns {Array<Entity>} | ||
* @public | ||
@@ -157,2 +157,27 @@ * @memberof CollectionOfEntity | ||
/** | ||
* Return the entities as an array. | ||
* Alias to `arrayOf`. | ||
* | ||
* @returns {Array<Entity>} | ||
* @public | ||
* @memberof CollectionOfEntity | ||
* @since 2.1.0 | ||
* @author Caique Araujo <caique@piggly.com.br> | ||
*/ | ||
get entities() { | ||
return this.arrayOf; | ||
} | ||
/** | ||
* Return the ids as an array. | ||
* | ||
* @returns {Array<ID>} | ||
* @public | ||
* @memberof CollectionOfEntity | ||
* @since 2.1.0 | ||
* @author Caique Araujo <caique@piggly.com.br> | ||
*/ | ||
get ids() { | ||
return Array.from(this._items.keys()); | ||
} | ||
/** | ||
* Return the number of entities. | ||
@@ -159,0 +184,0 @@ * |
@@ -8,2 +8,3 @@ export { default as Entity } from './Entity'; | ||
export { default as CollectionOfValueObjects } from './CollectionOfValueObjects'; | ||
export { default as CollectionOfRelatedEntity } from './CollectionOfRelatedEntity'; | ||
export { default as SchemaValidator } from './SchemaValidator'; | ||
@@ -10,0 +11,0 @@ export { default as Adapter } from './Adapter'; |
@@ -8,2 +8,3 @@ export { default as Entity } from './Entity'; | ||
export { default as CollectionOfValueObjects } from './CollectionOfValueObjects'; | ||
export { default as CollectionOfRelatedEntity } from './CollectionOfRelatedEntity'; | ||
export { default as SchemaValidator } from './SchemaValidator'; | ||
@@ -10,0 +11,0 @@ export { default as Adapter } from './Adapter'; |
@@ -0,1 +1,2 @@ | ||
import type { Entity as BaseEntity, EntityID } from '../core'; | ||
export type PaginateQuery = { | ||
@@ -17,1 +18,5 @@ page: number; | ||
} | ||
export type RelatedEntity<ID extends EntityID<any>, Entity extends BaseEntity<any, any>> = { | ||
id: ID; | ||
entity: Entity | null; | ||
}; |
{ | ||
"name": "@piggly/ddd-toolkit", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "A bunch of tools to use Model-Driven Design and Domain-Driven Design architecture in a back-end application.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
169669
141
4929