Commit 409b5a44 authored by Fred Eisele's avatar Fred Eisele
Browse files

clone from DefinitelyTyped::master

parent 88b52444
Loading
Loading
Loading
Loading
+3 −76
Changes for README.md: 3 added lines, 76 removed lines.
Original line number Diff line number Diff line
# typescript-typings
Each branch represents a different set of typescript typings that I am working on.
## kafka-node

## New Project

To create a new set of typings...

   git checkout master
   git checkout -b <new-project-name>

   edit the files as needed (see below for hints)
   git commit -m 'initial commit of sample'

The projects that have been previously commited 
are good samples of the types of edits you will need 
for your porject.

   git difftool master n3 

## Sync with DefinitelyTyped

In order to get you typings into the offical npm repository
you will need to convert your project typings and place
them in a DefinitelyTyped directory.

  * http://definitelytyped.org/
  * https://github.com/DefinitelyTyped/DefinitelyTyped


To make a new set of typings:
 * Checkout and develop the description files from DefinitelyTyped
     Development is easier here because you have the 
       advantage of having your reference-paths working properly.
     
 * branch from the master
     git checkout master
     git checkout -b newpackage
 * edit the `package.json`
     "name": "@types/sample",
     "version": "0.0.1",
     "description": "A set of TypeScript definitions for SAMPLE",
     "main": "",
     "files": [
       "index.d.ts"
     ],
 * add in the files from DefinitelyTyped
     cp <DT>/n3/* .
     index.d.ts
     newpackage-tests.ts

## Project Log

### N3

  git checkout n3

Lightning fast, spec-compatible, streaming RDF for JavaScript.

 * https://github.com/RubenVerborgh/N3.js

### webgme

  git checkout webgme

Web based generic modeling environment.

 * https://webgme.org/
 * https://github.com/webgme/webgme

### Cytoscape

  git checkout cytoscape

Graph theory (a.k.a. network) library for analysis and visualisation.

 * http://js.cytoscape.org/
 * https://github.com/cytoscape/cytoscape.js
A wrapper around the Node.js client for Apache Kafka 0.8 and later.

 * https://github.com/SOHU-Co/kafka-node
+151 −15
Changes for index.d.ts: 151 added lines, 15 removed lines.
Original line number Diff line number Diff line
// Type definitions for <SAMPLE> v0.0.1 
// Project: https://github.com/<SAMPLE>.js
// Definitions by: Fred Eisele <https://github.com/phreed>
// Type definitions for kafka-node 1.3.3
// Project: https://github.com/SOHU-Co/kafka-node/
// Definitions by: Daniel Imrie-Situnayake <https://github.com/dansitu/>, Bill <https://github.com/bkim54>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference types="node" />

/**
### 0.0.1 Changelog (https://github.com/<SAMPLE>)
// # Classes
export declare class Client {
    constructor(connectionString: string, clientId: string, options?: ZKOptions);
    close(callback?: Function): void;
    topicExists(topics: Array<string>, callback: Function): void;
    refreshMetadata(topics: Array<string>, cb?: (error: any, data: any) => any): void;
    close(cb: (error: any) => any): void;
}

export declare class Producer {
    constructor(client: Client, options?: any, customPartitioner?: any);
    on(eventName: string, cb: () => any): void;
    on(eventName: string, cb: (error: any) => any): void;
    send(payloads: Array<ProduceRequest>, cb: (error: any, data: any) => any): void;
    createTopics(topics: Array<string>, async: boolean, cb?: (error: any, data: any) => any): void;
    close(cb: (error: any) => any): void;
}

#### TODO:
export declare class HighLevelProducer {
    constructor(client: Client, options?: any, customPartitioner?: any);
    on(eventName: string, cb: () => any): void;
    on(eventName: string, cb: (error: any) => any): void;
    send(payloads: Array<ProduceRequest>, cb: (error: any, data: any) => any): void;
    createTopics(topics: Array<string>, async: boolean, cb?: (error: any, data: any) => any): void;
    close(cb: (error: any) => any): void;
}

export declare class Consumer {
    constructor(client: Client, fetchRequests: Array<OffsetFetchRequest>, options: ConsumerOptions);
    on(eventName: string, cb: (message: string) => any): void;
    on(eventName: string, cb: (error: any) => any): void;
    addTopics(topics: Array<string>, cb: (error: any, added: boolean) => any): void;
    addTopics(topics: Array<Topic>, cb: (error: any, added: boolean) => any, fromOffset: boolean): void;
    removeTopics(topics: Array<string>, cb: (error: any, removed: boolean) => any): void;
    commit(cb: (error: any, data: any) => any): void;
    setOffset(topic: string, partition: number, offset: number): void;
    pause(): void;
    resume(): void;
    pauseTopics(topics: Array<any> /* Array<string|Topic> */): void;
    resumeTopics(topics: Array<any> /* Array<string|Topic> */): void;
    close(force: boolean, cb: () => any): void;
}

