Skip to content

Commit deaf355

Browse files
chore: remove parser function and fix types (#28)
* 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 <[email protected]>
1 parent fce4d60 commit deaf355

17 files changed

+149
-184
lines changed

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# diff
2+
23
AsyncDiff is a library which compares two AsyncAPI Documents and provides information about the differences by pointing out explicitly informations like breaking changes.
4+
5+
## Note
6+
7+
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.
8+
9+
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.

Diff for: package-lock.json

+49-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
},
3434
"homepage": "https://github.com/asyncapi/diff#readme",
3535
"dependencies": {
36-
"@asyncapi/parser": "^1.5.1",
3736
"fast-json-patch": "^3.0.0-1"
3837
},
3938
"devDependencies": {
39+
"@asyncapi/parser": "^1.7.0",
4040
"@semantic-release/commit-analyzer": "^8.0.1",
4141
"@semantic-release/github": "^7.2.3",
4242
"@semantic-release/npm": "^7.1.3",

Diff for: src/categorizeChanges.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classifier from './classifier';
2-
import { Output, DiffOutput, DiffOutputItem } from './types';
2+
import { Output, DiffOutput, DiffOutputItem, OverrideStandard } from './types';
33

44
/**
55
* Categorize the changes
@@ -8,7 +8,7 @@ import { Output, DiffOutput, DiffOutputItem } from './types';
88
* @returns The final output containing the diff changes as well as the type of change
99
*/
1010
export default function categorizeChanges(
11-
standard: any,
11+
standard: OverrideStandard,
1212
diffs: DiffOutput[]
1313
): Output {
1414
// the final output

Diff for: src/classifier.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
/* eslint-disable security/detect-object-injection */
2-
// Disabling this since the object from which we are accessing the properties won't have any prototype chain.
3-
// Also, since we are just using this object to access properties, its safe to disable security check for now.
2+
// Disabling this since the property we are accessing will always have `/` as the prefix
3+
// Thus preventing the prototype chain attacks
44

55
import { generateClassifierPath } from './helpers/ClassifierHelpers';
6-
import { Classifier } from './types';
6+
import { Classifier, OverrideStandard } from './types';
77

88
/**
99
* Gets the classifier object from the standard object using the provided path
1010
* @param standard The standard object
1111
* @param path The JSONpointer path provided by the diff
1212
* @returns The classifier object containing `add`, `remove` & `edit` properties
1313
*/
14-
export default function classifier(standard: any, path: string): Classifier {
14+
export default function classifier(
15+
standard: OverrideStandard,
16+
path: string
17+
): Classifier {
1518
const classifierPath = generateClassifierPath(standard, path);
1619
if (!classifierPath) {
1720
return {

Diff for: src/helpers/ClassifierHelpers.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* eslint-disable security/detect-object-injection */
2-
// Disabling this since the standard object we will pass will have no prototype chain
3-
// thus, it will return undefined for properties not present in the object itself
2+
// Disabling this since the property we are accessing will always have `/` as the prefix
3+
// Thus preventing the prototype chain attacks
4+
5+
import { OverrideStandard } from '../types';
46

57
/**
68
* Changes the last element of array to `*`
@@ -23,7 +25,7 @@ export function changeLastElementToPlaceholder(path: string[]): string {
2325
* @returns The path found
2426
*/
2527
export function generateClassifierPath(
26-
standard: any,
28+
standard: OverrideStandard,
2729
path: string
2830
): string | undefined {
2931
// See this PR for a detailed walkthrough of this code with an example: https://github.com/asyncapi/diff/pull/19

Diff for: src/mergeStandard.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { StandardType } from './standard';
2-
import { OverrideObject } from './types';
1+
import { OverrideObject, StandardType } from './types';
32

43
/**
54
* Merges two standard objects

Diff for: src/parser.ts

-34
This file was deleted.

Diff for: src/standard.ts

-2
Original file line numberDiff line numberDiff line change
@@ -652,5 +652,3 @@ export const standard = {
652652
edit: nonBreaking,
653653
},
654654
};
655-
656-
export type StandardType = typeof standard;

0 commit comments

Comments
 (0)