
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Given an group of paths (say, from an API schema), you might need to create a set of proxy objects for interacting with those paths. This is the situation I found myself in while working on the Node client for the Heroku API.
Given a set of paths and a base constructor function, path-proxy will create a network of logical proxy objects based on the paths and attach it to the constructor's prototype.
npm install path-proxy --save
var pathProxy = require('path-proxy');
function ApiClient() {}
pathProxy.proxy(ApiClient, [
"/foo",
"/foo/{id}/bar"
]);
var client = new ApiClient();
client.foo("qux").bar();
This may not appear all that useful—they're mostly just empty functions—until you start mucking around with their prototypes:
var BarProxy = pathProxy.pathProxy(ApiClient, "/foo/{id}/bar");
BarProxy.prototype.sayHello = function () {
console.log("hello");
};
client.foo("qux").bar().sayHello(); // Logs "hello".
They also have access to a few useful attributes:
var baz = client.foo("qux").bar("baz");
baz.params; // ["qux", "baz"]
baz.pathSegments; // ["foo", "qux", "bar", "baz"]
baz.path; // "/foo/qux/bar/baz"
And can access the instance of the base constructor they're based off of:
ApiClient.prototype.delete = function (path, callback) {
var message = this.name + " deleted at " + path;
callback(message);
};
var client = new ApiClient();
client.name = "Jonathan";
BarProxy.prototype.delete = function (callback) {
this.base.delete(this.path, callback);
};
// This:
client.foo("qux").bar("baz").delete(function (message) {
// message == "Jonathan deleted at /foo/qux/bar/baz"
});
// Is equivalent to this:
client.delete("/foo/qux/bar/baz", function (message) {
// message == "Jonathan deleted at /foo/qux/bar/baz"
});
That's all there is for now. This is might prove to be a useful tool for working on documented API clients in the future. For now, don't rely on it. There are no tests, and it's more of a fun experiment at the moment
FAQs
A path proxy object constructor
The npm package path-proxy receives a total of 113,650 weekly downloads. As such, path-proxy popularity was classified as popular.
We found that path-proxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.