Match samples from README.md
export declare class HighLevelConsumer {
    constructor(client: Client, payloads: Array<Topic>, options: ConsumerOptions);
    on(eventName: string, cb: (message: string) => any): void;
    on(eventName: string, cb: (error: any) => any): void;
    addTopics(topics: Array<string>, cb: (error: any, added: boolean) => any): void;
    addTopics(topics: Array<Topic>, cb: (error: any, added: boolean) => any, fromOffset: boolean): void;
    removeTopics(topics: Array<string>, cb: (error: any, removed: boolean) => any): void;
    commit(cb: (error: any, data: any) => any): void;
    setOffset(topic: string, partition: number, offset: number): void;
    pause(): void;
    resume(): void;
    pauseTopics(topics: Array<any> /* Array<string|Topic> */): void;
    resumeTopics(topics: Array<any> /* Array<string|Topic> */): void;
    close(force: boolean, cb: () => any): void;
}

- [x] do it.
export declare class ConsumerGroup {
    constructor(options: ConsumerGroupOptions, topics: string[]);
    on(eventName: string, cb: (message: string) => any): void;
    on(eventName: string, cb: (error: any) => any): void;
    close(force: boolean, cb: (error: any) => any): void;
}

*/
export declare class Offset {
    constructor(client: Client);
    on(eventName: string, cb: () => any): void;
    fetch(payloads: Array<OffsetRequest>, cb: (error: any, data: any) => any): void;
    commit(groupId: string, payloads: Array<OffsetCommitRequest>, cb: (error: any, data: any) => any): void;
    fetchCommits(groupId: string, payloads: Array<OffsetFetchRequest>, cb: (error: any, data: any) => any): void;
    fetchLatestOffsets(topics: Array<string>, cb: (error: any, data: any) => any): void;
    fetchEarliestOffsets(topics: Array<string>, cb: (error: any, data: any) => any): void;
    on(eventName: string, cb: (error: any) => any): void;
}

declare module "sample" {
    import * as fs from "fs";
export declare class KeyedMessage {
    constructor(key: string, message: string);
}

    namespace Sample {
// # Interfaces
export interface AckBatchOptions {
    noAckBatchSize: number | null,
    noAckBatchAge: number | null
}

        type Dictionary = { [key: string]: any };
export interface ZKOptions {
    sessionTimeout?: number;
    spinDelay?: number;
    retries?: number;
}

export interface ProduceRequest {
    topic: string;
    messages: any; // Array<string> | Array<KeyedMessage> | string | KeyedMessage
    key?: any;
    partition?: number;
    attributes?: number;
}

