@busy-hour/blaze
Advanced tools
Comparing version 3.0.3 to 3.1.0
@@ -5,2 +5,14 @@ # Changelog | ||
## [3.1.0](https://github.com/Busy-Hour-Studio/blaze/compare/v3.0.3...v3.1.0) (2024-05-09) | ||
### Features | ||
* action meta initializer ([ba88d21](https://github.com/Busy-Hour-Studio/blaze/commit/ba88d21bd37e3e06a76b4251961f37dd85f95866)) | ||
### Bug Fixes | ||
* service creator type definitions ([d5d93a5](https://github.com/Busy-Hour-Studio/blaze/commit/d5d93a5a3f7277a00e8ed57d73ea9872c61cc3fc)) | ||
## [3.0.3](https://github.com/Busy-Hour-Studio/blaze/compare/v3.0.2...v3.0.3) (2024-05-03) | ||
@@ -7,0 +19,0 @@ |
@@ -40,2 +40,3 @@ "use strict"; | ||
$honoCtx; | ||
$meta; | ||
$query; | ||
@@ -48,3 +49,2 @@ $body; | ||
status; | ||
meta; | ||
headers; | ||
@@ -59,3 +59,3 @@ validations; | ||
constructor(options) { | ||
const { honoCtx, body, params, headers, validations } = options; | ||
const { honoCtx, body, params, headers, validations, meta } = options; | ||
this.$honoCtx = honoCtx; | ||
@@ -69,5 +69,5 @@ this.$reqHeaders = headers; | ||
this.status = null; | ||
this.meta = /* @__PURE__ */ new Map(); | ||
this.$meta = meta ? new Map(Object.entries(meta)) : /* @__PURE__ */ new Map(); | ||
this.headers = /* @__PURE__ */ new Map(); | ||
this.isRest = !!options.honoCtx; | ||
this.isRest = !!honoCtx; | ||
this.validations = validations; | ||
@@ -79,2 +79,17 @@ this.broker = import__.BlazeBroker; | ||
} | ||
get meta() { | ||
const meta = this.$meta; | ||
return { | ||
set(key, value) { | ||
meta.set(key, value); | ||
return this; | ||
}, | ||
get(key) { | ||
return meta.get(key); | ||
}, | ||
values: meta.values.bind(meta), | ||
forEach: meta.forEach.bind(meta), | ||
keys: meta.keys.bind(meta) | ||
}; | ||
} | ||
get query() { | ||
@@ -141,3 +156,3 @@ if (this.$query) | ||
static async create(options) { | ||
const { honoCtx, validator, throwOnValidationError } = options; | ||
const { honoCtx, validator, throwOnValidationError, meta } = options; | ||
const data = { | ||
@@ -185,2 +200,3 @@ body: null, | ||
honoCtx, | ||
meta, | ||
validations | ||
@@ -187,0 +203,0 @@ }); |
@@ -60,2 +60,3 @@ "use strict"; | ||
honoCtx: null, | ||
meta: null, | ||
validations: null | ||
@@ -62,0 +63,0 @@ }); |
@@ -48,2 +48,3 @@ "use strict"; | ||
honoCtx: null, | ||
meta: null, | ||
validations: null | ||
@@ -50,0 +51,0 @@ }); |
@@ -44,2 +44,3 @@ "use strict"; | ||
validator: this.action.validator ?? null, | ||
meta: this.action.meta ?? null, | ||
throwOnValidationError: this.action.throwOnValidationError ?? false | ||
@@ -46,0 +47,0 @@ }); |
@@ -53,2 +53,3 @@ "use strict"; | ||
validator: this.validator ?? null, | ||
meta: null, | ||
throwOnValidationError: this.event.throwOnValidationError ?? false | ||
@@ -55,0 +56,0 @@ }); |
@@ -58,2 +58,3 @@ "use strict"; | ||
validator: this.action.validator ?? null, | ||
meta: this.action.meta ?? null, | ||
throwOnValidationError: this.action.throwOnValidationError ?? false | ||
@@ -60,0 +61,0 @@ }); |
@@ -12,2 +12,3 @@ // src/event/BlazeContext.ts | ||
$honoCtx; | ||
$meta; | ||
$query; | ||
@@ -20,3 +21,2 @@ $body; | ||
status; | ||
meta; | ||
headers; | ||
@@ -31,3 +31,3 @@ validations; | ||
constructor(options) { | ||
const { honoCtx, body, params, headers, validations } = options; | ||
const { honoCtx, body, params, headers, validations, meta } = options; | ||
this.$honoCtx = honoCtx; | ||
@@ -41,5 +41,5 @@ this.$reqHeaders = headers; | ||
this.status = null; | ||
this.meta = /* @__PURE__ */ new Map(); | ||
this.$meta = meta ? new Map(Object.entries(meta)) : /* @__PURE__ */ new Map(); | ||
this.headers = /* @__PURE__ */ new Map(); | ||
this.isRest = !!options.honoCtx; | ||
this.isRest = !!honoCtx; | ||
this.validations = validations; | ||
@@ -51,2 +51,17 @@ this.broker = BlazeBroker; | ||
} | ||
get meta() { | ||
const meta = this.$meta; | ||
return { | ||
set(key, value) { | ||
meta.set(key, value); | ||
return this; | ||
}, | ||
get(key) { | ||
return meta.get(key); | ||
}, | ||
values: meta.values.bind(meta), | ||
forEach: meta.forEach.bind(meta), | ||
keys: meta.keys.bind(meta) | ||
}; | ||
} | ||
get query() { | ||
@@ -113,3 +128,3 @@ if (this.$query) | ||
static async create(options) { | ||
const { honoCtx, validator, throwOnValidationError } = options; | ||
const { honoCtx, validator, throwOnValidationError, meta } = options; | ||
const data = { | ||
@@ -157,2 +172,3 @@ body: null, | ||
honoCtx, | ||
meta, | ||
validations | ||
@@ -159,0 +175,0 @@ }); |
@@ -28,2 +28,3 @@ // src/router/Blaze.ts | ||
honoCtx: null, | ||
meta: null, | ||
validations: null | ||
@@ -30,0 +31,0 @@ }); |
@@ -16,2 +16,3 @@ // src/utils/setup.ts | ||
honoCtx: null, | ||
meta: null, | ||
validations: null | ||
@@ -18,0 +19,0 @@ }); |
@@ -22,2 +22,3 @@ // src/utils/setup/action.ts | ||
validator: this.action.validator ?? null, | ||
meta: this.action.meta ?? null, | ||
throwOnValidationError: this.action.throwOnValidationError ?? false | ||
@@ -24,0 +25,0 @@ }); |
@@ -31,2 +31,3 @@ // src/utils/setup/event.ts | ||
validator: this.validator ?? null, | ||
meta: null, | ||
throwOnValidationError: this.event.throwOnValidationError ?? false | ||
@@ -33,0 +34,0 @@ }); |
@@ -40,2 +40,3 @@ // src/utils/setup/rest.ts | ||
validator: this.action.validator ?? null, | ||
meta: this.action.meta ?? null, | ||
throwOnValidationError: this.action.throwOnValidationError ?? false | ||
@@ -42,0 +43,0 @@ }); |
import type { Service } from '../types/service'; | ||
export declare function createService(service: Service): Service; | ||
export declare function createService(service: Service): Service<string, import("..").Actions, import("..").Events>; |
@@ -11,2 +11,3 @@ /// <reference types="node" /> | ||
private readonly $honoCtx; | ||
private readonly $meta; | ||
private $query; | ||
@@ -19,3 +20,2 @@ private $body; | ||
status: StatusCode | null; | ||
readonly meta: Map<keyof Meta, Meta[keyof Meta]>; | ||
readonly headers: Map<string, string | string[]>; | ||
@@ -28,3 +28,10 @@ readonly validations: ValidationResult | null; | ||
readonly event: Broker['event']; | ||
constructor(options: ContextConstructorOption<Body, Params, Headers>); | ||
constructor(options: ContextConstructorOption<Meta, Body, Params, Headers>); | ||
get meta(): { | ||
set<K extends keyof Meta, V extends Meta[K]>(key: K, value: V): any; | ||
get<K_1 extends keyof Meta, V_1 extends Meta[K_1]>(key: K_1): V_1; | ||
values: () => IterableIterator<Meta[keyof Meta]>; | ||
forEach: (callbackfn: (value: Meta[keyof Meta], key: keyof Meta, map: Map<keyof Meta, Meta[keyof Meta]>) => void, thisArg?: any) => void; | ||
keys: () => IterableIterator<keyof Meta>; | ||
}; | ||
get query(): qs.ParsedUrlQuery; | ||
@@ -41,3 +48,3 @@ private get reqParams(); | ||
}; | ||
static create<Meta extends RecordUnknown = RecordUnknown, Body extends RecordUnknown = RecordUnknown, Params extends RecordUnknown = RecordUnknown, Headers extends RecordString = RecordString, BodyValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, ParamsValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, HeaderValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, Validator extends Partial<ContextValidation<BodyValidation, ParamsValidation, HeaderValidation>> = Partial<ContextValidation<BodyValidation, ParamsValidation, HeaderValidation>>>(options: CreateContextOption<Body, Params, Headers, BodyValidation, ParamsValidation, HeaderValidation, Validator>): Promise<BlazeContext<Meta, Body, Params, Headers>>; | ||
static create<Meta extends RecordUnknown = RecordUnknown, Body extends RecordUnknown = RecordUnknown, Params extends RecordUnknown = RecordUnknown, Headers extends RecordString = RecordString, BodyValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, ParamsValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, HeaderValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, Validator extends Partial<ContextValidation<BodyValidation, ParamsValidation, HeaderValidation>> = Partial<ContextValidation<BodyValidation, ParamsValidation, HeaderValidation>>>(options: CreateContextOption<Meta, Body, Params, Headers, BodyValidation, ParamsValidation, HeaderValidation, Validator>): Promise<BlazeContext<Meta, Body, Params, Headers>>; | ||
} |
@@ -28,2 +28,3 @@ import type { ResponseConfig } from '@asteasolutions/zod-to-openapi'; | ||
handler: ActionHandler<Result, Meta, FinalBody, FinalParams, FinalHeader>; | ||
meta?: Meta | null; | ||
rest?: RestParam | null; | ||
@@ -40,4 +41,5 @@ hooks?: ActionHook<Meta, FinalBody, FinalParams, FinalHeader, never> | null; | ||
}; | ||
export type AnyAction = Action<Random, RecordUnknown, Random, Random, Random>; | ||
export interface Actions { | ||
[key: string]: Action<Random, RecordUnknown, Random, Random, Random>; | ||
[key: string]: AnyAction; | ||
} |
import type { Context as HonoCtx } from 'hono'; | ||
import type { ZodObject, ZodRawShape } from 'zod'; | ||
import type { ContextValidation, RecordString, RecordUnknown, ValidationResult } from './helper'; | ||
export interface CreateContextOption<Body extends RecordUnknown = RecordUnknown, Params extends RecordUnknown = RecordUnknown, Headers extends RecordString = RecordString, BodyValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, ParamsValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, HeaderValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, Validator extends ContextValidation<BodyValidation, ParamsValidation, HeaderValidation> = ContextValidation<BodyValidation, ParamsValidation, HeaderValidation>> { | ||
export interface CreateContextOption<Meta extends RecordUnknown = RecordUnknown, Body extends RecordUnknown = RecordUnknown, Params extends RecordUnknown = RecordUnknown, Headers extends RecordString = RecordString, BodyValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, ParamsValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, HeaderValidation extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, Validator extends ContextValidation<BodyValidation, ParamsValidation, HeaderValidation> = ContextValidation<BodyValidation, ParamsValidation, HeaderValidation>> { | ||
honoCtx: HonoCtx | null; | ||
meta: Meta | null; | ||
body: Body | null; | ||
@@ -12,4 +13,4 @@ params: Params | null; | ||
} | ||
export interface ContextConstructorOption<Body extends RecordUnknown = RecordUnknown, Params extends RecordUnknown = RecordUnknown, Headers extends RecordString = RecordString> extends Omit<CreateContextOption<Body, Params, Headers>, 'validator' | 'throwOnValidationError'> { | ||
export interface ContextConstructorOption<Meta extends RecordUnknown = RecordUnknown, Body extends RecordUnknown = RecordUnknown, Params extends RecordUnknown = RecordUnknown, Headers extends RecordString = RecordString> extends Omit<CreateContextOption<Meta, Body, Params, Headers>, 'validator' | 'throwOnValidationError'> { | ||
validations: ValidationResult | null; | ||
} |
import type { ZodObject, ZodRawShape } from 'zod'; | ||
import type { Action, ActionOpenAPI, ActionValidator } from './action'; | ||
import type { Event } from './event'; | ||
import type { Action, ActionOpenAPI, Actions, ActionValidator } from './action'; | ||
import type { Event, Events } from './event'; | ||
import type { RecordString, RecordUnknown } from './helper'; | ||
import type { AfterHookHandler, BeforeHookHandler } from './hooks'; | ||
import type { Service } from './service'; | ||
import { Service } from './service'; | ||
export interface BlazeActionCreator { | ||
@@ -123,5 +123,5 @@ /** | ||
*/ | ||
<T extends Service>(service: T): Readonly<T>; | ||
<N extends string, A extends Actions, E extends Events, S extends Service<N, A, E>>(service: S): Readonly<S>; | ||
action: BlazeActionCreator; | ||
event: BlazeEventCreator; | ||
} |
@@ -21,4 +21,5 @@ import type { ZodObject, ZodRawShape } from 'zod'; | ||
} | ||
export type AnyEvent = Event<RecordUnknown, Random>; | ||
export interface Events { | ||
[key: string]: Event<RecordUnknown, Random>; | ||
[key: string]: AnyEvent; | ||
} |
@@ -7,7 +7,7 @@ import type { Router } from 'hono/router'; | ||
import type { Event, EventActionHandler, Events } from './event'; | ||
export interface Service { | ||
name?: string | null; | ||
export interface Service<N extends string = string, A extends Actions = Actions, E extends Events = Events> { | ||
name?: N | null; | ||
version?: number | null; | ||
actions?: Actions | null; | ||
events?: Events | null; | ||
actions?: A | null; | ||
events?: E | null; | ||
onCreated?: ActionHandler | null; | ||
@@ -14,0 +14,0 @@ onStarted?: ActionHandler | null; |
import { Service } from '../../types/service'; | ||
export declare function loadService(filePath: string): Promise<Service>; | ||
export declare function loadService(filePath: string): Promise<Service<string, import("../..").Actions, import("../..").Events>>; |
@@ -7,3 +7,3 @@ { | ||
"type": "module", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -10,0 +10,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
191172
4970