@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.
@@ -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
- /** 참조 배열에 등록, 인덱스 반환함수, 배열, Set, 원시값 */
4
+ /** Register in the reference array, return its index functions, arrays, Sets, primitives, etc. */
5
5
  addRef(value: unknown): number;
6
- /** SealedExecutors 객체 참조 배열에 등록중첩 @Type DTO용 */
6
+ /** Register a SealedExecutors object in the reference array for nested @Type DTOs */
7
7
  addExecutor(executor: SealedExecutors<unknown>): number;
8
- /** 에러 코드로 실패 처리 코드 문자열 생성 — path builder 바인딩 */
8
+ /** Generate a failure code string from an error code — path is bound by the builder */
9
9
  fail(code: string): string;
10
- /** 에러 수집 모드 여부 (= !stopAtFirstError) */
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 typeof 가드 삽입 여부를 판단하는 메타.
19
- * 해당 타입을 전제하는 rule만 설정 (예: isEmail → 'string').
20
- * @IsString 자체는 undefined (자체 typeof 포함).
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
- /** 파라미터를 외부에서 읽을 있도록 노출 — toJsonSchema 매핑에 사용 */
23
+ /** Expose rule parameters for external reading */
24
24
  readonly constraints?: Record<string, unknown>;
25
- /** async validate 함수 사용 true — deserialize-builder await 코드를 생성 */
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
- /** 검증 실패 BakerError.message 포함할 */
38
+ /** Value to include in BakerError.message on validation failure */
39
39
  message?: string | ((args: MessageArgs) => string);
40
- /** 검증 실패 BakerError.context 포함할 임의 */
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 원본 객체, serialize: class 인스턴스 */
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() 정규화 결과 — fn() 배열을 반환하면 true */
80
+ /** seal() normalization resulttrue if fn() returns an array */
81
81
  isArray?: boolean;
82
- /** seal() 정규화 결과fn() 해석 캐시된 클래스 (프리미티브 제외, DTO만) */
82
+ /** seal() normalization resultcached 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() — undefined/null validation 전체 skip */
92
+ /** @IsOptional() — skip all validation when undefined/null */
87
93
  isOptional?: boolean;
88
- /** @IsDefined() — undefined 불허 (@IsOptional 오버라이드). 현재 코드는 undefined 거부, null 후속 검증에 위임 */
94
+ /** @IsDefined() — disallow undefined (overrides @IsOptional). Current code rejects only undefined; null is delegated to subsequent validation */
89
95
  isDefined?: boolean;
90
- /** @IsNullable() — null 허용+할당, undefined 거부 */
96
+ /** @IsNullable() — allow and assign null, reject undefined */
91
97
  isNullable?: boolean;
92
- /** @ValidateIf(cond) — false 필드 전체 검증 skip */
98
+ /** @ValidateIf(cond) — skip all field validation when false */
93
99
  validateIf?: (obj: any) => boolean;
94
- /** @ValidateNested() — 중첩 DTO 재귀 검증 트리거. @Type 함께 사용 */
100
+ /** @ValidateNested() — trigger recursive validation for nested DTOs. Used with @Type */
95
101
  validateNested?: boolean;
96
- /** @ValidateNested({ each: true }) — 배열 원소별 중첩 DTO 검증 */
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
- /** 내부 executor — Result 패턴. deserialize() 감싸서 throw 변환 */
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
- /** 내부 executor — 항상 성공. serialize 무검증 전제 */
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 방향에 async 규칙/transform/nested 있으면 true */
124
+ /** true if the deserialize direction has async rules/transforms/nested */
120
125
  _isAsync: boolean;
121
- /** serialize 방향에 async transform/nested 있으면 true */
126
+ /** true if the serialize direction has async transforms/nested */
122
127
  _isSerializeAsync: boolean;
123
- /** seal 병합된 메타데이터 캐시 toJsonSchema에서 사용 (RAW 삭제 후에도 유효) */
128
+ /** Merged metadata cacheused 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": "1.0.0",
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": "^0.1.4"
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
- "husky": "^9.1.7"
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
  }