@sorisdk/matcher 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,145 @@
1
+ declare enum AudioFingerprintType {
2
+ Livestream = 1,
3
+ ArchiveCf = 2,
4
+ ArchivePg = 4
5
+ }
6
+ interface MatchConfig {
7
+ maxResults?: number;
8
+ scoreThreshold?: number;
9
+ gapThreshold?: number;
10
+ }
11
+ interface MatchResult {
12
+ name: string;
13
+ score: number;
14
+ position: number;
15
+ afpType: AudioFingerprintType;
16
+ }
17
+ type PackSource = Uint8Array | ArrayBuffer | Blob | Response | Request | string | URL;
18
+ type MatcherSessionEventMap = {
19
+ ready: {
20
+ createdAt: number;
21
+ };
22
+ packloadstart: {
23
+ sourceType: string;
24
+ };
25
+ packload: {
26
+ sourceType: string;
27
+ byteLength: number;
28
+ };
29
+ querystart: {
30
+ queryByteLength: number;
31
+ };
32
+ match: {
33
+ results: MatchResult[];
34
+ best: MatchResult | null;
35
+ };
36
+ nomatch: {
37
+ queryByteLength: number;
38
+ };
39
+ error: {
40
+ phase: string;
41
+ error: Error;
42
+ };
43
+ destroy: {
44
+ destroyedAt: number;
45
+ };
46
+ };
47
+ type MatcherSessionEventName = keyof MatcherSessionEventMap;
48
+ type MatcherSessionListener<T extends MatcherSessionEventName> = (payload: MatcherSessionEventMap[T]) => void;
49
+
50
+ type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
51
+
52
+ interface MatcherEphemeralKeyExchangeOptions {
53
+ endpoint: string | URL;
54
+ fetch?: FetchLike;
55
+ }
56
+ interface MatcherEphemeralAuthOptions {
57
+ endpoint: string | URL;
58
+ appId: string;
59
+ ephemeralKey?: string;
60
+ secretKey?: string;
61
+ exchange?: MatcherEphemeralKeyExchangeOptions;
62
+ sessionId: string;
63
+ version: string;
64
+ fetch?: FetchLike;
65
+ }
66
+ interface MatcherExchangeResponsePayload {
67
+ ephemeral_key?: unknown;
68
+ ephemeralKey?: unknown;
69
+ secret_key?: unknown;
70
+ secretKey?: unknown;
71
+ expires_at?: unknown;
72
+ expiresAt?: unknown;
73
+ ttl_seconds?: unknown;
74
+ ttlSeconds?: unknown;
75
+ }
76
+ interface MatcherAuthResponsePayload {
77
+ success?: boolean;
78
+ token?: unknown;
79
+ token_expires_at?: unknown;
80
+ tokenExpiresAt?: unknown;
81
+ updated?: unknown;
82
+ url?: unknown;
83
+ force_update?: unknown;
84
+ }
85
+ interface MatcherEphemeralAuthResult {
86
+ token: string;
87
+ tokenExpiresAt: string | null;
88
+ packUrl: string | null;
89
+ updated: number;
90
+ forceUpdate: boolean;
91
+ exchange: MatcherEphemeralKeyExchangeMetadata | null;
92
+ raw: MatcherAuthResponsePayload;
93
+ }
94
+ interface MatcherEphemeralKeyExchangeMetadata {
95
+ expiresAt: string | null;
96
+ ttlSeconds: number | null;
97
+ raw: MatcherExchangeResponsePayload;
98
+ }
99
+
100
+ interface InitMatcherOptions {
101
+ loader?: () => Promise<unknown>;
102
+ wasmModule?: unknown;
103
+ wasmInitInput?: unknown;
104
+ auth?: MatcherEphemeralAuthOptions;
105
+ }
106
+ interface MatcherSessionOptions extends InitMatcherOptions {
107
+ fetch?: FetchLike;
108
+ }
109
+ type InitMatcherResult = MatcherEphemeralAuthResult;
110
+ declare function initMatcher(options?: InitMatcherOptions): Promise<InitMatcherResult | void>;
111
+ declare class MatcherSession {
112
+ private readonly events;
113
+ private readonly fetcher?;
114
+ private readonly initOptions;
115
+ private readyPromise;
116
+ private bindings;
117
+ private database;
118
+ private matcher;
119
+ private destroyed;
120
+ private readonly distinctMatchDeduper;
121
+ constructor(options?: MatcherSessionOptions);
122
+ on<T extends MatcherSessionEventName>(eventName: T, listener: MatcherSessionListener<T>): this;
123
+ off<T extends MatcherSessionEventName>(eventName: T, listener: MatcherSessionListener<T>): this;
124
+ once<T extends MatcherSessionEventName>(eventName: T, listener: MatcherSessionListener<T>): this;
125
+ ready(): Promise<void>;
126
+ loadPack(source: PackSource): Promise<void>;
127
+ addEntry(name: string, afpType: AudioFingerprintType, fingerprint: Uint8Array): Promise<void>;
128
+ addOrReplace(name: string, afpType: AudioFingerprintType, fingerprint: Uint8Array): Promise<void>;
129
+ removeEntry(name: string): Promise<void>;
130
+ clear(): Promise<void>;
131
+ match(query: Uint8Array, config?: MatchConfig): Promise<MatchResult[]>;
132
+ bestMatch(query: Uint8Array, config?: MatchConfig): Promise<MatchResult | null>;
133
+ destroy(): void;
134
+ private bootstrap;
135
+ private ensureLiveReady;
136
+ private ensureNotDestroyed;
137
+ private matcherOrThrow;
138
+ private databaseOrThrow;
139
+ private emitDistinctMatchEvent;
140
+ }
141
+ declare function __setMatcherWasmModuleForTests(moduleLike: unknown): void;
142
+ declare function __setMatcherEmbeddedPackForTests(bytes: Uint8Array): void;
143
+ declare function __resetMatcherWasmForTests(): void;
144
+
145
+ export { AudioFingerprintType, type InitMatcherOptions, type InitMatcherResult, type MatchConfig, type MatchResult, type MatcherEphemeralAuthOptions, type MatcherEphemeralAuthResult, type MatcherEphemeralKeyExchangeMetadata, type MatcherEphemeralKeyExchangeOptions, MatcherSession, type MatcherSessionEventMap, type MatcherSessionEventName, type MatcherSessionListener, type MatcherSessionOptions, type PackSource, __resetMatcherWasmForTests, __setMatcherEmbeddedPackForTests, __setMatcherWasmModuleForTests, initMatcher };