From a46e790187ecb52741344441397bbae3065f03ef Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Thu, 11 Mar 2021 09:45:22 -0800 Subject: [PATCH] Use centralized MediaWiki typescript definition Use @wikimedia/types-wikimedia rather than maintaining our own. Bug: T263914 Change-Id: I5319f422b85a772c248f2114a75f906a1aff6251 --- package-lock.json | 6 +++ package.json | 1 + resources/mediawiki.d.ts | 108 --------------------------------------- resources/mw.d.ts | 1 + 4 files changed, 8 insertions(+), 108 deletions(-) delete mode 100644 resources/mediawiki.d.ts create mode 100644 resources/mw.d.ts diff --git a/package-lock.json b/package-lock.json index dd22a84..b4d2b02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2105,6 +2105,12 @@ "@xtuc/long": "4.2.2" } }, + "@wikimedia/types-wikimedia": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@wikimedia/types-wikimedia/-/types-wikimedia-0.2.0.tgz", + "integrity": "sha512-H2MbvBt7DTROqm6kCRNdK6nUZuBvSYjq/7k01ZI5/uR9mj8FzxsMQcH4joh8kFVQ2LpDPXNsaPq/P5hqIDtSAw==", + "dev": true + }, "@xtuc/ieee754": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz", diff --git a/package.json b/package.json index aeb41c8..7323cfe 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@types/jquery": "3.3.33", "@types/mustache": "4.0.1", "@types/node-fetch": "2.5.7", + "@wikimedia/types-wikimedia": "0.2.0", "babel-loader": "8.0.6", "bundlesize": "0.18.1", "eslint-config-wikimedia": "0.20.0", diff --git a/resources/mediawiki.d.ts b/resources/mediawiki.d.ts deleted file mode 100644 index ec22494..0000000 --- a/resources/mediawiki.d.ts +++ /dev/null @@ -1,108 +0,0 @@ -interface MwApi { - saveOption( name: string, value: unknown ): JQuery.Promise; -} - -type MwApiConstructor = new( options?: Object ) => MwApi; - -interface MwUri { - query: Record; - toString(): string; -} - -interface MwEventLog { - eventInSample( population: Object ): () => boolean; - inSample( num: Number ): () => boolean; - logEvent( schema: string, data: Object ): () => void; -} - -type UriConstructor = new( uri: string ) => MwUri; - -interface MediaWiki { - eventLog?: MwEventLog, - util: { - /** - * @param {string} id of portlet - */ - showPortlet( id: string ): () => void; - /** - * @param {string} id of portlet - */ - hidePortlet( id: string ): () => void; - /** - * @param {string} id of portlet - * @return {bool} - */ - isPortletVisible( id: string ): () => boolean, - /** - * Return a wrapper function that is debounced for the given duration. - * - * When it is first called, a timeout is scheduled. If before the timer - * is reached the wrapper is called again, it gets rescheduled for the - * same duration from now until it stops being called. The original function - * is called from the "tail" of such chain, with the last set of arguments. - * - * @since 1.34 - * @param {number} delay Time in milliseconds - * @param {Function} callback - * @return {Function} - */ - debounce(delay: number, callback: Function): () => void; - }; - Api: MwApiConstructor; - config: { - get( configKey: string|null, fallback?: any|null ): string; - set( configKey: string|null, value: any|null ): void; - }, - loader: { - /** - * Execute a function after one or more modules are ready. - * - * @param moduleName - * @param {Function} ready Callback to execute when all dependencies are - * ready. - * @param {Function} after Callback to execute if one or more dependencies - * failed. - */ - using( moduleName: string|null, ready?: Function, error?: Function ): JQuery.Promise; - - /** - * Load a given resourceLoader module. - * - * @param moduleName - */ - load( moduleName: string|null ): () => void; - /** - * Get the loading state of the module. - * On of 'registered', 'loaded', 'loading', 'ready', 'error', or 'missing'. - * - * @param moduleName - */ - getState( moduleName: string|null ): string; - }, - /** - * Loads the specified i18n message string. - * Shortcut for `mw.message( key, parameters... ).text()`. - * - * @param messageName i18n message name - */ - msg( messageName: string|null ): string; - - /** - * Get current timestamp - */ - now(): number, - - /** - * Track an analytic event. - * - * See https://gerrit.wikimedia.org/g/mediawiki/core/+/d7fe1ff0fe52735b1f41e91879c9617b376e807d/resources/src/mediawiki.base/mediawiki.base.js#375. - * - * @param topic The topic name - * @param [data] The data describing the event - */ - track(topic: string, data?: Record|number|string): void; - - Uri: UriConstructor; -} - -declare const mw: MediaWiki; diff --git a/resources/mw.d.ts b/resources/mw.d.ts new file mode 100644 index 0000000..6da5b29 --- /dev/null +++ b/resources/mw.d.ts @@ -0,0 +1 @@ +import '@wikimedia/types-wikimedia';