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

@dappworks/urpc

Package Overview
Dependencies
Maintainers
4
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dappworks/urpc - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

93

dist/index.d.ts

@@ -10,12 +10,13 @@ // Generated by dts-bundle-generator v9.5.1

}
export interface URPC_Variable<R> {
export interface URPC_Variable<T extends () => any = () => any, R = any> {
type?: "var";
get: R;
get: T;
set?: R extends () => infer U ? (value: ReturnType<T>) => U : never;
}
export type URPC_Schema = {
[key: string]: URPC_Function<any, any> | URPC_Variable<any>;
[key: string]: URPC_Function<any, any> | URPC_Variable<any, any>;
};
export declare class URPC<T extends URPC_Schema> {
export declare class URPC<T extends URPC_Schema = any> {
schemas: T;
static Var<R = any>(args: URPC_Variable<R>): URPC_Variable<R>;
static Var<T extends () => any, R = any>(args: URPC_Variable<T, R>): URPC_Variable<T, R>;
static Func<T extends Object = {}, R = any>(args: URPC_Function<T, R>): URPC_Function<T, R>;

@@ -33,9 +34,89 @@ constructor(args?: Partial<URPC<T>>);

input?: undefined;
} | undefined)[];
} | {
type: string;
name: string;
input?: undefined;
value?: undefined;
})[];
loadVars(): {
name: string;
value: any;
get: any;
set: ((value: any) => unknown) | undefined;
}[];
}
export declare const createSimpleHttpClient: <T extends URPC_Schema>(args: {
url: string;
}) => {
schema: {
loadFull(): Promise<ReturnType<URPC<T>["loadFull"]>>;
loadVars(): Promise<ReturnType<URPC<T>["loadVars"]>>;
};
func: {
call<R extends keyof T>(params: {
method: R;
input: T[R] extends URPC_Function<infer Z extends Object, any> ? Z : never;
}): Promise<T[R] extends URPC_Function<any, infer Z_1> ? Z_1 : never>;
};
var: {
overwrite(params: {
name: string;
value: any;
}): Promise<any>;
patch(params: {
name: string;
value: any;
}): Promise<any>;
};
};
export declare const createServerClient: <T extends URPC_Schema>({ urpc }: {
urpc: URPC<T>;
}) => {
urpc: URPC<T>;
handle({ name, params }: {
name: string;
params: Record<string, any>;
}): any;
schema: {
loadFull(): Promise<({
type: "func";
name: string;
input: any;
value?: undefined;
} | {
type: "var";
name: string;
value: any;
input?: undefined;
} | {
type: string;
name: string;
input?: undefined;
value?: undefined;
})[]>;
loadVars(): Promise<{
name: string;
value: any;
get: any;
set: ((value: any) => unknown) | undefined;
}[]>;
};
func: {
call(params: {
method: string;
input: Record<string, any>;
}): Promise<any>;
};
var: {
overwrite(params: {
name: string;
value: any;
}): Promise<unknown>;
patch(params: {
name: string;
value: any;
}): Promise<never>;
};
};
export {};

2

dist/index.js

@@ -1,1 +0,1 @@

