Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@busy-hour/blaze

Package Overview
Dependencies
Maintainers
0
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@busy-hour/blaze - npm Package Compare versions

Comparing version 3.4.0 to 4.0.0-0

dist/cjs/internal/BlazeMap.js

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [4.0.0-0](https://github.com/busy-hour-studio/blaze/compare/v3.4.0...v4.0.0-0) (2024-09-13)
### Bug Fixes
* reduce context creation overhead ([818bd68](https://github.com/busy-hour-studio/blaze/commit/818bd68ed9e8e79a451e4a60d5de16dcf8f6de28))
## [3.4.0](https://github.com/busy-hour-studio/blaze/compare/v3.3.7...v3.4.0) (2024-08-19)

@@ -7,0 +14,0 @@

40

dist/cjs/internal/BlazeContext.js

@@ -25,2 +25,3 @@ "use strict";

var import__ = require(".");
var import_common = require("../utils/common");
var import_context = require("../utils/helper/context");

@@ -39,3 +40,3 @@ var import_validator = require("../utils/helper/validator");

status;
headers;
$headers;
isRest;

@@ -57,4 +58,4 @@ broker;

this.status = null;
this.$meta = meta ? new Map(Object.entries(meta)) : /* @__PURE__ */ new Map();
this.headers = /* @__PURE__ */ new Map();
this.$meta = meta ? structuredClone(meta) : null;
this.$headers = null;
this.isRest = !!honoCtx;

@@ -68,16 +69,35 @@ this.$validations = validations;

get meta() {
if (!this.$meta)
this.$meta = {};
const meta = this.$meta;
return {
set(key, value) {
meta.set(key, value);
meta[key] = value;
return this;
},
get(key) {
return meta.get(key);
return meta[key];
},
values: meta.values.bind(meta),
forEach: meta.forEach.bind(meta),
keys: meta.keys.bind(meta)
entries() {
return Object.entries(meta);
}
};
}
get headers() {
if (!this.$headers)
this.$headers = {};
const headers = this.$headers;
return {
set(key, value) {
headers[key] = value;
return this;
},
get(key) {
return headers[key];
},
entries() {
return Object.entries(headers);
}
};
}
get query() {

@@ -214,3 +234,3 @@ if (this.$query)

ctx.$honoCtx = honoCtx;
ctx.$meta = meta ? new Map(Object.entries(meta)) : /* @__PURE__ */ new Map();
ctx.$meta = meta ? structuredClone(meta) : null;
ctx.$validations = validations;

@@ -229,3 +249,3 @@ } else {

if (honoCtx && cachedCtx) {
Object.assign(ctx.headers, new Map(honoCtx.res.headers));
ctx.$headers = (0, import_common.mapToObject)(honoCtx.res.headers);
}

@@ -232,0 +252,0 @@ return ctx;

@@ -24,10 +24,9 @@ "use strict";

module.exports = __toCommonJS(BlazeEventEmitter_exports);
var import_BlazeMap = require("./BlazeMap");
class BlazeEventEmitter {
$maxListeners;
$emitter;
$onceEmitter;
constructor(options) {
this.$maxListeners = options?.maxListener ?? 100;
this.$emitter = /* @__PURE__ */ new Map();
this.$onceEmitter = /* @__PURE__ */ new Map();
this.$emitter = new import_BlazeMap.BlazeMap();
}

@@ -72,33 +71,6 @@ listenerCount(eventName) {

}
createOnceListener(eventName, listener) {
const self = this;
return function onceListener(...values) {
listener(...values);
self.off(eventName, onceListener);
};
}
once(eventName, listener) {
const listenerCount = this.listenerCount(eventName);
const onceListener = this.createOnceListener(eventName, listener);
if (!this.$emitter.has(eventName)) {
this.$emitter.set(eventName, /* @__PURE__ */ new Set());
}
if (!this.$onceEmitter.has(eventName)) {
this.$onceEmitter.set(eventName, /* @__PURE__ */ new Map());
}
if (listenerCount >= this.$maxListeners)
return;
this.$emitter.get(eventName)?.add?.(onceListener);
this.$onceEmitter.get(eventName)?.set?.(onceListener, listener);
}
off(eventName, listener) {
if (!this.$emitter.has(eventName))
return;
const onceListener = this.$onceEmitter.get(eventName)?.get(listener);
if (!onceListener) {
this.$emitter.get(eventName)?.delete(listener);
return;
}
this.$emitter.get(eventName)?.delete(onceListener);
this.$onceEmitter.get(eventName)?.delete(listener);
this.$emitter.get(eventName)?.delete(listener);
}

@@ -125,7 +97,2 @@ offAll(eventName) {

}
if (this.$onceEmitter.has(eventName)) {
this.$onceEmitter.get(eventName)?.forEach((listener) => {
listenerSet.add(listener);
});
}
return listenerSet;

@@ -132,0 +99,0 @@ }

@@ -23,3 +23,4 @@ "use strict";

BlazeContext: () => import_BlazeContext.BlazeContext,
BlazeEvent: () => BlazeEvent
BlazeEvent: () => BlazeEvent,
BlazeMap: () => import_BlazeMap.BlazeMap
});

@@ -30,2 +31,3 @@ module.exports = __toCommonJS(internal_exports);

var import_BlazeContext = require("./BlazeContext");
var import_BlazeMap = require("./BlazeMap");
const BlazeBroker = new import_BlazeBroker.BlazeBroker();

@@ -37,3 +39,4 @@ const BlazeEvent = new import_BlazeEventEmitter.BlazeEventEmitter({});

BlazeContext,
BlazeEvent
BlazeEvent,
BlazeMap
});

