@little-nebulae/log 0.0.0-stage → 0.1.0
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/LICENSE.txt +21 -0
- package/README.md +2 -2
- package/dist/index.d.ts +213 -0
- package/dist/index.js +73 -0
- package/package.json +57 -3
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ryan Luong
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Little Nebula template
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Little Nebulae's library template
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Tagged } from "type-fest";
|
|
3
|
+
//#region src/constants.d.ts
|
|
4
|
+
export declare const LOG_LEVEL: {
|
|
5
|
+
readonly INFO: "info";
|
|
6
|
+
readonly WARN: "warn";
|
|
7
|
+
readonly ERROR: "error";
|
|
8
|
+
readonly FATAL: "fatal";
|
|
9
|
+
};
|
|
10
|
+
export declare const LOG_LEVELS: readonly ["info", "warn", "error", "fatal"];
|
|
11
|
+
export declare const DEFAULT_MINIMUM_LOG_LEVEL: {
|
|
12
|
+
readonly DEVELOPMENT: "info";
|
|
13
|
+
readonly PRODUCTION: "warn";
|
|
14
|
+
};
|
|
15
|
+
export declare const DEFAULT_LOG_DIR_NAME: {
|
|
16
|
+
readonly ROOT: "logs";
|
|
17
|
+
readonly MAIN: "main-thread";
|
|
18
|
+
readonly WORKER: "worker-threads";
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/schemas/operation.d.ts
|
|
22
|
+
export type OperationId = Tagged<string, "OperationId">;
|
|
23
|
+
export declare const OperationIdSchema: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
24
|
+
export declare const OperationPerformanceSchema: z.ZodObject<{
|
|
25
|
+
start: z.ZodInt;
|
|
26
|
+
end: z.ZodInt;
|
|
27
|
+
duration: z.ZodInt;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
export type OperationPerformance = z.infer<typeof OperationPerformanceSchema>;
|
|
30
|
+
export declare const OperationSchema: z.ZodObject<{
|
|
31
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
32
|
+
name: z.ZodString;
|
|
33
|
+
source: z.ZodString;
|
|
34
|
+
success: z.ZodBoolean;
|
|
35
|
+
input: z.ZodUnknown;
|
|
36
|
+
output: z.ZodUnknown;
|
|
37
|
+
performance: z.ZodObject<{
|
|
38
|
+
start: z.ZodInt;
|
|
39
|
+
end: z.ZodInt;
|
|
40
|
+
duration: z.ZodInt;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
export type Operation = z.infer<typeof OperationSchema>;
|
|
44
|
+
export declare const ConcurrentOperationsSchema: z.ZodObject<{
|
|
45
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
46
|
+
name: z.ZodString;
|
|
47
|
+
source: z.ZodString;
|
|
48
|
+
success: z.ZodBoolean;
|
|
49
|
+
input: z.ZodUnknown;
|
|
50
|
+
output: z.ZodUnknown;
|
|
51
|
+
performance: z.ZodObject<{
|
|
52
|
+
start: z.ZodInt;
|
|
53
|
+
end: z.ZodInt;
|
|
54
|
+
duration: z.ZodInt;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
operations: z.ZodArray<z.ZodObject<{
|
|
57
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
58
|
+
name: z.ZodString;
|
|
59
|
+
source: z.ZodString;
|
|
60
|
+
success: z.ZodBoolean;
|
|
61
|
+
input: z.ZodUnknown;
|
|
62
|
+
output: z.ZodUnknown;
|
|
63
|
+
performance: z.ZodObject<{
|
|
64
|
+
start: z.ZodInt;
|
|
65
|
+
end: z.ZodInt;
|
|
66
|
+
duration: z.ZodInt;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
}, z.core.$strip>>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
export type ConcurrentOperations = z.infer<typeof ConcurrentOperationsSchema>;
|
|
71
|
+
export declare const SequentialOperationsSchema: z.ZodObject<{
|
|
72
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
73
|
+
name: z.ZodString;
|
|
74
|
+
source: z.ZodString;
|
|
75
|
+
success: z.ZodBoolean;
|
|
76
|
+
input: z.ZodUnknown;
|
|
77
|
+
output: z.ZodUnknown;
|
|
78
|
+
performance: z.ZodObject<{
|
|
79
|
+
start: z.ZodInt;
|
|
80
|
+
end: z.ZodInt;
|
|
81
|
+
duration: z.ZodInt;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
operations: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
84
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
85
|
+
name: z.ZodString;
|
|
86
|
+
source: z.ZodString;
|
|
87
|
+
success: z.ZodBoolean;
|
|
88
|
+
input: z.ZodUnknown;
|
|
89
|
+
output: z.ZodUnknown;
|
|
90
|
+
performance: z.ZodObject<{
|
|
91
|
+
start: z.ZodInt;
|
|
92
|
+
end: z.ZodInt;
|
|
93
|
+
duration: z.ZodInt;
|
|
94
|
+
}, z.core.$strip>;
|
|
95
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
96
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
97
|
+
name: z.ZodString;
|
|
98
|
+
source: z.ZodString;
|
|
99
|
+
success: z.ZodBoolean;
|
|
100
|
+
input: z.ZodUnknown;
|
|
101
|
+
output: z.ZodUnknown;
|
|
102
|
+
performance: z.ZodObject<{
|
|
103
|
+
start: z.ZodInt;
|
|
104
|
+
end: z.ZodInt;
|
|
105
|
+
duration: z.ZodInt;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
operations: z.ZodArray<z.ZodObject<{
|
|
108
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
109
|
+
name: z.ZodString;
|
|
110
|
+
source: z.ZodString;
|
|
111
|
+
success: z.ZodBoolean;
|
|
112
|
+
input: z.ZodUnknown;
|
|
113
|
+
output: z.ZodUnknown;
|
|
114
|
+
performance: z.ZodObject<{
|
|
115
|
+
start: z.ZodInt;
|
|
116
|
+
end: z.ZodInt;
|
|
117
|
+
duration: z.ZodInt;
|
|
118
|
+
}, z.core.$strip>;
|
|
119
|
+
}, z.core.$strip>>;
|
|
120
|
+
}, z.core.$strip>]>>;
|
|
121
|
+
}, z.core.$strip>;
|
|
122
|
+
export type SequentialOperations = z.infer<typeof SequentialOperationsSchema>;
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/schemas/log.d.ts
|
|
125
|
+
export type LogId = Tagged<OperationId, "LogId">;
|
|
126
|
+
export declare const LogIdSchema: z.ZodPipe<z.ZodUUID, z.ZodTransform<LogId, string>>;
|
|
127
|
+
export declare const LogLevelSchema: z.ZodEnum<{
|
|
128
|
+
error: "error";
|
|
129
|
+
fatal: "fatal";
|
|
130
|
+
info: "info";
|
|
131
|
+
warn: "warn";
|
|
132
|
+
}>;
|
|
133
|
+
export type LogLevel = z.infer<typeof LogLevelSchema>;
|
|
134
|
+
export declare const LogContextSchema: z.ZodObject<{
|
|
135
|
+
who: z.ZodString;
|
|
136
|
+
didWhat: z.ZodString;
|
|
137
|
+
inWhere: z.ZodExactOptional<z.ZodString>;
|
|
138
|
+
atWhen: z.ZodDate;
|
|
139
|
+
}, z.core.$strip>;
|
|
140
|
+
export type LogContext = z.infer<typeof LogContextSchema>;
|
|
141
|
+
export declare const LogSchema: z.ZodObject<{
|
|
142
|
+
name: z.ZodString;
|
|
143
|
+
source: z.ZodString;
|
|
144
|
+
success: z.ZodBoolean;
|
|
145
|
+
input: z.ZodUnknown;
|
|
146
|
+
output: z.ZodUnknown;
|
|
147
|
+
performance: z.ZodObject<{
|
|
148
|
+
start: z.ZodInt;
|
|
149
|
+
end: z.ZodInt;
|
|
150
|
+
duration: z.ZodInt;
|
|
151
|
+
}, z.core.$strip>;
|
|
152
|
+
operations: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
153
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
154
|
+
name: z.ZodString;
|
|
155
|
+
source: z.ZodString;
|
|
156
|
+
success: z.ZodBoolean;
|
|
157
|
+
input: z.ZodUnknown;
|
|
158
|
+
output: z.ZodUnknown;
|
|
159
|
+
performance: z.ZodObject<{
|
|
160
|
+
start: z.ZodInt;
|
|
161
|
+
end: z.ZodInt;
|
|
162
|
+
duration: z.ZodInt;
|
|
163
|
+
}, z.core.$strip>;
|
|
164
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
165
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
166
|
+
name: z.ZodString;
|
|
167
|
+
source: z.ZodString;
|
|
168
|
+
success: z.ZodBoolean;
|
|
169
|
+
input: z.ZodUnknown;
|
|
170
|
+
output: z.ZodUnknown;
|
|
171
|
+
performance: z.ZodObject<{
|
|
172
|
+
start: z.ZodInt;
|
|
173
|
+
end: z.ZodInt;
|
|
174
|
+
duration: z.ZodInt;
|
|
175
|
+
}, z.core.$strip>;
|
|
176
|
+
operations: z.ZodArray<z.ZodObject<{
|
|
177
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
|
|
178
|
+
name: z.ZodString;
|
|
179
|
+
source: z.ZodString;
|
|
180
|
+
success: z.ZodBoolean;
|
|
181
|
+
input: z.ZodUnknown;
|
|
182
|
+
output: z.ZodUnknown;
|
|
183
|
+
performance: z.ZodObject<{
|
|
184
|
+
start: z.ZodInt;
|
|
185
|
+
end: z.ZodInt;
|
|
186
|
+
duration: z.ZodInt;
|
|
187
|
+
}, z.core.$strip>;
|
|
188
|
+
}, z.core.$strip>>;
|
|
189
|
+
}, z.core.$strip>]>>;
|
|
190
|
+
id: z.ZodPipe<z.ZodUUID, z.ZodTransform<LogId, string>>;
|
|
191
|
+
level: z.ZodEnum<{
|
|
192
|
+
error: "error";
|
|
193
|
+
fatal: "fatal";
|
|
194
|
+
info: "info";
|
|
195
|
+
warn: "warn";
|
|
196
|
+
}>;
|
|
197
|
+
context: z.ZodObject<{
|
|
198
|
+
who: z.ZodString;
|
|
199
|
+
didWhat: z.ZodString;
|
|
200
|
+
inWhere: z.ZodExactOptional<z.ZodString>;
|
|
201
|
+
atWhen: z.ZodDate;
|
|
202
|
+
}, z.core.$strip>;
|
|
203
|
+
message: z.ZodString;
|
|
204
|
+
}, z.core.$strip>;
|
|
205
|
+
export type Log = z.infer<typeof LogSchema>;
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/utils.d.ts
|
|
208
|
+
interface ComposeLogMessageParams extends LogContext {
|
|
209
|
+
level: LogLevel;
|
|
210
|
+
}
|
|
211
|
+
export declare function composeLogMessage({ level, who, didWhat, inWhere, atWhen }: ComposeLogMessageParams): string;
|
|
212
|
+
//#endregion
|
|
213
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { NonEmptyStringSchema, PositiveIntegerSchema } from "@little-nebulae/zod";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/constants.ts
|
|
4
|
+
const LOG_LEVEL = {
|
|
5
|
+
INFO: "info",
|
|
6
|
+
WARN: "warn",
|
|
7
|
+
ERROR: "error",
|
|
8
|
+
FATAL: "fatal"
|
|
9
|
+
};
|
|
10
|
+
const LOG_LEVELS = [
|
|
11
|
+
LOG_LEVEL.INFO,
|
|
12
|
+
LOG_LEVEL.WARN,
|
|
13
|
+
LOG_LEVEL.ERROR,
|
|
14
|
+
LOG_LEVEL.FATAL
|
|
15
|
+
];
|
|
16
|
+
const DEFAULT_MINIMUM_LOG_LEVEL = {
|
|
17
|
+
DEVELOPMENT: LOG_LEVEL.INFO,
|
|
18
|
+
PRODUCTION: LOG_LEVEL.WARN
|
|
19
|
+
};
|
|
20
|
+
const DEFAULT_LOG_DIR_NAME = {
|
|
21
|
+
ROOT: "logs",
|
|
22
|
+
MAIN: "main-thread",
|
|
23
|
+
WORKER: "worker-threads"
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/utils.ts
|
|
27
|
+
function composeLogMessage({ level, who, didWhat, inWhere, atWhen }) {
|
|
28
|
+
return `[${level.toUpperCase()}] ${who} ${didWhat}${inWhere ? " " + inWhere : ""} ${atWhen.toISOString()}.`;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/schemas/operation.ts
|
|
32
|
+
const OperationIdSchema = z.uuidv7().transform((id) => id);
|
|
33
|
+
const OperationPerformanceSchema = z.object({
|
|
34
|
+
start: PositiveIntegerSchema,
|
|
35
|
+
end: PositiveIntegerSchema,
|
|
36
|
+
duration: PositiveIntegerSchema
|
|
37
|
+
}).refine(({ start, end }) => end > start);
|
|
38
|
+
const OperationSchema = z.object({
|
|
39
|
+
id: OperationIdSchema,
|
|
40
|
+
name: NonEmptyStringSchema,
|
|
41
|
+
source: NonEmptyStringSchema,
|
|
42
|
+
success: z.boolean(),
|
|
43
|
+
input: z.unknown(),
|
|
44
|
+
output: z.unknown(),
|
|
45
|
+
performance: OperationPerformanceSchema
|
|
46
|
+
});
|
|
47
|
+
const ConcurrentOperationsSchema = z.object({
|
|
48
|
+
...OperationSchema.shape,
|
|
49
|
+
operations: z.array(OperationSchema)
|
|
50
|
+
});
|
|
51
|
+
const SequentialOperationsSchema = z.object({
|
|
52
|
+
...OperationSchema.shape,
|
|
53
|
+
operations: z.array(z.union([OperationSchema, ConcurrentOperationsSchema]))
|
|
54
|
+
});
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/schemas/log.ts
|
|
57
|
+
const LogIdSchema = z.uuidv7().transform((id) => id);
|
|
58
|
+
const LogLevelSchema = z.enum(LOG_LEVELS);
|
|
59
|
+
const LogContextSchema = z.object({
|
|
60
|
+
who: NonEmptyStringSchema,
|
|
61
|
+
didWhat: NonEmptyStringSchema,
|
|
62
|
+
inWhere: NonEmptyStringSchema.exactOptional(),
|
|
63
|
+
atWhen: z.date()
|
|
64
|
+
});
|
|
65
|
+
const LogSchema = z.object({
|
|
66
|
+
...SequentialOperationsSchema.shape,
|
|
67
|
+
id: LogIdSchema,
|
|
68
|
+
level: LogLevelSchema,
|
|
69
|
+
context: LogContextSchema,
|
|
70
|
+
message: NonEmptyStringSchema
|
|
71
|
+
});
|
|
72
|
+
//#endregion
|
|
73
|
+
export { ConcurrentOperationsSchema, DEFAULT_LOG_DIR_NAME, DEFAULT_MINIMUM_LOG_LEVEL, LOG_LEVEL, LOG_LEVELS, LogContextSchema, LogIdSchema, LogLevelSchema, LogSchema, OperationIdSchema, OperationPerformanceSchema, OperationSchema, SequentialOperationsSchema, composeLogMessage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@little-nebulae/log",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.js",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"tag": "latest"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@arethetypeswrong/core": "0.18.5",
|
|
20
|
+
"@little-nebulae/error": "1.4.0",
|
|
21
|
+
"@little-nebulae/result": "1.4.0",
|
|
22
|
+
"@little-nebulae/zod": "0.5.0",
|
|
23
|
+
"@oxc-node/cli": "0.1.7",
|
|
24
|
+
"@types/node": "26.6.5",
|
|
25
|
+
"oxfmt": "0.73.0",
|
|
26
|
+
"oxlint": "1.88.0",
|
|
27
|
+
"oxlint-tsgolint": "7.0.2004",
|
|
28
|
+
"publint": "0.3.25",
|
|
29
|
+
"tsdown": "0.23.1",
|
|
30
|
+
"type-fest": "5.10.0",
|
|
31
|
+
"typescript": "7.0.2",
|
|
32
|
+
"vitest": "5.0.4",
|
|
33
|
+
"zod": "4.6.7"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@little-nebulae/error": "^1.0.0",
|
|
37
|
+
"@little-nebulae/result": "^1.0.0",
|
|
38
|
+
"@little-nebulae/zod": "0",
|
|
39
|
+
"type-fest": "^5.0.0",
|
|
40
|
+
"zod": "^4.0.0"
|
|
41
|
+
},
|
|
42
|
+
"devEngines": {
|
|
43
|
+
"packageManager": {
|
|
44
|
+
"name": "pnpm",
|
|
45
|
+
"version": "12.11.2",
|
|
46
|
+
"onFail": "warn"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsdown",
|
|
51
|
+
"fmt": "oxfmt --disable-nested-config",
|
|
52
|
+
"fmt:check": "oxfmt --check --disable-nested-config",
|
|
53
|
+
"lint": "oxlint --disable-nested-config",
|
|
54
|
+
"lint:fix": "oxlint --fix --disable-nested-config",
|
|
55
|
+
"check": "pnpm run lint && pnpm run fmt:check",
|
|
56
|
+
"fix": "pnpm run lint:fix && pnpm run fmt",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"try": "oxnode src/try.ts"
|
|
59
|
+
}
|
|
6
60
|
}
|