@zipbul/baker 1.0.0 → 2.0.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 +150 -471
- package/dist/index-btgens0c.js +6 -0
- package/dist/index-k369bbht.js +6 -0
- package/dist/index.d.ts +5 -6
- package/dist/index.js +221 -161
- package/dist/src/collect.d.ts +3 -5
- package/dist/src/configure.d.ts +10 -16
- package/dist/src/create-rule.d.ts +7 -7
- package/dist/src/decorators/field.d.ts +31 -28
- package/dist/src/decorators/index.d.ts +1 -1
- package/dist/src/decorators/index.js +1 -1
- package/dist/src/errors.d.ts +33 -22
- package/dist/src/functions/_run-sealed.d.ts +7 -0
- package/dist/src/functions/deserialize.d.ts +8 -6
- package/dist/src/functions/index.d.ts +1 -2
- package/dist/src/functions/serialize.d.ts +6 -5
- package/dist/src/functions/validate.d.ts +13 -0
- package/dist/src/interfaces.d.ts +7 -7
- package/dist/src/registry.d.ts +4 -4
- package/dist/src/rules/index.d.ts +1 -1
- package/dist/src/rules/index.js +9 -9
- package/dist/src/rules/object.d.ts +1 -1
- package/dist/src/rules/string.d.ts +6 -48
- package/dist/src/seal/circular-analyzer.d.ts +4 -4
- package/dist/src/seal/expose-validator.d.ts +6 -6
- package/dist/src/seal/seal.d.ts +16 -16
- package/dist/src/seal/serialize-builder.d.ts +2 -2
- package/dist/src/symbols.d.ts +4 -6
- package/dist/src/symbols.js +2 -2
- package/dist/src/types.d.ts +34 -84
- package/package.json +13 -3
- package/README.ko.md +0 -588
- package/dist/index-57gr0v18.js +0 -6
- package/dist/index-aegrb1kn.js +0 -6
- package/dist/src/functions/to-json-schema.d.ts +0 -20
package/dist/src/types.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export interface EmitContext {
|
|
2
|
-
/** RegExp
|
|
2
|
+
/** Register a RegExp in the reference array, return its index */
|
|
3
3
|
addRegex(re: RegExp): number;
|
|
4
|
-
/**
|
|
4
|
+
/** Register in the reference array, return its index — functions, arrays, Sets, primitives, etc. */
|
|
5
5
|
addRef(value: unknown): number;
|
|
6
|
-
/** SealedExecutors
|
|
6
|
+
/** Register a SealedExecutors object in the reference array — for nested @Type DTOs */
|
|
7
7
|
addExecutor(executor: SealedExecutors<unknown>): number;
|
|
8
|
-
/**
|
|
8
|
+
/** Generate a failure code string from an error code — path is bound by the builder */
|
|
9
9
|
fail(code: string): string;
|
|
10
|
-
/**
|
|
10
|
+
/** Whether error collection mode is enabled (= !stopAtFirstError) */
|
|
11
11
|
collectErrors: boolean;
|
|
12
12
|
}
|
|
13
13
|
export interface EmittableRule {
|
|
@@ -15,17 +15,17 @@ export interface EmittableRule {
|
|
|
15
15
|
emit(varName: string, ctx: EmitContext): string;
|
|
16
16
|
readonly ruleName: string;
|
|
17
17
|
/**
|
|
18
|
-
* builder
|
|
19
|
-
*
|
|
20
|
-
* @IsString
|
|
18
|
+
* Meta for the builder to determine whether to insert a typeof guard.
|
|
19
|
+
* Only set for rules that assume a specific type (e.g., isEmail → 'string').
|
|
20
|
+
* @IsString itself is undefined (it includes its own typeof check).
|
|
21
21
|
*/
|
|
22
22
|
readonly requiresType?: 'string' | 'number' | 'boolean' | 'date';
|
|
23
|
-
/**
|
|
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;
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
28
|
+
/** Arguments for user-defined message callback */
|
|
29
29
|
export interface MessageArgs {
|
|
30
30
|
property: string;
|
|
31
31
|
value: unknown;
|
|
@@ -35,17 +35,17 @@ export interface RuleDef {
|
|
|
35
35
|
rule: EmittableRule;
|
|
36
36
|
each?: boolean;
|
|
37
37
|
groups?: string[];
|
|
38
|
-
/**
|
|
38
|
+
/** Value to include in BakerError.message on validation failure */
|
|
39
39
|
message?: string | ((args: MessageArgs) => string);
|
|
40
|
-
/**
|
|
40
|
+
/** Arbitrary value to include in BakerError.context on validation failure */
|
|
41
41
|
context?: unknown;
|
|
42
42
|
}
|
|
43
|
-
/** @Transform
|
|
43
|
+
/** @Transform callback signature */
|
|
44
44
|
export type TransformFunction = (params: TransformParams) => unknown;
|
|
45
45
|
export interface TransformParams {
|
|
46
46
|
value: unknown;
|
|
47
47
|
key: string;
|
|
48
|
-
/** deserialize: input
|
|
48
|
+
/** deserialize: original input object, serialize: class instance */
|
|
49
49
|
obj: Record<string, unknown>;
|
|
50
50
|
type: 'deserialize' | 'serialize';
|
|
51
51
|
}
|
|
@@ -77,23 +77,29 @@ export interface TypeDef {
|
|
|
77
77
|
}[];
|
|
78
78
|
};
|
|
79
79
|
keepDiscriminatorProperty?: boolean;
|
|
80
|
-
/** seal()
|
|
80
|
+
/** seal() normalization result — true if fn() returns an array */
|
|
81
81
|
isArray?: boolean;
|
|
82
|
-
/** seal()
|
|
82
|
+
/** seal() normalization result — cached class after resolving fn() (DTOs only, excluding primitives) */
|
|
83
83
|
resolvedClass?: new (...args: any[]) => any;
|
|
84
|
+
/** seal() normalization result — Map or Set collection type */
|
|
85
|
+
collection?: 'Map' | 'Set';
|
|
86
|
+
/** Nested DTO class thunk for Map value / Set element */
|
|
87
|
+
collectionValue?: () => new (...args: any[]) => any;
|
|
88
|
+
/** seal() normalization result — cached class after resolving collectionValue */
|
|
89
|
+
resolvedCollectionValue?: new (...args: any[]) => any;
|
|
84
90
|
}
|
|
85
91
|
export interface PropertyFlags {
|
|
86
|
-
/** @IsOptional() —
|
|
92
|
+
/** @IsOptional() — skip all validation when undefined/null */
|
|
87
93
|
isOptional?: boolean;
|
|
88
|
-
/** @IsDefined() — undefined
|
|
94
|
+
/** @IsDefined() — disallow undefined (overrides @IsOptional). Current code rejects only undefined; null is delegated to subsequent validation */
|
|
89
95
|
isDefined?: boolean;
|
|
90
|
-
/** @IsNullable() — null
|
|
96
|
+
/** @IsNullable() — allow and assign null, reject undefined */
|
|
91
97
|
isNullable?: boolean;
|
|
92
|
-
/** @ValidateIf(cond) —
|
|
98
|
+
/** @ValidateIf(cond) — skip all field validation when false */
|
|
93
99
|
validateIf?: (obj: any) => boolean;
|
|
94
|
-
/** @ValidateNested() —
|
|
100
|
+
/** @ValidateNested() — trigger recursive validation for nested DTOs. Used with @Type */
|
|
95
101
|
validateNested?: boolean;
|
|
96
|
-
/** @ValidateNested({ each: true }) —
|
|
102
|
+
/** @ValidateNested({ each: true }) — validate nested DTOs per array element */
|
|
97
103
|
validateNestedEach?: boolean;
|
|
98
104
|
}
|
|
99
105
|
export interface RawPropertyMeta {
|
|
@@ -103,7 +109,6 @@ export interface RawPropertyMeta {
|
|
|
103
109
|
exclude: ExcludeDef | null;
|
|
104
110
|
type: TypeDef | null;
|
|
105
111
|
flags: PropertyFlags;
|
|
106
|
-
schema: Record<string, unknown> | ((auto: Record<string, unknown>) => Record<string, unknown>) | null;
|
|
107
112
|
}
|
|
108
113
|
export interface RawClassMeta {
|
|
109
114
|
[propertyKey: string]: RawPropertyMeta;
|
|
@@ -112,69 +117,14 @@ import type { RuntimeOptions } from './interfaces';
|
|
|
112
117
|
import type { BakerError } from './errors';
|
|
113
118
|
import type { Result, ResultAsync } from '@zipbul/result';
|
|
114
119
|
export interface SealedExecutors<T> {
|
|
115
|
-
/**
|
|
120
|
+
/** Internal executor — Result pattern. deserialize() wraps and converts to throw */
|
|
116
121
|
_deserialize(input: unknown, options?: RuntimeOptions): Result<T, BakerError[]> | ResultAsync<T, BakerError[]>;
|
|
117
|
-
/**
|
|
122
|
+
/** Internal executor — always succeeds. serialize assumes no validation */
|
|
118
123
|
_serialize(instance: T, options?: RuntimeOptions): Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
119
|
-
/** deserialize
|
|
124
|
+
/** true if the deserialize direction has async rules/transforms/nested */
|
|
120
125
|
_isAsync: boolean;
|
|
121
|
-
/** serialize
|
|
126
|
+
/** true if the serialize direction has async transforms/nested */
|
|
122
127
|
_isSerializeAsync: boolean;
|
|
123
|
-
/**
|
|
128
|
+
/** Merged metadata cache — used internally by unseal helper */
|
|
124
129
|
_merged?: RawClassMeta;
|
|
125
130
|
}
|
|
126
|
-
export interface JsonSchema202012 {
|
|
127
|
-
$schema?: string;
|
|
128
|
-
$id?: string;
|
|
129
|
-
$ref?: string;
|
|
130
|
-
$defs?: Record<string, JsonSchema202012>;
|
|
131
|
-
$comment?: string;
|
|
132
|
-
type?: string | string[];
|
|
133
|
-
enum?: unknown[];
|
|
134
|
-
const?: unknown;
|
|
135
|
-
minimum?: number;
|
|
136
|
-
maximum?: number;
|
|
137
|
-
exclusiveMinimum?: number;
|
|
138
|
-
exclusiveMaximum?: number;
|
|
139
|
-
multipleOf?: number;
|
|
140
|
-
minLength?: number;
|
|
141
|
-
maxLength?: number;
|
|
142
|
-
pattern?: string;
|
|
143
|
-
format?: string;
|
|
144
|
-
items?: JsonSchema202012;
|
|
145
|
-
prefixItems?: JsonSchema202012[];
|
|
146
|
-
contains?: JsonSchema202012;
|
|
147
|
-
minContains?: number;
|
|
148
|
-
maxContains?: number;
|
|
149
|
-
minItems?: number;
|
|
150
|
-
maxItems?: number;
|
|
151
|
-
uniqueItems?: boolean;
|
|
152
|
-
properties?: Record<string, JsonSchema202012>;
|
|
153
|
-
required?: string[];
|
|
154
|
-
additionalProperties?: boolean | JsonSchema202012;
|
|
155
|
-
unevaluatedProperties?: boolean | JsonSchema202012;
|
|
156
|
-
patternProperties?: Record<string, JsonSchema202012>;
|
|
157
|
-
propertyNames?: JsonSchema202012;
|
|
158
|
-
minProperties?: number;
|
|
159
|
-
maxProperties?: number;
|
|
160
|
-
dependentRequired?: Record<string, string[]>;
|
|
161
|
-
dependentSchemas?: Record<string, JsonSchema202012>;
|
|
162
|
-
allOf?: JsonSchema202012[];
|
|
163
|
-
anyOf?: JsonSchema202012[];
|
|
164
|
-
oneOf?: JsonSchema202012[];
|
|
165
|
-
not?: JsonSchema202012;
|
|
166
|
-
if?: JsonSchema202012;
|
|
167
|
-
then?: JsonSchema202012;
|
|
168
|
-
else?: JsonSchema202012;
|
|
169
|
-
title?: string;
|
|
170
|
-
description?: string;
|
|
171
|
-
default?: unknown;
|
|
172
|
-
examples?: unknown[];
|
|
173
|
-
deprecated?: boolean;
|
|
174
|
-
readOnly?: boolean;
|
|
175
|
-
writeOnly?: boolean;
|
|
176
|
-
contentEncoding?: string;
|
|
177
|
-
contentMediaType?: string;
|
|
178
|
-
contentSchema?: JsonSchema202012;
|
|
179
|
-
[key: string]: unknown;
|
|
180
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zipbul/baker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Decorator-based validate + transform with inline code generation. class-validator DX, AOT-level performance, zero reflect-metadata.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Junhyung Park (https://github.com/parkrevil)",
|
|
@@ -63,13 +63,14 @@
|
|
|
63
63
|
"provenance": true
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@zipbul/result": "
|
|
66
|
+
"@zipbul/result": "1.0.0"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
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 --sourcemap=linked --root . --production && tsc -p tsconfig.build.json",
|
|
70
70
|
"typecheck": "tsc --noEmit",
|
|
71
71
|
"test": "bun test",
|
|
72
72
|
"test:coverage": "bun test --coverage",
|
|
73
|
+
"test:memory": "bun run scripts/check-memory.ts",
|
|
73
74
|
"changeset": "changeset",
|
|
74
75
|
"version-packages": "changeset version",
|
|
75
76
|
"release": "changeset publish",
|
|
@@ -79,7 +80,16 @@
|
|
|
79
80
|
"@changesets/cli": "^2.29.8",
|
|
80
81
|
"@commitlint/cli": "^20.4.2",
|
|
81
82
|
"@commitlint/config-conventional": "^20.4.2",
|
|
83
|
+
"@sinclair/typebox": "^0.34.48",
|
|
82
84
|
"@types/bun": "^1.3.9",
|
|
83
|
-
"
|
|
85
|
+
"ajv": "^8.18.0",
|
|
86
|
+
"arktype": "^2.2.0",
|
|
87
|
+
"class-transformer": "^0.5.1",
|
|
88
|
+
"class-validator": "^0.15.1",
|
|
89
|
+
"husky": "^9.1.7",
|
|
90
|
+
"mitata": "^1.0.34",
|
|
91
|
+
"reflect-metadata": "^0.2.2",
|
|
92
|
+
"valibot": "^1.3.1",
|
|
93
|
+
"zod": "^4.3.6"
|
|
84
94
|
}
|
|
85
95
|
}
|