@skmtc/core 0.55.0 → 0.56.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.
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Represents a rendered file with metadata.
3
+ */
4
+ export type FileObject = {
5
+ /** The rendered file content */
6
+ content: string;
7
+ /** The original file path */
8
+ path: string;
9
+ /** The resolved destination path */
10
+ destinationPath: string;
11
+ /** Number of lines in the rendered content */
12
+ lines: number;
13
+ /** Number of characters in the rendered content */
14
+ characters: number;
15
+ };
16
+ /**
17
+ * Arguments for rendering a single file.
18
+ */
19
+ type RenderFileArgs = {
20
+ /** The raw file content to render */
21
+ content: string;
22
+ /** The destination path for the file */
23
+ destinationPath: string;
24
+ /** Optional base path for path resolution */
25
+ basePath?: string;
26
+ };
27
+ /**
28
+ * Renders a single file with metadata calculation.
29
+ *
30
+ * This function processes a single file through the rendering pipeline,
31
+ * calculating file metadata such as line count and character count. It
32
+ * resolves the final path using the base path configuration.
33
+ *
34
+ * @param args - File rendering arguments
35
+ * @returns A FileObject with content and metadata
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const fileObject = renderFile({
40
+ * content: 'const x = 1;',
41
+ * destinationPath: 'utils.ts',
42
+ * basePath: './src'
43
+ * });
44
+ *
45
+ * console.log(fileObject.path); // './src/utils.ts'
46
+ * console.log(fileObject.content); // 'const x = 1;'
47
+ * console.log(fileObject.lines); // 1
48
+ * console.log(fileObject.characters); // 12
49
+ * ```
50
+ */
51
+ export declare const renderFile: ({ content, destinationPath, basePath }: RenderFileArgs) => FileObject;
52
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderFile = void 0;
4
+ const toResolvedArtifactPath_js_1 = require("../helpers/toResolvedArtifactPath.js");
5
+ /**
6
+ * Renders a single file with metadata calculation.
7
+ *
8
+ * This function processes a single file through the rendering pipeline,
9
+ * calculating file metadata such as line count and character count. It
10
+ * resolves the final path using the base path configuration.
11
+ *
12
+ * @param args - File rendering arguments
13
+ * @returns A FileObject with content and metadata
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const fileObject = renderFile({
18
+ * content: 'const x = 1;',
19
+ * destinationPath: 'utils.ts',
20
+ * basePath: './src'
21
+ * });
22
+ *
23
+ * console.log(fileObject.path); // './src/utils.ts'
24
+ * console.log(fileObject.content); // 'const x = 1;'
25
+ * console.log(fileObject.lines); // 1
26
+ * console.log(fileObject.characters); // 12
27
+ * ```
28
+ */
29
+ const renderFile = ({ content, destinationPath, basePath }) => {
30
+ const path = (0, toResolvedArtifactPath_js_1.toResolvedArtifactPath)({ basePath, destinationPath });
31
+ return {
32
+ content: content,
33
+ path,
34
+ destinationPath,
35
+ lines: content.split('\n').length,
36
+ characters: content.length
37
+ };
38
+ };
39
+ exports.renderFile = renderFile;
@@ -67,6 +67,25 @@ type TransformArgs = {
67
67
  * the generate/render pipeline is unaffected.
68
68
  */
69
69
  inspect?: boolean;
70
+ /**
71
+ * Called with each file of the run when the file is complete: its path, as
72
+ * a key of `artifacts`, and its text. The run then keeps no file's text,
73
+ * and `artifacts` of the result is empty; `manifest.files` has every file.
74
+ *
75
+ * For an OpenAPI document the run gives a file as soon as no subject left
76
+ * to run can write to it or read from it, so that a host can write it and
77
+ * the run can let it go. That run goes subject by subject, and writes the
78
+ * same files. A file can have its definitions in another order when more
79
+ * than one generator inserts into it, as when an operation generator that
80
+ * the config lists before a model generator inserts that generator's
81
+ * projection: each subject runs every generator before the next subject
82
+ * runs, and the models run first. A run with `attribution.postPass` or
83
+ * `inspect`, or of a GraphQL document, gives every file at the end.
84
+ *
85
+ * A run that fails has no files. What it gave before it failed, the host
86
+ * must drop. After the first subject that fails it gives no more.
87
+ */
88
+ onArtifact?: (path: string, content: string) => void;
70
89
  };
71
90
  /**
72
91
  * Transforms an OpenAPI v3 document into generated code artifacts and metadata.
@@ -136,7 +155,7 @@ type TransformArgs = {
136
155
  * }
137
156
  * ```
138
157
  */
139
- export declare const toArtifacts: ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, logLevel, stackTrail, attribution, inspect }: TransformArgs) => {
158
+ export declare const toArtifacts: ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, logLevel, stackTrail, attribution, inspect, onArtifact }: TransformArgs) => {
140
159
  artifacts: Record<string, string>;
141
160
  manifest: ManifestContent;
142
161
  /** The run's log lines (see {@link LogLine}). Not part of the manifest. */
@@ -70,7 +70,7 @@ const CoreContext_js_1 = require("../context/CoreContext.js");
70
70
  * }
71
71
  * ```
72
72
  */
73
- const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, logLevel, stackTrail, attribution, inspect }) => {
73
+ const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap, logsPath, startAt, silent, logLevel, stackTrail, attribution, inspect, onArtifact }) => {
74
74
  const context = new CoreContext_js_1.CoreContext({ spanId, logsPath, silent, logLevel });
75
75
  const { artifacts, files, previews, results, parseIssues, enrichmentWarnings, sidecars, generationMap, inspection, logs } = context.toArtifacts({
76
76
  settings,
@@ -79,7 +79,8 @@ const toArtifacts = ({ traceId, spanId, document, settings, toGeneratorConfigMap
79
79
  stackTrail,
80
80
  silent,
81
81
  attribution,
82
- inspect
82
+ inspect,
83
+ onArtifact
83
84
  });
84
85
  const manifest = {
85
86
  files,