chore: update schema and prettify, fix package.json and Makefile

This commit is contained in:
yusing 2025-04-16 05:46:37 +08:00
parent 49d062a94b
commit 7e56fce4c9
24 changed files with 778 additions and 583 deletions

View file

@ -31,12 +31,12 @@ ifeq ($(debug), 1)
else ifeq ($(pprof), 1) else ifeq ($(pprof), 1)
CGO_ENABLED = 1 CGO_ENABLED = 1
GORACE = log_path=logs/pprof strip_path_prefix=$(shell pwd)/ halt_on_error=1 GORACE = log_path=logs/pprof strip_path_prefix=$(shell pwd)/ halt_on_error=1
BUILD_FLAGS = -tags pprof BUILD_FLAGS += -tags pprof
VERSION := ${VERSION}-pprof VERSION := ${VERSION}-pprof
else else
CGO_ENABLED = 0 CGO_ENABLED = 0
LDFLAGS += -s -w LDFLAGS += -s -w
BUILD_FLAGS = -pgo=auto -tags production BUILD_FLAGS += -pgo=auto -tags production
endif endif
BUILD_FLAGS += -ldflags='$(LDFLAGS)' BUILD_FLAGS += -ldflags='$(LDFLAGS)'
@ -94,43 +94,5 @@ cloc:
link-binary: link-binary:
ln -s /app/${NAME} bin/run ln -s /app/${NAME} bin/run
# To generate schema
# comment out this part from typescript-json-schema.js#L884
#
# if (indexType.flags !== ts.TypeFlags.Number && !isIndexedObject) {
# throw new Error("Not supported: IndexSignatureDeclaration with index symbol other than a number or a string");
# }
gen-schema-single:
bun --bun run typescript-json-schema --noExtraProps --required --skipLibCheck --tsNodeRegister=true -o schemas/${OUT} schemas/${IN} ${CLASS}
# minify
python3 -c "import json; f=open('schemas/${OUT}', 'r'); j=json.load(f); f.close(); f=open('schemas/${OUT}', 'w'); json.dump(j, f, separators=(',', ':'));"
gen-schema:
cd schemas && bun --bun tsc
make IN=config/config.ts \
CLASS=Config \
OUT=config.schema.json \
gen-schema-single
make IN=providers/routes.ts \
CLASS=Routes \
OUT=routes.schema.json \
gen-schema-single
make IN=middlewares/middleware_compose.ts \
CLASS=MiddlewareCompose \
OUT=middleware_compose.schema.json \
gen-schema-single
make IN=docker.ts \
CLASS=DockerRoutes \
OUT=docker_routes.schema.json \
gen-schema-single
cd ..
publish-schema:
cd schemas && bun publish && cd ..
update-schema-generator:
pnpm up -g typescript-json-schema
push-github: push-github:
git push origin $(shell git rev-parse --abbrev-ref HEAD) git push origin $(shell git rev-parse --abbrev-ref HEAD)

33
schemas/Makefile Normal file
View file

@ -0,0 +1,33 @@
# To generate schema
# comment out this part from typescript-json-schema.js#L884
#
# if (indexType.flags !== ts.TypeFlags.Number && !isIndexedObject) {
# throw new Error("Not supported: IndexSignatureDeclaration with index symbol other than a number or a string");
# }
gen-schema-single:
bun -bun typescript-json-schema --noExtraProps --required --skipLibCheck --tsNodeRegister=true -o "${OUT}" "${IN}" ${CLASS}
# minify
python3 -c "import json; f=open('${OUT}', 'r'); j=json.load(f); f.close(); f=open('${OUT}', 'w'); json.dump(j, f, separators=(',', ':'));"
gen-schema:
bun -bun tsc
sed -i 's#"type": "module"#"type": "commonjs"#' package.json
make IN=config/config.ts \
CLASS=Config \
OUT=config.schema.json \
gen-schema-single
make IN=providers/routes.ts \
CLASS=Routes \
OUT=routes.schema.json \
gen-schema-single
make IN=middlewares/middleware_compose.ts \
CLASS=MiddlewareCompose \
OUT=middleware_compose.schema.json \
gen-schema-single
make IN=docker.ts \
CLASS=DockerRoutes \
OUT=docker_routes.schema.json \
gen-schema-single
sed -i 's#"type": "commonjs"#"type": "module"#' package.json
bun format:write

View file