@@ -36,2 +36,3 @@ "use strict";

hasOwnProperty: () => hasOwnProperty,
isEmpty: () => isEmpty,
isNil: () => isNil,

@@ -105,2 +106,11 @@ isOnCjs: () => isOnCjs,

}
function isEmpty(value) {
if (Array.isArray(value)) {
return value.length === 0;
}
if (value && typeof value === "object") {
return Object.keys(value).length === 0;
}
return false;
}
function isOnCjs() {

@@ -144,2 +154,3 @@ return typeof module !== "undefined" && typeof exports !== "undefined";

hasOwnProperty,
isEmpty,
isNil,

@@ -146,0 +157,0 @@ isOnCjs,

@@ -54,3 +54,3 @@ "use strict";

}
if (headers.size === 0) {
if ((0, import_common.isEmpty)(headers)) {
return [result, status, void 0];

@@ -57,0 +57,0 @@ }

@@ -28,9 +28,6 @@ "use strict";

module.exports = __toCommonJS(validator_exports);
var import_zod = require("zod");
var import_BlazeError = require("../../errors/BlazeError");
var import_context = require("./context");
function validateInput(input, schema) {
if (schema instanceof import_zod.ZodEffects)
return schema.safeParse(input);
const result = schema.passthrough().safeParse(input);
const result = schema.safeParse(input);
return result;

@@ -103,3 +100,3 @@ }

}
const result = validateInput(data.body, schema);
const result = await validateInput(data.body, schema);
validations.body = result.success;

@@ -106,0 +103,0 @@ if (result.success)

// src/internal/BlazeContext.ts
import { BlazeBroker } from "./index.js";
import { mapToObject } from "../utils/common.js";
import { getReqBody, getReqQuery } from "../utils/helper/context.js";

@@ -21,3 +22,3 @@ import {

status;
headers;
$headers;
isRest;

@@ -39,4 +40,4 @@ broker;

this.status = null;
this.$meta = meta ? new Map(Object.entries(meta)) : /* @__PURE__ */ new Map();
this.headers = /* @__PURE__ */ new Map();
this.$meta = meta ? structuredClone(meta) : null;
this.$headers = null;
this.isRest = !!honoCtx;

@@ -50,16 +51,35 @@ this.$validations = validations;

get meta() {
if (!this.$meta)
this.$meta = {};
const meta = this.$meta;
return {
set(key, value) {
meta.set(key, value);
meta[key] = value;
return this;
},
get(key) {
return meta.get(key);
return meta[key];
},
values: meta.values.bind(meta),
forEach: meta.forEach.bind(meta),
keys: meta.keys.bind(meta)
entries() {
return Object.entries(meta);
}
};
}
get headers() {
if (!this.$headers)
this.$headers = {};
const headers = this.$headers;
return {
set(key, value) {
headers[key] = value;
return this;
},
get(key) {
return headers[key];
},
entries() {
return Object.entries(headers);
}
};
}
get query() {

@@ -196,3 +216,3 @@ if (this.$query)

ctx.$honoCtx = honoCtx;
ctx.$meta = meta ? new Map(Object.entries(meta)) : /* @__PURE__ */ new Map();
ctx.$meta = meta ? structuredClone(meta) : null;
ctx.$validations = validations;

@@ -211,3 +231,3 @@ } else {

if (honoCtx && cachedCtx) {
Object.assign(ctx.headers, new Map(honoCtx.res.headers));
ctx.$headers = mapToObject(honoCtx.res.headers);
}

@@ -214,0 +234,0 @@ return ctx;

// src/internal/BlazeEventEmitter.ts
import { BlazeMap } from "./BlazeMap.js";
var BlazeEventEmitter = class {
$maxListeners;
$emitter;
$onceEmitter;
constructor(options) {
this.$maxListeners = options?.maxListener ?? 100;
this.$emitter = /* @__PURE__ */ new Map();
this.$onceEmitter = /* @__PURE__ */ new Map();
this.$emitter = new BlazeMap();
}

@@ -49,33 +48,6 @@ listenerCount(eventName) {

}
createOnceListener(eventName, listener) {
const self = this;
return function onceListener(...values) {
listener(...values);
self.off(eventName, onceListener);
};
}
once(eventName, listener) {
const listenerCount = this.listenerCount(eventName);
const onceListener = this.createOnceListener(eventName, listener);
if (!this.$emitter.has(eventName)) {
this.$emitter.set(eventName, /* @__PURE__ */ new Set());
}
if (!this.$onceEmitter.has(eventName)) {
this.$onceEmitter.set(eventName, /* @__PURE__ */ new Map());
}
if (listenerCount >= this.$maxListeners)
return;
this.$emitter.get(eventName)?.add?.(onceListener);
this.$onceEmitter.get(eventName)?.set?.(onceListener, listener);
}
off(eventName, listener) {
if (!this.$emitter.has(eventName))
return;
const onceListener = this.$onceEmitter.get(eventName)?.get(listener);
if (!onceListener) {
this.$emitter.get(eventName)?.delete(listener);
return;
}
this.$emitter.get(eventName)?.delete(onceListener);
this.$onceEmitter.get(eventName)?.delete(listener);
this.$emitter.get(eventName)?.delete(listener);
}

@@ -102,7 +74,2 @@ offAll(eventName) {

}
if (this.$onceEmitter.has(eventName)) {
this.$onceEmitter.get(eventName)?.forEach((listener) => {
listenerSet.add(listener);
});
}
return listenerSet;

@@ -109,0 +76,0 @@ }

@@ -5,2 +5,3 @@ // src/internal/index.ts

import { BlazeContext } from "./BlazeContext.js";
import { BlazeMap } from "./BlazeMap.js";
var BlazeBroker = new Broker();

@@ -11,3 +12,4 @@ var BlazeEvent = new EventEmitter({});

BlazeContext,
BlazeEvent
BlazeEvent,
BlazeMap
};

@@ -68,2 +68,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {

}
function isEmpty(value) {
if (Array.isArray(value)) {
return value.length === 0;
}
if (value && typeof value === "object") {
return Object.keys(value).length === 0;
}
return false;
}
function isOnCjs() {

@@ -106,2 +115,3 @@ return typeof module !== "undefined" && typeof exports !== "undefined";

hasOwnProperty,
isEmpty,
isNil,

@@ -108,0 +118,0 @@ isOnCjs,

// src/utils/helper/rest.ts
import { BlazeError } from "../../errors/BlazeError.js";
import { mapToObject } from "../common.js";
import { isEmpty, mapToObject } from "../common.js";
function extractRestPath(restRoute) {

@@ -27,3 +27,3 @@ const restPath = restRoute.split(" ");

}
if (headers.size === 0) {
if (isEmpty(headers)) {
return [result, status, void 0];

@@ -30,0 +30,0 @@ }

// src/utils/helper/validator.ts
import { ZodEffects } from "zod";
import { BlazeError } from "../../errors/BlazeError.js";
import { getReqBody, getReqQuery } from "./context.js";
function validateInput(input, schema) {
if (schema instanceof ZodEffects)
return schema.safeParse(input);
const result = schema.passthrough().safeParse(input);
const result = schema.safeParse(input);
return result;

@@ -76,3 +73,3 @@ }

}
const result = validateInput(data.body, schema);
const result = await validateInput(data.body, schema);
validations.body = result.success;

@@ -79,0 +76,0 @@ if (result.success)

@@ -1,5 +0,5 @@

import type { ZodEffects, ZodObject, ZodRawShape } from 'zod';
import type { ZodSchema } from 'zod';
import type { Action, ActionValidator } from '../types/action';
import type { RecordUnknown } from '../types/helper';
export declare function createActionValidator<H extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, P extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, Q extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, B extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>>(validator: ActionValidator<H, P, Q, B>): ActionValidator<H, P, Q, B>;
export declare function createAction<R, HR, M extends RecordUnknown, H extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, P extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, Q extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, B extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>>(action: Action<R, HR, M, H, P, Q, B>): Action<R, HR, M, H, P, Q, B, import("..").AcceptedAfterHook<HR, M, H["_output"], P["_output"], Q["_output"], B["_output"]>, import("..").AcceptedBeforeHook<M, H["_output"], P["_output"], Q["_output"], B["_output"]>>;
export declare function createActionValidator<H extends ZodSchema, P extends ZodSchema, Q extends ZodSchema, B extends ZodSchema>(validator: ActionValidator<H, P, Q, B>): ActionValidator<H, P, Q, B>;
export declare function createAction<R, HR, M extends RecordUnknown, H extends ZodSchema, P extends ZodSchema, Q extends ZodSchema, B extends ZodSchema>(action: Action<R, HR, M, H, P, Q, B>): Action<R, HR, M, H, P, Q, B, import("..").AcceptedAfterHook<HR, M, H["_output"], P["_output"], Q["_output"], B["_output"]>, import("..").AcceptedBeforeHook<M, H["_output"], P["_output"], Q["_output"], B["_output"]>>;

@@ -1,5 +0,5 @@

import type { ZodEffects, ZodObject, ZodRawShape } from 'zod';
import type { ZodSchema } from 'zod';
import type { Event } from '../types/event';
import type { RecordUnknown } from '../types/helper';
export declare function createEventValidator<Params extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>>(validator: Params): Params;
export declare function createEvent<M extends RecordUnknown, P extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>>(event: Event<M, P>): Event<M, P>;
export declare function createEventValidator<Params extends ZodSchema>(validator: Params): Params;
export declare function createEvent<M extends RecordUnknown, P extends ZodSchema>(event: Event<M, P>): Event<M, P>;
import type { StatusCode } from 'hono/utils/http-status';
import type { ZodEffects, ZodObject, ZodRawShape } from 'zod';
import type { ZodSchema } from 'zod';
import type { ContextConstructorOption, CreateContextOption } from '../types/context';

@@ -18,3 +18,3 @@ import type { RecordString, RecordUnknown, ValidationResult } from '../types/helper';

status: StatusCode | null;
readonly headers: Map<string, string | string[]>;
private $headers;
readonly isRest: boolean;

@@ -29,6 +29,9 @@ readonly broker: Broker;

get<K_1 extends keyof M, V_1 extends M[K_1]>(key: K_1): V_1;
values: () => IterableIterator<M[keyof M]>;
forEach: (callbackfn: (value: M[keyof M], key: keyof M, map: Map<keyof M, M[keyof M]>) => void, thisArg?: any) => void;
keys: () => IterableIterator<keyof M>;
entries(): [string, unknown][];
};
get headers(): {
set(key: string, value: string | string[]): any;
get(key: string): string | string[];
entries(): [string, string | string[]][];
};
get query(): Q;

@@ -46,3 +49,3 @@ private get reqParams();

get validations(): ValidationResult | null;
static create<M extends RecordUnknown, H extends RecordString, P extends RecordUnknown, Q extends RecordUnknown, B extends RecordUnknown, HV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, PV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, QV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, BV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>>(options: CreateContextOption<M, H, P, Q, B, HV, PV, QV, BV>): Promise<BlazeContext<M, H, P, Q, B>>;
static create<M extends RecordUnknown, H extends RecordString, P extends RecordUnknown, Q extends RecordUnknown, B extends RecordUnknown, HV extends ZodSchema, PV extends ZodSchema, QV extends ZodSchema, BV extends ZodSchema>(options: CreateContextOption<M, H, P, Q, B, HV, PV, QV, BV>): Promise<BlazeContext<M, H, P, Q, B>>;
}

