@axinom/mosaic-cli 0.14.2-rc.9 → 0.15.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -5
- package/src/cli/README.md +60 -0
- package/src/cli/index.ts +47 -0
- package/src/commands/apply-templates/apply-templates.spec.ts +623 -0
- package/src/commands/apply-templates/apply-templates.ts +494 -0
- package/src/commands/apply-templates/bitwarden-vault.ts +130 -0
- package/src/commands/apply-templates/index.ts +1 -0
- package/src/commands/create-extension-config/create-extension-config.ts +92 -0
- package/src/commands/create-extension-config/index.ts +23 -0
- package/src/commands/get-access-token/get-access-token-options.ts +9 -0
- package/src/commands/get-access-token/get-dev-access-token.ts +32 -0
- package/src/commands/get-access-token/index.ts +66 -0
- package/src/commands/graphql-diff.ts +143 -0
- package/src/commands/msg-codegen/codegen.ts +891 -0
- package/src/commands/msg-codegen/index.ts +48 -0
- package/src/commands/msg-codegen/lint.ts +84 -0
- package/src/commands/msg-codegen/message-codegen-options.ts +7 -0
- package/src/commands/msg-diff/asyncapi-override.ts +31 -0
- package/src/commands/msg-diff/git-checkout-tmp.ts +73 -0
- package/src/commands/msg-diff/index.ts +53 -0
- package/src/commands/msg-diff/message-diff-options.ts +7 -0
- package/src/commands/msg-diff/msg-diff.spec.ts +412 -0
- package/src/commands/msg-diff/msg-diff.ts +364 -0
- package/src/commands/msg-diff/test-resources/0/1-asyncapi.yml +38 -0
- package/src/commands/msg-diff/test-resources/0/2-asyncapi.yml +36 -0
- package/src/commands/msg-diff/test-resources/0/command.json +74 -0
- package/src/commands/msg-diff/test-resources/0/event.json +25 -0
- package/src/commands/msg-diff/test-resources/1/1-asyncapi.yml +25 -0
- package/src/commands/msg-diff/test-resources/1/moved-event.json +25 -0
- package/src/commands/msg-diff/test-resources/common.json +20 -0
- package/src/commands/pg-dump/README.md +21 -0
- package/src/commands/pg-dump/generate.ts +146 -0
- package/src/commands/pg-dump/index.ts +39 -0
- package/src/commands/pg-dump/pg-dump-options.ts +6 -0
- package/src/commands/publish-schema-to-db/README.md +130 -0
- package/src/commands/publish-schema-to-db/abstractions/base-smart-tags.ts +6 -0
- package/src/commands/publish-schema-to-db/abstractions/index.ts +5 -0
- package/src/commands/publish-schema-to-db/abstractions/pg-column.ts +31 -0
- package/src/commands/publish-schema-to-db/abstractions/pg-fk-column.ts +6 -0
- package/src/commands/publish-schema-to-db/abstractions/pg-table.ts +55 -0
- package/src/commands/publish-schema-to-db/abstractions/pg-type.ts +8 -0
- package/src/commands/publish-schema-to-db/content-entity-model.ts +93 -0
- package/src/commands/publish-schema-to-db/generate.ts +82 -0
- package/src/commands/publish-schema-to-db/index.ts +49 -0
- package/src/commands/publish-schema-to-db/jest.config.js +9 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/fk-column.spec.ts +42 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/fk-column.ts +41 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/index.ts +4 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/pk-column.spec.ts +47 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/pk-column.ts +34 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/primitive-column.spec.ts +65 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/primitive-column.ts +62 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/virtual-fk-column.spec.ts +24 -0
- package/src/commands/publish-schema-to-db/pg-models/columns/virtual-fk-column.ts +34 -0
- package/src/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.spec.ts +182 -0
- package/src/commands/publish-schema-to-db/pg-models/json-schema-parse-utils.ts +166 -0
- package/src/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.spec.ts +19 -0
- package/src/commands/publish-schema-to-db/pg-models/pg-sql-gen-utils.ts +237 -0
- package/src/commands/publish-schema-to-db/pg-models/pgl-utils.spec.ts +19 -0
- package/src/commands/publish-schema-to-db/pg-models/pgl-utils.ts +115 -0
- package/src/commands/publish-schema-to-db/pg-models/tables/content-entity-table.ts +104 -0
- package/src/commands/publish-schema-to-db/pg-models/tables/index.ts +3 -0
- package/src/commands/publish-schema-to-db/pg-models/tables/object-property-table.ts +113 -0
- package/src/commands/publish-schema-to-db/pg-models/tables/relations-table.ts +115 -0
- package/src/commands/publish-schema-to-db/postprocessors/collection-postprocessor.ts +33 -0
- package/src/commands/publish-schema-to-db/postprocessors/content-entity-model-postprocessor.ts +13 -0
- package/src/commands/publish-schema-to-db/postprocessors/episode-postprocessor.ts +37 -0
- package/src/commands/publish-schema-to-db/postprocessors/index.ts +6 -0
- package/src/commands/publish-schema-to-db/postprocessors/movie-postprocessor.ts +30 -0
- package/src/commands/publish-schema-to-db/postprocessors/postprocessing-utils.ts +21 -0
- package/src/commands/publish-schema-to-db/postprocessors/season-postprocessor.ts +37 -0
- package/src/commands/publish-schema-to-db/postprocessors/tvshow-postprocessor.ts +30 -0
- package/src/commands/publish-schema-to-db/publish-schema-to-db-options.ts +15 -0
- package/src/commands/publish-schema-to-db/types/sql-formatter.d.ts +10 -0
- package/src/exports.ts +2 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CommandModule } from 'yargs';
|
|
2
|
+
import { Codegen } from './codegen';
|
|
3
|
+
import { lint } from './lint';
|
|
4
|
+
import { MessageCodegenOptions } from './message-codegen-options';
|
|
5
|
+
|
|
6
|
+
export const msgCodegen: CommandModule<unknown, MessageCodegenOptions> = {
|
|
7
|
+
command: 'msg-codegen',
|
|
8
|
+
describe: 'Generates code from AsyncAPI document.',
|
|
9
|
+
builder: (yargs) =>
|
|
10
|
+
yargs
|
|
11
|
+
.option('inputDir', {
|
|
12
|
+
alias: 'i',
|
|
13
|
+
describe: 'Path to input directory - AsyncAPI document root.',
|
|
14
|
+
type: 'string',
|
|
15
|
+
demandOption: true,
|
|
16
|
+
})
|
|
17
|
+
.option('filePattern', {
|
|
18
|
+
alias: 'p',
|
|
19
|
+
describe: 'Regular expression that matches suitable input files.',
|
|
20
|
+
type: 'string',
|
|
21
|
+
default: '^.*(-asyncapi).(json|yaml|yml)$',
|
|
22
|
+
})
|
|
23
|
+
.option('outputDir', {
|
|
24
|
+
alias: 'o',
|
|
25
|
+
describe: 'Path to output directory - output root.',
|
|
26
|
+
type: 'string',
|
|
27
|
+
default: 'src/generated',
|
|
28
|
+
})
|
|
29
|
+
.option('lint', {
|
|
30
|
+
describe: 'Run the Spectral linter on message schemas.',
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
default: false,
|
|
33
|
+
})
|
|
34
|
+
.option('rulesetPath', {
|
|
35
|
+
alias: 'r',
|
|
36
|
+
describe: 'Path to a Spectral ruleset file for linting.',
|
|
37
|
+
type: 'string',
|
|
38
|
+
}),
|
|
39
|
+
handler: async (argv) => {
|
|
40
|
+
if (argv.lint) {
|
|
41
|
+
await lint(argv);
|
|
42
|
+
} else {
|
|
43
|
+
const codegen = new Codegen(argv);
|
|
44
|
+
await codegen.run();
|
|
45
|
+
}
|
|
46
|
+
console.log('done.');
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Document,
|
|
3
|
+
isJSONSchemaDraft4,
|
|
4
|
+
isJSONSchemaLoose,
|
|
5
|
+
Parsers,
|
|
6
|
+
Spectral,
|
|
7
|
+
} from '@stoplight/spectral';
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as glob from 'glob';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import { MessageCodegenOptions } from './message-codegen-options';
|
|
12
|
+
|
|
13
|
+
export async function lint(options: MessageCodegenOptions): Promise<void> {
|
|
14
|
+
console.log(`Linting schemas at ${options.inputDir}.`);
|
|
15
|
+
|
|
16
|
+
// Configure Spectral
|
|
17
|
+
const spectral = new Spectral({});
|
|
18
|
+
spectral.registerFormat('json-schema-loose', isJSONSchemaLoose);
|
|
19
|
+
spectral.registerFormat('json-schema-draft4', isJSONSchemaDraft4);
|
|
20
|
+
spectral.loadRuleset(getRuleset(options));
|
|
21
|
+
|
|
22
|
+
let lintingErrors = false;
|
|
23
|
+
// Find JSON schemas and lint
|
|
24
|
+
const schemas = glob.sync(path.join(options.inputDir, '/**/*.json'), {
|
|
25
|
+
absolute: true,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (schemas.length === 0) {
|
|
29
|
+
console.log('Could not find any schemas, exiting.');
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const schema of schemas) {
|
|
34
|
+
// console.log(schema);
|
|
35
|
+
const document = new Document(
|
|
36
|
+
fs.readFileSync(schema, 'utf-8'),
|
|
37
|
+
Parsers.Json,
|
|
38
|
+
schema,
|
|
39
|
+
);
|
|
40
|
+
const results = await spectral.run(document);
|
|
41
|
+
const errors = results.filter((r) => r.severity === 0);
|
|
42
|
+
if (errors.length > 0) {
|
|
43
|
+
lintingErrors = true;
|
|
44
|
+
console.log(`\nErrors in\n${schema}:`);
|
|
45
|
+
errors.forEach((e) => {
|
|
46
|
+
console.log(`* ${e.message}`);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (lintingErrors) {
|
|
52
|
+
console.log('There were linting errors.');
|
|
53
|
+
process.exit(1);
|
|
54
|
+
} else {
|
|
55
|
+
console.log('No linting errors found.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getRuleset(options: MessageCodegenOptions): string {
|
|
60
|
+
// This has to be an abs path, otherwise Spectral will fall back to network resolution.
|
|
61
|
+
let ruleset: string;
|
|
62
|
+
|
|
63
|
+
if (!options.rulesetPath) {
|
|
64
|
+
console.log(
|
|
65
|
+
'No ruleset path provided, trying to find one in the input directory.',
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const defaultRuleset = path.resolve(options.inputDir, '.spectral.yaml');
|
|
69
|
+
|
|
70
|
+
if (!fs.existsSync(defaultRuleset)) {
|
|
71
|
+
console.log(
|
|
72
|
+
`Could not find default ruleset at ${defaultRuleset}, exiting.`,
|
|
73
|
+
);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
ruleset = defaultRuleset;
|
|
77
|
+
} else {
|
|
78
|
+
ruleset = path.resolve(options.rulesetPath);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.log(`Using ruleset ${ruleset}`);
|
|
82
|
+
|
|
83
|
+
return ruleset;
|
|
84
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OverrideObject } from '@asyncapi/diff';
|
|
2
|
+
|
|
3
|
+
const unclassified: OverrideObject[string] = {
|
|
4
|
+
add: 'unclassified',
|
|
5
|
+
remove: 'unclassified',
|
|
6
|
+
edit: 'unclassified',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Asyncapi classifier overrides. See: https://github.com/asyncapi/diff#standard-object.
|
|
11
|
+
* Standard defs (defaults) are here: https://github.com/asyncapi/diff/blob/master/src/standard.ts.
|
|
12
|
+
*/
|
|
13
|
+
export const override: OverrideObject = {
|
|
14
|
+
// Custom property used to name queues.
|
|
15
|
+
'/x-service-id': {
|
|
16
|
+
add: 'breaking',
|
|
17
|
+
remove: 'breaking',
|
|
18
|
+
edit: 'breaking',
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
// Changing or removing queue name is a breaking change.
|
|
22
|
+
'/channels/*/bindings/amqp/queue/name': {
|
|
23
|
+
add: 'non-breaking',
|
|
24
|
+
remove: 'breaking',
|
|
25
|
+
edit: 'breaking',
|
|
26
|
+
},
|
|
27
|
+
// (workaround) To find the rule above every subpath needs to be defined (if not already defined in standard defs)
|
|
28
|
+
// see: https://github.com/asyncapi/diff/pull/19
|
|
29
|
+
'/channels/*/bindings/amqp/queue': unclassified,
|
|
30
|
+
'/channels/*/bindings/amqp': unclassified,
|
|
31
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import * as uuid from 'uuid';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Checkout a copy of a git directory, from a specified commit/branch, to a temp location.
|
|
9
|
+
* This can be used to compare the current state of the directory to another commit.
|
|
10
|
+
* Ful paths from the git root are preserved in the temp checkout.
|
|
11
|
+
*
|
|
12
|
+
* @param localDir A local directory path. Can be absolute or relative. Must be in a git repo.
|
|
13
|
+
* @param branch A branch or commit directory to use for the checkout.
|
|
14
|
+
*/
|
|
15
|
+
export class GitCheckoutTmp {
|
|
16
|
+
private _gitRoot: string | undefined;
|
|
17
|
+
private _tmpDir: string | undefined;
|
|
18
|
+
|
|
19
|
+
public checkout(localDir: string, branch: string): void {
|
|
20
|
+
this._gitRoot = findGitRoot(localDir);
|
|
21
|
+
const gitRelDir = path
|
|
22
|
+
.relative(this._gitRoot, localDir)
|
|
23
|
+
.replace(/\\/g, '/');
|
|
24
|
+
if (!gitRelDir) {
|
|
25
|
+
throw `localDir for checkout cannot be the git root!`;
|
|
26
|
+
}
|
|
27
|
+
this._tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), uuid.v4()));
|
|
28
|
+
try {
|
|
29
|
+
execSync(
|
|
30
|
+
`git -C ${this._gitRoot} --work-tree=${this._tmpDir} checkout ${branch} -- ${gitRelDir}`,
|
|
31
|
+
);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
this.cleanUp();
|
|
34
|
+
throw e;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* Location of the temp directory. Root directory of the checked out files.
|
|
40
|
+
*/
|
|
41
|
+
public get tmpDir(): string | undefined {
|
|
42
|
+
return this._tmpDir;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* Location of the git root dir. Root directory of the original files.
|
|
47
|
+
*/
|
|
48
|
+
public get gitRoot(): string | undefined {
|
|
49
|
+
return this._gitRoot;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* Clean up temp files. This will remove the temp directory if it exists.
|
|
54
|
+
*/
|
|
55
|
+
public cleanUp(): void {
|
|
56
|
+
try {
|
|
57
|
+
if (this._tmpDir !== undefined) {
|
|
58
|
+
fs.rmdirSync(this._tmpDir, { recursive: true });
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.error(`Failed to clean up tmp dir ${this._tmpDir}: ${e}`);
|
|
62
|
+
}
|
|
63
|
+
this._gitRoot = undefined;
|
|
64
|
+
this._tmpDir = undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* Finds the git root directory for a local path (relative or absolute).
|
|
70
|
+
*/
|
|
71
|
+
export function findGitRoot(dir: string): string {
|
|
72
|
+
return execSync(`git -C ${dir} rev-parse --show-toplevel`).toString().trim();
|
|
73
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as yargs from 'yargs';
|
|
2
|
+
import { CommandModule } from 'yargs';
|
|
3
|
+
import { MessageDiffOptions } from './message-diff-options';
|
|
4
|
+
import { MessageDiff } from './msg-diff';
|
|
5
|
+
|
|
6
|
+
export const msgDiff: CommandModule<unknown, MessageDiffOptions> = {
|
|
7
|
+
command: 'msg-diff',
|
|
8
|
+
describe: 'Generates code from AsyncAPI document.',
|
|
9
|
+
builder: (yargs) =>
|
|
10
|
+
yargs
|
|
11
|
+
.option('inputDir', {
|
|
12
|
+
alias: 'i',
|
|
13
|
+
describe: 'Path to input directory - AsyncAPI document root.',
|
|
14
|
+
type: 'string',
|
|
15
|
+
demandOption: true,
|
|
16
|
+
})
|
|
17
|
+
.option('filePattern', {
|
|
18
|
+
alias: 'p',
|
|
19
|
+
describe: 'Regular expression used to include suitable input files.',
|
|
20
|
+
type: 'string',
|
|
21
|
+
default: '^.*(-asyncapi).(json|yaml|yml)$',
|
|
22
|
+
})
|
|
23
|
+
.option('excludePattern', {
|
|
24
|
+
alias: 'e',
|
|
25
|
+
describe:
|
|
26
|
+
'Exclude input files matching a regular expression. Exclusion takes precedence over inclusion.',
|
|
27
|
+
type: 'string',
|
|
28
|
+
default: undefined,
|
|
29
|
+
})
|
|
30
|
+
.option('branch', {
|
|
31
|
+
alias: 'b',
|
|
32
|
+
description: 'Git branch or commit identifier to compare to.',
|
|
33
|
+
type: 'string',
|
|
34
|
+
default: 'origin/master',
|
|
35
|
+
})
|
|
36
|
+
.option('verbose', {
|
|
37
|
+
alias: 'v',
|
|
38
|
+
description: 'Verbose output including non-breaking changes.',
|
|
39
|
+
type: 'boolean',
|
|
40
|
+
default: false,
|
|
41
|
+
}),
|
|
42
|
+
handler: async (argv) => {
|
|
43
|
+
const diff = new MessageDiff(argv);
|
|
44
|
+
await diff.run();
|
|
45
|
+
console.log('done.');
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Dev helper. Script can be run directly with command:
|
|
50
|
+
// ts-node libs/cli/src/commands/msg-diff/index.ts msg-diff -i libs/messages/schemas
|
|
51
|
+
if (require.main === module) {
|
|
52
|
+
yargs.command(msgDiff).demandCommand().argv;
|
|
53
|
+
}
|