@thisisagile/easy
Advanced tools
Comparing version 1.8.2 to 1.8.3
import { Id, Json, JsonValue } from "../types"; | ||
import { Query } from "./Query"; | ||
import { List } from '../utils'; | ||
import { List } from '../types/List'; | ||
export interface Gateway { | ||
@@ -5,0 +5,0 @@ all(): Promise<List<Json>>; |
@@ -0,4 +1,14 @@ | ||
import { Json, Result } from '../types'; | ||
import { HttpStatus } from './HttpStatus'; | ||
export declare class EasyResponse { | ||
constructor(); | ||
get data(): void; | ||
readonly content?: any; | ||
constructor(content?: any); | ||
get data(): { | ||
items: Json[]; | ||
itemCount: number; | ||
}; | ||
get error(): { | ||
errors: Result[]; | ||
code: HttpStatus; | ||
}; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EasyResponse = void 0; | ||
const HttpStatus_1 = require("./HttpStatus"); | ||
class EasyResponse { | ||
constructor() { } | ||
get data() { return; } | ||
constructor(content) { | ||
this.content = content; | ||
} | ||
get data() { | ||
var _a, _b; | ||
return { | ||
items: (_a = this.content) === null || _a === void 0 ? void 0 : _a.data, | ||
itemCount: (_b = this.content) === null || _b === void 0 ? void 0 : _b.data.length | ||
}; | ||
} | ||
; | ||
get error() { | ||
var _a; | ||
return { | ||
errors: (_a = this.content) === null || _a === void 0 ? void 0 : _a.errors, | ||
code: HttpStatus_1.HttpStatus.BadRequest | ||
}; | ||
} | ||
; | ||
} | ||
exports.EasyResponse = EasyResponse; | ||
//# sourceMappingURL=EasyResponse.js.map |
@@ -1,4 +0,4 @@ | ||
import { List } from '../utils'; | ||
import { Uri } from '../types'; | ||
import { HttpVerb } from './HttpVerb'; | ||
import { List } from '../types/List'; | ||
export declare const route: (uri: Uri) => ClassDecorator; | ||
@@ -5,0 +5,0 @@ declare class Router { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.router = exports.route = void 0; | ||
const utils_1 = require("../utils"); | ||
exports.route = (uri) => (subject) => { utils_1.meta(subject).set('route', uri); }; | ||
const types_1 = require("../types"); | ||
exports.route = (uri) => (subject) => { types_1.meta(subject).set('route', uri); }; | ||
class Router { | ||
@@ -10,6 +10,5 @@ constructor(resource) { | ||
} | ||
get route() { return utils_1.meta(this.resource).get('route'); } | ||
get route() { return types_1.meta(this.resource).get('route'); } | ||
get verbs() { | ||
return utils_1.meta(this.resource).properties() | ||
.filter(p => p.get('verb')) | ||
return types_1.meta(this.resource).properties('verb') | ||
.map(p => ({ verb: p.get('verb').verb, f: () => p.property })); | ||
@@ -16,0 +15,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.del = exports.post = exports.patch = exports.put = exports.get = void 0; | ||
const utils_1 = require("../utils"); | ||
const HttpVerb_1 = require("./HttpVerb"); | ||
const HttpStatus_1 = require("./HttpStatus"); | ||
const verb = (v) => (subject, property) => { utils_1.meta(subject).property(property).set('verb', v); }; | ||
const types_1 = require("../types"); | ||
const verb = (v) => (subject, property) => { types_1.meta(subject).property(property).set('verb', v); }; | ||
exports.get = (onOk = HttpStatus_1.HttpStatus.Ok, onError = HttpStatus_1.HttpStatus.NotFound) => verb({ verb: HttpVerb_1.HttpVerb.Get, onOk, onError }); | ||
@@ -9,0 +9,0 @@ exports.put = (onOk = HttpStatus_1.HttpStatus.Ok, onError = HttpStatus_1.HttpStatus.BadRequest) => verb({ verb: HttpVerb_1.HttpVerb.Put, onOk, onError }); |
@@ -1,2 +0,4 @@ | ||
import { Code, Id } from "./Id"; | ||
import { Code, Id } from './Id'; | ||
import { List } from './List'; | ||
import { Get } from './Constructor'; | ||
export declare abstract class Enum { | ||
@@ -7,3 +9,5 @@ readonly name: string; | ||
constructor(name: string, id?: Id, code?: Code); | ||
static all<E extends Enum>(): List<E>; | ||
static byId<E extends Enum>(id: Id, alt?: Get<E>): E; | ||
} | ||
export declare const isEnum: (e?: unknown) => e is Enum; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isEnum = exports.Enum = void 0; | ||
const IsA_1 = require("./IsA"); | ||
const Meta_1 = require("./Meta"); | ||
const Is_1 = require("./Is"); | ||
const Constructor_1 = require("./Constructor"); | ||
class Enum { | ||
@@ -10,5 +14,12 @@ constructor(name, id = name.toLowerCase(), code = id) { | ||
} | ||
static all() { | ||
return Meta_1.meta(this).values().filter((e) => exports.isEnum(e)); | ||
} | ||
static byId(id, alt) { | ||
var _a; | ||
return (_a = Meta_1.meta(this).values().first((e) => exports.isEnum(e) && e.id === id)) !== null && _a !== void 0 ? _a : Constructor_1.ofGet(alt); | ||
} | ||
} | ||
exports.Enum = Enum; | ||
exports.isEnum = (e) => e instanceof Enum; | ||
exports.isEnum = (e) => Is_1.isDefined(e) && (e instanceof Enum) && IsA_1.isAn(e, 'name', 'id', 'code'); | ||
//# sourceMappingURL=Enum.js.map |
export declare type Id = string | number; | ||
export declare type Code = string | number; | ||
export declare const newId: () => Id; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.newId = void 0; | ||
const uuid_1 = require("uuid"); | ||
exports.newId = () => uuid_1.v4(); | ||
//# sourceMappingURL=Id.js.map |
@@ -7,2 +7,3 @@ export * from "./Constructor"; | ||
export * from "./Json"; | ||
export * from "./Meta"; | ||
export * from "./Result"; | ||
@@ -9,0 +10,0 @@ export * from "./Results"; |
@@ -19,2 +19,3 @@ "use strict"; | ||
__exportStar(require("./Json"), exports); | ||
__exportStar(require("./Meta"), exports); | ||
__exportStar(require("./Result"), exports); | ||
@@ -21,0 +22,0 @@ __exportStar(require("./Results"), exports); |
@@ -11,3 +11,2 @@ "use strict"; | ||
exports.isFunction = (o) => exports.isDefined(o) && typeof o === 'function'; | ||
// export const isFunction = (o?: unknown): o is Function => isDefined(o) && o instanceof Function; | ||
exports.isArray = (o) => exports.isDefined(o) && o instanceof Array; | ||
@@ -14,0 +13,0 @@ exports.isInstance = (ctor, o) => exports.isFunction(ctor) && o instanceof ctor; |
@@ -1,2 +0,1 @@ | ||
import { List } from '../utils'; | ||
export declare type Segment = { | ||
@@ -13,2 +12,6 @@ key: string; | ||
}; | ||
declare type Prop = { | ||
segment: Segment; | ||
value: unknown; | ||
}; | ||
export declare class Uri { | ||
@@ -21,6 +24,3 @@ readonly segments: Segment[]; | ||
readonly resource: Segment; | ||
constructor(segments: Segment[], props?: List<{ | ||
segment: Segment; | ||
value: unknown; | ||
}>); | ||
constructor(segments: Segment[], props?: import("./List").List<Prop>); | ||
get route(): string; | ||
@@ -33,1 +33,2 @@ get complete(): string; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Uri = exports.uri = void 0; | ||
const utils_1 = require("../utils"); | ||
const Is_1 = require("./Is"); | ||
const List_1 = require("./List"); | ||
exports.uri = { | ||
@@ -24,4 +24,5 @@ host: (key) => ({ | ||
}; | ||
const parse = (route, p) => route.replace(p.segment.segment, p.value.toString()); | ||
class Uri { | ||
constructor(segments, props = utils_1.list()) { | ||
constructor(segments, props = List_1.list()) { | ||
this.segments = segments; | ||
@@ -42,5 +43,5 @@ this.props = props; | ||
var _a; | ||
const route = this.props.reduce((r, p) => r.replace(p.segment.segment, p.value.toString()), this.complete); | ||
const route = this.props.reduce((r, p) => parse(r, p), this.complete); | ||
const q = (_a = this.props.mapDefined(p => { var _a, _b; return ((_a = p.segment) === null || _a === void 0 ? void 0 : _a.query) ? (_b = p.segment) === null || _b === void 0 ? void 0 : _b.query(p.value) : undefined; })) === null || _a === void 0 ? void 0 : _a.join('&'); | ||
this.props = utils_1.list(); | ||
this.props = List_1.list(); | ||
return Is_1.isNotEmpty(q) ? `${route}?${q}` : route; | ||
@@ -47,0 +48,0 @@ } |
@@ -1,5 +0,3 @@ | ||
export * from "./Array"; | ||
export * from "../types/Array"; | ||
export * from "./Case"; | ||
export * from './List'; | ||
export * from "./Meta"; | ||
export * from "./Promise"; |
@@ -13,7 +13,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./Array"), exports); | ||
__exportStar(require("../types/Array"), exports); | ||
__exportStar(require("./Case"), exports); | ||
__exportStar(require("./List"), exports); | ||
__exportStar(require("./Meta"), exports); | ||
__exportStar(require("./Promise"), exports); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.lte = exports.lt = exports.gte = exports.gt = exports.inList = exports.includes = exports.valid = exports.required = exports.defined = exports.constraint = void 0; | ||
const utils_1 = require("../utils"); | ||
const types_1 = require("../types"); | ||
exports.constraint = (c, message) => (subject, property) => { | ||
utils_1.meta(subject).property(property).set('constraint', { property, constraint: c, message }); | ||
types_1.meta(subject).property(property).set('constraint', { property, constraint: c, message }); | ||
}; | ||
@@ -9,0 +8,0 @@ exports.defined = (message) => exports.constraint(v => types_1.isDefined(v), message !== null && message !== void 0 ? message : '$property must be defined.'); |
@@ -5,3 +5,2 @@ "use strict"; | ||
const types_1 = require("../types"); | ||
const utils_1 = require("../utils"); | ||
const When_1 = require("./When"); | ||
@@ -15,3 +14,3 @@ const parse = (subject, v) => types_1.result(v.message.toString() | ||
? types_1.results('Object can not be validated') | ||
: utils_1.meta(subject).keys('constraint') | ||
: types_1.meta(subject).keys('constraint') | ||
.mapDefined(v => !v.constraint(subject[v.property]) ? parse(subject, v) : undefined) | ||
@@ -18,0 +17,0 @@ .reduce((rs, r) => rs.add(r), types_1.results()); |
{ | ||
"name": "@thisisagile/easy", | ||
"version": "1.8.2", | ||
"version": "1.8.3", | ||
"description": "Straightforward library for building domain-driven microservice architectures", | ||
@@ -35,2 +35,3 @@ "author": "Sander Hoogendoorn", | ||
"@types/jest": "^26.0.15", | ||
"@types/uuid": "^8.3.0", | ||
"jest": "^26.6.1", | ||
@@ -41,2 +42,3 @@ "jest-junit": "^12.0.0", | ||
"semantic-release": "^17.2.2", | ||
"uuid": "^8.3.1", | ||
"ts-jest": "^26.4.3", | ||
@@ -43,0 +45,0 @@ "typescript": "4.0.5" |
import { Id, Json, JsonValue } from "../types"; | ||
import { Query } from "./Query"; | ||
import { List } from '../utils'; | ||
import { List } from '../types/List'; | ||
@@ -5,0 +5,0 @@ export interface Gateway { |
@@ -0,6 +1,22 @@ | ||
import { Json, Result } from '../types'; | ||
import { HttpStatus } from './HttpStatus'; | ||
export class EasyResponse { | ||
constructor() {} | ||
get data() { return } | ||
constructor(readonly content?: any) {} | ||
get data(): { items: Json[], itemCount: number } { | ||
return { | ||
items: this.content?.data, | ||
itemCount: this.content?.data.length | ||
} | ||
}; | ||
get error(): { errors: Result[], code: HttpStatus } { | ||
return { | ||
errors: this.content?.errors, | ||
code: HttpStatus.BadRequest | ||
} | ||
}; | ||
} |
@@ -1,5 +0,5 @@ | ||
import { List, meta } from '../utils'; | ||
import { Uri } from '../types'; | ||
import { meta, Uri } from '../types'; | ||
import { HttpVerb } from './HttpVerb'; | ||
import { Verb } from './Verb'; | ||
import { List } from '../types/List'; | ||
@@ -15,4 +15,3 @@ export const route = (uri: Uri): ClassDecorator => | ||
get verbs(): List<{ verb: HttpVerb, f: Function }> { | ||
return meta(this.resource).properties() | ||
.filter(p => p.get('verb')) | ||
return meta(this.resource).properties('verb') | ||
.map(p => ({ verb: p.get<Verb>('verb').verb, f: () => p.property })); | ||
@@ -19,0 +18,0 @@ } |
@@ -1,4 +0,4 @@ | ||
import { meta } from '../utils'; | ||
import { HttpVerb } from './HttpVerb'; | ||
import { HttpStatus } from './HttpStatus'; | ||
import { meta } from '../types'; | ||
@@ -5,0 +5,0 @@ export type Verb = {verb: HttpVerb, onOk: HttpStatus, onError: HttpStatus}; |
@@ -1,7 +0,20 @@ | ||
import { Code, Id } from "./Id"; | ||
import { Code, Id } from './Id'; | ||
import { List } from './List'; | ||
import { isAn } from './IsA'; | ||
import { meta } from './Meta'; | ||
import { isDefined } from './Is'; | ||
import { Get, ofGet } from './Constructor'; | ||
export abstract class Enum { | ||
constructor(readonly name: string, readonly id: Id = name.toLowerCase(), readonly code: Code = id) {} | ||
static all<E extends Enum>(): List<E> { | ||
return meta(this).values().filter((e: unknown) => isEnum(e)); | ||
} | ||
static byId<E extends Enum>(id: Id, alt?: Get<E>): E { | ||
return meta(this).values().first((e: unknown) => isEnum(e) && e.id === id) ?? ofGet(alt); | ||
} | ||
} | ||
export const isEnum = (e?: unknown): e is Enum => e instanceof Enum; | ||
export const isEnum = (e?: unknown): e is Enum => isDefined(e) && (e instanceof Enum) && isAn<Enum>(e, 'name', 'id', 'code'); |
@@ -0,2 +1,6 @@ | ||
import { v4 as uuid } from "uuid"; | ||
export type Id = string | number; | ||
export type Code = string | number; | ||
export const newId = (): Id => uuid(); |
@@ -7,2 +7,3 @@ export * from "./Constructor"; | ||
export * from "./Json"; | ||
export * from "./Meta"; | ||
export * from "./Result"; | ||
@@ -9,0 +10,0 @@ export * from "./Results"; |
@@ -17,4 +17,2 @@ import { Constructor } from './Constructor'; | ||
// export const isFunction = (o?: unknown): o is Function => isDefined(o) && o instanceof Function; | ||
export const isArray = <T = any>(o?: unknown): o is Array<T> => isDefined(o) && o instanceof Array; | ||
@@ -27,1 +25,2 @@ | ||
export const isPrimitive = (o?: unknown): boolean => (o !== null) && !isObject(o) && !isFunction(o) && !isArray(o); | ||
@@ -1,3 +0,3 @@ | ||
import { list, List } from '../utils'; | ||
import { isNotEmpty } from './Is'; | ||
import { list } from './List'; | ||
@@ -29,3 +29,6 @@ export type Segment = { key: string, segment?: string, query?: (value: unknown) => string }; | ||
type Prop = { segment: Segment, value: unknown }; | ||
const parse = (route: string, p: Prop): string => route.replace(p.segment.segment, p.value.toString()); | ||
export class Uri { | ||
@@ -37,3 +40,3 @@ static readonly id = uri.path('id'); | ||
constructor(readonly segments: Segment[], private props: List<{ segment: Segment, value: unknown }> = list()) {} | ||
constructor(readonly segments: Segment[], private props = list<Prop>()) {} | ||
@@ -50,5 +53,5 @@ get route(): string { return ['', ...this.segments.map(s => s.segment)].join('/'); } | ||
toString(): string { | ||
const route = this.props.reduce((r, p) => r.replace(p.segment.segment, p.value.toString()), this.complete); | ||
const route = this.props.reduce((r: string, p: Prop) => parse(r, p), this.complete); | ||
const q = this.props.mapDefined(p => p.segment?.query ? p.segment?.query(p.value) : undefined)?.join('&'); | ||
this.props = list(); | ||
this.props = list<Prop>(); | ||
return isNotEmpty(q) ? `${route}?${q}` : route; | ||
@@ -55,0 +58,0 @@ } |
@@ -1,5 +0,3 @@ | ||
export * from "./Array"; | ||
export * from "../types/Array"; | ||
export * from "./Case"; | ||
export * from './List'; | ||
export * from "./Meta"; | ||
export * from "./Promise"; |
@@ -1,3 +0,2 @@ | ||
import { meta } from '../utils'; | ||
import { isDefined, isIn, isString, isValidatable, Text } from '../types'; | ||
import { isDefined, isIn, isString, isValidatable, meta, Text } from '../types'; | ||
@@ -4,0 +3,0 @@ export type Constraint = (value: unknown) => boolean; |
@@ -1,3 +0,2 @@ | ||
import { isDefined, result, Result, results, Results, Text } from '../types'; | ||
import { meta } from '../utils'; | ||
import { isDefined, meta, result, Result, results, Results, Text } from '../types'; | ||
import { Constraint } from './Contraints'; | ||
@@ -4,0 +3,0 @@ import { when } from './When'; |
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
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
92397
1347
11