Suite of AT Protocol TypeScript libraries built on web standards
21
fork

Configure Feed

Select the types of activity you want to include in your feed.

at lex 29 lines 774 B view raw
1// Explicitly not using "zod" types here to avoid mismatching types due to 2// version differences. 3 4export interface Checkable<T> { 5 parse: (obj: unknown) => T; 6 safeParse: ( 7 obj: unknown, 8 ) => { success: true; data: T } | { success: false; error: Error }; 9} 10 11export interface Def<T> { 12 name: string; 13 schema: Checkable<T>; 14} 15 16export const is = <T>(obj: unknown, def: Checkable<T>): obj is T => { 17 return def.safeParse(obj).success; 18}; 19 20export const create = <T>(def: Checkable<T>) => (v: unknown): v is T => 21 def.safeParse(v).success; 22 23export const assure = <T>(def: Checkable<T>, obj: unknown): T => { 24 return def.parse(obj); 25}; 26 27export const isObject = (obj: unknown): obj is Record<string, unknown> => { 28 return typeof obj === "object" && obj !== null; 29};