@skmtc/core 0.0.296 → 0.0.298

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/esm/context/CoreContext.d.ts +27 -54
  2. package/esm/context/CoreContext.d.ts.map +1 -1
  3. package/esm/context/CoreContext.js +105 -137
  4. package/esm/context/GenerateContext.d.ts +6 -4
  5. package/esm/context/GenerateContext.d.ts.map +1 -1
  6. package/esm/context/GenerateContext.js +84 -6
  7. package/esm/context/ParseContext.d.ts +11 -11
  8. package/esm/context/ParseContext.d.ts.map +1 -1
  9. package/esm/context/ParseContext.js +51 -5
  10. package/esm/context/RenderContext.d.ts +7 -19
  11. package/esm/context/RenderContext.d.ts.map +1 -1
  12. package/esm/context/RenderContext.js +56 -85
  13. package/esm/context/ResultsHandler.d.ts.map +1 -1
  14. package/esm/context/ResultsHandler.js +2 -6
  15. package/esm/context/StackTrail.d.ts +10 -0
  16. package/esm/context/StackTrail.d.ts.map +1 -0
  17. package/esm/context/StackTrail.js +68 -0
  18. package/esm/context/types.d.ts +13 -1
  19. package/esm/context/types.d.ts.map +1 -1
  20. package/esm/generate/generate.d.ts +6 -3
  21. package/esm/generate/generate.d.ts.map +1 -1
  22. package/esm/generate/generate.js +18 -45
  23. package/esm/mod.d.ts +0 -1
  24. package/esm/mod.d.ts.map +1 -1
  25. package/esm/mod.js +0 -1
  26. package/esm/oas/operation/Operation.d.ts +1 -1
  27. package/esm/oas/operation/Operation.d.ts.map +1 -1
  28. package/esm/oas/operation/Operation.js +1 -1
  29. package/esm/server/createServer.d.ts.map +1 -1
  30. package/esm/server/createServer.js +13 -13
  31. package/esm/types/Manifest.d.ts +11 -43
  32. package/esm/types/Manifest.d.ts.map +1 -1
  33. package/esm/types/Manifest.js +1 -5
  34. package/package.json +1 -1
  35. package/script/context/CoreContext.d.ts +27 -54
  36. package/script/context/CoreContext.d.ts.map +1 -1
  37. package/script/context/CoreContext.js +105 -137
  38. package/script/context/GenerateContext.d.ts +6 -4
  39. package/script/context/GenerateContext.d.ts.map +1 -1
  40. package/script/context/GenerateContext.js +106 -5
  41. package/script/context/ParseContext.d.ts +11 -11
  42. package/script/context/ParseContext.d.ts.map +1 -1
  43. package/script/context/ParseContext.js +76 -6
  44. package/script/context/RenderContext.d.ts +7 -19
  45. package/script/context/RenderContext.d.ts.map +1 -1
  46. package/script/context/RenderContext.js +56 -85
  47. package/script/context/ResultsHandler.d.ts.map +1 -1
  48. package/script/context/ResultsHandler.js +2 -6
  49. package/script/context/StackTrail.d.ts +10 -0
  50. package/script/context/StackTrail.d.ts.map +1 -0
  51. package/script/context/StackTrail.js +72 -0
  52. package/script/context/types.d.ts +13 -1
  53. package/script/context/types.d.ts.map +1 -1
  54. package/script/generate/generate.d.ts +6 -3
  55. package/script/generate/generate.d.ts.map +1 -1
  56. package/script/generate/generate.js +19 -47
  57. package/script/mod.d.ts +0 -1
  58. package/script/mod.d.ts.map +1 -1
  59. package/script/mod.js +0 -1
  60. package/script/oas/operation/Operation.d.ts +1 -1
  61. package/script/oas/operation/Operation.d.ts.map +1 -1
  62. package/script/oas/operation/Operation.js +1 -1
  63. package/script/server/createServer.d.ts.map +1 -1
  64. package/script/server/createServer.js +12 -12
  65. package/script/types/Manifest.d.ts +11 -43
  66. package/script/types/Manifest.d.ts.map +1 -1
  67. package/script/types/Manifest.js +1 -5
  68. package/esm/generate/generateModels.d.ts +0 -3
  69. package/esm/generate/generateModels.d.ts.map +0 -1
  70. package/esm/generate/generateModels.js +0 -44
  71. package/esm/generate/generateOperations.d.ts +0 -3
  72. package/esm/generate/generateOperations.d.ts.map +0 -1
  73. package/esm/generate/generateOperations.js +0 -53
  74. package/esm/parse/parse.d.ts +0 -4
  75. package/esm/parse/parse.d.ts.map +0 -1
  76. package/esm/parse/parse.js +0 -16
  77. package/script/generate/generateModels.d.ts +0 -3
  78. package/script/generate/generateModels.d.ts.map +0 -1
  79. package/script/generate/generateModels.js +0 -71
  80. package/script/generate/generateOperations.d.ts +0 -3
  81. package/script/generate/generateOperations.d.ts.map +0 -1
  82. package/script/generate/generateOperations.js +0 -80
  83. package/script/parse/parse.d.ts +0 -4
  84. package/script/parse/parse.d.ts.map +0 -1
  85. 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 { RenderContext, type FilesRenderResult } from './RenderContext.js';
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 { OperationGeneratorKey, ModelGeneratorKey } from '../types/GeneratorKeys.js';
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
- type SharedContext = {
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
- phase: SharedContext;
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
- phase: 'parse';
50
- result: WarningError;
51
- } | {
52
- phase: 'generate';
53
- generatorKey: OperationGeneratorKey | ModelGeneratorKey;
22
+ stackTrail: string;
54
23
  result: SuccessWarningError;
55
- } | {
56
- phase: 'render';
57
- result: WarningError;
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
- traceId: string;
62
- spanId: string;
63
- constructor({ phase, traceId, spanId }: CoreContextArgs);
64
- get logger(): log.Logger;
65
- setupGeneratePhase({ schemaModel, settings, generatorsMap }: GenerateArgs): void;
66
- captureResult(args: CaptureResultArgs): void;
67
- setupRenderPhase({ prettier, packageDependencies, settings, renderDependencies, pinnableGenerators }: RenderArgs): void;
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
- setCurrentLocation(location: OperationGeneratorKey | ModelGeneratorKey): void;
70
- getLogFields(): Record<string, string>;
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
- context: CoreContext;
66
+ stackTrail: StackTrail;
94
67
  };
