postgrest-parser 0.1.0 → 0.1.2
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/package.json +4 -5
- package/pkg/LICENSE +21 -0
- package/pkg/README.md +1082 -0
- package/pkg/client.d.ts +226 -0
- package/pkg/client.js +378 -0
- package/pkg/client.ts +528 -0
- package/pkg/package.json +31 -0
- package/pkg/postgrest_parser.d.ts +294 -0
- package/pkg/postgrest_parser.js +1151 -0
- package/pkg/postgrest_parser_bg.wasm +0 -0
- package/pkg/postgrest_parser_bg.wasm.d.ts +27 -0
- package/pkg/tsconfig.json +33 -0
- package/pkg/types.d.ts +174 -0
- package/pkg/types.js +16 -0
- package/pkg/types.ts +203 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Result of parsing a PostgREST query, designed for TypeScript consumption.
|
|
6
|
+
*/
|
|
7
|
+
export class WasmQueryResult {
|
|
8
|
+
private constructor();
|
|
9
|
+
free(): void;
|
|
10
|
+
[Symbol.dispose](): void;
|
|
11
|
+
/**
|
|
12
|
+
* Get the entire result as a JSON object
|
|
13
|
+
*/
|
|
14
|
+
toJSON(): any;
|
|
15
|
+
/**
|
|
16
|
+
* Get the query parameters as a JSON string
|
|
17
|
+
*/
|
|
18
|
+
readonly params: any;
|
|
19
|
+
/**
|
|
20
|
+
* Get the SQL query string
|
|
21
|
+
*/
|
|
22
|
+
readonly query: string;
|
|
23
|
+
/**
|
|
24
|
+
* Get the list of tables as a JSON array
|
|
25
|
+
*/
|
|
26
|
+
readonly tables: any;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Build a WHERE clause from parsed filters.
|
|
31
|
+
*
|
|
32
|
+
* # Arguments
|
|
33
|
+
*
|
|
34
|
+
* * `filters_json` - JSON array of filter conditions
|
|
35
|
+
*
|
|
36
|
+
* # Returns
|
|
37
|
+
*
|
|
38
|
+
* Returns an object with `clause` (SQL string) and `params` (array of values).
|
|
39
|
+
*/
|
|
40
|
+
export function buildFilterClause(filters_json: any): any;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Initialize schema cache from a database query executor.
|
|
44
|
+
*
|
|
45
|
+
* This function accepts a JavaScript async function that executes SQL queries
|
|
46
|
+
* and returns results. The schema introspection queries will be executed via
|
|
47
|
+
* this callback to populate the relationship cache.
|
|
48
|
+
*
|
|
49
|
+
* # Arguments
|
|
50
|
+
*
|
|
51
|
+
* * `query_executor` - An async JavaScript function with signature:
|
|
52
|
+
* `async (sql: string) => { rows: any[] }`
|
|
53
|
+
*
|
|
54
|
+
* # Example (TypeScript with PGlite)
|
|
55
|
+
*
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { PGlite } from '@electric-sql/pglite';
|
|
58
|
+
* import { initSchemaFromDb } from './pkg/postgrest_parser.js';
|
|
59
|
+
*
|
|
60
|
+
* const db = new PGlite();
|
|
61
|
+
*
|
|
62
|
+
* // Create query executor for WASM
|
|
63
|
+
* const queryExecutor = async (sql: string) => {
|
|
64
|
+
* const result = await db.query(sql);
|
|
65
|
+
* return { rows: result.rows };
|
|
66
|
+
* };
|
|
67
|
+
*
|
|
68
|
+
* // Initialize schema from database
|
|
69
|
+
* await initSchemaFromDb(queryExecutor);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export function initSchemaFromDb(query_executor: Function): Promise<void>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Initialize WASM module (call this first from JavaScript)
|
|
76
|
+
*/
|
|
77
|
+
export function init_panic_hook(): void;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Parse and generate SQL for a DELETE operation.
|
|
81
|
+
*
|
|
82
|
+
* # Arguments
|
|
83
|
+
*
|
|
84
|
+
* * `table` - The table name
|
|
85
|
+
* * `query_string` - Query string with filters and optional returning
|
|
86
|
+
* * `headers` - Optional headers as JSON string
|
|
87
|
+
*
|
|
88
|
+
* # Example (TypeScript)
|
|
89
|
+
*
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const result = parseDelete("users", "id=eq.123&returning=id", null);
|
|
92
|
+
* console.log(result.query); // DELETE FROM "users" WHERE ...
|
|
93
|
+
* console.log(result.params); // ["123"]
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function parseDelete(table: string, query_string: string, headers?: string | null): WasmQueryResult;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Parse and generate SQL for an INSERT operation.
|
|
100
|
+
*
|
|
101
|
+
* # Arguments
|
|
102
|
+
*
|
|
103
|
+
* * `table` - The table name
|
|
104
|
+
* * `body` - JSON body (single object or array of objects)
|
|
105
|
+
* * `query_string` - Optional query string for returning, on_conflict, etc.
|
|
106
|
+
* * `headers` - Optional headers as JSON string (e.g., '{"Prefer":"return=representation"}')
|
|
107
|
+
*
|
|
108
|
+
* # Example (TypeScript)
|
|
109
|
+
*
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const result = parseInsert("users",
|
|
112
|
+
* JSON.stringify({ name: "Alice", email: "alice@example.com" }),
|
|
113
|
+
* "on_conflict=email&returning=id,name",
|
|
114
|
+
* JSON.stringify({ Prefer: "return=representation" })
|
|
115
|
+
* );
|
|
116
|
+
* console.log(result.query); // INSERT INTO "users" ...
|
|
117
|
+
* console.log(result.params); // ["Alice", "alice@example.com"]
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export function parseInsert(table: string, body: string, query_string?: string | null, headers?: string | null): WasmQueryResult;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Parse only the query string without generating SQL.
|
|
124
|
+
*
|
|
125
|
+
* Useful if you want to inspect the parsed structure before generating SQL.
|
|
126
|
+
*
|
|
127
|
+
* # Arguments
|
|
128
|
+
*
|
|
129
|
+
* * `query_string` - The PostgREST query string
|
|
130
|
+
*
|
|
131
|
+
* # Returns
|
|
132
|
+
*
|
|
133
|
+
* Returns the parsed parameters as a JSON object.
|
|
134
|
+
*/
|
|
135
|
+
export function parseOnly(query_string: string): any;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Parse a PostgREST query string and convert it to SQL.
|
|
139
|
+
*
|
|
140
|
+
* # Arguments
|
|
141
|
+
*
|
|
142
|
+
* * `table` - The table name to query
|
|
143
|
+
* * `query_string` - The PostgREST query string (e.g., "select=id,name&age=gte.18")
|
|
144
|
+
*
|
|
145
|
+
* # Returns
|
|
146
|
+
*
|
|
147
|
+
* Returns a `WasmQueryResult` containing the SQL query, parameters, and affected tables.
|
|
148
|
+
*
|
|
149
|
+
* # Example (TypeScript)
|
|
150
|
+
*
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const result = parseQueryString("users", "age=gte.18&status=eq.active");
|
|
153
|
+
* console.log(result.query); // SELECT * FROM "users" WHERE ...
|
|
154
|
+
* console.log(result.params); // ["18", "active"]
|
|
155
|
+
* console.log(result.tables); // ["users"]
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export function parseQueryString(table: string, query_string: string): WasmQueryResult;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Parse a complete HTTP request and generate appropriate SQL.
|
|
162
|
+
*
|
|
163
|
+
* This is the most comprehensive function - it handles all HTTP methods
|
|
164
|
+
* and automatically chooses between SELECT, INSERT, UPDATE, DELETE, or RPC.
|
|
165
|
+
*
|
|
166
|
+
* # Arguments
|
|
167
|
+
*
|
|
168
|
+
* * `method` - HTTP method: "GET", "POST", "PUT", "PATCH", "DELETE"
|
|
169
|
+
* * `path` - Resource path (table name or "rpc/function_name")
|
|
170
|
+
* * `query_string` - URL query string
|
|
171
|
+
* * `body` - Request body as JSON string (or null)
|
|
172
|
+
* * `headers` - Optional headers as JSON object (for Prefer header)
|
|
173
|
+
*
|
|
174
|
+
* # Example (TypeScript)
|
|
175
|
+
*
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // SELECT query
|
|
178
|
+
* const getResult = parseRequest("GET", "users", "age=gte.18&limit=10", null, null);
|
|
179
|
+
*
|
|
180
|
+
* // INSERT with upsert
|
|
181
|
+
* const postResult = parseRequest("POST", "users", "on_conflict=email",
|
|
182
|
+
* JSON.stringify({ name: "Alice", email: "alice@example.com" }),
|
|
183
|
+
* JSON.stringify({ Prefer: "return=representation" })
|
|
184
|
+
* );
|
|
185
|
+
*
|
|
186
|
+
* // RPC call
|
|
187
|
+
* const rpcResult = parseRequest("POST", "rpc/my_function",
|
|
188
|
+
* "select=result",
|
|
189
|
+
* JSON.stringify({ arg1: "value" }),
|
|
190
|
+
* null
|
|
191
|
+
* );
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export function parseRequest(method: string, path: string, query_string: string, body?: string | null, headers?: string | null): WasmQueryResult;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Parse and generate SQL for an RPC (stored procedure/function) call.
|
|
198
|
+
*
|
|
199
|
+
* # Arguments
|
|
200
|
+
*
|
|
201
|
+
* * `function_name` - The function name (can include schema: "schema.function")
|
|
202
|
+
* * `body` - JSON object with function arguments (or null for no args)
|
|
203
|
+
* * `query_string` - Optional query string for filtering/ordering results
|
|
204
|
+
* * `headers` - Optional headers as JSON string
|
|
205
|
+
*
|
|
206
|
+
* # Example (TypeScript)
|
|
207
|
+
*
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const result = parseRpc("calculate_total",
|
|
210
|
+
* JSON.stringify({ order_id: 123, tax_rate: 0.08 }),
|
|
211
|
+
* "select=total,tax&limit=1",
|
|
212
|
+
* null
|
|
213
|
+
* );
|
|
214
|
+
* console.log(result.query); // SELECT * FROM calculate_total(...)
|
|
215
|
+
* console.log(result.params); // [123, 0.08]
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
export function parseRpc(function_name: string, body?: string | null, query_string?: string | null, headers?: string | null): WasmQueryResult;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Parse and generate SQL for an UPDATE operation.
|
|
222
|
+
*
|
|
223
|
+
* # Arguments
|
|
224
|
+
*
|
|
225
|
+
* * `table` - The table name
|
|
226
|
+
* * `body` - JSON object with fields to update
|
|
227
|
+
* * `query_string` - Query string with filters and optional returning
|
|
228
|
+
* * `headers` - Optional headers as JSON string
|
|
229
|
+
*
|
|
230
|
+
* # Example (TypeScript)
|
|
231
|
+
*
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const result = parseUpdate("users",
|
|
234
|
+
* JSON.stringify({ status: "active" }),
|
|
235
|
+
* "id=eq.123&returning=id,status",
|
|
236
|
+
* null
|
|
237
|
+
* );
|
|
238
|
+
* console.log(result.query); // UPDATE "users" SET ...
|
|
239
|
+
* console.log(result.params); // ["active", "123"]
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
export function parseUpdate(table: string, body: string, query_string: string, headers?: string | null): WasmQueryResult;
|
|
243
|
+
|
|
244
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
245
|
+
|
|
246
|
+
export interface InitOutput {
|
|
247
|
+
readonly memory: WebAssembly.Memory;
|
|
248
|
+
readonly __wbg_wasmqueryresult_free: (a: number, b: number) => void;
|
|
249
|
+
readonly buildFilterClause: (a: number, b: number) => void;
|
|
250
|
+
readonly initSchemaFromDb: (a: number) => number;
|
|
251
|
+
readonly parseDelete: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
252
|
+
readonly parseInsert: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
253
|
+
readonly parseOnly: (a: number, b: number, c: number) => void;
|
|
254
|
+
readonly parseQueryString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
255
|
+
readonly parseRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
|
|
256
|
+
readonly parseRpc: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
257
|
+
readonly parseUpdate: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
258
|
+
readonly wasmqueryresult_params: (a: number) => number;
|
|
259
|
+
readonly wasmqueryresult_query: (a: number, b: number) => void;
|
|
260
|
+
readonly wasmqueryresult_tables: (a: number) => number;
|
|
261
|
+
readonly wasmqueryresult_toJSON: (a: number) => number;
|
|
262
|
+
readonly init_panic_hook: () => void;
|
|
263
|
+
readonly __wasm_bindgen_func_elem_344: (a: number, b: number) => void;
|
|
264
|
+
readonly __wasm_bindgen_func_elem_345: (a: number, b: number, c: number, d: number) => void;
|
|
265
|
+
readonly __wasm_bindgen_func_elem_416: (a: number, b: number, c: number, d: number) => void;
|
|
266
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
267
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
268
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
269
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
270
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
271
|
+
readonly __wbindgen_start: () => void;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
278
|
+
* a precompiled `WebAssembly.Module`.
|
|
279
|
+
*
|
|
280
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
281
|
+
*
|
|
282
|
+
* @returns {InitOutput}
|
|
283
|
+
*/
|
|
284
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
288
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
289
|
+
*
|
|
290
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
291
|
+
*
|
|
292
|
+
* @returns {Promise<InitOutput>}
|
|
293
|
+
*/
|
|
294
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|