Skip to content

Commit

Permalink
chore: remove parser function and fix types (#28)
Browse files Browse the repository at this point in the history
* refactor types and some comments

* fix type changes in tests

* remove parser

* remove parser from dependencies

* add notes in readme

* fix tests for diff

Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com>
  • Loading branch information
aayushmau5 and magicmatatjahu authored Aug 12, 2021
1 parent fce4d60 commit deaf355
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 184 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# diff

AsyncDiff is a library which compares two AsyncAPI Documents and provides information about the differences by pointing out explicitly informations like breaking changes.

## Note

The library doesn't have a built-in parser to parse the given AsyncAPI document. Thus, users have to make sure they provide the valid & dereferenced AsyncAPI document as the input.

Users can use the [AsyncAPI parser](https://github.com/asyncapi/parser-js) to parse the document, or they can use other tools. Though they **must** make sure that the document is valid & dereferenced in case they use other tools to parse the documents.
72 changes: 49 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
},
"homepage": "https://github.com/asyncapi/diff#readme",
"dependencies": {
"@asyncapi/parser": "^1.5.1",
"fast-json-patch": "^3.0.0-1"
},
"devDependencies": {
"@asyncapi/parser": "^1.7.0",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/github": "^7.2.3",
"@semantic-release/npm": "^7.1.3",
Expand Down
4 changes: 2 additions & 2 deletions src/categorizeChanges.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classifier from './classifier';
import { Output, DiffOutput, DiffOutputItem } from './types';
import { Output, DiffOutput, DiffOutputItem, OverrideStandard } from './types';

/**
* Categorize the changes
Expand All @@ -8,7 +8,7 @@ import { Output, DiffOutput, DiffOutputItem } from './types';
* @returns The final output containing the diff changes as well as the type of change
*/
export default function categorizeChanges(
standard: any,
standard: OverrideStandard,
diffs: DiffOutput[]
): Output {
// the final output
Expand Down
11 changes: 7 additions & 4 deletions src/classifier.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
/* eslint-disable security/detect-object-injection */
// Disabling this since the object from which we are accessing the properties won't have any prototype chain.
// Also, since we are just using this object to access properties, its safe to disable security check for now.
// Disabling this since the property we are accessing will always have `/` as the prefix
// Thus preventing the prototype chain attacks

import { generateClassifierPath } from './helpers/ClassifierHelpers';
import { Classifier } from './types';
import { Classifier, OverrideStandard } from './types';

/**
* Gets the classifier object from the standard object using the provided path
* @param standard The standard object
* @param path The JSONpointer path provided by the diff
* @returns The classifier object containing `add`, `remove` & `edit` properties
*/
export default function classifier(standard: any, path: string): Classifier {
export default function classifier(
standard: OverrideStandard,
path: string
): Classifier {
const classifierPath = generateClassifierPath(standard, path);
if (!classifierPath) {
return {
Expand Down
8 changes: 5 additions & 3 deletions src/helpers/ClassifierHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable security/detect-object-injection */
// Disabling this since the standard object we will pass will have no prototype chain
// thus, it will return undefined for properties not present in the object itself
// Disabling this since the property we are accessing will always have `/` as the prefix
// Thus preventing the prototype chain attacks

import { OverrideStandard } from '../types';

/**
* Changes the last element of array to `*`
Expand All @@ -23,7 +25,7 @@ export function changeLastElementToPlaceholder(path: string[]): string {
* @returns The path found
*/
export function generateClassifierPath(
standard: any,
standard: OverrideStandard,
path: string
): string | undefined {
// See this PR for a detailed walkthrough of this code with an example: https://github.com/asyncapi/diff/pull/19
Expand Down
3 changes: 1 addition & 2 deletions src/mergeStandard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { StandardType } from './standard';
import { OverrideObject } from './types';
import { OverrideObject, StandardType } from './types';

/**
* Merges two standard objects
Expand Down
34 changes: 0 additions & 34 deletions src/parser.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/standard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,5 +652,3 @@ export const standard = {
edit: nonBreaking,
},
};

export type StandardType = typeof standard;
Loading

0 comments on commit deaf355

Please sign in to comment.