MCPcopy
hub / github.com/hcengineering/platform / exportProcess

Function exportProcess

plugins/process-resources/src/exporter.ts:212–280  ·  view source on GitHub ↗
(proc: Process, withSlots: boolean = true)

Source from the content-addressed store, hash-verified

210 * Returns normalized docs where all IDs are replaced with placeholders.
211 */
212export function exportProcess (proc: Process, withSlots: boolean = true): ExportResult {
213 const docs: Doc[] = [proc]
214 const required: Array<Ref<Class<Doc>>> = []
215 const client = getClient()
216 const m = client.getModel()
217 const h = client.getHierarchy()
218
219 // Collect states and transitions
220 docs.push(...m.findAllSync(processPlugin.class.State, { process: proc._id }))
221 const transitions = m.findAllSync(processPlugin.class.Transition, { process: proc._id })
222 docs.push(...transitions)
223
224 // Process type dependencies from transitions
225 for (const tr of transitions) {
226 processParams(tr.triggerParams, proc.masterTag, docs, required, m, h)
227 for (const action of tr.actions) {
228 processParams(action.params, proc.masterTag, docs, required, m, h)
229 if (action.results !== undefined) {
230 for (const res of action.results) {
231 processType(res.type, docs, required, m, h)
232 }
233 }
234 }
235 }
236
237 // Process type dependencies from context
238 if (proc.context !== undefined) {
239 for (const key in proc.context) {
240 const ctx = proc.context[key as any]
241 if (ctx.type !== undefined) {
242 processType(ctx.type, docs, required, m, h)
243 }
244 }
245 }
246
247 if (proc.resultType !== undefined) {
248 processType(proc.resultType, docs, required, m, h)
249 }
250
251 if (withSlots) {
252 // Detect slots and bindings
253 const requiredSlots: Record<string, SlotModel> = {}
254 const bindings: Record<string, string> = {}
255 detectSlots(proc, transitions, requiredSlots, bindings, m, h)
256
257 // Attach slots/bindings to the process doc for serialization
258 const clonedProc = { ...proc, requiredSlots, bindings }
259 const docIndex = docs.findIndex((d) => d._id === proc._id)
260 if (docIndex !== -1) docs[docIndex] = clonedProc
261
262 // Process type dependencies from detected slots
263 for (const slotId in requiredSlots) {
264 const slot = requiredSlots[slotId]
265 if (slot.slotKind === 'attribute' && (slot as AttributeSlotModel).type != null) {
266 processType((slot as AttributeSlotModel).type, docs, required, m, h)
267 } else if (slot.slotKind === 'class' || slot.slotKind === 'process') {
268 if (h.isDerived(slot._class, card.class.Card) && !required.includes(slot._class)) {
269 required.push(slot._class)

Callers 2

exportProcessesFunction · 0.85

Calls 9

getClientFunction · 0.90
processParamsFunction · 0.85
processTypeFunction · 0.85
detectSlotsFunction · 0.85
normalizeIdsFunction · 0.85
isDerivedMethod · 0.80
getModelMethod · 0.45
getHierarchyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected