@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.
- package/LICENSE +21 -0
- package/LICENSE-APACHE-2.0 +202 -0
- package/NOTICE +111 -0
- package/README.md +56 -0
- package/dist/build/index.d.ts +8 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +21 -0
- package/dist/build/index.js.map +9 -0
- package/dist/build/seam.d.ts +174 -0
- package/dist/build/seam.d.ts.map +1 -0
- package/dist/chunk-0w227vw2.js +233 -0
- package/dist/chunk-0w227vw2.js.map +11 -0
- package/dist/chunk-74gcrk47.js +563 -0
- package/dist/chunk-74gcrk47.js.map +14 -0
- package/dist/chunk-at1py5s5.js +373 -0
- package/dist/chunk-at1py5s5.js.map +12 -0
- package/dist/chunk-cpsnmzrf.js +126 -0
- package/dist/chunk-cpsnmzrf.js.map +10 -0
- package/dist/chunk-d82gg1hx.js +306 -0
- package/dist/chunk-d82gg1hx.js.map +10 -0
- package/dist/chunk-gjf102c9.js +1005 -0
- package/dist/chunk-gjf102c9.js.map +16 -0
- package/dist/chunk-kb3rsr7n.js +19 -0
- package/dist/chunk-kb3rsr7n.js.map +9 -0
- package/dist/chunk-tdvrvgt5.js +83 -0
- package/dist/chunk-tdvrvgt5.js.map +11 -0
- package/dist/chunk-z0c40tja.js +50 -0
- package/dist/chunk-z0c40tja.js.map +10 -0
- package/dist/core/data-dir-archive.d.ts +17 -0
- package/dist/core/data-dir-archive.d.ts.map +1 -0
- package/dist/core/internals.d.ts +59 -0
- package/dist/core/internals.d.ts.map +1 -0
- package/dist/core/marker.d.ts +35 -0
- package/dist/core/marker.d.ts.map +1 -0
- package/dist/core/mutex.d.ts +9 -0
- package/dist/core/mutex.d.ts.map +1 -0
- package/dist/core/names.d.ts +11 -0
- package/dist/core/names.d.ts.map +1 -0
- package/dist/core/parse.d.ts +11 -0
- package/dist/core/parse.d.ts.map +1 -0
- package/dist/core/pgwasm.d.ts +53 -0
- package/dist/core/pgwasm.d.ts.map +1 -0
- package/dist/core/storage.d.ts +14 -0
- package/dist/core/storage.d.ts.map +1 -0
- package/dist/create.d.ts +10 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/drizzle/codecs.d.ts +9 -0
- package/dist/drizzle/codecs.d.ts.map +1 -0
- package/dist/drizzle/driver.d.ts +50 -0
- package/dist/drizzle/driver.d.ts.map +1 -0
- package/dist/drizzle/index.d.ts +4 -0
- package/dist/drizzle/index.d.ts.map +1 -0
- package/dist/drizzle/index.js +261 -0
- package/dist/drizzle/index.js.map +12 -0
- package/dist/drizzle/session.d.ts +39 -0
- package/dist/drizzle/session.d.ts.map +1 -0
- package/dist/errors.d.ts +115 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/fs/base-filesystem.d.ts +118 -0
- package/dist/fs/base-filesystem.d.ts.map +1 -0
- package/dist/fs/index.d.ts +2 -0
- package/dist/fs/index.d.ts.map +1 -0
- package/dist/fs/index.js +11 -0
- package/dist/fs/index.js.map +9 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +9 -0
- package/dist/interface.d.ts +165 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/live/debounce-mutex.d.ts +6 -0
- package/dist/live/debounce-mutex.d.ts.map +1 -0
- package/dist/live/format-query.d.ts +8 -0
- package/dist/live/format-query.d.ts.map +1 -0
- package/dist/live/index.d.ts +9 -0
- package/dist/live/index.d.ts.map +1 -0
- package/dist/live/index.js +601 -0
- package/dist/live/index.js.map +12 -0
- package/dist/live/interface.d.ts +86 -0
- package/dist/live/interface.d.ts.map +1 -0
- package/dist/opfs/broker/client.d.ts +163 -0
- package/dist/opfs/broker/client.d.ts.map +1 -0
- package/dist/opfs/broker/protocol.d.ts +326 -0
- package/dist/opfs/broker/protocol.d.ts.map +1 -0
- package/dist/opfs/broker/server.d.ts +84 -0
- package/dist/opfs/broker/server.d.ts.map +1 -0
- package/dist/opfs/core/checksum.d.ts +3 -0
- package/dist/opfs/core/checksum.d.ts.map +1 -0
- package/dist/opfs/core/codec.d.ts +73 -0
- package/dist/opfs/core/codec.d.ts.map +1 -0
- package/dist/opfs/core/errors.d.ts +80 -0
- package/dist/opfs/core/errors.d.ts.map +1 -0
- package/dist/opfs/core/limits.d.ts +35 -0
- package/dist/opfs/core/limits.d.ts.map +1 -0
- package/dist/opfs/core/memory-port.d.ts +51 -0
- package/dist/opfs/core/memory-port.d.ts.map +1 -0
- package/dist/opfs/core/metadata-store.d.ts +19 -0
- package/dist/opfs/core/metadata-store.d.ts.map +1 -0
- package/dist/opfs/core/mounted-vfs.d.ts +119 -0
- package/dist/opfs/core/mounted-vfs.d.ts.map +1 -0
- package/dist/opfs/core/path.d.ts +14 -0
- package/dist/opfs/core/path.d.ts.map +1 -0
- package/dist/opfs/core/port.d.ts +30 -0
- package/dist/opfs/core/port.d.ts.map +1 -0
- package/dist/opfs/core/repacked-vfs.d.ts +138 -0
- package/dist/opfs/core/repacked-vfs.d.ts.map +1 -0
- package/dist/opfs/core/state-machine.d.ts +296 -0
- package/dist/opfs/core/state-machine.d.ts.map +1 -0
- package/dist/opfs/create.d.ts +50 -0
- package/dist/opfs/create.d.ts.map +1 -0
- package/dist/opfs/file-port.d.ts +14 -0
- package/dist/opfs/file-port.d.ts.map +1 -0
- package/dist/opfs/index.d.ts +37 -0
- package/dist/opfs/index.d.ts.map +1 -0
- package/dist/opfs/index.js +6671 -0
- package/dist/opfs/index.js.map +28 -0
- package/dist/opfs/opfs-port.d.ts +34 -0
- package/dist/opfs/opfs-port.d.ts.map +1 -0
- package/dist/opfs/opfs-repacked-fs.d.ts +55 -0
- package/dist/opfs/opfs-repacked-fs.d.ts.map +1 -0
- package/dist/opfs/wasi/preview1.d.ts +228 -0
- package/dist/opfs/wasi/preview1.d.ts.map +1 -0
- package/dist/protocol/index.d.ts +15 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +23 -0
- package/dist/protocol/index.js.map +10 -0
- package/dist/protocol/wire/buffer-reader.d.ts +13 -0
- package/dist/protocol/wire/buffer-reader.d.ts.map +1 -0
- package/dist/protocol/wire/buffer-writer.d.ts +12 -0
- package/dist/protocol/wire/buffer-writer.d.ts.map +1 -0
- package/dist/protocol/wire/index.d.ts +5 -0
- package/dist/protocol/wire/index.d.ts.map +1 -0
- package/dist/protocol/wire/messages.d.ts +194 -0
- package/dist/protocol/wire/messages.d.ts.map +1 -0
- package/dist/protocol/wire/parser.d.ts +12 -0
- package/dist/protocol/wire/parser.d.ts.map +1 -0
- package/dist/protocol/wire/serializer.d.ts +61 -0
- package/dist/protocol/wire/serializer.d.ts.map +1 -0
- package/dist/protocol/wire/string-utils.d.ts +6 -0
- package/dist/protocol/wire/string-utils.d.ts.map +1 -0
- package/dist/protocol/wire/types.d.ts +7 -0
- package/dist/protocol/wire/types.d.ts.map +1 -0
- package/dist/tar/gzip.d.ts +7 -0
- package/dist/tar/gzip.d.ts.map +1 -0
- package/dist/tar/tar.d.ts +39 -0
- package/dist/tar/tar.d.ts.map +1 -0
- package/dist/templating.d.ts +42 -0
- package/dist/templating.d.ts.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +69 -0
- package/skills/opfs/SKILL.md +138 -0
- package/src/build/index.ts +23 -0
- package/src/build/seam.ts +179 -0
- package/src/core/data-dir-archive.ts +68 -0
- package/src/core/internals.ts +87 -0
- package/src/core/marker.ts +94 -0
- package/src/core/mutex.ts +16 -0
- package/src/core/names.ts +26 -0
- package/src/core/parse.ts +79 -0
- package/src/core/pgwasm.ts +876 -0
- package/src/core/storage.ts +70 -0
- package/src/create.ts +134 -0
- package/src/drizzle/codecs.ts +114 -0
- package/src/drizzle/driver.ts +141 -0
- package/src/drizzle/index.ts +15 -0
- package/src/drizzle/session.ts +133 -0
- package/src/errors.ts +201 -0
- package/src/fs/base-filesystem.ts +149 -0
- package/src/fs/index.ts +7 -0
- package/src/index.ts +44 -0
- package/src/interface.ts +186 -0
- package/src/live/debounce-mutex.ts +45 -0
- package/src/live/format-query.ts +47 -0
- package/src/live/index.ts +707 -0
- package/src/live/interface.ts +109 -0
- package/src/opfs/broker/client.ts +482 -0
- package/src/opfs/broker/protocol.ts +624 -0
- package/src/opfs/broker/server.ts +522 -0
- package/src/opfs/core/checksum.ts +85 -0
- package/src/opfs/core/codec.ts +1051 -0
- package/src/opfs/core/errors.ts +134 -0
- package/src/opfs/core/limits.ts +68 -0
- package/src/opfs/core/memory-port.ts +459 -0
- package/src/opfs/core/metadata-store.ts +512 -0
- package/src/opfs/core/mounted-vfs.ts +407 -0
- package/src/opfs/core/path.ts +82 -0
- package/src/opfs/core/port.ts +114 -0
- package/src/opfs/core/repacked-vfs.ts +1464 -0
- package/src/opfs/core/state-machine.ts +1699 -0
- package/src/opfs/create.ts +125 -0
- package/src/opfs/file-port.ts +183 -0
- package/src/opfs/index.ts +113 -0
- package/src/opfs/opfs-port.ts +90 -0
- package/src/opfs/opfs-repacked-fs.ts +210 -0
- package/src/opfs/wasi/preview1.ts +1016 -0
- package/src/protocol/index.ts +24 -0
- package/src/protocol/wire/buffer-reader.ts +60 -0
- package/src/protocol/wire/buffer-writer.ts +93 -0
- package/src/protocol/wire/index.ts +15 -0
- package/src/protocol/wire/messages.ts +332 -0
- package/src/protocol/wire/parser.ts +373 -0
- package/src/protocol/wire/serializer.ts +233 -0
- package/src/protocol/wire/string-utils.ts +18 -0
- package/src/protocol/wire/types.ts +12 -0
- package/src/tar/gzip.ts +36 -0
- package/src/tar/tar.ts +253 -0
- package/src/templating.ts +103 -0
- package/src/types.ts +283 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { BaseFilesystem } from "../fs/base-filesystem";
|
|
2
|
+
import type { FilesystemDescription, FsStats } from "../fs/base-filesystem";
|
|
3
|
+
import { DurabilityModeMismatchError, StoreLimitError } from "./core/errors";
|
|
4
|
+
import type { RepackedPort } from "./core/port";
|
|
5
|
+
import { RepackedVfs } from "./core/repacked-vfs";
|
|
6
|
+
import type { RepackedStat } from "./core/repacked-vfs";
|
|
7
|
+
|
|
8
|
+
/** Physical durability selected once for the lifetime of a store `createOpfsPgwasm` opens. */
|
|
9
|
+
export type RepackedDurability = "relaxed" | "strict";
|
|
10
|
+
|
|
11
|
+
export interface RepackedFilesystemOptions {
|
|
12
|
+
/** Creation extent size: 8 KiB–16 MiB in 8 KiB steps. Defaults to 64 KiB. */
|
|
13
|
+
readonly extentSize?: number;
|
|
14
|
+
/** Physical durability for this instance. Defaults to `"relaxed"`. */
|
|
15
|
+
readonly durability?: RepackedDurability;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const DESCRIPTION: FilesystemDescription = Object.freeze({ name: "opfs-repacked", persistent: true });
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The pgwasm filesystem adapter owned by `createOpfsPgwasm`.
|
|
22
|
+
*
|
|
23
|
+
* Direct construction is unsupported. The factory retains this adapter so it
|
|
24
|
+
* can close all four handles when host initialization or shutdown fails.
|
|
25
|
+
*/
|
|
26
|
+
export abstract class OpfsRepackedFS extends BaseFilesystem {
|
|
27
|
+
readonly #vfs: RepackedVfs;
|
|
28
|
+
readonly #durability: RepackedDurability;
|
|
29
|
+
|
|
30
|
+
protected constructor(vfs: RepackedVfs, durability: RepackedDurability) {
|
|
31
|
+
super();
|
|
32
|
+
this.#vfs = vfs;
|
|
33
|
+
this.#durability = durability;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** An OPFS-repacked store: its data directory outlives the page. */
|
|
37
|
+
override get description(): FilesystemDescription {
|
|
38
|
+
return DESCRIPTION;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override async initialSyncFs(): Promise<void> {
|
|
42
|
+
this.#vfs.assertHealthy();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override async syncToFs(relaxedDurability = false): Promise<void> {
|
|
46
|
+
this.#vfs.assertHealthy();
|
|
47
|
+
if (relaxedDurability) this.#vfs.fail(new DurabilityModeMismatchError());
|
|
48
|
+
this.#vfs.runScheduledRepack();
|
|
49
|
+
if (this.#durability === "strict") this.#vfs.strictSync();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Stabilize every preceding data and metadata operation in strict order. */
|
|
53
|
+
strictSync(): void {
|
|
54
|
+
this.#vfs.strictSync();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @internal Factory lifecycle cleanup after host initialization fails. */
|
|
58
|
+
override async cleanupFailedInit(): Promise<void> {
|
|
59
|
+
this.#vfs.cleanupFailedInit();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
override async closeFs(): Promise<void> {
|
|
63
|
+
this.#vfs.close();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
chmod(path: string, mode: number): void {
|
|
67
|
+
this.#vfs.chmod(hostPath(path), mode, nowMs());
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
close(fd: number): void {
|
|
71
|
+
this.#vfs.close(fd);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
fstat(fd: number): FsStats {
|
|
75
|
+
return toFsStats(this.#vfs.fstat(fd));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
lstat(path: string): FsStats {
|
|
79
|
+
return toFsStats(this.#vfs.lstat(hostPath(path)));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
mkdir(path: string, options?: { recursive?: boolean; mode?: number }): void {
|
|
83
|
+
this.#vfs.mkdir(hostPath(path), {
|
|
84
|
+
...(options?.recursive === undefined ? {} : { recursive: options.recursive }),
|
|
85
|
+
...(options?.mode === undefined ? {} : { mode: options.mode }),
|
|
86
|
+
nowMs: nowMs(),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
open(path: string, flags = "r+", mode = 0o100666): number {
|
|
91
|
+
return this.#vfs.open(hostPath(path), flags, mode, nowMs());
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
readdir(path: string): string[] {
|
|
95
|
+
return this.#vfs.readdir(hostPath(path));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
read(fd: number, buffer: Uint8Array, offset: number, length: number, position: number): number {
|
|
99
|
+
return this.#vfs.read(fd, buffer, offset, length, toFileOffset(position));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
rename(oldPath: string, newPath: string): void {
|
|
103
|
+
this.#vfs.rename(hostPath(oldPath), hostPath(newPath), nowMs());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
rmdir(path: string): void {
|
|
107
|
+
this.#vfs.rmdir(hostPath(path), nowMs());
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
truncate(path: string, length: number): void {
|
|
111
|
+
this.#vfs.truncate(hostPath(path), toFileOffset(length), nowMs());
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
unlink(path: string): void {
|
|
115
|
+
this.#vfs.unlink(hostPath(path), nowMs());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
utimes(path: string, atime: number, mtime: number): void {
|
|
119
|
+
this.#vfs.utimes(hostPath(path), toTimestamp(atime), toTimestamp(mtime), nowMs());
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
writeFile(
|
|
123
|
+
path: string,
|
|
124
|
+
data: string | Uint8Array,
|
|
125
|
+
options?: { encoding?: string; mode?: number; flag?: string },
|
|
126
|
+
): void {
|
|
127
|
+
this.#vfs.writeFile(hostPath(path), data, {
|
|
128
|
+
...(options?.encoding === undefined ? {} : { encoding: options.encoding }),
|
|
129
|
+
...(options?.mode === undefined ? {} : { mode: options.mode }),
|
|
130
|
+
...(options?.flag === undefined ? {} : { flag: options.flag }),
|
|
131
|
+
nowMs: nowMs(),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
write(fd: number, buffer: Uint8Array, offset: number, length: number, position: number): number {
|
|
136
|
+
if (buffer instanceof Uint8Array) {
|
|
137
|
+
return this.#vfs.write(fd, buffer, offset, length, toFileOffset(position), nowMs());
|
|
138
|
+
}
|
|
139
|
+
const source = new Uint8Array(buffer as unknown as ArrayBuffer, offset, length);
|
|
140
|
+
return this.#vfs.write(fd, source, 0, source.byteLength, toFileOffset(position), nowMs());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
class ConcreteOpfsRepackedFS extends OpfsRepackedFS {
|
|
145
|
+
constructor(vfs: RepackedVfs, durability: RepackedDurability) {
|
|
146
|
+
super(vfs, durability);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function openOpfsRepackedFsForPort(
|
|
151
|
+
port: RepackedPort,
|
|
152
|
+
options: RepackedFilesystemOptions = {},
|
|
153
|
+
): Promise<OpfsRepackedFS> {
|
|
154
|
+
const durability = options.durability ?? "relaxed";
|
|
155
|
+
if (durability !== "relaxed" && durability !== "strict") {
|
|
156
|
+
throw new TypeError(`unsupported OPFS repacked durability: ${String(durability)}`);
|
|
157
|
+
}
|
|
158
|
+
const vfs = await RepackedVfs.open(port, {
|
|
159
|
+
...(options.extentSize === undefined ? {} : { extentSize: options.extentSize }),
|
|
160
|
+
});
|
|
161
|
+
return new ConcreteOpfsRepackedFS(vfs, durability);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function nowMs(): bigint {
|
|
165
|
+
return BigInt(Date.now());
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function hostPath(path: string): string {
|
|
169
|
+
return path === "" ? "/" : path;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function toFileOffset(value: number): bigint {
|
|
173
|
+
if (!Number.isSafeInteger(value) || value < 0) throw new TypeError("file offset is not a non-negative safe integer");
|
|
174
|
+
return BigInt(value);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function toTimestamp(value: number): bigint {
|
|
178
|
+
// Emscripten's utime path can pass fractional milliseconds (µs-precision
|
|
179
|
+
// utimensat converted to ms); floor instead of rejecting the syscall.
|
|
180
|
+
const floored = Math.floor(value);
|
|
181
|
+
if (!Number.isSafeInteger(floored) || floored < 0) {
|
|
182
|
+
throw new TypeError("timestamp is not a non-negative finite millisecond value");
|
|
183
|
+
}
|
|
184
|
+
return BigInt(floored);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function toFsStats(stat: RepackedStat): FsStats {
|
|
188
|
+
const size = toSafeNumber(stat.size, "file size");
|
|
189
|
+
const blksize = 4096;
|
|
190
|
+
return {
|
|
191
|
+
dev: 0,
|
|
192
|
+
ino: 0,
|
|
193
|
+
mode: stat.mode,
|
|
194
|
+
nlink: 1,
|
|
195
|
+
uid: 0,
|
|
196
|
+
gid: 0,
|
|
197
|
+
rdev: 0,
|
|
198
|
+
size,
|
|
199
|
+
blksize,
|
|
200
|
+
blocks: Math.ceil(size / blksize),
|
|
201
|
+
atime: toSafeNumber(stat.atimeMs, "access time"),
|
|
202
|
+
mtime: toSafeNumber(stat.mtimeMs, "modification time"),
|
|
203
|
+
ctime: toSafeNumber(stat.ctimeMs, "change time"),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function toSafeNumber(value: bigint, label: string): number {
|
|
208
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) throw new StoreLimitError(`${label} exceeds safe integer range`);
|
|
209
|
+
return Number(value);
|
|
210
|
+
}
|