@zipbul/baker 3.4.0 → 4.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/CHANGELOG.md +46 -0
- package/README.md +236 -148
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -10
- package/dist/src/baker.d.ts +26 -0
- package/dist/src/baker.js +1 -0
- package/dist/src/collect.js +1 -26
- package/dist/src/configure.d.ts +7 -1
- package/dist/src/configure.js +1 -43
- package/dist/src/create-rule.d.ts +2 -1
- package/dist/src/create-rule.js +1 -41
- package/dist/src/decorators/field.d.ts +2 -1
- package/dist/src/decorators/field.js +1 -277
- package/dist/src/decorators/index.js +1 -2
- package/dist/src/decorators/recipe.js +1 -23
- package/dist/src/enums.d.ts +51 -0
- package/dist/src/enums.js +1 -0
- package/dist/src/errors.js +1 -52
- package/dist/src/functions/check-call-options.js +1 -51
- package/dist/src/functions/deserialize.js +1 -57
- package/dist/src/functions/serialize.js +1 -52
- package/dist/src/functions/validate.js +1 -49
- package/dist/src/interfaces.js +0 -4
- package/dist/src/meta-access.js +1 -75
- package/dist/src/registry.js +1 -8
- package/dist/src/rule-metadata.js +1 -17
- package/dist/src/rule-plan.d.ts +5 -3
- package/dist/src/rule-plan.js +1 -117
- package/dist/src/rules/array.js +1 -96
- package/dist/src/rules/binary.js +3 -51
- package/dist/src/rules/combinators.js +1 -111
- package/dist/src/rules/common.js +1 -77
- package/dist/src/rules/date.js +1 -35
- package/dist/src/rules/index.js +1 -10
- package/dist/src/rules/locales.js +1 -249
- package/dist/src/rules/number.js +1 -79
- package/dist/src/rules/object.js +1 -49
- package/dist/src/rules/string.js +10 -2033
- package/dist/src/rules/typechecker.js +5 -171
- package/dist/src/seal/circular-analyzer.js +1 -63
- package/dist/src/seal/codegen-utils.js +1 -18
- package/dist/src/seal/deserialize-builder.js +265 -1564
- package/dist/src/seal/enums.d.ts +8 -0
- package/dist/src/seal/enums.js +1 -0
- package/dist/src/seal/expose-validator.js +1 -65
- package/dist/src/seal/seal-state.js +1 -18
- package/dist/src/seal/seal.d.ts +15 -1
- package/dist/src/seal/seal.js +1 -431
- package/dist/src/seal/serialize-builder.js +66 -370
- package/dist/src/seal/validate-meta.js +1 -61
- package/dist/src/symbols.js +1 -13
- package/dist/src/transformers/collection.transformer.js +1 -25
- package/dist/src/transformers/date.transformer.js +1 -18
- package/dist/src/transformers/index.js +1 -6
- package/dist/src/transformers/luxon.transformer.js +1 -34
- package/dist/src/transformers/moment.transformer.js +1 -32
- package/dist/src/transformers/number.transformer.js +1 -8
- package/dist/src/transformers/string.transformer.js +1 -12
- package/dist/src/types.d.ts +11 -10
- package/dist/src/types.js +0 -1
- package/dist/src/utils.js +1 -10
- package/package.json +2 -2
|
@@ -1,32 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
const MOMENT_MISSING = "momentTransformer requires the optional peer dependency 'moment'. Install it with: bun add moment";
|
|
3
|
-
async function momentTransformer(opts) {
|
|
4
|
-
let moment;
|
|
5
|
-
try {
|
|
6
|
-
moment = (await import('moment')).default;
|
|
7
|
-
}
|
|
8
|
-
catch (e) {
|
|
9
|
-
throw new BakerError(MOMENT_MISSING, { cause: e });
|
|
10
|
-
}
|
|
11
|
-
// Hoist format option once so the serialize closure doesn't re-read opts per call
|
|
12
|
-
const format = opts?.format;
|
|
13
|
-
return {
|
|
14
|
-
deserialize: ({ value }) => {
|
|
15
|
-
if (typeof value === 'string' || value instanceof Date) {
|
|
16
|
-
return moment(value);
|
|
17
|
-
}
|
|
18
|
-
return value;
|
|
19
|
-
},
|
|
20
|
-
serialize: ({ value }) => {
|
|
21
|
-
if (value &&
|
|
22
|
-
typeof value === 'object' &&
|
|
23
|
-
typeof value.toISOString === 'function' &&
|
|
24
|
-
typeof value.format === 'function') {
|
|
25
|
-
const v = value;
|
|
26
|
-
return format ? v.format(format) : v.toISOString();
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export { momentTransformer };
|
|
1
|
+
import{BakerError as x}from"../errors.js";const y="momentTransformer requires the optional peer dependency 'moment'. Install it with: bun add moment";async function momentTransformer(w){let g;try{g=(await import("moment")).default}catch(b){throw new x(y,{cause:b})}const j=w?.format;return{deserialize:({value:b})=>{if(typeof b==="string"||b instanceof Date)return g(b);return b},serialize:({value:b})=>{if(b&&typeof b==="object"&&typeof b.toISOString==="function"&&typeof b.format==="function"){const q=b;return j?q.format(j):q.toISOString()}return b}}}export{momentTransformer};
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
export function roundTransformer(
|
|
2
|
-
const factor = Math.pow(10, precision);
|
|
3
|
-
const round = (v) => (typeof v === 'number' && Number.isFinite(v) ? Math.round(v * factor) / factor : v);
|
|
4
|
-
return {
|
|
5
|
-
deserialize: ({ value }) => round(value),
|
|
6
|
-
serialize: ({ value }) => round(value),
|
|
7
|
-
};
|
|
8
|
-
}
|
|
1
|
+
export function roundTransformer(o=0){const e=Math.pow(10,o),n=(r)=>typeof r==="number"&&Number.isFinite(r)?Math.round(r*e)/e:r;return{deserialize:({value:r})=>n(r),serialize:({value:r})=>n(r)}}
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
export const trimTransformer = {
|
|
2
|
-
deserialize: ({ value }) => (typeof value === 'string' ? value.trim() : value),
|
|
3
|
-
serialize: ({ value }) => (typeof value === 'string' ? value.trim() : value),
|
|
4
|
-
};
|
|
5
|
-
export const toLowerCaseTransformer = {
|
|
6
|
-
deserialize: ({ value }) => (typeof value === 'string' ? value.toLowerCase() : value),
|
|
7
|
-
serialize: ({ value }) => (typeof value === 'string' ? value.toLowerCase() : value),
|
|
8
|
-
};
|
|
9
|
-
export const toUpperCaseTransformer = {
|
|
10
|
-
deserialize: ({ value }) => (typeof value === 'string' ? value.toUpperCase() : value),
|
|
11
|
-
serialize: ({ value }) => (typeof value === 'string' ? value.toUpperCase() : value),
|
|
12
|
-
};
|
|
1
|
+
export const trimTransformer={deserialize:({value:r})=>typeof r==="string"?r.trim():r,serialize:({value:r})=>typeof r==="string"?r.trim():r};export const toLowerCaseTransformer={deserialize:({value:r})=>typeof r==="string"?r.toLowerCase():r,serialize:({value:r})=>typeof r==="string"?r.toLowerCase():r};export const toUpperCaseTransformer={deserialize:({value:r})=>typeof r==="string"?r.toUpperCase():r,serialize:({value:r})=>typeof r==="string"?r.toUpperCase():r};
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Result, ResultAsync } from '@zipbul/result';
|
|
2
|
+
import type { CacheKey, CollectionType, RequiredType, RuleOp, RulePlanCheckKind, RulePlanExprKind } from './enums';
|
|
2
3
|
import type { BakerIssue } from './errors';
|
|
3
4
|
import type { RuntimeOptions } from './interfaces';
|
|
4
5
|
export interface EmitContext {
|
|
@@ -26,7 +27,7 @@ export interface EmittableRule {
|
|
|
26
27
|
* Only set for rules that assume a specific type (e.g., isEmail → 'string').
|
|
27
28
|
* `@IsString` itself is undefined (it includes its own typeof check).
|
|
28
29
|
*/
|
|
29
|
-
readonly requiresType?:
|
|
30
|
+
readonly requiresType?: RequiredType;
|
|
30
31
|
/** Expose rule parameters for external reading */
|
|
31
32
|
readonly constraints?: Record<string, unknown>;
|
|
32
33
|
/** true when the rule is explicitly async and must be awaited */
|
|
@@ -37,30 +38,30 @@ export interface InternalRule extends EmittableRule {
|
|
|
37
38
|
readonly plan?: RulePlan;
|
|
38
39
|
}
|
|
39
40
|
export type RulePlanExpr = {
|
|
40
|
-
kind:
|
|
41
|
+
kind: RulePlanExprKind.Value;
|
|
41
42
|
} | {
|
|
42
|
-
kind:
|
|
43
|
+
kind: RulePlanExprKind.Member;
|
|
43
44
|
object: RulePlanExpr;
|
|
44
45
|
property: 'length';
|
|
45
46
|
} | {
|
|
46
|
-
kind:
|
|
47
|
+
kind: RulePlanExprKind.Call0;
|
|
47
48
|
object: RulePlanExpr;
|
|
48
49
|
method: 'getTime';
|
|
49
50
|
} | {
|
|
50
|
-
kind:
|
|
51
|
+
kind: RulePlanExprKind.Literal;
|
|
51
52
|
value: number;
|
|
52
53
|
};
|
|
53
54
|
export type RulePlanCheck = {
|
|
54
|
-
kind:
|
|
55
|
+
kind: RulePlanCheckKind.Compare;
|
|
55
56
|
left: RulePlanExpr;
|
|
56
|
-
op:
|
|
57
|
+
op: RuleOp;
|
|
57
58
|
right: RulePlanExpr;
|
|
58
59
|
} | {
|
|
59
|
-
kind:
|
|
60
|
+
kind: RulePlanCheckKind.And | RulePlanCheckKind.Or;
|
|
60
61
|
checks: RulePlanCheck[];
|
|
61
62
|
};
|
|
62
63
|
export interface RulePlan {
|
|
63
|
-
cacheKey?:
|
|
64
|
+
cacheKey?: CacheKey;
|
|
64
65
|
failure: RulePlanCheck;
|
|
65
66
|
}
|
|
66
67
|
/** Arguments for user-defined message callback */
|
|
@@ -125,7 +126,7 @@ export interface TypeDef {
|
|
|
125
126
|
/** seal() normalization result — cached class after resolving fn() (DTOs only, excluding primitives) */
|
|
126
127
|
resolvedClass?: ClassCtor;
|
|
127
128
|
/** seal() normalization result — Map or Set collection type */
|
|
128
|
-
collection?:
|
|
129
|
+
collection?: CollectionType;
|
|
129
130
|
/** Nested DTO class thunk for Map value / Set element */
|
|
130
131
|
collectionValue?: () => ClassCtor;
|
|
131
132
|
/** seal() normalization result — cached class after resolving collectionValue */
|
package/dist/src/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/src/utils.js
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export function isAsyncFunction(fn) {
|
|
3
|
-
return Object.prototype.toString.call(fn) === '[object AsyncFunction]';
|
|
4
|
-
}
|
|
5
|
-
/** Promise-like detection used to enforce sync/async contract at runtime */
|
|
6
|
-
export function isPromiseLike(value) {
|
|
7
|
-
return ((typeof value === 'object' || typeof value === 'function') &&
|
|
8
|
-
value !== null &&
|
|
9
|
-
typeof value.then === 'function');
|
|
10
|
-
}
|
|
1
|
+
export function isAsyncFunction(b){return Object.prototype.toString.call(b)==="[object AsyncFunction]"}export function isPromiseLike(b){return(typeof b==="object"||typeof b==="function")&&b!==null&&typeof b.then==="function"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zipbul/baker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Bun-only AOT decorator-based DTO validation & serialization. class-validator DX, sealed code generation, zero reflect-metadata.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aot",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"provenance": true
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
|
-
"build": "
|
|
74
|
+
"build": "bash scripts/build.sh",
|
|
75
75
|
"changeset": "changeset",
|
|
76
76
|
"deps:check": "dpdm --no-warning --no-tree --no-output -T index.ts src/",
|
|
77
77
|
"format": "oxfmt",
|