Skip to content

Commit 8b398a3

Browse files
committed
Make Build and Evaluate fields private on Schema Validator | Formatting
1 parent 6dac45a commit 8b398a3

17 files changed

Lines changed: 122 additions & 124 deletions

readme.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -279,31 +279,31 @@ The following table shows compile performance for various JSON Schema structures
279279

280280
```python
281281
┌──────────────────────┬─────────────┬─────────────┐
282-
CompileTB1XAJV8
282+
Test TB1XAJV8
283283
├──────────────────────┼─────────────┼─────────────┤
284-
│ Boolean │ 28.4K ops/s │ 7K ops/s │
285-
│ Number │ 21.8K ops/s │ 7.7K ops/s │
286-
│ String │ 47.8K ops/s │ 7.3K ops/s │
287-
│ Null │ 35.6K ops/s │ 7.8K ops/s │
288-
│ Literal_String │ 28.6K ops/s │ 6.3K ops/s │
289-
│ Literal_Number │ 46.6K ops/s │ 6.2K ops/s │
290-
│ Literal_Boolean │ 40.8K ops/s │ 6.6K ops/s │
291-
│ Pattern │ 29.7K ops/s │ 4.9K ops/s │
292-
│ Object_Open │ 6.8K ops/s │ 1.1K ops/s │
293-
│ Object_Close │ 7.4K ops/s │ 833 ops/s │
294-
│ Object_Vector3 │ 19.4K ops/s │ 2.1K ops/s │
295-
│ Object_Basis3 │ 6K ops/s │ 895 ops/s │
296-
│ Intersect_And │ 12K ops/s │ 3.5K ops/s │
297-
│ Intersect_Structural │ 8.4K ops/s │ 1.1K ops/s │
298-
│ Union_Or │ 18.2K ops/s │ 2.5K ops/s │
299-
│ Union_Structural │ 10.9K ops/s │ 1.3K ops/s │
300-
│ Tuple_Values │ 7.3K ops/s │ 1.6K ops/s │
301-
│ Tuple_Objects │ 1.9K ops/s │ 339 ops/s │
302-
│ Array_Numbers_4 │ 29.9K ops/s │ 3.4K ops/s │
303-
│ Array_Numbers_8 │ 20.3K ops/s │ 3.4K ops/s │
304-
│ Array_Numbers_16 │ 29.4K ops/s │ 3.3K ops/s │
305-
│ Array_Objects_Open │ 6.3K ops/s │ 684 ops/s │
306-
│ Array_Objects_Close │ 7.3K ops/s │ 762 ops/s │
284+
│ Boolean │ 29.2K ops/s │ 7.1K ops/s │
285+
│ Number │ 34.5K ops/s │ 7.6K ops/s │
286+
│ String │ 48.9K ops/s │ 8.7K ops/s │
287+
│ Null │ 39.6K ops/s │ 7.6K ops/s │
288+
│ Literal_String │ 46.8K ops/s │ 6.8K ops/s │
289+
│ Literal_Number │ 48.3K ops/s │ 7.4K ops/s │
290+
│ Literal_Boolean │ 48.8K ops/s │ 7.3K ops/s │
291+
│ Pattern │ 32.5K ops/s │ 6.1K ops/s │
292+
│ Object_Open │ 6.6K ops/s │ 1.4K ops/s │
293+
│ Object_Close │ 7.6K ops/s │ 1K ops/s │
294+
│ Object_Vector3 │ 20.8K ops/s │ 2.8K ops/s │
295+
│ Object_Basis3 │ 7.5K ops/s │ 1K ops/s │
296+
│ Intersect_And │ 23K ops/s │ 3.9K ops/s │
297+
│ Intersect_Structural │ 8.7K ops/s │ 1.2K ops/s │
298+
│ Union_Or │ 17.9K ops/s │ 3.4K ops/s │
299+
│ Union_Structural │ 11.3K ops/s │ 2.1K ops/s │
300+
│ Tuple_Values │ 9.6K ops/s │ 2.1K ops/s │
301+
│ Tuple_Objects │ 2.1K ops/s │ 350 ops/s │
302+
│ Array_Numbers_4 │ 33.6K ops/s │ 4.2K ops/s │
303+
│ Array_Numbers_8 │ 39K ops/s │ 3.7K ops/s │
304+
│ Array_Numbers_16 │ 29.6K ops/s │ 3.8K ops/s │
305+
│ Array_Objects_Open │ 7.7K ops/s │ 833 ops/s │
306+
│ Array_Objects_Close │ 7.6K ops/s │ 860 ops/s │
307307
└──────────────────────┴─────────────┴─────────────┘
308308
```
309309

@@ -312,31 +312,31 @@ The following tables shows validation performance for various JSON Schema struct
312312

