alepha 0.9.3 → 0.9.4
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/README.md +46 -0
- package/batch.d.ts +3 -6
- package/bucket.d.ts +7 -14
- package/cache/redis.d.ts +7 -7
- package/cache.d.ts +2 -6
- package/command.d.ts +11 -11
- package/core.d.ts +99 -254
- package/datetime.d.ts +3 -7
- package/file.d.ts +0 -3
- package/lock/redis.d.ts +2 -5
- package/lock.d.ts +8 -15
- package/logger.cjs +8 -0
- package/logger.d.ts +222 -0
- package/logger.js +1 -0
- package/package.json +50 -42
- package/postgres.d.ts +192 -271
- package/queue/redis.d.ts +0 -2
- package/queue.d.ts +11 -19
- package/react/auth.d.ts +217 -134
- package/react/form.d.ts +113 -72
- package/react/head.d.ts +7 -14
- package/react/i18n.d.ts +23 -28
- package/react.d.ts +274 -256
- package/redis.d.ts +12 -12
- package/retry.d.ts +0 -4
- package/router.d.ts +0 -1
- package/scheduler.d.ts +9 -13
- package/security.d.ts +68 -86
- package/server/cache.d.ts +3 -5
- package/server/compress.d.ts +0 -3
- package/server/cookies.d.ts +4 -7
- package/server/cors.d.ts +1 -5
- package/server/health.d.ts +0 -3
- package/server/helmet.d.ts +28 -28
- package/server/links.d.ts +144 -42
- package/server/metrics.d.ts +1 -5
- package/server/multipart.d.ts +0 -2
- package/server/proxy.d.ts +3 -7
- package/server/security.d.ts +6 -7
- package/server/static.d.ts +4 -8
- package/server/swagger.d.ts +2 -6
- package/server.d.ts +72 -96
- package/topic/redis.d.ts +3 -6
- package/topic.d.ts +5 -13
- package/vite.d.ts +5 -7
package/logger.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var m = require('@alepha/logger');
|
|
3
|
+
Object.keys(m).forEach(function (k) {
|
|
4
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: function () { return m[k]; }
|
|
7
|
+
});
|
|
8
|
+
});
|
package/logger.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import * as _alepha_core0 from "alepha";
|
|
2
|
+
import { Alepha, KIND, LogLevel, LoggerInterface, Static } from "alepha";
|
|
3
|
+
import * as _sinclair_typebox0 from "@sinclair/typebox";
|
|
4
|
+
|
|
5
|
+
//#region src/providers/LogDestinationProvider.d.ts
|
|
6
|
+
declare abstract class LogDestinationProvider {
|
|
7
|
+
abstract write(message: string, entry: LogEntry): void;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/providers/LogFormatterProvider.d.ts
|
|
11
|
+
declare abstract class LogFormatterProvider {
|
|
12
|
+
abstract format(entry: LogEntry): string;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/services/Logger.d.ts
|
|
16
|
+
declare class Logger implements LoggerInterface {
|
|
17
|
+
protected readonly alepha: Alepha;
|
|
18
|
+
protected readonly formatter: LogFormatterProvider;
|
|
19
|
+
protected readonly destination: LogDestinationProvider;
|
|
20
|
+
protected readonly levels: Record<string, number>;
|
|
21
|
+
protected readonly service: string;
|
|
22
|
+
protected readonly module: string;
|
|
23
|
+
protected readonly app?: string;
|
|
24
|
+
protected appLogLevel: string;
|
|
25
|
+
protected logLevel: LogLevel;
|
|
26
|
+
constructor(service: string, module: string);
|
|
27
|
+
get context(): string | undefined;
|
|
28
|
+
get level(): string;
|
|
29
|
+
parseLevel(level: string, app: string): LogLevel;
|
|
30
|
+
asLogLevel(something: string): LogLevel;
|
|
31
|
+
error(message: string, data?: unknown): void;
|
|
32
|
+
warn(message: string, data?: unknown): void;
|
|
33
|
+
info(message: string, data?: unknown): void;
|
|
34
|
+
debug(message: string, data?: unknown): void;
|
|
35
|
+
trace(message: string, data?: unknown): void;
|
|
36
|
+
protected log(level: LogLevel, message: string, data?: unknown): void;
|
|
37
|
+
}
|
|
38
|
+
interface LogEntry {
|
|
39
|
+
level: LogLevel;
|
|
40
|
+
message: string;
|
|
41
|
+
service: string;
|
|
42
|
+
module: string;
|
|
43
|
+
context?: string;
|
|
44
|
+
data?: object | Error | string;
|
|
45
|
+
app?: string;
|
|
46
|
+
timestamp: Date;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/descriptors/$logger.d.ts
|
|
50
|
+
/**
|
|
51
|
+
* Create a logger.
|
|
52
|
+
*
|
|
53
|
+
* `name` is optional, by default it will use the name of the service.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { $logger } from "alepha";
|
|
58
|
+
*
|
|
59
|
+
* class MyService {
|
|
60
|
+
* log = $logger();
|
|
61
|
+
*
|
|
62
|
+
* constructor() {
|
|
63
|
+
* // print something like '[23:45:53.326] INFO <app.App>: App is ready!'
|
|
64
|
+
* this.log.info("Service initialized");
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare const $logger: {
|
|
70
|
+
(options?: LoggerDescriptorOptions): Logger;
|
|
71
|
+
[KIND]: typeof Logger;
|
|
72
|
+
};
|
|
73
|
+
interface LoggerDescriptorOptions {
|
|
74
|
+
name?: string;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/providers/ConsoleColorProvider.d.ts
|
|
78
|
+
declare class ConsoleColorProvider {
|
|
79
|
+
protected env: {
|
|
80
|
+
NO_COLOR?: string | undefined;
|
|
81
|
+
FORCE_COLOR?: string | undefined;
|
|
82
|
+
};
|
|
83
|
+
readonly colors: {
|
|
84
|
+
reset: string;
|
|
85
|
+
grey: string;
|
|
86
|
+
red: string;
|
|
87
|
+
orange: string;
|
|
88
|
+
green: string;
|
|
89
|
+
blue: string;
|
|
90
|
+
white: string;
|
|
91
|
+
cyan: string;
|
|
92
|
+
darkGrey: string;
|
|
93
|
+
silent: string;
|
|
94
|
+
error: string;
|
|
95
|
+
warn: string;
|
|
96
|
+
info: string;
|
|
97
|
+
debug: string;
|
|
98
|
+
trace: string;
|
|
99
|
+
};
|
|
100
|
+
protected enabled: boolean;
|
|
101
|
+
constructor();
|
|
102
|
+
colorize(color: keyof typeof (void 0).colors, text: string, reset?: string): string;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/providers/ConsoleDestinationProvider.d.ts
|
|
106
|
+
declare class ConsoleDestinationProvider extends LogDestinationProvider {
|
|
107
|
+
write(message: string): void;
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/providers/JsonFormatterProvider.d.ts
|
|
111
|
+
declare class JsonFormatterProvider extends LogFormatterProvider {
|
|
112
|
+
format(entry: LogEntry): string;
|
|
113
|
+
protected formatJsonError(error: Error): object;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/providers/MemoryDestinationProvider.d.ts
|
|
117
|
+
declare class MemoryDestinationProvider extends LogDestinationProvider {
|
|
118
|
+
protected entries: Array<LogEntry & {
|
|
119
|
+
formatted: string;
|
|
120
|
+
}>;
|
|
121
|
+
readonly options: {
|
|
122
|
+
maxEntries: number;
|
|
123
|
+
};
|
|
124
|
+
write(formatted: string, entry: LogEntry): void;
|
|
125
|
+
get logs(): (LogEntry & {
|
|
126
|
+
formatted: string;
|
|
127
|
+
})[];
|
|
128
|
+
clear(): void;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/providers/SimpleFormatterProvider.d.ts
|
|
132
|
+
declare class SimpleFormatterProvider extends LogFormatterProvider {
|
|
133
|
+
protected color: ConsoleColorProvider;
|
|
134
|
+
format(entry: LogEntry): string;
|
|
135
|
+
formatTimestamp(d: Date): string;
|
|
136
|
+
protected pad2: (n: number) => string;
|
|
137
|
+
protected pad3: (n: number) => string;
|
|
138
|
+
protected formatError(error: Error): string;
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/index.d.ts
|
|
142
|
+
declare const envSchema: _alepha_core0.TObject<{
|
|
143
|
+
/**
|
|
144
|
+
* Default log level for the application.
|
|
145
|
+
*
|
|
146
|
+
* Default by environment:
|
|
147
|
+
* - dev = info
|
|
148
|
+
* - prod = info
|
|
149
|
+
* - test = error
|
|
150
|
+
*
|
|
151
|
+
* Levels are: "trace" | "debug" | "info" | "warn" | "error" | "silent"
|
|
152
|
+
*
|
|
153
|
+
* Level can be set for a specific module:
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* LOG_LEVEL=my.module.name:debug,info # Set debug level for my.module.name and info for all other modules
|
|
157
|
+
* LOG_LEVEL=alepha:trace, info # Set trace level for all alepha modules and info for all other modules
|
|
158
|
+
*/
|
|
159
|
+
LOG_LEVEL: _alepha_core0.TOptional<_alepha_core0.TString>;
|
|
160
|
+
/**
|
|
161
|
+
* Built-in log formats.
|
|
162
|
+
* - "json" - JSON format, useful for structured logging and log aggregation. {@link JsonFormatterProvider}
|
|
163
|
+
* - "text" - Simple text format, human-readable, with colors. {@link SimpleFormatterProvider}
|
|
164
|
+
* - "raw" - Raw format, no formatting, just the message. {@link RawFormatterProvider}
|
|
165
|
+
*/
|
|
166
|
+
LOG_FORMAT: _alepha_core0.TOptional<_sinclair_typebox0.TUnsafe<"json" | "text" | "raw">>;
|
|
167
|
+
}>;
|
|
168
|
+
declare module "alepha" {
|
|
169
|
+
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
170
|
+
interface State {
|
|
171
|
+
logLevel?: string;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Minimalist logger module for Alepha.
|
|
176
|
+
*
|
|
177
|
+
* It offers a global logger interface (info, warn, ...) via the `$logger` descriptor.
|
|
178
|
+
*
|
|
179
|
+
* ```ts
|
|
180
|
+
* import { $logger } from "alepha/logger";
|
|
181
|
+
*
|
|
182
|
+
* class App {
|
|
183
|
+
* log = $logger();
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* ### Formatting and Destinations
|
|
188
|
+
*
|
|
189
|
+
* `AlephaLogger` is **extensible**, destinations and formatters can be added or replaced.
|
|
190
|
+
*
|
|
191
|
+
* Default log destinations are:
|
|
192
|
+
* - ConsoleDestinationProvider: logs to the console.
|
|
193
|
+
* - MemoryDestinationProvider: stores logs in memory for later retrieval.
|
|
194
|
+
*
|
|
195
|
+
* Default log formatters are:
|
|
196
|
+
* - JsonFormatterProvider: formats logs as JSON.
|
|
197
|
+
* - SimpleFormatterProvider: formats logs as simple text (with colors when possible).
|
|
198
|
+
* - RawFormatterProvider: formats logs as raw text without any formatting.
|
|
199
|
+
*
|
|
200
|
+
* ### Log Level
|
|
201
|
+
*
|
|
202
|
+
* You can configure the log level and format via environment variables:
|
|
203
|
+
*
|
|
204
|
+
* - `LOG_LEVEL`: Sets the default log level for the application.
|
|
205
|
+
* - `LOG_FORMAT`: Sets the default log format for the application.
|
|
206
|
+
*
|
|
207
|
+
* ```bash
|
|
208
|
+
* LOG_LEVEL=debug LOG_FORMAT=json node src/index.ts
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* Log level is also available in the state as `logLevel`, which can be used to dynamically change the log level at runtime.
|
|
212
|
+
* ```ts
|
|
213
|
+
* alepha.state("logLevel", "debug");
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* Log level is $module aware, meaning you can set different log levels for different modules.
|
|
217
|
+
* For example, you can set `LOG_LEVEL=my.module.name:debug,info` to set the log level to debug for `my.module.name` and info for all other modules.
|
|
218
|
+
*/
|
|
219
|
+
declare const AlephaLogger: _alepha_core0.Service<_alepha_core0.Module>;
|
|
220
|
+
//#endregion
|
|
221
|
+
export { $logger, AlephaLogger, ConsoleColorProvider, ConsoleDestinationProvider, JsonFormatterProvider, LogDestinationProvider, LogEntry, LogFormatterProvider, Logger, LoggerDescriptorOptions, MemoryDestinationProvider, SimpleFormatterProvider };
|
|
222
|
+
//# sourceMappingURL=index.d.ts.map
|
package/logger.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@alepha/logger'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alepha",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0"
|
|
@@ -15,49 +15,51 @@
|
|
|
15
15
|
"main": "./core.js",
|
|
16
16
|
"types": "./core.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@alepha/batch": "0.9.
|
|
19
|
-
"@alepha/bucket": "0.9.
|
|
20
|
-
"@alepha/cache": "0.9.
|
|
21
|
-
"@alepha/cache-redis": "0.9.
|
|
22
|
-
"@alepha/command": "0.9.
|
|
23
|
-
"@alepha/core": "0.9.
|
|
24
|
-
"@alepha/datetime": "0.9.
|
|
25
|
-
"@alepha/file": "0.9.
|
|
26
|
-
"@alepha/lock": "0.9.
|
|
27
|
-
"@alepha/lock-redis": "0.9.
|
|
28
|
-
"@alepha/
|
|
29
|
-
"@alepha/
|
|
30
|
-
"@alepha/queue
|
|
31
|
-
"@alepha/
|
|
32
|
-
"@alepha/react
|
|
33
|
-
"@alepha/react-
|
|
34
|
-
"@alepha/react-
|
|
35
|
-
"@alepha/react-
|
|
36
|
-
"@alepha/
|
|
37
|
-
"@alepha/
|
|
38
|
-
"@alepha/
|
|
39
|
-
"@alepha/
|
|
40
|
-
"@alepha/
|
|
41
|
-
"@alepha/
|
|
42
|
-
"@alepha/server
|
|
43
|
-
"@alepha/server-
|
|
44
|
-
"@alepha/server-
|
|
45
|
-
"@alepha/server-
|
|
46
|
-
"@alepha/server-
|
|
47
|
-
"@alepha/server-
|
|
48
|
-
"@alepha/server-
|
|
49
|
-
"@alepha/server-
|
|
50
|
-
"@alepha/server-
|
|
51
|
-
"@alepha/server-
|
|
52
|
-
"@alepha/server-
|
|
53
|
-
"@alepha/server-
|
|
54
|
-
"@alepha/server-
|
|
55
|
-
"@alepha/
|
|
56
|
-
"@alepha/topic
|
|
57
|
-
"@alepha/
|
|
18
|
+
"@alepha/batch": "0.9.4",
|
|
19
|
+
"@alepha/bucket": "0.9.4",
|
|
20
|
+
"@alepha/cache": "0.9.4",
|
|
21
|
+
"@alepha/cache-redis": "0.9.4",
|
|
22
|
+
"@alepha/command": "0.9.4",
|
|
23
|
+
"@alepha/core": "0.9.4",
|
|
24
|
+
"@alepha/datetime": "0.9.4",
|
|
25
|
+
"@alepha/file": "0.9.4",
|
|
26
|
+
"@alepha/lock": "0.9.4",
|
|
27
|
+
"@alepha/lock-redis": "0.9.4",
|
|
28
|
+
"@alepha/logger": "0.9.4",
|
|
29
|
+
"@alepha/postgres": "0.9.4",
|
|
30
|
+
"@alepha/queue": "0.9.4",
|
|
31
|
+
"@alepha/queue-redis": "0.9.4",
|
|
32
|
+
"@alepha/react": "0.9.4",
|
|
33
|
+
"@alepha/react-auth": "0.9.4",
|
|
34
|
+
"@alepha/react-form": "0.9.4",
|
|
35
|
+
"@alepha/react-head": "0.9.4",
|
|
36
|
+
"@alepha/react-i18n": "0.9.4",
|
|
37
|
+
"@alepha/redis": "0.9.4",
|
|
38
|
+
"@alepha/retry": "0.9.4",
|
|
39
|
+
"@alepha/router": "0.9.4",
|
|
40
|
+
"@alepha/scheduler": "0.9.4",
|
|
41
|
+
"@alepha/security": "0.9.4",
|
|
42
|
+
"@alepha/server": "0.9.4",
|
|
43
|
+
"@alepha/server-cache": "0.9.4",
|
|
44
|
+
"@alepha/server-compress": "0.9.4",
|
|
45
|
+
"@alepha/server-cookies": "0.9.4",
|
|
46
|
+
"@alepha/server-cors": "0.9.4",
|
|
47
|
+
"@alepha/server-health": "0.9.4",
|
|
48
|
+
"@alepha/server-helmet": "0.9.4",
|
|
49
|
+
"@alepha/server-links": "0.9.4",
|
|
50
|
+
"@alepha/server-metrics": "0.9.4",
|
|
51
|
+
"@alepha/server-multipart": "0.9.4",
|
|
52
|
+
"@alepha/server-proxy": "0.9.4",
|
|
53
|
+
"@alepha/server-security": "0.9.4",
|
|
54
|
+
"@alepha/server-static": "0.9.4",
|
|
55
|
+
"@alepha/server-swagger": "0.9.4",
|
|
56
|
+
"@alepha/topic": "0.9.4",
|
|
57
|
+
"@alepha/topic-redis": "0.9.4",
|
|
58
|
+
"@alepha/vite": "0.9.4",
|
|
59
|
+
"react": "^19.1.1"
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
60
|
-
"tsdown": "^0.
|
|
62
|
+
"tsdown": "^0.14.1"
|
|
61
63
|
},
|
|
62
64
|
"scripts": {
|
|
63
65
|
"build": "node build.ts"
|
|
@@ -123,6 +125,11 @@
|
|
|
123
125
|
"require": "./lock/redis.cjs",
|
|
124
126
|
"types": "./lock/redis.d.ts"
|
|
125
127
|
},
|
|
128
|
+
"./logger": {
|
|
129
|
+
"import": "./logger.js",
|
|
130
|
+
"require": "./logger.cjs",
|
|
131
|
+
"types": "./logger.d.ts"
|
|
132
|
+
},
|
|
126
133
|
"./postgres": {
|
|
127
134
|
"import": "./postgres.js",
|
|
128
135
|
"require": "./postgres.cjs",
|
|
@@ -286,6 +293,7 @@
|
|
|
286
293
|
"file",
|
|
287
294
|
"lock",
|
|
288
295
|
"lock-redis",
|
|
296
|
+
"logger",
|
|
289
297
|
"postgres",
|
|
290
298
|
"queue",
|
|
291
299
|
"queue-redis",
|