import { idFromName } from './builderIdUtils' import { normalizeInstrumentMethod, normalizeInstrumentRunItem, } from './runNormalizers' import { createTemplateEnvelope } from './templateEnvelopes' import { validateInstrumentRunData } from './templateValidators' import type { CreateInstrumentRunTemplateOptions, InstrumentRunItem, InstrumentRunTemplate, InstrumentRunTemplateData, } from './types' /** @deprecated Scheduled for removal from the core SDK in MINT 1.4; the biology templates move to a dedicated package or the owning plugins. */ export function createInstrumentRunTemplate( options: CreateInstrumentRunTemplateOptions ): InstrumentRunTemplate { const method = typeof options.method === 'string' || options.method === undefined ? { id: idFromName(options.method ?? 'Default method', 'method-1'), name: options.method ?? 'Default method', instrument: options.instrument, metadata: {}, } : normalizeInstrumentMethod(options.method, options.instrument) const items: InstrumentRunItem[] = [] let order = 1 if (options.includeBlanks !== false) { items.push({ id: 'blank-start', order, kind: 'blank', name: 'Blank start', methodId: method.id, status: 'planned', metadata: {}, }) order += 1 } if (options.includeQc !== false) { items.push({ id: 'qc-start', order, kind: 'qc', name: 'QC start', methodId: method.id, status: 'planned', metadata: {}, }) order += 1 } for (const [index, item] of options.items.entries()) { if (typeof item !== 'string') { const normalized = normalizeInstrumentRunItem(item, method.id, order, index) items.push(normalized) order = Math.max(order, normalized.order + 1) continue } const sampleId = idFromName(item, `sample-${index + 1}`) items.push({ id: `${sampleId}-run`, order, kind: 'sample', sampleId, name: item, methodId: method.id, status: 'planned', metadata: {}, }) order += 1 } if (options.includeQc !== false) { items.push({ id: 'qc-end', order, kind: 'qc', name: 'QC end', methodId: method.id, status: 'planned', metadata: {}, }) } const data: InstrumentRunTemplateData = { runId: 'run-1', instrument: options.instrument, methods: [method], items, metadata: options.metadata ?? {}, } validateInstrumentRunData(data) return createTemplateEnvelope('instrument-run', data, options.metadata ?? {}) }