313313
```python
314314
┌──────────────────────┬──────────────┬──────────────┐
315-
ValidateTB1XAJV8
315+
Test TB1XAJV8
316316
├──────────────────────┼──────────────┼──────────────┤
317-
│ Boolean │ 164.1M ops/s │ 181.5M ops/s │
318-
│ Number │ 107M ops/s │ 50.2M ops/s │
319-
│ String │ 102.2M ops/s │ 61.9M ops/s │
320-
│ Null │ 112.1M ops/s │ 48.2M ops/s │
321-
│ Literal_String │ 102.8M ops/s │ 61.5M ops/s │
322-
│ Literal_Number │ 109.1M ops/s │ 46.4M ops/s │
323-
│ Literal_Boolean │ 109.6M ops/s │ 63.3M ops/s │
324-
│ Pattern │ 24.7M ops/s │ 20.3M ops/s │
325-
│ Object_Open │ 75.4M ops/s │ 37.3M ops/s │
326-
│ Object_Close │ 35.9M ops/s │ 21.9M ops/s │
327-
│ Object_Vector3 │ 77.6M ops/s │ 47.4M ops/s │
328-
│ Object_Basis3 │ 37M ops/s │ 24.3M ops/s │
329-
│ Intersect_And │ 93.3M ops/s │ 61.1M ops/s │
330-
│ Intersect_Structural │ 83M ops/s │ 36.4M ops/s │
331-
│ Union_Or │ 99.7M ops/s │ 8.6M ops/s │
332-
│ Union_Structural │ 81.3M ops/s │ 43.5M ops/s │
333-
│ Tuple_Values │ 72.4M ops/s │ 41.7M ops/s │
334-
│ Tuple_Objects │ 32.6M ops/s │ 22.4M ops/s │
335-
│ Array_Numbers_4 │ 94.1M ops/s │ 42.8M ops/s │
336-
│ Array_Numbers_8 │ 90.6M ops/s │ 42.3M ops/s │
337-
│ Array_Numbers_16 │ 77.5M ops/s │ 40.2M ops/s │
338-
│ Array_Objects_Open │ 26.3M ops/s │ 19.6M ops/s │
339-
│ Array_Objects_Close │ 9.1M ops/s │ 10M ops/s │
317+
│ Boolean │ 192.2M ops/s │ 189.5M ops/s │
318+
│ Number │ 112.4M ops/s │ 61M ops/s │
319+
│ String │ 113.7M ops/s │ 64.1M ops/s │
320+
│ Null │ 112.8M ops/s │ 64.9M ops/s │
321+
│ Literal_String │ 108M ops/s │ 62.9M ops/s │
322+
│ Literal_Number │ 113.5M ops/s │ 63.2M ops/s │
323+
│ Literal_Boolean │ 109.2M ops/s │ 64.1M ops/s │
324+
│ Pattern │ 26.5M ops/s │ 22.4M ops/s │
325+
│ Object_Open │ 78M ops/s │ 47.2M ops/s │
326+
│ Object_Close │ 38.6M ops/s │ 27.6M ops/s │
327+
│ Object_Vector3 │ 91M ops/s │ 51.3M ops/s │
328+
│ Object_Basis3 │ 41.1M ops/s │ 27.4M ops/s │
329+
│ Intersect_And │ 107.6M ops/s │ 59.9M ops/s │
330+
│ Intersect_Structural │ 83.6M ops/s │ 46.3M ops/s │
331+
│ Union_Or │ 95M ops/s │ 7.9M ops/s │
332+
│ Union_Structural │ 84.5M ops/s │ 52.3M ops/s │
333+
│ Tuple_Values │ 74.7M ops/s │ 53M ops/s │
334+
│ Tuple_Objects │ 32.9M ops/s │ 22.3M ops/s │
335+
│ Array_Numbers_4 │ 93.3M ops/s │ 55.1M ops/s │
336+
│ Array_Numbers_8 │ 90.3M ops/s │ 50.8M ops/s │
337+
│ Array_Numbers_16 │ 76.8M ops/s │ 39.6M ops/s │
338+
│ Array_Objects_Open │ 28.7M ops/s │ 20.4M ops/s │
339+
│ Array_Objects_Close │ 10.3M ops/s │ 10.8M ops/s │
340340
└──────────────────────┴──────────────┴──────────────┘
341341
```
342342

src/schema/compile.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ THE SOFTWARE.
3232
import { Arguments } from '../system/arguments/index.ts'
3333
import { type TLocalizedValidationError } from '../error/index.ts'
3434
import { type Static } from '../type/types/static.ts'
35-
import * as Build from './build.ts'
3635
import * as Schema from './types/index.ts'
36+
import * as Build from './build.ts'
3737
import { Errors } from './errors.ts'
3838
import { ParseError } from './parse.ts'
3939

