@nuschtos/fixx 0.0.2

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/fixx.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * @param {string} option
5
+ * @returns {number}
6
+ */
7
+ export function hash(option: string): number;
8
+ export class Index {
9
+ free(): void;
10
+ /**
11
+ * @param {Uint8Array} buf
12
+ * @returns {Index}
13
+ */
14
+ static read(buf: Uint8Array): Index;
15
+ /**
16
+ * @param {string} query
17
+ * @param {number} max_results
18
+ * @returns {(string)[]}
19
+ */
20
+ search(query: string, max_results: number): (string)[];
21
+ }
22
+
23
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
24
+
25
+ export interface InitOutput {
26
+ readonly memory: WebAssembly.Memory;
27
+ readonly hash: (a: number, b: number) => number;
28
+ readonly __wbg_index_free: (a: number, b: number) => void;
29
+ readonly index_read: (a: number, b: number, c: number) => void;
30
+ readonly index_search: (a: number, b: number, c: number, d: number, e: number) => void;
31
+ readonly __wbindgen_export_0: (a: number, b: number) => number;
32
+ readonly __wbindgen_export_1: (a: number, b: number, c: number, d: number) => number;
33
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
34
+ readonly __wbindgen_export_2: (a: number, b: number, c: number) => void;
35
+ }
36
+
37
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
38
+ /**
39
+ * Instantiates the given `module`, which can either be bytes or
40
+ * a precompiled `WebAssembly.Module`.
41
+ *
42
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
43
+ *
44
+ * @returns {InitOutput}
45
+ */
46
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
47
+
48
+ /**
49
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
50
+ * for everything else, calls `WebAssembly.instantiate` directly.
51
+ *
52
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
53
+ *
54
+ * @returns {Promise<InitOutput>}
55
+ */
56
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/fixx.js ADDED
@@ -0,0 +1,329 @@
1
+ let wasm;
2
+
3
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
4
+
5
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
6
+
7
+ let cachedUint8ArrayMemory0 = null;
8
+
9
+ function getUint8ArrayMemory0() {
10
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
11
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
12
+ }
13
+ return cachedUint8ArrayMemory0;
14
+ }
15
+
16
+ function getStringFromWasm0(ptr, len) {
17
+ ptr = ptr >>> 0;
18
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
19
+ }
20
+
21
+ const heap = new Array(128).fill(undefined);
22
+
23
+ heap.push(undefined, null, true, false);
24
+
25
+ let heap_next = heap.length;
26
+
27
+ function addHeapObject(obj) {
28
+ if (heap_next === heap.length) heap.push(heap.length + 1);
29
+ const idx = heap_next;
30
+ heap_next = heap[idx];
31
+
32
+ heap[idx] = obj;
33
+ return idx;
34
+ }
35
+
36
+ let WASM_VECTOR_LEN = 0;
37
+
38
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
39
+
40
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
41
+ ? function (arg, view) {
42
+ return cachedTextEncoder.encodeInto(arg, view);
43
+ }
44
+ : function (arg, view) {
45
+ const buf = cachedTextEncoder.encode(arg);
46
+ view.set(buf);
47
+ return {
48
+ read: arg.length,
49
+ written: buf.length
50
+ };
51
+ });
52
+
53
+ function passStringToWasm0(arg, malloc, realloc) {
54
+
55
+ if (realloc === undefined) {
56
+ const buf = cachedTextEncoder.encode(arg);
57
+ const ptr = malloc(buf.length, 1) >>> 0;
58
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
59
+ WASM_VECTOR_LEN = buf.length;
60
+ return ptr;
61
+ }
62
+
63
+ let len = arg.length;
64
+ let ptr = malloc(len, 1) >>> 0;
65
+
66
+ const mem = getUint8ArrayMemory0();
67
+
68
+ let offset = 0;
69
+
70
+ for (; offset < len; offset++) {
71
+ const code = arg.charCodeAt(offset);
72
+ if (code > 0x7F) break;
73
+ mem[ptr + offset] = code;
74
+ }
75
+
76
+ if (offset !== len) {
77
+ if (offset !== 0) {
78
+ arg = arg.slice(offset);
79
+ }
80
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
81
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
82
+ const ret = encodeString(arg, view);
83
+
84
+ offset += ret.written;
85
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
86
+ }
87
+
88
+ WASM_VECTOR_LEN = offset;
89
+ return ptr;
90
+ }
91
+ /**
92
+ * @param {string} option
93
+ * @returns {number}
94
+ */
95
+ export function hash(option) {
96
+ const ptr0 = passStringToWasm0(option, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
97
+ const len0 = WASM_VECTOR_LEN;
98
+ const ret = wasm.hash(ptr0, len0);
99
+ return ret;
100
+ }
101
+
102
+ function passArray8ToWasm0(arg, malloc) {
103
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
104
+ getUint8ArrayMemory0().set(arg, ptr / 1);
105
+ WASM_VECTOR_LEN = arg.length;
106
+ return ptr;
107
+ }
108
+
109
+ let cachedDataViewMemory0 = null;
110
+
111
+ function getDataViewMemory0() {
112
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
113
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
114
+ }
115
+ return cachedDataViewMemory0;
116
+ }
117
+
118
+ function getObject(idx) { return heap[idx]; }
119
+
120
+ function dropObject(idx) {
121
+ if (idx < 132) return;
122
+ heap[idx] = heap_next;
123
+ heap_next = idx;
124
+ }
125
+
126
+ function takeObject(idx) {
127
+ const ret = getObject(idx);
128
+ dropObject(idx);
129
+ return ret;
130
+ }
131
+
132
+ function getArrayJsValueFromWasm0(ptr, len) {
133
+ ptr = ptr >>> 0;
134
+ const mem = getDataViewMemory0();
135
+ const result = [];
136
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
137
+ result.push(takeObject(mem.getUint32(i, true)));
138
+ }
139
+ return result;
140
+ }
141
+
142
+ const IndexFinalization = (typeof FinalizationRegistry === 'undefined')
143
+ ? { register: () => {}, unregister: () => {} }
144
+ : new FinalizationRegistry(ptr => wasm.__wbg_index_free(ptr >>> 0, 1));
145
+
146
+ export class Index {
147
+
148
+ static __wrap(ptr) {
149
+ ptr = ptr >>> 0;
150
+ const obj = Object.create(Index.prototype);
151
+ obj.__wbg_ptr = ptr;
152
+ IndexFinalization.register(obj, obj.__wbg_ptr, obj);
153
+ return obj;
154
+ }
155
+
156
+ __destroy_into_raw() {
157
+ const ptr = this.__wbg_ptr;
158
+ this.__wbg_ptr = 0;
159
+ IndexFinalization.unregister(this);
160
+ return ptr;
161
+ }
162
+
163
+ free() {
164
+ const ptr = this.__destroy_into_raw();
165
+ wasm.__wbg_index_free(ptr, 0);
166
+ }
167
+ /**
168
+ * @param {Uint8Array} buf
169
+ * @returns {Index}
170
+ */
171
+ static read(buf) {
172
+ try {
173
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
174
+ const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_export_0);
175
+ const len0 = WASM_VECTOR_LEN;
176
+ wasm.index_read(retptr, ptr0, len0);
177
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
178
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
179
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
180
+ if (r2) {
181
+ throw takeObject(r1);
182
+ }
183
+ return Index.__wrap(r0);
184
+ } finally {
185
+ wasm.__wbindgen_add_to_stack_pointer(16);
186
+ }
187
+ }
188
+ /**
189
+ * @param {string} query
190
+ * @param {number} max_results
191
+ * @returns {(string)[]}
192
+ */
193
+ search(query, max_results) {
194
+ try {
195
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
196
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
197
+ const len0 = WASM_VECTOR_LEN;
198
+ wasm.index_search(retptr, this.__wbg_ptr, ptr0, len0, max_results);
199
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
200
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
201
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
202
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
203
+ if (r3) {
204
+ throw takeObject(r2);
205
+ }
206
+ var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
207
+ wasm.__wbindgen_export_2(r0, r1 * 4, 4);
208
+ return v2;
209
+ } finally {
210
+ wasm.__wbindgen_add_to_stack_pointer(16);
211
+ }
212
+ }
213
+ }
214
+
215
+ async function __wbg_load(module, imports) {
216
+ if (typeof Response === 'function' && module instanceof Response) {
217
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
218
+ try {
219
+ return await WebAssembly.instantiateStreaming(module, imports);
220
+
221
+ } catch (e) {
222
+ if (module.headers.get('Content-Type') != 'application/wasm') {
223
+ 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);
224
+
225
+ } else {
226
+ throw e;
227
+ }
228
+ }
229
+ }
230
+
231
+ const bytes = await module.arrayBuffer();
232
+ return await WebAssembly.instantiate(bytes, imports);
233
+
234
+ } else {
235
+ const instance = await WebAssembly.instantiate(module, imports);
236
+
237
+ if (instance instanceof WebAssembly.Instance) {
238
+ return { instance, module };
239
+
240
+ } else {
241
+ return instance;
242
+ }
243
+ }
244
+ }
245
+
246
+ function __wbg_get_imports() {
247
+ const imports = {};
248
+ imports.wbg = {};
249
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
250
+ const ret = getStringFromWasm0(arg0, arg1);
251
+ return addHeapObject(ret);
252
+ };
253
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
254
+ throw new Error(getStringFromWasm0(arg0, arg1));
255
+ };
256
+
257
+ return imports;
258
+ }
259
+
260
+ function __wbg_init_memory(imports, memory) {
261
+
262
+ }
263
+
264
+ function __wbg_finalize_init(instance, module) {
265
+ wasm = instance.exports;
266
+ __wbg_init.__wbindgen_wasm_module = module;
267
+ cachedDataViewMemory0 = null;
268
+ cachedUint8ArrayMemory0 = null;
269
+
270
+
271
+
272
+ return wasm;
273
+ }
274
+
275
+ function initSync(module) {
276
+ if (wasm !== undefined) return wasm;
277
+
278
+
279
+ if (typeof module !== 'undefined') {
280
+ if (Object.getPrototypeOf(module) === Object.prototype) {
281
+ ({module} = module)
282
+ } else {
283
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
284
+ }
285
+ }
286
+
287
+ const imports = __wbg_get_imports();
288
+
289
+ __wbg_init_memory(imports);
290
+
291
+ if (!(module instanceof WebAssembly.Module)) {
292
+ module = new WebAssembly.Module(module);
293
+ }
294
+
295
+ const instance = new WebAssembly.Instance(module, imports);
296
+
297
+ return __wbg_finalize_init(instance, module);
298
+ }
299
+
300
+ async function __wbg_init(module_or_path) {
301
+ if (wasm !== undefined) return wasm;
302
+
303
+
304
+ if (typeof module_or_path !== 'undefined') {
305
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
306
+ ({module_or_path} = module_or_path)
307
+ } else {
308
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
309
+ }
310
+ }
311
+
312
+ if (typeof module_or_path === 'undefined') {
313
+ module_or_path = new URL('fixx_bg.wasm', import.meta.url);
314
+ }
315
+ const imports = __wbg_get_imports();
316
+
317
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
318
+ module_or_path = fetch(module_or_path);
319
+ }
320
+
321
+ __wbg_init_memory(imports);
322
+
323
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
324
+
325
+ return __wbg_finalize_init(instance, module);
326
+ }
327
+
328
+ export { initSync };
329
+ export default __wbg_init;
package/fixx_bg.wasm ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@nuschtos/fixx",
3
+ "type": "module",
4
+ "version": "0.0.2",
5
+ "license": "MIT OR Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/NuschtOS/ixx/"
9
+ },
10
+ "files": [
11
+ "fixx_bg.wasm",
12
+ "fixx.js",
13
+ "fixx.d.ts"
14
+ ],
15
+ "main": "fixx.js",
16
+ "types": "fixx.d.ts",
17
+ "sideEffects": [
18
+ "./snippets/*"
19
+ ]
20
+ }