@sanity-labs/groq-wasm 0.1.0 → 0.3.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/dist/groq_wasm-Z3ZUBGZA.js +258 -0
- package/dist/groq_wasm-Z3ZUBGZA.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -9
- package/dist/index.js.map +1 -1
- package/package.json +5 -13
- package/wasm/groq_wasm.d.ts +37 -0
- package/wasm/groq_wasm.js +307 -0
- package/wasm/groq_wasm_bg.wasm +0 -0
- package/dist/index.cjs +0 -253
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -160
- package/wasm/groq_wasm.cjs +0 -213
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// wasm/groq_wasm.js
|
|
2
|
+
function format(query, width) {
|
|
3
|
+
let deferred3_0;
|
|
4
|
+
let deferred3_1;
|
|
5
|
+
try {
|
|
6
|
+
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
7
|
+
const len0 = WASM_VECTOR_LEN;
|
|
8
|
+
const ret = wasm.format(ptr0, len0, isLikeNone(width) ? 4294967297 : width >>> 0);
|
|
9
|
+
var ptr2 = ret[0];
|
|
10
|
+
var len2 = ret[1];
|
|
11
|
+
if (ret[3]) {
|
|
12
|
+
ptr2 = 0;
|
|
13
|
+
len2 = 0;
|
|
14
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
15
|
+
}
|
|
16
|
+
deferred3_0 = ptr2;
|
|
17
|
+
deferred3_1 = len2;
|
|
18
|
+
return getStringFromWasm0(ptr2, len2);
|
|
19
|
+
} finally {
|
|
20
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function init() {
|
|
24
|
+
wasm.init();
|
|
25
|
+
}
|
|
26
|
+
function lint(query) {
|
|
27
|
+
let deferred3_0;
|
|
28
|
+
let deferred3_1;
|
|
29
|
+
try {
|
|
30
|
+
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
31
|
+
const len0 = WASM_VECTOR_LEN;
|
|
32
|
+
const ret = wasm.lint(ptr0, len0);
|
|
33
|
+
var ptr2 = ret[0];
|
|
34
|
+
var len2 = ret[1];
|
|
35
|
+
if (ret[3]) {
|
|
36
|
+
ptr2 = 0;
|
|
37
|
+
len2 = 0;
|
|
38
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
39
|
+
}
|
|
40
|
+
deferred3_0 = ptr2;
|
|
41
|
+
deferred3_1 = len2;
|
|
42
|
+
return getStringFromWasm0(ptr2, len2);
|
|
43
|
+
} finally {
|
|
44
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function __wbg_get_imports() {
|
|
48
|
+
const import0 = {
|
|
49
|
+
__proto__: null,
|
|
50
|
+
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
51
|
+
let deferred0_0;
|
|
52
|
+
let deferred0_1;
|
|
53
|
+
try {
|
|
54
|
+
deferred0_0 = arg0;
|
|
55
|
+
deferred0_1 = arg1;
|
|
56
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
57
|
+
} finally {
|
|
58
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
__wbg_new_227d7c05414eb861: function() {
|
|
62
|
+
const ret = new Error();
|
|
63
|
+
return ret;
|
|
64
|
+
},
|
|
65
|
+
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
66
|
+
const ret = arg1.stack;
|
|
67
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
68
|
+
const len1 = WASM_VECTOR_LEN;
|
|
69
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
70
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
71
|
+
},
|
|
72
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
73
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
74
|
+
return ret;
|
|
75
|
+
},
|
|
76
|
+
__wbindgen_init_externref_table: function() {
|
|
77
|
+
const table = wasm.__wbindgen_externrefs;
|
|
78
|
+
const offset = table.grow(4);
|
|
79
|
+
table.set(0, void 0);
|
|
80
|
+
table.set(offset + 0, void 0);
|
|
81
|
+
table.set(offset + 1, null);
|
|
82
|
+
table.set(offset + 2, true);
|
|
83
|
+
table.set(offset + 3, false);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
__proto__: null,
|
|
88
|
+
"./groq_wasm_bg.js": import0
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
var cachedDataViewMemory0 = null;
|
|
92
|
+
function getDataViewMemory0() {
|
|
93
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
|
|
94
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
95
|
+
}
|
|
96
|
+
return cachedDataViewMemory0;
|
|
97
|
+
}
|
|
98
|
+
function getStringFromWasm0(ptr, len) {
|
|
99
|
+
ptr = ptr >>> 0;
|
|
100
|
+
return decodeText(ptr, len);
|
|
101
|
+
}
|
|
102
|
+
var cachedUint8ArrayMemory0 = null;
|
|
103
|
+
function getUint8ArrayMemory0() {
|
|
104
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
105
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
106
|
+
}
|
|
107
|
+
return cachedUint8ArrayMemory0;
|
|
108
|
+
}
|
|
109
|
+
function isLikeNone(x) {
|
|
110
|
+
return x === void 0 || x === null;
|
|
111
|
+
}
|
|
112
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
113
|
+
if (realloc === void 0) {
|
|
114
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
115
|
+
const ptr2 = malloc(buf.length, 1) >>> 0;
|
|
116
|
+
getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
|
|
117
|
+
WASM_VECTOR_LEN = buf.length;
|
|
118
|
+
return ptr2;
|
|
119
|
+
}
|
|
120
|
+
let len = arg.length;
|
|
121
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
122
|
+
const mem = getUint8ArrayMemory0();
|
|
123
|
+
let offset = 0;
|
|
124
|
+
for (; offset < len; offset++) {
|
|
125
|
+
const code = arg.charCodeAt(offset);
|
|
126
|
+
if (code > 127) break;
|
|
127
|
+
mem[ptr + offset] = code;
|
|
128
|
+
}
|
|
129
|
+
if (offset !== len) {
|
|
130
|
+
if (offset !== 0) {
|
|
131
|
+
arg = arg.slice(offset);
|
|
132
|
+
}
|
|
133
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
134
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
135
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
136
|
+
offset += ret.written;
|
|
137
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
138
|
+
}
|
|
139
|
+
WASM_VECTOR_LEN = offset;
|
|
140
|
+
return ptr;
|
|
141
|
+
}
|
|
142
|
+
function takeFromExternrefTable0(idx) {
|
|
143
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
144
|
+
wasm.__externref_table_dealloc(idx);
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
148
|
+
cachedTextDecoder.decode();
|
|
149
|
+
var MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
150
|
+
var numBytesDecoded = 0;
|
|
151
|
+
function decodeText(ptr, len) {
|
|
152
|
+
numBytesDecoded += len;
|
|
153
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
154
|
+
cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
155
|
+
cachedTextDecoder.decode();
|
|
156
|
+
numBytesDecoded = len;
|
|
157
|
+
}
|
|
158
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
159
|
+
}
|
|
160
|
+
var cachedTextEncoder = new TextEncoder();
|
|
161
|
+
if (!("encodeInto" in cachedTextEncoder)) {
|
|
162
|
+
cachedTextEncoder.encodeInto = function(arg, view) {
|
|
163
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
164
|
+
view.set(buf);
|
|
165
|
+
return {
|
|
166
|
+
read: arg.length,
|
|
167
|
+
written: buf.length
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
var WASM_VECTOR_LEN = 0;
|
|
172
|
+
var wasmModule;
|
|
173
|
+
var wasm;
|
|
174
|
+
function __wbg_finalize_init(instance, module) {
|
|
175
|
+
wasm = instance.exports;
|
|
176
|
+
wasmModule = module;
|
|
177
|
+
cachedDataViewMemory0 = null;
|
|
178
|
+
cachedUint8ArrayMemory0 = null;
|
|
179
|
+
wasm.__wbindgen_start();
|
|
180
|
+
return wasm;
|
|
181
|
+
}
|
|
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
|
+
function initSync(module) {
|
|
217
|
+
if (wasm !== void 0) return wasm;
|
|
218
|
+
if (module !== void 0) {
|
|
219
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
220
|
+
({ module } = module);
|
|
221
|
+
} else {
|
|
222
|
+
console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const imports = __wbg_get_imports();
|
|
226
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
227
|
+
module = new WebAssembly.Module(module);
|
|
228
|
+
}
|
|
229
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
230
|
+
return __wbg_finalize_init(instance, module);
|
|
231
|
+
}
|
|
232
|
+
async function __wbg_init(module_or_path) {
|
|
233
|
+
if (wasm !== void 0) return wasm;
|
|
234
|
+
if (module_or_path !== void 0) {
|
|
235
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
236
|
+
({ module_or_path } = module_or_path);
|
|
237
|
+
} else {
|
|
238
|
+
console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (module_or_path === void 0) {
|
|
242
|
+
module_or_path = new URL("groq_wasm_bg.wasm", import.meta.url);
|
|
243
|
+
}
|
|
244
|
+
const imports = __wbg_get_imports();
|
|
245
|
+
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
|
|
246
|
+
module_or_path = fetch(module_or_path);
|
|
247
|
+
}
|
|
248
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
249
|
+
return __wbg_finalize_init(instance, module);
|
|
250
|
+
}
|
|
251
|
+
export {
|
|
252
|
+
__wbg_init as default,
|
|
253
|
+
format,
|
|
254
|
+
init,
|
|
255
|
+
initSync,
|
|
256
|
+
lint
|
|
257
|
+
};
|
|
258
|
+
//# sourceMappingURL=groq_wasm-Z3ZUBGZA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../wasm/groq_wasm.js"],"sourcesContent":["/* @ts-self-types=\"./groq_wasm.d.ts\" */\n\n/**\n * Format a GROQ query.\n *\n * # Arguments\n * * `query` - The GROQ query string to format\n * * `width` - Maximum line width (default: 80)\n *\n * # Returns\n * The formatted query string\n * @param {string} query\n * @param {number | null} [width]\n * @returns {string}\n */\nexport function format(query, width) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.format(ptr0, len0, isLikeNone(width) ? 0x100000001 : (width) >>> 0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\n\nexport function init() {\n wasm.init();\n}\n\n/**\n * Lint a GROQ query and return findings as JSON.\n *\n * # Arguments\n * * `query` - The GROQ query string to lint\n *\n * # Returns\n * A JSON string containing an array of findings\n * @param {string} query\n * @returns {string}\n */\nexport function lint(query) {\n let deferred3_0;\n let deferred3_1;\n try {\n const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.lint(ptr0, len0);\n var ptr2 = ret[0];\n var len2 = ret[1];\n if (ret[3]) {\n ptr2 = 0; len2 = 0;\n throw takeFromExternrefTable0(ret[2]);\n }\n deferred3_0 = ptr2;\n deferred3_1 = len2;\n return getStringFromWasm0(ptr2, len2);\n } finally {\n wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);\n }\n}\n\nfunction __wbg_get_imports() {\n const import0 = {\n __proto__: null,\n __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {\n let deferred0_0;\n let deferred0_1;\n try {\n deferred0_0 = arg0;\n deferred0_1 = arg1;\n console.error(getStringFromWasm0(arg0, arg1));\n } finally {\n wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);\n }\n },\n __wbg_new_227d7c05414eb861: function() {\n const ret = new Error();\n return ret;\n },\n __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {\n const ret = arg1.stack;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);\n const len1 = WASM_VECTOR_LEN;\n getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);\n getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);\n },\n __wbindgen_cast_0000000000000001: function(arg0, arg1) {\n // Cast intrinsic for `Ref(String) -> Externref`.\n const ret = getStringFromWasm0(arg0, arg1);\n return ret;\n },\n __wbindgen_init_externref_table: function() {\n const table = wasm.__wbindgen_externrefs;\n const offset = table.grow(4);\n table.set(0, undefined);\n table.set(offset + 0, undefined);\n table.set(offset + 1, null);\n table.set(offset + 2, true);\n table.set(offset + 3, false);\n },\n };\n return {\n __proto__: null,\n \"./groq_wasm_bg.js\": import0,\n };\n}\n\nlet cachedDataViewMemory0 = null;\nfunction getDataViewMemory0() {\n if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {\n cachedDataViewMemory0 = new DataView(wasm.memory.buffer);\n }\n return cachedDataViewMemory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return decodeText(ptr, len);\n}\n\nlet cachedUint8ArrayMemory0 = null;\nfunction getUint8ArrayMemory0() {\n if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {\n cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8ArrayMemory0;\n}\n\nfunction isLikeNone(x) {\n return x === undefined || x === null;\n}\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8ArrayMemory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;\n const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);\n const ret = cachedTextEncoder.encodeInto(arg, view);\n\n offset += ret.written;\n ptr = realloc(ptr, len, offset, 1) >>> 0;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction takeFromExternrefTable0(idx) {\n const value = wasm.__wbindgen_externrefs.get(idx);\n wasm.__externref_table_dealloc(idx);\n return value;\n}\n\nlet cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\ncachedTextDecoder.decode();\nconst MAX_SAFARI_DECODE_BYTES = 2146435072;\nlet numBytesDecoded = 0;\nfunction decodeText(ptr, len) {\n numBytesDecoded += len;\n if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {\n cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\n cachedTextDecoder.decode();\n numBytesDecoded = len;\n }\n return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));\n}\n\nconst cachedTextEncoder = new TextEncoder();\n\nif (!('encodeInto' in cachedTextEncoder)) {\n cachedTextEncoder.encodeInto = function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n };\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nlet wasmModule, wasm;\nfunction __wbg_finalize_init(instance, module) {\n wasm = instance.exports;\n wasmModule = module;\n cachedDataViewMemory0 = null;\n cachedUint8ArrayMemory0 = null;\n wasm.__wbindgen_start();\n return wasm;\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n const validResponse = module.ok && expectedResponseType(module.type);\n\n if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {\n console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\", e);\n\n } else { throw e; }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n\n function expectedResponseType(type) {\n switch (type) {\n case 'basic': case 'cors': case 'default': return true;\n }\n return false;\n }\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n\n if (module !== undefined) {\n if (Object.getPrototypeOf(module) === Object.prototype) {\n ({module} = module)\n } else {\n console.warn('using deprecated parameters for `initSync()`; pass a single object instead')\n }\n }\n\n const imports = __wbg_get_imports();\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n const instance = new WebAssembly.Instance(module, imports);\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(module_or_path) {\n if (wasm !== undefined) return wasm;\n\n\n if (module_or_path !== undefined) {\n if (Object.getPrototypeOf(module_or_path) === Object.prototype) {\n ({module_or_path} = module_or_path)\n } else {\n console.warn('using deprecated parameters for the initialization function; pass a single object instead')\n }\n }\n\n if (module_or_path === undefined) {\n module_or_path = new URL('groq_wasm_bg.wasm', import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {\n module_or_path = fetch(module_or_path);\n }\n\n const { instance, module } = await __wbg_load(await module_or_path, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync, __wbg_init as default };\n"],"mappings":";AAeO,SAAS,OAAO,OAAO,OAAO;AACjC,MAAI;AACJ,MAAI;AACJ,MAAI;AACA,UAAM,OAAO,kBAAkB,OAAO,KAAK,mBAAmB,KAAK,kBAAkB;AACrF,UAAM,OAAO;AACb,UAAM,MAAM,KAAK,OAAO,MAAM,MAAM,WAAW,KAAK,IAAI,aAAe,UAAW,CAAC;AACnF,QAAI,OAAO,IAAI,CAAC;AAChB,QAAI,OAAO,IAAI,CAAC;AAChB,QAAI,IAAI,CAAC,GAAG;AACR,aAAO;AAAG,aAAO;AACjB,YAAM,wBAAwB,IAAI,CAAC,CAAC;AAAA,IACxC;AACA,kBAAc;AACd,kBAAc;AACd,WAA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,SAAS,QAAQ;AACtB,MAAI,SAAS,OAAW,QAAO;AAG/B,MAAI,WAAW,QAAW;AACtB,QAAI,OAAO,eAAe,MAAM,MAAM,OAAO,WAAW;AACpD,OAAC,EAAC,OAAM,IAAI;AAAA,IAChB,OAAO;AACH,cAAQ,KAAK,4EAA4E;AAAA,IAC7F;AAAA,EACJ;AAEA,QAAM,UAAU,kBAAkB;AAClC,MAAI,EAAE,kBAAkB,YAAY,SAAS;AACzC,aAAS,IAAI,YAAY,OAAO,MAAM;AAAA,EAC1C;AACA,QAAM,WAAW,IAAI,YAAY,SAAS,QAAQ,OAAO;AACzD,SAAO,oBAAoB,UAAU,MAAM;AAC/C;AAEA,eAAe,WAAW,gBAAgB;AACtC,MAAI,SAAS,OAAW,QAAO;AAG/B,MAAI,mBAAmB,QAAW;AAC9B,QAAI,OAAO,eAAe,cAAc,MAAM,OAAO,WAAW;AAC5D,OAAC,EAAC,eAAc,IAAI;AAAA,IACxB,OAAO;AACH,cAAQ,KAAK,2FAA2F;AAAA,IAC5G;AAAA,EACJ;AAEA,MAAI,mBAAmB,QAAW;AAC9B,qBAAiB,IAAI,IAAI,qBAAqB,YAAY,GAAG;AAAA,EACjE;AACA,QAAM,UAAU,kBAAkB;AAElC,MAAI,OAAO,mBAAmB,YAAa,OAAO,YAAY,cAAc,0BAA0B,WAAa,OAAO,QAAQ,cAAc,0BAA0B,KAAM;AAC5K,qBAAiB,MAAM,cAAc;AAAA,EACzC;AAEA,QAAM,EAAE,UAAU,OAAO,IAAI,MAAM,WAAW,MAAM,gBAAgB,OAAO;AAE3E,SAAO,oBAAoB,UAAU,MAAM;AAC/C;","names":["ptr"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -136,7 +136,7 @@ declare function isValidSyntax(query: string): boolean;
|
|
|
136
136
|
* WASM Module Loader
|
|
137
137
|
*
|
|
138
138
|
* Handles loading and initializing the WASM modules for groq-lint and groq-format.
|
|
139
|
-
*
|
|
139
|
+
* Uses the `--target web` output from wasm-pack, which works in both Node.js and browsers.
|
|
140
140
|
*/
|
|
141
141
|
/**
|
|
142
142
|
* Check if WASM modules are initialized
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var WasmError = class extends Error {
|
|
|
15
15
|
this.code = code;
|
|
16
16
|
this.name = "WasmError";
|
|
17
17
|
}
|
|
18
|
+
code;
|
|
18
19
|
};
|
|
19
20
|
var RULE_ID_MAP = {
|
|
20
21
|
join_in_filter: "join-in-filter",
|
|
@@ -55,15 +56,18 @@ async function initWasm() {
|
|
|
55
56
|
}
|
|
56
57
|
async function doInit() {
|
|
57
58
|
try {
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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;
|
|
67
71
|
initialized = true;
|
|
68
72
|
} catch (error) {
|
|
69
73
|
initPromise = null;
|
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 * Currently supports Node.js environments.\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 // Dynamic import for the CommonJS WASM module\n // The wasm-pack nodejs target generates CJS with synchronous WASM loading\n const { createRequire } = await import('node:module')\n const { fileURLToPath } = await import('node:url')\n const { dirname, join } = await import('node:path')\n\n // Create a require function that can load CJS modules\n const currentDir = dirname(fileURLToPath(import.meta.url))\n const require = createRequire(import.meta.url)\n\n // Load the WASM module - it will synchronously initialize\n // Use .cjs extension since wasm-pack generates CJS and our package uses \"type\": \"module\"\n const wasmPath = join(currentDir, '..', 'wasm', 'groq_wasm.cjs')\n const wasm = require(wasmPath)\n\n // Store the functions\n wasmLint = wasm.lint\n wasmFormat = wasm.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;AACF;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,K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AA+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":["require"]}
|
|
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,u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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity-labs/groq-wasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "WASM bindings for GROQ linting and formatting (groq-lint + groq-format)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -20,18 +20,10 @@
|
|
|
20
20
|
"type": "module",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"default": "./dist/index.js"
|
|
26
|
-
},
|
|
27
|
-
"require": {
|
|
28
|
-
"types": "./dist/index.d.cts",
|
|
29
|
-
"default": "./dist/index.cjs"
|
|
30
|
-
}
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
31
25
|
}
|
|
32
26
|
},
|
|
33
|
-
"main": "./dist/index.cjs",
|
|
34
|
-
"module": "./dist/index.js",
|
|
35
27
|
"types": "./dist/index.d.ts",
|
|
36
28
|
"files": [
|
|
37
29
|
"dist",
|
|
@@ -40,8 +32,8 @@
|
|
|
40
32
|
"devDependencies": {
|
|
41
33
|
"tsup": "^8.3.5",
|
|
42
34
|
"typescript": "^5.7.2",
|
|
43
|
-
"vitest": "^
|
|
44
|
-
"@sanity-labs/lint-core": "0.
|
|
35
|
+
"vitest": "^4.0.0",
|
|
36
|
+
"@sanity-labs/lint-core": "0.2.0"
|
|
45
37
|
},
|
|
46
38
|
"engines": {
|
|
47
39
|
"node": ">=20.0.0"
|
package/wasm/groq_wasm.d.ts
CHANGED
|
@@ -25,3 +25,40 @@ export function init(): void;
|
|
|
25
25
|
* A JSON string containing an array of findings
|
|
26
26
|
*/
|
|
27
27
|
export function lint(query: string): string;
|
|
28
|
+
|
|
29
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
30
|
+
|
|
31
|
+
export interface InitOutput {
|
|
32
|
+
readonly memory: WebAssembly.Memory;
|
|
33
|
+
readonly format: (a: number, b: number, c: number) => [number, number, number, number];
|
|
34
|
+
readonly init: () => void;
|
|
35
|
+
readonly lint: (a: number, b: number) => [number, number, number, number];
|
|
36
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
37
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
38
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
39
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
40
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
41
|
+
readonly __wbindgen_start: () => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
48
|
+
* a precompiled `WebAssembly.Module`.
|
|
49
|
+
*
|
|
50
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
51
|
+
*
|
|
52
|
+
* @returns {InitOutput}
|
|
53
|
+
*/
|
|
54
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
58
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
59
|
+
*
|
|
60
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
61
|
+
*
|
|
62
|
+
* @returns {Promise<InitOutput>}
|
|
63
|
+
*/
|
|
64
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|