mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
Merge pull request #33083 from dantman/pkgcloud
Partial implementation of pkgcloud types
This commit is contained in:
7
types/pkgcloud/README.md
Normal file
7
types/pkgcloud/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
This file exists for reminding contributors that this definition is **WIP**.
|
||||
|
||||
### Note
|
||||
|
||||
pkgcloud has a large number of client types and providers. Only some clients and providers have types defined.
|
||||
|
||||
You are welcome to contribute definitions for other clients and providers and add provider specific properties.
|
||||
131
types/pkgcloud/index.d.ts
vendored
Normal file
131
types/pkgcloud/index.d.ts
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
// Type definitions for pkgcloud 1.7
|
||||
// Project: https://github.com/pkgcloud/pkgcloud#readme
|
||||
// Definitions by: Daniel Friesen <https://github.com/dantman>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export const version: string;
|
||||
|
||||
export interface ClientError extends Error {
|
||||
provider?: Providers;
|
||||
method?: string;
|
||||
failCode?: string;
|
||||
statusCode?: number;
|
||||
href?: string;
|
||||
headers?: { [headerName: string]: string };
|
||||
result?: any;
|
||||
}
|
||||
|
||||
export type Providers =
|
||||
| 'amazon'
|
||||
| 'azure'
|
||||
| 'digitalocean'
|
||||
| 'google'
|
||||
| 'hp'
|
||||
| 'iriscouch'
|
||||
| 'joyent'
|
||||
| 'mongohq'
|
||||
| 'mongolab'
|
||||
| 'oneandone'
|
||||
| 'openstack'
|
||||
| 'rackspace'
|
||||
| 'redistogo'
|
||||
| 'telefonic';
|
||||
|
||||
export interface BaseProviderOptions {
|
||||
provider: Providers;
|
||||
}
|
||||
|
||||
export interface AmazonProviderOptions {
|
||||
provider: 'amazon';
|
||||
keyId: string;
|
||||
key: string;
|
||||
region?: string;
|
||||
}
|
||||
|
||||
export interface AzureProviderOptions {
|
||||
provider: 'azure';
|
||||
storageAccount: string;
|
||||
storageAccessKey: string;
|
||||
location?: string;
|
||||
}
|
||||
|
||||
export type ProviderOptions = BaseProviderOptions & Partial<
|
||||
| AmazonProviderOptions
|
||||
| AzureProviderOptions
|
||||
>;
|
||||
|
||||
/**
|
||||
* Storage
|
||||
*/
|
||||
|
||||
export namespace storage {
|
||||
interface StorageUploadOptions {
|
||||
container: string;
|
||||
remote: string;
|
||||
}
|
||||
|
||||
interface StorageDownloadOptions {
|
||||
container: string;
|
||||
remote: string;
|
||||
}
|
||||
|
||||
interface Client {
|
||||
provider: string;
|
||||
config: ProviderOptions;
|
||||
protocol: string;
|
||||
|
||||
getContainers(
|
||||
callback: (err: ClientError, containers: Container[]) => any,
|
||||
): void;
|
||||
createContainer(
|
||||
options: any,
|
||||
callback: (err: ClientError, container: Container) => any,
|
||||
): void;
|
||||
destroyContainer(
|
||||
containerName: string,
|
||||
callback: (err: ClientError) => any,
|
||||
): void;
|
||||
getContainer(
|
||||
containerName: string,
|
||||
callback: (err: ClientError, container: Container) => any,
|
||||
): void;
|
||||
upload(options: StorageUploadOptions): NodeJS.WriteStream;
|
||||
download(options: StorageDownloadOptions): NodeJS.ReadStream;
|
||||
getFiles(
|
||||
containerName: string,
|
||||
callback: (err: ClientError, files: File[]) => any,
|
||||
): void;
|
||||
getFile(
|
||||
containerName: string,
|
||||
file: string,
|
||||
callback: (err: ClientError, file: File) => any,
|
||||
): void;
|
||||
removeFile(
|
||||
containerName: string,
|
||||
file: string,
|
||||
callback: (err: ClientError) => any,
|
||||
): void;
|
||||
// Logs
|
||||
on(
|
||||
eventName: string,
|
||||
callback: (message: string, object?: any) => any,
|
||||
): void;
|
||||
}
|
||||
|
||||
interface Container {
|
||||
// files: ?
|
||||
client: Client;
|
||||
}
|
||||
|
||||
interface File {
|
||||
container: string;
|
||||
name: string;
|
||||
size: number;
|
||||
client: Client;
|
||||
}
|
||||
|
||||
function createClient(options: ProviderOptions): Client;
|
||||
}
|
||||
64
types/pkgcloud/pkgcloud-tests.ts
Normal file
64
types/pkgcloud/pkgcloud-tests.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { createReadStream, createWriteStream } from "fs";
|
||||
import * as pkgcloud from "pkgcloud";
|
||||
|
||||
/**
|
||||
* Storage
|
||||
*/
|
||||
|
||||
// Amazon
|
||||
pkgcloud.storage.createClient({
|
||||
provider: 'amazon',
|
||||
keyId: 'ABDEFGHI',
|
||||
key: 'AABDEF==',
|
||||
});
|
||||
|
||||
// Azure
|
||||
pkgcloud.storage.createClient({
|
||||
provider: 'azure',
|
||||
storageAccount: 'abcdefg',
|
||||
storageAccessKey: 'AABDEF==',
|
||||
});
|
||||
|
||||
// Upload a File
|
||||
{
|
||||
const client = pkgcloud.storage.createClient({
|
||||
provider: 'amazon'
|
||||
});
|
||||
|
||||
const readStream = createReadStream('a-file.txt');
|
||||
const writeStream = client.upload({
|
||||
container: 'a-container',
|
||||
remote: 'remote-file-name.txt'
|
||||
});
|
||||
|
||||
writeStream.on('error', (err: pkgcloud.ClientError) => {});
|
||||
writeStream.on('success', (file: pkgcloud.storage.File) => {});
|
||||
readStream.pipe(writeStream);
|
||||
}
|
||||
|
||||
// Download a File
|
||||
{
|
||||
const client = pkgcloud.storage.createClient({
|
||||
provider: 'amazon'
|
||||
});
|
||||
|
||||
const readStream = client.download({
|
||||
container: 'a-container',
|
||||
remote: 'remote-file-name.txt'
|
||||
});
|
||||
readStream.pipe(createWriteStream('a-file.txt'));
|
||||
}
|
||||
|
||||
// Logs
|
||||
{
|
||||
const client = pkgcloud.storage.createClient({
|
||||
provider: 'amazon'
|
||||
});
|
||||
|
||||
client.on('log::*', (message, object) => {
|
||||
console.log(message);
|
||||
if (object) {
|
||||
console.dir(object);
|
||||
}
|
||||
});
|
||||
}
|
||||
23
types/pkgcloud/tsconfig.json
Normal file
23
types/pkgcloud/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"pkgcloud-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/pkgcloud/tslint.json
Normal file
1
types/pkgcloud/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user