lixnet 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,10 @@
1
1
  import type { FunctionInput, LXN_ServerClient_EventType } from "./types";
2
+ type ExtractRPCResponse<T> = T extends (...args: any) => infer R ? Awaited<R> : never;
2
3
  export default class LixnetClient<Events extends LXN_ServerClient_EventType> {
3
4
  private rpcUrl;
4
5
  constructor({ rpcUrl }: {
5
6
  rpcUrl: string;
6
7
  });
7
- call<K extends keyof Events>(event: K, input: FunctionInput<Events[K]>, options?: RequestInit): Promise<Awaited<ReturnType<Events[K]>>>;
8
+ call<K extends keyof Events>(event: K, input: FunctionInput<Events[K]>, options?: RequestInit): Promise<ExtractRPCResponse<Events[K]>>;
8
9
  }
10
+ export {};
@@ -1,10 +1,10 @@
1
1
  import { z } from "zod";
2
- import type { DebugLogger, FunctionInput, LXNServerHandler, LXN_ServerClient_EventType, LXN_ServerClient_Request } from "./types";
2
+ import type { DebugLogger, FunctionInput, FunctionOutput, LXNServerHandler, LXN_ServerClient_EventType, LXN_ServerClient_Request } from "./types";
3
3
  type LXNServerEventInput<Events extends LXN_ServerClient_EventType, TName extends keyof Events> = {
4
4
  event: TName;
5
5
  handler: LXNServerHandler<FunctionInput<Events[TName]> & {
6
6
  request: LXN_ServerClient_Request;
7
- }>;
7
+ }, FunctionOutput<Events[TName]>>;
8
8
  schema?: z.ZodSchema<any>;
9
9
  };
10
10
  export default class LixnetServer<Events extends LXN_ServerClient_EventType> {
@@ -2,9 +2,14 @@ export type DebugLogger = ({ error, message, }: {
2
2
  error?: boolean;
3
3
  message: string;
4
4
  }) => void;
5
- export type FunctionInput<T> = T extends (input: infer TInput) => any ? TInput : never;
6
- export type LXNServerHandler<Input> = (input: Input) => Promise<any> | any;
7
- export type LXN_ServerClient_EventType = Record<string, LXNServerHandler<any>>;
5
+ export type FunctionInput<T> = T extends (input: infer TInput) => any ? TInput : {
6
+ _TYPE_ERROR_: "Event definition must be a function type";
7
+ };
8
+ export type FunctionOutput<T> = T extends (...args: any) => infer R ? Awaited<R> : {
9
+ _TYPE_ERROR_: "Event definition must be a function type";
10
+ };
11
+ export type LXNServerHandler<Input, Output> = (input: Input) => Promise<Output> | Output;
12
+ export type LXN_ServerClient_EventType = object;
8
13
  export type LXN_ServerClient_Request = Request & {
9
14
  setAdditionalInit: (init: ResponseInit) => void;
10
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lixnet",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "author": "Nitlix",
5
5
  "license": "MIT",
6
6
  "repository": {