gemi 0.1.1 → 0.2.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.
Files changed (85) hide show
  1. package/dist/ApiRouter.d.ts +5 -0
  2. package/dist/ApiRouter.d.ts.map +1 -0
  3. package/dist/Controller.d.ts +3 -0
  4. package/dist/Controller.d.ts.map +1 -0
  5. package/dist/ViewRouter.d.ts +3 -0
  6. package/dist/ViewRouter.d.ts.map +1 -0
  7. package/dist/app/App.d.ts +93 -0
  8. package/dist/app/App.d.ts.map +1 -0
  9. package/dist/app/Plugin.d.ts +10 -0
  10. package/dist/app/Plugin.d.ts.map +1 -0
  11. package/dist/app/index.js +1697 -0
  12. package/dist/bin/gemi +0 -0
  13. package/dist/client/ClientRouter.d.ts +4 -0
  14. package/dist/client/ClientRouter.d.ts.map +1 -0
  15. package/dist/client/ClientRouterContext.d.ts +32 -0
  16. package/dist/client/ClientRouterContext.d.ts.map +1 -0
  17. package/dist/client/Form.d.ts +27 -3
  18. package/dist/client/Form.d.ts.map +1 -1
  19. package/dist/client/Image.d.ts +11 -0
  20. package/dist/client/Image.d.ts.map +1 -0
  21. package/dist/client/Mutation.d.ts +17 -0
  22. package/dist/client/Mutation.d.ts.map +1 -0
  23. package/dist/client/Root.d.ts +2 -0
  24. package/dist/client/Root.d.ts.map +1 -0
  25. package/dist/client/ServerDataProvider.d.ts +33 -0
  26. package/dist/client/ServerDataProvider.d.ts.map +1 -0
  27. package/dist/client/index.d.ts +7 -1
  28. package/dist/client/index.d.ts.map +1 -1
  29. package/dist/client/index.js +1641 -0
  30. package/dist/client/main.d.ts +2 -0
  31. package/dist/client/main.d.ts.map +1 -0
  32. package/dist/client/types.d.ts +4 -0
  33. package/dist/client/types.d.ts.map +1 -0
  34. package/dist/client/useMutation.d.ts +8 -0
  35. package/dist/client/useMutation.d.ts.map +1 -0
  36. package/dist/client/useQuery.d.ts +6 -0
  37. package/dist/client/useQuery.d.ts.map +1 -0
  38. package/dist/client/useUser.d.ts +2 -0
  39. package/dist/client/useUser.d.ts.map +1 -0
  40. package/dist/email/index.js +9098 -0
  41. package/dist/facades/index.js +71 -0
  42. package/dist/http/ApiRouter.d.ts +50 -0
  43. package/dist/http/ApiRouter.d.ts.map +1 -1
  44. package/dist/http/Controller.d.ts +2 -0
  45. package/dist/http/Controller.d.ts.map +1 -1
  46. package/dist/http/Error.d.ts +7 -0
  47. package/dist/http/Error.d.ts.map +1 -0
  48. package/dist/http/HttpRequest.d.ts +21 -0
  49. package/dist/http/HttpRequest.d.ts.map +1 -0
  50. package/dist/http/Middleware.d.ts +4 -0
  51. package/dist/http/Middleware.d.ts.map +1 -0
  52. package/dist/http/Router.d.ts +31 -0
  53. package/dist/http/Router.d.ts.map +1 -0
  54. package/dist/http/ViewRouter.d.ts +30 -0
  55. package/dist/http/ViewRouter.d.ts.map +1 -1
  56. package/dist/http/getCookies.d.ts +2 -0
  57. package/dist/http/getCookies.d.ts.map +1 -0
  58. package/dist/http/index.d.ts +4 -0
  59. package/dist/http/index.d.ts.map +1 -1
  60. package/dist/http/index.js +341 -0
  61. package/dist/http/requestContext.d.ts +4 -0
  62. package/dist/http/requestContext.d.ts.map +1 -0
  63. package/dist/index.d.ts +4 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/server/generateEtag.d.ts +2 -0
  66. package/dist/server/generateEtag.d.ts.map +1 -0
  67. package/dist/types.d.ts +4 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/utils/Subject.d.ts +9 -0
  70. package/dist/utils/Subject.d.ts.map +1 -0
  71. package/dist/utils/type.d.ts +2 -0
  72. package/dist/utils/type.d.ts.map +1 -0
  73. package/package.json +21 -8
  74. package/dist/client/index.mjs +0 -3174
  75. package/dist/client/useRouter.d.ts +0 -2
  76. package/dist/client/useRouter.d.ts.map +0 -1
  77. package/dist/fsevents-X6WP4TKM.node +0 -0
  78. package/dist/http/index.mjs +0 -16
  79. package/dist/server/Server.d.ts +0 -10
  80. package/dist/server/Server.d.ts.map +0 -1
  81. package/dist/server/dev.d.ts +0 -3
  82. package/dist/server/dev.d.ts.map +0 -1
  83. package/dist/server/index.d.ts +0 -2
  84. package/dist/server/index.d.ts.map +0 -1
  85. package/dist/server/index.mjs +0 -16315