@ -2,10 +2,10 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"workspaces": { "workspaces": {
"": { "": {
"name": "godoxy-types", "name": "godoxy-schemas",
"devDependencies": { "devDependencies": {
"prettier": "^3.4.2", "prettier": "^3.5.3",
"typescript": "^5.7.3", "typescript": "^5.8.3",
"typescript-json-schema": "^0.65.1", "typescript-json-schema": "^0.65.1",
}, },
}, },
@ -29,9 +29,9 @@
"@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="], "@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="],
"@types/node": ["@types/node@18.19.74", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-HMwEkkifei3L605gFdV+/UwtpxP6JSzM+xFk2Ia6DNFSwSVBRh9qp5Tgf4lNFOMfPVuU0WnkcWpXZpgn5ufO4A=="], "@types/node": ["@types/node@18.19.86", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-fifKayi175wLyKyc5qUfyENhQ1dCNI1UNjp653d8kuYcPQN5JhX3dGuP/XmvPTg/xRBn1VTLpbmi+H/Mr7tLfQ=="],
"acorn": ["acorn@8.14.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="], "acorn": ["acorn@8.14.1", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg=="],
"acorn-walk": ["acorn-walk@8.3.4", "", { "dependencies": { "acorn": "^8.11.0" } }, "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g=="], "acorn-walk": ["acorn-walk@8.3.4", "", { "dependencies": { "acorn": "^8.11.0" } }, "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g=="],
@ -83,7 +83,7 @@
"path-is-absolute": ["path-is-absolute@1.0.1", "", {}, "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg=="], "path-is-absolute": ["path-is-absolute@1.0.1", "", {}, "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg=="],
"prettier": ["prettier@3.4.2", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ=="], "prettier": ["prettier@3.5.3", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw=="],
"require-directory": ["require-directory@2.1.1", "", {}, "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q=="], "require-directory": ["require-directory@2.1.1", "", {}, "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q=="],
@ -95,7 +95,7 @@
"ts-node": ["ts-node@10.9.2", "", { "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", "@tsconfig/node12": "^1.0.7", "@tsconfig/node14": "^1.0.0", "@tsconfig/node16": "^1.0.2", "acorn": "^8.4.1", "acorn-walk": "^8.1.1", "arg": "^4.1.0", "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", "v8-compile-cache-lib": "^3.0.1", "yn": "3.1.1" }, "peerDependencies": { "@swc/core": ">=1.2.50", "@swc/wasm": ">=1.2.50", "@types/node": "*", "typescript": ">=2.7" }, "optionalPeers": ["@swc/core", "@swc/wasm"], "bin": { "ts-node": "dist/bin.js", "ts-script": "dist/bin-script-deprecated.js", "ts-node-cwd": "dist/bin-cwd.js", "ts-node-esm": "dist/bin-esm.js", "ts-node-script": "dist/bin-script.js", "ts-node-transpile-only": "dist/bin-transpile.js" } }, "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ=="], "ts-node": ["ts-node@10.9.2", "", { "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", "@tsconfig/node12": "^1.0.7", "@tsconfig/node14": "^1.0.0", "@tsconfig/node16": "^1.0.2", "acorn": "^8.4.1", "acorn-walk": "^8.1.1", "arg": "^4.1.0", "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", "v8-compile-cache-lib": "^3.0.1", "yn": "3.1.1" }, "peerDependencies": { "@swc/core": ">=1.2.50", "@swc/wasm": ">=1.2.50", "@types/node": "*", "typescript": ">=2.7" }, "optionalPeers": ["@swc/core", "@swc/wasm"], "bin": { "ts-node": "dist/bin.js", "ts-script": "dist/bin-script-deprecated.js", "ts-node-cwd": "dist/bin-cwd.js", "ts-node-esm": "dist/bin-esm.js", "ts-node-script": "dist/bin-script.js", "ts-node-transpile-only": "dist/bin-transpile.js" } }, "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ=="],
"typescript": ["typescript@5.7.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw=="], "typescript": ["typescript@5.8.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ=="],
"typescript-json-schema": ["typescript-json-schema@0.65.1", "", { "dependencies": { "@types/json-schema": "^7.0.9", "@types/node": "^18.11.9", "glob": "^7.1.7", "path-equal": "^1.2.5", "safe-stable-stringify": "^2.2.0", "ts-node": "^10.9.1", "typescript": "~5.5.0", "yargs": "^17.1.1" }, "bin": { "typescript-json-schema": "bin/typescript-json-schema" } }, "sha512-tuGH7ff2jPaUYi6as3lHyHcKpSmXIqN7/mu50x3HlYn0EHzLpmt3nplZ7EuhUkO0eqDRc9GqWNkfjgBPIS9kxg=="], "typescript-json-schema": ["typescript-json-schema@0.65.1", "", { "dependencies": { "@types/json-schema": "^7.0.9", "@types/node": "^18.11.9", "glob": "^7.1.7", "path-equal": "^1.2.5", "safe-stable-stringify": "^2.2.0", "ts-node": "^10.9.1", "typescript": "~5.5.0", "yargs": "^17.1.1" }, "bin": { "typescript-json-schema": "bin/typescript-json-schema" } }, "sha512-tuGH7ff2jPaUYi6as3lHyHcKpSmXIqN7/mu50x3HlYn0EHzLpmt3nplZ7EuhUkO0eqDRc9GqWNkfjgBPIS9kxg=="],

