Skip to content

Commit

Permalink
chore: update to prettier 3.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoniangreen committed Feb 24, 2024
1 parent 95218d3 commit 27ed940
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 230 deletions.
30 changes: 25 additions & 5 deletions lib/compile/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ abstract class Node {
}

class Def extends Node {
constructor(private readonly varKind: Name, private readonly name: Name, private rhs?: SafeExpr) {
constructor(
private readonly varKind: Name,
private readonly name: Name,
private rhs?: SafeExpr
) {
super()
}

Expand All @@ -63,7 +67,11 @@ class Def extends Node {
}

class Assign extends Node {
constructor(readonly lhs: Code, public rhs: SafeExpr, private readonly sideEffects?: boolean) {
constructor(
readonly lhs: Code,
public rhs: SafeExpr,
private readonly sideEffects?: boolean
) {
super()
}

Expand All @@ -84,7 +92,12 @@ class Assign extends Node {
}

class AssignOp extends Assign {
constructor(lhs: Code, private readonly op: Code, rhs: SafeExpr, sideEffects?: boolean) {
constructor(
lhs: Code,
private readonly op: Code,
rhs: SafeExpr,
sideEffects?: boolean
) {
super(lhs, rhs, sideEffects)
}

Expand Down Expand Up @@ -211,7 +224,10 @@ class Else extends BlockNode {
class If extends BlockNode {
static readonly kind = "if"
else?: If | Else
constructor(private condition: Code | boolean, nodes?: ChildNode[]) {
constructor(
private condition: Code | boolean,
nodes?: ChildNode[]
) {
super(nodes)
}

Expand Down Expand Up @@ -331,7 +347,11 @@ class ForIter extends For {

class Func extends BlockNode {
static readonly kind = "func"
constructor(public name: Name, public args: Code, public async?: boolean) {
constructor(
public name: Name,
public args: Code,
public async?: boolean
) {
super()
}

Expand Down
12 changes: 6 additions & 6 deletions lib/compile/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ function makeMergeEvaluated<T extends SomeEvaluated>({
to === undefined
? from
: to instanceof Name
? (from instanceof Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to)
: from instanceof Name
? (mergeToName(gen, to, from), from)
: mergeValues(from, to)
? (from instanceof Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to)
: from instanceof Name
? (mergeToName(gen, to, from), from)
: mergeValues(from, to)
return toName === Name && !(res instanceof Name) ? resultToName(gen, res) : res
}
}
Expand Down Expand Up @@ -195,8 +195,8 @@ export function getErrorPath(
? _`"[" + ${dataProp} + "]"`
: _`"['" + ${dataProp} + "']"`
: isNumber
? _`"/" + ${dataProp}`
: _`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")` // TODO maybe use global escapePointer
? _`"/" + ${dataProp}`
: _`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")` // TODO maybe use global escapePointer
}
return jsPropertySyntax ? getProperty(dataProp).toString() : "/" + escapeJsonPointer(dataProp)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/compile/validate/keyword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export function validSchemaType(
st === "array"
? Array.isArray(schema)
: st === "object"
? schema && typeof schema == "object" && !Array.isArray(schema)
: typeof schema == st || (allowUndefined && typeof schema == "undefined")
? schema && typeof schema == "object" && !Array.isArray(schema)
: typeof schema == st || (allowUndefined && typeof schema == "undefined")
)
)
}
Expand Down
8 changes: 4 additions & 4 deletions lib/standalone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ function standaloneCode(
return typeof refsOrFunc == "function"
? funcExportCode(refsOrFunc.source)
: refsOrFunc !== undefined
? multiExportsCode<string>(refsOrFunc, getValidate)
: multiExportsCode<SchemaEnv>(ajv.schemas, (sch) =>
sch.meta ? undefined : ajv.compile(sch.schema)
)
? multiExportsCode<string>(refsOrFunc, getValidate)
: multiExportsCode<SchemaEnv>(ajv.schemas, (sch) =>
sch.meta ? undefined : ajv.compile(sch.schema)
)

function getValidate(id: string): AnyValidateFunction {
const v = ajv.getSchema(id)
Expand Down
9 changes: 6 additions & 3 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ export interface DataValidateFunction {
}

export interface SchemaValidateFunction {
(schema: any, data: any, parentSchema?: AnySchemaObject, dataCxt?: DataValidationCxt):
| boolean
| Promise<any>
(
schema: any,
data: any,
parentSchema?: AnySchemaObject,
dataCxt?: DataValidationCxt
): boolean | Promise<any>
errors?: Partial<ErrorObject>[]
}

Expand Down
138 changes: 71 additions & 67 deletions lib/types/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,84 +46,88 @@ type UncheckedJSONSchemaType<T, IsPartial extends boolean> = (
type: readonly (T extends number
? JSONType<"number" | "integer", IsPartial>
: T extends string
? JSONType<"string", IsPartial>
: T extends boolean
? JSONType<"boolean", IsPartial>
: never)[]
? JSONType<"string", IsPartial>
: T extends boolean
? JSONType<"boolean", IsPartial>
: never)[]
} & UnionToIntersection<
T extends number
? NumberKeywords
: T extends string
? StringKeywords
: T extends boolean
? // eslint-disable-next-line @typescript-eslint/ban-types
{}
: never
? StringKeywords
: T extends boolean
? // eslint-disable-next-line @typescript-eslint/ban-types
{}
: never
>)
// this covers "normal" types; it's last so typescript looks to it first for errors
| ((T extends number
? {
type: JSONType<"number" | "integer", IsPartial>
} & NumberKeywords
: T extends string
? {
type: JSONType<"string", IsPartial>
} & StringKeywords
: T extends boolean
? {
type: JSONType<"boolean", IsPartial>
}
: T extends readonly [any, ...any[]]
? {
// JSON AnySchema for tuple
type: JSONType<"array", IsPartial>
items: {
readonly [K in keyof T]-?: UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>
} & {length: T["length"]}
minItems: T["length"]
} & ({maxItems: T["length"]} | {additionalItems: false})
: T extends readonly any[]
? {
type: JSONType<"array", IsPartial>
items: UncheckedJSONSchemaType<T[0], false>
contains?: UncheckedPartialSchema<T[0]>
minItems?: number
maxItems?: number
minContains?: number
maxContains?: number
uniqueItems?: true
additionalItems?: never
}
: T extends Record<string, any>
? {
// JSON AnySchema for records and dictionaries
// "required" is not optional because it is often forgotten
// "properties" are optional for more concise dictionary schemas
// "patternProperties" and can be only used with interfaces that have string index
type: JSONType<"object", IsPartial>
additionalProperties?: boolean | UncheckedJSONSchemaType<T[string], false>
unevaluatedProperties?: boolean | UncheckedJSONSchemaType<T[string], false>
properties?: IsPartial extends true
? Partial<UncheckedPropertiesSchema<T>>
: UncheckedPropertiesSchema<T>
patternProperties?: Record<string, UncheckedJSONSchemaType<T[string], false>>
propertyNames?: Omit<UncheckedJSONSchemaType<string, false>, "type"> & {type?: "string"}
dependencies?: {[K in keyof T]?: Readonly<(keyof T)[]> | UncheckedPartialSchema<T>}
dependentRequired?: {[K in keyof T]?: Readonly<(keyof T)[]>}
dependentSchemas?: {[K in keyof T]?: UncheckedPartialSchema<T>}
minProperties?: number
maxProperties?: number
} & (IsPartial extends true // "required" is not necessary if it's a non-partial type with no required keys // are listed it only asserts that optional cannot be listed. // "required" type does not guarantee that all required properties
? {required: Readonly<(keyof T)[]>}
: [UncheckedRequiredMembers<T>] extends [never]
? {required?: Readonly<UncheckedRequiredMembers<T>[]>}
: {required: Readonly<UncheckedRequiredMembers<T>[]>})
: T extends null
? {
type: JSONType<"null", IsPartial>
nullable: true
}
: never) & {
? {
type: JSONType<"string", IsPartial>
} & StringKeywords
: T extends boolean
? {
type: JSONType<"boolean", IsPartial>
}
: T extends readonly [any, ...any[]]
? {
// JSON AnySchema for tuple
type: JSONType<"array", IsPartial>
items: {
readonly [K in keyof T]-?: UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>
} & {length: T["length"]}
minItems: T["length"]
} & ({maxItems: T["length"]} | {additionalItems: false})
: T extends readonly any[]
? {
type: JSONType<"array", IsPartial>
items: UncheckedJSONSchemaType<T[0], false>
contains?: UncheckedPartialSchema<T[0]>
minItems?: number
maxItems?: number
minContains?: number
maxContains?: number
uniqueItems?: true
additionalItems?: never
}
: T extends Record<string, any>
? {
// JSON AnySchema for records and dictionaries
// "required" is not optional because it is often forgotten
// "properties" are optional for more concise dictionary schemas
// "patternProperties" and can be only used with interfaces that have string index
type: JSONType<"object", IsPartial>
additionalProperties?: boolean | UncheckedJSONSchemaType<T[string], false>
unevaluatedProperties?: boolean | UncheckedJSONSchemaType<T[string], false>
properties?: IsPartial extends true
? Partial<UncheckedPropertiesSchema<T>>
: UncheckedPropertiesSchema<T>
patternProperties?: Record<string, UncheckedJSONSchemaType<T[string], false>>
propertyNames?: Omit<UncheckedJSONSchemaType<string, false>, "type"> & {
type?: "string"
}
dependencies?: {
[K in keyof T]?: Readonly<(keyof T)[]> | UncheckedPartialSchema<T>
}
dependentRequired?: {[K in keyof T]?: Readonly<(keyof T)[]>}
dependentSchemas?: {[K in keyof T]?: UncheckedPartialSchema<T>}
minProperties?: number
maxProperties?: number
} & (IsPartial extends true // "required" is not necessary if it's a non-partial type with no required keys // are listed it only asserts that optional cannot be listed. // "required" type does not guarantee that all required properties
? {required: Readonly<(keyof T)[]>}
: [UncheckedRequiredMembers<T>] extends [never]
? {required?: Readonly<UncheckedRequiredMembers<T>[]>}
: {required: Readonly<UncheckedRequiredMembers<T>[]>})
: T extends null
? {
type: JSONType<"null", IsPartial>
nullable: true
}
: never) & {
allOf?: Readonly<UncheckedPartialSchema<T>[]>
anyOf?: Readonly<UncheckedPartialSchema<T>[]>
oneOf?: Readonly<UncheckedPartialSchema<T>[]>
Expand Down
Loading

0 comments on commit 27ed940

Please sign in to comment.