@nascentdigital/funnel-core 6.1.3 → 6.1.6
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/dist/schema/Block.d.ts +0 -7
- package/dist/schema/Block.js +5 -27
- package/dist/schema/blocks/PanelledBlock.d.ts +5 -3
- package/dist/schema/blocks/PanelledBlock.js +7 -3
- package/dist/services/Logger.d.ts +72 -0
- package/dist/services/Logger.js +256 -0
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +2 -1
- package/package.json +2 -2
package/dist/schema/Block.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export declare class Block<TId extends string = string, TFields extends Fields =
|
|
|
14
14
|
readonly editableFields: Fields.UnwrapOptional<TFields>;
|
|
15
15
|
readonly config: Block.Config.UnwrapOptional<TConfig>;
|
|
16
16
|
readonly getConfig?: Block.GetConfig<TFields, TConfig>;
|
|
17
|
-
readonly defaultContent?: Block.DefaultContent<TFields>;
|
|
18
17
|
protected constructor(args: Block.ConstructorArgs<TId, TFields, TConfig>);
|
|
19
18
|
optional(): Optional<Block<TId, TFields, TConfig>>;
|
|
20
19
|
unwrap(): this;
|
|
@@ -26,10 +25,6 @@ export declare class Block<TId extends string = string, TFields extends Fields =
|
|
|
26
25
|
hide(...keys: ReadonlyArray<Fields.OptionalKeys<TFields>>): Block<TId, TFields, TConfig>;
|
|
27
26
|
override(override: Fields.Override<TFields>): Block<TId, TFields, TConfig>;
|
|
28
27
|
extend<TAdditionalFields extends Fields>(fields: TAdditionalFields): Block<TId, TFields & TAdditionalFields, TConfig>;
|
|
29
|
-
/**
|
|
30
|
-
* Set default content when block gets created.
|
|
31
|
-
*/
|
|
32
|
-
withContent(defaultContent: Block.DefaultContent<TFields>): Block<TId, TFields, TConfig>;
|
|
33
28
|
static create<TId extends string, TFields extends Fields, TConfig extends Block.Config>(args: Block.FactoryArgs<TId, TFields, TConfig>): Block<TId, TFields, TConfig>;
|
|
34
29
|
}
|
|
35
30
|
export declare namespace Block {
|
|
@@ -64,7 +59,6 @@ export declare namespace Block {
|
|
|
64
59
|
updatedConfigSchema?: Partial<Config.UnwrapOptional<TConfig>>;
|
|
65
60
|
};
|
|
66
61
|
}
|
|
67
|
-
type DefaultContent<TFields extends Fields = Fields> = Array<keyof TFields>;
|
|
68
62
|
type Data<T extends Block = Block> = {
|
|
69
63
|
type: 'block';
|
|
70
64
|
id: T['id'];
|
|
@@ -112,7 +106,6 @@ export declare namespace Block {
|
|
|
112
106
|
editableFields: Fields.UnwrapOptional<TFields>;
|
|
113
107
|
config?: TConfig;
|
|
114
108
|
getConfig?: GetConfig<TFields, TConfig>;
|
|
115
|
-
defaultContent?: DefaultContent<TFields>;
|
|
116
109
|
};
|
|
117
110
|
type ModifyArgs<TId extends string, TFields extends Fields, TConfig extends Config> = Partial<Pick<ConstructorArgs<TId, TFields, TConfig>, 'name' | 'hint' | 'required'>>;
|
|
118
111
|
type FactoryArgs<TId extends string, TFields extends Fields, TConfig extends Config = Config> = Omit<ConstructorArgs<TId, TFields, TConfig>, 'editableFields' | 'required'>;
|
package/dist/schema/Block.js
CHANGED
|
@@ -29,7 +29,6 @@ class Block {
|
|
|
29
29
|
}, {})
|
|
30
30
|
: {};
|
|
31
31
|
this.getConfig = args.getConfig;
|
|
32
|
-
this.defaultContent = args.defaultContent;
|
|
33
32
|
}
|
|
34
33
|
optional() {
|
|
35
34
|
return new Optional_1.Optional(this);
|
|
@@ -39,7 +38,7 @@ class Block {
|
|
|
39
38
|
}
|
|
40
39
|
modify(args) {
|
|
41
40
|
// create new block (re-map required fields)
|
|
42
|
-
return new Block(Object.assign({ id: this.id, name: this.name, hint: this.hint, required: this.required, version: this.version, fields: this.fields, editableFields: this.editableFields, config: this.config, getConfig: this.getConfig
|
|
41
|
+
return new Block(Object.assign({ id: this.id, name: this.name, hint: this.hint, required: this.required, version: this.version, fields: this.fields, editableFields: this.editableFields, config: this.config, getConfig: this.getConfig }, args));
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
45
44
|
* Rename a block's name which is used in the editor.
|
|
@@ -73,8 +72,7 @@ class Block {
|
|
|
73
72
|
return fields;
|
|
74
73
|
}, Object.assign({}, this.editableFields)),
|
|
75
74
|
config: this.config,
|
|
76
|
-
getConfig: this.getConfig
|
|
77
|
-
defaultContent: this.defaultContent
|
|
75
|
+
getConfig: this.getConfig
|
|
78
76
|
});
|
|
79
77
|
}
|
|
80
78
|
override(override) {
|
|
@@ -90,8 +88,7 @@ class Block {
|
|
|
90
88
|
fields: this.fields,
|
|
91
89
|
editableFields: Object.assign(Object.assign({}, this.editableFields), overrides),
|
|
92
90
|
config: this.config,
|
|
93
|
-
getConfig: this.getConfig
|
|
94
|
-
defaultContent: this.defaultContent
|
|
91
|
+
getConfig: this.getConfig
|
|
95
92
|
});
|
|
96
93
|
}
|
|
97
94
|
extend(fields) {
|
|
@@ -104,25 +101,7 @@ class Block {
|
|
|
104
101
|
fields: Object.assign(Object.assign({}, this.fields), fields),
|
|
105
102
|
editableFields: Object.assign(Object.assign({}, this.editableFields), Fields_1.Fields.unwrap(fields)),
|
|
106
103
|
config: this.config,
|
|
107
|
-
getConfig: this.getConfig
|
|
108
|
-
defaultContent: this.defaultContent
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Set default content when block gets created.
|
|
113
|
-
*/
|
|
114
|
-
withContent(defaultContent) {
|
|
115
|
-
return new Block({
|
|
116
|
-
id: this.id,
|
|
117
|
-
name: this.name,
|
|
118
|
-
hint: this.hint,
|
|
119
|
-
required: this.required,
|
|
120
|
-
version: this.version,
|
|
121
|
-
fields: this.fields,
|
|
122
|
-
editableFields: this.editableFields,
|
|
123
|
-
config: this.config,
|
|
124
|
-
getConfig: this.getConfig,
|
|
125
|
-
defaultContent: defaultContent
|
|
104
|
+
getConfig: this.getConfig
|
|
126
105
|
});
|
|
127
106
|
}
|
|
128
107
|
static create(args) {
|
|
@@ -135,8 +114,7 @@ class Block {
|
|
|
135
114
|
fields: args.fields,
|
|
136
115
|
editableFields: Fields_1.Fields.unwrap(args.fields),
|
|
137
116
|
config: args.config,
|
|
138
|
-
getConfig: args.getConfig
|
|
139
|
-
defaultContent: args.defaultContent
|
|
117
|
+
getConfig: args.getConfig
|
|
140
118
|
});
|
|
141
119
|
}
|
|
142
120
|
}
|
|
@@ -3,10 +3,11 @@ import type { BlockLayout, PanelLayout, PanelSlot } from '../../ui';
|
|
|
3
3
|
import { Block } from '../Block';
|
|
4
4
|
import { Fields, Fields as FieldsModel } from '../Fields';
|
|
5
5
|
export declare class PanelledBlock<TId extends string = string, TFields extends PanelledBlock.Fields = any, TConfig extends PanelledBlock.Config = any> extends Block<TId, TFields, TConfig> {
|
|
6
|
+
readonly defaultContent?: PanelledBlock.DefaultContent<TFields>;
|
|
6
7
|
readonly getLayout?: PanelledBlock.GetLayout<TFields, TConfig>;
|
|
7
8
|
readonly defaultPanelLayouts: PanelledBlock.DefaultPanelLayouts;
|
|
8
9
|
readonly defaultLayoutConfigs: PanelledBlock.DefaultLayoutConfigs<TConfig>;
|
|
9
|
-
protected constructor({ getConfig, getLayout, defaultPanelLayouts, defaultLayoutConfigs, ...args }: PanelledBlock.ConstructorArgs<TId, TFields, TConfig>);
|
|
10
|
+
protected constructor({ getConfig, defaultContent, getLayout, defaultPanelLayouts, defaultLayoutConfigs, ...args }: PanelledBlock.ConstructorArgs<TId, TFields, TConfig>);
|
|
10
11
|
modify(args: Block.ModifyArgs<TId, TFields, TConfig>): PanelledBlock<TId, TFields, TConfig>;
|
|
11
12
|
/**
|
|
12
13
|
* Rename a block's name which is used in the editor.
|
|
@@ -18,7 +19,7 @@ export declare class PanelledBlock<TId extends string = string, TFields extends
|
|
|
18
19
|
/**
|
|
19
20
|
* Set default content when block gets created.
|
|
20
21
|
*/
|
|
21
|
-
withContent(defaultContent:
|
|
22
|
+
withContent(defaultContent: PanelledBlock.DefaultContent<TFields>): PanelledBlock<TId, TFields, TConfig>;
|
|
22
23
|
/**
|
|
23
24
|
* Specify a default layout for a set of active panels.
|
|
24
25
|
*/
|
|
@@ -39,6 +40,7 @@ export declare namespace PanelledBlock {
|
|
|
39
40
|
type UnwrapOptional<TConfig extends Config> = Block.Config.UnwrapOptional<TConfig>;
|
|
40
41
|
type Value<TConfig extends Config> = Block.Config.Value<TConfig>;
|
|
41
42
|
}
|
|
43
|
+
type DefaultContent<TFields extends Fields = Fields> = Array<keyof TFields>;
|
|
42
44
|
type GetConfig<TFields extends Fields = Fields, TConfig extends Config = Config> = Transform<GetConfig.Args<TFields, TConfig>, GetConfig.Result<TConfig>>;
|
|
43
45
|
namespace GetConfig {
|
|
44
46
|
type Args<TFields extends Fields, TConfig extends Config> = {
|
|
@@ -72,7 +74,7 @@ export declare namespace PanelledBlock {
|
|
|
72
74
|
config?: TConfig;
|
|
73
75
|
getConfig?: GetConfig<TFields, TConfig>;
|
|
74
76
|
getLayout?: GetLayout<TFields, TConfig>;
|
|
75
|
-
defaultContent?:
|
|
77
|
+
defaultContent?: DefaultContent<TFields>;
|
|
76
78
|
defaultPanelLayouts?: DefaultPanelLayouts;
|
|
77
79
|
defaultLayoutConfigs?: DefaultLayoutConfigs<TConfig>;
|
|
78
80
|
};
|
|
@@ -19,10 +19,11 @@ const Fields_1 = require("../Fields");
|
|
|
19
19
|
// class
|
|
20
20
|
class PanelledBlock extends Block_1.Block {
|
|
21
21
|
constructor(_a) {
|
|
22
|
-
var { getConfig, getLayout, defaultPanelLayouts, defaultLayoutConfigs } = _a, args = __rest(_a, ["getConfig", "getLayout", "defaultPanelLayouts", "defaultLayoutConfigs"]);
|
|
22
|
+
var { getConfig, defaultContent, getLayout, defaultPanelLayouts, defaultLayoutConfigs } = _a, args = __rest(_a, ["getConfig", "defaultContent", "getLayout", "defaultPanelLayouts", "defaultLayoutConfigs"]);
|
|
23
23
|
// construct base
|
|
24
24
|
super(Object.assign(Object.assign({}, args), { getConfig: getConfig }));
|
|
25
25
|
// initialize instance variables
|
|
26
|
+
this.defaultContent = defaultContent;
|
|
26
27
|
this.getLayout = getLayout;
|
|
27
28
|
this.defaultPanelLayouts = defaultPanelLayouts !== null && defaultPanelLayouts !== void 0 ? defaultPanelLayouts : {};
|
|
28
29
|
this.defaultLayoutConfigs = defaultLayoutConfigs !== null && defaultLayoutConfigs !== void 0 ? defaultLayoutConfigs : {};
|
|
@@ -110,7 +111,7 @@ class PanelledBlock extends Block_1.Block {
|
|
|
110
111
|
* Set default content when block gets created.
|
|
111
112
|
*/
|
|
112
113
|
withContent(defaultContent) {
|
|
113
|
-
return new
|
|
114
|
+
return new PanelledBlock({
|
|
114
115
|
id: this.id,
|
|
115
116
|
name: this.name,
|
|
116
117
|
hint: this.hint,
|
|
@@ -120,7 +121,10 @@ class PanelledBlock extends Block_1.Block {
|
|
|
120
121
|
editableFields: this.editableFields,
|
|
121
122
|
config: this.config,
|
|
122
123
|
getConfig: this.getConfig,
|
|
123
|
-
|
|
124
|
+
getLayout: this.getLayout,
|
|
125
|
+
defaultContent: defaultContent,
|
|
126
|
+
defaultPanelLayouts: this.defaultPanelLayouts,
|
|
127
|
+
defaultLayoutConfigs: this.defaultLayoutConfigs,
|
|
124
128
|
});
|
|
125
129
|
}
|
|
126
130
|
/**
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export declare class Logger {
|
|
2
|
+
private static _configurations?;
|
|
3
|
+
private static readonly _loggers;
|
|
4
|
+
readonly context: string;
|
|
5
|
+
readonly configuration: Logger.Configuration;
|
|
6
|
+
static configure(configurations: Logger.Configurations.Args): void;
|
|
7
|
+
static get(context?: Logger.Context.WithoutRoot): Logger;
|
|
8
|
+
private constructor();
|
|
9
|
+
error(message: string, ...args: any[]): void;
|
|
10
|
+
e(message: string, ...args: any[]): void;
|
|
11
|
+
warn(message: string, ...args: any[]): void;
|
|
12
|
+
w(message: string, ...args: any[]): void;
|
|
13
|
+
info(message: string, ...args: any[]): void;
|
|
14
|
+
i(message: string, ...args: any[]): void;
|
|
15
|
+
debug(message: string, ...args: any[]): void;
|
|
16
|
+
d(message: string, ...args: any[]): void;
|
|
17
|
+
verbose(message: string, ...args: any[]): void;
|
|
18
|
+
v(message: string, ...args: any[]): void;
|
|
19
|
+
trace(message: string, ...args: any[]): void;
|
|
20
|
+
t(message: string, ...args: any[]): void;
|
|
21
|
+
private log;
|
|
22
|
+
}
|
|
23
|
+
export declare namespace Logger {
|
|
24
|
+
type Context = Context.Root | `${string}` | `${string}${Context.Delimiter}${string}` | `${string}${Context.Delimiter}${string}${Context.Delimiter}${string}` | `${string}${Context.Delimiter}${string}${Context.Delimiter}${string}${Context.Delimiter}${string}`;
|
|
25
|
+
namespace Context {
|
|
26
|
+
const root: "";
|
|
27
|
+
type Root = typeof root;
|
|
28
|
+
const delimiter: ":";
|
|
29
|
+
type Delimiter = typeof delimiter;
|
|
30
|
+
type WithoutRoot = Exclude<Context, Root>;
|
|
31
|
+
}
|
|
32
|
+
type Level = 'error' | 'warn' | 'info' | 'debug' | 'verbose' | 'trace';
|
|
33
|
+
namespace Level {
|
|
34
|
+
const values: ReadonlyArray<Level>;
|
|
35
|
+
function compare(lhs: Level, rhs: Level): number;
|
|
36
|
+
function parse(value: string): Level | undefined;
|
|
37
|
+
}
|
|
38
|
+
type LevelOptions = Readonly<LevelOptions.Mutable>;
|
|
39
|
+
namespace LevelOptions {
|
|
40
|
+
type Flexible = Level | ReadonlyArray<Level> | LevelOptions;
|
|
41
|
+
type Mutable = Record<Level, boolean>;
|
|
42
|
+
function coerce(levelOrOptions: Flexible): LevelOptions;
|
|
43
|
+
function filter(levelOrOptions: Flexible): levelOrOptions is LevelOptions;
|
|
44
|
+
function fromLevels(levels: ReadonlyArray<Level>): LevelOptions;
|
|
45
|
+
}
|
|
46
|
+
type Configuration = {
|
|
47
|
+
levels: LevelOptions;
|
|
48
|
+
color?: string;
|
|
49
|
+
bgColor?: string;
|
|
50
|
+
};
|
|
51
|
+
namespace Configuration {
|
|
52
|
+
const defaults: Readonly<Configuration>;
|
|
53
|
+
type Flexible = {
|
|
54
|
+
levels?: LevelOptions.Flexible;
|
|
55
|
+
color?: string;
|
|
56
|
+
bgColor?: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
type Configurations = Readonly<Record<Context, Readonly<Configuration>>>;
|
|
60
|
+
namespace Configurations {
|
|
61
|
+
type Args = {
|
|
62
|
+
root: Configuration.Flexible;
|
|
63
|
+
contexts?: Readonly<Record<Context.WithoutRoot, Readonly<Configuration.Flexible>>>;
|
|
64
|
+
};
|
|
65
|
+
type Parsed = Readonly<Record<Context, Readonly<Partial<Configuration>>>>;
|
|
66
|
+
function parse({ root, contexts }: Args): Parsed;
|
|
67
|
+
}
|
|
68
|
+
type ConstructorArgs = {
|
|
69
|
+
context: string;
|
|
70
|
+
configuration: Configuration;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
// class
|
|
5
|
+
class Logger {
|
|
6
|
+
static configure(configurations) {
|
|
7
|
+
// set configuration
|
|
8
|
+
Logger._configurations = Object.assign({ [Logger.Context.root]: Logger.Configuration.defaults }, Logger.Configurations.parse(configurations));
|
|
9
|
+
// reset loggers
|
|
10
|
+
Logger._loggers.clear();
|
|
11
|
+
}
|
|
12
|
+
static get(context) {
|
|
13
|
+
var _a;
|
|
14
|
+
// helper to get logger
|
|
15
|
+
const loggers = Logger._loggers;
|
|
16
|
+
const configurations = (_a = Logger._configurations) !== null && _a !== void 0 ? _a : { [Logger.Context.root]: Logger.Configuration.defaults };
|
|
17
|
+
let currentConfiguration = configurations[Logger.Context.root];
|
|
18
|
+
const getLogger = (context) => {
|
|
19
|
+
var _a, _b, _c;
|
|
20
|
+
// get logger (or create one)
|
|
21
|
+
let logger = loggers.get(context);
|
|
22
|
+
if (!logger) {
|
|
23
|
+
const maybeConfiguration = configurations[context];
|
|
24
|
+
const configuration = {
|
|
25
|
+
levels: (_a = maybeConfiguration === null || maybeConfiguration === void 0 ? void 0 : maybeConfiguration.levels) !== null && _a !== void 0 ? _a : currentConfiguration.levels,
|
|
26
|
+
color: (_b = maybeConfiguration === null || maybeConfiguration === void 0 ? void 0 : maybeConfiguration.color) !== null && _b !== void 0 ? _b : currentConfiguration.color,
|
|
27
|
+
bgColor: (_c = maybeConfiguration === null || maybeConfiguration === void 0 ? void 0 : maybeConfiguration.bgColor) !== null && _c !== void 0 ? _c : currentConfiguration.bgColor
|
|
28
|
+
};
|
|
29
|
+
logger = new Logger({ context, configuration });
|
|
30
|
+
loggers.set(context, logger);
|
|
31
|
+
}
|
|
32
|
+
// return logger
|
|
33
|
+
return logger;
|
|
34
|
+
};
|
|
35
|
+
// walk context in parts, building along the way (this is required to get configurations right)
|
|
36
|
+
const contextParts = context
|
|
37
|
+
? context.split(Logger.Context.delimiter)
|
|
38
|
+
: [];
|
|
39
|
+
let logger = getLogger(Logger.Context.root);
|
|
40
|
+
for (const contextPart of contextParts) {
|
|
41
|
+
// get new logger
|
|
42
|
+
const context = logger.context === Logger.Context.root
|
|
43
|
+
? contextPart
|
|
44
|
+
: `${logger.context}${Logger.Context.delimiter}${contextPart}`;
|
|
45
|
+
logger = getLogger(context);
|
|
46
|
+
// update logger levels (used for cascading/inheriting nearest options)
|
|
47
|
+
currentConfiguration = logger.configuration;
|
|
48
|
+
}
|
|
49
|
+
// return logger
|
|
50
|
+
return logger;
|
|
51
|
+
}
|
|
52
|
+
constructor({ context, configuration }) {
|
|
53
|
+
// initialize instance variables
|
|
54
|
+
this.context = context;
|
|
55
|
+
this.configuration = configuration;
|
|
56
|
+
}
|
|
57
|
+
error(message, ...args) {
|
|
58
|
+
this.e(message, ...args);
|
|
59
|
+
}
|
|
60
|
+
e(message, ...args) {
|
|
61
|
+
this.log('error', message, args);
|
|
62
|
+
}
|
|
63
|
+
warn(message, ...args) {
|
|
64
|
+
this.w(message, ...args);
|
|
65
|
+
}
|
|
66
|
+
w(message, ...args) {
|
|
67
|
+
this.log('warn', message, args);
|
|
68
|
+
}
|
|
69
|
+
info(message, ...args) {
|
|
70
|
+
this.i(message, ...args);
|
|
71
|
+
}
|
|
72
|
+
i(message, ...args) {
|
|
73
|
+
this.log('info', message, args);
|
|
74
|
+
}
|
|
75
|
+
debug(message, ...args) {
|
|
76
|
+
this.d(message, ...args);
|
|
77
|
+
}
|
|
78
|
+
d(message, ...args) {
|
|
79
|
+
this.log('debug', message, args);
|
|
80
|
+
}
|
|
81
|
+
verbose(message, ...args) {
|
|
82
|
+
this.v(message, ...args);
|
|
83
|
+
}
|
|
84
|
+
v(message, ...args) {
|
|
85
|
+
this.log('verbose', message, args);
|
|
86
|
+
}
|
|
87
|
+
trace(message, ...args) {
|
|
88
|
+
this.t(message, ...args);
|
|
89
|
+
}
|
|
90
|
+
t(message, ...args) {
|
|
91
|
+
this.log('trace', message, args);
|
|
92
|
+
}
|
|
93
|
+
log(level, message, argsRaw) {
|
|
94
|
+
// skip if level isn't included
|
|
95
|
+
const { context: contextRaw, configuration: { color, bgColor, levels } } = this;
|
|
96
|
+
if (!levels[level]) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// basic formating if there's no color
|
|
100
|
+
const context = contextRaw === Logger.Context.root ? '$' : contextRaw;
|
|
101
|
+
let formattedMessage;
|
|
102
|
+
let args;
|
|
103
|
+
if (!color && !bgColor) {
|
|
104
|
+
formattedMessage = `[${context}] ${message}`;
|
|
105
|
+
args = argsRaw;
|
|
106
|
+
}
|
|
107
|
+
// or format for browser
|
|
108
|
+
else if (typeof global.window !== 'undefined') {
|
|
109
|
+
formattedMessage = `[%c${context}%c] ${message}`;
|
|
110
|
+
args = [
|
|
111
|
+
`color: ${color !== null && color !== void 0 ? color : 'inherit'}; background: ${bgColor !== null && bgColor !== void 0 ? bgColor : 'inherit'};`,
|
|
112
|
+
'color: inherit; background: inherit;',
|
|
113
|
+
...argsRaw
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
// or for console
|
|
117
|
+
else {
|
|
118
|
+
formattedMessage = `[${context}] ${message}`;
|
|
119
|
+
args = argsRaw;
|
|
120
|
+
}
|
|
121
|
+
// log based on level
|
|
122
|
+
switch (level) {
|
|
123
|
+
case 'error':
|
|
124
|
+
console.error(formattedMessage, ...args);
|
|
125
|
+
break;
|
|
126
|
+
case 'warn':
|
|
127
|
+
console.warn(formattedMessage, ...args);
|
|
128
|
+
break;
|
|
129
|
+
case 'info':
|
|
130
|
+
console.log(formattedMessage, ...args);
|
|
131
|
+
break;
|
|
132
|
+
case 'debug':
|
|
133
|
+
console.debug(formattedMessage, ...args);
|
|
134
|
+
break;
|
|
135
|
+
case 'verbose':
|
|
136
|
+
console.debug(formattedMessage, ...args);
|
|
137
|
+
break;
|
|
138
|
+
case 'trace':
|
|
139
|
+
console.trace(formattedMessage, ...args);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.Logger = Logger;
|
|
145
|
+
Logger._loggers = new Map();
|
|
146
|
+
// namespace
|
|
147
|
+
(function (Logger) {
|
|
148
|
+
let Context;
|
|
149
|
+
(function (Context) {
|
|
150
|
+
// root
|
|
151
|
+
Context.root = '';
|
|
152
|
+
// delimiter
|
|
153
|
+
Context.delimiter = ':';
|
|
154
|
+
// helpers
|
|
155
|
+
})(Context = Logger.Context || (Logger.Context = {}));
|
|
156
|
+
let Level;
|
|
157
|
+
(function (Level) {
|
|
158
|
+
// values
|
|
159
|
+
Level.values = [
|
|
160
|
+
'trace', 'verbose', 'debug', 'info', 'warn', 'error'
|
|
161
|
+
];
|
|
162
|
+
// helpers
|
|
163
|
+
function compare(lhs, rhs) {
|
|
164
|
+
return lhs === rhs
|
|
165
|
+
? 0
|
|
166
|
+
: Level.values.indexOf(lhs) < Level.values.indexOf(rhs)
|
|
167
|
+
? -1
|
|
168
|
+
: 1;
|
|
169
|
+
}
|
|
170
|
+
Level.compare = compare;
|
|
171
|
+
function parse(value) {
|
|
172
|
+
const normalizedValue = value.trim().toLowerCase();
|
|
173
|
+
return Level.values.includes(normalizedValue)
|
|
174
|
+
? normalizedValue
|
|
175
|
+
: undefined;
|
|
176
|
+
}
|
|
177
|
+
Level.parse = parse;
|
|
178
|
+
})(Level = Logger.Level || (Logger.Level = {}));
|
|
179
|
+
let LevelOptions;
|
|
180
|
+
(function (LevelOptions) {
|
|
181
|
+
// helpers
|
|
182
|
+
function coerce(levelOrOptions) {
|
|
183
|
+
// skip if it's already options
|
|
184
|
+
if (filter(levelOrOptions)) {
|
|
185
|
+
return levelOrOptions;
|
|
186
|
+
}
|
|
187
|
+
// or use level as minimum options
|
|
188
|
+
else if (typeof levelOrOptions === 'string') {
|
|
189
|
+
return Level.values.reduce((options, level) => {
|
|
190
|
+
// enable option if at least min level
|
|
191
|
+
options[level] = Level.compare(level, levelOrOptions) >= 0;
|
|
192
|
+
// keep reducing
|
|
193
|
+
return options;
|
|
194
|
+
}, {});
|
|
195
|
+
}
|
|
196
|
+
// or use levels from array of items (presence indicates active)
|
|
197
|
+
else {
|
|
198
|
+
return fromLevels(levelOrOptions);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
LevelOptions.coerce = coerce;
|
|
202
|
+
function filter(levelOrOptions) {
|
|
203
|
+
return typeof levelOrOptions !== 'string' && !Array.isArray(levelOrOptions);
|
|
204
|
+
}
|
|
205
|
+
LevelOptions.filter = filter;
|
|
206
|
+
function fromLevels(levels) {
|
|
207
|
+
// create options for any items that are indicated
|
|
208
|
+
return Level.values.reduce((options, level) => {
|
|
209
|
+
// enable/disable based on capture
|
|
210
|
+
options[level] = levels.includes(level);
|
|
211
|
+
// keep reducing
|
|
212
|
+
return options;
|
|
213
|
+
}, {});
|
|
214
|
+
}
|
|
215
|
+
LevelOptions.fromLevels = fromLevels;
|
|
216
|
+
})(LevelOptions = Logger.LevelOptions || (Logger.LevelOptions = {}));
|
|
217
|
+
let Configuration;
|
|
218
|
+
(function (Configuration) {
|
|
219
|
+
// defaults
|
|
220
|
+
Configuration.defaults = {
|
|
221
|
+
levels: {
|
|
222
|
+
trace: false,
|
|
223
|
+
verbose: false,
|
|
224
|
+
debug: false,
|
|
225
|
+
info: false,
|
|
226
|
+
warn: true,
|
|
227
|
+
error: true
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
})(Configuration = Logger.Configuration || (Logger.Configuration = {}));
|
|
231
|
+
let Configurations;
|
|
232
|
+
(function (Configurations) {
|
|
233
|
+
// helpers
|
|
234
|
+
function parse({ root, contexts = {} }) {
|
|
235
|
+
// create configuration
|
|
236
|
+
const configurations = {};
|
|
237
|
+
// bind root
|
|
238
|
+
configurations[Context.root] = {
|
|
239
|
+
levels: root.levels ? LevelOptions.coerce(root.levels) : undefined,
|
|
240
|
+
color: root.color,
|
|
241
|
+
bgColor: root.bgColor
|
|
242
|
+
};
|
|
243
|
+
// bind contexts
|
|
244
|
+
Object.entries(contexts).forEach(([context, configuration]) => {
|
|
245
|
+
configurations[context] = {
|
|
246
|
+
levels: configuration.levels ? LevelOptions.coerce(configuration.levels) : undefined,
|
|
247
|
+
color: configuration.color,
|
|
248
|
+
bgColor: configuration.bgColor
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
// return configuration
|
|
252
|
+
return configurations;
|
|
253
|
+
}
|
|
254
|
+
Configurations.parse = parse;
|
|
255
|
+
})(Configurations = Logger.Configurations || (Logger.Configurations = {}));
|
|
256
|
+
})(Logger || (exports.Logger = Logger = {}));
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./EventBus"), exports);
|
|
18
17
|
__exportStar(require("./humanVerification"), exports);
|
|
19
18
|
__exportStar(require("./leadGen"), exports);
|
|
19
|
+
__exportStar(require("./EventBus"), exports);
|
|
20
|
+
__exportStar(require("./Logger"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nascentdigital/funnel-core",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "git+https://github.com/nascentdigital/funnel.git",
|
|
6
6
|
"directory": "libs/core"
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"jest-tsd": "^0.2.2",
|
|
66
66
|
"ts-jest": "^29.3.2"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "63e7e3fa90a0d490576311a388e8a0d99bd4b5e4"
|
|
69
69
|
}
|