View file

@ -1,5 +1,9 @@
import { CIDR, HTTPHeader, HTTPMethod, StatusCodeRange, URI } from "../types"; import { CIDR, HTTPHeader, HTTPMethod, StatusCodeRange, URI } from "../types";
export declare const ACCESS_LOG_FORMATS: readonly ["combined", "common", "json"]; export declare const ACCESS_LOG_FORMATS: readonly [
"combined",
"common",
"json",
];
export type AccessLogFormat = (typeof ACCESS_LOG_FORMATS)[number]; export type AccessLogFormat = (typeof ACCESS_LOG_FORMATS)[number];
export type AccessLogConfig = { export type AccessLogConfig = {
/** /**
@ -34,7 +38,11 @@ export type AccessLogFilters = {
headers?: AccessLogFilter<HTTPHeader>; headers?: AccessLogFilter<HTTPHeader>;
cidr?: AccessLogFilter<CIDR>; cidr?: AccessLogFilter<CIDR>;
}; };
export declare const ACCESS_LOG_FIELD_MODES: readonly ["keep", "drop", "redact"]; export declare const ACCESS_LOG_FIELD_MODES: readonly [
"keep",
"drop",
"redact",
];
export type AccessLogFieldMode = (typeof ACCESS_LOG_FIELD_MODES)[number]; export type AccessLogFieldMode = (typeof ACCESS_LOG_FIELD_MODES)[number];
export type AccessLogField = { export type AccessLogField = {
default?: AccessLogFieldMode; default?: AccessLogFieldMode;

View file

@ -1,7 +1,21 @@
import { DomainOrWildcard, Email } from "../types"; import { DomainOrWildcard, Email } from "../types";
export declare const AUTOCERT_PROVIDERS: readonly ["local", "cloudflare", "clouddns", "duckdns", "ovh", "porkbun"]; export declare const AUTOCERT_PROVIDERS: readonly [
"local",
"cloudflare",
"clouddns",
"duckdns",
"ovh",
"porkbun",
];
export type AutocertProvider = (typeof AUTOCERT_PROVIDERS)[number]; export type AutocertProvider = (typeof AUTOCERT_PROVIDERS)[number];
export type AutocertConfig = LocalOptions | CloudflareOptions | CloudDNSOptions | DuckDNSOptions | OVHOptionsWithAppKey | OVHOptionsWithOAuth2Config | PorkbunOptions; export type AutocertConfig =
| LocalOptions
| CloudflareOptions
| CloudDNSOptions
| DuckDNSOptions
| OVHOptionsWithAppKey
| OVHOptionsWithOAuth2Config
| PorkbunOptions;
export interface AutocertConfigBase { export interface AutocertConfigBase {
email: Email; email: Email;
domains: DomainOrWildcard[]; domains: DomainOrWildcard[];
@ -41,7 +55,15 @@ export interface PorkbunOptions extends AutocertConfigBase {
secret_api_key: string; secret_api_key: string;
}; };
} }
export declare const OVH_ENDPOINTS: readonly ["ovh-eu", "ovh-ca", "ovh-us", "kimsufi-eu", "kimsufi-ca", "soyoustart-eu", "soyoustart-ca"]; export declare const OVH_ENDPOINTS: readonly [
"ovh-eu",
"ovh-ca",
"ovh-us",
"kimsufi-eu",
"kimsufi-ca",
"soyoustart-eu",
"soyoustart-ca",
];
export type OVHEndpoint = (typeof OVH_ENDPOINTS)[number]; export type OVHEndpoint = (typeof OVH_ENDPOINTS)[number];
export interface OVHOptionsWithAppKey extends AutocertConfigBase { export interface OVHOptionsWithAppKey extends AutocertConfigBase {
provider: "ovh"; provider: "ovh";

View file

@ -25,12 +25,14 @@ export type Config = {
*/ */
timeout_shutdown?: number; timeout_shutdown?: number;
}; };
export declare const autocertExamples: ({ export declare const autocertExamples: (
| {
provider: string; provider: string;
email?: undefined; email?: undefined;
domains?: undefined; domains?: undefined;
options?: undefined; options?: undefined;
} | { }
| {
provider: string; provider: string;
email: string; email: string;
domains: string[]; domains: string[];
@ -40,7 +42,8 @@ export declare const autocertExamples: ({
email?: undefined; email?: undefined;
password?: undefined; password?: undefined;
}; };
} | { }
| {
provider: string; provider: string;
email: string; email: string;
domains: string[]; domains: string[];
@ -50,5 +53,9 @@ export declare const autocertExamples: ({
password: string; password: string;
auth_token?: undefined; auth_token?: undefined;
}; };
})[]; }
export declare const matchDomainsExamples: readonly ["example.com", "*.example.com"]; )[];
export declare const matchDomainsExamples: readonly [
"example.com",
"*.example.com",
];

