@endo/pass-style

中文文档
2.0.1发布于 2026/08/18Apache-2.0TypeScriptES Module近 30 天下载 4万

Defines the taxonomy of Passable objects.

原始使用文档
文档目录14 节
  1. Overview
  2. Pass Styles
  3. Core Functions
  4. passStyleOf(value)
  5. isPassable(value)
  6. Far(iface, methods)
  7. makeTagged(tag, payload)
  8. Passable Values
  9. Pass-by-Copy vs Pass-by-Presence
  10. Pass-by-Copy
  11. Pass-by-reference
  12. Type Guards
  13. Integration with Endo Packages
  14. Deep Dives

@endo/pass-style

Defines what data can be passed between vats in an object-capability system.

Overview

The @endo/pass-style package defines the Passable type and provides the passStyleOf() function for classifying JavaScript values according to their PassStyle. This classification determines how values can safely be passed between isolated compartments or across network boundaries.

Every passable value has exactly one pass style from a fixed set of possibilities. The key distinction is between pass-by-copy (the value itself is copied) and Pass-by-reference.

Pass Styles

Pass StyleCategoryDescriptionExamples
'null'PrimitiveThe null valuenull
'undefined'PrimitiveThe undefined valueundefined
'boolean'PrimitiveBoolean primitivestrue, false
'number'PrimitiveIEEE 754 floats42, 3.14, NaN, Infinity
'bigint'PrimitiveArbitrary-precision integers123n, -456n
'string'PrimitiveWell-formed strings'hello', ''
'symbol'PrimitiveRegistered/well-known symbolsSymbol.iterator
'copyArray'Pass-by-copyFrozen arrays of passablesharden([1, 2, 3])
'copyRecord'Pass-by-copyFrozen plain objectsharden({ x: 10 })
'remotable'Pass-by-presenceFar objects & remote presencesFar('Counter', {...})
'tagged'ExtensionDomain-specific typesmakeTagged('copySet', [...])
'error'Pass-by-presenceError objectsharden(Error('failed'))
'promise'Pass-by-presencePromise objectsPromise.resolve(42)

Core Functions

passStyleOf(value)

Classifies a value's pass style. Throws if the value is not passable.

import { passStyleOf } from '@endo/pass-style';

passStyleOf(42);                    // 'number'
passStyleOf(harden([1, 2]));        // 'copyArray'
passStyleOf(harden({ x: 1 }));      // 'copyRecord'
passStyleOf(Promise.resolve());     // 'promise'

// Throws for non-passable values
passStyleOf({ x: 1 });  // Error: not frozen

isPassable(value)

Boolean test for passability. Returns true if the value is passable, false otherwise.

import { isPassable } from '@endo/pass-style';

isPassable(42);                // true
isPassable(harden([1, 2]));    // true
isPassable({ x: 1 });          // false - not frozen
isPassable(harden({ x: 1 }));  // true

Use isPassable() when you want a boolean result. Use passStyleOf() when you need the specific pass style or want detailed error messages.

Far(iface, methods)

Creates a remotable object that can be passed by reference.

import { Far } from '@endo/pass-style';

const counter = Far('Counter', {
  increment() { return count += 1; },
  getValue() { return count; }
});

passStyleOf(counter);  // 'remotable'

Note: Far objects are remotable but don't validate their inputs. For defensive objects with automatic input validation, see @endo/exo.

makeTagged(tag, payload)

Creates a CopyTagged object, the extension point for domain-specific data types.

import { makeTagged } from '@endo/pass-style';

const tagged = makeTagged('customType', { data: 42 });
passStyleOf(tagged);  // 'tagged'

Tagged objects are used internally by @endo/patterns to implement CopySet, CopyBag, and CopyMap.

Passable Values

A value is passable if it meets these requirements:

  1. Primitives are always passable (except unregistered symbols)
  2. Objects must be frozen via harden() from @endo/pass-style or ses
  3. No cyclic references in pass-by-copy structures (copyArray, copyRecord, tagged)
  4. Strings must be well-formed (no unpaired surrogates)
  5. Symbols must tentatively be created using passableSymbolForName() from @endo/pass-style.
// Passable - frozen array of primitives
const data = harden([1, 2, 3]);

// NOT passable - not frozen
const mutable = [1, 2, 3];

// NOT passable - cyclic reference
const cyclic = harden([]);
cyclic.push(cyclic);

Pass-by-Copy vs Pass-by-Presence

Pass-by-Copy

The value itself is copied when passed. Changes to the original don't affect copies.

Use for: Immutable data, configurations, messages, small structures

Pass styles: primitives, copyArray, copyRecord, tagged

const config = harden({
  timeout: 5000,
  retries: 3
});

// When passed, config is copied
// The recipient gets a separate copy

Pass-by-reference

A reference is passed. The object remains in its original location.

Use for: Objects with behavior, mutable state, capabilities, large objects

Pass styles: remotable, promise, error

const service = Far('Service', {
  getData() { return data; }
});

// When passed, only a reference is passed
// Method calls are forwarded to the original object

Type Guards

The package provides type guards for common pass styles:

import {
  isRecord, assertRecord,
  isCopyArray, assertCopyArray,
  isRemotable, assertRemotable,
  isAtom, assertAtom
} from '@endo/pass-style';

// Boolean checks
if (isRecord(value)) {
  // value is a CopyRecord
}

// Assertions (throw if false)
assertRemotable(obj);
// obj is guaranteed to be a remotable

Integration with Endo Packages

Complete Tutorial: See Message Passing for a comprehensive guide showing how pass-style works with patterns, exo, and eventual-send.

Deep Dives

For implementation details:

版本与发布记录

@endo/pass-style 共发布 32 个版本,首次发布于 2023/03/08;过去 12 个月发布了 5 个版本。

版本发布日期距今
2.0.1latest2026/08/182 个月前
1.8.2latest-v12026/08/142 个月前
1.8.12026/06/125 个月前
1.8.02026/04/176 个月前
1.7.02026/02/278 个月前
1.6.32025/07/121.3 年前

关于 @endo/pass-style 的常见问题

@endo/pass-style 是什么?

Defines the taxonomy of Passable objects.

如何安装 @endo/pass-style?

在项目目录运行 npm install @endo/pass-style,或使用 pnpm add / yarn add / bun add。

@endo/pass-style 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@endo/pass-style 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@endo/pass-style 可以商用吗?

@endo/pass-style 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@endo/pass-style 的下载量有多少?

根据 npm 官方下载统计,@endo/pass-style 在 2026/10/14 – 2026/11/12 这 30 天内被下载 40,439 次,日均约 1,348 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@endo/pass-style 还在维护吗?

最新版本 2.0.1 发布于 2026/08/18(2 个月前);至今共发布 32 个版本,其中过去 12 个月发布了 5 个;首次发布于 2023/03/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。