hono-utils 0.3.3 → 0.3.4

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.d.cts CHANGED
@@ -498,8 +498,7 @@ interface CreateTypedClientOptions {
498
498
  url: string;
499
499
  headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
500
500
  fetch?: typeof fetch;
501
- callbacks?: TypedClientCallbacks;
502
501
  }
503
- declare const createTypedClient: <TApp extends Hono<any, any, any>>(options: CreateTypedClientOptions) => <TSuccessData>(fn: (c: ReturnType<typeof hc<TApp>>) => Promise<ClientResponse<TSuccessData>>) => Promise<TSuccessData>;
502
+ declare const createTypedClient: <TApp extends Hono<any, any, any>>() => (options: CreateTypedClientOptions) => <TSuccessData>(fn: (c: ReturnType<typeof hc<TApp>>) => Promise<ClientResponse<TSuccessData>>, callbacks?: TypedClientCallbacks) => Promise<TSuccessData>;
504
503
 
505
504
  export { type ContextFn, type CreateTypedClientOptions, type HonoClientInfoVariables, type HonoI18nVariables, type HonoIsBotVariables, type HonoLanguageVariables, type HonoLoggerVariables, type HonoResponseVariables, type MessageHandlers, pbkdf2 as PBKDF2, QueueHandler, sha as SHA, type WrappableMiddleware, clientInfo, createTypedClient, hydrateVariable, i18n, isBot, jsonValidator, logger, onError, onNotFound, queue, response, withLogger };
package/dist/index.d.ts CHANGED
@@ -498,8 +498,7 @@ interface CreateTypedClientOptions {
498
498
  url: string;
499
499
  headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
500
500
  fetch?: typeof fetch;
501
- callbacks?: TypedClientCallbacks;
502
501
  }
503
- declare const createTypedClient: <TApp extends Hono<any, any, any>>(options: CreateTypedClientOptions) => <TSuccessData>(fn: (c: ReturnType<typeof hc<TApp>>) => Promise<ClientResponse<TSuccessData>>) => Promise<TSuccessData>;
502
+ declare const createTypedClient: <TApp extends Hono<any, any, any>>() => (options: CreateTypedClientOptions) => <TSuccessData>(fn: (c: ReturnType<typeof hc<TApp>>) => Promise<ClientResponse<TSuccessData>>, callbacks?: TypedClientCallbacks) => Promise<TSuccessData>;
504
503
 
505
504
  export { type ContextFn, type CreateTypedClientOptions, type HonoClientInfoVariables, type HonoI18nVariables, type HonoIsBotVariables, type HonoLanguageVariables, type HonoLoggerVariables, type HonoResponseVariables, type MessageHandlers, pbkdf2 as PBKDF2, QueueHandler, sha as SHA, type WrappableMiddleware, clientInfo, createTypedClient, hydrateVariable, i18n, isBot, jsonValidator, logger, onError, onNotFound, queue, response, withLogger };
package/dist/index.js CHANGED
@@ -14241,19 +14241,19 @@ var onNotFound = async (c) => {
14241
14241
  import { hc } from "hono/client";
14242
14242
  import { parseResponse, DetailedError } from "hono/client";
14243
14243
  import { HTTPException as HTTPException4 } from "hono/http-exception";
14244
- var createTypedClient = (options) => {
14245
- const client = hc(options.url, {
14246
- headers: options.headers,
14247
- fetch: options.fetch
14248
- });
14249
- const rpcClient = async (fn) => {
14250
- options.callbacks?.onStart?.();
14244
+ var createTypedClient = () => {
14245
+ return (options) => async (fn, callbacks) => {
14246
+ const client = hc(options.url, {
14247
+ headers: options.headers,
14248
+ fetch: options.fetch
14249
+ });
14250
+ callbacks?.onStart?.();
14251
14251
  let responseHeaders = new Headers();
14252
14252
  try {
14253
14253
  const response2 = await fn(client);
14254
14254
  responseHeaders = response2.headers;
14255
14255
  const data = await parseResponse(response2);
14256
- options.callbacks?.onSuccess?.(data, responseHeaders);
14256
+ callbacks?.onSuccess?.(data, responseHeaders);
14257
14257
  return data;
14258
14258
  } catch (err) {
14259
14259
  const errorBody = { message: err.message };
@@ -14262,20 +14262,19 @@ var createTypedClient = (options) => {
14262
14262
  const { detail, statusCode } = err;
14263
14263
  status = statusCode ?? 500;
14264
14264
  if (!detail) {
14265
- options.callbacks?.errorHandler?.(500, {
14265
+ callbacks?.errorHandler?.(500, {
14266
14266
  message: "Fetch malformed"
14267
14267
  });
14268
14268
  throw new HTTPException4(500, { message: "Fetch malformed" });
14269
14269
  }
14270
14270
  }
14271
- options.callbacks?.onError?.(errorBody, responseHeaders);
14272
- options.callbacks?.errorHandler?.(status, errorBody);
14271
+ callbacks?.onError?.(errorBody, responseHeaders);
14272
+ callbacks?.errorHandler?.(status, errorBody);
14273
14273
  throw new HTTPException4(status, errorBody);
14274
14274
  } finally {
14275
- options.callbacks?.onEnd?.();
14275
+ callbacks?.onEnd?.();
14276
14276
  }
14277
14277
  };
14278
- return rpcClient;
14279
14278
  };
14280
14279
  export {
14281
14280
  pbkdf2_exports as PBKDF2,