backend-common: refactor reader types
This commit is contained in:
@@ -17,8 +17,7 @@
|
||||
import fetch, { RequestInit, HeadersInit, Response } from 'node-fetch';
|
||||
import { Config } from '@backstage/config';
|
||||
import { NotFoundError } from '../errors';
|
||||
import { UrlReader } from './types';
|
||||
import { ReaderFactory } from './UrlReaders';
|
||||
import { ReaderFactory, UrlReader } from './types';
|
||||
|
||||
type Options = {
|
||||
// TODO: added here for future support, but we only allow dev.azure.com for now
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
import fetch, { RequestInit, HeadersInit, Response } from 'node-fetch';
|
||||
import { Config } from '@backstage/config';
|
||||
import { ReaderFactory } from './UrlReaders';
|
||||
import { UrlReader } from './types';
|
||||
import { ReaderFactory, UrlReader } from './types';
|
||||
import { NotFoundError } from '../errors';
|
||||
|
||||
type Options = {
|
||||
|
||||
@@ -18,8 +18,7 @@ import { Config } from '@backstage/config';
|
||||
import parseGitUri from 'git-url-parse';
|
||||
import fetch, { HeadersInit, RequestInit, Response } from 'node-fetch';
|
||||
import { NotFoundError } from '../errors';
|
||||
import { UrlReader } from './types';
|
||||
import { ReaderFactory } from './UrlReaders';
|
||||
import { ReaderFactory, UrlReader } from './types';
|
||||
|
||||
/**
|
||||
* The configuration parameters for a single GitHub API provider.
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
import fetch, { RequestInit, Response } from 'node-fetch';
|
||||
import { Config } from '@backstage/config';
|
||||
import { NotFoundError } from '../errors';
|
||||
import { UrlReader } from './types';
|
||||
import { ReaderFactory } from './UrlReaders';
|
||||
import { ReaderFactory, UrlReader } from './types';
|
||||
|
||||
type Options = {
|
||||
host: string;
|
||||
|
||||
@@ -14,14 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { UrlReader } from './types';
|
||||
|
||||
export type UrlReaderPredicate = (url: URL) => boolean;
|
||||
|
||||
export type UrlReaderPredicateTuple = {
|
||||
predicate: UrlReaderPredicate;
|
||||
reader: UrlReader;
|
||||
};
|
||||
import { UrlReader, UrlReaderPredicateTuple } from './types';
|
||||
|
||||
type Options = {
|
||||
// UrlReader to fall back to if no other reader is matched
|
||||
|
||||
@@ -16,30 +16,14 @@
|
||||
|
||||
import { Logger } from 'winston';
|
||||
import { Config } from '@backstage/config';
|
||||
import { UrlReader } from './types';
|
||||
import {
|
||||
UrlReaderPredicateMux,
|
||||
UrlReaderPredicateTuple,
|
||||
} from './UrlReaderPredicateMux';
|
||||
import { ReaderFactory, UrlReader } from './types';
|
||||
import { UrlReaderPredicateMux } from './UrlReaderPredicateMux';
|
||||
import { AzureUrlReader } from './AzureUrlReader';
|
||||
import { BitbucketUrlReader } from './BitbucketUrlReader';
|
||||
import { GithubUrlReader } from './GithubUrlReader';
|
||||
import { GitlabUrlReader } from './GitlabUrlReader';
|
||||
import { FetchUrlReader } from './FetchUrlReader';
|
||||
|
||||
export type ReaderFactoryOptions = {
|
||||
config: Config;
|
||||
logger: Logger;
|
||||
};
|
||||
|
||||
/**
|
||||
* A factory function that can read config to construct zero or more
|
||||
* UrlReaders along with a predicate for when it should be used.
|
||||
*/
|
||||
export type ReaderFactory = (
|
||||
options: ReaderFactoryOptions,
|
||||
) => UrlReaderPredicateTuple[];
|
||||
|
||||
/**
|
||||
* UrlReaders provide various utilities related to the UrlReader interface.
|
||||
*/
|
||||
|
||||
@@ -14,9 +14,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Logger } from 'winston';
|
||||
import { Config } from '@backstage/config';
|
||||
|
||||
/**
|
||||
* A generic interface for fetching plain data from URLs.
|
||||
*/
|
||||
export type UrlReader = {
|
||||
read(url: string): Promise<Buffer>;
|
||||
};
|
||||
|
||||
export type UrlReaderPredicateTuple = {
|
||||
predicate: (url: URL) => boolean;
|
||||
reader: UrlReader;
|
||||
};
|
||||
|
||||
/**
|
||||
* A factory function that can read config to construct zero or more
|
||||
* UrlReaders along with a predicate for when it should be used.
|
||||
*/
|
||||
export type ReaderFactory = (options: {
|
||||
config: Config;
|
||||
logger: Logger;
|
||||
}) => UrlReaderPredicateTuple[];
|
||||
|
||||
Reference in New Issue
Block a user