@skmtc/core 0.0.295 → 0.0.297
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 +27 -54
- package/esm/context/CoreContext.d.ts.map +1 -1
- package/esm/context/CoreContext.js +103 -139
- package/esm/context/GenerateContext.d.ts +6 -4
- package/esm/context/GenerateContext.d.ts.map +1 -1
- package/esm/context/GenerateContext.js +84 -6
- package/esm/context/ParseContext.d.ts +11 -11
- package/esm/context/ParseContext.d.ts.map +1 -1
- package/esm/context/ParseContext.js +51 -5
- package/esm/context/RenderContext.d.ts +7 -19
- package/esm/context/RenderContext.d.ts.map +1 -1
- package/esm/context/RenderContext.js +55 -85
- package/esm/context/ResultsHandler.d.ts.map +1 -1
- package/esm/context/ResultsHandler.js +2 -6
- package/esm/context/StackTrail.d.ts +10 -0
- package/esm/context/StackTrail.d.ts.map +1 -0
- package/esm/context/StackTrail.js +68 -0
- package/esm/context/types.d.ts +13 -1
- package/esm/context/types.d.ts.map +1 -1
- package/esm/generate/generate.d.ts +6 -3
- package/esm/generate/generate.d.ts.map +1 -1
- package/esm/generate/generate.js +18 -45
- package/esm/mod.d.ts +0 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +0 -1
- package/esm/oas/operation/Operation.d.ts +1 -1
- package/esm/oas/operation/Operation.d.ts.map +1 -1
- package/esm/oas/operation/Operation.js +1 -1
- package/esm/server/createServer.d.ts.map +1 -1
- package/esm/server/createServer.js +12 -13
- package/esm/types/Manifest.d.ts +11 -43
- package/esm/types/Manifest.d.ts.map +1 -1
- package/esm/types/Manifest.js +1 -5
- package/package.json +1 -1
- package/script/context/CoreContext.d.ts +27 -54
- package/script/context/CoreContext.d.ts.map +1 -1
- package/script/context/CoreContext.js +103 -139
- package/script/context/GenerateContext.d.ts +6 -4
- package/script/context/GenerateContext.d.ts.map +1 -1
- package/script/context/GenerateContext.js +106 -5
- package/script/context/ParseContext.d.ts +11 -11
- package/script/context/ParseContext.d.ts.map +1 -1
- package/script/context/ParseContext.js +76 -6
- package/script/context/RenderContext.d.ts +7 -19
- package/script/context/RenderContext.d.ts.map +1 -1
- package/script/context/RenderContext.js +55 -85
- package/script/context/ResultsHandler.d.ts.map +1 -1
- package/script/context/ResultsHandler.js +2 -6
- package/script/context/StackTrail.d.ts +10 -0
- package/script/context/StackTrail.d.ts.map +1 -0
- package/script/context/StackTrail.js +72 -0
- package/script/context/types.d.ts +13 -1
- package/script/context/types.d.ts.map +1 -1
- package/script/generate/generate.d.ts +6 -3
- package/script/generate/generate.d.ts.map +1 -1
- package/script/generate/generate.js +19 -47
- package/script/mod.d.ts +0 -1
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +0 -1
- package/script/oas/operation/Operation.d.ts +1 -1
- package/script/oas/operation/Operation.d.ts.map +1 -1
- package/script/oas/operation/Operation.js +1 -1
- package/script/server/createServer.d.ts.map +1 -1
- package/script/server/createServer.js +11 -12
- package/script/types/Manifest.d.ts +11 -43
- package/script/types/Manifest.d.ts.map +1 -1
- package/script/types/Manifest.js +1 -5
- package/esm/generate/generateModels.d.ts +0 -3
- package/esm/generate/generateModels.d.ts.map +0 -1
- package/esm/generate/generateModels.js +0 -44
- package/esm/generate/generateOperations.d.ts +0 -3
- package/esm/generate/generateOperations.d.ts.map +0 -1
- package/esm/generate/generateOperations.js +0 -53
- package/esm/parse/parse.d.ts +0 -4
- package/esm/parse/parse.d.ts.map +0 -1
- package/esm/parse/parse.js +0 -16
- package/script/generate/generateModels.d.ts +0 -3
- package/script/generate/generateModels.d.ts.map +0 -1
- package/script/generate/generateModels.js +0 -71
- package/script/generate/generateOperations.d.ts +0 -3
- package/script/generate/generateOperations.d.ts.map +0 -1
- package/script/generate/generateOperations.js +0 -80
- package/script/parse/parse.d.ts +0 -4
- package/script/parse/parse.d.ts.map +0 -1
- package/script/parse/parse.js +0 -20
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { GenerateContext } from './GenerateContext.js';
|
|
2
1
|
import type { AddRenderDependencyArgs, GetModelSettingsArgs, GetOperationSettingsArgs, PickArgs, RegisterArgs, InsertReturn, InsertArgs } from './GenerateContext.js';
|
|
3
|
-
import {
|
|
4
|
-
import type { AddGeneratorKeyArgs, FileContents, RenderDependencies, RenderOptions } from './types.js';
|
|
5
|
-
import type { ParseContext } from './ParseContext.js';
|
|
2
|
+
import type { AddGeneratorKeyArgs, FileContents, RenderDependencies } from './types.js';
|
|
6
3
|
import type { PrettierConfigType } from '../types/prettierConfig.js';
|
|
7
4
|
import type { OasDocument } from '../oas/document/Document.js';
|
|
8
|
-
import type { OpenAPIV3 } from 'openapi-types';
|
|
9
5
|
import type { BaseSettings, ClientSettings } from '../types/Settings.js';
|
|
10
6
|
import type { Definition } from '../dsl/Definition.js';
|
|
11
7
|
import type { OperationGenerator } from '../dsl/OperationInsertable.js';
|
|
@@ -15,84 +11,61 @@ import type { OasSchema } from '../oas/schema/Schema.js';
|
|
|
15
11
|
import type { OasRef } from '../oas/ref/Ref.js';
|
|
16
12
|
import type { GenerationType } from '../types/GeneratedValue.js';
|
|
17
13
|
import type { RefName } from '../types/RefName.js';
|
|
18
|
-
import type {
|
|
19
|
-
import type { Results, SuccessWarningError, WarningError } from '../types/Manifest.js';
|
|
14
|
+
import type { SuccessWarningError } from '../types/Manifest.js';
|
|
20
15
|
import * as log from '../deps/jsr.io/@std/log/0.224.6/mod.js';
|
|
21
|
-
|
|
22
|
-
type: 'parse';
|
|
23
|
-
context: ParseContext;
|
|
24
|
-
} | {
|
|
25
|
-
type: 'generate';
|
|
26
|
-
context: GenerateContext;
|
|
27
|
-
} | {
|
|
28
|
-
type: 'render';
|
|
29
|
-
context: RenderContext;
|
|
30
|
-
};
|
|
31
|
-
type GenerateArgs = {
|
|
32
|
-
schemaModel: OasDocument;
|
|
33
|
-
generatorsMap: Record<string, OperationGenerator | ModelGenerator>;
|
|
34
|
-
settings: ClientSettings | undefined;
|
|
35
|
-
};
|
|
16
|
+
import { StackTrail } from './StackTrail.js';
|
|
36
17
|
type CoreContextArgs = {
|
|
37
|
-
traceId: string;
|
|
38
18
|
spanId: string;
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
type RenderArgs = {
|
|
42
|
-
renderDependencies: RenderDependencies;
|
|
43
|
-
packageDependencies: Map<string, string>;
|
|
44
|
-
prettier?: PrettierConfigType;
|
|
45
|
-
settings: ClientSettings | undefined;
|
|
46
|
-
pinnableGenerators: string[];
|
|
19
|
+
schema: string;
|
|
47
20
|
};
|
|
48
21
|
type CaptureResultArgs = {
|
|
49
|
-
|
|
50
|
-
result: WarningError;
|
|
51
|
-
} | {
|
|
52
|
-
phase: 'generate';
|
|
53
|
-
generatorKey: OperationGeneratorKey | ModelGeneratorKey;
|
|
22
|
+
stackTrail: string;
|
|
54
23
|
result: SuccessWarningError;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
24
|
+
};
|
|
25
|
+
type TransformArgs = {
|
|
26
|
+
settings: ClientSettings | undefined;
|
|
27
|
+
generatorsMap: Record<string, OperationGenerator | ModelGenerator>;
|
|
28
|
+
prettier?: PrettierConfigType;
|
|
58
29
|
};
|
|
59
30
|
export declare class CoreContext {
|
|
60
31
|
#private;
|
|
61
|
-
|
|
62
|
-
spanId:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
32
|
+
logger: log.Logger;
|
|
33
|
+
constructor({ schema, spanId }: CoreContextArgs);
|
|
34
|
+
parse(): OasDocument;
|
|
35
|
+
transform({ settings, generatorsMap, prettier }: TransformArgs): {
|
|
36
|
+
results: Record<string, SuccessWarningError | undefined>;
|
|
37
|
+
files: Record<string, import("../types/Manifest.js").ManifestEntry>;
|
|
38
|
+
pinnable: Partial<Record<import("../mod.js").GeneratorKey, string>>;
|
|
39
|
+
renderDependencies: Record<string, string[]>;
|
|
40
|
+
artifacts: Record<string, string>;
|
|
41
|
+
};
|
|
42
|
+
captureResult({ stackTrail, result }: CaptureResultArgs): void;
|
|
43
|
+
captureCurrentResult(result: SuccessWarningError): void;
|
|
68
44
|
get phaseType(): 'parse' | 'generate' | 'render';
|
|
69
|
-
|
|
70
|
-
|
|
45
|
+
appendStackTrailChunk(chunk: string | string[] | StackTrail): void;
|
|
46
|
+
removeStackTrailChunk(chunk: string | string[] | StackTrail): void;
|
|
71
47
|
register({ destinationPath, ...args }: RegisterArgs): void;
|
|
72
48
|
addGeneratorKey({ generatorKey }: AddGeneratorKeyArgs): void;
|
|
73
49
|
resolveSchemaRefOnce(refName: RefName): OasSchema | OasRef<'schema'>;
|
|
74
50
|
addRenderDependency(args: AddRenderDependencyArgs): void;
|
|
75
51
|
getFile(filePath: string): FileContents;
|
|
76
52
|
findDefinition(args: PickArgs): Definition<GeneratedValue> | undefined;
|
|
77
|
-
render(options: RenderOptions): FilesRenderResult;
|
|
78
53
|
addFile(normalisedPath: string): FileContents;
|
|
79
54
|
getOperationBaseSettings(args: GetOperationSettingsArgs): BaseSettings;
|
|
80
55
|
insert<V extends GeneratedValue, T extends GenerationType>(args: InsertArgs<V, T>): InsertReturn<V, T>;
|
|
81
56
|
getModelBaseSettings(args: GetModelSettingsArgs): BaseSettings;
|
|
82
|
-
get results(): Results;
|
|
83
57
|
get files(): Map<string, FileContents>;
|
|
84
58
|
get renderDependencies(): RenderDependencies;
|
|
85
59
|
get packageDependencies(): Map<string, string>;
|
|
86
60
|
get schemaModel(): OasDocument;
|
|
87
61
|
get generatorsMap(): Record<string, OperationGenerator | ModelGenerator>;
|
|
88
|
-
get parsedDocument(): OpenAPIV3.Document;
|
|
89
62
|
get settings(): ClientSettings | undefined;
|
|
90
63
|
}
|
|
91
64
|
export type JsonFormatterArgs = {
|
|
92
65
|
logRecord: log.LogRecord;
|
|
93
|
-
|
|
66
|
+
stackTrail: StackTrail;
|
|
94
67
|
};
|
|
95
|
-
export declare function skmtcFormatter({ logRecord,
|
|
96
|
-
export declare function resultFormatter({ logRecord,
|
|
68
|
+
export declare function skmtcFormatter({ logRecord, stackTrail }: JsonFormatterArgs): string;
|
|
69
|
+
export declare function resultFormatter({ logRecord, stackTrail }: JsonFormatterArgs): string;
|
|
97
70
|
export {};
|
|
98
71
|
//# sourceMappingURL=CoreContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoreContext.d.ts","sourceRoot":"","sources":["../../src/context/CoreContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CoreContext.d.ts","sourceRoot":"","sources":["../../src/context/CoreContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,EACxB,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,EACX,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,EACnB,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE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9,21 +9,18 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _CoreContext_phase, _CoreContext_results;
|
|
12
|
+
var _CoreContext_instances, _CoreContext_phase, _CoreContext_results, _CoreContext_stackTrail, _CoreContext_setupLogger, _CoreContext_getStackTrail, _CoreContext_setupParsePhase, _CoreContext_setupGeneratePhase, _CoreContext_setupRenderPhase;
|
|
13
13
|
import { GenerateContext } from './GenerateContext.js';
|
|
14
14
|
import { match } from 'ts-pattern';
|
|
15
15
|
import { RenderContext } from './RenderContext.js';
|
|
16
|
+
import { ParseContext } from './ParseContext.js';
|
|
16
17
|
import * as log from '../deps/jsr.io/@std/log/0.224.6/mod.js';
|
|
17
18
|
import { ResultsHandler } from './ResultsHandler.js';
|
|
19
|
+
import { StackTrail } from './StackTrail.js';
|
|
18
20
|
export class CoreContext {
|
|
19
|
-
constructor({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
configurable: true,
|
|
23
|
-
writable: true,
|
|
24
|
-
value: void 0
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(this, "spanId", {
|
|
21
|
+
constructor({ schema, spanId }) {
|
|
22
|
+
_CoreContext_instances.add(this);
|
|
23
|
+
Object.defineProperty(this, "logger", {
|
|
27
24
|
enumerable: true,
|
|
28
25
|
configurable: true,
|
|
29
26
|
writable: true,
|
|
@@ -31,111 +28,63 @@ export class CoreContext {
|
|
|
31
28
|
});
|
|
32
29
|
_CoreContext_phase.set(this, void 0);
|
|
33
30
|
_CoreContext_results.set(this, void 0);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
40
|
-
this.traceId = traceId;
|
|
41
|
-
this.spanId = spanId;
|
|
42
|
-
log.setup({
|
|
43
|
-
handlers: {
|
|
44
|
-
[`${spanId}-logs`]: new log.ConsoleHandler('DEBUG', {
|
|
45
|
-
formatter: logRecord => skmtcFormatter({ logRecord, context: this }),
|
|
46
|
-
useColors: false
|
|
47
|
-
}),
|
|
48
|
-
[`${spanId}-results`]: new ResultsHandler('WARN', {
|
|
49
|
-
formatter: logRecord => resultFormatter({ logRecord, context: this }),
|
|
50
|
-
context: this
|
|
51
|
-
})
|
|
52
|
-
},
|
|
53
|
-
loggers: {
|
|
54
|
-
[spanId]: {
|
|
55
|
-
level: 'DEBUG',
|
|
56
|
-
handlers: [`${spanId}-logs`, `${spanId}-results`]
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
31
|
+
_CoreContext_stackTrail.set(this, void 0);
|
|
32
|
+
__classPrivateFieldSet(this, _CoreContext_stackTrail, new StackTrail([spanId]), "f");
|
|
33
|
+
__classPrivateFieldSet(this, _CoreContext_results, {}, "f");
|
|
34
|
+
this.logger = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupLogger).call(this, spanId);
|
|
35
|
+
__classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, schema), "f");
|
|
60
36
|
}
|
|
61
|
-
|
|
62
|
-
|
|
37
|
+
parse() {
|
|
38
|
+
if (__classPrivateFieldGet(this, _CoreContext_phase, "f").type !== 'parse') {
|
|
39
|
+
throw new Error(`Expected 'parse' phase, got '${__classPrivateFieldGet(this, _CoreContext_phase, "f").type}'`);
|
|
40
|
+
}
|
|
41
|
+
return __classPrivateFieldGet(this, _CoreContext_phase, "f").context.parse(this);
|
|
63
42
|
}
|
|
64
|
-
|
|
65
|
-
|
|
43
|
+
transform({ settings, generatorsMap, prettier }) {
|
|
44
|
+
if (__classPrivateFieldGet(this, _CoreContext_phase, "f").type !== 'parse') {
|
|
45
|
+
throw new Error(`Expected 'parse' phase, got '${__classPrivateFieldGet(this, _CoreContext_phase, "f").type}'`);
|
|
46
|
+
}
|
|
47
|
+
const schemaModel = __classPrivateFieldGet(this, _CoreContext_phase, "f").context.parse(this);
|
|
48
|
+
__classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
66
49
|
schemaModel,
|
|
67
50
|
settings,
|
|
68
51
|
generatorsMap
|
|
69
|
-
});
|
|
70
|
-
|
|
52
|
+
}), "f");
|
|
53
|
+
__classPrivateFieldGet(this, _CoreContext_phase, "f").context.generate(this);
|
|
54
|
+
__classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupRenderPhase).call(this, {
|
|
55
|
+
renderDependencies: this.renderDependencies,
|
|
56
|
+
packageDependencies: this.packageDependencies,
|
|
57
|
+
pinnableGenerators: Object.values(this.generatorsMap)
|
|
58
|
+
.map(({ id, pinnable }) => (pinnable ? id : null))
|
|
59
|
+
.filter(generatorId => generatorId !== null),
|
|
60
|
+
prettier,
|
|
61
|
+
settings
|
|
62
|
+
}), "f");
|
|
63
|
+
const renderOutput = __classPrivateFieldGet(this, _CoreContext_phase, "f").context.render({});
|
|
64
|
+
return {
|
|
65
|
+
...renderOutput,
|
|
66
|
+
results: __classPrivateFieldGet(this, _CoreContext_results, "f")
|
|
67
|
+
};
|
|
71
68
|
}
|
|
72
|
-
captureResult(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
__classPrivateFieldGet(this, _CoreContext_results, "f").parse = result;
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
.with({ phase: 'generate' }, ({ generatorKey, result }) => {
|
|
80
|
-
if (applyResult({
|
|
81
|
-
current: __classPrivateFieldGet(this, _CoreContext_results, "f").generate[generatorKey],
|
|
82
|
-
incoming: result
|
|
83
|
-
})) {
|
|
84
|
-
__classPrivateFieldGet(this, _CoreContext_results, "f").generate[generatorKey] = result;
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
.with({ phase: 'render' }, ({ result }) => {
|
|
88
|
-
if (applyResult({ current: __classPrivateFieldGet(this, _CoreContext_results, "f").render, incoming: result })) {
|
|
89
|
-
__classPrivateFieldGet(this, _CoreContext_results, "f").render = result;
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
.exhaustive();
|
|
69
|
+
captureResult({ stackTrail, result }) {
|
|
70
|
+
if (applyResult({ current: __classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail], incoming: result })) {
|
|
71
|
+
__classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail] = result;
|
|
72
|
+
}
|
|
93
73
|
}
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
files: this.files,
|
|
100
|
-
renderDependencies,
|
|
101
|
-
packageDependencies,
|
|
102
|
-
prettier,
|
|
103
|
-
settings,
|
|
104
|
-
pinnableGenerators
|
|
105
|
-
});
|
|
106
|
-
__classPrivateFieldSet(this, _CoreContext_phase, { type: 'render', context: renderContext }, "f");
|
|
74
|
+
captureCurrentResult(result) {
|
|
75
|
+
const stackTrail = __classPrivateFieldGet(this, _CoreContext_stackTrail, "f").toString();
|
|
76
|
+
if (applyResult({ current: __classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail], incoming: result })) {
|
|
77
|
+
__classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail] = result;
|
|
78
|
+
}
|
|
107
79
|
}
|
|
108
80
|
get phaseType() {
|
|
109
81
|
return __classPrivateFieldGet(this, _CoreContext_phase, "f").type;
|
|
110
82
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
114
|
-
.with({ type: 'generate' }, ({ context }) => {
|
|
115
|
-
context.setCurrentLocation(location);
|
|
116
|
-
})
|
|
117
|
-
.with({ type: 'parse' }, () => {
|
|
118
|
-
throw new Error(`Cannot set current location during parse phase`);
|
|
119
|
-
})
|
|
120
|
-
.with({ type: 'render' }, () => {
|
|
121
|
-
throw new Error(`Cannot set current location during render phase`);
|
|
122
|
-
})
|
|
123
|
-
.exhaustive();
|
|
83
|
+
appendStackTrailChunk(chunk) {
|
|
84
|
+
__classPrivateFieldGet(this, _CoreContext_stackTrail, "f").append(chunk);
|
|
124
85
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
phase: __classPrivateFieldGet(this, _CoreContext_phase, "f").type,
|
|
128
|
-
traceId: this.traceId,
|
|
129
|
-
spanId: this.spanId
|
|
130
|
-
};
|
|
131
|
-
return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
132
|
-
.with({ type: 'generate' }, ({ context }) => ({
|
|
133
|
-
...logFields,
|
|
134
|
-
...context.getLogFields()
|
|
135
|
-
}))
|
|
136
|
-
.with({ type: 'parse' }, () => logFields)
|
|
137
|
-
.with({ type: 'render' }, () => logFields)
|
|
138
|
-
.exhaustive();
|
|
86
|
+
removeStackTrailChunk(chunk) {
|
|
87
|
+
__classPrivateFieldGet(this, _CoreContext_stackTrail, "f").remove(chunk);
|
|
139
88
|
}
|
|
140
89
|
register({ destinationPath, ...args }) {
|
|
141
90
|
return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
@@ -211,17 +160,6 @@ export class CoreContext {
|
|
|
211
160
|
.with({ type: 'render' }, ({ context }) => context.pick(args))
|
|
212
161
|
.exhaustive();
|
|
213
162
|
}
|
|
214
|
-
render(options) {
|
|
215
|
-
return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
216
|
-
.with({ type: 'generate' }, () => {
|
|
217
|
-
throw new Error(`Cannot render during generate phase`);
|
|
218
|
-
})
|
|
219
|
-
.with({ type: 'parse' }, () => {
|
|
220
|
-
throw new Error(`Cannot render during parse phase`);
|
|
221
|
-
})
|
|
222
|
-
.with({ type: 'render' }, ({ context }) => context.render(options))
|
|
223
|
-
.exhaustive();
|
|
224
|
-
}
|
|
225
163
|
addFile(normalisedPath) {
|
|
226
164
|
return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
227
165
|
.with({ type: 'generate' }, ({ context }) => {
|
|
@@ -274,9 +212,6 @@ export class CoreContext {
|
|
|
274
212
|
})
|
|
275
213
|
.exhaustive();
|
|
276
214
|
}
|
|
277
|
-
get results() {
|
|
278
|
-
return __classPrivateFieldGet(this, _CoreContext_results, "f");
|
|
279
|
-
}
|
|
280
215
|
get files() {
|
|
281
216
|
return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
282
217
|
.with({ type: 'generate' }, ({ context }) => context.files)
|
|
@@ -326,17 +261,6 @@ export class CoreContext {
|
|
|
326
261
|
})
|
|
327
262
|
.exhaustive();
|
|
328
263
|
}
|
|
329
|
-
get parsedDocument() {
|
|
330
|
-
return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
331
|
-
.with({ type: 'parse' }, ({ context }) => context.parsedDocument)
|
|
332
|
-
.with({ type: 'generate' }, () => {
|
|
333
|
-
throw new Error(`Cannot access parsed document during generate phase`);
|
|
334
|
-
})
|
|
335
|
-
.with({ type: 'render' }, () => {
|
|
336
|
-
throw new Error(`Cannot access parsed document during render phase`);
|
|
337
|
-
})
|
|
338
|
-
.exhaustive();
|
|
339
|
-
}
|
|
340
264
|
get settings() {
|
|
341
265
|
return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
342
266
|
.with({ type: 'generate' }, ({ context }) => context.settings)
|
|
@@ -349,15 +273,62 @@ export class CoreContext {
|
|
|
349
273
|
.exhaustive();
|
|
350
274
|
}
|
|
351
275
|
}
|
|
352
|
-
_CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap()
|
|
276
|
+
_CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreContext_stackTrail = new WeakMap(), _CoreContext_instances = new WeakSet(), _CoreContext_setupLogger = function _CoreContext_setupLogger(spanId) {
|
|
277
|
+
log.setup({
|
|
278
|
+
handlers: {
|
|
279
|
+
[`${spanId}-logs`]: new log.ConsoleHandler('DEBUG', {
|
|
280
|
+
formatter: logRecord => skmtcFormatter({ logRecord, stackTrail: __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_getStackTrail).call(this) }),
|
|
281
|
+
useColors: false
|
|
282
|
+
}),
|
|
283
|
+
[`${spanId}-results`]: new ResultsHandler('WARN', {
|
|
284
|
+
formatter: logRecord => resultFormatter({ logRecord, stackTrail: __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_getStackTrail).call(this) }),
|
|
285
|
+
context: this
|
|
286
|
+
})
|
|
287
|
+
},
|
|
288
|
+
loggers: {
|
|
289
|
+
[spanId]: {
|
|
290
|
+
level: 'DEBUG',
|
|
291
|
+
handlers: [`${spanId}-logs`, `${spanId}-results`]
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
return log.getLogger(spanId);
|
|
296
|
+
}, _CoreContext_getStackTrail = function _CoreContext_getStackTrail() {
|
|
297
|
+
const substack = match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
298
|
+
.with({ type: 'parse' }, ({ context }) => context.stackTrail)
|
|
299
|
+
.with({ type: 'generate' }, ({ context }) => context.stackTrail)
|
|
300
|
+
.with({ type: 'render' }, ({ context }) => context.stackTrail)
|
|
301
|
+
.exhaustive();
|
|
302
|
+
return __classPrivateFieldGet(this, _CoreContext_stackTrail, "f").append(substack);
|
|
303
|
+
}, _CoreContext_setupParsePhase = function _CoreContext_setupParsePhase(schema) {
|
|
304
|
+
const parseContext = new ParseContext(schema);
|
|
305
|
+
return { type: 'parse', context: parseContext };
|
|
306
|
+
}, _CoreContext_setupGeneratePhase = function _CoreContext_setupGeneratePhase({ schemaModel, settings, generatorsMap }) {
|
|
307
|
+
const generateContext = new GenerateContext({
|
|
308
|
+
schemaModel,
|
|
309
|
+
settings,
|
|
310
|
+
generatorsMap
|
|
311
|
+
});
|
|
312
|
+
return { type: 'generate', context: generateContext };
|
|
313
|
+
}, _CoreContext_setupRenderPhase = function _CoreContext_setupRenderPhase({ prettier, packageDependencies, settings, renderDependencies, pinnableGenerators }) {
|
|
314
|
+
const renderContext = new RenderContext({
|
|
315
|
+
files: this.files,
|
|
316
|
+
renderDependencies,
|
|
317
|
+
packageDependencies,
|
|
318
|
+
prettier,
|
|
319
|
+
settings,
|
|
320
|
+
pinnableGenerators
|
|
321
|
+
});
|
|
322
|
+
return { type: 'render', context: renderContext };
|
|
323
|
+
};
|
|
353
324
|
const applyResult = ({ current, incoming }) => {
|
|
354
325
|
return (current === undefined ||
|
|
355
326
|
(current === 'success' && incoming !== 'success') ||
|
|
356
327
|
(current === 'warning' && incoming === 'error'));
|
|
357
328
|
};
|
|
358
|
-
export function skmtcFormatter({ logRecord,
|
|
329
|
+
export function skmtcFormatter({ logRecord, stackTrail }) {
|
|
359
330
|
return JSON.stringify({
|
|
360
|
-
|
|
331
|
+
stackTrail,
|
|
361
332
|
level: logRecord.levelName,
|
|
362
333
|
datetime: logRecord.datetime.getTime(),
|
|
363
334
|
message: logRecord.msg,
|
|
@@ -372,13 +343,6 @@ function flattenArgs(args) {
|
|
|
372
343
|
return args;
|
|
373
344
|
}
|
|
374
345
|
}
|
|
375
|
-
export function resultFormatter({ logRecord,
|
|
376
|
-
|
|
377
|
-
const formattedResult = JSON.stringify({
|
|
378
|
-
level: logRecord.levelName,
|
|
379
|
-
phase,
|
|
380
|
-
generatorKey
|
|
381
|
-
});
|
|
382
|
-
console.log('FORMATTED RESULT: ', formattedResult);
|
|
383
|
-
return formattedResult;
|
|
346
|
+
export function resultFormatter({ logRecord, stackTrail }) {
|
|
347
|
+
return JSON.stringify({ level: logRecord.levelName, stackTrail });
|
|
384
348
|
}
|
|
@@ -8,12 +8,12 @@ import type { BaseSettings, ClientSettings } from '../types/Settings.js';
|
|
|
8
8
|
import type { Method } from '../types/Method.js';
|
|
9
9
|
import type { OperationInsertable, OperationGenerator } from '../dsl/OperationInsertable.js';
|
|
10
10
|
import type { OasOperation } from '../oas/operation/Operation.js';
|
|
11
|
-
import type { ModelGeneratorKey, OperationGeneratorKey } from '../types/GeneratorKeys.js';
|
|
12
11
|
import type { CoreContext } from './CoreContext.js';
|
|
13
12
|
import type { ModelInsertable, ModelGenerator } from '../dsl/ModelInsertable.js';
|
|
14
13
|
import type { GenerationType, GeneratedDefintion, GeneratedValue } from '../types/GeneratedValue.js';
|
|
15
14
|
import type { ContentSettings } from '../dsl/ContentSettings.js';
|
|
16
15
|
import type { RefName } from '../types/RefName.js';
|
|
16
|
+
import { StackTrail } from './StackTrail.js';
|
|
17
17
|
type ConstructorArgs = {
|
|
18
18
|
schemaModel: OasDocument;
|
|
19
19
|
settings: ClientSettings | undefined;
|
|
@@ -59,16 +59,18 @@ export type InsertReturn<V extends GeneratedValue, T extends GenerationType> = {
|
|
|
59
59
|
definition: GeneratedDefintion<V, T>;
|
|
60
60
|
};
|
|
61
61
|
export declare class GenerateContext {
|
|
62
|
+
#private;
|
|
62
63
|
files: Map<string, FileContents>;
|
|
63
64
|
renderDependencies: RenderDependencies;
|
|
64
65
|
packageDependencies: Map<string, string>;
|
|
65
66
|
schemaModel: OasDocument;
|
|
66
67
|
settings: ClientSettings | undefined;
|
|
67
68
|
generatorsMap: Record<string, OperationGenerator | ModelGenerator>;
|
|
68
|
-
|
|
69
|
+
stackTrail: StackTrail;
|
|
69
70
|
constructor({ schemaModel, generatorsMap, settings }: ConstructorArgs);
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
generate(coreContext: CoreContext): void;
|
|
72
|
+
appendStackTrailChunk(chunk: string | string[] | StackTrail): void;
|
|
73
|
+
removeStackTrailChunk(chunk: string | string[] | StackTrail): void;
|
|
72
74
|
getFile(filePath: string, { throwIfNotFound }?: GetFileOptions): FileContents;
|
|
73
75
|
register({ imports, packageDependencies, definitions, destinationPath }: RegisterArgs): void;
|
|
74
76
|
insert<V extends GeneratedValue, T extends GenerationType>({ coreContext, generation, destinationPath, ...rest }: InsertArgs<V, T> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateContext.d.ts","sourceRoot":"","sources":["../../src/context/GenerateContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,kBAAkB,EACnB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"GenerateContext.d.ts","sourceRoot":"","sources":["../../src/context/GenerateContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,kBAAkB,EACnB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,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
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _GenerateContext_instances, _GenerateContext_runOperationGenerator, _GenerateContext_runModelGenerator, _GenerateContext_generateModel, _GenerateContext_generateOperation;
|
|
1
7
|
import { join, normalize } from '../deps/jsr.io/@std/path/1.0.0/mod.js';
|
|
2
8
|
import { Import } from '../dsl/Import.js';
|
|
3
|
-
import {
|
|
9
|
+
import { toOperationGeneratorKey } from '../types/GeneratorKeys.js';
|
|
4
10
|
import { OperationDriver } from '../dsl/OperationDriver.js';
|
|
5
11
|
import { ModelDriver } from '../dsl/ModelDriver.js';
|
|
12
|
+
import { StackTrail } from './StackTrail.js';
|
|
13
|
+
import * as Sentry from '@sentry/deno';
|
|
6
14
|
export class GenerateContext {
|
|
7
15
|
constructor({ schemaModel, generatorsMap, settings }) {
|
|
16
|
+
_GenerateContext_instances.add(this);
|
|
8
17
|
Object.defineProperty(this, "files", {
|
|
9
18
|
enumerable: true,
|
|
10
19
|
configurable: true,
|
|
@@ -41,12 +50,13 @@ export class GenerateContext {
|
|
|
41
50
|
writable: true,
|
|
42
51
|
value: void 0
|
|
43
52
|
});
|
|
44
|
-
Object.defineProperty(this, "
|
|
53
|
+
Object.defineProperty(this, "stackTrail", {
|
|
45
54
|
enumerable: true,
|
|
46
55
|
configurable: true,
|
|
47
56
|
writable: true,
|
|
48
57
|
value: void 0
|
|
49
58
|
});
|
|
59
|
+
this.stackTrail = new StackTrail();
|
|
50
60
|
this.generatorsMap = generatorsMap;
|
|
51
61
|
this.files = new Map();
|
|
52
62
|
this.renderDependencies = new Map();
|
|
@@ -54,11 +64,29 @@ export class GenerateContext {
|
|
|
54
64
|
this.schemaModel = schemaModel;
|
|
55
65
|
this.settings = settings;
|
|
56
66
|
}
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
generate(coreContext) {
|
|
68
|
+
Sentry.startSpan({ name: 'Generate operations' }, () => Object.values(coreContext.generatorsMap)
|
|
69
|
+
.filter(generator => generator.type === 'operation')
|
|
70
|
+
.forEach(generator => {
|
|
71
|
+
this.appendStackTrailChunk(generator.id);
|
|
72
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_runOperationGenerator).call(this, { context: coreContext, generator });
|
|
73
|
+
this.removeStackTrailChunk(generator.id);
|
|
74
|
+
}));
|
|
75
|
+
Sentry.startSpan({ name: 'Generate models' }, () => {
|
|
76
|
+
Object.values(coreContext.generatorsMap)
|
|
77
|
+
.filter(generator => generator.type === 'model')
|
|
78
|
+
.forEach(generator => {
|
|
79
|
+
this.appendStackTrailChunk(generator.id);
|
|
80
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_runModelGenerator).call(this, { context: coreContext, generator });
|
|
81
|
+
this.removeStackTrailChunk(generator.id);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
appendStackTrailChunk(chunk) {
|
|
86
|
+
this.stackTrail.append(chunk);
|
|
59
87
|
}
|
|
60
|
-
|
|
61
|
-
|
|
88
|
+
removeStackTrailChunk(chunk) {
|
|
89
|
+
this.stackTrail.remove(chunk);
|
|
62
90
|
}
|
|
63
91
|
getFile(filePath, { throwIfNotFound = false } = {}) {
|
|
64
92
|
const normalisedPath = normalize(filePath);
|
|
@@ -183,3 +211,53 @@ export class GenerateContext {
|
|
|
183
211
|
return this.getFile(exportPath).definitions.get(name);
|
|
184
212
|
}
|
|
185
213
|
}
|
|
214
|
+
_GenerateContext_instances = new WeakSet(), _GenerateContext_runOperationGenerator = function _GenerateContext_runOperationGenerator({ context, generator }) {
|
|
215
|
+
const generatorInstance = new generator(context);
|
|
216
|
+
context.schemaModel.operations.forEach(operation => {
|
|
217
|
+
// TODO If we make OasOperation generic, for example by
|
|
218
|
+
// adding a `method` type, we could make isSupported
|
|
219
|
+
// a type guard which could help us narrow down the
|
|
220
|
+
// exact operation type that a generator receives.
|
|
221
|
+
// This would allow us to remove some type checks
|
|
222
|
+
// in the generator implementations
|
|
223
|
+
// https://linear.app/skmtc/issue/SKM-32/generic-models-operations
|
|
224
|
+
const { path, method } = operation;
|
|
225
|
+
if (generator.isSupported(operation)) {
|
|
226
|
+
this.appendStackTrailChunk([path, method]);
|
|
227
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_generateOperation).call(this, { context, operation, generatorInstance });
|
|
228
|
+
this.removeStackTrailChunk([path, method]);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}, _GenerateContext_runModelGenerator = function _GenerateContext_runModelGenerator({ context, generator }) {
|
|
232
|
+
const generatorInstance = new generator(context);
|
|
233
|
+
const refNames = Object.keys(context.schemaModel.components?.schemas ?? {});
|
|
234
|
+
refNames.forEach(rn => {
|
|
235
|
+
this.appendStackTrailChunk(rn);
|
|
236
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_generateModel).call(this, {
|
|
237
|
+
context,
|
|
238
|
+
refName: rn,
|
|
239
|
+
generatorInstance
|
|
240
|
+
});
|
|
241
|
+
this.removeStackTrailChunk(rn);
|
|
242
|
+
});
|
|
243
|
+
}, _GenerateContext_generateModel = function _GenerateContext_generateModel({ context, refName, generatorInstance }) {
|
|
244
|
+
try {
|
|
245
|
+
generatorInstance.transformModel(refName);
|
|
246
|
+
context.captureCurrentResult('success');
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
context.logger.error(error);
|
|
250
|
+
context.captureCurrentResult('error');
|
|
251
|
+
Sentry.captureException(error);
|
|
252
|
+
}
|
|
253
|
+
}, _GenerateContext_generateOperation = function _GenerateContext_generateOperation({ context, operation, generatorInstance }) {
|
|
254
|
+
try {
|
|
255
|
+
generatorInstance.transformOperation(operation);
|
|
256
|
+
context.captureCurrentResult('success');
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
context.logger.error(error);
|
|
260
|
+
context.captureCurrentResult('error');
|
|
261
|
+
Sentry.captureException(error);
|
|
262
|
+
}
|
|
263
|
+
};
|