Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@endo/patterns

Package Overview
Dependencies
Maintainers
5
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@endo/patterns

Description forthcoming.

  • 0.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.2K
decreased by-10.9%
Maintainers
5
Weekly downloads
 
Created
Source

@endo/patterns

Defines new Passable data types and their encoding into the Tagged objects defined by the @endo/pass-style package. The @endo/pass-style package defines the lower level of abstraction on which we need broad agreement for interoperability. The higher level data types defined by this package include

  • CopyMap, CopySet, CopyBag -- new container types, in addition to the CopyArray and CopyRecord already defined by @endo/pass-style.
  • a variety of Matchers, for expression patterns that can match over Passables
  • Key -- Passables that can be keys in CopyMaps, CopySets, CopyBags, as well as MapStores and SetStores.
  • Pattern -- values that match some subset of Passables. Includes Matchers along with literal pass-by-copy structures that match theirselves.

The main export from the package is an M namespace object, for making a variety of Matchers (hence "M").

M can also make Guards that use Patterns to characterize dynamic behavior such as method argument/response signatures and promise awaiting. The @endo/exo package uses InterfaceGuards (each of which maps a collection of method names to their respective method guards) as the first level of defense for Exo objects against malformed input. For example:

const asyncSerializerI = M.interface('AsyncSerializer', {
  // This interface has a single method, which is async as indicated by M.callWhen().
  // The method accepts a single argument, consumed with an implied `await` as indicated by M.await(),
  // and the result of that implied `await` is allowed to fulfill to any value per M.any().
  // The method result is a string as indicated by M.string(),
  // which is inherently wrapped in a promise by the async nature of the method.
  getStringOf: M.callWhen(M.await(M.any())).returns(M.string()),
});
const asyncSerializer = makeExo('AsyncSerializer', asyncSerializerI, {
  // M.callWhen() delays invocation of this method implementation
  // while provided argument is in a pending state
  // (i.e., it is a promise that has not yet settled).
  getStringOf(val) { return String(val); },
});

const stringP = asyncSerializer.getStringOf(Promise.resolve(42n));
isPromise(stringP); // => true
await stringP; // => "42"

See types.js for the definitions of these new types and (at typedefs PatternMatchers and GuardMakers) the methods of the exported M namespace object.

FAQs

Package last updated on 19 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc