baobox 0.1.0 → 0.1.1-rc.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 +137 -89
- package/dist/compile/bun-fast-path.d.ts +1 -1
- package/dist/compile/bun-fast-path.d.ts.map +1 -1
- package/dist/compile/index.js +632 -505
- package/dist/compile/index.js.map +23 -23
- package/dist/error/collector/collections-basic.d.ts.map +1 -1
- package/dist/error/index.js +368 -288
- package/dist/error/index.js.map +14 -14
- package/dist/format/format.d.ts.map +1 -1
- package/dist/format/index.js +262 -89
- package/dist/format/index.js.map +9 -8
- package/dist/index.js +739 -609
- package/dist/index.js.map +39 -39
- package/dist/schema/core.d.ts.map +1 -1
- package/dist/schema/emitter.d.ts.map +1 -1
- package/dist/schema/engine.d.ts +2 -1
- package/dist/schema/engine.d.ts.map +1 -1
- package/dist/schema/index.js +343 -255
- package/dist/schema/index.js.map +13 -13
- package/dist/script/index.d.ts.map +1 -1
- package/dist/script/index.js +413 -324
- package/dist/script/index.js.map +18 -18
- package/dist/shared/bytes.d.ts.map +1 -1
- package/dist/shared/format-constants.d.ts +25 -0
- package/dist/shared/format-constants.d.ts.map +1 -1
- package/dist/shared/format-validators.d.ts +2 -2
- package/dist/shared/format-validators.d.ts.map +1 -1
- package/dist/shared/object-utils.d.ts.map +1 -1
- package/dist/shared/runtime-guards.d.ts +20 -0
- package/dist/shared/runtime-guards.d.ts.map +1 -1
- package/dist/shared/schema-access.d.ts +1 -1
- package/dist/shared/schema-access.d.ts.map +1 -1
- package/dist/shared/url-like.d.ts +16 -0
- package/dist/shared/url-like.d.ts.map +1 -0
- package/dist/shared/utils.d.ts +1 -1
- package/dist/shared/utils.d.ts.map +1 -1
- package/dist/shared/utils.js +254 -73
- package/dist/shared/utils.js.map +8 -7
- package/dist/standard/index.d.ts +2 -1
- package/dist/standard/index.d.ts.map +1 -1
- package/dist/standard/index.js +526 -422
- package/dist/standard/index.js.map +21 -21
- package/dist/system/index.js +363 -152
- package/dist/system/index.js.map +12 -11
- package/dist/system/system.d.ts.map +1 -1
- package/dist/type/codec-builtins.d.ts +3 -1
- package/dist/type/codec-builtins.d.ts.map +1 -1
- package/dist/type/extensions.d.ts +1 -0
- package/dist/type/extensions.d.ts.map +1 -1
- package/dist/type/index.d.ts +1 -1
- package/dist/type/index.d.ts.map +1 -1
- package/dist/type/index.js +389 -308
- package/dist/type/index.js.map +17 -17
- package/dist/type/instantiation.d.ts.map +1 -1
- package/dist/type/primitives.d.ts.map +1 -1
- package/dist/type/root-helpers.d.ts.map +1 -1
- package/dist/type/root-shared.d.ts +1 -1
- package/dist/type/root-shared.d.ts.map +1 -1
- package/dist/type/uint8array-codec.d.ts +8 -1
- package/dist/type/uint8array-codec.d.ts.map +1 -1
- package/dist/typebox.js +413 -324
- package/dist/typebox.js.map +18 -18
- package/dist/value/check.d.ts.map +1 -1
- package/dist/value/clean.d.ts.map +1 -1
- package/dist/value/convert.d.ts.map +1 -1
- package/dist/value/create.d.ts.map +1 -1
- package/dist/value/decode.d.ts.map +1 -1
- package/dist/value/default.d.ts.map +1 -1
- package/dist/value/diff.d.ts.map +1 -1
- package/dist/value/encode.d.ts.map +1 -1
- package/dist/value/equal.d.ts.map +1 -1
- package/dist/value/has-codec.d.ts.map +1 -1
- package/dist/value/hash.d.ts +0 -1
- package/dist/value/hash.d.ts.map +1 -1
- package/dist/value/index.js +666 -551
- package/dist/value/index.js.map +27 -27
- package/dist/value/mutate.d.ts.map +1 -1
- package/dist/value/patch.d.ts.map +1 -1
- package/dist/value/repair.d.ts.map +1 -1
- package/docs/package-contract.md +4 -0
- package/package.json +2 -4
- package/src/compile/bun-fast-path.ts +312 -0
- package/src/compile/emit.ts +166 -0
- package/src/compile/index.ts +317 -0
- package/src/error/catalog-types.ts +72 -0
- package/src/error/collector/advanced.ts +272 -0
- package/src/error/collector/collections-basic.ts +193 -0
- package/src/error/collector/collections-derived.ts +93 -0
- package/src/error/collector/collections-parameters.ts +74 -0
- package/src/error/collector/collections.ts +27 -0
- package/src/error/collector/primitives.ts +238 -0
- package/src/error/collector/shared.ts +15 -0
- package/src/error/collector.ts +28 -0
- package/src/error/errors.ts +53 -0
- package/src/error/index.ts +32 -0
- package/src/error/locales/de.ts +50 -0
- package/src/error/locales/en.ts +50 -0
- package/src/error/locales/es.ts +50 -0
- package/src/error/locales/fr.ts +50 -0
- package/src/error/locales/ja.ts +50 -0
- package/src/error/locales/ko.ts +50 -0
- package/src/error/locales/pt.ts +50 -0
- package/src/error/locales/shared.ts +9 -0
- package/src/error/locales/zh.ts +80 -0
- package/src/error/messages.ts +45 -0
- package/src/format/format.ts +132 -0
- package/src/format/index.ts +6 -0
- package/src/guard/guard.ts +274 -0
- package/src/guard/index.ts +8 -0
- package/src/index.ts +83 -0
- package/src/locale/index.ts +99 -0
- package/src/schema/build.ts +77 -0
- package/src/schema/check.ts +12 -0
- package/src/schema/compile.ts +47 -0
- package/src/schema/core-keywords.ts +272 -0
- package/src/schema/core.ts +112 -0
- package/src/schema/emitter-advanced.ts +22 -0
- package/src/schema/emitter-base.ts +91 -0
- package/src/schema/emitter-derived.ts +95 -0
- package/src/schema/emitter-reference.ts +66 -0
- package/src/schema/emitter-types.ts +10 -0
- package/src/schema/emitter-wrapper.ts +79 -0
- package/src/schema/emitter.ts +235 -0
- package/src/schema/engine.ts +240 -0
- package/src/schema/error-collector.ts +133 -0
- package/src/schema/errors.ts +14 -0
- package/src/schema/index.ts +5 -0
- package/src/schema/parse.ts +44 -0
- package/src/schema/pointer.ts +92 -0
- package/src/schema/predicates.ts +75 -0
- package/src/schema/resolve.ts +93 -0
- package/src/schema/runtime-keywords.ts +162 -0
- package/src/schema/schema.ts +13 -0
- package/src/schema/shared.ts +141 -0
- package/src/script/generic.ts +86 -0
- package/src/script/index.ts +125 -0
- package/src/script/literals.ts +75 -0
- package/src/script/shared.ts +94 -0
- package/src/shared/bytes.ts +74 -0
- package/src/shared/format-constants.ts +61 -0
- package/src/shared/format-validators.ts +133 -0
- package/src/shared/locale.ts +43 -0
- package/src/shared/object-utils.ts +159 -0
- package/src/shared/regex-json.ts +290 -0
- package/src/shared/registries.ts +83 -0
- package/src/shared/runtime-context.ts +196 -0
- package/src/shared/runtime-guards.ts +77 -0
- package/src/shared/schema-access.ts +149 -0
- package/src/shared/url-like.ts +15 -0
- package/src/shared/utils.ts +73 -0
- package/src/standard/index.ts +211 -0
- package/src/system/index.ts +6 -0
- package/src/system/system.ts +115 -0
- package/src/type/actions.ts +214 -0
- package/src/type/base-types.ts +5 -0
- package/src/type/codec-builtins.ts +31 -0
- package/src/type/combinator-core.ts +129 -0
- package/src/type/combinator-functions.ts +49 -0
- package/src/type/combinator-objects.ts +155 -0
- package/src/type/combinators.ts +34 -0
- package/src/type/composite-types.ts +46 -0
- package/src/type/containers-types.ts +56 -0
- package/src/type/containers.ts +64 -0
- package/src/type/extends.ts +156 -0
- package/src/type/extensions.ts +246 -0
- package/src/type/guards.ts +92 -0
- package/src/type/index.ts +245 -0
- package/src/type/instantiation.ts +307 -0
- package/src/type/kind.ts +75 -0
- package/src/type/narrow-types.ts +26 -0
- package/src/type/primitives-types.ts +116 -0
- package/src/type/primitives.ts +283 -0
- package/src/type/root-constants.ts +169 -0
- package/src/type/root-cyclic.ts +158 -0
- package/src/type/root-deferred.ts +77 -0
- package/src/type/root-guards.ts +91 -0
- package/src/type/root-helpers.ts +240 -0
- package/src/type/root-instantiate.ts +268 -0
- package/src/type/root-shared.ts +59 -0
- package/src/type/root-template.ts +206 -0
- package/src/type/schema.ts +81 -0
- package/src/type/static-const-types.ts +177 -0
- package/src/type/static-shared-types.ts +84 -0
- package/src/type/static-types.ts +226 -0
- package/src/type/string-action-types.ts +28 -0
- package/src/type/transform-types.ts +68 -0
- package/src/type/uint8array-codec.ts +55 -0
- package/src/type/wrapper-types.ts +89 -0
- package/src/typebox.ts +2 -0
- package/src/value/assert.ts +19 -0
- package/src/value/check-collections-derived.ts +198 -0
- package/src/value/check-collections.ts +130 -0
- package/src/value/check-extensions.ts +66 -0
- package/src/value/check-primitives.ts +132 -0
- package/src/value/check.ts +67 -0
- package/src/value/clean.ts +132 -0
- package/src/value/clone.ts +10 -0
- package/src/value/convert.ts +193 -0
- package/src/value/create.ts +167 -0
- package/src/value/decode.ts +146 -0
- package/src/value/default.ts +119 -0
- package/src/value/diff.ts +68 -0
- package/src/value/encode.ts +137 -0
- package/src/value/equal.ts +42 -0
- package/src/value/has-codec.ts +61 -0
- package/src/value/hash.ts +97 -0
- package/src/value/index.ts +149 -0
- package/src/value/mutate.ts +21 -0
- package/src/value/parse.ts +55 -0
- package/src/value/patch.ts +55 -0
- package/src/value/pipeline.ts +15 -0
- package/src/value/pointer.ts +169 -0
- package/src/value/repair.ts +183 -0
- package/src/value/result.ts +55 -0
package/README.md
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
# Baobox
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/d4551/baobox/actions/workflows/publish.yml)
|
|
4
|
+
[](https://github.com/d4551/baobox)
|
|
5
|
+
[](https://bun.sh)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
Baobox is a Bun-first, TypeScript-first schema library that keeps the familiar TypeBox-style authoring surface while adding result-first runtime APIs, scoped runtime contexts, compile caching, portable validator artifacts, and schema-interop helpers.
|
|
9
|
+
|
|
10
|
+
## ELI5
|
|
11
|
+
|
|
12
|
+
- You describe what valid data looks like once.
|
|
13
|
+
- Baobox can then answer different questions with the same schema:
|
|
14
|
+
- Is this value valid: `Check`
|
|
15
|
+
- Can you clean and coerce it safely: `TryParse`
|
|
16
|
+
- What exactly failed: `Explain` or `Errors`
|
|
17
|
+
- Can I reuse this on a hot path: `CompileCached`
|
|
18
|
+
- Can another tool consume the same schema: `StandardSchemaV1`
|
|
19
|
+
- If you do not want exception-driven control flow, use the `Try*` family.
|
|
20
|
+
|
|
21
|
+
## Why Baobox
|
|
22
|
+
|
|
23
|
+
- TypeBox-compatible root surface with baobox-only additions at the root entrypoint.
|
|
24
|
+
- Result-first runtime helpers: `TryParse`, `TryDecode`, `TryEncode`, `TryCreate`, and `TryRepair`.
|
|
25
|
+
- Scoped runtime contexts so locale catalogs, registries, settings, and compile caches do not have to be process-global.
|
|
26
|
+
- Compiled validators with cache reuse and portable `Validator.Artifact()` output.
|
|
27
|
+
- Standard Schema V1 adapters for typed baobox schemas and raw JSON-schema-style objects.
|
|
28
|
+
- Built-in codecs for common interop-heavy values: `Uint8Array`, `Date`, `URL`, and `bigint`.
|
|
29
|
+
- Localized validation errors with official bundles for every declared locale code through `baobox/locale`.
|
|
4
30
|
|
|
5
31
|
## Install
|
|
6
32
|
|
|
@@ -32,12 +58,14 @@ const User = Type.Object({
|
|
|
32
58
|
}, { required: ['id', 'email', 'age'] })
|
|
33
59
|
|
|
34
60
|
Check(User, { id: 'usr_1', email: 'ada@example.com', age: 37 })
|
|
61
|
+
// true
|
|
35
62
|
|
|
36
63
|
TryParse(Type.Object({ count: Type.Number() }), { count: '5' })
|
|
37
64
|
// { success: true, value: { count: 5 } }
|
|
38
65
|
|
|
39
66
|
const validator = CompileCached(User)
|
|
40
67
|
validator.Check({ id: 'usr_1', email: 'ada@example.com', age: 37 })
|
|
68
|
+
// true
|
|
41
69
|
|
|
42
70
|
TryDecode(DateCodec(), '2024-01-01T00:00:00.000Z')
|
|
43
71
|
// { success: true, value: new Date('2024-01-01T00:00:00.000Z') }
|
|
@@ -47,68 +75,102 @@ StandardUser['~standard'].validate({ id: 'usr_1', email: 'ada@example.com', age:
|
|
|
47
75
|
// { value: { id: 'usr_1', email: 'ada@example.com', age: 37 } }
|
|
48
76
|
```
|
|
49
77
|
|
|
50
|
-
##
|
|
78
|
+
## API Map
|
|
51
79
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
80
|
+
| Problem | API | Result |
|
|
81
|
+
| --- | --- | --- |
|
|
82
|
+
| Fast pass/fail validation | `Check(schema, value)` | `boolean` |
|
|
83
|
+
| Normalize without exceptions | `TryParse(schema, value)` | `ParseResult<T>` |
|
|
84
|
+
| Throwing parity path | `Parse(schema, value)` | normalized value or `ParseError` |
|
|
85
|
+
| Codec decode without exceptions | `TryDecode(schema, value)` | `ParseResult<T>` |
|
|
86
|
+
| Codec encode without exceptions | `TryEncode(schema, value)` | `ParseResult<T>` |
|
|
87
|
+
| Default generation without exceptions | `TryCreate(schema)` | `ParseResult<T>` |
|
|
88
|
+
| Repair without exceptions | `TryRepair(schema, value)` | `ParseResult<T>` |
|
|
89
|
+
| Raw issue metadata plus localized messages | `Explain(schema, value)` | diagnostics array |
|
|
90
|
+
| Reusable hot-path validator | `Compile(schema)` or `CompileCached(schema)` | `Validator` |
|
|
91
|
+
| Reload a prebuilt validator body | `CompileFromArtifact(schema, artifact)` | `Validator` |
|
|
92
|
+
| Adapt to Standard Schema V1 | `StandardSchemaV1(schema)` | standard-compatible wrapper |
|
|
58
93
|
|
|
59
|
-
##
|
|
94
|
+
## Result-First Runtime
|
|
60
95
|
|
|
61
|
-
|
|
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'] }))
|
|
96
|
+
Baobox keeps `Parse(schema, value)` as the upstream-style throwing path, but the default baobox direction is result-first:
|
|
68
97
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
98
|
+
- `TryParse` runs `Clone -> Default -> Convert -> Clean -> Check`
|
|
99
|
+
- `TryDecode` and `TryEncode` apply codec transforms without exception control flow
|
|
100
|
+
- `TryCreate` and `TryRepair` make default-generation and corrective flows explicit
|
|
101
|
+
- `Explain` preserves issue codes, params, locale, and final message
|
|
72
102
|
|
|
73
|
-
|
|
103
|
+
If you are writing request handling, config loading, env parsing, or service boundaries, the `Try*` APIs are usually the better fit.
|
|
74
104
|
|
|
75
|
-
|
|
105
|
+
## Compiled Validators
|
|
76
106
|
|
|
77
|
-
|
|
107
|
+
`Compile()` builds a reusable validator object. `CompileCached()` adds per-runtime-context cache reuse. `CompileFromArtifact()` reloads previously emitted validator code.
|
|
78
108
|
|
|
79
109
|
```ts
|
|
80
|
-
import {
|
|
81
|
-
import { System } from 'baobox/system'
|
|
110
|
+
import { CompileCached, CompileFromArtifact, Number, Object } from 'baobox'
|
|
82
111
|
|
|
83
|
-
|
|
112
|
+
const schema = Object({
|
|
113
|
+
count: Number({ minimum: 1 }),
|
|
114
|
+
}, { required: ['count'] })
|
|
84
115
|
|
|
85
|
-
|
|
86
|
-
|
|
116
|
+
const validator = CompileCached(schema)
|
|
117
|
+
const artifact = validator.Artifact()
|
|
118
|
+
const loaded = CompileFromArtifact(schema, artifact)
|
|
119
|
+
|
|
120
|
+
loaded.TryParse({ count: '2' })
|
|
121
|
+
// { success: true, value: { count: 2 } }
|
|
87
122
|
```
|
|
88
123
|
|
|
89
|
-
|
|
124
|
+
Technical details:
|
|
125
|
+
|
|
126
|
+
- compile caching is scoped to the active runtime context
|
|
127
|
+
- artifacts let you ship emitted validator code instead of regenerating it at startup
|
|
128
|
+
- Bun-specific byte-oriented fast paths are used only when the schema shape makes that safe
|
|
90
129
|
|
|
91
|
-
|
|
130
|
+
## Standard Schema Interop
|
|
131
|
+
|
|
132
|
+
Baobox can expose the same validation logic through the Standard Schema V1 contract.
|
|
92
133
|
|
|
93
134
|
```ts
|
|
94
|
-
import {
|
|
135
|
+
import { FromJsonSchema, StandardSchemaV1, Type, ToStandardSchema } from 'baobox'
|
|
136
|
+
|
|
137
|
+
const typed = StandardSchemaV1(Type.Object({
|
|
138
|
+
name: Type.String(),
|
|
139
|
+
age: Type.Number(),
|
|
140
|
+
}, { required: ['name', 'age'] }))
|
|
95
141
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
142
|
+
const raw = FromJsonSchema({
|
|
143
|
+
type: 'object',
|
|
144
|
+
properties: {
|
|
145
|
+
name: { type: 'string' },
|
|
146
|
+
age: { type: 'number' },
|
|
147
|
+
},
|
|
148
|
+
required: ['name', 'age'],
|
|
100
149
|
})
|
|
101
|
-
context.Locale.Set('en_TEST')
|
|
102
150
|
|
|
103
|
-
|
|
104
|
-
// [{ path: '/', code: 'INVALID_TYPE', message: 'yarrr-invalid-type' }]
|
|
151
|
+
ToStandardSchema(raw)['~standard'].validate({ name: 'Ada', age: 37 })
|
|
105
152
|
```
|
|
106
153
|
|
|
107
|
-
|
|
154
|
+
Use:
|
|
155
|
+
|
|
156
|
+
- `StandardSchemaV1()` when you want the canonical baobox adapter
|
|
157
|
+
- `ToStandardSchema()` when the input may already be typed or raw
|
|
158
|
+
- `FromJsonSchema()` when the source is explicitly a raw JSON-schema-style object
|
|
159
|
+
|
|
160
|
+
For schema-agnostic integrations, you can also import from `baobox/standard`.
|
|
161
|
+
|
|
162
|
+
## Locales And Runtime Contexts
|
|
163
|
+
|
|
164
|
+
The default runtime context is preloaded with an official bundle for every declared locale code. Native translated catalogs currently ship for `de_DE`, `en_US`, the Spanish family, the French family, `ja_JP`, `ko_KR`, the Portuguese family, and both Chinese packs. Remaining official bundles currently alias the English catalog until native translations are added.
|
|
108
165
|
|
|
109
166
|
```ts
|
|
110
167
|
import LocalePacks from 'baobox/locale'
|
|
111
168
|
import { CreateRuntimeContext, Errors, LocaleCodes, String } from 'baobox'
|
|
169
|
+
import { System } from 'baobox/system'
|
|
170
|
+
|
|
171
|
+
System.Locale.Set(System.Locale.ko_KR)
|
|
172
|
+
Errors(String(), 42)
|
|
173
|
+
// [{ path: '/', code: 'INVALID_TYPE', message: 'string이어야 합니다. 현재 값 유형: number' }]
|
|
112
174
|
|
|
113
175
|
const context = CreateRuntimeContext({ localeCatalogs: [] })
|
|
114
176
|
context.Locale.Register(LocaleCodes.it_IT, LocalePacks.it_IT)
|
|
@@ -118,25 +180,42 @@ Errors(String(), 42, context)
|
|
|
118
180
|
// [{ path: '/', code: 'INVALID_TYPE', message: 'Expected string, got number' }]
|
|
119
181
|
```
|
|
120
182
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
183
|
+
Use runtime contexts when you need:
|
|
184
|
+
|
|
185
|
+
- per-test or per-worker isolation
|
|
186
|
+
- tenant-specific registries or locale catalogs
|
|
187
|
+
- explicit compile-cache boundaries
|
|
188
|
+
- non-global settings and type-policy changes
|
|
189
|
+
|
|
190
|
+
## Built-In Codecs
|
|
191
|
+
|
|
192
|
+
Baobox ships codec helpers for common wire-format boundaries:
|
|
193
|
+
|
|
194
|
+
- `Uint8ArrayCodec()` for base64 JSON payloads and runtime byte arrays
|
|
195
|
+
- `DateCodec()` for ISO datetime strings to `Date`
|
|
196
|
+
- `URLCodec()` for string to `URL`
|
|
197
|
+
- `BigIntCodec()` for integer-string to `bigint`
|
|
198
|
+
|
|
199
|
+
These work with the same value and compile APIs as ordinary schemas.
|
|
200
|
+
|
|
201
|
+
## Public Entrypoints
|
|
202
|
+
|
|
203
|
+
| Entrypoint | Purpose |
|
|
204
|
+
| --- | --- |
|
|
205
|
+
| `baobox` | Root builders, value helpers, compile helpers, and baobox additions |
|
|
206
|
+
| `baobox/type` | Type builders and static type exports |
|
|
207
|
+
| `baobox/value` | Runtime value operations such as `Check`, `Parse`, `Errors`, `Repair`, `Diff`, and `Patch` |
|
|
208
|
+
| `baobox/schema` | Raw schema runtime plus baobox schema-emitter helpers |
|
|
209
|
+
| `baobox/error` | Structured validation error surface |
|
|
210
|
+
| `baobox/compile` | `Compile`, `Code`, and `Validator` |
|
|
211
|
+
| `baobox/format` | Format registry and format helpers |
|
|
212
|
+
| `baobox/guard` | Guard namespaces aligned with the TypeBox-style guard surface |
|
|
213
|
+
| `baobox/system` | Runtime settings, locale, hashing, memory, and environment helpers |
|
|
214
|
+
| `baobox/script` | Script DSL helpers |
|
|
215
|
+
| `baobox/locale` | Official locale bundles for the declared locale registry |
|
|
216
|
+
| `baobox/standard` | Standard Schema V1 adapter helpers |
|
|
217
|
+
|
|
218
|
+
Published consumers should only rely on package entrypoints. Direct `src/*` imports are internal to this repository and its tests.
|
|
140
219
|
|
|
141
220
|
## Guides
|
|
142
221
|
|
|
@@ -146,21 +225,6 @@ Errors(String(), 42, context)
|
|
|
146
225
|
- [Package contract and supported imports](docs/package-contract.md)
|
|
147
226
|
- [Parity policy and baobox-only additions](docs/parity-and-extensions.md)
|
|
148
227
|
|
|
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
228
|
## Repository Scripts
|
|
165
229
|
|
|
166
230
|
```bash
|
|
@@ -168,25 +232,9 @@ bun run build
|
|
|
168
232
|
bun run typecheck
|
|
169
233
|
bun test
|
|
170
234
|
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
235
|
```
|
|
184
236
|
|
|
185
|
-
|
|
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.
|
|
237
|
+
`bun run bench` compares validation and codec throughput against the installed `typebox` package so performance numbers stay tied to the current upstream implementation.
|
|
190
238
|
|
|
191
239
|
## License
|
|
192
240
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TSchema } from '../type/schema.js';
|
|
2
2
|
import type { RuntimeContext } from '../shared/runtime-context.js';
|
|
3
3
|
type FastCheck = (value: unknown) => boolean;
|
|
4
|
-
type FastStrategy = 'bun-native' | 'bun-native-const'
|
|
4
|
+
type FastStrategy = 'bun-native' | 'bun-native-const';
|
|
5
5
|
export interface BunFastPathResult {
|
|
6
6
|
fn: FastCheck;
|
|
7
7
|
code: string;
|
|
@@ -1 +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;
|
|
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;AAGjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAyBnE,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AAC7C,KAAK,YAAY,GAAG,YAAY,GAAG,kBAAkB,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,SAAS,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,YAAY,CAAC;CACxB;AAwPD,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"}
|