-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reference): change File from stamp to TypeScript class (#4096)
Refs #3481 BREAKING CHANGE: File from apidom-reference package became a class and requires to be instantiated with new operator.
- Loading branch information
Showing
66 changed files
with
519 additions
and
507 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { type } from 'ramda'; | ||
import { isString } from 'ramda-adjunct'; | ||
import { ParseResultElement } from '@swagger-api/apidom-core'; | ||
|
||
import * as url from './util/url'; | ||
|
||
/** | ||
* This class represents a File object with url and data. | ||
*/ | ||
|
||
export interface FileOptions { | ||
readonly uri: string; | ||
readonly mediaType?: string; | ||
readonly data?: Buffer | DataView | ArrayBuffer | string; | ||
readonly parseResult?: ParseResultElement; | ||
} | ||
|
||
class File { | ||
public uri: string; | ||
|
||
public mediaType: string; | ||
|
||
public data?: Buffer | DataView | ArrayBuffer | string; | ||
|
||
public parseResult?: ParseResultElement; | ||
|
||
constructor({ uri, mediaType = 'text/plain', data, parseResult }: FileOptions) { | ||
this.uri = uri; | ||
this.mediaType = mediaType; | ||
this.data = data; | ||
this.parseResult = parseResult; | ||
} | ||
|
||
get extension(): string { | ||
if (isString(this.uri)) { | ||
return url.getExtension(this.uri); | ||
} | ||
return ''; | ||
} | ||
|
||
toString(): string { | ||
if (typeof this.data === 'string') { | ||
return this.data; | ||
} | ||
|
||
if ( | ||
this.data instanceof ArrayBuffer || | ||
['ArrayBuffer'].includes(type(this.data)) || | ||
ArrayBuffer.isView(this.data) | ||
) { | ||
const textDecoder = new TextDecoder('utf-8'); | ||
return textDecoder.decode(this.data as Buffer | DataView | ArrayBuffer); | ||
} | ||
|
||
return String(this.data); | ||
} | ||
} | ||
|
||
export default File; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.