indexer-web 1.0.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,18 @@
1
+ import { EngineValue } from "./indexer_web.js";
2
+ export default class Indexer {
3
+ private workers;
4
+ private nextReqId;
5
+ private pending;
6
+ private progress;
7
+ private limit;
8
+ constructor();
9
+ private rpc;
10
+ private onProgress?;
11
+ private attach;
12
+ read(name: string, title: string, data: string | Uint8Array | Blob, cb?: (name: string, processBytes: number) => void): Promise<number>;
13
+ search(name: string, query: string, limit?: number): Promise<EngineValue[]>;
14
+ getTitleDocument(name: string, docId: number): Promise<string>;
15
+ clear(name: string): void;
16
+ clearAll(): void;
17
+ }
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAA;AAG5C,MAAM,CAAC,OAAO,OAAO,OAAO;IACxB,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,OAAO,CAA2C;IAC1D,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,KAAK,CAAqB;;IAUlC,OAAO,CAAC,GAAG;IAcX,OAAO,CAAC,UAAU,CAAC,CAA8C;IAEjE,OAAO,CAAC,MAAM;IAkBR,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI;IAqD3H,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW;IAStD,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAS5C,KAAK,CAAC,IAAI,EAAE,MAAM;IAQlB,QAAQ;CAKX"}
package/dist/index.js ADDED
@@ -0,0 +1,120 @@
1
+ import { EngineValue } from "./indexer_web.js";
2
+ export default class Indexer {
3
+ workers;
4
+ nextReqId;
5
+ pending;
6
+ progress;
7
+ limit;
8
+ constructor() {
9
+ this.workers = new Map();
10
+ this.nextReqId = 1;
11
+ this.pending = new Map();
12
+ this.progress = new Map();
13
+ this.limit = new Map();
14
+ }
15
+ rpc(worker, msg) {
16
+ let reqId = msg.reqId ?? this.nextReqId++;
17
+ msg.reqId = reqId;
18
+ return new Promise((resolve, reject) => {
19
+ this.pending.set(reqId, (reply) => {
20
+ if (reply.type === 'error')
21
+ reject(new Error(reply.message));
22
+ else
23
+ resolve(reply.value);
24
+ });
25
+ worker.postMessage(msg);
26
+ });
27
+ }
28
+ onProgress;
29
+ attach(worker) {
30
+ worker.addEventListener('message', (event) => {
31
+ const data = event.data;
32
+ if (data.type === 'progress') {
33
+ this.onProgress?.(data.name, data.progress);
34
+ return;
35
+ }
36
+ const reqId = data.reqId;
37
+ if (typeof reqId === 'number') {
38
+ const cb = this.pending.get(reqId);
39
+ if (cb) {
40
+ this.pending.delete(reqId);
41
+ cb(data);
42
+ }
43
+ }
44
+ });
45
+ }
46
+ async read(name, title, data, cb) {
47
+ if (cb)
48
+ this.onProgress = cb;
49
+ const worker = new Worker(new URL('./worker.js', import.meta.url), {
50
+ type: 'module',
51
+ name,
52
+ });
53
+ this.attach(worker);
54
+ await new Promise((resolve, reject) => {
55
+ worker.addEventListener('message', (event) => {
56
+ if (event.data.type === 'ready')
57
+ resolve(null);
58
+ }, { once: true });
59
+ worker.postMessage({ type: 'init' });
60
+ setTimeout(() => reject(new Error('Worker init timeout')), 10000);
61
+ });
62
+ const docId = await this.rpc(worker, { type: 'begin', name: title, reqId: this.nextReqId++ });
63
+ const chunkSize = 16 * 1024 * 1024;
64
+ if (typeof data === 'string') {
65
+ const response = await fetch(data);
66
+ if (!response.body)
67
+ throw new Error(`Could not fetch ${name}`);
68
+ const stream = response.body.getReader();
69
+ while (true) {
70
+ const { value, done } = await stream.read();
71
+ if (done)
72
+ break;
73
+ const buffer = value?.buffer.slice(value?.byteOffset, value?.byteOffset + value?.byteLength);
74
+ worker.postMessage({ type: 'feed', value: buffer }, [buffer]);
75
+ }
76
+ }
77
+ else if (data instanceof Blob) {
78
+ let offset = 0;
79
+ while (offset < data.size) {
80
+ const buffer = await data.slice(offset, offset + chunkSize).arrayBuffer();
81
+ worker.postMessage({ type: 'feed', value: buffer }, [buffer]);
82
+ offset += chunkSize;
83
+ }
84
+ }
85
+ else {
86
+ for (let offset = 0; offset < data.length; offset += chunkSize) {
87
+ const buffer = data.subarray(offset, offset + chunkSize).slice().buffer;
88
+ worker.postMessage({ type: 'feed', value: buffer }, [buffer]);
89
+ }
90
+ }
91
+ await this.rpc(worker, { type: 'end', reqId: this.nextReqId++ });
92
+ this.workers.set(name, worker);
93
+ return docId;
94
+ }
95
+ search(name, query, limit = 20) {
96
+ const worker = this.workers.get(name);
97
+ if (!worker)
98
+ throw new Error('No worker found.');
99
+ return this.rpc(worker, { type: 'search', query, limit, reqId: this.nextReqId++ });
100
+ }
101
+ getTitleDocument(name, docId) {
102
+ const worker = this.workers.get(name);
103
+ if (!worker)
104
+ throw new Error('No worker found.');
105
+ return this.rpc(worker, { type: 'name-document', idDoc: docId, reqId: this.nextReqId++ });
106
+ }
107
+ clear(name) {
108
+ const worker = this.workers.get(name);
109
+ if (!worker)
110
+ throw new Error('No worker found.');
111
+ worker.terminate();
112
+ this.workers.delete(name);
113
+ }
114
+ clearAll() {
115
+ for (const worker of this.workers.values())
116
+ worker.terminate();
117
+ this.workers.clear();
118
+ }
119
+ }
120
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB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ACrG,CAAC;IAED,gBAAgB,CAAC,IAAY,EAAE,KAAa;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAErC,IAAI,CAAC,MAAM;YACP,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;QAEvC,OAAO,IAAI,CAAC,GAAG,CAAS,MAAM,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;IACrG,CAAC;IAED,KAAK,CAAC,IAAY;QACd,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACrC,IAAI,CAAC,MAAM;YACP,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;QACvC,MAAM,CAAC,SAAS,EAAE,CAAA;QAClB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IAED,QAAQ;QACJ,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACtC,MAAM,CAAC,SAAS,EAAE,CAAA;QACtB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IACxB,CAAC;CACJ"}
@@ -0,0 +1,70 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class Engine {
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ add_content(content: Uint8Array): void;
8
+ begin_document(name: string): number;
9
+ constructor();
10
+ flush(): void;
11
+ insert(name: string, content: Uint8Array): void;
12
+ search(query: string, limit?: number | null): Array<any>;
13
+ doc_name(id_doc: number): string;
14
+ }
15
+
16
+ export class EngineValue {
17
+ private constructor();
18
+ free(): void;
19
+ [Symbol.dispose](): void;
20
+ doc_id: number;
21
+ count: number;
22
+ }
23
+
24
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
25
+
26
+ export interface InitOutput {
27
+ readonly memory: WebAssembly.Memory;
28
+ readonly __wbg_engine_free: (a: number, b: number) => void;
29
+ readonly __wbg_enginevalue_free: (a: number, b: number) => void;
30
+ readonly __wbg_get_enginevalue_count: (a: number) => number;
31
+ readonly __wbg_get_enginevalue_doc_id: (a: number) => number;
32
+ readonly __wbg_set_enginevalue_count: (a: number, b: number) => void;
33
+ readonly __wbg_set_enginevalue_doc_id: (a: number, b: number) => void;
34
+ readonly engine_add_content: (a: number, b: number, c: number) => void;
35
+ readonly engine_begin_document: (a: number, b: number, c: number) => number;
36
+ readonly engine_doc_name: (a: number, b: number) => [number, number];
37
+ readonly engine_flush: (a: number) => void;
38
+ readonly engine_insert: (a: number, b: number, c: number, d: number, e: number) => void;
39
+ readonly engine_new: () => number;
40
+ readonly engine_search: (a: number, b: number, c: number, d: number) => any;
41
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
42
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
43
+ readonly __wbindgen_exn_store: (a: number) => void;
44
+ readonly __externref_table_alloc: () => number;
45
+ readonly __wbindgen_externrefs: WebAssembly.Table;
46
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
47
+ readonly __wbindgen_start: () => void;
48
+ }
49
+
50
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
51
+
52
+ /**
53
+ * Instantiates the given `module`, which can either be bytes or
54
+ * a precompiled `WebAssembly.Module`.
55
+ *
56
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
57
+ *
58
+ * @returns {InitOutput}
59
+ */
60
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
61
+
62
+ /**
63
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
64
+ * for everything else, calls `WebAssembly.instantiate` directly.
65
+ *
66
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
67
+ *
68
+ * @returns {Promise<InitOutput>}
69
+ */
70
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,458 @@
1
+ let wasm;
2
+
3
+ function addToExternrefTable0(obj) {
4
+ const idx = wasm.__externref_table_alloc();
5
+ wasm.__wbindgen_externrefs.set(idx, obj);
6
+ return idx;
7
+ }
8
+
9
+ function debugString(val) {
10
+ // primitive types
11
+ const type = typeof val;
12
+ if (type == 'number' || type == 'boolean' || val == null) {
13
+ return `${val}`;
14
+ }
15
+ if (type == 'string') {
16
+ return `"${val}"`;
17
+ }
18
+ if (type == 'symbol') {
19
+ const description = val.description;
20
+ if (description == null) {
21
+ return 'Symbol';
22
+ } else {
23
+ return `Symbol(${description})`;
24
+ }
25
+ }
26
+ if (type == 'function') {
27
+ const name = val.name;
28
+ if (typeof name == 'string' && name.length > 0) {
29
+ return `Function(${name})`;
30
+ } else {
31
+ return 'Function';
32
+ }
33
+ }
34
+ // objects
35
+ if (Array.isArray(val)) {
36
+ const length = val.length;
37
+ let debug = '[';
38
+ if (length > 0) {
39
+ debug += debugString(val[0]);
40
+ }
41
+ for(let i = 1; i < length; i++) {
42
+ debug += ', ' + debugString(val[i]);
43
+ }
44
+ debug += ']';
45
+ return debug;
46
+ }
47
+ // Test for built-in
48
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
49
+ let className;
50
+ if (builtInMatches && builtInMatches.length > 1) {
51
+ className = builtInMatches[1];
52
+ } else {
53
+ // Failed to match the standard '[object ClassName]'
54
+ return toString.call(val);
55
+ }
56
+ if (className == 'Object') {
57
+ // we're a user defined class or Object
58
+ // JSON.stringify avoids problems with cycles, and is generally much
59
+ // easier than looping through ownProperties of `val`.
60
+ try {
61
+ return 'Object(' + JSON.stringify(val) + ')';
62
+ } catch (_) {
63
+ return 'Object';
64
+ }
65
+ }
66
+ // errors
67
+ if (val instanceof Error) {
68
+ return `${val.name}: ${val.message}\n${val.stack}`;
69
+ }
70
+ // TODO we could test for more things here, like `Set`s and `Map`s.
71
+ return className;
72
+ }
73
+
74
+ function getArrayU8FromWasm0(ptr, len) {
75
+ ptr = ptr >>> 0;
76
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
77
+ }
78
+
79
+ let cachedDataViewMemory0 = null;
80
+ function getDataViewMemory0() {
81
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
82
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
83
+ }
84
+ return cachedDataViewMemory0;
85
+ }
86
+
87
+ function getStringFromWasm0(ptr, len) {
88
+ ptr = ptr >>> 0;
89
+ return decodeText(ptr, len);
90
+ }
91
+
92
+ let cachedUint8ArrayMemory0 = null;
93
+ function getUint8ArrayMemory0() {
94
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
95
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
96
+ }
97
+ return cachedUint8ArrayMemory0;
98
+ }
99
+
100
+ function handleError(f, args) {
101
+ try {
102
+ return f.apply(this, args);
103
+ } catch (e) {
104
+ const idx = addToExternrefTable0(e);
105
+ wasm.__wbindgen_exn_store(idx);
106
+ }
107
+ }
108
+
109
+ function isLikeNone(x) {
110
+ return x === undefined || x === null;
111
+ }
112
+
113
+ function passArray8ToWasm0(arg, malloc) {
114
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
115
+ getUint8ArrayMemory0().set(arg, ptr / 1);
116
+ WASM_VECTOR_LEN = arg.length;
117
+ return ptr;
118
+ }
119
+
120
+ function passStringToWasm0(arg, malloc, realloc) {
121
+ if (realloc === undefined) {
122
+ const buf = cachedTextEncoder.encode(arg);
123
+ const ptr = malloc(buf.length, 1) >>> 0;
124
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
125
+ WASM_VECTOR_LEN = buf.length;
126
+ return ptr;
127
+ }
128
+
129
+ let len = arg.length;
130
+ let ptr = malloc(len, 1) >>> 0;
131
+
132
+ const mem = getUint8ArrayMemory0();
133
+
134
+ let offset = 0;
135
+
136
+ for (; offset < len; offset++) {
137
+ const code = arg.charCodeAt(offset);
138
+ if (code > 0x7F) break;
139
+ mem[ptr + offset] = code;
140
+ }
141
+ if (offset !== len) {
142
+ if (offset !== 0) {
143
+ arg = arg.slice(offset);
144
+ }
145
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
146
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
147
+ const ret = cachedTextEncoder.encodeInto(arg, view);
148
+
149
+ offset += ret.written;
150
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
151
+ }
152
+
153
+ WASM_VECTOR_LEN = offset;
154
+ return ptr;
155
+ }
156
+
157
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
158
+ cachedTextDecoder.decode();
159
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
160
+ let numBytesDecoded = 0;
161
+ function decodeText(ptr, len) {
162
+ numBytesDecoded += len;
163
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
164
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
165
+ cachedTextDecoder.decode();
166
+ numBytesDecoded = len;
167
+ }
168
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
169
+ }
170
+
171
+ const cachedTextEncoder = new TextEncoder();
172
+
173
+ if (!('encodeInto' in cachedTextEncoder)) {
174
+ cachedTextEncoder.encodeInto = function (arg, view) {
175
+ const buf = cachedTextEncoder.encode(arg);
176
+ view.set(buf);
177
+ return {
178
+ read: arg.length,
179
+ written: buf.length
180
+ };
181
+ }
182
+ }
183
+
184
+ let WASM_VECTOR_LEN = 0;
185
+
186
+ const EngineFinalization = (typeof FinalizationRegistry === 'undefined')
187
+ ? { register: () => {}, unregister: () => {} }
188
+ : new FinalizationRegistry(ptr => wasm.__wbg_engine_free(ptr >>> 0, 1));
189
+
190
+ const EngineValueFinalization = (typeof FinalizationRegistry === 'undefined')
191
+ ? { register: () => {}, unregister: () => {} }
192
+ : new FinalizationRegistry(ptr => wasm.__wbg_enginevalue_free(ptr >>> 0, 1));
193
+
194
+ export class Engine {
195
+ __destroy_into_raw() {
196
+ const ptr = this.__wbg_ptr;
197
+ this.__wbg_ptr = 0;
198
+ EngineFinalization.unregister(this);
199
+ return ptr;
200
+ }
201
+ free() {
202
+ const ptr = this.__destroy_into_raw();
203
+ wasm.__wbg_engine_free(ptr, 0);
204
+ }
205
+ /**
206
+ * @param {Uint8Array} content
207
+ */
208
+ add_content(content) {
209
+ const ptr0 = passArray8ToWasm0(content, wasm.__wbindgen_malloc);
210
+ const len0 = WASM_VECTOR_LEN;
211
+ wasm.engine_add_content(this.__wbg_ptr, ptr0, len0);
212
+ }
213
+ /**
214
+ * @param {string} name
215
+ * @returns {number}
216
+ */
217
+ begin_document(name) {
218
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
219
+ const len0 = WASM_VECTOR_LEN;
220
+ const ret = wasm.engine_begin_document(this.__wbg_ptr, ptr0, len0);
221
+ return ret >>> 0;
222
+ }
223
+ constructor() {
224
+ const ret = wasm.engine_new();
225
+ this.__wbg_ptr = ret >>> 0;
226
+ EngineFinalization.register(this, this.__wbg_ptr, this);
227
+ return this;
228
+ }
229
+ flush() {
230
+ wasm.engine_flush(this.__wbg_ptr);
231
+ }
232
+ /**
233
+ * @param {string} name
234
+ * @param {Uint8Array} content
235
+ */
236
+ insert(name, content) {
237
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
238
+ const len0 = WASM_VECTOR_LEN;
239
+ const ptr1 = passArray8ToWasm0(content, wasm.__wbindgen_malloc);
240
+ const len1 = WASM_VECTOR_LEN;
241
+ wasm.engine_insert(this.__wbg_ptr, ptr0, len0, ptr1, len1);
242
+ }
243
+ /**
244
+ * @param {string} query
245
+ * @param {number | null} [limit]
246
+ * @returns {Array<any>}
247
+ */
248
+ search(query, limit) {
249
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
250
+ const len0 = WASM_VECTOR_LEN;
251
+ const ret = wasm.engine_search(this.__wbg_ptr, ptr0, len0, isLikeNone(limit) ? 0x100000001 : (limit) >>> 0);
252
+ return ret;
253
+ }
254
+ /**
255
+ * @param {number} id_doc
256
+ * @returns {string}
257
+ */
258
+ doc_name(id_doc) {
259
+ let deferred1_0;
260
+ let deferred1_1;
261
+ try {
262
+ const ret = wasm.engine_doc_name(this.__wbg_ptr, id_doc);
263
+ deferred1_0 = ret[0];
264
+ deferred1_1 = ret[1];
265
+ return getStringFromWasm0(ret[0], ret[1]);
266
+ } finally {
267
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
268
+ }
269
+ }
270
+ }
271
+ if (Symbol.dispose) Engine.prototype[Symbol.dispose] = Engine.prototype.free;
272
+
273
+ export class EngineValue {
274
+ __destroy_into_raw() {
275
+ const ptr = this.__wbg_ptr;
276
+ this.__wbg_ptr = 0;
277
+ EngineValueFinalization.unregister(this);
278
+ return ptr;
279
+ }
280
+ free() {
281
+ const ptr = this.__destroy_into_raw();
282
+ wasm.__wbg_enginevalue_free(ptr, 0);
283
+ }
284
+ /**
285
+ * @returns {number}
286
+ */
287
+ get doc_id() {
288
+ const ret = wasm.__wbg_get_enginevalue_doc_id(this.__wbg_ptr);
289
+ return ret >>> 0;
290
+ }
291
+ /**
292
+ * @param {number} arg0
293
+ */
294
+ set doc_id(arg0) {
295
+ wasm.__wbg_set_enginevalue_doc_id(this.__wbg_ptr, arg0);
296
+ }
297
+ /**
298
+ * @returns {number}
299
+ */
300
+ get count() {
301
+ const ret = wasm.__wbg_get_enginevalue_count(this.__wbg_ptr);
302
+ return ret >>> 0;
303
+ }
304
+ /**
305
+ * @param {number} arg0
306
+ */
307
+ set count(arg0) {
308
+ wasm.__wbg_set_enginevalue_count(this.__wbg_ptr, arg0);
309
+ }
310
+ }
311
+ if (Symbol.dispose) EngineValue.prototype[Symbol.dispose] = EngineValue.prototype.free;
312
+
313
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
314
+
315
+ async function __wbg_load(module, imports) {
316
+ if (typeof Response === 'function' && module instanceof Response) {
317
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
318
+ try {
319
+ return await WebAssembly.instantiateStreaming(module, imports);
320
+ } catch (e) {
321
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
322
+
323
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
324
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
325
+
326
+ } else {
327
+ throw e;
328
+ }
329
+ }
330
+ }
331
+
332
+ const bytes = await module.arrayBuffer();
333
+ return await WebAssembly.instantiate(bytes, imports);
334
+ } else {
335
+ const instance = await WebAssembly.instantiate(module, imports);
336
+
337
+ if (instance instanceof WebAssembly.Instance) {
338
+ return { instance, module };
339
+ } else {
340
+ return instance;
341
+ }
342
+ }
343
+ }
344
+
345
+ function __wbg_get_imports() {
346
+ const imports = {};
347
+ imports.wbg = {};
348
+ imports.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6 = function(arg0, arg1) {
349
+ const ret = debugString(arg1);
350
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
351
+ const len1 = WASM_VECTOR_LEN;
352
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
353
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
354
+ };
355
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
356
+ throw new Error(getStringFromWasm0(arg0, arg1));
357
+ };
358
+ imports.wbg.__wbg_getRandomValues_1c61fac11405ffdc = function() { return handleError(function (arg0, arg1) {
359
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
360
+ }, arguments) };
361
+ imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
362
+ const ret = new Object();
363
+ return ret;
364
+ };
365
+ imports.wbg.__wbg_new_25f239778d6112b9 = function() {
366
+ const ret = new Array();
367
+ return ret;
368
+ };
369
+ imports.wbg.__wbg_push_7d9be8f38fc13975 = function(arg0, arg1) {
370
+ const ret = arg0.push(arg1);
371
+ return ret;
372
+ };
373
+ imports.wbg.__wbg_set_781438a03c0c3c81 = function() { return handleError(function (arg0, arg1, arg2) {
374
+ const ret = Reflect.set(arg0, arg1, arg2);
375
+ return ret;
376
+ }, arguments) };
377
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
378
+ // Cast intrinsic for `Ref(String) -> Externref`.
379
+ const ret = getStringFromWasm0(arg0, arg1);
380
+ return ret;
381
+ };
382
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
383
+ // Cast intrinsic for `F64 -> Externref`.
384
+ const ret = arg0;
385
+ return ret;
386
+ };
387
+ imports.wbg.__wbindgen_init_externref_table = function() {
388
+ const table = wasm.__wbindgen_externrefs;
389
+ const offset = table.grow(4);
390
+ table.set(0, undefined);
391
+ table.set(offset + 0, undefined);
392
+ table.set(offset + 1, null);
393
+ table.set(offset + 2, true);
394
+ table.set(offset + 3, false);
395
+ };
396
+
397
+ return imports;
398
+ }
399
+
400
+ function __wbg_finalize_init(instance, module) {
401
+ wasm = instance.exports;
402
+ __wbg_init.__wbindgen_wasm_module = module;
403
+ cachedDataViewMemory0 = null;
404
+ cachedUint8ArrayMemory0 = null;
405
+
406
+
407
+ wasm.__wbindgen_start();
408
+ return wasm;
409
+ }
410
+
411
+ function initSync(module) {
412
+ if (wasm !== undefined) return wasm;
413
+
414
+
415
+ if (typeof module !== 'undefined') {
416
+ if (Object.getPrototypeOf(module) === Object.prototype) {
417
+ ({module} = module)
418
+ } else {
419
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
420
+ }
421
+ }
422
+
423
+ const imports = __wbg_get_imports();
424
+ if (!(module instanceof WebAssembly.Module)) {
425
+ module = new WebAssembly.Module(module);
426
+ }
427
+ const instance = new WebAssembly.Instance(module, imports);
428
+ return __wbg_finalize_init(instance, module);
429
+ }
430
+
431
+ async function __wbg_init(module_or_path) {
432
+ if (wasm !== undefined) return wasm;
433
+
434
+
435
+ if (typeof module_or_path !== 'undefined') {
436
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
437
+ ({module_or_path} = module_or_path)
438
+ } else {
439
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
440
+ }
441
+ }
442
+
443
+ if (typeof module_or_path === 'undefined') {
444
+ module_or_path = new URL('indexer_web_bg.wasm', import.meta.url);
445
+ }
446
+ const imports = __wbg_get_imports();
447
+
448
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
449
+ module_or_path = fetch(module_or_path);
450
+ }
451
+
452
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
453
+
454
+ return __wbg_finalize_init(instance, module);
455
+ }
456
+
457
+ export { initSync };
458
+ export default __wbg_init;
Binary file
@@ -0,0 +1,23 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_engine_free: (a: number, b: number) => void;
5
+ export const __wbg_enginevalue_free: (a: number, b: number) => void;
6
+ export const __wbg_get_enginevalue_count: (a: number) => number;
7
+ export const __wbg_get_enginevalue_doc_id: (a: number) => number;
8
+ export const __wbg_set_enginevalue_count: (a: number, b: number) => void;
9
+ export const __wbg_set_enginevalue_doc_id: (a: number, b: number) => void;
10
+ export const engine_add_content: (a: number, b: number, c: number) => void;
11
+ export const engine_begin_document: (a: number, b: number, c: number) => number;
12
+ export const engine_doc_name: (a: number, b: number) => [number, number];
13
+ export const engine_flush: (a: number) => void;
14
+ export const engine_insert: (a: number, b: number, c: number, d: number, e: number) => void;
15
+ export const engine_new: () => number;
16
+ export const engine_search: (a: number, b: number, c: number, d: number) => any;
17
+ export const __wbindgen_malloc: (a: number, b: number) => number;
18
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
19
+ export const __wbindgen_exn_store: (a: number) => void;
20
+ export const __externref_table_alloc: () => number;
21
+ export const __wbindgen_externrefs: WebAssembly.Table;
22
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
23
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,51 @@
1
+ import { EngineValue } from './indexer_web.js';
2
+ export type WorkerMessage = {
3
+ type: 'ready';
4
+ } | {
5
+ type: 'document-ready';
6
+ value: number;
7
+ reqId: number;
8
+ } | {
9
+ type: 'result';
10
+ value: EngineValue[];
11
+ reqId: number;
12
+ } | {
13
+ type: 'error';
14
+ message: string;
15
+ reqId: number;
16
+ } | {
17
+ type: 'name-document';
18
+ value: string;
19
+ reqId: number;
20
+ } | {
21
+ type: 'end';
22
+ value: any;
23
+ reqId: number;
24
+ } | {
25
+ type: 'progress';
26
+ name: string;
27
+ progress: number;
28
+ };
29
+ export type MainMessage = {
30
+ type: 'init';
31
+ } | {
32
+ type: 'begin';
33
+ name: string;
34
+ reqId: number;
35
+ } | {
36
+ type: 'feed';
37
+ value: ArrayBuffer;
38
+ } | {
39
+ type: 'end';
40
+ reqId: number;
41
+ } | {
42
+ type: 'search';
43
+ query: string;
44
+ limit: number;
45
+ reqId: number;
46
+ } | {
47
+ type: 'name-document';
48
+ idDoc: number;
49
+ reqId: number;
50
+ };
51
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../ts/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MA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AAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { EngineValue } from './indexer_web.js';
2
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../ts/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../ts/worker.ts"],"names":[],"mappings":""}
package/dist/worker.js ADDED
@@ -0,0 +1,91 @@
1
+ import init, { Engine } from './indexer_web.js';
2
+ let indexer;
3
+ let chunk = 0;
4
+ let progress = 0;
5
+ let id = 0;
6
+ onmessage = async (event) => {
7
+ if (event.data.type === 'init') {
8
+ await init();
9
+ indexer = new Engine();
10
+ postMessage({
11
+ type: 'ready'
12
+ });
13
+ }
14
+ else if (event.data.type === 'begin') {
15
+ if (indexer) {
16
+ id = indexer.begin_document(event.data.name);
17
+ postMessage({
18
+ type: 'document-ready',
19
+ value: id,
20
+ reqId: event.data.reqId
21
+ });
22
+ }
23
+ else
24
+ postMessage({
25
+ type: 'error',
26
+ message: 'Unexpected error occurred',
27
+ reqId: event.data.reqId
28
+ });
29
+ }
30
+ else if (event.data.type === 'feed') {
31
+ if (indexer) {
32
+ const buffer = event.data.value;
33
+ progress += buffer.byteLength;
34
+ chunk += 1;
35
+ indexer.add_content(new Uint8Array(buffer));
36
+ if (chunk % 30 === 0) {
37
+ postMessage({
38
+ type: 'progress',
39
+ name: indexer.doc_name(id), progress
40
+ });
41
+ }
42
+ }
43
+ else
44
+ console.error(new Error('No activa document. Send "begin" before "feed".'));
45
+ }
46
+ else if (event.data.type === 'end') {
47
+ if (indexer) {
48
+ indexer.flush();
49
+ postMessage({
50
+ type: 'end',
51
+ value: true,
52
+ reqId: event.data.reqId
53
+ });
54
+ }
55
+ else
56
+ postMessage({
57
+ type: 'error',
58
+ message: 'Unexpected error occurred',
59
+ reqId: event.data.reqId
60
+ });
61
+ }
62
+ else if (event.data.type === 'search') {
63
+ if (indexer)
64
+ postMessage({
65
+ type: 'result',
66
+ value: indexer.search(event.data.query, event.data.limit),
67
+ reqId: event.data.reqId
68
+ });
69
+ else
70
+ postMessage({
71
+ type: 'error',
72
+ message: 'Unexpected error occurred',
73
+ reqId: event.data.reqId
74
+ });
75
+ }
76
+ else if (event.data.type === 'name-document') {
77
+ if (indexer)
78
+ postMessage({
79
+ type: 'name-document',
80
+ value: indexer.doc_name(event.data.idDoc),
81
+ reqId: event.data.reqId
82
+ });
83
+ else
84
+ postMessage({
85
+ type: 'error',
86
+ message: 'Unexpected error occurred',
87
+ reqId: event.data.reqId
88
+ });
89
+ }
90
+ };
91
+ //# sourceMappingURL=worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.js","sourceRoot":"","sources":["../ts/worker.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAG/C,IAAI,OAA2B,CAAA;AAC/B,IAAI,KAAK,GAAG,CAAC,CAAC;AACd,IAAI,QAAQ,GAAG,CAAC,CAAC;AACjB,IAAI,EAAE,GAAG,CAAC,CAAA;AAEV,SAAS,GAAG,KAAK,EAAE,KAAgC,EAAiB,EAAE;IAClE,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC7B,MAAM,IAAI,EAAE,CAAA;QACZ,OAAO,GAAG,IAAI,MAAM,EAAE,CAAC;QACvB,WAAW,CAAC;YACR,IAAI,EAAE,OAAO;SACQ,CAAC,CAAA;IAC9B,CAAC;SAAM,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QACrC,IAAI,OAAO,EAAE,CAAC;YACV,EAAE,GAAG,OAAO,CAAC,cAAc,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AC;gBACR,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,2BAA2B;gBACpC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;aACF,CAAC,CAAA;IAClC,CAAC;SAAM,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,IAAI,OAAO;YACP,WAAW,CAAC;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;gBACzD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;aACF,CAAC,CAAA;;YAE1B,WAAW,CAAC;gBACR,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,2BAA2B;gBACpC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;aACF,CAAC,CAAA;IAClC,CAAC;SAAM,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QAC7C,IAAI,OAAO;YACP,WAAW,CAAC;gBACR,IAAI,EAAE,eAAe;gBACrB,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;gBACzC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;aACF,CAAC,CAAA;;YAE1B,WAAW,CAAC;gBACR,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,2BAA2B;gBACpC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;aACF,CAAC,CAAA;IAClC,CAAC;AACL,CAAC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "indexer-web",
3
+ "version": "1.0.0",
4
+ "description": "Search engine core for indexing text files with high performance.",
5
+ "keywords": [
6
+ "inverted-index",
7
+ "inverted-index-core",
8
+ "ft-index",
9
+ "text-index-core",
10
+ "term-index",
11
+ "ft-search-core",
12
+ "search-core",
13
+ "text-search-core",
14
+ "ir-core",
15
+ "ir-engine"
16
+ ],
17
+ "homepage": "https://github.com/Saurus42/inverted-index-core#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/Saurus42/inverted-index-core/issues"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Saurus42/inverted-index-core.git"
24
+ },
25
+ "license": "MIT",
26
+ "author": "Mateusz Krasuski",
27
+ "type": "module",
28
+ "main": "dist/index.js",
29
+ "types": "dist/index.d.ts",
30
+ "exports": {
31
+ ".": "./dist/index.js"
32
+ },
33
+ "files": [ "dist", "readme.md" ],
34
+ "sideEffects": false,
35
+ "devDependencies": {
36
+ "@types/node": "^25.0.3",
37
+ "typescript": "^5.9.3"
38
+ }
39
+ }
package/readme.md ADDED
@@ -0,0 +1,163 @@
1
+ # indexer-web
2
+ High-performance inverted index for large text files, powered by Rust + WebAssembly and designed to work efficiently in browsers, Web Workers, and PWA.
3
+
4
+ Indexer processes data incrementally (streaming) and supports files from MBs to multiple GBs without blocking the main thread.
5
+
6
+ # Features
7
+
8
+ - Very fast text indexing (Rust + WASM)
9
+ - Runs inside Web Workers (non-blocking UI)
10
+ - Supports URL, Blob, and Uint8Array
11
+ - Handles hundreds of MB / GB-scale files
12
+ - Inverted index (term → documents + frequency)
13
+ - High-level JS API and low-level WASM access
14
+ - Ready for PWA usage
15
+
16
+ # Installation
17
+
18
+ ```
19
+ npm install indexer-web
20
+ ```
21
+
22
+ # Quick Start (High-level API)
23
+
24
+ ```javascript
25
+ import Indexer from "indexer-web";
26
+
27
+ const indexer = new Indexer();
28
+
29
+ // Index a document
30
+ const docId = await indexer.read(
31
+ "my-worker", // worker name (internal)
32
+ "Large document", // document title (stored in index)
33
+ "/huge-text-file.txt" // URL / Blob / Uint8Array
34
+ );
35
+
36
+ // Search
37
+ const results = await indexer.search("my-worker", "example", 10);
38
+
39
+ console.log(results);
40
+ /*
41
+ [
42
+ { doc_id: 0, count: 42 },
43
+ ...
44
+ ]
45
+ */
46
+
47
+ // Get document title
48
+ const title = await indexer.getTitleDocument("my-worker", docId);
49
+ console.log(title);
50
+ ```
51
+
52
+ # High-level API
53
+ ```
54
+ read(
55
+ workerName: string,
56
+ title: string,
57
+ data: string | Uint8Array | Blob,
58
+ onProgress?: (workerName: string, processedBytes: number) => void
59
+ ): Promise<number>
60
+ ```
61
+ Parameters
62
+
63
+ | Name | Description |
64
+ | :----------: | :---------------------------------------: |
65
+ | `workerName` | Identifier of the worker instance |
66
+ | `title` | Document title (required by core indexer) |
67
+ | `data` | URL, Blob, or Uint8Array |
68
+ | `onProgress` | Optional progress callback |
69
+
70
+ ```
71
+ search(
72
+ workerName: string,
73
+ query: string,
74
+ limit?: number
75
+ ): Promise<EngineValue[]>
76
+ ```
77
+ Searches for a term in the indexed documents.
78
+
79
+ ```
80
+ getTitleDocument(
81
+ workerName: string,
82
+ docId: number
83
+ ): Promise<string>
84
+ ```
85
+ Returns the document title.
86
+
87
+ ```
88
+ clear(workerName: string): void
89
+ ```
90
+ Terminates the worker and frees memory.
91
+
92
+ ```
93
+ clearAll(): void
94
+ ```
95
+ Terminates all workers.
96
+
97
+ # EngineValue
98
+
99
+ ```typescript
100
+ interface EngineValue {
101
+ doc_id: number;
102
+ count: number;
103
+ }
104
+ ```
105
+
106
+ - `doc_id` – document identifier
107
+ - `count` – number of occurrences in that document
108
+
109
+ # Low-level API (WASM)
110
+
111
+ For advanced use cases you can access the WASM engine directly
112
+ (no workers, no streaming wrapper).
113
+
114
+ ```javascript
115
+ import init, { Engine } from "indexer-web/dist/indexer_web";
116
+
117
+ await init();
118
+
119
+ const engine = new Engine();
120
+
121
+ const docId = engine.begin_document("Title");
122
+ engine.add_content(new Uint8Array(data));
123
+ engine.flush();
124
+
125
+ const results = engine.search("example", 10);
126
+ ```
127
+
128
+ ### When to use low-level API?
129
+
130
+ - Custom worker orchestration
131
+ - Node.js native usage
132
+ - Full control over memory & streaming
133
+ - Advanced experimentation
134
+
135
+ **Low-level API runs synchronously and may block the main thread.**
136
+
137
+ # Why Web Workers?
138
+
139
+ Indexing large files can take seconds.
140
+ Workers ensure:
141
+ - No UI freeze
142
+ - Smooth progress reporting
143
+ - Safe execution in browsers and PWAs
144
+
145
+ # PWA Support
146
+
147
+ Indexer works in:
148
+ - Browser
149
+ - Web Workers
150
+ - Progressive Web Apps (PWA)
151
+
152
+ Service Worker integration is possible and planned.
153
+
154
+ # Notes & Limitations
155
+
156
+ - Text is tokenized using ASCII rules
157
+ - Tokens shorter than 3 characters are ignored
158
+ - Case-insensitive (ASCII lowercase)
159
+ - Designed for text files, not binary formats
160
+
161
+ # License
162
+
163
+ MIT © Mateusz Krasuski