@@ -0,0 +1,71 @@
1
+ import {createRequire} from "node:module";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getProtoOf = Object.getPrototypeOf;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
17
+ };
18
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
+ var __require = createRequire(import.meta.url);
20
+
21
+ // http/requestContext.ts
22
+ import {AsyncLocalStorage} from "async_hooks";
23
+ var requestContext = new AsyncLocalStorage;
24
+
25
+ // facades/Auth.ts
26
+ class Auth {
27
+ static user() {
28
+ const requestContextStore = requestContext.getStore();
29
+ if (requestContextStore) {
30
+ return requestContextStore.get("user");
31
+ }
32
+ }
33
+ }
34
+ // http/Error.ts
35
+ class RequestBreakerError extends Error {
36
+ constructor() {
37
+ super(...arguments);
38
+ }
39
+ payload = { api: {}, view: {} };
40
+ }
41
+
42
+ // facades/Redirect.ts
43
+ class RedirectError extends RequestBreakerError {
44
+ constructor(path) {
45
+ super("Redirect error");
46
+ this.name = "RedirectError";
47
+ this.payload = {
48
+ api: {
49
+ status: 302,
50
+ data: { error: "Redirect error" }
51
+ },
52
+ view: {
53
+ status: 302,
54
+ headers: {
55
+ "Cache-Control": "private, no-cache, no-store, max-age=0, must-revalidate",
56
+ Location: path
57
+ }
58
+ }
59
+ };
60
+ }
61
+ }
62
+
63
+ class Redirect {
64
+ static to(path) {
65
+ throw new RedirectError(path);
66
+ }
67
+ }
68
+ export {
69
+ Redirect,
70
+ Auth
71
+ };
@@ -1,3 +1,53 @@
1
+ import type { Controller } from "./Controller";
2
+ import { type MiddlewareReturnType } from "./Router";
3
+ import type { App } from "../app/App";
4
+ type ControllerMethods<T extends new () => Controller> = {
5
+ [K in keyof InstanceType<T>]: InstanceType<T>[K] extends Function ? K : never;
6
+ }[keyof InstanceType<T>];
7
+ type DataResponse = {
8
+ data: any;
9
+ status: number;
10
+ headers: Record<string, string>;
11
+ cookies: Record<string, string>;
12
+ };
13
+ type ErrorResponse = {
14
+ error: any;
15
+ status: number;
16
+ headers: Record<string, string>;
17
+ cookies: Record<string, string>;
18
+ };
19
+ export type ApiRouteExec = (req: Request, params: Record<string, string>) => Promise<DataResponse | ErrorResponse>;
20
+ type ApiRouteConfig = {
21
+ method: string;
22
+ exec: ApiRouteExec;
23
+ };
24
+ export type ApiRouteChildren = Record<string, ApiRouteConfig | ApiRouteConfig[] | (new (app: App) => ApiRouter)>;
1
25
  export declare class ApiRouter {
26
+ routes: Record<string, any>;
27
+ middlewares: string[];
28
+ constructor();
29
+ middleware(req: Request): MiddlewareReturnType;
30
+ private handleRequest;
31
+ protected get<T extends new () => Controller>(controller: T, methodName: ControllerMethods<T>): {
32
+ method: string;
33
+ exec: (req: Request, params: Record<string, string>) => Promise<DataResponse | ErrorResponse>;
34
+ };
35
+ protected post<T extends new () => Controller>(controller: T, methodName: ControllerMethods<T>): {
36
+ method: string;
37
+ exec: (req: Request, params: Record<string, string>) => Promise<DataResponse | ErrorResponse>;
38
+ };
39
+ protected patch<T extends new () => Controller>(controller: T, methodName: ControllerMethods<T>): {
40
+ method: string;
41
+ exec: (req: Request, params: Record<string, string>) => Promise<DataResponse | ErrorResponse>;
42
+ };
43
+ protected put<T extends new () => Controller>(controller: T, methodName: ControllerMethods<T>): {
44
+ method: string;
45
+ exec: (req: Request, params: Record<string, string>) => Promise<DataResponse | ErrorResponse>;
46
+ };
47
+ protected delete<T extends new () => Controller>(controller: T, methodName: ControllerMethods<T>): {
48
+ method: string;
49
+ exec: (req: Request, params: Record<string, string>) => Promise<DataResponse | ErrorResponse>;
50
+ };
2
51
  }
