From 08d6351d256d324fa9d826ab1b296a9fc7668fcc Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 21 Jun 2024 11:09:06 +0530 Subject: [PATCH 1/2] Fix deployments dir check in the script to publish records --- demo/scripts/publish-records.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/scripts/publish-records.ts b/demo/scripts/publish-records.ts index efb2a72..71783d8 100644 --- a/demo/scripts/publish-records.ts +++ b/demo/scripts/publish-records.ts @@ -91,7 +91,7 @@ async function publishRecordsFromDir (recordsDir: string): Promise { // Check if deployment record files exist const deploymentRecordsDir = path.resolve(recordsDir, 'deployments'); - if (!fs.statSync(deploymentRecordsDir).isDirectory()) { + if (!fs.existsSync(deploymentRecordsDir) || !fs.statSync(deploymentRecordsDir).isDirectory()) { return; } console.log('--------------------------------------'); -- 2.45.2 From 120f36d07d6c0b22ff3422a99240c315d19be6fa Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 21 Jun 2024 15:59:09 +0530 Subject: [PATCH 2/2] Replace repository URL in records with published repo record id --- demo/scripts/publish-records.ts | 36 +++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/demo/scripts/publish-records.ts b/demo/scripts/publish-records.ts index 71783d8..6134438 100644 --- a/demo/scripts/publish-records.ts +++ b/demo/scripts/publish-records.ts @@ -4,14 +4,23 @@ import path from 'path'; import assert from 'assert'; import { hideBin } from 'yargs/helpers'; +import { StdFee } from '@cosmjs/stargate'; import { Registry } from '@cerc-io/registry-sdk'; import { getConfig, getGasAndFees, getConnectionInfo, txOutput } from '../../src/util'; +enum RecordType { + RepositoryRecord = 'RepositoryRecord', + ServiceRecord = 'ServiceRecord', + StackRecord = 'StackRecord', + SubgraphRecord = 'SubgraphRecord', + WatcherRecord = 'WatcherRecord', +} + const recordTypeToRecordField = new Map([ - ['WatcherRecord', 'watcher'], - ['SubgraphRecord', 'subgraph'], - ['ServiceRecord', 'service'] + [RecordType.WatcherRecord, 'watcher'], + [RecordType.SubgraphRecord, 'subgraph'], + [RecordType.ServiceRecord, 'service'] ]); let registry: Registry; @@ -81,7 +90,7 @@ async function publishRecordsFromDir (recordsDir: string): Promise { const record = readRecord(filePath); // Publish record - const result = await registry.setRecord({ privateKey: userKey, record, bondId }, userKey, fee); + const result = await publishRecord(userKey, bondId, fee, record); console.log(`Published record ${file}`); txOutput(result, JSON.stringify(result, undefined, 2), '', false); @@ -142,6 +151,25 @@ function readRecord (filePath: string): any { return record; } +async function publishRecord (userKey: string, bondId: string, fee: StdFee, record: any): Promise { + if (record.repository) { + const repoUrl = record.repository; + + const queryResult = await registry.queryRecords({ type: RecordType.RepositoryRecord, url: repoUrl }, true); + if (queryResult.length === 0) { + throw new Error(`Record not found, type: ${RecordType.RepositoryRecord}, url: ${repoUrl}`); + } + + // Assume the first query result + const repoRecordId = queryResult[0].id; + + // Replace repository URL with the repo record id + record.repository = repoRecordId; + } + + return registry.setRecord({ privateKey: userKey, record, bondId }, userKey, fee); +} + function getArgs (): any { return yargs(hideBin(process.argv)).parserConfiguration({ 'parse-numbers': false -- 2.45.2