From 05cbd3509b11ede2affc921e3c5ba607fae42671 Mon Sep 17 00:00:00 2001 From: bumbleblym Date: Fri, 13 Jan 2017 23:08:25 +0800 Subject: [PATCH 1/5] feat: webpack-notifier (#13991) --- webpack-notifier/index.d.ts | 23 ++++++++++++++++++++++ webpack-notifier/tsconfig.json | 20 +++++++++++++++++++ webpack-notifier/tslint.json | 1 + webpack-notifier/webpack-notifier-tests.ts | 14 +++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 webpack-notifier/index.d.ts create mode 100644 webpack-notifier/tsconfig.json create mode 100644 webpack-notifier/tslint.json create mode 100644 webpack-notifier/webpack-notifier-tests.ts diff --git a/webpack-notifier/index.d.ts b/webpack-notifier/index.d.ts new file mode 100644 index 0000000000..8caff77388 --- /dev/null +++ b/webpack-notifier/index.d.ts @@ -0,0 +1,23 @@ +// Type definitions for webpack-notifier 1.5 +// Project: https://github.com/Turbo87/webpack-notifier#readme +// Definitions by: Benjamin Lim +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Plugin, Webpack } from 'webpack'; + +export = WebpackNotifierPlugin; + +declare class WebpackNotifierPlugin implements Plugin { + constructor(options?: WebpackNotifierPlugin.Config); + apply(thisArg: Webpack, ...args: any[]): void; +} + +declare namespace WebpackNotifierPlugin { + export interface Config { + title?: string; + contentImage?: string; + excludeWarnings?: boolean; + alwaysNotify?: boolean; + skipFirstNotification?: boolean; + } +} diff --git a/webpack-notifier/tsconfig.json b/webpack-notifier/tsconfig.json new file mode 100644 index 0000000000..bb80e63baf --- /dev/null +++ b/webpack-notifier/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "webpack-notifier-tests.ts" + ] +} diff --git a/webpack-notifier/tslint.json b/webpack-notifier/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/webpack-notifier/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } diff --git a/webpack-notifier/webpack-notifier-tests.ts b/webpack-notifier/webpack-notifier-tests.ts new file mode 100644 index 0000000000..9ec1dede26 --- /dev/null +++ b/webpack-notifier/webpack-notifier-tests.ts @@ -0,0 +1,14 @@ +import WebpackNotifierPlugin = require('webpack-notifier'); +import { Plugin } from 'webpack'; + +const configs: Array = [ + { + title: 'Webpack', + contentImage: 'logo.png', + excludeWarnings: true, + alwaysNotify: true, + skipFirstNotification: true, + }, +]; + +const plugins: Array = configs.map(config => new WebpackNotifierPlugin(config)); From bd5e86ff2c2ff6e6633d3673d4a1c728a8a40fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Monteiro?= Date: Fri, 13 Jan 2017 15:11:57 +0000 Subject: [PATCH 2/5] Added angular-gridster definitions (#13961) * added angular-gridster definitions * stripped out bom * fixed index.d.ts based on travis * fixed interfaces name on test file --- angular-gridster/angular-gridster-tests.ts | 27 ++++ angular-gridster/index.d.ts | 145 +++++++++++++++++++++ angular-gridster/tsconfig.json | 20 +++ angular-gridster/tslint.json | 1 + 4 files changed, 193 insertions(+) create mode 100644 angular-gridster/angular-gridster-tests.ts create mode 100644 angular-gridster/index.d.ts create mode 100644 angular-gridster/tsconfig.json create mode 100644 angular-gridster/tslint.json diff --git a/angular-gridster/angular-gridster-tests.ts b/angular-gridster/angular-gridster-tests.ts new file mode 100644 index 0000000000..7333a20f4d --- /dev/null +++ b/angular-gridster/angular-gridster-tests.ts @@ -0,0 +1,27 @@ +import * as ng from "angular"; +import * as angular from "angular"; + +import gridster from "angular-gridster"; + +var myApp = angular.module("testModule", ["gridster"]); + +// configure gridster's global options +myApp.run(["gridsterConfig", (gridsterConfig: angular.gridster.GridsterConfig) => { + + gridsterConfig.mobileBreakPoint = 697; + gridsterConfig.colWidth = "100"; + gridsterConfig.rowHeight = "100"; + gridsterConfig.minColumns = 1; + gridsterConfig.columns = 20; + gridsterConfig.margins = [5, 5]; + gridsterConfig.minSizeX = 2; + gridsterConfig.minSizeY = 2; + gridsterConfig.outerMargin = true; + gridsterConfig.pushing = true; + gridsterConfig.floating = true; + gridsterConfig.swapping = true; + gridsterConfig.draggable = { enabled: true}; + gridsterConfig.resizable = { enabled: true, + handles: ["n", "s", "e", "w", "ne", "se", "sw", "nw"]}; + } +]); \ No newline at end of file diff --git a/angular-gridster/index.d.ts b/angular-gridster/index.d.ts new file mode 100644 index 0000000000..de60d6377b --- /dev/null +++ b/angular-gridster/index.d.ts @@ -0,0 +1,145 @@ +// Type definitions for angular-gridster (gridster module) 0.13 +// Project: https://github.com/ManifestWebDesign/angular-gridster +// Definitions by: Joao Monteiro +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as angular from "angular"; + +export default "gridster"; + +declare module "angular" { + + export namespace gridster { + + interface GridsterConfig { + + // number of columns in the grid + columns?: number; + // whether to push other items out of the way + + // whether to push other items out of the way + pushing?: boolean; + + // whether to automatically float items up so they stack + floating?: boolean; + + // whether or not to have items switch places instead of push down if they are the same size + swapping?: boolean; + + // width of the grid. "auto" will expand the grid to its parent container + width?: string; + + // width of grid columns. "auto" will divide the width of the grid evenly among the columns + colWidth?: string; + + // height of grid rows. 'match' will make it the same as the column width, a numeric value will be interpreted as pixels, + // '/2' is half the column width, '*5' is five times the column width, etc. + rowHeight?: string; + + // margins in between grid items + margins?: number[]; + + // whether to set the outer margin + outerMargin?: boolean; + + // toggle mobile view + isMobile?: boolean; + + // width threshold to toggle mobile mode + mobileBreakPoint?: number; + + // whether or not to toggle mobile mode when screen width is less than mobileBreakPoint + mobileModeEnabled?: boolean; + + // minimum amount of columns the grid can scale down to + minColumns?: number; + + // minimum amount of rows to show if the grid is empty + minRows?: number; + + // maximum amount of rows in the grid + maxRows?: number; + + // default width of an item in columns + defaultSizeX?: number; + + // default height of an item in rows + defaultSizeY?: number; + + // minimum column width of an item + minSizeX?: number; + + // maximum column width of an item + maxSizeX?: number; + + // minumum row height of an item + minSizeY?: number; + + // maximum row height of an item + maxSizeY?: number; + + saveGridItemCalculatedHeightInMobile?: boolean; + // grid item height in mobile display. true- to use the calculated height by sizeY given + + // options to pass to resizable handler + resizable?: { + + // whether the items are resizable + enabled?: boolean; + + // location of the resize handles + // e.g // ['s', 'e', 'n', 'w', 'se', 'ne', 'sw', 'nw'] + handles?: string[]; + + // optional callback fired when drag is started + start?(event: angular.IAngularEvent, $element: angular.IAugmentedJQuery, options: any): void; + + // optional callback fired when item is resized + resize?(event: angular.IAngularEvent, $element: angular.IAugmentedJQuery, options: any): void; + + // optional callback fired when item is finished dragging + stop?(event: angular.IAngularEvent, $element: angular.IAugmentedJQuery, options: any): void; + }; + + // options to pass to draggable handler + draggable?: { + + // whether the items are resizable + enabled?: boolean; + + // Distance in pixels from the edge of the viewport after which the viewport should scroll, relative to pointer + scrollSensitivity?: number; + + // Speed at which the window should scroll once the mouse pointer gets within scrollSensitivity distance + scrollSpeed?: number; + + // optional selector for drag handle + handle?: string; + + // optional callback fired when drag is started + start?(event: angular.IAngularEvent, $element: angular.IAugmentedJQuery, options: any): void; + + // optional callback fired when item is moved, + drag?(event: angular.IAngularEvent, $element: angular.IAugmentedJQuery, options: any): void; + + // optional callback fired when item is finished dragging + stop?(event: angular.IAngularEvent, $element: angular.IAugmentedJQuery, options: any): void; + }; + } + + interface StandardGridsterItem { + + // width of the item expressed in terms of number of columns it will occupy + sizeX: number; + + // height of the item expressed in terms of number of rows it will occupy + sizeY: number; + + // starting row where the item will be placed + row: number; + + // starting column where the item will be placed + col: number; + } + } +} \ No newline at end of file diff --git a/angular-gridster/tsconfig.json b/angular-gridster/tsconfig.json new file mode 100644 index 0000000000..ad0a51b48f --- /dev/null +++ b/angular-gridster/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "angular-gridster-tests.ts" + ] +} \ No newline at end of file diff --git a/angular-gridster/tslint.json b/angular-gridster/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/angular-gridster/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file From a1abf4fd44d411c689300f1c9fa99dc83e4de091 Mon Sep 17 00:00:00 2001 From: Young Rok Kim Date: Sat, 14 Jan 2017 00:18:45 +0900 Subject: [PATCH 3/5] [history] update to v4.5 (#13744) * [history] update to v4.5 - move legacy history to v2 folder - fix dependent packages' package.json file to use legacy history v2 * [history] change dependents to support old history * [history] fix updated dependents --- history/DOMUtils.d.ts | 6 + history/ExecutionEnvironment.d.ts | 1 + history/LocationUtils.d.ts | 5 + history/PathUtils.d.ts | 7 + history/createBrowserHistory.d.ts | 11 ++ history/createHashHistory.d.ts | 12 ++ history/createMemoryHistory.d.ts | 17 +++ history/createTransitionManager.d.ts | 15 ++ history/history-tests.ts | 136 ++++++++--------- history/index.d.ts | 142 ++++++------------ history/tsconfig.json | 19 ++- history/v2/history-tests.ts | 131 ++++++++++++++++ history/v2/index.d.ts | 138 +++++++++++++++++ history/{ => v2}/lib/DOMUtils.d.ts | 0 history/{ => v2}/lib/actions.d.ts | 0 .../{ => v2}/lib/createBrowserHistory.d.ts | 0 history/{ => v2}/lib/createHashHistory.d.ts | 0 history/{ => v2}/lib/createLocation.d.ts | 0 history/{ => v2}/lib/createMemoryHistory.d.ts | 0 history/{ => v2}/lib/useBasename.d.ts | 0 history/{ => v2}/lib/useBeforeUnload.d.ts | 0 history/{ => v2}/lib/useQueries.d.ts | 0 history/v2/tsconfig.json | 33 ++++ react-breadcrumbs/tsconfig.json | 5 +- react-i18next/tsconfig.json | 6 +- react-router-bootstrap/tsconfig.json | 7 +- react-router-redux/package.json | 2 +- react-router-redux/tsconfig.json | 3 + react-router-redux/v3/tsconfig.json | 5 +- react-router/tsconfig.json | 7 +- redux-bootstrap/package.json | 2 +- redux-bootstrap/tsconfig.json | 5 +- redux-router/package.json | 2 +- redux-router/tsconfig.json | 5 +- 34 files changed, 531 insertions(+), 191 deletions(-) create mode 100644 history/DOMUtils.d.ts create mode 100644 history/ExecutionEnvironment.d.ts create mode 100644 history/LocationUtils.d.ts create mode 100644 history/PathUtils.d.ts create mode 100644 history/createBrowserHistory.d.ts create mode 100644 history/createHashHistory.d.ts create mode 100644 history/createMemoryHistory.d.ts create mode 100644 history/createTransitionManager.d.ts create mode 100644 history/v2/history-tests.ts create mode 100644 history/v2/index.d.ts rename history/{ => v2}/lib/DOMUtils.d.ts (100%) rename history/{ => v2}/lib/actions.d.ts (100%) rename history/{ => v2}/lib/createBrowserHistory.d.ts (100%) rename history/{ => v2}/lib/createHashHistory.d.ts (100%) rename history/{ => v2}/lib/createLocation.d.ts (100%) rename history/{ => v2}/lib/createMemoryHistory.d.ts (100%) rename history/{ => v2}/lib/useBasename.d.ts (100%) rename history/{ => v2}/lib/useBeforeUnload.d.ts (100%) rename history/{ => v2}/lib/useQueries.d.ts (100%) create mode 100644 history/v2/tsconfig.json diff --git a/history/DOMUtils.d.ts b/history/DOMUtils.d.ts new file mode 100644 index 0000000000..7ec86d00c9 --- /dev/null +++ b/history/DOMUtils.d.ts @@ -0,0 +1,6 @@ +export const isExtraneousPopstateEvent: boolean; +export function addEventListener(node: EventTarget, event: string, listener: EventListenerOrEventListenerObject): void; +export function removeEventListener(node: EventTarget, event: string, listener: EventListenerOrEventListenerObject): void; +export function getConfirmation(message: string, callback: (result: boolean) => void): void; +export function supportsHistory(): boolean; +export function supportsGoWithoutReloadUsingHash(): boolean; diff --git a/history/ExecutionEnvironment.d.ts b/history/ExecutionEnvironment.d.ts new file mode 100644 index 0000000000..ac15888726 --- /dev/null +++ b/history/ExecutionEnvironment.d.ts @@ -0,0 +1 @@ +export const canUseDOM: boolean; diff --git a/history/LocationUtils.d.ts b/history/LocationUtils.d.ts new file mode 100644 index 0000000000..d78332e57c --- /dev/null +++ b/history/LocationUtils.d.ts @@ -0,0 +1,5 @@ +import { Path, LocationState, LocationKey, Location, LocationDescriptor } from './index'; + +export function locationsAreEqual(lv: LocationDescriptor, rv: LocationDescriptor): boolean; +export function createLocation(options: LocationDescriptor): Location; +export function createLocation(path: Path, state?: LocationState, key?: LocationKey, currentLocation?: Location): Location; diff --git a/history/PathUtils.d.ts b/history/PathUtils.d.ts new file mode 100644 index 0000000000..7ea7ed75a4 --- /dev/null +++ b/history/PathUtils.d.ts @@ -0,0 +1,7 @@ +import { Path, Location, LocationDescriptor } from './index'; + +export function addLeadingSlash(path: Path): Path; +export function stripLeadingSlash(path: Path): Path; +export function stripPrefix(path: Path, prefix: string): Path; +export function parsePath(path: Path): Location; +export function createPath(location: LocationDescriptor): Path; diff --git a/history/createBrowserHistory.d.ts b/history/createBrowserHistory.d.ts new file mode 100644 index 0000000000..0f3051ca3d --- /dev/null +++ b/history/createBrowserHistory.d.ts @@ -0,0 +1,11 @@ +import { History } from './index'; +import { getConfirmation } from './DOMUtils'; + +export interface BrowserHistoryBuildOptions { + basename?: string; + forceRefresh?: boolean; + getUserConfirmation?: typeof getConfirmation; + keyLength?: number; +} + +export default function createBrowserHistory(options?: BrowserHistoryBuildOptions): History; diff --git a/history/createHashHistory.d.ts b/history/createHashHistory.d.ts new file mode 100644 index 0000000000..5ae61557e4 --- /dev/null +++ b/history/createHashHistory.d.ts @@ -0,0 +1,12 @@ +import { History } from './index'; +import { getConfirmation } from './DOMUtils'; + +export type HashType = 'hashbang' | 'noslash' | 'slash'; + +export interface HashHistoryBuildOptions { + basename?: string; + hashType?: HashType; + getUserConfirmation?: typeof getConfirmation; +} + +export default function createHashHistory(options?: HashHistoryBuildOptions): History; diff --git a/history/createMemoryHistory.d.ts b/history/createMemoryHistory.d.ts new file mode 100644 index 0000000000..e1aca026e2 --- /dev/null +++ b/history/createMemoryHistory.d.ts @@ -0,0 +1,17 @@ +import { History, Location } from './index'; +import { getConfirmation } from './DOMUtils'; + +export interface MemoryHistoryBuildOptions { + getUserConfirmation?: typeof getConfirmation; + initialEntries?: string[]; + initialIndex?: number; + keyLength?: number; +} + +export interface MemoryHistory extends History { + index: number; + entries: Location[]; + canGo(n: number): boolean; +} + +export default function createMemoryHistory(options?: MemoryHistoryBuildOptions): MemoryHistory; diff --git a/history/createTransitionManager.d.ts b/history/createTransitionManager.d.ts new file mode 100644 index 0000000000..5294544a18 --- /dev/null +++ b/history/createTransitionManager.d.ts @@ -0,0 +1,15 @@ +import { Location, Action, LocationListener, UnregisterCallback } from './index'; +import { getConfirmation } from './DOMUtils'; + +export type PromptFunction = (location: Location, action: Action) => any; + +export type Prompt = PromptFunction | boolean; + +export interface TransitionManager { + setPrompt(nextPrompt?: Prompt): UnregisterCallback; + appendListener(listener: LocationListener): UnregisterCallback; + notifyListeners(location: Location, action: Action): void; + confirmTransitionTo(location: Location, action: Action, getUserConfirmation: typeof getConfirmation, callback: (result: boolean) => void): void; +} + +export default function createTransitionManager(): TransitionManager; diff --git a/history/history-tests.ts b/history/history-tests.ts index 1d6565838e..4cb788f806 100644 --- a/history/history-tests.ts +++ b/history/history-tests.ts @@ -1,31 +1,28 @@ -import { createHistory, createLocation, useBasename, useBeforeUnload, useQueries } from 'history' +import { createBrowserHistory, createMemoryHistory, createHashHistory, createLocation, Location } from 'history'; +import * as LocationUtils from 'history/LocationUtils'; +import * as PathUtils from 'history/PathUtils'; +import * as DOMUtils from 'history/DOMUtils'; +import * as ExecutionEnvironment from 'history/ExecutionEnvironment'; -import { getUserConfirmation } from 'history/lib/DOMUtils' - -interface Promise { - then(onfulfilled?: (value: T) => TResult): Promise; -} - -let doSomethingAsync: () => Promise; let input = { value: "" }; { - let history = createHistory() + let history = createBrowserHistory(); // Listen for changes to the current location. The // listener is called once immediately. - let unlisten = history.listen(function(location) { - console.log(location.pathname) - }) + let unlisten = history.listen(function (location) { + console.log(location.pathname); + }); // When you're finished, stop the listener. - unlisten() + unlisten(); // Push a new entry onto the history stack. - history.push('/home') + history.push('/home'); // Replace the current entry on the history stack. - history.replace('/profile') + history.replace('/profile'); // Push a new entry with state onto the history stack. history.push({ @@ -35,97 +32,90 @@ let input = { value: "" }; }); // Change just the search on an existing location. - //history.push({ ...location, search: '?the=other+search' }) + history.push({ pathname: location.pathname, search: '?the=other+search' }); // Go back to the previous history entry. The following // two lines are synonymous. - history.go(-1) - history.goBack() + history.go(-1); + history.goBack(); - let href = history.createHref('/the/path') + let href = history.createHref({ pathname: '/the/path' }); } { - let history = createHistory() + let history = createMemoryHistory(); // Pushing a path string. - history.push('/the/path') + history.push('/the/path'); // Omitting location state when pushing a location descriptor. - history.push({ pathname: '/the/path', search: '?the=search' }) + history.push({ pathname: '/the/path', search: '?the=search' }); + + let location = createLocation('/a/path?a=query', { the: 'state' }); // Extending an existing location object. - //history.push({ ...location, search: '?other=search' }) + history.push({ pathname: location.pathname, search: '?other=search' }); - let location = createLocation('/a/path?a=query', { the: 'state' }) + if (history.canGo(-1)) { + history.go(-1); + history.goBack(); + } - location = history.createLocation('/a/path?a=query', { the: 'state' }) + let unblock = history.block(true); + unblock(); + + history.entries.forEach(function (location) { + let typedLocation: Location = location; + }); } { - let history = createHistory() - history.listenBefore(function(location) { - if (input.value !== '') - return 'Are you sure you want to leave this page?' - }) + let history = createHashHistory() + history.listen(function (location) { + if (input.value !== '') { + return 'Are you sure you want to leave this page?'; + } + }); - history.listenBefore(function(location, callback) { - doSomethingAsync().then(callback) - }) + history.listen(function (location, action) { + if (typeof action === 'string') { + console.log(action); + } + }); } { - let history = createHistory({ + let history = createBrowserHistory({ + basename: 'base', + keyLength: 10, + forceRefresh: false, getUserConfirmation(message, callback) { - callback(window.confirm(message)) // The default behavior + callback(window.confirm(message)); // The default behavior } - }) + }); } { - let history = useBeforeUnload(createHistory)() - - history.listenBeforeUnload(function() { - return 'Are you sure you want to leave this page?' - }) + let location1 = LocationUtils.createLocation('path/1', { state: 1 }); + let location2 = LocationUtils.createLocation({ pathname: 'pathname', state: 2 }); + LocationUtils.locationsAreEqual(location1, location2); } { - let history = useQueries(createHistory)() - - history.listen(function(location) { - console.log(location.query) - }) + let path = PathUtils.createPath({ pathname: '/a/path', hash: '#hash' }); + let strippedPath = PathUtils.stripPrefix(path, '/a/'); + let location = PathUtils.parsePath(strippedPath); } { - let history = useQueries(createHistory)({ - parseQueryString: function(queryString) { - // TODO: return a parsed version of queryString - return {}; - }, - stringifyQuery: function(query) { - // TODO: return a query string created from query - return ""; - } - }) - - history.createPath({ pathname: '/the/path', query: { the: 'query' } }) - history.push({ pathname: '/the/path', query: { the: 'query' } }) + let eventTarget: EventTarget; + DOMUtils.addEventListener(eventTarget, 'onload', function (event) { event.preventDefault(); }); + DOMUtils.removeEventListener(eventTarget, 'onload', function (event) { event.preventDefault(); }); + DOMUtils.getConfirmation('confirm?', (result) => console.log(result)); + let booleanValues = DOMUtils.supportsGoWithoutReloadUsingHash() && DOMUtils.supportsHistory(); } { - // Run our app under the /base URL. - let history = useBasename(createHistory)({ - basename: '/base' - }) - - // At the /base/hello/world URL: - history.listen(function(location) { - console.log(location.pathname) // /hello/world - console.log(location.basename) // /base - }) - - history.createPath('/the/path') // /base/the/path - history.push('/the/path') // push /base/the/path -} \ No newline at end of file + let supportsDOM = ExecutionEnvironment.canUseDOM; + let isExtraneousPopstateEvent = DOMUtils.isExtraneousPopstateEvent; +} diff --git a/history/index.d.ts b/history/index.d.ts index 6b61fa1b77..a45b930efe 100644 --- a/history/index.d.ts +++ b/history/index.d.ts @@ -1,138 +1,90 @@ -// Type definitions for history v2.0.0 +// Type definitions for history 4.5 // Project: https://github.com/mjackson/history -// Definitions by: Sergey Buturlakin , Nathan Brown +// Definitions by: Sergey Buturlakin , Nathan Brown , Young Rok Kim // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - export as namespace History; -export type Action = string; -export type BeforeUnloadHook = () => string | boolean; -export type CreateHistory = (options?: HistoryOptions) => T; -export type CreateHistoryEnhancer = (createHistory: CreateHistory) => CreateHistory; +export type Action = 'PUSH' | 'POP' | 'REPLACE'; +export type UnregisterCallback = () => void; export interface History { - listenBefore(hook: TransitionHook): () => void; - listen(listener: LocationListener): () => void; - transitionTo(location: Location): void; - push(path: LocationDescriptor): void; - replace(path: LocationDescriptor): void; + length: number; + action: Action; + location: Location; + push(path: Path, state?: LocationState): void; + push(location: LocationDescriptorObject): void; + replace(path: Path, state?: LocationState): void; + replace(location: LocationDescriptorObject): void; go(n: number): void; goBack(): void; goForward(): void; - createKey(): LocationKey; - createPath(path: LocationDescriptor): Path; - createHref(path: LocationDescriptor): Href; - createLocation(path?: LocationDescriptor, action?: Action, key?: LocationKey): Location; - getCurrentLocation: () => Location - - /** @deprecated use a location descriptor instead */ - createLocation(path?: Path, state?: LocationState, action?: Action, key?: LocationKey): Location; - /** @deprecated use location.key to save state instead */ - pushState(state: LocationState, path: Path): void; - /** @deprecated use location.key to save state instead */ - replaceState(state: LocationState, path: Path): void; - /** @deprecated use location.key to save state instead */ - setState(state: LocationState): void; - /** @deprecated use listenBefore instead */ - registerTransitionHook(hook: TransitionHook): void; - /** @deprecated use the callback returned from listenBefore instead */ - unregisterTransitionHook(hook: TransitionHook): void; + block(prompt?: boolean): UnregisterCallback; + listen(listener: LocationListener): UnregisterCallback; + createHref(location: Path | LocationDescriptorObject): Href; } -export type HistoryOptions = { - getCurrentLocation?: () => Location; - finishTransition?: (nextLocation: Location) => boolean; - saveState?: (key: LocationKey, state: LocationState) => void; - go?: (n: number) => void; - getUserConfirmation?: (message: string, callback: (result: boolean) => void) => void; - keyLength?: number; - queryKey?: string | boolean; - stringifyQuery?: (obj: any) => string; - parseQueryString?: (str: string) => any; - basename?: string; - entries?: string | [any]; - current?: number; -} - -export type Location = { +export interface Location { pathname: Pathname; search: Search; - query: Query; state: LocationState; - action: Action; + hash: Hash; key: LocationKey; - basename?: string; -}; +} -export type LocationDescriptorObject = { +export interface LocationDescriptorObject { pathname?: Pathname; search?: Search; - query?: Query; state?: LocationState; -}; + hash?: Hash; + key?: LocationKey; +} export namespace History { - export type LocationDescriptor = LocationDescriptorObject | Path; + export type LocationDescriptor = Path | LocationDescriptorObject; export type LocationKey = string; - export type LocationListener = (location: Location) => void; - export type LocationState = Object; - export type Path = string // Pathname + QueryString; + export type LocationListener = (location: Location, action: Action) => void; + export type LocationState = any; + export type Path = string; export type Pathname = string; - export type Query = Object; - export type QueryString = string; export type Search = string; - export type TransitionHook = (location: Location, callback: (result: any) => void) => any + export type TransitionHook = (location: Location, callback: (result: any) => void) => any; + export type Hash = string; export type Href = string; } -// Back-compat aliases + export type LocationDescriptor = History.LocationDescriptor; export type LocationKey = History.LocationKey; export type LocationListener = History.LocationListener; export type LocationState = History.LocationState; export type Path = History.Path; export type Pathname = History.Pathname; -export type Query = History.Query; -export type QueryString = History.QueryString; export type Search = History.Search; export type TransitionHook = History.TransitionHook; +export type Hash = History.Hash; export type Href = History.Href; -export interface HistoryBeforeUnload { - listenBeforeUnload(hook: BeforeUnloadHook): () => void; -} - -export interface HistoryQueries { - pushState(state: LocationState, pathname: Pathname | Path, query?: Query): void; - replaceState(state: LocationState, pathname: Pathname | Path, query?: Query): void; - createPath(path: Path, query?: Query): Path; - createHref(path: Path, query?: Query): Href; -} - +import { default as createBrowserHistory } from "./createBrowserHistory"; +import { default as createHashHistory } from "./createHashHistory"; +import { default as createMemoryHistory } from "./createMemoryHistory"; +import { createLocation, locationsAreEqual } from "./LocationUtils"; +import { parsePath, createPath } from "./PathUtils"; // Global usage, without modules, needs the small trick, because lib.d.ts // already has `history` and `History` global definitions: // var createHistory = ((window as any).History as HistoryModule.Module).createHistory; export interface Module { - createHistory: CreateHistory; - createHashHistory: CreateHistory; - createMemoryHistory: CreateHistory; - createLocation(path?: Path, state?: LocationState, action?: Action, key?: LocationKey): Location; - useBasename(createHistory: CreateHistory): CreateHistory; - useBeforeUnload(createHistory: CreateHistory): CreateHistory; - useQueries(createHistory: CreateHistory): CreateHistory; - actions: { - PUSH: string; - REPLACE: string; - POP: string; - }; + createBrowserHistory: typeof createBrowserHistory; + createHashHistory: typeof createHashHistory; + createMemoryHistory: typeof createMemoryHistory; + createLocation: typeof createLocation; + locationsAreEqual: typeof locationsAreEqual; + parsePath: typeof parsePath; + createPath: typeof createPath; } -export { default as createHistory } from "./lib/createBrowserHistory"; -export { default as createHashHistory } from "./lib/createHashHistory"; -export { default as createMemoryHistory } from "./lib/createMemoryHistory"; -export { default as createLocation } from "./lib/createLocation"; -export { default as useBasename } from "./lib/useBasename"; -export { default as useBeforeUnload } from "./lib/useBeforeUnload"; -export { default as useQueries } from "./lib/useQueries"; -import * as Actions from "./lib/actions"; -export { Actions }; +export * from "./createBrowserHistory"; +export * from "./createHashHistory"; +export * from "./createMemoryHistory"; +export { createLocation, locationsAreEqual } from "./LocationUtils"; +export { parsePath, createPath } from "./PathUtils"; +export { createBrowserHistory, createHashHistory, createMemoryHistory }; diff --git a/history/tsconfig.json b/history/tsconfig.json index 87a547edfd..76df1a3976 100644 --- a/history/tsconfig.json +++ b/history/tsconfig.json @@ -16,14 +16,13 @@ "files": [ "index.d.ts", "history-tests.ts", - "lib/actions.d.ts", - "lib/createBrowserHistory.d.ts", - "lib/createHashHistory.d.ts", - "lib/createLocation.d.ts", - "lib/createMemoryHistory.d.ts", - "lib/DOMUtils.d.ts", - "lib/useBasename.d.ts", - "lib/useBeforeUnload.d.ts", - "lib/useQueries.d.ts" + "createBrowserHistory.d.ts", + "createMemoryHistory.d.ts", + "createHashHistory.d.ts", + "createTransitionManager.d.ts", + "DOMUtils.d.ts", + "ExecutionEnvironment.d.ts", + "LocationUtils.d.ts", + "PathUtils.d.ts" ] -} \ No newline at end of file +} diff --git a/history/v2/history-tests.ts b/history/v2/history-tests.ts new file mode 100644 index 0000000000..454b223e09 --- /dev/null +++ b/history/v2/history-tests.ts @@ -0,0 +1,131 @@ +import { createBrowserHistory, createLocation, useBasename, useBeforeUnload, useQueries } from 'history' + +import { getUserConfirmation } from 'history/lib/DOMUtils' + +interface Promise { + then(onfulfilled?: (value: T) => TResult): Promise; +} + +let doSomethingAsync: () => Promise; +let input = { value: "" }; + +{ + let history = createBrowserHistory() + + // Listen for changes to the current location. The + // listener is called once immediately. + let unlisten = history.listen(function(location) { + console.log(location.pathname) + }) + + // When you're finished, stop the listener. + unlisten() + + // Push a new entry onto the history stack. + history.push('/home') + + // Replace the current entry on the history stack. + history.replace('/profile') + + // Push a new entry with state onto the history stack. + history.push({ + pathname: '/about', + search: '?the=search', + state: { some: 'state' } + }); + + // Change just the search on an existing location. + //history.push({ ...location, search: '?the=other+search' }) + + // Go back to the previous history entry. The following + // two lines are synonymous. + history.go(-1) + history.goBack() + + let href = history.createHref('/the/path') +} + +{ + let history = createBrowserHistory() + + // Pushing a path string. + history.push('/the/path') + + // Omitting location state when pushing a location descriptor. + history.push({ pathname: '/the/path', search: '?the=search' }) + + // Extending an existing location object. + //history.push({ ...location, search: '?other=search' }) + + let location = createLocation('/a/path?a=query', { the: 'state' }) + + location = history.createLocation('/a/path?a=query', { the: 'state' }) +} + +{ + let history = createBrowserHistory() + history.listenBefore(function(location) { + if (input.value !== '') + return 'Are you sure you want to leave this page?' + }) + + history.listenBefore(function(location, callback) { + doSomethingAsync().then(callback) + }) +} + +{ + let history = createBrowserHistory({ + getUserConfirmation(message, callback) { + callback(window.confirm(message)) // The default behavior + } + }) +} + +{ + let history = useBeforeUnload(createBrowserHistory)() + + history.listenBeforeUnload(function() { + return 'Are you sure you want to leave this page?' + }) +} + +{ + let history = useQueries(createBrowserHistory)() + + history.listen(function(location) { + console.log(location.query) + }) +} + +{ + let history = useQueries(createBrowserHistory)({ + parseQueryString: function(queryString) { + // TODO: return a parsed version of queryString + return {}; + }, + stringifyQuery: function(query) { + // TODO: return a query string created from query + return ""; + } + }) + + history.createPath({ pathname: '/the/path', query: { the: 'query' } }) + history.push({ pathname: '/the/path', query: { the: 'query' } }) +} + +{ + // Run our app under the /base URL. + let history = useBasename(createBrowserHistory)({ + basename: '/base' + }) + + // At the /base/hello/world URL: + history.listen(function(location) { + console.log(location.pathname) // /hello/world + console.log(location.basename) // /base + }) + + history.createPath('/the/path') // /base/the/path + history.push('/the/path') // push /base/the/path +} \ No newline at end of file diff --git a/history/v2/index.d.ts b/history/v2/index.d.ts new file mode 100644 index 0000000000..5f719c2f0b --- /dev/null +++ b/history/v2/index.d.ts @@ -0,0 +1,138 @@ +// Type definitions for history v2.0.0 +// Project: https://github.com/mjackson/history +// Definitions by: Sergey Buturlakin , Nathan Brown +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace History; + +export type Action = string; +export type BeforeUnloadHook = () => string | boolean; +export type CreateHistory = (options?: HistoryOptions) => T; +export type CreateHistoryEnhancer = (createHistory: CreateHistory) => CreateHistory; + +export interface History { + listenBefore(hook: TransitionHook): () => void; + listen(listener: LocationListener): () => void; + transitionTo(location: Location): void; + push(path: LocationDescriptor): void; + replace(path: LocationDescriptor): void; + go(n: number): void; + goBack(): void; + goForward(): void; + createKey(): LocationKey; + createPath(path: LocationDescriptor): Path; + createHref(path: LocationDescriptor): Href; + createLocation(path?: LocationDescriptor, action?: Action, key?: LocationKey): Location; + getCurrentLocation: () => Location + + /** @deprecated use a location descriptor instead */ + createLocation(path?: Path, state?: LocationState, action?: Action, key?: LocationKey): Location; + /** @deprecated use location.key to save state instead */ + pushState(state: LocationState, path: Path): void; + /** @deprecated use location.key to save state instead */ + replaceState(state: LocationState, path: Path): void; + /** @deprecated use location.key to save state instead */ + setState(state: LocationState): void; + /** @deprecated use listenBefore instead */ + registerTransitionHook(hook: TransitionHook): void; + /** @deprecated use the callback returned from listenBefore instead */ + unregisterTransitionHook(hook: TransitionHook): void; +} + +export type HistoryOptions = { + getCurrentLocation?: () => Location; + finishTransition?: (nextLocation: Location) => boolean; + saveState?: (key: LocationKey, state: LocationState) => void; + go?: (n: number) => void; + getUserConfirmation?: (message: string, callback: (result: boolean) => void) => void; + keyLength?: number; + queryKey?: string | boolean; + stringifyQuery?: (obj: any) => string; + parseQueryString?: (str: string) => any; + basename?: string; + entries?: string | [any]; + current?: number; +} + +export type Location = { + pathname: Pathname; + search: Search; + query: Query; + state: LocationState; + action: Action; + key: LocationKey; + basename?: string; +}; + +export type LocationDescriptorObject = { + pathname?: Pathname; + search?: Search; + query?: Query; + state?: LocationState; +}; + +export namespace History { + export type LocationDescriptor = LocationDescriptorObject | Path; + export type LocationKey = string; + export type LocationListener = (location: Location) => void; + export type LocationState = Object; + export type Path = string // Pathname + QueryString; + export type Pathname = string; + export type Query = Object; + export type QueryString = string; + export type Search = string; + export type TransitionHook = (location: Location, callback: (result: any) => void) => any + export type Href = string; +} +// Back-compat aliases +export type LocationDescriptor = History.LocationDescriptor; +export type LocationKey = History.LocationKey; +export type LocationListener = History.LocationListener; +export type LocationState = History.LocationState; +export type Path = History.Path; +export type Pathname = History.Pathname; +export type Query = History.Query; +export type QueryString = History.QueryString; +export type Search = History.Search; +export type TransitionHook = History.TransitionHook; +export type Href = History.Href; + +export interface HistoryBeforeUnload { + listenBeforeUnload(hook: BeforeUnloadHook): () => void; +} + +export interface HistoryQueries { + pushState(state: LocationState, pathname: Pathname | Path, query?: Query): void; + replaceState(state: LocationState, pathname: Pathname | Path, query?: Query): void; + createPath(path: Path, query?: Query): Path; + createHref(path: Path, query?: Query): Href; +} + + +// Global usage, without modules, needs the small trick, because lib.d.ts +// already has `history` and `History` global definitions: +// var createHistory = ((window as any).History as HistoryModule.Module).createHistory; +export interface Module { + createHistory: CreateHistory; + createHashHistory: CreateHistory; + createMemoryHistory: CreateHistory; + createLocation(path?: Path, state?: LocationState, action?: Action, key?: LocationKey): Location; + useBasename(createHistory: CreateHistory): CreateHistory; + useBeforeUnload(createHistory: CreateHistory): CreateHistory; + useQueries(createHistory: CreateHistory): CreateHistory; + actions: { + PUSH: string; + REPLACE: string; + POP: string; + }; +} + +export { default as createBrowserHistory } from "./lib/createBrowserHistory"; +export { default as createHashHistory } from "./lib/createHashHistory"; +export { default as createMemoryHistory } from "./lib/createMemoryHistory"; +export { default as createLocation } from "./lib/createLocation"; +export { default as useBasename } from "./lib/useBasename"; +export { default as useBeforeUnload } from "./lib/useBeforeUnload"; +export { default as useQueries } from "./lib/useQueries"; +import * as Actions from "./lib/actions"; +export { Actions }; diff --git a/history/lib/DOMUtils.d.ts b/history/v2/lib/DOMUtils.d.ts similarity index 100% rename from history/lib/DOMUtils.d.ts rename to history/v2/lib/DOMUtils.d.ts diff --git a/history/lib/actions.d.ts b/history/v2/lib/actions.d.ts similarity index 100% rename from history/lib/actions.d.ts rename to history/v2/lib/actions.d.ts diff --git a/history/lib/createBrowserHistory.d.ts b/history/v2/lib/createBrowserHistory.d.ts similarity index 100% rename from history/lib/createBrowserHistory.d.ts rename to history/v2/lib/createBrowserHistory.d.ts diff --git a/history/lib/createHashHistory.d.ts b/history/v2/lib/createHashHistory.d.ts similarity index 100% rename from history/lib/createHashHistory.d.ts rename to history/v2/lib/createHashHistory.d.ts diff --git a/history/lib/createLocation.d.ts b/history/v2/lib/createLocation.d.ts similarity index 100% rename from history/lib/createLocation.d.ts rename to history/v2/lib/createLocation.d.ts diff --git a/history/lib/createMemoryHistory.d.ts b/history/v2/lib/createMemoryHistory.d.ts similarity index 100% rename from history/lib/createMemoryHistory.d.ts rename to history/v2/lib/createMemoryHistory.d.ts diff --git a/history/lib/useBasename.d.ts b/history/v2/lib/useBasename.d.ts similarity index 100% rename from history/lib/useBasename.d.ts rename to history/v2/lib/useBasename.d.ts diff --git a/history/lib/useBeforeUnload.d.ts b/history/v2/lib/useBeforeUnload.d.ts similarity index 100% rename from history/lib/useBeforeUnload.d.ts rename to history/v2/lib/useBeforeUnload.d.ts diff --git a/history/lib/useQueries.d.ts b/history/v2/lib/useQueries.d.ts similarity index 100% rename from history/lib/useQueries.d.ts rename to history/v2/lib/useQueries.d.ts diff --git a/history/v2/tsconfig.json b/history/v2/tsconfig.json new file mode 100644 index 0000000000..3fb38bc95c --- /dev/null +++ b/history/v2/tsconfig.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "paths": { + "history": ["history/v2"], + "history/*": ["history/v2/*"] + }, + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "history-tests.ts", + "lib/actions.d.ts", + "lib/createBrowserHistory.d.ts", + "lib/createHashHistory.d.ts", + "lib/createLocation.d.ts", + "lib/createMemoryHistory.d.ts", + "lib/DOMUtils.d.ts", + "lib/useBasename.d.ts", + "lib/useBeforeUnload.d.ts", + "lib/useQueries.d.ts" + ] +} diff --git a/react-breadcrumbs/tsconfig.json b/react-breadcrumbs/tsconfig.json index 383f995045..6ea9f28e53 100644 --- a/react-breadcrumbs/tsconfig.json +++ b/react-breadcrumbs/tsconfig.json @@ -6,6 +6,9 @@ "noImplicitThis": true, "strictNullChecks": false, "baseUrl": "../", + "paths": { + "history": ["history/v2"] + }, "typeRoots": [ "../" ], @@ -18,4 +21,4 @@ "index.d.ts", "react-breadcrumbs-tests.tsx" ] -} \ No newline at end of file +} diff --git a/react-i18next/tsconfig.json b/react-i18next/tsconfig.json index 419450172f..1bb017982f 100644 --- a/react-i18next/tsconfig.json +++ b/react-i18next/tsconfig.json @@ -6,6 +6,10 @@ "noImplicitThis": true, "strictNullChecks": true, "baseUrl": "../", + "paths": { + "history": ["history/v2"], + "history/*": ["history/v2/*"] + }, "typeRoots": [ "../" ], @@ -19,4 +23,4 @@ "index.d.ts", "react-i18next-tests.tsx" ] -} \ No newline at end of file +} diff --git a/react-router-bootstrap/tsconfig.json b/react-router-bootstrap/tsconfig.json index f2eb6746ed..6317ef7bef 100644 --- a/react-router-bootstrap/tsconfig.json +++ b/react-router-bootstrap/tsconfig.json @@ -5,8 +5,11 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": false, - "baseUrl": "../", "jsx": "preserve", + "baseUrl": "../", + "paths": { + "history": ["history/v2"] + }, "typeRoots": [ "../" ], @@ -18,4 +21,4 @@ "index.d.ts", "react-router-bootstrap-tests.tsx" ] -} \ No newline at end of file +} diff --git a/react-router-redux/package.json b/react-router-redux/package.json index e52256ea90..36ce503807 100644 --- a/react-router-redux/package.json +++ b/react-router-redux/package.json @@ -2,4 +2,4 @@ "dependencies": { "redux": "^3.6.0" } -} \ No newline at end of file +} diff --git a/react-router-redux/tsconfig.json b/react-router-redux/tsconfig.json index 364dc99edc..b2efdcc111 100644 --- a/react-router-redux/tsconfig.json +++ b/react-router-redux/tsconfig.json @@ -10,6 +10,9 @@ "noImplicitThis": true, "strictNullChecks": false, "baseUrl": "../", + "paths": { + "history": ["history/v2"] + }, "typeRoots": [ "../" ], diff --git a/react-router-redux/v3/tsconfig.json b/react-router-redux/v3/tsconfig.json index 7ec7e3584d..c2948e546c 100644 --- a/react-router-redux/v3/tsconfig.json +++ b/react-router-redux/v3/tsconfig.json @@ -9,10 +9,11 @@ "typeRoots": [ "../../" ], - "types": [], "paths": { + "history": ["history/v2"], "react-router-redux": ["react-router-redux/v3"] }, + "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, @@ -20,4 +21,4 @@ "index.d.ts", "react-router-redux-tests.ts" ] -} \ No newline at end of file +} diff --git a/react-router/tsconfig.json b/react-router/tsconfig.json index 5ad1b998bb..d887e5e5ec 100644 --- a/react-router/tsconfig.json +++ b/react-router/tsconfig.json @@ -9,8 +9,11 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": false, - "baseUrl": "../", "jsx": "react", + "baseUrl": "../", + "paths": { + "history": ["history/v2"] + }, "typeRoots": [ "../" ], @@ -18,4 +21,4 @@ "noEmit": true, "forceConsistentCasingInFileNames": true } -} \ No newline at end of file +} diff --git a/redux-bootstrap/package.json b/redux-bootstrap/package.json index e52256ea90..36ce503807 100644 --- a/redux-bootstrap/package.json +++ b/redux-bootstrap/package.json @@ -2,4 +2,4 @@ "dependencies": { "redux": "^3.6.0" } -} \ No newline at end of file +} diff --git a/redux-bootstrap/tsconfig.json b/redux-bootstrap/tsconfig.json index 0f1101ce6b..037ad9ef80 100644 --- a/redux-bootstrap/tsconfig.json +++ b/redux-bootstrap/tsconfig.json @@ -6,6 +6,9 @@ "noImplicitThis": true, "strictNullChecks": false, "baseUrl": "../", + "paths": { + "history": ["history/v2"] + }, "typeRoots": [ "../" ], @@ -18,4 +21,4 @@ "index.d.ts", "redux-bootstrap-tests.tsx" ] -} \ No newline at end of file +} diff --git a/redux-router/package.json b/redux-router/package.json index e52256ea90..36ce503807 100644 --- a/redux-router/package.json +++ b/redux-router/package.json @@ -2,4 +2,4 @@ "dependencies": { "redux": "^3.6.0" } -} \ No newline at end of file +} diff --git a/redux-router/tsconfig.json b/redux-router/tsconfig.json index 9eca733b65..34637231c1 100644 --- a/redux-router/tsconfig.json +++ b/redux-router/tsconfig.json @@ -6,6 +6,9 @@ "noImplicitThis": true, "strictNullChecks": false, "baseUrl": "../", + "paths": { + "history": ["history/v2"] + }, "typeRoots": [ "../" ], @@ -17,4 +20,4 @@ "index.d.ts", "redux-router-tests.ts" ] -} \ No newline at end of file +} From 0c0a06e1c2349d8c121c407ee0b7a53522c522f2 Mon Sep 17 00:00:00 2001 From: Dave Leaver Date: Sat, 14 Jan 2017 04:24:24 +1300 Subject: [PATCH 4/5] Add react-leaflet (#13922) * Add react-leaflet, required some additional leaflet work * 4 spaces * Fix tests, typescript 2.1 * Fix tslint fails. Have disabled no-empty-interface as things get ugly when trying to be clean for it. * Fix leaflet-geocoder-mapzen * Remove a lot of extra unnecessary interface definitions and be mostly no-empty-interface safe. There are a few small ones I have retained. * Use type instead of another interface --- leaflet-geocoder-mapzen/index.d.ts | 5 +- leaflet/index.d.ts | 11 + react-leaflet/index.d.ts | 238 +++++++++++ react-leaflet/react-leaflet-tests.tsx | 589 ++++++++++++++++++++++++++ react-leaflet/tsconfig.json | 21 + react-leaflet/tslint.json | 1 + 6 files changed, 861 insertions(+), 4 deletions(-) create mode 100644 react-leaflet/index.d.ts create mode 100644 react-leaflet/react-leaflet-tests.tsx create mode 100644 react-leaflet/tsconfig.json create mode 100644 react-leaflet/tslint.json diff --git a/leaflet-geocoder-mapzen/index.d.ts b/leaflet-geocoder-mapzen/index.d.ts index fb4f2357c7..934c67b563 100644 --- a/leaflet-geocoder-mapzen/index.d.ts +++ b/leaflet-geocoder-mapzen/index.d.ts @@ -6,9 +6,6 @@ /// declare namespace L { - // TODO: This should be defined by leaflet itself, not by leaflet-geocoder-mapzen - type PositionString = 'topleft' | 'topright' | 'bottomleft' | 'bottomright'; - namespace Control { export interface GeocoderStatic extends ClassStatic { /** @@ -80,7 +77,7 @@ declare namespace L { * * Default value: 'topleft'. */ - position?: PositionString; + position?: L.PositionString; /** * Attribution text to include. diff --git a/leaflet/index.d.ts b/leaflet/index.d.ts index baa07ab295..71f7c1824a 100644 --- a/leaflet/index.d.ts +++ b/leaflet/index.d.ts @@ -6,6 +6,7 @@ /// type NativeMouseEvent = MouseEvent; +type NativeKeyboardEvent = KeyboardEvent; declare namespace L { export class Class { @@ -1137,6 +1138,10 @@ declare namespace L { originalEvent: NativeMouseEvent; } + export interface KeyboardEvent extends Event { + originalEvent: NativeKeyboardEvent; + } + export interface LocationEvent extends Event { latlng: LatLng; bounds: LatLngBounds; @@ -1194,6 +1199,12 @@ declare namespace L { distance: number; } + export interface ZoomAnimEvent extends Event { + center: LatLng; + zoom: number; + noUpdate: boolean; + } + export namespace DomEvent { export function on(el: HTMLElement, types: string, fn: (ev: Event) => any, context?: any): typeof DomEvent; diff --git a/react-leaflet/index.d.ts b/react-leaflet/index.d.ts new file mode 100644 index 0000000000..62b77852e5 --- /dev/null +++ b/react-leaflet/index.d.ts @@ -0,0 +1,238 @@ +// Type definitions for react-leaflet 1.0 +// Project: https://github.com/PaulLeCam/react-leaflet +// Definitions by: Dave Leaver +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +import * as Leaflet from 'leaflet'; +import * as React from 'react'; + +//All events need to be lowercase so they don't collide with React.DOMAttributes +// which already declares things with some of the same names + +interface LeafletLayerEvents { + onbaselayerchange?: (event: Leaflet.LayersControlEvent) => void; + onoverlayadd?: (event: Leaflet.LayersControlEvent) => void; + onoverlayremove?: (event: Leaflet.LayersControlEvent) => void; + onlayeradd?: (event: Leaflet.LayerEvent) => void; + onlayerremove?: (event: Leaflet.LayerEvent) => void; +} +interface LeafletMapStateChangeEvents { + onzoomlevelschange?: (event: Leaflet.Event) => void; + onresize?: (event: Leaflet.ResizeEvent) => void; + onunload?: (event: Leaflet.Event) => void; + onviewreset?: (event: Leaflet.Event) => void; + onload?: (event: Leaflet.Event) => void; + onzoomstart?: (event: Leaflet.Event) => void; + onmovestart?: (event: Leaflet.Event) => void; + onzoom?: (event: Leaflet.Event) => void; + onmove?: (event: Leaflet.Event) => void; + onzoomend?: (event: Leaflet.Event) => void; + onmoveend?: (event: Leaflet.Event) => void; +} +interface LeafletPopupEvents { + onpopupopen?: (event: Leaflet.PopupEvent) => void; + onpopupclose?: (event: Leaflet.PopupEvent) => void; + onautopanstart?: (event: Leaflet.Event) => void; +} +interface LeafletTooltipEvents { + ontooltipopen?: (event: Leaflet.TooltipEvent) => void; + ontooltipclose?: (event: Leaflet.TooltipEvent) => void; +} +interface LeafletLocationEvents { + onlocationerror?: (event: Leaflet.ErrorEvent) => void; + onlocationfound?: (event: Leaflet.LocationEvent) => void; +} +interface LeafletInteractionEvents { + onclick?: (event: Leaflet.MouseEvent) => void; + ondblclick?: (event: Leaflet.MouseEvent) => void; + onmousedown?: (event: Leaflet.MouseEvent) => void; + onmouseup?: (event: Leaflet.MouseEvent) => void; + onmouseover?: (event: Leaflet.MouseEvent) => void; + onmouseout?: (event: Leaflet.MouseEvent) => void; + onmousemove?: (event: Leaflet.MouseEvent) => void; + oncontextmenu?: (event: Leaflet.MouseEvent) => void; + onkeypress?: (event: Leaflet.KeyboardEvent) => void; + onpreclick?: (event: Leaflet.MouseEvent) => void; +} +interface LeafletOtherEvents { + onzoomanim?: (event: Leaflet.ZoomAnimEvent) => void; +} +interface LeafletDraggingEvents { + ondragstart?: (event: Leaflet.Event) => void; + onmovestart?: (event: Leaflet.Event) => void; + ondrag?: (event: Leaflet.Event) => void; + ondragend?: (event: Leaflet.DragEndEvent) => void; + onmoveend?: (event: Leaflet.Event) => void; +} + + +interface MapProps extends React.HTMLProps, LeafletLayerEvents, LeafletMapStateChangeEvents, LeafletPopupEvents, LeafletTooltipEvents, LeafletLocationEvents, LeafletInteractionEvents, LeafletOtherEvents, Leaflet.MapOptions { + animate?: boolean; + bounds?: Leaflet.LatLngBoundsExpression; + boundsOptions?: Leaflet.FitBoundsOptions; + className?: string; + style?: React.CSSProperties; + useFlyTo?: boolean; + + id?: string; +} +declare type Map = React.ComponentClass; +declare const Map: Map; +interface MapInstance extends React.Component { + leafletElement: Leaflet.Map; +} + + +interface PaneProps { + name?: string; + style?: React.CSSProperties; + className?: string; +} +declare const Pane: React.ComponentClass; + + +//There is no Layer class, these are the base props for all layers on the map +interface LayerProps { + onadd?: (event: Leaflet.Event) => void; + onremove?: (event: Leaflet.Event) => void; + + //Popup events + onpopupopen?: (event: Leaflet.PopupEvent) => void; + onpopupclose?: (event: Leaflet.PopupEvent) => void; + + //Tooltip events + ontooltipopen?: (event: Leaflet.TooltipEvent) => void; + ontooltipclose?: (event: Leaflet.TooltipEvent) => void; +} + + +interface MarkerProps extends LayerProps, LeafletInteractionEvents, LeafletDraggingEvents { + position: Leaflet.LatLngExpression; + draggable?: boolean; + icon?: Leaflet.Icon; + zIndexOffset?: number; + opacity?: number; +} +declare const Marker: React.ComponentClass; +interface MarkerInstance extends React.Component { + leafletElement: Leaflet.Marker; +} + +interface PopupProps extends LayerProps, Leaflet.PopupOptions { + position?: Leaflet.LatLngExpression; +} +declare const Popup: React.ComponentClass; + +//tslint:disable-next-line:no-empty-interface +interface TooltipProps extends LayerProps, Leaflet.TooltipOptions { } +declare const Tooltip: React.ComponentClass; + +interface GridLayerProps extends LayerProps { + opacity?: number; + zIndex?: number; + + onloading?: (event: Leaflet.Event) => void; + ontileunload?: (event: Leaflet.TileEvent) => void; + ontileloadstart?: (event: Leaflet.TileEvent) => void; + ontileerror?: (event: Leaflet.TileErrorEvent) => void; + ontileload?: (event: Leaflet.TileEvent) => void; + onload?: (event: Leaflet.Event) => void; +} +declare const GridLayer: React.ComponentClass; + +interface TileLayerProps extends GridLayerProps, Leaflet.TileLayerOptions { + url: string; +} +declare const TileLayer: React.ComponentClass; + +interface ImageOverlayProps extends LayerProps, LeafletInteractionEvents { + url: string; + opacity?: string; +} +declare const ImageOverlay: React.ComponentClass; + +interface WMSTileLayerProps extends TileLayerProps { + url: string; +} +declare const WMSTileLayer: React.ComponentClass; + +//Path is an abstract class +//tslint:disable-next-line:no-empty-interface +interface PathProps extends LeafletLayerEvents, LeafletInteractionEvents, Leaflet.PathOptions { +} + + +interface CircleProps extends PathProps { + center: Leaflet.LatLngExpression; + radius?: number; +} +declare const Circle: React.ComponentClass; + +interface CircleMarkerProps extends PathProps { + center: Leaflet.LatLngExpression; + radius?: number; +} +declare const CircleMarker: React.ComponentClass; + +interface PolylineProps extends PathProps { + positions: Leaflet.LatLngExpression[] | Leaflet.LatLngExpression[][]; +} +declare const Polyline: React.ComponentClass; + +interface PolygonProps extends PathProps { + positions: Leaflet.LatLngExpression[] | Leaflet.LatLngExpression[][] | Leaflet.LatLngExpression[][][]; +} +declare const Polygon: React.ComponentClass; + +interface RectangleProps extends PathProps { + bounds: Leaflet.LatLngBoundsExpression; +} +declare const Rectangle: React.ComponentClass; + + +//tslint:disable-next-line:no-empty-interface +interface LayerGroupProps extends LayerProps { } +declare const LayerGroup: React.ComponentClass; + +//tslint:disable-next-line:no-empty-interface +interface FeatureGroupProps extends LayerGroupProps, Leaflet.PathOptions { } +declare const FeatureGroup: React.ComponentClass; + +interface GeoJSONProps extends FeatureGroupProps { + data: GeoJSON.GeoJsonObject; +} +declare const GeoJSON: React.ComponentClass; + + + +interface AttributionControlProps { + position?: Leaflet.ControlPosition; +} +declare const AttributionControl: React.ComponentClass; + +interface LayersControlProps { + position?: Leaflet.ControlPosition; +} +declare const LayersControl: React.ComponentClass & { BaseLayer: LayersControl.BaseLayer, Overlay: LayersControl.Overlay }; + +declare namespace LayersControl { + interface LayersControlLayerProps { + name: string; + checked?: boolean; + } + type BaseLayer = React.ComponentClass; + type Overlay = React.ComponentClass; +} + +interface ScaleControlProps { + position: Leaflet.ControlPosition; +} +declare const ScaleControl: React.ComponentClass; + +interface ZoomControlProps { + position: Leaflet.ControlPosition; +} +declare const ZoomControl: React.ComponentClass; diff --git a/react-leaflet/react-leaflet-tests.tsx b/react-leaflet/react-leaflet-tests.tsx new file mode 100644 index 0000000000..4a33aa0748 --- /dev/null +++ b/react-leaflet/react-leaflet-tests.tsx @@ -0,0 +1,589 @@ +import * as React from 'react'; +import * as Leaflet from 'leaflet'; +import { Component, PropTypes } from 'react'; +import { + Circle, + CircleMarker, + FeatureGroup, + LayerGroup, + LayersControl, + Map, + MapInstance, + Marker, + MarkerInstance, + Pane, + Polygon, + Polyline, + Popup, + Rectangle, + TileLayer, + Tooltip, + WMSTileLayer, + ZoomControl +} from 'react-leaflet'; +const { BaseLayer, Overlay } = LayersControl; + +///animate.js +export class AnimateExample extends Component { + state = { + animate: false, + hasLocation: false, + latlng: { + lat: 51.505, + lng: -0.09, + }, + } + + handleClick = (e: Leaflet.MouseEvent) => { + this.setState({ + latlng: e.latlng, + }) + } + + toggleAnimate = () => { + this.setState({ + animate: !this.state.animate, + }) + } + + render() { + const marker = this.state.hasLocation ? ( + + + You are here + + + ) : null + + return ( +
+ + + + {marker} + +
+ ) + } +} + +//bounds.js +const outer: Array<[number, number]> = [ + [50.505, -29.09], + [52.505, 29.09], +] +const inner: Array<[number, number]> = [ + [49.505, -2.09], + [53.505, 2.09], +] + +export class BoundsExample extends Component { + state = { + bounds: outer, + } + + onClickInner = () => { + this.setState({ bounds: inner }) + } + + onClickOuter = () => { + this.setState({ bounds: outer }) + } + + render() { + return ( + + + + + + ) + } +} + +//custom-component.js +const SomeFn = (asd: string) => ( + asd + asd +) + +const MyPopupMarker = ({ children, position }: any) => ( + + + {children} + + +); + +/*(MyPopupMarker as any).propTypes = { + children: MapPropTypes.children, + position: MapPropTypes.latlng, +}*/ + +const MyMarkersList = ({ markers }: any) => { + const items = markers.map(({ key, ...props }: any) => ( + + )) + return
{items}
+} +(MyMarkersList as any).propTypes = { + markers: PropTypes.array.isRequired, +} + +export class CustomComponent extends Component { + state = { + lat: 51.505, + lng: -0.09, + zoom: 13, + }; + + render() { + const center: [number, number] = [this.state.lat, this.state.lng] + + const markers = [ + { key: 'marker1', position: [51.5, -0.1], children: 'My first popup' }, + { key: 'marker2', position: [51.51, -0.1], children: 'My second popup' }, + { key: 'marker3', position: [51.49, -0.05], children: 'My third popup' }, + ] + return ( + + + + + ) + } +} + +//draggable-marker.js +export class DraggableExample extends Component { + state = { + center: { + lat: 51.505, + lng: -0.09, + }, + marker: { + lat: 51.505, + lng: -0.09, + }, + zoom: 13, + draggable: true, + } + + toggleDraggable = () => { + this.setState({ draggable: !this.state.draggable }) + } + + updatePosition = () => { + const { lat, lng } = (this.refs['marker'] as MarkerInstance).leafletElement.getLatLng() + this.setState({ + marker: { lat, lng }, + }) + } + + render() { + const position: [number, number] = [this.state.center.lat, this.state.center.lng] + const markerPosition: [number, number] = [this.state.marker.lat, this.state.marker.lng] + + return ( + + + + + + {this.state.draggable ? 'DRAG MARKER' : 'MARKER FIXED'} + + + + + ) + } +} + +//events.js +export class EventsExample extends Component { + state = { + hasLocation: false, + latlng: { + lat: 51.505, + lng: -0.09, + }, + } + + handleClick = () => { + (this.refs['map'] as MapInstance).leafletElement.locate() + } + + handleLocationFound = (e: Leaflet.LocationEvent) => { + this.setState({ + hasLocation: true, + latlng: e.latlng, + }) + } + + render() { + const marker = this.state.hasLocation ? ( + + + You are here + + + ) : null + + return ( + + + {marker} + + ) + } +} + +//layers-control.js +export class LayersControlExample extends Component { + render() { + const center: [number, number] = [51.505, -0.09] + const rectangle: Array<[number, number]> = [ + [51.49, -0.08], + [51.5, -0.06], + ] + + return ( + + + + + + + + + + + + A pretty CSS3 popup.
Easily customizable.
+
+
+
+ + + + + + + + + + + + + Popup in FeatureGroup + + + + + +
+
+ ) + } +} + +//other-layers.js +export class OtherLayersExample extends Component { + render() { + const center: [number, number] = [51.505, -0.09] + const rectangle: Array<[number, number]> = [ + [51.49, -0.08], + [51.5, -0.06], + ] + + return ( + + + + + + + + + + + + Popup in FeatureGroup + + + + + + ) + } +} + +//pane.js +export class PaneExample extends Component { + state = { + render: true, + } + + componentDidMount() { + setInterval(() => { + this.setState({ + render: !this.state.render, + }) + }, 5000) + } + + render() { + return ( + + + {this.state.render ? ( + + + + ) : null} + + + + + + + + ) + } +} + +//simple.js +export class SimpleExample extends Component { + state = { + lat: 51.505, + lng: -0.09, + zoom: 13, + } + + render() { + const position: [number, number] = [this.state.lat, this.state.lng] + return ( + + + + + A pretty CSS3 popup.
Easily customizable.
+
+
+
+ ) + } +} + +//tooltip.js +export class TooltipExample extends Component { + state = { + clicked: 0, + } + + onClickCircle = () => { + this.setState({ clicked: this.state.clicked + 1 }) + } + + render() { + const center: [number, number] = [51.505, -0.09] + + const multiPolygon: Array> = [ + [[51.51, -0.12], [51.51, -0.13], [51.53, -0.13]], + [[51.51, -0.05], [51.51, -0.07], [51.53, -0.07]], + ] + + const rectangle: Array<[number, number]> = [ + [51.49, -0.08], + [51.5, -0.06], + ] + + const clickedText = this.state.clicked === 0 + ? 'Click this Circle to change the Tooltip text' + : `Circle click: ${this.state.clicked}` + + return ( + + + + + {clickedText} + + + + + Tooltip for CircleMarker + + + + + sticky Tooltip for Polygon + + + + + permanent Tooltip for Rectangle + + + + ) + } +} + +//vector-layers.js +export class VectorLayersExample extends Component { + render() { + const center: [number, number] = [51.505, -0.09] + + const polyline: Array<[number, number]> = [ + [51.505, -0.09], + [51.51, -0.1], + [51.51, -0.12], + ] + + const multiPolyline: Array> = [ + [[51.5, -0.1], [51.5, -0.12], [51.52, -0.12]], + [[51.5, -0.05], [51.5, -0.06], [51.52, -0.06]], + ] + + const polygon: Array<[number, number]> = [ + [51.515, -0.09], + [51.52, -0.1], + [51.52, -0.12], + ] + + const multiPolygon: Array> = [ + [[51.51, -0.12], [51.51, -0.13], [51.53, -0.13]], + [[51.51, -0.05], [51.51, -0.07], [51.53, -0.07]], + ] + + const rectangle: Array<[number, number]> = [ + [51.49, -0.08], + [51.5, -0.06], + ] + + return ( + + + + + + Popup in CircleMarker + + + + + + + + + ) + } +} + +//wms-tile-layer.js +export class WMSTileLayerExample extends Component { + state = { + lat: 51.505, + lng: -0.09, + zoom: 5, + bluemarble: false, + } + + onClick = () => { + this.setState({ + bluemarble: !this.state.bluemarble, + }) + } + + render() { + return ( + + + + + ) + } +} + +//zoom-control.js +const ZoomControlExample = () => ( + + + + +) \ No newline at end of file diff --git a/react-leaflet/tsconfig.json b/react-leaflet/tsconfig.json new file mode 100644 index 0000000000..4ebf2bb5d3 --- /dev/null +++ b/react-leaflet/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "jsx": "react", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-leaflet-tests.tsx" + ] +} diff --git a/react-leaflet/tslint.json b/react-leaflet/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/react-leaflet/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From 08e9679d95273271c18d5d8dac3b958c6b0a83b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez?= Date: Fri, 13 Jan 2017 09:35:26 -0600 Subject: [PATCH 5/5] Made bunyan typing conform to the way the module was written (#13765) --- browser-bunyan/index.d.ts | 8 +- bunyan-logentries/bunyan-logentries-tests.ts | 4 +- bunyan/bunyan-tests.ts | 70 ++++++++------- bunyan/index.d.ts | 89 ++++++++++---------- easy-api-request/index.d.ts | 4 +- easy-xapi/index.d.ts | 4 +- restify-plugins/index.d.ts | 26 +++--- restify/index.d.ts | 6 +- 8 files changed, 112 insertions(+), 99 deletions(-) diff --git a/browser-bunyan/index.d.ts b/browser-bunyan/index.d.ts index df5116f1c4..f2981bfacd 100644 --- a/browser-bunyan/index.d.ts +++ b/browser-bunyan/index.d.ts @@ -3,6 +3,10 @@ // Definitions by: Paul Lockwood // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export * from "bunyan"; +import bunyan = require("bunyan"); -export function ConsoleFormattedStream(): void; +declare module "bunyan" { + export function ConsoleFormattedStream(): void; +} + +export = bunyan; diff --git a/bunyan-logentries/bunyan-logentries-tests.ts b/bunyan-logentries/bunyan-logentries-tests.ts index a644d028e4..a7a6f160d7 100644 --- a/bunyan-logentries/bunyan-logentries-tests.ts +++ b/bunyan-logentries/bunyan-logentries-tests.ts @@ -1,7 +1,7 @@ -import bunyan = require("bunyan"); +import Logger = require("bunyan"); import bunyanLogentries = require("bunyan-logentries"); -var logger: bunyan.Logger = bunyan.createLogger({ +var logger: Logger = Logger.createLogger({ name: "foobar", streams: [{ level: "info", diff --git a/bunyan/bunyan-tests.ts b/bunyan/bunyan-tests.ts index 06fce4b410..91b45765d1 100644 --- a/bunyan/bunyan-tests.ts +++ b/bunyan/bunyan-tests.ts @@ -1,83 +1,83 @@ -import * as bunyan from 'bunyan'; +import Logger = require('bunyan'); -var ringBufferOptions:bunyan.RingBufferOptions = { +var ringBufferOptions: Logger.RingBufferOptions = { limit: 100 }; -var ringBuffer:bunyan.RingBuffer = new bunyan.RingBuffer(ringBufferOptions); +var ringBuffer: Logger.RingBuffer = new Logger.RingBuffer(ringBufferOptions); ringBuffer.write("hello"); ringBuffer.end(); ringBuffer.destroy(); ringBuffer.destroySoon(); -var level:number; -level = bunyan.resolveLevel("trace"); -level = bunyan.resolveLevel("debug"); -level = bunyan.resolveLevel("info"); -level = bunyan.resolveLevel("warn"); -level = bunyan.resolveLevel("error"); -level = bunyan.resolveLevel("fatal"); -level = bunyan.resolveLevel(bunyan.TRACE); -level = bunyan.resolveLevel(bunyan.DEBUG); -level = bunyan.resolveLevel(bunyan.INFO); -level = bunyan.resolveLevel(bunyan.WARN); -level = bunyan.resolveLevel(bunyan.ERROR); -level = bunyan.resolveLevel(bunyan.FATAL); +var level: number; +level = Logger.resolveLevel("trace"); +level = Logger.resolveLevel("debug"); +level = Logger.resolveLevel("info"); +level = Logger.resolveLevel("warn"); +level = Logger.resolveLevel("error"); +level = Logger.resolveLevel("fatal"); +level = Logger.resolveLevel(Logger.TRACE); +level = Logger.resolveLevel(Logger.DEBUG); +level = Logger.resolveLevel(Logger.INFO); +level = Logger.resolveLevel(Logger.WARN); +level = Logger.resolveLevel(Logger.ERROR); +level = Logger.resolveLevel(Logger.FATAL); -var options:bunyan.LoggerOptions = { +var options: Logger.LoggerOptions = { name: 'test-logger', - serializers: bunyan.stdSerializers, + serializers: Logger.stdSerializers, streams: [{ type: 'stream', stream: process.stdout, - level: bunyan.TRACE + level: Logger.TRACE }, { type: 'file', path: '/tmp/test.log', - level: bunyan.DEBUG, + level: Logger.DEBUG, closeOnExit: true }, { type: 'rotating-file', path: '/tmp/test2.log', - level: bunyan.INFO, + level: Logger.INFO, closeOnExit: false, period: '1d', count: 3 }, { type: 'raw', stream: process.stderr, - level: bunyan.WARN + level: Logger.WARN }, { type: 'raw', stream: ringBuffer, - level: bunyan.ERROR + level: Logger.ERROR }] }; -var log = bunyan.createLogger(options); +var log = Logger.createLogger(options); var customSerializer = function(anything: any) { return { obj: anything}; }; log.addSerializers({anything: customSerializer}); -log.addSerializers(bunyan.stdSerializers); +log.addSerializers(Logger.stdSerializers); log.addSerializers( { - err: bunyan.stdSerializers.err, - req: bunyan.stdSerializers.req, - res: bunyan.stdSerializers.res + err: Logger.stdSerializers.err, + req: Logger.stdSerializers.req, + res: Logger.stdSerializers.res } ); var child = log.child({name: 'child'}); child.reopenFileStreams(); log.addStream({path: '/dev/null'}); -child.level(bunyan.DEBUG); +child.level(Logger.DEBUG); child.level('debug'); -child.levels(0, bunyan.ERROR); +child.levels(0, Logger.ERROR); child.levels(0, 'error'); -child.levels('stream1', bunyan.FATAL); +child.levels('stream1', Logger.FATAL); child.levels('stream1', 'fatal'); var buffer = new Buffer(0); @@ -118,4 +118,10 @@ var recursive: any = { } } -JSON.stringify(recursive, bunyan.safeCycles()); +JSON.stringify(recursive, Logger.safeCycles()); + +class MyLogger extends Logger { + constructor() { + super(options); + } +} diff --git a/bunyan/index.d.ts b/bunyan/index.d.ts index 6886aade90..787a0225f1 100644 --- a/bunyan/index.d.ts +++ b/bunyan/index.d.ts @@ -5,14 +5,13 @@ /// - import { EventEmitter } from 'events'; declare class Logger extends EventEmitter { - constructor(options: LoggerOptions); - addStream(stream: Stream): void; - addSerializers(serializers:Serializers | StdSerializers):void; - child(options: LoggerOptions, simple?: boolean): Logger; + constructor(options: Logger.LoggerOptions); + addStream(stream: Logger.Stream): void; + addSerializers(serializers: Logger.Serializers | Logger.StdSerializers): void; + child(options: Logger.LoggerOptions, simple?: boolean): Logger; child(obj: Object, simple?: boolean): Logger; reopenFileStreams(): void; @@ -21,7 +20,7 @@ declare class Logger extends EventEmitter { levels(name: number | string, value: number | string): void; fields: any; - src:boolean; + src: boolean; trace(error: Error, format?: any, ...params: any[]): void; trace(buffer: Buffer, format?: any, ...params: any[]): void; @@ -49,31 +48,23 @@ declare class Logger extends EventEmitter { fatal(format: string, ...params: any[]): void; } -interface LoggerOptions { - name: string; - streams?: Stream[]; - level?: string | number; - stream?: NodeJS.WritableStream; - serializers?: Serializers | StdSerializers; - src?: boolean; - [custom: string]: any; -} +declare namespace Logger { + const TRACE: number; + const DEBUG: number; + const INFO: number; + const WARN: number; + const ERROR: number; + const FATAL: number; -interface Serializer { - (input:any): any; -} + const stdSerializers: StdSerializers; -interface Serializers { - [key: string]: Serializer -} + function createLogger(options: LoggerOptions): Logger; -interface StdSerializers { - err: Serializer; - res: Serializer; - req: Serializer; -} + function safeCycles(): (key: string, value: any) => any; -interface Stream { + function resolveLevel(value: number | string): number; + + interface Stream { type?: string; level?: number | string; path?: string; @@ -81,22 +72,37 @@ interface Stream { closeOnExit?: boolean; period?: string; count?: number; -} + } -export declare var stdSerializers: StdSerializers; + interface LoggerOptions { + name: string; + streams?: Stream[]; + level?: string | number; + stream?: NodeJS.WritableStream; + serializers?: Serializers | StdSerializers; + src?: boolean; + [custom: string]: any; + } -export declare var TRACE: number; -export declare var DEBUG: number; -export declare var INFO: number; -export declare var WARN: number; -export declare var ERROR: number; -export declare var FATAL: number; + interface Serializer { + (input:any): any; + } -export declare function resolveLevel(value: number | string): number; + interface Serializers { + [key: string]: Serializer + } -export declare function createLogger(options: LoggerOptions): Logger; + interface StdSerializers { + err: Serializer; + res: Serializer; + req: Serializer; + } -declare class RingBuffer extends EventEmitter { + interface RingBufferOptions { + limit?: number; + } + + class RingBuffer extends EventEmitter { constructor(options: RingBufferOptions); writable: boolean; @@ -106,10 +112,7 @@ declare class RingBuffer extends EventEmitter { end(record?: any): void; destroy(): void; destroySoon(): void; + } } -interface RingBufferOptions { - limit?: number; -} - -export declare function safeCycles(): (key: string, value: any) => any; +export = Logger; diff --git a/easy-api-request/index.d.ts b/easy-api-request/index.d.ts index b3c8dc7643..8f4ca0d553 100644 --- a/easy-api-request/index.d.ts +++ b/easy-api-request/index.d.ts @@ -9,7 +9,7 @@ import stream = require('stream'); import http = require('http'); import request = require('request'); -import bunyan = require('bunyan'); +import Logger = require('bunyan'); import express = require('express'); import Q = require('q'); @@ -35,7 +35,7 @@ interface Result { declare class BaseRequest { protected base: request.Request; protected req: express.Request; - protected log: bunyan.Logger; + protected log: Logger; protected replyCookies: string[]; protected jSend: boolean; constructor(opts: any); diff --git a/easy-xapi/index.d.ts b/easy-xapi/index.d.ts index 13a8a7bfd9..f4a9e09391 100644 --- a/easy-xapi/index.d.ts +++ b/easy-xapi/index.d.ts @@ -18,7 +18,7 @@ declare namespace Express { declare module "easy-xapi" { import express = require('express'); import http = require('http'); - import bunyan = require('bunyan'); + import Logger = require('bunyan'); interface InitConfig { jSend?: {partial: boolean}; @@ -40,7 +40,7 @@ declare module "easy-xapi" { express: any; app: express.Application; server: http.Server; - log: bunyan.Logger; + log: Logger; listen: () => void; } diff --git a/restify-plugins/index.d.ts b/restify-plugins/index.d.ts index faf28e4c78..3ce557374f 100644 --- a/restify-plugins/index.d.ts +++ b/restify-plugins/index.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import {RequestHandler, Server, Request, Response, Route} from 'restify'; -import * as bunyan from 'bunyan'; +import Logger = require('bunyan'); //*************** This module includes the follow pre plugins, which are intended to be used prior to the routing of a request: @@ -15,7 +15,7 @@ export namespace pre { function context(): RequestHandler; /** - * + * */ function dedupeSlashes(): RequestHandler; @@ -56,7 +56,7 @@ interface AuditLoggerOptions { /** * Bunyan logger */ - log: bunyan.Logger; + log: Logger; /** * Restify server. If passed in, causes server to emit 'auditlog' event after audit logs are flushed @@ -74,7 +74,7 @@ interface AuditLoggerOptions { printLog?: boolean; /** - * + * */ body?: boolean; } @@ -165,12 +165,12 @@ interface BodyParserOptions { rejectUnknown?: boolean; /** - * + * */ reviver?: any; /** - * + * */ maxFieldsSize?: number; } @@ -192,7 +192,7 @@ interface UrlEncodedBodyParser { /** * Parse the HTTP request body IFF the contentType is application/x-www-form-urlencoded. - * + * * If req.params already contains a given key, that key is skipped and an * error is logged. */ @@ -287,7 +287,7 @@ interface RequestLogger { /** * Adds timers for each handler in your request chain - * + * * `options.properties` properties to pass to bunyan's `log.child()` method */ export function requestLogger(options?: RequestLogger): RequestHandler; @@ -341,7 +341,7 @@ interface MetricsCallback { err: Error; /** - * + * */ metrics: MetricsCallbackOptions; @@ -380,7 +380,7 @@ interface MetricsCallbackOptions { /** * If this value is set, err will be a corresponding `RequestCloseError` or `RequestAbortedError`. - * + * * If connectionState is either 'close' or 'aborted', then the statusCode is not applicable since the connection was severed before a response was written. */ connectionState: TMetricsCallback; @@ -395,7 +395,7 @@ interface MetricsReturns { /** * Listens to the server's after event and emits information about that request (5.x compatible only). - * + * * ``` * server.on('after', plugins.metrics( (err, metrics) => * { @@ -407,7 +407,7 @@ export function metrics(opts: {server: Server}, callback: (options: MetricsCallb /** * Parse the client's request for an OAUTH2 access tokensTable - * + * * Subsequent handlers will see `req.oauth2`, which looks like: * ``` * { @@ -441,7 +441,7 @@ interface RequestExpiryOptions { /** * A request expiry will use headers to tell if the incoming request has expired or not. - * + * * There are two options for this plugin: * 1. Absolute Time * * Time in Milliseconds since the Epoch when this request should be considered expired diff --git a/restify/index.d.ts b/restify/index.d.ts index b1350660d0..40a6938127 100644 --- a/restify/index.d.ts +++ b/restify/index.d.ts @@ -6,7 +6,7 @@ /// import http = require('http'); -import bunyan = require('bunyan'); +import Logger = require('bunyan'); import url = require('url'); @@ -196,7 +196,7 @@ interface Request extends http.IncomingMessage { */ href: () => string; - log: bunyan.Logger; + log: Logger; /** * retrieves the request uuid. was created when the request was setup. * @public @@ -486,7 +486,7 @@ interface HttpClient extends Client { patch: (opts?: string | { path?: string; [name: string]: any }, callback?: Function) => any; del: (opts?: string | { path?: string; [name: string]: any }, callback?: Function) => any; } - + interface ThrottleOptions { burst?: number; rate?: number;