@sanity-labs/groq-wasm 1.1.1 → 1.2.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.
package/README.md CHANGED
@@ -20,7 +20,8 @@ npm install @sanity-labs/groq-wasm
20
20
  ```typescript
21
21
  import { lint, format, validate } from '@sanity-labs/groq-wasm'
22
22
 
23
- // WASM loads when the module is imported. lint, format, and validate are sync.
23
+ // The default entry loads WASM when the module is imported.
24
+ // lint, format, and validate are sync after that import resolves.
24
25
 
25
26
  // Lint a query
26
27
  const findings = lint('*[_type == "post"]{ author-> }')
@@ -41,9 +42,44 @@ if (!result.ok) {
41
42
  }
42
43
  ```
43
44
 
45
+ ## Lazy initialization
46
+
47
+ The default browser entry fetches the WebAssembly module with a top-level `await`. Bundlers that wrap lazy chunks in non-async factories cannot import it. Sanity Studio's `bundledDev` mode does this and throws `SyntaxError: Unexpected reserved word`.
48
+
49
+ `@sanity-labs/groq-wasm/lazy` exports the same functions and does not fetch or compile the module when the module is evaluated. Initialize it, then call the API:
50
+
51
+ ```typescript
52
+ import { lint, format, validate, load } from '@sanity-labs/groq-wasm/lazy'
53
+
54
+ await load()
55
+
56
+ const findings = lint('*[_type == "post"]{ author-> }')
57
+ const formatted = format('*[_type=="post"]{title,body}')
58
+ ```
59
+
60
+ `load()` fetches the packaged `.wasm` file and initializes it. Concurrent calls share one request, and a later call after success does not fetch again. If `load()` rejects, the module stays uninitialized and the next call retries.
61
+
62
+ Pass bytes, a `Response`, or a compiled `WebAssembly.Module` to `initWasm()` when you already have the module. Bytes and a `WebAssembly.Module` initialize synchronously. A `Response` returns a promise. `await initWasm(source)` is safe for every accepted source. A second successful call does nothing.
63
+
64
+ ```typescript
65
+ import { initWasm, lint } from '@sanity-labs/groq-wasm/lazy'
66
+
67
+ initWasm(wasmBytes)
68
+ // await initWasm(response)
69
+ // initWasm(compiledModule)
70
+
71
+ const findings = lint(query)
72
+ ```
73
+
74
+ `lint()`, `format()`, `validate()`, `extractParams()`, and `isValidSyntax()` throw `WasmError` with code `NOT_INITIALIZED` until initialization has succeeded. `lint`, `format`, and `extractParams` still return without touching the module for an empty or whitespace-only query.
75
+
76
+ The raw module is also exported at `@sanity-labs/groq-wasm/wasm`.
77
+
78
+ The default `@sanity-labs/groq-wasm` entry is unchanged. Importing it still initializes the module immediately, and it does not export `load` or `initWasm`.
79
+
44
80
  ## API
45
81
 
46
- Importing the package loads the WASM module. `lint()`, `format()`, and `validate()` are synchronous after that import resolves.
82
+ Importing `@sanity-labs/groq-wasm` loads the WASM module. `lint()`, `format()`, and `validate()` are synchronous after that import resolves. To load the module yourself, import `@sanity-labs/groq-wasm/lazy` and call `load()` or `initWasm()`.
47
83
 
48
84
  ### Linting
49
85
 
@@ -177,8 +213,10 @@ The following rules are available (from Rust groq-lint):
177
213
 
178
214
  ## Error Handling
179
215
 
216
+ The default entry initializes WASM on import, so `NOT_INITIALIZED` is not raised from that entry. The lazy entry (`@sanity-labs/groq-wasm/lazy`) throws it when an API is used before `load()` or `initWasm()` has succeeded.
217
+
180
218
  ```typescript
181
- import { WasmError } from '@sanity-labs/groq-wasm'
219
+ import { WasmError, lint } from '@sanity-labs/groq-wasm/lazy'
182
220
 
183
221
  try {
184
222
  const findings = lint(query)
@@ -186,7 +224,7 @@ try {
186
224
  if (error instanceof WasmError) {
187
225
  switch (error.code) {
188
226
  case 'NOT_INITIALIZED':
189
- // Call initWasm() first
227
+ // Call load() or initWasm() on '@sanity-labs/groq-wasm/lazy' first
190
228
  break
191
229
  case 'PARSE_ERROR':
192
230
  // Invalid GROQ syntax
@@ -201,16 +239,17 @@ try {
201
239
 
202
240
  ## Browser Support
203
241
 
204
- This package works in modern browsers that support WebAssembly. The WASM modules are loaded automatically based on the environment.
242
+ This package works in modern browsers that support WebAssembly. The default browser entry fetches and initializes the WASM module on import, using top-level await.
205
243
 
206
244
  ```typescript
207
- // In browser. The WASM module is fetched and initialized on import.
208
245
  import { lint, validate } from '@sanity-labs/groq-wasm'
209
246
 
210
247
  const findings = lint(query)
211
248
  const parsed = validate(query)
