mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
Merge branch 'master' of https://github.com/DefinitelyTyped/DefinitelyTyped
This commit is contained in:
Vendored
+4
-4
@@ -262,13 +262,13 @@ declare namespace CodeMirror {
|
||||
Note that the widget node will become a descendant of nodes with CodeMirror-specific CSS classes, and those classes might in some cases affect it. */
|
||||
addLineWidget(line: any, node: HTMLElement, options?: {
|
||||
/** Whether the widget should cover the gutter. */
|
||||
coverGutter: boolean;
|
||||
coverGutter?: boolean;
|
||||
/** Whether the widget should stay fixed in the face of horizontal scrolling. */
|
||||
noHScroll: boolean;
|
||||
noHScroll?: boolean;
|
||||
/** Causes the widget to be placed above instead of below the text of the line. */
|
||||
above: boolean;
|
||||
above?: boolean;
|
||||
/** When true, will cause the widget to be rendered even if the line it is associated with is hidden. */
|
||||
showIfHidden: boolean;
|
||||
showIfHidden?: boolean;
|
||||
}): CodeMirror.LineWidget;
|
||||
|
||||
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/d3/d3-array
|
||||
// Definitions by: Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>, Tom Wanzek <https://github.com/tomwanzek>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 1.2.0
|
||||
|
||||
|
||||
Vendored
+1
@@ -5,6 +5,7 @@
|
||||
// Boris Yankov <https://github.com/borisyankov>
|
||||
// denisname <https://github.com/denisname>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 1.0.8
|
||||
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/d3/d3-brush/
|
||||
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 1.0.3
|
||||
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/d3/d3-chord/
|
||||
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 1.0.3
|
||||
|
||||
|
||||
@@ -12,8 +12,12 @@ import * as d3Hsv from 'd3-hsv';
|
||||
|
||||
// Preparatory steps -------------------------------------------------------------------
|
||||
|
||||
interface Interpolator<T> {
|
||||
(t: number): T;
|
||||
type Interpolator<T> = (t: number) => T;
|
||||
|
||||
interface Xyz {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
}
|
||||
|
||||
class NumCoercible {
|
||||
@@ -39,13 +43,17 @@ class StringCoercible {
|
||||
}
|
||||
}
|
||||
|
||||
let iNull: Interpolator<null>;
|
||||
let iBoolean: Interpolator<boolean>;
|
||||
let iNum: Interpolator<number>;
|
||||
let iString: Interpolator<string>;
|
||||
let iDate: Interpolator<Date>;
|
||||
let iArrayNum: Interpolator<number[]>;
|
||||
let iArrayStr: Interpolator<string[]>;
|
||||
let iArrayMixed: Interpolator<[Date, string]>;
|
||||
let iMix: Interpolator<Date | string>;
|
||||
let iKeyVal: Interpolator<{ [key: string]: any }>;
|
||||
let iXyz: Interpolator<Xyz>;
|
||||
let iRGBColorObj: Interpolator<d3Color.RGBColor>;
|
||||
let iZoom: d3Interpolate.ZoomInterpolator;
|
||||
|
||||
@@ -54,12 +62,20 @@ let str: string;
|
||||
let arrNum: number[];
|
||||
let arrStr: string[];
|
||||
let objKeyVal: { [key: string]: any };
|
||||
let xyz: Xyz;
|
||||
let objRGBColor: d3Color.RGBColor;
|
||||
let zoom: [number, number, number];
|
||||
|
||||
// test interpolate(a, b) signature ----------------------------------------------------
|
||||
|
||||
iNum = d3Interpolate.interpolate('1', 5);
|
||||
// $ExpectError
|
||||
iNum = d3Interpolate.interpolate('1', 5); // fails, https://github.com/Microsoft/TypeScript/issues/4002#issuecomment-124201510
|
||||
|
||||
// null and boolean interpolator
|
||||
iNull = d3Interpolate.interpolate(null, null);
|
||||
iNull = d3Interpolate.interpolate(10, null);
|
||||
iBoolean = d3Interpolate.interpolate(false, true);
|
||||
iBoolean = d3Interpolate.interpolate("10", true);
|
||||
|
||||
// color interpolator returning a color string
|
||||
iString = d3Interpolate.interpolate('seagreen', d3Color.rgb(100, 100, 100));
|
||||
@@ -87,32 +103,34 @@ iNum = d3Interpolate.interpolate(new NumCoercible(2), new NumCoercible(20));
|
||||
// Key Value
|
||||
|
||||
iKeyVal = d3Interpolate.interpolate({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 });
|
||||
iXyz = d3Interpolate.interpolate({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 });
|
||||
iXyz = d3Interpolate.interpolate<Xyz>({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 });
|
||||
|
||||
d3Interpolate.interpolate<NumCoercible>(new NumCoercible(1), new NumCoercible(5));
|
||||
d3Interpolate.interpolate<NumCoercible>({ a: 1 }, new NumCoercible(5));
|
||||
|
||||
// test interpolateNumber(a, b) signature ----------------------------------------------------
|
||||
// test interpolateNumber(a, b) signature ----------------------------------------------
|
||||
|
||||
iNum = d3Interpolate.interpolateNumber(0, 100);
|
||||
iNum = d3Interpolate.interpolateNumber(new NumCoercible(0), new NumCoercible(100));
|
||||
num = iNum(0.5);
|
||||
|
||||
// test interpolateNumber(a, b) signature ----------------------------------------------------
|
||||
// test interpolateNumber(a, b) signature ----------------------------------------------
|
||||
|
||||
iNum = d3Interpolate.interpolateRound(0, 100);
|
||||
iNum = d3Interpolate.interpolateRound(new NumCoercible(0), new NumCoercible(100));
|
||||
num = iNum(0.5);
|
||||
|
||||
// test interpolateString(a, b) signature ----------------------------------------------------
|
||||
// test interpolateString(a, b) signature ----------------------------------------------
|
||||
|
||||
iString = d3Interpolate.interpolateString('-1', '2');
|
||||
str = iString(0.5);
|
||||
|
||||
// test interpolateDate(a, b) signature ----------------------------------------------------
|
||||
// test interpolateDate(a, b) signature ------------------------------------------------
|
||||
|
||||
iDate = d3Interpolate.interpolateDate(new Date(2016, 6, 1), new Date(2016, 6, 31));
|
||||
|
||||
// test interpolateArray(a, b) signature ----------------------------------------------------
|
||||
// test interpolateArray(a, b) signature -----------------------------------------------
|
||||
|
||||
iArrayNum = d3Interpolate.interpolateArray<number[]>([1, 2], [4, 8]); // explicit typing
|
||||
arrNum = iArrayNum(0.5);
|
||||
@@ -129,39 +147,49 @@ arrStr = iArrayStr(0.5);
|
||||
// two element array with first element date and second element string
|
||||
iArrayMixed = d3Interpolate.interpolateArray<[Date, string]>([new Date(2016, 6, 1), 'b: 1'], [new Date(2016, 6, 31), 'b: 8']);
|
||||
|
||||
// test interpolateObject(a, b) signature ----------------------------------------------------
|
||||
// test interpolateObject(a, b) signature ----------------------------------------------
|
||||
|
||||
iKeyVal = d3Interpolate.interpolateObject({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 });
|
||||
objKeyVal = iKeyVal(0.5);
|
||||
|
||||
iXyz = d3Interpolate.interpolateObject({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 });
|
||||
iXyz = d3Interpolate.interpolateObject<Xyz>({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 });
|
||||
xyz = iXyz(0.5);
|
||||
|
||||
iRGBColorObj = d3Interpolate.interpolateObject<d3Color.RGBColor>(d3Color.rgb('steelblue'), d3Color.rgb('seagreen'));
|
||||
objRGBColor = iRGBColorObj(0.5);
|
||||
|
||||
// test interpolateTransformCss(a, b) signature ----------------------------------------------------
|
||||
// test interpolateTransformCss(a, b) signature ----------------------------------------
|
||||
|
||||
iString = d3Interpolate.interpolateTransformCss('rotate(0deg)', 'rotate(60deg)');
|
||||
str = iString(0.5);
|
||||
|
||||
// test interpolateTransformSvg(a, b) signature ----------------------------------------------------
|
||||
// test interpolateTransformSvg(a, b) signature ----------------------------------------
|
||||
|
||||
iString = d3Interpolate.interpolateTransformSvg('rotate(0)', 'rotate(60)');
|
||||
str = iString(0.5);
|
||||
|
||||
// test interpolateZoom(a, b) signature ----------------------------------------------------
|
||||
// test interpolateZoom(a, b) signature ------------------------------------------------
|
||||
|
||||
iZoom = d3Interpolate.interpolateZoom([50, 50, 300], [100, 100, 500]);
|
||||
zoom = iZoom(0.5);
|
||||
|
||||
num = iZoom.duration;
|
||||
console.log('Recommended transition duration = %d', iZoom.duration);
|
||||
|
||||
// test quantize(interpolator, n) signature ------------------------------------------------
|
||||
// test interpolateDiscrete(a, b) signature --------------------------------------------
|
||||
|
||||
iNum = d3Interpolate.interpolateDiscrete([1, 2, 3]);
|
||||
iMix = d3Interpolate.interpolateDiscrete([new Date(2016, 6, 1), 'b: 2']);
|
||||
|
||||
// test quantize(interpolator, n) signature --------------------------------------------
|
||||
|
||||
arrNum = d3Interpolate.quantize(d3Interpolate.interpolateRound(-1, 2), 4); // inferred template parameter type
|
||||
arrStr = d3Interpolate.quantize<string>(d3Interpolate.interpolateString('-1', '2'), 4); // explicit template parameter typing
|
||||
// $ExpectError
|
||||
arrStr = d3Interpolate.quantize<string>(d3Interpolate.interpolateRound(-1, 2), 4); // fails, due to explicit typing v argument type mismatch
|
||||
|
||||
// arrStr = d3Interpolate.quantize<string>(d3Interpolate.interpolateRound(-1, 2), 4); // test fails, due to explicit typing v argument type mismatch
|
||||
|
||||
// test interpolateRgb(a, b) signatures ----------------------------------------------------------------
|
||||
// test interpolateRgb(a, b) signatures ------------------------------------------------
|
||||
|
||||
// without gamma correction
|
||||
iString = d3Interpolate.interpolateRgb('seagreen', 'steelblue');
|
||||
@@ -172,13 +200,13 @@ str = iString(0.5);
|
||||
// with gamma correction
|
||||
iString = d3Interpolate.interpolateRgb.gamma(2.2)('purple', 'orange');
|
||||
|
||||
// test interpolateRgbBasis(color) and interpolateRgbBasisClosed(color) signatures -------------------------
|
||||
// test interpolateRgbBasis(color) and interpolateRgbBasisClosed(color) signatures ----
|
||||
|
||||
iString = d3Interpolate.interpolateRgbBasis(['seagreen', d3Color.rgb('steelblue'), 'rgb(100, 100, 100)']);
|
||||
iString = d3Interpolate.interpolateRgbBasis(['seagreen', d3Hsv.hsv('steelblue'), 'rgb(100, 100, 100)']);
|
||||
iString = d3Interpolate.interpolateRgbBasisClosed(['seagreen', d3Hsv.hsv('steelblue'), 'rgb(100, 100, 100)']);
|
||||
|
||||
// test interpolateHsl(a, b) and interpolateHslLong(a, b)----------------------------------------------------------------
|
||||
// test interpolateHsl(a, b) and interpolateHslLong(a, b)-------------------------------
|
||||
|
||||
iString = d3Interpolate.interpolateHsl('seagreen', 'steelblue');
|
||||
iString = d3Interpolate.interpolateHsl(d3Color.rgb('seagreen'), d3Color.hcl('steelblue'));
|
||||
@@ -188,13 +216,13 @@ iString = d3Interpolate.interpolateHslLong('seagreen', 'steelblue');
|
||||
iString = d3Interpolate.interpolateHslLong(d3Color.rgb('seagreen'), d3Color.hcl('steelblue'));
|
||||
iString = d3Interpolate.interpolateHslLong(d3Color.rgb('seagreen'), d3Hsv.hsv('steelblue'));
|
||||
|
||||
// test interpolateLab(a, b) --------------------------------------------------------------------------------------------
|
||||
// test interpolateLab(a, b) -----------------------------------------------------------
|
||||
|
||||
iString = d3Interpolate.interpolateLab('seagreen', 'steelblue');
|
||||
iString = d3Interpolate.interpolateLab(d3Color.rgb('seagreen'), d3Color.hcl('steelblue'));
|
||||
iString = d3Interpolate.interpolateLab(d3Color.rgb('seagreen'), d3Hsv.hsv('steelblue'));
|
||||
|
||||
// test interpolateHcl(a, b) and interpolateHclLong(a, b) ----------------------------------------------------------------
|
||||
// test interpolateHcl(a, b) and interpolateHclLong(a, b) ------------------------------
|
||||
|
||||
iString = d3Interpolate.interpolateHcl('seagreen', 'steelblue');
|
||||
iString = d3Interpolate.interpolateHcl(d3Color.rgb('seagreen'), d3Color.hcl('steelblue'));
|
||||
@@ -204,7 +232,7 @@ iString = d3Interpolate.interpolateHclLong('seagreen', 'steelblue');
|
||||
iString = d3Interpolate.interpolateHclLong(d3Color.rgb('seagreen'), d3Color.hcl('steelblue'));
|
||||
iString = d3Interpolate.interpolateHclLong(d3Color.rgb('seagreen'), d3Hsv.hsv('steelblue'));
|
||||
|
||||
// test interpolateCubehelix(a, b) and interpolateCubehelixLong(a, b) ---------------------------------------------------
|
||||
// test interpolateCubehelix(a, b) and interpolateCubehelixLong(a, b) ------------------
|
||||
|
||||
// without gamma correction
|
||||
iString = d3Interpolate.interpolateCubehelix('seagreen', 'steelblue');
|
||||
@@ -224,21 +252,29 @@ str = iString(0.5);
|
||||
// with gamma correction
|
||||
iString = d3Interpolate.interpolateCubehelixLong.gamma(2.2)('purple', 'orange');
|
||||
|
||||
// test interpolateBasis(splineNodes) and interpolateBasisClosed(splineNodes: number[]) ----------------------------
|
||||
// test interpolateBasis(splineNodes) and interpolateBasisClosed(splineNodes) ----------
|
||||
|
||||
iNum = d3Interpolate.interpolateBasis([1, 50, 30, 10]);
|
||||
|
||||
iNum = d3Interpolate.interpolateBasisClosed([1, 50, 30, 10]);
|
||||
|
||||
// test interpolateHue -----------------------------------------------------------------
|
||||
|
||||
iNum = d3Interpolate.interpolateHue(30, 90);
|
||||
|
||||
// test piecewise ----------------------------------------------------------------------
|
||||
|
||||
iZoom = d3Interpolate.piecewise(d3Interpolate.interpolateZoom, [[50, 50, 300], [100, 100, 500]]);
|
||||
|
||||
iString = d3Interpolate.piecewise(d3Interpolate.interpolateRgb.gamma(2.2), ['red', 'green', 'blue']);
|
||||
iString = d3Interpolate.piecewise(d3Interpolate.interpolateCubehelix, ['red', 'green', 'blue']);
|
||||
iZoom = d3Interpolate.piecewise(d3Interpolate.interpolateZoom, [[50, 50, 300], [100, 100, 500]]);
|
||||
iNum = d3Interpolate.piecewise(d3Interpolate.interpolateNumber, [1, 2, 3]);
|
||||
iNum = d3Interpolate.piecewise(d3Interpolate.interpolateRound, [1.1, 2.2, 3.3]);
|
||||
iString = d3Interpolate.piecewise(d3Interpolate.interpolateString, ['a', 'b', 'c']);
|
||||
iString = d3Interpolate.piecewise(d3Interpolate.interpolateString, ['2px', '3px', '5px']);
|
||||
iDate = d3Interpolate.piecewise(d3Interpolate.interpolateDate, [new Date(2018, 5, 1), new Date(2018, 5, 2), new Date(2018, 5, 3)]);
|
||||
iArrayNum = d3Interpolate.piecewise<number[]>(d3Interpolate.interpolateArray, [1, 2, 4, 8]);
|
||||
iArrayStr = d3Interpolate.piecewise<string[]>(d3Interpolate.interpolateArray, ['a', 'b', 'c', 'd']);
|
||||
iArrayMixed = d3Interpolate.piecewise<[Date, string]>(d3Interpolate.interpolateArray, [new Date(2016, 6, 1), 'b: 1']);
|
||||
iString = d3Interpolate.piecewise(d3Interpolate.interpolateTransformCss, ['rotate(0deg)', 'rotate(60deg)']);
|
||||
iString = d3Interpolate.piecewise(d3Interpolate.interpolateTransformSvg, ['rotate(0)', 'rotate(60)']);
|
||||
|
||||
iArrayNum = d3Interpolate.piecewise<number[]>(d3Interpolate.interpolateArray, [[1, 2], [4, 8]]);
|
||||
iArrayStr = d3Interpolate.piecewise<string[]>(d3Interpolate.interpolateArray, [['2px', '1em'], ['3px', '1.2em']]);
|
||||
iArrayMixed = d3Interpolate.piecewise<[Date, string]>(d3Interpolate.interpolateArray, [[new Date(2016, 6, 1), 'b: 1']]);
|
||||
|
||||
Vendored
+241
-24
@@ -1,97 +1,314 @@
|
||||
// Type definitions for D3JS d3-interpolate module 1.2
|
||||
// Type definitions for D3JS d3-interpolate module 1.3
|
||||
// Project: https://github.com/d3/d3-interpolate/
|
||||
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
|
||||
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>
|
||||
// Alex Ford <https://github.com/gustavderdrache>
|
||||
// Boris Yankov <https://github.com/borisyankov>
|
||||
// denisname <https://github.com/denisname>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 1.2.0
|
||||
// Last module patch version validated against: 1.3.2
|
||||
|
||||
import { ColorCommonInstance } from 'd3-color';
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// Shared Type Definitions and Interfaces
|
||||
// --------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export interface ZoomInterpolator extends Function {
|
||||
(t: number): ZoomView;
|
||||
/**
|
||||
* Recommended duration of zoom transition in ms
|
||||
* Recommended duration of zoom transition in milliseconds.
|
||||
*/
|
||||
duration: number;
|
||||
}
|
||||
|
||||
export interface ColorGammaInterpolationFactory extends Function {
|
||||
(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string);
|
||||
/**
|
||||
* Returns a new interpolator factory of the same type using the specified *gamma*.
|
||||
* For example, to interpolate from purple to orange with a gamma of 2.2 in RGB space: `d3.interpolateRgb.gamma(2.2)("purple", "orange")`.
|
||||
* See Eric Brasseur’s article, [Gamma error in picture scaling](https://web.archive.org/web/20160112115812/http://www.4p8.com/eric.brasseur/gamma.html), for more on gamma correction.
|
||||
*/
|
||||
gamma(g: number): ColorGammaInterpolationFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type zoomView is used to represent a numeric array with three elements.
|
||||
* In order of appearance the elements correspond to:
|
||||
* - cx: x-coordinate of the center of the viewport
|
||||
* - cy: y-coordinate of the center of the viewport
|
||||
* - cx: *x*-coordinate of the center of the viewport
|
||||
* - cy: *y*-coordinate of the center of the viewport
|
||||
* - width: size of the viewport
|
||||
*/
|
||||
export type ZoomView = [number, number, number];
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// Interpolation Function Factories
|
||||
// --------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an `null` constant interpolator.
|
||||
*/
|
||||
export function interpolate(a: any, b: null): ((t: number) => null);
|
||||
export function interpolate(a: number | { valueOf(): number }, b: number): ((t: number) => number);
|
||||
export function interpolate(a: any, b: ColorCommonInstance): ((t: number) => string);
|
||||
export function interpolate(a: Date, b: Date): ((t: number) => Date);
|
||||
export function interpolate(a: string | { toString(): string }, b: string): ((t: number) => string);
|
||||
export function interpolate<U extends any[]>(a: any[], b: U): ((t: number) => U);
|
||||
export function interpolate(a: number | { valueOf(): number }, b: { valueOf(): number }): ((t: number) => number);
|
||||
export function interpolate<U extends any>(a: any, b: U): ((t: number) => U); // TODO: extends 'any' should become 'object' with TS 2.2+ definitions
|
||||
export function interpolate(a: any, b: { [key: string]: any }): ((t: number) => { [key: string]: any });
|
||||
|
||||
/**
|
||||
* Returns an boolean constant interpolator of value `b`.
|
||||
*/
|
||||
export function interpolate(a: any, b: boolean): ((t: number) => boolean);
|
||||
|
||||
/**
|
||||
* Returns a `interpolateNumber` interpolator.
|
||||
*/
|
||||
export function interpolate(a: number | { valueOf(): number }, b: number): ((t: number) => number);
|
||||
|
||||
/**
|
||||
* Returns a `interpolateRgb` interpolator.
|
||||
*/
|
||||
export function interpolate(a: string | ColorCommonInstance, b: ColorCommonInstance): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Returns a `interpolateDate` interpolator.
|
||||
*/
|
||||
export function interpolate(a: Date, b: Date): ((t: number) => Date);
|
||||
|
||||
/**
|
||||
* Returns a `interpolateString` interpolator. If `b` is a string coercible to a color use use `interpolateRgb`.
|
||||
*/
|
||||
export function interpolate(a: string | { toString(): string }, b: string): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Returns a `interpolateArray` interpolator.
|
||||
*/
|
||||
export function interpolate<U extends any[]>(a: any[], b: U): ((t: number) => U);
|
||||
|
||||
/**
|
||||
* Returns a `interpolateNumber` interpolator.
|
||||
*/
|
||||
export function interpolate(a: number | { valueOf(): number }, b: { valueOf(): number }): ((t: number) => number);
|
||||
|
||||
/**
|
||||
* Returns a `interpolateObject` interpolator.
|
||||
*/
|
||||
export function interpolate<U extends object>(a: any, b: U): ((t: number) => U);
|
||||
|
||||
/**
|
||||
* Returns an interpolator between the two numbers `a` and `b`.
|
||||
* The returned interpolator is equivalent to: `(t) => a * (1 - t) + b * t`.
|
||||
*/
|
||||
export function interpolateNumber(a: number | { valueOf(): number }, b: number | { valueOf(): number }): ((t: number) => number);
|
||||
|
||||
/**
|
||||
* Returns an interpolator between the two numbers `a` and `b`; the interpolator is similar to `interpolateNumber`,
|
||||
* except it will round the resulting value to the nearest integer.
|
||||
*/
|
||||
export function interpolateRound(a: number | { valueOf(): number }, b: number | { valueOf(): number }): ((t: number) => number);
|
||||
|
||||
/**
|
||||
* Returns an interpolator between the two strings `a` and `b`.
|
||||
* The string interpolator finds numbers embedded in `a` and `b`, where each number is of the form understood by JavaScript.
|
||||
* A few examples of numbers that will be detected within a string: `-1`, `42`, `3.14159`, and `6.0221413e+23`.
|
||||
*
|
||||
* For each number embedded in `b`, the interpolator will attempt to find a corresponding number in `a`.
|
||||
* If a corresponding number is found, a numeric interpolator is created using `interpolateNumber`.
|
||||
* The remaining parts of the string `b` are used as a template.
|
||||
*
|
||||
* For example, if `a` is `"300 12px sans-serif"`, and `b` is `"500 36px Comic-Sans"`, two embedded numbers are found.
|
||||
* The remaining static parts (of string `b`) are a space between the two numbers (`" "`), and the suffix (`"px Comic-Sans"`).
|
||||
* The result of the interpolator at `t` = 0.5 is `"400 24px Comic-Sans"`.
|
||||
*/
|
||||
export function interpolateString(a: string | { toString(): string }, b: string | { toString(): string }): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Returns an interpolator between the two dates `a` and `b`.
|
||||
*
|
||||
* Note: *no defensive copy* of the returned date is created; the same Date instance is returned for every evaluation of the interpolator.
|
||||
* No copy is made for performance reasons; interpolators are often part of the inner loop of animated transitions.
|
||||
*/
|
||||
export function interpolateDate(a: Date, b: Date): ((t: number) => Date);
|
||||
|
||||
export type ArrayInterpolator<A extends any[]> = ((t: number) => A);
|
||||
|
||||
/**
|
||||
* Returns an interpolator between the two arrays `a` and `b`. Internally, an array template is created that is the same length in `b`.
|
||||
* For each element in `b`, if there exists a corresponding element in `a`, a generic interpolator is created for the two elements using `interpolate`.
|
||||
* If there is no such element, the static value from `b` is used in the template.
|
||||
* Then, for the given parameter `t`, the template’s embedded interpolators are evaluated. The updated array template is then returned.
|
||||
*
|
||||
* For example, if `a` is the array `[0, 1]` and `b` is the array `[1, 10, 100]`, then the result of the interpolator for `t = 0.5` is the array `[0.5, 5.5, 100]`.
|
||||
*
|
||||
* Note: *no defensive copy* of the template array is created; modifications of the returned array may adversely affect subsequent evaluation of the interpolator.
|
||||
* No copy is made for performance reasons; interpolators are often part of the inner loop of animated transitions.
|
||||
*/
|
||||
export function interpolateArray<A extends any[]>(a: any[], b: A): ArrayInterpolator<A>;
|
||||
|
||||
export function interpolateObject<U extends any>(a: any, b: U): ((t: number) => U); // TODO: extends 'any' should become 'object' with TS 2.2+ definitions
|
||||
export function interpolateObject(a: { [key: string]: any }, b: { [key: string]: any }): ((t: number) => { [key: string]: any });
|
||||
/**
|
||||
* Returns an interpolator between the two objects `a` and `b`. Internally, an object template is created that has the same properties as `b`.
|
||||
* For each property in `b`, if there exists a corresponding property in `a`, a generic interpolator is created for the two elements using `interpolate`.
|
||||
* If there is no such property, the static value from `b` is used in the template.
|
||||
* Then, for the given parameter `t`, the template's embedded interpolators are evaluated and the updated object template is then returned.
|
||||
*
|
||||
* For example, if `a` is the object `{x: 0, y: 1}` and `b` is the object `{x: 1, y: 10, z: 100}`, the result of the interpolator for `t = 0.5` is the object `{x: 0.5, y: 5.5, z: 100}`.
|
||||
*
|
||||
* Note: *no defensive copy* of the template object is created; modifications of the returned object may adversely affect subsequent evaluation of the interpolator.
|
||||
* No copy is made for performance reasons; interpolators are often part of the inner loop of animated transitions.
|
||||
*/
|
||||
export function interpolateObject<U extends object>(a: any, b: U): ((t: number) => U);
|
||||
|
||||
/**
|
||||
* Returns an interpolator between the two 2D CSS transforms represented by `a` and `b`.
|
||||
* Each transform is decomposed to a standard representation of translate, rotate, *x*-skew and scale; these component transformations are then interpolated.
|
||||
* This behavior is standardized by CSS: see [matrix decomposition for animation](http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition).
|
||||
*/
|
||||
export function interpolateTransformCss(a: string, b: string): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Returns an interpolator between the two 2D SVG transforms represented by `a` and `b`.
|
||||
* Each transform is decomposed to a standard representation of translate, rotate, *x*-skew and scale; these component transformations are then interpolated.
|
||||
* This behavior is standardized by CSS: see [matrix decomposition for animation](http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition).
|
||||
*/
|
||||
export function interpolateTransformSvg(a: string, b: string): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Create Interpolator for zoom views
|
||||
* Returns an interpolator between the two views `a` and `b` of a two-dimensional plane,
|
||||
* based on [“Smooth and efficient zooming and panning”](http://www.win.tue.nl/~vanwijk/zoompan.pdf).
|
||||
* Each view is defined as an array of three numbers: *cx*, *cy* and *width*.
|
||||
* The first two coordinates *cx*, *cy* represent the center of the viewport; the last coordinate *width* represents the size of the viewport.
|
||||
*
|
||||
* The returned interpolator exposes a *duration* property which encodes the recommended transition duration in milliseconds.
|
||||
* This duration is based on the path length of the curved trajectory through *x,y* space.
|
||||
* If you want to a slower or faster transition, multiply this by an arbitrary scale factor (*V* as described in the original paper).
|
||||
*/
|
||||
export function interpolateZoom(a: ZoomView, b: ZoomView): ZoomInterpolator;
|
||||
|
||||
/**
|
||||
* Returns a discrete interpolator for the given array of values. The returned interpolator maps `t` in `[0, 1 / n)` to values[0],
|
||||
* `t` in `[1 / n, 2 / n)` to `values[1]`, and so on, where `n = values.length`. In effect, this is a lightweight quantize scale with a fixed domain of [0, 1].
|
||||
*/
|
||||
export function interpolateDiscrete<T>(values: T[]): ((t: number) => T);
|
||||
|
||||
// Sampling ------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns `n` uniformly-spaced samples from the specified `interpolator`, where `n` is an integer greater than one.
|
||||
* The first sample is always at `t = 0`, and the last sample is always at `t = 1`.
|
||||
* This can be useful in generating a fixed number of samples from a given interpolator,
|
||||
* such as to derive the range of a [quantize scale](https://github.com/d3/d3-scale#quantize-scales) from a [continuous interpolator](https://github.com/d3/d3-scale#interpolateWarm).
|
||||
*
|
||||
* Caution: this method will not work with interpolators that do not return defensive copies of their output,
|
||||
* such as `d3.interpolateArray`, `d3.interpolateDate` and `d3.interpolateObject`. For those interpolators, you must wrap the interpolator and create a copy for each returned value.
|
||||
*/
|
||||
export function quantize<T>(interpolator: ((t: number) => T), n: number): T[];
|
||||
|
||||
// Color interpolation related
|
||||
// Color Spaces
|
||||
|
||||
/**
|
||||
* Returns an RGB color space interpolator between the two colors `a` and `b` with a configurable gamma. If the gamma is not specified, it defaults to 1.0.
|
||||
* The colors `a` and `b` need not be in RGB; they will be converted to RGB using [`d3.rgb`](https://github.com/d3/d3-color#rgb). The return value of the interpolator is an RGB string.
|
||||
*/
|
||||
export const interpolateRgb: ColorGammaInterpolationFactory;
|
||||
|
||||
/**
|
||||
* Returns a uniform nonrational B-spline interpolator through the specified array of *colors*, which are converted to RGB color space.
|
||||
* Implicit control points are generated such that the interpolator returns `colors[0]` at `t = 0` and `colors[colors.length - 1]` at `t = 1`.
|
||||
* Opacity interpolation is not currently supported. See also `d3.interpolateBasis`, and see [d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic) for examples.
|
||||
*/
|
||||
export function interpolateRgbBasis(colors: Array<string | ColorCommonInstance>): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Returns a uniform nonrational B-spline interpolator through the specified array of colors, which are converted to RGB color space.
|
||||
* The control points are implicitly repeated such that the resulting spline has cyclical C² continuity when repeated around `t` in [0,1];
|
||||
* this is useful, for example, to create cyclical color scales. Opacity interpolation is not currently supported.
|
||||
* See also `d3.interpolateBasisClosed, and see [d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic) for examples.
|
||||
*/
|
||||
export function interpolateRgbBasisClosed(colors: Array<string | ColorCommonInstance>): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Returns an HSL color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in HSL;
|
||||
* they will be converted to HSL using `d3.hsl`. If either color’s hue or saturation is NaN, the opposing color’s channel value is used.
|
||||
* The shortest path between hues is used. The return value of the interpolator is an RGB string.
|
||||
*/
|
||||
export function interpolateHsl(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Like `interpolateHsl`, but does not use the shortest path between hues.
|
||||
*/
|
||||
export function interpolateHslLong(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Returns a Lab color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in Lab;
|
||||
* they will be converted to Lab using `d3.lab`. The return value of the interpolator is an RGB string.
|
||||
*/
|
||||
export function interpolateLab(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Returns an HCL color space interpolator between the two colors `a` and `b`. The colors `a` and `b` need not be in HCL;
|
||||
* they will be converted to HCL using `d3.hcl`. If either color’s hue or chroma is NaN, the opposing color’s channel value is used.
|
||||
* The shortest path between hues is used. The return value of the interpolator is an RGB string.
|
||||
*/
|
||||
export function interpolateHcl(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Like `interpolateHcl`, but does not use the shortest path between hues.
|
||||
*/
|
||||
export function interpolateHclLong(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string);
|
||||
|
||||
/**
|
||||
* Returns a Cubehelix color space interpolator between the two colors `a` and `b` using a configurable `gamma`.
|
||||
* If the gamma is not specified, it defaults to 1.0. The colors `a` and `b` need not be in Cubehelix;
|
||||
* they will be converted to Cubehelix using [`d3.cubehelix`](https://github.com/d3/d3-color#cubehelix).
|
||||
* If either color’s hue or saturation is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is an RGB string.
|
||||
*/
|
||||
export const interpolateCubehelix: ColorGammaInterpolationFactory;
|
||||
|
||||
/**
|
||||
* Like `interpolateCubehelix`, but does not use the shortest path between hues.
|
||||
*/
|
||||
export const interpolateCubehelixLong: ColorGammaInterpolationFactory;
|
||||
|
||||
// Spline related
|
||||
/**
|
||||
* Returns an interpolator between the two hue angles `a` and `b`. If either hue is NaN, the opposing value is used.
|
||||
* The shortest path between hues is used. The return value of the interpolator is a number in `[0, 360)`.
|
||||
*/
|
||||
export function interpolateHue(a: number, b: number): ((t: number) => number);
|
||||
|
||||
// Splines -------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a uniform nonrational B-spline interpolator through the specified array of `values`, which must be numbers.
|
||||
* Implicit control points are generated such that the interpolator returns `values[0]` at `t` = 0 and `values[values.length - 1]` at `t` = 1.
|
||||
* See also [`d3.curveBasis`](https://github.com/d3/d3-shape#curveBasis).
|
||||
*/
|
||||
export function interpolateBasis(splineNodes: number[]): ((t: number) => number);
|
||||
|
||||
/**
|
||||
* Returns a uniform nonrational B-spline interpolator through the specified array of `values`, which must be numbers.
|
||||
* The control points are implicitly repeated such that the resulting one-dimensional spline has cyclical C² continuity when repeated around `t` in [0,1].
|
||||
* See also [`d3.curveBasisClosed`](https://github.com/d3/d3-shape#curveBasisClosed).
|
||||
*/
|
||||
export function interpolateBasisClosed(splineNodes: number[]): ((t: number) => number);
|
||||
|
||||
// Piecewise -----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a piecewise zoom interpolator, composing zoom interpolators for each adjacent pair of zoom view.
|
||||
* The returned interpolator maps `t` in `[0, 1 / (n - 1)]` to `interpolate(values[0], values[1])`, `t` in `[1 / (n - 1), 2 / (n - 1)]` to `interpolate(values[1], values[2])`,
|
||||
* and so on, where `n = values.length`. In effect, this is a lightweight linear scale.
|
||||
* For example, to blend through three different zoom views: `d3.piecewise(d3.interpolateZoom, [[0, 0, 1], [0, 0, 10], [0, 0, 15]])`.
|
||||
*/
|
||||
export function piecewise(interpolate: (a: ZoomView, b: ZoomView) => ZoomInterpolator, values: ZoomView[]): ZoomInterpolator;
|
||||
export function piecewise<A extends any[]>(interpolate: (a: any[], b: A) => ArrayInterpolator<A>, values: A): ArrayInterpolator<A>;
|
||||
|
||||
/**
|
||||
* Returns a piecewise array interpolator, composing array interpolators for each adjacent pair of arrays.
|
||||
* The returned interpolator maps `t` in `[0, 1 / (n - 1)]` to `interpolate(values[0], values[1])`, `t` in `[1 / (n - 1), 2 / (n - 1)]` to `interpolate(values[1], values[2])`,
|
||||
* and so on, where `n = values.length`. In effect, this is a lightweight linear scale.
|
||||
* For example, to blend through three different arrays: `d3.piecewise(d3.interpolateArray, [[0, 0, 1], [0, 0, 10], [0, 0, 15]])`.
|
||||
*/
|
||||
export function piecewise<A extends any[]>(interpolate: (a: any[], b: A) => ArrayInterpolator<A>, values: A[]): ArrayInterpolator<A>;
|
||||
|
||||
/**
|
||||
* Returns a piecewise interpolator, composing interpolators for each adjacent pair of values.
|
||||
* The returned interpolator maps `t` in `[0, 1 / (n - 1)]` to `interpolate(values[0], values[1])`, `t` in `[1 / (n - 1), 2 / (n - 1)]` to `interpolate(values[1], values[2])`,
|
||||
* and so on, where `n = values.length`. In effect, this is a lightweight linear scale.
|
||||
* For example, to blend through red, green and blue: `d3.piecewise(d3.interpolateRgb.gamma(2.2), ["red", "green", "blue"])`.
|
||||
*/
|
||||
export function piecewise<TData, Interpolator>(interpolate: (a: TData, b: TData) => Interpolator, values: TData[]): (t: number) => any;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"unified-signatures": false,
|
||||
"callable-types": false,
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/d3/d3-scale/
|
||||
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 2.0.0
|
||||
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/d3/d3-scale/
|
||||
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 1.0.7
|
||||
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/d3/d3-selection-multi/
|
||||
// Definitions by: Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 1.0.0
|
||||
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/d3/d3-transition/
|
||||
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 1.1
|
||||
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/d3/d3-zoom/
|
||||
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
// Last module patch version validated against: 1.7.0
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/application 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fapplication
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/array 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Farray
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/component 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fcomponent
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/controller 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fcontroller
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/debug 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fdebug
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/engine 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fengine
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/error 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Ferror
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/object 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fobject
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/polyfills 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fpolyfills
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/routing 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Frouting
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/runloop 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Frunloop
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/service 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fservice
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/string 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fstring
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
// Type definitions for @ember/test 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Ftest
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
@@ -1,34 +1,35 @@
|
||||
import { IncomingMessage, Server, ServerResponse } from "http";
|
||||
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify-jwt";
|
||||
import fastifyJwt = require("fastify-jwt");
|
||||
import fastify = require("fastify");
|
||||
|
||||
const fastify: FastifyInstance<Server, IncomingMessage, ServerResponse> = {
|
||||
jwt: {
|
||||
decode: (token, options) => {
|
||||
return token;
|
||||
},
|
||||
secret: "some-string",
|
||||
sign: (payload, options) => {
|
||||
return JSON.stringify(payload);
|
||||
},
|
||||
verify: (token, options) => {
|
||||
return token;
|
||||
},
|
||||
},
|
||||
};
|
||||
const app = fastify();
|
||||
|
||||
const req: FastifyRequest<IncomingMessage> = {
|
||||
jwtVerify: (_options) => {
|
||||
return req;
|
||||
},
|
||||
};
|
||||
app.register<fastifyJwt.FastifyJwtOptions>(fastifyJwt, {
|
||||
secret: "super-secret"
|
||||
});
|
||||
|
||||
const res: FastifyReply<ServerResponse> = {
|
||||
jwtSign: (_payload, _options, _next) => {
|
||||
return res;
|
||||
},
|
||||
};
|
||||
app.register<fastifyJwt.FastifyJwtOptions>(fastifyJwt, {
|
||||
secret: (request, reply, callback) => {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
fastify.jwt.sign({ a: "b" }, {}, (err, token) => {
|
||||
app.get("/path", (request, reply) => {
|
||||
request.jwtVerify();
|
||||
request.jwtVerify({});
|
||||
request.jwtVerify({}, () => "string");
|
||||
request.jwtVerify(() => "string", () => "string");
|
||||
|
||||
reply.jwtSign("payload");
|
||||
reply.jwtSign("payload", {});
|
||||
reply.jwtSign("payload", {}, () => "string");
|
||||
reply.jwtSign({ a: "b" }, {}, () => "string");
|
||||
reply.jwtSign([], {}, () => "string");
|
||||
reply.jwtSign(new Buffer("buffer"), {}, () => "string");
|
||||
reply.jwtSign("payload", () => "string", () => "string");
|
||||
});
|
||||
|
||||
app.jwt.sign({ a: "b" }, {}, (err, token) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
@@ -36,7 +37,7 @@ fastify.jwt.sign({ a: "b" }, {}, (err, token) => {
|
||||
return token;
|
||||
});
|
||||
|
||||
fastify.jwt.sign("string", { algorithm: "some-algorithm" }, (err, token) => {
|
||||
app.jwt.sign("string", { algorithm: "some-algorithm" }, (err, token) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
@@ -44,7 +45,7 @@ fastify.jwt.sign("string", { algorithm: "some-algorithm" }, (err, token) => {
|
||||
return token;
|
||||
});
|
||||
|
||||
fastify.jwt.sign([], {}, (err, token) => {
|
||||
app.jwt.sign([], {}, (err, token) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
@@ -52,7 +53,7 @@ fastify.jwt.sign([], {}, (err, token) => {
|
||||
return token;
|
||||
});
|
||||
|
||||
fastify.jwt.sign(9999, {}, (err, token) => {
|
||||
app.jwt.sign(new Buffer("buffer"), {}, (err, token) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
@@ -60,26 +61,13 @@ fastify.jwt.sign(9999, {}, (err, token) => {
|
||||
return token;
|
||||
});
|
||||
|
||||
fastify.jwt.decode("some-token");
|
||||
fastify.jwt.decode("some-token");
|
||||
fastify.jwt.secret = "some-secret";
|
||||
fastify.jwt.verify("some-token", {}, (err) => {
|
||||
app.jwt.decode("some-token");
|
||||
app.jwt.decode("some-token");
|
||||
app.jwt.secret = "some-secret";
|
||||
app.jwt.verify("some-token", {}, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
req.jwtVerify();
|
||||
req.jwtVerify({});
|
||||
req.jwtVerify({}, () => "string");
|
||||
req.jwtVerify(() => "string", () => "string");
|
||||
|
||||
res.jwtSign("payload");
|
||||
res.jwtSign("payload", {});
|
||||
res.jwtSign("payload", {}, () => "string");
|
||||
res.jwtSign({ a: "b" }, {}, () => "string");
|
||||
res.jwtSign([], {}, () => "string");
|
||||
res.jwtSign(9999, {}, () => "string");
|
||||
res.jwtSign("payload", () => "string", () => "string");
|
||||
|
||||
Vendored
+42
-16
@@ -1,26 +1,52 @@
|
||||
// Type definitions for fastify-jwt 0.4
|
||||
// Project: https://github.com/fastify/fastify-jwt#readme
|
||||
// Definitions by: My Self <https://github.com/jannikkeye>
|
||||
// Definitions by: Jannik Keye <https://github.com/jannikkeye>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
// TypeScript Version: 2.4
|
||||
import fastify = require("fastify");
|
||||
|
||||
import { Secret, SignOptions, VerifyOptions, VerifyCallback, SignCallback, DecodeOptions } from 'jsonwebtoken';
|
||||
import { IncomingMessage, ServerResponse } from 'http';
|
||||
|
||||
export interface FastifyInstance<HttpServer, HttpRequest, HttpResponse> {
|
||||
jwt: jwt;
|
||||
declare module "fastify" {
|
||||
interface FastifyInstance<HttpServer, HttpRequest, HttpResponse> {
|
||||
jwt: jwt;
|
||||
}
|
||||
|
||||
interface SignFunction {
|
||||
(payload: string | Buffer | object, options?: SignOptions): string;
|
||||
(payload: string | Buffer | object, options?: SignOptions, callback?: SignCallback): void;
|
||||
}
|
||||
|
||||
interface VerifyFunction {
|
||||
(token: string, options?: VerifyOptions, callback?: VerifyCallback): void;
|
||||
(token: string, options?: VerifyOptions): object | string;
|
||||
}
|
||||
|
||||
interface jwt {
|
||||
sign: SignFunction;
|
||||
verify: VerifyFunction;
|
||||
decode(token: string, options?: DecodeOptions): null | { [key: string]: any } | string;
|
||||
secret: Secret;
|
||||
}
|
||||
|
||||
interface FastifyRequest<HttpRequest> {
|
||||
jwtVerify: (options?: VerifyOptions | VerifyCallback, next?: VerifyCallback) => Promise<null | { [key: string]: any } | string> | null | { [key: string]: any } | string;
|
||||
}
|
||||
|
||||
interface FastifyReply<HttpResponse> {
|
||||
jwtSign: (payload: string | Buffer | object, options?: SignOptions | SignCallback, next?: SignCallback) => void;
|
||||
}
|
||||
}
|
||||
|
||||
export interface jwt {
|
||||
sign: (payload: any, options?: SignOptions, callback?: SignCallback) => void;
|
||||
verify: (token: string, options?: VerifyOptions, callback?: VerifyCallback) => void;
|
||||
decode: (token: string, options?: DecodeOptions) => null | { [key: string]: any } | string;
|
||||
secret: Secret;
|
||||
declare function fastifyJwt(): void;
|
||||
|
||||
declare namespace fastifyJwt {
|
||||
type SecretCallback = (request: fastify.FastifyRequest<IncomingMessage>, reply: string | Buffer | object, callback?: VerifyCallback | SignCallback) => void;
|
||||
|
||||
interface FastifyJwtOptions {
|
||||
secret: string | SecretCallback;
|
||||
}
|
||||
}
|
||||
|
||||
export interface FastifyRequest<HttpRequest> {
|
||||
jwtVerify: (options?: VerifyOptions | VerifyCallback, next?: VerifyCallback) => Promise<null | { [key: string]: any } | string> | null | { [key: string]: any } | string;
|
||||
}
|
||||
|
||||
export interface FastifyReply<HttpResponse> {
|
||||
jwtSign: (payload: any, options?: SignOptions | SignCallback, next?: SignCallback) => void;
|
||||
}
|
||||
export = fastifyJwt;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"fastify": "^1.11.2"
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
import { provider } from "ganache-core";
|
||||
import { provider } from 'ganache-core';
|
||||
|
||||
provider({ verbose: true });
|
||||
provider({ verbose: true, vmErrorsOnRPCResponse: false });
|
||||
|
||||
Vendored
+2
-1
@@ -4,7 +4,7 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
import { Provider } from "ethereum-protocol";
|
||||
import { Provider } from 'ethereum-protocol';
|
||||
export interface GanacheOpts {
|
||||
verbose?: boolean;
|
||||
logger?: {
|
||||
@@ -15,5 +15,6 @@ export interface GanacheOpts {
|
||||
networkId?: number;
|
||||
mnemonic?: string;
|
||||
gasLimit?: number;
|
||||
vmErrorsOnRPCResponse?: boolean;
|
||||
}
|
||||
export function provider(opts: GanacheOpts): Provider;
|
||||
|
||||
Vendored
+52
-34
@@ -1,4 +1,4 @@
|
||||
// Type definitions for hapi 17.0
|
||||
// Type definitions for hapi 17.6
|
||||
// Project: https://github.com/hapijs/hapi
|
||||
// Definitions by: Rafael Souza Fijalkowski <https://github.com/rafaelsouzaf>
|
||||
// Justin Simms <https://github.com/jhsimms>
|
||||
@@ -503,6 +503,14 @@ export interface Request extends Podium {
|
||||
*/
|
||||
readonly url: url.Url;
|
||||
|
||||
/**
|
||||
* Returns `true` when the request is active and processing should continue and `false` when the
|
||||
* request terminated early or completed its lifecycle. Useful when request processing is a
|
||||
* resource-intensive operation and should be terminated early if the request is no longer active
|
||||
* (e.g. client disconnected or aborted early).
|
||||
*/
|
||||
active(): boolean;
|
||||
|
||||
/**
|
||||
* Returns a response which you can pass into the reply interface where:
|
||||
* @param source - the value to set as the source of the reply interface, optional.
|
||||
@@ -1457,6 +1465,12 @@ export interface RouteOptionsResponse {
|
||||
status?: Util.Dictionary<RouteOptionsResponseSchema>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://www.w3.org/TR/referrer-policy/
|
||||
*/
|
||||
export type ReferrerPolicy = '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'unsafe-url' |
|
||||
'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin';
|
||||
|
||||
/**
|
||||
* Default value: false (security headers disabled).
|
||||
* Sets common security headers. To enable, set security to true or to an object with the following options:
|
||||
@@ -1531,6 +1545,12 @@ export interface RouteOptionsSecureObject {
|
||||
* boolean controlling the 'X-Content-Type-Options' header. Defaults to true setting the header to its only and default option, 'nosniff'.
|
||||
*/
|
||||
noSniff?: boolean;
|
||||
|
||||
/**
|
||||
* Controls the `Referrer-Policy` header, which has the following possible values.
|
||||
* @default false Header will not be send.
|
||||
*/
|
||||
referrer?: false | ReferrerPolicy;
|
||||
}
|
||||
|
||||
export type RouteOptionsSecure = boolean | RouteOptionsSecureObject;
|
||||
@@ -1842,30 +1862,6 @@ export interface RouteOptions {
|
||||
|
||||
/**
|
||||
* Default value: false (security headers disabled).
|
||||
* Sets common security headers. To enable, set security to true or to an object with the following options:
|
||||
* * hsts - controls the 'Strict-Transport-Security' header, where:
|
||||
* * * true - the header will be set to max-age=15768000. This is the default value.
|
||||
* * * a number - the maxAge parameter will be set to the provided value.
|
||||
* * * an object with the following fields:
|
||||
* * * * maxAge - the max-age portion of the header, as a number. Default is 15768000.
|
||||
* * * * includeSubDomains - a boolean specifying whether to add the includeSubDomains flag to the header.
|
||||
* * * * preload - a boolean specifying whether to add the 'preload' flag (used to submit domains inclusion in Chrome's HTTP Strict Transport Security (HSTS) preload list) to the header.
|
||||
* * xframe - controls the 'X-Frame-Options' header, where:
|
||||
* * * true - the header will be set to 'DENY'. This is the default value.
|
||||
* * * 'deny' - the headers will be set to 'DENY'.
|
||||
* * * 'sameorigin' - the headers will be set to 'SAMEORIGIN'.
|
||||
* * * an object for specifying the 'allow-from' rule, where:
|
||||
* * * * rule - one of:
|
||||
* * * * * 'deny'
|
||||
* * * * * 'sameorigin'
|
||||
* * * * * 'allow-from'
|
||||
* * * * source - when rule is 'allow-from' this is used to form the rest of the header, otherwise this field is ignored. If rule is 'allow-from' but source is unset, the rule will be
|
||||
* automatically changed to 'sameorigin'.
|
||||
* * xss - boolean that controls the 'X-XSS-PROTECTION' header for Internet Explorer. Defaults to true which sets the header to equal '1; mode=block'.
|
||||
* Note: this setting can create a security vulnerability in versions of Internet Exploere below 8, as well as unpatched versions of IE8. See here and here for more information. If you
|
||||
* actively support old versions of IE, it may be wise to explicitly set this flag to false.
|
||||
* * noOpen - boolean controlling the 'X-Download-Options' header for Internet Explorer, preventing downloads from executing in your context. Defaults to true setting the header to 'noopen'.
|
||||
* * noSniff - boolean controlling the 'X-Content-Type-Options' header. Defaults to true setting the header to its only and default option, 'nosniff'.
|
||||
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionssecurity)
|
||||
*/
|
||||
security?: RouteOptionsSecure;
|
||||
@@ -2821,6 +2817,12 @@ export interface ServerOptions {
|
||||
load?: {
|
||||
/** the frequency of sampling in milliseconds. When set to 0, the other load options are ignored. Defaults to 0 (no sampling). */
|
||||
sampleInterval?: number;
|
||||
|
||||
/**
|
||||
* Max concurrent requests.
|
||||
*/
|
||||
concurrent?: number;
|
||||
|
||||
/** maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). */
|
||||
maxHeapUsedBytes?: number;
|
||||
/**
|
||||
@@ -3177,7 +3179,9 @@ export interface ServerState {
|
||||
* An object containing the configuration of each cookie added via [server.state()](https://github.com/hapijs/hapi/blob/master/API.md#server.state()) where each key is the
|
||||
* cookie name and value is the configuration object.
|
||||
*/
|
||||
readonly cookies: object;
|
||||
readonly cookies: {
|
||||
[key: string]: ServerStateCookieOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
* An array containing the names of all configued cookies.
|
||||
@@ -3232,6 +3236,8 @@ export type DecorationMethod<T> = (this: T, ...args: any[]) => any;
|
||||
export interface PluginProperties {
|
||||
}
|
||||
|
||||
export type DecorateName = string | symbol;
|
||||
|
||||
/**
|
||||
* The server object is the main application container. The server manages all incoming requests along with all
|
||||
* the facilities provided by the framework. Each server supports a single connection (e.g. listen to port 80).
|
||||
@@ -3258,6 +3264,13 @@ export class Server extends Podium {
|
||||
*/
|
||||
auth: ServerAuth;
|
||||
|
||||
/**
|
||||
* Links another server to the initialize/start/stop state of the current server by calling the
|
||||
* controlled server `initialize()`/`start()`/`stop()` methods whenever the current server methods
|
||||
* are called, where:
|
||||
*/
|
||||
control(server: Server): void;
|
||||
|
||||
/**
|
||||
* Provides access to the decorations already applied to various framework interfaces. The object must not be
|
||||
* modified directly, but only through server.decorate.
|
||||
@@ -3350,6 +3363,11 @@ export class Server extends Podium {
|
||||
* event loop delay milliseconds.
|
||||
*/
|
||||
eventLoopDelay: number;
|
||||
|
||||
/**
|
||||
* Max concurrent requests.
|
||||
*/
|
||||
concurrent: number
|
||||
/**
|
||||
* V8 heap usage.
|
||||
*/
|
||||
@@ -3473,14 +3491,14 @@ export class Server extends Podium {
|
||||
* @return void;
|
||||
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdecoratetype-property-method-options)
|
||||
*/
|
||||
decorate(type: 'handler', property: string, method: HandlerDecorationMethod, options?: {apply?: boolean, extend?: boolean}): void;
|
||||
decorate(type: 'request', property: string, method: (existing: ((...args: any[]) => any)) => (request: Request) => DecorationMethod<Request>, options: {apply: true, extend: true}): void;
|
||||
decorate(type: 'request', property: string, method: (request: Request) => DecorationMethod<Request>, options: {apply: true, extend?: boolean}): void;
|
||||
decorate(type: 'request', property: string, method: DecorationMethod<Request>, options?: {apply?: boolean, extend?: boolean}): void;
|
||||
decorate(type: 'toolkit', property: string, method: (existing: ((...args: any[]) => any)) => DecorationMethod<ResponseToolkit>, options: {apply?: boolean, extend: true}): void;
|
||||
decorate(type: 'toolkit', property: string, method: DecorationMethod<ResponseToolkit>, options?: {apply?: boolean, extend?: boolean}): void;
|
||||
decorate(type: 'server', property: string, method: (existing: ((...args: any[]) => any)) => DecorationMethod<Server>, options: {apply?: boolean, extend: true}): void;
|
||||
decorate(type: 'server', property: string, method: DecorationMethod<Server>, options?: {apply?: boolean, extend?: boolean}): void;
|
||||
decorate(type: 'handler', property: DecorateName, method: HandlerDecorationMethod, options?: {apply?: boolean, extend?: boolean}): void;
|
||||
decorate(type: 'request', property: DecorateName, method: (existing: ((...args: any[]) => any)) => (request: Request) => DecorationMethod<Request>, options: {apply: true, extend: true}): void;
|
||||
decorate(type: 'request', property: DecorateName, method: (request: Request) => DecorationMethod<Request>, options: {apply: true, extend?: boolean}): void;
|
||||
decorate(type: 'request', property: DecorateName, method: DecorationMethod<Request>, options?: {apply?: boolean, extend?: boolean}): void;
|
||||
decorate(type: 'toolkit', property: DecorateName, method: (existing: ((...args: any[]) => any)) => DecorationMethod<ResponseToolkit>, options: {apply?: boolean, extend: true}): void;
|
||||
decorate(type: 'toolkit', property: DecorateName, method: DecorationMethod<ResponseToolkit>, options?: {apply?: boolean, extend?: boolean}): void;
|
||||
decorate(type: 'server', property: DecorateName, method: (existing: ((...args: any[]) => any)) => DecorationMethod<Server>, options: {apply?: boolean, extend: true}): void;
|
||||
decorate(type: 'server', property: DecorateName, method: DecorationMethod<Server>, options?: {apply?: boolean, extend?: boolean}): void;
|
||||
|
||||
/**
|
||||
* Used within a plugin to declare a required dependency on other plugins where:
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Request } from 'hapi';
|
||||
|
||||
const req: Request = <any> {};
|
||||
const act: boolean = req.active();
|
||||
@@ -9,7 +9,8 @@ import {
|
||||
RouteOptionsPayload,
|
||||
RouteOptionsResponse,
|
||||
RouteOptionsValidate,
|
||||
Server
|
||||
Server,
|
||||
RouteOptionsSecureObject
|
||||
} from "hapi";
|
||||
|
||||
const routeOptionsAccess: RouteOptionsAccess = {
|
||||
@@ -87,7 +88,20 @@ const routeOptionsResponse: RouteOptionsResponse = {
|
||||
200: true,
|
||||
302: true,
|
||||
404: false,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const routeOptionSecure: RouteOptionsSecureObject = {
|
||||
referrer: 'origin',
|
||||
noSniff: true,
|
||||
xframe: "deny",
|
||||
hsts: {
|
||||
includeSubdomains: true,
|
||||
maxAge: 1111,
|
||||
preload: false,
|
||||
},
|
||||
noOpen: false,
|
||||
xss: true,
|
||||
};
|
||||
|
||||
const routeOptionsValidate: RouteOptionsValidate = {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import { Server } from "hapi";
|
||||
|
||||
new Server().control(new Server());
|
||||
@@ -58,6 +58,8 @@ function decorateToolkitWithParams(this: ResponseToolkit, x: number, y: string)
|
||||
|
||||
server.decorate('toolkit', 'withParams', decorateToolkitWithParams);
|
||||
|
||||
server.decorate('toolkit', Symbol('hi'), decorateToolkitWithParams);
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/toolkitWithParams',
|
||||
|
||||
@@ -3,7 +3,10 @@ import { Server } from "hapi";
|
||||
|
||||
const server = new Server({
|
||||
port: 8000,
|
||||
load: { sampleInterval: 1000 }
|
||||
load: {
|
||||
sampleInterval: 1000,
|
||||
concurrent: 123,
|
||||
}
|
||||
});
|
||||
server.start();
|
||||
|
||||
|
||||
@@ -21,32 +21,34 @@
|
||||
"test/request/catch-all.ts",
|
||||
"test/request/event-types.ts",
|
||||
"test/request/get-log.ts",
|
||||
"test/request/methods.ts",
|
||||
"test/request/parameters.ts",
|
||||
"test/request/query.ts",
|
||||
"test/response/continue.ts",
|
||||
"test/response/error.ts",
|
||||
"test/response/redirect.ts",
|
||||
"test/response/response.ts",
|
||||
"test/response/response-events.ts",
|
||||
"test/response/response.ts",
|
||||
"test/route/adding-routes.ts",
|
||||
"test/route/config.ts",
|
||||
"test/route/handler.ts",
|
||||
"test/route/ext.ts",
|
||||
"test/route/route-options.ts",
|
||||
"test/route/handler.ts",
|
||||
"test/route/route-options-pre.ts",
|
||||
"test/route/route-options.ts",
|
||||
"test/route/validation.ts",
|
||||
"test/server/server-app.ts",
|
||||
"test/server/server-auth-api.ts",
|
||||
"test/server/server-auth-default.ts",
|
||||
"test/server/server-auth-test.ts",
|
||||
"test/server/server-bind.ts",
|
||||
"test/server/server-cache.ts",
|
||||
"test/server/server-cache-provision.ts",
|
||||
"test/server/server-cache.ts",
|
||||
"test/server/server-control.ts",
|
||||
"test/server/server-decoder.ts",
|
||||
"test/server/server-decorations.ts",
|
||||
"test/server/server-encoder.ts",
|
||||
"test/server/server-events.ts",
|
||||
"test/server/server-events-once.ts",
|
||||
"test/server/server-events.ts",
|
||||
"test/server/server-expose.ts",
|
||||
"test/server/server-info.ts",
|
||||
"test/server/server-inject.ts",
|
||||
|
||||
Vendored
+13
-7
@@ -1,4 +1,4 @@
|
||||
// Type definitions for joi 13.4
|
||||
// Type definitions for joi 13.6
|
||||
// Project: https://github.com/hapijs/joi
|
||||
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
|
||||
// Laurence Dougal Myers <https://github.com/laurence-myers>
|
||||
@@ -197,6 +197,7 @@ export interface ReferenceOptions {
|
||||
functions?: boolean;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:interface-name
|
||||
export interface IPOptions {
|
||||
version?: string[];
|
||||
cidr?: string;
|
||||
@@ -225,9 +226,7 @@ export interface ValidationErrorItem {
|
||||
context?: Context;
|
||||
}
|
||||
|
||||
export interface ValidationErrorFunction {
|
||||
(errors: ValidationErrorItem[]): string | ValidationErrorItem | ValidationErrorItem[] | Error;
|
||||
}
|
||||
export type ValidationErrorFunction = (errors: ValidationErrorItem[]) => string | ValidationErrorItem | ValidationErrorItem[] | Error;
|
||||
|
||||
export interface ValidationResult<T> extends Pick<Promise<T>, 'then' | 'catch'> {
|
||||
error: ValidationError;
|
||||
@@ -685,6 +684,11 @@ export interface StringSchema extends AnySchema {
|
||||
trim(): this;
|
||||
}
|
||||
|
||||
export interface SymbolSchema extends AnySchema {
|
||||
// TODO: support number and symbol index
|
||||
map(iterable: Iterable<[string | number | boolean | symbol, symbol]> | { [key: string]: symbol }): this;
|
||||
}
|
||||
|
||||
export interface ArraySchema extends AnySchema {
|
||||
/**
|
||||
* Allow this array to be sparse.
|
||||
@@ -1078,6 +1082,11 @@ export function object(schema?: SchemaMap): ObjectSchema;
|
||||
*/
|
||||
export function string(): StringSchema;
|
||||
|
||||
/**
|
||||
* Generates a schema object that matches any symbol.
|
||||
*/
|
||||
export function symbol(): SymbolSchema;
|
||||
|
||||
/**
|
||||
* Generates a type that will match one of the provided alternative schemas
|
||||
*/
|
||||
@@ -1110,7 +1119,6 @@ export function validate<T, R>(value: T, schema: SchemaLike, options: Validation
|
||||
* Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object).
|
||||
*/
|
||||
export function compile(schema: SchemaLike): Schema;
|
||||
export function compile<T extends Schema>(schema: SchemaLike): T;
|
||||
|
||||
/**
|
||||
* Validates a value against a schema and throws if validation fails.
|
||||
@@ -1145,9 +1153,7 @@ export function isRef(ref: any): ref is Reference;
|
||||
* of strings For string values path separator is a dot (`.`)
|
||||
*/
|
||||
export function reach(schema: ObjectSchema, path: string): Schema;
|
||||
export function reach<T extends Schema>(schema: ObjectSchema, path: string): T;
|
||||
export function reach(schema: ObjectSchema, path: string[]): Schema;
|
||||
export function reach<T extends Schema>(schema: ObjectSchema, path: string[]): T;
|
||||
|
||||
/**
|
||||
* Creates a new Joi instance customized with the extension(s) you provide included.
|
||||
|
||||
@@ -1142,3 +1142,9 @@ schema = Joi.raw(bool);
|
||||
schema = Joi.empty();
|
||||
schema = Joi.empty(str);
|
||||
schema = Joi.empty(anySchema);
|
||||
|
||||
schema = Joi.symbol();
|
||||
schema = Joi.symbol().map(new Map<string, symbol>());
|
||||
schema = Joi.symbol().map({
|
||||
key: Symbol('asd'),
|
||||
});
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
"rules": {
|
||||
// All are TODOs
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"interface-name": false,
|
||||
"no-empty-interface": false,
|
||||
"no-self-import": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"unified-signatures": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -3385,7 +3385,7 @@ interface JQuery {
|
||||
* @see {@link https://api.jquery.com/selector/}
|
||||
*/
|
||||
selector: string;
|
||||
[index: number]: HTMLElement;
|
||||
[index: number]: Element;
|
||||
|
||||
/**
|
||||
* Add elements to the set of matched elements.
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// Type definitions for MarkdownItLazyHeaders (markdown-it-lazy-headers) 0.13
|
||||
// Project: https://github.com/Galadirith/markdown-it-lazy-headers
|
||||
// Definitions by: Knom <https://github.com/knom>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
import { MarkdownIt } from 'markdown-it';
|
||||
|
||||
declare function lazyheaders(md: MarkdownIt): void;
|
||||
|
||||
export = lazyheaders;
|
||||
@@ -0,0 +1,13 @@
|
||||
import MarkdownIt = require("markdown-it");
|
||||
import lazyHeaders = require("markdown-it-lazy-headers");
|
||||
|
||||
const md = new MarkdownIt();
|
||||
|
||||
md.use(lazyHeaders);
|
||||
|
||||
const src = `# First header
|
||||
Lorem ipsum.
|
||||
## Next section!
|
||||
This is totaly awesome.`;
|
||||
|
||||
md.render(src);
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"markdown-it-lazy-headers-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+16
-4
@@ -19,6 +19,14 @@ export interface NextAppContext<Q extends DefaultQuery = DefaultQuery> {
|
||||
ctx: NextContext<Q>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial Props returned from base App class.
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/lib/app.js#L16
|
||||
*/
|
||||
export interface DefaultAppIProps {
|
||||
pageProps: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Props passed to the App component.
|
||||
* Component and pageProps are dynamic - cannot infer type.
|
||||
@@ -28,19 +36,23 @@ export interface NextAppContext<Q extends DefaultQuery = DefaultQuery> {
|
||||
export interface AppProps<Q extends DefaultQuery = DefaultQuery> {
|
||||
Component: NextComponentType<any, any, NextContext<Q>>;
|
||||
router: RouterProps<Q>;
|
||||
pageProps: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* App component type. Differs from the default type because the context it passes
|
||||
* to getInitialProps and the props is passes to the component are different.
|
||||
*
|
||||
* @template P Component props.
|
||||
* @template IP Initial props returned from getInitialProps.
|
||||
* @template C Context passed to getInitialProps.
|
||||
*/
|
||||
export type AppComponentType<IP = {}, C = NextAppContext> = NextComponentType<IP & AppProps, IP, C>;
|
||||
export type AppComponentType<P = {}, IP = P, C = NextAppContext> = NextComponentType<
|
||||
P & AppProps,
|
||||
IP,
|
||||
C
|
||||
>;
|
||||
|
||||
export class Container extends React.Component {}
|
||||
export default class App<P = {}> extends React.Component<P & AppProps> {
|
||||
static getInitialProps(context: NextAppContext): Promise<{ pageProps: any }>;
|
||||
export default class App<P = {}> extends React.Component<P & DefaultAppIProps & AppProps> {
|
||||
static getInitialProps(context: NextAppContext): Promise<DefaultAppIProps>;
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
export default function(): {serverRuntimeConfig: any, publicRuntimeConfig: any};
|
||||
export default function(): { serverRuntimeConfig: any; publicRuntimeConfig: any };
|
||||
|
||||
Vendored
+40
-23
@@ -3,14 +3,9 @@ import { NextContext, NextComponentType } from ".";
|
||||
import { DefaultQuery } from "./router";
|
||||
|
||||
export interface RenderPageResponse {
|
||||
buildManifest: { [key: string]: any };
|
||||
chunks: {
|
||||
names: string[];
|
||||
filenames: string[];
|
||||
};
|
||||
buildManifest: Record<string, any>;
|
||||
html?: string;
|
||||
head: Array<React.ReactElement<any>>;
|
||||
errorHtml: string;
|
||||
head?: Array<React.ReactElement<any>>;
|
||||
}
|
||||
|
||||
export interface PageProps {
|
||||
@@ -38,24 +33,42 @@ export interface NextDocumentContext<Q extends DefaultQuery = DefaultQuery> exte
|
||||
}
|
||||
|
||||
/**
|
||||
* Props passed to the Document component.
|
||||
* Initial Props returned from base Document class.
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/server/document.js#L16
|
||||
*/
|
||||
export interface DocumentProps {
|
||||
__NEXT_DATA__?: any;
|
||||
dev?: boolean;
|
||||
chunks?: {
|
||||
names: string[];
|
||||
filenames: string[];
|
||||
};
|
||||
html?: string;
|
||||
head?: Array<React.ReactElement<any>>;
|
||||
errorHtml?: string;
|
||||
export interface DefaultDocumentIProps extends RenderPageResponse {
|
||||
styles?: Array<React.ReactElement<any>>;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Props passed to the Document component.
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/server/render.js#L165
|
||||
*/
|
||||
export interface DocumentProps<Q extends DefaultQuery = DefaultQuery> {
|
||||
__NEXT_DATA__: {
|
||||
props: any;
|
||||
page: string;
|
||||
pathname: string;
|
||||
query: Q;
|
||||
buildId: string;
|
||||
assetPrefix?: string;
|
||||
runtimeConfig?: any;
|
||||
nextExport?: boolean;
|
||||
err?: any;
|
||||
};
|
||||
dev: boolean;
|
||||
dir?: string;
|
||||
staticMarkup: boolean;
|
||||
buildManifest: Record<string, any>;
|
||||
devFiles: string[];
|
||||
files: string[];
|
||||
dynamicImports: string[];
|
||||
assetPrefix: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Props supported by the Head component.
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/server/document.js#L42
|
||||
*/
|
||||
export interface HeadProps {
|
||||
nonce?: string;
|
||||
@@ -64,6 +77,7 @@ export interface HeadProps {
|
||||
|
||||
/**
|
||||
* Props supported by the NextScript component.
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/server/document.js#L141
|
||||
*/
|
||||
export interface NextScriptProps {
|
||||
nonce?: string;
|
||||
@@ -74,11 +88,12 @@ export interface NextScriptProps {
|
||||
* Document component type. Differs from the default type because the context it passes
|
||||
* to getInitialProps and the props is passes to the component are different.
|
||||
*
|
||||
* @template P Component props.
|
||||
* @template IP Initial props returned from getInitialProps.
|
||||
* @template C Context passed to getInitialProps.
|
||||
*/
|
||||
export type DocumentComponentType<IP = {}, C = NextDocumentContext> = NextComponentType<
|
||||
IP & DocumentProps,
|
||||
export type DocumentComponentType<P = {}, IP = P, C = NextDocumentContext> = NextComponentType<
|
||||
P & DocumentProps,
|
||||
IP,
|
||||
C
|
||||
>;
|
||||
@@ -86,6 +101,8 @@ export type DocumentComponentType<IP = {}, C = NextDocumentContext> = NextCompon
|
||||
export class Head extends React.Component<HeadProps> {}
|
||||
export class Main extends React.Component {}
|
||||
export class NextScript extends React.Component<NextScriptProps> {}
|
||||
export default class Document<P = {}> extends React.Component<P & DocumentProps> {
|
||||
static getInitialProps(context: NextDocumentContext): DocumentProps;
|
||||
export default class Document<P = {}> extends React.Component<
|
||||
P & DefaultDocumentIProps & DocumentProps
|
||||
> {
|
||||
static getInitialProps(context: NextDocumentContext): DefaultDocumentIProps;
|
||||
}
|
||||
|
||||
Vendored
+37
-24
@@ -1,29 +1,42 @@
|
||||
import * as React from "react";
|
||||
import {
|
||||
LoadableComponent,
|
||||
CommonOptions as LoadableOptions,
|
||||
LoadingComponentProps as LoadableLoadingComponentProps
|
||||
} from "react-loadable";
|
||||
|
||||
export interface DynamicOptions<TCProps, TLProps> {
|
||||
loading?: React.ComponentType<TLProps>;
|
||||
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
|
||||
|
||||
type AsyncComponent<P = any> = Promise<React.ComponentType<P>>;
|
||||
type AsyncComponentLoader<P = any> = () => AsyncComponent<P>;
|
||||
type ModuleMapping = Record<string, AsyncComponent>;
|
||||
type LoadedModuleMapping = Record<string, React.ComponentType>;
|
||||
|
||||
interface NextDynamicOptions<P = {}> extends Omit<LoadableOptions, "loading" | "modules"> {
|
||||
modules?: () => ModuleMapping; // overridden
|
||||
loading?: LoadableOptions["loading"]; // optional
|
||||
loader?: AsyncComponentLoader<P>; // optional, overriden
|
||||
render?: (props: P, loaded: LoadedModuleMapping) => React.ReactNode; // optional, overriden
|
||||
ssr?: boolean;
|
||||
modules?(
|
||||
props: TCProps & TLProps,
|
||||
): { [key: string]: Promise<React.ComponentType<any>> };
|
||||
render?(
|
||||
props: TCProps & TLProps,
|
||||
modules: { [key: string]: React.ComponentType<any> },
|
||||
): void;
|
||||
loadableGenerated?: {
|
||||
webpack?: any;
|
||||
modules?: any;
|
||||
};
|
||||
}
|
||||
|
||||
export class SameLoopPromise<T> extends Promise<T> {
|
||||
constructor(
|
||||
executor: (
|
||||
resolve: (value?: T) => void,
|
||||
reject: (reason?: any) => void,
|
||||
) => void,
|
||||
);
|
||||
setResult(value: T): void;
|
||||
setError(value: any): void;
|
||||
runIfNeeded(): void;
|
||||
}
|
||||
export default function<TCProps, TLProps>(
|
||||
componentPromise: Promise<React.ComponentType<TCProps>>,
|
||||
options?: DynamicOptions<TCProps, TLProps>,
|
||||
): React.ComponentType<TCProps & TLProps>;
|
||||
type DynamicComponent<P> = React.ComponentType<P> & LoadableComponent;
|
||||
|
||||
/**
|
||||
* Overloaded dynamic function.
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/lib/dynamic.js#L55
|
||||
*/
|
||||
declare function dynamic<P = {}>(
|
||||
options: AsyncComponent<P> | NextDynamicOptions<P>
|
||||
): DynamicComponent<P>;
|
||||
declare function dynamic<P = {}>(
|
||||
asyncModule: AsyncComponent<P>,
|
||||
options: NextDynamicOptions<P>
|
||||
): DynamicComponent<P>;
|
||||
|
||||
export type LoadingComponentProps = LoadableLoadingComponentProps;
|
||||
export default dynamic;
|
||||
|
||||
Vendored
+13
-1
@@ -1,2 +1,14 @@
|
||||
import * as React from "react";
|
||||
export default class extends React.Component<{ statusCode: number }> {}
|
||||
import { NextContext } from ".";
|
||||
|
||||
/**
|
||||
* Initial props returned from base Error class.
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/lib/error.js#L7
|
||||
*/
|
||||
export interface DefaultErrorIProps {
|
||||
statusCode: number;
|
||||
}
|
||||
|
||||
export default class Error<P = {}> extends React.Component<P & DefaultErrorIProps> {
|
||||
static getInitialProps(context: NextContext): DefaultErrorIProps;
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
import * as React from "react";
|
||||
|
||||
export function defaultHead(): JSX.Element[];
|
||||
export default class extends React.Component {
|
||||
export default class Head extends React.Component {
|
||||
static canUseDOM: boolean;
|
||||
static peek(): Array<React.ReactElement<any>>;
|
||||
static rewind(): Array<React.ReactElement<any>>;
|
||||
|
||||
Vendored
+7
-14
@@ -1,4 +1,4 @@
|
||||
// Type definitions for next 6.1
|
||||
// Type definitions for next 7.0
|
||||
// Project: https://github.com/zeit/next.js
|
||||
// Definitions by: Drew Hays <https://github.com/dru89>
|
||||
// Brice BERNARD <https://github.com/brikou>
|
||||
@@ -13,10 +13,8 @@
|
||||
|
||||
import * as http from "http";
|
||||
import * as url from "url";
|
||||
|
||||
import { Response as NodeResponse } from "node-fetch";
|
||||
|
||||
import { SingletonRouter, DefaultQuery } from "./router";
|
||||
import { SingletonRouter, DefaultQuery, UrlLike } from "./router";
|
||||
|
||||
declare namespace next {
|
||||
// Deprecated
|
||||
@@ -24,12 +22,10 @@ declare namespace next {
|
||||
type ServerConfig = NextConfig;
|
||||
// End Deprecated
|
||||
|
||||
type UrlLike = url.UrlObject | url.Url;
|
||||
|
||||
/**
|
||||
* Context object used in methods like `getInitialProps()`
|
||||
* https://github.com/zeit/next.js/blob/6.1.1/server/render.js#L77
|
||||
* https://github.com/zeit/next.js/blob/6.1.1/readme.md#fetching-data-and-component-lifecycle
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/server/render.js#L97
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/README.md#fetching-data-and-component-lifecycle
|
||||
*
|
||||
* @template Q Query object schema.
|
||||
*/
|
||||
@@ -52,7 +48,7 @@ declare namespace next {
|
||||
|
||||
/**
|
||||
* Next.js config schema.
|
||||
* https://github.com/zeit/next.js/blob/6.1.1/server/config.js#L10
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/server/config.js#L9
|
||||
*/
|
||||
interface NextConfig {
|
||||
webpack?: any;
|
||||
@@ -74,7 +70,7 @@ declare namespace next {
|
||||
|
||||
/**
|
||||
* Options passed to the Server constructor in Node.js.
|
||||
* https://github.com/zeit/next.js/blob/6.1.1/server/index.js#L30
|
||||
* https://github.com/zeit/next.js/blob/7.0.0/server/index.js#L25
|
||||
*/
|
||||
interface ServerOptions {
|
||||
dir?: string;
|
||||
@@ -89,7 +85,7 @@ declare namespace next {
|
||||
*/
|
||||
interface Server {
|
||||
// From constructor
|
||||
// https://github.com/zeit/next.js/blob/6.1.1/server/index.js#L30
|
||||
// https://github.com/zeit/next.js/blob/7.0.0/server/index.js#L25
|
||||
dir: string;
|
||||
dev: boolean;
|
||||
quiet: boolean;
|
||||
@@ -105,7 +101,6 @@ declare namespace next {
|
||||
distDir: string;
|
||||
hotReloader: any;
|
||||
buildId: string;
|
||||
availableChunks: object;
|
||||
generateETags: boolean;
|
||||
runtimeConfig?: object;
|
||||
};
|
||||
@@ -172,9 +167,7 @@ declare namespace next {
|
||||
): Promise<void>;
|
||||
isServeableUrl(path: string): boolean;
|
||||
readBuildId(): string;
|
||||
handleBuildId(buildId: string, res: http.ServerResponse): boolean;
|
||||
getCompilationError(): Promise<any>;
|
||||
send404(res: http.ServerResponse): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+7
-3
@@ -1,8 +1,12 @@
|
||||
import * as url from "url";
|
||||
import * as React from "react";
|
||||
import { UrlLike } from "./router";
|
||||
|
||||
export type UrlLike = url.UrlObject | url.Url;
|
||||
export interface LinkState {
|
||||
// Deprecated
|
||||
export type LinkState = LinkProps;
|
||||
// End Deprecated
|
||||
|
||||
export interface LinkProps {
|
||||
prefetch?: boolean;
|
||||
shallow?: boolean;
|
||||
scroll?: boolean;
|
||||
@@ -14,4 +18,4 @@ export interface LinkState {
|
||||
children: React.ReactElement<any>;
|
||||
}
|
||||
|
||||
export default class extends React.Component<LinkState> {}
|
||||
export default class Link extends React.Component<LinkProps> {}
|
||||
|
||||
Vendored
+12
-11
@@ -1,14 +1,13 @@
|
||||
import * as React from "react";
|
||||
import * as url from "url";
|
||||
|
||||
type UrlLike = url.UrlObject | url.Url;
|
||||
|
||||
type EventName = 'routeChangeStart'
|
||||
| 'routeChangeComplete'
|
||||
| 'routeChangeError'
|
||||
| 'beforeHistoryChange'
|
||||
| 'hashChangeStart'
|
||||
| 'hashChangeComplete';
|
||||
type EventName =
|
||||
| "routeChangeStart"
|
||||
| "routeChangeComplete"
|
||||
| "routeChangeError"
|
||||
| "beforeHistoryChange"
|
||||
| "hashChangeStart"
|
||||
| "hashChangeComplete";
|
||||
|
||||
interface RouteChangeError {
|
||||
cancelled: boolean;
|
||||
@@ -17,6 +16,8 @@ interface RouteChangeError {
|
||||
type EventHandler = (url: string) => any;
|
||||
type ErrorEventHandler = (err: RouteChangeError, url: string) => any;
|
||||
|
||||
export type UrlLike = url.UrlObject | url.Url;
|
||||
|
||||
export interface EventChangeOptions {
|
||||
shallow?: boolean;
|
||||
[key: string]: any;
|
||||
@@ -47,13 +48,13 @@ export interface RouterProps<Q = DefaultQuery> {
|
||||
push(
|
||||
url: string | UrlLike,
|
||||
as?: string | UrlLike,
|
||||
options?: EventChangeOptions,
|
||||
options?: EventChangeOptions
|
||||
): Promise<boolean>;
|
||||
reload(route: string): Promise<void>;
|
||||
replace(
|
||||
url: string | UrlLike,
|
||||
as?: string | UrlLike,
|
||||
options?: EventChangeOptions,
|
||||
options?: EventChangeOptions
|
||||
): Promise<boolean>;
|
||||
|
||||
// events (deprecated soonish)
|
||||
@@ -87,7 +88,7 @@ export interface WithRouterProps<Q = DefaultQuery> {
|
||||
// without defining props explicitly
|
||||
export function withRouter<T extends {}, Q = DefaultQuery>(
|
||||
// tslint:disable-next-line:no-unnecessary-generics
|
||||
Component: React.ComponentType<T & WithRouterProps<Q>>,
|
||||
Component: React.ComponentType<T & WithRouterProps<Q>>
|
||||
): React.ComponentType<T>;
|
||||
|
||||
declare const Router: SingletonRouter;
|
||||
|
||||
@@ -2,8 +2,8 @@ import * as React from "react";
|
||||
import App, { Container, NextAppContext, AppProps, AppComponentType } from "next/app";
|
||||
import { DefaultQuery } from "next/router";
|
||||
|
||||
interface NextComponentProps {
|
||||
example: string;
|
||||
interface TestAppProps {
|
||||
pageProps: any;
|
||||
}
|
||||
|
||||
interface TypedQuery extends DefaultQuery {
|
||||
@@ -21,10 +21,10 @@ class TestApp extends App {
|
||||
}
|
||||
}
|
||||
|
||||
class TestAppWithProps extends App<NextComponentProps> {
|
||||
class TestAppWithProps extends App<TestAppProps & WithExampleProps> {
|
||||
static async getInitialProps({ Component, router, ctx }: NextAppContext) {
|
||||
const pageProps = Component.getInitialProps && (await Component.getInitialProps(ctx));
|
||||
return { pageProps, example: "foobar" };
|
||||
return { pageProps };
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -55,8 +55,8 @@ interface TestProps {
|
||||
}
|
||||
|
||||
// Stateful HOC that adds props to wrapped component. Similar to what withRedux does.
|
||||
// tslint:disable-next-line no-unnecessary-generics
|
||||
const withExample = <P extends {}>(App: AppComponentType<P & WithExampleProps>) =>
|
||||
// tslint:disable-next-line no-unnecessary-generics, use-default-type-parameter
|
||||
const withExample = <P extends {}>(App: AppComponentType<P & WithExampleProps, P>) =>
|
||||
class extends React.Component<P & AppProps & WithExampleHocProps> {
|
||||
test: string;
|
||||
|
||||
@@ -79,7 +79,7 @@ const withExample = <P extends {}>(App: AppComponentType<P & WithExampleProps>)
|
||||
|
||||
// Basic stateless HOC. Similar to what withAuth would do.
|
||||
// tslint:disable-next-line no-unnecessary-generics
|
||||
const withBasic = <P extends {}, C extends {}>(App: AppComponentType<P, C>) =>
|
||||
const withBasic = <P extends {}, C extends {}>(App: AppComponentType<P, P, C>) =>
|
||||
class extends React.Component<P & AppProps> {
|
||||
static async getInitialProps(context: C) {
|
||||
const pageProps = App.getInitialProps && (await App.getInitialProps(context));
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
import Document, { DocumentProps, Enhancer, Head, Main, NextScript, NextDocumentContext, PageProps } from 'next/document';
|
||||
import Document, {
|
||||
Enhancer,
|
||||
Head,
|
||||
Main,
|
||||
NextScript,
|
||||
NextDocumentContext,
|
||||
PageProps
|
||||
} from "next/document";
|
||||
import * as React from "react";
|
||||
|
||||
const basicResults = (
|
||||
<Document any="property" should="work" here>
|
||||
<Head some="more" properties>
|
||||
<meta name="description" content="Head can have children, too!" />
|
||||
</Head>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</Document>
|
||||
);
|
||||
interface WithUrlProps {
|
||||
url: string;
|
||||
}
|
||||
|
||||
const withNonce = (
|
||||
<Document>
|
||||
<Head nonce="12345" />
|
||||
<NextScript nonce="12345" />
|
||||
</Document>
|
||||
);
|
||||
|
||||
class MyDoc extends Document {
|
||||
static async getInitialProps({ renderPage }: NextDocumentContext) {
|
||||
class MyDoc extends Document<WithUrlProps> {
|
||||
static getInitialProps({ req, renderPage }: NextDocumentContext) {
|
||||
// without callback
|
||||
const _page = renderPage();
|
||||
|
||||
// with callback
|
||||
const enhancer: Enhancer<PageProps, {}> = (App) => (props) => (<App />);
|
||||
const { html, head, errorHtml, chunks, buildManifest } = renderPage(enhancer);
|
||||
const enhancer: Enhancer<PageProps, {}> = App => props => <App />;
|
||||
const { html, head, buildManifest } = renderPage(enhancer);
|
||||
|
||||
const style = {};
|
||||
const styles = [<style />];
|
||||
|
||||
return { html, head, errorHtml, chunks, buildManifest, style };
|
||||
// Custom prop
|
||||
const url = req!.url;
|
||||
|
||||
return { html, head, buildManifest, styles, url };
|
||||
}
|
||||
|
||||
render() {
|
||||
const { pathname, query } = this.props.__NEXT_DATA__;
|
||||
|
||||
return (
|
||||
<html>
|
||||
<Head>
|
||||
<Head nonce="nonce" any="property" should="work" here>
|
||||
<title>My page</title>
|
||||
<style id='cxs-style' dangerouslySetInnerHTML={{ __html: this.props.style }} />
|
||||
{this.props.styles}
|
||||
</Head>
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
<p>{this.props.url}</p>
|
||||
{this.props.children}
|
||||
</body>
|
||||
</html>
|
||||
@@ -49,21 +49,12 @@ class MyDoc extends Document {
|
||||
}
|
||||
}
|
||||
|
||||
const extendedResults = (
|
||||
<MyDoc any="property" should="work" here>
|
||||
<Head some="more" properties>
|
||||
<meta name="description" content="Head can have children, too!" />
|
||||
</Head>
|
||||
<h1>Hey there</h1>
|
||||
</MyDoc>
|
||||
);
|
||||
|
||||
const renderPage: NextDocumentContext['renderPage'] = (enhancer) => ({
|
||||
const renderPage: NextDocumentContext["renderPage"] = enhancer => ({
|
||||
buildManifest: {},
|
||||
chunks: { names: [], filenames: [] },
|
||||
html: '',
|
||||
html: "",
|
||||
head: [<React.Fragment />],
|
||||
errorHtml: '',
|
||||
errorHtml: ""
|
||||
});
|
||||
|
||||
interface PageInitialProps extends PageProps {
|
||||
@@ -76,11 +67,18 @@ interface ProcessedInitialProps {
|
||||
bar: boolean;
|
||||
}
|
||||
|
||||
const enhancerExplicit: Enhancer<PageProps, {}> = (App) => (props) => (<App />);
|
||||
const enhancerInferred = (App: React.ComponentType<ProcessedInitialProps>) => ({ foo, bar }: PageInitialProps) => (<App fooLength={foo.length} bar={!!bar} />);
|
||||
const enhancerExplicit: Enhancer<PageProps, {}> = App => props => <App />;
|
||||
const enhancerInferred = (App: React.ComponentType<ProcessedInitialProps>) => ({
|
||||
foo,
|
||||
bar
|
||||
}: PageInitialProps) => <App fooLength={foo.length} bar={!!bar} />;
|
||||
const explicitEnhancerRenderResponse = renderPage(enhancerExplicit);
|
||||
const inferredEnhancerRenderResponse = renderPage(enhancerInferred);
|
||||
const defaultedTypesRenderResponse = renderPage((App) => (props) => (<App url={props.url} />));
|
||||
const defaultedTypesExtendedRenderResponse = renderPage((App) => (props) => (<App foo="bar" url={props.url} />));
|
||||
const explicitTypesRenderResponseOne = renderPage<PageProps, {}>((App) => (props) => (<App />));
|
||||
const explicitTypesRenderResponseTwo = renderPage<PageInitialProps, ProcessedInitialProps>((App) => ({ foo, bar }) => (<App fooLength={foo.length} bar={!!bar} />));
|
||||
const defaultedTypesRenderResponse = renderPage(App => props => <App url={props.url} />);
|
||||
const defaultedTypesExtendedRenderResponse = renderPage(App => props => (
|
||||
<App foo="bar" url={props.url} />
|
||||
));
|
||||
const explicitTypesRenderResponseOne = renderPage<PageProps, {}>(App => props => <App />);
|
||||
const explicitTypesRenderResponseTwo = renderPage<PageInitialProps, ProcessedInitialProps>(
|
||||
App => ({ foo, bar }) => <App fooLength={foo.length} bar={!!bar} />
|
||||
);
|
||||
|
||||
@@ -1,25 +1,65 @@
|
||||
import dynamic, * as d from "next/dynamic";
|
||||
import * as React from "react";
|
||||
import dynamic, { LoadingComponentProps } from "next/dynamic";
|
||||
|
||||
// typically you'd use this with an esnext-style import() statement, but we'll make do without
|
||||
interface DynamicComponentProps {
|
||||
// You'd typically do this via import('./MyComponent')
|
||||
interface MyComponentProps {
|
||||
foo: string;
|
||||
bar: number;
|
||||
}
|
||||
async function getComponent() {
|
||||
return (props: DynamicComponentProps) => (
|
||||
<div>
|
||||
I'm an async component! {props.foo} {props.bar}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const MyComponent: React.StatelessComponent<MyComponentProps> = () => <div>I'm async!</div>;
|
||||
const asyncComponent = Promise.resolve(MyComponent);
|
||||
|
||||
interface LoadingComponentProps {
|
||||
baz: boolean;
|
||||
}
|
||||
// Examples from
|
||||
// https://github.com/zeit/next.js/#dynamic-import
|
||||
|
||||
const DynamicComponent = dynamic(getComponent(), {
|
||||
loading: (props: LoadingComponentProps) => <div>Loading! {props.baz}</div>,
|
||||
const LoadingComponent: React.StatelessComponent<LoadingComponentProps> = ({
|
||||
isLoading,
|
||||
error
|
||||
}) => <p>loading...</p>;
|
||||
|
||||
// 1. Basic Usage (Also does SSR)
|
||||
const DynamicComponent = dynamic(asyncComponent);
|
||||
const dynamicComponentJSX = <DynamicComponent foo="bar" />;
|
||||
|
||||
// 2. With Custom Loading Component
|
||||
const DynamicComponentWithCustomLoading = dynamic(asyncComponent, {
|
||||
loading: LoadingComponent
|
||||
});
|
||||
const dynamicComponentWithCustomLoadingJSX = <DynamicComponentWithCustomLoading foo="bar" />;
|
||||
|
||||
// 3. With No SSR
|
||||
const DynamicComponentWithNoSSR = dynamic(asyncComponent, {
|
||||
ssr: false
|
||||
});
|
||||
|
||||
const jsx = <DynamicComponent foo="five" bar={5} baz />;
|
||||
// 4. With Multiple Modules At Once
|
||||
const HelloBundle = dynamic<MyComponentProps>({
|
||||
modules: () => {
|
||||
const components = {
|
||||
Hello1: asyncComponent,
|
||||
Hello2: asyncComponent
|
||||
};
|
||||
|
||||
return components;
|
||||
},
|
||||
render: (props, { Hello1, Hello2 }) => (
|
||||
<div>
|
||||
<h1>{props.foo}</h1>
|
||||
<Hello1 />
|
||||
<Hello2 />
|
||||
</div>
|
||||
)
|
||||
});
|
||||
const helloBundleJSX = <HelloBundle foo="bar" />;
|
||||
|
||||
// 5. With plain Loadable options
|
||||
const LoadableComponent = dynamic({
|
||||
loader: () => asyncComponent,
|
||||
loading: LoadingComponent,
|
||||
delay: 200,
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
// 6. No loading
|
||||
const DynamicComponentWithNoLoading = dynamic(asyncComponent, {
|
||||
loading: () => null
|
||||
});
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
import * as React from "react";
|
||||
import ErrorComponent from "next/error";
|
||||
import Error from "next/error";
|
||||
|
||||
const result = <ErrorComponent statusCode={404} />;
|
||||
interface WithFooProps {
|
||||
foo: string;
|
||||
}
|
||||
|
||||
const result = <Error statusCode={404} />;
|
||||
|
||||
class MyError extends Error<WithFooProps> {
|
||||
static getInitialProps() {
|
||||
return { statusCode: 404, foo: 'bar'};
|
||||
}
|
||||
|
||||
render() {
|
||||
const { statusCode, foo } = this.props;
|
||||
return <div>{statusCode} {foo}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,9 +77,7 @@ function handle(req: http.IncomingMessage, res: http.ServerResponse) {
|
||||
|
||||
let b: boolean;
|
||||
b = server.isServeableUrl("/path/to/thing");
|
||||
b = server.handleBuildId("{buildId}", res);
|
||||
|
||||
const s: string = server.readBuildId();
|
||||
server.getCompilationError().then(err => err.thisIsAnAny);
|
||||
server.send404(res);
|
||||
}
|
||||
|
||||
Vendored
+20
-3
@@ -5,7 +5,24 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { ReactNode, ReactElement } from 'react';
|
||||
export interface ReactElementLike {
|
||||
type: string | ((...args: any[]) => ReactElementLike);
|
||||
props: any;
|
||||
key: string | number | null;
|
||||
children?: ReactNodeLike;
|
||||
}
|
||||
|
||||
export interface ReactNodeArray extends Array<ReactNodeLike> {}
|
||||
|
||||
export type ReactNodeLike =
|
||||
| {}
|
||||
| ReactElementLike
|
||||
| ReactNodeArray
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
| undefined;
|
||||
|
||||
export const nominalTypeHack: unique symbol;
|
||||
|
||||
@@ -38,8 +55,8 @@ export const func: Requireable<(...args: any[]) => any>;
|
||||
export const number: Requireable<number>;
|
||||
export const object: Requireable<object>;
|
||||
export const string: Requireable<string>;
|
||||
export const node: Requireable<ReactNode>;
|
||||
export const element: Requireable<ReactElement<any>>;
|
||||
export const node: Requireable<ReactNodeLike>;
|
||||
export const element: Requireable<ReactElementLike>;
|
||||
export const symbol: Requireable<symbol>;
|
||||
export function instanceOf<T>(expectedClass: new (...args: any[]) => T): Requireable<T>;
|
||||
export function oneOf<T>(types: T[]): Requireable<T>;
|
||||
|
||||
Vendored
+2
-1
@@ -5,6 +5,7 @@
|
||||
// Microsoft <https://microsoft.com>
|
||||
// MartynasZilinskas <https://github.com/MartynasZilinskas>
|
||||
// Josh Rutherford <https://github.com/theruther4d>
|
||||
// JounQin <https://github.com/JounQin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
@@ -16,7 +17,7 @@ import {
|
||||
DOMAttributes, DOMElement, ReactNode, ReactPortal
|
||||
} from 'react';
|
||||
|
||||
export function findDOMNode(instance: ReactInstance): Element | null | Text;
|
||||
export function findDOMNode(instance: ReactInstance): Element | string | null;
|
||||
export function unmountComponentAtNode(container: Element): boolean;
|
||||
|
||||
export function createPortal(children: ReactNode, container: Element, key?: null | string): ReactPortal;
|
||||
|
||||
Vendored
+1
-1
@@ -194,7 +194,7 @@ export interface Props<OptionType> {
|
||||
/* Style modifier methods */
|
||||
styles?: StylesConfig;
|
||||
/* Sets the tabIndex attribute on the input */
|
||||
tabIndex?: string;
|
||||
tabIndex?: string | null;
|
||||
/* Select the currently focused option when the user presses tab */
|
||||
tabSelectsValue?: boolean;
|
||||
/* The value of the select; reflected by the selected option */
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Type definitions for reactstrap 6.0
|
||||
// Type definitions for reactstrap 6.4
|
||||
// Project: https://github.com/reactstrap/reactstrap#readme
|
||||
// Definitions by: Ali Hammad Baig <https://github.com/alihammad>
|
||||
// Marco Falkenberg <https://github.com/mfal>
|
||||
|
||||
Vendored
+2
@@ -4,6 +4,8 @@ import { CSSModule } from '../index';
|
||||
export type BreadcrumbProps<T = {}> = React.HTMLAttributes<HTMLElement> & {
|
||||
tag?: string;
|
||||
className?: string;
|
||||
listTag?: string;
|
||||
listClassName?: string;
|
||||
cssModule?: CSSModule;
|
||||
} & T;
|
||||
|
||||
|
||||
Vendored
+1
@@ -7,6 +7,7 @@ export type PopoverProps<T = {}> = React.HTMLAttributes<HTMLElement> & {
|
||||
toggle?: () => void;
|
||||
target: string | HTMLElement;
|
||||
container?: string | HTMLElement;
|
||||
boundariesElement?: Popper.Boundary | Element;
|
||||
className?: string;
|
||||
placement?: Popper.Placement;
|
||||
innerClassName?: string;
|
||||
|
||||
Vendored
+97
-101
@@ -1,115 +1,111 @@
|
||||
// Type definitions for shot 3.4
|
||||
// Project: https://github.com/hapijs/shot
|
||||
// Definitions by: AJP <https://github.com/AJamesPhillips>
|
||||
// Simon Schick <https://github.com/SimonSchick>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import stream = require("stream");
|
||||
import http = require("http");
|
||||
import { ServerResponse } from "http";
|
||||
import { Readable, Stream } from "stream";
|
||||
|
||||
interface ShotAPI {
|
||||
/**
|
||||
* Injects a fake request into an HTTP server.
|
||||
* @param dispatchFunc listener function. The same as you would pass to Http.createServer when making a node HTTP server. @see IListener
|
||||
* @param options request options object @see RequestOptions
|
||||
* @param callback the callback function @see Callback
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
inject(dispatchFunc: Shot.Listener, options: Shot.RequestOptions, callback: (res: Shot.ResponseObject) => void): void;
|
||||
/**
|
||||
* Injects a fake request into an HTTP server.
|
||||
* @param dispatchFunc listener function. The same as you would pass to Http.createServer when making a node HTTP server. @see IListener
|
||||
* @param options request options object @see RequestOptions
|
||||
* @param callback the callback function @see Callback
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
export function inject(dispatchFunc: Listener, options: RequestOptions, callback: (res: ResponseObject) => void): void;
|
||||
|
||||
/**
|
||||
* Checks if given object obj is a Shot Request object.
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotisinjectionobj}
|
||||
*/
|
||||
isInjection(obj: any): boolean;
|
||||
/**
|
||||
* Checks if given object obj is a Shot Request object.
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotisinjectionobj}
|
||||
*/
|
||||
export function isInjection(obj: any): boolean;
|
||||
|
||||
/**
|
||||
* listener function. The same as you would pass to Http.createServer when making a node HTTP server. Has the signature function (req, res) where:
|
||||
* * req - a simulated request object. Inherits from Stream.Readable.
|
||||
* * res - a simulated response object. Inherits from node's Http.ServerResponse.
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
export type Listener = (req: SimulatedRequestObject, res: SimulatedResponseObject) => void;
|
||||
|
||||
// disabled for backwards compat
|
||||
// tslint:disable:no-empty-interface
|
||||
|
||||
/**
|
||||
* a simulated request object. Inherits from Stream.Readable.
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
export interface SimulatedRequestObject extends Readable {}
|
||||
|
||||
/**
|
||||
* a simulated response object. Inherits from node's Http.ServerResponse.
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
export interface SimulatedResponseObject extends ServerResponse {}
|
||||
|
||||
// tslint:enable:no-empty-interface
|
||||
|
||||
/**
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
export interface RequestOptions {
|
||||
/** a string specifying the request URL. */
|
||||
url: string;
|
||||
/** a string specifying the HTTP request method, defaulting to 'GET'. */
|
||||
method?: string;
|
||||
/** a string specifying the HTTP HOST header value to be used if no header is provided, and the url does not include an authority component. Defaults to 'localhost'. */
|
||||
authority?: string;
|
||||
/** an optional object containing request headers. */
|
||||
headers?: Headers;
|
||||
/** an optional string specifying the client remote address. Defaults to '127.0.0.1'. */
|
||||
remoteAddress?: string;
|
||||
/** an optional request payload. Can be a string, Buffer, Stream or object. */
|
||||
payload?: string | Buffer | Stream | object;
|
||||
/** an object containing flags to simulate various conditions: */
|
||||
simulate?: {
|
||||
/** indicates whether the request will fire an end event. Defaults to undefined, meaning an end event will fire. */
|
||||
end?: boolean;
|
||||
/** indicates whether the request payload will be split into chunks. Defaults to `undefined`, meaning payload will not be chunked. */
|
||||
split?: boolean;
|
||||
/** whether the request will emit an error event. Defaults to undefined, meaning no error event will be emitted. If set to true, the emitted error will have a message of 'Simulated'. */
|
||||
error?: boolean;
|
||||
/** whether the request will emit a close event. Defaults to undefined, meaning no close event will be emitted. */
|
||||
close?: boolean;
|
||||
};
|
||||
/** Optional flag to validate this options object. Defaults to true. */
|
||||
validate?: boolean;
|
||||
}
|
||||
|
||||
declare namespace Shot {
|
||||
/**
|
||||
* listener function. The same as you would pass to Http.createServer when making a node HTTP server. Has the signature function (req, res) where:
|
||||
* * req - a simulated request object. Inherits from Stream.Readable.
|
||||
* * res - a simulated response object. Inherits from node's Http.ServerResponse.
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
export interface Listener {
|
||||
(req: SimulatedRequestObject, res: SimulatedResponseObject): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* a simulated request object. Inherits from Stream.Readable.
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
interface SimulatedRequestObject extends stream.Readable {}
|
||||
|
||||
/**
|
||||
* a simulated response object. Inherits from node's Http.ServerResponse.
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
interface SimulatedResponseObject extends http.ServerResponse {}
|
||||
|
||||
/**
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
export interface RequestOptions {
|
||||
/** a string specifying the request URL. */
|
||||
url: string;
|
||||
/** a string specifying the HTTP request method, defaulting to 'GET'. */
|
||||
method?: string;
|
||||
/** a string specifying the HTTP HOST header value to be used if no header is provided, and the url does not include an authority component. Defaults to 'localhost'. */
|
||||
authority?: string;
|
||||
/** an optional object containing request headers. */
|
||||
headers?: Headers;
|
||||
/** an optional string specifying the client remote address. Defaults to '127.0.0.1'. */
|
||||
remoteAddress?: string;
|
||||
/** an optional request payload. Can be a string, Buffer, Stream or object. */
|
||||
payload?: string | Buffer | stream.Stream | {[key: string]: any};
|
||||
/** an object containing flags to simulate various conditions: */
|
||||
simulate?: {
|
||||
/** indicates whether the request will fire an end event. Defaults to undefined, meaning an end event will fire. */
|
||||
end?: boolean;
|
||||
/** indicates whether the request payload will be split into chunks. Defaults to `undefined`, meaning payload will not be chunked. */
|
||||
split?: boolean;
|
||||
/** whether the request will emit an error event. Defaults to undefined, meaning no error event will be emitted. If set to true, the emitted error will have a message of 'Simulated'. */
|
||||
error?: boolean;
|
||||
/** whether the request will emit a close event. Defaults to undefined, meaning no close event will be emitted. */
|
||||
close?: boolean;
|
||||
}
|
||||
/** Optional flag to validate this options object. Defaults to true. */
|
||||
validate?: boolean;
|
||||
}
|
||||
|
||||
interface Headers {
|
||||
[header: string]: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
export interface ResponseObject {
|
||||
/** an object containing the raw request and response objects where: */
|
||||
raw: {
|
||||
/** the simulated request object. */
|
||||
req: SimulatedRequestObject;
|
||||
/** the simulated response object. */
|
||||
res: SimulatedResponseObject;
|
||||
};
|
||||
/** an object containing the response headers. */
|
||||
headers: Headers;
|
||||
/** the HTTP status code. */
|
||||
statusCode: number;
|
||||
/** the HTTP status message. */
|
||||
statusMessage: string;
|
||||
/** the payload as a UTF-8 encoded string. */
|
||||
payload: string;
|
||||
/** the raw payload as a Buffer. */
|
||||
rawPayload: Buffer;
|
||||
/** an object containing the response trailers. */
|
||||
trailers: {[index: string]: any};
|
||||
}
|
||||
export interface Headers {
|
||||
[header: string]: string | string[];
|
||||
}
|
||||
|
||||
declare var Shot: ShotAPI;
|
||||
|
||||
export = Shot;
|
||||
/**
|
||||
* @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback}
|
||||
*/
|
||||
export interface ResponseObject {
|
||||
/** an object containing the raw request and response objects where: */
|
||||
raw: {
|
||||
/** the simulated request object. */
|
||||
req: SimulatedRequestObject;
|
||||
/** the simulated response object. */
|
||||
res: SimulatedResponseObject;
|
||||
};
|
||||
/** an object containing the response headers. */
|
||||
headers: Headers;
|
||||
/** the HTTP status code. */
|
||||
statusCode: number;
|
||||
/** the HTTP status message. */
|
||||
statusMessage: string;
|
||||
/** the payload as a UTF-8 encoded string. */
|
||||
payload: string;
|
||||
/** the raw payload as a Buffer. */
|
||||
rawPayload: Buffer;
|
||||
/** an object containing the response trailers. */
|
||||
trailers: {[index: string]: any};
|
||||
}
|
||||
|
||||
@@ -9,10 +9,8 @@ import Shot = require('shot');
|
||||
|
||||
const internals: any = {};
|
||||
|
||||
internals.main = function () {
|
||||
|
||||
const dispatch = function (req: Http.IncomingMessage, res: Http.ServerResponse) {
|
||||
|
||||
internals.main = () => {
|
||||
const dispatch = (req: Http.IncomingMessage, res: Http.ServerResponse) => {
|
||||
const reply = 'Hello World';
|
||||
res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length });
|
||||
res.end(reply);
|
||||
@@ -20,8 +18,7 @@ internals.main = function () {
|
||||
|
||||
const server = Http.createServer(dispatch);
|
||||
|
||||
Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => {
|
||||
|
||||
Shot.inject(dispatch, { method: 'get', url: '/', headers: { test: 'asd', test2: ['a', 'b'] } }, (res) => {
|
||||
console.log(res.payload);
|
||||
});
|
||||
};
|
||||
|
||||
+1
-77
@@ -1,79 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
|
||||
Vendored
+76
@@ -0,0 +1,76 @@
|
||||
// Type definitions for walk 2.3
|
||||
// Project: https://git.coolaj86.com/coolaj86/fs-walk.js
|
||||
// Definitions by: Pontus Östlund <https://github.com/poppa>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Stats } from "fs";
|
||||
|
||||
export interface WalkStats extends Stats {
|
||||
name: string;
|
||||
type: "file"
|
||||
| "directory"
|
||||
| "symbolicLink"
|
||||
| "blockDevice"
|
||||
| "characterDevice"
|
||||
| "FIFO"
|
||||
| "socket";
|
||||
error?: NodeJS.ErrnoException;
|
||||
}
|
||||
|
||||
export interface WalkOptionsListeners {
|
||||
names?: WalkNamesEventCallback;
|
||||
files?: WalkStatArrayEventCallback;
|
||||
file?: WalkStatEventCallback;
|
||||
directories?: WalkStatArrayEventCallback;
|
||||
directory?: WalkStatEventCallback;
|
||||
end?: WalkStatArrayEventCallback;
|
||||
errors?: WalkStatArrayEventCallback;
|
||||
nodeError?: WalkStatArrayEventCallback;
|
||||
directoryError?: WalkStatArrayEventCallback;
|
||||
}
|
||||
|
||||
export interface WalkOptions {
|
||||
followLinks?: boolean;
|
||||
filters?: string[];
|
||||
listeners?: WalkOptionsListeners;
|
||||
}
|
||||
|
||||
export type WalkNext = () => void;
|
||||
|
||||
export type WalkStatEventCallback = (
|
||||
base: string,
|
||||
names: WalkStats,
|
||||
next: WalkNext) => void;
|
||||
|
||||
export type WalkStatArrayEventCallback = (
|
||||
base: string,
|
||||
names: WalkStats[],
|
||||
next: WalkNext) => void;
|
||||
|
||||
export type WalkNamesEventCallback = (
|
||||
base: string,
|
||||
names: string[],
|
||||
next: WalkNext) => void;
|
||||
|
||||
export type WalkStatArrayEvent
|
||||
= 'files'
|
||||
| 'directories'
|
||||
| 'errors'
|
||||
| 'nodeError'
|
||||
| 'directoryError';
|
||||
|
||||
export type WalkStatEvent = 'file' | 'directory';
|
||||
|
||||
export interface Walker {
|
||||
on(event: 'names', cb: WalkNamesEventCallback): void;
|
||||
on(event: WalkStatArrayEvent, cb: WalkStatArrayEventCallback): void;
|
||||
on(event: WalkStatEvent, cb: WalkStatEventCallback): void;
|
||||
on(event: 'end', cb: () => void): void;
|
||||
pause(): void;
|
||||
resume(): void;
|
||||
}
|
||||
|
||||
export function walk(path: string, options?: WalkOptions): Walker;
|
||||
export function walkSync(path: string, options?: WalkOptions): Walker;
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"walk-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,62 @@
|
||||
import * as walk from "walk";
|
||||
|
||||
const options: walk.WalkOptions = {
|
||||
followLinks: true,
|
||||
filters: ['.gitignore'],
|
||||
listeners: {
|
||||
directories: () => { },
|
||||
directory: () => { },
|
||||
directoryError: () => { },
|
||||
end: () => { },
|
||||
errors: () => { },
|
||||
file: () => { },
|
||||
files: () => { },
|
||||
names: () => { },
|
||||
nodeError: () => { }
|
||||
}
|
||||
};
|
||||
|
||||
// $ExpectType Walker
|
||||
const walker = walk.walk('.', options);
|
||||
walker.on('directories', (
|
||||
// $ExpectType string
|
||||
root,
|
||||
// $ExpectType WalkStats[]
|
||||
statsArray,
|
||||
// $ExpectType WalkNext
|
||||
next
|
||||
) => {
|
||||
root.trim();
|
||||
statsArray.forEach((stats) => `${stats.name} (${stats.type})`);
|
||||
next();
|
||||
});
|
||||
|
||||
walker.on('file', (
|
||||
// $ExpectType string
|
||||
root,
|
||||
// $ExpectType WalkStats
|
||||
stats,
|
||||
// $ExpectType WalkNext
|
||||
next
|
||||
) => {
|
||||
// $ExpectError
|
||||
if (stats.type === 'foo') {
|
||||
//
|
||||
}
|
||||
|
||||
switch (stats.type) {
|
||||
case "blockDevice":
|
||||
case "characterDevice":
|
||||
case "directory":
|
||||
case "FIFO":
|
||||
case "file":
|
||||
case "socket":
|
||||
case "symbolicLink":
|
||||
// All good
|
||||
break;
|
||||
}
|
||||
});
|
||||
// $ExpectError
|
||||
walker.on('foo', () => { });
|
||||
walker.pause();
|
||||
walker.resume();
|
||||
Reference in New Issue
Block a user