52
+ export {};
3
53
  //# sourceMappingURL=ApiRouter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApiRouter.d.ts","sourceRoot":"","sources":["../../http/ApiRouter.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS;CAAG"}
1
+ {"version":3,"file":"ApiRouter.d.ts","sourceRoot":"","sources":["../../http/ApiRouter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGtC,KAAK,iBAAiB,CAAC,CAAC,SAAS,UAAU,UAAU,IAAI;KACtD,CAAC,IAAI,MAAM,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,GAAG,KAAK;CAC9E,CAAC,MAAM,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzB,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC;AACF,KAAK,aAAa,GAAG;IACnB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,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AU,UAAU,EAC7C,UAAU,EAAE,CAAC,EACb,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;;;;CAKnC"}
@@ -1,3 +1,5 @@
1
+ import type { HttpRequest } from "./HttpRequest";
1
2
  export declare class Controller {
3
+ requests: Record<string, typeof HttpRequest<any>>;
2
4
  }
3
5
  //# sourceMappingURL=Controller.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Controller.d.ts","sourceRoot":"","sources":["../../http/Controller.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU;CAAG"}
1
+ {"version":3,"file":"Controller.d.ts","sourceRoot":"","sources":["../../http/Controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,qBAAa,UAAU;IACrB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAAM;CACxD"}
@@ -0,0 +1,7 @@
1
+ export declare class RequestBreakerError extends Error {
2
+ payload: {
3
+ api: Record<string, any>;
4
+ view: Record<string, any>;
5
+ };
6
+ }
7
+ //# sourceMappingURL=Error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../http/Error.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAoB,SAAQ,KAAK;IACrC,OAAO,EAAE;QACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC3B,CAAyB;CAC3B"}
@@ -0,0 +1,21 @@
1
+ declare class Input<T> extends Map {
2
+ constructor();
3
+ toJSON(): T;
4
+ }
5
+ export declare class HttpRequest<T = {}> {
6
+ rawRequest: Request;
7
+ headers: Headers;
8
+ cookies: Map<string, string>;
9
+ protected schema: Partial<Record<keyof T, Record<string, string>>>;
10
+ constructor(req: Request);
11
+ private parseBody;
12
+ private validateInput;
13
+ input(): Promise<Input<T>>;
14
+ safeInput(): Promise<{
15
+ isValid: boolean;
16
+ errors: Record<string, string[]>;
17
+ input: Input<T>;
18
+ }>;
19
+ }
20
+ export {};
21
+ //# sourceMappingURL=HttpRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpRequest.d.ts","sourceRoot":"","sources":["../../http/HttpRequest.ts"],"names":[],"mappings":"AAEA,cAAM,KAAK,CAAC,CAAC,CAAE,SAAQ,GAAG;;IAKjB,MAAM,IAAI,CAAC;CAGnB;AA4CD,qBAAa,WAAW,CAAC,CAAC,GAAG,EAAE;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEpC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAM;gBAE5D,GAAG,EAAE,OAAO;YAeV,SAAS;IAyCvB,OAAO,CAAC,aAAa;IAsBR,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAI1B,SAAS,IAAI,OAAO,CAAC;QAChC,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACjC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;KACjB,CAAC;CAoBH"}
@@ -0,0 +1,4 @@
1
+ export declare class Middleware {
2
+ run(_req: Request, ctx: Map<string, any>): Promise<{}>;
3
+ }
4
+ //# sourceMappingURL=Middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Middleware.d.ts","sourceRoot":"","sources":["../../http/Middleware.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU;IACf,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;CAG/C"}
@@ -0,0 +1,31 @@
1
+ import { RequestBreakerError } from "./Error";
2
+ type MiddlewareResult = Partial<{
3
+ headers: Record<string, string>;
4
+ cookies: Record<string, string>;
5
+ }>;
6
+ export type MiddlewareReturnType = void | Promise<MiddlewareResult> | MiddlewareResult;
7
+ export type RouterMiddleware = (req: Request) => MiddlewareReturnType;
8
+ export declare class AuthenticationError extends RequestBreakerError {
9
+ constructor();
10
+ payload: {
11
+ api: {
12
+ status: number;
13
+ data: {
14
+ error: string;
15
+ };
16
+ };
17
+ view: {
18
+ status: number;
19
+ headers: {
20
+ "Cache-Control": string;
21
+ Location: string;
22
+ };
23
+ };
24
+ };
25
+ }
26
+ export declare class ValidationError extends RequestBreakerError {
27
+ errors: Record<string, string[]>;
28
+ constructor(errors: Record<string, string[]>);
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=Router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../http/Router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,KAAK,gBAAgB,GAAG,OAAO,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAC5B,IAAI,GACJ,OAAO,CAAC,gBAAgB,CAAC,GACzB,gBAAgB,CAAC;AAErB,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,oBAAoB,CAAC;AAEtE,qBAAa,mBAAoB,SAAQ,mBAAmB;;IAM1D,OAAO;;;;;;;;;;;;;;MAaL;CACH;AAED,qBAAa,eAAgB,SAAQ,mBAAmB;IACtD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAM;gBAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;CAuB7C"}
@@ -1,3 +1,33 @@
1
+ import { Controller } from "./Controller";
2
+ import type { MiddlewareReturnType } from "./Router";
3
+ import type { App } from "../app/App";
4
+ type ControllerMethods<T extends new () => Controller> = {
5
+ [K in keyof InstanceType<T>]: InstanceType<T>[K] extends Function ? K : never;
6
+ }[keyof InstanceType<T>];
7
+ type ViewHandler<T extends new () => Controller> = [
8
+ controller: T,
9
+ method: ControllerMethods<T>
10
+ ];
11
+ type ViewPrepare = {
12
+ exec: (req: Request, params: Record<string, string>) => any;
13
+ viewPath: string;
14
+ children: ViewChildren;
15
+ middlewares: any[];
16
+ };
17
+ type ViewConfig = {
18
+ prepare: (_middlewares?: any[]) => ViewPrepare;
19
+ middlewares: (middlewares: any[]) => {
20
+ prepare: () => ViewPrepare;
21
+ };
22
+ };
23
+ export type ViewChildren = Record<string, ViewConfig | (new (app: App) => ViewRouter)>;
24
+ export type ViewRouteExec = (req: Request, params: Record<string, string>) => any;
1
25
  export declare class ViewRouter {
26
+ routes: ViewChildren;
27
+ middlewares: string[];
28
+ constructor();
29
+ middleware(req: Request): MiddlewareReturnType;
30
+ protected view<T extends new () => Controller>(viewPath: string, handler?: ViewHandler<T>, children?: ViewChildren): ViewConfig;
2
31
  }
32
+ export {};
3
33
  //# sourceMappingURL=ViewRouter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ViewRouter.d.ts","sourceRoot":"","sources":["../../http/ViewRouter.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU;CAAG"}
1
+ {"version":3,"file":"ViewRouter.d.ts","sourceRoot":"","sources":["../../http/ViewRouter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MA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,OAAO,GAAG,oBAAoB;IAErD,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,UAAU,UAAU,EAC3C,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,EACxB,QAAQ,GAAE,YAAiB,GAC1B,UAAU;CA0Bd"}
@@ -0,0 +1,2 @@
1
+ export declare function getCookies(req: Request): Map<string, string>;
2
+ //# sourceMappingURL=getCookies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCookies.d.ts","sourceRoot":"","sources":["../../http/getCookies.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAY5D"}
@@ -1,4 +1,8 @@
1
1
  export { Controller } from "./Controller";
2
2
  export { ApiRouter } from "./ApiRouter";
3
3
  export { ViewRouter } from "./ViewRouter";
4
+ export { ValidationError, AuthenticationError } from "./Router";
5
+ export { HttpRequest } from "./HttpRequest";
6
+ export { Middleware } from "./Middleware";
7
+ export { getCookies } from "./getCookies";
4
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,341 @@
1
+ import {createRequire} from "node:module";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getProtoOf = Object.getPrototypeOf;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
17
+ };
18
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
+ var __require = createRequire(import.meta.url);
20
+
21
+ // http/Controller.ts
22
+ class Controller {
23
+ requests = {};
24
+ }
25
+ // http/Error.ts
26
+ class RequestBreakerError extends Error {
27
+ constructor() {
28
+ super(...arguments);
29
+ }
30
+ payload = { api: {}, view: {} };
31
+ }
32
+
33
+ // http/Router.ts
34
+ class AuthenticationError extends RequestBreakerError {
35
+ constructor() {
36
+ super("Authentication error");
37
+ this.name = "AuthenticationError";
38
+ }
39
+ payload = {
40
+ api: {
41
+ status: 401,
42
+ data: { error: "Authentication error" }
43
+ },
44
+ view: {
45
+ status: 302,
46
+ headers: {
47
+ "Cache-Control": "private, no-cache, no-store, max-age=0, must-revalidate",
48
+ Location: "/auth/sign-in"
49
+ }
50
+ }
51
+ };
52
+ }
53
+
54
+ class ValidationError extends RequestBreakerError {
55
+ errors = {};
56
+ constructor(errors) {
57
+ console.log("ValidationError", { errors });
58
+ super("Validation error");
59
+ this.name = "ValidationError";
60
+ this.errors = errors;
61
+ this.payload = {
62
+ api: {
63
+ status: 400,
64
+ data: {
65
+ error: {
66
+ kind: "validation_error",
67
+ messages: errors
68
+ }
69
+ },
70
+ headers: {
71
+ "Content-Type": "application/json"
72
+ }
73
+ },
74
+ view: {
75
+ status: 400
76
+ }
77
+ };
78
+ }
79
+ }
80
+
81
+ // http/HttpRequest.ts
82
+ var validate = function(ruleName) {
83
+ const [rule, param] = ruleName.split(":");
84
+ switch (rule) {
85
+ case "required":
86
+ return (value) => {
87
+ return value !== null && value !== undefined;
88
+ };
89
+ case "password":
90
+ return (value) => {
91
+ const passwordRegex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{8,}$/;
92
+ return passwordRegex.test(value);
93
+ };
94
+ case "number":
95
+ return (value) => {
96
+ if (typeof value !== "number")
97
+ return false;
98
+ return !isNaN(value);
99
+ };
100
+ case "min":
101
+ return (value) => {
102
+ return value.length >= parseInt(param);
103
+ };
104
+ case "max":
105
+ return (value) => {
106
+ return value.length <= parseInt(param);
107
+ };
108
+ case "email":
109
+ return (value) => {
110
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
111
+ return emailRegex.test(value);
112
+ };
113
+ default:
114
+ return () => true;
115
+ }
116
+ };
117
+
118
+ class Input extends Map {
119
+ constructor() {
120
+ super();
121
+ }
122
+ toJSON() {
123
+ return Object.fromEntries(this);
124
+ }
125
+ }
126
+
127
+ class HttpRequest {
128
+ rawRequest;
129
+ headers;
130
+ cookies;
131
+ schema = {};
132
+ constructor(req) {
133
+ this.rawRequest = req;
134
+ this.headers = req.headers;
135
+ const cookie = this.rawRequest.headers.get("Cookie");
136
+ const cookies = new Map;
137
+ if (cookie) {
138
+ const cookieArray = cookie.split(";");
139
+ for (const c of cookieArray) {
140
+ const [key, value] = c.split("=");
141
+ cookies.set(key.trim(), value.trim());
142
+ }
143
+ }
144
+ this.cookies = cookies;
145
+ }
146
+ async parseBody() {
147
+ const inputMap = new Input;
148
+ if (this.rawRequest.headers.get("Content-Type") === "application/json") {
149
+ const body = await this.rawRequest.json();
150
+ for (const [key, value] of Object.entries(body)) {
151
+ inputMap.set(key, value);
152
+ }
153
+ }
154
+ if (this.rawRequest.headers.get("Content-Type") === "application/x-www-form-urlencoded") {
155
+ const body = await this.rawRequest.formData();
156
+ for (const [key, value] of body) {
157
+ console.log(key, value);
158
+ inputMap.set(key, value);
159
+ }
160
+ }
161
+ if (this.rawRequest.headers.get("Content-Type").startsWith("multipart/form-data")) {
162
+ const body = await this.rawRequest.formData();
163
+ for (const [key, value] of body) {
164
+ if (inputMap.has(key)) {
165
+ const currentValue = inputMap.get(key);
166
+ if (Array.isArray(currentValue)) {
167
+ currentValue.push(value);
168
+ inputMap.set(key, currentValue);
169
+ } else {
170
+ inputMap.set(key, [currentValue, value]);
171
+ }
172
+ } else {
173
+ inputMap.set(key, value);
174
+ }
175
+ }
176
+ }
177
+ return inputMap;
178
+ }
179
+ validateInput(input) {
180
+ const errors = {};
181
+ for (const [key, rules] of Object.entries(this.schema)) {
182
+ for (const [rule, message] of Object.entries(rules)) {
183
+ const validator = validate(rule);
184
+ if (!validator(input.get(key))) {
185
+ if (!errors[key]) {
186
+ errors[key] = [];
187
+ }
188
+ errors[key].push(String(message));
189
+ }
190
+ }
191
+ }
192
+ if (Object.keys(errors).length > 0) {
193
+ throw new ValidationError(errors);
194
+ } else {
195
+ return input;
196
+ }
197
+ }
198
+ async input() {
199
+ return this.validateInput(await this.parseBody());
200
+ }
201
+ async safeInput() {
202
+ const input = await this.parseBody();
203
+ try {
204
+ this.validateInput(input);
205
+ return {
206
+ isValid: true,
207
+ errors: {},
208
+ input
209
+ };
210
+ } catch (err) {
211
+ if (!(err instanceof ValidationError)) {
212
+ throw err;
213
+ }
214
+ return {
215
+ isValid: false,
216
+ errors: err.errors,
217
+ input
218
+ };
219
+ }
220
+ }
221
+ }
222
+
223
+ // http/ApiRouter.ts
224
+ class ApiRouter {
225
+ routes = {};
226
+ middlewares = [];
227
+ constructor() {
228
+ }
229
+ middleware(req) {
230
+ }
231
+ handleRequest(controller, methodName) {
232
+ return (method) => {
233
+ return {
234
+ method,
235
+ exec: async (req, params) => {
236
+ const controllerInstance = new controller;
237
+ const handler = controllerInstance[methodName].bind(controllerInstance);
238
+ const Req = controllerInstance.requests[methodName] ?? HttpRequest;
239
+ const httpRequest = new Req(req);
240
+ const {
241
+ data,
242
+ status = method === "post" ? 201 : 200,
243
+ headers = {},
244
+ cookies = {}
245
+ } = await handler(httpRequest, params);
246
+ return {
247
+ data,
248
+ status,
249
+ headers,
250
+ cookies
251
+ };
252
+ }
253
+ };
254
+ };
255
+ }
256
+ get(controller, methodName) {
257
+ const handler = this.handleRequest(controller, methodName);
258
+ return handler("get");
259
+ }
260
+ post(controller, methodName) {
261
+ const handler = this.handleRequest(controller, methodName);
262
+ return handler("post");
263
+ }
264
+ patch(controller, methodName) {
265
+ const handler = this.handleRequest(controller, methodName);
266
+ return handler("patch");
267
+ }
268
+ put(controller, methodName) {
269
+ const handler = this.handleRequest(controller, methodName);
270
+ return handler("put");
271
+ }
272
+ delete(controller, methodName) {
273
+ const handler = this.handleRequest(controller, methodName);
274
+ return handler("delete");
275
+ }
276
+ }
277
+ // http/ViewRouter.ts
278
+ class ViewRouter {
279
+ routes = {};
280
+ middlewares = [];
281
+ constructor() {
282
+ }
283
+ middleware(req) {
284
+ }
285
+ view(viewPath, handler, children = {}) {
286
+ function prepare(middlewares = []) {
287
+ return {
288
+ exec: async (req, params) => {
289
+ if (!handler) {
290
+ return { data: { [viewPath]: {} }, headers: {}, head: {} };
291
+ }
292
+ const [controller, methodName] = handler;
293
+ const instance = new controller;
294
+ const method = instance[methodName].bind(instance);
295
+ const { data, headers = {}, head = {} } = await method(req, params);
296
+ return { data: { [viewPath]: data }, headers, head };
297
+ },
298
+ children,
299
+ viewPath,
300
+ middlewares
301
+ };
302
+ }
303
+ return {
304
+ prepare,
305
+ middlewares: (middlewares) => {
306
+ prepare:
307
+ ;
308
+ }
309
+ };
310
+ }
311
+ }
312
+ // http/Middleware.ts
313
+ class Middleware {
314
+ async run(_req, ctx) {
315
+ return {};
316
+ }
317
+ }
318
+ // http/getCookies.ts
319
+ function getCookies(req) {
320
+ const cookies = req.headers.get("cookie");
321
+ if (!cookies) {
322
+ return new Map;
323
+ }
324
+ const _cookies = new Map;
325
+ const cookieStrings = cookies.split(";");
326
+ for (const cookieString of cookieStrings) {
327
+ const [name, value] = cookieString.split("=");
328
+ _cookies.set(name.trim(), value);
329
+ }
330
+ return _cookies;
331
+ }
332
+ export {
333
+ getCookies,
334
+ ViewRouter,
335
+ ValidationError,
336
+ Middleware,
337
+ HttpRequest,
338
+ Controller,
339
+ AuthenticationError,
340
+ ApiRouter
341
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import { AsyncLocalStorage } from "async_hooks";
3
+ export declare const requestContext: AsyncLocalStorage<Map<string, any>>;
4
+ //# sourceMappingURL=requestContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestContext.d.ts","sourceRoot":"","sources":["../../http/requestContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAYhD,eAAO,MAAM,cAAc,qCAA4C,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { Controller } from "./Controller";
2
+ export { ApiRouter } from "./ApiRouter";
3
+ export { ViewRouter } from "./ViewRouter";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function generateETag(lastModified: number): string;
2
+ //# sourceMappingURL=generateEtag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateEtag.d.ts","sourceRoot":"","sources":["../../server/generateEtag.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CASzD"}
@@ -0,0 +1,4 @@
1
+ type ComponentTreeBranch = Record<string, ComponentTree>;
2
+ export type ComponentTree = (string[] | ComponentTreeBranch)[];
3
+ export {};
4
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AACzD,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,GAAG,mBAAmB,CAAC,EAAE,CAAC"}