@thisisagile/easy
Advanced tools
Comparing version 1.3.5 to 1.4.0
@@ -1,3 +0,3 @@ | ||
import { Record } from "./Record"; | ||
import { Id } from "../types"; | ||
import { Record } from './Record'; | ||
import { Id } from '../types'; | ||
export declare abstract class Entity extends Record { | ||
@@ -4,0 +4,0 @@ readonly id: Id; |
@@ -1,6 +0,7 @@ | ||
import { Validatable } from "../types"; | ||
import { Json, Validatable } from '../types'; | ||
export declare abstract class Record implements Validatable { | ||
protected readonly state: any; | ||
constructor(state: any); | ||
get isValid(): boolean; | ||
constructor(state: any); | ||
toJSON(): Json; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Record = void 0; | ||
const types_1 = require("../types"); | ||
const validation_1 = require("../validation"); | ||
@@ -10,4 +11,7 @@ class Record { | ||
get isValid() { return validation_1.validate(this).isValid; } | ||
toJSON() { | ||
return types_1.jsonify({ ...this, state: undefined }); | ||
} | ||
} | ||
exports.Record = Record; | ||
//# sourceMappingURL=Record.js.map |
export declare const toArray: <T>(...items: (T | T[])[]) => T[]; | ||
export declare const toReduceDefined: <T>(ts: T[], condition: boolean, t: T) => T[]; | ||
export declare class List<T> extends Array<T> { | ||
} | ||
export declare const array: <T>(...items: (T | T[])[]) => List<T>; | ||
export declare const list: <T>(...items: (T | T[])[]) => List<T>; | ||
export declare const array: <T>(...items: (T | T[])[]) => T[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.list = exports.array = exports.List = exports.toReduceDefined = exports.toArray = void 0; | ||
exports.array = exports.toArray = void 0; | ||
const types_1 = require("../types"); | ||
exports.toArray = (...items) => (items.length > 1) ? items : types_1.isArray(items[0]) ? items[0] : types_1.isDefined(items[0]) ? [items[0]] : []; | ||
exports.toReduceDefined = (ts, condition, t) => condition ? ts.concat(t) : ts; | ||
class List extends Array { | ||
} | ||
exports.List = List; | ||
exports.array = (...items) => new Array(...exports.toArray(...items)); | ||
exports.list = (...items) => new List(...exports.toArray(...items)); | ||
//# sourceMappingURL=Array.js.map |
export * from "./Array"; | ||
export * from "./Case"; | ||
export * from './List'; | ||
export * from "./Meta"; | ||
export * from "./Promise"; |
@@ -15,4 +15,5 @@ "use strict"; | ||
__exportStar(require("./Case"), exports); | ||
__exportStar(require("./List"), exports); | ||
__exportStar(require("./Meta"), exports); | ||
__exportStar(require("./Promise"), exports); | ||
//# sourceMappingURL=index.js.map |
import "reflect-metadata"; | ||
import { List } from './List'; | ||
declare class ClassMeta { | ||
@@ -8,4 +9,4 @@ readonly subject: any; | ||
set: <T>(key: string, value: T) => T; | ||
properties: () => PropertyMeta[]; | ||
keys: <T = any>(key: string) => T[]; | ||
properties: () => List<PropertyMeta>; | ||
keys: <T = any>(key: string) => List<T>; | ||
property: (property: string) => PropertyMeta; | ||
@@ -12,0 +13,0 @@ } |
@@ -6,2 +6,3 @@ "use strict"; | ||
const types_1 = require("../types"); | ||
const List_1 = require("./List"); | ||
class ClassMeta { | ||
@@ -18,3 +19,3 @@ constructor(subject, data) { | ||
}; | ||
this.properties = () => [...Object.getOwnPropertyNames(this.subject), ...Object.getOwnPropertyNames(Object.getPrototypeOf(this.subject))] | ||
this.properties = () => List_1.list([...Object.getOwnPropertyNames(this.subject), ...Object.getOwnPropertyNames(Object.getPrototypeOf(this.subject))]) | ||
.map(p => this.property(p)); | ||
@@ -21,0 +22,0 @@ this.keys = (key) => this.properties().map(p => p.get(key)).filter(v => types_1.isDefined(v)); |
@@ -7,9 +7,6 @@ "use strict"; | ||
const When_1 = require("./When"); | ||
const parse = (subject, v) => { | ||
const message = v.message.toString() | ||
.replace('$property', `property '${v.property}'`) | ||
.replace('$subject', subject.constructor.name) | ||
.replace('$actual', `'${subject[v.property]}'`); | ||
return types_1.result(message, subject.constructor.name, v.property); | ||
}; | ||
const parse = (subject, v) => types_1.result(v.message.toString() | ||
.replace('$subject', subject.constructor.name) | ||
.replace('$property', `property '${v.property}'`) | ||
.replace('$actual', `'${subject[v.property]}'`), subject.constructor.name, v.property); | ||
exports.validate = (subject) => { | ||
@@ -19,3 +16,3 @@ return (!types_1.isDefined(subject)) | ||
: utils_1.meta(subject).keys('constraint') | ||
.reduce((rs, v) => utils_1.toReduceDefined(rs, !v.constraint(subject[v.property]), parse(subject, v)), []) | ||
.mapDefined(v => !v.constraint(subject[v.property]) ? parse(subject, v) : undefined) | ||
.reduce((rs, r) => rs.add(r), types_1.results()); | ||
@@ -22,0 +19,0 @@ }; |
{ | ||
"name": "@thisisagile/easy", | ||
"version": "1.3.5", | ||
"version": "1.4.0", | ||
"description": "Straightforward library for building domain-driven microservice architectures", | ||
@@ -5,0 +5,0 @@ "author": "Sander Hoogendoorn", |
# easy | ||
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=thisisagile_easy&metric=alert_status)](https://sonarcloud.io/dashboard?id=thisisagile_easy) | ||
[![npm package](https://img.shields.io/npm/v/@thisisagile/easy.svg)](https://www.npmjs.com/package/@thisisagile/easy) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) | ||
@@ -4,0 +5,0 @@ |
@@ -1,3 +0,3 @@ | ||
import { Record } from "./Record"; | ||
import { Id } from "../types"; | ||
import { Record } from './Record'; | ||
import { Id } from '../types'; | ||
@@ -4,0 +4,0 @@ export abstract class Entity extends Record { |
@@ -1,9 +0,12 @@ | ||
import {Validatable} from "../types"; | ||
import { Json, jsonify, Validatable } from '../types'; | ||
import { validate } from '../validation'; | ||
export abstract class Record implements Validatable { | ||
constructor(protected readonly state: any) {} | ||
get isValid(): boolean { return validate(this).isValid; } | ||
constructor(protected readonly state: any) {} | ||
toJSON(): Json { | ||
return jsonify({ ...this, state: undefined }); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { isArray, isDefined } from "../types"; | ||
import { isArray, isDefined } from '../types'; | ||
@@ -6,9 +6,2 @@ export const toArray = <T>(...items: (T | T[])[]): T[] => | ||
export const toReduceDefined = <T>(ts: T[], condition: boolean, t: T): T[] => condition ? ts.concat(t) : ts; | ||
export class List<T> extends Array<T> { | ||
} | ||
export const array = <T>(...items: (T | T[])[]): List<T> => new Array<T>(...toArray(...items)); | ||
export const list = <T>(...items: (T | T[])[]): List<T> => new List<T>(...toArray(...items)); | ||
export const array = <T>(...items: (T | T[])[]): Array<T> => new Array<T>(...toArray(...items)); |
export * from "./Array"; | ||
export * from "./Case"; | ||
export * from './List'; | ||
export * from "./Meta"; | ||
export * from "./Promise"; |
import "reflect-metadata"; | ||
import { isDefined } from "../types"; | ||
import { list, List } from './List'; | ||
@@ -14,7 +15,7 @@ class ClassMeta { | ||
properties = (): PropertyMeta[] => | ||
[...Object.getOwnPropertyNames(this.subject), ...Object.getOwnPropertyNames(Object.getPrototypeOf(this.subject))] | ||
properties = (): List<PropertyMeta> => | ||
list([...Object.getOwnPropertyNames(this.subject), ...Object.getOwnPropertyNames(Object.getPrototypeOf(this.subject))]) | ||
.map(p => this.property(p)); | ||
keys = <T = any>(key: string): T[] => | ||
keys = <T = any>(key: string): List<T> => | ||
this.properties().map(p => p.get<T>(key)).filter(v => isDefined(v)); | ||
@@ -21,0 +22,0 @@ |
import { isDefined, result, Result, results, Results, Text } from '../types'; | ||
import { meta, toReduceDefined } from '../utils'; | ||
import { meta } from '../utils'; | ||
import { Constraint } from './Contraints'; | ||
@@ -8,9 +8,8 @@ import { when } from './When'; | ||
const parse = (subject: unknown, v: Validator): Result => { | ||
const message = v.message.toString() | ||
const parse = (subject: unknown, v: Validator): Result => | ||
result(v.message.toString() | ||
.replace('$subject', subject.constructor.name) | ||
.replace('$property', `property '${v.property}'`) | ||
.replace('$subject', subject.constructor.name) | ||
.replace('$actual', `'${(subject as any)[v.property]}'`); | ||
return result(message, subject.constructor.name, v.property); | ||
}; | ||
.replace('$actual', `'${(subject as any)[v.property]}'`), | ||
subject.constructor.name, v.property); | ||
@@ -21,3 +20,3 @@ export const validate = (subject?: unknown): Results => { | ||
: meta(subject).keys<Validator>('constraint') | ||
.reduce((rs, v) => toReduceDefined(rs, !v.constraint((subject as any)[v.property]), parse(subject, v)), []) | ||
.mapDefined(v => !v.constraint((subject as any)[v.property]) ? parse(subject, v) : undefined) | ||
.reduce((rs, r) => rs.add(r), results()); | ||
@@ -24,0 +23,0 @@ }; |
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
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
69136
127
978
23