Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thisisagile/easy

Package Overview
Dependencies
Maintainers
2
Versions
1266
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thisisagile/easy - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

dist/types/Results.d.ts

1

dist/types/index.d.ts

@@ -8,3 +8,4 @@ export * from "./Constructor";

export * from "./Result";
export * from "./Results";
export * from "./Text";
export * from "./Validatable";

@@ -20,4 +20,5 @@ "use strict";

__exportStar(require("./Result"), exports);
__exportStar(require("./Results"), exports);
__exportStar(require("./Text"), exports);
__exportStar(require("./Validatable"), exports);
//# sourceMappingURL=index.js.map

7

dist/types/Result.d.ts

@@ -0,8 +1,9 @@

import { Text } from './Text';
export declare type Result = {
message: string;
message: Text;
domain?: string;
location?: string;
};
export declare const result: (message: string, domain?: string, location?: string) => {
message: string;
export declare const result: (message: Text, domain?: string, location?: string) => {
message: Text;
domain: string;

@@ -9,0 +10,0 @@ location: string;

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 list: <T>(...items: (T | T[])[]) => List<T>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toReduceDefined = exports.toArray = void 0;
exports.list = exports.List = exports.toReduceDefined = 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.list = (...items) => new List(...exports.toArray(...items));
//# sourceMappingURL=Array.js.map

@@ -13,2 +13,2 @@ import { Get, Predicate } from '../types';

}
export declare const choose: <V, O>(value: V) => Case<V, O>;
export declare const choose: <V, Out>(value: V) => Case<V, Out>;
export * from "./Array";
export * from "./Case";
export * from "./Meta";
export * from "./Promise";

@@ -14,3 +14,5 @@ "use strict";

__exportStar(require("./Array"), exports);
__exportStar(require("./Case"), exports);
__exportStar(require("./Meta"), exports);
__exportStar(require("./Promise"), exports);
//# sourceMappingURL=index.js.map
export * from "./Contraints";
export * from "./Results";
export * from "../types/Results";
export * from "./Validate";
export * from "./When";

@@ -14,5 +14,5 @@ "use strict";

__exportStar(require("./Contraints"), exports);
__exportStar(require("./Results"), exports);
__exportStar(require("../types/Results"), exports);
__exportStar(require("./Validate"), exports);
__exportStar(require("./When"), exports);
//# sourceMappingURL=index.js.map

@@ -1,4 +0,3 @@

import { Text } from '../types';
import { Constraint } from "./Contraints";
import { Results } from "./Results";
import { Results, Text } from '../types';
import { Constraint } from './Contraints';
export declare type Validator = {

@@ -5,0 +4,0 @@ property: string;

@@ -6,9 +6,8 @@ "use strict";

const utils_1 = require("../utils");
const Results_1 = require("./Results");
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]}'`);
.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);

@@ -18,8 +17,8 @@ };

return (!types_1.isDefined(subject))
? Results_1.results("Object can not be validated")
: utils_1.meta(subject).keys("constraint")
? types_1.results('Object can not be validated')
: utils_1.meta(subject).keys('constraint')
.reduce((rs, v) => utils_1.toReduceDefined(rs, !v.constraint(subject[v.property]), parse(subject, v)), [])
.reduce((rs, r) => rs.add(r), Results_1.results());
.reduce((rs, r) => rs.add(r), types_1.results());
};
exports.validateReject = (subject) => When_1.when(subject).not.isValid.reject();
//# sourceMappingURL=Validate.js.map

@@ -1,8 +0,7 @@

import { Results } from './Results';
import { Constructor, Text } from '../types';
import { Constructor, Predicate, Results, Text } from '../types';
declare class When<T> {
readonly subject: T;
readonly result: boolean;
private results;
constructor(subject: T, result?: boolean, results?: Results);
readonly invalid: boolean;
private results?;
constructor(subject: T, invalid?: boolean, results?: Results);
get not(): When<T>;

@@ -13,11 +12,11 @@ get isDefined(): When<T>;

get isValid(): When<T>;
clone: (result?: boolean) => When<T>;
isInstance: <U>(c: Constructor<U>) => When<T>;
with: (pred: (t: T) => boolean) => When<T>;
with: (pred: Predicate<T>) => When<T>;
in: (...items: T[]) => When<T>;
is: (item: T) => When<T>;
reject: (message?: Text | Error) => Promise<T>;
reject: (error?: Text | Error) => Promise<T>;
recover: (f: (item: T) => T | Promise<T>) => Promise<T>;
protected clone: (result?: boolean) => When<T>;
}
export declare const when: <T>(subject: T) => When<T>;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.when = void 0;
const Results_1 = require("./Results");
const types_1 = require("../types");

