@4players/odin-common 2.4.2 → 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 +1 -0
- package/lib/cjs/utility/log.js +47 -0
- package/lib/cjs/utility/result.js +3 -2
- package/lib/esm/index.js +1 -0
- package/lib/esm/utility/log.js +42 -0
- package/lib/esm/utility/result.js +3 -2
- package/lib/index.d.ts +1 -0
- package/lib/utility/log.d.ts +14 -0
- package/lib/utility/result.d.ts +2 -1
- package/package.json +2 -2
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);
|
|
@@ -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
|
|
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
|
@@ -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
|
|
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
|
@@ -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;
|
package/lib/utility/result.d.ts
CHANGED
|
@@ -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.
|
|
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",
|
|
@@ -43,4 +43,4 @@
|
|
|
43
43
|
"testyts": "~1.5.0",
|
|
44
44
|
"typescript": "~5.4.0"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|