@pgxsinkit/pgwasm 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE-APACHE-2.0 +202 -0
  3. package/NOTICE +111 -0
  4. package/README.md +56 -0
  5. package/dist/build/index.d.ts +8 -0
  6. package/dist/build/index.d.ts.map +1 -0
  7. package/dist/build/index.js +21 -0
  8. package/dist/build/index.js.map +9 -0
  9. package/dist/build/seam.d.ts +174 -0
  10. package/dist/build/seam.d.ts.map +1 -0
  11. package/dist/chunk-0w227vw2.js +233 -0
  12. package/dist/chunk-0w227vw2.js.map +11 -0
  13. package/dist/chunk-74gcrk47.js +563 -0
  14. package/dist/chunk-74gcrk47.js.map +14 -0
  15. package/dist/chunk-at1py5s5.js +373 -0
  16. package/dist/chunk-at1py5s5.js.map +12 -0
  17. package/dist/chunk-cpsnmzrf.js +126 -0
  18. package/dist/chunk-cpsnmzrf.js.map +10 -0
  19. package/dist/chunk-d82gg1hx.js +306 -0
  20. package/dist/chunk-d82gg1hx.js.map +10 -0
  21. package/dist/chunk-gjf102c9.js +1005 -0
  22. package/dist/chunk-gjf102c9.js.map +16 -0
  23. package/dist/chunk-kb3rsr7n.js +19 -0
  24. package/dist/chunk-kb3rsr7n.js.map +9 -0
  25. package/dist/chunk-tdvrvgt5.js +83 -0
  26. package/dist/chunk-tdvrvgt5.js.map +11 -0
  27. package/dist/chunk-z0c40tja.js +50 -0
  28. package/dist/chunk-z0c40tja.js.map +10 -0
  29. package/dist/core/data-dir-archive.d.ts +17 -0
  30. package/dist/core/data-dir-archive.d.ts.map +1 -0
  31. package/dist/core/internals.d.ts +59 -0
  32. package/dist/core/internals.d.ts.map +1 -0
  33. package/dist/core/marker.d.ts +35 -0
  34. package/dist/core/marker.d.ts.map +1 -0
  35. package/dist/core/mutex.d.ts +9 -0
  36. package/dist/core/mutex.d.ts.map +1 -0
  37. package/dist/core/names.d.ts +11 -0
  38. package/dist/core/names.d.ts.map +1 -0
  39. package/dist/core/parse.d.ts +11 -0
  40. package/dist/core/parse.d.ts.map +1 -0
  41. package/dist/core/pgwasm.d.ts +53 -0
  42. package/dist/core/pgwasm.d.ts.map +1 -0
  43. package/dist/core/storage.d.ts +14 -0
  44. package/dist/core/storage.d.ts.map +1 -0
  45. package/dist/create.d.ts +10 -0
  46. package/dist/create.d.ts.map +1 -0
  47. package/dist/drizzle/codecs.d.ts +9 -0
  48. package/dist/drizzle/codecs.d.ts.map +1 -0
  49. package/dist/drizzle/driver.d.ts +50 -0
  50. package/dist/drizzle/driver.d.ts.map +1 -0
  51. package/dist/drizzle/index.d.ts +4 -0
  52. package/dist/drizzle/index.d.ts.map +1 -0
  53. package/dist/drizzle/index.js +261 -0
  54. package/dist/drizzle/index.js.map +12 -0
  55. package/dist/drizzle/session.d.ts +39 -0
  56. package/dist/drizzle/session.d.ts.map +1 -0
  57. package/dist/errors.d.ts +115 -0
  58. package/dist/errors.d.ts.map +1 -0
  59. package/dist/fs/base-filesystem.d.ts +118 -0
  60. package/dist/fs/base-filesystem.d.ts.map +1 -0
  61. package/dist/fs/index.d.ts +2 -0
  62. package/dist/fs/index.d.ts.map +1 -0
  63. package/dist/fs/index.js +11 -0
  64. package/dist/fs/index.js.map +9 -0
  65. package/dist/index.d.ts +8 -0
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/index.js +53 -0
  68. package/dist/index.js.map +9 -0
  69. package/dist/interface.d.ts +165 -0
  70. package/dist/interface.d.ts.map +1 -0
  71. package/dist/live/debounce-mutex.d.ts +6 -0
  72. package/dist/live/debounce-mutex.d.ts.map +1 -0
  73. package/dist/live/format-query.d.ts +8 -0
  74. package/dist/live/format-query.d.ts.map +1 -0
  75. package/dist/live/index.d.ts +9 -0
  76. package/dist/live/index.d.ts.map +1 -0
  77. package/dist/live/index.js +601 -0
  78. package/dist/live/index.js.map +12 -0
  79. package/dist/live/interface.d.ts +86 -0
  80. package/dist/live/interface.d.ts.map +1 -0
  81. package/dist/opfs/broker/client.d.ts +163 -0
  82. package/dist/opfs/broker/client.d.ts.map +1 -0
  83. package/dist/opfs/broker/protocol.d.ts +326 -0
  84. package/dist/opfs/broker/protocol.d.ts.map +1 -0
  85. package/dist/opfs/broker/server.d.ts +84 -0
  86. package/dist/opfs/broker/server.d.ts.map +1 -0
  87. package/dist/opfs/core/checksum.d.ts +3 -0
  88. package/dist/opfs/core/checksum.d.ts.map +1 -0
  89. package/dist/opfs/core/codec.d.ts +73 -0
  90. package/dist/opfs/core/codec.d.ts.map +1 -0
  91. package/dist/opfs/core/errors.d.ts +80 -0
  92. package/dist/opfs/core/errors.d.ts.map +1 -0
  93. package/dist/opfs/core/limits.d.ts +35 -0
  94. package/dist/opfs/core/limits.d.ts.map +1 -0
  95. package/dist/opfs/core/memory-port.d.ts +51 -0
  96. package/dist/opfs/core/memory-port.d.ts.map +1 -0
  97. package/dist/opfs/core/metadata-store.d.ts +19 -0
  98. package/dist/opfs/core/metadata-store.d.ts.map +1 -0
  99. package/dist/opfs/core/mounted-vfs.d.ts +119 -0
  100. package/dist/opfs/core/mounted-vfs.d.ts.map +1 -0
  101. package/dist/opfs/core/path.d.ts +14 -0
  102. package/dist/opfs/core/path.d.ts.map +1 -0
  103. package/dist/opfs/core/port.d.ts +30 -0
  104. package/dist/opfs/core/port.d.ts.map +1 -0
  105. package/dist/opfs/core/repacked-vfs.d.ts +138 -0
  106. package/dist/opfs/core/repacked-vfs.d.ts.map +1 -0
  107. package/dist/opfs/core/state-machine.d.ts +296 -0
  108. package/dist/opfs/core/state-machine.d.ts.map +1 -0
  109. package/dist/opfs/create.d.ts +50 -0
  110. package/dist/opfs/create.d.ts.map +1 -0
  111. package/dist/opfs/file-port.d.ts +14 -0
  112. package/dist/opfs/file-port.d.ts.map +1 -0
  113. package/dist/opfs/index.d.ts +37 -0
  114. package/dist/opfs/index.d.ts.map +1 -0
  115. package/dist/opfs/index.js +6671 -0
  116. package/dist/opfs/index.js.map +28 -0
  117. package/dist/opfs/opfs-port.d.ts +34 -0
  118. package/dist/opfs/opfs-port.d.ts.map +1 -0
  119. package/dist/opfs/opfs-repacked-fs.d.ts +55 -0
  120. package/dist/opfs/opfs-repacked-fs.d.ts.map +1 -0
  121. package/dist/opfs/wasi/preview1.d.ts +228 -0
  122. package/dist/opfs/wasi/preview1.d.ts.map +1 -0
  123. package/dist/protocol/index.d.ts +15 -0
  124. package/dist/protocol/index.d.ts.map +1 -0
  125. package/dist/protocol/index.js +23 -0
  126. package/dist/protocol/index.js.map +10 -0
  127. package/dist/protocol/wire/buffer-reader.d.ts +13 -0
  128. package/dist/protocol/wire/buffer-reader.d.ts.map +1 -0
  129. package/dist/protocol/wire/buffer-writer.d.ts +12 -0
  130. package/dist/protocol/wire/buffer-writer.d.ts.map +1 -0
  131. package/dist/protocol/wire/index.d.ts +5 -0
  132. package/dist/protocol/wire/index.d.ts.map +1 -0
  133. package/dist/protocol/wire/messages.d.ts +194 -0
  134. package/dist/protocol/wire/messages.d.ts.map +1 -0
  135. package/dist/protocol/wire/parser.d.ts +12 -0
  136. package/dist/protocol/wire/parser.d.ts.map +1 -0
  137. package/dist/protocol/wire/serializer.d.ts +61 -0
  138. package/dist/protocol/wire/serializer.d.ts.map +1 -0
  139. package/dist/protocol/wire/string-utils.d.ts +6 -0
  140. package/dist/protocol/wire/string-utils.d.ts.map +1 -0
  141. package/dist/protocol/wire/types.d.ts +7 -0
  142. package/dist/protocol/wire/types.d.ts.map +1 -0
  143. package/dist/tar/gzip.d.ts +7 -0
  144. package/dist/tar/gzip.d.ts.map +1 -0
  145. package/dist/tar/tar.d.ts +39 -0
  146. package/dist/tar/tar.d.ts.map +1 -0
  147. package/dist/templating.d.ts +42 -0
  148. package/dist/templating.d.ts.map +1 -0
  149. package/dist/types.d.ts +76 -0
  150. package/dist/types.d.ts.map +1 -0
  151. package/package.json +69 -0
  152. package/skills/opfs/SKILL.md +138 -0
  153. package/src/build/index.ts +23 -0
  154. package/src/build/seam.ts +179 -0
  155. package/src/core/data-dir-archive.ts +68 -0
  156. package/src/core/internals.ts +87 -0
  157. package/src/core/marker.ts +94 -0
  158. package/src/core/mutex.ts +16 -0
  159. package/src/core/names.ts +26 -0
  160. package/src/core/parse.ts +79 -0
  161. package/src/core/pgwasm.ts +876 -0
  162. package/src/core/storage.ts +70 -0
  163. package/src/create.ts +134 -0
  164. package/src/drizzle/codecs.ts +114 -0
  165. package/src/drizzle/driver.ts +141 -0
  166. package/src/drizzle/index.ts +15 -0
  167. package/src/drizzle/session.ts +133 -0
  168. package/src/errors.ts +201 -0
  169. package/src/fs/base-filesystem.ts +149 -0
  170. package/src/fs/index.ts +7 -0
  171. package/src/index.ts +44 -0
  172. package/src/interface.ts +186 -0
  173. package/src/live/debounce-mutex.ts +45 -0
  174. package/src/live/format-query.ts +47 -0
  175. package/src/live/index.ts +707 -0
  176. package/src/live/interface.ts +109 -0
  177. package/src/opfs/broker/client.ts +482 -0
  178. package/src/opfs/broker/protocol.ts +624 -0
  179. package/src/opfs/broker/server.ts +522 -0
  180. package/src/opfs/core/checksum.ts +85 -0
  181. package/src/opfs/core/codec.ts +1051 -0
  182. package/src/opfs/core/errors.ts +134 -0
  183. package/src/opfs/core/limits.ts +68 -0
  184. package/src/opfs/core/memory-port.ts +459 -0
  185. package/src/opfs/core/metadata-store.ts +512 -0
  186. package/src/opfs/core/mounted-vfs.ts +407 -0
  187. package/src/opfs/core/path.ts +82 -0
  188. package/src/opfs/core/port.ts +114 -0
  189. package/src/opfs/core/repacked-vfs.ts +1464 -0
  190. package/src/opfs/core/state-machine.ts +1699 -0
  191. package/src/opfs/create.ts +125 -0
  192. package/src/opfs/file-port.ts +183 -0
  193. package/src/opfs/index.ts +113 -0
  194. package/src/opfs/opfs-port.ts +90 -0
  195. package/src/opfs/opfs-repacked-fs.ts +210 -0
  196. package/src/opfs/wasi/preview1.ts +1016 -0
  197. package/src/protocol/index.ts +24 -0
  198. package/src/protocol/wire/buffer-reader.ts +60 -0
  199. package/src/protocol/wire/buffer-writer.ts +93 -0
  200. package/src/protocol/wire/index.ts +15 -0
  201. package/src/protocol/wire/messages.ts +332 -0
  202. package/src/protocol/wire/parser.ts +373 -0
  203. package/src/protocol/wire/serializer.ts +233 -0
  204. package/src/protocol/wire/string-utils.ts +18 -0
  205. package/src/protocol/wire/types.ts +12 -0
  206. package/src/tar/gzip.ts +36 -0
  207. package/src/tar/tar.ts +253 -0
  208. package/src/templating.ts +103 -0
  209. package/src/types.ts +283 -0
