From 6ebebaf4b6d1bb824ef78097535ae3ea639f5321 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 26 Aug 2024 14:23:29 +0530 Subject: [PATCH] Update records publishing script to resolve watcher and image records --- demo/scripts/publish-records.ts | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/demo/scripts/publish-records.ts b/demo/scripts/publish-records.ts index 1f9c643..d32b372 100644 --- a/demo/scripts/publish-records.ts +++ b/demo/scripts/publish-records.ts @@ -16,6 +16,7 @@ enum RecordType { StackRecord = 'StackRecord', SubgraphRecord = 'SubgraphRecord', WatcherRecord = 'WatcherRecord', + DockerImageRecord = 'DockerImageRecord' } const recordTypeToRecordField = new Map([ @@ -188,6 +189,46 @@ async function publishRecord (userKey: string, bondId: string, fee: StdFee, reco record.repository = repoRecordId; } + // For stack records, check for attributes + if (record.type === RecordType.StackRecord) { + const watcherName = record.meta?.watcher; + const dockerImages = record.docker_images; + + // If .docker_images present, check for image records + if (Array.isArray(dockerImages) && dockerImages.length > 0) { + const dockerImageRecordsIdPromises = dockerImages.map(async (dockerImage) => { + // Find the required docker image record + const queryResult = await registry.queryRecords({ type: RecordType.DockerImageRecord, name: dockerImage }, true); + if (queryResult.length === 0) { + throw new Error(`Record not found, type: ${RecordType.DockerImageRecord}, name: ${dockerImage}`); + } + + // Assume the first query result + const dockerImageRecordId = queryResult[0].id; + + // Replace watcher name with the watcher record id + return dockerImageRecordId; + }); + + record.docker_images = await Promise.all(dockerImageRecordsIdPromises); + } + + // If .meta.watcher present, check for watcher record + if (watcherName) { + // Find the required watcher record + const queryResult = await registry.queryRecords({ type: RecordType.WatcherRecord, name: watcherName }, true); + if (queryResult.length === 0) { + throw new Error(`Record not found, type: ${RecordType.WatcherRecord}, name: ${watcherName}`); + } + + // Assume the first query result + const watcherRecordId = queryResult[0].id; + + // Replace watcher name with the watcher record id + record.meta.watcher = watcherRecordId; + } + } + return registry.setRecord({ privateKey: userKey, record, bondId }, userKey, fee); }