From c36e9374d2908d2e3f9832fc0b6baef6961e791f Mon Sep 17 00:00:00 2001 From: chizukicn Date: Wed, 28 Jun 2023 12:37:33 +0800 Subject: [PATCH] fix(swagger): mismatch docs api. --- bench/unit/path.ts | 6 +- package.json | 6 +- packages/core/src/app.ts | 50 +++--- packages/core/src/logger.ts | 2 +- packages/core/src/shared/request.ts | 14 +- packages/core/src/shared/route.ts | 6 +- packages/core/src/utils/path.ts | 73 ++------ packages/core/test/utils/faker.test.ts | 3 + packages/core/test/utils/path.test.ts | 32 ++-- .../swagger-middleware/build.config.ts | 18 ++ .../swagger-middleware/package.json | 27 +++ .../swagger-middleware/src}/index.ts | 5 +- .../swagger-middleware/src/test.json | 122 +++++++++++++ .../swagger-middleware/src}/types.ts | 1 + packages/integrations/swagger/package.json | 2 +- packages/integrations/swagger/src/build.ts | 30 ++-- packages/integrations/swagger/src/index.ts | 2 +- packages/integrations/swagger/src/service.ts | 17 +- packages/integrations/swagger/src/ui.ts | 12 +- .../integrations/swagger/test/swagger.test.ts | 4 +- packages/integrations/unplugin/src/index.ts | 31 ++-- packages/middlewares/src/index.ts | 3 +- packages/middlewares/src/middlewares/index.ts | 1 - packages/mock/test/hooks.test.ts | 6 +- packages/server/src/utils.ts | 6 +- packages/server/test/server.test.ts | 4 +- playgrounds/vite/src/app.vue | 2 +- playgrounds/vite/vite.config.ts | 4 +- pnpm-lock.yaml | 164 ++++++++++-------- tsconfig.json | 5 +- 30 files changed, 405 insertions(+), 253 deletions(-) create mode 100644 packages/integrations/swagger-middleware/build.config.ts create mode 100644 packages/integrations/swagger-middleware/package.json rename packages/{middlewares/src/middlewares/swagger => integrations/swagger-middleware/src}/index.ts (97%) create mode 100644 packages/integrations/swagger-middleware/src/test.json rename packages/{middlewares/src/middlewares/swagger => integrations/swagger-middleware/src}/types.ts (98%) diff --git a/bench/unit/path.ts b/bench/unit/path.ts index d223cd60..877604e1 100644 --- a/bench/unit/path.ts +++ b/bench/unit/path.ts @@ -1,14 +1,14 @@ -import { relativePath, slash } from "@fourze/core"; +import { normalizeURL, withoutBase } from "@fourze/core"; import { suite } from "../lib/suite"; // const source = new Array(100).fill(0).map((_, i) => i); suite("relativePath", 100000, () => { - relativePath("/api/abc", "/api"); + withoutBase("/api/abc", "/api"); }); suite("replace", 100000, () => { const a = "/api/abc"; const b = "/api"; - slash((a.replace(b, ""))); + normalizeURL((a.replace(b, ""))); }); diff --git a/package.json b/package.json index 53ff3d72..9486d6d5 100644 --- a/package.json +++ b/package.json @@ -52,8 +52,8 @@ "@fourze/swagger": "workspace:*", "@types/fs-extra": "^11.0.1", "@types/node": "^18.16.18", - "@vitest/coverage-v8": "^0.32.0", - "@vitest/ui": "^0.32.0", + "@vitest/coverage-v8": "^0.32.2", + "@vitest/ui": "^0.32.2", "autocannon": "^7.11.0", "bumpp": "^9.1.1", "chokidar": "^3.5.3", @@ -67,6 +67,6 @@ "tsx": "^3.12.7", "typescript": "^5.1.0", "unbuild": "^1.2.1", - "vitest": "^0.32.0" + "vitest": "^0.32.2" } } diff --git a/packages/core/src/app.ts b/packages/core/src/app.ts index 965d6499..9822bd63 100644 --- a/packages/core/src/app.ts +++ b/packages/core/src/app.ts @@ -1,4 +1,5 @@ import type { MaybePromise, MaybeRegex } from "maybe-types"; +import { withBase, withTrailingSlash, withoutBase, withoutTrailingSlash } from "ufo"; import { isArray, isFunction, isUndef } from "./utils/is"; import { createLogger } from "./logger"; import type { @@ -11,22 +12,20 @@ import type { FourzeNext, FourzePlugin } from "./shared"; +import { FOURZE_VERSION, createServiceContext } from "./shared"; import { - FOURZE_VERSION - , - createServiceContext -} from "./shared"; -import { - createSingletonPromise, deleteBy, isMatch, + createSingletonPromise, + deleteBy, + isMatch, isObject, isString, - relativePath, - resolves, restoreArray } from "./utils"; import { injectMeta } from "./shared/meta"; -export type FourzeAppSetup = (app: FourzeApp) => MaybePromise; +export type FourzeAppSetup = ( + app: FourzeApp +) => MaybePromise; export interface FourzeAppOptions { base?: string @@ -63,14 +62,16 @@ export function createApp(setup: FourzeAppSetup): FourzeApp; export function createApp(options: FourzeAppOptions): FourzeApp; -export function createApp(args: FourzeAppOptions | FourzeAppSetup = {}): FourzeApp { +export function createApp( + args: FourzeAppOptions | FourzeAppSetup = {} +): FourzeApp { const isSetup = isFunction(args); const isRoutes = Array.isArray(args); const isOptions = !isSetup && !isRoutes && isObject(args); const logger = createLogger("@fourze/core"); const options = isOptions ? args : {}; - const setup = isSetup ? args : options.setup ?? (() => { }); + const setup = isSetup ? args : options.setup ?? (() => {}); const { fallback } = options; @@ -105,14 +106,14 @@ export function createApp(args: FourzeAppOptions | FourzeAppSetup = {}): FourzeA const nextNode = ms.shift(); if (nextNode) { const [path, middleware] = nextNode; - const req = request.withScope(resolves(app.base, path)); + const req = request.withScope(withBase(path, app.base)); await middleware(req, response, doNext); } else { await next?.(); } } await doNext(); - // await response.done(); + // await response.done(); } else { await next?.(); } @@ -129,7 +130,7 @@ export function createApp(args: FourzeAppOptions | FourzeAppSetup = {}): FourzeA return middlewareStore .sort((a, b) => a.order - b.order) .filter((r) => isMatch(url, r.path)) - .map(r => [r.path, r.middleware] as [string, FourzeMiddleware]); + .map((r) => [r.path, r.middleware] as [string, FourzeMiddleware]); } return []; }; @@ -140,7 +141,7 @@ export function createApp(args: FourzeAppOptions | FourzeAppSetup = {}): FourzeA ) { const arg0 = args[0]; const isPath = isString(arg0); - const path = isPath ? arg0 : "/"; + const path = withoutTrailingSlash(isPath ? arg0 : "/"); const ms = (isPath ? args.slice(1) : args) as FourzeModule[]; for (let i = 0; i < ms.length; i++) { @@ -149,7 +150,11 @@ export function createApp(args: FourzeAppOptions | FourzeAppSetup = {}): FourzeA continue; } if (typeof middleware === "function") { - const node = { path, middleware, order: middleware.order ?? middlewareStore.length }; + const node = { + path, + middleware, + order: middleware.order ?? middlewareStore.length + }; if (!this.isReadying) { persistenceMiddlewareStore.push(node); } @@ -174,7 +179,11 @@ export function createApp(args: FourzeAppOptions | FourzeAppSetup = {}): FourzeA return this; }; - app.service = async function (this: FourzeApp, options: FourzeContextOptions, next?: FourzeHandle) { + app.service = async function ( + this: FourzeApp, + options: FourzeContextOptions, + next?: FourzeHandle + ) { const { request, response } = createServiceContext(options); await this(request, response, async () => { await next?.(request, response); @@ -225,6 +234,7 @@ export function createApp(args: FourzeAppOptions | FourzeAppSetup = {}): FourzeA } else if (setupReturn) { Object.assign(options, setupReturn); } + options.base = withTrailingSlash(options.base); } catch (e) { logger.error(e); } @@ -243,7 +253,7 @@ export function createApp(args: FourzeAppOptions | FourzeAppSetup = {}): FourzeA } // 装载插件 - const installPlugins = pluginStore.map(async r => { + const installPlugins = pluginStore.map(async (r) => { if (r.install) { try { await r.install(this); @@ -281,13 +291,13 @@ export function createApp(args: FourzeAppOptions | FourzeAppSetup = {}): FourzeA }; app.relative = function (url: string) { - return relativePath(url, this.base); + return withoutBase(url, this.base); }; Object.defineProperties(app, { middlewares: { get() { - return middlewareStore.map(r => r.middleware); + return middlewareStore.map((r) => r.middleware); }, enumerable: true }, diff --git a/packages/core/src/logger.ts b/packages/core/src/logger.ts index 4c4639d8..40f8819a 100644 --- a/packages/core/src/logger.ts +++ b/packages/core/src/logger.ts @@ -29,7 +29,7 @@ export type FourzeLogLevelKey = Uncapitalize; export type FourzeLogger = Consola; -let globalLoggerLevel: FourzeLogLevelKey | FourzeLogLevel = "info"; +let globalLoggerLevel: FourzeLogLevelKey | FourzeLogLevel = "fatal"; const loggerStore = new Map(); diff --git a/packages/core/src/shared/request.ts b/packages/core/src/shared/request.ts index 3c3ab002..4ad56012 100644 --- a/packages/core/src/shared/request.ts +++ b/packages/core/src/shared/request.ts @@ -2,10 +2,10 @@ import type { IncomingMessage } from "http"; import qs from "query-string"; import type { MaybeRegex } from "maybe-types"; import { safeParse } from "fast-content-type-parse"; -import { getQuery, parseURL } from "ufo"; +import { getQuery, parseURL, withoutBase } from "ufo"; import type { PolyfillHeaderInit } from "../polyfill"; import { decodeFormData, flatHeaders, getHeaderValue } from "../polyfill"; -import { isString, isUint8Array, memoize, parseJson, relativePath } from "../utils"; +import { isString, isUint8Array, parseJson } from "../utils"; import type { DefaultData, ExtractPropTypes, ExtractPropTypesWithIn, ObjectProps } from "./props"; import { validateProps, withDefaults } from "./props"; import type { FourzeRoute } from "./route"; @@ -35,6 +35,7 @@ export interface FourzeRequestOptions { body?: any params?: Record query?: Record + meta?: Record request?: IncomingMessage contentTypeParsers?: Map any> } @@ -90,7 +91,7 @@ export function createRequest(options: FourzeRequestOptions) { request.url = options.url ?? request.url; request.method = request.method ?? "GET"; - request.meta = {}; + request.meta = options.meta ?? {}; const headers = { ...flatHeaders(request.headers), @@ -162,12 +163,13 @@ export function createRequest(options: FourzeRequestOptions) { validateProps(route.props, data); }; - request.withScope = memoize((scope) => { + request.withScope = (scope) => { return createRequest({ ...options, - url: relativePath(request.url, scope) ?? request.url + meta: request.meta, + url: withoutBase(request.url, scope) ?? request.url }); - }); + }; Object.defineProperties(request, { [FOURZE_REQUEST_SYMBOL]: { diff --git a/packages/core/src/shared/route.ts b/packages/core/src/shared/route.ts index 67f31d5c..77645025 100644 --- a/packages/core/src/shared/route.ts +++ b/packages/core/src/shared/route.ts @@ -1,9 +1,9 @@ -import { resolves } from "../utils"; +import { withBase } from "../utils"; import type { DefaultData, ObjectProps } from "./props"; import type { RequestMethod } from "./request"; import { FOURZE_METHODS } from "./request"; import type { FourzeRouteMeta } from "./meta"; -import type { FourzeHandle } from "."; +import type { FourzeHandle } from "./interface"; const FOURZE_ROUTE_SYMBOL = Symbol("FourzeRoute"); @@ -76,7 +76,7 @@ export function defineRoute< } } - path = base ? resolves(base, path) : path; + path = base ? withBase(path, base) : path; return { method, diff --git a/packages/core/src/utils/path.ts b/packages/core/src/utils/path.ts index 1e168972..bef6d35f 100644 --- a/packages/core/src/utils/path.ts +++ b/packages/core/src/utils/path.ts @@ -1,75 +1,28 @@ -import minimatch from "minimatch"; import type { MaybeRegex } from "maybe-types"; -import { resolveURL } from "ufo"; +import { hasProtocol, isEmptyURL, isRelative, joinURL, normalizeURL, withLeadingSlash, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash } from "ufo"; +import minimatch from "minimatch"; import { isRegExp } from "./is"; -export function slash(...paths: string[]): string { - let path = paths - .map((p) => p.replace(/\\/g, "/")) - .join("/") - .replace(/\/+/g, "/"); - - if (path.length > 1 && path.endsWith("/")) { - path = path.slice(0, -1); - } - - if (!path.startsWith("/")) { - path = "/".concat(path); - } - - return path; -} - -export function relativePath(path: string, base?: string): string | null { - if (!hasProtocol(path)) { - if (base) { - if (base.endsWith("/")) { - base = base.slice(0, -1); - } - if (path.startsWith(base)) { - path = path.slice(base.length); - } else { - return null; - } - } - return path; - } - return null; -} - -const protocolReg = /^(\w+):\/\//i; - -export function hasProtocol(path: string) { - return protocolReg.test(path); -} - export function isMatch(path: string, ...pattern: MaybeRegex[]) { return pattern.some((r) => { if (isRegExp(r)) { return r.test(path); } - return path.startsWith(r) || minimatch(path, r, { matchBase: true, partial: true }); + + return path.startsWith(r) || minimatch(path, r, { matchBase: true }); }); } -/** - * 格式化路径 - * @param path - */ -export function normalize(path: string) { - if (!path.startsWith("/")) { - path = "/".concat(path); - } - path = path.replace(/\\/g, "/").replace(/\/+/g, "/"); - if (path.length > 1 && path.endsWith("/")) { - path = path.slice(0, -1); +export function withBase(input: string, base: string, trailingSlash = true) { + if (isEmptyURL(base) || hasProtocol(input)) { + return input; } - return path; -} + const _base = trailingSlash ? withTrailingSlash(base) : base; -export function resolves(...paths: string[]) { - if (paths.length === 0) { - return "/"; + if (input.startsWith(_base)) { + return input; } - return resolveURL(paths[0], ...paths.slice(1)); + return joinURL(_base, input); } + +export { withoutBase, normalizeURL, isEmptyURL, isRelative, joinURL, hasProtocol, withTrailingSlash, withoutTrailingSlash, withLeadingSlash, withoutLeadingSlash }; diff --git a/packages/core/test/utils/faker.test.ts b/packages/core/test/utils/faker.test.ts index d20ad2a9..0a55cab6 100644 --- a/packages/core/test/utils/faker.test.ts +++ b/packages/core/test/utils/faker.test.ts @@ -22,6 +22,9 @@ test("test-faker-object", () => { g: "{false}", h: "{null}", i: "{undefined}", + j: { + $type: "number" + }, tof: "{true|false}", num: "{100|200|300}", mixin: "{'a'|b|c}-{100-200|300-600|700-900}" diff --git a/packages/core/test/utils/path.test.ts b/packages/core/test/utils/path.test.ts index e68ecda0..c39a9956 100644 --- a/packages/core/test/utils/path.test.ts +++ b/packages/core/test/utils/path.test.ts @@ -1,18 +1,10 @@ import { expect, test } from "vitest"; import { isMatch, - relativePath, - resolves, - slash + withBase, + withoutBase } from "../../src/utils/path"; -test("test-slash", () => { - const path = "/hello/world/"; - const base = "/api/"; - expect(slash(base, path)).toBe("/api/hello/world"); - expect(slash("api/hello")).toBe("/api/hello"); -}); - test("test-isMatch", () => { expect(isMatch("/api/hello/test", "/api/*", "/api/hello")).toBe(true); }); @@ -22,18 +14,22 @@ test("test-relativePath", () => { const path2 = "/abc/def/ghi/"; const path3 = "/abc/"; const path4 = "/abc"; + const path5 = "/abc/abc.js"; const base = "/abc"; const normalBase = "/"; - expect(relativePath(path, base)).toBe("/def/ghi"); - expect(relativePath(path2, base)).toBe("/def/ghi/"); - expect(relativePath(path3, base)).toBe("/"); - expect(relativePath(path4, base)).toBe(""); - expect(relativePath(path, normalBase)).toBe("/abc/def/ghi"); + expect(withoutBase(path, base)).toBe("/def/ghi"); + expect(withoutBase(path2, base)).toBe("/def/ghi/"); + expect(withoutBase(path3, base)).toBe("/"); + expect(withoutBase(path4, base)).toBe("/"); + expect(withoutBase(path5, base)).toBe("/abc.js"); + expect(withoutBase(path, normalBase)).toBe("/abc/def/ghi"); }); test("test-resolvePath", () => { - const path = "https://test.com"; - const base = "/api"; - expect(resolves(path, base)).toBe("https://test.com/api"); + const base = "https://test.com"; + const path = "/api"; + expect(withBase(path, base)).toBe("https://test.com/api"); + + expect(withBase("/swagger-ui.css", "/swagger-ui/")).toBe("/swagger-ui/swagger-ui.css"); }); diff --git a/packages/integrations/swagger-middleware/build.config.ts b/packages/integrations/swagger-middleware/build.config.ts new file mode 100644 index 00000000..11858b09 --- /dev/null +++ b/packages/integrations/swagger-middleware/build.config.ts @@ -0,0 +1,18 @@ +import { defineBuildConfig } from "unbuild"; +import { devDependencies } from "./package.json"; + +const externals = [...Object.keys(devDependencies ?? {})]; + +export default defineBuildConfig({ + entries: ["src/index"], + clean: true, + declaration: true, + failOnWarn: false, + externals, + rollup: { + emitCJS: true, + dts: { + respectExternal: false + } + } +}); diff --git a/packages/integrations/swagger-middleware/package.json b/packages/integrations/swagger-middleware/package.json new file mode 100644 index 00000000..cb797bef --- /dev/null +++ b/packages/integrations/swagger-middleware/package.json @@ -0,0 +1,27 @@ +{ + "name": "@fourze/swagger-middleware", + "version": "0.28.1", + "description": "", + "main": "dist/index.cjs", + "module": "dist/index.mjs", + "types": "dist/index.d.ts", + "keywords": [ + "vite", + "mock", + "hmr" + ], + "files": [ + "dist/" + ], + "scripts": { + "build": "unbuild", + "stub": "unbuild --stub" + }, + "author": "chizuki", + "license": "MIT", + "dependencies": { + "@fourze/core": "workspace:*", + "maybe-types": "^0.0.3" + }, + "devDependencies": {} +} diff --git a/packages/middlewares/src/middlewares/swagger/index.ts b/packages/integrations/swagger-middleware/src/index.ts similarity index 97% rename from packages/middlewares/src/middlewares/swagger/index.ts rename to packages/integrations/swagger-middleware/src/index.ts index d64b8ed8..d54cafca 100644 --- a/packages/middlewares/src/middlewares/swagger/index.ts +++ b/packages/integrations/swagger-middleware/src/index.ts @@ -1,6 +1,5 @@ import type { FourzeApp, FourzeMiddleware, FourzeRouter, ObjectProps, PropType, RequestMethod } from "@fourze/core"; import { createQuery, isFunction, isRouter, normalizeProps } from "@fourze/core"; -import { RESOLVE_HEADER } from "../resolve"; import type { SwaggerOptions, SwaggerParameter, SwaggerPathSchema } from "./types"; function getParameterType(type: PropType): string | string[] { @@ -124,14 +123,14 @@ export function createSwaggerMiddleware( swagger: "2.0", info: options.info, host: options.host, - basePath: app.base, + basePath: options.basePath, schemes: options.schemas ?? ["http", "https"], consumes: options.consumes ?? ["application/json"], produces: options.produces ?? ["application/json"], paths: getPaths(), tags }; - res.setHeader(RESOLVE_HEADER, "off"); + res.setHeader("Fourze-Response-Resolve", "off"); res.send(docs, "application/json"); }; } diff --git a/packages/integrations/swagger-middleware/src/test.json b/packages/integrations/swagger-middleware/src/test.json new file mode 100644 index 00000000..ebcfefd2 --- /dev/null +++ b/packages/integrations/swagger-middleware/src/test.json @@ -0,0 +1,122 @@ +{ + "swagger": "2.0", + "schemes": ["http", "https"], + "consumes": ["application/json"], + "produces": ["application/json"], + "paths": { + "/test": { + "get": { + "summary": "测试", + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [ + { "in": "query", "name": "name", "type": "string", "required": true } + ], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_test" + } + }, + "/item/list": { + "get": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_item_list" + } + }, + "/item/{id}": { + "delete": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [ + { "in": "path", "name": "id", "type": "string", "required": true } + ], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_item_{id}" + }, + "get": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [ + { "in": "path", "name": "id", "type": "string", "required": true } + ], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_item_{id}" + } + }, + "/error": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_error" + }, + "/error-no-wrapper": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_error-no-wrapper" + }, + "/not-found": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_not-found" + }, + "/string-wrapper": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_string-wrapper" + }, + "/no-wrapper": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_no-wrapper" + }, + "/v1/health": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_v1_health" + }, + "/img/avatar.jpg": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_img_avatar.jpg" + }, + "/upload/avatar": { + "post": { + "tags": ["FourzeRouter@tbd48"], + "responses": {}, + "parameters": [ + { "in": "query", "name": "file", "type": "dr", "required": true } + ], + "produces": ["application/json"], + "consumes": ["application/json"], + "operationId": "_upload_avatar" + } + } + }, + "tags": { "source": [{ "name": "FourzeRouter@tbd48" }] } +} diff --git a/packages/middlewares/src/middlewares/swagger/types.ts b/packages/integrations/swagger-middleware/src/types.ts similarity index 98% rename from packages/middlewares/src/middlewares/swagger/types.ts rename to packages/integrations/swagger-middleware/src/types.ts index 5548f485..e8ddc7dd 100644 --- a/packages/middlewares/src/middlewares/swagger/types.ts +++ b/packages/integrations/swagger-middleware/src/types.ts @@ -61,4 +61,5 @@ export interface SwaggerOptions { consumes?: string[] produces?: string[] host?: string + basePath?: string } diff --git a/packages/integrations/swagger/package.json b/packages/integrations/swagger/package.json index 5c8a1f40..edb982ed 100644 --- a/packages/integrations/swagger/package.json +++ b/packages/integrations/swagger/package.json @@ -23,7 +23,7 @@ "@fourze/core": "workspace:*", "@fourze/mock": "workspace:*", "@fourze/server": "workspace:*", - "@fourze/middlewares": "workspace:*", + "@fourze/swagger-middleware": "workspace:*", "swagger-ui-dist": "^5.0.0", "fs-extra": "^11.1.1" }, diff --git a/packages/integrations/swagger/src/build.ts b/packages/integrations/swagger/src/build.ts index 73e56d8e..d38b2b15 100644 --- a/packages/integrations/swagger/src/build.ts +++ b/packages/integrations/swagger/src/build.ts @@ -4,9 +4,9 @@ import type { FourzeHmrApp } from "@fourze/server"; import type { InlineConfig } from "vite"; import { defineConfig, mergeConfig, build as viteBuild } from "vite"; import fs from "fs-extra"; -import { type RequestMethod, resolves } from "@fourze/core"; +import { withBase } from "@fourze/core"; import { createMockClient } from "@fourze/mock"; -import type { SwaggerOptions } from "@fourze/middlewares"; +import type { SwaggerOptions } from "@fourze/swagger-middleware"; import { getSwaggerFSPath } from "./service"; import { renderIndexHtml } from "./ui"; @@ -25,29 +25,23 @@ export interface SwaggerUIBuildOptions { */ distPath?: string - /** - * api的base - * @default "/" - */ - base?: string - assetsFilter?: (src: string) => boolean vite?: InlineConfig + swagger?: SwaggerOptions + /** * @default ".fourze-swagger" */ tmpDir?: string - defaultMethod?: RequestMethod - } function createMockDocsCode(options: SwaggerOptions = {}) { return ` import { defineRouter } from "@fourze/core"; - import { createSwaggerMiddleware } from "@fourze/middlewares"; + import { createSwaggerMiddleware } from "@fourze/swagger-middleware"; export default defineRouter((router,app) => { router.setMeta("swagger",false); router.get("/api-docs", createSwaggerMiddleware(app,${JSON.stringify(options)})); @@ -56,7 +50,7 @@ function createMockDocsCode(options: SwaggerOptions = {}) { } export function getModuleAlias() { - return ["@fourze/core", "@fourze/mock", "@fourze/swagger", "@fourze/middlewares"].map(r => { + return ["@fourze/core", "@fourze/mock", "@fourze/swagger", "@fourze/swagger-middleware"].map(r => { return { find: r, replacement: require.resolve(r) @@ -73,7 +67,7 @@ export async function build(app: FourzeHmrApp, options: SwaggerUIBuildOptions = // 固定加上swagger-ui的路径 const uiBase = options.vite?.base ?? "/"; - const apiBase = options.base ?? "/"; + const apiBase = options.swagger?.basePath ?? "/"; const uiPath = "/swagger-ui/"; @@ -82,7 +76,9 @@ export async function build(app: FourzeHmrApp, options: SwaggerUIBuildOptions = const mockDocsPath = path.join(tmpDir, "docs.ts"); await fs.outputFile(mockDocsPath, createMockDocsCode({ - defaultMethod: options.defaultMethod + defaultMethod: options.swagger?.defaultMethod, + basePath: apiBase, + ...options.swagger })); const moduleNames = app.moduleNames.concat(["./docs"]); @@ -91,8 +87,8 @@ export async function build(app: FourzeHmrApp, options: SwaggerUIBuildOptions = base: apiBase })); - await fs.outputFile(path.join(tmpDir, "index.html"), renderIndexHtml(resolves(uiBase, uiPath), { - url: resolves(apiBase, "/api-docs"), + await fs.outputFile(path.join(tmpDir, "index.html"), renderIndexHtml(withBase(uiPath, uiBase), { + url: withBase("/api-docs", apiBase), script: [ { src: "mock.ts", @@ -110,7 +106,7 @@ export async function build(app: FourzeHmrApp, options: SwaggerUIBuildOptions = // 打包接口文档 这里会有更好的方案吗??? await viteBuild(mergeConfig(options.vite ?? {}, defineConfig({ - base: resolves(uiBase, uiPath), + base: withBase(uiPath, uiBase), root: tmpDir, build: { outDir: path.join(distPath, uiPath), diff --git a/packages/integrations/swagger/src/index.ts b/packages/integrations/swagger/src/index.ts index fb6c66e8..4b6b829b 100644 --- a/packages/integrations/swagger/src/index.ts +++ b/packages/integrations/swagger/src/index.ts @@ -1,4 +1,4 @@ -export { createSwaggerMiddleware } from "@fourze/middlewares"; +export { createSwaggerMiddleware } from "@fourze/swagger-middleware"; export * from "./service"; diff --git a/packages/integrations/swagger/src/service.ts b/packages/integrations/swagger/src/service.ts index c430d68e..feea8f34 100644 --- a/packages/integrations/swagger/src/service.ts +++ b/packages/integrations/swagger/src/service.ts @@ -1,12 +1,13 @@ import type { FourzeApp, FourzeMiddleware } from "@fourze/core"; import { createApp } from "@fourze/core"; import { getAbsoluteFSPath } from "swagger-ui-dist"; -import { createSwaggerMiddleware } from "@fourze/middlewares"; -import type { SwaggerOptions } from "@fourze/middlewares"; +import { createSwaggerMiddleware } from "@fourze/swagger-middleware"; +import type { SwaggerOptions } from "@fourze/swagger-middleware"; +import { staticFile } from "@fourze/server"; import { renderIndexHtml } from "./ui"; export interface SwaggerUIServiceOptions extends SwaggerOptions { - base?: string + uiBase?: string documentPath?: string } @@ -15,13 +16,11 @@ export function service( app: FourzeApp, options: SwaggerUIServiceOptions = {} ): FourzeMiddleware { - const base = options.base ?? "/swagger-ui/"; + const uiBase = options.uiBase ?? "/swagger-ui/"; const documentPath = options.documentPath ?? "/api-docs"; const swaggerUISourcePath = getAbsoluteFSPath(); - const { staticFile } = require("@fourze/server") as typeof import("@fourze/server"); - const render = staticFile(swaggerUISourcePath, { maybes: [] }); @@ -32,15 +31,15 @@ export function service( const renderIndex: FourzeMiddleware = (req, res, next) => { if (req.path === "/" || req.path === "/index.html") { - res.send(renderIndexHtml(base), "text/html"); + res.send(renderIndexHtml(uiBase), "text/html"); } else { next?.(); } }; swaggerApp.use(documentPath, docsMiddleware); - swaggerApp.use(base, render); - swaggerApp.use(base, renderIndex); + swaggerApp.use(render); + swaggerApp.use(renderIndex); return swaggerApp; } diff --git a/packages/integrations/swagger/src/ui.ts b/packages/integrations/swagger/src/ui.ts index 531a8b7d..88506106 100644 --- a/packages/integrations/swagger/src/ui.ts +++ b/packages/integrations/swagger/src/ui.ts @@ -1,5 +1,5 @@ import type { RenderHtmlOptions } from "@fourze/core"; -import { isFunction, renderHtml, resolves, transformTemplate } from "@fourze/core"; +import { isFunction, renderHtml, transformTemplate, withBase } from "@fourze/core"; const defaultStyleTemplate = ` html { @@ -85,7 +85,7 @@ export interface RenderSwaggerUIOptions extends RenderHtmlOptions { export function renderIndexHtml(root: string, options: RenderSwaggerUIOptions = {}) { const scriptContent = transformTemplate(defaultScriptTemplate, { initOptions: stringifyOptions({ - url: options.url ?? "/api-docs" + url: options.url ?? withBase("/api-docs", root) }) }); @@ -93,12 +93,14 @@ export function renderIndexHtml(root: string, options: RenderSwaggerUIOptions = language: options.language ?? "en", favicon: options.favicon ?? `${root}/favicon-32x32.png`, script: [ - resolves(root, "/swagger-ui-bundle.js"), - resolves(root, "/swagger-ui-standalone-preset.js"), + withBase("/swagger-ui-bundle.js", root), + withBase("/swagger-ui-standalone-preset.js", root), ...(options.script ?? []) ], style: [ - resolves(root, "/swagger-ui.css"), + withBase("/favicon-16x16.png", root), + withBase("/favicon-32x32.png", root), + withBase("/swagger-ui.css", root), ...(options.style ?? []) ], title: "Swagger UI", diff --git a/packages/integrations/swagger/test/swagger.test.ts b/packages/integrations/swagger/test/swagger.test.ts index 164707c8..8937eace 100644 --- a/packages/integrations/swagger/test/swagger.test.ts +++ b/packages/integrations/swagger/test/swagger.test.ts @@ -1,7 +1,7 @@ import type { Server } from "http"; import { connect, normalizeAddress } from "@fourze/server"; import express from "express"; -import { createApp, defineRouter, randomInt, resolves } from "@fourze/core"; +import { createApp, defineRouter, randomInt, withBase } from "@fourze/core"; import { service } from "@fourze/swagger"; import { expect, test } from "vitest"; import axios from "axios"; @@ -46,7 +46,7 @@ test("test-swagger", async () => { protocol: "http" }); - const url = origin ? resolves(origin, "/api-docs") : "/api-docs"; + const url = origin ? withBase("/api-docs", origin) : "/api-docs"; const response = await axios.get(url); diff --git a/packages/integrations/unplugin/src/index.ts b/packages/integrations/unplugin/src/index.ts index 40339f6c..7728d053 100644 --- a/packages/integrations/unplugin/src/index.ts +++ b/packages/integrations/unplugin/src/index.ts @@ -1,6 +1,6 @@ import path from "path"; import type { DelayMsType, FourzeLogLevelKey, RequestMethod } from "@fourze/core"; -import { createLogger, isBoolean, resolves, setLoggerLevel } from "@fourze/core"; +import { createLogger, isBoolean, setLoggerLevel, withBase } from "@fourze/core"; import { createDelayMiddleware, createTimeoutMiddleware } from "@fourze/middlewares"; import { createUnplugin } from "unplugin"; @@ -8,10 +8,10 @@ import type { FourzeMockAppOptions } from "@fourze/mock"; import type { FourzeProxyOption } from "@fourze/server"; -import { createHmrApp, createServer, defineEnvs } from "@fourze/server"; +import { connect, createHmrApp, createServer, defineEnvs } from "@fourze/server"; import { build, getModuleAlias, service } from "@fourze/swagger"; -import type { InlineConfig } from "vite"; +import { type InlineConfig } from "vite"; import { createMockClient } from "@fourze/mock"; const PLUGIN_NAME = "unplugin-fourze"; @@ -163,7 +163,6 @@ const createFourzePlugin = createUnplugin((options: UnpluginFourzeOptions = {}) // ); const hmrApp = createHmrApp({ - base, allow, deny, dir, @@ -193,12 +192,14 @@ const createFourzePlugin = createUnplugin((options: UnpluginFourzeOptions = {}) async writeBundle() { if (generateDocument) { await build(hmrApp, { - base, distPath: viteConfig.build?.outDir, vite: { ...viteConfig }, - defaultMethod: swaggerOptions.defaultMethod + swagger: { + basePath: base, + ...swaggerOptions + } }); } }, @@ -294,24 +295,16 @@ const createFourzePlugin = createUnplugin((options: UnpluginFourzeOptions = {}) hmrApp.watch(watcher); } - const server = createServer(); - server.use(hmrApp); if (options.swagger !== false) { + const uiBase = withBase("/swagger-ui", viteConfig.base ?? "/"); const swaggerMiddleware = service(hmrApp, { - base: viteConfig.base ? resolves(viteConfig.base, "/swagger-ui/") : "/swagger-ui/", + uiBase, + basePath: base, ...swaggerOptions }); - server.use(swaggerMiddleware); - } - if (options.server?.port) { - try { - server.listen(port, host); - } catch (error) { - logger.error("Server listen failed.", error); - } - } else { - middlewares.use(server); + middlewares.use(uiBase, connect(swaggerMiddleware)); } + middlewares.use(base, connect(hmrApp)); } } } diff --git a/packages/middlewares/src/index.ts b/packages/middlewares/src/index.ts index 5458e32f..f3edebc7 100644 --- a/packages/middlewares/src/index.ts +++ b/packages/middlewares/src/index.ts @@ -1,10 +1,9 @@ -import { createDelayMiddleware, createFilterMiddleware, createHeaderMiddleware, createResolveMiddleware, createSwaggerMiddleware, createTimeoutMiddleware } from "./middlewares"; +import { createDelayMiddleware, createFilterMiddleware, createHeaderMiddleware, createResolveMiddleware, createTimeoutMiddleware } from "./middlewares"; export const middlewares = { delay: createDelayMiddleware, resolve: createResolveMiddleware, timeout: createTimeoutMiddleware, - swagger: createSwaggerMiddleware, header: createHeaderMiddleware, filter: createFilterMiddleware } as const; diff --git a/packages/middlewares/src/middlewares/index.ts b/packages/middlewares/src/middlewares/index.ts index 103a6550..a5d65cb5 100644 --- a/packages/middlewares/src/middlewares/index.ts +++ b/packages/middlewares/src/middlewares/index.ts @@ -1,6 +1,5 @@ export * from "./delay"; export * from "./header"; export * from "./resolve"; -export * from "./swagger"; export * from "./timeout"; export * from "./filter"; diff --git a/packages/mock/test/hooks.test.ts b/packages/mock/test/hooks.test.ts index b25fce36..2c24daf7 100644 --- a/packages/mock/test/hooks.test.ts +++ b/packages/mock/test/hooks.test.ts @@ -56,9 +56,11 @@ test("test-hooks", async () => { headers: { token: data.token } - }).then(r => r.json()); + }); - expect(res.token).toEqual(data.token.toUpperCase()); + const { token } = await res.json(); + + expect(token).toEqual(data.token.toUpperCase()); const res2 = await app.fetch("/api/test", { method: "post" }); diff --git a/packages/server/src/utils.ts b/packages/server/src/utils.ts index d5d22c44..30d0799b 100644 --- a/packages/server/src/utils.ts +++ b/packages/server/src/utils.ts @@ -5,15 +5,15 @@ import net from "net"; import type { AddressInfo } from "net"; import type { Server } from "http"; -import { isNumber, isString, slash } from "@fourze/core"; +import { isNumber, isString, normalizeURL } from "@fourze/core"; import { loopbackHosts, wildcardHosts } from "./constants"; export const isWindows = os.platform() === "win32"; /** - * copy from @vitejs/vite by @yyx990803 (Evan You) (MIT License) + * port @vitejs/vite by @yyx990803 (Evan You) (MIT License) */ export function normalizePath(id: string) { - return path.posix.normalize(isWindows ? slash(id) : id); + return path.posix.normalize(isWindows ? normalizeURL(id) : id); } export function defineEnvs( diff --git a/packages/server/test/server.test.ts b/packages/server/test/server.test.ts index 971ade77..2caa529c 100644 --- a/packages/server/test/server.test.ts +++ b/packages/server/test/server.test.ts @@ -1,5 +1,5 @@ import type { Server } from "http"; -import { createApp, defineRouter, randomInt, resolves } from "@fourze/core"; +import { createApp, defineRouter, randomInt, withBase } from "@fourze/core"; import { connect, createServer, normalizeAddress } from "@fourze/server"; import express from "connect"; import axios from "axios"; @@ -33,7 +33,7 @@ test("run-server", async () => { await server.listen(); const returnData = await axios - .get(resolves(server.origin, "/api/test")) + .get(withBase("/api/test", server.origin)) .then((r) => r.data); expect(returnData).toEqual(testData); diff --git a/playgrounds/vite/src/app.vue b/playgrounds/vite/src/app.vue index 6fa1a2a8..3fe30d47 100644 --- a/playgrounds/vite/src/app.vue +++ b/playgrounds/vite/src/app.vue @@ -84,7 +84,7 @@ async function request(options: RequestOptions) { const { url, method = "GET", params = {}, data = {}, type = "fetch" } = options; - const _url = mockEnabled.value ? `http://localhost:8080${url}` : url; + const _url = url; switch (type) { case "jquery": return $.ajax({ diff --git a/playgrounds/vite/vite.config.ts b/playgrounds/vite/vite.config.ts index cebf3abf..45236497 100644 --- a/playgrounds/vite/vite.config.ts +++ b/playgrounds/vite/vite.config.ts @@ -11,9 +11,9 @@ import windicss from "vite-plugin-windicss"; import tsconfig from "./tsconfig.json"; export default defineConfig({ - base: "/test", + base: "./test", server: { - port: 8000, + port: 7609, host: "0.0.0.0", fs: { strict: false diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 939b40d6..076bb6ab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,11 +30,11 @@ importers: specifier: ^18.16.18 version: 18.16.18 '@vitest/coverage-v8': - specifier: ^0.32.0 - version: 0.32.0(vitest@0.32.0) + specifier: ^0.32.2 + version: 0.32.2(vitest@0.32.2) '@vitest/ui': - specifier: ^0.32.0 - version: 0.32.0(vitest@0.32.0) + specifier: ^0.32.2 + version: 0.32.2(vitest@0.32.2) autocannon: specifier: ^7.11.0 version: 7.11.0 @@ -75,8 +75,8 @@ importers: specifier: ^1.2.1 version: 1.2.1 vitest: - specifier: ^0.32.0 - version: 0.32.0(@vitest/ui@0.32.0)(jsdom@22.1.0) + specifier: ^0.32.2 + version: 0.32.2(@vitest/ui@0.32.2)(jsdom@22.1.0) bench: dependencies: @@ -187,7 +187,7 @@ importers: devDependencies: '@nuxt/module-builder': specifier: ^0.4.0 - version: 0.4.0(@nuxt/kit@3.5.3)(nuxi@3.6.0) + version: 0.4.0(@nuxt/kit@3.5.3)(nuxi@3.6.1) '@nuxt/schema': specifier: ^3.5.3 version: 3.5.3(rollup@3.25.1) @@ -196,22 +196,22 @@ importers: version: 0.7.0 nuxt: specifier: ^3.5.3 - version: 3.5.3(@types/node@20.3.1)(eslint@8.42.0)(rollup@3.25.1)(typescript@5.1.3) + version: 3.5.3(@types/node@20.3.2)(eslint@8.42.0)(rollup@3.25.1)(typescript@5.1.3) packages/integrations/swagger: dependencies: '@fourze/core': specifier: workspace:* version: link:../../core - '@fourze/middlewares': - specifier: workspace:* - version: link:../../middlewares '@fourze/mock': specifier: workspace:* version: link:../../mock '@fourze/server': specifier: workspace:* version: link:../../server + '@fourze/swagger-middleware': + specifier: workspace:* + version: link:../swagger-middleware fs-extra: specifier: ^11.1.1 version: 11.1.1 @@ -226,6 +226,15 @@ importers: specifier: ^3.30.1 version: 3.30.1 + packages/integrations/swagger-middleware: + dependencies: + '@fourze/core': + specifier: workspace:* + version: link:../../core + maybe-types: + specifier: ^0.0.3 + version: 0.0.3 + packages/integrations/unplugin: dependencies: '@fourze/core': @@ -389,7 +398,7 @@ importers: version: link:../../packages/integrations/nuxt nuxt: specifier: 3.5.3 - version: 3.5.3(@types/node@20.3.1)(eslint@8.42.0)(rollup@3.25.1)(typescript@5.1.3) + version: 3.5.3(@types/node@20.3.2)(eslint@8.42.0)(rollup@3.25.1)(typescript@5.1.3) nuxt-windicss: specifier: ^2.6.1 version: 2.6.1(rollup@3.25.1)(vite@4.3.9) @@ -1517,7 +1526,7 @@ packages: jiti: 1.18.2 knitwork: 1.0.0 lodash.template: 4.5.0 - mlly: 1.3.0 + mlly: 1.4.0 pathe: 1.1.1 pkg-types: 1.0.3 scule: 1.0.0 @@ -1555,7 +1564,7 @@ packages: - rollup - supports-color - /@nuxt/module-builder@0.4.0(@nuxt/kit@3.5.3)(nuxi@3.6.0): + /@nuxt/module-builder@0.4.0(@nuxt/kit@3.5.3)(nuxi@3.6.1): resolution: {integrity: sha512-B+UAYgFV1Hkc2ZcD7GaiKZ3SNHhyxFlXzZoBWTc9ulE0Z/+rq6RTa9fNm13BZyGhVhDCl5FN/wF/yYa1O/D2iw==} hasBin: true peerDependencies: @@ -1566,7 +1575,7 @@ packages: consola: 3.1.0 mlly: 1.3.0 mri: 1.2.0 - nuxi: 3.6.0 + nuxi: 3.6.1 pathe: 1.1.1 unbuild: 1.2.1 transitivePeerDependencies: @@ -1646,7 +1655,7 @@ packages: resolution: {integrity: sha512-PjVETP7+iZXAs5Q8O4ivl4t6qjWZMZqwiTVogUXHoHGZZcw7GZW3u3tzfYfE1HbzyYJfr236IXqQ02MeR8Fz2w==} dev: true - /@nuxt/vite-builder@3.5.3(@types/node@20.3.1)(eslint@8.42.0)(rollup@3.25.1)(typescript@5.1.3)(vue@3.3.4): + /@nuxt/vite-builder@3.5.3(@types/node@20.3.2)(eslint@8.42.0)(rollup@3.25.1)(typescript@5.1.3)(vue@3.3.4): resolution: {integrity: sha512-7zEKpGh3iWGRDwbWUa8eRxdLMxZtPzetelmdmXPjtYKGwUebZOcBhpeJ+VgJKOIf4OEj9E7BZS+it/Ji9UG9qw==} engines: {node: ^14.18.0 || >=16.10.0} peerDependencies: @@ -1683,8 +1692,8 @@ packages: strip-literal: 1.0.1 ufo: 1.1.2 unplugin: 1.3.1 - vite: 4.3.9(@types/node@20.3.1) - vite-node: 0.31.4(@types/node@20.3.1) + vite: 4.3.9(@types/node@20.3.2) + vite-node: 0.31.4(@types/node@20.3.2) vite-plugin-checker: 0.6.0(eslint@8.42.0)(typescript@5.1.3)(vite@4.3.9) vue: 3.3.4 vue-bundle-renderer: 1.0.3 @@ -2111,8 +2120,8 @@ packages: /@types/node@18.16.18: resolution: {integrity: sha512-/aNaQZD0+iSBAGnvvN2Cx92HqE5sZCPZtx2TsK+4nvV23fFe09jVDvpArXr2j9DnYlzuU9WuoykDDc6wqvpNcw==} - /@types/node@20.3.1: - resolution: {integrity: sha512-EhcH/wvidPy1WeML3TtYFGR83UzjxeWRen9V402T8aUGYsCHOmfoisV3ZSg03gAFIbLq8TnWOJ0f4cALtnSEUg==} + /@types/node@20.3.2: + resolution: {integrity: sha512-vOBLVQeCQfIcF/2Y7eKFTqrMnizK5lRNQ7ykML/5RuwVXVWxYkgwS7xbt4B6fKCUPgbSL5FSsjHQpaGQP/dQmw==} dev: true /@types/normalize-package-data@2.4.1: @@ -2427,8 +2436,8 @@ packages: vue: 3.3.4 dev: true - /@vitest/coverage-v8@0.32.0(vitest@0.32.0): - resolution: {integrity: sha512-VXXlWq9X/NbsoP/l/CHLBjutsFFww1UY1qEhzGjn/DY7Tqe+z0Nu8XKc8im/XUAmjiWsh2XV7sy/F0IKAl4eaw==} + /@vitest/coverage-v8@0.32.2(vitest@0.32.2): + resolution: {integrity: sha512-/+V3nB3fyeuuSeKxCfi6XmWjDIxpky7AWSkGVfaMjAk7di8igBwRsThLjultwIZdTDH1RAxpjmCXEfSqsMFZOA==} peerDependencies: vitest: '>=0.32.0 <1' dependencies: @@ -2443,61 +2452,61 @@ packages: std-env: 3.3.3 test-exclude: 6.0.0 v8-to-istanbul: 9.1.0 - vitest: 0.32.0(@vitest/ui@0.32.0)(jsdom@22.1.0) + vitest: 0.32.2(@vitest/ui@0.32.2)(jsdom@22.1.0) transitivePeerDependencies: - supports-color dev: true - /@vitest/expect@0.32.0: - resolution: {integrity: sha512-VxVHhIxKw9Lux+O9bwLEEk2gzOUe93xuFHy9SzYWnnoYZFYg1NfBtnfnYWiJN7yooJ7KNElCK5YtA7DTZvtXtg==} + /@vitest/expect@0.32.2: + resolution: {integrity: sha512-6q5yzweLnyEv5Zz1fqK5u5E83LU+gOMVBDuxBl2d2Jfx1BAp5M+rZgc5mlyqdnxquyoiOXpXmFNkcGcfFnFH3Q==} dependencies: - '@vitest/spy': 0.32.0 - '@vitest/utils': 0.32.0 + '@vitest/spy': 0.32.2 + '@vitest/utils': 0.32.2 chai: 4.3.7 dev: true - /@vitest/runner@0.32.0: - resolution: {integrity: sha512-QpCmRxftHkr72xt5A08xTEs9I4iWEXIOCHWhQQguWOKE4QH7DXSKZSOFibuwEIMAD7G0ERvtUyQn7iPWIqSwmw==} + /@vitest/runner@0.32.2: + resolution: {integrity: sha512-06vEL0C1pomOEktGoLjzZw+1Fb+7RBRhmw/06WkDrd1akkT9i12su0ku+R/0QM69dfkIL/rAIDTG+CSuQVDcKw==} dependencies: - '@vitest/utils': 0.32.0 + '@vitest/utils': 0.32.2 concordance: 5.0.4 p-limit: 4.0.0 pathe: 1.1.1 dev: true - /@vitest/snapshot@0.32.0: - resolution: {integrity: sha512-yCKorPWjEnzpUxQpGlxulujTcSPgkblwGzAUEL+z01FTUg/YuCDZ8dxr9sHA08oO2EwxzHXNLjQKWJ2zc2a19Q==} + /@vitest/snapshot@0.32.2: + resolution: {integrity: sha512-JwhpeH/PPc7GJX38vEfCy9LtRzf9F4er7i4OsAJyV7sjPwjj+AIR8cUgpMTWK4S3TiamzopcTyLsZDMuldoi5A==} dependencies: magic-string: 0.30.0 pathe: 1.1.1 pretty-format: 27.5.1 dev: true - /@vitest/spy@0.32.0: - resolution: {integrity: sha512-MruAPlM0uyiq3d53BkwTeShXY0rYEfhNGQzVO5GHBmmX3clsxcWp79mMnkOVcV244sNTeDcHbcPFWIjOI4tZvw==} + /@vitest/spy@0.32.2: + resolution: {integrity: sha512-Q/ZNILJ4ca/VzQbRM8ur3Si5Sardsh1HofatG9wsJY1RfEaw0XKP8IVax2lI1qnrk9YPuG9LA2LkZ0EI/3d4ug==} dependencies: tinyspy: 2.1.1 dev: true - /@vitest/ui@0.32.0(vitest@0.32.0): - resolution: {integrity: sha512-55gugh6+owrOqW83RCgLm9q+o3SlzvFVgl1lyfnr0WB8ABxLoM+3pgusEjosscgEYGzTjTXaZY6xLd4qlfH/RQ==} + /@vitest/ui@0.32.2(vitest@0.32.2): + resolution: {integrity: sha512-N5JKftnB8qzKFtpQC5OcUGxYTLo6wiB/95Lgyk6MF52t74Y7BJOWbf6EFYhXqt9J0MSbhOR2kapq+WKKUGDW0g==} peerDependencies: vitest: '>=0.30.1 <1' dependencies: - '@vitest/utils': 0.32.0 + '@vitest/utils': 0.32.2 fast-glob: 3.2.12 fflate: 0.7.4 flatted: 3.2.7 pathe: 1.1.1 picocolors: 1.0.0 sirv: 2.0.3 - vitest: 0.32.0(@vitest/ui@0.32.0)(jsdom@22.1.0) + vitest: 0.32.2(@vitest/ui@0.32.2)(jsdom@22.1.0) dev: true - /@vitest/utils@0.32.0: - resolution: {integrity: sha512-53yXunzx47MmbuvcOPpLaVljHaeSu1G2dHdmy7+9ngMnQIkBQcvwOcoclWFnxDMxFbnq8exAfh3aKSZaK71J5A==} + /@vitest/utils@0.32.2: + resolution: {integrity: sha512-lnJ0T5i03j0IJaeW73hxe2AuVnZ/y1BhhCOuIcl9LIzXnbpXJT9Lrt6brwKHXLOiA7MZ6N5hSJjt0xE1dGNCzQ==} dependencies: - concordance: 5.0.4 + diff-sequences: 29.4.3 loupe: 2.3.6 pretty-format: 27.5.1 dev: true @@ -2887,7 +2896,6 @@ packages: resolution: {integrity: sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==} engines: {node: '>=0.4.0'} hasBin: true - dev: true /agent-base@6.0.2: resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==} @@ -3793,7 +3801,7 @@ packages: js-string-escape: 1.0.1 lodash: 4.17.21 md5-hex: 3.0.1 - semver: 7.5.1 + semver: 7.5.3 well-known-symbols: 2.0.0 dev: true @@ -4205,6 +4213,11 @@ packages: resolution: {integrity: sha512-KqFl6pOgOW+Y6wJgu80rHpo2/3H07vr8ntR9rkkFIRETewbf5GaYYcakYfiKz89K+sLsuPkQIZaXDMjUObZwWg==} dev: true + /diff-sequences@29.4.3: + resolution: {integrity: sha512-ofrBgwpPhCD85kMKtE9RYFFq6OC1A89oW2vvgWZNCwxrUpRUILopY7lsYyMDSjc8g6U6aiO0Qubg6r4Wgt5ZnA==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + dev: true + /dir-glob@3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} @@ -5511,7 +5524,7 @@ packages: dependencies: foreground-child: 3.1.1 jackspeak: 2.2.1 - minimatch: 9.0.1 + minimatch: 9.0.2 minipass: 6.0.2 path-scurry: 1.9.2 dev: true @@ -6950,6 +6963,13 @@ packages: brace-expansion: 2.0.1 dev: true + /minimatch@9.0.2: + resolution: {integrity: sha512-PZOT9g5v2ojiTL7r1xF6plNHLtOeTpSlDI007As2NlA2aYBMfVom17yqa6QzhmDP8QOhn7LjHTg7DFCVSSa6yg==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + brace-expansion: 2.0.1 + dev: true + /minimist@1.2.7: resolution: {integrity: sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==} dev: true @@ -7018,6 +7038,14 @@ packages: pkg-types: 1.0.3 ufo: 1.1.2 + /mlly@1.4.0: + resolution: {integrity: sha512-ua8PAThnTwpprIaU47EPeZ/bPUVp2QYBbWMphUQpVdBI3Lgqzm5KZQ45Agm3YJedHXaIHl6pBGabaLSUPPSptg==} + dependencies: + acorn: 8.9.0 + pathe: 1.1.1 + pkg-types: 1.0.3 + ufo: 1.1.2 + /mri@1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} engines: {node: '>=4'} @@ -7265,8 +7293,8 @@ packages: fsevents: 2.3.2 dev: true - /nuxi@3.6.0: - resolution: {integrity: sha512-gLmSE8NqNIz7HRPxBmO+Y+fgz95kMM25MzEoeuWLU/ZMWYqUOcvhsQEmv4ZZBfCe5/zv7+mO3G0UK1+Gi3QUoQ==} + /nuxi@3.6.1: + resolution: {integrity: sha512-8kyDHfyiq0oLywon8UlucQWyYj3toE5AU96COjbuQy8ZzyRT6KJlAmMXmFkO/VuIhaMC8qdlcZPYg/NnHTVjaQ==} engines: {node: ^14.18.0 || >=16.10.0} hasBin: true optionalDependencies: @@ -7297,7 +7325,7 @@ packages: - vite dev: true - /nuxt@3.5.3(@types/node@20.3.1)(eslint@8.42.0)(rollup@3.25.1)(typescript@5.1.3): + /nuxt@3.5.3(@types/node@20.3.2)(eslint@8.42.0)(rollup@3.25.1)(typescript@5.1.3): resolution: {integrity: sha512-fG39BZ5N5ATtmx2vuxN8APQPSlSsCDpfkJ0k581gMc7eFztqrBzPncZX5w3RQLW7AiGBE2yYEfqiwC6AVODBBg==} engines: {node: ^14.18.0 || >=16.10.0} hasBin: true @@ -7313,8 +7341,8 @@ packages: '@nuxt/schema': 3.5.3(rollup@3.25.1) '@nuxt/telemetry': 2.2.0(rollup@3.25.1) '@nuxt/ui-templates': 1.1.1 - '@nuxt/vite-builder': 3.5.3(@types/node@20.3.1)(eslint@8.42.0)(rollup@3.25.1)(typescript@5.1.3)(vue@3.3.4) - '@types/node': 20.3.1 + '@nuxt/vite-builder': 3.5.3(@types/node@20.3.2)(eslint@8.42.0)(rollup@3.25.1)(typescript@5.1.3)(vue@3.3.4) + '@types/node': 20.3.2 '@unhead/ssr': 1.1.27 '@unhead/vue': 1.1.27(vue@3.3.4) '@vue/shared': 3.3.4 @@ -9479,7 +9507,7 @@ packages: /unctx@2.3.1: resolution: {integrity: sha512-PhKke8ZYauiqh3FEMVNm7ljvzQiph0Mt3GBRve03IJm7ukfaON2OBK795tLwhbyfzknuRRkW0+Ze+CQUmzOZ+A==} dependencies: - acorn: 8.8.2 + acorn: 8.9.0 estree-walker: 3.0.3 magic-string: 0.30.0 unplugin: 1.3.1 @@ -9518,7 +9546,7 @@ packages: fast-glob: 3.2.12 local-pkg: 0.4.3 magic-string: 0.30.0 - mlly: 1.3.0 + mlly: 1.4.0 pathe: 1.1.1 pkg-types: 1.0.3 scule: 1.0.0 @@ -9734,7 +9762,7 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} - /vite-node@0.31.4(@types/node@20.3.1): + /vite-node@0.31.4(@types/node@20.3.2): resolution: {integrity: sha512-uzL377GjJtTbuc5KQxVbDu2xfU/x0wVjUtXQR2ihS21q/NK6ROr4oG0rsSkBBddZUVCwzfx22in76/0ZZHXgkQ==} engines: {node: '>=v14.18.0'} hasBin: true @@ -9744,7 +9772,7 @@ packages: mlly: 1.3.0 pathe: 1.1.1 picocolors: 1.0.0 - vite: 4.3.9(@types/node@20.3.1) + vite: 4.3.9(@types/node@20.3.2) transitivePeerDependencies: - '@types/node' - less @@ -9755,14 +9783,14 @@ packages: - terser dev: true - /vite-node@0.32.0(@types/node@18.16.18): - resolution: {integrity: sha512-220P/y8YacYAU+daOAqiGEFXx2A8AwjadDzQqos6wSukjvvTWNqleJSwoUn0ckyNdjHIKoxn93Nh1vWBqEKr3Q==} + /vite-node@0.32.2(@types/node@18.16.18): + resolution: {integrity: sha512-dTQ1DCLwl2aEseov7cfQ+kDMNJpM1ebpyMMMwWzBvLbis8Nla/6c9WQcqpPssTwS6Rp/+U6KwlIj8Eapw4bLdA==} engines: {node: '>=v14.18.0'} hasBin: true dependencies: cac: 6.7.14 debug: 4.3.4 - mlly: 1.3.0 + mlly: 1.4.0 pathe: 1.1.1 picocolors: 1.0.0 vite: 4.3.9(@types/node@18.16.18)(sass@1.63.3) @@ -9822,7 +9850,7 @@ packages: strip-ansi: 6.0.1 tiny-invariant: 1.3.1 typescript: 5.1.3 - vite: 4.3.9(@types/node@20.3.1) + vite: 4.3.9(@types/node@20.3.2) vscode-languageclient: 7.0.0 vscode-languageserver: 7.0.0 vscode-languageserver-textdocument: 1.0.8 @@ -9895,7 +9923,7 @@ packages: optionalDependencies: fsevents: 2.3.2 - /vite@4.3.9(@types/node@20.3.1): + /vite@4.3.9(@types/node@20.3.2): resolution: {integrity: sha512-qsTNZjO9NoJNW7KnOrgYwczm0WctJ8m/yqYAMAK9Lxt4SoySUfS5S8ia9K7JHpa3KEeMfyF8LoJ3c5NeBJy6pg==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -9920,7 +9948,7 @@ packages: terser: optional: true dependencies: - '@types/node': 20.3.1 + '@types/node': 20.3.2 esbuild: 0.17.19 postcss: 8.4.24 rollup: 3.25.1 @@ -9928,8 +9956,8 @@ packages: fsevents: 2.3.2 dev: true - /vitest@0.32.0(@vitest/ui@0.32.0)(jsdom@22.1.0): - resolution: {integrity: sha512-SW83o629gCqnV3BqBnTxhB10DAwzwEx3z+rqYZESehUB+eWsJxwcBQx7CKy0otuGMJTYh7qCVuUX23HkftGl/Q==} + /vitest@0.32.2(@vitest/ui@0.32.2)(jsdom@22.1.0): + resolution: {integrity: sha512-hU8GNNuQfwuQmqTLfiKcqEhZY72Zxb7nnN07koCUNmntNxbKQnVbeIS6sqUgR3eXSlbOpit8+/gr1KpqoMgWCQ==} engines: {node: '>=v14.18.0'} hasBin: true peerDependencies: @@ -9962,12 +9990,12 @@ packages: '@types/chai': 4.3.5 '@types/chai-subset': 1.3.3 '@types/node': 18.16.18 - '@vitest/expect': 0.32.0 - '@vitest/runner': 0.32.0 - '@vitest/snapshot': 0.32.0 - '@vitest/spy': 0.32.0 - '@vitest/ui': 0.32.0(vitest@0.32.0) - '@vitest/utils': 0.32.0 + '@vitest/expect': 0.32.2 + '@vitest/runner': 0.32.2 + '@vitest/snapshot': 0.32.2 + '@vitest/spy': 0.32.2 + '@vitest/ui': 0.32.2(vitest@0.32.2) + '@vitest/utils': 0.32.2 acorn: 8.8.2 acorn-walk: 8.2.0 cac: 6.7.14 @@ -9984,7 +10012,7 @@ packages: tinybench: 2.5.0 tinypool: 0.5.0 vite: 4.3.9(@types/node@18.16.18)(sass@1.63.3) - vite-node: 0.32.0(@types/node@18.16.18) + vite-node: 0.32.2(@types/node@18.16.18) why-is-node-running: 2.2.2 transitivePeerDependencies: - less diff --git a/tsconfig.json b/tsconfig.json index a5ea3e9a..39f60293 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,9 +26,12 @@ "@fourze/swagger": [ "./packages/integrations/swagger/src/index.ts" ], + "@fourze/swagger-middleware": [ + "./packages/integrations/swagger-middleware/src/index.ts" + ], "@fourze/middlewares": [ "./packages/middlewares/src/index.ts" - ] + ], } }, "exclude": ["node_modules", "dist"]