@zipbul/baker 1.1.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +189 -501
- package/dist/index-fnv35wrf.js +3 -0
- package/dist/index-k3d659ad.js +3 -0
- package/dist/index-s0n74vx1.js +3 -0
- package/dist/index-xdn55cz3.js +0 -3
- package/dist/index.d.ts +5 -6
- package/dist/index.js +212 -211
- package/dist/src/collect.d.ts +0 -2
- package/dist/src/configure.d.ts +0 -6
- package/dist/src/create-rule.d.ts +1 -1
- package/dist/src/decorators/field.d.ts +4 -21
- package/dist/src/decorators/index.d.ts +1 -1
- package/dist/src/decorators/index.js +1 -4
- package/dist/src/errors.d.ts +19 -8
- package/dist/src/functions/_run-sealed.d.ts +7 -0
- package/dist/src/functions/deserialize.d.ts +5 -4
- package/dist/src/functions/index.d.ts +1 -2
- package/dist/src/functions/serialize.d.ts +2 -2
- package/dist/src/functions/validate.d.ts +13 -0
- package/dist/src/rules/index.d.ts +2 -2
- package/dist/src/rules/index.js +8 -11
- package/dist/src/rules/string.d.ts +8 -48
- package/dist/src/symbols.d.ts +0 -2
- package/dist/src/symbols.js +1 -4
- package/dist/src/transformers/collection.transformer.d.ts +3 -0
- package/dist/src/transformers/date.transformer.d.ts +4 -0
- package/dist/src/transformers/index.d.ts +8 -0
- package/dist/src/transformers/index.js +2 -0
- package/dist/src/transformers/luxon.transformer.d.ts +6 -0
- package/dist/src/transformers/moment.transformer.d.ts +5 -0
- package/dist/src/transformers/number.transformer.d.ts +2 -0
- package/dist/src/transformers/string.transformer.d.ts +4 -0
- package/dist/src/types.d.ts +9 -63
- package/package.json +40 -6
- package/README.ko.md +0 -588
- package/dist/index-70ggmxsa.js +0 -6
- package/dist/index-gcptd79v.js +0 -6
- package/dist/src/functions/to-json-schema.d.ts +0 -20
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { trimTransformer, toLowerCaseTransformer, toUpperCaseTransformer } from './string.transformer';
|
|
2
|
+
export { roundTransformer } from './number.transformer';
|
|
3
|
+
export { unixSecondsTransformer, unixMillisTransformer, isoStringTransformer } from './date.transformer';
|
|
4
|
+
export { csvTransformer, jsonTransformer } from './collection.transformer';
|
|
5
|
+
export { luxonTransformer } from './luxon.transformer';
|
|
6
|
+
export type { LuxonTransformerOptions } from './luxon.transformer';
|
|
7
|
+
export { momentTransformer } from './moment.transformer';
|
|
8
|
+
export type { MomentTransformerOptions } from './moment.transformer';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{f as n}from"../../index-s0n74vx1.js";var s={deserialize:({value:r})=>typeof r==="string"?r.trim():r,serialize:({value:r})=>typeof r==="string"?r.trim():r},i={deserialize:({value:r})=>typeof r==="string"?r.toLowerCase():r,serialize:({value:r})=>typeof r==="string"?r.toLowerCase():r},f={deserialize:({value:r})=>typeof r==="string"?r.toUpperCase():r,serialize:({value:r})=>typeof r==="string"?r.toUpperCase():r};function m(r=0){let t=Math.pow(10,r),e=(o)=>typeof o==="number"&&Number.isFinite(o)?Math.round(o*t)/t:o;return{deserialize:({value:o})=>e(o),serialize:({value:o})=>e(o)}}var a={deserialize:({value:r})=>typeof r==="number"?new Date(r*1000):r,serialize:({value:r})=>r instanceof Date?Math.floor(r.getTime()/1000):r},p={deserialize:({value:r})=>typeof r==="number"?new Date(r):r,serialize:({value:r})=>r instanceof Date?r.getTime():r},T={deserialize:({value:r})=>{if(typeof r!=="string")return r;let t=new Date(r);return Number.isNaN(t.getTime())?r:t},serialize:({value:r})=>r instanceof Date?r.toISOString():r};function y(r=","){return{deserialize:({value:t})=>typeof t==="string"?t.split(r):t,serialize:({value:t})=>Array.isArray(t)?t.join(r):t}}var c={deserialize:({value:r})=>{if(typeof r!=="string")return r;try{return JSON.parse(r)}catch{return r}},serialize:({value:r})=>{if(r!=null&&typeof r==="object")return JSON.stringify(r);return r}};async function x(r){let{DateTime:t}=await import("luxon"),e=r?.zone??"utc";return{deserialize:({value:o})=>{if(typeof o==="string")return t.fromISO(o,{zone:e});if(o instanceof Date)return t.fromJSDate(o,{zone:e});return o},serialize:({value:o})=>{if(o&&typeof o==="object"&&typeof o.toISO==="function")return r?.format?o.toFormat(r.format):o.toISO();return o}}}async function z(r){let t=(await import("moment")).default;return{deserialize:({value:e})=>{if(typeof e==="string"||e instanceof Date)return t(e);return e},serialize:({value:e})=>{if(e&&typeof e==="object"&&typeof e.toISOString==="function"&&typeof e.format==="function")return r?.format?e.format(r.format):e.toISOString();return e}}}export{a as unixSecondsTransformer,p as unixMillisTransformer,s as trimTransformer,f as toUpperCaseTransformer,i as toLowerCaseTransformer,m as roundTransformer,z as momentTransformer,x as luxonTransformer,c as jsonTransformer,T as isoStringTransformer,y as csvTransformer};
|
package/dist/src/types.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface EmittableRule {
|
|
|
20
20
|
* @IsString itself is undefined (it includes its own typeof check).
|
|
21
21
|
*/
|
|
22
22
|
readonly requiresType?: 'string' | 'number' | 'boolean' | 'date';
|
|
23
|
-
/** Expose rule parameters for external reading
|
|
23
|
+
/** Expose rule parameters for external reading */
|
|
24
24
|
readonly constraints?: Record<string, unknown>;
|
|
25
25
|
/** true when using an async validate function — deserialize-builder generates await code */
|
|
26
26
|
readonly isAsync?: boolean;
|
|
@@ -40,15 +40,17 @@ export interface RuleDef {
|
|
|
40
40
|
/** Arbitrary value to include in BakerError.context on validation failure */
|
|
41
41
|
context?: unknown;
|
|
42
42
|
}
|
|
43
|
-
/** @Transform callback signature */
|
|
44
|
-
export type TransformFunction = (params: TransformParams) => unknown;
|
|
45
43
|
export interface TransformParams {
|
|
46
44
|
value: unknown;
|
|
47
45
|
key: string;
|
|
48
|
-
/** deserialize: original input object, serialize: class instance */
|
|
49
46
|
obj: Record<string, unknown>;
|
|
50
|
-
type: 'deserialize' | 'serialize';
|
|
51
47
|
}
|
|
48
|
+
export interface Transformer {
|
|
49
|
+
deserialize(params: TransformParams): unknown;
|
|
50
|
+
serialize(params: TransformParams): unknown;
|
|
51
|
+
}
|
|
52
|
+
/** Internal — direction-specific transform function stored after @Field processing */
|
|
53
|
+
export type TransformFunction = (params: TransformParams) => unknown;
|
|
52
54
|
export interface TransformDef {
|
|
53
55
|
fn: TransformFunction;
|
|
54
56
|
options?: {
|
|
@@ -96,7 +98,7 @@ export interface PropertyFlags {
|
|
|
96
98
|
/** @IsNullable() — allow and assign null, reject undefined */
|
|
97
99
|
isNullable?: boolean;
|
|
98
100
|
/** @ValidateIf(cond) — skip all field validation when false */
|
|
99
|
-
validateIf?: (obj: any) => boolean;
|
|
101
|
+
validateIf?: (obj: Record<string, any>) => boolean;
|
|
100
102
|
/** @ValidateNested() — trigger recursive validation for nested DTOs. Used with @Type */
|
|
101
103
|
validateNested?: boolean;
|
|
102
104
|
/** @ValidateNested({ each: true }) — validate nested DTOs per array element */
|
|
@@ -109,7 +111,6 @@ export interface RawPropertyMeta {
|
|
|
109
111
|
exclude: ExcludeDef | null;
|
|
110
112
|
type: TypeDef | null;
|
|
111
113
|
flags: PropertyFlags;
|
|
112
|
-
schema: Record<string, unknown> | ((auto: Record<string, unknown>) => Record<string, unknown>) | null;
|
|
113
114
|
}
|
|
114
115
|
export interface RawClassMeta {
|
|
115
116
|
[propertyKey: string]: RawPropertyMeta;
|
|
@@ -126,61 +127,6 @@ export interface SealedExecutors<T> {
|
|
|
126
127
|
_isAsync: boolean;
|
|
127
128
|
/** true if the serialize direction has async transforms/nested */
|
|
128
129
|
_isSerializeAsync: boolean;
|
|
129
|
-
/** Merged metadata cache
|
|
130
|
+
/** Merged metadata cache — used internally by unseal helper */
|
|
130
131
|
_merged?: RawClassMeta;
|
|
131
132
|
}
|
|
132
|
-
export interface JsonSchema202012 {
|
|
133
|
-
$schema?: string;
|
|
134
|
-
$id?: string;
|
|
135
|
-
$ref?: string;
|
|
136
|
-
$defs?: Record<string, JsonSchema202012>;
|
|
137
|
-
$comment?: string;
|
|
138
|
-
type?: string | string[];
|
|
139
|
-
enum?: unknown[];
|
|
140
|
-
const?: unknown;
|
|
141
|
-
minimum?: number;
|
|
142
|
-
maximum?: number;
|
|
143
|
-
exclusiveMinimum?: number;
|
|
144
|
-
exclusiveMaximum?: number;
|
|
145
|
-
multipleOf?: number;
|
|
146
|
-
minLength?: number;
|
|
147
|
-
maxLength?: number;
|
|
148
|
-
pattern?: string;
|
|
149
|
-
format?: string;
|
|
150
|
-
items?: JsonSchema202012;
|
|
151
|
-
prefixItems?: JsonSchema202012[];
|
|
152
|
-
contains?: JsonSchema202012;
|
|
153
|
-
minContains?: number;
|
|
154
|
-
maxContains?: number;
|
|
155
|
-
minItems?: number;
|
|
156
|
-
maxItems?: number;
|
|
157
|
-
uniqueItems?: boolean;
|
|
158
|
-
properties?: Record<string, JsonSchema202012>;
|
|
159
|
-
required?: string[];
|
|
160
|
-
additionalProperties?: boolean | JsonSchema202012;
|
|
161
|
-
unevaluatedProperties?: boolean | JsonSchema202012;
|
|
162
|
-
patternProperties?: Record<string, JsonSchema202012>;
|
|
163
|
-
propertyNames?: JsonSchema202012;
|
|
164
|
-
minProperties?: number;
|
|
165
|
-
maxProperties?: number;
|
|
166
|
-
dependentRequired?: Record<string, string[]>;
|
|
167
|
-
dependentSchemas?: Record<string, JsonSchema202012>;
|
|
168
|
-
allOf?: JsonSchema202012[];
|
|
169
|
-
anyOf?: JsonSchema202012[];
|
|
170
|
-
oneOf?: JsonSchema202012[];
|
|
171
|
-
not?: JsonSchema202012;
|
|
172
|
-
if?: JsonSchema202012;
|
|
173
|
-
then?: JsonSchema202012;
|
|
174
|
-
else?: JsonSchema202012;
|
|
175
|
-
title?: string;
|
|
176
|
-
description?: string;
|
|
177
|
-
default?: unknown;
|
|
178
|
-
examples?: unknown[];
|
|
179
|
-
deprecated?: boolean;
|
|
180
|
-
readOnly?: boolean;
|
|
181
|
-
writeOnly?: boolean;
|
|
182
|
-
contentEncoding?: string;
|
|
183
|
-
contentMediaType?: string;
|
|
184
|
-
contentSchema?: JsonSchema202012;
|
|
185
|
-
[key: string]: unknown;
|
|
186
|
-
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zipbul/baker",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Fastest decorator-based DTO validation for TypeScript. AOT code generation, 42ns per validation, 163x faster than class-validator. Zero reflect-metadata.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Junhyung Park (https://github.com/parkrevil)",
|
|
7
7
|
"repository": {
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"homepage": "https://github.com/zipbul/baker#readme",
|
|
13
13
|
"keywords": [
|
|
14
14
|
"validation",
|
|
15
|
+
"validator",
|
|
15
16
|
"transform",
|
|
17
|
+
"transformer",
|
|
16
18
|
"decorator",
|
|
17
19
|
"dto",
|
|
18
20
|
"typescript",
|
|
@@ -20,11 +22,15 @@
|
|
|
20
22
|
"type-safe",
|
|
21
23
|
"class-validator",
|
|
22
24
|
"class-transformer",
|
|
25
|
+
"class-validator-alternative",
|
|
26
|
+
"zod-alternative",
|
|
23
27
|
"serialize",
|
|
24
28
|
"deserialize",
|
|
25
29
|
"code-generation",
|
|
30
|
+
"aot",
|
|
26
31
|
"bun",
|
|
27
|
-
"
|
|
32
|
+
"fast-validation",
|
|
33
|
+
"schema-validation"
|
|
28
34
|
],
|
|
29
35
|
"engines": {
|
|
30
36
|
"bun": ">=1.0.0"
|
|
@@ -50,6 +56,10 @@
|
|
|
50
56
|
"./symbols": {
|
|
51
57
|
"import": "./dist/src/symbols.js",
|
|
52
58
|
"types": "./dist/src/symbols.d.ts"
|
|
59
|
+
},
|
|
60
|
+
"./transformers": {
|
|
61
|
+
"import": "./dist/src/transformers/index.js",
|
|
62
|
+
"types": "./dist/src/transformers/index.d.ts"
|
|
53
63
|
}
|
|
54
64
|
},
|
|
55
65
|
"files": [
|
|
@@ -62,14 +72,27 @@
|
|
|
62
72
|
"access": "public",
|
|
63
73
|
"provenance": true
|
|
64
74
|
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"luxon": ">=3.0.0",
|
|
77
|
+
"moment": ">=2.0.0"
|
|
78
|
+
},
|
|
79
|
+
"peerDependenciesMeta": {
|
|
80
|
+
"luxon": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"moment": {
|
|
84
|
+
"optional": true
|
|
85
|
+
}
|
|
86
|
+
},
|
|
65
87
|
"dependencies": {
|
|
66
|
-
"@zipbul/result": "
|
|
88
|
+
"@zipbul/result": "1.0.0"
|
|
67
89
|
},
|
|
68
90
|
"scripts": {
|
|
69
|
-
"build": "bun build index.ts src/decorators/index.ts src/rules/index.ts src/symbols.ts --outdir dist --target bun --format esm --splitting --packages external --
|
|
91
|
+
"build": "bun build index.ts src/decorators/index.ts src/rules/index.ts src/symbols.ts src/transformers/index.ts --outdir dist --target bun --format esm --splitting --packages external --root . --production && tsc -p tsconfig.build.json",
|
|
70
92
|
"typecheck": "tsc --noEmit",
|
|
71
93
|
"test": "bun test",
|
|
72
94
|
"test:coverage": "bun test --coverage",
|
|
95
|
+
"test:memory": "bun run scripts/check-memory.ts",
|
|
73
96
|
"changeset": "changeset",
|
|
74
97
|
"version-packages": "changeset version",
|
|
75
98
|
"release": "changeset publish",
|
|
@@ -79,7 +102,18 @@
|
|
|
79
102
|
"@changesets/cli": "^2.29.8",
|
|
80
103
|
"@commitlint/cli": "^20.4.2",
|
|
81
104
|
"@commitlint/config-conventional": "^20.4.2",
|
|
105
|
+
"@sinclair/typebox": "^0.34.48",
|
|
82
106
|
"@types/bun": "^1.3.9",
|
|
83
|
-
"
|
|
107
|
+
"@types/luxon": "^3.7.1",
|
|
108
|
+
"@types/moment": "^2.13.0",
|
|
109
|
+
"ajv": "^8.18.0",
|
|
110
|
+
"arktype": "^2.2.0",
|
|
111
|
+
"class-transformer": "^0.5.1",
|
|
112
|
+
"class-validator": "^0.15.1",
|
|
113
|
+
"husky": "^9.1.7",
|
|
114
|
+
"mitata": "^1.0.34",
|
|
115
|
+
"reflect-metadata": "^0.2.2",
|
|
116
|
+
"valibot": "^1.3.1",
|
|
117
|
+
"zod": "^4.3.6"
|
|
84
118
|
}
|
|
85
119
|
}
|