@@ -9,23 +8,21 @@ const Validate_1 = require("./Validate");

class When {
constructor(subject, result = true, results = Results_1.results()) {
constructor(subject, invalid = true, results) {
this.subject = subject;
this.result = result;
this.invalid = invalid;
this.results = results;
this.isInstance = (c) => this.clone(this.invalid === this.subject instanceof c);
this.with = (pred) => this.clone(this.invalid === types_1.ofGet(pred, this.subject));
this.in = (...items) => this.clone(this.invalid === types_1.isIn(this.subject, utils_1.toArray(...items)));
this.is = (item) => this.clone(this.invalid === (this.subject === item));
this.reject = (error) => { var _a; return !this.invalid ? utils_1.resolve(this.subject) : utils_1.reject((_a = this.results) !== null && _a !== void 0 ? _a : error); };
this.recover = (f) => utils_1.resolve(!this.invalid ? this.subject : f(this.subject));
this.clone = (result = true) => new When(this.subject, result, this.results);
this.isInstance = (c) => this.clone(this.result === this.subject instanceof c);
this.with = (pred) => this.clone(this.result === pred(this.subject));
this.in = (...items) => this.clone(this.result === types_1.isIn(this.subject, utils_1.toArray(...items)));
this.is = (item) => this.clone(this.result === (this.subject === item));
this.reject = (message) => !this.result
? Promise.resolve(this.subject)
: Promise.reject(types_1.isError(message) ? message : types_1.isDefined(this.results) ? this.results : Results_1.results(message));
this.recover = (f) => Promise.resolve(!this.result ? this.subject : f(this.subject));
}
get not() { return this.clone(!this.result); }
get isDefined() { return this.clone(this.result === types_1.isDefined(this.subject)); }
get isEmpty() { return this.clone(this.result === types_1.isEmpty(this.subject)); }
get isTrue() { return this.clone(this.result === !!this.subject); }
get not() { return this.clone(!this.invalid); }
get isDefined() { return this.clone(this.invalid === types_1.isDefined(this.subject)); }
get isEmpty() { return this.clone(this.invalid === types_1.isEmpty(this.subject)); }
get isTrue() { return this.clone(this.invalid === !!this.subject); }
get isValid() {
this.results = Validate_1.validate(this.subject);
return this.clone(this.result === this.results.isValid);
return this.clone(this.invalid === this.results.isValid);
}

@@ -32,0 +29,0 @@ }

{
"name": "@thisisagile/easy",
"version": "1.3.1",
"version": "1.3.2",
"description": "Straightforward library for building domain-driven microservice architectures",

@@ -5,0 +5,0 @@ "author": "Sander Hoogendoorn",

@@ -8,3 +8,4 @@ export * from "./Constructor";

export * from "./Result";
export * from "./Results";
export * from "./Text";
export * from "./Validatable";
import { isA } from "./IsA";
import { Text } from './Text';
export type Result = { message: string, domain?: string, location?: string };
export type Result = { message: Text, domain?: string, location?: string };
export const result = (message: string, domain?: string, location?: string) => ({ message, domain, location });
export const result = (message: Text, domain?: string, location?: string) => ({ message, domain, location });
export const isResult = (r?: unknown): r is Result => isA<Result>(r, "message");

@@ -7,1 +7,7 @@ import { isArray, isDefined } from "../types";

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 list = <T>(...items: (T | T[])[]): List<T> => new List(...toArray(...items));

@@ -23,2 +23,2 @@ import { Get, ofGet, Predicate } from '../types';

export const choose = <V, O>(value: V): Case<V, O> => new Case(value);
export const choose = <V, Out>(value: V): Case<V, Out> => new Case(value);
export * from "./Array";
export * from "./Case";
export * from "./Meta";
export * from "./Promise";
export * from "./Contraints";
export * from "./Results";
export * from "../types/Results";
export * from "./Validate";
export * from "./When";

@@ -1,5 +0,4 @@

import { isDefined, result, Result, Text } from '../types';
import { meta, toReduceDefined } from "../utils";
import { Constraint } from "./Contraints";
import { results, Results } from "./Results";
import { isDefined, result, Result, results, Results, Text } from '../types';
import { meta, toReduceDefined } from '../utils';
import { Constraint } from './Contraints';
import { when } from './When';

@@ -11,5 +10,5 @@

const message = v.message.toString()
.replace("$property", `property '${v.property}'`)
.replace("$subject", subject.constructor.name)
.replace("$actual", `'${(subject as any)[v.property]}'`);
.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);

@@ -20,4 +19,4 @@ };

