feat: add new typings for cloud-config-client (#38007)

This commit is contained in:
Jeroen Claassens 2019-09-05 01:27:22 +02:00 committed by Ron Buckton
parent 0d9b406920
commit 871e4ab3d1
4 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import client = require('cloud-config-client');
client.load({
name: 'invoices'
}).then(config => {
const conf = config; // $ExpectType Config
const value1 = config.get('this.is.a.key'); // $ExpectType any
});
// Async through IFFE
(async () => {
const config = await client.load({name: 'invoices'}); // $ExpectType Config
})();
// With additional options
client.load({
name: 'invoices',
profiles: ['profile1', 'profile2'],
label: 'label',
auth: {
pass: 'password',
user: 'admin',
}
}).then(config => {
const conf = config; // $ExpectType Config
const value1 = config.get('this.is.a.key'); // $ExpectType any
});

65
types/cloud-config-client/index.d.ts vendored Normal file
View File

@ -0,0 +1,65 @@
// Type definitions for cloud-config-client 1.4
// Project: https://github.com/victorherraiz/cloud-config-client#readme
// Definitions by: Jeroen Claassens <https://github.com/favna>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
/// <reference types="node" />
import http = require('http');
import https = require('https');
export function load(options: Options, callback?: LoadCallback): Promise<Config>;
export abstract class Config {
constructor(data: ConfigData, context: { [key: string]: any });
properties(): { [key: string]: any };
raw(): { [key: string]: any };
get(keyParts: string): any;
forEach(callback: (property: string, value: string) => void, includeOverridden?: boolean): void;
toObject(): { [key: string]: any };
toString(spaces: number): string;
}
export interface ConfigFile {
name: string;
source: ConfigSource;
}
export interface ConfigSource {
[key: string]: any;
}
export interface ConfigData {
name: string;
profiles: string[];
label: string;
version: string;
propertySources: ConfigFile[];
}
export interface Auth {
user: string;
pass: string;
}
export interface Options {
endpoint?: string;
rejectUnauthorized?: boolean;
/** @deprecated use name */
application?: string;
name: string;
profiles?: string | string[];
label?: string;
auth?: Auth;
agent?: http.Agent | https.Agent;
context?: {
[key: string]: any
};
}
export interface LoadCallback {
(error: Error, config?: Config): void;
}

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"cloud-config-client-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }