@t0.labs/daxta 0.2.1 → 0.2.2
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 +7 -7
- package/dist/cli/inject-main.d.ts +1 -1
- package/dist/cli/inject-main.js +23 -22
- package/dist/cli/install.d.ts +1 -1
- package/dist/cli/install.js +2 -2
- package/dist/cli/main.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/register.js +2 -2
- package/dist/serve/index.d.ts +3 -3
- package/dist/serve/index.js +6 -6
- package/dist/serve/middleware.d.ts +5 -5
- package/dist/serve/middleware.js +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,17 +16,17 @@ npx daxta install
|
|
|
16
16
|
- finds `main.ts`, asks **Y / n / other path**, injects:
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
|
-
import {
|
|
19
|
+
import { apiDocs } from '@t0.labs/daxta';
|
|
20
20
|
// ...
|
|
21
21
|
const app = await NestFactory.create(AppModule);
|
|
22
|
-
|
|
22
|
+
apiDocs(app);
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Flags: `--yes`, `--main src/main.ts`, `--skip-main`, `--dry-run`, `--skip-dep`
|
|
26
26
|
|
|
27
27
|
## Required env
|
|
28
28
|
|
|
29
|
-
`
|
|
29
|
+
`apiDocs(app)` **throws** if `DAXTA_DOCS` is missing:
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
DAXTA_DOCS=true # enable /docs
|
|
@@ -47,9 +47,9 @@ daxta call
|
|
|
47
47
|
## API
|
|
48
48
|
|
|
49
49
|
```ts
|
|
50
|
-
import {
|
|
50
|
+
import { apiDocs, apiDocsHandler, serveApiDocs } from '@t0.labs/daxta';
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
app.use(
|
|
54
|
-
|
|
52
|
+
apiDocs(app); // app /docs (needs DAXTA_DOCS)
|
|
53
|
+
app.use(apiDocsHandler()); // raw handler
|
|
54
|
+
serveApiDocs({ port: 5199 }); // standalone viewer
|
|
55
55
|
```
|
|
@@ -4,7 +4,7 @@ export declare function findMainCandidates(cwd: string): string[];
|
|
|
4
4
|
* Ask: use detected main, or type another path / n to skip.
|
|
5
5
|
*/
|
|
6
6
|
export declare function resolveMainPath(cwd: string, candidates: string[]): Promise<string | null>;
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function injectApiDocs(filePath: string, dryRun?: boolean): string;
|
|
8
8
|
export type InjectMainOptions = {
|
|
9
9
|
cwd?: string;
|
|
10
10
|
dryRun?: boolean;
|
package/dist/cli/inject-main.js
CHANGED
|
@@ -35,13 +35,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.findMainCandidates = findMainCandidates;
|
|
37
37
|
exports.resolveMainPath = resolveMainPath;
|
|
38
|
-
exports.
|
|
38
|
+
exports.injectApiDocs = injectApiDocs;
|
|
39
39
|
exports.promptAndInjectMain = promptAndInjectMain;
|
|
40
40
|
const readline_1 = require("readline");
|
|
41
41
|
const fs_1 = require("fs");
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
|
-
const IMPORT_LINE = `import {
|
|
44
|
-
const MARKER = '
|
|
43
|
+
const IMPORT_LINE = `import { apiDocs } from '@t0.labs/daxta';`;
|
|
44
|
+
const MARKER = 'apiDocs(';
|
|
45
45
|
function walk(dir, match, out = [], depth = 0) {
|
|
46
46
|
if (depth > 5 || !(0, fs_1.existsSync)(dir))
|
|
47
47
|
return out;
|
|
@@ -108,7 +108,7 @@ async function resolveMainPath(cwd, candidates) {
|
|
|
108
108
|
.map((c) => path.relative(cwd, c))
|
|
109
109
|
.join(', ')}${candidates.length > 4 ? ', …' : ''}`
|
|
110
110
|
: '';
|
|
111
|
-
const answer = await prompt(`Inject
|
|
111
|
+
const answer = await prompt(`Inject apiDocs(app) into ${rel}? [Y/n / or type another path]${others}\n> `);
|
|
112
112
|
if (!answer || /^y(es)?$/i.test(answer))
|
|
113
113
|
return def;
|
|
114
114
|
if (/^n(o)?$/i.test(answer))
|
|
@@ -120,18 +120,18 @@ async function resolveMainPath(cwd, candidates) {
|
|
|
120
120
|
}
|
|
121
121
|
function ensureImport(source) {
|
|
122
122
|
if (source.includes("from '@t0.labs/daxta'") || source.includes('from "@t0.labs/daxta"')) {
|
|
123
|
-
if (
|
|
123
|
+
if (/import\s*\{[^}]*\bapiDocs\b/.test(source))
|
|
124
124
|
return source;
|
|
125
125
|
return source.replace(/import\s*\{([^}]*)\}\s*from\s*['"]@t0\.labs\/daxta['"]\s*;?/, (full, names) => {
|
|
126
126
|
let next = names;
|
|
127
|
-
next = next.replace(/\
|
|
128
|
-
if (/\
|
|
127
|
+
next = next.replace(/\b(mountDaxtaDocs|docs)\b\s*,?\s*/g, '');
|
|
128
|
+
if (/\bapiDocs\b/.test(next)) {
|
|
129
129
|
return `import { ${next.trim().replace(/,$/, '')} } from '@t0.labs/daxta';`;
|
|
130
130
|
}
|
|
131
131
|
const trimmed = next.trim().replace(/,$/, '');
|
|
132
132
|
return trimmed
|
|
133
|
-
? `import { ${trimmed},
|
|
134
|
-
: `import {
|
|
133
|
+
? `import { ${trimmed}, apiDocs } from '@t0.labs/daxta';`
|
|
134
|
+
: `import { apiDocs } from '@t0.labs/daxta';`;
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
const lastImport = [...source.matchAll(/^import\s.+;?\s*$/gm)].pop();
|
|
@@ -143,17 +143,18 @@ function ensureImport(source) {
|
|
|
143
143
|
}
|
|
144
144
|
return `${IMPORT_LINE}\n\n${source}`;
|
|
145
145
|
}
|
|
146
|
-
function
|
|
147
|
-
if (source.includes(MARKER) || source.includes('mountDaxtaDocs(')) {
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
function ensureApiDocsCall(source) {
|
|
147
|
+
if (source.includes(MARKER) || source.includes('mountDaxtaDocs(') || /\bdocs\s*\(/.test(source)) {
|
|
148
|
+
return source
|
|
149
|
+
.replace(/\bmountDaxtaDocs\s*\(/g, 'apiDocs(')
|
|
150
|
+
.replace(/\bdocs\s*\(/g, 'apiDocs(');
|
|
150
151
|
}
|
|
151
152
|
const constMatch = source.match(/(const|let|var)\s+(\w+)\s*=\s*await\s+NestFactory\.create\b[\s\S]*?;/);
|
|
152
153
|
if (constMatch && constMatch.index != null) {
|
|
153
154
|
const varName = constMatch[2];
|
|
154
155
|
const insertAt = constMatch.index + constMatch[0].length;
|
|
155
156
|
const indent = guessIndent(source, insertAt);
|
|
156
|
-
const hook = `\n${indent}
|
|
157
|
+
const hook = `\n${indent}apiDocs(${varName});`;
|
|
157
158
|
return `${source.slice(0, insertAt)}${hook}${source.slice(insertAt)}`;
|
|
158
159
|
}
|
|
159
160
|
const assignMatch = source.match(/(\w+)\s*=\s*await\s+NestFactory\.create\b[\s\S]*?;/);
|
|
@@ -161,10 +162,10 @@ function ensureDocsCall(source) {
|
|
|
161
162
|
const varName = assignMatch[1];
|
|
162
163
|
const insertAt = assignMatch.index + assignMatch[0].length;
|
|
163
164
|
const indent = guessIndent(source, insertAt);
|
|
164
|
-
const hook = `\n${indent}
|
|
165
|
+
const hook = `\n${indent}apiDocs(${varName});`;
|
|
165
166
|
return `${source.slice(0, insertAt)}${hook}${source.slice(insertAt)}`;
|
|
166
167
|
}
|
|
167
|
-
throw new Error('Could not find `await NestFactory.create(...)` to inject
|
|
168
|
+
throw new Error('Could not find `await NestFactory.create(...)` to inject apiDocs(app). Add it manually near bootstrap.');
|
|
168
169
|
}
|
|
169
170
|
function guessIndent(source, index) {
|
|
170
171
|
const lineStart = source.lastIndexOf('\n', index - 1) + 1;
|
|
@@ -172,18 +173,18 @@ function guessIndent(source, index) {
|
|
|
172
173
|
const m = line.match(/^\s*/);
|
|
173
174
|
return m?.[0] ?? ' ';
|
|
174
175
|
}
|
|
175
|
-
function
|
|
176
|
+
function injectApiDocs(filePath, dryRun = false) {
|
|
176
177
|
const before = (0, fs_1.readFileSync)(filePath, 'utf8');
|
|
177
|
-
if (before.includes(MARKER) && /import\s*\{[^}]*\
|
|
178
|
-
return `already has
|
|
178
|
+
if (before.includes(MARKER) && /import\s*\{[^}]*\bapiDocs\b/.test(before)) {
|
|
179
|
+
return `already has apiDocs() in ${filePath}`;
|
|
179
180
|
}
|
|
180
181
|
let next = ensureImport(before);
|
|
181
|
-
next =
|
|
182
|
+
next = ensureApiDocsCall(next);
|
|
182
183
|
if (next === before)
|
|
183
184
|
return `no changes for ${filePath}`;
|
|
184
185
|
if (!dryRun)
|
|
185
186
|
(0, fs_1.writeFileSync)(filePath, next);
|
|
186
|
-
return `injected
|
|
187
|
+
return `injected apiDocs() into ${path.relative(process.cwd(), filePath)}`;
|
|
187
188
|
}
|
|
188
189
|
async function promptAndInjectMain(options = {}) {
|
|
189
190
|
const cwd = options.cwd ?? process.cwd();
|
|
@@ -209,5 +210,5 @@ async function promptAndInjectMain(options = {}) {
|
|
|
209
210
|
}
|
|
210
211
|
if (!target)
|
|
211
212
|
return 'skipped main.ts inject';
|
|
212
|
-
return
|
|
213
|
+
return injectApiDocs(target, options.dryRun);
|
|
213
214
|
}
|
package/dist/cli/install.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ export type InstallOptions = {
|
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Bootstrap: config, outDir, scripts, strip NODE_OPTIONS hacks,
|
|
11
|
-
* prompt to inject `
|
|
11
|
+
* prompt to inject `apiDocs(app)` into main.ts.
|
|
12
12
|
*/
|
|
13
13
|
export declare function installDaxta(options?: InstallOptions): Promise<void>;
|
package/dist/cli/install.js
CHANGED
|
@@ -152,7 +152,7 @@ function runPackageInstall(cwd, pm, dryRun) {
|
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* Bootstrap: config, outDir, scripts, strip NODE_OPTIONS hacks,
|
|
155
|
-
* prompt to inject `
|
|
155
|
+
* prompt to inject `apiDocs(app)` into main.ts.
|
|
156
156
|
*/
|
|
157
157
|
async function installDaxta(options = {}) {
|
|
158
158
|
const cwd = options.cwd ?? process.cwd();
|
|
@@ -198,7 +198,7 @@ async function installDaxta(options = {}) {
|
|
|
198
198
|
}
|
|
199
199
|
console.log('DAxTA install complete:\n' + log.map((line) => ` - ${line}`).join('\n'));
|
|
200
200
|
console.log(`
|
|
201
|
-
Set in .env (required when
|
|
201
|
+
Set in .env (required when apiDocs(app) runs):
|
|
202
202
|
DAXTA_DOCS=true # enable /docs
|
|
203
203
|
DAXTA_DOCS=false # disable (explicit)
|
|
204
204
|
|
package/dist/cli/main.js
CHANGED
|
@@ -22,7 +22,7 @@ Usage:
|
|
|
22
22
|
|
|
23
23
|
install:
|
|
24
24
|
writes config, strips NODE_OPTIONS register hacks, asks to inject
|
|
25
|
-
|
|
25
|
+
apiDocs(app) into main.ts (requires DAXTA_DOCS env at runtime)
|
|
26
26
|
`);
|
|
27
27
|
}
|
|
28
28
|
function parseArgs(argv) {
|
|
@@ -84,7 +84,7 @@ async function main() {
|
|
|
84
84
|
}
|
|
85
85
|
if (command === 'serve') {
|
|
86
86
|
const port = flags.port ? Number(flags.port) : undefined;
|
|
87
|
-
(0, serve_1.
|
|
87
|
+
(0, serve_1.serveApiDocs)({ port });
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
if (command === 'fields') {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { rebuildFromDisk, flushAndRebuild, clearPartialMarker, touchPartialMarke
|
|
|
4
4
|
export { install, flush, clearWorkerHits, getHits, type RecordedHit } from './recorder';
|
|
5
5
|
export { dtoRequired, type FieldLocation } from './fields/dto-fields';
|
|
6
6
|
export { buildFieldsFile, writeFieldsFile, readFieldsFile, type FieldsFile } from './fields/export-fields';
|
|
7
|
-
export {
|
|
7
|
+
export { apiDocs, apiDocsHandler, serveApiDocs, getDocsBasePath, getHtmlPath, getOutDir, getSpecJsonPath, type ApiDocsHandler, type ApiDocsOptions, } from './serve';
|
|
8
8
|
export { runInteractiveCall, runFileCall, executeCall, type CallValues } from './call';
|
|
9
9
|
export type { FieldDoc, OperationDoc } from './catalog';
|
|
10
10
|
export { installDaxta, type InstallOptions } from './cli/install';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.installDaxta = exports.executeCall = exports.runFileCall = exports.runInteractiveCall = exports.getSpecJsonPath = exports.getOutDir = exports.getHtmlPath = exports.getDocsBasePath = exports.
|
|
3
|
+
exports.installDaxta = exports.executeCall = exports.runFileCall = exports.runInteractiveCall = exports.getSpecJsonPath = exports.getOutDir = exports.getHtmlPath = exports.getDocsBasePath = exports.serveApiDocs = exports.apiDocsHandler = exports.apiDocs = exports.readFieldsFile = exports.writeFieldsFile = exports.buildFieldsFile = exports.dtoRequired = exports.getHits = exports.clearWorkerHits = exports.flush = exports.install = exports.touchPartialMarker = exports.clearPartialMarker = exports.flushAndRebuild = exports.rebuildFromDisk = exports.loadHits = exports.buildOpenApi = exports.buildDaxtaSpec = exports.resolveConfig = exports.getConfig = exports.defineConfig = void 0;
|
|
4
4
|
var config_1 = require("./config");
|
|
5
5
|
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return config_1.defineConfig; } });
|
|
6
6
|
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
|
|
@@ -26,9 +26,9 @@ Object.defineProperty(exports, "buildFieldsFile", { enumerable: true, get: funct
|
|
|
26
26
|
Object.defineProperty(exports, "writeFieldsFile", { enumerable: true, get: function () { return export_fields_1.writeFieldsFile; } });
|
|
27
27
|
Object.defineProperty(exports, "readFieldsFile", { enumerable: true, get: function () { return export_fields_1.readFieldsFile; } });
|
|
28
28
|
var serve_1 = require("./serve");
|
|
29
|
-
Object.defineProperty(exports, "
|
|
30
|
-
Object.defineProperty(exports, "
|
|
31
|
-
Object.defineProperty(exports, "
|
|
29
|
+
Object.defineProperty(exports, "apiDocs", { enumerable: true, get: function () { return serve_1.apiDocs; } });
|
|
30
|
+
Object.defineProperty(exports, "apiDocsHandler", { enumerable: true, get: function () { return serve_1.apiDocsHandler; } });
|
|
31
|
+
Object.defineProperty(exports, "serveApiDocs", { enumerable: true, get: function () { return serve_1.serveApiDocs; } });
|
|
32
32
|
Object.defineProperty(exports, "getDocsBasePath", { enumerable: true, get: function () { return serve_1.getDocsBasePath; } });
|
|
33
33
|
Object.defineProperty(exports, "getHtmlPath", { enumerable: true, get: function () { return serve_1.getHtmlPath; } });
|
|
34
34
|
Object.defineProperty(exports, "getOutDir", { enumerable: true, get: function () { return serve_1.getOutDir; } });
|
package/dist/register.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
/**
|
|
4
4
|
* Side-effect entry: `node -r @t0.labs/daxta/register`
|
|
5
|
-
* Prefer injecting `
|
|
5
|
+
* Prefer injecting `apiDocs(app)` into main.ts via `daxta install`.
|
|
6
6
|
*/
|
|
7
7
|
const middleware_1 = require("./serve/middleware");
|
|
8
8
|
function patchNestFactory() {
|
|
@@ -16,7 +16,7 @@ function patchNestFactory() {
|
|
|
16
16
|
const originalCreate = nestFactory.create.bind(nestFactory);
|
|
17
17
|
nestFactory.create = async (...args) => {
|
|
18
18
|
const app = await originalCreate(...args);
|
|
19
|
-
(0, middleware_1.
|
|
19
|
+
(0, middleware_1.apiDocs)(app);
|
|
20
20
|
return app;
|
|
21
21
|
};
|
|
22
22
|
}
|
package/dist/serve/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as http from 'http';
|
|
2
|
-
export {
|
|
2
|
+
export { apiDocs, apiDocsHandler, type ApiDocsHandler, type ApiDocsOptions } from './middleware';
|
|
3
3
|
export { getDocsBasePath, getHtmlPath, getOutDir, getSpecJsonPath } from './paths';
|
|
4
|
-
/** Standalone docs HTTP server (CLI: `daxta serve`). Prefer `
|
|
5
|
-
export declare function
|
|
4
|
+
/** Standalone docs HTTP server (CLI: `daxta serve`). Prefer `apiDocs(app)` on the app port. */
|
|
5
|
+
export declare function serveApiDocs(options?: {
|
|
6
6
|
port?: number;
|
|
7
7
|
}): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
package/dist/serve/index.js
CHANGED
|
@@ -33,8 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.getSpecJsonPath = exports.getOutDir = exports.getHtmlPath = exports.getDocsBasePath = exports.
|
|
37
|
-
exports.
|
|
36
|
+
exports.getSpecJsonPath = exports.getOutDir = exports.getHtmlPath = exports.getDocsBasePath = exports.apiDocsHandler = exports.apiDocs = void 0;
|
|
37
|
+
exports.serveApiDocs = serveApiDocs;
|
|
38
38
|
const fs_1 = require("fs");
|
|
39
39
|
const http = __importStar(require("http"));
|
|
40
40
|
const url_1 = require("url");
|
|
@@ -43,8 +43,8 @@ const paths_1 = require("./paths");
|
|
|
43
43
|
const proxy_1 = require("./proxy");
|
|
44
44
|
const spec_utils_1 = require("./spec-utils");
|
|
45
45
|
var middleware_1 = require("./middleware");
|
|
46
|
-
Object.defineProperty(exports, "
|
|
47
|
-
Object.defineProperty(exports, "
|
|
46
|
+
Object.defineProperty(exports, "apiDocs", { enumerable: true, get: function () { return middleware_1.apiDocs; } });
|
|
47
|
+
Object.defineProperty(exports, "apiDocsHandler", { enumerable: true, get: function () { return middleware_1.apiDocsHandler; } });
|
|
48
48
|
var paths_2 = require("./paths");
|
|
49
49
|
Object.defineProperty(exports, "getDocsBasePath", { enumerable: true, get: function () { return paths_2.getDocsBasePath; } });
|
|
50
50
|
Object.defineProperty(exports, "getHtmlPath", { enumerable: true, get: function () { return paths_2.getHtmlPath; } });
|
|
@@ -54,8 +54,8 @@ function send(res, status, body, headers = {}) {
|
|
|
54
54
|
res.writeHead(status, headers);
|
|
55
55
|
res.end(body);
|
|
56
56
|
}
|
|
57
|
-
/** Standalone docs HTTP server (CLI: `daxta serve`). Prefer `
|
|
58
|
-
function
|
|
57
|
+
/** Standalone docs HTTP server (CLI: `daxta serve`). Prefer `apiDocs(app)` on the app port. */
|
|
58
|
+
function serveApiDocs(options = {}) {
|
|
59
59
|
const config = (0, config_1.getConfig)();
|
|
60
60
|
const port = options.port ?? Number(process.env.DAXTA_DOCS_PORT || process.env.OPENAPI_DOCS_PORT || config.port);
|
|
61
61
|
const htmlPath = (0, paths_1.getHtmlPath)();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type ApiDocsOptions = {
|
|
2
2
|
/** URL prefix for the viewer. Default from config (`docsPath`) or `/docs`. */
|
|
3
3
|
basePath?: string;
|
|
4
4
|
};
|
|
@@ -20,12 +20,12 @@ type LooseResponse = {
|
|
|
20
20
|
end: (body?: string | Buffer) => void;
|
|
21
21
|
writeHead?: (code: number, headers?: Record<string, string>) => void;
|
|
22
22
|
};
|
|
23
|
-
export type
|
|
23
|
+
export type ApiDocsHandler = (req: LooseRequest, res: LooseResponse, next: (error?: unknown) => void) => void | Promise<void>;
|
|
24
24
|
/**
|
|
25
25
|
* Express / Nest handler that serves the DAxTA viewer under `/docs`
|
|
26
26
|
* (or `basePath`) and the Try-it proxy at `/__proxy`.
|
|
27
27
|
*/
|
|
28
|
-
export declare function
|
|
28
|
+
export declare function apiDocsHandler(options?: ApiDocsOptions): ApiDocsHandler;
|
|
29
29
|
/**
|
|
30
30
|
* Enable DAxTA `/docs` on a Nest / Express app (`app.use(...)`).
|
|
31
31
|
*
|
|
@@ -34,7 +34,7 @@ export declare function docsHandler(options?: DocsOptions): DocsHandler;
|
|
|
34
34
|
* - `true` | `1` | `yes` | `on` → serve `/docs`
|
|
35
35
|
* - `false` | `0` | `no` | `off` → no-op
|
|
36
36
|
*/
|
|
37
|
-
export declare function
|
|
37
|
+
export declare function apiDocs(app: {
|
|
38
38
|
use: (...handlers: unknown[]) => unknown;
|
|
39
|
-
}, options?:
|
|
39
|
+
}, options?: ApiDocsOptions): void;
|
|
40
40
|
export {};
|
package/dist/serve/middleware.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.apiDocsHandler = apiDocsHandler;
|
|
4
|
+
exports.apiDocs = apiDocs;
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const paths_1 = require("./paths");
|
|
7
7
|
const proxy_1 = require("./proxy");
|
|
@@ -60,7 +60,7 @@ function bodyToBuffer(body) {
|
|
|
60
60
|
* Express / Nest handler that serves the DAxTA viewer under `/docs`
|
|
61
61
|
* (or `basePath`) and the Try-it proxy at `/__proxy`.
|
|
62
62
|
*/
|
|
63
|
-
function
|
|
63
|
+
function apiDocsHandler(options = {}) {
|
|
64
64
|
const basePath = (options.basePath ?? (0, paths_1.getDocsBasePath)()).replace(/\/$/, '') || '/docs';
|
|
65
65
|
return async (req, res, next) => {
|
|
66
66
|
const method = (req.method || 'GET').toUpperCase();
|
|
@@ -128,7 +128,7 @@ function docsHandler(options = {}) {
|
|
|
128
128
|
* - `true` | `1` | `yes` | `on` → serve `/docs`
|
|
129
129
|
* - `false` | `0` | `no` | `off` → no-op
|
|
130
130
|
*/
|
|
131
|
-
function
|
|
131
|
+
function apiDocs(app, options = {}) {
|
|
132
132
|
const raw = process.env.DAXTA_DOCS;
|
|
133
133
|
if (raw == null || String(raw).trim() === '') {
|
|
134
134
|
throw new Error('DAxTA: DAXTA_DOCS is not set. Set DAXTA_DOCS=true to enable /docs, or DAXTA_DOCS=false to disable.');
|
|
@@ -141,5 +141,5 @@ function docs(app, options = {}) {
|
|
|
141
141
|
}
|
|
142
142
|
if (!enabled)
|
|
143
143
|
return;
|
|
144
|
-
app.use(
|
|
144
|
+
app.use(apiDocsHandler(options));
|
|
145
145
|
}
|