@samet-it/be-base-common 1.1.3 → 1.1.5

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,2 +1,2 @@
1
1
  export * from './index.types';
2
- export * from './logger.default';
2
+ export * from './logger.impl';
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./index.types"), exports);
18
- __exportStar(require("./logger.default"), exports);
18
+ __exportStar(require("./logger.impl"), exports);
@@ -1,68 +1,39 @@
1
- import type { ClassLike, Obj } from "@leyyo/common";
1
+ import type { ClassLike, Obj, Logger } from "@leyyo/common";
2
2
  /**
3
- * Base logger to align console
3
+ * Logger pool interface
4
4
  * */
5
5
  export interface LoggerLike {
6
6
  /**
7
- * Debug log
7
+ * Create logger by class name
8
8
  *
9
- * @param {string} message - message
10
- * @param {any} args - arguments
9
+ * @param {string} className - class name
10
+ * @return {Logger} - logger instance
11
11
  * */
12
- debug?(message: string, args?: unknown): void;
12
+ create(className: string): Logger;
13
13
  /**
14
- * Trace log
14
+ * Create logger by class
15
15
  *
16
- * @param {string} message - message
17
- * @param {any} args - arguments
16
+ * @param {function} clazz - class
17
+ * @return {Logger} - logger instance
18
18
  * */
19
- trace?(message: string, args?: unknown): void;
19
+ create(clazz: ClassLike): Logger;
20
20
  /**
21
- * Info log
21
+ * Create logger by instance
22
22
  *
23
- * @param {string} message - message
24
- * @param {any} args - arguments
23
+ * @param {Obj} instance - instance, ie: `this`
24
+ * @return {Logger} - logger instance
25
25
  * */
26
- info?(message: string, args?: unknown): void;
26
+ create(instance: Obj): Logger;
27
27
  /**
28
- * Info log
29
- * @alias info
28
+ * Get samet default logger
30
29
  *
31
- * @param {string} message - message
32
- * @param {any} args - arguments
30
+ * @return {Logger} - logger instance
33
31
  * */
34
- log?(message: string, args?: unknown): void;
32
+ get samet(): Logger;
35
33
  /**
36
- * Warning log
34
+ * Get developer default logger
37
35
  *
38
- * @param {(string|Error)} message - error or message
39
- * @param {any} args - arguments
36
+ * @return {Logger} - logger instance
40
37
  * */
41
- warn?(message: string | Error, args?: unknown): void;
42
- /**
43
- * Error log
44
- *
45
- * @param {(string|Error)} message - error or message
46
- * @param {any} args - arguments
47
- * */
48
- error?(message: string | Error, args?: unknown): void;
49
- /**
50
- * Fatal log
51
- *
52
- * @param {(string|Error)} message - error or message
53
- * @param {any} args - arguments
54
- * */
55
- fatal?(message: string | Error, args?: unknown): void;
56
- }
57
- /**
58
- * Extended logger to support to fork new logger
59
- * */
60
- export interface LoggerDefaultLike extends LoggerLike {
61
- /**
62
- * Create/fork new logger
63
- *
64
- * @param {(string|ClassLike|Obj)} clazz - class, name or instance
65
- * @return {LoggerLike} - new logger
66
- * */
67
- of(clazz: string | ClassLike | Obj): LoggerLike;
38
+ get developer(): Logger;
68
39
  }
