
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
[![Maintenance Status][status-image]][status-url] [![NPM version][npm-image]][npm-url] [![Dependencies][deps-image]][deps-url] [![Build Status][build-image]][build-url]
This project allows defining and using a promise-based API between different browser frames or workers.
RPC calls are defined between a callee and one or several callers
The callee must first set
an API for consumption.
This makes the API available for any callers requesting for an API with that ID.
The API can be any object containing functions and/or namespaces, and namespaces can be functions as well.
e.g.:
const api = {
syncFunc(...args) {
return someComputation(...args)
},
asyncFunc(...args) {
return performSomeAjaxRequest(...args)
},
someNamespace: {
namespacedFunction(...args) {
doSomething(...args)
}
},
add(a, b) {
return a + b
}
};
api.add.one = a => 1 + a; //api.add is both a function and a namespace!
rpc.api.set(appId, api);
Let the callee expose a 'maxOdd' function that recives as arguments a getNumbers and a filterOdd functions, and as a result return the max number.
Please note that the callee expose it's API by calling pmrpc.api.set
const api = {
maxOdd(getNumbers, getOdd) {
return getNumbers()
.then(getOdd)
.then(odds => Math.max(...odds))
}
}
pmrpc.api.set('functions', api)
The caller code will look as follow:
pmrpc.api.request('functions', {target: iframe.contentWindow})
.then(api => {
const filterOdd = arr => arr.filter(x => x % 2)
const getNumbers = () => [1, 2, 3, 4, 5, 6]
api.maxOdd(getNumbers, filterOdd)
.then(result => {
//result is 5 try it!
})
})
The callee may remove an API, and stop listening for requests to it. This makes the API no longer available, and rejects any other requests for the API with an error message. e.g.:
rpc.api.unset(appId)
onApiCall
When setting an API, you can also pass an options parameter with an onApiCall
option.
This callback will be called whenever any API method is invoked from any caller, with the following object:
e.g.:
const api = {
syncFunc(...args) {
return someComputation(...args);
},
asyncFunc(...args) {
return performSomeAjaxRequest(args)
}
}
rpc.api.set(appId, api, {onApiCall: function (data) {
console.log(data); // {appId: 'someAppId', call: 'theMethodCalled', args:['argument1', 'argument2']}
}});
onApiSettled
When setting an API, you can also pass an options parameter with an onApiSettled
option.
This callback will be called whenever any API method is invoked from any caller after the api has settled, with the following object:
onApiCall
callbacke.g.:
const api = {
syncFunc(...args) {
return someComputation(...args);
},
asyncFunc(...args) {
return performSomeAjaxRequest(args)
}
}
rpc.api.set(appId, api, {
onApiCall:() => performance.now(),
onApiSettled: message => {
console.log(`Method: ${message.call} was executed in ${performance.now() - message.onApiCallResult} ms`)
}
});
When setting an API, you can specify workers that may consume requested API. Inside worker, you can request
const api = {
asyncFunc(...args) {
return performSomeAjaxRequest(args)
}
}
const worker = new Worker('dowork.js')
rpc.api.set('appId', api, {workers: [worker]});
Inside web worker:
rpc.api.request('appId')
.then(api => api.asyncFunc())
To use an API, the caller must request it from the callee. The API is then returned in a promise, and all API calls return promises.
e.g.:
import rpc from 'pm-rpc';
rpc.api.request(
appId,
{
target //The callee window, usually parent
}
)
.then(api => api.syncFunc(...someArgs))
.then(result => {
// Do something with the results
});
[3.2.7]
onApiSettled
callbackFAQs
[![Maintenance Status][status-image]][status-url] [![NPM version][npm-image]][npm-url] [![Dependencies][deps-image]][deps-url] [![Build Status][build-image]][build-url]
The npm package pm-rpc receives a total of 207 weekly downloads. As such, pm-rpc popularity was classified as not popular.
We found that pm-rpc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.