valiq-js 0.1.0 → 0.1.1
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 +25 -28
- package/SECURITY.md +3 -3
- package/dist/core/error.cjs +1 -1
- package/dist/core/error.d.cts +1 -1
- package/dist/core/error.d.ts +1 -1
- package/dist/core/error.js +1 -1
- package/dist/core/schema.cjs +1 -1
- package/dist/core/schema.d.cts +2 -2
- package/dist/core/schema.d.ts +2 -2
- package/dist/core/schema.js +1 -1
- package/dist/core/standard.js +1 -1
- package/dist/json-schema/compile.cjs +1 -1
- package/dist/json-schema/compile.d.cts +2 -2
- package/dist/json-schema/compile.d.ts +2 -2
- package/dist/json-schema/compile.js +1 -1
- package/dist/json-schema/index.cjs +2 -2
- package/dist/json-schema/index.d.cts +2 -2
- package/dist/json-schema/index.d.ts +2 -2
- package/dist/json-schema/index.js +2 -2
- package/dist/schemas/composite.js +1 -1
- package/dist/to-json-schema.cjs +1 -1
- package/dist/to-json-schema.d.cts +1 -1
- package/dist/to-json-schema.d.ts +1 -1
- package/dist/to-json-schema.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# valiq-js
|
|
2
2
|
|
|
3
3
|
**Modern validation. Precise errors. Type-safe by design.**
|
|
4
4
|
|
|
5
|
-
[Documentation and live playground](https://www.m2toolkit.com/npm-packages/valiq)
|
|
5
|
+
[Documentation and live playground](https://www.m2toolkit.com/npm-packages/valiq-js)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
valiq-js is a TypeScript-first validation library for JavaScript and TypeScript. You describe your data
|
|
8
8
|
once and get a runtime validator, an inferred TypeScript type, structured errors that are safe to
|
|
9
9
|
send to clients or write to logs, and JSON Schema in both directions.
|
|
10
10
|
|
|
@@ -30,7 +30,7 @@ if (result.success) {
|
|
|
30
30
|
}
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
## Why
|
|
33
|
+
## Why valiq-js
|
|
34
34
|
|
|
35
35
|
- **One library for TypeScript schemas and JSON Schema.** Build schemas in TypeScript, or compile
|
|
36
36
|
existing JSON Schema documents (2020-12, 2019-09, draft-07) with
|
|
@@ -54,11 +54,11 @@ if (result.success) {
|
|
|
54
54
|
`new Function`, so it works under a strict Content Security Policy.
|
|
55
55
|
- **Works with your stack.** Implements [Standard Schema](https://standardschema.dev) and Standard
|
|
56
56
|
JSON Schema, so libraries that accept Standard Schema (such as tRPC, TanStack Form, React Hook
|
|
57
|
-
Form's Standard Schema resolver and Hono's standard validator) accept
|
|
57
|
+
Form's Standard Schema resolver and Hono's standard validator) accept valiq-js schemas directly.
|
|
58
58
|
- **Zero dependencies.** ESM and CommonJS, Node.js 18+ and modern browsers. About 9 KB min+gzip for
|
|
59
59
|
typical builder usage.
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
valiq-js does not try to beat Ajv at raw throughput: Ajv generates code and is about 3× faster on
|
|
62
62
|
valid data. See [Performance](#performance) for measured numbers.
|
|
63
63
|
|
|
64
64
|
## Installation
|
|
@@ -67,9 +67,6 @@ valid data. See [Performance](#performance) for measured numbers.
|
|
|
67
67
|
npm install valiq-js
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
The library is called Valiq; on npm it is published as `valiq-js`, so imports use
|
|
71
|
-
`'valiq-js'` and `'valiq-js/json-schema'`.
|
|
72
|
-
|
|
73
70
|
Requirements: Node.js 18 or later, or any modern browser (ES2022). TypeScript 5.0+ is recommended
|
|
74
71
|
for inference; `strict` mode is expected.
|
|
75
72
|
|
|
@@ -203,7 +200,7 @@ Product.parse({ sku: 'ABC-1234', price: 10 }); // typed { sku: string; price: nu
|
|
|
203
200
|
Supported: draft 2020-12, 2019-09 and draft-07, including `$ref` (local, `$id`, `$anchor`,
|
|
204
201
|
recursive, and pre-registered schemas through the `schemas` option), all composition keywords,
|
|
205
202
|
`if`/`then`/`else`, dependencies, `contains` with min/max, and 15 formats. Against the official
|
|
206
|
-
[JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite),
|
|
203
|
+
[JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite), valiq-js passes
|
|
207
204
|
**every test it runs** in the required suites: 1052 for 2020-12, 1032 for 2019-09 and 925 for
|
|
208
205
|
draft-07.
|
|
209
206
|
|
|
@@ -238,13 +235,13 @@ const Amount = v
|
|
|
238
235
|
|
|
239
236
|
## Node.js, browsers and frameworks
|
|
240
237
|
|
|
241
|
-
|
|
238
|
+
valiq-js has no dependencies and uses only standard JavaScript APIs (no Node.js built-ins), so it
|
|
242
239
|
runs in Node.js and browsers and should run unchanged in Deno, Bun and edge runtimes (only Node.js
|
|
243
240
|
is covered by the test suite today). It ships ESM and CommonJS builds with type declarations for
|
|
244
241
|
both.
|
|
245
242
|
|
|
246
243
|
```ts
|
|
247
|
-
// Any library that accepts a Standard Schema accepts a
|
|
244
|
+
// Any library that accepts a Standard Schema accepts a valiq-js schema:
|
|
248
245
|
import { v } from 'valiq-js';
|
|
249
246
|
const Login = v.object({ email: v.string().email(), password: v.string().min(8) });
|
|
250
247
|
const result = await Login['~standard'].validate({ email: 'dev@example.com', password: 'hunter22!' });
|
|
@@ -259,33 +256,33 @@ React usage is covered in [docs/examples.md](docs/examples.md#react-forms).
|
|
|
259
256
|
## Performance
|
|
260
257
|
|
|
261
258
|
Measured with `npm run benchmark` (tinybench, 1 s per task) on Node.js 22.23.1 on an Apple M4,
|
|
262
|
-
comparing valiq 0.1.0, ajv 8.20.0, zod 4.6.7 and valibot 1.5.0. Every library validates the same
|
|
259
|
+
comparing valiq-js 0.1.0, ajv 8.20.0, zod 4.6.7 and valibot 1.5.0. Every library validates the same
|
|
263
260
|
rules, and all accept unknown keys so that none of them copies the input. Higher is better.
|
|
264
261
|
|
|
265
|
-
| Workload |
|
|
266
|
-
| --------------------------------------- |
|
|
267
|
-
| Valid object (nested, 5 fields), ops/s |
|
|
268
|
-
| Invalid object, all errors, ops/s |
|
|
269
|
-
| Valid array of 1,000 objects, ops/s |
|
|
270
|
-
| Discriminated union, 300 items, ops/s |
|
|
271
|
-
| Define schema + first validation, ops/s |
|
|
262
|
+
| Workload | valiq-js | valiq-js (JSON Schema) | Ajv | Zod | Valibot |
|
|
263
|
+
| --------------------------------------- | -------: | ---------------------: | ------: | -----: | ------: |
|
|
264
|
+
| Valid object (nested, 5 fields), ops/s | 7.1 M | 4.1 M | 23.3 M | 3.5 M | 2.6 M |
|
|
265
|
+
| Invalid object, all errors, ops/s | 1.0 M | 0.82 M | 16.6 M | 1.4 M | 1.6 M |
|
|
266
|
+
| Valid array of 1,000 objects, ops/s | 7,832 | 4,396 | 38,307 | 3,576 | 2,723 |
|
|
267
|
+
| Discriminated union, 300 items, ops/s | 68,286 | 27,308 (`oneOf`) | 114,957 | 75,153 | 16,970 |
|
|
268
|
+
| Define schema + first validation, ops/s | 520 k | 42 k | 422 | 17 k | 899 k |
|
|
272
269
|
|
|
273
|
-
In short: Ajv is the fastest validator on hot paths because it generates JavaScript code.
|
|
270
|
+
In short: Ajv is the fastest validator on hot paths because it generates JavaScript code. valiq-js
|
|
274
271
|
does not generate code, which makes it CSP-safe. It is about 2× faster than Zod and 2.7× faster
|
|
275
272
|
than Valibot on valid objects, and it starts up three orders of magnitude faster than Ajv's
|
|
276
273
|
compiler (useful for serverless cold starts). On invalid input, Zod and Valibot are faster than
|
|
277
|
-
|
|
274
|
+
valiq-js when every error is collected. Numbers vary by machine and workload. Run the suite yourself;
|
|
278
275
|
the methodology is in [docs/performance.md](docs/performance.md).
|
|
279
276
|
|
|
280
277
|
Bundle size (min+gzip, measured with `npm run size -- --compare`): an object schema with string,
|
|
281
|
-
number and array checks costs 9.4 KB with
|
|
278
|
+
number and array checks costs 9.4 KB with valiq-js, 20.7 KB with Zod, 5.5 KB with `zod/mini`,
|
|
282
279
|
1.5 KB with Valibot and 34.6 KB with Ajv (no formats). Everything in `valiq-js` is 11.5 KB;
|
|
283
280
|
`fromJSONSchema` adds about 6 KB.
|
|
284
281
|
|
|
285
282
|
## Security
|
|
286
283
|
|
|
287
284
|
Validation checks shape and constraints. It is not sanitisation (it does not make strings safe for
|
|
288
|
-
HTML or SQL) and not authorisation.
|
|
285
|
+
HTML or SQL) and not authorisation. valiq-js is designed for untrusted input:
|
|
289
286
|
|
|
290
287
|
- Own properties only: values inherited from a polluted `Object.prototype` are treated as missing,
|
|
291
288
|
and `__proto__` keys are copied as data, never as prototypes.
|
|
@@ -302,7 +299,7 @@ See [docs/security.md](docs/security.md), and [SECURITY.md](SECURITY.md) to repo
|
|
|
302
299
|
|
|
303
300
|
## Documentation
|
|
304
301
|
|
|
305
|
-
The [documentation site](https://www.m2toolkit.com/npm-packages/valiq) has every page below, search
|
|
302
|
+
The [documentation site](https://www.m2toolkit.com/npm-packages/valiq-js) has every page below, search
|
|
306
303
|
and a live playground.
|
|
307
304
|
|
|
308
305
|
- [Getting started](docs/getting-started.md)
|
|
@@ -322,11 +319,11 @@ and a live playground.
|
|
|
322
319
|
|
|
323
320
|
## FAQ
|
|
324
321
|
|
|
325
|
-
**Should I use
|
|
326
|
-
is faster. Pick
|
|
322
|
+
**Should I use valiq-js or Ajv?** If you only validate JSON Schema documents on a very hot path, Ajv
|
|
323
|
+
is faster. Pick valiq-js if you want TypeScript-first schemas and JSON Schema in one library, errors
|
|
327
324
|
designed for users, strict schema checking with suggestions, fast startup or CSP compatibility.
|
|
328
325
|
|
|
329
|
-
**Does
|
|
326
|
+
**Does valiq-js strip unknown properties?** Not by default (the same as JSON Schema and Ajv). Use
|
|
330
327
|
`.strip()` to drop them, or `.strict()` to reject them. For API input, one of the two is
|
|
331
328
|
recommended.
|
|
332
329
|
|
package/SECURITY.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Supported versions
|
|
4
4
|
|
|
5
|
-
Only the latest published minor version receives security fixes while
|
|
5
|
+
Only the latest published minor version receives security fixes while valiq-js is in 0.x.
|
|
6
6
|
|
|
7
7
|
## Reporting a vulnerability
|
|
8
8
|
|
|
@@ -10,9 +10,9 @@ Please report vulnerabilities privately. Do not open a public issue.
|
|
|
10
10
|
|
|
11
11
|
- Use GitHub's private vulnerability reporting ("Report a vulnerability" under the repository's
|
|
12
12
|
Security tab), or
|
|
13
|
-
- email the maintainer at mohsinziadev@gmail.com with "valiq security" in the subject.
|
|
13
|
+
- email the maintainer at mohsinziadev@gmail.com with "valiq-js security" in the subject.
|
|
14
14
|
|
|
15
|
-
Include the
|
|
15
|
+
Include the valiq-js version, a minimal schema and input that reproduce the problem, and the impact
|
|
16
16
|
you expect (for example "validation accepts X" or "validation hangs on Y"). You should get an
|
|
17
17
|
acknowledgement within 5 working days. Once a fix is released, the advisory credits the reporter
|
|
18
18
|
unless they prefer otherwise.
|
package/dist/core/error.cjs
CHANGED
|
@@ -38,7 +38,7 @@ var ValiqError = class extends Error {
|
|
|
38
38
|
}).join("\n");
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
-
/** True for errors thrown by
|
|
41
|
+
/** True for errors thrown by valiq-js's `parse()`. Works across realms and duplicate installs. */
|
|
42
42
|
function isValiqError(error) {
|
|
43
43
|
return error instanceof ValiqError || error instanceof Error && error.name === "ValiqError" && Array.isArray(error.issues);
|
|
44
44
|
}
|
package/dist/core/error.d.cts
CHANGED
|
@@ -16,5 +16,5 @@ export declare class ValiqError extends Error {
|
|
|
16
16
|
/** A multi-line report for logs and terminals. */
|
|
17
17
|
format(): string;
|
|
18
18
|
}
|
|
19
|
-
/** True for errors thrown by
|
|
19
|
+
/** True for errors thrown by valiq-js's `parse()`. Works across realms and duplicate installs. */
|
|
20
20
|
export declare function isValiqError(error: unknown): error is ValiqError;
|
package/dist/core/error.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export declare class ValiqError extends Error {
|
|
|
16
16
|
/** A multi-line report for logs and terminals. */
|
|
17
17
|
format(): string;
|
|
18
18
|
}
|
|
19
|
-
/** True for errors thrown by
|
|
19
|
+
/** True for errors thrown by valiq-js's `parse()`. Works across realms and duplicate installs. */
|
|
20
20
|
export declare function isValiqError(error: unknown): error is ValiqError;
|
package/dist/core/error.js
CHANGED
|
@@ -40,7 +40,7 @@ export class ValiqError extends Error {
|
|
|
40
40
|
.join('\n');
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
/** True for errors thrown by
|
|
43
|
+
/** True for errors thrown by valiq-js's `parse()`. Works across realms and duplicate installs. */
|
|
44
44
|
export function isValiqError(error) {
|
|
45
45
|
return (error instanceof ValiqError ||
|
|
46
46
|
(error instanceof Error && error.name === 'ValiqError' && Array.isArray(error.issues)));
|
package/dist/core/schema.cjs
CHANGED
|
@@ -144,7 +144,7 @@ var Schema = class {
|
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
146
|
* Adds a custom check that runs after the schema itself passed. `check` must be side-effect
|
|
147
|
-
* free:
|
|
147
|
+
* free: valiq-js may call it more than once for invalid input.
|
|
148
148
|
*/
|
|
149
149
|
refine(check, options) {
|
|
150
150
|
const opts = typeof options === "string" ? { message: options } : options ?? {};
|
package/dist/core/schema.d.cts
CHANGED
|
@@ -37,7 +37,7 @@ export interface SafeParseFailure {
|
|
|
37
37
|
}
|
|
38
38
|
export type SafeParseResult<T> = SafeParseSuccess<T> | SafeParseFailure;
|
|
39
39
|
type StandardProps<In, Out> = StandardSchemaV1.Props<In, Out> & StandardJSONSchemaV1.Props<In, Out>;
|
|
40
|
-
/** Any
|
|
40
|
+
/** Any valiq-js schema. Use as a constraint: `<S extends AnySchema>`. */
|
|
41
41
|
export type AnySchema = Schema<unknown, unknown>;
|
|
42
42
|
/** The output type of a schema: what `parse` returns. */
|
|
43
43
|
export type Infer<S extends AnySchema> = S['~types']['output'];
|
|
@@ -81,7 +81,7 @@ export declare abstract class Schema<Out = unknown, In = Out> implements Standar
|
|
|
81
81
|
default(value: Exclude<Out, undefined> | (() => Exclude<Out, undefined>)): DefaultSchema<this>;
|
|
82
82
|
/**
|
|
83
83
|
* Adds a custom check that runs after the schema itself passed. `check` must be side-effect
|
|
84
|
-
* free:
|
|
84
|
+
* free: valiq-js may call it more than once for invalid input.
|
|
85
85
|
*/
|
|
86
86
|
refine(check: (value: Out) => boolean, options?: string | RefineOptions): this;
|
|
87
87
|
/** Maps the validated value to something else. The function receives already-valid data. */
|
package/dist/core/schema.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface SafeParseFailure {
|
|
|
37
37
|
}
|
|
38
38
|
export type SafeParseResult<T> = SafeParseSuccess<T> | SafeParseFailure;
|
|
39
39
|
type StandardProps<In, Out> = StandardSchemaV1.Props<In, Out> & StandardJSONSchemaV1.Props<In, Out>;
|
|
40
|
-
/** Any
|
|
40
|
+
/** Any valiq-js schema. Use as a constraint: `<S extends AnySchema>`. */
|
|
41
41
|
export type AnySchema = Schema<unknown, unknown>;
|
|
42
42
|
/** The output type of a schema: what `parse` returns. */
|
|
43
43
|
export type Infer<S extends AnySchema> = S['~types']['output'];
|
|
@@ -81,7 +81,7 @@ export declare abstract class Schema<Out = unknown, In = Out> implements Standar
|
|
|
81
81
|
default(value: Exclude<Out, undefined> | (() => Exclude<Out, undefined>)): DefaultSchema<this>;
|
|
82
82
|
/**
|
|
83
83
|
* Adds a custom check that runs after the schema itself passed. `check` must be side-effect
|
|
84
|
-
* free:
|
|
84
|
+
* free: valiq-js may call it more than once for invalid input.
|
|
85
85
|
*/
|
|
86
86
|
refine(check: (value: Out) => boolean, options?: string | RefineOptions): this;
|
|
87
87
|
/** Maps the validated value to something else. The function receives already-valid data. */
|
package/dist/core/schema.js
CHANGED
|
@@ -141,7 +141,7 @@ export class Schema {
|
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
143
|
* Adds a custom check that runs after the schema itself passed. `check` must be side-effect
|
|
144
|
-
* free:
|
|
144
|
+
* free: valiq-js may call it more than once for invalid input.
|
|
145
145
|
*/
|
|
146
146
|
refine(check, options) {
|
|
147
147
|
const opts = typeof options === 'string' ? { message: options } : (options ?? {});
|
package/dist/core/standard.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Structural copies of the Standard Schema and Standard JSON Schema interfaces
|
|
2
2
|
// (https://standardschema.dev, MIT). The spec asks implementers to copy them instead of
|
|
3
|
-
// depending on @standard-schema/spec, so
|
|
3
|
+
// depending on @standard-schema/spec, so valiq-js keeps zero runtime dependencies.
|
|
4
4
|
export {};
|
|
@@ -1104,7 +1104,7 @@ var Compiler = class {
|
|
|
1104
1104
|
}
|
|
1105
1105
|
}
|
|
1106
1106
|
};
|
|
1107
|
-
/** Adapts a JSON Schema validator to
|
|
1107
|
+
/** Adapts a JSON Schema validator to valiq-js's `run` contract. */
|
|
1108
1108
|
function toRun(validate) {
|
|
1109
1109
|
return (value, ctx) => validate(value, ctx) ? value : require_context.FAIL;
|
|
1110
1110
|
}
|
|
@@ -23,7 +23,7 @@ export interface JSONSchemaOptions {
|
|
|
23
23
|
customFormats?: Record<string, RegExp | ((value: string) => boolean)>;
|
|
24
24
|
/**
|
|
25
25
|
* Other schemas that `$ref` may point to, as a list (each needs an `$id`) or keyed by URI.
|
|
26
|
-
*
|
|
26
|
+
* valiq-js never fetches schemas over the network.
|
|
27
27
|
*/
|
|
28
28
|
schemas?: readonly JSONSchemaDocument[] | Record<string, JSONSchemaDocument>;
|
|
29
29
|
/** Builds pattern matchers, e.g. `(source) => new RE2(source, 'u')` to rule out ReDoS. */
|
|
@@ -76,6 +76,6 @@ export declare class Compiler {
|
|
|
76
76
|
private objectKeywords;
|
|
77
77
|
private applicators;
|
|
78
78
|
}
|
|
79
|
-
/** Adapts a JSON Schema validator to
|
|
79
|
+
/** Adapts a JSON Schema validator to valiq-js's `run` contract. */
|
|
80
80
|
export declare function toRun(validate: Validate): (value: unknown, ctx: Ctx) => unknown;
|
|
81
81
|
export {};
|
|
@@ -23,7 +23,7 @@ export interface JSONSchemaOptions {
|
|
|
23
23
|
customFormats?: Record<string, RegExp | ((value: string) => boolean)>;
|
|
24
24
|
/**
|
|
25
25
|
* Other schemas that `$ref` may point to, as a list (each needs an `$id`) or keyed by URI.
|
|
26
|
-
*
|
|
26
|
+
* valiq-js never fetches schemas over the network.
|
|
27
27
|
*/
|
|
28
28
|
schemas?: readonly JSONSchemaDocument[] | Record<string, JSONSchemaDocument>;
|
|
29
29
|
/** Builds pattern matchers, e.g. `(source) => new RE2(source, 'u')` to rule out ReDoS. */
|
|
@@ -76,6 +76,6 @@ export declare class Compiler {
|
|
|
76
76
|
private objectKeywords;
|
|
77
77
|
private applicators;
|
|
78
78
|
}
|
|
79
|
-
/** Adapts a JSON Schema validator to
|
|
79
|
+
/** Adapts a JSON Schema validator to valiq-js's `run` contract. */
|
|
80
80
|
export declare function toRun(validate: Validate): (value: unknown, ctx: Ctx) => unknown;
|
|
81
81
|
export {};
|
|
@@ -1182,7 +1182,7 @@ export class Compiler {
|
|
|
1182
1182
|
}
|
|
1183
1183
|
}
|
|
1184
1184
|
}
|
|
1185
|
-
/** Adapts a JSON Schema validator to
|
|
1185
|
+
/** Adapts a JSON Schema validator to valiq-js's `run` contract. */
|
|
1186
1186
|
export function toRun(validate) {
|
|
1187
1187
|
return (value, ctx) => (validate(value, ctx) ? value : FAIL);
|
|
1188
1188
|
}
|
|
@@ -5,7 +5,7 @@ const require_schema = require("../core/schema.cjs");
|
|
|
5
5
|
const require_compile = require("./compile.cjs");
|
|
6
6
|
// src/json-schema/index.ts
|
|
7
7
|
/**
|
|
8
|
-
* A
|
|
8
|
+
* A valiq-js schema backed by a JSON Schema document. It has the full schema API (`parse`,
|
|
9
9
|
* `safeParse`, `is`, `.optional()`, `.refine()`...) and can be nested inside `v.object()`.
|
|
10
10
|
*/
|
|
11
11
|
var JSONSchemaSchema = class extends require_schema.Schema {
|
|
@@ -34,7 +34,7 @@ var JSONSchemaSchema = class extends require_schema.Schema {
|
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
|
-
* Compiles a JSON Schema (2020-12, 2019-09 or draft-07) into a
|
|
37
|
+
* Compiles a JSON Schema (2020-12, 2019-09 or draft-07) into a valiq-js schema. Declare the schema
|
|
38
38
|
* `as const` to infer its TypeScript type. Throws `JSONSchemaError` for invalid or unsupported
|
|
39
39
|
* schemas, so problems surface at startup rather than on the first request.
|
|
40
40
|
*/
|
|
@@ -8,7 +8,7 @@ export type { FromSchema } from './infer.cjs';
|
|
|
8
8
|
export { toJSONSchema } from '../to-json-schema.cjs';
|
|
9
9
|
export type { ToJSONSchemaOptions, JSONSchemaTarget } from '../to-json-schema.cjs';
|
|
10
10
|
/**
|
|
11
|
-
* A
|
|
11
|
+
* A valiq-js schema backed by a JSON Schema document. It has the full schema API (`parse`,
|
|
12
12
|
* `safeParse`, `is`, `.optional()`, `.refine()`...) and can be nested inside `v.object()`.
|
|
13
13
|
*/
|
|
14
14
|
export declare class JSONSchemaSchema<T = unknown> extends Schema<T> {
|
|
@@ -26,7 +26,7 @@ export declare class JSONSchemaSchema<T = unknown> extends Schema<T> {
|
|
|
26
26
|
typed<U>(): JSONSchemaSchema<U>;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Compiles a JSON Schema (2020-12, 2019-09 or draft-07) into a
|
|
29
|
+
* Compiles a JSON Schema (2020-12, 2019-09 or draft-07) into a valiq-js schema. Declare the schema
|
|
30
30
|
* `as const` to infer its TypeScript type. Throws `JSONSchemaError` for invalid or unsupported
|
|
31
31
|
* schemas, so problems surface at startup rather than on the first request.
|
|
32
32
|
*/
|
|
@@ -8,7 +8,7 @@ export type { FromSchema } from './infer.js';
|
|
|
8
8
|
export { toJSONSchema } from '../to-json-schema.js';
|
|
9
9
|
export type { ToJSONSchemaOptions, JSONSchemaTarget } from '../to-json-schema.js';
|
|
10
10
|
/**
|
|
11
|
-
* A
|
|
11
|
+
* A valiq-js schema backed by a JSON Schema document. It has the full schema API (`parse`,
|
|
12
12
|
* `safeParse`, `is`, `.optional()`, `.refine()`...) and can be nested inside `v.object()`.
|
|
13
13
|
*/
|
|
14
14
|
export declare class JSONSchemaSchema<T = unknown> extends Schema<T> {
|
|
@@ -26,7 +26,7 @@ export declare class JSONSchemaSchema<T = unknown> extends Schema<T> {
|
|
|
26
26
|
typed<U>(): JSONSchemaSchema<U>;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Compiles a JSON Schema (2020-12, 2019-09 or draft-07) into a
|
|
29
|
+
* Compiles a JSON Schema (2020-12, 2019-09 or draft-07) into a valiq-js schema. Declare the schema
|
|
30
30
|
* `as const` to infer its TypeScript type. Throws `JSONSchemaError` for invalid or unsupported
|
|
31
31
|
* schemas, so problems surface at startup rather than on the first request.
|
|
32
32
|
*/
|
|
@@ -4,7 +4,7 @@ import { silentCtx } from "../core/context.js";
|
|
|
4
4
|
export { JSONSchemaError } from "./compile.js";
|
|
5
5
|
export { toJSONSchema } from "../to-json-schema.js";
|
|
6
6
|
/**
|
|
7
|
-
* A
|
|
7
|
+
* A valiq-js schema backed by a JSON Schema document. It has the full schema API (`parse`,
|
|
8
8
|
* `safeParse`, `is`, `.optional()`, `.refine()`...) and can be nested inside `v.object()`.
|
|
9
9
|
*/
|
|
10
10
|
export class JSONSchemaSchema extends Schema {
|
|
@@ -37,7 +37,7 @@ export class JSONSchemaSchema extends Schema {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Compiles a JSON Schema (2020-12, 2019-09 or draft-07) into a
|
|
40
|
+
* Compiles a JSON Schema (2020-12, 2019-09 or draft-07) into a valiq-js schema. Declare the schema
|
|
41
41
|
* `as const` to infer its TypeScript type. Throws `JSONSchemaError` for invalid or unsupported
|
|
42
42
|
* schemas, so problems surface at startup rather than on the first request.
|
|
43
43
|
*/
|
|
@@ -76,7 +76,7 @@ function findDiscriminator(options) {
|
|
|
76
76
|
const map = new Map();
|
|
77
77
|
for (let i = 0; i < shapes.length; i++) {
|
|
78
78
|
const schema = shapes[i][key];
|
|
79
|
-
// Kind checks rather than instanceof, so schemas from a second copy of
|
|
79
|
+
// Kind checks rather than instanceof, so schemas from a second copy of valiq-js still work.
|
|
80
80
|
const values = schema?.kind === 'literal'
|
|
81
81
|
? [schema.value]
|
|
82
82
|
: schema?.kind === 'enum'
|
package/dist/to-json-schema.cjs
CHANGED
|
@@ -19,7 +19,7 @@ function escapeRegExp(text) {
|
|
|
19
19
|
return text.replace(/[\\^$.*+?()[\]{}|/-]/g, "\\$&");
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Converts a
|
|
22
|
+
* Converts a valiq-js schema to JSON Schema. Refinements are not represented; everything else either
|
|
23
23
|
* converts exactly or follows the `unrepresentable` option.
|
|
24
24
|
*/
|
|
25
25
|
function toJSONSchema(schema, options = {}) {
|
|
@@ -17,7 +17,7 @@ export interface ToJSONSchemaOptions {
|
|
|
17
17
|
}
|
|
18
18
|
type JSONObject = Record<string, unknown>;
|
|
19
19
|
/**
|
|
20
|
-
* Converts a
|
|
20
|
+
* Converts a valiq-js schema to JSON Schema. Refinements are not represented; everything else either
|
|
21
21
|
* converts exactly or follows the `unrepresentable` option.
|
|
22
22
|
*/
|
|
23
23
|
export declare function toJSONSchema(schema: AnySchema, options?: ToJSONSchemaOptions): JSONObject;
|
package/dist/to-json-schema.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface ToJSONSchemaOptions {
|
|
|
17
17
|
}
|
|
18
18
|
type JSONObject = Record<string, unknown>;
|
|
19
19
|
/**
|
|
20
|
-
* Converts a
|
|
20
|
+
* Converts a valiq-js schema to JSON Schema. Refinements are not represented; everything else either
|
|
21
21
|
* converts exactly or follows the `unrepresentable` option.
|
|
22
22
|
*/
|
|
23
23
|
export declare function toJSONSchema(schema: AnySchema, options?: ToJSONSchemaOptions): JSONObject;
|
package/dist/to-json-schema.js
CHANGED
|
@@ -18,7 +18,7 @@ function escapeRegExp(text) {
|
|
|
18
18
|
return text.replace(/[\\^$.*+?()[\]{}|/-]/g, '\\$&');
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Converts a
|
|
21
|
+
* Converts a valiq-js schema to JSON Schema. Refinements are not represented; everything else either
|
|
22
22
|
* converts exactly or follows the `unrepresentable` option.
|
|
23
23
|
*/
|
|
24
24
|
export function toJSONSchema(schema, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valiq-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "TypeScript-first schema validation with precise, structured errors, JSON Schema (2020-12, 2019-09, draft-07) support, Standard Schema compatibility and zero dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"validation",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"json"
|
|
21
21
|
],
|
|
22
22
|
"author": "Mohsin Zia <mohsinziadev@gmail.com>",
|
|
23
|
-
"homepage": "https://www.m2toolkit.com/npm-packages/valiq",
|
|
23
|
+
"homepage": "https://www.m2toolkit.com/npm-packages/valiq-js",
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
26
26
|
"url": "git+https://github.com/Mohsinziadev/valiq.git"
|