@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
package/dist/wit.js ADDED
@@ -0,0 +1,248 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readdirSync, readFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ /** Component-model / WASI preview the guest targets. Independent of any package version. */
5
+ export const COMPONENT_MODEL = '0.3';
6
+ export const HTTP_ADAPTER_SOURCE = 'http-adapter';
7
+ export const NODE_COMPAT_SOURCE = 'node-compat';
8
+ export const WASI_HTTP_PACKAGE = 'wasi:http';
9
+ export const WASI_HTTP_VERSION = '0.3.0';
10
+ export const WASI_HTTP_INTERFACE = 'handler';
11
+ export const WASI_SOCKETS_PACKAGE = 'wasi:sockets';
12
+ export const WASI_SOCKETS_VERSION = '0.3.0';
13
+ export const WASI_RANDOM_PACKAGE = 'wasi:random';
14
+ export const WASI_RANDOM_VERSION = '0.3.0';
15
+ export const QUEUE_ADAPTER_SOURCE = 'queue-adapter';
16
+ export const DI_QUEUES_PACKAGE = 'di-framework:queues';
17
+ export const DI_QUEUES_VERSION = '0.1.0';
18
+ export const DI_QUEUES_INTERFACE = 'dispatch';
19
+ export const DI_SQLITE_PACKAGE = 'di-framework:sqlite';
20
+ export const DI_SQLITE_VERSION = '0.1.0';
21
+ export const DI_SQLITE_INTERFACE = 'database';
22
+ export const DI_SQLITE_TYPES_INTERFACE = 'types';
23
+ export const SQLITE_SOURCE = 'sqlite-backend';
24
+ export const HTTP_ADAPTER_REQUIREMENTS = [
25
+ {
26
+ package: WASI_HTTP_PACKAGE,
27
+ version: WASI_HTTP_VERSION,
28
+ interfaces: [WASI_HTTP_INTERFACE],
29
+ direction: 'export',
30
+ source: HTTP_ADAPTER_SOURCE,
31
+ },
32
+ ];
33
+ /** Default guest world: the HTTP adapter only. Bindings later concat onto this list. */
34
+ export function defaultProjectRequirements() {
35
+ return HTTP_ADAPTER_REQUIREMENTS.map((requirement) => ({ ...requirement }));
36
+ }
37
+ export const QUEUE_ADAPTER_REQUIREMENTS = [
38
+ {
39
+ package: DI_QUEUES_PACKAGE,
40
+ version: DI_QUEUES_VERSION,
41
+ interfaces: [DI_QUEUES_INTERFACE],
42
+ direction: 'export',
43
+ source: QUEUE_ADAPTER_SOURCE,
44
+ },
45
+ ];
46
+ export const SQLITE_IMPORT_REQUIREMENTS = [
47
+ {
48
+ package: DI_SQLITE_PACKAGE,
49
+ version: DI_SQLITE_VERSION,
50
+ interfaces: [DI_SQLITE_TYPES_INTERFACE, DI_SQLITE_INTERFACE],
51
+ direction: 'import',
52
+ source: SQLITE_SOURCE,
53
+ },
54
+ ];
55
+ /** Queue workers are long-lived HTTP services with SQLite-backed persistence. */
56
+ export function queueProjectRequirements() {
57
+ return [
58
+ ...defaultProjectRequirements(),
59
+ ...SQLITE_IMPORT_REQUIREMENTS.map((requirement) => ({ ...requirement })),
60
+ ];
61
+ }
62
+ export function sqliteProjectRequirements() {
63
+ return SQLITE_IMPORT_REQUIREMENTS.map((requirement) => ({ ...requirement }));
64
+ }
65
+ /**
66
+ * Runtime WASI pulled in by Node overlays (`node:net`/`dgram` → sockets,
67
+ * `node:crypto` → random). Only added to the guest world when the bundled JS
68
+ * actually imports those specifiers.
69
+ */
70
+ export function runtimeRequirementsFromJavaScript(source) {
71
+ const requirements = [];
72
+ if (source.includes('wasi:tls/client@0.3.0-draft')) {
73
+ requirements.push({
74
+ package: 'wasi:tls',
75
+ version: '0.3.0-draft',
76
+ interfaces: ['client', 'types'],
77
+ direction: 'import',
78
+ source: NODE_COMPAT_SOURCE,
79
+ });
80
+ }
81
+ const socketInterfaces = [];
82
+ if (source.includes(`${WASI_SOCKETS_PACKAGE}/types@${WASI_SOCKETS_VERSION}`)) {
83
+ socketInterfaces.push('types');
84
+ }
85
+ if (source.includes(`${WASI_SOCKETS_PACKAGE}/ip-name-lookup@${WASI_SOCKETS_VERSION}`)) {
86
+ socketInterfaces.push('ip-name-lookup');
87
+ }
88
+ if (socketInterfaces.length > 0) {
89
+ requirements.push({
90
+ package: WASI_SOCKETS_PACKAGE,
91
+ version: WASI_SOCKETS_VERSION,
92
+ interfaces: socketInterfaces,
93
+ direction: 'import',
94
+ source: NODE_COMPAT_SOURCE,
95
+ });
96
+ }
97
+ if (source.includes(`${WASI_RANDOM_PACKAGE}/random@${WASI_RANDOM_VERSION}`)) {
98
+ requirements.push({
99
+ package: WASI_RANDOM_PACKAGE,
100
+ version: WASI_RANDOM_VERSION,
101
+ interfaces: ['random'],
102
+ direction: 'import',
103
+ source: NODE_COMPAT_SOURCE,
104
+ });
105
+ }
106
+ if (source.includes('wasi:clocks/monotonic-clock@0.3.0')) {
107
+ requirements.push({
108
+ package: 'wasi:clocks',
109
+ version: '0.3.0',
110
+ interfaces: ['monotonic-clock'],
111
+ direction: 'import',
112
+ source: NODE_COMPAT_SOURCE,
113
+ });
114
+ }
115
+ if (source.includes('wasi:cli/environment@0.3.0')) {
116
+ requirements.push({
117
+ package: 'wasi:cli',
118
+ version: '0.3.0',
119
+ interfaces: ['environment'],
120
+ direction: 'import',
121
+ source: NODE_COMPAT_SOURCE,
122
+ });
123
+ }
124
+ if (source.includes(`${DI_SQLITE_PACKAGE}/${DI_SQLITE_INTERFACE}@${DI_SQLITE_VERSION}`)) {
125
+ requirements.push({
126
+ package: DI_SQLITE_PACKAGE,
127
+ version: DI_SQLITE_VERSION,
128
+ interfaces: [DI_SQLITE_TYPES_INTERFACE, DI_SQLITE_INTERFACE],
129
+ direction: 'import',
130
+ source: SQLITE_SOURCE,
131
+ });
132
+ }
133
+ return requirements;
134
+ }
135
+ /** @deprecated Use {@link runtimeRequirementsFromJavaScript}. */
136
+ export function socketRequirementsFromJavaScript(source) {
137
+ return runtimeRequirementsFromJavaScript(source);
138
+ }
139
+ export function parsePackageId(id) {
140
+ const separator = id.indexOf(':');
141
+ if (separator <= 0 || separator === id.length - 1) {
142
+ throw new Error(`Invalid WIT package id "${id}"`);
143
+ }
144
+ return { namespace: id.slice(0, separator), name: id.slice(separator + 1) };
145
+ }
146
+ function requirementKey(requirement) {
147
+ return [
148
+ requirement.direction,
149
+ requirement.package,
150
+ requirement.version,
151
+ requirement.instanceName ?? '',
152
+ ].join('\0');
153
+ }
154
+ /** Merge interface groups that share package, version, direction, and instance name. */
155
+ export function aggregateRequirements(requirements) {
156
+ const groups = new Map();
157
+ for (const requirement of requirements) {
158
+ if (requirement.interfaces.length === 0)
159
+ continue;
160
+ const key = requirementKey(requirement);
161
+ const existing = groups.get(key);
162
+ if (existing === undefined) {
163
+ groups.set(key, {
164
+ ...requirement,
165
+ interfaces: [...requirement.interfaces],
166
+ sources: [requirement.source],
167
+ });
168
+ continue;
169
+ }
170
+ for (const iface of requirement.interfaces) {
171
+ if (!existing.interfaces.includes(iface))
172
+ existing.interfaces.push(iface);
173
+ }
174
+ if (!existing.sources.includes(requirement.source))
175
+ existing.sources.push(requirement.source);
176
+ }
177
+ return [...groups.values()];
178
+ }
179
+ function importClause(requirement, iface) {
180
+ const { namespace, name } = parsePackageId(requirement.package);
181
+ const target = `${namespace}:${name}/${iface}@${requirement.version}`;
182
+ if (requirement.direction === 'export')
183
+ return `export ${target};`;
184
+ if (requirement.namedImport && requirement.instanceName)
185
+ return `import ${requirement.instanceName}: ${target};`;
186
+ // Legacy bindings retain their unlabeled imports.
187
+ // qjs previously could not encode `import name: pkg/iface` (cm-implements). Named instances
188
+ // still appear on hostInterfaces; the guest world is unlabeled.
189
+ return `import ${target};`;
190
+ }
191
+ export function renderWorldWit(packageName, version, requirements) {
192
+ const lines = [`package local:${packageName}@${version};`, '', 'world application {'];
193
+ const seen = new Set();
194
+ for (const requirement of aggregateRequirements(requirements)) {
195
+ for (const iface of requirement.interfaces) {
196
+ const clause = importClause(requirement, iface);
197
+ if (seen.has(clause))
198
+ continue;
199
+ seen.add(clause);
200
+ lines.push(` ${clause}`);
201
+ }
202
+ }
203
+ lines.push('}', '');
204
+ return lines.join('\n');
205
+ }
206
+ function packageIdFromWit(contents) {
207
+ const match = contents.match(/^package\s+([a-z][a-z0-9-]*:[a-z][a-z0-9-]*)@([0-9][^;\s]*)/m);
208
+ if (match == null)
209
+ return undefined;
210
+ return { id: match[1] ?? '', version: match[2] ?? '' };
211
+ }
212
+ export function digestBytes(content) {
213
+ return createHash('sha256').update(content).digest('hex');
214
+ }
215
+ export function buildWitLock(requirements, witDepsDirectory) {
216
+ const packages = [];
217
+ for (const entry of readdirSync(witDepsDirectory, { withFileTypes: true })) {
218
+ if (!entry.isDirectory())
219
+ continue;
220
+ const path = join(entry.name, 'package.wit');
221
+ const absolute = join(witDepsDirectory, path);
222
+ let contents;
223
+ try {
224
+ contents = readFileSync(absolute, 'utf8');
225
+ }
226
+ catch {
227
+ continue;
228
+ }
229
+ const parsed = packageIdFromWit(contents);
230
+ if (parsed === undefined)
231
+ continue;
232
+ packages.push({
233
+ id: parsed.id,
234
+ version: parsed.version,
235
+ source: 'bundled',
236
+ path: `wit/deps/${path.replaceAll('\\', '/')}`,
237
+ digest: digestBytes(contents),
238
+ });
239
+ }
240
+ packages.sort((left, right) => left.id.localeCompare(right.id));
241
+ return {
242
+ schemaVersion: 1,
243
+ componentModel: COMPONENT_MODEL,
244
+ world: 'application',
245
+ requirements: aggregateRequirements(requirements),
246
+ packages,
247
+ };
248
+ }
@@ -0,0 +1,12 @@
1
+ import type { WasmcloudProject } from './project.js';
2
+ export type WorkloadEntry = {
3
+ kind: 'component' | 'service';
4
+ exportName: string;
5
+ path: string;
6
+ subscriptions?: string[];
7
+ };
8
+ /** Read declarations without executing application code or resolving host bindings. */
9
+ export declare function discoverWorkloadEntry(entryPath: string, workload: string): WorkloadEntry;
10
+ /** An inferred description, never an application project or source composition file. */
11
+ export declare function writeWorkloadManifest(root: string, name: string, projects: Iterable<WasmcloudProject>): string;
12
+ export declare function renderWorkloadServiceAdapter(entry: WorkloadEntry): string;
@@ -0,0 +1,136 @@
1
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { join, relative } from 'node:path';
3
+ import { CommandFailure } from '@di-framework/cli-extension';
4
+ import ts from 'typescript';
5
+ /** Read declarations without executing application code or resolving host bindings. */
6
+ export function discoverWorkloadEntry(entryPath, workload) {
7
+ const source = ts.createSourceFile(entryPath, readFileSync(entryPath, 'utf8'), ts.ScriptTarget.Latest, true);
8
+ const fail = (message) => {
9
+ throw new CommandFailure('WASMCLOUD_WORKLOAD_INVALID', `${entryPath}: ${message}`, 2);
10
+ };
11
+ const declarations = new Map();
12
+ for (const statement of source.statements) {
13
+ if (!ts.isImportDeclaration(statement) ||
14
+ !ts.isStringLiteral(statement.moduleSpecifier) ||
15
+ statement.moduleSpecifier.text !== '@di-framework/bindings')
16
+ continue;
17
+ const imports = statement.importClause?.namedBindings;
18
+ if (!imports || !ts.isNamedImports(imports))
19
+ continue;
20
+ for (const imported of imports.elements) {
21
+ const name = imported.propertyName?.text ?? imported.name.text;
22
+ if (name === 'WorkloadComponent')
23
+ declarations.set(imported.name.text, 'component');
24
+ if (name === 'WorkloadService')
25
+ declarations.set(imported.name.text, 'service');
26
+ }
27
+ }
28
+ const entries = [];
29
+ for (const statement of source.statements) {
30
+ if (!ts.isVariableStatement(statement) ||
31
+ !statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword))
32
+ continue;
33
+ for (const declaration of statement.declarationList.declarations) {
34
+ const wrapper = declaration.initializer;
35
+ if (!ts.isIdentifier(declaration.name) ||
36
+ !wrapper ||
37
+ !ts.isCallExpression(wrapper) ||
38
+ !ts.isCallExpression(wrapper.expression) ||
39
+ !ts.isIdentifier(wrapper.expression.expression))
40
+ continue;
41
+ const kind = declarations.get(wrapper.expression.expression.text);
42
+ if (!kind)
43
+ continue;
44
+ const options = wrapper.expression.arguments[0];
45
+ if (!options || !ts.isObjectLiteralExpression(options))
46
+ fail('workload options must be an object literal');
47
+ const entry = { kind, exportName: declaration.name.text, path: '' };
48
+ for (const property of options.properties) {
49
+ if (!ts.isPropertyAssignment(property))
50
+ fail('workload options must be static properties');
51
+ const assignment = property;
52
+ const name = assignment.name.getText(source).replace(/^['"]|['"]$/g, '');
53
+ const value = assignment.initializer;
54
+ if (name === 'workload') {
55
+ if (!ts.isStringLiteral(value) || value.text !== workload)
56
+ fail('source workload must match di-framework.config.json');
57
+ }
58
+ else if (name === 'path') {
59
+ if (!ts.isStringLiteral(value) ||
60
+ !value.text.startsWith('/') ||
61
+ value.text.startsWith('//') ||
62
+ /[\s?#\\]/.test(value.text))
63
+ fail('member path must be a literal absolute path');
64
+ entry.path = value.text;
65
+ }
66
+ else if (name === 'subscriptions') {
67
+ if (kind !== 'service' ||
68
+ !ts.isArrayLiteralExpression(value) ||
69
+ value.elements.length === 0 ||
70
+ value.elements.some((v) => !ts.isStringLiteral(v) || !v.text.trim() || /[\s,]/.test(v.text)))
71
+ fail('service subscriptions must be a nonempty array of literal subjects');
72
+ entry.subscriptions = value.elements.map((v) => v.text);
73
+ }
74
+ else
75
+ fail(`unsupported workload option ${name}`);
76
+ }
77
+ if (!entry.path)
78
+ fail('components and services must declare a path');
79
+ entries.push(entry);
80
+ }
81
+ }
82
+ if (entries.length !== 1)
83
+ fail('declare exactly one exported WorkloadComponent or WorkloadService in the entry module');
84
+ return entries[0] ?? fail('workload entry is missing');
85
+ }
86
+ /** An inferred description, never an application project or source composition file. */
87
+ export function writeWorkloadManifest(root, name, projects) {
88
+ const members = [...projects]
89
+ .filter((p) => p.workload === name)
90
+ .sort((a, b) => a.applicationName.localeCompare(b.applicationName));
91
+ const paths = new Map();
92
+ const routes = new Map();
93
+ for (const member of members) {
94
+ const entry = member.workloadEntry;
95
+ if (!entry)
96
+ continue;
97
+ const path = entry.path;
98
+ const previous = paths.get(path);
99
+ if (previous)
100
+ throw new CommandFailure('WASMCLOUD_WORKLOAD_PATH_CONFLICT', `${name}: ${previous} and ${member.applicationName} both claim ${path}`, 2);
101
+ paths.set(path, member.applicationName);
102
+ if (entry.kind === 'component')
103
+ routes.set(path, member.applicationName);
104
+ }
105
+ const path = join(root, '.di-framework', 'workloads', `${name}.json`);
106
+ mkdirSync(join(root, '.di-framework', 'workloads'), { recursive: true });
107
+ writeFileSync(path, `${JSON.stringify({
108
+ schemaVersion: 1,
109
+ name,
110
+ members: members.map((p) => ({
111
+ name: p.applicationName,
112
+ project: relative(root, p.projectRoot),
113
+ entry: relative(p.projectRoot, p.entryPath),
114
+ ...p.workloadEntry,
115
+ })),
116
+ paths: Object.fromEntries(paths),
117
+ routes: Object.fromEntries(routes),
118
+ }, null, 2)}\n`);
119
+ return path;
120
+ }
121
+ export function renderWorkloadServiceAdapter(entry) {
122
+ const header = `import 'virtual:di-framework-wasmcloud-guests';\nimport { ${entry.exportName} as invoke } from 'virtual:di-framework-application';\n`;
123
+ if (entry.subscriptions) {
124
+ return `${header}export const handler = {
125
+ async handleMessage(message) {
126
+ try { await invoke(message); }
127
+ catch (error) {
128
+ if (error && ['reject', 'retry', 'other'].includes(error.tag)) throw error;
129
+ console.error('Workload message handler failed', error);
130
+ throw { tag: 'retry' };
131
+ }
132
+ }
133
+ };\n`;
134
+ }
135
+ return `${header}export const run = { async run() { await invoke(); } };\n`;
136
+ }
@@ -0,0 +1,45 @@
1
+ import { type CliIo } from '@di-framework/cli-extension';
2
+ import { type BindingRecord } from './bindings.js';
3
+ import { type DiscoveredCronJob } from './cron.js';
4
+ import type { WasmcloudDeps } from './deps.js';
5
+ import type { WasmcloudProject } from './project.js';
6
+ import { type DiscoveredQueueHandler } from './queues.js';
7
+ import type { ClusterConnection } from './target.js';
8
+ import { type WitRequirement } from './wit.js';
9
+ export declare const MANAGED_BY_LABEL = "di-framework";
10
+ export declare const WAIT_ATTEMPTS = 30;
11
+ export declare const WAIT_INTERVAL_MS = 2000;
12
+ export declare const WORKLOAD_DEPLOYMENT_RESOURCE = "workloaddeployment.runtime.wasmcloud.dev";
13
+ export declare const WORKLOAD_REPLICA_SET_RESOURCE = "workloadreplicaset.runtime.wasmcloud.dev";
14
+ /** Host directory where the storage hostgroup mounts the shared PVC. */
15
+ export declare const HOST_STORAGE_ROOT = "/var/lib/di-framework/storage";
16
+ /** Dedicated single-replica hostgroup that mounts persistent application storage. */
17
+ export declare const STORAGE_HOSTGROUP = "storage";
18
+ /** Guest mount path for application SQLite storage. */
19
+ export declare const DEFAULT_STORAGE_MOUNT = "/data";
20
+ /** Pinned CronJob invoker image that POSTs to the Wasm HTTP control API. */
21
+ export declare const CRON_INVOKER_IMAGE = "curlimages/curl:8.11.1";
22
+ export declare function deploymentResourceName(project: WasmcloudProject): string;
23
+ export declare function generatedManifestPath(project: WasmcloudProject): string;
24
+ export declare function hostStoragePath(applicationName: string): string;
25
+ /** Kubernetes Secret that holds DI_CONTROL_TOKEN for a workload. */
26
+ export declare function controlSecretResourceName(workloadName: string): string;
27
+ export interface WorkloadManifestOptions {
28
+ hasActors?: boolean;
29
+ hasPersistentStorage?: boolean;
30
+ replicas?: number;
31
+ storageVolume?: {
32
+ hostPath?: string;
33
+ mountPath?: string;
34
+ volumeName?: string;
35
+ };
36
+ /** Secret name providing control-plane credentials (merged into WASI environment). */
37
+ controlSecretName?: string;
38
+ /** Explicit environment config values (string map for localResources.environment.config). */
39
+ environment?: Record<string, string>;
40
+ }
41
+ export declare function renderWorkloadManifest(project: WasmcloudProject, connection: ClusterConnection, image: string, requirements?: readonly WitRequirement[], bindings?: readonly BindingRecord[], options?: WorkloadManifestOptions | boolean, cronJobs?: readonly DiscoveredCronJob[], queueHandlers?: readonly DiscoveredQueueHandler[]): string;
42
+ export declare function applyWorkload(project: WasmcloudProject, connection: ClusterConnection, image: string, io: CliIo, deps: WasmcloudDeps): Promise<string>;
43
+ export declare function deleteWorkload(project: WasmcloudProject, connection: ClusterConnection, io: CliIo, deps: WasmcloudDeps): Promise<void>;
44
+ export declare function waitForReady(project: WasmcloudProject, connection: ClusterConnection, deps: WasmcloudDeps, io?: CliIo): Promise<void>;
45
+ export declare function isReady(stdout: string): boolean;