@thisisagile/easy-service 20.1.2 → 21.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/http/Verb.d.ts +9 -6
- package/dist/http/Verb.js +4 -1
- package/dist/http/Verb.js.map +1 -1
- package/dist/resources/Requires.d.ts +4 -3
- package/dist/resources/Requires.js.map +1 -1
- package/dist/resources/Route.d.ts +5 -3
- package/dist/resources/Route.js.map +1 -1
- package/package.json +3 -3
- package/src/http/Verb.ts +7 -4
- package/src/resources/Requires.ts +2 -1
- package/src/resources/Route.ts +5 -3
package/dist/http/Verb.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { CacheControl
|
|
1
|
+
import { CacheControl } from "@thisisagile/easy";
|
|
2
|
+
import * as ContentType from "@thisisagile/easy/ContentType";
|
|
3
|
+
import * as HttpStatus from "@thisisagile/easy/HttpStatus";
|
|
4
|
+
import * as HttpVerb from "@thisisagile/easy/HttpVerb";
|
|
2
5
|
//#region src/http/Verb.d.ts
|
|
3
6
|
export type VerbOptions = {
|
|
4
|
-
onOk?: HttpStatus;
|
|
5
|
-
onNotFound?: HttpStatus;
|
|
6
|
-
onError?: HttpStatus;
|
|
7
|
-
type?: ContentType;
|
|
7
|
+
onOk?: HttpStatus.Enum;
|
|
8
|
+
onNotFound?: HttpStatus.Enum;
|
|
9
|
+
onError?: HttpStatus.Enum;
|
|
10
|
+
type?: ContentType.Enum;
|
|
8
11
|
cache?: CacheControl;
|
|
9
12
|
};
|
|
10
13
|
export type Verb = {
|
|
11
|
-
verb: HttpVerb;
|
|
14
|
+
verb: HttpVerb.Enum;
|
|
12
15
|
options: VerbOptions;
|
|
13
16
|
};
|
|
14
17
|
export declare const toVerbOptions: (options?: VerbOptions) => Required<VerbOptions>;
|
package/dist/http/Verb.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { CacheControl,
|
|
1
|
+
import { CacheControl, meta } from "@thisisagile/easy";
|
|
2
|
+
import * as ContentType from "@thisisagile/easy/ContentType";
|
|
3
|
+
import * as HttpStatus from "@thisisagile/easy/HttpStatus";
|
|
4
|
+
import * as HttpVerb from "@thisisagile/easy/HttpVerb";
|
|
2
5
|
//#region src/http/Verb.ts
|
|
3
6
|
const toVerbOptions = (options) => ({
|
|
4
7
|
onOk: options?.onOk ?? HttpStatus.Ok,
|
package/dist/http/Verb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Verb.js","names":[],"sources":["../../src/http/Verb.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"Verb.js","names":[],"sources":["../../src/http/Verb.ts"],"sourcesContent":["import * as ContentType from '@thisisagile/easy/ContentType';\nimport * as HttpStatus from '@thisisagile/easy/HttpStatus';\nimport * as HttpVerb from '@thisisagile/easy/HttpVerb';\nimport { meta, CacheControl } from '@thisisagile/easy';\n\nexport type VerbOptions = { onOk?: HttpStatus.Enum; onNotFound?: HttpStatus.Enum; onError?: HttpStatus.Enum; type?: ContentType.Enum; cache?: CacheControl };\nexport type Verb = { verb: HttpVerb.Enum; options: VerbOptions };\n\nexport const toVerbOptions = (options?: VerbOptions): Required<VerbOptions> => ({\n onOk: options?.onOk ?? HttpStatus.Ok,\n onNotFound: options?.onNotFound ?? HttpStatus.NotFound,\n onError: options?.onError ?? HttpStatus.BadRequest,\n type: options?.type ?? ContentType.Json,\n cache: options?.cache ?? CacheControl.disabled(),\n});\n\nconst toVerb =\n <T>(verb: HttpVerb.Enum, options?: VerbOptions): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('verb', { verb, options });\n };\n\nexport const get = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Get, options);\n\nexport const search = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Get, { onNotFound: HttpStatus.Ok, ...options });\n\nexport const put = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Put, options);\n\nexport const patch = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Patch, options);\n\nexport const post = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Post, { onOk: HttpStatus.Created, ...options });\n\nexport const del = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Delete, { onOk: HttpStatus.NoContent, ...options });\n\nexport const stream = (options?: VerbOptions): PropertyDecorator => toVerb(HttpVerb.Get, { type: ContentType.Stream, ...options });\n"],"mappings":";;;;;AAQA,MAAa,iBAAiB,aAAkD;CAC9E,MAAM,SAAS,QAAQ,WAAW;CAClC,YAAY,SAAS,cAAc,WAAW;CAC9C,SAAS,SAAS,WAAW,WAAW;CACxC,MAAM,SAAS,QAAQ,YAAY;CACnC,OAAO,SAAS,SAAS,aAAa,SAAS;AACjD;AAEA,MAAM,UACA,MAAqB,aACxB,SAAkB,aAAoC;CACrD,KAAK,OAAO,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,IAAI,QAAQ;EAAE;EAAM;CAAQ,CAAC;AAChE;AAEF,MAAa,OAAO,YAA6C,OAAO,SAAS,KAAK,OAAO;AAE7F,MAAa,UAAU,YAA6C,OAAO,SAAS,KAAK;CAAE,YAAY,WAAW;CAAI,GAAG;AAAQ,CAAC;AAElI,MAAa,OAAO,YAA6C,OAAO,SAAS,KAAK,OAAO;AAE7F,MAAa,SAAS,YAA6C,OAAO,SAAS,OAAO,OAAO;AAEjG,MAAa,QAAQ,YAA6C,OAAO,SAAS,MAAM;CAAE,MAAM,WAAW;CAAS,GAAG;AAAQ,CAAC;AAEhI,MAAa,OAAO,YAA6C,OAAO,SAAS,QAAQ;CAAE,MAAM,WAAW;CAAW,GAAG;AAAQ,CAAC;AAEnI,MAAa,UAAU,YAA6C,OAAO,SAAS,KAAK;CAAE,MAAM,YAAY;CAAQ,GAAG;AAAQ,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Enum } from "@thisisagile/easy/Scope";
|
|
2
|
+
import { Enum as Enum$1 } from "@thisisagile/easy/UseCase";
|
|
2
3
|
//#region src/resources/Requires.d.ts
|
|
3
4
|
export declare class Requires {
|
|
4
5
|
readonly labCoat: () => PropertyDecorator;
|
|
5
6
|
readonly token: () => PropertyDecorator;
|
|
6
|
-
readonly scope: (scope:
|
|
7
|
-
readonly useCase: (uc:
|
|
7
|
+
readonly scope: (scope: Enum) => PropertyDecorator;
|
|
8
|
+
readonly useCase: (uc: Enum$1) => PropertyDecorator;
|
|
8
9
|
}
|
|
9
10
|
export declare const requires: Requires;
|
|
10
11
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Requires.js","names":[],"sources":["../../src/resources/Requires.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Requires.js","names":[],"sources":["../../src/resources/Requires.ts"],"sourcesContent":["import type { Enum as Scope } from '@thisisagile/easy/Scope';\nimport type { Enum as UseCase } from '@thisisagile/easy/UseCase';\nimport { meta } from '@thisisagile/easy';\n\nexport class Requires {\n readonly labCoat =\n (): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('labCoat', true);\n };\n\n readonly token =\n (): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('token', true);\n };\n\n readonly scope =\n (scope: Scope): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('token', true);\n meta(subject).property(property).set('scope', scope);\n };\n\n readonly useCase =\n (uc: UseCase): PropertyDecorator =>\n (subject: unknown, property: string | symbol): void => {\n meta(subject).property(property).set('token', true);\n meta(subject).property(property).set('uc', uc);\n };\n}\n\nexport const requires = new Requires();\n"],"mappings":";;AAIA,IAAa,WAAb,MAAsB;CACpB,iBAEG,SAAkB,aAAoC;EACrD,KAAK,OAAO,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,IAAI,WAAW,IAAI;CACtD;CAEF,eAEG,SAAkB,aAAoC;EACrD,KAAK,OAAO,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,IAAI,SAAS,IAAI;CACpD;CAEF,SACG,WACA,SAAkB,aAAoC;EACrD,KAAK,OAAO,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,IAAI,SAAS,IAAI;EAClD,KAAK,OAAO,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,IAAI,SAAS,KAAK;CACrD;CAEF,WACG,QACA,SAAkB,aAAoC;EACrD,KAAK,OAAO,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,IAAI,SAAS,IAAI;EAClD,KAAK,OAAO,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,IAAI,MAAM,EAAE;CAC/C;AACJ;AAEA,MAAa,WAAW,IAAI,SAAS"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Resource } from "./Resource.js";
|
|
2
2
|
import { Verb } from "../http/Verb.js";
|
|
3
|
-
import { List, Req,
|
|
3
|
+
import { List, Req, Uri } from "@thisisagile/easy";
|
|
4
|
+
import { Enum as Enum$1 } from "@thisisagile/easy/Scope";
|
|
5
|
+
import { Enum as Enum$2 } from "@thisisagile/easy/UseCase";
|
|
4
6
|
import { RequestHandler } from "express";
|
|
5
7
|
//#region src/resources/Route.d.ts
|
|
6
8
|
export declare const route: (uri: Uri) => ClassDecorator;
|
|
@@ -8,8 +10,8 @@ export type Endpoint<T = unknown> = (re: Req) => Promise<T | List<T>>;
|
|
|
8
10
|
export type RouteRequires = {
|
|
9
11
|
token: boolean;
|
|
10
12
|
labCoat: boolean;
|
|
11
|
-
scope?:
|
|
12
|
-
uc?:
|
|
13
|
+
scope?: Enum$1;
|
|
14
|
+
uc?: Enum$2;
|
|
13
15
|
};
|
|
14
16
|
export type Route = {
|
|
15
17
|
verb: Verb;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Route.js","names":[],"sources":["../../src/resources/Route.ts"],"sourcesContent":["import { List, meta, Optional, tryTo, Uri,
|
|
1
|
+
{"version":3,"file":"Route.js","names":[],"sources":["../../src/resources/Route.ts"],"sourcesContent":["import type { Enum as Scope } from '@thisisagile/easy/Scope';\nimport type { Enum as UseCase } from '@thisisagile/easy/UseCase';\nimport { List, meta, Optional, tryTo, Uri, Req } from '@thisisagile/easy';\nimport { Resource } from './Resource';\nimport { RequestHandler } from 'express';\nimport { Verb } from '../http/Verb';\n\nexport const route =\n (uri: Uri): ClassDecorator =>\n (subject: unknown): void => {\n meta(subject).set('route', uri);\n };\n\nexport type Endpoint<T = unknown> = (re: Req) => Promise<T | List<T>>;\nexport type RouteRequires = { token: boolean; labCoat: boolean; scope?: Scope; uc?: UseCase };\nexport type Route = { verb: Verb; name: string; endpoint: Endpoint; requires: RouteRequires; middleware: RequestHandler[] };\nexport type Routes = { route: Uri; middleware: RequestHandler[]; endpoints: List<Route> };\n\nconst toRoute = (endpoint: Endpoint, requires: RouteRequires, verb?: Verb, middleware?: RequestHandler[], name = ''): Optional<Route> =>\n tryTo(verb)\n .is.defined()\n .map(verb => ({ verb, name, endpoint, requires, middleware: middleware ?? [] }) as Route)\n .orElse();\n\nclass Router implements Routes {\n constructor(readonly resource: Resource) {}\n\n get route(): Uri {\n return meta(this.resource).get('route');\n }\n\n get middleware(): RequestHandler[] {\n return meta(this.resource).get<RequestHandler[]>('middleware') ?? [];\n }\n\n get endpoints(): List<Route> {\n return meta(this.resource)\n .properties('verb')\n .mapDefined(v =>\n toRoute(\n this.resource[v.property],\n {\n labCoat: v.get<boolean>('labCoat') ?? false,\n token: v.get<boolean>('token') ?? false,\n scope: v.get<Scope>('scope'),\n uc: v.get<UseCase>('uc'),\n },\n v.get<Verb>('verb'),\n v.get<RequestHandler[]>('middleware'),\n v.property.toString()\n )\n );\n }\n}\n\nexport const routes = (resource: Resource): Routes => new Router(resource);\n"],"mappings":";;AAOA,MAAa,SACV,SACA,YAA2B;CAC1B,KAAK,OAAO,CAAC,CAAC,IAAI,SAAS,GAAG;AAChC;AAOF,MAAM,WAAW,UAAoB,UAAyB,MAAa,YAA+B,OAAO,OAC/G,MAAM,IAAI,CAAC,CACR,GAAG,QAAQ,CAAC,CACZ,KAAI,UAAS;CAAE;CAAM;CAAM;CAAU;CAAU,YAAY,cAAc,CAAC;AAAE,EAAW,CAAC,CACxF,OAAO;AAEZ,IAAM,SAAN,MAA+B;CACR;CAArB,YAAY,UAA6B;EAApB,KAAA,WAAA;CAAqB;CAE1C,IAAI,QAAa;EACf,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,IAAI,OAAO;CACxC;CAEA,IAAI,aAA+B;EACjC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,IAAsB,YAAY,KAAK,CAAC;CACrE;CAEA,IAAI,YAAyB;EAC3B,OAAO,KAAK,KAAK,QAAQ,CAAC,CACvB,WAAW,MAAM,CAAC,CAClB,YAAW,MACV,QACE,KAAK,SAAS,EAAE,WAChB;GACE,SAAS,EAAE,IAAa,SAAS,KAAK;GACtC,OAAO,EAAE,IAAa,OAAO,KAAK;GAClC,OAAO,EAAE,IAAW,OAAO;GAC3B,IAAI,EAAE,IAAa,IAAI;EACzB,GACA,EAAE,IAAU,MAAM,GAClB,EAAE,IAAsB,YAAY,GACpC,EAAE,SAAS,SAAS,CACtB,CACF;CACJ;AACF;AAEA,MAAa,UAAU,aAA+B,IAAI,OAAO,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy-service",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "21.0.0",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"lint": "yarn g:eslint . --ext .js,.jsx,.ts,.tsx --fix",
|
|
23
23
|
"format": "yarn g:prettier --check --write src test *.json",
|
|
24
|
-
"build": "yarn g:tsdown
|
|
24
|
+
"build": "yarn g:tsdown",
|
|
25
25
|
"test": "yarn g:jest --coverage",
|
|
26
26
|
"prepack": "yarn g:copy-readme"
|
|
27
27
|
},
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@thisisagile/easy-test": "*"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thisisagile/easy": "^
|
|
43
|
+
"@thisisagile/easy": "^21.0.0",
|
|
44
44
|
"jsonwebtoken": "^9.0.3"
|
|
45
45
|
},
|
|
46
46
|
"exports": {
|
package/src/http/Verb.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as ContentType from '@thisisagile/easy/ContentType';
|
|
2
|
+
import * as HttpStatus from '@thisisagile/easy/HttpStatus';
|
|
3
|
+
import * as HttpVerb from '@thisisagile/easy/HttpVerb';
|
|
4
|
+
import { meta, CacheControl } from '@thisisagile/easy';
|
|
2
5
|
|
|
3
|
-
export type VerbOptions = { onOk?: HttpStatus; onNotFound?: HttpStatus; onError?: HttpStatus; type?: ContentType; cache?: CacheControl };
|
|
4
|
-
export type Verb = { verb: HttpVerb; options: VerbOptions };
|
|
6
|
+
export type VerbOptions = { onOk?: HttpStatus.Enum; onNotFound?: HttpStatus.Enum; onError?: HttpStatus.Enum; type?: ContentType.Enum; cache?: CacheControl };
|
|
7
|
+
export type Verb = { verb: HttpVerb.Enum; options: VerbOptions };
|
|
5
8
|
|
|
6
9
|
export const toVerbOptions = (options?: VerbOptions): Required<VerbOptions> => ({
|
|
7
10
|
onOk: options?.onOk ?? HttpStatus.Ok,
|
|
@@ -12,7 +15,7 @@ export const toVerbOptions = (options?: VerbOptions): Required<VerbOptions> => (
|
|
|
12
15
|
});
|
|
13
16
|
|
|
14
17
|
const toVerb =
|
|
15
|
-
<T>(verb: HttpVerb, options?: VerbOptions): PropertyDecorator =>
|
|
18
|
+
<T>(verb: HttpVerb.Enum, options?: VerbOptions): PropertyDecorator =>
|
|
16
19
|
(subject: unknown, property: string | symbol): void => {
|
|
17
20
|
meta(subject).property(property).set('verb', { verb, options });
|
|
18
21
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Enum as Scope } from '@thisisagile/easy/Scope';
|
|
2
|
+
import type { Enum as UseCase } from '@thisisagile/easy/UseCase';
|
|
1
3
|
import { meta } from '@thisisagile/easy';
|
|
2
|
-
import { Scope, UseCase } from '@thisisagile/easy';
|
|
3
4
|
|
|
4
5
|
export class Requires {
|
|
5
6
|
readonly labCoat =
|
package/src/resources/Route.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Enum as Scope } from '@thisisagile/easy/Scope';
|
|
2
|
+
import type { Enum as UseCase } from '@thisisagile/easy/UseCase';
|
|
3
|
+
import { List, meta, Optional, tryTo, Uri, Req } from '@thisisagile/easy';
|
|
2
4
|
import { Resource } from './Resource';
|
|
3
5
|
import { RequestHandler } from 'express';
|
|
4
6
|
import { Verb } from '../http/Verb';
|
|
@@ -11,7 +13,7 @@ export const route =
|
|
|
11
13
|
|
|
12
14
|
export type Endpoint<T = unknown> = (re: Req) => Promise<T | List<T>>;
|
|
13
15
|
export type RouteRequires = { token: boolean; labCoat: boolean; scope?: Scope; uc?: UseCase };
|
|
14
|
-
export type Route = { verb: Verb; name: string
|
|
16
|
+
export type Route = { verb: Verb; name: string; endpoint: Endpoint; requires: RouteRequires; middleware: RequestHandler[] };
|
|
15
17
|
export type Routes = { route: Uri; middleware: RequestHandler[]; endpoints: List<Route> };
|
|
16
18
|
|
|
17
19
|
const toRoute = (endpoint: Endpoint, requires: RouteRequires, verb?: Verb, middleware?: RequestHandler[], name = ''): Optional<Route> =>
|
|
@@ -45,7 +47,7 @@ class Router implements Routes {
|
|
|
45
47
|
},
|
|
46
48
|
v.get<Verb>('verb'),
|
|
47
49
|
v.get<RequestHandler[]>('middleware'),
|
|
48
|
-
v.property.toString()
|
|
50
|
+
v.property.toString()
|
|
49
51
|
)
|
|
50
52
|
);
|
|
51
53
|
}
|