@bytecodealliance/jco-std
这个 @bytecodealliance/jco 子项目包含共享功能和
用于在 Javascript 中构建 Web Assembly 组件的可重复使用的库.
Web大会组件 是使用组件模型的网络大会二进制, 用于互操作的WebAssembly库、应用程序和环境的不断发展的架构.
WebAssembly 组件可以从服务器侧式应用程序使用 财务报告和审定财务报表 在浏览器中,以及
@bytecodealliance/jco-std 包含两种环境的共享功能和辅助工具.
@bytecodealliance/preview2-shim 是选入时使用的可选对等依赖
节点执行 wasi:tls。使用此提供者的应用程序必须共享
同样的shim 实例与他们的 WASI 套接字和流: 单独的例子
不同的资源类 和IO工人。 使用符合
已安装 jco-std 释放的对等要求。 其他消费者并不需要这个.
适配器
以下是由下列人员提供的适配器列表: @bytecodealliance/jco-std数字 :
HTTP 密码
| 导出 | 说明 |
|---|---|
http/adapters/hono | 启用更容易的构建 浩诺 HTTP 服务器 |
节点JS API(实验)
jco-std 还提供实验性节点JS API,用于工具如 jco 改为
将NodeJS程序建设为组件.
| 导出 | 说明 |
|---|---|
wasi/0.2.x/node/24.x.x/assert | node:assert 适配器, WASI p2 上的节点 24 |
wasi/0.2.x/node/24.x.x/console | node:console 宾客适配器,以取代明确的主机能力 |
wasi/0.2.x/node/24.x.x/errors | 节点 24 全球错误构建器和共享编码错误行为 |
wasi/0.2.x/node/24.x.x/dns | node:dns 宾客适配器,以取代明确的主机能力 |
wasi/0.2.x/node/24.x.x/fs | node:fs 财务报告和审定财务报表 node:fs/promises 超过明确的东道方能力 |
wasi/0.2.x/node/24.x.x/http | node:http API 有直接的 WASI 套接字 和 WASI HTTP 执行 |
wasi/0.2.x/node/24.x.x/http2 | node:http2 API 有直接和清晰文本 WASI 套接字执行 |
wasi/0.2.x/node/24.x.x/https | node:https API 共享 node:http 核心和执行 |
wasi/0.2.x/node/24.x.x/net | node:net 预览 |
wasi/0.2.x/node/24.x.x/net/core | node:net 核心在注入的 WASI 预览 2 套接字 |
wasi/0.2.x/node/24.x.x/os | node:os 宾客适配器,以取代明确的主机能力 |
wasi/0.2.x/node/24.x.x/path | node:path 适配器, WASI p2 上的节点 24 |
wasi/0.3.x/node/24.x.x/path | 相同的节点 24 路径执行和类型,与 P3 环境提供者使用 |
wasi/0.2.x/node/24.x.x/string-decoder | 来宾-当地 node:string_decoder 执行节点24 |
wasi/0.2.x/node/24.x.x/timers | 节点 24 调用时间与引擎调度 |
wasi/0.2.x/node/24.x.x/timers/promises | 承诺计时器、可中止间隔计时器和排程器 |
wasi/0.2.x/node/24.x.x/domain | node:domain,在上游贬值:每个用途 |
wasi/0.2.x/node/24.x.x/async-hooks | node:async_hooks 客机适配器,节点 24,仅同步瞄准镜 |
wasi/0.2.x/node/24.x.x/diagnostics-channel | node:diagnostics_channel 客机适配器,节点24 |
wasi/0.2.x/node/24.x.x/child-process | node:child_process 客机适配器,通过明确的主机能力24号节点 |
wasi/0.2.x/node/24.x.x/cluster | node:cluster 客机适配器,通过明确的主机能力24号节点 |
wasi/0.2.x/node/24.x.x/events | node:events jco在供应的发射芯上执行入口 |
wasi/0.2.x/node/24.x.x/module | node:module,节点24:分类和源地图;拒绝加载 |
wasi/0.2.x/node/26.x.x/ffi | node:ffi 客机适配器,通过明确的主机能力26号节点 |
wasi/0.2.x/node/26.x.x/ffi/host | 拒绝默认主机 jco:node/ffi |
wasi/0.2.x/node/26.x.x/ffi/host/node | Opt-in 主机在运行时间的真实性 node:ffi· ; setSuffix() 标出后缀 |
wasi/0.2.x/node/24.x.x/inspector | node:inspector 客机适配器,通过明确的主机能力24号节点 |
wasi/0.2.x/node/24.x.x/inspector/promises | node:inspector/promises,共享一个核心 node:inspector |
wasi/0.2.x/node/24.x.x/inspector/host | 拒绝默认主机 jco:node/inspector |
wasi/0.2.x/node/24.x.x/inspector/host/node | Opt-in 主机在运行时间的真实性 node:inspector |
wasi/0.2.x/node/24.x.x/stream 财务报告和审定财务报表 /stream/promises | 经典 可读流上的节点流 4.7.0, 有节点 24 适配器 |
wasi/0.2.x/node/24.x.x/stream/consumers | 可移植 node:stream/consumers,节点24 |
wasi/0.2.x/node/24.x.x/stream/iter | 来自节点24.20的可实验流 |
wasi/0.2.x/node/24.x.x/repl | node:repl 横过读行端口;只进行全局评价 |
wasi/0.2.x/node/24.x.x/tty | node:tty 客机适配器,通过明确的主机能力24号节点 |
wasi/0.2.x/node/24.x.x/tty/host | 拒绝默认主机 jco:node/tty |
wasi/0.2.x/node/24.x.x/tty/host/node | Opt-in 主机在运行时间的真实性 node:tty 及其说明 |
wasi/0.2.x/node/24.x.x/wasi | node:wasi 客机适配器, 节点 24; 只构造, 拒绝运行 |
wasi/0.2.x/node/24.x.x/wasi/host | 拒绝默认主机 jco:node/wasi |
wasi/0.2.x/node/24.x.x/wasi/host/node | 运行真实的 Opt- in 主机 node:wasi 它的构造器 uvwasi 检查 |
wasi/0.2.x/node/24.x.x/child-process/host | 拒绝默认主机 jco:node/child-process |
wasi/0.2.x/node/24.x.x/child-process/host/node | Opt-in 主机在运行时间的真实性 node:child_process |
wasi/0.2.x/node/24.x.x/cluster/host | 拒绝默认主机 jco:node/cluster |
wasi/0.2.x/node/24.x.x/cluster/host/node | Opt-in 主机在运行时间的真实性 node:cluster |
wasi/0.2.x/node/24.x.x/console/host | 拒绝默认主机 jco:node/console |
wasi/0.2.x/node/24.x.x/console/host/node | Opt-in 主机在运行时间的真实性 node:console |
wasi/0.2.x/node/24.x.x/dns/promises | node:dns/promises,共享一个核心 node:dns |
wasi/0.2.x/node/24.x.x/dns/host | 拒绝默认主机 jco:node/dns |
wasi/0.2.x/node/24.x.x/dns/host/node | Opt-in 主机在运行时间的真实性 node:dns |
wasi/0.2.x/node/24.x.x/fs/promises | node:fs/promises,共享一个核心 node:fs |
wasi/0.2.x/node/24.x.x/fs/host | 拒绝默认主机 jco:node/fs |
wasi/0.2.x/node/24.x.x/fs/host/node | Opt-in 主机在运行时间的真实性 node:fs |
wasi/0.2.x/node/24.x.x/http/core | node:http 可选择执行部分共享的核心 |
wasi/0.2.x/node/24.x.x/http/impl/wasi-sockets | node:http 预览 2 套接字 |
wasi/0.2.x/node/24.x.x/http/impl/wasi-http | node:http 预览 2 HTTP 执行 |
wasi/0.2.x/node/24.x.x/http/host | 拒绝默认主机 jco:node/http |
wasi/0.2.x/node/24.x.x/http/host/node | Opt-in 主机在运行时间的真实性 node:http 财务报告和审定财务报表 node:https |
wasi/0.2.x/node/24.x.x/https/core | node:https 可选择执行部分共享的核心 |
wasi/0.2.x/node/24.x.x/os/host | 拒绝默认主机 jco:node/os |
wasi/0.2.x/node/24.x.x/os/host/node | Opt-in 主机在运行时间的真实性 node:os |
node/path | 遗产未转换的别名 wasi/0.2.x/node/24.x.x/path |
快速启动
@bytecodealliance/jco-std 本节通过出口可以以各种方式使用
包含一些如何快速启动的例子.
Http( 通过Hono适配器)
用于 @bytecodealliance/jco-std 建楼 浩诺 webAssembly 的应用程序,
使用该 @bytecodealliance/jco-std/http/adapters/hono 导出 :
import { Hono } from "hono";
import { fire } from "@bytecodealliance/jco-std/wasi/0.2.x/http/adapters/hono/server";
const app = new Hono();
app.get("/", () => "Hello World!");
fire(app);
// Although we've called `fire()` with wasi HTTP configured for use above,
// we still need to actually export the `wasi:http/incoming-handler` interface object,
// as componentize-js will be looking for the ES module export.
export { incomingHandler } from "@bytecodealliance/jco-std/wasi/0.2.x/http/adapters/hono/server";
[注] 我们用
@bytecodealliance/jco-std/wasi/0.2.x但是,如果你想使用一个特定的版本,你可以 使用明确版本的导出像@bytecodealliance/jco-std/wasi/0.2.12。 。 。 .这个
0.2.x路径选择用组件化JS验证的最新 WASI 0.2 适配器 jco使用的版本. 它可能改变任何jco-std释放。 使用明确的版本 当您的组件必须保留一个更古老的WIT世界时,路径.
节点.js 兼容 API
[尖叫声] Jco的节点.js 组件的内置兼容性是实验性和主题 改为: API、行为和生成的组件接口可能改变 不相容,没有 铸币大释放.
上表列出了可用的适配器. 通常应用代码
保留它 node: 进口和让 jco componentize 选择执行.
见 节点.js 内置兼容性指南
用于设置、版本、能力和兼容性边界.
node:path
import path, { matchesGlob } from "node:path";
import { join as winJoin } from "node:path/win32";
export function outputPath(name) {
if (!matchesGlob(name, "**/*.js")) throw new TypeError("expected JavaScript");
return `${path.resolve("dist", name)}|${winJoin("C:\\dist", name)}`;
}
见 node:path。 。 。 .
node:string_decoder
import { Buffer } from "node:buffer";
import { StringDecoder } from "node:string_decoder";
const decoder = new StringDecoder("utf8");
decoder.write(Buffer.from([0xf0, 0x9f]));
decoder.end(Buffer.from([0x8c, 0x8d])); // "🌍"
见 node:string_decoder。 。 。 .
node:repl
import repl from "node:repl";
export function attach(input, output) {
const server = repl.start({ prompt: "app> ", input, output, useGlobal: true });
server.context.app = { version: "1.0.0" };
return server;
}
见 node:repl。 。 。 .
node:tty
import { ReadStream, WriteStream, isatty } from "node:tty";
export function terminal() {
if (!isatty(0) || !isatty(1)) throw new Error("a terminal is required");
return { input: new ReadStream(0), output: new WriteStream(1) };
}
见 node:tty。 。 。 .
node:wasi
import { WASI } from "node:wasi";
export function createWasi() {
return new WASI({ version: "preview1" });
}
见 node:wasi。 。 。 .
节点.js 错误全局
export function describeFailure() {
const cause = new TypeError("invalid input");
return new Error("operation failed", { cause }).cause.message;
}
见 节点.js 错误全局。 。 。 .
node:child_process
import { execFileSync } from "node:child_process";
export function nodeVersion() {
return execFileSync("node", ["--version"], { encoding: "utf8" }).trim();
}
见 node:child_process。 。 。 .
node:fs
import { readFileSync } from "node:fs";
import { writeFile } from "node:fs/promises";
export async function replace(path, contents) {
await writeFile(path, contents);
return readFileSync(path, "utf8");
}
见 node:fs。 。 。 .
node:os
import os from "node:os";
export function hostSummary() {
return `${os.platform()} ${os.arch()} (${os.availableParallelism()} CPUs)`;
}
见 node:os。 。 。 .
node:dns
import dns from "node:dns";
import dnsPromises from "node:dns/promises";
export function configuredServers() {
return [...dns.getServers(), ...dnsPromises.getServers()];
}
见 node:dns。 。 。 .
node:net
import { connect, createServer } from "node:net";
createServer((socket) => socket.end("hello")).listen(8080, "127.0.0.1");
connect(8080, "127.0.0.1").setEncoding("utf8").on("data", console.log);
见 node:net。 。 。 .
node:http 财务报告和审定财务报表 node:https
import { createServer } from "node:http";
import { get } from "node:https";
createServer((request, response) => {
response.end(`received ${request.method} ${request.url}`);
}).listen(8080, "127.0.0.1");
get("https://example.com/", (response) => response.resume());
见 node:http
财务报告和审定财务报表 node:https。 。 。 .
node:http2
import { connect } from "node:http2";
const session = connect("https://example.com");
const stream = session.request({ ":path": "/status" });
stream.on("end", () => session.close());
stream.end();
见 node:http2。 。 。 .
node:timers
import { setTimeout as delay, scheduler } from "node:timers/promises";
await delay(10, "ready");
await scheduler.yield();
见 node:timers。 。 。 .
许可证
这个项目根据Apache 2.0许可证获得许可,LLVM例外. 见 自由主义 更多细节.
捐款
除非您另有明确声明,否则有意提交的任何捐款 根据Apache-2.0许可证的定义, 应照此办理,不附加任何条件.