@sorisdk/matcher 0.1.3 → 0.1.5
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.
- package/README.md +11 -0
- package/dist/generated/core.d.ts +2 -1
- package/dist/generated/core_bg.js +120 -4
- package/dist/generated/core_bg.wasm +0 -0
- package/dist/generated/core_bg.wasm.d.ts +5 -3
- package/dist/index.d.ts +11 -2
- package/dist/index.js +64 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ await session.addEntry(
|
|
|
38
38
|
const result = await session.match(new Uint8Array([1, 2, 3]));
|
|
39
39
|
|
|
40
40
|
console.log(result.best);
|
|
41
|
+
console.log(await session.getEntryMetadata("demo-track"));
|
|
41
42
|
```
|
|
42
43
|
|
|
43
44
|
## Advanced wasm loading
|
|
@@ -67,3 +68,13 @@ const session = new MatcherSession({
|
|
|
67
68
|
- `URL`
|
|
68
69
|
|
|
69
70
|
If you want campaign events and browser recognition flow on top of matching, use `@sorisdk/web-audio`.
|
|
71
|
+
|
|
72
|
+
## Metadata lookup
|
|
73
|
+
|
|
74
|
+
Audiopack footer metadata is available through explicit lookup rather than being
|
|
75
|
+
embedded in `MatchResult`.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const best = await session.bestMatch(queryBytes);
|
|
79
|
+
const metadata = best ? await session.getEntryMetadata(best.name) : null;
|
|
80
|
+
```
|
package/dist/generated/core.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ export class WasmMatcherDatabase {
|
|
|
5
5
|
free(): void;
|
|
6
6
|
[Symbol.dispose](): void;
|
|
7
7
|
addEntry(name: string, afp_type: number, buffer: Uint8Array): void;
|
|
8
|
-
addOrReplace(name: string, afp_type: number, buffer: Uint8Array): void;
|
|
8
|
+
addOrReplace(name: string, afp_type: number, buffer: Uint8Array, metadata?: any | null): void;
|
|
9
9
|
clear(): void;
|
|
10
|
+
getEntryMetadata(name: string): any;
|
|
10
11
|
loadPackBytes(bytes: Uint8Array): void;
|
|
11
12
|
loadPackBytesAppend(bytes: Uint8Array): void;
|
|
12
13
|
constructor();
|
|
@@ -28,13 +28,14 @@ export class WasmMatcherDatabase {
|
|
|
28
28
|
* @param {string} name
|
|
29
29
|
* @param {number} afp_type
|
|
30
30
|
* @param {Uint8Array} buffer
|
|
31
|
+
* @param {any | null} [metadata]
|
|
31
32
|
*/
|
|
32
|
-
addOrReplace(name, afp_type, buffer) {
|
|
33
|
+
addOrReplace(name, afp_type, buffer, metadata) {
|
|
33
34
|
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
34
35
|
const len0 = WASM_VECTOR_LEN;
|
|
35
36
|
const ptr1 = passArray8ToWasm0(buffer, wasm.__wbindgen_malloc);
|
|
36
37
|
const len1 = WASM_VECTOR_LEN;
|
|
37
|
-
const ret = wasm.wasmmatcherdatabase_addOrReplace(this.__wbg_ptr, ptr0, len0, afp_type, ptr1, len1);
|
|
38
|
+
const ret = wasm.wasmmatcherdatabase_addOrReplace(this.__wbg_ptr, ptr0, len0, afp_type, ptr1, len1, isLikeNone(metadata) ? 0 : addToExternrefTable0(metadata));
|
|
38
39
|
if (ret[1]) {
|
|
39
40
|
throw takeFromExternrefTable0(ret[0]);
|
|
40
41
|
}
|
|
@@ -42,6 +43,19 @@ export class WasmMatcherDatabase {
|
|
|
42
43
|
clear() {
|
|
43
44
|
wasm.wasmmatcherdatabase_clear(this.__wbg_ptr);
|
|
44
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} name
|
|
48
|
+
* @returns {any}
|
|
49
|
+
*/
|
|
50
|
+
getEntryMetadata(name) {
|
|
51
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
52
|
+
const len0 = WASM_VECTOR_LEN;
|
|
53
|
+
const ret = wasm.wasmmatcherdatabase_getEntryMetadata(this.__wbg_ptr, ptr0, len0);
|
|
54
|
+
if (ret[2]) {
|
|
55
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
56
|
+
}
|
|
57
|
+
return takeFromExternrefTable0(ret[0]);
|
|
58
|
+
}
|
|
45
59
|
/**
|
|
46
60
|
* @returns {number}
|
|
47
61
|
*/
|
|
@@ -164,6 +178,12 @@ export function __wbg_String_8564e559799eccda(arg0, arg1) {
|
|
|
164
178
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
165
179
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
166
180
|
}
|
|
181
|
+
export function __wbg___wbindgen_bigint_get_as_i64_3d3aba5d616c6a51(arg0, arg1) {
|
|
182
|
+
const v = arg1;
|
|
183
|
+
const ret = typeof(v) === 'bigint' ? v : undefined;
|
|
184
|
+
getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
185
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
186
|
+
}
|
|
167
187
|
export function __wbg___wbindgen_boolean_get_6ea149f0a8dcc5ff(arg0) {
|
|
168
188
|
const v = arg0;
|
|
169
189
|
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
@@ -180,6 +200,14 @@ export function __wbg___wbindgen_in_a5d8b22e52b24dd1(arg0, arg1) {
|
|
|
180
200
|
const ret = arg0 in arg1;
|
|
181
201
|
return ret;
|
|
182
202
|
}
|
|
203
|
+
export function __wbg___wbindgen_is_bigint_ec25c7f91b4d9e93(arg0) {
|
|
204
|
+
const ret = typeof(arg0) === 'bigint';
|
|
205
|
+
return ret;
|
|
206
|
+
}
|
|
207
|
+
export function __wbg___wbindgen_is_function_3baa9db1a987f47d(arg0) {
|
|
208
|
+
const ret = typeof(arg0) === 'function';
|
|
209
|
+
return ret;
|
|
210
|
+
}
|
|
183
211
|
export function __wbg___wbindgen_is_null_52ff4ec04186736f(arg0) {
|
|
184
212
|
const ret = arg0 === null;
|
|
185
213
|
return ret;
|
|
@@ -189,10 +217,18 @@ export function __wbg___wbindgen_is_object_63322ec0cd6ea4ef(arg0) {
|
|
|
189
217
|
const ret = typeof(val) === 'object' && val !== null;
|
|
190
218
|
return ret;
|
|
191
219
|
}
|
|
220
|
+
export function __wbg___wbindgen_is_string_6df3bf7ef1164ed3(arg0) {
|
|
221
|
+
const ret = typeof(arg0) === 'string';
|
|
222
|
+
return ret;
|
|
223
|
+
}
|
|
192
224
|
export function __wbg___wbindgen_is_undefined_29a43b4d42920abd(arg0) {
|
|
193
225
|
const ret = arg0 === undefined;
|
|
194
226
|
return ret;
|
|
195
227
|
}
|
|
228
|
+
export function __wbg___wbindgen_jsval_eq_d3465d8a07697228(arg0, arg1) {
|
|
229
|
+
const ret = arg0 === arg1;
|
|
230
|
+
return ret;
|
|
231
|
+
}
|
|
196
232
|
export function __wbg___wbindgen_jsval_loose_eq_cac3565e89b4134c(arg0, arg1) {
|
|
197
233
|
const ret = arg0 == arg1;
|
|
198
234
|
return ret;
|
|
@@ -214,6 +250,18 @@ export function __wbg___wbindgen_string_get_7ed5322991caaec5(arg0, arg1) {
|
|
|
214
250
|
export function __wbg___wbindgen_throw_6b64449b9b9ed33c(arg0, arg1) {
|
|
215
251
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
216
252
|
}
|
|
253
|
+
export function __wbg_call_14b169f759b26747() { return handleError(function (arg0, arg1) {
|
|
254
|
+
const ret = arg0.call(arg1);
|
|
255
|
+
return ret;
|
|
256
|
+
}, arguments); }
|
|
257
|
+
export function __wbg_done_9158f7cc8751ba32(arg0) {
|
|
258
|
+
const ret = arg0.done;
|
|
259
|
+
return ret;
|
|
260
|
+
}
|
|
261
|
+
export function __wbg_entries_e0b73aa8571ddb56(arg0) {
|
|
262
|
+
const ret = Object.entries(arg0);
|
|
263
|
+
return ret;
|
|
264
|
+
}
|
|
217
265
|
export function __wbg_error_a6fa202b58aa1cd3(arg0, arg1) {
|
|
218
266
|
let deferred0_0;
|
|
219
267
|
let deferred0_1;
|
|
@@ -225,6 +273,18 @@ export function __wbg_error_a6fa202b58aa1cd3(arg0, arg1) {
|
|
|
225
273
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
226
274
|
}
|
|
227
275
|
}
|
|
276
|
+
export function __wbg_get_1affdbdd5573b16a() { return handleError(function (arg0, arg1) {
|
|
277
|
+
const ret = Reflect.get(arg0, arg1);
|
|
278
|
+
return ret;
|
|
279
|
+
}, arguments); }
|
|
280
|
+
export function __wbg_get_8360291721e2339f(arg0, arg1) {
|
|
281
|
+
const ret = arg0[arg1 >>> 0];
|
|
282
|
+
return ret;
|
|
283
|
+
}
|
|
284
|
+
export function __wbg_get_unchecked_17f53dad852b9588(arg0, arg1) {
|
|
285
|
+
const ret = arg0[arg1 >>> 0];
|
|
286
|
+
return ret;
|
|
287
|
+
}
|
|
228
288
|
export function __wbg_get_with_ref_key_6412cf3094599694(arg0, arg1) {
|
|
229
289
|
const ret = arg0[arg1];
|
|
230
290
|
return ret;
|
|
@@ -239,6 +299,16 @@ export function __wbg_instanceof_ArrayBuffer_7c8433c6ed14ffe3(arg0) {
|
|
|
239
299
|
const ret = result;
|
|
240
300
|
return ret;
|
|
241
301
|
}
|
|
302
|
+
export function __wbg_instanceof_Map_1b76fd4635be43eb(arg0) {
|
|
303
|
+
let result;
|
|
304
|
+
try {
|
|
305
|
+
result = arg0 instanceof Map;
|
|
306
|
+
} catch (_) {
|
|
307
|
+
result = false;
|
|
308
|
+
}
|
|
309
|
+
const ret = result;
|
|
310
|
+
return ret;
|
|
311
|
+
}
|
|
242
312
|
export function __wbg_instanceof_Uint8Array_152ba1f289edcf3f(arg0) {
|
|
243
313
|
let result;
|
|
244
314
|
try {
|
|
@@ -249,10 +319,22 @@ export function __wbg_instanceof_Uint8Array_152ba1f289edcf3f(arg0) {
|
|
|
249
319
|
const ret = result;
|
|
250
320
|
return ret;
|
|
251
321
|
}
|
|
322
|
+
export function __wbg_isArray_c3109d14ffc06469(arg0) {
|
|
323
|
+
const ret = Array.isArray(arg0);
|
|
324
|
+
return ret;
|
|
325
|
+
}
|
|
252
326
|
export function __wbg_isSafeInteger_4fc213d1989d6d2a(arg0) {
|
|
253
327
|
const ret = Number.isSafeInteger(arg0);
|
|
254
328
|
return ret;
|
|
255
329
|
}
|
|
330
|
+
export function __wbg_iterator_013bc09ec998c2a7() {
|
|
331
|
+
const ret = Symbol.iterator;
|
|
332
|
+
return ret;
|
|
333
|
+
}
|
|
334
|
+
export function __wbg_length_3d4ecd04bd8d22f1(arg0) {
|
|
335
|
+
const ret = arg0.length;
|
|
336
|
+
return ret;
|
|
337
|
+
}
|
|
256
338
|
export function __wbg_length_9f1775224cf1d815(arg0) {
|
|
257
339
|
const ret = arg0.length;
|
|
258
340
|
return ret;
|
|
@@ -265,6 +347,10 @@ export function __wbg_new_227d7c05414eb861() {
|
|
|
265
347
|
const ret = new Error();
|
|
266
348
|
return ret;
|
|
267
349
|
}
|
|
350
|
+
export function __wbg_new_34d45cc8e36aaead() {
|
|
351
|
+
const ret = new Map();
|
|
352
|
+
return ret;
|
|
353
|
+
}
|
|
268
354
|
export function __wbg_new_682678e2f47e32bc() {
|
|
269
355
|
const ret = new Array();
|
|
270
356
|
return ret;
|
|
@@ -273,6 +359,14 @@ export function __wbg_new_aa8d0fa9762c29bd() {
|
|
|
273
359
|
const ret = new Object();
|
|
274
360
|
return ret;
|
|
275
361
|
}
|
|
362
|
+
export function __wbg_next_0340c4ae324393c3() { return handleError(function (arg0) {
|
|
363
|
+
const ret = arg0.next();
|
|
364
|
+
return ret;
|
|
365
|
+
}, arguments); }
|
|
366
|
+
export function __wbg_next_7646edaa39458ef7(arg0) {
|
|
367
|
+
const ret = arg0.next;
|
|
368
|
+
return ret;
|
|
369
|
+
}
|
|
276
370
|
export function __wbg_now_a9b7df1cbee90986() {
|
|
277
371
|
const ret = Date.now();
|
|
278
372
|
return ret;
|
|
@@ -286,6 +380,10 @@ export function __wbg_set_3bf1de9fab0cd644(arg0, arg1, arg2) {
|
|
|
286
380
|
export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
|
|
287
381
|
arg0[arg1] = arg2;
|
|
288
382
|
}
|
|
383
|
+
export function __wbg_set_fde2cec06c23692b(arg0, arg1, arg2) {
|
|
384
|
+
const ret = arg0.set(arg1, arg2);
|
|
385
|
+
return ret;
|
|
386
|
+
}
|
|
289
387
|
export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
|
|
290
388
|
const ret = arg1.stack;
|
|
291
389
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -293,17 +391,26 @@ export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
|
|
|
293
391
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
294
392
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
295
393
|
}
|
|
394
|
+
export function __wbg_value_ee3a06f4579184fa(arg0) {
|
|
395
|
+
const ret = arg0.value;
|
|
396
|
+
return ret;
|
|
397
|
+
}
|
|
296
398
|
export function __wbindgen_cast_0000000000000001(arg0) {
|
|
297
399
|
// Cast intrinsic for `F64 -> Externref`.
|
|
298
400
|
const ret = arg0;
|
|
299
401
|
return ret;
|
|
300
402
|
}
|
|
301
|
-
export function __wbindgen_cast_0000000000000002(arg0
|
|
403
|
+
export function __wbindgen_cast_0000000000000002(arg0) {
|
|
404
|
+
// Cast intrinsic for `I64 -> Externref`.
|
|
405
|
+
const ret = arg0;
|
|
406
|
+
return ret;
|
|
407
|
+
}
|
|
408
|
+
export function __wbindgen_cast_0000000000000003(arg0, arg1) {
|
|
302
409
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
303
410
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
304
411
|
return ret;
|
|
305
412
|
}
|
|
306
|
-
export function
|
|
413
|
+
export function __wbindgen_cast_0000000000000004(arg0) {
|
|
307
414
|
// Cast intrinsic for `U64 -> Externref`.
|
|
308
415
|
const ret = BigInt.asUintN(64, arg0);
|
|
309
416
|
return ret;
|
|
@@ -427,6 +534,15 @@ function getUint8ArrayMemory0() {
|
|
|
427
534
|
return cachedUint8ArrayMemory0;
|
|
428
535
|
}
|
|
429
536
|
|
|
537
|
+
function handleError(f, args) {
|
|
538
|
+
try {
|
|
539
|
+
return f.apply(this, args);
|
|
540
|
+
} catch (e) {
|
|
541
|
+
const idx = addToExternrefTable0(e);
|
|
542
|
+
wasm.__wbindgen_exn_store(idx);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
430
546
|
function isLikeNone(x) {
|
|
431
547
|
return x === undefined || x === null;
|
|
432
548
|
}
|
|
Binary file
|
|
@@ -4,8 +4,9 @@ export const memory: WebAssembly.Memory;
|
|
|
4
4
|
export const __wbg_wasmmatcherdatabase_free: (a: number, b: number) => void;
|
|
5
5
|
export const __wbg_wasmmatcherengine_free: (a: number, b: number) => void;
|
|
6
6
|
export const wasmmatcherdatabase_addEntry: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
7
|
-
export const wasmmatcherdatabase_addOrReplace: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
7
|
+
export const wasmmatcherdatabase_addOrReplace: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
8
8
|
export const wasmmatcherdatabase_clear: (a: number) => void;
|
|
9
|
+
export const wasmmatcherdatabase_getEntryMetadata: (a: number, b: number, c: number) => [number, number, number];
|
|
9
10
|
export const wasmmatcherdatabase_length: (a: number) => number;
|
|
10
11
|
export const wasmmatcherdatabase_loadPackBytes: (a: number, b: number, c: number) => [number, number];
|
|
11
12
|
export const wasmmatcherdatabase_loadPackBytesAppend: (a: number, b: number, c: number) => [number, number];
|
|
@@ -18,8 +19,9 @@ export const wasmmatcherengine_resetDistinctMatchState: (a: number) => void;
|
|
|
18
19
|
export const init_matcher_wasm: () => void;
|
|
19
20
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
20
21
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
21
|
-
export const
|
|
22
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
23
|
+
export const __externref_table_alloc: () => number;
|
|
22
24
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
25
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
23
26
|
export const __externref_table_dealloc: (a: number) => void;
|
|
24
|
-
export const __externref_table_alloc: () => number;
|
|
25
27
|
export const __wbindgen_start: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,14 @@ interface MatchConfig {
|
|
|
8
8
|
scoreThreshold?: number;
|
|
9
9
|
gapThreshold?: number;
|
|
10
10
|
}
|
|
11
|
+
interface EntryMetadata {
|
|
12
|
+
id?: string | null;
|
|
13
|
+
name?: string | null;
|
|
14
|
+
title?: string | null;
|
|
15
|
+
image?: string | null;
|
|
16
|
+
type?: string | null;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
11
19
|
interface MatchResult {
|
|
12
20
|
name: string;
|
|
13
21
|
score: number;
|
|
@@ -125,9 +133,10 @@ declare class MatcherSession {
|
|
|
125
133
|
ready(): Promise<void>;
|
|
126
134
|
loadPack(source: PackSource): Promise<void>;
|
|
127
135
|
addEntry(name: string, afpType: AudioFingerprintType, fingerprint: Uint8Array): Promise<void>;
|
|
128
|
-
addOrReplace(name: string, afpType: AudioFingerprintType, fingerprint: Uint8Array): Promise<void>;
|
|
136
|
+
addOrReplace(name: string, afpType: AudioFingerprintType, fingerprint: Uint8Array, metadata?: EntryMetadata | null): Promise<void>;
|
|
129
137
|
removeEntry(name: string): Promise<void>;
|
|
130
138
|
clear(): Promise<void>;
|
|
139
|
+
getEntryMetadata(name: string): Promise<EntryMetadata | null>;
|
|
131
140
|
match(query: Uint8Array, config?: MatchConfig): Promise<MatchResult[]>;
|
|
132
141
|
bestMatch(query: Uint8Array, config?: MatchConfig): Promise<MatchResult | null>;
|
|
133
142
|
destroy(): void;
|
|
@@ -142,4 +151,4 @@ declare function __setMatcherWasmModuleForTests(moduleLike: unknown): void;
|
|
|
142
151
|
declare function __setMatcherEmbeddedPackForTests(bytes: Uint8Array): void;
|
|
143
152
|
declare function __resetMatcherWasmForTests(): void;
|
|
144
153
|
|
|
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 };
|
|
154
|
+
export { AudioFingerprintType, type EntryMetadata, 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 };
|
package/dist/index.js
CHANGED
|
@@ -307,12 +307,12 @@ var WrappedDatabase = class {
|
|
|
307
307
|
}
|
|
308
308
|
fn.call(this.inner, name, afpType, fingerprint);
|
|
309
309
|
}
|
|
310
|
-
addOrReplace(name, afpType, fingerprint) {
|
|
310
|
+
addOrReplace(name, afpType, fingerprint, metadata) {
|
|
311
311
|
const fn = getCallable(this.inner, ["addOrReplace", "add_or_replace"]);
|
|
312
312
|
if (!fn) {
|
|
313
313
|
throw new Error("WASM database is missing addOrReplace");
|
|
314
314
|
}
|
|
315
|
-
fn.call(this.inner, name, afpType, fingerprint);
|
|
315
|
+
fn.call(this.inner, name, afpType, fingerprint, metadata);
|
|
316
316
|
}
|
|
317
317
|
removeEntry(name) {
|
|
318
318
|
const fn = getCallable(this.inner, ["removeEntry", "remove_entry"]);
|
|
@@ -347,6 +347,17 @@ var WrappedDatabase = class {
|
|
|
347
347
|
}
|
|
348
348
|
appendFn.call(this.inner, bytes);
|
|
349
349
|
}
|
|
350
|
+
getEntryMetadata(name) {
|
|
351
|
+
const fn = getCallable(this.inner, ["getEntryMetadata", "get_entry_metadata"]);
|
|
352
|
+
if (!fn) {
|
|
353
|
+
throw new Error("WASM database is missing getEntryMetadata-compatible method");
|
|
354
|
+
}
|
|
355
|
+
const raw = fn.call(this.inner, name);
|
|
356
|
+
if (!raw || typeof raw !== "object") {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
return normalizeEntryMetadata(raw);
|
|
360
|
+
}
|
|
350
361
|
destroy() {
|
|
351
362
|
const fn = getCallable(this.inner, ["destroy", "free"]);
|
|
352
363
|
if (fn) {
|
|
@@ -412,6 +423,42 @@ function normalizeResult(raw) {
|
|
|
412
423
|
afpType
|
|
413
424
|
};
|
|
414
425
|
}
|
|
426
|
+
function isMapLike(raw) {
|
|
427
|
+
return raw instanceof Map || Object.prototype.toString.call(raw) === "[object Map]" && typeof raw.entries === "function";
|
|
428
|
+
}
|
|
429
|
+
function toEntryMetadataRecord(raw) {
|
|
430
|
+
if (isMapLike(raw)) {
|
|
431
|
+
const entries = [];
|
|
432
|
+
for (const [key, value] of raw.entries()) {
|
|
433
|
+
if (typeof key === "string") {
|
|
434
|
+
entries.push([key, value]);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return Object.fromEntries(entries);
|
|
438
|
+
}
|
|
439
|
+
return raw;
|
|
440
|
+
}
|
|
441
|
+
function normalizeEntryMetadata(raw) {
|
|
442
|
+
const metadata = toEntryMetadataRecord(raw);
|
|
443
|
+
const {
|
|
444
|
+
_id: legacyId,
|
|
445
|
+
id,
|
|
446
|
+
kind,
|
|
447
|
+
type,
|
|
448
|
+
title,
|
|
449
|
+
name,
|
|
450
|
+
image,
|
|
451
|
+
...rest
|
|
452
|
+
} = metadata;
|
|
453
|
+
return {
|
|
454
|
+
...rest,
|
|
455
|
+
...id !== void 0 || legacyId !== void 0 ? { id: String(id ?? legacyId) } : {},
|
|
456
|
+
...name !== void 0 ? { name: name == null ? null : String(name) } : {},
|
|
457
|
+
...title !== void 0 ? { title: title == null ? null : String(title) } : {},
|
|
458
|
+
...image !== void 0 ? { image: image == null ? null : String(image) } : {},
|
|
459
|
+
...type !== void 0 || kind !== void 0 ? { type: type == null && kind == null ? null : String(type ?? kind) } : {}
|
|
460
|
+
};
|
|
461
|
+
}
|
|
415
462
|
function normalizeResults(rawResults) {
|
|
416
463
|
return rawResults.filter((item) => typeof item === "object" && item !== null).map((item) => normalizeResult(item));
|
|
417
464
|
}
|
|
@@ -557,10 +604,15 @@ var MatcherSession = class {
|
|
|
557
604
|
handleError(this.events, "addEntry", error);
|
|
558
605
|
}
|
|
559
606
|
}
|
|
560
|
-
async addOrReplace(name, afpType, fingerprint) {
|
|
607
|
+
async addOrReplace(name, afpType, fingerprint, metadata) {
|
|
561
608
|
try {
|
|
562
609
|
await this.ensureLiveReady();
|
|
563
|
-
this.databaseOrThrow().addOrReplace(
|
|
610
|
+
this.databaseOrThrow().addOrReplace(
|
|
611
|
+
name,
|
|
612
|
+
afpType,
|
|
613
|
+
toUint8ArrayCopy(fingerprint),
|
|
614
|
+
metadata
|
|
615
|
+
);
|
|
564
616
|
this.distinctMatchDeduper.reset();
|
|
565
617
|
this.matcher?.resetDistinctMatchState?.();
|
|
566
618
|
} catch (error) {
|
|
@@ -587,6 +639,14 @@ var MatcherSession = class {
|
|
|
587
639
|
handleError(this.events, "clear", error);
|
|
588
640
|
}
|
|
589
641
|
}
|
|
642
|
+
async getEntryMetadata(name) {
|
|
643
|
+
try {
|
|
644
|
+
await this.ensureLiveReady();
|
|
645
|
+
return this.databaseOrThrow().getEntryMetadata(name);
|
|
646
|
+
} catch (error) {
|
|
647
|
+
handleError(this.events, "getEntryMetadata", error);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
590
650
|
async match(query, config) {
|
|
591
651
|
try {
|
|
592
652
|
await this.ensureLiveReady();
|