@little-nebulae/log 0.1.0 → 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.
Files changed (3) hide show
  1. package/dist/index.d.ts +69 -139
  2. package/dist/index.js +68 -40
  3. package/package.json +11 -15
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { z } from "zod";
2
2
  import { Tagged } from "type-fest";
3
- //#region src/constants.d.ts
4
3
  export declare const LOG_LEVEL: {
5
4
  readonly INFO: "info";
6
5
  readonly WARN: "warn";
@@ -17,176 +16,91 @@ export declare const DEFAULT_LOG_DIR_NAME: {
17
16
  readonly MAIN: "main-thread";
18
17
  readonly WORKER: "worker-threads";
19
18
  };
20
- //#endregion
21
- //#region src/schemas/operation.d.ts
22
19
  export type OperationId = Tagged<string, "OperationId">;
23
20
  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<{
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<{
31
26
  id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
32
- name: z.ZodString;
27
+ name: z.ZodLiteral<Name>;
33
28
  source: z.ZodString;
34
29
  success: z.ZodBoolean;
35
- input: z.ZodUnknown;
36
- output: z.ZodUnknown;
30
+ input: InputSchema;
31
+ output: OutputSchema;
37
32
  performance: z.ZodObject<{
38
33
  start: z.ZodInt;
39
34
  end: z.ZodInt;
40
35
  duration: z.ZodInt;
41
36
  }, z.core.$strip>;
42
37
  }, z.core.$strip>;
43
- export type Operation = z.infer<typeof OperationSchema>;
44
- export declare const ConcurrentOperationsSchema: z.ZodObject<{
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<{
45
51
  id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
46
- name: z.ZodString;
52
+ name: z.ZodLiteral<Name>;
47
53
  source: z.ZodString;
48
54
  success: z.ZodBoolean;
49
- input: z.ZodUnknown;
50
- output: z.ZodUnknown;
55
+ input: InputSchema;
56
+ output: OutputSchema;
51
57
  performance: z.ZodObject<{
52
58
  start: z.ZodInt;
53
59
  end: z.ZodInt;
54
60
  duration: z.ZodInt;
55
61
  }, 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>>;
62
+ operations: OperationsSchema;
69
63
  }, z.core.$strip>;
70
- export type ConcurrentOperations = z.infer<typeof ConcurrentOperationsSchema>;
71
- export declare const SequentialOperationsSchema: z.ZodObject<{
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
72
  id: z.ZodPipe<z.ZodUUID, z.ZodTransform<OperationId, string>>;
73
- name: z.ZodString;
73
+ name: z.ZodLiteral<Name>;
74
74
  source: z.ZodString;
75
75
  success: z.ZodBoolean;
76
- input: z.ZodUnknown;
77
- output: z.ZodUnknown;
76
+ input: InputSchema;
77
+ output: OutputSchema;
78
78
  performance: z.ZodObject<{
79
79
  start: z.ZodInt;
80
80
  end: z.ZodInt;
81
81
  duration: z.ZodInt;
82
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>]>>;
83
+ operations: OperationsSchema;
121
84
  }, z.core.$strip>;
122
- export type SequentialOperations = z.infer<typeof SequentialOperationsSchema>;
123
- //#endregion
124
- //#region src/schemas/log.d.ts
125
85
  export type LogId = Tagged<OperationId, "LogId">;
126
86
  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;
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>;
143
94
  source: z.ZodString;
144
95
  success: z.ZodBoolean;
145
- input: z.ZodUnknown;
146
- output: z.ZodUnknown;
96
+ input: InputSchema;
97
+ output: OutputSchema;
147
98
  performance: z.ZodObject<{
148
99
  start: z.ZodInt;
149
100
  end: z.ZodInt;
150
101
  duration: z.ZodInt;
151
102
  }, 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>]>>;
103
+ operations: OperationsSchema;
190
104
  id: z.ZodPipe<z.ZodUUID, z.ZodTransform<LogId, string>>;
191
105
  level: z.ZodEnum<{
192
106
  error: "error";
@@ -198,16 +112,32 @@ export declare const LogSchema: z.ZodObject<{
198
112
  who: z.ZodString;
199
113
  didWhat: z.ZodString;
200
114
  inWhere: z.ZodExactOptional<z.ZodString>;
201
- atWhen: z.ZodDate;
115
+ atWhen: z.ZodInt;
202
116
  }, z.core.$strip>;
203
- message: z.ZodString;
204
117
  }, z.core.$strip>;
205
- export type Log = z.infer<typeof LogSchema>;
206
- //#endregion
207
- //#region src/utils.d.ts
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
+ }
208
139
  interface ComposeLogMessageParams extends LogContext {
209
140
  level: LogLevel;
210
141
  }
211
142
  export declare function composeLogMessage({ level, who, didWhat, inWhere, atWhen }: ComposeLogMessageParams): string;
212
- //#endregion
213
143
  export {};
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { NonEmptyStringSchema, PositiveIntegerSchema } from "@little-nebulae/zod";
1
+ import { NonEmptyStringSchema, PositiveIntegerSchema } from "@little-nebulae/zod-schemas";
2
2
  import { z } from "zod";
3
- //#region src/constants.ts
3
+ // src/constants.ts
4
4
  const LOG_LEVEL = {
5
5
  INFO: "info",
6
6
  WARN: "warn",
@@ -22,52 +22,80 @@ const DEFAULT_LOG_DIR_NAME = {
22
22
  MAIN: "main-thread",
23
23
  WORKER: "worker-threads"
24
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
25
+ // src/schemas/operation/id.ts
32
26
  const OperationIdSchema = z.uuidv7().transform((id) => id);
27
+ // src/schemas/operation/performance.ts
33
28
  const OperationPerformanceSchema = z.object({
34
29
  start: PositiveIntegerSchema,
35
30
  end: PositiveIntegerSchema,
36
31
  duration: PositiveIntegerSchema
37
32
  }).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);
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
59
70
  const LogContextSchema = z.object({
60
71
  who: NonEmptyStringSchema,
61
72
  didWhat: NonEmptyStringSchema,
62
73
  inWhere: NonEmptyStringSchema.exactOptional(),
63
- atWhen: z.date()
74
+ atWhen: PositiveIntegerSchema
64
75
  });
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 };
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,6 @@
1
1
  {
2
2
  "name": "@little-nebulae/log",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist"
@@ -17,32 +17,28 @@
17
17
  },
18
18
  "devDependencies": {
19
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",
20
+ "@little-nebulae/zod-schemas": "0.2.0",
21
+ "@oxc-node/cli": "1.0.1",
24
22
  "@types/node": "26.6.5",
25
- "oxfmt": "0.73.0",
26
- "oxlint": "1.88.0",
27
- "oxlint-tsgolint": "7.0.2004",
23
+ "oxfmt": "0.74.0",
24
+ "oxlint": "1.89.0",
25
+ "oxlint-tsgolint": "7.0.2005",
28
26
  "publint": "0.3.25",
29
- "tsdown": "0.23.1",
27
+ "tsdown": "0.23.2",
30
28
  "type-fest": "5.10.0",
31
- "typescript": "7.0.2",
32
- "vitest": "5.0.4",
29
+ "typescript": "7.1.0-beta",
30
+ "vitest": "5.0.5",
33
31
  "zod": "4.6.7"
34
32
  },
35
33
  "peerDependencies": {
36
- "@little-nebulae/error": "^1.0.0",
37
- "@little-nebulae/result": "^1.0.0",
38
- "@little-nebulae/zod": "0",
34
+ "@little-nebulae/zod-schemas": "0",
39
35
  "type-fest": "^5.0.0",
40
36
  "zod": "^4.0.0"
41
37
  },
42
38
  "devEngines": {
43
39
  "packageManager": {
44
40
  "name": "pnpm",
45
- "version": "12.11.2",
41
+ "version": "12.15.0",
46
42
  "onFail": "warn"
47
43
  }
48
44
  },