@cudenix/cudenix 0.0.58 → 0.0.60
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/core/app.d.ts +16 -16
- package/dist/core/app.d.ts.map +1 -1
- package/dist/core/app.js +58 -185
- package/dist/core/app.js.map +1 -1
- package/dist/core/compile.d.ts +6 -1
- package/dist/core/compile.d.ts.map +1 -1
- package/dist/core/compile.js +121 -116
- package/dist/core/compile.js.map +1 -1
- package/dist/core/context.d.ts +3 -2
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +142 -76
- package/dist/core/context.js.map +1 -1
- package/dist/core/error.d.ts +2 -2
- package/dist/core/error.d.ts.map +1 -1
- package/dist/core/error.js +4 -3
- package/dist/core/error.js.map +1 -1
- package/dist/core/global.d.ts +5 -1
- package/dist/core/global.d.ts.map +1 -1
- package/dist/core/group.d.ts +1 -1
- package/dist/core/group.d.ts.map +1 -1
- package/dist/core/group.js +4 -4
- package/dist/core/group.js.map +1 -1
- package/dist/core/middleware.d.ts +1 -1
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/module.d.ts +7 -11
- package/dist/core/module.d.ts.map +1 -1
- package/dist/core/module.js +8 -8
- package/dist/core/module.js.map +1 -1
- package/dist/core/response.d.ts +1 -1
- package/dist/core/response.d.ts.map +1 -1
- package/dist/core/response.js +35 -21
- package/dist/core/response.js.map +1 -1
- package/dist/core/route.d.ts +12 -16
- package/dist/core/route.d.ts.map +1 -1
- package/dist/core/route.js +6 -7
- package/dist/core/route.js.map +1 -1
- package/dist/core/step.d.ts +4 -0
- package/dist/core/step.d.ts.map +1 -0
- package/dist/core/step.js +199 -0
- package/dist/core/step.js.map +1 -0
- package/dist/core/success.d.ts.map +1 -1
- package/dist/core/success.js +4 -3
- package/dist/core/success.js.map +1 -1
- package/dist/core/validator.d.ts +7 -11
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js.map +1 -1
- package/dist/ecosystem/client/client.d.ts +6 -5
- package/dist/ecosystem/client/client.d.ts.map +1 -1
- package/dist/ecosystem/client/client.js +59 -46
- package/dist/ecosystem/client/client.js.map +1 -1
- package/dist/ecosystem/client/index.d.ts +4 -0
- package/dist/ecosystem/client/index.d.ts.map +1 -0
- package/dist/ecosystem/client/index.js +4 -0
- package/dist/ecosystem/client/index.js.map +1 -0
- package/dist/ecosystem/client/sse.d.ts.map +1 -1
- package/dist/ecosystem/client/sse.js +15 -28
- package/dist/ecosystem/client/sse.js.map +1 -1
- package/dist/ecosystem/client/ws.d.ts.map +1 -1
- package/dist/ecosystem/client/ws.js +12 -12
- package/dist/ecosystem/client/ws.js.map +1 -1
- package/dist/ecosystem/plugins/cluster/cluster.d.ts.map +1 -1
- package/dist/ecosystem/plugins/cluster/cluster.js +4 -2
- package/dist/ecosystem/plugins/cluster/cluster.js.map +1 -1
- package/dist/ecosystem/plugins/cluster/index.d.ts +2 -0
- package/dist/ecosystem/plugins/cluster/index.d.ts.map +1 -0
- package/dist/ecosystem/plugins/cluster/index.js +2 -0
- package/dist/ecosystem/plugins/cluster/index.js.map +1 -0
- package/dist/ecosystem/plugins/compress/compress.d.ts +9 -0
- package/dist/ecosystem/plugins/compress/compress.d.ts.map +1 -0
- package/dist/ecosystem/plugins/compress/compress.js +56 -0
- package/dist/ecosystem/plugins/compress/compress.js.map +1 -0
- package/dist/ecosystem/plugins/compress/index.d.ts +2 -0
- package/dist/ecosystem/plugins/compress/index.d.ts.map +1 -0
- package/dist/ecosystem/plugins/compress/index.js +2 -0
- package/dist/ecosystem/plugins/compress/index.js.map +1 -0
- package/dist/ecosystem/plugins/cors/cors.d.ts +12 -0
- package/dist/ecosystem/plugins/cors/cors.d.ts.map +1 -0
- package/dist/ecosystem/plugins/cors/cors.js +69 -0
- package/dist/ecosystem/plugins/cors/cors.js.map +1 -0
- package/dist/ecosystem/plugins/cors/index.d.ts +2 -0
- package/dist/ecosystem/plugins/cors/index.d.ts.map +1 -0
- package/dist/ecosystem/plugins/cors/index.js +2 -0
- package/dist/ecosystem/plugins/cors/index.js.map +1 -0
- package/dist/ecosystem/plugins/events/events.d.ts.map +1 -1
- package/dist/ecosystem/plugins/events/events.js +0 -2
- package/dist/ecosystem/plugins/events/events.js.map +1 -1
- package/dist/ecosystem/plugins/events/index.d.ts +3 -0
- package/dist/ecosystem/plugins/events/index.d.ts.map +1 -0
- package/dist/ecosystem/plugins/events/index.js +2 -0
- package/dist/ecosystem/plugins/events/index.js.map +1 -0
- package/dist/ecosystem/{modules → plugins}/global-request-context/global-request-context.d.ts.map +1 -1
- package/dist/ecosystem/{modules → plugins}/global-request-context/global-request-context.js.map +1 -1
- package/dist/ecosystem/plugins/global-request-context/index.d.ts +2 -0
- package/dist/ecosystem/plugins/global-request-context/index.d.ts.map +1 -0
- package/dist/ecosystem/plugins/global-request-context/index.js +2 -0
- package/dist/ecosystem/plugins/global-request-context/index.js.map +1 -0
- package/dist/ecosystem/plugins/i18n/i18n.d.ts +11 -9
- package/dist/ecosystem/plugins/i18n/i18n.d.ts.map +1 -1
- package/dist/ecosystem/plugins/i18n/i18n.js +86 -52
- package/dist/ecosystem/plugins/i18n/i18n.js.map +1 -1
- package/dist/ecosystem/plugins/i18n/index.d.ts +3 -0
- package/dist/ecosystem/plugins/i18n/index.d.ts.map +1 -0
- package/dist/ecosystem/plugins/i18n/index.js +2 -0
- package/dist/ecosystem/plugins/i18n/index.js.map +1 -0
- package/dist/ecosystem/plugins/openapi/index.d.ts +3 -0
- package/dist/ecosystem/plugins/openapi/index.d.ts.map +1 -0
- package/dist/ecosystem/plugins/openapi/index.js +3 -0
- package/dist/ecosystem/plugins/openapi/index.js.map +1 -0
- package/dist/ecosystem/plugins/openapi/openapi.d.ts +5 -4
- package/dist/ecosystem/plugins/openapi/openapi.d.ts.map +1 -1
- package/dist/ecosystem/plugins/openapi/openapi.js +48 -44
- package/dist/ecosystem/plugins/openapi/openapi.js.map +1 -1
- package/dist/ecosystem/plugins/openapi/scalar.js +3 -3
- package/dist/ecosystem/plugins/openapi/scalar.js.map +1 -1
- package/dist/ecosystem/plugins/try-catch/index.d.ts +2 -0
- package/dist/ecosystem/plugins/try-catch/index.d.ts.map +1 -0
- package/dist/ecosystem/plugins/try-catch/index.js +2 -0
- package/dist/ecosystem/plugins/try-catch/index.js.map +1 -0
- package/dist/ecosystem/plugins/try-catch/try-catch.d.ts +9 -0
- package/dist/ecosystem/plugins/try-catch/try-catch.d.ts.map +1 -0
- package/dist/ecosystem/{modules/trycatch/trycatch.js → plugins/try-catch/try-catch.js} +6 -2
- package/dist/ecosystem/plugins/try-catch/try-catch.js.map +1 -0
- package/dist/types/all-properties-are-unknown.d.ts +1 -1
- package/dist/types/all-properties-are-unknown.d.ts.map +1 -1
- package/dist/types/conditionally-omit.d.ts +2 -5
- package/dist/types/conditionally-omit.d.ts.map +1 -1
- package/dist/types/conditionally-optional.d.ts +4 -4
- package/dist/types/conditionally-optional.d.ts.map +1 -1
- package/dist/types/extract-url-params.d.ts +5 -6
- package/dist/types/extract-url-params.d.ts.map +1 -1
- package/dist/types/standard-schema.d.ts +4 -4
- package/dist/types/standard-schema.d.ts.map +1 -1
- package/dist/utils/functions/is-generator.d.ts +2 -0
- package/dist/utils/functions/is-generator.d.ts.map +1 -0
- package/dist/utils/functions/is-generator.js +6 -0
- package/dist/utils/functions/is-generator.js.map +1 -0
- package/dist/utils/headers/quality.d.ts +2 -0
- package/dist/utils/headers/quality.d.ts.map +1 -0
- package/dist/utils/headers/quality.js +19 -0
- package/dist/utils/headers/quality.js.map +1 -0
- package/dist/utils/headers/select.d.ts +2 -0
- package/dist/utils/headers/select.d.ts.map +1 -0
- package/dist/utils/headers/select.js +54 -0
- package/dist/utils/headers/select.js.map +1 -0
- package/dist/utils/json/try-parse.d.ts +2 -0
- package/dist/utils/json/try-parse.d.ts.map +1 -0
- package/dist/utils/json/try-parse.js +9 -0
- package/dist/utils/json/try-parse.js.map +1 -0
- package/dist/utils/objects/empty.d.ts +1 -0
- package/dist/utils/objects/empty.d.ts.map +1 -1
- package/dist/utils/objects/empty.js +2 -1
- package/dist/utils/objects/empty.js.map +1 -1
- package/dist/utils/objects/merge.js +1 -1
- package/dist/utils/objects/merge.js.map +1 -1
- package/dist/utils/regexps/path-to-regexp.d.ts +6 -0
- package/dist/utils/regexps/path-to-regexp.d.ts.map +1 -0
- package/dist/utils/regexps/path-to-regexp.js +40 -0
- package/dist/utils/regexps/path-to-regexp.js.map +1 -0
- package/dist/utils/standard-schema/validate.d.ts +4 -1
- package/dist/utils/standard-schema/validate.d.ts.map +1 -1
- package/dist/utils/standard-schema/validate.js +12 -4
- package/dist/utils/standard-schema/validate.js.map +1 -1
- package/package.json +24 -23
- package/dist/ecosystem/modules/compress/compress.d.ts +0 -8
- package/dist/ecosystem/modules/compress/compress.d.ts.map +0 -1
- package/dist/ecosystem/modules/compress/compress.js +0 -116
- package/dist/ecosystem/modules/compress/compress.js.map +0 -1
- package/dist/ecosystem/modules/cors/cors.d.ts +0 -27
- package/dist/ecosystem/modules/cors/cors.d.ts.map +0 -1
- package/dist/ecosystem/modules/cors/cors.js +0 -67
- package/dist/ecosystem/modules/cors/cors.js.map +0 -1
- package/dist/ecosystem/modules/trycatch/trycatch.d.ts +0 -5
- package/dist/ecosystem/modules/trycatch/trycatch.d.ts.map +0 -1
- package/dist/ecosystem/modules/trycatch/trycatch.js.map +0 -1
- /package/dist/ecosystem/{modules → plugins}/global-request-context/global-request-context.d.ts +0 -0
- /package/dist/ecosystem/{modules → plugins}/global-request-context/global-request-context.js +0 -0
package/dist/core/app.d.ts
CHANGED
|
@@ -3,34 +3,34 @@ import type { AnyModule } from "../core/module.js";
|
|
|
3
3
|
import type { AnyRoute } from "../core/route.js";
|
|
4
4
|
import type { AnyStore } from "../core/store.js";
|
|
5
5
|
import type { AnyValidator } from "../core/validator.js";
|
|
6
|
-
|
|
7
|
-
export interface PluginOptions {
|
|
8
|
-
compile?: "AFTER" | "BEFORE" | false;
|
|
9
|
-
}
|
|
10
|
-
export interface MemoryPlugin {
|
|
11
|
-
plugin: Plugin;
|
|
12
|
-
options?: PluginOptions | undefined;
|
|
13
|
-
}
|
|
6
|
+
import type { MaybePromise } from "../types/maybe-promise.js";
|
|
14
7
|
export type Chain = (AnyMiddleware | AnyRoute | AnyStore | AnyValidator)[];
|
|
15
8
|
export interface Endpoint {
|
|
16
9
|
chain: Chain;
|
|
17
10
|
generator: boolean;
|
|
18
|
-
paramsRegexp
|
|
11
|
+
paramsRegexp?: RegExp;
|
|
19
12
|
path: string;
|
|
20
13
|
route: AnyRoute;
|
|
21
|
-
use:
|
|
14
|
+
use: number;
|
|
15
|
+
}
|
|
16
|
+
interface MethodData {
|
|
17
|
+
endpoints: Endpoint[];
|
|
18
|
+
regexp: RegExp;
|
|
19
|
+
}
|
|
20
|
+
type Plugin = (...options: any[]) => MaybePromise<void>;
|
|
21
|
+
interface PluginOptions {
|
|
22
|
+
compile?: "AFTER" | "BEFORE" | false;
|
|
22
23
|
}
|
|
23
24
|
export interface App {
|
|
24
25
|
compile(): Promise<void>;
|
|
25
|
-
endpoint(
|
|
26
|
-
|
|
27
|
-
fetch(request: Request): Promise<Response>;
|
|
26
|
+
endpoint(endpoint: Endpoint, path: string, request: Request): MaybePromise<Response>;
|
|
27
|
+
fetch(request: Request): MaybePromise<Response>;
|
|
28
28
|
listen(options?: Omit<Bun.Serve.Options<unknown>, "fetch" | "unix">): Promise<App>;
|
|
29
29
|
memory: Map<string, unknown>;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
methods: Map<string, MethodData>;
|
|
31
|
+
plugins(plugins: Plugin[], options: PluginOptions): App;
|
|
32
32
|
routes?: Record<string, Bun.Serve.Routes<unknown, string>>;
|
|
33
|
-
server?: Bun.Server<unknown
|
|
33
|
+
server?: Bun.Server<unknown>;
|
|
34
34
|
}
|
|
35
35
|
type Constructor = new (module: AnyModule) => App;
|
|
36
36
|
export declare const App: Constructor;
|
package/dist/core/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/core/app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/core/app.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAO1D,MAAM,MAAM,KAAK,GAAG,CAAC,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,YAAY,CAAC,EAAE,CAAC;AAE3E,MAAM,WAAW,QAAQ;IACxB,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,QAAQ,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACZ;AAOD,UAAU,UAAU;IACnB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,KAAK,MAAM,GAAG,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;AAExD,UAAU,aAAa;IACtB,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;CACrC;AAED,MAAM,WAAW,GAAG;IACnB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,QAAQ,CACP,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACd,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC1B,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,CACL,OAAO,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,GAC1D,OAAO,CAAC,GAAG,CAAC,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,aAAa,GAAG,GAAG,CAAC;IACxD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3D,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;CAC7B;AAED,KAAK,WAAW,GAAG,KAAK,MAAM,EAAE,SAAS,KAAK,GAAG,CAAC;AAElD,eAAO,MAAM,GAAG,EAKA,WAAW,CAAC;AAiL5B,eAAO,MAAM,GAAG,GAAI,QAAQ,SAAS,KACV,GAC1B,CAAC"}
|
package/dist/core/app.js
CHANGED
|
@@ -1,201 +1,80 @@
|
|
|
1
1
|
import { compile } from "../core/compile.js";
|
|
2
2
|
import { Context } from "../core/context.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { stepAndRespond } from "../core/step.js";
|
|
4
|
+
const NOT_FOUND_INIT = {
|
|
5
|
+
status: 404,
|
|
6
|
+
};
|
|
6
7
|
export const App = function (module) {
|
|
7
|
-
this.endpoints = new Map();
|
|
8
8
|
this.memory = new Map();
|
|
9
|
-
this.
|
|
9
|
+
this.methods = new Map();
|
|
10
10
|
this.memory.set("module", module);
|
|
11
11
|
};
|
|
12
12
|
App.prototype.compile = async function () {
|
|
13
|
+
const memoryPlugins = (this.memory.get("plugins") ?? []);
|
|
13
14
|
const pluginsAfterCompile = [];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
if (plugin.options?.compile === "AFTER") {
|
|
28
|
-
pluginsAfterCompile.push(plugin.plugin);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
await plugin.plugin.call(this);
|
|
15
|
+
for (let i = 0; i < memoryPlugins.length; i++) {
|
|
16
|
+
const plugin = memoryPlugins[i];
|
|
17
|
+
if (!plugin || plugin.options?.compile === false) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (plugin.options?.compile === "AFTER") {
|
|
21
|
+
pluginsAfterCompile.push(plugin.plugin);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const result = plugin.plugin.call(this);
|
|
25
|
+
if (result instanceof Promise) {
|
|
26
|
+
await result;
|
|
32
27
|
}
|
|
33
28
|
}
|
|
34
|
-
|
|
29
|
+
compile(this, this.memory.get("module"));
|
|
35
30
|
for (let i = 0; i < pluginsAfterCompile.length; i++) {
|
|
36
|
-
|
|
31
|
+
const result = pluginsAfterCompile[i]?.call(this);
|
|
32
|
+
if (result instanceof Promise) {
|
|
33
|
+
await result;
|
|
34
|
+
}
|
|
37
35
|
}
|
|
38
36
|
this.memory.delete("module");
|
|
39
37
|
this.memory.delete("plugins");
|
|
40
38
|
};
|
|
41
|
-
App.prototype.endpoint =
|
|
39
|
+
App.prototype.endpoint = function (endpoint, path, request) {
|
|
42
40
|
const context = new Context(endpoint, this.memory, path, request, this.server);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const link = chain[i];
|
|
51
|
-
if (!link) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (link.type === "ROUTE") {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (link.type === "MIDDLEWARE") {
|
|
58
|
-
const middleware = await link.middleware(context, () => {
|
|
59
|
-
return step(chain, i + 1);
|
|
60
|
-
});
|
|
61
|
-
if (middleware) {
|
|
62
|
-
context.response.content = middleware;
|
|
63
|
-
}
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (link.type === "STORE") {
|
|
67
|
-
const store = await link.store(context);
|
|
68
|
-
if (store instanceof Error) {
|
|
69
|
-
context.response.content = store;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
merge(context.store, store);
|
|
73
|
-
}
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (!link.request) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
const errors = new Map();
|
|
80
|
-
for (let i = 0; i < link.keys.length; i++) {
|
|
81
|
-
const key = link.keys[i];
|
|
82
|
-
const schema = link.request[key];
|
|
83
|
-
const validated = await validatorPlugin(schema, context.request[key], key);
|
|
84
|
-
if (validated.success) {
|
|
85
|
-
context.request[key] =
|
|
86
|
-
validated.content;
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const content = validated.content.pop
|
|
90
|
-
? validated.content
|
|
91
|
-
: [validated.content];
|
|
92
|
-
if (errors.has(key)) {
|
|
93
|
-
errors.get(key)?.details.push(...content);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
errors.set(key, {
|
|
97
|
-
details: content,
|
|
98
|
-
type: key,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
if (errors.size > 0) {
|
|
102
|
-
context.response.content = new Error(Array.from(errors.values()), {
|
|
103
|
-
status: 422,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (context.response.content) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (endpoint.generator) {
|
|
111
|
-
context.response.content = new ReadableStream({
|
|
112
|
-
async start(controller) {
|
|
113
|
-
let closed = false;
|
|
114
|
-
const onAbort = () => {
|
|
115
|
-
closed = true;
|
|
116
|
-
try {
|
|
117
|
-
controller.close();
|
|
118
|
-
}
|
|
119
|
-
catch { }
|
|
120
|
-
};
|
|
121
|
-
request.signal.addEventListener("abort", onAbort);
|
|
122
|
-
try {
|
|
123
|
-
for await (const chunk of endpoint.route.route(context)) {
|
|
124
|
-
if (closed) {
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
if (chunk.data.transform) {
|
|
128
|
-
if (chunk.id) {
|
|
129
|
-
controller.enqueue(`id: ${chunk.id}\n`);
|
|
130
|
-
}
|
|
131
|
-
if (chunk.event) {
|
|
132
|
-
controller.enqueue(`event: ${chunk.event}\n`);
|
|
133
|
-
}
|
|
134
|
-
if (chunk.retry) {
|
|
135
|
-
controller.enqueue(`retry: ${chunk.retry.toString()}\n`);
|
|
136
|
-
}
|
|
137
|
-
controller.enqueue(`data: ${JSON.stringify(chunk.data)}\n\n`);
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
controller.enqueue(chunk.data.content);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
catch {
|
|
144
|
-
}
|
|
145
|
-
finally {
|
|
146
|
-
request.signal.removeEventListener("abort", onAbort);
|
|
147
|
-
onAbort();
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const returned = await endpoint.route.route(context);
|
|
154
|
-
if (endpoint.route.method === "WS") {
|
|
155
|
-
this.server?.upgrade(request, {
|
|
156
|
-
data: {
|
|
157
|
-
close: async (ws, code, reason) => {
|
|
158
|
-
await returned?.close?.(ws, code, reason);
|
|
159
|
-
},
|
|
160
|
-
drain: async (ws) => {
|
|
161
|
-
await returned?.drain?.(ws);
|
|
162
|
-
},
|
|
163
|
-
message: async (ws, message) => {
|
|
164
|
-
await returned?.message(ws, message);
|
|
165
|
-
},
|
|
166
|
-
open: async (ws) => {
|
|
167
|
-
await returned?.open?.(ws);
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
context.response.content = returned;
|
|
174
|
-
};
|
|
175
|
-
await step(endpoint.chain, 0);
|
|
176
|
-
return processResponse(context.response);
|
|
41
|
+
const result = context.loadRequest();
|
|
42
|
+
if (result instanceof Promise) {
|
|
43
|
+
return result.then(() => {
|
|
44
|
+
return stepAndRespond(this, context, endpoint, request);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return stepAndRespond(this, context, endpoint, request);
|
|
177
48
|
};
|
|
178
|
-
App.prototype.fetch =
|
|
179
|
-
const
|
|
49
|
+
App.prototype.fetch = function (request) {
|
|
50
|
+
const data = this.methods.get(request.method);
|
|
51
|
+
if (!data) {
|
|
52
|
+
return new Response(undefined, NOT_FOUND_INIT);
|
|
53
|
+
}
|
|
54
|
+
const match = data.regexp.exec(request.url);
|
|
180
55
|
if (!match) {
|
|
181
|
-
return new Response(undefined,
|
|
182
|
-
status: 404,
|
|
183
|
-
});
|
|
56
|
+
return new Response(undefined, NOT_FOUND_INIT);
|
|
184
57
|
}
|
|
185
|
-
|
|
58
|
+
const path = match[2];
|
|
59
|
+
if (!path) {
|
|
60
|
+
return new Response(undefined, NOT_FOUND_INIT);
|
|
61
|
+
}
|
|
62
|
+
let index = -1;
|
|
186
63
|
for (let i = 3; i < match.length; i++) {
|
|
187
|
-
if (match[i] ===
|
|
188
|
-
|
|
189
|
-
break;
|
|
64
|
+
if (match[i] === undefined) {
|
|
65
|
+
continue;
|
|
190
66
|
}
|
|
67
|
+
index = i - 3;
|
|
68
|
+
break;
|
|
191
69
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
70
|
+
if (index === -1) {
|
|
71
|
+
return new Response(undefined, NOT_FOUND_INIT);
|
|
72
|
+
}
|
|
73
|
+
const endpoint = data.endpoints[index];
|
|
74
|
+
if (!endpoint) {
|
|
75
|
+
return new Response(undefined, NOT_FOUND_INIT);
|
|
197
76
|
}
|
|
198
|
-
return this.endpoint(
|
|
77
|
+
return this.endpoint(endpoint, path, request);
|
|
199
78
|
};
|
|
200
79
|
App.prototype.listen = async function (options) {
|
|
201
80
|
await this.compile();
|
|
@@ -222,30 +101,24 @@ App.prototype.listen = async function (options) {
|
|
|
222
101
|
},
|
|
223
102
|
},
|
|
224
103
|
});
|
|
225
|
-
process.once("
|
|
104
|
+
process.once("beforeExit", () => {
|
|
226
105
|
this.server?.stop(true);
|
|
227
106
|
this.server = undefined;
|
|
228
107
|
});
|
|
229
108
|
Bun.gc();
|
|
230
109
|
return this;
|
|
231
110
|
};
|
|
232
|
-
App.prototype.
|
|
111
|
+
App.prototype.plugins = function (plugins, options) {
|
|
233
112
|
if (!this.memory.has("plugins")) {
|
|
234
113
|
this.memory.set("plugins", []);
|
|
235
114
|
}
|
|
236
|
-
|
|
237
|
-
this.memory.get("plugins").push({
|
|
238
|
-
options,
|
|
239
|
-
plugin: plugins,
|
|
240
|
-
});
|
|
241
|
-
return this;
|
|
242
|
-
}
|
|
115
|
+
const memoryPlugins = this.memory.get("plugins");
|
|
243
116
|
for (let i = 0; i < plugins.length; i++) {
|
|
244
117
|
const plugin = plugins[i];
|
|
245
118
|
if (!plugin) {
|
|
246
119
|
continue;
|
|
247
120
|
}
|
|
248
|
-
|
|
121
|
+
memoryPlugins.push({
|
|
249
122
|
options,
|
|
250
123
|
plugin,
|
|
251
124
|
});
|
package/dist/core/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/core/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAA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AG,CAAC,EAAE,EAAE,CAAC;IAET,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAEF,GAAG,CAAC,SAAS,CAAC,OAAO,GAAG,UAEvB,OAAiB,EACjB,OAAsB;IAEtB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAmB,CAAC;IAEnE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAE1B,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,SAAS;QACV,CAAC;QAED,aAAa,CAAC,IAAI,CAAC;YAClB,OAAO;YACP,MAAM;SACN,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,MAAiB,EAAE,EAAE;IACxC,OAAO,IAAI,GAAG,CAAC,MAAM,CAAQ,CAAC;AAC/B,CAAC,CAAC"}
|
package/dist/core/compile.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { App } from "../core/app.js";
|
|
2
2
|
import { type AnyModule } from "../core/module.js";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const USE_BODY = 1;
|
|
4
|
+
export declare const USE_COOKIES = 2;
|
|
5
|
+
export declare const USE_HEADERS = 4;
|
|
6
|
+
export declare const USE_PARAMS = 8;
|
|
7
|
+
export declare const USE_QUERY = 16;
|
|
8
|
+
export declare const compile: (app: App, module: AnyModule) => void;
|
|
4
9
|
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/core/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAmB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/core/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAmB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,eAAe,CAAC;AAKvD,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,UAAU,IAAI,CAAC;AAC5B,eAAO,MAAM,SAAS,KAAK,CAAC;AA6N5B,eAAO,MAAM,OAAO,GAAI,KAAK,GAAG,EAAE,QAAQ,SAAS,SAiElD,CAAC"}
|