@@ -60,27 +60,16 @@ export const parseQuery = awaitInit(async (query) => {
6060} ) ;
6161
6262export const deparse = awaitInit ( async ( parseTree ) => {
63- if ( ! parseTree || ! parseTree . query ) {
64- throw new Error ( 'No protobuf data found in parse tree - original query is required for deparse ' ) ;
63+ if ( ! parseTree || ! parseTree . stmts || parseTree . stmts . length === 0 ) {
64+ throw new Error ( 'No protobuf data found in parse tree' ) ;
6565 }
6666
67- const queryPtr = stringToPtr ( parseTree . query ) ;
68- const lengthPtr = wasmModule . _malloc ( 4 ) ;
67+ const jsonPtr = stringToPtr ( JSON . stringify ( parseTree ) ) ;
6968
7069 try {
71- const protobufPtr = wasmModule . _wasm_parse_query_protobuf ( queryPtr , lengthPtr ) ;
72- const protobufLength = wasmModule . HEAPU32 [ lengthPtr >> 2 ] ;
73-
74- if ( ! protobufPtr || protobufLength <= 0 ) {
75- const errorMsg = ptrToString ( protobufPtr ) ;
76- wasmModule . _wasm_free_string ( protobufPtr ) ;
77- throw new Error ( errorMsg || 'Failed to generate protobuf data' ) ;
78- }
79-
80- const resultPtr = wasmModule . _wasm_deparse_protobuf ( protobufPtr , protobufLength ) ;
70+ const resultPtr = wasmModule . _wasm_deparse_json ( jsonPtr ) ;
8171 const resultStr = ptrToString ( resultPtr ) ;
8272
83- wasmModule . _wasm_free_string ( protobufPtr ) ;
8473 wasmModule . _wasm_free_string ( resultPtr ) ;
8574
8675 if ( resultStr . startsWith ( 'syntax error' ) || resultStr . startsWith ( 'deparse error' ) || resultStr . includes ( 'ERROR' ) ) {
@@ -89,8 +78,7 @@ export const deparse = awaitInit(async (parseTree) => {
8978
9079 return resultStr ;
9180 } finally {
92- wasmModule . _free ( queryPtr ) ;
93- wasmModule . _free ( lengthPtr ) ;
81+ wasmModule . _free ( jsonPtr ) ;
9482 }
9583} ) ;
9684
@@ -227,27 +215,17 @@ export function deparseSync(parseTree) {
227215 if ( ! wasmModule ) {
228216 throw new Error ( 'WASM module not initialized. Call loadModule() first.' ) ;
229217 }
230- if ( ! parseTree || ! parseTree . query ) {
231- throw new Error ( 'No protobuf data found in parse tree - original query is required for deparse' ) ;
218+
219+ if ( ! parseTree || ! parseTree . stmts || parseTree . stmts . length === 0 ) {
220+ throw new Error ( 'No protobuf data found in parse tree' ) ;
232221 }
233222
234- const queryPtr = stringToPtr ( parseTree . query ) ;
235- const lengthPtr = wasmModule . _malloc ( 4 ) ;
223+ const jsonPtr = stringToPtr ( JSON . stringify ( parseTree ) ) ;
236224
237225 try {
238- const protobufPtr = wasmModule . _wasm_parse_query_protobuf ( queryPtr , lengthPtr ) ;
239- const protobufLength = wasmModule . HEAPU32 [ lengthPtr >> 2 ] ;
240-
241- if ( ! protobufPtr || protobufLength <= 0 ) {
242- const errorMsg = ptrToString ( protobufPtr ) ;
243- wasmModule . _wasm_free_string ( protobufPtr ) ;
244- throw new Error ( errorMsg || 'Failed to generate protobuf data' ) ;
245- }
246-
247- const resultPtr = wasmModule . _wasm_deparse_protobuf ( protobufPtr , protobufLength ) ;
226+ const resultPtr = wasmModule . _wasm_deparse_json ( jsonPtr ) ;
248227 const resultStr = ptrToString ( resultPtr ) ;
249228
250- wasmModule . _wasm_free_string ( protobufPtr ) ;
251229 wasmModule . _wasm_free_string ( resultPtr ) ;
252230
253231 if ( resultStr . startsWith ( 'syntax error' ) || resultStr . startsWith ( 'deparse error' ) || resultStr . includes ( 'ERROR' ) ) {
@@ -256,8 +234,7 @@ export function deparseSync(parseTree) {
256234
257235 return resultStr ;
258236 } finally {
259- wasmModule . _free ( queryPtr ) ;
260- wasmModule . _free ( lengthPtr ) ;
237+ wasmModule . _free ( jsonPtr ) ;
261238 }
262239}
263240
0 commit comments