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
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# Baobox
|
|
2
|
+
|
|
3
|
+
Baobox is a Bun-first, TypeScript-first schema library that targets TypeBox parity while leaving room for Bun-native improvements.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add baobox
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requirements:
|
|
12
|
+
|
|
13
|
+
- `bun >= 1.3.11`
|
|
14
|
+
- `typescript >= 6.0.0`
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import Type, {
|
|
20
|
+
Check,
|
|
21
|
+
CompileCached,
|
|
22
|
+
DateCodec,
|
|
23
|
+
StandardSchemaV1,
|
|
24
|
+
TryDecode,
|
|
25
|
+
TryParse,
|
|
26
|
+
} from 'baobox'
|
|
27
|
+
|
|
28
|
+
const User = Type.Object({
|
|
29
|
+
id: Type.String(),
|
|
30
|
+
email: Type.String({ format: 'email' }),
|
|
31
|
+
age: Type.Number({ minimum: 0 }),
|
|
32
|
+
}, { required: ['id', 'email', 'age'] })
|
|
33
|
+
|
|
34
|
+
Check(User, { id: 'usr_1', email: 'ada@example.com', age: 37 })
|
|
35
|
+
|
|
36
|
+
TryParse(Type.Object({ count: Type.Number() }), { count: '5' })
|
|
37
|
+
// { success: true, value: { count: 5 } }
|
|
38
|
+
|
|
39
|
+
const validator = CompileCached(User)
|
|
40
|
+
validator.Check({ id: 'usr_1', email: 'ada@example.com', age: 37 })
|
|
41
|
+
|
|
42
|
+
TryDecode(DateCodec(), '2024-01-01T00:00:00.000Z')
|
|
43
|
+
// { success: true, value: new Date('2024-01-01T00:00:00.000Z') }
|
|
44
|
+
|
|
45
|
+
const StandardUser = StandardSchemaV1(User)
|
|
46
|
+
StandardUser['~standard'].validate({ id: 'usr_1', email: 'ada@example.com', age: '37' })
|
|
47
|
+
// { value: { id: 'usr_1', email: 'ada@example.com', age: 37 } }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Choose A Workflow
|
|
51
|
+
|
|
52
|
+
- `Check(schema, value)` returns a boolean. Use it when you only need pass/fail validation.
|
|
53
|
+
- `TryParse(schema, value)` runs the full normalization pipeline and returns `{ success, value | errors }`. Use it when the caller needs a non-throwing normalization path.
|
|
54
|
+
- `TryDecode`, `TryEncode`, `TryCreate`, and `TryRepair` extend the same result-first contract to codecs, default generation, and repair flows.
|
|
55
|
+
- `Parse(schema, value)` runs the full value pipeline: clone, default, convert, clean, then validate. It throws `ParseError` when validation still fails.
|
|
56
|
+
- `Explain(schema, value)` returns raw issue metadata plus the localized message and active locale.
|
|
57
|
+
- `Compile(schema)` creates a reusable validator for hot paths, now with per-context compile caching and portable `Validator.Artifact()` output. `Validator.Errors()` uses the same localized error messages as `Value.Errors()`.
|
|
58
|
+
|
|
59
|
+
## Standard Schema Adapter
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { StandardSchemaV1, Type } from 'baobox'
|
|
63
|
+
|
|
64
|
+
const User = StandardSchemaV1(Type.Object({
|
|
65
|
+
name: Type.String(),
|
|
66
|
+
age: Type.Number(),
|
|
67
|
+
}, { required: ['name', 'age'] }))
|
|
68
|
+
|
|
69
|
+
User['~standard'].validate({ name: 'Ada', age: '37' })
|
|
70
|
+
// { value: { name: 'Ada', age: 37 } }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Baobox also ships the dedicated `baobox/standard` subpath for schema-agnostic integrations.
|
|
74
|
+
|
|
75
|
+
`ToStandardSchema()` is the generic alias when you already have either a baobox schema or a raw JSON schema object. `FromJsonSchema()` is the explicit raw-schema entry point.
|
|
76
|
+
|
|
77
|
+
## Localized Validation Errors
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { Errors, String } from 'baobox'
|
|
81
|
+
import { System } from 'baobox/system'
|
|
82
|
+
|
|
83
|
+
System.Locale.Set(System.Locale.ko_KR)
|
|
84
|
+
|
|
85
|
+
Errors(String(), 42)
|
|
86
|
+
// [{ path: '/', code: 'INVALID_TYPE', message: 'string이어야 합니다. 현재 값 유형: number' }]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`en_US` is the default locale. Baobox now ships an official bundle for every declared locale code through `baobox/locale`, so declared locales no longer fall back through the registry lookup path. The translated catalog families currently include `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`). The remaining official bundles currently alias the English catalog until native translations are added.
|
|
90
|
+
|
|
91
|
+
You can also register scoped or process-default catalogs directly:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { CreateRuntimeContext, LocaleCodes, String, Errors } from 'baobox'
|
|
95
|
+
|
|
96
|
+
const context = CreateRuntimeContext()
|
|
97
|
+
context.Locale.Register('en_TEST', {
|
|
98
|
+
...context.Locale.GetCatalog(LocaleCodes.en_US),
|
|
99
|
+
INVALID_TYPE: () => 'yarrr-invalid-type',
|
|
100
|
+
})
|
|
101
|
+
context.Locale.Set('en_TEST')
|
|
102
|
+
|
|
103
|
+
Errors(String(), 42, context)
|
|
104
|
+
// [{ path: '/', code: 'INVALID_TYPE', message: 'yarrr-invalid-type' }]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
If you want to seed a scoped runtime with one of the official bundles explicitly, import it from `baobox/locale`:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import LocalePacks from 'baobox/locale'
|
|
111
|
+
import { CreateRuntimeContext, Errors, LocaleCodes, String } from 'baobox'
|
|
112
|
+
|
|
113
|
+
const context = CreateRuntimeContext({ localeCatalogs: [] })
|
|
114
|
+
context.Locale.Register(LocaleCodes.it_IT, LocalePacks.it_IT)
|
|
115
|
+
context.Locale.Set(LocaleCodes.it_IT)
|
|
116
|
+
|
|
117
|
+
Errors(String(), 42, context)
|
|
118
|
+
// [{ path: '/', code: 'INVALID_TYPE', message: 'Expected string, got number' }]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Package Contract
|
|
122
|
+
|
|
123
|
+
- Bun resolves public package entrypoints through the `bun` export condition to raw `src/*.ts` files.
|
|
124
|
+
- Standard ESM consumers resolve to built `dist/*.js` files plus generated declarations.
|
|
125
|
+
- The published JS layout is `dist/index.js`, `dist/value/index.js`, and matching subpath directories, which now aligns with the export map exactly.
|
|
126
|
+
- Supported public entrypoints are:
|
|
127
|
+
- `baobox`
|
|
128
|
+
- `baobox/type`
|
|
129
|
+
- `baobox/value`
|
|
130
|
+
- `baobox/schema`
|
|
131
|
+
- `baobox/error`
|
|
132
|
+
- `baobox/compile`
|
|
133
|
+
- `baobox/format`
|
|
134
|
+
- `baobox/guard`
|
|
135
|
+
- `baobox/system`
|
|
136
|
+
- `baobox/script`
|
|
137
|
+
- `baobox/locale`
|
|
138
|
+
- `baobox/standard`
|
|
139
|
+
- Direct `src/*` imports are used by this repository's tests and local development. They are not part of the published package contract.
|
|
140
|
+
|
|
141
|
+
## Guides
|
|
142
|
+
|
|
143
|
+
- [Choose Check vs TryParse vs Parse vs Compile](docs/workflows.md)
|
|
144
|
+
- [Work with official locale packs and registry scoping](docs/locale-packs.md)
|
|
145
|
+
- [Use Script, Module, and custom registries](docs/script-module-registries.md)
|
|
146
|
+
- [Package contract and supported imports](docs/package-contract.md)
|
|
147
|
+
- [Parity policy and baobox-only additions](docs/parity-and-extensions.md)
|
|
148
|
+
|
|
149
|
+
## Parity Policy
|
|
150
|
+
|
|
151
|
+
- Root exports are maintained as an upstream-complete superset.
|
|
152
|
+
- The `compile`, `error`, `format`, `guard`, `system`, and `value` subpaths are parity-tested against the installed `typebox` package.
|
|
153
|
+
- `baobox/schema` intentionally combines a `typebox/schema`-style raw schema runtime with baobox's schema emitter helpers.
|
|
154
|
+
|
|
155
|
+
## Bun-Native Fast Paths
|
|
156
|
+
|
|
157
|
+
- `Compile()` can specialize hot validation paths for Bun when the schema shape makes that safe.
|
|
158
|
+
- `CompileCached()` is the root convenience wrapper for cached validators, and `CompileFromArtifact()` reloads portable artifacts without re-emitting code.
|
|
159
|
+
- `Uint8ArrayCodec()` adds a Bun-first base64 codec surface for binary payloads and supports constant-payload specialization in compiled validators.
|
|
160
|
+
- `DateCodec()`, `URLCodec()`, and `BigIntCodec()` provide built-in codec surfaces for common interop-heavy values.
|
|
161
|
+
- Raw `Uint8Array` constant-byte comparisons can use a Bun `bun:ffi` memcmp fast path when the platform supports it.
|
|
162
|
+
- Bun documents `bun:ffi` as experimental, so baobox keeps the fast path narrow and falls back to non-FFI compiled validation whenever the schema does not require native byte comparison.
|
|
163
|
+
|
|
164
|
+
## Repository Scripts
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
bun run build
|
|
168
|
+
bun run typecheck
|
|
169
|
+
bun test
|
|
170
|
+
bun run bench
|
|
171
|
+
bun run publish:dry-run
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`bun run bench` prints comparative validation and codec throughput against the installed `typebox` package so benchmark output stays tied to the current upstream implementation.
|
|
175
|
+
|
|
176
|
+
## Publishing
|
|
177
|
+
|
|
178
|
+
Baobox is configured to publish to npm with `bun`.
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
bun run publish:dry-run
|
|
182
|
+
bun publish --access public
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
- `prepublishOnly` runs `bun run verify`, so a live publish always rebuilds and reruns the test suite first.
|
|
186
|
+
- GitHub Actions will attempt a publish on pushes to `main`, on published GitHub releases, and through manual workflow dispatch when `package.json` contains a version that is not already on npm.
|
|
187
|
+
- The workflow configures the npm registry on the runner and then requires the repository secret `NPM_TOKEN` before attempting a live publish.
|
|
188
|
+
- For a local first publish, authenticate once with `bunx npm login` before running `bun publish --access public`.
|
|
189
|
+
- Local `.npmrc` files are gitignored so auth tokens do not end up in the repository.
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TSchema } from '../type/schema.js';
|
|
2
|
+
import type { RuntimeContext } from '../shared/runtime-context.js';
|
|
3
|
+
type FastCheck = (value: unknown) => boolean;
|
|
4
|
+
type FastStrategy = 'bun-native' | 'bun-native-const' | 'bun-ffi';
|
|
5
|
+
export interface BunFastPathResult {
|
|
6
|
+
fn: FastCheck;
|
|
7
|
+
code: string;
|
|
8
|
+
accelerated: boolean;
|
|
9
|
+
strategy: FastStrategy;
|
|
10
|
+
}
|
|
11
|
+
export declare function compileBunFastPath(schema: TSchema, context: RuntimeContext): BunFastPathResult | null;
|
|
12
|
+
export declare function checkUint8ArrayCodecValue(value: unknown, minByteLength?: number, maxByteLength?: number, constBytes?: Uint8Array, constBase64?: string): boolean;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=bun-fast-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun-fast-path.d.ts","sourceRoot":"","sources":["../../src/compile/bun-fast-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAwBnE,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AAC7C,KAAK,YAAY,GAAG,YAAY,GAAG,kBAAkB,GAAG,SAAS,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,SAAS,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,YAAY,CAAC;CACxB;AAuPD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,cAAc,GACtB,iBAAiB,GAAG,IAAI,CAc1B;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,EACd,aAAa,CAAC,EAAE,MAAM,EACtB,aAAa,CAAC,EAAE,MAAM,EACtB,UAAU,CAAC,EAAE,UAAU,EACvB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAET"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TSchema } from '../type/schema.js';
|
|
2
|
+
export type EmitSchema = (schema: TSchema, valueExpr: string) => string;
|
|
3
|
+
export declare function emitPrimitiveSchemaCheck(currentSchema: TSchema, valueExpr: string): string | undefined;
|
|
4
|
+
export declare function emitStructuredSchemaCheck(currentSchema: TSchema, valueExpr: string, emitSchema: EmitSchema, nextVar: () => string): string | undefined;
|
|
5
|
+
//# sourceMappingURL=emit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/compile/emit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAQV,OAAO,EAIR,MAAM,mBAAmB,CAAC;AAG3B,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;AAsFxE,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAoCtG;AAED,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,OAAO,EACtB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,MAAM,MAAM,GACpB,MAAM,GAAG,SAAS,CAqBpB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Static, StaticDecode, StaticEncode, StaticParse, TSchema } from '../type/schema.js';
|
|
2
|
+
import type { ParseResult, SchemaError } from '../error/errors.js';
|
|
3
|
+
import type { SchemaIssueDiagnostic } from '../error/messages.js';
|
|
4
|
+
import { RuntimeContext } from '../shared/runtime-context.js';
|
|
5
|
+
export interface ValidatorArtifact {
|
|
6
|
+
body: string;
|
|
7
|
+
code: string;
|
|
8
|
+
hash: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CompileOptions {
|
|
11
|
+
artifact?: ValidatorArtifact;
|
|
12
|
+
cache?: boolean;
|
|
13
|
+
context?: RuntimeContext;
|
|
14
|
+
}
|
|
15
|
+
type RuntimeCheck = (value: unknown) => boolean;
|
|
16
|
+
interface CompileResult {
|
|
17
|
+
accelerated: boolean;
|
|
18
|
+
body: string;
|
|
19
|
+
code: string;
|
|
20
|
+
fn: RuntimeCheck;
|
|
21
|
+
strategy: string;
|
|
22
|
+
}
|
|
23
|
+
export declare class Validator<T extends TSchema> {
|
|
24
|
+
private readonly schema;
|
|
25
|
+
private readonly context;
|
|
26
|
+
private readonly hash;
|
|
27
|
+
private readonly artifact;
|
|
28
|
+
private readonly result;
|
|
29
|
+
constructor(schema: T, context: RuntimeContext, hash: string, artifact: ValidatorArtifact, result: CompileResult);
|
|
30
|
+
Artifact(): ValidatorArtifact;
|
|
31
|
+
Check(value: unknown): value is Static<T>;
|
|
32
|
+
Clean(value: unknown): StaticParse<T>;
|
|
33
|
+
Code(): string;
|
|
34
|
+
Context(): RuntimeContext;
|
|
35
|
+
Convert(value: unknown): StaticParse<T>;
|
|
36
|
+
Create(): Static<T>;
|
|
37
|
+
Decode(value: unknown): StaticDecode<T>;
|
|
38
|
+
Default(value: unknown): StaticParse<T>;
|
|
39
|
+
Encode(value: unknown): StaticEncode<T>;
|
|
40
|
+
Errors(value: unknown): SchemaError[];
|
|
41
|
+
Explain(value: unknown): SchemaIssueDiagnostic[];
|
|
42
|
+
Hash(): string;
|
|
43
|
+
IsAccelerated(): boolean;
|
|
44
|
+
Parse(value: unknown): StaticParse<T>;
|
|
45
|
+
Repair(value: unknown): StaticParse<T>;
|
|
46
|
+
Strategy(): string;
|
|
47
|
+
TryCreate(): ParseResult<Static<T>>;
|
|
48
|
+
TryDecode(value: unknown): ParseResult<StaticDecode<T>>;
|
|
49
|
+
TryEncode(value: unknown): ParseResult<StaticEncode<T>>;
|
|
50
|
+
TryParse(value: unknown): ParseResult<StaticParse<T>>;
|
|
51
|
+
TryRepair(value: unknown): ParseResult<StaticParse<T>>;
|
|
52
|
+
}
|
|
53
|
+
export declare function Compile<T extends TSchema>(schema: T): Validator<T>;
|
|
54
|
+
export declare function Compile<T extends TSchema>(schema: T, options: CompileOptions | RuntimeContext): Validator<T>;
|
|
55
|
+
export declare function Code<T extends TSchema>(schema: T, options?: CompileOptions | RuntimeContext): string;
|
|
56
|
+
export default Compile;
|
|
57
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.ts"],"names":[],"mappings":"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"}
|