@theokit/http 0.5.4 → 0.7.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/LICENSE +201 -0
- package/dist/app.d.ts +16 -0
- package/dist/app.js +3 -3
- package/dist/{chunk-34KOKJ5M.js → chunk-CMPP4ULU.js} +3 -3
- package/dist/{chunk-U46H4CGF.js → chunk-ELCXHPAD.js} +2 -2
- package/dist/{chunk-NDD7ANXZ.js → chunk-GXTGOPRU.js} +124 -6
- package/dist/chunk-GXTGOPRU.js.map +1 -0
- package/dist/{chunk-QGB5YC4T.js → chunk-JQMJK47T.js} +31 -4
- package/dist/chunk-JQMJK47T.js.map +1 -0
- package/dist/{chunk-3PGQVQWG.js → chunk-KPC7AIVC.js} +3 -1
- package/dist/chunk-KPC7AIVC.js.map +1 -0
- package/dist/{chunk-LKNI6QEP.js → chunk-MQAJWR3K.js} +1 -1
- package/dist/chunk-MQAJWR3K.js.map +1 -0
- package/dist/chunk-OBHHOS6E.js +257 -0
- package/dist/chunk-OBHHOS6E.js.map +1 -0
- package/dist/exception-filter-chain-V2MFO4WV.js +10 -0
- package/dist/index.d.ts +343 -8
- package/dist/index.js +230 -23
- package/dist/index.js.map +1 -1
- package/dist/interceptor-chain-ELSL6KZT.js +9 -0
- package/dist/{middleware-consumer-ljxK1fU_.d.ts → middleware-consumer-DcaksawH.d.ts} +1 -1
- package/dist/theokit-plugin.d.ts +1 -1
- package/dist/theokit-plugin.js +7 -167
- package/dist/theokit-plugin.js.map +1 -1
- package/package.json +19 -17
- package/dist/chunk-3PGQVQWG.js.map +0 -1
- package/dist/chunk-LKNI6QEP.js.map +0 -1
- package/dist/chunk-LWCNTZN6.js +0 -87
- package/dist/chunk-LWCNTZN6.js.map +0 -1
- package/dist/chunk-NDD7ANXZ.js.map +0 -1
- package/dist/chunk-QGB5YC4T.js.map +0 -1
- package/dist/exception-filter-chain-BCSQ3MZ2.js +0 -10
- package/dist/interceptor-chain-6S3PUV7J.js +0 -9
- /package/dist/{chunk-34KOKJ5M.js.map → chunk-CMPP4ULU.js.map} +0 -0
- /package/dist/{chunk-U46H4CGF.js.map → chunk-ELCXHPAD.js.map} +0 -0
- /package/dist/{exception-filter-chain-BCSQ3MZ2.js.map → exception-filter-chain-V2MFO4WV.js.map} +0 -0
- /package/dist/{interceptor-chain-6S3PUV7J.js.map → interceptor-chain-ELSL6KZT.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -2,35 +2,44 @@ import {
|
|
|
2
2
|
TheoApp,
|
|
3
3
|
createStaticHandler,
|
|
4
4
|
getMimeType,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
getRequestContext,
|
|
6
|
+
isSafePath,
|
|
7
|
+
renderToStream,
|
|
8
|
+
streamToResponse,
|
|
9
|
+
tryGetRequestContext
|
|
10
|
+
} from "./chunk-GXTGOPRU.js";
|
|
7
11
|
import {
|
|
8
12
|
MiddlewareConsumerImpl,
|
|
13
|
+
isControllerClass,
|
|
14
|
+
loadControllerWithSwc,
|
|
15
|
+
loadControllersFromGlob,
|
|
9
16
|
middlewareMatchesPath,
|
|
10
|
-
runMiddleware
|
|
11
|
-
|
|
17
|
+
runMiddleware,
|
|
18
|
+
transformControllerSource
|
|
19
|
+
} from "./chunk-OBHHOS6E.js";
|
|
12
20
|
import {
|
|
13
21
|
HttpDecoratorsConfigError,
|
|
14
22
|
createExecutionContext,
|
|
15
23
|
joinPath,
|
|
16
24
|
resolveDtoSchema,
|
|
17
25
|
walkControllerMetadata
|
|
18
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-JQMJK47T.js";
|
|
19
27
|
import {
|
|
20
28
|
createNodeAdapter
|
|
21
29
|
} from "./chunk-HLW7YKZE.js";
|
|
22
30
|
import {
|
|
23
31
|
runInterceptors
|
|
24
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-ELCXHPAD.js";
|
|
25
33
|
import {
|
|
26
34
|
runExceptionFilters
|
|
27
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-CMPP4ULU.js";
|
|
28
36
|
import {
|
|
29
37
|
BadGatewayException,
|
|
30
38
|
BadRequestException,
|
|
31
39
|
CATCH_EXCEPTIONS,
|
|
32
40
|
CONTROLLER_PREFIX,
|
|
33
41
|
ConflictException,
|
|
42
|
+
EXPOSE_AGENT,
|
|
34
43
|
ForbiddenException,
|
|
35
44
|
GatewayTimeoutException,
|
|
36
45
|
GoneException,
|
|
@@ -61,10 +70,10 @@ import {
|
|
|
61
70
|
UnsupportedMediaTypeException,
|
|
62
71
|
getMeta,
|
|
63
72
|
setMeta
|
|
64
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-KPC7AIVC.js";
|
|
65
74
|
import {
|
|
66
75
|
resolveOrNew
|
|
67
|
-
} from "./chunk-
|
|
76
|
+
} from "./chunk-MQAJWR3K.js";
|
|
68
77
|
import {
|
|
69
78
|
__name
|
|
70
79
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -170,6 +179,20 @@ function Res(opts) {
|
|
|
170
179
|
}
|
|
171
180
|
__name(Res, "Res");
|
|
172
181
|
|
|
182
|
+
// src/decorators/expose.ts
|
|
183
|
+
function Expose(agent, opts = {}) {
|
|
184
|
+
return (target, propertyKey) => {
|
|
185
|
+
const existing = getMeta(EXPOSE_AGENT, target.constructor) ?? [];
|
|
186
|
+
existing.push({
|
|
187
|
+
agent,
|
|
188
|
+
opts,
|
|
189
|
+
propertyKey
|
|
190
|
+
});
|
|
191
|
+
setMeta(EXPOSE_AGENT, target.constructor, existing);
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
__name(Expose, "Expose");
|
|
195
|
+
|
|
173
196
|
// src/decorators/response.ts
|
|
174
197
|
function HttpCode(status) {
|
|
175
198
|
return (target, propertyKey) => {
|
|
@@ -415,11 +438,12 @@ __name(registerControllers, "registerControllers");
|
|
|
415
438
|
|
|
416
439
|
// src/bridge/create-server.ts
|
|
417
440
|
import "reflect-metadata";
|
|
418
|
-
function
|
|
419
|
-
const { controllers, container, configure } = Array.isArray(controllersOrOpts) ? {
|
|
441
|
+
function createDecoratorHandler(controllersOrOpts) {
|
|
442
|
+
const { controllers, container, configure, serveAgent } = Array.isArray(controllersOrOpts) ? {
|
|
420
443
|
controllers: controllersOrOpts,
|
|
421
444
|
container: void 0,
|
|
422
|
-
configure: void 0
|
|
445
|
+
configure: void 0,
|
|
446
|
+
serveAgent: void 0
|
|
423
447
|
} : controllersOrOpts;
|
|
424
448
|
const middlewareConsumer = new MiddlewareConsumerImpl(container);
|
|
425
449
|
if (configure) configure(middlewareConsumer);
|
|
@@ -448,24 +472,33 @@ function createDecoratorServer(controllersOrOpts) {
|
|
|
448
472
|
if (aP !== bP) return aP ? 1 : -1;
|
|
449
473
|
return 0;
|
|
450
474
|
});
|
|
475
|
+
const handler = /* @__PURE__ */ __name((request) => handleRequest(routes, request, container, middlewareEntries, serveAgent), "handler");
|
|
476
|
+
handler.matches = (method, pathname) => findRoute(routes, method.toUpperCase(), pathname) !== null;
|
|
477
|
+
return handler;
|
|
478
|
+
}
|
|
479
|
+
__name(createDecoratorHandler, "createDecoratorHandler");
|
|
480
|
+
function createDecoratorServer(controllersOrOpts) {
|
|
481
|
+
const handle = createDecoratorHandler(controllersOrOpts);
|
|
451
482
|
const adapter = createNodeAdapter();
|
|
452
|
-
|
|
453
|
-
|
|
483
|
+
return adapter.createServer(async (request) => {
|
|
484
|
+
const res = await handle(request);
|
|
485
|
+
if (res) return res;
|
|
486
|
+
const { pathname } = new URL(request.url);
|
|
487
|
+
return jsonResponse(404, {
|
|
488
|
+
error: {
|
|
489
|
+
code: "NOT_FOUND",
|
|
490
|
+
message: `No route for ${request.method.toUpperCase()} ${pathname}`
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
});
|
|
454
494
|
}
|
|
455
495
|
__name(createDecoratorServer, "createDecoratorServer");
|
|
456
|
-
async function handleRequest(routes, request, container, middlewareEntries = []) {
|
|
496
|
+
async function handleRequest(routes, request, container, middlewareEntries = [], serveAgent) {
|
|
457
497
|
const url = new URL(request.url);
|
|
458
498
|
const method = request.method.toUpperCase();
|
|
459
499
|
const pathname = url.pathname;
|
|
460
500
|
const match = findRoute(routes, method, pathname);
|
|
461
|
-
if (!match)
|
|
462
|
-
return jsonResponse(404, {
|
|
463
|
-
error: {
|
|
464
|
-
code: "NOT_FOUND",
|
|
465
|
-
message: `No route for ${method} ${pathname}`
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
}
|
|
501
|
+
if (!match) return null;
|
|
469
502
|
const { walk, instance, params } = match;
|
|
470
503
|
try {
|
|
471
504
|
const mwResponse = await runMiddleware(middlewareEntries, request, pathname);
|
|
@@ -473,6 +506,17 @@ async function handleRequest(routes, request, container, middlewareEntries = [])
|
|
|
473
506
|
const ctx = createExecutionContext(request, instance.constructor, walk.propertyKey);
|
|
474
507
|
const guardResponse = await runGuards(walk.guards, ctx, container);
|
|
475
508
|
if (guardResponse) return guardResponse;
|
|
509
|
+
if (walk.agent) {
|
|
510
|
+
if (!serveAgent) {
|
|
511
|
+
return jsonResponse(500, {
|
|
512
|
+
error: {
|
|
513
|
+
code: "AGENT_SERVER_NOT_WIRED",
|
|
514
|
+
message: `Controller route ${String(walk.propertyKey)} is @Expose-bound but no serveAgent was provided to createDecoratorHandler. The framework must wire serveAgent (mountAgent).`
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
return await serveAgent(walk.agent.module, request, walk.agent.opts);
|
|
519
|
+
}
|
|
476
520
|
const body = await resolveBody(method, request, walk);
|
|
477
521
|
if (body instanceof Response) return body;
|
|
478
522
|
const args = buildArgs(walk.paramEntries, {
|
|
@@ -491,6 +535,7 @@ async function handleRequest(routes, request, container, middlewareEntries = [])
|
|
|
491
535
|
}
|
|
492
536
|
const handlerFn = instance[walk.propertyKey];
|
|
493
537
|
const result = await runInterceptors(walk.interceptors, () => handlerFn.apply(instance, args), request, container);
|
|
538
|
+
if (result instanceof Response) return result;
|
|
494
539
|
return buildResponse(result, walk, method);
|
|
495
540
|
} catch (err) {
|
|
496
541
|
return runExceptionFilters(err, walk.filters, request, container);
|
|
@@ -690,6 +735,152 @@ function contract(routes) {
|
|
|
690
735
|
return routes;
|
|
691
736
|
}
|
|
692
737
|
__name(contract, "contract");
|
|
738
|
+
|
|
739
|
+
// src/error-digest.ts
|
|
740
|
+
function djb2(input) {
|
|
741
|
+
let hash = 5381;
|
|
742
|
+
for (let i = 0; i < input.length; i++) {
|
|
743
|
+
hash = (hash << 5) + hash + input.charCodeAt(i) | 0;
|
|
744
|
+
}
|
|
745
|
+
return (hash >>> 0).toString(16);
|
|
746
|
+
}
|
|
747
|
+
__name(djb2, "djb2");
|
|
748
|
+
function digestError(err, context = {}) {
|
|
749
|
+
const message = extractMessage(err);
|
|
750
|
+
const status = extractStatus(err);
|
|
751
|
+
const rawStack = extractStack(err);
|
|
752
|
+
const digest = djb2(message);
|
|
753
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
754
|
+
return {
|
|
755
|
+
digest,
|
|
756
|
+
message,
|
|
757
|
+
status,
|
|
758
|
+
context,
|
|
759
|
+
...rawStack && !isProduction ? {
|
|
760
|
+
stack: rawStack
|
|
761
|
+
} : {}
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
__name(digestError, "digestError");
|
|
765
|
+
function extractMessage(err) {
|
|
766
|
+
if (err instanceof Error) {
|
|
767
|
+
return err.message;
|
|
768
|
+
}
|
|
769
|
+
if (typeof err === "string") {
|
|
770
|
+
return err;
|
|
771
|
+
}
|
|
772
|
+
if (typeof err === "number") {
|
|
773
|
+
return String(err);
|
|
774
|
+
}
|
|
775
|
+
try {
|
|
776
|
+
return JSON.stringify(err);
|
|
777
|
+
} catch {
|
|
778
|
+
return "Unknown error";
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
__name(extractMessage, "extractMessage");
|
|
782
|
+
function extractStatus(err) {
|
|
783
|
+
if (err instanceof HttpException) {
|
|
784
|
+
return err.statusCode;
|
|
785
|
+
}
|
|
786
|
+
return 500;
|
|
787
|
+
}
|
|
788
|
+
__name(extractStatus, "extractStatus");
|
|
789
|
+
function extractStack(err) {
|
|
790
|
+
if (err instanceof Error) {
|
|
791
|
+
return err.stack;
|
|
792
|
+
}
|
|
793
|
+
return void 0;
|
|
794
|
+
}
|
|
795
|
+
__name(extractStack, "extractStack");
|
|
796
|
+
|
|
797
|
+
// src/component-tree.ts
|
|
798
|
+
function createErrorBoundary(React, FallbackComponent) {
|
|
799
|
+
return class ErrorBoundary extends React.Component {
|
|
800
|
+
static {
|
|
801
|
+
__name(this, "ErrorBoundary");
|
|
802
|
+
}
|
|
803
|
+
constructor(props) {
|
|
804
|
+
super(props);
|
|
805
|
+
this.state = {
|
|
806
|
+
hasError: false
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
static getDerivedStateFromError() {
|
|
810
|
+
return {
|
|
811
|
+
hasError: true
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
render() {
|
|
815
|
+
if (this.state.hasError) {
|
|
816
|
+
return React.createElement(FallbackComponent);
|
|
817
|
+
}
|
|
818
|
+
return React.createElement(React.Fragment, null, this.props.children);
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
__name(createErrorBoundary, "createErrorBoundary");
|
|
823
|
+
async function composeComponentTree(tree) {
|
|
824
|
+
const React = await import("react");
|
|
825
|
+
return composeNode(React, tree);
|
|
826
|
+
}
|
|
827
|
+
__name(composeComponentTree, "composeComponentTree");
|
|
828
|
+
function composeNode(React, node) {
|
|
829
|
+
const { layout: Layout, page: Page, loading: Loading, error: ErrorFallback } = node;
|
|
830
|
+
if (!Page) {
|
|
831
|
+
return null;
|
|
832
|
+
}
|
|
833
|
+
let element = React.createElement(Page);
|
|
834
|
+
if (Loading) {
|
|
835
|
+
element = React.createElement(React.Suspense, {
|
|
836
|
+
fallback: React.createElement(Loading)
|
|
837
|
+
}, element);
|
|
838
|
+
}
|
|
839
|
+
if (ErrorFallback) {
|
|
840
|
+
const Boundary = createErrorBoundary(React, ErrorFallback);
|
|
841
|
+
element = React.createElement(Boundary, null, element);
|
|
842
|
+
}
|
|
843
|
+
if (Layout) {
|
|
844
|
+
element = React.createElement(Layout, null, element);
|
|
845
|
+
}
|
|
846
|
+
return element;
|
|
847
|
+
}
|
|
848
|
+
__name(composeNode, "composeNode");
|
|
849
|
+
|
|
850
|
+
// src/cache-signal.ts
|
|
851
|
+
function revalidateTag(tag) {
|
|
852
|
+
collectSignal({
|
|
853
|
+
kind: "tag",
|
|
854
|
+
value: tag,
|
|
855
|
+
timestamp: Date.now()
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
__name(revalidateTag, "revalidateTag");
|
|
859
|
+
function revalidatePath(path) {
|
|
860
|
+
collectSignal({
|
|
861
|
+
kind: "path",
|
|
862
|
+
value: path,
|
|
863
|
+
timestamp: Date.now()
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
__name(revalidatePath, "revalidatePath");
|
|
867
|
+
function getRevalidationSignals() {
|
|
868
|
+
const ctx = tryGetRequestContext();
|
|
869
|
+
if (!ctx) return [];
|
|
870
|
+
return ctx._revalidationSignals ?? [];
|
|
871
|
+
}
|
|
872
|
+
__name(getRevalidationSignals, "getRevalidationSignals");
|
|
873
|
+
function collectSignal(signal) {
|
|
874
|
+
const ctx = tryGetRequestContext();
|
|
875
|
+
if (!ctx) {
|
|
876
|
+
console.warn("[theokit] revalidateTag/revalidatePath called outside a request context. Signal ignored.");
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
const extended = ctx;
|
|
880
|
+
extended._revalidationSignals ??= [];
|
|
881
|
+
extended._revalidationSignals.push(signal);
|
|
882
|
+
}
|
|
883
|
+
__name(collectSignal, "collectSignal");
|
|
693
884
|
export {
|
|
694
885
|
All,
|
|
695
886
|
BadGatewayException,
|
|
@@ -701,6 +892,8 @@ export {
|
|
|
701
892
|
ConflictException,
|
|
702
893
|
Controller,
|
|
703
894
|
Delete,
|
|
895
|
+
EXPOSE_AGENT,
|
|
896
|
+
Expose,
|
|
704
897
|
ForbiddenException,
|
|
705
898
|
GatewayTimeoutException,
|
|
706
899
|
Get,
|
|
@@ -757,26 +950,40 @@ export {
|
|
|
757
950
|
UseFilters,
|
|
758
951
|
UseGuards,
|
|
759
952
|
UseInterceptors,
|
|
953
|
+
composeComponentTree,
|
|
760
954
|
contract,
|
|
761
955
|
createDecorator,
|
|
956
|
+
createDecoratorHandler,
|
|
762
957
|
createDecoratorServer,
|
|
763
958
|
createExecutionContext,
|
|
764
959
|
createStaticHandler,
|
|
765
960
|
createTypedClient,
|
|
961
|
+
digestError,
|
|
766
962
|
getMeta,
|
|
767
963
|
getMimeType,
|
|
964
|
+
getRequestContext,
|
|
965
|
+
getRevalidationSignals,
|
|
768
966
|
getThrottleOptions,
|
|
967
|
+
isControllerClass,
|
|
769
968
|
isSafePath,
|
|
770
969
|
isThrottleSkipped,
|
|
771
970
|
joinPath,
|
|
971
|
+
loadControllerWithSwc,
|
|
972
|
+
loadControllersFromGlob,
|
|
772
973
|
middlewareMatchesPath,
|
|
773
974
|
registerControllers,
|
|
975
|
+
renderToStream,
|
|
774
976
|
resolveDtoSchema,
|
|
775
977
|
resolveOrNew,
|
|
978
|
+
revalidatePath,
|
|
979
|
+
revalidateTag,
|
|
776
980
|
runExceptionFilters,
|
|
777
981
|
runInterceptors,
|
|
778
982
|
runMiddleware,
|
|
779
983
|
setMeta,
|
|
984
|
+
streamToResponse,
|
|
985
|
+
transformControllerSource,
|
|
986
|
+
tryGetRequestContext,
|
|
780
987
|
walkControllerMetadata
|
|
781
988
|
};
|
|
782
989
|
//# sourceMappingURL=index.js.map
|