baobox 0.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 +193 -0
- package/dist/compile/bun-fast-path.d.ts +14 -0
- package/dist/compile/bun-fast-path.d.ts.map +1 -0
- package/dist/compile/emit.d.ts +5 -0
- package/dist/compile/emit.d.ts.map +1 -0
- package/dist/compile/index.d.ts +57 -0
- package/dist/compile/index.d.ts.map +1 -0
- package/dist/compile/index.js +4711 -0
- package/dist/compile/index.js.map +65 -0
- package/dist/error/catalog-types.d.ts +30 -0
- package/dist/error/catalog-types.d.ts.map +1 -0
- package/dist/error/collector/advanced.d.ts +5 -0
- package/dist/error/collector/advanced.d.ts.map +1 -0
- package/dist/error/collector/collections-basic.d.ts +5 -0
- package/dist/error/collector/collections-basic.d.ts.map +1 -0
- package/dist/error/collector/collections-derived.d.ts +5 -0
- package/dist/error/collector/collections-derived.d.ts.map +1 -0
- package/dist/error/collector/collections-parameters.d.ts +5 -0
- package/dist/error/collector/collections-parameters.d.ts.map +1 -0
- package/dist/error/collector/collections.d.ts +5 -0
- package/dist/error/collector/collections.d.ts.map +1 -0
- package/dist/error/collector/primitives.d.ts +5 -0
- package/dist/error/collector/primitives.d.ts.map +1 -0
- package/dist/error/collector/shared.d.ts +6 -0
- package/dist/error/collector/shared.d.ts.map +1 -0
- package/dist/error/collector.d.ts +5 -0
- package/dist/error/collector.d.ts.map +1 -0
- package/dist/error/errors.d.ts +23 -0
- package/dist/error/errors.d.ts.map +1 -0
- package/dist/error/index.d.ts +11 -0
- package/dist/error/index.d.ts.map +1 -0
- package/dist/error/index.js +3163 -0
- package/dist/error/index.js.map +53 -0
- package/dist/error/locales/de.d.ts +3 -0
- package/dist/error/locales/de.d.ts.map +1 -0
- package/dist/error/locales/en.d.ts +3 -0
- package/dist/error/locales/en.d.ts.map +1 -0
- package/dist/error/locales/es.d.ts +3 -0
- package/dist/error/locales/es.d.ts.map +1 -0
- package/dist/error/locales/fr.d.ts +3 -0
- package/dist/error/locales/fr.d.ts.map +1 -0
- package/dist/error/locales/ja.d.ts +3 -0
- package/dist/error/locales/ja.d.ts.map +1 -0
- package/dist/error/locales/ko.d.ts +3 -0
- package/dist/error/locales/ko.d.ts.map +1 -0
- package/dist/error/locales/pt.d.ts +3 -0
- package/dist/error/locales/pt.d.ts.map +1 -0
- package/dist/error/locales/shared.d.ts +4 -0
- package/dist/error/locales/shared.d.ts.map +1 -0
- package/dist/error/locales/zh.d.ts +4 -0
- package/dist/error/locales/zh.d.ts.map +1 -0
- package/dist/error/messages.d.ts +7 -0
- package/dist/error/messages.d.ts.map +1 -0
- package/dist/format/format.d.ts +61 -0
- package/dist/format/format.d.ts.map +1 -0
- package/dist/format/index.d.ts +5 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +1475 -0
- package/dist/format/index.js.map +29 -0
- package/dist/guard/guard.d.ts +73 -0
- package/dist/guard/guard.d.ts.map +1 -0
- package/dist/guard/index.d.ts +7 -0
- package/dist/guard/index.d.ts.map +1 -0
- package/dist/guard/index.js +342 -0
- package/dist/guard/index.js.map +11 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8938 -0
- package/dist/index.js.map +104 -0
- package/dist/locale/index.d.ts +124 -0
- package/dist/locale/index.d.ts.map +1 -0
- package/dist/locale/index.js +564 -0
- package/dist/locale/index.js.map +20 -0
- package/dist/schema/build.d.ts +32 -0
- package/dist/schema/build.d.ts.map +1 -0
- package/dist/schema/check.d.ts +6 -0
- package/dist/schema/check.d.ts.map +1 -0
- package/dist/schema/compile.d.ts +16 -0
- package/dist/schema/compile.d.ts.map +1 -0
- package/dist/schema/core-keywords.d.ts +8 -0
- package/dist/schema/core-keywords.d.ts.map +1 -0
- package/dist/schema/core.d.ts +3 -0
- package/dist/schema/core.d.ts.map +1 -0
- package/dist/schema/emitter-advanced.d.ts +6 -0
- package/dist/schema/emitter-advanced.d.ts.map +1 -0
- package/dist/schema/emitter-base.d.ts +8 -0
- package/dist/schema/emitter-base.d.ts.map +1 -0
- package/dist/schema/emitter-derived.d.ts +5 -0
- package/dist/schema/emitter-derived.d.ts.map +1 -0
- package/dist/schema/emitter-reference.d.ts +5 -0
- package/dist/schema/emitter-reference.d.ts.map +1 -0
- package/dist/schema/emitter-types.d.ts +5 -0
- package/dist/schema/emitter-types.d.ts.map +1 -0
- package/dist/schema/emitter-wrapper.d.ts +5 -0
- package/dist/schema/emitter-wrapper.d.ts.map +1 -0
- package/dist/schema/emitter.d.ts +52 -0
- package/dist/schema/emitter.d.ts.map +1 -0
- package/dist/schema/engine.d.ts +61 -0
- package/dist/schema/engine.d.ts.map +1 -0
- package/dist/schema/error-collector.d.ts +4 -0
- package/dist/schema/error-collector.d.ts.map +1 -0
- package/dist/schema/errors.d.ts +7 -0
- package/dist/schema/errors.d.ts.map +1 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +3661 -0
- package/dist/schema/index.js.map +50 -0
- package/dist/schema/parse.d.ts +14 -0
- package/dist/schema/parse.d.ts.map +1 -0
- package/dist/schema/pointer.d.ts +13 -0
- package/dist/schema/pointer.d.ts.map +1 -0
- package/dist/schema/predicates.d.ts +62 -0
- package/dist/schema/predicates.d.ts.map +1 -0
- package/dist/schema/resolve.d.ts +6 -0
- package/dist/schema/resolve.d.ts.map +1 -0
- package/dist/schema/runtime-keywords.d.ts +136 -0
- package/dist/schema/runtime-keywords.d.ts.map +1 -0
- package/dist/schema/schema.d.ts +14 -0
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/schema/shared.d.ts +61 -0
- package/dist/schema/shared.d.ts.map +1 -0
- package/dist/script/generic.d.ts +3 -0
- package/dist/script/generic.d.ts.map +1 -0
- package/dist/script/index.d.ts +7 -0
- package/dist/script/index.d.ts.map +1 -0
- package/dist/script/index.js +3948 -0
- package/dist/script/index.js.map +55 -0
- package/dist/script/literals.d.ts +5 -0
- package/dist/script/literals.d.ts.map +1 -0
- package/dist/script/shared.d.ts +15 -0
- package/dist/script/shared.d.ts.map +1 -0
- package/dist/shared/bytes.d.ts +9 -0
- package/dist/shared/bytes.d.ts.map +1 -0
- package/dist/shared/format-constants.d.ts +16 -0
- package/dist/shared/format-constants.d.ts.map +1 -0
- package/dist/shared/format-validators.d.ts +13 -0
- package/dist/shared/format-validators.d.ts.map +1 -0
- package/dist/shared/locale.d.ts +43 -0
- package/dist/shared/locale.d.ts.map +1 -0
- package/dist/shared/object-utils.d.ts +21 -0
- package/dist/shared/object-utils.d.ts.map +1 -0
- package/dist/shared/regex-json.d.ts +5 -0
- package/dist/shared/regex-json.d.ts.map +1 -0
- package/dist/shared/registries.d.ts +41 -0
- package/dist/shared/registries.d.ts.map +1 -0
- package/dist/shared/runtime-context.d.ts +109 -0
- package/dist/shared/runtime-context.d.ts.map +1 -0
- package/dist/shared/runtime-guards.d.ts +7 -0
- package/dist/shared/runtime-guards.d.ts.map +1 -0
- package/dist/shared/schema-access.d.ts +34 -0
- package/dist/shared/schema-access.d.ts.map +1 -0
- package/dist/shared/utils.d.ts +9 -0
- package/dist/shared/utils.d.ts.map +1 -0
- package/dist/shared/utils.js +1321 -0
- package/dist/shared/utils.js.map +27 -0
- package/dist/standard/index.d.ts +51 -0
- package/dist/standard/index.d.ts.map +1 -0
- package/dist/standard/index.js +4551 -0
- package/dist/standard/index.js.map +66 -0
- package/dist/system/index.d.ts +5 -0
- package/dist/system/index.d.ts.map +1 -0
- package/dist/system/index.js +1632 -0
- package/dist/system/index.js.map +33 -0
- package/dist/system/system.d.ts +154 -0
- package/dist/system/system.d.ts.map +1 -0
- package/dist/type/actions.d.ts +48 -0
- package/dist/type/actions.d.ts.map +1 -0
- package/dist/type/base-types.d.ts +5 -0
- package/dist/type/base-types.d.ts.map +1 -0
- package/dist/type/codec-builtins.d.ts +9 -0
- package/dist/type/codec-builtins.d.ts.map +1 -0
- package/dist/type/combinator-core.d.ts +26 -0
- package/dist/type/combinator-core.d.ts.map +1 -0
- package/dist/type/combinator-functions.d.ts +16 -0
- package/dist/type/combinator-functions.d.ts.map +1 -0
- package/dist/type/combinator-objects.d.ts +30 -0
- package/dist/type/combinator-objects.d.ts.map +1 -0
- package/dist/type/combinators.d.ts +4 -0
- package/dist/type/combinators.d.ts.map +1 -0
- package/dist/type/composite-types.d.ts +39 -0
- package/dist/type/composite-types.d.ts.map +1 -0
- package/dist/type/containers-types.d.ts +47 -0
- package/dist/type/containers-types.d.ts.map +1 -0
- package/dist/type/containers.d.ts +7 -0
- package/dist/type/containers.d.ts.map +1 -0
- package/dist/type/extends.d.ts +32 -0
- package/dist/type/extends.d.ts.map +1 -0
- package/dist/type/extensions.d.ts +86 -0
- package/dist/type/extensions.d.ts.map +1 -0
- package/dist/type/guards.d.ts +78 -0
- package/dist/type/guards.d.ts.map +1 -0
- package/dist/type/index.d.ts +29 -0
- package/dist/type/index.d.ts.map +1 -0
- package/dist/type/index.js +4049 -0
- package/dist/type/index.js.map +51 -0
- package/dist/type/instantiation.d.ts +10 -0
- package/dist/type/instantiation.d.ts.map +1 -0
- package/dist/type/kind.d.ts +76 -0
- package/dist/type/kind.d.ts.map +1 -0
- package/dist/type/narrow-types.d.ts +23 -0
- package/dist/type/narrow-types.d.ts.map +1 -0
- package/dist/type/primitives-types.d.ts +103 -0
- package/dist/type/primitives-types.d.ts.map +1 -0
- package/dist/type/primitives.d.ts +81 -0
- package/dist/type/primitives.d.ts.map +1 -0
- package/dist/type/root-constants.d.ts +65 -0
- package/dist/type/root-constants.d.ts.map +1 -0
- package/dist/type/root-cyclic.d.ts +12 -0
- package/dist/type/root-cyclic.d.ts.map +1 -0
- package/dist/type/root-deferred.d.ts +39 -0
- package/dist/type/root-deferred.d.ts.map +1 -0
- package/dist/type/root-guards.d.ts +15 -0
- package/dist/type/root-guards.d.ts.map +1 -0
- package/dist/type/root-helpers.d.ts +28 -0
- package/dist/type/root-helpers.d.ts.map +1 -0
- package/dist/type/root-instantiate.d.ts +33 -0
- package/dist/type/root-instantiate.d.ts.map +1 -0
- package/dist/type/root-shared.d.ts +14 -0
- package/dist/type/root-shared.d.ts.map +1 -0
- package/dist/type/root-template.d.ts +15 -0
- package/dist/type/root-template.d.ts.map +1 -0
- package/dist/type/schema.d.ts +10 -0
- package/dist/type/schema.d.ts.map +1 -0
- package/dist/type/static-const-types.d.ts +25 -0
- package/dist/type/static-const-types.d.ts.map +1 -0
- package/dist/type/static-shared-types.d.ts +17 -0
- package/dist/type/static-shared-types.d.ts.map +1 -0
- package/dist/type/static-types.d.ts +39 -0
- package/dist/type/static-types.d.ts.map +1 -0
- package/dist/type/string-action-types.d.ts +24 -0
- package/dist/type/string-action-types.d.ts.map +1 -0
- package/dist/type/transform-types.d.ts +54 -0
- package/dist/type/transform-types.d.ts.map +1 -0
- package/dist/type/uint8array-codec.d.ts +8 -0
- package/dist/type/uint8array-codec.d.ts.map +1 -0
- package/dist/type/wrapper-types.d.ts +71 -0
- package/dist/type/wrapper-types.d.ts.map +1 -0
- package/dist/typebox.d.ts +3 -0
- package/dist/typebox.d.ts.map +1 -0
- package/dist/typebox.js +4767 -0
- package/dist/typebox.js.map +55 -0
- package/dist/value/assert.d.ts +8 -0
- package/dist/value/assert.d.ts.map +1 -0
- package/dist/value/check-collections-derived.d.ts +6 -0
- package/dist/value/check-collections-derived.d.ts.map +1 -0
- package/dist/value/check-collections.d.ts +5 -0
- package/dist/value/check-collections.d.ts.map +1 -0
- package/dist/value/check-extensions.d.ts +3 -0
- package/dist/value/check-extensions.d.ts.map +1 -0
- package/dist/value/check-primitives.d.ts +4 -0
- package/dist/value/check-primitives.d.ts.map +1 -0
- package/dist/value/check.d.ts +13 -0
- package/dist/value/check.d.ts.map +1 -0
- package/dist/value/clean.d.ts +4 -0
- package/dist/value/clean.d.ts.map +1 -0
- package/dist/value/clone.d.ts +3 -0
- package/dist/value/clone.d.ts.map +1 -0
- package/dist/value/convert.d.ts +4 -0
- package/dist/value/convert.d.ts.map +1 -0
- package/dist/value/create.d.ts +4 -0
- package/dist/value/create.d.ts.map +1 -0
- package/dist/value/decode.d.ts +4 -0
- package/dist/value/decode.d.ts.map +1 -0
- package/dist/value/default.d.ts +4 -0
- package/dist/value/default.d.ts.map +1 -0
- package/dist/value/diff.d.ts +9 -0
- package/dist/value/diff.d.ts.map +1 -0
- package/dist/value/encode.d.ts +4 -0
- package/dist/value/encode.d.ts.map +1 -0
- package/dist/value/equal.d.ts +3 -0
- package/dist/value/equal.d.ts.map +1 -0
- package/dist/value/has-codec.d.ts +3 -0
- package/dist/value/has-codec.d.ts.map +1 -0
- package/dist/value/hash.d.ts +3 -0
- package/dist/value/hash.d.ts.map +1 -0
- package/dist/value/index.d.ts +145 -0
- package/dist/value/index.d.ts.map +1 -0
- package/dist/value/index.js +4702 -0
- package/dist/value/index.js.map +71 -0
- package/dist/value/mutate.d.ts +3 -0
- package/dist/value/mutate.d.ts.map +1 -0
- package/dist/value/parse.d.ts +13 -0
- package/dist/value/parse.d.ts.map +1 -0
- package/dist/value/patch.d.ts +4 -0
- package/dist/value/patch.d.ts.map +1 -0
- package/dist/value/pipeline.d.ts +6 -0
- package/dist/value/pipeline.d.ts.map +1 -0
- package/dist/value/pointer.d.ts +8 -0
- package/dist/value/pointer.d.ts.map +1 -0
- package/dist/value/repair.d.ts +5 -0
- package/dist/value/repair.d.ts.map +1 -0
- package/dist/value/result.d.ts +10 -0
- package/dist/value/result.d.ts.map +1 -0
- package/docs/locale-packs.md +78 -0
- package/docs/package-contract.md +89 -0
- package/docs/parity-and-extensions.md +56 -0
- package/docs/script-module-registries.md +107 -0
- package/docs/workflows.md +154 -0
- package/package.json +117 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutate.d.ts","sourceRoot":"","sources":["../../src/value/mutate.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,wBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAqB7D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StaticParse, TSchema } from '../type/schema.js';
|
|
2
|
+
import type { ParseResult, SchemaError } from '../error/errors.js';
|
|
3
|
+
import type { RuntimeContext } from '../shared/runtime-context.js';
|
|
4
|
+
/** Error thrown when Value.Parse fails validation */
|
|
5
|
+
export declare class ParseError extends Error {
|
|
6
|
+
readonly errors: SchemaError[];
|
|
7
|
+
constructor(errors: SchemaError[]);
|
|
8
|
+
}
|
|
9
|
+
export declare function TryParse<T extends TSchema>(schema: T, value: unknown, context?: RuntimeContext): ParseResult<StaticParse<T>>;
|
|
10
|
+
/** Full validation pipeline: Clone → Default → Convert → Clean → Check */
|
|
11
|
+
export declare function Parse<T extends TSchema>(schema: T, value: unknown, context?: RuntimeContext): StaticParse<T>;
|
|
12
|
+
export type { ParseFailure, ParseResult, ParseSuccess } from '../error/errors.js';
|
|
13
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/value/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAOnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,qDAAqD;AACrD,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAgB,MAAM,EAAE,WAAW,EAAE,CAAC;gBAC1B,MAAM,EAAE,WAAW,EAAE;CAKlC;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EACxC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAe7B;AAED,0EAA0E;AAC1E,wBAAgB,KAAK,CAAC,CAAC,SAAS,OAAO,EACrC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,CAAC,CAAC,CAMhB;AAED,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../src/value/patch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAG1C,uDAAuD;AACvD,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,CAMvD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TSchema } from '../type/schema.js';
|
|
2
|
+
/** A pipeline stage that transforms a value */
|
|
3
|
+
export type PipelineStage = (schema: TSchema, value: unknown) => unknown;
|
|
4
|
+
/** Create a composable pipeline of value transformation stages */
|
|
5
|
+
export declare function Pipeline(stages: PipelineStage[]): (schema: TSchema, value: unknown) => unknown;
|
|
6
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/value/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,+CAA+C;AAC/C,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AAEzE,kEAAkE;AAClE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAQ9F"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare namespace Pointer {
|
|
2
|
+
function Get(value: unknown, pointer: string): unknown;
|
|
3
|
+
function Set(value: unknown, pointer: string, setValue: unknown): unknown;
|
|
4
|
+
function Delete(value: unknown, pointer: string): unknown;
|
|
5
|
+
function Has(value: unknown, pointer: string): boolean;
|
|
6
|
+
function Create(...tokens: string[]): string;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=pointer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pointer.d.ts","sourceRoot":"","sources":["../../src/value/pointer.ts"],"names":[],"mappings":"AAqFA,yBAAiB,OAAO,CAAC;IACvB,SAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAa5D;IAED,SAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CA4B/E;IAED,SAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAiB/D;IAED,SAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAY5D;IAED,SAAgB,MAAM,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAGlD;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StaticParse, TSchema } from '../type/schema.js';
|
|
2
|
+
import type { RuntimeContext } from '../shared/runtime-context.js';
|
|
3
|
+
/** Repair a value to conform to a schema. Returns a new value (does not mutate). */
|
|
4
|
+
export declare function Repair<T extends TSchema>(schema: T, value: unknown, context?: RuntimeContext): StaticParse<T>;
|
|
5
|
+
//# sourceMappingURL=repair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repair.d.ts","sourceRoot":"","sources":["../../src/value/repair.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EASX,OAAO,EAGR,MAAM,mBAAmB,CAAC;AAM3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAInE,oFAAoF;AACpF,wBAAgB,MAAM,CAAC,CAAC,SAAS,OAAO,EACtC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,CAAC,CAAC,CAehB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Static, StaticDecode, StaticEncode, StaticParse, TSchema } from '../type/schema.js';
|
|
2
|
+
import type { ParseResult } from '../error/errors.js';
|
|
3
|
+
import { Explain } from '../error/errors.js';
|
|
4
|
+
import type { RuntimeContext } from '../shared/runtime-context.js';
|
|
5
|
+
export declare function TryCreate<T extends TSchema>(schema: T, context?: RuntimeContext): ParseResult<Static<T>>;
|
|
6
|
+
export declare function TryDecode<T extends TSchema>(schema: T, value: unknown, context?: RuntimeContext): ParseResult<StaticDecode<T>>;
|
|
7
|
+
export declare function TryEncode<T extends TSchema>(schema: T, value: unknown, context?: RuntimeContext): ParseResult<StaticEncode<T>>;
|
|
8
|
+
export declare function TryRepair<T extends TSchema>(schema: T, value: unknown, context?: RuntimeContext): ParseResult<StaticParse<T>>;
|
|
9
|
+
export { Explain };
|
|
10
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/value/result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAClG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAU,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAOnE,wBAAgB,SAAS,CAAC,CAAC,SAAS,OAAO,EACzC,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAKxB;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,OAAO,EACzC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAM9B;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,OAAO,EACzC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAK9B;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,OAAO,EACzC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAK7B;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Work With Official Locale Packs and Registry Scoping
|
|
2
|
+
|
|
3
|
+
Baobox preloads an official locale bundle for every declared locale code. Those bundles are exported through `baobox/locale` and registered into the default runtime context automatically.
|
|
4
|
+
|
|
5
|
+
## What `baobox/locale` Exports
|
|
6
|
+
|
|
7
|
+
`baobox/locale` exports:
|
|
8
|
+
|
|
9
|
+
- A default `LocalePacks` object keyed by locale code
|
|
10
|
+
- Named exports for every declared locale code such as `en_US`, `ko_KR`, `it_IT`, and `zh_Hant`
|
|
11
|
+
- `OfficialLocaleCatalogs` for code that wants the full typed registry map
|
|
12
|
+
|
|
13
|
+
That means these are equivalent:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import LocalePacks, { ko_KR } from 'baobox/locale'
|
|
17
|
+
|
|
18
|
+
LocalePacks.ko_KR === ko_KR
|
|
19
|
+
// true
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Use The Process-Default Registry
|
|
23
|
+
|
|
24
|
+
The default runtime is already seeded with every declared locale bundle, so switching the active locale is enough for the common path.
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { Errors, String } from 'baobox'
|
|
28
|
+
import { System } from 'baobox/system'
|
|
29
|
+
|
|
30
|
+
System.Locale.Set(System.Locale.ko_KR)
|
|
31
|
+
|
|
32
|
+
Errors(String(), 42)
|
|
33
|
+
// [{ path: '/', code: 'INVALID_TYPE', message: 'string이어야 합니다. 현재 값 유형: number' }]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Seed A Scoped Runtime Explicitly
|
|
37
|
+
|
|
38
|
+
Import bundles from `baobox/locale` when you want an isolated runtime context with explicit locale registration.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import LocalePacks from 'baobox/locale'
|
|
42
|
+
import { CreateRuntimeContext, Errors, LocaleCodes, String } from 'baobox'
|
|
43
|
+
|
|
44
|
+
const context = CreateRuntimeContext({ localeCatalogs: [] })
|
|
45
|
+
|
|
46
|
+
context.Locale.Register(LocaleCodes.it_IT, LocalePacks.it_IT)
|
|
47
|
+
context.Locale.Set(LocaleCodes.it_IT)
|
|
48
|
+
|
|
49
|
+
Errors(String(), 42, context)
|
|
50
|
+
// [{ path: '/', code: 'INVALID_TYPE', message: 'Expected string, got number' }]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Add A Project-Specific Catalog
|
|
54
|
+
|
|
55
|
+
You can layer a custom locale on top of a shipped bundle.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import LocalePacks from 'baobox/locale'
|
|
59
|
+
import { CreateRuntimeContext, Errors, String } from 'baobox'
|
|
60
|
+
|
|
61
|
+
const context = CreateRuntimeContext({ localeCatalogs: [] })
|
|
62
|
+
|
|
63
|
+
context.Locale.Register('en_TEST', {
|
|
64
|
+
...LocalePacks.en_US,
|
|
65
|
+
INVALID_TYPE: () => 'yarrr-invalid-type',
|
|
66
|
+
})
|
|
67
|
+
context.Locale.Set('en_TEST')
|
|
68
|
+
|
|
69
|
+
Errors(String(), 42, context)
|
|
70
|
+
// [{ path: '/', code: 'INVALID_TYPE', message: 'yarrr-invalid-type' }]
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Translation Coverage
|
|
74
|
+
|
|
75
|
+
- Every declared locale code has an official bundle, so declared codes do not fall back through the registry lookup path.
|
|
76
|
+
- Native translated catalogs currently ship for `de_DE`, `en_US`, the Spanish family (`es_419`, `es_AR`, `es_ES`, `es_MX`), the French family (`fr_CA`, `fr_FR`), `ja_JP`, `ko_KR`, the Portuguese family (`pt_BR`, `pt_PT`), and both Chinese packs (`zh_Hans`, `zh_Hant`).
|
|
77
|
+
- Remaining official bundles currently alias the English catalog until native translations are added.
|
|
78
|
+
- Unknown locale identifiers still fall back to English unless you register them yourself.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Package Contract and Supported Imports
|
|
2
|
+
|
|
3
|
+
This document describes the supported public import surface for baobox.
|
|
4
|
+
|
|
5
|
+
## Resolution Behavior
|
|
6
|
+
|
|
7
|
+
Baobox publishes export-condition entries in `package.json`.
|
|
8
|
+
|
|
9
|
+
| Consumer | Resolution target |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| Bun | raw `src/*.ts` entrypoints through the `bun` condition |
|
|
12
|
+
| Standard ESM | built `dist/*.js` entrypoints through the `import` condition |
|
|
13
|
+
| TypeScript | generated `dist/*.d.ts` declarations through the `types` condition |
|
|
14
|
+
|
|
15
|
+
That means Bun consumers can work directly against the source entrypoints without a prebuild, while published ESM consumers use the generated distribution files.
|
|
16
|
+
|
|
17
|
+
The build writes JavaScript to `dist/index.js`, `dist/value/index.js`, and the matching subpath directories, so the emitted files and the export map stay in sync.
|
|
18
|
+
|
|
19
|
+
## Supported Public Entrypoints
|
|
20
|
+
|
|
21
|
+
These are the supported package imports:
|
|
22
|
+
|
|
23
|
+
- `baobox`
|
|
24
|
+
- `baobox/type`
|
|
25
|
+
- `baobox/value`
|
|
26
|
+
- `baobox/schema`
|
|
27
|
+
- `baobox/error`
|
|
28
|
+
- `baobox/compile`
|
|
29
|
+
- `baobox/format`
|
|
30
|
+
- `baobox/guard`
|
|
31
|
+
- `baobox/system`
|
|
32
|
+
- `baobox/script`
|
|
33
|
+
- `baobox/locale`
|
|
34
|
+
- `baobox/standard`
|
|
35
|
+
|
|
36
|
+
## What Each Entrypoint Is For
|
|
37
|
+
|
|
38
|
+
| Entrypoint | Purpose |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `baobox` | Root TypeBox-style builders plus the common value and compile helpers |
|
|
41
|
+
| `baobox/type` | Type builders, transforms, root helpers, and static type exports |
|
|
42
|
+
| `baobox/value` | Runtime value operations such as `Check`, `Parse`, `Errors`, `Repair`, `Diff`, and `Patch` |
|
|
43
|
+
| `baobox/schema` | Raw schema runtime helpers plus baobox schema emitter helpers |
|
|
44
|
+
| `baobox/error` | Structured validation error surface |
|
|
45
|
+
| `baobox/compile` | `Compile`, `Code`, and `Validator` |
|
|
46
|
+
| `baobox/format` | Format registry and format helpers |
|
|
47
|
+
| `baobox/guard` | Guard namespaces aligned with the TypeBox-style guard surface |
|
|
48
|
+
| `baobox/system` | Runtime settings, locale, hashing, memory, and environment helpers |
|
|
49
|
+
| `baobox/script` | Script DSL helpers |
|
|
50
|
+
| `baobox/locale` | Official per-locale catalog bundles for the declared locale registry |
|
|
51
|
+
| `baobox/standard` | Standard Schema V1 adapter helpers for typed and raw-schema interop |
|
|
52
|
+
|
|
53
|
+
## Supported vs Internal Imports
|
|
54
|
+
|
|
55
|
+
Supported:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { Object, String } from 'baobox'
|
|
59
|
+
import { Errors } from 'baobox/value'
|
|
60
|
+
import { System } from 'baobox/system'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Internal to this repository:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { Errors } from '../src/value/index.ts'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Direct `src/*` imports appear in this repository's tests because they validate the source tree before publishing. They are not part of the public package contract for consumers.
|
|
70
|
+
|
|
71
|
+
## Root Import Expectations
|
|
72
|
+
|
|
73
|
+
The root entrypoint supports both styles:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import Type from 'baobox'
|
|
77
|
+
import { Object, String } from 'baobox'
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The default namespace is convenient for builder-heavy code. Named imports are usually better when you want a small explicit surface.
|
|
81
|
+
|
|
82
|
+
## `baobox/schema` Is Intentionally Split
|
|
83
|
+
|
|
84
|
+
`baobox/schema` contains two related but distinct capabilities:
|
|
85
|
+
|
|
86
|
+
- A raw `typebox/schema`-style runtime surface for checking, parsing, compiling, pointer access, and resolving raw schema objects.
|
|
87
|
+
- The baobox schema emitter helpers that project baobox schemas to JSON-Schema-like output.
|
|
88
|
+
|
|
89
|
+
That split is intentional. The raw schema runtime and the baobox emitter solve different problems, but they live behind the same subpath.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Parity Policy and Baobox-Only Additions
|
|
2
|
+
|
|
3
|
+
Baobox aims for TypeBox compatibility without pretending to be a thin wrapper around upstream `typebox`.
|
|
4
|
+
|
|
5
|
+
## Parity Rules
|
|
6
|
+
|
|
7
|
+
Baobox maintains parity with two different expectations:
|
|
8
|
+
|
|
9
|
+
1. Root exports are treated as an upstream-complete superset.
|
|
10
|
+
2. The `compile`, `error`, `format`, `guard`, `system`, and `value` subpaths are runtime-parity tested against the installed `typebox` package.
|
|
11
|
+
|
|
12
|
+
That means upstream-compatible code should keep working, while baobox can still publish Bun-first additions.
|
|
13
|
+
|
|
14
|
+
## What "Superset" Means at Root
|
|
15
|
+
|
|
16
|
+
The root entrypoint must continue to expose the upstream root helpers. Baobox-specific helpers are allowed to remain public as long as they do not break upstream-compatible usage.
|
|
17
|
+
|
|
18
|
+
This is why root parity is tested as upstream-subset parity instead of exact key equality.
|
|
19
|
+
|
|
20
|
+
## What Counts as a Baobox Addition
|
|
21
|
+
|
|
22
|
+
Current baobox-specific improvements include:
|
|
23
|
+
|
|
24
|
+
- Bun-first package exports through the `bun` condition
|
|
25
|
+
- `TryParse()` and `Validator.TryParse()` for structured, non-throwing normalization results
|
|
26
|
+
- `TryDecode()`, `TryEncode()`, `TryCreate()`, and `TryRepair()` for result-first codec and value workflows
|
|
27
|
+
- `Explain()` for localized diagnostics that preserve raw issue metadata
|
|
28
|
+
- `Uint8ArrayCodec()` for base64 JSON payloads and runtime byte values
|
|
29
|
+
- `DateCodec()`, `URLCodec()`, and `BigIntCodec()` for common interop-heavy values
|
|
30
|
+
- Bun-native binary fast paths inside `Compile()` for byte-oriented schemas
|
|
31
|
+
- Compile caching plus portable validator artifacts
|
|
32
|
+
- Locale-aware validation messages and registries driven from `baobox/system`
|
|
33
|
+
- Official locale bundles for every declared locale code through `baobox/locale`
|
|
34
|
+
- Standard Schema V1 adapters through `baobox/standard`
|
|
35
|
+
|
|
36
|
+
These improvements extend the package, but they do not change the public `SchemaError` shape or the pass/fail semantics of validation.
|
|
37
|
+
|
|
38
|
+
## Stability Expectations
|
|
39
|
+
|
|
40
|
+
Baobox keeps the following compatibility boundaries stable:
|
|
41
|
+
|
|
42
|
+
- `SchemaError` stays `{ path, message, code }`
|
|
43
|
+
- `Parse(schema, value)` remains the throwing parity path; `TryParse(schema, value)` is the baobox-only extension
|
|
44
|
+
- `System.Locale` remains the default-process configuration entry point for localized error messages
|
|
45
|
+
- `CreateRuntimeContext()` scopes registries, locale catalogs, and compile caching without changing the default globals
|
|
46
|
+
- Published consumers should only rely on package entrypoints, not `src/*`
|
|
47
|
+
- Subpath parity tests remain the guardrail for TypeBox-aligned runtime behavior
|
|
48
|
+
|
|
49
|
+
## `baobox/schema` Is Not a Wrapper Layer
|
|
50
|
+
|
|
51
|
+
`baobox/schema` intentionally combines:
|
|
52
|
+
|
|
53
|
+
- a raw `typebox/schema`-style runtime surface, and
|
|
54
|
+
- baobox's schema emitter helpers
|
|
55
|
+
|
|
56
|
+
That makes it broader than upstream's split without introducing a compatibility shim or bridge layer.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Use Script, Module, and Custom Registries
|
|
2
|
+
|
|
3
|
+
Baobox keeps the TypeBox-style builder APIs, but it also supports a TypeScript-like DSL, named definition modules, and runtime registries for project-specific validation.
|
|
4
|
+
|
|
5
|
+
## Script DSL
|
|
6
|
+
|
|
7
|
+
Use `Script()` when the schema is easier to read as a compact type expression.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { Check, Script } from 'baobox'
|
|
11
|
+
|
|
12
|
+
const Users = Script('Array<{ name: string; age?: number }>')
|
|
13
|
+
|
|
14
|
+
Check(Users, [{ name: 'Ada' }, { name: 'Grace', age: 37 }])
|
|
15
|
+
// true
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
For reusable named definitions, use `ScriptWithDefinitions()`.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { Check, Object, ScriptWithDefinitions, String } from 'baobox'
|
|
22
|
+
|
|
23
|
+
const User = Object({ name: String() }, { required: ['name'] })
|
|
24
|
+
const Users = ScriptWithDefinitions('Array<User>', { User })
|
|
25
|
+
|
|
26
|
+
Check(Users, [{ name: 'Ada' }])
|
|
27
|
+
// true
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Module and Import
|
|
31
|
+
|
|
32
|
+
Use `Module()` when you want a small schema registry with named definitions, then resolve a concrete definition with `Import()`.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { Check, Import, Module, Object, String } from 'baobox'
|
|
36
|
+
|
|
37
|
+
const Models = Module({
|
|
38
|
+
User: Object({
|
|
39
|
+
id: String(),
|
|
40
|
+
name: String(),
|
|
41
|
+
}, { required: ['id', 'name'] }),
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const User = Import(Models, 'User')
|
|
45
|
+
|
|
46
|
+
Check(User, { id: 'usr_1', name: 'Ada' })
|
|
47
|
+
// true
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`module.Import(name)` returns a `Ref` schema. `Import(module, name)` returns the concrete definition directly.
|
|
51
|
+
|
|
52
|
+
## FormatRegistry
|
|
53
|
+
|
|
54
|
+
Use the format registry for new string formats.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { Check, FormatRegistry, String } from 'baobox'
|
|
58
|
+
|
|
59
|
+
FormatRegistry.Set('doc-slug', (value) => /^[a-z0-9-]+$/.test(value))
|
|
60
|
+
|
|
61
|
+
const Slug = String({ format: 'doc-slug' })
|
|
62
|
+
|
|
63
|
+
Check(Slug, 'docs-ready')
|
|
64
|
+
// true
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## TypeRegistry
|
|
68
|
+
|
|
69
|
+
Use the type registry for custom `~kind` validators.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { Check, TypeRegistry, type TSchema } from 'baobox'
|
|
73
|
+
|
|
74
|
+
TypeRegistry.Set('PositiveNumber', (_schema, value) =>
|
|
75
|
+
typeof value === 'number' && value > 0
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const PositiveNumber: TSchema = { '~kind': 'PositiveNumber' }
|
|
79
|
+
|
|
80
|
+
Check(PositiveNumber, 3)
|
|
81
|
+
// true
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Registry notes:
|
|
85
|
+
|
|
86
|
+
- Keep custom names stable. They become part of your schema contract.
|
|
87
|
+
- Clean up temporary test-only registrations with `Delete()`.
|
|
88
|
+
- `TypeRegistry` affects runtime validation. It does not add JSON Schema emission automatically.
|
|
89
|
+
|
|
90
|
+
## Codec
|
|
91
|
+
|
|
92
|
+
Use `Codec()` when you want typed decode and encode transforms without writing callback casts.
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { Codec, String } from 'baobox'
|
|
96
|
+
import { Decode, Encode } from 'baobox/value'
|
|
97
|
+
|
|
98
|
+
const Trimmed = Codec(String())
|
|
99
|
+
.Decode((value) => value.trim())
|
|
100
|
+
.Encode((value) => value.toUpperCase())
|
|
101
|
+
|
|
102
|
+
Decode(Trimmed, ' ada ')
|
|
103
|
+
// "ada"
|
|
104
|
+
|
|
105
|
+
Encode(Trimmed, 'ada')
|
|
106
|
+
// "ADA"
|
|
107
|
+
```
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Choose Check vs TryParse vs Parse vs Compile
|
|
2
|
+
|
|
3
|
+
Baobox exposes a result-first runtime family around the familiar TypeBox-style surface. The workflows share the same schema model, but they answer different questions.
|
|
4
|
+
|
|
5
|
+
| Need | API | Returns | Use when |
|
|
6
|
+
| --- | --- | --- | --- |
|
|
7
|
+
| Boolean validation | `Check(schema, value)` | `boolean` | You only need pass or fail |
|
|
8
|
+
| Normalize without exceptions | `TryParse(schema, value)` | `ParseResult<T>` | You want normalized output and structured errors without throwing |
|
|
9
|
+
| Codec decode without exceptions | `TryDecode(schema, value)` | `ParseResult<T>` | You want decoded output and structured failures |
|
|
10
|
+
| Codec encode without exceptions | `TryEncode(schema, value)` | `ParseResult<T>` | You want encoded output without throw-based control flow |
|
|
11
|
+
| Create defaults without exceptions | `TryCreate(schema)` | `ParseResult<T>` | You want generated defaults plus validation evidence |
|
|
12
|
+
| Repair without exceptions | `TryRepair(schema, value)` | `ParseResult<T>` | You want a corrected value and structured failures |
|
|
13
|
+
| Normalize then validate | `Parse(schema, value)` | normalized value or throws `ParseError` | You want defaults, conversions, and cleanup before validation |
|
|
14
|
+
| Explain failures with diagnostics | `Explain(schema, value)` | diagnostics array | You want raw issue codes, params, locale, and message |
|
|
15
|
+
| Reusable hot-path validator | `Compile(schema)` / `CompileCached(schema)` | `Validator` | You will validate the same schema repeatedly |
|
|
16
|
+
|
|
17
|
+
## Check
|
|
18
|
+
|
|
19
|
+
Use `Check` when you want the lowest-friction runtime guard.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { Check, Object, String } from 'baobox'
|
|
23
|
+
|
|
24
|
+
const User = Object({
|
|
25
|
+
id: String(),
|
|
26
|
+
name: String(),
|
|
27
|
+
}, { required: ['id', 'name'] })
|
|
28
|
+
|
|
29
|
+
Check(User, { id: 'usr_1', name: 'Ada' })
|
|
30
|
+
// true
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## TryParse
|
|
34
|
+
|
|
35
|
+
`TryParse` runs the full value pipeline in this order:
|
|
36
|
+
|
|
37
|
+
1. `Clone`
|
|
38
|
+
2. `Default`
|
|
39
|
+
3. `Convert`
|
|
40
|
+
4. `Clean`
|
|
41
|
+
5. `Check`
|
|
42
|
+
|
|
43
|
+
Use it when the caller wants normalized output and structured errors without exception control flow.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { Number, Object, TryParse } from 'baobox'
|
|
47
|
+
|
|
48
|
+
const Counter = Object({
|
|
49
|
+
count: Number(),
|
|
50
|
+
}, { required: ['count'], additionalProperties: false })
|
|
51
|
+
|
|
52
|
+
TryParse(Counter, { count: '5', extra: true })
|
|
53
|
+
// { success: true, value: { count: 5 } }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Parse
|
|
57
|
+
|
|
58
|
+
`Parse` runs the full value pipeline in this order:
|
|
59
|
+
|
|
60
|
+
1. `Clone`
|
|
61
|
+
2. `Default`
|
|
62
|
+
3. `Convert`
|
|
63
|
+
4. `Clean`
|
|
64
|
+
5. `Check`
|
|
65
|
+
|
|
66
|
+
That makes it the right choice for request payloads and config-like inputs.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { Object, Number, Optional, Parse, String } from 'baobox'
|
|
70
|
+
|
|
71
|
+
const Counter = Object({
|
|
72
|
+
count: Number(),
|
|
73
|
+
label: Optional(String()),
|
|
74
|
+
}, {
|
|
75
|
+
required: ['count'],
|
|
76
|
+
optional: ['label'],
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
Parse(Counter, { count: '5', extra: true })
|
|
81
|
+
// { count: 5 }
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
If the normalized value still fails validation, `Parse` throws `ParseError`. This preserves the upstream TypeBox-style contract. Prefer `TryParse` when the caller wants a non-throwing path.
|
|
85
|
+
|
|
86
|
+
## Compile
|
|
87
|
+
|
|
88
|
+
`Compile` is the reusable path. It creates a validator once and then exposes the common runtime helpers off that compiled instance.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { CompileCached, Number, Object } from 'baobox'
|
|
92
|
+
|
|
93
|
+
const validator = CompileCached(Object({
|
|
94
|
+
count: Number({ minimum: 1 }),
|
|
95
|
+
}, { required: ['count'] }))
|
|
96
|
+
|
|
97
|
+
validator.Check({ count: 2 })
|
|
98
|
+
// true
|
|
99
|
+
|
|
100
|
+
validator.TryParse({ count: '2' })
|
|
101
|
+
// { success: true, value: { count: 2 } }
|
|
102
|
+
|
|
103
|
+
validator.Errors({ count: 0 })
|
|
104
|
+
// [{ path: 'count', code: 'MINIMUM', message: 'Value must be >= 1' }]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Compiled validators now support:
|
|
108
|
+
|
|
109
|
+
- Per-runtime-context cache reuse.
|
|
110
|
+
- Portable `validator.Artifact()` output.
|
|
111
|
+
- Artifact reloading through `CompileFromArtifact(schema, artifact)`.
|
|
112
|
+
- The same result-first helpers as the root API: `TryDecode`, `TryEncode`, `TryCreate`, `TryParse`, and `TryRepair`.
|
|
113
|
+
|
|
114
|
+
## Explain
|
|
115
|
+
|
|
116
|
+
`Explain` preserves the raw issue metadata while still localizing the final message.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { Explain, String } from 'baobox'
|
|
120
|
+
|
|
121
|
+
Explain(String(), 42)
|
|
122
|
+
// [{
|
|
123
|
+
// path: '/',
|
|
124
|
+
// code: 'INVALID_TYPE',
|
|
125
|
+
// params: { expected: 'string', actual: 'number' },
|
|
126
|
+
// locale: 'en_US',
|
|
127
|
+
// message: 'Expected string, got number'
|
|
128
|
+
// }]
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Localized Errors
|
|
132
|
+
|
|
133
|
+
Both `Value.Errors()` and `Compile(schema).Errors()` read the active locale from `baobox/system`.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { Errors, String } from 'baobox'
|
|
137
|
+
import { System } from 'baobox/system'
|
|
138
|
+
|
|
139
|
+
System.Locale.Set(System.Locale.ko_KR)
|
|
140
|
+
|
|
141
|
+
Errors(String(), 42)
|
|
142
|
+
// [{ path: '/', code: 'INVALID_TYPE', message: 'string이어야 합니다. 현재 값 유형: number' }]
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Current behavior:
|
|
146
|
+
|
|
147
|
+
- `en_US` is the default locale.
|
|
148
|
+
- Every declared locale code now has an official bundle through `baobox/locale`, so declared locales resolve directly from the registry.
|
|
149
|
+
- Native translated catalogs currently ship for `de_DE`, `en_US`, the Spanish family (`es_419`, `es_AR`, `es_ES`, `es_MX`), the French family (`fr_CA`, `fr_FR`), `ja_JP`, `ko_KR`, the Portuguese family (`pt_BR`, `pt_PT`), and both Chinese packs (`zh_Hans`, `zh_Hant`).
|
|
150
|
+
- Remaining official bundles currently alias the English catalog until native translations are added.
|
|
151
|
+
|
|
152
|
+
You can scope locale, registry, and compile-cache behavior with `CreateRuntimeContext()` and pass that context into `Check`, `Parse`, `TryParse`, and `Compile`.
|
|
153
|
+
|
|
154
|
+
For explicit bundle imports and scoped registration examples, see [Work with official locale packs and registry scoping](./locale-packs.md).
|