From 94a0f73c85cbd95c8ac191fed8e5d07972e4a68f Mon Sep 17 00:00:00 2001 From: s0m3on3 Date: Wed, 7 Feb 2018 02:19:27 +0200 Subject: [PATCH] [adone] refactoring, additions * [collections] decomposition, add MapCache, NSCache, RefcountedCache, Set * [data] add protobuf, base32, basex, base58, base64url, varint, varintSigned * [is] improve function and asyncFunction, add emitter and asyncEmitter * add fake --- types/adone/glosses/collections.d.ts | 1965 ----------------- .../adone/glosses/collections/array_set.d.ts | 44 + .../glosses/collections/async_queue.d.ts | 12 + types/adone/glosses/collections/avl_tree.d.ts | 48 + .../collections/binary_search_tree.d.ts | 110 + .../glosses/collections/buffer_list.d.ts | 92 + .../adone/glosses/collections/byte_array.d.ts | 892 ++++++++ .../glosses/collections/default_map.d.ts | 9 + types/adone/glosses/collections/fast_lru.d.ts | 61 + types/adone/glosses/collections/index.d.ts | 28 + .../glosses/collections/linked_list.d.ts | 150 ++ types/adone/glosses/collections/lru.d.ts | 213 ++ .../adone/glosses/collections/map_cache.d.ts | 13 + types/adone/glosses/collections/ns_cache.d.ts | 17 + .../glosses/collections/priority_queue.d.ts | 78 + types/adone/glosses/collections/queue.d.ts | 31 + types/adone/glosses/collections/rb_tree.d.ts | 184 ++ .../glosses/collections/refcounted_cache.d.ts | 9 + types/adone/glosses/collections/set.d.ts | 17 + types/adone/glosses/collections/stack.d.ts | 36 + .../glosses/collections/timedout_map.d.ts | 32 + types/adone/glosses/data.d.ts | 178 ++ types/adone/glosses/fake.d.ts | 337 +++ types/adone/glosses/is.d.ts | 8 +- types/adone/index.d.ts | 3 +- types/adone/test/glosses/collections.ts | 1003 --------- .../test/glosses/collections/array_set.ts | 19 + .../test/glosses/collections/async_queue.ts | 12 + .../test/glosses/collections/avl_tree.ts | 28 + .../glosses/collections/binary_search_tree.ts | 36 + .../test/glosses/collections/buffer_list.ts | 42 + .../test/glosses/collections/byte_array.ts | 561 +++++ .../test/glosses/collections/default_map.ts | 14 + .../test/glosses/collections/fast_lru.ts | 21 + .../test/glosses/collections/linked_list.ts | 123 ++ types/adone/test/glosses/collections/lru.ts | 67 + .../test/glosses/collections/map_cache.ts | 21 + .../test/glosses/collections/ns_cache.ts | 21 + .../glosses/collections/priority_queue.ts | 36 + types/adone/test/glosses/collections/queue.ts | 17 + .../adone/test/glosses/collections/rb_tree.ts | 48 + .../glosses/collections/refcounted_cache.ts | 17 + types/adone/test/glosses/collections/set.ts | 26 + types/adone/test/glosses/collections/stack.ts | 16 + .../test/glosses/collections/timedout_map.ts | 22 + types/adone/test/glosses/data.ts | 273 +++ types/adone/test/glosses/fake.ts | 206 ++ types/adone/test/glosses/is.ts | 16 +- types/adone/tsconfig.json | 43 +- 49 files changed, 4280 insertions(+), 2975 deletions(-) delete mode 100644 types/adone/glosses/collections.d.ts create mode 100644 types/adone/glosses/collections/array_set.d.ts create mode 100644 types/adone/glosses/collections/async_queue.d.ts create mode 100644 types/adone/glosses/collections/avl_tree.d.ts create mode 100644 types/adone/glosses/collections/binary_search_tree.d.ts create mode 100644 types/adone/glosses/collections/buffer_list.d.ts create mode 100644 types/adone/glosses/collections/byte_array.d.ts create mode 100644 types/adone/glosses/collections/default_map.d.ts create mode 100644 types/adone/glosses/collections/fast_lru.d.ts create mode 100644 types/adone/glosses/collections/index.d.ts create mode 100644 types/adone/glosses/collections/linked_list.d.ts create mode 100644 types/adone/glosses/collections/lru.d.ts create mode 100644 types/adone/glosses/collections/map_cache.d.ts create mode 100644 types/adone/glosses/collections/ns_cache.d.ts create mode 100644 types/adone/glosses/collections/priority_queue.d.ts create mode 100644 types/adone/glosses/collections/queue.d.ts create mode 100644 types/adone/glosses/collections/rb_tree.d.ts create mode 100644 types/adone/glosses/collections/refcounted_cache.d.ts create mode 100644 types/adone/glosses/collections/set.d.ts create mode 100644 types/adone/glosses/collections/stack.d.ts create mode 100644 types/adone/glosses/collections/timedout_map.d.ts create mode 100644 types/adone/glosses/fake.d.ts delete mode 100644 types/adone/test/glosses/collections.ts create mode 100644 types/adone/test/glosses/collections/array_set.ts create mode 100644 types/adone/test/glosses/collections/async_queue.ts create mode 100644 types/adone/test/glosses/collections/avl_tree.ts create mode 100644 types/adone/test/glosses/collections/binary_search_tree.ts create mode 100644 types/adone/test/glosses/collections/buffer_list.ts create mode 100644 types/adone/test/glosses/collections/byte_array.ts create mode 100644 types/adone/test/glosses/collections/default_map.ts create mode 100644 types/adone/test/glosses/collections/fast_lru.ts create mode 100644 types/adone/test/glosses/collections/linked_list.ts create mode 100644 types/adone/test/glosses/collections/lru.ts create mode 100644 types/adone/test/glosses/collections/map_cache.ts create mode 100644 types/adone/test/glosses/collections/ns_cache.ts create mode 100644 types/adone/test/glosses/collections/priority_queue.ts create mode 100644 types/adone/test/glosses/collections/queue.ts create mode 100644 types/adone/test/glosses/collections/rb_tree.ts create mode 100644 types/adone/test/glosses/collections/refcounted_cache.ts create mode 100644 types/adone/test/glosses/collections/set.ts create mode 100644 types/adone/test/glosses/collections/stack.ts create mode 100644 types/adone/test/glosses/collections/timedout_map.ts create mode 100644 types/adone/test/glosses/fake.ts diff --git a/types/adone/glosses/collections.d.ts b/types/adone/glosses/collections.d.ts deleted file mode 100644 index 178921136d..0000000000 --- a/types/adone/glosses/collections.d.ts +++ /dev/null @@ -1,1965 +0,0 @@ -declare namespace adone { - namespace collection { - namespace I.LinkedList { - /** - * Represents the node of a linked list - */ - interface Node { - /** - * The next node - */ - next?: Node; - - /** - * The previous node - */ - prev?: Node; - - /** - * The value this node contains - */ - value: T; - } - } - - /** - * Represents a linked list - */ - class LinkedList { - /** - * The maximum length of the list - */ - readonly maxLength: number; - - /** - * Current length of the list - */ - readonly length: number; - - /** - * Whether the list is autoresizable - */ - readonly autoresize: boolean; - - /** - * @param maxLength Maximum length of the linked list - */ - constructor(maxLength?: number); - - /** - * Whether the list is full - */ - readonly full: boolean; - - /** - * Whether the list is empty - */ - readonly empty: boolean; - - /** - * Resizes the list - */ - resize(newLength: number): this; - - /** - * Adds a new node to the end - * - * @returns Added node - */ - push(value: T): I.LinkedList.Node; - - /** - * Removes the last node, returns undefined if the list is empty - */ - pop(): T | undefined; - - /** - * Removes the first node, returns undefined if the list is empty - */ - shift(): T | undefined; - - /** - * Inserts a new node at the beginning of the list - * - * @returns Added node - */ - unshift(value: T): I.LinkedList.Node; - - /** - * Moves the given node to the end of the list - */ - pushNode(node: I.LinkedList.Node): void; - - /** - * Moved the given node to the beginning of the list - */ - unshiftNode(node: I.LinkedList.Node): void; - - /** - * Removes the given node from the list - */ - removeNode(node: I.LinkedList.Node): void; - - /** - * Clears the list - * - * @param strong Whether to reset all the node's values - */ - clear(strong?: boolean): void; - - /** - * Convers the list to an array - */ - toArray(): T[]; - - /** - * The first element of the list - */ - readonly front: T; - - /** - * The last element of the list - */ - readonly back: T; - - /** - * Returns an iterator over the list elements - */ - [Symbol.iterator](): IterableIterator; - - /** - * Returns the next node for the given node - */ - nextNode(node: I.LinkedList.Node): I.LinkedList.Node; - - /** - * Maps this linked list to a new one using the given function - */ - map(fn: (value: T, index: number) => R): LinkedList; - - /** - * Invokes the given callback for each value from the beginning to the end (much faster than for-of). - * If the given function returns false it stops iterating. - */ - forEach(callback: (value: T, index: number) => void | boolean): void; - - /** - * Default length of a new created linked list - */ - static DEFAULT_LENGTH: number; - } - - namespace I { - type Long = math.Long; - - type Longable = math.I.Longable; - - namespace ByteArray { - interface Varint32 { - value: number; - length: number; - } - - interface Varint64 { - value: Long; - length: number; - } - - interface String { - string: string; - length: number; - } - - type Wrappable = string | ByteArray | Buffer | Uint8Array | ArrayBuffer; - - type Metrics = "b" | "c"; - } - } - - /** - * Represents an array of bytes, enhanced Node.js Buffer - */ - class ByteArray { - /** - * Constructs a new ByteArray - * - * @param capacity Initial capacity. Defaults to ByteArray.DEFAULT_CAPACITY(64) - * @param noAssert Whether to skip assertions of offsets and values. Defaults to ByteArray.DEFAULT_NOASSERT(false) - */ - constructor(capacity?: number, noAssert?: boolean); - - /** - * Reads a BitSet as an array of booleans. - * - * @param offset Offset to read from. Will use and increase offset by length if omitted. - */ - readBitSet(offset?: number): boolean[]; - - /** - * Reads the specified number of bytes. - * - * @param length Number of bytes to read - * @param offset Offset to read from. Will use and increase offset by length if omitted. - */ - read(length: number, offset?: number): ByteArray; - - /** - * Reads an 8bit signed integer - * - * @param offset Offset to read from - */ - readInt8(offset?: number): number; - - /** - * Reads an 8bit unsigned integer - * - * @param offset Offset to read from - */ - readUInt8(offset?: number): number; - - /** - * Reads a 16bit signed le integer - * - * @param offset Offset to read from - */ - readInt16LE(offset?: number): number; - - /** - * Reads a 16bit unsigned le integer - * - * @param offset Offset to read from - */ - readUInt16LE(offset?: number): number; - - /** - * Reads a 16bit signed be integer - * - * @param offset Offset to read from - */ - readInt16BE(offset?: number): number; - - /** - * Reads a 16bit unsigned be integer - * - * @param offset Offset to read from - */ - readUInt16BE(offset?: number): number; - - /** - * Reads a 32bit signed le integer - * - * @param offset Offset to read from - */ - readInt32LE(offset?: number): number; - - /** - * Reads a 32bit unsigned le integer - * - * @param offset Offset to read from - */ - readUInt32LE(offset?: number): number; - - /** - * Reads a 32bit signed be integer - * - * @param offset Offset to read from - */ - readInt32BE(offset?: number): number; - - /** - * Reads a 32bit unsigned be integer - * - * @param offset Offset to read from - */ - readUInt32BE(offset?: number): number; - - /** - * Reads a 64bit signed le integer as math.Long - * - * @param offset Offset to read from - */ - readInt64LE(offset?: number): math.Long; - - /** - * Reads a 64bit unsigned le integer as math.Long - * - * @param offset Offset to read from - */ - readUInt64LE(offset?: number): math.Long; - - /** - * Reads a 64bit signed be integer as math.Long - * - * @param offset Offset to read from - */ - readInt64BE(offset?: number): math.Long; - - /** - * Reads a 64bit unsigned be integer as math.Long - * - * @param offset Offset to read from - */ - readUInt64BE(offset?: number): math.Long; - - /** - * Reads a 32bit le float - * - * @param offset Offset to read from - */ - readFloatLE(offset?: number): number; - - /** - * Reads a 32bit be float - * - * @param offset Offset to read from - */ - readFloatBE(offset?: number): number; - - /** - * Reads a 64bit le float - * - * @param offset Offset to read from - */ - readDoubleLE(offset?: number): number; - - /** - * Reads a 64bit be float - * - * @param offset Offset to read from - */ - readDoubleBE(offset?: number): number; - - /** - * Appends some data to this ByteArray. - * This will overwrite any contents behind the specified offset up to the appended data's length. - * - * @param source The source write from - * @param offset Offset to write to - * @param length length to read from the source - * @param encoding encoding to use for wrapping the source in bytearray - */ - write(source: I.ByteArray.Wrappable, offset?: number, length?: number, encoding?: string): this; - - /** - * Writes the array as a bitset. - * @param value Array of booleans to write - */ - writeBitSet(value: number[]): this; - - /** - * Writes the array as a bitset. - * @param value Array of booleans to write - * @param offset Offset to write to - */ - writeBitSet(value: number[], offset: number): number; - - /** - * Writes an 8bit signed integer - * - * @param offset Offset to write to - */ - writeInt8(value: number, offset?: number): this; - - /** - * Writes an 8bit unsigned integer - * - * @param offset Offset to write to - */ - writeUInt8(value: number, offset?: number): this; - - /** - * Writes a 16bit signed le integer - * - * @param offset Offset to write to - */ - writeInt16LE(value: number, offset?: number): this; - - /** - * Writes a 16bit signed be integer - * - * @param offset Offset to write to - */ - writeInt16BE(value: number, offset?: number): this; - - /** - * Writes a 16bit unsigned le integer - * - * @param offset Offset to write to - */ - writeUInt16LE(value: number, offset?: number): this; - - /** - * Writes a 16bit unsigned be integer - * - * @param offset Offset to write to - */ - writeUInt16BE(value: number, offset?: number): this; - - /** - * Writes a 32bit signed le integer - * - * @param offset Offset to write to - */ - writeInt32LE(value: number, offset?: number): this; - - /** - * Writes a 32bit signed be integer - * - * @param offset Offset to write to - */ - writeInt32BE(value: number, offset?: number): this; - - /** - * Writes a 32bit unsigned le integer - * - * @param offset Offset to write to - */ - writeUInt32LE(value: number, offset?: number): this; - - /** - * Writes a 32bit unsigned be integer - * - * @param offset Offset to write to - */ - writeUInt32BE(value: number, offset?: number): this; - - /** - * Writes a 64bit signed le long integer - * - * @param offset Offset to write to - */ - writeInt64LE(value: math.Long | string | number, offset?: number): this; - - /** - * Writes a 64bit signed be long integer - * - * @param offset Offset to write to - */ - writeInt64BE(value: math.Long | string | number, offset?: number): this; - - /** - * Writes a 64bit unsigned le long integer - * - * @param offset Offset to write to - */ - writeUInt64LE(value: math.Long | string | number, offset?: number): this; - - /** - * Writes a 64bit unsigned be long integer - * - * @param offset Offset to write to - */ - writeUInt64BE(value: math.Long | string | number, offset?: number): this; - - /** - * Writes a 32bit le float - * - * @param offset Offset to write to - */ - writeFloatLE(value: number, offset?: number): this; - - /** - * Writes a 32bit be float - * - * @param offset Offset to write to - */ - writeFloatBE(value: number, offset?: number): this; - - /** - * Writes a 64bit le float - * - * @param offset Offset to write to - */ - writeDoubleLE(value: number, offset?: number): this; - - /** - * Writes a 64bit be float - * - * @param offset Offset to write to - */ - writeDoubleBE(value: number, offset?: number): this; - - /** - * Writes a 32bit base 128 variable-length integer - */ - writeVarint32(value: number): this; - - /** - * Writes a 32bit base 128 variable-length integer - * - * @param offset Offset to write to - */ - writeVarint32(value: number, offset: number): number; - - /** - * Writes a zig-zag encoded 32bit base 128 variable-length integer - */ - writeVarint32ZigZag(value: number): this; - - /** - * Writes a zig-zag encoded 32bit base 128 variable-length integer - * - * @param offset Offset to write to - */ - writeVarint32ZigZag(value: number, offset: number): number; - - /** - * Reads a 32bit base 128 variable-length integer - */ - readVarint32(): number; - - /** - * Reads a 32bit base 128 variable-length integer - * - * @param offset Offset to read from - */ - readVarint32(offset: number): I.ByteArray.Varint32; - - /** - * Reads a zig-zag encoded 32bit base 128 variable-length integer - */ - readVarint32ZigZag(): number; - - /** - * Reads a zig-zag encoded 32bit base 128 variable-length integer - * - * @param offset Offset to read from - */ - readVarint32ZigZag(offset: number): I.ByteArray.Varint32; - - /** - * Writes a 64bit base 128 variable-length integer - */ - writeVarint64(value: math.Long | string | number): this; - - /** - * Writes a 64bit base 128 variable-length integer - * - * @param offset Offset to write to - */ - writeVarint64(value: math.Long | string | number, offset: number): number; - - /** - * Writes a zig-zag encoded 64bit base 128 variable-length integer - */ - writeVarint64ZigZag(value: math.Long | string | number): this; - - /** - * Writes a zig-zag encoded 64bit base 128 variable-length integer - * - * @param offset Offset to write to - */ - writeVarint64ZigZag(value: math.Long | string | number, offset: number): number; - - /** - * Reads a 64bit base 128 variable-length integer - */ - readVarint64(): I.Long; - - /** - * Reads a 64bit base 128 variable-length integer - * - * @param offset Offset to read from - */ - readVarint64(offset: number): I.ByteArray.Varint64; - - /** - * Reads a zig-zag encoded 64bit base 128 variable-length integer - */ - readVarint64ZigZag(): math.Long; - - /** - * Reads a zig-zag encoded 64bit base 128 variable-length integer - * - * @param offset Offset to read from - */ - readVarint64ZigZag(offset: number): I.ByteArray.Varint64; - - /** - * Writes a NULL-terminated UTF8 encoded string. - * For this to work the specified string must not contain any NULL characters itself - */ - writeCString(str: string): this; - - /** - * Writes a NULL-terminated UTF8 encoded string. - * For this to work the specified string must not contain any NULL characters itself - * - * @param offset Offset to write to - */ - writeCString(str: string, offset: number): number; - - /** - * Reads a NULL-terminated UTF8 encoded string. - * For this to work the string read must not contain any NULL characters itself - */ - readCString(): string; - - /** - * Reads a NULL-terminated UTF8 encoded string. - * For this to work the string read must not contain any NULL characters itself - * - * @param offset Offset to read from - */ - readCString(offset: number): I.ByteArray.String; - - /** - * Writes an UTF8 encoded string - */ - writeString(str: string): this; - - /** - * Writes an UTF8 encoded string - * - * @param offset Offset to write to - */ - writeString(str: string, offset: number): number; - - /** - * Reads an UTF8 encoded string - * - * @param length Number of characters or bytes to read - * @param metrics Metrics specifying what n is meant to count. Defaults to ByteArray.METRICS_CHARS("c") - */ - readString(length: number, metrics?: I.ByteArray.Metrics): string; - - /** - * Reads an UTF8 encoded string - * - * @param length Number of characters or bytes to read - * @param metrics Metrics specifying what n is meant to count. Defaults to ByteArray.METRICS_CHARS("c") - * @param offset Offset to read from - */ - readString(length: number, metrics: I.ByteArray.Metrics, offset: number): I.ByteArray.String; - - /** - * Reads an UTF8 encoded string - * - * @param length Number of characters or bytes to read - * @param offset Offset to read from - */ - readString(length: number, offset: number): I.ByteArray.String; - - /** - * Writes a length as varint32 prefixed UTF8 encoded string - */ - writeVString(str: string): this; - - /** - * Writes a length as varint32 prefixed UTF8 encoded string - * - * @param offset Offset to read from - */ - writeVString(str: string, offset: number): number; - - /** - * Reads a length as varint32 prefixed UTF8 encoded string - */ - readVString(): string; - - /** - * Reads a length as varint32 prefixed UTF8 encoded string - * - * @param offset Offset to read from - */ - readVString(offset: number): I.ByteArray.String; - - /** - * Appends this ByteArray's contents to another ByteArray. - * This will overwrite any contents behind the specified offset up to the length of this ByteArray's data - * - * @param offset Offset to append to - */ - appendTo(target: ByteArray, offset?: number): this; - - /** - * Enables or disables assertions of argument types and offsets. - * Assertions are enabled by default but you can opt to disable them if your code already makes sure that everything is valid - */ - assert(assert?: boolean): this; - - /** - * Gets the capacity of this ByteArray's backing buffer - */ - capacity(): number; - - /** - * Clears this ByteArray's offsets by setting offset to 0 and limit to the backing buffer's capacity - */ - clear(): this; - - /** - * Creates a cloned instance of this ByteArray, - * preset with this ByteArray's values for offset, markedOffset and limit - * - * @param copy Whether to copy the backing buffer or to return another view on the same, false by default - */ - clone(copy?: boolean): ByteArray; - - /** - * Compacts this ByteArray to be backed by a buffer of its contents' length. - * Will set offset = 0 and limit = capacity and adapt markedOffset to the same relative position if set - * - * @param begin Offset to start at, buffer offset by default - * @param end Offset to end at, buffer limit by default - */ - compact(begin?: number, end?: number): this; - - /** - * Creates a copy of this ByteArray's contents. - * - * @param begin Begin offset, buffer offset by default - * @param end End offset, buffer limit by default - */ - copy(begin?: number, end?: number): ByteArray; - - /** - * Copies this ByteArray's contents to another ByteArray. - * - * @param targetOffset Offset to copy to. Will use and increase the target's offset by the number of bytes copied if omitted - * @param sourceOffset Offset to start copying from. Will use and increase offset by the number of bytes copied if omitted - * @param sourceLimit Offset to end copying from, defaults to the buffer limit - */ - copyTo(target: ByteArray, targetOffset?: number, souceOffset?: number, sourceLimit?: number): this | ByteArray; - - /** - * Makes sure that this ByteArray is backed by a ByteArray#buffer of at least the specified capacity. - * If the current capacity is exceeded, it will be doubled. - * If double the current capacity is less than the required capacity, the required capacity will be used instead - */ - ensureCapacity(capacity: number): this; - - /** - * Overwrites this ByteArray's contents with the specified value. - * - * @param value Byte value to fill with. If given as a string, the first character is used - * @param begin Begin offset. Will use and increase offset by the number of bytes written if omitted. defaults to offset - * @param end End offset, defaults to limit. - */ - fill(value: string | number, begin?: number, end?: number): this; - - /** - * Makes this ByteArray ready for a new sequence of write or relative read operations. - * Sets limit = offset and offset = 0. - * Make sure always to flip a ByteArray when all relative read or write operations are complete - */ - flip(): this; - - /** - * Marks an offset on this ByteArray to be used later - * - * @param offset Offset to mark. Defaults to offset. - */ - mark(offset?: number): this; - - /** - * Prepends some data to this ByteArray. - * This will overwrite any contents before the specified offset up to the prepended data's length. - * If there is not enough space available before the specified offset, - * the backing buffer will be resized and its contents moved accordingly - * - * @param source Data to prepend - * @param offset Offset to prepend at. Will use and decrease offset by the number of bytes prepended if omitted. - */ - prepend(source: I.ByteArray.Wrappable, offset: number): this; - - /** - * Prepends some data to this ByteArray. - * This will overwrite any contents before the specified offset up to the prepended data's length. - * If there is not enough space available before the specified offset, - * the backing buffer will be resized and its contents moved accordingly - * - * @param source Data to prepend - * @param encoding Encoding if data is a string - * @param offset Offset to prepend at. Will use and decrease offset by the number of bytes prepended if omitted. - */ - prepend(source: I.ByteArray.Wrappable, encoding?: string, offset?: number): this; - - /** - * Prepends this ByteArray to another ByteArray. - * This will overwrite any contents before the specified offset up to the prepended data's length. - * If there is not enough space available before the specified offset, - * the backing buffer will be resized and its contents moved accordingly - * - * @param offset Offset to prepend at - */ - prependTo(target: ByteArray, offset?: number): this; - - /** - * Gets the number of remaining readable bytes - */ - remaining(): number; - - /** - * Resets this ByteArray's offset. - * If an offset has been marked through mark before, offset will be set to markedOffset, which will then be discarded. - * If no offset has been marked, sets offset = 0 - */ - reset(): this; - - /** - * Resizes this ByteArray to be backed by a buffer of at least the given capacity. - * Will do nothing if already that large or larger. - * - * @param capacity Capacity required - */ - resize(capacity: number): this; - - /** - * Reverses this ByteArray's contents. - * - * @param begin Offset to start at, defaults to offset - * @param end Offset to end at, defaults to limit - */ - reverse(begin?: number, end?: number): this; - - /** - * Skips the next length bytes. This will just advance - */ - skip(length: number): this; - - /** - * Slices this ByteArray by creating a cloned instance with offset = begin and limit = end - * - * @param begin Begin offset, defaults to offset - * @param end End offset, defaults to limit - */ - slice(begin?: number, end?: number): ByteArray; - - /** - * Returns a copy of the backing buffer that contains this ByteArray's contents. - * - * @param forceCopy If true returns a copy, otherwise returns a view referencing the same memory if possible, false by default - * @param begin Begin offset, offset by default - * @param end End offset, limit by default - */ - toBuffer(forceCopy?: boolean, begin?: number, end?: number): Buffer; - - /** - * Returns a raw buffer compacted to contain this ByteArray's contents - */ - toArrayBuffer(): ArrayBuffer; - - /** - * Converts the ByteArray's contents to a string - * - * @param encoding Output encoding - * @param begin Begin offset, offset by default - * @param end End offset, limit by default - */ - toString(encoding?: string, begin?: number, end?: number): string; - - /** - * Encodes this ByteArray's contents to a base64 encoded string - * - * @param begin Begin offset, offset by default - * @param end End offset, limit by default - */ - toBase64(begin?: number, end?: number): string; - - /** - * Encodes this ByteArray to a binary encoded string, that is using only characters 0x00-0xFF as bytes - * - * @param begin Begin offset, offset by default - * @param end End offset, limit by default - */ - toBinary(begin?: number, end?: number): string; - - /** - * Encodes this ByteArray to a hex encoded string with marked offsets - * - * @param columns If true returns two columns hex + ascii, defaults to false - */ - toDebug(columns?: boolean): string; - - /** - * Encodes this ByteArray's contents to a hex encoded string - * - * @param begin Begin offset, offset by default - * @param end End offset, limit by default - */ - toHex(begin?: number, end?: number): string; - - /** - * Encodes this ByteArray's contents to an UTF8 encoded string - * - * @param begin Begin offset, offset by default - * @param end End offset, limit by default - */ - toUTF8(begin?: number, end?: number): string; - - static accessor(): typeof Buffer; - - /** - * Allocates a new ByteArray backed by a buffer of the specified capacity. - * - * @param capacity Initial capacity. Defaults to ByteArray.DEFAULT_CAPACITY(64) - * @param noAssert Whether to skip assertions of offsets and values. Defaults to ByteArray.DEFAULT_NOASSERT(false) - */ - static allocate(capacity?: number, noAssert?: boolean): ByteArray; - - /** - * Concatenates multiple ByteArrays into one - * - * @param encoding Encoding for strings - * @param noAssert Whether to skip assertions of offsets and values. Defaults to ByteArray.DEFAULT_NOASSERT(false) - */ - static concat(buffers: I.ByteArray.Wrappable[], encoding?: string, noAssert?: boolean): ByteArray; - - static type(): typeof Buffer; - - /** - * Wraps a buffer or a string. - * Sets the allocated ByteArray's offset to 0 and its limit to the length of the wrapped data - * - * @param encoding Encoding for strings - * @param noAssert Whether to skip assertions of offsets and values. Defaults to ByteArray.DEFAULT_NOASSERT(false) - */ - static wrap(buffer: I.ByteArray.Wrappable, encoding?: string, noAssert?: boolean): ByteArray; - - /** - * Calculates the actual number of bytes required to store a 32bit base 128 variable-length integer - */ - static calculateVarint32(value: number): number; - - /** - * Zigzag encodes a signed 32bit integer so that it can be effectively used with varint encoding - */ - static zigZagEncode32(n: number): number; - - /** - * Decodes a zigzag encoded signed 32bit integer - */ - static zigZagDecode32(n: number): number; - - /** - * Calculates the actual number of bytes required to store a 64bit base 128 variable-length integer - */ - static calculateVarint64(value: number | string): number; - - /** - * Zigzag encodes a signed 64bit integer so that it can be effectively used with varint encoding - */ - static zigZagEncode64(value: number | string | I.Long): I.Long; - - /** - * Decodes a zigzag encoded signed 64bit integer. - */ - static zigZagDecode64(value: number | string | I.Long): I.Long; - - /** - * Calculates the number of UTF8 characters of a string. - * JavaScript itself uses UTF-16, - * so that a string's length property does not reflect its actual UTF8 size if it contains code points larger than 0xFFFF - */ - static calculateUTF8Chars(str: string): number; - - /** - * Calculates the number of UTF8 bytes of a string. - */ - static calculateString(str: string): number; - - /** - * Decodes a base64 encoded string to a ByteArray - */ - static fromBase64(str: string): ByteArray; - - /** - * Encodes a binary string to base64 like window.btoa does - */ - static btoa(str: string): string; - - /** - * Decodes a base64 encoded string to binary like window.atob does - */ - static atob(b64: string): string; - - /** - * Decodes a binary encoded string, that is using only characters 0x00-0xFF as bytes, to a ByteArray - */ - static fromBinary(str: string): ByteArray; - - /** - * Decodes a hex encoded string with marked offsets to a ByteArray - */ - static fromDebug(str: string, noAssert?: boolean): ByteArray; - - /** - * Decodes a hex encoded string to a ByteArray - */ - static fromHex(str: string, noAssert?: boolean): ByteArray; - - /** - * Decodes an UTF8 encoded string to a ByteArray - */ - static fromUTF8(str: string, noAssert?: boolean): ByteArray; - - /** - * Default initial capacity - */ - static DEFAULT_CAPACITY: number; - - /** - * Default no assertions flag - */ - static DEFAULT_NOASSERT: boolean; - - /** - * Maximum number of bytes required to store a 32bit base 128 variable-length integer - */ - static MAX_VARINT32_BYTES: number; - - /** - * Maximum number of bytes required to store a 64bit base 128 variable-length integer - */ - static MAX_VARINT64_BYTES: number; - - /** - * Metrics representing number of UTF8 characters. Evaluates to `c`. - */ - static METRICS_CHARS: string; - - /** - * Metrics representing number of bytes. Evaluates to `b`. - */ - static METRICS_BYTES: string; - } - - /** - * Represents a queue - */ - class Queue { - /** - * Whether the queue is full - */ - readonly full: boolean; - - /** - * The length of the queue - */ - readonly length: number; - - /** - * Whether the queue is empty - */ - readonly empty: boolean; - - /** - * Inserts a new element at the end - */ - push(x: S): this; - - /** - * Removes and returns an element from the beginning - */ - pop(): T | undefined; - } - - /** - * Represents an asynchronous queue, each pop is a promise - * that is resolved with an existing element or an element that will be pushed in the future - */ - class AsyncQueue extends Queue> { - /** - * Returns a promise that will be resolved with an existing element or an element that will be pushed in the future - */ - pop(): Promise; - } - - namespace I.PriorityQueue { - interface ConstructorOptions { - /** - * Function that compares objects. - * - * Must return a positive value if a > b, a negative if a < b, and zero for equal objects - */ - compare?(a: T, b: T): number; - - /** - * Function that evaluates the priority value by the given objects, - * if the returned value > 0, then the first argument has higher priority, - * = 0 same priority, < 0 lower priority. - * By default the top element is an element that has the highest priority, - * the default priority function is equal to the compare function - */ - priority?(a: T, b: T): number; - } - } - - /** - * Represents a priority queue - */ - class PriorityQueue { - /** - * Whether the queue is empty - */ - readonly empty: boolean; - - /** - * The length of the queue - */ - readonly length: number; - - constructor(options?: I.PriorityQueue.ConstructorOptions); - - /** - * Clones the queue - */ - clone(): PriorityQueue; - - /** - * Inserts a new element - */ - push(x: T): this; - - /** - * Removes the top element (that has the highest priority) - */ - pop(): T | undefined; - - /** - * Deletes the given element from the queue - */ - delete(x: T): this; - - /** - * Replaces the top element (pop + push) - */ - replace(x: T): T; - - /** - * Faster push + pop - */ - pushpop(x: T): T; - - /** - * Converts the queue to an array, it works with a clone of the queue, so the original queue is untouched - */ - toArray(): T[]; - - /** - * Creates a queue object from the given iterable - */ - static from(iterable: Iterable, options?: I.PriorityQueue.ConstructorOptions): PriorityQueue; - } - - /** - * Represents a faster LRU cache but with less functionality - */ - class FastLRU { - /** - * @param size Cache size, unlimited by default - */ - constructor(size?: number, options?: { - /** - * Function that is called when a value is deleted - */ - dispose?(key: K, value: V): void - }); - - /** - * The actual size of the cache - */ - readonly size: number; - - /** - * Gets the value by the given key - */ - get(key: K): V | undefined; - - /** - * Sets a new value for the given key - */ - set(key: K, value: V): void; - - /** - * Deletes the given key from the cache - */ - delete(key: K): boolean; - - /** - * Checks whether the cache has an element with the given key - */ - has(key: K): boolean; - - /** - * Returns the keys iterator - */ - keys(): IterableIterator; - - /** - * Returns the values iterator - */ - values(): IterableIterator; - - /** - * Returns the entries iterator - */ - entries(): IterableIterator<[K, V]>; - - /** - * Clears the cache - */ - clear(): void; - } - - /** - * Represents a stack - */ - class Stack { - /** - * Whether the stack is empty - */ - readonly empty: boolean; - - /** - * The top element of the stack - */ - readonly top: T; - - /** - * Inserts a new element - */ - push(x: T): this; - - /** - * Removes the top element - */ - pop(): T | undefined; - - /** - * Returns an iterator over the values - */ - [Symbol.iterator](): IterableIterator; - - /** - * Creates a stack and pushed all the values from the given iterable object - */ - static from(iterable: Iterable): Stack; - } - - namespace I.BinarySearchTree { - interface ConstructorOptions { - /** - * The parent tree - */ - parent?: Tree; - - /** - * Value to keep in this node - */ - value?: V; - - /** - * WHether the values must be unique, false by default. - * If false you can store many values for same keys, otherwise only one - */ - unique?: boolean; - - /** - * Custom keys comparator, by default if a > b => -1, a < b -1, a === b => 0 - */ - compareKeys?(a: K, b: K): number; - - /** - * Function that defines whether 2 values are the same, by default a === b - */ - checkValueEquality?(a: V, b: V): boolean; - } - - interface Query { - $lt?: K; - $lte?: K; - $gt?: K; - $gte?: K; - } - } - - /** - * Represents a binary search tree - */ - class BinarySearchTree { - constructor(options?: I.BinarySearchTree.ConstructorOptions>); - - /** - * Returns the max descendant tree - */ - getMaxKeyDescendant(): BinarySearchTree; - - /** - * Returns the maximum key - */ - getMaxKey(): K; - - /** - * Returns the min descendant tree - */ - getMinKeyDescendant(): BinarySearchTree; - - /** - * Returns the minumum key - */ - getMinKey(): K; - - /** - * Traverses the tree and calls the given function for each node - */ - checkAllNodesFullfillCondition(test: (key: K, value: V) => void): void; - - /** - * Checks whether the tree is a binary search tree - */ - checkIsBST(): void; - - /** - * Returns the of keys in the tree - */ - getNumberOfKeys(): number; - - /** - * Inserts a new key/value - */ - insert(key: K, value: V): void; - - /** - * Searches the given key in the tree - */ - search(key: K): V[]; - - /** - * Returns all the values from the given key bounds - */ - betweenBounds(query: I.BinarySearchTree.Query): V[]; - - /** - * Deletes the given key/value from the tree - */ - delete(key: K, value?: V): void; - - /** - * Executed the given callback for each node from left to right - */ - executeOnEveryNode(fn: (tree: BinarySearchTree) => void): void; - - /** - * Prints the tree - */ - prettyPrint(printData?: boolean, spacing?: string): void; - } - - /** - * Represents an AVL tree, a self-balancing binary search tree - */ - class AVLTree { - constructor(options?: I.BinarySearchTree.ConstructorOptions>); - - /** - * Checks whether the tree is an avl tree - */ - checkIsAVLT(): void; - - /** - * Inserts a new key/value - */ - insert(key: K, value: V): void; - - /** - * Deletes the given key/value from the tree - */ - delete(key: K, value?: V): void; - - /** - * Returns the of keys in the tree - */ - getNumberOFKeys(): number; - - /** - * Searches the given key in the tree - */ - search(key: K): V[]; - - /** - * Returns all the values from the given key bounds - */ - betweenBounds(query: I.BinarySearchTree.Query): V[]; - - /** - * Executed the given callback for each node from left to right - */ - executeOnEveryNode(fn: (tree: AVLTree) => void): void; - - /** - * Prints the tree - */ - prettyPrint(printDate?: boolean, spacing?: string): void; - } - - namespace I.RedBlackTree { - interface Node { - /** - * The key associated to the node - */ - key: K; - - /** - * The value associated to the node - */ - value: V; - - /** - * The left subtree of the node - */ - left?: Node; - - /** - * The right subtree of the node - */ - right?: Node; - } - - interface Iterator { - /** - * Checks if the iterator is valid - */ - readonly valid: boolean; - - /** - * The value of the node at the iterator's current position, null if invalid - */ - readonly node: Node | null; - - /** - * The key of the item referenced by the iterator, undefined if invalid - */ - readonly key?: K; - - /** - * The value of the item referenced by the iterator, undefined if invalid - */ - readonly value?: V; - - /** - * Returns the position of this iterator in the sequence - */ - readonly index: number; - - /** - * If true, then the iterator is not at the end of the sequence - */ - readonly hasNext: boolean; - - /** - * If true, then the iterator is not at the beginning of the sequence - */ - readonly hasPrev: boolean; - - /** - * The tree associated to the iterator - */ - tree: RedBlackTree; - - /** - * Makes a copy of the iterator - */ - clone(): Iterator; - - /** - * Removes the item at the position of the iterator and returns a new rb-tree - */ - remove(): RedBlackTree; - - /** - * Advances the iterator to the next position - */ - next(): void; - - /** - * Updates the value of the node in the tree at this iterator and returns a new rb-tree - */ - update(value: V): RedBlackTree; - - /** - * Moves the iterator backward one element - */ - prev(): void; - } - } - - /** - * Represents a fully persistent red-black tree - */ - class RedBlackTree { - /** - * The root node of the tree - */ - root: I.RedBlackTree.Node; - - constructor(compare?: (a: K, b: K) => number, root?: RedBlackTree); - - /** - * A sorted array of all the keys in the tree - */ - readonly keys: K[]; - - /** - * An array of all the values in the tree - */ - readonly values: V[]; - - /** - * The number of items in the tree - */ - readonly length: number; - - /** - * An iterator pointing to the first element in the tree - */ - readonly begin: I.RedBlackTree.Iterator; - - /** - * An iterator pointing to the last element in the tree - */ - readonly end: I.RedBlackTree.Iterator; - - /** - * Creates a new tree with the new pair inserted - */ - insert(key: K, value: V): RedBlackTree; - - /** - * Walks a visitor function over the nodes of the tree in order - * - * @param visit A callback that gets executed on each node. - * If a truthy value is returned from the visitor, then iteration is stopped. - * @param lo An optional start of the range to visit (inclusive) - * @param hi An optional end of the range to visit (non-inclusive) - */ - forEach(visit: (key: K, value: V) => T, lo?: K, hi?: K): T; - - /** - * Finds an iterator starting at the given element - */ - at(idx: number): I.RedBlackTree.Iterator; - - /** - * Finds the first item in the tree whose key is >= key - */ - ge(key: K): I.RedBlackTree.Iterator; - - /** - * Finds the first item in the tree whose key is > key - */ - gt(key: K): I.RedBlackTree.Iterator; - - /** - * Finds the first item in the tree whose key is < key - */ - lt(key: K): I.RedBlackTree.Iterator; - - /** - * Finds the first item in the tree whose key is <= key - */ - le(key: K): I.RedBlackTree.Iterator; - - /** - * Returns an iterator pointing to the first item in the tree with key, otherwise null - */ - find(key: K): I.RedBlackTree.Iterator | null; - - /** - * Removes the first item with key in the tree - */ - remove(key: K): RedBlackTree; - - /** - * Retrieves the value associated to the given key - */ - get(key: K): V | undefined; - } - - /** - * Respresetns a data structure which is a combination of an array and a set. - * Adding a new member is O(1), testing for membership is O(1), - * and finding the index of an element is O(1). - */ - class ArraySet { - /** - * The number of unique items in this ArraySet. - * If duplicates have been added, than those do not count towards the size. - */ - readonly length: number; - - /** - * Adds the given value to this set. - * - * @param allowDuplicates Whether to allow duplicates in the set, false by default - */ - add(value: T, allowDuplicates?: boolean): this; - - /** - * Checks whether the given value is a member of the set - */ - has(value: T): boolean; - - /** - * Returns the index of the given element. - * If the value is not present it will return -1 - */ - indexOf(value: T): number; - - /** - * Converts the set to an array - */ - toArray(): T[]; - - /** - * Creates an ArraySet from the given iterable object - * - * @param allowDuplicates Whether to allow duplicates in the set, false by default - */ - static from(iterable: Iterable, allowDuplicates?: boolean): ArraySet; - } - - namespace I.BufferList { - type Appendable = Buffer | BufferList | string | number | Array; - } - - /** - * Represents a Node.js Buffer list collector, reader and streamer with callback/promise interface support - */ - class BufferList extends std.stream.Duplex implements PromiseLike { - /** - * Creates a new buffer list - */ - constructor(); - - /** - * Creates a new buffer list and initiates with the given value - */ - constructor(buffer: I.BufferList.Appendable); - - /** - * Creates a new buffer list and subscribes the given callback on the end/error event - */ - constructor(callback: (err: any, data: Buffer) => void); - - /** - * Adds an additional buffer or BufferList to the internal list - */ - append(buf: I.BufferList.Appendable): this; - - /** - * Ends the stream - */ - end(chunk?: Buffer): void; - end(chunk?: () => void): void; - - /** - * Returns the byte at the specified index - */ - get(idx: number): number; - - /** - * Returns a new Buffer object containing the bytes within the range specified. - */ - slice(start?: number, end?: number): Buffer; - - /** - * Copies the content of the list in the dest buffer - * starting from destStart and containing the bytes within the range specified with srcStart to srcEnd - * - * @param dstStart writes from this position - * @param srcStart reads bytes from this position - * @param srcEnd read bytes to this position - */ - copy(dst: T, dstStart?: number, srcStart?: number, srcEnd?: number): T; - - /** - * Returns a new BufferList object containing the bytes within the range specified. - * No copies will be performed. All buffers in the result share memory with the original list. - * - * @param start slice from - * @param end slice to - */ - shallowSlice(start?: number, end?: number): BufferList; - - /** - * Return a string representation of the buffer - */ - toString(encoding?: fs.I.Encoding, start?: number, end?: number): string; - - /** - * Shifts bytes off the start of the list - */ - consume(bytes: number): this; - - /** - * Performs a shallow-copy of the list. - */ - duplicate(): BufferList; - - /** - * Destroys the stream - */ - destroy(): void; - - then( - onfulfilled?: ((value: Buffer) => T1 | PromiseLike) | null, - onrejected?: ((reason: any) => T2 | PromiseLike) | null - ): PromiseLike; - - catch(onrejected?: ((reason: any) => T | PromiseLike) | null): PromiseLike; - } - - /** - * Represents a Map that has a default values factory object or function. - * Each get of non-existent key goes through the factory - */ - class DefaultMap extends Map { - constructor(factory?: ((key: K) => V) | { [key: string]: V }, iterable?: Iterable<[K, V]>); - } - - namespace I.LRU { - type LengthCalculator = (value: V, key: K) => number; - interface ConstructorOptions { - /** - * The maximum size of the cache, checked by applying the length function to all values in the cache. - * Default is Infinity - */ - max?: number; - - /** - * Maximum age in ms. Items are not pro-actively pruned out as they age, - * but if you try to get an item that is too old, - * it'll drop it and return undefined instead of giving it to you - */ - maxAge?: number; - - /** - * Function that is used to calculate the length of stored items - */ - length?: LengthCalculator; - - /** - * Function that is called on items when they are dropped from the cache - */ - dispose?(key: K, value: V): void; - - /** - * Whether to return the stale value before deleting it - */ - stale?: boolean; - - /** - * Dispose will only be called when a key falls out of the cache, not when it is overwritten - */ - noDisposeOnSet?: boolean; - } - - interface SerializedEntry { - /** - * key - */ - key: K; - - /** - * value - */ - value: V; - - /** - * when it becomes expired - */ - e: number; - } - - interface Entry { - /** - * key - */ - key: K; - - /** - * value - */ - value: V; - - /** - * entry length - */ - length: number; - - /** - * Timestamp when the entry was created - */ - now: number; - - /** - * Maximum live time - */ - maxAge: number; - } - } - - /** - * Represent an LRU cache - */ - class LRU { - /** - * Creates an LRU cache of the given size - */ - constructor(max: number); - - /** - * Creates an LRU cache with the given options - */ - constructor(options?: I.LRU.ConstructorOptions); - - /** - * The length of the cache, setter resizes the cache - */ - max: number; - - /** - * stale setting - */ - allowStale: boolean; - - /** - * maxAge setting - */ - maxAge: number; - - /** - * length setting - */ - lengthCalculator: I.LRU.LengthCalculator; - - /** - * Total length of objects in cache taking into account length options function - */ - readonly length: number; - - /** - * Total quantity of objects currently in cache. - * Note, that stale items are returned as part of this item count. - */ - readonly itemCount: number; - - /** - * Iterates over all the keys in the cache, in reverse recent-ness order. (ie, less recently used items are iterated over first.) - */ - rforEach(fn: (this: T, value: V, key: K, cache: LRU) => void, thisp?: T): void; - - /** - * Iterates over all the keys in the cache, in order of recent-ness - */ - forEach(fn: (this: T, value: V, key: K, cache: LRU) => void, thisp?: T): void; - - /** - * Returns an array of the keys in the cache - */ - keys(): K[]; - - /** - * Returns an array of the values in the cache - */ - values(): V[]; - - /** - * Clears the cache entirely, throwing away all values - */ - reset(): void; - - /** - * Return an array of the cache entries ready for serialization and usage with 'destinationCache.load(arr)` - */ - dump(): Array>; - - /** - * Returns an internal lru list of entries - */ - dumpLru(): LinkedList>; - - /** - * @param opts std.util.inspect options - */ - inspect(opts?: object): string; - - /** - * Sets a new value for the given key. Updates the "recently used"-ness of the key - * - * @param maxAge maxAge option specific for this key - * @returns Whether the key was set - */ - set(key: K, value: V, maxAge?: number): boolean; - - /** - * Check if a key is in the cache, without updating the recent-ness or deleting it for being stale - */ - has(key: K): boolean; - - /** - * Gets the value of the given key. Updates the "recently used"-ness of the key - */ - get(key: K): V | undefined; - - /** - * Returns the key value without updating the "recently used"-ness of the key - */ - peek(key: K): V | undefined; - - /** - * Deletes the less recently used element - */ - pop(): I.LRU.Entry; - - /** - * Deletes a key out of the cache - */ - del(key: K): void; - - /** - * Loads another cache entries array, obtained with sourceCache.dump(), into the cache. - * The destination cache is reset before loading new entries - */ - load(arr: Array>): void; - - /** - * Manually iterates over the entire cache proactively pruning old entries - */ - prune(): void; - } - - /** - * Represents a Map that keeps keys only for a specified interval of time - */ - class TimedoutMap extends Map { - /** - * @param timeout maximum age of the keys, 1000 by default - * @param callback callback that is called with each key when the timeout is passed - */ - constructor(timeout?: number, callback?: (key: K) => void); - - /** - * Gets the timeout - */ - getTimeout(): number; - - /** - * Sets the timeout - */ - setTimeout(ms: number): void; - - /** - * Iterates over the map and calls the callback for each element - */ - forEach(callback: (this: T, value: V, key: K, cache: this) => void, thisArg?: T): this; - - /** - * Deletes the given key - */ - delete(key: K): boolean; - } - } -} diff --git a/types/adone/glosses/collections/array_set.d.ts b/types/adone/glosses/collections/array_set.d.ts new file mode 100644 index 0000000000..c13d8769f1 --- /dev/null +++ b/types/adone/glosses/collections/array_set.d.ts @@ -0,0 +1,44 @@ +declare namespace adone.collection { + /** + * Respresetns a data structure which is a combination of an array and a set. + * Adding a new member is O(1), testing for membership is O(1), + * and finding the index of an element is O(1). + */ + class ArraySet { + /** + * The number of unique items in this ArraySet. + * If duplicates have been added, than those do not count towards the size. + */ + readonly length: number; + + /** + * Adds the given value to this set. + * + * @param allowDuplicates Whether to allow duplicates in the set, false by default + */ + add(value: T, allowDuplicates?: boolean): this; + + /** + * Checks whether the given value is a member of the set + */ + has(value: T): boolean; + + /** + * Returns the index of the given element. + * If the value is not present it will return -1 + */ + indexOf(value: T): number; + + /** + * Converts the set to an array + */ + toArray(): T[]; + + /** + * Creates an ArraySet from the given iterable object + * + * @param allowDuplicates Whether to allow duplicates in the set, false by default + */ + static from(iterable: Iterable, allowDuplicates?: boolean): ArraySet; + } +} diff --git a/types/adone/glosses/collections/async_queue.d.ts b/types/adone/glosses/collections/async_queue.d.ts new file mode 100644 index 0000000000..9a575a33be --- /dev/null +++ b/types/adone/glosses/collections/async_queue.d.ts @@ -0,0 +1,12 @@ +declare namespace adone.collection { + /** + * Represents an asynchronous queue, each pop is a promise + * that is resolved with an existing element or an element that will be pushed in the future + */ + class AsyncQueue extends Queue> { + /** + * Returns a promise that will be resolved with an existing element or an element that will be pushed in the future + */ + pop(): Promise; + } +} diff --git a/types/adone/glosses/collections/avl_tree.d.ts b/types/adone/glosses/collections/avl_tree.d.ts new file mode 100644 index 0000000000..2b5dc132b6 --- /dev/null +++ b/types/adone/glosses/collections/avl_tree.d.ts @@ -0,0 +1,48 @@ +declare namespace adone.collection { + /** + * Represents an AVL tree, a self-balancing binary search tree + */ + class AVLTree { + constructor(options?: I.BinarySearchTree.ConstructorOptions>); + + /** + * Checks whether the tree is an avl tree + */ + checkIsAVLT(): void; + + /** + * Inserts a new key/value + */ + insert(key: K, value: V): void; + + /** + * Deletes the given key/value from the tree + */ + delete(key: K, value?: V): void; + + /** + * Returns the of keys in the tree + */ + getNumberOFKeys(): number; + + /** + * Searches the given key in the tree + */ + search(key: K): V[]; + + /** + * Returns all the values from the given key bounds + */ + betweenBounds(query: I.BinarySearchTree.Query): V[]; + + /** + * Executed the given callback for each node from left to right + */ + executeOnEveryNode(fn: (tree: AVLTree) => void): void; + + /** + * Prints the tree + */ + prettyPrint(printDate?: boolean, spacing?: string): void; + } +} diff --git a/types/adone/glosses/collections/binary_search_tree.d.ts b/types/adone/glosses/collections/binary_search_tree.d.ts new file mode 100644 index 0000000000..878bd7e6a4 --- /dev/null +++ b/types/adone/glosses/collections/binary_search_tree.d.ts @@ -0,0 +1,110 @@ +declare namespace adone.collection { + namespace I.BinarySearchTree { + interface ConstructorOptions { + /** + * The parent tree + */ + parent?: Tree; + + /** + * Value to keep in this node + */ + value?: V; + + /** + * WHether the values must be unique, false by default. + * If false you can store many values for same keys, otherwise only one + */ + unique?: boolean; + + /** + * Custom keys comparator, by default if a > b => -1, a < b -1, a === b => 0 + */ + compareKeys?(a: K, b: K): number; + + /** + * Function that defines whether 2 values are the same, by default a === b + */ + checkValueEquality?(a: V, b: V): boolean; + } + + interface Query { + $lt?: K; + $lte?: K; + $gt?: K; + $gte?: K; + } + } + + /** + * Represents a binary search tree + */ + class BinarySearchTree { + constructor(options?: I.BinarySearchTree.ConstructorOptions>); + + /** + * Returns the max descendant tree + */ + getMaxKeyDescendant(): BinarySearchTree; + + /** + * Returns the maximum key + */ + getMaxKey(): K; + + /** + * Returns the min descendant tree + */ + getMinKeyDescendant(): BinarySearchTree; + + /** + * Returns the minumum key + */ + getMinKey(): K; + + /** + * Traverses the tree and calls the given function for each node + */ + checkAllNodesFullfillCondition(test: (key: K, value: V) => void): void; + + /** + * Checks whether the tree is a binary search tree + */ + checkIsBST(): void; + + /** + * Returns the of keys in the tree + */ + getNumberOfKeys(): number; + + /** + * Inserts a new key/value + */ + insert(key: K, value: V): void; + + /** + * Searches the given key in the tree + */ + search(key: K): V[]; + + /** + * Returns all the values from the given key bounds + */ + betweenBounds(query: I.BinarySearchTree.Query): V[]; + + /** + * Deletes the given key/value from the tree + */ + delete(key: K, value?: V): void; + + /** + * Executed the given callback for each node from left to right + */ + executeOnEveryNode(fn: (tree: BinarySearchTree) => void): void; + + /** + * Prints the tree + */ + prettyPrint(printData?: boolean, spacing?: string): void; + } +} diff --git a/types/adone/glosses/collections/buffer_list.d.ts b/types/adone/glosses/collections/buffer_list.d.ts new file mode 100644 index 0000000000..b2a4157385 --- /dev/null +++ b/types/adone/glosses/collections/buffer_list.d.ts @@ -0,0 +1,92 @@ +declare namespace adone.collection { + namespace I.BufferList { + type Appendable = Buffer | BufferList | string | number | Array; + } + + /** + * Represents a Node.js Buffer list collector, reader and streamer with callback/promise interface support + */ + class BufferList extends std.stream.Duplex implements PromiseLike { + /** + * Creates a new buffer list + */ + constructor(); + + /** + * Creates a new buffer list and initiates with the given value + */ + constructor(buffer: I.BufferList.Appendable); + + /** + * Creates a new buffer list and subscribes the given callback on the end/error event + */ + constructor(callback: (err: any, data: Buffer) => void); + + /** + * Adds an additional buffer or BufferList to the internal list + */ + append(buf: I.BufferList.Appendable): this; + + /** + * Ends the stream + */ + end(chunk?: Buffer): void; + end(chunk?: () => void): void; + + /** + * Returns the byte at the specified index + */ + get(idx: number): number; + + /** + * Returns a new Buffer object containing the bytes within the range specified. + */ + slice(start?: number, end?: number): Buffer; + + /** + * Copies the content of the list in the dest buffer + * starting from destStart and containing the bytes within the range specified with srcStart to srcEnd + * + * @param dstStart writes from this position + * @param srcStart reads bytes from this position + * @param srcEnd read bytes to this position + */ + copy(dst: T, dstStart?: number, srcStart?: number, srcEnd?: number): T; + + /** + * Returns a new BufferList object containing the bytes within the range specified. + * No copies will be performed. All buffers in the result share memory with the original list. + * + * @param start slice from + * @param end slice to + */ + shallowSlice(start?: number, end?: number): BufferList; + + /** + * Return a string representation of the buffer + */ + toString(encoding?: fs.I.Encoding, start?: number, end?: number): string; + + /** + * Shifts bytes off the start of the list + */ + consume(bytes: number): this; + + /** + * Performs a shallow-copy of the list. + */ + duplicate(): BufferList; + + /** + * Destroys the stream + */ + destroy(): void; + + then( + onfulfilled?: ((value: Buffer) => T1 | PromiseLike) | null, + onrejected?: ((reason: any) => T2 | PromiseLike) | null + ): PromiseLike; + + catch(onrejected?: ((reason: any) => T | PromiseLike) | null): PromiseLike; + } +} diff --git a/types/adone/glosses/collections/byte_array.d.ts b/types/adone/glosses/collections/byte_array.d.ts new file mode 100644 index 0000000000..1dc3080fb3 --- /dev/null +++ b/types/adone/glosses/collections/byte_array.d.ts @@ -0,0 +1,892 @@ +declare namespace adone.collection { + namespace I { + type Long = math.Long; + + type Longable = math.I.Longable; + + namespace ByteArray { + interface Varint32 { + value: number; + length: number; + } + + interface Varint64 { + value: Long; + length: number; + } + + interface String { + string: string; + length: number; + } + + type Wrappable = string | ByteArray | Buffer | Uint8Array | ArrayBuffer; + + type Metrics = "b" | "c"; + } + } + + /** + * Represents an array of bytes, enhanced Node.js Buffer + */ + class ByteArray { + readonly woffset: number; + + readonly roffset: number; + + readonly buffer: Buffer; + + readonly noAssert: boolean; + + /** + * Constructs a new ByteArray + * + * @param capacity Initial capacity. Defaults to ByteArray.DEFAULT_CAPACITY(64) + * @param noAssert Whether to skip assertions of offsets and values. Defaults to ByteArray.DEFAULT_NOASSERT(false) + */ + constructor(capacity?: number, noAssert?: boolean); + + /** + * Reads a BitSet as an array of booleans. + * + * @param offset Offset to read from. Will use and increase offset by length if omitted. + */ + readBitSet(offset?: number): boolean[]; + + /** + * Reads the specified number of bytes. + * + * @param length Number of bytes to read + * @param offset Offset to read from. Will use and increase offset by length if omitted. + */ + read(length: number, offset?: number): ByteArray; + + /** + * Reads an 8bit signed integer + * + * @param offset Offset to read from + */ + readInt8(offset?: number): number; + + /** + * Reads an 8bit unsigned integer + * + * @param offset Offset to read from + */ + readUInt8(offset?: number): number; + + /** + * Reads a 16bit signed le integer + * + * @param offset Offset to read from + */ + readInt16LE(offset?: number): number; + + /** + * Reads a 16bit unsigned le integer + * + * @param offset Offset to read from + */ + readUInt16LE(offset?: number): number; + + /** + * Reads a 16bit signed be integer + * + * @param offset Offset to read from + */ + readInt16BE(offset?: number): number; + + /** + * Reads a 16bit unsigned be integer + * + * @param offset Offset to read from + */ + readUInt16BE(offset?: number): number; + + /** + * Reads a 32bit signed le integer + * + * @param offset Offset to read from + */ + readInt32LE(offset?: number): number; + + /** + * Reads a 32bit unsigned le integer + * + * @param offset Offset to read from + */ + readUInt32LE(offset?: number): number; + + /** + * Reads a 32bit signed be integer + * + * @param offset Offset to read from + */ + readInt32BE(offset?: number): number; + + /** + * Reads a 32bit unsigned be integer + * + * @param offset Offset to read from + */ + readUInt32BE(offset?: number): number; + + /** + * Reads a 64bit signed le integer as math.Long + * + * @param offset Offset to read from + */ + readInt64LE(offset?: number): math.Long; + + /** + * Reads a 64bit unsigned le integer as math.Long + * + * @param offset Offset to read from + */ + readUInt64LE(offset?: number): math.Long; + + /** + * Reads a 64bit signed be integer as math.Long + * + * @param offset Offset to read from + */ + readInt64BE(offset?: number): math.Long; + + /** + * Reads a 64bit unsigned be integer as math.Long + * + * @param offset Offset to read from + */ + readUInt64BE(offset?: number): math.Long; + + /** + * Reads a 32bit le float + * + * @param offset Offset to read from + */ + readFloatLE(offset?: number): number; + + /** + * Reads a 32bit be float + * + * @param offset Offset to read from + */ + readFloatBE(offset?: number): number; + + /** + * Reads a 64bit le float + * + * @param offset Offset to read from + */ + readDoubleLE(offset?: number): number; + + /** + * Reads a 64bit be float + * + * @param offset Offset to read from + */ + readDoubleBE(offset?: number): number; + + /** + * Appends some data to this ByteArray. + * This will overwrite any contents behind the specified offset up to the appended data's length. + * + * @param source The source write from + * @param offset Offset to write at + * @param length length to read from the source + * @param encoding encoding to use for wrapping the source in bytearray + */ + write(source: I.ByteArray.Wrappable, offset?: number, length?: number, encoding?: string): this; + + /** + * Writes the array as a bitset. + * @param value Array of booleans to write + */ + writeBitSet(value: number[]): this; + + /** + * Writes the array as a bitset. + * @param value Array of booleans to write + * @param offset Offset to write at + */ + writeBitSet(value: number[], offset: number): number; + + /** + * Writes a buffer at the given offset + * @param buf Buffer to write + * @param offset Offset to write at + */ + writeBuffer(buf: Buffer, offset?: number): this; + + /** + * Writes an 8bit signed integer + * + * @param offset Offset to write at + */ + writeInt8(value: number, offset?: number): this; + + /** + * Writes an 8bit unsigned integer + * + * @param offset Offset to write at + */ + writeUInt8(value: number, offset?: number): this; + + /** + * Writes a 16bit signed le integer + * + * @param offset Offset to write at + */ + writeInt16LE(value: number, offset?: number): this; + + /** + * Writes a 16bit signed be integer + * + * @param offset Offset to write at + */ + writeInt16BE(value: number, offset?: number): this; + + /** + * Writes a 16bit unsigned le integer + * + * @param offset Offset to write at + */ + writeUInt16LE(value: number, offset?: number): this; + + /** + * Writes a 16bit unsigned be integer + * + * @param offset Offset to write at + */ + writeUInt16BE(value: number, offset?: number): this; + + /** + * Writes a 32bit signed le integer + * + * @param offset Offset to write at + */ + writeInt32LE(value: number, offset?: number): this; + + /** + * Writes a 32bit signed be integer + * + * @param offset Offset to write at + */ + writeInt32BE(value: number, offset?: number): this; + + /** + * Writes a 32bit unsigned le integer + * + * @param offset Offset to write at + */ + writeUInt32LE(value: number, offset?: number): this; + + /** + * Writes a 32bit unsigned be integer + * + * @param offset Offset to write at + */ + writeUInt32BE(value: number, offset?: number): this; + + /** + * Writes a 64bit signed le long integer + * + * @param offset Offset to write at + */ + writeInt64LE(value: math.Long | string | number, offset?: number): this; + + /** + * Writes a 64bit signed be long integer + * + * @param offset Offset to write at + */ + writeInt64BE(value: math.Long | string | number, offset?: number): this; + + /** + * Writes a 64bit unsigned le long integer + * + * @param offset Offset to write at + */ + writeUInt64LE(value: math.Long | string | number, offset?: number): this; + + /** + * Writes a 64bit unsigned be long integer + * + * @param offset Offset to write at + */ + writeUInt64BE(value: math.Long | string | number, offset?: number): this; + + /** + * Writes a 32bit le float + * + * @param offset Offset to write at + */ + writeFloatLE(value: number, offset?: number): this; + + /** + * Writes a 32bit be float + * + * @param offset Offset to write at + */ + writeFloatBE(value: number, offset?: number): this; + + /** + * Writes a 64bit le float + * + * @param offset Offset to write at + */ + writeDoubleLE(value: number, offset?: number): this; + + /** + * Writes a 64bit be float + * + * @param offset Offset to write at + */ + writeDoubleBE(value: number, offset?: number): this; + + /** + * Writes a 32bit base 128 variable-length integer + */ + writeVarint32(value: number): this; + + /** + * Writes a 32bit base 128 variable-length integer + * + * @param offset Offset to write at + */ + writeVarint32(value: number, offset: number): number; + + /** + * Writes a zig-zag encoded 32bit base 128 variable-length integer + */ + writeVarint32ZigZag(value: number): this; + + /** + * Writes a zig-zag encoded 32bit base 128 variable-length integer + * + * @param offset Offset to write at + */ + writeVarint32ZigZag(value: number, offset: number): number; + + /** + * Reads a 32bit base 128 variable-length integer + */ + readVarint32(): number; + + /** + * Reads a 32bit base 128 variable-length integer + * + * @param offset Offset to read from + */ + readVarint32(offset: number): I.ByteArray.Varint32; + + /** + * Reads a zig-zag encoded 32bit base 128 variable-length integer + */ + readVarint32ZigZag(): number; + + /** + * Reads a zig-zag encoded 32bit base 128 variable-length integer + * + * @param offset Offset to read from + */ + readVarint32ZigZag(offset: number): I.ByteArray.Varint32; + + /** + * Writes a 64bit base 128 variable-length integer + */ + writeVarint64(value: math.Long | string | number): this; + + /** + * Writes a 64bit base 128 variable-length integer + * + * @param offset Offset to write at + */ + writeVarint64(value: math.Long | string | number, offset: number): number; + + /** + * Writes a zig-zag encoded 64bit base 128 variable-length integer + */ + writeVarint64ZigZag(value: math.Long | string | number): this; + + /** + * Writes a zig-zag encoded 64bit base 128 variable-length integer + * + * @param offset Offset to write at + */ + writeVarint64ZigZag(value: math.Long | string | number, offset: number): number; + + /** + * Reads a 64bit base 128 variable-length integer + */ + readVarint64(): I.Long; + + /** + * Reads a 64bit base 128 variable-length integer + * + * @param offset Offset to read from + */ + readVarint64(offset: number): I.ByteArray.Varint64; + + /** + * Reads a zig-zag encoded 64bit base 128 variable-length integer + */ + readVarint64ZigZag(): math.Long; + + /** + * Reads a zig-zag encoded 64bit base 128 variable-length integer + * + * @param offset Offset to read from + */ + readVarint64ZigZag(offset: number): I.ByteArray.Varint64; + + /** + * Writes a NULL-terminated UTF8 encoded string. + * For this to work the specified string must not contain any NULL characters itself + */ + writeCString(str: string): this; + + /** + * Writes a NULL-terminated UTF8 encoded string. + * For this to work the specified string must not contain any NULL characters itself + * + * @param offset Offset to write at + */ + writeCString(str: string, offset: number): number; + + /** + * Reads a NULL-terminated UTF8 encoded string. + * For this to work the string read must not contain any NULL characters itself + */ + readCString(): string; + + /** + * Reads a NULL-terminated UTF8 encoded string. + * For this to work the string read must not contain any NULL characters itself + * + * @param offset Offset to read from + */ + readCString(offset: number): I.ByteArray.String; + + /** + * Writes an UTF8 encoded string + */ + writeString(str: string): this; + + /** + * Writes an UTF8 encoded string + * + * @param offset Offset to write at + */ + writeString(str: string, offset: number): number; + + /** + * Reads an UTF8 encoded string + * + * @param length Number of characters or bytes to read + * @param metrics Metrics specifying what n is meant to count. Defaults to ByteArray.METRICS_CHARS("c") + */ + readString(length: number, metrics?: I.ByteArray.Metrics): string; + + /** + * Reads an UTF8 encoded string + * + * @param length Number of characters or bytes to read + * @param metrics Metrics specifying what n is meant to count. Defaults to ByteArray.METRICS_CHARS("c") + * @param offset Offset to read from + */ + readString(length: number, metrics: I.ByteArray.Metrics, offset: number): I.ByteArray.String; + + /** + * Reads an UTF8 encoded string + * + * @param length Number of characters or bytes to read + * @param offset Offset to read from + */ + readString(length: number, offset: number): I.ByteArray.String; + + /** + * Writes a length as varint32 prefixed UTF8 encoded string + */ + writeVString(str: string): this; + + /** + * Writes a length as varint32 prefixed UTF8 encoded string + * + * @param offset Offset to read from + */ + writeVString(str: string, offset: number): number; + + /** + * Reads a length as varint32 prefixed UTF8 encoded string + */ + readVString(): string; + + /** + * Reads a length as varint32 prefixed UTF8 encoded string + * + * @param offset Offset to read from + */ + readVString(offset: number): I.ByteArray.String; + + /** + * Appends this ByteArray's contents to another ByteArray. + * This will overwrite any contents behind the specified offset up to the length of this ByteArray's data + * + * @param offset Offset to append to + */ + appendTo(target: ByteArray, offset?: number): this; + + /** + * Enables or disables assertions of argument types and offsets. + * Assertions are enabled by default but you can opt to disable them if your code already makes sure that everything is valid + */ + assert(assert?: boolean): this; + + /** + * Gets the capacity of this ByteArray's backing buffer + */ + capacity(): number; + + /** + * Clears this ByteArray's offsets by setting offset to 0 and limit to the backing buffer's capacity + */ + clear(): this; + + /** + * Creates a cloned instance of this ByteArray, + * preset with this ByteArray's values for offset, markedOffset and limit + * + * @param copy Whether to copy the backing buffer or to return another view on the same, false by default + */ + clone(copy?: boolean): ByteArray; + + /** + * Compacts this ByteArray to be backed by a buffer of its contents' length. + * Will set offset = 0 and limit = capacity and adapt markedOffset to the same relative position if set + * + * @param begin Offset to start at, buffer offset by default + * @param end Offset to end at, buffer limit by default + */ + compact(begin?: number, end?: number): this; + + /** + * Creates a copy of this ByteArray's contents. + * + * @param begin Begin offset, buffer offset by default + * @param end End offset, buffer limit by default + */ + copy(begin?: number, end?: number): ByteArray; + + /** + * Copies this ByteArray's contents to another ByteArray. + * + * @param targetOffset Offset to copy to. Will use and increase the target's offset by the number of bytes copied if omitted + * @param sourceOffset Offset to start copying from. Will use and increase offset by the number of bytes copied if omitted + * @param sourceLimit Offset to end copying from, defaults to the buffer limit + */ + copyTo(target: ByteArray, targetOffset?: number, souceOffset?: number, sourceLimit?: number): this | ByteArray; + + /** + * Makes sure that this ByteArray is backed by a ByteArray#buffer of at least the specified capacity. + * If the current capacity is exceeded, it will be doubled. + * If double the current capacity is less than the required capacity, the required capacity will be used instead + */ + ensureCapacity(capacity: number): this; + + /** + * Overwrites this ByteArray's contents with the specified value. + * + * @param value Byte value to fill with. If given as a string, the first character is used + * @param begin Begin offset. Will use and increase offset by the number of bytes written if omitted. defaults to offset + * @param end End offset, defaults to limit. + */ + fill(value: string | number, begin?: number, end?: number): this; + + /** + * Makes this ByteArray ready for a new sequence of write or relative read operations. + * Sets limit = offset and offset = 0. + * Make sure always to flip a ByteArray when all relative read or write operations are complete + */ + flip(): this; + + /** + * Marks an offset on this ByteArray to be used later + * + * @param offset Offset to mark. Defaults to offset. + */ + mark(offset?: number): this; + + /** + * Prepends some data to this ByteArray. + * This will overwrite any contents before the specified offset up to the prepended data's length. + * If there is not enough space available before the specified offset, + * the backing buffer will be resized and its contents moved accordingly + * + * @param source Data to prepend + * @param offset Offset to prepend at. Will use and decrease offset by the number of bytes prepended if omitted. + */ + prepend(source: I.ByteArray.Wrappable, offset: number): this; + + /** + * Prepends some data to this ByteArray. + * This will overwrite any contents before the specified offset up to the prepended data's length. + * If there is not enough space available before the specified offset, + * the backing buffer will be resized and its contents moved accordingly + * + * @param source Data to prepend + * @param encoding Encoding if data is a string + * @param offset Offset to prepend at. Will use and decrease offset by the number of bytes prepended if omitted. + */ + prepend(source: I.ByteArray.Wrappable, encoding?: string, offset?: number): this; + + /** + * Prepends this ByteArray to another ByteArray. + * This will overwrite any contents before the specified offset up to the prepended data's length. + * If there is not enough space available before the specified offset, + * the backing buffer will be resized and its contents moved accordingly + * + * @param offset Offset to prepend at + */ + prependTo(target: ByteArray, offset?: number): this; + + /** + * Gets the number of remaining readable bytes + */ + remaining(): number; + + /** + * Resets this ByteArray's offset. + * If an offset has been marked through mark before, offset will be set to markedOffset, which will then be discarded. + * If no offset has been marked, sets offset = 0 + */ + reset(): this; + + /** + * Resizes this ByteArray to be backed by a buffer of at least the given capacity. + * Will do nothing if already that large or larger. + * + * @param capacity Capacity required + */ + resize(capacity: number): this; + + /** + * Reverses this ByteArray's contents. + * + * @param begin Offset to start at, defaults to offset + * @param end Offset to end at, defaults to limit + */ + reverse(begin?: number, end?: number): this; + + /** + * Skips the next length bytes. This will just advance + */ + skip(length: number): this; + + /** + * Slices this ByteArray by creating a cloned instance with offset = begin and limit = end + * + * @param begin Begin offset, defaults to offset + * @param end End offset, defaults to limit + */ + slice(begin?: number, end?: number): ByteArray; + + /** + * Returns a copy of the backing buffer that contains this ByteArray's contents. + * + * @param forceCopy If true returns a copy, otherwise returns a view referencing the same memory if possible, false by default + * @param begin Begin offset, offset by default + * @param end End offset, limit by default + */ + toBuffer(forceCopy?: boolean, begin?: number, end?: number): Buffer; + + /** + * Returns a raw buffer compacted to contain this ByteArray's contents + */ + toArrayBuffer(): ArrayBuffer; + + /** + * Converts the ByteArray's contents to a string + * + * @param encoding Output encoding + * @param begin Begin offset, offset by default + * @param end End offset, limit by default + */ + toString(encoding?: string, begin?: number, end?: number): string; + + /** + * Encodes this ByteArray's contents to a base64 encoded string + * + * @param begin Begin offset, offset by default + * @param end End offset, limit by default + */ + toBase64(begin?: number, end?: number): string; + + /** + * Encodes this ByteArray to a binary encoded string, that is using only characters 0x00-0xFF as bytes + * + * @param begin Begin offset, offset by default + * @param end End offset, limit by default + */ + toBinary(begin?: number, end?: number): string; + + /** + * Encodes this ByteArray to a hex encoded string with marked offsets + * + * @param columns If true returns two columns hex + ascii, defaults to false + */ + toDebug(columns?: boolean): string; + + /** + * Encodes this ByteArray's contents to a hex encoded string + * + * @param begin Begin offset, offset by default + * @param end End offset, limit by default + */ + toHex(begin?: number, end?: number): string; + + /** + * Encodes this ByteArray's contents to an UTF8 encoded string + * + * @param begin Begin offset, offset by default + * @param end End offset, limit by default + */ + toUTF8(begin?: number, end?: number): string; + + static accessor(): typeof Buffer; + + /** + * Allocates a new ByteArray backed by a buffer of the specified capacity. + * + * @param capacity Initial capacity. Defaults to ByteArray.DEFAULT_CAPACITY(64) + * @param noAssert Whether to skip assertions of offsets and values. Defaults to ByteArray.DEFAULT_NOASSERT(false) + */ + static allocate(capacity?: number, noAssert?: boolean): ByteArray; + + /** + * Concatenates multiple ByteArrays into one + * + * @param encoding Encoding for strings + * @param noAssert Whether to skip assertions of offsets and values. Defaults to ByteArray.DEFAULT_NOASSERT(false) + */ + static concat(buffers: I.ByteArray.Wrappable[], encoding?: string, noAssert?: boolean): ByteArray; + + static type(): typeof Buffer; + + /** + * Wraps a buffer or a string. + * Sets the allocated ByteArray's offset to 0 and its limit to the length of the wrapped data + * + * @param encoding Encoding for strings + * @param noAssert Whether to skip assertions of offsets and values. Defaults to ByteArray.DEFAULT_NOASSERT(false) + */ + static wrap(buffer: I.ByteArray.Wrappable, encoding?: string, noAssert?: boolean): ByteArray; + + /** + * Calculates the actual number of bytes required to store a 32bit base 128 variable-length integer + */ + static calculateVarint32(value: number): number; + + /** + * Zigzag encodes a signed 32bit integer so that it can be effectively used with varint encoding + */ + static zigZagEncode32(n: number): number; + + /** + * Decodes a zigzag encoded signed 32bit integer + */ + static zigZagDecode32(n: number): number; + + /** + * Calculates the actual number of bytes required to store a 64bit base 128 variable-length integer + */ + static calculateVarint64(value: number | string): number; + + /** + * Zigzag encodes a signed 64bit integer so that it can be effectively used with varint encoding + */ + static zigZagEncode64(value: number | string | I.Long): I.Long; + + /** + * Decodes a zigzag encoded signed 64bit integer. + */ + static zigZagDecode64(value: number | string | I.Long): I.Long; + + /** + * Calculates the number of UTF8 characters of a string. + * JavaScript itself uses UTF-16, + * so that a string's length property does not reflect its actual UTF8 size if it contains code points larger than 0xFFFF + */ + static calculateUTF8Chars(str: string): number; + + /** + * Calculates the number of UTF8 bytes of a string. + */ + static calculateString(str: string): number; + + /** + * Decodes a base64 encoded string to a ByteArray + */ + static fromBase64(str: string): ByteArray; + + /** + * Encodes a binary string to base64 like window.btoa does + */ + static btoa(str: string): string; + + /** + * Decodes a base64 encoded string to binary like window.atob does + */ + static atob(b64: string): string; + + /** + * Decodes a binary encoded string, that is using only characters 0x00-0xFF as bytes, to a ByteArray + */ + static fromBinary(str: string): ByteArray; + + /** + * Decodes a hex encoded string with marked offsets to a ByteArray + */ + static fromDebug(str: string, noAssert?: boolean): ByteArray; + + /** + * Decodes a hex encoded string to a ByteArray + */ + static fromHex(str: string, noAssert?: boolean): ByteArray; + + /** + * Decodes an UTF8 encoded string to a ByteArray + */ + static fromUTF8(str: string, noAssert?: boolean): ByteArray; + + /** + * Default initial capacity + */ + static DEFAULT_CAPACITY: number; + + /** + * Default no assertions flag + */ + static DEFAULT_NOASSERT: boolean; + + /** + * Maximum number of bytes required to store a 32bit base 128 variable-length integer + */ + static MAX_VARINT32_BYTES: number; + + /** + * Maximum number of bytes required to store a 64bit base 128 variable-length integer + */ + static MAX_VARINT64_BYTES: number; + + /** + * Metrics representing number of UTF8 characters. Evaluates to `c`. + */ + static METRICS_CHARS: string; + + /** + * Metrics representing number of bytes. Evaluates to `b`. + */ + static METRICS_BYTES: string; + } +} diff --git a/types/adone/glosses/collections/default_map.d.ts b/types/adone/glosses/collections/default_map.d.ts new file mode 100644 index 0000000000..46b8ccebfe --- /dev/null +++ b/types/adone/glosses/collections/default_map.d.ts @@ -0,0 +1,9 @@ +declare namespace adone.collection { + /** + * Represents a Map that has a default values factory object or function. + * Each get of non-existent key goes through the factory + */ + class DefaultMap extends Map { + constructor(factory?: ((key: K) => V) | { [key: string]: V }, iterable?: Iterable<[K, V]>); + } +} diff --git a/types/adone/glosses/collections/fast_lru.d.ts b/types/adone/glosses/collections/fast_lru.d.ts new file mode 100644 index 0000000000..e991322bc0 --- /dev/null +++ b/types/adone/glosses/collections/fast_lru.d.ts @@ -0,0 +1,61 @@ +declare namespace adone.collection { + /** + * Represents a faster LRU cache but with less functionality + */ + class FastLRU { + /** + * @param size Cache size, unlimited by default + */ + constructor(size?: number, options?: { + /** + * Function that is called when a value is deleted + */ + dispose?(key: K, value: V): void + }); + + /** + * The actual size of the cache + */ + readonly size: number; + + /** + * Gets the value by the given key + */ + get(key: K): V | undefined; + + /** + * Sets a new value for the given key + */ + set(key: K, value: V): void; + + /** + * Deletes the given key from the cache + */ + delete(key: K): boolean; + + /** + * Checks whether the cache has an element with the given key + */ + has(key: K): boolean; + + /** + * Returns the keys iterator + */ + keys(): IterableIterator; + + /** + * Returns the values iterator + */ + values(): IterableIterator; + + /** + * Returns the entries iterator + */ + entries(): IterableIterator<[K, V]>; + + /** + * Clears the cache + */ + clear(): void; + } +} diff --git a/types/adone/glosses/collections/index.d.ts b/types/adone/glosses/collections/index.d.ts new file mode 100644 index 0000000000..234ffe85f4 --- /dev/null +++ b/types/adone/glosses/collections/index.d.ts @@ -0,0 +1,28 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// + +declare namespace adone { + /** + * Data structures + */ + namespace collection { + // + } +} diff --git a/types/adone/glosses/collections/linked_list.d.ts b/types/adone/glosses/collections/linked_list.d.ts new file mode 100644 index 0000000000..69ffa4da4b --- /dev/null +++ b/types/adone/glosses/collections/linked_list.d.ts @@ -0,0 +1,150 @@ +declare namespace adone.collection { + namespace I.LinkedList { + /** + * Represents the node of a linked list + */ + interface Node { + /** + * The next node + */ + next?: Node; + + /** + * The previous node + */ + prev?: Node; + + /** + * The value this node contains + */ + value: T; + } + } + + /** + * Represents a linked list + */ + class LinkedList { + /** + * The maximum length of the list + */ + readonly maxLength: number; + + /** + * Current length of the list + */ + readonly length: number; + + /** + * Whether the list is autoresizable + */ + readonly autoresize: boolean; + + /** + * @param maxLength Maximum length of the linked list + */ + constructor(maxLength?: number); + + /** + * Whether the list is full + */ + readonly full: boolean; + + /** + * Whether the list is empty + */ + readonly empty: boolean; + + /** + * Resizes the list + */ + resize(newLength: number): this; + + /** + * Adds a new node to the end + * + * @returns Added node + */ + push(value: T): I.LinkedList.Node; + + /** + * Removes the last node, returns undefined if the list is empty + */ + pop(): T | undefined; + + /** + * Removes the first node, returns undefined if the list is empty + */ + shift(): T | undefined; + + /** + * Inserts a new node at the beginning of the list + * + * @returns Added node + */ + unshift(value: T): I.LinkedList.Node; + + /** + * Moves the given node to the end of the list + */ + pushNode(node: I.LinkedList.Node): void; + + /** + * Moved the given node to the beginning of the list + */ + unshiftNode(node: I.LinkedList.Node): void; + + /** + * Removes the given node from the list + */ + removeNode(node: I.LinkedList.Node): void; + + /** + * Clears the list + * + * @param strong Whether to reset all the node's values + */ + clear(strong?: boolean): void; + + /** + * Convers the list to an array + */ + toArray(): T[]; + + /** + * The first element of the list + */ + readonly front: T; + + /** + * The last element of the list + */ + readonly back: T; + + /** + * Returns an iterator over the list elements + */ + [Symbol.iterator](): IterableIterator; + + /** + * Returns the next node for the given node + */ + nextNode(node: I.LinkedList.Node): I.LinkedList.Node; + + /** + * Maps this linked list to a new one using the given function + */ + map(fn: (value: T, index: number) => R): LinkedList; + + /** + * Invokes the given callback for each value from the beginning to the end (much faster than for-of). + * If the given function returns false it stops iterating. + */ + forEach(callback: (value: T, index: number) => void | boolean): void; + + /** + * Default length of a new created linked list + */ + static DEFAULT_LENGTH: number; + } +} diff --git a/types/adone/glosses/collections/lru.d.ts b/types/adone/glosses/collections/lru.d.ts new file mode 100644 index 0000000000..7d41e32cd5 --- /dev/null +++ b/types/adone/glosses/collections/lru.d.ts @@ -0,0 +1,213 @@ +declare namespace adone.collection { + namespace I.LRU { + type LengthCalculator = (value: V, key: K) => number; + interface ConstructorOptions { + /** + * The maximum size of the cache, checked by applying the length function to all values in the cache. + * Default is Infinity + */ + max?: number; + + /** + * Maximum age in ms. Items are not pro-actively pruned out as they age, + * but if you try to get an item that is too old, + * it'll drop it and return undefined instead of giving it to you + */ + maxAge?: number; + + /** + * Function that is used to calculate the length of stored items + */ + length?: LengthCalculator; + + /** + * Function that is called on items when they are dropped from the cache + */ + dispose?(key: K, value: V): void; + + /** + * Whether to return the stale value before deleting it + */ + stale?: boolean; + + /** + * Dispose will only be called when a key falls out of the cache, not when it is overwritten + */ + noDisposeOnSet?: boolean; + } + + interface SerializedEntry { + /** + * key + */ + key: K; + + /** + * value + */ + value: V; + + /** + * when it becomes expired + */ + e: number; + } + + interface Entry { + /** + * key + */ + key: K; + + /** + * value + */ + value: V; + + /** + * entry length + */ + length: number; + + /** + * Timestamp when the entry was created + */ + now: number; + + /** + * Maximum live time + */ + maxAge: number; + } + } + + /** + * Represent an LRU cache + */ + class LRU { + /** + * Creates an LRU cache of the given size + */ + constructor(max: number); + + /** + * Creates an LRU cache with the given options + */ + constructor(options?: I.LRU.ConstructorOptions); + + /** + * The length of the cache, setter resizes the cache + */ + max: number; + + /** + * stale setting + */ + allowStale: boolean; + + /** + * maxAge setting + */ + maxAge: number; + + /** + * length setting + */ + lengthCalculator: I.LRU.LengthCalculator; + + /** + * Total length of objects in cache taking into account length options function + */ + readonly length: number; + + /** + * Total quantity of objects currently in cache. + * Note, that stale items are returned as part of this item count. + */ + readonly itemCount: number; + + /** + * Iterates over all the keys in the cache, in reverse recent-ness order. (ie, less recently used items are iterated over first.) + */ + rforEach(fn: (this: T, value: V, key: K, cache: LRU) => void, thisp?: T): void; + + /** + * Iterates over all the keys in the cache, in order of recent-ness + */ + forEach(fn: (this: T, value: V, key: K, cache: LRU) => void, thisp?: T): void; + + /** + * Returns an array of the keys in the cache + */ + keys(): K[]; + + /** + * Returns an array of the values in the cache + */ + values(): V[]; + + /** + * Clears the cache entirely, throwing away all values + */ + reset(): void; + + /** + * Return an array of the cache entries ready for serialization and usage with 'destinationCache.load(arr)` + */ + dump(): Array>; + + /** + * Returns an internal lru list of entries + */ + dumpLru(): LinkedList>; + + /** + * @param opts std.util.inspect options + */ + inspect(opts?: object): string; + + /** + * Sets a new value for the given key. Updates the "recently used"-ness of the key + * + * @param maxAge maxAge option specific for this key + * @returns Whether the key was set + */ + set(key: K, value: V, maxAge?: number): boolean; + + /** + * Check if a key is in the cache, without updating the recent-ness or deleting it for being stale + */ + has(key: K): boolean; + + /** + * Gets the value of the given key. Updates the "recently used"-ness of the key + */ + get(key: K): V | undefined; + + /** + * Returns the key value without updating the "recently used"-ness of the key + */ + peek(key: K): V | undefined; + + /** + * Deletes the less recently used element + */ + pop(): I.LRU.Entry; + + /** + * Deletes a key out of the cache + */ + del(key: K): void; + + /** + * Loads another cache entries array, obtained with sourceCache.dump(), into the cache. + * The destination cache is reset before loading new entries + */ + load(arr: Array>): void; + + /** + * Manually iterates over the entire cache proactively pruning old entries + */ + prune(): void; + } +} diff --git a/types/adone/glosses/collections/map_cache.d.ts b/types/adone/glosses/collections/map_cache.d.ts new file mode 100644 index 0000000000..55bbb6e05f --- /dev/null +++ b/types/adone/glosses/collections/map_cache.d.ts @@ -0,0 +1,13 @@ +declare namespace adone.collection { + class MapCache { + has(key: string): boolean; + + get(key: string): T; + + set(key: string, value: T): void; + + delete(key: string): void; + + clear(): void; + } +} diff --git a/types/adone/glosses/collections/ns_cache.d.ts b/types/adone/glosses/collections/ns_cache.d.ts new file mode 100644 index 0000000000..5630c295d3 --- /dev/null +++ b/types/adone/glosses/collections/ns_cache.d.ts @@ -0,0 +1,17 @@ +declare namespace adone.collection { + class NSCache { + constructor(size: number, namespaces: string[]); + + resize(newSize: number): void; + + set(ns: string, key: string, value: T): void; + + get(ns: string, key: string): T; + + has(ns: string, key: string): boolean; + + delete(ns: string, key: string): void; + + clear(): void; + } +} diff --git a/types/adone/glosses/collections/priority_queue.d.ts b/types/adone/glosses/collections/priority_queue.d.ts new file mode 100644 index 0000000000..0fb1e92814 --- /dev/null +++ b/types/adone/glosses/collections/priority_queue.d.ts @@ -0,0 +1,78 @@ +declare namespace adone.collection { + namespace I.PriorityQueue { + interface ConstructorOptions { + /** + * Function that compares objects. + * + * Must return a positive value if a > b, a negative if a < b, and zero for equal objects + */ + compare?(a: T, b: T): number; + + /** + * Function that evaluates the priority value by the given objects, + * if the returned value > 0, then the first argument has higher priority, + * = 0 same priority, < 0 lower priority. + * By default the top element is an element that has the highest priority, + * the default priority function is equal to the compare function + */ + priority?(a: T, b: T): number; + } + } + + /** + * Represents a priority queue + */ + class PriorityQueue { + /** + * Whether the queue is empty + */ + readonly empty: boolean; + + /** + * The length of the queue + */ + readonly length: number; + + constructor(options?: I.PriorityQueue.ConstructorOptions); + + /** + * Clones the queue + */ + clone(): PriorityQueue; + + /** + * Inserts a new element + */ + push(x: T): this; + + /** + * Removes the top element (that has the highest priority) + */ + pop(): T | undefined; + + /** + * Deletes the given element from the queue + */ + delete(x: T): this; + + /** + * Replaces the top element (pop + push) + */ + replace(x: T): T; + + /** + * Faster push + pop + */ + pushpop(x: T): T; + + /** + * Converts the queue to an array, it works with a clone of the queue, so the original queue is untouched + */ + toArray(): T[]; + + /** + * Creates a queue object from the given iterable + */ + static from(iterable: Iterable, options?: I.PriorityQueue.ConstructorOptions): PriorityQueue; + } +} diff --git a/types/adone/glosses/collections/queue.d.ts b/types/adone/glosses/collections/queue.d.ts new file mode 100644 index 0000000000..e67eb8fda9 --- /dev/null +++ b/types/adone/glosses/collections/queue.d.ts @@ -0,0 +1,31 @@ +declare namespace adone.collection { + /** + * Represents a queue + */ + class Queue { + /** + * Whether the queue is full + */ + readonly full: boolean; + + /** + * The length of the queue + */ + readonly length: number; + + /** + * Whether the queue is empty + */ + readonly empty: boolean; + + /** + * Inserts a new element at the end + */ + push(x: S): this; + + /** + * Removes and returns an element from the beginning + */ + pop(): T | undefined; + } +} diff --git a/types/adone/glosses/collections/rb_tree.d.ts b/types/adone/glosses/collections/rb_tree.d.ts new file mode 100644 index 0000000000..2ed7a81323 --- /dev/null +++ b/types/adone/glosses/collections/rb_tree.d.ts @@ -0,0 +1,184 @@ +declare namespace adone.collection { + namespace I.RedBlackTree { + interface Node { + /** + * The key associated to the node + */ + key: K; + + /** + * The value associated to the node + */ + value: V; + + /** + * The left subtree of the node + */ + left?: Node; + + /** + * The right subtree of the node + */ + right?: Node; + } + + interface Iterator { + /** + * Checks if the iterator is valid + */ + readonly valid: boolean; + + /** + * The value of the node at the iterator's current position, null if invalid + */ + readonly node: Node | null; + + /** + * The key of the item referenced by the iterator, undefined if invalid + */ + readonly key?: K; + + /** + * The value of the item referenced by the iterator, undefined if invalid + */ + readonly value?: V; + + /** + * Returns the position of this iterator in the sequence + */ + readonly index: number; + + /** + * If true, then the iterator is not at the end of the sequence + */ + readonly hasNext: boolean; + + /** + * If true, then the iterator is not at the beginning of the sequence + */ + readonly hasPrev: boolean; + + /** + * The tree associated to the iterator + */ + tree: RedBlackTree; + + /** + * Makes a copy of the iterator + */ + clone(): Iterator; + + /** + * Removes the item at the position of the iterator and returns a new rb-tree + */ + remove(): RedBlackTree; + + /** + * Advances the iterator to the next position + */ + next(): void; + + /** + * Updates the value of the node in the tree at this iterator and returns a new rb-tree + */ + update(value: V): RedBlackTree; + + /** + * Moves the iterator backward one element + */ + prev(): void; + } + } + + /** + * Represents a fully persistent red-black tree + */ + class RedBlackTree { + /** + * The root node of the tree + */ + root: I.RedBlackTree.Node; + + constructor(compare?: (a: K, b: K) => number, root?: RedBlackTree); + + /** + * A sorted array of all the keys in the tree + */ + readonly keys: K[]; + + /** + * An array of all the values in the tree + */ + readonly values: V[]; + + /** + * The number of items in the tree + */ + readonly length: number; + + /** + * An iterator pointing to the first element in the tree + */ + readonly begin: I.RedBlackTree.Iterator; + + /** + * An iterator pointing to the last element in the tree + */ + readonly end: I.RedBlackTree.Iterator; + + /** + * Creates a new tree with the new pair inserted + */ + insert(key: K, value: V): RedBlackTree; + + /** + * Walks a visitor function over the nodes of the tree in order + * + * @param visit A callback that gets executed on each node. + * If a truthy value is returned from the visitor, then iteration is stopped. + * @param lo An optional start of the range to visit (inclusive) + * @param hi An optional end of the range to visit (non-inclusive) + */ + forEach(visit: (key: K, value: V) => T, lo?: K, hi?: K): T; + + /** + * Finds an iterator starting at the given element + */ + at(idx: number): I.RedBlackTree.Iterator; + + /** + * Finds the first item in the tree whose key is >= key + */ + ge(key: K): I.RedBlackTree.Iterator; + + /** + * Finds the first item in the tree whose key is > key + */ + gt(key: K): I.RedBlackTree.Iterator; + + /** + * Finds the first item in the tree whose key is < key + */ + lt(key: K): I.RedBlackTree.Iterator; + + /** + * Finds the first item in the tree whose key is <= key + */ + le(key: K): I.RedBlackTree.Iterator; + + /** + * Returns an iterator pointing to the first item in the tree with key, otherwise null + */ + find(key: K): I.RedBlackTree.Iterator | null; + + /** + * Removes the first item with key in the tree + */ + remove(key: K): RedBlackTree; + + /** + * Retrieves the value associated to the given key + */ + get(key: K): V | undefined; + } +} diff --git a/types/adone/glosses/collections/refcounted_cache.d.ts b/types/adone/glosses/collections/refcounted_cache.d.ts new file mode 100644 index 0000000000..79410423a4 --- /dev/null +++ b/types/adone/glosses/collections/refcounted_cache.d.ts @@ -0,0 +1,9 @@ +declare namespace adone.collection { + class RefcountedCache extends MapCache { + ref(key: string): void; + + unref(key: string): void; + + references(key: string): number; + } +} diff --git a/types/adone/glosses/collections/set.d.ts b/types/adone/glosses/collections/set.d.ts new file mode 100644 index 0000000000..f1a6bae96d --- /dev/null +++ b/types/adone/glosses/collections/set.d.ts @@ -0,0 +1,17 @@ +declare namespace adone.collection { + class Set { + constructor(key?: (x: T) => any); + + has(value: T): boolean; + + add(value: T): void; + + delete(value: T): void; + + get(value: T): T; // ??? + + readonly size: number; + + only(): T; + } +} diff --git a/types/adone/glosses/collections/stack.d.ts b/types/adone/glosses/collections/stack.d.ts new file mode 100644 index 0000000000..90fe35b99b --- /dev/null +++ b/types/adone/glosses/collections/stack.d.ts @@ -0,0 +1,36 @@ +declare namespace adone.collection { + /** + * Represents a stack + */ + class Stack { + /** + * Whether the stack is empty + */ + readonly empty: boolean; + + /** + * The top element of the stack + */ + readonly top: T; + + /** + * Inserts a new element + */ + push(x: T): this; + + /** + * Removes the top element + */ + pop(): T | undefined; + + /** + * Returns an iterator over the values + */ + [Symbol.iterator](): IterableIterator; + + /** + * Creates a stack and pushed all the values from the given iterable object + */ + static from(iterable: Iterable): Stack; + } +} diff --git a/types/adone/glosses/collections/timedout_map.d.ts b/types/adone/glosses/collections/timedout_map.d.ts new file mode 100644 index 0000000000..fedcf79fa2 --- /dev/null +++ b/types/adone/glosses/collections/timedout_map.d.ts @@ -0,0 +1,32 @@ +declare namespace adone.collection { + /** + * Represents a Map that keeps keys only for a specified interval of time + */ + class TimedoutMap extends Map { + /** + * @param timeout maximum age of the keys, 1000 by default + * @param callback callback that is called with each key when the timeout is passed + */ + constructor(timeout?: number, callback?: (key: K) => void); + + /** + * Gets the timeout + */ + getTimeout(): number; + + /** + * Sets the timeout + */ + setTimeout(ms: number): void; + + /** + * Iterates over the map and calls the callback for each element + */ + forEach(callback: (this: T, value: V, key: K, cache: this) => void, thisArg?: T): this; + + /** + * Deletes the given key + */ + delete(key: K): boolean; + } +} diff --git a/types/adone/glosses/data.d.ts b/types/adone/glosses/data.d.ts index a22ba10750..4d3dae7b2b 100644 --- a/types/adone/glosses/data.d.ts +++ b/types/adone/glosses/data.d.ts @@ -1050,5 +1050,183 @@ declare namespace adone { */ function decode(buf: Buffer, options?: I.DeserializeOptions): any; } + + namespace protobuf { + namespace schema { + namespace I { + interface Field { + name: string | null; + type: string | null; + tag: number; + map: { + from: string; + to: string; + } | null; + oneof: string | null; + required: boolean; + repeated: boolean; + options: object; + } + + interface Enum { + name: string; + values: object; + options: object; + } + + interface Extend { + name: string; + message: Message; + } + + interface Message { + name: string; + enums: Enum[]; + extends: Extend[]; + messages: Message[]; + fields: Field[]; + extensions: { + from: number, + to: number + } | null; + } + + interface RPCMethod { + name: string; + input_type: string | null; + output_type: string | null; + client_streaming: boolean; + server_streaming: boolean; + options: object; + } + + interface Service { + name: string; + methods: RPCMethod[]; + options: object; + } + + interface Schema { + syntax: any; // ?? + package: string | null; + imports: string[]; + enums: Enum[]; + messages: Message[]; + options: object; + extends: Extend[]; + services?: Service[]; + } + } + + function parse(buf: Buffer | string): I.Schema; + + function stringify(schema: object): string; + } + + function create(proto: Buffer | string | object, opts?: object): object; + } + + namespace base32 { + function charmap(alphabet: string, mappings?: T): T; + + namespace I { + interface Spec { + alphabet: string; + charmap: { + [c: string]: number; + }; + } + } + + const rfc4648: I.Spec; + + const crockford: I.Spec; + + const base32hex: I.Spec; + + namespace I { + interface DecoderOptions { + type: "rfc4648" | "crockford" | "base32hex"; + charmap?: object; + } + + interface EncoderOptions { + type: "rfc4648" | "crockford" | "base32hex"; + alphabet?: string; + } + } + + class Decoder { + constructor(options?: I.DecoderOptions); + + write(str: string): this; + + finalize(str?: string): Buffer; + } + + class Encoder { + constructor(options?: I.EncoderOptions); + + write(buf: Buffer): this; + + finalize(buf?: Buffer): string; + } + + function encode(buf: Buffer, options?: I.EncoderOptions): string; + + function decode(str: string, options?: I.DecoderOptions): Buffer; + } + + namespace I { + interface BaseX { + encode(buf: Buffer): string; + + decode(str: string): Buffer; + + decodeUnsafe(str: string): Buffer; + } + } + + function basex(alphabet: string): I.BaseX; + + const base58: I.BaseX; + + namespace base64url { + function unescape(str: string): string; + + function escape(str: string): string; + + namespace I { + interface EncodeOptions { + encoding?: string; + } + + interface DecodeOptions { + encoding?: string; + buffer?: boolean; + } + } + + function encode(str: Buffer | string, options?: I.EncodeOptions): string; + + function decode(str: string, options: I.DecodeOptions & { buffer: true }): Buffer; + function decode(str: string, options?: I.DecodeOptions): string; + } + + namespace varint { + function encode(num: number, out?: T[], offset?: number): T[]; + + function decode(buf: Buffer, offset?: number): number; + + function encodingLength(value: number): number; + } + + namespace varintSigned { + function encode(num: number, out?: T[], offset?: number): T[]; + + function decode(buf: Buffer, offset?: number): number; + + function encodingLength(value: number): number; + } } } diff --git a/types/adone/glosses/fake.d.ts b/types/adone/glosses/fake.d.ts new file mode 100644 index 0000000000..0c403747e4 --- /dev/null +++ b/types/adone/glosses/fake.d.ts @@ -0,0 +1,337 @@ +declare namespace adone { + namespace fake { + namespace I { + interface Card { + name: string; + username: string; + email: string; + address: FullAddress; + phone: string; + website: string; + company: Company; + posts: Post[]; + accountHistory: string[]; + } + + interface FullAddress { + streetA: string; + streetB: string; + streetC: string; + streetD: string; + city: string; + state: string; + county: string; + zipcode: string; + geo: Geo; + } + + interface Geo { + lat: string; + lng: string; + } + + interface Company { + name: string; + catchPhrase: string; + bs: string; + } + + interface Post { + words: string; + sentence: string; + sentences: string; + paragraph: string; + } + + interface ContextualCard { + name: string; + username: string; + email: string; + dob: Date; + phone: string; + address: Address; + website: string; + company: Company; + } + + interface Address { + street: string; + suite: string; + city: string; + state: string; + zipcode: string; + geo: Geo; + } + + interface UserCard { + name: string; + username: string; + email: string; + address: Address; + phone: string; + website: string; + company: Company; + } + + interface Transaction { + amount: string; + date: Date; + business: string; + name: string; + type: string; + account: string; + } + } + + namespace address { + function zipCode(format?: string): string; + function city(format?: number): string; + function cityPrefix(): string; + function citySuffix(): string; + function streetName(): string; + function streetAddress(useFullAddress?: boolean): string; + function streetSuffix(): string; + function streetPrefix(): string; + function secondaryAddress(): string; + function county(): string; + function country(): string; + function countryCode(): string; + function state(useAbbr?: boolean): string; + function stateAbbr(): string; + function latitude(): string; + function longitude(): string; + } + + namespace commerce { + function color(): string; + function department(): string; + function productName(): string; + function price(min?: number, max?: number, dec?: number, symbol?: string): string; + function productAdjective(): string; + function productMaterial(): string; + function product(): string; + } + + namespace company { + function suffixes(): string[]; + function companyName(format?: number): string; + function companySuffix(): string; + function catchPhrase(): string; + function bs(): string; + function catchPhraseAdjective(): string; + function catchPhraseDescriptor(): string; + function catchPhraseNoun(): string; + function bsAdjective(): string; + function bsBuzz(): string; + function bsNoun(): string; + } + + namespace database { + function column(): string; + function type(): string; + function collation(): string; + function engine(): string; + } + + namespace date { + function past(years?: number, refDate?: string|Date): Date; + function future(years?: number, refDate?: string|Date): Date; + function between(from: string|number|Date, to: string|Date): Date; + function recent(days?: number): Date; + function soon(days?: number): Date; + function month(options?: { abbr?: boolean, context?: boolean }): string; + function weekday(options?: { abbr?: boolean, context?: boolean }): string; + } + + function fake(str: string): string; + + namespace finance { + function account(length?: number): string; + function accountName(): string; + function mask(length?: number, parens?: boolean, elipsis?: boolean): string; + function amount(min?: number, max?: number, dec?: number, symbol?: string): string; + function transactionType(): string; + function currencyCode(): string; + function currencyName(): string; + function currencySymbol(): string; + function bitcoinAddress(): string; + function ethereumAddress(): string; + function iban(formatted?: boolean): string; + function bic(): string; + } + + namespace hacker { + function abbreviation(): string; + function adjective(): string; + function noun(): string; + function verb(): string; + function ingverb(): string; + function phrase(): string; + } + + namespace helpers { + function randomize(array: T[]): T; + function randomize(): string; + function slugify(string?: string): string; + function replaceSymbolWithNumber(string?: string, symbol?: string): string; + function replaceSymbols(string?: string): string; + function shuffle(o: T[]): T[]; + function shuffle(): string[]; + function mustache(str: string, data: { [key: string]: string|((substring: string, ...args: any[]) => string) }): string; + function createCard(): I.Card; + function contextualCard(): I.ContextualCard; + function userCard(): I.UserCard; + function createTransaction(): I.Transaction; + } + + namespace image { + function image(): string; + function avatar(): string; + function imageUrl(width?: number, height?: number, category?: string): string; + function abstract(width?: number, height?: number): string; + function animals(width?: number, height?: number): string; + function business(width?: number, height?: number): string; + function cats(width?: number, height?: number): string; + function city(width?: number, height?: number): string; + function food(width?: number, height?: number): string; + function nightlife(width?: number, height?: number): string; + function fashion(width?: number, height?: number): string; + function people(width?: number, height?: number): string; + function nature(width?: number, height?: number): string; + function sports(width?: number, height?: number): string; + function technics(width?: number, height?: number): string; + function transport(width?: number, height?: number): string; + function dataUri(width?: number, height?: number): string; + } + + namespace internet { + function avatar(): string; + function email(firstName?: string, lastName?: string, provider?: string): string; + function exampleEmail(firstName?: string, lastName?: string): string; + function userName(firstName?: string, lastName?: string): string; + function protocol(): string; + function url(): string; + function domainName(): string; + function domainSuffix(): string; + function domainWord(): string; + function ip(): string; + function ipv6(): string; + function userAgent(): string; + function color(baseRed255?: number, baseGreen255?: number, baseBlue255?: number): string; + function mac(): string; + function password(len?: number, memorable?: boolean, pattern?: string|RegExp, prefix?: string): string; + } + + namespace lorem { + function word(): string; + function words(num?: number): string; + function sentence(wordCount?: number, range?: number): string; + function slug(wordCount?: number): string; + function sentences(sentenceCount?: number): string; + function paragraph(sentenceCount?: number): string; + function paragraphs(paragraphCount?: number, separator?: string): string; + function text(times?: number): string; + function lines(lineCount?: number): string; + } + + namespace name { + function firstName(gender?: number): string; + function lastName(gender?: number): string; + function findName(firstName?: string, lastName?: string, gender?: number): string; + function jobTitle(): string; + function prefix(): string; + function suffix(): string; + function title(): string; + function jobDescriptor(): string; + function jobArea(): string; + function jobType(): string; + } + + namespace phone { + function phoneNumber(format?: string): string; + function phoneNumberFormat(phoneFormatsArrayIndex?: number): string; + function phoneFormats(): string; + } + + namespace random { + function number(max: number): number; + function number(options?: { min?: number, max?: number, precision?: number }): number; + function arrayElement(): string; + function arrayElement(array: T[]): T; + function objectElement(object?: { [key: string]: any }, field?: "key"): string; + function objectElement(object?: { [key: string]: T }, field?: any): T; + function uuid(): string; + function boolean(): boolean; + function word(type?: string): string; + function words(count?: number): string; + function image(): string; + function locale(): string; + function alphaNumeric(count?: number): string; + function hexaDecimal(count?: number): string; + } + + namespace system { + function fileName(ext: string, type: string): string; + function commonFileName(ext: string, type: string): string; + function mimeType(): string; + function commonFileType(): string; + function commonFileExt(): string; + function fileType(): string; + function fileExt(mimeType: string): string; + function directoryPath(): string; + function filePath(): string; + function semver(): string; + } + + function seed(value: number): void; + + namespace I { + type Locale = + | "az" + | "cz" + | "de" + | "de_AT" + | "de_CH" + | "el" + | "en" + | "en_AU" + | "en_BORK" + | "en_CA" + | "en_GB" + | "en_IE" + | "en_IND" + | "en_US" + | "en_au_ocker" + | "es" + | "es_MX" + | "fa" + | "fr" + | "fr_CA" + | "ge" + | "id_ID" + | "it" + | "ja" + | "ko" + | "lv" + | "nb_NO" + | "nep" + | "nl" + | "nl_BE" + | "pl" + | "pt_BR" + | "ro" + | "ru" + | "sk" + | "sv" + | "tr" + | "uk" + | "vi" + | "zh_CN" + | "zh_TW"; + } + + function getLocale(): I.Locale; + + function setLocale(locale: I.Locale): void; + } +} diff --git a/types/adone/glosses/is.d.ts b/types/adone/glosses/is.d.ts index 7df9559524..9065da138b 100644 --- a/types/adone/glosses/is.d.ts +++ b/types/adone/glosses/is.d.ts @@ -227,13 +227,13 @@ declare namespace adone { /** * Checks whether the given object is a function */ - function _function(obj: any): boolean; + function _function(obj: any): obj is (...args: any[]) => any; export { _function as function }; /** * Checks whether the given object is an async function */ - export function asyncFunction(obj: any): boolean; + export function asyncFunction(obj: any): obj is (...args: any[]) => Promise; /** * Checks whether the given object is a promise @@ -672,5 +672,9 @@ declare namespace adone { * Checks whether the given object is a valid UUID identifier (v1, v2, v3, v4 or v5) */ export function uuid(obj: any, version?: "all"): obj is string; + + export function emitter(obj: any): obj is event.Emitter; + + export function asyncEmitter(obj: any): obj is event.AsyncEmitter; } } diff --git a/types/adone/index.d.ts b/types/adone/index.d.ts index ad0645f04d..5d22ac1bfd 100644 --- a/types/adone/index.d.ts +++ b/types/adone/index.d.ts @@ -8,12 +8,13 @@ /// /// /// -/// +/// /// /// /// /// /// +/// /// /// /// diff --git a/types/adone/test/glosses/collections.ts b/types/adone/test/glosses/collections.ts deleted file mode 100644 index ec227d4440..0000000000 --- a/types/adone/test/glosses/collections.ts +++ /dev/null @@ -1,1003 +0,0 @@ -namespace collectionTests { - const { collection } = adone; - - namespace linkedListTests { - const { LinkedList } = collection; - - namespace creation { - new LinkedList(); - new LinkedList(10); - } - - namespace properties { - { const a: boolean = new LinkedList().full; } - { const a: boolean = new LinkedList().empty; } - { const a: number = new LinkedList().maxLength; } - { const a: number = new LinkedList().length; } - { const a: boolean = new LinkedList().autoresize; } - } - - namespace resize { - { const a: boolean = new LinkedList().resize(100).full; } - } - - namespace push { - const a = new LinkedList().push(10); - a.next; - a.prev; - const b: number = a.value; - } - - namespace pop { - const a: number | undefined = new LinkedList().pop(); - } - - namespace shift { - const a: number | undefined = new LinkedList().shift(); - } - - namespace unshift { - const a = new LinkedList().unshift("hello"); - a.next; - a.prev; - const b: string = a.value; - } - - namespace pushNode { - const a = new LinkedList(); - const node = a.push("1230"); - a.pushNode(node); - } - - namespace unshiftNode { - const a = new LinkedList(); - const node = a.push(10); - a.unshiftNode(node); - } - - namespace removeNode { - const a = new LinkedList(); - const node = a.unshift("10"); - a.removeNode(node); - } - - namespace clear { - new LinkedList().clear(); - new LinkedList().clear(true); - } - - namespace toArray { - const a = new LinkedList(); - const b: number[] = a.toArray(); - } - - namespace front { - const a = new LinkedList(); - const b: number = a.front; - } - - namespace back { - const a = new LinkedList(); - const b: number = a.back; - } - - namespace iterating { - const a = new LinkedList(); - for (const b of a) { - const i: string = b; - } - const c = new LinkedList(); - for (const b of c) { - const i: number = b; - } - } - - namespace nextNode { - const a = new LinkedList(); - const n1 = a.push("h"); - const n2 = a.nextNode(n1); - n1.next; - n1.prev; - const t: string = n1.value; - } - - namespace map { - const a = new LinkedList(); - const f = (a: number, idx: number) => `${a}${idx}`; - const b = a.map(f); - const c: string = b.front; - } - - namespace forEach { - const a = new LinkedList(); - - a.forEach((a: number, b: number) => { - const c = a + b; - }); - } - - namespace static { - const a: number = LinkedList.DEFAULT_LENGTH; - } - } - - namespace ByteArrayTests { - const { ByteArray } = collection; - - new ByteArray(); - new ByteArray(10); - new ByteArray(10, true); - - const buffer = new ByteArray(); - - namespace readBitSet { - const a: boolean[] = buffer.readBitSet(); - const b: boolean[] = buffer.readBitSet(10); - } - - namespace read { - const a: adone.collection.ByteArray = buffer.read(1); - const b: adone.collection.ByteArray = 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.collection.ByteArray = buffer.write("1"); - const b: adone.collection.ByteArray = buffer.write(new ByteArray()); - const c: adone.collection.ByteArray = buffer.write(Buffer.alloc(10)); - const d: adone.collection.ByteArray = buffer.write(new Uint8Array([1, 2, 3])); - const e: adone.collection.ByteArray = buffer.write(new ArrayBuffer(10)); - const f: adone.collection.ByteArray = buffer.write("1", 10); - const g: adone.collection.ByteArray = buffer.write("1", 10, 10); - const h: adone.collection.ByteArray = buffer.write("1", 10, 10, "utf8"); - } - - namespace writeBitSet { - const a: adone.collection.ByteArray = buffer.writeBitSet([1, 2, 3]); - const b: number = buffer.writeBitSet([1, 2, 3], 10); - } - - namespace writeInt8 { - const a: adone.collection.ByteArray = buffer.writeInt8(10); - const b: adone.collection.ByteArray = buffer.writeInt8(10, 10); - } - - namespace writeUInt8 { - const a: adone.collection.ByteArray = buffer.writeUInt8(10); - const b: adone.collection.ByteArray = buffer.writeUInt8(10, 10); - } - - namespace writeInt16LE { - const a: adone.collection.ByteArray = buffer.writeInt16LE(10); - const b: adone.collection.ByteArray = buffer.writeInt16LE(10, 10); - } - - namespace writeInt16BE { - const a: adone.collection.ByteArray = buffer.writeInt16BE(10); - const b: adone.collection.ByteArray = buffer.writeInt16BE(10, 10); - } - - namespace writeUInt16LE { - const a: adone.collection.ByteArray = buffer.writeUInt16LE(10); - const b: adone.collection.ByteArray = buffer.writeUInt16LE(10, 10); - } - - namespace writeUInt16BE { - const a: adone.collection.ByteArray = buffer.writeUInt16BE(10); - const b: adone.collection.ByteArray = buffer.writeUInt16BE(10, 10); - } - - namespace writeInt32LE { - const a: adone.collection.ByteArray = buffer.writeInt32LE(10); - const b: adone.collection.ByteArray = buffer.writeInt32LE(10, 10); - } - - namespace writeInt32BE { - const a: adone.collection.ByteArray = buffer.writeInt32BE(10); - const b: adone.collection.ByteArray = buffer.writeInt32BE(10, 10); - } - - namespace writeUInt32LE { - const a: adone.collection.ByteArray = buffer.writeUInt32LE(10); - const b: adone.collection.ByteArray = buffer.writeUInt32LE(10, 10); - } - - namespace writeUInt32BE { - const a: adone.collection.ByteArray = buffer.writeUInt32BE(10); - const b: adone.collection.ByteArray = buffer.writeUInt32BE(10, 10); - } - - namespace writeInt64LE { - const a: adone.collection.ByteArray = buffer.writeInt64LE(10); - const b: adone.collection.ByteArray = buffer.writeInt64LE(10, 10); - } - - namespace writeInt64BE { - const a: adone.collection.ByteArray = buffer.writeInt64BE(10); - const b: adone.collection.ByteArray = buffer.writeInt64BE(10, 10); - } - - namespace writeUInt64LE { - const a: adone.collection.ByteArray = buffer.writeUInt64LE(10); - const b: adone.collection.ByteArray = buffer.writeUInt64LE(10, 10); - } - - namespace writeUInt64BE { - const a: adone.collection.ByteArray = buffer.writeUInt64BE(10); - const b: adone.collection.ByteArray = buffer.writeUInt64BE(10, 10); - } - - namespace writeFloatLE { - const a: adone.collection.ByteArray = buffer.writeFloatLE(10); - const b: adone.collection.ByteArray = buffer.writeFloatLE(10, 10); - } - - namespace writeFloatBE { - const a: adone.collection.ByteArray = buffer.writeFloatBE(10); - const b: adone.collection.ByteArray = buffer.writeFloatBE(10, 10); - } - - namespace writeDoubleLE { - const a: adone.collection.ByteArray = buffer.writeDoubleLE(10); - const b: adone.collection.ByteArray = buffer.writeDoubleLE(10, 10); - } - - namespace writeDoubleBE { - const a: adone.collection.ByteArray = buffer.writeDoubleBE(10); - const b: adone.collection.ByteArray = buffer.writeDoubleBE(10, 10); - } - - namespace writeVarInt32 { - const a: adone.collection.ByteArray = buffer.writeVarint32(10); - const b: number = buffer.writeVarint32(10, 10); - } - - namespace writeVarInt32ZigZag { - const a: adone.collection.ByteArray = 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.collection.ByteArray = buffer.writeVarint64(10); - const b: number = buffer.writeVarint64(10, 10); - } - - namespace writeVarint64ZigZag { - const a: adone.collection.ByteArray = 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.collection.ByteArray = 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.collection.ByteArray = 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.collection.ByteArray = 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.collection.ByteArray = buffer.appendTo(new ByteArray()); - const b: adone.collection.ByteArray = buffer.appendTo(new ByteArray(), 10); - } - - namespace assert { - const a: adone.collection.ByteArray = buffer.assert(); - const b: adone.collection.ByteArray = buffer.assert(true); - } - - namespace capacity { - const a: number = buffer.capacity(); - } - - namespace clear { - const a: adone.collection.ByteArray = buffer.clear(); - } - - namespace copy { - const a: adone.collection.ByteArray = buffer.clone(); - const c: adone.collection.ByteArray = buffer.clone(true); - } - - namespace compact { - const a: adone.collection.ByteArray = buffer.compact(); - const b: adone.collection.ByteArray = buffer.compact(1); - const c: adone.collection.ByteArray = buffer.compact(1, 10); - } - - namespace copyTo { - const a: adone.collection.ByteArray = buffer.copyTo(new ByteArray()); - const b: adone.collection.ByteArray = buffer.copyTo(new ByteArray(), 0); - const c: adone.collection.ByteArray = buffer.copyTo(new ByteArray(), 0, 0); - const d: adone.collection.ByteArray = buffer.copyTo(new ByteArray(), 0, 0, 10); - } - - namespace ensureCapacity { - const a: adone.collection.ByteArray = buffer.ensureCapacity(10); - } - - namespace fill { - const a: adone.collection.ByteArray = buffer.fill("0"); - const b: adone.collection.ByteArray = buffer.fill(0); - const c: adone.collection.ByteArray = buffer.fill(0, 0); - const d: adone.collection.ByteArray = buffer.fill(0, 0, 10); - } - - namespace flip { - const a: adone.collection.ByteArray = buffer.flip(); - } - - namespace mark { - const a: adone.collection.ByteArray = buffer.mark(); - const b: adone.collection.ByteArray = buffer.mark(10); - } - - namespace prepend { - const a: adone.collection.ByteArray = buffer.prepend(""); - const b: adone.collection.ByteArray = buffer.prepend(new ByteArray()); - const c: adone.collection.ByteArray = buffer.prepend(Buffer.alloc(10)); - const d: adone.collection.ByteArray = buffer.prepend(new Uint8Array([1, 2, 3])); - const e: adone.collection.ByteArray = buffer.prepend(new ArrayBuffer(10)); - const f: adone.collection.ByteArray = buffer.prepend("", "utf8"); - const g: adone.collection.ByteArray = buffer.prepend("", "utf8", 10); - const h: adone.collection.ByteArray = buffer.prepend("", 10); - } - - namespace prependTo { - const a: adone.collection.ByteArray = buffer.prependTo(new ByteArray()); - const b: adone.collection.ByteArray = buffer.prependTo(new ByteArray(), 10); - } - - namespace remaining { - const a: number = buffer.remaining(); - } - - namespace reset { - const a: adone.collection.ByteArray = buffer.reset(); - } - - namespace resize { - const a: adone.collection.ByteArray = buffer.resize(10); - } - - namespace reverse { - const a: adone.collection.ByteArray = buffer.reverse(); - const b: adone.collection.ByteArray = buffer.reverse(1); - const c: adone.collection.ByteArray = buffer.reverse(1, 10); - } - - namespace skip { - const a: adone.collection.ByteArray = buffer.skip(10); - } - - namespace slice { - const a: adone.collection.ByteArray = buffer.slice(); - const b: adone.collection.ByteArray = buffer.slice(1); - const c: adone.collection.ByteArray = 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 = ByteArray.accessor(); - } - - namespace allocate { - const a: adone.collection.ByteArray = ByteArray.allocate(); - const b: adone.collection.ByteArray = ByteArray.allocate(10); - const c: adone.collection.ByteArray = ByteArray.allocate(10, true); - } - - namespace concat { - const a: adone.collection.ByteArray = ByteArray.concat([ - new ByteArray(), - Buffer.alloc(10), - new Uint8Array([1, 2, 3]), - new ArrayBuffer(10) - ]); - const b: adone.collection.ByteArray = ByteArray.concat([ - new ByteArray(), - Buffer.alloc(10), - new Uint8Array([1, 2, 3]), - new ArrayBuffer(10) - ], "utf8"); - const c: adone.collection.ByteArray = ByteArray.concat([ - new ByteArray(), - Buffer.alloc(10), - new Uint8Array([1, 2, 3]), - new ArrayBuffer(10) - ], "utf8", true); - } - - namespace type { - const a: typeof Buffer = ByteArray.type(); - } - - namespace wrap { - const a: adone.collection.ByteArray = ByteArray.wrap(""); - const b: adone.collection.ByteArray = ByteArray.wrap(new ByteArray()); - const c: adone.collection.ByteArray = ByteArray.wrap(Buffer.alloc(10)); - const d: adone.collection.ByteArray = ByteArray.wrap(new Uint8Array([1, 2, 3])); - const e: adone.collection.ByteArray = ByteArray.wrap(new ArrayBuffer(10)); - const f: adone.collection.ByteArray = ByteArray.wrap("", "utf8"); - const g: adone.collection.ByteArray = ByteArray.wrap("", "utf8", true); - } - - namespace calculateVarint32 { - const a: number = ByteArray.calculateVarint32(10); - } - - namespace zigZagEncode32 { - const a: number = ByteArray.zigZagEncode32(10); - } - - namespace zigZagDecode32 { - const a: number = ByteArray.zigZagDecode32(10); - } - - namespace calculateVarint64 { - const a: number = ByteArray.calculateVarint64(10); - const b: number = ByteArray.calculateVarint64("10"); - } - - namespace zigZagEncode64 { - const a: adone.math.Long = ByteArray.zigZagEncode64(10); - const b: adone.math.Long = ByteArray.zigZagEncode64("10"); - const c: adone.math.Long = ByteArray.zigZagEncode64(adone.math.Long.fromValue(10)); - } - - namespace zigZagDecode64 { - const a: adone.math.Long = ByteArray.zigZagDecode64(10); - const b: adone.math.Long = ByteArray.zigZagDecode64("10"); - const c: adone.math.Long = ByteArray.zigZagDecode64(adone.math.Long.fromValue(10)); - } - - namespace calculateUTF8Chars { - const a: number = ByteArray.calculateUTF8Chars("123"); - } - - namespace calculateString { - const a: number = ByteArray.calculateString("123"); - } - - namespace fromBase64 { - const a: adone.collection.ByteArray = ByteArray.fromBase64("123"); - } - - namespace btoa { - const a: string = ByteArray.btoa("123"); - } - - namespace atob { - const a: string = ByteArray.atob("123"); - } - - namespace fromBinary { - const a: adone.collection.ByteArray = ByteArray.fromBinary("123"); - } - - namespace fromDebug { - const a: adone.collection.ByteArray = ByteArray.fromDebug("12"); - const b: adone.collection.ByteArray = ByteArray.fromDebug("12", true); - } - - namespace fromHex { - const a: adone.collection.ByteArray = ByteArray.fromHex("192"); - const b: adone.collection.ByteArray = ByteArray.fromHex("192", true); - } - - namespace fromUTF8 { - const a: adone.collection.ByteArray = ByteArray.fromUTF8("123"); - const b: adone.collection.ByteArray = ByteArray.fromUTF8("123", true); - } - - namespace constants { - const a: number = ByteArray.DEFAULT_CAPACITY; - const b: boolean = ByteArray.DEFAULT_NOASSERT; - const c: number = ByteArray.MAX_VARINT32_BYTES; - const d: number = ByteArray.MAX_VARINT64_BYTES; - const e: string = ByteArray.METRICS_CHARS; - const f: string = ByteArray.METRICS_BYTES; - } - } - } - - namespace queueTests { - const { Queue } = collection; - type Queue = adone.collection.Queue; - - new Queue(); - { const a: Queue = new Queue().push(123).push(123); } - { const a: number | undefined = new Queue().push(123).pop(); } - { const a: string | undefined = new Queue().push(123).pop(); } - { const a: boolean = new Queue().full; } - { const a: number = new Queue().length; } - { const a: boolean = new Queue().empty; } - } - - namespace asyncQueueTests { - const { AsyncQueue } = collection; - type AsyncQueue = adone.collection.AsyncQueue; - - { const a: AsyncQueue = new AsyncQueue().push(123); } - { const a: Promise = new AsyncQueue().push(123).pop(); } - } - - namespace priorityQueueTests { - const { PriorityQueue } = collection; - type PriorityQueue = adone.collection.PriorityQueue; - - { const a: boolean = new PriorityQueue().empty; } - { const a: number = new PriorityQueue().length; } - new PriorityQueue(); - new PriorityQueue({}); - new PriorityQueue({ - compare(a: number, b: number) { - return a - b; - } - }); - new PriorityQueue({ - priority(a: string, b: string) { - return a.length - b.length; - } - }); - { const a: PriorityQueue = new PriorityQueue().clone(); } - { const a: PriorityQueue = new PriorityQueue().push("123"); } - { const a: string | undefined = new PriorityQueue().pop(); } - { const a: PriorityQueue = new PriorityQueue().delete("123"); } - { const a: PriorityQueue = new PriorityQueue().delete("123"); } - { const a: string = new PriorityQueue().replace("123"); } - { const a: string = new PriorityQueue().pushpop("123"); } - { const a: string[] = new PriorityQueue().toArray(); } - { const a: PriorityQueue = PriorityQueue.from(["1"]); } - { const a: PriorityQueue = PriorityQueue.from(["1"], {}); } - { const a: PriorityQueue = PriorityQueue.from(["1"], { compare: (a: string, b: string) => a.length - b.length }); } - { const a: PriorityQueue = PriorityQueue.from(["1"], { priority: (a: string, b: string) => a.length - b.length }); } - } - - namespace fastlruTests { - const { FastLRU } = collection; - - new FastLRU(); - new FastLRU(100); - new FastLRU(100, { dispose: (key: string, value: number) => null }); - { const a: number = new FastLRU().size; } - { const a: number | undefined = new FastLRU().get("key"); } - new FastLRU().set("key", 123); - { const a: boolean = new FastLRU().delete("key"); } - { const a: boolean = new FastLRU().has("key"); } - { const a: string[] = [...new FastLRU().keys()]; } - { const a: number[] = [...new FastLRU().values()]; } - { const a: number[] = [...new FastLRU().values()]; } - { const a: Array<[string, number]> = [...new FastLRU().entries()]; } - new FastLRU().clear(); - } - - namespace stackTests { - const { Stack } = collection; - type Stack = adone.collection.Stack; - - { const a: boolean = new Stack().empty; } - { const a: number = new Stack().top; } - { const a: Stack = new Stack().push(123); } - { const a: number | undefined = new Stack().pop(); } - { const a: number[] = [...new Stack()]; } - { const a: Stack = Stack.from([1, 2, 3]); } - } - - namespace binarySearchTreeTests { - const { BinarySearchTree } = collection; - type BinarySearchTree = adone.collection.BinarySearchTree; - - new BinarySearchTree(); - new BinarySearchTree({}); - new BinarySearchTree({ checkValueEquality: (a: number, b: number) => a === b }); - new BinarySearchTree({ compareKeys: (a: string, b: string) => a.length - b.length }); - new BinarySearchTree({ parent: new BinarySearchTree() }); - new BinarySearchTree({ unique: true }); - new BinarySearchTree({ value: 123 }); - { const a: BinarySearchTree = new BinarySearchTree().getMaxKeyDescendant(); } - { const a: string = new BinarySearchTree().getMaxKey(); } - { const a: BinarySearchTree = new BinarySearchTree().getMinKeyDescendant(); } - { const a: string = new BinarySearchTree().getMinKey(); } - new BinarySearchTree().checkAllNodesFullfillCondition((key: string, value: number) => null); - new BinarySearchTree().checkIsBST(); - { const a: number = new BinarySearchTree().getNumberOfKeys(); } - new BinarySearchTree().insert("asd", 123); - { const a: number[] = new BinarySearchTree().search("asd"); } - { const a: number[] = new BinarySearchTree().betweenBounds({ $gt: "" }); } - { const a: number[] = new BinarySearchTree().betweenBounds({ $lt: "" }); } - { const a: number[] = new BinarySearchTree().betweenBounds({ $lte: "" }); } - { const a: number[] = new BinarySearchTree().betweenBounds({ $gte: "" }); } - new BinarySearchTree().delete("key"); - new BinarySearchTree().delete("key", 123); - new BinarySearchTree().executeOnEveryNode((tree: BinarySearchTree) => null); - new BinarySearchTree().prettyPrint(); - new BinarySearchTree().prettyPrint(true); - new BinarySearchTree().prettyPrint(true, " "); - } - - namespace avlTreeTests { - const { AVLTree } = collection; - type AVLTree = adone.collection.AVLTree; - - new AVLTree(); - new AVLTree({ checkValueEquality: (a: number, b: number) => a === b }); - new AVLTree({ compareKeys: (a: string, b: string) => a.length - b.length }); - new AVLTree({ parent: new AVLTree() }); - new AVLTree({ unique: false }); - new AVLTree({ value: 123 }); - new AVLTree().checkIsAVLT(); - new AVLTree().insert("123", 123); - new AVLTree().delete("123"); - new AVLTree().delete("123", 123); - { const a: number = new AVLTree().getNumberOFKeys(); } - { const a: number[] = new AVLTree().search("key"); } - { const a: number[] = new AVLTree().betweenBounds({}); } - { const a: number[] = new AVLTree().betweenBounds({ $gt: "ads" }); } - { const a: number[] = new AVLTree().betweenBounds({ $lt: "ads" }); } - { const a: number[] = new AVLTree().betweenBounds({ $gte: "ads" }); } - { const a: number[] = new AVLTree().betweenBounds({ $lte: "ads" }); } - new AVLTree().executeOnEveryNode((tree: AVLTree) => null); - } - - namespace redBlackTreeTests { - const { RedBlackTree } = collection; - type RedBlackTree = adone.collection.RedBlackTree; - type RedBlackTreeIterator = adone.collection.I.RedBlackTree.Iterator; - type RedBlackTreeNode = adone.collection.I.RedBlackTree.Node; - - new RedBlackTree(); - new RedBlackTree((a: string, b: string) => a.length - b.length); - new RedBlackTree(undefined, new RedBlackTree()); - { const a: string[] = new RedBlackTree().keys; } - { const a: number[] = new RedBlackTree().values; } - { const a: number = new RedBlackTree().length; } - { - const a: RedBlackTreeIterator = new RedBlackTree().begin; - { const b: boolean = a.valid; } - { const b: RedBlackTreeNode | null = a.node; } - { const b: string | undefined = a.key; } - { const b: number | undefined = a.value; } - { const b: number = a.index; } - { const b: boolean = a.hasNext; } - { const b: boolean = a.hasPrev; } - { const b: RedBlackTree = a.tree; } - { const b: RedBlackTreeIterator = a.clone(); } - { const b: RedBlackTree = a.remove(); } - a.next(); - { const b: RedBlackTree = a.update(333); } - a.prev(); - } - { const a: RedBlackTreeIterator = new RedBlackTree().end; } - { const a: RedBlackTree = new RedBlackTree().insert("123", 456); } - { const a: number = new RedBlackTree().forEach((key: string, value: number) => value); } - { const a: number = new RedBlackTree().forEach((key: string, value: number) => value, "1"); } - { const a: number = new RedBlackTree().forEach((key: string, value: number) => value, "1", "2"); } - { const a: RedBlackTreeIterator = new RedBlackTree().at(1); } - { const a: RedBlackTreeIterator = new RedBlackTree().ge("1"); } - { const a: RedBlackTreeIterator = new RedBlackTree().gt("1"); } - { const a: RedBlackTreeIterator = new RedBlackTree().lt("1"); } - { const a: RedBlackTreeIterator = new RedBlackTree().le("1"); } - { const a: RedBlackTreeIterator | null = new RedBlackTree().find("1"); } - { const a: RedBlackTree = new RedBlackTree().remove("1"); } - { const a: RedBlackTree = new RedBlackTree().remove("1"); } - { const a: number | undefined = new RedBlackTree().get("1"); } - } - - namespace arraySetTests { - const { ArraySet } = collection; - type ArraySet = adone.collection.ArraySet; - - new ArraySet(); - { const a: number = new ArraySet().length; } - { const a: ArraySet = new ArraySet().add("hello"); } - { const a: ArraySet = new ArraySet().add("hello", true); } - { const a: boolean = new ArraySet().has("string"); } - { const a: number = new ArraySet().indexOf("hello"); } - { const a: string[] = new ArraySet().toArray(); } - { const a: ArraySet = ArraySet.from([1]); } - { const a: ArraySet = ArraySet.from([1], true); } - } - - namespace bufferListTests { - const { BufferList } = collection; - type BufferList = adone.collection.BufferList; - - new BufferList(); - new BufferList(Buffer.from("123")); - new BufferList("123"); - new BufferList(123); - new BufferList([Buffer.from("123"), "123", 123]); - new BufferList((err: any, data: Buffer) => null); - new BufferList().append(Buffer.from("123")); - new BufferList().append("123"); - new BufferList().append(123); - new BufferList().append([Buffer.from("123"), "123", 123]); - new BufferList().end(Buffer.from("123")); - new BufferList().end(); - { const a: number = new BufferList().get(123); } - { const a: Buffer = new BufferList().slice(); } - { const a: Buffer = new BufferList().slice(1); } - { const a: Buffer = new BufferList().slice(1, 2); } - { const a: Buffer = new BufferList().copy(Buffer.alloc(100)); } - { const a: Buffer = new BufferList().copy(Buffer.alloc(100), 0); } - { const a: Buffer = new BufferList().copy(Buffer.alloc(100), 0, 1); } - { const a: Buffer = new BufferList().copy(Buffer.alloc(100), 0, 1, 2); } - { const a: BufferList = new BufferList().shallowSlice(); } - { const a: BufferList = new BufferList().shallowSlice(1); } - { const a: BufferList = new BufferList().shallowSlice(1, 2); } - { const a: string = new BufferList().toString(); } - { const a: string = new BufferList().toString("utf8"); } - { const a: string = new BufferList().toString("utf8", 1); } - { const a: string = new BufferList().toString("utf8", 1, 2); } - { const a: BufferList = new BufferList().consume(10); } - { const a: BufferList = new BufferList().duplicate(); } - new BufferList().destroy(); - new BufferList().then((x: Buffer) => null); - new BufferList().catch((err: any) => null); - } - - namespace defaultMapTests { - const { DefaultMap } = collection; - type DefaultMap = adone.collection.DefaultMap; - - new DefaultMap(); - { const a: DefaultMap = new DefaultMap(undefined, [["1", 2]]); } - { const a: DefaultMap = new DefaultMap((key: string) => 123); } - { const a: DefaultMap = new DefaultMap({ a: 123 }); } - } - - namespace lruTests { - const { LRU } = collection; - type LRU = adone.collection.LRU; - - new LRU(); - new LRU(100); - new LRU({}); - new LRU({ max: 100 }); - new LRU({ dispose: (key: string, value: number) => null }); - new LRU({ maxAge: 100 }); - new LRU({ noDisposeOnSet: false }); - new LRU({ stale: true }); - { const a: number = new LRU().max; } - { new LRU().max = 100; } - { const a: boolean = new LRU().allowStale; } - { new LRU().allowStale = false; } - { const a: number = new LRU().maxAge; } - { new LRU().maxAge = 100; } - { const a: (v: number, k: string) => number = new LRU().lengthCalculator; } - { new LRU().lengthCalculator = () => 123; } - { const a: number = new LRU().length; } - { const a: number = new LRU().itemCount; } - new LRU().rforEach((value: number, key: string) => null); - new LRU().rforEach(function (value: number, key: string) { - const b: number = this.a; - }, { a: 1 }); - new LRU().forEach((value: number, key: string) => null); - new LRU().forEach(function (value: number, key: string) { - const b: number = this.a; - }, { a: 1 }); - { const a: string[] = new LRU().keys(); } - { const a: number[] = new LRU().values(); } - new LRU().reset(); - { - const a: Array> = new LRU().dump(); - const [b] = a; - { const c: number = b.e; } - { const c: string = b.key; } - { const c: number = b.value; } - } - { - const a: adone.collection.LinkedList> = new LRU().dumpLru(); - const b = a.shift(); - if (b !== undefined) { - { const a: string = b.key; } - { const a: number = b.value; } - { const a: number = b.now; } - { const a: number = b.maxAge; } - } - } - { const a: string = new LRU().inspect(); } - { const a: string = new LRU().inspect({}); } - { const a: boolean = new LRU().set("asd", 13); } - { const a: boolean = new LRU().set("asd", 13, 100500); } - { const a: boolean = new LRU().has("asd"); } - { const a: number | undefined = new LRU().get("asd"); } - { const a: number | undefined = new LRU().peek("asd"); } - { const a: adone.collection.I.LRU.Entry = new LRU().pop(); } - new LRU().del("asd"); - new LRU().load(new LRU().dump()); - new LRU().prune(); - } - - namespace timedoutMapTests { - const { TimedoutMap } = collection; - type TimedoutMap = adone.collection.TimedoutMap; - - new TimedoutMap(); - new TimedoutMap(1000); - new TimedoutMap(1000, (key: string) => null); - { - const a: TimedoutMap = new TimedoutMap().forEach((value: number, key: string) => null); - } - { - const a: TimedoutMap = new TimedoutMap().forEach(function (value: number, key: string) { - const a: number = this.a; - }, { a: 1 }); - } - { const a: boolean = new TimedoutMap().delete("123"); } - } -} diff --git a/types/adone/test/glosses/collections/array_set.ts b/types/adone/test/glosses/collections/array_set.ts new file mode 100644 index 0000000000..49fd8582ce --- /dev/null +++ b/types/adone/test/glosses/collections/array_set.ts @@ -0,0 +1,19 @@ +namespace adoneTests.collection.ArraySet { + const { + collection: { + ArraySet + } + } = adone; + + type ArraySet = adone.collection.ArraySet; + + new ArraySet(); + { const a: number = new ArraySet().length; } + { const a: ArraySet = new ArraySet().add("hello"); } + { const a: ArraySet = new ArraySet().add("hello", true); } + { const a: boolean = new ArraySet().has("string"); } + { const a: number = new ArraySet().indexOf("hello"); } + { const a: string[] = new ArraySet().toArray(); } + { const a: ArraySet = ArraySet.from([1]); } + { const a: ArraySet = ArraySet.from([1], true); } +} diff --git a/types/adone/test/glosses/collections/async_queue.ts b/types/adone/test/glosses/collections/async_queue.ts new file mode 100644 index 0000000000..43374e6d3a --- /dev/null +++ b/types/adone/test/glosses/collections/async_queue.ts @@ -0,0 +1,12 @@ +namespace adoneTests.collection.AsyncQueue { + const { + collection: { + AsyncQueue + } + } = adone; + + type AsyncQueue = adone.collection.AsyncQueue; + + { const a: AsyncQueue = new AsyncQueue().push(123); } + { const a: Promise = new AsyncQueue().push(123).pop(); } +} diff --git a/types/adone/test/glosses/collections/avl_tree.ts b/types/adone/test/glosses/collections/avl_tree.ts new file mode 100644 index 0000000000..9c032deb2d --- /dev/null +++ b/types/adone/test/glosses/collections/avl_tree.ts @@ -0,0 +1,28 @@ +namespace adoneTests.collection.AVLTree { + const { + collection: { + AVLTree + } + } = adone; + + type AVLTree = adone.collection.AVLTree; + + new AVLTree(); + new AVLTree({ checkValueEquality: (a: number, b: number) => a === b }); + new AVLTree({ compareKeys: (a: string, b: string) => a.length - b.length }); + new AVLTree({ parent: new AVLTree() }); + new AVLTree({ unique: false }); + new AVLTree({ value: 123 }); + new AVLTree().checkIsAVLT(); + new AVLTree().insert("123", 123); + new AVLTree().delete("123"); + new AVLTree().delete("123", 123); + { const a: number = new AVLTree().getNumberOFKeys(); } + { const a: number[] = new AVLTree().search("key"); } + { const a: number[] = new AVLTree().betweenBounds({}); } + { const a: number[] = new AVLTree().betweenBounds({ $gt: "ads" }); } + { const a: number[] = new AVLTree().betweenBounds({ $lt: "ads" }); } + { const a: number[] = new AVLTree().betweenBounds({ $gte: "ads" }); } + { const a: number[] = new AVLTree().betweenBounds({ $lte: "ads" }); } + new AVLTree().executeOnEveryNode((tree: AVLTree) => null); +} diff --git a/types/adone/test/glosses/collections/binary_search_tree.ts b/types/adone/test/glosses/collections/binary_search_tree.ts new file mode 100644 index 0000000000..56f9a28e72 --- /dev/null +++ b/types/adone/test/glosses/collections/binary_search_tree.ts @@ -0,0 +1,36 @@ +namespace adoneTests.collection.BinarySearchTree { + const { + collection: { + BinarySearchTree + } + } = adone; + + type BinarySearchTree = adone.collection.BinarySearchTree; + + new BinarySearchTree(); + new BinarySearchTree({}); + new BinarySearchTree({ checkValueEquality: (a: number, b: number) => a === b }); + new BinarySearchTree({ compareKeys: (a: string, b: string) => a.length - b.length }); + new BinarySearchTree({ parent: new BinarySearchTree() }); + new BinarySearchTree({ unique: true }); + new BinarySearchTree({ value: 123 }); + { const a: BinarySearchTree = new BinarySearchTree().getMaxKeyDescendant(); } + { const a: string = new BinarySearchTree().getMaxKey(); } + { const a: BinarySearchTree = new BinarySearchTree().getMinKeyDescendant(); } + { const a: string = new BinarySearchTree().getMinKey(); } + new BinarySearchTree().checkAllNodesFullfillCondition((key: string, value: number) => null); + new BinarySearchTree().checkIsBST(); + { const a: number = new BinarySearchTree().getNumberOfKeys(); } + new BinarySearchTree().insert("asd", 123); + { const a: number[] = new BinarySearchTree().search("asd"); } + { const a: number[] = new BinarySearchTree().betweenBounds({ $gt: "" }); } + { const a: number[] = new BinarySearchTree().betweenBounds({ $lt: "" }); } + { const a: number[] = new BinarySearchTree().betweenBounds({ $lte: "" }); } + { const a: number[] = new BinarySearchTree().betweenBounds({ $gte: "" }); } + new BinarySearchTree().delete("key"); + new BinarySearchTree().delete("key", 123); + new BinarySearchTree().executeOnEveryNode((tree: BinarySearchTree) => null); + new BinarySearchTree().prettyPrint(); + new BinarySearchTree().prettyPrint(true); + new BinarySearchTree().prettyPrint(true, " "); +} diff --git a/types/adone/test/glosses/collections/buffer_list.ts b/types/adone/test/glosses/collections/buffer_list.ts new file mode 100644 index 0000000000..265d54033f --- /dev/null +++ b/types/adone/test/glosses/collections/buffer_list.ts @@ -0,0 +1,42 @@ +namespace adoneTests.collection.BufferList { + const { + collection: { + BufferList + } + } = adone; + + type BufferList = adone.collection.BufferList; + + new BufferList(); + new BufferList(Buffer.from("123")); + new BufferList("123"); + new BufferList(123); + new BufferList([Buffer.from("123"), "123", 123]); + new BufferList((err: any, data: Buffer) => null); + new BufferList().append(Buffer.from("123")); + new BufferList().append("123"); + new BufferList().append(123); + new BufferList().append([Buffer.from("123"), "123", 123]); + new BufferList().end(Buffer.from("123")); + new BufferList().end(); + { const a: number = new BufferList().get(123); } + { const a: Buffer = new BufferList().slice(); } + { const a: Buffer = new BufferList().slice(1); } + { const a: Buffer = new BufferList().slice(1, 2); } + { const a: Buffer = new BufferList().copy(Buffer.alloc(100)); } + { const a: Buffer = new BufferList().copy(Buffer.alloc(100), 0); } + { const a: Buffer = new BufferList().copy(Buffer.alloc(100), 0, 1); } + { const a: Buffer = new BufferList().copy(Buffer.alloc(100), 0, 1, 2); } + { const a: BufferList = new BufferList().shallowSlice(); } + { const a: BufferList = new BufferList().shallowSlice(1); } + { const a: BufferList = new BufferList().shallowSlice(1, 2); } + { const a: string = new BufferList().toString(); } + { const a: string = new BufferList().toString("utf8"); } + { const a: string = new BufferList().toString("utf8", 1); } + { const a: string = new BufferList().toString("utf8", 1, 2); } + { const a: BufferList = new BufferList().consume(10); } + { const a: BufferList = new BufferList().duplicate(); } + new BufferList().destroy(); + new BufferList().then((x: Buffer) => null); + new BufferList().catch((err: any) => null); +} diff --git a/types/adone/test/glosses/collections/byte_array.ts b/types/adone/test/glosses/collections/byte_array.ts new file mode 100644 index 0000000000..7254008322 --- /dev/null +++ b/types/adone/test/glosses/collections/byte_array.ts @@ -0,0 +1,561 @@ +namespace adoneTests.collection.ByteArray { + const { + collection: { + ByteArray + } + } = adone; + + new ByteArray(); + new ByteArray(10); + new ByteArray(10, true); + + const buffer = new ByteArray(); + + buffer.woffset === 2; + buffer.roffset === 3; + buffer.noAssert === true; + buffer.buffer.writeUInt8(0, 0); + + namespace readBitSet { + const a: boolean[] = buffer.readBitSet(); + const b: boolean[] = buffer.readBitSet(10); + } + + namespace read { + const a: adone.collection.ByteArray = buffer.read(1); + const b: adone.collection.ByteArray = 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.collection.ByteArray = buffer.write("1"); + const b: adone.collection.ByteArray = buffer.write(new ByteArray()); + const c: adone.collection.ByteArray = buffer.write(Buffer.alloc(10)); + const d: adone.collection.ByteArray = buffer.write(new Uint8Array([1, 2, 3])); + const e: adone.collection.ByteArray = buffer.write(new ArrayBuffer(10)); + const f: adone.collection.ByteArray = buffer.write("1", 10); + const g: adone.collection.ByteArray = buffer.write("1", 10, 10); + const h: adone.collection.ByteArray = buffer.write("1", 10, 10, "utf8"); + } + + namespace writeBitSet { + const a: adone.collection.ByteArray = buffer.writeBitSet([1, 2, 3]); + const b: number = buffer.writeBitSet([1, 2, 3], 10); + } + + namespace writeInt8 { + const a: adone.collection.ByteArray = buffer.writeInt8(10); + const b: adone.collection.ByteArray = buffer.writeInt8(10, 10); + } + + namespace writeUInt8 { + const a: adone.collection.ByteArray = buffer.writeUInt8(10); + const b: adone.collection.ByteArray = buffer.writeUInt8(10, 10); + } + + namespace writeInt16LE { + const a: adone.collection.ByteArray = buffer.writeInt16LE(10); + const b: adone.collection.ByteArray = buffer.writeInt16LE(10, 10); + } + + namespace writeInt16BE { + const a: adone.collection.ByteArray = buffer.writeInt16BE(10); + const b: adone.collection.ByteArray = buffer.writeInt16BE(10, 10); + } + + namespace writeUInt16LE { + const a: adone.collection.ByteArray = buffer.writeUInt16LE(10); + const b: adone.collection.ByteArray = buffer.writeUInt16LE(10, 10); + } + + namespace writeUInt16BE { + const a: adone.collection.ByteArray = buffer.writeUInt16BE(10); + const b: adone.collection.ByteArray = buffer.writeUInt16BE(10, 10); + } + + namespace writeInt32LE { + const a: adone.collection.ByteArray = buffer.writeInt32LE(10); + const b: adone.collection.ByteArray = buffer.writeInt32LE(10, 10); + } + + namespace writeInt32BE { + const a: adone.collection.ByteArray = buffer.writeInt32BE(10); + const b: adone.collection.ByteArray = buffer.writeInt32BE(10, 10); + } + + namespace writeUInt32LE { + const a: adone.collection.ByteArray = buffer.writeUInt32LE(10); + const b: adone.collection.ByteArray = buffer.writeUInt32LE(10, 10); + } + + namespace writeUInt32BE { + const a: adone.collection.ByteArray = buffer.writeUInt32BE(10); + const b: adone.collection.ByteArray = buffer.writeUInt32BE(10, 10); + } + + namespace writeInt64LE { + const a: adone.collection.ByteArray = buffer.writeInt64LE(10); + const b: adone.collection.ByteArray = buffer.writeInt64LE(10, 10); + } + + namespace writeInt64BE { + const a: adone.collection.ByteArray = buffer.writeInt64BE(10); + const b: adone.collection.ByteArray = buffer.writeInt64BE(10, 10); + } + + namespace writeUInt64LE { + const a: adone.collection.ByteArray = buffer.writeUInt64LE(10); + const b: adone.collection.ByteArray = buffer.writeUInt64LE(10, 10); + } + + namespace writeUInt64BE { + const a: adone.collection.ByteArray = buffer.writeUInt64BE(10); + const b: adone.collection.ByteArray = buffer.writeUInt64BE(10, 10); + } + + namespace writeFloatLE { + const a: adone.collection.ByteArray = buffer.writeFloatLE(10); + const b: adone.collection.ByteArray = buffer.writeFloatLE(10, 10); + } + + namespace writeFloatBE { + const a: adone.collection.ByteArray = buffer.writeFloatBE(10); + const b: adone.collection.ByteArray = buffer.writeFloatBE(10, 10); + } + + namespace writeDoubleLE { + const a: adone.collection.ByteArray = buffer.writeDoubleLE(10); + const b: adone.collection.ByteArray = buffer.writeDoubleLE(10, 10); + } + + namespace writeDoubleBE { + const a: adone.collection.ByteArray = buffer.writeDoubleBE(10); + const b: adone.collection.ByteArray = buffer.writeDoubleBE(10, 10); + } + + namespace writeVarInt32 { + const a: adone.collection.ByteArray = buffer.writeVarint32(10); + const b: number = buffer.writeVarint32(10, 10); + } + + namespace writeVarInt32ZigZag { + const a: adone.collection.ByteArray = 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.collection.ByteArray = buffer.writeVarint64(10); + const b: number = buffer.writeVarint64(10, 10); + } + + namespace writeVarint64ZigZag { + const a: adone.collection.ByteArray = 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.collection.ByteArray = 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.collection.ByteArray = 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.collection.ByteArray = 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.collection.ByteArray = buffer.appendTo(new ByteArray()); + const b: adone.collection.ByteArray = buffer.appendTo(new ByteArray(), 10); + } + + namespace assert { + const a: adone.collection.ByteArray = buffer.assert(); + const b: adone.collection.ByteArray = buffer.assert(true); + } + + namespace capacity { + const a: number = buffer.capacity(); + } + + namespace clear { + const a: adone.collection.ByteArray = buffer.clear(); + } + + namespace copy { + const a: adone.collection.ByteArray = buffer.clone(); + const c: adone.collection.ByteArray = buffer.clone(true); + } + + namespace compact { + const a: adone.collection.ByteArray = buffer.compact(); + const b: adone.collection.ByteArray = buffer.compact(1); + const c: adone.collection.ByteArray = buffer.compact(1, 10); + } + + namespace copyTo { + const a: adone.collection.ByteArray = buffer.copyTo(new ByteArray()); + const b: adone.collection.ByteArray = buffer.copyTo(new ByteArray(), 0); + const c: adone.collection.ByteArray = buffer.copyTo(new ByteArray(), 0, 0); + const d: adone.collection.ByteArray = buffer.copyTo(new ByteArray(), 0, 0, 10); + } + + namespace ensureCapacity { + const a: adone.collection.ByteArray = buffer.ensureCapacity(10); + } + + namespace fill { + const a: adone.collection.ByteArray = buffer.fill("0"); + const b: adone.collection.ByteArray = buffer.fill(0); + const c: adone.collection.ByteArray = buffer.fill(0, 0); + const d: adone.collection.ByteArray = buffer.fill(0, 0, 10); + } + + namespace flip { + const a: adone.collection.ByteArray = buffer.flip(); + } + + namespace mark { + const a: adone.collection.ByteArray = buffer.mark(); + const b: adone.collection.ByteArray = buffer.mark(10); + } + + namespace prepend { + const a: adone.collection.ByteArray = buffer.prepend(""); + const b: adone.collection.ByteArray = buffer.prepend(new ByteArray()); + const c: adone.collection.ByteArray = buffer.prepend(Buffer.alloc(10)); + const d: adone.collection.ByteArray = buffer.prepend(new Uint8Array([1, 2, 3])); + const e: adone.collection.ByteArray = buffer.prepend(new ArrayBuffer(10)); + const f: adone.collection.ByteArray = buffer.prepend("", "utf8"); + const g: adone.collection.ByteArray = buffer.prepend("", "utf8", 10); + const h: adone.collection.ByteArray = buffer.prepend("", 10); + } + + namespace prependTo { + const a: adone.collection.ByteArray = buffer.prependTo(new ByteArray()); + const b: adone.collection.ByteArray = buffer.prependTo(new ByteArray(), 10); + } + + namespace remaining { + const a: number = buffer.remaining(); + } + + namespace reset { + const a: adone.collection.ByteArray = buffer.reset(); + } + + namespace resize { + const a: adone.collection.ByteArray = buffer.resize(10); + } + + namespace reverse { + const a: adone.collection.ByteArray = buffer.reverse(); + const b: adone.collection.ByteArray = buffer.reverse(1); + const c: adone.collection.ByteArray = buffer.reverse(1, 10); + } + + namespace skip { + const a: adone.collection.ByteArray = buffer.skip(10); + } + + namespace slice { + const a: adone.collection.ByteArray = buffer.slice(); + const b: adone.collection.ByteArray = buffer.slice(1); + const c: adone.collection.ByteArray = 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 = ByteArray.accessor(); + } + + namespace allocate { + const a: adone.collection.ByteArray = ByteArray.allocate(); + const b: adone.collection.ByteArray = ByteArray.allocate(10); + const c: adone.collection.ByteArray = ByteArray.allocate(10, true); + } + + namespace concat { + const a: adone.collection.ByteArray = ByteArray.concat([ + new ByteArray(), + Buffer.alloc(10), + new Uint8Array([1, 2, 3]), + new ArrayBuffer(10) + ]); + const b: adone.collection.ByteArray = ByteArray.concat([ + new ByteArray(), + Buffer.alloc(10), + new Uint8Array([1, 2, 3]), + new ArrayBuffer(10) + ], "utf8"); + const c: adone.collection.ByteArray = ByteArray.concat([ + new ByteArray(), + Buffer.alloc(10), + new Uint8Array([1, 2, 3]), + new ArrayBuffer(10) + ], "utf8", true); + } + + namespace type { + const a: typeof Buffer = ByteArray.type(); + } + + namespace wrap { + const a: adone.collection.ByteArray = ByteArray.wrap(""); + const b: adone.collection.ByteArray = ByteArray.wrap(new ByteArray()); + const c: adone.collection.ByteArray = ByteArray.wrap(Buffer.alloc(10)); + const d: adone.collection.ByteArray = ByteArray.wrap(new Uint8Array([1, 2, 3])); + const e: adone.collection.ByteArray = ByteArray.wrap(new ArrayBuffer(10)); + const f: adone.collection.ByteArray = ByteArray.wrap("", "utf8"); + const g: adone.collection.ByteArray = ByteArray.wrap("", "utf8", true); + } + + namespace calculateVarint32 { + const a: number = ByteArray.calculateVarint32(10); + } + + namespace zigZagEncode32 { + const a: number = ByteArray.zigZagEncode32(10); + } + + namespace zigZagDecode32 { + const a: number = ByteArray.zigZagDecode32(10); + } + + namespace calculateVarint64 { + const a: number = ByteArray.calculateVarint64(10); + const b: number = ByteArray.calculateVarint64("10"); + } + + namespace zigZagEncode64 { + const a: adone.math.Long = ByteArray.zigZagEncode64(10); + const b: adone.math.Long = ByteArray.zigZagEncode64("10"); + const c: adone.math.Long = ByteArray.zigZagEncode64(adone.math.Long.fromValue(10)); + } + + namespace zigZagDecode64 { + const a: adone.math.Long = ByteArray.zigZagDecode64(10); + const b: adone.math.Long = ByteArray.zigZagDecode64("10"); + const c: adone.math.Long = ByteArray.zigZagDecode64(adone.math.Long.fromValue(10)); + } + + namespace calculateUTF8Chars { + const a: number = ByteArray.calculateUTF8Chars("123"); + } + + namespace calculateString { + const a: number = ByteArray.calculateString("123"); + } + + namespace fromBase64 { + const a: adone.collection.ByteArray = ByteArray.fromBase64("123"); + } + + namespace btoa { + const a: string = ByteArray.btoa("123"); + } + + namespace atob { + const a: string = ByteArray.atob("123"); + } + + namespace fromBinary { + const a: adone.collection.ByteArray = ByteArray.fromBinary("123"); + } + + namespace fromDebug { + const a: adone.collection.ByteArray = ByteArray.fromDebug("12"); + const b: adone.collection.ByteArray = ByteArray.fromDebug("12", true); + } + + namespace fromHex { + const a: adone.collection.ByteArray = ByteArray.fromHex("192"); + const b: adone.collection.ByteArray = ByteArray.fromHex("192", true); + } + + namespace fromUTF8 { + const a: adone.collection.ByteArray = ByteArray.fromUTF8("123"); + const b: adone.collection.ByteArray = ByteArray.fromUTF8("123", true); + } + + namespace constants { + const a: number = ByteArray.DEFAULT_CAPACITY; + const b: boolean = ByteArray.DEFAULT_NOASSERT; + const c: number = ByteArray.MAX_VARINT32_BYTES; + const d: number = ByteArray.MAX_VARINT64_BYTES; + const e: string = ByteArray.METRICS_CHARS; + const f: string = ByteArray.METRICS_BYTES; + } + } +} diff --git a/types/adone/test/glosses/collections/default_map.ts b/types/adone/test/glosses/collections/default_map.ts new file mode 100644 index 0000000000..1273b91982 --- /dev/null +++ b/types/adone/test/glosses/collections/default_map.ts @@ -0,0 +1,14 @@ +namespace adoneTests.collection.DefaultMap { + const { + collection: { + DefaultMap + } + } = adone; + + type DefaultMap = adone.collection.DefaultMap; + + new DefaultMap(); + { const a: DefaultMap = new DefaultMap(undefined, [["1", 2]]); } + { const a: DefaultMap = new DefaultMap((key: string) => 123); } + { const a: DefaultMap = new DefaultMap({ a: 123 }); } +} diff --git a/types/adone/test/glosses/collections/fast_lru.ts b/types/adone/test/glosses/collections/fast_lru.ts new file mode 100644 index 0000000000..0e61f51dc5 --- /dev/null +++ b/types/adone/test/glosses/collections/fast_lru.ts @@ -0,0 +1,21 @@ +namespace adoneTests.collection.FastLRU { + const { + collection: { + FastLRU + } + } = adone; + + new FastLRU(); + new FastLRU(100); + new FastLRU(100, { dispose: (key: string, value: number) => null }); + { const a: number = new FastLRU().size; } + { const a: number | undefined = new FastLRU().get("key"); } + new FastLRU().set("key", 123); + { const a: boolean = new FastLRU().delete("key"); } + { const a: boolean = new FastLRU().has("key"); } + { const a: string[] = [...new FastLRU().keys()]; } + { const a: number[] = [...new FastLRU().values()]; } + { const a: number[] = [...new FastLRU().values()]; } + { const a: Array<[string, number]> = [...new FastLRU().entries()]; } + new FastLRU().clear(); +} diff --git a/types/adone/test/glosses/collections/linked_list.ts b/types/adone/test/glosses/collections/linked_list.ts new file mode 100644 index 0000000000..f64a32c1aa --- /dev/null +++ b/types/adone/test/glosses/collections/linked_list.ts @@ -0,0 +1,123 @@ +namespace adoneTests.collection.LinkedList { + const { + collection: { + LinkedList + } + } = adone; + + namespace creation { + new LinkedList(); + new LinkedList(10); + } + + namespace properties { + { const a: boolean = new LinkedList().full; } + { const a: boolean = new LinkedList().empty; } + { const a: number = new LinkedList().maxLength; } + { const a: number = new LinkedList().length; } + { const a: boolean = new LinkedList().autoresize; } + } + + namespace resize { + { const a: boolean = new LinkedList().resize(100).full; } + } + + namespace push { + const a = new LinkedList().push(10); + a.next; + a.prev; + const b: number = a.value; + } + + namespace pop { + const a: number | undefined = new LinkedList().pop(); + } + + namespace shift { + const a: number | undefined = new LinkedList().shift(); + } + + namespace unshift { + const a = new LinkedList().unshift("hello"); + a.next; + a.prev; + const b: string = a.value; + } + + namespace pushNode { + const a = new LinkedList(); + const node = a.push("1230"); + a.pushNode(node); + } + + namespace unshiftNode { + const a = new LinkedList(); + const node = a.push(10); + a.unshiftNode(node); + } + + namespace removeNode { + const a = new LinkedList(); + const node = a.unshift("10"); + a.removeNode(node); + } + + namespace clear { + new LinkedList().clear(); + new LinkedList().clear(true); + } + + namespace toArray { + const a = new LinkedList(); + const b: number[] = a.toArray(); + } + + namespace front { + const a = new LinkedList(); + const b: number = a.front; + } + + namespace back { + const a = new LinkedList(); + const b: number = a.back; + } + + namespace iterating { + const a = new LinkedList(); + for (const b of a) { + const i: string = b; + } + const c = new LinkedList(); + for (const b of c) { + const i: number = b; + } + } + + namespace nextNode { + const a = new LinkedList(); + const n1 = a.push("h"); + const n2 = a.nextNode(n1); + n1.next; + n1.prev; + const t: string = n1.value; + } + + namespace map { + const a = new LinkedList(); + const f = (a: number, idx: number) => `${a}${idx}`; + const b = a.map(f); + const c: string = b.front; + } + + namespace forEach { + const a = new LinkedList(); + + a.forEach((a: number, b: number) => { + const c = a + b; + }); + } + + namespace static { + const a: number = LinkedList.DEFAULT_LENGTH; + } +} diff --git a/types/adone/test/glosses/collections/lru.ts b/types/adone/test/glosses/collections/lru.ts new file mode 100644 index 0000000000..934e5a1fbf --- /dev/null +++ b/types/adone/test/glosses/collections/lru.ts @@ -0,0 +1,67 @@ +namespace adoneTests.collection.LRU { + const { + collection: { + LRU + } + } = adone; + + type LRU = adone.collection.LRU; + + new LRU(); + new LRU(100); + new LRU({}); + new LRU({ max: 100 }); + new LRU({ dispose: (key: string, value: number) => null }); + new LRU({ maxAge: 100 }); + new LRU({ noDisposeOnSet: false }); + new LRU({ stale: true }); + { const a: number = new LRU().max; } + { new LRU().max = 100; } + { const a: boolean = new LRU().allowStale; } + { new LRU().allowStale = false; } + { const a: number = new LRU().maxAge; } + { new LRU().maxAge = 100; } + { const a: (v: number, k: string) => number = new LRU().lengthCalculator; } + { new LRU().lengthCalculator = () => 123; } + { const a: number = new LRU().length; } + { const a: number = new LRU().itemCount; } + new LRU().rforEach((value: number, key: string) => null); + new LRU().rforEach(function (value: number, key: string) { + const b: number = this.a; + }, { a: 1 }); + new LRU().forEach((value: number, key: string) => null); + new LRU().forEach(function (value: number, key: string) { + const b: number = this.a; + }, { a: 1 }); + { const a: string[] = new LRU().keys(); } + { const a: number[] = new LRU().values(); } + new LRU().reset(); + { + const a: Array> = new LRU().dump(); + const [b] = a; + { const c: number = b.e; } + { const c: string = b.key; } + { const c: number = b.value; } + } + { + const a: adone.collection.LinkedList> = new LRU().dumpLru(); + const b = a.shift(); + if (b !== undefined) { + { const a: string = b.key; } + { const a: number = b.value; } + { const a: number = b.now; } + { const a: number = b.maxAge; } + } + } + { const a: string = new LRU().inspect(); } + { const a: string = new LRU().inspect({}); } + { const a: boolean = new LRU().set("asd", 13); } + { const a: boolean = new LRU().set("asd", 13, 100500); } + { const a: boolean = new LRU().has("asd"); } + { const a: number | undefined = new LRU().get("asd"); } + { const a: number | undefined = new LRU().peek("asd"); } + { const a: adone.collection.I.LRU.Entry = new LRU().pop(); } + new LRU().del("asd"); + new LRU().load(new LRU().dump()); + new LRU().prune(); +} diff --git a/types/adone/test/glosses/collections/map_cache.ts b/types/adone/test/glosses/collections/map_cache.ts new file mode 100644 index 0000000000..bcd0ffb887 --- /dev/null +++ b/types/adone/test/glosses/collections/map_cache.ts @@ -0,0 +1,21 @@ +namespace adoneTests.collection.MapCache { + const { + collection: { + MapCache + } + } = adone; + + new MapCache(); + + new MapCache().has("hello"); + new MapCache().get("hello"); + new MapCache().set("hello", "world"); + new MapCache().delete("hello"); + new MapCache().clear(); + + { + const a = new MapCache(); + a.set("a", "b"); + a.get("a").charCodeAt(20); + } +} diff --git a/types/adone/test/glosses/collections/ns_cache.ts b/types/adone/test/glosses/collections/ns_cache.ts new file mode 100644 index 0000000000..a8e8c14397 --- /dev/null +++ b/types/adone/test/glosses/collections/ns_cache.ts @@ -0,0 +1,21 @@ +namespace adoneTests.collection.NSCache { + const { + collection: { + NSCache + } + } = adone; + + new NSCache(10, ["a", "b", "c"]); + new NSCache(10, ["a", "b", "c"]).resize(100); + new NSCache(10, ["a", "b", "c"]).set("a", "b", "c"); + new NSCache(10, ["a", "b", "c"]).get("a", "b"); + new NSCache(10, ["a", "b", "c"]).has("a", "b"); + new NSCache(10, ["a", "b", "c"]).delete("a", "b"); + new NSCache(10, ["a", "b", "c"]).clear(); + + { + const a = new NSCache(10, ["a", "b", "c"]); + a.set("a", "b", "c"); + a.get("a", "b").charCodeAt(100); + } +} diff --git a/types/adone/test/glosses/collections/priority_queue.ts b/types/adone/test/glosses/collections/priority_queue.ts new file mode 100644 index 0000000000..950e7394e7 --- /dev/null +++ b/types/adone/test/glosses/collections/priority_queue.ts @@ -0,0 +1,36 @@ +namespace adoneTests.collection.PriorityQueue { + const { + collection: { + PriorityQueue + } + } = adone; + + type PriorityQueue = adone.collection.PriorityQueue; + + { const a: boolean = new PriorityQueue().empty; } + { const a: number = new PriorityQueue().length; } + new PriorityQueue(); + new PriorityQueue({}); + new PriorityQueue({ + compare(a: number, b: number) { + return a - b; + } + }); + new PriorityQueue({ + priority(a: string, b: string) { + return a.length - b.length; + } + }); + { const a: PriorityQueue = new PriorityQueue().clone(); } + { const a: PriorityQueue = new PriorityQueue().push("123"); } + { const a: string | undefined = new PriorityQueue().pop(); } + { const a: PriorityQueue = new PriorityQueue().delete("123"); } + { const a: PriorityQueue = new PriorityQueue().delete("123"); } + { const a: string = new PriorityQueue().replace("123"); } + { const a: string = new PriorityQueue().pushpop("123"); } + { const a: string[] = new PriorityQueue().toArray(); } + { const a: PriorityQueue = PriorityQueue.from(["1"]); } + { const a: PriorityQueue = PriorityQueue.from(["1"], {}); } + { const a: PriorityQueue = PriorityQueue.from(["1"], { compare: (a: string, b: string) => a.length - b.length }); } + { const a: PriorityQueue = PriorityQueue.from(["1"], { priority: (a: string, b: string) => a.length - b.length }); } +} diff --git a/types/adone/test/glosses/collections/queue.ts b/types/adone/test/glosses/collections/queue.ts new file mode 100644 index 0000000000..fd6df7f39b --- /dev/null +++ b/types/adone/test/glosses/collections/queue.ts @@ -0,0 +1,17 @@ +namespace adoneTests.collection.Queue { + const { + collection: { + Queue + } + } = adone; + + type Queue = adone.collection.Queue; + + new Queue(); + { const a: Queue = new Queue().push(123).push(123); } + { const a: number | undefined = new Queue().push(123).pop(); } + { const a: string | undefined = new Queue().push(123).pop(); } + { const a: boolean = new Queue().full; } + { const a: number = new Queue().length; } + { const a: boolean = new Queue().empty; } +} diff --git a/types/adone/test/glosses/collections/rb_tree.ts b/types/adone/test/glosses/collections/rb_tree.ts new file mode 100644 index 0000000000..1b624284f6 --- /dev/null +++ b/types/adone/test/glosses/collections/rb_tree.ts @@ -0,0 +1,48 @@ +namespace adoneTests.collection.RedBlackTree { + const { + collection: { + RedBlackTree + } + } = adone; + + type RedBlackTree = adone.collection.RedBlackTree; + type RedBlackTreeIterator = adone.collection.I.RedBlackTree.Iterator; + type RedBlackTreeNode = adone.collection.I.RedBlackTree.Node; + + new RedBlackTree(); + new RedBlackTree((a: string, b: string) => a.length - b.length); + new RedBlackTree(undefined, new RedBlackTree()); + { const a: string[] = new RedBlackTree().keys; } + { const a: number[] = new RedBlackTree().values; } + { const a: number = new RedBlackTree().length; } + { + const a: RedBlackTreeIterator = new RedBlackTree().begin; + { const b: boolean = a.valid; } + { const b: RedBlackTreeNode | null = a.node; } + { const b: string | undefined = a.key; } + { const b: number | undefined = a.value; } + { const b: number = a.index; } + { const b: boolean = a.hasNext; } + { const b: boolean = a.hasPrev; } + { const b: RedBlackTree = a.tree; } + { const b: RedBlackTreeIterator = a.clone(); } + { const b: RedBlackTree = a.remove(); } + a.next(); + { const b: RedBlackTree = a.update(333); } + a.prev(); + } + { const a: RedBlackTreeIterator = new RedBlackTree().end; } + { const a: RedBlackTree = new RedBlackTree().insert("123", 456); } + { const a: number = new RedBlackTree().forEach((key: string, value: number) => value); } + { const a: number = new RedBlackTree().forEach((key: string, value: number) => value, "1"); } + { const a: number = new RedBlackTree().forEach((key: string, value: number) => value, "1", "2"); } + { const a: RedBlackTreeIterator = new RedBlackTree().at(1); } + { const a: RedBlackTreeIterator = new RedBlackTree().ge("1"); } + { const a: RedBlackTreeIterator = new RedBlackTree().gt("1"); } + { const a: RedBlackTreeIterator = new RedBlackTree().lt("1"); } + { const a: RedBlackTreeIterator = new RedBlackTree().le("1"); } + { const a: RedBlackTreeIterator | null = new RedBlackTree().find("1"); } + { const a: RedBlackTree = new RedBlackTree().remove("1"); } + { const a: RedBlackTree = new RedBlackTree().remove("1"); } + { const a: number | undefined = new RedBlackTree().get("1"); } +} diff --git a/types/adone/test/glosses/collections/refcounted_cache.ts b/types/adone/test/glosses/collections/refcounted_cache.ts new file mode 100644 index 0000000000..6262d57d60 --- /dev/null +++ b/types/adone/test/glosses/collections/refcounted_cache.ts @@ -0,0 +1,17 @@ +namespace adoneTests.collection.RefcountedCache { + const { + collection: { + RefcountedCache + } + } = adone; + + new RefcountedCache(); + new RefcountedCache().ref("a"); + new RefcountedCache().unref("a"); + new RefcountedCache().references("a") === 5; + + { + const a = new RefcountedCache(); + a.get("b").charCodeAt(100); + } +} diff --git a/types/adone/test/glosses/collections/set.ts b/types/adone/test/glosses/collections/set.ts new file mode 100644 index 0000000000..2e2314956e --- /dev/null +++ b/types/adone/test/glosses/collections/set.ts @@ -0,0 +1,26 @@ +namespace adoneTests.collection.Set { + const { + collection: { + Set + } + } = adone; + + new Set().add("a"); + new Set().has("a"); + new Set().delete("a"); + new Set().get("a"); + new Set().has("a") === true; + new Set().only(); + new Set().size === 5; + + { + const a = new Set(); + + a.add(1); + a.has(2); + a.delete(2); + a.get(2); // ??? + a.only() === 5; + a.size === 5; + } +} diff --git a/types/adone/test/glosses/collections/stack.ts b/types/adone/test/glosses/collections/stack.ts new file mode 100644 index 0000000000..df13f82f8e --- /dev/null +++ b/types/adone/test/glosses/collections/stack.ts @@ -0,0 +1,16 @@ +namespace adoneTests.collection.Stack { + const { + collection: { + Stack + } + } = adone; + + type Stack = adone.collection.Stack; + + { const a: boolean = new Stack().empty; } + { const a: number = new Stack().top; } + { const a: Stack = new Stack().push(123); } + { const a: number | undefined = new Stack().pop(); } + { const a: number[] = [...new Stack()]; } + { const a: Stack = Stack.from([1, 2, 3]); } +} diff --git a/types/adone/test/glosses/collections/timedout_map.ts b/types/adone/test/glosses/collections/timedout_map.ts new file mode 100644 index 0000000000..ffca754e2a --- /dev/null +++ b/types/adone/test/glosses/collections/timedout_map.ts @@ -0,0 +1,22 @@ +namespace adoneTests.collection.TimedoutMap { + const { + collection: { + TimedoutMap + } + } = adone; + + type TimedoutMap = adone.collection.TimedoutMap; + + new TimedoutMap(); + new TimedoutMap(1000); + new TimedoutMap(1000, (key: string) => null); + { + const a: TimedoutMap = new TimedoutMap().forEach((value: number, key: string) => null); + } + { + const a: TimedoutMap = new TimedoutMap().forEach(function (value: number, key: string) { + const a: number = this.a; + }, { a: 1 }); + } + { const a: boolean = new TimedoutMap().delete("123"); } +} diff --git a/types/adone/test/glosses/data.ts b/types/adone/test/glosses/data.ts index e9ef88d14b..00403a56da 100644 --- a/types/adone/test/glosses/data.ts +++ b/types/adone/test/glosses/data.ts @@ -570,4 +570,277 @@ namespace dataTests { bson.decode(bson.encode({ a: 1 }), { promoteLongs: false }).a; bson.decode(bson.encode({ a: 1 }), { promoteValues: true }).a; } + + namespace protobuf { + const { + protobuf + } = data; + + protobuf.create("hello"); + protobuf.create(Buffer.from("hello")); + protobuf.create({}); + protobuf.create({}, {}); + + namespace schema { + const { + schema + } = protobuf; + + const s = schema.parse("hello"); + s.syntax; + s.package; + if (!adone.is.null(s.package)) { + const c: string = s.package; + } + s.imports[0].charCodeAt(100); + + namespace enums { + const [a] = s.enums; + a.name.charCodeAt(100); + a.values; + a.options; + } + + namespace message { + const [msg] = s.messages; + msg.name; + { + const [a] = msg.enums; + a.name; + a.options; + a.values; + } + { + const [a] = msg.extends; + a.name; + a.message; + } + { + const [a] = msg.messages; + a.name; + a.enums; + a.extends; + a.messages; + a.fields; + a.extensions; + } + { + const [a] = msg.fields; + if (!adone.is.null(a.name)) { + a.name.charCodeAt(100); + } + if (!adone.is.null(a.type)) { + a.type.charCodeAt(100); + } + a.tag === 3; + if (!adone.is.null(a.map)) { + a.map.from.charCodeAt(100); + a.map.to.charCodeAt(100); + } + if (!adone.is.null(a.oneof)) { + a.oneof.charCodeAt(100); + } + a.required === false; + a.repeated === true; + a.options; + } + if (!adone.is.null(msg.extensions)) { + msg.extensions.from === 2; + msg.extensions.to === 3; + } + } + + s.options; + + s.extends[0].message; + s.extends[0].name; + + if (!adone.is.nil(s.services)) { + const [svc] = s.services; + + svc.name.charCodeAt(100); + svc.options; + + const [m] = svc.methods; + + m.name.charCodeAt(100); + if (!adone.is.null(m.input_type)) { + m.input_type.charCodeAt(100); + } + if (!adone.is.null(m.output_type)) { + m.output_type.charCodeAt(100); + } + m.client_streaming === true; + m.server_streaming === true; + m.options; + } + } + } + + namespace base32 { + const { + base32 + } = data; + + base32.charmap("asd"); + base32.charmap("asd", {}); + + base32.rfc4648.alphabet.charCodeAt(0); + base32.rfc4648.charmap["X"] === 2; + + base32.crockford.alphabet.charCodeAt(0); + base32.crockford.charmap["X"] === 2; + + base32.base32hex.alphabet.charCodeAt(0); + base32.base32hex.charmap["X"] === 2; + + namespace decoder { + const { + Decoder + } = base32; + new Decoder(); + new Decoder({ + type: "base32hex" + }); + new Decoder({ + type: "crockford" + }); + new Decoder({ + type: "rfc4648" + }); + new Decoder({ + type: "rfc4648", + charmap: {} + }); + const d = new Decoder(); + d.write("asd").write("aa"); + { const a: Buffer = d.finalize(); } + { const a: Buffer = d.finalize("c"); } + } + + namespace encoder { + const { + Encoder + } = base32; + + new Encoder(); + new Encoder({ + type: "base32hex" + }); + new Encoder({ + type: "crockford" + }); + new Encoder({ + type: "rfc4648" + }); + new Encoder({ + type: "rfc4648", + alphabet: "a" + }); + + const e = new Encoder(); + e.write(Buffer.from("b")).write(Buffer.from("a")); + { const a: string = e.finalize(); } + { const a: string = e.finalize(Buffer.from("c")); } + } + + base32.encode(Buffer.from("hello")).charCodeAt(100); + base32.encode(Buffer.from("hello"), { + type: "rfc4648" + }).charCodeAt(100); + base32.encode(Buffer.from("hello"), { + type: "crockford" + }).charCodeAt(100); + base32.encode(Buffer.from("hello"), { + type: "base32hex" + }).charCodeAt(100); + base32.encode(Buffer.from("hello"), { + type: "base32hex", + alphabet: "asd" + }).charCodeAt(100); + + base32.decode("asd").writeUInt8(100, 0); + base32.decode("asd", { + type: "base32hex" + }).writeUInt8(100, 0); + base32.decode("asd", { + type: "crockford" + }).writeUInt8(100, 0); + base32.decode("asd", { + type: "rfc4648" + }).writeUInt8(100, 0); + base32.decode("asd", { + type: "rfc4648", + charmap: {} + }).writeUInt8(100, 0); + } + + namespace basex { + const { + basex + } = data; + + const d = basex("abc"); + const a: Buffer = d.decode("str"); + const b: string = d.encode(Buffer.from("hello")); + const c: Buffer = d.decodeUnsafe("hello"); + } + + namespace base58 { + const { + base58 + } = data; + + const a: Buffer = base58.decode("str"); + const b: string = base58.encode(Buffer.from("hello")); + const c: Buffer = base58.decodeUnsafe("hello"); + } + + namespace base64url { + const { + base64url + } = data; + + base64url.unescape("a").charCodeAt(100); + base64url.escape("a").charCodeAt(100); + + base64url.encode("a").charCodeAt(100); + base64url.encode(Buffer.from("a")).charCodeAt(100); + base64url.encode(Buffer.from("a"), {}).charCodeAt(100); + base64url.encode(Buffer.from("a"), { + encoding: "utf8" + }).charCodeAt(100); + + base64url.decode("a").charCodeAt(100); + base64url.decode("a", { buffer: true }).writeUInt8(0, 0); + base64url.decode("a", { encoding: "utf8" }).charCodeAt(100); + } + + namespace varint { + const { + varint + } = data; + + varint.encode(12)[0]; + varint.encode(12, [])[0]; + varint.encode(12, [], 1)[0]; + + varint.decode(Buffer.from("hello")) === 5; + varint.decode(Buffer.from("hello"), 2) === 5; + varint.encodingLength(100500) === 5; + } + + namespace varintSigned { + const { + varintSigned + } = data; + + varintSigned.encode(12)[0]; + varintSigned.encode(12, [])[0]; + varintSigned.encode(12, [], 1)[0]; + + varintSigned.decode(Buffer.from("hello")) === 5; + varintSigned.decode(Buffer.from("hello"), 2) === 5; + varintSigned.encodingLength(100500) === 5; + } } diff --git a/types/adone/test/glosses/fake.ts b/types/adone/test/glosses/fake.ts new file mode 100644 index 0000000000..016d7ba7b0 --- /dev/null +++ b/types/adone/test/glosses/fake.ts @@ -0,0 +1,206 @@ +namespace adoneTests.fake { + const { + fake + } = adone; + + { const a: string = fake.address.zipCode(); } + { const a: string = fake.address.zipCode('###'); } + { const a: string = fake.address.city(); } + { const a: string = fake.address.city(0); } + { const a: string = fake.address.cityPrefix(); } + { const a: string = fake.address.citySuffix(); } + { const a: string = fake.address.streetName(); } + { const a: string = fake.address.streetAddress(); } + { const a: string = fake.address.streetAddress(false); } + { const a: string = fake.address.streetSuffix(); } + { const a: string = fake.address.streetPrefix(); } + { const a: string = fake.address.secondaryAddress(); } + { const a: string = fake.address.county(); } + { const a: string = fake.address.country(); } + { const a: string = fake.address.countryCode(); } + { const a: string = fake.address.state(); } + { const a: string = fake.address.state(false); } + { const a: string = fake.address.stateAbbr(); } + { const a: string = fake.address.latitude(); } + { const a: string = fake.address.longitude(); } + + { const a: string = fake.commerce.color(); } + { const a: string = fake.commerce.department(); } + { const a: string = fake.commerce.productName(); } + { const a: string = fake.commerce.price(); } + { const a: string = fake.commerce.price(0, 0, 0, '#'); } + { const a: string = fake.commerce.productAdjective(); } + { const a: string = fake.commerce.productMaterial(); } + { const a: string = fake.commerce.product(); } + + { const a: string[] = fake.company.suffixes(); } + { const a: string = fake.company.companyName(); } + { const a: string = fake.company.companyName(0); } + { const a: string = fake.company.companySuffix(); } + { const a: string = fake.company.catchPhrase(); } + { const a: string = fake.company.bs(); } + { const a: string = fake.company.catchPhraseAdjective(); } + { const a: string = fake.company.catchPhraseDescriptor(); } + { const a: string = fake.company.catchPhraseNoun(); } + { const a: string = fake.company.bsAdjective(); } + { const a: string = fake.company.bsBuzz(); } + { const a: string = fake.company.bsNoun(); } + + { const a: string = fake.database.column(); } + { const a: string = fake.database.type(); } + { const a: string = fake.database.collation(); } + { const a: string = fake.database.engine(); } + + { const a: Date = fake.date.past(); } + { const a: Date = fake.date.future(); } + { const a: Date = fake.date.between('foo', 'bar'); } + { const a: Date = fake.date.between(new Date(), new Date()); } + { const a: Date = fake.date.recent(); } + { const a: Date = fake.date.recent(100); } + { const a: Date = fake.date.soon(); } + { const a: Date = fake.date.soon(30); } + { const a: string = fake.date.month(); } + { const a: string = fake.date.month({ + abbr: true, + context: true + }); } + { const a: string = fake.date.weekday(); } + { const a: string = fake.date.weekday({ + abbr: true, + context: true + }); } + + { const a: string = fake.finance.account(); } + { const a: string = fake.finance.account(0); } + { const a: string = fake.finance.accountName(); } + { const a: string = fake.finance.mask(); } + { const a: string = fake.finance.mask(0, false, false); } + { const a: string = fake.finance.amount(); } + { const a: string = fake.finance.amount(0, 0, 0, '#'); } + { const a: string = fake.finance.transactionType(); } + { const a: string = fake.finance.currencyCode(); } + { const a: string = fake.finance.currencyName(); } + { const a: string = fake.finance.currencySymbol(); } + { const a: string = fake.finance.bitcoinAddress(); } + { const a: string = fake.finance.ethereumAddress(); } + { const a: string = fake.finance.iban(); } + { const a: string = fake.finance.iban(true); } + { const a: string = fake.finance.bic(); } + + { const a: string = fake.hacker.abbreviation(); } + { const a: string = fake.hacker.adjective(); } + { const a: string = fake.hacker.noun(); } + { const a: string = fake.hacker.verb(); } + { const a: string = fake.hacker.ingverb(); } + { const a: string = fake.hacker.phrase(); } + + { const a: string = fake.helpers.randomize(); } + { const a: number = fake.helpers.randomize([1, 2, 3, 4]); } + { const a: string = fake.helpers.randomize(['foo', 'bar', 'quux']); } + { const a: string = fake.helpers.slugify('foo bar quux'); } + { const a: string = fake.helpers.replaceSymbolWithNumber('foo# bar#'); } + { const a: string = fake.helpers.replaceSymbols('foo# bar? quux#'); } + { const a: string[] = fake.helpers.shuffle(['foo', 'bar', 'quux']); } + { const a: string = fake.helpers.mustache('{{foo}}{{bar}}', {foo: 'x', bar: 'y'}); } + + const card = fake.helpers.createCard(); + { const a: string = card.name; } + { const a: string = card.address.streetA; } + const contextualCard = fake.helpers.contextualCard(); + { const a: string = contextualCard.name; } + { const a: string = contextualCard.address.suite; } + const userCard = fake.helpers.userCard(); + { const a: string = userCard.name; } + { const a: string = userCard.address.suite; } + + { const a: string = fake.internet.avatar(); } + { const a: string = fake.internet.email(); } + { const a: string = fake.internet.email('foo', 'bar', 'quux'); } + { const a: string = fake.internet.exampleEmail(); } + { const a: string = fake.internet.exampleEmail('foo', 'bar'); } + { const a: string = fake.internet.protocol(); } + { const a: string = fake.internet.url(); } + { const a: string = fake.internet.domainName(); } + { const a: string = fake.internet.domainSuffix(); } + { const a: string = fake.internet.domainWord(); } + { const a: string = fake.internet.ip(); } + { const a: string = fake.internet.userAgent(); } + { const a: string = fake.internet.color(); } + { const a: string = fake.internet.color(0, 0, 0); } + { const a: string = fake.internet.mac(); } + { const a: string = fake.internet.password(); } + { const a: string = fake.internet.password(0, false, '#', 'foo'); } + + { const a: string = fake.lorem.word(); } + { const a: string = fake.lorem.words(); } + { const a: string = fake.lorem.words(0); } + { const a: string = fake.lorem.sentence(); } + { const a: string = fake.lorem.sentence(0, 0); } + { const a: string = fake.lorem.slug(); } + { const a: string = fake.lorem.slug(0); } + { const a: string = fake.lorem.sentences(); } + { const a: string = fake.lorem.sentences(0); } + { const a: string = fake.lorem.paragraph(); } + { const a: string = fake.lorem.paragraph(0); } + { const a: string = fake.lorem.paragraphs(); } + { const a: string = fake.lorem.paragraphs(0, ''); } + { const a: string = fake.lorem.text(); } + { const a: string = fake.lorem.text(0); } + { const a: string = fake.lorem.lines(); } + { const a: string = fake.lorem.lines(0); } + + { const a: string = fake.name.firstName(); } + { const a: string = fake.name.firstName(0); } + { const a: string = fake.name.lastName(); } + { const a: string = fake.name.lastName(0); } + { const a: string = fake.name.findName(); } + { const a: string = fake.name.findName('', '', 0); } + { const a: string = fake.name.jobTitle(); } + { const a: string = fake.name.prefix(); } + { const a: string = fake.name.suffix(); } + { const a: string = fake.name.title(); } + { const a: string = fake.name.jobDescriptor(); } + { const a: string = fake.name.jobArea(); } + { const a: string = fake.name.jobType(); } + + { const a: string = fake.phone.phoneNumber(); } + { const a: string = fake.phone.phoneNumber('#'); } + { const a: string = fake.phone.phoneNumberFormat(); } + { const a: string = fake.phone.phoneNumberFormat(0); } + { const a: string = fake.phone.phoneFormats(); } + + { const a: number = fake.random.number(); } + { const a: number = fake.random.number(0); } + { const a: number = fake.random.number({ + min: 0, + max: 0, + precision: 0 + }); } + { const a: string = fake.random.arrayElement(); } + { const a: string = fake.random.arrayElement(['foo', 'bar', 'quux']); } + { const a: string = fake.random.objectElement(); } + { const a: string = fake.random.objectElement({foo: 'bar', field: 'foo'}); } + { const a: string = fake.random.uuid(); } + { const a: boolean = fake.random.boolean(); } + { const a: string = fake.random.word(); } + { const a: string = fake.random.word("noun"); } + { const a: string = fake.random.words(); } + { const a: string = fake.random.words(0); } + { const a: string = fake.random.image(); } + { const a: string = fake.random.locale(); } + { const a: string = fake.random.alphaNumeric(); } + { const a: string = fake.random.alphaNumeric(0); } + { const a: string = fake.random.hexaDecimal(); } + { const a: string = fake.random.hexaDecimal(3); } + + { const a: string = fake.system.fileName("foo", "bar"); } + { const a: string = fake.system.commonFileName("foo", "bar"); } + { const a: string = fake.system.mimeType(); } + { const a: string = fake.system.commonFileType(); } + { const a: string = fake.system.commonFileExt(); } + { const a: string = fake.system.fileType(); } + { const a: string = fake.system.fileExt("foo"); } + { const a: string = fake.system.directoryPath(); } + { const a: string = fake.system.filePath(); } + { const a: string = fake.system.semver(); } +} diff --git a/types/adone/test/glosses/is.ts b/types/adone/test/glosses/is.ts index 13b00530d7..2065dfe01b 100644 --- a/types/adone/test/glosses/is.ts +++ b/types/adone/test/glosses/is.ts @@ -133,8 +133,20 @@ namespace isTests { } } { const a: boolean = is.dotfile("abc"); } - { const a: boolean = is.function(() => { }); } - { const a: boolean = is.asyncFunction(async () => { }); } + { + const a: boolean = is.function(() => { }); + const b: any = 2; + if (is.function(b)) { + b(); + } + } + { + const a: boolean = is.asyncFunction(async () => { }); + const b: any = 2; + if (is.asyncFunction(b)) { + b().then(() => {}); + } + } { const a: boolean = is.promise({}); const b: any = 2; diff --git a/types/adone/tsconfig.json b/types/adone/tsconfig.json index 175d3c1252..e77e755b85 100644 --- a/types/adone/tsconfig.json +++ b/types/adone/tsconfig.json @@ -22,6 +22,7 @@ "files": [ "index.d.ts", "adone.d.ts", + "glosses/fake.d.ts", "glosses/math/index.d.ts", "glosses/math/matrix.d.ts", "glosses/math/simd.d.ts", @@ -32,7 +33,26 @@ "glosses/promise.d.ts", "glosses/shani.d.ts", "glosses/shani-global.d.ts", - "glosses/collections.d.ts", + "glosses/collections/index.d.ts", + "glosses/collections/array_set.d.ts", + "glosses/collections/async_queue.d.ts", + "glosses/collections/avl_tree.d.ts", + "glosses/collections/binary_search_tree.d.ts", + "glosses/collections/buffer_list.d.ts", + "glosses/collections/byte_array.d.ts", + "glosses/collections/default_map.d.ts", + "glosses/collections/fast_lru.d.ts", + "glosses/collections/linked_list.d.ts", + "glosses/collections/lru.d.ts", + "glosses/collections/map_cache.d.ts", + "glosses/collections/ns_cache.d.ts", + "glosses/collections/priority_queue.d.ts", + "glosses/collections/queue.d.ts", + "glosses/collections/rb_tree.d.ts", + "glosses/collections/refcounted_cache.d.ts", + "glosses/collections/set.d.ts", + "glosses/collections/stack.d.ts", + "glosses/collections/timedout_map.d.ts", "glosses/events.d.ts", "glosses/fs.d.ts", "glosses/is.d.ts", @@ -46,7 +66,27 @@ "adone-tests.ts", "test/index.ts", "test/index-import.ts", + "test/glosses/fake.ts", "test/glosses/application.ts", + "test/glosses/collections/array_set.ts", + "test/glosses/collections/async_queue.ts", + "test/glosses/collections/avl_tree.ts", + "test/glosses/collections/binary_search_tree.ts", + "test/glosses/collections/buffer_list.ts", + "test/glosses/collections/byte_array.ts", + "test/glosses/collections/default_map.ts", + "test/glosses/collections/fast_lru.ts", + "test/glosses/collections/linked_list.ts", + "test/glosses/collections/lru.ts", + "test/glosses/collections/map_cache.ts", + "test/glosses/collections/ns_cache.ts", + "test/glosses/collections/priority_queue.ts", + "test/glosses/collections/queue.ts", + "test/glosses/collections/rb_tree.ts", + "test/glosses/collections/refcounted_cache.ts", + "test/glosses/collections/set.ts", + "test/glosses/collections/stack.ts", + "test/glosses/collections/timedout_map.ts", "test/glosses/math/index.ts", "test/glosses/math/matrix.ts", "test/glosses/math/simd.ts", @@ -57,7 +97,6 @@ "test/glosses/promise.ts", "test/glosses/shani.ts", "test/glosses/shani-global.ts", - "test/glosses/collections.ts", "test/glosses/events.ts", "test/glosses/fs.ts", "test/glosses/is.ts",