@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.
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,182 @@
1
+ import * as fs from 'node:fs';
2
+ import { join, relative, resolve, sep } from 'node:path';
3
+ import { CommandFailure } from '@di-framework/cli-extension';
4
+ import { ALWAYS_SKIP_DIRECTORIES } from './manifest.js';
5
+ import { isInside } from './paths.js';
6
+ import { CONFIG_FILE_NAME, loadProject } from './project.js';
7
+ export function discoverProjects(workspaceRoot, discovery) {
8
+ const configs = findConfigFiles(workspaceRoot, discovery);
9
+ const byName = new Map();
10
+ for (const configPath of configs) {
11
+ const project = loadProject(configPath);
12
+ const existing = byName.get(project.applicationName) ?? [];
13
+ existing.push(project);
14
+ byName.set(project.applicationName, existing);
15
+ }
16
+ const duplicates = [...byName.entries()].filter(([, projects]) => projects.length > 1);
17
+ if (duplicates.length > 0) {
18
+ const [name, projects] = duplicates[0] ?? ['', []];
19
+ const paths = projects.map((project) => project.configPath);
20
+ throw new CommandFailure('WASMCLOUD_DUPLICATE_PROJECT', `Duplicate project name "${name}" found in:\n${paths.map((path) => ` ${path}`).join('\n')}`, 2, { name, paths });
21
+ }
22
+ return new Map([...byName.entries()].map(([name, projects]) => [name, projects[0]]));
23
+ }
24
+ export function resolveApplication(startDirectory, name, workspaceRoot, discovery) {
25
+ if (name === undefined) {
26
+ const project = loadProject(startDirectory);
27
+ if (!isInside(workspaceRoot, project.projectRoot)) {
28
+ throw new CommandFailure('WASMCLOUD_PROJECT_NOT_FOUND', `Nearest project ${project.configPath} is outside the workspace ${workspaceRoot}`, 2, { startDirectory, configPath: project.configPath, workspaceRoot });
29
+ }
30
+ return project;
31
+ }
32
+ const projects = discoverProjects(workspaceRoot, discovery);
33
+ const match = projects.get(name);
34
+ if (match === undefined) {
35
+ const known = [...projects.keys()].sort();
36
+ throw new CommandFailure('WASMCLOUD_PROJECT_NOT_FOUND', known.length === 0
37
+ ? `No project named "${name}" found in the workspace.`
38
+ : `No project named "${name}" found in the workspace. Known projects: ${known.join(', ')}`, 2, { name, workspaceRoot, known });
39
+ }
40
+ return match;
41
+ }
42
+ export function findConfigFiles(workspaceRoot, discovery) {
43
+ const logicalRoot = resolve(workspaceRoot);
44
+ let realRoot;
45
+ try {
46
+ realRoot = fs.realpathSync(logicalRoot);
47
+ }
48
+ catch {
49
+ return [];
50
+ }
51
+ const matches = [];
52
+ const visited = new Set();
53
+ walk(logicalRoot, realRoot, logicalRoot, discovery, visited, matches);
54
+ return matches.sort();
55
+ }
56
+ function walk(logicalRoot, realRoot, directory, discovery, visited, matches) {
57
+ let realDirectory;
58
+ try {
59
+ realDirectory = fs.realpathSync(directory);
60
+ }
61
+ catch {
62
+ return;
63
+ }
64
+ if (visited.has(realDirectory) || !isInside(realRoot, realDirectory))
65
+ return;
66
+ visited.add(realDirectory);
67
+ for (const entry of readDirents(directory)) {
68
+ const fullPath = join(directory, entry.name);
69
+ let isDirectory = entry.isDirectory();
70
+ let isFile = entry.isFile();
71
+ if (entry.isSymbolicLink()) {
72
+ let realPath;
73
+ try {
74
+ realPath = fs.realpathSync(fullPath);
75
+ }
76
+ catch {
77
+ continue;
78
+ }
79
+ if (!isInside(realRoot, realPath))
80
+ continue;
81
+ const stated = statLinkTarget(realPath);
82
+ if (stated === undefined)
83
+ continue;
84
+ isDirectory = stated.isDirectory;
85
+ isFile = stated.isFile;
86
+ if (isDirectory && visited.has(realPath))
87
+ continue;
88
+ }
89
+ if (isDirectory) {
90
+ if (ALWAYS_SKIP_DIRECTORIES.has(entry.name))
91
+ continue;
92
+ const relativeDirectory = relativePath(logicalRoot, fullPath);
93
+ if (isExcluded(relativeDirectory, discovery.exclude))
94
+ continue;
95
+ walk(logicalRoot, realRoot, fullPath, discovery, visited, matches);
96
+ continue;
97
+ }
98
+ if (isFile && entry.name === CONFIG_FILE_NAME) {
99
+ const relativeFile = relativePath(logicalRoot, fullPath);
100
+ if (isExcluded(relativeFile, discovery.exclude))
101
+ continue;
102
+ if (!isIncluded(relativeFile, discovery.include))
103
+ continue;
104
+ try {
105
+ if (fs.lstatSync(fullPath).isSymbolicLink()) {
106
+ const realPath = fs.realpathSync(fullPath);
107
+ if (!isInside(realRoot, realPath))
108
+ continue;
109
+ }
110
+ }
111
+ catch {
112
+ continue;
113
+ }
114
+ matches.push(fullPath);
115
+ }
116
+ }
117
+ }
118
+ export function readDirents(directory) {
119
+ try {
120
+ return [...fs.readdirSync(directory, { withFileTypes: true })];
121
+ }
122
+ catch {
123
+ return [];
124
+ }
125
+ }
126
+ export function statLinkTarget(path) {
127
+ try {
128
+ const stat = fs.statSync(path);
129
+ return { isDirectory: stat.isDirectory(), isFile: stat.isFile() };
130
+ }
131
+ catch {
132
+ return undefined;
133
+ }
134
+ }
135
+ function relativePath(root, absolutePath) {
136
+ return relative(root, absolutePath).split(sep).join('/');
137
+ }
138
+ export function isIncluded(relativeFile, patterns) {
139
+ return patterns.some((pattern) => matchGlob(relativeFile, pattern));
140
+ }
141
+ export function isExcluded(relativePathValue, patterns) {
142
+ return patterns.some((pattern) => matchGlob(relativePathValue, pattern) || matchGlob(`${relativePathValue}/**`, pattern));
143
+ }
144
+ export function matchGlob(path, pattern) {
145
+ return globToRegExp(pattern.replaceAll('\\', '/')).test(path.replaceAll('\\', '/'));
146
+ }
147
+ function globToRegExp(pattern) {
148
+ let index = 0;
149
+ let source = '^';
150
+ const normalized = pattern.replace(/^\.\//, '');
151
+ while (index < normalized.length) {
152
+ const character = normalized[index] ?? '';
153
+ if (character === '*' && normalized[index + 1] === '*') {
154
+ if (normalized[index + 2] === '/') {
155
+ source += '(?:.*/)?';
156
+ index += 3;
157
+ }
158
+ else {
159
+ source += '.*';
160
+ index += 2;
161
+ }
162
+ continue;
163
+ }
164
+ if (character === '*') {
165
+ source += '[^/]*';
166
+ index += 1;
167
+ continue;
168
+ }
169
+ if (character === '?') {
170
+ source += '[^/]';
171
+ index += 1;
172
+ continue;
173
+ }
174
+ if ('\\^$+{}()|[]'.includes(character))
175
+ source += `\\${character}`;
176
+ else
177
+ source += character;
178
+ index += 1;
179
+ }
180
+ source += '$';
181
+ return new RegExp(source);
182
+ }
@@ -0,0 +1,8 @@
1
+ import type { CliIo, CommandResult } from '@di-framework/cli-extension';
2
+ import { type WasmcloudDeps } from './deps.js';
3
+ export type DoctorCheck = {
4
+ name: string;
5
+ ok: boolean;
6
+ detail?: string;
7
+ };
8
+ export declare function runWasmcloudDoctor(args: readonly string[], _io: CliIo, deps?: WasmcloudDeps): Promise<CommandResult>;
package/dist/doctor.js ADDED
@@ -0,0 +1,82 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { relative } from 'node:path';
3
+ import { discoverBindings } from './bindings.js';
4
+ import { DEFAULT_DEPS } from './deps.js';
5
+ import { requiresWasmCloudHost, resolveDevRunner } from './dev-runner.js';
6
+ import { loadProject } from './project.js';
7
+ import { invalidUsage } from './support.js';
8
+ export async function runWasmcloudDoctor(args, _io, deps = DEFAULT_DEPS) {
9
+ if (args.length > 0) {
10
+ invalidUsage(`platform doctor does not accept arguments: ${args[0]}`, args[0] ?? '');
11
+ }
12
+ const project = loadProject(deps.cwd());
13
+ const check = (name, detail) => detail === undefined ? { name, ok: false } : { name, ok: true, detail };
14
+ const checks = [
15
+ check('Bun', Bun.version),
16
+ check('Node.js', deps.nodeBinaryPath() && deps.capture('node', ['--version'])),
17
+ check('@di-framework/core', deps.resolveFromProject(project.projectRoot, '@di-framework/core')),
18
+ check('@di-framework/http', deps.resolveFromProject(project.projectRoot, '@di-framework/http')),
19
+ ...(existsSync(project.bindingsPath ?? '')
20
+ ? [
21
+ check('@di-framework/bindings', deps.resolveFromProject(project.projectRoot, '@di-framework/bindings')),
22
+ ]
23
+ : []),
24
+ check('Pulumi', deps.capture('pulumi', ['version'])),
25
+ check('Docker', deps.capture('docker', ['version', '--format', '{{.Server.Version}}'])),
26
+ check('kubectl', deps.capture('kubectl', ['version', '--client', '--output=yaml'])),
27
+ check('oras', deps.capture('oras', ['version'])),
28
+ ];
29
+ let discoveredBindings;
30
+ let bindingsError;
31
+ if (existsSync(project.bindingsPath ?? '')) {
32
+ try {
33
+ discoveredBindings = discoverBindings(project, deps);
34
+ }
35
+ catch (error) {
36
+ bindingsError = error instanceof Error ? error.message : String(error);
37
+ }
38
+ }
39
+ let runnerDetail;
40
+ try {
41
+ runnerDetail = resolveDevRunner(deps, {
42
+ wasmCloudHost: requiresWasmCloudHost((discoveredBindings ?? []).map((binding) => binding.requirement)),
43
+ }).kind;
44
+ }
45
+ catch {
46
+ runnerDetail = undefined;
47
+ }
48
+ checks.push(check('dev runner', runnerDetail));
49
+ if (discoveredBindings !== undefined) {
50
+ for (const binding of discoveredBindings) {
51
+ const secret = binding.secretFrom === undefined ? 'no secret ref' : `secretFrom ${binding.secretFrom}`;
52
+ checks.push({
53
+ name: `binding ${binding.name}`,
54
+ ok: true,
55
+ detail: `${binding.className} ${binding.requirement.package}@${binding.requirement.version} (${secret})`,
56
+ });
57
+ }
58
+ }
59
+ else if (bindingsError !== undefined) {
60
+ checks.push({
61
+ name: 'bindings',
62
+ ok: false,
63
+ detail: bindingsError,
64
+ });
65
+ }
66
+ const failed = checks.some((entry) => !entry.ok);
67
+ const lines = [
68
+ `${project.applicationName}`,
69
+ '',
70
+ ...checks.map((entry) => entry.ok ? `✓ ${entry.name}: ${entry.detail}` : `✗ ${entry.name} is unavailable`),
71
+ '',
72
+ `Contract: incoming HTTP → default export in ${relative(project.projectRoot, project.entryPath)}`,
73
+ ];
74
+ return {
75
+ data: {
76
+ application: project.applicationName,
77
+ checks: checks.map((entry) => ({ ...entry })),
78
+ },
79
+ text: lines.join('\n'),
80
+ exitCode: failed ? 1 : 0,
81
+ };
82
+ }
@@ -0,0 +1,9 @@
1
+ import type { BindingRecord } from './bindings.js';
2
+ /** Must match `@di-framework/bindings` `WASMCLOUD_GUESTS_GLOBAL`. */
3
+ export declare const WASMCLOUD_GUESTS_GLOBAL = "di-framework.wasmcloud.guests";
4
+ /**
5
+ * ES module of real WIT guest imports. Evaluating it installs the guests on
6
+ * `globalThis` before the application module runs.
7
+ */
8
+ export declare function renderGuestsModule(bindings: readonly BindingRecord[]): string;
9
+ export declare function emptyGuestsModule(): string;
package/dist/guests.js ADDED
@@ -0,0 +1,56 @@
1
+ /** Must match `@di-framework/bindings` `WASMCLOUD_GUESTS_GLOBAL`. */
2
+ export const WASMCLOUD_GUESTS_GLOBAL = 'di-framework.wasmcloud.guests';
3
+ function specifierFor(binding, iface) {
4
+ if (binding.serviceName && iface !== 'types')
5
+ return `${binding.name}-${iface}`;
6
+ return `${binding.requirement.package}/${iface}@${binding.requirement.version}`;
7
+ }
8
+ /**
9
+ * ES module of real WIT guest imports. Evaluating it installs the guests on
10
+ * `globalThis` before the application module runs.
11
+ */
12
+ export function renderGuestsModule(bindings) {
13
+ const lines = [];
14
+ const specifierIdents = new Map();
15
+ const entries = [];
16
+ let next = 0;
17
+ for (const binding of bindings) {
18
+ const idents = [];
19
+ for (const iface of binding.requirement.interfaces) {
20
+ // `types` is a shared WIT types package (no funcs). qjs cannot resolve it
21
+ // as a JS module; query/prepared `use` the same types at the WIT layer.
22
+ if (iface === 'types')
23
+ continue;
24
+ const specifier = specifierFor(binding, iface);
25
+ let ident = specifierIdents.get(specifier);
26
+ if (ident === undefined) {
27
+ ident = `guest${next}`;
28
+ next += 1;
29
+ specifierIdents.set(specifier, ident);
30
+ lines.push(`import * as ${ident} from ${JSON.stringify(specifier)};`);
31
+ }
32
+ idents.push(ident);
33
+ }
34
+ const value = idents.length === 0
35
+ ? '{}'
36
+ : idents.length === 1
37
+ ? (idents[0] ?? '{}')
38
+ : `Object.assign({}, ${idents.join(', ')})`;
39
+ entries.push(` ${JSON.stringify(binding.name)}: ${value},`);
40
+ }
41
+ if (lines.length > 0)
42
+ lines.push('');
43
+ lines.push('const guests = {');
44
+ lines.push(...entries);
45
+ lines.push('};', '');
46
+ lines.push(`globalThis[Symbol.for(${JSON.stringify(WASMCLOUD_GUESTS_GLOBAL)})] = guests;`, '', 'export { guests };', '');
47
+ return lines.join('\n');
48
+ }
49
+ export function emptyGuestsModule() {
50
+ return [
51
+ 'const guests = {};',
52
+ `globalThis[Symbol.for(${JSON.stringify(WASMCLOUD_GUESTS_GLOBAL)})] = guests;`,
53
+ 'export { guests };',
54
+ '',
55
+ ].join('\n');
56
+ }
@@ -0,0 +1,29 @@
1
+ import { type WitRequirement } from './wit.js';
2
+ export type HostInterface = {
3
+ name?: string;
4
+ namespace: string;
5
+ package: string;
6
+ version: string;
7
+ interfaces: string[];
8
+ config?: Record<string, string>;
9
+ configFrom?: Array<{
10
+ name: string;
11
+ }>;
12
+ secretFrom?: Array<{
13
+ name: string;
14
+ }>;
15
+ };
16
+ export type HostInterfaceOptions = {
17
+ httpHost?: string;
18
+ subscriptions?: string[];
19
+ };
20
+ export type BindingHostOverlay = {
21
+ name: string;
22
+ className: string;
23
+ config?: Record<string, string>;
24
+ configFrom?: string;
25
+ secretFrom?: string;
26
+ };
27
+ export declare function hostInterfacesFromRequirements(requirements: readonly WitRequirement[], options?: HostInterfaceOptions, overlays?: readonly BindingHostOverlay[]): HostInterface[];
28
+ export declare function renderHostInterfacesYaml(interfaces: readonly HostInterface[]): string;
29
+ export declare function yamlQuote(value: string): string;
@@ -0,0 +1,142 @@
1
+ import { aggregateRequirements, parsePackageId, WASI_HTTP_INTERFACE, WASI_HTTP_PACKAGE, WASI_RANDOM_PACKAGE, WASI_SOCKETS_PACKAGE, } from './wit.js';
2
+ // These providers link QuickJS's unlabeled imports through their default route.
3
+ // Supplying a name selects the implements route, which cannot link those imports.
4
+ const UNLABELED_HOST_PACKAGES = new Set([
5
+ 'wasmcloud:postgres',
6
+ 'wasmcloud:keyvalue',
7
+ 'wasmcloud:blobstore',
8
+ 'wasmcloud:messaging',
9
+ 'wasmcloud:secrets',
10
+ ]);
11
+ function hostInterfaceFromRequirement(requirement, options) {
12
+ const { namespace, name } = parsePackageId(requirement.package);
13
+ const entry = {
14
+ namespace,
15
+ package: name,
16
+ version: requirement.version,
17
+ // Key-value resource types are linked internally, not advertised by the provider.
18
+ interfaces: requirement.package === 'wasmcloud:keyvalue' ||
19
+ (requirement.package === 'wasmcloud:postgres' &&
20
+ requirement.interfaces.every((iface) => iface === 'types'))
21
+ ? requirement.interfaces.filter((iface) => iface !== 'types')
22
+ : [...requirement.interfaces],
23
+ };
24
+ if (requirement.instanceName !== undefined &&
25
+ (requirement.namedImport || !UNLABELED_HOST_PACKAGES.has(requirement.package))) {
26
+ entry.name = requirement.instanceName;
27
+ }
28
+ if (requirement.package === WASI_HTTP_PACKAGE &&
29
+ requirement.interfaces.includes(WASI_HTTP_INTERFACE) &&
30
+ options.httpHost !== undefined) {
31
+ entry.config = { host: options.httpHost };
32
+ }
33
+ if (requirement.package === 'wasmcloud:messaging' && options.subscriptions) {
34
+ entry.config = { ...entry.config, subscriptions: options.subscriptions.join(',') };
35
+ }
36
+ return entry;
37
+ }
38
+ export function hostInterfacesFromRequirements(requirements, options = {}, overlays = []) {
39
+ const byName = new Map(overlays.map((overlay) => [overlay.name, overlay]));
40
+ const entries = aggregateRequirements(requirements)
41
+ .filter((requirement) => requirement.package !== WASI_SOCKETS_PACKAGE &&
42
+ requirement.package !== WASI_RANDOM_PACKAGE &&
43
+ requirement.package !== 'wasi:tls' &&
44
+ requirement.package !== 'wasi:clocks')
45
+ .map((requirement) => {
46
+ const entry = hostInterfaceFromRequirement(requirement, options);
47
+ const overlay = requirement.instanceName !== undefined
48
+ ? (byName.get(requirement.instanceName) ??
49
+ (requirement.namedImport
50
+ ? overlays.find((candidate) => requirement.sources.includes(candidate.className))
51
+ : undefined))
52
+ : overlays.find((candidate) => requirement.sources.includes(candidate.className));
53
+ if (requirement.package === 'wasmcloud:postgres' &&
54
+ requirement.interfaces.every((iface) => iface === 'types'))
55
+ return entry;
56
+ if (overlay === undefined)
57
+ return entry;
58
+ if (overlay.config !== undefined) {
59
+ entry.config = { ...entry.config, ...overlay.config };
60
+ }
61
+ if (overlay.configFrom !== undefined)
62
+ entry.configFrom = [{ name: overlay.configFrom }];
63
+ if (overlay.secretFrom !== undefined)
64
+ entry.secretFrom = [{ name: overlay.secretFrom }];
65
+ return entry;
66
+ });
67
+ return mergeHttpHostInterfaces(entries);
68
+ }
69
+ function mergeHttpHostInterfaces(entries) {
70
+ const merged = [];
71
+ for (const entry of entries) {
72
+ // Import/export directions belong to the WIT world, but the CRD requires one
73
+ // unnamed host entry per package/version. Preserve overlays from both sides.
74
+ const existing = ((entry.namespace === 'wasi' && entry.package === 'http') ||
75
+ (entry.namespace === 'wasmcloud' && entry.package === 'messaging')) &&
76
+ entry.name === undefined
77
+ ? merged.find((candidate) => candidate.namespace === entry.namespace &&
78
+ candidate.package === entry.package &&
79
+ candidate.version === entry.version &&
80
+ candidate.name === undefined)
81
+ : undefined;
82
+ if (existing === undefined) {
83
+ merged.push(entry);
84
+ continue;
85
+ }
86
+ existing.interfaces = [...new Set([...existing.interfaces, ...entry.interfaces])];
87
+ if (entry.config !== undefined)
88
+ existing.config = { ...existing.config, ...entry.config };
89
+ if (entry.configFrom !== undefined) {
90
+ existing.configFrom = [...(existing.configFrom ?? []), ...entry.configFrom];
91
+ }
92
+ if (entry.secretFrom !== undefined) {
93
+ existing.secretFrom = [...(existing.secretFrom ?? []), ...entry.secretFrom];
94
+ }
95
+ }
96
+ // The core links wasi:http/client; only handler is advertised by the ingress
97
+ // provider. This changes host discovery, never the guest's WIT imports.
98
+ return merged
99
+ .map((entry) => entry.namespace === 'wasi' && entry.package === 'http'
100
+ ? { ...entry, interfaces: entry.interfaces.filter((iface) => iface !== 'client') }
101
+ : entry)
102
+ .filter((entry) => entry.interfaces.length > 0);
103
+ }
104
+ export function renderHostInterfacesYaml(interfaces) {
105
+ if (interfaces.length === 0)
106
+ return '';
107
+ const lines = [' hostInterfaces:'];
108
+ for (const entry of interfaces) {
109
+ if (entry.name !== undefined) {
110
+ lines.push(` - name: ${yamlQuote(entry.name)}`);
111
+ lines.push(` namespace: ${entry.namespace}`);
112
+ }
113
+ else {
114
+ lines.push(` - namespace: ${entry.namespace}`);
115
+ }
116
+ lines.push(` package: ${entry.package}`);
117
+ lines.push(` version: ${yamlQuote(entry.version)}`);
118
+ lines.push(' interfaces:');
119
+ for (const iface of entry.interfaces)
120
+ lines.push(` - ${iface}`);
121
+ if (entry.config !== undefined) {
122
+ lines.push(' config:');
123
+ for (const [key, value] of Object.entries(entry.config)) {
124
+ lines.push(` ${yamlQuote(key)}: ${yamlQuote(value)}`);
125
+ }
126
+ }
127
+ if (entry.configFrom !== undefined) {
128
+ lines.push(' configFrom:');
129
+ for (const ref of entry.configFrom)
130
+ lines.push(` - name: ${yamlQuote(ref.name)}`);
131
+ }
132
+ if (entry.secretFrom !== undefined) {
133
+ lines.push(' secretFrom:');
134
+ for (const ref of entry.secretFrom)
135
+ lines.push(` - name: ${yamlQuote(ref.name)}`);
136
+ }
137
+ }
138
+ return lines.join('\n');
139
+ }
140
+ export function yamlQuote(value) {
141
+ return JSON.stringify(value);
142
+ }
@@ -0,0 +1,33 @@
1
+ export { type DiscoveredCronJob, discoverScheduledJobs, discoverScheduledJobsInFile, normalizeCronExpression, renderCronAdapterModule, renderCronInvokerModule, } from './cron.js';
2
+ export { ACTORS_INVOCATION_PATH, type ActorDiscoveredRecord, type ActorMethodRecord, type ActorModuleOptions, createWasmcloudActorAdapter, discoverActors, emptyActorsModule, handleActorInvocationRequest, isActorInvocationRequest, renderActorsModule, WASMCLOUD_ACTORS_GLOBAL, type WasmcloudActorAdapter, } from './actors.js';
3
+ export { parseAppCommandArgs, parsePlatformCommandArgs, parsePlatformInitArgs } from './args.js';
4
+ export { type BindingRecord, defaultSecretName, discoverBindings, parseBindingsFile, requirementsFromBindings, } from './bindings.js';
5
+ export { BUILD_PROFILE, buildComponent, canonicalBuildDigest, requirementsForProject, runWasmcloudBuild, WASI_HTTP_INTERFACE, WASI_HTTP_VERSION, } from './build.js';
6
+ export { createWasmcloudCommand } from './command.js';
7
+ export { runWasmcloudDeploy, type WasmcloudDeployData, type WasmcloudDeployResult, } from './deploy.js';
8
+ export { type BundleOptions, COMPONENT_IMPORT_EXTERNAL, COMPONENTIZE_QJS_ENV, COMPONENTIZE_QJS_PACKAGE, componentizeQjsPlatformPackageName, DEFAULT_DEPS, findInstalledComponentizeQjsCli, nativeComponentizeQjsOnPath, nodeCompatibilityPlugin, resolveComponentizeQjsPath, type WasmcloudDeps, } from './deps.js';
9
+ export { runWasmcloudDestroy } from './destroy.js';
10
+ export { parseDevArgs, runWasmcloudDev } from './dev.js';
11
+ export { DEV_RUNNER_ENV, requiresWasmCloudHost, resolveDevRunner, } from './dev-runner.js';
12
+ export { discoverProjects, findConfigFiles, resolveApplication, } from './discovery.js';
13
+ export { runWasmcloudDoctor } from './doctor.js';
14
+ export { emptyGuestsModule, renderGuestsModule, WASMCLOUD_GUESTS_GLOBAL } from './guests.js';
15
+ export { hostInterfacesFromRequirements } from './host-interface.js';
16
+ export { DEPLOY_MANIFEST_NAME, type DeployManifest, type DeployTarget, loadDeployManifest, parseDeployManifest, } from './manifest.js';
17
+ export { wasmcloudNodeEnv, wasmcloudUnenvPreset } from './node-compat/env.js';
18
+ export { compactEnviron, createNodeCompatSeed, NODE_COMPAT_SEED_ID, type NodeCompatSeed, } from './node-compat/seed.js';
19
+ export { OCI_ARTIFACT_PLATFORM } from './oci.js';
20
+ export { loadPlatformOutputs, PLATFORM_OUTPUT_SCHEMA_VERSION, type PlatformOutputs, resolvePlatformDirectory, runWasmcloudPlatformDeploy, runWasmcloudPlatformDestroy, } from './platform.js';
21
+ export { createPlatformProjectName, LOCAL_PLATFORM_PATH, PLATFORM_PROJECT_TOKEN, PLATFORM_START_COMMAND, runWasmcloudPlatformInit, } from './platform-init.js';
22
+ export { asWitIdentifier, CONFIG_FILE_NAME, findUp, loadProject, resolveInside, type WasmcloudProject, } from './project.js';
23
+ export { contentDigest, ociReference, projectRelativePath, publishComponent } from './publish.js';
24
+ export { pulumiEnvironment, runPulumi } from './pulumi.js';
25
+ export { type DiscoveredQueueHandler, discoverQueueHandlers, isQueueWorkerProject, parseQueueHandlersInFile, } from './queues.js';
26
+ export { materializeRegistry, type RegistryInput, type RegistryLocation, registryReferenceHost, registryUsesPlainHttp, } from './registry.js';
27
+ export { BACKING_SERVICE_API_VERSION, BACKING_SERVICE_KIND, BACKING_SERVICE_RESOURCE, buildBackingServiceManifest, DEFAULT_SERVICE_CLASSES, isBackingServiceName, isServiceType, parseServiceCreateArgs, parseServiceListArgs, parseServiceNameArgs, runWasmcloudServiceClasses, runWasmcloudServiceCreate, runWasmcloudServiceDelete, runWasmcloudServiceGet, runWasmcloudServiceList, SERVICE_TYPES, summarizeService, } from './service.js';
28
+ export { resolveConnection, resolveTarget } from './target.js';
29
+ export { renderWashDevYaml, writeWashDevConfig } from './wash-dev.js';
30
+ export { aggregateRequirements, COMPONENT_MODEL, DI_QUEUES_INTERFACE, DI_QUEUES_PACKAGE, DI_QUEUES_VERSION, defaultProjectRequirements, HTTP_ADAPTER_REQUIREMENTS, QUEUE_ADAPTER_REQUIREMENTS, QUEUE_ADAPTER_SOURCE, queueProjectRequirements, renderWorldWit, runtimeRequirementsFromJavaScript, socketRequirementsFromJavaScript, type WitRequirement, } from './wit.js';
31
+ export { applyWorkload, CRON_INVOKER_IMAGE, controlSecretResourceName, DEFAULT_STORAGE_MOUNT, deleteWorkload, HOST_STORAGE_ROOT, hostStoragePath, isReady, renderWorkloadManifest, STORAGE_HOSTGROUP, type WorkloadManifestOptions, } from './workload.js';
32
+ declare const _default: import("@di-framework/cli-extension").ExtensionManifest;
33
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ export { discoverScheduledJobs, discoverScheduledJobsInFile, normalizeCronExpression, renderCronAdapterModule, renderCronInvokerModule, } from './cron.js';
2
+ import { defineExtension } from '@di-framework/cli-extension';
3
+ import { createWasmcloudCommand } from './command.js';
4
+ export { ACTORS_INVOCATION_PATH, createWasmcloudActorAdapter, discoverActors, emptyActorsModule, handleActorInvocationRequest, isActorInvocationRequest, renderActorsModule, WASMCLOUD_ACTORS_GLOBAL, } from './actors.js';
5
+ export { parseAppCommandArgs, parsePlatformCommandArgs, parsePlatformInitArgs } from './args.js';
6
+ export { defaultSecretName, discoverBindings, parseBindingsFile, requirementsFromBindings, } from './bindings.js';
7
+ export { BUILD_PROFILE, buildComponent, canonicalBuildDigest, requirementsForProject, runWasmcloudBuild, WASI_HTTP_INTERFACE, WASI_HTTP_VERSION, } from './build.js';
8
+ export { createWasmcloudCommand } from './command.js';
9
+ export { runWasmcloudDeploy, } from './deploy.js';
10
+ export { COMPONENT_IMPORT_EXTERNAL, COMPONENTIZE_QJS_ENV, COMPONENTIZE_QJS_PACKAGE, componentizeQjsPlatformPackageName, DEFAULT_DEPS, findInstalledComponentizeQjsCli, nativeComponentizeQjsOnPath, nodeCompatibilityPlugin, resolveComponentizeQjsPath, } from './deps.js';
11
+ export { runWasmcloudDestroy } from './destroy.js';
12
+ export { parseDevArgs, runWasmcloudDev } from './dev.js';
13
+ export { DEV_RUNNER_ENV, requiresWasmCloudHost, resolveDevRunner, } from './dev-runner.js';
14
+ export { discoverProjects, findConfigFiles, resolveApplication, } from './discovery.js';
15
+ export { runWasmcloudDoctor } from './doctor.js';
16
+ export { emptyGuestsModule, renderGuestsModule, WASMCLOUD_GUESTS_GLOBAL } from './guests.js';
17
+ export { hostInterfacesFromRequirements } from './host-interface.js';
18
+ export { DEPLOY_MANIFEST_NAME, loadDeployManifest, parseDeployManifest, } from './manifest.js';
19
+ export { wasmcloudNodeEnv, wasmcloudUnenvPreset } from './node-compat/env.js';
20
+ export { compactEnviron, createNodeCompatSeed, NODE_COMPAT_SEED_ID, } from './node-compat/seed.js';
21
+ export { OCI_ARTIFACT_PLATFORM } from './oci.js';
22
+ export { loadPlatformOutputs, PLATFORM_OUTPUT_SCHEMA_VERSION, resolvePlatformDirectory, runWasmcloudPlatformDeploy, runWasmcloudPlatformDestroy, } from './platform.js';
23
+ export { createPlatformProjectName, LOCAL_PLATFORM_PATH, PLATFORM_PROJECT_TOKEN, PLATFORM_START_COMMAND, runWasmcloudPlatformInit, } from './platform-init.js';
24
+ export { asWitIdentifier, CONFIG_FILE_NAME, findUp, loadProject, resolveInside, } from './project.js';
25
+ export { contentDigest, ociReference, projectRelativePath, publishComponent } from './publish.js';
26
+ export { pulumiEnvironment, runPulumi } from './pulumi.js';
27
+ export { discoverQueueHandlers, isQueueWorkerProject, parseQueueHandlersInFile, } from './queues.js';
28
+ export { materializeRegistry, registryReferenceHost, registryUsesPlainHttp, } from './registry.js';
29
+ export { BACKING_SERVICE_API_VERSION, BACKING_SERVICE_KIND, BACKING_SERVICE_RESOURCE, buildBackingServiceManifest, DEFAULT_SERVICE_CLASSES, isBackingServiceName, isServiceType, parseServiceCreateArgs, parseServiceListArgs, parseServiceNameArgs, runWasmcloudServiceClasses, runWasmcloudServiceCreate, runWasmcloudServiceDelete, runWasmcloudServiceGet, runWasmcloudServiceList, SERVICE_TYPES, summarizeService, } from './service.js';
30
+ export { resolveConnection, resolveTarget } from './target.js';
31
+ export { renderWashDevYaml, writeWashDevConfig } from './wash-dev.js';
32
+ export { aggregateRequirements, COMPONENT_MODEL, DI_QUEUES_INTERFACE, DI_QUEUES_PACKAGE, DI_QUEUES_VERSION, defaultProjectRequirements, HTTP_ADAPTER_REQUIREMENTS, QUEUE_ADAPTER_REQUIREMENTS, QUEUE_ADAPTER_SOURCE, queueProjectRequirements, renderWorldWit, runtimeRequirementsFromJavaScript, socketRequirementsFromJavaScript, } from './wit.js';
33
+ export { applyWorkload, CRON_INVOKER_IMAGE, controlSecretResourceName, DEFAULT_STORAGE_MOUNT, deleteWorkload, HOST_STORAGE_ROOT, hostStoragePath, isReady, renderWorkloadManifest, STORAGE_HOSTGROUP, } from './workload.js';
34
+ export default defineExtension({
35
+ schemaVersion: 1,
36
+ name: 'platform',
37
+ description: 'Build, serve, and deploy DI Framework apps as wasmCloud components',
38
+ command: createWasmcloudCommand(),
39
+ });
@@ -0,0 +1,9 @@
1
+ import type { WasmcloudDeps } from './deps.js';
2
+ import type { ClusterConnection } from './target.js';
3
+ export declare function kubectlArgs(connection: ClusterConnection, args: readonly string[]): string[];
4
+ export declare function runKubectl(deps: WasmcloudDeps, connection: ClusterConnection, args: readonly string[], cwd: string): Promise<void>;
5
+ export declare function captureKubectl(deps: WasmcloudDeps, connection: ClusterConnection, args: readonly string[], cwd: string): Promise<{
6
+ exitCode: number;
7
+ stdout: string;
8
+ stderr: string;
9
+ }>;
@@ -0,0 +1,17 @@
1
+ import { toolFailed } from './support.js';
2
+ export function kubectlArgs(connection, args) {
3
+ const flags = ['--kubeconfig', connection.kubeconfig, '--namespace', connection.namespace];
4
+ if (connection.context !== undefined) {
5
+ flags.push('--context', connection.context);
6
+ }
7
+ return [...flags, ...args];
8
+ }
9
+ export async function runKubectl(deps, connection, args, cwd) {
10
+ const result = await deps.runner('kubectl', kubectlArgs(connection, args), { cwd });
11
+ if (result.exitCode !== 0) {
12
+ throw toolFailed(`kubectl ${args[0]}`, result.exitCode);
13
+ }
14
+ }
15
+ export async function captureKubectl(deps, connection, args, cwd) {
16
+ return deps.runCaptured('kubectl', kubectlArgs(connection, args), { cwd });
17
+ }
@@ -0,0 +1,9 @@
1
+ import type { BindingRecord } from './bindings.js';
2
+ import type { WasmcloudDeps } from './deps.js';
3
+ import type { WasmcloudProject } from './project.js';
4
+ import type { ClusterConnection } from './target.js';
5
+ export declare const ASSOCIATION_WORKLOAD_LABEL = "di-framework.dev/binding-workload";
6
+ export declare function associationName(workload: string, bindingName: string): string;
7
+ export declare function applyManagedBindings(project: WasmcloudProject, connection: ClusterConnection, bindings: readonly BindingRecord[], deps: WasmcloudDeps): Promise<Set<string>>;
8
+ /** Called only after a successful rollout, or after workload deletion completes. */
9
+ export declare function cleanupManagedBindings(project: WasmcloudProject, connection: ClusterConnection, desired: ReadonlySet<string>, deps: WasmcloudDeps): Promise<void>;