@4players/odin-common 2.4.1 → 2.4.3

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/lib/cjs/index.js CHANGED
@@ -36,4 +36,5 @@ __exportStar(require("./utility/strand"), exports);
36
36
  __exportStar(require("./utility/url"), exports);
37
37
  __exportStar(require("./utility/uuid"), exports);
38
38
  __exportStar(require("./utility/validation"), exports);
39
+ __exportStar(require("./utility/log"), exports);
39
40
  __exportStar(require("./plugin/api"), exports);
@@ -8,6 +8,12 @@ const peer_1 = require("../schema/peer");
8
8
  const media_1 = require("../schema/media");
9
9
  const webrtc_1 = require("../schema/webrtc");
10
10
  exports.MainCommandsRpc = {
11
+ Hello: {
12
+ request: zod_1.z.object({
13
+ stream: zod_1.z.literal('main'),
14
+ }),
15
+ response: zod_1.z.null(),
16
+ },
11
17
  JoinRoom: {
12
18
  request: zod_1.z.object({
13
19
  token: zod_1.z.string(),
@@ -35,6 +41,16 @@ exports.MainCommandsRpc = {
35
41
  },
36
42
  };
37
43
  exports.RoomCommandsRpc = {
44
+ Hello: {
45
+ request: zod_1.z.object({
46
+ stream: zod_1.z.literal('room'),
47
+ token: zod_1.z.string(),
48
+ room_id: zod_1.z.string(),
49
+ user_data: serialization_1.ByteArraySchema,
50
+ position: peer_1.PeerPositionSchema,
51
+ }),
52
+ response: zod_1.z.null(),
53
+ },
38
54
  UpdatePeer: {
39
55
  request: zod_1.z.object({ user_data: serialization_1.ByteArraySchema }),
40
56
  response: zod_1.z.null(),
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.log = exports.OdinError = void 0;
4
+ class OdinError extends Error {
5
+ constructor(message = '', options) {
6
+ super(message);
7
+ this.message = message;
8
+ this.name = 'OdinError';
9
+ const date = new Date();
10
+ const hours = date.getHours();
11
+ const minutes = date.getMinutes();
12
+ const seconds = date.getSeconds();
13
+ if (options === null || options === void 0 ? void 0 : options.project) {
14
+ this.message = `ODIN ${options === null || options === void 0 ? void 0 : options.project} | ${options === null || options === void 0 ? void 0 : options.kind}`;
15
+ }
16
+ this.message += ` at ${options === null || options === void 0 ? void 0 : options.project} ${hours}:${minutes}:${seconds}\n`;
17
+ this.message += `${message}\n`;
18
+ }
19
+ }
20
+ exports.OdinError = OdinError;
21
+ function log(message, options, filters = { projects: [], kind: [] }) {
22
+ for (const projectName of filters.projects) {
23
+ if (options.project === projectName) {
24
+ for (const kindName of filters.kind) {
25
+ if (options.kind === kindName) {
26
+ let logMessage = '';
27
+ const date = new Date();
28
+ const hours = date.getHours();
29
+ const minutes = date.getMinutes();
30
+ const seconds = date.getSeconds();
31
+ if (options === null || options === void 0 ? void 0 : options.project) {
32
+ logMessage = `ODIN ${options === null || options === void 0 ? void 0 : options.project} | ${options === null || options === void 0 ? void 0 : options.kind}`;
33
+ }
34
+ logMessage += ` at ${options === null || options === void 0 ? void 0 : options.project} ${hours}:${minutes}:${seconds}\n`;
35
+ logMessage += `${message}\n`;
36
+ if (options.logType) {
37
+ console[options.logType](logMessage);
38
+ }
39
+ else {
40
+ console.log(logMessage);
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ exports.log = log;
@@ -2,14 +2,15 @@
2
2
  /* eslint-disable no-redeclare */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.unwrap = exports.failure = exports.success = exports.fail = exports.assert = void 0;
5
+ const log_1 = require("./log");
5
6
  function assert(condition, message) {
6
7
  if (!condition) {
7
8
  fail(message);
8
9
  }
9
10
  }
10
11
  exports.assert = assert;
11
- function fail(message) {
12
- throw new Error(message);
12
+ function fail(message, options) {
13
+ throw new log_1.OdinError(message, options);
13
14
  }
14
15
  exports.fail = fail;
15
16
  function success(value) {
package/lib/esm/index.js CHANGED
@@ -20,4 +20,5 @@ export * from './utility/strand';
20
20
  export * from './utility/url';
21
21
  export * from './utility/uuid';
22
22
  export * from './utility/validation';
23
+ export * from './utility/log';
23
24
  export * from './plugin/api';
@@ -5,6 +5,12 @@ import { PeerIdSchema, PeerPositionSchema } from '../schema/peer';
5
5
  import { MediaIdSchema, MediaPropertiesSchema } from '../schema/media';
6
6
  import { WebRtcUpdateSchema } from '../schema/webrtc';
7
7
  export const MainCommandsRpc = {
8
+ Hello: {
9
+ request: z.object({
10
+ stream: z.literal('main'),
11
+ }),
12
+ response: z.null(),
13
+ },
8
14
  JoinRoom: {
9
15
  request: z.object({
10
16
  token: z.string(),
@@ -32,6 +38,16 @@ export const MainCommandsRpc = {
32
38
  },
33
39
  };
34
40
  export const RoomCommandsRpc = {
41
+ Hello: {
42
+ request: z.object({
43
+ stream: z.literal('room'),
44
+ token: z.string(),
45
+ room_id: z.string(),
46
+ user_data: ByteArraySchema,
47
+ position: PeerPositionSchema,
48
+ }),
49
+ response: z.null(),
50
+ },
35
51
  UpdatePeer: {
36
52
  request: z.object({ user_data: ByteArraySchema }),
37
53
  response: z.null(),
@@ -0,0 +1,42 @@
1
+ export class OdinError extends Error {
2
+ constructor(message = '', options) {
3
+ super(message);
4
+ this.message = message;
5
+ this.name = 'OdinError';
6
+ const date = new Date();
7
+ const hours = date.getHours();
8
+ const minutes = date.getMinutes();
9
+ const seconds = date.getSeconds();
10
+ if (options === null || options === void 0 ? void 0 : options.project) {
11
+ this.message = `ODIN ${options === null || options === void 0 ? void 0 : options.project} | ${options === null || options === void 0 ? void 0 : options.kind}`;
12
+ }
13
+ this.message += ` at ${options === null || options === void 0 ? void 0 : options.project} ${hours}:${minutes}:${seconds}\n`;
14
+ this.message += `${message}\n`;
15
+ }
16
+ }
17
+ export function log(message, options, filters = { projects: [], kind: [] }) {
18
+ for (const projectName of filters.projects) {
19
+ if (options.project === projectName) {
20
+ for (const kindName of filters.kind) {
21
+ if (options.kind === kindName) {
22
+ let logMessage = '';
23
+ const date = new Date();
24
+ const hours = date.getHours();
25
+ const minutes = date.getMinutes();
26
+ const seconds = date.getSeconds();
27
+ if (options === null || options === void 0 ? void 0 : options.project) {
28
+ logMessage = `ODIN ${options === null || options === void 0 ? void 0 : options.project} | ${options === null || options === void 0 ? void 0 : options.kind}`;
29
+ }
30
+ logMessage += ` at ${options === null || options === void 0 ? void 0 : options.project} ${hours}:${minutes}:${seconds}\n`;
31
+ logMessage += `${message}\n`;
32
+ if (options.logType) {
33
+ console[options.logType](logMessage);
34
+ }
35
+ else {
36
+ console.log(logMessage);
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
@@ -1,11 +1,12 @@
1
1
  /* eslint-disable no-redeclare */
2
+ import { OdinError } from './log';
2
3
  export function assert(condition, message) {
3
4
  if (!condition) {
4
5
  fail(message);
5
6
  }
6
7
  }
7
- export function fail(message) {
8
- throw new Error(message);
8
+ export function fail(message, options) {
9
+ throw new OdinError(message, options);
9
10
  }
10
11
  export function success(value) {
11
12
  return { type: 'Success', value };
package/lib/index.d.ts CHANGED
@@ -20,4 +20,5 @@ export * from './utility/strand';
20
20
  export * from './utility/url';
21
21
  export * from './utility/uuid';
22
22
  export * from './utility/validation';
23
+ export * from './utility/log';
23
24
  export * from './plugin/api';
@@ -5,6 +5,16 @@ export type Commands = Record<string, {
5
5
  response: z.ZodTypeAny;
6
6
  }>;
7
7
  export declare const MainCommandsRpc: {
8
+ Hello: {
9
+ request: z.ZodObject<{
10
+ stream: z.ZodLiteral<"main">;
11
+ }, "strip", z.ZodTypeAny, {
12
+ stream: "main";
13
+ }, {
14
+ stream: "main";
15
+ }>;
16
+ response: z.ZodNull;
17
+ };
8
18
  JoinRoom: {
9
19
  request: z.ZodObject<{
10
20
  token: z.ZodString;
@@ -96,6 +106,28 @@ export declare const MainCommandsRpc: {
96
106
  };
97
107
  export type MainCommands = typeof MainCommandsRpc;
98
108
  export declare const RoomCommandsRpc: {
109
+ Hello: {
110
+ request: z.ZodObject<{
111
+ stream: z.ZodLiteral<"room">;
112
+ token: z.ZodString;
113
+ room_id: z.ZodString;
114
+ user_data: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
115
+ position: z.ZodUnion<[z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>]>;
116
+ }, "strip", z.ZodTypeAny, {
117
+ user_data: Uint8Array;
118
+ stream: "room";
119
+ token: string;
120
+ room_id: string;
121
+ position: [number, number, number] | [number, number];
122
+ }, {
123
+ user_data: Uint8Array;
124
+ stream: "room";
125
+ token: string;
126
+ room_id: string;
127
+ position: [number, number, number] | [number, number];
128
+ }>;
129
+ response: z.ZodNull;
130
+ };
99
131
  UpdatePeer: {
100
132
  request: z.ZodObject<{
101
133
  user_data: z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>;
@@ -0,0 +1,14 @@
1
+ export type LogOptions = {
2
+ kind: string;
3
+ project: string;
4
+ logType?: 'debug' | 'info' | 'warn' | 'error';
5
+ };
6
+ export declare class OdinError extends Error {
7
+ message: string;
8
+ readonly name = "OdinError";
9
+ constructor(message?: string, options?: LogOptions);
10
+ }
11
+ export declare function log(message: string, options: LogOptions, filters?: {
12
+ projects: string[];
13
+ kind: string[];
14
+ }): void;
@@ -1,5 +1,6 @@
1
+ import { LogOptions } from './log';
1
2
  export declare function assert(condition: unknown, message: string): asserts condition;
2
- export declare function fail(message: string): never;
3
+ export declare function fail(message: string, options?: LogOptions): never;
3
4
  export type Failure = {
4
5
  type: 'Failure';
5
6
  reason: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4players/odin-common",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
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",