itty-sockets 0.8.0 → 0.8.1

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.
Files changed (2) hide show
  1. package/connect.d.ts +7 -4
  2. package/package.json +1 -1
package/connect.d.ts CHANGED
@@ -39,11 +39,12 @@ type EventUnion<Events> = {
39
39
  message: infer M;
40
40
  } ? M : never);
41
41
  type SendFn<Base, Events extends Record<string, any>> = keyof Events extends never ? <T = any>(message: T, ...args: Base extends IttyProtocol ? [uid?: string] : []) => IttySocket<Base, Events> : (message: EventUnion<Events>, ...args: Base extends IttyProtocol ? [uid?: string] : []) => IttySocket<Base, Events>;
42
+ type EmptyEvents = {};
42
43
  export interface IttySocketConnect {
43
- <Events extends Record<string, any> = Record<string, never>>(url: `ws://${string}` | `wss://${string}`, queryParams?: any): IttySocket<object, Events>;
44
- <Events extends Record<string, any> = Record<string, never>>(channelID: string, options?: IttySocketOptions): IttySocket<IttyProtocol, Events>;
44
+ <Events extends Record<string, any> = EmptyEvents>(url: `ws://${string}` | `wss://${string}`, queryParams?: any): IttySocket<object, Events>;
45
+ <Events extends Record<string, any> = EmptyEvents>(channelID: string, options?: IttySocketOptions): IttySocket<IttyProtocol, Events>;
45
46
  }
46
- export type IttySocket<Base = object, Events extends Record<string, any> = Record<string, never>> = {
47
+ export type IttySocket<Base = object, Events extends Record<string, any> = EmptyEvents> = {
47
48
  open: () => IttySocket<Base, Events>;
48
49
  close: () => IttySocket<Base, Events>;
49
50
  send: SendFn<Base, Events>;
@@ -55,7 +56,7 @@ export type IttySocket<Base = object, Events extends Record<string, any> = Recor
55
56
  type: K;
56
57
  message: Events[K];
57
58
  }) => any): IttySocket<Base, Events>;
58
- on<T = any>(type: 'message', listener: (event: Base & {
59
+ on<T = any>(type: 'message', listener: (event: Base & T & {
59
60
  message: T;
60
61
  }) => any): IttySocket<Base, Events>;
61
62
  } & (Base extends IttyProtocol ? {
@@ -65,9 +66,11 @@ export type IttySocket<Base = object, Events extends Record<string, any> = Recor
65
66
  } : object) & {
66
67
  on<T = Record<string, any>>(type: string, listener: (event: Base & T & {
67
68
  type: string;
69
+ message: T;
68
70
  }) => any): IttySocket<Base, Events>;
69
71
  on<T = Record<string, any>>(type: (event?: any) => any, listener: (event: Base & T & {
70
72
  type: string;
73
+ message: T;
71
74
  }) => any): IttySocket<Base, Events>;
72
75
  };
73
76
  export declare let connect: IttySocketConnect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itty-sockets",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "WebSockets : simplified and minified.",
5
5
  "type": "module",
6
6
  "exports": {