inbox-queries.ts (1536B)
1 import { canonicalPublicKey } from '../contracts/public-key.ts'; 2 import { 3 PRIVATE_TRANSPORT_BUDGETS, 4 PUBLIC_QUERY_BUDGETS 5 } from '../config/budgets.ts'; 6 import type { PublicFilter } from './exports.ts'; 7 8 export function inboxPreferenceQueries( 9 author: unknown 10 ): readonly PublicFilter[] { 11 const key = canonicalPublicKey(author); 12 if (!key) throw new Error('inbox_author_invalid'); 13 return [ 14 { 15 kinds: [10050], 16 authors: [key], 17 limit: PUBLIC_QUERY_BUDGETS.requestedPerRelay 18 } 19 ]; 20 } 21 22 // No inner-time cursor or throttle; live limit0 excludes initial history, not 23 // future backdated messages. Actual relay semantics require separate Q. 24 export function privateInboxQueries( 25 owner: unknown, 26 mode: 'live' | 'backfill', 27 since?: number, 28 until?: number 29 ): readonly PublicFilter[] { 30 const key = canonicalPublicKey(owner); 31 if (!key) throw Error('inbox_owner_invalid'); 32 if (mode !== 'live' && mode !== 'backfill') throw Error('inbox_mode_invalid'); 33 if ( 34 since !== undefined && 35 (mode === 'live' || !Number.isSafeInteger(since) || since < 0) 36 ) 37 throw Error('inbox_outer_since_invalid'); 38 if ( 39 until !== undefined && 40 (mode === 'live' || !Number.isSafeInteger(until) || until < 0) 41 ) 42 throw Error('inbox_outer_until_invalid'); 43 return [ 44 { 45 ...(until === undefined ? {} : { until }), 46 ...(since === undefined ? {} : { since }), 47 kinds: [1059], 48 '#p': [key], 49 limit: mode === 'live' ? 0 : PRIVATE_TRANSPORT_BUDGETS.requestedPerRelay 50 } 51 ]; 52 }