@di-framework/cli-plugin-platform 6.1.1 → 6.1.2
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 +127 -2
- package/dist/assets/http-adapter.js +2 -5
- package/dist/assets/sqlite/BUILD-INFO.txt +1 -1
- package/dist/assets/wit/deps/di-framework-pglite/package.wit +175 -0
- package/dist/bindings.js +7 -6
- package/dist/build.d.ts +8 -0
- package/dist/build.js +56 -4
- package/dist/console/cluster.d.ts +3 -0
- package/dist/console/cluster.js +57 -4
- package/dist/deploy.d.ts +6 -0
- package/dist/deploy.js +23 -5
- package/dist/deps.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/node-compat/console.js +16 -1
- package/dist/node-compat/crypto-subtle.d.ts +6 -0
- package/dist/node-compat/crypto-subtle.js +41 -4
- package/dist/node-compat/crypto.d.ts +3 -2
- package/dist/node-compat/crypto.js +66 -17
- package/dist/node-compat/fs.d.ts +24 -2
- package/dist/node-compat/fs.js +137 -15
- package/dist/node-compat/node-errors.d.ts +20 -0
- package/dist/node-compat/node-errors.js +73 -0
- package/dist/node-compat/storage.d.ts +3 -3
- package/dist/node-compat/wasi-random.d.ts +21 -1
- package/dist/node-compat/wasi-random.js +45 -12
- package/dist/pglite.d.ts +106 -0
- package/dist/pglite.js +347 -0
- package/dist/project.d.ts +11 -0
- package/dist/project.js +14 -1
- package/dist/secret-admission.d.ts +21 -0
- package/dist/secret-admission.js +29 -0
- package/dist/wit.d.ts +3 -0
- package/dist/wit.js +12 -0
- package/dist/workload.d.ts +29 -0
- package/dist/workload.js +157 -39
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -31,7 +31,8 @@ A component project is marked by `di-framework.config.json`:
|
|
|
31
31
|
|
|
32
32
|
Named wasmCloud host-interface bindings live in `src/bindings.ts` (override with `"bindings"`).
|
|
33
33
|
Each exported class extending a `@di-framework/bindings` base and decorated with
|
|
34
|
-
`@
|
|
34
|
+
`@PlatformBinding('name')` is discovered statically and added to the WIT requirement graph.
|
|
35
|
+
`@WasmCloudBinding('name')` remains a deprecated alias of the same decorator.
|
|
35
36
|
The binding name selects its configuration overlay and normally becomes `hostInterfaces[].name`.
|
|
36
37
|
For `wasmcloud:postgres`, `wasmcloud:keyvalue`, `wasmcloud:blobstore`,
|
|
37
38
|
`wasmcloud:messaging`, and `wasmcloud:secrets`, host declarations omit the name to
|
|
@@ -171,6 +172,14 @@ declares an unnamed `wasi:logging` host interface (`interfaces: [logging]`). `pl
|
|
|
171
172
|
links it only for `wash`; wasmtime and jco cannot provide it, so those builds keep a
|
|
172
173
|
console that discards output.
|
|
173
174
|
|
|
175
|
+
Guest console lines format values the way Node's console does where JSON allows it.
|
|
176
|
+
WIT `s64`/`u64` values (SQLite integers, row counts, timestamps) reach JavaScript as
|
|
177
|
+
BigInt. A top-level BigInt prints as `42n`, as in Node, so `console.log(3n)` writes `3n`
|
|
178
|
+
rather than `3`. A BigInt nested in an object or array prints as the JSON string `"42n"`
|
|
179
|
+
(`{"id":"42n"}`, where Node prints `{ id: 42n }`) so the line stays valid JSON. Log
|
|
180
|
+
tooling cannot tell that value from the string `"42n"`; treat a string field matching
|
|
181
|
+
`^-?\d+n$` as a BigInt where the difference matters.
|
|
182
|
+
|
|
174
183
|
Logs are on by default. Set `"logs": false` in `di-framework.config.json` to opt a project out:
|
|
175
184
|
|
|
176
185
|
```json
|
|
@@ -294,6 +303,43 @@ di-framework platform cluster destroy --yes
|
|
|
294
303
|
|
|
295
304
|
Application `destroy` never runs `pulumi destroy`.
|
|
296
305
|
|
|
306
|
+
### Control Secret
|
|
307
|
+
|
|
308
|
+
An application that serves HTTP, cron, queues or actors gets a Secret
|
|
309
|
+
`<deployment>-control` holding `DI_CONTROL_TOKEN` and `DI_CONTROL_IDENTITY`. Tenant
|
|
310
|
+
developers may create, update and delete Secrets but not read, list, watch or patch them,
|
|
311
|
+
so the CLI never reads it back:
|
|
312
|
+
|
|
313
|
+
- `deploy` writes a new random token every time: it creates the Secret and, if it already
|
|
314
|
+
exists, replaces the whole Secret with an unconditional update. If keys were added to it
|
|
315
|
+
by hand, the platform's `tenant-secret-update` admission policy denies that update (it
|
|
316
|
+
refuses any update that drops a key), and deploy stops with "the control Secret
|
|
317
|
+
`<deployment>-control` has keys this CLI didn't write"; delete it with
|
|
318
|
+
`kubectl delete secret <deployment>-control` and redeploy. Other failed writes show
|
|
319
|
+
kubectl's reason, scrubbed of the token.
|
|
320
|
+
- The token rotates at that Secret write, before `kubectl apply`. The WorkloadDeployment
|
|
321
|
+
carries `DI_CONTROL_TOKEN_REVISION` (a digest of the token), so the deploy rolls the
|
|
322
|
+
workload onto the new token, but not at the same moment as its cron invokers: a CronJob
|
|
323
|
+
pod reads the Secret when it starts, so the invokers switch first and can get 401 from
|
|
324
|
+
the workload until its rollout is ready (the Job's retries normally absorb this).
|
|
325
|
+
- A deploy that fails after the Secret write (a failed `apply`, a rejected
|
|
326
|
+
WorkloadDeployment, a rollout that never becomes ready, or an interrupted deploy) leaves
|
|
327
|
+
the running workload on the old token while the invokers use the new one, so cron
|
|
328
|
+
invocations keep failing until the next successful deploy. A failed deploy's error then
|
|
329
|
+
ends with "the control token was rotated; re-run deploy to roll the workload onto it".
|
|
330
|
+
- `destroy` deletes the Secret by name, after the WorkloadDeployment, Service and CronJobs.
|
|
331
|
+
It deletes only `<deployment>-control`: Secrets are no longer part of its label-selected
|
|
332
|
+
delete (that would list them), so a Secret you labelled
|
|
333
|
+
`app.kubernetes.io/name=<deployment>` yourself stays; delete it by name.
|
|
334
|
+
- The console's credential reassignment replaces the named Secret with one holding only
|
|
335
|
+
`credential`; labels and annotations on it are not kept. It works only on a Secret whose
|
|
336
|
+
single key is `credential`: the console cannot read the Secret, so the platform's
|
|
337
|
+
`tenant-secret-update` admission policy refuses a replace that drops a key, and the
|
|
338
|
+
console answers 409. So does a Secret whose type is not `Opaque`, since the API server
|
|
339
|
+
refuses to change a Secret's type. Platform-managed Secrets (`di-binding-*`, `di-bs-*`,
|
|
340
|
+
`di-tenant-stock`, `di-platform-routes`) are refused with 403 before any request, and an
|
|
341
|
+
admission denial for a managed name also answers 403.
|
|
342
|
+
|
|
297
343
|
The generated local target publishes through its loopback registry NodePort and puts the equivalent
|
|
298
344
|
in-cluster registry address in the WorkloadDeployment. Both references use the same repository and
|
|
299
345
|
stable canonical-input tag. An `http://` push URL or `insecure = true` adds ORAS `--plain-http` only
|
|
@@ -474,7 +520,7 @@ matching pool is unavailable. `hostgroup` defaults to `default`. These selectors
|
|
|
474
520
|
existing host pools; application deployment does not provision them.
|
|
475
521
|
|
|
476
522
|
A target with a `hostgroup` is a tenant target, and its storage belongs to the platform.
|
|
477
|
-
Actors, queues, workers, and `persistentStorage: true` deploy with the annotation
|
|
523
|
+
Actors, queues, workers, PGlite guests, and `persistentStorage: true` deploy with the annotation
|
|
478
524
|
`di-framework.dev/persistent-storage: "true"` (plus `di-framework.dev/storage-mount:
|
|
479
525
|
"/data/actors"` for actors) and no volume, volume mount, or host path. The platform
|
|
480
526
|
controller creates `<storageRoot>/di-tenants/<tenant uid>/workloads/<workload>`, shared by
|
|
@@ -501,6 +547,85 @@ to the implicit workload; they do not select user identity or Kubernetes namespa
|
|
|
501
547
|
|
|
502
548
|
Generated platforms support declarative `tenants` and `users` in their Pulumi stack configuration. See [the generated platform guide](assets/platform/README.md#users-and-tenants) for CRDs, roles, token issuance, and lifecycle behavior.
|
|
503
549
|
|
|
550
|
+
### Embedded PostgreSQL (PGlite)
|
|
551
|
+
|
|
552
|
+
A guest that imports `di-framework:pglite/database@0.2.0` gets the
|
|
553
|
+
[PGlite provider](https://github.com/di-framework/platform/tree/main/platform/pglite-component)
|
|
554
|
+
plugged in after componentize (`wac plug`, like the SQLite provider). The database runs inside
|
|
555
|
+
the component: there is no `wasmcloud:postgres` binding, service, or connection string. Pin the
|
|
556
|
+
published provider by digest in `di-framework.config.json`:
|
|
557
|
+
|
|
558
|
+
```json
|
|
559
|
+
{
|
|
560
|
+
"name": "orders",
|
|
561
|
+
"entry": "src/app.ts",
|
|
562
|
+
"pglite": {
|
|
563
|
+
"image": "ghcr.io/di-framework/pglite-component@sha256:<64 hex>",
|
|
564
|
+
"storageMount": "/data",
|
|
565
|
+
"dataDir": "/data/pglite"
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
```ts
|
|
571
|
+
import { open } from 'di-framework:pglite/database@0.2.0';
|
|
572
|
+
|
|
573
|
+
const db = open(process.env.DI_PGLITE_DATA_DIR ?? '/data/pglite', undefined);
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
| Field | Default | Meaning |
|
|
577
|
+
| --- | --- | --- |
|
|
578
|
+
| `image` | required unless `wasm` is set | `<repository>@sha256:<digest>`, the manifest digest the platform publish job records. Tags are refused because they move. |
|
|
579
|
+
| `wasm` | none | A local provider build inside the project (symlinks resolved), used instead of `image` for offline development. Unverified; see below. |
|
|
580
|
+
| `storageMount` | `/data` | Guest preopen of the workload's persistent directory. Tenant targets accept `/data` or `/data/actors`. |
|
|
581
|
+
| `dataDir` | `<storageMount>/pglite` | Database root, at or under `storageMount`. The guest receives it as `DI_PGLITE_DATA_DIR`. |
|
|
582
|
+
|
|
583
|
+
The build pulls the provider with `oras`: `oras manifest fetch`, then `oras blob fetch` of the
|
|
584
|
+
manifest's single `application/wasm` layer. It checks that the manifest hashes to the pinned
|
|
585
|
+
digest and the layer to the digest the manifest names, then caches both at
|
|
586
|
+
`oci/sha256/<digest>/` under `$DI_FRAMEWORK_CACHE_DIR` (default `$XDG_CACHE_HOME/di-framework`,
|
|
587
|
+
else `~/.cache/di-framework`). A cached entry is verified again on every build and pulled again
|
|
588
|
+
if it no longer matches, and stale `.pull-*` staging directories (older than a day) are removed.
|
|
589
|
+
The build plugs a private copy of the verified bytes (`.di-framework/di-framework-pglite.wasm`),
|
|
590
|
+
so a later change to the shared cache cannot reach the composed component. While the GHCR
|
|
591
|
+
package is private, run `oras login ghcr.io` first.
|
|
592
|
+
|
|
593
|
+
`DI_FRAMEWORK_PGLITE_WASM=/path/to/di-framework-pglite.wasm` overrides both `wasm` and `image`.
|
|
594
|
+
A local provider is only checked to be WebAssembly, never against the digest, and the build prints
|
|
595
|
+
a `Warning:` on stderr when it uses one. `platform deploy`, and any build with `CI` set, refuse a
|
|
596
|
+
local provider unless `DI_FRAMEWORK_ALLOW_LOCAL_PGLITE=1` is set. The deploy result reports the
|
|
597
|
+
provider's source: the digest pin, or the local path marked unverified. Don't commit `wasm`
|
|
598
|
+
next to `image`: it replaces the pin on every build.
|
|
599
|
+
|
|
600
|
+
The build fails when the guest imports the database without a `pglite` entry, or when a `pglite`
|
|
601
|
+
entry has no matching import, because the deploy renders the following from the config alone:
|
|
602
|
+
|
|
603
|
+
- The workload's single component gets `localResources.config`
|
|
604
|
+
`di-framework.dev/exclusive-instance: "true"`, so the tenant host runs at most one instance of
|
|
605
|
+
it. The key is never put on a WorkloadService, which admission rejects; a guest shaped as a
|
|
606
|
+
service deploys as a component. The opt-in takes effect only on the exclusive tenant host
|
|
607
|
+
image (`ghcr.io/di-framework/wash:2.8.0-wasi-tls-exclusive`, selected with the platform's
|
|
608
|
+
`tenantHostImage`); see the platform's `tenant-host/README.md`. On stock wash the key is
|
|
609
|
+
ignored, and a saturated or draining pool builds a second instance that opens the same data
|
|
610
|
+
directory. `platform deploy` warns on stderr when a tenant host group's pod image is not
|
|
611
|
+
tagged `*-exclusive`. On other targets, including the `storage` host group, it cannot see the
|
|
612
|
+
host and prints a note instead.
|
|
613
|
+
- Persistent storage, as for `persistentStorage: true`. Tenant targets get the
|
|
614
|
+
`di-framework.dev/persistent-storage: "true"` annotation, plus `di-framework.dev/storage-mount`
|
|
615
|
+
when `storageMount` is not `/data`. Other targets get a host path volume on the `storage` pool.
|
|
616
|
+
- `replicas: 1` and `deployPolicy: Recreate`. Other replica counts are refused.
|
|
617
|
+
|
|
618
|
+
Give each database one owner. Members of one implicit workload share one storage directory,
|
|
619
|
+
mounted at each member's own `storageMount`. So `/data/pglite` under a `/data` mount and
|
|
620
|
+
`/data/actors/pglite` under a `/data/actors` mount are the same database. Members that both embed
|
|
621
|
+
PGlite need different `dataDir` values *relative to `storageMount`*. `platform deploy` refuses a
|
|
622
|
+
workload where two members resolve to the same root (`WASMCLOUD_PGLITE_DATA_DIR_CONFLICT`).
|
|
623
|
+
|
|
624
|
+
`platform dev` composes the provider but does not support PGlite yet. It mounts no storage
|
|
625
|
+
directory and sets no `DI_PGLITE_DATA_DIR`, so `open` fails locally. Exercise the database
|
|
626
|
+
against a deployed workload, or run the composed component with
|
|
627
|
+
`wasmtime run --dir ./data::/data` as the provider README shows.
|
|
628
|
+
|
|
504
629
|
### Managed PostgreSQL (upcoming release)
|
|
505
630
|
|
|
506
631
|
`di-framework platform service create postgres --name orders --wait` provisions
|
|
@@ -1287,9 +1287,6 @@ async function toWebRequest(incoming) {
|
|
|
1287
1287
|
for (const [name, value] of incoming.getHeaders().copyAll()) {
|
|
1288
1288
|
headers.append(name, decoder.decode(value));
|
|
1289
1289
|
}
|
|
1290
|
-
if (method === "GET" || method === "HEAD") {
|
|
1291
|
-
return new Request(`${scheme}://${authority}${path}`, { method, headers });
|
|
1292
|
-
}
|
|
1293
1290
|
let bodyBytes;
|
|
1294
1291
|
try {
|
|
1295
1292
|
const consumed = WasiRequest.consumeBody(incoming, lowerFuture({ tag: "ok", val: undefined }, VOID_RESULT_FUTURE_TYPES));
|
|
@@ -1305,7 +1302,7 @@ async function toWebRequest(incoming) {
|
|
|
1305
1302
|
return new Request(`${scheme}://${authority}${path}`, {
|
|
1306
1303
|
method,
|
|
1307
1304
|
headers,
|
|
1308
|
-
body: bodyBytes
|
|
1305
|
+
body: method === "GET" || method === "HEAD" ? undefined : bodyBytes
|
|
1309
1306
|
});
|
|
1310
1307
|
}
|
|
1311
1308
|
async function handleActorInvocation(request) {
|
|
@@ -1353,8 +1350,8 @@ async function fromWebResponse(response) {
|
|
|
1353
1350
|
var handler = {
|
|
1354
1351
|
async handle(incoming) {
|
|
1355
1352
|
try {
|
|
1356
|
-
ensureWasiEnvironment();
|
|
1357
1353
|
const request = await toWebRequest(incoming);
|
|
1354
|
+
ensureWasiEnvironment();
|
|
1358
1355
|
const isControlPath = isCronInvokeRequest(request) || isQueueControlRequest(request) || isActorInvocationRequest(request);
|
|
1359
1356
|
if (isControlPath && !allowControlSurface(request)) {
|
|
1360
1357
|
return await fromWebResponse(controlSurfaceNotFound());
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// From di-framework/platform platform/pglite-component/wit/world.wit (4f1af1bdd941).
|
|
2
|
+
// The pglite-provider world is left out: it imports the private engine package,
|
|
3
|
+
// which is composed away inside the published component.
|
|
4
|
+
package di-framework:pglite@0.2.0;
|
|
5
|
+
|
|
6
|
+
/// Types shared by the `database` interface.
|
|
7
|
+
///
|
|
8
|
+
/// Mirrors `di-framework:sqlite/types` on purpose so consumers can switch
|
|
9
|
+
/// between the SQLite and PGlite providers with minimal code changes:
|
|
10
|
+
/// same `value`/`row`/`error` shapes, same connection lifecycle
|
|
11
|
+
/// (`open`/`query`/`run`/`exec`/`first`/transactions/`close`).
|
|
12
|
+
/// Differences from SQLite are documented on the affected items.
|
|
13
|
+
interface types {
|
|
14
|
+
/// A structured error reported by Postgres itself.
|
|
15
|
+
record pg-error {
|
|
16
|
+
/// SQLSTATE code (e.g. `23505` = unique_violation).
|
|
17
|
+
/// SQLite reports numeric result codes instead.
|
|
18
|
+
code: string,
|
|
19
|
+
/// Human-readable message from the server.
|
|
20
|
+
message: string,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// Errors raised by functions in this package. Intentionally non-exhaustive:
|
|
24
|
+
/// consumers must keep a catch-all arm.
|
|
25
|
+
variant error {
|
|
26
|
+
/// The data directory could not be opened, initialization failed, or
|
|
27
|
+
/// another connection already owns this component instance.
|
|
28
|
+
open-failed(string),
|
|
29
|
+
/// The connection has been closed with `close` and cannot be used again.
|
|
30
|
+
closed,
|
|
31
|
+
/// The statement could not be prepared or executed: syntax error, unknown
|
|
32
|
+
/// table or column. Only single statements are accepted by `run`/`query`/`first`
|
|
33
|
+
/// (unlike `exec`, which allows `;`-separated batches like the SQLite provider).
|
|
34
|
+
invalid-sql(string),
|
|
35
|
+
/// Wrong number of parameters or a value that could not be bound.
|
|
36
|
+
/// Parameters bind positionally to `$1`, `$2`, ... (not `?`/`?NNN`).
|
|
37
|
+
invalid-params(string),
|
|
38
|
+
/// Postgres reported an error while executing the statement (constraint
|
|
39
|
+
/// violation, undefined table, ...). Branch on `pg-error.code` (SQLSTATE)
|
|
40
|
+
/// for machine-readable handling.
|
|
41
|
+
execution-failed(pg-error),
|
|
42
|
+
/// A column value could not be converted into a `value`.
|
|
43
|
+
value-conversion-failed(string),
|
|
44
|
+
/// The embedded engine is unusable. Restart the component to recover.
|
|
45
|
+
connection-lost(string),
|
|
46
|
+
/// `begin`, `commit`, `rollback` (or a savepoint call) was issued in a
|
|
47
|
+
/// state that does not permit it (e.g. `commit` with no open transaction).
|
|
48
|
+
invalid-transaction-state(string),
|
|
49
|
+
/// Any other implementation-specific failure.
|
|
50
|
+
other(string),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// A dynamically-typed value, used for parameters and results.
|
|
54
|
+
/// Identical to the SQLite provider plus `boolean`: Postgres has a native
|
|
55
|
+
/// boolean type and the text encoding (`t`/`f`) is lossy without it.
|
|
56
|
+
/// `json` and `timestamp` are new in 0.2.0 for PostgreSQL-specific types.
|
|
57
|
+
///
|
|
58
|
+
/// Results (session is `DateStyle=ISO`, `TimeZone=UTC`):
|
|
59
|
+
/// - `bool` -> `boolean`; `int2`/`int4`/`int8` -> `integer` (`int8` too);
|
|
60
|
+
/// `float4`/`float8` -> `real`; `bytea` -> `blob`.
|
|
61
|
+
/// - `json` and `jsonb` -> `json` (JSON text).
|
|
62
|
+
/// - `timestamptz` -> `timestamp`, RFC 3339 in UTC (`2024-01-15T10:30:00Z`,
|
|
63
|
+
/// fractional seconds kept). `infinity` and `-infinity` are returned as
|
|
64
|
+
/// those literals.
|
|
65
|
+
/// - `timestamp` (no zone) and `date` -> `text` (`2024-01-15 10:30:00`,
|
|
66
|
+
/// `2024-01-15`).
|
|
67
|
+
/// - `uuid` and `numeric` -> `text`; arrays -> `text` as PostgreSQL array
|
|
68
|
+
/// literals (`{a,b}`); all other types -> `text`.
|
|
69
|
+
///
|
|
70
|
+
/// Parameters: `text`, `json` and `timestamp` are sent with unknown type
|
|
71
|
+
/// (OID 0) so PostgreSQL infers the type from context; a parameter with no
|
|
72
|
+
/// context (`SELECT $1 IS NULL`) needs a cast.
|
|
73
|
+
variant value {
|
|
74
|
+
null,
|
|
75
|
+
integer(s64),
|
|
76
|
+
real(f64),
|
|
77
|
+
text(string),
|
|
78
|
+
blob(list<u8>),
|
|
79
|
+
boolean(bool),
|
|
80
|
+
json(string),
|
|
81
|
+
timestamp(string),
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// A result row: `(column-name, value)` pairs in column order.
|
|
85
|
+
type row = list<tuple<string, value>>;
|
|
86
|
+
|
|
87
|
+
/// Options accepted by `open`. Every field is optional; `none` means the
|
|
88
|
+
/// documented default.
|
|
89
|
+
record open-options {
|
|
90
|
+
/// Database name for the session. Only `template1` is currently supported.
|
|
91
|
+
database: option<string>,
|
|
92
|
+
/// Reserved: WASI lacks the signal timer used for query cancellation.
|
|
93
|
+
/// Only none or zero is supported; nonzero values fail open.
|
|
94
|
+
statement-timeout-ms: option<u32>,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/// Embedded PostgreSQL access. The engine is bundled into the provider and
|
|
99
|
+
/// queries pass through WebAssembly memory; no sockets or sidecar are used.
|
|
100
|
+
/// Data and runtime files live underneath a directory in a writable WASI
|
|
101
|
+
/// filesystem preopen. The host must grant exclusive ownership of that
|
|
102
|
+
/// directory to one component instance at a time.
|
|
103
|
+
interface database {
|
|
104
|
+
use types.{error, value, row, open-options};
|
|
105
|
+
|
|
106
|
+
/// Open a persistent database root (e.g. `/data/orders`); an empty path
|
|
107
|
+
/// selects `/data/pglite`. No ephemeral fallback. The root contains `data/`
|
|
108
|
+
/// (PGDATA), `runtime/` (bundled support files), and bootstrap scratch files.
|
|
109
|
+
/// Only one open connection and one database root per component instance
|
|
110
|
+
/// are supported. Close/drop releases the connection for reuse at that root.
|
|
111
|
+
open: func(path: string, options: option<open-options>) -> result<connection, error>;
|
|
112
|
+
|
|
113
|
+
/// The bundled engine version string, `17.5`; does not open a database.
|
|
114
|
+
server-version: func() -> result<string, error>;
|
|
115
|
+
|
|
116
|
+
/// An exclusive handle to the embedded session. Closing or dropping it
|
|
117
|
+
/// rolls back uncommitted work and resets session state.
|
|
118
|
+
resource connection {
|
|
119
|
+
/// Execute one or more `;`-separated statements and discard any results.
|
|
120
|
+
/// Intended for DDL / migrations. Untrusted input must never be
|
|
121
|
+
/// interpolated into `sql`.
|
|
122
|
+
exec: func(sql: string) -> result<_, error>;
|
|
123
|
+
|
|
124
|
+
/// Execute a single parameterized statement and return the number of rows
|
|
125
|
+
/// affected (the `CommandComplete` tag count). Parameters bind positionally
|
|
126
|
+
/// to `$1`, `$2`, ...
|
|
127
|
+
run: func(sql: string, params: list<value>) -> result<u64, error>;
|
|
128
|
+
|
|
129
|
+
/// Execute a single parameterized statement and return all rows.
|
|
130
|
+
query: func(sql: string, params: list<value>) -> result<list<row>, error>;
|
|
131
|
+
|
|
132
|
+
/// Execute a single parameterized statement and return only the first row,
|
|
133
|
+
/// or `none` when the statement produced no rows.
|
|
134
|
+
first: func(sql: string, params: list<value>) -> result<option<row>, error>;
|
|
135
|
+
|
|
136
|
+
/// `BEGIN`. Fails with `invalid-transaction-state` if a transaction is
|
|
137
|
+
/// already open on this connection; nest with `savepoint` instead.
|
|
138
|
+
begin: func() -> result<_, error>;
|
|
139
|
+
|
|
140
|
+
/// `COMMIT` the open transaction.
|
|
141
|
+
commit: func() -> result<_, error>;
|
|
142
|
+
|
|
143
|
+
/// `ROLLBACK` the open transaction.
|
|
144
|
+
rollback: func() -> result<_, error>;
|
|
145
|
+
|
|
146
|
+
/// `SAVEPOINT <name>`; usable for nested transactions. `name` must match
|
|
147
|
+
/// `[A-Za-z_][A-Za-z0-9_]*`.
|
|
148
|
+
savepoint: func(name: string) -> result<_, error>;
|
|
149
|
+
|
|
150
|
+
/// `RELEASE SAVEPOINT <name>`.
|
|
151
|
+
release-savepoint: func(name: string) -> result<_, error>;
|
|
152
|
+
|
|
153
|
+
/// `ROLLBACK TO SAVEPOINT <name>` followed by `RELEASE`, so the savepoint
|
|
154
|
+
/// is fully unwound.
|
|
155
|
+
rollback-to-savepoint: func(name: string) -> result<_, error>;
|
|
156
|
+
|
|
157
|
+
/// True while a transaction (or savepoint) is open on this connection.
|
|
158
|
+
/// Reported by the engine, including transactions issued through `exec`.
|
|
159
|
+
in-transaction: func() -> bool;
|
|
160
|
+
|
|
161
|
+
/// Rows affected by the most recent `run`/`exec` on this connection.
|
|
162
|
+
rows-affected: func() -> u64;
|
|
163
|
+
|
|
164
|
+
/// Explicitly close the connection. Subsequent calls fail with `closed`.
|
|
165
|
+
close: func() -> result<_, error>;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/// The world a consumer targets when it wants a Postgres database.
|
|
170
|
+
/// `wac plug` satisfies these imports with the `pglite-provider`
|
|
171
|
+
/// component's exports.
|
|
172
|
+
world imports {
|
|
173
|
+
import types;
|
|
174
|
+
import database;
|
|
175
|
+
}
|
package/dist/bindings.js
CHANGED
|
@@ -3,8 +3,9 @@ import { dirname, join } from 'node:path';
|
|
|
3
3
|
import { CommandFailure } from '@di-framework/cli-extension';
|
|
4
4
|
import ts from 'typescript';
|
|
5
5
|
import { asWitIdentifier } from './project.js';
|
|
6
|
+
const BINDING_DECORATOR_NAMES = new Set(['PlatformBinding', 'WasmCloudBinding']);
|
|
6
7
|
function importedDecoratorNames(source) {
|
|
7
|
-
const names = new Set(
|
|
8
|
+
const names = new Set(BINDING_DECORATOR_NAMES);
|
|
8
9
|
for (const statement of source.statements) {
|
|
9
10
|
if (!ts.isImportDeclaration(statement) || statement.importClause == null)
|
|
10
11
|
continue;
|
|
@@ -16,7 +17,7 @@ function importedDecoratorNames(source) {
|
|
|
16
17
|
continue;
|
|
17
18
|
for (const element of named.elements) {
|
|
18
19
|
const imported = (element.propertyName ?? element.name).text;
|
|
19
|
-
if (imported
|
|
20
|
+
if (BINDING_DECORATOR_NAMES.has(imported))
|
|
20
21
|
names.add(element.name.text);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -191,12 +192,12 @@ export function parseBindingsFile(filePath, catalog, applicationName) {
|
|
|
191
192
|
const [nameArg, optionsArg] = decorator.expression.arguments;
|
|
192
193
|
const name = stringLiteral(nameArg);
|
|
193
194
|
if (name === undefined) {
|
|
194
|
-
bindingsFailure('WASMCLOUD_BINDING_INVALID_NAME', `${statement.name.text} @
|
|
195
|
+
bindingsFailure('WASMCLOUD_BINDING_INVALID_NAME', `${statement.name.text} @PlatformBinding name must be a string literal`, { className: statement.name.text });
|
|
195
196
|
}
|
|
196
197
|
bindingName = name;
|
|
197
198
|
const parsed = objectLiteral(optionsArg);
|
|
198
199
|
if (optionsArg !== undefined && parsed === undefined) {
|
|
199
|
-
bindingsFailure('WASMCLOUD_BINDING_INVALID_OPTIONS', `${statement.name.text} @
|
|
200
|
+
bindingsFailure('WASMCLOUD_BINDING_INVALID_OPTIONS', `${statement.name.text} @PlatformBinding options must be an object literal of string values`, { className: statement.name.text });
|
|
200
201
|
}
|
|
201
202
|
if (parsed !== undefined) {
|
|
202
203
|
if (parsed.serviceName !== undefined && typeof parsed.serviceName !== 'string')
|
|
@@ -219,12 +220,12 @@ export function parseBindingsFile(filePath, catalog, applicationName) {
|
|
|
219
220
|
};
|
|
220
221
|
const secretProblem = rejectsPlaintextSecret(options.config);
|
|
221
222
|
if (secretProblem !== undefined) {
|
|
222
|
-
bindingsFailure('WASMCLOUD_BINDING_PLAINTEXT_SECRET', `${statement.name.text} @
|
|
223
|
+
bindingsFailure('WASMCLOUD_BINDING_PLAINTEXT_SECRET', `${statement.name.text} @PlatformBinding: ${secretProblem}`, { className: statement.name.text, name: bindingName });
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
}
|
|
226
227
|
if (bindingName === undefined) {
|
|
227
|
-
bindingsFailure('WASMCLOUD_BINDING_INVALID_NAME', `${statement.name.text} must be decorated with @
|
|
228
|
+
bindingsFailure('WASMCLOUD_BINDING_INVALID_NAME', `${statement.name.text} must be decorated with @PlatformBinding('name')`, { className: statement.name.text });
|
|
228
229
|
}
|
|
229
230
|
if (!/^[a-z][a-z0-9-]*$/.test(bindingName)) {
|
|
230
231
|
bindingsFailure('WASMCLOUD_BINDING_INVALID_NAME', `${statement.name.text} binding name "${bindingName}" must be a WIT identifier`, { className: statement.name.text, name: bindingName });
|
package/dist/build.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CliIo, type CommandResult } from '@di-framework/cli-extension';
|
|
2
2
|
import { type WasmcloudDeps } from './deps.js';
|
|
3
|
+
import { type ResolvedPglite } from './pglite.js';
|
|
3
4
|
import { type WasmcloudProject } from './project.js';
|
|
4
5
|
import { COMPONENT_MODEL, WASI_HTTP_INTERFACE, WASI_HTTP_VERSION, type WitLock, type WitRequirement } from './wit.js';
|
|
5
6
|
export { COMPONENT_MODEL, WASI_HTTP_INTERFACE, WASI_HTTP_VERSION };
|
|
@@ -15,11 +16,18 @@ export type BuildSummary = {
|
|
|
15
16
|
entry: string;
|
|
16
17
|
profile: string;
|
|
17
18
|
actors?: string[];
|
|
19
|
+
/** The composed PGlite provider: where it came from and, when pulled, its pinned image. */
|
|
20
|
+
pglite?: {
|
|
21
|
+
source: ResolvedPglite['source'];
|
|
22
|
+
image?: string;
|
|
23
|
+
path?: string;
|
|
24
|
+
};
|
|
18
25
|
};
|
|
19
26
|
export declare function requirementsForProject(project: WasmcloudProject, deps?: WasmcloudDeps): WitRequirement[];
|
|
20
27
|
/** The disposable `.di-framework/` build directory: WIT world, bundle, and manifests. */
|
|
21
28
|
export declare function buildComponent(project: WasmcloudProject, io: CliIo, deps: WasmcloudDeps, options?: {
|
|
22
29
|
guestLogging?: boolean;
|
|
30
|
+
deploy?: boolean;
|
|
23
31
|
}): Promise<BuildSummary>;
|
|
24
32
|
/**
|
|
25
33
|
* Stable logical version for deployment. ComponentizeJS snapshots can contain
|
package/dist/build.js
CHANGED
|
@@ -10,6 +10,7 @@ import { discoverScheduledJobs, renderCronAdapterModule, renderCronInvokerModule
|
|
|
10
10
|
import { DEFAULT_DEPS } from './deps.js';
|
|
11
11
|
import { renderGuestsModule } from './guests.js';
|
|
12
12
|
import { OCI_ARTIFACT_PLATFORM } from './oci.js';
|
|
13
|
+
import { DI_PGLITE_PACKAGE, DI_PGLITE_VERSION, PGLITE_WASM_FILE, resolvePgliteComponent, } from './pglite.js';
|
|
13
14
|
import { loadProject } from './project.js';
|
|
14
15
|
import { discoverQueueHandlers, isQueueWorkerProject } from './queues.js';
|
|
15
16
|
import { renderQueuesModule } from './queues-module.js';
|
|
@@ -145,7 +146,7 @@ async function composeProvider(project, deps, io, options) {
|
|
|
145
146
|
io.stdout.write(`Composing ${options.label} provider...\n`);
|
|
146
147
|
const compiler = options.namedImports ? deps.componentizeQjsPath() : undefined;
|
|
147
148
|
if (options.namedImports && !compiler)
|
|
148
|
-
throw new CommandFailure('WASMCLOUD_COMPILER_REQUIRED', 'Managed PostgreSQL
|
|
149
|
+
throw new CommandFailure('WASMCLOUD_COMPILER_REQUIRED', 'Managed PostgreSQL needs componentize-qjs 0.4.4-di.3 or newer for named-import composition', 3);
|
|
149
150
|
const result = await deps.runCaptured(compiler ?? wac, compiler
|
|
150
151
|
? ['compose', project.outputPath, '--definition', options.wasm, '-o', composed]
|
|
151
152
|
: ['plug', '--plug', options.wasm, project.outputPath, '-o', composed], { cwd: project.projectRoot, env: { ...process.env, PATH: envPath } });
|
|
@@ -155,7 +156,7 @@ async function composeProvider(project, deps, io, options) {
|
|
|
155
156
|
writeFileSync(project.outputPath, readFileSync(composed));
|
|
156
157
|
rmSync(composed, { force: true });
|
|
157
158
|
}
|
|
158
|
-
async function inspectComponentImports(project, requirements, deps) {
|
|
159
|
+
async function inspectComponentImports(project, requirements, deps, composedAway = []) {
|
|
159
160
|
if (!isWasmMagic(project.outputPath))
|
|
160
161
|
return;
|
|
161
162
|
const captured = await deps.runCaptured(requireNodeBinary(deps.nodeBinaryPath()), [deps.jcoCliPath(), 'wit', project.outputPath], { cwd: project.projectRoot });
|
|
@@ -163,6 +164,11 @@ async function inspectComponentImports(project, requirements, deps) {
|
|
|
163
164
|
throw new CommandFailure('WASMCLOUD_COMPONENT_IMPORTS_UNREADABLE', `Could not inspect component imports for ${project.applicationName}`, 3, { application: project.applicationName });
|
|
164
165
|
}
|
|
165
166
|
const wit = `${captured.stdout}\n${captured.stderr}`;
|
|
167
|
+
for (const provider of composedAway) {
|
|
168
|
+
if (wit.includes(`${provider.package}/`)) {
|
|
169
|
+
throw new CommandFailure(provider.failureCode, `Composed component still imports ${provider.package}; the provider was not plugged in`, 3, { application: project.applicationName, package: provider.package });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
166
172
|
for (const requirement of requirements) {
|
|
167
173
|
if (requirement.direction !== 'import')
|
|
168
174
|
continue;
|
|
@@ -174,6 +180,22 @@ async function inspectComponentImports(project, requirements, deps) {
|
|
|
174
180
|
}
|
|
175
181
|
}
|
|
176
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* The PGlite provider for a guest that imports `di-framework:pglite/database`. The config
|
|
185
|
+
* and the import must agree: the deploy marks the component exclusive and gives it storage
|
|
186
|
+
* from the config alone, so a config without the import (or the reverse) is refused.
|
|
187
|
+
*/
|
|
188
|
+
async function resolvePglite(project, imported, io, deps, deploy) {
|
|
189
|
+
if (imported && project.pglite === undefined) {
|
|
190
|
+
throw new CommandFailure('WASMCLOUD_PGLITE_NOT_CONFIGURED', `${project.applicationName} imports ${DI_PGLITE_PACKAGE}/database@${DI_PGLITE_VERSION}; pin the provider in di-framework.config.json: "pglite": { "image": "ghcr.io/di-framework/pglite-component@sha256:<digest>" }`, 2, { application: project.applicationName });
|
|
191
|
+
}
|
|
192
|
+
if (project.pglite === undefined)
|
|
193
|
+
return undefined;
|
|
194
|
+
if (!imported) {
|
|
195
|
+
throw new CommandFailure('WASMCLOUD_PGLITE_UNUSED', `di-framework.config.json configures "pglite", but ${project.applicationName} does not import ${DI_PGLITE_PACKAGE}/database@${DI_PGLITE_VERSION}; remove "pglite" or import it`, 2, { application: project.applicationName });
|
|
196
|
+
}
|
|
197
|
+
return resolvePgliteComponent(project.pglite, io, deps, project.projectRoot, { deploy });
|
|
198
|
+
}
|
|
177
199
|
/** The disposable `.di-framework/` build directory: WIT world, bundle, and manifests. */
|
|
178
200
|
export async function buildComponent(project, io, deps, options = {}) {
|
|
179
201
|
const generatedDirectory = join(project.projectRoot, '.di-framework');
|
|
@@ -281,6 +303,12 @@ export async function buildComponent(project, io, deps, options = {}) {
|
|
|
281
303
|
lock = buildWitLock(finalRequirements, join(generatedWit, 'deps'));
|
|
282
304
|
writeFileSync(join(generatedDirectory, 'wit.lock.json'), `${JSON.stringify(lock, null, 2)}\n`);
|
|
283
305
|
}
|
|
306
|
+
const needsPglite = finalRequirements.some((requirement) => requirement.package === DI_PGLITE_PACKAGE && requirement.direction === 'import');
|
|
307
|
+
const pglite = await resolvePglite(project, needsPglite, io, deps, options.deploy === true);
|
|
308
|
+
// Plug a private copy of the verified bytes: the shared cache may change after verification.
|
|
309
|
+
const pgliteWasm = join(generatedDirectory, PGLITE_WASM_FILE);
|
|
310
|
+
if (pglite !== undefined)
|
|
311
|
+
writeFileSync(pgliteWasm, pglite.bytes);
|
|
284
312
|
const componentize = await runComponentize(project, generatedWit, bundledJavaScript, deps);
|
|
285
313
|
if (componentize.exitCode !== 0) {
|
|
286
314
|
throw toolFailed(componentize.tool, componentize.exitCode);
|
|
@@ -294,13 +322,28 @@ export async function buildComponent(project, io, deps, options = {}) {
|
|
|
294
322
|
for (const provider of composedProviders) {
|
|
295
323
|
await composeComponentProvider(project, deps, io, provider, namedImports);
|
|
296
324
|
}
|
|
325
|
+
if (pglite !== undefined) {
|
|
326
|
+
await composeProvider(project, deps, io, {
|
|
327
|
+
label: `${DI_PGLITE_PACKAGE}@${DI_PGLITE_VERSION}`,
|
|
328
|
+
wasm: pgliteWasm,
|
|
329
|
+
namedImports,
|
|
330
|
+
failureCode: 'WASMCLOUD_PGLITE_COMPOSE_FAILED',
|
|
331
|
+
});
|
|
332
|
+
}
|
|
297
333
|
const composedPackages = new Set(composedProviders.map((provider) => provider.package));
|
|
334
|
+
if (pglite !== undefined)
|
|
335
|
+
composedPackages.add(DI_PGLITE_PACKAGE);
|
|
298
336
|
await inspectComponentImports(project, finalRequirements.filter((requirement) => !(requirement.direction === 'import' &&
|
|
299
337
|
(requirement.package === 'di-framework:sqlite' ||
|
|
300
|
-
composedPackages.has(requirement.package)))), deps
|
|
338
|
+
composedPackages.has(requirement.package)))), deps, pglite === undefined
|
|
339
|
+
? []
|
|
340
|
+
: [{ package: DI_PGLITE_PACKAGE, failureCode: 'WASMCLOUD_PGLITE_COMPOSE_FAILED' }]);
|
|
301
341
|
const deploymentDigest = canonicalBuildDigest(bundledJavaScript, generatedWit, join(generatedDirectory, 'oci-config.json'), lock, profile, needsSqliteCompose
|
|
302
342
|
? join(deps.assetsDirectory(), 'sqlite', 'di-framework-sqlite.wasm')
|
|
303
|
-
: undefined,
|
|
343
|
+
: undefined, [
|
|
344
|
+
...composedProviders.map((provider) => provider.wasm),
|
|
345
|
+
...(pglite === undefined ? [] : [pgliteWasm]),
|
|
346
|
+
]);
|
|
304
347
|
const artifactDigest = digestBytes(readFileSync(project.outputPath));
|
|
305
348
|
const summary = {
|
|
306
349
|
application: project.applicationName,
|
|
@@ -311,6 +354,15 @@ export async function buildComponent(project, io, deps, options = {}) {
|
|
|
311
354
|
entry: relative(project.projectRoot, project.entryPath),
|
|
312
355
|
profile,
|
|
313
356
|
...(actors.length > 0 ? { actors: actors.map((a) => a.actorName) } : {}),
|
|
357
|
+
...(pglite === undefined
|
|
358
|
+
? {}
|
|
359
|
+
: {
|
|
360
|
+
pglite: {
|
|
361
|
+
source: pglite.source,
|
|
362
|
+
...(pglite.image === undefined ? {} : { image: pglite.image }),
|
|
363
|
+
...(pglite.path === undefined ? {} : { path: pglite.path }),
|
|
364
|
+
},
|
|
365
|
+
}),
|
|
314
366
|
};
|
|
315
367
|
writeFileSync(join(generatedDirectory, 'build.json'), `${JSON.stringify({ schemaVersion: 1, ...summary }, null, 2)}\n`);
|
|
316
368
|
io.stdout.write(`Built ${summary.component}\n`);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { WasmcloudDeps } from '../deps.js';
|
|
2
2
|
import type { ClusterConnection } from '../target.js';
|
|
3
3
|
import type { BindingDocument, HostFailure, JsonPatchOp, WorkloadDocument } from './catalog.js';
|
|
4
|
+
/** True for a Secret the platform manages; a tenant user may not replace it. */
|
|
5
|
+
export declare function isPlatformManagedSecretName(name: string): boolean;
|
|
6
|
+
export { MANAGED_SECRET_DENIALS, SECRET_UPDATE_KEYS_MESSAGE } from '../secret-admission.js';
|
|
4
7
|
export type SignalView = {
|
|
5
8
|
success: number;
|
|
6
9
|
error: number;
|