codekingpro/portable-devtools
114k
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Timestamp = void 0;
4const base_1 = require("./base");
5const file_1 = require("./file");
6const utils_1 = require("./utils");
7/**
8 * A container for the signed part of timestamp metadata.
9 *
10 * A top-level that specifies the latest version of the snapshot role metadata file,
11 * and hence the latest versions of all metadata and targets on the repository.
12 */
13class Timestamp extends base_1.Signed {
14 type = base_1.MetadataKind.Timestamp;
15 snapshotMeta;
16 constructor(options) {
17 super(options);
18 this.snapshotMeta = options.snapshotMeta || new file_1.MetaFile({ version: 1 });
19 }
20 equals(other) {
21 if (!(other instanceof Timestamp)) {
22 return false;
23 }
24 return super.equals(other) && this.snapshotMeta.equals(other.snapshotMeta);
25 }
26 toJSON() {
27 return {
28 _type: this.type,
29 spec_version: this.specVersion,
30 version: this.version,
31 expires: this.expires,
32 meta: { 'snapshot.json': this.snapshotMeta.toJSON() },
33 ...this.unrecognizedFields,
34 };
35 }
36 static fromJSON(data) {
37 const { unrecognizedFields, ...commonFields } = base_1.Signed.commonFieldsFromJSON(data);
38 const { meta, ...rest } = unrecognizedFields;
39 return new Timestamp({
40 ...commonFields,
41 snapshotMeta: snapshotMetaFromJSON(meta),
42 unrecognizedFields: rest,
43 });
44 }
45}
46exports.Timestamp = Timestamp;
47function snapshotMetaFromJSON(data) {
48 let snapshotMeta;
49 if (utils_1.guard.isDefined(data)) {
50 const snapshotData = data['snapshot.json'];
51 if (!utils_1.guard.isDefined(snapshotData) || !utils_1.guard.isObject(snapshotData)) {
52 throw new TypeError('missing snapshot.json in meta');
53 }
54 else {
55 snapshotMeta = file_1.MetaFile.fromJSON(snapshotData);
56 }
57 }
58 return snapshotMeta;
59}
60 