From c98ea9de9706cebe7573fb6383ef78ff300b11bd Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 28 Sep 2015 22:28:39 +0300 Subject: [PATCH] Added definitions for flake-idgen --- flake-idgen/flake-idgen-tests.ts | 27 +++++++++++++++++++++++++++ flake-idgen/flake-idgen.d.ts | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 flake-idgen/flake-idgen-tests.ts create mode 100644 flake-idgen/flake-idgen.d.ts diff --git a/flake-idgen/flake-idgen-tests.ts b/flake-idgen/flake-idgen-tests.ts new file mode 100644 index 00000000000000..5828bc91379981 --- /dev/null +++ b/flake-idgen/flake-idgen-tests.ts @@ -0,0 +1,27 @@ +/// + +// require flake-idgen +import FlakeId = require('flake-idgen'); +let flakeIdGen1 = new FlakeId({datacenter: 9, worker: 7}); + +// create flake IDs +console.log(flakeIdGen1.next()); +console.log(flakeIdGen1.next()); +console.log(flakeIdGen1.next()); + +// create flake IDs using a callback +flakeIdGen1.next((err, id) => { + console.info(id); +}); + +flakeIdGen1.next((err, id) => { + console.info(id); +}); + +let flakeIdGen2 = new FlakeId(); +let flakeIdGen3 = new FlakeId({datacenter: 9, worker: 7}); +let flakeIdGen4 = new FlakeId({epoch: 1300000000000}) +console.info(flakeIdGen2.next()); +console.info(flakeIdGen3.next()); +console.info(flakeIdGen4.next()); + diff --git a/flake-idgen/flake-idgen.d.ts b/flake-idgen/flake-idgen.d.ts new file mode 100644 index 00000000000000..9462eaba497eaf --- /dev/null +++ b/flake-idgen/flake-idgen.d.ts @@ -0,0 +1,22 @@ +// Type definitions for flakge-idgen 0.1.4 +// Project: https://github.com/T-PWK/flake-idgen +// Definitions by: Yuce Tekol +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module 'flake-idgen' { + interface ConstructorOptions { + datacenter?: number; + worker?: number; + id?: number; + epoch?: number; + seqMask?: number; + } + + class FlakeId { + constructor(options?: ConstructorOptions); + next(callback?: (err: Error, id: Buffer) => void): Buffer; + } + export = FlakeId; +}