From d6084b2ae2c7074897ff8869eeffafedf3e2cd7e Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Fri, 24 Oct 2025 13:11:03 +0200 Subject: [PATCH 1/4] rename sources to .ts --- src/alert/{alert.js => alert.ts} | 0 src/alert/{condition.js => condition.ts} | 0 src/alert/{index.js => index.ts} | 0 src/annotations/{graphite.js => graphite.ts} | 0 src/annotations/{index.js => index.ts} | 0 src/{config.js => config.ts} | 0 src/{dashboard.js => dashboard.ts} | 0 src/{errors.js => errors.ts} | 0 src/{external-link.js => external-link.ts} | 0 src/{id.js => id.ts} | 0 src/{index.js => index.ts} | 0 src/panels/{dashboard_list.js => dashboard_list.ts} | 0 src/panels/{graph.js => graph.ts} | 0 src/panels/{index.js => index.ts} | 0 src/panels/{singlestat.js => singlestat.ts} | 0 src/panels/{table.js => table.ts} | 0 src/panels/{text.js => text.ts} | 0 src/{publish.js => publish.ts} | 0 src/{row.js => row.ts} | 0 src/{target.js => target.ts} | 0 src/templates/{custom.js => custom.ts} | 0 src/templates/{index.js => index.ts} | 0 src/templates/{query.js => query.ts} | 0 23 files changed, 0 insertions(+), 0 deletions(-) rename src/alert/{alert.js => alert.ts} (100%) rename src/alert/{condition.js => condition.ts} (100%) rename src/alert/{index.js => index.ts} (100%) rename src/annotations/{graphite.js => graphite.ts} (100%) rename src/annotations/{index.js => index.ts} (100%) rename src/{config.js => config.ts} (100%) rename src/{dashboard.js => dashboard.ts} (100%) rename src/{errors.js => errors.ts} (100%) rename src/{external-link.js => external-link.ts} (100%) rename src/{id.js => id.ts} (100%) rename src/{index.js => index.ts} (100%) rename src/panels/{dashboard_list.js => dashboard_list.ts} (100%) rename src/panels/{graph.js => graph.ts} (100%) rename src/panels/{index.js => index.ts} (100%) rename src/panels/{singlestat.js => singlestat.ts} (100%) rename src/panels/{table.js => table.ts} (100%) rename src/panels/{text.js => text.ts} (100%) rename src/{publish.js => publish.ts} (100%) rename src/{row.js => row.ts} (100%) rename src/{target.js => target.ts} (100%) rename src/templates/{custom.js => custom.ts} (100%) rename src/templates/{index.js => index.ts} (100%) rename src/templates/{query.js => query.ts} (100%) diff --git a/src/alert/alert.js b/src/alert/alert.ts similarity index 100% rename from src/alert/alert.js rename to src/alert/alert.ts diff --git a/src/alert/condition.js b/src/alert/condition.ts similarity index 100% rename from src/alert/condition.js rename to src/alert/condition.ts diff --git a/src/alert/index.js b/src/alert/index.ts similarity index 100% rename from src/alert/index.js rename to src/alert/index.ts diff --git a/src/annotations/graphite.js b/src/annotations/graphite.ts similarity index 100% rename from src/annotations/graphite.js rename to src/annotations/graphite.ts diff --git a/src/annotations/index.js b/src/annotations/index.ts similarity index 100% rename from src/annotations/index.js rename to src/annotations/index.ts diff --git a/src/config.js b/src/config.ts similarity index 100% rename from src/config.js rename to src/config.ts diff --git a/src/dashboard.js b/src/dashboard.ts similarity index 100% rename from src/dashboard.js rename to src/dashboard.ts diff --git a/src/errors.js b/src/errors.ts similarity index 100% rename from src/errors.js rename to src/errors.ts diff --git a/src/external-link.js b/src/external-link.ts similarity index 100% rename from src/external-link.js rename to src/external-link.ts diff --git a/src/id.js b/src/id.ts similarity index 100% rename from src/id.js rename to src/id.ts diff --git a/src/index.js b/src/index.ts similarity index 100% rename from src/index.js rename to src/index.ts diff --git a/src/panels/dashboard_list.js b/src/panels/dashboard_list.ts similarity index 100% rename from src/panels/dashboard_list.js rename to src/panels/dashboard_list.ts diff --git a/src/panels/graph.js b/src/panels/graph.ts similarity index 100% rename from src/panels/graph.js rename to src/panels/graph.ts diff --git a/src/panels/index.js b/src/panels/index.ts similarity index 100% rename from src/panels/index.js rename to src/panels/index.ts diff --git a/src/panels/singlestat.js b/src/panels/singlestat.ts similarity index 100% rename from src/panels/singlestat.js rename to src/panels/singlestat.ts diff --git a/src/panels/table.js b/src/panels/table.ts similarity index 100% rename from src/panels/table.js rename to src/panels/table.ts diff --git a/src/panels/text.js b/src/panels/text.ts similarity index 100% rename from src/panels/text.js rename to src/panels/text.ts diff --git a/src/publish.js b/src/publish.ts similarity index 100% rename from src/publish.js rename to src/publish.ts diff --git a/src/row.js b/src/row.ts similarity index 100% rename from src/row.js rename to src/row.ts diff --git a/src/target.js b/src/target.ts similarity index 100% rename from src/target.js rename to src/target.ts diff --git a/src/templates/custom.js b/src/templates/custom.ts similarity index 100% rename from src/templates/custom.js rename to src/templates/custom.ts diff --git a/src/templates/index.js b/src/templates/index.ts similarity index 100% rename from src/templates/index.js rename to src/templates/index.ts diff --git a/src/templates/query.js b/src/templates/query.ts similarity index 100% rename from src/templates/query.js rename to src/templates/query.ts From be742404a8e4845957fa3a3a11162df9a734a1f6 Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Fri, 24 Oct 2025 13:35:41 +0200 Subject: [PATCH 2/4] disable strict typescript checks, while migration is in progress --- eslint.config.mjs | 1 + tsconfig.json | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 6fd39f0..9812433 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -26,6 +26,7 @@ export default defineConfig([ rules: { '@typescript-eslint/no-require-imports': 'off', '@typescript-eslint/no-this-alias': 'off', + '@typescript-eslint/no-explicit-any': 'off', }, }, ]); diff --git a/tsconfig.json b/tsconfig.json index b387160..add75eb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,7 @@ // Stricter Typechecking Options "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": true, + "exactOptionalPropertyTypes": false, // Style Options // "noImplicitReturns": true, @@ -31,7 +31,7 @@ // "noPropertyAccessFromIndexSignature": true, // Recommended Options - "strict": true, + "strict": false, "verbatimModuleSyntax": false, "isolatedModules": true, "noUncheckedSideEffectImports": true, From 1edafd77e49913738acd1d29ddc8cee6c0c4ae54 Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Fri, 24 Oct 2025 13:35:56 +0200 Subject: [PATCH 3/4] type fixes/improvements --- src/alert/alert.ts | 8 ++- src/alert/condition.ts | 7 +- src/alert/index.ts | 8 +-- src/annotations/graphite.ts | 11 ++-- src/annotations/index.ts | 6 +- src/config.ts | 7 +- src/dashboard.ts | 13 ++-- src/errors.ts | 11 +++- src/external-link.ts | 3 +- src/id.ts | 6 +- src/index.ts | 28 ++++---- src/panels/dashboard_list.ts | 9 ++- src/panels/graph.ts | 10 +-- src/panels/index.ts | 13 ++-- src/panels/singlestat.ts | 11 ++-- src/panels/table.ts | 11 ++-- src/panels/text.ts | 11 ++-- src/publish.ts | 11 ++-- src/row.ts | 10 +-- src/target.ts | 121 +++++++++++++++++++++++++++++++++-- src/templates/custom.ts | 10 +-- src/templates/index.ts | 8 +-- src/templates/query.ts | 9 +-- 23 files changed, 224 insertions(+), 118 deletions(-) diff --git a/src/alert/alert.ts b/src/alert/alert.ts index 5445d18..0c0356e 100644 --- a/src/alert/alert.ts +++ b/src/alert/alert.ts @@ -1,5 +1,9 @@ class Alert { - constructor(opts = {}) { + private conditions: any[]; + + private state: any; + + constructor(opts: any = {}) { this.conditions = []; this.state = { @@ -46,4 +50,4 @@ class Alert { } } -module.exports = Alert; +export = Alert; diff --git a/src/alert/condition.ts b/src/alert/condition.ts index da26755..f059149 100644 --- a/src/alert/condition.ts +++ b/src/alert/condition.ts @@ -1,4 +1,9 @@ class Condition { + private state: object; + private _evaluator: { params: any[]; type: string }; + private _operator: { type: string }; + private _query: { params: any[] }; + private _reducer: { params: any[]; type: string }; constructor(opts = {}) { this.state = {}; @@ -105,4 +110,4 @@ class Condition { } } -module.exports = Condition; +export = Condition; diff --git a/src/alert/index.ts b/src/alert/index.ts index e28ae0d..fe34d2a 100644 --- a/src/alert/index.ts +++ b/src/alert/index.ts @@ -1,9 +1,7 @@ -'use strict'; +import Alert = require('./alert'); +import Condition = require('./condition'); -var Alert = require('./alert'); -var Condition = require('./condition'); - -module.exports = { +export = { Alert: Alert, Condition: Condition, }; diff --git a/src/annotations/graphite.ts b/src/annotations/graphite.ts index a547a09..de541a2 100644 --- a/src/annotations/graphite.ts +++ b/src/annotations/graphite.ts @@ -18,12 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - -var errors = require('../errors'); +import errors = require('../errors'); class Graphite { - constructor(opts = {}) { + private state: any; + constructor(opts: any = {}) { if (!opts.name) { throw errors.UnfulfilledRequirement.create( '{component} missing requirement: {unfulfilledArg}', @@ -44,7 +43,7 @@ class Graphite { ); } - var defaults = { + const defaults = { name: 'no name', datasource: 'graphite', showLine: true, @@ -67,4 +66,4 @@ class Graphite { } } -module.exports = Graphite; +export = Graphite; diff --git a/src/annotations/index.ts b/src/annotations/index.ts index 2ab8184..ae5a35e 100644 --- a/src/annotations/index.ts +++ b/src/annotations/index.ts @@ -18,10 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; +import Graphite = require('./graphite'); -var Graphite = require('./graphite'); - -module.exports = { +export = { Graphite: Graphite, }; diff --git a/src/config.ts b/src/config.ts index 6f4f020..59a40cb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -18,8 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; -var xtend = require('xtend'); +import xtend = require('xtend'); /** * `user` - Auth user, defaults to "guest" @@ -28,7 +27,7 @@ var xtend = require('xtend'); * `cookie` - Key/value pair for auth, defaults to"auth-openid=" * `headers` - Map of header keys/values, defaults to no headers */ -var configurations = { +let configurations = { user: 'guest', group: 'guest', url: 'https://your.graphite.url.com/elasticsearch/grafana-dash/dashboard/', @@ -44,7 +43,7 @@ function getConfig() { return configurations; } -module.exports = { +export = { configure: configure, getConfig: getConfig, }; diff --git a/src/dashboard.ts b/src/dashboard.ts index 3ded0b5..677143e 100644 --- a/src/dashboard.ts +++ b/src/dashboard.ts @@ -18,13 +18,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - -var Templates = require('./templates'); -var Annotations = require('./annotations'); -var ExternalLink = require('./external-link'); +import Templates = require('./templates'); +import Annotations = require('./annotations'); +import ExternalLink = require('./external-link'); class Dashboard { + private state: any; + private rows: any[]; + private links: any[]; constructor(opts = {}) { this.state = {}; this._init(opts); @@ -123,4 +124,4 @@ class Dashboard { } } -module.exports = Dashboard; +export = Dashboard; diff --git a/src/errors.ts b/src/errors.ts index 93afa12..67e43c2 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -18,15 +18,20 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; -var SError = require('error').SError; +import error = require('error'); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +declare class _SError extends error.SError { + static create(message: string, info: Record): error.SError; +} +const SError = error.SError as typeof _SError; class UnfulfilledRequirement extends SError {} class InvalidState extends SError {} class Misconfigured extends SError {} class ResponseError extends SError {} -module.exports = { +export = { UnfulfilledRequirement: UnfulfilledRequirement, InvalidState: InvalidState, Misconfigured: Misconfigured, diff --git a/src/external-link.ts b/src/external-link.ts index 50361d0..23e1c51 100644 --- a/src/external-link.ts +++ b/src/external-link.ts @@ -19,6 +19,7 @@ // THE SOFTWARE. class ExternalLink { + private state: any; constructor(opts = {}) { const defaults = { title: '', @@ -61,4 +62,4 @@ class ExternalLink { } } -module.exports = ExternalLink; +export = ExternalLink; diff --git a/src/id.ts b/src/id.ts index ee53311..559eae8 100644 --- a/src/id.ts +++ b/src/id.ts @@ -18,15 +18,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - // Used to provide unique if for // generated graphs -var graphId = 0; +let graphId = 0; function generateGraphId() { graphId = graphId + 1; return graphId; } -module.exports = generateGraphId; +export = generateGraphId; diff --git a/src/index.ts b/src/index.ts index a601eff..f939ab7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,22 +18,20 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; +import Dashboard = require('./dashboard'); +import Row = require('./row'); +import ExternalLink = require('./external-link'); +import Target = require('./target'); +import Panels = require('./panels'); +import Alert = require('./alert/alert'); +import Condition = require('./alert/condition'); +import Templates = require('./templates'); +import publish = require('./publish'); +import generateGraphId = require('./id'); +import config = require('./config'); +import Annotations = require('./annotations'); -var Dashboard = require('./dashboard'); -var Row = require('./row'); -var ExternalLink = require('./external-link'); -var Target = require('./target'); -var Panels = require('./panels'); -var Alert = require('./alert/alert'); -var Condition = require('./alert/condition'); -var Templates = require('./templates'); -var publish = require('./publish'); -var generateGraphId = require('./id'); -var config = require('./config'); -var Annotations = require('./annotations'); - -module.exports = { +export = { Dashboard: Dashboard, Row: Row, ExternalLink: ExternalLink, diff --git a/src/panels/dashboard_list.ts b/src/panels/dashboard_list.ts index ea953bc..e4c1953 100644 --- a/src/panels/dashboard_list.ts +++ b/src/panels/dashboard_list.ts @@ -18,12 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - -var generateGraphId = require('../id'); +import generateGraphId = require('../id'); class DashboardList { - constructor(opts = {}) { + private state: any; + constructor(opts: any = {}) { this.state = { title: 'dashboard list', error: false, @@ -60,4 +59,4 @@ class DashboardList { } } -module.exports = DashboardList; +export = DashboardList; diff --git a/src/panels/graph.ts b/src/panels/graph.ts index 10c2b39..abd7211 100644 --- a/src/panels/graph.ts +++ b/src/panels/graph.ts @@ -18,12 +18,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - -const generateGraphId = require('../id'); +import generateGraphId = require('../id'); class Graph { - constructor(opts = {}) { + private _currentRefIndex: number; + private state: any; + constructor(opts: any = {}) { this._currentRefIndex = 0; const defaults = { @@ -150,4 +150,4 @@ function handleRefTargets(target, targets) { return {}; } -module.exports = Graph; +export = Graph; diff --git a/src/panels/index.ts b/src/panels/index.ts index bdde40b..d21d424 100644 --- a/src/panels/index.ts +++ b/src/panels/index.ts @@ -18,14 +18,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; -var Graph = require('./graph'); -var SingleStat = require('./singlestat'); -var Text = require('./text'); -var Table = require('./table'); -var DashboardList = require('./dashboard_list'); +import Graph = require('./graph'); +import SingleStat = require('./singlestat'); +import Text = require('./text'); +import Table = require('./table'); +import DashboardList = require('./dashboard_list'); -module.exports = { +export = { Graph: Graph, SingleStat: SingleStat, Text: Text, diff --git a/src/panels/singlestat.ts b/src/panels/singlestat.ts index 35a5737..f3972ce 100644 --- a/src/panels/singlestat.ts +++ b/src/panels/singlestat.ts @@ -18,13 +18,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - -var generateGraphId = require('../id'); +import generateGraphId = require('../id'); class SingleStat { - constructor(opts = {}) { - var defaults = { + private state: any; + constructor(opts: any = {}) { + const defaults = { id: generateGraphId(), title: 'single stat', targets: [], @@ -104,4 +103,4 @@ class SingleStat { } } -module.exports = SingleStat; +export = SingleStat; diff --git a/src/panels/table.ts b/src/panels/table.ts index 48de96d..bd60ad8 100644 --- a/src/panels/table.ts +++ b/src/panels/table.ts @@ -18,13 +18,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - -var generateGraphId = require('../id'); +import generateGraphId = require('../id'); class Table { - constructor(opts = {}) { - var defaults = { + private state: any; + constructor(opts: any = {}) { + const defaults = { title: 'Panel Title', error: false, span: 12, @@ -107,4 +106,4 @@ class Table { } } -module.exports = Table; +export = Table; diff --git a/src/panels/text.ts b/src/panels/text.ts index 233f9a6..440927a 100644 --- a/src/panels/text.ts +++ b/src/panels/text.ts @@ -18,13 +18,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - -var generateGraphId = require('../id'); +import generateGraphId = require('../id'); class Text { - constructor(opts = {}) { - var defaults = { + private state: any; + constructor(opts: any = {}) { + const defaults = { title: '', id: generateGraphId(), error: false, @@ -59,4 +58,4 @@ class Text { } } -module.exports = Text; +export = Text; diff --git a/src/publish.ts b/src/publish.ts index f3fb5ad..3cd3f99 100644 --- a/src/publish.ts +++ b/src/publish.ts @@ -18,12 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; -const fetch = require('node-fetch'); -const config = require('./config'); -const errors = require('./errors'); +import fetch = require('node-fetch'); +import config = require('./config'); +import errors = require('./errors'); -function publish(dashboard, opts = {}) { +function publish(dashboard, opts: any = {}) { if (!dashboard) { throw errors.UnfulfilledRequirement.create( '{component} missing requirement: {unfulfilledArg}', @@ -117,4 +116,4 @@ function publish(dashboard, opts = {}) { }); } -module.exports = publish; +export = publish; diff --git a/src/row.ts b/src/row.ts index 3052c42..27517e6 100644 --- a/src/row.ts +++ b/src/row.ts @@ -18,14 +18,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - -var xtend = require('xtend'); +import xtend = require('xtend'); class Row { + private state: any; + private panels: any[]; constructor(opts) { opts = opts || {}; - var state = { + const state = { title: 'New row', height: '250px', editable: true, @@ -54,4 +54,4 @@ class Row { } } -module.exports = Row; +export = Row; diff --git a/src/target.ts b/src/target.ts index 7a54954..f6be828 100644 --- a/src/target.ts +++ b/src/target.ts @@ -18,12 +18,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; +/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging,prefer-rest-params */ -var _ = require('underscore'); -var util = require('util'); +import _ = require('underscore'); +import util = require('util'); class Target { + private source: any; + private func: any; + + constructor(template: string, ...substitutions: any[]); + constructor(source: Target, func: (string | number | boolean)[]); + constructor() { if (arguments.length === 0) { throw new Error( @@ -41,6 +47,9 @@ class Target { } } + static PRIMITIVES: typeof PRIMITIVES; + static COLORS: typeof COLORS; + toString() { if (this.func) { const args = _.reduce( @@ -83,6 +92,12 @@ class Target { return this.summarize('15min'); } + // @ts-expect-error disabling typechecks for this call + declare hide: any; + /** + * @deprecated this is weird - function replaces itself to be "true" when called, do expect surprises when calling + */ + // @ts-expect-error disabling typechecks for this call hide() { this.hide = true; return this; @@ -186,13 +201,105 @@ const PRIMITIVES = { }; Target.PRIMITIVES = PRIMITIVES; +interface Target { + absolute(...args: any[]): Target; + aggregateLine(...args: any[]): Target; + alias(arg1: any, ...args: any[]): Target; + aliasByMetric(...args: any[]): Target; + aliasByNode(arg1: any, ...args: any[]): Target; + aliasSub(arg1: any, arg2: any, ...args: any[]): Target; + alpha(arg1: any, ...args: any[]): Target; + areaBetween(...args: any[]): Target; + asPercent(...args: any[]): Target; + averageAbove(arg1: any, ...args: any[]): Target; + averageBelow(arg1: any, ...args: any[]): Target; + averageOutsidePercentile(arg1: any, ...args: any[]): Target; + averageSeries(...args: any[]): Target; + averageSeriesWithWildcards(arg1: any, ...args: any[]): Target; + cactiStyle(...args: any[]): Target; + color(arg1: any, ...args: any[]): Target; + consolidateBy(arg1: any, ...args: any[]): Target; + countSeries(...args: any[]): Target; + cumulative(...args: any[]): Target; + currentAbove(arg1: any, ...args: any[]): Target; + currentBelow(arg1: any, ...args: any[]): Target; + dashed(...args: any[]): Target; + derivative(...args: any[]): Target; + diffSeries(arg1: any, ...args: any[]): Target; + divideSeries(arg1: any, ...args: any[]): Target; + drawAsInfinite(...args: any[]): Target; + exclude(arg1: any, ...args: any[]): Target; + grep(arg1: any, ...args: any[]): Target; + group(...args: any[]): Target; + groupByNode(arg1: any, arg2: any, ...args: any[]): Target; + highestAverage(arg1: any, ...args: any[]): Target; + highestCurrent(arg1: any, ...args: any[]): Target; + highestMax(arg1: any, ...args: any[]): Target; + hitcount(arg1: any, ...args: any[]): Target; + holtWintersAbberation(...args: any[]): Target; + holtWintersConfidenceArea(...args: any[]): Target; + holtWintersConfidenceBands(...args: any[]): Target; + holtWintersForecast(...args: any[]): Target; + integral(...args: any[]): Target; + invert(...args: any[]): Target; + isNonNull(...args: any[]): Target; + keepLastValue(...args: any[]): Target; + legendValue(arg1: any, ...args: any[]): Target; + limit(arg1: any, ...args: any[]): Target; + lineWidth(arg1: any, ...args: any[]): Target; + logarithm(...args: any[]): Target; + lowestAverage(arg1: any, ...args: any[]): Target; + lowestCurrent(arg1: any, ...args: any[]): Target; + mapSeries(arg1: any, ...args: any[]): Target; + maxSeries(...args: any[]): Target; + maximumAbove(arg1: any, ...args: any[]): Target; + maximumBelow(arg1: any, ...args: any[]): Target; + minSeries(...args: any[]): Target; + minimumAbove(arg1: any, ...args: any[]): Target; + mostDeviant(arg1: any, ...args: any[]): Target; + movingAverage(arg1: any, ...args: any[]): Target; + movingMedian(arg1: any, ...args: any[]): Target; + multiplySeries(...args: any[]): Target; + nPercentile(arg1: any, ...args: any[]): Target; + nonNegativeDerivative(...args: any[]): Target; + offset(arg1: any, ...args: any[]): Target; + offsetToZero(...args: any[]): Target; + perSecond(...args: any[]): Target; + percentileOfSeries(arg1: any, ...args: any[]): Target; + rangeOfSeries(...args: any[]): Target; + reduceSeries(arg1: any, arg2: any, arg3: any, ...args: any[]): Target; + removeAbovePercentile(arg1: any, ...args: any[]): Target; + removeAboveValue(arg1: any, ...args: any[]): Target; + removeBelowPercentile(arg1: any, ...args: any[]): Target; + removeBelowValue(arg1: any, ...args: any[]): Target; + removeBetweenPercentile(arg1: any, ...args: any[]): Target; + scale(arg1: any, ...args: any[]): Target; + scaleToSeconds(arg1: any, ...args: any[]): Target; + secondYAxis(...args: any[]): Target; + smartSummarize(arg1: any, ...args: any[]): Target; + sortByMaxima(...args: any[]): Target; + sortByMinima(...args: any[]): Target; + sortByName(...args: any[]): Target; + sortByTotal(...args: any[]): Target; + stacked(...args: any[]): Target; + stddevSeries(...args: any[]): Target; + stdev(arg1: any, ...args: any[]): Target; + sum(...args: any[]): Target; + sumSeries(...args: any[]): Target; + sumSeriesWithWildcards(arg1: any, ...args: any[]): Target; + summarize(arg1: any, ...args: any[]): Target; + timeShift(arg1: any, ...args: any[]): Target; + timeStack(arg1: any, arg2: any, arg3: any, ...args: any[]): Target; + transformNull(...args: any[]): Target; + useSeriesAbove(arg1: any, arg2: any, arg3: any, ...args: any[]): Target; + weightedAverage(arg1: any, arg2: any, ...args: any[]): Target; +} + _.each(Target.PRIMITIVES, function each(n, method) { Target.prototype[method] = function t() { if (arguments.length < n) { - /*eslint-disable*/ - console.warn("Incorrect number of arguments passed to %s", method); + console.warn('Incorrect number of arguments passed to %s', method); console.trace(); - /*eslint-enable*/ } return new Target( this, @@ -222,4 +329,4 @@ _.each(Target.COLORS, function each(color) { }; }); -module.exports = Target; +export = Target; diff --git a/src/templates/custom.ts b/src/templates/custom.ts index 15e934c..1be4b2c 100644 --- a/src/templates/custom.ts +++ b/src/templates/custom.ts @@ -18,11 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - const DEFAULT_VARIABLE_ALL = '$__all'; class Custom { + private state: any; + private defaultValue: string; constructor(opts = {}) { this.state = { allFormat: 'glob', @@ -66,8 +66,8 @@ class Custom { return; } - let newOptions = []; - let newQuery = []; + const newOptions = []; + const newQuery = []; let hasAll = false; for (let i = 0; i < this.state.options.length; i++) { @@ -118,4 +118,4 @@ class Custom { } } -module.exports = Custom; +export = Custom; diff --git a/src/templates/index.ts b/src/templates/index.ts index ae704e5..ab890b3 100644 --- a/src/templates/index.ts +++ b/src/templates/index.ts @@ -18,12 +18,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; +import Custom = require('./custom'); +import Query = require('./query'); -var Custom = require('./custom'); -var Query = require('./query'); - -module.exports = { +export = { Custom: Custom, Query: Query, }; diff --git a/src/templates/query.ts b/src/templates/query.ts index 406f9c2..ef614c5 100644 --- a/src/templates/query.ts +++ b/src/templates/query.ts @@ -18,8 +18,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -'use strict'; - /** * Provide a query to populate template variable. * @@ -40,7 +38,10 @@ * @see http://docs.grafana.org/reference/templating/ */ class Query { - constructor(query, opts = {}) { + private state: any; + private _required: string[]; + private _overridable: string[]; + constructor(query: any, opts: any = {}) { this.state = { query: query, name: opts.name, @@ -91,4 +92,4 @@ class Query { } } -module.exports = Query; +export = Query; From 2d0aec61fdb3522d74d1b3b8d71cb7288eaf839b Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Fri, 24 Oct 2025 15:29:19 +0200 Subject: [PATCH 4/4] enable typechecks for js files --- src/dashboard.ts | 6 +++--- src/panels/dashboard_list.ts | 2 +- src/panels/graph.ts | 2 +- src/panels/singlestat.ts | 2 +- src/panels/table.ts | 2 +- src/panels/text.ts | 2 +- src/row.ts | 4 ++-- src/target.ts | 2 +- src/templates/custom.ts | 2 +- src/templates/query.ts | 2 +- test/target.test.js | 1 + tsconfig.json | 2 +- 12 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/dashboard.ts b/src/dashboard.ts index 677143e..e6b7ad9 100644 --- a/src/dashboard.ts +++ b/src/dashboard.ts @@ -23,9 +23,9 @@ import Annotations = require('./annotations'); import ExternalLink = require('./external-link'); class Dashboard { - private state: any; - private rows: any[]; - private links: any[]; + state: any; + rows: any[]; + links: any[]; constructor(opts = {}) { this.state = {}; this._init(opts); diff --git a/src/panels/dashboard_list.ts b/src/panels/dashboard_list.ts index e4c1953..4ca1772 100644 --- a/src/panels/dashboard_list.ts +++ b/src/panels/dashboard_list.ts @@ -21,7 +21,7 @@ import generateGraphId = require('../id'); class DashboardList { - private state: any; + state: any; constructor(opts: any = {}) { this.state = { title: 'dashboard list', diff --git a/src/panels/graph.ts b/src/panels/graph.ts index abd7211..87978ab 100644 --- a/src/panels/graph.ts +++ b/src/panels/graph.ts @@ -22,7 +22,7 @@ import generateGraphId = require('../id'); class Graph { private _currentRefIndex: number; - private state: any; + state: any; constructor(opts: any = {}) { this._currentRefIndex = 0; diff --git a/src/panels/singlestat.ts b/src/panels/singlestat.ts index f3972ce..e836f88 100644 --- a/src/panels/singlestat.ts +++ b/src/panels/singlestat.ts @@ -21,7 +21,7 @@ import generateGraphId = require('../id'); class SingleStat { - private state: any; + state: any; constructor(opts: any = {}) { const defaults = { id: generateGraphId(), diff --git a/src/panels/table.ts b/src/panels/table.ts index bd60ad8..ee5e3e9 100644 --- a/src/panels/table.ts +++ b/src/panels/table.ts @@ -21,7 +21,7 @@ import generateGraphId = require('../id'); class Table { - private state: any; + state: any; constructor(opts: any = {}) { const defaults = { title: 'Panel Title', diff --git a/src/panels/text.ts b/src/panels/text.ts index 440927a..63ce143 100644 --- a/src/panels/text.ts +++ b/src/panels/text.ts @@ -21,7 +21,7 @@ import generateGraphId = require('../id'); class Text { - private state: any; + state: any; constructor(opts: any = {}) { const defaults = { title: '', diff --git a/src/row.ts b/src/row.ts index 27517e6..2ba9045 100644 --- a/src/row.ts +++ b/src/row.ts @@ -21,8 +21,8 @@ import xtend = require('xtend'); class Row { - private state: any; - private panels: any[]; + state: any; + panels: any[]; constructor(opts) { opts = opts || {}; const state = { diff --git a/src/target.ts b/src/target.ts index f6be828..279955b 100644 --- a/src/target.ts +++ b/src/target.ts @@ -24,7 +24,7 @@ import _ = require('underscore'); import util = require('util'); class Target { - private source: any; + source: any; private func: any; constructor(template: string, ...substitutions: any[]); diff --git a/src/templates/custom.ts b/src/templates/custom.ts index 1be4b2c..74c547f 100644 --- a/src/templates/custom.ts +++ b/src/templates/custom.ts @@ -21,7 +21,7 @@ const DEFAULT_VARIABLE_ALL = '$__all'; class Custom { - private state: any; + state: any; private defaultValue: string; constructor(opts = {}) { this.state = { diff --git a/src/templates/query.ts b/src/templates/query.ts index ef614c5..e0c54dd 100644 --- a/src/templates/query.ts +++ b/src/templates/query.ts @@ -38,7 +38,7 @@ * @see http://docs.grafana.org/reference/templating/ */ class Query { - private state: any; + state: any; private _required: string[]; private _overridable: string[]; constructor(query: any, opts: any = {}) { diff --git a/test/target.test.js b/test/target.test.js index 9745243..408665e 100644 --- a/test/target.test.js +++ b/test/target.test.js @@ -25,6 +25,7 @@ var Target = require('../src/target'); test('Target throws exception on invalid invocation', function () { expect(function shouldThrow() { + // @ts-expect-error intentionally invalid call new Target(); }).toThrow( 'Incorrect invocation of Target. Must provide at least one argument' diff --git a/tsconfig.json b/tsconfig.json index add75eb..73d1874 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ // Visit https://aka.ms/tsconfig to read more about this file "compilerOptions": { "allowJs": true, - "checkJs": false, + "checkJs": true, // File Layout "rootDir": "./", "noEmit": true,