slicejs-web-framework 3.3.6 → 3.3.8
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/.opencode/opencode.json +14 -14
- package/Slice/Components/Structural/ContextManager/ContextManager.js +420 -369
- package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +421 -420
- package/Slice/Components/Structural/Controller/Controller.js +1198 -1199
- package/Slice/Components/Structural/Debugger/Debugger.js +1504 -1497
- package/Slice/Components/Structural/EventManager/EventManager.js +334 -338
- package/Slice/Components/Structural/Logger/Logger.js +200 -145
- package/Slice/Components/Structural/Router/Router.js +775 -752
- package/Slice/Components/Structural/StylesManager/StylesManager.js +82 -78
- package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +106 -84
- package/Slice/Slice.js +618 -577
- package/Slice/tests/build-singleton.test.js +244 -221
- package/Slice/tests/bundle-v2-runtime-contract.test.js +738 -728
- package/Slice/tests/context-patch-use.test.js +95 -0
- package/Slice/tests/fixtures/real-runtime-loader.mjs +21 -19
- package/Slice/tests/public-env-typed-accessors.test.js +66 -0
- package/api/index.js +281 -286
- package/api/utils/publicEnvResolver.js +123 -117
- package/package.json +44 -44
|
@@ -1,145 +1,200 @@
|
|
|
1
|
-
import Log from './Log.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
*
|
|
112
|
-
* @param {
|
|
113
|
-
* @returns {
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
*
|
|
121
|
-
* @param {string}
|
|
122
|
-
* @
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
1
|
+
import Log from './Log.js';
|
|
2
|
+
|
|
3
|
+
const logTypes = {
|
|
4
|
+
ERROR: 'error',
|
|
5
|
+
WARN: 'warn',
|
|
6
|
+
INFO: 'info',
|
|
7
|
+
DEBUG: 'debug',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default class Logger {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.logs = [];
|
|
13
|
+
this.logEnabled = slice.loggerConfig.enabled;
|
|
14
|
+
this.showLogsConfig = slice.loggerConfig.showLogs;
|
|
15
|
+
|
|
16
|
+
this.showLog = function showLog(log) {
|
|
17
|
+
if (!this.showLogsConfig) return;
|
|
18
|
+
|
|
19
|
+
const logType = log.logType;
|
|
20
|
+
|
|
21
|
+
Object.keys(this.showLogsConfig).forEach((logConfig) => {
|
|
22
|
+
if (this.showLogsConfig[logConfig][logType] === true) {
|
|
23
|
+
switch (logConfig) {
|
|
24
|
+
case 'console':
|
|
25
|
+
switch (logType) {
|
|
26
|
+
case logTypes.ERROR:
|
|
27
|
+
console.error(
|
|
28
|
+
`\x1b[31mERROR\x1b[0m - ${log.componentCategory} - ${log.componentSliceId} - ${log.message}`,
|
|
29
|
+
log.error
|
|
30
|
+
);
|
|
31
|
+
break;
|
|
32
|
+
case logTypes.WARN:
|
|
33
|
+
if (log.error) {
|
|
34
|
+
console.warn(
|
|
35
|
+
`\x1b[33m⚠ WARN\x1b[0m - ${log.componentCategory} - ${log.componentSliceId} - ${log.message}`,
|
|
36
|
+
log.error
|
|
37
|
+
);
|
|
38
|
+
} else {
|
|
39
|
+
console.warn(
|
|
40
|
+
`\x1b[33m⚠ WARN\x1b[0m - ${log.componentCategory} - ${log.componentSliceId} - ${log.message}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
case logTypes.INFO:
|
|
45
|
+
if (log.error) {
|
|
46
|
+
console.log(
|
|
47
|
+
`\x1b[32m✔ INFO\x1b[0m - ${log.componentCategory} - ${log.componentSliceId} - ${log.message}`,
|
|
48
|
+
log.error
|
|
49
|
+
);
|
|
50
|
+
} else {
|
|
51
|
+
console.log(
|
|
52
|
+
`\x1b[32m✔ INFO\x1b[0m - ${log.componentCategory} - ${log.componentSliceId} - ${log.message}`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case logTypes.DEBUG:
|
|
57
|
+
if (log.error) {
|
|
58
|
+
console.debug(
|
|
59
|
+
`\x1b[36m🔍 DEBUG\x1b[0m - ${log.componentCategory} - ${log.componentSliceId} - ${log.message}`,
|
|
60
|
+
log.error
|
|
61
|
+
);
|
|
62
|
+
} else {
|
|
63
|
+
console.debug(
|
|
64
|
+
`\x1b[36m🔍 DEBUG\x1b[0m - ${log.componentCategory} - ${log.componentSliceId} - ${log.message}`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
console.log(
|
|
70
|
+
`\x1b[37mUNKNOWN\x1b[0m - ${log.componentCategory} - ${log.componentSliceId} - ${log.message}`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
createLog(logType, componentSliceId, message, error = null) {
|
|
81
|
+
if (!this.logEnabled) return;
|
|
82
|
+
let componentName;
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
componentName = slice.controller.activeComponents.get(componentSliceId).constructor.name;
|
|
86
|
+
} catch (_err) {
|
|
87
|
+
componentName = componentSliceId;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let componentCategory = slice.controller.getComponentCategory(componentName);
|
|
91
|
+
if (componentSliceId === 'Slice' || componentSliceId === 'ThemeManager') componentCategory = 'Structural';
|
|
92
|
+
const log = new Log(logType, componentCategory, componentSliceId, message, error);
|
|
93
|
+
this.logs.push(log);
|
|
94
|
+
this.showLog(log);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Log an error message.
|
|
99
|
+
* @param {string} componentSliceId
|
|
100
|
+
* @param {string} message
|
|
101
|
+
* @param {any} [error]
|
|
102
|
+
* @returns {void}
|
|
103
|
+
*/
|
|
104
|
+
error(componentSliceId, message, error) {
|
|
105
|
+
this.createLog(logTypes.ERROR, componentSliceId, message, error);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Log a warning message.
|
|
110
|
+
* @param {string} componentSliceId
|
|
111
|
+
* @param {string} message
|
|
112
|
+
* @param {any} [error]
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
115
|
+
warn(componentSliceId, message, error) {
|
|
116
|
+
this.createLog(logTypes.WARN, componentSliceId, message, error);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Log an info message.
|
|
121
|
+
* @param {string} componentSliceId
|
|
122
|
+
* @param {string} message
|
|
123
|
+
* @param {any} [error]
|
|
124
|
+
* @returns {void}
|
|
125
|
+
*/
|
|
126
|
+
info(componentSliceId, message, error) {
|
|
127
|
+
this.createLog(logTypes.INFO, componentSliceId, message, error);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Log a debug message.
|
|
132
|
+
* @param {string} componentSliceId
|
|
133
|
+
* @param {string} message
|
|
134
|
+
* @param {any} [error]
|
|
135
|
+
* @returns {void}
|
|
136
|
+
*/
|
|
137
|
+
debug(componentSliceId, message, error) {
|
|
138
|
+
this.createLog(logTypes.DEBUG, componentSliceId, message, error);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ── Retrocompatibilidad: métodos antiguos redirigen a los nuevos ──
|
|
142
|
+
|
|
143
|
+
/** @deprecated Use .error() instead */
|
|
144
|
+
logError(componentSliceId, message, error) {
|
|
145
|
+
this.error(componentSliceId, message, error);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** @deprecated Use .warn() instead */
|
|
149
|
+
logWarning(componentSliceId, message, error) {
|
|
150
|
+
this.warn(componentSliceId, message, error);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** @deprecated Use .info() instead */
|
|
154
|
+
logInfo(componentSliceId, message, error) {
|
|
155
|
+
this.info(componentSliceId, message, error);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Get all logs.
|
|
160
|
+
* @returns {Array}
|
|
161
|
+
*/
|
|
162
|
+
getLogs() {
|
|
163
|
+
return this.logs;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Clear all logs.
|
|
168
|
+
* @returns {void}
|
|
169
|
+
*/
|
|
170
|
+
clearLogs() {
|
|
171
|
+
this.logs = [];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Filter logs by type.
|
|
176
|
+
* @param {string} type
|
|
177
|
+
* @returns {Array}
|
|
178
|
+
*/
|
|
179
|
+
getLogsByLogType(type) {
|
|
180
|
+
return this.logs.filter((log) => log.logType === type);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Filter logs by component category.
|
|
185
|
+
* @param {string} componentCategory
|
|
186
|
+
* @returns {Array}
|
|
187
|
+
*/
|
|
188
|
+
getLogsByComponentCategory(componentCategory) {
|
|
189
|
+
return this.logs.filter((log) => log.componentCategory === componentCategory);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Filter logs by component sliceId.
|
|
194
|
+
* @param {string} componentSliceId
|
|
195
|
+
* @returns {Array}
|
|
196
|
+
*/
|
|
197
|
+
getLogsByComponent(componentSliceId) {
|
|
198
|
+
return this.logs.filter((log) => log.componentSliceId === componentSliceId);
|
|
199
|
+
}
|
|
200
|
+
}
|