Socket
Socket
Sign inDemoInstall

@busy-hour/blaze

Package Overview
Dependencies
Maintainers
1
Versions
40
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 2.0.0 to 2.0.1

dist/cjs/event/index.js

8

CHANGELOG.md

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

## [2.0.1](https://github.com/Busy-Hour-Studio/blaze/compare/v2.0.0...v2.0.1) (2024-04-19)
### Bug Fixes
* cjs types build ([4ad2f69](https://github.com/Busy-Hour-Studio/blaze/commit/4ad2f697dd13d3be0b485d36cf798720344b87b6))
* remove redundant binding ([2d3c550](https://github.com/Busy-Hour-Studio/blaze/commit/2d3c550ecd8577bb07cf94d3b462f0a0e4955e93))
## [2.0.0](https://github.com/Busy-Hour-Studio/blaze/compare/v1.2.2...v2.0.0) (2024-02-28)

@@ -7,0 +15,0 @@

12

dist/cjs/errors/BlazeError.js

@@ -27,6 +27,6 @@ "use strict";

errors;
constructor(err) {
constructor(err, status = 500) {
if (typeof err === "string") {
super(err);
this.status = 500;
this.status = status;
this.name = "BlazeError";

@@ -40,2 +40,10 @@ } else {

}
toJSON() {
return {
errors: this.errors,
message: this.message,
name: this.name,
status: this.status
};
}
}

@@ -42,0 +50,0 @@ // Annotate the CommonJS export names for ESM import in node:

8

dist/cjs/event/BlazeBroker.js

@@ -24,8 +24,8 @@ "use strict";

module.exports = __toCommonJS(BlazeBroker_exports);
var import__ = require(".");
var import_BlazeError = require("../errors/BlazeError");
var import_constant = require("../utils/constant");
var import_BlazeEvent = require("./BlazeEvent");
class BlazeBroker {
hasListener(eventName) {
return import_BlazeEvent.BlazeEvent.listenerCount(eventName) > 0;
return import__.BlazeEvent.listenerCount(eventName) > 0;
}

@@ -46,3 +46,3 @@ validateEventName(eventName) {

this.validateEventName(eventName);
return import_BlazeEvent.BlazeEvent.emitAsync(eventName, ...values);
return import__.BlazeEvent.emitAsync(eventName, ...values);
}

@@ -54,3 +54,3 @@ // eslint-disable-next-line no-use-before-define, @typescript-eslint/no-shadow

emit(eventName, ...values) {
return import_BlazeEvent.BlazeEvent.emit(eventName, ...values);
return import__.BlazeEvent.emit(eventName, ...values);
}

@@ -57,0 +57,0 @@ event(eventName, ...values) {

@@ -35,5 +35,5 @@ "use strict";

var import_node_querystring = __toESM(require("node:querystring"), 1);
var import__ = require(".");
var import_context = require("../utils/helper/context");
var import_validator = require("../utils/helper/validator");
var import_BlazeBroker = require("./BlazeBroker");
class BlazeContext {

@@ -52,8 +52,8 @@ $honoCtx;

isRest;
broker;
broker = import__.BlazeBroker;
// Aliases for broker
call;
mcall;
emit;
event;
call = import__.BlazeBroker.call.bind(import__.BlazeBroker);
mcall = import__.BlazeBroker.mcall.bind(import__.BlazeBroker);
emit = import__.BlazeBroker.emit.bind(import__.BlazeBroker);
event = import__.BlazeBroker.event.bind(import__.BlazeBroker);
constructor(options) {

@@ -73,7 +73,2 @@ const { honoCtx, body, params, headers, validations } = options;

this.validations = validations;
this.broker = new import_BlazeBroker.BlazeBroker();
this.call = this.broker.call.bind(this.broker);
this.mcall = this.broker.mcall.bind(this.broker);
this.emit = this.broker.emit.bind(this.broker);
this.event = this.broker.event.bind(this.broker);
}

@@ -83,6 +78,8 @@ get query() {

return this.$query;
if (!this.$honoCtx)
return {};
const url = new URL(this.$honoCtx.req.url).searchParams;
this.$query = import_node_querystring.default.parse(url.toString());
if (!this.$honoCtx) {
this.$query = {};
} else {
const url = new URL(this.$honoCtx.req.url).searchParams;
this.$query = import_node_querystring.default.parse(url.toString());
}
return this.$query;

@@ -93,5 +90,7 @@ }

return this.$reqParams;
if (!this.$honoCtx)
return {};
this.$reqParams = this.$honoCtx.req.param();
if (!this.$honoCtx) {
this.$reqParams = {};
} else {
this.$reqParams = this.$honoCtx.req.param();
}
return this.$reqParams;

@@ -102,5 +101,7 @@ }

return this.$reqHeaders;
if (!this.$honoCtx)
return {};
this.$reqHeaders = this.$honoCtx.req.header();
if (!this.$honoCtx) {
this.$reqHeaders = {};
} else {
this.$reqHeaders = this.$honoCtx.req.header();
}
return this.$reqHeaders;

@@ -122,5 +123,7 @@ }

return this.$body;
if (!this.$honoCtx)
return {};
this.$body = await (0, import_context.getReqBody)(this.$honoCtx) ?? {};
if (!this.$honoCtx) {
this.$body = {};
} else {
this.$body = await (0, import_context.getReqBody)(this.$honoCtx) ?? {};
}
return this.$body;

@@ -127,0 +130,0 @@ }

@@ -34,4 +34,4 @@ "use strict";

openapi(route) {
let method = route.method ? route.method : "post";
method = method === "all" ? "post" : method.toLowerCase();
let method = route.method ? route.method.toLowerCase() : "post";
method = method === "all" ? "post" : method;
const newRoute = {

@@ -38,0 +38,0 @@ ...route,

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

removeTrailingSlash: () => removeTrailingSlash,
require: () => require2,
resolvePromise: () => resolvePromise,

@@ -33,3 +34,5 @@ toArray: () => toArray

module.exports = __toCommonJS(common_exports);
var import_BlazeContext = require("../event/BlazeContext");
var import_module = require("module");
var import_event = require("../event");
const import_meta = {};
function hasOwnProperty(obj, property) {

@@ -52,3 +55,3 @@ return Object.hasOwn(obj, property);

const version = service.version ? `v${service.version}` : "";
return [version, service.name].map((val) => removeTrailingSlash(val)).filter(Boolean).join("/");
return [version, service.name].map((val) => typeof val === "string" ? removeTrailingSlash(val) : null).filter(Boolean).join("/");
}

@@ -75,3 +78,3 @@ function getServiceName(service) {

const [blazeCtx, blazeErr] = await resolvePromise(
import_BlazeContext.BlazeContext.create(options)
import_event.BlazeContext.create(options)
);

@@ -89,2 +92,3 @@ if (!blazeCtx || blazeErr) {

}
const require2 = (0, import_module.createRequire)(import_meta.url);
// Annotate the CommonJS export names for ESM import in node:

@@ -99,4 +103,5 @@ 0 && (module.exports = {

removeTrailingSlash,
require,
resolvePromise,
toArray
});

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

extractRestPath: () => extractRestPath,
getRestResponse: () => getRestResponse,
getRouteHandler: () => getRouteHandler,

@@ -48,2 +49,14 @@ handleRestError: () => handleRestError,

}
function getRestResponse(options) {
const result = options.result;
const { status, headers } = options.ctx;
if (!status) {
return [result, void 0, void 0];
}
if (headers.size === 0) {
return [result, status, void 0];
}
const resHeaders = (0, import_common.mapToObject)(options.ctx.headers);
return [result, status, resHeaders];
}
function handleRestError(options) {

@@ -60,9 +73,4 @@ const { err, ctx, honoCtx } = options;

function handleRestResponse(options) {
const { ctx, honoCtx, result } = options;
const status = ctx.status ?? void 0;
let headers;
if (status) {
headers = ctx.headers.size > 0 ? (0, import_common.mapToObject)(ctx.headers) : void 0;
}
const args = [result, status, headers];
const { ctx, honoCtx } = options;
const args = getRestResponse(options);
switch (ctx.response) {

@@ -84,2 +92,3 @@ case "text":

extractRestPath,
getRestResponse,
getRouteHandler,

@@ -86,0 +95,0 @@ handleRestError,

@@ -25,4 +25,4 @@ "use strict";

var import_common = require("../common");
async function loadService(filePath) {
const file = await import(filePath);
function loadService(filePath) {
const file = (0, import_common.require)(filePath);
let service;

@@ -35,2 +35,5 @@ if (

service = file.default;
if ((0, import_common.hasOwnProperty)(service, "default")) {
service = service.default;
}
} else {

@@ -37,0 +40,0 @@ service = file;

@@ -70,3 +70,12 @@ "use strict";

if (!data.body && honoCtx) {
data.body = await (0, import_context.getReqBody)(honoCtx);
const method = honoCtx.req.method.toUpperCase();
switch (method) {
case "GET":
case "DELETE":
case "USE":
return;
default:
data.body = await (0, import_context.getReqBody)(honoCtx);
break;
}
}

@@ -73,0 +82,0 @@ const result = validateInput(data.body, schema);

@@ -36,5 +36,5 @@ "use strict";

var import_BlazeError = require("../errors/BlazeError");
var import_BlazeContext = require("../event/BlazeContext");
var import_event = require("../event");
var import_service = require("./setup/service");
async function initializeServices(options) {
function initializeServices(options) {
const { app, path: sourcePath } = options;

@@ -44,3 +44,3 @@ if (!import_node_fs.default.existsSync(sourcePath)) {

}
const blazeCtx = new import_BlazeContext.BlazeContext({
const blazeCtx = new import_event.BlazeContext({
body: null,

@@ -53,13 +53,11 @@ params: null,

const serviceFiles = import_node_fs.default.readdirSync(sourcePath);
const pendingServices = await Promise.all(
serviceFiles.map(async (servicePath) => {
const service = await import_service.BlazeService.create({
app,
servicePath,
blazeCtx,
sourcePath
});
return service;
})
);
const pendingServices = serviceFiles.map((servicePath) => {
const service = import_service.BlazeService.create({
app,
servicePath,
blazeCtx,
sourcePath
});
return service;
});
pendingServices.forEach((service) => service.onStarted());

@@ -66,0 +64,0 @@ }

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

module.exports = __toCommonJS(action_exports);
var import_BlazeEvent = require("../../event/BlazeEvent");
var import_event = require("../../event");
var import_common = require("../common");

@@ -36,3 +36,3 @@ var import_handler = require("../helper/handler");

this.action = options.action;
import_BlazeEvent.BlazeEvent.on(this.actionName, this.actionHandler.bind(this));
import_event.BlazeEvent.on(this.actionName, this.actionHandler.bind(this));
}

@@ -39,0 +39,0 @@ async actionHandler(body, params, headers) {

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

module.exports = __toCommonJS(event_exports);
var import_BlazeEvent = require("../../event/BlazeEvent");
var import_event = require("../../event");
var import_common = require("../common");

@@ -45,3 +45,3 @@ var import_constant = require("../constant");

};
import_BlazeEvent.BlazeEvent.on(this.eventName, this.eventHandler.bind(this));
import_event.BlazeEvent.on(this.eventName, this.eventHandler.bind(this));
}

@@ -48,0 +48,0 @@ async eventHandler(body, params, headers) {

@@ -65,5 +65,3 @@ "use strict";

}
return honoCtx.json(contextRes.error, {
status
});
return honoCtx.json(contextRes.error, status);
}

@@ -70,0 +68,0 @@ const { result: blazeCtx } = contextRes;

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

var import_node_path = __toESM(require("node:path"), 1);
var import_BlazeError = require("../../errors/BlazeError");
var import_BlazeEvent = require("../../event/BlazeEvent");
var import_event = require("../../event");
var import_router = require("../../router");

@@ -42,3 +41,3 @@ var import_common = require("../common");

var import_action = require("./action");
var import_event = require("./event");
var import_event2 = require("./event");
var import_rest = require("./rest");

@@ -59,5 +58,2 @@ class BlazeService {

const { service, blazeCtx, servicePath, app } = options;
if (typeof service.name === "undefined" || service.name === null) {
throw new import_BlazeError.BlazeError("Service name is required");
}
this.service = service;

@@ -91,39 +87,29 @@ this.servicePath = servicePath;

if (!this.service.actions)
return [];
const actions = Object.entries(this.service.actions).map(
([actionAlias, action]) => {
if (action.rest)
this.loadRest(action);
const actionInstace = new import_action.BlazeServiceAction({
action,
actionAlias,
serviceName: this.serviceName
});
this.handlers.push({
name: actionInstace.actionName,
handler: actionInstace.actionHandler
});
return actionInstace;
}
);
return this.actions.concat(actions);
return this.actions;
for (const actionAlias in this.service.actions) {
const action = this.service.actions[actionAlias];
if (action.rest)
this.loadRest(action);
const instance = new import_action.BlazeServiceAction({
action,
actionAlias,
serviceName: this.serviceName
});
this.actions.push(instance);
}
return this.actions;
}
loadServiceEvents() {
if (!this.service.events)
return;
const events = Object.entries(this.service.events).map(
([eventAlias, event]) => {
const eventInstance = new import_event.BlazeServiceEvent({
event,
eventAlias,
serviceName: this.serviceName
});
this.handlers.push({
name: eventInstance.eventName,
handler: eventInstance.eventHandler
});
return eventInstance;
}
);
return this.events.concat(events);
return this.events;
for (const eventAlias in this.service.events) {
const event = this.service.events[eventAlias];
const instance = new import_event2.BlazeServiceEvent({
event,
eventAlias,
serviceName: this.serviceName
});
this.events.push(instance);
}
return this.events;
}

@@ -142,3 +128,3 @@ assignRestRoute() {

this.actions.forEach((action) => {
import_BlazeEvent.BlazeEvent.off(action.actionName, action.actionHandler);
import_event.BlazeEvent.off(action.actionName, action.actionHandler);
});

@@ -152,3 +138,3 @@ }

this.actions.forEach((action) => {
import_BlazeEvent.BlazeEvent.on(action.actionName, action.actionHandler);
import_event.BlazeEvent.on(action.actionName, action.actionHandler);
});

@@ -160,5 +146,5 @@ }

}
static async create(options) {
static create(options) {
const servicePath = import_node_path.default.resolve(options.sourcePath, options.servicePath);
const serviceFile = await (0, import_service.loadService)(servicePath);
const serviceFile = (0, import_service.loadService)(servicePath);
const service = new BlazeService({

@@ -165,0 +151,0 @@ app: options.app,

@@ -7,2 +7,9 @@ import type { BlazeErrorOption } from '../types/error';

constructor(err: BlazeErrorOption);
constructor(message: string, status?: number);
toJSON(): {
errors: unknown;
message: string;
name: string;
status: number;
};
}

@@ -8,5 +8,4 @@ /// <reference types="node" />

import type { ResponseType } from '../types/rest';
import { BlazeBroker } from './BlazeBroker';
export declare class BlazeContext<Meta extends RecordUnknown = RecordUnknown, Body extends RecordUnknown = RecordUnknown, Params extends RecordUnknown = RecordUnknown, Headers extends RecordString = RecordString> {
private $honoCtx;
private readonly $honoCtx;
private $query;

@@ -23,7 +22,7 @@ private $body;

readonly isRest: boolean;
readonly broker: BlazeBroker;
readonly call: BlazeBroker['call'];
readonly mcall: BlazeBroker['mcall'];
readonly emit: BlazeBroker['emit'];
readonly event: BlazeBroker['event'];
readonly broker: import("./BlazeBroker").BlazeBroker;
readonly call: <T, U = T extends (infer T_1)[] ? import("../types/action").ActionCallResult<T_1> : import("../types/action").ActionCallResult<T>>(eventName: string, ...values: unknown[]) => Promise<U[]>;
readonly mcall: <T, U = T extends (infer T_1)[] ? import("../types/action").ActionCallResult<T_1> : import("../types/action").ActionCallResult<T>>(...args: [eventName: string, ...values: unknown[]][]) => Promise<U[][]>;
readonly emit: (eventName: string, ...values: unknown[]) => boolean;
readonly event: (eventName: string, ...values: unknown[]) => boolean;
constructor(options: ContextConstructorOption<Body, Params, Headers>);

@@ -30,0 +29,0 @@ get query(): qs.ParsedUrlQuery;

import type { ResponseConfig } from '@asteasolutions/zod-to-openapi';
import type { ZodObject, ZodRawShape } from 'zod';
import type { BlazeContext } from '../event/BlazeContext';
import type { BlazeContext } from '../event';
import type { Random, RecordString, RecordUnknown } from './helper';

@@ -5,0 +5,0 @@ import type { ActionHook } from './hooks';

import type { RecordString, RecordUnknown } from './helper';
export type BlazeErrorOption = string | {
export interface BlazeErrorOption {
errors: RecordUnknown | RecordString | unknown | null;

@@ -7,2 +7,2 @@ status: number;

name?: string | null;
};
}
import type { ZodObject, ZodRawShape } from 'zod';
import type { BlazeContext } from '../event/BlazeContext';
import type { BlazeContext } from '../event';
import type { ActionHandler } from './action';

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

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

import type { BlazeContext } from '../event/BlazeContext';
import type { BlazeContext } from '../event';
import type { RecordString, RecordUnknown } from './helper';

@@ -3,0 +3,0 @@ export interface BeforeHookHandler<Meta extends RecordUnknown = RecordUnknown, Body extends RecordUnknown = RecordUnknown, Params extends RecordUnknown = RecordUnknown, Header extends RecordString = RecordString> {

import type { Context as HonoCtx } from 'hono';
import type { BlazeContext } from '../event/BlazeContext';
import type { BlazeContext } from '../event';
import type { Blaze } from '../router';

@@ -4,0 +4,0 @@ import type { Action } from './action';

import type { Router } from 'hono/router';
import type { RouterRoute } from 'hono/types';
import type { BlazeContext } from '../event/BlazeContext';
import type { BlazeContext } from '../event';
import type { Blaze } from '../router';

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

export interface Service {
name: string;
name?: string | null;
version?: number | null;

@@ -11,0 +11,0 @@ actions?: Actions | null;

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

import { BlazeContext } from '../event/BlazeContext';
/// <reference types="node" />
import { BlazeContext } from '../event';
import type { ActionCallResult } from '../types/action';

@@ -15,1 +16,2 @@ import type { CreateContextOption } from '../types/context';

export declare function createContext(options: CreateContextOption): Promise<ActionCallResult<BlazeContext>>;
export declare const require: NodeRequire;

@@ -1,3 +0,3 @@

import { BlazeContext } from '../../event/BlazeContext';
import { BlazeContext } from '../../event';
import { Action, ActionCallResult } from '../../types/action';
export declare function eventHandler(action: Action, blazeCtx: BlazeContext): Promise<ActionCallResult<unknown>>;
/// <reference types="node" />
import { Hono } from 'hono';
import type { StatusCode } from 'hono/utils/http-status';
import type { Blaze } from '../../router/Blaze';
import type { Method, RestErrorHandlerOption, RestParam, RestResponseHandlerOption, RestRoute } from '../../types/rest';
export declare function extractRestPath(restRoute: RestRoute): readonly [null, string] | readonly [Method, string];
export declare function extractRestParams(params: RestParam): readonly [Method | null, string];
export declare function getRouteHandler(router: Hono, method: Method | null): import("hono/types").MiddlewareHandlerInterface<import("hono").Env, import("hono/types").BlankSchema, "/">;
export declare function getRouteHandler(router: Blaze, method: Method | null): import("hono/types").MiddlewareHandlerInterface<import("hono").Env, {}, "/">;
export declare function getRestResponse(options: Omit<RestResponseHandlerOption, 'honoCtx'>): readonly [
never,
StatusCode | undefined,
Record<string, string | string[]> | undefined
];
export declare function handleRestError(options: RestErrorHandlerOption): Response & import("hono").TypedResponse<{
status: number;
errors: never;
message: string;
name: string;
message: string;
stack?: string | undefined;
cause?: undefined;
status: number;
}>;
export declare function handleRestResponse(options: RestResponseHandlerOption): Response | Promise<Response>;
import { Service } from '../../types/service';
export declare function loadService(filePath: string): Promise<Service>;
export declare function loadService(filePath: string): Service;
import type { LoadServiceOption } from '../types/service';
export declare function initializeServices(options: LoadServiceOption): Promise<void>;
export declare function initializeServices(options: LoadServiceOption): void;

@@ -27,3 +27,3 @@ import { Blaze } from '../../router';

onStarted(): void;
static create(options: CreateServiceOption): Promise<BlazeService>;
static create(options: CreateServiceOption): BlazeService;
}

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

"type": "module",
"version": "2.0.0",
"version": "2.0.1",
"license": "MIT",

@@ -10,0 +10,0 @@ "devDependencies": {

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