@docyrus/tanstack-db-generator
Version:
Code generator utilities for TanStack Query / Database integration with Docyrus API
47 lines (46 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractNonDataSourceEndpoints = extractNonDataSourceEndpoints;
const ENDPOINT_GROUPS = [
{ name: 'users', pattern: /^\/v1\/users/ },
{ name: 'notifications', pattern: /^\/v1\/notifications/ },
{ name: 'enums', pattern: /^\/v1\/enums/ }
];
function extractNonDataSourceEndpoints(spec) {
const groups = new Map();
// Initialize groups
for (const group of ENDPOINT_GROUPS) {
groups.set(group.name, {
name: group.name,
basePath: `/v1/${group.name}`,
endpoints: []
});
}
// Process all paths
for (const [path, pathItem] of Object.entries(spec.paths)) {
// Skip dataSource paths
if (path.includes('/data-sources/'))
continue;
// Check which group this path belongs to
const group = ENDPOINT_GROUPS.find(g => g.pattern.test(path));
if (!group)
continue;
const endpointGroup = groups.get(group.name);
// Process each method
const methods = ['get', 'post', 'patch', 'put', 'delete'];
for (const method of methods) {
const operation = pathItem[method];
if (!operation)
continue;
endpointGroup.endpoints.push({
path,
method,
operationId: operation.operationId || `${method}_${path.replace(/[^a-zA-Z0-9]/g, '_')}`,
tag: operation.tags?.[0] || group.name,
operation
});
}
}
// Filter out empty groups
return Array.from(groups.values()).filter(g => g.endpoints.length > 0);
}