Skip to content

Commit ff49062

Browse files
committed
remove "as any" usage
1 parent 2a0d281 commit ff49062

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/composables/node/useNodePricing.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { INodeInputSlot } from '@/lib/litegraph/src/interfaces'
1717
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
1818
import type { PriceBadge, WidgetDependency } from '@/schemas/nodeDefSchema'
1919
import { useNodeDefStore } from '@/stores/nodeDefStore'
20+
import type { Expression } from 'jsonata'
2021
import jsonata from 'jsonata'
2122

2223
const DEFAULT_NUMBER_OPTIONS: Intl.NumberFormatOptions = {
@@ -103,7 +104,7 @@ type JsonataPricingRule = {
103104
}
104105

105106
type CompiledJsonataPricingRule = JsonataPricingRule & {
106-
_compiled: { evaluate: (input: unknown) => unknown } | null
107+
_compiled: Expression | null
107108
}
108109

109110
type JsonataEvalContext = {
@@ -241,38 +242,38 @@ const formatPricingResult = (
241242
): string => {
242243
if (!result || typeof result !== 'object') return ''
243244

244-
const r = result as Partial<PricingResult>
245+
const r = result as PricingResult
245246

246247
if (r.type === 'text') {
247-
return (r as any).text ?? ''
248+
return r.text ?? ''
248249
}
249250

250251
if (r.type === 'usd') {
251-
const usd = asFiniteNumber((r as any).usd)
252+
const usd = asFiniteNumber(r.usd)
252253
if (usd === null) return ''
253-
const fmt = { ...defaults, ...((r as any).format ?? {}) }
254+
const fmt = { ...defaults, ...(r.format ?? {}) }
254255
return formatCreditsLabel(usd, fmt)
255256
}
256257

257258
if (r.type === 'range_usd') {
258-
const minUsd = asFiniteNumber((r as any).min_usd)
259-
const maxUsd = asFiniteNumber((r as any).max_usd)
259+
const minUsd = asFiniteNumber(r.min_usd)
260+
const maxUsd = asFiniteNumber(r.max_usd)
260261
if (minUsd === null || maxUsd === null) return ''
261-
const fmt = { ...defaults, ...((r as any).format ?? {}) }
262+
const fmt = { ...defaults, ...(r.format ?? {}) }
262263
return formatCreditsRangeLabel(minUsd, maxUsd, fmt)
263264
}
264265

265266
if (r.type === 'list_usd') {
266-
const arr = Array.isArray((r as any).usd) ? (r as any).usd : null
267+
const arr = Array.isArray(r.usd) ? r.usd : null
267268
if (!arr) return ''
268269

269270
const usdValues = arr
270271
.map(asFiniteNumber)
271-
.filter((x: any) => x != null) as number[]
272+
.filter((x): x is number => x != null)
272273

273274
if (usdValues.length === 0) return ''
274275

275-
const fmt = { ...defaults, ...((r as any).format ?? {}) }
276+
const fmt = { ...defaults, ...(r.format ?? {}) }
276277
return formatCreditsListLabel(usdValues, fmt)
277278
}
278279

@@ -284,7 +285,7 @@ const formatPricingResult = (
284285
// -----------------------------
285286
const compileRule = (rule: JsonataPricingRule): CompiledJsonataPricingRule => {
286287
try {
287-
return { ...rule, _compiled: jsonata(rule.expr) as any }
288+
return { ...rule, _compiled: jsonata(rule.expr) }
288289
} catch (e) {
289290
// Do not crash app on bad expressions; just disable rule.
290291
console.error('[pricing/jsonata] failed to compile expr:', rule.expr, e)
@@ -365,7 +366,7 @@ const scheduleEvaluation = (
365366

366367
const nodeName = (node.constructor as any)?.nodeData?.name ?? ''
367368

368-
const promise = Promise.resolve(rule._compiled.evaluate(ctx as any))
369+
const promise = Promise.resolve(rule._compiled.evaluate(ctx))
369370
.then((res) => {
370371
const label = formatPricingResult(res, rule.result_defaults ?? {})
371372

@@ -485,7 +486,7 @@ export const useNodePricing = () => {
485486
const nodeDef = nodeDefStore.nodeDefsByName[nodeType]
486487
if (!nodeDef) return []
487488

488-
const priceBadge = (nodeDef as any).price_badge as PriceBadge | undefined
489+
const priceBadge = nodeDef.price_badge
489490
if (!priceBadge) return []
490491

491492
const dependsOn = priceBadge.depends_on ?? { widgets: [], inputs: [] }

src/stores/nodeDefStore.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import type {
1414
import type {
1515
ComfyInputsSpec as ComfyInputSpecV1,
1616
ComfyNodeDef as ComfyNodeDefV1,
17-
ComfyOutputTypesSpec as ComfyOutputSpecV1
17+
ComfyOutputTypesSpec as ComfyOutputSpecV1,
18+
PriceBadge
1819
} from '@/schemas/nodeDefSchema'
1920
import { NodeSearchService } from '@/services/nodeSearchService'
2021
import { useSubgraphStore } from '@/stores/subgraphStore'
@@ -66,6 +67,12 @@ export class ComfyNodeDefImpl
6667
* Order of inputs for each category (required, optional, hidden)
6768
*/
6869
readonly input_order?: Record<string, string[]>
70+
/**
71+
* Price badge definition for API nodes.
72+
* Contains a JSONata expression to calculate pricing based on widget values
73+
* and input connectivity.
74+
*/
75+
readonly price_badge?: PriceBadge
6976

7077
// V2 fields
7178
readonly inputs: Record<string, InputSpecV2>
@@ -134,6 +141,7 @@ export class ComfyNodeDefImpl
134141
this.output_name = obj.output_name
135142
this.output_tooltips = obj.output_tooltips
136143
this.input_order = obj.input_order
144+
this.price_badge = obj.price_badge
137145

138146
// Initialize V2 fields
139147
const defV2 = transformNodeDefV1ToV2(obj)

0 commit comments

Comments
 (0)