first commit

This commit is contained in:
2026-06-09 18:35:55 -03:00
commit 3581e221d0
448 changed files with 519709 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import { ENDPOINTS } from "./endpoints.js";
function toCamelCase(name) {
return name.charAt(0).toLowerCase() + name.slice(1);
}
function pickMethod(endpoint) {
if (endpoint.httpMethods.includes("POST"))
return "POST";
if (endpoint.httpMethods.includes("GET"))
return "GET";
if (endpoint.httpMethods.includes("PUT"))
return "PUT";
return endpoint.httpMethods[0];
}
export function createNamespaceService(http, namespace) {
const endpoints = ENDPOINTS.filter((e) => e.namespace === namespace);
const handler = async (operation, body, query) => {
const endpoint = endpoints.find((e) => e.operation.toLowerCase() === operation.toLowerCase());
if (!endpoint) {
throw new Error(`Unknown ${namespace} operation: ${operation}`);
}
return http.request(endpoint.path, {
method: pickMethod(endpoint),
body,
query,
});
};
const service = handler;
for (const endpoint of endpoints) {
const methodName = toCamelCase(endpoint.operation);
service[methodName] = (body, query) => handler(endpoint.operation, body, query);
}
return service;
}
//# sourceMappingURL=service.js.map