@thisisagile/easy-service 19.1.4 → 20.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/_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.js +6 -0
- package/dist/health/HealthResource.d.ts +6 -3
- package/dist/health/HealthResource.js +16 -0
- package/dist/health/HealthResource.js.map +1 -0
- package/dist/health/HealthUri.d.ts +6 -3
- package/dist/health/HealthUri.js +10 -0
- package/dist/health/HealthUri.js.map +1 -0
- package/dist/http/OriginatedError.d.ts +8 -5
- package/dist/http/OriginatedError.js +18 -0
- package/dist/http/OriginatedError.js.map +1 -0
- package/dist/http/Verb.d.ts +11 -8
- package/dist/http/Verb.js +38 -0
- package/dist/http/Verb.js.map +1 -0
- package/dist/index.d.ts +11 -10
- package/dist/index.js +9 -236
- package/dist/resources/AppProvider.d.ts +9 -6
- package/dist/resources/AppProvider.js +0 -0
- package/dist/resources/Requires.d.ts +8 -5
- package/dist/resources/Requires.js +23 -0
- package/dist/resources/Requires.js.map +1 -0
- package/dist/resources/Resource.d.ts +3 -0
- package/dist/resources/Resource.js +0 -0
- package/dist/resources/Route.d.ts +19 -16
- package/dist/resources/Route.js +37 -0
- package/dist/resources/Route.js.map +1 -0
- package/dist/resources/Service.d.ts +16 -13
- package/dist/resources/Service.js +29 -0
- package/dist/resources/Service.js.map +1 -0
- package/dist/security/Jwt.d.ts +12 -9
- package/dist/security/Jwt.js +19 -0
- package/dist/security/Jwt.js.map +1 -0
- package/package.json +19 -17
- package/dist/chunk-2XMYNSTI.mjs +0 -11
- package/dist/chunk-2XMYNSTI.mjs.map +0 -1
- package/dist/chunk-4D3CGIDW.mjs +0 -22
- package/dist/chunk-4D3CGIDW.mjs.map +0 -1
- package/dist/chunk-4N72FQFX.mjs +0 -16
- package/dist/chunk-4N72FQFX.mjs.map +0 -1
- package/dist/chunk-B37TXK4C.mjs +0 -40
- package/dist/chunk-B37TXK4C.mjs.map +0 -1
- package/dist/chunk-BTPC4SVP.mjs +0 -1
- package/dist/chunk-BTPC4SVP.mjs.map +0 -1
- package/dist/chunk-KHAYZJCB.mjs +0 -29
- package/dist/chunk-KHAYZJCB.mjs.map +0 -1
- package/dist/chunk-OQUQPJ6S.mjs +0 -25
- package/dist/chunk-OQUQPJ6S.mjs.map +0 -1
- package/dist/chunk-RJWBTUKZ.mjs +0 -27
- package/dist/chunk-RJWBTUKZ.mjs.map +0 -1
- package/dist/chunk-VXGHOHGY.mjs +0 -1
- package/dist/chunk-VXGHOHGY.mjs.map +0 -1
- package/dist/chunk-W62PBGRF.mjs +0 -31
- package/dist/chunk-W62PBGRF.mjs.map +0 -1
- package/dist/chunk-YB7NDS5U.mjs +0 -20
- package/dist/chunk-YB7NDS5U.mjs.map +0 -1
- package/dist/health/HealthResource.mjs +0 -11
- package/dist/health/HealthResource.mjs.map +0 -1
- package/dist/health/HealthUri.mjs +0 -8
- package/dist/health/HealthUri.mjs.map +0 -1
- package/dist/http/OriginatedError.mjs +0 -12
- package/dist/http/OriginatedError.mjs.map +0 -1
- package/dist/http/Verb.mjs +0 -22
- package/dist/http/Verb.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -60
- package/dist/index.mjs.map +0 -1
- package/dist/resources/AppProvider.mjs +0 -2
- package/dist/resources/AppProvider.mjs.map +0 -1
- package/dist/resources/Requires.mjs +0 -10
- package/dist/resources/Requires.mjs.map +0 -1
- package/dist/resources/Resource.mjs +0 -2
- package/dist/resources/Resource.mjs.map +0 -1
- package/dist/resources/Route.mjs +0 -10
- package/dist/resources/Route.mjs.map +0 -1
- package/dist/resources/Service.mjs +0 -8
- package/dist/resources/Service.mjs.map +0 -1
- package/dist/security/Jwt.mjs +0 -8
- package/dist/security/Jwt.mjs.map +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/decorate.js
|
|
2
|
+
function __decorate(decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { __decorate as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/decorateMetadata.js
|
|
2
|
+
function __decorateMetadata(k, v) {
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
export { __decorateMetadata as default };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Resource } from "../resources/Resource.js";
|
|
2
|
+
import { Json } from "@thisisagile/easy";
|
|
3
|
+
//#region src/health/HealthResource.d.ts
|
|
3
4
|
export declare class HealthResource implements Resource {
|
|
4
|
-
|
|
5
|
+
ok: () => Promise<Json>;
|
|
5
6
|
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=HealthResource.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HealthUri } from "./HealthUri.js";
|
|
2
|
+
import { route } from "../resources/Route.js";
|
|
3
|
+
import { get } from "../http/Verb.js";
|
|
4
|
+
import __decorateMetadata from "../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.js";
|
|
5
|
+
import __decorate from "../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.js";
|
|
6
|
+
import { resolve } from "@thisisagile/easy";
|
|
7
|
+
//#region src/health/HealthResource.ts
|
|
8
|
+
let HealthResource = class HealthResource {
|
|
9
|
+
ok = () => resolve({ state: "Service is healthy." });
|
|
10
|
+
};
|
|
11
|
+
__decorate([get(), __decorateMetadata("design:type", Object)], HealthResource.prototype, "ok", void 0);
|
|
12
|
+
HealthResource = __decorate([route(HealthUri.Health)], HealthResource);
|
|
13
|
+
//#endregion
|
|
14
|
+
export { HealthResource };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=HealthResource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HealthResource.js","names":[],"sources":["../../src/health/HealthResource.ts"],"sourcesContent":["import { resolve, Json } from '@thisisagile/easy';\nimport { HealthUri } from './HealthUri';\nimport { Resource } from '../resources/Resource';\nimport { route } from '../resources/Route';\nimport { get } from '../http/Verb';\n\n@route(HealthUri.Health)\nexport class HealthResource implements Resource {\n @get()\n ok = (): Promise<Json> => resolve({ state: 'Service is healthy.' });\n}\n"],"mappings":";;;;;;;AAOO,IAAM,iBAAN,MAAM,eAAmC;CAC9C,WAC0B,QAAQ,EAAE,OAAO,sBAAsB,CAAC;AACpE;AAFG,WAAA,CAAA,IAAI,GAAA,mBAAA,eAAA,MAAA,CAAA,GAAA,eAAA,WAAA,MAAA,KAAA,CAAA;AAFN,iBAAA,WAAA,CAAA,MAAM,UAAU,MAAM,CAAA,GAAA,cAAA"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { EasyUri } from
|
|
1
|
+
import { EasyUri } from "@thisisagile/easy";
|
|
2
|
+
//#region src/health/HealthUri.d.ts
|
|
2
3
|
export declare class HealthUri extends EasyUri {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
static readonly health: import("@thisisagile/easy").Segment;
|
|
5
|
+
static readonly Health: HealthUri;
|
|
5
6
|
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=HealthUri.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EasyUri, uri } from "@thisisagile/easy";
|
|
2
|
+
//#region src/health/HealthUri.ts
|
|
3
|
+
var HealthUri = class HealthUri extends EasyUri {
|
|
4
|
+
static health = uri.segment("health");
|
|
5
|
+
static Health = new HealthUri([HealthUri.health]);
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { HealthUri };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=HealthUri.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HealthUri.js","names":[],"sources":["../../src/health/HealthUri.ts"],"sourcesContent":["import { EasyUri, uri } from '@thisisagile/easy';\n\nexport class HealthUri extends EasyUri {\n static readonly health = uri.segment('health');\n static readonly Health = new HealthUri([HealthUri.health]);\n}\n"],"mappings":";;AAEA,IAAa,YAAb,MAAa,kBAAkB,QAAQ;CACrC,OAAgB,SAAS,IAAI,QAAQ,QAAQ;CAC7C,OAAgB,SAAS,IAAI,UAAU,CAAC,UAAU,MAAM,CAAC;AAC3D"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { VerbOptions } from "./Verb.js";
|
|
2
|
+
import { ErrorOrigin } from "@thisisagile/easy";
|
|
3
|
+
//#region src/http/OriginatedError.d.ts
|
|
3
4
|
export declare class OriginatedError extends Error {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
readonly origin: ErrorOrigin;
|
|
6
|
+
readonly options?: VerbOptions | undefined;
|
|
7
|
+
constructor(origin: ErrorOrigin, options?: VerbOptions | undefined);
|
|
7
8
|
}
|
|
8
9
|
export declare const isOriginatedError: (e?: unknown) => e is OriginatedError;
|
|
9
10
|
export declare const toOriginatedError: (e: unknown, options?: VerbOptions) => OriginatedError;
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=OriginatedError.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isError } from "@thisisagile/easy";
|
|
2
|
+
//#region src/http/OriginatedError.ts
|
|
3
|
+
var OriginatedError = class extends Error {
|
|
4
|
+
origin;
|
|
5
|
+
options;
|
|
6
|
+
constructor(origin, options) {
|
|
7
|
+
super();
|
|
8
|
+
this.origin = origin;
|
|
9
|
+
this.options = options;
|
|
10
|
+
if (isError(origin)) this.stack = origin.stack;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const isOriginatedError = (e) => isError(e) && e instanceof OriginatedError;
|
|
14
|
+
const toOriginatedError = (e, options) => isOriginatedError(e) ? e : new OriginatedError(e, options);
|
|
15
|
+
//#endregion
|
|
16
|
+
export { OriginatedError, isOriginatedError, toOriginatedError };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=OriginatedError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OriginatedError.js","names":[],"sources":["../../src/http/OriginatedError.ts"],"sourcesContent":["import { ErrorOrigin, isError } from '@thisisagile/easy';\nimport { VerbOptions } from './Verb';\n\nexport class OriginatedError extends Error {\n constructor(\n readonly origin: ErrorOrigin,\n readonly options?: VerbOptions\n ) {\n super();\n if (isError(origin)) this.stack = origin.stack;\n }\n}\n\nexport const isOriginatedError = (e?: unknown): e is OriginatedError => isError(e) && e instanceof OriginatedError;\n\nexport const toOriginatedError = (e: unknown, options?: VerbOptions): OriginatedError =>\n isOriginatedError(e) ? e : new OriginatedError(e as ErrorOrigin, options);\n"],"mappings":";;AAGA,IAAa,kBAAb,cAAqC,MAAM;CAE9B;CACA;CAFX,YACE,QACA,SACA;EACA,MAAM;EAHG,KAAA,SAAA;EACA,KAAA,UAAA;EAGT,IAAI,QAAQ,MAAM,GAAG,KAAK,QAAQ,OAAO;CAC3C;AACF;AAEA,MAAa,qBAAqB,MAAsC,QAAQ,CAAC,KAAK,aAAa;AAEnG,MAAa,qBAAqB,GAAY,YAC5C,kBAAkB,CAAC,IAAI,IAAI,IAAI,gBAAgB,GAAkB,OAAO"}
|
package/dist/http/Verb.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { CacheControl, ContentType, HttpStatus, HttpVerb } from
|
|
1
|
+
import { CacheControl, ContentType, HttpStatus, HttpVerb } from "@thisisagile/easy";
|
|
2
|
+
//#region src/http/Verb.d.ts
|
|
2
3
|
export type VerbOptions = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
onOk?: HttpStatus;
|
|
5
|
+
onNotFound?: HttpStatus;
|
|
6
|
+
onError?: HttpStatus;
|
|
7
|
+
type?: ContentType;
|
|
8
|
+
cache?: CacheControl;
|
|
8
9
|
};
|
|
9
10
|
export type Verb = {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
verb: HttpVerb;
|
|
12
|
+
options: VerbOptions;
|
|
12
13
|
};
|
|
13
14
|
export declare const toVerbOptions: (options?: VerbOptions) => Required<VerbOptions>;
|
|
14
15
|
export declare const get: (options?: VerbOptions) => PropertyDecorator;
|
|
@@ -18,3 +19,5 @@ export declare const patch: (options?: VerbOptions) => PropertyDecorator;
|
|
|
18
19
|
export declare const post: (options?: VerbOptions) => PropertyDecorator;
|
|
19
20
|
export declare const del: (options?: VerbOptions) => PropertyDecorator;
|
|
20
21
|
export declare const stream: (options?: VerbOptions) => PropertyDecorator;
|
|
22
|
+
//#endregion
|
|
23
|
+
//# sourceMappingURL=Verb.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CacheControl, ContentType, HttpStatus, HttpVerb, meta } from "@thisisagile/easy";
|
|
2
|
+
//#region src/http/Verb.ts
|
|
3
|
+
const toVerbOptions = (options) => ({
|
|
4
|
+
onOk: options?.onOk ?? HttpStatus.Ok,
|
|
5
|
+
onNotFound: options?.onNotFound ?? HttpStatus.NotFound,
|
|
6
|
+
onError: options?.onError ?? HttpStatus.BadRequest,
|
|
7
|
+
type: options?.type ?? ContentType.Json,
|
|
8
|
+
cache: options?.cache ?? CacheControl.disabled()
|
|
9
|
+
});
|
|
10
|
+
const toVerb = (verb, options) => (subject, property) => {
|
|
11
|
+
meta(subject).property(property).set("verb", {
|
|
12
|
+
verb,
|
|
13
|
+
options
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
const get = (options) => toVerb(HttpVerb.Get, options);
|
|
17
|
+
const search = (options) => toVerb(HttpVerb.Get, {
|
|
18
|
+
onNotFound: HttpStatus.Ok,
|
|
19
|
+
...options
|
|
20
|
+
});
|
|
21
|
+
const put = (options) => toVerb(HttpVerb.Put, options);
|
|
22
|
+
const patch = (options) => toVerb(HttpVerb.Patch, options);
|
|
23
|
+
const post = (options) => toVerb(HttpVerb.Post, {
|
|
24
|
+
onOk: HttpStatus.Created,
|
|
25
|
+
...options
|
|
26
|
+
});
|
|
27
|
+
const del = (options) => toVerb(HttpVerb.Delete, {
|
|
28
|
+
onOk: HttpStatus.NoContent,
|
|
29
|
+
...options
|
|
30
|
+
});
|
|
31
|
+
const stream = (options) => toVerb(HttpVerb.Get, {
|
|
32
|
+
type: ContentType.Stream,
|
|
33
|
+
...options
|
|
34
|
+
});
|
|
35
|
+
//#endregion
|
|
36
|
+
export { del, get, patch, post, put, search, stream, toVerbOptions };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=Verb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Verb.js","names":[],"sources":["../../src/http/Verb.ts"],"sourcesContent":["import { meta, CacheControl, ContentType, HttpStatus, HttpVerb } from '@thisisagile/easy';\n\nexport type VerbOptions = { onOk?: HttpStatus; onNotFound?: HttpStatus; onError?: HttpStatus; type?: ContentType; cache?: CacheControl };\nexport type Verb = { verb: HttpVerb; 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, 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":";;AAKA,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,MAAgB,aACnB,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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Resource } from "./resources/Resource.js";
|
|
2
|
+
import { HealthResource } from "./health/HealthResource.js";
|
|
3
|
+
import { HealthUri } from "./health/HealthUri.js";
|
|
4
|
+
import { Verb, VerbOptions, del, get, patch, post, put, search, stream, toVerbOptions } from "./http/Verb.js";
|
|
5
|
+
import { OriginatedError, isOriginatedError, toOriginatedError } from "./http/OriginatedError.js";
|
|
6
|
+
import { Service } from "./resources/Service.js";
|
|
7
|
+
import { AppProvider, Handler } from "./resources/AppProvider.js";
|
|
8
|
+
import { Requires, requires } from "./resources/Requires.js";
|
|
9
|
+
import { Endpoint, Route, RouteRequires, Routes, route, routes } from "./resources/Route.js";
|
|
10
|
+
import { Jwt } from "./security/Jwt.js";
|
|
11
|
+
export { AppProvider, Endpoint, Handler, HealthResource, HealthUri, Jwt, OriginatedError, Requires, Resource, Route, RouteRequires, Routes, Service, Verb, VerbOptions, del, get, isOriginatedError, patch, post, put, requires, route, routes, search, stream, toOriginatedError, toVerbOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,236 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
30
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
31
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
32
|
-
if (decorator = decorators[i])
|
|
33
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
34
|
-
if (kind && result)
|
|
35
|
-
__defProp(target, key, result);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/index.ts
|
|
40
|
-
var src_exports = {};
|
|
41
|
-
__export(src_exports, {
|
|
42
|
-
HealthResource: () => HealthResource,
|
|
43
|
-
HealthUri: () => HealthUri,
|
|
44
|
-
Jwt: () => Jwt,
|
|
45
|
-
OriginatedError: () => OriginatedError,
|
|
46
|
-
Requires: () => Requires,
|
|
47
|
-
Service: () => Service,
|
|
48
|
-
del: () => del,
|
|
49
|
-
get: () => get,
|
|
50
|
-
isOriginatedError: () => isOriginatedError,
|
|
51
|
-
patch: () => patch,
|
|
52
|
-
post: () => post,
|
|
53
|
-
put: () => put,
|
|
54
|
-
requires: () => requires,
|
|
55
|
-
route: () => route,
|
|
56
|
-
routes: () => routes,
|
|
57
|
-
search: () => search,
|
|
58
|
-
stream: () => stream,
|
|
59
|
-
toOriginatedError: () => toOriginatedError,
|
|
60
|
-
toVerbOptions: () => toVerbOptions
|
|
61
|
-
});
|
|
62
|
-
module.exports = __toCommonJS(src_exports);
|
|
63
|
-
|
|
64
|
-
// src/health/HealthResource.ts
|
|
65
|
-
var import_easy4 = require("@thisisagile/easy");
|
|
66
|
-
|
|
67
|
-
// src/health/HealthUri.ts
|
|
68
|
-
var import_easy = require("@thisisagile/easy");
|
|
69
|
-
var HealthUri = class _HealthUri extends import_easy.EasyUri {
|
|
70
|
-
static health = import_easy.uri.segment("health");
|
|
71
|
-
static Health = new _HealthUri([_HealthUri.health]);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// src/resources/Route.ts
|
|
75
|
-
var import_easy2 = require("@thisisagile/easy");
|
|
76
|
-
var route = (uri2) => (subject) => {
|
|
77
|
-
(0, import_easy2.meta)(subject).set("route", uri2);
|
|
78
|
-
};
|
|
79
|
-
var toRoute = (endpoint, requires2, verb, middleware, name = "") => (0, import_easy2.tryTo)(verb).is.defined().map((verb2) => ({ verb: verb2, name, endpoint, requires: requires2, middleware: middleware ?? [] })).orElse();
|
|
80
|
-
var Router = class {
|
|
81
|
-
constructor(resource) {
|
|
82
|
-
this.resource = resource;
|
|
83
|
-
}
|
|
84
|
-
get route() {
|
|
85
|
-
return (0, import_easy2.meta)(this.resource).get("route");
|
|
86
|
-
}
|
|
87
|
-
get middleware() {
|
|
88
|
-
return (0, import_easy2.meta)(this.resource).get("middleware") ?? [];
|
|
89
|
-
}
|
|
90
|
-
get endpoints() {
|
|
91
|
-
return (0, import_easy2.meta)(this.resource).properties("verb").mapDefined(
|
|
92
|
-
(v) => toRoute(
|
|
93
|
-
this.resource[v.property],
|
|
94
|
-
{
|
|
95
|
-
labCoat: v.get("labCoat") ?? false,
|
|
96
|
-
token: v.get("token") ?? false,
|
|
97
|
-
scope: v.get("scope"),
|
|
98
|
-
uc: v.get("uc")
|
|
99
|
-
},
|
|
100
|
-
v.get("verb"),
|
|
101
|
-
v.get("middleware"),
|
|
102
|
-
v.property.toString()
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
var routes = (resource) => new Router(resource);
|
|
108
|
-
|
|
109
|
-
// src/http/Verb.ts
|
|
110
|
-
var import_easy3 = require("@thisisagile/easy");
|
|
111
|
-
var toVerbOptions = (options) => ({
|
|
112
|
-
onOk: options?.onOk ?? import_easy3.HttpStatus.Ok,
|
|
113
|
-
onNotFound: options?.onNotFound ?? import_easy3.HttpStatus.NotFound,
|
|
114
|
-
onError: options?.onError ?? import_easy3.HttpStatus.BadRequest,
|
|
115
|
-
type: options?.type ?? import_easy3.ContentType.Json,
|
|
116
|
-
cache: options?.cache ?? import_easy3.CacheControl.disabled()
|
|
117
|
-
});
|
|
118
|
-
var toVerb = (verb, options) => (subject, property) => {
|
|
119
|
-
(0, import_easy3.meta)(subject).property(property).set("verb", { verb, options });
|
|
120
|
-
};
|
|
121
|
-
var get = (options) => toVerb(import_easy3.HttpVerb.Get, options);
|
|
122
|
-
var search = (options) => toVerb(import_easy3.HttpVerb.Get, { onNotFound: import_easy3.HttpStatus.Ok, ...options });
|
|
123
|
-
var put = (options) => toVerb(import_easy3.HttpVerb.Put, options);
|
|
124
|
-
var patch = (options) => toVerb(import_easy3.HttpVerb.Patch, options);
|
|
125
|
-
var post = (options) => toVerb(import_easy3.HttpVerb.Post, { onOk: import_easy3.HttpStatus.Created, ...options });
|
|
126
|
-
var del = (options) => toVerb(import_easy3.HttpVerb.Delete, { onOk: import_easy3.HttpStatus.NoContent, ...options });
|
|
127
|
-
var stream = (options) => toVerb(import_easy3.HttpVerb.Get, { type: import_easy3.ContentType.Stream, ...options });
|
|
128
|
-
|
|
129
|
-
// src/health/HealthResource.ts
|
|
130
|
-
var HealthResource = class {
|
|
131
|
-
ok = () => (0, import_easy4.resolve)({ state: "Service is healthy." });
|
|
132
|
-
};
|
|
133
|
-
__decorateClass([
|
|
134
|
-
get()
|
|
135
|
-
], HealthResource.prototype, "ok", 2);
|
|
136
|
-
HealthResource = __decorateClass([
|
|
137
|
-
route(HealthUri.Health)
|
|
138
|
-
], HealthResource);
|
|
139
|
-
|
|
140
|
-
// src/http/OriginatedError.ts
|
|
141
|
-
var import_easy5 = require("@thisisagile/easy");
|
|
142
|
-
var OriginatedError = class extends Error {
|
|
143
|
-
constructor(origin, options) {
|
|
144
|
-
super();
|
|
145
|
-
this.origin = origin;
|
|
146
|
-
this.options = options;
|
|
147
|
-
if ((0, import_easy5.isError)(origin))
|
|
148
|
-
this.stack = origin.stack;
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
var isOriginatedError = (e) => (0, import_easy5.isError)(e) && e instanceof OriginatedError;
|
|
152
|
-
var toOriginatedError = (e, options) => isOriginatedError(e) ? e : new OriginatedError(e, options);
|
|
153
|
-
|
|
154
|
-
// src/resources/Requires.ts
|
|
155
|
-
var import_easy6 = require("@thisisagile/easy");
|
|
156
|
-
var Requires = class {
|
|
157
|
-
labCoat = () => (subject, property) => {
|
|
158
|
-
(0, import_easy6.meta)(subject).property(property).set("labCoat", true);
|
|
159
|
-
};
|
|
160
|
-
token = () => (subject, property) => {
|
|
161
|
-
(0, import_easy6.meta)(subject).property(property).set("token", true);
|
|
162
|
-
};
|
|
163
|
-
scope = (scope) => (subject, property) => {
|
|
164
|
-
(0, import_easy6.meta)(subject).property(property).set("token", true);
|
|
165
|
-
(0, import_easy6.meta)(subject).property(property).set("scope", scope);
|
|
166
|
-
};
|
|
167
|
-
useCase = (uc) => (subject, property) => {
|
|
168
|
-
(0, import_easy6.meta)(subject).property(property).set("token", true);
|
|
169
|
-
(0, import_easy6.meta)(subject).property(property).set("uc", uc);
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
var requires = new Requires();
|
|
173
|
-
|
|
174
|
-
// src/resources/Service.ts
|
|
175
|
-
var import_easy7 = require("@thisisagile/easy");
|
|
176
|
-
var Service = class extends import_easy7.Enum {
|
|
177
|
-
constructor(name, app, resources = (0, import_easy7.toList)()) {
|
|
178
|
-
super(name);
|
|
179
|
-
this.name = name;
|
|
180
|
-
this.app = app;
|
|
181
|
-
this.resources = resources;
|
|
182
|
-
}
|
|
183
|
-
port = 8080;
|
|
184
|
-
pre = () => [];
|
|
185
|
-
post = () => [];
|
|
186
|
-
with(...resources) {
|
|
187
|
-
return (0, import_easy7.tryTo)(this).accept((t) => t.resources.add(resources.map((r) => new r()))).value;
|
|
188
|
-
}
|
|
189
|
-
atPort(port) {
|
|
190
|
-
return (0, import_easy7.tryTo)(this).accept((t) => t.port = port).value;
|
|
191
|
-
}
|
|
192
|
-
start(message = `Service ${this.name} listening on port ${this.port} with ${this.resources.length} resources.`) {
|
|
193
|
-
(0, import_easy7.tryTo)(this).accept((t) => t.pre().forEach((h) => this.app.use(h))).accept((t) => t.resources.forEach((r) => this.app.route(this, r))).accept((t) => t.post().forEach((h) => this.app.use(h))).accept((t) => t.app.listen(this.port, message));
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
// src/security/Jwt.ts
|
|
198
|
-
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
199
|
-
var import_easy8 = require("@thisisagile/easy");
|
|
200
|
-
var Jwt = class _Jwt extends import_easy8.Jwt {
|
|
201
|
-
static of = (a) => new _Jwt(a.jwt);
|
|
202
|
-
get isValid() {
|
|
203
|
-
return (0, import_easy8.tryTo)(() => import_easy8.ctx.env.get("tokenPublicKey") ?? "").map((key) => import_jsonwebtoken.default.verify(this.value, key)).map(() => true).orElse() ?? false;
|
|
204
|
-
}
|
|
205
|
-
static sign = (token, options) => (0, import_easy8.tryTo)(() => import_easy8.ctx.env.get("tokenPrivateKey") ?? "").is.not.empty().map(
|
|
206
|
-
(key) => import_jsonwebtoken.default.sign(token, key, {
|
|
207
|
-
...options,
|
|
208
|
-
expiresIn: import_easy8.ctx.env.get("tokenExpiresIn") ?? "1h",
|
|
209
|
-
keyid: import_easy8.ctx.env.get("tokenKeyid") ?? "easy",
|
|
210
|
-
algorithm: import_easy8.ctx.env.get("tokenAlgorithm", "RS256")
|
|
211
|
-
})
|
|
212
|
-
).map((s) => new _Jwt(s)).value;
|
|
213
|
-
};
|
|
214
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
215
|
-
0 && (module.exports = {
|
|
216
|
-
HealthResource,
|
|
217
|
-
HealthUri,
|
|
218
|
-
Jwt,
|
|
219
|
-
OriginatedError,
|
|
220
|
-
Requires,
|
|
221
|
-
Service,
|
|
222
|
-
del,
|
|
223
|
-
get,
|
|
224
|
-
isOriginatedError,
|
|
225
|
-
patch,
|
|
226
|
-
post,
|
|
227
|
-
put,
|
|
228
|
-
requires,
|
|
229
|
-
route,
|
|
230
|
-
routes,
|
|
231
|
-
search,
|
|
232
|
-
stream,
|
|
233
|
-
toOriginatedError,
|
|
234
|
-
toVerbOptions
|
|
235
|
-
});
|
|
236
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { HealthUri } from "./health/HealthUri.js";
|
|
2
|
+
import { route, routes } from "./resources/Route.js";
|
|
3
|
+
import { del, get, patch, post, put, search, stream, toVerbOptions } from "./http/Verb.js";
|
|
4
|
+
import { HealthResource } from "./health/HealthResource.js";
|
|
5
|
+
import { OriginatedError, isOriginatedError, toOriginatedError } from "./http/OriginatedError.js";
|
|
6
|
+
import { Requires, requires } from "./resources/Requires.js";
|
|
7
|
+
import { Service } from "./resources/Service.js";
|
|
8
|
+
import { Jwt } from "./security/Jwt.js";
|
|
9
|
+
export { HealthResource, HealthUri, Jwt, OriginatedError, Requires, Service, del, get, isOriginatedError, patch, post, put, requires, route, routes, search, stream, toOriginatedError, toVerbOptions };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { Resource } from
|
|
2
|
-
import { Service } from
|
|
3
|
-
import { Func } from
|
|
1
|
+
import { Resource } from "./Resource.js";
|
|
2
|
+
import { Service } from "./Service.js";
|
|
3
|
+
import { Func } from "@thisisagile/easy";
|
|
4
|
+
//#region src/resources/AppProvider.d.ts
|
|
4
5
|
export type Handler = Func<void, any>;
|
|
5
6
|
export interface AppProvider {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
use: (h: Handler) => void;
|
|
8
|
+
route: (s: Service, r: Resource) => void;
|
|
9
|
+
listen: (port: number, message?: string) => void;
|
|
9
10
|
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=AppProvider.d.ts.map
|
|
File without changes
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { Scope, UseCase } from
|
|
1
|
+
import { Scope, UseCase } from "@thisisagile/easy";
|
|
2
|
+
//#region src/resources/Requires.d.ts
|
|
2
3
|
export declare class Requires {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
readonly labCoat: () => PropertyDecorator;
|
|
5
|
+
readonly token: () => PropertyDecorator;
|
|
6
|
+
readonly scope: (scope: Scope) => PropertyDecorator;
|
|
7
|
+
readonly useCase: (uc: UseCase) => PropertyDecorator;
|
|
7
8
|
}
|
|
8
9
|
export declare const requires: Requires;
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=Requires.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { meta } from "@thisisagile/easy";
|
|
2
|
+
//#region src/resources/Requires.ts
|
|
3
|
+
var Requires = class {
|
|
4
|
+
labCoat = () => (subject, property) => {
|
|
5
|
+
meta(subject).property(property).set("labCoat", true);
|
|
6
|
+
};
|
|
7
|
+
token = () => (subject, property) => {
|
|
8
|
+
meta(subject).property(property).set("token", true);
|
|
9
|
+
};
|
|
10
|
+
scope = (scope) => (subject, property) => {
|
|
11
|
+
meta(subject).property(property).set("token", true);
|
|
12
|
+
meta(subject).property(property).set("scope", scope);
|
|
13
|
+
};
|
|
14
|
+
useCase = (uc) => (subject, property) => {
|
|
15
|
+
meta(subject).property(property).set("token", true);
|
|
16
|
+
meta(subject).property(property).set("uc", uc);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const requires = new Requires();
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Requires, requires };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=Requires.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Requires.js","names":[],"sources":["../../src/resources/Requires.ts"],"sourcesContent":["import { meta } from '@thisisagile/easy';\nimport { Scope, UseCase } 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":";;AAGA,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"}
|
|
File without changes
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Resource } from "./Resource.js";
|
|
2
|
+
import { Verb } from "../http/Verb.js";
|
|
3
|
+
import { List, Req, Scope, Uri, UseCase } from "@thisisagile/easy";
|
|
4
|
+
import { RequestHandler } from "express";
|
|
5
|
+
//#region src/resources/Route.d.ts
|
|
5
6
|
export declare const route: (uri: Uri) => ClassDecorator;
|
|
6
7
|
export type Endpoint<T = unknown> = (re: Req) => Promise<T | List<T>>;
|
|
7
8
|
export type RouteRequires = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
token: boolean;
|
|
10
|
+
labCoat: boolean;
|
|
11
|
+
scope?: Scope;
|
|
12
|
+
uc?: UseCase;
|
|
12
13
|
};
|
|
13
14
|
export type Route = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
verb: Verb;
|
|
16
|
+
name: string;
|
|
17
|
+
endpoint: Endpoint;
|
|
18
|
+
requires: RouteRequires;
|
|
19
|
+
middleware: RequestHandler[];
|
|
19
20
|
};
|
|
20
21
|
export type Routes = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
route: Uri;
|
|
23
|
+
middleware: RequestHandler[];
|
|
24
|
+
endpoints: List<Route>;
|
|
24
25
|
};
|
|
25
26
|
export declare const routes: (resource: Resource) => Routes;
|
|
27
|
+
//#endregion
|
|
28
|
+
//# sourceMappingURL=Route.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { meta, tryTo } from "@thisisagile/easy";
|
|
2
|
+
//#region src/resources/Route.ts
|
|
3
|
+
const route = (uri) => (subject) => {
|
|
4
|
+
meta(subject).set("route", uri);
|
|
5
|
+
};
|
|
6
|
+
const toRoute = (endpoint, requires, verb, middleware, name = "") => tryTo(verb).is.defined().map((verb) => ({
|
|
7
|
+
verb,
|
|
8
|
+
name,
|
|
9
|
+
endpoint,
|
|
10
|
+
requires,
|
|
11
|
+
middleware: middleware ?? []
|
|
12
|
+
})).orElse();
|
|
13
|
+
var Router = class {
|
|
14
|
+
resource;
|
|
15
|
+
constructor(resource) {
|
|
16
|
+
this.resource = resource;
|
|
17
|
+
}
|
|
18
|
+
get route() {
|
|
19
|
+
return meta(this.resource).get("route");
|
|
20
|
+
}
|
|
21
|
+
get middleware() {
|
|
22
|
+
return meta(this.resource).get("middleware") ?? [];
|
|
23
|
+
}
|
|
24
|
+
get endpoints() {
|
|
25
|
+
return meta(this.resource).properties("verb").mapDefined((v) => toRoute(this.resource[v.property], {
|
|
26
|
+
labCoat: v.get("labCoat") ?? false,
|
|
27
|
+
token: v.get("token") ?? false,
|
|
28
|
+
scope: v.get("scope"),
|
|
29
|
+
uc: v.get("uc")
|
|
30
|
+
}, v.get("verb"), v.get("middleware"), v.property.toString()));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const routes = (resource) => new Router(resource);
|
|
34
|
+
//#endregion
|
|
35
|
+
export { route, routes };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=Route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Route.js","names":[],"sources":["../../src/resources/Route.ts"],"sourcesContent":["import { List, meta, Optional, tryTo, Uri, Scope, UseCase, 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":";;AAKA,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"}
|