Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
snapshot.js73 linesDownload Raw Back to dist
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3    return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.Snapshot = void 0;
7const util_1 = __importDefault(require("util"));
8const base_1 = require("./base");
9const file_1 = require("./file");
10const utils_1 = require("./utils");
11/**
12 * A container for the signed part of snapshot metadata.
13 *
14 * Snapshot contains information about all target Metadata files.
15 * A top-level role that specifies the latest versions of all targets metadata files,
16 * and hence the latest versions of all targets (including any dependencies between them) on the repository.
17 */
18class Snapshot extends base_1.Signed {
19    type = base_1.MetadataKind.Snapshot;
20    meta;
21    constructor(opts) {
22        super(opts);
23        this.meta = opts.meta || { 'targets.json': new file_1.MetaFile({ version: 1 }) };
24    }
25    equals(other) {
26        if (!(other instanceof Snapshot)) {
27            return false;
28        }
29        return super.equals(other) && util_1.default.isDeepStrictEqual(this.meta, other.meta);
30    }
31    toJSON() {
32        return {
33            _type: this.type,
34            meta: metaToJSON(this.meta),
35            spec_version: this.specVersion,
36            version: this.version,
37            expires: this.expires,
38            ...this.unrecognizedFields,
39        };
40    }
41    static fromJSON(data) {
42        const { unrecognizedFields, ...commonFields } = base_1.Signed.commonFieldsFromJSON(data);
43        const { meta, ...rest } = unrecognizedFields;
44        return new Snapshot({
45            ...commonFields,
46            meta: metaFromJSON(meta),
47            unrecognizedFields: rest,
48        });
49    }
50}
51exports.Snapshot = Snapshot;
52function metaToJSON(meta) {
53    return Object.entries(meta).reduce((acc, [path, metadata]) => ({
54        ...acc,
55        [path]: metadata.toJSON(),
56    }), {});
57}
58function metaFromJSON(data) {
59    let meta;
60    if (utils_1.guard.isDefined(data)) {
61        if (!utils_1.guard.isObjectRecord(data)) {
62            throw new TypeError('meta field is malformed');
63        }
64        else {
65            meta = Object.entries(data).reduce((acc, [path, metadata]) => ({
66                ...acc,
67                [path]: file_1.MetaFile.fromJSON(metadata),
68            }), {});
69        }
70    }
71    return meta;
72}
73 
codekingpro/portable-devtools · Team Ai