@sanity-labs/groq-wasm 0.2.0 → 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.
@@ -1,3 +1,41 @@
1
+ // src/types.ts
2
+ function mapSeverity(wasmSeverity) {
3
+ switch (wasmSeverity) {
4
+ case "high":
5
+ return "error";
6
+ case "medium":
7
+ return "warning";
8
+ case "low":
9
+ return "info";
10
+ }
11
+ }
12
+ var WasmError = class extends Error {
13
+ constructor(message, code) {
14
+ super(message);
15
+ this.code = code;
16
+ this.name = "WasmError";
17
+ }
18
+ code;
19
+ };
20
+ var RULE_ID_MAP = {
21
+ join_in_filter: "join-in-filter",
22
+ join_to_get_id: "join-to-get-id",
23
+ computed_value_in_filter: "computed-value-in-filter",
24
+ match_on_id: "match-on-id",
25
+ order_on_expr: "order-on-expr",
26
+ deep_pagination: "deep-pagination",
27
+ large_pages: "large-pages",
28
+ non_literal_comparison: "non-literal-comparison",
29
+ repeated_dereference: "repeated-dereference",
30
+ count_in_correlated_subquery: "count-in-correlated-subquery",
31
+ very_large_query: "very-large-query",
32
+ extremely_large_query: "extremely-large-query",
33
+ many_joins: "many-joins"
34
+ };
35
+ function mapRuleId(rustRuleId) {
36
+ return RULE_ID_MAP[rustRuleId] ?? rustRuleId.replace(/_/g, "-");
37
+ }
38
+
1
39
  // wasm/groq_wasm.js
2
40
  function format(query, width) {
3
41
  let deferred3_0;
@@ -20,9 +58,6 @@ function format(query, width) {
20
58
  wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
21
59
  }
22
60
  }
