-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.ts
144 lines (130 loc) · 3.5 KB
/
provider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { Manifest } from './manifest';
import { DropboxProvider } from './providers/dropbox';
import { OSSProvider } from './providers/oss';
import { S3Provider } from './providers/s3';
export interface ExtensionShortDetails {
name: string;
latestVersion: string;
lastUpdated: Date;
}
export interface ListRemoteResult {
details: ExtensionShortDetails[];
}
export interface ExtensionDetails {
name: string;
version: string;
description: string;
readMe: string;
changeLog: string;
lastUpdated: Date;
}
export interface ExtensionHistory {
name: string;
versions: {
[version: string]: Date;
};
}
// test only !!!
const mockBackend = {
listRemoteExtensions: async () => {
return {
details: [
{
name: 'ext1',
latestVersion: '0.1',
lastUpdated: new Date(1995, 11, 17),
},
],
};
},
showExtensionDetails: async (name: string, version: string) => {
return {
name,
version,
description: 'mock extension',
readMe: 'this is readme',
changeLog: 'this is changeLog',
lastUpdated: new Date(1995, 11, 17),
};
},
showExtensionHistory: async (name: string) => {
return {
name,
versions: {
'0.0.1': new Date(1995, 11, 17),
'0.0.2': new Date(1995, 11, 18),
'0.1': new Date(1995, 11, 19),
},
};
},
publishExtension: async (packagePath: string, manifest: Manifest) => {
if (!packagePath || manifest.version === '1.0') {
return false;
}
return true;
},
unpublishExtension: async (name: string, version?: string) => {
if (name === 'ext2' || version === '1.0') {
return false;
} else {
return true;
}
},
checkExtension: async (name: string, version?: string) => {
if (name === 'ext1' || version === '0.0.2') {
return true;
} else {
return false;
}
},
};
export function getProvider(backend: string, backendOptions?: any): Provider {
if (backend === 'mock') {
return mockBackend;
} else if (backend === 'oss') {
return new OSSProvider(backendOptions);
} else if (backend === 'dropbox') {
return new DropboxProvider(backendOptions);
} else if (backend === 's3') {
return new S3Provider(backendOptions);
}
throw new Error(`Unknown provider: ${backend}`);
}
export interface Provider {
/**
* list remote extension brief information
*/
listRemoteExtensions(): Promise<ListRemoteResult>;
/**
* show an extension details
* @param extId extension extId
* @param version version of extension, use latest version if missing
*/
showExtensionDetails(
extId: string,
version?: string
): Promise<ExtensionDetails>;
/**
* show history of an extension
* @param extId extension extId
*/
showExtensionHistory(extId: string): Promise<ExtensionHistory>;
/**
* publish an extension to a remote host
* @param packagePath extension package path
* @param version version of extension
*/
publishExtension(packagePath: string, manifest: Manifest): Promise<boolean>;
/**
* unpublish an extension from a remote host
* @param extId extension extId
* @param version version of extension, use latest version if missing
*/
unpublishExtension(extId: string, version?: string): Promise<boolean>;
/**
* check existance of an extension on a remote host
* @param extId extension name
* @param version version of extension, use latest version if missing
*/
checkExtension(extId: string, version?: string): Promise<boolean>;
}