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

@agoric/eventual-send

Package Overview
Dependencies
Maintainers
4
Versions
322
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agoric/eventual-send - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

103

dist/eventual-send.cjs.js

@@ -5,6 +5,97 @@ 'use strict';

// Create HandledPromise static methods as a bridge from v0.2.4 to
// new proposal support (wavy dot's infrastructure).
/* global globalThis window */
// Shim globalThis when we don't have it.
if (typeof globalThis === 'undefined') {
const myGlobal = typeof window === 'undefined' ? global : window;
myGlobal.globalThis = myGlobal;
}
const harden = (globalThis.SES && globalThis.SES.harden) || Object.freeze;
/**
* A Proxy handler for E(x).
*
* @param {*} x Any value passed to E(x)
* @returns {ProxyHandler} the Proxy handler
*/
function EProxyHandler(x, HandledPromise) {
return harden({
get(_target, p, _receiver) {
if (`${p}` !== p) {
return undefined;
}
// Harden this Promise because it's our only opportunity to ensure
// p1=E(x).foo() is hardened. The Handled Promise API does not (yet)
// allow the handler to synchronously influence the promise returned
// by the handled methods, so we must freeze it from the outside. See
// #95 for details.
return (...args) => harden(HandledPromise.applyMethod(x, p, args));
},
deleteProperty(_target, p) {
return harden(HandledPromise.delete(x, p));
},
set(_target, p, value, _receiver) {
return harden(HandledPromise.set(x, p, value));
},
apply(_target, _thisArg, argArray = []) {
return harden(HandledPromise.apply(x, argArray));
},
has(_target, _p) {
// We just pretend everything exists.
return true;
},
});
}
function makeE(HandledPromise) {
return harden(function E(x) {
// p = E(x).name(args)
//
// E(x) returns a proxy on which you can call arbitrary methods. Each of
// these method calls returns a promise. The method will be invoked on
// whatever 'x' designates (or resolves to) in a future turn, not this
// one.
const handler = EProxyHandler(x, HandledPromise);
return harden(new Proxy({}, handler));
});
}
/* global globalThis */
const harden$1 = (globalThis.SES && globalThis.SES.harden) || Object.freeze;
// 'E' and 'HandledPromise' are exports of the module
// For now:
// import { HandledPromise, E } from '@agoric/eventual-send';
// ...
// TODO: Maybe rename the global to something only the tildot rewriter uses.
if (!globalThis.HandledPromise) {
/* eslint-disable no-use-before-define */
// Install the shim as best we can.
maybeExtendPromise(Promise);
globalThis.HandledPromise = makeHandledPromise(Promise);
/* eslint-enable no-use-before-define */
}
// Provide a handled platform Promise if SES has not run.
const { HandledPromise } = globalThis;
const E = makeE(HandledPromise);
// the following methods (makeHandledPromise and maybeExtendPromise) are part
// of the shim, and will not be exported by the module once the feature
// becomes a part of standard javascript
// Create HandledPromise static methods as a bridge from v0.2.4
// to new proposal support (wavy dot's infrastructure).
function makeHandledPromise(EPromise) {
return {
// TODO: Use HandledPromise.resolve to store our weakmap, and
// install it on Promise.resolve.
// eslint-disable-next-line no-shadow
function HandledPromise(executor, _unfulfilledHandler = undefined) {
throw Error(`FIXME: unimplemented`);
}
const staticMethods = {
get(target, key) {

@@ -41,2 +132,4 @@ return EPromise.resolve(target).get(key);

};
return harden$1(Object.assign(HandledPromise, staticMethods));
}

@@ -307,3 +400,3 @@

// by the executor.
return handledP;
return harden$1(handledP);
},

@@ -344,3 +437,5 @@ }),

exports.E = E;
exports.HandledPromise = HandledPromise;
exports.makeHandledPromise = makeHandledPromise;
exports.maybeExtendPromise = maybeExtendPromise;

@@ -1,5 +0,96 @@

