@di-framework/pglite-component 0.0.0-stage → 6.0.9
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 +144 -2
- package/dist/BUILD-INFO.txt +13 -0
- package/dist/SHA256SUMS +3 -0
- package/dist/THIRD-PARTY-NOTICES.txt +345 -0
- package/dist/di-framework-pglite.wasm +0 -0
- package/dist/di-framework-pglite.wit +350 -0
- package/package.json +26 -4
- package/wit/deps/pglite-engine/engine.wit +16 -0
- package/wit/deps/wasi-cli-0.2.0/package.wit +159 -0
- package/wit/deps/wasi-clocks-0.2.0/package.wit +29 -0
- package/wit/deps/wasi-filesystem-0.2.0/package.wit +158 -0
- package/wit/deps/wasi-http-0.2.0/package.wit +571 -0
- package/wit/deps/wasi-io-0.2.0/package.wit +48 -0
- package/wit/deps/wasi-random-0.2.0/package.wit +18 -0
- package/wit/deps/wasi-sockets-0.2.0/package.wit +833 -0
- package/wit/world.wit +165 -0
package/wit/world.wit
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
package di-framework:pglite@0.1.0;
|
|
2
|
+
|
|
3
|
+
/// Types shared by the `database` interface.
|
|
4
|
+
///
|
|
5
|
+
/// Mirrors `di-framework:sqlite/types` on purpose so consumers can switch
|
|
6
|
+
/// between the SQLite and PGlite providers with minimal code changes:
|
|
7
|
+
/// same `value`/`row`/`error` shapes, same connection lifecycle
|
|
8
|
+
/// (`open`/`query`/`run`/`exec`/`first`/transactions/`close`).
|
|
9
|
+
/// Differences from SQLite are documented on the affected items.
|
|
10
|
+
interface types {
|
|
11
|
+
/// A structured error reported by Postgres itself.
|
|
12
|
+
record pg-error {
|
|
13
|
+
/// SQLSTATE code (e.g. `23505` = unique_violation).
|
|
14
|
+
/// SQLite reports numeric result codes instead.
|
|
15
|
+
code: string,
|
|
16
|
+
/// Human-readable message from the server.
|
|
17
|
+
message: string,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// Errors raised by functions in this package. Intentionally non-exhaustive:
|
|
21
|
+
/// consumers must keep a catch-all arm.
|
|
22
|
+
variant error {
|
|
23
|
+
/// The data directory could not be opened, initialization failed, or
|
|
24
|
+
/// another connection already owns this component instance.
|
|
25
|
+
open-failed(string),
|
|
26
|
+
/// The connection has been closed with `close` and cannot be used again.
|
|
27
|
+
closed,
|
|
28
|
+
/// The statement could not be prepared or executed: syntax error, unknown
|
|
29
|
+
/// table or column. Only single statements are accepted by `run`/`query`/`first`
|
|
30
|
+
/// (unlike `exec`, which allows `;`-separated batches like the SQLite provider).
|
|
31
|
+
invalid-sql(string),
|
|
32
|
+
/// Wrong number of parameters or a value that could not be bound.
|
|
33
|
+
/// Parameters bind positionally to `$1`, `$2`, ... (not `?`/`?NNN`).
|
|
34
|
+
invalid-params(string),
|
|
35
|
+
/// Postgres reported an error while executing the statement (constraint
|
|
36
|
+
/// violation, undefined table, ...). Branch on `pg-error.code` (SQLSTATE)
|
|
37
|
+
/// for machine-readable handling.
|
|
38
|
+
execution-failed(pg-error),
|
|
39
|
+
/// A column value could not be converted into a `value`.
|
|
40
|
+
value-conversion-failed(string),
|
|
41
|
+
/// The embedded engine is unusable. Restart the component to recover.
|
|
42
|
+
connection-lost(string),
|
|
43
|
+
/// `begin`, `commit`, `rollback` (or a savepoint call) was issued in a
|
|
44
|
+
/// state that does not permit it (e.g. `commit` with no open transaction).
|
|
45
|
+
invalid-transaction-state(string),
|
|
46
|
+
/// Any other implementation-specific failure.
|
|
47
|
+
other(string),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// A dynamically-typed value, used for parameters and results.
|
|
51
|
+
/// Identical to the SQLite provider plus `boolean`: Postgres has a native
|
|
52
|
+
/// boolean type and the text encoding (`t`/`f`) is lossy without it.
|
|
53
|
+
variant value {
|
|
54
|
+
null,
|
|
55
|
+
integer(s64),
|
|
56
|
+
real(f64),
|
|
57
|
+
text(string),
|
|
58
|
+
blob(list<u8>),
|
|
59
|
+
boolean(bool),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// A result row: `(column-name, value)` pairs in column order.
|
|
63
|
+
type row = list<tuple<string, value>>;
|
|
64
|
+
|
|
65
|
+
/// Options accepted by `open`. Every field is optional; `none` means the
|
|
66
|
+
/// documented default.
|
|
67
|
+
record open-options {
|
|
68
|
+
/// Database name for the session. Only `template1` is currently supported.
|
|
69
|
+
database: option<string>,
|
|
70
|
+
/// Reserved: WASI lacks the signal timer used for query cancellation.
|
|
71
|
+
/// Only none or zero is supported; nonzero values fail open.
|
|
72
|
+
statement-timeout-ms: option<u32>,
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/// Embedded PostgreSQL access. The engine is bundled into the provider and
|
|
77
|
+
/// queries pass through WebAssembly memory; no sockets or sidecar are used.
|
|
78
|
+
/// Data and runtime files live underneath a directory in a writable WASI
|
|
79
|
+
/// filesystem preopen. The host must grant exclusive ownership of that
|
|
80
|
+
/// directory to one component instance at a time.
|
|
81
|
+
interface database {
|
|
82
|
+
use types.{error, value, row, open-options};
|
|
83
|
+
|
|
84
|
+
/// Open a persistent database root (e.g. `/data/orders`); an empty path
|
|
85
|
+
/// selects `/data/pglite`. No ephemeral fallback. The root contains `data/`
|
|
86
|
+
/// (PGDATA), `runtime/` (bundled support files), and bootstrap scratch files.
|
|
87
|
+
/// Only one open connection and one database root per component instance
|
|
88
|
+
/// are supported. Close/drop releases the connection for reuse at that root.
|
|
89
|
+
open: func(path: string, options: option<open-options>) -> result<connection, error>;
|
|
90
|
+
|
|
91
|
+
/// The bundled engine version string, `17.5`; does not open a database.
|
|
92
|
+
server-version: func() -> result<string, error>;
|
|
93
|
+
|
|
94
|
+
/// An exclusive handle to the embedded session. Closing or dropping it
|
|
95
|
+
/// rolls back uncommitted work and resets session state.
|
|
96
|
+
resource connection {
|
|
97
|
+
/// Execute one or more `;`-separated statements and discard any results.
|
|
98
|
+
/// Intended for DDL / migrations. Untrusted input must never be
|
|
99
|
+
/// interpolated into `sql`.
|
|
100
|
+
exec: func(sql: string) -> result<_, error>;
|
|
101
|
+
|
|
102
|
+
/// Execute a single parameterized statement and return the number of rows
|
|
103
|
+
/// affected (the `CommandComplete` tag count). Parameters bind positionally
|
|
104
|
+
/// to `$1`, `$2`, ...
|
|
105
|
+
run: func(sql: string, params: list<value>) -> result<u64, error>;
|
|
106
|
+
|
|
107
|
+
/// Execute a single parameterized statement and return all rows.
|
|
108
|
+
query: func(sql: string, params: list<value>) -> result<list<row>, error>;
|
|
109
|
+
|
|
110
|
+
/// Execute a single parameterized statement and return only the first row,
|
|
111
|
+
/// or `none` when the statement produced no rows.
|
|
112
|
+
first: func(sql: string, params: list<value>) -> result<option<row>, error>;
|
|
113
|
+
|
|
114
|
+
/// `BEGIN`. Fails with `invalid-transaction-state` if a transaction is
|
|
115
|
+
/// already open on this connection; nest with `savepoint` instead.
|
|
116
|
+
begin: func() -> result<_, error>;
|
|
117
|
+
|
|
118
|
+
/// `COMMIT` the open transaction.
|
|
119
|
+
commit: func() -> result<_, error>;
|
|
120
|
+
|
|
121
|
+
/// `ROLLBACK` the open transaction.
|
|
122
|
+
rollback: func() -> result<_, error>;
|
|
123
|
+
|
|
124
|
+
/// `SAVEPOINT <name>`; usable for nested transactions. `name` must match
|
|
125
|
+
/// `[A-Za-z_][A-Za-z0-9_]*`.
|
|
126
|
+
savepoint: func(name: string) -> result<_, error>;
|
|
127
|
+
|
|
128
|
+
/// `RELEASE SAVEPOINT <name>`.
|
|
129
|
+
release-savepoint: func(name: string) -> result<_, error>;
|
|
130
|
+
|
|
131
|
+
/// `ROLLBACK TO SAVEPOINT <name>` followed by `RELEASE`, so the savepoint
|
|
132
|
+
/// is fully unwound.
|
|
133
|
+
rollback-to-savepoint: func(name: string) -> result<_, error>;
|
|
134
|
+
|
|
135
|
+
/// True while a transaction (or savepoint) is open on this connection.
|
|
136
|
+
/// Reported by the engine, including transactions issued through `exec`.
|
|
137
|
+
in-transaction: func() -> bool;
|
|
138
|
+
|
|
139
|
+
/// Rows affected by the most recent `run`/`exec` on this connection.
|
|
140
|
+
rows-affected: func() -> u64;
|
|
141
|
+
|
|
142
|
+
/// Explicitly close the connection. Subsequent calls fail with `closed`.
|
|
143
|
+
close: func() -> result<_, error>;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/// The world implemented by the provider component.
|
|
148
|
+
/// Kept symmetric with the sqlite-component: `types` is exported explicitly
|
|
149
|
+
/// so the component is self-contained for `wac plug`.
|
|
150
|
+
///
|
|
151
|
+
/// The private engine import is resolved during the provider build. The
|
|
152
|
+
/// shipped artifact has only WASI imports, including filesystem and randomness.
|
|
153
|
+
world pglite-provider {
|
|
154
|
+
import di-framework:pglite-engine/engine@0.1.0;
|
|
155
|
+
export types;
|
|
156
|
+
export database;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// The world a consumer targets when it wants a Postgres database.
|
|
160
|
+
/// `wac plug` satisfies these imports with the `pglite-provider`
|
|
161
|
+
/// component's exports.
|
|
162
|
+
world imports {
|
|
163
|
+
import types;
|
|
164
|
+
import database;
|
|
165
|
+
}
|