@cudenix/cudenix 0.0.57 → 0.0.59
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 +4 -3
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +145 -75
- 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 +37 -15
- 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 +8 -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 +11 -0
- package/dist/ecosystem/{modules → plugins}/cors/cors.d.ts.map +1 -1
- 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 +6 -5
- package/dist/ecosystem/plugins/i18n/i18n.d.ts.map +1 -1
- package/dist/ecosystem/plugins/i18n/i18n.js +86 -53
- 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 +4 -3
- package/dist/ecosystem/plugins/openapi/openapi.d.ts.map +1 -1
- package/dist/ecosystem/plugins/openapi/openapi.js +48 -43
- 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 +8 -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.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/utils/cookies/get/cookies.d.ts +0 -2
- package/dist/utils/cookies/get/cookies.d.ts.map +0 -1
- package/dist/utils/cookies/get/cookies.js +0 -18
- package/dist/utils/cookies/get/cookies.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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/cors/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/cors/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/events/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,MAAM,EAAE,OAAO,EAAE,CAAC,IAC/D,YAAY,CAAC,MAAM,CAAC,CAAC;AAEtB,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;AAElC,KAAK,WAAW,GAAG,UAAU,QAAQ,CAAC;AAEtC,eAAO,MAAM,KAAK,EAEF,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/events/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,MAAM,EAAE,OAAO,EAAE,CAAC,IAC/D,YAAY,CAAC,MAAM,CAAC,CAAC;AAEtB,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;AAElC,KAAK,WAAW,GAAG,UAAU,QAAQ,CAAC;AAEtC,eAAO,MAAM,KAAK,EAEF,WAAW,CAAC;AAE5B,eAAO,MAAM,KAAK,GACjB,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,OAEpD,KAAK,CAAC,MAAM,CAClC,CAAC;AAEF,eAAO,MAAM,MAAM,4BAAU,CAAC"}
|
|
@@ -2,8 +2,6 @@ import { EventEmitter } from "node:events";
|
|
|
2
2
|
export const Event = function () {
|
|
3
3
|
return new EventEmitter();
|
|
4
4
|
};
|
|
5
|
-
Event.prototype = Object.create(EventEmitter.prototype);
|
|
6
|
-
Event.prototype.constructor = Event;
|
|
7
5
|
export const event = () => {
|
|
8
6
|
return new Event();
|
|
9
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/events/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAS3C,MAAM,CAAC,MAAM,KAAK,GAAG;IACpB,OAAO,IAAI,YAAY,EAAE,CAAC;AAC3B,CAA2B,CAAC;AAE5B,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/events/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAS3C,MAAM,CAAC,MAAM,KAAK,GAAG;IACpB,OAAO,IAAI,YAAY,EAAE,CAAC;AAC3B,CAA2B,CAAC;AAE5B,MAAM,CAAC,MAAM,KAAK,GAAG,GAEjB,EAAE;IACL,OAAO,IAAI,KAAK,EAAmB,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,mBAAmB,kCAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC"}
|
package/dist/ecosystem/{modules → plugins}/global-request-context/global-request-context.d.ts.map
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-request-context.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/
|
|
1
|
+
{"version":3,"file":"global-request-context.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/global-request-context/global-request-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D,eAAO,MAAM,iBAAiB,wCAA+C,CAAC;AAE9E,eAAO,MAAM,iBAAiB,uCAE7B,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;EAIhC,CAAC"}
|
package/dist/ecosystem/{modules → plugins}/global-request-context/global-request-context.js.map
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-request-context.js","sourceRoot":"","sources":["../../../../src/ecosystem/
|
|
1
|
+
{"version":3,"file":"global-request-context.js","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/global-request-context/global-request-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAuB,CAAC;AAE9E,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACrC,OAAO,iBAAiB,CAAC,QAAQ,EAAE,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACxC,OAAO,MAAM,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAClD,MAAM,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/global-request-context/index.ts"],"names":[],"mappings":"AAAA,cAAc,mEAAmE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/global-request-context/index.ts"],"names":[],"mappings":"AAAA,cAAc,mEAAmE,CAAC"}
|
|
@@ -2,7 +2,7 @@ export type DeepPaths<Type extends Record<PropertyKey, unknown>> = {
|
|
|
2
2
|
[Key in keyof Type]: Key extends string ? Type[Key] extends Record<PropertyKey, unknown> ? `${Key}` | `${Key}.${DeepPaths<Type[Key]>}` : `${Key}` : never;
|
|
3
3
|
}[keyof Type];
|
|
4
4
|
export type DeepValue<Type extends Record<PropertyKey, unknown>, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof Type ? Type[Key] extends Record<PropertyKey, unknown> ? DeepValue<Type[Key], Rest> : never : never : Path extends keyof Type ? Type[Path] : never;
|
|
5
|
-
export type ExtractPlaceholders<String extends string> = String extends `${infer _Start}\${${infer Param}}${infer Rest}` ?
|
|
5
|
+
export type ExtractPlaceholders<String extends string, Acc extends string = never> = String extends `${infer _Start}\${${infer Param}}${infer Rest}` ? ExtractPlaceholders<Rest, Acc | Param> : Acc;
|
|
6
6
|
export interface Translation {
|
|
7
7
|
[key: string]: string | Translation | (string | Translation)[];
|
|
8
8
|
}
|
|
@@ -13,19 +13,20 @@ export interface TranslateOptions<Translation> {
|
|
|
13
13
|
} : undefined;
|
|
14
14
|
}
|
|
15
15
|
export interface I18n {
|
|
16
|
-
path: string;
|
|
17
16
|
cookie?: string;
|
|
18
17
|
header?: string;
|
|
19
18
|
language: string;
|
|
20
19
|
languages: string[];
|
|
20
|
+
path: string;
|
|
21
21
|
translations: Translation;
|
|
22
22
|
}
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
23
|
+
export declare const loadTranslations: (directory: string) => Promise<Translation>;
|
|
24
|
+
export declare const replace: <Translation extends string>(translation: Translation, replacements: { [Key in ExtractPlaceholders<Translation>]?: string; }) => Translation;
|
|
25
|
+
export declare const load: (path: string, language: string, { cookie, header, types, }?: Pick<I18n, "cookie" | "header"> & {
|
|
25
26
|
types: boolean;
|
|
26
27
|
}) => Promise<void>;
|
|
27
28
|
export declare const getLanguage: () => string;
|
|
28
|
-
export declare const translate: <const Path extends DeepPaths<Cudenix.i18n.Translations>>(path: Path, { language, replace, }?: TranslateOptions<DeepValue<Cudenix.i18n.Translations, Path>>) => DeepValue<Cudenix.i18n.Translations, Path>;
|
|
29
|
+
export declare const translate: <const Path extends DeepPaths<Cudenix.i18n.Translations>>(path: Path, { language, replace: replacements, }?: TranslateOptions<DeepValue<Cudenix.i18n.Translations, Path>>) => DeepValue<Cudenix.i18n.Translations, Path>;
|
|
29
30
|
export declare const i18n: () => import("../../../core/module.js").Module<import("../../../index.js").MergeErrors<{}, import("../../../index.js").TransformError<never>>, "/", {}, {}, import("../../../index.js").MergeSuccesses<{}, import("../../../index.js").TransformSuccess<never>>, {
|
|
30
31
|
inputs: NonNullable<unknown>;
|
|
31
32
|
outputs: NonNullable<unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/i18n/i18n.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/i18n/i18n.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,SAAS,CAAC,IAAI,SAAS,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI;KACjE,GAAG,IAAI,MAAM,IAAI,GAAG,GAAG,SAAS,MAAM,GACpC,IAAI,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAC7C,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAC3C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AAM,EAAE,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,WAAW,CAAC;CAC1B;AAED,eAAO,MAAM,gBAAgB,GAAU,WAAW,MAAM,yBAgDvD,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,WAAW,SAAS,MAAM,EACjD,aAAa,WAAW,EACxB,cAAc,GACZ,GAAG,IAAI,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,GAClD,KA8CgB,WACjB,CAAC;AAEF,eAAO,MAAM,IAAI,GAChB,MAAM,MAAM,EACZ,UAAU,MAAM,EAChB,6BAIG,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC,GAAG;IACpC,KAAK,EAAE,OAAO,CAAC;CACM,kBA+CtB,CAAC;AAEF,eAAO,MAAM,WAAW,cAKvB,CAAC;AAEF,eAAO,MAAM,SAAS,GACrB,KAAK,CAAC,IAAI,SAAS,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,EAEvD,MAAM,IAAI,EACV,uCAGG,gBAAgB,CAClB,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAC5B,+CAiCf,CAAC;AAEF,eAAO,MAAM,IAAI;;;EAuBhB,CAAC"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { readdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { module } from "../../../core/module.js";
|
|
4
|
-
import { getRequestContext } from "../../../ecosystem/
|
|
5
|
-
import {
|
|
6
|
-
import { Empty } from "../../../utils/objects/empty.js";
|
|
7
|
-
const
|
|
8
|
-
const loadTranslations = async (directory) => {
|
|
4
|
+
import { getRequestContext } from "../../../ecosystem/plugins/global-request-context/global-request-context.js";
|
|
5
|
+
import { selectHeader } from "../../../utils/headers/select.js";
|
|
6
|
+
import { Empty, FreezeEmpty } from "../../../utils/objects/empty.js";
|
|
7
|
+
const STORE = new Empty();
|
|
8
|
+
export const loadTranslations = async (directory) => {
|
|
9
9
|
const result = new Empty();
|
|
10
10
|
const entries = await readdir(directory, {
|
|
11
11
|
withFileTypes: true,
|
|
12
12
|
});
|
|
13
|
+
const promises = [];
|
|
13
14
|
for (let i = 0; i < entries.length; i++) {
|
|
14
15
|
const entry = entries[i];
|
|
15
16
|
if (!entry) {
|
|
@@ -17,33 +18,61 @@ const loadTranslations = async (directory) => {
|
|
|
17
18
|
}
|
|
18
19
|
const fullPath = join(directory, entry.name);
|
|
19
20
|
if (entry.isDirectory()) {
|
|
20
|
-
|
|
21
|
+
promises.push(loadTranslations(fullPath).then((data) => {
|
|
22
|
+
result[entry.name] = data;
|
|
23
|
+
}));
|
|
21
24
|
continue;
|
|
22
25
|
}
|
|
23
26
|
if (entry.isFile() && entry.name.endsWith(".json")) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
promises.push(Bun.file(fullPath)
|
|
28
|
+
.json()
|
|
29
|
+
.then((data) => {
|
|
30
|
+
if (entry.name === "index.json") {
|
|
31
|
+
Object.assign(result, data);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
result[entry.name.slice(0, -5)] = data;
|
|
35
|
+
}));
|
|
30
36
|
}
|
|
31
37
|
}
|
|
38
|
+
await Promise.all(promises);
|
|
32
39
|
return result;
|
|
33
40
|
};
|
|
34
|
-
export const replace = (translation,
|
|
35
|
-
const
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
+
export const replace = (translation, replacements) => {
|
|
42
|
+
const length = translation.length;
|
|
43
|
+
let result = "";
|
|
44
|
+
let i = 0;
|
|
45
|
+
while (i < length) {
|
|
46
|
+
if (translation.charCodeAt(i) === 0x24 &&
|
|
47
|
+
i + 1 < length &&
|
|
48
|
+
translation.charCodeAt(i + 1) === 0x7b) {
|
|
49
|
+
const start = i + 2;
|
|
50
|
+
const closingIdx = translation.indexOf("}", start);
|
|
51
|
+
if (closingIdx !== -1 && closingIdx !== start) {
|
|
52
|
+
const key = translation.slice(start, closingIdx);
|
|
53
|
+
const value = replacements[key];
|
|
54
|
+
if (value !== undefined) {
|
|
55
|
+
result += value;
|
|
56
|
+
i = closingIdx + 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
result += translation[i];
|
|
61
|
+
i++;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const nextDollar = translation.indexOf("${", i);
|
|
65
|
+
if (nextDollar === -1) {
|
|
66
|
+
result += translation.slice(i);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
result += translation.slice(i, nextDollar);
|
|
70
|
+
i = nextDollar;
|
|
41
71
|
}
|
|
42
|
-
replaced = replaced.replaceAll(`\${${key}}`, replace[key] ?? "");
|
|
43
72
|
}
|
|
44
|
-
return
|
|
73
|
+
return result;
|
|
45
74
|
};
|
|
46
|
-
export const load = async (path, language,
|
|
75
|
+
export const load = async (path, language, { cookie, header, types, } = FreezeEmpty) => {
|
|
47
76
|
const directories = await readdir(path, {
|
|
48
77
|
withFileTypes: true,
|
|
49
78
|
});
|
|
@@ -54,29 +83,35 @@ export const load = async (path, language, options) => {
|
|
|
54
83
|
.map((directory) => {
|
|
55
84
|
return directory.name;
|
|
56
85
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
86
|
+
Object.assign(STORE, {
|
|
87
|
+
cookie,
|
|
88
|
+
header,
|
|
89
|
+
language,
|
|
90
|
+
languages,
|
|
91
|
+
path,
|
|
92
|
+
translations: new Empty(),
|
|
93
|
+
});
|
|
94
|
+
const promises = [];
|
|
63
95
|
for (let i = 0; i < languages.length; i++) {
|
|
64
96
|
const language = languages[i];
|
|
65
97
|
if (!language) {
|
|
66
98
|
continue;
|
|
67
99
|
}
|
|
68
|
-
|
|
100
|
+
promises.push(loadTranslations(join(path, language)).then((translations) => {
|
|
101
|
+
STORE.translations[language] = translations;
|
|
102
|
+
}));
|
|
69
103
|
}
|
|
70
|
-
|
|
71
|
-
|
|
104
|
+
await Promise.all(promises);
|
|
105
|
+
if (types !== false) {
|
|
106
|
+
await Bun.write(join(path, "types.d.ts"), `namespace Cudenix.i18n { interface Translations ${JSON.stringify(STORE.translations[language])}; };`);
|
|
72
107
|
}
|
|
73
108
|
};
|
|
74
109
|
export const getLanguage = () => {
|
|
75
|
-
return (getRequestContext()?.store.i18n
|
|
76
|
-
|
|
110
|
+
return (getRequestContext()?.store.i18n?.language ??
|
|
111
|
+
STORE.language);
|
|
77
112
|
};
|
|
78
|
-
export const translate = (path, { language, replace, } =
|
|
79
|
-
const translations =
|
|
113
|
+
export const translate = (path, { language, replace: replacements, } = FreezeEmpty) => {
|
|
114
|
+
const translations = STORE.translations[language ?? getLanguage()];
|
|
80
115
|
if (!translations) {
|
|
81
116
|
return path;
|
|
82
117
|
}
|
|
@@ -87,29 +122,27 @@ export const translate = (path, { language, replace, } = new Empty()) => {
|
|
|
87
122
|
if (!key) {
|
|
88
123
|
continue;
|
|
89
124
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const keys = Object.keys(replace);
|
|
94
|
-
for (let i = 0; i < keys.length; i++) {
|
|
95
|
-
const key = keys[i];
|
|
96
|
-
if (!key) {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
translation = translation.replaceAll(`\${${key}}`, replace[key] ?? "");
|
|
125
|
+
const next = translation[key];
|
|
126
|
+
if (next === undefined) {
|
|
127
|
+
return path;
|
|
100
128
|
}
|
|
129
|
+
translation = next;
|
|
130
|
+
}
|
|
131
|
+
if (replacements && typeof translation === "string") {
|
|
132
|
+
translation = replace(translation, replacements);
|
|
101
133
|
}
|
|
102
134
|
return translation;
|
|
103
135
|
};
|
|
104
136
|
export const i18n = () => {
|
|
105
|
-
return module().middleware(({ request: { raw },
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
137
|
+
return module().middleware(({ request: { raw }, response: { cookies }, store }, next) => {
|
|
138
|
+
store.i18n = {
|
|
139
|
+
language: STORE.languages.length <= 1
|
|
140
|
+
? STORE.language
|
|
141
|
+
: (selectHeader((STORE.cookie
|
|
142
|
+
? cookies.get(STORE.cookie)
|
|
143
|
+
: undefined) ??
|
|
144
|
+
raw.headers.get(STORE.header ?? "accept-language") ??
|
|
145
|
+
STORE.language, STORE.languages, true) ?? STORE.language),
|
|
113
146
|
};
|
|
114
147
|
return next();
|
|
115
148
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/i18n/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mEAAmE,CAAC;AACtG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/i18n/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mEAAmE,CAAC;AACtG,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,KAAK,GAAG,IAAI,KAAK,EAAqB,CAAC;AAoD7C,M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oot":"","sources":["../../../../src/ecosystem/plugins/i18n/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,mBAAmB,gCAAgC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/i18n/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/openapi/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/openapi/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { App } from "../../../core/app.js";
|
|
2
|
-
|
|
2
|
+
interface OpenapiPluginOptions {
|
|
3
3
|
description?: string;
|
|
4
4
|
title?: string;
|
|
5
5
|
version?: string;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
interface OpenapiModuleOptions {
|
|
8
8
|
path?: `/${string}`;
|
|
9
9
|
}
|
|
10
10
|
export declare const plugin: (toJsonSchema: (schema: any) => Record<string, any>, { description, title, version, }?: OpenapiPluginOptions) => (this: App) => string;
|
|
@@ -24,7 +24,7 @@ export declare const openapi: ({ path }?: OpenapiModuleOptions) => import("../..
|
|
|
24
24
|
method: "GET";
|
|
25
25
|
path: `/${string}/json`;
|
|
26
26
|
request: import("../../../index.js").MergeInferValidatorRequest<{}, import("../../../index.js").DeepInferValidatorInput<Partial<import("../../../index.js").ValidatorRequest<unknown, unknown, unknown, unknown, unknown>>>>;
|
|
27
|
-
response: import("../../../core/success.js").Success<
|
|
27
|
+
response: import("../../../core/success.js").Success<string, 200, false>;
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
};
|
|
@@ -32,4 +32,5 @@ export declare const openapi: ({ path }?: OpenapiModuleOptions) => import("../..
|
|
|
32
32
|
inputs: NonNullable<unknown>;
|
|
33
33
|
outputs: NonNullable<unknown>;
|
|
34
34
|
}>;
|
|
35
|
+
export {};
|
|
35
36
|
//# sourceMappingURL=openapi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/openapi/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../../src/ecosystem/plugins/openapi/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAYtC,UAAU,oBAAoB;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,oBAAoB;IAC7B,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,MAAM,GAClB,cAAc,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClD,mCAIG,oBAAkC,MAEpB,MAAM,GAAG,WAyN1B,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,WAAU,oBAAkC;;;;;;;;;;;;;;;;;;;;;;;EAmCnE,CAAC"}
|
|
@@ -1,42 +1,30 @@
|
|
|
1
1
|
import { module } from "../../../core/module.js";
|
|
2
2
|
import { success } from "../../../core/success.js";
|
|
3
3
|
import { scalar } from "../../../ecosystem/plugins/openapi/scalar.js";
|
|
4
|
-
import { Empty } from "../../../utils/objects/empty.js";
|
|
5
|
-
const
|
|
6
|
-
const endsWithSRegexp = /s$/;
|
|
7
|
-
const startsWithEllipsisRegexp = /^\.{3}/;
|
|
8
|
-
const startsWithSlashRegexp = /^\/{/;
|
|
9
|
-
const contentTypes = [
|
|
4
|
+
import { Empty, FreezeEmpty } from "../../../utils/objects/empty.js";
|
|
5
|
+
const CONTENT_TYPES = [
|
|
10
6
|
"application/json",
|
|
11
7
|
"multipart/form-data",
|
|
12
8
|
"text/plain",
|
|
13
9
|
];
|
|
14
|
-
export const plugin = (toJsonSchema, { description = "Cudenix Documentation", title = "Cudenix Documentation", version = "0.0.1", } =
|
|
10
|
+
export const plugin = (toJsonSchema, { description = "Cudenix Documentation", title = "Cudenix Documentation", version = "0.0.1", } = FreezeEmpty) => {
|
|
15
11
|
return function () {
|
|
16
12
|
const paths = new Empty();
|
|
17
|
-
const methods = Array.from(this.endpoints.keys());
|
|
18
13
|
const tags = new Set();
|
|
19
|
-
for (
|
|
20
|
-
|
|
21
|
-
if (!method) {
|
|
14
|
+
for (const [method, methodData] of this.methods) {
|
|
15
|
+
if (!methodData) {
|
|
22
16
|
continue;
|
|
23
17
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
for (let j = 0; j < endpoints.length; j++) {
|
|
29
|
-
const endpoint = endpoints[j];
|
|
18
|
+
for (let j = 0; j < methodData.endpoints.length; j++) {
|
|
19
|
+
const endpoint = methodData.endpoints[j];
|
|
30
20
|
if (!endpoint) {
|
|
31
21
|
continue;
|
|
32
22
|
}
|
|
33
|
-
const path = endpoint.path
|
|
34
|
-
.replaceAll(/:(\w+)/g, "{$1}")
|
|
35
|
-
.replaceAll(/\.{3}(\w+)/g, "{$1}");
|
|
23
|
+
const path = endpoint.path.replaceAll(/(?::|\.{3})(\w+)\??/g, "{$1}");
|
|
36
24
|
const operation = new Empty();
|
|
37
25
|
for (let k = 0; k < endpoint.chain.length; k++) {
|
|
38
26
|
const link = endpoint.chain[k];
|
|
39
|
-
if (link
|
|
27
|
+
if (!link || link.type !== "VALIDATOR") {
|
|
40
28
|
continue;
|
|
41
29
|
}
|
|
42
30
|
const keys = Object.keys(link.request);
|
|
@@ -46,7 +34,11 @@ export const plugin = (toJsonSchema, { description = "Cudenix Documentation", ti
|
|
|
46
34
|
continue;
|
|
47
35
|
}
|
|
48
36
|
if (key !== "body") {
|
|
49
|
-
const _in = key
|
|
37
|
+
const _in = key === "params"
|
|
38
|
+
? "path"
|
|
39
|
+
: key.endsWith("s")
|
|
40
|
+
? key.slice(0, -1)
|
|
41
|
+
: key;
|
|
50
42
|
const schema = toJsonSchema(link.request[key]);
|
|
51
43
|
operation.parameters ??= [];
|
|
52
44
|
if (schema.type === "object") {
|
|
@@ -60,7 +52,7 @@ export const plugin = (toJsonSchema, { description = "Cudenix Documentation", ti
|
|
|
60
52
|
operation.parameters.push({
|
|
61
53
|
in: _in,
|
|
62
54
|
name: key,
|
|
63
|
-
required: schema.required?.
|
|
55
|
+
required: (schema.required?.indexOf(key) ?? -1) !== -1,
|
|
64
56
|
schema: property,
|
|
65
57
|
});
|
|
66
58
|
}
|
|
@@ -75,13 +67,14 @@ export const plugin = (toJsonSchema, { description = "Cudenix Documentation", ti
|
|
|
75
67
|
operation.requestBody ??= {
|
|
76
68
|
content: new Empty(),
|
|
77
69
|
};
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
const bodySchema = toJsonSchema(link.request[key]);
|
|
71
|
+
for (let m = 0; m < CONTENT_TYPES.length; m++) {
|
|
72
|
+
const contentType = CONTENT_TYPES[m];
|
|
80
73
|
if (!contentType) {
|
|
81
74
|
continue;
|
|
82
75
|
}
|
|
83
76
|
operation.requestBody.content[contentType] = {
|
|
84
|
-
schema:
|
|
77
|
+
schema: bodySchema,
|
|
85
78
|
};
|
|
86
79
|
}
|
|
87
80
|
}
|
|
@@ -93,9 +86,9 @@ export const plugin = (toJsonSchema, { description = "Cudenix Documentation", ti
|
|
|
93
86
|
if (!param) {
|
|
94
87
|
continue;
|
|
95
88
|
}
|
|
96
|
-
const name = param
|
|
97
|
-
.
|
|
98
|
-
.
|
|
89
|
+
const name = param.slice(param.charCodeAt(0) === 46 ? 3 : 1, param.charCodeAt(param.length - 1) === 63
|
|
90
|
+
? param.length - 1
|
|
91
|
+
: param.length);
|
|
99
92
|
if (operation.parameters?.some((parameter) => {
|
|
100
93
|
return (parameter.in === "path" &&
|
|
101
94
|
parameter.name === name);
|
|
@@ -106,9 +99,9 @@ export const plugin = (toJsonSchema, { description = "Cudenix Documentation", ti
|
|
|
106
99
|
operation.parameters.push({
|
|
107
100
|
in: "path",
|
|
108
101
|
name,
|
|
109
|
-
required: !
|
|
102
|
+
required: !param.endsWith("?"),
|
|
110
103
|
schema: {
|
|
111
|
-
pattern:
|
|
104
|
+
pattern: param.startsWith("...")
|
|
112
105
|
? ".*"
|
|
113
106
|
: undefined,
|
|
114
107
|
type: "string",
|
|
@@ -116,13 +109,12 @@ export const plugin = (toJsonSchema, { description = "Cudenix Documentation", ti
|
|
|
116
109
|
});
|
|
117
110
|
}
|
|
118
111
|
}
|
|
119
|
-
if (!
|
|
112
|
+
if (!path.startsWith("/{")) {
|
|
120
113
|
const tag = path.split("/")[1];
|
|
121
|
-
if (
|
|
122
|
-
|
|
114
|
+
if (tag) {
|
|
115
|
+
operation.tags = [tag];
|
|
116
|
+
tags.add(tag);
|
|
123
117
|
}
|
|
124
|
-
operation.tags = [tag];
|
|
125
|
-
tags.add(tag);
|
|
126
118
|
}
|
|
127
119
|
paths[path] ??= new Empty();
|
|
128
120
|
paths[path][method.toLowerCase()] =
|
|
@@ -137,24 +129,37 @@ export const plugin = (toJsonSchema, { description = "Cudenix Documentation", ti
|
|
|
137
129
|
},
|
|
138
130
|
openapi: "3.1.0",
|
|
139
131
|
paths,
|
|
140
|
-
tags: Array.from(tags
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
tags: Array.from(tags, (tag) => {
|
|
133
|
+
return {
|
|
134
|
+
name: tag,
|
|
135
|
+
};
|
|
136
|
+
}),
|
|
143
137
|
});
|
|
144
138
|
return "openapi";
|
|
145
139
|
};
|
|
146
140
|
};
|
|
147
|
-
export const openapi = ({ path } =
|
|
148
|
-
const url =
|
|
141
|
+
export const openapi = ({ path } = FreezeEmpty) => {
|
|
142
|
+
const url = (path ?? "/openapi");
|
|
143
|
+
let cachedHtml;
|
|
144
|
+
let cachedJson;
|
|
149
145
|
return module()
|
|
150
146
|
.route("GET", url, ({ memory, response: { headers } }) => {
|
|
151
147
|
headers.set("Content-Type", "text/html");
|
|
152
|
-
|
|
148
|
+
if (!cachedHtml) {
|
|
149
|
+
cachedJson ??= JSON.stringify(memory.get("openapi"));
|
|
150
|
+
cachedHtml = scalar("Cudenix Documentation", cachedJson, JSON.stringify({}));
|
|
151
|
+
}
|
|
152
|
+
return success(cachedHtml, {
|
|
153
153
|
transform: false,
|
|
154
154
|
});
|
|
155
155
|
})
|
|
156
156
|
.route("GET", `${url}/json`, ({ memory }) => {
|
|
157
|
-
|
|
157
|
+
if (!cachedJson) {
|
|
158
|
+
cachedJson = JSON.stringify(memory.get("openapi"));
|
|
159
|
+
}
|
|
160
|
+
return success(cachedJson, {
|
|
161
|
+
transform: false,
|
|
162
|
+
});
|
|
158
163
|
});
|
|
159
164
|
};
|
|
160
165
|
//# sourceMappingURL=openapi.js.map
|