Skip to content

Commit

Permalink
feat: big bang reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
Amzani committed Mar 15, 2024
1 parent fdfb8cf commit ad2a686
Show file tree
Hide file tree
Showing 59 changed files with 455 additions and 399 deletions.
8 changes: 4 additions & 4 deletions src/adapters/api/controllers/generator.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Router, Request, Response, NextFunction } from 'express';
import { Controller } from '../interfaces';
import { ArchiverService } from '../../../internal/archiver.service';
import { GeneratorService } from '../../../internal/generator.service';
import { ProblemException } from '../exceptions/problem.exception';
import { Controller } from '../core/interfaces';
import { ArchiverService } from '../../../core/services/archiver.service';
import { GeneratorService } from '../../../core/services/generator.service';
import { ProblemException } from '../core/exceptions/problem.exception';
// import { ProblemException } from '../exceptions/problem.exception';

export class GeneratorController implements Controller {
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/api/controllers/ping.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Router, Request, Response, NextFunction } from 'express';
import { Controller } from '../interfaces';
import { Controller } from '../core/interfaces';
// import { ProblemException } from '../exceptions/problem.exception';

export class PingController implements Controller {
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/api/app.ts → src/adapters/api/core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cors from 'cors';
// @ts-ignore
import helmet from 'helmet';
import { problemMiddleware } from './middlewares/problem.middleware';
import { logger } from '../../utils/logger';
import { logger } from '../../../utils/logger';
import { API_VERSION,
CORS_ORIGIN,
CORS_CREDENTIALS,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextFunction, Request, Response } from 'express';

import { ProblemException } from '../exceptions/problem.exception';
import { logger } from '../../../utils/logger';
import { logger } from '../../../../utils/logger';

/**
* Catch problem exception, log it and serialize error to human readable form.
Expand Down
File renamed without changes.
14 changes: 4 additions & 10 deletions src/adapters/cli/commands/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Flags } from '@oclif/core';
import { Example } from '@oclif/core/lib/interfaces';
import Command from '../base';
import Command from '../core/base';
import bundle from '@asyncapi/bundler';
import { promises } from 'fs';
import path from 'path';
import { Specification, load } from '../../../internal/models/SpecificationFile';
import { Specification, load } from '../core/models/SpecificationFile';
import { bundleFlags } from '../core/flags/bundle.flags';

const { writeFile } = promises;

Expand All @@ -19,13 +19,7 @@ export default class Bundle extends Command {
'asyncapi bundle ./asyncapi.yaml ./features.yaml --base ./asyncapi.yaml --reference-into-components'
];

static flags = {
help: Flags.help({ char: 'h' }),
output: Flags.string({ char: 'o', description: 'The output file name. Omitting this flag the result will be printed in the console.' }),
'reference-into-components': Flags.boolean({ char: 'r', description: 'Bundle the message $refs into components object.' }),
base: Flags.string({ char: 'b', description: 'Path to the file which will act as a base. This is required when some properties are to needed to be overwritten.' }),
};

static flags = bundleFlags();
async run() {
const { argv, flags } = await this.parse(Bundle);
const output = flags.output;
Expand Down
17 changes: 4 additions & 13 deletions src/adapters/cli/commands/config/context/add.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import { Flags } from '@oclif/core';
import Command from '../../../base';
import { addContext, setCurrentContext } from '../../../../../internal/models/Context';
import Command from '../../../core/base';
import { addContext, setCurrentContext } from '../../../core/models/Context';
import {
MissingContextFileError,
ContextFileWrongFormatError,
} from '../../../../../errors/context-error';
import { addFlags } from '../../../core/flags/config/context.flags';

export default class ContextAdd extends Command {
static description = 'Add a context to the store';
static flags = {
help: Flags.help({ char: 'h' }),
'set-current': Flags.boolean({
char: 's',
description: 'Set context being added as the current context',
default: false,
required: false,
})
};

static flags = addFlags();
static args = [
{ name: 'context-name', description: 'context name', required: true },
{
Expand Down
10 changes: 4 additions & 6 deletions src/adapters/cli/commands/config/context/current.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Flags } from '@oclif/core';
import Command from '../../../base';
import { getCurrentContext, CONTEXT_FILE_PATH } from '../../../../../internal/models/Context';
import Command from '../../../core/base';
import { getCurrentContext, CONTEXT_FILE_PATH } from '../../../core/models/Context';
import {
MissingContextFileError,
ContextFileWrongFormatError,
ContextFileEmptyError,
ContextNotFoundError,
} from '../../../../../errors/context-error';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextCurrent extends Command {
static description = 'Shows the current context that is being used';
static flags = {
help: Flags.help({ char: 'h' }),
};
static flags = helpFlag();

async run() {
let fileContent;
Expand Down
10 changes: 4 additions & 6 deletions src/adapters/cli/commands/config/context/edit.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Flags } from '@oclif/core';
import Command from '../../../base';
import { editContext, CONTEXT_FILE_PATH } from '../../../../../internal/models/Context';
import Command from '../../../core/base';
import { editContext, CONTEXT_FILE_PATH } from '../../../core/models/Context';
import {
MissingContextFileError,
ContextFileWrongFormatError,
ContextFileEmptyError,
} from '../../../../../errors/context-error';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextEdit extends Command {
static description = 'Edit a context in the store';
static flags = {
help: Flags.help({ char: 'h' }),
};
static flags = helpFlag();

static args = [
{ name: 'context-name', description: 'context name', required: true },
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/cli/commands/config/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loadHelpClass } from '@oclif/core';
import Command from '../../../base';
import Command from '../../../core/base';

export default class Context extends Command {
static description =
Expand Down
10 changes: 4 additions & 6 deletions src/adapters/cli/commands/config/context/init.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Flags } from '@oclif/core';
import Command from '../../../base';
import { initContext } from '../../../../../internal/models/Context';
import Command from '../../../core/base';
import { initContext } from '../../../core/models/Context';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextInit extends Command {
static description = 'Initialize context';
static flags = {
help: Flags.help({ char: 'h' }),
};
static flags = helpFlag();

static contextFilePathMessage = `Specify directory in which context file should be created:
- current directory : asyncapi config context init . (default)
Expand Down
10 changes: 4 additions & 6 deletions src/adapters/cli/commands/config/context/list.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { Flags } from '@oclif/core';
import Command from '../../../base';
import Command from '../../../core/base';
import {
loadContextFile,
isContextFileEmpty,
CONTEXT_FILE_PATH,
} from '../../../../../internal/models/Context';
} from '../../../core/models/Context';
import {
MissingContextFileError,
ContextFileWrongFormatError,
} from '../../../../../errors/context-error';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextList extends Command {
static description = 'List all the stored contexts in the store';
static flags = {
help: Flags.help({ char: 'h' }),
};
static flags = helpFlag();

async run() {
try {
Expand Down
10 changes: 4 additions & 6 deletions src/adapters/cli/commands/config/context/remove.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Flags } from '@oclif/core';
import Command from '../../../base';
import { removeContext, CONTEXT_FILE_PATH } from '../../../../../internal/models/Context';
import Command from '../../../core/base';
import { removeContext, CONTEXT_FILE_PATH } from '../../../core/models/Context';
import {
MissingContextFileError,
ContextFileWrongFormatError,
ContextFileEmptyError,
} from '../../../../../errors/context-error';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextRemove extends Command {
static description = 'Delete a context from the store';
static flags = {
help: Flags.help({ char: 'h' }),
};
static flags = helpFlag();

static args = [
{
Expand Down
10 changes: 4 additions & 6 deletions src/adapters/cli/commands/config/context/use.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Flags } from '@oclif/core';
import Command from '../../../base';
import { setCurrentContext, CONTEXT_FILE_PATH } from '../../../../../internal/models/Context';
import Command from '../../../core/base';
import { setCurrentContext, CONTEXT_FILE_PATH } from '../../../core/models/Context';
import {
MissingContextFileError,
ContextFileWrongFormatError,
ContextFileEmptyError,
} from '../../../../../errors/context-error';
import { helpFlag } from '../../../core/flags/global.flags';

export default class ContextUse extends Command {
static description = 'Set a context as current';
static flags = {
help: Flags.help({ char: 'h' }),
};
static flags = helpFlag();

static args = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/cli/commands/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Command from '../../base';
import Command from '../../core/base';
import {loadHelpClass} from '@oclif/core';

export default class Config extends Command {
Expand Down
8 changes: 3 additions & 5 deletions src/adapters/cli/commands/config/versions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Flags } from '@oclif/core';
import Command from '../../base';
import Command from '../../core/base';
import { helpFlag } from '../../core/flags/global.flags';

export default class Versions extends Command {
static description = 'Show versions of AsyncAPI tools used';

static flags = {
help: Flags.help({ char: 'h' }),
};
static flags = helpFlag();

async run() {
const dependencies: string[] = [];
Expand Down
12 changes: 4 additions & 8 deletions src/adapters/cli/commands/convert.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { promises as fPromises } from 'fs';
import { Flags } from '@oclif/core';
import Command from '../base';
import Command from '../core/base';
import { ValidationError } from '../../../errors/validation-error';
import { load } from '../../../internal/models/SpecificationFile';
import { load } from '../core/models/SpecificationFile';
import { SpecificationFileNotFound } from '../../../errors/specification-file';
import { convert } from '@asyncapi/converter';

import type { ConvertVersion } from '@asyncapi/converter';

// @ts-ignore
import specs from '@asyncapi/specs';
import { convertFlags } from '../core/flags/convert.flags';

const latestVersion = Object.keys(specs.schemas).pop() as string;

export default class Convert extends Command {
static description = 'Convert asyncapi documents older to newer versions';

static flags = {
help: Flags.help({ char: 'h' }),
output: Flags.string({ char: 'o', description: 'path to the file where the result is saved' }),
'target-version': Flags.string({ char: 't', description: 'asyncapi version to convert to', default: latestVersion })
};
static flags = convertFlags(latestVersion);

static args = [
{ name: 'spec-file', description: 'spec path, url, or context-name', required: false },
Expand Down
43 changes: 7 additions & 36 deletions src/adapters/cli/commands/diff.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,29 @@
/* eslint-disable sonarjs/no-duplicate-string */
import { Flags } from '@oclif/core';
import * as diff from '@asyncapi/diff';
import AsyncAPIDiff from '@asyncapi/diff/lib/asyncapidiff';
import { promises as fs } from 'fs';
import chalk from 'chalk';
import { load, Specification } from '../../../internal/models/SpecificationFile';
import Command from '../base';
import { load, Specification } from '../core/models/SpecificationFile';
import Command from '../core/base';
import { ValidationError } from '../../../errors/validation-error';
import { SpecificationFileNotFound } from '../../../errors/specification-file';
import {
DiffBreakingChangeError,
DiffOverrideFileError,
DiffOverrideJSONError,
} from '../../../errors/diff-error';
import { specWatcher } from '../globals';
import { watchFlag } from '../flags';
import { validationFlags, parse, convertToOldAPI } from '../parser';
import { specWatcher } from '../core/globals';
import { parse, convertToOldAPI } from '../core/parser';

import type { SpecWatcherParams } from '../globals';
import type { SpecWatcherParams } from '../core/globals';
import { diffFlags } from '../core/flags/diff.flags';

const { readFile } = fs;

export default class Diff extends Command {
static description = 'Find diff between two asyncapi files';

static flags = {
help: Flags.help({ char: 'h' }),
format: Flags.string({
char: 'f',
description: 'format of the output',
default: 'yaml',
options: ['json', 'yaml', 'yml', 'md'],
}),
type: Flags.string({
char: 't',
description: 'type of the output',
default: 'all',
options: ['breaking', 'non-breaking', 'unclassified', 'all'],
}),
markdownSubtype: Flags.string({
description: 'the format of changes made to AsyncAPI document. It works only when diff is generated using md type. For example, when you specify subtype as json, then diff information in markdown is dumped as json structure.',
default: undefined,
options: ['json', 'yaml', 'yml']
}),
overrides: Flags.string({
char: 'o',
description: 'path to JSON file containing the override properties',
}),
'no-error': Flags.boolean({
description: 'don\'t show error on breaking changes',
}),
watch: watchFlag(),
...validationFlags({ logDiagnostics: false }),
};
static flags = diffFlags();

static args = [
{
Expand Down
Loading

0 comments on commit ad2a686

Please sign in to comment.