"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Manifest = exports.DistributionListManifest = exports.DistributionManifest = exports.OciImageIndexManifest = exports.OciImageManifest = exports.OciImageConfig = exports.Descriptor = exports.ManifestObject = exports.HelmConfigBlob = void 0;
const zod_1 = require("zod");
// Helm manifests
exports.HelmConfigBlob = zod_1.z.object({
    home: zod_1.z.string().optional(),
    sources: zod_1.z.array(zod_1.z.string()).optional(),
});
// OCI manifests
/**
 *  OCI manifest object
 */
exports.ManifestObject = zod_1.z.object({
    schemaVersion: zod_1.z.literal(2),
    mediaType: zod_1.z.string(),
});
/**
 * Oci descriptor
 * https://github.com/opencontainers/image-spec/blob/main/descriptor.md
 */
exports.Descriptor = zod_1.z.object({
    mediaType: zod_1.z.string(),
    digest: zod_1.z.string(),
    size: zod_1.z.number(),
});
/**
 * OCI platform properties
 * https://github.com/opencontainers/image-spec/blob/main/image-index.md
 */
const OciPlatform = zod_1.z
    .object({
    architecture: zod_1.z.string().optional(),
})
    .optional();
/**
 * OCI Image Configuration.
 *
 * Compatible with old docker configiguration.
 https://github.com/opencontainers/image-spec/blob/main/config.md
 */
exports.OciImageConfig = zod_1.z.object({
    architecture: zod_1.z.string(),
    config: zod_1.z.object({ Labels: zod_1.z.record(zod_1.z.string()).optional() }).optional(),
});
/**
 * OCI Image Manifest
 * The same structure as docker image manifest, but mediaType is not required and is not present in the wild.
 * https://github.com/opencontainers/image-spec/blob/main/manifest.md
 */
exports.OciImageManifest = exports.ManifestObject.extend({
    mediaType: zod_1.z
        .literal('application/vnd.oci.image.manifest.v1+json')
        .default('application/vnd.oci.image.manifest.v1+json'),
    config: exports.Descriptor.extend({
        mediaType: zod_1.z.enum([
            'application/vnd.oci.image.config.v1+json',
            'application/vnd.cncf.helm.config.v1+json',
        ]),
    }),
    annotations: zod_1.z.record(zod_1.z.string()).optional(),
});
/**
 * OCI Image List
 * mediaType is not required.
 * https://github.com/opencontainers/image-spec/blob/main/image-index.md
 */
exports.OciImageIndexManifest = exports.ManifestObject.extend({
    mediaType: zod_1.z
        .literal('application/vnd.oci.image.index.v1+json')
        .default('application/vnd.oci.image.index.v1+json'),
    manifests: zod_1.z.array(exports.Descriptor.extend({
        mediaType: zod_1.z.enum([
            'application/vnd.oci.image.manifest.v1+json',
            'application/vnd.oci.image.index.v1+json',
        ]),
        platform: OciPlatform,
    })),
    annotations: zod_1.z.record(zod_1.z.string()).optional(),
});
// Old Docker manifests
/**
 * Image Manifest
 * https://docs.docker.com/registry/spec/manifest-v2-2/#image-manifest
 */
exports.DistributionManifest = exports.ManifestObject.extend({
    mediaType: zod_1.z.literal('application/vnd.docker.distribution.manifest.v2+json'),
    config: exports.Descriptor.extend({
        mediaType: zod_1.z.literal('application/vnd.docker.container.image.v1+json'),
    }),
});
/**
 * Manifest List
 * https://docs.docker.com/registry/spec/manifest-v2-2/#manifest-list
 */
exports.DistributionListManifest = exports.ManifestObject.extend({
    mediaType: zod_1.z.literal('application/vnd.docker.distribution.manifest.list.v2+json'),
    manifests: zod_1.z.array(exports.Descriptor.extend({
        mediaType: zod_1.z.literal('application/vnd.docker.distribution.manifest.v2+json'),
        platform: OciPlatform,
    })),
});
// Combined manifests
exports.Manifest = zod_1.z.union([
    exports.DistributionManifest,
    exports.DistributionListManifest,
    exports.OciImageManifest,
    exports.OciImageIndexManifest,
]);
//# sourceMappingURL=schema.js.map