View file

@ -12,7 +12,8 @@ export type EntrypointConfig = {
*/ */
access_log?: AccessLogConfig; access_log?: AccessLogConfig;
}; };
export declare const accessLogExamples: readonly [{ export declare const accessLogExamples: readonly [
{
readonly path: "/var/log/access.log"; readonly path: "/var/log/access.log";
readonly format: "combined"; readonly format: "combined";
readonly filters: { readonly filters: {
@ -28,12 +29,21 @@ export declare const accessLogExamples: readonly [{
}; };
}; };
}; };
}]; },
export declare const middlewaresExamples: readonly [{ ];
export declare const middlewaresExamples: readonly [
{
readonly use: "RedirectHTTP"; readonly use: "RedirectHTTP";
}, { },
{
readonly use: "CIDRWhitelist"; readonly use: "CIDRWhitelist";
readonly allow: readonly ["127.0.0.1", "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]; readonly allow: readonly [
"127.0.0.1",
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16",
];
readonly status: 403; readonly status: 403;
readonly message: "Forbidden"; readonly message: "Forbidden";
}]; },
];

View file

@ -1,5 +1,9 @@
import { URL } from "../types"; import { URL } from "../types";
export declare const NOTIFICATION_PROVIDERS: readonly ["webhook", "gotify", "ntfy"]; export declare const NOTIFICATION_PROVIDERS: readonly [
"webhook",
"gotify",
"ntfy",
];
export type NotificationProvider = (typeof NOTIFICATION_PROVIDERS)[number]; export type NotificationProvider = (typeof NOTIFICATION_PROVIDERS)[number];
export type NotificationConfig = { export type NotificationConfig = {
name: string; name: string;
@ -19,7 +23,12 @@ export interface NtfyConfig extends NotificationConfig {
} }
export declare const WEBHOOK_TEMPLATES: readonly ["", "discord"]; export declare const WEBHOOK_TEMPLATES: readonly ["", "discord"];
export declare const WEBHOOK_METHODS: readonly ["POST", "GET", "PUT"]; export declare const WEBHOOK_METHODS: readonly ["POST", "GET", "PUT"];
export declare const WEBHOOK_MIME_TYPES: readonly ["application/json", "application/x-www-form-urlencoded", "text/plain", "text/markdown"]; export declare const WEBHOOK_MIME_TYPES: readonly [
"application/json",
"application/x-www-form-urlencoded",
"text/plain",
"text/markdown",
];
export declare const WEBHOOK_COLOR_MODES: readonly ["hex", "dec"]; export declare const WEBHOOK_COLOR_MODES: readonly ["hex", "dec"];
export type WebhookTemplate = (typeof WEBHOOK_TEMPLATES)[number]; export type WebhookTemplate = (typeof WEBHOOK_TEMPLATES)[number];
export type WebhookMethod = (typeof WEBHOOK_METHODS)[number]; export type WebhookMethod = (typeof WEBHOOK_METHODS)[number];

View file

@ -30,22 +30,29 @@ export type Providers = {
notification?: (WebhookConfig | GotifyConfig | NtfyConfig)[]; notification?: (WebhookConfig | GotifyConfig | NtfyConfig)[];
}; };
export declare const includeExamples: readonly ["file1.yml", "file2.yml"]; export declare const includeExamples: readonly ["file1.yml", "file2.yml"];
export declare const dockerExamples: readonly [{ export declare const dockerExamples: readonly [
{
readonly local: "$DOCKER_HOST"; readonly local: "$DOCKER_HOST";
}, { },
{
readonly remote: "tcp://10.0.2.1:2375"; readonly remote: "tcp://10.0.2.1:2375";
}, { },
{
readonly remote2: "ssh://root:1234@10.0.2.2"; readonly remote2: "ssh://root:1234@10.0.2.2";
}]; },
export declare const notificationExamples: readonly [{ ];
export declare const notificationExamples: readonly [
{
readonly name: "gotify"; readonly name: "gotify";
readonly provider: "gotify"; readonly provider: "gotify";
readonly url: "https://gotify.domain.tld"; readonly url: "https://gotify.domain.tld";
readonly token: "abcd"; readonly token: "abcd";
}, { },
{
readonly name: "discord"; readonly name: "discord";
readonly provider: "webhook"; readonly provider: "webhook";
readonly template: "discord"; readonly template: "discord";
readonly url: "https://discord.com/api/webhooks/1234/abcd"; readonly url: "https://discord.com/api/webhooks/1234/abcd";
}]; },
];
export declare const agentExamples: readonly ["10.0.2.3:8890", "10.0.2.4:8890"]; export declare const agentExamples: readonly ["10.0.2.3:8890", "10.0.2.4:8890"];

