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

@chijs/rpc

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chijs/rpc - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

1

lib/base.d.ts
export interface IRejection {
e: number;
m: unknown;
s?: string;
}

@@ -5,0 +6,0 @@ export declare function encodeReject(reject: unknown): IRejection;

6

lib/base.js
export function encodeReject(reject) {
if (reject instanceof Error) {
return { e: 1, m: reject.message };
return { e: 1, m: reject.message, s: reject.stack };
}

@@ -9,3 +9,5 @@ return { e: 0, m: reject };

if (reject.e) {
return new Error(reject.m);
const error = new Error(reject.m);
error.stack = reject.s;
return error;
}

@@ -12,0 +14,0 @@ return reject.m;

@@ -17,3 +17,3 @@ import { Fn, IRpcMsg, RpcId, SubscriptionId } from './base.js';

export declare type PublishCb<T, K extends PublishKeys<T>> = T extends RpcTypeDescriptor<infer _, infer B> ? B[K] extends Fn<infer _, infer R> ? (data: R, err?: unknown) => void : never : never;
export declare type RpcDescriptor = RpcTypeDescriptor<{}, {}>;
export declare type RpcBaseDescriptor = RpcTypeDescriptor<{}, {}>;
export interface IRpcEndpointInfo {

@@ -24,8 +24,8 @@ provides: string[];

export declare type InternalDescriptor = RpcTypeDescriptor<{
['$:ping'](): void;
['$:subscribe'](type: string, ...args: unknown[]): SubscriptionId;
['$:unsubscribe'](id: SubscriptionId): void;
['$:info'](): IRpcEndpointInfo;
['#:ping'](): void;
['#:subscribe'](type: string, ...args: unknown[]): SubscriptionId;
['#:unsubscribe'](id: SubscriptionId): void;
['#:info'](): IRpcEndpointInfo;
}, {}>;
export declare class RpcEndpoint<D extends RpcDescriptor> {
export declare class RpcEndpoint<D extends RpcBaseDescriptor> {
localId: RpcId;

@@ -36,3 +36,3 @@ send: (msg: IRpcMsg) => unknown;

constructor(localId: RpcId, send: (msg: IRpcMsg) => unknown, logger: Logger);
getHandle<D extends RpcDescriptor>(remoteId: RpcId): RpcHandle<D>;
getHandle<D extends RpcBaseDescriptor>(remoteId: RpcId): RpcHandle<D>;
recv(msg: IRpcMsg): void;

@@ -55,11 +55,11 @@ provide<K extends ProvideKeys<D>>(name: K, fn: WithThis<RpcHandle<D>, ProvideImpl<D, K>>): void;

}
export interface IRpcCallable<D extends RpcDescriptor> {
export interface IRpcCallable<D extends RpcBaseDescriptor> {
call<K extends ProvideKeys<D>>(name: K, ...args: ProvideArgs<D, K>): Promise<ProvideReturn<D, K>>;
}
export declare class RpcHandle<D extends RpcDescriptor> {
endpoint: RpcEndpoint<RpcDescriptor>;
export declare class RpcHandle<D extends RpcBaseDescriptor> {
endpoint: RpcEndpoint<RpcBaseDescriptor>;
remoteId: RpcId;
disposed: boolean;
constructor(endpoint: RpcEndpoint<RpcDescriptor>, remoteId: RpcId);
connect(): Promise<void>;
constructor(endpoint: RpcEndpoint<RpcBaseDescriptor>, remoteId: RpcId);
ping(): Promise<void>;
private handleDie;

@@ -73,3 +73,3 @@ private handleCallRequest;

dispose(reason: unknown): Promise<void>;
call<K extends ProvideKeys<D>>(name: K, ...args: ProvideArgs<D, K>): Promise<ProvideReturn<D, K>>;
call<K extends ProvideKeys<D>>(name: K, ...args: ProvideArgs<D, K>): Promise<Awaited<ProvideReturn<D, K>>>;
exec<K extends ProvideKeys<D>>(name: K, ...args: ProvideArgs<D, K>): Promise<void>;

@@ -76,0 +76,0 @@ subscribe<K extends PublishKeys<D>>(name: K, cb: PublishCb<D, K>, ...args: PublishArgs<D, K>): Promise<SubscriptionId>;

@@ -5,4 +5,4 @@ import { nanoid } from 'nanoid';

// eslint-disable-next-line @typescript-eslint/no-empty-function
endpoint.provide('$:ping', () => { });
endpoint.provide('$:subscribe', async function (type, ...args) {
endpoint.provide('#:ping', () => { });
endpoint.provide('#:subscribe', async function (type, ...args) {
const impl = this.endpoint.published(type);

@@ -21,3 +21,3 @@ const subscriptionId = nanoid();

});
endpoint.provide('$:unsubscribe', async function (id) {
endpoint.provide('#:unsubscribe', async function (id) {
const publication = this.publications.get(id);

@@ -29,3 +29,3 @@ if (publication) {

});
endpoint.provide('$:info', function () {
endpoint.provide('#:info', function () {
return {

@@ -113,4 +113,4 @@ provides: [...this.endpoint.provides.keys()],

}
async connect() {
await this.call('$:ping');
async ping() {
await this.call('#:ping');
}

@@ -262,3 +262,3 @@ handleDie(msg) {

async subscribe(name, cb, ...args) {
const subscription = await this.call('$:subscribe', name, ...args);
const subscription = await this.call('#:subscribe', name, ...args);
this.subscriptions.set(subscription, { cb });

@@ -269,3 +269,3 @@ return subscription;

if (this.subscriptions.delete(id)) {
await this.call('$:unsubscribe', id);
await this.call('#:unsubscribe', id);
}

@@ -272,0 +272,0 @@ }

@@ -5,6 +5,1 @@ export * from './base.js';

export * from './wrapper.js';
export declare const RPC: {
server: () => string;
worker: (workerId: string) => string;
client: (clientId: string) => string;
};

@@ -5,7 +5,2 @@ export * from './base.js';

export * from './wrapper.js';
export const RPC = {
server: () => 's',
worker: (workerId) => `w${workerId}`,
client: (clientId) => `c${clientId}`
};
//# sourceMappingURL=index.js.map

@@ -7,4 +7,5 @@ import { Logger } from 'pino';

send: (msg: IRpcMsg) => unknown;
meta?: unknown;
connections: Set<string>;
constructor(router: RpcRouter, id: RpcId, send: (msg: IRpcMsg) => unknown);
constructor(router: RpcRouter, id: RpcId, send: (msg: IRpcMsg) => unknown, meta?: unknown);
recv(msg: IRpcMsg): Promise<void>;

@@ -18,3 +19,4 @@ disconnect(remote: RpcId, reason: unknown): Promise<void>;

constructor(logger: Logger);
createAdapter(id: RpcId, send: (msg: IRpcMsg) => unknown): RpcAdapter;
create(id: RpcId, send: (msg: IRpcMsg) => unknown, meta?: unknown): RpcAdapter;
get(id: RpcId): RpcAdapter | undefined;
}

@@ -14,7 +14,9 @@ import { encodeReject, RpcMsgType } from './base.js';

send;
meta;
connections;
constructor(router, id, send) {
constructor(router, id, send, meta) {
this.router = router;
this.id = id;
this.send = send;
this.meta = meta;
this.connections = new Set();

@@ -65,10 +67,13 @@ }

}
createAdapter(id, send) {
create(id, send, meta) {
if (this.adapters.has(id))
throw new Error('Adapter already exists');
const adapter = new RpcAdapter(this, id, send);
const adapter = new RpcAdapter(this, id, send, meta);
this.adapters.set(id, adapter);
return adapter;
}
get(id) {
return this.adapters.get(id);
}
}
//# sourceMappingURL=router.js.map
import type { WithoutPrefix } from '@chijs/util';
import type { RpcDescriptor, RpcHandle } from './endpoint.js';
import type { RpcBaseDescriptor, RpcHandle } from './endpoint.js';
export declare type RpcWrapped<M, P extends string> = WithoutPrefix<M, P>;
declare type GetProvide<H> = H extends RpcHandle<infer D> ? D['provide'] : never;
export declare function createRpcWrapper<H extends RpcHandle<RpcDescriptor>, P extends string>(handle: H, prefix: P): WithoutPrefix<GetProvide<H>, P> & {
export declare function createRpcWrapper<H extends RpcHandle<RpcBaseDescriptor>, P extends string>(handle: H, prefix: P): WithoutPrefix<GetProvide<H>, P> & {
handle: H;
};
export {};

@@ -0,0 +0,0 @@ export function createRpcWrapper(handle, prefix) {

{
"name": "@chijs/rpc",
"version": "0.0.1",
"version": "0.0.2",
"main": "lib/index.js",
"license": "AGPL-3.0",
"description": "Core components of Chi framwork",
"description": "RPC implementation of Chi framwork",
"author": "thezzisu <thezzisu@gmail.com>",

@@ -19,3 +19,3 @@ "private": false,

"dependencies": {
"@chijs/util": "^0.0.1"
"@chijs/util": "^0.0.4"
},

@@ -22,0 +22,0 @@ "devDependencies": {},

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

# `@chijs/core`
# `@chijs/rpc`
> RPC implementation of Chi framwork

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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