@busy-hour/blaze
Advanced tools
Comparing version 3.0.0-3 to 3.0.0
@@ -5,2 +5,10 @@ # Changelog | ||
## [3.0.0](https://github.com/Busy-Hour-Studio/blaze/compare/v3.0.0-3...v3.0.0) (2024-04-23) | ||
### Features | ||
* optional dependencies ([3383b48](https://github.com/Busy-Hour-Studio/blaze/commit/3383b487e3882547524950b075d9ff0d0838b80b)) | ||
* simplified cjs/esm loader ([5508978](https://github.com/Busy-Hour-Studio/blaze/commit/5508978078ece4870e3122b104d4ef265caebd17)) | ||
## [3.0.0-3](https://github.com/Busy-Hour-Studio/blaze/compare/v3.0.0-2...v3.0.0-3) (2024-04-21) | ||
@@ -7,0 +15,0 @@ |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -25,19 +24,14 @@ var __defProp = Object.defineProperty; | ||
module.exports = __toCommonJS(BlazeDependency_exports); | ||
var import_BlazeError = require("../errors/BlazeError"); | ||
var import_common = require("../utils/common"); | ||
var import_constant = require("../utils/constant"); | ||
class BlazeDependency { | ||
$runTime; | ||
$nodeAdapter; | ||
moduleExist; | ||
modules; | ||
constructor() { | ||
const node = this.loadNodeAdapter(); | ||
this.$nodeAdapter = node.adapter; | ||
this.moduleExist = { | ||
"node-adapter": node.isExist | ||
this.modules = { | ||
[import_constant.ExternalModule.NodeAdapter]: this.loadNodeAdapter(), | ||
[import_constant.ExternalModule.ZodApi]: this.loadZodApi() | ||
}; | ||
this.$runTime = this.getRunTime(); | ||
} | ||
load(pkg) { | ||
return (0, import_common.crossRequire)(pkg); | ||
} | ||
getRunTime() { | ||
@@ -50,18 +44,13 @@ if (process.versions.node) | ||
try { | ||
return { | ||
isExist: true, | ||
adapter: this.load("@hono/node-server") | ||
}; | ||
return (0, import_common.crossRequire)(import_constant.ExternalModule.NodeAdapter); | ||
} catch { | ||
return { | ||
isExist: false, | ||
adapter: null | ||
}; | ||
return null; | ||
} | ||
} | ||
get nodeAdapter() { | ||
if (!this.$nodeAdapter) { | ||
throw new import_BlazeError.BlazeError("Node Adapter is not installed"); | ||
loadZodApi() { | ||
try { | ||
return (0, import_common.crossRequire)(import_constant.ExternalModule.ZodApi); | ||
} catch { | ||
return null; | ||
} | ||
return this.$nodeAdapter; | ||
} | ||
@@ -68,0 +57,0 @@ get runTime() { |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __create = Object.create; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -29,2 +28,3 @@ var __defProp = Object.defineProperty; | ||
module.exports = __toCommonJS(src_exports); | ||
var import_validator = require("./types/validator"); | ||
var import_creator = require("./creator"); | ||
@@ -31,0 +31,0 @@ var import_BlazeError = require("./errors/BlazeError"); |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -40,2 +39,3 @@ var __create = Object.create; | ||
var import_common = require("../utils/common"); | ||
var import_constant = require("../utils/constant"); | ||
var import_service2 = require("../utils/setup/service"); | ||
@@ -49,2 +49,3 @@ var import_BlazeRouter = require("./BlazeRouter"); | ||
blazeCtx; | ||
adapter; | ||
fetch; | ||
@@ -63,2 +64,3 @@ constructor(options) { | ||
}); | ||
this.adapter = import_config.BlazeDependency.modules[import_constant.ExternalModule.NodeAdapter]; | ||
this.fetch = this.router.fetch.bind(this.router); | ||
@@ -125,4 +127,4 @@ if (options.path) { | ||
const args = this.getServeConfig(port, listener); | ||
if (import_config.BlazeDependency.runTime === "node" && import_config.BlazeDependency.moduleExist["node-adapter"]) { | ||
import_config.BlazeDependency.nodeAdapter.serve(...args); | ||
if (import_config.BlazeDependency.runTime === "node" && this.adapter) { | ||
this.adapter.serve(...args); | ||
} | ||
@@ -129,0 +131,0 @@ if ((0, import_common.isNil)(listener)) { |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -25,10 +24,19 @@ var __defProp = Object.defineProperty; | ||
module.exports = __toCommonJS(BlazeRouter_exports); | ||
var import_zod_to_openapi = require("@asteasolutions/zod-to-openapi"); | ||
var import_hono = require("hono"); | ||
var import_config = require("../config"); | ||
var import_BlazeError = require("../errors/BlazeError"); | ||
var import_Logger = require("../errors/Logger"); | ||
var import_constant = require("../utils/constant"); | ||
var import_router = require("../utils/helper/router"); | ||
class BlazeRouter extends import_hono.Hono { | ||
openAPIRegistry; | ||
zodApi; | ||
constructor(options) { | ||
super({ strict: false, router: options.router }); | ||
this.openAPIRegistry = new import_zod_to_openapi.OpenAPIRegistry(); | ||
this.zodApi = import_config.BlazeDependency.modules[import_constant.ExternalModule.ZodApi]; | ||
if (!this.zodApi) { | ||
this.openAPIRegistry = null; | ||
return; | ||
} | ||
this.openAPIRegistry = new this.zodApi.OpenAPIRegistry(); | ||
} | ||
@@ -42,7 +50,17 @@ openapi(route) { | ||
}; | ||
this.on(route.method, route.path, route.handler); | ||
if (!this.openAPIRegistry) { | ||
import_Logger.Logger.warn(`Please install "${import_constant.ExternalModule.ZodApi}" to use OpenAPI.`); | ||
return; | ||
} | ||
this.openAPIRegistry.registerPath(newRoute); | ||
this.on(route.method, route.path, route.handler); | ||
} | ||
getOpenAPIDocument(config) { | ||
const generator = new import_zod_to_openapi.OpenApiGeneratorV3(this.openAPIRegistry.definitions); | ||
if (!this.zodApi || !this.openAPIRegistry) { | ||
import_Logger.Logger.error(`${import_constant.ExternalModule.ZodApi} is not installed`); | ||
throw new import_BlazeError.BlazeError(`${import_constant.ExternalModule.ZodApi} is not installed`); | ||
} | ||
const generator = new this.zodApi.OpenApiGeneratorV3( | ||
this.openAPIRegistry.definitions | ||
); | ||
const document = generator.generateDocument(config); | ||
@@ -52,3 +70,9 @@ return document; | ||
getOpenAPI31Document(config) { | ||
const generator = new import_zod_to_openapi.OpenApiGeneratorV31(this.openAPIRegistry.definitions); | ||
if (!this.zodApi || !this.openAPIRegistry) { | ||
import_Logger.Logger.error(`${import_constant.ExternalModule.ZodApi} is not installed`); | ||
throw new import_BlazeError.BlazeError(`${import_constant.ExternalModule.ZodApi} is not installed`); | ||
} | ||
const generator = new this.zodApi.OpenApiGeneratorV31( | ||
this.openAPIRegistry.definitions | ||
); | ||
const document = generator.generateDocument(config); | ||
@@ -87,3 +111,3 @@ return document; | ||
super.route(path, app); | ||
if (!(app instanceof BlazeRouter)) { | ||
if (!(app instanceof BlazeRouter) || !app.openAPIRegistry) { | ||
return this; | ||
@@ -90,0 +114,0 @@ } |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -25,5 +24,16 @@ var __defProp = Object.defineProperty; | ||
module.exports = __toCommonJS(validator_exports); | ||
var import_zod_to_openapi = require("@asteasolutions/zod-to-openapi"); | ||
var import_zod = require("zod"); | ||
(0, import_zod_to_openapi.extendZodWithOpenApi)(import_zod.z); | ||
var import_config = require("../config"); | ||
var import_BlazeError = require("../errors/BlazeError"); | ||
var import_Logger = require("../errors/Logger"); | ||
var import_constant = require("../utils/constant"); | ||
const zodApi = import_config.BlazeDependency.modules[import_constant.ExternalModule.ZodApi]; | ||
if (zodApi) { | ||
zodApi.extendZodWithOpenApi(import_zod.z); | ||
} else { | ||
import_zod.z.ZodType.prototype.openapi = () => { | ||
import_Logger.Logger.error(`${import_constant.ExternalModule.ZodApi} is not installed`); | ||
throw new import_BlazeError.BlazeError(`${import_constant.ExternalModule.ZodApi} is not installed`); | ||
}; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -30,0 +40,0 @@ 0 && (module.exports = { |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,3 +0,2 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
var import_router = require("hono/router"); |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,6 +0,7 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
@@ -19,2 +20,10 @@ var __export = (target, all) => { | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
@@ -29,2 +38,3 @@ var common_exports = {}; | ||
isNil: () => isNil, | ||
isOnCjs: () => isOnCjs, | ||
loadFile: () => loadFile, | ||
@@ -37,3 +47,6 @@ mapToObject: () => mapToObject, | ||
module.exports = __toCommonJS(common_exports); | ||
var import_node_fs = __toESM(require("node:fs"), 1); | ||
var import_node_module = require("node:module"); | ||
var import_node_path = __toESM(require("node:path"), 1); | ||
var import_BlazeError = require("../errors/BlazeError"); | ||
var import_event = require("../event"); | ||
@@ -53,4 +66,4 @@ const import_meta = {}; | ||
} | ||
function removeTrailingSlash(path) { | ||
return path.replace(/^\/+/, ""); | ||
function removeTrailingSlash(path2) { | ||
return path2.replace(/^\/+/, ""); | ||
} | ||
@@ -94,10 +107,28 @@ function getRestPath(service) { | ||
} | ||
function isOnCjs() { | ||
return typeof module !== "undefined" && typeof exports !== "undefined"; | ||
} | ||
function loadFile(id) { | ||
if (IS_CJS) { | ||
if (isOnCjs()) { | ||
return require(id); | ||
} | ||
if (!import_node_fs.default.existsSync(id)) { | ||
throw new import_BlazeError.BlazeError(`${id} doesn't exist`); | ||
} | ||
if (import_node_fs.default.statSync(id).isDirectory()) { | ||
const infos = import_node_fs.default.readdirSync(id); | ||
const index = infos.find( | ||
(info) => info.match(/index\.[jt]s$|index.[cm][jt]s$/) | ||
); | ||
if (!index) { | ||
throw new import_BlazeError.BlazeError( | ||
`No index file found in directory ${id} (expected to find index.[jt]s or index.[cm][jt]s)` | ||
); | ||
} | ||
return import(import_node_path.default.join(id, index)); | ||
} | ||
return import(id); | ||
} | ||
function crossRequire(id) { | ||
if (IS_CJS) { | ||
if (isOnCjs()) { | ||
return require(id); | ||
@@ -116,2 +147,3 @@ } | ||
isNil, | ||
isOnCjs, | ||
loadFile, | ||
@@ -118,0 +150,0 @@ mapToObject, |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -22,2 +21,3 @@ var __defProp = Object.defineProperty; | ||
__export(constant_exports, { | ||
ExternalModule: () => ExternalModule, | ||
FORM_CONTENT_TYPE: () => FORM_CONTENT_TYPE, | ||
@@ -48,4 +48,10 @@ RESERVED_KEYWORD: () => RESERVED_KEYWORD, | ||
]; | ||
var ExternalModule = /* @__PURE__ */ ((ExternalModule2) => { | ||
ExternalModule2["NodeAdapter"] = "@hono/node-server"; | ||
ExternalModule2["ZodApi"] = "@asteasolutions/zod-to-openapi"; | ||
return ExternalModule2; | ||
})(ExternalModule || {}); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
ExternalModule, | ||
FORM_CONTENT_TYPE, | ||
@@ -52,0 +58,0 @@ RESERVED_KEYWORD, |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -27,2 +26,4 @@ var __defProp = Object.defineProperty; | ||
function assignOpenAPIRegistry(router, docPath, def) { | ||
if (!router.openAPIRegistry) | ||
return; | ||
switch (def.type) { | ||
@@ -29,0 +30,0 @@ case "component": |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __create = Object.create; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __defProp = Object.defineProperty; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = true | ||
"use strict"; | ||
@@ -3,0 +2,0 @@ var __create = Object.create; |
@@ -1,21 +0,14 @@ | ||
const IS_CJS = false | ||
// src/config/BlazeDependency.ts | ||
import { BlazeError } from "../errors/BlazeError.js"; | ||
import { crossRequire } from "../utils/common.js"; | ||
import { ExternalModule } from "../utils/constant.js"; | ||
var BlazeDependency = class { | ||
$runTime; | ||
$nodeAdapter; | ||
moduleExist; | ||
modules; | ||
constructor() { | ||
const node = this.loadNodeAdapter(); | ||
this.$nodeAdapter = node.adapter; | ||
this.moduleExist = { | ||
"node-adapter": node.isExist | ||
this.modules = { | ||
[ExternalModule.NodeAdapter]: this.loadNodeAdapter(), | ||
[ExternalModule.ZodApi]: this.loadZodApi() | ||
}; | ||
this.$runTime = this.getRunTime(); | ||
} | ||
load(pkg) { | ||
return crossRequire(pkg); | ||
} | ||
getRunTime() { | ||
@@ -28,18 +21,13 @@ if (process.versions.node) | ||
try { | ||
return { | ||
isExist: true, | ||
adapter: this.load("@hono/node-server") | ||
}; | ||
return crossRequire(ExternalModule.NodeAdapter); | ||
} catch { | ||
return { | ||
isExist: false, | ||
adapter: null | ||
}; | ||
return null; | ||
} | ||
} | ||
get nodeAdapter() { | ||
if (!this.$nodeAdapter) { | ||
throw new BlazeError("Node Adapter is not installed"); | ||
loadZodApi() { | ||
try { | ||
return crossRequire(ExternalModule.ZodApi); | ||
} catch { | ||
return null; | ||
} | ||
return this.$nodeAdapter; | ||
} | ||
@@ -46,0 +34,0 @@ get runTime() { |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/config/index.ts | ||
@@ -4,0 +2,0 @@ import { BlazeDependency as Depedency } from "./BlazeDependency.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/creator/action.ts | ||
@@ -4,0 +2,0 @@ function createActionValidator(validator) { |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/creator/event.ts | ||
@@ -4,0 +2,0 @@ function createEventValidator(validator) { |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/creator/hooks.ts | ||
@@ -4,0 +2,0 @@ function createAfterHook(hook) { |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/creator/index.ts | ||
@@ -4,0 +2,0 @@ import { createAction, createActionValidator } from "./action.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/creator/openapi.ts | ||
@@ -4,0 +2,0 @@ function createActionOpenAPI(openapi) { |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/creator/service.ts | ||
@@ -4,0 +2,0 @@ function createService(service) { |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/errors/BlazeError.ts | ||
@@ -4,0 +2,0 @@ var BlazeError = class extends Error { |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/event/BlazeBroker.ts | ||
@@ -4,0 +2,0 @@ import { BlazeEvent } from "./index.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/event/BlazeContext.ts | ||
@@ -4,0 +2,0 @@ import qs from "node:querystring"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/event/BlazeEventEmitter.ts | ||
@@ -4,0 +2,0 @@ var BlazeEventEmitter = class { |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/event/index.ts | ||
@@ -4,0 +2,0 @@ import { BlazeBroker as Broker } from "./BlazeBroker.js"; |
@@ -1,4 +0,3 @@ | ||
const IS_CJS = false | ||
// src/index.ts | ||
import "./types/validator.js"; | ||
import { BlazeCreator } from "./creator/index.js"; | ||
@@ -5,0 +4,0 @@ import { BlazeError } from "./errors/BlazeError.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/router/Blaze.ts | ||
@@ -9,2 +7,3 @@ import fs from "node:fs"; | ||
import { isNil } from "../utils/common.js"; | ||
import { ExternalModule } from "../utils/constant.js"; | ||
import { BlazeService } from "../utils/setup/service.js"; | ||
@@ -18,2 +17,3 @@ import { BlazeRouter } from "./BlazeRouter.js"; | ||
blazeCtx; | ||
adapter; | ||
fetch; | ||
@@ -32,2 +32,3 @@ constructor(options) { | ||
}); | ||
this.adapter = BlazeDependency.modules[ExternalModule.NodeAdapter]; | ||
this.fetch = this.router.fetch.bind(this.router); | ||
@@ -94,4 +95,4 @@ if (options.path) { | ||
const args = this.getServeConfig(port, listener); | ||
if (BlazeDependency.runTime === "node" && BlazeDependency.moduleExist["node-adapter"]) { | ||
BlazeDependency.nodeAdapter.serve(...args); | ||
if (BlazeDependency.runTime === "node" && this.adapter) { | ||
this.adapter.serve(...args); | ||
} | ||
@@ -98,0 +99,0 @@ if (isNil(listener)) { |
@@ -1,16 +0,19 @@ | ||
const IS_CJS = false | ||
// src/router/BlazeRouter.ts | ||
import { | ||
OpenAPIRegistry, | ||
OpenApiGeneratorV3, | ||
OpenApiGeneratorV31 | ||
} from "@asteasolutions/zod-to-openapi"; | ||
import { Hono } from "hono"; | ||
import { BlazeDependency } from "../config/index.js"; | ||
import { BlazeError } from "../errors/BlazeError.js"; | ||
import { Logger } from "../errors/Logger.js"; | ||
import { ExternalModule } from "../utils/constant.js"; | ||
import { assignOpenAPIRegistry } from "../utils/helper/router.js"; | ||
var BlazeRouter = class _BlazeRouter extends Hono { | ||
openAPIRegistry; | ||
zodApi; | ||
constructor(options) { | ||
super({ strict: false, router: options.router }); | ||
this.openAPIRegistry = new OpenAPIRegistry(); | ||
this.zodApi = BlazeDependency.modules[ExternalModule.ZodApi]; | ||
if (!this.zodApi) { | ||
this.openAPIRegistry = null; | ||
return; | ||
} | ||
this.openAPIRegistry = new this.zodApi.OpenAPIRegistry(); | ||
} | ||
@@ -24,7 +27,17 @@ openapi(route) { | ||
}; | ||
this.on(route.method, route.path, route.handler); | ||
if (!this.openAPIRegistry) { | ||
Logger.warn(`Please install "${ExternalModule.ZodApi}" to use OpenAPI.`); | ||
return; | ||
} | ||
this.openAPIRegistry.registerPath(newRoute); | ||
this.on(route.method, route.path, route.handler); | ||
} | ||
getOpenAPIDocument(config) { | ||
const generator = new OpenApiGeneratorV3(this.openAPIRegistry.definitions); | ||
if (!this.zodApi || !this.openAPIRegistry) { | ||
Logger.error(`${ExternalModule.ZodApi} is not installed`); | ||
throw new BlazeError(`${ExternalModule.ZodApi} is not installed`); | ||
} | ||
const generator = new this.zodApi.OpenApiGeneratorV3( | ||
this.openAPIRegistry.definitions | ||
); | ||
const document = generator.generateDocument(config); | ||
@@ -34,3 +47,9 @@ return document; | ||
getOpenAPI31Document(config) { | ||
const generator = new OpenApiGeneratorV31(this.openAPIRegistry.definitions); | ||
if (!this.zodApi || !this.openAPIRegistry) { | ||
Logger.error(`${ExternalModule.ZodApi} is not installed`); | ||
throw new BlazeError(`${ExternalModule.ZodApi} is not installed`); | ||
} | ||
const generator = new this.zodApi.OpenApiGeneratorV31( | ||
this.openAPIRegistry.definitions | ||
); | ||
const document = generator.generateDocument(config); | ||
@@ -69,3 +88,3 @@ return document; | ||
super.route(path, app); | ||
if (!(app instanceof _BlazeRouter)) { | ||
if (!(app instanceof _BlazeRouter) || !app.openAPIRegistry) { | ||
return this; | ||
@@ -72,0 +91,0 @@ } |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/router/index.ts | ||
@@ -4,0 +2,0 @@ import { Blaze } from "./Blaze.js"; |
@@ -1,9 +0,18 @@ | ||
const IS_CJS = false | ||
// src/router/validator.ts | ||
import { extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi"; | ||
import { z } from "zod"; | ||
extendZodWithOpenApi(z); | ||
import { BlazeDependency } from "../config/index.js"; | ||
import { BlazeError } from "../errors/BlazeError.js"; | ||
import { Logger } from "../errors/Logger.js"; | ||
import { ExternalModule } from "../utils/constant.js"; | ||
var zodApi = BlazeDependency.modules[ExternalModule.ZodApi]; | ||
if (zodApi) { | ||
zodApi.extendZodWithOpenApi(z); | ||
} else { | ||
z.ZodType.prototype.openapi = () => { | ||
Logger.error(`${ExternalModule.ZodApi} is not installed`); | ||
throw new BlazeError(`${ExternalModule.ZodApi} is not installed`); | ||
}; | ||
} | ||
export { | ||
z | ||
}; |
@@ -1,4 +0,2 @@ | ||
const IS_CJS = false | ||
// src/types/hono.ts | ||
import "hono/router"; |
@@ -1,2 +0,1 @@ | ||
const IS_CJS = false | ||
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { | ||
@@ -11,3 +10,6 @@ get: (a, b) => (typeof require !== "undefined" ? require : a)[b] | ||
// src/utils/common.ts | ||
import fs from "node:fs"; | ||
import { createRequire } from "node:module"; | ||
import path from "node:path"; | ||
import { BlazeError } from "../errors/BlazeError.js"; | ||
import { BlazeContext } from "../event/index.js"; | ||
@@ -26,4 +28,4 @@ function hasOwnProperty(obj, property) { | ||
} | ||
function removeTrailingSlash(path) { | ||
return path.replace(/^\/+/, ""); | ||
function removeTrailingSlash(path2) { | ||
return path2.replace(/^\/+/, ""); | ||
} | ||
@@ -67,10 +69,28 @@ function getRestPath(service) { | ||
} | ||
function isOnCjs() { | ||
return typeof module !== "undefined" && typeof exports !== "undefined"; | ||
} | ||
function loadFile(id) { | ||
if (IS_CJS) { | ||
if (isOnCjs()) { | ||
return __require(id); | ||
} | ||
if (!fs.existsSync(id)) { | ||
throw new BlazeError(`${id} doesn't exist`); | ||
} | ||
if (fs.statSync(id).isDirectory()) { | ||
const infos = fs.readdirSync(id); | ||
const index = infos.find( | ||
(info) => info.match(/index\.[jt]s$|index.[cm][jt]s$/) | ||
); | ||
if (!index) { | ||
throw new BlazeError( | ||
`No index file found in directory ${id} (expected to find index.[jt]s or index.[cm][jt]s)` | ||
); | ||
} | ||
return import(path.join(id, index)); | ||
} | ||
return import(id); | ||
} | ||
function crossRequire(id) { | ||
if (IS_CJS) { | ||
if (isOnCjs()) { | ||
return __require(id); | ||
@@ -88,2 +108,3 @@ } | ||
isNil, | ||
isOnCjs, | ||
loadFile, | ||
@@ -90,0 +111,0 @@ mapToObject, |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/constant.ts | ||
@@ -24,3 +22,9 @@ var RESERVED_KEYWORD = { | ||
]; | ||
var ExternalModule = /* @__PURE__ */ ((ExternalModule2) => { | ||
ExternalModule2["NodeAdapter"] = "@hono/node-server"; | ||
ExternalModule2["ZodApi"] = "@asteasolutions/zod-to-openapi"; | ||
return ExternalModule2; | ||
})(ExternalModule || {}); | ||
export { | ||
ExternalModule, | ||
FORM_CONTENT_TYPE, | ||
@@ -27,0 +31,0 @@ RESERVED_KEYWORD, |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/helper/context.ts | ||
@@ -4,0 +2,0 @@ import { FORM_CONTENT_TYPE, REST_CONTENT_TYPE } from "../constant.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/helper/handler.ts | ||
@@ -4,0 +2,0 @@ import { resolvePromise } from "../common.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/helper/hooks.ts | ||
@@ -4,0 +2,0 @@ import { resolvePromise, toArray } from "../common.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/helper/rest.ts | ||
@@ -4,0 +2,0 @@ import { BlazeError } from "../../errors/BlazeError.js"; |
@@ -1,6 +0,6 @@ | ||
const IS_CJS = false | ||
// src/utils/helper/router.ts | ||
import { mergePath } from "hono/utils/url"; | ||
function assignOpenAPIRegistry(router, docPath, def) { | ||
if (!router.openAPIRegistry) | ||
return; | ||
switch (def.type) { | ||
@@ -7,0 +7,0 @@ case "component": |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/helper/service.ts | ||
@@ -4,0 +2,0 @@ import { hasOwnProperty, loadFile } from "../common.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/helper/validator.ts | ||
@@ -4,0 +2,0 @@ import { BlazeError } from "../../errors/BlazeError.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/setup.ts | ||
@@ -4,0 +2,0 @@ import fs from "node:fs"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/setup/action.ts | ||
@@ -4,0 +2,0 @@ import { BlazeEvent } from "../../event/index.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/setup/event.ts | ||
@@ -4,0 +2,0 @@ import { BlazeEvent } from "../../event/index.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/setup/rest.ts | ||
@@ -4,0 +2,0 @@ import { BlazeError } from "../../errors/BlazeError.js"; |
@@ -1,3 +0,1 @@ | ||
const IS_CJS = false | ||
// src/utils/setup/service.ts | ||
@@ -4,0 +2,0 @@ import path from "node:path"; |
@@ -0,11 +1,10 @@ | ||
import { DependencyModule } from '../types/config'; | ||
export declare class BlazeDependency { | ||
private $runTime; | ||
private $nodeAdapter; | ||
readonly moduleExist: Record<'node-adapter', boolean>; | ||
private readonly $runTime; | ||
readonly modules: DependencyModule; | ||
constructor(); | ||
load<T>(pkg: string): T; | ||
private getRunTime; | ||
private loadNodeAdapter; | ||
get nodeAdapter(): typeof import("@hono/node-server"); | ||
private loadZodApi; | ||
get runTime(): "node" | "other"; | ||
} |
@@ -0,1 +1,2 @@ | ||
import './types/validator'; | ||
export type { Action, ActionHandler, ActionOpenAPI, ActionValidator, Actions, OpenAPIBody, } from './types/action'; | ||
@@ -2,0 +3,0 @@ export type { ActionCallRecord, ActionEventCallRequest, EventCallRecord, ExtractActionHandler, ExtractActionValidator, ExtractEventValidator, } from './types/common'; |
@@ -13,2 +13,3 @@ /// <reference types="node" /> | ||
private readonly blazeCtx; | ||
private readonly adapter; | ||
readonly fetch: BlazeFetch; | ||
@@ -15,0 +16,0 @@ constructor(options: CreateBlazeOption); |
@@ -1,2 +0,2 @@ | ||
import { OpenAPIRegistry, OpenApiGeneratorV3, OpenApiGeneratorV31 } from '@asteasolutions/zod-to-openapi'; | ||
import type { OpenAPIRegistry, OpenApiGeneratorV3, OpenApiGeneratorV31 } from '@asteasolutions/zod-to-openapi'; | ||
import type { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator'; | ||
@@ -8,3 +8,4 @@ import type { Env, Schema } from 'hono'; | ||
export declare class BlazeRouter<E extends Env = Env, S extends Schema = NonNullable<unknown>, BasePath extends string = '/'> extends Hono<E, S, BasePath> { | ||
readonly openAPIRegistry: OpenAPIRegistry; | ||
readonly openAPIRegistry: OpenAPIRegistry | null; | ||
private zodApi; | ||
constructor(options: CreateBlazeOption); | ||
@@ -11,0 +12,0 @@ openapi(route: BlazeOpenAPIOption): void; |
@@ -15,3 +15,4 @@ import { BlazeContext } from '../event'; | ||
export declare function createContext(options: CreateContextOption): Promise<ActionCallResult<BlazeContext>>; | ||
export declare function loadFile(id: string): Promise<Random>; | ||
export declare function crossRequire(id: string): Promise<Random>; | ||
export declare function isOnCjs(): boolean; | ||
export declare function loadFile<T = Random>(id: string): Promise<T>; | ||
export declare function crossRequire<T = Random>(id: string): T; |
@@ -18,1 +18,5 @@ export declare const RESERVED_KEYWORD: { | ||
export declare const FORM_CONTENT_TYPE: readonly ["application/x-www-form-urlencoded", "multipart/form-data"]; | ||
export declare enum ExternalModule { | ||
NodeAdapter = "@hono/node-server", | ||
ZodApi = "@asteasolutions/zod-to-openapi" | ||
} |
import type { LoadServiceOption } from '../types/service'; | ||
/** | ||
* Load all the services from the given path | ||
* @deprecated use Blaze.load instead | ||
*/ | ||
export declare function initializeServices(options: LoadServiceOption): Promise<void>; |
@@ -7,5 +7,6 @@ { | ||
"type": "module", | ||
"version": "3.0.0-3", | ||
"version": "3.0.0", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@asteasolutions/zod-to-openapi": "^6.3.1", | ||
"@commitlint/cli": "^17.8.1", | ||
@@ -18,3 +19,2 @@ "@commitlint/config-conventional": "^17.8.1", | ||
"@typescript-eslint/parser": "^6.21.0", | ||
"arg": "^5.0.2", | ||
"commit-and-tag-version": "^12.2.0", | ||
@@ -40,3 +40,2 @@ "esbuild": "^0.20.1", | ||
"dependencies": { | ||
"@asteasolutions/zod-to-openapi": "^6.3.1", | ||
"hono": "^4.0.5", | ||
@@ -43,0 +42,0 @@ "zod": "^3.22.4" |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
190907
2
150
4922
1
- Removed@asteasolutions/zod-to-openapi@6.4.0(transitive)
- Removedopenapi3-ts@4.4.0(transitive)
- Removedyaml@2.5.1(transitive)