95
- export declare function skmtcFormatter({ logRecord, context }: JsonFormatterArgs): string;
96
- export declare function resultFormatter({ logRecord, context }: JsonFormatterArgs): string;
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":"AAAA,OA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mB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ7C;IAED,IAAI,WAAW,IAAI,WAAW,CAU7B;IAED,IAAI,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,cAAc,CAAC,CAUvE;IAED,IAAI,QAAQ,IAAI,cAAc,GAAG,SAAS,CAUzC;CACF;AAeD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,GAAG,CAAC,SAAS,CAAA;IACxB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,wBAAgB,cAAc,CAAC,EAC7B,SAAS,EACT,UAAU,EACX,EAAE,iBAAiB,GAAG,MAAM,CAQ5B;AAUD,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,UAAU,EACX,EAAE,iBAAiB,GAAG,MAAM,CAE5B"}
@@ -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({ phase, traceId, spanId }) {
20
- Object.defineProperty(this, "traceId", {
21
- enumerable: true,
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,65 @@ export class CoreContext {
31
28
  });
32
29
  _CoreContext_phase.set(this, void 0);
33
30
  _CoreContext_results.set(this, void 0);
34
- __classPrivateFieldSet(this, _CoreContext_results, {
35
- parse: 'success',
36
- generate: {},
37
- render: 'success'
38
- }, "f");
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
- get logger() {
62
- return log.getLogger(this.spanId);
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
- setupGeneratePhase({ schemaModel, settings, generatorsMap }) {
65
- const generateContext = new GenerateContext({
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
- __classPrivateFieldSet(this, _CoreContext_phase, { type: 'generate', context: generateContext }, "f");
52
+ }), "f");
53
+ __classPrivateFieldGet(this, _CoreContext_phase, "f").context.generate(this);
54
+ console.log('GENERATED', this.files.size);
55
+ __classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupRenderPhase).call(this, {
56
+ renderDependencies: this.renderDependencies,
57
+ packageDependencies: this.packageDependencies,
58
+ pinnableGenerators: Object.values(this.generatorsMap)
59
+ .map(({ id, pinnable }) => (pinnable ? id : null))
60
+ .filter(generatorId => generatorId !== null),
61
+ prettier,
62
+ settings
63
+ }), "f");
64
+ const renderOutput = __classPrivateFieldGet(this, _CoreContext_phase, "f").context.render({});
65
+ console.log('RENDER OUTPUT', JSON.stringify(renderOutput, null, 2).slice(0, 1000));
66
+ return {
67
+ ...renderOutput,
68
+ results: __classPrivateFieldGet(this, _CoreContext_results, "f")
69
+ };
71
70
  }
72
- captureResult(args) {
73
- match(args)
74
- .with({ phase: 'parse' }, ({ result }) => {
75
- if (applyResult({ current: __classPrivateFieldGet(this, _CoreContext_results, "f").parse, incoming: result })) {
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();
71
+ captureResult({ stackTrail, result }) {
72
+ if (applyResult({ current: __classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail], incoming: result })) {
73
+ __classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail] = result;
74
+ }
93
75
  }
94
- setupRenderPhase({ prettier, packageDependencies, settings, renderDependencies, pinnableGenerators }) {
95
- const renderContext = new RenderContext({
96
- traceId: this.traceId,
97
- spanId: this.spanId,
98
- results: __classPrivateFieldGet(this, _CoreContext_results, "f"),
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");
76
+ captureCurrentResult(result) {
77
+ const stackTrail = __classPrivateFieldGet(this, _CoreContext_stackTrail, "f").toString();
78
+ if (applyResult({ current: __classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail], incoming: result })) {
79
+ __classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail] = result;
80
+ }
107
81
  }
108
82
  get phaseType() {
109
83
  return __classPrivateFieldGet(this, _CoreContext_phase, "f").type;
110
84
  }
111
- // @TODO This feels like it belongs in GenerateContext
112
- setCurrentLocation(location) {
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();
85
+ appendStackTrailChunk(chunk) {
86
+ __classPrivateFieldGet(this, _CoreContext_stackTrail, "f").append(chunk);
124
87
  }
125
- getLogFields() {
126
- const logFields = {
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();
88
+ removeStackTrailChunk(chunk) {
89
+ __classPrivateFieldGet(this, _CoreContext_stackTrail, "f").remove(chunk);
139
90
  }
140
91
  register({ destinationPath, ...args }) {
141
92
  return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
@@ -211,17 +162,6 @@ export class CoreContext {
211
162
  .with({ type: 'render' }, ({ context }) => context.pick(args))
212
163
  .exhaustive();
213
164
  }
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
165
  addFile(normalisedPath) {
226
166
  return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
227
167
  .with({ type: 'generate' }, ({ context }) => {
@@ -274,9 +214,6 @@ export class CoreContext {
274
214
  })
275
215
  .exhaustive();
276
216
  }
277
- get results() {
278
- return __classPrivateFieldGet(this, _CoreContext_results, "f");
279
- }
280
217
  get files() {
281
218
  return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
282
219
  .with({ type: 'generate' }, ({ context }) => context.files)
@@ -326,17 +263,6 @@ export class CoreContext {
326
263
  })
327
264
  .exhaustive();
328
265
  }
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
266
  get settings() {
341
267
  return match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
342
268
  .with({ type: 'generate' }, ({ context }) => context.settings)
@@ -349,15 +275,62 @@ export class CoreContext {
349
275
  .exhaustive();
350
276
  }
351
277
  }
352
- _CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap();
278
+ _CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreContext_stackTrail = new WeakMap(), _CoreContext_instances = new WeakSet(), _CoreContext_setupLogger = function _CoreContext_setupLogger(spanId) {
279
+ log.setup({
280
+ handlers: {
281
+ [`${spanId}-logs`]: new log.ConsoleHandler('DEBUG', {
282
+ formatter: logRecord => skmtcFormatter({ logRecord, stackTrail: __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_getStackTrail).call(this) }),
283
+ useColors: false
284
+ }),
285
+ [`${spanId}-results`]: new ResultsHandler('WARN', {
286
+ formatter: logRecord => resultFormatter({ logRecord, stackTrail: __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_getStackTrail).call(this) }),
287
+ context: this
288
+ })
289
+ },
290
+ loggers: {
291
+ [spanId]: {
292
+ level: 'DEBUG',
293
+ handlers: [`${spanId}-logs`, `${spanId}-results`]
294
+ }
295
+ }
296
+ });
297
+ return log.getLogger(spanId);
298
+ }, _CoreContext_getStackTrail = function _CoreContext_getStackTrail() {
299
+ const substack = match(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
300
+ .with({ type: 'parse' }, ({ context }) => context.stackTrail)
301
+ .with({ type: 'generate' }, ({ context }) => context.stackTrail)
302
+ .with({ type: 'render' }, ({ context }) => context.stackTrail)
303
+ .exhaustive();
304
+ return __classPrivateFieldGet(this, _CoreContext_stackTrail, "f").append(substack);
305
+ }, _CoreContext_setupParsePhase = function _CoreContext_setupParsePhase(schema) {
306
+ const parseContext = new ParseContext(schema);
307
+ return { type: 'parse', context: parseContext };
308
+ }, _CoreContext_setupGeneratePhase = function _CoreContext_setupGeneratePhase({ schemaModel, settings, generatorsMap }) {
309
+ const generateContext = new GenerateContext({
310
+ schemaModel,
311
+ settings,
312
+ generatorsMap
313
+ });
314
+ return { type: 'generate', context: generateContext };
315
+ }, _CoreContext_setupRenderPhase = function _CoreContext_setupRenderPhase({ prettier, packageDependencies, settings, renderDependencies, pinnableGenerators }) {
316
+ const renderContext = new RenderContext({
317
+ files: this.files,
318
+ renderDependencies,
319
+ packageDependencies,
320
+ prettier,
321
+ settings,
322
+ pinnableGenerators
323
+ });
324
+ return { type: 'render', context: renderContext };
325
+ };
353
326
  const applyResult = ({ current, incoming }) => {
354
327
  return (current === undefined ||
355
328
  (current === 'success' && incoming !== 'success') ||
356
329
  (current === 'warning' && incoming === 'error'));
357
330
  };
358
- export function skmtcFormatter({ logRecord, context }) {
331
+ export function skmtcFormatter({ logRecord, stackTrail }) {
359
332
  return JSON.stringify({
360
- ...context.getLogFields(),
333
+ stackTrail,
361
334
  level: logRecord.levelName,
362
335
  datetime: logRecord.datetime.getTime(),
363
336
  message: logRecord.msg,
@@ -372,11 +345,6 @@ function flattenArgs(args) {
372
345
  return args;
373
346
  }
374
347
  }
375
- export function resultFormatter({ logRecord, context }) {
376
- const { phase, generatorKey } = context.getLogFields();
377
- return JSON.stringify({
378
- level: logRecord.levelName,
379
- phase,
380
- generatorKey
381
- });
348
+ export function resultFormatter({ logRecord, stackTrail }) {
349
+ return JSON.stringify({ level: logRecord.levelName, stackTrail });
382
350
  }
@@ -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
- currentLocation: OperationGeneratorKey | ModelGeneratorKey | undefined;
69
+ stackTrail: StackTrail;
69
70
  constructor({ schemaModel, generatorsMap, settings }: ConstructorArgs);
70
- setCurrentLocation(location: OperationGeneratorKey | ModelGeneratorKey): void;
71
- getLogFields(): Record<string, string>;
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
- {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WAAW,EACX,eAAe,EAChB,EAAE,YAAY;IA6Bf,MAAM,CAAC,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,cAAc,EAAE,EACzD,WAAW,EACX,UAAU,EACV,eAAe,EACf,GAAG,IAAI,EACR,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;QAAE,WAAW,EAAE,WAAW,CAAA;KAAE,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IA4BvE,wBAAwB,CAAC,EACvB,WAAW,EACX,IAAI,EACJ,MAAM,EACP,EAAE,wBAAwB;IAwB3B,oBAAoB,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,oBAAoB;IAwBnE,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,YAAY;IAgB7C,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;IAWpE,mBAAmB,CAAC,EAClB,WAAW,EACX,YAAY,EACZ,SAAS,EACV,EAAE,uBAAuB;IAc1B,oDAAoD;IACpD,cAAc,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS;CAGvE"}
@@ -1,10 +1,19 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ 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 { fromGeneratorKey, toOperationGeneratorKey } from '../types/GeneratorKeys.js';
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, "currentLocation", {
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
- setCurrentLocation(location) {
58
- this.currentLocation = location;
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
- getLogFields() {
61
- return this.currentLocation ? fromGeneratorKey(this.currentLocation) : {};
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
+ };