@axinom/mosaic-cli 0.54.0-rc.2 → 0.54.0-rc.21
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/dist/cli/index.js +6 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/apply-templates/apply-templates.js +12 -11
- package/dist/commands/apply-templates/apply-templates.js.map +1 -1
- package/dist/commands/apply-templates/bitwarden-vault.js.map +1 -1
- package/dist/commands/create/command.js +26 -11
- package/dist/commands/create/command.js.map +1 -1
- package/dist/commands/create/createSolution.js +31 -31
- package/dist/commands/create/createSolution.js.map +1 -1
- package/dist/commands/create/helpers/git.d.ts +1 -1
- package/dist/commands/create/helpers/git.js +8 -9
- package/dist/commands/create/helpers/git.js.map +1 -1
- package/dist/commands/create/helpers/logger.js +8 -7
- package/dist/commands/create/helpers/logger.js.map +1 -1
- package/dist/commands/create/runQuestionaire.js +18 -18
- package/dist/commands/create/runQuestionaire.js.map +1 -1
- package/dist/commands/create-extension-config/create-extension-config.js +14 -14
- package/dist/commands/create-extension-config/create-extension-config.js.map +1 -1
- package/dist/commands/create-extension-config/index.js +2 -1
- package/dist/commands/create-extension-config/index.js.map +1 -1
- package/dist/commands/get-access-token/get-dev-access-token.js +3 -4
- package/dist/commands/get-access-token/get-dev-access-token.js.map +1 -1
- package/dist/commands/get-access-token/index.js +6 -6
- package/dist/commands/get-access-token/index.js.map +1 -1
- package/dist/commands/graphql-diff.js +44 -46
- package/dist/commands/graphql-diff.js.map +1 -1
- package/dist/commands/hosting/manifest/manifest-commands.js +3 -4
- package/dist/commands/hosting/manifest/manifest-commands.js.map +1 -1
- package/dist/commands/hosting/manifest/upload-manifest.js +7 -7
- package/dist/commands/hosting/manifest/upload-manifest.js.map +1 -1
- package/dist/commands/hosting/pilet/pilet-commands.js +3 -4
- package/dist/commands/hosting/pilet/pilet-commands.js.map +1 -1
- package/dist/commands/hosting/pilet/register-pilet.js +13 -10
- package/dist/commands/hosting/pilet/register-pilet.js.map +1 -1
- package/dist/commands/hosting/service/deploy/service-deploy-command.js +3 -4
- package/dist/commands/hosting/service/deploy/service-deploy-command.js.map +1 -1
- package/dist/commands/hosting/service/deploy/service-deploy.js +14 -14
- package/dist/commands/hosting/service/deploy/service-deploy.js.map +1 -1
- package/dist/commands/hosting/service/undeploy/service-undeploy-command.js +3 -4
- package/dist/commands/hosting/service/undeploy/service-undeploy-command.js.map +1 -1
- package/dist/commands/hosting/service/undeploy/service-undeploy.js +11 -11
- package/dist/commands/hosting/service/undeploy/service-undeploy.js.map +1 -1
- package/dist/commands/msg-codegen/codegen.js +298 -322
- package/dist/commands/msg-codegen/codegen.js.map +1 -1
- package/dist/commands/msg-codegen/index.js +4 -5
- package/dist/commands/msg-codegen/index.js.map +1 -1
- package/dist/commands/msg-codegen/lint.js +55 -60
- package/dist/commands/msg-codegen/lint.js.map +1 -1
- package/dist/commands/msg-codegen/presets.js +2 -1
- package/dist/commands/msg-codegen/presets.js.map +1 -1
- package/dist/commands/msg-codegen/utils.js +25 -25
- package/dist/commands/msg-codegen/utils.js.map +1 -1
- package/dist/commands/msg-diff/git-checkout-tmp.js +7 -6
- package/dist/commands/msg-diff/git-checkout-tmp.js.map +1 -1
- package/dist/commands/msg-diff/index.js +4 -4
- package/dist/commands/msg-diff/index.js.map +1 -1
- package/dist/commands/msg-diff/msg-diff.js +188 -198
- package/dist/commands/msg-diff/msg-diff.js.map +1 -1
- package/dist/commands/pg-dump/generate.js +5 -4
- package/dist/commands/pg-dump/generate.js.map +1 -1
- package/dist/commands/publish-schema-to-db/content-entity-model.js.map +1 -1
- package/dist/commands/publish-schema-to-db/generate.js +45 -45
- package/dist/commands/publish-schema-to-db/generate.js.map +1 -1
- package/dist/commands/publish-schema-to-db/index.js +3 -4
- package/dist/commands/publish-schema-to-db/index.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/columns/pk-column.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/columns/primitive-column.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.js +18 -22
- package/dist/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.js +26 -29
- package/dist/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/pgl-utils.js +11 -11
- package/dist/commands/publish-schema-to-db/pg-models/pgl-utils.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/tables/content-entity-table.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/tables/object-property-table.js.map +1 -1
- package/dist/commands/publish-schema-to-db/pg-models/tables/relations-table.js.map +1 -1
- package/dist/commands/publish-schema-to-db/postprocessors/postprocessing-utils.js +2 -3
- package/dist/commands/publish-schema-to-db/postprocessors/postprocessing-utils.js.map +1 -1
- package/dist/commands/service/purge-permissions/purge-permissions-command.js +3 -4
- package/dist/commands/service/purge-permissions/purge-permissions-command.js.map +1 -1
- package/dist/commands/service/purge-permissions/purge-permissions.js +4 -5
- package/dist/commands/service/purge-permissions/purge-permissions.js.map +1 -1
- package/dist/commands/service/sync-permissions/sync-permission-command.js +3 -4
- package/dist/commands/service/sync-permissions/sync-permission-command.js.map +1 -1
- package/dist/commands/service/sync-permissions/sync-permissions.js +5 -5
- package/dist/commands/service/sync-permissions/sync-permissions.js.map +1 -1
- package/dist/commands/unpublish-pilet/index.js +7 -7
- package/dist/commands/unpublish-pilet/index.js.map +1 -1
- package/dist/commands/unpublish-pilet/unpublish-pilet.js +4 -4
- package/dist/commands/unpublish-pilet/unpublish-pilet.js.map +1 -1
- package/package.json +15 -10
- package/src/commands/apply-templates/apply-templates.spec.ts +20 -11
- package/src/commands/apply-templates/apply-templates.ts +1 -1
- package/src/commands/create/helpers/logger.ts +1 -1
- package/src/commands/create-extension-config/create-extension-config.ts +1 -1
- package/src/commands/get-access-token/index.ts +1 -1
- package/src/commands/hosting/pilet/register-pilet.ts +1 -1
- package/src/commands/msg-diff/msg-diff.spec.ts +6 -9
- package/src/commands/pg-dump/generate.ts +1 -1
- package/src/commands/publish-schema-to-db/pg-models/columns/fk-column.spec.ts +18 -14
- package/src/commands/publish-schema-to-db/pg-models/columns/pk-column.spec.ts +11 -7
- package/src/commands/publish-schema-to-db/pg-models/columns/primitive-column.spec.ts +1 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/virtual-fk-column.spec.ts +1 -0
- package/src/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.spec.ts +2 -1
- package/src/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.spec.ts +1 -0
- package/src/commands/publish-schema-to-db/pg-models/pgl-utils.spec.ts +1 -0
- package/src/commands/unpublish-pilet/index.ts +1 -1
- package/src/types/find-nearest-file.d.ts +11 -0
- package/src/commands/publish-schema-to-db/jest.config.js +0 -9
|
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.Codegen = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const modelina_1 = require("@asyncapi/modelina");
|
|
7
|
-
const parser_1 = require("@asyncapi/parser");
|
|
8
|
-
const endent_1 = require("endent");
|
|
9
|
-
const fs = require("fs");
|
|
10
|
-
const path = require("path");
|
|
7
|
+
const parser_1 = tslib_1.__importStar(require("@asyncapi/parser"));
|
|
8
|
+
const endent_1 = tslib_1.__importDefault(require("endent"));
|
|
9
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
10
|
+
const path = tslib_1.__importStar(require("path"));
|
|
11
11
|
const common_1 = require("../../common");
|
|
12
12
|
const presets_1 = require("./presets");
|
|
13
13
|
const utils_1 = require("./utils");
|
|
@@ -36,60 +36,56 @@ class Codegen {
|
|
|
36
36
|
this.schemasOutputRoot = path.join(this.outputRoot, 'schemas');
|
|
37
37
|
this.messagingSettingsOutputRoot = path.join(this.outputRoot, 'config');
|
|
38
38
|
}
|
|
39
|
-
run() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
});
|
|
39
|
+
async run() {
|
|
40
|
+
console.log('Running message codegen.');
|
|
41
|
+
console.log(`* schema root: ${this.schemaRoot}`);
|
|
42
|
+
console.log(`* output root: ${this.outputRoot}`);
|
|
43
|
+
try {
|
|
44
|
+
await this.walk(this.schemaRoot);
|
|
45
|
+
await this.barrelExportTs([], [
|
|
46
|
+
this.typesOutputRoot,
|
|
47
|
+
this.schemasOutputRoot,
|
|
48
|
+
this.messagingSettingsOutputRoot,
|
|
49
|
+
], path.join(this.outputRoot, 'index.ts'));
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
console.log(e);
|
|
53
|
+
process.exit(common_1.exitCode);
|
|
54
|
+
}
|
|
57
55
|
}
|
|
58
56
|
/**
|
|
59
57
|
* Recursively walks a schemas directory and generates TS + bundled JSON schema files.
|
|
60
58
|
* @param dir - Directory to walk.
|
|
61
59
|
*/
|
|
62
|
-
walk(dir) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
});
|
|
60
|
+
async walk(dir) {
|
|
61
|
+
const items = await fs.promises.readdir(dir);
|
|
62
|
+
const fullPathItems = items.map((i) => path.join(dir, i));
|
|
63
|
+
const dirs = fullPathItems.filter((i) => fs.statSync(i).isDirectory());
|
|
64
|
+
const files = fullPathItems.filter((i) => fs.statSync(i).isFile() && this.filePattern.test(i));
|
|
65
|
+
if ([...files, ...dirs].length === 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const asyncApiFile of files) {
|
|
69
|
+
console.log(`Processing ${asyncApiFile}.`);
|
|
70
|
+
await this.processAsyncAPIDocument(asyncApiFile);
|
|
71
|
+
}
|
|
72
|
+
for (const directory of dirs) {
|
|
73
|
+
await this.walk(directory);
|
|
74
|
+
}
|
|
75
|
+
if (files.length === 0) {
|
|
76
|
+
//Calculate correct TS output related directories for barrel exports.
|
|
77
|
+
const tsDirs = dirs.map((d) => path.join(this.typesOutputRoot, path.relative(this.schemaRoot, d)));
|
|
78
|
+
const tsIndexOutPath = path.join(this.typesOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, dir), 'index.ts');
|
|
79
|
+
await this.barrelExportTs([], tsDirs, tsIndexOutPath);
|
|
80
|
+
// Calculate correct JSON schema output related directories for barrel exports.
|
|
81
|
+
const schemaDirs = dirs.map((d) => path.join(this.schemasOutputRoot, path.relative(this.schemaRoot, d)));
|
|
82
|
+
const schemaIndexOutPath = path.join(this.schemasOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, dir), 'index.ts');
|
|
83
|
+
await this.barrelExportSchema([], schemaDirs, schemaIndexOutPath);
|
|
84
|
+
// Calculate correct Message Settings output related directories for barrel exports.
|
|
85
|
+
const settingsDirs = dirs.map((d) => path.join(this.messagingSettingsOutputRoot, path.relative(this.schemaRoot, d)));
|
|
86
|
+
const messagingIndexOutPath = path.join(this.messagingSettingsOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, dir), 'index.ts');
|
|
87
|
+
await this.barrelExportSettings([], settingsDirs, messagingIndexOutPath);
|
|
88
|
+
}
|
|
93
89
|
}
|
|
94
90
|
/**
|
|
95
91
|
* Builds a path for the generated TS file from an input JSON schema path, retains directory structure.
|
|
@@ -111,170 +107,162 @@ class Codegen {
|
|
|
111
107
|
* Generates TS interfaces and JSON schemas from AsyncAPI schema.
|
|
112
108
|
* @param asyncApiFile - path to AsyncAPI document
|
|
113
109
|
*/
|
|
114
|
-
processAsyncAPIDocument(asyncApiFile) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
yield this.exportSettings(document, messagingSettingsOutputPath);
|
|
132
|
-
});
|
|
110
|
+
async processAsyncAPIDocument(asyncApiFile) {
|
|
111
|
+
const parser = new parser_1.default();
|
|
112
|
+
const { document, diagnostics } = await (0, parser_1.fromFile)(parser, asyncApiFile).parse();
|
|
113
|
+
if (document === undefined) {
|
|
114
|
+
console.error(`Failed to parse ${asyncApiFile}.`);
|
|
115
|
+
console.error(diagnostics);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
//export Typescript models
|
|
119
|
+
const tsModelsOutputPath = path.join(this.typesOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, asyncApiFile));
|
|
120
|
+
await this.exportTsModels(document, tsModelsOutputPath);
|
|
121
|
+
//export JSON Schemas
|
|
122
|
+
const schemasOutputPath = path.join(this.schemasOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, asyncApiFile));
|
|
123
|
+
await this.exportSchemas(document, schemasOutputPath);
|
|
124
|
+
//export message settings
|
|
125
|
+
const messagingSettingsOutputPath = path.join(this.messagingSettingsOutputRoot, (0, utils_1.getRelativeDir)(this.schemaRoot, asyncApiFile));
|
|
126
|
+
await this.exportSettings(document, messagingSettingsOutputPath);
|
|
133
127
|
}
|
|
134
128
|
/**
|
|
135
129
|
* Export all TS models from AsyncAPI document
|
|
136
130
|
* @param asyncAPIDocument - AsyncAPI Document object
|
|
137
131
|
* @param outputPath - output path for generated files
|
|
138
132
|
*/
|
|
139
|
-
exportTsModels(asyncAPIDocument, outputPath) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
133
|
+
async exportTsModels(asyncAPIDocument, outputPath) {
|
|
134
|
+
const generator = new modelina_1.TypeScriptGenerator({
|
|
135
|
+
modelType: 'interface',
|
|
136
|
+
enumType: 'union',
|
|
137
|
+
mapType: 'indexedObject',
|
|
138
|
+
constraints: {
|
|
139
|
+
propertyKey: (0, modelina_1.typeScriptDefaultPropertyKeyConstraints)({
|
|
140
|
+
NAMING_FORMATTER: (name) => modelina_1.FormatHelpers.toSnakeCase(name),
|
|
141
|
+
NO_RESERVED_KEYWORDS: (0, utils_1.createDummyReservedKeywordsChecker)(),
|
|
142
|
+
}),
|
|
143
|
+
modelName: (0, modelina_1.typeScriptDefaultModelNameConstraints)({
|
|
144
|
+
NO_RESERVED_KEYWORDS: (0, utils_1.createDummyReservedKeywordsChecker)(),
|
|
145
|
+
}),
|
|
146
|
+
},
|
|
147
|
+
// Order of presets matters!
|
|
148
|
+
presets: [
|
|
149
|
+
presets_1.NULLABLE_PROPERTY_TO_UNION_PRESET,
|
|
150
|
+
presets_1.ANY_TO_UNKNOWN_PRESET,
|
|
151
|
+
presets_1.ADDITIONAL_PROPERTIES_PRESET,
|
|
152
|
+
presets_1.EXPORT_TYPES_PRESET,
|
|
153
|
+
modelina_1.TS_DESCRIPTION_PRESET,
|
|
154
|
+
presets_1.IMPORTS_PRESET,
|
|
155
|
+
],
|
|
156
|
+
});
|
|
157
|
+
let outputModels = await generator.generate(asyncAPIDocument);
|
|
158
|
+
for (const schema of asyncAPIDocument.components().schemas()) {
|
|
159
|
+
const referencedModels = await generator.generate(schema.json());
|
|
160
|
+
outputModels = outputModels.map((om) => referencedModels.find((rm) => om.modelName === rm.modelName) || om);
|
|
161
|
+
}
|
|
162
|
+
const groupedModels = {};
|
|
163
|
+
outputModels.map((outModel) => {
|
|
164
|
+
const modelPathPrefix = (0, utils_1.getModelPathPrefix)(outModel.modelName);
|
|
165
|
+
if (groupedModels[modelPathPrefix] === undefined) {
|
|
166
|
+
groupedModels[modelPathPrefix] = [];
|
|
168
167
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const tsDirs = [];
|
|
178
|
-
for (const pathPrefix in groupedModels) {
|
|
179
|
-
const models = groupedModels[pathPrefix];
|
|
180
|
-
const groupOutPutPath = path.join(outputPath, pathPrefix);
|
|
181
|
-
if (pathPrefix) {
|
|
182
|
-
tsDirs.push(groupOutPutPath);
|
|
183
|
-
}
|
|
184
|
-
yield fs.promises.mkdir(groupOutPutPath, {
|
|
185
|
-
recursive: true,
|
|
186
|
-
});
|
|
187
|
-
const tsFiles = [];
|
|
188
|
-
for (const outputModel of models) {
|
|
189
|
-
const outputFilePath = this.buildTsOutPath(groupOutPutPath, outputModel.modelName);
|
|
190
|
-
yield fs.promises.writeFile(outputFilePath, outputModel.result);
|
|
191
|
-
tsFiles.push(outputFilePath);
|
|
192
|
-
}
|
|
193
|
-
//generate barrel export for all model in AsyncAPI document
|
|
194
|
-
const tsIndexOutPath = path.join(groupOutPutPath, 'index.ts');
|
|
195
|
-
yield this.barrelExportTs(tsFiles, [], tsIndexOutPath);
|
|
168
|
+
groupedModels[modelPathPrefix].push(outModel);
|
|
169
|
+
});
|
|
170
|
+
const tsDirs = [];
|
|
171
|
+
for (const pathPrefix in groupedModels) {
|
|
172
|
+
const models = groupedModels[pathPrefix];
|
|
173
|
+
const groupOutPutPath = path.join(outputPath, pathPrefix);
|
|
174
|
+
if (pathPrefix) {
|
|
175
|
+
tsDirs.push(groupOutPutPath);
|
|
196
176
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
177
|
+
await fs.promises.mkdir(groupOutPutPath, {
|
|
178
|
+
recursive: true,
|
|
179
|
+
});
|
|
180
|
+
const tsFiles = [];
|
|
181
|
+
for (const outputModel of models) {
|
|
182
|
+
const outputFilePath = this.buildTsOutPath(groupOutPutPath, outputModel.modelName);
|
|
183
|
+
await fs.promises.writeFile(outputFilePath, outputModel.result);
|
|
184
|
+
tsFiles.push(outputFilePath);
|
|
200
185
|
}
|
|
201
|
-
|
|
186
|
+
//generate barrel export for all model in AsyncAPI document
|
|
187
|
+
const tsIndexOutPath = path.join(groupOutPutPath, 'index.ts');
|
|
188
|
+
await this.barrelExportTs(tsFiles, [], tsIndexOutPath);
|
|
189
|
+
}
|
|
190
|
+
if (tsDirs.length > 0) {
|
|
191
|
+
const tsIndexOutPath = path.join(outputPath, 'index.ts');
|
|
192
|
+
await this.barrelExportTs([], tsDirs, tsIndexOutPath);
|
|
193
|
+
}
|
|
202
194
|
}
|
|
203
195
|
/**
|
|
204
196
|
* Export all JSON Schemas from AsyncAPI document
|
|
205
197
|
* @param asyncAPIDocument - AsyncAPI Document object
|
|
206
198
|
* @param outputPath - output path for generated files
|
|
207
199
|
*/
|
|
208
|
-
exportSchemas(asyncAPIDocument, outputPath) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
groupedSchemas[schemaPathPrefix] = [];
|
|
215
|
-
}
|
|
216
|
-
groupedSchemas[schemaPathPrefix].push(message);
|
|
200
|
+
async exportSchemas(asyncAPIDocument, outputPath) {
|
|
201
|
+
const groupedSchemas = {};
|
|
202
|
+
for (const message of asyncAPIDocument.allMessages()) {
|
|
203
|
+
const schemaPathPrefix = (0, utils_1.getModelPathPrefix)((0, utils_1.getMessageTitle)(message));
|
|
204
|
+
if (groupedSchemas[schemaPathPrefix] === undefined) {
|
|
205
|
+
groupedSchemas[schemaPathPrefix] = [];
|
|
217
206
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
207
|
+
groupedSchemas[schemaPathPrefix].push(message);
|
|
208
|
+
}
|
|
209
|
+
const schemaDirs = [];
|
|
210
|
+
for (const pathPrefix in groupedSchemas) {
|
|
211
|
+
const messages = groupedSchemas[pathPrefix];
|
|
212
|
+
const schemaFiles = [];
|
|
213
|
+
const groupOutPutPath = path.join(outputPath, pathPrefix);
|
|
214
|
+
if (pathPrefix) {
|
|
215
|
+
schemaDirs.push(groupOutPutPath);
|
|
216
|
+
}
|
|
217
|
+
await fs.promises.mkdir(groupOutPutPath, {
|
|
218
|
+
recursive: true,
|
|
219
|
+
});
|
|
220
|
+
for (const msg of messages) {
|
|
221
|
+
const payload = msg.payload();
|
|
222
|
+
if (payload !== undefined && payload.json() !== undefined) {
|
|
223
|
+
const filteredPayload = (0, utils_1.removeXParserProperties)(payload.json());
|
|
224
|
+
const outputSchemaPath = this.buildSchemaOutPath(groupOutPutPath, (0, utils_1.getMessageTitle)(msg));
|
|
225
|
+
await this.bundleSchema(filteredPayload, outputSchemaPath);
|
|
226
|
+
schemaFiles.push(outputSchemaPath);
|
|
237
227
|
}
|
|
238
|
-
//generate barrel export for all model in AsyncAPI document
|
|
239
|
-
const schemasIndexOutPath = path.join(groupOutPutPath, 'index.ts');
|
|
240
|
-
yield this.barrelExportSchema(schemaFiles, [], schemasIndexOutPath);
|
|
241
228
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
229
|
+
//generate barrel export for all model in AsyncAPI document
|
|
230
|
+
const schemasIndexOutPath = path.join(groupOutPutPath, 'index.ts');
|
|
231
|
+
await this.barrelExportSchema(schemaFiles, [], schemasIndexOutPath);
|
|
232
|
+
}
|
|
233
|
+
const schemaIndexOutPath = path.join(outputPath, 'index.ts');
|
|
234
|
+
await this.barrelExportSchema([], schemaDirs, schemaIndexOutPath);
|
|
245
235
|
}
|
|
246
236
|
/**
|
|
247
237
|
* Export all AsyncAPI document channels to Messaging Settings
|
|
248
238
|
* @param asyncAPIDocument - AsyncAPI Document object
|
|
249
239
|
* @param outputPath - output path for generated files
|
|
250
240
|
*/
|
|
251
|
-
exportSettings(asyncAPIDocument, outputPath) {
|
|
241
|
+
async exportSettings(asyncAPIDocument, outputPath) {
|
|
252
242
|
var _a, _b;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
});
|
|
274
|
-
}
|
|
243
|
+
const serviceTitle = (0, utils_1.getServiceTitle)(asyncAPIDocument);
|
|
244
|
+
const serviceId = (0, utils_1.getServiceId)(asyncAPIDocument);
|
|
245
|
+
const channelsData = [];
|
|
246
|
+
for (const channel of asyncAPIDocument.channels()) {
|
|
247
|
+
const queueName = (_a = channel.bindings().get('amqp')) === null || _a === void 0 ? void 0 : _a.value().queue.name;
|
|
248
|
+
if (queueName !== undefined) {
|
|
249
|
+
const routingKey = channel.address();
|
|
250
|
+
const action = (0, utils_1.getChannelAction)(channel);
|
|
251
|
+
const payloadName = (_b = (0, utils_1.getPayloadTitle)(channel)) !== null && _b !== void 0 ? _b : 'undefined';
|
|
252
|
+
const aggregateType = (0, utils_1.getChannelAggregateType)(channel);
|
|
253
|
+
const aggregateIdField = (0, utils_1.getChannelAggregateIdField)(channel);
|
|
254
|
+
channelsData.push({
|
|
255
|
+
routingKey,
|
|
256
|
+
queueName,
|
|
257
|
+
payloadName,
|
|
258
|
+
acceptedAction: action,
|
|
259
|
+
isMultiTenant: routingKey.includes('*.*'),
|
|
260
|
+
aggregateType,
|
|
261
|
+
aggregateIdField,
|
|
262
|
+
});
|
|
275
263
|
}
|
|
276
|
-
|
|
277
|
-
|
|
264
|
+
}
|
|
265
|
+
await this.generateMessagingSettings(serviceId, serviceTitle, channelsData, outputPath);
|
|
278
266
|
}
|
|
279
267
|
/**
|
|
280
268
|
* Generate Messaging Settings based on Channels data.
|
|
@@ -283,15 +271,13 @@ class Codegen {
|
|
|
283
271
|
* @param channelsData - AsyncAPI channels information
|
|
284
272
|
* @param outputPath - output path for generated files
|
|
285
273
|
*/
|
|
286
|
-
generateMessagingSettings(serviceId, serviceTitle, channelsData, outputPath) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
yield this.barrelExportSettings(messagingSettingFiles.filter((f) => f), [], schemaIndexOutPath);
|
|
294
|
-
});
|
|
274
|
+
async generateMessagingSettings(serviceId, serviceTitle, channelsData, outputPath) {
|
|
275
|
+
const messagingSettingFiles = [];
|
|
276
|
+
messagingSettingFiles.push(await this.createMessagingSettingFile(true, serviceId, serviceTitle, channelsData.filter((data) => data.isMultiTenant === true), outputPath));
|
|
277
|
+
messagingSettingFiles.push(await this.createMessagingSettingFile(false, serviceId, serviceTitle, channelsData.filter((data) => data.isMultiTenant === false), outputPath));
|
|
278
|
+
//barrel export for messaging settings
|
|
279
|
+
const schemaIndexOutPath = path.join(outputPath, 'index.ts');
|
|
280
|
+
await this.barrelExportSettings(messagingSettingFiles.filter((f) => f), [], schemaIndexOutPath);
|
|
295
281
|
}
|
|
296
282
|
/**
|
|
297
283
|
* Create new Messaging Settings file.
|
|
@@ -301,20 +287,19 @@ class Codegen {
|
|
|
301
287
|
* @param channelsData - AsyncAPI channels information
|
|
302
288
|
* @param outputPath - output path for generated files
|
|
303
289
|
*/
|
|
304
|
-
createMessagingSettingFile(isMultiTenant, serviceId, serviceTitle, channelsData, outputPath) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
? (0, endent_1.default) `private constructor(
|
|
290
|
+
async createMessagingSettingFile(isMultiTenant, serviceId, serviceTitle, channelsData, outputPath) {
|
|
291
|
+
if (channelsData.length === 0) {
|
|
292
|
+
return ``;
|
|
293
|
+
}
|
|
294
|
+
const baseClass = isMultiTenant
|
|
295
|
+
? `MultiTenantMessagingSettings`
|
|
296
|
+
: `MessagingSettings`;
|
|
297
|
+
const className = `${modelina_1.FormatHelpers.toPascalCase(serviceTitle)}${baseClass}`;
|
|
298
|
+
const action = isMultiTenant ? 'extends' : 'implements';
|
|
299
|
+
const visibility = isMultiTenant ? '' : 'public readonly ';
|
|
300
|
+
const toStringOverride = isMultiTenant ? ' override' : '';
|
|
301
|
+
const constructor = serviceId === AX_COMMON_SERVICE_ID
|
|
302
|
+
? (0, endent_1.default) `private constructor(
|
|
318
303
|
${visibility}serviceId: string,
|
|
319
304
|
${visibility}messageType: string,
|
|
320
305
|
${visibility}queue: string,
|
|
@@ -323,10 +308,10 @@ class Codegen {
|
|
|
323
308
|
${visibility}aggregateType: string,
|
|
324
309
|
) {
|
|
325
310
|
${isMultiTenant
|
|
326
|
-
|
|
327
|
-
|
|
311
|
+
? `super(serviceId, messageType, queue, routingKey, action, aggregateType);`
|
|
312
|
+
: ''}
|
|
328
313
|
}`
|
|
329
|
-
|
|
314
|
+
: (0, endent_1.default) `private constructor(
|
|
330
315
|
${visibility}messageType: string,
|
|
331
316
|
${visibility}queue: string,
|
|
332
317
|
${visibility}routingKey: string,
|
|
@@ -334,30 +319,29 @@ class Codegen {
|
|
|
334
319
|
${visibility}aggregateType: string,
|
|
335
320
|
) {
|
|
336
321
|
${isMultiTenant
|
|
337
|
-
|
|
338
|
-
|
|
322
|
+
? `super('${serviceId}', messageType, queue, routingKey, action, aggregateType);`
|
|
323
|
+
: ''}
|
|
339
324
|
}`;
|
|
340
|
-
|
|
341
|
-
|
|
325
|
+
const properties = channelsData.map((data) => this.createMessagingSettingProperty(data, className, serviceId === AX_COMMON_SERVICE_ID));
|
|
326
|
+
const content = (0, endent_1.default) `import { ${baseClass} } from '@axinom/mosaic-message-bus-abstractions';
|
|
342
327
|
|
|
343
328
|
export class ${className} ${action} ${baseClass} {
|
|
344
329
|
${properties.join(`\n`)}
|
|
345
330
|
${isMultiTenant || serviceId === AX_COMMON_SERVICE_ID
|
|
346
|
-
|
|
347
|
-
|
|
331
|
+
? ``
|
|
332
|
+
: `\npublic readonly serviceId = '${serviceId}';\n`}
|
|
348
333
|
${constructor}
|
|
349
334
|
|
|
350
335
|
public${toStringOverride} toString = (): string => {
|
|
351
336
|
return this.messageType;
|
|
352
337
|
};
|
|
353
338
|
}`;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
});
|
|
358
|
-
yield fs.promises.writeFile(filePath, content);
|
|
359
|
-
return filePath;
|
|
339
|
+
const filePath = path.join(outputPath, `${modelina_1.FormatHelpers.toParamCase(className)}.ts`);
|
|
340
|
+
await fs.promises.mkdir(path.dirname(filePath), {
|
|
341
|
+
recursive: true,
|
|
360
342
|
});
|
|
343
|
+
await fs.promises.writeFile(filePath, content);
|
|
344
|
+
return filePath;
|
|
361
345
|
}
|
|
362
346
|
/**
|
|
363
347
|
* Create Messaging Settings property from Channel Data.
|
|
@@ -420,11 +404,9 @@ class Codegen {
|
|
|
420
404
|
* @param jsonSchema - Schema object.
|
|
421
405
|
* @param outPath - Output JSON schema path.
|
|
422
406
|
*/
|
|
423
|
-
bundleSchema(jsonSchema, outPath) {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
yield fs.promises.writeFile(outPath, JSON.stringify(jsonSchema, null, 2));
|
|
427
|
-
});
|
|
407
|
+
async bundleSchema(jsonSchema, outPath) {
|
|
408
|
+
await fs.promises.mkdir(path.dirname(outPath), { recursive: true });
|
|
409
|
+
await fs.promises.writeFile(outPath, JSON.stringify(jsonSchema, null, 2));
|
|
428
410
|
}
|
|
429
411
|
// TODO: Consider doing named exports based on message groups to not just put all messages in one namespace.
|
|
430
412
|
// TODO: Maybe some templating engine would be better than just building strings.
|
|
@@ -435,65 +417,63 @@ class Codegen {
|
|
|
435
417
|
* @param dirs - Directories to roll up.
|
|
436
418
|
* @param outPath - Path where to write `index.ts`.
|
|
437
419
|
*/
|
|
438
|
-
barrelExportTs(files, dirs, outPath) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
schemaEnum = (0, endent_1.default) `
|
|
420
|
+
async barrelExportTs(files, dirs, outPath) {
|
|
421
|
+
console.log(`Rolling up TS exports to ${outPath}.`);
|
|
422
|
+
const items = [
|
|
423
|
+
...files.map((f) => path.basename(f, '.ts')),
|
|
424
|
+
...dirs.filter((d) => fs.existsSync(d)).map((d) => path.basename(d)),
|
|
425
|
+
];
|
|
426
|
+
if (items.length < 1) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const exports = `${items
|
|
430
|
+
.sort()
|
|
431
|
+
.map((p) => `export * from './${p}';`)
|
|
432
|
+
.join('\n')}`;
|
|
433
|
+
let schemaEnum = '';
|
|
434
|
+
let typeNamesEnum = '';
|
|
435
|
+
// TODO: Break this up into smaller pieces.
|
|
436
|
+
// TODO: Consider adding docstring to generated enums.
|
|
437
|
+
if (files.length > 0) {
|
|
438
|
+
const sortedFiles = files.sort();
|
|
439
|
+
// TODO: Message envelope is handled separately, we could remove this entirely.
|
|
440
|
+
// If message-envelope requires some special handling.
|
|
441
|
+
if (files.length === 1 && files[0].endsWith('message-envelope.ts')) {
|
|
442
|
+
const file = files[0];
|
|
443
|
+
schemaEnum = (0, endent_1.default) `
|
|
463
444
|
export enum MessageEnvelopeSchema {
|
|
464
445
|
MessageEnvelope = '${(0, utils_1.toPosixPath)(this.tsPathToSchemaPath(file))}'
|
|
465
446
|
}
|
|
466
447
|
`;
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
let enumNameBase = modelina_1.FormatHelpers.toPascalCase((0, utils_1.getRelativeDir)(this.typesOutputRoot, path.dirname(outPath)));
|
|
451
|
+
if (!enumNameBase.includes('Types')) {
|
|
452
|
+
enumNameBase = enumNameBase.replace('Payloads', ''); // Remove the Payloads prefix to reduce noise
|
|
453
|
+
schemaEnum = (0, endent_1.default) `
|
|
473
454
|
export enum ${enumNameBase}Schemas {
|
|
474
455
|
${sortedFiles
|
|
475
|
-
|
|
476
|
-
|
|
456
|
+
.map((f) => `${modelina_1.FormatHelpers.toPascalCase(path.basename(f, '.ts'))} = '${(0, utils_1.toPosixPath)(this.tsPathToSchemaPath(f))}'`)
|
|
457
|
+
.join(',\n')}
|
|
477
458
|
}`;
|
|
478
|
-
|
|
459
|
+
typeNamesEnum = (0, endent_1.default) `
|
|
479
460
|
export enum ${enumNameBase}Types {
|
|
480
461
|
${sortedFiles
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
462
|
+
.sort()
|
|
463
|
+
.map((f) => `${modelina_1.FormatHelpers.toPascalCase(path.basename(f, '.ts'))} = '${modelina_1.FormatHelpers.toPascalCase(path.basename(f, '.ts'))}'`)
|
|
464
|
+
.join(',\n')}
|
|
484
465
|
}`;
|
|
485
|
-
}
|
|
486
466
|
}
|
|
487
467
|
}
|
|
488
|
-
|
|
468
|
+
}
|
|
469
|
+
const contents = (0, endent_1.default) `
|
|
489
470
|
${exports}
|
|
490
471
|
|
|
491
472
|
${schemaEnum}
|
|
492
473
|
|
|
493
474
|
${typeNamesEnum}
|
|
494
475
|
`;
|
|
495
|
-
|
|
496
|
-
});
|
|
476
|
+
await fs.promises.writeFile(outPath, contents);
|
|
497
477
|
}
|
|
498
478
|
/**
|
|
499
479
|
* Generates a barrel index.ts for all Messaging Settings inside `outPath`.
|
|
@@ -501,32 +481,30 @@ class Codegen {
|
|
|
501
481
|
* @param dirs - Directories to roll up.
|
|
502
482
|
* @param outPath - Path where to write `index.ts`.
|
|
503
483
|
*/
|
|
504
|
-
barrelExportSettings(files, dirs, outPath) {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
contents = (0, endent_1.default) `
|
|
484
|
+
async barrelExportSettings(files, dirs, outPath) {
|
|
485
|
+
console.log(`Rolling up Messaging Settings exports to ${outPath}.`);
|
|
486
|
+
const items = [
|
|
487
|
+
...files.map((f) => path.basename(f, '.ts')),
|
|
488
|
+
...dirs.filter((d) => fs.existsSync(d)).map((d) => path.basename(d)),
|
|
489
|
+
];
|
|
490
|
+
const dirExports = dirs
|
|
491
|
+
.sort()
|
|
492
|
+
.filter((d) => fs.existsSync(d))
|
|
493
|
+
.map((d) => path.basename(d));
|
|
494
|
+
if (items.length < 1) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
let contents = '';
|
|
498
|
+
if (files.length > 0) {
|
|
499
|
+
const baseNames = files.map((f) => path.basename(f, '.ts')).sort();
|
|
500
|
+
const messagingImports = baseNames.map((n) => `export * from './${n}';`);
|
|
501
|
+
contents = (0, endent_1.default) `
|
|
523
502
|
${messagingImports.join('\n')}
|
|
524
503
|
`;
|
|
525
|
-
|
|
526
|
-
|
|
504
|
+
}
|
|
505
|
+
contents += (0, endent_1.default) `\n
|
|
527
506
|
${dirExports.map((d) => `export * from './${d}';`).join('\n')}`;
|
|
528
|
-
|
|
529
|
-
});
|
|
507
|
+
await fs.promises.writeFile(outPath, contents);
|
|
530
508
|
}
|
|
531
509
|
/**
|
|
532
510
|
* Generates a barrel index.ts for all JSON schemas inside `outPath`.
|
|
@@ -534,35 +512,33 @@ class Codegen {
|
|
|
534
512
|
* @param dirs - Directories to roll up.
|
|
535
513
|
* @param outPath - Path where to write `index.ts`.
|
|
536
514
|
*/
|
|
537
|
-
barrelExportSchema(files, dirs, outPath) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
contents = (0, endent_1.default) `
|
|
515
|
+
async barrelExportSchema(files, dirs, outPath) {
|
|
516
|
+
console.log(`Rolling up JSON exports to ${outPath}.`);
|
|
517
|
+
const items = [
|
|
518
|
+
...files.map((f) => path.basename(f, '.json')),
|
|
519
|
+
...dirs.filter((d) => fs.existsSync(d)).map((d) => path.basename(d)),
|
|
520
|
+
];
|
|
521
|
+
const dirExports = dirs
|
|
522
|
+
.sort()
|
|
523
|
+
.filter((d) => fs.existsSync(d))
|
|
524
|
+
.map((d) => path.basename(d));
|
|
525
|
+
if (items.length < 1) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
let contents = '';
|
|
529
|
+
if (files.length > 0) {
|
|
530
|
+
const baseNames = files.map((f) => path.basename(f, '.json')).sort();
|
|
531
|
+
const schemaImports = baseNames.map((n) => `import * as ${modelina_1.FormatHelpers.toPascalCase(n)} from './${n}.json';`);
|
|
532
|
+
const schemaExports = baseNames.map((n) => `export const ${modelina_1.FormatHelpers.toPascalCase(n)}Schema = ${modelina_1.FormatHelpers.toPascalCase(n)};`);
|
|
533
|
+
contents = (0, endent_1.default) `
|
|
557
534
|
${schemaImports.join('\n')}
|
|
558
535
|
|
|
559
536
|
${schemaExports.join('\n')}
|
|
560
537
|
`;
|
|
561
|
-
|
|
562
|
-
|
|
538
|
+
}
|
|
539
|
+
contents += (0, endent_1.default) `\n
|
|
563
540
|
${dirExports.map((d) => `export * from './${d}';`).join('\n')}`;
|
|
564
|
-
|
|
565
|
-
});
|
|
541
|
+
await fs.promises.writeFile(outPath, contents);
|
|
566
542
|
}
|
|
567
543
|
/**
|
|
568
544
|
* Converts a generated TS path to a corresponding JSON schema path.
|