@dotdo/pglite 0.1.0 → 0.1.1
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/amcheck.tar.gz +0 -0
- package/dist/auth_delay.tar.gz +0 -0
- package/dist/auto_explain.tar.gz +0 -0
- package/dist/basebackup_to_shell.tar.gz +0 -0
- package/dist/basic_archive.tar.gz +0 -0
- package/dist/bloom.tar.gz +0 -0
- package/dist/btree_gin.tar.gz +0 -0
- package/dist/btree_gist.tar.gz +0 -0
- package/dist/{chunk-FY2WAP66.js → chunk-5U7S5PTI.js} +2 -2
- package/dist/chunk-5U7S5PTI.js.map +1 -0
- package/dist/{chunk-NS5M47NH.js → chunk-I55HERVV.js} +3 -3
- package/dist/chunk-I55HERVV.js.map +1 -0
- package/dist/{chunk-XGK36GMM.js → chunk-J77SUHST.js} +2 -2
- package/dist/chunk-J77SUHST.js.map +1 -0
- package/dist/citext.tar.gz +0 -0
- package/dist/contrib/amcheck.cjs +1 -1
- package/dist/contrib/amcheck.cjs.map +1 -1
- package/dist/contrib/amcheck.d.cts +10 -0
- package/dist/contrib/amcheck.d.ts +10 -0
- package/dist/contrib/amcheck.js +1 -1
- package/dist/contrib/amcheck.js.map +1 -1
- package/dist/contrib/auto_explain.cjs +1 -1
- package/dist/contrib/auto_explain.cjs.map +1 -1
- package/dist/contrib/auto_explain.d.cts +10 -0
- package/dist/contrib/auto_explain.d.ts +10 -0
- package/dist/contrib/auto_explain.js +1 -1
- package/dist/contrib/auto_explain.js.map +1 -1
- package/dist/contrib/bloom.cjs +1 -1
- package/dist/contrib/bloom.cjs.map +1 -1
- package/dist/contrib/bloom.d.cts +10 -0
- package/dist/contrib/bloom.d.ts +10 -0
- package/dist/contrib/bloom.js +1 -1
- package/dist/contrib/bloom.js.map +1 -1
- package/dist/contrib/btree_gin.cjs +1 -1
- package/dist/contrib/btree_gin.cjs.map +1 -1
- package/dist/contrib/btree_gin.d.cts +10 -0
- package/dist/contrib/btree_gin.d.ts +10 -0
- package/dist/contrib/btree_gin.js +1 -1
- package/dist/contrib/btree_gin.js.map +1 -1
- package/dist/contrib/btree_gist.cjs +1 -1
- package/dist/contrib/btree_gist.cjs.map +1 -1
- package/dist/contrib/btree_gist.d.cts +10 -0
- package/dist/contrib/btree_gist.d.ts +10 -0
- package/dist/contrib/btree_gist.js +1 -1
- package/dist/contrib/btree_gist.js.map +1 -1
- package/dist/contrib/citext.cjs +1 -1
- package/dist/contrib/citext.cjs.map +1 -1
- package/dist/contrib/citext.d.cts +10 -0
- package/dist/contrib/citext.d.ts +10 -0
- package/dist/contrib/citext.js +1 -1
- package/dist/contrib/citext.js.map +1 -1
- package/dist/contrib/cube.cjs +1 -1
- package/dist/contrib/cube.cjs.map +1 -1
- package/dist/contrib/cube.d.cts +10 -0
- package/dist/contrib/cube.d.ts +10 -0
- package/dist/contrib/cube.js +1 -1
- package/dist/contrib/cube.js.map +1 -1
- package/dist/contrib/dict_int.cjs +1 -1
- package/dist/contrib/dict_int.cjs.map +1 -1
- package/dist/contrib/dict_int.d.cts +10 -0
- package/dist/contrib/dict_int.d.ts +10 -0
- package/dist/contrib/dict_int.js +1 -1
- package/dist/contrib/dict_int.js.map +1 -1
- package/dist/contrib/dict_xsyn.cjs +1 -1
- package/dist/contrib/dict_xsyn.cjs.map +1 -1
- package/dist/contrib/dict_xsyn.d.cts +10 -0
- package/dist/contrib/dict_xsyn.d.ts +10 -0
- package/dist/contrib/dict_xsyn.js +1 -1
- package/dist/contrib/dict_xsyn.js.map +1 -1
- package/dist/contrib/earthdistance.cjs +1 -1
- package/dist/contrib/earthdistance.cjs.map +1 -1
- package/dist/contrib/earthdistance.d.cts +10 -0
- package/dist/contrib/earthdistance.d.ts +10 -0
- package/dist/contrib/earthdistance.js +1 -1
- package/dist/contrib/earthdistance.js.map +1 -1
- package/dist/contrib/file_fdw.cjs +1 -1
- package/dist/contrib/file_fdw.cjs.map +1 -1
- package/dist/contrib/file_fdw.d.cts +10 -0
- package/dist/contrib/file_fdw.d.ts +10 -0
- package/dist/contrib/file_fdw.js +1 -1
- package/dist/contrib/file_fdw.js.map +1 -1
- package/dist/contrib/fuzzystrmatch.cjs +1 -1
- package/dist/contrib/fuzzystrmatch.cjs.map +1 -1
- package/dist/contrib/fuzzystrmatch.d.cts +10 -0
- package/dist/contrib/fuzzystrmatch.d.ts +10 -0
- package/dist/contrib/fuzzystrmatch.js +1 -1
- package/dist/contrib/fuzzystrmatch.js.map +1 -1
- package/dist/contrib/hstore.cjs +1 -1
- package/dist/contrib/hstore.cjs.map +1 -1
- package/dist/contrib/hstore.d.cts +10 -0
- package/dist/contrib/hstore.d.ts +10 -0
- package/dist/contrib/hstore.js +1 -1
- package/dist/contrib/hstore.js.map +1 -1
- package/dist/contrib/intarray.cjs +1 -1
- package/dist/contrib/intarray.cjs.map +1 -1
- package/dist/contrib/intarray.d.cts +10 -0
- package/dist/contrib/intarray.d.ts +10 -0
- package/dist/contrib/intarray.js +1 -1
- package/dist/contrib/intarray.js.map +1 -1
- package/dist/contrib/isn.cjs +1 -1
- package/dist/contrib/isn.cjs.map +1 -1
- package/dist/contrib/isn.d.cts +10 -0
- package/dist/contrib/isn.d.ts +10 -0
- package/dist/contrib/isn.js +1 -1
- package/dist/contrib/isn.js.map +1 -1
- package/dist/contrib/lo.cjs +1 -1
- package/dist/contrib/lo.cjs.map +1 -1
- package/dist/contrib/lo.d.cts +10 -0
- package/dist/contrib/lo.d.ts +10 -0
- package/dist/contrib/lo.js +1 -1
- package/dist/contrib/lo.js.map +1 -1
- package/dist/contrib/ltree.cjs +1 -1
- package/dist/contrib/ltree.cjs.map +1 -1
- package/dist/contrib/ltree.d.cts +10 -0
- package/dist/contrib/ltree.d.ts +10 -0
- package/dist/contrib/ltree.js +1 -1
- package/dist/contrib/ltree.js.map +1 -1
- package/dist/contrib/pageinspect.cjs +1 -1
- package/dist/contrib/pageinspect.cjs.map +1 -1
- package/dist/contrib/pageinspect.d.cts +10 -0
- package/dist/contrib/pageinspect.d.ts +10 -0
- package/dist/contrib/pageinspect.js +1 -1
- package/dist/contrib/pageinspect.js.map +1 -1
- package/dist/contrib/pg_buffercache.cjs +1 -1
- package/dist/contrib/pg_buffercache.cjs.map +1 -1
- package/dist/contrib/pg_buffercache.d.cts +10 -0
- package/dist/contrib/pg_buffercache.d.ts +10 -0
- package/dist/contrib/pg_buffercache.js +1 -1
- package/dist/contrib/pg_buffercache.js.map +1 -1
- package/dist/contrib/pg_freespacemap.cjs +1 -1
- package/dist/contrib/pg_freespacemap.cjs.map +1 -1
- package/dist/contrib/pg_freespacemap.d.cts +10 -0
- package/dist/contrib/pg_freespacemap.d.ts +10 -0
- package/dist/contrib/pg_freespacemap.js +1 -1
- package/dist/contrib/pg_freespacemap.js.map +1 -1
- package/dist/contrib/pg_surgery.cjs +1 -1
- package/dist/contrib/pg_surgery.cjs.map +1 -1
- package/dist/contrib/pg_surgery.d.cts +10 -0
- package/dist/contrib/pg_surgery.d.ts +10 -0
- package/dist/contrib/pg_surgery.js +1 -1
- package/dist/contrib/pg_surgery.js.map +1 -1
- package/dist/contrib/pg_trgm.cjs +1 -1
- package/dist/contrib/pg_trgm.cjs.map +1 -1
- package/dist/contrib/pg_trgm.d.cts +10 -0
- package/dist/contrib/pg_trgm.d.ts +10 -0
- package/dist/contrib/pg_trgm.js +1 -1
- package/dist/contrib/pg_trgm.js.map +1 -1
- package/dist/contrib/pg_visibility.cjs +1 -1
- package/dist/contrib/pg_visibility.cjs.map +1 -1
- package/dist/contrib/pg_visibility.d.cts +10 -0
- package/dist/contrib/pg_visibility.d.ts +10 -0
- package/dist/contrib/pg_visibility.js +1 -1
- package/dist/contrib/pg_visibility.js.map +1 -1
- package/dist/contrib/pg_walinspect.cjs +1 -1
- package/dist/contrib/pg_walinspect.cjs.map +1 -1
- package/dist/contrib/pg_walinspect.d.cts +10 -0
- package/dist/contrib/pg_walinspect.d.ts +10 -0
- package/dist/contrib/pg_walinspect.js +1 -1
- package/dist/contrib/pg_walinspect.js.map +1 -1
- package/dist/contrib/pgcrypto.cjs +1 -1
- package/dist/contrib/pgcrypto.cjs.map +1 -1
- package/dist/contrib/pgcrypto.d.cts +10 -0
- package/dist/contrib/pgcrypto.d.ts +10 -0
- package/dist/contrib/pgcrypto.js +1 -1
- package/dist/contrib/pgcrypto.js.map +1 -1
- package/dist/contrib/seg.cjs +1 -1
- package/dist/contrib/seg.cjs.map +1 -1
- package/dist/contrib/seg.d.cts +10 -0
- package/dist/contrib/seg.d.ts +10 -0
- package/dist/contrib/seg.js +1 -1
- package/dist/contrib/seg.js.map +1 -1
- package/dist/contrib/tablefunc.cjs +1 -1
- package/dist/contrib/tablefunc.cjs.map +1 -1
- package/dist/contrib/tablefunc.d.cts +10 -0
- package/dist/contrib/tablefunc.d.ts +10 -0
- package/dist/contrib/tablefunc.js +1 -1
- package/dist/contrib/tablefunc.js.map +1 -1
- package/dist/contrib/tcn.cjs +1 -1
- package/dist/contrib/tcn.cjs.map +1 -1
- package/dist/contrib/tcn.d.cts +10 -0
- package/dist/contrib/tcn.d.ts +10 -0
- package/dist/contrib/tcn.js +1 -1
- package/dist/contrib/tcn.js.map +1 -1
- package/dist/contrib/tsm_system_rows.cjs +1 -1
- package/dist/contrib/tsm_system_rows.cjs.map +1 -1
- package/dist/contrib/tsm_system_rows.d.cts +10 -0
- package/dist/contrib/tsm_system_rows.d.ts +10 -0
- package/dist/contrib/tsm_system_rows.js +1 -1
- package/dist/contrib/tsm_system_rows.js.map +1 -1
- package/dist/contrib/tsm_system_time.cjs +1 -1
- package/dist/contrib/tsm_system_time.cjs.map +1 -1
- package/dist/contrib/tsm_system_time.d.cts +10 -0
- package/dist/contrib/tsm_system_time.d.ts +10 -0
- package/dist/contrib/tsm_system_time.js +1 -1
- package/dist/contrib/tsm_system_time.js.map +1 -1
- package/dist/contrib/unaccent.cjs +1 -1
- package/dist/contrib/unaccent.cjs.map +1 -1
- package/dist/contrib/unaccent.d.cts +10 -0
- package/dist/contrib/unaccent.d.ts +10 -0
- package/dist/contrib/unaccent.js +1 -1
- package/dist/contrib/unaccent.js.map +1 -1
- package/dist/contrib/uuid_ossp.cjs +1 -1
- package/dist/contrib/uuid_ossp.cjs.map +1 -1
- package/dist/contrib/uuid_ossp.d.cts +10 -0
- package/dist/contrib/uuid_ossp.d.ts +10 -0
- package/dist/contrib/uuid_ossp.js +1 -1
- package/dist/contrib/uuid_ossp.js.map +1 -1
- package/dist/cube.tar.gz +0 -0
- package/dist/dblink.tar.gz +0 -0
- package/dist/dict_int.tar.gz +0 -0
- package/dist/dict_xsyn.tar.gz +0 -0
- package/dist/earthdistance.tar.gz +0 -0
- package/dist/file_fdw.tar.gz +0 -0
- package/dist/fs/base.cjs +1 -1
- package/dist/fs/base.cjs.map +1 -1
- package/dist/fs/base.d.cts +1 -0
- package/dist/fs/base.d.ts +1 -0
- package/dist/fs/base.js +1 -1
- package/dist/fs/nodefs.cjs +1 -1
- package/dist/fs/nodefs.cjs.map +1 -1
- package/dist/fs/nodefs.d.cts +12 -0
- package/dist/fs/nodefs.d.ts +12 -0
- package/dist/fs/nodefs.js +1 -1
- package/dist/fs/opfs-ahp.cjs +3 -3
- package/dist/fs/opfs-ahp.cjs.map +1 -1
- package/dist/fs/opfs-ahp.d.cts +112 -0
- package/dist/fs/opfs-ahp.d.ts +112 -0
- package/dist/fs/opfs-ahp.js +1 -1
- package/dist/fuzzystrmatch.tar.gz +0 -0
- package/dist/hstore.tar.gz +0 -0
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +416 -0
- package/dist/index.d.ts +416 -0
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/intagg.tar.gz +0 -0
- package/dist/intarray.tar.gz +0 -0
- package/dist/isn.tar.gz +0 -0
- package/dist/live/index.cjs +5 -5
- package/dist/live/index.cjs.map +1 -1
- package/dist/live/index.d.cts +149 -0
- package/dist/live/index.d.ts +149 -0
- package/dist/live/index.js +1 -1
- package/dist/live/index.js.map +1 -1
- package/dist/lo.tar.gz +0 -0
- package/dist/ltree.tar.gz +0 -0
- package/dist/oid2name.tar.gz +0 -0
- package/dist/pageinspect.tar.gz +0 -0
- package/dist/passwordcheck.tar.gz +0 -0
- package/dist/pg_buffercache.tar.gz +0 -0
- package/dist/pg_freespacemap.tar.gz +0 -0
- package/dist/pg_hashids/index.cjs +1 -1
- package/dist/pg_hashids/index.cjs.map +1 -1
- package/dist/pg_hashids/index.d.cts +11 -0
- package/dist/pg_hashids/index.d.ts +11 -0
- package/dist/pg_hashids/index.js +1 -1
- package/dist/pg_hashids/index.js.map +1 -1
- package/dist/pg_hashids.tar.gz +0 -0
- package/dist/pg_ivm/index.cjs +1 -1
- package/dist/pg_ivm/index.cjs.map +1 -1
- package/dist/pg_ivm/index.d.cts +11 -0
- package/dist/pg_ivm/index.d.ts +11 -0
- package/dist/pg_ivm/index.js +1 -1
- package/dist/pg_ivm/index.js.map +1 -1
- package/dist/pg_ivm.tar.gz +0 -0
- package/dist/pg_prewarm.tar.gz +0 -0
- package/dist/pg_stat_statements.tar.gz +0 -0
- package/dist/pg_surgery.tar.gz +0 -0
- package/dist/pg_textsearch.tar.gz +0 -0
- package/dist/pg_trgm.tar.gz +0 -0
- package/dist/pg_uuidv7/index.cjs +1 -1
- package/dist/pg_uuidv7/index.cjs.map +1 -1
- package/dist/pg_uuidv7/index.d.cts +11 -0
- package/dist/pg_uuidv7/index.d.ts +11 -0
- package/dist/pg_uuidv7/index.js +1 -1
- package/dist/pg_uuidv7/index.js.map +1 -1
- package/dist/pg_uuidv7.tar.gz +0 -0
- package/dist/pg_visibility.tar.gz +0 -0
- package/dist/pg_walinspect.tar.gz +0 -0
- package/dist/pgcrypto.tar.gz +0 -0
- package/dist/pglite-RfkRSGmH.d.cts +1507 -0
- package/dist/pglite-RfkRSGmH.d.ts +1507 -0
- package/dist/pglite.cjs +3 -3
- package/dist/pglite.data +0 -0
- package/dist/pglite.html +1 -0
- package/dist/pglite.js +16 -0
- package/dist/pglite.wasm +0 -0
- package/dist/pgrowlocks.tar.gz +0 -0
- package/dist/pgstattuple.tar.gz +0 -0
- package/dist/pgtap/index.cjs +1 -1
- package/dist/pgtap/index.cjs.map +1 -1
- package/dist/pgtap/index.d.cts +11 -0
- package/dist/pgtap/index.d.ts +11 -0
- package/dist/pgtap/index.js +1 -1
- package/dist/pgtap/index.js.map +1 -1
- package/dist/pgtap.tar.gz +0 -0
- package/dist/postgres_fdw.tar.gz +0 -0
- package/dist/seg.tar.gz +0 -0
- package/dist/spi.tar.gz +0 -0
- package/dist/tablefunc.tar.gz +0 -0
- package/dist/tcn.tar.gz +0 -0
- package/dist/templating.d.cts +69 -0
- package/dist/templating.d.ts +69 -0
- package/dist/test_decoding.tar.gz +0 -0
- package/dist/tsm_system_rows.tar.gz +0 -0
- package/dist/tsm_system_time.tar.gz +0 -0
- package/dist/unaccent.tar.gz +0 -0
- package/dist/uuid-ossp.tar.gz +0 -0
- package/dist/vacuumlo.tar.gz +0 -0
- package/dist/vector/index.cjs +1 -1
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.d.cts +11 -0
- package/dist/vector/index.d.ts +11 -0
- package/dist/vector/index.js +1 -1
- package/dist/vector/index.js.map +1 -1
- package/dist/vector.tar.gz +0 -0
- package/dist/worker/index.cjs.map +1 -1
- package/dist/worker/index.d.cts +115 -0
- package/dist/worker/index.d.ts +115 -0
- package/dist/worker/index.js +1 -1
- package/dist/worker/index.js.map +1 -1
- package/dist/xml2.tar.gz +0 -0
- package/package.json +1 -1
- package/dist/chunk-FY2WAP66.js.map +0 -1
- package/dist/chunk-NS5M47NH.js.map +0 -1
- package/dist/chunk-XGK36GMM.js.map +0 -1
|
@@ -0,0 +1,1507 @@
|
|
|
1
|
+
declare const Modes: {
|
|
2
|
+
readonly text: 0;
|
|
3
|
+
readonly binary: 1;
|
|
4
|
+
};
|
|
5
|
+
type Mode = (typeof Modes)[keyof typeof Modes];
|
|
6
|
+
type BufferParameter = ArrayBuffer | ArrayBufferView;
|
|
7
|
+
|
|
8
|
+
type MessageName = 'parseComplete' | 'bindComplete' | 'closeComplete' | 'noData' | 'portalSuspended' | 'replicationStart' | 'emptyQuery' | 'copyDone' | 'copyData' | 'rowDescription' | 'parameterDescription' | 'parameterStatus' | 'backendKeyData' | 'notification' | 'readyForQuery' | 'commandComplete' | 'dataRow' | 'copyInResponse' | 'copyOutResponse' | 'authenticationOk' | 'authenticationMD5Password' | 'authenticationCleartextPassword' | 'authenticationSASL' | 'authenticationSASLContinue' | 'authenticationSASLFinal' | 'error' | 'notice';
|
|
9
|
+
type BackendMessage = {
|
|
10
|
+
name: MessageName;
|
|
11
|
+
length: number;
|
|
12
|
+
};
|
|
13
|
+
declare const parseComplete: BackendMessage;
|
|
14
|
+
declare const bindComplete: BackendMessage;
|
|
15
|
+
declare const closeComplete: BackendMessage;
|
|
16
|
+
declare const noData: BackendMessage;
|
|
17
|
+
declare const portalSuspended: BackendMessage;
|
|
18
|
+
declare const replicationStart: BackendMessage;
|
|
19
|
+
declare const emptyQuery: BackendMessage;
|
|
20
|
+
declare const copyDone: BackendMessage;
|
|
21
|
+
declare class AuthenticationOk implements BackendMessage {
|
|
22
|
+
readonly length: number;
|
|
23
|
+
readonly name = "authenticationOk";
|
|
24
|
+
constructor(length: number);
|
|
25
|
+
}
|
|
26
|
+
declare class AuthenticationCleartextPassword implements BackendMessage {
|
|
27
|
+
readonly length: number;
|
|
28
|
+
readonly name = "authenticationCleartextPassword";
|
|
29
|
+
constructor(length: number);
|
|
30
|
+
}
|
|
31
|
+
declare class AuthenticationMD5Password implements BackendMessage {
|
|
32
|
+
readonly length: number;
|
|
33
|
+
readonly salt: Uint8Array;
|
|
34
|
+
readonly name = "authenticationMD5Password";
|
|
35
|
+
constructor(length: number, salt: Uint8Array);
|
|
36
|
+
}
|
|
37
|
+
declare class AuthenticationSASL implements BackendMessage {
|
|
38
|
+
readonly length: number;
|
|
39
|
+
readonly mechanisms: string[];
|
|
40
|
+
readonly name = "authenticationSASL";
|
|
41
|
+
constructor(length: number, mechanisms: string[]);
|
|
42
|
+
}
|
|
43
|
+
declare class AuthenticationSASLContinue implements BackendMessage {
|
|
44
|
+
readonly length: number;
|
|
45
|
+
readonly data: string;
|
|
46
|
+
readonly name = "authenticationSASLContinue";
|
|
47
|
+
constructor(length: number, data: string);
|
|
48
|
+
}
|
|
49
|
+
declare class AuthenticationSASLFinal implements BackendMessage {
|
|
50
|
+
readonly length: number;
|
|
51
|
+
readonly data: string;
|
|
52
|
+
readonly name = "authenticationSASLFinal";
|
|
53
|
+
constructor(length: number, data: string);
|
|
54
|
+
}
|
|
55
|
+
type AuthenticationMessage = AuthenticationOk | AuthenticationCleartextPassword | AuthenticationMD5Password | AuthenticationSASL | AuthenticationSASLContinue | AuthenticationSASLFinal;
|
|
56
|
+
interface NoticeOrError {
|
|
57
|
+
message: string | undefined;
|
|
58
|
+
severity: string | undefined;
|
|
59
|
+
code: string | undefined;
|
|
60
|
+
detail: string | undefined;
|
|
61
|
+
hint: string | undefined;
|
|
62
|
+
position: string | undefined;
|
|
63
|
+
internalPosition: string | undefined;
|
|
64
|
+
internalQuery: string | undefined;
|
|
65
|
+
where: string | undefined;
|
|
66
|
+
schema: string | undefined;
|
|
67
|
+
table: string | undefined;
|
|
68
|
+
column: string | undefined;
|
|
69
|
+
dataType: string | undefined;
|
|
70
|
+
constraint: string | undefined;
|
|
71
|
+
file: string | undefined;
|
|
72
|
+
line: string | undefined;
|
|
73
|
+
routine: string | undefined;
|
|
74
|
+
}
|
|
75
|
+
declare class DatabaseError extends Error implements NoticeOrError {
|
|
76
|
+
readonly length: number;
|
|
77
|
+
readonly name: MessageName;
|
|
78
|
+
severity: string | undefined;
|
|
79
|
+
code: string | undefined;
|
|
80
|
+
detail: string | undefined;
|
|
81
|
+
hint: string | undefined;
|
|
82
|
+
position: string | undefined;
|
|
83
|
+
internalPosition: string | undefined;
|
|
84
|
+
internalQuery: string | undefined;
|
|
85
|
+
where: string | undefined;
|
|
86
|
+
schema: string | undefined;
|
|
87
|
+
table: string | undefined;
|
|
88
|
+
column: string | undefined;
|
|
89
|
+
dataType: string | undefined;
|
|
90
|
+
constraint: string | undefined;
|
|
91
|
+
file: string | undefined;
|
|
92
|
+
line: string | undefined;
|
|
93
|
+
routine: string | undefined;
|
|
94
|
+
constructor(message: string, length: number, name: MessageName);
|
|
95
|
+
}
|
|
96
|
+
declare class CopyDataMessage implements BackendMessage {
|
|
97
|
+
readonly length: number;
|
|
98
|
+
readonly chunk: Uint8Array;
|
|
99
|
+
readonly name = "copyData";
|
|
100
|
+
constructor(length: number, chunk: Uint8Array);
|
|
101
|
+
}
|
|
102
|
+
declare class CopyResponse implements BackendMessage {
|
|
103
|
+
readonly length: number;
|
|
104
|
+
readonly name: MessageName;
|
|
105
|
+
readonly binary: boolean;
|
|
106
|
+
readonly columnTypes: number[];
|
|
107
|
+
constructor(length: number, name: MessageName, binary: boolean, columnCount: number);
|
|
108
|
+
}
|
|
109
|
+
declare class Field {
|
|
110
|
+
readonly name: string;
|
|
111
|
+
readonly tableID: number;
|
|
112
|
+
readonly columnID: number;
|
|
113
|
+
readonly dataTypeID: number;
|
|
114
|
+
readonly dataTypeSize: number;
|
|
115
|
+
readonly dataTypeModifier: number;
|
|
116
|
+
readonly format: Mode;
|
|
117
|
+
constructor(name: string, tableID: number, columnID: number, dataTypeID: number, dataTypeSize: number, dataTypeModifier: number, format: Mode);
|
|
118
|
+
}
|
|
119
|
+
declare class RowDescriptionMessage implements BackendMessage {
|
|
120
|
+
readonly length: number;
|
|
121
|
+
readonly fieldCount: number;
|
|
122
|
+
readonly name: MessageName;
|
|
123
|
+
readonly fields: Field[];
|
|
124
|
+
constructor(length: number, fieldCount: number);
|
|
125
|
+
}
|
|
126
|
+
declare class ParameterDescriptionMessage implements BackendMessage {
|
|
127
|
+
readonly length: number;
|
|
128
|
+
readonly parameterCount: number;
|
|
129
|
+
readonly name: MessageName;
|
|
130
|
+
readonly dataTypeIDs: number[];
|
|
131
|
+
constructor(length: number, parameterCount: number);
|
|
132
|
+
}
|
|
133
|
+
declare class ParameterStatusMessage implements BackendMessage {
|
|
134
|
+
readonly length: number;
|
|
135
|
+
readonly parameterName: string;
|
|
136
|
+
readonly parameterValue: string;
|
|
137
|
+
readonly name: MessageName;
|
|
138
|
+
constructor(length: number, parameterName: string, parameterValue: string);
|
|
139
|
+
}
|
|
140
|
+
declare class BackendKeyDataMessage implements BackendMessage {
|
|
141
|
+
readonly length: number;
|
|
142
|
+
readonly processID: number;
|
|
143
|
+
readonly secretKey: number;
|
|
144
|
+
readonly name: MessageName;
|
|
145
|
+
constructor(length: number, processID: number, secretKey: number);
|
|
146
|
+
}
|
|
147
|
+
declare class NotificationResponseMessage implements BackendMessage {
|
|
148
|
+
readonly length: number;
|
|
149
|
+
readonly processId: number;
|
|
150
|
+
readonly channel: string;
|
|
151
|
+
readonly payload: string;
|
|
152
|
+
readonly name: MessageName;
|
|
153
|
+
constructor(length: number, processId: number, channel: string, payload: string);
|
|
154
|
+
}
|
|
155
|
+
declare class ReadyForQueryMessage implements BackendMessage {
|
|
156
|
+
readonly length: number;
|
|
157
|
+
readonly status: string;
|
|
158
|
+
readonly name: MessageName;
|
|
159
|
+
constructor(length: number, status: string);
|
|
160
|
+
}
|
|
161
|
+
declare class CommandCompleteMessage implements BackendMessage {
|
|
162
|
+
readonly length: number;
|
|
163
|
+
readonly text: string;
|
|
164
|
+
readonly name: MessageName;
|
|
165
|
+
constructor(length: number, text: string);
|
|
166
|
+
}
|
|
167
|
+
declare class DataRowMessage implements BackendMessage {
|
|
168
|
+
length: number;
|
|
169
|
+
fields: (string | null)[];
|
|
170
|
+
readonly fieldCount: number;
|
|
171
|
+
readonly name: MessageName;
|
|
172
|
+
constructor(length: number, fields: (string | null)[]);
|
|
173
|
+
}
|
|
174
|
+
declare class NoticeMessage implements BackendMessage, NoticeOrError {
|
|
175
|
+
readonly length: number;
|
|
176
|
+
readonly message: string | undefined;
|
|
177
|
+
constructor(length: number, message: string | undefined);
|
|
178
|
+
readonly name = "notice";
|
|
179
|
+
severity: string | undefined;
|
|
180
|
+
code: string | undefined;
|
|
181
|
+
detail: string | undefined;
|
|
182
|
+
hint: string | undefined;
|
|
183
|
+
position: string | undefined;
|
|
184
|
+
internalPosition: string | undefined;
|
|
185
|
+
internalQuery: string | undefined;
|
|
186
|
+
where: string | undefined;
|
|
187
|
+
schema: string | undefined;
|
|
188
|
+
table: string | undefined;
|
|
189
|
+
column: string | undefined;
|
|
190
|
+
dataType: string | undefined;
|
|
191
|
+
constraint: string | undefined;
|
|
192
|
+
file: string | undefined;
|
|
193
|
+
line: string | undefined;
|
|
194
|
+
routine: string | undefined;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
type messages_AuthenticationCleartextPassword = AuthenticationCleartextPassword;
|
|
198
|
+
declare const messages_AuthenticationCleartextPassword: typeof AuthenticationCleartextPassword;
|
|
199
|
+
type messages_AuthenticationMD5Password = AuthenticationMD5Password;
|
|
200
|
+
declare const messages_AuthenticationMD5Password: typeof AuthenticationMD5Password;
|
|
201
|
+
type messages_AuthenticationMessage = AuthenticationMessage;
|
|
202
|
+
type messages_AuthenticationOk = AuthenticationOk;
|
|
203
|
+
declare const messages_AuthenticationOk: typeof AuthenticationOk;
|
|
204
|
+
type messages_AuthenticationSASL = AuthenticationSASL;
|
|
205
|
+
declare const messages_AuthenticationSASL: typeof AuthenticationSASL;
|
|
206
|
+
type messages_AuthenticationSASLContinue = AuthenticationSASLContinue;
|
|
207
|
+
declare const messages_AuthenticationSASLContinue: typeof AuthenticationSASLContinue;
|
|
208
|
+
type messages_AuthenticationSASLFinal = AuthenticationSASLFinal;
|
|
209
|
+
declare const messages_AuthenticationSASLFinal: typeof AuthenticationSASLFinal;
|
|
210
|
+
type messages_BackendKeyDataMessage = BackendKeyDataMessage;
|
|
211
|
+
declare const messages_BackendKeyDataMessage: typeof BackendKeyDataMessage;
|
|
212
|
+
type messages_BackendMessage = BackendMessage;
|
|
213
|
+
type messages_CommandCompleteMessage = CommandCompleteMessage;
|
|
214
|
+
declare const messages_CommandCompleteMessage: typeof CommandCompleteMessage;
|
|
215
|
+
type messages_CopyDataMessage = CopyDataMessage;
|
|
216
|
+
declare const messages_CopyDataMessage: typeof CopyDataMessage;
|
|
217
|
+
type messages_CopyResponse = CopyResponse;
|
|
218
|
+
declare const messages_CopyResponse: typeof CopyResponse;
|
|
219
|
+
type messages_DataRowMessage = DataRowMessage;
|
|
220
|
+
declare const messages_DataRowMessage: typeof DataRowMessage;
|
|
221
|
+
type messages_DatabaseError = DatabaseError;
|
|
222
|
+
declare const messages_DatabaseError: typeof DatabaseError;
|
|
223
|
+
type messages_Field = Field;
|
|
224
|
+
declare const messages_Field: typeof Field;
|
|
225
|
+
type messages_MessageName = MessageName;
|
|
226
|
+
type messages_NoticeMessage = NoticeMessage;
|
|
227
|
+
declare const messages_NoticeMessage: typeof NoticeMessage;
|
|
228
|
+
type messages_NotificationResponseMessage = NotificationResponseMessage;
|
|
229
|
+
declare const messages_NotificationResponseMessage: typeof NotificationResponseMessage;
|
|
230
|
+
type messages_ParameterDescriptionMessage = ParameterDescriptionMessage;
|
|
231
|
+
declare const messages_ParameterDescriptionMessage: typeof ParameterDescriptionMessage;
|
|
232
|
+
type messages_ParameterStatusMessage = ParameterStatusMessage;
|
|
233
|
+
declare const messages_ParameterStatusMessage: typeof ParameterStatusMessage;
|
|
234
|
+
type messages_ReadyForQueryMessage = ReadyForQueryMessage;
|
|
235
|
+
declare const messages_ReadyForQueryMessage: typeof ReadyForQueryMessage;
|
|
236
|
+
type messages_RowDescriptionMessage = RowDescriptionMessage;
|
|
237
|
+
declare const messages_RowDescriptionMessage: typeof RowDescriptionMessage;
|
|
238
|
+
declare const messages_bindComplete: typeof bindComplete;
|
|
239
|
+
declare const messages_closeComplete: typeof closeComplete;
|
|
240
|
+
declare const messages_copyDone: typeof copyDone;
|
|
241
|
+
declare const messages_emptyQuery: typeof emptyQuery;
|
|
242
|
+
declare const messages_noData: typeof noData;
|
|
243
|
+
declare const messages_parseComplete: typeof parseComplete;
|
|
244
|
+
declare const messages_portalSuspended: typeof portalSuspended;
|
|
245
|
+
declare const messages_replicationStart: typeof replicationStart;
|
|
246
|
+
declare namespace messages {
|
|
247
|
+
export { messages_AuthenticationCleartextPassword as AuthenticationCleartextPassword, messages_AuthenticationMD5Password as AuthenticationMD5Password, type messages_AuthenticationMessage as AuthenticationMessage, messages_AuthenticationOk as AuthenticationOk, messages_AuthenticationSASL as AuthenticationSASL, messages_AuthenticationSASLContinue as AuthenticationSASLContinue, messages_AuthenticationSASLFinal as AuthenticationSASLFinal, messages_BackendKeyDataMessage as BackendKeyDataMessage, type messages_BackendMessage as BackendMessage, messages_CommandCompleteMessage as CommandCompleteMessage, messages_CopyDataMessage as CopyDataMessage, messages_CopyResponse as CopyResponse, messages_DataRowMessage as DataRowMessage, messages_DatabaseError as DatabaseError, messages_Field as Field, type messages_MessageName as MessageName, messages_NoticeMessage as NoticeMessage, messages_NotificationResponseMessage as NotificationResponseMessage, messages_ParameterDescriptionMessage as ParameterDescriptionMessage, messages_ParameterStatusMessage as ParameterStatusMessage, messages_ReadyForQueryMessage as ReadyForQueryMessage, messages_RowDescriptionMessage as RowDescriptionMessage, messages_bindComplete as bindComplete, messages_closeComplete as closeComplete, messages_copyDone as copyDone, messages_emptyQuery as emptyQuery, messages_noData as noData, messages_parseComplete as parseComplete, messages_portalSuspended as portalSuspended, messages_replicationStart as replicationStart };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
type IDBFS = Emscripten.FileSystemType & {
|
|
251
|
+
quit: () => void;
|
|
252
|
+
dbs: Record<string, IDBDatabase>;
|
|
253
|
+
};
|
|
254
|
+
type FS = typeof FS & {
|
|
255
|
+
filesystems: {
|
|
256
|
+
MEMFS: Emscripten.FileSystemType;
|
|
257
|
+
NODEFS: Emscripten.FileSystemType;
|
|
258
|
+
IDBFS: IDBFS;
|
|
259
|
+
};
|
|
260
|
+
quit: () => void;
|
|
261
|
+
};
|
|
262
|
+
interface PostgresMod extends Omit<EmscriptenModule, 'preInit' | 'preRun' | 'postRun'> {
|
|
263
|
+
preInit: Array<{
|
|
264
|
+
(mod: PostgresMod): void;
|
|
265
|
+
}>;
|
|
266
|
+
preRun: Array<{
|
|
267
|
+
(mod: PostgresMod): void;
|
|
268
|
+
}>;
|
|
269
|
+
postRun: Array<{
|
|
270
|
+
(mod: PostgresMod): void;
|
|
271
|
+
}>;
|
|
272
|
+
FS: FS;
|
|
273
|
+
FD_BUFFER_MAX: number;
|
|
274
|
+
WASM_PREFIX: string;
|
|
275
|
+
INITIAL_MEMORY: number;
|
|
276
|
+
pg_extensions: Record<string, Promise<Blob | null>>;
|
|
277
|
+
_pgl_initdb: () => number;
|
|
278
|
+
_pgl_backend: () => void;
|
|
279
|
+
_pgl_shutdown: () => void;
|
|
280
|
+
_pgl_reseed_random: (seed_high: number, seed_low: number) => void;
|
|
281
|
+
_interactive_write: (msgLength: number) => void;
|
|
282
|
+
_interactive_one: (length: number, peek: number) => void;
|
|
283
|
+
_set_read_write_cbs: (read_cb: number, write_cb: number) => void;
|
|
284
|
+
addFunction: (cb: (ptr: any, length: number) => void, signature: string) => number;
|
|
285
|
+
removeFunction: (f: number) => void;
|
|
286
|
+
wasmTable?: WebAssembly.Table;
|
|
287
|
+
}
|
|
288
|
+
type PostgresFactory<T extends PostgresMod = PostgresMod> = (moduleOverrides?: Partial<T>) => Promise<T>;
|
|
289
|
+
declare const _default: PostgresFactory<PostgresMod>;
|
|
290
|
+
|
|
291
|
+
type postgresMod_FS = FS;
|
|
292
|
+
type postgresMod_PostgresMod = PostgresMod;
|
|
293
|
+
declare namespace postgresMod {
|
|
294
|
+
export { type postgresMod_FS as FS, type postgresMod_PostgresMod as PostgresMod, _default as default };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
type DumpTarCompressionOptions = 'none' | 'gzip' | 'auto';
|
|
298
|
+
|
|
299
|
+
declare const WASM_PREFIX = "/tmp/pglite";
|
|
300
|
+
declare const PGDATA: string;
|
|
301
|
+
type FsType = 'nodefs' | 'idbfs' | 'memoryfs' | 'opfs-ahp';
|
|
302
|
+
/**
|
|
303
|
+
* Filesystem interface.
|
|
304
|
+
* All virtual filesystems that are compatible with PGlite must implement
|
|
305
|
+
* this interface.
|
|
306
|
+
*/
|
|
307
|
+
interface Filesystem {
|
|
308
|
+
/**
|
|
309
|
+
* Initiate the filesystem and return the options to pass to the emscripten module.
|
|
310
|
+
*/
|
|
311
|
+
init(pg: PGlite, emscriptenOptions: Partial<PostgresMod>): Promise<{
|
|
312
|
+
emscriptenOpts: Partial<PostgresMod>;
|
|
313
|
+
}>;
|
|
314
|
+
/**
|
|
315
|
+
* Sync the filesystem to any underlying storage.
|
|
316
|
+
*/
|
|
317
|
+
syncToFs(relaxedDurability?: boolean): Promise<void>;
|
|
318
|
+
/**
|
|
319
|
+
* Sync the filesystem from any underlying storage.
|
|
320
|
+
*/
|
|
321
|
+
initialSyncFs(): Promise<void>;
|
|
322
|
+
/**
|
|
323
|
+
* Dump the PGDATA dir from the filesystem to a gzipped tarball.
|
|
324
|
+
*/
|
|
325
|
+
dumpTar(dbname: string, compression?: DumpTarCompressionOptions): Promise<File | Blob>;
|
|
326
|
+
/**
|
|
327
|
+
* Close the filesystem.
|
|
328
|
+
*/
|
|
329
|
+
closeFs(): Promise<void>;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Base class for all emscripten built-in filesystems.
|
|
333
|
+
*/
|
|
334
|
+
declare class EmscriptenBuiltinFilesystem implements Filesystem {
|
|
335
|
+
protected dataDir?: string;
|
|
336
|
+
protected pg?: PGlite;
|
|
337
|
+
constructor(dataDir?: string);
|
|
338
|
+
init(pg: PGlite, emscriptenOptions: Partial<PostgresMod>): Promise<{
|
|
339
|
+
emscriptenOpts: Partial<PostgresMod>;
|
|
340
|
+
}>;
|
|
341
|
+
syncToFs(_relaxedDurability?: boolean): Promise<void>;
|
|
342
|
+
initialSyncFs(): Promise<void>;
|
|
343
|
+
closeFs(): Promise<void>;
|
|
344
|
+
dumpTar(dbname: string, compression?: DumpTarCompressionOptions): Promise<Blob | File>;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Abstract base class for all custom virtual filesystems.
|
|
348
|
+
* Each custom filesystem needs to implement an interface similar to the NodeJS FS API.
|
|
349
|
+
*/
|
|
350
|
+
declare abstract class BaseFilesystem implements Filesystem {
|
|
351
|
+
protected dataDir?: string;
|
|
352
|
+
protected pg?: PGlite;
|
|
353
|
+
readonly debug: boolean;
|
|
354
|
+
constructor(dataDir?: string, { debug }?: {
|
|
355
|
+
debug?: boolean;
|
|
356
|
+
});
|
|
357
|
+
syncToFs(_relaxedDurability?: boolean): Promise<void>;
|
|
358
|
+
initialSyncFs(): Promise<void>;
|
|
359
|
+
closeFs(): Promise<void>;
|
|
360
|
+
dumpTar(dbname: string, compression?: DumpTarCompressionOptions): Promise<Blob | File>;
|
|
361
|
+
init(pg: PGlite, emscriptenOptions: Partial<PostgresMod>): Promise<{
|
|
362
|
+
emscriptenOpts: Partial<PostgresMod>;
|
|
363
|
+
}>;
|
|
364
|
+
abstract chmod(path: string, mode: number): void;
|
|
365
|
+
abstract close(fd: number): void;
|
|
366
|
+
abstract fstat(fd: number): FsStats;
|
|
367
|
+
abstract lstat(path: string): FsStats;
|
|
368
|
+
abstract mkdir(path: string, options?: {
|
|
369
|
+
recursive?: boolean;
|
|
370
|
+
mode?: number;
|
|
371
|
+
}): void;
|
|
372
|
+
abstract open(path: string, flags?: string, mode?: number): number;
|
|
373
|
+
abstract readdir(path: string): string[];
|
|
374
|
+
abstract read(fd: number, buffer: Uint8Array, // Buffer to read into
|
|
375
|
+
offset: number, // Offset in buffer to start writing to
|
|
376
|
+
length: number, // Number of bytes to read
|
|
377
|
+
position: number): number;
|
|
378
|
+
abstract rename(oldPath: string, newPath: string): void;
|
|
379
|
+
abstract rmdir(path: string): void;
|
|
380
|
+
abstract truncate(path: string, len: number): void;
|
|
381
|
+
abstract unlink(path: string): void;
|
|
382
|
+
abstract utimes(path: string, atime: number, mtime: number): void;
|
|
383
|
+
abstract writeFile(path: string, data: string | Uint8Array, options?: {
|
|
384
|
+
encoding?: string;
|
|
385
|
+
mode?: number;
|
|
386
|
+
flag?: string;
|
|
387
|
+
}): void;
|
|
388
|
+
abstract write(fd: number, buffer: Uint8Array, // Buffer to read from
|
|
389
|
+
offset: number, // Offset in buffer to start reading from
|
|
390
|
+
length: number, // Number of bytes to write
|
|
391
|
+
position: number): number;
|
|
392
|
+
}
|
|
393
|
+
type FsStats = {
|
|
394
|
+
dev: number;
|
|
395
|
+
ino: number;
|
|
396
|
+
mode: number;
|
|
397
|
+
nlink: number;
|
|
398
|
+
uid: number;
|
|
399
|
+
gid: number;
|
|
400
|
+
rdev: number;
|
|
401
|
+
size: number;
|
|
402
|
+
blksize: number;
|
|
403
|
+
blocks: number;
|
|
404
|
+
atime: number;
|
|
405
|
+
mtime: number;
|
|
406
|
+
ctime: number;
|
|
407
|
+
};
|
|
408
|
+
declare const ERRNO_CODES: {
|
|
409
|
+
readonly EBADF: 8;
|
|
410
|
+
readonly EBADFD: 127;
|
|
411
|
+
readonly EEXIST: 20;
|
|
412
|
+
readonly EINVAL: 28;
|
|
413
|
+
readonly EISDIR: 31;
|
|
414
|
+
readonly ENODEV: 43;
|
|
415
|
+
readonly ENOENT: 44;
|
|
416
|
+
readonly ENOTDIR: 54;
|
|
417
|
+
readonly ENOTEMPTY: 55;
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Callback interface for PGlite's Emscripten module integration.
|
|
422
|
+
*
|
|
423
|
+
* These callbacks enable communication between PostgreSQL's C code (compiled to WASM)
|
|
424
|
+
* and JavaScript without requiring runtime WASM compilation. This is achieved through
|
|
425
|
+
* EM_JS trampolines that are compiled at build time.
|
|
426
|
+
*
|
|
427
|
+
* The callbacks are stored in `Module._pgliteCallbacks` and are invoked by the
|
|
428
|
+
* trampoline functions in the WASM code when PostgreSQL needs to read input or
|
|
429
|
+
* write output.
|
|
430
|
+
*
|
|
431
|
+
* This approach is necessary for Cloudflare Workers compatibility, where runtime
|
|
432
|
+
* WASM compilation via `addFunction` is blocked for security reasons.
|
|
433
|
+
*
|
|
434
|
+
* @see https://blog.pyodide.org/posts/function-pointer-cast-handling/
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```typescript
|
|
438
|
+
* // Setting up callbacks on the Emscripten module
|
|
439
|
+
* (mod as any)._pgliteCallbacks = {
|
|
440
|
+
* read: (ptr, maxLength) => {
|
|
441
|
+
* // Copy data to WASM memory at ptr
|
|
442
|
+
* mod.HEAP8.set(inputData.subarray(readOffset, readOffset + length), ptr);
|
|
443
|
+
* return length;
|
|
444
|
+
* },
|
|
445
|
+
* write: (ptr, length) => {
|
|
446
|
+
* // Read data from WASM memory at ptr
|
|
447
|
+
* const bytes = mod.HEAPU8.subarray(ptr, ptr + length);
|
|
448
|
+
* processOutput(bytes);
|
|
449
|
+
* return length;
|
|
450
|
+
* }
|
|
451
|
+
* };
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
interface PGliteCallbacks {
|
|
455
|
+
/**
|
|
456
|
+
* Read callback - called when PostgreSQL needs input data.
|
|
457
|
+
*
|
|
458
|
+
* This callback is invoked by the `recv()` trampoline in the WASM code
|
|
459
|
+
* when PostgreSQL is waiting for input (e.g., query data from the client).
|
|
460
|
+
*
|
|
461
|
+
* @param ptr - Pointer to WASM memory where data should be written
|
|
462
|
+
* @param maxLength - Maximum number of bytes that can be written
|
|
463
|
+
* @returns Number of bytes actually written, or negative value on error
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* read: (ptr, maxLength) => {
|
|
468
|
+
* const available = outputData.length - readOffset;
|
|
469
|
+
* const length = Math.min(available, maxLength);
|
|
470
|
+
* mod.HEAP8.set(
|
|
471
|
+
* outputData.subarray(readOffset, readOffset + length),
|
|
472
|
+
* ptr
|
|
473
|
+
* );
|
|
474
|
+
* readOffset += length;
|
|
475
|
+
* return length;
|
|
476
|
+
* }
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
read: ((ptr: number, maxLength: number) => number) | null;
|
|
480
|
+
/**
|
|
481
|
+
* Write callback - called when PostgreSQL has output data.
|
|
482
|
+
*
|
|
483
|
+
* This callback is invoked by the `send()` trampoline in the WASM code
|
|
484
|
+
* when PostgreSQL sends response data (e.g., query results, errors, notices).
|
|
485
|
+
*
|
|
486
|
+
* @param ptr - Pointer to WASM memory containing the output data
|
|
487
|
+
* @param length - Number of bytes available to read
|
|
488
|
+
* @returns Number of bytes processed, or negative value on error
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```typescript
|
|
492
|
+
* write: (ptr, length) => {
|
|
493
|
+
* const bytes = mod.HEAPU8.subarray(ptr, ptr + length);
|
|
494
|
+
* protocolParser.parse(bytes, (msg) => {
|
|
495
|
+
* handleMessage(msg);
|
|
496
|
+
* });
|
|
497
|
+
* return length;
|
|
498
|
+
* }
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
write: ((ptr: number, length: number) => number) | null;
|
|
502
|
+
}
|
|
503
|
+
type FilesystemType = 'nodefs' | 'idbfs' | 'memoryfs';
|
|
504
|
+
type DebugLevel = 0 | 1 | 2 | 3 | 4 | 5;
|
|
505
|
+
type RowMode = 'array' | 'object';
|
|
506
|
+
interface ParserOptions {
|
|
507
|
+
[pgType: number]: (value: string) => unknown;
|
|
508
|
+
}
|
|
509
|
+
interface SerializerOptions {
|
|
510
|
+
[pgType: number]: (value: unknown) => string;
|
|
511
|
+
}
|
|
512
|
+
interface QueryOptions {
|
|
513
|
+
rowMode?: RowMode;
|
|
514
|
+
parsers?: ParserOptions;
|
|
515
|
+
serializers?: SerializerOptions;
|
|
516
|
+
blob?: Blob | File;
|
|
517
|
+
onNotice?: (notice: NoticeMessage) => void;
|
|
518
|
+
paramTypes?: number[];
|
|
519
|
+
}
|
|
520
|
+
interface ExecProtocolOptions {
|
|
521
|
+
syncToFs?: boolean;
|
|
522
|
+
throwOnError?: boolean;
|
|
523
|
+
onNotice?: (notice: NoticeMessage) => void;
|
|
524
|
+
}
|
|
525
|
+
interface ExtensionSetupResult<TNamespace = unknown> {
|
|
526
|
+
emscriptenOpts?: Record<string, unknown>;
|
|
527
|
+
namespaceObj?: TNamespace;
|
|
528
|
+
bundlePath?: URL;
|
|
529
|
+
init?: () => Promise<void>;
|
|
530
|
+
close?: () => Promise<void>;
|
|
531
|
+
/**
|
|
532
|
+
* List of extension names that must be loaded before this extension.
|
|
533
|
+
* Used for automatic dependency resolution in lazy loading.
|
|
534
|
+
*/
|
|
535
|
+
dependencies?: string[];
|
|
536
|
+
}
|
|
537
|
+
type ExtensionSetup<TNamespace = unknown> = (pg: PGliteInterfaceBase, emscriptenOpts: Record<string, unknown>, clientOnly?: boolean) => Promise<ExtensionSetupResult<TNamespace>>;
|
|
538
|
+
interface Extension<TNamespace = unknown> {
|
|
539
|
+
name: string;
|
|
540
|
+
setup: ExtensionSetup<TNamespace>;
|
|
541
|
+
}
|
|
542
|
+
type ExtensionNamespace<T> = T extends Extension<infer TNamespace> ? TNamespace : unknown;
|
|
543
|
+
type Extensions = {
|
|
544
|
+
[namespace: string]: Extension | URL;
|
|
545
|
+
};
|
|
546
|
+
type InitializedExtensions<TExtensions extends Extensions = Extensions> = {
|
|
547
|
+
[K in keyof TExtensions]: ExtensionNamespace<TExtensions[K]>;
|
|
548
|
+
};
|
|
549
|
+
interface ExecProtocolResult {
|
|
550
|
+
messages: BackendMessage[];
|
|
551
|
+
data: Uint8Array;
|
|
552
|
+
}
|
|
553
|
+
interface DumpDataDirResult {
|
|
554
|
+
tarball: Uint8Array;
|
|
555
|
+
extension: '.tar' | '.tgz';
|
|
556
|
+
filename: string;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Memory snapshot for fast cold starts.
|
|
560
|
+
* Contains pre-initialized WASM memory state captured after initdb.
|
|
561
|
+
*/
|
|
562
|
+
interface MemorySnapshot {
|
|
563
|
+
/**
|
|
564
|
+
* Snapshot format version for compatibility checking
|
|
565
|
+
*/
|
|
566
|
+
version: string;
|
|
567
|
+
/**
|
|
568
|
+
* Size of the WASM heap in bytes
|
|
569
|
+
*/
|
|
570
|
+
heapSize: number;
|
|
571
|
+
/**
|
|
572
|
+
* The captured WASM linear memory as an ArrayBuffer
|
|
573
|
+
*/
|
|
574
|
+
heap: ArrayBuffer;
|
|
575
|
+
/**
|
|
576
|
+
* Timestamp when the snapshot was captured (Unix ms)
|
|
577
|
+
*/
|
|
578
|
+
capturedAt: number;
|
|
579
|
+
/**
|
|
580
|
+
* PostgreSQL version this snapshot was created with
|
|
581
|
+
*/
|
|
582
|
+
pgVersion?: string;
|
|
583
|
+
/**
|
|
584
|
+
* Extensions that were pre-loaded in the snapshot
|
|
585
|
+
*/
|
|
586
|
+
extensions?: string[];
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Memory statistics for monitoring WASM heap usage.
|
|
590
|
+
* Useful for tracking memory consumption in constrained environments
|
|
591
|
+
* like Cloudflare Workers (128MB limit).
|
|
592
|
+
*/
|
|
593
|
+
interface MemoryStats {
|
|
594
|
+
/**
|
|
595
|
+
* Total WASM heap size in bytes (allocated memory)
|
|
596
|
+
*/
|
|
597
|
+
heapSize: number;
|
|
598
|
+
/**
|
|
599
|
+
* Peak heap size observed during this session (if trackable)
|
|
600
|
+
* Note: This is only tracked from when PGlite was initialized
|
|
601
|
+
*/
|
|
602
|
+
peakHeapSize: number;
|
|
603
|
+
/**
|
|
604
|
+
* PostgreSQL memory configuration settings
|
|
605
|
+
*/
|
|
606
|
+
postgresSettings: {
|
|
607
|
+
sharedBuffers: string;
|
|
608
|
+
workMem: string;
|
|
609
|
+
tempBuffers: string;
|
|
610
|
+
walBuffers: string;
|
|
611
|
+
maintenanceWorkMem: string;
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
interface PGliteOptions<TExtensions extends Extensions = Extensions> {
|
|
615
|
+
dataDir?: string;
|
|
616
|
+
username?: string;
|
|
617
|
+
database?: string;
|
|
618
|
+
fs?: Filesystem;
|
|
619
|
+
debug?: DebugLevel;
|
|
620
|
+
relaxedDurability?: boolean;
|
|
621
|
+
extensions?: TExtensions;
|
|
622
|
+
loadDataDir?: Blob | File;
|
|
623
|
+
initialMemory?: number;
|
|
624
|
+
wasmModule?: WebAssembly.Module;
|
|
625
|
+
fsBundle?: Blob | File;
|
|
626
|
+
parsers?: ParserOptions;
|
|
627
|
+
serializers?: SerializerOptions;
|
|
628
|
+
/**
|
|
629
|
+
* Pre-initialized memory snapshot for fast cold starts.
|
|
630
|
+
* When provided, skips initdb and restores from the snapshot.
|
|
631
|
+
* CRITICAL: RNG is automatically reseeded after restore for security.
|
|
632
|
+
*/
|
|
633
|
+
memorySnapshot?: MemorySnapshot;
|
|
634
|
+
/**
|
|
635
|
+
* Enable lazy (on-demand) extension loading to reduce initial memory usage.
|
|
636
|
+
*
|
|
637
|
+
* When enabled:
|
|
638
|
+
* - Extension bundles are NOT loaded during PGlite initialization
|
|
639
|
+
* - Extensions are loaded when `loadExtension()` is called explicitly
|
|
640
|
+
* - Memory is only consumed when extensions are actually needed
|
|
641
|
+
*
|
|
642
|
+
* **Performance Characteristics:**
|
|
643
|
+
* - Faster startup: Skip loading unused extension bundles
|
|
644
|
+
* - Lower baseline memory: Only core PostgreSQL in memory initially
|
|
645
|
+
* - On-demand cost: First use of extension incurs ~100-500ms load time
|
|
646
|
+
*
|
|
647
|
+
* **Recommended for:**
|
|
648
|
+
* - Memory-constrained environments (Cloudflare Workers: 128MB limit)
|
|
649
|
+
* - Applications that conditionally use extensions
|
|
650
|
+
* - Serverless functions with cold start sensitivity
|
|
651
|
+
*
|
|
652
|
+
* @default false
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```typescript
|
|
656
|
+
* const pg = await PGlite.create({
|
|
657
|
+
* extensions: { vector: vectorExtension },
|
|
658
|
+
* lazyExtensions: true, // Don't load vector yet
|
|
659
|
+
* });
|
|
660
|
+
*
|
|
661
|
+
* // Later, when vector is needed:
|
|
662
|
+
* await pg.loadExtension('vector');
|
|
663
|
+
* await pg.exec('CREATE EXTENSION vector;');
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
lazyExtensions?: boolean;
|
|
667
|
+
/**
|
|
668
|
+
* Automatically load extensions when extension-specific SQL is detected.
|
|
669
|
+
*
|
|
670
|
+
* **Note:** This feature requires SQL parsing and is not yet implemented.
|
|
671
|
+
* Currently has no effect. Use `loadExtension()` for explicit loading.
|
|
672
|
+
*
|
|
673
|
+
* @default false
|
|
674
|
+
*/
|
|
675
|
+
autoLoadExtensions?: boolean;
|
|
676
|
+
/**
|
|
677
|
+
* Feature flags to conditionally enable/disable extensions.
|
|
678
|
+
*
|
|
679
|
+
* When a flag is set to `false`, the extension:
|
|
680
|
+
* - Will not appear in `getExtensionStatus()`
|
|
681
|
+
* - Cannot be loaded via `loadExtension()`
|
|
682
|
+
* - `isExtensionAvailable()` returns false
|
|
683
|
+
*
|
|
684
|
+
* **Use Cases:**
|
|
685
|
+
* - A/B testing extension features
|
|
686
|
+
* - Environment-specific extension availability
|
|
687
|
+
* - Gradual rollout of new extensions
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
690
|
+
* ```typescript
|
|
691
|
+
* const pg = await PGlite.create({
|
|
692
|
+
* extensions: { vector: vectorExtension, pgcrypto: pgcryptoExtension },
|
|
693
|
+
* extensionFlags: {
|
|
694
|
+
* vector: process.env.ENABLE_VECTOR === 'true',
|
|
695
|
+
* pgcrypto: true, // Always available
|
|
696
|
+
* },
|
|
697
|
+
* });
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
|
+
extensionFlags?: Record<string, boolean>;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Status of a configured extension.
|
|
704
|
+
*
|
|
705
|
+
* Used by `getExtensionStatus()` to report the current state of each
|
|
706
|
+
* extension. This is particularly useful when using lazy loading to
|
|
707
|
+
* understand which extensions are available vs loaded.
|
|
708
|
+
*
|
|
709
|
+
* @example
|
|
710
|
+
* ```typescript
|
|
711
|
+
* const status = await pg.getExtensionStatus();
|
|
712
|
+
* // { vector: { configured: true, loaded: false } }
|
|
713
|
+
* ```
|
|
714
|
+
*/
|
|
715
|
+
interface ExtensionStatus {
|
|
716
|
+
/**
|
|
717
|
+
* Whether the extension is configured in PGliteOptions.extensions
|
|
718
|
+
* and not disabled by a feature flag.
|
|
719
|
+
*/
|
|
720
|
+
configured: boolean;
|
|
721
|
+
/**
|
|
722
|
+
* Whether the extension bundle has been loaded into WASM memory.
|
|
723
|
+
* When false, the extension can still be loaded on-demand.
|
|
724
|
+
*/
|
|
725
|
+
loaded: boolean;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Memory statistics for a single extension.
|
|
729
|
+
*
|
|
730
|
+
* Provides detailed memory usage information for monitoring extensions
|
|
731
|
+
* in memory-constrained environments like Cloudflare Workers (128MB limit).
|
|
732
|
+
*
|
|
733
|
+
* **Memory Budget Planning:**
|
|
734
|
+
* - bundleSize: Network transfer cost (compressed)
|
|
735
|
+
* - heapIncrease: Actual runtime memory cost (uncompressed + WASM overhead)
|
|
736
|
+
*
|
|
737
|
+
* @example
|
|
738
|
+
* ```typescript
|
|
739
|
+
* const stats = await pg.getExtensionMemoryStats();
|
|
740
|
+
* for (const [name, info] of Object.entries(stats)) {
|
|
741
|
+
* console.log(`${name}: ${info.bundleSize / 1024}KB bundle, ` +
|
|
742
|
+
* `${info.heapIncrease ? info.heapIncrease / 1024 + 'KB heap' : 'heap N/A'}`);
|
|
743
|
+
* }
|
|
744
|
+
* ```
|
|
745
|
+
*/
|
|
746
|
+
interface ExtensionMemoryStats {
|
|
747
|
+
/**
|
|
748
|
+
* Size of the compressed extension bundle in bytes.
|
|
749
|
+
* This is 0 if the extension hasn't been loaded yet.
|
|
750
|
+
*/
|
|
751
|
+
bundleSize: number;
|
|
752
|
+
/**
|
|
753
|
+
* Whether the extension is currently loaded in WASM memory.
|
|
754
|
+
*/
|
|
755
|
+
loaded: boolean;
|
|
756
|
+
/**
|
|
757
|
+
* WASM heap size increase after loading this extension.
|
|
758
|
+
* Only available if heap growth was detected during loading.
|
|
759
|
+
* May be undefined if the heap didn't need to grow.
|
|
760
|
+
*/
|
|
761
|
+
heapIncrease?: number;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Base interface for PGlite without extension namespaces.
|
|
765
|
+
* Classes should implement this interface. The full PGliteInterface
|
|
766
|
+
* type includes extension namespaces and is used for return types.
|
|
767
|
+
*/
|
|
768
|
+
interface PGliteInterfaceBase {
|
|
769
|
+
readonly waitReady: Promise<void>;
|
|
770
|
+
readonly debug: DebugLevel;
|
|
771
|
+
readonly ready: boolean;
|
|
772
|
+
readonly closed: boolean;
|
|
773
|
+
close(): Promise<void>;
|
|
774
|
+
query<T>(query: string, params?: unknown[], options?: QueryOptions): Promise<Results<T>>;
|
|
775
|
+
sql<T>(sqlStrings: TemplateStringsArray, ...params: unknown[]): Promise<Results<T>>;
|
|
776
|
+
exec(query: string, options?: QueryOptions): Promise<Array<Results>>;
|
|
777
|
+
describeQuery(query: string): Promise<DescribeQueryResult>;
|
|
778
|
+
transaction<T>(callback: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
779
|
+
execProtocolRaw(message: Uint8Array, options?: ExecProtocolOptions): Promise<Uint8Array>;
|
|
780
|
+
execProtocol(message: Uint8Array, options?: ExecProtocolOptions): Promise<ExecProtocolResult>;
|
|
781
|
+
runExclusive<T>(fn: () => Promise<T>): Promise<T>;
|
|
782
|
+
listen(channel: string, callback: (payload: string) => void, tx?: Transaction): Promise<(tx?: Transaction) => Promise<void>>;
|
|
783
|
+
unlisten(channel: string, callback?: (payload: string) => void, tx?: Transaction): Promise<void>;
|
|
784
|
+
onNotification(callback: (channel: string, payload: string) => void): () => void;
|
|
785
|
+
offNotification(callback: (channel: string, payload: string) => void): void;
|
|
786
|
+
dumpDataDir(compression?: DumpTarCompressionOptions): Promise<File | Blob>;
|
|
787
|
+
refreshArrayTypes(): Promise<void>;
|
|
788
|
+
getMemoryStats(): Promise<MemoryStats>;
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Full PGlite interface including extension namespaces.
|
|
792
|
+
* Use this for return types. Classes should implement PGliteInterfaceBase.
|
|
793
|
+
*/
|
|
794
|
+
type PGliteInterface<T extends Extensions = Record<string, never>> = PGliteInterfaceBase & InitializedExtensions<T>;
|
|
795
|
+
type PGliteInterfaceExtensions<E> = E extends Extensions ? {
|
|
796
|
+
[K in keyof E]: E[K] extends Extension ? Awaited<ReturnType<E[K]['setup']>>['namespaceObj'] extends infer N ? N extends undefined | null | void ? never : N : never : never;
|
|
797
|
+
} : Record<string, never>;
|
|
798
|
+
type Row<T = {
|
|
799
|
+
[key: string]: unknown;
|
|
800
|
+
}> = T;
|
|
801
|
+
type Results<T = {
|
|
802
|
+
[key: string]: unknown;
|
|
803
|
+
}> = {
|
|
804
|
+
rows: Row<T>[];
|
|
805
|
+
affectedRows?: number;
|
|
806
|
+
fields: {
|
|
807
|
+
name: string;
|
|
808
|
+
dataTypeID: number;
|
|
809
|
+
}[];
|
|
810
|
+
blob?: Blob;
|
|
811
|
+
};
|
|
812
|
+
interface Transaction {
|
|
813
|
+
query<T>(query: string, params?: unknown[], options?: QueryOptions): Promise<Results<T>>;
|
|
814
|
+
sql<T>(sqlStrings: TemplateStringsArray, ...params: unknown[]): Promise<Results<T>>;
|
|
815
|
+
exec(query: string, options?: QueryOptions): Promise<Array<Results>>;
|
|
816
|
+
rollback(): Promise<void>;
|
|
817
|
+
listen(channel: string, callback: (payload: string) => void): Promise<(tx?: Transaction) => Promise<void>>;
|
|
818
|
+
get closed(): boolean;
|
|
819
|
+
}
|
|
820
|
+
type DescribeQueryResult = {
|
|
821
|
+
queryParams: {
|
|
822
|
+
dataTypeID: number;
|
|
823
|
+
serializer: Serializer;
|
|
824
|
+
}[];
|
|
825
|
+
resultFields: {
|
|
826
|
+
name: string;
|
|
827
|
+
dataTypeID: number;
|
|
828
|
+
parser: Parser;
|
|
829
|
+
}[];
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
declare const BOOL = 16;
|
|
833
|
+
declare const BYTEA = 17;
|
|
834
|
+
declare const CHAR = 18;
|
|
835
|
+
declare const INT8 = 20;
|
|
836
|
+
declare const INT2 = 21;
|
|
837
|
+
declare const INT4 = 23;
|
|
838
|
+
declare const REGPROC = 24;
|
|
839
|
+
declare const TEXT = 25;
|
|
840
|
+
declare const OID = 26;
|
|
841
|
+
declare const TID = 27;
|
|
842
|
+
declare const XID = 28;
|
|
843
|
+
declare const CID = 29;
|
|
844
|
+
declare const JSON = 114;
|
|
845
|
+
declare const XML = 142;
|
|
846
|
+
declare const PG_NODE_TREE = 194;
|
|
847
|
+
declare const SMGR = 210;
|
|
848
|
+
declare const PATH = 602;
|
|
849
|
+
declare const POLYGON = 604;
|
|
850
|
+
declare const CIDR = 650;
|
|
851
|
+
declare const FLOAT4 = 700;
|
|
852
|
+
declare const FLOAT8 = 701;
|
|
853
|
+
declare const ABSTIME = 702;
|
|
854
|
+
declare const RELTIME = 703;
|
|
855
|
+
declare const TINTERVAL = 704;
|
|
856
|
+
declare const CIRCLE = 718;
|
|
857
|
+
declare const MACADDR8 = 774;
|
|
858
|
+
declare const MONEY = 790;
|
|
859
|
+
declare const MACADDR = 829;
|
|
860
|
+
declare const INET = 869;
|
|
861
|
+
declare const ACLITEM = 1033;
|
|
862
|
+
declare const BPCHAR = 1042;
|
|
863
|
+
declare const VARCHAR = 1043;
|
|
864
|
+
declare const DATE = 1082;
|
|
865
|
+
declare const TIME = 1083;
|
|
866
|
+
declare const TIMESTAMP = 1114;
|
|
867
|
+
declare const TIMESTAMPTZ = 1184;
|
|
868
|
+
declare const INTERVAL = 1186;
|
|
869
|
+
declare const TIMETZ = 1266;
|
|
870
|
+
declare const BIT = 1560;
|
|
871
|
+
declare const VARBIT = 1562;
|
|
872
|
+
declare const NUMERIC = 1700;
|
|
873
|
+
declare const REFCURSOR = 1790;
|
|
874
|
+
declare const REGPROCEDURE = 2202;
|
|
875
|
+
declare const REGOPER = 2203;
|
|
876
|
+
declare const REGOPERATOR = 2204;
|
|
877
|
+
declare const REGCLASS = 2205;
|
|
878
|
+
declare const REGTYPE = 2206;
|
|
879
|
+
declare const UUID = 2950;
|
|
880
|
+
declare const TXID_SNAPSHOT = 2970;
|
|
881
|
+
declare const PG_LSN = 3220;
|
|
882
|
+
declare const PG_NDISTINCT = 3361;
|
|
883
|
+
declare const PG_DEPENDENCIES = 3402;
|
|
884
|
+
declare const TSVECTOR = 3614;
|
|
885
|
+
declare const TSQUERY = 3615;
|
|
886
|
+
declare const GTSVECTOR = 3642;
|
|
887
|
+
declare const REGCONFIG = 3734;
|
|
888
|
+
declare const REGDICTIONARY = 3769;
|
|
889
|
+
declare const JSONB = 3802;
|
|
890
|
+
declare const REGNAMESPACE = 4089;
|
|
891
|
+
declare const REGROLE = 4096;
|
|
892
|
+
declare const types: {
|
|
893
|
+
string: {
|
|
894
|
+
to: number;
|
|
895
|
+
from: number[];
|
|
896
|
+
serialize: (x: string | number) => string;
|
|
897
|
+
parse: (x: string) => string;
|
|
898
|
+
};
|
|
899
|
+
number: {
|
|
900
|
+
to: number;
|
|
901
|
+
from: number[];
|
|
902
|
+
serialize: (x: number) => string;
|
|
903
|
+
parse: (x: string) => number;
|
|
904
|
+
};
|
|
905
|
+
bigint: {
|
|
906
|
+
to: number;
|
|
907
|
+
from: number[];
|
|
908
|
+
serialize: (x: bigint) => string;
|
|
909
|
+
parse: (x: string) => number | bigint;
|
|
910
|
+
};
|
|
911
|
+
json: {
|
|
912
|
+
to: number;
|
|
913
|
+
from: number[];
|
|
914
|
+
serialize: (x: any) => string;
|
|
915
|
+
parse: (x: string) => any;
|
|
916
|
+
};
|
|
917
|
+
boolean: {
|
|
918
|
+
to: number;
|
|
919
|
+
from: number[];
|
|
920
|
+
serialize: (x: boolean) => "t" | "f";
|
|
921
|
+
parse: (x: string) => x is "t";
|
|
922
|
+
};
|
|
923
|
+
date: {
|
|
924
|
+
to: number;
|
|
925
|
+
from: number[];
|
|
926
|
+
serialize: (x: Date | string | number) => string;
|
|
927
|
+
parse: (x: string | number) => Date;
|
|
928
|
+
};
|
|
929
|
+
bytea: {
|
|
930
|
+
to: number;
|
|
931
|
+
from: number[];
|
|
932
|
+
serialize: (x: Uint8Array) => string;
|
|
933
|
+
parse: (x: string) => Uint8Array;
|
|
934
|
+
};
|
|
935
|
+
};
|
|
936
|
+
type Parser = (x: string, typeId?: number) => any;
|
|
937
|
+
type Serializer = (x: any) => string;
|
|
938
|
+
type TypeHandler = {
|
|
939
|
+
to: number;
|
|
940
|
+
from: number | number[];
|
|
941
|
+
serialize: Serializer;
|
|
942
|
+
parse: Parser;
|
|
943
|
+
};
|
|
944
|
+
type TypeHandlers = {
|
|
945
|
+
[key: string]: TypeHandler;
|
|
946
|
+
};
|
|
947
|
+
declare const parsers: {
|
|
948
|
+
[key: string]: (x: string, typeId?: number) => any;
|
|
949
|
+
[key: number]: (x: string, typeId?: number) => any;
|
|
950
|
+
};
|
|
951
|
+
declare const serializers: {
|
|
952
|
+
[key: string]: Serializer;
|
|
953
|
+
[key: number]: Serializer;
|
|
954
|
+
};
|
|
955
|
+
declare function parseType(x: string | null, type: number, parsers?: ParserOptions): any;
|
|
956
|
+
declare function arraySerializer(xs: any, serializer: Serializer | undefined, typarray: number): string;
|
|
957
|
+
declare function arrayParser(x: string, parser: Parser, typarray: number): any;
|
|
958
|
+
|
|
959
|
+
declare const types$1_ABSTIME: typeof ABSTIME;
|
|
960
|
+
declare const types$1_ACLITEM: typeof ACLITEM;
|
|
961
|
+
declare const types$1_BIT: typeof BIT;
|
|
962
|
+
declare const types$1_BOOL: typeof BOOL;
|
|
963
|
+
declare const types$1_BPCHAR: typeof BPCHAR;
|
|
964
|
+
declare const types$1_BYTEA: typeof BYTEA;
|
|
965
|
+
declare const types$1_CHAR: typeof CHAR;
|
|
966
|
+
declare const types$1_CID: typeof CID;
|
|
967
|
+
declare const types$1_CIDR: typeof CIDR;
|
|
968
|
+
declare const types$1_CIRCLE: typeof CIRCLE;
|
|
969
|
+
declare const types$1_DATE: typeof DATE;
|
|
970
|
+
declare const types$1_FLOAT4: typeof FLOAT4;
|
|
971
|
+
declare const types$1_FLOAT8: typeof FLOAT8;
|
|
972
|
+
declare const types$1_GTSVECTOR: typeof GTSVECTOR;
|
|
973
|
+
declare const types$1_INET: typeof INET;
|
|
974
|
+
declare const types$1_INT2: typeof INT2;
|
|
975
|
+
declare const types$1_INT4: typeof INT4;
|
|
976
|
+
declare const types$1_INT8: typeof INT8;
|
|
977
|
+
declare const types$1_INTERVAL: typeof INTERVAL;
|
|
978
|
+
declare const types$1_JSON: typeof JSON;
|
|
979
|
+
declare const types$1_JSONB: typeof JSONB;
|
|
980
|
+
declare const types$1_MACADDR: typeof MACADDR;
|
|
981
|
+
declare const types$1_MACADDR8: typeof MACADDR8;
|
|
982
|
+
declare const types$1_MONEY: typeof MONEY;
|
|
983
|
+
declare const types$1_NUMERIC: typeof NUMERIC;
|
|
984
|
+
declare const types$1_OID: typeof OID;
|
|
985
|
+
declare const types$1_PATH: typeof PATH;
|
|
986
|
+
declare const types$1_PG_DEPENDENCIES: typeof PG_DEPENDENCIES;
|
|
987
|
+
declare const types$1_PG_LSN: typeof PG_LSN;
|
|
988
|
+
declare const types$1_PG_NDISTINCT: typeof PG_NDISTINCT;
|
|
989
|
+
declare const types$1_PG_NODE_TREE: typeof PG_NODE_TREE;
|
|
990
|
+
declare const types$1_POLYGON: typeof POLYGON;
|
|
991
|
+
type types$1_Parser = Parser;
|
|
992
|
+
declare const types$1_REFCURSOR: typeof REFCURSOR;
|
|
993
|
+
declare const types$1_REGCLASS: typeof REGCLASS;
|
|
994
|
+
declare const types$1_REGCONFIG: typeof REGCONFIG;
|
|
995
|
+
declare const types$1_REGDICTIONARY: typeof REGDICTIONARY;
|
|
996
|
+
declare const types$1_REGNAMESPACE: typeof REGNAMESPACE;
|
|
997
|
+
declare const types$1_REGOPER: typeof REGOPER;
|
|
998
|
+
declare const types$1_REGOPERATOR: typeof REGOPERATOR;
|
|
999
|
+
declare const types$1_REGPROC: typeof REGPROC;
|
|
1000
|
+
declare const types$1_REGPROCEDURE: typeof REGPROCEDURE;
|
|
1001
|
+
declare const types$1_REGROLE: typeof REGROLE;
|
|
1002
|
+
declare const types$1_REGTYPE: typeof REGTYPE;
|
|
1003
|
+
declare const types$1_RELTIME: typeof RELTIME;
|
|
1004
|
+
declare const types$1_SMGR: typeof SMGR;
|
|
1005
|
+
type types$1_Serializer = Serializer;
|
|
1006
|
+
declare const types$1_TEXT: typeof TEXT;
|
|
1007
|
+
declare const types$1_TID: typeof TID;
|
|
1008
|
+
declare const types$1_TIME: typeof TIME;
|
|
1009
|
+
declare const types$1_TIMESTAMP: typeof TIMESTAMP;
|
|
1010
|
+
declare const types$1_TIMESTAMPTZ: typeof TIMESTAMPTZ;
|
|
1011
|
+
declare const types$1_TIMETZ: typeof TIMETZ;
|
|
1012
|
+
declare const types$1_TINTERVAL: typeof TINTERVAL;
|
|
1013
|
+
declare const types$1_TSQUERY: typeof TSQUERY;
|
|
1014
|
+
declare const types$1_TSVECTOR: typeof TSVECTOR;
|
|
1015
|
+
declare const types$1_TXID_SNAPSHOT: typeof TXID_SNAPSHOT;
|
|
1016
|
+
type types$1_TypeHandler = TypeHandler;
|
|
1017
|
+
type types$1_TypeHandlers = TypeHandlers;
|
|
1018
|
+
declare const types$1_UUID: typeof UUID;
|
|
1019
|
+
declare const types$1_VARBIT: typeof VARBIT;
|
|
1020
|
+
declare const types$1_VARCHAR: typeof VARCHAR;
|
|
1021
|
+
declare const types$1_XID: typeof XID;
|
|
1022
|
+
declare const types$1_XML: typeof XML;
|
|
1023
|
+
declare const types$1_arrayParser: typeof arrayParser;
|
|
1024
|
+
declare const types$1_arraySerializer: typeof arraySerializer;
|
|
1025
|
+
declare const types$1_parseType: typeof parseType;
|
|
1026
|
+
declare const types$1_parsers: typeof parsers;
|
|
1027
|
+
declare const types$1_serializers: typeof serializers;
|
|
1028
|
+
declare const types$1_types: typeof types;
|
|
1029
|
+
declare namespace types$1 {
|
|
1030
|
+
export { types$1_ABSTIME as ABSTIME, types$1_ACLITEM as ACLITEM, types$1_BIT as BIT, types$1_BOOL as BOOL, types$1_BPCHAR as BPCHAR, types$1_BYTEA as BYTEA, types$1_CHAR as CHAR, types$1_CID as CID, types$1_CIDR as CIDR, types$1_CIRCLE as CIRCLE, types$1_DATE as DATE, types$1_FLOAT4 as FLOAT4, types$1_FLOAT8 as FLOAT8, types$1_GTSVECTOR as GTSVECTOR, types$1_INET as INET, types$1_INT2 as INT2, types$1_INT4 as INT4, types$1_INT8 as INT8, types$1_INTERVAL as INTERVAL, types$1_JSON as JSON, types$1_JSONB as JSONB, types$1_MACADDR as MACADDR, types$1_MACADDR8 as MACADDR8, types$1_MONEY as MONEY, types$1_NUMERIC as NUMERIC, types$1_OID as OID, types$1_PATH as PATH, types$1_PG_DEPENDENCIES as PG_DEPENDENCIES, types$1_PG_LSN as PG_LSN, types$1_PG_NDISTINCT as PG_NDISTINCT, types$1_PG_NODE_TREE as PG_NODE_TREE, types$1_POLYGON as POLYGON, type types$1_Parser as Parser, types$1_REFCURSOR as REFCURSOR, types$1_REGCLASS as REGCLASS, types$1_REGCONFIG as REGCONFIG, types$1_REGDICTIONARY as REGDICTIONARY, types$1_REGNAMESPACE as REGNAMESPACE, types$1_REGOPER as REGOPER, types$1_REGOPERATOR as REGOPERATOR, types$1_REGPROC as REGPROC, types$1_REGPROCEDURE as REGPROCEDURE, types$1_REGROLE as REGROLE, types$1_REGTYPE as REGTYPE, types$1_RELTIME as RELTIME, types$1_SMGR as SMGR, type types$1_Serializer as Serializer, types$1_TEXT as TEXT, types$1_TID as TID, types$1_TIME as TIME, types$1_TIMESTAMP as TIMESTAMP, types$1_TIMESTAMPTZ as TIMESTAMPTZ, types$1_TIMETZ as TIMETZ, types$1_TINTERVAL as TINTERVAL, types$1_TSQUERY as TSQUERY, types$1_TSVECTOR as TSVECTOR, types$1_TXID_SNAPSHOT as TXID_SNAPSHOT, type types$1_TypeHandler as TypeHandler, type types$1_TypeHandlers as TypeHandlers, types$1_UUID as UUID, types$1_VARBIT as VARBIT, types$1_VARCHAR as VARCHAR, types$1_XID as XID, types$1_XML as XML, types$1_arrayParser as arrayParser, types$1_arraySerializer as arraySerializer, types$1_parseType as parseType, types$1_parsers as parsers, types$1_serializers as serializers, types$1_types as types };
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
declare abstract class BasePGlite implements Pick<PGliteInterfaceBase, 'query' | 'sql' | 'exec' | 'transaction'> {
|
|
1034
|
+
#private;
|
|
1035
|
+
serializers: Record<number | string, Serializer>;
|
|
1036
|
+
parsers: Record<number | string, Parser>;
|
|
1037
|
+
abstract debug: DebugLevel;
|
|
1038
|
+
/**
|
|
1039
|
+
* Execute a postgres wire protocol message
|
|
1040
|
+
* @param message The postgres wire protocol message to execute
|
|
1041
|
+
* @returns The result of the query
|
|
1042
|
+
*/
|
|
1043
|
+
abstract execProtocol(message: Uint8Array, { syncToFs, onNotice }: ExecProtocolOptions): Promise<ExecProtocolResult>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Execute a postgres wire protocol message
|
|
1046
|
+
* @param message The postgres wire protocol message to execute
|
|
1047
|
+
* @returns The parsed results of the query
|
|
1048
|
+
*/
|
|
1049
|
+
abstract execProtocolStream(message: Uint8Array, { syncToFs, onNotice }: ExecProtocolOptions): Promise<BackendMessage[]>;
|
|
1050
|
+
/**
|
|
1051
|
+
* Execute a postgres wire protocol message directly without wrapping the response.
|
|
1052
|
+
* Only use if `execProtocol()` doesn't suite your needs.
|
|
1053
|
+
*
|
|
1054
|
+
* **Warning:** This bypasses PGlite's protocol wrappers that manage error/notice messages,
|
|
1055
|
+
* transactions, and notification listeners. Only use if you need to bypass these wrappers and
|
|
1056
|
+
* don't intend to use the above features.
|
|
1057
|
+
*
|
|
1058
|
+
* @param message The postgres wire protocol message to execute
|
|
1059
|
+
* @returns The direct message data response produced by Postgres
|
|
1060
|
+
*/
|
|
1061
|
+
abstract execProtocolRaw(message: Uint8Array, { syncToFs }: ExecProtocolOptions): Promise<Uint8Array>;
|
|
1062
|
+
/**
|
|
1063
|
+
* Sync the database to the filesystem
|
|
1064
|
+
* @returns Promise that resolves when the database is synced to the filesystem
|
|
1065
|
+
*/
|
|
1066
|
+
abstract syncToFs(): Promise<void>;
|
|
1067
|
+
/**
|
|
1068
|
+
* Handle a file attached to the current query
|
|
1069
|
+
* @param file The file to handle
|
|
1070
|
+
*/
|
|
1071
|
+
abstract _handleBlob(blob?: File | Blob): Promise<void>;
|
|
1072
|
+
/**
|
|
1073
|
+
* Get the written file
|
|
1074
|
+
*/
|
|
1075
|
+
abstract _getWrittenBlob(): Promise<File | Blob | undefined>;
|
|
1076
|
+
/**
|
|
1077
|
+
* Cleanup the current file
|
|
1078
|
+
*/
|
|
1079
|
+
abstract _cleanupBlob(): Promise<void>;
|
|
1080
|
+
abstract _checkReady(): Promise<void>;
|
|
1081
|
+
abstract _runExclusiveQuery<T>(fn: () => Promise<T>): Promise<T>;
|
|
1082
|
+
abstract _runExclusiveTransaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
1083
|
+
/**
|
|
1084
|
+
* Listen for notifications on a channel
|
|
1085
|
+
*/
|
|
1086
|
+
abstract listen(channel: string, callback: (payload: string) => void, tx?: Transaction): Promise<(tx?: Transaction) => Promise<void>>;
|
|
1087
|
+
/**
|
|
1088
|
+
* Initialize the array types
|
|
1089
|
+
* The oid if the type of an element and the typarray is the oid of the type of the
|
|
1090
|
+
* array.
|
|
1091
|
+
* We extract these from the database then create the serializers/parsers for
|
|
1092
|
+
* each type.
|
|
1093
|
+
* This should be called at the end of #init() in the implementing class.
|
|
1094
|
+
*/
|
|
1095
|
+
_initArrayTypes({ force }?: {
|
|
1096
|
+
force?: boolean | undefined;
|
|
1097
|
+
}): Promise<void>;
|
|
1098
|
+
/**
|
|
1099
|
+
* Re-syncs the array types from the database
|
|
1100
|
+
* This is useful if you add a new type to the database and want to use it, otherwise pglite won't recognize it.
|
|
1101
|
+
*/
|
|
1102
|
+
refreshArrayTypes(): Promise<void>;
|
|
1103
|
+
/**
|
|
1104
|
+
* Execute a single SQL statement
|
|
1105
|
+
* This uses the "Extended Query" postgres wire protocol message.
|
|
1106
|
+
* @param query The query to execute
|
|
1107
|
+
* @param params Optional parameters for the query
|
|
1108
|
+
* @returns The result of the query
|
|
1109
|
+
*/
|
|
1110
|
+
query<T>(query: string, params?: any[], options?: QueryOptions): Promise<Results<T>>;
|
|
1111
|
+
/**
|
|
1112
|
+
* Execute a single SQL statement like with {@link PGlite.query}, but with a
|
|
1113
|
+
* templated statement where template values will be treated as parameters.
|
|
1114
|
+
*
|
|
1115
|
+
* You can use helpers from `/template` to further format the query with
|
|
1116
|
+
* identifiers, raw SQL, and nested statements.
|
|
1117
|
+
*
|
|
1118
|
+
* This uses the "Extended Query" postgres wire protocol message.
|
|
1119
|
+
*
|
|
1120
|
+
* @param query The query to execute with parameters as template values
|
|
1121
|
+
* @returns The result of the query
|
|
1122
|
+
*
|
|
1123
|
+
* @example
|
|
1124
|
+
* ```ts
|
|
1125
|
+
* const results = await db.sql`SELECT * FROM ${identifier`foo`} WHERE id = ${id}`
|
|
1126
|
+
* ```
|
|
1127
|
+
*/
|
|
1128
|
+
sql<T>(sqlStrings: TemplateStringsArray, ...params: any[]): Promise<Results<T>>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Execute a SQL query, this can have multiple statements.
|
|
1131
|
+
* This uses the "Simple Query" postgres wire protocol message.
|
|
1132
|
+
* @param query The query to execute
|
|
1133
|
+
* @returns The result of the query
|
|
1134
|
+
*/
|
|
1135
|
+
exec(query: string, options?: QueryOptions): Promise<Array<Results>>;
|
|
1136
|
+
/**
|
|
1137
|
+
* Describe a query
|
|
1138
|
+
* @param query The query to describe
|
|
1139
|
+
* @returns A description of the result types for the query
|
|
1140
|
+
*/
|
|
1141
|
+
describeQuery(query: string, options?: QueryOptions): Promise<DescribeQueryResult>;
|
|
1142
|
+
/**
|
|
1143
|
+
* Execute a transaction
|
|
1144
|
+
* @param callback A callback function that takes a transaction object
|
|
1145
|
+
* @returns The result of the transaction
|
|
1146
|
+
*/
|
|
1147
|
+
transaction<T>(callback: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
1148
|
+
/**
|
|
1149
|
+
* Run a function exclusively, no other transactions or queries will be allowed
|
|
1150
|
+
* while the function is running.
|
|
1151
|
+
* This is useful when working with the execProtocol methods as they are not blocked,
|
|
1152
|
+
* and do not block the locks used by transactions and queries.
|
|
1153
|
+
* @param fn The function to run
|
|
1154
|
+
* @returns The result of the function
|
|
1155
|
+
*/
|
|
1156
|
+
runExclusive<T>(fn: () => Promise<T>): Promise<T>;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
declare class PGlite extends BasePGlite implements PGliteInterfaceBase, AsyncDisposable {
|
|
1160
|
+
#private;
|
|
1161
|
+
fs?: Filesystem;
|
|
1162
|
+
protected mod?: PostgresMod;
|
|
1163
|
+
readonly dataDir?: string;
|
|
1164
|
+
readonly waitReady: Promise<void>;
|
|
1165
|
+
readonly debug: DebugLevel;
|
|
1166
|
+
static readonly DEFAULT_RECV_BUF_SIZE: number;
|
|
1167
|
+
static readonly MAX_BUFFER_SIZE: number;
|
|
1168
|
+
/**
|
|
1169
|
+
* Create a new PGlite instance
|
|
1170
|
+
* @param dataDir The directory to store the database files
|
|
1171
|
+
* Prefix with idb:// to use indexeddb filesystem in the browser
|
|
1172
|
+
* Use memory:// to use in-memory filesystem
|
|
1173
|
+
* @param options PGlite options
|
|
1174
|
+
*/
|
|
1175
|
+
constructor(dataDir?: string, options?: PGliteOptions);
|
|
1176
|
+
/**
|
|
1177
|
+
* Create a new PGlite instance
|
|
1178
|
+
* @param options PGlite options including the data directory
|
|
1179
|
+
*/
|
|
1180
|
+
constructor(options?: PGliteOptions);
|
|
1181
|
+
/**
|
|
1182
|
+
* Create a new PGlite instance with extensions on the Typescript interface
|
|
1183
|
+
* (The main constructor does enable extensions, however due to the limitations
|
|
1184
|
+
* of Typescript, the extensions are not available on the instance interface)
|
|
1185
|
+
* @param options PGlite options including the data directory
|
|
1186
|
+
* @returns A promise that resolves to the PGlite instance when it's ready.
|
|
1187
|
+
*/
|
|
1188
|
+
static create<O extends PGliteOptions>(options?: O): Promise<PGlite & PGliteInterfaceExtensions<O['extensions']>>;
|
|
1189
|
+
/**
|
|
1190
|
+
* Create a new PGlite instance with extensions on the Typescript interface
|
|
1191
|
+
* (The main constructor does enable extensions, however due to the limitations
|
|
1192
|
+
* of Typescript, the extensions are not available on the instance interface)
|
|
1193
|
+
* @param dataDir The directory to store the database files
|
|
1194
|
+
* Prefix with idb:// to use indexeddb filesystem in the browser
|
|
1195
|
+
* Use memory:// to use in-memory filesystem
|
|
1196
|
+
* @param options PGlite options
|
|
1197
|
+
* @returns A promise that resolves to the PGlite instance when it's ready.
|
|
1198
|
+
*/
|
|
1199
|
+
static create<O extends PGliteOptions>(dataDir?: string, options?: O): Promise<PGlite & PGliteInterfaceExtensions<O['extensions']>>;
|
|
1200
|
+
/**
|
|
1201
|
+
* Capture a memory snapshot of the current PGlite state.
|
|
1202
|
+
* This can be used for fast cold starts by skipping initdb.
|
|
1203
|
+
*
|
|
1204
|
+
* IMPORTANT: Only capture snapshots from a freshly initialized instance
|
|
1205
|
+
* without user data. Snapshots should be created at build time.
|
|
1206
|
+
*
|
|
1207
|
+
* @returns A MemorySnapshot that can be used to restore the state
|
|
1208
|
+
*/
|
|
1209
|
+
captureSnapshot(): Promise<MemorySnapshot>;
|
|
1210
|
+
/**
|
|
1211
|
+
* The Postgres Emscripten Module
|
|
1212
|
+
*/
|
|
1213
|
+
get Module(): PostgresMod;
|
|
1214
|
+
/**
|
|
1215
|
+
* The ready state of the database
|
|
1216
|
+
*/
|
|
1217
|
+
get ready(): boolean;
|
|
1218
|
+
/**
|
|
1219
|
+
* The closed state of the database
|
|
1220
|
+
*/
|
|
1221
|
+
get closed(): boolean;
|
|
1222
|
+
/**
|
|
1223
|
+
* Get memory statistics for monitoring WASM heap usage.
|
|
1224
|
+
* Useful for tracking memory consumption in constrained environments
|
|
1225
|
+
* like Cloudflare Workers (128MB limit).
|
|
1226
|
+
*
|
|
1227
|
+
* @returns Memory statistics including heap size and PostgreSQL settings
|
|
1228
|
+
*/
|
|
1229
|
+
getMemoryStats(): Promise<MemoryStats>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Load a single extension on demand.
|
|
1232
|
+
*
|
|
1233
|
+
* This method enables lazy loading of PostgreSQL extensions, deferring the
|
|
1234
|
+
* memory cost of extension bundles until they are actually needed. This is
|
|
1235
|
+
* particularly valuable in memory-constrained environments like Cloudflare
|
|
1236
|
+
* Workers (128MB limit).
|
|
1237
|
+
*
|
|
1238
|
+
* **Performance Characteristics:**
|
|
1239
|
+
* - First call: Resolves dependencies, fetches bundle, compiles WASM (~100-500ms)
|
|
1240
|
+
* - Subsequent calls: Returns immediately (no-op)
|
|
1241
|
+
* - Memory: Bundle size + ~10-50% overhead for compiled code
|
|
1242
|
+
*
|
|
1243
|
+
* **Thread Safety:**
|
|
1244
|
+
* This method is protected by a mutex to prevent race conditions when
|
|
1245
|
+
* multiple concurrent calls attempt to load the same extension.
|
|
1246
|
+
*
|
|
1247
|
+
* @param extName The name of the extension to load (must match key in extensions option)
|
|
1248
|
+
* @throws Error if extension is not configured, disabled by feature flag, or loading fails
|
|
1249
|
+
*
|
|
1250
|
+
* @example
|
|
1251
|
+
* ```typescript
|
|
1252
|
+
* const pg = await PGlite.create({
|
|
1253
|
+
* extensions: { vector: vectorExtension },
|
|
1254
|
+
* lazyExtensions: true,
|
|
1255
|
+
* });
|
|
1256
|
+
*
|
|
1257
|
+
* // Extension not loaded yet - minimal memory footprint
|
|
1258
|
+
* await pg.loadExtension('vector');
|
|
1259
|
+
* // Now vector extension is available for use
|
|
1260
|
+
*
|
|
1261
|
+
* await pg.exec('CREATE EXTENSION IF NOT EXISTS vector;');
|
|
1262
|
+
* ```
|
|
1263
|
+
*/
|
|
1264
|
+
loadExtension(extName: string): Promise<void>;
|
|
1265
|
+
/**
|
|
1266
|
+
* Load multiple extensions concurrently.
|
|
1267
|
+
*
|
|
1268
|
+
* This method loads multiple extensions in parallel where possible, while
|
|
1269
|
+
* respecting dependency ordering. Each extension's loadExtension call is
|
|
1270
|
+
* protected by a mutex, so dependencies are resolved correctly even with
|
|
1271
|
+
* concurrent calls.
|
|
1272
|
+
*
|
|
1273
|
+
* **Performance Note:**
|
|
1274
|
+
* For extensions with shared dependencies, this is more efficient than
|
|
1275
|
+
* sequential loading because the dependency is only loaded once (the
|
|
1276
|
+
* loadExtension mutex ensures idempotent loading).
|
|
1277
|
+
*
|
|
1278
|
+
* @param extNames Array of extension names to load
|
|
1279
|
+
*
|
|
1280
|
+
* @example
|
|
1281
|
+
* ```typescript
|
|
1282
|
+
* // Load vector and pgcrypto concurrently
|
|
1283
|
+
* await pg.loadExtensions(['vector', 'pgcrypto']);
|
|
1284
|
+
* ```
|
|
1285
|
+
*/
|
|
1286
|
+
loadExtensions(extNames: string[]): Promise<void>;
|
|
1287
|
+
/**
|
|
1288
|
+
* Get the load status of all configured extensions.
|
|
1289
|
+
*
|
|
1290
|
+
* This method returns information about which extensions are configured
|
|
1291
|
+
* and whether they have been loaded into memory. Useful for:
|
|
1292
|
+
* - Debugging extension availability
|
|
1293
|
+
* - Monitoring lazy loading progress
|
|
1294
|
+
* - Building UI that shows extension status
|
|
1295
|
+
*
|
|
1296
|
+
* **Note:** Extensions disabled by feature flags are excluded from the result.
|
|
1297
|
+
*
|
|
1298
|
+
* @returns Object mapping extension names to their status (configured/loaded)
|
|
1299
|
+
*
|
|
1300
|
+
* @example
|
|
1301
|
+
* ```typescript
|
|
1302
|
+
* const status = await pg.getExtensionStatus();
|
|
1303
|
+
* // { vector: { configured: true, loaded: false },
|
|
1304
|
+
* // pgcrypto: { configured: true, loaded: true } }
|
|
1305
|
+
*
|
|
1306
|
+
* const unloaded = Object.entries(status)
|
|
1307
|
+
* .filter(([_, s]) => !s.loaded)
|
|
1308
|
+
* .map(([name]) => name);
|
|
1309
|
+
* ```
|
|
1310
|
+
*/
|
|
1311
|
+
getExtensionStatus(): Promise<Record<string, ExtensionStatus>>;
|
|
1312
|
+
/**
|
|
1313
|
+
* Check if an extension is available for use.
|
|
1314
|
+
*
|
|
1315
|
+
* An extension is available if it:
|
|
1316
|
+
* 1. Is configured in the extensions option
|
|
1317
|
+
* 2. Is not disabled by a feature flag
|
|
1318
|
+
*
|
|
1319
|
+
* This does NOT check if the extension is loaded - use `getExtensionStatus()`
|
|
1320
|
+
* to check load state.
|
|
1321
|
+
*
|
|
1322
|
+
* **Use Case:** Check availability before attempting to use extension features,
|
|
1323
|
+
* enabling graceful degradation when extensions are not configured.
|
|
1324
|
+
*
|
|
1325
|
+
* @param extName The extension name to check
|
|
1326
|
+
* @returns true if the extension can be loaded and used
|
|
1327
|
+
*
|
|
1328
|
+
* @example
|
|
1329
|
+
* ```typescript
|
|
1330
|
+
* if (await pg.isExtensionAvailable('vector')) {
|
|
1331
|
+
* await pg.loadExtension('vector');
|
|
1332
|
+
* await pg.exec('CREATE EXTENSION vector;');
|
|
1333
|
+
* } else {
|
|
1334
|
+
* console.log('Vector search not available');
|
|
1335
|
+
* }
|
|
1336
|
+
* ```
|
|
1337
|
+
*/
|
|
1338
|
+
isExtensionAvailable(extName: string): Promise<boolean>;
|
|
1339
|
+
/**
|
|
1340
|
+
* Get memory statistics for each configured extension.
|
|
1341
|
+
*
|
|
1342
|
+
* Returns detailed memory information for monitoring and optimization:
|
|
1343
|
+
* - **bundleSize**: Compressed bundle size in bytes (0 if not loaded)
|
|
1344
|
+
* - **loaded**: Whether the extension is currently in memory
|
|
1345
|
+
* - **heapIncrease**: WASM heap growth when extension was loaded (if measurable)
|
|
1346
|
+
*
|
|
1347
|
+
* **Memory Monitoring Use Cases:**
|
|
1348
|
+
* - Track which extensions consume the most memory
|
|
1349
|
+
* - Monitor total extension memory in constrained environments
|
|
1350
|
+
* - Identify candidates for lazy loading optimization
|
|
1351
|
+
*
|
|
1352
|
+
* **Note:** heapIncrease may not always be available if the heap didn't grow
|
|
1353
|
+
* during loading (e.g., if sufficient memory was already allocated).
|
|
1354
|
+
*
|
|
1355
|
+
* @returns Object mapping extension names to their memory statistics
|
|
1356
|
+
*
|
|
1357
|
+
* @example
|
|
1358
|
+
* ```typescript
|
|
1359
|
+
* const memStats = await pg.getExtensionMemoryStats();
|
|
1360
|
+
* const totalBundleSize = Object.values(memStats)
|
|
1361
|
+
* .reduce((sum, s) => sum + s.bundleSize, 0);
|
|
1362
|
+
* console.log(`Total extension bundles: ${(totalBundleSize / 1024).toFixed(1)} KB`);
|
|
1363
|
+
* ```
|
|
1364
|
+
*/
|
|
1365
|
+
getExtensionMemoryStats(): Promise<Record<string, ExtensionMemoryStats>>;
|
|
1366
|
+
/**
|
|
1367
|
+
* Register a callback to be notified when an extension is loaded.
|
|
1368
|
+
*
|
|
1369
|
+
* Callbacks are invoked asynchronously (via queueMicrotask) after each
|
|
1370
|
+
* extension finishes loading. This allows you to:
|
|
1371
|
+
* - Track loading progress in real-time
|
|
1372
|
+
* - Update UI when extensions become available
|
|
1373
|
+
* - Log extension loading for debugging
|
|
1374
|
+
*
|
|
1375
|
+
* **Thread Safety:** Callbacks are invoked after the loading mutex is released,
|
|
1376
|
+
* so it's safe to call other PGlite methods from within the callback.
|
|
1377
|
+
*
|
|
1378
|
+
* @param callback Function called with extension name when loading completes
|
|
1379
|
+
* @returns Unsubscribe function to remove the listener
|
|
1380
|
+
*
|
|
1381
|
+
* @example
|
|
1382
|
+
* ```typescript
|
|
1383
|
+
* const unsubscribe = pg.onExtensionLoad((extName) => {
|
|
1384
|
+
* console.log(`Extension ${extName} is now available`);
|
|
1385
|
+
* });
|
|
1386
|
+
*
|
|
1387
|
+
* await pg.loadExtension('vector');
|
|
1388
|
+
* // Logs: "Extension vector is now available"
|
|
1389
|
+
*
|
|
1390
|
+
* unsubscribe(); // Stop listening
|
|
1391
|
+
* ```
|
|
1392
|
+
*/
|
|
1393
|
+
onExtensionLoad(callback: (extName: string) => void): () => void;
|
|
1394
|
+
/**
|
|
1395
|
+
* Close the database
|
|
1396
|
+
* @returns A promise that resolves when the database is closed
|
|
1397
|
+
*/
|
|
1398
|
+
close(): Promise<void>;
|
|
1399
|
+
/**
|
|
1400
|
+
* Close the database when the object exits scope
|
|
1401
|
+
* Stage 3 ECMAScript Explicit Resource Management
|
|
1402
|
+
* https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management
|
|
1403
|
+
*/
|
|
1404
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
1405
|
+
/**
|
|
1406
|
+
* Handle a file attached to the current query
|
|
1407
|
+
* @param file The file to handle
|
|
1408
|
+
*/
|
|
1409
|
+
_handleBlob(blob?: File | Blob): Promise<void>;
|
|
1410
|
+
/**
|
|
1411
|
+
* Cleanup the current file
|
|
1412
|
+
*/
|
|
1413
|
+
_cleanupBlob(): Promise<void>;
|
|
1414
|
+
/**
|
|
1415
|
+
* Get the written blob from the current query
|
|
1416
|
+
* @returns The written blob
|
|
1417
|
+
*/
|
|
1418
|
+
_getWrittenBlob(): Promise<Blob | undefined>;
|
|
1419
|
+
/**
|
|
1420
|
+
* Wait for the database to be ready
|
|
1421
|
+
*/
|
|
1422
|
+
_checkReady(): Promise<void>;
|
|
1423
|
+
/**
|
|
1424
|
+
* Execute a postgres wire protocol synchronously
|
|
1425
|
+
* @param message The postgres wire protocol message to execute
|
|
1426
|
+
* @returns The direct message data response produced by Postgres
|
|
1427
|
+
*/
|
|
1428
|
+
execProtocolRawSync(message: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
1429
|
+
/**
|
|
1430
|
+
* Execute a postgres wire protocol message directly without wrapping the response.
|
|
1431
|
+
* Only use if `execProtocol()` doesn't suite your needs.
|
|
1432
|
+
*
|
|
1433
|
+
* **Warning:** This bypasses PGlite's protocol wrappers that manage error/notice messages,
|
|
1434
|
+
* transactions, and notification listeners. Only use if you need to bypass these wrappers and
|
|
1435
|
+
* don't intend to use the above features.
|
|
1436
|
+
*
|
|
1437
|
+
* @param message The postgres wire protocol message to execute
|
|
1438
|
+
* @returns The direct message data response produced by Postgres
|
|
1439
|
+
*/
|
|
1440
|
+
execProtocolRaw(message: Uint8Array, { syncToFs }?: ExecProtocolOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
1441
|
+
/**
|
|
1442
|
+
* Execute a postgres wire protocol message
|
|
1443
|
+
* @param message The postgres wire protocol message to execute
|
|
1444
|
+
* @returns The result of the query
|
|
1445
|
+
*/
|
|
1446
|
+
execProtocol(message: Uint8Array, { syncToFs, throwOnError, onNotice, }?: ExecProtocolOptions): Promise<ExecProtocolResult>;
|
|
1447
|
+
/**
|
|
1448
|
+
* Execute a postgres wire protocol message
|
|
1449
|
+
* @param message The postgres wire protocol message to execute
|
|
1450
|
+
* @returns The parsed results of the query
|
|
1451
|
+
*/
|
|
1452
|
+
execProtocolStream(message: Uint8Array, { syncToFs, throwOnError, onNotice }?: ExecProtocolOptions): Promise<BackendMessage[]>;
|
|
1453
|
+
/**
|
|
1454
|
+
* Check if the database is in a transaction
|
|
1455
|
+
* @returns True if the database is in a transaction, false otherwise
|
|
1456
|
+
*/
|
|
1457
|
+
isInTransaction(): boolean;
|
|
1458
|
+
/**
|
|
1459
|
+
* Perform any sync operations implemented by the filesystem, this is
|
|
1460
|
+
* run after every query to ensure that the filesystem is synced.
|
|
1461
|
+
*/
|
|
1462
|
+
syncToFs(): Promise<void>;
|
|
1463
|
+
/**
|
|
1464
|
+
* Listen for a notification
|
|
1465
|
+
* @param channel The channel to listen on
|
|
1466
|
+
* @param callback The callback to call when a notification is received
|
|
1467
|
+
*/
|
|
1468
|
+
listen(channel: string, callback: (payload: string) => void, tx?: Transaction): Promise<(tx?: Transaction) => Promise<void>>;
|
|
1469
|
+
/**
|
|
1470
|
+
* Stop listening for a notification
|
|
1471
|
+
* @param channel The channel to stop listening on
|
|
1472
|
+
* @param callback The callback to remove
|
|
1473
|
+
*/
|
|
1474
|
+
unlisten(channel: string, callback?: (payload: string) => void, tx?: Transaction): Promise<void>;
|
|
1475
|
+
/**
|
|
1476
|
+
* Listen to notifications
|
|
1477
|
+
* @param callback The callback to call when a notification is received
|
|
1478
|
+
*/
|
|
1479
|
+
onNotification(callback: (channel: string, payload: string) => void): () => void;
|
|
1480
|
+
/**
|
|
1481
|
+
* Stop listening to notifications
|
|
1482
|
+
* @param callback The callback to remove
|
|
1483
|
+
*/
|
|
1484
|
+
offNotification(callback: (channel: string, payload: string) => void): void;
|
|
1485
|
+
/**
|
|
1486
|
+
* Dump the PGDATA dir from the filesystem to a gzipped tarball.
|
|
1487
|
+
* @param compression The compression options to use - 'gzip', 'auto', 'none'
|
|
1488
|
+
* @returns The tarball as a File object where available, and fallback to a Blob
|
|
1489
|
+
*/
|
|
1490
|
+
dumpDataDir(compression?: DumpTarCompressionOptions): Promise<File | Blob>;
|
|
1491
|
+
/**
|
|
1492
|
+
* Run a function in a mutex that's exclusive to queries
|
|
1493
|
+
* @param fn The query to run
|
|
1494
|
+
* @returns The result of the query
|
|
1495
|
+
*/
|
|
1496
|
+
_runExclusiveQuery<T>(fn: () => Promise<T>): Promise<T>;
|
|
1497
|
+
/**
|
|
1498
|
+
* Run a function in a mutex that's exclusive to transactions
|
|
1499
|
+
* @param fn The function to run
|
|
1500
|
+
* @returns The result of the function
|
|
1501
|
+
*/
|
|
1502
|
+
_runExclusiveTransaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
1503
|
+
clone(): Promise<PGliteInterface>;
|
|
1504
|
+
_runExclusiveListen<T>(fn: () => Promise<T>): Promise<T>;
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
export { type DescribeQueryResult as A, type BackendMessage as B, BaseFilesystem as C, type DebugLevel as D, EmscriptenBuiltinFilesystem as E, type FilesystemType as F, type FsStats as G, BasePGlite as H, type InitializedExtensions as I, type DumpTarCompressionOptions as J, PGDATA as K, type FsType as L, type Mode as M, type Filesystem as N, ERRNO_CODES as O, type Parser as P, type QueryOptions as Q, type Results as R, type SerializerOptions as S, type Transaction as T, WASM_PREFIX as W, type BufferParameter as a, PGlite as b, type PostgresMod as c, type PGliteInterfaceBase as d, type MemorySnapshot as e, type PGliteCallbacks as f, type RowMode as g, type ParserOptions as h, type ExecProtocolOptions as i, type ExtensionSetupResult as j, type ExtensionSetup as k, type Extension as l, messages as m, type ExtensionNamespace as n, type Extensions as o, postgresMod as p, type ExecProtocolResult as q, type DumpDataDirResult as r, type MemoryStats as s, types$1 as t, type PGliteOptions as u, type ExtensionStatus as v, type ExtensionMemoryStats as w, type PGliteInterface as x, type PGliteInterfaceExtensions as y, type Row as z };
|