Replace repository URL in records with published repo record id (#67)

Part of [Define record schemas for entities](https://www.notion.so/Define-record-schemas-for-entities-e13e84d7cf7c4087aae69035733faff0)

Reviewed-on: #67
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
Prathamesh Musale 2024-06-24 07:27:39 +00:00
parent aff309eaad
commit ed06cc05a6
2 changed files with 37 additions and 9 deletions

View File

@ -57,12 +57,12 @@
### Example ### Example
* Query for `ajna-watcher` deployment(s): * Query for `azimuth-watcher` deployment(s):
* Find the `WatcherRecord` for `ajna-watcher`: * Find the `WatcherRecord` for `azimuth-watcher`:
```bash ```bash
WATCHER_RECORD_ID=$(laconic registry record list --all --type WatcherRecord --name ajna-watcher | jq -r '.[].id') WATCHER_RECORD_ID=$(laconic registry record list --all --type WatcherRecord --name azimuth-watcher | jq -r '.[].id')
``` ```
* Find corresponding deployment(s): * Find corresponding deployment(s):
@ -74,7 +74,7 @@
laconic registry record list --all --type WatcherDeploymentRecord watcher $WATCHER_RECORD_ID | jq -r '.[].attributes.url' laconic registry record list --all --type WatcherDeploymentRecord watcher $WATCHER_RECORD_ID | jq -r '.[].attributes.url'
# Expected output: # Expected output:
https://ajna-watcher-endpoint.example.com https://azimuth-watcher-endpoint.example.com
``` ```
* Query for `sushiswap-v3-subgraph` deployment(s): * Query for `sushiswap-v3-subgraph` deployment(s):

View File

@ -4,14 +4,23 @@ import path from 'path';
import assert from 'assert'; import assert from 'assert';
import { hideBin } from 'yargs/helpers'; import { hideBin } from 'yargs/helpers';
import { StdFee } from '@cosmjs/stargate';
import { Registry } from '@cerc-io/registry-sdk'; import { Registry } from '@cerc-io/registry-sdk';
import { getConfig, getGasAndFees, getConnectionInfo, txOutput } from '../../src/util'; import { getConfig, getGasAndFees, getConnectionInfo, txOutput } from '../../src/util';
enum RecordType {
RepositoryRecord = 'RepositoryRecord',
ServiceRecord = 'ServiceRecord',
StackRecord = 'StackRecord',
SubgraphRecord = 'SubgraphRecord',
WatcherRecord = 'WatcherRecord',
}
const recordTypeToRecordField = new Map<string, string>([ const recordTypeToRecordField = new Map<string, string>([
['WatcherRecord', 'watcher'], [RecordType.WatcherRecord, 'watcher'],
['SubgraphRecord', 'subgraph'], [RecordType.SubgraphRecord, 'subgraph'],
['ServiceRecord', 'service'] [RecordType.ServiceRecord, 'service']
]); ]);
let registry: Registry; let registry: Registry;
@ -81,7 +90,7 @@ async function publishRecordsFromDir (recordsDir: string): Promise<void> {
const record = readRecord(filePath); const record = readRecord(filePath);
// Publish record // 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}`); console.log(`Published record ${file}`);
txOutput(result, JSON.stringify(result, undefined, 2), '', false); txOutput(result, JSON.stringify(result, undefined, 2), '', false);
@ -91,7 +100,7 @@ async function publishRecordsFromDir (recordsDir: string): Promise<void> {
// Check if deployment record files exist // Check if deployment record files exist
const deploymentRecordsDir = path.resolve(recordsDir, 'deployments'); const deploymentRecordsDir = path.resolve(recordsDir, 'deployments');
if (!fs.statSync(deploymentRecordsDir).isDirectory()) { if (!fs.existsSync(deploymentRecordsDir) || !fs.statSync(deploymentRecordsDir).isDirectory()) {
return; return;
} }
console.log('--------------------------------------'); console.log('--------------------------------------');
@ -142,6 +151,25 @@ function readRecord (filePath: string): any {
return record; return record;
} }
async function publishRecord (userKey: string, bondId: string, fee: StdFee, record: any): Promise<any> {
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 { function getArgs (): any {
return yargs(hideBin(process.argv)).parserConfiguration({ return yargs(hideBin(process.argv)).parserConfiguration({
'parse-numbers': false 'parse-numbers': false