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.

add explicit typings

+28 -18
+2 -2
common/dates.ts
··· 3 3 export const HOUR = MINUTE * 60; 4 4 export const DAY = HOUR * 24; 5 5 6 - export const lessThanAgoMs = (time: Date, range: number) => { 6 + export const lessThanAgoMs = (time: Date, range: number): boolean => { 7 7 return Date.now() < time.getTime() + range; 8 8 }; 9 9 ··· 26 26 return !isNaN(date.getTime()) && date.toISOString() === dateString; 27 27 } 28 28 29 - export function toSimplifiedISOSafe(dateStr: string) { 29 + export function toSimplifiedISOSafe(dateStr: string): string { 30 30 const date = new Date(dateStr); 31 31 if (isNaN(date.getTime())) { 32 32 return new Date(0).toISOString();
+7 -2
common/ipld.ts
··· 12 12 export const cborEncode = cborCodec.encode; 13 13 export const cborDecode = cborCodec.decode; 14 14 15 - export const dataToCborBlock = (data: unknown) => { 15 + export const dataToCborBlock = ( 16 + data: unknown, 17 + ): Promise<mf.BlockView> => { 16 18 return Block.encode({ 17 19 value: data, 18 20 codec: cborCodec, ··· 44 46 return val as Record<string, unknown>; 45 47 }; 46 48 47 - export const verifyCidForBytes = async (cid: CID, bytes: Uint8Array) => { 49 + export const verifyCidForBytes = async ( 50 + cid: CID, 51 + bytes: Uint8Array, 52 + ): Promise<void> => { 48 53 const digest = await sha256.digest(bytes); 49 54 const expected = CID.createV1(cid.code, digest); 50 55 if (!cid.equals(expected)) {
+1 -1
common/logger.ts
··· 52 52 53 53 const subsystemLoggers: Record<string, Logger> = {}; 54 54 55 - export const subsystemLogger = (name: string) => { 55 + export const subsystemLogger = (name: string): Logger => { 56 56 if (subsystemLoggers[name]) return subsystemLoggers[name]; 57 57 58 58 const subsystemEnabled = enabled &&
+5 -3
common/obfuscate.ts
··· 1 1 import { decodeBase64 } from "@std/encoding"; 2 2 3 - export function obfuscateEmail(email: string) { 3 + export function obfuscateEmail(email: string): string { 4 4 const [local, domain] = email.split("@"); 5 5 return `${obfuscateWord(local)}@${obfuscateWord(domain)}`; 6 6 } 7 7 8 - export function obfuscateWord(word: string) { 8 + export function obfuscateWord(word: string): string { 9 9 return `${word.charAt(0)}***${word.charAt(word.length - 1)}`; 10 10 } 11 11 12 - export function obfuscateHeaders(headers: Record<string, string>) { 12 + export function obfuscateHeaders( 13 + headers: Record<string, string>, 14 + ): Record<string, string> { 13 15 const obfuscatedHeaders: Record<string, string> = {}; 14 16 for (const key in headers) { 15 17 if (key.toLowerCase() === "authorization") {
+4 -2
common/retry.ts
··· 35 35 throw doneError; 36 36 } 37 37 38 - export function createRetryable(retryable: (err: unknown) => boolean) { 38 + export function createRetryable(retryable: (err: unknown) => boolean): { 39 + <T>(fn: () => Promise<T>, opts?: RetryOptions): Promise<T>; 40 + } { 39 41 return <T>(fn: () => Promise<T>, opts?: RetryOptions) => 40 42 retry(fn, { ...opts, retryable }); 41 43 } 42 44 43 45 // Waits exponential backoff with max and jitter: ~100, ~200, ~400, ~800, ~1000, ~1000, ... 44 - export function backoffMs(n: number, multiplier = 100, max = 1000) { 46 + export function backoffMs(n: number, multiplier = 100, max = 1000): number { 45 47 const exponentialMs = Math.pow(2, n) * multiplier; 46 48 const ms = Math.min(exponentialMs, max); 47 49 return jitter(ms);
+6 -5
common/types.ts
··· 16 16 return cid; 17 17 }); 18 18 19 - const carHeader = z.object({ 20 - version: z.literal(1), 21 - roots: z.array(cidSchema), 22 - }); 19 + const carHeader: z.ZodObject<{ version: z.ZodLiteral<1>; roots: z.ZodArray }> = 20 + z.object({ 21 + version: z.literal(1), 22 + roots: z.array(cidSchema), 23 + }); 23 24 export type CarHeader = z.infer<typeof carHeader>; 24 25 25 - export const schema = { 26 + export const schema: Record<string, z.ZodTypeAny> = { 26 27 cid: cidSchema, 27 28 carHeader, 28 29 bytes: z.instanceof(Uint8Array),
+3 -3
common/util.ts
··· 39 39 return dst; 40 40 } 41 41 42 - export const jitter = (maxMs: number) => { 42 + export const jitter = (maxMs: number): number => { 43 43 return Math.round((Math.random() - 0.5) * maxMs * 2); 44 44 }; 45 45 46 - export const wait = (ms: number) => { 46 + export const wait = (ms: number): Promise<void> => { 47 47 return new Promise((res) => setTimeout(res, ms)); 48 48 }; 49 49 ··· 110 110 export const asyncFilter = async <T>( 111 111 arr: T[], 112 112 fn: (t: T) => Promise<boolean>, 113 - ) => { 113 + ): Promise<T[]> => { 114 114 const results = await Promise.all(arr.map((t) => fn(t))); 115 115 return arr.filter((_, i) => results[i]); 116 116 };