mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-14 16:35:01 -05:00
improvement(code-quality): centralize regex checks, normalization (#2554)
* improvement(code-quality): centralize regex checks, normalization * simplify resolution * fix(copilot): don't allow duplicate name blocks * centralize uuid check
This commit is contained in:
committed by
GitHub
parent
b23299dae4
commit
bf8fbebe22
@@ -1,8 +1,8 @@
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { BlockType, REFERENCE } from '@/executor/constants'
|
||||
import { BlockType } from '@/executor/constants'
|
||||
import type { ExecutionState, LoopScope } from '@/executor/execution/state'
|
||||
import type { ExecutionContext } from '@/executor/types'
|
||||
import { replaceValidReferences } from '@/executor/utils/reference-validation'
|
||||
import { createEnvVarPattern, replaceValidReferences } from '@/executor/utils/reference-validation'
|
||||
import { BlockResolver } from '@/executor/variables/resolvers/block'
|
||||
import { EnvResolver } from '@/executor/variables/resolvers/env'
|
||||
import { LoopResolver } from '@/executor/variables/resolvers/loop'
|
||||
@@ -185,8 +185,7 @@ export class VariableResolver {
|
||||
throw replacementError
|
||||
}
|
||||
|
||||
const envRegex = new RegExp(`${REFERENCE.ENV_VAR_START}([^}]+)${REFERENCE.ENV_VAR_END}`, 'g')
|
||||
result = result.replace(envRegex, (match) => {
|
||||
result = result.replace(createEnvVarPattern(), (match) => {
|
||||
const resolved = this.resolveReference(match, resolutionContext)
|
||||
return typeof resolved === 'string' ? resolved : match
|
||||
})
|
||||
@@ -236,8 +235,7 @@ export class VariableResolver {
|
||||
throw replacementError
|
||||
}
|
||||
|
||||
const envRegex = new RegExp(`${REFERENCE.ENV_VAR_START}([^}]+)${REFERENCE.ENV_VAR_END}`, 'g')
|
||||
result = result.replace(envRegex, (match) => {
|
||||
result = result.replace(createEnvVarPattern(), (match) => {
|
||||
const resolved = this.resolveReference(match, resolutionContext)
|
||||
return typeof resolved === 'string' ? resolved : match
|
||||
})
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
import { isReference, parseReferencePath, SPECIAL_REFERENCE_PREFIXES } from '@/executor/constants'
|
||||
import {
|
||||
isReference,
|
||||
normalizeName,
|
||||
parseReferencePath,
|
||||
SPECIAL_REFERENCE_PREFIXES,
|
||||
} from '@/executor/constants'
|
||||
import {
|
||||
navigatePath,
|
||||
type ResolutionContext,
|
||||
type Resolver,
|
||||
} from '@/executor/variables/resolvers/reference'
|
||||
import type { SerializedWorkflow } from '@/serializer/types'
|
||||
import { normalizeName } from '@/stores/workflows/utils'
|
||||
|
||||
export class BlockResolver implements Resolver {
|
||||
private blockByNormalizedName: Map<string, string>
|
||||
private nameToBlockId: Map<string, string>
|
||||
|
||||
constructor(private workflow: SerializedWorkflow) {
|
||||
this.blockByNormalizedName = new Map()
|
||||
this.nameToBlockId = new Map()
|
||||
for (const block of workflow.blocks) {
|
||||
this.blockByNormalizedName.set(block.id, block.id)
|
||||
if (block.metadata?.name) {
|
||||
const normalized = normalizeName(block.metadata.name)
|
||||
this.blockByNormalizedName.set(normalized, block.id)
|
||||
this.nameToBlockId.set(normalizeName(block.metadata.name), block.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,11 +82,7 @@ export class BlockResolver implements Resolver {
|
||||
}
|
||||
|
||||
private findBlockIdByName(name: string): string | undefined {
|
||||
if (this.blockByNormalizedName.has(name)) {
|
||||
return this.blockByNormalizedName.get(name)
|
||||
}
|
||||
const normalized = normalizeName(name)
|
||||
return this.blockByNormalizedName.get(normalized)
|
||||
return this.nameToBlockId.get(normalizeName(name))
|
||||
}
|
||||
|
||||
public formatValueForBlock(
|
||||
|
||||
@@ -117,7 +117,7 @@ export class ParallelResolver implements Resolver {
|
||||
// String handling
|
||||
if (typeof rawItems === 'string') {
|
||||
// Skip references - they should be resolved by the variable resolver
|
||||
if (rawItems.startsWith('<')) {
|
||||
if (rawItems.startsWith(REFERENCE.START)) {
|
||||
return []
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { VariableManager } from '@/lib/workflows/variables/variable-manager'
|
||||
import { isReference, parseReferencePath, REFERENCE } from '@/executor/constants'
|
||||
import { isReference, normalizeName, parseReferencePath, REFERENCE } from '@/executor/constants'
|
||||
import {
|
||||
navigatePath,
|
||||
type ResolutionContext,
|
||||
type Resolver,
|
||||
} from '@/executor/variables/resolvers/reference'
|
||||
import { normalizeName } from '@/stores/workflows/utils'
|
||||
|
||||
const logger = createLogger('WorkflowResolver')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user