@rpcbase/api 0.150.0 → 0.151.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/dist/index.js CHANGED
@@ -27509,10 +27509,6 @@ var getErrorFields = (issues) => {
27509
27509
  }
27510
27510
  return Object.keys(fields).length > 0 ? fields : void 0;
27511
27511
  };
27512
- var getApiRoutePath = (route) => {
27513
- if (typeof route === "string") return route;
27514
- return "ROUTE" in route ? route.ROUTE : route.Route;
27515
- };
27516
27512
  var parseApiRequest = (schema, input) => {
27517
27513
  const result = schema.safeParse(input);
27518
27514
  if (result.success) return result.data;
@@ -27543,13 +27539,12 @@ var withApiRequestIdExposed = (options) => {
27543
27539
  };
27544
27540
  var initApi = async ({ app, routes, cors: corsOptions, errors }) => {
27545
27541
  await (await loadInitApiClient())({ app });
27546
- const registerHandler = (method, route, handler) => {
27547
- const path = getApiRoutePath(route);
27548
- assert(path.startsWith("/api"), "API routes must start with /api");
27542
+ const registerHandler = (method, path, requestSchema, handler) => {
27543
+ assert(typeof path === "string" && path.startsWith("/api"), "API routes must be explicit string paths starting with /api");
27549
27544
  app[method](path, async (req, res, next) => {
27550
27545
  const requestPayload = method === "get" ? req.query : req.body ?? {};
27551
27546
  try {
27552
- const result = await handler(typeof route === "string" ? requestPayload : parseApiRequest(route.requestSchema, requestPayload), {
27547
+ const result = await handler(requestSchema ? parseApiRequest(requestSchema, requestPayload) : requestPayload, {
27553
27548
  req,
27554
27549
  res
27555
27550
  });
@@ -27561,8 +27556,12 @@ var initApi = async ({ app, routes, cors: corsOptions, errors }) => {
27561
27556
  }
27562
27557
  });
27563
27558
  };
27564
- const createApiMethod = (method) => ((route, handler) => {
27565
- registerHandler(method, route, handler);
27559
+ const createApiMethod = (method) => ((path, requestSchemaOrHandler, validatedHandler) => {
27560
+ if (validatedHandler === void 0) {
27561
+ registerHandler(method, path, void 0, requestSchemaOrHandler);
27562
+ return;
27563
+ }
27564
+ registerHandler(method, path, requestSchemaOrHandler, validatedHandler);
27566
27565
  });
27567
27566
  const api = {
27568
27567
  use: (path, middleware) => {