23
- function init() {
24
- wasm.init();
25
- }
26
61
  function lint(query) {
27
62
  let deferred3_0;
28
63
  let deferred3_1;
@@ -179,40 +214,6 @@ function __wbg_finalize_init(instance, module) {
179
214
  wasm.__wbindgen_start();
180
215
  return wasm;
181
216
  }
182
- async function __wbg_load(module, imports) {
183
- if (typeof Response === "function" && module instanceof Response) {
184
- if (typeof WebAssembly.instantiateStreaming === "function") {
185
- try {
186
- return await WebAssembly.instantiateStreaming(module, imports);
187
- } catch (e) {
188
- const validResponse = module.ok && expectedResponseType(module.type);
189
- if (validResponse && module.headers.get("Content-Type") !== "application/wasm") {
190
- 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);
191
- } else {
192
- throw e;
193
- }
194
- }
195
- }
196
- const bytes = await module.arrayBuffer();
197
- return await WebAssembly.instantiate(bytes, imports);
198
- } else {
199
- const instance = await WebAssembly.instantiate(module, imports);
200
- if (instance instanceof WebAssembly.Instance) {
201
- return { instance, module };
202
- } else {
203
- return instance;
204
- }
205
- }
206
- function expectedResponseType(type) {
207
- switch (type) {
208
- case "basic":
209
- case "cors":
210
- case "default":
211
- return true;
212
- }
213
- return false;
214
- }
215
- }
216
217
  function initSync(module) {
217
218
  if (wasm !== void 0) return wasm;
218
219
  if (module !== void 0) {
@@ -229,30 +230,124 @@ function initSync(module) {
229
230
  const instance = new WebAssembly.Instance(module, imports);
230
231
  return __wbg_finalize_init(instance, module);
231
232
  }
232
- async function __wbg_init(module_or_path) {
233
- if (wasm !== void 0) return wasm;
234
- if (module_or_path !== void 0) {
235
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
236
- ({ module_or_path } = module_or_path);
233
+
234
+ // src/wasm-loader.ts
235
+ function initWasm(bytes) {
236
+ try {
237
+ initSync({ module: bytes });
238
+ } catch (error) {
239
+ throw new WasmError(
240
+ `Failed to initialize WASM: ${error instanceof Error ? error.message : String(error)}`,
241
+ "WASM_ERROR"
242
+ );
243
+ }
244
+ }
245
+ function callLint(query) {
246
+ return lint(query);
247
+ }
248
+ function callFormat(query, width) {
249
+ return format(query, width ?? null);
250
+ }
251
+
252
+ // src/lint.ts
253
+ function lint2(query, config) {
254
+ if (!query.trim()) {
255
+ return [];
256
+ }
257
+ try {
258
+ const resultJson = callLint(query);
259
+ const wasmFindings = JSON.parse(resultJson);
260
+ let findings = wasmFindings;
261
+ if (config?.rules) {
262
+ const rules = config.rules;
263
+ findings = findings.filter((f) => {
264
+ const enabled = rules[f.ruleId];
265
+ return enabled !== false;
266
+ });
267
+ }
268
+ return findings.map((wf) => convertFinding(wf, query));
269
+ } catch (error) {
270
+ if (error instanceof WasmError) {
271
+ throw error;
272
+ }
273
+ const message = error instanceof Error ? error.message : String(error);
274
+ if (message.includes("parse") || message.includes("Parse")) {
275
+ throw new WasmError(`Failed to parse query: ${message}`, "PARSE_ERROR");
276
+ }
277
+ throw new WasmError(`Lint failed: ${message}`, "WASM_ERROR");
278
+ }
279
+ }
280
+ function convertFinding(wf, query) {
281
+ return {
282
+ ruleId: mapRuleId(wf.ruleId),
283
+ message: wf.message,
284
+ severity: mapSeverity(wf.severity),
285
+ span: byteSpanToSourceSpan(wf.start, wf.end, query)
286
+ };
287
+ }
288
+ function byteSpanToSourceSpan(startByte, endByte, query) {
289
+ return {
290
+ start: byteOffsetToLocation(startByte, query),
291
+ end: byteOffsetToLocation(endByte, query)
292
+ };
293
+ }
294
+ function byteOffsetToLocation(offset, query) {
295
+ let line = 1;
296
+ let column = 1;
297
+ let currentOffset = 0;
298
+ for (const char of query) {
299
+ if (currentOffset >= offset) {
300
+ break;
301
+ }
302
+ if (char === "\n") {
303
+ line++;
304
+ column = 1;
237
305
  } else {
238
- console.warn("using deprecated parameters for the initialization function; pass a single object instead");
306
+ column++;
239
307
  }
308
+ currentOffset++;
240
309
  }
241
- if (module_or_path === void 0) {
242
- module_or_path = new URL("groq_wasm_bg.wasm", import.meta.url);
310
+ return { line, column, offset };
311
+ }
312
+
313
+ // src/format.ts
314
+ var DEFAULT_WIDTH = 80;
315
+ function format2(query, config) {
316
+ const width = config?.width ?? DEFAULT_WIDTH;
317
+ if (!query.trim()) {
318
+ return query;
243
319
  }
244
- const imports = __wbg_get_imports();
245
- if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
246
- module_or_path = fetch(module_or_path);
320
+ try {
321
+ return callFormat(query, width);
322
+ } catch (error) {
323
+ const message = error instanceof Error ? error.message : String(error);
324
+ if (message.includes("parse") || message.includes("Parse")) {
325
+ throw new WasmError(`Failed to parse query: ${message}`, "PARSE_ERROR");
326
+ }
327
+ throw new WasmError(`Format failed: ${message}`, "WASM_ERROR");
328
+ }
329
+ }
330
+ function isValidSyntax(query) {
331
+ try {
332
+ format2(query);
333
+ return true;
334
+ } catch (error) {
335
+ if (error instanceof WasmError && error.code === "PARSE_ERROR") {
336
+ return false;
337
+ }
338
+ throw error;
247
339
  }
248
- const { instance, module } = await __wbg_load(await module_or_path, imports);
249
- return __wbg_finalize_init(instance, module);
250
340
  }
341
+
251
342
  export {
252
- __wbg_init as default,
253
- format,
254
- init,
255
- initSync,
256
- lint
343
+ mapSeverity,
344
+ WasmError,
345
+ RULE_ID_MAP,
346
+ mapRuleId,
347
+ initWasm,
348
+ lint2 as lint,
349
+ DEFAULT_WIDTH,
350
+ format2 as format,
351
+ isValidSyntax
257
352
  };
258
- //# sourceMappingURL=groq_wasm-Z3ZUBGZA.js.map
353
+ //# sourceMappingURL=chunk-2DNVGC7B.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts","../wasm/groq_wasm.js","../src/wasm-loader.ts","../src/lint.ts","../src/format.ts"],"sourcesContent":["/**\n * Types for @sanity-labs/groq-wasm\n *\n * These types match the Rust API from groq-lint and groq-format,\n * converted to TypeScript conventions (snake_case → camelCase).\n */\n\n/**\n * Severity levels matching Rust groq-lint\n * Rust: High, Medium, Low → TS: error, warning, info\n */\nexport type WasmSeverity = 'high' | 'medium' | 'low'\n\n/**\n * Map WASM severity to our standard severity\n */\nexport function mapSeverity(wasmSeverity: WasmSeverity): 'error' | 'warning' | 'info' {\n switch (wasmSeverity) {\n case 'high':\n return 'error'\n case 'medium':\n return 'warning'\n case 'low':\n return 'info'\n }\n}\n\n/**\n * A finding from the Rust linter (JSON format from WASM)\n */\nexport interface WasmFinding {\n /** Rule ID (snake_case from Rust) */\n ruleId: string\n /** Human-readable message */\n message: string\n /** Severity level */\n severity: WasmSeverity\n /** Start byte offset (0-based) */\n start: number\n /** End byte offset (0-based) */\n end: number\n}\n\n/**\n * Configuration for linting\n */\nexport interface WasmLintConfig {\n /** Rules to enable/disable (rule_id → enabled) */\n rules?: Record<string, boolean>\n}\n\n/**\n * Configuration for formatting\n */\nexport interface WasmFormatConfig {\n /** Maximum line width (default: 80) */\n width?: number\n}\n\n/**\n * Error from WASM operations\n */\nexport class WasmError extends Error {\n constructor(\n message: string,\n public readonly code: 'PARSE_ERROR' | 'WASM_ERROR'\n ) {\n super(message)\n this.name = 'WasmError'\n }\n}\n\n/**\n * Rule ID mapping from Rust (snake_case) to TS (kebab-case)\n */\nexport const RULE_ID_MAP: Record<string, string> = {\n join_in_filter: 'join-in-filter',\n join_to_get_id: 'join-to-get-id',\n computed_value_in_filter: 'computed-value-in-filter',\n match_on_id: 'match-on-id',\n order_on_expr: 'order-on-expr',\n deep_pagination: 'deep-pagination',\n large_pages: 'large-pages',\n non_literal_comparison: 'non-literal-comparison',\n repeated_dereference: 'repeated-dereference',\n count_in_correlated_subquery: 'count-in-correlated-subquery',\n very_large_query: 'very-large-query',\n extremely_large_query: 'extremely-large-query',\n many_joins: 'many-joins',\n}\n\n/**\n * Convert Rust rule ID to TS convention\n */\nexport function mapRuleId(rustRuleId: string): string {\n return RULE_ID_MAP[rustRuleId] ?? rustRuleId.replace(/_/g, '-')\n}\n","/* @ts-self-types=\"./groq_wasm.d.ts\" */\n\n/**\n * Format a GROQ query.\n *\n * # Arguments\n * * `query` - The GROQ query string to format\n * * `width` - Maximum line width (default: 80)\n *\n * # Returns\n * The formatted query string\n * @param {string} query\n * @param {number | null} [width]\n * @returns {string}\n */\nexport function format(query, width) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.format(ptr0, len0, isLikeNone(width) ? 0x100000001 : (width) >>> 0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\n\nexport function init() {\n wasm.init();\n}\n\n/**\n * Lint a GROQ query and return findings as JSON.\n *\n * # Arguments\n * * `query` - The GROQ query string to lint\n *\n * # Returns\n * A JSON string containing an array of findings\n * @param {string} query\n * @returns {string}\n */\nexport function lint(query) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.lint(ptr0, len0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\n\nfunction __wbg_get_imports() {\n const import0 = {\n __proto__: null,\n __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {\n let deferred0_0;\n let deferred0_1;\n try {\n deferred0_0 = arg0;\n deferred0_1 = arg1;\n console.error(getStringFromWasm0(arg0, arg1));\n } finally {\n wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);\n }\n },\n __wbg_new_227d7c05414eb861: function() {\n const ret = new Error();\n return ret;\n },\n __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {\n const ret = arg1.stack;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);\n getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);\n },\n __wbindgen_cast_0000000000000001: function(arg0, arg1) {\n // Cast intrinsic for `Ref(String) -> Externref`.\n const ret = getStringFromWasm0(arg0, arg1);\n return ret;\n },\n __wbindgen_init_externref_table: function() {\n const table = wasm.__wbindgen_externrefs;\n const offset = table.grow(4);\n table.set(0, undefined);\n table.set(offset + 0, undefined);\n table.set(offset + 1, null);\n table.set(offset + 2, true);\n table.set(offset + 3, false);\n },\n };\n return {\n __proto__: null,\n \"./groq_wasm_bg.js\": import0,\n };\n}\n\nlet cachedDataViewMemory0 = null;\nfunction getDataViewMemory0() {\n if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {\n cachedDataViewMemory0 = new DataView(wasm.memory.buffer);\n }\n return cachedDataViewMemory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return decodeText(ptr, len);\n}\n\nlet cachedUint8ArrayMemory0 = null;\nfunction getUint8ArrayMemory0() {\n if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {\n cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8ArrayMemory0;\n}\n\nfunction isLikeNone(x) {\n return x === undefined || x === null;\n}\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8ArrayMemory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;\n const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);\n const ret = cachedTextEncoder.encodeInto(arg, view);\n\n offset += ret.written;\n ptr = realloc(ptr, len, offset, 1) >>> 0;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction takeFromExternrefTable0(idx) {\n const value = wasm.__wbindgen_externrefs.get(idx);\n wasm.__externref_table_dealloc(idx);\n return value;\n}\n\nlet cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\ncachedTextDecoder.decode();\nconst MAX_SAFARI_DECODE_BYTES = 2146435072;\nlet numBytesDecoded = 0;\nfunction decodeText(ptr, len) {\n numBytesDecoded += len;\n if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {\n cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\n cachedTextDecoder.decode();\n numBytesDecoded = len;\n }\n return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));\n}\n\nconst cachedTextEncoder = new TextEncoder();\n\nif (!('encodeInto' in cachedTextEncoder)) {\n cachedTextEncoder.encodeInto = function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n };\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nlet wasmModule, wasm;\nfunction __wbg_finalize_init(instance, module) {\n wasm = instance.exports;\n wasmModule = module;\n cachedDataViewMemory0 = null;\n cachedUint8ArrayMemory0 = null;\n wasm.__wbindgen_start();\n return wasm;\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n const validResponse = module.ok && expectedResponseType(module.type);\n\n if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {\n 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);\n\n } else { throw e; }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n\n function expectedResponseType(type) {\n switch (type) {\n case 'basic': case 'cors': case 'default': return true;\n }\n return false;\n }\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n\n if (module !== undefined) {\n if (Object.getPrototypeOf(module) === Object.prototype) {\n ({module} = module)\n } else {\n console.warn('using deprecated parameters for `initSync()`; pass a single object instead')\n }\n }\n\n const imports = __wbg_get_imports();\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n const instance = new WebAssembly.Instance(module, imports);\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(module_or_path) {\n if (wasm !== undefined) return wasm;\n\n\n if (module_or_path !== undefined) {\n if (Object.getPrototypeOf(module_or_path) === Object.prototype) {\n ({module_or_path} = module_or_path)\n } else {\n console.warn('using deprecated parameters for the initialization function; pass a single object instead')\n }\n }\n\n if (module_or_path === undefined) {\n module_or_path = new URL('groq_wasm_bg.wasm', import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {\n module_or_path = fetch(module_or_path);\n }\n\n const { instance, module } = await __wbg_load(await module_or_path, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync, __wbg_init as default };\n","/**\n * WASM module runtime.\n *\n * Exposes the WASM-backed lint/format calls and a synchronous init helper.\n * The actual byte loading is platform-specific and happens in the\n * environment-specific entry (`index.ts` for Node, `index.browser.ts` for\n * the browser). By the time any caller of this package can call `lint()` /\n * `format()`, the entry has already run `initWasm(bytes)`.\n */\n\nimport * as wasmModule from '../wasm/groq_wasm.js'\n\nimport { WasmError } from './types.js'\n\nexport function initWasm(bytes: ArrayBuffer | Uint8Array): void {\n try {\n wasmModule.initSync({ module: bytes })\n } catch (error) {\n throw new WasmError(\n `Failed to initialize WASM: ${error instanceof Error ? error.message : String(error)}`,\n 'WASM_ERROR'\n )\n }\n}\n\nexport function callLint(query: string): string {\n return wasmModule.lint(query)\n}\n\nexport function callFormat(query: string, width?: number): string {\n return wasmModule.format(query, width ?? null)\n}\n","/**\n * GROQ Linting via WASM\n *\n * Wraps the Rust groq-lint library compiled to WASM.\n */\n\nimport type { Finding, SourceLocation, SourceSpan } from '@sanity-labs/lint-core'\nimport {\n mapRuleId,\n mapSeverity,\n WasmError,\n type WasmFinding,\n type WasmLintConfig,\n} from './types.js'\nimport { callLint } from './wasm-loader.js'\n\n/**\n * Lint a GROQ query using the WASM-based linter\n *\n * @param query - The GROQ query string to lint\n * @param config - Optional configuration\n * @returns Array of findings\n * @throws {WasmError} If query parsing fails\n *\n * @example\n * ```typescript\n * import {lint} from '@sanity-labs/groq-wasm'\n *\n * const findings = lint('*[_type == \"post\"]{ author-> }')\n * // [{ ruleId: 'join-in-filter', message: '...', severity: 'error' }]\n * ```\n */\nexport function lint(query: string, config?: WasmLintConfig): Finding[] {\n if (!query.trim()) {\n return []\n }\n\n try {\n // Call WASM function - returns JSON string\n const resultJson = callLint(query)\n const wasmFindings: WasmFinding[] = JSON.parse(resultJson)\n\n // Filter by config if provided\n let findings = wasmFindings\n if (config?.rules) {\n const rules = config.rules\n findings = findings.filter((f) => {\n const enabled = rules[f.ruleId]\n return enabled !== false\n })\n }\n\n // Convert to our Finding type\n return findings.map((wf) => convertFinding(wf, query))\n } catch (error) {\n if (error instanceof WasmError) {\n throw error\n }\n\n // Parse errors from WASM come as thrown strings/errors\n const message = error instanceof Error ? error.message : String(error)\n\n if (message.includes('parse') || message.includes('Parse')) {\n throw new WasmError(`Failed to parse query: ${message}`, 'PARSE_ERROR')\n }\n\n throw new WasmError(`Lint failed: ${message}`, 'WASM_ERROR')\n }\n}\n\n/**\n * Convert WASM finding to our Finding type\n */\nfunction convertFinding(wf: WasmFinding, query: string): Finding {\n return {\n ruleId: mapRuleId(wf.ruleId),\n message: wf.message,\n severity: mapSeverity(wf.severity),\n span: byteSpanToSourceSpan(wf.start, wf.end, query),\n }\n}\n\n/**\n * Convert byte offsets to line/column source span\n */\nfunction byteSpanToSourceSpan(startByte: number, endByte: number, query: string): SourceSpan {\n return {\n start: byteOffsetToLocation(startByte, query),\n end: byteOffsetToLocation(endByte, query),\n }\n}\n\n/**\n * Convert byte offset to line/column location\n */\nfunction byteOffsetToLocation(offset: number, query: string): SourceLocation {\n let line = 1\n let column = 1\n let currentOffset = 0\n\n for (const char of query) {\n if (currentOffset >= offset) {\n break\n }\n\n if (char === '\\n') {\n line++\n column = 1\n } else {\n column++\n }\n\n currentOffset++\n }\n\n return { line, column, offset }\n}\n","/**\n * GROQ Formatting via WASM\n *\n * Wraps the Rust groq-format library compiled to WASM.\n */\n\nimport { WasmError, type WasmFormatConfig } from './types.js'\nimport { callFormat } from './wasm-loader.js'\n\n/**\n * Default line width for formatting\n * Matches Rust groq-format DEFAULT_WIDTH\n */\nexport const DEFAULT_WIDTH = 80\n\n/**\n * Format a GROQ query using the WASM-based formatter\n *\n * @param query - The GROQ query string to format\n * @param config - Optional configuration (width defaults to 80)\n * @returns Formatted query string\n * @throws {WasmError} If query parsing fails\n *\n * @example\n * ```typescript\n * import {format} from '@sanity-labs/groq-wasm'\n *\n * const formatted = format('*[_type==\"post\"]{title,body}')\n * // '*[_type == \"post\"]{ title, body }'\n * ```\n */\nexport function format(query: string, config?: WasmFormatConfig): string {\n const width = config?.width ?? DEFAULT_WIDTH\n\n if (!query.trim()) {\n return query\n }\n\n try {\n return callFormat(query, width)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n\n if (message.includes('parse') || message.includes('Parse')) {\n throw new WasmError(`Failed to parse query: ${message}`, 'PARSE_ERROR')\n }\n\n throw new WasmError(`Format failed: ${message}`, 'WASM_ERROR')\n }\n}\n\n/**\n * Check if a query can be parsed (without full formatting)\n *\n * @param query - The GROQ query to validate\n * @returns true if the query is valid GROQ syntax\n */\nexport function isValidSyntax(query: string): boolean {\n try {\n format(query)\n return true\n } catch (error) {\n if (error instanceof WasmError && error.code === 'PARSE_ERROR') {\n return false\n }\n throw error\n }\n}\n"],"mappings":";AAgBO,SAAS,YAAY,cAA0D;AACpF,UAAQ,cAAc;AAAA,IACpB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;AAqCO,IAAM,YAAN,cAAwB,MAAM;AAAA,EACnC,YACE,SACgB,MAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AAAA,EAJkB;AAKpB;AAKO,IAAM,cAAsC;AAAA,EACjD,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,0BAA0B;AAAA,EAC1B,aAAa;AAAA,EACb,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,aAAa;AAAA,EACb,wBAAwB;AAAA,EACxB,sBAAsB;AAAA,EACtB,8BAA8B;AAAA,EAC9B,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,YAAY;AACd;AAKO,SAAS,UAAU,YAA4B;AACpD,SAAO,YAAY,UAAU,KAAK,WAAW,QAAQ,MAAM,GAAG;AAChE;;;ACjFO,SAAS,OAAO,OAAO,OAAO;AACjC,MAAI;AACJ,MAAI;AACJ,MAAI;AACA,UAAM,OAAO,kBAAkB,OAAO,KAAK,mBAAmB,KAAK,kBAAkB;AACrF,UAAM,OAAO;AACb,UAAM,MAAM,KAAK,OAAO,MAAM,MAAM,WAAW,KAAK,IAAI,aAAe,UAAW,CAAC;AACnF,QAAI,OAAO,IAAI,CAAC;AAChB,QAAI,OAAO,IAA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AAO;AACX,MAAI,SAAS;AACb,MAAI,gBAAgB;AAEpB,aAAW,QAAQ,OAAO;AACxB,QAAI,iBAAiB,QAAQ;AAC3B;AAAA,IACF;AAEA,QAAI,SAAS,MAAM;AACjB;AACA,eAAS;AAAA,IACX,OAAO;AACL;AAAA,IACF;AAEA;AAAA,EACF;AAEA,SAAO,EAAE,MAAM,QAAQ,OAAO;AAChC;;;ACvGO,IAAM,gBAAgB;AAkBtB,SAASC,QAAO,OAAe,QAAmC;AACvE,QAAM,QAAQ,QAAQ,SAAS;AAE/B,MAAI,CAAC,MAAM,KAAK,GAAG;AACjB,WAAO;AAAA,EACT;AAEA,MAAI;AACF,WAAO,WAAW,OAAO,KAAK;AAAA,EAChC,SAAS,OAAO;AACd,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAErE,QAAI,QAAQ,SAAS,OAAO,KAAK,QAAQ,SAAS,OAAO,GAAG;AAC1D,YAAM,IAAI,UAAU,0BAA0B,OAAO,IAAI,aAAa;AAAA,IACxE;AAEA,UAAM,IAAI,UAAU,kBAAkB,OAAO,IAAI,YAAY;AAAA,EAC/D;AACF;AAQO,SAAS,cAAc,OAAwB;AACpD,MAAI;AACF,IAAAA,QAAO,KAAK;AACZ,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa,MAAM,SAAS,eAAe;AAC9D,aAAO;AAAA,IACT;AACA,UAAM;AAAA,EACR;AACF;","names":["ptr","lint","format"]}
@@ -0,0 +1,123 @@
1
+ import { Finding } from '@sanity-labs/lint-core';
2
+
3
+ /**
4
+ * Types for @sanity-labs/groq-wasm
5
+ *
6
+ * These types match the Rust API from groq-lint and groq-format,
7
+ * converted to TypeScript conventions (snake_case → camelCase).
8
+ */
9
+ /**
10
+ * Severity levels matching Rust groq-lint
11
+ * Rust: High, Medium, Low → TS: error, warning, info
12
+ */
13
+ type WasmSeverity = 'high' | 'medium' | 'low';
14
+ /**
15
+ * Map WASM severity to our standard severity
16
+ */
17
+ declare function mapSeverity(wasmSeverity: WasmSeverity): 'error' | 'warning' | 'info';
18
+ /**
19
+ * A finding from the Rust linter (JSON format from WASM)
20
+ */
21
+ interface WasmFinding {
22
+ /** Rule ID (snake_case from Rust) */
23
+ ruleId: string;
24
+ /** Human-readable message */
25
+ message: string;
26
+ /** Severity level */
27
+ severity: WasmSeverity;
28
+ /** Start byte offset (0-based) */
29
+ start: number;
30
+ /** End byte offset (0-based) */
31
+ end: number;
32
+ }
33
+ /**
34
+ * Configuration for linting
35
+ */
36
+ interface WasmLintConfig {
37
+ /** Rules to enable/disable (rule_id → enabled) */
38
+ rules?: Record<string, boolean>;
39
+ }
40
+ /**
41
+ * Configuration for formatting
42
+ */
43
+ interface WasmFormatConfig {
44
+ /** Maximum line width (default: 80) */
45
+ width?: number;
46
+ }
47
+ /**
48
+ * Error from WASM operations
49
+ */
50
+ declare class WasmError extends Error {
51
+ readonly code: 'PARSE_ERROR' | 'WASM_ERROR';
52
+ constructor(message: string, code: 'PARSE_ERROR' | 'WASM_ERROR');
53
+ }
54
+ /**
55
+ * Rule ID mapping from Rust (snake_case) to TS (kebab-case)
56
+ */
57
+ declare const RULE_ID_MAP: Record<string, string>;
58
+ /**
59
+ * Convert Rust rule ID to TS convention
60
+ */
61
+ declare function mapRuleId(rustRuleId: string): string;
62
+
63
+ /**
64
+ * GROQ Linting via WASM
65
+ *
66
+ * Wraps the Rust groq-lint library compiled to WASM.
67
+ */
68
+
69
+ /**
70
+ * Lint a GROQ query using the WASM-based linter
71
+ *
72
+ * @param query - The GROQ query string to lint
73
+ * @param config - Optional configuration
74
+ * @returns Array of findings
75
+ * @throws {WasmError} If query parsing fails
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * import {lint} from '@sanity-labs/groq-wasm'
80
+ *
81
+ * const findings = lint('*[_type == "post"]{ author-> }')
82
+ * // [{ ruleId: 'join-in-filter', message: '...', severity: 'error' }]
83
+ * ```
84
+ */
85
+ declare function lint(query: string, config?: WasmLintConfig): Finding[];
86
+
87
+ /**
88
+ * GROQ Formatting via WASM
89
+ *
90
+ * Wraps the Rust groq-format library compiled to WASM.
91
+ */
92
+
93
+ /**
94
+ * Default line width for formatting
95
+ * Matches Rust groq-format DEFAULT_WIDTH
96
+ */
97
+ declare const DEFAULT_WIDTH = 80;
98
+ /**
99
+ * Format a GROQ query using the WASM-based formatter
100
+ *
101
+ * @param query - The GROQ query string to format
102
+ * @param config - Optional configuration (width defaults to 80)
103
+ * @returns Formatted query string
104
+ * @throws {WasmError} If query parsing fails
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * import {format} from '@sanity-labs/groq-wasm'
109
+ *
110
+ * const formatted = format('*[_type=="post"]{title,body}')
111
+ * // '*[_type == "post"]{ title, body }'
112
+ * ```
113
+ */
114
+ declare function format(query: string, config?: WasmFormatConfig): string;
115
+ /**
116
+ * Check if a query can be parsed (without full formatting)
117
+ *
118
+ * @param query - The GROQ query to validate
119
+ * @returns true if the query is valid GROQ syntax
120
+ */
121
+ declare function isValidSyntax(query: string): boolean;
122
+
123
+ export { DEFAULT_WIDTH, RULE_ID_MAP, WasmError, type WasmFinding, type WasmFormatConfig, type WasmLintConfig, type WasmSeverity, format, isValidSyntax, lint, mapRuleId, mapSeverity };
@@ -0,0 +1,32 @@
1
+ import {
2
+ DEFAULT_WIDTH,
3
+ RULE_ID_MAP,
4
+ WasmError,
5
+ format,
6
+ initWasm,
7
+ isValidSyntax,
8
+ lint,
9
+ mapRuleId,
10
+ mapSeverity
11
+ } from "./chunk-2DNVGC7B.js";
12
+
13
+ // src/index.browser.ts
14
+ var wasmUrl = new URL("../wasm/groq_wasm_bg.wasm", import.meta.url);
15
+ var response = await fetch(wasmUrl);
16
+ if (!response.ok) {
17
+ throw new Error(
18
+ `Failed to fetch GROQ WASM module from ${wasmUrl.href}: ${response.status} ${response.statusText}`
19
+ );
20
+ }
21
+ initWasm(await response.arrayBuffer());
22
+ export {
23
+ DEFAULT_WIDTH,
24
+ RULE_ID_MAP,
25
+ WasmError,
26
+ format,
27
+ isValidSyntax,
28
+ lint,
29
+ mapRuleId,
30
+ mapSeverity
31
+ };
32
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.browser.ts"],"sourcesContent":["/**\n * @sanity-labs/groq-wasm — Browser entry.\n *\n * Fetches the WASM bytes at import time and initializes the module via\n * top-level await + `initSync`. After this module finishes loading,\n * `lint()` and `format()` are usable synchronously. Bundlers that\n * understand `new URL('...', import.meta.url)` (Vite, Rollup, Webpack 5,\n * esbuild) emit the WASM file as an asset and rewrite the URL.\n */\n\nimport { initWasm } from './wasm-loader.js'\n\nconst wasmUrl = new URL('../wasm/groq_wasm_bg.wasm', import.meta.url)\nconst response = await fetch(wasmUrl)\nif (!response.ok) {\n throw new Error(\n `Failed to fetch GROQ WASM module from ${wasmUrl.href}: ${response.status} ${response.statusText}`\n )\n}\ninitWasm(await response.arrayBuffer())\n\nexport * from './public.js'\n"],"mappings":";;;;;;;;;;;;;AAYA,IAAM,UAAU,IAAI,IAAI,6BAA6B,YAAY,GAAG;AACpE,IAAM,WAAW,MAAM,MAAM,OAAO;AACpC,IAAI,CAAC,SAAS,IAAI;AAChB,QAAM,IAAI;AAAA,IACR,yCAAyC,QAAQ,IAAI,KAAK,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,EAClG;AACF;AACA,SAAS,MAAM,SAAS,YAAY,CAAC;","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,160 +1,2 @@
1
- import { Finding } from '@sanity-labs/lint-core';
2
-
3
- /**
4
- * Types for @sanity-labs/groq-wasm
5
- *
6
- * These types match the Rust API from groq-lint and groq-format,
7
- * converted to TypeScript conventions (snake_case → camelCase).
8
- */
9
- /**
10
- * Severity levels matching Rust groq-lint
11
- * Rust: High, Medium, Low → TS: error, warning, info
12
- */
13
- type WasmSeverity = 'high' | 'medium' | 'low';
14
- /**
15
- * Map WASM severity to our standard severity
16
- */
17
- declare function mapSeverity(wasmSeverity: WasmSeverity): 'error' | 'warning' | 'info';
18
- /**
19
- * A finding from the Rust linter (JSON format from WASM)
20
- */
21
- interface WasmFinding {
22
- /** Rule ID (snake_case from Rust) */
23
- ruleId: string;
24
- /** Human-readable message */
25
- message: string;
26
- /** Severity level */
27
- severity: WasmSeverity;
28
- /** Start byte offset (0-based) */
29
- start: number;
30
- /** End byte offset (0-based) */
31
- end: number;
32
- }
33
- /**
34
- * Configuration for linting
35
- */
36
- interface WasmLintConfig {
37
- /** Rules to enable/disable (rule_id → enabled) */
38
- rules?: Record<string, boolean>;
39
- }
40
- /**
41
- * Configuration for formatting
42
- */
43
- interface WasmFormatConfig {
44
- /** Maximum line width (default: 80) */
45
- width?: number;
46
- }
47
- /**
48
- * Error from WASM operations
49
- */
50
- declare class WasmError extends Error {
51
- readonly code: 'NOT_INITIALIZED' | 'PARSE_ERROR' | 'WASM_ERROR';
52
- constructor(message: string, code: 'NOT_INITIALIZED' | 'PARSE_ERROR' | 'WASM_ERROR');
53
- }
54
- /**
55
- * Rule ID mapping from Rust (snake_case) to TS (kebab-case)
56
- */
57
- declare const RULE_ID_MAP: Record<string, string>;
58
- /**
59
- * Convert Rust rule ID to TS convention
60
- */
61
- declare function mapRuleId(rustRuleId: string): string;
62
-
63
- /**
64
- * GROQ Linting via WASM
65
- *
66
- * Wraps the Rust groq-lint library compiled to WASM.
67
- */
68
-
69
- /**
70
- * Lint a GROQ query using the WASM-based linter
71
- *
72
- * @param query - The GROQ query string to lint
73
- * @param config - Optional configuration
74
- * @returns Array of findings
75
- * @throws {WasmError} If WASM is not initialized or query parsing fails
76
- *
77
- * @example
78
- * ```typescript
79
- * import { initWasm, lint } from '@sanity-labs/groq-wasm'
80
- *
81
- * await initWasm()
82
- *
83
- * const findings = lint('*[_type == "post"]{ author-> }')
84
- * // [{ ruleId: 'join-in-filter', message: '...', severity: 'error' }]
85
- * ```
86
- */
87
- declare function lint(query: string, config?: WasmLintConfig): Finding[];
88
- /**
89
- * Async version of lint for environments that prefer promises
90
- */
91
- declare function lintAsync(query: string, config?: WasmLintConfig): Promise<Finding[]>;
92
-
93
- /**
94
- * GROQ Formatting via WASM
95
- *
96
- * Wraps the Rust groq-format library compiled to WASM.
97
- */
98
-
99
- /**
100
- * Default line width for formatting
101
- * Matches Rust groq-format DEFAULT_WIDTH
102
- */
103
- declare const DEFAULT_WIDTH = 80;
104
- /**
105
- * Format a GROQ query using the WASM-based formatter
106
- *
107
- * @param query - The GROQ query string to format
108
- * @param config - Optional configuration (width defaults to 80)
109
- * @returns Formatted query string
110
- * @throws {WasmError} If WASM is not initialized or query parsing fails
111
- *
112
- * @example
113
- * ```typescript
114
- * import { initWasm, format } from '@sanity-labs/groq-wasm'
115
- *
116
- * await initWasm()
117
- *
118
- * const formatted = format('*[_type=="post"]{title,body}')
119
- * // '*[_type == "post"]{ title, body }'
120
- * ```
121
- */
122
- declare function format(query: string, config?: WasmFormatConfig): string;
123
- /**
124
- * Async version of format for environments that prefer promises
125
- */
126
- declare function formatAsync(query: string, config?: WasmFormatConfig): Promise<string>;
127
- /**
128
- * Check if a query can be parsed (without full formatting)
129
- *
130
- * @param query - The GROQ query to validate
131
- * @returns true if the query is valid GROQ syntax
132
- */
133
- declare function isValidSyntax(query: string): boolean;
134
-
135
- /**
136
- * WASM Module Loader
137
- *
138
- * Handles loading and initializing the WASM modules for groq-lint and groq-format.
139
- * Uses the `--target web` output from wasm-pack, which works in both Node.js and browsers.
140
- */
141
- /**
142
- * Check if WASM modules are initialized
143
- */
144
- declare function isInitialized(): boolean;
145
- /**
146
- * Initialize WASM modules
147
- *
148
- * Call this once at application startup. Safe to call multiple times.
149
- *
150
- * @example
151
- * ```typescript
152
- * import { initWasm } from '@sanity-labs/groq-wasm'
153
- *
154
- * await initWasm()
155
- * // Now lint() and format() are ready to use
156
- * ```
157
- */
158
- declare function initWasm(): Promise<void>;
159
-
160
- export { DEFAULT_WIDTH, RULE_ID_MAP, WasmError, type WasmFinding, type WasmFormatConfig, type WasmLintConfig, type WasmSeverity, format, formatAsync, initWasm, isInitialized, isValidSyntax, lint, lintAsync, mapRuleId, mapSeverity };
1
+ export { DEFAULT_WIDTH, RULE_ID_MAP, WasmError, WasmFinding, WasmFormatConfig, WasmLintConfig, WasmSeverity, format, isValidSyntax, lint, mapRuleId, mapSeverity } from './index.browser.js';
2
+ import '@sanity-labs/lint-core';
package/dist/index.js CHANGED
@@ -1,206 +1,27 @@
1
- // src/types.ts
2
- function mapSeverity(wasmSeverity) {
3
- switch (wasmSeverity) {
4
- case "high":
5
- return "error";
6
- case "medium":
7
- return "warning";
8
- case "low":
9
- return "info";
10
- }
11
- }
12
- var WasmError = class extends Error {
13
- constructor(message, code) {
14
- super(message);
15
- this.code = code;
16
- this.name = "WasmError";
17
- }
18
- };
19
- var RULE_ID_MAP = {
20
- join_in_filter: "join-in-filter",
21
- join_to_get_id: "join-to-get-id",
22
- computed_value_in_filter: "computed-value-in-filter",
23
- match_on_id: "match-on-id",
24
- order_on_expr: "order-on-expr",
25
- deep_pagination: "deep-pagination",
26
- large_pages: "large-pages",
27
- non_literal_comparison: "non-literal-comparison",
28
- repeated_dereference: "repeated-dereference",
29
- count_in_correlated_subquery: "count-in-correlated-subquery",
30
- very_large_query: "very-large-query",
31
- extremely_large_query: "extremely-large-query",
32
- many_joins: "many-joins"
33
- };
34
- function mapRuleId(rustRuleId) {
35
- return RULE_ID_MAP[rustRuleId] ?? rustRuleId.replace(/_/g, "-");
36
- }
37
-
38
- // src/wasm-loader.ts
39
- var initialized = false;
40
- var initPromise = null;
41
- var wasmLint = null;
42
- var wasmFormat = null;
43
- function isInitialized() {
44
- return initialized;
45
- }
46
- async function initWasm() {
47
- if (initialized) {
48
- return;
49
- }
50
- if (initPromise) {
51
- return initPromise;
52
- }
53
- initPromise = doInit();
54
- await initPromise;
55
- }
56
- async function doInit() {
57
- try {
58
- const wasmModule = await import("./groq_wasm-Z3ZUBGZA.js");
59
- const wasmUrl = new URL("../wasm/groq_wasm_bg.wasm", import.meta.url);
60
- if (wasmUrl.protocol === "file:") {
61
- const { readFile } = await import("fs/promises");
62
- const { fileURLToPath } = await import("url");
63
- const bytes = await readFile(fileURLToPath(wasmUrl));
64
- await wasmModule.default({ module_or_path: bytes });
65
- } else {
66
- await wasmModule.default({ module_or_path: wasmUrl });
67
- }
68
- wasmLint = wasmModule.lint;
69
- wasmFormat = wasmModule.format;
70
- initialized = true;
71
- } catch (error) {
72
- initPromise = null;
73
- throw new WasmError(
74
- `Failed to initialize WASM: ${error instanceof Error ? error.message : String(error)}`,
75
- "WASM_ERROR"
76
- );
77
- }
78
- }
79
- function callLint(query) {
80
- if (!initialized || !wasmLint) {
81
- throw new WasmError("WASM not initialized. Call initWasm() first.", "NOT_INITIALIZED");
82
- }
83
- return wasmLint(query);
84
- }
85
- function callFormat(query, width) {
86
- if (!initialized || !wasmFormat) {
87
- throw new WasmError("WASM not initialized. Call initWasm() first.", "NOT_INITIALIZED");
88
- }
89
- return wasmFormat(query, width ?? null);
90
- }
91
-
92
- // src/lint.ts
93
- function lint(query, config) {
94
- if (!isInitialized()) {
95
- throw new WasmError("WASM not initialized. Call initWasm() first.", "NOT_INITIALIZED");
96
- }
97
- if (!query.trim()) {
98
- return [];
99
- }
100
- try {
101
- const resultJson = callLint(query);
102
- const wasmFindings = JSON.parse(resultJson);
103
- let findings = wasmFindings;
104
- if (config?.rules) {
105
- const rules = config.rules;
106
- findings = findings.filter((f) => {
107
- const enabled = rules[f.ruleId];
108
- return enabled !== false;
109
- });
110
- }
111
- return findings.map((wf) => convertFinding(wf, query));
112
- } catch (error) {
113
- if (error instanceof WasmError) {
114
- throw error;
115
- }
116
- const message = error instanceof Error ? error.message : String(error);
117
- if (message.includes("parse") || message.includes("Parse")) {
118
- throw new WasmError(`Failed to parse query: ${message}`, "PARSE_ERROR");
119
- }
120
- throw new WasmError(`Lint failed: ${message}`, "WASM_ERROR");
121
- }
122
- }
123
- async function lintAsync(query, config) {
124
- return lint(query, config);
125
- }
126
- function convertFinding(wf, query) {
127
- return {
128
- ruleId: mapRuleId(wf.ruleId),
129
- message: wf.message,
130
- severity: mapSeverity(wf.severity),
131
- span: byteSpanToSourceSpan(wf.start, wf.end, query)
132
- };
133
- }
134
- function byteSpanToSourceSpan(startByte, endByte, query) {
135
- return {
136
- start: byteOffsetToLocation(startByte, query),
137
- end: byteOffsetToLocation(endByte, query)
138
- };
139
- }
140
- function byteOffsetToLocation(offset, query) {
141
- let line = 1;
142
- let column = 1;
143
- let currentOffset = 0;
144
- for (const char of query) {
145
- if (currentOffset >= offset) {
146
- break;
147
- }
148
- if (char === "\n") {
149
- line++;
150
- column = 1;
151
- } else {
152
- column++;
153
- }
154
- currentOffset++;
155
- }
156
- return { line, column, offset };
157
- }
1
+ import {
2
+ DEFAULT_WIDTH,
3
+ RULE_ID_MAP,
4
+ WasmError,
5
+ format,
6
+ initWasm,
7
+ isValidSyntax,
8
+ lint,
9
+ mapRuleId,
10
+ mapSeverity
11
+ } from "./chunk-2DNVGC7B.js";
158
12
 
159
- // src/format.ts
160
- var DEFAULT_WIDTH = 80;
161
- function format(query, config) {
162
- if (!isInitialized()) {
163
- throw new WasmError("WASM not initialized. Call initWasm() first.", "NOT_INITIALIZED");
164
- }
165
- const width = config?.width ?? DEFAULT_WIDTH;
166
- if (!query.trim()) {
167
- return query;
168
- }
169
- try {
170
- return callFormat(query, width);
171
- } catch (error) {
172
- const message = error instanceof Error ? error.message : String(error);
173
- if (message.includes("parse") || message.includes("Parse")) {
174
- throw new WasmError(`Failed to parse query: ${message}`, "PARSE_ERROR");
175
- }
176
- throw new WasmError(`Format failed: ${message}`, "WASM_ERROR");
177
- }
178
- }
179
- async function formatAsync(query, config) {
180
- return format(query, config);
181
- }
182
- function isValidSyntax(query) {
183
- try {
184
- format(query);
185
- return true;
186
- } catch (error) {
187
- if (error instanceof WasmError && error.code === "PARSE_ERROR") {
188
- return false;
189
- }
190
- throw error;
191
- }
192
- }
13
+ // src/index.ts
14
+ import { readFileSync } from "fs";
15
+ import { fileURLToPath } from "url";
16
+ var wasmPath = fileURLToPath(new URL("../wasm/groq_wasm_bg.wasm", import.meta.url));
17
+ initWasm(readFileSync(wasmPath));
193
18
  export {
194
19
  DEFAULT_WIDTH,
195
20
  RULE_ID_MAP,
196
21
  WasmError,
197
22
  format,
198
- formatAsync,
199
- initWasm,
200
- isInitialized,
201
23
  isValidSyntax,
202
24
  lint,
203
- lintAsync,
204
25
  mapRuleId,
205
26
  mapSeverity
206
27
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/wasm-loader.ts","../src/lint.ts","../src/format.ts"],"sourcesContent":["/**\n * Types for @sanity-labs/groq-wasm\n *\n * These types match the Rust API from groq-lint and groq-format,\n * converted to TypeScript conventions (snake_case → camelCase).\n */\n\n/**\n * Severity levels matching Rust groq-lint\n * Rust: High, Medium, Low → TS: error, warning, info\n */\nexport type WasmSeverity = 'high' | 'medium' | 'low'\n\n/**\n * Map WASM severity to our standard severity\n */\nexport function mapSeverity(wasmSeverity: WasmSeverity): 'error' | 'warning' | 'info' {\n switch (wasmSeverity) {\n case 'high':\n return 'error'\n case 'medium':\n return 'warning'\n case 'low':\n return 'info'\n }\n}\n\n/**\n * A finding from the Rust linter (JSON format from WASM)\n */\nexport interface WasmFinding {\n /** Rule ID (snake_case from Rust) */\n ruleId: string\n /** Human-readable message */\n message: string\n /** Severity level */\n severity: WasmSeverity\n /** Start byte offset (0-based) */\n start: number\n /** End byte offset (0-based) */\n end: number\n}\n\n/**\n * Configuration for linting\n */\nexport interface WasmLintConfig {\n /** Rules to enable/disable (rule_id → enabled) */\n rules?: Record<string, boolean>\n}\n\n/**\n * Configuration for formatting\n */\nexport interface WasmFormatConfig {\n /** Maximum line width (default: 80) */\n width?: number\n}\n\n/**\n * Error from WASM operations\n */\nexport class WasmError extends Error {\n constructor(\n message: string,\n public readonly code: 'NOT_INITIALIZED' | 'PARSE_ERROR' | 'WASM_ERROR'\n ) {\n super(message)\n this.name = 'WasmError'\n }\n}\n\n/**\n * Rule ID mapping from Rust (snake_case) to TS (kebab-case)\n */\nexport const RULE_ID_MAP: Record<string, string> = {\n join_in_filter: 'join-in-filter',\n join_to_get_id: 'join-to-get-id',\n computed_value_in_filter: 'computed-value-in-filter',\n match_on_id: 'match-on-id',\n order_on_expr: 'order-on-expr',\n deep_pagination: 'deep-pagination',\n large_pages: 'large-pages',\n non_literal_comparison: 'non-literal-comparison',\n repeated_dereference: 'repeated-dereference',\n count_in_correlated_subquery: 'count-in-correlated-subquery',\n very_large_query: 'very-large-query',\n extremely_large_query: 'extremely-large-query',\n many_joins: 'many-joins',\n}\n\n/**\n * Convert Rust rule ID to TS convention\n */\nexport function mapRuleId(rustRuleId: string): string {\n return RULE_ID_MAP[rustRuleId] ?? rustRuleId.replace(/_/g, '-')\n}\n","/**\n * WASM Module Loader\n *\n * Handles loading and initializing the WASM modules for groq-lint and groq-format.\n * Uses the `--target web` output from wasm-pack, which works in both Node.js and browsers.\n */\n\nimport { WasmError } from './types.js'\n\n// WASM module state\nlet initialized = false\nlet initPromise: Promise<void> | null = null\n\n// WASM module functions (set after initialization)\nlet wasmLint: ((query: string) => string) | null = null\nlet wasmFormat: ((query: string, width?: number | null) => string) | null = null\n\n/**\n * Check if WASM modules are initialized\n */\nexport function isInitialized(): boolean {\n return initialized\n}\n\n/**\n * Initialize WASM modules\n *\n * Call this once at application startup. Safe to call multiple times.\n *\n * @example\n * ```typescript\n * import { initWasm } from '@sanity-labs/groq-wasm'\n *\n * await initWasm()\n * // Now lint() and format() are ready to use\n * ```\n */\nexport async function initWasm(): Promise<void> {\n if (initialized) {\n return\n }\n\n if (initPromise) {\n return initPromise\n }\n\n initPromise = doInit()\n await initPromise\n}\n\nasync function doInit(): Promise<void> {\n try {\n const wasmModule = await import('../wasm/groq_wasm.js')\n const wasmUrl = new URL('../wasm/groq_wasm_bg.wasm', import.meta.url)\n\n if (wasmUrl.protocol === 'file:') {\n // Node.js: fetch() doesn't support file:// URLs, read from disk\n const { readFile } = await import('node:fs/promises')\n const { fileURLToPath } = await import('node:url')\n const bytes = await readFile(fileURLToPath(wasmUrl))\n await wasmModule.default({ module_or_path: bytes })\n } else {\n // Browser / other runtimes: use fetch via the default init path\n await wasmModule.default({ module_or_path: wasmUrl })\n }\n\n // Store the functions\n wasmLint = wasmModule.lint\n wasmFormat = wasmModule.format\n\n initialized = true\n } catch (error) {\n initPromise = null\n throw new WasmError(\n `Failed to initialize WASM: ${error instanceof Error ? error.message : String(error)}`,\n 'WASM_ERROR'\n )\n }\n}\n\n/**\n * Call the WASM lint function\n * @throws {WasmError} If not initialized\n */\nexport function callLint(query: string): string {\n if (!initialized || !wasmLint) {\n throw new WasmError('WASM not initialized. Call initWasm() first.', 'NOT_INITIALIZED')\n }\n return wasmLint(query)\n}\n\n/**\n * Call the WASM format function\n * @throws {WasmError} If not initialized\n */\nexport function callFormat(query: string, width?: number): string {\n if (!initialized || !wasmFormat) {\n throw new WasmError('WASM not initialized. Call initWasm() first.', 'NOT_INITIALIZED')\n }\n return wasmFormat(query, width ?? null)\n}\n","/**\n * GROQ Linting via WASM\n *\n * Wraps the Rust groq-lint library compiled to WASM.\n */\n\nimport type { Finding, SourceLocation, SourceSpan } from '@sanity-labs/lint-core'\nimport {\n mapRuleId,\n mapSeverity,\n WasmError,\n type WasmFinding,\n type WasmLintConfig,\n} from './types.js'\nimport { callLint, isInitialized } from './wasm-loader.js'\n\n/**\n * Lint a GROQ query using the WASM-based linter\n *\n * @param query - The GROQ query string to lint\n * @param config - Optional configuration\n * @returns Array of findings\n * @throws {WasmError} If WASM is not initialized or query parsing fails\n *\n * @example\n * ```typescript\n * import { initWasm, lint } from '@sanity-labs/groq-wasm'\n *\n * await initWasm()\n *\n * const findings = lint('*[_type == \"post\"]{ author-> }')\n * // [{ ruleId: 'join-in-filter', message: '...', severity: 'error' }]\n * ```\n */\nexport function lint(query: string, config?: WasmLintConfig): Finding[] {\n if (!isInitialized()) {\n throw new WasmError('WASM not initialized. Call initWasm() first.', 'NOT_INITIALIZED')\n }\n\n // Handle empty query - nothing to lint\n if (!query.trim()) {\n return []\n }\n\n try {\n // Call WASM function - returns JSON string\n const resultJson = callLint(query)\n const wasmFindings: WasmFinding[] = JSON.parse(resultJson)\n\n // Filter by config if provided\n let findings = wasmFindings\n if (config?.rules) {\n const rules = config.rules\n findings = findings.filter((f) => {\n const enabled = rules[f.ruleId]\n return enabled !== false\n })\n }\n\n // Convert to our Finding type\n return findings.map((wf) => convertFinding(wf, query))\n } catch (error) {\n if (error instanceof WasmError) {\n throw error\n }\n\n // Parse errors from WASM come as thrown strings/errors\n const message = error instanceof Error ? error.message : String(error)\n\n if (message.includes('parse') || message.includes('Parse')) {\n throw new WasmError(`Failed to parse query: ${message}`, 'PARSE_ERROR')\n }\n\n throw new WasmError(`Lint failed: ${message}`, 'WASM_ERROR')\n }\n}\n\n/**\n * Async version of lint for environments that prefer promises\n */\nexport async function lintAsync(query: string, config?: WasmLintConfig): Promise<Finding[]> {\n // WASM operations are synchronous, but we provide async API\n // for consistency and future-proofing (e.g., if we add worker support)\n return lint(query, config)\n}\n\n/**\n * Convert WASM finding to our Finding type\n */\nfunction convertFinding(wf: WasmFinding, query: string): Finding {\n return {\n ruleId: mapRuleId(wf.ruleId),\n message: wf.message,\n severity: mapSeverity(wf.severity),\n span: byteSpanToSourceSpan(wf.start, wf.end, query),\n }\n}\n\n/**\n * Convert byte offsets to line/column source span\n */\nfunction byteSpanToSourceSpan(startByte: number, endByte: number, query: string): SourceSpan {\n return {\n start: byteOffsetToLocation(startByte, query),\n end: byteOffsetToLocation(endByte, query),\n }\n}\n\n/**\n * Convert byte offset to line/column location\n */\nfunction byteOffsetToLocation(offset: number, query: string): SourceLocation {\n let line = 1\n let column = 1\n let currentOffset = 0\n\n for (const char of query) {\n if (currentOffset >= offset) {\n break\n }\n\n if (char === '\\n') {\n line++\n column = 1\n } else {\n column++\n }\n\n currentOffset++\n }\n\n return { line, column, offset }\n}\n","/**\n * GROQ Formatting via WASM\n *\n * Wraps the Rust groq-format library compiled to WASM.\n */\n\nimport { WasmError, type WasmFormatConfig } from './types.js'\nimport { callFormat, isInitialized } from './wasm-loader.js'\n\n/**\n * Default line width for formatting\n * Matches Rust groq-format DEFAULT_WIDTH\n */\nexport const DEFAULT_WIDTH = 80\n\n/**\n * Format a GROQ query using the WASM-based formatter\n *\n * @param query - The GROQ query string to format\n * @param config - Optional configuration (width defaults to 80)\n * @returns Formatted query string\n * @throws {WasmError} If WASM is not initialized or query parsing fails\n *\n * @example\n * ```typescript\n * import { initWasm, format } from '@sanity-labs/groq-wasm'\n *\n * await initWasm()\n *\n * const formatted = format('*[_type==\"post\"]{title,body}')\n * // '*[_type == \"post\"]{ title, body }'\n * ```\n */\nexport function format(query: string, config?: WasmFormatConfig): string {\n if (!isInitialized()) {\n throw new WasmError('WASM not initialized. Call initWasm() first.', 'NOT_INITIALIZED')\n }\n\n const width = config?.width ?? DEFAULT_WIDTH\n\n // Handle empty query\n if (!query.trim()) {\n return query\n }\n\n try {\n return callFormat(query, width)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n\n if (message.includes('parse') || message.includes('Parse')) {\n throw new WasmError(`Failed to parse query: ${message}`, 'PARSE_ERROR')\n }\n\n throw new WasmError(`Format failed: ${message}`, 'WASM_ERROR')\n }\n}\n\n/**\n * Async version of format for environments that prefer promises\n */\nexport async function formatAsync(query: string, config?: WasmFormatConfig): Promise<string> {\n // WASM operations are synchronous, but we provide async API\n // for consistency and future-proofing\n return format(query, config)\n}\n\n/**\n * Check if a query can be parsed (without full formatting)\n *\n * @param query - The GROQ query to validate\n * @returns true if the query is valid GROQ syntax\n */\nexport function isValidSyntax(query: string): boolean {\n try {\n format(query)\n return true\n } catch (error) {\n if (error instanceof WasmError && error.code === 'PARSE_ERROR') {\n return false\n }\n // Re-throw other errors\n throw error\n }\n}\n"],"mappings":";AAgBO,SAAS,YAAY,cAA0D;AACpF,UAAQ,cAAc;AAAA,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AO,KAAK;AAErE,QAAI,QAAQ,SAAS,OAAO,KAAK,QAAQ,SAAS,OAAO,GAAG;AAC1D,YAAM,IAAI,UAAU,0BAA0B,OAAO,IAAI,aAAa;AAAA,IACxE;AAEA,UAAM,IAAI,UAAU,kBAAkB,OAAO,IAAI,YAAY;AAAA,EAC/D;AACF;AAKA,eAAsB,YAAY,OAAe,QAA4C;AAG3F,SAAO,OAAO,OAAO,MAAM;AAC7B;AAQO,SAAS,cAAc,OAAwB;AACpD,MAAI;AACF,WAAO,KAAK;AACZ,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa,MAAM,SAAS,eAAe;AAC9D,aAAO;AAAA,IACT;AAEA,UAAM;AAAA,EACR;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @sanity-labs/groq-wasm — Node entry.\n *\n * Loads the WASM module synchronously at import time using `fs.readFileSync`\n * + `initSync`. After importing this package, `lint()` and `format()` are\n * usable immediately — no async bootstrap.\n */\n\nimport { readFileSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\n\nimport { initWasm } from './wasm-loader.js'\n\nconst wasmPath = fileURLToPath(new URL('../wasm/groq_wasm_bg.wasm', import.meta.url))\ninitWasm(readFileSync(wasmPath))\n\nexport * from './public.js'\n"],"mappings":";;;;;;;;;;;;;AAQA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAI9B,IAAM,WAAW,cAAc,IAAI,IAAI,6BAA6B,YAAY,GAAG,CAAC;AACpF,SAAS,aAAa,QAAQ,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity-labs/groq-wasm",
3
- "version": "0.2.0",
3
+ "version": "1.0.0",
4
4
  "description": "WASM bindings for GROQ linting and formatting (groq-lint + groq-format)",
5
5
  "keywords": [
6
6
  "sanity",
@@ -21,6 +21,7 @@
21
21
  "exports": {
22
22
  ".": {
23
23
  "types": "./dist/index.d.ts",
24
+ "browser": "./dist/index.browser.js",
24
25
  "default": "./dist/index.js"
25
26
  }
26
27
  },
@@ -32,11 +33,11 @@
32
33
  "devDependencies": {
33
34
  "tsup": "^8.3.5",
34
35
  "typescript": "^5.7.2",
35
- "vitest": "^2.1.8",
36
- "@sanity-labs/lint-core": "0.1.0"
36
+ "vitest": "^4.0.0",
37
+ "@sanity-labs/lint-core": "1.0.0"
37
38
  },
38
39
  "engines": {
39
- "node": ">=20.0.0"
40
+ "node": ">=22.3.0"
40
41
  },
41
42
  "publishConfig": {
42
43
  "access": "public"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../wasm/groq_wasm.js"],"sourcesContent":["/* @ts-self-types=\"./groq_wasm.d.ts\" */\n\n/**\n * Format a GROQ query.\n *\n * # Arguments\n * * `query` - The GROQ query string to format\n * * `width` - Maximum line width (default: 80)\n *\n * # Returns\n * The formatted query string\n * @param {string} query\n * @param {number | null} [width]\n * @returns {string}\n */\nexport function format(query, width) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.format(ptr0, len0, isLikeNone(width) ? 0x100000001 : (width) >>> 0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\n\nexport function init() {\n wasm.init();\n}\n\n/**\n * Lint a GROQ query and return findings as JSON.\n *\n * # Arguments\n * * `query` - The GROQ query string to lint\n *\n * # Returns\n * A JSON string containing an array of findings\n * @param {string} query\n * @returns {string}\n */\nexport function lint(query) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.lint(ptr0, len0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\n\nfunction __wbg_get_imports() {\n const import0 = {\n __proto__: null,\n __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {\n let deferred0_0;\n let deferred0_1;\n try {\n deferred0_0 = arg0;\n deferred0_1 = arg1;\n console.error(getStringFromWasm0(arg0, arg1));\n } finally {\n wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);\n }\n },\n __wbg_new_227d7c05414eb861: function() {\n const ret = new Error();\n return ret;\n },\n __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {\n const ret = arg1.stack;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);\n getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);\n },\n __wbindgen_cast_0000000000000001: function(arg0, arg1) {\n // Cast intrinsic for `Ref(String) -> Externref`.\n const ret = getStringFromWasm0(arg0, arg1);\n return ret;\n },\n __wbindgen_init_externref_table: function() {\n const table = wasm.__wbindgen_externrefs;\n const offset = table.grow(4);\n table.set(0, undefined);\n table.set(offset + 0, undefined);\n table.set(offset + 1, null);\n table.set(offset + 2, true);\n table.set(offset + 3, false);\n },\n };\n return {\n __proto__: null,\n \"./groq_wasm_bg.js\": import0,\n };\n}\n\nlet cachedDataViewMemory0 = null;\nfunction getDataViewMemory0() {\n if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {\n cachedDataViewMemory0 = new DataView(wasm.memory.buffer);\n }\n return cachedDataViewMemory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return decodeText(ptr, len);\n}\n\nlet cachedUint8ArrayMemory0 = null;\nfunction getUint8ArrayMemory0() {\n if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {\n cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8ArrayMemory0;\n}\n\nfunction isLikeNone(x) {\n return x === undefined || x === null;\n}\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8ArrayMemory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;\n const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);\n const ret = cachedTextEncoder.encodeInto(arg, view);\n\n offset += ret.written;\n ptr = realloc(ptr, len, offset, 1) >>> 0;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction takeFromExternrefTable0(idx) {\n const value = wasm.__wbindgen_externrefs.get(idx);\n wasm.__externref_table_dealloc(idx);\n return value;\n}\n\nlet cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\ncachedTextDecoder.decode();\nconst MAX_SAFARI_DECODE_BYTES = 2146435072;\nlet numBytesDecoded = 0;\nfunction decodeText(ptr, len) {\n numBytesDecoded += len;\n if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {\n cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\n cachedTextDecoder.decode();\n numBytesDecoded = len;\n }\n return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));\n}\n\nconst cachedTextEncoder = new TextEncoder();\n\nif (!('encodeInto' in cachedTextEncoder)) {\n cachedTextEncoder.encodeInto = function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n };\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nlet wasmModule, wasm;\nfunction __wbg_finalize_init(instance, module) {\n wasm = instance.exports;\n wasmModule = module;\n cachedDataViewMemory0 = null;\n cachedUint8ArrayMemory0 = null;\n wasm.__wbindgen_start();\n return wasm;\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n const validResponse = module.ok && expectedResponseType(module.type);\n\n if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {\n 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);\n\n } else { throw e; }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n\n function expectedResponseType(type) {\n switch (type) {\n case 'basic': case 'cors': case 'default': return true;\n }\n return false;\n }\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n\n if (module !== undefined) {\n if (Object.getPrototypeOf(module) === Object.prototype) {\n ({module} = module)\n } else {\n console.warn('using deprecated parameters for `initSync()`; pass a single object instead')\n }\n }\n\n const imports = __wbg_get_imports();\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n const instance = new WebAssembly.Instance(module, imports);\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(module_or_path) {\n if (wasm !== undefined) return wasm;\n\n\n if (module_or_path !== undefined) {\n if (Object.getPrototypeOf(module_or_path) === Object.prototype) {\n ({module_or_path} = module_or_path)\n } else {\n console.warn('using deprecated parameters for the initialization function; pass a single object instead')\n }\n }\n\n if (module_or_path === undefined) {\n module_or_path = new URL('groq_wasm_bg.wasm', import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {\n module_or_path = fetch(module_or_path);\n }\n\n const { instance, module } = await __wbg_load(await module_or_path, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync, __wbg_init as default };\n"],"mappings":";AAeO,SAAS,OAAO,OAAO,OAAO;AACjC,MAAI;AACJ,MAAI;AACJ,MAAI;AACA,UAAM,OAAO,kBAAkB,OAAO,KAAK,mBAAmB,KAAK,kBAAkB;AACrF,UAAM,OAAO;AACb,UAAM,MAAM,KAAK,OAAO,MAAM,MAAM,WAAW,KAAK,IAAI,aAAe,UAAW,CAAC;AACnF,QAAI,OAAO,IAAI,CAAC;AAChB,QAAI,OAAO,IAAI,CAAC;AAChB,QAAI,IAAI,CAAC,GAAG;AACR,aAAO;AAAG,aAAO;AACjB,YAAM,wBAAwB,IAAI,CAAC,CAAC;AAAA,IACxC;AACA,kBAAc;AACd,kBAAc;AACd,WAAO,mBAAmB,MAAM,IAAI;AAAA,EACxC,UAAE;AACE,SAAK,gBAAgB,aAAa,aAAa,CAAC;AAAA,EACpD;AACJ;AAEO,SAAS,OAAO;AACnB,OAAK,KAAK;AACd;AAaO,SAAS,KAAK,OAAO;AACxB,MAAI;AACJ,MAAI;AACJ,MAAI;AACA,UAAM,OAAO,kBAAkB,OAAO,KAAK,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