@@ -43,33 +43,33 @@ import { ParseError } from './parse.ts'
4343
export class Validator<const Schema extends Schema.XSchema = Schema.XSchema,
4444
Value extends unknown = Static<Schema>
4545
> {
46-
private readonly build: Build.BuildResult
47-
private readonly result: Build.EvaluateResult
46+
readonly #buildResult: Build.BuildResult
47+
readonly #evaluateResult: Build.EvaluateResult
4848
constructor(context: Record<string, Schema.XSchema>, schema: Schema) {
49-
this.build = Build.Build(context, schema)
50-
this.result = this.build.Evaluate()
49+
this.#buildResult = Build.Build(context, schema)
50+
this.#evaluateResult = this.#buildResult.Evaluate()
5151
}
5252
/** Returns true if this Validator is using JIT acceleration. */
5353
public IsAccelerated(): boolean {
54-
return this.result.IsAccelerated
54+
return this.#evaluateResult.IsAccelerated
5555
}
5656
/** Returns the underlying Schema used to construct this Validator. */
5757
public Schema(): Schema {
58-
return this.build.Schema() as never
58+
return this.#buildResult.Schema() as never
5959
}
6060
/** Performs a type-guard check on the provided value. */
6161
public Check(value: unknown): value is Value {
62-
return this.result.Check(value)
62+
return this.#evaluateResult.Check(value)
6363
}
6464
/** Validates a value and returns it. Will throw if invalid. */
6565
public Parse(value: unknown): Value {
66-
if(this.result.Check(value)) return value as never
67-
const [_result, errors] = Errors(this.build.Context(), this.build.Schema(), value)
68-
throw new ParseError(this.build.Schema(), value, errors)
66+
if(this.#evaluateResult.Check(value)) return value as never
67+
const [_result, errors] = Errors(this.#buildResult.Context(), this.#buildResult.Schema(), value)
68+
throw new ParseError(this.#buildResult.Schema(), value, errors)
6969
}
7070
/** Inspects a value and returns a detailed list of validation errors. */
7171
public Errors(value: unknown): [result: boolean, errors: TLocalizedValidationError[]] {
72-
return Errors(this.build.Context(), this.build.Schema(), value)
72+
return Errors(this.#buildResult.Context(), this.#buildResult.Schema(), value)
7373
}
7474
}
7575
// ------------------------------------------------------------------

src/schema/engine/_context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function HasUnevaluated(context: Record<PropertyKey, unknown>, schema: un
5959
// BuildContext
6060
// ------------------------------------------------------------------
6161
export class BuildContext {
62-
constructor(private readonly hasUnevaluated: boolean) {}
62+
constructor(private readonly hasUnevaluated: boolean) { }
6363
public UseUnevaluated(): boolean {
6464
return this.hasUnevaluated
6565
}

src/schema/engine/_externals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ export function ResetExternal(): void {
5454
// GetExternals
5555
// ------------------------------------------------------------------
5656
export function GetExternal(): TExternal {
57-
return { ... state }
57+
return { ...state }
5858
}

src/schema/engine/additionalItems.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function BuildAdditionalItems(stack: Stack, context: BuildContext, schema
5959
export function CheckAdditionalItems(stack: Stack, context: CheckContext, schema: Schema.XAdditionalItems, value: unknown[]): boolean {
6060
if (!IsValid(schema)) return true
6161
const isAdditionalItems = value.every((item, index) => {
62-
return G.IsLessThan(index, schema.items.length)
62+
return G.IsLessThan(index, schema.items.length)
6363
|| (CheckSchemaPushStack(stack, context, schema.additionalItems, item) && context.AddIndex(index))
6464
})
6565
return isAdditionalItems
@@ -72,7 +72,7 @@ export function ErrorAdditionalItems(stack: Stack, context: ErrorContext, schema
7272
const isAdditionalItems = value.every((item, index) => {
7373
const nextSchemaPath = `${schemaPath}/additionalItems`
7474
const nextInstancePath = `${instancePath}/${index}`
75-
return G.IsLessThan(index, schema.items.length) ||
75+
return G.IsLessThan(index, schema.items.length) ||
7676
(ErrorSchemaPushStack(stack, context, nextSchemaPath, nextInstancePath, schema.additionalItems, item) && context.AddIndex(index))
7777
})
7878
return isAdditionalItems

src/schema/engine/additionalProperties.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function BuildAdditionalPropertiesStandard(stack: Stack, context: BuildCo
9292
const isKey = E.Call(E.Member(regexp, 'test'), [key])
9393
const addKey = context.AddKey(key)
9494
const guarded = context.UseUnevaluated() ? E.Or(isKey, E.And(isSchema, addKey)) : E.Or(isKey, isSchema)
95-
const result = E.Every(E.Keys(value), E.Constant(0), [key, _index], guarded)
95+
const result = E.Every(E.Keys(value), E.Constant(0), [key, _index], guarded)
9696
return result
9797
}
9898
// ------------------------------------------------------------------
@@ -109,7 +109,7 @@ export function BuildAdditionalProperties(stack: Stack, context: BuildContext, s
109109
export function CheckAdditionalProperties(stack: Stack, context: CheckContext, schema: S.XAdditionalProperties, value: Record<PropertyKey, unknown>): boolean {
110110
const regexp = new RegExp(GetPropertiesPattern(schema))
111111
const isAdditionalProperties = G.Every(G.Keys(value), 0, (key, _index) => {
112-
return regexp.test(key) ||
112+
return regexp.test(key) ||
113113
(CheckSchemaPushStack(stack, context, schema.additionalProperties, value[key]) && context.AddKey(key))
114114
})
115115
return isAdditionalProperties
@@ -124,16 +124,16 @@ export function ErrorAdditionalProperties(stack: Stack, context: ErrorContext, s
124124
const nextSchemaPath = `${schemaPath}/additionalProperties`
125125
const nextInstancePath = `${instancePath}/${key}`
126126
const nextContext = new AccumulatedErrorContext()
127-
const isAdditionalProperty = regexp.test(key) ||
128-
(ErrorSchemaPushStack(stack, nextContext, nextSchemaPath, nextInstancePath, schema.additionalProperties, value[key]) && context.AddKey(key))
127+
const isAdditionalProperty = regexp.test(key) ||
128+
(ErrorSchemaPushStack(stack, nextContext, nextSchemaPath, nextInstancePath, schema.additionalProperties, value[key]) && context.AddKey(key))
129129

130130
if (!isAdditionalProperty) additionalProperties.push(key)
131131
return isAdditionalProperty
132132
})
133133
return isAdditionalProperties || context.AddError({
134134
keyword: 'additionalProperties',
135135
schemaPath,
136-
instancePath: instancePath,
136+
instancePath,
137137
params: { additionalProperties },
138138
})
139139
}

src/schema/engine/allOf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function BuildAllOfFast(stack: Stack, context: BuildContext, schema: Schema.XAll
4545
return E.ReduceAnd(schema.allOf.map((schema) => BuildSchema(stack, context, schema, value)))
4646
}
4747
export function BuildAllOf(stack: Stack, context: BuildContext, schema: Schema.XAllOf, value: string): string {
48-
return context.UseUnevaluated()
49-
? BuildAllOfStandard(stack, context, schema, value)
48+
return context.UseUnevaluated()
49+
? BuildAllOfStandard(stack, context, schema, value)
5050
: BuildAllOfFast(stack, context, schema, value)
5151
}
5252
// ------------------------------------------------------------------

src/schema/engine/anyOf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function BuildAnyOfFast(stack: Stack, context: BuildContext, schema: Schema.XAny
4545
return E.ReduceOr(schema.anyOf.map((schema) => BuildSchema(stack, context, schema, value)))
4646
}
4747
export function BuildAnyOf(stack: Stack, context: BuildContext, schema: Schema.XAnyOf, value: string): string {
48-
return context.UseUnevaluated()
49-
? BuildAnyOfStandard(stack, context, schema, value)
48+
return context.UseUnevaluated()
49+
? BuildAnyOfStandard(stack, context, schema, value)
5050
: BuildAnyOfFast(stack, context, schema, value)
5151
}
5252
// ------------------------------------------------------------------

src/schema/engine/contains.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function BuildContains(stack: Stack, context: BuildContext, schema: Schem
5757
// ------------------------------------------------------------------
5858
export function CheckContains(stack: Stack, context: CheckContext, schema: Schema.XContains, value: unknown[]): boolean {
5959
if (!IsValid(schema)) return true
60-
return !G.IsEqual(value.length, 0) &&
60+
return !G.IsEqual(value.length, 0) &&
6161
value.some((item) => CheckSchema(stack, context, schema.contains, item))
6262
}
6363
// ------------------------------------------------------------------

src/schema/engine/dependentRequired.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function CheckDependentRequired(_stack: Stack, _context: CheckContext, sc
6161
// ------------------------------------------------------------------
6262
// Error
6363
// ------------------------------------------------------------------
64-
export function ErrorDependentRequired(_stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XDependentRequired, value: Record<PropertyKey, unknown>): boolean {
64+
export function ErrorDependentRequired(_stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XDependentRequired, value: Record<PropertyKey, unknown>): boolean {
6565
const isLength = G.IsEqual(G.Keys(value).length, 0)
6666
const isEveryEntry = G.EveryAll(G.Entries(schema.dependentRequired), 0, ([key, keys]) => {
6767
return !G.HasPropertyKey(value, key) || G.EveryAll(keys, 0, (dependency) => G.HasPropertyKey(value, dependency) || context.AddError({

0 commit comments

Comments
 (0)