class P{schemas;static Var(o){return{...o,type:"var"}}static Func(o){return{...o,type:"func"}}constructor(o={}){Object.assign(this,o)}loadFull(){return Object.entries(this.schemas).map(([o,c])=>{if(c.type=="func"){const{type:l,input:m}=c;return{type:l,name:o,input:m}}if(c.type=="var"){const{type:l,get:m}=c;return{type:l,name:o,value:m()}}})}loadVars(){return Object.entries(this.schemas).filter(([o,c])=>c.type=="var").map(([o,c])=>{const{get:l}=c;return{name:o,value:l()}})}}export{P as URPC};
var d=Object.create;var{defineProperty:K,getPrototypeOf:b,getOwnPropertyNames:m}=Object;var g=Object.prototype.hasOwnProperty;var h=(B,Q,W)=>{W=B!=null?d(b(B)):{};const Z=Q||!B||!B.__esModule?K(W,"default",{value:B,enumerable:!0}):W;for(let $ of m(B))if(!g.call(Z,$))K(Z,$,{get:()=>B[$],enumerable:!0});return Z};var k=(B,Q)=>()=>(Q||B((Q={exports:{}}).exports,Q),Q.exports);var j=k((k0,S)=>{var B0=function(B,Q){return B==null?void 0:B[Q]},Q0=function(B){var Q=!1;if(B!=null&&typeof B.toString!="function")try{Q=!!(B+"")}catch(W){}return Q},U=function(B){var Q=-1,W=B?B.length:0;this.clear();while(++Q<W){var Z=B[Q];this.set(Z[0],Z[1])}},Y0=function(){this.__data__=w?w(null):{}},_0=function(B){return this.has(B)&&delete this.__data__[B]},w0=function(B){var Q=this.__data__;if(w){var W=Q[B];return W===N?void 0:W}return A.call(Q,B)?Q[B]:void 0},V0=function(B){var Q=this.__data__;return w?Q[B]!==void 0:A.call(Q,B)},q0=function(B,Q){var W=this.__data__;return W[B]=w&&Q===void 0?N:Q,this},Y=function(B){var Q=-1,W=B?B.length:0;this.clear();while(++Q<W){var Z=B[Q];this.set(Z[0],Z[1])}},J0=function(){this.__data__=[]},R0=function(B){var Q=this.__data__,W=V(Q,B);if(W<0)return!1;var Z=Q.length-1;if(W==Z)Q.pop();else U0.call(Q,W,1);return!0},A0=function(B){var Q=this.__data__,W=V(Q,B);return W<0?void 0:Q[W][1]},G0=function(B){return V(this.__data__,B)>-1},z0=function(B,Q){var W=this.__data__,Z=V(W,B);if(Z<0)W.push([B,Q]);else W[Z][1]=Q;return this},X=function(B){var Q=-1,W=B?B.length:0;this.clear();while(++Q<W){var Z=B[Q];this.set(Z[0],Z[1])}},F0=function(){this.__data__={hash:new U,map:new(X0||Y),string:new U}},K0=function(B){return q(this,B).delete(B)},E0=function(B){return q(this,B).get(B)},L0=function(B){return q(this,B).has(B)},O0=function(B,Q){return q(this,B).set(B,Q),this},V=function(B,Q){var W=B.length;while(W--)if(j0(B[W][0],Q))return W;return-1},T0=function(B,Q){Q=H0(Q,B)?[Q]:P0(Q);var W=0,Z=Q.length;while(B!=null&&W<Z)B=B[x0(Q[W++])];return W&&W==Z?B:void 0},N0=function(B){if(!x(B)||D0(B))return!1;var Q=C0(B)||Q0(B)?$0:t;return Q.test(S0(B))},M0=function(B){if(typeof B=="string")return B;if(z(B))return T?T.call(B):"";var Q=B+"";return Q=="0"&&1/B==-M?"-0":Q},P0=function(B){return f(B)?B:f0(B)},q=function(B,Q){var W=B.__data__;return I0(Q)?W[typeof Q=="string"?"string":"hash"]:W.map},D=function(B,Q){var W=B0(B,Q);return N0(W)?W:void 0},H0=function(B,Q){if(f(B))return!1;var W=typeof B;if(W=="number"||W=="symbol"||W=="boolean"||B==null||z(B))return!0;return v.test(B)||!y.test(B)||Q!=null&&B in Object(Q)},I0=function(B){var Q=typeof B;return Q=="string"||Q=="number"||Q=="symbol"||Q=="boolean"?B!=="__proto__":B===null},D0=function(B){return!!E&&E in B},x0=function(B){if(typeof B=="string"||z(B))return B;var Q=B+"";return Q=="0"&&1/B==-M?"-0":Q},S0=function(B){if(B!=null){try{return H.call(B)}catch(Q){}try{return B+""}catch(Q){}}return""},G=function(B,Q){if(typeof B!="function"||Q&&typeof Q!="function")throw new TypeError(n);var W=function(){var Z=arguments,$=Q?Q.apply(this,Z):Z[0],_=W.cache;if(_.has($))return _.get($);var F=B.apply(this,Z);return W.cache=_.set($,F),F};return W.cache=new(G.Cache||X),W},j0=function(B,Q){return B===Q||B!==B&&Q!==Q},C0=function(B){var Q=x(B)?I.call(B):"";return Q==i||Q==o},x=function(B){var Q=typeof B;return!!B&&(Q=="object"||Q=="function")},d0=function(B){return!!B&&typeof B=="object"},z=function(B){return typeof B=="symbol"||d0(B)&&I.call(B)==c},b0=function(B){return B==null?"":M0(B)},m0=function(B,Q,W){var Z=B==null?void 0:T0(B,Q);return Z===void 0?W:Z},n="Expected a function",N="__lodash_hash_undefined__",M=Infinity,i="[object Function]",o="[object GeneratorFunction]",c="[object Symbol]",y=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,v=/^\w*$/,s=/^\./,u=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,l=/[\\^$.*+?()[\]{}|]/g,r=/\\(\\)?/g,t=/^\[object .+?Constructor\]$/,a=typeof global=="object"&&global&&global.Object===Object&&global,e=typeof self=="object"&&self&&self.Object===Object&&self,R=a||e||Function("return this")(),W0=Array.prototype,Z0=Function.prototype,P=Object.prototype,J=R["__core-js_shared__"],E=function(){var B=/[^.]+$/.exec(J&&J.keys&&J.keys.IE_PROTO||"");return B?"Symbol(src)_1."+B:""}(),H=Z0.toString,A=P.hasOwnProperty,I=P.toString,$0=RegExp("^"+H.call(A).replace(l,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),L=R.Symbol,U0=W0.splice,X0=D(R,"Map"),w=D(Object,"create"),O=L?L.prototype:void 0,T=O?O.toString:void 0;U.prototype.clear=Y0;U.prototype.delete=_0;U.prototype.get=w0;U.prototype.has=V0;U.prototype.set=q0;Y.prototype.clear=J0;Y.prototype.delete=R0;Y.prototype.get=A0;Y.prototype.has=G0;Y.prototype.set=z0;X.prototype.clear=F0;X.prototype.delete=K0;X.prototype.get=E0;X.prototype.has=L0;X.prototype.set=O0;var f0=G(function(B){B=b0(B);var Q=[];if(s.test(B))Q.push("");return B.replace(u,function(W,Z,$,_){Q.push($?_.replace(r,"$1"):Z||W)}),Q});G.Cache=X;var f=Array.isArray;S.exports=m0});class p{schemas;static Var(B){return{...B,type:"var"}}static Func(B){return{...B,type:"func"}}constructor(B={}){Object.assign(this,B)}loadFull(){return Object.entries(this.schemas).map(([B,Q])=>{if(Q.type=="func"){const{type:W,input:Z}=Q;return{type:W,name:B,input:Z}}if(Q.type=="var"){const{type:W,get:Z}=Q;return{type:W,name:B,value:Z()}}return{type:"unknown",name:B}})}loadVars(){return Object.entries(this.schemas).filter(([B,Q])=>Q.type=="var").map(([B,Q])=>{const{get:W,set:Z}=Q;return{name:B,value:W(),get:W,set:Z}})}}var C=h(j(),1),p0=(B)=>{return{schema:{async loadFull(){return fetch(`${B.url}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"schema.loadFull"})}).then((Q)=>Q.json())},async loadVars(){return fetch(`${B.url}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"schema.loadVars"})}).then((Q)=>Q.json())}},func:{async call(Q){return fetch(`${B.url}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"func.call",params:Q})}).then((W)=>W.json())}},var:{async overwrite(Q){return fetch(`${B.url}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"var.overwrite",params:Q})}).then((W)=>W.json())},async patch(Q){return fetch(`${B.url}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"var.patch",params:Q})}).then((W)=>W.json())}}}},n0=({urpc:B})=>{const Q={urpc:B,handle({name:W,params:Z}){const $=C.default(Q,W);if(console.log(W,Z),!$)throw new Error("invalid name");return $(Z)},schema:{async loadFull(){return B.loadFull()},async loadVars(){return B.loadVars()}},func:{async call(W){const Z=B.schemas[W.method];if(!Z)throw new Error("invalid func name");return Z.func({input:W.input})}},var:{async overwrite(W){const Z=B.schemas[W.name];if(!Z)throw new Error("invalid var name");if(!Z.set)throw new Error("variable can't be set");return Z.set({value:W.value})},async patch(W){throw new Error("TBD")}}};return Q};export{p0 as createSimpleHttpClient,n0 as createServerClient,p as URPC};
{
"name": "@dappworks/urpc",
"version": "0.0.1",
"version": "0.0.2",
"module": "index.ts",

@@ -17,3 +17,5 @@ "main": "dist/index.js",

"@types/bun": "latest",
"bun-plugin-dts": "^0.2.3"
"@types/lodash.get": "^4.4.9",
"bun-plugin-dts": "^0.2.3",
"hono": "^4.2.6"
},

@@ -33,3 +35,6 @@ "peerDependencies": {

"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"lodash.get": "^4.4.2"
}
}

@@ -6,5 +6,36 @@ # urpc

```bash
bun install
bun add @dappworks/urpc
```
```ts
import URPC from "@dappworks/urpc";
const urpc = new URPC({
schemas: {
sum: URPC.Func({
input: { a: 0, b: 0 },
func: ({ input }) => input.a + input.b,
}),
foo: URPC.Var({ get: () => data.foo }),
},
});
const serverClient = createServerClient({ urpc });
const app = new Hono();
app.post("/urpc", async (c) => {
const body = (await c.req.json()) as any;
const res = await serverClient.handle(body);
return c.json(res);
});
// client
const client = createSimpleHttpClient<typeof urpc.schemas>({
url: "http://localhost:3000/urpc",
});
client.func.call();
client.var.overwrite();
client.schema.loadFull();
client.schema.loadVars();
```
To run:

@@ -11,0 +42,0 @@

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