@t0.labs/daxta 0.2.0
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 +40 -0
- package/assets/favicon.png +0 -0
- package/assets/viewer.html +1835 -0
- package/bin/daxta.js +2 -0
- package/dist/build/build-spec.d.ts +28 -0
- package/dist/build/build-spec.js +704 -0
- package/dist/build/incremental.d.ts +12 -0
- package/dist/build/incremental.js +121 -0
- package/dist/call/index.d.ts +24 -0
- package/dist/call/index.js +204 -0
- package/dist/catalog/index.d.ts +27 -0
- package/dist/catalog/index.js +111 -0
- package/dist/cli/install.d.ts +6 -0
- package/dist/cli/install.js +333 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +102 -0
- package/dist/config.d.ts +31 -0
- package/dist/config.js +106 -0
- package/dist/fields/dto-fields.d.ts +4 -0
- package/dist/fields/dto-fields.js +372 -0
- package/dist/fields/export-fields.d.ts +23 -0
- package/dist/fields/export-fields.js +218 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +42 -0
- package/dist/jest/global-setup.d.ts +1 -0
- package/dist/jest/global-setup.js +7 -0
- package/dist/jest/global-teardown.d.ts +1 -0
- package/dist/jest/global-teardown.js +20 -0
- package/dist/jest/reporter.d.ts +7 -0
- package/dist/jest/reporter.js +29 -0
- package/dist/path.util.d.ts +6 -0
- package/dist/path.util.js +108 -0
- package/dist/recorder/index.d.ts +15 -0
- package/dist/recorder/index.js +176 -0
- package/dist/register.d.ts +1 -0
- package/dist/register.js +27 -0
- package/dist/serve/index.d.ts +9 -0
- package/dist/serve/index.js +126 -0
- package/dist/serve/middleware.d.ts +38 -0
- package/dist/serve/middleware.js +131 -0
- package/dist/serve/paths.d.ts +7 -0
- package/dist/serve/paths.js +66 -0
- package/dist/serve/proxy.d.ts +16 -0
- package/dist/serve/proxy.js +52 -0
- package/dist/serve/spec-utils.d.ts +2 -0
- package/dist/serve/spec-utils.js +27 -0
- package/dist/setup.d.ts +1 -0
- package/dist/setup.js +7 -0
- package/package.json +75 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.installDaxta = installDaxta;
|
|
37
|
+
const fs_1 = require("fs");
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const child_process_1 = require("child_process");
|
|
40
|
+
function walk(dir, match, out = [], depth = 0) {
|
|
41
|
+
if (depth > 6 || !(0, fs_1.existsSync)(dir))
|
|
42
|
+
return out;
|
|
43
|
+
for (const name of (0, fs_1.readdirSync)(dir)) {
|
|
44
|
+
if (name === 'node_modules' || name === 'dist' || name === '.git' || name === 'coverage')
|
|
45
|
+
continue;
|
|
46
|
+
const full = path.join(dir, name);
|
|
47
|
+
let st;
|
|
48
|
+
try {
|
|
49
|
+
st = (0, fs_1.statSync)(full);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (st.isDirectory())
|
|
55
|
+
walk(full, match, out, depth + 1);
|
|
56
|
+
else if (match(name))
|
|
57
|
+
out.push(full);
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function readJson(filePath) {
|
|
62
|
+
return JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
|
|
63
|
+
}
|
|
64
|
+
function writeJson(filePath, value) {
|
|
65
|
+
(0, fs_1.writeFileSync)(filePath, `${JSON.stringify(value, null, 2)}\n`);
|
|
66
|
+
}
|
|
67
|
+
function detectPackageManager(cwd, pkg) {
|
|
68
|
+
if ((0, fs_1.existsSync)(path.join(cwd, 'pnpm-lock.yaml')) || pkg.packageManager?.startsWith('pnpm'))
|
|
69
|
+
return 'pnpm';
|
|
70
|
+
if ((0, fs_1.existsSync)(path.join(cwd, 'yarn.lock')))
|
|
71
|
+
return 'yarn';
|
|
72
|
+
return 'npm';
|
|
73
|
+
}
|
|
74
|
+
function ensureScripts(pkg) {
|
|
75
|
+
const scripts = (pkg.scripts ??= {});
|
|
76
|
+
const wanted = {
|
|
77
|
+
'daxta:build': 'daxta build',
|
|
78
|
+
'daxta:serve': 'daxta serve',
|
|
79
|
+
'daxta:fields': 'daxta fields',
|
|
80
|
+
'daxta:call': 'daxta call',
|
|
81
|
+
};
|
|
82
|
+
const changed = [];
|
|
83
|
+
for (const [key, value] of Object.entries(wanted)) {
|
|
84
|
+
if (scripts[key] !== value) {
|
|
85
|
+
scripts[key] = value;
|
|
86
|
+
changed.push(key);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return changed;
|
|
90
|
+
}
|
|
91
|
+
function withNodeRequire(command, moduleId) {
|
|
92
|
+
if (command.includes(moduleId))
|
|
93
|
+
return command;
|
|
94
|
+
if (command.startsWith('NODE_OPTIONS=')) {
|
|
95
|
+
return command.replace(/NODE_OPTIONS=(['"]?)([^'"]*)\1/, (_, q, val) => {
|
|
96
|
+
const next = val.includes(moduleId) ? val : `${val} --require ${moduleId}`.trim();
|
|
97
|
+
return `NODE_OPTIONS=${q}${next}${q}`;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return `NODE_OPTIONS='--require ${moduleId}' ${command}`;
|
|
101
|
+
}
|
|
102
|
+
function ensureNestRegister(pkg) {
|
|
103
|
+
const scripts = (pkg.scripts ??= {});
|
|
104
|
+
const changed = [];
|
|
105
|
+
for (const key of ['start', 'start:dev', 'start:debug', 'start:prod']) {
|
|
106
|
+
const current = scripts[key];
|
|
107
|
+
if (!current)
|
|
108
|
+
continue;
|
|
109
|
+
const next = withNodeRequire(current, '@t0.labs/daxta/register');
|
|
110
|
+
if (next !== current) {
|
|
111
|
+
scripts[key] = next;
|
|
112
|
+
changed.push(key);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return changed;
|
|
116
|
+
}
|
|
117
|
+
function ensureDependency(pkg) {
|
|
118
|
+
const inDeps = Boolean(pkg.dependencies?.['@t0.labs/daxta'] || pkg.devDependencies?.['@t0.labs/daxta']);
|
|
119
|
+
if (inDeps)
|
|
120
|
+
return false;
|
|
121
|
+
pkg.devDependencies = { ...(pkg.devDependencies ?? {}), '@t0.labs/daxta': '^0.1.0' };
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
function writeConfig(cwd, dryRun) {
|
|
125
|
+
const configPath = path.join(cwd, 'daxta.config.ts');
|
|
126
|
+
if ((0, fs_1.existsSync)(configPath))
|
|
127
|
+
return `exists ${configPath}`;
|
|
128
|
+
const body = `import { defineConfig } from '@t0.labs/daxta';
|
|
129
|
+
|
|
130
|
+
export default defineConfig({
|
|
131
|
+
workspace: 'API',
|
|
132
|
+
baseUrl: 'http://localhost:3000',
|
|
133
|
+
controllersRoot: 'src',
|
|
134
|
+
outDir: 'daxta/out',
|
|
135
|
+
docsPath: '/docs',
|
|
136
|
+
treeLayout: 'resource-first',
|
|
137
|
+
fieldsFile: 'daxta/out/daxta.fields.json',
|
|
138
|
+
});
|
|
139
|
+
`;
|
|
140
|
+
if (!dryRun)
|
|
141
|
+
(0, fs_1.writeFileSync)(configPath, body);
|
|
142
|
+
return `wrote ${configPath}`;
|
|
143
|
+
}
|
|
144
|
+
function patchJestConfig(filePath, dryRun) {
|
|
145
|
+
const notes = [];
|
|
146
|
+
let data;
|
|
147
|
+
try {
|
|
148
|
+
data = JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return [`skip non-json jest config ${filePath}`];
|
|
152
|
+
}
|
|
153
|
+
const setup = Array.isArray(data.setupFilesAfterEnv) ? [...data.setupFilesAfterEnv] : [];
|
|
154
|
+
if (!setup.includes('@t0.labs/daxta/setup')) {
|
|
155
|
+
setup.unshift('@t0.labs/daxta/setup');
|
|
156
|
+
data.setupFilesAfterEnv = setup;
|
|
157
|
+
notes.push('setupFilesAfterEnv += @t0.labs/daxta/setup');
|
|
158
|
+
}
|
|
159
|
+
const reporters = Array.isArray(data.reporters) ? [...data.reporters] : ['default'];
|
|
160
|
+
const hasDaxtaReporter = reporters.some((entry) => {
|
|
161
|
+
if (entry === '@t0.labs/daxta/jest-reporter')
|
|
162
|
+
return true;
|
|
163
|
+
if (Array.isArray(entry) && entry[0] === '@t0.labs/daxta/jest-reporter')
|
|
164
|
+
return true;
|
|
165
|
+
return false;
|
|
166
|
+
});
|
|
167
|
+
if (!hasDaxtaReporter) {
|
|
168
|
+
reporters.push('@t0.labs/daxta/jest-reporter');
|
|
169
|
+
data.reporters = reporters;
|
|
170
|
+
notes.push('reporters += @t0.labs/daxta/jest-reporter');
|
|
171
|
+
}
|
|
172
|
+
if (!data.globalSetup) {
|
|
173
|
+
data.globalSetup = '@t0.labs/daxta/jest-global-setup';
|
|
174
|
+
notes.push('globalSetup = @t0.labs/daxta/jest-global-setup');
|
|
175
|
+
}
|
|
176
|
+
if (!data.globalTeardown) {
|
|
177
|
+
data.globalTeardown = '@t0.labs/daxta/jest-global-teardown';
|
|
178
|
+
notes.push('globalTeardown = @t0.labs/daxta/jest-global-teardown');
|
|
179
|
+
}
|
|
180
|
+
if (!dryRun && notes.length)
|
|
181
|
+
writeJson(filePath, data);
|
|
182
|
+
return notes.map((n) => `${path.relative(process.cwd(), filePath)}: ${n}`);
|
|
183
|
+
}
|
|
184
|
+
function resolveRootDirPath(cwd, jestConfigPath, value) {
|
|
185
|
+
if (!value.includes('<rootDir>'))
|
|
186
|
+
return path.isAbsolute(value) ? value : path.join(cwd, value);
|
|
187
|
+
// jest rootDir is often relative to the config file directory
|
|
188
|
+
let rootDir = cwd;
|
|
189
|
+
try {
|
|
190
|
+
const cfg = readJson(jestConfigPath);
|
|
191
|
+
if (cfg.rootDir)
|
|
192
|
+
rootDir = path.resolve(path.dirname(jestConfigPath), cfg.rootDir);
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// ignore
|
|
196
|
+
}
|
|
197
|
+
return value.replace('<rootDir>', rootDir);
|
|
198
|
+
}
|
|
199
|
+
function injectIntoTsFile(filePath, dryRun, kind) {
|
|
200
|
+
if (!(0, fs_1.existsSync)(filePath))
|
|
201
|
+
return null;
|
|
202
|
+
let text = (0, fs_1.readFileSync)(filePath, 'utf8');
|
|
203
|
+
const before = text;
|
|
204
|
+
if (kind === 'setup') {
|
|
205
|
+
if (text.includes('clearWorkerHits') && text.includes('@t0.labs/daxta'))
|
|
206
|
+
return null;
|
|
207
|
+
if (!text.includes("@t0.labs/daxta")) {
|
|
208
|
+
text = `import { clearWorkerHits } from '@t0.labs/daxta';\n${text}`;
|
|
209
|
+
}
|
|
210
|
+
if (!/clearWorkerHits\s*\(/.test(text)) {
|
|
211
|
+
text = text.replace(/(export\s+default\s+async\s+function[^{]*\{)/, '$1\n clearWorkerHits();');
|
|
212
|
+
if (!/clearWorkerHits\s*\(/.test(text)) {
|
|
213
|
+
text = text.replace(/(export\s+default\s+async\s*\(\s*\)\s*:\s*Promise<void>\s*=>\s*\{)/, '$1\n clearWorkerHits();');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
if ((text.includes('buildDaxtaSpec') || text.includes('buildOpenApi')) && text.includes('@t0.labs/daxta'))
|
|
219
|
+
return null;
|
|
220
|
+
if (!text.includes('@t0.labs/daxta')) {
|
|
221
|
+
text = `import { buildDaxtaSpec, clearPartialMarker } from '@t0.labs/daxta';\n${text}`;
|
|
222
|
+
}
|
|
223
|
+
if (!text.includes('buildDaxtaSpec(') && !text.includes('buildOpenApi(')) {
|
|
224
|
+
const hook = `
|
|
225
|
+
try {
|
|
226
|
+
const result = buildDaxtaSpec({ silent: true });
|
|
227
|
+
if (result.changed) {
|
|
228
|
+
console.log(\`DAxTA docs updated (\${result.hits} hits, \${result.operations} operations)\`);
|
|
229
|
+
}
|
|
230
|
+
clearPartialMarker();
|
|
231
|
+
} catch (error) {
|
|
232
|
+
console.error('DAxTA build failed:', error);
|
|
233
|
+
}
|
|
234
|
+
`;
|
|
235
|
+
text = text.replace(/(export\s+default\s+async\s+function[^{]*\{)/, `$1${hook}`);
|
|
236
|
+
if (!text.includes('buildDaxtaSpec({ silent: true })')) {
|
|
237
|
+
text = text.replace(/(export\s+default\s+async\s*\(\s*\)\s*:\s*Promise<void>\s*=>\s*\{)/, `$1${hook}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (text === before)
|
|
242
|
+
return null;
|
|
243
|
+
if (!dryRun)
|
|
244
|
+
(0, fs_1.writeFileSync)(filePath, text);
|
|
245
|
+
return `patched ${path.relative(process.cwd(), filePath)}`;
|
|
246
|
+
}
|
|
247
|
+
function stripManualNestMount(cwd, dryRun) {
|
|
248
|
+
const notes = [];
|
|
249
|
+
for (const rel of ['src/common/utils/start-daxta-docs.util.ts', 'src/common/utils/start-openapi-docs.util.ts']) {
|
|
250
|
+
const file = path.join(cwd, rel);
|
|
251
|
+
if (!(0, fs_1.existsSync)(file))
|
|
252
|
+
continue;
|
|
253
|
+
if (!dryRun)
|
|
254
|
+
(0, fs_1.unlinkSync)(file);
|
|
255
|
+
notes.push(`removed ${rel} (auto /docs via @t0.labs/daxta/register)`);
|
|
256
|
+
}
|
|
257
|
+
const configInit = path.join(cwd, 'src/common/utils/config-init.util.ts');
|
|
258
|
+
if ((0, fs_1.existsSync)(configInit)) {
|
|
259
|
+
let text = (0, fs_1.readFileSync)(configInit, 'utf8');
|
|
260
|
+
const before = text;
|
|
261
|
+
text = text.replace(/import\s+\{\s*startDaxtaDocs\s*\}\s+from\s+['"]\.\/start-daxta-docs\.util['"];\n?/g, '');
|
|
262
|
+
text = text.replace(/import\s+\{\s*startOpenApiDocs\s*\}\s+from\s+['"]\.\/start-openapi-docs\.util['"];\n?/g, '');
|
|
263
|
+
text = text.replace(/\n\s*startDaxtaDocs\(app\);\n?/g, '\n');
|
|
264
|
+
text = text.replace(/\n\s*startOpenApiDocs\(app\);\n?/g, '\n');
|
|
265
|
+
if (text !== before) {
|
|
266
|
+
if (!dryRun)
|
|
267
|
+
(0, fs_1.writeFileSync)(configInit, text);
|
|
268
|
+
notes.push('cleaned Nest mount from src/common/utils/config-init.util.ts');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return notes;
|
|
272
|
+
}
|
|
273
|
+
function runPackageInstall(cwd, pm, dryRun) {
|
|
274
|
+
if (dryRun)
|
|
275
|
+
return 'dry-run skip package install';
|
|
276
|
+
const args = pm === 'pnpm' ? ['add', '-D', '@t0.labs/daxta'] : pm === 'yarn' ? ['add', '-D', '@t0.labs/daxta'] : ['install', '-D', '@t0.labs/daxta'];
|
|
277
|
+
const result = (0, child_process_1.spawnSync)(pm, args, { cwd, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
278
|
+
if (result.status !== 0)
|
|
279
|
+
throw new Error(`${pm} ${args.join(' ')} failed`);
|
|
280
|
+
return `installed @t0.labs/daxta via ${pm}`;
|
|
281
|
+
}
|
|
282
|
+
function installDaxta(options = {}) {
|
|
283
|
+
const cwd = options.cwd ?? process.cwd();
|
|
284
|
+
const dryRun = Boolean(options.dryRun);
|
|
285
|
+
const pkgPath = path.join(cwd, 'package.json');
|
|
286
|
+
if (!(0, fs_1.existsSync)(pkgPath))
|
|
287
|
+
throw new Error(`No package.json in ${cwd}`);
|
|
288
|
+
const pkg = readJson(pkgPath);
|
|
289
|
+
const pm = detectPackageManager(cwd, pkg);
|
|
290
|
+
const log = [];
|
|
291
|
+
log.push(writeConfig(cwd, dryRun));
|
|
292
|
+
const depAdded = ensureDependency(pkg);
|
|
293
|
+
if (depAdded)
|
|
294
|
+
log.push('package.json: added @t0.labs/daxta to devDependencies');
|
|
295
|
+
const scriptChanges = ensureScripts(pkg);
|
|
296
|
+
if (scriptChanges.length)
|
|
297
|
+
log.push(`package.json scripts: ${scriptChanges.join(', ')}`);
|
|
298
|
+
const nestScripts = ensureNestRegister(pkg);
|
|
299
|
+
if (nestScripts.length)
|
|
300
|
+
log.push(`Nest auto /docs via register on: ${nestScripts.join(', ')}`);
|
|
301
|
+
if (!dryRun)
|
|
302
|
+
writeJson(pkgPath, pkg);
|
|
303
|
+
const outDir = path.join(cwd, 'daxta', 'out');
|
|
304
|
+
if (!dryRun)
|
|
305
|
+
(0, fs_1.mkdirSync)(outDir, { recursive: true });
|
|
306
|
+
log.push(`outDir ready: daxta/out`);
|
|
307
|
+
const jestConfigs = walk(cwd, (name) => name.startsWith('jest.') && name.endsWith('.json'));
|
|
308
|
+
for (const file of jestConfigs) {
|
|
309
|
+
log.push(...patchJestConfig(file, dryRun));
|
|
310
|
+
try {
|
|
311
|
+
const data = readJson(file);
|
|
312
|
+
for (const key of ['globalSetup', 'globalTeardown']) {
|
|
313
|
+
const value = data[key];
|
|
314
|
+
if (typeof value !== 'string' || value.includes('daxta'))
|
|
315
|
+
continue;
|
|
316
|
+
const candidate = resolveRootDirPath(cwd, file, value);
|
|
317
|
+
const note = injectIntoTsFile(candidate, dryRun, key === 'globalSetup' ? 'setup' : 'teardown');
|
|
318
|
+
if (note)
|
|
319
|
+
log.push(note);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
// ignore
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
log.push(...stripManualNestMount(cwd, dryRun));
|
|
327
|
+
if (!options.skipDep && depAdded)
|
|
328
|
+
log.push(runPackageInstall(cwd, pm, dryRun));
|
|
329
|
+
else if (!options.skipDep)
|
|
330
|
+
log.push('@t0.labs/daxta already listed (skip package manager add)');
|
|
331
|
+
console.log('DAxTA install complete:\n' + log.map((line) => ` - ${line}`).join('\n'));
|
|
332
|
+
console.log('\nNext: run your app / tests, then open http://localhost:<port>/docs');
|
|
333
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const build_spec_1 = require("../build/build-spec");
|
|
4
|
+
const call_1 = require("../call");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const export_fields_1 = require("../fields/export-fields");
|
|
7
|
+
const serve_1 = require("../serve");
|
|
8
|
+
const install_1 = require("./install");
|
|
9
|
+
function usage() {
|
|
10
|
+
console.log(`DAxTA CLI (@t0.labs/daxta)
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
daxta install [--dry-run] [--skip-dep]
|
|
14
|
+
daxta init (alias of install)
|
|
15
|
+
daxta build
|
|
16
|
+
daxta serve [--port <n>]
|
|
17
|
+
daxta fields [METHOD] [PATH] [--out <file>]
|
|
18
|
+
daxta call [METHOD] [PATH] [--fields <file>] [--header k:v ...]
|
|
19
|
+
daxta call --file <values.json> [--header k:v ...]
|
|
20
|
+
`);
|
|
21
|
+
}
|
|
22
|
+
function parseArgs(argv) {
|
|
23
|
+
const args = argv.slice(2);
|
|
24
|
+
const command = args[0];
|
|
25
|
+
const positional = [];
|
|
26
|
+
const flags = {};
|
|
27
|
+
const headers = {};
|
|
28
|
+
for (let i = 1; i < args.length; i += 1) {
|
|
29
|
+
const token = args[i];
|
|
30
|
+
if (token === '--port' || token === '--out' || token === '--fields' || token === '--file') {
|
|
31
|
+
flags[token.slice(2)] = args[++i];
|
|
32
|
+
}
|
|
33
|
+
else if (token === '--header') {
|
|
34
|
+
const raw = args[++i] ?? '';
|
|
35
|
+
const idx = raw.indexOf(':');
|
|
36
|
+
if (idx === -1)
|
|
37
|
+
throw new Error(`Invalid --header ${raw}; expected name:value`);
|
|
38
|
+
headers[raw.slice(0, idx).trim()] = raw.slice(idx + 1).trim();
|
|
39
|
+
}
|
|
40
|
+
else if (token.startsWith('--')) {
|
|
41
|
+
flags[token.slice(2)] = true;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
positional.push(token);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return { command, positional, flags, headers };
|
|
48
|
+
}
|
|
49
|
+
async function main() {
|
|
50
|
+
(0, config_1.resetConfig)();
|
|
51
|
+
(0, config_1.getConfig)(true);
|
|
52
|
+
const { command, positional, flags, headers } = parseArgs(process.argv);
|
|
53
|
+
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
54
|
+
usage();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (command === 'install' || command === 'init') {
|
|
58
|
+
(0, install_1.installDaxta)({
|
|
59
|
+
dryRun: Boolean(flags['dry-run']),
|
|
60
|
+
skipDep: Boolean(flags['skip-dep']),
|
|
61
|
+
});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (command === 'build') {
|
|
65
|
+
(0, build_spec_1.buildDaxtaSpec)({ requireHits: true });
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (command === 'serve') {
|
|
69
|
+
const port = flags.port ? Number(flags.port) : undefined;
|
|
70
|
+
(0, serve_1.startDaxtaDocsServer)({ port });
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (command === 'fields') {
|
|
74
|
+
const method = positional[0]?.toLowerCase();
|
|
75
|
+
const pathTemplate = positional[1];
|
|
76
|
+
const out = typeof flags.out === 'string' ? flags.out : undefined;
|
|
77
|
+
const target = (0, export_fields_1.writeFieldsFile)(method || pathTemplate ? { method, path: pathTemplate } : undefined, out);
|
|
78
|
+
console.log(`Wrote ${target}`);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (command === 'call') {
|
|
82
|
+
if (typeof flags.file === 'string') {
|
|
83
|
+
await (0, call_1.runFileCall)({ valuesFile: flags.file, headers });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const method = positional[0]?.toLowerCase();
|
|
87
|
+
const pathTemplate = positional[1];
|
|
88
|
+
await (0, call_1.runInteractiveCall)({
|
|
89
|
+
fieldsFile: typeof flags.fields === 'string' ? flags.fields : undefined,
|
|
90
|
+
method,
|
|
91
|
+
path: pathTemplate,
|
|
92
|
+
headers,
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
usage();
|
|
97
|
+
process.exitCode = 1;
|
|
98
|
+
}
|
|
99
|
+
main().catch((error) => {
|
|
100
|
+
console.error(error instanceof Error ? error.message : error);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
});
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type TreeLayout = 'resource-first' | 'url-order';
|
|
2
|
+
export type SpecInfo = {
|
|
3
|
+
title?: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
};
|
|
7
|
+
export type DaxtaConfig = {
|
|
8
|
+
workspace?: string;
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
controllersRoot?: string;
|
|
11
|
+
outDir?: string;
|
|
12
|
+
treeLayout?: TreeLayout;
|
|
13
|
+
treePathOverrides?: Record<string, string[]>;
|
|
14
|
+
port?: number;
|
|
15
|
+
fieldsFile?: string;
|
|
16
|
+
docsPath?: string;
|
|
17
|
+
templatize?: (pathname: string, test?: string) => string | null | undefined;
|
|
18
|
+
operationTag?: (pathTemplate: string, method: string) => string | undefined;
|
|
19
|
+
operationTitle?: (method: string, pathTemplate: string) => string | undefined;
|
|
20
|
+
securitySchemeId?: (headerName: string) => string | undefined;
|
|
21
|
+
specInfo?: () => SpecInfo | undefined;
|
|
22
|
+
operationOrder?: (opKey: string) => number | undefined;
|
|
23
|
+
includeHit?: (method: string, pathTemplate: string, test?: string) => boolean;
|
|
24
|
+
treePathSegments?: (pathTemplate: string) => string[] | undefined;
|
|
25
|
+
};
|
|
26
|
+
export type ResolvedDaxtaConfig = Required<Pick<DaxtaConfig, 'workspace' | 'baseUrl' | 'controllersRoot' | 'outDir' | 'treeLayout' | 'treePathOverrides' | 'port' | 'fieldsFile' | 'docsPath'>> & DaxtaConfig;
|
|
27
|
+
export declare function defineConfig(config: DaxtaConfig): DaxtaConfig;
|
|
28
|
+
export declare function resolveConfig(cwd?: string, overrides?: DaxtaConfig): ResolvedDaxtaConfig;
|
|
29
|
+
export declare function getConfig(forceReload?: boolean): ResolvedDaxtaConfig;
|
|
30
|
+
export declare function setConfig(config: ResolvedDaxtaConfig): void;
|
|
31
|
+
export declare function resetConfig(): void;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.defineConfig = defineConfig;
|
|
37
|
+
exports.resolveConfig = resolveConfig;
|
|
38
|
+
exports.getConfig = getConfig;
|
|
39
|
+
exports.setConfig = setConfig;
|
|
40
|
+
exports.resetConfig = resetConfig;
|
|
41
|
+
const fs_1 = require("fs");
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const DEFAULTS = {
|
|
44
|
+
workspace: 'API',
|
|
45
|
+
baseUrl: 'http://localhost:3000',
|
|
46
|
+
controllersRoot: 'src',
|
|
47
|
+
outDir: 'daxta/out',
|
|
48
|
+
treeLayout: 'resource-first',
|
|
49
|
+
treePathOverrides: {},
|
|
50
|
+
port: 5199,
|
|
51
|
+
fieldsFile: 'daxta.fields.json',
|
|
52
|
+
docsPath: '/docs',
|
|
53
|
+
};
|
|
54
|
+
let cached = null;
|
|
55
|
+
function defineConfig(config) {
|
|
56
|
+
return config;
|
|
57
|
+
}
|
|
58
|
+
function loadConfigFile(cwd) {
|
|
59
|
+
const candidates = ['daxta.config.ts', 'daxta.config.js', 'daxta.config.mjs', 'daxta.config.cjs'];
|
|
60
|
+
for (const name of candidates) {
|
|
61
|
+
const full = path.join(cwd, name);
|
|
62
|
+
if (!(0, fs_1.existsSync)(full))
|
|
63
|
+
continue;
|
|
64
|
+
try {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
66
|
+
const { createJiti } = require('jiti');
|
|
67
|
+
const jiti = createJiti(__filename);
|
|
68
|
+
const mod = jiti(full);
|
|
69
|
+
return (mod.default ?? mod);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw new Error(`Failed to load ${name}: ${error instanceof Error ? error.message : error}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
77
|
+
function resolveConfig(cwd = process.cwd(), overrides) {
|
|
78
|
+
const file = loadConfigFile(cwd);
|
|
79
|
+
const merged = {
|
|
80
|
+
...DEFAULTS,
|
|
81
|
+
...file,
|
|
82
|
+
...overrides,
|
|
83
|
+
treePathOverrides: {
|
|
84
|
+
...DEFAULTS.treePathOverrides,
|
|
85
|
+
...(file.treePathOverrides ?? {}),
|
|
86
|
+
...(overrides?.treePathOverrides ?? {}),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
merged.controllersRoot = path.isAbsolute(merged.controllersRoot)
|
|
90
|
+
? merged.controllersRoot
|
|
91
|
+
: path.join(cwd, merged.controllersRoot);
|
|
92
|
+
merged.outDir = path.isAbsolute(merged.outDir) ? merged.outDir : path.join(cwd, merged.outDir);
|
|
93
|
+
merged.fieldsFile = path.isAbsolute(merged.fieldsFile) ? merged.fieldsFile : path.join(cwd, merged.fieldsFile);
|
|
94
|
+
return merged;
|
|
95
|
+
}
|
|
96
|
+
function getConfig(forceReload = false) {
|
|
97
|
+
if (!cached || forceReload)
|
|
98
|
+
cached = resolveConfig();
|
|
99
|
+
return cached;
|
|
100
|
+
}
|
|
101
|
+
function setConfig(config) {
|
|
102
|
+
cached = config;
|
|
103
|
+
}
|
|
104
|
+
function resetConfig() {
|
|
105
|
+
cached = null;
|
|
106
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export type FieldLocation = 'path' | 'query' | 'header' | 'body';
|
|
3
|
+
/** Returns required flag from DTO metadata, or undefined when unknown (no DTO / no validators). */
|
|
4
|
+
export declare function dtoRequired(method: string, pathTemplate: string, location: FieldLocation, fieldName: string): boolean | undefined;
|