// Ported from js-yaml v3.13.1:
// https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import type { Type } from "../_type.ts";
import { isPlainObject } from "../_utils.ts";

function resolveYamlPairs(data: unknown[][]): boolean {
  if (data === null) return true;
  return data.every((it) => isPlainObject(it) && Object.keys(it).length === 1);
}

export const pairs: Type<"sequence"> = {
  tag: "tag:yaml.org,2002:pairs",
  construct(data: Record<string, unknown>[] | null): [string, unknown][] {
    // Converts an array of objects into an array of key-value pairs.
    return data?.flatMap(Object.entries) ?? [];
  },
  kind: "sequence",
  resolve: resolveYamlPairs,
};

// denoCacheMetadata={"headers":{"access-control-expose-headers":"*","x-robots-tag":"noindex","cf-cache-status":"HIT","cf-ray":"a223e6590e567db6-LAX","date":"Tue, 28 Jul 2026 12:31:15 GMT","accept-ranges":"bytes","age":"1086610","x-content-type-options":"nosniff","set-cookie":"__cf_bm=50mJa8NJioLOlf7I9.9rK1Z9hCBo7OOm2YjaIAiFvuw-1785241875.3731968-1.0.1.1-hp4Mps5W_Z3U88Bg0dZ0xzROTpIa85eYV_gFkMZuaaiA8QGYK3qzhcTeybGiTiD2u7cW8Jh5Xyv0_OysHMWNg3YkOG9UIih97xKo85iZ98N_z28Dw7lh09BgaONwj866; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=YZs8cwXUfAYwFfelvVf9iCAdoT6zoPIutZrbSE3Yz2mg1x20V3IVRInnlVIlibmhCpCEJNpqmv%2FUtPkCeBLlUxs6gYu8Y0o1eTu%2FP5HPSoJYsq0Pud1qJsU%3D\"}]}","x-jsr-backend":"modules","content-type":"text/typescript","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","alt-svc":"h3=\":443\"; ma=86400","cross-origin-resource-policy":"cross-origin","content-length":"854","access-control-allow-origin":"*","server":"cloudflare","cache-control":"public, max-age=31536000, immutable","etag":"\"9b171991ed0101bb268b5c977ec33608\"","vary":"Origin","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';"},"url":"https://jsr.io/@std/yaml/1.0.5/_type/pairs.ts","time":1785241875}