Socket
Socket
Sign inDemoInstall

@aomex/web

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aomex/web - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

102

CHANGELOG.md
# @aomex/web
## 0.0.6
## 0.0.7
### Patch Changes
- [`d3a2757`](https://github.com/aomex/aomex/commit/d3a2757b38391ad70a206d95eac09520c64e9b85) Thanks [@geekact](https://github.com/geekact)! - fix(web): statusCode 覆盖无效
- [`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f) Thanks [@geekact](https://github.com/geekact)! - refactor: rename package helper to utility
- [`07c8575`](https://github.com/aomex/aomex/commit/07c857565ede4eca7e88de4e8c5e5f244f9d16cb) Thanks [@geekact](https://github.com/geekact)! - feat(web): 删除 error-pre-respond 事件
- [`ceb2d82`](https://github.com/aomex/aomex/commit/ceb2d8269755dca3f79b755224259b8a99bc65d0) Thanks [@geekact](https://github.com/geekact)! - chore(cache,web): upgrade lru-cache from 7.14.1 to 7.17.0
- [`e80844a`](https://github.com/aomex/aomex/commit/e80844a6808fd0f3b9d613ec3163b06357316cae) Thanks [@geekact](https://github.com/geekact)! - feat(web): 导出 statuses 库
- [`146b6b5`](https://github.com/aomex/aomex/commit/146b6b5f09d4b9f557c1771686f3585bebf4cfc9) Thanks [@geekact](https://github.com/geekact)! - refactor(helper): 重命名 color 为 chalk
- [`56f65c8`](https://github.com/aomex/aomex/commit/56f65c8509b40679272ed58f63e12d98e1818503) Thanks [@geekact](https://github.com/geekact)! - feat(web): 设置 body 时设置 headers
- [`c6df4de`](https://github.com/aomex/aomex/commit/c6df4de61fc28f452f8a202c9a485e1a061b3eb6) Thanks [@geekact](https://github.com/geekact)! - feat(web): 动态获取 contentType
- [`79e19c1`](https://github.com/aomex/aomex/commit/79e19c1ae2a35b38580a4d2a27b6dde634345126) Thanks [@geekact](https://github.com/geekact)! - fix(web): 仅在 body setter 中可以强制指定 statusCode
- [`9adefaa`](https://github.com/aomex/aomex/commit/9adefaa8baaaafb7be610c7a98920c9830d10a3c) Thanks [@geekact](https://github.com/geekact)! - feat(web): 挂载中间件时检测到链条自动创建分割点
- [`a8bb601`](https://github.com/aomex/aomex/commit/a8bb601acaf1e1d580511ae886a4ae99bf19f699) Thanks [@geekact](https://github.com/geekact)! - feat(web): response 增加 isJSON 方法
- [`902597b`](https://github.com/aomex/aomex/commit/902597b2f98fda7e63f7419a5ef62ab2acb7c863) Thanks [@geekact](https://github.com/geekact)! - feat(web): 定制异常的响应格式使用事件触发
- Updated dependencies [[`146b6b5`](https://github.com/aomex/aomex/commit/146b6b5f09d4b9f557c1771686f3585bebf4cfc9), [`e8dee7c`](https://github.com/aomex/aomex/commit/e8dee7c3f064587cd2afb9cb95ab3341f63ccd27)]:
- @aomex/helper@0.0.3
- @aomex/core@0.0.5
## 0.0.5
### Patch Changes
- [`d8debb9`](https://github.com/aomex/aomex/commit/d8debb9b6319d30e48cb77d97103b5559c57789c) Thanks [@geekact](https://github.com/geekact)! - refactor(web): response 的 header 均使用首字母大写的格式
- [`64c10e1`](https://github.com/aomex/aomex/commit/64c10e17ff92251bb2d9f45e0bddde5cba8a3b20) Thanks [@geekact](https://github.com/geekact)! - refactor(web): 重命名函数 getContentType 为 getMimeType
- [`6a57463`](https://github.com/aomex/aomex/commit/6a57463c1107c38a8b8cf5fa00ff3289bf629c0a) Thanks [@geekact](https://github.com/geekact)! - refactor(middleware): 类型 MiddlewareFn 和 GetMiddlewareProps 迁移到命名空间
- [`8857115`](https://github.com/aomex/aomex/commit/88571153b7e84ec6d66d37970c3ef7b4e1924a03) Thanks [@geekact](https://github.com/geekact)! - refactor(web): file-validator 重命名部分类型
- [`68b1365`](https://github.com/aomex/aomex/commit/68b13655922a0714bcdd2101ce659da382d44e8b) Thanks [@geekact](https://github.com/geekact)! - feat(web): app 增加 debug 配置
- [`b51a81a`](https://github.com/aomex/aomex/commit/b51a81a65313073dff5307b310b6656da2ad5186) Thanks [@geekact](https://github.com/geekact)! - fix(web): 部分类型依赖从 devDeps 转移到 deps
- [`b5aaec5`](https://github.com/aomex/aomex/commit/b5aaec540e3d732868a270a969a94ccd6ff9ac6a) Thanks [@geekact](https://github.com/geekact)! - refactor(validator): 内部数据迁移到 static 属性以减少最终导出模块数量
- [`fd6ae40`](https://github.com/aomex/aomex/commit/fd6ae40577bd9a62c211d4615483fc5dd58f5865) Thanks [@geekact](https://github.com/geekact)! - fix(web): 内部循环引用
- Updated dependencies [[`956bba9`](https://github.com/aomex/aomex/commit/956bba9e5b954f34486ad5f2b45a5277c1f980c9), [`ee021e3`](https://github.com/aomex/aomex/commit/ee021e342814f12777e538c06a19971e1020f201)]:
- @aomex/helper@0.0.2
- @aomex/core@0.0.4
## 0.0.4
### Patch Changes
- [`121253a`](https://github.com/aomex/aomex/commit/121253a6fc203e427bfd25e82d713bec6ac13b38) Thanks [@geekact](https://github.com/geekact)! - middleware 增加构造函数
- [`59dc183`](https://github.com/aomex/aomex/commit/59dc183bcec9b7221c18865563b38cba5d82869b) Thanks [@geekact](https://github.com/geekact)! - 增加 response 中间件
- [`8cb74fd`](https://github.com/aomex/aomex/commit/8cb74fdd27626037aa9bc80cb2930e4f0d67f8e6) Thanks [@geekact](https://github.com/geekact)! - middleware 增加 skipIf 方法
- [`d834392`](https://github.com/aomex/aomex/commit/d834392b1e0f6333d66d11378d9f4ceb813a58a9) Thanks [@geekact](https://github.com/geekact)! - 导出通用的 skip 函数
- [`91feda4`](https://github.com/aomex/aomex/commit/91feda457dfa8bd8dd2c8f38bfaaf4f7f2f7702f) Thanks [@geekact](https://github.com/geekact)! - 重命名 pathItemInMethod 为 methodItem
- Updated dependencies []:
- @aomex/core@0.0.3
## 0.0.3
### Patch Changes
- [`4735157`](https://github.com/aomex/aomex/commit/4735157c52d0abecc41d6c7f416280ebfd6ee696) Thanks [@geekact](https://github.com/geekact)! - 响应未设置 statusCode
- [`d6ac7b5`](https://github.com/aomex/aomex/commit/d6ac7b5403334b51fa15dbe82dd6b5b6d048f661) Thanks [@geekact](https://github.com/geekact)! - response 增加 vary 方法
- [`9254754`](https://github.com/aomex/aomex/commit/9254754d234fc0062eb5d600284ee8453825306c) Thanks [@geekact](https://github.com/geekact)! - response 增加 varyAppend 方法
- [`6056f55`](https://github.com/aomex/aomex/commit/6056f556577865220d6b5be2a4eafad9e4dbf8d4) Thanks [@geekact](https://github.com/geekact)! - request 增加 ip 属性
- [`1c67399`](https://github.com/aomex/aomex/commit/1c673992c4b313c2accb4cbc1fc66537a9886c29) Thanks [@geekact](https://github.com/geekact)! - 导出 HttpError 类型
- [`352642a`](https://github.com/aomex/aomex/commit/352642abf2ccb3fe97e2d83a691d8428ccfc9758) Thanks [@geekact](https://github.com/geekact)! - request 增加 fresh 属性
- Updated dependencies [[`d1ce4e2`](https://github.com/aomex/aomex/commit/d1ce4e2276f93c44e67ea06666d048917fa94e53)]:
- @aomex/core@0.0.2
## 0.0.2
### Patch Changes
- [`cdb1405`](https://github.com/aomex/aomex/commit/cdb1405ccb557c122fc6b6cfdc8b845caacba87c) Thanks [@geekact](https://github.com/geekact)! - 使全局中间件生效
## 0.0.1
### Patch Changes
- Updated dependencies [[`be095e9`](https://github.com/aomex/aomex/commit/be095e964ec136982581f4ea09024f716ff93a3d)]:
- @aomex/helper@0.0.1
- @aomex/core@0.0.1
- Updated dependencies [[`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f)]:
- @aomex/utility@0.0.4
- @aomex/core@0.0.6

