Skip to content

Commit

Permalink
fixup! codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben committed Jan 13, 2025
1 parent 3e1cb75 commit 0133f4a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
11 changes: 8 additions & 3 deletions packages/api/src/client/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ export function maybe$typed<V, Id extends string, Hash extends string>(
}

export type Validator<R = unknown> = (v: unknown) => ValidationResult<R>
export type ValidatorParam<V extends Validator> =
V extends Validator<infer R> ? R : never

export function asPredicate<V extends Validator>(validator: V) {
return <T,>(v: T): v is T & (V extends Validator<infer R> ? R : never) =>
validator(v).success
/**
* Utility function that allows to convert a "validate*" utility function into a
* type predicate.
*/
export function asPredicate<V extends Validator>(validate: V) {
return <T,>(v: T): v is T & ValidatorParam<V> => validate(v).success
}
11 changes: 8 additions & 3 deletions packages/bsky/src/lexicon/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ export function maybe$typed<V, Id extends string, Hash extends string>(
}

export type Validator<R = unknown> = (v: unknown) => ValidationResult<R>
export type ValidatorParam<V extends Validator> =
V extends Validator<infer R> ? R : never

export function asPredicate<V extends Validator>(validator: V) {
return <T,>(v: T): v is T & (V extends Validator<infer R> ? R : never) =>
validator(v).success
/**
* Utility function that allows to convert a "validate*" utility function into a
* type predicate.
*/
export function asPredicate<V extends Validator>(validate: V) {
return <T,>(v: T): v is T & ValidatorParam<V> => validate(v).success
}
11 changes: 8 additions & 3 deletions packages/ozone/src/lexicon/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ export function maybe$typed<V, Id extends string, Hash extends string>(
}

export type Validator<R = unknown> = (v: unknown) => ValidationResult<R>
export type ValidatorParam<V extends Validator> =
V extends Validator<infer R> ? R : never

export function asPredicate<V extends Validator>(validator: V) {
return <T,>(v: T): v is T & (V extends Validator<infer R> ? R : never) =>
validator(v).success
/**
* Utility function that allows to convert a "validate*" utility function into a
* type predicate.
*/
export function asPredicate<V extends Validator>(validate: V) {
return <T,>(v: T): v is T & ValidatorParam<V> => validate(v).success
}
11 changes: 8 additions & 3 deletions packages/pds/src/lexicon/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ export function maybe$typed<V, Id extends string, Hash extends string>(
}

export type Validator<R = unknown> = (v: unknown) => ValidationResult<R>
export type ValidatorParam<V extends Validator> =
V extends Validator<infer R> ? R : never

export function asPredicate<V extends Validator>(validator: V) {
return <T,>(v: T): v is T & (V extends Validator<infer R> ? R : never) =>
validator(v).success
/**
* Utility function that allows to convert a "validate*" utility function into a
* type predicate.
*/
export function asPredicate<V extends Validator>(validate: V) {
return <T,>(v: T): v is T & ValidatorParam<V> => validate(v).success
}

0 comments on commit 0133f4a

Please sign in to comment.