@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,12 @@
|
|
|
1
|
+
import { type BuildResult } from './build-spec';
|
|
2
|
+
export declare function rebuildFromDisk(options?: {
|
|
3
|
+
silent?: boolean;
|
|
4
|
+
force?: boolean;
|
|
5
|
+
html?: boolean;
|
|
6
|
+
}): BuildResult | null;
|
|
7
|
+
export declare function flushAndRebuild(options?: {
|
|
8
|
+
silent?: boolean;
|
|
9
|
+
force?: boolean;
|
|
10
|
+
}): BuildResult | null;
|
|
11
|
+
export declare function touchPartialMarker(result: BuildResult): void;
|
|
12
|
+
export declare function clearPartialMarker(): void;
|
|
@@ -0,0 +1,121 @@
|
|
|
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.rebuildFromDisk = rebuildFromDisk;
|
|
37
|
+
exports.flushAndRebuild = flushAndRebuild;
|
|
38
|
+
exports.touchPartialMarker = touchPartialMarker;
|
|
39
|
+
exports.clearPartialMarker = clearPartialMarker;
|
|
40
|
+
const fs_1 = require("fs");
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const config_1 = require("../config");
|
|
43
|
+
const recorder_1 = require("../recorder");
|
|
44
|
+
const build_spec_1 = require("./build-spec");
|
|
45
|
+
function getBuildLockPath() {
|
|
46
|
+
return path.join((0, config_1.getConfig)().outDir, '.build.lock');
|
|
47
|
+
}
|
|
48
|
+
function tryLock() {
|
|
49
|
+
try {
|
|
50
|
+
(0, fs_1.mkdirSync)(path.dirname(getBuildLockPath()), { recursive: true });
|
|
51
|
+
return (0, fs_1.openSync)(getBuildLockPath(), 'wx');
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function unlock(fd) {
|
|
58
|
+
try {
|
|
59
|
+
(0, fs_1.closeSync)(fd);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// ignore
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
(0, fs_1.unlinkSync)(getBuildLockPath());
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// ignore
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function withLock(options, run) {
|
|
72
|
+
let fd = tryLock();
|
|
73
|
+
if (fd == null && options.force) {
|
|
74
|
+
const deadline = Date.now() + 8000;
|
|
75
|
+
while (fd == null && Date.now() < deadline) {
|
|
76
|
+
const pauseUntil = Date.now() + 25;
|
|
77
|
+
while (Date.now() < pauseUntil) {
|
|
78
|
+
// brief spin
|
|
79
|
+
}
|
|
80
|
+
fd = tryLock();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (fd == null)
|
|
84
|
+
return null;
|
|
85
|
+
try {
|
|
86
|
+
return run();
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
unlock(fd);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function rebuildFromDisk(options = {}) {
|
|
93
|
+
return withLock({ force: options.force }, () => {
|
|
94
|
+
const result = (0, build_spec_1.buildDaxtaSpec)({ silent: options.silent ?? true, html: options.html });
|
|
95
|
+
if (!options.silent && result.changed) {
|
|
96
|
+
console.log(`DAxTA (partial) ${result.hits} hits, ${result.operations} ops — ${result.updated} updated, ${result.unchanged} unchanged`);
|
|
97
|
+
}
|
|
98
|
+
if (result.changed)
|
|
99
|
+
touchPartialMarker(result);
|
|
100
|
+
return result;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function flushAndRebuild(options = {}) {
|
|
104
|
+
(0, recorder_1.flush)();
|
|
105
|
+
return rebuildFromDisk(options);
|
|
106
|
+
}
|
|
107
|
+
function touchPartialMarker(result) {
|
|
108
|
+
const marker = path.join((0, config_1.getConfig)().outDir, 'partial.json');
|
|
109
|
+
(0, fs_1.writeFileSync)(marker, `${JSON.stringify({ at: new Date().toISOString(), hits: result.hits, operations: result.operations }, null, 2)}\n`);
|
|
110
|
+
}
|
|
111
|
+
function clearPartialMarker() {
|
|
112
|
+
const marker = path.join((0, config_1.getConfig)().outDir, 'partial.json');
|
|
113
|
+
if (!(0, fs_1.existsSync)(marker))
|
|
114
|
+
return;
|
|
115
|
+
try {
|
|
116
|
+
(0, fs_1.unlinkSync)(marker);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// ignore
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type FieldsFile } from '../fields/export-fields';
|
|
2
|
+
export type CallValues = {
|
|
3
|
+
method: string;
|
|
4
|
+
path: string;
|
|
5
|
+
pathParams?: Record<string, string>;
|
|
6
|
+
query?: Record<string, string>;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
body?: unknown;
|
|
9
|
+
};
|
|
10
|
+
export declare function promptForOperation(fieldsFile: FieldsFile, options?: {
|
|
11
|
+
method?: string;
|
|
12
|
+
path?: string;
|
|
13
|
+
}): Promise<CallValues>;
|
|
14
|
+
export declare function executeCall(values: CallValues, extraHeaders?: Record<string, string>): Promise<void>;
|
|
15
|
+
export declare function runInteractiveCall(options?: {
|
|
16
|
+
fieldsFile?: string;
|
|
17
|
+
method?: string;
|
|
18
|
+
path?: string;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
export declare function runFileCall(options: {
|
|
22
|
+
valuesFile: string;
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,204 @@
|
|
|
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.promptForOperation = promptForOperation;
|
|
37
|
+
exports.executeCall = executeCall;
|
|
38
|
+
exports.runInteractiveCall = runInteractiveCall;
|
|
39
|
+
exports.runFileCall = runFileCall;
|
|
40
|
+
const readline = __importStar(require("readline"));
|
|
41
|
+
const config_1 = require("../config");
|
|
42
|
+
const export_fields_1 = require("../fields/export-fields");
|
|
43
|
+
function ask(rl, prompt) {
|
|
44
|
+
return new Promise((resolve) => rl.question(prompt, resolve));
|
|
45
|
+
}
|
|
46
|
+
function setNested(target, dotted, raw, type) {
|
|
47
|
+
const parts = dotted.replace(/\[\]/g, '.0').split('.').filter(Boolean);
|
|
48
|
+
let cursor = target;
|
|
49
|
+
for (let i = 0; i < parts.length - 1; i += 1) {
|
|
50
|
+
const key = parts[i];
|
|
51
|
+
const next = parts[i + 1];
|
|
52
|
+
const asIndex = /^\d+$/.test(next);
|
|
53
|
+
const container = cursor;
|
|
54
|
+
if (container[key] == null)
|
|
55
|
+
container[key] = asIndex ? [] : {};
|
|
56
|
+
cursor = container[key];
|
|
57
|
+
}
|
|
58
|
+
const leaf = parts[parts.length - 1];
|
|
59
|
+
let value = raw;
|
|
60
|
+
if (type.includes('integer') || type === 'number') {
|
|
61
|
+
const n = Number(raw);
|
|
62
|
+
value = Number.isNaN(n) ? raw : n;
|
|
63
|
+
}
|
|
64
|
+
else if (type === 'boolean') {
|
|
65
|
+
value = raw.toLowerCase() === 'true';
|
|
66
|
+
}
|
|
67
|
+
else if (raw === 'null') {
|
|
68
|
+
value = null;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
try {
|
|
72
|
+
if ((raw.startsWith('{') && raw.endsWith('}')) || (raw.startsWith('[') && raw.endsWith(']')))
|
|
73
|
+
value = JSON.parse(raw);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// keep string
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (Array.isArray(cursor) && /^\d+$/.test(leaf))
|
|
80
|
+
cursor[Number(leaf)] = value;
|
|
81
|
+
else
|
|
82
|
+
cursor[leaf] = value;
|
|
83
|
+
}
|
|
84
|
+
async function promptForOperation(fieldsFile, options = {}) {
|
|
85
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
86
|
+
try {
|
|
87
|
+
let ops = fieldsFile.operations;
|
|
88
|
+
if (options.method)
|
|
89
|
+
ops = ops.filter((op) => op.method === options.method.toLowerCase());
|
|
90
|
+
if (options.path)
|
|
91
|
+
ops = ops.filter((op) => op.path === options.path);
|
|
92
|
+
if (!ops.length)
|
|
93
|
+
throw new Error('No matching operations in fields file.');
|
|
94
|
+
let selected = ops[0];
|
|
95
|
+
if (ops.length > 1 && !options.method && !options.path) {
|
|
96
|
+
console.log('Operations:');
|
|
97
|
+
ops.forEach((op, i) => console.log(` [${i + 1}] ${op.method.toUpperCase()} ${op.path}`));
|
|
98
|
+
const pick = await ask(rl, 'Select operation number: ');
|
|
99
|
+
const index = Number(pick) - 1;
|
|
100
|
+
if (!ops[index])
|
|
101
|
+
throw new Error('Invalid selection');
|
|
102
|
+
selected = ops[index];
|
|
103
|
+
}
|
|
104
|
+
else if (ops.length > 1) {
|
|
105
|
+
console.log('Operations:');
|
|
106
|
+
ops.forEach((op, i) => console.log(` [${i + 1}] ${op.method.toUpperCase()} ${op.path}`));
|
|
107
|
+
const pick = await ask(rl, 'Select operation number: ');
|
|
108
|
+
const index = Number(pick) - 1;
|
|
109
|
+
if (!ops[index])
|
|
110
|
+
throw new Error('Invalid selection');
|
|
111
|
+
selected = ops[index];
|
|
112
|
+
}
|
|
113
|
+
console.log(`\n${selected.method.toUpperCase()} ${selected.path}`);
|
|
114
|
+
const pathParams = {};
|
|
115
|
+
const query = {};
|
|
116
|
+
const headers = {};
|
|
117
|
+
const body = {};
|
|
118
|
+
// Prefer leaf fields for body (skip pure object containers when children exist)
|
|
119
|
+
const bodyLeaves = selected.fields.filter((f) => f.in === 'body');
|
|
120
|
+
const hasChild = (name) => bodyLeaves.some((f) => f.name.startsWith(`${name}.`) || f.name.startsWith(`${name}[]`));
|
|
121
|
+
const effective = [
|
|
122
|
+
...selected.fields.filter((f) => f.in !== 'body'),
|
|
123
|
+
...bodyLeaves.filter((f) => !hasChild(f.name)),
|
|
124
|
+
];
|
|
125
|
+
for (const field of effective) {
|
|
126
|
+
const reqLabel = field.required === true ? 'required' : field.required === false ? 'optional' : 'unknown';
|
|
127
|
+
const hint = field.required === false || field.required === undefined ? ' (Enter to skip)' : '';
|
|
128
|
+
const answer = (await ask(rl, `${field.in}.${field.name} [${field.type}, ${reqLabel}]${hint}: `)).trim();
|
|
129
|
+
if (!answer) {
|
|
130
|
+
if (field.required === true)
|
|
131
|
+
throw new Error(`Missing required field: ${field.in}.${field.name}`);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (field.in === 'path')
|
|
135
|
+
pathParams[field.name] = answer;
|
|
136
|
+
else if (field.in === 'query')
|
|
137
|
+
query[field.name] = answer;
|
|
138
|
+
else if (field.in === 'header')
|
|
139
|
+
headers[field.name] = answer;
|
|
140
|
+
else
|
|
141
|
+
setNested(body, field.name, answer, field.type);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
method: selected.method,
|
|
145
|
+
path: selected.path,
|
|
146
|
+
pathParams: Object.keys(pathParams).length ? pathParams : undefined,
|
|
147
|
+
query: Object.keys(query).length ? query : undefined,
|
|
148
|
+
headers: Object.keys(headers).length ? headers : undefined,
|
|
149
|
+
body: Object.keys(body).length ? body : undefined,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
rl.close();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function applyPathParams(template, params) {
|
|
157
|
+
return template.replace(/\{([^}]+)\}/g, (_, name) => {
|
|
158
|
+
const value = params?.[name];
|
|
159
|
+
if (value == null)
|
|
160
|
+
throw new Error(`Missing path param: ${name}`);
|
|
161
|
+
return encodeURIComponent(value);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
async function executeCall(values, extraHeaders = {}) {
|
|
165
|
+
const baseUrl = (0, config_1.getConfig)().baseUrl.replace(/\/$/, '');
|
|
166
|
+
const url = new URL(applyPathParams(values.path, values.pathParams), `${baseUrl}/`);
|
|
167
|
+
for (const [key, value] of Object.entries(values.query ?? {}))
|
|
168
|
+
url.searchParams.set(key, value);
|
|
169
|
+
const headers = {
|
|
170
|
+
accept: 'application/json',
|
|
171
|
+
...extraHeaders,
|
|
172
|
+
...(values.headers ?? {}),
|
|
173
|
+
};
|
|
174
|
+
const hasBody = values.body !== undefined && !['get', 'head'].includes(values.method);
|
|
175
|
+
if (hasBody && !headers['content-type'])
|
|
176
|
+
headers['content-type'] = 'application/json';
|
|
177
|
+
const response = await fetch(url, {
|
|
178
|
+
method: values.method.toUpperCase(),
|
|
179
|
+
headers,
|
|
180
|
+
body: hasBody ? JSON.stringify(values.body) : undefined,
|
|
181
|
+
});
|
|
182
|
+
const text = await response.text();
|
|
183
|
+
let pretty = text;
|
|
184
|
+
try {
|
|
185
|
+
pretty = JSON.stringify(JSON.parse(text), null, 2);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
// keep raw
|
|
189
|
+
}
|
|
190
|
+
console.log(`\nHTTP ${response.status}`);
|
|
191
|
+
console.log(pretty || '(empty body)');
|
|
192
|
+
}
|
|
193
|
+
async function runInteractiveCall(options = {}) {
|
|
194
|
+
const file = (0, export_fields_1.readFieldsFile)(options.fieldsFile);
|
|
195
|
+
const values = await promptForOperation(file, { method: options.method, path: options.path });
|
|
196
|
+
await executeCall(values, options.headers);
|
|
197
|
+
}
|
|
198
|
+
async function runFileCall(options) {
|
|
199
|
+
const { readFileSync } = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
200
|
+
const values = JSON.parse(readFileSync(options.valuesFile, 'utf8'));
|
|
201
|
+
if (!values.method || !values.path)
|
|
202
|
+
throw new Error('values file must include method and path');
|
|
203
|
+
await executeCall(values, options.headers);
|
|
204
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type TreeLayout } from '../config';
|
|
2
|
+
export type { TreeLayout };
|
|
3
|
+
export type FieldDoc = {
|
|
4
|
+
name: string;
|
|
5
|
+
in: 'path' | 'query' | 'header' | 'body';
|
|
6
|
+
type: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type OperationDoc = {
|
|
10
|
+
title: string;
|
|
11
|
+
fields: FieldDoc[];
|
|
12
|
+
};
|
|
13
|
+
export declare const STATUS_TEXT: Record<string, string>;
|
|
14
|
+
export declare function declaredMethods(test?: string): string[] | null;
|
|
15
|
+
export declare function pathSegments(pathTemplate: string): string[];
|
|
16
|
+
export declare function treePathSegments(pathTemplate: string): string[];
|
|
17
|
+
export declare function viewerTreeConfig(): {
|
|
18
|
+
workspace: string;
|
|
19
|
+
baseUrl: string;
|
|
20
|
+
docsPath: string;
|
|
21
|
+
treeLayout: "resource-first" | "url-order";
|
|
22
|
+
treePathOverrides: Record<string, string[]>;
|
|
23
|
+
};
|
|
24
|
+
export declare function operationTag(pathTemplate: string, method: string): string;
|
|
25
|
+
export declare function defaultTitle(method: string, pathTemplate: string): string;
|
|
26
|
+
export declare function caseGroup(test?: string): string;
|
|
27
|
+
export declare function caseName(test?: string): string;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STATUS_TEXT = void 0;
|
|
4
|
+
exports.declaredMethods = declaredMethods;
|
|
5
|
+
exports.pathSegments = pathSegments;
|
|
6
|
+
exports.treePathSegments = treePathSegments;
|
|
7
|
+
exports.viewerTreeConfig = viewerTreeConfig;
|
|
8
|
+
exports.operationTag = operationTag;
|
|
9
|
+
exports.defaultTitle = defaultTitle;
|
|
10
|
+
exports.caseGroup = caseGroup;
|
|
11
|
+
exports.caseName = caseName;
|
|
12
|
+
const config_1 = require("../config");
|
|
13
|
+
exports.STATUS_TEXT = {
|
|
14
|
+
'200': 'OK',
|
|
15
|
+
'201': 'Created',
|
|
16
|
+
'204': 'No Content',
|
|
17
|
+
'400': 'Bad Request',
|
|
18
|
+
'401': 'Unauthorized',
|
|
19
|
+
'403': 'Forbidden',
|
|
20
|
+
'404': 'Not Found',
|
|
21
|
+
'409': 'Conflict',
|
|
22
|
+
'422': 'Unprocessable Entity',
|
|
23
|
+
'500': 'Internal Server Error',
|
|
24
|
+
};
|
|
25
|
+
const METHOD_ALIASES = {
|
|
26
|
+
update: ['patch', 'put'],
|
|
27
|
+
upsert: ['put', 'post', 'patch'],
|
|
28
|
+
};
|
|
29
|
+
function declaredMethods(test) {
|
|
30
|
+
if (!test)
|
|
31
|
+
return null;
|
|
32
|
+
const declared = test.match(/\[(GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]/i);
|
|
33
|
+
if (!declared)
|
|
34
|
+
return null;
|
|
35
|
+
const method = declared[1].toLowerCase();
|
|
36
|
+
return METHOD_ALIASES[method] ?? [method];
|
|
37
|
+
}
|
|
38
|
+
function pathSegments(pathTemplate) {
|
|
39
|
+
return pathTemplate.split('/').filter((part) => part && !part.startsWith('{'));
|
|
40
|
+
}
|
|
41
|
+
function treePathSegments(pathTemplate) {
|
|
42
|
+
const config = (0, config_1.getConfig)();
|
|
43
|
+
const custom = config.treePathSegments?.(pathTemplate);
|
|
44
|
+
if (custom)
|
|
45
|
+
return custom;
|
|
46
|
+
const exact = config.treePathOverrides[pathTemplate];
|
|
47
|
+
if (exact?.length)
|
|
48
|
+
return exact;
|
|
49
|
+
const parts = pathTemplate.split('/').filter(Boolean);
|
|
50
|
+
if (parts.length >= 3 && /^v\d+$/i.test(parts[0]) && config.treeLayout === 'resource-first') {
|
|
51
|
+
return [parts[0], parts[2], parts[1], ...parts.slice(3)];
|
|
52
|
+
}
|
|
53
|
+
return parts;
|
|
54
|
+
}
|
|
55
|
+
function viewerTreeConfig() {
|
|
56
|
+
const config = (0, config_1.getConfig)();
|
|
57
|
+
return {
|
|
58
|
+
workspace: config.workspace,
|
|
59
|
+
baseUrl: config.baseUrl,
|
|
60
|
+
docsPath: config.docsPath,
|
|
61
|
+
treeLayout: config.treeLayout,
|
|
62
|
+
treePathOverrides: config.treePathOverrides,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function titleCase(value) {
|
|
66
|
+
return value
|
|
67
|
+
.split('-')
|
|
68
|
+
.filter(Boolean)
|
|
69
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
70
|
+
.join(' ');
|
|
71
|
+
}
|
|
72
|
+
function operationTag(pathTemplate, method) {
|
|
73
|
+
const custom = (0, config_1.getConfig)().operationTag?.(pathTemplate, method);
|
|
74
|
+
if (custom)
|
|
75
|
+
return custom;
|
|
76
|
+
const parts = pathSegments(pathTemplate).filter((part) => !/^v\d+$/i.test(part));
|
|
77
|
+
if (!parts.length)
|
|
78
|
+
return 'API';
|
|
79
|
+
if (parts.length === 1)
|
|
80
|
+
return titleCase(parts[0]);
|
|
81
|
+
return `${titleCase(parts[0])} / ${titleCase(parts[1])}`;
|
|
82
|
+
}
|
|
83
|
+
function defaultTitle(method, pathTemplate) {
|
|
84
|
+
const custom = (0, config_1.getConfig)().operationTitle?.(method, pathTemplate);
|
|
85
|
+
if (custom)
|
|
86
|
+
return custom;
|
|
87
|
+
return pathTemplate;
|
|
88
|
+
}
|
|
89
|
+
function caseGroup(test) {
|
|
90
|
+
if (!test)
|
|
91
|
+
return 'Other';
|
|
92
|
+
if (/SEMANTIC ERROR CASES\s*-\s*AUTH/i.test(test))
|
|
93
|
+
return 'Auth';
|
|
94
|
+
if (/POSITIVE CASES/i.test(test))
|
|
95
|
+
return 'Success';
|
|
96
|
+
if (/SEMANTIC ERROR CASES/i.test(test))
|
|
97
|
+
return 'Business errors';
|
|
98
|
+
if (/INVALID CASES/i.test(test))
|
|
99
|
+
return 'Invalid input';
|
|
100
|
+
if (/OMITTED/i.test(test))
|
|
101
|
+
return 'Missing fields';
|
|
102
|
+
return 'Other';
|
|
103
|
+
}
|
|
104
|
+
function caseName(test) {
|
|
105
|
+
if (!test)
|
|
106
|
+
return 'example';
|
|
107
|
+
return (test
|
|
108
|
+
.replace(/^.*?\[(?:GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]\s*(?:\(integration\))?\s*/i, '')
|
|
109
|
+
.replace(/^(POSITIVE CASES|SEMANTIC ERROR CASES(?:\s*-\s*AUTH)?|INVALID CASES|OMITTED(?: FIELD)? CASES)\s+/i, '')
|
|
110
|
+
.trim() || test);
|
|
111
|
+
}
|