@shina1024/jqx-yup-adapter
v0.1.2
Published
Yup adapter for jqx, a jq-compatible JSON processor written in MoonBit
Downloads
384
Maintainers
Readme
@shina1024/jqx-yup-adapter
Yup adapter for the stable @shina1024/jqx JS/TS runtime contract.
Install
pnpm add @shina1024/jqx @shina1024/jqx-yup-adapter yupUse this package when you want Yup to validate jqx inputs and outputs without depending on jqx runtime internals.
Quick Start
createAdapter(runtime).filter(...) is the primary on-ramp:
import { runtime } from "@shina1024/jqx";
import { createAdapter } from "@shina1024/jqx-yup-adapter";
import * as yup from "yup";
const adapter = createAdapter(runtime);
const result = await adapter.filter({
filter: ".users[].name",
input: { users: [{ name: "alice" }, { name: "bob" }] },
inputSchema: yup
.object({
users: yup
.array(
yup
.object({
name: yup.string().defined(),
})
.defined(),
)
.defined(),
})
.defined(),
outputSchema: yup.string().defined(),
});Stable Runtime Contract
This adapter sits on the stable jqx runtime contract. Most applications pass runtime from @shina1024/jqx, but any compatible JqxRuntime or JqxQueryRuntime implementation works.
Secondary APIs
infer(...)
Use infer(...) when you want filter-based type inference without schema validation:
const inferred = await adapter.infer({
filter: ".users[].name",
input: { users: [{ name: "alice" }] },
});createQueryAdapter(runtime).query(...)
Use the query adapter only when you are already working with jqx query AST helpers:
import { field, queryRuntime, toAst } from "@shina1024/jqx";
import { createQueryAdapter } from "@shina1024/jqx-yup-adapter";
const queryAdapter = createQueryAdapter(queryRuntime);
const result = await queryAdapter.query({
query: toAst(field("user")),
input: { user: { name: "alice" } },
inputSchema: yup
.object({
user: yup
.object({
name: yup.string().defined(),
})
.defined(),
})
.defined(),
outputSchema: yup
.object({
name: yup.string().defined(),
})
.defined(),
});Error Model
Adapter errors keep the stable jqx top-level contract:
input_validationruntimeoutput_validation
The top-level message is jqx-owned for logging and control flow. issues stays native to Yup as yup.ValidationError[].
Scripts
pnpm build
pnpm format
pnpm format:check
pnpm lint
pnpm lint:typeaware
pnpm lint:fix
pnpm typecheck
pnpm testpnpm build bundles ESM/CJS with tsdown and emits declarations with tsgo. pnpm typecheck uses tsgo.
Related Docs
- Runtime and bind surface:
../jqx/README.md - Root cross-surface overview:
../../README.mbt.md
