Skip to content

Commit e3bc011

Browse files
move storage adapter interface back to utils
1 parent 98c252e commit e3bc011

File tree

4 files changed

+31
-109
lines changed

4 files changed

+31
-109
lines changed

packages/oc-azure-storage-adapter/src/index.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import format from 'stringformat';
88
import fs from 'fs-extra';
99
import nodeDir, { PathsResult } from 'node-dir';
1010
import { promisify } from 'util';
11-
12-
import { getFileInfo, strings } from 'oc-storage-adapters-utils';
11+
import {
12+
getFileInfo,
13+
strings,
14+
StorageAdapter
15+
} from 'oc-storage-adapters-utils';
1316

1417
const getPaths: (path: string) => Promise<PathsResult> = promisify(
1518
nodeDir.paths
@@ -39,27 +42,6 @@ export interface AzureConfig {
3942
refreshInterval?: number;
4043
}
4144

42-
export interface StorageAdapter {
43-
adapterType: string;
44-
getFile(filePath: string): Promise<string>;
45-
getJson<T = unknown>(filePath: string, force?: boolean): Promise<T>;
46-
getUrl: (componentName: string, version: string, fileName: string) => string;
47-
listSubDirectories(dir: string): Promise<string[]>;
48-
maxConcurrentRequests: number;
49-
putDir(folderPath: string, filePath: string): Promise<unknown>;
50-
putFile(
51-
filePath: string,
52-
fileName: string,
53-
isPrivate: boolean
54-
): Promise<unknown>;
55-
putFileContent(
56-
data: unknown,
57-
path: string,
58-
isPrivate: boolean
59-
): Promise<unknown>;
60-
isValid: () => boolean;
61-
}
62-
6345
export default function azureAdapter(conf: AzureConfig): StorageAdapter {
6446
const isValid = () => {
6547
if (

packages/oc-gs-storage-adapter/src/index.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import fs from 'fs-extra';
44
import nodeDir, { PathsResult } from 'node-dir';
55
import { Storage, UploadOptions } from '@google-cloud/storage';
66
import tmp from 'tmp';
7-
import { getFileInfo, strings } from 'oc-storage-adapters-utils';
7+
import {
8+
getFileInfo,
9+
strings,
10+
StorageAdapter
11+
} from 'oc-storage-adapters-utils';
812
import { promisify } from 'util';
913

1014
const getPaths: (path: string) => Promise<PathsResult> = promisify(
@@ -20,27 +24,6 @@ export interface GsConfig {
2024
refreshInterval?: number;
2125
}
2226

23-
export interface StorageAdapter {
24-
adapterType: string;
25-
getFile(filePath: string): Promise<string>;
26-
getJson<T = unknown>(filePath: string, force?: boolean): Promise<T>;
27-
getUrl: (componentName: string, version: string, fileName: string) => string;
28-
listSubDirectories(dir: string): Promise<string[]>;
29-
maxConcurrentRequests: number;
30-
putDir(folderPath: string, filePath: string): Promise<unknown>;
31-
putFile(
32-
filePath: string,
33-
fileName: string,
34-
isPrivate: boolean
35-
): Promise<unknown>;
36-
putFileContent(
37-
data: unknown,
38-
path: string,
39-
isPrivate: boolean
40-
): Promise<unknown>;
41-
isValid: () => boolean;
42-
}
43-
4427
export default function gsAdapter(conf: GsConfig): StorageAdapter {
4528
const isValid = () => {
4629
if (!conf.bucket || !conf.projectId || !conf.path) {

packages/oc-s3-storage-adapter/src/index.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import nodeDir, { PathsResult } from 'node-dir';
1010
import _ from 'lodash';
1111
import { promisify } from 'util';
1212

13-
import { getFileInfo, getNextYear, strings } from 'oc-storage-adapters-utils';
13+
import {
14+
getFileInfo,
15+
getNextYear,
16+
strings,
17+
StorageAdapter
18+
} from 'oc-storage-adapters-utils';
1419

1520
import type { Agent as httpAgent } from 'http';
1621
import type { Agent as httpsAgent } from 'https';
@@ -44,27 +49,6 @@ export type S3Config = RequireAllOrNone<
4449
'key' | 'secret'
4550
>;
4651

47-
export interface StorageAdapter {
48-
adapterType: string;
49-
getFile(filePath: string): Promise<string>;
50-
getJson<T = unknown>(filePath: string, force?: boolean): Promise<T>;
51-
getUrl: (componentName: string, version: string, fileName: string) => string;
52-
listSubDirectories(dir: string): Promise<string[]>;
53-
maxConcurrentRequests: number;
54-
putDir(folderPath: string, filePath: string): Promise<unknown>;
55-
putFile(
56-
filePath: string,
57-
fileName: string,
58-
isPrivate: boolean
59-
): Promise<unknown>;
60-
putFileContent(
61-
data: unknown,
62-
path: string,
63-
isPrivate: boolean
64-
): Promise<unknown>;
65-
isValid: () => boolean;
66-
}
67-
6852
const streamToString = (stream: NodeJS.ReadableStream) =>
6953
new Promise((resolve, reject) => {
7054
const chunks: Buffer[] = [];

packages/oc-storage-adapters-utils/src/index.ts

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,23 @@ export { getMimeType } from './get-mime-type';
33
export { getNextYear } from './get-next-year';
44
export * as strings from './strings';
55

6-
type Callback<Data = unknown, E = Error> = (err: E | null, data: Data) => void;
7-
86
export interface StorageAdapter {
97
adapterType: string;
10-
getFile: {
11-
(filePath: string, cb: Callback<string>): void;
12-
(filePath: string): Promise<string>;
13-
};
14-
getJson: {
15-
<T = unknown>(
16-
filePath: string,
17-
force: boolean,
18-
cb: Callback<T, string>
19-
): void;
20-
<T = unknown>(filePath: string, force: boolean): Promise<T>;
21-
<T = unknown>(filePath: string, cb: Callback<T, string>): void;
22-
<T = unknown>(filePath: string): Promise<T>;
23-
};
8+
getFile(filePath: string): Promise<string>;
9+
getJson<T = unknown>(filePath: string, force?: boolean): Promise<T>;
2410
getUrl: (componentName: string, version: string, fileName: string) => string;
25-
listSubDirectories: {
26-
(dir: string, cb: Callback<string[], Error & { code?: string }>): void;
27-
(dir: string): Promise<string[]>;
28-
};
11+
listSubDirectories(dir: string): Promise<string[]>;
2912
maxConcurrentRequests: number;
30-
putDir: {
31-
(folderPath: string, filePath: string, cb: Callback): void;
32-
(folderPath: string, filePath: string): Promise<unknown>;
33-
};
34-
putFile: {
35-
(
36-
filePath: string,
37-
fileName: string,
38-
isPrivate: boolean,
39-
callback: Callback<unknown, string>
40-
): void;
41-
(filePath: string, fileName: string, isPrivate: boolean): Promise<unknown>;
42-
};
43-
putFileContent: {
44-
(
45-
data: unknown,
46-
path: string,
47-
isPrivate: boolean,
48-
callback: Callback<unknown, string>
49-
): void;
50-
(data: unknown, path: string, isPrivate: boolean): Promise<unknown>;
51-
};
13+
putDir(folderPath: string, filePath: string): Promise<unknown>;
14+
putFile(
15+
filePath: string,
16+
fileName: string,
17+
isPrivate: boolean
18+
): Promise<unknown>;
19+
putFileContent(
20+
data: unknown,
21+
path: string,
22+
isPrivate: boolean
23+
): Promise<unknown>;
24+
isValid: () => boolean;
5225
}

0 commit comments

Comments
 (0)