    export = Sample;
export interface ConsumerOptions {
    groupId?: string;
    id?: string;
    autoCommit?: boolean;
    autoCommitIntervalMs?: number;
    fetchMaxWaitMs?: number;
    fetchMinBytes?: number;
    fetchMaxBytes?: number;
    fromOffset?: boolean;
    encoding?: string;
}

export interface CustomPartitionAssignmentProtocol {
    name: string;
    version: number;
    userData: {};
    assign: (topicPattern: any, groupMembers: any, callback: (error: any, result: any) => void) => void;
}

export interface ConsumerGroupOptions {
    host: string;
    zk?: ZKOptions;
    batch?: AckBatchOptions;
    ssl?: boolean;
    id: string;
    groupId: string;
    sessionTimeout: number;
    protocol: Array<"roundrobin" | "range" | CustomPartitionAssignmentProtocol>;
    fromOffset: "earliest" | "latest" | "none";
    migrateHLC: false;
    migrateRolling: true;
}

export interface Topic {
    topic: string;
    offset?: number;
    encoding?: string;
    autoCommit?: boolean;
}

export interface OffsetRequest {
    topic: string;
    partition?: number;
    time?: number;
    maxNum?: number;
}

export interface OffsetCommitRequest {
    topic: string;
    partition?: number;
    offset: number;
    metadata?: string;
}

export interface OffsetFetchRequest {
    topic: string;
    partition?: number;
    offset?: number;
}

kafka-node-tests.ts

0 → 100644
+176 −0
Changes for kafka-node-tests.ts: 176 added lines, 0 removed lines.
Original line number Diff line number Diff line
import kafka = require('kafka-node');

var basicClient = new kafka.Client('localhost:2181/', 'sendMessage');

var optionsClient = new kafka.Client('localhost:2181/', 'sendMessage', {
    sessionTimeout: 30000,
    spinDelay: 1000,
    retries: 0
});
optionsClient.close();
optionsClient.close(function(){});

var producer = new kafka.Producer(basicClient);
producer.on('error', function(error: Error){});
producer.on('ready', function(){

    var messages = [{
        topic: 'topicName',
        messages: ['message body'],
        partition: 0,
        attributes: 2
    }, {
        topic: 'topicName',
        messages: ['message body'],
        partition: 0
    }, {
        topic: 'topicName',
        messages: ['message body'],
        attributes: 0
    }, {
        topic: 'topicName',
        messages: ['message body']
    }, {
        topic: 'topicName',
        messages: [new kafka.KeyedMessage('key', 'message')]
    }];

    producer.send(messages, function(err: Error){});
    producer.send(messages, function(err: Error, data: Object){});

    producer.createTopics(['t'], true, function (err: Error, data: Object) {});
    producer.createTopics(['t'], false, function (err, data) {});
    // producer.createTopics(['t'], function (err: Error, data: Object) {}); // Omitting middle argument is not possible in TS

});

var highLevelProducer = new kafka.HighLevelProducer(basicClient);
highLevelProducer.on('error', function(error: Error){});
highLevelProducer.on('ready', function(){

    var messages = [{
        topic: 'topicName',
        messages: ['message body'],
        attributes: 2
    }, {
        topic: 'topicName',
        messages: ['message body'],
        partition: 0
    }, {
        topic: 'topicName',
        messages: ['message body'],
        attributes: 0
    }, {
        topic: 'topicName',
        messages: ['message body']
    }, {
        topic: 'topicName',
        messages: [new kafka.KeyedMessage('key', 'message')]
    }];

    producer.send(messages, function(err: Error){});
    producer.send(messages, function(err: Error, data: Object){});

    producer.createTopics(['t'], true, function (err: Error, data: Object) {});
    producer.createTopics(['t'], false, function (err, data) {});
    // producer.createTopics(['t'], function (err: Error, data: Object) {}); // Omitting middle argument is not possible in TS

});

var fetchRequests = [{ topic: 'awesome' }];
var consumer = new kafka.Consumer(basicClient, fetchRequests, {
    groupId: 'abcde',
    autoCommit: true
});
consumer.on('error', function(error: Error){});
consumer.on('message', function(message){});

consumer.addTopics(['t1', 't2'], function (err, added) {});
consumer.addTopics([{ topic: 't1', offset: 10 }], function (err, added) {}, true);

consumer.removeTopics(['t1', 't2'], function (err, removed) {});

consumer.commit(function (err, data) {});

consumer.setOffset('topic', 0, 0);

consumer.pause();
consumer.resume();
consumer.pauseTopics([
    'topic1',
    { topic: 'topic2', partition: 0 }
]);
consumer.resumeTopics([
    'topic1',
    { topic: 'topic2', partition: 0 }
]);

consumer.close(true, function () {});

var fetchRequests = [{ topic: 'awesome' }];
var hlConsumer = new kafka.HighLevelConsumer(basicClient, fetchRequests, {
    groupId: 'abcde',
    autoCommit: true
});

hlConsumer.on('error', function(error: Error){});
hlConsumer.on('message', function(message){});
hlConsumer.addTopics(['t1', 't2'], function (err, added) {});
hlConsumer.addTopics([{ topic: 't1', offset: 10 }], function (err, added) {}, true);

hlConsumer.removeTopics(['t1', 't2'], function (err, removed) {});

hlConsumer.commit(function (err, data) {});

hlConsumer.setOffset('topic', 0, 0);

hlConsumer.pause();
hlConsumer.resume();
hlConsumer.pauseTopics([
    'topic1',
    { topic: 'topic2', partition: 0 }
]);
hlConsumer.resumeTopics([
    'topic1',
    { topic: 'topic2', partition: 0 }
]);

hlConsumer.close(true, function () {});

var ackBatchOptions = {'noAckBatchSize': 1024, 'noAckBatchAge': 10};
var cgOptions: kafka.ConsumerGroupOptions = {
    host: 'localhost:2181/',
    batch: ackBatchOptions,
    groupId: 'groupID',
    id: 'consumerID',
    sessionTimeout: 15000,
    protocol: ["roundrobin"],
    fromOffset: "latest",
    migrateHLC: false,
    migrateRolling: true
};

var consumerGroup = new kafka.ConsumerGroup( cgOptions, ['topic1']);
consumerGroup.on('error', (err) => {});
consumerGroup.on('message', (msg) => {});
consumerGroup.close(true, () => {});

var offset = new kafka.Offset(basicClient);

offset.on('ready', function(){});

offset.fetch([
    { topic: 't', partition: 0, time: Date.now(), maxNum: 1 },
    { topic: 't' }
], function (err, data) { });

offset.commit('groupId', [
    { topic: 't', partition: 0, offset: 10 }
], function (err, data) { });

offset.fetchCommits('groupId', [
    { topic: 't', partition: 0 }
], function (err, data) {});

offset.fetchLatestOffsets(['t'], (err, offsets) => {})
offset.fetchEarliestOffsets(['t'], (err, offsets) => {})

sample-tests.ts

deleted100644 → 0
+0 −27
Changes for sample-tests.ts: 0 added lines, 27 removed lines.
Original line number Diff line number Diff line
/// <reference path="./index.d.ts" />
/// <reference path="../node/index.d.ts" />


/**
  [?] has correct naming convention

  checked compilation succeeds  
   [+] tsc --noImplicitAny --target es5 ./index.d.ts
   [x] tsc --noImplicitAny --target es6 ./index.d.ts

  [x] has a test file with the suffix of -tests.ts

  checked the test file
   [x] tsc --noImplicitAny --target es5 --module commonjs ./sample-tests.ts 
   [x] tsc --noImplicitAny --target es6 --module commonjs ./sample-tests.ts 

*/

import * as Sample from "sample";
import * as fs from "fs";
import * as stream from "stream";

function test_it() {

}
+5 −2
Changes for tsconfig.json: 5 added lines, 2 removed lines.
Original line number Diff line number Diff line
{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "lib": [
            "es6"
        ],
        "noImplicitAny": true,
        "noImplicitThis": true,
        "strictNullChecks": false,
        "baseUrl": "../",
        "typeRoots": [
@@ -14,6 +17,6 @@
    },
    "files": [
        "index.d.ts",
        "SAMPLE-tests.ts"
        "kafka-node-tests.ts"
    ]
}
 No newline at end of file