Merge pull request #23738 from ciferox/adone

[adone] refactoring
This commit is contained in:
Benjamin Lichtman
2018-02-28 11:14:29 -08:00
committed by GitHub
28 changed files with 825 additions and 421 deletions

View File

@@ -7,16 +7,15 @@ declare namespace adone {
export function identity<T>(x: T): T;
export function truly(): true;
export function falsely(): false;
export const ok: "OK";
export const bad: "BAD";
export const exts: [".js", ".tjs", ".ajs"];
export const ok: "ok";
export const bad: "bad";
export function log(...args: any[]): void;
export function fatal(...args: any[]): void;
export function error(...args: any[]): void;
export function warn(...args: any[]): void;
export function info(...args: any[]): void;
export function debug(...args: any[]): void;
export function trace(...args: any[]): void;
export function logFatal(...args: any[]): void;
export function logError(...args: any[]): void;
export function logWarn(...args: any[]): void;
export function logInfo(...args: any[]): void;
export function logDebug(...args: any[]): void;
export function logTrace(...args: any[]): void;
export function o(...props: any[]): object;
export const Date: typeof global.Date;
export const hrtime: typeof global.process.hrtime;
@@ -76,35 +75,9 @@ declare namespace adone {
set(Class: object, tag: string): void;
has(obj: object, tag: string): boolean;
define(tag: string, predicate?: string): void;
SUBSYSTEM: symbol;
APPLICATION: symbol;
TRANSFORM: symbol;
CORE_STREAM: symbol;
LOGGER: symbol;
LONG: symbol;
BIGNUMBER: symbol;
EXBUFFER: symbol;
EXDATE: symbol;
CONFIGURATION: symbol;
GENESIS_NETRON: symbol;
GENESIS_PEER: symbol;
NETRON: symbol;
NETRON_PEER: symbol;
NETRON_ADAPTER: symbol;
NETRON_DEFINITION: symbol;
NETRON_DEFINITIONS: symbol;
NETRON_REFERENCE: symbol;
NETRON_INTERFACE: symbol;
NETRON_STUB: symbol;
NETRON_REMOTESTUB: symbol;
NETRON_STREAM: symbol;
FAST_STREAM: symbol;
FAST_FS_STREAM: symbol;
FAST_FS_MAP_STREAM: symbol;
}
}
export const tag: I.Tag;
export function bind(libName: string): object;
export function getAssetAbsolutePath(relPath: string): string;
export function loadAsset(relPath: string): string | Buffer;
export function require(path: string): object;
@@ -122,11 +95,10 @@ declare namespace adone {
export const runtime: I.Runtime;
export const homePath: string;
export const rootPath: string;
export const etcPath: string;
export const config: object;
export const emptyBuffer: Buffer;
export const ROOT_PATH: string;
export const ETC_PATH: string;
export const configuration: object;
export const EMPTY_BUFFER: Buffer;
export const assert: assertion.I.AssertFunction;
export const expect: assertion.I.ExpectFunction;

View File

@@ -1019,7 +1019,7 @@ declare namespace adone {
}
}
class AssertionError extends exception.Exception {
class AssertionError extends error.Exception {
constructor(message?: string, props?: object, ssf?: object)
}

View File

@@ -27,5 +27,7 @@ declare namespace adone.collection {
* Removes and returns an element from the beginning
*/
pop(): T | undefined;
static from<T>(iterable: Iterable<T>, length?: number): Queue<T>;
}
}

View File

