From 48c8449d4b9aa5fa6d550b8f4ca798b950c2f164 Mon Sep 17 00:00:00 2001 From: am Date: Wed, 9 Aug 2017 19:37:17 +0200 Subject: [PATCH] [adone] introduce typings (#18709) * [adone] introduce typings * [adone] refactor to module style * [adone] set strictNullChecks = true, fix utils test * [adone] rename tests file, change compileOptions.target * [adone] add interface namespaces * [adone] add some util typings, fixes * util.toposort * util.GlobExp options * util.ltgt * util.fakeClock * fix loadAsset return type * [adone] create namespaces for tests * [adone] create interface for util.fakeClock --- types/adone/adone-tests.ts | 3 + types/adone/adone.d.ts | 77 +++ types/adone/glosses/common.d.ts | 462 +++++++++++++++++ types/adone/glosses/math.d.ts | 115 ++++ types/adone/glosses/std.d.ts | 65 +++ types/adone/glosses/utils.d.ts | 462 +++++++++++++++++ types/adone/index.d.ts | 9 + types/adone/test/glosses/common.ts | 808 +++++++++++++++++++++++++++++ types/adone/test/glosses/math.ts | 259 +++++++++ types/adone/test/glosses/std.ts | 161 ++++++ types/adone/test/glosses/utils.ts | 736 ++++++++++++++++++++++++++ types/adone/test/index-import.ts | 6 + types/adone/test/index.ts | 69 +++ types/adone/tsconfig.json | 34 ++ types/adone/tslint.json | 8 + 15 files changed, 3274 insertions(+) create mode 100644 types/adone/adone-tests.ts create mode 100644 types/adone/adone.d.ts create mode 100644 types/adone/glosses/common.d.ts create mode 100644 types/adone/glosses/math.d.ts create mode 100644 types/adone/glosses/std.d.ts create mode 100644 types/adone/glosses/utils.d.ts create mode 100644 types/adone/index.d.ts create mode 100644 types/adone/test/glosses/common.ts create mode 100644 types/adone/test/glosses/math.ts create mode 100644 types/adone/test/glosses/std.ts create mode 100644 types/adone/test/glosses/utils.ts create mode 100644 types/adone/test/index-import.ts create mode 100644 types/adone/test/index.ts create mode 100644 types/adone/tsconfig.json create mode 100644 types/adone/tslint.json diff --git a/types/adone/adone-tests.ts b/types/adone/adone-tests.ts new file mode 100644 index 0000000000..861660ee89 --- /dev/null +++ b/types/adone/adone-tests.ts @@ -0,0 +1,3 @@ +// Actual tests inside ./test/ + +const a: string = adone.ok; diff --git a/types/adone/adone.d.ts b/types/adone/adone.d.ts new file mode 100644 index 0000000000..f968bfa342 --- /dev/null +++ b/types/adone/adone.d.ts @@ -0,0 +1,77 @@ +/// + +declare const _null: symbol; +export { _null as null }; +export function noop(): void; +export function identity(x: T): T; +export function truly(): true; +export function falsely(): false; +export const ok: "OK"; +export const bad: "BAD"; +export const exts: [".js", ".tjs", ".ajs"]; +export function log(...args: any[]): void; +export function fatal(...args: any[]): void; +export function error(...args: any[]): void; +export function warn(...args: any[]): void; +export function info(...args: any[]): void; +export function debug(...args: any[]): void; +export function trace(...args: any[]): void; +export function o(...props: any[]): object; +export const Date: typeof global.Date; +export const hrtime: typeof global.process.hrtime; +export const setTimeout: typeof global.setTimeout; +export const setInterval: typeof global.setInterval; +export const setImmediate: typeof global.setImmediate; +export const clearTimeout: typeof global.clearTimeout; +export const clearInterval: typeof global.clearInterval; +export const clearImmediate: typeof global.clearImmediate; +interface LazifyOptions { + configurable: boolean; +} +export function lazify(modules: object, obj?: object, require?: (path: string) => any, options?: LazifyOptions): object; +interface Tag { + set(Class: object, tag: string): void; + has(obj: object, tag: string): boolean; + define(tag: string, predicate?: string): void; + SUBSYSTEM: symbol; + APPLICATION: symbol; + TRANSFORM: symbol; + CORE_STREAM: symbol; + LOGGER: symbol; + LONG: symbol; + BIGNUMBER: symbol; + EXBUFFER: symbol; + EXDATE: symbol; + CONFIGURATION: symbol; + GENESIS_NETRON: symbol; + GENESIS_PEER: symbol; + NETRON: symbol; + NETRON_PEER: symbol; + NETRON_ADAPTER: symbol; + NETRON_DEFINITION: symbol; + NETRON_DEFINITIONS: symbol; + NETRON_REFERENCE: symbol; + NETRON_INTERFACE: symbol; + NETRON_STUB: symbol; + NETRON_REMOTESTUB: symbol; + NETRON_STREAM: symbol; + FAST_STREAM: symbol; + FAST_FS_STREAM: symbol; + FAST_FS_MAP_STREAM: symbol; +} +export const tag: Tag; +export function run(App: object, ignoreArgs?: boolean): Promise; +export function bind(libName: string): object; +export function getAssetAbsolutePath(relPath: string): string; +export function loadAsset(relPath: string): string | Buffer; +export function require(path: string): object; +export const package: object; + +import * as std from "./glosses/std"; +export { std }; + +export * from "./glosses/common"; +export * from "./glosses/math"; +export * from "./glosses/utils"; + +export as namespace adone; diff --git a/types/adone/glosses/common.d.ts b/types/adone/glosses/common.d.ts new file mode 100644 index 0000000000..f424598c02 --- /dev/null +++ b/types/adone/glosses/common.d.ts @@ -0,0 +1,462 @@ +export namespace is { + function _null(obj: any): boolean; + export { _null as null }; + export function undefined(obj: any): boolean; + export function exist(obj: any): boolean; + export function nil(obj: any): boolean; + export function number(obj: any): boolean; + export function numeral(obj: any): boolean; + export function infinite(obj: any): boolean; + export function odd(obj: any): boolean; + export function even(obj: any): boolean; + export function float(obj: any): boolean; + export function negativeZero(obj: any): boolean; + export function string(obj: any): boolean; + export function emptyString(obj: any): boolean; + export function substring(substring: string, string: string, offset?: number): boolean; + export function prefix(prefix: string, string: string): boolean; + export function suffix(suffix: string, string: string): boolean; + export function boolean(obj: any): boolean; + export function json(obj: any): boolean; + export function object(obj: any): boolean; + export function plainObject(obj: any): boolean; + function _class(obj: any): boolean; + export { _class as class }; + export function emptyObject(obj: any): boolean; + export function propertyOwned(obj: any, field: string): boolean; + export function propertyDefined(obj: any, field: string): boolean; + export function conforms(obj: object, schema: object, strict?: boolean): boolean; + export function arrayLikeObject(obj: any): boolean; + export function inArray(value: T, array: any[], offset?: number, comparator?: (a: T, b: T) => boolean): boolean; + export function sameType(value: any, other: any): boolean; + export function primitive(obj: any): boolean; + export function equalArrays(left: any[], right: any[]): boolean; + export function deepEqual(left: any, right: any): boolean; + export function shallowEqual(left: any, right: any): boolean; + export function stream(obj: any): boolean; + export function writableStream(obj: any): boolean; + export function readableStream(obj: any): boolean; + export function duplexStream(obj: any): boolean; + export function transformStream(obj: any): boolean; + export function utf8(obj: Buffer): boolean; + export function win32PathAbsolute(path: string): boolean; + export function posixPathAbsolute(path: string): boolean; + export function pathAbsolute(path: string): boolean; + export function glob(str: string): boolean; + export function dotfile(str: string): boolean; + function _function(obj: any): boolean; + export { _function as function }; + export function asyncFunction(obj: any): boolean; + export function promise(obj: any): boolean; + export function validDate(str: string): boolean; + export function buffer(obj: any): boolean; + export function callback(obj: any): boolean; + export function generator(obj: any): boolean; + export function nan(obj: any): boolean; + export function finite(obj: any): boolean; + export function integer(obj: any): boolean; + export function safeInteger(obj: any): boolean; + export function array(obj: any): boolean; + export function uint8Array(obj: any): boolean; + export function configuration(obj: any): boolean; + export function long(obj: any): boolean; + export function bigNumber(obj: any): boolean; + export function exbuffer(obj: any): boolean; + export function exdate(obj: any): boolean; + export function transform(obj: any): boolean; + export function subsystem(obj: any): boolean; + export function application(obj: any): boolean; + export function logger(obj: any): boolean; + export function coreStream(obj: any): boolean; + export function fastStream(obj: any): boolean; + export function fastFSStream(obj: any): boolean; + export function fastFSMapStream(obj: any): boolean; + export function genesisNetron(obj: any): boolean; + export function genesisPeer(obj: any): boolean; + export function netronAdapter(obj: any): boolean; + export function netron(obj: any): boolean; + export function netronPeer(obj: any): boolean; + export function netronDefinition(obj: any): boolean; + export function netronDefinitions(obj: any): boolean; + export function netronReference(obj: any): boolean; + export function netronInterface(obj: any): boolean; + export function netronContext(obj: any): boolean; + export function netronIMethod(netronInterface: object, name: string): boolean; + export function netronIProperty(netronInterface: any, name: string): boolean; + export function netronStub(obj: any): boolean; + export function netronRemoteStub(obj: any): boolean; + export function netronStream(obj: any): boolean; + export function iterable(obj: any): boolean; + export const windows: boolean; + export const linux: boolean; + export const freebsd: boolean; + export const darwin: boolean; + export const sunos: boolean; + export function uppercase(str: string): boolean; + export function lowercase(str: string): boolean; + export function digits(str: string): boolean; + export function identifier(str: string): boolean; + export function binaryExtension(str: string): boolean; + export function binaryPath(str: string): boolean; + export function ip4(str: string): boolean; + export function ip6(str: string): boolean; + export function arrayBuffer(obj: any): boolean; + export function arrayBufferView(obj: any): boolean; + export function date(obj: any): boolean; + export function error(obj: any): boolean; + export function map(obj: any): boolean; + export function regexp(obj: any): boolean; + export function set(obj: any): boolean; + export function symbol(obj: any): boolean; + export function validUTF8(obj: any): boolean; +} + +export namespace x { + class Exception extends Error { + constructor(message?: string | Error, captureStackTrace?: boolean); + } + class Runtime extends Exception { } + class IncompleteBufferError extends Exception { } + class NotImplemented extends Exception { } + class IllegalState extends Exception { } + class NotValid extends Exception { } + class Unknown extends Exception { } + class NotExists extends Exception { } + class Exists extends Exception { } + class Empty extends Exception { } + class InvalidAccess extends Exception { } + class NotSupported extends Exception { } + class InvalidArgument extends Exception { } + class InvalidNumberOfArguments extends Exception { } + class NotFound extends Exception { } + class Timeout extends Exception { } + class Incorrect extends Exception { } + class NotAllowed extends Exception { } + class LimitExceeded extends Exception { } + class Encoding extends Exception { } + class Network extends Exception { } + class Bind extends Exception { } + class Connect extends Exception { } + class Database extends Exception { } + class DatabaseInitialization extends Exception { } + class DatabaseOpen extends Exception { } + class DatabaseRead extends Exception { } + class DatabaseWrite extends Exception { } + class NetronIllegalState extends Exception { } + class NetronPeerDisconnected extends Exception { } + class NetronTimeout extends Exception { } +} + +export class EventEmitter { + static listenerCount(emitter: EventEmitter, event: string | symbol): number; + static defaultMaxListeners: number; + + addListener(event: string | symbol, listener: (...args: any[]) => void): this; + on(event: string | symbol, listener: (...args: any[]) => void): this; + once(event: string | symbol, listener: (...args: any[]) => void): this; + prependListener(event: string | symbol, listener: (...args: any[]) => void): this; + prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; + removeListener(event: string | symbol, listener: (...args: any[]) => void): this; + removeAllListeners(event?: string | symbol): this; + setMaxListeners(n: number): this; + getMaxListeners(): number; + listeners(event: string | symbol): Array<(...args: any[]) => any>; + emit(event: string | symbol, ...args: any[]): boolean; + eventNames(): Array; + listenerCount(type: string | symbol): number; +} + +export class AsyncEmitter extends EventEmitter { + constructor(concurrency?: number); + + setConcurrency(max?: number): this; + + emitParallel(event: string, ...args: any[]): Promise; + + emitSerial(event: string, ...args: any[]): Promise; + + emitReduce(event: string, ...args: any[]): Promise; + + emitReduceRight(event: string, ...args: any[]): Promise; + + subscribe(event: string, listener: (...args: any[]) => void, once?: boolean): () => void; +} + +declare namespace I { + type Long = adone.math.Long; + + type Longable = adone.math.I.Longable; + + namespace ExBuffer { + interface Varint32 { + value: number; + length: number; + } + + interface Varint64 { + value: Long; + length: number; + } + + interface String { + string: string; + length: number; + } + + type Wrappable = string | ExBuffer | Buffer | Uint8Array | ArrayBuffer; + + type METRICS = "b" | "c"; + } +} + +export class ExBuffer { + constructor(capacity?: number, noAssert?: boolean); + + readBitSet(offset?: number): number[]; + + read(length: number, offset?: number): ExBuffer; + + readInt8(offset?: number): number; + + readUInt8(offset?: number): number; + + readInt16LE(offset?: number): number; + + readUInt16LE(offset?: number): number; + + readInt16BE(offset?: number): number; + + readUInt16BE(offset?: number): number; + + readInt32LE(offset?: number): number; + + readUInt32LE(offset?: number): number; + + readInt32BE(offset?: number): number; + + readUInt32BE(offset?: number): number; + + readInt64LE(offset?: number): adone.math.Long; + + readUInt64LE(offset?: number): adone.math.Long; + + readInt64BE(offset?: number): adone.math.Long; + + readUInt64BE(offset?: number): adone.math.Long; + + readFloatLE(offset?: number): number; + + readFloatBE(offset?: number): number; + + readDoubleLE(offset?: number): number; + + readDoubleBE(offset?: number): number; + + write(source: I.ExBuffer.Wrappable, offset?: number, length?: number, encoding?: string): this; + + writeBitSet(value: number[]): this; + + writeBitSet(value: number[], offset: number): number; + + writeInt8(value: number, offset?: number): this; + + writeUInt8(value: number, offset?: number): this; + + writeInt16LE(value: number, offset?: number): this; + + writeInt16BE(value: number, offset?: number): this; + + writeUInt16LE(value: number, offset?: number): this; + + writeUInt16BE(value: number, offset?: number): this; + + writeInt32LE(value: number, offset?: number): this; + + writeInt32BE(value: number, offset?: number): this; + + writeUInt32LE(value: number, offset?: number): this; + + writeUInt32BE(value: number, offset?: number): this; + + writeInt64LE(value: I.Longable, offset?: number): this; + + writeInt64BE(value: I.Longable, offset?: number): this; + + writeUInt64LE(value: I.Longable, offset?: number): this; + + writeUInt64BE(value: I.Longable, offset?: number): this; + + writeFloatLE(value: number, offset?: number): this; + + writeFloatBE(value: number, offset?: number): this; + + writeDoubleLE(value: number, offset?: number): this; + + writeDoubleBE(value: number, offset?: number): this; + + writeVarint32(value: number): this; + + writeVarint32(value: number, offset: number): number; + + writeVarint32ZigZag(value: number): this; + + writeVarint32ZigZag(value: number, offset: number): number; + + readVarint32(): number; + + readVarint32(offset: number): I.ExBuffer.Varint32; + + readVarint32ZigZag(): number; + + readVarint32ZigZag(offset: number): I.ExBuffer.Varint32; + + writeVarint64(value: I.Longable): this; + + writeVarint64(value: I.Longable, offset: number): number; + + writeVarint64ZigZag(value: I.Longable): this; + + writeVarint64ZigZag(value: I.Longable, offset: number): number; + + readVarint64(): I.Long; + + readVarint64(offset: number): I.ExBuffer.Varint64; + + readVarint64ZigZag(): adone.math.Long; + + readVarint64ZigZag(offset: number): I.ExBuffer.Varint64; + + writeCString(str: string): this; + + writeCString(str: string, offset: number): number; + + readCString(): string; + + readCString(offset: number): I.ExBuffer.String; + + writeString(str: string): this; + + writeString(str: string, offset: number): number; + + readString(length: number, metrics?: I.ExBuffer.METRICS): string; + + readString(length: number, metrics: I.ExBuffer.METRICS, offset: number): I.ExBuffer.String; + + readString(length: number, offset: number): I.ExBuffer.String; + + writeVString(str: string): this; + + writeVString(str: string, offset: number): number; + + readVString(): string; + + readVString(offset: number): I.ExBuffer.String; + + appendTo(target: ExBuffer, offset?: number): this; + + assert(assert?: boolean): this; + + capacity(): number; + + clear(): this; + + compact(begin?: number, end?: number): this; + + copy(begin?: number, end?: number): ExBuffer; + + copyTo(target: ExBuffer, targetOffset?: number, souceOffset?: number, sourceLimit?: number): this | ExBuffer; + + ensureCapacity(capacity: number): this; + + fill(value: string | number, begin?: number, end?: number): this; + + flip(): this; + + mark(offset?: number): this; + + prepend(source: I.ExBuffer.Wrappable, encoding?: string, offset?: number): this; + + prepend(source: I.ExBuffer.Wrappable, offset: number): this; + + prependTo(target: ExBuffer, offset?: number): this; + + remaining(): number; + + reset(): this; + + resize(capacity: number): this; + + reverse(begin?: number, end?: number): this; + + skip(length: number): this; + + slice(begin?: number, end?: number): ExBuffer; + + toBuffer(forceCopy?: boolean, begin?: number, end?: number): Buffer; + + toArrayBuffer(): ArrayBuffer; + + toString(encoding?: string, begin?: number, end?: number): string; + + toBase64(begin?: number, end?: number): string; + + toBinary(begin?: number, end?: number): string; + + toDebug(columns?: boolean): string; + + toHex(begin?: number, end?: number): string; + + toUTF8(begin?: number, end?: number): string; + + static accessor(): typeof Buffer; + + static allocate(capacity?: number, noAssert?: boolean): ExBuffer; + + static concat(buffers: I.ExBuffer.Wrappable[], encoding?: string, noAssert?: boolean): ExBuffer; + + static type(): typeof Buffer; + + static wrap(buffer: I.ExBuffer.Wrappable, encoding?: string, noAssert?: boolean): ExBuffer; + + static calculateVarint32(value: number): number; + + static zigZagEncode32(n: number): number; + + static zigZagDecode32(n: number): number; + + static calculateVarint64(value: number | string): number; + + static zigZagEncode64(value: number | string | I.Long): I.Long; + + static zigZagDecode64(value: number | string | I.Long): I.Long; + + static calculateUTF8Chars(str: string): number; + + static calculateString(str: string): number; + + static fromBase64(str: string): ExBuffer; + + static btoa(str: string): string; + + static atob(b64: string): string; + + static fromBinary(str: string): ExBuffer; + + static fromDebug(str: string, noAssert?: boolean): ExBuffer; + + static fromHex(str: string, noAssert?: boolean): ExBuffer; + + static fromUTF8(str: string, noAssert?: boolean): ExBuffer; + + static DEFAULT_CAPACITY: number; + + static DEFAULT_NOASSERT: boolean; + + static MAX_VARINT32_BYTES: number; + + static MAX_VARINT64_BYTES: number; + + static METRICS_CHARS: string; + + static METRICS_BYTES: string; +} diff --git a/types/adone/glosses/math.d.ts b/types/adone/glosses/math.d.ts new file mode 100644 index 0000000000..d16b2a8c04 --- /dev/null +++ b/types/adone/glosses/math.d.ts @@ -0,0 +1,115 @@ +export namespace math { + namespace I { + interface LowHighBits { + low: number; + high: number; + } + type Longable = math.Long | number | string | LowHighBits; + } + + export class Long { + constructor(low?: number, high?: number, unsigned?: boolean); + + toInt(): number; + + toNumber(): number; + + toString(radix?: number): string; + + getHighBits(): number; + + getHighBitsUnsigned(): number; + + getLowBits(): number; + + getLowBitsUnsigned(): number; + + getNumBitsAbs(): number; + + isZero(): boolean; + + isNegative(): boolean; + + isPositive(): boolean; + + isOdd(): boolean; + + isEven(): boolean; + + equals(other: I.Longable): boolean; + + lessThan(other: I.Longable): boolean; + + lessThanOrEqual(other: I.Longable): boolean; + + greaterThan(other: I.Longable): boolean; + + greaterThanOrEqual(other: I.Longable): boolean; + + compare(other: I.Longable): number; + + negate(): Long; + + add(addend: I.Longable): Long; + + sub(subtrahend: I.Longable): Long; + + mul(multiplier: I.Longable): Long; + + div(divisor: I.Longable): Long; + + mod(divisor: I.Longable): Long; + + not(): Long; + + and(other: I.Longable): Long; + + or(other: I.Longable): Long; + + xor(other: I.Longable): Long; + + shl(numBits: number | Long): Long; + + shr(numBits: number | Long): Long; + + shru(numBits: number | Long): Long; + + toSigned(): Long; + + toUnsigned(): Long; + + toBytes(le?: boolean): number[]; + + toBytesLE(): number[]; + + toBytesBE(): number[]; + + static fromInt(value: number, unsigned?: boolean): Long; + + static fromNumber(value?: number, unsigned?: boolean): Long; + + static fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long; + + static fromString(str: string, unsigned?: boolean, radix?: number): Long; + + static fromString(str: string, radix?: number): Long; + + static fromValue(val: I.Longable): Long; + + static MIN_VALUE: Long; + + static MAX_VALUE: Long; + + static MAX_UNSIGNED_VALUE: Long; + + static ZERO: Long; + + static UZERO: Long; + + static ONE: Long; + + static UONE: Long; + + static NEG_ONE: Long; + } +} diff --git a/types/adone/glosses/std.d.ts b/types/adone/glosses/std.d.ts new file mode 100644 index 0000000000..9c30b41f62 --- /dev/null +++ b/types/adone/glosses/std.d.ts @@ -0,0 +1,65 @@ +import * as assert from "assert"; +import * as fs from "fs"; +import * as path from "path"; +import * as util from "util"; +import * as events from "events"; +import * as stream from "stream"; +import * as url from "url"; +import * as net from "net"; +import * as http from "http"; +import * as https from "https"; +import * as child_process from "child_process"; +import * as os from "os"; +import * as cluster from "cluster"; +import * as repl from "repl"; +import * as punycode from "punycode"; +import * as readline from "readline"; +import * as string_decoder from "string_decoder"; +import * as querystring from "querystring"; +import * as crypto from "crypto"; +import * as vm from "vm"; +import * as v8 from "v8"; +import * as domain from "domain"; +import * as tty from "tty"; +import * as buffer from "buffer"; +import * as constants from "constants"; +import * as zlib from "zlib"; +import * as tls from "tls"; +import * as console from "console"; +import * as dns from "dns"; +import * as timers from "timers"; +import * as dgram from "dgram"; + +export { + assert, + fs, + path, + util, + events, + stream, + url, + net, + http, + https, + child_process, + os, + cluster, + repl, + punycode, + readline, + string_decoder, + querystring, + crypto, + vm, + v8, + domain, + tty, + buffer, + constants, + zlib, + tls, + console, + dns, + timers, + dgram, +}; diff --git a/types/adone/glosses/utils.d.ts b/types/adone/glosses/utils.d.ts new file mode 100644 index 0000000000..629b9a08bd --- /dev/null +++ b/types/adone/glosses/utils.d.ts @@ -0,0 +1,462 @@ +export namespace util { + function arrify(val: T[]): T[]; + function arrify(val: T): [T]; + + function slice(args: T[], sliceStart?: number, sliceEnd?: number): T[]; + + function spliceOne(list: any[], index: number): void; + + function normalizePath(str: string, stripTrailing?: boolean): string; + + function unixifyPath(filePath: string, unescape?: boolean): string; + + function functionName(fn: (...args: any[]) => any): string; + + function mapArguments(argmap: (...args: any[]) => any | any[]): (...args: any[]) => any; + function mapArguments(argmap: number): (...args: T[]) => T[]; + function mapArguments(...args: any[]): (x: T) => T; + + namespace I { + interface ParseMsResult { + days: number; + hours: number; + minutes: number; + seconds: number; + milliseconds: number; + } + } + function parseMs(ms: number): I.ParseMsResult; + + function pluralizeWord(str: string, plural?: string, count?: number): string; + + function functionParams(func: (...args: any[]) => any): string[]; + + function randomChoice(arrayLike: ArrayLike, from?: number, to?: number): T; + + function shuffleArray(array: T[]): T[]; + + function enumerate(iterable: Iterable, start?: number): IterableIterator<[number, T]>; + + function zip(a: Iterable, b: Iterable): IterableIterator<[T1, T2]>; + function zip(a: Iterable, b: Iterable, c: Iterable): IterableIterator<[T1, T2, T3]>; + function zip(a: Iterable, b: Iterable, c: Iterable, d: Iterable): IterableIterator<[T1, T2, T3, T4]>; + function zip(...iterables: Array>): IterableIterator; + + namespace I { + interface KeysOptions { + onlyEnumerable?: boolean; + followProto?: boolean; + all?: boolean; + } + } + function keys(object: object, options?: I.KeysOptions): string[]; + + function values(object: object, options?: I.KeysOptions): any[]; + + function entries(object: object, options?: I.KeysOptions): Array; + + function toDotNotation(object: object): object; + + namespace I { + interface FlattenOptions { + depth?: number; + } + } + function flatten(array: any[], options?: I.FlattenOptions): any[]; + + function globParent(str: string): string; + + namespace I { + interface ByResult { + (a: S, b: S): R; + compare(a: T, b: T): R; + by(a: S): T; + } + } + function by(by: (a: S) => T, compare?: (a: T, b: T) => R): I.ByResult; + + function toFastProperties(object: object): object; + + function stripBom(x: string): string; + + namespace I { + interface SortKeysOptions { + deep?: boolean; + compare?(a: any, b: any): number; + } + } + function sortKeys(object: object, options?: I.SortKeysOptions): object; + + namespace I { + interface GlobizeOptions { + exts?: string; + recursively?: boolean; + } + } + function globize(path: string, options?: I.GlobizeOptions): string; + + function unique(array: T[], projection?: (a: T) => any): T[]; + + function invertObject(source: object, options?: I.KeysOptions): object; + + namespace I { + interface HumanizeTimeOptions { + msDecimalDigits?: number; + secDecimalDigits?: number; + verbose?: boolean; + compact?: boolean; + } + } + function humanizeTime(ms: number, options?: I.HumanizeTimeOptions): string; + function humanizeSize(num: number, space?: string): string; + + function parseSize(str: string | number): number | null; + + namespace I { + interface CloneOptions { + deep?: boolean; + } + } + function clone(object: object, options?: I.CloneOptions): object; + + function toUTF8Array(str: string): number[]; + + function asyncIter(array: T[], iter: (elem: T, index: number, cb: () => void) => any, cb: () => void): void; + + function asyncFor(obj: { [key: string]: T }, iter: (key: string, value: T, index: number, length: number, next: () => void) => void, cb: () => void): void; + + namespace I { + interface OnceOptions { + silent: boolean; + } + } + function once(fn: (...args: any[]) => T, options?: I.OnceOptions): (...args: any[]) => T; + + namespace I { + type WaterFallTask = (...args: any[]) => void; + } + function asyncWaterfall(tasks: I.WaterFallTask[], callback?: (err?: Error | null, ...args: any[]) => void): void; + + function xrange(start?: number, stop?: number, step?: number): IterableIterator; + + function range(start?: number, stop?: number, step?: number): number[]; + + function reFindAll(regexp: RegExp, str: string): RegExpExecArray[]; + + function assignDeep(target: T, ...sources: object[]): T; + + namespace I { + interface MatchOptions { + index?: boolean; + start?: number; + end?: number; + dot?: boolean; + } + } + function match(criteria: any | any[], options?: I.MatchOptions): (value: any | any[], options?: I.MatchOptions) => number | boolean; + function match(criteria: any | any[], value: any | any[], options?: I.MatchOptions): number | boolean; + + namespace I { + interface ToposortFunction { + (edges: Array<[T, T]>): T[]; + array(nodes: T[], edges: Array<[T, T]>): T[]; + } + } + const toposort: I.ToposortFunction; + + namespace I { + interface JSEscOptions { + escapeEverything?: boolean; + minimal?: boolean; + isScriptContext?: boolean; + quotes?: string; + wrap?: boolean; + es6?: boolean; + json?: boolean; + compact?: boolean; + lowercaseHex?: boolean; + numbers?: string; + indent?: string; + indentLevel?: number; + __inline1__?: boolean; + __inline2__?: boolean; + } + } + function jsesc(argument: any, options?: I.JSEscOptions): string; + + function typeOf(obj: any): string; + + namespace memcpy { + function utou(target: Buffer, targetOffset: number, source: Buffer, sourceStart: number, sourceEnd: number): number; + function atoa(target: ArrayBuffer, targetOffset: number, source: ArrayBuffer, sourceStart: number, sourceEnd: number): number; + function atou(target: Buffer, targetOffset: number, source: ArrayBuffer, sourceStart: number, sourceEnd: number): number; + function utoa(target: ArrayBuffer, targetOffset: number, source: Buffer, sourceStart: number, sourceEnd: number): number; + function copy(target: Buffer | ArrayBuffer, targetOffset: number, source: Buffer | ArrayBuffer, sourceStart: number, sourceEnd: number): number; + } + + namespace uuid { + namespace I { + interface V1Options { + clockseq?: number; + msecs?: number; + nsecs?: number; + } + } + function v1(options?: I.V1Options): string; + function v1(options: I.V1Options, buf: any[], offset?: number): number[]; + + function v4(options?: any): string; + function v4(options: any, buf: any[], offset?: number): number[]; + + function v5(name: string | number[], namespace: string | number[]): string; + function v5(name: string | number[], namespace: string | number[], buf: any[], offset?: number): number[]; + } + + namespace I { + interface Delegator { + method(name: string): Delegator; + access(name: string): Delegator; + getter(name: string): Delegator; + setter(name: string): Delegator; + } + } + function delegate(object: object, property: string): I.Delegator; + + namespace I { + interface GlobExpOptions { + nocomment?: boolean; + nonegate?: boolean; + nobrace?: boolean; + noglobstar?: boolean; + nocase?: boolean; + dot?: boolean; + noext?: boolean; + matchBase?: boolean; + flipNegate?: boolean; + } + } + + class GlobExp { + constructor(pattern: string, options?: I.GlobExpOptions); + + hasMagic(): boolean; + + static hasMagic(pattern: string, options?: I.GlobExpOptions): boolean; + + expandBraces(): string[]; + + static expandBraces(pattern: string, options?: I.GlobExpOptions): string[]; + + makeRe(): RegExp; + + static makeRe(pattern: string, options?: I.GlobExpOptions): RegExp; + + static test(p: string, pattern: string, options?: I.GlobExpOptions): boolean; + + test(p: string): boolean; + } + + namespace iconv { + // TODO: need to normalize source code + } + + namespace sqlstring { + function escapeId(val: string | string[], forbidQualified?: boolean): string; + function dateToString(date: any, timeZone?: string): string; + function arrayToList(array: any[]): string; + function bufferToString(buffer: Buffer): string; + function objectToValues(object: object, timeZone?: string): string; + function escape(value: any, stringifyObjects?: boolean, timeZone?: string): string; + function format(sql: string, values?: any | any[], stringifyObjects?: boolean, timeZone?: string): string; + } + + namespace I { + interface EditorOptions { + text?: string; + editor?: string; + path?: string; + ext?: string; + } + } + class Editor { + static DEFAULT: string; + + constructor(options?: I.EditorOptions); + + spawn(): Promise; + + run(): Promise; + + cleanup(): Promise; + + static edit(options?: I.EditorOptions): Promise; + } + + namespace I { + interface BinarySearchFunction { + (aHaystack: T[], aNeedle: number, aLow?: number, aHigh?: number, aCompare?: (a: T, b: T) => number, aBias?: number): T; + GREATEST_LOWER_BOUND: number; + LEAST_UPPER_BOUND: number; + } + } + const binarySearch: I.BinarySearchFunction; + + namespace buffer { + function concat(list: Buffer[], totalLength: number): Buffer; + function mask(buffer: Buffer, mask: Buffer, output: Buffer, offset: number, length: number): void; + function unmask(buffer: Buffer, mask: Buffer): void; + } + + function shebang(str: string): string | null; + + class ReInterval { + constructor(callback: (...args: any[]) => void, interval: number, args?: any[]); + + reschedule(interval: number): void; + + clear(): void; + + destroy(): void; + } + + class RateLimiter { + constructor(tokensPerInterval?: number, interval?: number, fireImmediately?: boolean); + + removeTokens(count: number): Promise; + + tryRemoveTokens(count: number): boolean; + + getTokensRemaining(): number; + } + + namespace I { + interface ThrottleOptions { + max?: number; + interval?: number; + ordered?: boolean; + waitForReturn?: boolean; + } + } + function throttle(fn: () => R, options?: I.ThrottleOptions): () => Promise; + function throttle(fn: (a: T1) => R, options?: I.ThrottleOptions): (a: T1) => Promise; + function throttle(fn: (a: T1, b: T2) => R, options?: I.ThrottleOptions): (a: T1, b: T2) => Promise; + function throttle(fn: (a: T1, b: T2, c: T3) => R, options?: I.ThrottleOptions): (a: T1, b: T2, c: T3) => Promise; + function throttle(fn: (a: T1, b: T2, c: T3, d: T4) => R, options?: I.ThrottleOptions): (a: T1, b: T2, c: T3, d: T4) => Promise; + function throttle(fn: (a: T1, b: T2, c: T3, d: T4, e: T5) => R, options?: I.ThrottleOptions): (a: T1, b: T2, c: T3, d: T4, e: T5) => Promise; + function throttle(fn: (...args: any[]) => R, options?: I.ThrottleOptions): (...args: any[]) => Promise; + + namespace I.fakeClock { + interface Timer { + id: number; + ref(): void; + unref(): void; + } + interface Clock { + setTimeout(func: (...args: any[]) => void, timeout: number, ...args: any[]): Timer; + clearTimeout(timer: Timer): void; + nextTick(func: (...args: any[]) => void, ...args: any[]): void; + setInterval(func: (...args: any[]) => void, ...args: any[]): Timer; + clearInterval(timer: Timer): void; + setImmediate(func: (...args: any[]) => void, ...args: any[]): Timer; + clearImmediate(timer: Timer): void; + updateHrTime(newNow: number): void; + tick(ms: number): number; + next(): number; + runAll(): number; + runToLast(): number; + setSystemTime(systemTime: number): void; + hrtime(prev?: [number, number]): [number, number]; + } + interface InstalledClock extends Clock { + uninstall(): void; + } + interface InstallOptions { + target?: object; + now?: number; + toFake?: string[]; + loopLimit?: number; + shouldAdvanceTime?: boolean; + advanceTimeDelta?: number; + } + + interface Timers { + setTimeout: typeof global.setTimeout; + clearTimeout: typeof global.clearTimeout; + setInterval: typeof global.setInterval; + clearInterval: typeof global.clearInterval; + setImmediate: typeof global.setImmediate; + clearImmediate: typeof global.clearImmediate; + Date: typeof global.Date; + hrtime: typeof global.process.hrtime; + nextTick: typeof global.process.nextTick; + } + + interface FakeClock { + timers: Timers; + createClock(now?: number, loopLimit?: number): Clock; + install(now: number | Date | InstallOptions): InstalledClock; + } + } + + const fakeClock: I.fakeClock.FakeClock; + + namespace ltgt { + namespace I { + interface Range { + lt?: T; + lte?: T; + gt?: T; + gte?: T; + min?: T; + max?: T; + start?: T; + end?: T; + reverse?: boolean; + } + type Comparator = (a: T, b: T) => number; + } + function contains(range: I.Range, key: T, compare?: I.Comparator): boolean; + + function filter(range: I.Range, compare?: I.Comparator): (key: T) => boolean; + + function toLtgt( + range: I.Range, + _range: object, + map?: (value: T, isUpperBound: boolean) => R, + lowerBound?: T, + upperBound?: T + ): I.Range; + + function endInclusive(range: I.Range): boolean; + + function startInclusive(range: I.Range): boolean; + + function end(range: I.Range): T | undefined; + + function end(range: I.Range, defaultValue: R): T | R; + + function start(range: I.Range): T | undefined; + + function start(range: I.Range, defaultValue?: R): T | R; + + function upperBound(range: I.Range): T | undefined; + + function upperBound(range: I.Range, defaultValue: R): T | R; + + function upperBoundKey(range: I.Range): T | undefined; + + function upperBoundExclusive(range: I.Range): boolean; + + function lowerBoundExclusive(range: I.Range): boolean; + + function upperBoundInclusive(range: I.Range): boolean; + + function lowerBoundInclusive(range: I.Range): boolean; + + function lowerBound(range: I.Range): T | undefined; + + function lowerBound(range: I.Range, defaultValue: R): T | R; + + function lowerBoundKey(range: I.Range): T | undefined; + } +} diff --git a/types/adone/index.d.ts b/types/adone/index.d.ts new file mode 100644 index 0000000000..663e8c8407 --- /dev/null +++ b/types/adone/index.d.ts @@ -0,0 +1,9 @@ +// Type definitions for adone 0.6 +// Project: https://github.com/ciferox/adone +// Definitions by: am , Maximus +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +import * as adone from "./adone"; + +export default adone; diff --git a/types/adone/test/glosses/common.ts b/types/adone/test/glosses/common.ts new file mode 100644 index 0000000000..c66f6a5410 --- /dev/null +++ b/types/adone/test/glosses/common.ts @@ -0,0 +1,808 @@ +namespace commonTests { + namespace is { + { const a: boolean = adone.is.null({}); } + { const a: boolean = adone.is.undefined({}); } + { const a: boolean = adone.is.exist({}); } + { const a: boolean = adone.is.nil({}); } + { const a: boolean = adone.is.number({}); } + { const a: boolean = adone.is.numeral({}); } + { const a: boolean = adone.is.infinite({}); } + { const a: boolean = adone.is.odd({}); } + { const a: boolean = adone.is.even({}); } + { const a: boolean = adone.is.float({}); } + { const a: boolean = adone.is.negativeZero({}); } + { const a: boolean = adone.is.string({}); } + { const a: boolean = adone.is.emptyString({}); } + { const a: boolean = adone.is.substring("abc", "abcdef"); } + { const a: boolean = adone.is.substring("abc", "abcdef", 0); } + { const a: boolean = adone.is.prefix("abc", "abcdef"); } + { const a: boolean = adone.is.suffix("def", "abbdef"); } + { const a: boolean = adone.is.boolean({}); } + { const a: boolean = adone.is.json({}); } + { const a: boolean = adone.is.object({}); } + { const a: boolean = adone.is.plainObject({}); } + { const a: boolean = adone.is.class({}); } + { const a: boolean = adone.is.emptyObject({}); } + { const a: boolean = adone.is.propertyOwned({}, "a"); } + { const a: boolean = adone.is.propertyDefined({}, "a"); } + { const a: boolean = adone.is.conforms({}, {}); } + { const a: boolean = adone.is.conforms({}, {}, true); } + { const a: boolean = adone.is.arrayLikeObject({}); } + { const a: boolean = adone.is.inArray(1, [1, 2, 3]); } + { const a: boolean = adone.is.inArray(1, [1, 2, 3], 0); } + { const a: boolean = adone.is.inArray(1, [1, 2, 3], 0, (a, b) => a === b); } + { const a: boolean = adone.is.sameType({}, {}); } + { const a: boolean = adone.is.primitive({}); } + { const a: boolean = adone.is.equalArrays([], []); } + { const a: boolean = adone.is.deepEqual({}, {}); } + { const a: boolean = adone.is.shallowEqual({}, {}); } + { const a: boolean = adone.is.stream({}); } + { const a: boolean = adone.is.writableStream({}); } + { const a: boolean = adone.is.readableStream({}); } + { const a: boolean = adone.is.duplexStream({}); } + { const a: boolean = adone.is.transformStream({}); } + { const a: boolean = adone.is.utf8(Buffer.alloc(10)); } + { const a: boolean = adone.is.win32PathAbsolute("abc"); } + { const a: boolean = adone.is.posixPathAbsolute("abc"); } + { const a: boolean = adone.is.pathAbsolute("abc"); } + { const a: boolean = adone.is.glob("abc"); } + { const a: boolean = adone.is.dotfile("abc"); } + { const a: boolean = adone.is.function(() => { }); } + { const a: boolean = adone.is.asyncFunction(async () => { }); } + { const a: boolean = adone.is.promise({}); } + { const a: boolean = adone.is.validDate("07.08.2017"); } + { const a: boolean = adone.is.buffer({}); } + { const a: boolean = adone.is.callback({}); } + { const a: boolean = adone.is.generator({}); } + { const a: boolean = adone.is.nan({}); } + { const a: boolean = adone.is.finite({}); } + { const a: boolean = adone.is.integer({}); } + { const a: boolean = adone.is.safeInteger({}); } + { const a: boolean = adone.is.array({}); } + { const a: boolean = adone.is.uint8Array({}); } + { const a: boolean = adone.is.configuration({}); } + { const a: boolean = adone.is.long({}); } + { const a: boolean = adone.is.bigNumber({}); } + { const a: boolean = adone.is.exbuffer({}); } + { const a: boolean = adone.is.exdate({}); } + { const a: boolean = adone.is.transform({}); } + { const a: boolean = adone.is.subsystem({}); } + { const a: boolean = adone.is.application({}); } + { const a: boolean = adone.is.logger({}); } + { const a: boolean = adone.is.coreStream({}); } + { const a: boolean = adone.is.fastStream({}); } + { const a: boolean = adone.is.fastFSStream({}); } + { const a: boolean = adone.is.fastFSMapStream({}); } + { const a: boolean = adone.is.genesisNetron({}); } + { const a: boolean = adone.is.genesisPeer({}); } + { const a: boolean = adone.is.netronAdapter({}); } + { const a: boolean = adone.is.netron({}); } + { const a: boolean = adone.is.netronPeer({}); } + { const a: boolean = adone.is.netronDefinition({}); } + { const a: boolean = adone.is.netronDefinitions({}); } + { const a: boolean = adone.is.netronReference({}); } + { const a: boolean = adone.is.netronInterface({}); } + { const a: boolean = adone.is.netronContext({}); } + { const a: boolean = adone.is.netronIMethod({}, "hello"); } + { const a: boolean = adone.is.netronIProperty({}, "hello"); } + { const a: boolean = adone.is.netronStub({}); } + { const a: boolean = adone.is.netronRemoteStub({}); } + { const a: boolean = adone.is.netronStream({}); } + { const a: boolean = adone.is.iterable({}); } + { const a: boolean = adone.is.windows; } + { const a: boolean = adone.is.linux; } + { const a: boolean = adone.is.freebsd; } + { const a: boolean = adone.is.darwin; } + { const a: boolean = adone.is.sunos; } + { const a: boolean = adone.is.uppercase("abc"); } + { const a: boolean = adone.is.lowercase("abc"); } + { const a: boolean = adone.is.digits("012"); } + { const a: boolean = adone.is.identifier("someMethod"); } + { const a: boolean = adone.is.binaryExtension("mp3"); } + { const a: boolean = adone.is.binaryPath("a.mp3"); } + { const a: boolean = adone.is.ip4("192.168.1.1"); } + { const a: boolean = adone.is.ip6("::192.168.1.1"); } + { const a: boolean = adone.is.arrayBuffer({}); } + { const a: boolean = adone.is.arrayBufferView({}); } + { const a: boolean = adone.is.date({}); } + { const a: boolean = adone.is.error({}); } + { const a: boolean = adone.is.map({}); } + { const a: boolean = adone.is.regexp({}); } + { const a: boolean = adone.is.set({}); } + { const a: boolean = adone.is.symbol({}); } + { const a: boolean = adone.is.validUTF8({}); } + } + + namespace x { + { const a: Error = new adone.x.Exception(); } + { const a: Error = new adone.x.Exception("message"); } + { const a: Error = new adone.x.Exception(new Error()); } + { const a: Error = new adone.x.Exception(new Error(), true); } + { const a: adone.x.Exception = new adone.x.Runtime(); } + { const a: adone.x.Exception = new adone.x.IncompleteBufferError(); } + { const a: adone.x.Exception = new adone.x.NotImplemented(); } + { const a: adone.x.Exception = new adone.x.IllegalState(); } + { const a: adone.x.Exception = new adone.x.NotValid(); } + { const a: adone.x.Exception = new adone.x.Unknown(); } + { const a: adone.x.Exception = new adone.x.NotExists(); } + { const a: adone.x.Exception = new adone.x.Exists(); } + { const a: adone.x.Exception = new adone.x.Empty(); } + { const a: adone.x.Exception = new adone.x.InvalidAccess(); } + { const a: adone.x.Exception = new adone.x.NotSupported(); } + { const a: adone.x.Exception = new adone.x.InvalidArgument(); } + { const a: adone.x.Exception = new adone.x.InvalidNumberOfArguments(); } + { const a: adone.x.Exception = new adone.x.NotFound(); } + { const a: adone.x.Exception = new adone.x.Timeout(); } + { const a: adone.x.Exception = new adone.x.Incorrect(); } + { const a: adone.x.Exception = new adone.x.NotAllowed(); } + { const a: adone.x.Exception = new adone.x.LimitExceeded(); } + { const a: adone.x.Exception = new adone.x.Encoding(); } + { const a: adone.x.Exception = new adone.x.Network(); } + { const a: adone.x.Exception = new adone.x.Bind(); } + { const a: adone.x.Exception = new adone.x.Connect(); } + { const a: adone.x.Exception = new adone.x.Database(); } + { const a: adone.x.Exception = new adone.x.DatabaseInitialization(); } + { const a: adone.x.Exception = new adone.x.DatabaseOpen(); } + { const a: adone.x.Exception = new adone.x.DatabaseRead(); } + { const a: adone.x.Exception = new adone.x.DatabaseWrite(); } + { const a: adone.x.Exception = new adone.x.NetronIllegalState(); } + { const a: adone.x.Exception = new adone.x.NetronPeerDisconnected(); } + { const a: adone.x.Exception = new adone.x.NetronTimeout(); } + } + + namespace EventEmitter { + namespace static { + const a: number = adone.EventEmitter.listenerCount(new adone.EventEmitter(), "event"); + const b: number = adone.EventEmitter.defaultMaxListeners; + } + + namespace addListener { + const a: adone.EventEmitter = new adone.EventEmitter().addListener("event", () => { }); + const b: adone.EventEmitter = new adone.EventEmitter().addListener(Symbol("event"), () => { }); + } + + namespace on { + const a: adone.EventEmitter = new adone.EventEmitter().on("event", () => { }); + const b: adone.EventEmitter = new adone.EventEmitter().on(Symbol("event"), () => { }); + } + + namespace once { + const a: adone.EventEmitter = new adone.EventEmitter().once("event", () => { }); + const b: adone.EventEmitter = new adone.EventEmitter().once(Symbol("event"), () => { }); + } + + namespace prependListener { + const a: adone.EventEmitter = new adone.EventEmitter().prependListener("event", () => { }); + const b: adone.EventEmitter = new adone.EventEmitter().prependListener(Symbol("event"), () => { }); + } + + namespace prependOnceListener { + const a: adone.EventEmitter = new adone.EventEmitter().prependOnceListener("event", () => { }); + const b: adone.EventEmitter = new adone.EventEmitter().prependOnceListener(Symbol("event"), () => { }); + } + + namespace prependOnceListener { + const a: adone.EventEmitter = new adone.EventEmitter().prependOnceListener("event", () => { }); + const b: adone.EventEmitter = new adone.EventEmitter().prependOnceListener(Symbol("event"), () => { }); + } + + namespace removeListener { + const a: adone.EventEmitter = new adone.EventEmitter().removeListener("event", () => { }); + const b: adone.EventEmitter = new adone.EventEmitter().removeListener(Symbol("event"), () => { }); + } + + namespace removeAllListeners { + const a: adone.EventEmitter = new adone.EventEmitter().removeAllListeners("event"); + const b: adone.EventEmitter = new adone.EventEmitter().removeAllListeners(Symbol("event")); + } + + namespace setMaxListeners { + const a: adone.EventEmitter = new adone.EventEmitter().setMaxListeners(10); + } + + namespace getMaxListeners { + const a: number = new adone.EventEmitter().getMaxListeners(); + } + + namespace listeners { + const a: Array<(...args: any[]) => any> = new adone.EventEmitter().listeners("event"); + const b: Array<(...args: any[]) => any> = new adone.EventEmitter().listeners(Symbol("event")); + } + + namespace emit { + const a: boolean = new adone.EventEmitter().emit("event", 1, 2, 3); + const b: boolean = new adone.EventEmitter().emit(Symbol("event"), 1, 2, 3); + } + + namespace eventNames { + const a: Array = new adone.EventEmitter().eventNames(); + const b: Array = new adone.EventEmitter().eventNames(); + } + + namespace listenerCount { + const a: number = new adone.EventEmitter().listenerCount("event"); + const b: number = new adone.EventEmitter().listenerCount(Symbol("event")); + } + } + + namespace AsyncEmitter { + const a: adone.EventEmitter = new adone.AsyncEmitter(); + new adone.AsyncEmitter(10); + + namespace setConcurrency { + const a: adone.AsyncEmitter = new adone.AsyncEmitter().setConcurrency(); + const b: adone.AsyncEmitter = new adone.AsyncEmitter().setConcurrency(10); + } + + namespace emitParallel { + const a: Promise = new adone.AsyncEmitter().emitParallel("even"); + const b: Promise = new adone.AsyncEmitter().emitParallel("even", 1, 2, 3); + } + + namespace emitSerial { + const a: Promise = new adone.AsyncEmitter().emitSerial("even"); + const b: Promise = new adone.AsyncEmitter().emitSerial("even", 1, 2, 3); + } + + namespace emitReduce { + const a: Promise = new adone.AsyncEmitter().emitReduce("even"); + const b: Promise = new adone.AsyncEmitter().emitReduce("even", 1, 2, 3); + } + + namespace emitReduceRight { + const a: Promise = new adone.AsyncEmitter().emitReduceRight("even"); + const b: Promise = new adone.AsyncEmitter().emitReduceRight("even", 1, 2, 3); + } + + namespace subscribe { + const a: () => void = new adone.AsyncEmitter().subscribe("event", () => { }); + const b: () => void = new adone.AsyncEmitter().subscribe("event", () => { }, true); + } + } + + namespace ExBuffer { + new adone.ExBuffer(); + new adone.ExBuffer(10); + new adone.ExBuffer(10, true); + + const buffer = new adone.ExBuffer(); + + namespace readBitSet { + const a: number[] = buffer.readBitSet(); + const b: number[] = buffer.readBitSet(10); + } + + namespace read { + const a: adone.ExBuffer = buffer.read(1); + const b: adone.ExBuffer = buffer.read(1, 10); + } + + namespace readInt8 { + const a: number = buffer.readInt8(); + const b: number = buffer.readInt8(10); + } + + namespace readUInt8 { + const a: number = buffer.readUInt8(); + const b: number = buffer.readUInt8(10); + } + + namespace readInt16LE { + const a: number = buffer.readInt16LE(); + const b: number = buffer.readInt16LE(10); + } + + namespace readUInt16LE { + const a: number = buffer.readUInt16LE(); + const b: number = buffer.readUInt16LE(10); + } + + namespace readInt16BE { + const a: number = buffer.readInt16BE(); + const b: number = buffer.readInt16BE(10); + } + + namespace readUInt16BE { + const a: number = buffer.readUInt16BE(); + const b: number = buffer.readUInt16BE(10); + } + + namespace readInt32LE { + const a: number = buffer.readInt32LE(); + const b: number = buffer.readInt32LE(10); + } + + namespace readUInt32LE { + const a: number = buffer.readUInt32LE(); + const b: number = buffer.readUInt32LE(10); + } + + namespace readInt32BE { + const a: number = buffer.readInt32BE(); + const b: number = buffer.readInt32BE(10); + } + + namespace readUInt32BE { + const a: number = buffer.readUInt32BE(); + const b: number = buffer.readUInt32BE(10); + } + + namespace readInt64LE { + const a: adone.math.Long = buffer.readInt64LE(); + const b: adone.math.Long = buffer.readInt64LE(10); + } + + namespace readUInt64LE { + const a: adone.math.Long = buffer.readUInt64LE(); + const b: adone.math.Long = buffer.readUInt64LE(10); + } + + namespace readInt64BE { + const a: adone.math.Long = buffer.readInt64BE(); + const b: adone.math.Long = buffer.readInt64BE(10); + } + + namespace readUInt64BE { + const a: adone.math.Long = buffer.readUInt64BE(); + const b: adone.math.Long = buffer.readUInt64BE(10); + } + + namespace readFloatLE { + const a: number = buffer.readFloatLE(); + const b: number = buffer.readFloatLE(10); + } + + namespace readFloatBE { + const a: number = buffer.readFloatBE(); + const b: number = buffer.readFloatBE(10); + } + + namespace readDoubleLE { + const a: number = buffer.readDoubleLE(); + const b: number = buffer.readDoubleLE(10); + } + + namespace readDoubleBE { + const a: number = buffer.readDoubleBE(); + const b: number = buffer.readDoubleBE(10); + } + + namespace write { + const a: adone.ExBuffer = buffer.write("1"); + const b: adone.ExBuffer = buffer.write(new adone.ExBuffer()); + const c: adone.ExBuffer = buffer.write(Buffer.alloc(10)); + const d: adone.ExBuffer = buffer.write(new Uint8Array([1, 2, 3])); + const e: adone.ExBuffer = buffer.write(new ArrayBuffer(10)); + const f: adone.ExBuffer = buffer.write("1", 10); + const g: adone.ExBuffer = buffer.write("1", 10, 10); + const h: adone.ExBuffer = buffer.write("1", 10, 10, "utf8"); + } + + namespace writeBitSet { + const a: adone.ExBuffer = buffer.writeBitSet([1, 2, 3]); + const b: number = buffer.writeBitSet([1, 2, 3], 10); + } + + namespace writeInt8 { + const a: adone.ExBuffer = buffer.writeInt8(10); + const b: adone.ExBuffer = buffer.writeInt8(10, 10); + } + + namespace writeUInt8 { + const a: adone.ExBuffer = buffer.writeUInt8(10); + const b: adone.ExBuffer = buffer.writeUInt8(10, 10); + } + + namespace writeInt16LE { + const a: adone.ExBuffer = buffer.writeInt16LE(10); + const b: adone.ExBuffer = buffer.writeInt16LE(10, 10); + } + + namespace writeInt16BE { + const a: adone.ExBuffer = buffer.writeInt16BE(10); + const b: adone.ExBuffer = buffer.writeInt16BE(10, 10); + } + + namespace writeUInt16LE { + const a: adone.ExBuffer = buffer.writeUInt16LE(10); + const b: adone.ExBuffer = buffer.writeUInt16LE(10, 10); + } + + namespace writeUInt16BE { + const a: adone.ExBuffer = buffer.writeUInt16BE(10); + const b: adone.ExBuffer = buffer.writeUInt16BE(10, 10); + } + + namespace writeInt32LE { + const a: adone.ExBuffer = buffer.writeInt32LE(10); + const b: adone.ExBuffer = buffer.writeInt32LE(10, 10); + } + + namespace writeInt32BE { + const a: adone.ExBuffer = buffer.writeInt32BE(10); + const b: adone.ExBuffer = buffer.writeInt32BE(10, 10); + } + + namespace writeUInt32LE { + const a: adone.ExBuffer = buffer.writeUInt32LE(10); + const b: adone.ExBuffer = buffer.writeUInt32LE(10, 10); + } + + namespace writeUInt32BE { + const a: adone.ExBuffer = buffer.writeUInt32BE(10); + const b: adone.ExBuffer = buffer.writeUInt32BE(10, 10); + } + + namespace writeInt64LE { + const a: adone.ExBuffer = buffer.writeInt64LE(10); + const b: adone.ExBuffer = buffer.writeInt64LE(10, 10); + } + + namespace writeInt64BE { + const a: adone.ExBuffer = buffer.writeInt64BE(10); + const b: adone.ExBuffer = buffer.writeInt64BE(10, 10); + } + + namespace writeUInt64LE { + const a: adone.ExBuffer = buffer.writeUInt64LE(10); + const b: adone.ExBuffer = buffer.writeUInt64LE(10, 10); + } + + namespace writeUInt64BE { + const a: adone.ExBuffer = buffer.writeUInt64BE(10); + const b: adone.ExBuffer = buffer.writeUInt64BE(10, 10); + } + + namespace writeFloatLE { + const a: adone.ExBuffer = buffer.writeFloatLE(10); + const b: adone.ExBuffer = buffer.writeFloatLE(10, 10); + } + + namespace writeFloatBE { + const a: adone.ExBuffer = buffer.writeFloatBE(10); + const b: adone.ExBuffer = buffer.writeFloatBE(10, 10); + } + + namespace writeDoubleLE { + const a: adone.ExBuffer = buffer.writeDoubleLE(10); + const b: adone.ExBuffer = buffer.writeDoubleLE(10, 10); + } + + namespace writeDoubleBE { + const a: adone.ExBuffer = buffer.writeDoubleBE(10); + const b: adone.ExBuffer = buffer.writeDoubleBE(10, 10); + } + + namespace writeVarInt32 { + const a: adone.ExBuffer = buffer.writeVarint32(10); + const b: number = buffer.writeVarint32(10, 10); + } + + namespace writeVarInt32ZigZag { + const a: adone.ExBuffer = buffer.writeVarint32ZigZag(10); + const b: number = buffer.writeVarint32ZigZag(10, 10); + } + + namespace readVarint32 { + const a: number = buffer.readVarint32(); + const b: { value: number, length: number } = buffer.readVarint32(10); + } + + namespace readVarint32ZigZag { + const a: number = buffer.readVarint32ZigZag(); + const b: { value: number, length: number } = buffer.readVarint32ZigZag(10); + } + + namespace writeVarint64 { + const a: adone.ExBuffer = buffer.writeVarint64(10); + const b: number = buffer.writeVarint64(10, 10); + } + + namespace writeVarint64ZigZag { + const a: adone.ExBuffer = buffer.writeVarint64ZigZag(10); + const b: number = buffer.writeVarint64ZigZag(10, 10); + } + + namespace readVarint64 { + const a: adone.math.Long = buffer.readVarint64(); + const b: { value: adone.math.Long, length: number } = buffer.readVarint64(10); + } + + namespace readVarint64ZigZag { + const a: adone.math.Long = buffer.readVarint64ZigZag(); + const b: { value: adone.math.Long, length: number } = buffer.readVarint64ZigZag(10); + } + + namespace writeCString { + const a: adone.ExBuffer = buffer.writeCString("asd"); + const b: number = buffer.writeCString("123", 10); + } + + namespace readCString { + const a: string = buffer.readCString(); + const b: { string: string, length: number } = buffer.readCString(10); + } + + namespace writeString { + const a: adone.ExBuffer = buffer.writeString("abc"); + const b: number = buffer.writeString("abc", 10); + } + + namespace readString { + const a: string = buffer.readString(10); + const b: string = buffer.readString(10, "b"); + const c: string = buffer.readString(10, "c"); + const d: { string: string, length: number } = buffer.readString(10, "c", 10); + } + + namespace writeVString { + const a: adone.ExBuffer = buffer.writeVString("abc"); + const b: number = buffer.writeVString("abc", 10); + } + + namespace readVString { + const a: string = buffer.readVString(); + const b: { string: string, length: number } = buffer.readVString(10); + } + + namespace appendTo { + const a: adone.ExBuffer = buffer.appendTo(new adone.ExBuffer()); + const b: adone.ExBuffer = buffer.appendTo(new adone.ExBuffer(), 10); + } + + namespace assert { + const a: adone.ExBuffer = buffer.assert(); + const b: adone.ExBuffer = buffer.assert(true); + } + + namespace capacity { + const a: number = buffer.capacity(); + } + + namespace clear { + const a: adone.ExBuffer = buffer.clear(); + } + + namespace compact { + const a: adone.ExBuffer = buffer.compact(); + const b: adone.ExBuffer = buffer.compact(1); + const c: adone.ExBuffer = buffer.compact(1, 10); + } + + namespace copyTo { + const a: adone.ExBuffer = buffer.copyTo(new adone.ExBuffer()); + const b: adone.ExBuffer = buffer.copyTo(new adone.ExBuffer(), 0); + const c: adone.ExBuffer = buffer.copyTo(new adone.ExBuffer(), 0, 0); + const d: adone.ExBuffer = buffer.copyTo(new adone.ExBuffer(), 0, 0, 10); + } + + namespace ensureCapacity { + const a: adone.ExBuffer = buffer.ensureCapacity(10); + } + + namespace fill { + const a: adone.ExBuffer = buffer.fill("0"); + const b: adone.ExBuffer = buffer.fill(0); + const c: adone.ExBuffer = buffer.fill(0, 0); + const d: adone.ExBuffer = buffer.fill(0, 0, 10); + } + + namespace flip { + const a: adone.ExBuffer = buffer.flip(); + } + + namespace mark { + const a: adone.ExBuffer = buffer.mark(); + const b: adone.ExBuffer = buffer.mark(10); + } + + namespace prepend { + const a: adone.ExBuffer = buffer.prepend(""); + const b: adone.ExBuffer = buffer.prepend(new adone.ExBuffer()); + const c: adone.ExBuffer = buffer.prepend(Buffer.alloc(10)); + const d: adone.ExBuffer = buffer.prepend(new Uint8Array([1, 2, 3])); + const e: adone.ExBuffer = buffer.prepend(new ArrayBuffer(10)); + const f: adone.ExBuffer = buffer.prepend("", "utf8"); + const g: adone.ExBuffer = buffer.prepend("", "utf8", 10); + const h: adone.ExBuffer = buffer.prepend("", 10); + } + + namespace prependTo { + const a: adone.ExBuffer = buffer.prependTo(new adone.ExBuffer()); + const b: adone.ExBuffer = buffer.prependTo(new adone.ExBuffer(), 10); + } + + namespace remaining { + const a: number = buffer.remaining(); + } + + namespace reset { + const a: adone.ExBuffer = buffer.reset(); + } + + namespace resize { + const a: adone.ExBuffer = buffer.resize(10); + } + + namespace reverse { + const a: adone.ExBuffer = buffer.reverse(); + const b: adone.ExBuffer = buffer.reverse(1); + const c: adone.ExBuffer = buffer.reverse(1, 10); + } + + namespace skip { + const a: adone.ExBuffer = buffer.skip(10); + } + + namespace slice { + const a: adone.ExBuffer = buffer.slice(); + const b: adone.ExBuffer = buffer.slice(1); + const c: adone.ExBuffer = buffer.slice(1, 10); + } + + namespace toBuffer { + const a: Buffer = buffer.toBuffer(); + const b: Buffer = buffer.toBuffer(true); + const c: Buffer = buffer.toBuffer(true, 0); + const d: Buffer = buffer.toBuffer(true, 0, 10); + } + + namespace toArrayBuffer { + const a: ArrayBuffer = buffer.toArrayBuffer(); + } + + namespace toString { + const a: string = buffer.toString(); + const b: string = buffer.toString("utf8"); + const c: string = buffer.toString("utf8", 0); + const d: string = buffer.toString("utf8", 0, 10); + } + + namespace toBase64 { + const a: string = buffer.toBase64(); + const b: string = buffer.toBase64(0); + const c: string = buffer.toBase64(0, 10); + } + + namespace toBinary { + const a: string = buffer.toBinary(); + const b: string = buffer.toBinary(0); + const c: string = buffer.toBinary(0, 10); + } + + namespace toDebug { + const a: string = buffer.toDebug(); + const b: string = buffer.toDebug(true); + } + + namespace toUTF8 { + const a: string = buffer.toUTF8(); + const b: string = buffer.toUTF8(0); + const c: string = buffer.toUTF8(0, 10); + } + + namespace static { + namespace accessor { + const a: typeof Buffer = adone.ExBuffer.accessor(); + } + + namespace allocate { + const a: adone.ExBuffer = adone.ExBuffer.allocate(); + const b: adone.ExBuffer = adone.ExBuffer.allocate(10); + const c: adone.ExBuffer = adone.ExBuffer.allocate(10, true); + } + + namespace concat { + const a: adone.ExBuffer = adone.ExBuffer.concat([ + new adone.ExBuffer(), + Buffer.alloc(10), + new Uint8Array([1, 2, 3]), + new ArrayBuffer(10) + ]); + const b: adone.ExBuffer = adone.ExBuffer.concat([ + new adone.ExBuffer(), + Buffer.alloc(10), + new Uint8Array([1, 2, 3]), + new ArrayBuffer(10) + ], "utf8"); + const c: adone.ExBuffer = adone.ExBuffer.concat([ + new adone.ExBuffer(), + Buffer.alloc(10), + new Uint8Array([1, 2, 3]), + new ArrayBuffer(10) + ], "utf8", true); + } + + namespace type { + const a: typeof Buffer = adone.ExBuffer.type(); + } + + namespace wrap { + const a: adone.ExBuffer = adone.ExBuffer.wrap(""); + const b: adone.ExBuffer = adone.ExBuffer.wrap(new adone.ExBuffer()); + const c: adone.ExBuffer = adone.ExBuffer.wrap(Buffer.alloc(10)); + const d: adone.ExBuffer = adone.ExBuffer.wrap(new Uint8Array([1, 2, 3])); + const e: adone.ExBuffer = adone.ExBuffer.wrap(new ArrayBuffer(10)); + const f: adone.ExBuffer = adone.ExBuffer.wrap("", "utf8"); + const g: adone.ExBuffer = adone.ExBuffer.wrap("", "utf8", true); + } + + namespace calculateVarint32 { + const a: number = adone.ExBuffer.calculateVarint32(10); + } + + namespace zigZagEncode32 { + const a: number = adone.ExBuffer.zigZagEncode32(10); + } + + namespace zigZagDecode32 { + const a: number = adone.ExBuffer.zigZagDecode32(10); + } + + namespace calculateVarint64 { + const a: number = adone.ExBuffer.calculateVarint64(10); + const b: number = adone.ExBuffer.calculateVarint64("10"); + } + + namespace zigZagEncode64 { + const a: adone.math.Long = adone.ExBuffer.zigZagEncode64(10); + const b: adone.math.Long = adone.ExBuffer.zigZagEncode64("10"); + const c: adone.math.Long = adone.ExBuffer.zigZagEncode64(adone.math.Long.fromValue(10)); + } + + namespace zigZagDecode64 { + const a: adone.math.Long = adone.ExBuffer.zigZagDecode64(10); + const b: adone.math.Long = adone.ExBuffer.zigZagDecode64("10"); + const c: adone.math.Long = adone.ExBuffer.zigZagDecode64(adone.math.Long.fromValue(10)); + } + + namespace calculateUTF8Chars { + const a: number = adone.ExBuffer.calculateUTF8Chars("123"); + } + + namespace calculateString { + const a: number = adone.ExBuffer.calculateString("123"); + } + + namespace fromBase64 { + const a: adone.ExBuffer = adone.ExBuffer.fromBase64("123"); + } + + namespace btoa { + const a: string = adone.ExBuffer.btoa("123"); + } + + namespace atob { + const a: string = adone.ExBuffer.atob("123"); + } + + namespace fromBinary { + const a: adone.ExBuffer = adone.ExBuffer.fromBinary("123"); + } + + namespace fromDebug { + const a: adone.ExBuffer = adone.ExBuffer.fromDebug("12"); + const b: adone.ExBuffer = adone.ExBuffer.fromDebug("12", true); + } + + namespace fromHex { + const a: adone.ExBuffer = adone.ExBuffer.fromHex("192"); + const b: adone.ExBuffer = adone.ExBuffer.fromHex("192", true); + } + + namespace fromUTF8 { + const a: adone.ExBuffer = adone.ExBuffer.fromUTF8("123"); + const b: adone.ExBuffer = adone.ExBuffer.fromUTF8("123", true); + } + + namespace constants { + const a: number = adone.ExBuffer.DEFAULT_CAPACITY; + const b: boolean = adone.ExBuffer.DEFAULT_NOASSERT; + const c: number = adone.ExBuffer.MAX_VARINT32_BYTES; + const d: number = adone.ExBuffer.MAX_VARINT64_BYTES; + const e: string = adone.ExBuffer.METRICS_CHARS; + const f: string = adone.ExBuffer.METRICS_BYTES; + } + } + } +} diff --git a/types/adone/test/glosses/math.ts b/types/adone/test/glosses/math.ts new file mode 100644 index 0000000000..8a9e9bc1cf --- /dev/null +++ b/types/adone/test/glosses/math.ts @@ -0,0 +1,259 @@ +const { math } = adone; + +namespace mathTests { + namespace Long { + new math.Long(); + new math.Long(0); + new math.Long(0, 0); + new math.Long(0, 0, true); + + namespace toInt { + const a: number = new math.Long().toInt(); + } + + namespace toNumber { + const a: number = new math.Long().toNumber(); + } + + namespace toString { + const a: string = new math.Long().toString(); + const b: string = new math.Long().toString(16); + } + + namespace getHighBits { + const a: number = new math.Long().getHighBits(); + } + + namespace getLowBits { + const a: number = new math.Long().getLowBits(); + } + + namespace getLowBitsUnsigned { + const a: number = new math.Long().getLowBitsUnsigned(); + } + + namespace getHighBitsUnsigned { + const a: number = new math.Long().getHighBitsUnsigned(); + } + + namespace getNumBitsAbs { + const a: number = new math.Long().getNumBitsAbs(); + } + + namespace isZero { + const a: boolean = new math.Long().isZero(); + } + + namespace isNegative { + const a: boolean = new math.Long().isNegative(); + } + + namespace isPositive { + const a: boolean = new math.Long().isPositive(); + } + + namespace isOdd { + const a: boolean = new math.Long().isOdd(); + } + + namespace isEven { + const a: boolean = new math.Long().isEven(); + } + + namespace equals { + const a = new math.Long(); + const b: boolean = a.equals(new math.Long()); + const c: boolean = a.equals(1); + const d: boolean = a.equals("1"); + const e: boolean = a.equals({ low: 0, high: 0 }); + } + + namespace lessThan { + const a = new math.Long(); + const b: boolean = a.lessThan(new math.Long()); + const c: boolean = a.lessThan(1); + const d: boolean = a.lessThan("1"); + const e: boolean = a.lessThan({ low: 0, high: 0 }); + } + + namespace lessThanOrEqual { + const a = new math.Long(); + const b: boolean = a.lessThanOrEqual(new math.Long()); + const c: boolean = a.lessThanOrEqual(1); + const d: boolean = a.lessThanOrEqual("1"); + const e: boolean = a.lessThanOrEqual({ low: 0, high: 0 }); + } + + namespace greaterThan { + const a = new math.Long(); + const b: boolean = a.greaterThan(new math.Long()); + const c: boolean = a.greaterThan(1); + const d: boolean = a.greaterThan("1"); + const e: boolean = a.greaterThan({ low: 0, high: 0 }); + } + + namespace greaterThanOrEqual { + const a = new math.Long(); + const b: boolean = a.greaterThanOrEqual(new math.Long()); + const c: boolean = a.greaterThanOrEqual(1); + const d: boolean = a.greaterThanOrEqual("1"); + const e: boolean = a.greaterThanOrEqual({ low: 0, high: 0 }); + } + + namespace greaterThanOrEqual { + const a = new math.Long(); + const b: number = a.compare(new math.Long()); + const c: number = a.compare(1); + const d: number = a.compare("1"); + const e: number = a.compare({ low: 0, high: 0 }); + } + + namespace negate { + const a: adone.math.Long = new math.Long().negate(); + } + + namespace add { + const a = new math.Long(); + const b: adone.math.Long = a.add(new math.Long()); + const c: adone.math.Long = a.add(1); + const d: adone.math.Long = a.add("1"); + const e: adone.math.Long = a.add({ low: 0, high: 0 }); + } + + namespace sub { + const a = new math.Long(); + const b: adone.math.Long = a.sub(new math.Long()); + const c: adone.math.Long = a.sub(1); + const d: adone.math.Long = a.sub("1"); + const e: adone.math.Long = a.sub({ low: 0, high: 0 }); + } + + namespace mul { + const a = new math.Long(); + const b: adone.math.Long = a.mul(new math.Long()); + const c: adone.math.Long = a.mul(1); + const d: adone.math.Long = a.mul("1"); + const e: adone.math.Long = a.mul({ low: 0, high: 0 }); + } + + namespace div { + const a = new math.Long(); + const b: adone.math.Long = a.div(new math.Long()); + const c: adone.math.Long = a.div(1); + const d: adone.math.Long = a.div("1"); + const e: adone.math.Long = a.div({ low: 0, high: 0 }); + } + + namespace mod { + const a = new math.Long(); + const b: adone.math.Long = a.mod(new math.Long()); + const c: adone.math.Long = a.mod(1); + const d: adone.math.Long = a.mod("1"); + const e: adone.math.Long = a.mod({ low: 0, high: 0 }); + } + + namespace not { + const a: adone.math.Long = new math.Long().not(); + } + + namespace and { + const a = new math.Long(); + const b: adone.math.Long = a.and(new math.Long()); + const c: adone.math.Long = a.and(1); + const d: adone.math.Long = a.and("1"); + const e: adone.math.Long = a.and({ low: 0, high: 0 }); + } + + namespace or { + const a = new math.Long(); + const b: adone.math.Long = a.or(new math.Long()); + const c: adone.math.Long = a.or(1); + const d: adone.math.Long = a.or("1"); + const e: adone.math.Long = a.or({ low: 0, high: 0 }); + } + + namespace xor { + const a = new math.Long(); + const b: adone.math.Long = a.xor(new math.Long()); + const c: adone.math.Long = a.xor(1); + const d: adone.math.Long = a.xor("1"); + const e: adone.math.Long = a.xor({ low: 0, high: 0 }); + } + + namespace shl { + const a = new math.Long(); + const b: adone.math.Long = a.shl(new math.Long()); + const c: adone.math.Long = a.shl(1); + } + + namespace shr { + const a = new math.Long(); + const b: adone.math.Long = a.shr(new math.Long()); + const c: adone.math.Long = a.shr(1); + } + + namespace shru { + const a = new math.Long(); + const b: adone.math.Long = a.shr(new math.Long()); + const c: adone.math.Long = a.shr(1); + } + + namespace toSigned { + const a: adone.math.Long = new math.Long().toSigned(); + } + + namespace toUnsigned { + const a: adone.math.Long = new math.Long().toUnsigned(); + } + + namespace toBytes { + const a: number[] = new math.Long().toBytes(); + } + + namespace toBytesLE { + const a: number[] = new math.Long().toBytesLE(); + } + + namespace static { + namespace fromInt { + const a: adone.math.Long = math.Long.fromInt(123); + const b: adone.math.Long = math.Long.fromInt(123, true); + } + + namespace fromNumber { + const a: adone.math.Long = math.Long.fromNumber(123); + const b: adone.math.Long = math.Long.fromNumber(123, true); + } + + namespace fromBits { + const a: adone.math.Long = math.Long.fromBits(0, 0); + const b: adone.math.Long = math.Long.fromBits(123, 0, true); + } + + namespace fromString { + const a: adone.math.Long = math.Long.fromString("123"); + const b: adone.math.Long = math.Long.fromString("123", true); + const c: adone.math.Long = math.Long.fromString("123", 16); + const d: adone.math.Long = math.Long.fromString("123", true, 16); + } + + namespace fromValue { + const a: adone.math.Long = math.Long.fromValue(new math.Long()); + const b: adone.math.Long = math.Long.fromValue(1); + const c: adone.math.Long = math.Long.fromValue("1"); + const e: adone.math.Long = math.Long.fromValue({ low: 0, high: 0 }); + } + + namespace constants { + const a: adone.math.Long = math.Long.MIN_VALUE; + const b: adone.math.Long = math.Long.MAX_VALUE; + const c: adone.math.Long = math.Long.MAX_UNSIGNED_VALUE; + const d: adone.math.Long = math.Long.ZERO; + const e: adone.math.Long = math.Long.UZERO; + const f: adone.math.Long = math.Long.ONE; + const g: adone.math.Long = math.Long.UONE; + const h: adone.math.Long = math.Long.NEG_ONE; + } + } + } +} diff --git a/types/adone/test/glosses/std.ts b/types/adone/test/glosses/std.ts new file mode 100644 index 0000000000..611f9401e9 --- /dev/null +++ b/types/adone/test/glosses/std.ts @@ -0,0 +1,161 @@ +import adone from "adone"; + +import * as assert from "assert"; +import * as fs from "fs"; +import * as path from "path"; +import * as util from "util"; +import * as events from "events"; +import * as stream from "stream"; +import * as url from "url"; +import * as net from "net"; +import * as http from "http"; +import * as https from "https"; +import * as child_process from "child_process"; +import * as os from "os"; +import * as cluster from "cluster"; +import * as repl from "repl"; +import * as punycode from "punycode"; +import * as readline from "readline"; +import * as string_decoder from "string_decoder"; +import * as querystring from "querystring"; +import * as crypto from "crypto"; +import * as vm from "vm"; +import * as v8 from "v8"; +import * as domain from "domain"; +import * as tty from "tty"; +import * as buffer from "buffer"; +import * as constants from "constants"; +import * as zlib from "zlib"; +import * as tls from "tls"; +import * as console from "console"; +import * as dns from "dns"; +import * as timers from "timers"; +import * as dgram from "dgram"; + +const { std } = adone; + +namespace stdTests { + namespace assert { + std.assert(true); + } + + namespace fs { + std.fs.readFileSync("test").length; + } + + namespace path { + std.path.join("a", "b").charAt(0); + } + + namespace util { + std.util.format("hello").charAt(0); + } + + namespace events { + new std.events.EventEmitter().on("event", () => {}); + } + + namespace steam { + new std.stream.PassThrough().resume(); + } + + namespace url { + std.url.parse("https://adone.io").hostname; + } + + namespace net { + std.net.connect(31337).write("hello"); + } + + namespace http { + std.http.get("http://localhost").end(); + } + + namespace https { + std.https.get("https://adone.io").end(); + } + + namespace child_process { + std.child_process.fork(__filename, [], { stdio: ["ipc"] }).send("hello"); + } + + namespace os { + std.os.tmpdir().charAt(0); + } + + namespace cluster { + std.cluster.fork().kill(); + } + + namespace repl { + std.repl.start().close(); + } + + namespace punycode { + std.punycode.decode("ads").charAt(0); + } + + namespace readline { + std.readline.clearLine(process.stdout, 1); + } + + namespace string_decoder { + new std.string_decoder.StringDecoder().end().charAt(0); + } + + namespace querystring { + std.querystring.escape("hello").charAt(0); + } + + namespace crypto { + std.crypto.createHash("sha1").update("hello").digest("hex"); + } + + namespace vm { + std.vm.runInContext("a + 2", std.vm.createContext({ a: 1 })); + } + + namespace v8 { + std.v8.getHeapStatistics().heap_size_limit + 2; + } + + namespace domain { + std.domain.create().members; + } + + namespace tty { + std.tty.isatty(1) === true; + } + + namespace buffer { + std.buffer.Buffer.alloc(10); + } + + namespace constants { + std.constants.EACCES + 2; + } + + namespace zlib { + std.zlib.createDeflate().write("ttt"); + } + + namespace tls { + std.tls.connect({}).end(); + } + + namespace console { + std.console.trace("message"); + } + + namespace dns { + std.dns.resolve4("adone.io", (err, data) => {}); + } + + namespace timers { + std.timers.setTimeout(() => {}, 2000).unref(); + } + + namespace dgram { + std.dgram.createSocket("udp4").bind(31337); + } +} diff --git a/types/adone/test/glosses/utils.ts b/types/adone/test/glosses/utils.ts new file mode 100644 index 0000000000..c0f119cb6e --- /dev/null +++ b/types/adone/test/glosses/utils.ts @@ -0,0 +1,736 @@ +const { util } = adone; + +namespace utilTests { + namespace arrify { + const a: number[] = util.arrify([1, 2, 3]); + const b: number[] = util.arrify(1); + const c: string[] = util.arrify("2"); + const d: string[] = util.arrify(["1"]); + } + + namespace slice { + const a: number[] = util.slice([1, 2, 3]); + const b: number[] = util.slice([1, 2, 3], 1); + const c: number[] = util.slice([1, 2, 3], 1, 4); + const d: string[] = util.slice(["1"]); + } + + namespace spliceOne { + util.spliceOne([1, 2, 3], 0); + } + + namespace normalizePath { + const a: string = util.normalizePath("path"); + const b: string = util.normalizePath("path", true); + } + + namespace unixifyPath { + const a: string = util.unixifyPath("path"); + const b: string = util.unixifyPath("path", true); + } + + namespace functionName { + const a: string = util.functionName(function f() { }); + const b: string = util.functionName((a, b, c) => { }); + } + + namespace mapArguments { + const a: (...args: any[]) => any = util.mapArguments(() => { }); + const b: (...args: T[]) => T[] = util.mapArguments(1); + const c: (...args: any[]) => any = util.mapArguments([1]); + const d: (x: T) => T = util.mapArguments(); + } + + namespace parseMs { + const result: { + days: number; + hours: number; + milliseconds: number; + minutes: number; + } = util.parseMs(123); + } + + namespace pluralizeWord { + const a: string = util.pluralizeWord("day"); + const b: string = util.pluralizeWord("day", "days"); + const c: string = util.pluralizeWord("day", "days", 1); + } + + namespace functionParams { + const a: string[] = util.functionParams((a: any, b: any, c: any) => { }); + } + + namespace randomChoice { + const a: number = util.randomChoice([1, 2, 3]); + const b: string = util.randomChoice(["1", "2", "3"]); + } + + namespace shuffleArray { + const a: number[] = util.shuffleArray([1, 2, 3]); + const b: string[] = util.shuffleArray(["1", "2", "3"]); + } + + namespace enumerate { + { + const a = util.enumerate([1, 2, 3]); + const it = a[Symbol.iterator](); + const value: [number, number] = it.next().value; + for (const i of a) { + const [idx, value]: [number, number] = i; + } + } + { + const a = util.enumerate(["1", "2"]); + const it = a[Symbol.iterator](); + const value: [number, string] = it.next().value; + for (const i of a) { + const [idx, value]: [number, string] = i; + } + } + } + + namespace zip { + { + const a = util.zip([1, 2, 3], ["4", "5", "6"]); + const it = a[Symbol.iterator](); + const value: [number, string] = it.next().value; + for (const i of a) { + const [i1, i2]: [number, string] = i; + } + } + { + const a = util.zip( + [1, 2, 3], + ["4", "5", "6"], + [7, 8, 9] + ); + const it = a[Symbol.iterator](); + const value: [number, string, number] = it.next().value; + for (const i of a) { + const [i1, i2, i3]: [number, string, number] = i; + } + } + { + const a = util.zip( + [1, 2, 3], + ["4", "5", "6"], + [7, 8, 9], + ["10", "11", "12"] + ); + const it = a[Symbol.iterator](); + const value: [number, string, number, string] = it.next().value; + for (const i of a) { + const [i1, i2, i3, i4]: [number, string, number, string] = i; + } + } + { + const a = util.zip( + [1, 2, 3], + ["4", "5", "6"], + [7, 8, 9], + ["10", "11", "12"], + [13, 14, 15, 16] + ); + const it = a[Symbol.iterator](); + const value: any[] = it.next().value; + for (const i of a) { + const [i1, i2, i3, i4]: any[] = i; + } + } + } + + namespace keys { + const a: string[] = util.keys({}); + const b: string[] = util.keys({}, { all: true }); + const c: string[] = util.keys({}, { followProto: true }); + const d: string[] = util.keys({}, { onlyEnumerable: true }); + } + + namespace values { + const a: any[] = util.values({}); + const b: any[] = util.values({}, { all: true }); + const c: any[] = util.values({}, { followProto: true }); + const d: any[] = util.values({}, { onlyEnumerable: true }); + } + + namespace entries { + const a: Array<[string, any]> = util.entries({}); + const b: Array<[string, any]> = util.entries({}, { all: true }); + const c: Array<[string, any]> = util.entries({}, { followProto: true }); + const d: Array<[string, any]> = util.entries({}, { onlyEnumerable: true }); + } + + namespace toDotNotation { + const a: object = util.toDotNotation({ a: 1 }); + } + + namespace flatten { + const a: number[] = util.flatten([1, [2, 3]]); + const b: number[] = util.flatten([1, [2, 3]], {}); + const c: number[] = util.flatten([1, [2, 3]], { depth: 1 }); + } + + namespace globParent { + const a: string = util.globParent("a/b/c/**"); + } + + namespace by { + const a: (a: number, b: number) => any = util.by((x: number): number => x); + const b: (a: number, b: number) => number = util.by((x: number): string => `${x}`, (a: string, b: string) => a.length - b.length); + } + + namespace toFastProperties { + const a: object = util.toFastProperties({}); + } + + namespace stripBom { + const a: string = util.stripBom("123"); + } + + namespace sortKeys { + const a: object = util.sortKeys({}); + const b: object = util.sortKeys({}, {}); + const c: object = util.sortKeys({}, { deep: true }); + const d: object = util.sortKeys({}, { compare: (a, b) => 2 }); + } + + namespace globize { + const a: string = util.globize("test"); + const b: string = util.globize("test", {}); + const c: string = util.globize("test", { exts: "" }); + const d: string = util.globize("test", { recursively: true }); + } + + namespace unique { + const a: number[] = util.unique([1, 2, 3]); + const b: string[] = util.unique(["1", "2", "3"]); + const c: object[] = util.unique([{ a: 1 }, { a: 2 }], (obj: any) => obj.a); + } + + namespace invertObject { + const a: object = util.invertObject({}); + const b: object = util.invertObject({}, {}); + const c: object = util.invertObject({}, { all: true }); + const d: object = util.invertObject({}, { followProto: true }); + const e: object = util.invertObject({}, { onlyEnumerable: true }); + } + + namespace humanizeTime { + const a: string = util.humanizeTime(12345); + const b: string = util.humanizeTime(12345, {}); + const c: string = util.humanizeTime(12345, { compact: true }); + const d: string = util.humanizeTime(12345, { msDecimalDigits: 2 }); + const e: string = util.humanizeTime(12345, { secDecimalDigits: 2 }); + const f: string = util.humanizeTime(12345, { verbose: true }); + } + + namespace humanizeSize { + const a: string = util.humanizeSize(12345); + const b: string = util.humanizeSize(12345, ""); + } + + namespace parseSize { + const a: number | null = util.parseSize(123); + const b: number | null = util.parseSize("123Kb"); + } + + namespace clone { + const a: object = util.clone({}); + const b: object = util.clone({}, {}); + const c: object = util.clone({}, { deep: true }); + } + + namespace toUTF8Array { + const a: number[] = util.toUTF8Array("hello"); + } + + namespace asyncIter { + util.asyncIter([1, 2, 3], () => { }, () => { }); + } + + namespace asyncFor { + util.asyncFor({}, () => { }, () => { }); + } + + namespace once { + { + const f = () => 2; + const a: () => number = util.once(f); + } + { + const f = (a: number) => `${a}`; + const a: (a: number) => string = util.once(f); + } + } + + namespace asyncWaterfall { + util.asyncWaterfall([ + (callback: (a: any, b: any, c: any) => void) => { + callback(null, 'one', 'two'); + } + ], (err: any, result: any) => { + // + }); + } + + namespace xrange { + for (const i of util.xrange(10)) { + const a: number = i; + } + for (const i of util.xrange(1, 10)) { + const a: number = i; + } + for (const i of util.xrange(1, 10, 2)) { + const a: number = i; + } + } + namespace range { + const a: number[] = util.range(10); + const b: number[] = util.range(1, 10); + const c: number[] = util.range(1, 10, 2); + } + + namespace reFindAll { + const a: RegExpExecArray[] = util.reFindAll(/\d+/, "1 2 3 4 5"); + } + + namespace assignDeep { + const a: object = util.assignDeep({ a: 1 }, { a: 2 }); + } + + namespace match { + const a: number | boolean = util.match(["a", "b", "c"], "a"); + const b: (a: any, b: any) => number | boolean = util.match("a", { index: true }); + const c: number | boolean = util.match(["a", "b", "c"], "a", { dot: true }); + const d: (a: any, b: any) => number | boolean = util.match("a", { end: 2 }); + const e: (a: any, b: any) => number | boolean = util.match("a", { start: 2 }); + const f: (a: any, b: any) => number | boolean = util.match("a"); + } + + namespace toposort { + const a: number[] = util.toposort([ + [0, 1], + [2, 3], + [4, 5], + [6, 7] + ]); + const b: number[] = util.toposort.array([0, 1, 2], [ + [0, 1], + [2, 3], + [4, 5], + [6, 7] + ]); + } + + namespace jsesc { + const a: string = util.jsesc({ a: 1 }); + const b: string = util.jsesc({ a: 1 }, { escapeEverything: true }); + const c: string = util.jsesc({ a: 1 }, { minimal: true }); + const d: string = util.jsesc({ a: 1 }, { isScriptContext: true }); + const e: string = util.jsesc({ a: 1 }, { quotes: "'" }); + const f: string = util.jsesc({ a: 1 }, { wrap: true }); + const g: string = util.jsesc({ a: 1 }, { es6: true }); + const h: string = util.jsesc({ a: 1 }, { json: true }); + const i: string = util.jsesc({ a: 1 }, { compact: true }); + const j: string = util.jsesc({ a: 1 }, { lowercaseHex: true }); + const k: string = util.jsesc({ a: 1 }, { numbers: "decimal" }); + const l: string = util.jsesc({ a: 1 }, { indent: " " }); + const m: string = util.jsesc({ a: 1 }, { indentLevel: 4 }); + const n: string = util.jsesc({ a: 1 }, { __inline1__: true }); + const o: string = util.jsesc({ a: 1 }, { __inline2__: true }); + } + + namespace typeOf { + const a: string = util.typeOf(1); + } + + namespace memcpy { + const a: number = util.memcpy.utou(Buffer.alloc(10), 0, Buffer.alloc(10), 0, 10); + const b: number = util.memcpy.atoa(new ArrayBuffer(10), 0, new ArrayBuffer(10), 0, 10); + const c: number = util.memcpy.atou(Buffer.alloc(10), 0, new ArrayBuffer(10), 0, 10); + const d: number = util.memcpy.utoa(new ArrayBuffer(10), 0, Buffer.alloc(10), 0, 10); + const e: number = util.memcpy.copy(Buffer.alloc(10), 0, Buffer.alloc(10), 0, 10); + const f: number = util.memcpy.copy(new ArrayBuffer(10), 0, new ArrayBuffer(10), 0, 10); + const g: number = util.memcpy.copy(Buffer.alloc(10), 0, new ArrayBuffer(10), 0, 10); + const h: number = util.memcpy.copy(new ArrayBuffer(10), 0, Buffer.alloc(10), 0, 10); + } + + namespace uuid { + namespace v1 { + const a: string = util.uuid.v1(); + const b: number[] = util.uuid.v1({}, []); + const c: number[] = util.uuid.v1({}, [], 1); + const d: string = util.uuid.v1({}); + const e: string = util.uuid.v1({ clockseq: 1 }); + const f: string = util.uuid.v1({ msecs: 1 }); + const g: string = util.uuid.v1({ nsecs: 1 }); + } + + namespace v4 { + const a: string = util.uuid.v4(); + const b: number[] = util.uuid.v4({}, []); + const c: number[] = util.uuid.v4({}, [], 1); + const d: string = util.uuid.v4({}); + const e: string = util.uuid.v4({ clockseq: 1 }); + const f: string = util.uuid.v4({ msecs: 1 }); + const g: string = util.uuid.v4({ nsecs: 1 }); + } + + namespace v5 { + const a: string = util.uuid.v5([], []); + const b: number[] = util.uuid.v5([], [], []); + const c: number[] = util.uuid.v5([], [], [], 1); + } + } + + namespace delegate { + const a = util.delegate({}, "a"); + a.getter("a").access("b").method("c").setter("d"); + } + + namespace GlobExp { + { + const glob = new util.GlobExp("*.js"); + const a: boolean = glob.hasMagic(); + const b: string[] = glob.expandBraces(); + const c: RegExp = glob.makeRe(); + const d: boolean = glob.test("a.js"); + } + { + const a: boolean = util.GlobExp.hasMagic("*.js"); + const b: string[] = util.GlobExp.expandBraces("*.js"); + const c: RegExp = util.GlobExp.makeRe("*.js"); + const d: boolean = util.GlobExp.test("*.js", "a.js"); + } + new util.GlobExp(""); + new util.GlobExp("", {}); + new util.GlobExp("", { dot: true }); + new util.GlobExp("", { flipNegate: true }); + new util.GlobExp("", { matchBase: true }); + new util.GlobExp("", { nobrace: true }); + new util.GlobExp("", { nocase: true }); + new util.GlobExp("", { nocomment: true }); + new util.GlobExp("", { noext: true }); + new util.GlobExp("", { noglobstar: true }); + new util.GlobExp("", { nonegate: true }); + util.GlobExp.hasMagic("", {}); + util.GlobExp.hasMagic("", { dot: true }); + util.GlobExp.hasMagic("", { flipNegate: true }); + util.GlobExp.hasMagic("", { matchBase: true }); + util.GlobExp.hasMagic("", { nobrace: true }); + util.GlobExp.hasMagic("", { nocase: true }); + util.GlobExp.hasMagic("", { nocomment: true }); + util.GlobExp.hasMagic("", { noext: true }); + util.GlobExp.hasMagic("", { noglobstar: true }); + util.GlobExp.hasMagic("", { nonegate: true }); + util.GlobExp.expandBraces("", {}); + util.GlobExp.expandBraces("", { dot: true }); + util.GlobExp.expandBraces("", { flipNegate: true }); + util.GlobExp.expandBraces("", { matchBase: true }); + util.GlobExp.expandBraces("", { nobrace: true }); + util.GlobExp.expandBraces("", { nocase: true }); + util.GlobExp.expandBraces("", { nocomment: true }); + util.GlobExp.expandBraces("", { noext: true }); + util.GlobExp.expandBraces("", { noglobstar: true }); + util.GlobExp.expandBraces("", { nonegate: true }); + util.GlobExp.makeRe("", {}); + util.GlobExp.makeRe("", { dot: true }); + util.GlobExp.makeRe("", { flipNegate: true }); + util.GlobExp.makeRe("", { matchBase: true }); + util.GlobExp.makeRe("", { nobrace: true }); + util.GlobExp.makeRe("", { nocase: true }); + util.GlobExp.makeRe("", { nocomment: true }); + util.GlobExp.makeRe("", { noext: true }); + util.GlobExp.makeRe("", { noglobstar: true }); + util.GlobExp.makeRe("", { nonegate: true }); + util.GlobExp.test("a", "b", {}); + util.GlobExp.test("a", "b", { dot: true }); + util.GlobExp.test("a", "b", { flipNegate: true }); + util.GlobExp.test("a", "b", { matchBase: true }); + util.GlobExp.test("a", "b", { nobrace: true }); + util.GlobExp.test("a", "b", { nocase: true }); + util.GlobExp.test("a", "b", { nocomment: true }); + util.GlobExp.test("a", "b", { noext: true }); + util.GlobExp.test("a", "b", { noglobstar: true }); + util.GlobExp.test("a", "b", { nonegate: true }); + } + + namespace iconv { + // TODO + } + + namespace sqlstring { + namespace escapeId { + const a: string = util.sqlstring.escapeId("asd"); + const b: string = util.sqlstring.escapeId(["asd"]); + const c: string = util.sqlstring.escapeId(["asd"], true); + } + + namespace dateToString { + const a: string = util.sqlstring.dateToString(Date.now()); + const b: string = util.sqlstring.dateToString(123, "local"); + } + + namespace arrayToList { + const a: string = util.sqlstring.arrayToList(["1", "a"]); + } + + namespace bufferToString { + const a: string = util.sqlstring.bufferToString(Buffer.alloc(10)); + } + + namespace objectToValues { + const a: string = util.sqlstring.objectToValues({ a: 1 }); + const b: string = util.sqlstring.objectToValues({ a: 1 }, "local"); + } + + namespace escape { + const a: string = util.sqlstring.escape(1); + const b: string = util.sqlstring.escape(1, true); + const c: string = util.sqlstring.escape(1, true, "local"); + } + + namespace format { + const a: string = util.sqlstring.format("??"); + const b: string = util.sqlstring.format("??", "a"); + const c: string = util.sqlstring.format("??", ["a"]); + const d: string = util.sqlstring.format("??", ["a"], true); + } + } + + namespace Editor { + namespace options { + new util.Editor(); + new util.Editor({}); + new util.Editor({ text: "" }); + new util.Editor({ editor: "" }); + new util.Editor({ path: "" }); + new util.Editor({ ext: "" }); + } + + const a: string = util.Editor.DEFAULT; + new util.Editor().spawn().then((x: adone.std.child_process.ChildProcess) => { }); + new util.Editor().run().then((x: string) => { }); + new util.Editor().cleanup().then((x: undefined) => { }); + util.Editor.edit().then((x: string) => { }); + } + + namespace binarySearch { + const a: number = util.binarySearch.GREATEST_LOWER_BOUND; + const b: number = util.binarySearch.GREATEST_LOWER_BOUND; + const c: number = util.binarySearch([1, 2, 3], 2); + const d: number = util.binarySearch([1, 2, 3], 2, 0); + const e: number = util.binarySearch([1, 2, 3], 2, 0, 10); + const f: number = util.binarySearch([1, 2, 3], 2, 0, 10, (a, b) => a - b); + const g: number = util.binarySearch([1, 2, 3], 2, 0, 10, (a, b) => a - b, util.binarySearch.GREATEST_LOWER_BOUND); + } + + namespace buffer { + const a: Buffer = util.buffer.concat([Buffer.alloc(10), Buffer.alloc(20)], 30); + util.buffer.mask(Buffer.alloc(10), Buffer.alloc(10), Buffer.alloc(10), 0, 10); + util.buffer.unmask(Buffer.alloc(10), Buffer.alloc(10)); + } + + namespace shebang { + const a: string | null = util.shebang("#!/bin/sh"); + } + + namespace ReInterval { + new util.ReInterval(() => { }, 1000); + new util.ReInterval(() => { }, 1000, [1]); + const a = new util.ReInterval(() => { }, 1000); + a.reschedule(400); + a.clear(); + a.destroy(); + } + + namespace RateLimiter { + new util.RateLimiter(); + new util.RateLimiter(1); + new util.RateLimiter(1, 1000); + new util.RateLimiter(1, 1000, true); + const a = new util.RateLimiter(); + a.removeTokens(1).then((x: number) => { }); + const b: boolean = a.tryRemoveTokens(10); + const c: number = a.getTokensRemaining(); + } + + namespace throttle { + const a: () => Promise = util.throttle(() => 42); + const b: (a: number) => Promise = util.throttle((a: number) => `${a}`); + const c: (a: number, b: string) => Promise = util.throttle((a: number, b: string) => String(a) + b); + const d = util.throttle(() => { }, {}); + const e = util.throttle(() => { }, { interval: 1000 }); + const f = util.throttle(() => { }, { max: 10 }); + const g = util.throttle(() => { }, { ordered: true }); + const h = util.throttle(() => { }, { waitForReturn: true }); + } + + namespace fakeClock { + namespace timers { + const a: typeof global.setTimeout = util.fakeClock.timers.setTimeout; + const b: typeof global.clearTimeout = util.fakeClock.timers.clearTimeout; + const c: typeof global.setInterval = util.fakeClock.timers.setInterval; + const d: typeof global.clearInterval = util.fakeClock.timers.clearInterval; + const e: typeof global.setImmediate = util.fakeClock.timers.setImmediate; + const f: typeof global.clearImmediate = util.fakeClock.timers.clearImmediate; + const g: typeof global.Date = util.fakeClock.timers.Date; + const h: typeof global.process.hrtime = util.fakeClock.timers.hrtime; + const i: typeof global.process.nextTick = util.fakeClock.timers.nextTick; + } + + namespace install { + util.fakeClock.install(100); + util.fakeClock.install(new Date()); + util.fakeClock.install({}); + util.fakeClock.install({ advanceTimeDelta: 20 }); + util.fakeClock.install({ loopLimit: 20 }); + util.fakeClock.install({ now: 20 }); + util.fakeClock.install({ shouldAdvanceTime: false }); + util.fakeClock.install({ target: {} }); + const clock = util.fakeClock.install({ toFake: ["setTimeout", "clearTimeout"] }); + { + const timer = clock.setTimeout(() => {}, 100, 1, 2, 3); + const id: number = timer.id; + timer.ref(); + timer.unref(); + clock.clearTimeout(timer); + } + { + const timer = clock.setInterval(() => {}, 1, 2, 3); + const id: number = timer.id; + timer.ref(); + timer.unref(); + clock.clearInterval(timer); + } + { + const timer = clock.setImmediate(() => {}, 1, 2, 3); + const id: number = timer.id; + timer.ref(); + timer.unref(); + clock.clearImmediate(timer); + } + clock.nextTick(() => {}, 1, 2, 3); + clock.updateHrTime(10); + const a: number = clock.tick(100); + const b: number = clock.next(); + const c: number = clock.runAll(); + const d: number = clock.runToLast(); + clock.setSystemTime(100); + const e: [number, number] = clock.hrtime(); + const f: [number, number] = clock.hrtime(e); + clock.uninstall(); + } + + namespace createClock { + util.fakeClock.createClock(); + util.fakeClock.createClock(0); + const clock = util.fakeClock.createClock(0, 100); + { + const timer = clock.setTimeout(() => {}, 100, 1, 2, 3); + const id: number = timer.id; + timer.ref(); + timer.unref(); + clock.clearTimeout(timer); + } + { + const timer = clock.setInterval(() => {}, 1, 2, 3); + const id: number = timer.id; + timer.ref(); + timer.unref(); + clock.clearInterval(timer); + } + { + const timer = clock.setImmediate(() => {}, 1, 2, 3); + const id: number = timer.id; + timer.ref(); + timer.unref(); + clock.clearImmediate(timer); + } + clock.nextTick(() => {}, 1, 2, 3); + clock.updateHrTime(10); + const a: number = clock.tick(100); + const b: number = clock.next(); + const c: number = clock.runAll(); + const d: number = clock.runToLast(); + clock.setSystemTime(100); + const e: [number, number] = clock.hrtime(); + const f: [number, number] = clock.hrtime(e); + } + + namespace ltgt { + namespace contains { + const a: boolean = util.ltgt.contains({ lt: 2 }, 2); + const b: boolean = util.ltgt.contains({ lt: 2 }, 2, (a, b) => b - a); + const c: boolean = util.ltgt.contains({ lt: "2" }, "2"); + const d: boolean = util.ltgt.contains({ lt: "2" }, "2", (a, b) => b.charCodeAt(0) - a.charCodeAt(0)); + } + + namespace filter { + const a: (a: number) => boolean = util.ltgt.filter({ lt: 2 }); + const b: (a: number) => boolean = util.ltgt.filter({ lt: 2 }, (a, b) => b - a); + const c: (a: string) => boolean = util.ltgt.filter({ lt: "2" }); + const d: (a: string) => boolean = util.ltgt.filter({ lt: "2" }, (a, b) => b.charCodeAt(0) - a.charCodeAt(0)); + } + + namespace toLtgt { + const a: adone.util.ltgt.I.Range = util.ltgt.toLtgt({ lt: 2 }, {}); + const b: adone.util.ltgt.I.Range = util.ltgt.toLtgt({ lt: 2 }, {}, (a) => `${a}`); + const c: adone.util.ltgt.I.Range = util.ltgt.toLtgt({ lt: 2 }, {}, (a) => a, 2); + const d: adone.util.ltgt.I.Range = util.ltgt.toLtgt({ lt: 2 }, {}, (a) => a, 2, 5); + } + + namespace endEnclusive { + const a: boolean = util.ltgt.endInclusive({ lt: 2 }); + } + + namespace startInclusive { + const a: boolean = util.ltgt.startInclusive({ lt: 2 }); + } + + namespace end { + const a: number | undefined = util.ltgt.end({ lt: 2 }); + const b: number | string = util.ltgt.end({ lt: 2 }, "2"); + const c: number = util.ltgt.end({ lt: 2 }, 2); + } + + namespace start { + const a: number | undefined = util.ltgt.start({ lt: 2 }); + const b: number | string = util.ltgt.start({ lt: 2 }, "2"); + const c: number = util.ltgt.start({ lt: 2 }, 2); + } + + namespace upperBound { + const a: number | undefined = util.ltgt.upperBound({ lt: 2 }); + const b: number | string = util.ltgt.upperBound({ lt: 2 }, "2"); + const c: number = util.ltgt.upperBound({ lt: 2 }, 2); + } + + namespace upperBoundKey { + const a: number | undefined = util.ltgt.upperBoundKey({ lt: 2 }); + } + + namespace upperBoundExclusive { + const a: boolean = util.ltgt.upperBoundInclusive({ lt: 2 }); + } + + namespace lowerBoundExclusive { + const a: boolean = util.ltgt.lowerBoundInclusive({ lt: 2 }); + } + + namespace upperBoundInclusive { + const a: boolean = util.ltgt.upperBoundInclusive({ lt: 2 }); + } + + namespace lowerBoundInclusive { + const a: boolean = util.ltgt.lowerBoundInclusive({ lt: 2 }); + } + + namespace lowerBound { + const a: number | undefined = util.ltgt.lowerBound({ lt: 2 }); + const b: number | string = util.ltgt.lowerBound({ lt: 2 }, "2"); + const c: number = util.ltgt.lowerBound({ lt: 2 }, 2); + } + } + } +} diff --git a/types/adone/test/index-import.ts b/types/adone/test/index-import.ts new file mode 100644 index 0000000000..906e57938c --- /dev/null +++ b/types/adone/test/index-import.ts @@ -0,0 +1,6 @@ +import adone from "adone"; + +namespace AdoneRootImportTests { + adone.falsely() === false; + adone.std.fs.createReadStream(__filename).close(); +} diff --git a/types/adone/test/index.ts b/types/adone/test/index.ts new file mode 100644 index 0000000000..7cc5034602 --- /dev/null +++ b/types/adone/test/index.ts @@ -0,0 +1,69 @@ +namespace AdoneRootTests { + { const a: symbol = adone.null; } + adone.noop(); + { const a: number = adone.identity(2); } + { const a: string = adone.identity("2"); } + { const a: number[] = adone.identity([1, 2]); } + { adone.truly() === true; } + { adone.falsely() === false; } + { const a: string = adone.ok; } + { const a: string = adone.bad; } + { const a: string[] = adone.exts; } + adone.log(); + adone.fatal(); + adone.error(); + adone.warn(); + adone.info(); + adone.debug(); + adone.trace(); + { const a: object = adone.o(); } + { const a: object = adone.o({}); } + { const a: typeof Date = adone.Date; } + { const a: typeof process.hrtime = adone.hrtime; } + { const a: typeof setTimeout = adone.setTimeout; } + { const a: typeof clearTimeout = adone.clearTimeout; } + { const a: typeof setInterval = adone.setInterval; } + { const a: typeof clearInterval = adone.clearInterval; } + { const a: typeof setImmediate = adone.setImmediate; } + { const a: typeof clearImmediate = adone.clearImmediate; } + adone.lazify({}); + adone.lazify({}, {}); + adone.lazify({}, {}, () => { }); + adone.lazify({}, {}, () => { }, { configurable: true }); + adone.tag.set({}, "123"); + adone.tag.has({}, "123") === true; + adone.tag.define("12"); + adone.tag.define("123", "456"); + { const a: symbol = adone.tag.SUBSYSTEM; } + { const a: symbol = adone.tag.APPLICATION; } + { const a: symbol = adone.tag.TRANSFORM; } + { const a: symbol = adone.tag.CORE_STREAM; } + { const a: symbol = adone.tag.LOGGER; } + { const a: symbol = adone.tag.LONG; } + { const a: symbol = adone.tag.BIGNUMBER; } + { const a: symbol = adone.tag.EXBUFFER; } + { const a: symbol = adone.tag.EXDATE; } + { const a: symbol = adone.tag.CONFIGURATION; } + { const a: symbol = adone.tag.GENESIS_NETRON; } + { const a: symbol = adone.tag.GENESIS_PEER; } + { const a: symbol = adone.tag.NETRON; } + { const a: symbol = adone.tag.NETRON_PEER; } + { const a: symbol = adone.tag.NETRON_ADAPTER; } + { const a: symbol = adone.tag.NETRON_DEFINITION; } + { const a: symbol = adone.tag.NETRON_DEFINITIONS; } + { const a: symbol = adone.tag.NETRON_REFERENCE; } + { const a: symbol = adone.tag.NETRON_INTERFACE; } + { const a: symbol = adone.tag.NETRON_STUB; } + { const a: symbol = adone.tag.NETRON_REMOTESTUB; } + { const a: symbol = adone.tag.NETRON_STREAM; } + { const a: symbol = adone.tag.FAST_STREAM; } + { const a: symbol = adone.tag.FAST_FS_STREAM; } + { const a: symbol = adone.tag.FAST_FS_MAP_STREAM; } + { const a: Promise = adone.run({}); } + { const a: Promise = adone.run({}, false); } + { const a: object = adone.bind("library"); } // hmm + { const a: string = adone.getAssetAbsolutePath("asset"); } + { const a: Buffer | string = adone.loadAsset("asset"); } + { const a: object = adone.require("path"); } + { const a: object = adone.package; } +} diff --git a/types/adone/tsconfig.json b/types/adone/tsconfig.json new file mode 100644 index 0000000000..6fe0c82586 --- /dev/null +++ b/types/adone/tsconfig.json @@ -0,0 +1,34 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2017", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "adone.d.ts", + "glosses/common.d.ts", + "glosses/math.d.ts", + "glosses/std.d.ts", + "glosses/utils.d.ts", + "adone-tests.ts", + "test/index.ts", + "test/index-import.ts", + "test/glosses/common.ts", + "test/glosses/math.ts", + "test/glosses/std.ts", + "test/glosses/utils.ts" + ] +} diff --git a/types/adone/tslint.json b/types/adone/tslint.json new file mode 100644 index 0000000000..5f7dd6afd7 --- /dev/null +++ b/types/adone/tslint.json @@ -0,0 +1,8 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-namespace": false, + "strict-export-declare-modifiers": false, + "no-single-declare-module": false + } +} \ No newline at end of file