@sorisdk/matcher 0.1.2 → 0.1.4
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 +30 -0
- package/dist/default-loader.js +5 -0
- package/dist/generated/core.d.ts +2 -1
- package/dist/generated/core.js +1 -1
- package/dist/generated/core_bg.js +146 -30
- 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 +62 -18
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -14,6 +14,11 @@ npm install @sorisdk/matcher
|
|
|
14
14
|
|
|
15
15
|
Vite-based apps need `vite-plugin-wasm`.
|
|
16
16
|
|
|
17
|
+
The default loader is intended to work in both Vite dev/build and Nuxt client production bundles. If you need to override wasm loading explicitly, pass either:
|
|
18
|
+
|
|
19
|
+
- `loader: () => import("@sorisdk/matcher/generated/core.js")`
|
|
20
|
+
- `wasmModule: await import("@sorisdk/matcher/generated/core.js")`
|
|
21
|
+
|
|
17
22
|
## Minimal example
|
|
18
23
|
|
|
19
24
|
```ts
|
|
@@ -33,6 +38,21 @@ await session.addEntry(
|
|
|
33
38
|
const result = await session.match(new Uint8Array([1, 2, 3]));
|
|
34
39
|
|
|
35
40
|
console.log(result.best);
|
|
41
|
+
console.log(await session.getEntryMetadata("demo-track"));
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Advanced wasm loading
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { MatcherSession, initMatcher } from "@sorisdk/matcher";
|
|
48
|
+
|
|
49
|
+
await initMatcher({
|
|
50
|
+
loader: () => import("@sorisdk/matcher/generated/core.js")
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const session = new MatcherSession({
|
|
54
|
+
wasmModule: await import("@sorisdk/matcher/generated/core.js")
|
|
55
|
+
});
|
|
36
56
|
```
|
|
37
57
|
|
|
38
58
|
## Pack loading
|
|
@@ -48,3 +68,13 @@ console.log(result.best);
|
|
|
48
68
|
- `URL`
|
|
49
69
|
|
|
50
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();
|
package/dist/generated/core.js
CHANGED
|
@@ -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
|
*/
|
|
@@ -149,11 +163,11 @@ if (Symbol.dispose) WasmMatcherEngine.prototype[Symbol.dispose] = WasmMatcherEng
|
|
|
149
163
|
export function init_matcher_wasm() {
|
|
150
164
|
wasm.init_matcher_wasm();
|
|
151
165
|
}
|
|
152
|
-
export function
|
|
166
|
+
export function __wbg_Error_960c155d3d49e4c2(arg0, arg1) {
|
|
153
167
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
154
168
|
return ret;
|
|
155
169
|
}
|
|
156
|
-
export function
|
|
170
|
+
export function __wbg_Number_32bf70a599af1d4b(arg0) {
|
|
157
171
|
const ret = Number(arg0);
|
|
158
172
|
return ret;
|
|
159
173
|
}
|
|
@@ -164,46 +178,68 @@ 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
|
}
|
|
167
|
-
export function
|
|
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
|
+
}
|
|
187
|
+
export function __wbg___wbindgen_boolean_get_6ea149f0a8dcc5ff(arg0) {
|
|
168
188
|
const v = arg0;
|
|
169
189
|
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
170
190
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
171
191
|
}
|
|
172
|
-
export function
|
|
192
|
+
export function __wbg___wbindgen_debug_string_ab4b34d23d6778bd(arg0, arg1) {
|
|
173
193
|
const ret = debugString(arg1);
|
|
174
194
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
175
195
|
const len1 = WASM_VECTOR_LEN;
|
|
176
196
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
177
197
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
178
198
|
}
|
|
179
|
-
export function
|
|
199
|
+
export function __wbg___wbindgen_in_a5d8b22e52b24dd1(arg0, arg1) {
|
|
180
200
|
const ret = arg0 in arg1;
|
|
181
201
|
return ret;
|
|
182
202
|
}
|
|
183
|
-
export function
|
|
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
|
+
}
|
|
211
|
+
export function __wbg___wbindgen_is_null_52ff4ec04186736f(arg0) {
|
|
184
212
|
const ret = arg0 === null;
|
|
185
213
|
return ret;
|
|
186
214
|
}
|
|
187
|
-
export function
|
|
215
|
+
export function __wbg___wbindgen_is_object_63322ec0cd6ea4ef(arg0) {
|
|
188
216
|
const val = arg0;
|
|
189
217
|
const ret = typeof(val) === 'object' && val !== null;
|
|
190
218
|
return ret;
|
|
191
219
|
}
|
|
192
|
-
export function
|
|
220
|
+
export function __wbg___wbindgen_is_string_6df3bf7ef1164ed3(arg0) {
|
|
221
|
+
const ret = typeof(arg0) === 'string';
|
|
222
|
+
return ret;
|
|
223
|
+
}
|
|
224
|
+
export function __wbg___wbindgen_is_undefined_29a43b4d42920abd(arg0) {
|
|
193
225
|
const ret = arg0 === undefined;
|
|
194
226
|
return ret;
|
|
195
227
|
}
|
|
196
|
-
export function
|
|
228
|
+
export function __wbg___wbindgen_jsval_eq_d3465d8a07697228(arg0, arg1) {
|
|
229
|
+
const ret = arg0 === arg1;
|
|
230
|
+
return ret;
|
|
231
|
+
}
|
|
232
|
+
export function __wbg___wbindgen_jsval_loose_eq_cac3565e89b4134c(arg0, arg1) {
|
|
197
233
|
const ret = arg0 == arg1;
|
|
198
234
|
return ret;
|
|
199
235
|
}
|
|
200
|
-
export function
|
|
236
|
+
export function __wbg___wbindgen_number_get_c7f42aed0525c451(arg0, arg1) {
|
|
201
237
|
const obj = arg1;
|
|
202
238
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
203
239
|
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
204
240
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
205
241
|
}
|
|
206
|
-
export function
|
|
242
|
+
export function __wbg___wbindgen_string_get_7ed5322991caaec5(arg0, arg1) {
|
|
207
243
|
const obj = arg1;
|
|
208
244
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
209
245
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -211,9 +247,21 @@ export function __wbg___wbindgen_string_get_914df97fcfa788f2(arg0, arg1) {
|
|
|
211
247
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
212
248
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
213
249
|
}
|
|
214
|
-
export function
|
|
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,11 +273,23 @@ 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;
|
|
231
291
|
}
|
|
232
|
-
export function
|
|
292
|
+
export function __wbg_instanceof_ArrayBuffer_7c8433c6ed14ffe3(arg0) {
|
|
233
293
|
let result;
|
|
234
294
|
try {
|
|
235
295
|
result = arg0 instanceof ArrayBuffer;
|
|
@@ -239,7 +299,17 @@ export function __wbg_instanceof_ArrayBuffer_ff7c1337a5e3b33a(arg0) {
|
|
|
239
299
|
const ret = result;
|
|
240
300
|
return ret;
|
|
241
301
|
}
|
|
242
|
-
export function
|
|
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
|
+
}
|
|
312
|
+
export function __wbg_instanceof_Uint8Array_152ba1f289edcf3f(arg0) {
|
|
243
313
|
let result;
|
|
244
314
|
try {
|
|
245
315
|
result = arg0 instanceof Uint8Array;
|
|
@@ -249,42 +319,70 @@ export function __wbg_instanceof_Uint8Array_4b8da683deb25d72(arg0) {
|
|
|
249
319
|
const ret = result;
|
|
250
320
|
return ret;
|
|
251
321
|
}
|
|
252
|
-
export function
|
|
322
|
+
export function __wbg_isArray_c3109d14ffc06469(arg0) {
|
|
323
|
+
const ret = Array.isArray(arg0);
|
|
324
|
+
return ret;
|
|
325
|
+
}
|
|
326
|
+
export function __wbg_isSafeInteger_4fc213d1989d6d2a(arg0) {
|
|
253
327
|
const ret = Number.isSafeInteger(arg0);
|
|
254
328
|
return ret;
|
|
255
329
|
}
|
|
256
|
-
export function
|
|
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
|
+
}
|
|
338
|
+
export function __wbg_length_9f1775224cf1d815(arg0) {
|
|
257
339
|
const ret = arg0.length;
|
|
258
340
|
return ret;
|
|
259
341
|
}
|
|
342
|
+
export function __wbg_new_0c7403db6e782f19(arg0) {
|
|
343
|
+
const ret = new Uint8Array(arg0);
|
|
344
|
+
return ret;
|
|
345
|
+
}
|
|
260
346
|
export function __wbg_new_227d7c05414eb861() {
|
|
261
347
|
const ret = new Error();
|
|
262
348
|
return ret;
|
|
263
349
|
}
|
|
264
|
-
export function
|
|
265
|
-
const ret = new
|
|
350
|
+
export function __wbg_new_34d45cc8e36aaead() {
|
|
351
|
+
const ret = new Map();
|
|
266
352
|
return ret;
|
|
267
353
|
}
|
|
268
|
-
export function
|
|
269
|
-
const ret = new
|
|
354
|
+
export function __wbg_new_682678e2f47e32bc() {
|
|
355
|
+
const ret = new Array();
|
|
270
356
|
return ret;
|
|
271
357
|
}
|
|
272
|
-
export function
|
|
273
|
-
const ret = new
|
|
358
|
+
export function __wbg_new_aa8d0fa9762c29bd() {
|
|
359
|
+
const ret = new Object();
|
|
274
360
|
return ret;
|
|
275
361
|
}
|
|
276
|
-
export function
|
|
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
|
+
}
|
|
370
|
+
export function __wbg_now_a9b7df1cbee90986() {
|
|
277
371
|
const ret = Date.now();
|
|
278
372
|
return ret;
|
|
279
373
|
}
|
|
280
|
-
export function
|
|
374
|
+
export function __wbg_prototypesetcall_a6b02eb00b0f4ce2(arg0, arg1, arg2) {
|
|
281
375
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
282
376
|
}
|
|
377
|
+
export function __wbg_set_3bf1de9fab0cd644(arg0, arg1, arg2) {
|
|
378
|
+
arg0[arg1 >>> 0] = arg2;
|
|
379
|
+
}
|
|
283
380
|
export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
|
|
284
381
|
arg0[arg1] = arg2;
|
|
285
382
|
}
|
|
286
|
-
export function
|
|
287
|
-
|
|
383
|
+
export function __wbg_set_fde2cec06c23692b(arg0, arg1, arg2) {
|
|
384
|
+
const ret = arg0.set(arg1, arg2);
|
|
385
|
+
return ret;
|
|
288
386
|
}
|
|
289
387
|
export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
|
|
290
388
|
const ret = arg1.stack;
|
|
@@ -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
|
@@ -289,11 +289,8 @@ function getCallable(obj, names) {
|
|
|
289
289
|
return null;
|
|
290
290
|
}
|
|
291
291
|
var defaultLoader = async () => {
|
|
292
|
-
const
|
|
293
|
-
return
|
|
294
|
-
/* @vite-ignore */
|
|
295
|
-
generatedModuleUrl.href
|
|
296
|
-
);
|
|
292
|
+
const loaderModule = await import("./default-loader.js");
|
|
293
|
+
return loaderModule.default();
|
|
297
294
|
};
|
|
298
295
|
var INTERNAL_DUPLICATE_MATCH_FLAG = "__matcherDuplicate";
|
|
299
296
|
var WrappedDatabase = class {
|
|
@@ -310,12 +307,12 @@ var WrappedDatabase = class {
|
|
|
310
307
|
}
|
|
311
308
|
fn.call(this.inner, name, afpType, fingerprint);
|
|
312
309
|
}
|
|
313
|
-
addOrReplace(name, afpType, fingerprint) {
|
|
310
|
+
addOrReplace(name, afpType, fingerprint, metadata) {
|
|
314
311
|
const fn = getCallable(this.inner, ["addOrReplace", "add_or_replace"]);
|
|
315
312
|
if (!fn) {
|
|
316
313
|
throw new Error("WASM database is missing addOrReplace");
|
|
317
314
|
}
|
|
318
|
-
fn.call(this.inner, name, afpType, fingerprint);
|
|
315
|
+
fn.call(this.inner, name, afpType, fingerprint, metadata);
|
|
319
316
|
}
|
|
320
317
|
removeEntry(name) {
|
|
321
318
|
const fn = getCallable(this.inner, ["removeEntry", "remove_entry"]);
|
|
@@ -350,6 +347,17 @@ var WrappedDatabase = class {
|
|
|
350
347
|
}
|
|
351
348
|
appendFn.call(this.inner, bytes);
|
|
352
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
|
+
}
|
|
353
361
|
destroy() {
|
|
354
362
|
const fn = getCallable(this.inner, ["destroy", "free"]);
|
|
355
363
|
if (fn) {
|
|
@@ -380,15 +388,18 @@ var WrappedMatcher = class {
|
|
|
380
388
|
if (!raw) {
|
|
381
389
|
return null;
|
|
382
390
|
}
|
|
383
|
-
if (typeof raw === "object" && raw !== null
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
391
|
+
if (typeof raw === "object" && raw !== null) {
|
|
392
|
+
const duplicateResult = raw;
|
|
393
|
+
if (duplicateResult.duplicate === true && duplicateResult.best) {
|
|
394
|
+
const normalized = normalizeResult(duplicateResult.best);
|
|
395
|
+
Object.defineProperty(normalized, INTERNAL_DUPLICATE_MATCH_FLAG, {
|
|
396
|
+
value: true,
|
|
397
|
+
enumerable: false,
|
|
398
|
+
configurable: false,
|
|
399
|
+
writable: false
|
|
400
|
+
});
|
|
401
|
+
return normalized;
|
|
402
|
+
}
|
|
392
403
|
}
|
|
393
404
|
return normalizeResult(raw);
|
|
394
405
|
}
|
|
@@ -412,6 +423,26 @@ function normalizeResult(raw) {
|
|
|
412
423
|
afpType
|
|
413
424
|
};
|
|
414
425
|
}
|
|
426
|
+
function normalizeEntryMetadata(raw) {
|
|
427
|
+
const {
|
|
428
|
+
_id: legacyId,
|
|
429
|
+
id,
|
|
430
|
+
kind,
|
|
431
|
+
type,
|
|
432
|
+
title,
|
|
433
|
+
name,
|
|
434
|
+
image,
|
|
435
|
+
...rest
|
|
436
|
+
} = raw;
|
|
437
|
+
return {
|
|
438
|
+
...rest,
|
|
439
|
+
...id !== void 0 || legacyId !== void 0 ? { id: String(id ?? legacyId) } : {},
|
|
440
|
+
...name !== void 0 ? { name: name == null ? null : String(name) } : {},
|
|
441
|
+
...title !== void 0 ? { title: title == null ? null : String(title) } : {},
|
|
442
|
+
...image !== void 0 ? { image: image == null ? null : String(image) } : {},
|
|
443
|
+
...type !== void 0 || kind !== void 0 ? { type: type == null && kind == null ? null : String(type ?? kind) } : {}
|
|
444
|
+
};
|
|
445
|
+
}
|
|
415
446
|
function normalizeResults(rawResults) {
|
|
416
447
|
return rawResults.filter((item) => typeof item === "object" && item !== null).map((item) => normalizeResult(item));
|
|
417
448
|
}
|
|
@@ -557,10 +588,15 @@ var MatcherSession = class {
|
|
|
557
588
|
handleError(this.events, "addEntry", error);
|
|
558
589
|
}
|
|
559
590
|
}
|
|
560
|
-
async addOrReplace(name, afpType, fingerprint) {
|
|
591
|
+
async addOrReplace(name, afpType, fingerprint, metadata) {
|
|
561
592
|
try {
|
|
562
593
|
await this.ensureLiveReady();
|
|
563
|
-
this.databaseOrThrow().addOrReplace(
|
|
594
|
+
this.databaseOrThrow().addOrReplace(
|
|
595
|
+
name,
|
|
596
|
+
afpType,
|
|
597
|
+
toUint8ArrayCopy(fingerprint),
|
|
598
|
+
metadata
|
|
599
|
+
);
|
|
564
600
|
this.distinctMatchDeduper.reset();
|
|
565
601
|
this.matcher?.resetDistinctMatchState?.();
|
|
566
602
|
} catch (error) {
|
|
@@ -587,6 +623,14 @@ var MatcherSession = class {
|
|
|
587
623
|
handleError(this.events, "clear", error);
|
|
588
624
|
}
|
|
589
625
|
}
|
|
626
|
+
async getEntryMetadata(name) {
|
|
627
|
+
try {
|
|
628
|
+
await this.ensureLiveReady();
|
|
629
|
+
return this.databaseOrThrow().getEntryMetadata(name);
|
|
630
|
+
} catch (error) {
|
|
631
|
+
handleError(this.events, "getEntryMetadata", error);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
590
634
|
async match(query, config) {
|
|
591
635
|
try {
|
|
592
636
|
await this.ensureLiveReady();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sorisdk/matcher",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Browser WASM SDK for audio fingerprint matching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build:wasm": "node ../../scripts/build-wasm-package.mjs matcher",
|
|
42
42
|
"build:assets": "node ./scripts/copy-assets.mjs",
|
|
43
|
-
"build": "tsup src/index.ts --format esm --dts && pnpm run build:wasm && pnpm run build:assets",
|
|
43
|
+
"build": "tsup src/index.ts --format esm --dts && pnpm run build:wasm && pnpm run build:assets && node ../../scripts/write-default-loader.mjs packages/matcher ./generated/core.js",
|
|
44
44
|
"test": "vitest run",
|
|
45
45
|
"test:watch": "vitest"
|
|
46
46
|
}
|