// Create HandledPromise static methods as a bridge from v0.2.4 to
// new proposal support (wavy dot's infrastructure).
/* global globalThis window */
// Shim globalThis when we don't have it.
if (typeof globalThis === 'undefined') {
const myGlobal = typeof window === 'undefined' ? global : window;
myGlobal.globalThis = myGlobal;
}
const harden = (globalThis.SES && globalThis.SES.harden) || Object.freeze;
/**
* A Proxy handler for E(x).
*
* @param {*} x Any value passed to E(x)
* @returns {ProxyHandler} the Proxy handler
*/
function EProxyHandler(x, HandledPromise) {
return harden({
get(_target, p, _receiver) {
if (`${p}` !== p) {
return undefined;
}
// Harden this Promise because it's our only opportunity to ensure
// p1=E(x).foo() is hardened. The Handled Promise API does not (yet)
// allow the handler to synchronously influence the promise returned
// by the handled methods, so we must freeze it from the outside. See
// #95 for details.
return (...args) => harden(HandledPromise.applyMethod(x, p, args));
},
deleteProperty(_target, p) {
return harden(HandledPromise.delete(x, p));
},
set(_target, p, value, _receiver) {
return harden(HandledPromise.set(x, p, value));
},
apply(_target, _thisArg, argArray = []) {
return harden(HandledPromise.apply(x, argArray));
},
has(_target, _p) {
// We just pretend everything exists.
return true;
},
});
}
function makeE(HandledPromise) {
return harden(function E(x) {
// p = E(x).name(args)
//
// E(x) returns a proxy on which you can call arbitrary methods. Each of
// these method calls returns a promise. The method will be invoked on
// whatever 'x' designates (or resolves to) in a future turn, not this
// one.
const handler = EProxyHandler(x, HandledPromise);
return harden(new Proxy({}, handler));
});
}
/* global globalThis */
const harden$1 = (globalThis.SES && globalThis.SES.harden) || Object.freeze;
// 'E' and 'HandledPromise' are exports of the module
// For now:
// import { HandledPromise, E } from '@agoric/eventual-send';
// ...
// TODO: Maybe rename the global to something only the tildot rewriter uses.
if (!globalThis.HandledPromise) {
/* eslint-disable no-use-before-define */
// Install the shim as best we can.
maybeExtendPromise(Promise);
globalThis.HandledPromise = makeHandledPromise(Promise);
/* eslint-enable no-use-before-define */
}
// Provide a handled platform Promise if SES has not run.
const { HandledPromise } = globalThis;
const E = makeE(HandledPromise);
// the following methods (makeHandledPromise and maybeExtendPromise) are part
// of the shim, and will not be exported by the module once the feature
// becomes a part of standard javascript
// Create HandledPromise static methods as a bridge from v0.2.4
// to new proposal support (wavy dot's infrastructure).
function makeHandledPromise(EPromise) {
return {
// TODO: Use HandledPromise.resolve to store our weakmap, and
// install it on Promise.resolve.
// eslint-disable-next-line no-shadow
function HandledPromise(executor, _unfulfilledHandler = undefined) {
throw Error(`FIXME: unimplemented`);
}
const staticMethods = {
get(target, key) {

@@ -36,2 +127,4 @@ return EPromise.resolve(target).get(key);

};
return harden$1(Object.assign(HandledPromise, staticMethods));
}

@@ -302,3 +395,3 @@

// by the executor.
return handledP;
return harden$1(handledP);
},

@@ -339,2 +432,2 @@ }),

export { makeHandledPromise, maybeExtendPromise };
export { E, HandledPromise, makeHandledPromise, maybeExtendPromise };

