@aomex/core
Advanced tools
Comparing version 1.0.2 to 1.0.3
# @aomex/core | ||
## 1.0.3 | ||
### Patch Changes | ||
- [`8826dab`](https://github.com/aomex/aomex/commit/8826dabbc4415144cb008ce1dacbe0e16ac1ffaf) Thanks [@geekact](https://github.com/geekact)! - perf(core): 优化compose函数性能 | ||
- [`71e1a4a`](https://github.com/aomex/aomex/commit/71e1a4ae202ec2d1c289cf807142ce4013ae80b1) Thanks [@geekact](https://github.com/geekact)! - feat(core): 增加stream验证器 | ||
- Updated dependencies []: | ||
- @aomex/internal-tools@1.0.3 | ||
## 1.0.2 | ||
@@ -4,0 +15,0 @@ |
import { OpenAPIV3 } from 'openapi-types'; | ||
export { OpenAPIV3 as OpenAPI } from 'openapi-types'; | ||
import { NonReadonly } from '@aomex/internal-tools'; | ||
import * as stream from 'stream'; | ||
import stream$1 from 'node:stream'; | ||
@@ -100,2 +102,7 @@ declare abstract class I18nFormat<Args extends object | unknown = unknown> { | ||
}; | ||
stream: { | ||
must_be_stream: I18nFormat<{ | ||
label: string; | ||
}>; | ||
}; | ||
dateTime: { | ||
@@ -815,2 +822,17 @@ must_be_date: I18nFormat<{ | ||
declare namespace StreamValidator { | ||
interface Options<T = stream$1.Stream> extends Validator.Options<T> { | ||
} | ||
} | ||
declare class StreamValidator<T = stream$1.Stream> extends Validator<T> { | ||
protected config: StreamValidator.Options<T>; | ||
docs: (docs: Validator.PartialOpenAPISchema, mode?: Validator.DocumentMergeMode) => this; | ||
optional: () => StreamValidator<T | Validator.TOptional>; | ||
nullable: () => StreamValidator<T | null>; | ||
transform: <T1>(fn: Validator.TransformFn<T, T1>) => TransformedValidator<T1>; | ||
protected validateValue(value: stream$1.Stream, _key: string, label: string): magistrate.Result<stream$1.Stream>; | ||
protected copy: () => this; | ||
protected toDocument(): OpenAPIV3.SchemaObject; | ||
} | ||
declare namespace StringValidator { | ||
@@ -981,2 +1003,6 @@ interface Options<T> extends BaseStringValidator.Options<T> { | ||
}[number]>; | ||
/** | ||
* 数据流 | ||
*/ | ||
stream(): StreamValidator<stream.Stream>; | ||
string(): StringValidator<string>; | ||
@@ -1036,2 +1062,2 @@ ulid(): UlidValidator<string>; | ||
export { AnyValidator, ArrayValidator, BaseNumberValidator, BaseStringValidator, BigIntValidator, BooleanValidator, BufferValidator, type CombinedServices, type ComposeFn, DateTimeValidator, EmailValidator, EnumValidator, HashValidator, I18n, I18nFormat, IntValidator, IpValidator, type MiddleWareToken, Middleware, MiddlewareChain, type MiddlewareChainPlatform, type MiddlewarePlatform, MixinMiddleware, MixinMiddlewareChain, type MixinMiddlewareToken, type Next, NumberValidator, ObjectValidator, OneOfValidator, Rule, Service, StringValidator, type TransformedValidator, UlidValidator, UrlValidator, UuidValidator, Validator, ValidatorError, type ValidatorToken, combineServices, compose, flattenMiddlewareToken, i18n, magistrate, mdchain, middleware, rule, toValidator, validate }; | ||
export { AnyValidator, ArrayValidator, BaseNumberValidator, BaseStringValidator, BigIntValidator, BooleanValidator, BufferValidator, type CombinedServices, type ComposeFn, DateTimeValidator, EmailValidator, EnumValidator, HashValidator, I18n, I18nFormat, IntValidator, IpValidator, type MiddleWareToken, Middleware, MiddlewareChain, type MiddlewareChainPlatform, type MiddlewarePlatform, MixinMiddleware, MixinMiddlewareChain, type MixinMiddlewareToken, type Next, NumberValidator, ObjectValidator, OneOfValidator, Rule, Service, StreamValidator, StringValidator, type TransformedValidator, UlidValidator, UrlValidator, UuidValidator, Validator, ValidatorError, type ValidatorToken, combineServices, compose, flattenMiddlewareToken, i18n, magistrate, mdchain, middleware, rule, toValidator, validate }; |
@@ -117,2 +117,5 @@ // src/i18n/i18n-format.ts | ||
}, | ||
stream: { | ||
must_be_stream: "{{label}}\uFF1A\u5FC5\u987B\u662Fstream\u7C7B\u578B" | ||
}, | ||
dateTime: { | ||
@@ -174,2 +177,5 @@ must_be_date: "{{label}}\uFF1A\u5FC5\u987B\u662F\u65F6\u95F4\u7C7B\u578B", | ||
}, | ||
stream: { | ||
must_be_stream: "{{label}}: must be stream" | ||
}, | ||
dateTime: { | ||
@@ -220,3 +226,7 @@ must_be_date: "{{label}}: must be date-time", | ||
// src/middleware/compose.ts | ||
var noop = () => { | ||
}; | ||
var compose = (middlewareList) => { | ||
const total = middlewareList.length; | ||
const fns = middlewareList.map((md) => md["fn"]); | ||
return (ctx, next) => { | ||
@@ -228,5 +238,7 @@ let lastIndex = -1; | ||
} | ||
const fn = i === middlewareList.length ? next : middlewareList[i]["fn"]; | ||
lastIndex = i; | ||
await fn?.(ctx, dispatch.bind(null, i + 1)); | ||
const finished = (lastIndex = i) === total; | ||
const fn = finished ? next : fns[lastIndex]; | ||
if (fn) { | ||
await fn(ctx, finished ? noop : dispatch.bind(null, i + 1)); | ||
} | ||
}; | ||
@@ -1258,2 +1270,19 @@ return dispatch(0); | ||
// src/validator/validators/stream.ts | ||
import stream from "node:stream"; | ||
var StreamValidator = class extends Validator { | ||
validateValue(value, _key, label) { | ||
if (!(value instanceof stream.Stream)) { | ||
return magistrate.fail(i18n.t("core.validator.stream.must_be_stream", { label })); | ||
} | ||
return magistrate.ok(value); | ||
} | ||
toDocument() { | ||
return { | ||
type: "string", | ||
format: "binary" | ||
}; | ||
} | ||
}; | ||
// src/validator/validators/string.ts | ||
@@ -1492,2 +1521,8 @@ var StringValidator = class extends BaseStringValidator { | ||
} | ||
/** | ||
* 数据流 | ||
*/ | ||
stream() { | ||
return new StreamValidator(); | ||
} | ||
string() { | ||
@@ -1587,2 +1622,3 @@ return new StringValidator(); | ||
Service, | ||
StreamValidator, | ||
StringValidator, | ||
@@ -1589,0 +1625,0 @@ UlidValidator, |
{ | ||
"name": "@aomex/core", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "aomex核心库", | ||
@@ -39,5 +39,5 @@ "type": "module", | ||
"openapi-types": "^12.1.3", | ||
"@aomex/internal-tools": "^1.0.2" | ||
"@aomex/internal-tools": "^1.0.3" | ||
}, | ||
"scripts": {} | ||
} |
Sorry, the diff of this file is not supported yet
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
208173
2614
Updated@aomex/internal-tools@^1.0.3