@di-framework/cli-plugin-platform 0.0.1 → 6.0.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 +408 -0
- package/dist/actor-protocol.d.ts +4 -0
- package/dist/actor-protocol.js +162 -0
- package/dist/actors.d.ts +31 -0
- package/dist/actors.js +296 -0
- package/dist/args.d.ts +15 -0
- package/dist/args.js +66 -0
- package/dist/assets/http-adapter.js +876 -0
- package/dist/assets/platform/.gitignore.tmpl +6 -0
- package/dist/assets/platform/Pulumi.yaml.tmpl +6 -0
- package/dist/assets/platform/README.md +208 -0
- package/dist/assets/platform/index.ts.tmpl +2 -0
- package/dist/assets/platform/package.json.tmpl +18 -0
- package/dist/assets/platform/tsconfig.json +11 -0
- package/dist/assets/queue-adapter.js +60 -0
- package/dist/assets/sqlite/BUILD-INFO.txt +13 -0
- package/dist/assets/sqlite/SHA256SUMS +2 -0
- package/dist/assets/sqlite/di-framework-sqlite.wasm +0 -0
- package/dist/assets/sqlite/di-framework-sqlite.wit +337 -0
- package/dist/assets/wit/deps/LICENSE.md +8 -0
- package/dist/assets/wit/deps/di-framework-queues/package.wit +18 -0
- package/dist/assets/wit/deps/di-framework-sqlite/package.wit +211 -0
- package/dist/assets/wit/deps/wasi-cli/package.wit +70 -0
- package/dist/assets/wit/deps/wasi-clocks/package.wit +42 -0
- package/dist/assets/wit/deps/wasi-config/package.wit +15 -0
- package/dist/assets/wit/deps/wasi-filesystem/package.wit +184 -0
- package/dist/assets/wit/deps/wasi-http/package.wit +170 -0
- package/dist/assets/wit/deps/wasi-random/package.wit +17 -0
- package/dist/assets/wit/deps/wasi-sockets/package.wit +105 -0
- package/dist/assets/wit/deps/wasi-tls/package.wit +26 -0
- package/dist/assets/wit/deps/wasmcloud-blobstore/package.wit +153 -0
- package/dist/assets/wit/deps/wasmcloud-keyvalue/package.wit +370 -0
- package/dist/assets/wit/deps/wasmcloud-messaging/package.wit +125 -0
- package/dist/assets/wit/deps/wasmcloud-postgres/package.wit +435 -0
- package/dist/assets/wit/deps/wasmcloud-secrets/package.wit +80 -0
- package/dist/async-transform.d.ts +3 -0
- package/dist/async-transform.js +60 -0
- package/dist/bindings.d.ts +34 -0
- package/dist/bindings.js +307 -0
- package/dist/build.d.ts +29 -0
- package/dist/build.js +325 -0
- package/dist/command.d.ts +3 -0
- package/dist/command.js +141 -0
- package/dist/control/auth.d.ts +18 -0
- package/dist/control/auth.js +89 -0
- package/dist/control/cron.d.ts +7 -0
- package/dist/control/cron.js +86 -0
- package/dist/control/index.d.ts +4 -0
- package/dist/control/index.js +4 -0
- package/dist/control/network.d.ts +12 -0
- package/dist/control/network.js +49 -0
- package/dist/control/queues.d.ts +15 -0
- package/dist/control/queues.js +77 -0
- package/dist/cron.d.ts +26 -0
- package/dist/cron.js +239 -0
- package/dist/deploy.d.ts +29 -0
- package/dist/deploy.js +57 -0
- package/dist/deps.d.ts +96 -0
- package/dist/deps.js +303 -0
- package/dist/destroy.d.ts +3 -0
- package/dist/destroy.js +24 -0
- package/dist/dev-runner.d.ts +24 -0
- package/dist/dev-runner.js +83 -0
- package/dist/dev.d.ts +8 -0
- package/dist/dev.js +76 -0
- package/dist/discovery.d.ts +15 -0
- package/dist/discovery.js +182 -0
- package/dist/doctor.d.ts +8 -0
- package/dist/doctor.js +82 -0
- package/dist/guests.d.ts +9 -0
- package/dist/guests.js +56 -0
- package/dist/host-interface.d.ts +29 -0
- package/dist/host-interface.js +142 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +39 -0
- package/dist/kubernetes.d.ts +9 -0
- package/dist/kubernetes.js +17 -0
- package/dist/managed-bindings.d.ts +9 -0
- package/dist/managed-bindings.js +150 -0
- package/dist/manifest.d.ts +36 -0
- package/dist/manifest.js +257 -0
- package/dist/namespace.d.ts +2 -0
- package/dist/namespace.js +4 -0
- package/dist/node-compat/async-hooks.d.ts +29 -0
- package/dist/node-compat/async-hooks.js +80 -0
- package/dist/node-compat/bootstrap.d.ts +1 -0
- package/dist/node-compat/bootstrap.js +9 -0
- package/dist/node-compat/bytes.d.ts +7 -0
- package/dist/node-compat/bytes.js +41 -0
- package/dist/node-compat/crypto-hash.d.ts +27 -0
- package/dist/node-compat/crypto-hash.js +108 -0
- package/dist/node-compat/crypto-subtle.d.ts +59 -0
- package/dist/node-compat/crypto-subtle.js +288 -0
- package/dist/node-compat/crypto.d.ts +136 -0
- package/dist/node-compat/crypto.js +142 -0
- package/dist/node-compat/dgram.d.ts +49 -0
- package/dist/node-compat/dgram.js +197 -0
- package/dist/node-compat/env.d.ts +6 -0
- package/dist/node-compat/env.js +88 -0
- package/dist/node-compat/fetch-runtime.d.ts +80 -0
- package/dist/node-compat/fetch-runtime.js +314 -0
- package/dist/node-compat/fs.d.ts +84 -0
- package/dist/node-compat/fs.js +285 -0
- package/dist/node-compat/http-parser.d.ts +40 -0
- package/dist/node-compat/http-parser.js +185 -0
- package/dist/node-compat/http.d.ts +130 -0
- package/dist/node-compat/http.js +688 -0
- package/dist/node-compat/https.d.ts +28 -0
- package/dist/node-compat/https.js +88 -0
- package/dist/node-compat/module.d.ts +11 -0
- package/dist/node-compat/module.js +35 -0
- package/dist/node-compat/net.d.ts +119 -0
- package/dist/node-compat/net.js +441 -0
- package/dist/node-compat/process.d.ts +25 -0
- package/dist/node-compat/process.js +63 -0
- package/dist/node-compat/runtime-application.d.ts +4 -0
- package/dist/node-compat/runtime-application.js +24 -0
- package/dist/node-compat/seed-virtual.d.ts +6 -0
- package/dist/node-compat/seed-virtual.js +6 -0
- package/dist/node-compat/seed.d.ts +20 -0
- package/dist/node-compat/seed.js +106 -0
- package/dist/node-compat/socket-address.d.ts +35 -0
- package/dist/node-compat/socket-address.js +162 -0
- package/dist/node-compat/timers.d.ts +32 -0
- package/dist/node-compat/timers.js +96 -0
- package/dist/node-compat/tls.d.ts +57 -0
- package/dist/node-compat/tls.js +290 -0
- package/dist/node-compat/wasi-random.d.ts +2 -0
- package/dist/node-compat/wasi-random.js +25 -0
- package/dist/node-compat/wasi-sockets.d.ts +47 -0
- package/dist/node-compat/wasi-sockets.js +134 -0
- package/dist/oci.d.ts +9 -0
- package/dist/oci.js +9 -0
- package/dist/paths.d.ts +7 -0
- package/dist/paths.js +13 -0
- package/dist/platform-init.d.ts +13 -0
- package/dist/platform-init.js +265 -0
- package/dist/platform.d.ts +22 -0
- package/dist/platform.js +170 -0
- package/dist/project.d.ts +39 -0
- package/dist/project.js +130 -0
- package/dist/publish.d.ts +15 -0
- package/dist/publish.js +57 -0
- package/dist/pulumi.d.ts +4 -0
- package/dist/pulumi.js +27 -0
- package/dist/queues-module.d.ts +4 -0
- package/dist/queues-module.js +89 -0
- package/dist/queues.d.ts +16 -0
- package/dist/queues.js +167 -0
- package/dist/registry.d.ts +16 -0
- package/dist/registry.js +27 -0
- package/dist/service.d.ts +162 -0
- package/dist/service.js +678 -0
- package/dist/support.d.ts +14 -0
- package/dist/support.js +37 -0
- package/dist/target.d.ts +18 -0
- package/dist/target.js +45 -0
- package/dist/toml.d.ts +6 -0
- package/dist/toml.js +245 -0
- package/dist/wash-dev.d.ts +18 -0
- package/dist/wash-dev.js +80 -0
- package/dist/wit.d.ts +76 -0
- package/dist/wit.js +248 -0
- package/dist/workload-members.d.ts +12 -0
- package/dist/workload-members.js +136 -0
- package/dist/workload.d.ts +45 -0
- package/dist/workload.js +457 -0
- package/package.json +55 -8
- package/src/index.ts +0 -2
package/README.md
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
# @di-framework/cli-plugin-platform
|
|
2
|
+
|
|
3
|
+
di-framework CLI extension for targeting [wasmCloud](https://wasmcloud.com): build a DI Framework
|
|
4
|
+
HTTP app into a WASI 0.3 WebAssembly component, serve it locally, and deploy it from a workspace
|
|
5
|
+
manifest.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
di-framework extensions install platform
|
|
9
|
+
|
|
10
|
+
di-framework platform build # bundle + jco componentize → dist/<name>.wasm
|
|
11
|
+
di-framework platform dev # build, then serve locally (wasmtime by default)
|
|
12
|
+
di-framework platform deploy # nearest project, default target
|
|
13
|
+
di-framework platform deploy greeter # named project anywhere in the workspace
|
|
14
|
+
di-framework platform deploy greeter --target development
|
|
15
|
+
di-framework platform destroy greeter
|
|
16
|
+
di-framework platform cluster init # generate deploy/platform + local target
|
|
17
|
+
di-framework platform cluster up local --yes # start the generated platform
|
|
18
|
+
di-framework platform cluster destroy local --yes
|
|
19
|
+
di-framework platform doctor # project + toolchain readiness checks
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Run these commands directly. Do not wrap them in `package.json` scripts.
|
|
23
|
+
|
|
24
|
+
## Project convention
|
|
25
|
+
|
|
26
|
+
A component project is marked by `di-framework.config.json`:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{ "name": "my-app", "entry": "src/app.ts", "output": "dist/my-app.wasm" }
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Named wasmCloud host-interface bindings live in `src/bindings.ts` (override with `"bindings"`).
|
|
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.
|
|
35
|
+
The binding name selects its configuration overlay and normally becomes `hostInterfaces[].name`.
|
|
36
|
+
For `wasmcloud:postgres`, `wasmcloud:keyvalue`, `wasmcloud:blobstore`,
|
|
37
|
+
`wasmcloud:messaging`, and `wasmcloud:secrets`, host declarations omit the name to
|
|
38
|
+
select the provider route that links QuickJS imports. The generated guest world uses unlabeled
|
|
39
|
+
`import pkg/iface@version` statements because `jco --backend qjs` cannot encode
|
|
40
|
+
`import name: pkg/iface` (`cm-implements`). Secret values are never taken from source;
|
|
41
|
+
`secretFrom` defaults to `<application>-<binding>`. Unnamed bindings such as config and
|
|
42
|
+
outgoing HTTP retain their overlays through the binding class that contributed the requirements.
|
|
43
|
+
|
|
44
|
+
Host declarations reflect the interfaces advertised by the runtime: key-value `types`
|
|
45
|
+
is linked internally, and the core links `wasi:http/client`. Both remain in the guest WIT
|
|
46
|
+
imports but are omitted from host discovery. HTTP ingress and outgoing requirements
|
|
47
|
+
share one unnamed host declaration per version, retaining configuration from both.
|
|
48
|
+
Outgoing requests also require the workload component’s `localResources.allowedHosts`
|
|
49
|
+
to allow the destination; the binding itself does not grant egress access.
|
|
50
|
+
|
|
51
|
+
Build writes `.di-framework/guests.js` with real WIT `import * as` specifiers and installs
|
|
52
|
+
those modules on `globalThis` before the application runs, which is how
|
|
53
|
+
`@di-framework/bindings` constructors receive the guest.
|
|
54
|
+
|
|
55
|
+
The configured `name` is the only project identity. The extension owns the WebAssembly/WASI
|
|
56
|
+
boundary: it records WIT requirements (the HTTP adapter exports `wasi:http/handler@0.3.0` today),
|
|
57
|
+
generates one world and a `wit.lock.json` from that graph, bundles the entry behind a WASI-HTTP ↔
|
|
58
|
+
Web Fetch adapter, and componentizes with `@di-framework/componentize-qjs` (a wasmtime-48
|
|
59
|
+
fork of componentize-qjs 0.4.4 that can stub imported `async func`s such as
|
|
60
|
+
`wasmcloud:postgres@0.2.0`). Set `DI_FRAMEWORK_COMPONENTIZE_QJS` to override the
|
|
61
|
+
resolved CLI.
|
|
62
|
+
|
|
63
|
+
The bootstrap installs text encoding and Fetch globals before evaluating application
|
|
64
|
+
imports, including Node modules with module-level constants. `node:timers` and global
|
|
65
|
+
`setTimeout`, `setInterval`, and `setImmediate` use the WASI monotonic clock. Timer
|
|
66
|
+
handles support cancellation, refresh, and ref/unref flags; process-lifetime ref
|
|
67
|
+
semantics do not apply to an invocation-driven component.
|
|
68
|
+
|
|
69
|
+
`node:async_hooks` supplies context scopes and binding. The bundler lowers async
|
|
70
|
+
functions and `for await` loops into Promise continuations, whose callbacks retain
|
|
71
|
+
the calling context. Timer callbacks also retain context. Native async-generator
|
|
72
|
+
bodies and dynamically evaluated async code are not instrumented by this transform.
|
|
73
|
+
|
|
74
|
+
A workload must explicitly permit WASI DNS lookups. Add hostnames or wildcard suffixes
|
|
75
|
+
to the project configuration, for example:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"name": "socket-app",
|
|
80
|
+
"entry": "src/app.ts",
|
|
81
|
+
"allowedIpNameLookups": ["echo.wasmcloud.svc.cluster.local"]
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The deployer writes these names under the component's
|
|
86
|
+
`localResources.allowedIpNameLookups`. Omission keeps the host's default denial;
|
|
87
|
+
it does not implicitly grant unrestricted DNS access.
|
|
88
|
+
|
|
89
|
+
Guest JS keeps the framework's Node contract. The bundler runs [unenv](https://github.com/unjs/unenv)
|
|
90
|
+
`nodeCompat` plus a wasmCloud preset: `node:path`, `Buffer`, and the rest of
|
|
91
|
+
the Node builtin map come from unenv; `node:fs` is an in-memory filesystem (with `ENOENT`),
|
|
92
|
+
`process.env` / `process.cwd()` are guest-shaped (not the host process), and `createRequire` throws
|
|
93
|
+
`MODULE_NOT_FOUND`. `node:net` and `node:dgram` overlay WASI 0.3 `wasi:sockets` (`tcp-socket` /
|
|
94
|
+
`udp-socket` / `ip-name-lookup`) so `@di-framework/socket`'s Node TCP/UDP adapters run unchanged.
|
|
95
|
+
`node:crypto` overlays `wasi:random@0.3.0` plus guest hashes and the Web Crypto subset used by
|
|
96
|
+
socket security (`createHash` / `createHmac` / `randomBytes` / `randomUUID` / `subtle` HMAC, HKDF,
|
|
97
|
+
AES-GCM, ECDH P-256). `node:http` is HTTP/1.1 on that TCP overlay (`createServer`, `request` /
|
|
98
|
+
`get`, `'upgrade'`) so the Node WebSocket adapter (`ws`) can handshake. Those WIT imports are added
|
|
99
|
+
to the guest world only when the bundle actually uses them; they are runtime WASI, not wasmCloud
|
|
100
|
+
`hostInterfaces`. `node:tls` supplies client `connect` / `TLSSocket` (including an existing
|
|
101
|
+
`node:net` socket for STARTTLS) through the host's `wasi:tls/client@0.3.0-draft` encryption
|
|
102
|
+
and decryption streams. `node:https` supplies HTTP/1.1 `request` / `get` and an Agent
|
|
103
|
+
that carries connection options; requests wait for verified `secureConnect` before sending.
|
|
104
|
+
`child_process` stays an unenv mock. Config files from the project (`*.json` / `*.yaml` / `*.toml` / `.env`) are
|
|
105
|
+
seeded into that filesystem at componentize time. Do not put secrets in those files. Stock jco 1.32.1 / componentize-qjs 0.4.4 uses wasmtime 47,
|
|
106
|
+
which stubs unknown imports with sync `func_new` and fails at wizer with
|
|
107
|
+
`type mismatch with async`. Sync imports such as `wasi:config@0.2.0-rc.1` also
|
|
108
|
+
componentize with stock jco and run on `wasmtime serve -S config`. Build state
|
|
109
|
+
lives in the disposable `.di-framework/` directory.
|
|
110
|
+
|
|
111
|
+
TLS requires a host with the opt-in `wasi-tls` feature, such as a TLS-enabled
|
|
112
|
+
`wash-runtime` build, or Wasmtime 48 with `-S p3=y,tls=y,inherit-network=y,allow-ip-name-lookup=y`.
|
|
113
|
+
The draft WIT is pinned to the wasmCloud interface; importing TLS or HTTPS adds it to the
|
|
114
|
+
component world automatically. `platform dev` enables TLS and outbound network access
|
|
115
|
+
automatically when using Wasmtime for a component that imports TLS. Other runners need
|
|
116
|
+
their own TLS-enabled host configuration. A host without TLS cannot instantiate that component.
|
|
117
|
+
See [wasmCloud host TLS configuration](https://wasmcloud.com/docs/runtime/building-custom-hosts/#tls-for-wasitls-components).
|
|
118
|
+
|
|
119
|
+
Certificate chain and server-name verification are mandatory and use the host's trust store.
|
|
120
|
+
Use `servername` when connecting by address to a DNS-named service, and configure private
|
|
121
|
+
CA trust on the host, including in local development. Guest `ca` / client certificates,
|
|
122
|
+
`rejectUnauthorized: false`, custom identity checks, TLS versions/ciphers, ALPN, sessions,
|
|
123
|
+
and certificate inspection are unsupported and throw explicit errors. Server-side
|
|
124
|
+
`tls.createServer` / `https.createServer` are unsupported; incoming HTTPS terminates at
|
|
125
|
+
the host ingress. This is a client subset, without connection pooling or HTTP/2.
|
|
126
|
+
Use `tls.connect(options)` rather than calling `.connect()` on a `TLSSocket`.
|
|
127
|
+
|
|
128
|
+
HTTPS responses without `Content-Length` or chunked encoding finish only when the
|
|
129
|
+
peer closes the connection. If the peer keeps it open, the response can wait indefinitely.
|
|
130
|
+
Set `options.timeout` and destroy the request in its `timeout` handler; the timeout
|
|
131
|
+
is an inactivity notification and does not cancel the request automatically:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { get } from 'node:https';
|
|
135
|
+
|
|
136
|
+
const req = get('https://example.com/', { timeout: 10_000 }, (res) => {
|
|
137
|
+
res.on('data', (chunk) => console.log(chunk.toString()));
|
|
138
|
+
res.on('error', (error) => console.error(error));
|
|
139
|
+
});
|
|
140
|
+
req.on('timeout', () => req.destroy(new Error('HTTPS request timed out')));
|
|
141
|
+
req.on('error', (error) => console.error(error));
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Use a separate deadline timer if the entire operation must finish within a fixed
|
|
145
|
+
time, including a peer that keeps sending data without closing the response.
|
|
146
|
+
|
|
147
|
+
Run `DI_WASI_TLS_SMOKE=1 bun test tests/node-compat-tls-native.test.ts` from this package
|
|
148
|
+
to compile and exercise both clients against real Wasmtime TLS. This opt-in check needs
|
|
149
|
+
the componentizer, Wasmtime 48, OpenSSL, and network access to `example.com`; it also
|
|
150
|
+
starts a temporary local HTTPS server to confirm that an untrusted certificate is rejected.
|
|
151
|
+
|
|
152
|
+
Package versions are independent of the component-model preview: a WASI 0.3 guest may
|
|
153
|
+
still import `wasmcloud:*` packages at their own versions.
|
|
154
|
+
|
|
155
|
+
Local `platform dev` uses `wasmtime serve -S cli -S p3 -S config` when wasmtime 46+ is on
|
|
156
|
+
PATH, then `wash dev`, then `jco serve`. A guest that imports `wasmcloud:*` selects `wash`
|
|
157
|
+
even when wasmtime is present. Set `DI_FRAMEWORK_WASMCLOUD_DEV_RUNNER` to
|
|
158
|
+
`wasmtime`, `wash`, or `jco` to pin one. Wasmtime hosts WASI HTTP and unlabeled
|
|
159
|
+
`wasi:config` locally (`-S config-var=key=value` to seed values). wasmCloud-only imports
|
|
160
|
+
such as `wasmcloud:postgres` still need `wash` or a wasmCloud host.
|
|
161
|
+
|
|
162
|
+
`wash` 2.5.x has no `--address` flag. The extension writes
|
|
163
|
+
`.di-framework/wash-dev.yaml` (`dev.address`, `host_interfaces`,
|
|
164
|
+
`wasm_proposals: [component-model-async]`) and runs `wash dev --user-config` against it.
|
|
165
|
+
Set `WASMCLOUD_POSTGRES_URL` to populate `dev.postgres_url`; never put secrets in source.
|
|
166
|
+
|
|
167
|
+
## Deployment manifest
|
|
168
|
+
|
|
169
|
+
Deployment topology lives in `di-framework.deploy.toml` at the workspace root. The CLI finds it by
|
|
170
|
+
walking upward from the current directory. The file describes **targets**, not applications: there
|
|
171
|
+
is no `apps` table, and projects may live in any directory layout.
|
|
172
|
+
|
|
173
|
+
```toml
|
|
174
|
+
default-target = "local"
|
|
175
|
+
|
|
176
|
+
[targets.local]
|
|
177
|
+
platform = "deploy/platform"
|
|
178
|
+
stack = "dev"
|
|
179
|
+
|
|
180
|
+
[targets.development]
|
|
181
|
+
kubeconfig = "${KUBECONFIG}"
|
|
182
|
+
context = "team-development"
|
|
183
|
+
namespace = "wasmcloud"
|
|
184
|
+
|
|
185
|
+
[targets.development.registry]
|
|
186
|
+
push = "https://registry.example.com/team"
|
|
187
|
+
pull = "registry.internal.example.com/team"
|
|
188
|
+
insecure = false
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
- `di-framework platform deploy` with no name uses the nearest `di-framework.config.json`.
|
|
192
|
+
- `di-framework platform deploy greeter` recursively discovers projects (skipping `.git`,
|
|
193
|
+
`node_modules`, `.di-framework`, and generated output by default) and matches the configured
|
|
194
|
+
`name`. Duplicate names fail with every conflicting path.
|
|
195
|
+
- `${VAR}` interpolation fails if the variable is unset or empty. Do not put credentials in the
|
|
196
|
+
manifest.
|
|
197
|
+
|
|
198
|
+
### Managed Pulumi target
|
|
199
|
+
|
|
200
|
+
From the workspace root, generate a self-contained local platform (k0s, a local OCI registry, and
|
|
201
|
+
the wasmCloud operator) from templates shipped with this extension:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
di-framework platform cluster init
|
|
205
|
+
di-framework platform cluster up local --yes
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`platform init` writes `deploy/platform` and creates or updates `di-framework.deploy.toml` so
|
|
209
|
+
`local` is a managed target (`platform = "deploy/platform"`, `stack = "dev"`). Existing files are
|
|
210
|
+
left alone unless you pass `--force`. The command prints the exact start command when it finishes.
|
|
211
|
+
Platform deploy runs the package-manager-neutral `pulumi install` command automatically, so the
|
|
212
|
+
generated project works immediately in a blank consumer workspace without a root workspace entry
|
|
213
|
+
or a manual install inside `deploy/platform`.
|
|
214
|
+
|
|
215
|
+
The generated Pulumi project provisions only platform concerns. It has workspace- and stack-scoped
|
|
216
|
+
Docker names, a dedicated network, persistent k0s state/log volumes, pinned images and chart,
|
|
217
|
+
readiness checks, and loopback-only high ports. It must not contain application names, component
|
|
218
|
+
builds, application Services, or WorkloadDeployments. The defaults are Kubernetes `26443`, registry
|
|
219
|
+
`25000`, and HTTP `28180`; set `apiPort`, `registryPort`, or `httpPort` with `pulumi config set` in
|
|
220
|
+
`deploy/platform` to choose another distinct port from 1024 through 65535.
|
|
221
|
+
|
|
222
|
+
The CLI reads a small output contract from `pulumi stack output --json`:
|
|
223
|
+
|
|
224
|
+
| Output | Required | Meaning |
|
|
225
|
+
| --- | --- | --- |
|
|
226
|
+
| `kubeconfig` | yes | kubeconfig YAML or a filesystem path |
|
|
227
|
+
| `namespace` | yes | Kubernetes namespace for workloads |
|
|
228
|
+
| `registry` | yes | legacy string shorthand, or `{ push, pull, insecure }` transport object |
|
|
229
|
+
| `context` | no | kubectl context |
|
|
230
|
+
| `endpoints.http` / `endpoints.kubernetes` / `endpoints.registry` | no | optional URLs |
|
|
231
|
+
|
|
232
|
+
Provision and tear down that stack explicitly:
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
di-framework platform cluster up local --yes
|
|
236
|
+
di-framework platform cluster destroy local --yes
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Application `destroy` never runs `pulumi destroy`.
|
|
240
|
+
|
|
241
|
+
The generated local target publishes through its loopback registry NodePort and puts the equivalent
|
|
242
|
+
in-cluster registry address in the WorkloadDeployment. Both references use the same repository and
|
|
243
|
+
stable canonical-input tag. An `http://` push URL or `insecure = true` adds ORAS `--plain-http` only
|
|
244
|
+
for that target; TLS remains the default everywhere else.
|
|
245
|
+
|
|
246
|
+
### Existing cluster
|
|
247
|
+
|
|
248
|
+
When kubeconfig and a registry are already available, declare an external target with only access
|
|
249
|
+
information (as `development` above) and deploy:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
export KUBECONFIG="$HOME/.kube/config"
|
|
253
|
+
di-framework platform deploy greeter --target development
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Application deploy
|
|
257
|
+
|
|
258
|
+
For the selected project the extension:
|
|
259
|
+
|
|
260
|
+
1. Builds the component.
|
|
261
|
+
2. Publishes it with `oras` from the project root using project-relative artifact paths and a stable
|
|
262
|
+
canonical-input reference (`<registry>/<wit-name>:sha256-<deployment-digest>`). The actual
|
|
263
|
+
component-byte digest is calculated and reported separately because ComponentizeJS snapshots may
|
|
264
|
+
vary byte-for-byte for identical inputs.
|
|
265
|
+
3. Derives a wasmCloud `WorkloadDeployment` and Kubernetes `Service` (written under `.di-framework/deploy/`, not checked in).
|
|
266
|
+
4. Configures `wasi:http/handler@0.3.0` with the project name as its host, applies the resources,
|
|
267
|
+
and waits for current `Ready=True` or compatible older readiness schemas.
|
|
268
|
+
|
|
269
|
+
For the generated local platform the result reports the HTTP URL and required Host header. It is
|
|
270
|
+
directly reachable without `kubectl port-forward`, for example:
|
|
271
|
+
|
|
272
|
+
```sh
|
|
273
|
+
curl -H 'Host: greeter' http://127.0.0.1:28180/
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Demonstration layout
|
|
277
|
+
|
|
278
|
+
A complete workspace is in [`examples/workspace`](./examples/workspace): `deploy/platform` plus
|
|
279
|
+
projects at `services/greeter` and `nested/deep/echo`. Copy that tree or start from the TOML
|
|
280
|
+
above.
|
|
281
|
+
|
|
282
|
+
The manifest contract for extensions is documented in
|
|
283
|
+
[`@di-framework/cli-extension`](https://www.npmjs.com/package/@di-framework/cli-extension).
|
|
284
|
+
|
|
285
|
+
## Live integration test
|
|
286
|
+
|
|
287
|
+
The opt-in test packs the CLI and extension dependencies, installs those tarballs in a blank
|
|
288
|
+
temporary workspace, and runs the full platform/application lifecycle against Docker:
|
|
289
|
+
|
|
290
|
+
```sh
|
|
291
|
+
DI_FRAMEWORK_WASMCLOUD_LIVE=1 bun test packages/cli-plugin-platform/tests/live-workflow.test.ts
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
It requires Docker, Pulumi, kubectl, ORAS, npm, Bun, and curl. The test selects unused loopback
|
|
295
|
+
ports and removes its scoped platform resources in a `finally` cleanup.
|
|
296
|
+
|
|
297
|
+
## Actor Integration with wasmCloud
|
|
298
|
+
|
|
299
|
+
The wasmCloud plugin natively integrates virtual actors from `@di-framework/actors` into WebAssembly components and Kubernetes deployments.
|
|
300
|
+
|
|
301
|
+
### 1. Build-Time Actor Scanning & Dispatch Generation
|
|
302
|
+
- **Static Discovery**: During `di-framework platform build`, source files are scanned for `@Actor` and `@ActorMethod` decorators using TypeScript AST analysis.
|
|
303
|
+
- **Dispatch Module Generation**: The build generates `.di-framework/actors.js` which explicitly imports actor classes, registers them with `ActorRuntime`, sets up `SqliteActorStorage`, and exports `dispatchActorInvocation`. This prevents registered actors and their methods from being eliminated by Rolldown tree-shaking.
|
|
304
|
+
- **Private Invocations**: Invocations are delivered privately via `/_actors/invoke` or private service bindings without exposing public HTTP routes.
|
|
305
|
+
|
|
306
|
+
### 2. Runtime Execution Model
|
|
307
|
+
- **Activation & Scheduling**: Actor activations live in-memory within the host component instance. Per-actor mailbox queues asynchronously serialize calls to the same actor identity (`namespace:actorName:actorKey`) while allowing distinct actors to execute concurrently.
|
|
308
|
+
- **Host Storage Capabilities**: Persistent storage is bound via host capabilities (filesystem volume mount at `/data/actors`, configured via `ACTOR_STORAGE_DIR`). Each actor has an isolated SQLite database file with single-writer process file locking.
|
|
309
|
+
- **Transactions & Migrations**: Method invocations execute within actor-scoped transactions that commit on success and roll back on errors. Schema migrations run automatically before an actor's first activation; migration failures reject activation before calls can proceed.
|
|
310
|
+
|
|
311
|
+
### 3. Deployment & Operating Safety Constraints
|
|
312
|
+
- **Single-Host Constraint**: To ensure data consistency and prevent database split-brain with SQLite file locking, actor workloads enforce `replicas: 1`. Accidental configurations with `replicas > 1` are rejected with `WASMCLOUD_ACTORS_REPLICA_CONSTRAINT`.
|
|
313
|
+
- **Persistent Volumes**: Generated manifests provision a Kubernetes `PersistentVolumeClaim` mounted at `/data/actors`.
|
|
314
|
+
- **Upgrade & Drain Behavior**: The workload uses Kubernetes rollout `strategy: { type: "Recreate" }`, guaranteeing that the terminating pod drains active calls and releases SQLite locks before the new version activates and executes pending migrations.
|
|
315
|
+
- **Single-Host vs. Distributed**: Single-host wasmCloud actor deployment is designed for standalone, resilient edge or single-node deployments. Distributed actor clustering, key partitioning, and remote consensus across wasmCloud nodes are part of distributed actor capabilities.
|
|
316
|
+
|
|
317
|
+
Actor HTTP dispatch is restricted to the reserved `/_actors/` path. Actor headers on other paths do not intercept application requests. Error responses expose stable error names and generic messages; they omit internal exception details and migration objects.
|
|
318
|
+
|
|
319
|
+
## Building from source
|
|
320
|
+
|
|
321
|
+
The package build compiles the SQLite provider from
|
|
322
|
+
`../di-framework-sqlite-component` using its pinned Rust, WASI SDK, and wasm-tools
|
|
323
|
+
versions. Install that toolchain from the repository root before `bun install`
|
|
324
|
+
(the root postinstall builds the workspace):
|
|
325
|
+
|
|
326
|
+
```sh
|
|
327
|
+
bash packages/di-framework-sqlite-component/scripts/install-tools.sh --rust
|
|
328
|
+
bun install --frozen-lockfile
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Subsequent `bun run build` runs rebuild the provider through Cargo's incremental
|
|
332
|
+
build cache and stage its WASM, WIT, metadata, and checksums under
|
|
333
|
+
`dist/assets/sqlite`. Generated artifacts are ignored by Git and included in the
|
|
334
|
+
published npm package; npm consumers do not need the Rust build toolchain.
|
|
335
|
+
|
|
336
|
+
## Implicit workloads
|
|
337
|
+
|
|
338
|
+
A package can declare `"workload": "warehouse"` in `di-framework.config.json`.
|
|
339
|
+
The CLI discovers other packages with that name and generates
|
|
340
|
+
`.di-framework/workloads/warehouse.json` at the deployment workspace root. No parent
|
|
341
|
+
application or explicit member list is required. Member deployments remain independent
|
|
342
|
+
and carry a `di-framework.dev/workload` Kubernetes label.
|
|
343
|
+
|
|
344
|
+
In the entry module, export one variable wrapped in `WorkloadComponent({ path: '/take' })`
|
|
345
|
+
or `WorkloadService({ path: '/sync', subscriptions: ['warehouse.stock'] })`, imported from
|
|
346
|
+
`@di-framework/bindings`. The workload name lives in config; source describes behavior.
|
|
347
|
+
The CLI statically reads literal options, rejects conflicting member paths, and selects
|
|
348
|
+
the exported handler without requiring a default export. A service with subscriptions
|
|
349
|
+
exports `wasmcloud:messaging/handler@0.3.0`; a service without subscriptions exports
|
|
350
|
+
`wasi:cli/run@0.3.0`. Both initialize declared host bindings before loading the entrypoint.
|
|
351
|
+
|
|
352
|
+
The inferred manifest records routes but does not install a shared HTTP router. On the
|
|
353
|
+
current Kubernetes runtime, HTTP members retain their individual Host headers. See the
|
|
354
|
+
[warehouse example](../../examples/warehouse/README.md) for the complete deployment.
|
|
355
|
+
|
|
356
|
+
## Tenant deployment targets
|
|
357
|
+
|
|
358
|
+
Each external target selects a user's credentials, namespace, registry, and host groups:
|
|
359
|
+
|
|
360
|
+
```toml
|
|
361
|
+
[targets.alice]
|
|
362
|
+
kubeconfig = "${ALICE_KUBECONFIG}"
|
|
363
|
+
context = "alice"
|
|
364
|
+
namespace = "tenant-alice"
|
|
365
|
+
hostgroup = "alice"
|
|
366
|
+
storage-hostgroup = "alice-storage"
|
|
367
|
+
|
|
368
|
+
[targets.alice.registry]
|
|
369
|
+
push = "https://registry.example.com/alice"
|
|
370
|
+
pull = "registry.example.com/alice"
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Run `di-framework platform deploy warehouse-take --target alice`. All Kubernetes calls,
|
|
374
|
+
including deletion and diagnostics, use that target's kubeconfig, context, and namespace.
|
|
375
|
+
The generated WorkloadDeployment also sets `spec.template.spec.environment` to the target
|
|
376
|
+
namespace, so host selection cannot silently fall back to another environment when the
|
|
377
|
+
matching pool is unavailable. `hostgroup` defaults to `default`; `storage-hostgroup` defaults
|
|
378
|
+
to `storage` for actors, queues, and persistent storage. These selectors refer to existing
|
|
379
|
+
host pools; application deployment does not provision them.
|
|
380
|
+
|
|
381
|
+
Generated managed platforms set `operator.allowSharedHosts: false`. Existing generated
|
|
382
|
+
platforms and external clusters, including di-framework-kube, need their operator Helm
|
|
383
|
+
values updated separately. Application deploy does not reconfigure the operator.
|
|
384
|
+
|
|
385
|
+
Generated platforms provision namespaces, host pools, isolated Redis/NATS backends,
|
|
386
|
+
network policies, quotas, ServiceAccounts, and RBAC from declarative Tenant/User
|
|
387
|
+
resources. Administrators issue expiring ServiceAccount tokens; no identity provider
|
|
388
|
+
or login service is required. External clusters need equivalent provisioning.
|
|
389
|
+
The local registry remains shared and unauthenticated. Never distribute the platform's
|
|
390
|
+
administrative kubeconfig as a user's deployment credential.
|
|
391
|
+
|
|
392
|
+
An existing target that intentionally used a host in another environment must now have
|
|
393
|
+
a host in its own namespace environment. Workload names and decorator paths remain local
|
|
394
|
+
to the implicit workload; they do not select user identity or Kubernetes namespaces.
|
|
395
|
+
|
|
396
|
+
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.
|
|
397
|
+
|
|
398
|
+
### Managed PostgreSQL (upcoming release)
|
|
399
|
+
|
|
400
|
+
`di-framework platform service create postgres --name orders --wait` provisions
|
|
401
|
+
a dedicated instance through the default `postgres-dedicated` class. A
|
|
402
|
+
`@WasmCloudBinding('orders-db', { serviceName: 'orders' })` on a `Postgres` subclass
|
|
403
|
+
selects it. Deployment validates references and waits for controller-managed
|
|
404
|
+
ServiceBindings before applying the workload. Successful updates and workload
|
|
405
|
+
deletion remove obsolete deployment-owned associations. Shared projections stay
|
|
406
|
+
while other workloads use them.
|
|
407
|
+
|
|
408
|
+
See [PostgreSQL storage, deletion, and recovery](../di-framework-platform/README.md#dedicated-postgresql-upcoming-release).
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ActorRuntime } from '@di-framework/actors';
|
|
2
|
+
export declare const ACTORS_INVOCATION_PATH = "/_actors/invoke";
|
|
3
|
+
export declare function isActorInvocationRequest(request: Request): boolean;
|
|
4
|
+
export declare function handleActorInvocationRequest(request: Request, runtime?: ActorRuntime, dispatchFn?: (actorType: string, actorKey: string, method: string, args?: unknown[]) => Promise<unknown>): Promise<Response>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { authorizeControlRequest, unauthorizedResponse } from './control/auth.js';
|
|
2
|
+
export const ACTORS_INVOCATION_PATH = '/_actors/invoke';
|
|
3
|
+
export function isActorInvocationRequest(request) {
|
|
4
|
+
try {
|
|
5
|
+
const url = new URL(request.url);
|
|
6
|
+
return url.pathname.startsWith('/_actors/');
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function randomRequestId() {
|
|
13
|
+
return `req-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
14
|
+
}
|
|
15
|
+
export async function handleActorInvocationRequest(request, runtime, dispatchFn) {
|
|
16
|
+
if (!runtime && !dispatchFn) {
|
|
17
|
+
return new Response(JSON.stringify({
|
|
18
|
+
success: false,
|
|
19
|
+
error: {
|
|
20
|
+
name: 'ActorRuntimeError',
|
|
21
|
+
message: 'No actor runtime or actors registered in this component',
|
|
22
|
+
},
|
|
23
|
+
}), { status: 404, headers: { 'content-type': 'application/json' } });
|
|
24
|
+
}
|
|
25
|
+
const auth = authorizeControlRequest(request, ['invoke']);
|
|
26
|
+
if (!auth.ok)
|
|
27
|
+
return unauthorizedResponse(auth);
|
|
28
|
+
try {
|
|
29
|
+
let actorType;
|
|
30
|
+
let actorKey;
|
|
31
|
+
let method;
|
|
32
|
+
let args = [];
|
|
33
|
+
let requestId = randomRequestId();
|
|
34
|
+
let deadline;
|
|
35
|
+
let namespace;
|
|
36
|
+
const callerId = auth.identity.id;
|
|
37
|
+
let expectedGeneration;
|
|
38
|
+
const url = new URL(request.url);
|
|
39
|
+
const subPath = url.pathname.replace(/^\/_actors\/?/, '');
|
|
40
|
+
const pathParts = subPath ? subPath.split('/').filter(Boolean) : [];
|
|
41
|
+
if (request.method === 'POST') {
|
|
42
|
+
const parsed = await request.json().catch(() => ({}));
|
|
43
|
+
const body = parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
44
|
+
actorType = body.actorType ?? request.headers.get('x-actor-type') ?? pathParts[0];
|
|
45
|
+
actorKey = body.actorKey ?? request.headers.get('x-actor-key') ?? pathParts[1];
|
|
46
|
+
method = body.method ?? request.headers.get('x-actor-method') ?? pathParts[2];
|
|
47
|
+
args = Array.isArray(body.args) ? body.args : [];
|
|
48
|
+
if (typeof body.requestId === 'string' && body.requestId)
|
|
49
|
+
requestId = body.requestId;
|
|
50
|
+
if (typeof body.deadline === 'number')
|
|
51
|
+
deadline = body.deadline;
|
|
52
|
+
if (typeof body.namespace === 'string')
|
|
53
|
+
namespace = body.namespace;
|
|
54
|
+
if (typeof body.expectedGeneration === 'number')
|
|
55
|
+
expectedGeneration = body.expectedGeneration;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
actorType = request.headers.get('x-actor-type') ?? pathParts[0];
|
|
59
|
+
actorKey = request.headers.get('x-actor-key') ?? pathParts[1];
|
|
60
|
+
method = request.headers.get('x-actor-method') ?? pathParts[2];
|
|
61
|
+
const qArgs = url.searchParams.get('args');
|
|
62
|
+
if (qArgs) {
|
|
63
|
+
try {
|
|
64
|
+
const parsed = JSON.parse(qArgs);
|
|
65
|
+
args = Array.isArray(parsed) ? parsed : [parsed];
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
args = [qArgs];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const headerDeadline = request.headers.get('x-actor-deadline');
|
|
72
|
+
if (headerDeadline)
|
|
73
|
+
deadline = Number(headerDeadline);
|
|
74
|
+
namespace = request.headers.get('x-actor-namespace') ?? undefined;
|
|
75
|
+
}
|
|
76
|
+
if (typeof actorType !== 'string' ||
|
|
77
|
+
!actorType ||
|
|
78
|
+
typeof actorKey !== 'string' ||
|
|
79
|
+
!actorKey ||
|
|
80
|
+
typeof method !== 'string' ||
|
|
81
|
+
!method) {
|
|
82
|
+
return new Response(JSON.stringify({
|
|
83
|
+
success: false,
|
|
84
|
+
error: {
|
|
85
|
+
name: 'ActorInvocationBadRequest',
|
|
86
|
+
message: 'actorType, actorKey, and method are required for actor invocation',
|
|
87
|
+
},
|
|
88
|
+
}), { status: 400, headers: { 'content-type': 'application/json' } });
|
|
89
|
+
}
|
|
90
|
+
if (runtime) {
|
|
91
|
+
// Resolve via the portable package condition at componentize time so the
|
|
92
|
+
// adapter never pulls bun:sqlite into the Wasm guest.
|
|
93
|
+
const { ActorRpcDispatcher } = await import('@di-framework/actors/portable');
|
|
94
|
+
// Always pass the options object: `instanceof ActorRuntime` fails across package
|
|
95
|
+
// entrypoints (main vs portable) and would read `options.runtime` as undefined.
|
|
96
|
+
const dispatcher = new ActorRpcDispatcher({ runtime });
|
|
97
|
+
const rpcRequest = {
|
|
98
|
+
requestId,
|
|
99
|
+
namespace,
|
|
100
|
+
actorType,
|
|
101
|
+
actorKey,
|
|
102
|
+
method,
|
|
103
|
+
args,
|
|
104
|
+
callerId,
|
|
105
|
+
deadline,
|
|
106
|
+
expectedGeneration,
|
|
107
|
+
};
|
|
108
|
+
const response = await dispatcher.dispatch(rpcRequest);
|
|
109
|
+
const status = response.success
|
|
110
|
+
? 200
|
|
111
|
+
: response.error?.name === 'ActorAuthorizationError'
|
|
112
|
+
? 403
|
|
113
|
+
: response.error?.name === 'ActorDeadlineExceededError'
|
|
114
|
+
? 504
|
|
115
|
+
: response.error?.name === 'ActorNotRegisteredError' ||
|
|
116
|
+
response.error?.name === 'ActorMethodNotFoundError'
|
|
117
|
+
? 404
|
|
118
|
+
: 500;
|
|
119
|
+
return new Response(JSON.stringify(response), {
|
|
120
|
+
status,
|
|
121
|
+
headers: { 'content-type': 'application/json' },
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const invoke = dispatchFn;
|
|
125
|
+
const result = await invoke(actorType, actorKey, method, args);
|
|
126
|
+
return new Response(JSON.stringify({ requestId, success: true, result }), {
|
|
127
|
+
status: 200,
|
|
128
|
+
headers: { 'content-type': 'application/json' },
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
const name = [
|
|
133
|
+
'ActorNotRegisteredError',
|
|
134
|
+
'ActorMethodNotFoundError',
|
|
135
|
+
'ActorInvocationBadRequest',
|
|
136
|
+
'ActorMigrationError',
|
|
137
|
+
'ActorAuthorizationError',
|
|
138
|
+
'ActorDeadlineExceededError',
|
|
139
|
+
].find((candidate) => candidate === error?.name) ?? 'ActorInvocationError';
|
|
140
|
+
const isNotFound = name === 'ActorNotRegisteredError' || name === 'ActorMethodNotFoundError';
|
|
141
|
+
const isBadRequest = name === 'ActorInvocationBadRequest';
|
|
142
|
+
const isUnauthorized = name === 'ActorAuthorizationError';
|
|
143
|
+
const isDeadline = name === 'ActorDeadlineExceededError';
|
|
144
|
+
const status = isNotFound
|
|
145
|
+
? 404
|
|
146
|
+
: isBadRequest
|
|
147
|
+
? 400
|
|
148
|
+
: isUnauthorized
|
|
149
|
+
? 403
|
|
150
|
+
: isDeadline
|
|
151
|
+
? 504
|
|
152
|
+
: 500;
|
|
153
|
+
return new Response(JSON.stringify({
|
|
154
|
+
success: false,
|
|
155
|
+
error: {
|
|
156
|
+
name,
|
|
157
|
+
// Never echo handler exception text — it may contain private details.
|
|
158
|
+
message: 'Actor invocation failed',
|
|
159
|
+
},
|
|
160
|
+
}), { status, headers: { 'content-type': 'application/json' } });
|
|
161
|
+
}
|
|
162
|
+
}
|
package/dist/actors.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ActorRuntime } from '@di-framework/actors';
|
|
2
|
+
import type { WasmcloudProject } from './project.js';
|
|
3
|
+
export declare const WASMCLOUD_ACTORS_GLOBAL = "di-framework.wasmcloud.actors";
|
|
4
|
+
export { ACTORS_INVOCATION_PATH, handleActorInvocationRequest, isActorInvocationRequest, } from './actor-protocol.js';
|
|
5
|
+
export interface ActorMethodRecord {
|
|
6
|
+
name: string;
|
|
7
|
+
methodName: string;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ActorDiscoveredRecord {
|
|
11
|
+
className: string;
|
|
12
|
+
actorName: string;
|
|
13
|
+
namespace: string;
|
|
14
|
+
filePath: string;
|
|
15
|
+
importPath: string;
|
|
16
|
+
methods: ActorMethodRecord[];
|
|
17
|
+
hasMigrations: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface ActorModuleOptions {
|
|
20
|
+
defaultStorageDir?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WasmcloudActorAdapter {
|
|
23
|
+
handle(request: Request): Promise<Response>;
|
|
24
|
+
invoke(actorType: string, actorKey: string, method: string, args?: unknown[]): Promise<unknown>;
|
|
25
|
+
dispatchActorInvocation(actorType: string, actorKey: string, method: string, args?: unknown[]): Promise<unknown>;
|
|
26
|
+
actorRuntime: ActorRuntime;
|
|
27
|
+
}
|
|
28
|
+
export declare function createWasmcloudActorAdapter(actorRuntime: ActorRuntime): WasmcloudActorAdapter;
|
|
29
|
+
export declare function discoverActors(project: WasmcloudProject): ActorDiscoveredRecord[];
|
|
30
|
+
export declare function renderActorsModule(actors: readonly ActorDiscoveredRecord[], options?: ActorModuleOptions): string;
|
|
31
|
+
export declare function emptyActorsModule(): string;
|