ondc-code-generator 0.0.1 → 0.0.3

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 (77) hide show
  1. package/dist/constants/syntax.js +2 -0
  2. package/{src/example.ts → dist/example.js} +1 -4
  3. package/dist/{Generator → generator}/config-compiler.js +25 -4
  4. package/dist/{Generator → generator}/generators/documentation/markdown-message-generator.js +0 -13
  5. package/dist/{Generator → generator}/generators/typescript/ts-generator.js +3 -4
  6. package/dist/{Generator → generator}/validators/abstract-validator.js +1 -1
  7. package/dist/{Generator → generator}/validators/config-validator.js +4 -4
  8. package/dist/{Generator → generator}/validators/session-data-config/session-data-validator.js +2 -2
  9. package/dist/{Generator → generator}/validators/tests-config/sub-validations.js +38 -33
  10. package/dist/{Generator → generator}/validators/tests-config/test-list-validator.js +3 -3
  11. package/dist/{Generator → generator}/validators/tests-config/test-validator.js +7 -7
  12. package/dist/index.js +1 -38
  13. package/dist/services/return-complier/tokens.js +3 -0
  14. package/dist/utils/general-utils/string-utils.js +10 -2
  15. package/package.json +6 -4
  16. package/dist/Generator/config-validator.js +0 -21
  17. package/dist/Generator/generators/markdown-message-generator.js +0 -25
  18. package/dist/Generator/pipline.js +0 -1
  19. package/dist/Generator/validators/validation-error.js +0 -9
  20. package/dist/services/rename-later/main.js +0 -1
  21. package/dist/services/rename-later/parser.js +0 -22
  22. package/dist/services/rename-later/tokens.js +0 -32
  23. package/dist/services/rename-later/tokens1.js +0 -33
  24. package/dist/utils/file-system.js +0 -1
  25. package/src/constants/operations.ts +0 -19
  26. package/src/constants/syntax.ts +0 -81
  27. package/src/generator/config-compiler.ts +0 -122
  28. package/src/generator/generators/classes/abstract-generator.ts +0 -29
  29. package/src/generator/generators/documentation/markdown-message-generator.ts +0 -43
  30. package/src/generator/generators/documentation/md-generator.ts +0 -76
  31. package/src/generator/generators/documentation/templates/index.mustache +0 -36
  32. package/src/generator/generators/documentation/templates/style.css +0 -204
  33. package/src/generator/generators/python/py-generator.ts +0 -0
  34. package/src/generator/generators/typescript/templates/api-test.mustache +0 -7
  35. package/src/generator/generators/typescript/templates/json-path-utils.ts +0 -17
  36. package/src/generator/generators/typescript/templates/schema-template.mustache +0 -18
  37. package/src/generator/generators/typescript/templates/test-config.mustache +0 -28
  38. package/src/generator/generators/typescript/templates/test-object.mustache +0 -20
  39. package/src/generator/generators/typescript/templates/validation-code.mustache +0 -39
  40. package/src/generator/generators/typescript/templates/validation-utils.ts +0 -117
  41. package/src/generator/generators/typescript/ts-ast.ts +0 -72
  42. package/src/generator/generators/typescript/ts-generator.ts +0 -275
  43. package/src/generator/validators/abstract-validator.ts +0 -23
  44. package/src/generator/validators/config-validator.ts +0 -55
  45. package/src/generator/validators/session-data-config/session-data-validator.ts +0 -58
  46. package/src/generator/validators/tests-config/sub-validations.ts +0 -302
  47. package/src/generator/validators/tests-config/test-list-validator.ts +0 -59
  48. package/src/generator/validators/tests-config/test-validator.ts +0 -69
  49. package/src/index.ts +0 -2
  50. package/src/services/return-complier/ast-functions/compile-to-markdown.ts +0 -152
  51. package/src/services/return-complier/ast-functions/semantic-validations.ts +0 -44
  52. package/src/services/return-complier/ast.ts +0 -147
  53. package/src/services/return-complier/combined.ts +0 -8
  54. package/src/services/return-complier/parser.ts +0 -128
  55. package/src/services/return-complier/tokens.ts +0 -184
  56. package/src/services/schema-service.ts +0 -42
  57. package/src/types/build.ts +0 -51
  58. package/src/types/compiler-types.ts +0 -3
  59. package/src/types/config-types.ts +0 -27
  60. package/src/types/error-codes.ts +0 -6
  61. package/src/types/general-types.ts +0 -2
  62. package/src/utils/config-utils/json-schema-utils.ts +0 -150
  63. package/src/utils/config-utils/yaml.ts +0 -17
  64. package/src/utils/fs-utils.ts +0 -32
  65. package/src/utils/general-utils/string-utils.ts +0 -76
  66. package/src/utils/general-utils/test-object-utils.ts +0 -14
  67. package/src/utils/general-utils/validation-utils.ts +0 -30
  68. package/src/utils/json-path-utils/extract-string-paths.ts +0 -139
  69. package/src/utils/json-path-utils/paths.ts +0 -44
  70. package/src/utils/logger.ts +0 -53
  71. package/tsconfig.json +0 -17
  72. /package/dist/{Generator → generator}/generators/classes/abstract-generator.js +0 -0
  73. /package/dist/{Generator → generator}/generators/documentation/md-generator.js +0 -0
  74. /package/dist/{Generator → generator}/generators/python/py-generator.js +0 -0
  75. /package/dist/{Generator → generator}/generators/typescript/templates/json-path-utils.js +0 -0
  76. /package/dist/{Generator → generator}/generators/typescript/templates/validation-utils.js +0 -0
  77. /package/dist/{Generator → generator}/generators/typescript/ts-ast.js +0 -0
