@di-framework/cli-plugin-platform 0.0.1 → 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +408 -0
- package/dist/actor-protocol.d.ts +4 -0
- package/dist/actor-protocol.js +162 -0
- package/dist/actors.d.ts +31 -0
- package/dist/actors.js +296 -0
- package/dist/args.d.ts +15 -0
- package/dist/args.js +66 -0
- package/dist/assets/http-adapter.js +876 -0
- package/dist/assets/platform/.gitignore.tmpl +6 -0
- package/dist/assets/platform/Pulumi.yaml.tmpl +6 -0
- package/dist/assets/platform/README.md +208 -0
- package/dist/assets/platform/index.ts.tmpl +2 -0
- package/dist/assets/platform/package.json.tmpl +18 -0
- package/dist/assets/platform/tsconfig.json +11 -0
- package/dist/assets/queue-adapter.js +60 -0
- package/dist/assets/sqlite/BUILD-INFO.txt +13 -0
- package/dist/assets/sqlite/SHA256SUMS +2 -0
- package/dist/assets/sqlite/di-framework-sqlite.wasm +0 -0
- package/dist/assets/sqlite/di-framework-sqlite.wit +337 -0
- package/dist/assets/wit/deps/LICENSE.md +8 -0
- package/dist/assets/wit/deps/di-framework-queues/package.wit +18 -0
- package/dist/assets/wit/deps/di-framework-sqlite/package.wit +211 -0
- package/dist/assets/wit/deps/wasi-cli/package.wit +70 -0
- package/dist/assets/wit/deps/wasi-clocks/package.wit +42 -0
- package/dist/assets/wit/deps/wasi-config/package.wit +15 -0
- package/dist/assets/wit/deps/wasi-filesystem/package.wit +184 -0
- package/dist/assets/wit/deps/wasi-http/package.wit +170 -0
- package/dist/assets/wit/deps/wasi-random/package.wit +17 -0
- package/dist/assets/wit/deps/wasi-sockets/package.wit +105 -0
- package/dist/assets/wit/deps/wasi-tls/package.wit +26 -0
- package/dist/assets/wit/deps/wasmcloud-blobstore/package.wit +153 -0
- package/dist/assets/wit/deps/wasmcloud-keyvalue/package.wit +370 -0
- package/dist/assets/wit/deps/wasmcloud-messaging/package.wit +125 -0
- package/dist/assets/wit/deps/wasmcloud-postgres/package.wit +435 -0
- package/dist/assets/wit/deps/wasmcloud-secrets/package.wit +80 -0
- package/dist/async-transform.d.ts +3 -0
- package/dist/async-transform.js +60 -0
- package/dist/bindings.d.ts +34 -0
- package/dist/bindings.js +307 -0
- package/dist/build.d.ts +29 -0
- package/dist/build.js +325 -0
- package/dist/command.d.ts +3 -0
- package/dist/command.js +141 -0
- package/dist/control/auth.d.ts +18 -0
- package/dist/control/auth.js +89 -0
- package/dist/control/cron.d.ts +7 -0
- package/dist/control/cron.js +86 -0
- package/dist/control/index.d.ts +4 -0
- package/dist/control/index.js +4 -0
- package/dist/control/network.d.ts +12 -0
- package/dist/control/network.js +49 -0
- package/dist/control/queues.d.ts +15 -0
- package/dist/control/queues.js +77 -0
- package/dist/cron.d.ts +26 -0
- package/dist/cron.js +239 -0
- package/dist/deploy.d.ts +29 -0
- package/dist/deploy.js +57 -0
- package/dist/deps.d.ts +96 -0
- package/dist/deps.js +303 -0
- package/dist/destroy.d.ts +3 -0
- package/dist/destroy.js +24 -0
- package/dist/dev-runner.d.ts +24 -0
- package/dist/dev-runner.js +83 -0
- package/dist/dev.d.ts +8 -0
- package/dist/dev.js +76 -0
- package/dist/discovery.d.ts +15 -0
- package/dist/discovery.js +182 -0
- package/dist/doctor.d.ts +8 -0
- package/dist/doctor.js +82 -0
- package/dist/guests.d.ts +9 -0
- package/dist/guests.js +56 -0
- package/dist/host-interface.d.ts +29 -0
- package/dist/host-interface.js +142 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +39 -0
- package/dist/kubernetes.d.ts +9 -0
- package/dist/kubernetes.js +17 -0
- package/dist/managed-bindings.d.ts +9 -0
- package/dist/managed-bindings.js +150 -0
- package/dist/manifest.d.ts +36 -0
- package/dist/manifest.js +257 -0
- package/dist/namespace.d.ts +2 -0
- package/dist/namespace.js +4 -0
- package/dist/node-compat/async-hooks.d.ts +29 -0
- package/dist/node-compat/async-hooks.js +80 -0
- package/dist/node-compat/bootstrap.d.ts +1 -0
- package/dist/node-compat/bootstrap.js +9 -0
- package/dist/node-compat/bytes.d.ts +7 -0
- package/dist/node-compat/bytes.js +41 -0
- package/dist/node-compat/crypto-hash.d.ts +27 -0
- package/dist/node-compat/crypto-hash.js +108 -0
- package/dist/node-compat/crypto-subtle.d.ts +59 -0
- package/dist/node-compat/crypto-subtle.js +288 -0
- package/dist/node-compat/crypto.d.ts +136 -0
- package/dist/node-compat/crypto.js +142 -0
- package/dist/node-compat/dgram.d.ts +49 -0
- package/dist/node-compat/dgram.js +197 -0
- package/dist/node-compat/env.d.ts +6 -0
- package/dist/node-compat/env.js +88 -0
- package/dist/node-compat/fetch-runtime.d.ts +80 -0
- package/dist/node-compat/fetch-runtime.js +314 -0
- package/dist/node-compat/fs.d.ts +84 -0
- package/dist/node-compat/fs.js +285 -0
- package/dist/node-compat/http-parser.d.ts +40 -0
- package/dist/node-compat/http-parser.js +185 -0
- package/dist/node-compat/http.d.ts +130 -0
- package/dist/node-compat/http.js +688 -0
- package/dist/node-compat/https.d.ts +28 -0
- package/dist/node-compat/https.js +88 -0
- package/dist/node-compat/module.d.ts +11 -0
- package/dist/node-compat/module.js +35 -0
- package/dist/node-compat/net.d.ts +119 -0
- package/dist/node-compat/net.js +441 -0
- package/dist/node-compat/process.d.ts +25 -0
- package/dist/node-compat/process.js +63 -0
- package/dist/node-compat/runtime-application.d.ts +4 -0
- package/dist/node-compat/runtime-application.js +24 -0
- package/dist/node-compat/seed-virtual.d.ts +6 -0
- package/dist/node-compat/seed-virtual.js +6 -0
- package/dist/node-compat/seed.d.ts +20 -0
- package/dist/node-compat/seed.js +106 -0
- package/dist/node-compat/socket-address.d.ts +35 -0
- package/dist/node-compat/socket-address.js +162 -0
- package/dist/node-compat/timers.d.ts +32 -0
- package/dist/node-compat/timers.js +96 -0
- package/dist/node-compat/tls.d.ts +57 -0
- package/dist/node-compat/tls.js +290 -0
- package/dist/node-compat/wasi-random.d.ts +2 -0
- package/dist/node-compat/wasi-random.js +25 -0
- package/dist/node-compat/wasi-sockets.d.ts +47 -0
- package/dist/node-compat/wasi-sockets.js +134 -0
- package/dist/oci.d.ts +9 -0
- package/dist/oci.js +9 -0
- package/dist/paths.d.ts +7 -0
- package/dist/paths.js +13 -0
- package/dist/platform-init.d.ts +13 -0
- package/dist/platform-init.js +265 -0
- package/dist/platform.d.ts +22 -0
- package/dist/platform.js +170 -0
- package/dist/project.d.ts +39 -0
- package/dist/project.js +130 -0
- package/dist/publish.d.ts +15 -0
- package/dist/publish.js +57 -0
- package/dist/pulumi.d.ts +4 -0
- package/dist/pulumi.js +27 -0
- package/dist/queues-module.d.ts +4 -0
- package/dist/queues-module.js +89 -0
- package/dist/queues.d.ts +16 -0
- package/dist/queues.js +167 -0
- package/dist/registry.d.ts +16 -0
- package/dist/registry.js +27 -0
- package/dist/service.d.ts +162 -0
- package/dist/service.js +678 -0
- package/dist/support.d.ts +14 -0
- package/dist/support.js +37 -0
- package/dist/target.d.ts +18 -0
- package/dist/target.js +45 -0
- package/dist/toml.d.ts +6 -0
- package/dist/toml.js +245 -0
- package/dist/wash-dev.d.ts +18 -0
- package/dist/wash-dev.js +80 -0
- package/dist/wit.d.ts +76 -0
- package/dist/wit.js +248 -0
- package/dist/workload-members.d.ts +12 -0
- package/dist/workload-members.js +136 -0
- package/dist/workload.d.ts +45 -0
- package/dist/workload.js +457 -0
- package/package.json +55 -8
- package/src/index.ts +0 -2
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { toBytes, toNodeBuffer } from './bytes.js';
|
|
2
|
+
import { createHash, createHmac, Hash, Hmac } from './crypto-hash.js';
|
|
3
|
+
import { getRandomValues, randomUUID, subtle, webcrypto } from './crypto-subtle.js';
|
|
4
|
+
import { getRandomBytes } from './wasi-random.js';
|
|
5
|
+
export { createHash, createHmac, getRandomValues, Hash, Hmac, randomUUID, subtle, webcrypto };
|
|
6
|
+
function cryptoUnsupported(name) {
|
|
7
|
+
const error = new Error(`crypto.${name} is not implemented in the wasmCloud guest`);
|
|
8
|
+
error.code = 'ERR_CRYPTO_UNSUPPORTED';
|
|
9
|
+
return error;
|
|
10
|
+
}
|
|
11
|
+
function notImplemented(name) {
|
|
12
|
+
return () => {
|
|
13
|
+
throw cryptoUnsupported(name);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export function randomBytes(size, callback) {
|
|
17
|
+
const bytes = toNodeBuffer(getRandomBytes(size));
|
|
18
|
+
if (typeof callback === 'function') {
|
|
19
|
+
queueMicrotask(() => callback(null, bytes));
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return bytes;
|
|
23
|
+
}
|
|
24
|
+
export function randomFillSync(buffer, offset, size) {
|
|
25
|
+
const view = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
26
|
+
const start = offset ?? 0;
|
|
27
|
+
const length = size ?? view.length - start;
|
|
28
|
+
view.set(getRandomBytes(length), start);
|
|
29
|
+
return buffer;
|
|
30
|
+
}
|
|
31
|
+
export function randomFill(buffer, offset, size, callback) {
|
|
32
|
+
let start = 0;
|
|
33
|
+
let length;
|
|
34
|
+
let cb;
|
|
35
|
+
if (typeof offset === 'function')
|
|
36
|
+
cb = offset;
|
|
37
|
+
else {
|
|
38
|
+
start = offset ?? 0;
|
|
39
|
+
if (typeof size === 'function')
|
|
40
|
+
cb = size;
|
|
41
|
+
else {
|
|
42
|
+
length = size;
|
|
43
|
+
cb = callback;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const filled = randomFillSync(buffer, start, length);
|
|
47
|
+
if (cb !== undefined) {
|
|
48
|
+
queueMicrotask(() => cb(null, filled));
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return filled;
|
|
52
|
+
}
|
|
53
|
+
export function randomInt(min, max, callback) {
|
|
54
|
+
let low = 0;
|
|
55
|
+
let high = min;
|
|
56
|
+
let cb = callback;
|
|
57
|
+
if (typeof max === 'function') {
|
|
58
|
+
cb = max;
|
|
59
|
+
}
|
|
60
|
+
else if (typeof max === 'number') {
|
|
61
|
+
low = min;
|
|
62
|
+
high = max;
|
|
63
|
+
}
|
|
64
|
+
const range = high - low;
|
|
65
|
+
if (!Number.isSafeInteger(low) || !Number.isSafeInteger(high) || range <= 0 || range >= 2 ** 48) {
|
|
66
|
+
throw new RangeError('The value of "max" is out of range');
|
|
67
|
+
}
|
|
68
|
+
const sampleSpace = 2 ** 48;
|
|
69
|
+
const limit = sampleSpace - (sampleSpace % range);
|
|
70
|
+
let value;
|
|
71
|
+
do {
|
|
72
|
+
const bytes = getRandomBytes(6);
|
|
73
|
+
value = 0;
|
|
74
|
+
for (const byte of bytes)
|
|
75
|
+
value = value * 256 + byte;
|
|
76
|
+
} while (value >= limit);
|
|
77
|
+
const result = low + (value % range);
|
|
78
|
+
if (cb !== undefined) {
|
|
79
|
+
queueMicrotask(() => cb(null, result));
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
export function timingSafeEqual(a, b) {
|
|
85
|
+
const left = toBytes(a);
|
|
86
|
+
const right = toBytes(b);
|
|
87
|
+
if (left.length !== right.length) {
|
|
88
|
+
const error = new Error('Input buffers must have the same byte length');
|
|
89
|
+
error.code = 'ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH';
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
let diff = 0;
|
|
93
|
+
for (let i = 0; i < left.length; i++)
|
|
94
|
+
diff |= (left[i] ?? 0) ^ (right[i] ?? 0);
|
|
95
|
+
return diff === 0;
|
|
96
|
+
}
|
|
97
|
+
export const rng = randomBytes;
|
|
98
|
+
export const prng = randomBytes;
|
|
99
|
+
export const checkPrime = notImplemented('checkPrime');
|
|
100
|
+
export const checkPrimeSync = notImplemented('checkPrimeSync');
|
|
101
|
+
export const createCipheriv = notImplemented('createCipheriv');
|
|
102
|
+
export const createDecipheriv = notImplemented('createDecipheriv');
|
|
103
|
+
export const createDiffieHellman = notImplemented('createDiffieHellman');
|
|
104
|
+
export const createECDH = notImplemented('createECDH');
|
|
105
|
+
export const createPrivateKey = notImplemented('createPrivateKey');
|
|
106
|
+
export const createPublicKey = notImplemented('createPublicKey');
|
|
107
|
+
export const createSecretKey = notImplemented('createSecretKey');
|
|
108
|
+
export const createSign = notImplemented('createSign');
|
|
109
|
+
export const createVerify = notImplemented('createVerify');
|
|
110
|
+
export const diffieHellman = notImplemented('diffieHellman');
|
|
111
|
+
export const generateKeyPair = notImplemented('generateKeyPair');
|
|
112
|
+
export const generateKeyPairSync = notImplemented('generateKeyPairSync');
|
|
113
|
+
export const generateKey = notImplemented('generateKey');
|
|
114
|
+
export const pbkdf2 = notImplemented('pbkdf2');
|
|
115
|
+
export const pbkdf2Sync = notImplemented('pbkdf2Sync');
|
|
116
|
+
export const scrypt = notImplemented('scrypt');
|
|
117
|
+
export const scryptSync = notImplemented('scryptSync');
|
|
118
|
+
export const sign = notImplemented('sign');
|
|
119
|
+
export const verify = notImplemented('verify');
|
|
120
|
+
export const hkdfSync = notImplemented('hkdfSync');
|
|
121
|
+
export const privateDecrypt = notImplemented('privateDecrypt');
|
|
122
|
+
export const privateEncrypt = notImplemented('privateEncrypt');
|
|
123
|
+
export const publicDecrypt = notImplemented('publicDecrypt');
|
|
124
|
+
export const publicEncrypt = notImplemented('publicEncrypt');
|
|
125
|
+
const cryptoObject = {
|
|
126
|
+
createHash,
|
|
127
|
+
createHmac,
|
|
128
|
+
Hash,
|
|
129
|
+
Hmac,
|
|
130
|
+
randomBytes,
|
|
131
|
+
randomFill,
|
|
132
|
+
randomFillSync,
|
|
133
|
+
randomInt,
|
|
134
|
+
randomUUID,
|
|
135
|
+
getRandomValues,
|
|
136
|
+
timingSafeEqual,
|
|
137
|
+
subtle,
|
|
138
|
+
webcrypto,
|
|
139
|
+
rng,
|
|
140
|
+
prng,
|
|
141
|
+
};
|
|
142
|
+
export default cryptoObject;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { type IpAddressFamily, type IpSocketAddress } from './socket-address.js';
|
|
3
|
+
import { type WasiUdpSocket } from './wasi-sockets.js';
|
|
4
|
+
export type RemoteInfo = {
|
|
5
|
+
address: string;
|
|
6
|
+
family: 'IPv4' | 'IPv6';
|
|
7
|
+
port: number;
|
|
8
|
+
size: number;
|
|
9
|
+
};
|
|
10
|
+
export type SocketType = 'udp4' | 'udp6';
|
|
11
|
+
export declare class Socket extends EventEmitter {
|
|
12
|
+
type: SocketType;
|
|
13
|
+
family: IpAddressFamily;
|
|
14
|
+
native: WasiUdpSocket | undefined;
|
|
15
|
+
bound: boolean;
|
|
16
|
+
closed: boolean;
|
|
17
|
+
receiving: boolean;
|
|
18
|
+
localAddress: string;
|
|
19
|
+
localPort: number;
|
|
20
|
+
constructor(type?: SocketType | {
|
|
21
|
+
type?: SocketType;
|
|
22
|
+
});
|
|
23
|
+
bind(portOrOptions?: number | {
|
|
24
|
+
port?: number;
|
|
25
|
+
address?: string;
|
|
26
|
+
} | (() => void), addressOrCallback?: string | (() => void), maybeCallback?: () => void): this;
|
|
27
|
+
send(msg: string | Uint8Array, offsetOrPort?: number, lengthOrAddress?: number | string, portOrCallback?: number | ((error?: Error | null, bytes?: number) => void), addressOrCallback?: string | ((error?: Error | null, bytes?: number) => void), maybeCallback?: (error?: Error | null, bytes?: number) => void): void;
|
|
28
|
+
address(): {
|
|
29
|
+
address: string;
|
|
30
|
+
family: string;
|
|
31
|
+
port: number;
|
|
32
|
+
};
|
|
33
|
+
close(callback?: () => void): this;
|
|
34
|
+
ref(): this;
|
|
35
|
+
unref(): this;
|
|
36
|
+
bindResolved(local: IpSocketAddress): void;
|
|
37
|
+
bindNative(address: string, port: number): Promise<void>;
|
|
38
|
+
sendNative(bytes: Uint8Array, port: number, address: string, callback?: (error?: Error | null, bytes?: number) => void): Promise<void>;
|
|
39
|
+
startReceive(native: WasiUdpSocket): void;
|
|
40
|
+
receiveLoop(native: WasiUdpSocket): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export declare function createSocket(type?: SocketType | {
|
|
43
|
+
type?: SocketType;
|
|
44
|
+
}, listener?: (msg: Uint8Array, rinfo: RemoteInfo) => void): Socket;
|
|
45
|
+
declare const _default: {
|
|
46
|
+
Socket: typeof Socket;
|
|
47
|
+
createSocket: typeof createSocket;
|
|
48
|
+
};
|
|
49
|
+
export default _default;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { familyFromHost, formatIpSocketAddress, ipSocketAddress, unspecifiedAddress, } from './socket-address.js';
|
|
3
|
+
import { createUdpSocket, firstOfTuple, readSocketAddress, resolveSocketAddress, socketError, toBytes, toNodeBuffer, unwrapAsync, unwrapResult, } from './wasi-sockets.js';
|
|
4
|
+
function familyFromType(type) {
|
|
5
|
+
const name = typeof type === 'string' ? type : (type.type ?? 'udp4');
|
|
6
|
+
return name === 'udp6' ? 'ipv6' : 'ipv4';
|
|
7
|
+
}
|
|
8
|
+
function emitSocketError(emitter, error) {
|
|
9
|
+
if (typeof emitter.listenerCount === 'function' && emitter.listenerCount('error') === 0)
|
|
10
|
+
return;
|
|
11
|
+
emitter.emit('error', error);
|
|
12
|
+
}
|
|
13
|
+
export class Socket extends EventEmitter {
|
|
14
|
+
type;
|
|
15
|
+
family;
|
|
16
|
+
native;
|
|
17
|
+
bound = false;
|
|
18
|
+
closed = false;
|
|
19
|
+
receiving = false;
|
|
20
|
+
localAddress = '';
|
|
21
|
+
localPort = 0;
|
|
22
|
+
constructor(type = 'udp4') {
|
|
23
|
+
super();
|
|
24
|
+
this.type = (typeof type === 'string' ? type : (type.type ?? 'udp4'));
|
|
25
|
+
this.family = familyFromType(type);
|
|
26
|
+
}
|
|
27
|
+
bind(portOrOptions, addressOrCallback, maybeCallback) {
|
|
28
|
+
let port = 0;
|
|
29
|
+
let address = this.family === 'ipv6' ? '::' : '0.0.0.0';
|
|
30
|
+
let callback;
|
|
31
|
+
if (typeof portOrOptions === 'function') {
|
|
32
|
+
callback = portOrOptions;
|
|
33
|
+
}
|
|
34
|
+
else if (typeof portOrOptions === 'object' && portOrOptions !== null) {
|
|
35
|
+
port = portOrOptions.port ?? 0;
|
|
36
|
+
address = portOrOptions.address ?? address;
|
|
37
|
+
callback = typeof addressOrCallback === 'function' ? addressOrCallback : undefined;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (typeof portOrOptions === 'number')
|
|
41
|
+
port = portOrOptions;
|
|
42
|
+
if (typeof addressOrCallback === 'string')
|
|
43
|
+
address = addressOrCallback;
|
|
44
|
+
else if (typeof addressOrCallback === 'function')
|
|
45
|
+
callback = addressOrCallback;
|
|
46
|
+
if (typeof maybeCallback === 'function')
|
|
47
|
+
callback = maybeCallback;
|
|
48
|
+
}
|
|
49
|
+
if (typeof callback === 'function')
|
|
50
|
+
this.once('listening', callback);
|
|
51
|
+
const resolved = ipSocketAddress(address, port, this.family);
|
|
52
|
+
if (resolved !== undefined)
|
|
53
|
+
this.bindResolved(resolved);
|
|
54
|
+
else
|
|
55
|
+
void this.bindNative(address, port);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
send(msg, offsetOrPort, lengthOrAddress, portOrCallback, addressOrCallback, maybeCallback) {
|
|
59
|
+
let bytes = toBytes(msg);
|
|
60
|
+
let port = 0;
|
|
61
|
+
let address = this.family === 'ipv6' ? '::1' : '127.0.0.1';
|
|
62
|
+
let callback;
|
|
63
|
+
if (typeof offsetOrPort === 'number' && typeof lengthOrAddress === 'number') {
|
|
64
|
+
bytes = bytes.subarray(offsetOrPort, offsetOrPort + lengthOrAddress);
|
|
65
|
+
port = typeof portOrCallback === 'number' ? portOrCallback : 0;
|
|
66
|
+
if (typeof addressOrCallback === 'string')
|
|
67
|
+
address = addressOrCallback;
|
|
68
|
+
callback =
|
|
69
|
+
typeof maybeCallback === 'function'
|
|
70
|
+
? maybeCallback
|
|
71
|
+
: typeof addressOrCallback === 'function'
|
|
72
|
+
? addressOrCallback
|
|
73
|
+
: undefined;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
port = typeof offsetOrPort === 'number' ? offsetOrPort : 0;
|
|
77
|
+
if (typeof lengthOrAddress === 'string')
|
|
78
|
+
address = lengthOrAddress;
|
|
79
|
+
callback =
|
|
80
|
+
typeof portOrCallback === 'function'
|
|
81
|
+
? portOrCallback
|
|
82
|
+
: typeof addressOrCallback === 'function'
|
|
83
|
+
? addressOrCallback
|
|
84
|
+
: undefined;
|
|
85
|
+
}
|
|
86
|
+
void this.sendNative(bytes, port, address, callback);
|
|
87
|
+
}
|
|
88
|
+
address() {
|
|
89
|
+
return {
|
|
90
|
+
address: this.localAddress || (this.family === 'ipv6' ? '::' : '0.0.0.0'),
|
|
91
|
+
family: this.family === 'ipv6' ? 'IPv6' : 'IPv4',
|
|
92
|
+
port: this.localPort,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
close(callback) {
|
|
96
|
+
this.closed = true;
|
|
97
|
+
if (typeof callback === 'function')
|
|
98
|
+
this.once('close', callback);
|
|
99
|
+
queueMicrotask(() => this.emit('close'));
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
ref() {
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
unref() {
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
bindResolved(local) {
|
|
109
|
+
try {
|
|
110
|
+
const native = this.native ?? createUdpSocket(this.family);
|
|
111
|
+
this.native = native;
|
|
112
|
+
unwrapResult(native.bind(local), 'bind');
|
|
113
|
+
const reported = formatIpSocketAddress(readSocketAddress(native.getLocalAddress(), 'getsockname'));
|
|
114
|
+
this.localAddress = reported.address;
|
|
115
|
+
this.localPort = reported.port;
|
|
116
|
+
this.bound = true;
|
|
117
|
+
this.startReceive(native);
|
|
118
|
+
queueMicrotask(() => this.emit('listening'));
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
emitSocketError(this, error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async bindNative(address, port) {
|
|
125
|
+
try {
|
|
126
|
+
this.family = familyFromHost(address, this.family);
|
|
127
|
+
this.bindResolved(await resolveSocketAddress(address, port, this.family, 'bind'));
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
emitSocketError(this, error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async sendNative(bytes, port, address, callback) {
|
|
134
|
+
try {
|
|
135
|
+
if (this.closed)
|
|
136
|
+
throw socketError('invalid-state', 'send');
|
|
137
|
+
const native = this.native ?? createUdpSocket(this.family);
|
|
138
|
+
this.native = native;
|
|
139
|
+
if (!this.bound) {
|
|
140
|
+
this.bindResolved(unspecifiedAddress(this.family, 0));
|
|
141
|
+
}
|
|
142
|
+
const remote = await resolveSocketAddress(address, port, this.family, 'send');
|
|
143
|
+
await unwrapAsync(native.send(bytes, remote), 'send');
|
|
144
|
+
callback?.(null, bytes.length);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (callback !== undefined)
|
|
148
|
+
callback(error);
|
|
149
|
+
else
|
|
150
|
+
emitSocketError(this, error);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
startReceive(native) {
|
|
154
|
+
if (this.receiving)
|
|
155
|
+
return;
|
|
156
|
+
this.receiving = true;
|
|
157
|
+
void this.receiveLoop(native);
|
|
158
|
+
}
|
|
159
|
+
async receiveLoop(native) {
|
|
160
|
+
while (!this.closed) {
|
|
161
|
+
try {
|
|
162
|
+
const received = await unwrapAsync(native.receive(), 'recv');
|
|
163
|
+
const tuple = Array.isArray(received)
|
|
164
|
+
? received
|
|
165
|
+
: firstOfTuple(received);
|
|
166
|
+
const payload = toBytes(Array.isArray(tuple) ? tuple[0] : tuple);
|
|
167
|
+
const remoteRaw = Array.isArray(tuple) ? tuple[1] : undefined;
|
|
168
|
+
const remote = remoteRaw !== undefined
|
|
169
|
+
? formatIpSocketAddress(readSocketAddress(remoteRaw, 'recv'))
|
|
170
|
+
: {
|
|
171
|
+
address: '',
|
|
172
|
+
family: (this.family === 'ipv6' ? 'IPv6' : 'IPv4'),
|
|
173
|
+
port: 0,
|
|
174
|
+
};
|
|
175
|
+
const rinfo = {
|
|
176
|
+
address: remote.address,
|
|
177
|
+
family: remote.family,
|
|
178
|
+
port: remote.port,
|
|
179
|
+
size: payload.length,
|
|
180
|
+
};
|
|
181
|
+
this.emit('message', toNodeBuffer(payload), rinfo);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (!this.closed)
|
|
185
|
+
emitSocketError(this, error);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
export function createSocket(type = 'udp4', listener) {
|
|
192
|
+
const socket = new Socket(type);
|
|
193
|
+
if (typeof listener === 'function')
|
|
194
|
+
socket.on('message', listener);
|
|
195
|
+
return socket;
|
|
196
|
+
}
|
|
197
|
+
export default { Socket, createSocket };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Preset, type ResolvedEnvironment } from 'unenv';
|
|
2
|
+
/** Prefer compiled `.js` in published dist; fall back to `.ts` under bun tests. */
|
|
3
|
+
export declare function resolveRuntimeFile(fromDirectory: string, name: string): string;
|
|
4
|
+
export declare function wasmcloudUnenvPreset(fsPath?: string, processPath?: string, modulePath?: string, netPath?: string, dgramPath?: string, cryptoPath?: string, httpPath?: string, tlsPath?: string, httpsPath?: string): Preset;
|
|
5
|
+
export declare function rolldownInject(inject: ResolvedEnvironment['inject']): Record<string, string | [string, string]>;
|
|
6
|
+
export declare function wasmcloudNodeEnv(): ResolvedEnvironment;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { defineEnv } from 'unenv';
|
|
5
|
+
const directory = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
/** Prefer compiled `.js` in published dist; fall back to `.ts` under bun tests. */
|
|
7
|
+
export function resolveRuntimeFile(fromDirectory, name) {
|
|
8
|
+
const compiled = join(fromDirectory, `${name}.js`);
|
|
9
|
+
return existsSync(compiled) ? compiled : join(fromDirectory, `${name}.ts`);
|
|
10
|
+
}
|
|
11
|
+
function runtimeFile(name) {
|
|
12
|
+
return resolveRuntimeFile(directory, name);
|
|
13
|
+
}
|
|
14
|
+
export function wasmcloudUnenvPreset(fsPath = runtimeFile('fs'), processPath = runtimeFile('process'), modulePath = runtimeFile('module'), netPath = runtimeFile('net'), dgramPath = runtimeFile('dgram'), cryptoPath = runtimeFile('crypto'), httpPath = runtimeFile('http'), tlsPath = runtimeFile('tls'), httpsPath = runtimeFile('https')) {
|
|
15
|
+
return {
|
|
16
|
+
meta: { name: 'unenv:wasmcloud' },
|
|
17
|
+
alias: {
|
|
18
|
+
async_hooks: runtimeFile('async-hooks'),
|
|
19
|
+
'node:async_hooks': runtimeFile('async-hooks'),
|
|
20
|
+
timers: runtimeFile('timers'),
|
|
21
|
+
'node:timers': runtimeFile('timers'),
|
|
22
|
+
fs: fsPath,
|
|
23
|
+
'node:fs': fsPath,
|
|
24
|
+
process: processPath,
|
|
25
|
+
'node:process': processPath,
|
|
26
|
+
module: modulePath,
|
|
27
|
+
'node:module': modulePath,
|
|
28
|
+
net: netPath,
|
|
29
|
+
'node:net': netPath,
|
|
30
|
+
dgram: dgramPath,
|
|
31
|
+
'node:dgram': dgramPath,
|
|
32
|
+
crypto: cryptoPath,
|
|
33
|
+
'node:crypto': cryptoPath,
|
|
34
|
+
http: httpPath,
|
|
35
|
+
'node:http': httpPath,
|
|
36
|
+
tls: tlsPath,
|
|
37
|
+
'node:tls': tlsPath,
|
|
38
|
+
https: httpsPath,
|
|
39
|
+
'node:https': httpsPath,
|
|
40
|
+
},
|
|
41
|
+
inject: {
|
|
42
|
+
process: [processPath, 'default'],
|
|
43
|
+
crypto: [cryptoPath, 'webcrypto'],
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function withoutProcessPolyfill(polyfill) {
|
|
48
|
+
return polyfill.filter((entry) => !entry.includes('polyfill/process'));
|
|
49
|
+
}
|
|
50
|
+
export function rolldownInject(inject) {
|
|
51
|
+
const result = {};
|
|
52
|
+
for (const [name, value] of Object.entries(inject)) {
|
|
53
|
+
if (Array.isArray(value)) {
|
|
54
|
+
const specifier = value[0];
|
|
55
|
+
const exported = value[1];
|
|
56
|
+
if (typeof specifier === 'string' && typeof exported === 'string') {
|
|
57
|
+
result[name] = [specifier, exported];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (typeof value === 'string') {
|
|
61
|
+
result[name] = value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
let cached;
|
|
67
|
+
export function wasmcloudNodeEnv() {
|
|
68
|
+
if (cached !== undefined)
|
|
69
|
+
return cached;
|
|
70
|
+
const processPath = runtimeFile('process');
|
|
71
|
+
const env = defineEnv({
|
|
72
|
+
nodeCompat: true,
|
|
73
|
+
resolve: true,
|
|
74
|
+
presets: [wasmcloudUnenvPreset()],
|
|
75
|
+
}).env;
|
|
76
|
+
const cryptoPath = runtimeFile('crypto');
|
|
77
|
+
cached = {
|
|
78
|
+
alias: env.alias,
|
|
79
|
+
inject: {
|
|
80
|
+
...env.inject,
|
|
81
|
+
process: [processPath, 'default'],
|
|
82
|
+
crypto: [cryptoPath, 'webcrypto'],
|
|
83
|
+
},
|
|
84
|
+
polyfill: withoutProcessPolyfill(env.polyfill),
|
|
85
|
+
external: env.external,
|
|
86
|
+
};
|
|
87
|
+
return cached;
|
|
88
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Fetch/URL/encoding globals for QuickJS-based WASI 0.3 guests.
|
|
3
|
+
*
|
|
4
|
+
* WASI 0.3 async HTTP (`wasi:http/handler#handle`) is the component interface,
|
|
5
|
+
* not the WHATWG Fetch API. componentize-qjs embeds QuickJS, which has neither
|
|
6
|
+
* `Request`/`Response` nor `URLSearchParams`. StarlingMonkey does provide
|
|
7
|
+
* Fetch; install these polyfills only when those globals are missing so the
|
|
8
|
+
* application contract (`new Response(...)`) stays unchanged.
|
|
9
|
+
*/
|
|
10
|
+
export declare class TextEncoderPolyfill {
|
|
11
|
+
encode(input?: string): Uint8Array;
|
|
12
|
+
}
|
|
13
|
+
export declare class TextDecoderPolyfill {
|
|
14
|
+
decode(input?: ArrayBuffer | ArrayBufferView | null): string;
|
|
15
|
+
}
|
|
16
|
+
export declare class URLSearchParamsPolyfill {
|
|
17
|
+
#private;
|
|
18
|
+
constructor(init?: string | URLSearchParamsPolyfill | Record<string, string>);
|
|
19
|
+
get(name: string): string | null;
|
|
20
|
+
entries(): IterableIterator<[string, string]>;
|
|
21
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
22
|
+
toString(): string;
|
|
23
|
+
}
|
|
24
|
+
export declare class URLPolyfill {
|
|
25
|
+
href: string;
|
|
26
|
+
protocol: string;
|
|
27
|
+
hostname: string;
|
|
28
|
+
host: string;
|
|
29
|
+
port: string;
|
|
30
|
+
pathname: string;
|
|
31
|
+
search: string;
|
|
32
|
+
hash: string;
|
|
33
|
+
origin: string;
|
|
34
|
+
searchParams: URLSearchParamsPolyfill;
|
|
35
|
+
constructor(url: string, base?: string);
|
|
36
|
+
toString(): string;
|
|
37
|
+
}
|
|
38
|
+
export declare class HeadersPolyfill {
|
|
39
|
+
#private;
|
|
40
|
+
constructor(init?: HeadersPolyfill | Record<string, string> | Array<[string, string]>);
|
|
41
|
+
append(name: string, value: string): void;
|
|
42
|
+
set(name: string, value: string): void;
|
|
43
|
+
get(name: string): string | null;
|
|
44
|
+
has(name: string): boolean;
|
|
45
|
+
delete(name: string): void;
|
|
46
|
+
entries(): IterableIterator<[string, string]>;
|
|
47
|
+
forEach(callback: (value: string, name: string, parent: HeadersPolyfill) => void): void;
|
|
48
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
49
|
+
}
|
|
50
|
+
export declare function isAsyncIterable(value: unknown): value is AsyncIterable<unknown>;
|
|
51
|
+
type BodySource = Uint8Array | AsyncIterable<unknown> | null;
|
|
52
|
+
export declare function collectBytes(source: BodySource): Promise<Uint8Array>;
|
|
53
|
+
export declare function bodyAsStream(source: BodySource): AsyncIterable<Uint8Array> | null;
|
|
54
|
+
export declare class RequestPolyfill {
|
|
55
|
+
#private;
|
|
56
|
+
method: string;
|
|
57
|
+
url: string;
|
|
58
|
+
headers: HeadersPolyfill;
|
|
59
|
+
constructor(input: string | RequestPolyfill, init?: Record<string, unknown>);
|
|
60
|
+
get body(): AsyncIterable<Uint8Array> | null;
|
|
61
|
+
clone(): RequestPolyfill;
|
|
62
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
63
|
+
text(): Promise<string>;
|
|
64
|
+
json(): Promise<unknown>;
|
|
65
|
+
}
|
|
66
|
+
export declare class ResponsePolyfill {
|
|
67
|
+
#private;
|
|
68
|
+
status: number;
|
|
69
|
+
statusText: string;
|
|
70
|
+
headers: HeadersPolyfill;
|
|
71
|
+
ok: boolean;
|
|
72
|
+
constructor(body?: unknown, init?: Record<string, unknown>);
|
|
73
|
+
static json(data: unknown, init?: Record<string, unknown>): ResponsePolyfill;
|
|
74
|
+
get body(): AsyncIterable<Uint8Array> | null;
|
|
75
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
76
|
+
text(): Promise<string>;
|
|
77
|
+
json(): Promise<unknown>;
|
|
78
|
+
}
|
|
79
|
+
export declare function installFetchRuntime(force?: boolean): void;
|
|
80
|
+
export {};
|