@agoric/captp
Advanced tools
Comparing version 0.1.2 to 1.0.0
@@ -6,5 +6,7 @@ // This logic was mostly lifted from @agoric/swingset-vat liveSlots.js | ||
import Nat from '@agoric/nat'; | ||
import { HandledPromise } from '@agoric/eventual-send'; | ||
import { HandledPromise, E } from '@agoric/eventual-send'; | ||
export default function makeCapTP(ourId, send, bootstrapObj = undefined) { | ||
export { E, HandledPromise, Nat, harden }; | ||
export function makeCapTP(ourId, send, bootstrapObj = undefined) { | ||
const { serialize, unserialize } = makeMarshal( | ||
@@ -71,2 +73,34 @@ // eslint-disable-next-line no-use-before-define | ||
function makeRemote(slot) { | ||
const handler = { | ||
POST(_o, prop, args) { | ||
// Support: o~.[prop](...args) remote method invocation | ||
// FIXME: Implement a HandledPromise here to support pipelining. | ||
const pr = {}; | ||
pr.p = new Promise((resolve, reject) => { | ||
pr.res = resolve; | ||
pr.rej = reject; | ||
}); | ||
lastQuestionID += 1; | ||
const questionID = lastQuestionID; | ||
questions.set(questionID, pr); | ||
send({ | ||
type: 'CTP_CALL', | ||
questionID, | ||
target: slot, | ||
method: serialize(harden([prop, args])), | ||
}); | ||
return harden(pr.p); | ||
}, | ||
}; | ||
const pr = {}; | ||
pr.p = Promise.makeHandled((res, rej, resolveWithPresence) => { | ||
pr.rej = rej; | ||
pr.resPres = () => resolveWithPresence(handler); | ||
pr.res = res; | ||
}, handler); | ||
return harden(pr); | ||
} | ||
function unserializeSlot(data, slots) { | ||
@@ -77,31 +111,3 @@ const slot = slots[Nat(data.index)]; | ||
// Make a new handled promise for the slot. | ||
const handler = { | ||
POST(_o, prop, args) { | ||
// Support: o~.[prop](...args) remote method invocation | ||
const pr = {}; | ||
pr.p = new Promise((resolve, reject) => { | ||
pr.res = resolve; | ||
pr.rej = reject; | ||
}); | ||
lastQuestionID += 1; | ||
const questionID = lastQuestionID; | ||
questions.set(questionID, pr); | ||
send({ | ||
type: 'CTP_CALL', | ||
questionID, | ||
target: slot, | ||
method: serialize(harden([prop, args])), | ||
}); | ||
return harden(pr.p); | ||
}, | ||
}; | ||
const pr = {}; | ||
pr.p = Promise.makeHandled((res, rej, resolveWithPresence) => { | ||
pr.rej = rej; | ||
pr.resPres = () => resolveWithPresence(handler); | ||
pr.res = res; | ||
}, handler); | ||
harden(pr); | ||
const pr = makeRemote(slot); | ||
if (slot[0] === 'o') { | ||
@@ -200,3 +206,15 @@ // A new presence | ||
}; | ||
return [handler, getBootstrap]; | ||
harden(handler); | ||
// Return a dispatch function. | ||
const dispatch = obj => { | ||
const fn = handler[obj.type]; | ||
if (fn) { | ||
fn(obj); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
return harden({ dispatch, getBootstrap }); | ||
} |
{ | ||
"name": "@agoric/captp", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "Capability Transfer Protocol for distributed objects", | ||
@@ -13,3 +13,5 @@ "keywords": [ | ||
"license": "Apache-2.0", | ||
"main": "lib/captp.js", | ||
"main": "dist/captp.cjs.js", | ||
"module": "dist/captp.esm.js", | ||
"browser": "dist/captp.umd.js", | ||
"directories": { | ||
@@ -20,3 +22,4 @@ "lib": "lib", | ||
"files": [ | ||
"lib" | ||
"lib", | ||
"dist" | ||
], | ||
@@ -28,2 +31,3 @@ "repository": { | ||
"scripts": { | ||
"build": "rollup -c", | ||
"test": "tape -r esm 'test/**/*.js'", | ||
@@ -52,3 +56,6 @@ "lint-fix": "eslint --fix '**/*.{js,jsx}'", | ||
"@agoric/nat": "^2.0.1", | ||
"esm": "^3.2.5" | ||
"esm": "^3.2.5", | ||
"rollup": "^1.24.0", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-node-resolve": "^5.2.0" | ||
}, | ||
@@ -55,0 +62,0 @@ "bugs": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
277349
7
7797
0
8
1
+ Addedrollup@^1.24.0
+ Added@types/estree@1.0.6(transitive)
+ Added@types/node@22.10.2(transitive)
+ Added@types/resolve@0.0.8(transitive)
+ Addedacorn@7.4.1(transitive)
+ Addedbuiltin-modules@3.3.0(transitive)
+ Addedestree-walker@0.6.1(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedis-module@1.0.0(transitive)
+ Addedis-reference@1.2.1(transitive)
+ Addedmagic-string@0.25.9(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedrollup@1.32.1(transitive)
+ Addedrollup-plugin-commonjs@10.1.0(transitive)
+ Addedrollup-plugin-node-resolve@5.2.0(transitive)
+ Addedrollup-pluginutils@2.8.2(transitive)
+ Addedsourcemap-codec@1.4.8(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedundici-types@6.20.0(transitive)