118

dist/index.d.ts
import { Chain, PureChain, PureMiddlewareToken, Next, Middleware, OpenAPI, Validator, TransformedValidator, ValidateResult, ValidatorOptions } from '@aomex/core';
import { NonReadonly } from '@aomex/helper';
import { NonReadonly } from '@aomex/utility';
import { Server, RequestListener, ServerResponse, IncomingMessage } from 'node:http';

@@ -28,4 +28,4 @@ import EventEmitter from 'node:events';

interface WebAppOption {
silent?: boolean;
debug?: boolean;
globalChain?: WebChain;
queryParser?: IParseOptions;

@@ -44,3 +44,3 @@ }

on(eventName: string | symbol, listener: (...args: any[]) => void): this;
mount(middleware: WebMiddlewareToken): void;
mount(middleware: WebMiddlewareToken | null): void;
}

@@ -84,5 +84,2 @@

};
/**
* 批量设置头部数据
*/
setHeaders(headers: {

@@ -106,5 +103,2 @@ [K: string]: string | number | readonly string[];

set body(val: Body);
/**
* 判断body是否为JSON格式
*/
isJSON(body: Body): body is object;

@@ -121,11 +115,3 @@ flush(): any;

protected setStatus(code: number): void;
/**
* 根据header设置头部信息
*/
protected determineHeaders(): void;
/**
* 重新整理body=null和状态的关系
* - status-code
* - content-type
*/
protected determineNullBody(): void;

@@ -170,2 +156,4 @@ }

/**
* Throw a http error
*
* ```typescript

@@ -196,7 +184,8 @@ * ctx.throw(403)

/**
* 跳过指定web插件或者web插件集合
* @param token web插件或者web插件集合
* @param options 跳过条件,不传则代表`总是跳过`
* Skip specific middleware or chain
* - by condition: options=`object|function`
* - never skip : options=`false`
* - always skip : options=`true`
*/
declare const skip: <Props extends object = object>(token: WebMiddlewareToken<Props>, options?: WebMiddlewareSkipOptions | NonNullable<WebMiddlewareSkipOptions['custom']>) => WebMiddleware<Props>;
declare function skip<Props extends object, T extends WebMiddlewareSkipOptions | NonNullable<WebMiddlewareSkipOptions['custom']> | boolean>(token: WebMiddlewareToken<Props>, options: T): WebMiddleware<T extends false ? Props : T extends true ? object : Partial<Props>>;

@@ -216,3 +205,3 @@ declare module '@aomex/core' {

constructor(fn: (ctx: NonReadonly<Props> & WebContext, next: Next) => any);
skipIf(options: WebMiddlewareSkipOptions | NonNullable<WebMiddlewareSkipOptions['custom']>): WebMiddleware<Props>;
skipIf(options: WebMiddlewareSkipOptions | NonNullable<WebMiddlewareSkipOptions['custom']>): WebMiddleware<Partial<Props>>;
toDocument(options: WebMiddlewareToDocument): void;

@@ -226,3 +215,2 @@ }

}
type FileSizeUnit = 'B' | 'b' | 'KB' | 'kb' | 'MB' | 'mb' | 'GB' | 'gb' | 'TB' | 'tb';
interface FileValidatorOptions<T> extends ValidatorOptions<T> {

@@ -241,9 +229,12 @@ maxSize?: number;

/**
* @param {String} unit 默认单位:`B`,即字节
* Examples:
* - 1024
* - 2048
* - '15KB'
* - '20MB'
*/
maxSize(amount: number, unit?: FileSizeUnit): this;
maxSize(byte: number | string): this;
/**
* 限制文件的`mime-type`。无论传入标准的格式还是普通的后缀,最终都会转换成标准的mime-types
* ```typescript
* file.mimeTypes('.html', '.js', 'image/*', 'text/plain');
* file.mimeTypes('.html', '.png', 'image/*', 'text/plain');
* ```

@@ -272,18 +263,15 @@ */

/**
* 对请求时的body数据做验证。验证通过后可通过`ctx.body`获得结果
* Validate web request body
*
* ```typescript
* export const router = new Router();
*
* router.post('/users', {
* mount: [
* body({
* name: rule.string(),
* age: rule.int().optional(),
* }),
* ],
* action: async (ctx) => {
* console.log(ctx.body);
* },
* });
* // ctx.request.body = { id: '100', name: 'aomex' };
* chain.web
* .mount(body({
* id: rule.int().max(1000),
* name: rule.string(),
* age: rule.int().default(10)
* }))
* .mount(middleware.web((ctx, next) => {
* console.log(ctx.body); // { id: 100, name: 'aomex', age: 10 }
* }));
* ```

@@ -307,20 +295,14 @@ */

/**
* 对url上的查询字符串做验证。验证通过后可通过`ctx.query`获得结果
* Validate web request querystring
*
* ```typescript
* export const router = new Router();
*
* // https://example.com/users?search=lili&page=1
* router.get('/users', {
* mount: [
* query({
* search: rule.string().optional(),
* page: rule.int().min(1).default(1),
* pageSize: rule.int().min(5).default(10),
* }),
* ],
* action: async (ctx) => {
* console.log(ctx.query);
* },
* });
* // ctx.request.query = { id: '100', name: 'aomex' };
* chain.web
* .mount(query({
* id: rule.int().max(1000),
* name: rule.string(),
* }))
* .mount(middleware.web((ctx, next) => {
* console.log(ctx.query); // { id: 100 }
* }));
* ```

@@ -344,17 +326,13 @@ */

/**
* 验证路径参数。验证通过后可通过`ctx.params`获得结果
* Validate web request path params
*
* ```typescript
* export const router = new Router();
*
* router.put('/users/:id', {
* mount: [
* params({
* id: rule.int().max(1000),
* }),
* ],
* action: async (ctx) => {
* console.log(ctx.params);
* },
* });
* // ctx.request.params = { id: '100', name: 'aomex' };
* chain.web
* .mount(params({
* id: rule.int().max(1000),
* }))
* .mount(middleware.web((ctx, next) => {
* console.log(ctx.params); // { id: 100 }
* }));
* ```

@@ -361,0 +339,0 @@ */

@@ -8,8 +8,12 @@ // src/override/middleware.ts

import { compose, Middleware, middleware } from "@aomex/core";
import { toArray } from "@aomex/helper";
var skip = (token, options) => {
if (!options)
import { toArray } from "@aomex/utility";
function skip(token, options) {
if (options === true) {
return middleware.web((_, next) => next());
}
const originFn = token instanceof Middleware ? token.fn : compose(toArray(token));
if (options === false) {
return middleware.web(originFn);
}
const opts = typeof options === "function" ? { custom: options } : options;
const originFn = token instanceof Middleware ? token.fn : compose(toArray(token));
return middleware.web(async (ctx, next) => {

@@ -19,3 +23,3 @@ const skipped = await shouldSkip(ctx, opts);

});
};
}
var shouldSkip = async (ctx, options) => {

@@ -72,25 +76,13 @@ if (await options.custom?.(ctx))

} from "@aomex/core";
import { bytes } from "@aomex/utility";
var FileValidator = class extends Validator {
/**
* @param {String} unit 默认单位:`B`,即字节
* Examples:
* - 1024
* - 2048
* - '15KB'
* - '20MB'
*/
maxSize(amount, unit = "B") {
let scale;
switch (unit.toUpperCase()) {
case "B":
scale = 1;
break;
case "KB":
scale = 1024;
break;
case "MB":
scale = 1048576;
break;
case "GB":
scale = 1048576 * 1024;
break;
case "TB":
scale = 1048576 * 1048576;
}
this.config.maxSize = amount * scale;
maxSize(byte) {
this.config.maxSize = typeof byte === "number" ? byte : bytes(byte);
return this;

@@ -170,3 +162,3 @@ }

import { Chain as Chain2, compose as compose2 } from "@aomex/core";
import { chalk } from "@aomex/helper";
import { chalk } from "@aomex/utility";

@@ -311,5 +303,2 @@ // src/app/request.ts

}
/**
* 批量设置头部数据
*/
setHeaders(headers) {

@@ -377,5 +366,2 @@ for (const [key, value] of Object.entries(headers)) {

}
/**
* 判断body是否为JSON格式
*/
isJSON(body2) {

@@ -458,5 +444,2 @@ return !(!body2 || typeof body2 === "string" || body2 instanceof Stream || Buffer.isBuffer(body2));

}
/**
* 根据header设置头部信息
*/
determineHeaders() {

@@ -490,7 +473,2 @@ if (this._determineHeaders)

}
/**
* 重新整理body=null和状态的关系
* - status-code
* - content-type
*/
determineNullBody() {

@@ -539,3 +517,3 @@ if (this._determineNullBody || this.body !== null)

if (!this.listenerCount("error")) {
this.on("error", this.log);
this.on("error", this.log.bind(this));
}

@@ -547,2 +525,4 @@ return (req, res) => {

log(err) {
if (this.options.silent)
return;
if ((err.status || err.statusCode) === 404 || err.expose)

@@ -559,4 +539,6 @@ return;

mount(middleware2) {
if (middleware2 === null)
return;
if (middleware2 instanceof Chain2) {
this.chainPoints.push(Chain2.createPoint(middleware2));
this.chainPoints.push(Chain2.createSplitPoint(middleware2));
}

@@ -563,0 +545,0 @@ this.middlewareList.push(middleware2);

{
"name": "@aomex/web",
"version": "0.0.6",
"version": "0.0.7",
"description": "",

@@ -29,6 +29,6 @@ "type": "module",

"peerDependencies": {
"@aomex/core": "^0.0.5"
"@aomex/core": "^0.0.6"
},
"dependencies": {
"@aomex/helper": "^0.0.3",
"@aomex/utility": "^0.0.4",
"@types/accepts": "^1.3.5",

@@ -50,3 +50,3 @@ "@types/content-disposition": "^0.5.5",

"http-errors": "^2.0.0",
"lru-cache": "^7.14.1",
"lru-cache": "^7.17.0",
"mime-types": "^2.1.35",

@@ -61,3 +61,3 @@ "parseurl": "^1.3.3",

"devDependencies": {
"@aomex/core": "^0.0.5",
"@aomex/core": "^0.0.6",
"@types/co-body": "^6.1.0",

@@ -64,0 +64,0 @@ "@types/content-type": "^1.1.5",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc