@4players/odin-common 1.4.3 → 1.5.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.0
4
+
5
+ - Added `generateUUID`
6
+ - Added `validateUUID`
7
+ - Added re-exports for WebSocket package types
8
+
3
9
  ## 1.4.3
4
10
 
5
11
  - Added union zod schemas for room event validation
package/lib/cjs/index.js CHANGED
@@ -34,6 +34,7 @@ __exportStar(require("./utility/selector"), exports);
34
34
  __exportStar(require("./utility/sleep"), exports);
35
35
  __exportStar(require("./utility/strand"), exports);
36
36
  __exportStar(require("./utility/url"), exports);
37
+ __exportStar(require("./utility/uuid"), exports);
37
38
  __exportStar(require("./utility/validation"), exports);
38
39
  __exportStar(require("./utility/websocket"), exports);
39
40
  __exportStar(require("./plugin/api"), exports);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateUUID = exports.generateUUID = void 0;
4
+ const uuid_1 = require("uuid");
5
+ function generateUUID() {
6
+ return (0, uuid_1.v4)();
7
+ }
8
+ exports.generateUUID = generateUUID;
9
+ function validateUUID(uuid) {
10
+ return (0, uuid_1.validate)(uuid);
11
+ }
12
+ exports.validateUUID = validateUUID;
@@ -9,8 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.webSocketConnectOnce = exports.webSocketConnect = void 0;
12
+ exports.webSocketConnectOnce = exports.webSocketConnect = exports.WebSocketClient = void 0;
13
13
  const ws_1 = require("ws");
14
+ Object.defineProperty(exports, "WebSocketClient", { enumerable: true, get: function () { return ws_1.WebSocket; } });
14
15
  const result_1 = require("./result");
15
16
  const sleep_1 = require("./sleep");
16
17
  function webSocketConnect(url, connectIntervals, clientOptions, onFailure) {
package/lib/esm/index.js CHANGED
@@ -18,6 +18,7 @@ export * from './utility/selector';
18
18
  export * from './utility/sleep';
19
19
  export * from './utility/strand';
20
20
  export * from './utility/url';
21
+ export * from './utility/uuid';
21
22
  export * from './utility/validation';
22
23
  export * from './utility/websocket';
23
24
  export * from './plugin/api';
@@ -0,0 +1,7 @@
1
+ import { v4, validate } from 'uuid';
2
+ export function generateUUID() {
3
+ return v4();
4
+ }
5
+ export function validateUUID(uuid) {
6
+ return validate(uuid);
7
+ }
@@ -7,9 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { WebSocket } from 'ws';
10
+ import { WebSocket as WebSocketClient, } from 'ws';
11
11
  import { failure, success } from './result';
12
12
  import { sleep } from './sleep';
13
+ export { WebSocketClient, };
13
14
  export function webSocketConnect(url, connectIntervals, clientOptions, onFailure) {
14
15
  return __awaiter(this, void 0, void 0, function* () {
15
16
  const start = performance.now();
@@ -42,7 +43,7 @@ export function webSocketConnectOnce(url, clientOptions) {
42
43
  return __awaiter(this, void 0, void 0, function* () {
43
44
  let webSocket;
44
45
  try {
45
- webSocket = new WebSocket(url, clientOptions);
46
+ webSocket = new WebSocketClient(url, clientOptions);
46
47
  }
47
48
  catch (reason) {
48
49
  return failure(`unable to create websocket; ${reason}`);
package/lib/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export * from './utility/selector';
18
18
  export * from './utility/sleep';
19
19
  export * from './utility/strand';
20
20
  export * from './utility/url';
21
+ export * from './utility/uuid';
21
22
  export * from './utility/validation';
22
23
  export * from './utility/websocket';
23
24
  export * from './plugin/api';
@@ -1,9 +1,10 @@
1
+ /// <reference types="ws" />
1
2
  import * as z from 'zod';
2
- import { WebSocket } from 'ws';
3
3
  import { MessagePackRpc } from '../schema/serialization';
4
4
  import { Accept, Result } from './result';
5
5
  import { Commands } from '../rpc/commands';
6
6
  import { Notifications } from '../rpc/notifications';
7
+ import { WebSocketClient } from './websocket';
7
8
  export declare function msgpackEncode(value: unknown): ArrayBuffer;
8
9
  export declare function msgpackDecode(buffer: ArrayBuffer): unknown;
9
10
  export interface RpcMessage {
@@ -15,7 +16,7 @@ export interface RpcRequest {
15
16
  timeoutId: ReturnType<typeof setTimeout> | undefined;
16
17
  }
17
18
  export declare class RpcConnection {
18
- readonly webSocket: WebSocket;
19
+ readonly webSocket: WebSocketClient;
19
20
  private readonly _SendQueue;
20
21
  private readonly _RecvQueue;
21
22
  private readonly _Requests;
@@ -23,7 +24,7 @@ export declare class RpcConnection {
23
24
  private _NextId;
24
25
  get closed(): boolean;
25
26
  get closeSignal(): AbortSignal;
26
- constructor(webSocket: WebSocket);
27
+ constructor(webSocket: WebSocketClient);
27
28
  request(name: string, properties: unknown): Promise<Result<unknown> | 'closed'>;
28
29
  request(name: string, properties: unknown, timeout: number): Promise<Result<unknown> | 'closed' | 'timeout'>;
29
30
  notify(name: string, properties: unknown): void;
@@ -47,7 +48,7 @@ export type RealizedEvents<E extends Notifications> = {
47
48
  export declare class TypedRpcConnection<C extends Commands, E extends Notifications> extends RpcConnection {
48
49
  readonly _Commands: C;
49
50
  readonly _Events: E;
50
- constructor(webSocket: WebSocket, _Commands: C, _Events: E);
51
+ constructor(webSocket: WebSocketClient, _Commands: C, _Events: E);
51
52
  request<Name extends Extract<keyof C, string>>(name: Name, properties: z.infer<C[Name]['request']>): Promise<Result<z.infer<C[Name]['response']>> | 'closed'>;
52
53
  request<Name extends Extract<keyof C, string>>(name: Name, properties: z.infer<C[Name]['request']>, timeout: number): Promise<Result<z.infer<C[Name]['response']>> | 'closed' | 'timeout'>;
53
54
  notify<Name extends Extract<keyof C, string>>(name: Name, properties: z.infer<C[Name]['request']>): void;
@@ -0,0 +1,2 @@
1
+ export declare function generateUUID(): string;
2
+ export declare function validateUUID(uuid: string): boolean;
@@ -1,7 +1,8 @@
1
- import { ClientOptions, WebSocket } from 'ws';
1
+ import { WebSocket as WebSocketClient, ClientOptions as WebSocketClientOptions, CloseEvent as WebSocketCloseEvent, ErrorEvent as WebSocketErrorEvent, MessageEvent as WebSocketMessageEvent, EventListenerOptions as WebSocketEventListenerOptions, Event as WebSocketEvent } from 'ws';
2
2
  import { Result } from './result';
3
- export declare function webSocketConnect(url: URL, connectIntervals: number[], clientOptions?: ClientOptions, onFailure?: (failures: number, cancel: () => void) => void): Promise<{
4
- connect: () => Promise<Result<WebSocket>>;
3
+ export { WebSocketClient, WebSocketClientOptions, WebSocketCloseEvent, WebSocketErrorEvent, WebSocketMessageEvent, WebSocketEventListenerOptions, WebSocketEvent, };
4
+ export declare function webSocketConnect(url: URL, connectIntervals: number[], clientOptions?: WebSocketClientOptions, onFailure?: (failures: number, cancel: () => void) => void): Promise<{
5
+ connect: () => Promise<Result<WebSocketClient>>;
5
6
  cancel: () => void;
6
7
  }>;
7
- export declare function webSocketConnectOnce(url: URL, clientOptions?: ClientOptions): Promise<Result<WebSocket>>;
8
+ export declare function webSocketConnectOnce(url: URL, clientOptions?: WebSocketClientOptions): Promise<Result<WebSocketClient>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4players/odin-common",
3
- "version": "1.4.3",
3
+ "version": "1.5.1",
4
4
  "description": "A collection of commonly used type definitions and utility functions across ODIN web projects",
5
5
  "author": "Josho Bleicker <josho.bleicker@4players.io> (https://www.4players.io)",
6
6
  "homepage": "https://www.4players.io",
@@ -24,19 +24,18 @@
24
24
  "lint": "eslint . --ext .ts",
25
25
  "test": "testyts"
26
26
  },
27
- "engines": {
28
- "node": ">=14"
29
- },
30
27
  "dependencies": {
31
28
  "@msgpack/msgpack": "~3.0.0-beta2",
32
- "@types/ws": "~8.5.0",
29
+ "uuid": "~9.0.0",
33
30
  "ws": "~8.16.0",
34
31
  "zod": "~3.22.0"
35
32
  },
36
33
  "devDependencies": {
37
34
  "@types/node": "~20.11.0",
38
- "@typescript-eslint/eslint-plugin": "~7.0.0",
39
- "@typescript-eslint/parser": "~7.0.0",
35
+ "@types/uuid": "~9.0.0",
36
+ "@types/ws": "~8.5.0",
37
+ "@typescript-eslint/eslint-plugin": "~7.1.0",
38
+ "@typescript-eslint/parser": "~7.1.0",
40
39
  "eslint": "~8.57.0",
41
40
  "eslint-config-semistandard": "~17.0.0",
42
41
  "eslint-plugin-import": "~2.29.0",