@di-framework/cli-plugin-platform 6.0.3 → 6.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +196 -21
- package/dist/args.d.ts +2 -1
- package/dist/args.js +9 -5
- package/dist/assets/http-adapter.js +63 -0
- package/dist/assets/platform/README.md +22 -6
- package/dist/assets/sqlite/BUILD-INFO.txt +1 -1
- package/dist/assets/wit/deps/wasi-clocks-0.2.12/package.wit +43 -0
- package/dist/assets/wit/deps/wasi-filesystem-0.2.12/package.wit +196 -0
- package/dist/assets/wit/deps/wasi-io-0.2.12/package.wit +66 -0
- package/dist/assets/wit/deps/wasi-logging/package.wit +36 -0
- package/dist/build.d.ts +3 -1
- package/dist/build.js +4 -2
- package/dist/command.js +31 -13
- package/dist/console/auth.d.ts +20 -0
- package/dist/console/auth.js +82 -0
- package/dist/console/catalog.d.ts +196 -0
- package/dist/console/catalog.js +821 -0
- package/dist/console/cluster.d.ts +30 -0
- package/dist/console/cluster.js +299 -0
- package/dist/console/errors.d.ts +10 -0
- package/dist/console/errors.js +32 -0
- package/dist/console/run.d.ts +18 -0
- package/dist/console/run.js +102 -0
- package/dist/console/server.d.ts +25 -0
- package/dist/console/server.js +668 -0
- package/dist/console/services.d.ts +47 -0
- package/dist/console/services.js +111 -0
- package/dist/console-ui/app.css +1 -0
- package/dist/console-ui/app.js +260 -0
- package/dist/console-ui/di-framework-mark.png +0 -0
- package/dist/console-ui/index.html +13 -0
- package/dist/deps.d.ts +2 -0
- package/dist/deps.js +5 -3
- package/dist/dev.js +10 -5
- package/dist/egress.d.ts +40 -0
- package/dist/egress.js +214 -0
- package/dist/host-interface.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/manifest.d.ts +7 -0
- package/dist/manifest.js +35 -8
- package/dist/node-compat/console.d.ts +18 -0
- package/dist/node-compat/console.js +42 -0
- package/dist/node-compat/env.js +6 -0
- package/dist/node-compat/events.d.ts +20 -0
- package/dist/node-compat/events.js +55 -0
- package/dist/node-compat/fetch-runtime.d.ts +31 -0
- package/dist/node-compat/fetch-runtime.js +62 -0
- package/dist/node-compat/fs-promises.d.ts +30 -0
- package/dist/node-compat/fs-promises.js +3 -0
- package/dist/node-compat/fs.d.ts +79 -0
- package/dist/node-compat/fs.js +112 -5
- package/dist/node-compat/net.d.ts +2 -1
- package/dist/node-compat/net.js +3 -1
- package/dist/node-compat/storage.d.ts +87 -0
- package/dist/node-compat/storage.js +244 -0
- package/dist/node-compat/stream.d.ts +24 -0
- package/dist/node-compat/stream.js +70 -0
- package/dist/platform.js +2 -4
- package/dist/project.d.ts +5 -0
- package/dist/project.js +4 -0
- package/dist/service.d.ts +21 -2
- package/dist/service.js +71 -5
- package/dist/target.js +6 -1
- package/dist/wit.d.ts +8 -0
- package/dist/wit.js +28 -0
- package/dist/workload.d.ts +45 -0
- package/dist/workload.js +98 -26
- package/package.json +14 -4
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { getDirectories } from 'wasi:filesystem/preopens@0.2.12';
|
|
2
|
+
/** Node.js errno for each wasi:filesystem error-code the shim reports. */
|
|
3
|
+
const ERRNO = {
|
|
4
|
+
'no-entry': ['ENOENT', -2],
|
|
5
|
+
exist: ['EEXIST', -17],
|
|
6
|
+
'not-directory': ['ENOTDIR', -20],
|
|
7
|
+
'is-directory': ['EISDIR', -21],
|
|
8
|
+
'not-empty': ['ENOTEMPTY', -39],
|
|
9
|
+
access: ['EACCES', -13],
|
|
10
|
+
'not-permitted': ['EPERM', -1],
|
|
11
|
+
'read-only': ['EROFS', -30],
|
|
12
|
+
'insufficient-space': ['ENOSPC', -28],
|
|
13
|
+
invalid: ['EINVAL', -22],
|
|
14
|
+
'cross-device': ['EXDEV', -18],
|
|
15
|
+
};
|
|
16
|
+
/** Default guest storage mount; see DEFAULT_STORAGE_MOUNT in the deploy manifest. */
|
|
17
|
+
const DEFAULT_MOUNT = '/data';
|
|
18
|
+
const READ_CHUNK = 64 * 1024;
|
|
19
|
+
/** Map a thrown wasi:filesystem error-code to a Node.js-shaped error. */
|
|
20
|
+
export function storageError(error, syscall, path) {
|
|
21
|
+
const payload = typeof error === 'object' && error !== null && 'payload' in error
|
|
22
|
+
? error.payload
|
|
23
|
+
: error;
|
|
24
|
+
const wasiCode = typeof payload === 'string' ? payload : 'io';
|
|
25
|
+
const [code, errno] = ERRNO[wasiCode] ?? ['EIO', -5];
|
|
26
|
+
const result = new Error(`${code}: ${wasiCode}, ${syscall} '${path}'`);
|
|
27
|
+
result.code = code;
|
|
28
|
+
result.errno = errno;
|
|
29
|
+
result.syscall = syscall;
|
|
30
|
+
result.path = path;
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
function release(descriptor) {
|
|
34
|
+
const dispose = descriptor[Symbol.dispose];
|
|
35
|
+
if (typeof dispose === 'function')
|
|
36
|
+
dispose.call(descriptor);
|
|
37
|
+
}
|
|
38
|
+
function toNumber(value) {
|
|
39
|
+
return typeof value === 'bigint' ? Number(value) : value;
|
|
40
|
+
}
|
|
41
|
+
function under(path, prefix) {
|
|
42
|
+
return path === prefix || path.startsWith(`${prefix}/`);
|
|
43
|
+
}
|
|
44
|
+
/** Storage mounts the deploy manifest can request: `/data`, or `DI_STORAGE_DIR` when set. */
|
|
45
|
+
function defaultPrefixes() {
|
|
46
|
+
const env = globalThis.process
|
|
47
|
+
?.env;
|
|
48
|
+
const configured = env?.DI_STORAGE_DIR?.replace(/\/+$/, '');
|
|
49
|
+
return configured?.startsWith('/') ? [DEFAULT_MOUNT, configured] : [DEFAULT_MOUNT];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Paths under a host-mounted directory (the platform's `/data` preopen) live in
|
|
53
|
+
* wasi:filesystem so every workload member sees them. Only absolute, non-root preopens
|
|
54
|
+
* qualify; every other path stays in the guest's in-memory filesystem. Preopens are
|
|
55
|
+
* read on the first storage path, never at module initialization: only paths under a
|
|
56
|
+
* storage prefix consult them.
|
|
57
|
+
*/
|
|
58
|
+
export function createStorage(preopens, prefixes = defaultPrefixes) {
|
|
59
|
+
let mounts;
|
|
60
|
+
function list() {
|
|
61
|
+
if (mounts === undefined) {
|
|
62
|
+
mounts = preopens()
|
|
63
|
+
.map(([root, path]) => ({ root, path: path.replace(/\/+$/, '') }))
|
|
64
|
+
.filter((mount) => mount.path.startsWith('/') && mount.path !== '')
|
|
65
|
+
.sort((left, right) => right.path.length - left.path.length);
|
|
66
|
+
}
|
|
67
|
+
return mounts;
|
|
68
|
+
}
|
|
69
|
+
/** The mount holding an absolute, normalized guest path, and the path inside it. */
|
|
70
|
+
function locate(path) {
|
|
71
|
+
for (const mount of list()) {
|
|
72
|
+
if (path === mount.path)
|
|
73
|
+
return { root: mount.root, relative: '.' };
|
|
74
|
+
if (under(path, mount.path)) {
|
|
75
|
+
return { root: mount.root, relative: path.slice(mount.path.length + 1) };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
function at(path, syscall, run) {
|
|
81
|
+
const location = locate(path);
|
|
82
|
+
if (location === undefined)
|
|
83
|
+
throw storageError('no-entry', syscall, path);
|
|
84
|
+
try {
|
|
85
|
+
return run(location.root, location.relative);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw storageError(error, syscall, path);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function withFile(path, syscall, open, access, run) {
|
|
92
|
+
return at(path, syscall, (root, relative) => {
|
|
93
|
+
const file = root.openAt({ symlinkFollow: true }, relative, open, access);
|
|
94
|
+
try {
|
|
95
|
+
return run(file);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
release(file);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function readAll(file) {
|
|
103
|
+
const chunks = [];
|
|
104
|
+
let offset = 0;
|
|
105
|
+
for (;;) {
|
|
106
|
+
const [data, end] = file.read(READ_CHUNK, offset);
|
|
107
|
+
const chunk = data instanceof Uint8Array ? data : Uint8Array.from(data);
|
|
108
|
+
chunks.push(chunk);
|
|
109
|
+
offset += chunk.byteLength;
|
|
110
|
+
if (end || chunk.byteLength === 0)
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
const result = new Uint8Array(offset);
|
|
114
|
+
let position = 0;
|
|
115
|
+
for (const chunk of chunks) {
|
|
116
|
+
result.set(chunk, position);
|
|
117
|
+
position += chunk.byteLength;
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
function writeAll(file, bytes, offset) {
|
|
122
|
+
let written = 0;
|
|
123
|
+
while (written < bytes.byteLength) {
|
|
124
|
+
const count = toNumber(file.write(bytes.subarray(written), offset + written));
|
|
125
|
+
if (count <= 0)
|
|
126
|
+
throw 'io';
|
|
127
|
+
written += count;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function stat(path) {
|
|
131
|
+
return at(path, 'stat', (root, relative) => {
|
|
132
|
+
const result = relative === '.' ? root.stat() : root.statAt({ symlinkFollow: true }, relative);
|
|
133
|
+
const time = result.dataModificationTimestamp;
|
|
134
|
+
return {
|
|
135
|
+
directory: result.type === 'directory',
|
|
136
|
+
size: toNumber(result.size),
|
|
137
|
+
mtimeMs: time ? toNumber(time.seconds) * 1000 + Math.floor(time.nanoseconds / 1e6) : 0,
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function readdir(path) {
|
|
142
|
+
return withFile(path, 'scandir', {}, { read: true }, (directory) => {
|
|
143
|
+
const entries = [];
|
|
144
|
+
const stream = directory.readDirectory();
|
|
145
|
+
for (let entry = stream.readDirectoryEntry(); entry; entry = stream.readDirectoryEntry()) {
|
|
146
|
+
entries.push({ name: entry.name, directory: entry.type === 'directory' });
|
|
147
|
+
}
|
|
148
|
+
return entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function exists(path) {
|
|
152
|
+
try {
|
|
153
|
+
stat(path);
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function mkdir(path, recursive) {
|
|
161
|
+
if (!recursive) {
|
|
162
|
+
at(path, 'mkdir', (root, relative) => root.createDirectoryAt(relative));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const location = locate(path);
|
|
166
|
+
if (location === undefined)
|
|
167
|
+
throw storageError('no-entry', 'mkdir', path);
|
|
168
|
+
if (location.relative === '.')
|
|
169
|
+
return;
|
|
170
|
+
let current = '';
|
|
171
|
+
for (const part of location.relative.split('/')) {
|
|
172
|
+
current = current ? `${current}/${part}` : part;
|
|
173
|
+
try {
|
|
174
|
+
location.root.createDirectoryAt(current);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
const failure = storageError(error, 'mkdir', path);
|
|
178
|
+
if (failure.code !== 'EEXIST')
|
|
179
|
+
throw failure;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function remove(path, recursive) {
|
|
184
|
+
if (stat(path).directory) {
|
|
185
|
+
if (recursive) {
|
|
186
|
+
for (const entry of readdir(path))
|
|
187
|
+
remove(`${path}/${entry.name}`, true);
|
|
188
|
+
}
|
|
189
|
+
at(path, 'rmdir', (root, relative) => root.removeDirectoryAt(relative));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
at(path, 'unlink', (root, relative) => root.unlinkFileAt(relative));
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
owns(path) {
|
|
196
|
+
if (!prefixes().some((prefix) => under(path, prefix)))
|
|
197
|
+
return false;
|
|
198
|
+
return locate(path) !== undefined;
|
|
199
|
+
},
|
|
200
|
+
readFile(path) {
|
|
201
|
+
return withFile(path, 'open', {}, { read: true }, readAll);
|
|
202
|
+
},
|
|
203
|
+
writeFile(path, bytes) {
|
|
204
|
+
withFile(path, 'open', { create: true, truncate: true }, { write: true }, (file) => writeAll(file, bytes, 0));
|
|
205
|
+
},
|
|
206
|
+
appendFile(path, bytes) {
|
|
207
|
+
withFile(path, 'open', { create: true }, { write: true }, (file) => writeAll(file, bytes, toNumber(file.stat().size)));
|
|
208
|
+
},
|
|
209
|
+
readAt(path, length, offset) {
|
|
210
|
+
return withFile(path, 'read', {}, { read: true }, (file) => {
|
|
211
|
+
const [data] = file.read(length, offset);
|
|
212
|
+
return data instanceof Uint8Array ? data : Uint8Array.from(data);
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
writeAt(path, bytes, offset) {
|
|
216
|
+
return withFile(path, 'write', { create: true }, { write: true }, (file) => {
|
|
217
|
+
const start = offset === 'end' ? toNumber(file.stat().size) : offset;
|
|
218
|
+
writeAll(file, bytes, start);
|
|
219
|
+
return start + bytes.byteLength;
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
truncate(path) {
|
|
223
|
+
withFile(path, 'open', { create: true, truncate: true }, { write: true }, () => undefined);
|
|
224
|
+
},
|
|
225
|
+
stat,
|
|
226
|
+
exists,
|
|
227
|
+
readdir,
|
|
228
|
+
mkdir,
|
|
229
|
+
remove,
|
|
230
|
+
unlink(path) {
|
|
231
|
+
at(path, 'unlink', (root, relative) => root.unlinkFileAt(relative));
|
|
232
|
+
},
|
|
233
|
+
rename(from, to) {
|
|
234
|
+
const target = locate(to);
|
|
235
|
+
at(from, 'rename', (root, relative) => {
|
|
236
|
+
if (target === undefined || target.root !== root)
|
|
237
|
+
throw 'cross-device';
|
|
238
|
+
root.renameAt(relative, target.root, target.relative);
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/** The guest's storage, backed by the host's preopened directories. */
|
|
244
|
+
export const storage = createStorage(() => getDirectories());
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EventEmitter } from './events.js';
|
|
2
|
+
export * from 'unenv/node/stream';
|
|
3
|
+
type Emitter = InstanceType<typeof EventEmitter>;
|
|
4
|
+
export declare function Stream(this: Emitter, options?: {
|
|
5
|
+
captureRejections?: boolean;
|
|
6
|
+
}): void;
|
|
7
|
+
declare const stream: typeof Stream & typeof import("node:stream") & {
|
|
8
|
+
isDisturbed: any;
|
|
9
|
+
isReadable: any;
|
|
10
|
+
compose: any;
|
|
11
|
+
isErrored: any;
|
|
12
|
+
destroy: any;
|
|
13
|
+
_isUint8Array: any;
|
|
14
|
+
_uint8ArrayToBuffer: any;
|
|
15
|
+
_isArrayBufferView: any;
|
|
16
|
+
duplexPair: any;
|
|
17
|
+
getDefaultHighWaterMark: any;
|
|
18
|
+
isDestroyed: any;
|
|
19
|
+
isWritable: any;
|
|
20
|
+
setDefaultHighWaterMark: any;
|
|
21
|
+
} & {
|
|
22
|
+
Stream: typeof Stream;
|
|
23
|
+
};
|
|
24
|
+
export default stream;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// unenv's `Stream` throws on construction, so packages that subclass Node's legacy
|
|
2
|
+
// stream (`Stream.call(this)` plus `util.inherits(Foo, Stream)`) fail. This is Node's
|
|
3
|
+
// legacy Stream: a callable EventEmitter with the classic `pipe`.
|
|
4
|
+
import unenvStream from 'unenv/node/stream';
|
|
5
|
+
import { EventEmitter } from './events.js';
|
|
6
|
+
export * from 'unenv/node/stream';
|
|
7
|
+
export function Stream(options) {
|
|
8
|
+
EventEmitter.call(this, options);
|
|
9
|
+
}
|
|
10
|
+
Object.setPrototypeOf(Stream.prototype, EventEmitter.prototype);
|
|
11
|
+
Object.setPrototypeOf(Stream, EventEmitter);
|
|
12
|
+
Stream.prototype.pipe = function pipe(dest, options) {
|
|
13
|
+
const source = this;
|
|
14
|
+
function ondata(chunk) {
|
|
15
|
+
if (dest.writable && dest.write(chunk) === false && source.pause)
|
|
16
|
+
source.pause();
|
|
17
|
+
}
|
|
18
|
+
source.on('data', ondata);
|
|
19
|
+
function ondrain() {
|
|
20
|
+
if (source.readable && source.resume)
|
|
21
|
+
source.resume();
|
|
22
|
+
}
|
|
23
|
+
dest.on('drain', ondrain);
|
|
24
|
+
// Without `end: false`, end dest once when source ends or closes.
|
|
25
|
+
if (!dest._isStdio && options?.end !== false) {
|
|
26
|
+
source.on('end', onend);
|
|
27
|
+
source.on('close', onclose);
|
|
28
|
+
}
|
|
29
|
+
let didOnEnd = false;
|
|
30
|
+
function onend() {
|
|
31
|
+
if (didOnEnd)
|
|
32
|
+
return;
|
|
33
|
+
didOnEnd = true;
|
|
34
|
+
dest.end();
|
|
35
|
+
}
|
|
36
|
+
function onclose() {
|
|
37
|
+
if (didOnEnd)
|
|
38
|
+
return;
|
|
39
|
+
didOnEnd = true;
|
|
40
|
+
if (typeof dest.destroy === 'function')
|
|
41
|
+
dest.destroy();
|
|
42
|
+
}
|
|
43
|
+
// Don't leave dangling pipes when there are errors.
|
|
44
|
+
function onerror(error) {
|
|
45
|
+
cleanup();
|
|
46
|
+
if (this.listenerCount('error') === 0)
|
|
47
|
+
this.emit('error', error);
|
|
48
|
+
}
|
|
49
|
+
source.prependListener('error', onerror);
|
|
50
|
+
dest.prependListener('error', onerror);
|
|
51
|
+
function cleanup() {
|
|
52
|
+
source.removeListener('data', ondata);
|
|
53
|
+
dest.removeListener('drain', ondrain);
|
|
54
|
+
source.removeListener('end', onend);
|
|
55
|
+
source.removeListener('close', onclose);
|
|
56
|
+
source.removeListener('error', onerror);
|
|
57
|
+
dest.removeListener('error', onerror);
|
|
58
|
+
source.removeListener('end', cleanup);
|
|
59
|
+
source.removeListener('close', cleanup);
|
|
60
|
+
dest.removeListener('close', cleanup);
|
|
61
|
+
}
|
|
62
|
+
source.on('end', cleanup);
|
|
63
|
+
source.on('close', cleanup);
|
|
64
|
+
dest.on('close', cleanup);
|
|
65
|
+
dest.emit('pipe', source);
|
|
66
|
+
return dest;
|
|
67
|
+
};
|
|
68
|
+
// `require('stream')` in Node is the Stream function carrying the other exports.
|
|
69
|
+
const stream = Object.assign(Stream, unenvStream, { Stream });
|
|
70
|
+
export default stream;
|
package/dist/platform.js
CHANGED
|
@@ -8,6 +8,7 @@ import { isNamespace } from './namespace.js';
|
|
|
8
8
|
import { resolveInsideRoot } from './paths.js';
|
|
9
9
|
import { pulumiEnvironment, runPulumi } from './pulumi.js';
|
|
10
10
|
import { materializeRegistry } from './registry.js';
|
|
11
|
+
import { resolveTarget } from './target.js';
|
|
11
12
|
export const PLATFORM_OUTPUT_SCHEMA_VERSION = 2;
|
|
12
13
|
export async function runWasmcloudPlatformDeploy(args, io, deps = DEFAULT_DEPS) {
|
|
13
14
|
const options = parsePlatformCommandArgs(args, 'platform cluster up');
|
|
@@ -75,10 +76,7 @@ export function resolvePlatformDirectory(target, workspaceRoot, manifestPath) {
|
|
|
75
76
|
}
|
|
76
77
|
function loadManagedPlatform(deps, targetName) {
|
|
77
78
|
const manifest = loadDeployManifest(deps.cwd(), deps.env);
|
|
78
|
-
const target = manifest
|
|
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
|
-
}
|
|
79
|
+
const target = resolveTarget(manifest, targetName);
|
|
82
80
|
if (target.kind !== 'managed') {
|
|
83
81
|
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
82
|
}
|
package/dist/project.d.ts
CHANGED
|
@@ -31,6 +31,11 @@ export type WasmcloudProject = {
|
|
|
31
31
|
* dedicated hostPath volume (SQLite / migration history).
|
|
32
32
|
*/
|
|
33
33
|
persistentStorage?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* False when `"logs": false` opts out of guest logs: no wasi:logging console and a
|
|
36
|
+
* `di-framework.dev/logs: "false"` WorkloadDeployment annotation. Absent means on.
|
|
37
|
+
*/
|
|
38
|
+
logs?: false;
|
|
34
39
|
};
|
|
35
40
|
export declare function findUp(startDirectory: string, fileName: string): string | undefined;
|
|
36
41
|
/** Paths from the config must stay inside the project root. */
|
package/dist/project.js
CHANGED
|
@@ -75,6 +75,9 @@ export function loadProject(startDirectory) {
|
|
|
75
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
76
|
configInvalid('allowedIpNameLookups must be an array of DNS names, IP addresses, or wildcard suffixes', configPath);
|
|
77
77
|
}
|
|
78
|
+
if (config.logs !== undefined && typeof config.logs !== 'boolean') {
|
|
79
|
+
configInvalid(`${CONFIG_FILE_NAME} "logs" must be a boolean when present`, configPath);
|
|
80
|
+
}
|
|
78
81
|
const witName = asWitIdentifier(config.name);
|
|
79
82
|
const entryPath = resolveInside(projectRoot, config.entry, 'entry', configPath);
|
|
80
83
|
const outputPath = resolveInside(projectRoot, config.output ?? `dist/${witName}.wasm`, 'output', configPath);
|
|
@@ -114,6 +117,7 @@ export function loadProject(startDirectory) {
|
|
|
114
117
|
ingress,
|
|
115
118
|
...(cronMode ? { cronMode } : {}),
|
|
116
119
|
...(persistentStorage ? { persistentStorage: true } : {}),
|
|
120
|
+
...(config.logs === false ? { logs: false } : {}),
|
|
117
121
|
...(config.allowedIpNameLookups === undefined
|
|
118
122
|
? {}
|
|
119
123
|
: { allowedIpNameLookups: config.allowedIpNameLookups }),
|
package/dist/service.d.ts
CHANGED
|
@@ -4,12 +4,21 @@ export declare const BACKING_SERVICE_API_VERSION = "platform.di-framework.dev/v1
|
|
|
4
4
|
export declare const BACKING_SERVICE_KIND = "BackingService";
|
|
5
5
|
export declare const BACKING_SERVICE_RESOURCE = "backingservices.platform.di-framework.dev";
|
|
6
6
|
export declare const BACKING_SERVICE_CLASS_RESOURCE = "backingserviceclasses.platform.di-framework.dev";
|
|
7
|
-
export declare const SERVICE_TYPES: readonly ["keyvalue", "messaging", "postgres"];
|
|
7
|
+
export declare const SERVICE_TYPES: readonly ["keyvalue", "messaging", "blobstore", "postgres", "egress"];
|
|
8
8
|
export type ServiceType = (typeof SERVICE_TYPES)[number];
|
|
9
9
|
export declare const DEFAULT_SERVICE_CLASSES: {
|
|
10
10
|
readonly keyvalue: "keyvalue-redis";
|
|
11
11
|
readonly messaging: "messaging-nats";
|
|
12
|
+
readonly blobstore: "blobstore-nats";
|
|
12
13
|
readonly postgres: "postgres-dedicated";
|
|
14
|
+
readonly egress: "egress-public";
|
|
15
|
+
};
|
|
16
|
+
export declare const DEFAULT_SERVICE_PROVIDERS: {
|
|
17
|
+
readonly keyvalue: "redis";
|
|
18
|
+
readonly messaging: "nats";
|
|
19
|
+
readonly blobstore: "nats";
|
|
20
|
+
readonly postgres: "postgres";
|
|
21
|
+
readonly egress: "platform";
|
|
13
22
|
};
|
|
14
23
|
export declare const DEFAULT_WAIT_TIMEOUT_MS = 120000;
|
|
15
24
|
export declare const WAIT_POLL_INTERVAL_MS = 2000;
|
|
@@ -26,6 +35,8 @@ export type ServiceCreateOptions = {
|
|
|
26
35
|
className?: string;
|
|
27
36
|
parameters?: ServiceSizingParameters;
|
|
28
37
|
deletionPolicy?: DeletionPolicy;
|
|
38
|
+
/** Egress only: hosts the workload may reach. */
|
|
39
|
+
destinations?: string[];
|
|
29
40
|
target?: string;
|
|
30
41
|
namespace?: string;
|
|
31
42
|
context?: string;
|
|
@@ -60,9 +71,11 @@ type BackingServiceDocument = {
|
|
|
60
71
|
className?: string;
|
|
61
72
|
parameters?: ServiceSizingParameters;
|
|
62
73
|
deletionPolicy?: string;
|
|
74
|
+
destinations?: string[];
|
|
63
75
|
};
|
|
64
76
|
status?: {
|
|
65
77
|
conditions?: ReadyCondition[];
|
|
78
|
+
approved?: string[];
|
|
66
79
|
endpoint?: {
|
|
67
80
|
host?: string;
|
|
68
81
|
port?: number;
|
|
@@ -88,8 +101,12 @@ export type ServiceSummary = {
|
|
|
88
101
|
capability: string;
|
|
89
102
|
};
|
|
90
103
|
deletionPolicy?: string;
|
|
104
|
+
destinations?: string[];
|
|
105
|
+
approved?: string[];
|
|
91
106
|
};
|
|
92
107
|
export declare function isServiceType(value: string): value is ServiceType;
|
|
108
|
+
/** An egress destination: `host`, `*.suffix`, `host:port`, or `*.suffix:port`. */
|
|
109
|
+
export declare function isEgressDestination(value: string): boolean;
|
|
93
110
|
/** DNS-label rules aligned with the BackingService CRD metadata.name schema (max 40). */
|
|
94
111
|
export declare function isBackingServiceName(value: string, max?: number): boolean;
|
|
95
112
|
export declare function serviceTypeDiscoveryText(): string;
|
|
@@ -99,6 +116,7 @@ export declare function buildBackingServiceManifest(options: {
|
|
|
99
116
|
className?: string;
|
|
100
117
|
parameters?: ServiceSizingParameters;
|
|
101
118
|
deletionPolicy?: DeletionPolicy;
|
|
119
|
+
destinations?: readonly string[];
|
|
102
120
|
}): Record<string, unknown>;
|
|
103
121
|
export declare function parseServiceCreateArgs(args: readonly string[]): ServiceCreateOptions;
|
|
104
122
|
export declare function parseServiceNameArgs(args: readonly string[], command: string): ServiceNameOptions;
|
|
@@ -117,11 +135,12 @@ export declare function runWasmcloudServiceCreate(args: readonly string[], io: C
|
|
|
117
135
|
} | undefined;
|
|
118
136
|
wait: boolean;
|
|
119
137
|
ready: string;
|
|
138
|
+
destinations?: string[] | undefined;
|
|
120
139
|
deletionPolicy?: "Retain" | "Delete" | undefined;
|
|
121
140
|
parameters?: ServiceSizingParameters | undefined;
|
|
122
141
|
context?: string | undefined;
|
|
123
142
|
name: string;
|
|
124
|
-
type: "messaging" | "
|
|
143
|
+
type: "postgres" | "keyvalue" | "messaging" | "blobstore" | "egress";
|
|
125
144
|
className: string;
|
|
126
145
|
namespace: string;
|
|
127
146
|
target: string;
|
package/dist/service.js
CHANGED
|
@@ -12,20 +12,38 @@ export const BACKING_SERVICE_API_VERSION = 'platform.di-framework.dev/v1alpha1';
|
|
|
12
12
|
export const BACKING_SERVICE_KIND = 'BackingService';
|
|
13
13
|
export const BACKING_SERVICE_RESOURCE = 'backingservices.platform.di-framework.dev';
|
|
14
14
|
export const BACKING_SERVICE_CLASS_RESOURCE = 'backingserviceclasses.platform.di-framework.dev';
|
|
15
|
-
export const SERVICE_TYPES = ['keyvalue', 'messaging', 'postgres'];
|
|
15
|
+
export const SERVICE_TYPES = ['keyvalue', 'messaging', 'blobstore', 'postgres', 'egress'];
|
|
16
16
|
export const DEFAULT_SERVICE_CLASSES = {
|
|
17
17
|
keyvalue: 'keyvalue-redis',
|
|
18
18
|
messaging: 'messaging-nats',
|
|
19
|
+
blobstore: 'blobstore-nats',
|
|
19
20
|
postgres: 'postgres-dedicated',
|
|
21
|
+
egress: 'egress-public',
|
|
22
|
+
};
|
|
23
|
+
export const DEFAULT_SERVICE_PROVIDERS = {
|
|
24
|
+
keyvalue: 'redis',
|
|
25
|
+
messaging: 'nats',
|
|
26
|
+
blobstore: 'nats',
|
|
27
|
+
postgres: 'postgres',
|
|
28
|
+
egress: 'platform',
|
|
20
29
|
};
|
|
21
30
|
export const DEFAULT_WAIT_TIMEOUT_MS = 120_000;
|
|
22
31
|
export const WAIT_POLL_INTERVAL_MS = 2_000;
|
|
23
32
|
const NAME_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
|
|
24
33
|
const QUANTITY_PATTERN = /^[0-9]+(\.[0-9]+)?(m|Ki|Mi|Gi|Ti)?$/;
|
|
34
|
+
/** `host`, `*.suffix`, optionally with `:port`; matches the BackingService egress schema. */
|
|
35
|
+
const DESTINATION_PATTERN = /^(?:\*\.)?[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*(?::([0-9]{1,5}))?$/;
|
|
25
36
|
const DELETION_POLICIES = ['Retain', 'Delete'];
|
|
26
37
|
export function isServiceType(value) {
|
|
27
38
|
return SERVICE_TYPES.includes(value);
|
|
28
39
|
}
|
|
40
|
+
/** An egress destination: `host`, `*.suffix`, `host:port`, or `*.suffix:port`. */
|
|
41
|
+
export function isEgressDestination(value) {
|
|
42
|
+
const match = DESTINATION_PATTERN.exec(value);
|
|
43
|
+
if (match === null || value.length > 260)
|
|
44
|
+
return false;
|
|
45
|
+
return match[1] === undefined || (Number(match[1]) >= 1 && Number(match[1]) <= 65535);
|
|
46
|
+
}
|
|
29
47
|
/** DNS-label rules aligned with the BackingService CRD metadata.name schema (max 40). */
|
|
30
48
|
export function isBackingServiceName(value, max = 40) {
|
|
31
49
|
return value.length >= 1 && value.length <= max && NAME_PATTERN.test(value);
|
|
@@ -35,15 +53,20 @@ export function serviceTypeDiscoveryText() {
|
|
|
35
53
|
'Supported resource types:',
|
|
36
54
|
' keyvalue default class keyvalue-redis',
|
|
37
55
|
' messaging default class messaging-nats',
|
|
56
|
+
' blobstore default class blobstore-nats',
|
|
38
57
|
' postgres default class postgres-dedicated',
|
|
58
|
+
' egress default class egress-public (needs --destination)',
|
|
39
59
|
'',
|
|
40
60
|
'Usage: di-framework platform service create <type> --name=<name> [--class=<class>]',
|
|
61
|
+
' di-framework platform service create egress <name> --destination <host[:port]> [--destination …]',
|
|
41
62
|
'Discover classes: di-framework platform service classes',
|
|
42
63
|
];
|
|
43
64
|
return `${lines.join('\n')}\n`;
|
|
44
65
|
}
|
|
45
66
|
export function buildBackingServiceManifest(options) {
|
|
46
67
|
const spec = { type: options.type };
|
|
68
|
+
if (options.destinations !== undefined)
|
|
69
|
+
spec.destinations = [...options.destinations];
|
|
47
70
|
if (options.className !== undefined)
|
|
48
71
|
spec.className = options.className;
|
|
49
72
|
if (options.parameters !== undefined && Object.keys(options.parameters).length > 0) {
|
|
@@ -70,6 +93,7 @@ export function parseServiceCreateArgs(args) {
|
|
|
70
93
|
let timeoutMs = DEFAULT_WAIT_TIMEOUT_MS;
|
|
71
94
|
let timeoutExplicit = false;
|
|
72
95
|
const parameters = {};
|
|
96
|
+
const destinations = [];
|
|
73
97
|
for (let position = 0; position < args.length; position++) {
|
|
74
98
|
const token = args[position] ?? '';
|
|
75
99
|
const nameOpt = matchOption(args, position, token, '--name');
|
|
@@ -162,6 +186,12 @@ export function parseServiceCreateArgs(args) {
|
|
|
162
186
|
position = timeoutOpt.consumedThrough;
|
|
163
187
|
continue;
|
|
164
188
|
}
|
|
189
|
+
const destinationOpt = matchOption(args, position, token, '--destination');
|
|
190
|
+
if (destinationOpt) {
|
|
191
|
+
destinations.push(destinationOpt.value);
|
|
192
|
+
position = destinationOpt.consumedThrough;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
165
195
|
if (token === '--wait') {
|
|
166
196
|
if (wait)
|
|
167
197
|
invalidUsage('Option may be provided only once: --wait', '--wait');
|
|
@@ -172,7 +202,13 @@ export function parseServiceCreateArgs(args) {
|
|
|
172
202
|
invalidUsage(`Unknown option: ${token}`, token, { command: 'platform service create' });
|
|
173
203
|
}
|
|
174
204
|
if (type !== undefined) {
|
|
175
|
-
|
|
205
|
+
// `service create egress <name>`: the name may follow the type instead of --name.
|
|
206
|
+
if (name !== undefined)
|
|
207
|
+
invalidUsage(`Unexpected argument: ${token}`, token, {
|
|
208
|
+
command: 'platform service create',
|
|
209
|
+
});
|
|
210
|
+
name = token;
|
|
211
|
+
continue;
|
|
176
212
|
}
|
|
177
213
|
if (!isServiceType(token)) {
|
|
178
214
|
invalidUsage(`Unknown service type "${token}". Supported types: ${SERVICE_TYPES.join(', ')}`, token, { command: 'platform service create', types: [...SERVICE_TYPES] });
|
|
@@ -190,6 +226,7 @@ export function parseServiceCreateArgs(args) {
|
|
|
190
226
|
wait,
|
|
191
227
|
timeoutMs,
|
|
192
228
|
parameters: Object.keys(parameters).length > 0 ? parameters : undefined,
|
|
229
|
+
...(destinations.length > 0 ? { destinations } : {}),
|
|
193
230
|
};
|
|
194
231
|
}
|
|
195
232
|
export function parseServiceNameArgs(args, command) {
|
|
@@ -281,6 +318,22 @@ function validateSizing(parameters) {
|
|
|
281
318
|
}
|
|
282
319
|
}
|
|
283
320
|
}
|
|
321
|
+
function validateDestinations(type, options) {
|
|
322
|
+
const command = { command: 'platform service create' };
|
|
323
|
+
if (type !== 'egress') {
|
|
324
|
+
if (options.destinations !== undefined)
|
|
325
|
+
invalidUsage('--destination applies only to egress services', '--destination', command);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (options.destinations === undefined)
|
|
329
|
+
invalidUsage('Missing required --destination for an egress service (host, *.suffix, host:port, or *.suffix:port)', '--destination', command);
|
|
330
|
+
for (const destination of options.destinations) {
|
|
331
|
+
if (!isEgressDestination(destination))
|
|
332
|
+
invalidUsage(`Invalid destination "${destination}". Use host, *.suffix, host:port, or *.suffix:port`, destination, command);
|
|
333
|
+
}
|
|
334
|
+
if (options.parameters !== undefined || options.deletionPolicy !== undefined)
|
|
335
|
+
invalidUsage('Egress services take no sizing or deletion-policy options', 'egress', command);
|
|
336
|
+
}
|
|
284
337
|
function validateCreateOptions(options) {
|
|
285
338
|
if (options.type === undefined) {
|
|
286
339
|
throw new CommandFailure('INVALID_USAGE', `Missing service type.\n${serviceTypeDiscoveryText().trimEnd()}`, 2, {
|
|
@@ -301,6 +354,7 @@ function validateCreateOptions(options) {
|
|
|
301
354
|
invalidUsage(`Invalid class name "${options.className}". Class names must be DNS labels of at most 40 characters`, options.className, { command: 'platform service create' });
|
|
302
355
|
}
|
|
303
356
|
validateSizing(options.parameters);
|
|
357
|
+
validateDestinations(options.type, options);
|
|
304
358
|
return { type: options.type, name: options.name };
|
|
305
359
|
}
|
|
306
360
|
async function resolveServiceConnection(options, deps) {
|
|
@@ -374,6 +428,8 @@ export function summarizeService(document) {
|
|
|
374
428
|
}
|
|
375
429
|
: {}),
|
|
376
430
|
...(document.spec?.deletionPolicy ? { deletionPolicy: document.spec.deletionPolicy } : {}),
|
|
431
|
+
...(document.spec?.destinations ? { destinations: document.spec.destinations } : {}),
|
|
432
|
+
...(document.status?.approved ? { approved: document.status.approved } : {}),
|
|
377
433
|
};
|
|
378
434
|
}
|
|
379
435
|
function formatServiceTable(services) {
|
|
@@ -385,7 +441,9 @@ function formatServiceTable(services) {
|
|
|
385
441
|
service.type,
|
|
386
442
|
service.className || '-',
|
|
387
443
|
service.ready,
|
|
388
|
-
service.endpoint
|
|
444
|
+
service.endpoint
|
|
445
|
+
? `${service.endpoint.host}:${service.endpoint.port}`
|
|
446
|
+
: (service.destinations?.join(',') ?? '-'),
|
|
389
447
|
]);
|
|
390
448
|
const widths = headers.map((header, index) => Math.max(header.length, ...rows.map((row) => row[index]?.length ?? 0)));
|
|
391
449
|
const line = (cells) => cells.map((cell, index) => cell.padEnd(widths[index] ?? 0)).join(' ');
|
|
@@ -406,6 +464,10 @@ function formatServiceDetail(summary) {
|
|
|
406
464
|
}
|
|
407
465
|
if (summary.deletionPolicy)
|
|
408
466
|
lines.push(`Deletion policy: ${summary.deletionPolicy}`);
|
|
467
|
+
if (summary.destinations)
|
|
468
|
+
lines.push(`Destinations: ${summary.destinations.join(', ')}`);
|
|
469
|
+
if (summary.approved)
|
|
470
|
+
lines.push(`Approved: ${summary.approved.join(', ') || '-'}`);
|
|
409
471
|
return `${lines.join('\n')}\n`;
|
|
410
472
|
}
|
|
411
473
|
function isServiceReady(document) {
|
|
@@ -476,6 +538,7 @@ export async function runWasmcloudServiceCreate(args, io, deps = DEFAULT_DEPS) {
|
|
|
476
538
|
className: options.className,
|
|
477
539
|
parameters: options.parameters,
|
|
478
540
|
deletionPolicy: options.deletionPolicy,
|
|
541
|
+
destinations: options.destinations,
|
|
479
542
|
});
|
|
480
543
|
const dir = mkdtempSync(join(tmpdir(), 'di-backing-service-'));
|
|
481
544
|
const path = join(dir, `${name}.json`);
|
|
@@ -520,6 +583,7 @@ export async function runWasmcloudServiceCreate(args, io, deps = DEFAULT_DEPS) {
|
|
|
520
583
|
: {}),
|
|
521
584
|
...(options.parameters ? { parameters: options.parameters } : {}),
|
|
522
585
|
...(options.deletionPolicy ? { deletionPolicy: options.deletionPolicy } : {}),
|
|
586
|
+
...(options.destinations ? { destinations: options.destinations } : {}),
|
|
523
587
|
wait: options.wait,
|
|
524
588
|
ready: summary.ready,
|
|
525
589
|
...(summary.endpoint ? { endpoint: summary.endpoint } : {}),
|
|
@@ -599,7 +663,9 @@ export async function runWasmcloudServiceDelete(args, io, deps = DEFAULT_DEPS) {
|
|
|
599
663
|
let deletionPolicy;
|
|
600
664
|
try {
|
|
601
665
|
const existing = await getServiceDocument(connection, options.name, deps);
|
|
602
|
-
|
|
666
|
+
// Egress provisions nothing, so there is nothing to retain.
|
|
667
|
+
if (existing.spec?.type !== 'egress')
|
|
668
|
+
deletionPolicy = existing.spec?.deletionPolicy ?? 'Retain';
|
|
603
669
|
}
|
|
604
670
|
catch (error) {
|
|
605
671
|
if (error instanceof CommandFailure && error.code === 'WASMCLOUD_SERVICE_NOT_FOUND') {
|
|
@@ -653,7 +719,7 @@ export async function runWasmcloudServiceClasses(args, _io, deps = DEFAULT_DEPS)
|
|
|
653
719
|
: SERVICE_TYPES.map((type) => ({
|
|
654
720
|
name: DEFAULT_SERVICE_CLASSES[type],
|
|
655
721
|
type,
|
|
656
|
-
provider: type
|
|
722
|
+
provider: DEFAULT_SERVICE_PROVIDERS[type],
|
|
657
723
|
default: true,
|
|
658
724
|
}));
|
|
659
725
|
const headers = ['NAME', 'TYPE', 'PROVIDER', 'DEFAULT'];
|