genome 1.0.1 → 1.0.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/LICENSE CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,286 +1,97 @@
1
1
  ![NPM Version](https://img.shields.io/npm/v/genome?style=flat-square&color=%23e8b339)
2
- ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/overthemike/genome/test.yml?style=flat-square&color=%23e8b339)
2
+ ![Crates.io Version](https://img.shields.io/crates/v/genome-rs?style=flat-square&color=%23e8b339)
3
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/overthemike/genome/ci.yml?style=flat-square&color=%23e8b339)
3
4
  ![npm bundle size](https://img.shields.io/bundlephobia/minzip/genome?style=flat-square&color=%23e8b339)
4
5
  ![NPM License](https://img.shields.io/npm/l/genome?style=flat-square&color=%23e8b339)
6
+ # `genome`
5
7
 
8
+ Deterministic structural hashing for JSON values. Generates hierarchical
9
+ IDs that capture the shape of an object — same structure, same ID,
10
+ regardless of values.
6
11
 
7
- # genome
8
-
9
- A lightweight, robust library for generating unique identifiers for JavaScript/TypeScript objects based on their structure rather than requiring explicit string keys.
10
-
11
- ## Purpose
12
-
13
- This library provides a solution for scenarios where you need to:
14
-
15
- - Persist and rehydrate state without requiring explicit string keys
16
- - Identify structurally identical objects across different instances
17
- - Match objects by their shape rather than by identity or manual keys
18
- - Detect circular references safely
19
-
20
- ## Installation
12
+ ## Install
21
13
 
14
+ **[npm (WASM) ↗](https://www.npmjs.com/package/genome)**
22
15
  ```bash
23
- pnpm add genome
24
- ```
25
-
26
- ## Basic Usage
27
- ```typescript
28
- import { generateStructureId, getCompactId } from 'genome';
29
-
30
- // Example object
31
- const user = {
32
- name: 'John',
33
- age: 30,
34
- preferences: {
35
- theme: 'dark',
36
- notifications: true
37
- }
38
- }
39
-
40
- // Generate a unique ID based on the object structure and it's properties' types
41
- const id = generateStructureId(user) // L0:3713-L1:5761-L2:13827
42
-
43
- // Generate a unique ID and then hash that value
44
- const hashed = getCompactId(user) // cd76ea96
45
-
46
- // Get info on what a structure would be without generating
47
- const {
48
- id, // L0:541598767187353870402585606-L1:1547425049106725343623905933-L2:10
49
- levels, // 3
50
- collisions // 0 ID collisions - same object structure already ran through generator
51
- } = getStructureInfo(user)
52
-
53
- // Get info for a compact id
54
- const {
55
- id, // cd76ea96
56
- levels, // 3
57
- collisions // 0 ID collisions - same object structure already ran through generator
58
- } = getCompactInfo(user)
59
-
60
- // get all of the data being stored about the state - debugging info
61
- const allStructureStateData = exportStructureState()
16
+ npm install genome
62
17
  ```
63
18
 
64
- ## API Reference
65
-
66
- ### `generateStructureId(obj: Record<string, any>, config?: StructureIdConfig): string`
67
-
68
- Generates a unique ID string based on the structure of the provided object.
69
-
70
- - **Parameters**:
71
- - `obj`: The object to generate an ID for.
72
- - `config` (optional): Configuration options for ID generation.
73
- - **Returns**: A string representing the structure ID.
74
-
75
- ### `getStructureInfo(obj: Record<string, any>, config?: StructureIdConfig): { id: string; levels: number; collisionCount: number; }`
76
-
77
- Provides additional information about the object's structure.
78
-
79
- - **Parameters**:
80
- - `obj`: The object to analyze.
81
- - `config` (optional): Configuration options for ID generation.
82
- - **Returns**: An object containing:
83
- - `id`: The structure ID.
84
- - `levels`: The number of nesting levels in the object.
85
- - `collisionCount`: The number of times this structure has been encountered.
86
-
87
- ### `setStructureIdConfig(config: StructureIdConfig): void`
88
-
89
- Sets global configuration options for structure ID generation.
90
-
91
- - **Parameters**:
92
- - `config`: The configuration object.
93
-
94
- ### `getStructureIdConfig(): StructureIdConfig`
95
-
96
- Gets the current global configuration.
97
-
98
- - **Returns**: A copy of the current global configuration object.
99
-
100
- ### `resetState(): void`
101
-
102
- Resets the internal state of the library, clearing all cached property mappings.
103
-
104
- **Note**: You typically don't need to call this unless you want to start fresh with property-to-bit mappings.
105
-
106
- ### Configuration Options
107
-
108
- The `StructureIdConfig` object supports the following options:
109
-
110
- ```typescript
111
- interface StructureIdConfig {
112
- newIdOnCollision?: boolean;
113
- }
19
+ **[Rust ↗](https://crates.io/crates/genome-rs)**
20
+ ```toml
21
+ [dependencies]
22
+ genome = "1.0.0"
114
23
  ```
115
24
 
116
- #### `newIdOnCollision` (default: `false`)
25
+ ## Usage
117
26
 
118
- When set to `true`, each object with the same structure will receive a unique ID. This is useful when you need to distinguish between different object instances that share the same structure.
119
-
120
- ```typescript
121
- // Generate a unique ID for each object, even with the same structure
122
- const config = { newIdOnCollision: true };
27
+ **TypeScript / JavaScript**
28
+ ```ts
29
+ import init, { hash, signature, compare, compareValues, setConfig, reset } from 'genome'
123
30
 
124
- const obj1 = { name: "John", age: 30 };
125
- const obj2 = { name: "Alice", age: 25 };
31
+ // `init()` loads and compiles the WASM binary — call it once before using any other functions.
32
+ await init()
126
33
 
127
- const id1 = generateStructureId(obj1, config);
128
- const id2 = generateStructureId(obj2, config);
34
+ const id = hash(JSON.stringify({ id: 1, name: "alice" }))
35
+ const score = compare(id1, id2)
129
36
 
130
- console.log(id1); // "L0:0-L1:5"
131
- console.log(id2); // "L0:1-L1:5"
132
- console.log(id1 === id2); // false (even though structure is identical)
37
+ // setConfig(newIdOnCollision, ignoreArrayLength, ignoreValueTypes)
38
+ setConfig(false, true, false)
133
39
  ```
134
40
 
135
- You can set this option globally or per call:
41
+ **Rust**
42
+ ```rust
43
+ use genome::{Genome, GenomeConfig};
44
+ use serde_json::json;
136
45
 
137
- ```typescript
138
- // Set globally
139
- setStructureIdConfig({ newIdOnCollision: true });
46
+ let mut g = Genome::new(GenomeConfig::default());
140
47
 
141
- // Will use global config
142
- const id1 = generateStructureId(obj1);
143
- const id2 = generateStructureId(obj2);
48
+ let id1 = g.hash(&json!({ "id": 1, "name": "alice" }));
49
+ let id2 = g.hash(&json!({ "id": 2, "name": "bob" }));
144
50
 
145
- // Override for a specific call
146
- const id3 = generateStructureId(obj3, { newIdOnCollision: false });
51
+ assert_eq!(id1, id2); // same structure
147
52
  ```
148
53
 
149
- ## When to use `genome`
150
-
151
- The `genome` library shines in scenarios where you need to identify and match objects based on their structure rather than explicit keys or instance identity. Here are some ideal use cases:
152
-
153
- ### State Management Without Explicit Keys
54
+ ## Config
154
55
 
155
- When persisting and rehydrating application state, you often need a way to match stored state with the corresponding objects in your application. Instead of manually maintaining string keys for every object, `genome` automatically generates consistent identifiers based on object structure.
56
+ | Option | Type | Default | Description |
57
+ |--------|------|---------|-------------|
58
+ | `newIdOnCollision` | bool | false | Give structurally identical values distinct IDs |
59
+ | `ignoreArrayLength` | bool | false | Treat arrays with different lengths but same element shapes as equivalent |
60
+ | `ignoreValueTypes` | bool | false | Treat all scalar types as equivalent — only key names and depth matter |
156
61
 
157
- ```ts
158
- // Instead of this:
159
- const componentKey = "user-preferences-panel";
160
- storeState(componentKey, preferences);
161
- // Later:
162
- const savedState = getState(componentKey);
163
-
164
- // You can do this:
165
- const structureId = generateStructureId(preferences);
166
- storeState(structureId, preferences);
167
- // Later:
168
- const savedState = getState(generateStructureId(preferences));
169
- ```
62
+ ## API
170
63
 
171
- ### Memoization and Caching
64
+ ### `hash(json)`
65
+ Accepts a JSON string. Use `JSON.stringify()` before passing.
172
66
 
173
- When implementing memoization patterns, you can use structure-based IDs to cache results based on input structure rather than identity:
67
+ ### `signature(value)`
68
+ Returns the structural fingerprint. In default mode returns the full ID.
69
+ When `newIdOnCollision` is true, strips L0 and returns L1+ only.
174
70
 
175
- ```ts
176
- const memoizedResults = new Map<string, any>();
177
-
178
- function expensiveCalculation(data: SomeComplexObject) {
179
- const structureId = generateStructureId(data);
180
-
181
- if (memoizedResults.has(structureId)) {
182
- return memoizedResults.get(structureId);
183
- }
184
-
185
- const result = /* complex calculation */;
186
- memoizedResults.set(structureId, result);
187
- return result;
188
- }
189
- ```
190
-
191
- ### Normalizing Data for Storage
192
-
193
- When storing objects in databases or state management systems, you can use structural IDs to create consistent references:
194
-
195
- ```ts
196
- function normalizeForStorage(entities: Record<string, unknown>[]) {
197
- const normalizedEntities: Record<string, any> = {};
198
-
199
- for (const entity of entities) {
200
- const id = generateStructureId(entity);
201
- normalizedEntities[id] = entity;
202
- }
203
-
204
- return normalizedEntities;
205
- }
206
- ```
71
+ ### `compare(idA, idB) → number`
72
+ Compares two structure IDs and returns a similarity score from 0.0 to 1.0.
207
73
 
208
- ### Change detection
74
+ ### `compareValues(a, b)`
75
+ Compares two JSON strings structurally.
209
76
 
210
- Detect changes in object structure without relying on reference equality:
77
+ ### `seed(sig, count)`
78
+ Seeds the collision counter for a known signature. Useful for restoring persisted state.
211
79
 
212
- ```ts
213
- function hasStructuralChanges(oldObj: object, newObj: object): boolean {
214
- return generateStructureId(oldObj) !== generateStructureId(newObj);
215
- }
216
- ```
80
+ ### `reset()`
81
+ Clears all internal state.
217
82
 
218
- ### Object Deduplication
83
+ ## How it works
219
84
 
220
- Efficiently identify and remove duplicate objects with identical structures:
85
+ genome builds a hierarchical hash where each level (`L0`, `L1`, `L2`...)
86
+ represents a depth in the object tree. Two objects with the same keys,
87
+ same nesting structure, and same value types will always produce the same ID
88
+ regardless of the actual values stored.
221
89
 
222
- ```ts
223
- function deduplicateByStructure<T>(objects: T[]): T[] {
224
- const uniqueStructures = new Map<string, T>();
225
-
226
- for (const obj of objects) {
227
- const id = generateStructureId(obj as Record<string, unknown>);
228
- if (!uniqueStructures.has(id)) {
229
- uniqueStructures.set(id, obj);
230
- }
231
- }
232
-
233
- return Array.from(uniqueStructures.values());
234
- }
235
90
  ```
236
-
237
- ### Unique Per-Instance IDs
238
-
239
- When you need to uniquely identify each object instance, even if they share the same structure, you can use the `newIdOnCollision` option:
240
-
241
- ```ts
242
- function assignUniqueIds<T>(objects: T[]): Map<T, string> {
243
- const idMap = new Map<T, string>();
244
- const config = { newIdOnCollision: true };
245
-
246
- for (const obj of objects) {
247
- const id = generateStructureId(obj as Record<string, unknown>, config);
248
- idMap.set(obj, id);
249
- }
250
-
251
- return idMap;
252
- }
91
+ { id: 1, name: "alice", address: { city: "NYC" } }
92
+ └── L0: root level (keys: id, name, address + their types)
93
+ └── L1: depth 1 (keys inside address: city + its type)
253
94
  ```
254
- ### Benefits Over Manual Key Management
255
-
256
- - Automatic: No need to manually specify and maintain string keys
257
- - Consistent: Same structure always generates the same ID
258
- - Structural: Changes to object structure are automatically reflected in the ID
259
- - Safe: Handles circular references without issues
260
- - Deterministic: Property order doesn't affect the generated ID
261
-
262
- ## How It Works
263
-
264
- The library uses a bit-wise approach to generate structure IDs:
265
-
266
- 1. Each JavaScript type gets a unique bit value (`number`, `string`, `object`, etc.)
267
- 2. Each property name gets a unique bit value the first time it's encountered
268
- 3. These bit values are consistently used for the same types and property names
269
- 4. The object is traversed, and hash values are calculated for each level of nesting
270
- 5. The final ID is formed by combining these level hashes
271
-
272
- This approach ensures:
273
- - Identical structures get identical IDs
274
- - Different structures get different IDs
275
- - The algorithm works correctly with circular references
276
- - Property order doesn't affect the generated ID
277
-
278
- ## Performance Considerations
279
-
280
- - The library maintains a global mapping of property names to bit values, which grows as more unique property names are encountered
281
- - For very large or complex objects, the bit values might become quite large (using BigInt internally)
282
- - Circular references are handled efficiently without stack overflows
283
95
 
284
96
  ## License
285
-
286
- MIT
97
+ MIT
package/genome.js ADDED
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./genome.d.ts" */
2
+
3
+ import * as wasm from "./genome_bg.wasm";
4
+ import { __wbg_set_wasm } from "./genome_bg.js";
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ compare, compareValues, hash, hashStr, reset, seed, setConfig, signature
9
+ } from "./genome_bg.js";
@@ -0,0 +1,288 @@
1
+ /**
2
+ * Compares two structure ID strings and returns a similarity score
3
+ * between 0.0 (completely different) and 1.0 (identical).
4
+ *
5
+ * ```js
6
+ * import { compare } from 'genome'
7
+ * const score = compare("L0:100-L1:200", "L0:100-L1:200") // 1.0
8
+ * ```
9
+ * @param {string} id_a
10
+ * @param {string} id_b
11
+ * @returns {number}
12
+ */
13
+ export function compare(id_a, id_b) {
14
+ const ptr0 = passStringToWasm0(id_a, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
15
+ const len0 = WASM_VECTOR_LEN;
16
+ const ptr1 = passStringToWasm0(id_b, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
17
+ const len1 = WASM_VECTOR_LEN;
18
+ const ret = wasm.compare(ptr0, len0, ptr1, len1);
19
+ return ret;
20
+ }
21
+
22
+ /**
23
+ * Compares two JSON strings structurally and returns a similarity score.
24
+ *
25
+ * ```js
26
+ * import { compareValues } from 'genome'
27
+ * const score = compareValues(
28
+ * JSON.stringify({ id: 1, name: "alice" }),
29
+ * JSON.stringify({ id: 2, name: "bob" }),
30
+ * ) // 1.0 — same structure
31
+ * ```
32
+ * @param {string} a
33
+ * @param {string} b
34
+ * @returns {number}
35
+ */
36
+ export function compareValues(a, b) {
37
+ const ptr0 = passStringToWasm0(a, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
38
+ const len0 = WASM_VECTOR_LEN;
39
+ const ptr1 = passStringToWasm0(b, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
40
+ const len1 = WASM_VECTOR_LEN;
41
+ const ret = wasm.compareValues(ptr0, len0, ptr1, len1);
42
+ if (ret[2]) {
43
+ throw takeFromExternrefTable0(ret[1]);
44
+ }
45
+ return ret[0];
46
+ }
47
+
48
+ /**
49
+ * Generates a deterministic hierarchical structure ID for a JSON string.
50
+ *
51
+ * ```js
52
+ * import { hash } from 'genome'
53
+ * const id = hash(JSON.stringify({ id: 1, name: "alice" }))
54
+ * ```
55
+ * @param {string} json
56
+ * @returns {string}
57
+ */
58
+ export function hash(json) {
59
+ let deferred3_0;
60
+ let deferred3_1;
61
+ try {
62
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
63
+ const len0 = WASM_VECTOR_LEN;
64
+ const ret = wasm.hash(ptr0, len0);
65
+ var ptr2 = ret[0];
66
+ var len2 = ret[1];
67
+ if (ret[3]) {
68
+ ptr2 = 0; len2 = 0;
69
+ throw takeFromExternrefTable0(ret[2]);
70
+ }
71
+ deferred3_0 = ptr2;
72
+ deferred3_1 = len2;
73
+ return getStringFromWasm0(ptr2, len2);
74
+ } finally {
75
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Hashes a string with xxHash32 and returns a hex string.
81
+ *
82
+ * ```js
83
+ * import { hashStr } from 'genome'
84
+ * const hex = hashStr("hello", 0)
85
+ * ```
86
+ * @param {string} input
87
+ * @param {number} seed
88
+ * @returns {string}
89
+ */
90
+ export function hashStr(input, seed) {
91
+ let deferred2_0;
92
+ let deferred2_1;
93
+ try {
94
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
95
+ const len0 = WASM_VECTOR_LEN;
96
+ const ret = wasm.hashStr(ptr0, len0, seed);
97
+ deferred2_0 = ret[0];
98
+ deferred2_1 = ret[1];
99
+ return getStringFromWasm0(ret[0], ret[1]);
100
+ } finally {
101
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Resets all internal state — clears the key cache and collision counters.
107
+ *
108
+ * ```js
109
+ * import { reset } from 'genome'
110
+ * reset()
111
+ * ```
112
+ */
113
+ export function reset() {
114
+ wasm.reset();
115
+ }
116
+
117
+ /**
118
+ * Seeds the collision counter for a known signature.
119
+ * Use this to restore persisted counter state.
120
+ *
121
+ * ```js
122
+ * import { seed } from 'genome'
123
+ * seed("L1:12345-L2:67890", 3n)
124
+ * ```
125
+ * @param {string} signature
126
+ * @param {bigint} count
127
+ */
128
+ export function seed(signature, count) {
129
+ const ptr0 = passStringToWasm0(signature, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
130
+ const len0 = WASM_VECTOR_LEN;
131
+ wasm.seed(ptr0, len0, count);
132
+ }
133
+
134
+ /**
135
+ * Sets the global config. Call this before using any other functions
136
+ * if you need non-default behaviour.
137
+ *
138
+ * ```js
139
+ * import { setConfig, hash } from 'genome'
140
+ *
141
+ * setConfig({ ignoreArrayLength: true, ignoreValueTypes: true })
142
+ * const id = hash(JSON.stringify({ items: [1, 2, 3] }))
143
+ * ```
144
+ * @param {boolean} new_id_on_collision
145
+ * @param {boolean} ignore_array_length
146
+ * @param {boolean} ignore_value_types
147
+ */
148
+ export function setConfig(new_id_on_collision, ignore_array_length, ignore_value_types) {
149
+ wasm.setConfig(new_id_on_collision, ignore_array_length, ignore_value_types);
150
+ }
151
+
152
+ /**
153
+ * Returns the structural signature for a JSON string.
154
+ *
155
+ * In default mode returns the full ID. When `newIdOnCollision` is true
156
+ * (set via `setConfig`), strips L0 and returns L1+ only.
157
+ *
158
+ * ```js
159
+ * import { signature } from 'genome'
160
+ * const sig = signature(JSON.stringify({ id: 1, name: "alice" }))
161
+ * ```
162
+ * @param {string} json
163
+ * @returns {string}
164
+ */
165
+ export function signature(json) {
166
+ let deferred3_0;
167
+ let deferred3_1;
168
+ try {
169
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
170
+ const len0 = WASM_VECTOR_LEN;
171
+ const ret = wasm.signature(ptr0, len0);
172
+ var ptr2 = ret[0];
173
+ var len2 = ret[1];
174
+ if (ret[3]) {
175
+ ptr2 = 0; len2 = 0;
176
+ throw takeFromExternrefTable0(ret[2]);
177
+ }
178
+ deferred3_0 = ptr2;
179
+ deferred3_1 = len2;
180
+ return getStringFromWasm0(ptr2, len2);
181
+ } finally {
182
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
183
+ }
184
+ }
185
+ export function __wbindgen_cast_0000000000000001(arg0, arg1) {
186
+ // Cast intrinsic for `Ref(String) -> Externref`.
187
+ const ret = getStringFromWasm0(arg0, arg1);
188
+ return ret;
189
+ }
190
+ export function __wbindgen_init_externref_table() {
191
+ const table = wasm.__wbindgen_externrefs;
192
+ const offset = table.grow(4);
193
+ table.set(0, undefined);
194
+ table.set(offset + 0, undefined);
195
+ table.set(offset + 1, null);
196
+ table.set(offset + 2, true);
197
+ table.set(offset + 3, false);
198
+ }
199
+ function getStringFromWasm0(ptr, len) {
200
+ ptr = ptr >>> 0;
201
+ return decodeText(ptr, len);
202
+ }
203
+
204
+ let cachedUint8ArrayMemory0 = null;
205
+ function getUint8ArrayMemory0() {
206
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
207
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
208
+ }
209
+ return cachedUint8ArrayMemory0;
210
+ }
211
+
212
+ function passStringToWasm0(arg, malloc, realloc) {
213
+ if (realloc === undefined) {
214
+ const buf = cachedTextEncoder.encode(arg);
215
+ const ptr = malloc(buf.length, 1) >>> 0;
216
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
217
+ WASM_VECTOR_LEN = buf.length;
218
+ return ptr;
219
+ }
220
+
221
+ let len = arg.length;
222
+ let ptr = malloc(len, 1) >>> 0;
223
+
224
+ const mem = getUint8ArrayMemory0();
225
+
226
+ let offset = 0;
227
+
228
+ for (; offset < len; offset++) {
229
+ const code = arg.charCodeAt(offset);
230
+ if (code > 0x7F) break;
231
+ mem[ptr + offset] = code;
232
+ }
233
+ if (offset !== len) {
234
+ if (offset !== 0) {
235
+ arg = arg.slice(offset);
236
+ }
237
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
238
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
239
+ const ret = cachedTextEncoder.encodeInto(arg, view);
240
+
241
+ offset += ret.written;
242
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
243
+ }
244
+
245
+ WASM_VECTOR_LEN = offset;
246
+ return ptr;
247
+ }
248
+
249
+ function takeFromExternrefTable0(idx) {
250
+ const value = wasm.__wbindgen_externrefs.get(idx);
251
+ wasm.__externref_table_dealloc(idx);
252
+ return value;
253
+ }
254
+
255
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
256
+ cachedTextDecoder.decode();
257
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
258
+ let numBytesDecoded = 0;
259
+ function decodeText(ptr, len) {
260
+ numBytesDecoded += len;
261
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
262
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
263
+ cachedTextDecoder.decode();
264
+ numBytesDecoded = len;
265
+ }
266
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
267
+ }
268
+
269
+ const cachedTextEncoder = new TextEncoder();
270
+
271
+ if (!('encodeInto' in cachedTextEncoder)) {
272
+ cachedTextEncoder.encodeInto = function (arg, view) {
273
+ const buf = cachedTextEncoder.encode(arg);
274
+ view.set(buf);
275
+ return {
276
+ read: arg.length,
277
+ written: buf.length
278
+ };
279
+ };
280
+ }
281
+
282
+ let WASM_VECTOR_LEN = 0;
283
+
284
+
285
+ let wasm;
286
+ export function __wbg_set_wasm(val) {
287
+ wasm = val;
288
+ }