@t0.labs/daxta 0.2.1 → 0.2.5
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 +20 -19
- package/dist/cli/discover-test.d.ts +21 -0
- package/dist/cli/discover-test.js +150 -0
- package/dist/cli/inject-main.d.ts +3 -2
- package/dist/cli/inject-main.js +45 -44
- package/dist/cli/install.d.ts +4 -2
- package/dist/cli/install.js +130 -67
- package/dist/cli/main.js +10 -7
- package/dist/cli/test.d.ts +2 -2
- package/dist/cli/test.js +163 -41
- package/dist/cli/ui.d.ts +26 -0
- package/dist/cli/ui.js +110 -0
- package/dist/config.d.ts +4 -0
- 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/dist/cli/ui.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.c = void 0;
|
|
4
|
+
exports.sleep = sleep;
|
|
5
|
+
exports.banner = banner;
|
|
6
|
+
exports.step = step;
|
|
7
|
+
exports.box = box;
|
|
8
|
+
exports.nextSteps = nextSteps;
|
|
9
|
+
const isTTY = Boolean(process.stdout.isTTY);
|
|
10
|
+
const useColor = isTTY && !process.env.NO_COLOR && process.env.FORCE_COLOR !== '0';
|
|
11
|
+
const ansi = {
|
|
12
|
+
reset: '\x1b[0m',
|
|
13
|
+
bold: '\x1b[1m',
|
|
14
|
+
dim: '\x1b[2m',
|
|
15
|
+
cyan: '\x1b[36m',
|
|
16
|
+
green: '\x1b[32m',
|
|
17
|
+
yellow: '\x1b[33m',
|
|
18
|
+
magenta: '\x1b[35m',
|
|
19
|
+
red: '\x1b[31m',
|
|
20
|
+
};
|
|
21
|
+
function paint(code, text) {
|
|
22
|
+
if (!useColor)
|
|
23
|
+
return text;
|
|
24
|
+
return `${code}${text}${ansi.reset}`;
|
|
25
|
+
}
|
|
26
|
+
exports.c = {
|
|
27
|
+
bold: (t) => paint(ansi.bold, t),
|
|
28
|
+
dim: (t) => paint(ansi.dim, t),
|
|
29
|
+
cyan: (t) => paint(ansi.cyan, t),
|
|
30
|
+
green: (t) => paint(ansi.green, t),
|
|
31
|
+
yellow: (t) => paint(ansi.yellow, t),
|
|
32
|
+
magenta: (t) => paint(ansi.magenta, t),
|
|
33
|
+
red: (t) => paint(ansi.red, t),
|
|
34
|
+
};
|
|
35
|
+
function sleep(ms) {
|
|
36
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
37
|
+
}
|
|
38
|
+
function banner(title, subtitle) {
|
|
39
|
+
console.log('');
|
|
40
|
+
console.log(`${exports.c.cyan(exports.c.bold('◆'))} ${exports.c.bold(title)}${subtitle ? exports.c.dim(` ${subtitle}`) : ''}`);
|
|
41
|
+
console.log(exports.c.dim('─'.repeat(Math.min(56, Math.max(28, title.length + 10)))));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Spinner while work runs → ✔ / ✖, optional detail lines, then a short pause to read.
|
|
45
|
+
*/
|
|
46
|
+
async function step(label, work, options = {}) {
|
|
47
|
+
const paceMs = options.paceMs ?? 0;
|
|
48
|
+
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
49
|
+
let i = 0;
|
|
50
|
+
let timer;
|
|
51
|
+
if (isTTY) {
|
|
52
|
+
process.stdout.write(` ${exports.c.cyan(frames[0])} ${label}`);
|
|
53
|
+
timer = setInterval(() => {
|
|
54
|
+
i = (i + 1) % frames.length;
|
|
55
|
+
process.stdout.write(`\r ${exports.c.cyan(frames[i])} ${label}`);
|
|
56
|
+
}, 80);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.log(` … ${label}`);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const result = await work();
|
|
63
|
+
if (timer)
|
|
64
|
+
clearInterval(timer);
|
|
65
|
+
let summary = '';
|
|
66
|
+
let details = [];
|
|
67
|
+
if (typeof result === 'string')
|
|
68
|
+
summary = result;
|
|
69
|
+
else if (result && typeof result === 'object') {
|
|
70
|
+
summary = result.summary;
|
|
71
|
+
details = result.details ?? [];
|
|
72
|
+
}
|
|
73
|
+
const line = summary ? `${label} ${exports.c.dim(summary)}` : label;
|
|
74
|
+
if (isTTY)
|
|
75
|
+
process.stdout.write(`\r ${exports.c.green('✔')} ${line}${' '.repeat(12)}\n`);
|
|
76
|
+
else
|
|
77
|
+
console.log(` ✔ ${line}`);
|
|
78
|
+
for (const d of details) {
|
|
79
|
+
console.log(` ${exports.c.dim('→')} ${d}`);
|
|
80
|
+
}
|
|
81
|
+
if (paceMs > 0)
|
|
82
|
+
await sleep(paceMs);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (timer)
|
|
86
|
+
clearInterval(timer);
|
|
87
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
88
|
+
if (isTTY)
|
|
89
|
+
process.stdout.write(`\r ${exports.c.red('✖')} ${label} ${exports.c.red(msg)}${' '.repeat(8)}\n`);
|
|
90
|
+
else
|
|
91
|
+
console.log(` ✖ ${label} ${msg}`);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function box(title, lines) {
|
|
96
|
+
console.log('');
|
|
97
|
+
console.log(` ${exports.c.magenta(exports.c.bold(title))}`);
|
|
98
|
+
for (const line of lines) {
|
|
99
|
+
console.log(` ${exports.c.dim('│')} ${line}`);
|
|
100
|
+
}
|
|
101
|
+
console.log('');
|
|
102
|
+
}
|
|
103
|
+
function nextSteps(lines) {
|
|
104
|
+
console.log(` ${exports.c.bold('Next')}`);
|
|
105
|
+
for (const { cmd, why } of lines) {
|
|
106
|
+
console.log(` ${exports.c.cyan('$')} ${exports.c.bold(cmd)}`);
|
|
107
|
+
console.log(` ${exports.c.dim(why)}`);
|
|
108
|
+
}
|
|
109
|
+
console.log('');
|
|
110
|
+
}
|
package/dist/config.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ export type DaxtaConfig = {
|
|
|
14
14
|
port?: number;
|
|
15
15
|
fieldsFile?: string;
|
|
16
16
|
docsPath?: string;
|
|
17
|
+
/** package.json script name used by `daxta test` (e.g. test:integration) */
|
|
18
|
+
testScript?: string;
|
|
19
|
+
/** Optional explicit Jest JSON config path */
|
|
20
|
+
jestConfig?: string;
|
|
17
21
|
templatize?: (pathname: string, test?: string) => string | null | undefined;
|
|
18
22
|
operationTag?: (pathTemplate: string, method: string) => string | undefined;
|
|
19
23
|
operationTitle?: (method: string, pathTemplate: string) => string | undefined;
|
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
|
}
|