@@ -0,0 +1,7 @@
1
+ import type { LoggerLike } from "./index.types";
2
+ /**
3
+ * Logger pool
4
+ *
5
+ * @type {LoggerLike}
6
+ * */
7
+ export declare const logger: LoggerLike;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = void 0;
4
+ const common_1 = require("@leyyo/common");
5
+ /**
6
+ * Logger pool class
7
+ * */
8
+ class LoggerImpl {
9
+ /**
10
+ * Create logger
11
+ *
12
+ * @param {(string|ClassLike|Obj)} ref - class name, class or instance
13
+ * @return {Logger} - logger instance
14
+ * */
15
+ create(ref) {
16
+ return common_1.$log.create(ref);
17
+ }
18
+ /** @inheritDoc */
19
+ get samet() {
20
+ if (!this._sametLogger) {
21
+ this._sametLogger = common_1.$log.create('Samet');
22
+ }
23
+ return this._sametLogger;
24
+ }
25
+ /** @inheritDoc */
26
+ get developer() {
27
+ if (!this._developerLogger) {
28
+ this._developerLogger = common_1.$log.create('Developer');
29
+ }
30
+ return this._developerLogger;
31
+ }
32
+ }
33
+ // noinspection JSUnusedGlobalSymbols
34
+ /**
35
+ * Logger pool
36
+ *
37
+ * @type {LoggerLike}
38
+ * */
39
+ exports.logger = new LoggerImpl();
@@ -34,10 +34,6 @@ export interface Entity<I extends IdLike = IdLike, N extends CanBeI18N<L> = Name
34
34
  * Updated by
35
35
  * */
36
36
  updatedBy?: UuidLike;
37
- /**
38
- * Urn
39
- * */
40
- _urn?: UrnLike;
41
37
  /**
42
38
  * Trash id if it's trashed
43
39
  * */
@@ -81,12 +77,13 @@ export interface IdDocLike<I extends IdLike = IdLike> {
81
77
  * Id
82
78
  * */
83
79
  id?: I;
80
+ /**
81
+ * Urn
82
+ * */
83
+ urn?: UrnLike;
84
84
  }
85
85
  export type View<I extends IdLike = IdLike> = IdDocLike<I>;
86
86
  export type Portion<I extends IdLike = IdLike> = IdDocLike<I>;
87
- export interface Portions<I extends IdLike = IdLike> {
88
- ids: Array<I>;
89
- }
90
87
  export type DefDims = 'pair' | 'view' | 'portion';
