@lunora/values 1.0.0-alpha.1 → 1.0.0-alpha.3
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/dist/index.d.mts
CHANGED
|
@@ -400,6 +400,44 @@ type ValidatorMap = Record<string, Validator>;
|
|
|
400
400
|
/** Infer the object type from a {@link ValidatorMap} — optional validators (`v.optional`) become optional keys. */
|
|
401
401
|
type InferValidatorMap<A extends ValidatorMap> = { [K in keyof A as undefined extends Infer<A[K]> ? K : never]?: Infer<A[K]> } & { [K in keyof A as undefined extends Infer<A[K]> ? never : K]: Infer<A[K]> };
|
|
402
402
|
/**
|
|
403
|
+
* A precompiled fast-path parser for one {@link ValidatorMap}. Returns the fully
|
|
404
|
+
* built, validated record on a confident success, or the {@link DEFER_VALIDATION}
|
|
405
|
+
* sentinel to hand the input back to the interpreted parser.
|
|
406
|
+
*
|
|
407
|
+
* The contract is soundness, not completeness: a compiled parser may return
|
|
408
|
+
* {@link DEFER_VALIDATION} for any input it is not certain about (the interpreted
|
|
409
|
+
* path then runs and either succeeds or throws the canonical error), but it must
|
|
410
|
+
* NEVER return a built record for input the interpreted parser would reject, and
|
|
411
|
+
* the record it returns must be byte-for-byte what the interpreted parser would
|
|
412
|
+
* have produced. This lets `@lunora/codegen` emit zero-allocation structural
|
|
413
|
+
* checks (the common case) while every error message and every tricky validator
|
|
414
|
+
* still flows through the single interpreted implementation below — so error
|
|
415
|
+
* contracts can never drift.
|
|
416
|
+
*
|
|
417
|
+
* The `source` parameter is intentionally `any`: the codegen-emitted body is
|
|
418
|
+
* plain JavaScript (no type annotations — it must also be loadable via
|
|
419
|
+
* `new Function` in the compiler's differential tests) that index-walks the input
|
|
420
|
+
* to arbitrary depth, which strict TypeScript forbids on `unknown`/`object`. An
|
|
421
|
+
* `any` input lets the emitted structural checks type-check cleanly while the
|
|
422
|
+
* RESULT stays strongly typed; soundness is enforced by the differential test
|
|
423
|
+
* harness, not the input type.
|
|
424
|
+
*/
|
|
425
|
+
type CompiledValidatorMap = (source: any) => Record<string, unknown> | typeof DEFER_VALIDATION;
|
|
426
|
+
/**
|
|
427
|
+
* Sentinel a {@link CompiledValidatorMap} returns to defer to the interpreted
|
|
428
|
+
* parser. A unique symbol (never a valid parse result — {@link parseValidatorMap}
|
|
429
|
+
* always yields a record) so the seam can distinguish "compiled handled it" from
|
|
430
|
+
* "compiled bailed" with a single identity check and no per-call allocation.
|
|
431
|
+
*/
|
|
432
|
+
declare const DEFER_VALIDATION: unique symbol;
|
|
433
|
+
/**
|
|
434
|
+
* Install a compiled fast-path parser for `validators`. Idempotent-ish: a second
|
|
435
|
+
* install overwrites the first (codegen emits each map once, so this only matters
|
|
436
|
+
* if a host installs by hand). See {@link CompiledValidatorMap} for the contract
|
|
437
|
+
* the parser must honour.
|
|
438
|
+
*/
|
|
439
|
+
declare const installCompiledValidatorMap: (validators: object, compiled: CompiledValidatorMap) => void;
|
|
440
|
+
/**
|
|
403
441
|
* Validate each declared field of `source` through its validator, re-wrapping
|
|
404
442
|
* any {@link ValidationError} with a `label.<key>:` prefix and the rebuilt path
|
|
405
443
|
* `[key, ...error.path]` so the failure points at the offending field. Optional
|
|
@@ -411,7 +449,12 @@ type InferValidatorMap<A extends ValidatorMap> = { [K in keyof A as undefined ex
|
|
|
411
449
|
* `body` / `params`), and `@lunora/workflow`'s reusable steps (`step args`) — so
|
|
412
450
|
* the error-prefixing and optional-skip semantics can't drift apart. The `label`
|
|
413
451
|
* is the only thing each caller varies.
|
|
452
|
+
*
|
|
453
|
+
* When a codegen-emitted {@link CompiledValidatorMap} is installed for this exact
|
|
454
|
+
* `validators` object, the fast path runs first; it either returns the finished
|
|
455
|
+
* record (a confident success — the common case) or {@link DEFER_VALIDATION}, in
|
|
456
|
+
* which case the interpreted loop below runs and owns the result (and any error).
|
|
414
457
|
*/
|
|
415
458
|
declare const parseValidatorMap: (validators: ValidatorMap, source: Record<string, unknown>, label: string) => Record<string, unknown>;
|
|
416
459
|
declare const VERSION = "0.0.0";
|
|
417
|
-
export { type CheckOptions, type Column, type ColumnMeta, type ColumnValidator, type Id, type Infer, type InferInsert, type InferSelect, type InferStandardOutput, type InferValidatorMap, type InsertShape, type JsonSchema, type JsonSchemaFragment, type MetaOptions, type SchemaNodeReader, type SelectShape, type ServerDefaultContext, type TimestampColumnValidator, VERSION, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, argsToJsonSchema, describeValue, formatPath, isOrWrapsFromValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
|
460
|
+
export { type CheckOptions, type Column, type ColumnMeta, type ColumnValidator, type CompiledValidatorMap, DEFER_VALIDATION, type Id, type Infer, type InferInsert, type InferSelect, type InferStandardOutput, type InferValidatorMap, type InsertShape, type JsonSchema, type JsonSchemaFragment, type MetaOptions, type SchemaNodeReader, type SelectShape, type ServerDefaultContext, type TimestampColumnValidator, VERSION, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, argsToJsonSchema, describeValue, formatPath, installCompiledValidatorMap, isOrWrapsFromValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
package/dist/index.d.ts
CHANGED
|
@@ -400,6 +400,44 @@ type ValidatorMap = Record<string, Validator>;
|
|
|
400
400
|
/** Infer the object type from a {@link ValidatorMap} — optional validators (`v.optional`) become optional keys. */
|
|
401
401
|
type InferValidatorMap<A extends ValidatorMap> = { [K in keyof A as undefined extends Infer<A[K]> ? K : never]?: Infer<A[K]> } & { [K in keyof A as undefined extends Infer<A[K]> ? never : K]: Infer<A[K]> };
|
|
402
402
|
/**
|
|
403
|
+
* A precompiled fast-path parser for one {@link ValidatorMap}. Returns the fully
|
|
404
|
+
* built, validated record on a confident success, or the {@link DEFER_VALIDATION}
|
|
405
|
+
* sentinel to hand the input back to the interpreted parser.
|
|
406
|
+
*
|
|
407
|
+
* The contract is soundness, not completeness: a compiled parser may return
|
|
408
|
+
* {@link DEFER_VALIDATION} for any input it is not certain about (the interpreted
|
|
409
|
+
* path then runs and either succeeds or throws the canonical error), but it must
|
|
410
|
+
* NEVER return a built record for input the interpreted parser would reject, and
|
|
411
|
+
* the record it returns must be byte-for-byte what the interpreted parser would
|
|
412
|
+
* have produced. This lets `@lunora/codegen` emit zero-allocation structural
|
|
413
|
+
* checks (the common case) while every error message and every tricky validator
|
|
414
|
+
* still flows through the single interpreted implementation below — so error
|
|
415
|
+
* contracts can never drift.
|
|
416
|
+
*
|
|
417
|
+
* The `source` parameter is intentionally `any`: the codegen-emitted body is
|
|
418
|
+
* plain JavaScript (no type annotations — it must also be loadable via
|
|
419
|
+
* `new Function` in the compiler's differential tests) that index-walks the input
|
|
420
|
+
* to arbitrary depth, which strict TypeScript forbids on `unknown`/`object`. An
|
|
421
|
+
* `any` input lets the emitted structural checks type-check cleanly while the
|
|
422
|
+
* RESULT stays strongly typed; soundness is enforced by the differential test
|
|
423
|
+
* harness, not the input type.
|
|
424
|
+
*/
|
|
425
|
+
type CompiledValidatorMap = (source: any) => Record<string, unknown> | typeof DEFER_VALIDATION;
|
|
426
|
+
/**
|
|
427
|
+
* Sentinel a {@link CompiledValidatorMap} returns to defer to the interpreted
|
|
428
|
+
* parser. A unique symbol (never a valid parse result — {@link parseValidatorMap}
|
|
429
|
+
* always yields a record) so the seam can distinguish "compiled handled it" from
|
|
430
|
+
* "compiled bailed" with a single identity check and no per-call allocation.
|
|
431
|
+
*/
|
|
432
|
+
declare const DEFER_VALIDATION: unique symbol;
|
|
433
|
+
/**
|
|
434
|
+
* Install a compiled fast-path parser for `validators`. Idempotent-ish: a second
|
|
435
|
+
* install overwrites the first (codegen emits each map once, so this only matters
|
|
436
|
+
* if a host installs by hand). See {@link CompiledValidatorMap} for the contract
|
|
437
|
+
* the parser must honour.
|
|
438
|
+
*/
|
|
439
|
+
declare const installCompiledValidatorMap: (validators: object, compiled: CompiledValidatorMap) => void;
|
|
440
|
+
/**
|
|
403
441
|
* Validate each declared field of `source` through its validator, re-wrapping
|
|
404
442
|
* any {@link ValidationError} with a `label.<key>:` prefix and the rebuilt path
|
|
405
443
|
* `[key, ...error.path]` so the failure points at the offending field. Optional
|
|
@@ -411,7 +449,12 @@ type InferValidatorMap<A extends ValidatorMap> = { [K in keyof A as undefined ex
|
|
|
411
449
|
* `body` / `params`), and `@lunora/workflow`'s reusable steps (`step args`) — so
|
|
412
450
|
* the error-prefixing and optional-skip semantics can't drift apart. The `label`
|
|
413
451
|
* is the only thing each caller varies.
|
|
452
|
+
*
|
|
453
|
+
* When a codegen-emitted {@link CompiledValidatorMap} is installed for this exact
|
|
454
|
+
* `validators` object, the fast path runs first; it either returns the finished
|
|
455
|
+
* record (a confident success — the common case) or {@link DEFER_VALIDATION}, in
|
|
456
|
+
* which case the interpreted loop below runs and owns the result (and any error).
|
|
414
457
|
*/
|
|
415
458
|
declare const parseValidatorMap: (validators: ValidatorMap, source: Record<string, unknown>, label: string) => Record<string, unknown>;
|
|
416
459
|
declare const VERSION = "0.0.0";
|
|
417
|
-
export { type CheckOptions, type Column, type ColumnMeta, type ColumnValidator, type Id, type Infer, type InferInsert, type InferSelect, type InferStandardOutput, type InferValidatorMap, type InsertShape, type JsonSchema, type JsonSchemaFragment, type MetaOptions, type SchemaNodeReader, type SelectShape, type ServerDefaultContext, type TimestampColumnValidator, VERSION, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, argsToJsonSchema, describeValue, formatPath, isOrWrapsFromValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
|
460
|
+
export { type CheckOptions, type Column, type ColumnMeta, type ColumnValidator, type CompiledValidatorMap, DEFER_VALIDATION, type Id, type Infer, type InferInsert, type InferSelect, type InferStandardOutput, type InferValidatorMap, type InsertShape, type JsonSchema, type JsonSchemaFragment, type MetaOptions, type SchemaNodeReader, type SelectShape, type ServerDefaultContext, type TimestampColumnValidator, VERSION, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, argsToJsonSchema, describeValue, formatPath, installCompiledValidatorMap, isOrWrapsFromValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ export { ValidationError, describeValue, formatPath } from './packem_shared/Vali
|
|
|
2
2
|
export { jsonSchemaFromNode, objectSchemaFromNodes } from './packem_shared/jsonSchemaFromNode-weszUOQG.mjs';
|
|
3
3
|
export { argsToJsonSchema, toJsonSchema } from './packem_shared/argsToJsonSchema-DdHmmamC.mjs';
|
|
4
4
|
export { isOrWrapsFromValidator, optionalInner, v } from './packem_shared/isOrWrapsFromValidator-DJMAE0l9.mjs';
|
|
5
|
-
export { parseValidatorMap } from './packem_shared/
|
|
5
|
+
export { DEFER_VALIDATION, installCompiledValidatorMap, parseValidatorMap } from './packem_shared/DEFER_VALIDATION-B23I3ZdL.mjs';
|
|
6
6
|
|
|
7
7
|
const VERSION = "0.0.0";
|
|
8
8
|
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { ValidationError } from './ValidationError-DWWcFe37.mjs';
|
|
2
2
|
|
|
3
|
+
const DEFER_VALIDATION = /* @__PURE__ */ Symbol("lunora.deferValidation");
|
|
4
|
+
const COMPILED_PARSERS = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
const installCompiledValidatorMap = (validators, compiled) => {
|
|
6
|
+
COMPILED_PARSERS.set(validators, compiled);
|
|
7
|
+
};
|
|
3
8
|
const parseValidatorMap = (validators, source, label) => {
|
|
9
|
+
const compiled = COMPILED_PARSERS.get(validators);
|
|
10
|
+
if (compiled !== void 0) {
|
|
11
|
+
const fast = compiled(source);
|
|
12
|
+
if (fast !== DEFER_VALIDATION) {
|
|
13
|
+
return fast;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
4
16
|
const out = {};
|
|
5
17
|
for (const key of Object.keys(validators)) {
|
|
6
18
|
const validator = validators[key];
|
|
@@ -27,4 +39,4 @@ const parseValidatorMap = (validators, source, label) => {
|
|
|
27
39
|
return out;
|
|
28
40
|
};
|
|
29
41
|
|
|
30
|
-
export { parseValidatorMap };
|
|
42
|
+
export { DEFER_VALIDATION, installCompiledValidatorMap, parseValidatorMap };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/values",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"description": "Validators for Lunora: the v.* validator suite with end-to-end return-type inference",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"directory": "packages/values"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist",
|
|
28
|
+
"./dist",
|
|
29
29
|
"README.md",
|
|
30
30
|
"LICENSE.md",
|
|
31
31
|
"__assets__"
|