212
249
  ```
213
250
 
251
+ When the bundler cannot handle that top-level await, import `@sanity-labs/groq-wasm/lazy` and call `await load()` before using the API.
252
+
214
253
  ## Architecture
215
254
 
216
255
  This package uses a **wrapper crate** approach:
@@ -222,7 +261,9 @@ packages/groq-wasm/
222
261
  │ └── src/lib.rs # wasm-bindgen exports
223
262
  ├── wasm/ # Built WASM output (generated)
224
263
  ├── src/ # TypeScript wrappers
225
- │ ├── index.ts # Main exports
264
+ │ ├── index.ts # Node entry (sync init)
265
+ │ ├── index.browser.ts # Browser entry (top-level await)
266
+ │ ├── index.lazy.ts # Lazy entry (load / initWasm)
226
267
  │ ├── params.ts # Parameter extraction API
227
268
  │ ├── lint.ts # Linting API
228
269
  │ ├── format.ts # Formatting API
@@ -59,24 +59,25 @@ function extractParams(query) {
59
59
  }
60
60
  }
61
61
  function format(query, width) {
62
- let deferred3_0;
63
- let deferred3_1;
62
+ let deferred4_0;
63
+ let deferred4_1;
64
64
  try {
65
+ const val2 = +(isLikeNone(width) ? Number.MAX_SAFE_INTEGER : width >>> 0);
65
66
  const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
66
67
  const len0 = WASM_VECTOR_LEN;
67
- const ret = wasm.format(ptr0, len0, isLikeNone(width) ? Number.MAX_SAFE_INTEGER : width >>> 0);
68
- var ptr2 = ret[0];
69
- var len2 = ret[1];
68
+ const ret = wasm.format(ptr0, len0, val2);
69
+ var ptr3 = ret[0];
70
+ var len3 = ret[1];
70
71
  if (ret[3]) {
71
- ptr2 = 0;
72
- len2 = 0;
72
+ ptr3 = 0;
73
+ len3 = 0;
73
74
  throw takeFromExternrefTable0(ret[2]);
74
75
  }
75
- deferred3_0 = ptr2;
76
- deferred3_1 = len2;
77
- return getStringFromWasm0(ptr2, len2);
76
+ deferred4_0 = ptr3;
77
+ deferred4_1 = len3;
78
+ return getStringFromWasm0(ptr3, len3);
78
79
  } finally {
79
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
80
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
80
81
  }
81
82
  }
82
83
  function lint(query) {
@@ -128,16 +129,16 @@ function __wbg_get_imports() {
128
129
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
129
130
  }
130
131
  },
131
- __wbg_new_227d7c05414eb861: function() {
132
+ __wbg_new_bb74001155cb8ca8: function() {
132
133
  const ret = new Error();
133
134
  return ret;
134
135
  },
135
- __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
136
+ __wbg_stack_575c4e0918581b9c: function(arg0, arg1) {
136
137
  const ret = arg1.stack;
137
138
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
138
139
  const len1 = WASM_VECTOR_LEN;
139
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
140
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
140
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
141
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
141
142
  },
142
143
  __wbindgen_generic_0000000000000001: function(arg0, arg1) {
143
144
  const ret = getStringFromWasm0(arg0, arg1);
@@ -145,12 +146,11 @@ function __wbg_get_imports() {
145
146
  },
146
147
  __wbindgen_init_externref_table: function() {
147
148
  const table = wasm.__wbindgen_externrefs;
148
- const offset = table.grow(4);
149
149
  table.set(0, void 0);
150
- table.set(offset + 0, void 0);
151
- table.set(offset + 1, null);
152
- table.set(offset + 2, true);
153
- table.set(offset + 3, false);
150
+ table.set(1024, void 0);
151
+ table.set(1025, null);
152
+ table.set(1026, true);
153
+ table.set(1027, false);
154
154
  }
155
155
  };
156
156
  return {
@@ -166,7 +166,8 @@ function getDataViewMemory0() {
166
166
  return cachedDataViewMemory0;
167
167
  }
168
168
  function getStringFromWasm0(ptr, len) {
169
- return decodeText(ptr >>> 0, len);
169
+ ptr = ptr >>> 0;
170
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
170
171
  }
171
172
  var cachedUint8ArrayMemory0 = null;
172
173
  function getUint8ArrayMemory0() {
@@ -213,18 +214,18 @@ function takeFromExternrefTable0(idx) {
213
214
  wasm.__externref_table_dealloc(idx);
214
215
  return value;
215
216
  }
216
- var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
217
+ var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
217
218
  cachedTextDecoder.decode();
218
219
  var MAX_SAFARI_DECODE_BYTES = 2146435072;
219
220
  var numBytesDecoded = 0;
220
- function decodeText(ptr, len) {
221
- numBytesDecoded += len;
221
+ function decodeText(bytes) {
222
+ numBytesDecoded += bytes.length;
222
223
  if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
223
- cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
224
+ cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
224
225
  cachedTextDecoder.decode();
225
- numBytesDecoded = len;
226
+ numBytesDecoded = bytes.length;
226
227
  }
227
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
228
+ return cachedTextDecoder.decode(bytes);
228
229
  }
229
230
  var cachedTextEncoder = new TextEncoder();
230
231
  if (!("encodeInto" in cachedTextEncoder)) {
@@ -268,28 +269,64 @@ function initSync(module) {
268
269
  }
269
270
 
270
271
  // src/wasm-loader.ts
271
- function initWasm(bytes) {
272
- try {
273
- initSync({ module: bytes });
274
- } catch (error) {
275
- throw new WasmError(
276
- `Failed to initialize WASM: ${error instanceof Error ? error.message : String(error)}`,
277
- "WASM_ERROR"
278
- );
272
+ var NOT_INITIALIZED_MESSAGE = "GROQ WASM module is not initialized. Call load() or initWasm() before using this API.";
273
+ var initialized = false;
274
+ function isWasmInitialized() {
275
+ return initialized;
276
+ }
277
+ function initWasm(source) {
278
+ if (isResponse(source)) {
279
+ return initFromResponse(source);
279
280
  }
281
+ initFromCompiled(source);
280
282
  }
281
283
  function callLint(query) {
284
+ assertInitialized();
282
285
  return lint(query);
283
286
  }
284
287
  function callExtractParams(query) {
288
+ assertInitialized();
285
289
  return extractParams(query);
286
290
  }
287
291
  function callFormat(query, width) {
292
+ assertInitialized();
288
293
  return format(query, width ?? null);
289
294
  }
290
295
  function callValidate(query) {
296
+ assertInitialized();
291
297
  return validate(query);
292
298
  }
299
+ function assertInitialized() {
300
+ if (!initialized) {
301
+ throw new WasmError(NOT_INITIALIZED_MESSAGE, "NOT_INITIALIZED");
302
+ }
303
+ }
304
+ function isResponse(source) {
305
+ return typeof Response === "function" && source instanceof Response;
306
+ }
307
+ function initFromCompiled(source) {
308
+ if (initialized) return;
309
+ try {
310
+ initSync({ module: source });
311
+ } catch (error) {
312
+ throw new WasmError(
313
+ `Failed to initialize WASM: ${error instanceof Error ? error.message : String(error)}`,
314
+ "WASM_ERROR"
315
+ );
316
+ }
317
+ initialized = true;
318
+ }
319
+ async function initFromResponse(response) {
320
+ if (initialized) return;
321
+ if (!response.ok) {
322
+ const from = response.url ? ` from ${response.url}` : "";
323
+ throw new WasmError(
324
+ `Failed to read GROQ WASM module${from}: ${response.status} ${response.statusText}`,
325
+ "WASM_ERROR"
326
+ );
327
+ }
328
+ initFromCompiled(await response.arrayBuffer());
329
+ }
293
330
 
294
331
  // src/offsets.ts
295
332
  function createUtf8OffsetMapper(text) {
@@ -339,6 +376,9 @@ function extractParams2(query) {
339
376
  try {
340
377
  resultJson = callExtractParams(query);
341
378
  } catch (error) {
379
+ if (error instanceof WasmError) {
380
+ throw error;
381
+ }
342
382
  const message = error instanceof Error ? error.message : String(error);
343
383
  if (message.includes("parse") || message.includes("Parse")) {
344
384
  throw new WasmError(`Failed to parse query: ${message}`, "PARSE_ERROR");
@@ -424,6 +464,9 @@ function format2(query, config) {
424
464
  try {
425
465
  return callFormat(query, width);
426
466
  } catch (error) {
467
+ if (error instanceof WasmError) {
468
+ throw error;
469
+ }
427
470
  const message = error instanceof Error ? error.message : String(error);
428
471
  if (message.includes("parse") || message.includes("Parse")) {
429
472
  throw new WasmError(`Failed to parse query: ${message}`, "PARSE_ERROR");
@@ -449,6 +492,9 @@ function validate2(query) {
449
492
  try {
450
493
  parsed = JSON.parse(callValidate(query));
451
494
  } catch (error) {
495
+ if (error instanceof WasmError) {
496
+ throw error;
497
+ }
452
498
  const message = error instanceof Error ? error.message : String(error);
453
499
  throw new WasmError(`Validate failed: ${message}`, "WASM_ERROR");
454
500
  }
@@ -503,6 +549,7 @@ export {
503
549
  WasmError,
504
550
  RULE_ID_MAP,
505
551
  mapRuleId,
552
+ isWasmInitialized,
506
553
  initWasm,
507
554
  extractParams2 as extractParams,
508
555
  lint2 as lint,
@@ -511,4 +558,4 @@ export {
511
558
  isValidSyntax,
512
559
  validate2 as validate
513
560
  };
514
- //# sourceMappingURL=chunk-XXDG7JJH.js.map
561
+ //# sourceMappingURL=chunk-PIYLCZE4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts","../wasm/groq_wasm.js","../src/wasm-loader.ts","../src/offsets.ts","../src/params.ts","../src/lint.ts","../src/format.ts","../src/validate.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 offset into the UTF-8 encoding of the query (0-based) */\n start: number\n /** End offset into the UTF-8 encoding of the query (0-based, exclusive) */\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 * A parameter reference from the Rust parser (JSON format from WASM)\n */\nexport interface WasmParamReference {\n /** Parameter name without the `$` */\n name: string\n /** Start byte offset of the `$` (0-based, UTF-8) */\n start: number\n /** End byte offset, exclusive (0-based, UTF-8) */\n end: number\n}\n\n/**\n * One `$name` reference in a query, from {@link extractParams}.\n *\n * `start` and `end` are indices into the JavaScript query string (UTF-16 code\n * units), not UTF-8 byte offsets. `start` is inclusive and `end` is exclusive,\n * so `query.slice(start, end)` is `\"$name\"`. Lines and columns are 1-based,\n * and columns count UTF-16 code units, matching `SourceLocation` on lint\n * findings.\n */\nexport interface ParamReference {\n /** Inclusive start index of the `$`, 0-based UTF-16 code units. */\n start: number\n /** Exclusive end index, 0-based UTF-16 code units. */\n end: number\n /** 1-based line number of `start`. */\n line: number\n /** 1-based column of `start`, counted in UTF-16 code units. */\n column: number\n /** 1-based line number of `end`. */\n endLine: number\n /** 1-based column of `end`, counted in UTF-16 code units. */\n endColumn: number\n}\n\n/**\n * A query parameter referenced by a GROQ query, from {@link extractParams}.\n */\nexport interface QueryParam {\n /** Parameter name without the `$`, e.g. `\"type\"` for `$type`. */\n name: string\n /** Every reference to this parameter, in source order. Never empty. */\n references: ParamReference[]\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' | 'NOT_INITIALIZED'\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 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 unlimited_query: 'unlimited-query',\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/**\n * A GROQ syntax error from `validate`.\n *\n * `start` and `end` are indices into the JavaScript query string (UTF-16 code\n * units), not UTF-8 byte offsets. `start` is inclusive and `end` is exclusive,\n * so `query.slice(start, end)` is the reported span. groq-parser reports UTF-8\n * byte offsets; `validate` converts them. A zero-width span (`start === end`)\n * is a caret on a token boundary.\n *\n * `line` / `column` locate `start`, and `endLine` / `endColumn` locate `end`.\n * Lines and columns are 1-based. Columns count UTF-16 code units, matching\n * `SourceLocation` on lint findings.\n */\nexport interface ValidateError {\n /** Parser message, without a serialized position suffix. */\n message: string\n /** Inclusive start index, 0-based UTF-16 code units. */\n start: number\n /** Exclusive end index, 0-based UTF-16 code units. */\n end: number\n /** 1-based line number of `start`. */\n line: number\n /** 1-based column of `start`, counted in UTF-16 code units. */\n column: number\n /** 1-based line number of `end`. */\n endLine: number\n /** 1-based column of `end`, counted in UTF-16 code units. */\n endColumn: number\n}\n\n/**\n * Result of {@link validate}.\n *\n * Syntax errors are values, not thrown exceptions. `lint` and `format` still\n * throw {@link WasmError} when a query does not parse.\n */\nexport type ValidateResult = { ok: true } | { ok: false; error: ValidateError }\n","/* @ts-self-types=\"./groq_wasm.d.ts\" */\n\n/**\n * List every query parameter a GROQ query references, as JSON.\n *\n * Returns one entry per reference, ordered by `start`. Byte offsets are\n * UTF-8 offsets into `query`; the JavaScript wrapper converts them to UTF-16\n * code unit indices. Parameters bound by a custom function (`fn ns::f($p)`)\n * are omitted inside that function's body.\n * @param {string} query\n * @returns {string}\n */\nexport function extractParams(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.extractParams(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\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 deferred4_0;\n let deferred4_1;\n try {\n const val2 = +(isLikeNone(width) ? Number.MAX_SAFE_INTEGER : (width) >>> 0);\n const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.format(ptr0, len0, val2);\n var ptr3 = ret[0];\n var len3 = ret[1];\n if (ret[3]) {\n ptr3 = 0; len3 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred4_0 = ptr3;\n deferred4_1 = len3;\n return getStringFromWasm0(ptr3, len3);\n } finally {\n wasm.__wbindgen_free(deferred4_0, deferred4_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\n/**\n * Parse a GROQ query and return a JSON validation result.\n *\n * Byte offsets in the JSON are UTF-8 offsets into `query`. The JavaScript\n * wrapper converts them to UTF-16 code unit indices.\n *\n * Success is `{\"ok\":true}`. A syntax error is\n * `{\"ok\":false,\"message\":\"...\",\"start\":N,\"end\":M}` where `start` is inclusive,\n * `end` is exclusive, and the two are equal when the parser reports a caret\n * rather than a token span.\n * @param {string} query\n * @returns {string}\n */\nexport function validate(query) {\n let deferred2_0;\n let deferred2_1;\n try {\n const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.validate(ptr0, len0);\n deferred2_0 = ret[0];\n deferred2_1 = ret[1];\n return getStringFromWasm0(ret[0], ret[1]);\n } finally {\n wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);\n }\n}\nfunction __wbg_get_imports() {\n const import0 = {\n __proto__: null,\n __wbg_error_757e9472f8410341: 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_bb74001155cb8ca8: function() {\n const ret = new Error();\n return ret;\n },\n __wbg_stack_575c4e0918581b9c: 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 >>> 0) + 4 * 1, len1, true);\n getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);\n },\n __wbindgen_generic_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 table.set(0, undefined);\n table.set(1024, undefined);\n table.set(1025, null);\n table.set(1026, true);\n table.set(1027, 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(getUint8ArrayMemory0().subarray(ptr, 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 });\ncachedTextDecoder.decode();\nconst MAX_SAFARI_DECODE_BYTES = 2146435072;\nlet numBytesDecoded = 0;\nfunction decodeText(bytes) {\n numBytesDecoded += bytes.length;\n if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {\n cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });\n cachedTextDecoder.decode();\n numBytesDecoded = bytes.length;\n }\n return cachedTextDecoder.decode(bytes);\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, wasmInstance, wasm;\nfunction __wbg_finalize_init(instance, module) {\n wasmInstance = instance;\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 (!module.ok) {\n throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);\n }\n\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n const validResponse = 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\nlet __wbg_init_promise;\nasync function __wbg_init(module_or_path) {\n if (wasm !== undefined) return wasm;\n if (__wbg_init_promise === undefined) {\n __wbg_init_promise = __wbg_init_once(module_or_path);\n __wbg_init_promise.catch(() => { __wbg_init_promise = undefined; });\n }\n return __wbg_init_promise;\n}\n\nasync function __wbg_init_once(module_or_path) {\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/validate calls and init helpers.\n * Byte loading is platform-specific:\n * - `index.ts` reads the file and calls `initWasm` synchronously (Node).\n * - `index.browser.ts` fetches it with top-level await (browser).\n * - `index.lazy.ts` does neither until `load()` or `initWasm()`.\n */\n\nimport * as wasmModule from '../wasm/groq_wasm.js'\n\nimport { WasmError } from './types.js'\n\n/**\n * Bytes, a compiled module, or a fetch `Response` accepted by {@link initWasm}.\n * A `Response` initializes asynchronously. The other forms are synchronous.\n */\nexport type WasmInitSource = ArrayBuffer | Uint8Array | WebAssembly.Module | Response\n\nconst NOT_INITIALIZED_MESSAGE =\n 'GROQ WASM module is not initialized. Call load() or initWasm() before using this API.'\n\nlet initialized = false\n\nexport function isWasmInitialized(): boolean {\n return initialized\n}\n\n/**\n * Initialize the GROQ WebAssembly module.\n *\n * `ArrayBuffer`, `Uint8Array`, and `WebAssembly.Module` initialize\n * synchronously and this function returns `void`. A `Response` is consumed\n * asynchronously and this function returns a promise. `await initWasm(source)`\n * is valid for every accepted source. A second successful call does nothing.\n *\n * @throws {WasmError} With code `WASM_ERROR` when the bytes cannot be\n * instantiated, or when the module is not initialized yet and `source` is a\n * `Response` that is not ok.\n */\nexport function initWasm(source: ArrayBuffer | Uint8Array | WebAssembly.Module): void\nexport function initWasm(source: Response): Promise<void>\nexport function initWasm(source: WasmInitSource): void | Promise<void> {\n if (isResponse(source)) {\n return initFromResponse(source)\n }\n initFromCompiled(source)\n}\n\nexport function callLint(query: string): string {\n assertInitialized()\n return wasmModule.lint(query)\n}\n\nexport function callExtractParams(query: string): string {\n assertInitialized()\n return wasmModule.extractParams(query)\n}\n\nexport function callFormat(query: string, width?: number): string {\n assertInitialized()\n return wasmModule.format(query, width ?? null)\n}\n\nexport function callValidate(query: string): string {\n assertInitialized()\n return wasmModule.validate(query)\n}\n\nfunction assertInitialized(): void {\n if (!initialized) {\n throw new WasmError(NOT_INITIALIZED_MESSAGE, 'NOT_INITIALIZED')\n }\n}\n\nfunction isResponse(source: WasmInitSource): source is Response {\n return typeof Response === 'function' && source instanceof Response\n}\n\nfunction initFromCompiled(source: ArrayBuffer | Uint8Array | WebAssembly.Module): void {\n if (initialized) return\n\n try {\n wasmModule.initSync({ module: source })\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 initialized = true\n}\n\nasync function initFromResponse(response: Response): Promise<void> {\n if (initialized) return\n\n if (!response.ok) {\n const from = response.url ? ` from ${response.url}` : ''\n throw new WasmError(\n `Failed to read GROQ WASM module${from}: ${response.status} ${response.statusText}`,\n 'WASM_ERROR'\n )\n }\n\n initFromCompiled(await response.arrayBuffer())\n}\n","/**\n * Conversion from groq-parser's UTF-8 byte offsets to JavaScript string\n * coordinates.\n *\n * wasm-bindgen passes the query to Rust with `TextEncoder`, so parser spans\n * are byte offsets into the query's UTF-8 encoding. JavaScript strings are\n * UTF-16, so those offsets stop matching string indices once the query\n * contains non-ASCII text.\n */\n\n/** A position in a JavaScript string. */\nexport interface TextPosition {\n /** 0-based UTF-16 code unit index. */\n index: number\n /** 1-based line. Advances on `\\n`. */\n line: number\n /** 1-based column, counted in UTF-16 code units. */\n column: number\n}\n\n/**\n * Create a function that maps UTF-8 byte offsets in `text` to\n * {@link TextPosition}s.\n *\n * The mapper resumes from the previous result, so calling it with ascending\n * offsets walks `text` once. A smaller offset restarts from the beginning.\n * An offset inside a code point resolves to the start of that code point, and\n * an offset past the end resolves to the end of `text`.\n */\nexport function createUtf8OffsetMapper(text: string): (byteOffset: number) => TextPosition {\n let index = 0\n let bytes = 0\n let line = 1\n let column = 1\n\n return (byteOffset) => {\n if (byteOffset < bytes) {\n index = 0\n bytes = 0\n line = 1\n column = 1\n }\n\n while (index < text.length && bytes < byteOffset) {\n const codePoint = text.codePointAt(index) ?? 0\n const byteWidth = utf8ByteLength(codePoint)\n if (bytes + byteWidth > byteOffset) {\n break\n }\n\n const utf16Width = codePoint > 0xffff ? 2 : 1\n bytes += byteWidth\n index += utf16Width\n\n if (codePoint === 0x0a) {\n line += 1\n column = 1\n } else {\n column += utf16Width\n }\n }\n\n return { index, line, column }\n }\n}\n\n/**\n * UTF-8 byte length of one code point, matching `TextEncoder`.\n *\n * Unpaired surrogates fall in the 3-byte range. `TextEncoder` replaces each\n * of them with U+FFFD, which is also 3 bytes.\n */\nfunction utf8ByteLength(codePoint: number): number {\n if (codePoint <= 0x7f) return 1\n if (codePoint <= 0x7ff) return 2\n if (codePoint <= 0xffff) return 3\n return 4\n}\n","/**\n * GROQ query parameter extraction via WASM.\n *\n * Wraps groq-parser's `ParseResult::referenced_params`. The parser reports\n * UTF-8 byte offsets; this module converts them to UTF-16 code unit indices.\n */\n\nimport { createUtf8OffsetMapper } from './offsets.js'\nimport { WasmError, type QueryParam, type WasmParamReference } from './types.js'\nimport { callExtractParams } from './wasm-loader.js'\n\n/**\n * List the query parameters (`$name`) a GROQ query references.\n *\n * Returns one entry per distinct name, in order of first reference. Each entry\n * lists every reference to that name in source order. Names do not include\n * the `$`, so they match the keys of the params object passed to a client.\n *\n * Parameters bound by a custom function (`fn ns::f($p) = ...`) are local to\n * that function's body and are not reported from inside it. `$name` text\n * inside string literals and comments is not a reference.\n *\n * Reference `start` / `end` are 0-based UTF-16 code unit indices into\n * `query` (`end` is exclusive), so `query.slice(start, end)` is `\"$name\"`.\n *\n * An empty or whitespace-only query returns `[]`, like `lint('')`.\n *\n * @param query - The GROQ query string\n * @returns Referenced parameters, in order of first reference\n * @throws {WasmError} With code `PARSE_ERROR` if the query does not parse\n *\n * @example\n * ```typescript\n * import {extractParams} from '@sanity-labs/groq-wasm'\n *\n * extractParams('*[_type == $type][0...$limit]').map((param) => param.name)\n * // ['type', 'limit']\n * ```\n */\nexport function extractParams(query: string): QueryParam[] {\n if (!query.trim()) {\n return []\n }\n\n let resultJson: string\n try {\n resultJson = callExtractParams(query)\n } catch (error) {\n if (error instanceof WasmError) {\n throw error\n }\n\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(`Extract params failed: ${message}`, 'WASM_ERROR')\n }\n\n const wasmReferences: WasmParamReference[] = JSON.parse(resultJson)\n const toPosition = createUtf8OffsetMapper(query)\n const params = new Map<string, QueryParam>()\n\n for (const reference of wasmReferences) {\n const start = toPosition(reference.start)\n const end = toPosition(reference.end)\n\n let param = params.get(reference.name)\n if (!param) {\n param = { name: reference.name, references: [] }\n params.set(reference.name, param)\n }\n\n param.references.push({\n start: start.index,\n end: end.index,\n line: start.line,\n column: start.column,\n endLine: end.line,\n endColumn: end.column,\n })\n }\n\n return [...params.values()]\n}\n","/**\n * GROQ Linting via WASM\n *\n * Wraps the Rust groq-lint library compiled to WASM.\n */\n\nimport type { Finding, SourceSpan } from '@sanity-labs/lint-core'\n\nimport { createUtf8OffsetMapper } from './offsets.js'\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 * Finding spans are source locations in JavaScript string coordinates.\n * The Rust linter reports UTF-8 byte offsets; `line`, `column`, and `offset`\n * below are converted from those bytes. `column` counts UTF-16 code units.\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 UTF-8 byte offsets to a line/column source span.\n *\n * `column` is a 1-based count of UTF-16 code units and `offset` is the\n * matching JavaScript string index. See {@link createUtf8OffsetMapper}.\n */\nfunction byteSpanToSourceSpan(startByte: number, endByte: number, query: string): SourceSpan {\n const toPosition = createUtf8OffsetMapper(query)\n const start = toPosition(startByte)\n const end = toPosition(endByte)\n return {\n start: { line: start.line, column: start.column, offset: start.index },\n end: { line: end.line, column: end.column, offset: end.index },\n }\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 if (error instanceof WasmError) {\n throw error\n }\n\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","/**\n * GROQ syntax validation via WASM.\n *\n * Wraps groq-parser's structured parse errors. The parser reports UTF-8 byte\n * offsets; this module converts them to UTF-16 code unit indices.\n */\n\nimport { createUtf8OffsetMapper } from './offsets.js'\nimport { WasmError, type ValidateError, type ValidateResult } from './types.js'\nimport { callValidate } from './wasm-loader.js'\n\n/**\n * Parse a GROQ query.\n *\n * Returns `{ok: true}` when the query parses. Syntax errors are returned as\n * `{ok: false, error}` and are not thrown. `lint` and `format` still throw\n * {@link WasmError} on invalid syntax; this function does not change that.\n *\n * `error.start` and `error.end` are 0-based UTF-16 code unit indices into\n * `query` (`end` is exclusive), which is what JavaScript strings and editors\n * such as Vision use. groq-parser's `ParseError` positions are UTF-8 byte\n * offsets (`Position.start` / `Position.end` in groq-parser-rs). An empty or\n * whitespace-only query is a syntax error (`\"no query\"`) at offset 0, unlike\n * `lint('')` and `format('')`, which treat it as nothing to do.\n *\n * `line` / `column` locate `start`, and `endLine` / `endColumn` locate `end`.\n * They are 1-based. Columns count UTF-16 code units, matching `SourceLocation`\n * on lint findings.\n *\n * Parameter references (`$name`) are accepted. This is a syntax check and does\n * not require the parameters to be declared.\n *\n * @example\n * ```typescript\n * import {validate} from '@sanity-labs/groq-wasm'\n *\n * validate('*[_type == \"post\"]')\n * // {ok: true}\n *\n * validate('*[\"é\" == ]')\n * // {\n * // ok: false,\n * // error: {\n * // message: 'unexpected token \"]\", expected expression',\n * // start: 9,\n * // end: 10,\n * // line: 1,\n * // column: 10,\n * // endLine: 1,\n * // endColumn: 11,\n * // },\n * // }\n * ```\n */\nexport function validate(query: string): ValidateResult {\n let parsed: unknown\n try {\n parsed = JSON.parse(callValidate(query))\n } catch (error) {\n if (error instanceof WasmError) {\n throw error\n }\n\n const message = error instanceof Error ? error.message : String(error)\n throw new WasmError(`Validate failed: ${message}`, 'WASM_ERROR')\n }\n\n const payload = readValidatePayload(parsed)\n switch (payload.ok) {\n case true:\n return { ok: true }\n case false:\n return { ok: false, error: toValidateError(query, payload) }\n default: {\n const unexpected: never = payload\n throw new WasmError(`Unexpected validate result: ${JSON.stringify(unexpected)}`, 'WASM_ERROR')\n }\n }\n}\n\ninterface WasmValidateFailure {\n ok: false\n message: string\n start: number\n end: number\n}\n\ntype WasmValidatePayload = { ok: true } | WasmValidateFailure\n\nfunction readValidatePayload(value: unknown): WasmValidatePayload {\n if (!isRecord(value)) {\n throw new WasmError('Validate returned an invalid payload', 'WASM_ERROR')\n }\n\n const ok = value['ok']\n if (ok === true) {\n return { ok: true }\n }\n\n const message = value['message']\n const start = value['start']\n const end = value['end']\n if (\n ok === false &&\n typeof message === 'string' &&\n typeof start === 'number' &&\n typeof end === 'number'\n ) {\n return { ok: false, message, start, end }\n }\n\n throw new WasmError('Validate returned an invalid payload', 'WASM_ERROR')\n}\n\nfunction toValidateError(query: string, failure: WasmValidateFailure): ValidateError {\n const toPosition = createUtf8OffsetMapper(query)\n const start = toPosition(Math.max(0, failure.start))\n const end = toPosition(Math.max(failure.start, failure.end))\n return {\n message: failure.message,\n start: start.index,\n end: end.index,\n line: start.line,\n column: start.column,\n endLine: end.line,\n endColumn: end.column,\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null\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;AAmFO,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,8BAA8B;AAAA,EAC9B,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,YAAY;AAAA,EACZ,iBAAiB;AACnB;AAKO,SAAS,UAAU,YAA4B;AACpD,SAAO,YAAY,UAAU,KAAK,WAAW,QAAQ,MAAM,GAAG;AAChE;;;AClIO,SAAS,cAAc,OAAO;AACjC,MAAI;AACJ,MAAI;AACJ,MAAI;AACA,UAAM,OAAO,kBAAkB,OAAO,KAAK,mBAAmB,KAAK,kBAAkB;AACrF,UAAM,OAAO;AACb,UAAM,MAAM,KAAK,cAAc,MAAM,IAAI;AACzC,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;A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pB,UAAM,IAAI,UAAU,wCAAwC,YAAY;AAAA,EAC1E;AAEA,QAAM,KAAK,MAAM,IAAI;AACrB,MAAI,OAAO,MAAM;AACf,WAAO,EAAE,IAAI,KAAK;AAAA,EACpB;AAEA,QAAM,UAAU,MAAM,SAAS;AAC/B,QAAM,QAAQ,MAAM,OAAO;AAC3B,QAAM,MAAM,MAAM,KAAK;AACvB,MACE,OAAO,SACP,OAAO,YAAY,YACnB,OAAO,UAAU,YACjB,OAAO,QAAQ,UACf;AACA,WAAO,EAAE,IAAI,OAAO,SAAS,OAAO,IAAI;AAAA,EAC1C;AAEA,QAAM,IAAI,UAAU,wCAAwC,YAAY;AAC1E;AAEA,SAAS,gBAAgB,OAAe,SAA6C;AACnF,QAAM,aAAa,uBAAuB,KAAK;AAC/C,QAAM,QAAQ,WAAW,KAAK,IAAI,GAAG,QAAQ,KAAK,CAAC;AACnD,QAAM,MAAM,WAAW,KAAK,IAAI,QAAQ,OAAO,QAAQ,GAAG,CAAC;AAC3D,SAAO;AAAA,IACL,SAAS,QAAQ;AAAA,IACjB,OAAO,MAAM;AAAA,IACb,KAAK,IAAI;AAAA,IACT,MAAM,MAAM;AAAA,IACZ,QAAQ,MAAM;AAAA,IACd,SAAS,IAAI;AAAA,IACb,WAAW,IAAI;AAAA,EACjB;AACF;AAEA,SAAS,SAAS,OAAkD;AAClE,SAAO,OAAO,UAAU,YAAY,UAAU;AAChD;","names":["ptr","extractParams","lint","format","validate"]}
@@ -80,8 +80,8 @@ interface QueryParam {
80
80
  * Error from WASM operations
81
81
  */
82
82
  declare class WasmError extends Error {
83
- readonly code: 'PARSE_ERROR' | 'WASM_ERROR';
84
- constructor(message: string, code: 'PARSE_ERROR' | 'WASM_ERROR');
83
+ readonly code: 'PARSE_ERROR' | 'WASM_ERROR' | 'NOT_INITIALIZED';
84
+ constructor(message: string, code: 'PARSE_ERROR' | 'WASM_ERROR' | 'NOT_INITIALIZED');
85
85
  }
86
86
  /**
87
87
  * Rule ID mapping from Rust (snake_case) to TS (kebab-case)
@@ -10,7 +10,7 @@ import {
10
10
  mapRuleId,
11
11
  mapSeverity,
12
12
  validate
13
- } from "./chunk-XXDG7JJH.js";
13
+ } from "./chunk-PIYLCZE4.js";
14
14
 
15
15
  // src/index.browser.ts
16
16
  var wasmUrl = new URL("../wasm/groq_wasm_bg.wasm", import.meta.url);
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  mapRuleId,
11
11
  mapSeverity,
12
12
  validate
13
- } from "./chunk-XXDG7JJH.js";
13
+ } from "./chunk-PIYLCZE4.js";
14
14
 
15
15
  // src/index.ts
16
16
  import { readFileSync } from "fs";
@@ -0,0 +1,58 @@
1
+ export { DEFAULT_WIDTH, ParamReference, QueryParam, RULE_ID_MAP, ValidateError, ValidateResult, WasmError, WasmFinding, WasmFormatConfig, WasmLintConfig, WasmSeverity, extractParams, format, isValidSyntax, lint, mapRuleId, mapSeverity, validate } from './index.browser.js';
2
+ import '@sanity-labs/lint-core';
3
+
4
+ /**
5
+ * WASM module runtime.
6
+ *
7
+ * Exposes the WASM-backed lint/format/validate calls and init helpers.
8
+ * Byte loading is platform-specific:
9
+ * - `index.ts` reads the file and calls `initWasm` synchronously (Node).
10
+ * - `index.browser.ts` fetches it with top-level await (browser).
11
+ * - `index.lazy.ts` does neither until `load()` or `initWasm()`.
12
+ */
13
+ /**
14
+ * Bytes, a compiled module, or a fetch `Response` accepted by {@link initWasm}.
15
+ * A `Response` initializes asynchronously. The other forms are synchronous.
16
+ */
17
+ type WasmInitSource = ArrayBuffer | Uint8Array | WebAssembly.Module | Response;
18
+ /**
19
+ * Initialize the GROQ WebAssembly module.
20
+ *
21
+ * `ArrayBuffer`, `Uint8Array`, and `WebAssembly.Module` initialize
22
+ * synchronously and this function returns `void`. A `Response` is consumed
23
+ * asynchronously and this function returns a promise. `await initWasm(source)`
24
+ * is valid for every accepted source. A second successful call does nothing.
25
+ *
26
+ * @throws {WasmError} With code `WASM_ERROR` when the bytes cannot be
27
+ * instantiated, or when the module is not initialized yet and `source` is a
28
+ * `Response` that is not ok.
29
+ */
30
+ declare function initWasm(source: ArrayBuffer | Uint8Array | WebAssembly.Module): void;
31
+ declare function initWasm(source: Response): Promise<void>;
32
+
33
+ /**
34
+ * @sanity-labs/groq-wasm — Lazy entry (`@sanity-labs/groq-wasm/lazy`).
35
+ *
36
+ * Re-exports the public API plus `load()` and `initWasm()`. Evaluating this
37
+ * module does not fetch or compile the WebAssembly module and does not use
38
+ * top-level await. Call `load()` (or `initWasm()` with your own bytes) before
39
+ * `lint()`, `format()`, `validate()`, or `extractParams()`.
40
+ *
41
+ * Bundlers that understand `new URL('...', import.meta.url)` rewrite the URL
42
+ * inside `load()` and emit the `.wasm` file as an asset.
43
+ */
44
+
45
+ /**
46
+ * Fetch the packaged WebAssembly module and initialize it.
47
+ *
48
+ * Resolves immediately when the module is already initialized. Concurrent
49
+ * calls share one in-flight request. A rejection leaves the module
50
+ * uninitialized so a later call can retry.
51
+ *
52
+ * @throws {WasmError} With code `WASM_ERROR` when the file cannot be fetched
53
+ * or instantiated.
54
+ */
55
+ declare function load(): Promise<void>;
56
+
57
+ export { initWasm, load };
58
+ export type { WasmInitSource };
@@ -0,0 +1,61 @@
1
+ import {
2
+ DEFAULT_WIDTH,
3
+ RULE_ID_MAP,
4
+ WasmError,
5
+ extractParams,
6
+ format,
7
+ initWasm,
8
+ isValidSyntax,
9
+ isWasmInitialized,
10
+ lint,
11
+ mapRuleId,
12
+ mapSeverity,
13
+ validate
14
+ } from "./chunk-PIYLCZE4.js";
15
+
16
+ // src/index.lazy.ts
17
+ var pendingLoad;
18
+ function load() {
19
+ if (isWasmInitialized()) return Promise.resolve();
20
+ if (!pendingLoad) {
21
+ pendingLoad = fetchAndInit().finally(() => {
22
+ pendingLoad = void 0;
23
+ });
24
+ }
25
+ return pendingLoad;
26
+ }
27
+ async function fetchAndInit() {
28
+ const wasmUrl = new URL("../wasm/groq_wasm_bg.wasm", import.meta.url);
29
+ let response;
30
+ try {
31
+ response = await fetch(wasmUrl);
32
+ } catch (error) {
33
+ const message = error instanceof Error ? error.message : String(error);
34
+ throw new WasmError(
35
+ `Failed to fetch GROQ WASM module from ${wasmUrl.href}: ${message}`,
36
+ "WASM_ERROR"
37
+ );
38
+ }
39
+ if (!response.ok) {
40
+ throw new WasmError(
41
+ `Failed to fetch GROQ WASM module from ${wasmUrl.href}: ${response.status} ${response.statusText}`,
42
+ "WASM_ERROR"
43
+ );
44
+ }
45
+ await initWasm(response);
46
+ }
47
+ export {
48
+ DEFAULT_WIDTH,
49
+ RULE_ID_MAP,
50
+ WasmError,
51
+ extractParams,
52
+ format,
53
+ initWasm,
54
+ isValidSyntax,
55
+ lint,
56
+ load,
57
+ mapRuleId,
58
+ mapSeverity,
59
+ validate
60
+ };
61
+ //# sourceMappingURL=index.lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.lazy.ts"],"sourcesContent":["/**\n * @sanity-labs/groq-wasm — Lazy entry (`@sanity-labs/groq-wasm/lazy`).\n *\n * Re-exports the public API plus `load()` and `initWasm()`. Evaluating this\n * module does not fetch or compile the WebAssembly module and does not use\n * top-level await. Call `load()` (or `initWasm()` with your own bytes) before\n * `lint()`, `format()`, `validate()`, or `extractParams()`.\n *\n * Bundlers that understand `new URL('...', import.meta.url)` rewrite the URL\n * inside `load()` and emit the `.wasm` file as an asset.\n */\n\nimport { WasmError } from './types.js'\nimport { initWasm, isWasmInitialized, type WasmInitSource } from './wasm-loader.js'\n\nexport { initWasm, type WasmInitSource }\nexport * from './public.js'\n\nlet pendingLoad: Promise<void> | undefined\n\n/**\n * Fetch the packaged WebAssembly module and initialize it.\n *\n * Resolves immediately when the module is already initialized. Concurrent\n * calls share one in-flight request. A rejection leaves the module\n * uninitialized so a later call can retry.\n *\n * @throws {WasmError} With code `WASM_ERROR` when the file cannot be fetched\n * or instantiated.\n */\nexport function load(): Promise<void> {\n if (isWasmInitialized()) return Promise.resolve()\n if (!pendingLoad) {\n pendingLoad = fetchAndInit().finally(() => {\n pendingLoad = undefined\n })\n }\n return pendingLoad\n}\n\nasync function fetchAndInit(): Promise<void> {\n const wasmUrl = new URL('../wasm/groq_wasm_bg.wasm', import.meta.url)\n let response: Response\n try {\n response = await fetch(wasmUrl)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new WasmError(\n `Failed to fetch GROQ WASM module from ${wasmUrl.href}: ${message}`,\n 'WASM_ERROR'\n )\n }\n\n if (!response.ok) {\n throw new WasmError(\n `Failed to fetch GROQ WASM module from ${wasmUrl.href}: ${response.status} ${response.statusText}`,\n 'WASM_ERROR'\n )\n }\n\n await initWasm(response)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,IAAI;AAYG,SAAS,OAAsB;AACpC,MAAI,kBAAkB,EAAG,QAAO,QAAQ,QAAQ;AAChD,MAAI,CAAC,aAAa;AAChB,kBAAc,aAAa,EAAE,QAAQ,MAAM;AACzC,oBAAc;AAAA,IAChB,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEA,eAAe,eAA8B;AAC3C,QAAM,UAAU,IAAI,IAAI,6BAA6B,YAAY,GAAG;AACpE,MAAI;AACJ,MAAI;AACF,eAAW,MAAM,MAAM,OAAO;AAAA,EAChC,SAAS,OAAO;AACd,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,UAAM,IAAI;AAAA,MACR,yCAAyC,QAAQ,IAAI,KAAK,OAAO;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI;AAAA,MACR,yCAAyC,QAAQ,IAAI,KAAK,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,MAChG;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,QAAQ;AACzB;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity-labs/groq-wasm",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "WASM bindings for GROQ linting and formatting (groq-lint + groq-format)",
5
5
  "keywords": [
6
6
  "sanity",
@@ -23,7 +23,13 @@
23
23
  "types": "./dist/index.d.ts",
24
24
  "browser": "./dist/index.browser.js",
25
25
  "default": "./dist/index.js"
26
- }
26
+ },
27
+ "./lazy": {
28
+ "types": "./dist/index.lazy.d.ts",
29
+ "import": "./dist/index.lazy.js",
30
+ "default": "./dist/index.lazy.js"
31
+ },
32
+ "./wasm": "./wasm/groq_wasm_bg.wasm"
27
33
  },
28
34
  "types": "./dist/index.d.ts",
29
35
  "files": [
package/wasm/groq_wasm.js CHANGED
@@ -45,23 +45,24 @@ export function extractParams(query) {
45
45
  * @returns {string}
46
46
  */
47
47
  export function format(query, width) {
48
- let deferred3_0;
49
- let deferred3_1;
48
+ let deferred4_0;
49
+ let deferred4_1;
50
50
  try {
51
+ const val2 = +(isLikeNone(width) ? Number.MAX_SAFE_INTEGER : (width) >>> 0);
51
52
  const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
52
53
  const len0 = WASM_VECTOR_LEN;
53
- const ret = wasm.format(ptr0, len0, isLikeNone(width) ? Number.MAX_SAFE_INTEGER : (width) >>> 0);
54
- var ptr2 = ret[0];
55
- var len2 = ret[1];
54
+ const ret = wasm.format(ptr0, len0, val2);
55
+ var ptr3 = ret[0];
56
+ var len3 = ret[1];
56
57
  if (ret[3]) {
57
- ptr2 = 0; len2 = 0;
58
+ ptr3 = 0; len3 = 0;
58
59
  throw takeFromExternrefTable0(ret[2]);
59
60
  }
60
- deferred3_0 = ptr2;
61
- deferred3_1 = len2;
62
- return getStringFromWasm0(ptr2, len2);
61
+ deferred4_0 = ptr3;
62
+ deferred4_1 = len3;
63
+ return getStringFromWasm0(ptr3, len3);
63
64
  } finally {
64
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
65
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
65
66
  }
66
67
  }
67
68
 
@@ -142,16 +143,16 @@ function __wbg_get_imports() {
142
143
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
143
144
  }
144
145
  },
145
- __wbg_new_227d7c05414eb861: function() {
146
+ __wbg_new_bb74001155cb8ca8: function() {
146
147
  const ret = new Error();
147
148
  return ret;
148
149
  },
149
- __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
150
+ __wbg_stack_575c4e0918581b9c: function(arg0, arg1) {
150
151
  const ret = arg1.stack;
151
152
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
152
153
  const len1 = WASM_VECTOR_LEN;
153
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
154
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
154
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
155
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
155
156
  },
156
157
  __wbindgen_generic_0000000000000001: function(arg0, arg1) {
157
158
  // Cast intrinsic for `Ref(String) -> Externref`.
@@ -160,12 +161,11 @@ function __wbg_get_imports() {
160
161
  },
161
162
  __wbindgen_init_externref_table: function() {
162
163
  const table = wasm.__wbindgen_externrefs;
163
- const offset = table.grow(4);
164
164
  table.set(0, undefined);
165
- table.set(offset + 0, undefined);
166
- table.set(offset + 1, null);
167
- table.set(offset + 2, true);
168
- table.set(offset + 3, false);
165
+ table.set(1024, undefined);
166
+ table.set(1025, null);
167
+ table.set(1026, true);
168
+ table.set(1027, false);
169
169
  },
170
170
  };
171
171
  return {
@@ -183,7 +183,8 @@ function getDataViewMemory0() {
183
183
  }
184
184
 
185
185
  function getStringFromWasm0(ptr, len) {
186
- return decodeText(ptr >>> 0, len);
186
+ ptr = ptr >>> 0;
187
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
187
188
  }
188
189
 
189
190
  let cachedUint8ArrayMemory0 = null;
@@ -241,18 +242,18 @@ function takeFromExternrefTable0(idx) {
241
242
  return value;
242
243
  }
243
244
 
244
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
245
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
245
246
  cachedTextDecoder.decode();
246
247
  const MAX_SAFARI_DECODE_BYTES = 2146435072;
247
248
  let numBytesDecoded = 0;
248
- function decodeText(ptr, len) {
249
- numBytesDecoded += len;
249
+ function decodeText(bytes) {
250
+ numBytesDecoded += bytes.length;
250
251
  if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
251
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
252
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
252
253
  cachedTextDecoder.decode();
253
- numBytesDecoded = len;
254
+ numBytesDecoded = bytes.length;
254
255
  }
255
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
256
+ return cachedTextDecoder.decode(bytes);
256
257
  }
257
258
 
258
259
  const cachedTextEncoder = new TextEncoder();
@@ -340,9 +341,17 @@ function initSync(module) {
340
341
  return __wbg_finalize_init(instance, module);
341
342
  }
342
343
 
344
+ let __wbg_init_promise;
343
345
  async function __wbg_init(module_or_path) {
344
346
  if (wasm !== undefined) return wasm;
347
+ if (__wbg_init_promise === undefined) {
348
+ __wbg_init_promise = __wbg_init_once(module_or_path);
349
+ __wbg_init_promise.catch(() => { __wbg_init_promise = undefined; });
350
+ }
351
+ return __wbg_init_promise;
352
+ }
345
353
 
354
+ async function __wbg_init_once(module_or_path) {
346
355
 
347
356
  if (module_or_path !== undefined) {
348
357
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
Binary file
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts","../wasm/groq_wasm.js","../src/wasm-loader.ts","../src/offsets.ts","../src/params.ts","../src/lint.ts","../src/format.ts","../src/validate.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 offset into the UTF-8 encoding of the query (0-based) */\n start: number\n /** End offset into the UTF-8 encoding of the query (0-based, exclusive) */\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 * A parameter reference from the Rust parser (JSON format from WASM)\n */\nexport interface WasmParamReference {\n /** Parameter name without the `$` */\n name: string\n /** Start byte offset of the `$` (0-based, UTF-8) */\n start: number\n /** End byte offset, exclusive (0-based, UTF-8) */\n end: number\n}\n\n/**\n * One `$name` reference in a query, from {@link extractParams}.\n *\n * `start` and `end` are indices into the JavaScript query string (UTF-16 code\n * units), not UTF-8 byte offsets. `start` is inclusive and `end` is exclusive,\n * so `query.slice(start, end)` is `\"$name\"`. Lines and columns are 1-based,\n * and columns count UTF-16 code units, matching `SourceLocation` on lint\n * findings.\n */\nexport interface ParamReference {\n /** Inclusive start index of the `$`, 0-based UTF-16 code units. */\n start: number\n /** Exclusive end index, 0-based UTF-16 code units. */\n end: number\n /** 1-based line number of `start`. */\n line: number\n /** 1-based column of `start`, counted in UTF-16 code units. */\n column: number\n /** 1-based line number of `end`. */\n endLine: number\n /** 1-based column of `end`, counted in UTF-16 code units. */\n endColumn: number\n}\n\n/**\n * A query parameter referenced by a GROQ query, from {@link extractParams}.\n */\nexport interface QueryParam {\n /** Parameter name without the `$`, e.g. `\"type\"` for `$type`. */\n name: string\n /** Every reference to this parameter, in source order. Never empty. */\n references: ParamReference[]\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 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 unlimited_query: 'unlimited-query',\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/**\n * A GROQ syntax error from `validate`.\n *\n * `start` and `end` are indices into the JavaScript query string (UTF-16 code\n * units), not UTF-8 byte offsets. `start` is inclusive and `end` is exclusive,\n * so `query.slice(start, end)` is the reported span. groq-parser reports UTF-8\n * byte offsets; `validate` converts them. A zero-width span (`start === end`)\n * is a caret on a token boundary.\n *\n * `line` / `column` locate `start`, and `endLine` / `endColumn` locate `end`.\n * Lines and columns are 1-based. Columns count UTF-16 code units, matching\n * `SourceLocation` on lint findings.\n */\nexport interface ValidateError {\n /** Parser message, without a serialized position suffix. */\n message: string\n /** Inclusive start index, 0-based UTF-16 code units. */\n start: number\n /** Exclusive end index, 0-based UTF-16 code units. */\n end: number\n /** 1-based line number of `start`. */\n line: number\n /** 1-based column of `start`, counted in UTF-16 code units. */\n column: number\n /** 1-based line number of `end`. */\n endLine: number\n /** 1-based column of `end`, counted in UTF-16 code units. */\n endColumn: number\n}\n\n/**\n * Result of {@link validate}.\n *\n * Syntax errors are values, not thrown exceptions. `lint` and `format` still\n * throw {@link WasmError} when a query does not parse.\n */\nexport type ValidateResult = { ok: true } | { ok: false; error: ValidateError }\n","/* @ts-self-types=\"./groq_wasm.d.ts\" */\n\n/**\n * List every query parameter a GROQ query references, as JSON.\n *\n * Returns one entry per reference, ordered by `start`. Byte offsets are\n * UTF-8 offsets into `query`; the JavaScript wrapper converts them to UTF-16\n * code unit indices. Parameters bound by a custom function (`fn ns::f($p)`)\n * are omitted inside that function's body.\n * @param {string} query\n * @returns {string}\n */\nexport function extractParams(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.extractParams(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\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) ? Number.MAX_SAFE_INTEGER : (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\n/**\n * Parse a GROQ query and return a JSON validation result.\n *\n * Byte offsets in the JSON are UTF-8 offsets into `query`. The JavaScript\n * wrapper converts them to UTF-16 code unit indices.\n *\n * Success is `{\"ok\":true}`. A syntax error is\n * `{\"ok\":false,\"message\":\"...\",\"start\":N,\"end\":M}` where `start` is inclusive,\n * `end` is exclusive, and the two are equal when the parser reports a caret\n * rather than a token span.\n * @param {string} query\n * @returns {string}\n */\nexport function validate(query) {\n let deferred2_0;\n let deferred2_1;\n try {\n const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.validate(ptr0, len0);\n deferred2_0 = ret[0];\n deferred2_1 = ret[1];\n return getStringFromWasm0(ret[0], ret[1]);\n } finally {\n wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);\n }\n}\nfunction __wbg_get_imports() {\n const import0 = {\n __proto__: null,\n __wbg_error_757e9472f8410341: 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_generic_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 return decodeText(ptr >>> 0, 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, wasmInstance, wasm;\nfunction __wbg_finalize_init(instance, module) {\n wasmInstance = instance;\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 (!module.ok) {\n throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);\n }\n\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n const validResponse = 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/validate 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 callExtractParams(query: string): string {\n return wasmModule.extractParams(query)\n}\n\nexport function callFormat(query: string, width?: number): string {\n return wasmModule.format(query, width ?? null)\n}\n\nexport function callValidate(query: string): string {\n return wasmModule.validate(query)\n}\n","/**\n * Conversion from groq-parser's UTF-8 byte offsets to JavaScript string\n * coordinates.\n *\n * wasm-bindgen passes the query to Rust with `TextEncoder`, so parser spans\n * are byte offsets into the query's UTF-8 encoding. JavaScript strings are\n * UTF-16, so those offsets stop matching string indices once the query\n * contains non-ASCII text.\n */\n\n/** A position in a JavaScript string. */\nexport interface TextPosition {\n /** 0-based UTF-16 code unit index. */\n index: number\n /** 1-based line. Advances on `\\n`. */\n line: number\n /** 1-based column, counted in UTF-16 code units. */\n column: number\n}\n\n/**\n * Create a function that maps UTF-8 byte offsets in `text` to\n * {@link TextPosition}s.\n *\n * The mapper resumes from the previous result, so calling it with ascending\n * offsets walks `text` once. A smaller offset restarts from the beginning.\n * An offset inside a code point resolves to the start of that code point, and\n * an offset past the end resolves to the end of `text`.\n */\nexport function createUtf8OffsetMapper(text: string): (byteOffset: number) => TextPosition {\n let index = 0\n let bytes = 0\n let line = 1\n let column = 1\n\n return (byteOffset) => {\n if (byteOffset < bytes) {\n index = 0\n bytes = 0\n line = 1\n column = 1\n }\n\n while (index < text.length && bytes < byteOffset) {\n const codePoint = text.codePointAt(index) ?? 0\n const byteWidth = utf8ByteLength(codePoint)\n if (bytes + byteWidth > byteOffset) {\n break\n }\n\n const utf16Width = codePoint > 0xffff ? 2 : 1\n bytes += byteWidth\n index += utf16Width\n\n if (codePoint === 0x0a) {\n line += 1\n column = 1\n } else {\n column += utf16Width\n }\n }\n\n return { index, line, column }\n }\n}\n\n/**\n * UTF-8 byte length of one code point, matching `TextEncoder`.\n *\n * Unpaired surrogates fall in the 3-byte range. `TextEncoder` replaces each\n * of them with U+FFFD, which is also 3 bytes.\n */\nfunction utf8ByteLength(codePoint: number): number {\n if (codePoint <= 0x7f) return 1\n if (codePoint <= 0x7ff) return 2\n if (codePoint <= 0xffff) return 3\n return 4\n}\n","/**\n * GROQ query parameter extraction via WASM.\n *\n * Wraps groq-parser's `ParseResult::referenced_params`. The parser reports\n * UTF-8 byte offsets; this module converts them to UTF-16 code unit indices.\n */\n\nimport { createUtf8OffsetMapper } from './offsets.js'\nimport { WasmError, type QueryParam, type WasmParamReference } from './types.js'\nimport { callExtractParams } from './wasm-loader.js'\n\n/**\n * List the query parameters (`$name`) a GROQ query references.\n *\n * Returns one entry per distinct name, in order of first reference. Each entry\n * lists every reference to that name in source order. Names do not include\n * the `$`, so they match the keys of the params object passed to a client.\n *\n * Parameters bound by a custom function (`fn ns::f($p) = ...`) are local to\n * that function's body and are not reported from inside it. `$name` text\n * inside string literals and comments is not a reference.\n *\n * Reference `start` / `end` are 0-based UTF-16 code unit indices into\n * `query` (`end` is exclusive), so `query.slice(start, end)` is `\"$name\"`.\n *\n * An empty or whitespace-only query returns `[]`, like `lint('')`.\n *\n * @param query - The GROQ query string\n * @returns Referenced parameters, in order of first reference\n * @throws {WasmError} With code `PARSE_ERROR` if the query does not parse\n *\n * @example\n * ```typescript\n * import {extractParams} from '@sanity-labs/groq-wasm'\n *\n * extractParams('*[_type == $type][0...$limit]').map((param) => param.name)\n * // ['type', 'limit']\n * ```\n */\nexport function extractParams(query: string): QueryParam[] {\n if (!query.trim()) {\n return []\n }\n\n let resultJson: string\n try {\n resultJson = callExtractParams(query)\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(`Extract params failed: ${message}`, 'WASM_ERROR')\n }\n\n const wasmReferences: WasmParamReference[] = JSON.parse(resultJson)\n const toPosition = createUtf8OffsetMapper(query)\n const params = new Map<string, QueryParam>()\n\n for (const reference of wasmReferences) {\n const start = toPosition(reference.start)\n const end = toPosition(reference.end)\n\n let param = params.get(reference.name)\n if (!param) {\n param = { name: reference.name, references: [] }\n params.set(reference.name, param)\n }\n\n param.references.push({\n start: start.index,\n end: end.index,\n line: start.line,\n column: start.column,\n endLine: end.line,\n endColumn: end.column,\n })\n }\n\n return [...params.values()]\n}\n","/**\n * GROQ Linting via WASM\n *\n * Wraps the Rust groq-lint library compiled to WASM.\n */\n\nimport type { Finding, SourceSpan } from '@sanity-labs/lint-core'\n\nimport { createUtf8OffsetMapper } from './offsets.js'\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 * Finding spans are source locations in JavaScript string coordinates.\n * The Rust linter reports UTF-8 byte offsets; `line`, `column`, and `offset`\n * below are converted from those bytes. `column` counts UTF-16 code units.\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 UTF-8 byte offsets to a line/column source span.\n *\n * `column` is a 1-based count of UTF-16 code units and `offset` is the\n * matching JavaScript string index. See {@link createUtf8OffsetMapper}.\n */\nfunction byteSpanToSourceSpan(startByte: number, endByte: number, query: string): SourceSpan {\n const toPosition = createUtf8OffsetMapper(query)\n const start = toPosition(startByte)\n const end = toPosition(endByte)\n return {\n start: { line: start.line, column: start.column, offset: start.index },\n end: { line: end.line, column: end.column, offset: end.index },\n }\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","/**\n * GROQ syntax validation via WASM.\n *\n * Wraps groq-parser's structured parse errors. The parser reports UTF-8 byte\n * offsets; this module converts them to UTF-16 code unit indices.\n */\n\nimport { createUtf8OffsetMapper } from './offsets.js'\nimport { WasmError, type ValidateError, type ValidateResult } from './types.js'\nimport { callValidate } from './wasm-loader.js'\n\n/**\n * Parse a GROQ query.\n *\n * Returns `{ok: true}` when the query parses. Syntax errors are returned as\n * `{ok: false, error}` and are not thrown. `lint` and `format` still throw\n * {@link WasmError} on invalid syntax; this function does not change that.\n *\n * `error.start` and `error.end` are 0-based UTF-16 code unit indices into\n * `query` (`end` is exclusive), which is what JavaScript strings and editors\n * such as Vision use. groq-parser's `ParseError` positions are UTF-8 byte\n * offsets (`Position.start` / `Position.end` in groq-parser-rs). An empty or\n * whitespace-only query is a syntax error (`\"no query\"`) at offset 0, unlike\n * `lint('')` and `format('')`, which treat it as nothing to do.\n *\n * `line` / `column` locate `start`, and `endLine` / `endColumn` locate `end`.\n * They are 1-based. Columns count UTF-16 code units, matching `SourceLocation`\n * on lint findings.\n *\n * Parameter references (`$name`) are accepted. This is a syntax check and does\n * not require the parameters to be declared.\n *\n * @example\n * ```typescript\n * import {validate} from '@sanity-labs/groq-wasm'\n *\n * validate('*[_type == \"post\"]')\n * // {ok: true}\n *\n * validate('*[\"é\" == ]')\n * // {\n * // ok: false,\n * // error: {\n * // message: 'unexpected token \"]\", expected expression',\n * // start: 9,\n * // end: 10,\n * // line: 1,\n * // column: 10,\n * // endLine: 1,\n * // endColumn: 11,\n * // },\n * // }\n * ```\n */\nexport function validate(query: string): ValidateResult {\n let parsed: unknown\n try {\n parsed = JSON.parse(callValidate(query))\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new WasmError(`Validate failed: ${message}`, 'WASM_ERROR')\n }\n\n const payload = readValidatePayload(parsed)\n switch (payload.ok) {\n case true:\n return { ok: true }\n case false:\n return { ok: false, error: toValidateError(query, payload) }\n default: {\n const unexpected: never = payload\n throw new WasmError(`Unexpected validate result: ${JSON.stringify(unexpected)}`, 'WASM_ERROR')\n }\n }\n}\n\ninterface WasmValidateFailure {\n ok: false\n message: string\n start: number\n end: number\n}\n\ntype WasmValidatePayload = { ok: true } | WasmValidateFailure\n\nfunction readValidatePayload(value: unknown): WasmValidatePayload {\n if (!isRecord(value)) {\n throw new WasmError('Validate returned an invalid payload', 'WASM_ERROR')\n }\n\n const ok = value['ok']\n if (ok === true) {\n return { ok: true }\n }\n\n const message = value['message']\n const start = value['start']\n const end = value['end']\n if (\n ok === false &&\n typeof message === 'string' &&\n typeof start === 'number' &&\n typeof end === 'number'\n ) {\n return { ok: false, message, start, end }\n }\n\n throw new WasmError('Validate returned an invalid payload', 'WASM_ERROR')\n}\n\nfunction toValidateError(query: string, failure: WasmValidateFailure): ValidateError {\n const toPosition = createUtf8OffsetMapper(query)\n const start = toPosition(Math.max(0, failure.start))\n const end = toPosition(Math.max(failure.start, failure.end))\n return {\n message: failure.message,\n start: start.index,\n end: end.index,\n line: start.line,\n column: start.column,\n endLine: end.line,\n endColumn: end.column,\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null\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;AAmFO,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,8BAA8B;AAAA,EAC9B,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,YAAY;AAAA,EACZ,iBAAiB;AACnB;AAKO,SAAS,UAAU,YAA4B;AACpD,SAAO,YAAY,UAAU,KAAK,WAAW,QAAQ,MAAM,GAAG;AAChE;;;AClIO,SAAS,cAAc,OAAO;AACjC,MAAI;AACJ,MAA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