mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
add zookeeper definition (#20588)
* add zookeeper definition * type defintion fixed * zookeeper
This commit is contained in:
Vendored
+104
@@ -0,0 +1,104 @@
|
||||
// Type definitions for zookeeper 3.4
|
||||
// Project: https://github.com/yfinkelstein/node-zookeeper#readme
|
||||
// Definitions by: xialeistudio <https://github.com/xialeistudio>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
/// <reference types="node" />
|
||||
|
||||
type ACL = number | { perms: number, scheme: string, auth: string };
|
||||
|
||||
interface Stat {
|
||||
czxid: number;
|
||||
mzxid: number;
|
||||
ctime: number;
|
||||
mtime: number;
|
||||
version: number;
|
||||
cversion: number;
|
||||
aversion: number;
|
||||
ephemeralOwner: string;
|
||||
dataLength: number;
|
||||
numChildren: number;
|
||||
pzxid: number;
|
||||
}
|
||||
|
||||
interface ConnectionOptions {
|
||||
connect?: string;
|
||||
timeout?: number;
|
||||
host_order_deterministic?: boolean;
|
||||
data_as_buffer?: boolean;
|
||||
debug_level?: number;
|
||||
}
|
||||
|
||||
type child2_callback = (rc: number, error: string, children: string[], stat: Stat) => void;
|
||||
type watch_callback = (type: number, state: number, path: string) => void;
|
||||
type acl_callback = (rc: number, error: string, acl: ACL[], stat: Stat) => void;
|
||||
|
||||
type Callback<T> = (rc: number, error: string, value: T) => void;
|
||||
export = Zookeeper;
|
||||
|
||||
declare class Zookeeper extends Client {
|
||||
constructor(options: ConnectionOptions);
|
||||
|
||||
connect(callback: (e: Error | null, client: Client) => void): void;
|
||||
|
||||
close(): void;
|
||||
}
|
||||
|
||||
declare class Client {
|
||||
client_id?: string;
|
||||
client_password?: any;
|
||||
state?: number;
|
||||
timeout?: number;
|
||||
is_unrecoverable?: boolean;
|
||||
|
||||
a_create(path: string, data: string | Buffer, flags: number, callback: Callback<string>): void;
|
||||
|
||||
mkdirp(path: string, callback: (e?: Error) => void): void;
|
||||
|
||||
a_exists(path: string, watch: boolean, callback: Callback<Stat>): void;
|
||||
|
||||
a_get(path: string, watch: boolean, callback: Callback<Buffer | string>): void;
|
||||
|
||||
a_get_children(path: string, watch: boolean, callback: Callback<string[]>): void;
|
||||
|
||||
a_get_children2(path: string, watch: boolean, callback: child2_callback): void;
|
||||
|
||||
a_set(path: string, data: Buffer | string, version: number, callback: Callback<Stat>): void;
|
||||
|
||||
a_delete_(path: string, version: number, callback: Callback<void>): void;
|
||||
|
||||
a_set_acl(path: string, version: number, acl: ACL[], callback: Callback<void>): void;
|
||||
|
||||
a_get_acl(path: string, callback: acl_callback): void;
|
||||
|
||||
add_auth(schema: string, auth: string, callback: Callback<void>): void;
|
||||
|
||||
aw_exists(path: string, watch_callback: watch_callback, callback: Callback<Stat>): void;
|
||||
|
||||
aw_get(path: string, watch_callback: watch_callback, callback: Callback<Buffer | string>): void;
|
||||
|
||||
aw_get_children(path: string, watch_callback: watch_callback, callback: Callback<string[]>): void;
|
||||
|
||||
aw_get_children2(path: string, watch_callback: watch_callback, callback: child2_callback): void;
|
||||
}
|
||||
|
||||
declare namespace Zookeeper {
|
||||
// log levels
|
||||
const ZOO_LOG_LEVEL_ERROR = 1;
|
||||
const ZOO_LOG_LEVEL_WARN = 2;
|
||||
const ZOO_LOG_LEVEL_INFO = 3;
|
||||
const ZOO_LOG_LEVEL_DEBUG = 4;
|
||||
// acl permissions
|
||||
const ZOO_OPEN_ACL_UNSAFE: number;
|
||||
const ZOO_READ_ACL_UNSAFE: number;
|
||||
const ZOO_CREATOR_ALL_ACL: number;
|
||||
const ZOO_PERM_READ = 1;
|
||||
const ZOO_PERM_WRITE = 2;
|
||||
const ZOO_PERM_CREATE = 4;
|
||||
const ZOO_PERM_DELETE = 8;
|
||||
const ZOO_PERM_ADMIN = 16;
|
||||
const ZOO_PERM_ALL = 31;
|
||||
// Dunno
|
||||
const ZOO_EPHEMERAL = 1;
|
||||
const ZOO_SEQUENCE = 2;
|
||||
}
|
||||
@@ -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",
|
||||
"zookeeper-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,24 @@
|
||||
import ZooKeeper = require('zookeeper');
|
||||
|
||||
const zk = new ZooKeeper({
|
||||
connect: "localhost:2181",
|
||||
timeout: 2000,
|
||||
debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARN,
|
||||
host_order_deterministic: false,
|
||||
data_as_buffer: true,
|
||||
});
|
||||
// test1
|
||||
zk.connect((e) => {
|
||||
if (e) throw e;
|
||||
console.log("zk session established, id=%s", zk.client_id);
|
||||
zk.a_create("/node.js1", "some value", ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_EPHEMERAL, (rc, error, path) => {
|
||||
if (rc !== 0) {
|
||||
console.log("zk node create result: %d, error: '%s', path=%s", rc, error, path);
|
||||
} else {
|
||||
console.log("created zk node %s", path);
|
||||
process.nextTick(() => {
|
||||
zk.close();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user