@aomex/core
Advanced tools
Comparing version 0.0.22 to 0.0.23
# @aomex/core | ||
## 0.0.23 | ||
### Patch Changes | ||
- [`7b09277`](https://github.com/aomex/aomex/commit/7b09277136910966f500c8132303c7ddee84340c) Thanks [@geekact](https://github.com/geekact)! - refactor(core): 数组验证器的forceToArray方法参数替换formatter为transform | ||
- [`9c78999`](https://github.com/aomex/aomex/commit/9c78999ebcb2962f30344acfbf6de0733d6fdd41) Thanks [@geekact](https://github.com/geekact)! - fix(core): 注册自定义验证规则无效 | ||
- [`f4b012d`](https://github.com/aomex/aomex/commit/f4b012d98cddb2918479ea05df6c266dd914e53a) Thanks [@geekact](https://github.com/geekact)! - feat(core): 增加`ulid`验证规则 | ||
## 0.0.22 | ||
@@ -4,0 +14,0 @@ |
@@ -298,4 +298,7 @@ export { default as chalk } from 'chalk'; | ||
interface ForceOptions { | ||
/** | ||
* 过滤允许转换为数组的数据 | ||
*/ | ||
filter?: (value: any) => boolean; | ||
formatter?: (value: any) => any[]; | ||
transform?: (value: any) => any[]; | ||
/** | ||
@@ -650,2 +653,17 @@ * 遇到字符串则使用逗号(`/ \s*,\s* /`)分割 | ||
declare namespace UlidValidator { | ||
interface Options<T = string> extends BaseStringValidator.Options<T> { | ||
} | ||
} | ||
declare class UlidValidator<T = string> extends BaseStringValidator<T> { | ||
protected config: UlidValidator.Options<T>; | ||
docs: (docs: Validator.PartialOpenAPISchema, mode?: Validator.DocumentMergeMode) => this; | ||
optional: () => UlidValidator<T | Validator.TOptional>; | ||
nullable: () => UlidValidator<T | null>; | ||
default: (uuid: Validator.ParameterOrFn<T>) => UlidValidator<T | Validator.TDefault>; | ||
transform: <T1>(fn: Validator.TransformFn<T, T1>) => TransformedValidator<T1>; | ||
protected validateValue(ulid: string, key: string, superKeys: string[]): magistrate.Result<string>; | ||
protected toDocument(): OpenAPIV3.SchemaObject; | ||
} | ||
declare class Rule { | ||
@@ -747,2 +765,3 @@ static register<T extends Rule, K extends keyof T>(this: new (...args: any[]) => T, name: K, SubValidator: new (...args: any[]) => Validator): void; | ||
uuid(versions: [UuidValidator.Version, ...UuidValidator.Version[]]): UuidValidator<string>; | ||
ulid(): UlidValidator<string>; | ||
dateTime(): DateTimeValidator<Date>; | ||
@@ -762,3 +781,3 @@ } | ||
/** | ||
* 确保缓存没有过期 | ||
* 查看缓存是否存在 | ||
*/ | ||
@@ -768,3 +787,3 @@ exists(key: string): Promise<boolean>; | ||
* | ||
* 获取缓存。如果没有值并且为提供默认值,则返回`null` | ||
* 获取缓存。如果未找到缓存并且未提供默认值,则返回`null` | ||
* ```typescript | ||
@@ -778,3 +797,9 @@ * await cache.get('non-exist'); // null | ||
/** | ||
* 删除缓存并返回这个值。如果没有值并且为提供默认值,则返回`null` | ||
* 获取缓存后立即将该值从引擎中删除。如果未找到缓存并且未提供默认值,则返回`null` | ||
* | ||
* ```typescript | ||
* await cache.set('key', 'value'); | ||
* await cache.getAndDelete<string>('key'); // 'value' | ||
* await cache.get('key'); // null | ||
* ``` | ||
*/ | ||
@@ -795,3 +820,3 @@ getAndDelete<T>(key: string, defaultValue: T): Promise<T>; | ||
/** | ||
* 设置缓存 | ||
* 设置缓存。可以指定过期时间(毫秒) | ||
* | ||
@@ -817,3 +842,3 @@ * ```typescript | ||
/** | ||
* 删除缓存 | ||
* 删除指定缓存 | ||
*/ | ||
@@ -879,2 +904,2 @@ delete(key: string): Promise<boolean>; | ||
export { AnyValidator, ArrayValidator, BaseNumberValidator, BaseStringValidator, BigIntValidator, BooleanValidator, BufferValidator, Cache, CacheOptions, Chain, ChainPlatform, Compose, DateTimeValidator, EmailValidator, EnumValidator, HashValidator, IntValidator, IpValidator, LengthRange, MemoryCache, MemoryCacheOptions, MiddleWareToken, Middleware, MiddlewarePlatform, MixinLength, Next, NonReadonly, NumberValidator, ObjectValidator, OneOfValidator, PathToFileOptions, PureChain, PureMiddleware, PureMiddlewareToken, Rule, StringValidator, TransformedValidator, Union2Intersection, UuidValidator, ValidateOptions, Validator, ValidatorError, _PureFn, chain, compose, fileToModules, forceValidator, magistrate, middleware, mixinLength, pathToFiles, rule, sleep, toArray, validate }; | ||
export { AnyValidator, ArrayValidator, BaseNumberValidator, BaseStringValidator, BigIntValidator, BooleanValidator, BufferValidator, Cache, CacheOptions, Chain, ChainPlatform, Compose, DateTimeValidator, EmailValidator, EnumValidator, HashValidator, IntValidator, IpValidator, LengthRange, MemoryCache, MemoryCacheOptions, MiddleWareToken, Middleware, MiddlewarePlatform, MixinLength, Next, NonReadonly, NumberValidator, ObjectValidator, OneOfValidator, PathToFileOptions, PureChain, PureMiddleware, PureMiddlewareToken, Rule, StringValidator, TransformedValidator, UlidValidator, Union2Intersection, UuidValidator, ValidateOptions, Validator, ValidatorError, _PureFn, chain, compose, fileToModules, forceValidator, magistrate, middleware, mixinLength, pathToFiles, rule, sleep, toArray, validate }; |
@@ -350,5 +350,5 @@ // src/utility/to-array.ts | ||
} | ||
match(pattern) { | ||
match(pattern2) { | ||
const validator = this.copy(); | ||
validator.config.pattern = pattern; | ||
validator.config.pattern = pattern2; | ||
return validator; | ||
@@ -369,4 +369,4 @@ } | ||
shouldMatchPattern(value, key, superKeys) { | ||
const { pattern } = this.config; | ||
if (pattern && !pattern.test(value)) { | ||
const { pattern: pattern2 } = this.config; | ||
if (pattern2 && !pattern2.test(value)) { | ||
return magistrate.fail("not match regexp", key, superKeys); | ||
@@ -391,7 +391,7 @@ } | ||
toDocument() { | ||
const { lengthRange = {}, pattern } = this.config; | ||
const { lengthRange = {}, pattern: pattern2 } = this.config; | ||
return { | ||
type: "string", | ||
// FIXME: openapi没地方放`pattern.flags` | ||
pattern: pattern ? pattern.source : void 0, | ||
pattern: pattern2 ? pattern2.source : void 0, | ||
minLength: lengthRange.min, | ||
@@ -490,3 +490,3 @@ maxLength: lengthRange.max | ||
stringSeparator, | ||
formatter = (_) => [_] | ||
transform = (_) => [_] | ||
} = force === true ? {} : force; | ||
@@ -499,3 +499,3 @@ if (filter(value)) { | ||
} else { | ||
items = formatter(value); | ||
items = transform(value); | ||
} | ||
@@ -1124,2 +1124,27 @@ } | ||
// src/validator/validators/ulid-validator.ts | ||
var pattern = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/; | ||
var UlidValidator = class extends BaseStringValidator { | ||
validateValue(ulid, key, superKeys) { | ||
let checker; | ||
checker = this.shouldBeString(ulid, key, superKeys); | ||
if (checker) | ||
return checker; | ||
ulid = this.getTrimValue(ulid); | ||
checker = this.shouldMatchPattern(ulid, key, superKeys); | ||
if (checker) | ||
return checker; | ||
if (!pattern.test(ulid)) { | ||
return magistrate.fail(`must be ULID`, key, superKeys); | ||
} | ||
return magistrate.ok(ulid); | ||
} | ||
toDocument() { | ||
return { | ||
...super.toDocument(), | ||
format: "ulid" | ||
}; | ||
} | ||
}; | ||
// src/validator/api/force-validator.ts | ||
@@ -1164,3 +1189,3 @@ function forceValidator(validator) { | ||
static register(name, SubValidator) { | ||
this.constructor.prototype[name] = () => new SubValidator(); | ||
this.prototype[name] = () => new SubValidator(); | ||
} | ||
@@ -1268,2 +1293,5 @@ /** | ||
} | ||
ulid() { | ||
return new UlidValidator(); | ||
} | ||
dateTime() { | ||
@@ -1286,3 +1314,3 @@ return new DateTimeValidator(); | ||
/** | ||
* 确保缓存没有过期 | ||
* 查看缓存是否存在 | ||
*/ | ||
@@ -1312,3 +1340,3 @@ async exists(key) { | ||
/** | ||
* 设置缓存 | ||
* 设置缓存。可以指定过期时间(毫秒) | ||
* | ||
@@ -1340,3 +1368,3 @@ * ```typescript | ||
/** | ||
* 删除缓存 | ||
* 删除指定缓存 | ||
*/ | ||
@@ -1452,9 +1480,9 @@ async delete(key) { | ||
return Promise.all( | ||
patterns.map(async (pattern) => { | ||
pattern = path.posix.resolve(pattern); | ||
if (!hasMagic(pattern, { magicalBraces: true })) { | ||
const stats = await stat(pattern); | ||
patterns.map(async (pattern2) => { | ||
pattern2 = path.posix.resolve(pattern2); | ||
if (!hasMagic(pattern2, { magicalBraces: true })) { | ||
const stats = await stat(pattern2); | ||
if (!stats.isFile()) { | ||
pattern = path.posix.resolve( | ||
pattern, | ||
pattern2 = path.posix.resolve( | ||
pattern2, | ||
`./**/*.{ts,js,mts,mjs,cts,cjs}` | ||
@@ -1464,3 +1492,3 @@ ); | ||
} | ||
return glob(pattern, options2); | ||
return glob(pattern2, options2); | ||
}) | ||
@@ -1525,2 +1553,3 @@ ); | ||
StringValidator, | ||
UlidValidator, | ||
UuidValidator, | ||
@@ -1527,0 +1556,0 @@ Validator, |
{ | ||
"name": "@aomex/core", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
188654
2379
0