Comparing version 0.0.1 to 0.0.2
export interface IRejection { | ||
e: number; | ||
m: unknown; | ||
s?: string; | ||
} | ||
@@ -5,0 +6,0 @@ export declare function encodeReject(reject: unknown): IRejection; |
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
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
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
31855
4
+ Added@chijs/util@0.0.4(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedatomic-sleep@1.0.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedfast-redact@3.5.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedon-exit-leak-free@2.1.2(transitive)
+ Addedpino@8.21.0(transitive)
+ Addedpino-abstract-transport@1.2.0(transitive)
+ Addedpino-std-serializers@6.2.2(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedprocess-warning@3.0.0(transitive)
+ Addedquick-format-unescaped@4.0.4(transitive)
+ Addedreadable-stream@4.5.2(transitive)
+ Addedreal-require@0.2.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafe-stable-stringify@2.5.0(transitive)
+ Addedsonic-boom@3.8.1(transitive)
+ Addedsplit2@4.2.0(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedthread-stream@2.7.0(transitive)
- Removed@chijs/util@0.0.1(transitive)
Updated@chijs/util@^0.0.4