meteor-type-validation
Version:
A lightweight set of TypeScript utilities to add proper type inference and validation for your Meteor publications and methods
22 lines (19 loc) • 665 B
text/typescript
import type { GenericSchema } from 'valibot';
import type { BaseContext, UnwrapSchemaOutput } from './types/ValidatedResources';
export abstract class Guard {
constructor(
public readonly context: BaseContext,
protected readonly params: unknown[]
) {}
public abstract validate(): asserts this;
public abstract get validatedContext(): unknown;
}
export interface GuardStatic<TGuard extends Guard = Guard> {
new(...context: any): TGuard;
}
export type GuardFunction<
TSchemas extends GenericSchema[] = GenericSchema[],
> = (request: {
context: BaseContext,
params: UnwrapSchemaOutput<TSchemas>
}) => asserts request;