@atomic-ehr/codegen 0.0.1-canary.20250822114054.4ca1428 → 0.0.1-canary.20250822150706.c3b8669
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/dist/api/builder.d.ts +3 -3
- package/dist/api/builder.d.ts.map +1 -1
- package/dist/api/builder.js +374 -0
- package/dist/api/generators/base/BaseGenerator.d.ts +4 -4
- package/dist/api/generators/base/BaseGenerator.d.ts.map +1 -1
- package/dist/api/generators/base/BaseGenerator.js +572 -0
- package/dist/api/generators/base/FileManager.d.ts +2 -2
- package/dist/api/generators/base/FileManager.d.ts.map +1 -1
- package/dist/api/generators/base/FileManager.js +204 -0
- package/dist/api/generators/base/PythonTypeMapper.d.ts +2 -2
- package/dist/api/generators/base/PythonTypeMapper.d.ts.map +1 -1
- package/dist/api/generators/base/PythonTypeMapper.js +71 -0
- package/dist/api/generators/base/TemplateEngine.d.ts +1 -1
- package/dist/api/generators/base/TemplateEngine.d.ts.map +1 -1
- package/dist/api/generators/base/TemplateEngine.js +133 -0
- package/dist/api/generators/base/TypeMapper.js +153 -0
- package/dist/api/generators/base/TypeScriptTypeMapper.d.ts +1 -1
- package/dist/api/generators/base/TypeScriptTypeMapper.d.ts.map +1 -1
- package/dist/api/generators/base/TypeScriptTypeMapper.js +232 -0
- package/dist/api/generators/base/builders/DirectoryBuilder.d.ts +4 -4
- package/dist/api/generators/base/builders/DirectoryBuilder.d.ts.map +1 -1
- package/dist/api/generators/base/builders/DirectoryBuilder.js +215 -0
- package/dist/api/generators/base/builders/FileBuilder.d.ts +2 -2
- package/dist/api/generators/base/builders/FileBuilder.d.ts.map +1 -1
- package/dist/api/generators/base/builders/FileBuilder.js +408 -0
- package/dist/api/generators/base/builders/IndexBuilder.d.ts +2 -2
- package/dist/api/generators/base/builders/IndexBuilder.d.ts.map +1 -1
- package/dist/api/generators/base/builders/IndexBuilder.js +290 -0
- package/dist/api/generators/base/enhanced-errors.d.ts +2 -2
- package/dist/api/generators/base/enhanced-errors.d.ts.map +1 -1
- package/dist/api/generators/base/enhanced-errors.js +259 -0
- package/dist/api/generators/base/error-handler.d.ts +1 -1
- package/dist/api/generators/base/error-handler.d.ts.map +1 -1
- package/dist/api/generators/base/error-handler.js +243 -0
- package/dist/api/generators/base/errors.d.ts +2 -2
- package/dist/api/generators/base/errors.d.ts.map +1 -1
- package/dist/api/generators/base/errors.js +694 -0
- package/dist/api/generators/base/index.d.ts +22 -22
- package/dist/api/generators/base/index.d.ts.map +1 -1
- package/dist/api/generators/base/index.js +161 -0
- package/dist/api/generators/base/types.d.ts +2 -2
- package/dist/api/generators/base/types.d.ts.map +1 -1
- package/dist/api/generators/base/types.js +12 -0
- package/dist/api/generators/rest-client.d.ts +2 -2
- package/dist/api/generators/rest-client.d.ts.map +1 -1
- package/dist/api/generators/rest-client.js +847 -0
- package/dist/api/generators/search-parameter-enhancer.d.ts +1 -1
- package/dist/api/generators/search-parameter-enhancer.d.ts.map +1 -1
- package/dist/api/generators/search-parameter-enhancer.js +801 -0
- package/dist/api/generators/types.js +4 -0
- package/dist/api/generators/typescript.d.ts +3 -3
- package/dist/api/generators/typescript.d.ts.map +1 -1
- package/dist/api/generators/typescript.js +537 -0
- package/dist/api/generators/validation-generator.js +632 -0
- package/dist/api/index.d.ts +10 -10
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +51 -0
- package/dist/cli/commands/generate/typescript.d.ts +1 -1
- package/dist/cli/commands/generate/typescript.d.ts.map +1 -1
- package/dist/cli/commands/generate/typescript.js +52 -0
- package/dist/cli/commands/generate.d.ts +5 -12
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +158 -0
- package/dist/cli/commands/index.d.ts +2 -1
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +100 -0
- package/dist/cli/commands/typeschema/generate.js +130 -0
- package/dist/cli/commands/typeschema.js +48 -0
- package/dist/cli/index.js +12 -8664
- package/dist/cli/utils/log.d.ts +2 -2
- package/dist/cli/utils/log.d.ts.map +1 -1
- package/dist/cli/utils/log.js +23 -0
- package/dist/cli/utils/prompts.js +224 -0
- package/dist/cli/utils/spinner.js +270 -0
- package/dist/config.js +703 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +84 -40
- package/dist/logger.js +290 -0
- package/dist/typeschema/cache.d.ts +2 -2
- package/dist/typeschema/cache.d.ts.map +1 -1
- package/dist/typeschema/cache.js +285 -0
- package/dist/typeschema/core/binding.d.ts +1 -1
- package/dist/typeschema/core/binding.d.ts.map +1 -1
- package/dist/typeschema/core/binding.js +187 -0
- package/dist/typeschema/core/field-builder.d.ts +1 -1
- package/dist/typeschema/core/field-builder.d.ts.map +1 -1
- package/dist/typeschema/core/field-builder.js +259 -0
- package/dist/typeschema/core/identifier.js +117 -0
- package/dist/typeschema/core/nested-types.d.ts +1 -1
- package/dist/typeschema/core/nested-types.d.ts.map +1 -1
- package/dist/typeschema/core/nested-types.js +111 -0
- package/dist/typeschema/core/transformer.d.ts +2 -2
- package/dist/typeschema/core/transformer.d.ts.map +1 -1
- package/dist/typeschema/core/transformer.js +345 -0
- package/dist/typeschema/generator.d.ts +3 -3
- package/dist/typeschema/generator.d.ts.map +1 -1
- package/dist/typeschema/generator.js +352 -0
- package/dist/typeschema/index.d.ts +14 -14
- package/dist/typeschema/index.d.ts.map +1 -1
- package/dist/typeschema/index.js +92 -0
- package/dist/typeschema/parser.d.ts +2 -2
- package/dist/typeschema/parser.d.ts.map +1 -1
- package/dist/typeschema/parser.js +310 -0
- package/dist/typeschema/profile/processor.d.ts +1 -1
- package/dist/typeschema/profile/processor.d.ts.map +1 -1
- package/dist/typeschema/profile/processor.js +268 -0
- package/dist/typeschema/schema.js +456 -0
- package/dist/typeschema/type-schema.types.js +39 -0
- package/dist/typeschema/types.js +4 -0
- package/dist/typeschema/utils.d.ts +1 -1
- package/dist/typeschema/utils.d.ts.map +1 -1
- package/dist/typeschema/utils.js +13 -0
- package/dist/typeschema/value-set/processor.d.ts +1 -1
- package/dist/typeschema/value-set/processor.d.ts.map +1 -1
- package/dist/typeschema/value-set/processor.js +168 -0
- package/dist/utils/codegen-logger.js +204 -0
- package/dist/utils.js +42 -0
- package/package.json +15 -4
- package/dist/index-fgcebdva.js +0 -8515
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AAGH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,40 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for the @atomic-ehr/codegen library
|
|
3
|
+
*
|
|
4
|
+
* ## Overview
|
|
5
|
+
*
|
|
6
|
+
* atomic-codegen is a comprehensive code generation toolkit for FHIR healthcare standards,
|
|
7
|
+
* designed with TypeSchema as the intermediate format for maximum flexibility and type safety.
|
|
8
|
+
*
|
|
9
|
+
* ## Key Features
|
|
10
|
+
*
|
|
11
|
+
* - **🔥 FHIR R4/R5 Support**: Complete FHIR resource and profile generation
|
|
12
|
+
* - **🇺🇸 US Core Profiles**: Built-in support for US healthcare implementation guides
|
|
13
|
+
* - **📋 TypeSchema Integration**: Uses TypeSchema as universal intermediate format
|
|
14
|
+
* - **🎯 Type Safety**: Full TypeScript support with runtime validation
|
|
15
|
+
* - **⚡ Performance**: Built with Bun for maximum speed
|
|
16
|
+
* - **🏗️ Extensible**: Plugin architecture for custom generators
|
|
17
|
+
*
|
|
18
|
+
* ## Quick Start
|
|
19
|
+
*
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { APIBuilder } from '@atomic-ehr/codegen';
|
|
22
|
+
*
|
|
23
|
+
* // High-level API for common workflows
|
|
24
|
+
* const api = new APIBuilder();
|
|
25
|
+
*
|
|
26
|
+
* // Generate FHIR types from packages
|
|
27
|
+
* await api
|
|
28
|
+
* .fromFHIRPackages(['hl7.fhir.r4.core@4.0.1', 'hl7.fhir.us.core@6.1.0'])
|
|
29
|
+
* .typescript('./src/types/fhir')
|
|
30
|
+
* .withValidation()
|
|
31
|
+
* .generate();
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* ## Architecture
|
|
35
|
+
*
|
|
36
|
+
* The library follows a three-stage architecture:
|
|
37
|
+
*
|
|
38
|
+
* 1. **Input**: FHIR packages, JSON Schema, or custom schemas
|
|
39
|
+
* 2. **TypeSchema**: Universal intermediate representation
|
|
40
|
+
* 3. **Output**: TypeScript, Python, Go, or custom target languages
|
|
41
|
+
*
|
|
42
|
+
* ## Examples
|
|
43
|
+
*
|
|
44
|
+
* ### FHIR Patient with US Core Extensions
|
|
45
|
+
*
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { USCorePatient, USCoreRaceExtension } from './types/fhir';
|
|
48
|
+
*
|
|
49
|
+
* const patient: USCorePatient = {
|
|
50
|
+
* resourceType: 'Patient',
|
|
51
|
+
* identifier: [{ value: 'MRN-123' }],
|
|
52
|
+
* name: [{ family: 'Johnson', given: ['Maria'] }],
|
|
53
|
+
* gender: 'female',
|
|
54
|
+
* extension: [{
|
|
55
|
+
* url: 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-race',
|
|
56
|
+
* extension: [{ url: 'text', valueString: 'Hispanic or Latino' }]
|
|
57
|
+
* } as USCoreRaceExtension]
|
|
58
|
+
* };
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* ### Runtime Validation
|
|
62
|
+
*
|
|
63
|
+
* ```typescript
|
|
64
|
+
* import { isUSCorePatient, validateFHIRResource } from './types/fhir/guards';
|
|
65
|
+
*
|
|
66
|
+
* if (isUSCorePatient(someData)) {
|
|
67
|
+
* // TypeScript knows this is a USCorePatient
|
|
68
|
+
* const validation = await validateFHIRResource(someData);
|
|
69
|
+
* if (validation.valid) {
|
|
70
|
+
* console.log('Valid US Core Patient!');
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @packageDocumentation
|
|
76
|
+
* @module @atomic-ehr/codegen
|
|
77
|
+
* @version 0.0.1
|
|
78
|
+
* @author Atomic EHR Team
|
|
79
|
+
* @since 0.0.1
|
|
80
|
+
*/
|
|
81
|
+
// Export new high-level API (primary)
|
|
82
|
+
export * from "./api/index.js";
|
|
83
|
+
// Export new config system
|
|
84
|
+
export * from "./config.js";
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured Logging System for Atomic Codegen
|
|
3
|
+
*
|
|
4
|
+
* Provides configurable logging with levels, structured output, and context
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Log levels in order of severity
|
|
8
|
+
*/
|
|
9
|
+
export var LogLevel;
|
|
10
|
+
(function (LogLevel) {
|
|
11
|
+
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
12
|
+
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
13
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
14
|
+
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
15
|
+
LogLevel[LogLevel["SILENT"] = 4] = "SILENT";
|
|
16
|
+
})(LogLevel || (LogLevel = {}));
|
|
17
|
+
/**
|
|
18
|
+
* Console output implementation
|
|
19
|
+
*/
|
|
20
|
+
export class ConsoleOutput {
|
|
21
|
+
useStderr;
|
|
22
|
+
constructor(useStderr = false) {
|
|
23
|
+
this.useStderr = useStderr;
|
|
24
|
+
}
|
|
25
|
+
write(entry, formatted) {
|
|
26
|
+
const output = this.useStderr || entry.level >= LogLevel.WARN
|
|
27
|
+
? console.error
|
|
28
|
+
: console.log;
|
|
29
|
+
output(formatted);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* File output implementation
|
|
34
|
+
*/
|
|
35
|
+
export class FileOutput {
|
|
36
|
+
filePath;
|
|
37
|
+
constructor(filePath) {
|
|
38
|
+
this.filePath = filePath;
|
|
39
|
+
}
|
|
40
|
+
async write(_entry, formatted) {
|
|
41
|
+
const _file = Bun.file(this.filePath);
|
|
42
|
+
const content = `${formatted}\n`;
|
|
43
|
+
try {
|
|
44
|
+
// Append to file
|
|
45
|
+
await Bun.write(this.filePath, content, { createPath: true });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
// Fallback to console if file write fails
|
|
49
|
+
console.error(`Failed to write to log file ${this.filePath}:`, error);
|
|
50
|
+
console.error(formatted);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Main logger class
|
|
56
|
+
*/
|
|
57
|
+
export class Logger {
|
|
58
|
+
config;
|
|
59
|
+
constructor(config = {}) {
|
|
60
|
+
this.config = {
|
|
61
|
+
level: LogLevel.INFO,
|
|
62
|
+
format: "pretty",
|
|
63
|
+
includeTimestamp: true,
|
|
64
|
+
includeContext: true,
|
|
65
|
+
colorize: true,
|
|
66
|
+
outputs: [new ConsoleOutput()],
|
|
67
|
+
...config,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Update logger configuration
|
|
72
|
+
*/
|
|
73
|
+
configure(config) {
|
|
74
|
+
this.config = { ...this.config, ...config };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check if a log level should be output
|
|
78
|
+
*/
|
|
79
|
+
shouldLog(level) {
|
|
80
|
+
return level >= this.config.level;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create a log entry
|
|
84
|
+
*/
|
|
85
|
+
createEntry(level, message, context, error, operation) {
|
|
86
|
+
const entry = {
|
|
87
|
+
timestamp: new Date().toISOString(),
|
|
88
|
+
level,
|
|
89
|
+
levelName: LogLevel[level],
|
|
90
|
+
message,
|
|
91
|
+
component: this.config.component,
|
|
92
|
+
};
|
|
93
|
+
if (context && this.config.includeContext) {
|
|
94
|
+
entry.context = context;
|
|
95
|
+
}
|
|
96
|
+
if (operation) {
|
|
97
|
+
entry.operation = operation;
|
|
98
|
+
}
|
|
99
|
+
if (error) {
|
|
100
|
+
entry.error = {
|
|
101
|
+
name: error.name,
|
|
102
|
+
message: error.message,
|
|
103
|
+
stack: error.stack,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return entry;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Format log entry for output
|
|
110
|
+
*/
|
|
111
|
+
formatEntry(entry) {
|
|
112
|
+
switch (this.config.format) {
|
|
113
|
+
case "json":
|
|
114
|
+
return JSON.stringify(entry);
|
|
115
|
+
case "compact":
|
|
116
|
+
return this.formatCompact(entry);
|
|
117
|
+
default:
|
|
118
|
+
return this.formatPretty(entry);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Format entry in compact format
|
|
123
|
+
*/
|
|
124
|
+
formatCompact(entry) {
|
|
125
|
+
const timestamp = this.config.includeTimestamp ? `${entry.timestamp} ` : "";
|
|
126
|
+
const component = entry.component ? `[${entry.component}] ` : "";
|
|
127
|
+
const operation = entry.operation ? `(${entry.operation}) ` : "";
|
|
128
|
+
const level = this.colorizeLevel(entry.levelName, entry.level);
|
|
129
|
+
return `${timestamp}${level} ${component}${operation}${entry.message}`;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Format entry in pretty format
|
|
133
|
+
*/
|
|
134
|
+
formatPretty(entry) {
|
|
135
|
+
let formatted = "";
|
|
136
|
+
// Header line
|
|
137
|
+
const timestamp = this.config.includeTimestamp ? `${entry.timestamp} ` : "";
|
|
138
|
+
const component = entry.component ? `[${entry.component}] ` : "";
|
|
139
|
+
const operation = entry.operation ? `(${entry.operation}) ` : "";
|
|
140
|
+
const level = this.colorizeLevel(entry.levelName.padEnd(5), entry.level);
|
|
141
|
+
formatted += `${timestamp}${level} ${component}${operation}${entry.message}`;
|
|
142
|
+
// Context
|
|
143
|
+
if (entry.context && Object.keys(entry.context).length > 0) {
|
|
144
|
+
formatted += `\n Context: ${JSON.stringify(entry.context, null, 2).split("\n").join("\n ")}`;
|
|
145
|
+
}
|
|
146
|
+
// Error details
|
|
147
|
+
if (entry.error) {
|
|
148
|
+
formatted += `\n Error: [${entry.error.code || entry.error.name}] ${entry.error.message}`;
|
|
149
|
+
if (entry.error.context && Object.keys(entry.error.context).length > 0) {
|
|
150
|
+
formatted += `\n Error Context: ${JSON.stringify(entry.error.context, null, 2).split("\n").join("\n ")}`;
|
|
151
|
+
}
|
|
152
|
+
if (entry.error.suggestions && entry.error.suggestions.length > 0) {
|
|
153
|
+
formatted += `\n Suggestions:\n${entry.error.suggestions.map((s) => ` • ${s}`).join("\n")}`;
|
|
154
|
+
}
|
|
155
|
+
if (entry.level === LogLevel.DEBUG && entry.error.stack) {
|
|
156
|
+
formatted += `\n Stack: ${entry.error.stack.split("\n").join("\n ")}`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return formatted;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Colorize log level if enabled
|
|
163
|
+
*/
|
|
164
|
+
colorizeLevel(levelName, level) {
|
|
165
|
+
if (!this.config.colorize) {
|
|
166
|
+
return levelName;
|
|
167
|
+
}
|
|
168
|
+
const colors = {
|
|
169
|
+
[LogLevel.DEBUG]: "\x1b[36m", // Cyan
|
|
170
|
+
[LogLevel.INFO]: "\x1b[32m", // Green
|
|
171
|
+
[LogLevel.WARN]: "\x1b[33m", // Yellow
|
|
172
|
+
[LogLevel.ERROR]: "\x1b[31m", // Red
|
|
173
|
+
};
|
|
174
|
+
const reset = "\x1b[0m";
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
const color = colors[level] || "";
|
|
177
|
+
return `${color}${levelName}${reset}`;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Write log entry to all outputs
|
|
181
|
+
*/
|
|
182
|
+
async writeEntry(entry) {
|
|
183
|
+
if (!this.shouldLog(entry.level)) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const formatted = this.formatEntry(entry);
|
|
187
|
+
for (const output of this.config.outputs) {
|
|
188
|
+
try {
|
|
189
|
+
await output.write(entry, formatted);
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
// Fallback to console if output fails
|
|
193
|
+
console.error("Logger output failed:", error);
|
|
194
|
+
console.error(formatted);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Log debug message
|
|
200
|
+
*/
|
|
201
|
+
async debug(message, context, operation) {
|
|
202
|
+
const entry = this.createEntry(LogLevel.DEBUG, message, context, undefined, operation);
|
|
203
|
+
await this.writeEntry(entry);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Log info message
|
|
207
|
+
*/
|
|
208
|
+
async info(message, context, operation) {
|
|
209
|
+
const entry = this.createEntry(LogLevel.INFO, message, context, undefined, operation);
|
|
210
|
+
await this.writeEntry(entry);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Log warning message
|
|
214
|
+
*/
|
|
215
|
+
async warn(message, context, operation) {
|
|
216
|
+
const entry = this.createEntry(LogLevel.WARN, message, context, undefined, operation);
|
|
217
|
+
await this.writeEntry(entry);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Log error message
|
|
221
|
+
*/
|
|
222
|
+
async error(message, error, context, operation) {
|
|
223
|
+
const entry = this.createEntry(LogLevel.ERROR, message, context, error, operation);
|
|
224
|
+
await this.writeEntry(entry);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Create a child logger with additional context
|
|
228
|
+
*/
|
|
229
|
+
child(component, context) {
|
|
230
|
+
const childLogger = new Logger({
|
|
231
|
+
...this.config,
|
|
232
|
+
component: this.config.component
|
|
233
|
+
? `${this.config.component}.${component}`
|
|
234
|
+
: component,
|
|
235
|
+
});
|
|
236
|
+
// If context is provided, wrap all logging methods to include it
|
|
237
|
+
if (context) {
|
|
238
|
+
const originalMethods = {
|
|
239
|
+
debug: childLogger.debug.bind(childLogger),
|
|
240
|
+
info: childLogger.info.bind(childLogger),
|
|
241
|
+
warn: childLogger.warn.bind(childLogger),
|
|
242
|
+
error: childLogger.error.bind(childLogger),
|
|
243
|
+
};
|
|
244
|
+
childLogger.debug = (message, additionalContext, operation) => originalMethods.debug(message, { ...context, ...additionalContext }, operation);
|
|
245
|
+
childLogger.info = (message, additionalContext, operation) => originalMethods.info(message, { ...context, ...additionalContext }, operation);
|
|
246
|
+
childLogger.warn = (message, additionalContext, operation) => originalMethods.warn(message, { ...context, ...additionalContext }, operation);
|
|
247
|
+
childLogger.error = (message, error, additionalContext, operation) => originalMethods.error(message, error, { ...context, ...additionalContext }, operation);
|
|
248
|
+
}
|
|
249
|
+
return childLogger;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Default logger instance
|
|
254
|
+
*/
|
|
255
|
+
export const logger = new Logger();
|
|
256
|
+
/**
|
|
257
|
+
* Configure the default logger
|
|
258
|
+
*/
|
|
259
|
+
export function configureLogger(config) {
|
|
260
|
+
logger.configure(config);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Create logger from environment variables and config
|
|
264
|
+
*/
|
|
265
|
+
export function createLoggerFromConfig(config) {
|
|
266
|
+
const level = config?.debug
|
|
267
|
+
? LogLevel.DEBUG
|
|
268
|
+
: config?.verbose
|
|
269
|
+
? LogLevel.INFO
|
|
270
|
+
: config?.logLevel
|
|
271
|
+
? (LogLevel[config.logLevel.toUpperCase()] ??
|
|
272
|
+
LogLevel.INFO)
|
|
273
|
+
: LogLevel.INFO;
|
|
274
|
+
const format = config?.logFormat === "json"
|
|
275
|
+
? "json"
|
|
276
|
+
: config?.logFormat === "compact"
|
|
277
|
+
? "compact"
|
|
278
|
+
: "pretty";
|
|
279
|
+
const outputs = [new ConsoleOutput()];
|
|
280
|
+
if (config?.logFile) {
|
|
281
|
+
outputs.push(new FileOutput(config.logFile));
|
|
282
|
+
}
|
|
283
|
+
return new Logger({
|
|
284
|
+
level,
|
|
285
|
+
format,
|
|
286
|
+
component: config?.component,
|
|
287
|
+
outputs,
|
|
288
|
+
colorize: !config?.logFile, // Disable colors when logging to file
|
|
289
|
+
});
|
|
290
|
+
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Caching system for TypeSchema documents with both in-memory and persistent file-based storage.
|
|
5
5
|
*/
|
|
6
|
-
import type { TypeSchemaConfig } from "../config";
|
|
7
|
-
import type { TypeSchema, TypeSchemaIdentifier } from "./type-schema.types";
|
|
6
|
+
import type { TypeSchemaConfig } from "../config.js";
|
|
7
|
+
import type { TypeSchema, TypeSchemaIdentifier } from "./type-schema.types.js";
|
|
8
8
|
/**
|
|
9
9
|
* TypeSchema Cache with optional persistent storage
|
|
10
10
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/typeschema/cache.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/typeschema/cache.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAW/E;;GAEG;AACH,qBAAa,eAAe;IAC3B,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,QAAQ,CAAC,CAAS;gBAEd,MAAM,CAAC,EAAE,gBAAgB;IAcrC;;OAEG;IACG,GAAG,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5C;;OAEG;IACH,GAAG,CAAC,UAAU,EAAE,oBAAoB,GAAG,UAAU,GAAG,IAAI;IAKxD;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IASxC;;OAEG;IACH,GAAG,CAAC,UAAU,EAAE,oBAAoB,GAAG,OAAO;IAK9C;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAS9B;;OAEG;IACH,MAAM,CAAC,UAAU,EAAE,oBAAoB,GAAG,OAAO;IAKjD;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IASjC;;OAEG;IACH,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU,EAAE;IAU/C;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE;IAUrC;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,IAAI;IAMpC;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAYjC;;OAEG;YACW,YAAY;IA+C1B;;OAEG;YACW,aAAa;IAgC3B;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAgBhC;AAKD;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAKzE;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAC1C,MAAM,CAAC,EAAE,gBAAgB,GACvB,OAAO,CAAC,eAAe,CAAC,CAI1B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAKvC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAEpD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC9B,UAAU,EAAE,oBAAoB,GAC9B,UAAU,GAAG,IAAI,CAEnB;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,oBAAoB,GAAG,OAAO,CAElE"}
|