File diff suppressed because one or more lines are too long

21
schemas/index.d.ts vendored
View file

@ -16,4 +16,23 @@ import ConfigSchema from "./config.schema.json";
import DockerRoutesSchema from "./docker_routes.schema.json"; import DockerRoutesSchema from "./docker_routes.schema.json";
import MiddlewareComposeSchema from "./middleware_compose.schema.json"; import MiddlewareComposeSchema from "./middleware_compose.schema.json";
import RoutesSchema from "./routes.schema.json"; import RoutesSchema from "./routes.schema.json";
export { AccessLog, Autocert, Config, ConfigSchema, DockerRoutesSchema, Entrypoint, GoDoxy, Healthcheck, Homepage, IdleWatcher, LoadBalance, MiddlewareCompose, MiddlewareComposeSchema, Middlewares, Notification, Providers, Routes, RoutesSchema, }; export {
AccessLog,
Autocert,
Config,
ConfigSchema,
DockerRoutesSchema,
Entrypoint,
GoDoxy,
Healthcheck,
Homepage,
IdleWatcher,
LoadBalance,
MiddlewareCompose,
MiddlewareComposeSchema,
Middlewares,
Notification,
Providers,
Routes,
RoutesSchema,
};

View file

@ -1,10 +1,24 @@
import * as types from "../types"; import * as types from "../types";
export type KeyOptMapping<T extends { export type KeyOptMapping<
T extends {
use: string; use: string;
}> = { },
> = {
[key in T["use"]]?: Omit<T, "use">; [key in T["use"]]?: Omit<T, "use">;
}; };
export declare const ALL_MIDDLEWARES: readonly ["ErrorPage", "RedirectHTTP", "SetXForwarded", "HideXForwarded", "CIDRWhitelist", "CloudflareRealIP", "ModifyRequest", "ModifyResponse", "OIDC", "RateLimit", "RealIP"]; export declare const ALL_MIDDLEWARES: readonly [
"ErrorPage",
"RedirectHTTP",
"SetXForwarded",
"HideXForwarded",
"CIDRWhitelist",
"CloudflareRealIP",
"ModifyRequest",
"ModifyResponse",
"OIDC",
"RateLimit",
"RealIP",
];
/** /**
* @type object * @type object
* @patternProperties {"^.*@file$": {"type": "null"}} * @patternProperties {"^.*@file$": {"type": "null"}}
@ -12,10 +26,39 @@ export declare const ALL_MIDDLEWARES: readonly ["ErrorPage", "RedirectHTTP", "Se
export type MiddlewareFileRef = { export type MiddlewareFileRef = {
[key: `${string}@file`]: null; [key: `${string}@file`]: null;
}; };
export type MiddlewaresMap = (KeyOptMapping<CustomErrorPage> & KeyOptMapping<RedirectHTTP> & KeyOptMapping<SetXForwarded> & KeyOptMapping<HideXForwarded> & KeyOptMapping<CIDRWhitelist> & KeyOptMapping<CloudflareRealIP> & KeyOptMapping<ModifyRequest> & KeyOptMapping<ModifyResponse> & KeyOptMapping<OIDC> & KeyOptMapping<RateLimit> & KeyOptMapping<RealIP>) | MiddlewareFileRef; export type MiddlewaresMap =
export type MiddlewareComposeMap = CustomErrorPage | RedirectHTTP | SetXForwarded | HideXForwarded | CIDRWhitelist | CloudflareRealIP | ModifyRequest | ModifyResponse | OIDC | RateLimit | RealIP; | (KeyOptMapping<CustomErrorPage> &
KeyOptMapping<RedirectHTTP> &
KeyOptMapping<SetXForwarded> &
KeyOptMapping<HideXForwarded> &
KeyOptMapping<CIDRWhitelist> &
KeyOptMapping<CloudflareRealIP> &
KeyOptMapping<ModifyRequest> &
KeyOptMapping<ModifyResponse> &
KeyOptMapping<OIDC> &
KeyOptMapping<RateLimit> &
KeyOptMapping<RealIP>)
| MiddlewareFileRef;
export type MiddlewareComposeMap =
| CustomErrorPage
| RedirectHTTP
| SetXForwarded
| HideXForwarded
| CIDRWhitelist
| CloudflareRealIP
| ModifyRequest
| ModifyResponse
| OIDC
| RateLimit
| RealIP;
export type CustomErrorPage = { export type CustomErrorPage = {
use: "error_page" | "errorPage" | "ErrorPage" | "custom_error_page" | "customErrorPage" | "CustomErrorPage"; use:
| "error_page"
| "errorPage"
| "ErrorPage"
| "custom_error_page"
| "customErrorPage"
| "CustomErrorPage";
}; };
export type RedirectHTTP = { export type RedirectHTTP = {
use: "redirect_http" | "redirectHTTP" | "RedirectHTTP"; use: "redirect_http" | "redirectHTTP" | "RedirectHTTP";
@ -59,7 +102,12 @@ export type CloudflareRealIP = {
recursive?: boolean; recursive?: boolean;
}; };
export type ModifyRequest = { export type ModifyRequest = {
use: "request" | "Request" | "modify_request" | "modifyRequest" | "ModifyRequest"; use:
| "request"
| "Request"
| "modify_request"
| "modifyRequest"
| "ModifyRequest";
/** Set HTTP headers */ /** Set HTTP headers */
set_headers?: { set_headers?: {
[key: types.HTTPHeader]: string; [key: types.HTTPHeader]: string;
@ -74,7 +122,12 @@ export type ModifyRequest = {
add_prefix?: string; add_prefix?: string;
}; };
export type ModifyResponse = { export type ModifyResponse = {
use: "response" | "Response" | "modify_response" | "modifyResponse" | "ModifyResponse"; use:
| "response"
| "Response"
| "modify_response"
| "modifyResponse"
| "ModifyResponse";
/** Set HTTP headers */ /** Set HTTP headers */
set_headers?: { set_headers?: {
[key: types.HTTPHeader]: string; [key: types.HTTPHeader]: string;

View file

@ -1,6 +1,6 @@
{ {
"name": "godoxy-schemas", "name": "godoxy-schemas",
"version": "0.10.0-3", "version": "0.10.1-6",
"description": "JSON Schema and typescript types for GoDoxy configuration", "description": "JSON Schema and typescript types for GoDoxy configuration",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
@ -8,9 +8,11 @@
"url": "https://github.com/yusing/godoxy" "url": "https://github.com/yusing/godoxy"
}, },
"files": [ "files": [
"schemas/", "**/*.ts",
"README.md", "**/*.js",
"LICENSE" "*.schema.json",
"../README.md",
"../LICENSE"
], ],
"type": "module", "type": "module",
"main": "./index.ts", "main": "./index.ts",
@ -22,15 +24,14 @@
} }
}, },
"devDependencies": { "devDependencies": {
"prettier": "^3.4.2", "prettier": "^3.5.3",
"typescript": "^5.7.3", "typescript": "^5.8.3",
"typescript-json-schema": "^0.65.1" "typescript-json-schema": "^0.65.1"
}, },
"displayName": "GoDoxy Types", "displayName": "GoDoxy Types",
"packageManager": "bun@1.2.0", "packageManager": "bun@1.2.9",
"publisher": "yusing", "publisher": "yusing",
"scripts": { "scripts": {
"gen-schema": "make gen-schema", "format:write": "prettier --write \"**/*.ts\" --cache"
"format:write": "prettier --write \"schemas/**/*.ts\" --cache"
} }
} }

