@sanity-labs/groq-wasm 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +12 -9
- package/dist/index.js.map +1 -1
- package/package.json +3 -11
- 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
package/dist/index.d.cts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { Finding } from '@sanity-labs/lint-core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Types for @sanity-labs/groq-wasm
|
|
5
|
-
*
|
|
6
|
-
* These types match the Rust API from groq-lint and groq-format,
|
|
7
|
-
* converted to TypeScript conventions (snake_case → camelCase).
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Severity levels matching Rust groq-lint
|
|
11
|
-
* Rust: High, Medium, Low → TS: error, warning, info
|
|
12
|
-
*/
|
|
13
|
-
type WasmSeverity = 'high' | 'medium' | 'low';
|
|
14
|
-
/**
|
|
15
|
-
* Map WASM severity to our standard severity
|
|
16
|
-
*/
|
|
17
|
-
declare function mapSeverity(wasmSeverity: WasmSeverity): 'error' | 'warning' | 'info';
|
|
18
|
-
/**
|
|
19
|
-
* A finding from the Rust linter (JSON format from WASM)
|
|
20
|
-
*/
|
|
21
|
-
interface WasmFinding {
|
|
22
|
-
/** Rule ID (snake_case from Rust) */
|
|
23
|
-
ruleId: string;
|
|
24
|
-
/** Human-readable message */
|
|
25
|
-
message: string;
|
|
26
|
-
/** Severity level */
|
|
27
|
-
severity: WasmSeverity;
|
|
28
|
-
/** Start byte offset (0-based) */
|
|
29
|
-
start: number;
|
|
30
|
-
/** End byte offset (0-based) */
|
|
31
|
-
end: number;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Configuration for linting
|
|
35
|
-
*/
|
|
36
|
-
interface WasmLintConfig {
|
|
37
|
-
/** Rules to enable/disable (rule_id → enabled) */
|
|
38
|
-
rules?: Record<string, boolean>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Configuration for formatting
|
|
42
|
-
*/
|
|
43
|
-
interface WasmFormatConfig {
|
|
44
|
-
/** Maximum line width (default: 80) */
|
|
45
|
-
width?: number;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Error from WASM operations
|
|
49
|
-
*/
|
|
50
|
-
declare class WasmError extends Error {
|
|
51
|
-
readonly code: 'NOT_INITIALIZED' | 'PARSE_ERROR' | 'WASM_ERROR';
|
|
52
|
-
constructor(message: string, code: 'NOT_INITIALIZED' | 'PARSE_ERROR' | 'WASM_ERROR');
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Rule ID mapping from Rust (snake_case) to TS (kebab-case)
|
|
56
|
-
*/
|
|
57
|
-
declare const RULE_ID_MAP: Record<string, string>;
|
|
58
|
-
/**
|
|
59
|
-
* Convert Rust rule ID to TS convention
|
|
60
|
-
*/
|
|
61
|
-
declare function mapRuleId(rustRuleId: string): string;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* GROQ Linting via WASM
|
|
65
|
-
*
|
|
66
|
-
* Wraps the Rust groq-lint library compiled to WASM.
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Lint a GROQ query using the WASM-based linter
|
|
71
|
-
*
|
|
72
|
-
* @param query - The GROQ query string to lint
|
|
73
|
-
* @param config - Optional configuration
|
|
74
|
-
* @returns Array of findings
|
|
75
|
-
* @throws {WasmError} If WASM is not initialized or query parsing fails
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* import { initWasm, lint } from '@sanity-labs/groq-wasm'
|
|
80
|
-
*
|
|
81
|
-
* await initWasm()
|
|
82
|
-
*
|
|
83
|
-
* const findings = lint('*[_type == "post"]{ author-> }')
|
|
84
|
-
* // [{ ruleId: 'join-in-filter', message: '...', severity: 'error' }]
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
declare function lint(query: string, config?: WasmLintConfig): Finding[];
|
|
88
|
-
/**
|
|
89
|
-
* Async version of lint for environments that prefer promises
|
|
90
|
-
*/
|
|
91
|
-
declare function lintAsync(query: string, config?: WasmLintConfig): Promise<Finding[]>;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* GROQ Formatting via WASM
|
|
95
|
-
*
|
|
96
|
-
* Wraps the Rust groq-format library compiled to WASM.
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Default line width for formatting
|
|
101
|
-
* Matches Rust groq-format DEFAULT_WIDTH
|
|
102
|
-
*/
|
|
103
|
-
declare const DEFAULT_WIDTH = 80;
|
|
104
|
-
/**
|
|
105
|
-
* Format a GROQ query using the WASM-based formatter
|
|
106
|
-
*
|
|
107
|
-
* @param query - The GROQ query string to format
|
|
108
|
-
* @param config - Optional configuration (width defaults to 80)
|
|
109
|
-
* @returns Formatted query string
|
|
110
|
-
* @throws {WasmError} If WASM is not initialized or query parsing fails
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* import { initWasm, format } from '@sanity-labs/groq-wasm'
|
|
115
|
-
*
|
|
116
|
-
* await initWasm()
|
|
117
|
-
*
|
|
118
|
-
* const formatted = format('*[_type=="post"]{title,body}')
|
|
119
|
-
* // '*[_type == "post"]{ title, body }'
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
declare function format(query: string, config?: WasmFormatConfig): string;
|
|
123
|
-
/**
|
|
124
|
-
* Async version of format for environments that prefer promises
|
|
125
|
-
*/
|
|
126
|
-
declare function formatAsync(query: string, config?: WasmFormatConfig): Promise<string>;
|
|
127
|
-
/**
|
|
128
|
-
* Check if a query can be parsed (without full formatting)
|
|
129
|
-
*
|
|
130
|
-
* @param query - The GROQ query to validate
|
|
131
|
-
* @returns true if the query is valid GROQ syntax
|
|
132
|
-
*/
|
|
133
|
-
declare function isValidSyntax(query: string): boolean;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* WASM Module Loader
|
|
137
|
-
*
|
|
138
|
-
* Handles loading and initializing the WASM modules for groq-lint and groq-format.
|
|
139
|
-
* Currently supports Node.js environments.
|
|
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 };
|
package/wasm/groq_wasm.cjs
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
let imports = {};
|
|
3
|
-
imports['__wbindgen_placeholder__'] = module.exports;
|
|
4
|
-
|
|
5
|
-
let cachedDataViewMemory0 = null;
|
|
6
|
-
function getDataViewMemory0() {
|
|
7
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
8
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
9
|
-
}
|
|
10
|
-
return cachedDataViewMemory0;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getStringFromWasm0(ptr, len) {
|
|
14
|
-
ptr = ptr >>> 0;
|
|
15
|
-
return decodeText(ptr, len);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let cachedUint8ArrayMemory0 = null;
|
|
19
|
-
function getUint8ArrayMemory0() {
|
|
20
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
21
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
22
|
-
}
|
|
23
|
-
return cachedUint8ArrayMemory0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isLikeNone(x) {
|
|
27
|
-
return x === undefined || x === null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
31
|
-
if (realloc === undefined) {
|
|
32
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
33
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
34
|
-
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
35
|
-
WASM_VECTOR_LEN = buf.length;
|
|
36
|
-
return ptr;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let len = arg.length;
|
|
40
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
41
|
-
|
|
42
|
-
const mem = getUint8ArrayMemory0();
|
|
43
|
-
|
|
44
|
-
let offset = 0;
|
|
45
|
-
|
|
46
|
-
for (; offset < len; offset++) {
|
|
47
|
-
const code = arg.charCodeAt(offset);
|
|
48
|
-
if (code > 0x7F) break;
|
|
49
|
-
mem[ptr + offset] = code;
|
|
50
|
-
}
|
|
51
|
-
if (offset !== len) {
|
|
52
|
-
if (offset !== 0) {
|
|
53
|
-
arg = arg.slice(offset);
|
|
54
|
-
}
|
|
55
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
56
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
57
|
-
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
58
|
-
|
|
59
|
-
offset += ret.written;
|
|
60
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
WASM_VECTOR_LEN = offset;
|
|
64
|
-
return ptr;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function takeFromExternrefTable0(idx) {
|
|
68
|
-
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
69
|
-
wasm.__externref_table_dealloc(idx);
|
|
70
|
-
return value;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
74
|
-
cachedTextDecoder.decode();
|
|
75
|
-
function decodeText(ptr, len) {
|
|
76
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const cachedTextEncoder = new TextEncoder();
|
|
80
|
-
|
|
81
|
-
if (!('encodeInto' in cachedTextEncoder)) {
|
|
82
|
-
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
83
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
84
|
-
view.set(buf);
|
|
85
|
-
return {
|
|
86
|
-
read: arg.length,
|
|
87
|
-
written: buf.length
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let WASM_VECTOR_LEN = 0;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Format a GROQ query.
|
|
96
|
-
*
|
|
97
|
-
* # Arguments
|
|
98
|
-
* * `query` - The GROQ query string to format
|
|
99
|
-
* * `width` - Maximum line width (default: 80)
|
|
100
|
-
*
|
|
101
|
-
* # Returns
|
|
102
|
-
* The formatted query string
|
|
103
|
-
* @param {string} query
|
|
104
|
-
* @param {number | null} [width]
|
|
105
|
-
* @returns {string}
|
|
106
|
-
*/
|
|
107
|
-
function format(query, width) {
|
|
108
|
-
let deferred3_0;
|
|
109
|
-
let deferred3_1;
|
|
110
|
-
try {
|
|
111
|
-
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
112
|
-
const len0 = WASM_VECTOR_LEN;
|
|
113
|
-
const ret = wasm.format(ptr0, len0, isLikeNone(width) ? 0x100000001 : (width) >>> 0);
|
|
114
|
-
var ptr2 = ret[0];
|
|
115
|
-
var len2 = ret[1];
|
|
116
|
-
if (ret[3]) {
|
|
117
|
-
ptr2 = 0; len2 = 0;
|
|
118
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
119
|
-
}
|
|
120
|
-
deferred3_0 = ptr2;
|
|
121
|
-
deferred3_1 = len2;
|
|
122
|
-
return getStringFromWasm0(ptr2, len2);
|
|
123
|
-
} finally {
|
|
124
|
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.format = format;
|
|
128
|
-
|
|
129
|
-
function init() {
|
|
130
|
-
wasm.init();
|
|
131
|
-
}
|
|
132
|
-
exports.init = init;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Lint a GROQ query and return findings as JSON.
|
|
136
|
-
*
|
|
137
|
-
* # Arguments
|
|
138
|
-
* * `query` - The GROQ query string to lint
|
|
139
|
-
*
|
|
140
|
-
* # Returns
|
|
141
|
-
* A JSON string containing an array of findings
|
|
142
|
-
* @param {string} query
|
|
143
|
-
* @returns {string}
|
|
144
|
-
*/
|
|
145
|
-
function lint(query) {
|
|
146
|
-
let deferred3_0;
|
|
147
|
-
let deferred3_1;
|
|
148
|
-
try {
|
|
149
|
-
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
150
|
-
const len0 = WASM_VECTOR_LEN;
|
|
151
|
-
const ret = wasm.lint(ptr0, len0);
|
|
152
|
-
var ptr2 = ret[0];
|
|
153
|
-
var len2 = ret[1];
|
|
154
|
-
if (ret[3]) {
|
|
155
|
-
ptr2 = 0; len2 = 0;
|
|
156
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
157
|
-
}
|
|
158
|
-
deferred3_0 = ptr2;
|
|
159
|
-
deferred3_1 = len2;
|
|
160
|
-
return getStringFromWasm0(ptr2, len2);
|
|
161
|
-
} finally {
|
|
162
|
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
exports.lint = lint;
|
|
166
|
-
|
|
167
|
-
exports.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
|
168
|
-
let deferred0_0;
|
|
169
|
-
let deferred0_1;
|
|
170
|
-
try {
|
|
171
|
-
deferred0_0 = arg0;
|
|
172
|
-
deferred0_1 = arg1;
|
|
173
|
-
console.error(getStringFromWasm0(arg0, arg1));
|
|
174
|
-
} finally {
|
|
175
|
-
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
exports.__wbg_new_8a6f238a6ece86ea = function() {
|
|
180
|
-
const ret = new Error();
|
|
181
|
-
return ret;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
exports.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
|
185
|
-
const ret = arg1.stack;
|
|
186
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
187
|
-
const len1 = WASM_VECTOR_LEN;
|
|
188
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
189
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
193
|
-
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
194
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
195
|
-
return ret;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
exports.__wbindgen_init_externref_table = function() {
|
|
199
|
-
const table = wasm.__wbindgen_externrefs;
|
|
200
|
-
const offset = table.grow(4);
|
|
201
|
-
table.set(0, undefined);
|
|
202
|
-
table.set(offset + 0, undefined);
|
|
203
|
-
table.set(offset + 1, null);
|
|
204
|
-
table.set(offset + 2, true);
|
|
205
|
-
table.set(offset + 3, false);
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const wasmPath = `${__dirname}/groq_wasm_bg.wasm`;
|
|
209
|
-
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
210
|
-
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
211
|
-
const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;
|
|
212
|
-
|
|
213
|
-
wasm.__wbindgen_start();
|