@little-nebulae/log 0.0.0-stage → 0.2.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 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
- # Temporary Holding Version
1
+ # Little Nebula template
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Little Nebulae's library template
@@ -0,0 +1,143 @@
1
+ import { z } from "zod";
2
+ import { Tagged } from "type-fest";
3
+ export declare const LOG_LEVEL: {
4
+ readonly INFO: "info";
5
+ readonly WARN: "warn";
6
+ readonly ERROR: "error";
7
+ readonly FATAL: "fatal";
8
+ };
9
+ export declare const LOG_LEVELS: readonly ["info", "warn", "error", "fatal"];
10
+ export declare const DEFAULT_MINIMUM_LOG_LEVEL: {
11
+ readonly DEVELOPMENT: "info";
12
+ readonly PRODUCTION: "warn";
13
+ };
14
+ export declare const DEFAULT_LOG_DIR_NAME: {
15
+ readonly ROOT: "logs";
16
+ readonly MAIN: "main-thread";
17
+ readonly WORKER: "worker-threads";
18
+ };
19
+ export type OperationId = Tagged<string, "OperationId">;
20
+ export declare const OperationIdSchema: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
21
+ export declare function createOperationSchema<Name extends string, InputSchema extends z.ZodType, OutputSchema extends z.ZodType>({ name, inputSchema, outputSchema }: {
22
+ name: Name;
23
+ inputSchema: InputSchema;
24
+ outputSchema: OutputSchema;
25
+ }): z.ZodObject<{
26
+ id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
27
+ name: z.ZodLiteral<Name>;
28
+ source: z.ZodString;
29
+ success: z.ZodBoolean;
30
+ input: InputSchema;
31
+ output: OutputSchema;
32
+ performance: z.ZodObject<{
33
+ start: z.ZodInt;
34
+ end: z.ZodInt;
35
+ duration: z.ZodInt;
36
+ }, z.core.$strip>;
37
+ }, z.core.$strip>;
38
+ export type OperationSchemaType = ReturnType<typeof createOperationSchema>;
39
+ export declare const OperationPerformanceSchema: z.ZodObject<{
40
+ start: z.ZodInt;
41
+ end: z.ZodInt;
42
+ duration: z.ZodInt;
43
+ }, z.core.$strip>;
44
+ export type OperationPerformance = z.infer<typeof OperationPerformanceSchema>;
45
+ export declare function createConcurrentOperationsSchema<Name extends string, InputSchema extends z.ZodType, OutputSchema extends z.ZodType, OperationsSchema extends z.ZodTuple<readonly [OperationSchemaType, ...OperationSchemaType[]]>>({ name, inputSchema, outputSchema, operationsSchema }: {
46
+ name: Name;
47
+ inputSchema: InputSchema;
48
+ outputSchema: OutputSchema;
49
+ operationsSchema: OperationsSchema;
50
+ }): z.ZodObject<{
51
+ id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
52
+ name: z.ZodLiteral<Name>;
53
+ source: z.ZodString;
54
+ success: z.ZodBoolean;
55
+ input: InputSchema;
56
+ output: OutputSchema;
57
+ performance: z.ZodObject<{
58
+ start: z.ZodInt;
59
+ end: z.ZodInt;
60
+ duration: z.ZodInt;
61
+ }, z.core.$strip>;
62
+ operations: OperationsSchema;
63
+ }, z.core.$strip>;
64
+ export type ConcurrentOperationsSchemaType = ReturnType<typeof createConcurrentOperationsSchema>;
65
+ export type SequentialOperationsTuple = z.ZodTuple<readonly [OperationSchemaType | ConcurrentOperationsSchemaType, ...(OperationSchemaType | ConcurrentOperationsSchemaType)[]]>;
66
+ export declare function createSequentialOperationsSchema<Name extends string, InputSchema extends z.ZodType, OutputSchema extends z.ZodType, OperationsSchema extends SequentialOperationsTuple>({ name, inputSchema, outputSchema, operationsSchema }: {
67
+ name: Name;
68
+ inputSchema: InputSchema;
69
+ outputSchema: OutputSchema;
70
+ operationsSchema: OperationsSchema;
71
+ }): z.ZodObject<{
72
+ id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
73
+ name: z.ZodLiteral<Name>;
74
+ source: z.ZodString;
75
+ success: z.ZodBoolean;
76
+ input: InputSchema;
77
+ output: OutputSchema;
78
+ performance: z.ZodObject<{
79
+ start: z.ZodInt;
80
+ end: z.ZodInt;
81
+ duration: z.ZodInt;
82
+ }, z.core.$strip>;
83
+ operations: OperationsSchema;
84
+ }, z.core.$strip>;
85
+ export type LogId = Tagged<OperationId, "LogId">;
86
+ export declare const LogIdSchema: z.ZodPipe<z.ZodUUID, z.ZodTransform<LogId, string>>;
87
+ export declare function createLogSchema<Name extends string, InputSchema extends z.ZodType, OutputSchema extends z.ZodType, OperationsSchema extends SequentialOperationsTuple>({ name, inputSchema, outputSchema, operationsSchema }: {
88
+ name: Name;
89
+ inputSchema: InputSchema;
90
+ outputSchema: OutputSchema;
91
+ operationsSchema: OperationsSchema;
92
+ }): z.ZodObject<{
93
+ name: z.ZodLiteral<Name>;
94
+ source: z.ZodString;
95
+ success: z.ZodBoolean;
96
+ input: InputSchema;
97
+ output: OutputSchema;
98
+ performance: z.ZodObject<{
99
+ start: z.ZodInt;
100
+ end: z.ZodInt;
101
+ duration: z.ZodInt;
102
+ }, z.core.$strip>;
103
+ operations: OperationsSchema;
104
+ id: z.ZodPipe<z.ZodUUID, z.ZodTransform<LogId, string>>;
105
+ level: z.ZodEnum<{
106
+ error: "error";
107
+ fatal: "fatal";
108
+ info: "info";
109
+ warn: "warn";
110
+ }>;
111
+ context: z.ZodObject<{
112
+ who: z.ZodString;
113
+ didWhat: z.ZodString;
114
+ inWhere: z.ZodExactOptional<z.ZodString>;
115
+ atWhen: z.ZodInt;
116
+ }, z.core.$strip>;
117
+ }, z.core.$strip>;
118
+ export type Log<Name extends string = string, InputSchema extends z.ZodType = z.ZodType, OutputSchema extends z.ZodType = z.ZodType, OperationsSchema extends SequentialOperationsTuple = SequentialOperationsTuple> = z.infer<ReturnType<typeof createLogSchema<Name, InputSchema, OutputSchema, OperationsSchema>>>;
119
+ export declare const LogLevelSchema: z.ZodEnum<{
120
+ error: "error";
121
+ fatal: "fatal";
122
+ info: "info";
123
+ warn: "warn";
124
+ }>;
125
+ export type LogLevel = z.infer<typeof LogLevelSchema>;
126
+ export declare const LogContextSchema: z.ZodObject<{
127
+ who: z.ZodString;
128
+ didWhat: z.ZodString;
129
+ inWhere: z.ZodExactOptional<z.ZodString>;
130
+ atWhen: z.ZodInt;
131
+ }, z.core.$strip>;
132
+ export type LogContext = z.infer<typeof LogContextSchema>;
133
+ export declare abstract class Logger {
134
+ abstract [LOG_LEVEL.INFO]<TLog extends Log>(log: TLog, ...rest: unknown[]): void;
135
+ abstract [LOG_LEVEL.WARN]<TLog extends Log>(log: TLog, ...rest: unknown[]): void;
136
+ abstract [LOG_LEVEL.ERROR]<TLog extends Log>(log: TLog, ...rest: unknown[]): void;
137
+ abstract [LOG_LEVEL.FATAL]<TLog extends Log>(log: TLog, ...rest: unknown[]): void;
138
+ }
139
+ interface ComposeLogMessageParams extends LogContext {
140
+ level: LogLevel;
141
+ }
142
+ export declare function composeLogMessage({ level, who, didWhat, inWhere, atWhen }: ComposeLogMessageParams): string;
143
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,101 @@
1
+ import { NonEmptyStringSchema, PositiveIntegerSchema } from "@little-nebulae/zod-schemas";
2
+ import { z } from "zod";
3
+ // 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
+ // src/schemas/operation/id.ts
26
+ const OperationIdSchema = z.uuidv7().transform((id) => id);
27
+ // src/schemas/operation/performance.ts
28
+ const OperationPerformanceSchema = z.object({
29
+ start: PositiveIntegerSchema,
30
+ end: PositiveIntegerSchema,
31
+ duration: PositiveIntegerSchema
32
+ }).refine(({ start, end }) => end > start);
33
+ // src/schemas/operation/index.ts
34
+ function createOperationSchema({ name, inputSchema, outputSchema }) {
35
+ return z.object({
36
+ id: OperationIdSchema,
37
+ name: z.literal(name),
38
+ source: NonEmptyStringSchema,
39
+ success: z.boolean(),
40
+ input: inputSchema,
41
+ output: outputSchema,
42
+ performance: OperationPerformanceSchema
43
+ });
44
+ }
45
+ // src/schemas/operation/concurrent.ts
46
+ function createConcurrentOperationsSchema({ name, inputSchema, outputSchema, operationsSchema }) {
47
+ const SingleOperationSchema = createOperationSchema({
48
+ name,
49
+ inputSchema,
50
+ outputSchema
51
+ });
52
+ return z.object({
53
+ ...SingleOperationSchema.shape,
54
+ operations: operationsSchema
55
+ });
56
+ }
57
+ // src/schemas/operation/sequential.ts
58
+ function createSequentialOperationsSchema({ name, inputSchema, outputSchema, operationsSchema }) {
59
+ const SingleOperationSchema = createOperationSchema({
60
+ name,
61
+ inputSchema,
62
+ outputSchema
63
+ });
64
+ return z.object({
65
+ ...SingleOperationSchema.shape,
66
+ operations: operationsSchema
67
+ });
68
+ }
69
+ // src/schemas/log/context.ts
70
+ const LogContextSchema = z.object({
71
+ who: NonEmptyStringSchema,
72
+ didWhat: NonEmptyStringSchema,
73
+ inWhere: NonEmptyStringSchema.exactOptional(),
74
+ atWhen: PositiveIntegerSchema
75
+ });
76
+ // src/schemas/log/id.ts
77
+ const LogIdSchema = z.uuidv7().transform((id) => id);
78
+ // src/schemas/log/level.ts
79
+ const LogLevelSchema = z.enum(LOG_LEVELS);
80
+ // src/schemas/log/index.ts
81
+ function createLogSchema({ name, inputSchema, outputSchema, operationsSchema }) {
82
+ const SequentialOperationsSchema = createSequentialOperationsSchema({
83
+ name,
84
+ inputSchema,
85
+ outputSchema,
86
+ operationsSchema
87
+ });
88
+ return z.object({
89
+ ...SequentialOperationsSchema.shape,
90
+ id: LogIdSchema,
91
+ level: LogLevelSchema,
92
+ context: LogContextSchema
93
+ });
94
+ }
95
+ // src/logger.ts
96
+ var Logger = class {};
97
+ // src/utils.ts
98
+ function composeLogMessage({ level, who, didWhat, inWhere, atWhen }) {
99
+ return `[${level.toUpperCase()}] ${who} ${didWhat}${inWhere ? " " + inWhere : ""} ${new Date(atWhen).toISOString()}.`;
100
+ }
101
+ export { DEFAULT_LOG_DIR_NAME, DEFAULT_MINIMUM_LOG_LEVEL, LOG_LEVEL, LOG_LEVELS, LogContextSchema, LogIdSchema, LogLevelSchema, Logger, OperationIdSchema, OperationPerformanceSchema, composeLogMessage, createConcurrentOperationsSchema, createLogSchema, createOperationSchema, createSequentialOperationsSchema };
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@little-nebulae/log",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.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/zod-schemas": "0.2.0",
21
+ "@oxc-node/cli": "1.0.1",
22
+ "@types/node": "26.6.5",
23
+ "oxfmt": "0.74.0",
24
+ "oxlint": "1.89.0",
25
+ "oxlint-tsgolint": "7.0.2005",
26
+ "publint": "0.3.25",
27
+ "tsdown": "0.23.2",
28
+ "type-fest": "5.10.0",
29
+ "typescript": "7.1.0-beta",
30
+ "vitest": "5.0.5",
31
+ "zod": "4.6.7"
32
+ },
33
+ "peerDependencies": {
34
+ "@little-nebulae/zod-schemas": "0",
35
+ "type-fest": "^5.0.0",
36
+ "zod": "^4.0.0"
37
+ },
38
+ "devEngines": {
39
+ "packageManager": {
40
+ "name": "pnpm",
41
+ "version": "12.15.0",
42
+ "onFail": "warn"
43
+ }
44
+ },
45
+ "scripts": {
46
+ "build": "tsdown",
47
+ "fmt": "oxfmt --disable-nested-config",
48
+ "fmt:check": "oxfmt --check --disable-nested-config",
49
+ "lint": "oxlint --disable-nested-config",
50
+ "lint:fix": "oxlint --fix --disable-nested-config",
51
+ "check": "pnpm run lint && pnpm run fmt:check",
52
+ "fix": "pnpm run lint:fix && pnpm run fmt",
53
+ "test": "vitest run",
54
+ "try": "oxnode src/try.ts"
55
+ }
6
56
  }