View file

@ -1,7 +1,17 @@
import { Duration, URI } from "../types"; import { Duration, URI } from "../types";
export declare const STOP_METHODS: readonly ["pause", "stop", "kill"]; export declare const STOP_METHODS: readonly ["pause", "stop", "kill"];
export type StopMethod = (typeof STOP_METHODS)[number]; export type StopMethod = (typeof STOP_METHODS)[number];
export declare const STOP_SIGNALS: readonly ["", "SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT", "INT", "TERM", "HUP", "QUIT"]; export declare const STOP_SIGNALS: readonly [
"",
"SIGINT",
"SIGTERM",
"SIGHUP",
"SIGQUIT",
"INT",
"TERM",
"HUP",
"QUIT",
];
export type Signal = (typeof STOP_SIGNALS)[number]; export type Signal = (typeof STOP_SIGNALS)[number];
export type IdleWatcherConfig = { export type IdleWatcherConfig = {
idle_timeout?: Duration; idle_timeout?: Duration;

View file

@ -1,5 +1,9 @@
import { RealIP } from "../middlewares/middlewares"; import { RealIP } from "../middlewares/middlewares";
export declare const LOAD_BALANCE_MODES: readonly ["round_robin", "least_conn", "ip_hash"]; export declare const LOAD_BALANCE_MODES: readonly [
"round_robin",
"least_conn",
"ip_hash",
];
export type LoadBalanceMode = (typeof LOAD_BALANCE_MODES)[number]; export type LoadBalanceMode = (typeof LOAD_BALANCE_MODES)[number];
export type LoadBalanceConfigBase = { export type LoadBalanceConfigBase = {
/** Alias (subdomain or FDN) of load-balancer /** Alias (subdomain or FDN) of load-balancer
@ -14,7 +18,13 @@ export type LoadBalanceConfigBase = {
*/ */
weight?: number; weight?: number;
}; };
export type LoadBalanceConfig = LoadBalanceConfigBase & ({} | RoundRobinLoadBalanceConfig | LeastConnLoadBalanceConfig | IPHashLoadBalanceConfig); export type LoadBalanceConfig = LoadBalanceConfigBase &
(
| {}
| RoundRobinLoadBalanceConfig
| LeastConnLoadBalanceConfig
| IPHashLoadBalanceConfig
);
export type IPHashLoadBalanceConfig = { export type IPHashLoadBalanceConfig = {
mode: "ip_hash"; mode: "ip_hash";
/** Real IP config, header to get client IP from */ /** Real IP config, header to get client IP from */

View file

@ -1,7 +1,15 @@
import { AccessLogConfig } from "../config/access_log"; import { AccessLogConfig } from "../config/access_log";
import { accessLogExamples } from "../config/entrypoint"; import { accessLogExamples } from "../config/entrypoint";
import { MiddlewaresMap } from "../middlewares/middlewares"; import { MiddlewaresMap } from "../middlewares/middlewares";
import { Duration, Hostname, IPv4, IPv6, PathPattern, Port, StreamPort } from "../types"; import {
Duration,
Hostname,
IPv4,
IPv6,
PathPattern,
Port,
StreamPort,
} from "../types";
import { HealthcheckConfig } from "./healthcheck"; import { HealthcheckConfig } from "./healthcheck";
import { HomepageConfig } from "./homepage"; import { HomepageConfig } from "./homepage";
import { LoadBalanceConfig } from "./loadbalance"; import { LoadBalanceConfig } from "./loadbalance";
@ -89,6 +97,8 @@ export type FileServerRoute = {
* @examples require(".").accessLogExamples * @examples require(".").accessLogExamples
*/ */
access_log?: AccessLogConfig; access_log?: AccessLogConfig;
/** Healthcheck config */
healthcheck?: HealthcheckConfig;
}; };
export type StreamRoute = { export type StreamRoute = {
/** Alias (subdomain or FDN) /** Alias (subdomain or FDN)
@ -109,24 +119,30 @@ export type StreamRoute = {
/** Healthcheck config */ /** Healthcheck config */
healthcheck?: HealthcheckConfig; healthcheck?: HealthcheckConfig;
}; };
export declare const homepageExamples: ({ export declare const homepageExamples: (
| {
name: string; name: string;
icon: string; icon: string;
category: string; category: string;
} | { }
| {
name: string; name: string;
icon: string; icon: string;
category?: undefined; category?: undefined;
})[]; }
export declare const loadBalanceExamples: ({ )[];
export declare const loadBalanceExamples: (
| {
link: string; link: string;
mode: string; mode: string;
config?: undefined; config?: undefined;
} | { }
| {
link: string; link: string;
mode: string; mode: string;
config: { config: {
header: string; header: string;
}; };
})[]; }
)[];
export { accessLogExamples }; export { accessLogExamples };

View file

@ -1,7 +1,15 @@
import { AccessLogConfig } from "../config/access_log"; import { AccessLogConfig } from "../config/access_log";
import { accessLogExamples } from "../config/entrypoint"; import { accessLogExamples } from "../config/entrypoint";
import { MiddlewaresMap } from "../middlewares/middlewares"; import { MiddlewaresMap } from "../middlewares/middlewares";
import { Duration, Hostname, IPv4, IPv6, PathPattern, Port, StreamPort } from "../types"; import {
Duration,
Hostname,
IPv4,
IPv6,
PathPattern,
Port,
StreamPort,
} from "../types";
import { HealthcheckConfig } from "./healthcheck"; import { HealthcheckConfig } from "./healthcheck";
import { HomepageConfig } from "./homepage"; import { HomepageConfig } from "./homepage";
import { LoadBalanceConfig } from "./loadbalance"; import { LoadBalanceConfig } from "./loadbalance";
@ -94,7 +102,9 @@ export type FileServerRoute = {
* @examples require(".").accessLogExamples * @examples require(".").accessLogExamples
*/ */
access_log?: AccessLogConfig; access_log?: AccessLogConfig;
} /** Healthcheck config */
healthcheck?: HealthcheckConfig;
};
export type StreamRoute = { export type StreamRoute = {
/** Alias (subdomain or FDN) /** Alias (subdomain or FDN)

File diff suppressed because one or more lines are too long

View file

@ -5,12 +5,14 @@
"target": "ESNext", "target": "ESNext",
"module": "ESNext", "module": "ESNext",
"moduleResolution": "Node", "moduleResolution": "Node",
"strict": true, "strict": false,
"esModuleInterop": true, "esModuleInterop": false,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"allowJs": true, "allowJs": false,
"resolveJsonModule": true, "resolveJsonModule": true,
"declaration": true "declaration": true,
"allowSyntheticDefaultImports": true
}, },
"include": ["."] "include": ["**/*.ts"],
"exclude": ["node_modules"]
} }

20
schemas/types.d.ts vendored
View file

@ -4,7 +4,17 @@
export type Null = null; export type Null = null;
export type Nullable<T> = T | Null; export type Nullable<T> = T | Null;
export type NullOrEmptyMap = {} | Null; export type NullOrEmptyMap = {} | Null;
export declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "CONNECT", "HEAD", "OPTIONS", "TRACE"]; export declare const HTTP_METHODS: readonly [
"GET",
"POST",
"PUT",
"PATCH",
"DELETE",
"CONNECT",
"HEAD",
"OPTIONS",
"TRACE",
];
export type HTTPMethod = (typeof HTTP_METHODS)[number]; export type HTTPMethod = (typeof HTTP_METHODS)[number];
/** /**
* HTTP Header * HTTP Header
@ -49,7 +59,13 @@ export type IPv4 = string & {};
* @type string * @type string
*/ */
export type IPv6 = string & {}; export type IPv6 = string & {};
export type CIDR = `${number}.${number}.${number}.${number}` | `${string}:${string}:${string}:${string}:${string}:${string}:${string}:${string}` | `${number}.${number}.${number}.${number}/${number}` | `::${number}` | `${string}::/${number}` | `${string}:${string}::/${number}`; export type CIDR =
| `${number}.${number}.${number}.${number}`
| `${string}:${string}:${string}:${string}:${string}:${string}:${string}:${string}`
| `${number}.${number}.${number}.${number}/${number}`
| `::${number}`
| `${string}::/${number}`
| `${string}:${string}::/${number}`;
/** /**
* @type integer * @type integer
* @minimum 0 * @minimum 0