@@ -1,150 +0,0 @@
1
- import { JSONSchema7, JSONSchema7Definition } from "json-schema";
2
- import { remove } from "winston";
3
-
4
- /**
5
- * Recursively removes all "required" and "enum" properties from a JSON Schema.
6
- * @param schema - The JSON Schema object to process.
7
- * @returns A new JSON Schema object with "required" and "enum" properties removed.
8
- */
9
- export function removeRequiredAndEnum(
10
- schema: JSONSchema7 | boolean,
11
- removeEnums: boolean = true,
12
- removeRequired: boolean = true
13
- ): JSONSchema7 | boolean {
14
- if (typeof schema === "boolean") {
15
- // Boolean schemas are returned as is
16
- return schema;
17
- }
18
-
19
- // Create a shallow copy to avoid mutating the original schema
20
- const cleanedSchema: JSONSchema7 = { ...schema };
21
-
22
- // Remove "required" and "enum" properties
23
- if (removeRequired) {
24
- delete cleanedSchema.required;
25
- }
26
- if (removeEnums) {
27
- delete cleanedSchema.enum;
28
- }
29
-
30
- // Helper function to process child schemas
31
- const processSchema = (
32
- subSchema: JSONSchema7Definition
33
- ): JSONSchema7Definition => {
34
- return removeRequiredAndEnum(subSchema, removeEnums, removeRequired);
35
- };
36
-
37
- // Process "properties"
38
- if (cleanedSchema.properties) {
39
- const newProperties: { [key: string]: JSONSchema7Definition } = {};
40
- for (const key in cleanedSchema.properties) {
41
- newProperties[key] = processSchema(cleanedSchema.properties[key]);
42
- }
43
- cleanedSchema.properties = newProperties;
44
- }
45
-
46
- // Process "patternProperties"
47
- if (cleanedSchema.patternProperties) {
48
- const newPatternProperties: { [key: string]: JSONSchema7Definition } = {};
49
- for (const key in cleanedSchema.patternProperties) {
50
- newPatternProperties[key] = processSchema(
51
- cleanedSchema.patternProperties[key]
52
- );
53
- }
54
- cleanedSchema.patternProperties = newPatternProperties;
55
- }
56
-
57
- // Process "additionalProperties"
58
- if (
59
- typeof cleanedSchema.additionalProperties === "object" &&
60
- cleanedSchema.additionalProperties !== null
61
- ) {
62
- cleanedSchema.additionalProperties = removeRequiredAndEnum(
63
- cleanedSchema.additionalProperties,
64
- removeEnums,
65
- removeRequired
66
- );
67
- }
68
-
69
- // Process "items"
70
- if (cleanedSchema.items) {
71
- if (Array.isArray(cleanedSchema.items)) {
72
- cleanedSchema.items = cleanedSchema.items.map((item) =>
73
- removeRequiredAndEnum(item, removeEnums, removeRequired)
74
- );
75
- } else {
76
- cleanedSchema.items = removeRequiredAndEnum(
77
- cleanedSchema.items,
78
- removeEnums,
79
- removeRequired
80
- );
81
- }
82
- }
83
-
84
- // Process "additionalItems"
85
- if (
86
- typeof cleanedSchema.additionalItems === "object" &&
87
- cleanedSchema.additionalItems !== null
88
- ) {
89
- cleanedSchema.additionalItems = removeRequiredAndEnum(
90
- cleanedSchema.additionalItems,
91
- removeEnums,
92
- removeRequired
93
- );
94
- }
95
-
96
- // Process combiners: "allOf", "anyOf", "oneOf"
97
- ["allOf", "anyOf", "oneOf"].forEach((combiner) => {
98
- if (
99
- cleanedSchema[combiner as keyof JSONSchema7] &&
100
- Array.isArray(cleanedSchema[combiner as keyof JSONSchema7])
101
- ) {
102
- // @ts-ignore
103
- cleanedSchema[combiner as keyof JSONSchema7] = (
104
- cleanedSchema[combiner as keyof JSONSchema7] as JSONSchema7[]
105
- ).map((subSchema) =>
106
- removeRequiredAndEnum(subSchema, removeEnums, removeRequired)
107
- );
108
- }
109
- });
110
-
111
- // Process "not"
112
- if (cleanedSchema.not) {
113
- cleanedSchema.not = removeRequiredAndEnum(
114
- cleanedSchema.not,
115
- removeEnums,
116
- removeRequired
117
- );
118
- }
119
-
120
- // Process "definitions"
121
- if (cleanedSchema.definitions) {
122
- const newDefinitions: { [key: string]: JSONSchema7Definition } = {};
123
- for (const key in cleanedSchema.definitions) {
124
- newDefinitions[key] = processSchema(cleanedSchema.definitions[key]);
125
- }
126
- cleanedSchema.definitions = newDefinitions;
127
- }
128
- // Process "if", "then", "else"
129
- ["if", "then", "else"].forEach((keyword) => {
130
- if (cleanedSchema[keyword as keyof JSONSchema7]) {
131
- // @ts-ignore
132
- cleanedSchema[keyword as keyof JSONSchema7] = removeRequiredAndEnum(
133
- cleanedSchema[keyword as keyof JSONSchema7] as JSONSchema7,
134
- removeEnums,
135
- removeRequired
136
- );
137
- }
138
- });
139
-
140
- // Process "contains"
141
- if (cleanedSchema.contains) {
142
- cleanedSchema.contains = removeRequiredAndEnum(
143
- cleanedSchema.contains,
144
- removeEnums,
145
- removeRequired
146
- );
147
- }
148
-
149
- return cleanedSchema;
150
- }
@@ -1,17 +0,0 @@
1
- import yaml from "js-yaml";
2
- import RefParser from "@apidevtools/json-schema-ref-parser";
3
-
4
- export async function loadAndDereferenceYaml<T>(yamlData: string) {
5
- const raw = yaml.load(yamlData);
6
- const data = (await dereferenceSchema(raw)) as T;
7
- return data;
8
- }
9
-
10
- async function dereferenceSchema(schema: any) {
11
- try {
12
- const dereferencedSchema = await RefParser.dereference(schema);
13
- return dereferencedSchema;
14
- } catch (error) {
15
- console.error("Error dereferencing schema:", error);
16
- }
17
- }
@@ -1,32 +0,0 @@
1
- import fs from "fs-extra";
2
- import * as path from "path";
3
- import prettier from "prettier";
4
- import logger from "./logger.js";
5
-
6
- export function writeFileWithFsExtra(
7
- rootPath: string,
8
- relativeFilePath: string,
9
- content: string
10
- ): void {
11
- // Resolve the full file path
12
- const filePath = path.resolve(rootPath, relativeFilePath);
13
- logger.debug(`Writing file to ${filePath}`);
14
- fs.outputFileSync(filePath, content);
15
- }
16
-
17
- export async function formatCode(code: string, lang: string) {
18
- return await prettier.format(code, {
19
- parser: lang,
20
- tabWidth: 4,
21
- });
22
- }
23
-
24
- export async function writeAndFormatCode(
25
- rootPath: string,
26
- relativeFilePath: string,
27
- content: string,
28
- lang: string
29
- ) {
30
- const formattedCode = await formatCode(content, lang);
31
- writeFileWithFsExtra(rootPath, relativeFilePath, formattedCode);
32
- }
@@ -1,76 +0,0 @@
1
- import {
2
- nodeReservedKeywords,
3
- TestObjectSyntax,
4
- } from "../../constants/syntax.js";
5
- import { TestObject } from "../../types/config-types.js";
6
- import { getVariablesFromTest } from "./test-object-utils.js";
7
-
8
- /**
9
- * Check if the string matches the pattern: lowercase letters and underscores only, no leading or trailing underscores
10
- *
11
- * @param str
12
- * @returns true if the string is in snake_case, false otherwise
13
- */
14
- export function isSnakeCase(str: string): boolean {
15
- const snakeCasePattern = /^[a-z0-9A-Z]+(_[a-z0-9A-Z]+)*$/;
16
- return snakeCasePattern.test(str);
17
- }
18
-
19
- export function isValidVariableName(input: string): boolean {
20
- // Regular expression to match valid variable names
21
- const validVariableNameRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
22
-
23
- // Check if input matches the regex
24
- const matchesPattern = validVariableNameRegex.test(input);
25
-
26
- const isNotReservedKeyword = !nodeReservedKeywords.has(input);
27
-
28
- return matchesPattern && isNotReservedKeyword;
29
- }
30
-
31
- /**
32
- * Adds '>' at the beginning of each line in the given Markdown string.
33
- *
34
- * @param {string} markdown - The input Markdown string.
35
- * @returns {string} - The modified Markdown string with '>' added to each line.
36
- */
37
- export function addBlockquoteToMarkdown(markdown: string): string {
38
- return markdown
39
- .split("\n") // Split the input string into an array of lines.
40
- .map((line) => ">" + (line.trim() !== "" ? " " + line : "")) // Add '>' in front of each line.
41
- .join("\n"); // Join the array of lines back into a single string.
42
- }
43
-
44
- export function ConvertArrayToStringsInTestObject(testObject: TestObject) {
45
- const variables = getVariablesFromTest(testObject);
46
- const testDuplicate = { ...testObject };
47
- const scope = testObject[TestObjectSyntax.Scope];
48
- for (const variable of variables) {
49
- if (Array.isArray(testObject[variable])) {
50
- let vals = testObject[variable].map((v) => `"${v}"`).join(", ");
51
- vals = vals.replace(/"/g, `"`);
52
- testDuplicate[variable] = `[${vals}]`;
53
- } else {
54
- if (scope) {
55
- const path = testDuplicate[variable] as string;
56
- const pathWithoutDollar = path.slice(2);
57
- testDuplicate[variable] = `${scope}.${pathWithoutDollar}`;
58
- }
59
- }
60
- }
61
- return testDuplicate;
62
- }
63
-
64
- export function ConvertArrayToString(arr: any[]) {
65
- let vals = arr.map((v) => `"${v}"`).join(", ");
66
- vals = vals.replace(/"/g, `"`);
67
- return `[${vals}]`;
68
- }
69
-
70
- export function addTabToMarkdown(markdown: string) {
71
- // Split the markdown into lines, add a tab to each line, and rejoin
72
- return markdown
73
- .split("\n") // Split the input into individual lines
74
- .map((line) => `\t${line}`) // Add a tab character at the beginning of each line
75
- .join("\n"); // Rejoin the lines into a single string
76
- }
@@ -1,14 +0,0 @@
1
- import { TestObjectSyntax } from "../../constants/syntax.js";
2
- import { TestObject } from "../../types/config-types.js";
3
-
4
- export function getVariablesFromTest(testObject: TestObject) {
5
- const variables: string[] = [];
6
- const keys = Object.keys(testObject);
7
- for (const key of keys) {
8
- if (Object.values(TestObjectSyntax).includes(key as TestObjectSyntax)) {
9
- continue;
10
- }
11
- variables.push(key);
12
- }
13
- return variables;
14
- }
@@ -1,30 +0,0 @@
1
- import { SessionDataApi } from "../../types/config-types.js";
2
- import { Primitive, ValidVariableLine } from "../../types/general-types.js";
3
-
4
- export function isPrimitive(value: unknown): value is Primitive {
5
- return (
6
- value === null ||
7
- ["string", "number", "boolean", "symbol", "bigint"].includes(typeof value)
8
- );
9
- }
10
-
11
- export function isValidVariableValueType(line: any): line is ValidVariableLine {
12
- if (typeof line === "string") {
13
- return true;
14
- }
15
- return Array.isArray(line) && line.every((item) => isPrimitive(item));
16
- }
17
-
18
- export function getExternalVariables(
19
- sessionData: Record<string, SessionDataApi>
20
- ) {
21
- const variables: string[] = [];
22
- Object.values(sessionData).forEach((session) => {
23
- Object.keys(session).forEach((key) => {
24
- if (!variables.includes(key)) {
25
- variables.push(key);
26
- }
27
- });
28
- });
29
- return variables;
30
- }
@@ -1,139 +0,0 @@
1
- // Import the JSONSchema7 type from the official types package
2
- import { JSONSchema7 } from "json-schema";
3
-
4
- /**
5
- * Extracts all possible JSON paths from a given JSON Schema Draft-07.
6
- *
7
- * @param schema - The JSON Schema Draft-07 object.
8
- * @returns An array of JSON paths as strings.
9
- */
10
- export function getAllJsonPaths(schema: JSONSchema7): string[] {
11
- const paths: Set<string> = new Set();
12
-
13
- /**
14
- * Recursively traverses the JSON schema to extract paths.
15
- *
16
- * @param currentSchema - The current schema node being traversed.
17
- * @param currentPath - The JSON path accumulated so far.
18
- */
19
- function traverse(currentSchema: JSONSchema7, currentPath: string) {
20
- if (!currentSchema) return;
21
-
22
- // Normalize the 'type' property to an array for consistent processing
23
- const schemaTypes = Array.isArray(currentSchema.type)
24
- ? currentSchema.type
25
- : currentSchema.type
26
- ? [currentSchema.type]
27
- : [];
28
-
29
- // Handle combinators: allOf, anyOf, oneOf
30
- const combinators: Array<keyof JSONSchema7> = ["allOf", "anyOf", "oneOf"];
31
- for (const comb of combinators) {
32
- if (currentSchema[comb]) {
33
- // @ts-ignore
34
- for (const subSchema of currentSchema[comb]!) {
35
- traverse(subSchema as JSONSchema7, currentPath);
36
- }
37
- }
38
- }
39
-
40
- // Handle 'not' by skipping as it signifies exclusion
41
- if (currentSchema.not) {
42
- // Skipping 'not' schemas as they represent negations
43
- }
44
-
45
- // If the schema is of type 'object', traverse its properties
46
- if (schemaTypes.includes("object") && currentSchema.properties) {
47
- for (const [propName, propSchema] of Object.entries(
48
- currentSchema.properties
49
- )) {
50
- const newPath =
51
- currentPath === "$" ? `$.${propName}` : `${currentPath}.${propName}`;
52
- traverse(propSchema as JSONSchema7, newPath);
53
- }
54
-
55
- // Handle 'additionalProperties' if it's a schema
56
- if (
57
- currentSchema.additionalProperties &&
58
- typeof currentSchema.additionalProperties === "object"
59
- ) {
60
- const newPath = `${currentPath}.*`; // Using '*' to denote any additional property
61
- traverse(currentSchema.additionalProperties as JSONSchema7, newPath);
62
- }
63
-
64
- // Handle 'patternProperties'
65
- if (currentSchema.patternProperties) {
66
- for (const [pattern, patternSchema] of Object.entries(
67
- currentSchema.patternProperties
68
- )) {
69
- const newPath = `${currentPath}.*`; // Using '*' as a placeholder for any matching pattern
70
- traverse(patternSchema as JSONSchema7, newPath);
71
- }
72
- }
73
- }
74
-
75
- // If the schema is of type 'array', traverse its items
76
- if (schemaTypes.includes("array") && currentSchema.items) {
77
- if (Array.isArray(currentSchema.items)) {
78
- // Tuple validation: items is an array of schemas
79
- currentSchema.items.forEach((itemSchema, index) => {
80
- const newPath = `${currentPath}[*]`; // Using [*] to denote any index
81
- traverse(itemSchema as JSONSchema7, newPath);
82
- });
83
- } else {
84
- // List validation: items is a single schema
85
- const newPath = `${currentPath}[*]`;
86
- traverse(currentSchema.items as JSONSchema7, newPath);
87
- }
88
- }
89
-
90
- // Define primitive types considered as leaf nodes
91
- const primitiveTypes: Array<Extract<JSONSchema7["type"], string>> = [
92
- "string",
93
- "number",
94
- "integer",
95
- "boolean",
96
- "null",
97
- ];
98
-
99
- // If the schema defines a primitive type, record the path
100
- if (schemaTypes.some((type) => primitiveTypes.includes(type))) {
101
- paths.add(currentPath);
102
- }
103
-
104
- // If 'enum' is present without a specific type, consider it as a leaf node
105
- if (currentSchema.enum) {
106
- paths.add(currentPath);
107
- }
108
-
109
- // If 'const' is present, consider it as a leaf node
110
- if (currentSchema.const !== undefined) {
111
- paths.add(currentPath);
112
- }
113
-
114
- // Handle cases where 'type' is not specified but 'properties' or 'items' are present
115
- if (!currentSchema.type) {
116
- if (currentSchema.properties) {
117
- for (const [propName, propSchema] of Object.entries(
118
- currentSchema.properties
119
- )) {
120
- const newPath =
121
- currentPath === "$"
122
- ? `$.${propName}`
123
- : `${currentPath}.${propName}`;
124
- traverse(propSchema as JSONSchema7, newPath);
125
- }
126
- }
127
- if (currentSchema.items) {
128
- const newPath = `${currentPath}[*]`;
129
- traverse(currentSchema.items as JSONSchema7, newPath);
130
- }
131
- }
132
- }
133
-
134
- // Initialize traversal with the root schema and the root path symbol '$'
135
- traverse(schema, "$");
136
-
137
- // Convert the Set to an array and return
138
- return Array.from(paths);
139
- }
@@ -1,44 +0,0 @@
1
- import jsonpath from "jsonpath";
2
- export function isValidJsonPath(jsonPath: string) {
3
- try {
4
- jsonpath.query({}, jsonPath);
5
- return true;
6
- } catch (error) {
7
- return false;
8
- }
9
- }
10
-
11
- /**
12
- * Replaces all content inside square brackets in a JSONPath with an asterisk '*',
13
- * handling nested brackets if they occur.
14
- *
15
- * @param jsonPath - The JSONPath string to transform.
16
- * @returns The transformed JSONPath string with contents inside brackets replaced by '*'.
17
- */
18
- export function replaceBracketsWithAsteriskNested(jsonPath: string): string {
19
- let result = "";
20
- let i = 0;
21
- while (i < jsonPath.length) {
22
- if (jsonPath[i] === "[") {
23
- // Start of bracketed expression
24
- let bracketDepth = 1;
25
- let j = i + 1;
26
- while (j < jsonPath.length && bracketDepth > 0) {
27
- if (jsonPath[j] === "[") {
28
- bracketDepth++;
29
- } else if (jsonPath[j] === "]") {
30
- bracketDepth--;
31
- }
32
- j++;
33
- }
34
- // Replace the content inside the brackets with '*'
35
- result += "[*]";
36
- i = j; // Move i to after the closing ']'
37
- } else {
38
- // Copy character as-is
39
- result += jsonPath[i];
40
- i++;
41
- }
42
- }
43
- return result;
44
- }
@@ -1,53 +0,0 @@
1
- import winston from "winston";
2
- import chalk from "chalk";
3
-
4
- const { combine, timestamp, printf, errors } = winston.format;
5
-
6
- // Define colors for log levels and messages
7
- const levelColors: Record<string, chalk.Chalk> = {
8
- error: chalk.bold.red, // Bright red for errors
9
- warn: chalk.hex("#FFA500"), // Orange for warnings
10
- info: chalk.blue, // Blue for information
11
- debug: chalk.green, // Green for debugging
12
- default: chalk.white, // Default color for others
13
- };
14
-
15
- const messageColors: Record<string, chalk.Chalk> = {
16
- error: chalk.redBright, // Highlight error messages
17
- warn: chalk.yellowBright, // Bright yellow for warnings
18
- info: chalk.cyan, // Cyan for information messages
19
- debug: chalk.magentaBright, // Bright magenta for debugging
20
- default: chalk.gray, // Default gray for fallback
21
- };
22
-
23
- // Custom log format
24
- const logFormat = printf(({ level, message, timestamp, stack }) => {
25
- const levelColor = levelColors[level] || levelColors.default; // Colorize level
26
- const messageColor = messageColors[level] || messageColors.default; // Colorize message
27
-
28
- const coloredLevel = levelColor(`[${level.toUpperCase()}]`); // Apply color to log level
29
- const coloredTimestamp = chalk.dim(timestamp); // Dim timestamp
30
- const coloredMessage = messageColor(message); // Apply message-specific color
31
- const coloredStack = stack ? chalk.dim(stack) : ""; // Dim stack trace if present
32
-
33
- return `${coloredTimestamp} ${coloredLevel}: ${coloredMessage} ${coloredStack}`;
34
- });
35
-
36
- // Determine log level based on environment
37
- const logLevel = process.env.NODE_ENV === "production" ? "info" : "debug";
38
-
39
- // Configure Winston logger
40
- const logger = winston.createLogger({
41
- level: logLevel,
42
- format: combine(
43
- timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
44
- errors({ stack: true }), // Include stack trace in error messages
45
- logFormat
46
- ),
47
- transports: [
48
- // Console transport with colorized output
49
- new winston.transports.Console(),
50
- ],
51
- });
52
-
53
- export default logger;
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ES2020",
5
- "moduleResolution": "node",
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "esModuleInterop": true,
9
- "forceConsistentCasingInFileNames": true,
10
- "strict": true,
11
- "skipLibCheck": true,
12
- "allowSyntheticDefaultImports": true,
13
- "resolveJsonModule": true
14
- },
15
- "include": ["src/**/*"],
16
- "exclude": ["node_modules", "dist"]
17
- }