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

Function importProcess

plugins/process-resources/src/exporter.ts:304–340  ·  view source on GitHub ↗
(
  masterTag: Ref<MasterTag>,
  json: string,
  bindings?: Record<string, string>
)

Source from the content-addressed store, hash-verified

302 * and creates all documents (process, states, transitions) in the model.
303 */
304export async function importProcess (
305 masterTag: Ref<MasterTag>,
306 json: string,
307 bindings?: Record<string, string>
308): Promise<void> {
309 try {
310 const data = JSON.parse(json) as Doc[]
311 if (data.length === 0) return
312 const denormalizedData = denormalizeIds(data, masterTag, bindings ?? {})
313 const client = getClient()
314 const m = client.getModel()
315 const apply = client.apply('Import process')
316 for (const elem of denormalizedData) {
317 if (elem._class === processPlugin.class.Process) {
318 ;(elem as any).masterTag = masterTag
319 if (bindings !== undefined) {
320 ;(elem as any).bindings = bindings
321 }
322 // Strip template metadata — slots will be re-detected for the new environment
323 delete (elem as any).requiredSlots
324 }
325 const existing = m.findObject(elem._id)
326 if (existing !== undefined) {
327 const newData = stripData(elem)
328 const oldData = stripData(existing)
329 if (!deepEqual(newData, oldData)) {
330 await apply.updateDoc(elem._class, existing.space, elem._id, newData)
331 }
332 continue
333 }
334 await apply.createDoc(elem._class, core.space.Model, stripData(elem), elem._id)
335 }
336 await apply.commit(true)
337 } catch (e) {
338 console.error('Failed to import process:', e)
339 }
340}
341
342// ─── ID Normalization ────────────────────────────────────────────────────────
343

Callers 1

Calls 10

getClientFunction · 0.90
denormalizeIdsFunction · 0.85
stripDataFunction · 0.70
parseMethod · 0.45
getModelMethod · 0.45
applyMethod · 0.45
updateDocMethod · 0.45
createDocMethod · 0.45
commitMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected