@di-framework/cli-plugin-platform 0.0.1 → 6.0.3
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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getRandomBytes as wasiGetRandomBytes } from 'wasi:random/random@0.3.0';
|
|
2
|
+
import { toBytes } from './bytes.js';
|
|
3
|
+
function unwrapRandom(value) {
|
|
4
|
+
if (value !== null && typeof value === 'object' && 'tag' in value) {
|
|
5
|
+
const result = value;
|
|
6
|
+
if (result.tag === 'ok')
|
|
7
|
+
return toBytes(result.val);
|
|
8
|
+
throw new Error(`wasi:random failed: ${String(result.val)}`);
|
|
9
|
+
}
|
|
10
|
+
return toBytes(value);
|
|
11
|
+
}
|
|
12
|
+
/** Guest CSPRNG from WASI 0.3 `wasi:random/random`. */
|
|
13
|
+
export function getRandomBytes(size) {
|
|
14
|
+
if (!Number.isFinite(size) || size < 0) {
|
|
15
|
+
throw new RangeError(`getRandomBytes size must be a non-negative integer, received ${size}`);
|
|
16
|
+
}
|
|
17
|
+
if (size === 0)
|
|
18
|
+
return new Uint8Array();
|
|
19
|
+
const bytes = unwrapRandom(wasiGetRandomBytes(size));
|
|
20
|
+
if (bytes.length === size)
|
|
21
|
+
return bytes.slice();
|
|
22
|
+
if (bytes.length > size)
|
|
23
|
+
return bytes.slice(0, size);
|
|
24
|
+
throw new Error(`wasi:random returned ${bytes.length} bytes, expected ${size}`);
|
|
25
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type IpAddressFamily, type IpSocketAddress } from './socket-address.js';
|
|
2
|
+
export type WasiResult<T> = {
|
|
3
|
+
tag: 'ok';
|
|
4
|
+
val: T;
|
|
5
|
+
} | {
|
|
6
|
+
tag: 'err';
|
|
7
|
+
val: unknown;
|
|
8
|
+
};
|
|
9
|
+
export type WasiTcpSocket = {
|
|
10
|
+
bind(localAddress: IpSocketAddress): unknown;
|
|
11
|
+
connect(remoteAddress: IpSocketAddress): unknown;
|
|
12
|
+
listen(): unknown;
|
|
13
|
+
send(data: AsyncIterable<Uint8Array>): unknown;
|
|
14
|
+
receive(): unknown;
|
|
15
|
+
getLocalAddress(): unknown;
|
|
16
|
+
getRemoteAddress(): unknown;
|
|
17
|
+
};
|
|
18
|
+
export type WasiUdpSocket = {
|
|
19
|
+
bind(localAddress: IpSocketAddress): unknown;
|
|
20
|
+
connect(remoteAddress: IpSocketAddress): unknown;
|
|
21
|
+
send(data: Uint8Array | number[], remoteAddress?: IpSocketAddress): unknown;
|
|
22
|
+
receive(): unknown;
|
|
23
|
+
getLocalAddress(): unknown;
|
|
24
|
+
getRemoteAddress(): unknown;
|
|
25
|
+
};
|
|
26
|
+
type ErrnoException = Error & {
|
|
27
|
+
code: string;
|
|
28
|
+
errno: number;
|
|
29
|
+
syscall: string;
|
|
30
|
+
address?: string;
|
|
31
|
+
port?: number;
|
|
32
|
+
};
|
|
33
|
+
export declare function errorCodeName(value: unknown): string;
|
|
34
|
+
export declare function socketError(value: unknown, syscall: string, address?: string, port?: number): ErrnoException;
|
|
35
|
+
export declare function unwrapResult<T>(value: unknown, syscall: string): T;
|
|
36
|
+
export declare function unwrapAsync<T>(value: unknown, syscall: string): Promise<T>;
|
|
37
|
+
export declare function firstOfTuple<T>(value: T | [T, ...unknown[]] | {
|
|
38
|
+
res: T;
|
|
39
|
+
}): T;
|
|
40
|
+
export declare function asAsyncIterable<T>(value: unknown): AsyncIterable<T>;
|
|
41
|
+
export declare function toBytes(data: unknown): Uint8Array;
|
|
42
|
+
export declare function toNodeBuffer(bytes: Uint8Array): Uint8Array;
|
|
43
|
+
export declare function createTcpSocket(family: IpAddressFamily): WasiTcpSocket;
|
|
44
|
+
export declare function createUdpSocket(family: IpAddressFamily): WasiUdpSocket;
|
|
45
|
+
export declare function readSocketAddress(value: unknown, syscall: string): IpSocketAddress;
|
|
46
|
+
export declare function resolveSocketAddress(host: string, port: number, family: IpAddressFamily, syscall: string): Promise<IpSocketAddress>;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { resolveAddresses } from 'wasi:sockets/ip-name-lookup@0.3.0';
|
|
2
|
+
import { TcpSocket, UdpSocket } from 'wasi:sockets/types@0.3.0';
|
|
3
|
+
import { ipSocketAddress, parseIpSocketAddress, } from './socket-address.js';
|
|
4
|
+
const SOCKET_ERRNO = {
|
|
5
|
+
'access-denied': { code: 'EACCES', errno: -13 },
|
|
6
|
+
'not-supported': { code: 'ENOTSUP', errno: -95 },
|
|
7
|
+
'invalid-argument': { code: 'EINVAL', errno: -22 },
|
|
8
|
+
'out-of-memory': { code: 'ENOMEM', errno: -12 },
|
|
9
|
+
timeout: { code: 'ETIMEDOUT', errno: -110 },
|
|
10
|
+
'invalid-state': { code: 'EINVAL', errno: -22 },
|
|
11
|
+
'address-not-bindable': { code: 'EADDRNOTAVAIL', errno: -99 },
|
|
12
|
+
'address-in-use': { code: 'EADDRINUSE', errno: -98 },
|
|
13
|
+
'remote-unreachable': { code: 'EHOSTUNREACH', errno: -113 },
|
|
14
|
+
'connection-refused': { code: 'ECONNREFUSED', errno: -111 },
|
|
15
|
+
'connection-broken': { code: 'EPIPE', errno: -32 },
|
|
16
|
+
'connection-reset': { code: 'ECONNRESET', errno: -104 },
|
|
17
|
+
'connection-aborted': { code: 'ECONNABORTED', errno: -103 },
|
|
18
|
+
'datagram-too-large': { code: 'EMSGSIZE', errno: -90 },
|
|
19
|
+
'name-unresolvable': { code: 'ENOTFOUND', errno: -3008 },
|
|
20
|
+
'temporary-resolver-failure': { code: 'EAGAIN', errno: -11 },
|
|
21
|
+
'permanent-resolver-failure': { code: 'ENOTFOUND', errno: -3008 },
|
|
22
|
+
};
|
|
23
|
+
export function errorCodeName(value) {
|
|
24
|
+
if (typeof value === 'string')
|
|
25
|
+
return value;
|
|
26
|
+
if (value !== null && typeof value === 'object' && 'tag' in value) {
|
|
27
|
+
return String(value.tag);
|
|
28
|
+
}
|
|
29
|
+
return 'other';
|
|
30
|
+
}
|
|
31
|
+
export function socketError(value, syscall, address, port) {
|
|
32
|
+
const name = errorCodeName(value);
|
|
33
|
+
const mapped = SOCKET_ERRNO[name] ?? { code: 'EIO', errno: -5 };
|
|
34
|
+
const error = new Error(`${mapped.code}: ${name.replace(/-/g, ' ')}, ${syscall}`);
|
|
35
|
+
error.code = mapped.code;
|
|
36
|
+
error.errno = mapped.errno;
|
|
37
|
+
error.syscall = syscall;
|
|
38
|
+
if (address !== undefined)
|
|
39
|
+
error.address = address;
|
|
40
|
+
if (port !== undefined)
|
|
41
|
+
error.port = port;
|
|
42
|
+
return error;
|
|
43
|
+
}
|
|
44
|
+
export function unwrapResult(value, syscall) {
|
|
45
|
+
if (value !== null && typeof value === 'object' && 'tag' in value) {
|
|
46
|
+
const result = value;
|
|
47
|
+
if (result.tag === 'err')
|
|
48
|
+
throw socketError(result.val, syscall);
|
|
49
|
+
if (result.tag === 'ok')
|
|
50
|
+
return result.val;
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
export async function unwrapAsync(value, syscall) {
|
|
55
|
+
return unwrapResult(await Promise.resolve(value), syscall);
|
|
56
|
+
}
|
|
57
|
+
export function firstOfTuple(value) {
|
|
58
|
+
if (Array.isArray(value))
|
|
59
|
+
return value[0];
|
|
60
|
+
if (value !== null && typeof value === 'object' && 'res' in value)
|
|
61
|
+
return value.res;
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
export function asAsyncIterable(value) {
|
|
65
|
+
if (value != null && typeof value === 'object' && Symbol.asyncIterator in value) {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
if (value != null && typeof value === 'object' && Symbol.iterator in value) {
|
|
69
|
+
return {
|
|
70
|
+
async *[Symbol.asyncIterator]() {
|
|
71
|
+
yield* value;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
throw socketError('invalid-argument', 'read');
|
|
76
|
+
}
|
|
77
|
+
export function toBytes(data) {
|
|
78
|
+
if (typeof data === 'number')
|
|
79
|
+
return Uint8Array.of(data & 0xff);
|
|
80
|
+
if (typeof data === 'string')
|
|
81
|
+
return new TextEncoder().encode(data);
|
|
82
|
+
if (data instanceof Uint8Array)
|
|
83
|
+
return data;
|
|
84
|
+
if (ArrayBuffer.isView(data)) {
|
|
85
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
86
|
+
}
|
|
87
|
+
if (Array.isArray(data))
|
|
88
|
+
return Uint8Array.from(data.map((byte) => Number(byte) & 0xff));
|
|
89
|
+
return new Uint8Array();
|
|
90
|
+
}
|
|
91
|
+
export function toNodeBuffer(bytes) {
|
|
92
|
+
return typeof Buffer === 'undefined' ? bytes : Buffer.from(bytes);
|
|
93
|
+
}
|
|
94
|
+
export function createTcpSocket(family) {
|
|
95
|
+
const created = TcpSocket.create(family);
|
|
96
|
+
return unwrapResult(created, 'socket');
|
|
97
|
+
}
|
|
98
|
+
export function createUdpSocket(family) {
|
|
99
|
+
const created = UdpSocket.create(family);
|
|
100
|
+
return unwrapResult(created, 'socket');
|
|
101
|
+
}
|
|
102
|
+
export function readSocketAddress(value, syscall) {
|
|
103
|
+
const parsed = parseIpSocketAddress(unwrapResult(value, syscall));
|
|
104
|
+
if (parsed === undefined)
|
|
105
|
+
throw socketError('invalid-argument', syscall);
|
|
106
|
+
return parsed;
|
|
107
|
+
}
|
|
108
|
+
export async function resolveSocketAddress(host, port, family, syscall) {
|
|
109
|
+
const parsed = ipSocketAddress(host, port, family);
|
|
110
|
+
if (parsed !== undefined)
|
|
111
|
+
return parsed;
|
|
112
|
+
const resolved = unwrapResult(await Promise.resolve(resolveAddresses(host)), syscall);
|
|
113
|
+
const first = resolved[0];
|
|
114
|
+
if (first === undefined)
|
|
115
|
+
throw socketError('name-unresolvable', syscall, host, port);
|
|
116
|
+
if (first !== null && typeof first === 'object' && 'tag' in first) {
|
|
117
|
+
const tagged = first;
|
|
118
|
+
if (tagged.tag === 'ipv6') {
|
|
119
|
+
const address = Array.isArray(tagged.val)
|
|
120
|
+
? tagged.val
|
|
121
|
+
: undefined;
|
|
122
|
+
if (address === undefined)
|
|
123
|
+
throw socketError('name-unresolvable', syscall, host, port);
|
|
124
|
+
return { tag: 'ipv6', val: { port, address, flowInfo: 0, scopeId: 0 } };
|
|
125
|
+
}
|
|
126
|
+
const address = Array.isArray(tagged.val)
|
|
127
|
+
? tagged.val
|
|
128
|
+
: undefined;
|
|
129
|
+
if (address === undefined)
|
|
130
|
+
throw socketError('name-unresolvable', syscall, host, port);
|
|
131
|
+
return { tag: 'ipv4', val: { port, address } };
|
|
132
|
+
}
|
|
133
|
+
throw socketError('name-unresolvable', syscall, host, port);
|
|
134
|
+
}
|
package/dist/oci.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OCI config for published components. wasmCloud/ORAS treat component artifacts
|
|
3
|
+
* as `architecture: wasm` with the historical `wasip2` OS field; that names the
|
|
4
|
+
* artifact type, not the WASI preview the guest was compiled for.
|
|
5
|
+
*/
|
|
6
|
+
export declare const OCI_ARTIFACT_PLATFORM: {
|
|
7
|
+
readonly architecture: "wasm";
|
|
8
|
+
readonly os: "wasip2";
|
|
9
|
+
};
|
package/dist/oci.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OCI config for published components. wasmCloud/ORAS treat component artifacts
|
|
3
|
+
* as `architecture: wasm` with the historical `wasip2` OS field; that names the
|
|
4
|
+
* artifact type, not the WASI preview the guest was compiled for.
|
|
5
|
+
*/
|
|
6
|
+
export const OCI_ARTIFACT_PLATFORM = {
|
|
7
|
+
architecture: 'wasm',
|
|
8
|
+
os: 'wasip2',
|
|
9
|
+
};
|
package/dist/paths.d.ts
ADDED
package/dist/paths.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
2
|
+
export function isInside(root, candidate) {
|
|
3
|
+
const relativePath = relative(resolve(root), resolve(candidate));
|
|
4
|
+
if (relativePath === '')
|
|
5
|
+
return true;
|
|
6
|
+
return relativePath !== '..' && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath);
|
|
7
|
+
}
|
|
8
|
+
export function resolveInsideRoot(root, value) {
|
|
9
|
+
const absolutePath = resolve(root, value);
|
|
10
|
+
return isInside(root, absolutePath) && relative(resolve(root), absolutePath) !== ''
|
|
11
|
+
? { ok: true, path: absolutePath }
|
|
12
|
+
: { ok: false };
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type CliIo, type CommandResult } from '@di-framework/cli-extension';
|
|
2
|
+
import { type WasmcloudDeps } from './deps.js';
|
|
3
|
+
export declare const LOCAL_PLATFORM_PATH = "deploy/platform";
|
|
4
|
+
export declare const LOCAL_TARGET_NAME = "local";
|
|
5
|
+
export declare const LOCAL_STACK_NAME = "dev";
|
|
6
|
+
export declare const PLATFORM_START_COMMAND = "di-framework platform cluster up local --yes";
|
|
7
|
+
export declare const PLATFORM_PROJECT_TOKEN = "{{DI_FRAMEWORK_PLATFORM_PROJECT}}";
|
|
8
|
+
export declare function runWasmcloudPlatformInit(args: readonly string[], io: CliIo, deps?: WasmcloudDeps): Promise<CommandResult>;
|
|
9
|
+
export declare function createPlatformProjectName(workspaceRoot: string): string;
|
|
10
|
+
export declare function resolveWorkspaceRoot(startDirectory: string): string;
|
|
11
|
+
export declare function destinationRelativePath(relativePath: string): string;
|
|
12
|
+
export declare function listTemplateFiles(templateRoot: string): string[];
|
|
13
|
+
export declare function serializeDeployToml(document: Record<string, unknown>): string;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { closeSync, constants, existsSync, mkdirSync, openSync, readdirSync, readFileSync, writeFileSync, writeSync, } from 'node:fs';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { basename, dirname, join, relative, sep } from 'node:path';
|
|
6
|
+
import { CommandFailure } from '@di-framework/cli-extension';
|
|
7
|
+
import { parsePlatformInitArgs } from './args.js';
|
|
8
|
+
import { DEFAULT_DEPS } from './deps.js';
|
|
9
|
+
import { DEPLOY_MANIFEST_NAME, findDeployManifest } from './manifest.js';
|
|
10
|
+
import { parseToml, TomlParseError } from './toml.js';
|
|
11
|
+
export const LOCAL_PLATFORM_PATH = 'deploy/platform';
|
|
12
|
+
export const LOCAL_TARGET_NAME = 'local';
|
|
13
|
+
export const LOCAL_STACK_NAME = 'dev';
|
|
14
|
+
export const PLATFORM_START_COMMAND = 'di-framework platform cluster up local --yes';
|
|
15
|
+
export const PLATFORM_PROJECT_TOKEN = '{{DI_FRAMEWORK_PLATFORM_PROJECT}}';
|
|
16
|
+
const LOCAL_TARGET_FIELDS = {
|
|
17
|
+
platform: LOCAL_PLATFORM_PATH,
|
|
18
|
+
stack: LOCAL_STACK_NAME,
|
|
19
|
+
};
|
|
20
|
+
export async function runWasmcloudPlatformInit(args, io, deps = DEFAULT_DEPS) {
|
|
21
|
+
const { force } = parsePlatformInitArgs(args);
|
|
22
|
+
const workspaceRoot = resolveWorkspaceRoot(deps.cwd());
|
|
23
|
+
const templateRoot = join(deps.assetsDirectory(), 'platform');
|
|
24
|
+
if (!existsSync(join(templateRoot, 'Pulumi.yaml')) &&
|
|
25
|
+
!existsSync(join(templateRoot, 'Pulumi.yaml.tmpl'))) {
|
|
26
|
+
throw new CommandFailure('WASMCLOUD_PLATFORM_TEMPLATE_NOT_FOUND', `wasmCloud platform templates were not found at ${templateRoot}. Rebuild @di-framework/cli-plugin-platform so dist/assets/platform is installed.`, 3, { templateRoot });
|
|
27
|
+
}
|
|
28
|
+
const platformRoot = join(workspaceRoot, ...LOCAL_PLATFORM_PATH.split('/'));
|
|
29
|
+
mkdirSync(platformRoot, { recursive: true });
|
|
30
|
+
io.stdout.write(`Initializing local wasmCloud platform in ${platformRoot}\n`);
|
|
31
|
+
const written = [];
|
|
32
|
+
const skipped = [];
|
|
33
|
+
const platformProject = createPlatformProjectName(workspaceRoot);
|
|
34
|
+
for (const relativePath of listTemplateFiles(templateRoot)) {
|
|
35
|
+
const destination = join(platformRoot, ...destinationRelativePath(relativePath).split('/'));
|
|
36
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
37
|
+
const content = renderTemplate(readFileSync(join(templateRoot, ...relativePath.split('/'))), platformProject);
|
|
38
|
+
const writtenName = destinationRelativePath(relativePath);
|
|
39
|
+
if (writeFilePreserving(destination, content, force, io))
|
|
40
|
+
written.push(writtenName);
|
|
41
|
+
else
|
|
42
|
+
skipped.push(writtenName);
|
|
43
|
+
}
|
|
44
|
+
const manifestPath = join(workspaceRoot, DEPLOY_MANIFEST_NAME);
|
|
45
|
+
const manifest = updateDeployManifest(manifestPath, force, io);
|
|
46
|
+
if (manifest.written)
|
|
47
|
+
written.push(DEPLOY_MANIFEST_NAME);
|
|
48
|
+
else
|
|
49
|
+
skipped.push(DEPLOY_MANIFEST_NAME);
|
|
50
|
+
io.stdout.write(`\nNext:\n ${PLATFORM_START_COMMAND}\n`);
|
|
51
|
+
return {
|
|
52
|
+
data: {
|
|
53
|
+
workspaceRoot,
|
|
54
|
+
platformRoot,
|
|
55
|
+
manifestPath,
|
|
56
|
+
defaultTarget: LOCAL_TARGET_NAME,
|
|
57
|
+
target: LOCAL_TARGET_NAME,
|
|
58
|
+
force,
|
|
59
|
+
written,
|
|
60
|
+
skipped,
|
|
61
|
+
startCommand: PLATFORM_START_COMMAND,
|
|
62
|
+
},
|
|
63
|
+
text: `Initialized local platform at ${LOCAL_PLATFORM_PATH}. Start it with:\n${PLATFORM_START_COMMAND}`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function createPlatformProjectName(workspaceRoot) {
|
|
67
|
+
const normalized = basename(workspaceRoot)
|
|
68
|
+
.toLowerCase()
|
|
69
|
+
.replace(/[^a-z0-9-]+/g, '-');
|
|
70
|
+
const slug = normalized.split('-').filter(Boolean).join('-').slice(0, 28);
|
|
71
|
+
const hash = createHash('sha256').update(workspaceRoot).digest('hex').slice(0, 10);
|
|
72
|
+
return `di-framework-wasmcloud-${slug || 'workspace'}-${hash}`;
|
|
73
|
+
}
|
|
74
|
+
function renderTemplate(content, platformProject) {
|
|
75
|
+
const source = content.toString('utf8');
|
|
76
|
+
const platformVersion = createRequire(import.meta.url)('@di-framework/platform/package.json').version;
|
|
77
|
+
return Buffer.from(source
|
|
78
|
+
.replaceAll(PLATFORM_PROJECT_TOKEN, platformProject)
|
|
79
|
+
.replaceAll('{{DI_FRAMEWORK_PLATFORM_VERSION}}', platformVersion));
|
|
80
|
+
}
|
|
81
|
+
export function resolveWorkspaceRoot(startDirectory) {
|
|
82
|
+
const manifestPath = findDeployManifest(startDirectory);
|
|
83
|
+
return manifestPath === undefined ? startDirectory : dirname(manifestPath);
|
|
84
|
+
}
|
|
85
|
+
export function destinationRelativePath(relativePath) {
|
|
86
|
+
return relativePath.endsWith('.tmpl') ? relativePath.slice(0, -'.tmpl'.length) : relativePath;
|
|
87
|
+
}
|
|
88
|
+
export function listTemplateFiles(templateRoot) {
|
|
89
|
+
const files = [];
|
|
90
|
+
const walk = (directory) => {
|
|
91
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
92
|
+
if (entry.name === '.DS_Store')
|
|
93
|
+
continue;
|
|
94
|
+
const fullPath = join(directory, entry.name);
|
|
95
|
+
if (entry.isDirectory()) {
|
|
96
|
+
walk(fullPath);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
files.push(relative(templateRoot, fullPath).split(sep).join('/'));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
walk(templateRoot);
|
|
103
|
+
return files.sort();
|
|
104
|
+
}
|
|
105
|
+
function writeFilePreserving(path, content, force, io) {
|
|
106
|
+
if (force) {
|
|
107
|
+
writeFileSync(path, content);
|
|
108
|
+
io.stdout.write(` write ${path}\n`);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const fd = openSync(path, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY);
|
|
113
|
+
try {
|
|
114
|
+
writeSync(fd, Buffer.isBuffer(content) ? content : Buffer.from(content));
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
closeSync(fd);
|
|
118
|
+
}
|
|
119
|
+
io.stdout.write(` write ${path}\n`);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (isErrno(error, 'EEXIST')) {
|
|
124
|
+
io.stdout.write(` skip ${path} (exists; use --force to overwrite)\n`);
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function isErrno(error, code) {
|
|
131
|
+
return typeof error === 'object' && error !== null && 'code' in error && error.code === code;
|
|
132
|
+
}
|
|
133
|
+
function updateDeployManifest(manifestPath, force, io) {
|
|
134
|
+
let source;
|
|
135
|
+
try {
|
|
136
|
+
source = readFileSync(manifestPath, 'utf8');
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (!isErrno(error, 'ENOENT'))
|
|
140
|
+
throw error;
|
|
141
|
+
const created = writeFilePreserving(manifestPath, canonicalManifest(), false, io);
|
|
142
|
+
return { written: created };
|
|
143
|
+
}
|
|
144
|
+
let parsed;
|
|
145
|
+
try {
|
|
146
|
+
parsed = parseToml(source);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
const line = error instanceof TomlParseError ? error.line : undefined;
|
|
150
|
+
throw new CommandFailure('WASMCLOUD_DEPLOY_MANIFEST_INVALID', `Could not parse ${manifestPath}${line === undefined ? '' : ` (line ${line})`}: ${error instanceof Error ? error.message : String(error)}`, 2, { manifestPath, ...(line === undefined ? {} : { line }) });
|
|
151
|
+
}
|
|
152
|
+
if ('apps' in parsed) {
|
|
153
|
+
throw new CommandFailure('WASMCLOUD_DEPLOY_MANIFEST_INVALID', `${DEPLOY_MANIFEST_NAME} must not declare "apps"; project identity comes only from di-framework.config.json`, 2, { manifestPath });
|
|
154
|
+
}
|
|
155
|
+
const desired = mergeLocalTarget(parsed, force);
|
|
156
|
+
if (desired.unchanged) {
|
|
157
|
+
io.stdout.write(` skip ${manifestPath} (exists; use --force to overwrite)\n`);
|
|
158
|
+
return { written: false };
|
|
159
|
+
}
|
|
160
|
+
rewriteFile(manifestPath, serializeDeployToml(desired.document));
|
|
161
|
+
io.stdout.write(` write ${manifestPath}\n`);
|
|
162
|
+
return { written: true };
|
|
163
|
+
}
|
|
164
|
+
function rewriteFile(path, content) {
|
|
165
|
+
const fd = openSync(path, constants.O_WRONLY | constants.O_TRUNC);
|
|
166
|
+
try {
|
|
167
|
+
writeSync(fd, content);
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
closeSync(fd);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function mergeLocalTarget(parsed, force) {
|
|
174
|
+
const targets = isRecord(parsed.targets) ? { ...parsed.targets } : {};
|
|
175
|
+
const existing = targets[LOCAL_TARGET_NAME];
|
|
176
|
+
const localMatches = isRecord(existing) &&
|
|
177
|
+
existing.platform === LOCAL_TARGET_FIELDS.platform &&
|
|
178
|
+
existing.stack === LOCAL_TARGET_FIELDS.stack &&
|
|
179
|
+
Object.keys(existing).every((key) => key === 'platform' || key === 'stack');
|
|
180
|
+
if (!force && existing !== undefined && !localMatches) {
|
|
181
|
+
return { document: parsed, unchanged: true };
|
|
182
|
+
}
|
|
183
|
+
const document = { ...parsed, targets };
|
|
184
|
+
let changed = false;
|
|
185
|
+
if (force || existing === undefined) {
|
|
186
|
+
if (!localMatches) {
|
|
187
|
+
targets[LOCAL_TARGET_NAME] = { ...LOCAL_TARGET_FIELDS };
|
|
188
|
+
changed = true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (force || parsed['default-target'] === undefined) {
|
|
192
|
+
if (document['default-target'] !== LOCAL_TARGET_NAME) {
|
|
193
|
+
document['default-target'] = LOCAL_TARGET_NAME;
|
|
194
|
+
changed = true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return { document, unchanged: !changed };
|
|
198
|
+
}
|
|
199
|
+
function canonicalManifest() {
|
|
200
|
+
return serializeDeployToml({
|
|
201
|
+
'default-target': LOCAL_TARGET_NAME,
|
|
202
|
+
targets: { [LOCAL_TARGET_NAME]: { ...LOCAL_TARGET_FIELDS } },
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
export function serializeDeployToml(document) {
|
|
206
|
+
const lines = [
|
|
207
|
+
'# Deployment topology only. Project identity comes from each',
|
|
208
|
+
'# di-framework.config.json `name` — this file has no `apps` table.',
|
|
209
|
+
];
|
|
210
|
+
if (typeof document['default-target'] === 'string') {
|
|
211
|
+
lines.push(`default-target = ${tomlString(document['default-target'])}`);
|
|
212
|
+
}
|
|
213
|
+
if (isRecord(document.discovery)) {
|
|
214
|
+
lines.push('', '[discovery]');
|
|
215
|
+
emitTableFields(lines, document.discovery);
|
|
216
|
+
}
|
|
217
|
+
const targets = isRecord(document.targets) ? document.targets : {};
|
|
218
|
+
for (const name of Object.keys(targets).sort(localFirst)) {
|
|
219
|
+
const table = targets[name];
|
|
220
|
+
if (!isRecord(table))
|
|
221
|
+
continue;
|
|
222
|
+
lines.push('', `[targets.${name}]`);
|
|
223
|
+
emitTableFields(lines, table);
|
|
224
|
+
emitNestedTables(lines, `targets.${name}`, table);
|
|
225
|
+
}
|
|
226
|
+
lines.push('');
|
|
227
|
+
return `${lines.join('\n')}`;
|
|
228
|
+
}
|
|
229
|
+
function localFirst(left, right) {
|
|
230
|
+
if (left === LOCAL_TARGET_NAME)
|
|
231
|
+
return -1;
|
|
232
|
+
if (right === LOCAL_TARGET_NAME)
|
|
233
|
+
return 1;
|
|
234
|
+
return left.localeCompare(right);
|
|
235
|
+
}
|
|
236
|
+
function emitTableFields(lines, table) {
|
|
237
|
+
for (const [key, value] of Object.entries(table)) {
|
|
238
|
+
if (typeof value === 'string') {
|
|
239
|
+
lines.push(`${key} = ${tomlString(value)}`);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (Array.isArray(value) && value.every((entry) => typeof entry === 'string')) {
|
|
243
|
+
lines.push(`${key} = [${value.map((entry) => tomlString(entry)).join(', ')}]`);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (typeof value === 'boolean')
|
|
247
|
+
lines.push(`${key} = ${value}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function emitNestedTables(lines, prefix, table) {
|
|
251
|
+
for (const [key, value] of Object.entries(table)) {
|
|
252
|
+
if (!isRecord(value))
|
|
253
|
+
continue;
|
|
254
|
+
const nestedPrefix = `${prefix}.${key}`;
|
|
255
|
+
lines.push('', `[${nestedPrefix}]`);
|
|
256
|
+
emitTableFields(lines, value);
|
|
257
|
+
emitNestedTables(lines, nestedPrefix, value);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function tomlString(value) {
|
|
261
|
+
return `"${value.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`;
|
|
262
|
+
}
|
|
263
|
+
function isRecord(value) {
|
|
264
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
265
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CliIo, CommandResult } from '@di-framework/cli-extension';
|
|
2
|
+
import { type WasmcloudDeps } from './deps.js';
|
|
3
|
+
import { type ManagedTarget } from './manifest.js';
|
|
4
|
+
import { type RegistryLocation } from './registry.js';
|
|
5
|
+
export declare const PLATFORM_OUTPUT_SCHEMA_VERSION = 2;
|
|
6
|
+
export type PlatformEndpoints = {
|
|
7
|
+
http?: string;
|
|
8
|
+
kubernetes?: string;
|
|
9
|
+
registry?: string;
|
|
10
|
+
};
|
|
11
|
+
export type PlatformOutputs = {
|
|
12
|
+
schemaVersion: typeof PLATFORM_OUTPUT_SCHEMA_VERSION;
|
|
13
|
+
kubeconfig: string;
|
|
14
|
+
namespace: string;
|
|
15
|
+
registry: RegistryLocation;
|
|
16
|
+
context?: string;
|
|
17
|
+
endpoints?: PlatformEndpoints;
|
|
18
|
+
};
|
|
19
|
+
export declare function runWasmcloudPlatformDeploy(args: readonly string[], io: CliIo, deps?: WasmcloudDeps): Promise<CommandResult>;
|
|
20
|
+
export declare function runWasmcloudPlatformDestroy(args: readonly string[], io: CliIo, deps?: WasmcloudDeps): Promise<CommandResult>;
|
|
21
|
+
export declare function loadPlatformOutputs(deps: WasmcloudDeps, platformRoot: string, stack: string, targetName: string): Promise<PlatformOutputs>;
|
|
22
|
+
export declare function resolvePlatformDirectory(target: ManagedTarget, workspaceRoot: string, manifestPath: string): string;
|