@@ -582,7 +582,7 @@ declare namespace adone {
/**
* Represents a YAML exception
*/
class Exception extends adone.exception.Exception {
class Exception extends adone.error.Exception {
reason: string;
mark: Mark;

View File

@@ -1,5 +1,5 @@
declare namespace adone {
namespace exception {
namespace error {
class Exception extends Error {
constructor(message?: string | Error, captureStackTrace?: boolean);
}

10
types/adone/glosses/pretty/index.d.ts vendored Normal file
View File

@@ -0,0 +1,10 @@
/// <reference path="./json.d.ts" />
/// <reference path="./size.d.ts" />
/// <reference path="./table.d.ts" />
/// <reference path="./time.d.ts" />
declare namespace adone {
namespace pretty {
//
}
}

16
types/adone/glosses/pretty/json.d.ts vendored Normal file
View File

@@ -0,0 +1,16 @@
declare namespace adone.pretty {
namespace I {
interface JSONOptions {
emptyArrayMsg?: string;
keysColor?: string;
dashColor?: string;
numberColor?: string;
stringColor?: string;
defaultIndentation?: number;
noColor?: boolean;
noAlign?: boolean;
}
}
function json(data: any, options?: I.JSONOptions, indentation?: number): string;
}

3
types/adone/glosses/pretty/size.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
declare namespace adone.pretty {
function size(num: number, space?: string): string;
}

38
types/adone/glosses/pretty/table.d.ts vendored Normal file
View File

@@ -0,0 +1,38 @@
declare namespace adone.pretty {
namespace I {
interface TableColumn {
id: string;
header?: string;
align?: "right" | "center" | "left";
width?: string | number;
maxWidth?: number | string;
wordwrap?: "soft" | "hard" | adone.text.I.WordWrapOptions;
handle?: (item: object) => string;
format?: string | ((val: any, item: object) => string);
style?: string | ((val: any, str: string) => string);
}
type TableModel = TableColumn[];
interface TableStyle {
"padding-left"?: number;
"padding-right"?: number;
head?: string[];
broder?: string[];
compact?: boolean;
}
interface TableOptions {
model: TableModel;
noHeader?: boolean;
borderless?: boolean;
style?: TableStyle;
width?: number | string;
countAnsiEscapeCodes?: boolean;
}
type TableData = Array<{ [id: string]: any }>;
}
function table(data: I.TableData, options: I.TableOptions): string;
}

11
types/adone/glosses/pretty/time.d.ts vendored Normal file
View File

@@ -0,0 +1,11 @@
declare namespace adone.pretty {
namespace I {
interface TimeOptions {
msDecimalDigits?: number;
secDecimalDigits?: number;
verbose?: boolean;
compact?: boolean;
}
}
function time(ms: number, options?: I.TimeOptions): string;
}

View File

@@ -1,4 +1,3 @@
/// <reference path="./pretties.d.ts" />
/// <reference path="./spinners.d.ts" />
/// <reference path="./table.d.ts" />
/// <reference path="./unicode.d.ts" />

View File

@@ -1,55 +0,0 @@
declare namespace adone.text {
namespace pretty {
namespace I {
interface JSONOptions {
emptyArrayMsg?: string;
keysColor?: string;
dashColor?: string;
numberColor?: string;
stringColor?: string;
defaultIndentation?: number;
noColor?: boolean;
noAlign?: boolean;
}
}
function json(data: any, options?: I.JSONOptions, indentation?: number): string;
namespace I {
interface TableColumn {
id: string;
header?: string;
align?: "right" | "center" | "left";
width?: string | number;
maxWidth?: number | string;
wordwrap?: "soft" | "hard" | adone.text.I.WordWrapOptions;
handle?: (item: object) => string;
format?: string | ((val: any, item: object) => string);
style?: string | ((val: any, str: string) => string);
}
type TableModel = TableColumn[];
interface TableStyle {
"padding-left"?: number;
"padding-right"?: number;
head?: string[];
broder?: string[];
compact?: boolean;
}
interface TableOptions {
model: TableModel;
noHeader?: boolean;
borderless?: boolean;
style?: TableStyle;
width?: number | string;
countAnsiEscapeCodes?: boolean;
}
type TableData = Array<{ [id: string]: any }>;
}
function table(data: I.TableData, options: I.TableOptions): string;
}
}

View File

@@ -86,17 +86,6 @@ declare namespace adone {
function invertObject(source: object, options?: I.KeysOptions): object;
namespace I {
interface HumanizeTimeOptions {
msDecimalDigits?: number;
secDecimalDigits?: number;
verbose?: boolean;
compact?: boolean;
}
}
function humanizeTime(ms: number, options?: I.HumanizeTimeOptions): string;
function humanizeSize(num: number, space?: string): string;
function parseSize(str: string | number): number | null;
namespace I {
@@ -547,7 +536,7 @@ declare namespace adone {
namespace throttle {
namespace I {
interface Options {
max?: number;
concurrency?: number;
interval?: number;
ordered?: boolean;
waitForReturn?: boolean;

204
types/adone/glosses/vault.d.ts vendored Normal file
View File

@@ -0,0 +1,204 @@
declare namespace adone {
namespace vault {
namespace I {
interface VaultConstructorOptions {
// TODO: leveldb options
location: string;
ValuableClass?: object;
}
interface VaultClearOptions {
hosts?: boolean;
tags?: boolean;
}
interface VaultToJSONOptions {
valuable?: ValuableToJSONOptions;
includeStats?: boolean;
}
interface ValuableToJSONOptions {
includeId?: boolean;
includeEntryId?: boolean;
entriesAsArray?: boolean;
tags?: "normal" | "onlyName" | "onlyId" | "none";
}
interface VaultJSONStats {
location: string;
created: number;
updated: number;
}
}
class Vault<T extends Valuable = Valuable> {
constructor(options: I.VaultConstructorOptions);
open(): Promise<void>;
close(): Promise<void>;
location(): string;
create(name: string, tags?: string[]): Promise<T>;
get(name: string): Promise<T>;
release(name: string): void;
delete(name: string): Promise<void>;
clear(options?: I.VaultClearOptions): Promise<number>;
has(name: string): boolean;
keys(): string[];
values(): Promise<any[]>;
entries(): Promise<{ [key: string]: any }>;
toJSON(options: I.VaultToJSONOptions & { valuable: object, includeStats: true }): Promise<{
valuables: object[],
stats: I.VaultJSONStats
}>;
toJSON(options: I.VaultToJSONOptions & { valuable: object }): Promise<{
valuables: object[]
}>;
toJSON(options: I.VaultToJSONOptions & { includeStats: true }): Promise<{
stats: I.VaultJSONStats
}>;
toJSON(): {};
addTag(tag: string, vid?: number): Promise<number| null>;
deleteTag(tag: string): Promise<boolean>;
tags(ids?: number[], opts?: { privateProps?: boolean }): object[];
tagNames(ids?: number[]): string[];
getNotes(): string;
setNotes(notes: string): Promise<void>;
}
namespace I {
interface ValueableEntriesOptions {
entriesAsArray?: boolean;
includeEntryId?: boolean;
}
interface ValuableEntry {
name: string;
value: any;
type: string;
}
interface ValuableClearOptions {
includeNotes?: boolean;
includeTags?: boolean;
}
interface ValuableJSON {
name: string;
notes: string;
entries: I.ValuableEntry[];
}
}
class Valuable {
constructor(vaule: Vault, id: number, metaData: object, tags: object[]);
name(): string;
internalId(): number;
getNotes(): string;
setNotes(notes: string): Promise<void>;
set(name: string, value: any, type?: string): Promise<number>;
setMulti(entries: object): Promise<void>;
get(name: string): Promise<any>;
type(name: string): any;
has(name: string): boolean;
keys(): string[];
entries(opts: I.ValueableEntriesOptions & { entriesAsArray: true }): Promise<I.ValuableEntry[]>;
entries(opts: I.ValueableEntriesOptions & { entriesAsArray: true, includeEntryId: true }): Promise<Array<I.ValuableEntry & { id: number }>>;
entries(opts?: I.ValueableEntriesOptions): Promise<object>;
delete(name: string): Promise<number>;
clear(opts?: I.ValuableClearOptions): Promise<number>;
toJSON(opts?: I.ValuableToJSONOptions): object; // TODO
fromJSON(json: object): Promise<number>;
addTag(tag: string): Promise<void>;
hasTag(tag: string): boolean;
deleteTag(tag: string): Promise<boolean>;
deleteAllTags(): Promise<void>;
tags(): object[];
}
function open(options?: I.VaultConstructorOptions): Promise<Vault>;
namespace I {
interface SlicedValuable {
name(): string;
internalId(): number;
getNotes(): string;
setNotes(notes: string): Promise<number>;
set(name: string, value: any, type?: string): Promise<number>;
setMulti(entries: object): Promise<void>;
get(name: string): Promise<any>;
type(name: string): any;
has(name: string): boolean;
keys(): string[];
entries(opts: I.ValueableEntriesOptions & { entriesAsArray: true }): Promise<I.ValuableEntry[]>;
entries(opts: I.ValueableEntriesOptions & { entriesAsArray: true, includeEntryId: true }): Promise<Array<I.ValuableEntry & { id: number }>>;
entries(opts?: I.ValueableEntriesOptions): Promise<object>;
delete(name: string): Promise<number>;
toJSON(opts?: I.ValuableToJSONOptions): object;
fromJSON(json: object): Promise<number>;
addTag(tag: string): Promise<void>;
hasTag(tag: string): boolean;
deleteTag(tag: string): Promise<boolean>;
deleteAllTags(): Promise<void>;
tags(): object[];
}
}
function slice(valuable: Valuable, prefix: string | string[], separator?: string): I.SlicedValuable;
}
}

View File

@@ -14,7 +14,7 @@
/// <reference path="./glosses/data.d.ts" />
/// <reference path="./glosses/datetime.d.ts" />
/// <reference path="./glosses/events.d.ts" />
/// <reference path="./glosses/exceptions.d.ts" />
/// <reference path="./glosses/errors.d.ts" />
/// <reference path="./glosses/fake.d.ts" />
/// <reference path="./glosses/fast.d.ts" />
/// <reference path="./glosses/fs.d.ts" />
@@ -22,6 +22,7 @@
/// <reference path="./glosses/math/index.d.ts" />
/// <reference path="./glosses/meta.d.ts" />
/// <reference path="./glosses/net/index.d.ts" />
/// <reference path="./glosses/pretty/index.d.ts" />
/// <reference path="./glosses/promise.d.ts" />
/// <reference path="./glosses/regex.d.ts" />
/// <reference path="./glosses/semver.d.ts" />
@@ -33,6 +34,7 @@
/// <reference path="./glosses/templating/index.d.ts" />
/// <reference path="./glosses/text/index.d.ts" />
/// <reference path="./glosses/utils.d.ts" />
/// <reference path="./glosses/vault.d.ts" />
declare const _adone: typeof adone;

View File

@@ -3,9 +3,9 @@ namespace assertionTests {
namespace assertionInterface {
namespace exception {
const a: adone.exception.Exception = new assertion.AssertionError();
const b: adone.exception.Exception = new assertion.AssertionError("hello");
const c: adone.exception.Exception = new assertion.AssertionError("hello", { actual: 2, expected: 3 }, () => {});
const a: adone.error.Exception = new assertion.AssertionError();
const b: adone.error.Exception = new assertion.AssertionError("hello");
const c: adone.error.Exception = new assertion.AssertionError("hello", { actual: 2, expected: 3 }, () => {});
}
namespace config {

View File

@@ -14,4 +14,15 @@ namespace adoneTests.collection.Queue {
{ const a: boolean = new Queue().full; }
{ const a: number = new Queue().length; }
{ const a: boolean = new Queue().empty; }
{
const q = Queue.from([1, 2, 3]);
const a: number | undefined = q.pop();
}
{
const q = Queue.from((function*() {
yield 42;
})());
const a: number | undefined = q.pop();
}
}

View File

@@ -0,0 +1,36 @@
namespace ErrorsTests {
{ const a: Error = new adone.error.Exception(); }
{ const a: Error = new adone.error.Exception("message"); }
{ const a: Error = new adone.error.Exception(new Error()); }
{ const a: Error = new adone.error.Exception(new Error(), true); }
{ const a: adone.error.Exception = new adone.error.Runtime(); }
{ const a: adone.error.Exception = new adone.error.IncompleteBufferError(); }
{ const a: adone.error.Exception = new adone.error.NotImplemented(); }
{ const a: adone.error.Exception = new adone.error.IllegalState(); }
{ const a: adone.error.Exception = new adone.error.NotValid(); }
{ const a: adone.error.Exception = new adone.error.Unknown(); }
{ const a: adone.error.Exception = new adone.error.NotExists(); }
{ const a: adone.error.Exception = new adone.error.Exists(); }
{ const a: adone.error.Exception = new adone.error.Empty(); }
{ const a: adone.error.Exception = new adone.error.InvalidAccess(); }
{ const a: adone.error.Exception = new adone.error.NotSupported(); }
{ const a: adone.error.Exception = new adone.error.InvalidArgument(); }
{ const a: adone.error.Exception = new adone.error.InvalidNumberOfArguments(); }
{ const a: adone.error.Exception = new adone.error.NotFound(); }
{ const a: adone.error.Exception = new adone.error.Timeout(); }
{ const a: adone.error.Exception = new adone.error.Incorrect(); }
{ const a: adone.error.Exception = new adone.error.NotAllowed(); }
{ const a: adone.error.Exception = new adone.error.LimitExceeded(); }
{ const a: adone.error.Exception = new adone.error.Encoding(); }
{ const a: adone.error.Exception = new adone.error.Network(); }
{ const a: adone.error.Exception = new adone.error.Bind(); }
{ const a: adone.error.Exception = new adone.error.Connect(); }
{ const a: adone.error.Exception = new adone.error.Database(); }
{ const a: adone.error.Exception = new adone.error.DatabaseInitialization(); }
{ const a: adone.error.Exception = new adone.error.DatabaseOpen(); }
{ const a: adone.error.Exception = new adone.error.DatabaseRead(); }
{ const a: adone.error.Exception = new adone.error.DatabaseWrite(); }
{ const a: adone.error.Exception = new adone.error.NetronIllegalState(); }
{ const a: adone.error.Exception = new adone.error.NetronPeerDisconnected(); }
{ const a: adone.error.Exception = new adone.error.NetronTimeout(); }
}

View File

@@ -1,36 +0,0 @@
namespace ExcetpionsTests {
{ const a: Error = new adone.exception.Exception(); }
{ const a: Error = new adone.exception.Exception("message"); }
{ const a: Error = new adone.exception.Exception(new Error()); }
{ const a: Error = new adone.exception.Exception(new Error(), true); }
{ const a: adone.exception.Exception = new adone.exception.Runtime(); }
{ const a: adone.exception.Exception = new adone.exception.IncompleteBufferError(); }
{ const a: adone.exception.Exception = new adone.exception.NotImplemented(); }
{ const a: adone.exception.Exception = new adone.exception.IllegalState(); }
{ const a: adone.exception.Exception = new adone.exception.NotValid(); }
{ const a: adone.exception.Exception = new adone.exception.Unknown(); }
{ const a: adone.exception.Exception = new adone.exception.NotExists(); }
{ const a: adone.exception.Exception = new adone.exception.Exists(); }
{ const a: adone.exception.Exception = new adone.exception.Empty(); }
{ const a: adone.exception.Exception = new adone.exception.InvalidAccess(); }
{ const a: adone.exception.Exception = new adone.exception.NotSupported(); }
{ const a: adone.exception.Exception = new adone.exception.InvalidArgument(); }
{ const a: adone.exception.Exception = new adone.exception.InvalidNumberOfArguments(); }
{ const a: adone.exception.Exception = new adone.exception.NotFound(); }
{ const a: adone.exception.Exception = new adone.exception.Timeout(); }
{ const a: adone.exception.Exception = new adone.exception.Incorrect(); }
{ const a: adone.exception.Exception = new adone.exception.NotAllowed(); }
{ const a: adone.exception.Exception = new adone.exception.LimitExceeded(); }
{ const a: adone.exception.Exception = new adone.exception.Encoding(); }
{ const a: adone.exception.Exception = new adone.exception.Network(); }
{ const a: adone.exception.Exception = new adone.exception.Bind(); }
{ const a: adone.exception.Exception = new adone.exception.Connect(); }
{ const a: adone.exception.Exception = new adone.exception.Database(); }
{ const a: adone.exception.Exception = new adone.exception.DatabaseInitialization(); }
{ const a: adone.exception.Exception = new adone.exception.DatabaseOpen(); }
{ const a: adone.exception.Exception = new adone.exception.DatabaseRead(); }
{ const a: adone.exception.Exception = new adone.exception.DatabaseWrite(); }
{ const a: adone.exception.Exception = new adone.exception.NetronIllegalState(); }
{ const a: adone.exception.Exception = new adone.exception.NetronPeerDisconnected(); }
{ const a: adone.exception.Exception = new adone.exception.NetronTimeout(); }
}

View File

@@ -0,0 +1,19 @@
namespace adoneTests.pretty.json {
const {
json
} = adone.pretty;
let str: string;
str = json({});
str = json({}, {});
str = json({}, {}, 1);
str = json({}, { dashColor: "green" });
str = json({}, { defaultIndentation: 10 });
str = json({}, { emptyArrayMsg: "asdas" });
str = json({}, { keysColor: "green" });
str = json({}, { noAlign: true });
str = json({}, { noColor: true });
str = json({}, { numberColor: "green" });
str = json({}, { stringColor: "green" });
}

View File

@@ -0,0 +1,12 @@
namespace adoneTests.pretty.size {
const {
pretty: {
size
}
} = adone;
let str: string;
str = size(12345);
str = size(12345, "");
}

View File

@@ -0,0 +1,177 @@
namespace adoneTests.pretty.table {
const {
table
} = adone.pretty;
let str: string;
str = table([], {
model: []
});
str = table([], {
borderless: true,
model: []
});
str = table([], {
countAnsiEscapeCodes: true,
model: []
});
str = table([], {
noHeader: true,
model: []
});
str = table([], {
style: {
"padding-left": 1
},
model: []
});
str = table([], {
style: {
"padding-right": 1
},
model: []
});
str = table([], {
style: {
broder: ["a"]
},
model: []
});
str = table([], {
style: {
compact: true
},
model: []
});
str = table([], {
style: {
head: ["a"]
},
model: []
});
str = table([], {
width: 100,
model: []
});
str = table([], {
width: "100%",
model: []
});
str = table([], {
model: [{
id: "ads",
align: "center"
}]
});
str = table([], {
model: [{
id: "ads",
format: "%s"
}]
});
str = table([], {
model: [{
id: "ads",
format(val: any, item: object) {
return "2";
}
}]
});
str = table([], {
model: [{
id: "ads",
handle(item: object) {
return "a";
}
}]
});
str = table([], {
model: [{
id: "ads",
header: "he"
}]
});
str = table([], {
model: [{
id: "ads",
maxWidth: "100%"
}]
});
str = table([], {
model: [{
id: "ads",
maxWidth: 100
}]
});
str = table([], {
model: [{
id: "ads",
style: "asd"
}]
});
str = table([], {
model: [{
id: "ads",
style(val: any, str: string) {
return "1";
}
}]
});
str = table([], {
model: [{
id: "ads",
width: 100
}]
});
str = table([], {
model: [{
id: "ads",
width: "100%"
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: "soft"
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: "hard"
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: {
countAnsiEscapeCodes: true
}
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: {
join: true
}
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: {
mode: "soft"
}
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: {
mode: "hard"
}
}]
});
}

View File

@@ -0,0 +1,14 @@
namespace adoneTests.pretty.time {
const {
time
} = adone.pretty;
let str: string;
str = time(12345);
str = time(12345, {});
str = time(12345, { compact: true });
str = time(12345, { msDecimalDigits: 2 });
str = time(12345, { secDecimalDigits: 2 });
str = time(12345, { verbose: true });
}

View File

@@ -1,203 +0,0 @@
namespace adoneTests.text.pretty {
const {
text: {
pretty
}
} = adone;
let str: string;
namespace json {
const {
json
} = pretty;
str = json({});
str = json({}, {});
str = json({}, {}, 1);
str = json({}, { dashColor: "green" });
str = json({}, { defaultIndentation: 10 });
str = json({}, { emptyArrayMsg: "asdas" });
str = json({}, { keysColor: "green" });
str = json({}, { noAlign: true });
str = json({}, { noColor: true });
str = json({}, { numberColor: "green" });
str = json({}, { stringColor: "green" });
}
namespace table {
const {
table
} = pretty;
str = table([], {
model: []
});
str = table([], {
borderless: true,
model: []
});
str = table([], {
countAnsiEscapeCodes: true,
model: []
});
str = table([], {
noHeader: true,
model: []
});
str = table([], {
style: {
"padding-left": 1
},
model: []
});
str = table([], {
style: {
"padding-right": 1
},
model: []
});
str = table([], {
style: {
broder: ["a"]
},
model: []
});
str = table([], {
style: {
compact: true
},
model: []
});
str = table([], {
style: {
head: ["a"]
},
model: []
});
str = table([], {
width: 100,
model: []
});
str = table([], {
width: "100%",
model: []
});
str = table([], {
model: [{
id: "ads",
align: "center"
}]
});
str = table([], {
model: [{
id: "ads",
format: "%s"
}]
});
str = table([], {
model: [{
id: "ads",
format(val: any, item: object) {
return "2";
}
}]
});
str = table([], {
model: [{
id: "ads",
handle(item: object) {
return "a";
}
}]
});
str = table([], {
model: [{
id: "ads",
header: "he"
}]
});
str = table([], {
model: [{
id: "ads",
maxWidth: "100%"
}]
});
str = table([], {
model: [{
id: "ads",
maxWidth: 100
}]
});
str = table([], {
model: [{
id: "ads",
style: "asd"
}]
});
str = table([], {
model: [{
id: "ads",
style(val: any, str: string) {
return "1";
}
}]
});
str = table([], {
model: [{
id: "ads",
width: 100
}]
});
str = table([], {
model: [{
id: "ads",
width: "100%"
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: "soft"
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: "hard"
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: {
countAnsiEscapeCodes: true
}
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: {
join: true
}
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: {
mode: "soft"
}
}]
});
str = table([], {
model: [{
id: "ads",
wordwrap: {
mode: "hard"
}
}]
});
}
}

View File

@@ -195,20 +195,6 @@ namespace utilTests {
const e: object = util.invertObject({}, { onlyEnumerable: true });
}
namespace humanizeTime {
const a: string = util.humanizeTime(12345);
const b: string = util.humanizeTime(12345, {});
const c: string = util.humanizeTime(12345, { compact: true });
const d: string = util.humanizeTime(12345, { msDecimalDigits: 2 });
const e: string = util.humanizeTime(12345, { secDecimalDigits: 2 });
const f: string = util.humanizeTime(12345, { verbose: true });
}
namespace humanizeSize {
const a: string = util.humanizeSize(12345);
const b: string = util.humanizeSize(12345, "");
}
namespace parseSize {
const a: number | null = util.parseSize(123);
const b: number | null = util.parseSize("123Kb");
@@ -486,7 +472,7 @@ namespace utilTests {
const c: (a: number, b: string) => Promise<string> = util.throttle.create((a: number, b: string) => String(a) + b);
const d = util.throttle.create(() => { }, {});
const e = util.throttle.create(() => { }, { interval: 1000 });
const f = util.throttle.create(() => { }, { max: 10 });
const f = util.throttle.create(() => { }, { concurrency: 10 });
const g = util.throttle.create(() => { }, { ordered: true });
const h = util.throttle.create(() => { }, { waitForReturn: true });
const i = util.throttle.create(() => { }, { onDone() {} });

View File

@@ -0,0 +1,203 @@
namespace adoneTests.vault {
const {
is,
vault
} = adone;
let num: number;
let bool: boolean;
let obj: object;
let str: string;
namespace Vault {
const {
Vault
} = vault;
new Vault({
location: "a"
});
new Vault({
location: "a",
ValuableClass: vault.Valuable
});
const v = new Vault({
location: "a"
});
v.addTag("hello").then((x) => {
if (!is.null(x)) {
num = x;
}
});
v.clear().then((x) => {
num = x;
});
v.close().then();
v.create("hello").then((x) => {
x.set("a", "b");
});
v.create("hello", ["a", "b"]).then((x) => {
x.set("a", "b");
});
v.delete("a").then();
v.deleteTag("a").then((x) => {
bool = x;
});
v.entries().then((x) => {
obj = x;
});
v.get("a").then((x) => {
x.set("a", "b");
});
str = v.getNotes();
bool = v.has("a");
str = v.keys()[0];
str = v.location();
v.open().then(() => {});
v.release("name");
v.setNotes("asd").then();
str = v.tagNames()[0];
str = v.tagNames([1])[0];
obj = v.tags()[0];
obj = v.toJSON();
v.toJSON({ valuable: { includeId: true } }).then((x) => {
obj = x.valuables[0];
});
v.toJSON({ includeStats: true }).then((x) => {
num = x.stats.created;
num = x.stats.updated;
str = x.stats.location;
});
v.values().then((x) => {
x[0];
});
}
namespace Valuable {
new vault.Vault({ location: "a" }).get("a").then((v) => {
v.addTag("a").then();
v.clear().then((x) => {
num = x;
});
v.clear({ includeNotes: true }).then((x) => {
num = x;
});
v.clear({ includeTags: true }).then((x) => {
num = x;
});
v.delete("a").then((x) => {
num = x;
});
v.deleteAllTags();
v.entries().then((x) => {
obj = x;
});
v.entries({ entriesAsArray: true }).then((x) => {
obj = x;
});
v.entries({ includeEntryId: true }).then((x) => {
obj = x;
});
v.fromJSON({}).then((x) => {
num = x;
});
v.get("a").then();
str = v.getNotes();
bool = v.has("a");
bool = v.hasTag("a");
num = v.internalId();
str = v.keys()[0];
str = v.name();
v.set("a", "b").then((x) => {
num = x;
});
v.set("a", "b", "wtf").then((x) => {
num = x;
});
v.setMulti({ a: "1", b: "2" }).then();
v.setNotes("a").then();
obj = v.tags();
obj = v.toJSON();
obj = v.toJSON({ entriesAsArray: true });
obj = v.toJSON({ includeEntryId: true });
obj = v.toJSON({ includeId: false });
obj = v.toJSON({ tags: "normal" });
obj = v.toJSON({ tags: "none" });
obj = v.toJSON({ tags: "onlyId" });
obj = v.toJSON({ tags: "onlyName" });
v.type("a");
});
}
namespace slice {
new vault.Vault({ location: "a" }).get("a").then((valuable) => {
vault.slice(valuable, "s");
vault.slice(valuable, ["s"]);
vault.slice(valuable, ["s"], "a");
vault.slice(valuable, ["s"], "a");
const v = vault.slice(valuable, "s");
v.addTag("a").then();
v.delete("a").then((x) => {
num = x;
});
v.deleteAllTags().then();
v.deleteTag("a").then((x) => {
bool = x;
});
v.entries().then((x) => {
obj = x;
});
v.entries({}).then((x) => {
obj = x;
});
v.entries({ entriesAsArray: true }).then((x) => {
obj = x;
});
v.entries({ includeEntryId: true }).then((x) => {
obj = x;
});
v.fromJSON({}).then((x) => {
num = x;
});
v.get("a").then();
str = v.getNotes();
bool = v.has("a");
bool = v.hasTag("a");
num = v.internalId();
str = v.keys()[0];
str = v.name();
v.set("a", "b").then((x) => {
num = x;
});
v.set("a", "b", "wtf").then((x) => {
num = x;
});
v.setMulti({}).then();
v.setNotes("a").then((x) => {
num = x;
});
obj = v.tags()[0];
obj = v.toJSON();
obj = v.toJSON({});
obj = v.toJSON({ entriesAsArray: true });
obj = v.toJSON({ includeEntryId: true });
obj = v.toJSON({ includeId: true });
obj = v.toJSON({ tags: "none" });
obj = v.toJSON({ tags: "normal" });
obj = v.toJSON({ tags: "onlyId" });
obj = v.toJSON({ tags: "onlyName" });
v.type("a");
});
}
namespace open {
vault.open({ location: "a" }).then((x) => {
x.get("a").then((x) => x.setMulti({}));
});
vault.open({ location: "a", ValuableClass: vault.Valuable }).then((x) => {
x.get("a").then((x) => x.setMulti({}));
});
}
}

View File

@@ -1,23 +1,32 @@
namespace AdoneRootTests {
{ const a: symbol = adone.null; }
let num: number;
let sym: symbol;
let str: string;
let numarr: number[];
let obj: object;
let bool: boolean;
sym = adone.null;
adone.noop();
{ const a: number = adone.identity(2); }
{ const a: string = adone.identity("2"); }
{ const a: number[] = adone.identity([1, 2]); }
{ adone.truly() === true; }
{ adone.falsely() === false; }
{ const a: string = adone.ok; }
{ const a: string = adone.bad; }
{ const a: string[] = adone.exts; }
num = adone.identity(2);
str = adone.identity("3");
numarr = adone.identity([1, 2]);
adone.truly() === true;
adone.falsely() === false;
str = adone.ok;
str = adone.bad;
adone.log();
adone.fatal();
adone.error();
adone.warn();
adone.info();
adone.debug();
adone.trace();
{ const a: object = adone.o(); }
{ const a: object = adone.o({}); }
adone.logFatal();
adone.logError();
adone.logWarn();
adone.logInfo();
adone.logDebug();
adone.logTrace();
obj = adone.o();
obj = adone.o({});
{ const a: typeof Date = adone.Date; }
{ const a: typeof process.hrtime = adone.hrtime; }
{ const a: typeof global.setTimeout = adone.setTimeout; }
@@ -26,6 +35,7 @@ namespace AdoneRootTests {
{ const a: typeof clearInterval = adone.clearInterval; }
{ const a: typeof global.setImmediate = adone.setImmediate; }
{ const a: typeof clearImmediate = adone.clearImmediate; }
adone.lazify({});
adone.lazify({}, {});
adone.lazify({}, {}, () => { });
@@ -33,40 +43,15 @@ namespace AdoneRootTests {
adone.lazify({}, {}, () => { }, { configurable: true });
adone.lazify({}, {}, () => { }, { writable: false });
adone.lazify({}, {}, () => { }, { mapper: (key: string, obj: any) => null });
adone.tag.set({}, "123");
{ const a: boolean = adone.tag.has({}, "123"); }
bool = adone.tag.has({}, "123");
adone.tag.define("12");
adone.tag.define("123", "456");
{ const a: symbol = adone.tag.SUBSYSTEM; }
{ const a: symbol = adone.tag.APPLICATION; }
{ const a: symbol = adone.tag.TRANSFORM; }
{ const a: symbol = adone.tag.CORE_STREAM; }
{ const a: symbol = adone.tag.LOGGER; }
{ const a: symbol = adone.tag.LONG; }
{ const a: symbol = adone.tag.BIGNUMBER; }
{ const a: symbol = adone.tag.EXBUFFER; }
{ const a: symbol = adone.tag.EXDATE; }
{ const a: symbol = adone.tag.CONFIGURATION; }
{ const a: symbol = adone.tag.GENESIS_NETRON; }
{ const a: symbol = adone.tag.GENESIS_PEER; }
{ const a: symbol = adone.tag.NETRON; }
{ const a: symbol = adone.tag.NETRON_PEER; }
{ const a: symbol = adone.tag.NETRON_ADAPTER; }
{ const a: symbol = adone.tag.NETRON_DEFINITION; }
{ const a: symbol = adone.tag.NETRON_DEFINITIONS; }
{ const a: symbol = adone.tag.NETRON_REFERENCE; }
{ const a: symbol = adone.tag.NETRON_INTERFACE; }
{ const a: symbol = adone.tag.NETRON_STUB; }
{ const a: symbol = adone.tag.NETRON_REMOTESTUB; }
{ const a: symbol = adone.tag.NETRON_STREAM; }
{ const a: symbol = adone.tag.FAST_STREAM; }
{ const a: symbol = adone.tag.FAST_FS_STREAM; }
{ const a: symbol = adone.tag.FAST_FS_MAP_STREAM; }
{ const a: object = adone.bind("library"); } // hmm
{ const a: string = adone.getAssetAbsolutePath("asset"); }
str = adone.getAssetAbsolutePath("asset");
{ const a: Buffer | string = adone.loadAsset("asset"); }
{ const a: object = adone.require("path"); }
{ const a: object = adone.package; }
obj = adone.require("path");
obj = adone.package;
{ const a: typeof adone.assertion.assert = adone.assert; }
{ const a: typeof adone.assertion.expect = adone.expect; }
}

View File

@@ -16,7 +16,8 @@
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true
"experimentalDecorators": true,
"esModuleInterop": true
},
"files": [
"adone-tests.ts",
@@ -51,7 +52,7 @@
"glosses/data.d.ts",
"glosses/datetime.d.ts",
"glosses/events.d.ts",
"glosses/exceptions.d.ts",
"glosses/errors.d.ts",
"glosses/fake.d.ts",
"glosses/fast.d.ts",
"glosses/fs.d.ts",
@@ -63,6 +64,10 @@
"glosses/net/http/client.d.ts",
"glosses/net/http/index.d.ts",
"glosses/net/index.d.ts",
"glosses/pretty/json.d.ts",
"glosses/pretty/size.d.ts",
"glosses/pretty/table.d.ts",
"glosses/pretty/time.d.ts",
"glosses/promise.d.ts",
"glosses/regex.d.ts",
"glosses/semver.d.ts",
@@ -78,11 +83,11 @@
"glosses/templating/index.d.ts",
"glosses/templating/nunjucks.d.ts",
"glosses/text/index.d.ts",
"glosses/text/pretties.d.ts",
"glosses/text/spinners.d.ts",
"glosses/text/table.d.ts",
"glosses/text/unicode.d.ts",
"glosses/utils.d.ts",
"glosses/vault.d.ts",
"index.d.ts",
"test/glosses/application.ts",
"test/glosses/archives.ts",
@@ -113,7 +118,7 @@
"test/glosses/data.ts",
"test/glosses/datetime.ts",
"test/glosses/events.ts",
"test/glosses/exceptions.ts",
"test/glosses/errors.ts",
"test/glosses/fake.ts",
"test/glosses/fast.ts",
"test/glosses/fs.ts",
@@ -123,6 +128,10 @@
"test/glosses/math/simd.ts",
"test/glosses/meta.ts",
"test/glosses/net/http/client.ts",
"test/glosses/pretty/json.ts",
"test/glosses/pretty/size.ts",
"test/glosses/pretty/table.ts",
"test/glosses/pretty/time.ts",
"test/glosses/promise.ts",
"test/glosses/regex.ts",
"test/glosses/semver.ts",
@@ -136,11 +145,11 @@
"test/glosses/templating/dot.ts",
"test/glosses/templating/nunjucks.ts",
"test/glosses/text/index.ts",
"test/glosses/text/pretties.ts",
"test/glosses/text/spinners.ts",
"test/glosses/text/table.ts",
"test/glosses/text/unicode.ts",
"test/glosses/utils.ts",
"test/glosses/vault.ts",
"test/index-import.ts",
"test/index.ts"
]