@agoric/eventual-send
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -6,2 +6,4 @@ 'use strict'; | ||
/* global globalThis window */ | ||
// eslint-disable-next-line spaced-comment | ||
/// <reference path="index.d.ts" /> | ||
// Shim globalThis when we don't have it. | ||
@@ -52,9 +54,2 @@ if (typeof globalThis === 'undefined') { | ||
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); | ||
@@ -64,37 +59,51 @@ return harden(new Proxy({}, handler)); | ||
let EChain; | ||
const makers = { | ||
G(x) { | ||
// Return getter. | ||
return new Proxy( | ||
{}, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
const EChain = x => { | ||
return harden({ | ||
get G() { | ||
// Return getter. | ||
return new Proxy( | ||
{ EChain: 'getter' }, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.get(x, prop)); | ||
}, | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.get(x, prop)); | ||
); | ||
}, | ||
get D() { | ||
// Return deleter. | ||
return new Proxy( | ||
{ EChain: 'deleter' }, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.delete(x, prop)); | ||
}, | ||
}, | ||
}, | ||
); | ||
}, | ||
D(x) { | ||
// Return deleter. | ||
return new Proxy( | ||
{}, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
); | ||
}, | ||
get S() { | ||
// Return setter. | ||
return new Proxy( | ||
{ EChain: 'setter' }, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return harden(value => | ||
EChain(HandledPromise.set(x, prop, value)), | ||
); | ||
}, | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.delete(x, prop)); | ||
}, | ||
}, | ||
); | ||
}, | ||
S(x) { | ||
// Return setter. | ||
return new Proxy( | ||
{}, | ||
{ | ||
); | ||
}, | ||
get M() { | ||
// Return method-caller. | ||
return new Proxy((..._args) => {}, { | ||
has(_target, _prop) { | ||
@@ -104,16 +113,2 @@ return true; | ||
get(_target, prop) { | ||
return harden(value => EChain(HandledPromise.set(x, prop, value))); | ||
}, | ||
}, | ||
); | ||
}, | ||
M(x) { | ||
// Return method-caller. | ||
return new Proxy( | ||
{}, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return harden((...args) => | ||
@@ -126,23 +121,9 @@ EChain(HandledPromise.applyMethod(x, prop, args)), | ||
}, | ||
}, | ||
); | ||
}, | ||
P(x) { | ||
// Return as promise. | ||
return Promise.resolve(x); | ||
}, | ||
}; | ||
EChain = x => { | ||
return new Proxy( | ||
{}, // empty shadow | ||
{ | ||
has(_target, prop) { | ||
return Object.keys(makers).indexOf(prop) >= 0; | ||
}, | ||
get(_target, prop) { | ||
return harden(makers[prop](x)); | ||
}, | ||
}); | ||
}, | ||
); | ||
get P() { | ||
// Return as promise. | ||
return Promise.resolve(x); | ||
}, | ||
}); | ||
}; | ||
@@ -555,5 +536,5 @@ | ||
exports.E = E; | ||
exports.HandledPromise = HandledPromise; | ||
exports.E = E; | ||
exports.makeHandledPromise = makeHandledPromise; | ||
exports.maybeExtendPromise = maybeExtendPromise; |
/* global globalThis window */ | ||
// eslint-disable-next-line spaced-comment | ||
/// <reference path="index.d.ts" /> | ||
// Shim globalThis when we don't have it. | ||
@@ -47,9 +49,2 @@ if (typeof globalThis === 'undefined') { | ||
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); | ||
@@ -59,37 +54,51 @@ return harden(new Proxy({}, handler)); | ||
let EChain; | ||
const makers = { | ||
G(x) { | ||
// Return getter. | ||
return new Proxy( | ||
{}, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
const EChain = x => { | ||
return harden({ | ||
get G() { | ||
// Return getter. | ||
return new Proxy( | ||
{ EChain: 'getter' }, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.get(x, prop)); | ||
}, | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.get(x, prop)); | ||
); | ||
}, | ||
get D() { | ||
// Return deleter. | ||
return new Proxy( | ||
{ EChain: 'deleter' }, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.delete(x, prop)); | ||
}, | ||
}, | ||
}, | ||
); | ||
}, | ||
D(x) { | ||
// Return deleter. | ||
return new Proxy( | ||
{}, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
); | ||
}, | ||
get S() { | ||
// Return setter. | ||
return new Proxy( | ||
{ EChain: 'setter' }, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return harden(value => | ||
EChain(HandledPromise.set(x, prop, value)), | ||
); | ||
}, | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.delete(x, prop)); | ||
}, | ||
}, | ||
); | ||
}, | ||
S(x) { | ||
// Return setter. | ||
return new Proxy( | ||
{}, | ||
{ | ||
); | ||
}, | ||
get M() { | ||
// Return method-caller. | ||
return new Proxy((..._args) => {}, { | ||
has(_target, _prop) { | ||
@@ -99,16 +108,2 @@ return true; | ||
get(_target, prop) { | ||
return harden(value => EChain(HandledPromise.set(x, prop, value))); | ||
}, | ||
}, | ||
); | ||
}, | ||
M(x) { | ||
// Return method-caller. | ||
return new Proxy( | ||
{}, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return harden((...args) => | ||
@@ -121,23 +116,9 @@ EChain(HandledPromise.applyMethod(x, prop, args)), | ||
}, | ||
}, | ||
); | ||
}, | ||
P(x) { | ||
// Return as promise. | ||
return Promise.resolve(x); | ||
}, | ||
}; | ||
EChain = x => { | ||
return new Proxy( | ||
{}, // empty shadow | ||
{ | ||
has(_target, prop) { | ||
return Object.keys(makers).indexOf(prop) >= 0; | ||
}, | ||
get(_target, prop) { | ||
return harden(makers[prop](x)); | ||
}, | ||
}); | ||
}, | ||
); | ||
get P() { | ||
// Return as promise. | ||
return Promise.resolve(x); | ||
}, | ||
}); | ||
}; | ||
@@ -550,2 +531,2 @@ | ||
export { HandledPromise, E, makeHandledPromise, maybeExtendPromise }; | ||
export { E, HandledPromise, makeHandledPromise, maybeExtendPromise }; |
@@ -8,2 +8,4 @@ (function (global, factory) { | ||
/* global globalThis window */ | ||
// eslint-disable-next-line spaced-comment | ||
/// <reference path="index.d.ts" /> | ||
// Shim globalThis when we don't have it. | ||
@@ -54,9 +56,2 @@ if (typeof globalThis === 'undefined') { | ||
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); | ||
@@ -66,37 +61,51 @@ return harden(new Proxy({}, handler)); | ||
let EChain; | ||
const makers = { | ||
G(x) { | ||
// Return getter. | ||
return new Proxy( | ||
{}, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
const EChain = x => { | ||
return harden({ | ||
get G() { | ||
// Return getter. | ||
return new Proxy( | ||
{ EChain: 'getter' }, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.get(x, prop)); | ||
}, | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.get(x, prop)); | ||
); | ||
}, | ||
get D() { | ||
// Return deleter. | ||
return new Proxy( | ||
{ EChain: 'deleter' }, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.delete(x, prop)); | ||
}, | ||
}, | ||
}, | ||
); | ||
}, | ||
D(x) { | ||
// Return deleter. | ||
return new Proxy( | ||
{}, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
); | ||
}, | ||
get S() { | ||
// Return setter. | ||
return new Proxy( | ||
{ EChain: 'setter' }, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return harden(value => | ||
EChain(HandledPromise.set(x, prop, value)), | ||
); | ||
}, | ||
}, | ||
get(_target, prop) { | ||
return EChain(HandledPromise.delete(x, prop)); | ||
}, | ||
}, | ||
); | ||
}, | ||
S(x) { | ||
// Return setter. | ||
return new Proxy( | ||
{}, | ||
{ | ||
); | ||
}, | ||
get M() { | ||
// Return method-caller. | ||
return new Proxy((..._args) => {}, { | ||
has(_target, _prop) { | ||
@@ -106,16 +115,2 @@ return true; | ||
get(_target, prop) { | ||
return harden(value => EChain(HandledPromise.set(x, prop, value))); | ||
}, | ||
}, | ||
); | ||
}, | ||
M(x) { | ||
// Return method-caller. | ||
return new Proxy( | ||
{}, | ||
{ | ||
has(_target, _prop) { | ||
return true; | ||
}, | ||
get(_target, prop) { | ||
return harden((...args) => | ||
@@ -128,23 +123,9 @@ EChain(HandledPromise.applyMethod(x, prop, args)), | ||
}, | ||
}, | ||
); | ||
}, | ||
P(x) { | ||
// Return as promise. | ||
return Promise.resolve(x); | ||
}, | ||
}; | ||
EChain = x => { | ||
return new Proxy( | ||
{}, // empty shadow | ||
{ | ||
has(_target, prop) { | ||
return Object.keys(makers).indexOf(prop) >= 0; | ||
}, | ||
get(_target, prop) { | ||
return harden(makers[prop](x)); | ||
}, | ||
}); | ||
}, | ||
); | ||
get P() { | ||
// Return as promise. | ||
return Promise.resolve(x); | ||
}, | ||
}); | ||
}; | ||
@@ -557,4 +538,4 @@ | ||
exports.E = E; | ||
exports.HandledPromise = HandledPromise; | ||
exports.E = E; | ||
exports.makeHandledPromise = makeHandledPromise; | ||
@@ -561,0 +542,0 @@ exports.maybeExtendPromise = maybeExtendPromise; |
{ | ||
"name": "@agoric/eventual-send", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Extend a Promise class to implement the eventual-send API", | ||
@@ -5,0 +5,0 @@ "main": "dist/eventual-send.cjs.js", |
// Type definitions for eventual-send | ||
// TODO: Add jsdocs. | ||
type Property = string | number | symbol; | ||
interface HandledPromiseConstructor { | ||
prototype: Promise<unknown>; | ||
applyFunction(target: unknown, args: unknown[]): Promise<unknown>; | ||
applyFunctionSendOnly(target: unknown, args: unknown[]): void; | ||
applyMethod(target: unknown, prop: Property, args: unknown[]): Promise<unknown>; | ||
applyMethodSendOnly(target: unknown, prop: Property, args: unknown[]): void; | ||
delete(target: unknown, prop: Property): Promise<boolean>; | ||
deleteSendOnly(target: unknown, prop: Property): void; | ||
get(target: unknown, prop: Property): Promise<unknown>; | ||
getSendOnly(target: unknown, prop: Property): void; | ||
has(target: unknown, prop: Property): Promise<boolean>; | ||
hasSendOnly(target: unknown, prop: Property): void; | ||
set<T = unknown>(target: unknown, prop: Property, value: T): Promise<T>; | ||
setSendOnly(target: unknown, prop: Property, value: unknown): void; | ||
} | ||
declare const HandledPromise: HandledPromiseConstructor; | ||
interface ESingleMethod<U> { | ||
[prop: Property]: (...args) => U; | ||
} | ||
interface EChain<T = unknown> { | ||
M: EChainMethod<EChain<T>>; | ||
G: EChainGet<EChain<T>>; | ||
S: EChainSet<EChain<T>>; | ||
D: EChainDelete<EChain<boolean>>; | ||
P: Promise<T>; | ||
sendOnly: EChainSendOnly; | ||
} | ||
interface EChainSendOnly { | ||
M: EChainMethod<void>; | ||
G: EChainGet<void>; | ||
S: EChainSet<void>; | ||
D: EChainDelete<void>; | ||
} | ||
interface EChainMethod<U> { | ||
(...args: unknown[]): U; | ||
[prop: Property]: (...args: unknown) => U; | ||
} | ||
interface EChainGet<U> { | ||
[prop: Property]: U; | ||
} | ||
interface EChainSet<U> { | ||
/** | ||
* Eventually set the prop property. | ||
*/ | ||
[prop: Property]: (value: unknown) => U; | ||
} | ||
interface EChainDelete<U> { | ||
/** | ||
* Eventually delete the prop property. | ||
*/ | ||
[prop: Property]: U is void ? U : EChain<boolean>; | ||
} | ||
interface EProxy { | ||
/** | ||
* 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. | ||
* | ||
* @param {*} x target for method call | ||
* @returns {ESingleMethod} method call proxy | ||
*/ | ||
(x: unknown): ESingleMethod<Promise<unknown>>; | ||
sendOnly: (x: unknown) => ESingleMethod<void>; | ||
/** | ||
* E.C(x) returns a chain where operations are selected by | ||
* uppercase single-letter selectors. | ||
* | ||
* @param {*} x target for first operation | ||
* @returns {EChain} | ||
*/ | ||
C(x: unknown): EChain; | ||
} | ||
export const E: EProxy; | ||
interface EHandler { | ||
GET(p: EPromise<unknown>, name: string | number | symbol): EPromise<unknown>; | ||
PUT(p: EPromise<unknown>, name: string | number | symbol, value: unknown): EPromise<void>; | ||
DELETE(p: EPromise<unknown>, name: string | number | symbol): EPromise<boolean>; | ||
POST(p: EPromise<unknown>, name?: string | number | symbol, args: unknown[]): EPromise<unknown>; | ||
GET(p: EPromise<unknown>, name: Property): EPromise<unknown>; | ||
PUT(p: EPromise<unknown>, name: Property, value: unknown): EPromise<void>; | ||
DELETE(p: EPromise<unknown>, name: Property): EPromise<boolean>; | ||
POST(p: EPromise<unknown>, name?: Property, args: unknown[]): EPromise<unknown>; | ||
} | ||
export interface EPromise<R> extends Promise<R> { | ||
get(name: string | number | symbol): EPromise<unknown>; | ||
put(name: string | number | symbol, value: unknown): EPromise<void>; | ||
delete(name: string | number | symbol): EPromise<boolean>; | ||
post(name?: string | number | symbol, args: unknown[]): EPromise<unknown>; | ||
invoke(name: string | number | symbol, ...args: unknown[]): EPromise<unknown>; | ||
get(name: Property): EPromise<unknown>; | ||
put(name: Property, value: unknown): EPromise<void>; | ||
delete(name: Property): EPromise<boolean>; | ||
post(name?: Property, args: unknown[]): EPromise<unknown>; | ||
invoke(name: Property, ...args: unknown[]): EPromise<unknown>; | ||
fapply(args: unknown[]): EPromise<unknown>; | ||
@@ -18,0 +105,0 @@ fcall(...args: unknown[]): EPromise<unknown>; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68750
1567