@@ -8,3 +8,2 @@ import type { EventListener, EventName } from '../types/event';

private $emitter;
private $onceEmitter;
constructor(options: Option);

@@ -17,4 +16,2 @@ listenerCount(eventName: EventName): number;

on(eventName: EventName, listener: EventListener): void;
private createOnceListener;
once(eventName: EventName, listener: EventListener): void;
off(eventName: EventName, listener: EventListener): void;

@@ -21,0 +18,0 @@ offAll(): void;

import { BlazeBroker as Broker } from './BlazeBroker';
import { BlazeEventEmitter as EventEmitter } from './BlazeEventEmitter';
export { BlazeContext } from './BlazeContext';
export { BlazeMap } from './BlazeMap';
export declare const BlazeBroker: Broker;
export declare const BlazeEvent: EventEmitter;
import type { ResponseConfig } from '@asteasolutions/zod-to-openapi';
import type { ZodEffects, ZodObject, ZodRawShape } from 'zod';
import type { ZodSchema } from 'zod';
import type { BlazeContext } from '../internal';

@@ -7,3 +7,3 @@ import type { Random, RecordString, RecordUnknown } from './helper';

import type { Middleware, RestParam } from './rest';
export interface ActionValidator<H extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, P extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, Q extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, B extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>> {
export interface ActionValidator<H extends ZodSchema = ZodSchema, P extends ZodSchema = ZodSchema, Q extends ZodSchema = ZodSchema, B extends ZodSchema = ZodSchema> {
header?: H | null;

@@ -26,3 +26,3 @@ params?: P | null;

}
export interface Action<R = unknown | void, HR = unknown | void, M extends RecordUnknown = RecordUnknown, H extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, P extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, Q extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, B extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, AH extends AcceptedAfterHook<HR, M, H['_output'], P['_output'], Q['_output'], B['_output']> = AcceptedAfterHook<HR, M, H['_output'], P['_output'], Q['_output'], B['_output']>, BH extends AcceptedBeforeHook<M, H['_output'], P['_output'], Q['_output'], B['_output']> = AcceptedBeforeHook<M, H['_output'], P['_output'], Q['_output'], B['_output']>> {
export interface Action<R = unknown | void, HR = unknown | void, M extends RecordUnknown = RecordUnknown, H extends ZodSchema = ZodSchema, P extends ZodSchema = ZodSchema, Q extends ZodSchema = ZodSchema, B extends ZodSchema = ZodSchema, AH extends AcceptedAfterHook<HR, M, H['_output'], P['_output'], Q['_output'], B['_output']> = AcceptedAfterHook<HR, M, H['_output'], P['_output'], Q['_output'], B['_output']>, BH extends AcceptedBeforeHook<M, H['_output'], P['_output'], Q['_output'], B['_output']> = AcceptedBeforeHook<M, H['_output'], P['_output'], Q['_output'], B['_output']>> {
openapi?: ActionOpenAPI | null;

@@ -29,0 +29,0 @@ middlewares?: Middleware[] | null;

import type { Context as HonoCtx } from 'hono';
import type { ZodEffects, ZodObject, ZodRawShape } from 'zod';
import type { ZodSchema } from 'zod';
import type { BlazeContext } from '../internal';
import type { ContextValidation, Random, RecordString, RecordUnknown, ValidationResult } from './helper';
export interface CreateContextOption<M extends RecordUnknown = RecordUnknown, H extends RecordString = RecordString, P extends RecordUnknown = RecordUnknown, Q extends RecordUnknown = RecordUnknown, B extends RecordUnknown = RecordUnknown, HV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, PV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, QV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, BV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, V extends ContextValidation<HV, PV, QV, BV> = ContextValidation<HV, PV, QV, BV>> {
export interface CreateContextOption<M extends RecordUnknown = RecordUnknown, H extends RecordString = RecordString, P extends RecordUnknown = RecordUnknown, Q extends RecordUnknown = RecordUnknown, B extends RecordUnknown = RecordUnknown, HV extends ZodSchema = ZodSchema, PV extends ZodSchema = ZodSchema, QV extends ZodSchema = ZodSchema, BV extends ZodSchema = ZodSchema, V extends ContextValidation<HV, PV, QV, BV> = ContextValidation<HV, PV, QV, BV>> {
honoCtx: HonoCtx | null;

@@ -15,5 +15,5 @@ meta: M | null;

}
export interface ContextConstructorOption<M extends RecordUnknown, H extends RecordString, P extends RecordUnknown, Q extends RecordUnknown, B extends RecordUnknown, HV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, PV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, QV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, BV extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>> extends Omit<CreateContextOption<M, H, P, Q, B, HV, PV, QV, BV>, 'validator' | 'throwOnValidationError'> {
export interface ContextConstructorOption<M extends RecordUnknown, H extends RecordString, P extends RecordUnknown, Q extends RecordUnknown, B extends RecordUnknown, HV extends ZodSchema = ZodSchema, PV extends ZodSchema = ZodSchema, QV extends ZodSchema = ZodSchema, BV extends ZodSchema = ZodSchema> extends Omit<CreateContextOption<M, H, P, Q, B, HV, PV, QV, BV>, 'validator' | 'throwOnValidationError'> {
validations: ValidationResult | null;
}
export type AnyContext = BlazeContext<Random, Random, Random, Random, Random>;

@@ -1,2 +0,2 @@

import type { ZodEffects, ZodObject, ZodRawShape } from 'zod';
import type { ZodSchema } from 'zod';
import type { Action, ActionOpenAPI, Actions, ActionValidator } from './action';

@@ -20,3 +20,3 @@ import type { Event, Events } from './event';

*/
<R, HR, M extends RecordUnknown, H extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, P extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, Q extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, B extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, AH extends AcceptedAfterHook<HR, M, H['_output'], P['_output'], Q['_output'], B['_output']>, BH extends AcceptedBeforeHook<M, H['_output'], P['_output'], Q['_output'], B['_output']>>(action: Action<R, HR, M, H, P, Q, B, AH, BH>): Action<R, HR, M, H, P, Q, B, AH, BH>;
<R, HR, M extends RecordUnknown, H extends ZodSchema, P extends ZodSchema, Q extends ZodSchema, B extends ZodSchema, AH extends AcceptedAfterHook<HR, M, H['_output'], P['_output'], Q['_output'], B['_output']>, BH extends AcceptedBeforeHook<M, H['_output'], P['_output'], Q['_output'], B['_output']>>(action: Action<R, HR, M, H, P, Q, B, AH, BH>): Action<R, HR, M, H, P, Q, B, AH, BH>;
/**

@@ -33,3 +33,3 @@ * Create a reuseable validator for actions body, params and headers.

*/
validator<H extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, P extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, Q extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>, B extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>>(validator: ActionValidator<H, P, Q, B>): ActionValidator<H, P, Q, B>;
validator<H extends ZodSchema, P extends ZodSchema, Q extends ZodSchema, B extends ZodSchema>(validator: ActionValidator<H, P, Q, B>): ActionValidator<H, P, Q, B>;
/**

@@ -98,3 +98,3 @@ * Create an openai spec for action.

*/
<M extends RecordUnknown, P extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>>(event: Event<M, P>): Event<M, P>;
<M extends RecordUnknown, P extends ZodSchema>(event: Event<M, P>): Event<M, P>;
/**

@@ -110,3 +110,3 @@ * Create a reuseable validator for events parameters.

*/
validator<Params extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>>(validator: Params): Params;
validator<Params extends ZodSchema>(validator: Params): Params;
}

@@ -113,0 +113,0 @@ export interface BlazeServiceCreator {

@@ -1,2 +0,2 @@

import type { ZodEffects, ZodObject, ZodRawShape } from 'zod';
import type { ZodSchema } from 'zod';
import type { BlazeContext } from '../internal';

@@ -16,3 +16,3 @@ import type { ActionHandler } from './action';

}
export interface Event<M extends RecordUnknown = RecordUnknown, P extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>> {
export interface Event<M extends RecordUnknown = RecordUnknown, P extends ZodSchema = ZodSchema> {
validator?: P | null;

@@ -19,0 +19,0 @@ handler: EventHandler<M, P['_output']>;

import type { Context as HonoContext } from 'hono';
import type { ZodEffects, ZodObject, ZodRawShape } from 'zod';
import type { ZodSchema } from 'zod';
export type RecordUnknown = Record<string, unknown>;
export type RecordString = Record<string, string>;
export type Random = any;
export interface ContextValidation<H extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, P extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, Q extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>, B extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> = ZodObject<ZodRawShape>> {
export interface ContextValidation<H extends ZodSchema = ZodSchema, P extends ZodSchema = ZodSchema, Q extends ZodSchema = ZodSchema, B extends ZodSchema = ZodSchema> {
header?: H | null;

@@ -26,3 +26,3 @@ params?: P | null;

data: ContextData<H, P, Q, B>;
schema: ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>;
schema: ZodSchema;
honoCtx: HonoContext | null;

@@ -29,0 +29,0 @@ throwOnValidationError: boolean;

import type { RouteConfig, ZodRequestBody } from '@asteasolutions/zod-to-openapi';
import type { Router } from 'hono/router';
import type { Env, MiddlewareHandler, RouterRoute } from 'hono/types';
import type { AnyZodObject } from 'zod';
import type { ZodSchema } from 'zod';
import type { RecordUnknown } from './helper';

@@ -15,5 +15,5 @@ import type { Method, Middleware } from './rest';

body?: ZodRequestBody;
params?: AnyZodObject;
headers?: AnyZodObject;
query?: AnyZodObject;
params?: ZodSchema;
headers?: ZodSchema;
query?: ZodSchema;
}

@@ -20,0 +20,0 @@ export interface BlazeOpenAPIOption extends Omit<RouteConfig, 'request' | 'method'> {

@@ -15,4 +15,5 @@ import { BlazeContext } from '../internal';

export declare function createContext(options: CreateContextOption): Promise<ActionCallResult<BlazeContext>>;
export declare function isEmpty(value: Random): boolean;
export declare function isOnCjs(): boolean;
export declare function loadFile<T = Random>(id: string): Promise<T>;
export declare function crossRequire<T = Random>(id: string): T;

@@ -12,8 +12,3 @@ import type { StatusCode } from 'hono/utils/http-status';

];
export declare function handleRestError(options: RestErrorHandlerOption): Response & import("hono").TypedResponse<{
name: string;
message: string;
stack?: string | undefined;
cause?: undefined;
}, 500 | 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | -1, "json">;
export declare function handleRestError(options: RestErrorHandlerOption): Response & import("hono").TypedResponse<never, 500 | 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | -1, "json">;
export declare function handleRestResponse(options: RestResponseHandlerOption): Response;

@@ -1,8 +0,4 @@

import { ZodEffects, ZodObject, ZodRawShape } from 'zod';
import type { ZodSchema } from 'zod';
import type { DataValidatorOption } from '../../types/helper';
export declare function validateInput<T extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>>>(input: unknown, schema: T): import("zod").SafeParseSuccess<{
[x: string]: any;
}> | import("zod").SafeParseError<{
[x: string]: any;
}>;
export declare function validateInput<T extends ZodSchema>(input: unknown, schema: T): import("zod").SafeParseReturnType<any, any>;
export declare function validateHeader(options: DataValidatorOption): void;

@@ -9,0 +5,0 @@ export declare function validateParams(options: DataValidatorOption): void;

@@ -7,3 +7,3 @@ {

"type": "module",
"version": "3.4.0",
"version": "4.0.0-0",
"license": "MIT",

@@ -39,4 +39,4 @@ "devDependencies": {

"dependencies": {
"hono": "^4.4.9",
"zod": "^3.22.4"
"hono": ">=4.6.1",
"zod": ">=3.23.8"
},

@@ -43,0 +43,0 @@ "author": "Muhammad Firdaus Sati (https://github.com/krsbx)",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc