@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.
- package/esm/context/CoreContext.d.ts +27 -54
- package/esm/context/CoreContext.d.ts.map +1 -1
- package/esm/context/CoreContext.js +105 -137
- 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 +56 -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 +13 -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 +105 -137
- 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 +56 -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 +12 -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
|
@@ -33,7 +33,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
33
33
|
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");
|
|
34
34
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
35
35
|
};
|
|
36
|
-
var _CoreContext_phase, _CoreContext_results;
|
|
36
|
+
var _CoreContext_instances, _CoreContext_phase, _CoreContext_results, _CoreContext_stackTrail, _CoreContext_setupLogger, _CoreContext_getStackTrail, _CoreContext_setupParsePhase, _CoreContext_setupGeneratePhase, _CoreContext_setupRenderPhase;
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.CoreContext = void 0;
|
|
39
39
|
exports.skmtcFormatter = skmtcFormatter;
|
|
@@ -41,17 +41,14 @@ exports.resultFormatter = resultFormatter;
|
|
|
41
41
|
const GenerateContext_js_1 = require("./GenerateContext.js");
|
|
42
42
|
const ts_pattern_1 = require("ts-pattern");
|
|
43
43
|
const RenderContext_js_1 = require("./RenderContext.js");
|
|
44
|
+
const ParseContext_js_1 = require("./ParseContext.js");
|
|
44
45
|
const log = __importStar(require("../deps/jsr.io/@std/log/0.224.6/mod.js"));
|
|
45
46
|
const ResultsHandler_js_1 = require("./ResultsHandler.js");
|
|
47
|
+
const StackTrail_js_1 = require("./StackTrail.js");
|
|
46
48
|
class CoreContext {
|
|
47
|
-
constructor({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: void 0
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(this, "spanId", {
|
|
49
|
+
constructor({ schema, spanId }) {
|
|
50
|
+
_CoreContext_instances.add(this);
|
|
51
|
+
Object.defineProperty(this, "logger", {
|
|
55
52
|
enumerable: true,
|
|
56
53
|
configurable: true,
|
|
57
54
|
writable: true,
|
|
@@ -59,111 +56,65 @@ class CoreContext {
|
|
|
59
56
|
});
|
|
60
57
|
_CoreContext_phase.set(this, void 0);
|
|
61
58
|
_CoreContext_results.set(this, void 0);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
__classPrivateFieldSet(this, _CoreContext_phase, phase, "f");
|
|
68
|
-
this.traceId = traceId;
|
|
69
|
-
this.spanId = spanId;
|
|
70
|
-
log.setup({
|
|
71
|
-
handlers: {
|
|
72
|
-
[`${spanId}-logs`]: new log.ConsoleHandler('DEBUG', {
|
|
73
|
-
formatter: logRecord => skmtcFormatter({ logRecord, context: this }),
|
|
74
|
-
useColors: false
|
|
75
|
-
}),
|
|
76
|
-
[`${spanId}-results`]: new ResultsHandler_js_1.ResultsHandler('WARN', {
|
|
77
|
-
formatter: logRecord => resultFormatter({ logRecord, context: this }),
|
|
78
|
-
context: this
|
|
79
|
-
})
|
|
80
|
-
},
|
|
81
|
-
loggers: {
|
|
82
|
-
[spanId]: {
|
|
83
|
-
level: 'DEBUG',
|
|
84
|
-
handlers: [`${spanId}-logs`, `${spanId}-results`]
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
59
|
+
_CoreContext_stackTrail.set(this, void 0);
|
|
60
|
+
__classPrivateFieldSet(this, _CoreContext_stackTrail, new StackTrail_js_1.StackTrail([spanId]), "f");
|
|
61
|
+
__classPrivateFieldSet(this, _CoreContext_results, {}, "f");
|
|
62
|
+
this.logger = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupLogger).call(this, spanId);
|
|
63
|
+
__classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, schema), "f");
|
|
88
64
|
}
|
|
89
|
-
|
|
90
|
-
|
|
65
|
+
parse() {
|
|
66
|
+
if (__classPrivateFieldGet(this, _CoreContext_phase, "f").type !== 'parse') {
|
|
67
|
+
throw new Error(`Expected 'parse' phase, got '${__classPrivateFieldGet(this, _CoreContext_phase, "f").type}'`);
|
|
68
|
+
}
|
|
69
|
+
return __classPrivateFieldGet(this, _CoreContext_phase, "f").context.parse(this);
|
|
91
70
|
}
|
|
92
|
-
|
|
93
|
-
|
|
71
|
+
transform({ settings, generatorsMap, prettier }) {
|
|
72
|
+
if (__classPrivateFieldGet(this, _CoreContext_phase, "f").type !== 'parse') {
|
|
73
|
+
throw new Error(`Expected 'parse' phase, got '${__classPrivateFieldGet(this, _CoreContext_phase, "f").type}'`);
|
|
74
|
+
}
|
|
75
|
+
const schemaModel = __classPrivateFieldGet(this, _CoreContext_phase, "f").context.parse(this);
|
|
76
|
+
__classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
|
|
94
77
|
schemaModel,
|
|
95
78
|
settings,
|
|
96
79
|
generatorsMap
|
|
97
|
-
});
|
|
98
|
-
|
|
80
|
+
}), "f");
|
|
81
|
+
__classPrivateFieldGet(this, _CoreContext_phase, "f").context.generate(this);
|
|
82
|
+
console.log('GENERATED', this.files.size);
|
|
83
|
+
__classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupRenderPhase).call(this, {
|
|
84
|
+
renderDependencies: this.renderDependencies,
|
|
85
|
+
packageDependencies: this.packageDependencies,
|
|
86
|
+
pinnableGenerators: Object.values(this.generatorsMap)
|
|
87
|
+
.map(({ id, pinnable }) => (pinnable ? id : null))
|
|
88
|
+
.filter(generatorId => generatorId !== null),
|
|
89
|
+
prettier,
|
|
90
|
+
settings
|
|
91
|
+
}), "f");
|
|
92
|
+
const renderOutput = __classPrivateFieldGet(this, _CoreContext_phase, "f").context.render({});
|
|
93
|
+
console.log('RENDER OUTPUT', JSON.stringify(renderOutput, null, 2).slice(0, 1000));
|
|
94
|
+
return {
|
|
95
|
+
...renderOutput,
|
|
96
|
+
results: __classPrivateFieldGet(this, _CoreContext_results, "f")
|
|
97
|
+
};
|
|
99
98
|
}
|
|
100
|
-
captureResult(
|
|
101
|
-
(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
__classPrivateFieldGet(this, _CoreContext_results, "f").parse = result;
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
.with({ phase: 'generate' }, ({ generatorKey, result }) => {
|
|
108
|
-
if (applyResult({
|
|
109
|
-
current: __classPrivateFieldGet(this, _CoreContext_results, "f").generate[generatorKey],
|
|
110
|
-
incoming: result
|
|
111
|
-
})) {
|
|
112
|
-
__classPrivateFieldGet(this, _CoreContext_results, "f").generate[generatorKey] = result;
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
.with({ phase: 'render' }, ({ result }) => {
|
|
116
|
-
if (applyResult({ current: __classPrivateFieldGet(this, _CoreContext_results, "f").render, incoming: result })) {
|
|
117
|
-
__classPrivateFieldGet(this, _CoreContext_results, "f").render = result;
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
.exhaustive();
|
|
99
|
+
captureResult({ stackTrail, result }) {
|
|
100
|
+
if (applyResult({ current: __classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail], incoming: result })) {
|
|
101
|
+
__classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail] = result;
|
|
102
|
+
}
|
|
121
103
|
}
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
files: this.files,
|
|
128
|
-
renderDependencies,
|
|
129
|
-
packageDependencies,
|
|
130
|
-
prettier,
|
|
131
|
-
settings,
|
|
132
|
-
pinnableGenerators
|
|
133
|
-
});
|
|
134
|
-
__classPrivateFieldSet(this, _CoreContext_phase, { type: 'render', context: renderContext }, "f");
|
|
104
|
+
captureCurrentResult(result) {
|
|
105
|
+
const stackTrail = __classPrivateFieldGet(this, _CoreContext_stackTrail, "f").toString();
|
|
106
|
+
if (applyResult({ current: __classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail], incoming: result })) {
|
|
107
|
+
__classPrivateFieldGet(this, _CoreContext_results, "f")[stackTrail] = result;
|
|
108
|
+
}
|
|
135
109
|
}
|
|
136
110
|
get phaseType() {
|
|
137
111
|
return __classPrivateFieldGet(this, _CoreContext_phase, "f").type;
|
|
138
112
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
(0, ts_pattern_1.match)(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
142
|
-
.with({ type: 'generate' }, ({ context }) => {
|
|
143
|
-
context.setCurrentLocation(location);
|
|
144
|
-
})
|
|
145
|
-
.with({ type: 'parse' }, () => {
|
|
146
|
-
throw new Error(`Cannot set current location during parse phase`);
|
|
147
|
-
})
|
|
148
|
-
.with({ type: 'render' }, () => {
|
|
149
|
-
throw new Error(`Cannot set current location during render phase`);
|
|
150
|
-
})
|
|
151
|
-
.exhaustive();
|
|
113
|
+
appendStackTrailChunk(chunk) {
|
|
114
|
+
__classPrivateFieldGet(this, _CoreContext_stackTrail, "f").append(chunk);
|
|
152
115
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
phase: __classPrivateFieldGet(this, _CoreContext_phase, "f").type,
|
|
156
|
-
traceId: this.traceId,
|
|
157
|
-
spanId: this.spanId
|
|
158
|
-
};
|
|
159
|
-
return (0, ts_pattern_1.match)(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
160
|
-
.with({ type: 'generate' }, ({ context }) => ({
|
|
161
|
-
...logFields,
|
|
162
|
-
...context.getLogFields()
|
|
163
|
-
}))
|
|
164
|
-
.with({ type: 'parse' }, () => logFields)
|
|
165
|
-
.with({ type: 'render' }, () => logFields)
|
|
166
|
-
.exhaustive();
|
|
116
|
+
removeStackTrailChunk(chunk) {
|
|
117
|
+
__classPrivateFieldGet(this, _CoreContext_stackTrail, "f").remove(chunk);
|
|
167
118
|
}
|
|
168
119
|
register({ destinationPath, ...args }) {
|
|
169
120
|
return (0, ts_pattern_1.match)(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
@@ -239,17 +190,6 @@ class CoreContext {
|
|
|
239
190
|
.with({ type: 'render' }, ({ context }) => context.pick(args))
|
|
240
191
|
.exhaustive();
|
|
241
192
|
}
|
|
242
|
-
render(options) {
|
|
243
|
-
return (0, ts_pattern_1.match)(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
244
|
-
.with({ type: 'generate' }, () => {
|
|
245
|
-
throw new Error(`Cannot render during generate phase`);
|
|
246
|
-
})
|
|
247
|
-
.with({ type: 'parse' }, () => {
|
|
248
|
-
throw new Error(`Cannot render during parse phase`);
|
|
249
|
-
})
|
|
250
|
-
.with({ type: 'render' }, ({ context }) => context.render(options))
|
|
251
|
-
.exhaustive();
|
|
252
|
-
}
|
|
253
193
|
addFile(normalisedPath) {
|
|
254
194
|
return (0, ts_pattern_1.match)(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
255
195
|
.with({ type: 'generate' }, ({ context }) => {
|
|
@@ -302,9 +242,6 @@ class CoreContext {
|
|
|
302
242
|
})
|
|
303
243
|
.exhaustive();
|
|
304
244
|
}
|
|
305
|
-
get results() {
|
|
306
|
-
return __classPrivateFieldGet(this, _CoreContext_results, "f");
|
|
307
|
-
}
|
|
308
245
|
get files() {
|
|
309
246
|
return (0, ts_pattern_1.match)(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
310
247
|
.with({ type: 'generate' }, ({ context }) => context.files)
|
|
@@ -354,17 +291,6 @@ class CoreContext {
|
|
|
354
291
|
})
|
|
355
292
|
.exhaustive();
|
|
356
293
|
}
|
|
357
|
-
get parsedDocument() {
|
|
358
|
-
return (0, ts_pattern_1.match)(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
359
|
-
.with({ type: 'parse' }, ({ context }) => context.parsedDocument)
|
|
360
|
-
.with({ type: 'generate' }, () => {
|
|
361
|
-
throw new Error(`Cannot access parsed document during generate phase`);
|
|
362
|
-
})
|
|
363
|
-
.with({ type: 'render' }, () => {
|
|
364
|
-
throw new Error(`Cannot access parsed document during render phase`);
|
|
365
|
-
})
|
|
366
|
-
.exhaustive();
|
|
367
|
-
}
|
|
368
294
|
get settings() {
|
|
369
295
|
return (0, ts_pattern_1.match)(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
370
296
|
.with({ type: 'generate' }, ({ context }) => context.settings)
|
|
@@ -378,15 +304,62 @@ class CoreContext {
|
|
|
378
304
|
}
|
|
379
305
|
}
|
|
380
306
|
exports.CoreContext = CoreContext;
|
|
381
|
-
_CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap()
|
|
307
|
+
_CoreContext_phase = new WeakMap(), _CoreContext_results = new WeakMap(), _CoreContext_stackTrail = new WeakMap(), _CoreContext_instances = new WeakSet(), _CoreContext_setupLogger = function _CoreContext_setupLogger(spanId) {
|
|
308
|
+
log.setup({
|
|
309
|
+
handlers: {
|
|
310
|
+
[`${spanId}-logs`]: new log.ConsoleHandler('DEBUG', {
|
|
311
|
+
formatter: logRecord => skmtcFormatter({ logRecord, stackTrail: __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_getStackTrail).call(this) }),
|
|
312
|
+
useColors: false
|
|
313
|
+
}),
|
|
314
|
+
[`${spanId}-results`]: new ResultsHandler_js_1.ResultsHandler('WARN', {
|
|
315
|
+
formatter: logRecord => resultFormatter({ logRecord, stackTrail: __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_getStackTrail).call(this) }),
|
|
316
|
+
context: this
|
|
317
|
+
})
|
|
318
|
+
},
|
|
319
|
+
loggers: {
|
|
320
|
+
[spanId]: {
|
|
321
|
+
level: 'DEBUG',
|
|
322
|
+
handlers: [`${spanId}-logs`, `${spanId}-results`]
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
return log.getLogger(spanId);
|
|
327
|
+
}, _CoreContext_getStackTrail = function _CoreContext_getStackTrail() {
|
|
328
|
+
const substack = (0, ts_pattern_1.match)(__classPrivateFieldGet(this, _CoreContext_phase, "f"))
|
|
329
|
+
.with({ type: 'parse' }, ({ context }) => context.stackTrail)
|
|
330
|
+
.with({ type: 'generate' }, ({ context }) => context.stackTrail)
|
|
331
|
+
.with({ type: 'render' }, ({ context }) => context.stackTrail)
|
|
332
|
+
.exhaustive();
|
|
333
|
+
return __classPrivateFieldGet(this, _CoreContext_stackTrail, "f").append(substack);
|
|
334
|
+
}, _CoreContext_setupParsePhase = function _CoreContext_setupParsePhase(schema) {
|
|
335
|
+
const parseContext = new ParseContext_js_1.ParseContext(schema);
|
|
336
|
+
return { type: 'parse', context: parseContext };
|
|
337
|
+
}, _CoreContext_setupGeneratePhase = function _CoreContext_setupGeneratePhase({ schemaModel, settings, generatorsMap }) {
|
|
338
|
+
const generateContext = new GenerateContext_js_1.GenerateContext({
|
|
339
|
+
schemaModel,
|
|
340
|
+
settings,
|
|
341
|
+
generatorsMap
|
|
342
|
+
});
|
|
343
|
+
return { type: 'generate', context: generateContext };
|
|
344
|
+
}, _CoreContext_setupRenderPhase = function _CoreContext_setupRenderPhase({ prettier, packageDependencies, settings, renderDependencies, pinnableGenerators }) {
|
|
345
|
+
const renderContext = new RenderContext_js_1.RenderContext({
|
|
346
|
+
files: this.files,
|
|
347
|
+
renderDependencies,
|
|
348
|
+
packageDependencies,
|
|
349
|
+
prettier,
|
|
350
|
+
settings,
|
|
351
|
+
pinnableGenerators
|
|
352
|
+
});
|
|
353
|
+
return { type: 'render', context: renderContext };
|
|
354
|
+
};
|
|
382
355
|
const applyResult = ({ current, incoming }) => {
|
|
383
356
|
return (current === undefined ||
|
|
384
357
|
(current === 'success' && incoming !== 'success') ||
|
|
385
358
|
(current === 'warning' && incoming === 'error'));
|
|
386
359
|
};
|
|
387
|
-
function skmtcFormatter({ logRecord,
|
|
360
|
+
function skmtcFormatter({ logRecord, stackTrail }) {
|
|
388
361
|
return JSON.stringify({
|
|
389
|
-
|
|
362
|
+
stackTrail,
|
|
390
363
|
level: logRecord.levelName,
|
|
391
364
|
datetime: logRecord.datetime.getTime(),
|
|
392
365
|
message: logRecord.msg,
|
|
@@ -401,11 +374,6 @@ function flattenArgs(args) {
|
|
|
401
374
|
return args;
|
|
402
375
|
}
|
|
403
376
|
}
|
|
404
|
-
function resultFormatter({ logRecord,
|
|
405
|
-
|
|
406
|
-
return JSON.stringify({
|
|
407
|
-
level: logRecord.levelName,
|
|
408
|
-
phase,
|
|
409
|
-
generatorKey
|
|
410
|
-
});
|
|
377
|
+
function resultFormatter({ logRecord, stackTrail }) {
|
|
378
|
+
return JSON.stringify({ level: logRecord.levelName, stackTrail });
|
|
411
379
|
}
|
|
@@ -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,KA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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,4 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
26
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
27
|
+
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");
|
|
28
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
|
+
};
|
|
30
|
+
var _GenerateContext_instances, _GenerateContext_runOperationGenerator, _GenerateContext_runModelGenerator, _GenerateContext_generateModel, _GenerateContext_generateOperation;
|
|
2
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
32
|
exports.GenerateContext = void 0;
|
|
4
33
|
const mod_js_1 = require("../deps/jsr.io/@std/path/1.0.0/mod.js");
|
|
@@ -6,8 +35,11 @@ const Import_js_1 = require("../dsl/Import.js");
|
|
|
6
35
|
const GeneratorKeys_js_1 = require("../types/GeneratorKeys.js");
|
|
7
36
|
const OperationDriver_js_1 = require("../dsl/OperationDriver.js");
|
|
8
37
|
const ModelDriver_js_1 = require("../dsl/ModelDriver.js");
|
|
38
|
+
const StackTrail_js_1 = require("./StackTrail.js");
|
|
39
|
+
const Sentry = __importStar(require("@sentry/deno"));
|
|
9
40
|
class GenerateContext {
|
|
10
41
|
constructor({ schemaModel, generatorsMap, settings }) {
|
|
42
|
+
_GenerateContext_instances.add(this);
|
|
11
43
|
Object.defineProperty(this, "files", {
|
|
12
44
|
enumerable: true,
|
|
13
45
|
configurable: true,
|
|
@@ -44,12 +76,13 @@ class GenerateContext {
|
|
|
44
76
|
writable: true,
|
|
45
77
|
value: void 0
|
|
46
78
|
});
|
|
47
|
-
Object.defineProperty(this, "
|
|
79
|
+
Object.defineProperty(this, "stackTrail", {
|
|
48
80
|
enumerable: true,
|
|
49
81
|
configurable: true,
|
|
50
82
|
writable: true,
|
|
51
83
|
value: void 0
|
|
52
84
|
});
|
|
85
|
+
this.stackTrail = new StackTrail_js_1.StackTrail();
|
|
53
86
|
this.generatorsMap = generatorsMap;
|
|
54
87
|
this.files = new Map();
|
|
55
88
|
this.renderDependencies = new Map();
|
|
@@ -57,11 +90,29 @@ class GenerateContext {
|
|
|
57
90
|
this.schemaModel = schemaModel;
|
|
58
91
|
this.settings = settings;
|
|
59
92
|
}
|
|
60
|
-
|
|
61
|
-
|
|
93
|
+
generate(coreContext) {
|
|
94
|
+
Sentry.startSpan({ name: 'Generate operations' }, () => Object.values(coreContext.generatorsMap)
|
|
95
|
+
.filter(generator => generator.type === 'operation')
|
|
96
|
+
.forEach(generator => {
|
|
97
|
+
this.appendStackTrailChunk(generator.id);
|
|
98
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_runOperationGenerator).call(this, { context: coreContext, generator });
|
|
99
|
+
this.removeStackTrailChunk(generator.id);
|
|
100
|
+
}));
|
|
101
|
+
Sentry.startSpan({ name: 'Generate models' }, () => {
|
|
102
|
+
Object.values(coreContext.generatorsMap)
|
|
103
|
+
.filter(generator => generator.type === 'model')
|
|
104
|
+
.forEach(generator => {
|
|
105
|
+
this.appendStackTrailChunk(generator.id);
|
|
106
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_runModelGenerator).call(this, { context: coreContext, generator });
|
|
107
|
+
this.removeStackTrailChunk(generator.id);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
62
110
|
}
|
|
63
|
-
|
|
64
|
-
|
|
111
|
+
appendStackTrailChunk(chunk) {
|
|
112
|
+
this.stackTrail.append(chunk);
|
|
113
|
+
}
|
|
114
|
+
removeStackTrailChunk(chunk) {
|
|
115
|
+
this.stackTrail.remove(chunk);
|
|
65
116
|
}
|
|
66
117
|
getFile(filePath, { throwIfNotFound = false } = {}) {
|
|
67
118
|
const normalisedPath = (0, mod_js_1.normalize)(filePath);
|
|
@@ -187,3 +238,53 @@ class GenerateContext {
|
|
|
187
238
|
}
|
|
188
239
|
}
|
|
189
240
|
exports.GenerateContext = GenerateContext;
|
|
241
|
+
_GenerateContext_instances = new WeakSet(), _GenerateContext_runOperationGenerator = function _GenerateContext_runOperationGenerator({ context, generator }) {
|
|
242
|
+
const generatorInstance = new generator(context);
|
|
243
|
+
context.schemaModel.operations.forEach(operation => {
|
|
244
|
+
// TODO If we make OasOperation generic, for example by
|
|
245
|
+
// adding a `method` type, we could make isSupported
|
|
246
|
+
// a type guard which could help us narrow down the
|
|
247
|
+
// exact operation type that a generator receives.
|
|
248
|
+
// This would allow us to remove some type checks
|
|
249
|
+
// in the generator implementations
|
|
250
|
+
// https://linear.app/skmtc/issue/SKM-32/generic-models-operations
|
|
251
|
+
const { path, method } = operation;
|
|
252
|
+
if (generator.isSupported(operation)) {
|
|
253
|
+
this.appendStackTrailChunk([path, method]);
|
|
254
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_generateOperation).call(this, { context, operation, generatorInstance });
|
|
255
|
+
this.removeStackTrailChunk([path, method]);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}, _GenerateContext_runModelGenerator = function _GenerateContext_runModelGenerator({ context, generator }) {
|
|
259
|
+
const generatorInstance = new generator(context);
|
|
260
|
+
const refNames = Object.keys(context.schemaModel.components?.schemas ?? {});
|
|
261
|
+
refNames.forEach(rn => {
|
|
262
|
+
this.appendStackTrailChunk(rn);
|
|
263
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_generateModel).call(this, {
|
|
264
|
+
context,
|
|
265
|
+
refName: rn,
|
|
266
|
+
generatorInstance
|
|
267
|
+
});
|
|
268
|
+
this.removeStackTrailChunk(rn);
|
|
269
|
+
});
|
|
270
|
+
}, _GenerateContext_generateModel = function _GenerateContext_generateModel({ context, refName, generatorInstance }) {
|
|
271
|
+
try {
|
|
272
|
+
generatorInstance.transformModel(refName);
|
|
273
|
+
context.captureCurrentResult('success');
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
context.logger.error(error);
|
|
277
|
+
context.captureCurrentResult('error');
|
|
278
|
+
Sentry.captureException(error);
|
|
279
|
+
}
|
|
280
|
+
}, _GenerateContext_generateOperation = function _GenerateContext_generateOperation({ context, operation, generatorInstance }) {
|
|
281
|
+
try {
|
|
282
|
+
generatorInstance.transformOperation(operation);
|
|
283
|
+
context.captureCurrentResult('success');
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
context.logger.error(error);
|
|
287
|
+
context.captureCurrentResult('error');
|
|
288
|
+
Sentry.captureException(error);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
|
-
import
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
};
|
|
2
|
+
import { StackTrail } from './StackTrail.js';
|
|
3
|
+
import type { CoreContext } from './CoreContext.js';
|
|
4
|
+
import type { OasDocument } from '../oas/document/Document.js';
|
|
6
5
|
export declare class ParseContext {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
#private;
|
|
7
|
+
schema: string;
|
|
8
|
+
stackTrail: StackTrail;
|
|
9
|
+
constructor(schema: string);
|
|
10
|
+
parse(context: CoreContext): OasDocument;
|
|
11
|
+
appendStackTrailChunk(frame: string | string[] | StackTrail): void;
|
|
12
|
+
removeStackTrailChunk(frame: string | string[] | StackTrail): void;
|
|
13
13
|
}
|
|
14
|
-
export {}
|
|
14
|
+
export declare const parseSchema: (schema: string) => OpenAPIV3.Document<{}>;
|
|
15
15
|
//# sourceMappingURL=ParseContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParseContext.d.ts","sourceRoot":"","sources":["../../src/context/ParseContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"ParseContext.d.ts","sourceRoot":"","sources":["../../src/context/ParseContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAK5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAE9D,qBAAa,YAAY;;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,UAAU,CAAA;gBAEV,MAAM,EAAE,MAAM;IAK1B,KAAK,CAAC,OAAO,EAAE,WAAW;IAkC1B,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU;IAI3D,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU;CAG5D;AAED,eAAO,MAAM,WAAW,WAAY,MAAM,2BAMzC,CAAA"}
|
|
@@ -1,22 +1,92 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
26
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
27
|
+
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");
|
|
28
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
|
+
};
|
|
30
|
+
var _ParseContext_instances, _ParseContext_parseSchema, _ParseContext_parseDocument;
|
|
2
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ParseContext = void 0;
|
|
32
|
+
exports.parseSchema = exports.ParseContext = void 0;
|
|
33
|
+
const StackTrail_js_1 = require("./StackTrail.js");
|
|
34
|
+
const Sentry = __importStar(require("@sentry/deno"));
|
|
35
|
+
const mod_js_1 = require("../deps/jsr.io/@std/yaml/0.215.0/mod.js");
|
|
36
|
+
const toDocumentV3_js_1 = require("../oas/document/toDocumentV3.js");
|
|
37
|
+
const Trail_js_1 = require("./Trail.js");
|
|
4
38
|
class ParseContext {
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
39
|
+
constructor(schema) {
|
|
40
|
+
_ParseContext_instances.add(this);
|
|
41
|
+
Object.defineProperty(this, "schema", {
|
|
7
42
|
enumerable: true,
|
|
8
43
|
configurable: true,
|
|
9
44
|
writable: true,
|
|
10
45
|
value: void 0
|
|
11
46
|
});
|
|
12
|
-
Object.defineProperty(this, "
|
|
47
|
+
Object.defineProperty(this, "stackTrail", {
|
|
13
48
|
enumerable: true,
|
|
14
49
|
configurable: true,
|
|
15
50
|
writable: true,
|
|
16
51
|
value: void 0
|
|
17
52
|
});
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
53
|
+
this.schema = schema;
|
|
54
|
+
this.stackTrail = new StackTrail_js_1.StackTrail();
|
|
55
|
+
}
|
|
56
|
+
parse(context) {
|
|
57
|
+
const parsedDocument = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_parseSchema).call(this);
|
|
58
|
+
return __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_parseDocument).call(this, context, parsedDocument);
|
|
59
|
+
}
|
|
60
|
+
appendStackTrailChunk(frame) {
|
|
61
|
+
this.stackTrail.append(frame);
|
|
62
|
+
}
|
|
63
|
+
removeStackTrailChunk(frame) {
|
|
64
|
+
this.stackTrail.remove(frame);
|
|
20
65
|
}
|
|
21
66
|
}
|
|
22
67
|
exports.ParseContext = ParseContext;
|
|
68
|
+
_ParseContext_instances = new WeakSet(), _ParseContext_parseSchema = function _ParseContext_parseSchema() {
|
|
69
|
+
const parsedDocument = Sentry.startSpan({ name: 'Parse schema to document' }, () => (0, exports.parseSchema)(this.schema));
|
|
70
|
+
return parsedDocument;
|
|
71
|
+
}, _ParseContext_parseDocument = function _ParseContext_parseDocument(context, parsedDocument) {
|
|
72
|
+
const trail = new Trail_js_1.Trail({
|
|
73
|
+
document: parsedDocument
|
|
74
|
+
});
|
|
75
|
+
if (!parsedDocument.openapi.startsWith('3.0.')) {
|
|
76
|
+
throw new Error('Only OpenAPI v3 is supported');
|
|
77
|
+
}
|
|
78
|
+
return (0, toDocumentV3_js_1.toDocumentV3)({
|
|
79
|
+
document: parsedDocument,
|
|
80
|
+
trail,
|
|
81
|
+
context
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const parseSchema = (schema) => {
|
|
85
|
+
if (schema.trimStart().startsWith('{')) {
|
|
86
|
+
return JSON.parse(schema);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return (0, mod_js_1.parse)(schema);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
exports.parseSchema = parseSchema;
|