"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.adapter = void 0;
const datasource_helper_1 = require("./datasource-helper");
const key = 'github-tags-datasource-v2';
const query = datasource_helper_1.GithubGraphqlDatasourceHelper.prepareQuery(`
  refs(
    first: $count
    after: $cursor
    orderBy: {field: TAG_COMMIT_DATE, direction: DESC}
    refPrefix: "refs/tags/"
  ) {
    pageInfo {
      hasNextPage
      endCursor
    }
    nodes {
      version: name
      target {
        type: __typename
        ... on Commit {
          newDigest: oid
          releaseTimestamp: committedDate
        }
        ... on Tag {
          target {
            ... on Commit {
              newDigest: oid
            }
          }
          tagger {
            releaseTimestamp: date
          }
        }
      }
    }
  }`);
function transform(item) {
    const { version, target } = item;
    if (target.type === 'Commit') {
        const { newDigest, releaseTimestamp } = target;
        return { version, gitRef: version, newDigest, releaseTimestamp };
    }
    else if (target.type === 'Tag') {
        const { newDigest } = target.target;
        const { releaseTimestamp } = target.tagger;
        return { version, gitRef: version, newDigest, releaseTimestamp };
    }
    return null;
}
exports.adapter = { key, query, transform };
//# sourceMappingURL=tags-adapter.js.map