@brett_lamy/ui 4.0.0 → 5.0.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/README.md +1 -1
- package/dist/components/animated-height.d.ts +3 -1
- package/dist/components/animated-height.d.ts.map +1 -1
- package/dist/components/animated-height.js +11 -11
- package/dist/components/artifact-chat-container.d.ts.map +1 -1
- package/dist/components/artifact-chat-container.js +81 -82
- package/dist/components/button.d.ts +4 -3
- package/dist/components/button.d.ts.map +1 -1
- package/dist/components/button.js +22 -9
- package/dist/components/canvas.d.ts +91 -0
- package/dist/components/canvas.d.ts.map +1 -0
- package/dist/components/canvas.js +296 -0
- package/dist/components/composer/composer-cards.d.ts +55 -0
- package/dist/components/composer/composer-cards.d.ts.map +1 -0
- package/dist/components/composer/composer-cards.js +351 -0
- package/dist/components/composer/composer.d.ts +9 -1
- package/dist/components/composer/composer.d.ts.map +1 -1
- package/dist/components/composer/composer.js +179 -154
- package/dist/components/context-menu.d.ts +25 -0
- package/dist/components/context-menu.d.ts.map +1 -0
- package/dist/components/context-menu.js +127 -0
- package/dist/components/credenza.d.ts.map +1 -1
- package/dist/components/credenza.js +52 -92
- package/dist/components/cron-editor.d.ts +47 -0
- package/dist/components/cron-editor.d.ts.map +1 -0
- package/dist/components/cron-editor.js +297 -0
- package/dist/components/dropdown-menu.d.ts +3 -1
- package/dist/components/dropdown-menu.d.ts.map +1 -1
- package/dist/components/dropdown-menu.js +5 -5
- package/dist/components/edge-drawer.d.ts.map +1 -1
- package/dist/components/edge-drawer.js +1 -0
- package/dist/components/file-upload.d.ts +121 -0
- package/dist/components/file-upload.d.ts.map +1 -0
- package/dist/components/file-upload.js +405 -0
- package/dist/components/filter-input.d.ts +22 -0
- package/dist/components/filter-input.d.ts.map +1 -0
- package/dist/components/filter-input.js +126 -0
- package/dist/components/filter.d.ts +154 -0
- package/dist/components/filter.d.ts.map +1 -0
- package/dist/components/filter.js +815 -0
- package/dist/components/floating-chat.d.ts.map +1 -1
- package/dist/components/floating-chat.js +71 -88
- package/dist/components/floating-sheet.d.ts.map +1 -1
- package/dist/components/floating-sheet.js +93 -104
- package/dist/components/markdown-editor.d.ts +2 -0
- package/dist/components/markdown-editor.d.ts.map +1 -1
- package/dist/components/markdown-editor.js +46 -45
- package/dist/components/markdown-view.d.ts +6 -1
- package/dist/components/markdown-view.d.ts.map +1 -1
- package/dist/components/markdown-view.js +13 -11
- package/dist/components/navigation-stack.d.ts +3 -5
- package/dist/components/navigation-stack.d.ts.map +1 -1
- package/dist/components/navigation-stack.js +212 -382
- package/dist/components/passkey-enroll-dialog.d.ts +36 -0
- package/dist/components/passkey-enroll-dialog.d.ts.map +1 -0
- package/dist/components/passkey-enroll-dialog.js +234 -0
- package/dist/components/result-table.d.ts +38 -0
- package/dist/components/result-table.d.ts.map +1 -0
- package/dist/components/result-table.js +161 -0
- package/dist/components/schema-tree.d.ts +19 -0
- package/dist/components/schema-tree.d.ts.map +1 -0
- package/dist/components/schema-tree.js +172 -0
- package/dist/components/side-drawer.d.ts.map +1 -1
- package/dist/components/side-drawer.js +117 -143
- package/dist/components/slider.d.ts.map +1 -1
- package/dist/components/slider.js +4 -1
- package/dist/components/spinner-shapes.d.ts +263 -0
- package/dist/components/spinner-shapes.d.ts.map +1 -0
- package/dist/components/spinner-shapes.js +771 -0
- package/dist/components/spinner.d.ts +133 -3
- package/dist/components/spinner.d.ts.map +1 -1
- package/dist/components/spinner.js +445 -29
- package/dist/components/sql-console.d.ts +28 -0
- package/dist/components/sql-console.d.ts.map +1 -0
- package/dist/components/sql-console.js +348 -0
- package/dist/components/sql-editor.d.ts +47 -0
- package/dist/components/sql-editor.d.ts.map +1 -0
- package/dist/components/sql-editor.js +170 -0
- package/dist/components/tab-view.d.ts +2 -2
- package/dist/components/tab-view.d.ts.map +1 -1
- package/dist/components/tab-view.js +63 -49
- package/dist/components/tailscale-login-button.d.ts +53 -0
- package/dist/components/tailscale-login-button.d.ts.map +1 -0
- package/dist/components/tailscale-login-button.js +197 -0
- package/dist/components/time-input.d.ts +46 -0
- package/dist/components/time-input.d.ts.map +1 -0
- package/dist/components/time-input.js +258 -0
- package/dist/components/toast.d.ts +5 -2
- package/dist/components/toast.d.ts.map +1 -1
- package/dist/components/toast.js +249 -125
- package/dist/components/vault-gate.d.ts +60 -0
- package/dist/components/vault-gate.d.ts.map +1 -0
- package/dist/components/vault-gate.js +382 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +85 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +129 -83
- package/dist/lib/back-history.d.ts +5 -0
- package/dist/lib/back-history.d.ts.map +1 -0
- package/dist/lib/back-history.js +44 -0
- package/dist/lib/canvas-math.d.ts +82 -0
- package/dist/lib/canvas-math.d.ts.map +1 -0
- package/dist/lib/canvas-math.js +226 -0
- package/dist/lib/controllable-state.d.ts +4 -0
- package/dist/lib/controllable-state.d.ts.map +1 -0
- package/dist/lib/controllable-state.js +11 -0
- package/dist/lib/cron.d.ts +55 -0
- package/dist/lib/cron.d.ts.map +1 -0
- package/dist/lib/cron.js +269 -0
- package/dist/lib/edge-swipe.d.ts +36 -0
- package/dist/lib/edge-swipe.d.ts.map +1 -0
- package/dist/lib/edge-swipe.js +73 -0
- package/dist/lib/file-upload.d.ts +187 -0
- package/dist/lib/file-upload.d.ts.map +1 -0
- package/dist/lib/file-upload.js +349 -0
- package/dist/lib/filter-query.d.ts +90 -0
- package/dist/lib/filter-query.d.ts.map +1 -0
- package/dist/lib/filter-query.js +459 -0
- package/dist/lib/filter.d.ts +120 -0
- package/dist/lib/filter.d.ts.map +1 -0
- package/dist/lib/filter.js +399 -0
- package/dist/lib/format-bytes.d.ts +3 -0
- package/dist/lib/format-bytes.d.ts.map +1 -0
- package/dist/lib/format-bytes.js +16 -0
- package/dist/lib/gpu-cron.d.ts +51 -0
- package/dist/lib/gpu-cron.d.ts.map +1 -0
- package/dist/lib/gpu-cron.js +81 -0
- package/dist/lib/gpu-query/featurize.d.ts +19 -0
- package/dist/lib/gpu-query/featurize.d.ts.map +1 -0
- package/dist/lib/gpu-query/featurize.js +88 -0
- package/dist/lib/gpu-query/index.d.ts +73 -0
- package/dist/lib/gpu-query/index.d.ts.map +1 -0
- package/dist/lib/gpu-query/index.js +117 -0
- package/dist/lib/gpu-query/kernel.wgsl.d.ts +30 -0
- package/dist/lib/gpu-query/kernel.wgsl.d.ts.map +1 -0
- package/dist/lib/gpu-query/model.d.ts +8 -0
- package/dist/lib/gpu-query/model.d.ts.map +1 -0
- package/dist/lib/gpu-query/model.js +91 -0
- package/dist/lib/gpu-query/schema.d.ts +40 -0
- package/dist/lib/gpu-query/schema.d.ts.map +1 -0
- package/dist/lib/gpu-query/schema.js +0 -0
- package/dist/lib/gpu-query/webgpu.d.ts +12 -0
- package/dist/lib/gpu-query/webgpu.d.ts.map +1 -0
- package/dist/lib/gpu-query/weights.d.ts +17 -0
- package/dist/lib/gpu-query/weights.d.ts.map +1 -0
- package/dist/lib/gpu-query/weights.js +40 -0
- package/dist/lib/gpu-query/weights.json.d.ts +3 -0
- package/dist/lib/gpu-query/weights2.js +25 -0
- package/dist/lib/gpu-time.d.ts +77 -0
- package/dist/lib/gpu-time.d.ts.map +1 -0
- package/dist/lib/gpu-time.js +260 -0
- package/dist/lib/morph-path.d.ts +22 -0
- package/dist/lib/morph-path.d.ts.map +1 -0
- package/dist/lib/morph-path.js +42 -0
- package/dist/lib/passkey.d.ts +120 -0
- package/dist/lib/passkey.d.ts.map +1 -0
- package/dist/lib/passkey.js +186 -0
- package/dist/lib/persistent-state.d.ts +9 -0
- package/dist/lib/persistent-state.d.ts.map +1 -0
- package/dist/lib/persistent-state.js +37 -0
- package/dist/lib/pglite-core.d.ts +219 -0
- package/dist/lib/pglite-core.d.ts.map +1 -0
- package/dist/lib/pglite-core.js +273 -0
- package/dist/lib/pglite-files.d.ts +7 -0
- package/dist/lib/pglite-files.d.ts.map +1 -0
- package/dist/lib/pglite-files.js +17 -0
- package/dist/lib/pglite-schema.d.ts +58 -0
- package/dist/lib/pglite-schema.d.ts.map +1 -0
- package/dist/lib/pglite-schema.js +105 -0
- package/dist/lib/pglite-storage.d.ts +33 -0
- package/dist/lib/pglite-storage.d.ts.map +1 -0
- package/dist/lib/pglite-storage.js +55 -0
- package/dist/lib/pglite-transfer.d.ts +53 -0
- package/dist/lib/pglite-transfer.d.ts.map +1 -0
- package/dist/lib/pglite-transfer.js +126 -0
- package/dist/lib/pglite.d.ts +106 -0
- package/dist/lib/pglite.d.ts.map +1 -0
- package/dist/lib/pglite.js +298 -0
- package/dist/lib/pull-to-refresh.d.ts +24 -0
- package/dist/lib/pull-to-refresh.d.ts.map +1 -0
- package/dist/lib/pull-to-refresh.js +74 -0
- package/dist/lib/scroll-hidden.d.ts +6 -0
- package/dist/lib/scroll-hidden.d.ts.map +1 -0
- package/dist/lib/scroll-hidden.js +21 -0
- package/dist/lib/sql-format.d.ts +62 -0
- package/dist/lib/sql-format.d.ts.map +1 -0
- package/dist/lib/sql-format.js +175 -0
- package/dist/lib/sql-lex.d.ts +25 -0
- package/dist/lib/sql-lex.d.ts.map +1 -0
- package/dist/lib/sql-lex.js +135 -0
- package/dist/lib/tab-lock.d.ts +28 -0
- package/dist/lib/tab-lock.d.ts.map +1 -0
- package/dist/lib/tab-lock.js +80 -0
- package/dist/lib/tailscale-connect.d.ts +56 -0
- package/dist/lib/tailscale-connect.d.ts.map +1 -0
- package/dist/lib/tailscale-connect.js +99 -0
- package/dist/lib/tailscale-fake.d.ts +33 -0
- package/dist/lib/tailscale-fake.d.ts.map +1 -0
- package/dist/lib/tailscale-fake.js +80 -0
- package/dist/lib/tailscale-policy.d.ts +71 -0
- package/dist/lib/tailscale-policy.d.ts.map +1 -0
- package/dist/lib/tailscale-policy.js +244 -0
- package/dist/lib/tailscale-react.d.ts +20 -0
- package/dist/lib/tailscale-react.d.ts.map +1 -0
- package/dist/lib/tailscale-react.js +37 -0
- package/dist/lib/tailscale-router/bridge.d.ts +60 -0
- package/dist/lib/tailscale-router/bridge.d.ts.map +1 -0
- package/dist/lib/tailscale-router/bridge.js +198 -0
- package/dist/lib/tailscale-router/react.d.ts +19 -0
- package/dist/lib/tailscale-router/react.d.ts.map +1 -0
- package/dist/lib/tailscale-router/react.js +52 -0
- package/dist/lib/tailscale.d.ts +204 -0
- package/dist/lib/tailscale.d.ts.map +1 -0
- package/dist/lib/tailscale.js +443 -0
- package/dist/lib/title-flight.d.ts +34 -0
- package/dist/lib/title-flight.d.ts.map +1 -0
- package/dist/lib/title-flight.js +123 -0
- package/dist/lib/vault-react.d.ts +49 -0
- package/dist/lib/vault-react.d.ts.map +1 -0
- package/dist/lib/vault-react.js +196 -0
- package/dist/lib/vault-storage.d.ts +30 -0
- package/dist/lib/vault-storage.d.ts.map +1 -0
- package/dist/lib/vault-storage.js +105 -0
- package/dist/lib/vault.d.ts +200 -0
- package/dist/lib/vault.d.ts.map +1 -0
- package/dist/lib/vault.js +641 -0
- package/dist/tailscale-sw.js +332 -0
- package/package.json +35 -5
- package/dist/components/icon-button.d.ts +0 -19
- package/dist/components/icon-button.d.ts.map +0 -1
- package/dist/components/icon-button.js +0 -31
- package/dist/components/measure-h.d.ts +0 -7
- package/dist/components/measure-h.d.ts.map +0 -1
- package/dist/components/measure-h.js +0 -20
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { positionToLineColumn as e, splitStatements as t } from "./sql-lex.js";
|
|
2
|
+
//#region src/lib/pglite-core.ts
|
|
3
|
+
var n = class extends Error {
|
|
4
|
+
code;
|
|
5
|
+
constructor(e, t, n) {
|
|
6
|
+
super(t, n), this.name = "PGliteError", this.code = e;
|
|
7
|
+
}
|
|
8
|
+
}, r = class extends n {
|
|
9
|
+
found;
|
|
10
|
+
expected;
|
|
11
|
+
dataDir;
|
|
12
|
+
constructor(e, t, n, r) {
|
|
13
|
+
super("VERSION_MISMATCH", `"${e}" was created by Postgres ${t}, but this build of PGlite runs Postgres ${n ?? "a different major version"}. The data was left untouched. Open it with the PGlite release that created it and export a SQL dump, then import that dump into a new database. Pin the @electric-sql/pglite version so upgrades are deliberate.`, r), this.name = "DataDirVersionError", this.found = t, this.expected = n, this.dataDir = e;
|
|
14
|
+
}
|
|
15
|
+
}, i = class extends Error {
|
|
16
|
+
kind;
|
|
17
|
+
migration;
|
|
18
|
+
constructor(e, t, n) {
|
|
19
|
+
super(t, n?.cause === void 0 ? void 0 : { cause: n.cause }), this.name = "MigrationError", this.kind = e, this.migration = n?.migration;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function a(t, n) {
|
|
23
|
+
let r = t ?? {}, i = { message: typeof t == "string" ? t : typeof r.message == "string" ? r.message : "Unknown error" };
|
|
24
|
+
typeof r.code == "string" && (i.code = r.code), typeof r.severity == "string" && (i.severity = r.severity), typeof r.detail == "string" && (i.detail = r.detail), typeof r.hint == "string" && (i.hint = r.hint);
|
|
25
|
+
let a = typeof r.position == "string" || typeof r.position == "number" ? Number(r.position) : NaN;
|
|
26
|
+
return Number.isFinite(a) && a > 0 && (i.position = a, n !== void 0 && Object.assign(i, e(n, a))), i;
|
|
27
|
+
}
|
|
28
|
+
function o(e) {
|
|
29
|
+
return `"${e.replace(/"/g, "\"\"")}"`;
|
|
30
|
+
}
|
|
31
|
+
var s = new Set("all analyse analyze and any array as asc asymmetric both case cast check collate column constraint create current_catalog current_date current_role current_time current_timestamp current_user default deferrable desc distinct do else end except false fetch for foreign from grant group having in initially intersect into lateral leading limit localtime localtimestamp not null offset on only or order placing primary references returning select session_user some symmetric table then to trailing true union unique user using variadic when where window with".split(" "));
|
|
32
|
+
function c(e) {
|
|
33
|
+
return /^[a-z_][a-z0-9_$]*$/.test(e) && !s.has(e) ? e : o(e);
|
|
34
|
+
}
|
|
35
|
+
function l(e) {
|
|
36
|
+
return `'${e.replace(/'/g, "''")}'`;
|
|
37
|
+
}
|
|
38
|
+
function u(e) {
|
|
39
|
+
let t = e?.trim() || "memory://";
|
|
40
|
+
return t.startsWith("memory://") ? {
|
|
41
|
+
kind: "memory",
|
|
42
|
+
name: "",
|
|
43
|
+
dataDir: "memory://"
|
|
44
|
+
} : t.startsWith("idb://") ? {
|
|
45
|
+
kind: "idb",
|
|
46
|
+
name: t.slice(6),
|
|
47
|
+
dataDir: t
|
|
48
|
+
} : t.startsWith("opfs-ahp://") ? {
|
|
49
|
+
kind: "opfs-ahp",
|
|
50
|
+
name: t.slice(11),
|
|
51
|
+
dataDir: t
|
|
52
|
+
} : t.startsWith("file://") ? {
|
|
53
|
+
kind: "nodefs",
|
|
54
|
+
name: t.slice(7),
|
|
55
|
+
dataDir: t
|
|
56
|
+
} : {
|
|
57
|
+
kind: "nodefs",
|
|
58
|
+
name: t,
|
|
59
|
+
dataDir: t
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var d = (e) => `/pglite/${e}`;
|
|
63
|
+
function f() {
|
|
64
|
+
if (typeof indexedDB > "u") throw new n("UNSUPPORTED", "IndexedDB is not available here; use dataDir \"memory://\".");
|
|
65
|
+
return indexedDB;
|
|
66
|
+
}
|
|
67
|
+
async function p(e) {
|
|
68
|
+
let t = u(e);
|
|
69
|
+
if (t.kind !== "idb" || typeof indexedDB > "u") return null;
|
|
70
|
+
let n = d(t.name), r = typeof indexedDB.databases == "function" ? await indexedDB.databases() : void 0;
|
|
71
|
+
return r && !r.some((e) => e.name === n) ? null : new Promise((e) => {
|
|
72
|
+
let t = indexedDB.open(n);
|
|
73
|
+
t.onerror = () => e(null), t.onblocked = () => e(null), t.onupgradeneeded = () => {
|
|
74
|
+
t.transaction?.abort();
|
|
75
|
+
}, t.onsuccess = () => {
|
|
76
|
+
let r = t.result;
|
|
77
|
+
try {
|
|
78
|
+
if (!r.objectStoreNames.contains("FILE_DATA")) return e(null);
|
|
79
|
+
let t = r.transaction(["FILE_DATA"], "readonly").objectStore("FILE_DATA").get(`${n}/PG_VERSION`);
|
|
80
|
+
t.onerror = () => e(null), t.onsuccess = () => {
|
|
81
|
+
let n = t.result?.contents;
|
|
82
|
+
e(n && new TextDecoder().decode(n).trim() || null);
|
|
83
|
+
};
|
|
84
|
+
} catch {
|
|
85
|
+
e(null);
|
|
86
|
+
} finally {
|
|
87
|
+
r.close();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async function m(e, { timeoutMs: t = 5e3 } = {}) {
|
|
93
|
+
let r = u(e);
|
|
94
|
+
if (r.kind === "opfs-ahp") {
|
|
95
|
+
await (await navigator.storage.getDirectory()).removeEntry(r.name, { recursive: !0 }).catch((e) => {
|
|
96
|
+
if (e?.name !== "NotFoundError") throw e;
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (r.kind !== "idb") return;
|
|
101
|
+
let i = f(), a = Date.now();
|
|
102
|
+
for (;;) {
|
|
103
|
+
if (await new Promise((e, t) => {
|
|
104
|
+
let n = i.deleteDatabase(d(r.name));
|
|
105
|
+
n.onsuccess = () => e(!0), n.onerror = () => t(n.error ?? /* @__PURE__ */ Error("Could not delete the database")), n.onblocked = () => e(!1);
|
|
106
|
+
})) return;
|
|
107
|
+
if (Date.now() - a > t) throw new n("LOCKED", `"${e}" is still open in another tab or worker, so it could not be deleted.`);
|
|
108
|
+
await new Promise((e) => setTimeout(e, 100));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function h(e) {
|
|
112
|
+
let t = await fetch(e);
|
|
113
|
+
if (!t.ok) throw new n("OPEN_FAILED", `Could not fetch ${String(e)} (${t.status}).`);
|
|
114
|
+
try {
|
|
115
|
+
return await WebAssembly.compileStreaming(t.clone());
|
|
116
|
+
} catch {
|
|
117
|
+
return WebAssembly.compile(await t.arrayBuffer());
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function g(e) {
|
|
121
|
+
if (!e) return {};
|
|
122
|
+
let [t, r, i] = await Promise.all([
|
|
123
|
+
e.wasm ? h(e.wasm) : void 0,
|
|
124
|
+
e.initdbWasm ? h(e.initdbWasm) : void 0,
|
|
125
|
+
e.data ? fetch(e.data).then((t) => t.ok ? t.blob() : Promise.reject(new n("OPEN_FAILED", `Could not fetch ${String(e.data)} (${t.status}).`))) : void 0
|
|
126
|
+
]);
|
|
127
|
+
return {
|
|
128
|
+
pgliteWasmModule: t,
|
|
129
|
+
initdbWasmModule: r,
|
|
130
|
+
fsBundle: i
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async function _(e) {
|
|
134
|
+
let { rows: t } = await e.query("select current_setting('server_version') as v, version() as full"), n = t[0]?.v ?? "";
|
|
135
|
+
return {
|
|
136
|
+
serverVersion: n,
|
|
137
|
+
serverMajor: parseInt(n, 10) || 0,
|
|
138
|
+
pgliteVersion: /PGlite ([\w.-]+)/.exec(t[0]?.full ?? "")?.[1]
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
var v;
|
|
142
|
+
function y() {
|
|
143
|
+
return v ??= (async () => {
|
|
144
|
+
let { PGlite: e } = await import("@electric-sql/pglite"), t = await e.create();
|
|
145
|
+
try {
|
|
146
|
+
return String((await _(t)).serverMajor);
|
|
147
|
+
} finally {
|
|
148
|
+
await t.close();
|
|
149
|
+
}
|
|
150
|
+
})().catch((e) => {
|
|
151
|
+
throw v = void 0, e;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async function b(e = {}) {
|
|
155
|
+
let t = u(e.dataDir), o = await p(t.dataDir) ?? void 0;
|
|
156
|
+
if (e.loadDataDir && o) throw new n("DATABASE_EXISTS", `"${t.dataDir}" already exists, and a data-directory archive can only be loaded into a new database. Choose another name, or delete it first (this destroys its data).`);
|
|
157
|
+
let s, c;
|
|
158
|
+
try {
|
|
159
|
+
let n = await import("@electric-sql/pglite"), i = { ...e.extensions };
|
|
160
|
+
if (e.live !== !1 && (i.live = (await import("@electric-sql/pglite/live")).live), e.worker) {
|
|
161
|
+
let { PGliteWorker: n } = await import("@electric-sql/pglite/worker");
|
|
162
|
+
s = e.worker(), c = await n.create(s, {
|
|
163
|
+
dataDir: t.dataDir,
|
|
164
|
+
extensions: i,
|
|
165
|
+
id: e.workerId,
|
|
166
|
+
relaxedDurability: e.relaxedDurability,
|
|
167
|
+
loadDataDir: e.loadDataDir,
|
|
168
|
+
debug: e.debug
|
|
169
|
+
});
|
|
170
|
+
} else c = await n.PGlite.create({
|
|
171
|
+
dataDir: t.dataDir,
|
|
172
|
+
extensions: i,
|
|
173
|
+
relaxedDurability: e.relaxedDurability,
|
|
174
|
+
loadDataDir: e.loadDataDir,
|
|
175
|
+
debug: e.debug,
|
|
176
|
+
...await g(e.assets)
|
|
177
|
+
});
|
|
178
|
+
let a = await _(c);
|
|
179
|
+
if (o && o !== String(a.serverMajor)) throw new r(t.dataDir, o, String(a.serverMajor));
|
|
180
|
+
let l = e.migrations?.length ? (await S(c, e.migrations)).applied : [], u = c;
|
|
181
|
+
return {
|
|
182
|
+
db: u,
|
|
183
|
+
info: {
|
|
184
|
+
dataDir: t.dataDir,
|
|
185
|
+
kind: t.kind,
|
|
186
|
+
...a,
|
|
187
|
+
worker: !!s,
|
|
188
|
+
migrated: l,
|
|
189
|
+
previousMajor: o
|
|
190
|
+
},
|
|
191
|
+
close: async () => {
|
|
192
|
+
await u.close().catch(() => void 0), s?.terminate();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
} catch (e) {
|
|
196
|
+
if (await c?.close().catch(() => void 0), s?.terminate(), e instanceof n || e instanceof i) throw e;
|
|
197
|
+
if (o) {
|
|
198
|
+
let n = await y().catch(() => void 0);
|
|
199
|
+
if (n && n !== o) throw new r(t.dataDir, o, n, { cause: e });
|
|
200
|
+
}
|
|
201
|
+
throw new n("OPEN_FAILED", `Could not open "${t.dataDir}": ${a(e).message}`, { cause: e });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function x(e) {
|
|
205
|
+
let t = 2166136261;
|
|
206
|
+
for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
|
|
207
|
+
return (t >>> 0).toString(16).padStart(8, "0");
|
|
208
|
+
}
|
|
209
|
+
async function S(e, t, { table: n = "_bl_migrations" } = {}) {
|
|
210
|
+
let r = /* @__PURE__ */ new Set();
|
|
211
|
+
for (let e of t) {
|
|
212
|
+
if (r.has(e.id)) throw new i("duplicate", `Migration id "${e.id}" appears more than once.`, { migration: e.id });
|
|
213
|
+
r.add(e.id);
|
|
214
|
+
}
|
|
215
|
+
let s = o(n);
|
|
216
|
+
await e.exec(`create table if not exists ${s} (position integer primary key, id text not null unique, checksum text, applied_at timestamptz not null default now())`);
|
|
217
|
+
let { rows: c } = await e.query(`select position, id, checksum from ${s} order by position`);
|
|
218
|
+
if (c.length > t.length) {
|
|
219
|
+
let e = c.slice(t.length).map((e) => e.id);
|
|
220
|
+
throw new i("unknown-applied", `The database has applied migrations this app does not know: ${e.join(", ")}. It was probably migrated by a newer version of the app; refusing to open it.`, { migration: e[0] });
|
|
221
|
+
}
|
|
222
|
+
c.forEach((e, n) => {
|
|
223
|
+
let r = t[n];
|
|
224
|
+
if (e.id !== r.id) throw new i("order", `Migration history has drifted: position ${n + 1} is "${e.id}" in the database but "${r.id}" in the list. Applied migrations must be an unchanged prefix of the list; add new migrations at the end.`, { migration: r.id });
|
|
225
|
+
if (typeof r.sql == "string" && e.checksum && e.checksum !== x(r.sql)) throw new i("changed", `Migration "${r.id}" was edited after it was applied. Add a new migration instead of changing an applied one.`, { migration: r.id });
|
|
226
|
+
});
|
|
227
|
+
let l = [];
|
|
228
|
+
for (let n = c.length; n < t.length; n++) {
|
|
229
|
+
let r = t[n];
|
|
230
|
+
try {
|
|
231
|
+
await e.transaction(async (e) => {
|
|
232
|
+
typeof r.sql == "string" ? await e.exec(r.sql) : await r.sql(e), await e.query(`insert into ${s} (position, id, checksum) values ($1, $2, $3)`, [
|
|
233
|
+
n + 1,
|
|
234
|
+
r.id,
|
|
235
|
+
typeof r.sql == "string" ? x(r.sql) : null
|
|
236
|
+
]);
|
|
237
|
+
});
|
|
238
|
+
} catch (e) {
|
|
239
|
+
throw new i("failed", `Migration "${r.id}" failed and was rolled back: ${a(e).message}`, {
|
|
240
|
+
migration: r.id,
|
|
241
|
+
cause: e
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
l.push(r.id);
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
applied: l,
|
|
248
|
+
skipped: c.length
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
async function C(e, n) {
|
|
252
|
+
let r = t(n), i = performance.now();
|
|
253
|
+
try {
|
|
254
|
+
let t = await e.exec(n), a = t.length === r.length;
|
|
255
|
+
return {
|
|
256
|
+
results: t.map((e, t) => ({
|
|
257
|
+
...e,
|
|
258
|
+
statement: a ? r[t].text : void 0
|
|
259
|
+
})),
|
|
260
|
+
durationMs: performance.now() - i,
|
|
261
|
+
statementCount: r.length
|
|
262
|
+
};
|
|
263
|
+
} catch (t) {
|
|
264
|
+
return /\b(begin|start\s+transaction)\b/i.test(n) && await e.exec("rollback").catch(() => void 0), {
|
|
265
|
+
results: [],
|
|
266
|
+
durationMs: performance.now() - i,
|
|
267
|
+
error: a(t, n),
|
|
268
|
+
statementCount: r.length
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
export { r as DataDirVersionError, i as MigrationError, n as PGliteError, m as deleteDatabase, c as identifier, b as openDatabase, u as parseDataDir, p as peekDataDirVersion, o as quoteIdent, l as quoteLiteral, _ as readServerInfo, S as runMigrations, C as runSql, y as runtimePostgresMajor, a as toSqlError };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Saves a `Blob` / `File` through a temporary link (the download attribute). */
|
|
2
|
+
export declare function downloadFile(file: Blob & {
|
|
3
|
+
name?: string;
|
|
4
|
+
}, name?: string): void;
|
|
5
|
+
/** Opens the file picker and resolves with the chosen file, or `null` if it was dismissed. Call it from a click handler. */
|
|
6
|
+
export declare function pickFile(accept?: string): Promise<File | null>;
|
|
7
|
+
//# sourceMappingURL=pglite-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pglite-files.d.ts","sourceRoot":"","sources":["../../src/lib/pglite-files.ts"],"names":[],"mappings":"AAIA,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAWhF;AAED,4HAA4H;AAC5H,wBAAgB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAkB9D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/lib/pglite-files.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
let n = URL.createObjectURL(e), r = document.createElement("a");
|
|
4
|
+
r.href = n, r.download = t ?? e.name ?? "download", r.rel = "noopener", document.body.append(r), r.click(), r.remove(), setTimeout(() => URL.revokeObjectURL(n), 3e4);
|
|
5
|
+
}
|
|
6
|
+
function t(e) {
|
|
7
|
+
return new Promise((t) => {
|
|
8
|
+
let n = document.createElement("input");
|
|
9
|
+
n.type = "file", e && (n.accept = e), n.style.display = "none", n.addEventListener("change", () => {
|
|
10
|
+
t(n.files?.[0] ?? null), n.remove();
|
|
11
|
+
}), n.addEventListener("cancel", () => {
|
|
12
|
+
t(null), n.remove();
|
|
13
|
+
}), document.body.append(n), n.click();
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { e as downloadFile, t as pickFile };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SqlError, SqlRunner } from './pglite-core';
|
|
2
|
+
export type RelationKind = 'table' | 'view' | 'materialized view' | 'foreign table' | 'partitioned table';
|
|
3
|
+
export interface ColumnReference {
|
|
4
|
+
schema: string;
|
|
5
|
+
table: string;
|
|
6
|
+
column: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SchemaColumn {
|
|
9
|
+
name: string;
|
|
10
|
+
/** `format_type`: `integer`, `character varying(255)`, `timestamp with time zone`, `text[]`. */
|
|
11
|
+
type: string;
|
|
12
|
+
/** The type's OID, to look up with `pgTypeName`. */
|
|
13
|
+
typeOid: number;
|
|
14
|
+
nullable: boolean;
|
|
15
|
+
/** The default expression, e.g. `nextval('app.t_id_seq'::regclass)` or `now()`. */
|
|
16
|
+
default: string | null;
|
|
17
|
+
isPrimaryKey: boolean;
|
|
18
|
+
/** The column this one points at, when it is (part of) a foreign key. */
|
|
19
|
+
references: ColumnReference | null;
|
|
20
|
+
}
|
|
21
|
+
export interface SchemaTable {
|
|
22
|
+
schema: string;
|
|
23
|
+
name: string;
|
|
24
|
+
kind: RelationKind;
|
|
25
|
+
comment: string | null;
|
|
26
|
+
columns: SchemaColumn[];
|
|
27
|
+
/** Rows, per the `rowCounts` option; `null` for views, when not counted, or when the count failed. */
|
|
28
|
+
rowCount: number | null;
|
|
29
|
+
}
|
|
30
|
+
export interface SchemaNode {
|
|
31
|
+
name: string;
|
|
32
|
+
tables: SchemaTable[];
|
|
33
|
+
}
|
|
34
|
+
export interface SchemaInfo {
|
|
35
|
+
schemas: SchemaNode[];
|
|
36
|
+
}
|
|
37
|
+
export interface LoadSchemaOptions {
|
|
38
|
+
/** Include `pg_catalog`, `information_schema` and TOAST schemas. Default false. */
|
|
39
|
+
system?: boolean;
|
|
40
|
+
/** Include BL UI's own bookkeeping tables (`_bl_migrations`). Default false. */
|
|
41
|
+
internal?: boolean;
|
|
42
|
+
/** `exact` runs `count(*)` on each table (default; fine for browser-sized data), `estimate` reads the planner's
|
|
43
|
+
statistics (instant, but 0 or -1 for a table that was never analyzed → shown as `null`), `none` skips counts. */
|
|
44
|
+
rowCounts?: 'exact' | 'estimate' | 'none';
|
|
45
|
+
/** Stop counting after this many tables (default 100). */
|
|
46
|
+
maxCounted?: number;
|
|
47
|
+
}
|
|
48
|
+
/** Reads the schema. Never throws for a failed row count (that table's `rowCount` is `null`). */
|
|
49
|
+
export declare function loadSchema(db: SqlRunner, { system, internal, rowCounts, maxCounted }?: LoadSchemaOptions): Promise<SchemaInfo>;
|
|
50
|
+
export interface UseSchemaState {
|
|
51
|
+
schema: SchemaInfo | null;
|
|
52
|
+
isLoading: boolean;
|
|
53
|
+
error: SqlError | null;
|
|
54
|
+
refetch: () => void;
|
|
55
|
+
}
|
|
56
|
+
/** The provider's schema. Re-read after writes made through `useExec` / `useTransaction` (or `invalidate()`). */
|
|
57
|
+
export declare function useSchema(options?: LoadSchemaOptions): UseSchemaState;
|
|
58
|
+
//# sourceMappingURL=pglite-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pglite-schema.d.ts","sourceRoot":"","sources":["../../src/lib/pglite-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAA0B,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAQ1F,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,mBAAmB,GAAG,eAAe,GAAG,mBAAmB,CAAC;AAE1G,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,gGAAgG;IAChG,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,mFAAmF;IACnF,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,yEAAyE;IACzE,UAAU,EAAE,eAAe,GAAG,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,sGAAsG;IACtG,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;wHACoH;IACpH,SAAS,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,MAAM,CAAC;IAC1C,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAoCD,iGAAiG;AACjG,wBAAsB,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,EAAE,MAAc,EAAE,QAAgB,EAAE,SAAmB,EAAE,UAAgB,EAAE,GAAE,iBAAsB,GAAG,OAAO,CAAC,UAAU,CAAC,CAgDxK;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,iHAAiH;AACjH,wBAAgB,SAAS,CAAC,OAAO,GAAE,iBAAsB,GAAG,cAAc,CAoBzE"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { quoteIdent as e, toSqlError as t } from "./pglite-core.js";
|
|
3
|
+
import { useDatabaseStatus as n } from "./pglite.js";
|
|
4
|
+
import { useEffect as r, useState as i } from "react";
|
|
5
|
+
//#region src/lib/pglite-schema.ts
|
|
6
|
+
var a = {
|
|
7
|
+
r: "table",
|
|
8
|
+
v: "view",
|
|
9
|
+
m: "materialized view",
|
|
10
|
+
f: "foreign table",
|
|
11
|
+
p: "partitioned table"
|
|
12
|
+
}, o = "\nselect n.nspname as schema, c.relname as table, c.relkind::text as kind, obj_description(c.oid, 'pg_class') as comment,\n c.reltuples::float8 as estimate,\n a.attname as column, format_type(a.atttypid, a.atttypmod) as type, a.atttypid::int as type_oid,\n not a.attnotnull as nullable, pg_get_expr(d.adbin, d.adrelid) as \"default\",\n coalesce(a.attnum = any(pk.indkey), false) as is_pk\nfrom pg_class c\njoin pg_namespace n on n.oid = c.relnamespace\njoin pg_attribute a on a.attrelid = c.oid and a.attnum > 0 and not a.attisdropped\nleft join pg_attrdef d on d.adrelid = c.oid and d.adnum = a.attnum\nleft join pg_index pk on pk.indrelid = c.oid and pk.indisprimary\nwhere c.relkind in ('r', 'v', 'm', 'f', 'p')\n and not c.relispartition\norder by n.nspname, c.relname, a.attnum", s = "\nselect n.nspname as schema, c.relname as table, a.attname as column,\n fn.nspname as ref_schema, fc.relname as ref_table, fa.attname as ref_column\nfrom pg_constraint con\njoin pg_class c on c.oid = con.conrelid\njoin pg_namespace n on n.oid = c.relnamespace\njoin pg_class fc on fc.oid = con.confrelid\njoin pg_namespace fn on fn.oid = fc.relnamespace\ncross join lateral unnest(con.conkey, con.confkey) as k(attnum, fattnum)\njoin pg_attribute a on a.attrelid = con.conrelid and a.attnum = k.attnum\njoin pg_attribute fa on fa.attrelid = con.confrelid and fa.attnum = k.fattnum\nwhere con.contype = 'f'", c = (e) => e === "pg_catalog" || e === "information_schema" || e.startsWith("pg_toast") || e.startsWith("pg_temp");
|
|
13
|
+
async function l(t, { system: n = !1, internal: r = !1, rowCounts: i = "exact", maxCounted: l = 100 } = {}) {
|
|
14
|
+
let [u, d] = await Promise.all([t.query(o), t.query(s)]), f = /* @__PURE__ */ new Map();
|
|
15
|
+
for (let e of d.rows) f.set(`${e.schema}.${e.table}.${e.column}`, {
|
|
16
|
+
schema: e.ref_schema,
|
|
17
|
+
table: e.ref_table,
|
|
18
|
+
column: e.ref_column
|
|
19
|
+
});
|
|
20
|
+
let p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
|
|
21
|
+
for (let e of u.rows) {
|
|
22
|
+
if (!n && c(e.schema) || !r && e.table.startsWith("_bl_")) continue;
|
|
23
|
+
let t = `${e.schema}.${e.table}`, i = p.get(t);
|
|
24
|
+
i || (i = {
|
|
25
|
+
schema: e.schema,
|
|
26
|
+
name: e.table,
|
|
27
|
+
kind: a[e.kind] ?? "table",
|
|
28
|
+
comment: e.comment,
|
|
29
|
+
columns: [],
|
|
30
|
+
rowCount: null
|
|
31
|
+
}, p.set(t, i), m.set(t, e.estimate)), i.columns.push({
|
|
32
|
+
name: e.column,
|
|
33
|
+
type: e.type,
|
|
34
|
+
typeOid: e.type_oid,
|
|
35
|
+
nullable: e.nullable,
|
|
36
|
+
default: e.default,
|
|
37
|
+
isPrimaryKey: e.is_pk,
|
|
38
|
+
references: f.get(`${t}.${e.column}`) ?? null
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (i === "estimate") for (let [e, t] of p) t.kind !== "view" && (t.rowCount = (m.get(e) ?? -1) >= 0 ? Math.round(m.get(e)) : null);
|
|
42
|
+
else if (i === "exact") {
|
|
43
|
+
let n = [...p.values()].filter((e) => e.kind === "table" || e.kind === "partitioned table" || e.kind === "materialized view").slice(0, l);
|
|
44
|
+
for (let r of n) try {
|
|
45
|
+
let { rows: n } = await t.query(`select count(*)::float8 as n from ${e(r.schema)}.${e(r.name)}`);
|
|
46
|
+
r.rowCount = n[0]?.n ?? null;
|
|
47
|
+
} catch {
|
|
48
|
+
r.rowCount = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let h = /* @__PURE__ */ new Map();
|
|
52
|
+
for (let e of p.values()) {
|
|
53
|
+
let t = h.get(e.schema);
|
|
54
|
+
t || h.set(e.schema, t = {
|
|
55
|
+
name: e.schema,
|
|
56
|
+
tables: []
|
|
57
|
+
}), t.tables.push(e);
|
|
58
|
+
}
|
|
59
|
+
return { schemas: [...h.values()] };
|
|
60
|
+
}
|
|
61
|
+
function u(e = {}) {
|
|
62
|
+
let { db: a, epoch: o } = n(), [s, c] = i({
|
|
63
|
+
schema: null,
|
|
64
|
+
error: null,
|
|
65
|
+
loading: !0
|
|
66
|
+
}), [u, d] = i(0), { system: f, internal: p, rowCounts: m, maxCounted: h } = e;
|
|
67
|
+
return r(() => {
|
|
68
|
+
if (!a) return;
|
|
69
|
+
let e = !1;
|
|
70
|
+
return c((e) => e.loading ? e : {
|
|
71
|
+
...e,
|
|
72
|
+
loading: !0
|
|
73
|
+
}), l(a, {
|
|
74
|
+
system: f,
|
|
75
|
+
internal: p,
|
|
76
|
+
rowCounts: m,
|
|
77
|
+
maxCounted: h
|
|
78
|
+
}).then((t) => !e && c({
|
|
79
|
+
schema: t,
|
|
80
|
+
error: null,
|
|
81
|
+
loading: !1
|
|
82
|
+
}), (n) => !e && c((e) => ({
|
|
83
|
+
schema: e.schema,
|
|
84
|
+
error: t(n),
|
|
85
|
+
loading: !1
|
|
86
|
+
}))), () => {
|
|
87
|
+
e = !0;
|
|
88
|
+
};
|
|
89
|
+
}, [
|
|
90
|
+
a,
|
|
91
|
+
o,
|
|
92
|
+
u,
|
|
93
|
+
f,
|
|
94
|
+
p,
|
|
95
|
+
m,
|
|
96
|
+
h
|
|
97
|
+
]), {
|
|
98
|
+
schema: s.schema,
|
|
99
|
+
isLoading: !a || s.loading,
|
|
100
|
+
error: s.error,
|
|
101
|
+
refetch: () => d((e) => e + 1)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { l as loadSchema, u as useSchema };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface PersistenceSupport {
|
|
2
|
+
/** The probe finished (before that every flag is `false`/`null`). */
|
|
3
|
+
checked: boolean;
|
|
4
|
+
/** Served over HTTPS or localhost: required for `navigator.locks`, OPFS and `crypto.subtle`. */
|
|
5
|
+
secureContext: boolean;
|
|
6
|
+
/** IndexedDB exists: `idb://` works. */
|
|
7
|
+
indexedDB: boolean;
|
|
8
|
+
/** The origin private file system exists (`navigator.storage.getDirectory`). `opfs-ahp://` additionally needs a worker. */
|
|
9
|
+
opfs: boolean;
|
|
10
|
+
/** Web Workers (needed for `opfs-ahp://` and for a database shared by several tabs). */
|
|
11
|
+
worker: boolean;
|
|
12
|
+
/** `navigator.locks`: needed by `useTabLock` / `SingleTabGate`. */
|
|
13
|
+
locks: boolean;
|
|
14
|
+
/** WebAssembly (always true in current browsers). */
|
|
15
|
+
wasm: boolean;
|
|
16
|
+
/** The browser promised not to evict this origin's storage; `null` when it cannot tell. */
|
|
17
|
+
persisted: boolean | null;
|
|
18
|
+
/** Bytes used and available to this origin; `null` when the browser does not estimate. */
|
|
19
|
+
estimate: {
|
|
20
|
+
usage: number;
|
|
21
|
+
quota: number;
|
|
22
|
+
} | null;
|
|
23
|
+
/** Ask for persistent storage; resolves with the answer (and updates `persisted`). Call it from a user action. */
|
|
24
|
+
persist: () => Promise<boolean>;
|
|
25
|
+
/** Re-read the estimate (after a big write). */
|
|
26
|
+
refresh: () => void;
|
|
27
|
+
}
|
|
28
|
+
type Probe = Omit<PersistenceSupport, 'persist' | 'refresh'>;
|
|
29
|
+
/** Reads the capabilities. Browser only. */
|
|
30
|
+
export declare function detectPersistenceSupport(): Promise<Probe>;
|
|
31
|
+
export declare function usePersistenceSupport(): PersistenceSupport;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=pglite-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pglite-storage.d.ts","sourceRoot":"","sources":["../../src/lib/pglite-storage.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,kBAAkB;IACjC,qEAAqE;IACrE,OAAO,EAAE,OAAO,CAAC;IACjB,gGAAgG;IAChG,aAAa,EAAE,OAAO,CAAC;IACvB,wCAAwC;IACxC,SAAS,EAAE,OAAO,CAAC;IACnB,2HAA2H;IAC3H,IAAI,EAAE,OAAO,CAAC;IACd,wFAAwF;IACxF,MAAM,EAAE,OAAO,CAAC;IAChB,mEAAmE;IACnE,KAAK,EAAE,OAAO,CAAC;IACf,qDAAqD;IACrD,IAAI,EAAE,OAAO,CAAC;IACd,2FAA2F;IAC3F,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,0FAA0F;IAC1F,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAClD,kHAAkH;IAClH,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,gDAAgD;IAChD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,KAAK,KAAK,GAAG,IAAI,CAAC,kBAAkB,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;AAM7D,4CAA4C;AAC5C,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,KAAK,CAAC,CAkB/D;AAED,wBAAgB,qBAAqB,IAAI,kBAAkB,CAkB1D"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback as e, useEffect as t, useState as n } from "react";
|
|
3
|
+
//#region src/lib/pglite-storage.ts
|
|
4
|
+
var r = {
|
|
5
|
+
checked: !1,
|
|
6
|
+
secureContext: !1,
|
|
7
|
+
indexedDB: !1,
|
|
8
|
+
opfs: !1,
|
|
9
|
+
worker: !1,
|
|
10
|
+
locks: !1,
|
|
11
|
+
wasm: !1,
|
|
12
|
+
persisted: null,
|
|
13
|
+
estimate: null
|
|
14
|
+
};
|
|
15
|
+
async function i() {
|
|
16
|
+
if (typeof navigator > "u") return {
|
|
17
|
+
...r,
|
|
18
|
+
checked: !0
|
|
19
|
+
};
|
|
20
|
+
let e = navigator.storage, [t, n] = await Promise.all([e?.persisted ? e.persisted().catch(() => null) : Promise.resolve(null), e?.estimate ? e.estimate().catch(() => null) : Promise.resolve(null)]);
|
|
21
|
+
return {
|
|
22
|
+
checked: !0,
|
|
23
|
+
secureContext: typeof isSecureContext == "boolean" && isSecureContext,
|
|
24
|
+
indexedDB: typeof indexedDB < "u",
|
|
25
|
+
opfs: typeof e?.getDirectory == "function",
|
|
26
|
+
worker: typeof Worker < "u",
|
|
27
|
+
locks: !!navigator.locks,
|
|
28
|
+
wasm: typeof WebAssembly == "object",
|
|
29
|
+
persisted: t,
|
|
30
|
+
estimate: n && n.usage !== void 0 && n.quota !== void 0 ? {
|
|
31
|
+
usage: n.usage,
|
|
32
|
+
quota: n.quota
|
|
33
|
+
} : null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function a() {
|
|
37
|
+
let [a, o] = n(r), [s, c] = n(0);
|
|
38
|
+
t(() => {
|
|
39
|
+
let e = !0;
|
|
40
|
+
return i().then((t) => e && o(t)), () => {
|
|
41
|
+
e = !1;
|
|
42
|
+
};
|
|
43
|
+
}, [s]);
|
|
44
|
+
let l = e(async () => {
|
|
45
|
+
let e = typeof navigator > "u" ? void 0 : navigator.storage, t = e?.persist ? await e.persist().catch(() => !1) : !1;
|
|
46
|
+
return c((e) => e + 1), t;
|
|
47
|
+
}, []), u = e(() => c((e) => e + 1), []);
|
|
48
|
+
return {
|
|
49
|
+
...a,
|
|
50
|
+
persist: l,
|
|
51
|
+
refresh: u
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { i as detectPersistenceSupport, a as usePersistenceSupport };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Database, OpenDatabaseOptions, OpenedDatabase } from './pglite-core';
|
|
2
|
+
export type ExportFormat = 'sql' | 'datadir';
|
|
3
|
+
export interface ExportOptions {
|
|
4
|
+
/** File name; default `database-pg<major>.sql` / `database-pg<major>-pglite<version>.tar.gz`. */
|
|
5
|
+
fileName?: string;
|
|
6
|
+
/** Extra pg_dump arguments for `sql` (`['--schema-only']`, `['--table=app.notes']`). `--inserts` is always on. */
|
|
7
|
+
args?: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface ExportResult {
|
|
10
|
+
file: File;
|
|
11
|
+
format: ExportFormat;
|
|
12
|
+
/** The Postgres version that wrote it (`18.3`). A `datadir` archive restores only into the same major. */
|
|
13
|
+
postgresVersion: string;
|
|
14
|
+
postgresMajor: number;
|
|
15
|
+
pgliteVersion?: string;
|
|
16
|
+
bytes: number;
|
|
17
|
+
}
|
|
18
|
+
/** Exports the database. `sql` is the portable backup; `datadir` the same-version archive. */
|
|
19
|
+
export declare function exportDatabase(db: Database, format?: ExportFormat, options?: ExportOptions): Promise<ExportResult>;
|
|
20
|
+
/** `sql` for text dumps, `datadir` for gzip / tar archives — by magic bytes, then by file name. */
|
|
21
|
+
export declare function detectImportFormat(file: Blob & {
|
|
22
|
+
name?: string;
|
|
23
|
+
}): Promise<ExportFormat>;
|
|
24
|
+
/** The Postgres major version recorded in a data-directory archive (its `PG_VERSION` file), or `null` if there is none. */
|
|
25
|
+
export declare function readArchiveVersion(file: Blob): Promise<string | null>;
|
|
26
|
+
/** The Postgres version a SQL dump says it came from (`-- Dumped from database version 18.3`), if it says. */
|
|
27
|
+
export declare function dumpVersion(sql: string): string | null;
|
|
28
|
+
export interface ImportResult {
|
|
29
|
+
format: ExportFormat;
|
|
30
|
+
/** Version the file says it came from, when it says. */
|
|
31
|
+
sourceVersion: string | null;
|
|
32
|
+
/** Things worth telling the user (a dump from a newer Postgres, …). */
|
|
33
|
+
warnings: string[];
|
|
34
|
+
/** The statements of a SQL import ran in one transaction: true when they all applied. */
|
|
35
|
+
applied: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** Imports a file.
|
|
38
|
+
*
|
|
39
|
+
* - Into an open `Database`: applies a SQL dump (a data-directory archive cannot be loaded into a running database —
|
|
40
|
+
* that throws `UNSUPPORTED`; restore it by opening a new database with it).
|
|
41
|
+
* - Into a config (`{ dataDir, … }`): opens a NEW database from the file — a SQL dump into an empty database, a data
|
|
42
|
+
* directory archive via PGlite's `loadDataDir` — and returns it open; the caller owns it. A name that already holds a database
|
|
43
|
+
* is refused (`DATABASE_EXISTS`), and an archive from another Postgres major is refused before anything starts
|
|
44
|
+
* ({@link DataDirVersionError}). */
|
|
45
|
+
export declare function importDatabase(target: Database, file: Blob & {
|
|
46
|
+
name?: string;
|
|
47
|
+
}): Promise<ImportResult>;
|
|
48
|
+
export declare function importDatabase(target: OpenDatabaseOptions, file: Blob & {
|
|
49
|
+
name?: string;
|
|
50
|
+
}): Promise<ImportResult & OpenedDatabase & {
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
}>;
|
|
53
|
+
//# sourceMappingURL=pglite-transfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pglite-transfer.d.ts","sourceRoot":"","sources":["../../src/lib/pglite-transfer.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,KAAK,QAAQ,EAAE,KAAK,mBAAmB,EAAE,KAAK,cAAc,EAC7D,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,SAAS,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC5B,iGAAiG;IACjG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kHAAkH;IAClH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,YAAY,CAAC;IACrB,0GAA0G;IAC1G,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,8FAA8F;AAC9F,wBAAsB,cAAc,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAE,YAAoB,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAiBnI;AAED,mGAAmG;AACnG,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAM9F;AAwCD,2HAA2H;AAC3H,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAE3E;AAED,8GAA8G;AAC9G,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEtD;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,wDAAwD;IACxD,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,uEAAuE;IACvE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,yFAAyF;IACzF,OAAO,EAAE,OAAO,CAAC;CAClB;AAqBD;;;;;;;uCAOuC;AACvC,wBAAsB,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAC9G,wBAAsB,cAAc,CAAC,MAAM,EAAE,mBAAmB,EAAE,IAAI,EAAE,IAAI,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,YAAY,GAAG,cAAc,GAAG;IAAE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAAC"}
|