91
88
  export type I18nBase<L extends LangLike = LangLike, V = string> = {
92
89
  [lang in L]: V;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samet-it/be-base-common",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Backend Base Common",
5
5
  "repository": {
6
6
  "type": "git",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "dependencies": {
66
66
  "@leyyo/common": "^1.2.3",
67
- "@leyyo/env": "^1.2.1",
67
+ "@leyyo/env": "^1.2.5",
68
68
  "@leyyo/asl": "^1.2.1"
69
69
  }
70
70
  }
@@ -1,41 +0,0 @@
1
- import type { ClassLike, Obj } from "@leyyo/common";
2
- import type { LoggerDefaultLike, LoggerLike } from "./index.types";
3
- /** @inheritDoc */
4
- export declare class LoggerDefault implements LoggerDefaultLike {
5
- private readonly _className;
6
- /**
7
- * Constructor
8
- *
9
- * @param {(string|ClassLike|Obj)} clazz - class, name or instance
10
- * */
11
- constructor(clazz?: string | ClassLike | Obj);
12
- /**
13
- * Builds the log message
14
- *
15
- * @param {any} message - message or error
16
- * @return {string} - formatted message
17
- * */
18
- private _buildMessage;
19
- /** @inheritDoc */
20
- of(clazz: string | ClassLike | Obj): LoggerLike;
21
- /** @inheritDoc */
22
- debug(message: string, args?: unknown): void;
23
- /** @inheritDoc */
24
- error(message: string | Error, args?: unknown): void;
25
- /** @inheritDoc */
26
- fatal(message: string | Error, args?: unknown): void;
27
- /** @inheritDoc */
28
- info(message: string, args?: unknown): void;
29
- /** @inheritDoc */
30
- log(message: string, args?: unknown): void;
31
- /** @inheritDoc */
32
- trace(message: string, args?: unknown): void;
33
- /** @inheritDoc */
34
- warn(message: string | Error, args?: unknown): void;
35
- }
36
- /**
37
- * Base logger instance
38
- *
39
- * @type {LoggerDefaultLike}
40
- * */
41
- export declare const logger: LoggerDefaultLike;
@@ -1,142 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logger = exports.LoggerDefault = void 0;
4
- /** @inheritDoc */
5
- class LoggerDefault {
6
- /**
7
- * Constructor
8
- *
9
- * @param {(string|ClassLike|Obj)} clazz - class, name or instance
10
- * */
11
- constructor(clazz) {
12
- var _a;
13
- switch (typeof clazz) {
14
- case "string":
15
- this._className = clazz;
16
- break;
17
- case "function":
18
- this._className = clazz.name;
19
- break;
20
- case "object":
21
- if (clazz) {
22
- this._className = (_a = clazz.constructor) === null || _a === void 0 ? void 0 : _a.name;
23
- }
24
- break;
25
- }
26
- if (this._className) {
27
- this._className = this._className ? `[${this._className}] ` : '';
28
- }
29
- }
30
- /**
31
- * Builds the log message
32
- *
33
- * @param {any} message - message or error
34
- * @return {string} - formatted message
35
- * */
36
- _buildMessage(message) {
37
- var _a, _b;
38
- switch (typeof message) {
39
- case "string":
40
- return message.trim();
41
- case "boolean":
42
- return message ? 'true' : 'false';
43
- case "bigint":
44
- case "number":
45
- return message.toString();
46
- case "object":
47
- if (message instanceof Error) {
48
- const errorName = message.name ? `[${message.name}] => ` : '';
49
- return `${errorName}${(_a = message.message) !== null && _a !== void 0 ? _a : 'Unknown error'}`;
50
- }
51
- return JSON.stringify(message);
52
- case "symbol":
53
- return message.description;
54
- case "undefined":
55
- return '';
56
- case "function":
57
- return `${(_b = message.name) !== null && _b !== void 0 ? _b : '~fnc~'}(${message.length})`;
58
- }
59
- }
60
- /** @inheritDoc */
61
- of(clazz) {
62
- return new LoggerDefault(clazz);
63
- }
64
- /** @inheritDoc */
65
- debug(message, args) {
66
- const line = `[${new Date().toISOString()}] ${this._className}${this._buildMessage(message)}`;
67
- if (args === undefined) {
68
- console.debug(line);
69
- }
70
- else {
71
- console.debug(line, args);
72
- }
73
- }
74
- /** @inheritDoc */
75
- error(message, args) {
76
- const line = `[${new Date().toISOString()}] ${this._className}${this._buildMessage(message)}`;
77
- if (args === undefined) {
78
- console.error(line);
79
- }
80
- else {
81
- console.error(line, args);
82
- }
83
- }
84
- /** @inheritDoc */
85
- fatal(message, args) {
86
- const line = `[${new Date().toISOString()}] ${this._className}[#fatal]${this._buildMessage(message)}`;
87
- if (args === undefined) {
88
- console.error(line);
89
- }
90
- else {
91
- console.error(line, args);
92
- }
93
- }
94
- /** @inheritDoc */
95
- info(message, args) {
96
- const line = `[${new Date().toISOString()}] ${this._className}${this._buildMessage(message)}`;
97
- if (args === undefined) {
98
- console.info(line);
99
- }
100
- else {
101
- console.info(line, args);
102
- }
103
- }
104
- /** @inheritDoc */
105
- log(message, args) {
106
- const line = `[${new Date().toISOString()}] ${this._className}${this._buildMessage(message)}`;
107
- if (args === undefined) {
108
- console.log(line);
109
- }
110
- else {
111
- console.log(line, args);
112
- }
113
- }
114
- /** @inheritDoc */
115
- trace(message, args) {
116
- const line = `[${new Date().toISOString()}] ${this._className}${this._buildMessage(message)}`;
117
- if (args === undefined) {
118
- console.trace(line);
119
- }
120
- else {
121
- console.trace(line, args);
122
- }
123
- }
124
- /** @inheritDoc */
125
- warn(message, args) {
126
- const line = `[${new Date().toISOString()}] ${this._className}${this._buildMessage(message)}`;
127
- if (args === undefined) {
128
- console.warn(line);
129
- }
130
- else {
131
- console.warn(line, args);
132
- }
133
- }
134
- }
135
- exports.LoggerDefault = LoggerDefault;
136
- // noinspection JSUnusedGlobalSymbols
137
- /**
138
- * Base logger instance
139
- *
140
- * @type {LoggerDefaultLike}
141
- * */
142
- exports.logger = new LoggerDefault();