Update records publishing script to resolve watcher and image records
This commit is contained in:
parent
6055da62c7
commit
6ebebaf4b6
@ -16,6 +16,7 @@ enum RecordType {
|
|||||||
StackRecord = 'StackRecord',
|
StackRecord = 'StackRecord',
|
||||||
SubgraphRecord = 'SubgraphRecord',
|
SubgraphRecord = 'SubgraphRecord',
|
||||||
WatcherRecord = 'WatcherRecord',
|
WatcherRecord = 'WatcherRecord',
|
||||||
|
DockerImageRecord = 'DockerImageRecord'
|
||||||
}
|
}
|
||||||
|
|
||||||
const recordTypeToRecordField = new Map<string, string>([
|
const recordTypeToRecordField = new Map<string, string>([
|
||||||
@ -188,6 +189,46 @@ async function publishRecord (userKey: string, bondId: string, fee: StdFee, reco
|
|||||||
record.repository = repoRecordId;
|
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);
|
return registry.setRecord({ privateKey: userKey, record, bondId }, userKey, fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user