diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index df45a8a9e7..0305e57c9b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -644,7 +644,7 @@ /types/connect-mongo/ @Syati /types/connect-mongodb-session/ @NattapongSiri /types/connect-pg-simple/ @pasieronen -/types/connect-redis/ @xstoudi @morcerf +/types/connect-redis/ @xstoudi /types/connect-slashes/ @samherrmann /types/connect-timeout/ @cyrilschumacher /types/consola/ @Jungwoo-An @@ -3691,8 +3691,8 @@ /types/rdflib/ @cenotelie /types/re-base/ @jordandrako /types/reach__router/ @kingdaro -/types/react/v15/ @bbenezech @pzavolinsky @digiguru @ericanderson @morcerf @tkrotoff @DovydasNavickas @onigoetz -/types/react/ @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @morcerf @tkrotoff @DovydasNavickas @onigoetz @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @hotell @franklixuefei +/types/react/v15/ @bbenezech @pzavolinsky @digiguru @ericanderson @tkrotoff @DovydasNavickas @onigoetz +/types/react/ @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @tkrotoff @DovydasNavickas @onigoetz @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @hotell @franklixuefei /types/react-adal/ @dkorolev1 /types/react-albus/ @sseppola @conradreuter @kuirak /types/react-alert/v2/ @ssyrell diff --git a/README.md b/README.md index 9a31d73da1..eba170c493 100644 --- a/README.md +++ b/README.md @@ -336,3 +336,6 @@ This project is licensed under the MIT license. Copyrights on the definition files are respective of each contributor listed at the beginning of each definition file. [![Analytics](https://ga-beacon.appspot.com/UA-47495295-4/borisyankov/DefinitelyTyped)](https://github.com/igrigorik/ga-beacon) + +[![Build Status](https://typescript.visualstudio.com/TypeScript/_apis/build/status/sandersn.types-publisher-watchdog)](https://typescript.visualstudio.com/TypeScript/_build/latest?definitionId=13) Are packages being published to npm in less than 10,000 seconds on average? +[![Build Status](https://typescript.visualstudio.com/TypeScript/_apis/build/status/sandersn.typescript-bot-watchdog)](https://typescript.visualstudio.com/TypeScript/_build/latest?definitionId=14) Has typescript-bot been active on DefinitelyTyped in the last two hours? diff --git a/notNeededPackages.json b/notNeededPackages.json index cf5c9449d7..53ff6a7124 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -1656,6 +1656,12 @@ "sourceRepoURL": "https://github.com/ansman/validate.js", "asOfVersion": "0.11.0" }, + { + "libraryName": "vega", + "typingsPackageName": "vega", + "sourceRepoURL": "https://github.com/vega/vega", + "asOfVersion": "3.2.0" + }, { "libraryName": "vso-node-api", "typingsPackageName": "vso-node-api", diff --git a/types/analytics-node/index.d.ts b/types/analytics-node/index.d.ts index 6834087ff7..cc9e5386e2 100644 --- a/types/analytics-node/index.d.ts +++ b/types/analytics-node/index.d.ts @@ -22,8 +22,8 @@ declare namespace AnalyticsNode { }, timestamp?: Date; messageId?: string; - anonymousId: string | number; - userId: string | number; + anonymousId?: string | number; + userId?: string | number; } interface Data { @@ -47,7 +47,8 @@ declare namespace AnalyticsNode { /* The identify method lets you tie a user to their actions and record traits about them. */ identify(message: { - userId: string | number; + userId?: string | number; + anonymousId?: string | number; traits?: Object; timestamp?: Date; context?: Object; @@ -56,7 +57,8 @@ declare namespace AnalyticsNode { /* The track method lets you record the actions your users perform. */ track(message: { - userId: string | number; + userId?: string | number; + anonymousId?: string | number; event: string; properties?: Object; timestamp?: Date; @@ -67,7 +69,8 @@ declare namespace AnalyticsNode { /* The page method lets you record page views on your website, along with optional extra information about the page being viewed. */ page(message: { - userId: string | number; + userId?: string | number; + anonymousId?: string | number; category?: string; name?: string; properties?: Object; @@ -79,19 +82,20 @@ declare namespace AnalyticsNode { /* alias is how you associate one identity with another. */ alias(message: { previousId: string | number; - userId: string | number; + userId?: string | number; + anonymousId?: string | number; integrations?: Integrations; }, callback?: (err: Error, data: Data) => void): Analytics; /* Group calls can be used to associate individual users with shared accounts or companies. */ group(message: { - userId: string | number; + userId?: string | number; + anonymousId?: string | number; groupId: string | number; traits?: Object; context?: Object; timestamp?: Date; - anonymous_id?: string | number; integrations?: Integrations; }, callback?: (err: Error, data: Data) => void): Analytics; diff --git a/types/babel__core/babel__core-tests.ts b/types/babel__core/babel__core-tests.ts index a873c3392f..623d4121fe 100644 --- a/types/babel__core/babel__core-tests.ts +++ b/types/babel__core/babel__core-tests.ts @@ -29,3 +29,7 @@ babel.transformFromAst(parsedAst!, sourceCode, options, (err, result) => { const transformFromAstSyncResult = babel.transformFromAstSync(parsedAst!, sourceCode, options); const { code, map, ast } = transformFromAstSyncResult!; + +babel.transformFromAstAsync(parsedAst!, sourceCode, options).then(transformFromAstAsyncResult => { + const { code, map, ast } = transformFromAstAsyncResult!; +}); diff --git a/types/babel__core/index.d.ts b/types/babel__core/index.d.ts index 85a89392af..ad061fba80 100644 --- a/types/babel__core/index.d.ts +++ b/types/babel__core/index.d.ts @@ -349,7 +349,7 @@ export function transformFromAstSync(ast: Node, code?: string, opts?: TransformO /** * Given an AST, transform it. */ -export function transformFromAstSync(ast: Node, code?: string, opts?: TransformOptions): Promise; +export function transformFromAstAsync(ast: Node, code?: string, opts?: TransformOptions): Promise; // A babel plugin is a simple function which must return an object matching // the following interface. Babel will throw if it finds unknown properties. diff --git a/types/babel__traverse/babel__traverse-tests.ts b/types/babel__traverse/babel__traverse-tests.ts index 5b4fbbef5f..1a1bf712d7 100644 --- a/types/babel__traverse/babel__traverse-tests.ts +++ b/types/babel__traverse/babel__traverse-tests.ts @@ -89,7 +89,8 @@ const v1: Visitor = { const id = path.scope.generateUidIdentifierBasedOnNode(path.node.id!); path.remove(); - path.scope.parent.push({ id, init: path.node }); + path.scope.parent.push({ id }); + path.scope.parent.push({ id, init: t.stringLiteral('foo'), kind: "const" }); path.scope.rename("n", "x"); path.scope.rename("n"); @@ -104,7 +105,7 @@ const BindingKindTest: Visitor = { kind === 'const'; kind === 'let'; kind === 'var'; - // The following should fail when uncommented - // kind === 'anythingElse'; + // $ExpectError + kind === 'anythingElse'; }, }; diff --git a/types/babel__traverse/index.d.ts b/types/babel__traverse/index.d.ts index 465a60464f..93c768a913 100644 --- a/types/babel__traverse/index.d.ts +++ b/types/babel__traverse/index.d.ts @@ -90,7 +90,12 @@ export class Scope { removeData(key: string): void; - push(opts: any): void; + push(opts: { + id: t.LVal, + init?: t.Expression, + unique?: boolean, + kind?: "var" | "let" | "const", + }): void; getProgramParent(): Scope; diff --git a/types/bull/index.d.ts b/types/bull/index.d.ts index 6096d98145..dd5723f2d2 100644 --- a/types/bull/index.d.ts +++ b/types/bull/index.d.ts @@ -92,7 +92,7 @@ declare namespace Bull { * Define a custom backoff strategy */ backoffStrategies?: { - [key: string]: (attemptsMade: number, err: typeof Error) => number; + [key: string]: (attemptsMade: number, err: Error) => number; }; /** diff --git a/types/codemirror/codemirror-comment.d.ts b/types/codemirror/codemirror-comment.d.ts index 47b99fd989..706e42e807 100644 --- a/types/codemirror/codemirror-comment.d.ts +++ b/types/codemirror/codemirror-comment.d.ts @@ -41,7 +41,3 @@ declare module "codemirror" { fullLines?: boolean; } } - -declare module "codemirror/addon/comment/comment" { - export = CodeMirror; -} diff --git a/types/codemirror/codemirror-panel.d.ts b/types/codemirror/codemirror-panel.d.ts index 2059c8ff72..a361992641 100644 --- a/types/codemirror/codemirror-panel.d.ts +++ b/types/codemirror/codemirror-panel.d.ts @@ -45,7 +45,3 @@ declare module "codemirror" { } } - -declare module "codemirror/addon/display/panel" { - export = CodeMirror; -} diff --git a/types/codemirror/codemirror-showhint.d.ts b/types/codemirror/codemirror-showhint.d.ts index c6f367d0d2..dfbbcdc4e1 100644 --- a/types/codemirror/codemirror-showhint.d.ts +++ b/types/codemirror/codemirror-showhint.d.ts @@ -76,7 +76,3 @@ declare module "codemirror" { hintOptions?: ShowHintOptions; } } - -declare module "codemirror/addon/hint/show-hint" { - export = CodeMirror; -} diff --git a/types/connect-redis/index.d.ts b/types/connect-redis/index.d.ts index 5675512795..c5a26de73a 100644 --- a/types/connect-redis/index.d.ts +++ b/types/connect-redis/index.d.ts @@ -1,7 +1,6 @@ // Type definitions for connect-redis // Project: https://npmjs.com/package/connect-redis // Definitions by: Xavier Stouder -// Albert Kurniawan // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 diff --git a/types/elasticsearch/elasticsearch-tests.ts b/types/elasticsearch/elasticsearch-tests.ts index ee57f847fa..0d12a931ed 100644 --- a/types/elasticsearch/elasticsearch-tests.ts +++ b/types/elasticsearch/elasticsearch-tests.ts @@ -209,7 +209,7 @@ client.get({ id: '1', routing: '1' }, (error, response) => { - const routing = response._routing; + const routing = response._routing; }); client.mget({ @@ -338,22 +338,43 @@ client.indices.updateAliases({ // ... }); -client.reindex({ - body: { - source: { - index: "twitter" - }, - dest: { - index: "new_twitter" +client.indices.updateAliases({ + body: { + actions: [ + { + add: { + index: 'logstash-2018.11', alias: 'logstash-filtered', filter: { + query: { + exists: { field: 'id' } + } + }, + routing: 'id' } } + ] + } +}).then((response) => { + // ... +}, (error) => { + // ... +}); + +client.reindex({ + body: { + source: { + index: "twitter" + }, + dest: { + index: "new_twitter" + } + } }) -.then(response => { + .then(response => { const { took, timed_out } = response; // ... -}); + }); // Errors function testErrors() { - throw new elasticsearch.errors.AuthenticationException(); + throw new elasticsearch.errors.AuthenticationException(); } diff --git a/types/elasticsearch/index.d.ts b/types/elasticsearch/index.d.ts index 0d16cc6a4b..401627d2c1 100644 --- a/types/elasticsearch/index.d.ts +++ b/types/elasticsearch/index.d.ts @@ -1400,6 +1400,8 @@ export interface IndicesUpdateAliasesParamsAction { index?: string; indices?: string[]; alias: string; + routing?: string; + filter?: object; }; remove?: { index?: string; diff --git a/types/expo/expo-tests.tsx b/types/expo/expo-tests.tsx index 5bb6b5abc4..75dee784de 100644 --- a/types/expo/expo-tests.tsx +++ b/types/expo/expo-tests.tsx @@ -145,7 +145,8 @@ Audio.setAudioModeAsync({ playsInSilentModeIOS: true, interruptionModeIOS: 2, interruptionModeAndroid: 1, - allowsRecordingIOS: true + allowsRecordingIOS: true, + playThroughEarpieceAndroid: false }); Audio.setIsEnabledAsync(true); diff --git a/types/expo/index.d.ts b/types/expo/index.d.ts index b406b4e8ec..9e48e391d8 100644 --- a/types/expo/index.d.ts +++ b/types/expo/index.d.ts @@ -12,6 +12,7 @@ // Nathan Phillip Brink // Martin Olsson // Levan Basharuli +// Pavel Ihm // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -405,6 +406,9 @@ export namespace Audio { /** an enum selecting how your experience’s audio should interact with the audio from other apps on Android: */ interruptionModeAndroid: InterruptionModeAndroid; + + /** Boolean selecting if audio should go to earpiece (only on Android). */ + playThroughEarpieceAndroid: boolean; } function setIsEnabledAsync(value: boolean): Promise; @@ -566,7 +570,7 @@ export interface PlaybackStatusToSet { volume?: number; } -export type PlaybackSource = RequireSource | { uri: string } | Asset; +export type PlaybackSource = RequireSource | { uri: string, headers?: { [header: string]: string }, overrideFileExtensionAndroid?: string } | Asset; export class PlaybackObject { /** @@ -2355,7 +2359,7 @@ export namespace Calendar { /** Name for the account that owns this calendar */ ownerAccount?: string; // Android - /** Time zone for the calendar */ + /** Time zone for the calendar */ timeZone?: string; // Android /** Alarm methods that this calendar supports */ @@ -2398,7 +2402,7 @@ export namespace Calendar { /** Visible name of the event */ title?: string; - /** Location field of the event */ + /** Location field of the event */ location?: string; /** Date when the event record was created */ diff --git a/types/fabric/fabric-impl.d.ts b/types/fabric/fabric-impl.d.ts index 485a603966..39b3e45757 100644 --- a/types/fabric/fabric-impl.d.ts +++ b/types/fabric/fabric-impl.d.ts @@ -3467,7 +3467,7 @@ export class IText extends Object { * @param [endIndex] End index to get styles at * @return styles Style object at a specified (or current) index */ - getSelectionStyles(startIndex: number, endIndex: number): any; + getSelectionStyles(startIndex: number, endIndex: number, complete?: boolean): any; /** * Sets style of a current selection * @param [styles] Styles object diff --git a/types/file-type/file-type-tests.ts b/types/file-type/file-type-tests.ts index ecfd658a1a..640d2c8fb0 100644 --- a/types/file-type/file-type-tests.ts +++ b/types/file-type/file-type-tests.ts @@ -2,3 +2,5 @@ import fileType = require("file-type"); fileType(new Buffer([0xFF, 0xD8, 0xFF])); fileType(new Uint8Array([0xFF, 0xD8, 0xFF])); + +const minimumBytes: number = fileType.minimumBytes; diff --git a/types/file-type/index.d.ts b/types/file-type/index.d.ts index c7f95c256e..2a0deee26a 100644 --- a/types/file-type/index.d.ts +++ b/types/file-type/index.d.ts @@ -15,4 +15,6 @@ declare namespace FileType { ext: string; mime: string; } + + const minimumBytes: number; } diff --git a/types/google-map-react/index.d.ts b/types/google-map-react/index.d.ts index a917ae426e..56686c94c1 100644 --- a/types/google-map-react/index.d.ts +++ b/types/google-map-react/index.d.ts @@ -131,6 +131,9 @@ export interface Props { onChildClick?(hoverKey: any, childProps: any): void; onChildMouseEnter?(hoverKey: any, childProps: any): void; onChildMouseLeave?(hoverKey: any, childProps: any): void; + onChildMouseDown?(childKey: any, childProps: any, mouse: any): void; + onChildMouseUp?(childKey: any, childProps: any, mouse: any): void; + onChildMouseMove?(childKey: any, childProps: any, mouse: any): void; onDrag?(args: any): void; onZoomAnimationStart?(args: any): void; onZoomAnimationEnd?(args: any): void; diff --git a/types/got/got-tests.ts b/types/got/got-tests.ts index 934adfc9a8..55680e7d27 100644 --- a/types/got/got-tests.ts +++ b/types/got/got-tests.ts @@ -269,3 +269,4 @@ got('http://todomvc.com', { retry: 2 }); got('http://todomvc.com', { retry: { retries: 2, methods: ['GET'], statusCodes: [408, 504], maxRetryAfter: 1 } }); got('http://todomvc.com', { throwHttpErrors: false }); got('http://todomvc.com', { hooks: { beforeRequest: [ () => 'foo']} }); +got('http://todomvc.com', { timeout: 1 }).catch((e) => e instanceof got.TimeoutError); diff --git a/types/got/index.d.ts b/types/got/index.d.ts index 6b0929fdcf..d0cfc682dc 100644 --- a/types/got/index.d.ts +++ b/types/got/index.d.ts @@ -53,6 +53,10 @@ declare class CancelError extends StdError { name: 'CancelError'; } +declare class TimeoutError extends StdError { + name: 'TimeoutError'; +} + declare class StdError extends Error { code?: string; host?: string; @@ -75,6 +79,7 @@ declare const got: got.GotFn & MaxRedirectsError: typeof MaxRedirectsError; UnsupportedProtocolError: typeof UnsupportedProtocolError; CancelError: typeof CancelError; + TimeoutError: typeof TimeoutError; }; interface InternalRequestOptions extends https.RequestOptions { @@ -215,7 +220,7 @@ declare namespace got { removeListener(event: 'uploadProgress', listener: (progress: Progress) => void): this; } - type GotError = RequestError | ReadError | ParseError | HTTPError | MaxRedirectsError | UnsupportedProtocolError | CancelError; + type GotError = RequestError | ReadError | ParseError | HTTPError | MaxRedirectsError | UnsupportedProtocolError | CancelError | TimeoutError; interface Progress { percent: number; diff --git a/types/grecaptcha/grecaptcha-tests.ts b/types/grecaptcha/grecaptcha-tests.ts index 288836d6b3..970660cc6c 100644 --- a/types/grecaptcha/grecaptcha-tests.ts +++ b/types/grecaptcha/grecaptcha-tests.ts @@ -18,11 +18,15 @@ const badge1: ReCaptchaV2.Badge = "bottomleft"; const badge2: ReCaptchaV2.Badge = "bottomright"; const badge3: ReCaptchaV2.Badge = "inline"; -const invisibleParams: ReCaptchaV2.Parameters = { +const invisibleParams1: ReCaptchaV2.Parameters = { sitekey: "siteKey", badge: badge1, }; +const invisibleParams2: ReCaptchaV2.Parameters = { + badge: badge2, +}; + const id1: number = grecaptcha.render("foo"); const id2: number = grecaptcha.render("foo", params); const id3: number = grecaptcha.render(document.getElementById("foo")); diff --git a/types/grecaptcha/index.d.ts b/types/grecaptcha/index.d.ts index c9dedbfb74..4430aa90e9 100644 --- a/types/grecaptcha/index.d.ts +++ b/types/grecaptcha/index.d.ts @@ -46,7 +46,7 @@ declare namespace ReCaptchaV2 { /** * Your sitekey. */ - sitekey: string; + sitekey?: string; /** * Optional. The color theme of the widget. * Accepted values: "light", "dark" diff --git a/types/i18next/index.d.ts b/types/i18next/index.d.ts index 84433c26ec..d2e0b4ee6b 100644 --- a/types/i18next/index.d.ts +++ b/types/i18next/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for i18next 11.9 +// Type definitions for i18next 12.1 // Project: http://i18next.com // Definitions by: Michael Ledin // Budi Irawan @@ -160,6 +160,12 @@ declare namespace i18next { */ resources?: Resource; + /** + * Allow initializing with bundled resources while using a backend to load non bundled ones. + * @default false + */ + partialBundledLanguages?: boolean; + /** * language to use (overrides language detection) * @default undefined diff --git a/types/ini/index.d.ts b/types/ini/index.d.ts index f534ff1b8d..4efacfe182 100644 --- a/types/ini/index.d.ts +++ b/types/ini/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for ini v1.3.3 // Project: https://github.com/isaacs/ini // Definitions by: Marcin Porębski +// Chris Arnesen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped interface EncodeOptions { @@ -8,9 +9,13 @@ interface EncodeOptions { whitespace: boolean } -export function decode(inistring: string): any; -export function parse(initstring: string): any; -export function encode(object: any, options?: EncodeOptions): string; -export function stringify(object: any, options?: EncodeOptions): string; +export function decode(str: string): { + [key: string]: any; +}; +export function parse(str: string): { + [key: string]: any; +}; +export function encode(object: any, options?: EncodeOptions | string): string; +export function stringify(object: any, options?: EncodeOptions | string): string; export function safe(val: string): string; export function unsafe(val: string): string; diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 2b378a6048..d434b5e198 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -251,7 +251,7 @@ declare namespace jest { * @param fn The function for your test * @param timeout The timeout for an async function test */ - (name: string, fn: ProvidesCallback, timeout?: number): void; + (name: string, fn?: ProvidesCallback, timeout?: number): void; /** * Only runs this test in the current file. */ diff --git a/types/johnny-five/index.d.ts b/types/johnny-five/index.d.ts index 6a00952153..a770cd2126 100644 --- a/types/johnny-five/index.d.ts +++ b/types/johnny-five/index.d.ts @@ -365,22 +365,22 @@ export declare class LCD { rows: number; cols: number; - print(message: string): void; - useChar(char: string): void; - clear(): void; - cursor(row: number, col: number): void; - home(): void; - on(): void; - off(): void; - display(): void; - noDisplay(): void; - blink(): void; - noBlink(): void; - autoscroll(): void; - noAutoscroll(): void; - bgColor(color: any): void; - noBacklight(): void; - backlight(): void; + print(message: string): this; + useChar(char: string): this; + clear(): this; + cursor(row: number, col: number): this; + home(): this; + on(): this; + off(): this; + display(): this; + noDisplay(): this; + blink(): this; + noBlink(): this; + autoscroll(): this; + noAutoscroll(): this; + bgColor(color: any): this; + noBacklight(): this; + backlight(): this; } export interface LedOption { diff --git a/types/mapbox/index.d.ts b/types/mapbox/index.d.ts index 334d644e21..97da469e4a 100644 --- a/types/mapbox/index.d.ts +++ b/types/mapbox/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for Mapbox 1.6 // Project: https://www.mapbox.com/mapbox.js/ // Definitions by: Maxime Fabre +// Florian Luccioni // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -153,6 +154,20 @@ declare global { getGeoJSON(): any; } + // StyleLayer + ////////////////////////////////////////////////////////////////////// + + /** + * L.mapbox.styleLayer provides a way to integrate styles created with Mapbox Studio into your map. + */ + function styleLayer(url: string, options?: StyleLayerOptions): StyleLayer; + + interface StyleLayerOptions extends Leaflet.TileLayerOptions { + sanitizer?(template: string): string; + } + + type StyleLayer = Leaflet.TileLayer; + ////////////////////////////////////////////////////////////////////// ////////////////////////////// GEOCODING ///////////////////////////// ////////////////////////////////////////////////////////////////////// diff --git a/types/mapbox/mapbox-tests.ts b/types/mapbox/mapbox-tests.ts index ab9ad6c5de..a9610ba5c4 100644 --- a/types/mapbox/mapbox-tests.ts +++ b/types/mapbox/mapbox-tests.ts @@ -4,6 +4,8 @@ const mapboxTiles = L.tileLayer('https://{s}.tiles.mapbox.com/v3/examples.map-i8 const map = L.map('map').addLayer(mapboxTiles).setView(new L.LatLng([42.3610, -71.0587]), 15); +const lightTiles = L.mapbox.styleLayer('mapbox://styles/mapbox/light-v9').addTo(map); + const coordinates = document.getElementById('coordinates'); const marker = L.marker(new L.LatLng([0, 0]), { diff --git a/types/meteor/test/globals/meteor-tests.ts b/types/meteor/test/globals/meteor-tests.ts index 782701086f..e3a3e750bb 100644 --- a/types/meteor/test/globals/meteor-tests.ts +++ b/types/meteor/test/globals/meteor-tests.ts @@ -371,19 +371,19 @@ Comments.find({ viewNumber: { $gt: 100 } }); Comments.find({ viewNumber: { $not: { $lt: 100, $gt: 1000 } } }); Comments.find({ tags: { $in: [ "tag-1", "tag-2", "tag-3" ] } }); Comments.find({ $or: [ { text: "hello" }, { text: "world" } ] }); -Comments.find({ $or: [ - { text: "hello" }, - { text: "world", viewNumber: { $gt: 0 } } +Comments.find({ $or: [ + { text: "hello" }, + { text: "world", viewNumber: { $gt: 0 } } ], authorId: "test-author-id" }); -Comments.find({ $and: [ - { $or: [{ authorId: "author-id-1" }, { authorId: "author-id-2" }] }, +Comments.find({ $and: [ + { $or: [{ authorId: "author-id-1" }, { authorId: "author-id-2" }] }, { $or: [{ tags: "tag-1" }, { tags: "tag-2" }] } ]}); Comments.find({ $query: {inlineLinks: { $exists: true, $type: "array" } } }); -Comments.find({ inlineLinks: { $elemMatch: { - objectType: InlineObjectType.Image, - objectUrl: { $regex: "https://(www\.?)youtube\.com" } +Comments.find({ inlineLinks: { $elemMatch: { + objectType: InlineObjectType.Image, + objectUrl: { $regex: "https://(www\.?)youtube\.com" } } } }); Comments.find({ "inlineLinks.objectType": InlineObjectType.Person }); Comments.find({ tags: "tag-1" }); diff --git a/types/meteor/test/meteor-tests.ts b/types/meteor/test/meteor-tests.ts index b45284df52..63f83ef79d 100644 --- a/types/meteor/test/meteor-tests.ts +++ b/types/meteor/test/meteor-tests.ts @@ -383,19 +383,19 @@ Comments.find({ viewNumber: { $gt: 100 } }); Comments.find({ viewNumber: { $not: { $lt: 100, $gt: 1000 } } }); Comments.find({ tags: { $in: [ "tag-1", "tag-2", "tag-3" ] } }); Comments.find({ $or: [ { text: "hello" }, { text: "world" } ] }); -Comments.find({ $or: [ - { text: "hello" }, - { text: "world", viewNumber: { $gt: 0 } } +Comments.find({ $or: [ + { text: "hello" }, + { text: "world", viewNumber: { $gt: 0 } } ], authorId: "test-author-id" }); -Comments.find({ $and: [ - { $or: [{ authorId: "author-id-1" }, { authorId: "author-id-2" }] }, +Comments.find({ $and: [ + { $or: [{ authorId: "author-id-1" }, { authorId: "author-id-2" }] }, { $or: [{ tags: "tag-1" }, { tags: "tag-2" }] } ]}); Comments.find({ $query: { inlineLinks: { $exists: true, $type: "array" } } }); -Comments.find({ inlineLinks: { $elemMatch: { - objectType: InlineObjectType.Image, - objectUrl: { $regex: "https://(www\.?)youtube\.com" } +Comments.find({ inlineLinks: { $elemMatch: { + objectType: InlineObjectType.Image, + objectUrl: { $regex: "https://(www\.?)youtube\.com" } } } }); Comments.find({ "inlineLinks.objectType": InlineObjectType.Person }); Comments.find({ tags: "tag-1" }); diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index ab4d2f4c02..b31a8dd7b9 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -79,7 +79,7 @@ export interface ClientSession extends EventEmitter { /** The server id associated with this session */ id: any; /** - * Aborts the currently active transaction in this session. + * Aborts the currently active transaction in this session. * @param {MongoCallback} [cb] Optional callback for completion of this operation */ abortTransaction(cb?: MongoCallback): Promise; @@ -89,7 +89,7 @@ export interface ClientSession extends EventEmitter { */ advanceOperationTime(operamtionTime: Timestamp): void; /** - * Commits the currently active transaction in this session. + * Commits the currently active transaction in this session. * @param {MongoCallback} [cb] Optional callback for completion of this operation */ commitTransaction(cb?: MongoCallback): Promise; @@ -110,7 +110,7 @@ export interface ClientSession extends EventEmitter { * Used to determine if this session equals another * * @param {ClientSession} session A class representing a client session on the server - * @returns {boolean} if the sessions are equal + * @returns {boolean} if the sessions are equal */ equals(session: ClientSession): boolean; @@ -118,13 +118,13 @@ export interface ClientSession extends EventEmitter { incrementTransactionNumber(): void; /** - * @returns {boolean} this session is currently in a transaction or not + * @returns {boolean} this session is currently in a transaction or not */ inTransaction(): boolean; /** * Starts a new transaction with the given options. - * @param {TransactionOptions} options + * @param {TransactionOptions} options * @memberof ClientSession */ startTransaction(options?: TransactionOptions): void; @@ -219,10 +219,10 @@ export class MongoError extends Error { * client/user (eg. "Email address must be unique" instead of "Both email * address and username must be unique") - which caters for a better (app) * user experience. - * + * * Details: https://github.com/Automattic/mongoose/issues/2129 (issue for * mongoose, but the same applies for the native mongodb driver) - * + * * Note that in mongoose (the link above) the prop in question is called * 'message' while in mongodb it is called 'errmsg'. This can be seen in * multiple places in the source code, for example here: @@ -231,6 +231,7 @@ export class MongoError extends Error { errmsg?: string; } + /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#.connect */ export interface MongoClientOptions extends DbCreateOptions, @@ -240,57 +241,120 @@ export interface MongoClientOptions extends SocketOptions, SSLOptions, HighAvailabilityOptions { - // The logging level (error/warn/info/debug) + + /** + * The logging level (error/warn/info/debug) + */ loggerLevel?: string; - // Custom logger object - logger?: Object; - // Default: false; + + /** + * Custom logger object + */ + logger?: Object | log; + + /** + * Validate MongoClient passed in options for correctness. + * Default: false + */ validateOptions?: Object; - // The name of the application that created this MongoClient instance. + + /** + * The name of the application that created this MongoClient instance. + */ appname?: string; + + /** + * Authentifikation credentials + */ auth?: { + /** + * The username for auth + */ user: string; + /** + * The password for auth + */ password: string; - }, - // Determines whether or not to use the new url parser - useNewUrlParser?: boolean + }; + + /** + * Determines whether or not to use the new url parser + */ + useNewUrlParser?: boolean; + + /** + * Mechanism for authentication: DEFAULT, GSSAPI, PLAIN, MONGODB-X509, 'MONGODB-CR', SCRAM-SHA-1 or SCRAM-SHA-256 + */ + authMechanism?: 'DEFAULT' | 'GSSAPI' | 'PLAIN' | 'MONGODB-X509' | 'MONGODB-CR' | 'SCRAM-SHA-1' | 'SCRAM-SHA-256' | string; } export interface SSLOptions { - // Passed directly through to tls.createSecureContext. See https://nodejs.org/dist/latest-v9.x/docs/api/tls.html#tls_tls_createsecurecontext_options for more info. + /** + * Passed directly through to tls.createSecureContext. See https://nodejs.org/dist/latest-v9.x/docs/api/tls.html#tls_tls_createsecurecontext_options for more info. + */ ciphers?: string; - // Passed directly through to tls.createSecureContext. See https://nodejs.org/dist/latest-v9.x/docs/api/tls.html#tls_tls_createsecurecontext_options for more info. + /** + * Passed directly through to tls.createSecureContext. See https://nodejs.org/dist/latest-v9.x/docs/api/tls.html#tls_tls_createsecurecontext_options for more info. + */ ecdhCurve?: string; - // Default:5; Number of connections for each server instance + /** + * Default:5; Number of connections for each server instance + */ poolSize?: number; - // If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections + /** + * If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections + */ minSize?: number; - // Use ssl connection (needs to have a mongod server with ssl support) + /** + * Use ssl connection (needs to have a mongod server with ssl support) + */ ssl?: boolean; - // Default: true; Validate mongod server certificate against ca (mongod server >=2.4 with ssl support required) + /** + * Default: true; Validate mongod server certificate against ca (mongod server >=2.4 with ssl support required) + */ sslValidate?: boolean; - // Default: true; Server identity checking during SSL + /** + * Default: true; Server identity checking during SSL + */ checkServerIdentity?: boolean | Function; - // Array of valid certificates either as Buffers or Strings + /** + * Array of valid certificates either as Buffers or Strings + */ sslCA?: Array; - // SSL Certificate revocation list binary buffer + /** + * SSL Certificate revocation list binary buffer + */ sslCRL?: Array; - // SSL Certificate binary buffer + /** + * SSL Certificate binary buffer + */ sslCert?: Buffer | string; - // SSL Key file binary buffer + /** + * SSL Key file binary buffer + */ sslKey?: Buffer | string; - // SSL Certificate pass phrase + /** + * SSL Certificate pass phrase + */ sslPass?: Buffer | string; - // String containing the server name requested via TLS SNI. + /** + * String containing the server name requested via TLS SNI. + */ servername?: string; } export interface HighAvailabilityOptions { - // Default: true; Turn on high availability monitoring. + /** + * Default: true; Turn on high availability monitoring. + */ ha?: boolean; - // Default: 10000; The High availability period for replicaset inquiry + /** + * Default: 10000; The High availability period for replicaset inquiry + */ haInterval?: number; - // Default: false; + /** + * Default: false; + */ domainsEnabled?: boolean; } @@ -299,7 +363,12 @@ export class ReadPreference { constructor(mode: string, tags: Object); mode: string; tags: any; - options: { maxStalenessSeconds?: number }; // Max Secondary Read Stalleness in Seconds + options: { + /** + * Max Secondary Read Stalleness in Seconds + */ + maxStalenessSeconds?: number + }; static PRIMARY: string; static PRIMARY_PREFERRED: string; static SECONDARY: string; @@ -311,86 +380,156 @@ export class ReadPreference { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html */ export interface DbCreateOptions extends CommonOptions { - // If the database authentication is dependent on another databaseName. + /** + * If the database authentication is dependent on another databaseName. + */ authSource?: string; - // Default: false; Force server to create _id fields instead of client. + /** + * Default: false; Force server to create _id fields instead of client. + */ forceServerObjectId?: boolean; - // Default: false; Use c++ bson parser. + /** + * Default: false; Use c++ bson parser. + */ native_parser?: boolean; - // Serialize functions on any object. + /** + * Serialize functions on any object. + */ serializeFunctions?: boolean; - // Specify if the BSON serializer should ignore undefined fields. + /** + * Specify if the BSON serializer should ignore undefined fields. + */ ignoreUndefined?: boolean; - // Return document results as raw BSON buffers. + /** + * Return document results as raw BSON buffers. + */ raw?: boolean; - // Default: true; Promotes Long values to number if they fit inside the 53 bits resolution. + /** + * Default: true; Promotes Long values to number if they fit inside the 53 bits resolution. + */ promoteLongs?: boolean; - // Default: false; Promotes Binary BSON values to native Node Buffers + /** + * Default: false; Promotes Binary BSON values to native Node Buffers + */ promoteBuffers?: boolean; - // the prefered read preference. use 'ReadPreference' class. + /** + * the prefered read preference. use 'ReadPreference' class. + */ readPreference?: ReadPreference | string; - // Default: true; Promotes BSON values to native types where possible, set to false to only receive wrapper types. + /** + * Default: true; Promotes BSON values to native types where possible, set to false to only receive wrapper types. + */ promoteValues?: Object; - // Custom primary key factory to generate _id values (see Custom primary keys). + /** + * Custom primary key factory to generate _id values (see Custom primary keys). + */ pkFactory?: Object; - // ES6 compatible promise constructor + /** + * ES6 compatible promise constructor + */ promiseLibrary?: Object; - /** https://docs.mongodb.com/manual/reference/read-concern/#read-concern */ + /** + * https://docs.mongodb.com/manual/reference/read-concern/#read-concern + **/ readConcern?: ReadConcern; - // Sets a cap on how many operations the driver will buffer up before giving up on getting a - // working connection, default is -1 which is unlimited. + /** + * Sets a cap on how many operations the driver will buffer up before giving up on getting a + * working connection, default is -1 which is unlimited. + */ bufferMaxEntries?: number; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Server.html */ export interface SocketOptions { - // Reconnect on error. default:false + /** + * Reconnect on error. default:false + */ autoReconnect?: boolean; - // TCP Socket NoDelay option. default:true + /** + * TCP Socket NoDelay option. default:true + */ noDelay?: boolean; - // TCP KeepAlive enabled on the socket. default:true + /** + * TCP KeepAlive enabled on the socket. default:true + */ keepAlive?: boolean; - // TCP KeepAlive initial delay before sending first keep-alive packet when idle. default:300000 + /** + * TCP KeepAlive initial delay before sending first keep-alive packet when idle. default:300000 + */ keepAliveInitialDelay?: number; - // TCP Connection timeout setting. default 0 + /** + * TCP Connection timeout setting. default 0 + */ connectTimeoutMS?: number; - // Version of IP stack. Can be 4, 6 or null. default: null. - // If null, will attempt to connect with IPv6, and will fall back to IPv4 on failure - // refer to http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html + /** + * Version of IP stack. Can be 4, 6 or null. default: null. + * + * If null, will attempt to connect with IPv6, and will fall back to IPv4 on failure + * refer to http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html + */ family?: 4 | 6 | null; - // TCP Socket timeout setting. default 0 + /** + * TCP Socket timeout setting. default 0 + */ socketTimeoutMS?: number; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Server.html */ export interface ServerOptions extends SSLOptions { - // Default: 30; + /** + * Default: 30; + */ reconnectTries?: number; - // Default: 1000; + /** + * Default: 1000; + */ reconnectInterval?: number; - // Default: true; + /** + * Default: true; + */ monitoring?: boolean + + /** + * Socket Options + */ socketOptions?: SocketOptions; - // Default: 10000; The High availability period for replicaset inquiry + + /** + * Default: 10000; The High availability period for replicaset inquiry + */ haInterval?: number; - // Default: false; + /** + * Default: false; + */ domainsEnabled?: boolean; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Mongos.html */ export interface MongosOptions extends SSLOptions, HighAvailabilityOptions { - // Default: 15; Cutoff latency point in MS for MongoS proxy selection + /** + * Default: 15; Cutoff latency point in MS for MongoS proxy selection + */ acceptableLatencyMS?: number; + + /** + * Socket Options + */ socketOptions?: SocketOptions; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/ReplSet.html */ export interface ReplSetOptions extends SSLOptions, HighAvailabilityOptions { - // The max staleness to secondary reads (values under 10 seconds cannot be guaranteed); + /** + * The max staleness to secondary reads (values under 10 seconds cannot be guaranteed); + */ maxStalenessSeconds?: number; - // The name of the replicaset to connect to. + /** + * The name of the replicaset to connect to. + */ replicaSet?: string; - // Default: 15 ; Range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms) + /** + * Default: 15 ; Range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms) + */ secondaryAcceptableLatencyMS?: number; connectWithNoPrimary?: boolean; socketOptions?: SocketOptions; @@ -482,28 +621,40 @@ export interface CommonOptions extends WriteConcern { session?: ClientSession; } -// Deprecated http://mongodb.github.io/node-mongodb-native/3.1/api/Server.html +/** + * @deprecated + * @see http://mongodb.github.io/node-mongodb-native/3.1/api/Server.html + */ export class Server extends EventEmitter { constructor(host: string, port: number, options?: ServerOptions); connections(): Array; } -// Deprecated http://mongodb.github.io/node-mongodb-native/3.1/api/ReplSet.html +/** + * @deprecated + * @see http://mongodb.github.io/node-mongodb-native/3.1/api/ReplSet.html + */ export class ReplSet extends EventEmitter { constructor(servers: Array, options?: ReplSetOptions); connections(): Array; } -// Deprecated http://mongodb.github.io/node-mongodb-native/3.1/api/ReplSet.html +/** + * @deprecated + * @see http://mongodb.github.io/node-mongodb-native/3.1/api/Mongos.html + */ export class Mongos extends EventEmitter { constructor(servers: Array, options?: MongosOptions); connections(): Array; } -/** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#addUser */ +/** + * @deprecated + * @see http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#addUser + */ export interface DbAddUserOptions extends CommonOptions { customData?: Object; roles?: Object[]; @@ -543,27 +694,48 @@ export interface DbCollectionOptions extends CommonOptions { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#createIndex */ export interface IndexOptions extends CommonOptions { - // Creates an unique index. + /** + * Creates an unique index. + */ unique?: boolean; - // Creates a sparse index. + /** + * Creates a sparse index. + */ sparse?: boolean; - // Creates the index in the background, yielding whenever possible. + /** + * Creates the index in the background, yielding whenever possible. + */ background?: boolean; - // A unique index cannot be created on a key that has pre-existing duplicate values. - // If you would like to create the index anyway, keeping the first document the database indexes and - // deleting all subsequent documents that have duplicate value + /** + * A unique index cannot be created on a key that has pre-existing duplicate values. + * + * If you would like to create the index anyway, keeping the first document the database indexes and + * deleting all subsequent documents that have duplicate value + */ dropDups?: boolean; - // For geo spatial indexes set the lower bound for the co-ordinates. + /** + * For geo spatial indexes set the lower bound for the co-ordinates. + */ min?: number; - // For geo spatial indexes set the high bound for the co-ordinates. + /** + * For geo spatial indexes set the high bound for the co-ordinates. + */ max?: number; - // Specify the format version of the indexes. + /** + * Specify the format version of the indexes. + */ v?: number; - // Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher) + /** + * Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher) + */ expireAfterSeconds?: number; - // Override the auto generated index name (useful if the resulting name is larger than 128 bytes) + /** + * Override the auto generated index name (useful if the resulting name is larger than 128 bytes) + */ name?: string; - // Creates a partial index based on the given filter object (MongoDB 3.2 or higher) + /** + * Creates a partial index based on the given filter object (MongoDB 3.2 or higher) + */ partialFilterExpression?: any; collation?: Object; default_language?: string @@ -619,17 +791,27 @@ export interface FSyncOptions extends CommonOptions { fsync?: boolean } -// Documentation : http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html +/** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html */ export interface Collection { - // Get the collection name. + /** + * Get the collection name. + */ collectionName: string; - // Get the full collection namespace. + /** + * Get the full collection namespace. + */ namespace: string; - // The current write concern values. + /** + * The current write concern values. + */ writeConcern: any; - // The current read concern values. + /** + * The current read concern values. + */ readConcern: ReadConcern; - // Get current index hint for collection. + /** + * Get current index hint for collection. + */ hint: any; /** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#aggregate */ aggregate(callback: MongoCallback>): AggregationCursor; @@ -880,40 +1062,70 @@ export type FilterQuery = { [P in keyof T]?: T[P] | Condition; } | { [key: string]: any }; -// Documentation: http://docs.mongodb.org/manual/reference/command/collStats/ +/** http://docs.mongodb.org/manual/reference/command/collStats/ */ export interface CollStats { - // Namespace. + /** + * Namespace. + */ ns: string; - // Number of documents. + /** + * Number of documents. + */ count: number; - // Collection size in bytes. + /** + * Collection size in bytes. + */ size: number; - // Average object size in bytes. + /** + * Average object size in bytes. + */ avgObjSize: number; - // (Pre)allocated space for the collection in bytes. + /** + * (Pre)allocated space for the collection in bytes. + */ storageSize: number; - // Number of extents (contiguously allocated chunks of datafile space). + /** + * Number of extents (contiguously allocated chunks of datafile space). + */ numExtents: number; - // Number of indexes. + /** + * Number of indexes. + */ nindexes: number; - // Size of the most recently created extent in bytes. + /** + * Size of the most recently created extent in bytes. + */ lastExtentSize: number; - // Padding can speed up updates if documents grow. + /** + * Padding can speed up updates if documents grow. + */ paddingFactor: number; - // A number that indicates the user-set flags on the collection. userFlags only appears when using the mmapv1 storage engine. + /** + * A number that indicates the user-set flags on the collection. userFlags only appears when using the mmapv1 storage engine. + */ userFlags?: number; - // Total index size in bytes. + /** + * Total index size in bytes. + */ totalIndexSize: number; - // Size of specific indexes in bytes. + /** + * Size of specific indexes in bytes. + */ indexSizes: { _id_: number; [index: string]: number; }; - // `true` if the collection is capped. + /** + * `true` if the collection is capped. + */ capped: boolean; - // The maximum number of documents that may be present in a capped collection. + /** + * The maximum number of documents that may be present in a capped collection. + */ max: number; - // The maximum size of a capped collection. + /** + * The maximum size of a capped collection. + */ maxSize: number; wiredTiger?: WiredTigerData; indexDetails?: any; @@ -1059,18 +1271,28 @@ export interface WiredTigerData { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#aggregate */ export interface CollectionAggregationOptions { readPreference?: ReadPreference | string; - // Return the query as cursor, on 2.6 > it returns as a real cursor - // on pre 2.6 it returns as an emulated cursor. + /** + * Return the query as cursor, on 2.6 > it returns as a real cursor + * on pre 2.6 it returns as an emulated cursor. + */ cursor?: { batchSize?: number }; - // Explain returns the aggregation execution plan (requires mongodb 2.6 >). + /** + * Explain returns the aggregation execution plan (requires mongodb 2.6 >). + */ explain?: boolean; - // lets the server know if it can use disk to store - // temporary results for the aggregation (requires mongodb 2.6 >). + /** + * Lets the server know if it can use disk to store + * temporary results for the aggregation (requires mongodb 2.6 >). + */ allowDiskUse?: boolean; - // specifies a cumulative time limit in milliseconds for processing operations - // on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. + /** + * specifies a cumulative time limit in milliseconds for processing operations + * on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. + */ maxTimeMS?: number; - // Allow driver to bypass schema validation in MongoDB 3.2 or higher. + /** + * Allow driver to bypass schema validation in MongoDB 3.2 or higher. + */ bypassDocumentValidation?: boolean; raw?: boolean; promoteLongs?: boolean; @@ -1084,23 +1306,37 @@ export interface CollectionAggregationOptions { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#insertMany */ export interface CollectionInsertManyOptions extends CommonOptions { - // Serialize functions on any object. + /** + * Serialize functions on any object. + */ serializeFunctions?: boolean; - //Force server to assign _id values instead of driver. + /** + * Force server to assign _id values instead of driver. + */ forceServerObjectId?: boolean; - // Allow driver to bypass schema validation in MongoDB 3.2 or higher. + /** + * Allow driver to bypass schema validation in MongoDB 3.2 or higher. + */ bypassDocumentValidation?: boolean; - // If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails. + /** + * If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails. + */ ordered?: boolean; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#bulkWrite */ export interface CollectionBulkWriteOptions extends CommonOptions { - // Serialize functions on any object. + /** + * Serialize functions on any object. + */ serializeFunctions?: boolean; - // Execute write operation in ordered or unordered fashion. + /** + * Execute write operation in ordered or unordered fashion. + */ ordered?: boolean; - // Allow driver to bypass schema validation in MongoDB 3.2 or higher. + /** + * Allow driver to bypass schema validation in MongoDB 3.2 or higher. + */ bypassDocumentValidation?: boolean; //Force server to assign _id values instead of driver. forceServerObjectId?: boolean; @@ -1120,13 +1356,21 @@ export interface BulkWriteOpResultObject { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#count */ export interface MongoCountPreferences { - // The limit of documents to count. + /** + * The limit of documents to count. + */ limit?: number; - // The number of documents to skip for the count. + /** + * The number of documents to skip for the count. + */ skip?: boolean; - // An index name hint for the query. + /** + * An index name hint for the query. + */ hint?: string; - // The preferred read preference + /** + * The preferred read preference + */ readPreference?: ReadPreference | string; maxTimeMS?: number; session?: ClientSession; @@ -1292,7 +1536,10 @@ export interface FindOneOptions { limit?: number; sort?: Array | Object; projection?: Object; - fields?: Object; // Deprecated Use options.projection instead + /** + * @deprecated Use options.projection instead + */ + fields?: Object; skip?: number; hint?: Object; explain?: boolean; @@ -1328,7 +1575,9 @@ export interface InsertWriteOpResult { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#insertOne */ export interface CollectionInsertOneOptions extends CommonOptions { - // Serialize functions on any object. + /** + * Serialize functions on any object. + */ serializeFunctions?: boolean; //Force server to assign _id values instead of driver. forceServerObjectId?: boolean; @@ -1683,17 +1932,29 @@ export class GridFSBucketWriteStream extends Writable { /** https://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucketWriteStream.html */ export interface GridFSBucketWriteStreamOptions { - /** Custom file id for the GridFS file. */ + /** + * Custom file id for the GridFS file. + **/ id?: GridFSBucketWriteStreamId, - /** The chunk size to use, in bytes */ + /** + * The chunk size to use, in bytes + */ chunkSizeBytes?: number, - /** The write concern */ + /** + * The write concern + */ w?: number, - /** The write concern timeout */ + /** + * The write concern timeout + */ wtimeout?: number, - /** The journal write concern */ + /** + * The journal write concern + */ j?: number - /** Default false; If true, disables adding an md5 field to file data */ + /** + * Default false; If true, disables adding an md5 field to file data + */ disableMD5?: boolean } @@ -1732,8 +1993,14 @@ export interface ChangeStreamOptions { type GridFSBucketWriteStreamId = string | number | Object | ObjectID; export interface LoggerOptions { - loggerLevel?: string // Custom logger function - logger?: log // Override default global log level. + /** + * Custom logger function + */ + loggerLevel?: string + /** + * Override default global log level. + */ + logger?: log } export type log = (message?: string, state?: LoggerState) => void @@ -1749,30 +2016,54 @@ export interface LoggerState { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Logger.html */ export class Logger { constructor(className: string, options?: LoggerOptions) - // Log a message at the debug level + /** + * Log a message at the debug level + */ debug(message: string, state: LoggerState): void - // Log a message at the warn level + /** + * Log a message at the warn level + */ warn(message: string, state: LoggerState): void - // Log a message at the info level + /** + * Log a message at the info level + */ info(message: string, state: LoggerState): void - // Log a message at the error level + /** + * Log a message at the error level + */ error(message: string, state: LoggerState): void - // Is the logger set at info level + /** + * Is the logger set at info level + */ isInfo(): boolean - // Is the logger set at error level + /** + * Is the logger set at error level + */ isError(): boolean - // Is the logger set at error level + /** + * Is the logger set at error level + */ isWarn(): boolean - // Is the logger set at debug level + /** + * Is the logger set at debug level + */ isDebug(): boolean - // Resets the logger to default settings, error and no filtered classes + /** + * Resets the logger to default settings, error and no filtered classes + */ static reset(): void - // Get the current logger function + /** + * Get the current logger function + */ static currentLogger(): log //Set the current logger function static setCurrentLogger(log: log): void - // Set what classes to log. + /** + * Set what classes to log. + */ static filter(type: string, values: string[]): void - // Set the current log level + /** + * Set the current log level + */ static setLevel(level: string): void } diff --git a/types/mongodb/mongodb-tests.ts b/types/mongodb/mongodb-tests.ts index b9b4a63c8d..ea755a8eb1 100644 --- a/types/mongodb/mongodb-tests.ts +++ b/types/mongodb/mongodb-tests.ts @@ -7,6 +7,7 @@ const connectionString = 'mongodb://127.0.0.1:27017/test'; var format = require('util').format; let options: mongodb.MongoClientOptions = { authSource: ' ', + loggerLevel: 'debug', w: 1, wtimeout: 300, j: true, @@ -21,7 +22,6 @@ let options: mongodb.MongoClientOptions = { reconnectTries: 123456, reconnectInterval: 123456, - ssl: true, sslValidate: false, checkServerIdentity: function () { }, @@ -31,12 +31,14 @@ let options: mongodb.MongoClientOptions = { sslKey: new Buffer(999), sslPass: new Buffer(999), promoteBuffers: false, - useNewUrlParser: false + useNewUrlParser: false, + authMechanism: 'SCRAM-SHA-1', + forceServerObjectId: false } MongoClient.connect(connectionString, options, function (err: mongodb.MongoError, client: mongodb.MongoClient) { if (err) throw err; const db = client.db('test'); - + var collection = db.collection('test_insert'); collection.insertOne({ a: 2 }, function (err: mongodb.MongoError, docs: any) { @@ -263,11 +265,11 @@ async function transfer(client: mongodb.MongoClient, from: any, to: any, amount: // `session.abortTransaction()` will undo the above `findOneAndUpdate()` throw new Error('Insufficient funds: ' + (A.balance + amount)); } - + const B = await db.collection('Account'). findOneAndUpdate({ name: to }, { $inc: { balance: amount } }, opts). then(res => res.value); - + await session.commitTransaction(); session.endSession(); return { from: A, to: B }; @@ -287,3 +289,4 @@ mongodb.connect(connectionString).then((client) => { ); }); + diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 5963be87ed..3672b75b8f 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -811,11 +811,11 @@ declare module "mongoose" { * @param fn callback */ post(method: string, fn: ( - error: mongodb.MongoError, doc: T, next: (err?: NativeError) => void + doc: T, next: (err?: NativeError) => void ) => void): this; post(method: string, fn: ( - doc: T, next: (err?: NativeError) => void + error: mongodb.MongoError, doc: T, next: (err?: NativeError) => void ) => void): this; /** diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index c8873f85b3..f713ba8538 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -491,12 +491,12 @@ preHookTestSchemaArr.push( ); schema -.post('save', function (error, doc, next) { +.post('save', function (error: mongoose.Error, doc: mongoose.Document, next: (err?: mongoose.NativeError) => void) { error.stack; doc.model; next.apply; }) -.post('save', function (doc: mongoose.Document, next: Function) { +.post('save', function (doc: mongoose.Document, next: (err?: mongoose.NativeError) => void) { doc.model; next(new Error()); }) diff --git a/types/mssql/index.d.ts b/types/mssql/index.d.ts index d4558737ba..891186f7ee 100644 --- a/types/mssql/index.d.ts +++ b/types/mssql/index.d.ts @@ -316,6 +316,7 @@ export declare class PreparedStatement extends events.EventEmitter { public parameters: IRequestParameters; public stream: any; public constructor(connection?: ConnectionPool); + public constructor(transaction: Transaction); public input(name: string, type: (() => ISqlType) | ISqlType): PreparedStatement; public output(name: string, type: (() => ISqlType) | ISqlType): PreparedStatement; public prepare(statement?: string): Promise; diff --git a/types/mssql/mssql-tests.ts b/types/mssql/mssql-tests.ts index 72bbc15126..18ad4b3ad9 100644 --- a/types/mssql/mssql-tests.ts +++ b/types/mssql/mssql-tests.ts @@ -189,6 +189,16 @@ function test_request_constructor() { var request4 = new sql.Request(); } +function test_prepared_statement_constructor() { + // Request can be constructed with a connection, preparedStatment, transaction or no arguments + var connection: sql.ConnectionPool = new sql.ConnectionPool(config); + var preparedStatment = new sql.PreparedStatement(connection); + var transaction = new sql.Transaction(connection); + + var preparedSatement1 = new sql.PreparedStatement(connection); + var preparedSatement2 = new sql.PreparedStatement(transaction); +} + function test_classes_extend_eventemitter() { var connection: sql.ConnectionPool = new sql.ConnectionPool(config); var transaction = new sql.Transaction(); diff --git a/types/newman/index.d.ts b/types/newman/index.d.ts index cd2801c375..7bd7aef744 100644 --- a/types/newman/index.d.ts +++ b/types/newman/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for newman 3.10 +// Type definitions for newman 3.11 // Project: https://github.com/postmanlabs/newman // Definitions by: Leonid Logvinov // Graham McGregor @@ -168,9 +168,12 @@ export interface NewmanRunExecutionAssertion { error: NewmanRunExecutionAssertionError; } export interface NewmanRunExecutionAssertionError { + name: string; + index: number; + test: string; message: string; -} -export interface NewmanRunFailure { + stack: string; +}export interface NewmanRunFailure { error: NewmanRunExecutionAssertionError; /** The event where the failure occurred */ at: string; diff --git a/types/ngeohash/index.d.ts b/types/ngeohash/index.d.ts index 25c8f29e5b..7fa05a0f4e 100644 --- a/types/ngeohash/index.d.ts +++ b/types/ngeohash/index.d.ts @@ -12,7 +12,7 @@ declare namespace ngeohash { type GeographicBoundingBox = [number, number, number, number]; type NSEW = [number, number]; - function encode(latitude: number, longitude: number, precision?: number): string; + function encode(latitude: number | string, longitude: number | string, precision?: number): string; function decode(hashstring: string): GeographicPoint; function decode_bbox(hashstring: string): GeographicBoundingBox; function bboxes(minlat: number, minlon: number, maxlat: number, maxlon: number, precision?: number): Array; diff --git a/types/ngeohash/ngeohash-tests.ts b/types/ngeohash/ngeohash-tests.ts index 34ad34d7cf..5c77ae94df 100644 --- a/types/ngeohash/ngeohash-tests.ts +++ b/types/ngeohash/ngeohash-tests.ts @@ -1,6 +1,7 @@ import geohash = require('ngeohash'); console.log(geohash.encode(37.8324, 112.5584)); +console.log(geohash.encode('37.8324', '112.5584')); // prints ww8p1r4t8 var latlon = geohash.decode('ww8p1r4t8'); diff --git a/types/noble/index.d.ts b/types/noble/index.d.ts index 61ca1f2113..5b4af235e7 100644 --- a/types/noble/index.d.ts +++ b/types/noble/index.d.ts @@ -30,6 +30,8 @@ export declare function removeListener(event: "scanStop", listener: () => void): export declare function removeListener(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter; export declare function removeListener(event: string, listener: Function): events.EventEmitter; +export declare function removeAllListeners(event?: string): events.EventEmitter; + export declare var state:string; export declare class Peripheral extends events.EventEmitter { diff --git a/types/noble/noble-tests.ts b/types/noble/noble-tests.ts index 0c8dcf6c20..a4441eba6e 100644 --- a/types/noble/noble-tests.ts +++ b/types/noble/noble-tests.ts @@ -35,6 +35,12 @@ noble.removeListener("discover", (peripheral: noble.Peripheral): void => { peripheral.disconnect((): void => {}); }); +noble.removeAllListeners("stateChange"); +noble.removeAllListeners("scanStart"); +noble.removeAllListeners("scanStop"); +noble.removeAllListeners("discover"); +noble.removeAllListeners(); + var peripheral: noble.Peripheral = new noble.Peripheral(); peripheral.uuid = "12ad4e81"; peripheral.advertisement = { diff --git a/types/node-forge/index.d.ts b/types/node-forge/index.d.ts index d362eb1c27..1a2b028a90 100644 --- a/types/node-forge/index.d.ts +++ b/types/node-forge/index.d.ts @@ -7,6 +7,7 @@ // Beeno Tung // Joe Flateau // Nikita Koryabkin +// timhwang21 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 @@ -20,6 +21,15 @@ declare module "node-forge" { type Utf8 = string; type OID = string; + namespace jsbn { + class BigInteger { + data: number[]; + t: number; + s: number; + toString(): string; + } + } + namespace pem { interface EncodeOptions { @@ -40,28 +50,18 @@ declare module "node-forge" { } namespace pki { - type PEM = string; - type Key = any; + type PublicKey = rsa.PublicKey | ed25519.Key; + type PrivateKey = rsa.PrivateKey | ed25519.Key; interface KeyPair { publicKey: PublicKey; privateKey: PrivateKey; } - interface PublicKey { - encrypt(data: string, scheme?: string, schemeOptions?: number): Bytes - verify(digest: string, signature: string, scheme?: string): boolean - } - - interface PrivateKey { - decrypt(data: string, scheme?: string, schemeOptions?: number): string - sign(md: string, scheme?: string): Bytes - } - function pemToDer(pem: PEM): util.ByteStringBuffer; function privateKeyToPem(key: PrivateKey, maxline?: number): PEM; - function privateKeyInfoToPem(key: PrivateKey, maxline?: number): PEM; + function privateKeyInfoToPem(key: Bytes, maxline?: number): PEM; function publicKeyToPem(key: PublicKey, maxline?: number): PEM; function publicKeyFromPem(pem: PEM): PublicKey; function privateKeyFromPem(pem: PEM): PrivateKey; @@ -73,7 +73,38 @@ declare module "node-forge" { } var oids: oids; + namespace ed25519 { + type Key = ArrayBuffer; + } + namespace rsa { + type EncryptionScheme = 'RSAES-PKCS1-V1_5' | 'RSA-OAEP' | 'RAW' | 'NONE' | null; + type SignatureScheme = 'RSASSA-PKCS1-V1_5' | pss.PSS | 'NONE' | null; + + interface PublicKey { + n: jsbn.BigInteger; + e: jsbn.BigInteger; + encrypt(data: Bytes, scheme?: EncryptionScheme, schemeOptions?: any): Bytes; + verify(digest: Bytes, signature: Bytes, scheme?: SignatureScheme): boolean; + } + + interface PrivateKey { + n: jsbn.BigInteger; + e: jsbn.BigInteger; + d: jsbn.BigInteger; + p: jsbn.BigInteger; + q: jsbn.BigInteger; + dP: jsbn.BigInteger; + dQ: jsbn.BigInteger; + qInv: jsbn.BigInteger; + decrypt(data: Bytes, scheme?: EncryptionScheme, schemeOptions?: any): Bytes; + sign(md: md.MessageDigest, scheme?: SignatureScheme): Bytes; + } + + interface KeyPair { + publicKey: PublicKey; + privateKey: PrivateKey; + } interface GenerateKeyPairOptions { bits?: number; @@ -84,9 +115,9 @@ declare module "node-forge" { prng?: any; algorithm?: string; } - + function setPublicKey(n: any, e: any): any; - + function generateKeyPair(bits?: number, e?: number, callback?: (err: Error, keypair: KeyPair) => void): KeyPair; function generateKeyPair(options?: GenerateKeyPairOptions, callback?: (err: Error, keypair: KeyPair) => void): KeyPair; } @@ -160,8 +191,8 @@ declare module "node-forge" { hash: any; }; extensions: any[]; - privateKey: Key; - publicKey: Key; + privateKey: PrivateKey; + publicKey: PublicKey; md: any; /** * Sets the subject of this certificate. @@ -200,7 +231,7 @@ declare module "node-forge" { * @param key the private key to sign with. * @param md the message digest object to use (defaults to forge.md.sha1). */ - sign(key: pki.Key, md: md.MessageDigest): void; + sign(key: pki.PrivateKey, md?: md.MessageDigest): void; /** * Attempts verify the signature on the passed certificate using this * certificate's public key. @@ -215,19 +246,30 @@ declare module "node-forge" { function certificateFromAsn1(obj: asn1.Asn1, computeHash?: boolean): Certificate; - function decryptRsaPrivateKey(pem: PEM, passphrase?: string): Key; + function decryptRsaPrivateKey(pem: PEM, passphrase?: string): PrivateKey; function createCertificate(): Certificate; - + function certificationRequestToPem(cert: Certificate, maxline?: number): PEM; - + function certificationRequestFromPem(pem: PEM, computeHash?: boolean, strict?: boolean): Certificate; - + function createCertificationRequest(): Certificate; - - function publicKeyToAsn1(publicKey: Key): any; - - function publicKeyToRSAPublicKey(publicKey: Key): any; + + function publicKeyToAsn1(publicKey: PublicKey): any; + + function publicKeyToRSAPublicKey(publicKey: PublicKey): any; + } + + namespace random { + function getBytes(count: number, callback?: (bytes: Bytes) => any): Bytes; + function getBytesSync(count: number): Bytes; + type CB = (_: any, seed: string) => void; + interface Random { + seedFileSync: (needed: number) => string; + seedFile: (needed: number, cb: CB) => void; + } + function createInstance(): Random; } namespace ssh { @@ -249,22 +291,22 @@ declare module "node-forge" { /** * @description Encodes a private RSA key as an OpenSSH file */ - function privateKeyToOpenSSH(privateKey: pki.Key, passphrase?: string): string; + function privateKeyToOpenSSH(privateKey: pki.PrivateKey, passphrase?: string): string; /** * @description Encodes (and optionally encrypts) a private RSA key as a Putty PPK file */ - function privateKeyToPutty(privateKey: pki.Key, passphrase?: string, comment?: string): string; + function privateKeyToPutty(privateKey: pki.PrivateKey, passphrase?: string, comment?: string): string; /** * @description Encodes a public RSA key as an OpenSSH file */ - function publicKeyToOpenSSH(publicKey: pki.Key, comment?: string): string | pki.PEM; + function publicKeyToOpenSSH(publicKey: pki.PublicKey, comment?: string): string | pki.PEM; /** * @description Gets the SSH fingerprint for the given public key */ - function getPublicKeyFingerprint(publicKey: pki.Key, options?: FingerprintOptions): util.ByteStringBuffer | Hex | string; + function getPublicKeyFingerprint(publicKey: pki.PublicKey, options?: FingerprintOptions): util.ByteStringBuffer | Hex | string; } namespace asn1 { @@ -377,7 +419,7 @@ declare module "node-forge" { function decodeUtf8(encoded: Utf8): string; function createBuffer(): ByteBuffer; - function createBuffer(input: string, encode: string): ByteBuffer; + function createBuffer(input: Bytes | ArrayBuffer | ArrayBufferView | ByteStringBuffer, encode: string): ByteBuffer; namespace binary { namespace raw { @@ -418,7 +460,7 @@ declare module "node-forge" { interface Bag { type: string; attributes: any; - key?: pki.Key; + key?: pki.PrivateKey; cert?: pki.Certificate; asn1: asn1.Asn1 } @@ -441,12 +483,12 @@ declare module "node-forge" { function pkcs12FromAsn1(obj: any, strict?: boolean, password?: string): Pkcs12Pfx; function pkcs12FromAsn1(obj: any, password?: string): Pkcs12Pfx; } - + namespace pkcs7 { interface PkcsSignedData { content?: string | util.ByteBuffer; contentInfo?: { value: any[] }; - + addCertificate(certificate: pki.Certificate): void; addSigner(options: { key: string; @@ -459,14 +501,16 @@ declare module "node-forge" { }): void; toAsn1(): asn1.Asn1; } - + function createSignedData(): PkcsSignedData; } namespace md { + type Encoding = "raw" | "utf8" + interface MessageDigest { - update(msg: string, encoding?: string): MessageDigest; + update(msg: string, encoding?: Encoding): MessageDigest; digest(): util.ByteStringBuffer; } @@ -477,7 +521,7 @@ declare module "node-forge" { namespace sha256 { function create(): MessageDigest; } - + namespace sha512 { function create(): MessageDigest; } @@ -513,18 +557,16 @@ declare module "node-forge" { tag: util.ByteStringBuffer; } } - + namespace pss { - function create(any: any): any; + type PSS = any; + + function create(any: any): PSS; } - + namespace mgf { namespace mgf1 { function create(any: any): any; } } - - namespace random { - function getBytesSync(length: number): Bytes; - } } diff --git a/types/node-forge/node-forge-tests.ts b/types/node-forge/node-forge-tests.ts index abc863f7ff..a8d352ad1a 100644 --- a/types/node-forge/node-forge-tests.ts +++ b/types/node-forge/node-forge-tests.ts @@ -8,9 +8,7 @@ let x: string = forge.ssh.privateKeyToOpenSSH(key); let pemKey: forge.pki.PEM = publicKeyPem; let publicKeyRsa = forge.pki.publicKeyFromPem(pemKey); let privateKeyRsa = forge.pki.privateKeyFromPem(privateKeyPem); -let privateKeyRsa2 = forge.pki.privateKeyInfoToPem(privateKeyRsa); let byteBufferString = forge.pki.pemToDer(privateKeyPem); -let certPem = forge.pki.certificateFromPem(pemKey); let cert = forge.pki.createCertificate(); { @@ -118,6 +116,7 @@ if (forge.util.fillString('1', 5) !== '11111') throw Error('forge.util.fillStrin } { + let key = forge.random.getBytesSync(24) let payload = { asd: 'asd' }; let cipher = forge.cipher.createCipher('3DES-ECB', forge.util.createBuffer(key, 'raw')); cipher.start(); @@ -133,7 +132,7 @@ if (forge.util.fillString('1', 5) !== '11111') throw Error('forge.util.fillStrin let decrypted = decipher.output as forge.util.ByteStringBuffer; let content = JSON.parse(forge.util.encodeUtf8(decrypted.getBytes())); - if (content.asd == payload.asd) throw Error('forge.cipher.createCipher failed'); + if (content.asd !== payload.asd) throw Error('forge.cipher.createCipher failed'); } { @@ -189,3 +188,18 @@ if (forge.util.fillString('1', 5) !== '11111') throw Error('forge.util.fillStrin // self-sign certificate cert.sign(keypair.privateKey, forge.md.sha256.create()); } + +{ + let md: forge.md.MessageDigest; + let hex: string; + let signature: forge.Bytes + + md = forge.md.sha256.create(); + md = md.update('Test'); + hex = md.digest().toHex(); + + signature = keypair.privateKey.sign(md) + if (!keypair.publicKey.verify(md.digest().bytes(), signature)) { + throw Error("rsa signature verification fail"); + } +} diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 0f6698035d..47cfea335e 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -2501,7 +2501,9 @@ declare module "readline" { } declare module "vm" { - interface Context { } + interface Context { + [key: string]: any; + } interface BaseOptions { /** * Specifies the filename used in stack traces produced by this script. diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index c59ed08064..c0f80728fc 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -3677,6 +3677,12 @@ import * as p from "process"; function test() { throw new repl.Recoverable(new Error("test")); } + + _server.context['key0'] = 1; + _server.context['key1'] = ""; + _server.context['key2'] = true; + _server.context['key3'] = []; + _server.context['key4'] = {}; } } diff --git a/types/node/v9/index.d.ts b/types/node/v9/index.d.ts index 4678c59c74..3660d87725 100644 --- a/types/node/v9/index.d.ts +++ b/types/node/v9/index.d.ts @@ -2390,7 +2390,9 @@ declare module "readline" { } declare module "vm" { - export interface Context { } + export interface Context { + [key: string]: any; + } export interface ScriptOptions { filename?: string; lineOffset?: number; diff --git a/types/oauth2-server/index.d.ts b/types/oauth2-server/index.d.ts index 27a863051f..a846c489a2 100644 --- a/types/oauth2-server/index.d.ts +++ b/types/oauth2-server/index.d.ts @@ -2,7 +2,8 @@ // Project: https://github.com/oauthjs/node-oauth2-server // Definitions by: Robbie Van Gorkom , // Charles Irick , -// Daniel Fischer +// Daniel Fischer , +// Vitor Santos // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -112,6 +113,56 @@ declare namespace OAuth2Server { redirect(url: string): void; } + abstract class AbstractGrantType { + /** + * Instantiates AbstractGrantType using the supplied options. + * + */ + constructor(options: TokenOptions) + + /** + * Generate access token. Calls Model#generateAccessToken() if implemented. + * + */ + generateAccessToken(client: Client, user: User, scope: string | string[]): Promise; + + /** + * Generate refresh token. Calls Model#generateRefreshToken() if implemented. + * + */ + generateRefreshToken(client: Client, user: User, scope: string | string[]): Promise; + + /** + * Get access token expiration date. + * + */ + getAccessTokenExpiresAt(): Date; + + /** + * Get refresh token expiration date. + * + */ + getRefreshTokenExpiresAt(): Date; + + /** + * Get scope from the request body. + * + */ + getScope(request: Request): string; + + /** + * Validate requested scope. Calls Model#validateScope() if implemented. + * + */ + validateScope(user: User, client: Client, scope: string | string[]): Promise; + + /** + * Retrieve info from the request and client and return token + * + */ + abstract handle(request: Request, client: Client): Promise; + } + interface ServerOptions extends AuthenticateOptions, AuthorizeOptions, TokenOptions { /** * Model object @@ -183,6 +234,11 @@ declare namespace OAuth2Server { * Always revoke the used refresh token and issue a new one for the refresh_token grant. */ alwaysIssueNewRefreshToken?: boolean; + + /** + * Additional supported grant types. + */ + extendedGrantTypes?: { [key: string]: typeof AbstractGrantType }; } /** diff --git a/types/office-js/index.d.ts b/types/office-js/index.d.ts index ceb6f2263b..616f8fe12b 100644 --- a/types/office-js/index.d.ts +++ b/types/office-js/index.d.ts @@ -21758,18 +21758,19 @@ declare namespace Excel { interface BasicDataValidation { /** * - * Gets or sets the Formula1, i.e. minimum value or value depending of the operator. - When setting the value, it can be passed in as a number, a range object, or a string formula (where the string is either a stringified number, a cell reference like "=A1", or a formula like "=MIN(A1, B1)"). - When retrieving the value, it will always be returned as a string formula, for example: "=10", "=A1", "=SUM(A1:B5)", etc. + * Specifies the right-hand operand when the operator property is set to a binary operator such as GreaterThan (the left-hand operand is the value the user tries to enter in the cell). With the ternary operators Between and NotBetween, specifies the lower bound operand. + * For example, setting formula1 to 10 and operator to GreaterThan means that valid data for the range must be greater than 10. + * When setting the value, it can be passed in as a number, a range object, or a string formula (where the string is either a stringified number, a cell reference like "=A1", or a formula like "=MIN(A1, B1)"). + * When retrieving the value, it will always be returned as a string formula, for example: "=10", "=A1", "=SUM(A1:B5)", etc. * * [Api set: ExcelApi 1.8] */ formula1: string | number | Range; /** * - * Gets or sets the Formula2, i.e. maximum value or value depending of the operator. - When setting the value, it can be passed in as a number, a range object, or a string formula (where the string is either a stringified number, a cell reference like "=A1", or a formula like "=MIN(A1, B1)"). - When retrieving the value, it will always be returned as a string formula, for example: "=10", "=A1", "=SUM(A1:B5)", etc. + * With the ternary operators Between and NotBetween, specifies the upper bound operand. Is not used with the binary operators, such as GreaterThan. + * When setting the value, it can be passed in as a number, a range object, or a string formula (where the string is either a stringified number, a cell reference like "=A1", or a formula like "=MIN(A1, B1)"). + * When retrieving the value, it will always be returned as a string formula, for example: "=10", "=A1", "=SUM(A1:B5)", etc. * * [Api set: ExcelApi 1.8] */ @@ -21791,18 +21792,18 @@ declare namespace Excel { interface DateTimeDataValidation { /** * - * Gets or sets the Formula1, i.e. minimum value or value depending of the operator. - When setting the value, it can be passed in as a Date, a Range object, or a string formula (where the string is either a stringified date/time in ISO8601 format, a cell reference like "=A1", or a formula like "=MIN(A1, B1)"). - When retrieving the value, it will always be returned as a string formula, for example: "=10", "=A1", "=SUM(A1:B5)", etc. + * Specifies the right-hand operand when the operator property is set to a binary operator such as GreaterThan (the left-hand operand is the value the user tries to enter in the cell). With the ternary operators Between and NotBetween, specifies the lower bound operand. + * When setting the value, it can be passed in as a Date, a Range object, or a string formula (where the string is either a stringified date/time in ISO8601 format, a cell reference like "=A1", or a formula like "=MIN(A1, B1)"). + * When retrieving the value, it will always be returned as a string formula, for example: "=10", "=A1", "=SUM(A1:B5)", etc. * * [Api set: ExcelApi 1.8] */ formula1: string | Date | Range; /** * - * Gets or sets the Formula2, i.e. maximum value or value depending of the operator. - When setting the value, it can be passed in as a Date, a Range object, or a string (where the string is either a stringified date/time in ISO8601 format, a cell reference like "=A1", or a formula like "=MIN(A1, B1)"). - When retrieving the value, it will always be returned as a string formula, for example: "=10", "=A1", "=SUM(A1:B5)", etc. + * With the ternary operators Between and NotBetween, specifies the upper bound operand. Is not used with the binary operators, such as GreaterThan. + * When setting the value, it can be passed in as a Date, a Range object, or a string (where the string is either a stringified date/time in ISO8601 format, a cell reference like "=A1", or a formula like "=MIN(A1, B1)"). + * When retrieving the value, it will always be returned as a string formula, for example: "=10", "=A1", "=SUM(A1:B5)", etc. * * [Api set: ExcelApi 1.8] */ @@ -50829,7 +50830,7 @@ declare namespace Word { getRange(rangeLocation?: "Whole" | "Start" | "End" | "Before" | "After" | "Content"): Word.Range; /** * - * Inserts a break at the specified location in the main document. The insertLocation value can be 'Before' or 'After'. + * Inserts a break at the specified location in the main document. * * [Api set: WordApi 1.2] * @@ -50839,7 +50840,7 @@ declare namespace Word { insertBreak(breakType: Word.BreakType, insertLocation: Word.InsertLocation): void; /** * - * Inserts a break at the specified location in the main document. The insertLocation value can be 'Before' or 'After'. + * Inserts a break at the specified location in the main document. * * [Api set: WordApi 1.2] * @@ -50856,7 +50857,7 @@ declare namespace Word { insertContentControl(): Word.ContentControl; /** * - * Inserts a document at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts a document at the specified location. * * [Api set: WordApi 1.2] * @@ -50866,7 +50867,7 @@ declare namespace Word { insertFileFromBase64(base64File: string, insertLocation: Word.InsertLocation): Word.Range; /** * - * Inserts a document at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts a document at the specified location. * * [Api set: WordApi 1.2] * @@ -50876,7 +50877,7 @@ declare namespace Word { insertFileFromBase64(base64File: string, insertLocation: "Before" | "After" | "Start" | "End" | "Replace"): Word.Range; /** * - * Inserts HTML at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts HTML at the specified location. * * [Api set: WordApi 1.2] * @@ -50886,7 +50887,7 @@ declare namespace Word { insertHtml(html: string, insertLocation: Word.InsertLocation): Word.Range; /** * - * Inserts HTML at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts HTML at the specified location. * * [Api set: WordApi 1.2] * @@ -50916,7 +50917,7 @@ declare namespace Word { insertInlinePictureFromBase64(base64EncodedImage: string, insertLocation: "Before" | "After" | "Start" | "End" | "Replace"): Word.InlinePicture; /** * - * Inserts OOXML at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts OOXML at the specified location. * * [Api set: WordApi 1.2] * @@ -50926,7 +50927,7 @@ declare namespace Word { insertOoxml(ooxml: string, insertLocation: Word.InsertLocation): Word.Range; /** * - * Inserts OOXML at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts OOXML at the specified location. * * [Api set: WordApi 1.2] * @@ -50936,7 +50937,7 @@ declare namespace Word { insertOoxml(ooxml: string, insertLocation: "Before" | "After" | "Start" | "End" | "Replace"): Word.Range; /** * - * Inserts a paragraph at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts a paragraph at the specified location. * * [Api set: WordApi 1.2] * @@ -50946,7 +50947,7 @@ declare namespace Word { insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation): Word.Paragraph; /** * - * Inserts a paragraph at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts a paragraph at the specified location. * * [Api set: WordApi 1.2] * @@ -50956,7 +50957,7 @@ declare namespace Word { insertParagraph(paragraphText: string, insertLocation: "Before" | "After" | "Start" | "End" | "Replace"): Word.Paragraph; /** * - * Inserts text at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts text at the specified location. * * [Api set: WordApi 1.2] * @@ -50966,7 +50967,7 @@ declare namespace Word { insertText(text: string, insertLocation: Word.InsertLocation): Word.Range; /** * - * Inserts text at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts text at the specified location. * * [Api set: WordApi 1.2] * @@ -51777,7 +51778,7 @@ declare namespace Word { getTextRanges(endingMarks: string[], trimSpacing?: boolean): Word.RangeCollection; /** * - * Inserts a break at the specified location in the main document. The insertLocation value can be 'Before' or 'After'. + * Inserts a break at the specified location in the main document. * * [Api set: WordApi 1.1] * @@ -51787,7 +51788,7 @@ declare namespace Word { insertBreak(breakType: Word.BreakType, insertLocation: Word.InsertLocation): void; /** * - * Inserts a break at the specified location in the main document. The insertLocation value can be 'Before' or 'After'. + * Inserts a break at the specified location in the main document. * * [Api set: WordApi 1.1] * @@ -51884,7 +51885,7 @@ declare namespace Word { insertOoxml(ooxml: string, insertLocation: "Before" | "After" | "Start" | "End" | "Replace"): Word.Range; /** * - * Inserts a paragraph at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts a paragraph at the specified location. * * [Api set: WordApi 1.1] * @@ -51894,7 +51895,7 @@ declare namespace Word { insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation): Word.Paragraph; /** * - * Inserts a paragraph at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts a paragraph at the specified location. * * [Api set: WordApi 1.1] * @@ -51904,7 +51905,7 @@ declare namespace Word { insertParagraph(paragraphText: string, insertLocation: "Before" | "After" | "Start" | "End" | "Replace"): Word.Paragraph; /** * - * Inserts a table with the specified number of rows and columns. The insertLocation value can be 'Before' or 'After'. + * Inserts a table with the specified number of rows and columns. * * [Api set: WordApi 1.3] * @@ -51916,7 +51917,7 @@ declare namespace Word { insertTable(rowCount: number, columnCount: number, insertLocation: Word.InsertLocation, values?: string[][]): Word.Table; /** * - * Inserts a table with the specified number of rows and columns. The insertLocation value can be 'Before' or 'After'. + * Inserts a table with the specified number of rows and columns. * * [Api set: WordApi 1.3] * @@ -52355,7 +52356,7 @@ declare namespace Word { getTextRanges(endingMarks: string[], trimSpacing?: boolean): Word.RangeCollection; /** * - * Inserts a break at the specified location in the main document. The insertLocation value can be 'Before' or 'After'. + * Inserts a break at the specified location in the main document. * * [Api set: WordApi 1.1] * @@ -52365,7 +52366,7 @@ declare namespace Word { insertBreak(breakType: Word.BreakType, insertLocation: Word.InsertLocation): void; /** * - * Inserts a break at the specified location in the main document. The insertLocation value can be 'Before' or 'After'. + * Inserts a break at the specified location in the main document. * * [Api set: WordApi 1.1] * @@ -52462,7 +52463,7 @@ declare namespace Word { insertOoxml(ooxml: string, insertLocation: "Before" | "After" | "Start" | "End" | "Replace"): Word.Range; /** * - * Inserts a paragraph at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts a paragraph at the specified location. * * [Api set: WordApi 1.1] * @@ -52472,7 +52473,7 @@ declare namespace Word { insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation): Word.Paragraph; /** * - * Inserts a paragraph at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts a paragraph at the specified location. * * [Api set: WordApi 1.1] * @@ -52482,7 +52483,7 @@ declare namespace Word { insertParagraph(paragraphText: string, insertLocation: "Before" | "After" | "Start" | "End" | "Replace"): Word.Paragraph; /** * - * Inserts a table with the specified number of rows and columns. The insertLocation value can be 'Before' or 'After'. + * Inserts a table with the specified number of rows and columns. * * [Api set: WordApi 1.3] * @@ -52494,7 +52495,7 @@ declare namespace Word { insertTable(rowCount: number, columnCount: number, insertLocation: Word.InsertLocation, values?: string[][]): Word.Table; /** * - * Inserts a table with the specified number of rows and columns. The insertLocation value can be 'Before' or 'After'. + * Inserts a table with the specified number of rows and columns. * * [Api set: WordApi 1.3] * @@ -53357,7 +53358,7 @@ declare namespace Word { insertContentControl(): Word.ContentControl; /** * - * Inserts a paragraph at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts a paragraph at the specified location. * * [Api set: WordApi 1.3] * @@ -53367,7 +53368,7 @@ declare namespace Word { insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation): Word.Paragraph; /** * - * Inserts a paragraph at the specified location. The insertLocation value can be 'Before' or 'After'. + * Inserts a paragraph at the specified location. * * [Api set: WordApi 1.3] * @@ -53377,7 +53378,7 @@ declare namespace Word { insertParagraph(paragraphText: string, insertLocation: "Before" | "After" | "Start" | "End" | "Replace"): Word.Paragraph; /** * - * Inserts a table with the specified number of rows and columns. The insertLocation value can be 'Before' or 'After'. + * Inserts a table with the specified number of rows and columns. * * [Api set: WordApi 1.3] * @@ -53389,7 +53390,7 @@ declare namespace Word { insertTable(rowCount: number, columnCount: number, insertLocation: Word.InsertLocation, values?: string[][]): Word.Table; /** * - * Inserts a table with the specified number of rows and columns. The insertLocation value can be 'Before' or 'After'. + * Inserts a table with the specified number of rows and columns. * * [Api set: WordApi 1.3] * diff --git a/types/ol/ol-tests.ts b/types/ol/ol-tests.ts index ca099420cd..be19e61a2b 100644 --- a/types/ol/ol-tests.ts +++ b/types/ol/ol-tests.ts @@ -303,7 +303,7 @@ import VectorTile from 'ol/vectortile'; import View from 'ol/view'; // Map -const map: ol.Map = new Map( {}); +const map: ol.Map = new Map({} as any); declare const mapView: View; declare const layerBase: LayerBase; declare const control: ControlControl; @@ -320,6 +320,6 @@ declare const size: ol.Size; declare const position: ol.Pixel; view = map.getView(); view.getProjection(); -view.animate( {}); -view.calculateExtent( 'size'); +view.animate({} as any); +view.calculateExtent('size' as any); view.centerOn(coordinate, size, position); diff --git a/types/openlayers/index.d.ts b/types/openlayers/index.d.ts index 3214bad15c..b0356122e4 100644 --- a/types/openlayers/index.d.ts +++ b/types/openlayers/index.d.ts @@ -12494,6 +12494,7 @@ export namespace olx { renderer?: (ol.RendererType | Array<(ol.RendererType | string)> | string); target?: (Element | string); view?: ol.View; + moveTolerance?: number; } /** diff --git a/types/openlayers/openlayers-tests.ts b/types/openlayers/openlayers-tests.ts index d631a9e9bb..9fb6f0bb3b 100644 --- a/types/openlayers/openlayers-tests.ts +++ b/types/openlayers/openlayers-tests.ts @@ -175,7 +175,7 @@ loadingStrategy = ol.loadingstrategy.tile(tilegrid); // ol.geom.Circle // booleanValue = circle.intersectsExtent(extent); -circle = circle.transform(projectionLike, projectionLike); +circle = circle.transform(projectionLike, projectionLike) as ol.geom.Circle; // // diff --git a/types/paper/index.d.ts b/types/paper/index.d.ts index 016581f16c..d3c818b112 100644 --- a/types/paper/index.d.ts +++ b/types/paper/index.d.ts @@ -1491,7 +1491,7 @@ declare module paper { /** * The color of the stroke. */ - strokeColor: Color | string; + strokeColor: Color | string | null; /** * The width of the stroke. @@ -1539,7 +1539,7 @@ declare module paper { /** * The fill color of the item. */ - fillColor: Color | string; + fillColor: Color | string | null; /** * The fill-rule with which the shape gets filled. Please note that only modern browsers support fill-rules other than 'nonzero'. @@ -1551,7 +1551,7 @@ declare module paper { /** * The shadow color. */ - shadowColor: Color | string; + shadowColor: Color | string | null; /** * The shadow’s blur radius. diff --git a/types/pino/index.d.ts b/types/pino/index.d.ts index bea9987832..8efaa85d33 100644 --- a/types/pino/index.d.ts +++ b/types/pino/index.d.ts @@ -5,6 +5,7 @@ // Christian Rackerseder // GP // Alex Ferrando +// Oleksandr Sidko // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -243,13 +244,12 @@ declare namespace P { interface PrettyOptions { /** - * If set to true, it will only covert the unix timestamp to ISO 8601 date format, and reserialize the JSON (equivalent to pino -t). + * Translate the epoch time value into a human readable date and time string. + * This flag also can set the format string to apply when translating the date to human readable format. + * The default format is yyyy-mm-dd HH:MM:ss.l o in UTC. + * For a list of available pattern letters see the {@link https://www.npmjs.com/package/dateformat|dateformat documentation}. */ - timeTransOnly?: boolean; - /** - * A custom function to format the line, is passed the JSON object as an argument and should return a string value. - */ - formatter?(log: LogDescriptor): string; + translateTime?: boolean | string; /** * If set to true, it will print the name of the log level as the first field in the log line. Default: `false`. */ @@ -261,7 +261,24 @@ declare namespace P { /** * If set to true, will add color information to the formatted output message. Default: `false`. */ - forceColor?: boolean; + colorize?: boolean; + /** + * Appends carriage return and line feed, instead of just a line feed, to the formatted log line. + */ + crlf?: boolean; + /** + * Define the log keys that are associated with error like objects. Default: ["err", "error"] + */ + errorLikeObjectKeys?: string[]; + /** + * When formatting an error object, display this list of properties. + * The list should be a comma separated list of properties. Default: '' + */ + errorProps?: string; + /** + * Specify a search pattern according to {@link http://jmespath.org|jmespath} + */ + search?: string; } type Level = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace'; diff --git a/types/pino/pino-tests.ts b/types/pino/pino-tests.ts index d3203b5dd4..3a6283c3e4 100644 --- a/types/pino/pino-tests.ts +++ b/types/pino/pino-tests.ts @@ -123,3 +123,16 @@ anotherRedacted.info({ msg: 'another logged with redacted properties', anotherPath: 'Not shown' }); + +const pretty = pino({ + prettyPrint: { + colorize: true, + crlf: false, + errorLikeObjectKeys: ['err', 'error'], + errorProps: '', + levelFirst: false, + messageKey: 'msg', + translateTime: 'UTC:h:MM:ss TT Z', + search: 'foo == `bar`' + } +}); diff --git a/types/prettier/index.d.ts b/types/prettier/index.d.ts index 3a64129364..6cef2ef27a 100644 --- a/types/prettier/index.d.ts +++ b/types/prettier/index.d.ts @@ -256,7 +256,7 @@ export function clearConfigCache(): void; export interface SupportLanguage { name: string; since?: string; - parsers: string[]; + parsers: BuiltInParserName[] | string[]; group?: string; tmScope: string; aceMode: string; diff --git a/types/puppeteer/index.d.ts b/types/puppeteer/index.d.ts index bfd14d9c35..cbb31f2fd0 100644 --- a/types/puppeteer/index.d.ts +++ b/types/puppeteer/index.d.ts @@ -1715,7 +1715,7 @@ export interface Page extends EventEmitter, FrameBase { } export interface TargetAwaiter { - waitForTarget(predicate: (target: Target) => boolean, options: Timeoutable): Promise; + waitForTarget(predicate: (target: Target) => boolean, options?: Timeoutable): Promise; } /** A Browser is created when Puppeteer connects to a Chromium instance, either through puppeteer.launch or puppeteer.connect. */ diff --git a/types/react-datepicker/index.d.ts b/types/react-datepicker/index.d.ts index 6368e273e3..e727155520 100644 --- a/types/react-datepicker/index.d.ts +++ b/types/react-datepicker/index.d.ts @@ -7,6 +7,7 @@ // Roy Xue // Koala Human // Sean Kelley +// Justin Grant // Jake Boone // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/react-dom/server/index.d.ts b/types/react-dom/server/index.d.ts index 53bbca7250..ef42606717 100644 --- a/types/react-dom/server/index.d.ts +++ b/types/react-dom/server/index.d.ts @@ -1,4 +1,10 @@ -/// +// forward declarations +declare global { + namespace NodeJS { + // tslint:disable-next-line:no-empty-interface + interface ReadableStream {} + } +} import { ReactElement } from 'react'; diff --git a/types/react-intl/index.d.ts b/types/react-intl/index.d.ts index 17e738bb2a..aaba74820b 100644 --- a/types/react-intl/index.d.ts +++ b/types/react-intl/index.d.ts @@ -9,6 +9,7 @@ // Krister Kari // Martin Raedlinger // Kanitkorn Sujautra +// obedm503 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -46,6 +47,7 @@ declare namespace ReactIntl { messages: React.Requireable; defaultLocale: React.Requireable; defaultFormats: React.Requireable; + onError: React.Requireable; } interface IntlFormat { @@ -78,6 +80,7 @@ declare namespace ReactIntl { defaultLocale: string; defaultFormats: any; now(): number; + onError(error: string): void; } interface InjectedIntlProps { @@ -197,6 +200,7 @@ declare namespace ReactIntl { defaultFormats?: any; textComponent?: any; initialNow?: any; + onError?: (error: string) => void; } } diff --git a/types/react-intl/react-intl-tests.tsx b/types/react-intl/react-intl-tests.tsx index b3b23bb38f..63af762e61 100644 --- a/types/react-intl/react-intl-tests.tsx +++ b/types/react-intl/react-intl-tests.tsx @@ -401,7 +401,15 @@ class TestApp extends React.Component { hello: "Hello, {name}!" }; return ( - + console.error(error)} + > diff --git a/types/react-native-scrollable-tab-view/index.d.ts b/types/react-native-scrollable-tab-view/index.d.ts index 9be23aa66c..d992012856 100644 --- a/types/react-native-scrollable-tab-view/index.d.ts +++ b/types/react-native-scrollable-tab-view/index.d.ts @@ -125,7 +125,7 @@ export default class ScrollableTabView extends React.Component = T & { - tabLabel: React.ReactType; + tabLabel: React.ReactChild; }; export interface DefaultTabBarProps { diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 9e68e283a9..6e54b6d7c9 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -9030,34 +9030,15 @@ export const Platform: PlatformStatic; export const PlatformIOS: PlatformIOSStatic; export const PixelRatio: PixelRatioStatic; -export interface ComponentInterface

{ - name?: string; - displayName?: string; - propTypes: PropTypes.ValidationMap

; -} - /** - * Used to create React components that directly wrap native component - * implementations. Config information is extracted from data exported from the - * UIManager module. You should also wrap the native component in a - * hand-written component with full propTypes definitions and other - * documentation - pass the hand-written component in as `componentInterface` to - * verify all the native props are documented via `propTypes`. + * Creates values that can be used like React components which represent native + * view managers. You should create JavaScript modules that wrap these values so + * that the results are memoized. Example: * - * If some native props shouldn't be exposed in the wrapper interface, you can - * pass null for `componentInterface` and call `verifyPropTypes` directly - * with `nativePropsToIgnore`; + * const View = requireNativeComponent('RCTView'); * - * Common types are lined up with the appropriate prop differs with - * `TypeToDifferMap`. Non-scalar types not in the map default to `deepDiffer`. */ -export function requireNativeComponent( - viewName: string, - componentInterface?: ComponentInterface

, - extraConfig?: { nativeOnly?: NP } -): React.ComponentClass< - Partial>> & { [K in keyof NP]?: any} ->; +export function requireNativeComponent(viewName: string): React.ReactType; export function findNodeHandle( componentOrHandle: null | number | React.Component | React.ComponentClass diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 56d6b7035b..b5d7a5faeb 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -822,12 +822,7 @@ class BridgedComponentTest extends React.Component { } } -const NativeBridgedComponent = requireNativeComponent("NativeBridgedComponent", BridgedComponentTest, { - nativeOnly: { - nativeProp: true, - } -}); - +const NativeBridgedComponent = requireNativeComponent("NativeBridgedComponent"); const SwitchColorTest = () => ( diff --git a/types/react-tag-input/index.d.ts b/types/react-tag-input/index.d.ts index 39654e5b31..f659faedf3 100644 --- a/types/react-tag-input/index.d.ts +++ b/types/react-tag-input/index.d.ts @@ -18,20 +18,26 @@ export interface ReactTagsProps { handleAddition: ((tag: {id: string, text: string}) => void); handleDelete: ((i: number) => void); handleDrag?: ((tag: { id: string; text: string; }, currPos: number, newPos: number) => void); - handleInputChange?: ((value: string) => void); handleFilterSuggestions?: ((textInputValue: string, possibleSuggestionsArray: Array<{ id: string, text: string }>) => Array<{ id: string, text: string }>); - handleInputBlur?: ((textInputValue: string) => void); + handleTagClick?: ((i: number) => void); autofocus?: boolean; allowDeleteFromEmptyInput?: boolean; + handleInputChange?: ((value: string) => void); + handleInputFocus?: ((value: string) => void); + handleInputBlur?: ((textInputValue: string) => void); minQueryLength?: number; removeComponent?: React.Component; autocomplete?: boolean | 1; readOnly?: boolean; - maxLength?: number; name?: string; id?: string; + maxLength?: number; + + inline?: boolean; + allowUnique?: boolean; + allowDragDrop?: boolean; } export class WithContext extends React.Component { } diff --git a/types/react-test-renderer/react-test-renderer-tests.ts b/types/react-test-renderer/react-test-renderer-tests.ts index 45568c81a7..83dc510e2b 100644 --- a/types/react-test-renderer/react-test-renderer-tests.ts +++ b/types/react-test-renderer/react-test-renderer-tests.ts @@ -43,14 +43,14 @@ function testInstance(inst: ReactTestInstance) { inst.props = { prop1: "p", }; - inst.type = "t"; - testInstance(inst.find(n => n.type === "t")); + inst.type = "a"; + testInstance(inst.find(n => n.type === "a")); testInstance(inst.findByProps({ prop1: "p" })); - testInstance(inst.findByType("t")); + testInstance(inst.findByType("a")); testInstance(inst.findByType(TestComponent)); inst.findAll(n => n.type === "t", { deep: true }).map(testInstance); inst.findAllByProps({ prop1: "p" }, { deep: true }).map(testInstance); - inst.findAllByType("t", { deep: true }).map(testInstance); + inst.findAllByType("a", { deep: true }).map(testInstance); inst.findAllByType(TestComponent, { deep: true }).map(testInstance); } diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 25f3c710ae..f525d7838c 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -8,7 +8,6 @@ // Patricio Zavolinsky // Digiguru // Eric Anderson -// Albert Kurniawan // Tanguy Krotoff // Dovydas Navickas // Stéphane Goetz @@ -50,7 +49,11 @@ declare namespace React { // React Elements // ---------------------------------------------------------------------- - type ReactType

= string | ComponentType

; + type ReactType

= + { + [K in keyof JSX.IntrinsicElements]: P extends JSX.IntrinsicElements[K] ? K : never + }[keyof JSX.IntrinsicElements] | + ComponentType

; type ComponentType

= ComponentClass

| FunctionComponent

; type Key = string | number; @@ -713,17 +716,17 @@ declare namespace React { * NOTE: prefer ComponentPropsWithRef, if the ref is forwarded, * or ComponentPropsWithoutRef when refs are not supported. */ - type ComponentProps> = + type ComponentProps = T extends ComponentType ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : {}; - type ComponentPropsWithRef> = + type ComponentPropsWithRef = T extends ComponentClass ? PropsWithoutRef

& RefAttributes> : PropsWithRef>; - type ComponentPropsWithoutRef> = + type ComponentPropsWithoutRef = PropsWithoutRef>; // will show `Memo(${Component.displayName || Component.name})` in devtools by default, diff --git a/types/react/test/index.ts b/types/react/test/index.ts index 97d61118b9..8a4a2bd89b 100644 --- a/types/react/test/index.ts +++ b/types/react/test/index.ts @@ -14,6 +14,14 @@ import update = require("react-addons-update"); import createReactClass = require("create-react-class"); import * as DOM from "react-dom-factories"; +// NOTE: forward declarations for tests +declare function setInterval(...args: any[]): any; +declare function clearInterval(...args: any[]): any; +declare var console: Console; +interface Console { + log(...args: any[]): void; +} + interface Props extends React.Attributes { hello: string; world?: string | null; @@ -501,7 +509,7 @@ class Timer extends React.Component<{}, TimerState> { state = { secondsElapsed: 0 }; - private _interval: NodeJS.Timer; + private _interval: number; tick() { this.setState((prevState, props) => ({ secondsElapsed: prevState.secondsElapsed + 1 diff --git a/types/react/test/tsx.tsx b/types/react/test/tsx.tsx index f344fb2838..60fcb6dccc 100644 --- a/types/react/test/tsx.tsx +++ b/types/react/test/tsx.tsx @@ -325,3 +325,23 @@ type ImgPropsWithRefRef = ImgPropsWithRef['ref']; type ImgPropsWithoutRef = React.ComponentPropsWithoutRef<'img'>; // $ExpectType false type ImgPropsHasRef = 'ref' extends keyof ImgPropsWithoutRef ? true : false; + +const HasClassName: React.ReactType<{ className?: string }> = 'a'; +const HasFoo: React.ReactType<{ foo: boolean }> = 'a'; // $ExpectError +const HasFoo2: React.ReactType<{ foo: boolean }> = (props: { foo: boolean }) => null; +const HasFoo3: React.ReactType<{ foo: boolean }> = (props: { foo: string }) => null; // $ExpectError +const HasHref: React.ReactType<{ href?: string }> = 'a'; +const HasHref2: React.ReactType<{ href?: string }> = 'div'; // $ExpectError + +const CustomElement: React.ReactType = 'my-undeclared-element'; // $ExpectError + +// custom elements now need to be declared as intrinsic elements +declare global { + namespace JSX { + interface IntrinsicElements { + 'my-declared-element': {}; + } + } +} + +const CustomElement2: React.ReactType = 'my-declared-element'; diff --git a/types/react/v15/index.d.ts b/types/react/v15/index.d.ts index 78ec7d8951..ce2a523123 100644 --- a/types/react/v15/index.d.ts +++ b/types/react/v15/index.d.ts @@ -8,7 +8,6 @@ // Patricio Zavolinsky // Digiguru // Eric Anderson -// Albert Kurniawan // Tanguy Krotoff // Dovydas Navickas // Stéphane Goetz diff --git a/types/react/v15/test/index.ts b/types/react/v15/test/index.ts index 30dd3bd75d..79d05ac8d0 100644 --- a/types/react/v15/test/index.ts +++ b/types/react/v15/test/index.ts @@ -11,6 +11,14 @@ import * as TestUtils from "react-addons-test-utils"; import TransitionGroup = require("react-addons-transition-group"); import update = require("react-addons-update"); +// NOTE: forward declarations for tests +declare function setInterval(...args: any[]): any; +declare function clearInterval(...args: any[]): any; +declare var console: Console; +interface Console { + log(...args: any[]): void; +} + interface Props extends React.Attributes { hello: string; world?: string; @@ -505,7 +513,7 @@ class Timer extends React.Component<{}, TimerState> { state = { secondsElapsed: 0 }; - private _interval: NodeJS.Timer; + private _interval: number; tick() { this.setState((prevState, props) => ({ secondsElapsed: prevState.secondsElapsed + 1 diff --git a/types/recharts/index.d.ts b/types/recharts/index.d.ts index a9301374f1..34e3cbcb88 100644 --- a/types/recharts/index.d.ts +++ b/types/recharts/index.d.ts @@ -796,6 +796,7 @@ export interface TooltipPayload { fill?: string; dataKey?: DataKey; formatter?: TooltipFormatter; + payload?: any; } export interface TooltipProps extends Animatable { diff --git a/types/redux-first-router/index.d.ts b/types/redux-first-router/index.d.ts index 2184deed0b..13b4578322 100644 --- a/types/redux-first-router/index.d.ts +++ b/types/redux-first-router/index.d.ts @@ -6,6 +6,7 @@ // corydeppen // jscinoz // surgeboris +// geirsagberg // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 @@ -24,6 +25,8 @@ export type StateGetter = () => TState; export type RouteString = string; +export type ConfirmLeave = (state: object, action: object) => Nullable; + export type RouteThunk = ( dispatch: Dispatch, getState: StateGetter, @@ -36,6 +39,9 @@ export type RouteObject = TKeys & { thunk?: RouteThunk; fromPath?(path: string, key?: string): string; toPath?(param: string, key?: string): string; + coerceNumbers?: boolean; + confirmLeave?: ConfirmLeave; + meta?: Meta; }; export type Route = RouteString | RouteObject; @@ -194,25 +200,107 @@ export interface NavigatorsConfig { }; } +export interface Bag { + action: ReceivedAction | Action; + extra: any; +} + export interface Options { - title?: string | SelectTitleState; + /** + * A prefix that will be prepended to the URL. For example, using a basename of '/playground', + * a route with the path '/home' would correspond to the URL path '/playground/home'. + */ + basename?: string; + /** + * Whether or not a trailing delimiter is allowed when matching path. + */ + strict?: boolean; + /** + * The name of the state key or a selector function to specify where in your Redux state tree + * Redux First Router should expect your page location reducer to be attached to. + */ location?: string | SelectLocationState; - notFoundPath?: string; - scrollTop?: boolean; - onBeforeChange?(dispatch: Dispatch, getState: StateGetter): void; - onAfterChange?(dispatch: Dispatch, getState: StateGetter): void; - onBackNext?(dispatch: Dispatch, getState: StateGetter): void; - restoreScroll?(history: History): ScrollBehavior; + /** + * The name of the state key or a selector function to specify where in your Redux state tree + * Redux First Router should expect your page title reducer to be attached to. + * This can be omitted if you attach the reducer at state.title. + */ + title?: string | SelectTitleState; + /** + * Can be set to false to bypass the initial dispatch, so you can do it manually, perhaps after running sagas. + */ initialDispatch?: boolean; - querySerializer?: QuerySerializer; - navigators?: NavigatorsConfig; + /** + * An array of entries to initialise history object. Useful for server side rendering and tests. + */ initialEntries?: HistoryEntries; + /** + * An object with parse and stringify methods, such as the `query-string` or `qs` libraries (or anything handmade). + * This will be used to handle querystrings. Without this option, query strings are ignored silently. + */ + querySerializer?: QuerySerializer; + /** + * The path where users may be redirected in 2 situations: when you dispatch an action with no matching path, + * or if you manually call dispatch(redirect({ type: NOT_FOUND })), where NOT_FOUND is an export from this package. + * The type in actions and state will be NOT_FOUND, which you can use to show a 404 page. + */ + notFoundPath?: string; + /** + * Whether or not window.scrollTo(0, 0) should be run on route changes so the user starts each page at the top. + */ + scrollTop?: boolean; + /** + * A function to update window/elements scroll position. + */ + restoreScroll?(history: History): ScrollBehavior; + /** + * A simple function that will be called before the routes change. + * It's passed your standard `dispatch` and `getState` arguments like a thunk, + * as well as the `bag` object as a third parameter, which contains the dispatched `action` and the configured `extra` value. + */ + onBeforeChange?(dispatch: Dispatch, getState: StateGetter, bag: Bag): void; + /** + * A simple function that will be called after the routes change. + * It's passed your standard `dispatch` and `getState` arguments like a thunk, + * as well as the `bag` object as a third parameter, which contains the dispatched `action` and the configured `extra` value. + */ + onAfterChange?(dispatch: Dispatch, getState: StateGetter, bag: Bag): void; + /** + * A simple function that will be called whenever the user uses the browser back/next buttons. + * It's passed your standard `dispatch` and `getState` arguments like a thunk, + * as well as the `bag` object as a third parameter, which contains the dispatched `action` + * and the configured `extra` value. Actions with kinds `back`, `next`, and `pop` trigger this. + */ + onBackNext?(dispatch: Dispatch, getState: StateGetter, bag: Bag): void; + /** + * A function receiving `message` and `callback` when navigation is blocked with `confirmLeave`. + * The message is the return value from `confirmLeave`. + * The callback can be called with `true` to unblock the navigation, or with `false` to cancel the navigation. + */ + displayConfirmLeave?: DisplayConfirmLeave; + /** + * A function returning a history object compatible with the popular `history` package. + */ createHistory?(): History; + /** + * A map of of your Redux state keys to _React Navigation_ navigators. + */ + navigators?: NavigatorsConfig; + /** + * An optional value that will be passed as part of the third `bag` argument to all options callbacks and routes thunk. + * It works much like the `withExtraArgument` feature of `redux-thunk` or the `context` argument of GraphQL resolvers. + * You can use it to pass any required context to your thunks without having to tightly couple them to it. + * For example, you could pass an instance of an API client initialised with authentication cookies, + * or a function `addReducer` to inject new code split reducers into the store. + */ + extra?: any; } export type Params = object; export type Payload = object; +export type DisplayConfirmLeave = (message: string, callback: (unblock: boolean) => void) => void; + export type ScrollUpdater = (performedByUser: boolean) => void; export const NOT_FOUND: '@@redux-first-router/NOT_FOUND'; diff --git a/types/redux-first-router/redux-first-router-tests.ts b/types/redux-first-router/redux-first-router-tests.ts index 5297be4175..0439f551c7 100644 --- a/types/redux-first-router/redux-first-router-tests.ts +++ b/types/redux-first-router/redux-first-router-tests.ts @@ -7,21 +7,24 @@ import { redirect, Action as ReduxFirstRouterAction, QuerySerializer, - pathToAction + pathToAction, + StateGetter, + Bag, + Navigators, + NavigationAction, + Nullable, + Route } from 'redux-first-router'; import { - AnyAction, createStore, applyMiddleware, Middleware, - MiddlewareAPI, - Store, Dispatch, compose, - Action, - StoreEnhancer, StoreEnhancerStoreCreator, - combineReducers + combineReducers, + AnyAction, + Store } from 'redux'; import { History } from 'history'; @@ -52,28 +55,40 @@ const routesMap: RoutesMap = { } }; -const { - reducer, - middleware, - enhancer, - initialDispatch, - thunk, -} = connectRoutes(routesMap, { - initialDispatch: false, - onBeforeChange: (dispatch, getState) => { - dispatch; // $ExpectType Dispatch - getState; // $ExpectType StateGetter +const { reducer, middleware, enhancer, initialDispatch, thunk } = connectRoutes(routesMap, { + basename: '/base', + strict: false, + location: state => { + const locationState = state.location; // $ExpectType LocationState + return locationState; + }, + title: state => { + const title = state.location.pathname; // $ExpectType string + return title; + }, + initialDispatch: false, + initialEntries: [], + querySerializer: { + stringify: queryString => { + queryString; // $ExpectType object + return ''; }, - location: state => { - const locationState = state.location; // $ExpectType LocationState - return locationState; - }, - title: state => { - const title = state.location.pathname; // $ExpectType string - return title; - }, - createHistory: () => history, - }); + parse: params => { + params; // $ExpectType string + return {}; + } + }, + notFoundPath: 'not-found', + scrollTop: true, + restoreScroll: (history: History) => { + return {}; + }, + onBeforeChange: (dispatch: Dispatch, getState: StateGetter, bag: Bag) => { }, + onAfterChange: (dispatch: Dispatch, getState: StateGetter, bag: Bag) => { }, + onBackNext: (dispatch: Dispatch, getState: StateGetter, bag: Bag) => { }, + displayConfirmLeave: (message: string, callback: (unblock: boolean) => void) => { }, + createHistory: (options?: any) => history +}); const dumbMiddleware: Middleware = store => next => action => next(action); @@ -89,10 +104,9 @@ const combined = combineReducers({ location: reducer }); const store = createStore(combined, storeEnhancer); // Test that `thunk()` has correct state types now that `store` is defined -thunk(store) - .then((t) => { - t = t!; // $ExpectType RouteThunk - }); +thunk(store).then(t => { + t = t!; // $ExpectType RouteThunk +}); const receivedAction: ReceivedAction = { type: 'HOME', @@ -102,8 +116,8 @@ actionToPath(receivedAction, routesMap); // $ExpectType string pathToAction('/', routesMap); // $ExpectType ReceivedAction const querySerializer: QuerySerializer = { - stringify: (params) => '', - parse: (queryString) => ({}) + stringify: params => '', + parse: queryString => ({}) }; actionToPath(receivedAction, routesMap, querySerializer); // $ExpectType string pathToAction('/', routesMap, querySerializer); // $ExpectType ReceivedAction diff --git a/types/sequelize/index.d.ts b/types/sequelize/index.d.ts index 88ed87efae..f25aacc3e4 100644 --- a/types/sequelize/index.d.ts +++ b/types/sequelize/index.d.ts @@ -2295,8 +2295,8 @@ declare namespace sequelize { * interfaces. * * beforeValidate, afterValidate, beforeBulkCreate, beforeBulkDestroy, beforeBulkUpdate, beforeCreate, - * beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, afterBulkCreate, afterBulkDestroy and - * afterBulkUpdate. + * beforeDestroy, beforeSave, beforeUpdate, afterCreate, afterDestroy, afterSave, afterUpdate, afterBulkCreate, + * afterBulkDestroy and afterBulkUpdate. */ interface HooksDefineOptions { @@ -2310,6 +2310,8 @@ declare namespace sequelize { afterDelete?: (instance: TInstance, options: Object, fn?: Function) => any; beforeUpdate?: (instance: TInstance, options: Object, fn?: Function) => any; afterUpdate?: (instance: TInstance, options: Object, fn?: Function) => any; + beforeSave?: (instance: TInstance, options: Object, fn?: Function) => any; + afterSave?: (instance: TInstance, options: Object, fn?: Function) => any; beforeBulkCreate?: (instances: TInstance[], options: Object, fn?: Function) => any; afterBulkCreate?: (instances: TInstance[], options: Object, fn?: Function) => any; beforeBulkDestroy?: (options: Object, fn?: Function) => any; @@ -5272,9 +5274,10 @@ declare namespace sequelize { /** * An object of hook function that are called before and after certain lifecycle events. * The possible hooks are: beforeValidate, afterValidate, beforeBulkCreate, beforeBulkDestroy, - * beforeBulkUpdate, beforeCreate, beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, - * afterBulkCreate, afterBulkDestory and afterBulkUpdate. See Hooks for more information about hook - * functions and their signatures. Each property can either be a function, or an array of functions. + * beforeBulkUpdate, beforeCreate, beforeDestroy, beforeSave, beforeUpdate, afterCreate, afterDestroy, + * afterSave, afterUpdate, afterBulkCreate, afterBulkDestory and afterBulkUpdate. + * See Hooks for more information about hook functions and their signatures. Each property can either + * be a function, or an array of functions. */ hooks?: HooksDefineOptions; diff --git a/types/simple-oauth2/index.d.ts b/types/simple-oauth2/index.d.ts index 19a1ff2698..8091a56f2d 100644 --- a/types/simple-oauth2/index.d.ts +++ b/types/simple-oauth2/index.d.ts @@ -3,13 +3,14 @@ // Definitions by: Michael Müller , // Troy Lamerton // Martín Rodriguez +// Linus Unnebäck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.9 /** Creates a new simple-oauth2 client with the passed configuration */ -export function create(options: ModuleOptions): OAuthClient; +export function create(options: ModuleOptions): OAuthClient; -export interface ModuleOptions { +export interface ModuleOptions { client: { /** Service registered client id. Required. */ id: string, @@ -18,7 +19,7 @@ export interface ModuleOptions { /** Parameter name used to send the client secret. Default to client_secret. */ secretParamName?: string, /** Parameter name used to send the client id. Default to client_id. */ - idParamName?: string + idParamName?: ClientIdName }; auth: { /** String used to set the host to request the tokens to. Required. */ @@ -91,7 +92,7 @@ export interface ClientCredentialTokenConfig { scope?: string | string[]; } -export interface OAuthClient { +export interface OAuthClient { authorizationCode: { /** * Redirect the user to the autorization page @@ -99,8 +100,8 @@ export interface OAuthClient { */ authorizeURL( params?: { - /** A key-value pair where key is ModuleOptions#client.idParamName and the value represents the Client-ID */ - [ idParamName: string ]: string | undefined + /** A string that represents the Client-ID */ + [key in ClientIdName]?: string } & { /** A string that represents the registered application URI where the user is redirected after authentication */ redirect_uri?: string, diff --git a/types/simple-oauth2/simple-oauth2-tests.ts b/types/simple-oauth2/simple-oauth2-tests.ts index e066ad41c0..c33564b7cd 100644 --- a/types/simple-oauth2/simple-oauth2-tests.ts +++ b/types/simple-oauth2/simple-oauth2-tests.ts @@ -17,6 +17,12 @@ const credentials: oauth2lib.ModuleOptions = { const oauth2 = oauth2lib.create(credentials); +// Test custom `idParamName` +{ + const oauth2 = oauth2lib.create({ client: { id: 'x', secret: 'x', idParamName: 'foobar' }, auth: { tokenHost: 'x' } }); + oauth2.authorizationCode.authorizeURL({ foobar: 'x' }); +} + // #Authorization Code flow (async () => { // Authorization oauth2 URI @@ -26,6 +32,12 @@ const oauth2 = oauth2lib.create(credentials); state: '' }); + oauth2.authorizationCode.authorizeURL({ + redirect_uri: 'http://localhost:3000/callback', + scope: ['', ''], + state: '' + }); + // Redirect example using Express (see http://expressjs.com/api.html#res.redirect) // res.redirect(authorizationUri); diff --git a/types/stoppable/index.d.ts b/types/stoppable/index.d.ts index 395dd828c8..1b30c5a995 100644 --- a/types/stoppable/index.d.ts +++ b/types/stoppable/index.d.ts @@ -1,11 +1,18 @@ -// Type definitions for stoppable 1.0 +// Type definitions for stoppable 1.1 // Project: https://github.com/hunterloftis/stoppable // Definitions by: Eric Byers +// John Plusjé // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// import { Server } from 'http'; -declare function stoppable(server: Server, grace?: number): Server; +declare namespace stoppable { + interface StoppableServer extends Server { + stop(callback?: (e: Error, gracefully: boolean) => void): void; + } +} + +declare function stoppable(server: Server, grace?: number): stoppable.StoppableServer; export = stoppable; diff --git a/types/stoppable/stoppable-tests.ts b/types/stoppable/stoppable-tests.ts index 84cf826bef..930a2340bd 100644 --- a/types/stoppable/stoppable-tests.ts +++ b/types/stoppable/stoppable-tests.ts @@ -1,8 +1,12 @@ import * as http from 'http'; import stoppable = require('stoppable'); -const server: http.Server = stoppable(http.createServer()); -server.close(); +const server: stoppable.StoppableServer = stoppable(http.createServer()); +server.stop(); -const server2: http.Server = stoppable(http.createServer(), 10000); -server2.close(); +const server2: stoppable.StoppableServer = stoppable(http.createServer(), 10000); +server2.stop(); + +const server3: stoppable.StoppableServer = stoppable(http.createServer()); +server.stop((err, gracefully) => {}); +server.close(); diff --git a/types/stripejs/element.d.ts b/types/stripejs/element.d.ts index 4a1e7b3c46..c6cfda71e4 100644 --- a/types/stripejs/element.d.ts +++ b/types/stripejs/element.d.ts @@ -163,7 +163,7 @@ export interface StripeElement { * The type of element that can be created by the ElementCreator * @see ElementCreator */ -export type ElementType = 'card' | 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'postalCode'; +export type ElementType = 'card' | 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'postalCode' | 'paymentRequestButton'; // --- ELEMENT EVENTS --- // export interface OnChange { @@ -295,6 +295,7 @@ export interface PaymentButtonOptions { complete?: PaymentRequestButtonStyle; empty?: PaymentRequestButtonStyle; invalid?: PaymentRequestButtonStyle; + paymentRequestButton?: PaymentRequestButtonStyle; }; } diff --git a/types/stripejs/index.d.ts b/types/stripejs/index.d.ts index f2a7ab21aa..0ee2016af2 100644 --- a/types/stripejs/index.d.ts +++ b/types/stripejs/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for stripe.js 3.0 // Project: https://stripe.com/ // Definitions by: Robin van Tienhoven +// Matt Ferderer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 diff --git a/types/stripejs/token.d.ts b/types/stripejs/token.d.ts index e3a3a51590..89da22bf8e 100644 --- a/types/stripejs/token.d.ts +++ b/types/stripejs/token.d.ts @@ -56,11 +56,16 @@ export interface TokenData { */ name: string; + /** + * The amount paid, not a decimal. In USD this is in cents. + */ + amount?: number; + /** * Fields for billing address information. */ address_line1: string; - address_line2: string; + address_line2?: string; address_city: string; address_state: string; address_zip: string; @@ -69,7 +74,7 @@ export interface TokenData { * A two character country code identifying the country * @example 'US' */ - address_country: string; + address_country?: string; /** * Used to add a card to an account diff --git a/types/styled-components/index.d.ts b/types/styled-components/index.d.ts index a842c94c63..1b26568498 100644 --- a/types/styled-components/index.d.ts +++ b/types/styled-components/index.d.ts @@ -287,6 +287,10 @@ export type ThemedStyledInterface = ThemedBaseStyledInterface< export type StyledInterface = ThemedStyledInterface; export interface BaseThemedCssFunction { + ( + first: TemplateStringsArray | NonNullable, + ...interpolations: SimpleInterpolation[] + ): FlattenSimpleInterpolation; ( first: | TemplateStringsArray diff --git a/types/styled-components/test/index.tsx b/types/styled-components/test/index.tsx index e435d90011..50a17b7069 100644 --- a/types/styled-components/test/index.tsx +++ b/types/styled-components/test/index.tsx @@ -99,6 +99,21 @@ const fadeIn = keyframes` } `; +const showAnimation = css` + opacity: 1; + transform: scale(1) translateY(0); +`; + +const hideAnimation = css` + opacity: 0; + transform: scale(0.95, 0.8) translateY(20px); +`; + +const entryAnimation = keyframes` + from { ${hideAnimation} } + to { ${showAnimation} } +`; + const animationRule = css` ${fadeIn} 1s infinite alternate; `; diff --git a/types/tus-js-client/index.d.ts b/types/tus-js-client/index.d.ts index defb27fea0..4cbb34a818 100644 --- a/types/tus-js-client/index.d.ts +++ b/types/tus-js-client/index.d.ts @@ -6,7 +6,7 @@ export interface UploadOptions { endpoint: string; - fingerprint?: string; + fingerprint?: (file: File, options?: UploadOptions) => string; resume?: boolean; metadata?: { [key: string]: string }; onProgress?: ((bytesSent: number, bytesTotal: number) => void) | null; diff --git a/types/tus-js-client/tus-js-client-tests.ts b/types/tus-js-client/tus-js-client-tests.ts index a13d9da12f..237f1df233 100644 --- a/types/tus-js-client/tus-js-client-tests.ts +++ b/types/tus-js-client/tus-js-client-tests.ts @@ -10,7 +10,7 @@ const file = new File(["foo"], "foo.txt", { const upload = new Tus.Upload(file, { endpoint: "", - fingerprint: "fingerprint", + fingerprint: (file: File) => file.name, resume: true, metadata: { filename: "foo.txt" diff --git a/types/vega/index.d.ts b/types/vega/index.d.ts deleted file mode 100644 index da7b0fee32..0000000000 --- a/types/vega/index.d.ts +++ /dev/null @@ -1,562 +0,0 @@ -// Type definitions for Vega -// Project: http://trifacta.github.io/vega/ -// Definitions by: Tom Crockett -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare namespace vg { - - export type ChartViewConstructor = { - (args: {renderer: 'svg'} & ViewArgs): SvgView; - (args: {renderer: 'canvas'} & ViewArgs): CanvasView; - (args: ViewArgs): View; - }; - - export interface Parse { - spec(url: string, callback: (chart: ChartViewConstructor) => void): void; - spec(spec: Spec, callback: (chart: ChartViewConstructor) => void): void; - data(dataSet: Data[], callback: () => void): void; - // TODO all the other stuff - } - - export interface ViewArgs { - // TODO docs - el?: any; - data?: any; - hover?: boolean; - renderer?: string; - } - - export interface View { - // TODO docs - width(): number; - width(w: number): this; - - height(): number; - height(h: number): this; - - padding(): Padding; - padding(p: Padding): this; - - viewport(): number[]; - viewport(v: number[]): this; - - renderer(r: string): this; - - data(): Runtime.DataSets; - data(d: any/*TODO*/): this; - - initialize(selector: string): this; - initialize(node: Element): this; - - render(r?: any[]): this; - - update(options?: UpdateOptions): this; - - model(): Vega.Model; - - defs(): Defs; - defs(defs: Defs): this; - } - - export interface SvgView extends View { - svg(): string; - } - - export interface CanvasView extends View { - canvas(): any; // Returns a node-canvas instance - } - - export interface Padding { - // TODO docs - top: number; - right: number; - bottom: number; - left: number; - } - - export interface UpdateOptions { - // TODO docs - props?: string; - items?: any; - duration?: number; - ease?: string; - } - - export interface Bounds { - x1: number; - y1: number; - x2: number; - y2: number; - clear(): Bounds; - set(x1: number, y1: number, x2: number, y2: number): Bounds; - add(x: number, y: number): Bounds; - expand(d: number): Bounds; - round(): Bounds; - translate(dx: number, dy: number): Bounds; - rotate(angle: number, x: number, y: number): Bounds; - union(b: Bounds): Bounds; - encloses(b: Bounds): boolean; - intersects(b: Bounds): boolean; - contains(x: number, y: number): boolean; - width(): number; - height(): number; - } - - export interface Model { - defs(): Defs; - defs(defs: Defs): Model; - - data(): Runtime.DataSets; - data(data: Runtime.DataSets): Model; - - ingest(name: string, tx: any/*TODO*/, input: any/*TODO*/): void; - - dependencies(name: string, tx: any/*TODO*/): void; - - width(w: number): Model; - - height(h: number): Model; - - scene(): Node; - scene(node: Node): Model; - - build(): Model; - - encode(trans?: any/*TODO*/, request?: string, item?: any): Model; - - reset(): Model; - } - - export namespace Runtime { - export interface DataSets { - [name: string]: Datum[]; - } - - export interface Datum { - [key: string]: any - } - - export interface Marks { - type: string; - width: number; - height: number; - scales: Scale[]; - axes: Axis[]; - legends: Legend[]; - marks: Mark[]; - } - - export interface PropertySets { - enter?: Properties; - exit?: Properties; - update?: Properties; - hover?: Properties; - } - - export interface Properties { - (item: Node, group: Node, trans: any/*TODO*/): void; - } - } - - export interface Node { - def: Vega.Mark; - marktype: string; - interactive: boolean; - items: Node[]; - bounds: Bounds; - - // mark item members - hasPropertySet(name: string): boolean; - cousin(offset: number, index: number): Node; - sibling(offset: number): Node; - remove(): Node; - touch(): void; - - // group members - scales?: {[name: string]: any}; - axisItems?: Node[]; - } - - export interface Defs { - width: number; - height: number; - viewport?: number[]; - padding: any; - marks: Runtime.Marks; - data: Data[]; - } - - export interface Spec { - /** - * A unique name for the visualization specification. - */ - name?: string; - /** - * The total width, in pixels, of the data rectangle. Default is 500 if - * undefined. - */ - width?: number; - /** - * The total height, in pixels, of the data rectangle. Default is 500 if - * undefined. - */ - height?: number; - /** - * The width and height of the on-screen viewport, in pixels. If necessary, - * clipping and scrolling will be applied. - */ - viewport?: number[]; - /** - * [Number | Object | String] - * The internal padding, in pixels, from the edge of the visualization - * canvas to the data rectangle. If an object is provided, it must include - * {top, left, right, bottom} properties. Two string values are also - * acceptable: "auto" (the default) and "strict". Auto-padding computes the - * padding dynamically based on the contents of the visualization. All - * marks, including axes and legends, are used to compute the necessary - * padding. "Strict" auto-padding attempts to adjust the padding such that - * the overall width and height of the visualization is unchanged. This mode - * can cause the visualization's width and height parameters to be adjusted - * such that the total size, including padding, remains constant. Note that - * in some cases strict padding is not possible; for example, if the axis - * labels are much larger than the data rectangle. - */ - padding?: number | string | { - top: number; left: number; right: number; bottom: number - }; // string is "auto" or "strict" - /** - * Definitions of data to visualize. - */ - data: Data[]; - /** - * Scale transform definitions. - */ - scales?: Scale[]; - /** - * Axis definitions. - */ - axes?: Axis[]; - /** - * Legend definitions. - */ - legends?: Legend[]; - /** - * Graphical mark definitions. - */ - marks: (Mark | GroupMark)[]; - } - - export interface Data { - /** - * A unique name for the data set. - */ - name: string; - /** - * An object that specifies the format for the data file, if loaded from a - * URL. - */ - format?: Data.Format; - /** - * The actual data set to use. The values property allows data to be inlined - * directly within the specification itself. - */ - values?: any; - /** - * The name of another data set to use as the source for this data set. The - * source property is particularly useful in combination with a transform - * pipeline to derive new data. - */ - source?: string; - /** - * A URL from which to load the data set. Use the format property to ensure - * the loaded data is correctly parsed. If the format property is not specified, - * the data is assumed to be in a row-oriented JSON format. - */ - url?: string; - /** - * An array of transforms to perform on the data. Transform operators will be - * run on the default data, as provided by late-binding or as specified by the - * source, values, or url properties. - */ - transform?: Data.Transform[]; - } - - export namespace Data { - export interface FormatBase { - /** - * The currently supported format types are json (JavaScript Object - * Notation), csv (comma-separated values), tsv (tab-separated values), - * topojson, and treejson. - */ - type: string; - // TODO: fields for specific formats - } - - /** - * The JSON property containing the desired data. - * This parameter can be used when the loaded JSON file may have surrounding structure or meta-data. - * For example "property": "values.features" is equivalent to retrieving json.values.features from the - * loaded JSON object. - */ - export interface JsonFormat extends FormatBase { - type: string; // "json" - property?: string; - } - - export interface CsvOrTsvFormat extends FormatBase { - type: string; // "csv" | "tsv" - parse?: { - [propertyName: string]: string; // "number" | "boolean" | "date" - } - } - - export interface TopoJsonFormat extends FormatBase { - type: string; // "topojson" - feature?: string; - mesh?: string; - } - - export interface TreeJson extends FormatBase { - type: string; // "treejson" - children?: string; - parse?: { - [propertyName: string]: string; // "number" | "boolean" | "date" - } - } - - export type Format = JsonFormat | CsvOrTsvFormat | TopoJsonFormat | TreeJson; - - export interface Transform { - // TODO - } - } - - export interface Scale { - // TODO docs - - // -- Common scale properties - name?: string; - type?: string; - domain?: any; - domainMin?: any; - domainMax?: any; - range?: any; - rangeMin?: any; - rangeMax?: any; - reverse?: boolean; - round?: boolean; - - // -- Ordinal scale properties - points?: boolean; - padding?: number; - sort?: boolean; - - // -- Time/Quantitative scale properties - clamp?: boolean; - /** boolean for quantitative scales, string for time scales */ - nice?: boolean | string; - - // -- Quantitative scale properties - exponent?: number; - zero?: boolean; - } - - export interface Axis { - // TODO docs - type: string; - scale: string; - orient?: string; - title?: string; - titleOffset?: number; - format?: string; - ticks?: number; - values?: any[]; - subdivide?: number; - tickPadding?: number; - tickSize?: number; - tickSizeMajor?: number; - tickSizeMinor?: number; - tickSizeEnd?: number; - offset?: any; - layer?: string; - grid?: boolean; - properties?: Axis.Properties - } - - export namespace Axis { - export interface Properties { - ticks?: PropertySet; - minorTicks?: PropertySet; - grid?: PropertySet; - labels?: PropertySet; - title?: PropertySet; - axis?: PropertySet; - } - } - - export interface Legend { - // TODO - } - - export interface Mark { - // TODO docs - // Stuff from Spec.Mark - type: string; // "rect" | "symbol" | "path" | "arc" | "area" | "line" | "rule" | "image" | "text" | "group" - name?: string; - description?: string; - from?: Mark.From; - key?: string; - delay?: ValueRefs; - /** - * "linear-in" | "linear-out" | "linear-in-out" | "linear-out-in" | "quad-in" | "quad-out" | "quad-in-out" | - * "quad-out-in" | "cubic-in" | "cubic-out" | "cubic-in-out" | "cubic-out-in" | "sin-in" | "sin-out" | "sin-in-out" | - * "sin-out-in" | "exp-in" | "exp-out" | "exp-in-out" | "exp-out-in" | "circle-in" | "circle-out" | "circle-in-out" | - * "circle-out-in" | "bounce-in" | "bounce-out" | "bounce-in-out" | "bounce-out-in" - */ - ease?: string; - - interactive?: boolean; - - // Runtime PropertySets - properties?: PropertySets; - } - - export module Mark { - export interface From { - // TODO docs - data?: string; - mark?: string; - transform?: Data.Transform[]; - } - } - - export interface GroupMark extends Mark { - type: string; // "group" - /** - * Scale transform definitions. - */ - scales?: Scale[]; - /** - * Axis definitions. - */ - axes?: Axis[]; - /** - * Legend definitions. - */ - legends?: Legend[]; - /** - * Groups differ from other mark types in their ability to contain children marks. - * Marks defined within a group mark can inherit data from their parent group. - * For inheritance to work each data element for a group must contain data elements of its own. - * This arrangement of nested data is typically achieved by facetting the data, such that each group-level data element includes its own array of sub-elements - */ - marks?: (Mark | GroupMark)[]; - } - - export interface PropertySets { - // TODO docs - enter?: PropertySet; - exit?: PropertySet; - update?: PropertySet; - hover?: PropertySet; - } - - export interface PropertySet { - // TODO docs - - // -- Shared visual properties - x?: ValueRefs; - x2?: ValueRefs; - width?: ValueRefs; - y?: ValueRefs; - y2?: ValueRefs; - height?: ValueRefs; - opacity?: ValueRefs; - fill?: ValueRefs; - fillOpacity?: ValueRefs; - stroke?: ValueRefs; - strokeWidth?: ValueRefs; - strokeOpacity?: ValueRefs; - strokeDash?: ValueRefs; - strokeDashOffset?: ValueRefs; - - // -- symbol - size?: ValueRefs; - shape?: ValueRefs; - - // -- path - path?: ValueRefs; - - // -- arc - innerRadius?: ValueRefs; - outerRadius?: ValueRefs; - startAngle?: ValueRefs; - endAngle?: ValueRefs; - - // -- area / line - interpolate?: ValueRefs; - tension?: ValueRefs; - - // -- image / text - align?: ValueRefs; - baseline?: ValueRefs; - - // -- image - url?: ValueRefs; - - // -- text - text?: ValueRefs; - dx?: ValueRefs; - dy?: ValueRefs; - angle?: ValueRefs; - font?: ValueRefs; - fontSize?: ValueRefs; - fontWeight?: ValueRefs; - fontStyle?: ValueRefs; - } - - export interface ValueRef { - // TODO docs - value?: any; - field?: any; - group?: any; - scale?: any; - mult?: number; - offset?: number; - band?: boolean; - test?: string; - } - - export type ValueRefs = ValueRef | ValueRef[]; - - export var parse: Parse; - export namespace scene { - export function item(mark: Node): Node; - } - - export class Bounds implements Bounds { - x1: number; - y1: number; - x2: number; - y2: number; - clear(): Bounds; - set(x1: number, y1: number, x2: number, y2: number): Bounds; - add(x: number, y: number): Bounds; - expand(d: number): Bounds; - round(): Bounds; - translate(dx: number, dy: number): Bounds; - rotate(angle: number, x: number, y: number): Bounds; - union(b: Bounds): Bounds; - encloses(b: Bounds): boolean; - intersects(b: Bounds): boolean; - contains(x: number, y: number): boolean; - width(): number; - height(): number; - } - - // TODO: classes for View, Model, etc. -} - -export = vg; -export as namespace vg; -export as namespace Vega; diff --git a/types/vega/tsconfig.json b/types/vega/tsconfig.json deleted file mode 100644 index f49e5e811b..0000000000 --- a/types/vega/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6", - "dom" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "vega-tests.ts" - ] -} \ No newline at end of file diff --git a/types/vega/tslint.json b/types/vega/tslint.json deleted file mode 100644 index a41bf5d19a..0000000000 --- a/types/vega/tslint.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "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 - } -} diff --git a/types/vega/vega-tests.ts b/types/vega/vega-tests.ts deleted file mode 100644 index 5baeaee024..0000000000 --- a/types/vega/vega-tests.ts +++ /dev/null @@ -1,2035 +0,0 @@ - - -// examples from http://trifacta.github.io/vega/editor/ -var specs: Vega.Spec[]; - -specs[0] = { - "name": "arc", - "width": 400, - "height": 400, - "data": [ - { - "name": "table", - "values": [12, 23, 47, 6, 52, 19], - "transform": [ - { "type": "pie", "value": "data" } - ] - } - ], - "scales": [ - { - "name": "r", - "type": "sqrt", - "domain": { "data": "table", "field": "data" }, - "range": [20, 100] - } - ], - "marks": [ - { - "type": "arc", - "from": { "data": "table" }, - "properties": { - "enter": { - "x": { "group": "width", "mult": 0.5 }, - "y": { "group": "height", "mult": 0.5 }, - "startAngle": { "field": "startAngle" }, - "endAngle": { "field": "endAngle" }, - "innerRadius": { "value": 20 }, - "outerRadius": { "scale": "r" }, - "stroke": { "value": "#fff" } - }, - "update": { - "fill": { "value": "#ccc" } - }, - "hover": { - "fill": { "value": "pink" } - } - } - } - ] -} - -specs[1] = { - "width": 500, - "height": 200, - "padding": { "top": 10, "left": 30, "bottom": 30, "right": 10 }, - "data": [ - { - "name": "table", - "values": [ - { "x": 1, "y": 28 }, { "x": 2, "y": 55 }, - { "x": 3, "y": 43 }, { "x": 4, "y": 91 }, - { "x": 5, "y": 81 }, { "x": 6, "y": 53 }, - { "x": 7, "y": 19 }, { "x": 8, "y": 87 }, - { "x": 9, "y": 52 }, { "x": 10, "y": 48 }, - { "x": 11, "y": 24 }, { "x": 12, "y": 49 }, - { "x": 13, "y": 87 }, { "x": 14, "y": 66 }, - { "x": 15, "y": 17 }, { "x": 16, "y": 27 }, - { "x": 17, "y": 68 }, { "x": 18, "y": 16 }, - { "x": 19, "y": 49 }, { "x": 20, "y": 15 } - ] - } - ], - "scales": [ - { - "name": "x", - "type": "linear", - "range": "width", - "zero": false, - "domain": { "data": "table", "field": "data.x" } - }, - { - "name": "y", - "type": "linear", - "range": "height", - "nice": true, - "domain": { "data": "table", "field": "data.y" } - } - ], - "axes": [ - { "type": "x", "scale": "x", "ticks": 20 }, - { "type": "y", "scale": "y" } - ], - "marks": [ - { - "type": "area", - "from": { "data": "table" }, - "properties": { - "enter": { - "interpolate": { "value": "monotone" }, - "x": { "scale": "x", "field": "data.x" }, - "y": { "scale": "y", "field": "data.y" }, - "y2": { "scale": "y", "value": 0 }, - "fill": { "value": "steelblue" } - }, - "update": { - "fillOpacity": { "value": 1 } - }, - "hover": { - "fillOpacity": { "value": 0.5 } - } - } - } - ] -} - -specs[2] = { - "width": 200, - "height": 720, - "data": [ - { - "name": "barley", - "url": "data/barley.json" - }, - { - "name": "variety", - "source": "barley", - "transform": [ - { "type": "facet", "keys": ["data.variety"] }, - { "type": "stats", "value": "data.yield", "median": true }, - { "type": "sort", "by": "-median" } - ] - }, - { - "name": "site", - "source": "barley", - "transform": [ - { "type": "facet", "keys": ["data.site"] }, - { "type": "stats", "value": "data.yield", "median": true }, - { "type": "sort", "by": "-median" } - ] - } - ], - "scales": [ - { - "name": "g", - "type": "ordinal", - "range": "height", - "padding": 0.15, - "domain": { "data": "site", "field": "key" } - }, - { - "name": "x", - "type": "linear", - "nice": true, - "range": "width", - "domain": { "data": "barley", "field": "data.yield" } - }, - { - "name": "c", - "type": "ordinal", - "range": "category10" - } - ], - "axes": [ - { "type": "x", "scale": "x", "offset": -12 } - ], - "marks": [ - { - "type": "text", - "from": { "data": "site" }, - "properties": { - "enter": { - "x": { "group": "width", "mult": 0.5 }, - "y": { "scale": "g", "field": "key", "offset": -2 }, - "fontWeight": { "value": "bold" }, - "text": { "field": "key" }, - "align": { "value": "center" }, - "baseline": { "value": "bottom" }, - "fill": { "value": "#000" } - } - } - }, - { - "type": "group", - "from": { "data": "site" }, - "scales": [ - { - "name": "y", - "type": "ordinal", - "range": "height", - "points": true, - "padding": 1.2, - "domain": { "data": "variety", "field": "key" } - } - ], - "axes": [ - { - "type": "y", - "scale": "y", - "tickSize": 0, - "properties": { "axis": { "stroke": { "value": "transparent" } } } - } - ], - "properties": { - "enter": { - "x": { "value": 0.5 }, - "y": { "scale": "g", "field": "key" }, - "height": { "scale": "g", "band": true }, - "width": { "group": "width" }, - "stroke": { "value": "#ccc" } - } - }, - "marks": [ - { - "type": "symbol", - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.yield" }, - "y": { "scale": "y", "field": "data.variety" }, - "size": { "value": 50 }, - "stroke": { "scale": "c", "field": "data.year" }, - "strokeWidth": { "value": 2 } - } - } - } - ] - } - ] -} - -specs[3] = { - "width": 960, - "height": 500, - "data": [ - { - "name": "unemp", - "url": "data/unemployment.tsv", - "format": { "type": "tsv", "parse": { "rate": "number" } } - }, - { - "name": "counties", - "url": "data/us-10m.json", - "format": { "type": "topojson", "feature": "counties" }, - "transform": [ - { "type": "geopath", "value": "data", "projection": "albersUsa" }, - { - "type": "zip", - "key": "data.id", - "with": "unemp", - "withKey": "data.id", - "as": "value", - "default": null - }, - { "type": "filter", "test": "d.path!=null && d.value!=null" } - ] - } - ], - "scales": [ - { - "name": "color", - "type": "quantize", - "domain": [0, 0.15], - "range": ["#f7fbff", "#deebf7", "#c6dbef", "#9ecae1", "#6baed6", - "#4292c6", "#2171b5", "#08519c", "#08306b"] - } - ], - "marks": [ - { - "type": "path", - "from": { "data": "counties" }, - "properties": { - "enter": { "path": { "field": "path" } }, - "update": { "fill": { "scale": "color", "field": "value.data.rate" } }, - "hover": { "fill": { "value": "red" } } - } - } - ] -} - -specs[4] = { - "width": 300, - "height": 240, - "data": [ - { - "name": "table", - "url": "data/groups.json" - } - ], - "scales": [ - { - "name": "cat", - "type": "ordinal", - "range": "height", - "padding": 0.2, - "domain": { "data": "table", "field": "data.category" } - }, - { - "name": "val", - "range": "width", - "round": true, - "nice": true, - "domain": { "data": "table", "field": "data.value" } - }, - { - "name": "color", - "type": "ordinal", - "range": "category20" - } - ], - "axes": [ - { "type": "y", "scale": "cat", "tickSize": 0, "tickPadding": 8 }, - { "type": "x", "scale": "val" } - ], - "marks": [ - { - "type": "group", - "from": { - "data": "table", - "transform": [{ "type": "facet", "keys": ["data.category"] }] - }, - "properties": { - "enter": { - "y": { "scale": "cat", "field": "key" }, - "height": { "scale": "cat", "band": true } - } - }, - "scales": [ - { - "name": "pos", - "type": "ordinal", - "range": "height", - "domain": { "field": "data.position" } - } - ], - "marks": [ - { - "type": "rect", - "properties": { - "enter": { - "y": { "scale": "pos", "field": "data.position" }, - "height": { "scale": "pos", "band": true }, - "x": { "scale": "val", "field": "data.value" }, - "x2": { "scale": "val", "value": 0 }, - "fill": { "scale": "color", "field": "data.position" } - } - } - }, - { - "type": "text", - "properties": { - "enter": { - "y": { "scale": "pos", "field": "data.position" }, - "dy": { "scale": "pos", "band": true, "mult": 0.5 }, - "x": { "scale": "val", "field": "data.value", "offset": -4 }, - "fill": { "value": "white" }, - "align": { "value": "right" }, - "baseline": { "value": "middle" }, - "text": { "field": "data.value" } - } - } - } - ] - } - ] -} - -specs[5] = { - "width": 400, - "height": 100, - "padding": { "top": 30, "left": 30, "bottom": 30, "right": 10 }, - "data": [ - { - "name": "stats", - "values": [ - { "label": "Category A", "mean": 1, "lo": 0, "hi": 2 }, - { "label": "Category B", "mean": 2, "lo": 1.5, "hi": 2.5 }, - { "label": "Category C", "mean": 3, "lo": 1.7, "hi": 4.3 }, - { "label": "Category D", "mean": 4, "lo": 3, "hi": 5 }, - { "label": "Category E", "mean": 5, "lo": 4.1, "hi": 5.9 } - ] - } - ], - "scales": [ - { - "name": "y", - "type": "ordinal", - "range": "height", - "domain": { "data": "stats", "field": "index" } - }, - { - "name": "x", - "range": [100, 400], - "nice": true, - "zero": true, - "domain": { "data": "stats", "field": "data.hi" } - } - ], - "axes": [ - { "type": "x", "scale": "x", "ticks": 6 } - ], - "marks": [ - { - "type": "text", - "from": { "data": "stats" }, - "properties": { - "enter": { - "x": { "value": 0 }, - "y": { "scale": "y", "field": "index" }, - "baseline": { "value": "middle" }, - "fill": { "value": "#000" }, - "text": { "field": "data.label" }, - "font": { "value": "Helvetica Neue" }, - "fontSize": { "value": 13 } - } - } - }, - { - "type": "rect", - "from": { "data": "stats" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.lo" }, - "x2": { "scale": "x", "field": "data.hi" }, - "y": { "scale": "y", "field": "index", "offset": -1 }, - "height": { "value": 1 }, - "fill": { "value": "#888" } - } - } - }, - { - "type": "symbol", - "from": { "data": "stats" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.mean" }, - "y": { "scale": "y", "field": "index" }, - "size": { "value": 40 }, - "fill": { "value": "#000" } - } - } - } - ] -} - -specs[6] = { - "name": "force", - "width": 500, - "height": 500, - "padding": { "top": 0, "bottom": 0, "left": 0, "right": 0 }, - "data": [ - { - "name": "edges", - "url": "data/miserables.json", - "format": { "type": "json", "property": "links" }, - "transform": [ - { "type": "copy", "from": "data", "fields": ["source", "target"] } - ] - }, - { - "name": "nodes", - "url": "data/miserables.json", - "format": { "type": "json", "property": "nodes" }, - "transform": [ - { - "type": "force", - "links": "edges", - "linkDistance": 70, - "charge": -100, - "iterations": 1000 - } - ] - } - ], - "marks": [ - { - "type": "path", - "from": { - "data": "edges", - "transform": [ - { "type": "link", "shape": "line" } - ] - }, - "properties": { - "update": { - "path": { "field": "path" }, - "stroke": { "value": "#ccc" }, - "strokeWidth": { "value": 0.5 } - } - } - }, - { - "type": "symbol", - "from": { "data": "nodes" }, - "properties": { - "enter": { - "fillOpacity": { "value": 0.3 }, - "stroke": { "value": "steelblue" } - }, - "update": { - "x": { "field": "x" }, - "y": { "field": "y" }, - "fill": { "value": "steelblue" } - }, - "hover": { - "fill": { "value": "#f00" } - } - } - } - ] -}; - -specs[7] = { - "name": "image", - "width": 200, - "height": 200, - "padding": { "left": 30, "top": 10, "bottom": 30, "right": 10 }, - "data": [ - { - "name": "data", - "values": [ - { "x": 0.5, "y": 0.5, "img": "data/ffox.png" }, - { "x": 1.5, "y": 1.5, "img": "data/gimp.png" }, - { "x": 2.5, "y": 2.5, "img": "data/7zip.png" } - ] - } - ], - "scales": [ - { "name": "x", "domain": [0, 3], "range": "width" }, - { "name": "y", "domain": [0, 3], "range": "height" } - ], - "axes": [ - { "type": "x", "scale": "x" }, - { "type": "y", "scale": "y" } - ], - "marks": [ - { - "type": "image", - "from": { "data": "data" }, - "properties": { - "enter": { - "url": { "field": "data.img" }, - "width": { "value": 50 }, - "height": { "value": 50 }, - "x": { "scale": "x", "field": "data.x" }, - "y": { "scale": "y", "field": "data.y" }, - "align": { "value": "center" }, - "baseline": { "value": "middle" } - }, - "update": { - "opacity": { "value": 1.0 } - }, - "hover": { - "opacity": { "value": 0.5 } - } - } - } - ] -} - -specs[8] = { - "width": 800, - "height": 500, - "padding": { "left": 15, "right": 65, "top": 10, "bottom": 20 }, - "data": [ - { - "name": "jobs", - "url": "data/jobs.json" - }, - { - "name": "series", - "source": "jobs", - "transform": [ - { "type": "facet", "keys": ["data.job", "data.sex"] }, - { "type": "stats", "value": "data.perc" }, - { "type": "stack", "point": "data.year", "height": "data.perc", "order": "reverse" } - ] - }, - { - "name": "stats", - "source": "jobs", - "transform": [ - { "type": "facet", "keys": ["data.year"] }, - { "type": "stats", "value": "data.perc" } - ] - } - ], - "scales": [ - { - "name": "x", - "type": "linear", - "range": "width", - "zero": false, "round": true, - "domain": { "data": "jobs", "field": "data.year" } - }, - { - "name": "y", - "type": "linear", - "range": "height", "round": true, - "domain": { "data": "stats", "field": "sum" } - }, - { - "name": "color", - "type": "ordinal", - "domain": ["men", "women"], - "range": ["#33f", "#f33"] - }, - { - "name": "alpha", - "type": "linear", - "domain": { "data": "series", "field": "sum" }, - "range": [0.4, 0.8] - }, - { - "name": "font", - "type": "sqrt", - "range": [0, 24], "round": true, - "domain": { "data": "stats", "field": "sum" } - }, - { - "name": "align", - "type": "quantize", - "range": ["left", "center", "right"], "zero": false, - "domain": [1730, 2130] - }, - { - "name": "offset", - "type": "quantize", - "range": [6, 0, -6], "zero": false, - "domain": [1730, 2130] - } - ], - "axes": [ - { "type": "x", "scale": "x", "format": "d", "ticks": 15, "tickSizeEnd": 0 }, - { - "type": "y", "scale": "y", "format": "n", "orient": "right", - "grid": true, "layer": "back", "tickSize": 12, - "properties": { - "axis": { "stroke": { "value": "transparent" } }, - "grid": { "stroke": { "value": "#ccc" } }, - "ticks": { "stroke": { "value": "#ccc" } } - } - } - ], - "marks": [ - { - "type": "group", - "from": { "data": "series" }, - "marks": [ - { - "type": "area", - "properties": { - "update": { - "x": { "scale": "x", "field": "data.year" }, - "y": { "scale": "y", "field": "y" }, - "y2": { "scale": "y", "field": "y2" }, - "fill": { "scale": "color", "field": "data.sex" }, - "fillOpacity": { "scale": "alpha", "group": "sum" } - }, - "hover": { - "fillOpacity": { "value": 0.2 } - } - } - } - ] - }, - { - "type": "group", - "from": { "data": "series" }, - "marks": [ - { - "type": "text", - "from": { - "transform": [ - { "type": "slice", "by": "max", "field": "data.perc" } - ] - }, - "interactive": false, - "properties": { - "update": { - "x": { "scale": "x", "field": "data.year" }, - "dx": { "scale": "offset", "field": "data.year" }, - "y": { "scale": "y", "field": "cy" }, - "fill": { "value": "#000" }, - "fillOpacity": { "scale": "font", "field": "data.perc", "mult": 0.15 }, - "fontSize": { "scale": "font", "field": "data.perc", "offset": 5 }, - "text": { "field": "data.job" }, - "align": { "scale": "align", "field": "data.year" }, - "baseline": { "value": "middle" } - } - } - } - ] - } - ] -}; - -specs[9] = { - "name": "lifelines", - "width": 400, - "height": 100, - "data": [ - { - "name": "people", - "values": [ - { - "label": "Washington", "born": -7506057600000, "died": -5366196000000, - "enter": -5701424400000, "leave": -5453884800000 - }, - { - "label": "Adams", "born": -7389766800000, "died": -4528285200000, - "enter": -5453884800000, "leave": -5327740800000 - }, - { - "label": "Jefferson", "born": -7154586000000, "died": -4528285200000, - "enter": -5327740800000, "leave": -5075280000000 - }, - { - "label": "Madison", "born": -6904544400000, "died": -4213184400000, - "enter": -5075280000000, "leave": -4822819200000 - }, - { - "label": "Monroe", "born": -6679904400000, "died": -4370518800000, - "enter": -4822819200000, "leave": -4570358400000 - } - ] - }, - { - "name": "events", - "format": { "type": "json", "parse": { "when": "date" } }, - "values": [ - { "name": "Decl. of Independence", "when": "July 4, 1776" }, - { "name": "U.S. Constitution", "when": "3/4/1789" }, - { "name": "Louisiana Purchase", "when": "April 30, 1803" }, - { "name": "Monroe Doctrine", "when": "Dec 2, 1823" } - ] - } - - ], - "scales": [ - { - "name": "y", - "type": "ordinal", - "range": "height", - "domain": { "data": "people", "field": "data.label" } - }, - { - "name": "x", - "type": "time", - "range": "width", - "round": true, - "nice": "year", - "domain": { "data": "people", "field": ["data.born", "data.died"] } - } - ], - "axes": [ - { "type": "x", "scale": "x" } - ], - "marks": [ - { - "type": "text", - "from": { "data": "events" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.when" }, - "y": { "value": -10 }, - "angle": { "value": -25 }, - "fill": { "value": "#000" }, - "text": { "field": "data.name" }, - "font": { "value": "Helvetica Neue" }, - "fontSize": { "value": 10 } - } - } - }, - { - "type": "rect", - "from": { "data": "events" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.when" }, - "y": { "value": -8 }, - "width": { "value": 1 }, - "height": { "group": "height", "offset": 8 }, - "fill": { "value": "#888" } - } - } - }, - { - "type": "text", - "from": { "data": "people" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.born" }, - "y": { "scale": "y", "field": "data.label", "offset": -3 }, - "fill": { "value": "#000" }, - "text": { "field": "data.label" }, - "font": { "value": "Helvetica Neue" }, - "fontSize": { "value": 10 } - } - } - }, - { - "type": "rect", - "from": { "data": "people" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.born" }, - "x2": { "scale": "x", "field": "data.died" }, - "y": { "scale": "y", "field": "data.label" }, - "height": { "value": 2 }, - "fill": { "value": "#557" } - } - } - }, - { - "type": "rect", - "from": { "data": "people" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.enter" }, - "x2": { "scale": "x", "field": "data.leave" }, - "y": { "scale": "y", "field": "data.label", "offset": -1 }, - "height": { "value": 4 }, - "fill": { "value": "#e44" } - } - } - } - ] -} - -specs[10] = { - "width": 1920, - "height": 1000, - "viewport": [960, 500], - "data": [ - { - "name": "world", - "url": "data/world-110m.json", - "format": { "type": "topojson", "feature": "countries" } - } - ], - "marks": [ - { - "type": "path", - "from": { - "data": "world", - "transform": [{ - "type": "geopath", - "value": "data", - "projection": "winkel3", - "scale": 300, - "translate": [960, 500] - }] - }, - "properties": { - "enter": { - "stroke": { "value": "#fff" }, - "path": { "field": "path" } - }, - "update": { "fill": { "value": "#ccc" } }, - "hover": { "fill": { "value": "pink" } } - } - } - ] -} - -specs[11] = { - "width": 760, - "height": 260, - "data": [ - { - "name": "temp", - "url": "data/napoleon.json", - "format": { "type": "json", "property": "temp" }, - "transform": [ - { "type": "formula", "field": "lat", "expr": "55" }, - { - "type": "geo", - "lat": "lat", - "lon": "data.lon", - "center": [32.52, 53.3], - "scale": 3000 - } - ] - }, - { - "name": "army", - "url": "data/napoleon.json", - "format": { "type": "json", "property": "army" }, - "transform": [ - { - "type": "geo", - "lat": "data.lat", - "lon": "data.lon", - "center": [32.52, 53.3], - "scale": 3000 - } - ] - }, - { - "name": "cities", - "url": "data/napoleon.json", - "format": { "type": "json", "property": "cities" }, - "transform": [ - { - "type": "geo", - "lat": "data.lat", - "lon": "data.lon", - "center": [32.52, 53.3], - "scale": 3000 - } - ] - } - ], - "scales": [ - { - "name": "color", - "type": "ordinal", - "domain": { "data": "army", "field": "data.dir" }, - "range": ["brown", "black"] - }, - { - "name": "lw", - "type": "linear", "zero": false, - "domain": { "data": "army", "field": "data.size" }, - "range": [1, 50] - } - ], - "marks": [ - { - "type": "group", - "properties": { - "enter": { - "x": { "value": 0 }, - "y": { "value": 200 }, - "width": { "group": "width" }, - "height": { "value": 60 } - } - }, - "scales": [ - { - "name": "y", - "type": "linear", "zero": false, "round": true, - "domain": { "data": "temp", "field": "data.temp" }, - "range": "height" - } - ], - "axes": [ - { - "type": "y", "scale": "y", "ticks": 4, "orient": "right", - "grid": true, "layer": "back" - } - ], - "marks": [ - { - "type": "rule", - "from": { "data": "temp" }, - "properties": { - "enter": { - "x": { "field": "x" }, - "y1": 0, - "y2": { "scale": "y", "field": "data.temp" }, - "stroke": { "value": "#ccc" } - } - } - }, - { - "type": "line", - "from": { "data": "temp" }, - "properties": { - "enter": { - "x": { "field": "x" }, - "y": { "scale": "y", "field": "data.temp" }, - "stroke": { "value": "#000" }, - "strokeWidth": { "value": 2 } - } - } - }, - { - "type": "text", - "from": { "data": "temp" }, - "properties": { - "enter": { - "x": { "field": "x", "offset": -2 }, - "y": { "scale": "y", "field": "data.temp", "offset": 6 }, - "fill": { "value": "#000" }, - "text": { "field": "data.date" }, - "font": { "value": "Georgia" }, - "fontSize": { "value": 10 }, - "align": { "value": "center" }, - "baseline": { "value": "top" } - } - } - } - ] - }, - { - "type": "group", - "from": { - "data": "army", - "transform": [ - { "type": "facet", "keys": ["data.group", "data.dir"] } - ] - }, - "marks": [ - { - "type": "group", - "from": { - "transform": [ - { "type": "window", "size": 2, "step": 1 } - ] - }, - "marks": [ - { - "type": "line", - "properties": { - "enter": { - "x": { "field": "x" }, - "y": { "field": "y" }, - "stroke": { "scale": "color", "field": "data.dir" }, - "strokeWidth": { "scale": "lw", "field": "data.size" }, - "strokeCap": { "value": "round" } - } - } - } - ] - } - ] - }, - { - "type": "symbol", - "from": { "data": "cities" }, - "properties": { - "enter": { - "x": { "field": "x" }, - "y": { "field": "y" }, - "size": { "value": 25 }, - "fill": { "value": "brown" }, - "stroke": { "value": "#000" } - } - } - }, - { - "type": "text", - "from": { "data": "cities" }, - "properties": { - "enter": { - "x": { "field": "x", "offset": 1 }, - "y": { "field": "y", "offset": -4 }, - "fill": { "value": "#fff" }, - "fillOpacity": { "value": 0.8 }, - "text": { "field": "data.city" }, - "align": { "value": "center" }, - "baseline": { "value": "bottom" }, - "font": { "value": "Georgia" }, - "fontSize": { "value": 9 }, - "fontStyle": { "value": "italic" } - } - } - }, - { - "type": "text", - "from": { "data": "cities" }, - "properties": { - "enter": { - "x": { "field": "x" }, - "y": { "field": "y", "offset": -5 }, - "fill": { "value": "#000" }, - "text": { "field": "data.city" }, - "align": { "value": "center" }, - "baseline": { "value": "bottom" }, - "font": { "value": "Georgia" }, - "fontSize": { "value": 9 }, - "fontStyle": { "value": "italic" } - } - } - } - ] -} - -specs[12] = { - "width": 700, - "height": 400, - "data": [ - { - "name": "cars", - "url": "data/cars.json" - }, - { - "name": "fields", - "values": ["cyl", "dsp", "lbs", "hp", "acc", "mpg", "year"] - } - ], - "scales": [ - { - "name": "ord", - "type": "ordinal", - "range": "width", "points": true, - "domain": { "data": "fields", "field": "data" } - }, - { - "name": "cyl", - "range": "height", "zero": false, "nice": true, - "domain": { "data": "cars", "field": "data.cyl" } - }, - { - "name": "dsp", - "range": "height", "zero": false, "nice": true, - "domain": { "data": "cars", "field": "data.dsp" } - }, - { - "name": "lbs", - "range": "height", "zero": false, "nice": true, - "domain": { "data": "cars", "field": "data.lbs" } - }, - { - "name": "hp", - "range": "height", "zero": false, "nice": true, - "domain": { "data": "cars", "field": "data.hp" } - }, - { - "name": "acc", - "range": "height", "zero": false, "nice": true, - "domain": { "data": "cars", "field": "data.acc" } - }, - { - "name": "mpg", - "range": "height", "zero": false, "nice": true, - "domain": { "data": "cars", "field": "data.mpg" } - }, - { - "name": "year", - "range": "height", "zero": false, "nice": true, - "domain": { "data": "cars", "field": "data.year" } - } - ], - "axes": [ - { "type": "y", "scale": "cyl", "offset": { "scale": "ord", "value": "cyl" } }, - { "type": "y", "scale": "dsp", "offset": { "scale": "ord", "value": "dsp" } }, - { "type": "y", "scale": "lbs", "offset": { "scale": "ord", "value": "lbs" } }, - { "type": "y", "scale": "hp", "offset": { "scale": "ord", "value": "hp" } }, - { "type": "y", "scale": "acc", "offset": { "scale": "ord", "value": "acc" } }, - { "type": "y", "scale": "mpg", "offset": { "scale": "ord", "value": "mpg" } }, - { "type": "y", "scale": "year", "offset": { "scale": "ord", "value": "year" } } - ], - "marks": [ - { - "type": "group", - "from": { "data": "cars" }, - "marks": [ - { - "type": "line", - "from": { "data": "fields" }, - "properties": { - "enter": { - "x": { "scale": "ord", "field": "data" }, - "y": { "scale": { "field": "data" }, "group": "data", "field": "data" }, - "stroke": { "value": "steelblue" }, - "strokeWidth": { "value": 1 }, - "strokeOpacity": { "value": 0.3 } - } - } - } - ] - }, - { - "type": "text", - "from": { "data": "fields" }, - "properties": { - "enter": { - "x": { "scale": "ord", "field": "data", "offset": -8 }, - "y": { "group": "height", "offset": 6 }, - "fontWeight": { "value": "bold" }, - "fill": { "value": "black" }, - "text": { "field": "data" }, - "align": { "value": "right" }, - "baseline": { "value": "top" } - } - } - } - ] -} - -specs[13] = { - "width": 700, - "height": 400, - "padding": { "top": 0, "left": 0, "bottom": 20, "right": 0 }, - "data": [ - { - "name": "pop2000", - "url": "data/population.json", - "transform": [ - { "type": "filter", "test": "d.data.year == 2000" } - ] - } - ], - "scales": [ - { - "name": "g", - "domain": [0, 1], - "range": [340, 10] - }, - { - "name": "y", - "type": "ordinal", - "range": "height", - "reverse": true, - "domain": { "data": "pop2000", "field": "data.age" } - }, - { - "name": "c", - "type": "ordinal", - "domain": [1, 2], - "range": ["#1f77b4", "#e377c2"] - } - ], - "marks": [ - { - "type": "text", - "interactive": false, - "from": { - "data": "pop2000", - "transform": [{ "type": "unique", "field": "data.age", "as": "age" }] - }, - "properties": { - "enter": { - "x": { "value": 325 }, - "y": { "scale": "y", "field": "age", "offset": 11 }, - "text": { "field": "age" }, - "baseline": { "value": "middle" }, - "align": { "value": "center" }, - "fill": { "value": "#000" } - } - } - }, - { - "type": "group", - "from": { - "data": "pop2000", - "transform": [ - { "type": "facet", "keys": ["data.sex"] } - ] - }, - "properties": { - "update": { - "x": { "scale": "g", "field": "index" }, - "y": { "value": 0 }, - "width": { "value": 300 }, - "height": { "group": "height" } - } - }, - "scales": [ - { - "name": "x", - "type": "linear", - "range": "width", - "reverse": true, - "nice": true, - "domain": { "data": "pop2000", "field": "data.people" } - } - ], - "axes": [ - { "type": "x", "scale": "x", "format": "s" } - ], - "marks": [ - { - "type": "rect", - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.people" }, - "x2": { "scale": "x", "value": 0 }, - "y": { "scale": "y", "field": "data.age" }, - "height": { "scale": "y", "band": true, "offset": -1 }, - "fillOpacity": { "value": 0.6 }, - "fill": { "scale": "c", "field": "data.sex" } - } - } - } - ] - } - ] -} - -specs[14] = { - "width": 200, - "height": 200, - "data": [ - { - "name": "iris", - "url": "data/iris.json" - } - ], - "scales": [ - { - "name": "x", - "nice": true, - "range": "width", - "domain": { "data": "iris", "field": "data.sepalWidth" } - }, - { - "name": "y", - "nice": true, - "range": "height", - "domain": { "data": "iris", "field": "data.petalLength" } - }, - { - "name": "c", - "type": "ordinal", - "domain": { "data": "iris", "field": "data.species" }, - "range": ["#800", "#080", "#008"] - } - ], - "axes": [ - { "type": "x", "scale": "x", "offset": 5, "ticks": 5, "title": "Sepal Width" }, - { "type": "y", "scale": "y", "offset": 5, "ticks": 5, "title": "Petal Length" } - ], - "legends": [ - { - "fill": "c", - "title": "Species", - "offset": 0, - "properties": { - "symbols": { - "fillOpacity": { "value": 0.5 }, - "stroke": { "value": "transparent" } - } - } - } - ], - "marks": [ - { - "type": "symbol", - "from": { "data": "iris" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.sepalWidth" }, - "y": { "scale": "y", "field": "data.petalLength" }, - "fill": { "scale": "c", "field": "data.species" }, - "fillOpacity": { "value": 0.5 } - }, - "update": { - "size": { "value": 100 }, - "stroke": { "value": "transparent" } - }, - "hover": { - "size": { "value": 300 }, - "stroke": { "value": "white" } - } - } - } - ] -} - -specs[15] = { - "width": 600, - "height": 600, - "data": [ - { - "name": "iris", - "url": "data/iris.json" - }, - { - "name": "fields", - "values": ["petalLength", "petalWidth", "sepalWidth", "sepalLength"] - } - ], - "scales": [ - { - "name": "gx", - "type": "ordinal", - "range": "width", - "round": true, - "domain": { "data": "fields", "field": "data" } - }, - { - "name": "gy", - "type": "ordinal", - "range": "height", - "round": true, - "domain": { "data": "fields", "field": "data" } - }, - { - "name": "c", - "type": "ordinal", - "domain": { "data": "iris", "field": "data.species" }, - "range": ["#800", "#080", "#008"] - } - ], - "legends": [ - { - "fill": "c", - "title": "Species", - "offset": 10, - "properties": { - "symbols": { - "fillOpacity": { "value": 0.5 }, - "stroke": { "value": "transparent" } - } - } - } - ], - "marks": [ - { - "type": "group", - "from": { - "data": "fields", - "transform": [{ "type": "cross" }] - }, - "properties": { - "enter": { - "x": { "scale": "gx", "field": "a.data" }, - "y": { "scale": "gy", "field": "b.data" }, - "width": { "scale": "gx", "band": true, "offset": -35 }, - "height": { "scale": "gy", "band": true, "offset": -35 }, - "stroke": { "value": "#ddd" } - } - }, - "scales": [ - { - "name": "x", - "range": "width", - "zero": false, - "round": true, - "domain": { "data": "iris", "field": { "group": "a.data" } } - }, - { - "name": "y", - "range": "height", - "zero": false, - "round": true, - "domain": { "data": "iris", "field": { "group": "b.data" } } - } - ], - "axes": [ - { "type": "x", "scale": "x", "ticks": 5 }, - { "type": "y", "scale": "y", "ticks": 5 } - ], - "marks": [ - { - "type": "symbol", - "from": { "data": "iris" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": { "group": "a.data" } }, - "y": { "scale": "y", "field": { "group": "b.data" } }, - "fill": { "scale": "c", "field": "data.spec[0]ies" }, - "fillOpacity": { "value": 0.5 } - }, - "update": { - "size": { "value": 36 }, - "stroke": { "value": "transparent" } - }, - "hover": { - "size": { "value": 100 }, - "stroke": { "value": "white" } - } - } - } - ] - } - ] -} - -specs[16] = { - "width": 500, - "height": 200, - "padding": { "top": 10, "left": 30, "bottom": 30, "right": 10 }, - "data": [ - { - "name": "table", - "values": [ - { "x": 0, "y": 28, "c": 0 }, { "x": 0, "y": 55, "c": 1 }, - { "x": 1, "y": 43, "c": 0 }, { "x": 1, "y": 91, "c": 1 }, - { "x": 2, "y": 81, "c": 0 }, { "x": 2, "y": 53, "c": 1 }, - { "x": 3, "y": 19, "c": 0 }, { "x": 3, "y": 87, "c": 1 }, - { "x": 4, "y": 52, "c": 0 }, { "x": 4, "y": 48, "c": 1 }, - { "x": 5, "y": 24, "c": 0 }, { "x": 5, "y": 49, "c": 1 }, - { "x": 6, "y": 87, "c": 0 }, { "x": 6, "y": 66, "c": 1 }, - { "x": 7, "y": 17, "c": 0 }, { "x": 7, "y": 27, "c": 1 }, - { "x": 8, "y": 68, "c": 0 }, { "x": 8, "y": 16, "c": 1 }, - { "x": 9, "y": 49, "c": 0 }, { "x": 9, "y": 15, "c": 1 } - ] - }, - { - "name": "stats", - "source": "table", - "transform": [ - { "type": "facet", "keys": ["data.x"] }, - { "type": "stats", "value": "data.y" } - ] - } - ], - "scales": [ - { - "name": "x", - "type": "linear", - "range": "width", - "zero": false, - "domain": { "data": "table", "field": "data.x" } - }, - { - "name": "y", - "type": "linear", - "range": "height", - "nice": true, - "domain": { "data": "stats", "field": "sum" } - }, - { - "name": "color", - "type": "ordinal", - "range": "category10" - } - ], - "axes": [ - { "type": "x", "scale": "x" }, - { "type": "y", "scale": "y" } - ], - "marks": [ - { - "type": "group", - "from": { - "data": "table", - "transform": [ - { "type": "facet", "keys": ["data.c"] }, - { "type": "stack", "point": "data.x", "height": "data.y" } - ] - }, - "marks": [ - { - "type": "area", - "properties": { - "enter": { - "interpolate": { "value": "monotone" }, - "x": { "scale": "x", "field": "data.x" }, - "y": { "scale": "y", "field": "y" }, - "y2": { "scale": "y", "field": "y2" }, - "fill": { "scale": "color", "field": "data.c" } - }, - "update": { - "fillOpacity": { "value": 1 } - }, - "hover": { - "fillOpacity": { "value": 0.5 } - } - } - } - ] - } - ] -} - -specs[17] = { - "width": 500, - "height": 200, - "padding": { "top": 10, "left": 30, "bottom": 30, "right": 10 }, - "data": [ - { - "name": "table", - "values": [ - { "x": 0, "y": 28, "c": 0 }, { "x": 0, "y": 55, "c": 1 }, - { "x": 1, "y": 43, "c": 0 }, { "x": 1, "y": 91, "c": 1 }, - { "x": 2, "y": 81, "c": 0 }, { "x": 2, "y": 53, "c": 1 }, - { "x": 3, "y": 19, "c": 0 }, { "x": 3, "y": 87, "c": 1 }, - { "x": 4, "y": 52, "c": 0 }, { "x": 4, "y": 48, "c": 1 }, - { "x": 5, "y": 24, "c": 0 }, { "x": 5, "y": 49, "c": 1 }, - { "x": 6, "y": 87, "c": 0 }, { "x": 6, "y": 66, "c": 1 }, - { "x": 7, "y": 17, "c": 0 }, { "x": 7, "y": 27, "c": 1 }, - { "x": 8, "y": 68, "c": 0 }, { "x": 8, "y": 16, "c": 1 }, - { "x": 9, "y": 49, "c": 0 }, { "x": 9, "y": 15, "c": 1 } - ] - }, - { - "name": "stats", - "source": "table", - "transform": [ - { "type": "facet", "keys": ["data.x"] }, - { "type": "stats", "value": "data.y" } - ] - } - ], - "scales": [ - { - "name": "x", - "type": "ordinal", - "range": "width", - "domain": { "data": "table", "field": "data.x" } - }, - { - "name": "y", - "type": "linear", - "range": "height", - "nice": true, - "domain": { "data": "stats", "field": "sum" } - }, - { - "name": "color", - "type": "ordinal", - "range": "category10" - } - ], - "axes": [ - { "type": "x", "scale": "x" }, - { "type": "y", "scale": "y" } - ], - "marks": [ - { - "type": "group", - "from": { - "data": "table", - "transform": [ - { "type": "facet", "keys": ["data.c"] }, - { "type": "stack", "point": "data.x", "height": "data.y" } - ] - }, - "marks": [ - { - "type": "rect", - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.x" }, - "width": { "scale": "x", "band": true, "offset": -1 }, - "y": { "scale": "y", "field": "y" }, - "y2": { "scale": "y", "field": "y2" }, - "fill": { "scale": "color", "field": "data.c" } - }, - "update": { - "fillOpacity": { "value": 1 } - }, - "hover": { - "fillOpacity": { "value": 0.5 } - } - } - } - ] - } - ] -} - -specs[18] = { - "width": 500, - "height": 200, - "data": [ - { - "name": "stocks", - "url": "data/stocks.csv", - "format": { "type": "csv", "parse": { "price": "number", "date": "date" } } - } - ], - "scales": [ - { - "name": "x", - "type": "time", - "range": "width", - "domain": { "data": "stocks", "field": "data.date" } - }, - { - "name": "y", - "type": "linear", - "range": "height", - "nice": true, - "domain": { "data": "stocks", "field": "data.price" } - }, - { - "name": "color", "type": "ordinal", "range": "category10" - } - ], - "axes": [ - { "type": "x", "scale": "x", "tickSizeEnd": 0 }, - { "type": "y", "scale": "y" } - ], - "marks": [ - { - "type": "group", - "from": { - "data": "stocks", - "transform": [{ "type": "facet", "keys": ["data.symbol"] }] - }, - "marks": [ - { - "type": "line", - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.date" }, - "y": { "scale": "y", "field": "data.price" }, - "stroke": { "scale": "color", "field": "data.symbol" }, - "strokeWidth": { "value": 2 } - } - } - }, - { - "type": "text", - "from": { - "transform": [{ "type": "filter", "test": "index==data.length-1" }] - }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "data.date", "offset": 2 }, - "y": { "scale": "y", "field": "data.price" }, - "fill": { "scale": "color", "field": "data.symbol" }, - "text": { "field": "data.symbol" }, - "baseline": { "value": "middle" } - } - } - } - ] - } - ] -} - -specs[19] = { - "name": "treemap", - "width": 960, - "height": 500, - "padding": 2.5, - "data": [ - { - "name": "tree", - "url": "data/flare.json", - "format": { "type": "treejson" }, - "transform": [ - { "type": "treemap", "value": "data.size" } - ] - } - ], - "scales": [ - { - "name": "color", - "type": "ordinal", - "range": [ - "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d", - "#fd8d3c", "#fdae6b", "#fdd0a2", "#31a354", "#74c476", - "#a1d99b", "#c7e9c0", "#756bb1", "#9e9ac8", "#bcbddc", - "#dadaeb", "#636363", "#969696", "#bdbdbd", "#d9d9d9" - ] - }, - { - "name": "size", - "type": "ordinal", - "domain": [0, 1, 2, 3], - "range": [256, 28, 20, 14] - }, - { - "name": "opacity", - "type": "ordinal", - "domain": [0, 1, 2, 3], - "range": [0.15, 0.5, 0.8, 1.0] - } - ], - "marks": [ - { - "type": "rect", - "from": { - "data": "tree", - "transform": [{ "type": "filter", "test": "d.values" }] - }, - "interactive": false, - "properties": { - "enter": { - "x": { "field": "x" }, - "y": { "field": "y" }, - "width": { "field": "width" }, - "height": { "field": "height" }, - "fill": { "scale": "color", "field": "data.name" } - } - } - }, - { - "type": "rect", - "from": { - "data": "tree", - "transform": [{ "type": "filter", "test": "!d.values" }] - }, - "properties": { - "enter": { - "x": { "field": "x" }, - "y": { "field": "y" }, - "width": { "field": "width" }, - "height": { "field": "height" }, - "stroke": { "value": "#fff" } - }, - "update": { - "fill": { "value": "rgba(0,0,0,0)" } - }, - "hover": { - "fill": { "value": "red" } - } - } - }, - { - "type": "text", - "from": { - "data": "tree", - "transform": [{ "type": "filter", "test": "d.values" }] - }, - "interactive": false, - "properties": { - "enter": { - "x": { "field": "x" }, - "y": { "field": "y" }, - "dx": { "field": "width", "mult": 0.5 }, - "dy": { "field": "height", "mult": 0.5 }, - "font": { "value": "Helvetica Neue" }, - "fontSize": { "scale": "size", "field": "depth" }, - "align": { "value": "center" }, - "baseline": { "value": "middle" }, - "fill": { "value": "#000" }, - "fillOpacity": { "scale": "opacity", "field": "depth" }, - "text": { "field": "data.name" } - } - } - } - ] -} - -specs[20] = { - "width": 250, - "height": 200, - "data": [ - { - "name": "weather", - "url": "data/weather.json" - } - ], - "scales": [ - { - "name": "x", - "type": "ordinal", - "range": "width", - "padding": 0.1, "round": true, - "domain": { "data": "weather", "field": "index" } - }, - { - "name": "y", - "range": "height", - "nice": true, "zero": false, "round": true, - "domain": { - "data": "weather", - "field": ["data.record.low", "data.record.high"] - } - } - ], - "axes": [ - { - "type": "y", "scale": "y", "ticks": 3, "tickSize": 0, - "orient": "right", "grid": true, - "properties": { - "grid": { "stroke": { "value": "white" }, "strokeWidth": { "value": 2 } }, - "axis": { "stroke": { "value": "transparent" } } - } - } - ], - "marks": [ - { - "type": "text", - "from": { "data": "weather" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "index" }, - "dx": { "scale": "x", "band": true, "mult": 0.5 }, - "y": { "value": 0 }, - "fill": { "value": "#000" }, - "text": { "field": "data.day" }, - "align": { "value": "center" }, - "baseline": { "value": "bottom" } - } - } - }, - { - "type": "rect", - "from": { "data": "weather" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "index" }, - "width": { "scale": "x", "band": true, "offset": -1 }, - "y": { "scale": "y", "field": "data.record.low" }, - "y2": { "scale": "y", "field": "data.record.high" }, - "fill": { "value": "#ccc" } - } - } - }, - { - "type": "rect", - "from": { "data": "weather" }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "index" }, - "width": { "scale": "x", "band": true, "offset": -1 }, - "y": { "scale": "y", "field": "data.normal.low" }, - "y2": { "scale": "y", "field": "data.normal.high" }, - "fill": { "value": "#999" } - } - } - }, - { - "type": "rect", - "from": { - "data": "weather", - "transform": [{ "type": "filter", "test": "d.data.actual" }] - }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "index", "offset": 4 }, - "width": { "scale": "x", "band": true, "offset": -8 }, - "y": { "scale": "y", "field": "data.actual.low" }, - "y2": { "scale": "y", "field": "data.actual.high" }, - "fill": { "value": "#000" } - } - } - }, - { - "type": "rect", - "from": { - "data": "weather", - "transform": [{ "type": "filter", "test": "d.data.forecast" }] - }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "index", "offset": 9 }, - "width": { "scale": "x", "band": true, "offset": -18 }, - "y": { "scale": "y", "field": "data.forecast.low.low" }, - "y2": { "scale": "y", "field": "data.forecast.high.high" }, - "fill": { "value": "#000" } - } - } - }, - { - "type": "rect", - "from": { - "data": "weather", - "transform": [{ "type": "filter", "test": "d.data.forecast" }] - }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "index", "offset": 4 }, - "width": { "scale": "x", "band": true, "offset": -8 }, - "y": { "scale": "y", "field": "data.forecast.low.low" }, - "y2": { "scale": "y", "field": "data.forecast.low.high" }, - "fill": { "value": "#000" } - } - } - }, - { - "type": "rect", - "from": { - "data": "weather", - "transform": [{ "type": "filter", "test": "d.data.forecast" }] - }, - "properties": { - "enter": { - "x": { "scale": "x", "field": "index", "offset": 4 }, - "width": { "scale": "x", "band": true, "offset": -8 }, - "y": { "scale": "y", "field": "data.forecast.high.low" }, - "y2": { "scale": "y", "field": "data.forecast.high.high" }, - "fill": { "value": "#000" } - } - } - } - ] -} - -const hoverFill21: Vega.ValueRefs = [{ - "test": "datum.value < 30", - "value": "#f00" -}, { - "value": "#f55" -}]; - -specs[21] = { - "name": "wordcloud", - "width": 400, - "height": 400, - "padding": { "top": 0, "bottom": 0, "left": 0, "right": 0 }, - "data": [ - { - "name": "table", - "values": [ - { "text": "poem", "value": 80 }, - { "text": "peom", "value": 44 }, - { "text": "moep", "value": 40 }, - { "text": "meop", "value": 36 }, - { "text": "emop", "value": 32 }, - { "text": "epom", "value": 28 }, - { "text": "opem", "value": 24 }, - { "text": "omep", "value": 20 }, - { "text": "mope", "value": 56 }, - { "text": "mepo", "value": 12 }, - { "text": "pemo", "value": 10 }, - { "text": "pome", "value": 10 } - ], - "transform": [ - { - "type": "wordcloud", - "text": "data.text", - "font": "Helvetica Neue", - "fontSize": "data.value", - "rotate": { "random": [-60, -30, 0, 30, 60] } - } - ] - } - ], - "marks": [ - { - "type": "text", - "from": { "data": "table" }, - "properties": { - "enter": { - "x": { "field": "x" }, - "y": { "field": "y" }, - "angle": { "field": "angle" }, - "align": { "value": "center" }, - "baseline": { "value": "alphabetic" }, - "font": { "field": "font" }, - "fontSize": { "field": "fontSize" }, - "text": { "field": "data.text" } - }, - "update": { - "fill": [{ - "test": "datum.value < 30", - "value": "steelblue" - }, { - "value": "blue" - }] - }, - "hover": { - "fill": hoverFill21 - } - } - } - ] -} - -specs.forEach(spec => { - vg.parse.spec(spec, chart => { - chart({el:"#vis"}).update(); - }); -}); diff --git a/types/vfile-location/index.d.ts b/types/vfile-location/index.d.ts index e8ad37bc32..fbea17630e 100644 --- a/types/vfile-location/index.d.ts +++ b/types/vfile-location/index.d.ts @@ -1,12 +1,13 @@ // Type definitions for vfile-location 2.0 // Project: https://github.com/vfile/vfile-location // Definitions by: Ika +// Junyoung Choi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.4 +// TypeScript Version: 3.0 import * as VFile from "vfile"; -declare function vfileLocation(vfile: string | VFile.VFile<{}>): vfileLocation.Location; +declare function vfileLocation(vfile: string | VFile.VFile): vfileLocation.Location; declare namespace vfileLocation { interface Location { diff --git a/types/vfile/index.d.ts b/types/vfile/index.d.ts index 2ef3b03f19..df729e0a49 100644 --- a/types/vfile/index.d.ts +++ b/types/vfile/index.d.ts @@ -1,35 +1,34 @@ -// Type definitions for VFile 2.2 +// Type definitions for VFile 3.0 // Project: https://github.com/vfile/vfile // Definitions by: bizen241 // Junyoung Choi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.4 +// TypeScript Version: 3.0 /// import * as Unist from 'unist'; declare namespace vfile { - type Contents = string | Buffer; + type VFileContents = string | Buffer; interface NodeWithPosition extends Unist.Node { position: Unist.Position; [key: string]: any; } - interface VFileParamsBase { - data?: D; - contents?: Contents; + interface VFileOptions { + contents?: VFileContents; path?: string; basename?: string; stem?: string; extname?: string; dirname?: string; cwd?: string; + data?: any; + [key: string]: any; } - type VFileParams = VFileParamsBase & C; - /** * File-related message describing something at certain position. */ @@ -102,12 +101,11 @@ declare namespace vfile { */ type ToString = (encoding?: BufferEncoding) => string; - interface VFileBase { + interface VFile { /** * @param options If `options` is `string` or `Buffer`, treats it as `{contents: options}`. If `options` is a `VFile`, returns it. All other options are set on the newly created `vfile`. */ - (input?: Contents): VFile; - (input?: VFile | VFileParams): VFile; + (input?: VFileContents | F | VFileOptions): F; message: Message; fail: Fail; info: Info; @@ -119,7 +117,7 @@ declare namespace vfile { * Place to store custom information. * It's OK to store custom data directly on the `vfile`, moving it to `data` gives a little more privacy. */ - data: C['data']; + data: unknown; /** * List of messages associated with the file. */ @@ -127,7 +125,7 @@ declare namespace vfile { /** * Raw value. */ - contents: Contents; + contents: VFileContents; /** * Path of `vfile`. * Cannot be nullified. @@ -161,8 +159,6 @@ declare namespace vfile { cwd: string; toString: ToString; } - - type VFile = VFileBase & C; } /** @@ -170,6 +166,6 @@ declare namespace vfile { * Path related properties are set in the following order (least specific to most specific): `history`, `path`, `basename`, `stem`, `extname`, `dirname`. * It’s not possible to set either `dirname` or `extname` without setting either `history`, `path`, `basename`, or `stem` as well. */ -declare const vfile: vfile.VFile<{}>; +declare const vfile: vfile.VFile; export = vfile; diff --git a/types/vfile/readme.md b/types/vfile/readme.md new file mode 100644 index 0000000000..21525242cb --- /dev/null +++ b/types/vfile/readme.md @@ -0,0 +1,60 @@ +## VFile typescript Docs + +Below are some examples of how to use these Definitions.
+Scenarios where the Typescript code is identical to plain Javascript code are omitted. + +### Using `data` property + +Because `data` property type is set `unknown`, you have to make your own type guard. + +```ts +interface CustomData { + message: string; +} +// This is the type guard +function isCustomData(data: any): data is CustomData { + return data != null && typeof data.message === 'string'; +} +function doSomethingWithCustomData(data: CustomData) { +} +const customData: CustomData = { + message: 'tango' +}; +const fileWithData = vfile({ + data: customData +}); + +if (isCustomData(fileWithData.data)) { + doSomethingWithCustomData(fileWithData.data); +} +// The below code will throw a compiler error +doSomethingWithCustomData(fileWithData.data); // $ExpectError +``` + +### Extending VFile + +```ts +import vfile = require('vfile') + +// 1. Define extended vfile interface +interface CustomVFile extends vfile.VFile { + custom: string; + data: { + custom: number; + }; +} + +// 2. Provide the extended interface to generic type parameter +// So it can be used for return value +const file: CustomVFile = vfile({ + path: '~/example.txt', + contents: 'Alpha *braavo* charlie.', + custom: 'Custom tango', + data: { + custom: 12345 + } +}); + +// vfile recognize extended VFile values. So it will return same type. +const copiedFile: CustomVFile = vfile(file); +``` diff --git a/types/vfile/vfile-tests.ts b/types/vfile/vfile-tests.ts index 0b19246ae8..5c14c8502b 100644 --- a/types/vfile/vfile-tests.ts +++ b/types/vfile/vfile-tests.ts @@ -1,48 +1,39 @@ -import vfile = require("vfile"); +import vfile = require('vfile'); import * as Unist from 'unist'; // Instantiation -vfile(); +const file: vfile.VFile = vfile(); vfile('string'); vfile(Buffer.from('string')); vfile(vfile()); vfile({ stem: 'readme', extname: '.md' }); -vfile({ custom: 'data' }); -try { - vfile({ extname: '.md' }); -} catch (e) { - console.log('Error: set extname without path'); -} -const file = vfile<{custom: string, data: {custom: number}}>({ - path: '~/example.txt', - contents: 'Alpha *braavo* charlie.', - custom: 'Custom tango', - data: { - custom: 12345 - }, -}); - -file.path; // => '~/example.txt' -file.dirname; // => '~' +vfile({ path: 1234 }); // $ExpectError +file.path = '~/test.txt'; +file.dirname = '~'; file.extname = '.md'; +file.basename = 'test.text'; +file.history = ['~/test.txt']; // => ['~/example.txt', '~/example.md', '~/index.text'] +file.messages = [{ + file: '~/test.txt', + ruleId: '', + reason: '', + line: 1, + column: 1, + location: { + start: { + line: 1, + column: 1, + }, + end: { + line: 1, + column: 1, + } + }, + source: '' +}]; -file.basename; // => 'example.md' - -file.basename = 'index.text'; - -file.history; // => ['~/example.txt', '~/example.md', '~/index.text'] - -file.message('`braavo` is misspelt; did you mean `bravo`?', {line: 1, column: 8}); - -console.log(file.messages); - -// Typings of the custom data can be resolved from the parameters above -const custom: string = file.custom; // 'Custom tango' -const dataCustom: number = file.data.custom; // 12345 - -// message method accept any Stringifiable Position(e.g. point, position, node with position) const startPoint: Unist.Point = { line: 1, column: 1, @@ -54,18 +45,56 @@ const position: Unist.Position = { column: 2, }, }; -// Accept Point + file.message('test', startPoint); -// Accept Position file.message('test', position); -// Accept Node with extra value file.message('test', { type: 'ramdom node', position, extraValue: 'extra tango', }); -// But, it must reject any malformed position + file.message('test', { start: 'invalid point' }); // $ExpectError -// Typings of original properties must be kept -const fileWithWrongParams = vfile({ path: 1234 }); // $ExpectError +// Using `data` prop +interface CustomData { + message: string; +} +function isCustomData(data: any): data is CustomData { + return data != null && typeof data.message === 'string'; +} +function doSomethingWithCustomData(data: CustomData) { +} +const customData: CustomData = { + message: 'tango' +}; +const fileWithData = vfile({ + data: customData +}); + +if (isCustomData(fileWithData.data)) { + doSomethingWithCustomData(fileWithData.data); +} +doSomethingWithCustomData(fileWithData.data); // $ExpectError + +// Extending vfile +interface CustomVFile extends vfile.VFile { + custom: string; + data: { + custom: number; + }; +} + +const customVFile = vfile({ + path: '~/example.txt', + contents: 'Alpha *braavo* charlie.', + custom: 'Custom tango', + data: { + custom: 12345 + } +}); + +customVFile.custom = 'test'; +customVFile.data.custom = 1234; + +const copiedFile: CustomVFile = vfile(customVFile); diff --git a/types/webpack-chain/index.d.ts b/types/webpack-chain/index.d.ts index 033ef9951f..d821d13417 100644 --- a/types/webpack-chain/index.d.ts +++ b/types/webpack-chain/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for webpack-chain 4.8 +// Type definitions for webpack-chain 5.0 // Project: https://github.com/mozilla-neutrino/webpack-chain // Definitions by: Eirikur Nilsson , Paul Sachs // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -209,7 +209,7 @@ declare namespace Config { flagIncludedChunks(value: boolean): this; mergeDuplicateChunks(value: boolean): this; minimize(value: boolean): this; - minimizer(value: webpack.Plugin[]): this; + minimizer(name: string): Plugin; namedChunks(value: boolean): this; namedModules(value: boolean): this; nodeEnv(value: boolean | string): this; diff --git a/types/webpack-chain/webpack-chain-tests.ts b/types/webpack-chain/webpack-chain-tests.ts index f1d0daa5e2..b655df07ea 100644 --- a/types/webpack-chain/webpack-chain-tests.ts +++ b/types/webpack-chain/webpack-chain-tests.ts @@ -173,7 +173,9 @@ config .flagIncludedChunks(true) .mergeDuplicateChunks(true) .minimize(true) - .minimizer([]) + .minimizer('foo') + .use(webpack.DefinePlugin) + .end() .namedChunks(true) .namedModules(true) .nodeEnv(true) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index 357c63e330..f5beb1dc63 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -1394,7 +1394,6 @@ declare namespace webpack { constructor(); } - /** @deprecated use webpack.NoEmitOnErrorsPlugin */ class NormalModuleReplacementPlugin extends Plugin { constructor(resourceRegExp: any, newResource: any); } diff --git a/types/weixin-app/index.d.ts b/types/weixin-app/index.d.ts index 9a41debd2a..2e2eb35481 100644 --- a/types/weixin-app/index.d.ts +++ b/types/weixin-app/index.d.ts @@ -936,7 +936,7 @@ declare namespace wx { /** 本地缓存中的指定的 key */ key: string; /** 接口调用的回调函数,res = {data: key对应的内容} */ - success(res: DataResponse): void; + success(res: { data: Record | string | undefined }): void; } /** * 从本地缓存中异步获取指定 key 对应的内容。 @@ -3058,12 +3058,33 @@ declare namespace wx { * 登录态过期后开发者可以再调用wx.login获取新的用户登录态。 */ function checkSession(options: CheckSessionOption): void; + + // scope 列表 + type Scope = + | "scope.userInfo" + | "scope.userLocation" + | "scope.address" + | "scope.invoiceTitle" + | "scope.invoice" + | "scope.werun" + | "scope.record" + | "scope.writePhotosAlbum" + | "scope.camera"; + + // 开放接口-----设置 + interface AuthorizeOption { + scope: Scope; + success?(res: ErrMsgResponse): void; + fail?(): void; + complete?(): void; + } + /** * 提前向用户发起授权请求。 * 调用后会立刻弹窗询问用户是否同意授权小程序使用某项功能或获取用户的某些数据, * 但不会实际调用对应接口。如果用户之前已经同意授权,则不会出现弹窗,直接返回成功。 */ - function authorize(options: AuthSetting): void; + function authorize(options: AuthorizeOption): void; // 开放接口-----用户信息 interface UserInfo { nickName: string; @@ -3283,22 +3304,9 @@ declare namespace wx { * */ function openCard(options: OpenCardOptions): void; - // 开放接口-----设置 - interface AuthSetting { - scope: - | "scope.userInfo" - | "scope.userLocation" - | "scope.address" - | "scope.invoiceTitle" - | "scope.werun" - | "scope.record" - | "scope.writePhotosAlbum"; - success?(res: ErrMsgResponse): void; - fail?(): void; - complete?(): void; - } + interface OpenSettingOptions extends BaseOptions { - success?(res: { authSetting: AuthSetting }): void; + success?(res: { authSetting: { [key in Scope]: string} }): void; } /** * 调起客户端小程序设置界面,返回用户设置的操作结果。