Skip to content

Commit 743f0ff

Browse files
committed
cleanup entry point
1 parent 21580d1 commit 743f0ff

File tree

4 files changed

+26
-80
lines changed

4 files changed

+26
-80
lines changed

index.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

package.json

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,21 @@
33
"version": "17.2.0",
44
"description": "The real PostgreSQL query parser",
55
"homepage": "https://github.com/launchql/libpg-query-node",
6-
"main": "index.js",
7-
"typings": "index.d.ts",
6+
"main": "./wasm/index.cjs",
7+
"typings": "./wasm/index.d.ts",
88
"publishConfig": {
99
"access": "public"
1010
},
1111
"files": [
12-
"index.js",
13-
"index.d.ts",
12+
"wasm/*",
1413
"libpg_query/*",
15-
"script/*",
16-
"wasm/*"
14+
"script/*"
1715
],
1816
"exports": {
1917
".": {
20-
"types": "./index.d.ts",
18+
"types": "./wasm/index.d.ts",
2119
"import": "./wasm/index.js",
22-
"require": "./index.js",
23-
"default": "./index.js"
24-
},
25-
"./wasm": {
26-
"types": "./index.d.ts",
27-
"default": "./wasm/index.js"
20+
"require": "./wasm/index.cjs"
2821
}
2922
},
3023
"scripts": {

wasm/index.cjs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ const initPromise = PgQueryModule.default().then((module) => {
66
wasmModule = module;
77
});
88

9+
async function loadModule() {
10+
if (!wasmModule) {
11+
await initPromise;
12+
}
13+
return wasmModule;
14+
}
15+
916
function awaitInit(fn) {
1017
return async (...args) => {
1118
await initPromise;
@@ -164,8 +171,6 @@ const normalize = awaitInit(async (query) => {
164171
}
165172
});
166173

167-
168-
169174
const parseQueryDetailed = awaitInit(async (query) => {
170175
const queryPtr = stringToPtr(query);
171176
let resultPtr;
@@ -208,7 +213,7 @@ const parseQueryDetailed = awaitInit(async (query) => {
208213
// Sync versions that assume WASM module is already initialized
209214
function parseQuerySync(query) {
210215
if (!wasmModule) {
211-
throw new Error('WASM module not initialized. Call an async method first to initialize.');
216+
throw new Error('WASM module not initialized. Call loadModule() first.');
212217
}
213218
const queryPtr = stringToPtr(query);
214219
let resultPtr;
@@ -253,7 +258,7 @@ function parseQuerySync(query) {
253258

254259
function deparseSync(parseTree) {
255260
if (!wasmModule) {
256-
throw new Error('WASM module not initialized. Call an async method first to initialize.');
261+
throw new Error('WASM module not initialized. Call loadModule() first.');
257262
}
258263
const protobufData = protobufCache.get(parseTree);
259264

@@ -284,7 +289,7 @@ function deparseSync(parseTree) {
284289

285290
function parsePlPgSQLSync(query) {
286291
if (!wasmModule) {
287-
throw new Error('WASM module not initialized. Call an async method first to initialize.');
292+
throw new Error('WASM module not initialized. Call loadModule() first.');
288293
}
289294
const queryPtr = stringToPtr(query);
290295
let resultPtr;
@@ -308,7 +313,7 @@ function parsePlPgSQLSync(query) {
308313

309314
function fingerprintSync(query) {
310315
if (!wasmModule) {
311-
throw new Error('WASM module not initialized. Call an async method first to initialize.');
316+
throw new Error('WASM module not initialized. Call loadModule() first.');
312317
}
313318
const queryPtr = stringToPtr(query);
314319
let resultPtr;
@@ -332,7 +337,7 @@ function fingerprintSync(query) {
332337

333338
function normalizeSync(query) {
334339
if (!wasmModule) {
335-
throw new Error('WASM module not initialized. Call an async method first to initialize.');
340+
throw new Error('WASM module not initialized. Call loadModule() first.');
336341
}
337342
const queryPtr = stringToPtr(query);
338343
let resultPtr;
@@ -356,7 +361,7 @@ function normalizeSync(query) {
356361

357362
function parseQueryDetailedSync(query) {
358363
if (!wasmModule) {
359-
throw new Error('WASM module not initialized. Call an async method first to initialize.');
364+
throw new Error('WASM module not initialized. Call loadModule() first.');
360365
}
361366
const queryPtr = stringToPtr(query);
362367
let resultPtr;
@@ -396,13 +401,8 @@ function parseQueryDetailedSync(query) {
396401
}
397402
}
398403

399-
400-
401-
function isReady() {
402-
return !!wasmModule;
403-
}
404-
405404
module.exports = {
405+
loadModule,
406406
parseQuery,
407407
deparse,
408408
parsePlPgSQL,
@@ -414,7 +414,5 @@ module.exports = {
414414
parsePlPgSQLSync,
415415
fingerprintSync,
416416
normalizeSync,
417-
parseQueryDetailedSync,
418-
isReady,
419-
initPromise
417+
parseQueryDetailedSync
420418
};
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { ParseResult } from "@pgsql/types";
22

3+
export async function loadModule(): Promise<void>;
4+
35
export function parseQuery(sql: string): Promise<ParseResult>;
46
export function parsePlPgSQL(funcsSql: string): Promise<any>;
57
export function parseQuerySync(sql: string): ParseResult;
68
export function parsePlPgSQLSync(funcsSql: string): any;
79
export function deparse(parseTree: any): Promise<string>;
8-
export function deparseSync(parseTree: any): any;
10+
export function deparseSync(parseTree: any): string;
911
export function fingerprint(sql: string): Promise<string>;
1012
export function fingerprintSync(sql: string): string;
1113
export function normalize(sql: string): Promise<string>;
1214
export function normalizeSync(sql: string): string;
1315
export function parseQueryDetailed(sql: string): Promise<ParseResult>;
1416
export function parseQueryDetailedSync(sql: string): ParseResult;
15-
export function isReady(): boolean;
16-
export * from '@pgsql/types';
17+
18+
export * from '@pgsql/types';

0 commit comments

Comments
 (0)