@@ -0,0 +1,115 @@
1
+ import type { BuildIdentity, FilesystemKind } from "./build/seam";
2
+ import type { QueryOptions } from "./interface";
3
+ import type { DatabaseError } from "./protocol/wire/messages";
4
+ /** The base of every error pgwasm itself raises (SQL errors are {@link DatabaseError}). */
5
+ export declare class PgwasmError extends Error {
6
+ name: string;
7
+ }
8
+ /** A `dataDir` pgwasm does not accept: an unknown scheme, a bare path, or `dataDir` with `fs`. */
9
+ export declare class UnsupportedDataDirError extends PgwasmError {
10
+ name: string;
11
+ readonly dataDir: string;
12
+ constructor(dataDir: string, reason: string);
13
+ }
14
+ /** An `opfs-ahp://` dataDir: that filesystem is gone (ADR-0062 decision 6). */
15
+ export declare class OpfsAhpRemovedError extends UnsupportedDataDirError {
16
+ name: string;
17
+ /** Where the OPFS store lives now. */
18
+ readonly replacement = "@pgxsinkit/pgwasm/opfs";
19
+ constructor(dataDir: string);
20
+ }
21
+ /** The build does not mount the requested kind of storage. */
22
+ export declare class UnsupportedFilesystemError extends PgwasmError {
23
+ name: string;
24
+ readonly kind: FilesystemKind;
25
+ readonly build: string;
26
+ constructor(kind: FilesystemKind, build: BuildIdentity, supported: readonly FilesystemKind[]);
27
+ }
28
+ /** The build needs a cross-origin-isolated context, and this one is not. */
29
+ export declare class CrossOriginIsolationRequiredError extends PgwasmError {
30
+ name: string;
31
+ constructor(build: BuildIdentity);
32
+ }
33
+ /** A server extension compiled for another build. */
34
+ export declare class ExtensionBuildMismatchError extends PgwasmError {
35
+ name: string;
36
+ constructor(extension: string, extensionBuild: string, build: BuildIdentity);
37
+ }
38
+ /** The build a data directory (or a Store backup) records. `"unmarked"` predates build markers. */
39
+ export type RecordedBuild = {
40
+ readonly build: string;
41
+ readonly dataFormat: number;
42
+ } | "unmarked";
43
+ /**
44
+ * A data directory or Store backup made by another Postgres build. A store's build is fixed when it is
45
+ * created (ADR-0063 build permanence); nothing was written.
46
+ */
47
+ export declare class BuildMismatchError extends PgwasmError {
48
+ name: string;
49
+ readonly expected: {
50
+ readonly build: string;
51
+ readonly dataFormat: number;
52
+ };
53
+ readonly found: RecordedBuild;
54
+ readonly source: "data-directory" | "backup";
55
+ constructor(build: BuildIdentity, found: RecordedBuild, source: "data-directory" | "backup");
56
+ }
57
+ /** A data directory or backup of the same build in a data format this release does not read. */
58
+ export declare class DataFormatMismatchError extends PgwasmError {
59
+ name: string;
60
+ readonly expected: number;
61
+ readonly found: number;
62
+ readonly source: "data-directory" | "backup";
63
+ constructor(build: BuildIdentity, found: number, source: "data-directory" | "backup");
64
+ }
65
+ /** A build marker that cannot be read: corrupt, or written by a newer pgwasm. Nothing was written. */
66
+ export declare class BuildMarkerUnreadableError extends PgwasmError {
67
+ name: string;
68
+ readonly raw: string;
69
+ constructor(raw: string, reason: string);
70
+ }
71
+ /** `loadDataDir` was given for a data directory that already holds a database. */
72
+ export declare class DataDirExistsError extends PgwasmError {
73
+ name: string;
74
+ constructor();
75
+ }
76
+ /** A Store backup that cannot be restored: not a tarball, or a member outside the data directory. */
77
+ export declare class BackupFormatError extends PgwasmError {
78
+ name: string;
79
+ }
80
+ /** The storage is held by another open database (an IndexedDB store open in another context). */
81
+ export declare class StorageInUseError extends PgwasmError {
82
+ name: string;
83
+ constructor(message: string);
84
+ }
85
+ /** The database is closing or closed. */
86
+ export declare class PgwasmClosedError extends PgwasmError {
87
+ name: string;
88
+ constructor(state: "closing" | "closed");
89
+ }
90
+ /**
91
+ * The Postgres build failed underneath a statement (an exception that is not an SQL error: a storage
92
+ * failure thrown into the engine, a PANIC's abort). The instance is failed: every later statement
93
+ * throws this same error, and `close()` releases resources and rejects with it.
94
+ */
95
+ export declare class PgwasmFailedError extends PgwasmError {
96
+ name: string;
97
+ }
98
+ /** A feature the build does not have (see its capabilities). */
99
+ export declare class UnsupportedFeatureError extends PgwasmError {
100
+ name: string;
101
+ }
102
+ /** An SQL error from a query, with the query that raised it. */
103
+ export interface QueryError extends DatabaseError {
104
+ query: string | undefined;
105
+ params: readonly unknown[] | undefined;
106
+ queryOptions: QueryOptions | undefined;
107
+ }
108
+ /** Attach the query to the SQL error it raised. */
109
+ export declare function makeQueryError(data: {
110
+ error: DatabaseError;
111
+ query: string;
112
+ params: readonly unknown[] | undefined;
113
+ options: QueryOptions | undefined;
114
+ }): QueryError;
115
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,2FAA2F;AAC3F,qBAAa,WAAY,SAAQ,KAAK;IAC3B,IAAI,SAAiB;CAC/B;AAED,kGAAkG;AAClG,qBAAa,uBAAwB,SAAQ,WAAW;IAC7C,IAAI,SAA6B;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAG1C;CACF;AAED,+EAA+E;AAC/E,qBAAa,mBAAoB,SAAQ,uBAAuB;IACrD,IAAI,SAAyB;IACtC,sCAAsC;IACtC,QAAQ,CAAC,WAAW,4BAA4B;IAEhD,YAAY,OAAO,EAAE,MAAM,EAM1B;CACF;AAED,8DAA8D;AAC9D,qBAAa,0BAA2B,SA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;IACvC,OAAO,EAAE,YAAY,GAAG,SAAS,CAAC;CACnC,GAAG,UAAU,CAEb"}
@@ -0,0 +1,118 @@
1
+ /** Stat results, in the shape a POSIX `stat` returns them. Times are milliseconds since the epoch. */
2
+ export interface FsStats {
3
+ dev: number;
4
+ ino: number;
5
+ mode: number;
6
+ nlink: number;
7
+ uid: number;
8
+ gid: number;
9
+ rdev: number;
10
+ size: number;
11
+ blksize: number;
12
+ blocks: number;
13
+ atime: number;
14
+ mtime: number;
15
+ ctime: number;
16
+ }
17
+ /**
18
+ * Errno values, in the numbering Postgres builds use (Emscripten's). A filesystem reports a failed
19
+ * operation by throwing an error whose `code` is one of these; an error without a `code` is reported to
20
+ * Postgres as `EIO`.
21
+ */
22
+ export declare const ERRNO_CODES: {
23
+ readonly EBADF: 8;
24
+ readonly EBADFD: 127;
25
+ readonly EEXIST: 20;
26
+ readonly EINVAL: 28;
27
+ readonly EIO: 29;
28
+ readonly EISDIR: 31;
29
+ readonly ENODEV: 43;
30
+ readonly ENOENT: 44;
31
+ readonly ENOTDIR: 54;
32
+ readonly ENOTEMPTY: 55;
33
+ };
34
+ /**
35
+ * A filesystem call that failed and was reported to Postgres as an errno. Kept in a small ring so
36
+ * that when Postgres later fails, the storage failures underneath it are visible.
37
+ */
38
+ export interface SyscallError {
39
+ readonly op: string;
40
+ readonly path: string;
41
+ readonly errno: number;
42
+ readonly message: string;
43
+ readonly timeMs: number;
44
+ }
45
+ /**
46
+ * What a filesystem says about itself, reported in `pg.storage` as `{ kind: "vfs", ...description }`:
47
+ * a short name for diagnostics, and whether what it holds survives the process (or the page) that wrote it.
48
+ */
49
+ export interface FilesystemDescription {
50
+ /** A short name for diagnostics, e.g. `opfs-repacked`. */
51
+ readonly name: string;
52
+ /**
53
+ * Whether the data directory outlives the process (or page) that wrote it. Absent when the filesystem
54
+ * doesn't say: nothing outside it can tell, so callers treat an undeclared filesystem as the author's
55
+ * own call rather than as non-persistent.
56
+ */
57
+ readonly persistent?: boolean;
58
+ }
59
+ /**
60
+ * A synchronous virtual filesystem that holds a data directory, mounted by a Postgres build in place
61
+ * of its built-in storage (pass it as `createPgwasm({ fs })`). Paths are absolute within the
62
+ * filesystem, `/`-separated, `/` being the data directory itself.
63
+ *
64
+ * Besides the POSIX-shaped operations, a filesystem takes part in durability: pgwasm calls
65
+ * `syncToFs(relaxed)` after statements (see `createPgwasm`'s `relaxedDurability`), the build calls
66
+ * `initialSyncFs()` once when it mounts the filesystem, `closeFs()` when the database closes and
67
+ * `cleanupFailedInit()` when a boot fails after the filesystem was handed over.
68
+ */
69
+ export declare abstract class BaseFilesystem {
70
+ #private;
71
+ readonly debug: boolean;
72
+ constructor({ debug }?: {
73
+ debug?: boolean;
74
+ });
75
+ /**
76
+ * What this filesystem is, as `pg.storage` reports it. Defaults to `{ name: "custom" }`, persistence
77
+ * undeclared: a filesystem overrides it to name itself and to say whether its data outlives the process
78
+ * (`persistent: true`) or not (`persistent: false`), since nothing else can tell.
79
+ */
80
+ get description(): FilesystemDescription;
81
+ /** The most recent failed filesystem calls reported to Postgres (up to 50), oldest first. */
82
+ get recentSyscallErrors(): readonly SyscallError[];
83
+ /** Record a failed call. The build's mount calls this where it turns a thrown error into an errno. */
84
+ recordSyscallError(op: string, path: string, errno: number, message: string): void;
85
+ /** Make everything written so far durable. `relaxed` is pgwasm's background persist. */
86
+ syncToFs(_relaxed?: boolean): Promise<void>;
87
+ /** Called once when the build mounts the filesystem, before anything reads it. */
88
+ initialSyncFs(): Promise<void>;
89
+ /** Release everything the filesystem holds. Called when the database closes. */
90
+ closeFs(): Promise<void>;
91
+ /** Release what the filesystem holds after a boot failed. Defaults to {@link closeFs}. */
92
+ cleanupFailedInit(): Promise<void>;
93
+ abstract chmod(path: string, mode: number): void;
94
+ abstract close(fd: number): void;
95
+ abstract fstat(fd: number): FsStats;
96
+ abstract lstat(path: string): FsStats;
97
+ abstract mkdir(path: string, options?: {
98
+ recursive?: boolean;
99
+ mode?: number;
100
+ }): void;
101
+ abstract open(path: string, flags?: string, mode?: number): number;
102
+ abstract readdir(path: string): string[];
103
+ /** Read into `buffer[offset, offset + length)` from `position`; returns the bytes read. */
104
+ abstract read(fd: number, buffer: Uint8Array, offset: number, length: number, position: number): number;
105
+ abstract rename(oldPath: string, newPath: string): void;
106
+ abstract rmdir(path: string): void;
107
+ abstract truncate(path: string, length: number): void;
108
+ abstract unlink(path: string): void;
109
+ abstract utimes(path: string, atime: number, mtime: number): void;
110
+ abstract writeFile(path: string, data: string | Uint8Array, options?: {
111
+ encoding?: string;
112
+ mode?: number;
113
+ flag?: string;
114
+ }): void;
115
+ /** Write `buffer[offset, offset + length)` at `position`; returns the bytes written. */
116
+ abstract write(fd: number, buffer: Uint8Array, offset: number, length: number, position: number): number;
117
+ }
118
+ //# sourceMappingURL=base-filesystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-filesystem.d.ts","sourceRoot":"","sources":["../../src/fs/base-filesystem.ts"],"names":[],"mappings":"AAGA,sGAAsG;AACtG,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW;aACtB,KAAK,EAAE,CAAC;aACR,MAAM,EAAE,GAAG;aACX,MAAM,EAAE,EAAE;aACV,MAAM,EAAE,EAAE;aACV,GAAG,EAAE,EAAE;aACP,MAAM,EAAE,EAAE;aACV,MAAM,EAAE,EAAE;a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,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAClE,QAAQ,CAAC,SAAS,CAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5D,IAAI,CAAC;IACR,wFAAwF;IACxF,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1G"}
@@ -0,0 +1,2 @@
1
+ export { BaseFilesystem, ERRNO_CODES, type FilesystemDescription, type FsStats, type SyscallError, } from "./base-filesystem";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,WAAW,EACX,KAAK,qBAAqB,EAC1B,KAAK,OAAO,EACZ,KAAK,YAAY,GAClB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,11 @@
1
+ // @bun
2
+ import {
3
+ ERRNO_CODES2,
4
+ BaseFilesystem2
5
+ } from "../chunk-z0c40tja.js";
6
+ export {
7
+ BaseFilesystem2 as BaseFilesystem,
8
+ ERRNO_CODES2 as ERRNO_CODES
9
+ };
10
+
11
+ //# debugId=4A8A8482683E477F64756E2164756E21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "4A8A8482683E477F64756E2164756E21",
8
+ "names": []
9
+ }
@@ -0,0 +1,8 @@
1
+ export { createPgwasm } from "./create";
2
+ export type { DebugLevel, DumpCompression, Extension, ExtensionNamespaces, ExtensionSetupResult, Extensions, FilesystemKind, ParserOptions, Pgwasm, PgwasmOptions, PgwasmWithExtensions, QueryOptions, Results, Row, RowMode, SerializerOptions, StorageDescription, Transaction, } from "./interface";
3
+ export type { BuildIdentity, PostgresBuild, ServerExtension } from "./build/seam";
4
+ export { BackupFormatError, BuildMarkerUnreadableError, BuildMismatchError, CrossOriginIsolationRequiredError, DataDirExistsError, DataFormatMismatchError, ExtensionBuildMismatchError, OpfsAhpRemovedError, PgwasmClosedError, PgwasmError, PgwasmFailedError, StorageInUseError, UnsupportedDataDirError, UnsupportedFeatureError, UnsupportedFilesystemError, type QueryError, type RecordedBuild, } from "./errors";
5
+ export { DatabaseError } from "./protocol/wire/messages";
6
+ export { identifier, raw } from "./templating";
7
+ export * as types from "./types";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EACV,UAAU,EACV,eAAe,EACf,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,UAAU,EACV,cAAc,EACd,aAAa,EACb,MAAM,EACN,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,OAAO,EACP,GAAG,EACH,OAAO,EACP,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,kBAAkB,EAClB,iCAAiC,EACjC,kBAAkB,EAClB,uBAAuB,EACvB,2BAA2B,EAC3B,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,EAC1B,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ // @bun
2
+ import {
3
+ identifier2,
4
+ raw2,
5
+ createPgwasm2
6
+ } from "./chunk-gjf102c9.js";
7
+ import {
8
+ PgwasmError2,
9
+ UnsupportedDataDirError2,
10
+ OpfsAhpRemovedError2,
11
+ UnsupportedFilesystemError2,
12
+ CrossOriginIsolationRequiredError2,
13
+ ExtensionBuildMismatchError2,
14
+ BuildMismatchError2,
15
+ DataFormatMismatchError2,
16
+ BuildMarkerUnreadableError2,
17
+ DataDirExistsError2,
18
+ BackupFormatError2,
19
+ StorageInUseError2,
20
+ PgwasmClosedError2,
21
+ PgwasmFailedError2,
22
+ UnsupportedFeatureError2
23
+ } from "./chunk-cpsnmzrf.js";
24
+ import {
25
+ exports_types
26
+ } from "./chunk-d82gg1hx.js";
27
+ import {
28
+ DatabaseError2
29
+ } from "./chunk-74gcrk47.js";
30
+ export {
31
+ BackupFormatError2 as BackupFormatError,
32
+ BuildMarkerUnreadableError2 as BuildMarkerUnreadableError,
33
+ BuildMismatchError2 as BuildMismatchError,
34
+ CrossOriginIsolationRequiredError2 as CrossOriginIsolationRequiredError,
35
+ DataDirExistsError2 as DataDirExistsError,
36
+ DataFormatMismatchError2 as DataFormatMismatchError,
37
+ DatabaseError2 as DatabaseError,
38
+ ExtensionBuildMismatchError2 as ExtensionBuildMismatchError,
39
+ OpfsAhpRemovedError2 as OpfsAhpRemovedError,
40
+ PgwasmClosedError2 as PgwasmClosedError,
41
+ PgwasmError2 as PgwasmError,
42
+ PgwasmFailedError2 as PgwasmFailedError,
43
+ StorageInUseError2 as StorageInUseError,
44
+ UnsupportedDataDirError2 as UnsupportedDataDirError,
45
+ UnsupportedFeatureError2 as UnsupportedFeatureError,
46
+ UnsupportedFilesystemError2 as UnsupportedFilesystemError,
47
+ createPgwasm2 as createPgwasm,
48
+ identifier2 as identifier,
49
+ raw2 as raw,
50
+ exports_types as types
51
+ };
52
+
53
+ //# debugId=C7AC010DA503A44C64756E2164756E21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "C7AC010DA503A44C64756E2164756E21",
8
+ "names": []
9
+ }
@@ -0,0 +1,165 @@
1
+ import type { BuildIdentity, DebugLevel, FilesystemKind, PostgresBuild, ServerExtension } from "./build/seam";
2
+ import type { BaseFilesystem } from "./fs/base-filesystem";
3
+ import type { NoticeMessage } from "./protocol/wire/messages";
4
+ export type { DebugLevel } from "./build/seam";
5
+ /** `object` rows keyed by column name, or `array` rows in column order. */
6
+ export type RowMode = "array" | "object";
7
+ /** A result row when no row type is given. */
8
+ export type Row = Record<string, unknown>;
9
+ /** Per-query parsers, by type OID. */
10
+ export interface ParserOptions {
11
+ [pgType: number]: (value: string, typeId?: number) => unknown;
12
+ }
13
+ /** Per-query serializers, by type OID. */
14
+ export interface SerializerOptions {
15
+ [pgType: number]: (value: unknown) => string;
16
+ }
17
+ export interface QueryOptions {
18
+ readonly rowMode?: RowMode;
19
+ readonly parsers?: ParserOptions;
20
+ readonly serializers?: SerializerOptions;
21
+ /** What `COPY … FROM '/dev/blob'` reads during this query. */
22
+ readonly blob?: Blob | File;
23
+ readonly onNotice?: (notice: NoticeMessage) => void;
24
+ /** Parameter type OIDs to declare, in order, instead of letting Postgres infer them. */
25
+ readonly paramTypes?: readonly number[];
26
+ }
27
+ /** The result of one statement. */
28
+ export interface Results<T = Row> {
29
+ rows: T[];
30
+ /** Rows changed so far by INSERT/UPDATE/DELETE/COPY/MERGE, cumulative across a multi-statement exec. */
31
+ affectedRows?: number;
32
+ /** The statement's command, e.g. "SELECT", "INSERT", "CREATE". */
33
+ command?: string;
34
+ /** The row count in the command tag (rows returned or changed by this statement). */
35
+ rowCount?: number;
36
+ fields: {
37
+ name: string;
38
+ dataTypeID: number;
39
+ }[];
40
+ /** What `COPY … TO '/dev/blob'` wrote, when it wrote anything. */
41
+ blob?: Blob;
42
+ }
43
+ /** The handle a `transaction` callback receives. It stops working when the transaction ends. */
44
+ export interface Transaction {
45
+ query<T = Row>(sql: string, params?: readonly unknown[], options?: QueryOptions): Promise<Results<T>>;
46
+ sql<T = Row>(sqlStrings: TemplateStringsArray, ...params: unknown[]): Promise<Results<T>>;
47
+ exec(sql: string, options?: QueryOptions): Promise<Results[]>;
48
+ rollback(): Promise<void>;
49
+ listen(channel: string, callback: (payload: string) => void): Promise<(tx?: Transaction) => Promise<void>>;
50
+ readonly closed: boolean;
51
+ }
52
+ /** Where a data directory lives, as reported by {@link Pgwasm.storage}. */
53
+ export type StorageDescription = {
54
+ readonly kind: "memory";
55
+ } | {
56
+ readonly kind: "idb";
57
+ readonly name: string;
58
+ } | {
59
+ readonly kind: "file";
60
+ readonly path: string;
61
+ }
62
+ /**
63
+ * A filesystem passed as `createPgwasm({ fs })`, as its `description` reports it. `persistent` is absent
64
+ * when the filesystem doesn't declare it.
65
+ */
66
+ | {
67
+ readonly kind: "vfs";
68
+ readonly name: string;
69
+ readonly persistent?: boolean;
70
+ };
71
+ /** How {@link Pgwasm.dumpDataDir} compresses: `auto` and `gzip` gzip the tarball, `none` does not. */
72
+ export type DumpCompression = "none" | "gzip" | "auto";
73
+ /** What a client extension's `setup` returns. */
74
+ export interface ExtensionSetupResult<TNamespace = unknown> {
75
+ /** Attached to the instance under the extension's key in `extensions`. */
76
+ readonly namespace?: TNamespace;
77
+ /** Run once the database is ready. */
78
+ readonly init?: () => Promise<void>;
79
+ /** Run when the database closes. */
80
+ readonly close?: () => Promise<void>;
81
+ }
82
+ /** A client extension: code that runs beside the database, such as `live`. */
83
+ export interface Extension<TNamespace = unknown> {
84
+ readonly name: string;
85
+ setup(pg: Pgwasm): Promise<ExtensionSetupResult<TNamespace>>;
86
+ }
87
+ /** The `extensions` option: client extensions and a build's server extensions, by key. */
88
+ export type Extensions = Readonly<Record<string, Extension | ServerExtension>>;
89
+ /**
90
+ * The namespaces client extensions attach, by their key in `extensions`. An extension that attaches
91
+ * none (its namespace type is `undefined` or `unknown`) adds no key: the database has no such member.
92
+ */
93
+ export type ExtensionNamespaces<E extends Extensions> = {
94
+ readonly [K in keyof E as E[K] extends Extension<infer N> ? unknown extends N ? never : [N] extends [undefined] ? never : K : never]: E[K] extends Extension<infer N> ? N : never;
95
+ };
96
+ export interface PgwasmOptions<E extends Extensions = Extensions> {
97
+ /** The Postgres build to run, e.g. `cBuild` from `@pgxsinkit/pgwasm-c`. */
98
+ readonly build: PostgresBuild;
99
+ /**
100
+ * Where the data directory lives: `memory://` (the default), `idb://<name>` (IndexedDB) or
101
+ * `file://<path>` (a directory, on Bun). A scheme is required. Exclusive with `fs`.
102
+ */
103
+ readonly dataDir?: string;
104
+ /** A filesystem to mount as the data directory instead of `dataDir`. */
105
+ readonly fs?: BaseFilesystem;
106
+ /** A Store backup (`dumpDataDir()` output) to create the data directory from. */
107
+ readonly loadDataDir?: Blob | File;
108
+ /**
109
+ * Client extensions (such as `live`) and the build's server extensions, by key. Typed as the
110
+ * inferred `E` intersected with {@link Extensions}: `E` carries each extension's namespace onto the
111
+ * database, and the intersection gives an extension written inline its `setup(pg: Pgwasm)` type.
112
+ */
113
+ readonly extensions?: E & Extensions;
114
+ /**
115
+ * Return from a statement before its storage persist completes. The persist runs in the
116
+ * background, and a failure is reported by the next statement.
117
+ */
118
+ readonly relaxedDurability?: boolean;
119
+ /** Run as this role (`SET ROLE`) once started. */
120
+ readonly username?: string;
121
+ /** The database to connect to. Defaults to `postgres`. */
122
+ readonly database?: string;
123
+ /** Server settings (GUCs), e.g. `{ application_name: "app" }`. */
124
+ readonly settings?: Readonly<Record<string, string>>;
125
+ readonly parsers?: ParserOptions;
126
+ readonly serializers?: SerializerOptions;
127
+ readonly debug?: DebugLevel;
128
+ }
129
+ /** A running database. */
130
+ export interface Pgwasm extends AsyncDisposable {
131
+ /** Settled once the database is ready; `createPgwasm` resolves only then. */
132
+ readonly waitReady: Promise<void>;
133
+ readonly ready: boolean;
134
+ readonly closed: boolean;
135
+ readonly debug: DebugLevel;
136
+ /** The build this database runs on. */
137
+ readonly build: BuildIdentity;
138
+ /** Where the data directory lives. */
139
+ readonly storage: StorageDescription;
140
+ /** One statement, through the extended protocol, with parameters. */
141
+ query<T = Row>(sql: string, params?: readonly unknown[], options?: QueryOptions): Promise<Results<T>>;
142
+ /** One statement from a template; interpolated values become parameters. */
143
+ sql<T = Row>(sqlStrings: TemplateStringsArray, ...params: unknown[]): Promise<Results<T>>;
144
+ /** Any number of statements, through the simple protocol, without parameters. */
145
+ exec(sql: string, options?: QueryOptions): Promise<Results[]>;
146
+ /** Run `callback` in a transaction: COMMIT when it resolves, ROLLBACK when it throws. */
147
+ transaction<T>(callback: (tx: Transaction) => Promise<T>): Promise<T>;
148
+ /** Run `fn` while no query or transaction runs. */
149
+ runExclusive<T>(fn: () => Promise<T>): Promise<T>;
150
+ /** LISTEN on a channel; resolves to the matching unlisten. */
151
+ listen(channel: string, callback: (payload: string) => void, tx?: Transaction): Promise<(tx?: Transaction) => Promise<void>>;
152
+ /** UNLISTEN one callback, or every callback when none is given. */
153
+ unlisten(channel: string, callback?: (payload: string) => void, tx?: Transaction): Promise<void>;
154
+ /** Every notification on every channel; returns the unsubscribe. */
155
+ onNotification(callback: (channel: string, payload: string) => void): () => void;
156
+ /** Re-read the array types, after creating a type whose arrays should parse. */
157
+ refreshArrayTypes(): Promise<void>;
158
+ /** A Store backup: the data directory as a tarball, restorable through `loadDataDir`. */
159
+ dumpDataDir(compression?: DumpCompression): Promise<File>;
160
+ close(): Promise<void>;
161
+ }
162
+ /** A database with its client extensions' namespaces attached. */
163
+ export type PgwasmWithExtensions<E extends Extensions> = Pgwasm & ExtensionNamespaces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,CAAC,EAAE,WAAW,GACf,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,EAAE,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjG,oEAAoE;IACpE,cAAc,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACjF,gFAAgF;IAChF,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,yFAAyF;IACzF,WAAW,CAAC,WAAW,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,kEAAkE;AAClE,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,UAAU,IAAI,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAEzF,YAAY,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Run at most one call at a time, and collapse waiting calls into the latest: a call made while one
3
+ * runs is scheduled after it, replacing (and resolving to `undefined`) any call already scheduled.
4
+ */
5
+ export declare function debounceMutex<A extends unknown[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R | undefined>;
6
+ //# sourceMappingURL=debounce-mutex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce-mutex.d.ts","sourceRoot":"","sources":["../../src/live/debounce-mutex.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAClD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC7B,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAmCxC"}
@@ -0,0 +1,8 @@
1
+ import type { Pgwasm, Transaction } from "../interface";
2
+ /**
3
+ * Inline a query's parameters as SQL literals (Postgres' own `format(%L)`), for statements that cannot
4
+ * take parameters (a `CREATE VIEW`). The tables the query references must exist, since the parameter
5
+ * types come from describing it. `tx` runs the final `format()` inside a transaction.
6
+ */
7
+ export declare function formatQuery(pg: Pgwasm, query: string, params?: readonly unknown[] | null, tx?: Transaction | Pgwasm): Promise<string>;
8
+ //# sourceMappingURL=format-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-query.d.ts","sourceRoot":"","sources":["../../src/live/format-query.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKxD;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI,EAClC,EAAE,CAAC,EAAE,WAAW,GAAG,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC,CA0BjB"}
@@ -0,0 +1,9 @@
1
+ import type { Extension } from "../interface";
2
+ import type { LiveNamespace } from "./interface";
3
+ export type { Change, ChangeDelete, ChangeInsert, ChangeReset, ChangeUpdate, LiveChanges, LiveChangesOptions, LiveIncrementalQueryOptions, LiveNamespace, LiveQuery, LiveQueryOptions, LiveQueryResults, PgwasmWithLive, } from "./interface";
4
+ /**
5
+ * Live queries: `live.query`, `live.changes` and `live.incrementalQuery`, re-run when a table they read
6
+ * changes (statement-level NOTIFY triggers, created once per table).
7
+ */
8
+ export declare const live: Extension<LiveNamespace>;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/live/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAqC,MAAM,cAAc,CAAC;AAGjF,OAAO,KAAK,EAKV,aAAa,EAId,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,2BAA2B,EAC3B,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,aAAa,CAAC;AA2pBrB;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,SAAS,CAAC,aAAa,CAGzC,CAAC"}