@decohere/http 0.0.1-dev.116
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/README.md +246 -0
- package/commonjs/src/app/app.js +166 -0
- package/commonjs/src/app/index.js +19 -0
- package/commonjs/src/app/module.js +17 -0
- package/commonjs/src/auth/ability.js +54 -0
- package/commonjs/src/auth/auth.config.js +23 -0
- package/commonjs/src/auth/auth.extensions.js +106 -0
- package/commonjs/src/auth/auth.types.js +65 -0
- package/commonjs/src/auth/casl-authorization.service.js +36 -0
- package/commonjs/src/auth/index.js +23 -0
- package/commonjs/src/auth/principal-provider.js +19 -0
- package/commonjs/src/auth/safe-outbound-url.js +102 -0
- package/commonjs/src/auth/token-service.js +151 -0
- package/commonjs/src/builder/builder.js +95 -0
- package/commonjs/src/builder/index.js +18 -0
- package/commonjs/src/const.js +87 -0
- package/commonjs/src/health/health.controller.js +75 -0
- package/commonjs/src/health/health.extensions.js +50 -0
- package/commonjs/src/health/index.js +21 -0
- package/commonjs/src/health/readiness.service.js +67 -0
- package/commonjs/src/health/readiness.types.js +7 -0
- package/commonjs/src/hosting/hosted-service-host.js +88 -0
- package/commonjs/src/hosting/hosted-service.js +11 -0
- package/commonjs/src/hosting/index.js +19 -0
- package/commonjs/src/http/http.compression.js +27 -0
- package/commonjs/src/http/http.extensions.js +269 -0
- package/commonjs/src/http/http.options.js +26 -0
- package/commonjs/src/http/http.options.store.js +20 -0
- package/commonjs/src/http/http.security.js +27 -0
- package/commonjs/src/http/http.static.js +248 -0
- package/commonjs/src/http/index.js +22 -0
- package/commonjs/src/index.js +27 -0
- package/commonjs/src/openapi/index.js +45 -0
- package/commonjs/src/openapi/openapi.generator.js +103 -0
- package/commonjs/src/openapi/openapi.types.js +4 -0
- package/commonjs/src/openapi/request-schema.js +187 -0
- package/commonjs/src/openapi/request-validator.js +85 -0
- package/commonjs/src/providers/fastify.provider.js +391 -0
- package/commonjs/src/providers/index.js +18 -0
- package/commonjs/src/routing/anvil.types.js +99 -0
- package/commonjs/src/routing/decorators/argument.decorator.js +49 -0
- package/commonjs/src/routing/decorators/auth.decorator.js +70 -0
- package/commonjs/src/routing/decorators/controller.decorator.js +16 -0
- package/commonjs/src/routing/decorators/field.decorator.js +25 -0
- package/commonjs/src/routing/decorators/index.js +24 -0
- package/commonjs/src/routing/decorators/request.decorator.js +30 -0
- package/commonjs/src/routing/decorators/response.decorator.js +34 -0
- package/commonjs/src/routing/decorators/route.decorator.js +67 -0
- package/commonjs/src/routing/filters/exception-filter-host.js +145 -0
- package/commonjs/src/routing/filters/exception-filter.js +28 -0
- package/commonjs/src/routing/index.js +25 -0
- package/commonjs/src/routing/middleware/http-access-log.middleware.js +47 -0
- package/commonjs/src/routing/middleware/middleware.js +20 -0
- package/commonjs/src/routing/middleware/request-id.js +30 -0
- package/commonjs/src/routing/path.util.js +51 -0
- package/commonjs/src/routing/pipes/index.js +18 -0
- package/commonjs/src/routing/pipes/pipes.js +145 -0
- package/commonjs/src/routing/services/index.js +18 -0
- package/commonjs/src/routing/services/route-argument-resolver.js +77 -0
- package/commonjs/src/routing/services/route-registry.js +194 -0
- package/commonjs/src/routing/services/router.js +158 -0
- package/commonjs/src/sse/index.js +26 -0
- package/commonjs/src/sse/sse.decorator.js +42 -0
- package/commonjs/src/sse/sse.encoder.js +73 -0
- package/commonjs/src/sse/sse.types.js +36 -0
- package/commonjs/src/sse/sse.wire.js +40 -0
- package/commonjs/src/testing/boot-module.js +38 -0
- package/commonjs/src/testing/index.js +20 -0
- package/commonjs/src/testing/sse-reader.js +98 -0
- package/es6/src/app/app.js +148 -0
- package/es6/src/app/index.js +2 -0
- package/es6/src/app/module.js +7 -0
- package/es6/src/auth/ability.js +45 -0
- package/es6/src/auth/auth.config.js +19 -0
- package/es6/src/auth/auth.extensions.js +83 -0
- package/es6/src/auth/auth.types.js +35 -0
- package/es6/src/auth/casl-authorization.service.js +40 -0
- package/es6/src/auth/index.js +6 -0
- package/es6/src/auth/principal-provider.js +14 -0
- package/es6/src/auth/safe-outbound-url.js +99 -0
- package/es6/src/auth/token-service.js +141 -0
- package/es6/src/builder/builder.js +85 -0
- package/es6/src/builder/index.js +1 -0
- package/es6/src/const.js +33 -0
- package/es6/src/health/health.controller.js +65 -0
- package/es6/src/health/health.extensions.js +40 -0
- package/es6/src/health/index.js +4 -0
- package/es6/src/health/readiness.service.js +57 -0
- package/es6/src/health/readiness.types.js +4 -0
- package/es6/src/hosting/hosted-service-host.js +81 -0
- package/es6/src/hosting/hosted-service.js +8 -0
- package/es6/src/hosting/index.js +2 -0
- package/es6/src/http/http.compression.js +9 -0
- package/es6/src/http/http.extensions.js +259 -0
- package/es6/src/http/http.options.js +16 -0
- package/es6/src/http/http.options.store.js +13 -0
- package/es6/src/http/http.security.js +9 -0
- package/es6/src/http/http.static.js +224 -0
- package/es6/src/http/index.js +5 -0
- package/es6/src/index.js +10 -0
- package/es6/src/openapi/index.js +3 -0
- package/es6/src/openapi/openapi.generator.js +82 -0
- package/es6/src/openapi/openapi.types.js +1 -0
- package/es6/src/openapi/request-schema.js +160 -0
- package/es6/src/openapi/request-validator.js +71 -0
- package/es6/src/providers/fastify.provider.js +376 -0
- package/es6/src/providers/index.js +1 -0
- package/es6/src/routing/anvil.types.js +57 -0
- package/es6/src/routing/decorators/argument.decorator.js +28 -0
- package/es6/src/routing/decorators/auth.decorator.js +58 -0
- package/es6/src/routing/decorators/controller.decorator.js +6 -0
- package/es6/src/routing/decorators/field.decorator.js +15 -0
- package/es6/src/routing/decorators/index.js +7 -0
- package/es6/src/routing/decorators/request.decorator.js +24 -0
- package/es6/src/routing/decorators/response.decorator.js +16 -0
- package/es6/src/routing/decorators/route.decorator.js +37 -0
- package/es6/src/routing/filters/exception-filter-host.js +127 -0
- package/es6/src/routing/filters/exception-filter.js +10 -0
- package/es6/src/routing/index.js +8 -0
- package/es6/src/routing/middleware/http-access-log.middleware.js +37 -0
- package/es6/src/routing/middleware/middleware.js +10 -0
- package/es6/src/routing/middleware/request-id.js +14 -0
- package/es6/src/routing/path.util.js +33 -0
- package/es6/src/routing/pipes/index.js +1 -0
- package/es6/src/routing/pipes/pipes.js +118 -0
- package/es6/src/routing/services/index.js +1 -0
- package/es6/src/routing/services/route-argument-resolver.js +67 -0
- package/es6/src/routing/services/route-registry.js +184 -0
- package/es6/src/routing/services/router.js +148 -0
- package/es6/src/sse/index.js +2 -0
- package/es6/src/sse/sse.decorator.js +31 -0
- package/es6/src/sse/sse.encoder.js +67 -0
- package/es6/src/sse/sse.types.js +22 -0
- package/es6/src/sse/sse.wire.js +30 -0
- package/es6/src/testing/boot-module.js +35 -0
- package/es6/src/testing/index.js +2 -0
- package/es6/src/testing/sse-reader.js +91 -0
- package/package.json +64 -0
- package/types/src/app/app.d.ts +41 -0
- package/types/src/app/index.d.ts +2 -0
- package/types/src/app/module.d.ts +15 -0
- package/types/src/auth/ability.d.ts +19 -0
- package/types/src/auth/auth.config.d.ts +28 -0
- package/types/src/auth/auth.extensions.d.ts +53 -0
- package/types/src/auth/auth.types.d.ts +73 -0
- package/types/src/auth/casl-authorization.service.d.ts +28 -0
- package/types/src/auth/index.d.ts +6 -0
- package/types/src/auth/principal-provider.d.ts +20 -0
- package/types/src/auth/safe-outbound-url.d.ts +9 -0
- package/types/src/auth/token-service.d.ts +31 -0
- package/types/src/builder/builder.d.ts +36 -0
- package/types/src/builder/index.d.ts +1 -0
- package/types/src/const.d.ts +32 -0
- package/types/src/health/health.controller.d.ts +16 -0
- package/types/src/health/health.extensions.d.ts +31 -0
- package/types/src/health/index.d.ts +4 -0
- package/types/src/health/readiness.service.d.ts +9 -0
- package/types/src/health/readiness.types.d.ts +14 -0
- package/types/src/hosting/hosted-service-host.d.ts +37 -0
- package/types/src/hosting/hosted-service.d.ts +31 -0
- package/types/src/hosting/index.d.ts +2 -0
- package/types/src/http/http.compression.d.ts +32 -0
- package/types/src/http/http.extensions.d.ts +79 -0
- package/types/src/http/http.options.d.ts +39 -0
- package/types/src/http/http.options.store.d.ts +7 -0
- package/types/src/http/http.security.d.ts +20 -0
- package/types/src/http/http.static.d.ts +160 -0
- package/types/src/http/index.d.ts +5 -0
- package/types/src/index.d.ts +10 -0
- package/types/src/openapi/index.d.ts +6 -0
- package/types/src/openapi/openapi.generator.d.ts +6 -0
- package/types/src/openapi/openapi.types.d.ts +58 -0
- package/types/src/openapi/request-schema.d.ts +21 -0
- package/types/src/openapi/request-validator.d.ts +9 -0
- package/types/src/providers/fastify.provider.d.ts +56 -0
- package/types/src/providers/index.d.ts +1 -0
- package/types/src/routing/anvil.types.d.ts +119 -0
- package/types/src/routing/decorators/argument.decorator.d.ts +11 -0
- package/types/src/routing/decorators/auth.decorator.d.ts +30 -0
- package/types/src/routing/decorators/controller.decorator.d.ts +3 -0
- package/types/src/routing/decorators/field.decorator.d.ts +2 -0
- package/types/src/routing/decorators/index.d.ts +7 -0
- package/types/src/routing/decorators/request.decorator.d.ts +8 -0
- package/types/src/routing/decorators/response.decorator.d.ts +4 -0
- package/types/src/routing/decorators/route.decorator.d.ts +7 -0
- package/types/src/routing/filters/exception-filter-host.d.ts +19 -0
- package/types/src/routing/filters/exception-filter.d.ts +16 -0
- package/types/src/routing/index.d.ts +8 -0
- package/types/src/routing/middleware/http-access-log.middleware.d.ts +8 -0
- package/types/src/routing/middleware/middleware.d.ts +10 -0
- package/types/src/routing/middleware/request-id.d.ts +6 -0
- package/types/src/routing/path.util.d.ts +9 -0
- package/types/src/routing/pipes/index.d.ts +1 -0
- package/types/src/routing/pipes/pipes.d.ts +21 -0
- package/types/src/routing/services/index.d.ts +1 -0
- package/types/src/routing/services/route-argument-resolver.d.ts +10 -0
- package/types/src/routing/services/route-registry.d.ts +20 -0
- package/types/src/routing/services/router.d.ts +22 -0
- package/types/src/sse/index.d.ts +3 -0
- package/types/src/sse/sse.decorator.d.ts +17 -0
- package/types/src/sse/sse.encoder.d.ts +16 -0
- package/types/src/sse/sse.types.d.ts +37 -0
- package/types/src/sse/sse.wire.d.ts +9 -0
- package/types/src/testing/boot-module.d.ts +34 -0
- package/types/src/testing/index.d.ts +4 -0
- package/types/src/testing/sse-reader.d.ts +29 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get AllowAnonymous () {
|
|
13
|
+
return AllowAnonymous;
|
|
14
|
+
},
|
|
15
|
+
get Authorize () {
|
|
16
|
+
return Authorize;
|
|
17
|
+
},
|
|
18
|
+
get CurrentUser () {
|
|
19
|
+
return CurrentUser;
|
|
20
|
+
},
|
|
21
|
+
get getAuthorizeOptions () {
|
|
22
|
+
return getAuthorizeOptions;
|
|
23
|
+
},
|
|
24
|
+
get isAllowAnonymous () {
|
|
25
|
+
return isAllowAnonymous;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const _reflection = require("@decohere/core/reflection");
|
|
29
|
+
const _const = require("../../const.js");
|
|
30
|
+
function Authorize(action, subject = "all") {
|
|
31
|
+
const options = {
|
|
32
|
+
action,
|
|
33
|
+
subject
|
|
34
|
+
};
|
|
35
|
+
return (target, methodName, _descriptor)=>{
|
|
36
|
+
if (methodName) {
|
|
37
|
+
const fn = target[methodName];
|
|
38
|
+
(0, _reflection.defineMeta)(_const.MetadataKeys.authorize, options, fn);
|
|
39
|
+
} else {
|
|
40
|
+
(0, _reflection.defineMeta)(_const.MetadataKeys.authorize, options, target.prototype);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function AllowAnonymous() {
|
|
45
|
+
return (target, methodName, _descriptor)=>{
|
|
46
|
+
const fn = target[methodName];
|
|
47
|
+
(0, _reflection.defineMeta)(_const.MetadataKeys.allowAnonymous, true, fn);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function getAuthorizeOptions(controllerPrototype, handlerFn) {
|
|
51
|
+
// Method-level overrides class-level
|
|
52
|
+
const methodLevel = (0, _reflection.getMeta)(_const.MetadataKeys.authorize, handlerFn);
|
|
53
|
+
if (methodLevel !== undefined) return methodLevel;
|
|
54
|
+
return (0, _reflection.getMeta)(_const.MetadataKeys.authorize, controllerPrototype);
|
|
55
|
+
}
|
|
56
|
+
function isAllowAnonymous(_controllerPrototype, handlerFn) {
|
|
57
|
+
return (0, _reflection.getMeta)(_const.MetadataKeys.allowAnonymous, handlerFn) === true;
|
|
58
|
+
}
|
|
59
|
+
function CurrentUser() {
|
|
60
|
+
return (target, propertyKey, parameterIndex)=>{
|
|
61
|
+
const fn = target[propertyKey];
|
|
62
|
+
const meta = {
|
|
63
|
+
argumentIndex: parameterIndex,
|
|
64
|
+
argumentLocation: "principal",
|
|
65
|
+
mappingKey: undefined,
|
|
66
|
+
pipes: []
|
|
67
|
+
};
|
|
68
|
+
(0, _reflection.defineArgumentMeta)(_const.MetadataKeys.parameter, meta, fn, parameterIndex);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Controller", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Controller;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _const = require("../../const.js");
|
|
12
|
+
function Controller(options) {
|
|
13
|
+
return (target)=>{
|
|
14
|
+
Reflect.defineMetadata(_const.MetadataKeys.controller, options, target.prototype);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Field", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Field;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _reflection = require("@decohere/core/reflection");
|
|
12
|
+
const _const = require("../../const.js");
|
|
13
|
+
function Field(fieldLocation, mappingKey) {
|
|
14
|
+
return (target, fieldName)=>{
|
|
15
|
+
const fieldMap = (0, _reflection.getMeta)(_const.MetadataKeys.fieldMap, target) ?? new Map();
|
|
16
|
+
const fieldType = (0, _reflection.getFieldType)(target, fieldName);
|
|
17
|
+
fieldMap.set(fieldName, {
|
|
18
|
+
fieldKey: fieldName,
|
|
19
|
+
mappingKey,
|
|
20
|
+
fieldType,
|
|
21
|
+
fieldLocation
|
|
22
|
+
});
|
|
23
|
+
(0, _reflection.defineMeta)(_const.MetadataKeys.fieldMap, fieldMap, target);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./argument.decorator.js"), exports);
|
|
6
|
+
_export_star(require("./auth.decorator.js"), exports);
|
|
7
|
+
_export_star(require("./controller.decorator.js"), exports);
|
|
8
|
+
_export_star(require("./field.decorator.js"), exports);
|
|
9
|
+
_export_star(require("./request.decorator.js"), exports);
|
|
10
|
+
_export_star(require("./response.decorator.js"), exports);
|
|
11
|
+
_export_star(require("./route.decorator.js"), exports);
|
|
12
|
+
function _export_star(from, to) {
|
|
13
|
+
Object.keys(from).forEach(function(k) {
|
|
14
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
15
|
+
Object.defineProperty(to, k, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function() {
|
|
18
|
+
return from[k];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return from;
|
|
24
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Request", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Request;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _reflection = require("@decohere/core/reflection");
|
|
12
|
+
const _const = require("../../const.js");
|
|
13
|
+
function Request(mappingKey) {
|
|
14
|
+
return (target)=>{
|
|
15
|
+
const inst = new target();
|
|
16
|
+
const fieldMap = (0, _reflection.getMeta)(_const.MetadataKeys.fieldMap, target.prototype) ?? new Map();
|
|
17
|
+
const fields = (0, _reflection.getFields)(inst);
|
|
18
|
+
for (const field of fields){
|
|
19
|
+
const fieldType = (0, _reflection.getFieldType)(target.prototype, field.key);
|
|
20
|
+
const overrides = fieldMap.get(field.key);
|
|
21
|
+
fieldMap.set(field.key, {
|
|
22
|
+
fieldKey: field.key,
|
|
23
|
+
mappingKey: overrides?.mappingKey ?? field.key,
|
|
24
|
+
fieldType: overrides?.fieldType ?? fieldType,
|
|
25
|
+
fieldLocation: overrides?.fieldLocation ?? mappingKey
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
(0, _reflection.defineMeta)(_const.MetadataKeys.fieldMap, fieldMap, target.prototype);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get Header () {
|
|
13
|
+
return Header;
|
|
14
|
+
},
|
|
15
|
+
get HttpCode () {
|
|
16
|
+
return HttpCode;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _reflection = require("@decohere/core/reflection");
|
|
20
|
+
const _const = require("../../const.js");
|
|
21
|
+
function HttpCode(statusCode) {
|
|
22
|
+
return (_target, _methodName, descriptor)=>{
|
|
23
|
+
(0, _reflection.defineMeta)(_const.MetadataKeys.httpCode, statusCode, descriptor.value);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function Header(name, value) {
|
|
27
|
+
return (_target, _methodName, descriptor)=>{
|
|
28
|
+
const existing = (0, _reflection.getMeta)(_const.MetadataKeys.headers, descriptor.value) ?? {};
|
|
29
|
+
(0, _reflection.defineMeta)(_const.MetadataKeys.headers, {
|
|
30
|
+
...existing,
|
|
31
|
+
[name]: value
|
|
32
|
+
}, descriptor.value);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get Delete () {
|
|
13
|
+
return Delete;
|
|
14
|
+
},
|
|
15
|
+
get Get () {
|
|
16
|
+
return Get;
|
|
17
|
+
},
|
|
18
|
+
get Patch () {
|
|
19
|
+
return Patch;
|
|
20
|
+
},
|
|
21
|
+
get Post () {
|
|
22
|
+
return Post;
|
|
23
|
+
},
|
|
24
|
+
get Put () {
|
|
25
|
+
return Put;
|
|
26
|
+
},
|
|
27
|
+
get Route () {
|
|
28
|
+
return Route;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const _reflection = require("@decohere/core/reflection");
|
|
32
|
+
const _const = require("../../const.js");
|
|
33
|
+
const _anviltypes = require("../anvil.types.js");
|
|
34
|
+
function Get(path) {
|
|
35
|
+
return routeDecorator(_const.HTTPMethods.GET, path);
|
|
36
|
+
}
|
|
37
|
+
function Post(path) {
|
|
38
|
+
return routeDecorator(_const.HTTPMethods.POST, path);
|
|
39
|
+
}
|
|
40
|
+
function Put(path) {
|
|
41
|
+
return routeDecorator(_const.HTTPMethods.PUT, path);
|
|
42
|
+
}
|
|
43
|
+
function Patch(path) {
|
|
44
|
+
return routeDecorator(_const.HTTPMethods.PATCH, path);
|
|
45
|
+
}
|
|
46
|
+
function Delete(path) {
|
|
47
|
+
return routeDecorator(_const.HTTPMethods.DELETE, path);
|
|
48
|
+
}
|
|
49
|
+
function Route(method, path) {
|
|
50
|
+
return routeDecorator(method, path);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Store method + relative path only. Controller / global prefixes are applied
|
|
54
|
+
* at registration time in RouteRegistry (avoids TS decorator-order issues).
|
|
55
|
+
*/ function routeDecorator(method, path = "") {
|
|
56
|
+
return (targetClass, functionName, descriptor)=>{
|
|
57
|
+
if (path !== "" && !path.startsWith("/")) {
|
|
58
|
+
throw new _anviltypes.RouteConfigurationError(`Error configuring routes. Path defined in controller ${targetClass.constructor.name}.${functionName}() should start '/'`);
|
|
59
|
+
}
|
|
60
|
+
const { value: handler } = descriptor;
|
|
61
|
+
const routeConfig = {
|
|
62
|
+
method,
|
|
63
|
+
path
|
|
64
|
+
};
|
|
65
|
+
(0, _reflection.defineMeta)(_const.MetadataKeys.route, routeConfig, handler);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get DefaultHttpExceptionFilter () {
|
|
13
|
+
return DefaultHttpExceptionFilter;
|
|
14
|
+
},
|
|
15
|
+
get ExceptionFilterHost () {
|
|
16
|
+
return ExceptionFilterHost;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _crucible = require("@decohere/crucible");
|
|
20
|
+
const _decorators = require("@decohere/crucible/decorators");
|
|
21
|
+
const _scribe = require("@decohere/scribe");
|
|
22
|
+
const _const = require("../../const.js");
|
|
23
|
+
const _anviltypes = require("../anvil.types.js");
|
|
24
|
+
const _exceptionfilter = require("./exception-filter.js");
|
|
25
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
26
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
27
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
28
|
+
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;
|
|
29
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
30
|
+
}
|
|
31
|
+
function _ts_metadata(k, v) {
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
+
}
|
|
34
|
+
function _ts_param(paramIndex, decorator) {
|
|
35
|
+
return function(target, key) {
|
|
36
|
+
decorator(target, key, paramIndex);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
class DefaultHttpExceptionFilter {
|
|
40
|
+
logger = _scribe.scribe.logger(DefaultHttpExceptionFilter.name);
|
|
41
|
+
catch(error, _ctx) {
|
|
42
|
+
if (error instanceof _anviltypes.ValidationError) {
|
|
43
|
+
return {
|
|
44
|
+
status: 400,
|
|
45
|
+
body: {
|
|
46
|
+
statusCode: 400,
|
|
47
|
+
error: "Bad Request",
|
|
48
|
+
message: error.message,
|
|
49
|
+
errors: error.errors
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (error instanceof _anviltypes.HttpError) {
|
|
54
|
+
// Never expose internal auth failure details (header shape, issuer, etc.) to clients.
|
|
55
|
+
if (error.status === 401) {
|
|
56
|
+
this.logger.warn(error.message);
|
|
57
|
+
return {
|
|
58
|
+
status: 401,
|
|
59
|
+
body: {
|
|
60
|
+
message: "Unauthorized"
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Sanitize only true 500s. Keep intentional 503 probe messages (e.g. /ready).
|
|
65
|
+
if (error.status === 500) {
|
|
66
|
+
this.logger.error(error.message);
|
|
67
|
+
return {
|
|
68
|
+
status: 500,
|
|
69
|
+
body: {
|
|
70
|
+
message: "Internal Server Error"
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
status: error.status,
|
|
76
|
+
body: {
|
|
77
|
+
message: error.message
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (error instanceof Error) {
|
|
82
|
+
this.logger.error(error.message, error.stack);
|
|
83
|
+
return {
|
|
84
|
+
status: 500,
|
|
85
|
+
body: {
|
|
86
|
+
message: "Internal Server Error"
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
status: 500,
|
|
92
|
+
body: {
|
|
93
|
+
message: "Internal Server Error"
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
DefaultHttpExceptionFilter = _ts_decorate([
|
|
99
|
+
(0, _decorators.injectable)()
|
|
100
|
+
], DefaultHttpExceptionFilter);
|
|
101
|
+
class ExceptionFilterHost {
|
|
102
|
+
options;
|
|
103
|
+
scope;
|
|
104
|
+
filters;
|
|
105
|
+
constructor(options, scope){
|
|
106
|
+
this.options = options;
|
|
107
|
+
this.scope = scope;
|
|
108
|
+
}
|
|
109
|
+
async handle(error, ctx) {
|
|
110
|
+
for (const filter of this.getFilters()){
|
|
111
|
+
const filterType = filter.constructor;
|
|
112
|
+
const types = (0, _exceptionfilter.getCatchTypes)(filterType);
|
|
113
|
+
if (types.length === 0 || types.some((t)=>error instanceof t)) {
|
|
114
|
+
return await filter.catch(error, ctx);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return new DefaultHttpExceptionFilter().catch(error, ctx);
|
|
118
|
+
}
|
|
119
|
+
getFilters() {
|
|
120
|
+
if (this.filters != null) {
|
|
121
|
+
return this.filters;
|
|
122
|
+
}
|
|
123
|
+
const custom = this.options?.filterTypes.map((type)=>{
|
|
124
|
+
if (this.scope == null) {
|
|
125
|
+
return new type();
|
|
126
|
+
}
|
|
127
|
+
return this.scope.resolve(type);
|
|
128
|
+
}) ?? [];
|
|
129
|
+
this.filters = [
|
|
130
|
+
...custom,
|
|
131
|
+
new DefaultHttpExceptionFilter()
|
|
132
|
+
];
|
|
133
|
+
return this.filters;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
ExceptionFilterHost = _ts_decorate([
|
|
137
|
+
(0, _decorators.injectable)(),
|
|
138
|
+
_ts_param(0, (0, _decorators.inject)(_const.HttpOptionsToken)),
|
|
139
|
+
_ts_param(1, (0, _decorators.inject)(_crucible.LifetimeScopeToken)),
|
|
140
|
+
_ts_metadata("design:type", Function),
|
|
141
|
+
_ts_metadata("design:paramtypes", [
|
|
142
|
+
typeof HttpOptions === "undefined" ? Object : HttpOptions,
|
|
143
|
+
typeof LifetimeScope === "undefined" ? Object : LifetimeScope
|
|
144
|
+
])
|
|
145
|
+
], ExceptionFilterHost);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get Catch () {
|
|
13
|
+
return Catch;
|
|
14
|
+
},
|
|
15
|
+
get getCatchTypes () {
|
|
16
|
+
return getCatchTypes;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _reflection = require("@decohere/core/reflection");
|
|
20
|
+
const _const = require("../../const.js");
|
|
21
|
+
function Catch(...types) {
|
|
22
|
+
return (target)=>{
|
|
23
|
+
(0, _reflection.defineMeta)(_const.MetadataKeys.catch, types, target);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function getCatchTypes(filterType) {
|
|
27
|
+
return (0, _reflection.getMeta)(_const.MetadataKeys.catch, filterType) ?? [];
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./anvil.types.js"), exports);
|
|
6
|
+
_export_star(require("./decorators/index.js"), exports);
|
|
7
|
+
_export_star(require("./filters/exception-filter.js"), exports);
|
|
8
|
+
_export_star(require("./filters/exception-filter-host.js"), exports);
|
|
9
|
+
_export_star(require("./middleware/http-access-log.middleware.js"), exports);
|
|
10
|
+
_export_star(require("./middleware/middleware.js"), exports);
|
|
11
|
+
_export_star(require("./middleware/request-id.js"), exports);
|
|
12
|
+
_export_star(require("./pipes/index.js"), exports);
|
|
13
|
+
function _export_star(from, to) {
|
|
14
|
+
Object.keys(from).forEach(function(k) {
|
|
15
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
16
|
+
Object.defineProperty(to, k, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function() {
|
|
19
|
+
return from[k];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return from;
|
|
25
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "HttpAccessLogMiddleware", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return HttpAccessLogMiddleware;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _decorators = require("@decohere/crucible/decorators");
|
|
12
|
+
const _scribe = require("@decohere/scribe");
|
|
13
|
+
const _anviltypes = require("../anvil.types.js");
|
|
14
|
+
const _requestid = require("./request-id.js");
|
|
15
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
16
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
17
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
18
|
+
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;
|
|
19
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
20
|
+
}
|
|
21
|
+
class HttpAccessLogMiddleware {
|
|
22
|
+
async use(ctx, next) {
|
|
23
|
+
const logger = _scribe.scribe.logger(HttpAccessLogMiddleware.name);
|
|
24
|
+
const start = performance.now();
|
|
25
|
+
ctx.request.responseHeaders[_requestid.REQUEST_ID_HEADER] = ctx.request.requestId;
|
|
26
|
+
let status = ctx.route.httpCode ?? 200;
|
|
27
|
+
try {
|
|
28
|
+
return await next();
|
|
29
|
+
} catch (error) {
|
|
30
|
+
status = error instanceof _anviltypes.HttpError ? error.status : 500;
|
|
31
|
+
throw error;
|
|
32
|
+
} finally{
|
|
33
|
+
const durationMs = Math.round(performance.now() - start);
|
|
34
|
+
logger.info({
|
|
35
|
+
msg: "access",
|
|
36
|
+
method: ctx.request.method,
|
|
37
|
+
path: ctx.request.url,
|
|
38
|
+
status,
|
|
39
|
+
durationMs,
|
|
40
|
+
requestId: ctx.request.requestId
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
HttpAccessLogMiddleware = _ts_decorate([
|
|
46
|
+
(0, _decorators.injectable)()
|
|
47
|
+
], HttpAccessLogMiddleware);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "composeMiddleware", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return composeMiddleware;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function composeMiddleware(middlewares, handler, ctx) {
|
|
12
|
+
const dispatch = (index)=>{
|
|
13
|
+
if (index >= middlewares.length) {
|
|
14
|
+
return handler();
|
|
15
|
+
}
|
|
16
|
+
const middleware = middlewares[index];
|
|
17
|
+
return middleware.use(ctx, ()=>dispatch(index + 1));
|
|
18
|
+
};
|
|
19
|
+
return dispatch(0);
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get REQUEST_ID_HEADER () {
|
|
13
|
+
return REQUEST_ID_HEADER;
|
|
14
|
+
},
|
|
15
|
+
get resolveRequestId () {
|
|
16
|
+
return resolveRequestId;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _nodecrypto = require("node:crypto");
|
|
20
|
+
const REQUEST_ID_HEADER = "x-request-id";
|
|
21
|
+
function resolveRequestId(headers, fallback) {
|
|
22
|
+
const fromHeader = headers[REQUEST_ID_HEADER]?.trim();
|
|
23
|
+
if (fromHeader) {
|
|
24
|
+
return fromHeader;
|
|
25
|
+
}
|
|
26
|
+
if (fallback?.trim()) {
|
|
27
|
+
return fallback.trim();
|
|
28
|
+
}
|
|
29
|
+
return (0, _nodecrypto.randomUUID)();
|
|
30
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Normalize a prefix to `/foo` form with no trailing slash. Empty → `""`. */ "use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get applyGlobalPrefix () {
|
|
13
|
+
return applyGlobalPrefix;
|
|
14
|
+
},
|
|
15
|
+
get joinRoutePath () {
|
|
16
|
+
return joinRoutePath;
|
|
17
|
+
},
|
|
18
|
+
get normalizePrefix () {
|
|
19
|
+
return normalizePrefix;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
function normalizePrefix(prefix) {
|
|
23
|
+
if (prefix == null || prefix === "" || prefix === "/") {
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
const withSlash = prefix.startsWith("/") ? prefix : `/${prefix}`;
|
|
27
|
+
return withSlash.replace(/\/+$/, "");
|
|
28
|
+
}
|
|
29
|
+
function joinRoutePath(prefix, routePath) {
|
|
30
|
+
const p = normalizePrefix(prefix);
|
|
31
|
+
if (routePath === "" || routePath == null) {
|
|
32
|
+
return p === "" ? "/" : p;
|
|
33
|
+
}
|
|
34
|
+
if (routePath === "/") {
|
|
35
|
+
return p === "" ? "/" : `${p}/`;
|
|
36
|
+
}
|
|
37
|
+
if (!routePath.startsWith("/")) {
|
|
38
|
+
throw new Error(`Route path must start with '/': ${routePath}`);
|
|
39
|
+
}
|
|
40
|
+
return `${p}${routePath}`;
|
|
41
|
+
}
|
|
42
|
+
function applyGlobalPrefix(globalPrefix, path) {
|
|
43
|
+
const g = normalizePrefix(globalPrefix);
|
|
44
|
+
if (g === "") {
|
|
45
|
+
return path === "" ? "/" : path;
|
|
46
|
+
}
|
|
47
|
+
if (path === "/") {
|
|
48
|
+
return `${g}/`;
|
|
49
|
+
}
|
|
50
|
+
return `${g}${path.startsWith("/") ? path : `/${path}`}`;
|
|
51
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./pipes.js"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|