@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.
Files changed (169) hide show
  1. package/README.md +408 -0
  2. package/dist/actor-protocol.d.ts +4 -0
  3. package/dist/actor-protocol.js +162 -0
  4. package/dist/actors.d.ts +31 -0
  5. package/dist/actors.js +296 -0
  6. package/dist/args.d.ts +15 -0
  7. package/dist/args.js +66 -0
  8. package/dist/assets/http-adapter.js +876 -0
  9. package/dist/assets/platform/.gitignore.tmpl +6 -0
  10. package/dist/assets/platform/Pulumi.yaml.tmpl +6 -0
  11. package/dist/assets/platform/README.md +208 -0
  12. package/dist/assets/platform/index.ts.tmpl +2 -0
  13. package/dist/assets/platform/package.json.tmpl +18 -0
  14. package/dist/assets/platform/tsconfig.json +11 -0
  15. package/dist/assets/queue-adapter.js +60 -0
  16. package/dist/assets/sqlite/BUILD-INFO.txt +13 -0
  17. package/dist/assets/sqlite/SHA256SUMS +2 -0
  18. package/dist/assets/sqlite/di-framework-sqlite.wasm +0 -0
  19. package/dist/assets/sqlite/di-framework-sqlite.wit +337 -0
  20. package/dist/assets/wit/deps/LICENSE.md +8 -0
  21. package/dist/assets/wit/deps/di-framework-queues/package.wit +18 -0
  22. package/dist/assets/wit/deps/di-framework-sqlite/package.wit +211 -0
  23. package/dist/assets/wit/deps/wasi-cli/package.wit +70 -0
  24. package/dist/assets/wit/deps/wasi-clocks/package.wit +42 -0
  25. package/dist/assets/wit/deps/wasi-config/package.wit +15 -0
  26. package/dist/assets/wit/deps/wasi-filesystem/package.wit +184 -0
  27. package/dist/assets/wit/deps/wasi-http/package.wit +170 -0
  28. package/dist/assets/wit/deps/wasi-random/package.wit +17 -0
  29. package/dist/assets/wit/deps/wasi-sockets/package.wit +105 -0
  30. package/dist/assets/wit/deps/wasi-tls/package.wit +26 -0
  31. package/dist/assets/wit/deps/wasmcloud-blobstore/package.wit +153 -0
  32. package/dist/assets/wit/deps/wasmcloud-keyvalue/package.wit +370 -0
  33. package/dist/assets/wit/deps/wasmcloud-messaging/package.wit +125 -0
  34. package/dist/assets/wit/deps/wasmcloud-postgres/package.wit +435 -0
  35. package/dist/assets/wit/deps/wasmcloud-secrets/package.wit +80 -0
  36. package/dist/async-transform.d.ts +3 -0
  37. package/dist/async-transform.js +60 -0
  38. package/dist/bindings.d.ts +34 -0
  39. package/dist/bindings.js +307 -0
  40. package/dist/build.d.ts +29 -0
  41. package/dist/build.js +325 -0
  42. package/dist/command.d.ts +3 -0
  43. package/dist/command.js +141 -0
  44. package/dist/control/auth.d.ts +18 -0
  45. package/dist/control/auth.js +89 -0
  46. package/dist/control/cron.d.ts +7 -0
  47. package/dist/control/cron.js +86 -0
  48. package/dist/control/index.d.ts +4 -0
  49. package/dist/control/index.js +4 -0
  50. package/dist/control/network.d.ts +12 -0
  51. package/dist/control/network.js +49 -0
  52. package/dist/control/queues.d.ts +15 -0
  53. package/dist/control/queues.js +77 -0
  54. package/dist/cron.d.ts +26 -0
  55. package/dist/cron.js +239 -0
  56. package/dist/deploy.d.ts +29 -0
  57. package/dist/deploy.js +57 -0
  58. package/dist/deps.d.ts +96 -0
  59. package/dist/deps.js +303 -0
  60. package/dist/destroy.d.ts +3 -0
  61. package/dist/destroy.js +24 -0
  62. package/dist/dev-runner.d.ts +24 -0
  63. package/dist/dev-runner.js +83 -0
  64. package/dist/dev.d.ts +8 -0
  65. package/dist/dev.js +76 -0
  66. package/dist/discovery.d.ts +15 -0
  67. package/dist/discovery.js +182 -0
  68. package/dist/doctor.d.ts +8 -0
  69. package/dist/doctor.js +82 -0
  70. package/dist/guests.d.ts +9 -0
  71. package/dist/guests.js +56 -0
  72. package/dist/host-interface.d.ts +29 -0
  73. package/dist/host-interface.js +142 -0
  74. package/dist/index.d.ts +33 -0
  75. package/dist/index.js +39 -0
  76. package/dist/kubernetes.d.ts +9 -0
  77. package/dist/kubernetes.js +17 -0
  78. package/dist/managed-bindings.d.ts +9 -0
  79. package/dist/managed-bindings.js +150 -0
  80. package/dist/manifest.d.ts +36 -0
  81. package/dist/manifest.js +257 -0
  82. package/dist/namespace.d.ts +2 -0
  83. package/dist/namespace.js +4 -0
  84. package/dist/node-compat/async-hooks.d.ts +29 -0
  85. package/dist/node-compat/async-hooks.js +80 -0
  86. package/dist/node-compat/bootstrap.d.ts +1 -0
  87. package/dist/node-compat/bootstrap.js +9 -0
  88. package/dist/node-compat/bytes.d.ts +7 -0
  89. package/dist/node-compat/bytes.js +41 -0
  90. package/dist/node-compat/crypto-hash.d.ts +27 -0
  91. package/dist/node-compat/crypto-hash.js +108 -0
  92. package/dist/node-compat/crypto-subtle.d.ts +59 -0
  93. package/dist/node-compat/crypto-subtle.js +288 -0
  94. package/dist/node-compat/crypto.d.ts +136 -0
  95. package/dist/node-compat/crypto.js +142 -0
  96. package/dist/node-compat/dgram.d.ts +49 -0
  97. package/dist/node-compat/dgram.js +197 -0
  98. package/dist/node-compat/env.d.ts +6 -0
  99. package/dist/node-compat/env.js +88 -0
  100. package/dist/node-compat/fetch-runtime.d.ts +80 -0
  101. package/dist/node-compat/fetch-runtime.js +314 -0
  102. package/dist/node-compat/fs.d.ts +84 -0
  103. package/dist/node-compat/fs.js +285 -0
  104. package/dist/node-compat/http-parser.d.ts +40 -0
  105. package/dist/node-compat/http-parser.js +185 -0
  106. package/dist/node-compat/http.d.ts +130 -0
  107. package/dist/node-compat/http.js +688 -0
  108. package/dist/node-compat/https.d.ts +28 -0
  109. package/dist/node-compat/https.js +88 -0
  110. package/dist/node-compat/module.d.ts +11 -0
  111. package/dist/node-compat/module.js +35 -0
  112. package/dist/node-compat/net.d.ts +119 -0
  113. package/dist/node-compat/net.js +441 -0
  114. package/dist/node-compat/process.d.ts +25 -0
  115. package/dist/node-compat/process.js +63 -0
  116. package/dist/node-compat/runtime-application.d.ts +4 -0
  117. package/dist/node-compat/runtime-application.js +24 -0
  118. package/dist/node-compat/seed-virtual.d.ts +6 -0
  119. package/dist/node-compat/seed-virtual.js +6 -0
  120. package/dist/node-compat/seed.d.ts +20 -0
  121. package/dist/node-compat/seed.js +106 -0
  122. package/dist/node-compat/socket-address.d.ts +35 -0
  123. package/dist/node-compat/socket-address.js +162 -0
  124. package/dist/node-compat/timers.d.ts +32 -0
  125. package/dist/node-compat/timers.js +96 -0
  126. package/dist/node-compat/tls.d.ts +57 -0
  127. package/dist/node-compat/tls.js +290 -0
  128. package/dist/node-compat/wasi-random.d.ts +2 -0
  129. package/dist/node-compat/wasi-random.js +25 -0
  130. package/dist/node-compat/wasi-sockets.d.ts +47 -0
  131. package/dist/node-compat/wasi-sockets.js +134 -0
  132. package/dist/oci.d.ts +9 -0
  133. package/dist/oci.js +9 -0
  134. package/dist/paths.d.ts +7 -0
  135. package/dist/paths.js +13 -0
  136. package/dist/platform-init.d.ts +13 -0
  137. package/dist/platform-init.js +265 -0
  138. package/dist/platform.d.ts +22 -0
  139. package/dist/platform.js +170 -0
  140. package/dist/project.d.ts +39 -0
  141. package/dist/project.js +130 -0
  142. package/dist/publish.d.ts +15 -0
  143. package/dist/publish.js +57 -0
  144. package/dist/pulumi.d.ts +4 -0
  145. package/dist/pulumi.js +27 -0
  146. package/dist/queues-module.d.ts +4 -0
  147. package/dist/queues-module.js +89 -0
  148. package/dist/queues.d.ts +16 -0
  149. package/dist/queues.js +167 -0
  150. package/dist/registry.d.ts +16 -0
  151. package/dist/registry.js +27 -0
  152. package/dist/service.d.ts +162 -0
  153. package/dist/service.js +678 -0
  154. package/dist/support.d.ts +14 -0
  155. package/dist/support.js +37 -0
  156. package/dist/target.d.ts +18 -0
  157. package/dist/target.js +45 -0
  158. package/dist/toml.d.ts +6 -0
  159. package/dist/toml.js +245 -0
  160. package/dist/wash-dev.d.ts +18 -0
  161. package/dist/wash-dev.js +80 -0
  162. package/dist/wit.d.ts +76 -0
  163. package/dist/wit.js +248 -0
  164. package/dist/workload-members.d.ts +12 -0
  165. package/dist/workload-members.js +136 -0
  166. package/dist/workload.d.ts +45 -0
  167. package/dist/workload.js +457 -0
  168. package/package.json +55 -8
  169. package/src/index.ts +0 -2
