chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,431 @@
|
||||
/**
|
||||
* @vitest-environment node
|
||||
*/
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { BlockState } from '@/stores/workflows/workflow/types'
|
||||
|
||||
vi.unmock('@/blocks/registry')
|
||||
|
||||
import { backfillCanonicalModes, migrateSubblockIds } from './subblock-migrations'
|
||||
|
||||
function makeBlock(overrides: Partial<BlockState> & { type: string }): BlockState {
|
||||
return {
|
||||
id: 'block-1',
|
||||
name: 'Test',
|
||||
position: { x: 0, y: 0 },
|
||||
subBlocks: {},
|
||||
outputs: {},
|
||||
enabled: true,
|
||||
...overrides,
|
||||
} as BlockState
|
||||
}
|
||||
|
||||
describe('migrateSubblockIds', () => {
|
||||
describe('knowledge block', () => {
|
||||
it('should rename knowledgeBaseId to knowledgeBaseSelector', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
subBlocks: {
|
||||
operation: { id: 'operation', type: 'dropdown', value: 'search' },
|
||||
knowledgeBaseId: {
|
||||
id: 'knowledgeBaseId',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-uuid-123',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = migrateSubblockIds(input)
|
||||
|
||||
expect(migrated).toBe(true)
|
||||
expect(blocks.b1.subBlocks.knowledgeBaseSelector).toEqual({
|
||||
id: 'knowledgeBaseSelector',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-uuid-123',
|
||||
})
|
||||
expect(blocks.b1.subBlocks.knowledgeBaseId).toBeUndefined()
|
||||
expect(blocks.b1.subBlocks.operation.value).toBe('search')
|
||||
})
|
||||
|
||||
it('should prefer new key when both old and new exist', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
subBlocks: {
|
||||
knowledgeBaseId: {
|
||||
id: 'knowledgeBaseId',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'stale-kb',
|
||||
},
|
||||
knowledgeBaseSelector: {
|
||||
id: 'knowledgeBaseSelector',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'fresh-kb',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = migrateSubblockIds(input)
|
||||
|
||||
expect(migrated).toBe(true)
|
||||
expect(blocks.b1.subBlocks.knowledgeBaseSelector.value).toBe('fresh-kb')
|
||||
expect(blocks.b1.subBlocks.knowledgeBaseId).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should not touch blocks that already use the new key', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
subBlocks: {
|
||||
knowledgeBaseSelector: {
|
||||
id: 'knowledgeBaseSelector',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-uuid',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = migrateSubblockIds(input)
|
||||
|
||||
expect(migrated).toBe(false)
|
||||
expect(blocks.b1.subBlocks.knowledgeBaseSelector.value).toBe('kb-uuid')
|
||||
})
|
||||
})
|
||||
|
||||
it('should not mutate the input blocks', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
subBlocks: {
|
||||
knowledgeBaseId: {
|
||||
id: 'knowledgeBaseId',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-uuid',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks } = migrateSubblockIds(input)
|
||||
|
||||
expect(input.b1.subBlocks.knowledgeBaseId).toBeDefined()
|
||||
expect(blocks.b1.subBlocks.knowledgeBaseSelector).toBeDefined()
|
||||
expect(blocks).not.toBe(input)
|
||||
})
|
||||
|
||||
it('should skip blocks with no registered migrations', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'function',
|
||||
subBlocks: {
|
||||
code: { id: 'code', type: 'code', value: 'console.log("hi")' },
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = migrateSubblockIds(input)
|
||||
|
||||
expect(migrated).toBe(false)
|
||||
expect(blocks.b1.subBlocks.code.value).toBe('console.log("hi")')
|
||||
})
|
||||
|
||||
it('should repair malformed subBlocks for every block type without deleting values', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'function',
|
||||
subBlocks: {
|
||||
code: { id: 'code', type: 'unknown', value: 'console.log("hi")' },
|
||||
language: { value: 'javascript' },
|
||||
undefined: { type: 'unknown', value: null },
|
||||
noId: { type: 'short-input', value: 'stale' },
|
||||
noType: { id: 'noType', value: 'stale' },
|
||||
unknownType: { id: 'unknownType', type: 'unknown', value: 'preserved' },
|
||||
notRecord: 'stale',
|
||||
arrayValue: ['a', 'b'],
|
||||
} as unknown as BlockState['subBlocks'],
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = migrateSubblockIds(input)
|
||||
|
||||
expect(migrated).toBe(true)
|
||||
expect(blocks.b1.subBlocks.code).toEqual({
|
||||
id: 'code',
|
||||
type: 'code',
|
||||
value: 'console.log("hi")',
|
||||
})
|
||||
expect(blocks.b1.subBlocks.language).toEqual({
|
||||
id: 'language',
|
||||
type: 'dropdown',
|
||||
value: 'javascript',
|
||||
})
|
||||
expect(blocks.b1.subBlocks.undefined).toBeUndefined()
|
||||
expect(blocks.b1.subBlocks.noId).toBeUndefined()
|
||||
expect(blocks.b1.subBlocks.noType).toBeUndefined()
|
||||
expect(blocks.b1.subBlocks.unknownType).toBeUndefined()
|
||||
expect(blocks.b1.subBlocks.notRecord).toBeUndefined()
|
||||
expect(blocks.b1.subBlocks.arrayValue).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should preserve malformed legacy subBlocks before renaming them', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
subBlocks: {
|
||||
knowledgeBaseId: {
|
||||
id: 'knowledgeBaseId',
|
||||
type: 'unknown',
|
||||
value: 'kb-uuid-123',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = migrateSubblockIds(input)
|
||||
|
||||
expect(migrated).toBe(true)
|
||||
expect(blocks.b1.subBlocks.knowledgeBaseId).toBeUndefined()
|
||||
expect(blocks.b1.subBlocks.knowledgeBaseSelector).toEqual({
|
||||
id: 'knowledgeBaseSelector',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-uuid-123',
|
||||
})
|
||||
})
|
||||
|
||||
it('should migrate multiple blocks in one pass', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
id: 'b1',
|
||||
type: 'knowledge',
|
||||
subBlocks: {
|
||||
knowledgeBaseId: {
|
||||
id: 'knowledgeBaseId',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-1',
|
||||
},
|
||||
},
|
||||
}),
|
||||
b2: makeBlock({
|
||||
id: 'b2',
|
||||
type: 'knowledge',
|
||||
subBlocks: {
|
||||
knowledgeBaseId: {
|
||||
id: 'knowledgeBaseId',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-2',
|
||||
},
|
||||
},
|
||||
}),
|
||||
b3: makeBlock({
|
||||
id: 'b3',
|
||||
type: 'function',
|
||||
subBlocks: {
|
||||
code: { id: 'code', type: 'code', value: '' },
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = migrateSubblockIds(input)
|
||||
|
||||
expect(migrated).toBe(true)
|
||||
expect(blocks.b1.subBlocks.knowledgeBaseSelector.value).toBe('kb-1')
|
||||
expect(blocks.b2.subBlocks.knowledgeBaseSelector.value).toBe('kb-2')
|
||||
expect(blocks.b3.subBlocks.code).toBeDefined()
|
||||
})
|
||||
|
||||
it('should handle blocks with empty subBlocks', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({ type: 'knowledge', subBlocks: {} }),
|
||||
}
|
||||
|
||||
const { migrated } = migrateSubblockIds(input)
|
||||
|
||||
expect(migrated).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('backfillCanonicalModes', () => {
|
||||
it('should add missing canonicalModes entry for knowledge block with basic value', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
data: {},
|
||||
subBlocks: {
|
||||
operation: { id: 'operation', type: 'dropdown', value: 'search' },
|
||||
knowledgeBaseSelector: {
|
||||
id: 'knowledgeBaseSelector',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-uuid',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = backfillCanonicalModes(input)
|
||||
|
||||
expect(migrated).toBe(true)
|
||||
const modes = blocks.b1.data?.canonicalModes as Record<string, string>
|
||||
expect(modes.knowledgeBaseId).toBe('basic')
|
||||
})
|
||||
|
||||
it('should resolve to advanced when only the advanced value is set', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
data: {},
|
||||
subBlocks: {
|
||||
operation: { id: 'operation', type: 'dropdown', value: 'search' },
|
||||
manualKnowledgeBaseId: {
|
||||
id: 'manualKnowledgeBaseId',
|
||||
type: 'short-input',
|
||||
value: 'kb-uuid-manual',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = backfillCanonicalModes(input)
|
||||
|
||||
expect(migrated).toBe(true)
|
||||
const modes = blocks.b1.data?.canonicalModes as Record<string, string>
|
||||
expect(modes.knowledgeBaseId).toBe('advanced')
|
||||
})
|
||||
|
||||
it('should not overwrite existing canonicalModes entries', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
data: { canonicalModes: { knowledgeBaseId: 'advanced', documentId: 'basic' } },
|
||||
subBlocks: {
|
||||
knowledgeBaseSelector: {
|
||||
id: 'knowledgeBaseSelector',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-uuid',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = backfillCanonicalModes(input)
|
||||
|
||||
expect(migrated).toBe(false)
|
||||
const modes = blocks.b1.data?.canonicalModes as Record<string, string>
|
||||
expect(modes.knowledgeBaseId).toBe('advanced')
|
||||
})
|
||||
|
||||
it('should skip blocks with no canonical pairs in their config', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'function',
|
||||
data: {},
|
||||
subBlocks: {
|
||||
code: { id: 'code', type: 'code', value: '' },
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { migrated } = backfillCanonicalModes(input)
|
||||
|
||||
expect(migrated).toBe(false)
|
||||
})
|
||||
|
||||
it('should not mutate the input blocks', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
data: {},
|
||||
subBlocks: {
|
||||
knowledgeBaseSelector: {
|
||||
id: 'knowledgeBaseSelector',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-uuid',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks } = backfillCanonicalModes(input)
|
||||
|
||||
expect(input.b1.data?.canonicalModes).toBeUndefined()
|
||||
expect((blocks.b1.data?.canonicalModes as Record<string, string>).knowledgeBaseId).toBe('basic')
|
||||
expect(blocks).not.toBe(input)
|
||||
})
|
||||
|
||||
it('should resolve correctly when existing field became the basic variant', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
data: {},
|
||||
subBlocks: {
|
||||
operation: { id: 'operation', type: 'dropdown', value: 'search' },
|
||||
knowledgeBaseSelector: {
|
||||
id: 'knowledgeBaseSelector',
|
||||
type: 'knowledge-base-selector',
|
||||
value: 'kb-uuid',
|
||||
},
|
||||
manualKnowledgeBaseId: {
|
||||
id: 'manualKnowledgeBaseId',
|
||||
type: 'short-input',
|
||||
value: '',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = backfillCanonicalModes(input)
|
||||
|
||||
expect(migrated).toBe(true)
|
||||
const modes = blocks.b1.data?.canonicalModes as Record<string, string>
|
||||
expect(modes.knowledgeBaseId).toBe('basic')
|
||||
})
|
||||
|
||||
it('should resolve correctly when existing field became the advanced variant', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
data: {},
|
||||
subBlocks: {
|
||||
operation: { id: 'operation', type: 'dropdown', value: 'search' },
|
||||
knowledgeBaseSelector: {
|
||||
id: 'knowledgeBaseSelector',
|
||||
type: 'knowledge-base-selector',
|
||||
value: '',
|
||||
},
|
||||
manualKnowledgeBaseId: {
|
||||
id: 'manualKnowledgeBaseId',
|
||||
type: 'short-input',
|
||||
value: 'manually-entered-kb-id',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = backfillCanonicalModes(input)
|
||||
|
||||
expect(migrated).toBe(true)
|
||||
const modes = blocks.b1.data?.canonicalModes as Record<string, string>
|
||||
expect(modes.knowledgeBaseId).toBe('advanced')
|
||||
})
|
||||
|
||||
it('should default to basic when neither value is set', () => {
|
||||
const input: Record<string, BlockState> = {
|
||||
b1: makeBlock({
|
||||
type: 'knowledge',
|
||||
data: {},
|
||||
subBlocks: {
|
||||
operation: { id: 'operation', type: 'dropdown', value: 'search' },
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
const { blocks, migrated } = backfillCanonicalModes(input)
|
||||
|
||||
expect(migrated).toBe(true)
|
||||
const modes = blocks.b1.data?.canonicalModes as Record<string, string>
|
||||
expect(modes.knowledgeBaseId).toBe('basic')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,245 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { isPlainRecord } from '@sim/utils/object'
|
||||
import { DEFAULT_SUBBLOCK_TYPE } from '@sim/workflow-persistence/subblocks'
|
||||
import { sanitizeMalformedSubBlocks } from '@/lib/workflows/sanitization/subblocks'
|
||||
import {
|
||||
buildCanonicalIndex,
|
||||
buildSubBlockValues,
|
||||
isCanonicalPair,
|
||||
resolveCanonicalMode,
|
||||
} from '@/lib/workflows/subblocks/visibility'
|
||||
import { getBlock } from '@/blocks'
|
||||
import type { BlockState } from '@/stores/workflows/workflow/types'
|
||||
|
||||
const logger = createLogger('SubblockMigrations')
|
||||
|
||||
/**
|
||||
* Maps old subblock IDs to their current equivalents per block type.
|
||||
*
|
||||
* When a subblock is renamed in a block definition, old deployed/saved states
|
||||
* still carry the value under the previous key. Without this mapping the
|
||||
* serializer silently drops the value, breaking execution.
|
||||
*
|
||||
* Format: { blockType: { oldSubblockId: newSubblockId } }
|
||||
*/
|
||||
export const SUBBLOCK_ID_MIGRATIONS: Record<string, Record<string, string>> = {
|
||||
knowledge: {
|
||||
knowledgeBaseId: 'knowledgeBaseSelector',
|
||||
},
|
||||
algolia: {
|
||||
listPage: 'page',
|
||||
listHitsPerPage: 'hitsPerPage',
|
||||
},
|
||||
kalshi: {
|
||||
settlementStatus: '_removed_settlementStatus',
|
||||
},
|
||||
dynamodb: {
|
||||
key: 'getKey',
|
||||
filterExpression: 'queryFilterExpression',
|
||||
expressionAttributeNames: 'queryExpressionAttributeNames',
|
||||
expressionAttributeValues: 'queryExpressionAttributeValues',
|
||||
limit: 'queryLimit',
|
||||
conditionExpression: 'updateConditionExpression',
|
||||
},
|
||||
ashby: {
|
||||
emailType: '_removed_emailType',
|
||||
phoneType: '_removed_phoneType',
|
||||
expandApplicationFormDefinition: '_removed_expandApplicationFormDefinition',
|
||||
expandSurveyFormDefinitions: '_removed_expandSurveyFormDefinitions',
|
||||
filterCandidateId: '_removed_filterCandidateId',
|
||||
},
|
||||
apollo: {
|
||||
contact_ids_bulk: 'contacts',
|
||||
account_ids_bulk: 'accounts',
|
||||
close_date: 'closed_date',
|
||||
stage_id: 'opportunity_stage_id',
|
||||
note: 'task_notes',
|
||||
description: '_removed_description',
|
||||
stage_ids: '_removed_stage_ids',
|
||||
owner_ids: '_removed_owner_ids',
|
||||
},
|
||||
rippling: {
|
||||
action: '_removed_action',
|
||||
candidateDepartment: '_removed_candidateDepartment',
|
||||
candidatePhone: '_removed_candidatePhone',
|
||||
candidateStartDate: '_removed_candidateStartDate',
|
||||
email: '_removed_email',
|
||||
employeeId: '_removed_employeeId',
|
||||
endDate: '_removed_endDate',
|
||||
firstName: '_removed_firstName',
|
||||
groupId: '_removed_groupId',
|
||||
groupName: '_removed_groupName',
|
||||
groupVersion: '_removed_groupVersion',
|
||||
jobTitle: '_removed_jobTitle',
|
||||
lastName: '_removed_lastName',
|
||||
leaveRequestId: '_removed_leaveRequestId',
|
||||
managedBy: '_removed_managedBy',
|
||||
nextCursor: '_removed_nextCursor',
|
||||
offset: '_removed_offset',
|
||||
roleId: '_removed_roleId',
|
||||
spokeId: '_removed_spokeId',
|
||||
startDate: '_removed_startDate',
|
||||
status: '_removed_status',
|
||||
users: '_removed_users',
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates legacy subblock IDs inside a single block's subBlocks map.
|
||||
* Returns a new subBlocks record if anything changed, or the original if not.
|
||||
*/
|
||||
function migrateBlockSubblockIds(
|
||||
blockType: string,
|
||||
subBlocks: Record<string, BlockState['subBlocks'][string]>,
|
||||
renames: Record<string, string>
|
||||
): { subBlocks: Record<string, BlockState['subBlocks'][string]>; migrated: boolean } {
|
||||
let migrated = false
|
||||
|
||||
for (const oldId of Object.keys(renames)) {
|
||||
if (oldId in subBlocks) {
|
||||
migrated = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (!migrated) return { subBlocks, migrated: false }
|
||||
|
||||
const result = { ...subBlocks }
|
||||
const blockConfig = getBlock(blockType)
|
||||
|
||||
for (const [oldId, newId] of Object.entries(renames)) {
|
||||
if (!(oldId in result)) continue
|
||||
|
||||
if (newId in result) {
|
||||
delete result[oldId]
|
||||
continue
|
||||
}
|
||||
|
||||
const oldEntry: unknown = result[oldId]
|
||||
const configuredType = blockConfig?.subBlocks?.find((config) => config.id === newId)?.type
|
||||
if (isPlainRecord(oldEntry)) {
|
||||
const type =
|
||||
configuredType ||
|
||||
(typeof oldEntry.type === 'string' && oldEntry.type.length > 0
|
||||
? oldEntry.type === 'unknown'
|
||||
? DEFAULT_SUBBLOCK_TYPE
|
||||
: oldEntry.type
|
||||
: DEFAULT_SUBBLOCK_TYPE)
|
||||
const value = Object.hasOwn(oldEntry, 'value') ? oldEntry.value : null
|
||||
|
||||
result[newId] = {
|
||||
...oldEntry,
|
||||
id: newId,
|
||||
type: type as BlockState['subBlocks'][string]['type'],
|
||||
value: value as BlockState['subBlocks'][string]['value'],
|
||||
}
|
||||
} else {
|
||||
result[newId] = {
|
||||
id: newId,
|
||||
type: configuredType || DEFAULT_SUBBLOCK_TYPE,
|
||||
value: oldEntry as BlockState['subBlocks'][string]['value'],
|
||||
}
|
||||
}
|
||||
delete result[oldId]
|
||||
}
|
||||
|
||||
return { subBlocks: result, migrated: true }
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies subblock-ID migrations to every block in a workflow.
|
||||
* Returns a new blocks record with migrated subBlocks where needed.
|
||||
*/
|
||||
export function migrateSubblockIds(blocks: Record<string, BlockState>): {
|
||||
blocks: Record<string, BlockState>
|
||||
migrated: boolean
|
||||
} {
|
||||
let anyMigrated = false
|
||||
const result: Record<string, BlockState> = {}
|
||||
|
||||
for (const [blockId, block] of Object.entries(blocks)) {
|
||||
if (!block.subBlocks) {
|
||||
result[blockId] = block
|
||||
continue
|
||||
}
|
||||
|
||||
const renames = SUBBLOCK_ID_MIGRATIONS[block.type]
|
||||
const renamed = renames
|
||||
? migrateBlockSubblockIds(block.type, block.subBlocks, renames)
|
||||
: { subBlocks: block.subBlocks, migrated: false }
|
||||
const renamedBlock = renamed.migrated ? { ...block, subBlocks: renamed.subBlocks } : block
|
||||
const sanitized = sanitizeMalformedSubBlocks(renamedBlock)
|
||||
const blockMigrated = renamed.migrated || sanitized.changed
|
||||
|
||||
if (blockMigrated) {
|
||||
if (renamed.migrated) {
|
||||
logger.info('Migrated legacy subblock IDs', {
|
||||
blockId: block.id,
|
||||
blockType: block.type,
|
||||
})
|
||||
}
|
||||
anyMigrated = true
|
||||
result[blockId] = { ...renamedBlock, subBlocks: sanitized.subBlocks }
|
||||
} else {
|
||||
result[blockId] = block
|
||||
}
|
||||
}
|
||||
|
||||
return { blocks: result, migrated: anyMigrated }
|
||||
}
|
||||
|
||||
/**
|
||||
* Backfills missing `canonicalModes` entries in block data.
|
||||
*
|
||||
* When a canonical pair is added to a block definition, existing blocks
|
||||
* won't have the entry in `data.canonicalModes`. Without it the editor
|
||||
* toggle may not render correctly. This resolves the correct mode based
|
||||
* on which subblock value is populated and adds the missing entry.
|
||||
*/
|
||||
export function backfillCanonicalModes(blocks: Record<string, BlockState>): {
|
||||
blocks: Record<string, BlockState>
|
||||
migrated: boolean
|
||||
} {
|
||||
let anyMigrated = false
|
||||
const result: Record<string, BlockState> = {}
|
||||
|
||||
for (const [blockId, block] of Object.entries(blocks)) {
|
||||
const blockConfig = getBlock(block.type)
|
||||
if (!blockConfig?.subBlocks || !block.subBlocks) {
|
||||
result[blockId] = block
|
||||
continue
|
||||
}
|
||||
|
||||
const canonicalIndex = buildCanonicalIndex(blockConfig.subBlocks)
|
||||
const pairs = Object.values(canonicalIndex.groupsById).filter(isCanonicalPair)
|
||||
if (pairs.length === 0) {
|
||||
result[blockId] = block
|
||||
continue
|
||||
}
|
||||
|
||||
const existing = (block.data?.canonicalModes ?? {}) as Record<string, 'basic' | 'advanced'>
|
||||
let patched: Record<string, 'basic' | 'advanced'> | null = null
|
||||
|
||||
const values = buildSubBlockValues(block.subBlocks)
|
||||
|
||||
for (const group of pairs) {
|
||||
if (existing[group.canonicalId] != null) continue
|
||||
|
||||
const resolved = resolveCanonicalMode(group, values)
|
||||
if (!patched) patched = { ...existing }
|
||||
patched[group.canonicalId] = resolved
|
||||
}
|
||||
|
||||
if (patched) {
|
||||
anyMigrated = true
|
||||
result[blockId] = {
|
||||
...block,
|
||||
data: { ...(block.data ?? {}), canonicalModes: patched },
|
||||
}
|
||||
} else {
|
||||
result[blockId] = block
|
||||
}
|
||||
}
|
||||
|
||||
return { blocks: result, migrated: anyMigrated }
|
||||
}
|
||||
Reference in New Issue
Block a user