Skip to content

Basic Typescript Type Definitions #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ cover_html
.splunkrc
*.zip
test_logs/*
docs/
docs/
.vscode/
*.tgz
29 changes: 13 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@

## How to contribute

If you would like to contribute to this project, go here for more information:

* [Splunk and open source][contributions]
* [Individual contributions][indivcontrib]
* [Company contributions][companycontrib]
If you would like to contribute to this project, see [Contributions to Splunk][indivcontrib] for more information.

## Issues & Bug Reports

If you're seeing some unexpected behavior with this project, please create an [issue on GitHub][issues] with the following information:

0. Version of this project you're using (ex: 1.7.1)
0. Platform version (ex: Windows Server 2012)
0. Framework version (ex: Node.js 0.10.37) or Browser (ex: Chrome 43.0.2357.81)
0. Splunk version (ex: 6.2.2)
0. Other relevant information (ex: local/remote environment, Splunk network configuration)
1. Version of this project you're using (ex: 1.7.1)
1. Platform version (ex: Windows Server 2012)
1. Framework version (ex: Node.js 0.10.37) or Browser (ex: Chrome 43.0.2357.81)
1. Splunk version (ex: 6.2.2)
1. Other relevant information (ex: local/remote environment, Splunk network configuration)

Alternatively, if you have a Splunk question please ask on [Splunk Answers][answers]

Expand All @@ -26,14 +22,14 @@ We love to see pull requests!

To create a pull request:

0. Fill out the [Individual Contributor Agreement][indivcontrib].
0. Fork [the repository][repo].
0. Make changes to the **`develop`** branch, preferably with tests.
0. Create a [pull request][pulls] against the **`develop`** branch.
1. Fill out the [Individual Contributor Agreement][indivcontrib].
1. Fork [the repository][repo].
1. Make changes to the **`develop`** branch, preferably with tests.
1. Create a [pull request][pulls] against the **`develop`** branch.

## Contact us

You can reach Splunk support at _support@splunk.com_ if you have Splunk related questions.
You can [contact support][contact] if you have Splunk related questions.

You can reach the Developer Platform team at _devinfo@splunk.com_.

Expand All @@ -43,4 +39,5 @@ You can reach the Developer Platform team at _devinfo@splunk.com_.
[answers]: http://answers.splunk.com/
[repo]: https://github.com/splunk/splunk-sdk-javascript
[issues]: https://github.com/splunk/splunk-sdk-javascript/issues
[pulls]: https://github.com/splunk/splunk-sdk-javascript/pulls
[pulls]: https://github.com/splunk/splunk-sdk-javascript/pulls
[contact]: https://www.splunk.com/en_us/support-and-services.html
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ JavaScript. This SDK supports both server- and client-side JavaScript.

## Requirements

* Node.js v.0.12, or v4 or later. The Splunk SDK for Javascript is tested with Node.js v.0.12, v4.2, and v10.0.
* Node.js v.0.12, or v4 or later. The Splunk SDK for Javascript is tested with Node.js v.0.12, v4.2, and v10.0, as well as with Typescript 3.8.
* Splunk Enterprise 6.3.0 or later, or Splunk Cloud. The Splunk SDK for Javascript is tested with Splunk Enterprise 7.0 and 7.2.

## Installation
Expand Down Expand Up @@ -57,6 +57,12 @@ code:

var splunkjs = require('splunk-sdk');

Or, to include the Splunk SDK in your Typescript project, use the `import` function in your code:

```typescript
import * as splunk from "splunk-sdk";
```

## Usage

The following examples show you how to list search jobs using client-side and
Expand Down Expand Up @@ -110,6 +116,47 @@ jobs:
});
});

### Typescript code example

This example shows how to use the Splunk SDK for Javascript in a Typescript project:

```typescript
import * as splunk from "splunk-sdk";

const service = new splunk.Service({username: "admin", password: "changeme"});

service.login((err, success) => {
if (err) {
throw err;
}

console.log("Login was successful: " + success);
service.jobs().fetch((err, jobs) => {
const jobList = jobs.list();
for(let i = 0; i < jobList.length; i++) {
console.log("Job " + i + ": " + jobList[i].sid);
}
});
});
```

Here is a good example of a `tslint.json` configuration that works well with this library and doesn't spit out too many errors, since these are basic Typescript definitions. Note that allowing the `var` keyword, as well as not using arrow functions makes typescript behave less predictably:

```json
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"no-var-keyword": false,
"only-arrow-functions": false,
"no-console": false
},
"rulesDirectory": []
```

## SDK examples

The Splunk SDK for JavaScript contains several server- and client-based examples.
Expand Down Expand Up @@ -251,6 +298,11 @@ To run all the tests and generate JUnit compatible XML in `splunk-sdk-javascript
<td>Packaged third-party dependencies (such as test runners)</td>
</tr>

<tr>
<td><b>/dist</b></td>
<td>Typescript Definition files</td>
</tr>

<tr>
<td><b>/docs</b></td>
<td>API reference documentation</td>
Expand Down Expand Up @@ -364,7 +416,7 @@ If you would like to contribute to the SDK, go here for more information:
### Support

1. You will be granted support if you or your company are already covered under an existing maintenance/support agreement.
Send an email to support@splunk.com and include "Splunk SDK for JavaScript" in the subject line.
Submit a new case in the [Support Portal][contact] and include "Splunk SDK for JavaScript" in the subject line.
2. If you are not covered under an existing maintenance/support agreement, you
can find help through the broader community at:
<ul>
Expand All @@ -381,6 +433,8 @@ If you would like to contribute to the SDK, go here for more information:

### Contact us

You can [contact support][contact] if you have Splunk related questions.

You can reach the Developer Platform team at _devinfo@splunk.com_.

## License
Expand All @@ -403,6 +457,7 @@ of embedded libraries and their licenses:
* [commander Node.js command-line interfaces][commander]: [MIT][commander-license]
* [script.js Asyncronous JavaScript loader and dependency manager][script.js]: [Apache][scriptjs-license]
* [base64.js Fast base64 encoding/decoding][base64.js]: [MIT][base64-license]
* [Typescript Typed JavaScript at Any Scale](https://www.typescriptlang.org/): [Apache]


[dox]: https://github.com/visionmedia/dox
Expand Down Expand Up @@ -451,3 +506,4 @@ of embedded libraries and their licenses:
[indivcontrib]: http://dev.splunk.com/goto/individualcontributions
[companycontrib]: http://dev.splunk.com/view/companycontributions/SP-CAAAEDR
[githubjsissues]: https://github.com/splunk/splunk-sdk-javascript/issues
[contact]: https://www.splunk.com/en_us/support-and-services.html
89 changes: 89 additions & 0 deletions dist/contrib/commander.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
declare const _exports: any;
export = _exports;
export var Command: typeof Command;
export var Option: typeof Option;
/**
* Initialize a new `Command`.
*
* @param {String} name
* @api public
*/
declare function Command(name: string): void;
declare class Command {
/**
* Initialize a new `Command`.
*
* @param {String} name
* @api public
*/
constructor(name: string);
commands: any[];
options: any[];
args: any[];
name: string;
opts: {};
/**
* Inherit from `EventEmitter.prototype`.
*/
__proto__: any;
command(name: string): Command;
parseExpectedArgs(args: any[]): Command;
action(fn: Function): Command;
option(flags: string, description: string, fn: any, defaultValue: any, isRequired: any): Command;
parse(argv: any[]): Command;
rawArgs: any[];
normalize(args: any[]): any[];
parseArgs(args: any[], unknown: any, required: any): Command;
executedCommand: any;
optionFor(arg: string): Option;
parseOptions(argv: any[]): any[];
missingArgument(name: string): void;
optionMissingArgument(option: string, flag: string): void;
optionMissing(option: string): void;
unknownOption(flag: string): void;
version(str: string, flags: string, ...args: any[]): Command;
_version: string;
description(str: string, ...args: any[]): string | Command;
_description: string;
usage(str: string, ...args: any[]): string | Command;
_usage: string;
largestOptionLength(): number;
optionHelp(): string;
commandHelp(): string;
helpInformation(): string;
promptForNumber(str: string, fn: Function): void;
promptForDate(str: string, fn: Function): void;
promptSingleLine(str: string, fn: Function, ...args: any[]): any;
promptMultiLine(str: string, fn: Function): void;
prompt(str: string, fn: Function, ...args: any[]): any;
password(str: string, mask: string, fn: Function): void;
confirm(str: string, fn: Function): void;
choose(list: any[], fn: Function): void;
}
/**
* Initialize a new `Option` with the given `flags` and `description`.
*
* @param {String} flags
* @param {String} description
* @api public
*/
declare function Option(flags: string, description: string): void;
declare class Option {
/**
* Initialize a new `Option` with the given `flags` and `description`.
*
* @param {String} flags
* @param {String} description
* @api public
*/
constructor(flags: string, description: string);
flags: string;
required: number;
optional: number;
bool: boolean;
short: any;
long: any;
description: string;
name(): string;
is(arg: string): boolean;
}
2 changes: 2 additions & 0 deletions dist/contrib/nodeunit/test_reporter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export var info: string;
export function run(modules: any, options: any): void;
26 changes: 26 additions & 0 deletions dist/contrib/script.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
declare const _exports: {
(e: any, t: any, n: any): {
(e: any, t: any, n: any): any;
get: (n: any, r: any) => void;
order(e: any, t: any, n: any): void;
path(e: any): void;
urlArgs(e: any): void;
ready(e: any, t: any, n: any): any;
done(e: any): void;
};
get: (n: any, r: any) => void;
order(e: any, t: any, n: any): void;
path(e: any): void;
urlArgs(e: any): void;
ready(e: any, t: any, n: any): {
(e: any, t: any, n: any): any;
get: (n: any, r: any) => void;
order(e: any, t: any, n: any): void;
path(e: any): void;
urlArgs(e: any): void;
ready(e: any, t: any, n: any): any;
done(e: any): void;
};
done(e: any): void;
};
export = _exports;
1 change: 1 addition & 0 deletions dist/examples/node/cmdline.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function create(): any;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/apps.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, done: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/apps_async.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, callback: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/endpoint_instantiation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, done: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/firedalerts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, done: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/firedalerts_async.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, callback: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/firedalerts_create.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, done: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/firedalerts_delete.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, done: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/get_job.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, callback: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/log.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, done: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/pivot_async.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, callback: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/savedsearches.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, done: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/savedsearches_async.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, callback: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/savedsearches_create.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, done: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/savedsearches_delete.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, done: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/search_blocking.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, callback: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/search_normal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, callback: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/search_oneshot.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, callback: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/helloworld/search_realtime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(opts: any, callback: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/jobs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(argv: any, callback: any): void;
1 change: 1 addition & 0 deletions dist/examples/node/search.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function main(argv: any, callback: any): void;
23 changes: 23 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export declare const Logger: {
log: (...args: any[]) => void;
error: (...args: any[]) => void;
warn: (...args: any[]) => void;
info: (...args: any[]) => void;
printMessages: (allMessages: any) => void;
setLevel: (level: string | number, ...args: any[]) => void;
levels: {
"ALL": number;
"INFO": number;
"WARN": number;
"ERROR": number;
"NONE": number;
};
};
export declare const Context: any;
export declare const Service: any;
export declare const Http: any;
export declare const Utils: typeof import("./lib/utils");
export declare const Async: typeof import("./lib/async");
export declare const Paths: any;
export declare const Class: any;
export declare const ModularInputs: typeof import("./lib/modularinputs");
1 change: 1 addition & 0 deletions dist/lib/async.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
2 changes: 2 additions & 0 deletions dist/lib/context.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const _exports: any;
export = _exports;
1 change: 1 addition & 0 deletions dist/lib/entries/browser.entry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions dist/lib/entries/browser.test.entry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions dist/lib/entries/browser.ui.charting.entry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions dist/lib/entries/browser.ui.entry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions dist/lib/entries/browser.ui.timeline.entry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
2 changes: 2 additions & 0 deletions dist/lib/http.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const _exports: any;
export = _exports;
Empty file added dist/lib/jquery.class.d.ts
Empty file.
Loading