@@ -0,0 +1,170 @@
1
+ import { chmodSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
2
+ import { isAbsolute, join, resolve } from 'node:path';
3
+ import { CommandFailure } from '@di-framework/cli-extension';
4
+ import { parsePlatformCommandArgs } from './args.js';
5
+ import { DEFAULT_DEPS } from './deps.js';
6
+ import { loadDeployManifest } from './manifest.js';
7
+ import { isNamespace } from './namespace.js';
8
+ import { resolveInsideRoot } from './paths.js';
9
+ import { pulumiEnvironment, runPulumi } from './pulumi.js';
10
+ import { materializeRegistry } from './registry.js';
11
+ export const PLATFORM_OUTPUT_SCHEMA_VERSION = 2;
12
+ export async function runWasmcloudPlatformDeploy(args, io, deps = DEFAULT_DEPS) {
13
+ const options = parsePlatformCommandArgs(args, 'platform cluster up');
14
+ const { target, platformRoot, stack } = loadManagedPlatform(deps, options.target);
15
+ io.stdout.write(`Deploying platform target ${target.name} (stack ${stack})...\n`);
16
+ io.stdout.write('Installing generated Pulumi project dependencies...\n');
17
+ await runPulumi(deps, ['install'], platformRoot);
18
+ await runPulumi(deps, ['stack', 'select', stack, '--create'], platformRoot);
19
+ await runPulumi(deps, ['up', ...(options.yes ? ['--yes'] : [])], platformRoot);
20
+ const outputs = await loadPlatformOutputs(deps, platformRoot, stack, target.name);
21
+ return {
22
+ data: {
23
+ target: target.name,
24
+ stack,
25
+ platformRoot,
26
+ namespace: outputs.namespace,
27
+ registry: outputs.registry,
28
+ ...(outputs.endpoints === undefined ? {} : { endpoints: outputs.endpoints }),
29
+ },
30
+ text: `Platform target ${target.name} is up (stack ${stack}).${outputs.endpoints?.http === undefined
31
+ ? ''
32
+ : ` HTTP entrypoint: ${outputs.endpoints.http} (send the deployed project's configured name as the Host header).`}`,
33
+ };
34
+ }
35
+ export async function runWasmcloudPlatformDestroy(args, io, deps = DEFAULT_DEPS) {
36
+ const options = parsePlatformCommandArgs(args, 'platform cluster destroy');
37
+ const { target, platformRoot, stack } = loadManagedPlatform(deps, options.target);
38
+ io.stdout.write(`Destroying platform target ${target.name} (stack ${stack})...\n`);
39
+ await runPulumi(deps, ['install'], platformRoot);
40
+ await runPulumi(deps, ['stack', 'select', stack], platformRoot);
41
+ await runPulumi(deps, ['destroy', ...(options.yes ? ['--yes'] : [])], platformRoot);
42
+ return {
43
+ data: { target: target.name, stack, platformRoot },
44
+ text: `Destroyed platform target ${target.name} (stack ${stack}).`,
45
+ };
46
+ }
47
+ export async function loadPlatformOutputs(deps, platformRoot, stack, targetName) {
48
+ await runPulumi(deps, ['stack', 'select', stack], platformRoot);
49
+ const result = await deps.runCaptured('pulumi', ['stack', 'output', '--json'], {
50
+ cwd: platformRoot,
51
+ env: pulumiEnvironment(deps.env, platformRoot),
52
+ });
53
+ if (result.exitCode !== 0) {
54
+ throw new CommandFailure('WASMCLOUD_PLATFORM_NOT_READY', `Managed target "${targetName}" did not produce stack outputs. Deploy the platform first with: di-framework platform cluster up ${targetName}`, 3, { target: targetName, stack, platformRoot, exitCode: result.exitCode });
55
+ }
56
+ let raw;
57
+ try {
58
+ raw = JSON.parse(result.stdout);
59
+ }
60
+ catch (error) {
61
+ throw invalidOutputs(targetName, `pulumi stack output --json was not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
62
+ }
63
+ return materializeOutputs(raw, targetName, platformRoot);
64
+ }
65
+ export function resolvePlatformDirectory(target, workspaceRoot, manifestPath) {
66
+ const resolved = resolveInsideRoot(workspaceRoot, target.platform);
67
+ if (!resolved.ok) {
68
+ throw new CommandFailure('WASMCLOUD_DEPLOY_MANIFEST_INVALID', `Target "${target.name}" platform "${target.platform}" must be a directory inside the workspace`, 2, { target: target.name, platform: target.platform, manifestPath });
69
+ }
70
+ const pulumiFile = join(resolved.path, 'Pulumi.yaml');
71
+ if (!existsSync(pulumiFile)) {
72
+ throw new CommandFailure('WASMCLOUD_PLATFORM_NOT_FOUND', `Managed target "${target.name}" platform ${resolved.path} has no Pulumi.yaml. Point platform at a Pulumi project that provisions only the wasmCloud platform.`, 2, { target: target.name, platformRoot: resolved.path });
73
+ }
74
+ return resolved.path;
75
+ }
76
+ function loadManagedPlatform(deps, targetName) {
77
+ const manifest = loadDeployManifest(deps.cwd(), deps.env);
78
+ const target = manifest.targets[targetName];
79
+ if (target === undefined) {
80
+ throw new CommandFailure('WASMCLOUD_TARGET_NOT_FOUND', `Unknown target "${targetName}". Known targets: ${Object.keys(manifest.targets).join(', ')}`, 2, { target: targetName, targets: Object.keys(manifest.targets), manifestPath: manifest.path });
81
+ }
82
+ if (target.kind !== 'managed') {
83
+ throw new CommandFailure('WASMCLOUD_TARGET_INVALID', `Target "${target.name}" is kubeconfig-only and has no managed platform to deploy or destroy.`, 2, { target: target.name });
84
+ }
85
+ const platformRoot = resolvePlatformDirectory(target, manifest.workspaceRoot, manifest.path);
86
+ return { manifest, target, platformRoot, stack: target.stack };
87
+ }
88
+ function materializeOutputs(raw, targetName, platformRoot) {
89
+ if (!isRecord(raw)) {
90
+ throw invalidOutputs(targetName, 'stack outputs must be a JSON object');
91
+ }
92
+ if (raw.schemaVersion !== undefined &&
93
+ raw.schemaVersion !== 1 &&
94
+ raw.schemaVersion !== PLATFORM_OUTPUT_SCHEMA_VERSION) {
95
+ throw invalidOutputs(targetName, `unsupported schemaVersion ${JSON.stringify(raw.schemaVersion)}; expected ${PLATFORM_OUTPUT_SCHEMA_VERSION}`);
96
+ }
97
+ const kubeconfig = requiredString(raw.kubeconfig, 'kubeconfig', targetName);
98
+ const namespace = requiredString(raw.namespace, 'namespace', targetName);
99
+ if (!isNamespace(namespace))
100
+ throw invalidOutputs(targetName, 'namespace must be a Kubernetes namespace (a DNS label of at most 63 characters)');
101
+ const registry = parseRegistry(raw.registry, targetName);
102
+ const context = raw.context === undefined ? undefined : requiredString(raw.context, 'context', targetName);
103
+ const endpoints = parseEndpoints(raw.endpoints, targetName);
104
+ let kubeconfigPath = kubeconfig;
105
+ if (kubeconfig.includes('\n') || kubeconfig.includes('apiVersion:')) {
106
+ const generated = join(platformRoot, '.di-framework');
107
+ mkdirSync(generated, { recursive: true });
108
+ kubeconfigPath = join(generated, 'kubeconfig.yaml');
109
+ writeFileSync(kubeconfigPath, kubeconfig.endsWith('\n') ? kubeconfig : `${kubeconfig}\n`, {
110
+ mode: 0o600,
111
+ });
112
+ chmodSync(kubeconfigPath, 0o600);
113
+ }
114
+ else if (!isAbsolute(kubeconfigPath)) {
115
+ kubeconfigPath = resolve(platformRoot, kubeconfigPath);
116
+ }
117
+ return {
118
+ schemaVersion: PLATFORM_OUTPUT_SCHEMA_VERSION,
119
+ kubeconfig: kubeconfigPath,
120
+ namespace,
121
+ registry,
122
+ context,
123
+ endpoints,
124
+ };
125
+ }
126
+ function parseRegistry(value, targetName) {
127
+ if (typeof value === 'string') {
128
+ return materializeRegistry(requiredString(value, 'registry', targetName));
129
+ }
130
+ if (!isRecord(value)) {
131
+ throw invalidOutputs(targetName, '"registry" must be a string shorthand or an object with push, pull, and insecure');
132
+ }
133
+ const push = requiredString(value.push, 'registry.push', targetName);
134
+ const pull = requiredString(value.pull, 'registry.pull', targetName);
135
+ if (typeof value.insecure !== 'boolean') {
136
+ throw invalidOutputs(targetName, '"registry.insecure" must be a boolean');
137
+ }
138
+ const unknown = Object.keys(value).filter((key) => key !== 'push' && key !== 'pull' && key !== 'insecure');
139
+ if (unknown.length > 0) {
140
+ throw invalidOutputs(targetName, `"registry" has unsupported fields: ${unknown.join(', ')}`);
141
+ }
142
+ return materializeRegistry({ push, pull, insecure: value.insecure });
143
+ }
144
+ function parseEndpoints(value, targetName) {
145
+ if (value === undefined)
146
+ return undefined;
147
+ if (!isRecord(value)) {
148
+ throw invalidOutputs(targetName, 'endpoints must be an object when present');
149
+ }
150
+ const http = value.http === undefined ? undefined : requiredString(value.http, 'endpoints.http', targetName);
151
+ const kubernetes = value.kubernetes === undefined
152
+ ? undefined
153
+ : requiredString(value.kubernetes, 'endpoints.kubernetes', targetName);
154
+ const registry = value.registry === undefined
155
+ ? undefined
156
+ : requiredString(value.registry, 'endpoints.registry', targetName);
157
+ return { http, kubernetes, registry };
158
+ }
159
+ function requiredString(value, field, targetName) {
160
+ if (typeof value !== 'string' || value.trim() === '') {
161
+ throw invalidOutputs(targetName, `missing required output "${field}". The platform Pulumi program must export kubeconfig, namespace, and registry.`);
162
+ }
163
+ return value;
164
+ }
165
+ function invalidOutputs(targetName, message) {
166
+ return new CommandFailure('WASMCLOUD_PLATFORM_OUTPUT_INVALID', `Platform target "${targetName}" output contract is invalid: ${message}`, 2, { target: targetName, schemaVersion: PLATFORM_OUTPUT_SCHEMA_VERSION });
167
+ }
168
+ function isRecord(value) {
169
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
170
+ }
@@ -0,0 +1,39 @@
1
+ import { type WorkloadEntry } from './workload-members.js';
2
+ export declare const CONFIG_FILE_NAME = "di-framework.config.json";
3
+ export type WasmcloudProject = {
4
+ /** Display name exactly as configured. */
5
+ applicationName: string;
6
+ workload?: string;
7
+ workloadEntry?: WorkloadEntry;
8
+ /** Explicit actor deployment override for programmatically constructed projects. */
9
+ actors?: boolean;
10
+ /** Explicit WASI DNS allowlist, separate from outbound HTTP permissions. */
11
+ allowedIpNameLookups?: string[];
12
+ applicationType?: string;
13
+ configPath: string;
14
+ entryPath: string;
15
+ outputPath: string;
16
+ /** Absolute path to the bindings file when present or configured. */
17
+ bindingsPath: string | undefined;
18
+ /** True when `bindings` was set in di-framework.config.json. */
19
+ bindingsConfigured: boolean;
20
+ bindingsRelative: string;
21
+ projectRoot: string;
22
+ version: string;
23
+ /** `name` slugified into a WIT package identifier. */
24
+ witName: string;
25
+ /** Whether this component exposes an HTTP ingress handler. Defaults to true. */
26
+ ingress?: boolean;
27
+ /** Cron execution mode override. */
28
+ cronMode?: 'in-process' | 'external';
29
+ /**
30
+ * When true, deploy onto the single-replica storage hostgroup with a
31
+ * dedicated hostPath volume (SQLite / migration history).
32
+ */
33
+ persistentStorage?: boolean;
34
+ };
35
+ export declare function findUp(startDirectory: string, fileName: string): string | undefined;
36
+ /** Paths from the config must stay inside the project root. */
37
+ export declare function resolveInside(projectRoot: string, value: string, label: string, configPath: string): string;
38
+ export declare function asWitIdentifier(value: string): string;
39
+ export declare function loadProject(startDirectory: string): WasmcloudProject;
@@ -0,0 +1,130 @@
1
+ import { accessSync, constants, existsSync, readFileSync } from 'node:fs';
2
+ import { isIP } from 'node:net';
3
+ import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
4
+ import { CommandFailure } from '@di-framework/cli-extension';
5
+ import { discoverWorkloadEntry } from './workload-members.js';
6
+ export const CONFIG_FILE_NAME = 'di-framework.config.json';
7
+ export function findUp(startDirectory, fileName) {
8
+ let previous = '';
9
+ let current = resolve(startDirectory);
10
+ while (current !== previous) {
11
+ const candidate = join(current, fileName);
12
+ if (existsSync(candidate))
13
+ return candidate;
14
+ previous = current;
15
+ current = dirname(current);
16
+ }
17
+ return undefined;
18
+ }
19
+ function configInvalid(message, configPath) {
20
+ throw new CommandFailure('WASMCLOUD_CONFIG_INVALID', message, 2, { configPath });
21
+ }
22
+ /** Paths from the config must stay inside the project root. */
23
+ export function resolveInside(projectRoot, value, label, configPath) {
24
+ const absolutePath = resolve(projectRoot, value);
25
+ const relativePath = relative(projectRoot, absolutePath);
26
+ if (relativePath === '' ||
27
+ relativePath === '..' ||
28
+ relativePath.startsWith(`..${process.platform === 'win32' ? '\\' : '/'}`) ||
29
+ isAbsolute(relativePath)) {
30
+ configInvalid(`${label} must point to a file inside the project`, configPath);
31
+ }
32
+ return absolutePath;
33
+ }
34
+ export function asWitIdentifier(value) {
35
+ const collapsed = value.toLowerCase().replace(/[^a-z0-9-]+/g, '-');
36
+ let start = 0;
37
+ let end = collapsed.length;
38
+ while (start < end && collapsed[start] === '-')
39
+ start++;
40
+ while (end > start && collapsed[end - 1] === '-')
41
+ end--;
42
+ const identifier = collapsed.slice(start, end);
43
+ return /^[a-z]/.test(identifier) ? identifier : `app-${identifier || 'component'}`;
44
+ }
45
+ export function loadProject(startDirectory) {
46
+ const configPath = findUp(startDirectory, CONFIG_FILE_NAME);
47
+ if (configPath === undefined) {
48
+ throw new CommandFailure('WASMCLOUD_PROJECT_NOT_FOUND', `No ${CONFIG_FILE_NAME} found. Run this command from a DI Framework component project.`, 2, { startDirectory });
49
+ }
50
+ const projectRoot = dirname(configPath);
51
+ let config;
52
+ try {
53
+ config = JSON.parse(readFileSync(configPath, 'utf8'));
54
+ }
55
+ catch (error) {
56
+ configInvalid(`Could not parse ${configPath}: ${error instanceof Error ? error.message : String(error)}`, configPath);
57
+ }
58
+ if (typeof config.name !== 'string' || config.name.trim() === '') {
59
+ configInvalid(`${CONFIG_FILE_NAME} must contain a non-empty "name"`, configPath);
60
+ }
61
+ if (typeof config.entry !== 'string' || config.entry.trim() === '') {
62
+ configInvalid(`${CONFIG_FILE_NAME} must contain a non-empty "entry"`, configPath);
63
+ }
64
+ if (config.output !== undefined && typeof config.output !== 'string') {
65
+ configInvalid(`${CONFIG_FILE_NAME} "output" must be a string when present`, configPath);
66
+ }
67
+ if (config.bindings !== undefined && typeof config.bindings !== 'string') {
68
+ configInvalid(`${CONFIG_FILE_NAME} "bindings" must be a string when present`, configPath);
69
+ }
70
+ if (config.allowedIpNameLookups !== undefined &&
71
+ (!Array.isArray(config.allowedIpNameLookups) ||
72
+ config.allowedIpNameLookups.some((name) => typeof name !== 'string' ||
73
+ !(name === '*' ||
74
+ isIP(name) !== 0 ||
75
+ /^(?:\*\.)?[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i.test(name))))) {
76
+ configInvalid('allowedIpNameLookups must be an array of DNS names, IP addresses, or wildcard suffixes', configPath);
77
+ }
78
+ const witName = asWitIdentifier(config.name);
79
+ const entryPath = resolveInside(projectRoot, config.entry, 'entry', configPath);
80
+ const outputPath = resolveInside(projectRoot, config.output ?? `dist/${witName}.wasm`, 'output', configPath);
81
+ const bindingsValue = typeof config.bindings === 'string' ? config.bindings.trim() : '';
82
+ const bindingsConfigured = bindingsValue !== '';
83
+ const bindingsRelative = bindingsConfigured ? bindingsValue : 'src/bindings.ts';
84
+ const bindingsPath = resolveInside(projectRoot, bindingsRelative, 'bindings', configPath);
85
+ try {
86
+ accessSync(entryPath, constants.R_OK);
87
+ }
88
+ catch {
89
+ configInvalid(`entry "${config.entry}" is not readable`, configPath);
90
+ }
91
+ const packagePath = join(projectRoot, 'package.json');
92
+ const packageJson = existsSync(packagePath)
93
+ ? JSON.parse(readFileSync(packagePath, 'utf8'))
94
+ : {};
95
+ const version = typeof packageJson.version === 'string' &&
96
+ /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(packageJson.version)
97
+ ? packageJson.version
98
+ : '0.1.0';
99
+ if (config.workload !== undefined &&
100
+ (typeof config.workload !== 'string' ||
101
+ !/^[a-z][a-z0-9-]{0,61}[a-z0-9]$|^[a-z]$/.test(config.workload))) {
102
+ configInvalid('workload must be a DNS label of at most 63 characters', configPath);
103
+ }
104
+ const workload = config.workload;
105
+ const workloadEntry = workload ? discoverWorkloadEntry(entryPath, workload) : undefined;
106
+ const ingress = workloadEntry
107
+ ? workloadEntry.kind === 'component' && workloadEntry.path !== undefined
108
+ : config.ingress !== false && config.http !== false;
109
+ const cronMode = config.cronMode === 'external' ? 'external' : undefined;
110
+ const persistentStorage = config.persistentStorage === true;
111
+ return {
112
+ applicationName: config.name,
113
+ ...(workload ? { workload, workloadEntry } : {}),
114
+ ingress,
115
+ ...(cronMode ? { cronMode } : {}),
116
+ ...(persistentStorage ? { persistentStorage: true } : {}),
117
+ ...(config.allowedIpNameLookups === undefined
118
+ ? {}
119
+ : { allowedIpNameLookups: config.allowedIpNameLookups }),
120
+ configPath,
121
+ entryPath,
122
+ outputPath,
123
+ bindingsPath,
124
+ bindingsConfigured,
125
+ bindingsRelative,
126
+ projectRoot,
127
+ version,
128
+ witName,
129
+ };
130
+ }
@@ -0,0 +1,15 @@
1
+ import type { CliIo } from '@di-framework/cli-extension';
2
+ import type { WasmcloudDeps } from './deps.js';
3
+ import type { WasmcloudProject } from './project.js';
4
+ import type { ClusterConnection } from './target.js';
5
+ export type PublishedImage = {
6
+ artifactDigest: string;
7
+ digest: string;
8
+ pullReference: string;
9
+ pushReference: string;
10
+ reference: string;
11
+ };
12
+ export declare function contentDigest(filePath: string): string;
13
+ export declare function ociReference(registry: string, repository: string, digest: string): string;
14
+ export declare function publishComponent(project: WasmcloudProject, connection: ClusterConnection, io: CliIo, deps: WasmcloudDeps, deploymentDigest: string): Promise<PublishedImage>;
15
+ export declare function projectRelativePath(projectRoot: string, path: string): string;
@@ -0,0 +1,57 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readFileSync } from 'node:fs';
3
+ import { isAbsolute, join, relative, sep } from 'node:path';
4
+ import { registryReferenceHost, registryUsesPlainHttp } from './registry.js';
5
+ import { toolFailed } from './support.js';
6
+ export function contentDigest(filePath) {
7
+ return createHash('sha256').update(readFileSync(filePath)).digest('hex');
8
+ }
9
+ export function ociReference(registry, repository, digest) {
10
+ return `${registryReferenceHost(registry)}/${repository}:sha256-${digest}`;
11
+ }
12
+ export async function publishComponent(project, connection, io, deps, deploymentDigest) {
13
+ const artifactDigest = contentDigest(project.outputPath);
14
+ const pushReference = ociReference(connection.registry.push, project.witName, deploymentDigest);
15
+ const pullReference = ociReference(connection.registry.pull, project.witName, deploymentDigest);
16
+ const configPath = join(project.projectRoot, '.di-framework', 'oci-config.json');
17
+ const componentPath = projectRelativePath(project.projectRoot, project.outputPath);
18
+ const projectConfigPath = projectRelativePath(project.projectRoot, configPath);
19
+ io.stdout.write(`Publishing ${componentPath} as ${pushReference}...\n`);
20
+ const transportArgs = registryUsesPlainHttp(connection.registry) ? ['--plain-http'] : [];
21
+ const existing = await deps.runCaptured('oras', ['manifest', 'fetch', ...transportArgs, '--descriptor', pushReference], { cwd: project.projectRoot });
22
+ if (existing.exitCode === 0) {
23
+ io.stdout.write(`OCI tag ${pushReference} already exists; keeping it immutable.\n`);
24
+ return {
25
+ artifactDigest,
26
+ digest: deploymentDigest,
27
+ pullReference,
28
+ pushReference,
29
+ reference: pushReference,
30
+ };
31
+ }
32
+ const pushed = await deps.runner('oras', [
33
+ 'push',
34
+ ...transportArgs,
35
+ '--config',
36
+ `${projectConfigPath}:application/vnd.wasm.config.v0+json`,
37
+ pushReference,
38
+ `${componentPath}:application/wasm`,
39
+ ], { cwd: project.projectRoot });
40
+ if (pushed.exitCode !== 0) {
41
+ throw toolFailed('oras push', pushed.exitCode);
42
+ }
43
+ return {
44
+ artifactDigest,
45
+ digest: deploymentDigest,
46
+ pullReference,
47
+ pushReference,
48
+ reference: pushReference,
49
+ };
50
+ }
51
+ export function projectRelativePath(projectRoot, path) {
52
+ const value = relative(projectRoot, path);
53
+ if (value === '' || value === '..' || value.startsWith(`..${sep}`) || isAbsolute(value)) {
54
+ throw new Error(`OCI artifact path must be inside the project: ${path}`);
55
+ }
56
+ return value.split(sep).join('/');
57
+ }
@@ -0,0 +1,4 @@
1
+ import type { WasmcloudDeps } from './deps.js';
2
+ /** Local file backend and passphrase defaults, without touching the caller's environment. */
3
+ export declare function pulumiEnvironment(env: Record<string, string | undefined>, projectRoot?: string): Record<string, string | undefined>;
4
+ export declare function runPulumi(deps: WasmcloudDeps, args: readonly string[], cwd: string): Promise<void>;
package/dist/pulumi.js ADDED
@@ -0,0 +1,27 @@
1
+ import { mkdirSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { toolFailed } from './support.js';
5
+ /** Local file backend and passphrase defaults, without touching the caller's environment. */
6
+ export function pulumiEnvironment(env, projectRoot) {
7
+ return {
8
+ ...env,
9
+ PULUMI_BACKEND_URL: env.PULUMI_BACKEND_URL ??
10
+ (projectRoot === undefined
11
+ ? 'file://~'
12
+ : pathToFileURL(join(projectRoot, '.pulumi-state')).href),
13
+ PULUMI_CONFIG_PASSPHRASE: env.PULUMI_CONFIG_PASSPHRASE ?? 'local-dev',
14
+ };
15
+ }
16
+ export async function runPulumi(deps, args, cwd) {
17
+ if (deps.env.PULUMI_BACKEND_URL === undefined) {
18
+ mkdirSync(join(cwd, '.pulumi-state'), { recursive: true });
19
+ }
20
+ const result = await deps.runner('pulumi', args, {
21
+ cwd,
22
+ env: pulumiEnvironment(deps.env, cwd),
23
+ });
24
+ if (result.exitCode !== 0) {
25
+ throw toolFailed(`pulumi ${args[0]}`, result.exitCode);
26
+ }
27
+ }
@@ -0,0 +1,4 @@
1
+ import type { DiscoveredQueueHandler } from './queues.js';
2
+ /** Generated module that opens SQLite-backed queues and pumps workers per request. */
3
+ export declare function renderQueuesModule(handlers: readonly DiscoveredQueueHandler[]): string;
4
+ export declare function emptyQueuesModule(): string;
@@ -0,0 +1,89 @@
1
+ /** Generated module that opens SQLite-backed queues and pumps workers per request. */
2
+ export function renderQueuesModule(handlers) {
3
+ return `import { WasmSqliteQueueBackend, QueueWorker, ContainerQueueDispatcher } from '@di-framework/queues';
4
+ import { loadApplication } from 'virtual:di-framework-wasmcloud-runtime';
5
+
6
+ const handlerConfig = ${JSON.stringify(handlers.map((handler) => ({
7
+ queueName: handler.queueName,
8
+ className: handler.className,
9
+ methodName: handler.methodName,
10
+ options: handler.options,
11
+ })), null, 2)};
12
+
13
+ let queueBackend;
14
+ let queueWorker;
15
+ let workerReady;
16
+ let workerInit;
17
+
18
+ function resolveQueueDbPath() {
19
+ const storageDir = process.env.DI_STORAGE_DIR || '.';
20
+ return process.env.QUEUE_DB_PATH || (storageDir.replace(/\\/$/, '') + '/queue.db');
21
+ }
22
+
23
+ export function getQueueBackend() {
24
+ if (!queueBackend) {
25
+ queueBackend = new WasmSqliteQueueBackend(resolveQueueDbPath());
26
+ }
27
+ return queueBackend;
28
+ }
29
+
30
+ async function ensureWorker() {
31
+ if (workerReady) return workerReady;
32
+ if (!workerInit) {
33
+ workerInit = (async () => {
34
+ const backend = getQueueBackend();
35
+ const application = await loadApplication();
36
+ const exported = application.default ?? application;
37
+ const container = exported?.container ?? exported;
38
+ // Prefer the nested ContainerQueueDispatcher (apps attach it as \`default\`).
39
+ // Do NOT treat itty-router's \`dispatch\` as a queue dispatcher.
40
+ const dispatcher =
41
+ exported instanceof ContainerQueueDispatcher
42
+ ? exported
43
+ : exported?.default instanceof ContainerQueueDispatcher
44
+ ? exported.default
45
+ : new ContainerQueueDispatcher(container);
46
+ const queues = handlerConfig.map((handler) => handler.queueName);
47
+ const concurrency = Math.max(
48
+ 1,
49
+ ...handlerConfig.map((handler) => {
50
+ const envName =
51
+ 'DI_QUEUE_' +
52
+ handler.queueName.replace(/[^A-Za-z0-9]/g, '_').toUpperCase() +
53
+ '_CONCURRENCY';
54
+ return Number(process.env[envName] ?? handler.options.concurrency ?? 1);
55
+ }),
56
+ );
57
+ // Wasm HTTP tasks are request-scoped: do not start setTimeout poll loops.
58
+ queueWorker = new QueueWorker(backend, dispatcher, { queues, concurrency });
59
+ workerReady = queueWorker;
60
+ return queueWorker;
61
+ })().catch((error) => {
62
+ workerInit = undefined;
63
+ workerReady = undefined;
64
+ throw error;
65
+ });
66
+ }
67
+ return workerInit;
68
+ }
69
+
70
+ export async function ensureQueueWorkers() {
71
+ await ensureWorker();
72
+ }
73
+
74
+ /** Drain pending jobs during this HTTP invocation (request-driven Wasm worker). */
75
+ export async function pumpQueueWorkers(maxJobsPerQueue = 32) {
76
+ const worker = await ensureWorker();
77
+ return worker.pump(maxJobsPerQueue);
78
+ }
79
+
80
+ export const queueHandlers = handlerConfig;
81
+ `;
82
+ }
83
+ export function emptyQueuesModule() {
84
+ return `export const queueBackend = undefined;
85
+ export function getQueueBackend() { return undefined; }
86
+ export async function ensureQueueWorkers() {}
87
+ export async function pumpQueueWorkers() { return 0; }
88
+ `;
89
+ }
@@ -0,0 +1,16 @@
1
+ import type { WasmcloudProject } from './project.js';
2
+ export type DiscoveredQueueHandler = {
3
+ className: string;
4
+ methodName: string;
5
+ queueName: string;
6
+ filePath: string;
7
+ options: {
8
+ maxRetries?: number;
9
+ backoffMs?: number;
10
+ timeoutMs?: number;
11
+ concurrency?: number;
12
+ };
13
+ };
14
+ export declare function parseQueueHandlersInFile(filePath: string): DiscoveredQueueHandler[];
15
+ export declare function discoverQueueHandlers(project: WasmcloudProject): DiscoveredQueueHandler[];
16
+ export declare function isQueueWorkerProject(project: WasmcloudProject, queueHandlers: readonly DiscoveredQueueHandler[]): boolean;