Merge branch 'types-2.0' into mergemaster20161129

This commit is contained in:
Paul van Brenk
2016-11-30 11:11:47 -08:00
20 changed files with 1846 additions and 34 deletions
+5 -1
View File
@@ -80,7 +80,11 @@ var axiosInstance = axios.create({
timeout: 1000
});
axiosInstance.request({url: "issues/1"});
axiosInstance.request({url: "issues/1"}).then(res => {
if (res.headers['content-type'].startsWith('application/json')) {
throw new Error('Unexpected content-type');
}
});
axios.all<Repository, Repository>([getRepoDetails, getRepoDetails]).then(([repo1, repo2]) => {
var sumIds = repo1.data.id + repo2.data.id;
+1 -1
View File
@@ -159,7 +159,7 @@ declare namespace Axios {
/**
* headers that the server responded with
*/
headers: Object;
headers: {[index: string]: any};
/**
* config that was provided to `axios` for the request
+3 -3
View File
@@ -334,15 +334,15 @@ b = Reflect.setPrototypeOf(a, a);
// #############################################################################################
// ECMAScript 7
// Modules: es7.array.includes, es7.string.at, es7.string.lpad, es7.string.rpad,
// Modules: es7.array.includes, es7.string.at, ees7.string.pad-start, es7.string.pad-end,
// es7.object.to-array, es7.object.get-own-property-descriptors, es7.regexp.escape,
// es7.map.to-json, and es7.set.to-json
// #############################################################################################
b = arrayOfPoint.includes(point, i);
s = s.at(i);
s = s.lpad(i, s);
s = s.rpad(i, s);
s = s.padStart(i, s);
s = s.padEnd(i, s);
arrayOfAny = Object.values(a);
arrayOfStringAny = Object.entries(a);
pdm = Object.getOwnPropertyDescriptors(a);
+3 -3
View File
@@ -890,7 +890,7 @@ declare namespace Reflect {
// #############################################################################################
// ECMAScript 7
// Modules: es7.array.includes, es7.string.at, es7.string.lpad, es7.string.rpad,
// Modules: es7.array.includes, es7.string.at, es7.string.pad-start, es7.string.pad-end,
// es7.object.to-array, es7.object.get-own-property-descriptors, es7.regexp.escape,
// es7.map.to-json, and es7.set.to-json
// #############################################################################################
@@ -901,8 +901,8 @@ interface Array<T> {
interface String {
at(index: number): string;
lpad(length: number, fillStr?: string): string;
rpad(length: number, fillStr?: string): string;
padStart(length: number, fillStr?: string): string;
padEnd(length: number, fillStr?: string): string;
}
interface ObjectConstructor {
+2 -1
View File
@@ -3,6 +3,7 @@
//date operations
var start: Date = gantt.date.week_start(new Date());
var next: Date = gantt.date.add(new Date(), 1, "week");
var datePos: Date = gantt.dateFromPos(0);
//hotkeys
gantt.keys.edit_cancel = 13;
@@ -33,4 +34,4 @@ gantt.attachEvent("onBeforeLightbox", function (id?: string) {
});
//gantt enterprise
var gantt2 = Gantt.getGanttInstance();
gantt2.config.api_date = "format";
gantt2.config.api_date = "format";
+18 -18
View File
@@ -1,13 +1,13 @@
// Type definitions for dhtmlxGantt 4.0.0
// Project: http://dhtmlx.com/docs/products/dhtmlxGantt
// Definitions by: Maksim Kozhukh <http://github.com/mkozhukh>
// Definitions by: Maksim Kozhukh <http://github.com/mkozhukh>, Christophe Camicas <http://github.com/chriscamicas>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface GanttCallback { (...args: any[]) : any }
type GanttEventName ='onAfterAutoSchedule'|'onAfterBatchUpdate'|'onAfterLightbox'|'onAfterLinkAdd'|'onAfterLinkDelete'|'onAfterLinkUpdate'|'onAfterRedo'|'onAfterTaskAdd'|'onAfterTaskAutoSchedule'|'onAfterTaskDelete'|'onAfterTaskDrag'|'onAfterTaskMove'|'onAfterTaskUpdate'|'onAfterUndo'|'onAjaxError'|'onBeforeAutoSchedule'|'onBeforeBatchUpdate'|'onBeforeCollapse'|'onBeforeDataRender'|'onBeforeExpand'|'onBeforeGanttReady'|'onBeforeGanttRender'|'onBeforeLightbox'|'onBeforeLinkAdd'|'onBeforeLinkDelete'|'onBeforeLinkDisplay'|'onBeforeLinkUpdate'|'onBeforeParse'|'onBeforeRedo'|'onBeforeRowDragEnd'|'onBeforeTaskAdd'|'onBeforeTaskAutoSchedule'|'onBeforeTaskChanged'|'onBeforeTaskDelete'|'onBeforeTaskDisplay'|'onBeforeTaskDrag'|'onBeforeTaskMove'|'onBeforeTaskSelected'|'onBeforeTaskUpdate'|'onBeforeUndo'|'onCircularLinkError'|'onClear'|'onCollapse'|'onColumnResize'|'onColumnResizeEnd'|'onColumnResizeStart'|'onContextMenu'|'onDataRender'|'onEmptyClick'|'onError'|'onExpand'|'onGanttReady'|'onGanttRender'|'onGanttScroll'|'onGridHeaderClick'|'onGridResize'|'onGridResizeEnd'|'onGridResizeStart'|'onLightbox'|'onLightboxButton'|'onLightboxCancel'|'onLightboxChange'|'onLightboxDelete'|'onLightboxSave'|'onLinkClick'|'onLinkDblClick'|'onLinkIdChange'|'onLinkValidation'|'onLoadEnd'|'onLoadStart'|'onMouseMove'|'onOptionsLoad'|'onParse'|'onRowDragEnd'|'onRowDragStart'|'onScaleAdjusted'|'onScaleClick'|'onTaskClick'|'onTaskClosed'|'onTaskCreated'|'onTaskDblClick'|'onTaskDrag'|'onTaskIdChange'|'onTaskLoading'|'onTaskOpened'|'onTaskRowClick'|'onTaskSelected'|'onTaskUnselected'|'onTemplatesReady';
type GanttCallback = (...args: any[]) => any;
type GanttEventName = 'onAfterAutoSchedule'|'onAfterBatchUpdate'|'onAfterLightbox'|'onAfterLinkAdd'|'onAfterLinkDelete'|'onAfterLinkUpdate'|'onAfterRedo'|'onAfterTaskAdd'|'onAfterTaskAutoSchedule'|'onAfterTaskDelete'|'onAfterTaskDrag'|'onAfterTaskMove'|'onAfterTaskUpdate'|'onAfterUndo'|'onAjaxError'|'onBeforeAutoSchedule'|'onBeforeBatchUpdate'|'onBeforeCollapse'|'onBeforeDataRender'|'onBeforeExpand'|'onBeforeGanttReady'|'onBeforeGanttRender'|'onBeforeLightbox'|'onBeforeLinkAdd'|'onBeforeLinkDelete'|'onBeforeLinkDisplay'|'onBeforeLinkUpdate'|'onBeforeParse'|'onBeforeRedo'|'onBeforeRowDragEnd'|'onBeforeTaskAdd'|'onBeforeTaskAutoSchedule'|'onBeforeTaskChanged'|'onBeforeTaskDelete'|'onBeforeTaskDisplay'|'onBeforeTaskDrag'|'onBeforeTaskMove'|'onBeforeTaskSelected'|'onBeforeTaskUpdate'|'onBeforeUndo'|'onCircularLinkError'|'onClear'|'onCollapse'|'onColumnResize'|'onColumnResizeEnd'|'onColumnResizeStart'|'onContextMenu'|'onDataRender'|'onEmptyClick'|'onError'|'onExpand'|'onGanttReady'|'onGanttRender'|'onGanttScroll'|'onGridHeaderClick'|'onGridResize'|'onGridResizeEnd'|'onGridResizeStart'|'onLightbox'|'onLightboxButton'|'onLightboxCancel'|'onLightboxChange'|'onLightboxDelete'|'onLightboxSave'|'onLinkClick'|'onLinkDblClick'|'onLinkIdChange'|'onLinkValidation'|'onLoadEnd'|'onLoadStart'|'onMouseMove'|'onOptionsLoad'|'onParse'|'onRowDragEnd'|'onRowDragStart'|'onScaleAdjusted'|'onScaleClick'|'onTaskClick'|'onTaskClosed'|'onTaskCreated'|'onTaskDblClick'|'onTaskDrag'|'onTaskIdChange'|'onTaskLoading'|'onTaskOpened'|'onTaskRowClick'|'onTaskSelected'|'onTaskUnselected'|'onTemplatesReady';
interface GanttTemplates{
interface GanttTemplates {
/**
* specifies the format of dates that are set by means of API methods. Used to parse incoming dates
* @param date the date which needs formatting
@@ -269,7 +269,7 @@ interface GanttTemplates{
}
interface GanttConfigOptions{
interface GanttConfigOptions {
/**
* sets the date format for addTask() method to
*/
@@ -802,7 +802,7 @@ interface GanttConfigOptions{
}
interface GanttDateHelpers{
interface GanttDateHelpers {
add(origin: Date, count: number, unit: string): Date;
copy(origin: Date): Date;
@@ -823,21 +823,21 @@ interface GanttDateHelpers{
to_fixed(value: number): string;
}
interface GanttHotkeys{
interface GanttHotkeys {
edit_save: number;
edit_cancel: number;
}
//Gantt.locale
//Gantt.locale
interface GanttLocaleDate{
interface GanttLocaleDate {
month_full: string[];
month_short: string[];
day_full: string[];
day_short: string[];
}
interface GanttLocaleLabels{
interface GanttLocaleLabels {
new_task: string;
icon_save: string;
icon_cancel: string;
@@ -861,25 +861,25 @@ interface GanttLocaleLabels{
years: string;
}
interface GanttLocale{
interface GanttLocale {
date: GanttLocaleDate;
labels: GanttLocaleLabels;
}
interface GanttEnterprise{
interface GanttEnterprise {
/**
* Creates a new instance of Gantt
*/
getGanttInstance(): GanttStatic;
}
interface GanttStatic{
interface GanttStatic {
templates: GanttTemplates;
config: GanttConfigOptions;
date: GanttDateHelpers;
keys: GanttHotkeys;
skin: String;
version: String;
skin: string;
version: string;
locale: GanttLocale;
$click: any;
@@ -1056,10 +1056,10 @@ interface GanttStatic{
dataProcessor(url: string): void;
/**
* gets the date of the specified horizontal position in the chart area
* returns the date of the specified horizontal position in the chart area
* @param pos the relative horizontal position you want to know the date of
*/
dateFromPos(pos: number): void;
dateFromPos(pos: number): Date;
/**
* returns false if the provided argument is undefined, otherwise true
@@ -1730,4 +1730,4 @@ interface GanttStatic{
declare var gantt: GanttStatic;
declare var Gantt: GanttEnterprise;
declare var Gantt: GanttEnterprise;
+64
View File
@@ -0,0 +1,64 @@
// Type definitions for fxn 0.0.4
// Project: https://github.com/poly/fxn
// Definitions by: Adam Charron <https://github.com/charrondev>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node"/>
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
export interface HttpHeaders {
[item: string]: string;
}
export abstract class Controller {
protected _method: HttpMethod;
protected _path: string;
protected _requestHeaders: Object;
protected _headers: Object;
protected _status: number;
protected _responder: Function;
protected _securityPolicies: Object;
protected params: any;
constructor(path: string, method: string, requestHeaders: Object, params: Object, responder: Function);
convertMethod(method: HttpMethod, id: number): string;
run(): void;
notImplemented(msg: string, details: Object): boolean;
before(): void;
after(): void;
get(): void;
put(): void;
post(): void;
del(): void;
options(): void;
index(): void;
show(): void;
update(): void;
create(): void;
destroy(): void;
status(value: number): boolean;
setHeaders(): HttpHeaders;
setHeader(key: string, value: string): string;
appendHeader(key: string, value: string): string;
getHeader(key: string, value: string): string;
code(code: number): number;
getStatus(): number;
render(data: Buffer | String | Object): void;
allowOrigin(value: string): this;
securityPolicy(directive: string, src: string): string;
redirect(location: string): void;
}
export abstract class Daemon {
constructor(string: string);
}
export abstract class Application {
constructor(string: string);
send: Function;
}
export abstract class Router {}
export abstract class Scheduler {}
+18
View File
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts"
]
}
+290
View File
@@ -0,0 +1,290 @@
import * as Hoek from "hoek";
/**
* Import the entire module as above or use named imports:
* import { clone, merge, assert } from "hoek";
* "Tests" taken straight from hoek API reference and adapted to TypeScript.
*/
// clone(obj)
let nestedObj = {
w: /^something$/ig,
x: {
a: [1, 2, 3],
b: 123456,
c: new Date()
},
y: 'y',
z: new Date()
};
let copy = Hoek.clone(nestedObj);
copy.x.b = 100;
console.log(copy.y); // results in 'y'
console.log(nestedObj.x.b); // results in 123456
console.log(copy.x.b); // results in 100
// cloneWithShallow(obj, keys)
nestedObj = {
w: /^something$/ig,
x: {
a: [1, 2, 3],
b: 123456,
c: new Date()
},
y: 'y',
z: new Date()
};
copy = Hoek.cloneWithShallow(nestedObj, ['x']);
copy.x.b = 100;
console.log(copy.y); // results in 'y'
console.log(nestedObj.x.b); // results in 100
console.log(copy.x.b); // results in 100
// merge(target, source, isNullOverride, isMergeArrays)
let target = { a: 1, b: 2 };
let source = { a: 0, c: 5 };
let source2 = { a: null, c: 5 };
Hoek.merge(target, source); // results in {a: 0, b: 2, c: 5}
Hoek.merge(target, source2); // results in {a: null, b: 2, c: 5}
Hoek.merge(target, source2, false); // results in {a: 1, b: 2, c: 5}
let targetArray = [1, 2, 3];
let sourceArray = [4, 5];
Hoek.merge(targetArray, sourceArray); // results in [1, 2, 3, 4, 5]
Hoek.merge(targetArray, sourceArray, true, false); // results in [4, 5]
// applyToDefaults(defaults, options, isNullOverride)
let defaults = { host: "localhost", port: 8000 };
let options = { port: 8080 };
let config = Hoek.applyToDefaults(defaults, options); // results in { host: "localhost", port: 8080 }
defaults = { host: "localhost", port: 8000 };
let options1 = { host: null, port: 8080 };
config = Hoek.applyToDefaults(defaults, options1, true); // results in { host: null, port: 8080 }
// applyToDefaultsWithShallow(defaults, options, keys)
let defaults1 = {
server: {
host: "localhost",
port: 8000
},
name: 'example'
};
let options2 = { server: { port: 8080 } };
let config1 = Hoek.applyToDefaultsWithShallow(defaults1, options2, ['server']); // results in { server: { port: 8080 }, name: 'example' }
// deepEqual(b, a, [options])
Hoek.deepEqual({ a: [1, 2], b: 'string', c: { d: true } }, { a: [1, 2], b: 'string', c: { d: true } }); //results in true
Hoek.deepEqual(Object.create(null), {}, { prototype: false }); //results in true
Hoek.deepEqual(Object.create(null), {}); //results in false
// unique(array, key)
let array = [1, 2, 2, 3, 3, 4, 5, 6];
let newArray = Hoek.unique(array); // results in [1,2,3,4,5,6]
let array1 = [{ id: 1 }, { id: 1 }, { id: 2 }];
let newArray1 = Hoek.unique(array1, "id"); // results in [{id: 1}, {id: 2}]
// mapToObject(array, key)
array = [1, 2, 3];
let newObject = Hoek.mapToObject(array); // results in {"1": true, "2": true, "3": true}
array1 = [{ id: 1 }, { id: 2 }];
newObject = Hoek.mapToObject(array1, "id"); // results in {"1": true, "2": true}
// intersect(array1, array2)
array = [1, 2, 3];
let array2 = [1, 4, 5];
let newArray2 = Hoek.intersect(array, array2); // results in [1]
// contain(ref, values, [options])
Hoek.contain('aaa', 'a', { only: true }); // true
Hoek.contain([{ a: 1 }], [{ a: 1 }], { deep: true }); // true
Hoek.contain([1, 2, 2], [1, 2], { once: true }); // false
Hoek.contain({ a: 1, b: 2, c: 3 }, { a: 1, d: 4 }, { part: true }); // true
// flatten(array, [target])
let array3 = [1, [2, 3]];
let flattenedArray = Hoek.flatten(array); // results in [1, 2, 3]
array3 = [1, [2, 3]];
let target1 = [4, [5]];
flattenedArray = Hoek.flatten(array3, target1); // results in [4, [5], 1, 2, 3]
// reach(obj, chain, [options])
let chain = 'a.b.c';
let obj = { a: { b: { c: 1 } } };
Hoek.reach(obj, chain); // returns 1
chain = 'a.b.-1';
let obj1 = { a: { b: [2, 3, 6] } };
Hoek.reach(obj1, chain); // returns 6
// reachTemplate(obj, template, [options])
chain = 'a.b.c';
obj = { a: { b: { c: 1 } } };
Hoek.reachTemplate(obj, '1+{a.b.c}=2'); // returns '1+1=2'
// transform(obj, transform, [options])
let source1 = {
address: {
one: '123 main street',
two: 'PO Box 1234'
},
title: 'Warehouse',
state: 'CA'
};
let result = Hoek.transform(source1, {
'person.address.lineOne': 'address.one',
'person.address.lineTwo': 'address.two',
'title': 'title',
'person.address.region': 'state'
});
// Results in
// {
// person: {
// address: {
// lineOne: '123 main street',
// lineTwo: 'PO Box 1234',
// region: 'CA'
// }
// },
// title: 'Warehouse'
// }
// shallow(obj)
let shallow = Hoek.shallow({ a: { b: 1 } });
// stringify(obj)
let a: any = {};
a.b = a;
Hoek.stringify(a); // Returns '[Cannot display object: Converting circular structure to JSON]'
// Timer
let timerObj = new Hoek.Timer();
console.log("Time is now: " + timerObj.ts);
console.log("Elapsed time from initialization: " + timerObj.elapsed() + 'milliseconds');
// Bench
let benchObj = new Hoek.Bench();
console.log("Elapsed time from initialization: " + benchObj.elapsed() + 'milliseconds');
// base64urlEncode(value)
Hoek.base64urlEncode("hoek");
// base64urlDecode(value)
Hoek.base64urlDecode("aG9law==");
// escapeHtml(string)
let string = '<html> hey </html>';
let escapedString = Hoek.escapeHtml(string); // returns &lt;html&gt; hey &lt;/html&gt;
// escapeHeaderAttribute(attribute)
a = Hoek.escapeHeaderAttribute('I said "go w\\o me"'); //returns I said \"go w\\o me\"
// escapeRegex(string)
a = Hoek.escapeRegex('4^f$s.4*5+-_?%=#!:@|~\\/`"(>)[<]d{}s,'); // returns 4\^f\$s\.4\*5\+\-_\?%\=#\!\:@\|~\\\/`"\(>\)\[<\]d\{\}s\,
// assert(condition, message)
let x = 1, y = 2;
Hoek.assert(x === y, 'x should equal y'); // Throws 'x should equal y'
Hoek.assert(x === y, new Error('x should equal y')); // Throws the given error object
// abort(message)
Hoek.abort("Error message");
// displayStack(slice)
let stack = Hoek.displayStack();
console.log(stack);
// callStack(slice)
let stack2 = Hoek.callStack();
console.log(stack2);
// nextTick(fn)
let myFn = function () {
console.log('Do this later');
};
let nextFn = Hoek.nextTick(myFn);
nextFn();
console.log('Do this first');
// Results in:
//
// Do this first
// Do this later
// once(fn)
myFn = function () {
console.log('Ran myFn');
};
let onceFn = Hoek.once(myFn);
onceFn(); // results in "Ran myFn"
onceFn(); // results in undefined
// ignore
Hoek.ignore();
// uniqueFilename(path, extension)
let result1 = Hoek.uniqueFilename('./test/modules', 'txt'); // results in "full/path/test/modules/{random}.txt"
// isInteger(value)
result = Hoek.isInteger('23');
+211
View File
@@ -0,0 +1,211 @@
// Type definitions for hoek 4.1
// Project: https://github.com/hapijs/hoek
// Definitions by: Prashant Tiwari <https://github.com/prashaantt>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface ContainOptions {
/** Perform a deep comparison of the values? */
deep?: boolean;
/** Allow only one occurrence of each value? */
once?: boolean;
/** Don't allow values not explicitly listed? */
only?: boolean;
/** Allow partial match of the values? */
part?: boolean;
}
interface ReachOptions {
/** String to split chain path on. Defaults to ".". */
separator?: string;
/** Value to return if the path or value is not present. Default is undefined. */
default?: any;
/** Throw an error on missing member? Default is false. */
strict?: boolean;
/** Allow traversing functions for properties? */
functions?: boolean;
}
// Object
/**
* Clone an object or an array.
*/
export function clone<T>(obj: T): T;
/**
* Clone an object or array.
* */
export function cloneWithShallow(obj: any, keys: string[]): any;
/**
* Merge all the properties of source into target. */
export function merge<T1, T2>(target: T1, source: T2, isNullOverride?: boolean, isMergeArrays?: boolean): T1 & T2;
/**
* Apply options to a copy of the defaults.
* */
export function applyToDefaults<T1, T2>(defaults: T1, options: T2, isNullOverride?: boolean): T1 & T2;
/**
* Apply options to a copy of the defaults.
*/
export function applyToDefaultsWithShallow<T1, T2>(defaults: T1, options: T2, keys?: string[]): T1 & T2;
/**
* Perform a deep comparison of the two values.
*/
export function deepEqual<T>(b: T, a: T, options?: any): T;
/**
* Remove duplicate items from Array.
*/
export function unique<T>(array: T[], key?: string): T[];
/**
* Convert an Array into an Object.
*/
export function mapToObject(array: any[], key?: string): any;
/**
* Find the common unique items in two arrays.
*/
export function intersect(array1: any[], array2: any[]): any;
/**
* Test if the reference value contains the provided values.
*/
export function contain(ref: any, values: any, options?: ContainOptions): boolean;
/**
* Flatten an array.
*/
export function flatten(array: any[], target?: any[]): any[];
/**
* Convert an object key chain string to reference.
*/
export function reach(obj: any, chain: any, options?: ReachOptions): any;
/**
* Replace string parameters ({name}) with their corresponding object key values.
*/
export function reachTemplate(obj: any, template: string, options?: ReachOptions): any;
/**
* Transform an existing object into a new one based on the supplied obj and transform map.
*/
export function transform(obj: any, transform: any, options?: ReachOptions): any;
/**
* Perform a shallow copy by copying the references of all the top level children.
*/
export function shallow(obj: any): any;
/**
* Convert an object to string. Any errors are caught and reported back in the form of the returned string.
*/
export function stringify(obj: any): string;
// Timer
/**
* A Timer object.
*/
export class Timer {
/** The number of milliseconds elapsed since the epoch. */
ts: number;
/** The time (ms) elapsed since the timer was created. */
elapsed(): number;
}
// Bench
/**
* Same as Timer, except ts stores the internal node clock.
*/
export class Bench {
/** The number of milliseconds on the node clock elapsed since the epoch. */
ts: number;
/** The time (ms) elapsed since the timer was created. */
elapsed(): number;
}
// Binary Encoding/Decoding
/**
* Encode value of string or buffer type in Base64 or URL encoding.
*/
export function base64urlEncode(value: string): string;
/**
* Decode string into Base64 or URL encoding.
*/
export function base64urlDecode(value: string): string;
// Escaping Characters
/**
* Escape html characters.
*/
export function escapeHtml(htmlString: string): string;
/**
* Escape attribute value for use in HTTP header.
*/
export function escapeHeaderAttribute(attribute: string): string;
/**
* Escape string for Regex construction.
*/
export function escapeRegex(regexString: string): string;
// Errors
/**
* Print message or throw error if condition fails.
*/
export function assert(condition: boolean, message: string | Error): void | Error;
/**
* Throw if process.env.NODE_ENV === 'test'. Else display most recent stack and exit process.
*/
export function abort(message: string | Error): void;
/**
* Display the trace stack.
*/
export function displayStack(slice?: any): string[];
/**
* Return a trace stack array.
*/
export function callStack(slice?: any): any[];
// Function
/**
* Wrap fn in process.nextTick.
*/
export function nextTick(fn: () => void): () => void;
/**
* Make sure fn is only run once.
*/
export function once(fn: () => void): () => void;
/**
* A simple no-op function.
*/
export function ignore(): void;
// Miscellaneous
/**
* path to prepend to a randomly generated file name.
*/
export function uniqueFilename(path: string, extension?: string): string;
/**
* Check value to see if it is an integer.
*/
export function isInteger(value: any): boolean;
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"hoek-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "../tslint.json"
}
+2
View File
@@ -43,6 +43,8 @@ declare namespace Koa {
toJSON(): any;
inspect(): any;
[key: string]: any;
}
export interface Request {
+1009
View File
File diff suppressed because it is too large Load Diff
+154
View File
@@ -0,0 +1,154 @@
import * as Nodal from './index.d';
let BlogPost: typeof Nodal.Model;
class User extends Nodal.Model {
public beforeSave (callback: (err?: Error) => void) {
if (!this.hasErrors() && this.hasChanged('password')) {
callback();
} else {
callback(new Error("Has errors"));
}
}
public verifyPassword (unencrypted: string, callback: (model: Nodal.Model, err: Error, result: boolean) => void) {
}
}
User.setDatabase(Nodal.require('db/main.js'));
User.setSchema(Nodal.my.Schema.models.User);
User.validates('username', 'must exist', v => v);
User.validates('password', 'must be at least 5 characters in length', v => v && v.length >= 5);
class BlogPostsController extends Nodal.Controller {
index() {
BlogPost.query()
.join('user')
.join('comments')
.where(this.params.query)
.end((err, blogPosts) => {
this.respond(err || blogPosts);
});
}
show() {
BlogPost.find(this.params.route.id, (err, blogPost) => this.respond(err || blogPost));
}
create() {
BlogPost.create(this.params.body, (err, blogPost) => this.respond(err || blogPost));
}
update() {
BlogPost.update(this.params.route.id, this.params.body, (err, blogPost) => this.respond(err || blogPost));
}
destroy() {
BlogPost.destroy(this.params.route.id, (err, blogPost) => this.respond(err || blogPost))
}
}
type generateParam = string | number;
class AccessToken extends Nodal.Model {
constructor(modelData: Object) {
super(modelData);
}
public static generateAccessTokenString (...args: generateParam[]) {
return "thing";
}
public static login (params: any, callback: Function) {
if (params.body.grant_type !== 'password') {
return callback(new Error('Must supply grant_type'));
}
User.query<User>()
.where({username: params.body.username})
.end((err, users) => {
if (err || !users || !users.length) {
return callback(new Error('User not found'));
}
const user = users[0];
user.verifyPassword(params.body.password, (error, result) => {
if (error || !result) {
return callback(new Error('Invalid credentials'));
}
new AccessToken({
user_id: user.get('id'),
access_token: this.generateAccessTokenString(user.get('id'), user.get('email'), new Date().valueOf()),
token_type: 'bearer',
expires_at: (new Date(new Date().valueOf() + (30 * 24 * 60 * 60 * 1000))),
ip_address: params.ip_address
}).save(callback);
});
});
}
public static verify (params: any, callback: Function) {
this.query()
.join('user')
.where({
access_token: params.auth.access_token,
expires_at__gte: new Date()
})
.end((err, accessTokens) => {
if (err || !accessTokens || !accessTokens.length) {
return callback(new Error('Your access token is invalid.'));
}
const accessToken = accessTokens[0];
if (!accessToken.joined('user')) {
return callback(new Error('Your access token belongs to an invalid user.'));
}
return callback(null, accessToken, accessToken.joined('user'));
});
}
public static logout (params: any, callback: Function) {
this.verify(params, (err: Error, accessToken: AccessToken) => {
if (err) {
return callback(err);
}
return accessToken.destroy(callback);
});
}
}
AccessToken.setDatabase(Nodal.require('db/main.js'));
AccessToken.setSchema(Nodal.my.Schema.models.AccessToken);
AccessToken.joinsTo(User, {multiple: true});
class AuthController extends Nodal.Controller {
public authorize (callback: Function) {
this.setHeader('Cache-Control', 'no-store');
this.setHeader('Pragma', 'no-cache');
AccessToken.verify(this.params, (err: Error, accessToken: string, user: User) => {
if (err) {
return this.respond(err);
}
callback(accessToken, user);
});
}
}
export default AuthController;
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"nodal-tests.ts"
]
}
+1 -1
View File
@@ -7,7 +7,7 @@ const path = require("path");
// Path of tslint when `types-publisher` is symlinked
const symlinkedTslintPath = "../node_modules/types-publisher/node_modules/tslint"
const tslintPath = existsSync(path.join(pkg, symlinkedTslintPath)) ? symlinkedTslintPath : "../node_modules/tslint";
const cmd = `node ${tslintPath}/lib/tslint-cli --format stylish **/*.d.ts`;
const cmd = `node ${tslintPath}/lib/tslint-cli --format stylish "**/*.d.ts"`;
console.log(cmd);
try {
+5 -6
View File
@@ -3,7 +3,7 @@
// Definitions by: Michel Salib <https://github.com/michelsalib>, Jason McNeil <https://github.com/jasonrm>, Christopher Currens <https://github.com/ccurrens>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="./processors.d.ts" />
export = xml2js;
@@ -30,8 +30,8 @@ declare namespace xml2js {
interface Options {
async?: boolean;
attrkey?: string;
attrNameProcessors?: [(name: string) => string];
attrValueProcessors?: [(name: string) => string];
attrNameProcessors?: [(name: string) => any];
attrValueProcessors?: [(name: string) => any];
charkey?: string;
charsAsChildren?: boolean;
childkey?: string;
@@ -46,10 +46,10 @@ declare namespace xml2js {
normalize?: boolean;
normalizeTags?: boolean;
strict?: boolean;
tagNameProcessors?: [(name: string) => string];
tagNameProcessors?: [(name: string) => any];
trim?: boolean;
validator?: Function;
valueProcessors?: [(name: string) => string];
valueProcessors?: [(name: string) => any];
xmlns?: boolean;
}
@@ -76,4 +76,3 @@ declare namespace xml2js {
toString(): string;
}
}
+11
View File
@@ -0,0 +1,11 @@
declare module 'xml2js/lib/processors' {
export function firstCharLowerCase(name: string): string;
export function normalize(name: string): string;
export function parseBooleans(name: string): boolean;
export function parseNumbers(name: string): number;
export function stripPrefix(name: string): string;
}
+8
View File
@@ -1,6 +1,7 @@
/// <reference types="node"/>
import xml2js = require('xml2js');
import * as processors from 'xml2js/lib/processors';
xml2js.parseString('<root>Hello xml2js!</root>', (err: any, result: any) => { });
@@ -32,6 +33,13 @@ xml2js.parseString('<root>Hello xml2js!</root>', {
valueProcessors: undefined
}, (err: any, result: any) => { });
xml2js.parseString('<root>Hello xml2js!</root>', {
attrNameProcessors: [processors.firstCharLowerCase],
attrValueProcessors: [processors.normalize],
tagNameProcessors: [processors.stripPrefix],
valueProcessors: [processors.parseBooleans, processors.parseNumbers]
}, (err: any, result: any) => { });
var builder = new xml2js.Builder({
renderOpts: {
pretty: false