@skmtc/core 0.0.782 → 0.0.783
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/esm/context/CoreContext.d.ts +175 -0
- package/esm/context/CoreContext.d.ts.map +1 -1
- package/esm/context/CoreContext.js +178 -0
- package/esm/dsl/ContentBase.d.ts +115 -0
- package/esm/dsl/ContentBase.d.ts.map +1 -1
- package/esm/dsl/ContentBase.js +110 -0
- package/esm/helpers/strings.d.ts +63 -0
- package/esm/helpers/strings.d.ts.map +1 -1
- package/esm/helpers/strings.js +59 -0
- package/esm/mod.d.ts +66 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +66 -0
- package/esm/run/toArtifacts.d.ts +114 -0
- package/esm/run/toArtifacts.d.ts.map +1 -1
- package/esm/run/toArtifacts.js +86 -0
- package/esm/types/Settings.d.ts +129 -0
- package/esm/types/Settings.d.ts.map +1 -1
- package/esm/types/Settings.js +3 -0
- package/esm/typescript/List.d.ts +111 -0
- package/esm/typescript/List.d.ts.map +1 -1
- package/esm/typescript/List.js +106 -0
- package/package.json +1 -1
- package/script/context/CoreContext.d.ts +175 -0
- package/script/context/CoreContext.d.ts.map +1 -1
- package/script/context/CoreContext.js +178 -0
- package/script/dsl/ContentBase.d.ts +115 -0
- package/script/dsl/ContentBase.d.ts.map +1 -1
- package/script/dsl/ContentBase.js +110 -0
- package/script/helpers/strings.d.ts +63 -0
- package/script/helpers/strings.d.ts.map +1 -1
- package/script/helpers/strings.js +59 -0
- package/script/mod.d.ts +66 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +66 -0
- package/script/run/toArtifacts.d.ts +114 -0
- package/script/run/toArtifacts.d.ts.map +1 -1
- package/script/run/toArtifacts.js +86 -0
- package/script/types/Settings.d.ts +129 -0
- package/script/types/Settings.d.ts.map +1 -1
- package/script/types/Settings.js +3 -0
- package/script/typescript/List.d.ts +111 -0
- package/script/typescript/List.d.ts.map +1 -1
- package/script/typescript/List.js +106 -0
package/script/mod.d.ts
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module SKMTC Core
|
|
3
|
+
*
|
|
4
|
+
* SKMTC (Schema Kit Mapping & Type Conversion) is a powerful TypeScript/Deno library
|
|
5
|
+
* for processing OpenAPI v3 documents and generating code artifacts. It provides a
|
|
6
|
+
* comprehensive three-phase pipeline for parsing, generating, and rendering OpenAPI
|
|
7
|
+
* schemas into various output formats.
|
|
8
|
+
*
|
|
9
|
+
* ## Quick Start
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { toArtifacts } from '@skmtc/core';
|
|
13
|
+
*
|
|
14
|
+
* const result = await toArtifacts({
|
|
15
|
+
* traceId: 'my-trace',
|
|
16
|
+
* spanId: 'my-span',
|
|
17
|
+
* documentObject: openApiDoc,
|
|
18
|
+
* settings: clientSettings,
|
|
19
|
+
* toGeneratorConfigMap: () => generatorMap,
|
|
20
|
+
* startAt: Date.now(),
|
|
21
|
+
* silent: false
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* console.log(result.artifacts); // Generated code files
|
|
25
|
+
* console.log(result.manifest); // Generation metadata
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* ## Architecture
|
|
29
|
+
*
|
|
30
|
+
* The library follows a three-phase pipeline:
|
|
31
|
+
* - **Parse Phase**: Converts OpenAPI v3 JSON into internal OAS objects
|
|
32
|
+
* - **Generate Phase**: Transforms OAS objects into generator artifacts
|
|
33
|
+
* - **Render Phase**: Renders artifacts to formatted files
|
|
34
|
+
*
|
|
35
|
+
* ## Key Components
|
|
36
|
+
*
|
|
37
|
+
* - {@link CoreContext} - Main orchestration class for the pipeline
|
|
38
|
+
* - {@link toArtifacts} - Primary transformation function
|
|
39
|
+
* - {@link ContentBase} - Base class for creating generators
|
|
40
|
+
* - {@link ModelBase} and {@link OperationBase} - DSL building blocks
|
|
41
|
+
* - {@link List} - Powerful string manipulation and code generation utility
|
|
42
|
+
*
|
|
43
|
+
* ## Type System
|
|
44
|
+
*
|
|
45
|
+
* The library provides comprehensive TypeScript types for OpenAPI schemas,
|
|
46
|
+
* generator configurations, and output artifacts. All major types are
|
|
47
|
+
* validated using Valibot schemas for runtime safety.
|
|
48
|
+
*
|
|
49
|
+
* @example Basic Usage
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import { CoreContext } from '@skmtc/core';
|
|
52
|
+
*
|
|
53
|
+
* const context = new CoreContext({
|
|
54
|
+
* spanId: 'my-span',
|
|
55
|
+
* silent: false
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* const result = await context.toArtifacts({
|
|
59
|
+
* documentObject: myOpenApiDoc,
|
|
60
|
+
* settings: mySettings,
|
|
61
|
+
* toGeneratorConfigMap: () => myGenerators,
|
|
62
|
+
* prettier: prettierConfig,
|
|
63
|
+
* silent: false
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
1
67
|
import "./_dnt.polyfills.js";
|
|
2
68
|
export * from './app/validate.js';
|
|
3
69
|
export * from './context/CoreContext.js';
|
package/script/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,OAAO,qBAAqB,CAAC;AAG7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBA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AAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mCAAmC,CAAA;AACjD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,sBAAsB,CAAA;AACpC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,uCAAuC,CAAA;AACrD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iCAAiC,CAAA"}
|
package/script/mod.js
CHANGED
|
@@ -14,6 +14,72 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* @module SKMTC Core
|
|
19
|
+
*
|
|
20
|
+
* SKMTC (Schema Kit Mapping & Type Conversion) is a powerful TypeScript/Deno library
|
|
21
|
+
* for processing OpenAPI v3 documents and generating code artifacts. It provides a
|
|
22
|
+
* comprehensive three-phase pipeline for parsing, generating, and rendering OpenAPI
|
|
23
|
+
* schemas into various output formats.
|
|
24
|
+
*
|
|
25
|
+
* ## Quick Start
|
|
26
|
+
*
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { toArtifacts } from '@skmtc/core';
|
|
29
|
+
*
|
|
30
|
+
* const result = await toArtifacts({
|
|
31
|
+
* traceId: 'my-trace',
|
|
32
|
+
* spanId: 'my-span',
|
|
33
|
+
* documentObject: openApiDoc,
|
|
34
|
+
* settings: clientSettings,
|
|
35
|
+
* toGeneratorConfigMap: () => generatorMap,
|
|
36
|
+
* startAt: Date.now(),
|
|
37
|
+
* silent: false
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* console.log(result.artifacts); // Generated code files
|
|
41
|
+
* console.log(result.manifest); // Generation metadata
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* ## Architecture
|
|
45
|
+
*
|
|
46
|
+
* The library follows a three-phase pipeline:
|
|
47
|
+
* - **Parse Phase**: Converts OpenAPI v3 JSON into internal OAS objects
|
|
48
|
+
* - **Generate Phase**: Transforms OAS objects into generator artifacts
|
|
49
|
+
* - **Render Phase**: Renders artifacts to formatted files
|
|
50
|
+
*
|
|
51
|
+
* ## Key Components
|
|
52
|
+
*
|
|
53
|
+
* - {@link CoreContext} - Main orchestration class for the pipeline
|
|
54
|
+
* - {@link toArtifacts} - Primary transformation function
|
|
55
|
+
* - {@link ContentBase} - Base class for creating generators
|
|
56
|
+
* - {@link ModelBase} and {@link OperationBase} - DSL building blocks
|
|
57
|
+
* - {@link List} - Powerful string manipulation and code generation utility
|
|
58
|
+
*
|
|
59
|
+
* ## Type System
|
|
60
|
+
*
|
|
61
|
+
* The library provides comprehensive TypeScript types for OpenAPI schemas,
|
|
62
|
+
* generator configurations, and output artifacts. All major types are
|
|
63
|
+
* validated using Valibot schemas for runtime safety.
|
|
64
|
+
*
|
|
65
|
+
* @example Basic Usage
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { CoreContext } from '@skmtc/core';
|
|
68
|
+
*
|
|
69
|
+
* const context = new CoreContext({
|
|
70
|
+
* spanId: 'my-span',
|
|
71
|
+
* silent: false
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* const result = await context.toArtifacts({
|
|
75
|
+
* documentObject: myOpenApiDoc,
|
|
76
|
+
* settings: mySettings,
|
|
77
|
+
* toGeneratorConfigMap: () => myGenerators,
|
|
78
|
+
* prettier: prettierConfig,
|
|
79
|
+
* silent: false
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
17
83
|
require("./_dnt.polyfills.js");
|
|
18
84
|
__exportStar(require("./app/validate.js"), exports);
|
|
19
85
|
__exportStar(require("./context/CoreContext.js"), exports);
|
|
@@ -3,17 +3,131 @@ import type { PrettierConfigType } from '../types/PrettierConfig.js';
|
|
|
3
3
|
import type { ManifestContent } from '../types/Manifest.js';
|
|
4
4
|
import type { GeneratorsMapContainer } from '../types/GeneratorType.js';
|
|
5
5
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
6
|
+
/**
|
|
7
|
+
* Arguments for the {@link toArtifacts} transformation function.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const args: TransformArgs = {
|
|
12
|
+
* traceId: 'api-generation-v1',
|
|
13
|
+
* spanId: 'user-api-span',
|
|
14
|
+
* documentObject: openApiDocument,
|
|
15
|
+
* settings: {
|
|
16
|
+
* basePath: './generated',
|
|
17
|
+
* skip: { models: ['InternalModel'] }
|
|
18
|
+
* },
|
|
19
|
+
* toGeneratorConfigMap: () => myGeneratorMap,
|
|
20
|
+
* startAt: Date.now(),
|
|
21
|
+
* silent: false
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
6
25
|
type TransformArgs = {
|
|
26
|
+
/** Unique identifier for the transformation trace */
|
|
7
27
|
traceId: string;
|
|
28
|
+
/** Unique identifier for this transformation span */
|
|
8
29
|
spanId: string;
|
|
30
|
+
/** The OpenAPI v3 document to process */
|
|
9
31
|
documentObject: OpenAPIV3.Document;
|
|
32
|
+
/** Client settings for customizing generation behavior */
|
|
10
33
|
settings: ClientSettings | undefined;
|
|
34
|
+
/** Optional Prettier configuration for code formatting */
|
|
11
35
|
prettier?: PrettierConfigType;
|
|
36
|
+
/** Optional path for writing log files */
|
|
12
37
|
logsPath?: string;
|
|
38
|
+
/** Function that returns the generator configuration map */
|
|
13
39
|
toGeneratorConfigMap: <EnrichmentType = undefined>() => GeneratorsMapContainer<EnrichmentType>;
|
|
40
|
+
/** Timestamp when transformation started */
|
|
14
41
|
startAt: number;
|
|
42
|
+
/** Whether to suppress console output during generation */
|
|
15
43
|
silent: boolean;
|
|
16
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Transforms an OpenAPI v3 document into generated code artifacts and metadata.
|
|
47
|
+
*
|
|
48
|
+
* This is the primary function for the SKMTC transformation pipeline. It orchestrates
|
|
49
|
+
* the three-phase process of parsing OpenAPI documents, generating code artifacts,
|
|
50
|
+
* and rendering them to formatted files.
|
|
51
|
+
*
|
|
52
|
+
* The function creates a {@link CoreContext} instance and executes the full pipeline:
|
|
53
|
+
* 1. **Parse**: Converts the OpenAPI document into internal OAS objects
|
|
54
|
+
* 2. **Generate**: Transforms OAS objects using the provided generator configuration
|
|
55
|
+
* 3. **Render**: Formats and prepares the final code artifacts
|
|
56
|
+
*
|
|
57
|
+
* @param args - Configuration for the transformation process
|
|
58
|
+
* @returns A promise resolving to the generated artifacts and manifest
|
|
59
|
+
*
|
|
60
|
+
* @example Basic usage
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { toArtifacts } from '@skmtc/core';
|
|
63
|
+
*
|
|
64
|
+
* const result = await toArtifacts({
|
|
65
|
+
* traceId: 'my-api-generation',
|
|
66
|
+
* spanId: 'user-service',
|
|
67
|
+
* documentObject: myOpenApiDoc,
|
|
68
|
+
* settings: {
|
|
69
|
+
* basePath: './src/generated',
|
|
70
|
+
* skip: {
|
|
71
|
+
* models: ['InternalModel', 'DebugInfo'],
|
|
72
|
+
* operations: {
|
|
73
|
+
* '/internal/**': ['get', 'post']
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
* },
|
|
77
|
+
* toGeneratorConfigMap: () => ({
|
|
78
|
+
* models: modelGenerator,
|
|
79
|
+
* operations: operationGenerator
|
|
80
|
+
* }),
|
|
81
|
+
* startAt: Date.now(),
|
|
82
|
+
* silent: false
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // Access generated files
|
|
86
|
+
* Object.entries(result.artifacts).forEach(([path, content]) => {
|
|
87
|
+
* console.log(`Generated: ${path}`);
|
|
88
|
+
* await Deno.writeTextFile(path, content);
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* // Access generation metadata
|
|
92
|
+
* console.log(`Generated ${Object.keys(result.manifest.files).length} files`);
|
|
93
|
+
* console.log(`Generation took ${result.manifest.endAt - result.manifest.startAt}ms`);
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example With Prettier formatting
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const result = await toArtifacts({
|
|
99
|
+
* traceId: 'formatted-generation',
|
|
100
|
+
* spanId: 'api-client',
|
|
101
|
+
* documentObject: openApiDoc,
|
|
102
|
+
* settings: clientSettings,
|
|
103
|
+
* prettier: {
|
|
104
|
+
* semi: true,
|
|
105
|
+
* singleQuote: true,
|
|
106
|
+
* trailingComma: 'es5'
|
|
107
|
+
* },
|
|
108
|
+
* toGeneratorConfigMap: () => generatorMap,
|
|
109
|
+
* startAt: Date.now(),
|
|
110
|
+
* silent: true
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @example Error handling
|
|
115
|
+
* ```typescript
|
|
116
|
+
* try {
|
|
117
|
+
* const result = await toArtifacts(transformArgs);
|
|
118
|
+
*
|
|
119
|
+
* // Check for generation errors in the results
|
|
120
|
+
* const hasErrors = Object.values(result.manifest.results)
|
|
121
|
+
* .some(result => result === 'error');
|
|
122
|
+
*
|
|
123
|
+
* if (hasErrors) {
|
|
124
|
+
* console.warn('Generation completed with errors');
|
|
125
|
+
* }
|
|
126
|
+
* } catch (error) {
|
|
127
|
+
* console.error('Transformation failed:', error);
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
17
131
|
export declare const toArtifacts: ({ traceId, spanId, documentObject, settings, prettier, toGeneratorConfigMap, logsPath, startAt, silent }: TransformArgs) => Promise<{
|
|
18
132
|
artifacts: Record<string, string>;
|
|
19
133
|
manifest: ManifestContent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toArtifacts.d.ts","sourceRoot":"","sources":["../../src/run/toArtifacts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAEpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"toArtifacts.d.ts","sourceRoot":"","sources":["../../src/run/toArtifacts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAEpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,KAAK,aAAa,GAAG;IACnB,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAA;IACf,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAA;IACd,yCAAyC;IACzC,cAAc,EAAE,SAAS,CAAC,QAAQ,CAAA;IAClC,0DAA0D;IAC1D,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAA;IACpC,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,kBAAkB,CAAA;IAC7B,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4DAA4D;IAC5D,oBAAoB,EAAE,CAAC,cAAc,GAAG,SAAS,OAAO,sBAAsB,CAAC,cAAc,CAAC,CAAA;IAC9F,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAA;IACf,2DAA2D;IAC3D,MAAM,EAAE,OAAO,CAAA;CAChB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqFG;AACH,eAAO,MAAM,WAAW,GAAU,0GAU/B,aAAa,KAAG,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,QAAQ,EAAE,eAAe,CAAA;CAAE,CAyB1F,CAAA"}
|
|
@@ -36,6 +36,92 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.toArtifacts = void 0;
|
|
37
37
|
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
38
38
|
const CoreContext_js_1 = require("../context/CoreContext.js");
|
|
39
|
+
/**
|
|
40
|
+
* Transforms an OpenAPI v3 document into generated code artifacts and metadata.
|
|
41
|
+
*
|
|
42
|
+
* This is the primary function for the SKMTC transformation pipeline. It orchestrates
|
|
43
|
+
* the three-phase process of parsing OpenAPI documents, generating code artifacts,
|
|
44
|
+
* and rendering them to formatted files.
|
|
45
|
+
*
|
|
46
|
+
* The function creates a {@link CoreContext} instance and executes the full pipeline:
|
|
47
|
+
* 1. **Parse**: Converts the OpenAPI document into internal OAS objects
|
|
48
|
+
* 2. **Generate**: Transforms OAS objects using the provided generator configuration
|
|
49
|
+
* 3. **Render**: Formats and prepares the final code artifacts
|
|
50
|
+
*
|
|
51
|
+
* @param args - Configuration for the transformation process
|
|
52
|
+
* @returns A promise resolving to the generated artifacts and manifest
|
|
53
|
+
*
|
|
54
|
+
* @example Basic usage
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { toArtifacts } from '@skmtc/core';
|
|
57
|
+
*
|
|
58
|
+
* const result = await toArtifacts({
|
|
59
|
+
* traceId: 'my-api-generation',
|
|
60
|
+
* spanId: 'user-service',
|
|
61
|
+
* documentObject: myOpenApiDoc,
|
|
62
|
+
* settings: {
|
|
63
|
+
* basePath: './src/generated',
|
|
64
|
+
* skip: {
|
|
65
|
+
* models: ['InternalModel', 'DebugInfo'],
|
|
66
|
+
* operations: {
|
|
67
|
+
* '/internal/**': ['get', 'post']
|
|
68
|
+
* }
|
|
69
|
+
* }
|
|
70
|
+
* },
|
|
71
|
+
* toGeneratorConfigMap: () => ({
|
|
72
|
+
* models: modelGenerator,
|
|
73
|
+
* operations: operationGenerator
|
|
74
|
+
* }),
|
|
75
|
+
* startAt: Date.now(),
|
|
76
|
+
* silent: false
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Access generated files
|
|
80
|
+
* Object.entries(result.artifacts).forEach(([path, content]) => {
|
|
81
|
+
* console.log(`Generated: ${path}`);
|
|
82
|
+
* await Deno.writeTextFile(path, content);
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // Access generation metadata
|
|
86
|
+
* console.log(`Generated ${Object.keys(result.manifest.files).length} files`);
|
|
87
|
+
* console.log(`Generation took ${result.manifest.endAt - result.manifest.startAt}ms`);
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @example With Prettier formatting
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const result = await toArtifacts({
|
|
93
|
+
* traceId: 'formatted-generation',
|
|
94
|
+
* spanId: 'api-client',
|
|
95
|
+
* documentObject: openApiDoc,
|
|
96
|
+
* settings: clientSettings,
|
|
97
|
+
* prettier: {
|
|
98
|
+
* semi: true,
|
|
99
|
+
* singleQuote: true,
|
|
100
|
+
* trailingComma: 'es5'
|
|
101
|
+
* },
|
|
102
|
+
* toGeneratorConfigMap: () => generatorMap,
|
|
103
|
+
* startAt: Date.now(),
|
|
104
|
+
* silent: true
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example Error handling
|
|
109
|
+
* ```typescript
|
|
110
|
+
* try {
|
|
111
|
+
* const result = await toArtifacts(transformArgs);
|
|
112
|
+
*
|
|
113
|
+
* // Check for generation errors in the results
|
|
114
|
+
* const hasErrors = Object.values(result.manifest.results)
|
|
115
|
+
* .some(result => result === 'error');
|
|
116
|
+
*
|
|
117
|
+
* if (hasErrors) {
|
|
118
|
+
* console.warn('Generation completed with errors');
|
|
119
|
+
* }
|
|
120
|
+
* } catch (error) {
|
|
121
|
+
* console.error('Transformation failed:', error);
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
39
125
|
const toArtifacts = async ({ traceId, spanId, documentObject, settings, prettier, toGeneratorConfigMap, logsPath, startAt, silent }) => {
|
|
40
126
|
const context = new CoreContext_js_1.CoreContext({ spanId, logsPath, silent });
|
|
41
127
|
const { artifacts, files, previews, results, mappings } = await context.toArtifacts({
|
|
@@ -2,23 +2,152 @@ import "../_dnt.polyfills.js";
|
|
|
2
2
|
import { type GeneratorEnrichments } from './Enrichments.js';
|
|
3
3
|
import * as v from 'valibot';
|
|
4
4
|
import { type Method } from './Method.js';
|
|
5
|
+
/**
|
|
6
|
+
* Valibot schema for {@link ModulePackage}.
|
|
7
|
+
*/
|
|
5
8
|
export declare const modulePackage: v.GenericSchema<ModulePackage>;
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for a module package in the generation output.
|
|
11
|
+
*
|
|
12
|
+
* Module packages allow organizing generated code into separate npm packages
|
|
13
|
+
* or modules with custom root paths and naming conventions.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const packages: ModulePackage[] = [
|
|
18
|
+
* {
|
|
19
|
+
* rootPath: './packages/api-client',
|
|
20
|
+
* moduleName: '@myorg/api-client'
|
|
21
|
+
* },
|
|
22
|
+
* {
|
|
23
|
+
* rootPath: './packages/types',
|
|
24
|
+
* moduleName: '@myorg/api-types'
|
|
25
|
+
* }
|
|
26
|
+
* ];
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
6
29
|
export type ModulePackage = {
|
|
30
|
+
/** The root file system path for this package */
|
|
7
31
|
rootPath: string;
|
|
32
|
+
/** Optional module name for package.json or imports */
|
|
8
33
|
moduleName?: string;
|
|
9
34
|
};
|
|
10
35
|
export declare const skipPaths: v.GenericSchema<SkipPaths>;
|
|
11
36
|
export declare const skipOperations: v.GenericSchema<SkipOperations>;
|
|
12
37
|
export declare const skipModels: v.GenericSchema<SkipModels>;
|
|
13
38
|
export declare const clientSettings: v.GenericSchema<ClientSettings>;
|
|
39
|
+
/**
|
|
40
|
+
* Configuration for skipping specific HTTP methods on API paths.
|
|
41
|
+
*
|
|
42
|
+
* Maps path patterns to arrays of HTTP methods that should be excluded
|
|
43
|
+
* from generation.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const skipPaths: SkipPaths = {
|
|
48
|
+
* '/admin/**': ['get', 'post'],
|
|
49
|
+
* '/debug': ['*'] // Skip all methods
|
|
50
|
+
* };
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
14
53
|
export type SkipPaths = Record<string, Method[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for skipping model generation by generator type.
|
|
56
|
+
*
|
|
57
|
+
* Maps generator keys to arrays of model names that should be excluded.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const skipModels: SkipModels = {
|
|
62
|
+
* 'typescript-models': ['InternalModel', 'DebugInfo'],
|
|
63
|
+
* 'validation': ['TempModel*'] // Supports glob patterns
|
|
64
|
+
* };
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
15
67
|
export type SkipModels = Record<string, string[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Configuration for skipping operation generation by generator type.
|
|
70
|
+
*
|
|
71
|
+
* Maps generator keys to {@link SkipPaths} configurations for excluding
|
|
72
|
+
* specific operations from generation.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const skipOperations: SkipOperations = {
|
|
77
|
+
* 'api-client': {
|
|
78
|
+
* '/internal/**': ['*'],
|
|
79
|
+
* '/admin': ['delete']
|
|
80
|
+
* }
|
|
81
|
+
* };
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
16
84
|
export type SkipOperations = Record<string, SkipPaths>;
|
|
85
|
+
/**
|
|
86
|
+
* Union type representing different skip configurations.
|
|
87
|
+
*
|
|
88
|
+
* Can be either operation-specific skipping, model-specific skipping,
|
|
89
|
+
* or a simple string pattern for broad exclusions.
|
|
90
|
+
*/
|
|
17
91
|
export type Skip = SkipOperations | SkipModels | string;
|
|
92
|
+
/**
|
|
93
|
+
* Main configuration object for SKMTC client settings.
|
|
94
|
+
*
|
|
95
|
+
* Controls various aspects of code generation including output paths,
|
|
96
|
+
* package organization, enrichments, and selective skipping of content.
|
|
97
|
+
*
|
|
98
|
+
* @example Basic configuration
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const settings: ClientSettings = {
|
|
101
|
+
* basePath: './src/generated',
|
|
102
|
+
* skip: [
|
|
103
|
+
* 'InternalModel', // Skip specific model
|
|
104
|
+
* {
|
|
105
|
+
* 'api-client': {
|
|
106
|
+
* '/admin/**': ['*'] // Skip all admin operations
|
|
107
|
+
* }
|
|
108
|
+
* }
|
|
109
|
+
* ]
|
|
110
|
+
* };
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @example Advanced configuration with packages
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const settings: ClientSettings = {
|
|
116
|
+
* basePath: './generated',
|
|
117
|
+
* packages: [
|
|
118
|
+
* {
|
|
119
|
+
* rootPath: './packages/client',
|
|
120
|
+
* moduleName: '@company/api-client'
|
|
121
|
+
* },
|
|
122
|
+
* {
|
|
123
|
+
* rootPath: './packages/types',
|
|
124
|
+
* moduleName: '@company/api-types'
|
|
125
|
+
* }
|
|
126
|
+
* ],
|
|
127
|
+
* enrichments: {
|
|
128
|
+
* models: customModelEnrichments,
|
|
129
|
+
* operations: customOperationEnrichments
|
|
130
|
+
* },
|
|
131
|
+
* skip: [
|
|
132
|
+
* {
|
|
133
|
+
* 'models': ['Internal*', 'Debug*'],
|
|
134
|
+
* 'operations': {
|
|
135
|
+
* '/health': ['get'],
|
|
136
|
+
* '/metrics/**': ['*']
|
|
137
|
+
* }
|
|
138
|
+
* }
|
|
139
|
+
* ]
|
|
140
|
+
* };
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
18
143
|
export type ClientSettings = {
|
|
144
|
+
/** Base output path for generated files */
|
|
19
145
|
basePath?: string;
|
|
146
|
+
/** Array of module package configurations */
|
|
20
147
|
packages?: ModulePackage[];
|
|
148
|
+
/** Custom enrichments for extending generation */
|
|
21
149
|
enrichments?: GeneratorEnrichments;
|
|
150
|
+
/** Array of skip configurations to exclude content */
|
|
22
151
|
skip?: Skip[];
|
|
23
152
|
};
|
|
24
153
|
export type SkmtcClientConfig = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Settings.d.ts","sourceRoot":"","sources":["../../src/types/Settings.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,EAAwB,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAClF,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC,aAAa,CAGvD,C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MAAM,CAAA;IACjB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAA;IAC1B,kDAAkD;IAClD,WAAW,CAAC,EAAE,oBAAoB,CAAA;IAClC,sDAAsD;IACtD,IAAI,CAAC,EAAE,IAAI,EAAE,CAAA;CACd,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,cAAc,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,aAAa,CAAC,iBAAiB,CAG/D,CAAA"}
|
package/script/types/Settings.js
CHANGED
|
@@ -38,6 +38,9 @@ require("../_dnt.polyfills.js");
|
|
|
38
38
|
const Enrichments_js_1 = require("./Enrichments.js");
|
|
39
39
|
const v = __importStar(require("valibot"));
|
|
40
40
|
const Method_js_1 = require("./Method.js");
|
|
41
|
+
/**
|
|
42
|
+
* Valibot schema for {@link ModulePackage}.
|
|
43
|
+
*/
|
|
41
44
|
exports.modulePackage = v.object({
|
|
42
45
|
rootPath: v.string(),
|
|
43
46
|
moduleName: v.optional(v.string())
|