Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
KhudaDad414 committed Mar 27, 2024
2 parents d70cfb8 + d427f8a commit a7d643f
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 10 deletions.
1 change: 1 addition & 0 deletions .asyncapi-analytics
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"analyticsEnabled":"true","infoMessageShown":"true","userID":"bca0ae59-2ef9-4b6c-88a1-96b16f837ef9"}
31 changes: 31 additions & 0 deletions asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
asyncapi: 3.0.0
info:
title: Account Serviceeeeee
version: 1.0.04
description: This service is in charge of processing user signups
channels:
userSignedUp:
address: user/signedup
messages:
UserSignedUp:
$ref: '#/components/messages/UserSignedUp'
operations:
onUserSignUp:
action: receive
channel:
$ref: '#/channels/userSignedUp'
messages:
- $ref: '#/channels/userSignedUp/messages/UserSignedUp'
components:
messages:
UserSignedUp:
payload:
type: object
properties:
displayName:
type: string
description: Name of the user
email:
type: string
format: email
description: Email of the user
5 changes: 5 additions & 0 deletions css/asyncapi.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions css/global.min.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
html{-moz-tab-size:4;-o-tab-size:4;tab-size:4;line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0;font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji}
88 changes: 88 additions & 0 deletions index.html

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions js/asyncapi-ui.min.js

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MetadataFromDocument, MetricMetadata, NewRelicSink, Recorder, Sink, Std
import { Parser } from '@asyncapi/parser';
import { Specification } from 'models/SpecificationFile';
import { join, resolve } from 'path';
import { existsSync } from 'fs-extra';
import { existsSync, statSync } from 'fs-extra';
import { promises as fPromises } from 'fs';
import { v4 as uuidv4 } from 'uuid';

Expand All @@ -20,6 +20,7 @@ export default abstract class extends Command {
parser = new Parser();
metricsMetadata: MetricMetadata = {};
specFile: Specification | undefined;
specFilePath: string | undefined;

async init(): Promise<void> {
await super.init();
Expand Down Expand Up @@ -69,6 +70,7 @@ export default abstract class extends Command {

async recordActionMetric(recordFunc: (recorder: Recorder) => Promise<void>) {
try {
this.setSource();
await recordFunc(await this.recorder);
await (await this.recorder).flush();
} catch (e: any) {
Expand All @@ -78,6 +80,16 @@ export default abstract class extends Command {
}
}

setSource() {
if (this.specFilePath) {
console.log(this.specFilePath);
const stats = statSync(this.specFilePath);
console.log(stats);
const creationDate = stats.birthtime.toISOString();
console.log(creationDate);
this.metricsMetadata['file_creation_time'] = creationDate;
}
}
async finally(error: Error | undefined): Promise<any> {
await super.finally(error);
this.metricsMetadata['success'] = error === undefined;
Expand Down Expand Up @@ -106,7 +118,7 @@ export default abstract class extends Command {
break;
case 'production':
// NODE_ENV set to `production` in bin/run_bin, which is specified in 'bin' package.json section
sink = new NewRelicSink(process.env.ASYNCAPI_METRICS_NEWRELIC_KEY || 'eu01xx73a8521047150dd9414f6aedd2FFFFNRAL');
sink = new NewRelicSink(process.env.ASYNCAPI_METRICS_NEWRELIC_KEY || 'eu01xx1dbea6bbf5f6b546cef26c042bFFFFNRAL');

if (analyticsConfigFileContent.infoMessageShown === 'false') {
this.log('\nAsyncAPI anonymously tracks command executions to improve the specification and tools, ensuring no sensitive data reaches our servers. It aids in comprehending how AsyncAPI tools are used and adopted, facilitating ongoing improvements to our specifications and tools.\n\nTo disable tracking, please run the following command:\n asyncapi config analytics --disable\n\nOnce disabled, if you want to enable tracking back again then run:\n asyncapi config analytics --enable');
Expand Down
4 changes: 2 additions & 2 deletions src/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class Bundle extends Command {

this.metricsMetadata.files = AsyncAPIFiles.length;

if (flags.base) {baseFile = (await load(flags.base)).text();}
if (flags.base) {baseFile = (await load(this,flags.base)).text();}

const fileContents = AsyncAPIFiles.map((file) => file.text());

Expand Down Expand Up @@ -90,7 +90,7 @@ export default class Bundle extends Command {
async loadFiles(filepaths: string[]): Promise<Specification[]> {
const files = [];
for (const filepath of filepaths) {
const file = await load(filepath);
const file = await load(this,filepath);
files.push(file);
}
return files;
Expand Down
8 changes: 4 additions & 4 deletions src/commands/generate/fromTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ export default class Template extends Command {
mapBaseUrlToFolder: parsedFlags.mapBaseUrlToFolder,
disabledHooks: parsedFlags.disableHooks,
};
const asyncapiInput = (await load(asyncapi)) || (await load());


const asyncapiInput = (await load(this,asyncapi)) || (await load(this));
this.specFile = asyncapiInput;
this.metricsMetadata.template = template;

Expand Down Expand Up @@ -207,7 +207,7 @@ export default class Template extends Command {
private async generate(asyncapi: string | undefined, template: string, output: string, options: any, genOption: any) {
let specification: Specification;
try {
specification = await load(asyncapi);
specification = await load(this,asyncapi);
} catch (err: any) {
return this.error(
new ValidationError({
Expand All @@ -231,7 +231,7 @@ export default class Template extends Command {
}

private async runWatchMode(asyncapi: string | undefined, template: string, output: string, watchHandler: ReturnType<typeof this.watcherHandler>) {
const specification = await load(asyncapi);
const specification = await load(this,asyncapi);

const watchDir = path.resolve(template);
const outputPath = path.resolve(watchDir, output);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/new/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class NewFile extends Command {
}
await writeFile(fileNameToWriteToDisk, asyncApiFile, { encoding: 'utf8' });
console.log(`Created file ${fileNameToWriteToDisk}...`);
this.specFile = await load(fileNameToWriteToDisk);
this.specFile = await load(this,fileNameToWriteToDisk);
this.metricsMetadata.selected_template = selectedTemplate;
}
}
4 changes: 3 additions & 1 deletion src/models/SpecificationFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import yaml from 'js-yaml';
import { loadContext } from './Context';
import { ErrorLoadingSpec } from '../errors/specification-file';
import { MissingContextFileError } from '../errors/context-error';
import type Command from 'base';

const { readFile, lstat } = fs;
const allowedFileNames: string[] = [
Expand Down Expand Up @@ -121,7 +122,7 @@ interface LoadType {
}

/* eslint-disable sonarjs/cognitive-complexity */
export async function load(filePathOrContextName?: string, loadType?: LoadType): Promise<Specification> { // NOSONAR
export async function load(command?: Command, filePathOrContextName?: string, loadType?: LoadType): Promise<Specification> { // NOSONAR
if (filePathOrContextName) {
if (loadType?.file) { return Specification.fromFile(filePathOrContextName); }
if (loadType?.context) { return loadFromContext(filePathOrContextName); }
Expand All @@ -136,6 +137,7 @@ export async function load(filePathOrContextName?: string, loadType?: LoadType):
return Specification.fromURL(filePathOrContextName);
}
await fileExists(filePathOrContextName);
if (command) {command.specFilePath = filePathOrContextName;}
return Specification.fromFile(filePathOrContextName);
}

Expand Down

0 comments on commit a7d643f

Please sign in to comment.