@@ -7,6 +7,97 @@ (function (global, factory) {

// Create HandledPromise static methods as a bridge from v0.2.4 to
// new proposal support (wavy dot's infrastructure).
/* global globalThis window */
// Shim globalThis when we don't have it.
if (typeof globalThis === 'undefined') {
const myGlobal = typeof window === 'undefined' ? global : window;
myGlobal.globalThis = myGlobal;
}
const harden = (globalThis.SES && globalThis.SES.harden) || Object.freeze;
/**
* A Proxy handler for E(x).
*
* @param {*} x Any value passed to E(x)
* @returns {ProxyHandler} the Proxy handler
*/
function EProxyHandler(x, HandledPromise) {
return harden({
get(_target, p, _receiver) {
if (`${p}` !== p) {
return undefined;
}
// Harden this Promise because it's our only opportunity to ensure
// p1=E(x).foo() is hardened. The Handled Promise API does not (yet)
// allow the handler to synchronously influence the promise returned
// by the handled methods, so we must freeze it from the outside. See
// #95 for details.
return (...args) => harden(HandledPromise.applyMethod(x, p, args));
},
deleteProperty(_target, p) {
return harden(HandledPromise.delete(x, p));
},
set(_target, p, value, _receiver) {
return harden(HandledPromise.set(x, p, value));
},
apply(_target, _thisArg, argArray = []) {
return harden(HandledPromise.apply(x, argArray));
},
has(_target, _p) {
// We just pretend everything exists.
return true;
},
});
}
function makeE(HandledPromise) {
return harden(function E(x) {
// p = E(x).name(args)
//
// E(x) returns a proxy on which you can call arbitrary methods. Each of
// these method calls returns a promise. The method will be invoked on
// whatever 'x' designates (or resolves to) in a future turn, not this
// one.
const handler = EProxyHandler(x, HandledPromise);
return harden(new Proxy({}, handler));
});
}
/* global globalThis */
const harden$1 = (globalThis.SES && globalThis.SES.harden) || Object.freeze;
// 'E' and 'HandledPromise' are exports of the module
// For now:
// import { HandledPromise, E } from '@agoric/eventual-send';
// ...
// TODO: Maybe rename the global to something only the tildot rewriter uses.
if (!globalThis.HandledPromise) {
/* eslint-disable no-use-before-define */
// Install the shim as best we can.
maybeExtendPromise(Promise);
globalThis.HandledPromise = makeHandledPromise(Promise);
/* eslint-enable no-use-before-define */
}
// Provide a handled platform Promise if SES has not run.
const { HandledPromise } = globalThis;
const E = makeE(HandledPromise);
// the following methods (makeHandledPromise and maybeExtendPromise) are part
// of the shim, and will not be exported by the module once the feature
// becomes a part of standard javascript
// Create HandledPromise static methods as a bridge from v0.2.4
// to new proposal support (wavy dot's infrastructure).
function makeHandledPromise(EPromise) {
return {
// TODO: Use HandledPromise.resolve to store our weakmap, and
// install it on Promise.resolve.
// eslint-disable-next-line no-shadow
function HandledPromise(executor, _unfulfilledHandler = undefined) {
throw Error(`FIXME: unimplemented`);
}
const staticMethods = {
get(target, key) {

@@ -43,2 +134,4 @@ return EPromise.resolve(target).get(key);

};
return harden$1(Object.assign(HandledPromise, staticMethods));
}

@@ -309,3 +402,3 @@

// by the executor.
return handledP;
return harden$1(handledP);
},

@@ -346,2 +439,4 @@ }),

exports.E = E;
exports.HandledPromise = HandledPromise;
exports.makeHandledPromise = makeHandledPromise;

@@ -348,0 +443,0 @@ exports.maybeExtendPromise = maybeExtendPromise;

13

package.json
{
"name": "@agoric/eventual-send",
"version": "0.3.0",
"version": "0.3.1",
"description": "Extend a Promise class to implement the eventual-send API",

@@ -10,3 +10,3 @@ "main": "dist/eventual-send.cjs.js",

"scripts": {
"test": "node -r esm test/test-all.js",
"test": "tape -r esm 'test/**/test*.js'",
"build": "rollup -c",

@@ -26,3 +26,5 @@ "lint-fix": "eslint --fix '**/*.{js,jsx}'",

"homepage": "https://github.com/Agoric/eventual-send#readme",
"dependencies": {},
"dependencies": {
"@agoric/harden": "^0.0.4"
},
"devDependencies": {

@@ -38,3 +40,2 @@ "eslint": "^5.3.0",

"prettier": "^1.16.4",
"promises-aplus-tests": "^2.1.2",
"rollup": "^1.2.2",

@@ -49,5 +50,3 @@ "tape": "^4.11.0",

"eventual send",
"infix bang",
"promises-aplus",
"promises"
"wavy dot"
],

@@ -54,0 +53,0 @@ "files": [

@@ -8,20 +8,10 @@ # MaybeExtendPromise

[![Promises/A+ 1.1 compliant][aplus-logo]][aplus-url] Promises/A+ 1.1 compliant
Extend the Promise class to implements the eventual-send API. This API is used by the ECMAScript eventual-send proposal.
Extend a Promise class to implements the eventual-send API. This API is used by the ECMAScript infix-bang proposal.
## How to use
> Note: If you're writing an application, you probably don't want to use this package directly. You'll want to use the eventual-send `!` operator (infix bang) provided in [SES](https://github.com/Agoric/SES) or other platforms.
> Note: If you're writing an application, you probably don't want to use this package directly. You'll want to use the eventual-send `~.` operator (tildot) provided in [SES](https://github.com/Agoric/SES) or other platforms.
The updated `EPromise` class can be used as described in `test/test.js`.
After importing `@agoric/eventual-send`, the updated `Promise` class can be used as described in `test/test.js`.
## Creating a custom EPromise Class
This package (`@agoric/eventual-send`) provides a `maybeExtendPromise()` which can be used to extend your own `Promise` class. When you call `maybeExtendPromise()`, you give it an underlying `Promise` constructor that is augmented with eventual-send methods.
You can extend any existing Promises/A+ implementation, including the ECMAScript 6 and later `Promise` implementation.
[aplus-url]: https://promisesaplus.com/
[aplus-logo]: https://promisesaplus.com/assets/logo-small.png
[circleci-svg]: https://circleci.com/gh/Agoric/eventual-send.svg?style=svg

@@ -28,0 +18,0 @@ [circleci-url]: https://circleci.com/gh/Agoric/eventual-send

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