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