@di-framework/cli-plugin-platform 6.1.1 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +259 -2
  2. package/dist/assets/http-adapter.js +6 -6
  3. package/dist/assets/sqlite/BUILD-INFO.txt +1 -1
  4. package/dist/assets/wit/deps/di-framework-pglite/package.wit +175 -0
  5. package/dist/bindings.js +7 -6
  6. package/dist/build.d.ts +31 -0
  7. package/dist/build.js +192 -12
  8. package/dist/console/catalog.js +2 -1
  9. package/dist/console/cluster.d.ts +3 -0
  10. package/dist/console/cluster.js +57 -4
  11. package/dist/control/auth.js +14 -2
  12. package/dist/deploy.d.ts +6 -0
  13. package/dist/deploy.js +27 -5
  14. package/dist/deps.js +1 -1
  15. package/dist/environment-names.d.ts +6 -0
  16. package/dist/environment-names.js +10 -0
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/node-compat/console.js +16 -1
  20. package/dist/node-compat/crypto-subtle.d.ts +6 -0
  21. package/dist/node-compat/crypto-subtle.js +41 -4
  22. package/dist/node-compat/crypto.d.ts +3 -2
  23. package/dist/node-compat/crypto.js +66 -17
  24. package/dist/node-compat/fs.d.ts +24 -2
  25. package/dist/node-compat/fs.js +137 -15
  26. package/dist/node-compat/node-errors.d.ts +20 -0
  27. package/dist/node-compat/node-errors.js +73 -0
  28. package/dist/node-compat/storage.d.ts +3 -3
  29. package/dist/node-compat/wasi-random.d.ts +21 -1
  30. package/dist/node-compat/wasi-random.js +45 -12
  31. package/dist/pglite-encryption.d.ts +79 -0
  32. package/dist/pglite-encryption.js +196 -0
  33. package/dist/pglite.d.ts +153 -0
  34. package/dist/pglite.js +423 -0
  35. package/dist/project.d.ts +18 -0
  36. package/dist/project.js +49 -1
  37. package/dist/secret-admission.d.ts +21 -0
  38. package/dist/secret-admission.js +29 -0
  39. package/dist/wit.d.ts +3 -0
  40. package/dist/wit.js +12 -0
  41. package/dist/workload.d.ts +51 -0
  42. package/dist/workload.js +320 -40
  43. 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