return (!isDefined(subject))
? results("Object can not be validated")
: meta(subject).keys<Validator>("constraint")
? results('Object can not be validated')
: meta(subject).keys<Validator>('constraint')
.reduce((rs, v) => toReduceDefined(rs, !v.constraint((subject as any)[v.property]), parse(subject, v)), [])

@@ -24,0 +23,0 @@ .reduce((rs, r) => rs.add(r), results());

@@ -1,46 +0,43 @@

import { results as res, Results } from './Results';
import { Constructor, isDefined, isEmpty, isError, isIn, Text } from '../types';
import { Constructor, isDefined, isEmpty, isIn, ofGet, Predicate, Results, Text } from '../types';
import { validate } from './Validate';
import { toArray } from '../utils';
import { reject, resolve, toArray } from '../utils';
class When<T> {
constructor(readonly subject: T, readonly result = true, private results: Results = res()) {}
constructor(readonly subject: T, readonly invalid = true, private results?: Results) {}
get not(): When<T> { return this.clone(!this.result); }
get not(): When<T> { return this.clone(!this.invalid); }
get isDefined(): When<T> { return this.clone(this.result === isDefined(this.subject)); }
get isDefined(): When<T> { return this.clone(this.invalid === isDefined(this.subject)); }
get isEmpty(): When<T> { return this.clone(this.result === isEmpty(this.subject)); }
get isEmpty(): When<T> { return this.clone(this.invalid === isEmpty(this.subject)); }
get isTrue(): When<T> { return this.clone(this.result === !!this.subject); }
get isTrue(): When<T> { return this.clone(this.invalid === !!this.subject); }
get isValid(): When<T> {
this.results = validate(this.subject);
return this.clone(this.result === this.results.isValid);
return this.clone(this.invalid === this.results.isValid);
}
clone = (result = true): When<T> => new When(this.subject, result, this.results);
isInstance = <U>(c: Constructor<U>): When<T> =>
this.clone(this.result === this.subject instanceof c);
this.clone(this.invalid === this.subject instanceof c);
with = (pred: (t: T) => boolean): When<T> =>
this.clone(this.result === pred(this.subject));
with = (pred: Predicate<T>): When<T> =>
this.clone(this.invalid === ofGet(pred, this.subject));
in = (...items: T[]): When<T> =>
this.clone(this.result === isIn(this.subject, toArray(...items)));
this.clone(this.invalid === isIn(this.subject, toArray(...items)));
is = (item: T): When<T> =>
this.clone(this.result === (this.subject === item));
this.clone(this.invalid === (this.subject === item));
reject = (message?: Text | Error): Promise<T> =>
!this.result
? Promise.resolve(this.subject)
: Promise.reject(isError(message) ? message : isDefined(this.results) ? this.results : res(message));
reject = (error?: Text | Error): Promise<T> =>
!this.invalid ? resolve(this.subject) : reject(this.results ?? error);
recover = (f: (item: T) => T | Promise<T>): Promise<T> =>
Promise.resolve(!this.result ? this.subject : f(this.subject));
resolve(!this.invalid ? this.subject : f(this.subject));
protected clone = (result = true): When<T> => new When(this.subject, result, this.results);
}
export const when = <T>(subject: T): When<T> => new When<T>(subject);

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc