princejs 1.9.2 → 1.9.3
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/Readme.md +61 -1
- package/dist/prince.d.ts +51 -1
- package/dist/prince.d.ts.map +1 -1
- package/dist/prince.js +12801 -11
- package/dist/scheduler.d.ts +83 -6
- package/dist/scheduler.d.ts.map +1 -1
- package/dist/scheduler.js +54 -1
- package/package.json +1 -1
package/dist/scheduler.d.ts
CHANGED
|
@@ -1,13 +1,90 @@
|
|
|
1
1
|
export declare const cron: (pattern: string, task: () => void) => void;
|
|
2
|
-
export
|
|
3
|
-
title: string;
|
|
4
|
-
version: string;
|
|
5
|
-
}) => {
|
|
2
|
+
export interface OpenAPISpec {
|
|
6
3
|
openapi: string;
|
|
7
4
|
info: {
|
|
8
5
|
title: string;
|
|
9
6
|
version: string;
|
|
7
|
+
[key: string]: unknown;
|
|
10
8
|
};
|
|
11
|
-
paths:
|
|
12
|
-
|
|
9
|
+
paths: Record<string, unknown>;
|
|
10
|
+
components?: Record<string, unknown>;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface ScalarOptions {
|
|
14
|
+
/** Scalar theme. Options: "default" | "alternate" | "moon" | "purple" | "solarized" | "bluePlanet" | "deepSpace" | "saturn" | "kepler" | "mars" | "none" */
|
|
15
|
+
theme?: string;
|
|
16
|
+
/** Page title shown in the browser tab. Defaults to the spec's info.title. */
|
|
17
|
+
pageTitle?: string;
|
|
18
|
+
/** Layout mode. "modern" (default) or "classic" */
|
|
19
|
+
layout?: "modern" | "classic";
|
|
20
|
+
/** Hide the spec download button. */
|
|
21
|
+
hideDownloadButton?: boolean;
|
|
22
|
+
/** Custom CSS injected into the page. */
|
|
23
|
+
customCss?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface OpenAPIBuilder {
|
|
26
|
+
/** The raw spec object — mutate this to add paths, components, etc. */
|
|
27
|
+
spec: OpenAPISpec;
|
|
28
|
+
/** Backward-compatible direct accessors — mirrors spec.openapi / .info / .paths */
|
|
29
|
+
readonly openapi: string;
|
|
30
|
+
readonly info: OpenAPISpec["info"];
|
|
31
|
+
readonly paths: OpenAPISpec["paths"];
|
|
32
|
+
/**
|
|
33
|
+
* Returns a plain-function route handler that serves the Scalar UI.
|
|
34
|
+
* Mount it on any path in your router.
|
|
35
|
+
*
|
|
36
|
+
* Works with any framework that uses `(req, res) => void` handlers
|
|
37
|
+
* (Node http, Express, Fastify inject, etc.).
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Plain Node http
|
|
41
|
+
* server.on("request", (req, res) => {
|
|
42
|
+
* if (req.url === "/docs") return api.scalar()(req, res);
|
|
43
|
+
* if (req.url === "/openapi.json") return api.json()(req, res);
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // Express / Hono-style
|
|
48
|
+
* app.get("/docs", api.scalar({ theme: "moon" }));
|
|
49
|
+
* app.get("/openapi.json", api.json());
|
|
50
|
+
*/
|
|
51
|
+
scalar(options?: ScalarOptions): (req: unknown, res: {
|
|
52
|
+
writeHead(status: number, headers: Record<string, string>): void;
|
|
53
|
+
end(body: string): void;
|
|
54
|
+
}) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Returns a route handler that serves the raw OpenAPI spec as JSON.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* app.get("/openapi.json", api.json());
|
|
60
|
+
*/
|
|
61
|
+
json(): (req: unknown, res: {
|
|
62
|
+
writeHead(status: number, headers: Record<string, string>): void;
|
|
63
|
+
end(body: string): void;
|
|
64
|
+
}) => void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates an OpenAPI builder with a `.scalar()` and `.json()` route handler,
|
|
68
|
+
* mirroring the Hono / @scalar/hono-api-reference middleware pattern —
|
|
69
|
+
* but framework-agnostic.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* import http from "http";
|
|
73
|
+
* import { openapi } from "./scheduler";
|
|
74
|
+
*
|
|
75
|
+
* const api = openapi({ title: "My API", version: "1.0.0" });
|
|
76
|
+
*
|
|
77
|
+
* api.spec.paths["/hello"] = {
|
|
78
|
+
* get: { summary: "Say hello", responses: { 200: { description: "OK" } } },
|
|
79
|
+
* };
|
|
80
|
+
*
|
|
81
|
+
* http.createServer((req, res) => {
|
|
82
|
+
* if (req.url === "/docs") return api.scalar({ theme: "moon" })(req, res);
|
|
83
|
+
* if (req.url === "/openapi.json") return api.json()(req, res);
|
|
84
|
+
* }).listen(3000);
|
|
85
|
+
*/
|
|
86
|
+
export declare const openapi: (info: {
|
|
87
|
+
title: string;
|
|
88
|
+
version: string;
|
|
89
|
+
}) => OpenAPIBuilder;
|
|
13
90
|
//# sourceMappingURL=scheduler.d.ts.map
|
package/dist/scheduler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,GAAI,SAAS,MAAM,EAAE,MAAM,MAAM,IAAI,SAiCrD,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,GAAI,SAAS,MAAM,EAAE,MAAM,MAAM,IAAI,SAiCrD,CAAC;AAIF,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACjE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC,GAAG,EAAE,MAAM,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K,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,KAAG,cAyDlE,CAAC"}
|
package/dist/scheduler.js
CHANGED
|
@@ -23,7 +23,60 @@ var cron = (pattern, task) => {
|
|
|
23
23
|
setInterval(check, 60000);
|
|
24
24
|
};
|
|
25
25
|
var openapi = (info) => {
|
|
26
|
-
|
|
26
|
+
const spec = { openapi: "3.0.0", info, paths: {} };
|
|
27
|
+
const renderScalarHtml = (options = {}) => {
|
|
28
|
+
const {
|
|
29
|
+
pageTitle = spec.info.title,
|
|
30
|
+
theme = "default",
|
|
31
|
+
layout = "modern",
|
|
32
|
+
hideDownloadButton = false,
|
|
33
|
+
customCss = ""
|
|
34
|
+
} = options;
|
|
35
|
+
return `<!doctype html>
|
|
36
|
+
<html lang="en">
|
|
37
|
+
<head>
|
|
38
|
+
<meta charset="utf-8" />
|
|
39
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
40
|
+
<title>${pageTitle}</title>
|
|
41
|
+
${customCss ? `<style>${customCss}</style>` : ""}
|
|
42
|
+
</head>
|
|
43
|
+
<body>
|
|
44
|
+
<script
|
|
45
|
+
id="api-reference"
|
|
46
|
+
type="application/json"
|
|
47
|
+
data-theme="${theme}"
|
|
48
|
+
data-layout="${layout}"
|
|
49
|
+
${hideDownloadButton ? 'data-hide-download-button="true"' : ""}
|
|
50
|
+
>${JSON.stringify(spec)}</script>
|
|
51
|
+
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
52
|
+
</body>
|
|
53
|
+
</html>`;
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
spec,
|
|
57
|
+
get openapi() {
|
|
58
|
+
return spec.openapi;
|
|
59
|
+
},
|
|
60
|
+
get info() {
|
|
61
|
+
return spec.info;
|
|
62
|
+
},
|
|
63
|
+
get paths() {
|
|
64
|
+
return spec.paths;
|
|
65
|
+
},
|
|
66
|
+
scalar(options = {}) {
|
|
67
|
+
return (_req, res) => {
|
|
68
|
+
const html = renderScalarHtml(options);
|
|
69
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
70
|
+
res.end(html);
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
json() {
|
|
74
|
+
return (_req, res) => {
|
|
75
|
+
res.writeHead(200, { "Content-Type": "application/json; charset=utf-8" });
|
|
76
|
+
res.end(JSON.stringify(spec, null, 2));
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
27
80
|
};
|
|
28
81
|
export {
|
|
29
82
|
openapi,
|
package/package.json
CHANGED