- `@WasmCloudBinding('name')` is discovered statically and added to the WIT requirement graph.
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,104 @@ 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`. The workload gets
310
+ the whole Secret as environment variables, and a workload without an environment label may
311
+ reference no other Secret, so it is also where an app keeps its own runtime secrets. Declare
312
+ those keys in `di-framework.config.json`:
313
+
314
+ ```json
315
+ {
316
+ "controlSecretKeys": ["ISSUER_URL", "AUTH_ACTIVE_PRIVATE_JWK", "DI_PGLITE_KEY"]
317
+ }
318
+ ```
319
+
320
+ A declared key must be an environment variable name. `DI_*` names belong to the framework, so
321
+ of those only `DI_PGLITE_KEY` and `DI_PGLITE_KEY_PREVIOUS` may be declared, and so may none of
322
+ the names the CLI renders into the workload's environment (`ACTOR_STORAGE_DIR`,
323
+ `QUEUE_DB_PATH`, `MIGRATION_DB_PATH`). Deploy never writes or reads values for these keys, and
324
+ refuses any key that is neither the CLI's nor declared.
325
+
326
+ **Once app keys exist, the app's tooling owns the control token.** A tenant developer cannot
327
+ read the Secret, so the tooling cannot keep the CLI's token value. It replaces the whole Secret
328
+ with:
329
+ - its own values;
330
+ - a freshly minted, non-empty `DI_CONTROL_TOKEN` (for example 32 random bytes, base64url);
331
+ - `DI_CONTROL_IDENTITY` set to the workload name.
332
+
333
+ It then rolls the workload, for example by setting a revision entry in the WorkloadDeployment's
334
+ environment config, as identity-server's `runtime-secrets.ts apply` does. From then on deploy
335
+ keeps that Secret, and token included, never rotates it. Rotate by re-running the tooling. The
336
+ platform issue
337
+ [di-framework/platform#203](https://github.com/di-framework/platform/issues/203) proposes a
338
+ separate `<workload>-secrets` so the control Secret can go back to being CLI-owned and rotated
339
+ on every deploy.
340
+
341
+ - A new Secret is created with the CLI's keys and a new random token.
342
+ - Tenant developers may create, update and delete Secrets but not read, list, watch or patch
343
+ them. The CLI never reads the Secret back for them; `kubectl auth can-i get` decides this
344
+ without sending a read. Every check below is a dry-run update (`?dryRun=All`, nothing
345
+ stored). It asks the platform's `tenant-secret-update` admission policy, which refuses an
346
+ update that drops a key, about key names only. With app keys declared, deploy:
347
+ 1. Checks that the policy protects the Secret. A dry run keeping only `DI_CONTROL_IDENTITY`
348
+ must be refused. If it is accepted, the policy does not apply to this caller (a write-only
349
+ identity that is not `di-user-*`, or a namespace outside the policy), or the Secret has no
350
+ token. A blind replace could then drop the app keys for good, so deploy stops with
351
+ `WASMCLOUD_CONTROL_SECRET_UNGUARDED` and writes nothing. As a result, a write-only caller
352
+ outside `di-user-*` (for example a CI ServiceAccount bound to the developer role) cannot
353
+ deploy a project that declares app keys. Deploy it as a tenant developer, or with an
354
+ identity that may read Secrets.
355
+ 2. Replaces the whole Secret with the CLI's keys and a new token. That succeeds, and rotates
356
+ the token, only while the Secret holds nothing else.
357
+ 3. If the replace is refused, sends a dry run with the CLI's keys and every declared key. If
358
+ the policy refuses that too, an undeclared key exists: deploy stops with "the control
359
+ Secret `<deployment>-control` has keys this CLI didn't write". Declare the keys, or
360
+ delete the Secret with `kubectl delete secret <deployment>-control` and redeploy.
361
+ 4. Leaves out `DI_CONTROL_TOKEN`, then `DI_CONTROL_IDENTITY`, in two more dry runs. Each must
362
+ be refused, which proves the key is stored. Otherwise the app tooling dropped it, and
363
+ deploy stops with `WASMCLOUD_CONTROL_SECRET_INCOMPLETE` rather than run a workload
364
+ without control credentials. The checks see key names only, so a present but empty
365
+ `DI_CONTROL_TOKEN` passes them. The deployed workload then has no usable token and
366
+ answers every control request (cron, queue and actor endpoints) with 401; it never falls
367
+ back to unauthenticated access. Make sure the tooling writes a non-empty token.
368
+ 5. Keeps the Secret as it is, token included, says "Kept control Secret
369
+ `<deployment>-control`", and renders no `DI_CONTROL_TOKEN_REVISION`.
370
+
371
+ These checks rely on `tenant-secret-update` having no dry-run exemption
372
+ ([di-framework/platform#204](https://github.com/di-framework/platform/issues/204)). Without
373
+ declared keys, deploy only replaces, as before.
374
+ - A caller who may read Secrets (a cluster admin) gets the Secret read. Deploy stops, naming
375
+ the keys, when one is neither the CLI's nor declared, instead of dropping it. Otherwise it
376
+ writes a new token with the declared keys carried over, conditional on the version it read,
377
+ and a concurrent change stops deploy with "changed while deploy was updating it; re-run
378
+ deploy". Nothing read is printed. Failures are scrubbed of every value read: values of four
379
+ characters or more wherever they appear, and shorter ones as whole tokens.
380
+ - Other failed writes show kubectl's reason, scrubbed of the token.
381
+ - When deploy writes a token, it rotates at that Secret write, before `kubectl apply`. The WorkloadDeployment
382
+ carries `DI_CONTROL_TOKEN_REVISION` (a digest of the token), so the deploy rolls the
383
+ workload onto the new token, but not at the same moment as its cron invokers: a CronJob
384
+ pod reads the Secret when it starts, so the invokers switch first and can get 401 from
385
+ the workload until its rollout is ready (the Job's retries normally absorb this).
386
+ - A deploy that fails after the Secret write (a failed `apply`, a rejected
387
+ WorkloadDeployment, a rollout that never becomes ready, or an interrupted deploy) leaves
388
+ the running workload on the old token while the invokers use the new one, so cron
389
+ invocations keep failing until the next successful deploy. A failed deploy's error then
390
+ ends with "the control token was rotated; re-run deploy to roll the workload onto it".
391
+ - `destroy` deletes the Secret by name, after the WorkloadDeployment, Service and CronJobs.
392
+ It deletes only `<deployment>-control`: Secrets are no longer part of its label-selected
393
+ delete (that would list them), so a Secret you labelled
394
+ `app.kubernetes.io/name=<deployment>` yourself stays; delete it by name.
395
+ - The console's credential reassignment replaces the named Secret with one holding only
396
+ `credential`; labels and annotations on it are not kept. It works only on a Secret whose
397
+ single key is `credential`: the console cannot read the Secret, so the platform's
398
+ `tenant-secret-update` admission policy refuses a replace that drops a key, and the
399
+ console answers 409. So does a Secret whose type is not `Opaque`, since the API server
400
+ refuses to change a Secret's type. Platform-managed Secrets (`di-binding-*`, `di-bs-*`,
401
+ `di-tenant-stock`, `di-platform-routes`) are refused with 403 before any request, and an
402
+ admission denial for a managed name also answers 403.
403
+
297
404
  The generated local target publishes through its loopback registry NodePort and puts the equivalent
298
405
  in-cluster registry address in the WorkloadDeployment. Both references use the same repository and
299
406
  stable canonical-input tag. An `http://` push URL or `insecure = true` adds ORAS `--plain-http` only
@@ -474,7 +581,7 @@ matching pool is unavailable. `hostgroup` defaults to `default`. These selectors
474
581
  existing host pools; application deployment does not provision them.
475
582
 
476
583
  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
584
+ Actors, queues, workers, PGlite guests, and `persistentStorage: true` deploy with the annotation
478
585
  `di-framework.dev/persistent-storage: "true"` (plus `di-framework.dev/storage-mount:
479
586
  "/data/actors"` for actors) and no volume, volume mount, or host path. The platform
480
587
  controller creates `<storageRoot>/di-tenants/<tenant uid>/workloads/<workload>`, shared by
@@ -501,6 +608,156 @@ to the implicit workload; they do not select user identity or Kubernetes namespa
501
608
 
502
609
  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
610
 
611
+ ### Embedded PostgreSQL (PGlite)
612
+
613
+ A guest that imports `di-framework:pglite/database@0.2.0` gets the
614
+ [PGlite provider](https://github.com/di-framework/platform/tree/main/platform/pglite-component)
615
+ plugged in after componentize (`wac plug`, like the SQLite provider). The database runs inside
616
+ the component: there is no `wasmcloud:postgres` binding, service, or connection string. Pin the
617
+ published provider by digest in `di-framework.config.json`:
618
+
619
+ ```json
620
+ {
621
+ "name": "orders",
622
+ "entry": "src/app.ts",
623
+ "pglite": {
624
+ "image": "ghcr.io/di-framework/pglite-component@sha256:<64 hex>",
625
+ "storageMount": "/data",
626
+ "dataDir": "/data/pglite"
627
+ }
628
+ }
629
+ ```
630
+
631
+ ```ts
632
+ import { open } from 'di-framework:pglite/database@0.2.0';
633
+
634
+ const db = open(process.env.DI_PGLITE_DATA_DIR ?? '/data/pglite', undefined);
635
+ ```
636
+
637
+ | Field | Default | Meaning |
638
+ | --- | --- | --- |
639
+ | `image` | required unless `wasm` is set | `<repository>@sha256:<digest>`, the manifest digest the platform publish job records. Tags are refused because they move. |
640
+ | `wasm` | none | A local provider build inside the project (symlinks resolved), used instead of `image` for offline development. Unverified; see below. |
641
+ | `storageMount` | `/data` | Guest preopen of the workload's persistent directory. Tenant targets accept `/data` or `/data/actors`. |
642
+ | `dataDir` | `<storageMount>/pglite` | Database root, at or under `storageMount`. The guest receives it as `DI_PGLITE_DATA_DIR`. |
643
+ | `encryption` | none | `{ "image": "ghcr.io/di-framework/pglite-encfs@sha256:<digest>" }` (or a local `wasm`): encrypt the data directory at rest; see [Encryption at rest](#encryption-at-rest). |
644
+
645
+ The build pulls the provider with `oras`: `oras manifest fetch`, then `oras blob fetch` of the
646
+ manifest's single `application/wasm` layer. It checks that the manifest hashes to the pinned
647
+ digest and the layer to the digest the manifest names, then caches both at
648
+ `oci/sha256/<digest>/` under `$DI_FRAMEWORK_CACHE_DIR` (default `$XDG_CACHE_HOME/di-framework`,
649
+ else `~/.cache/di-framework`). A cached entry is verified again on every build and pulled again
650
+ if it no longer matches, and stale `.pull-*` staging directories (older than a day) are removed.
651
+ The build plugs a private copy of the verified bytes (`.di-framework/di-framework-pglite.wasm`),
652
+ so a later change to the shared cache cannot reach the composed component. While the GHCR
653
+ package is private, run `oras login ghcr.io` first.
654
+
655
+ `DI_FRAMEWORK_PGLITE_WASM=/path/to/di-framework-pglite.wasm` overrides both `wasm` and `image`.
656
+ A local provider is only checked to be WebAssembly, never against the digest, and the build prints
657
+ a `Warning:` on stderr when it uses one. `platform deploy`, and any build with `CI` set, refuse a
658
+ local provider unless `DI_FRAMEWORK_ALLOW_LOCAL_PGLITE=1` is set. The deploy result reports the
659
+ provider's source: the digest pin, or the local path marked unverified. Don't commit `wasm`
660
+ next to `image`: it replaces the pin on every build.
661
+
662
+ The build fails when the guest imports the database without a `pglite` entry, or when a `pglite`
663
+ entry has no matching import, because the deploy renders the following from the config alone:
664
+
665
+ - The workload's single component gets `localResources.config`
666
+ `di-framework.dev/exclusive-instance: "true"`, so the tenant host runs at most one instance of
667
+ it. The key is never put on a WorkloadService, which admission rejects; a guest shaped as a
668
+ service deploys as a component. The opt-in takes effect only on the exclusive tenant host
669
+ image (`ghcr.io/di-framework/wash:2.8.0-wasi-tls-exclusive`, selected with the platform's
670
+ `tenantHostImage`); see the platform's `tenant-host/README.md`. On stock wash the key is
671
+ ignored, and a saturated or draining pool builds a second instance that opens the same data
672
+ directory. `platform deploy` warns on stderr when a tenant host group's pod image is not
673
+ tagged `*-exclusive`. On other targets, including the `storage` host group, it cannot see the
674
+ host and prints a note instead.
675
+ - Persistent storage, as for `persistentStorage: true`. Tenant targets get the
676
+ `di-framework.dev/persistent-storage: "true"` annotation, plus `di-framework.dev/storage-mount`
677
+ when `storageMount` is not `/data`. Other targets get a host path volume on the `storage` pool.
678
+ - `replicas: 1` and `deployPolicy: Recreate`. Other replica counts are refused.
679
+
680
+ #### Encryption at rest
681
+
682
+ `pglite.encryption` plugs an encrypting `wasi:filesystem` layer between the provider and the
683
+ host, so the data directory holds only ciphertext. The layer is composed into the provider
684
+ first, with an explicit `wac compose` (see below). That result is then plugged into the guest
685
+ exactly as an unencrypted provider is. The guest's own WASI imports still go straight to the
686
+ host.
687
+
688
+ ```json
689
+ {
690
+ "controlSecretKeys": ["DI_PGLITE_KEY"],
691
+ "pglite": {
692
+ "image": "ghcr.io/di-framework/pglite-component@sha256:<64 hex>",
693
+ "encryption": { "image": "ghcr.io/di-framework/pglite-encfs@sha256:<64 hex>" }
694
+ }
695
+ }
696
+ ```
697
+
698
+ - `encryption.image` is pinned by digest and pulled, verified and cached like the provider
699
+ (`oci/sha256/<digest>/di-framework-pglite-encfs.wasm`); the build plugs a private copy,
700
+ `.di-framework/di-framework-pglite-encfs.wasm`. `encryption.wasm` (a local build inside the
701
+ project) and `DI_FRAMEWORK_PGLITE_ENCFS_WASM` override it under the same rules as a local
702
+ provider: unverified, warned about, and refused by `platform deploy` and on CI unless
703
+ `DI_FRAMEWORK_ALLOW_LOCAL_PGLITE=1`.
704
+ - The layer reads its master key from `DI_PGLITE_KEY` (and, while rotating,
705
+ `DI_PGLITE_KEY_PREVIOUS`). The key reaches the guest only through the workload's control
706
+ Secret, so the build fails with `WASMCLOUD_PGLITE_KEY_UNDECLARED` unless `DI_PGLITE_KEY` is in
707
+ `controlSecretKeys` (see [Control Secret](#control-secret)). That check runs first, before
708
+ bundling or any pull. The CLI never writes or reads the
709
+ key: put it in `<deployment>-control` with your own tooling, and keep a copy, since losing it
710
+ loses the database.
711
+ - The layer must sit between the provider and the host, and `wac plug` cannot prove that.
712
+ `wac plug` silently skips an export whose type does not fit, and it exits 0 as long as
713
+ anything plugged. So the build does this instead:
714
+ 1. Reads both worlds with `jco wit`.
715
+ 2. Takes, for each provider import the layer exports, the export with the same name and
716
+ version, or else one on the same semver track the way `wac` matches them. That means the
717
+ same major from 1.0 on, the same minor for 0.x, and an exact match for 0.0.z and
718
+ pre-releases. Every `wasi:filesystem/*` import must get one.
719
+ 3. Writes `.di-framework/pglite-encryption.wac`. It instantiates the layer against the host
720
+ and passes each of those exports to the provider as a named instantiation argument.
721
+ 4. Composes it with `wac compose`, which type-checks every argument.
722
+
723
+ The build stops with `WASMCLOUD_PGLITE_ENCRYPTION_NOT_INTERPOSED`, carrying `wac`'s message
724
+ when there is one, if any of these holds:
725
+ - the layer misses a filesystem interface, is on another version track, or exports a type
726
+ the provider cannot use;
727
+ - the provider's world has an item the build cannot read as a versioned interface (such as a
728
+ plain-named `import fs: interface { … }`);
729
+ - the provider imports something that is neither wired to the layer nor on the host
730
+ pass-through allowlist (`wasi:io/*`, `wasi:clocks/*`, `wasi:random/*`, `wasi:cli/*`).
731
+
732
+ Build the layer for the WASI versions the pinned provider imports (`wasi:filesystem/*@0.2.9`
733
+ for provider 6.0.11). A missing `wac` or `jco` fails with `WASMCLOUD_WAC_REQUIRED` or
734
+ `WASMCLOUD_JCO_REQUIRED`.
735
+ - The layer must carry the platform's `di-framework:pglite-encfs` custom section
736
+ (`format=1 codec=aes-256-xts`). Without it the build stops with
737
+ `WASMCLOUD_PGLITE_ENCRYPTION_LAYER_UNMARKED`, which catches a no-op or debug layer pinned by
738
+ mistake or a stale local build. The build proves the wiring and the layer's identity, not the
739
+ cipher: the marker can be forged, so trust in what the layer actually does comes from the
740
+ digest pin of `encryption.image`.
741
+ - Only the engine has `DI_PGLITE_KEY` hidden. The layer filters it from the provider's
742
+ environment, but the guest's own `wasi:cli/environment` still comes from the host, so your
743
+ application code can read the key.
744
+ - The composed provider is `.di-framework/di-framework-pglite.encrypted.wasm`. The deployment
745
+ digest hashes the raw provider and layer bytes, not `wac`'s output, so changing either one
746
+ redeploys. The build and deploy results report the layer
747
+ (`PGlite: <image>, encrypted at rest by <layer>`).
748
+ - `encryption.image` must not pin the provider's repository or digest.
749
+
750
+ Give each database one owner. Members of one implicit workload share one storage directory,
751
+ mounted at each member's own `storageMount`. So `/data/pglite` under a `/data` mount and
752
+ `/data/actors/pglite` under a `/data/actors` mount are the same database. Members that both embed
753
+ PGlite need different `dataDir` values *relative to `storageMount`*. `platform deploy` refuses a
754
+ workload where two members resolve to the same root (`WASMCLOUD_PGLITE_DATA_DIR_CONFLICT`).
755
+
756
+ `platform dev` composes the provider but does not support PGlite yet. It mounts no storage
757
+ directory and sets no `DI_PGLITE_DATA_DIR`, so `open` fails locally. Exercise the database
758
+ against a deployed workload, or run the composed component with
759
+ `wasmtime run --dir ./data::/data` as the provider README shows.
760
+
504
761
  ### Managed PostgreSQL (upcoming release)
505
762
 
506
763
  `di-framework platform service create postgres --name orders --wait` provisions
@@ -34,7 +34,10 @@ function parseIdentities() {
34
34
  return { identities: singleTokenIdentities(), configured: true };
35
35
  }
36
36
  const identities = singleTokenIdentities();
37
- return { identities, configured: identities.length > 0 };
37
+ return { identities, configured: identities.length > 0 || isDeployed() };
38
+ }
39
+ function isDeployed() {
40
+ return process.env.DI_CONTROL_REJECT_FORWARDED === "1" || (process.env.DI_CONTROL_HTTP_HOST ?? "").trim() !== "" || process.env.DI_CONTROL_IDENTITY !== undefined || process.env.DI_CONTROL_TOKEN !== undefined;
38
41
  }
39
42
  function hasRequiredRole(identity, requiredRoles) {
40
43
  return !requiredRoles.some((role) => !identity.roles.includes(role) && !identity.roles.includes("admin"));
@@ -1287,9 +1290,6 @@ async function toWebRequest(incoming) {
1287
1290
  for (const [name, value] of incoming.getHeaders().copyAll()) {
1288
1291
  headers.append(name, decoder.decode(value));
1289
1292
  }
1290
- if (method === "GET" || method === "HEAD") {
1291
- return new Request(`${scheme}://${authority}${path}`, { method, headers });
1292
- }
1293
1293
  let bodyBytes;
1294
1294
  try {
1295
1295
  const consumed = WasiRequest.consumeBody(incoming, lowerFuture({ tag: "ok", val: undefined }, VOID_RESULT_FUTURE_TYPES));
@@ -1305,7 +1305,7 @@ async function toWebRequest(incoming) {
1305
1305
  return new Request(`${scheme}://${authority}${path}`, {
1306
1306
  method,
1307
1307
  headers,
1308
- body: bodyBytes
1308
+ body: method === "GET" || method === "HEAD" ? undefined : bodyBytes
1309
1309
  });
1310
1310
  }
1311
1311
  async function handleActorInvocation(request) {
@@ -1353,8 +1353,8 @@ async function fromWebResponse(response) {
1353
1353
  var handler = {
1354
1354
  async handle(incoming) {
1355
1355
  try {
1356
- ensureWasiEnvironment();
1357
1356
  const request = await toWebRequest(incoming);
1357
+ ensureWasiEnvironment();
1358
1358
  const isControlPath = isCronInvokeRequest(request) || isQueueControlRequest(request) || isActorInvocationRequest(request);
1359
1359
  if (isControlPath && !allowControlSurface(request)) {
1360
1360
  return await fromWebResponse(controlSurfaceNotFound());
@@ -1,6 +1,6 @@
1
1
  component: di-framework:sqlite@0.1.0
2
2
  profile: release
3
- built: 2026-10-09T03:29:59Z
3
+ built: 2026-10-12T20:41:07Z
4
4
  rustc: rustc 1.97.1 (8bab26f4f 2026-07-14)
5
5
  target: wasm32-wasip2
6
6
  wasi-sdk: 34.0
@@ -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(['WasmCloudBinding']);
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 === 'WasmCloudBinding')
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} @WasmCloudBinding name must be a string literal`, { className: 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} @WasmCloudBinding options must be an object literal of string values`, { className: 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} @WasmCloudBinding: ${secretProblem}`, { className: statement.name.text, name: bindingName });
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 @WasmCloudBinding('name')`, { className: statement.name.text });
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,41 @@ 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?: ComponentOrigin & {
21
+ /** The encryption layer plugged into the provider, from `pglite.encryption`. */
22
+ encryption?: ComponentOrigin;
23
+ };
24
+ };
25
+ /** Where a composed component came from: a digest pin (pulled or cached) or a local file. */
26
+ export type ComponentOrigin = {
27
+ source: ResolvedPglite['source'];
28
+ image?: string;
29
+ path?: string;
18
30
  };
19
31
  export declare function requirementsForProject(project: WasmcloudProject, deps?: WasmcloudDeps): WitRequirement[];
32
+ /**
33
+ * Composes the encryption layer into the provider and writes the result to `output`, which the
34
+ * build then plugs into the guest instead of the provider.
35
+ *
36
+ * `wac plug` silently skips a layer export whose name matches but whose type is not a subtype of
37
+ * the provider's import, and exits 0 when anything else plugged, so it cannot prove the layer is
38
+ * in the path. Instead the build reads both worlds with `jco wit`, plans which layer export each
39
+ * provider import takes (every `wasi:filesystem/*` import must have one), and composes a WAC
40
+ * document that passes each of them as a named instantiation argument (`wac compose`). wac
41
+ * type-checks every argument, so a layer that does not fit fails the build here rather than
42
+ * being bypassed. The document is kept at `.di-framework/pglite-encryption.wac`.
43
+ *
44
+ * Wiring cannot show that the layer encrypts: a pass-through layer wires the same way. So the
45
+ * layer must also carry the platform's `di-framework:pglite-encfs` custom section. That marker
46
+ * catches the wrong artifact (a no-op or debug layer, a stale local build); it is forgeable, so
47
+ * what the layer actually does rests on the digest pin.
48
+ */
49
+ export declare function encryptProvider(project: Pick<WasmcloudProject, 'projectRoot' | 'applicationName'>, deps: WasmcloudDeps, io: CliIo, provider: string, layer: string, output: string): Promise<void>;
20
50
  /** The disposable `.di-framework/` build directory: WIT world, bundle, and manifests. */
21
51
  export declare function buildComponent(project: WasmcloudProject, io: CliIo, deps: WasmcloudDeps, options?: {
22
52
  guestLogging?: boolean;
53
+ deploy?: boolean;
23
54
  }): Promise<BuildSummary>;
24
55
  /**
25
56
  * Stable logical version for deployment. ComponentizeJS snapshots can contain