@mark1russell7/package-id 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/purl.ts","../src/version.ts","../src/osv.ts","../src/vers.ts"],"sourcesContent":["/**\n * Package URLs (purl): parse, format and normalize, as the purl specification tells\n * (`https://github.com/package-url/purl-spec`). The form is `pkg:type/namespace/name@version?qualifiers#subpath`.\n *\n * The functions are plain functions with no fetch and no state.\n */\n\n/** A package URL as its parts. Each text part is decoded: it has no percent-encoding. */\nexport interface Purl {\n /** The type of the package, in lower case, for example `npm` or `pypi`. */\n readonly type: string;\n /** The namespace, with `/` between its segments, or `undefined` when the purl has no namespace. */\n readonly namespace?: string;\n /** The name of the package. */\n readonly name: string;\n /** The version, or `undefined` when the purl has no version. */\n readonly version?: string;\n /** The qualifiers, with lower-case keys. A qualifier with an empty value is not in the record. */\n readonly qualifiers?: Readonly<Record<string, string>>;\n /** The subpath, with `/` between its segments, or `undefined` when the purl has no subpath. */\n readonly subpath?: string;\n}\n\n/** The pattern of a type: a letter first, then letters, digits, `.`, `+` or `-`. */\nconst TYPE = /^[a-z][a-z0-9.+-]*$/;\n\n/** The pattern of a qualifier key: a letter first, then letters, digits, `.`, `-` or `_`. */\nconst KEY = /^[a-z][a-z0-9._-]*$/;\n\n/**\n * The types whose namespace and name are not case sensitive. The canonical form of these parts is lower case.\n * The list comes from the type definitions of the purl specification.\n */\nconst LOWER_NAMESPACE_AND_NAME: ReadonlySet<string> = new Set([\"alpm\", \"apk\", \"bitbucket\", \"composer\", \"deb\", \"github\", \"golang\", \"npm\"]);\n\n/** The types whose name only is not case sensitive. The canonical form of the name is lower case. */\nconst LOWER_NAME: ReadonlySet<string> = new Set([\"hex\", \"pub\", \"pypi\"]);\n\n/** This function percent-encodes one part of a purl. A letter, a digit, `.-_~` and `:` stay as they are. */\nfunction encode(text: string): string {\n return encodeURIComponent(text)\n .replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`)\n .replace(/%3A/g, \":\");\n}\n\n/** This function decodes one part of a purl, or gives `undefined` for a bad percent-encoding. */\nfunction decode(text: string): string | undefined {\n try {\n return decodeURIComponent(text);\n } catch {\n return undefined;\n }\n}\n\n/** This function splits a path into its decoded segments. It discards each empty segment. */\nfunction segments(text: string): string[] | undefined {\n const parts: string[] = [];\n for (const raw of text.split(\"/\")) {\n if (raw === \"\") continue;\n const part = decode(raw);\n if (part === undefined) return undefined;\n parts.push(part);\n }\n return parts;\n}\n\n/**\n * This function gives the canonical parts of a purl. The type and the qualifier keys are in lower case. The parts\n * follow the case rules of the type, and no part is empty.\n * It gives `undefined` when a part breaks a rule of the specification.\n */\nexport function normalizePurl(purl: Purl): Purl | undefined {\n const type = purl.type.toLowerCase();\n if (!TYPE.test(type)) return undefined;\n const lowerAll = LOWER_NAMESPACE_AND_NAME.has(type);\n const lowerName = lowerAll || LOWER_NAME.has(type);\n let name = lowerName ? purl.name.toLowerCase() : purl.name;\n if (type === \"pypi\") name = name.replace(/_/g, \"-\");\n if (name === \"\") return undefined;\n const space = purl.namespace?.split(\"/\").filter((segment) => segment !== \"\").join(\"/\");\n const namespace = space === undefined || space === \"\" ? undefined : lowerAll ? space.toLowerCase() : space;\n if (type === \"maven\" && namespace === undefined) return undefined;\n const qualifiers: Record<string, string> = {};\n for (const [key, value] of Object.entries(purl.qualifiers ?? {})) {\n const lower = key.toLowerCase();\n if (!KEY.test(lower)) return undefined;\n if (value !== \"\") qualifiers[lower] = value;\n }\n const subpath = purl.subpath\n ?.split(\"/\")\n .filter((segment) => segment !== \"\" && segment !== \".\" && segment !== \"..\")\n .join(\"/\");\n return {\n type,\n ...(namespace === undefined ? {} : { namespace }),\n name,\n ...(purl.version === undefined || purl.version === \"\" ? {} : { version: purl.version }),\n ...(Object.keys(qualifiers).length === 0 ? {} : { qualifiers }),\n ...(subpath === undefined || subpath === \"\" ? {} : { subpath }),\n };\n}\n\n/**\n * This function reads a purl text into its parts, as the parse steps of the specification tell, and normalizes them.\n * It gives `undefined` when the text is not a valid purl.\n */\nexport function parsePurl(text: string): Purl | undefined {\n let rest = text.trim();\n let subpath: string | undefined;\n const hash = rest.indexOf(\"#\");\n if (hash >= 0) {\n const parts = segments(rest.slice(hash + 1));\n if (parts === undefined) return undefined;\n subpath = parts.filter((segment) => segment !== \".\" && segment !== \"..\").join(\"/\");\n rest = rest.slice(0, hash);\n }\n let qualifiers: Record<string, string> | undefined;\n const question = rest.indexOf(\"?\");\n if (question >= 0) {\n qualifiers = {};\n for (const pair of rest.slice(question + 1).split(\"&\")) {\n if (pair === \"\") continue;\n const equal = pair.indexOf(\"=\");\n if (equal <= 0) return undefined;\n const key = pair.slice(0, equal).toLowerCase();\n const value = decode(pair.slice(equal + 1));\n if (value === undefined || key in qualifiers) return undefined;\n qualifiers[key] = value;\n }\n rest = rest.slice(0, question);\n }\n const colon = rest.indexOf(\":\");\n if (colon < 0 || rest.slice(0, colon).toLowerCase() !== \"pkg\") return undefined;\n rest = rest.slice(colon + 1).replace(/^\\/+/, \"\");\n const slash = rest.indexOf(\"/\");\n if (slash <= 0) return undefined;\n const type = rest.slice(0, slash);\n rest = rest.slice(slash + 1);\n let version: string | undefined;\n const at = rest.lastIndexOf(\"@\");\n // An npm scope in a purl is `%40`, so a raw `@` starts the version. A raw `@` at the start of the\n // namespace is not a version.\n if (at > 0) {\n version = decode(rest.slice(at + 1));\n if (version === undefined) return undefined;\n rest = rest.slice(0, at);\n }\n const path = segments(rest);\n if (path === undefined || path.length === 0) return undefined;\n const name = path[path.length - 1]!;\n const namespace = path.length > 1 ? path.slice(0, -1).join(\"/\") : undefined;\n return normalizePurl({\n type,\n ...(namespace === undefined ? {} : { namespace }),\n name,\n ...(version === undefined ? {} : { version }),\n ...(qualifiers === undefined ? {} : { qualifiers }),\n ...(subpath === undefined ? {} : { subpath }),\n });\n}\n\n/**\n * This function writes the canonical text of a purl: the parts normalized, each part percent-encoded and the\n * qualifiers in the order of their keys. It gives `undefined` when a part breaks a rule of the specification.\n */\nexport function formatPurl(purl: Purl): string | undefined {\n const canonical = normalizePurl(purl);\n if (canonical === undefined) return undefined;\n let text = `pkg:${canonical.type}/`;\n if (canonical.namespace !== undefined) text += `${canonical.namespace.split(\"/\").map(encode).join(\"/\")}/`;\n text += encode(canonical.name);\n if (canonical.version !== undefined) text += `@${encode(canonical.version)}`;\n const keys = Object.keys(canonical.qualifiers ?? {}).sort();\n // A qualifier value keeps its `/`, as the test suite of the specification does with `repository_url`.\n if (keys.length > 0) text += `?${keys.map((key) => `${key}=${encode(canonical.qualifiers![key]!).replace(/%2F/g, \"/\")}`).join(\"&\")}`;\n if (canonical.subpath !== undefined) text += `#${canonical.subpath.split(\"/\").map(encode).join(\"/\")}`;\n return text;\n}\n\n/**\n * This function gives the canonical purl of the package with no version, no qualifiers and no subpath. A person who\n * names a package with this text names each version of it. It gives `undefined` when the text is not a valid purl.\n */\nexport function packagePurlOf(text: string): string | undefined {\n const purl = parsePurl(text);\n return purl === undefined ? undefined : formatPurl({ type: purl.type, ...(purl.namespace === undefined ? {} : { namespace: purl.namespace }), name: purl.name });\n}\n","/**\n * The version order of each ecosystem: SemVer, Go modules, PEP 440, Debian and RPM. Each function compares two\n * versions of one scheme. A text that is not a version of the scheme gives `undefined`, not a guess.\n */\n\n/** The version schemes that this module compares. */\nexport type VersionScheme = \"semver\" | \"golang\" | \"pypi\" | \"deb\" | \"rpm\";\n\n/** The version scheme of each purl type whose order this module knows. */\nconst TYPE_SCHEMES: ReadonlyMap<string, VersionScheme> = new Map([\n [\"npm\", \"semver\"],\n [\"cargo\", \"semver\"],\n [\"semver\", \"semver\"],\n [\"golang\", \"golang\"],\n [\"pypi\", \"pypi\"],\n [\"deb\", \"deb\"],\n [\"rpm\", \"rpm\"],\n]);\n\n/** This function gives the version scheme of a purl type, or `undefined` for a type whose order this module does not know. */\nexport function versionScheme(type: string): VersionScheme | undefined {\n return TYPE_SCHEMES.get(type.toLowerCase());\n}\n\n/**\n * This function compares two versions of one scheme. The result is below 0 when `a` comes before `b`, 0 when they are\n * equal and above 0 when `a` comes after `b`. When a text is not a version of the scheme, the result is `undefined`.\n */\nexport function compareVersions(scheme: string, a: string, b: string): number | undefined {\n switch (scheme) {\n case \"semver\":\n case \"npm\":\n case \"cargo\":\n return compareSemver(a, b);\n case \"golang\":\n return compareGo(a, b);\n case \"pypi\":\n return comparePep440(a, b);\n case \"deb\":\n return compareDebian(a, b);\n case \"rpm\":\n return compareRpm(a, b);\n default:\n return undefined;\n }\n}\n\nconst sign = (n: number): number => (n < 0 ? -1 : n > 0 ? 1 : 0);\nconst compareText = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);\nconst compareDigits = (a: string, b: string): number => {\n const x = a.replace(/^0+(?=\\d)/, \"\");\n const y = b.replace(/^0+(?=\\d)/, \"\");\n return x.length !== y.length ? sign(x.length - y.length) : compareText(x, y);\n};\n\n// SemVer 2.0.0. The build metadata does not change the order.\nconst SEMVER = /^v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$/;\n\n/** The parts of a SemVer version that decide its order. */\ninterface Semver {\n readonly core: readonly [string, string, string];\n readonly pre: readonly string[];\n}\n\nfunction parseSemver(text: string): Semver | undefined {\n const match = SEMVER.exec(text.trim().replace(/^=/, \"\"));\n if (match === null) return undefined;\n return { core: [match[1]!, match[2]!, match[3]!], pre: match[4] === undefined ? [] : match[4].split(\".\") };\n}\n\nfunction compareSemverParts(x: Semver, y: Semver): number {\n for (let i = 0; i < 3; i++) {\n const c = compareDigits(x.core[i]!, y.core[i]!);\n if (c !== 0) return c;\n }\n // A version with a pre-release comes before the same version with no pre-release.\n if (x.pre.length === 0 || y.pre.length === 0) return sign(y.pre.length - x.pre.length);\n for (let i = 0; i < Math.min(x.pre.length, y.pre.length); i++) {\n const p = x.pre[i]!;\n const q = y.pre[i]!;\n const pn = /^\\d+$/.test(p);\n const qn = /^\\d+$/.test(q);\n const c = pn && qn ? compareDigits(p, q) : pn ? -1 : qn ? 1 : compareText(p, q);\n if (c !== 0) return c;\n }\n return sign(x.pre.length - y.pre.length);\n}\n\n/** This function compares two SemVer 2.0.0 versions. It accepts a leading `v` or `=`, as npm does. */\nexport function compareSemver(a: string, b: string): number | undefined {\n const x = parseSemver(a);\n const y = parseSemver(b);\n return x === undefined || y === undefined ? undefined : compareSemverParts(x, y);\n}\n\n/**\n * This function compares two versions of Go modules. A Go version starts with `v` and follows SemVer. A pseudo-version is\n * a pre-release, so it has its place in the order of SemVer. The suffix `+incompatible` is build metadata.\n */\nexport function compareGo(a: string, b: string): number | undefined {\n if (!a.startsWith(\"v\") || !b.startsWith(\"v\")) return undefined;\n return compareSemver(a, b);\n}\n\n// PEP 440: the pattern of the version specification of the Python packaging guide.\nconst PEP440 =\n /^\\s*v?(?:(?:(\\d+)!)?(\\d+(?:\\.\\d+)*)(?:[-_.]?(a|b|c|rc|alpha|beta|pre|preview)[-_.]?(\\d+)?)?(?:-(\\d+)|[-_.]?(post|rev|r)[-_.]?(\\d+)?)?(?:[-_.]?(dev)[-_.]?(\\d+)?)?)(?:\\+([a-z0-9]+(?:[-_.][a-z0-9]+)*))?\\s*$/i;\n\n/** The parts of a PEP 440 version that decide its order. */\ninterface Pep440 {\n readonly epoch: number;\n readonly release: readonly number[];\n /** The pre-release as a rank (a 0, b 1, rc 2) and a number. */\n readonly pre?: readonly [number, number];\n readonly post?: number;\n readonly dev?: number;\n readonly local: readonly string[];\n}\n\nconst PRE_RANK: Readonly<Record<string, number>> = { a: 0, alpha: 0, b: 1, beta: 1, c: 2, rc: 2, pre: 2, preview: 2 };\n\nfunction parsePep440(text: string): Pep440 | undefined {\n const m = PEP440.exec(text);\n if (m === null) return undefined;\n const release = m[2]!.split(\".\").map(Number);\n while (release.length > 1 && release[release.length - 1] === 0) release.pop();\n const post = m[5] !== undefined ? Number(m[5]) : m[6] !== undefined ? Number(m[7] ?? 0) : undefined;\n return {\n epoch: Number(m[1] ?? 0),\n release,\n ...(m[3] === undefined ? {} : { pre: [PRE_RANK[m[3].toLowerCase()]!, Number(m[4] ?? 0)] as const }),\n ...(post === undefined ? {} : { post }),\n ...(m[8] === undefined ? {} : { dev: Number(m[9] ?? 0) }),\n local: m[10] === undefined ? [] : m[10].toLowerCase().split(/[-_.]/),\n };\n}\n\nfunction compareNumbers(a: readonly number[], b: readonly number[]): number {\n for (let i = 0; i < Math.max(a.length, b.length); i++) {\n const c = sign((a[i] ?? 0) - (b[i] ?? 0));\n if (c !== 0) return c;\n }\n return 0;\n}\n\n/** This function compares two PEP 440 versions, with the order of the Python packaging specification. */\nexport function comparePep440(a: string, b: string): number | undefined {\n const x = parsePep440(a);\n const y = parsePep440(b);\n if (x === undefined || y === undefined) return undefined;\n const epoch = sign(x.epoch - y.epoch);\n if (epoch !== 0) return epoch;\n const release = compareNumbers(x.release, y.release);\n if (release !== 0) return release;\n // A dev release with no pre-release and no post-release comes before each pre-release.\n const preKey = (v: Pep440): readonly number[] => (v.pre !== undefined ? [0, ...v.pre] : v.post === undefined && v.dev !== undefined ? [-1] : [1]);\n const pre = compareNumbers(preKey(x), preKey(y));\n if (pre !== 0) return pre;\n const postKey = (v: Pep440): readonly number[] => (v.post === undefined ? [-1] : [0, v.post]);\n const post = compareNumbers(postKey(x), postKey(y));\n if (post !== 0) return post;\n const devKey = (v: Pep440): readonly number[] => (v.dev === undefined ? [1] : [0, v.dev]);\n const dev = compareNumbers(devKey(x), devKey(y));\n if (dev !== 0) return dev;\n return compareLocal(x.local, y.local);\n}\n\n// A local version comes after the same version with no local part. A number segment comes after a text segment.\nfunction compareLocal(a: readonly string[], b: readonly string[]): number {\n for (let i = 0; i < Math.min(a.length, b.length); i++) {\n const p = a[i]!;\n const q = b[i]!;\n const pn = /^\\d+$/.test(p);\n const qn = /^\\d+$/.test(q);\n const c = pn && qn ? compareDigits(p, q) : pn ? 1 : qn ? -1 : compareText(p, q);\n if (c !== 0) return c;\n }\n return sign(a.length - b.length);\n}\n\n// The order of a character of a Debian version: `~` comes before the end, the end before a letter, a letter before\n// each other character. A digit has the rank of the end, as in dpkg.\nfunction debianRank(text: string, i: number): number {\n if (i >= text.length) return 0;\n const c = text[i]!;\n if (/d/.test(c)) return 0;\n if (c === \"~\") return -1;\n if (/[A-Za-z]/.test(c)) return c.charCodeAt(0);\n return c.charCodeAt(0) + 256;\n}\n\n// The comparison of dpkg: parts with no digit and parts of digits, one after the other.\nfunction compareDebianPart(a: string, b: string): number {\n let i = 0;\n let j = 0;\n while (i < a.length || j < b.length) {\n while ((i < a.length && !/\\d/.test(a[i]!)) || (j < b.length && !/\\d/.test(b[j]!))) {\n const c = debianRank(a, i) - debianRank(b, j);\n if (c !== 0) return sign(c);\n i++;\n j++;\n }\n let p = \"\";\n let q = \"\";\n while (i < a.length && /\\d/.test(a[i]!)) p += a[i++];\n while (j < b.length && /\\d/.test(b[j]!)) q += b[j++];\n const c = compareDigits(p || \"0\", q || \"0\");\n if (c !== 0) return c;\n }\n return 0;\n}\n\nconst DEBIAN = /^(?:(\\d+):)?([0-9][A-Za-z0-9.+~:-]*?)(?:-([A-Za-z0-9.+~]+))?$/;\n\n/** This function compares two Debian versions (`[epoch:]upstream[-revision]`) with the order of dpkg. */\nexport function compareDebian(a: string, b: string): number | undefined {\n const x = DEBIAN.exec(a.trim());\n const y = DEBIAN.exec(b.trim());\n if (x === null || y === null) return undefined;\n const epoch = compareDigits(x[1] ?? \"0\", y[1] ?? \"0\");\n if (epoch !== 0) return epoch;\n const upstream = compareDebianPart(x[2]!, y[2]!);\n if (upstream !== 0) return upstream;\n return compareDebianPart(x[3] ?? \"0\", y[3] ?? \"0\");\n}\n\n// The comparison of rpmvercmp: segments of letters or digits. `~` comes before each other thing, also the end. `^` comes\n// after the end, but before each other segment.\nfunction rpmvercmp(a: string, b: string): number {\n if (a === b) return 0;\n let i = 0;\n let j = 0;\n for (;;) {\n while (i < a.length && !/[A-Za-z0-9~^]/.test(a[i]!)) i++;\n while (j < b.length && !/[A-Za-z0-9~^]/.test(b[j]!)) j++;\n const ca = a[i];\n const cb = b[j];\n if (ca === \"~\" || cb === \"~\") {\n if (ca !== \"~\") return 1;\n if (cb !== \"~\") return -1;\n i++;\n j++;\n continue;\n }\n if (ca === \"^\" || cb === \"^\") {\n if (ca === undefined) return -1;\n if (cb === undefined) return 1;\n if (ca !== \"^\") return 1;\n if (cb !== \"^\") return -1;\n i++;\n j++;\n continue;\n }\n if (ca === undefined || cb === undefined) break;\n const digits = /\\d/.test(ca);\n const same = digits ? /\\d/ : /[A-Za-z]/;\n let p = \"\";\n let q = \"\";\n while (i < a.length && same.test(a[i]!)) p += a[i++];\n while (j < b.length && same.test(b[j]!)) q += b[j++];\n // A segment of digits comes after a segment of letters.\n if (q === \"\") return digits ? 1 : -1;\n const c = digits ? compareDigits(p, q) : compareText(p, q);\n if (c !== 0) return c;\n }\n if (i >= a.length && j >= b.length) return 0;\n return i >= a.length ? -1 : 1;\n}\n\nconst RPM = /^(?:(\\d+):)?([^-]+)(?:-([^-]+))?$/;\n\n/** This function compares two RPM versions (`[epoch:]version[-release]`) with the order of `rpmvercmp`. */\nexport function compareRpm(a: string, b: string): number | undefined {\n const x = RPM.exec(a.trim());\n const y = RPM.exec(b.trim());\n if (x === null || y === null) return undefined;\n const epoch = compareDigits(x[1] ?? \"0\", y[1] ?? \"0\");\n if (epoch !== 0) return epoch;\n const version = rpmvercmp(x[2]!, y[2]!);\n if (version !== 0) return version;\n // A version with no release comes before each release of that version. Thus a check of a fix does not take it as fixed.\n return rpmvercmp(x[3] ?? \"\", y[3] ?? \"\");\n}\n","/**\n * The map from the ecosystems of OSV (`https://ossf.github.io/osv-schema/`) to purl types, and the purl of a package\n * of an OSV record.\n */\n\nimport { formatPurl, packagePurlOf } from \"./purl.ts\";\nimport type { Vers, VersConstraint } from \"./vers.ts\";\nimport { compareVersions, versionScheme } from \"./version.ts\";\n\n/**\n * The purl type of each OSV ecosystem that has one. An ecosystem that is not in the table has no purl.\n * For a Linux distribution, the table key is the part of the ecosystem before the first `:`.\n */\nexport const OSV_PURL_TYPES: Readonly<Record<string, string>> = {\n npm: \"npm\",\n PyPI: \"pypi\",\n \"crates.io\": \"cargo\",\n RubyGems: \"gem\",\n NuGet: \"nuget\",\n Go: \"golang\",\n Maven: \"maven\",\n Packagist: \"composer\",\n Pub: \"pub\",\n Hex: \"hex\",\n Hackage: \"hackage\",\n CRAN: \"cran\",\n \"GitHub Actions\": \"github\",\n Debian: \"deb\",\n Ubuntu: \"deb\",\n Alpine: \"apk\",\n};\n\n/** The purl namespace of each OSV ecosystem of a Linux distribution: the name of the distribution. */\nconst DISTRIBUTION: Readonly<Record<string, string>> = { Debian: \"debian\", Ubuntu: \"ubuntu\", Alpine: \"alpine\" };\n\n/** This function gives the namespace and the name of an OSV package name, as the purl type of its ecosystem splits them. */\nfunction split(type: string, name: string): { readonly namespace?: string; readonly name: string } | undefined {\n switch (type) {\n case \"npm\": {\n const slash = name.indexOf(\"/\");\n return name.startsWith(\"@\") && slash > 1 ? { namespace: name.slice(0, slash), name: name.slice(slash + 1) } : { name };\n }\n case \"golang\":\n case \"composer\":\n case \"github\": {\n const slash = name.lastIndexOf(\"/\");\n return slash > 0 ? { namespace: name.slice(0, slash), name: name.slice(slash + 1) } : { name };\n }\n case \"maven\": {\n const colon = name.indexOf(\":\");\n return colon > 0 ? { namespace: name.slice(0, colon), name: name.slice(colon + 1) } : undefined;\n }\n default:\n return { name };\n }\n}\n\n/**\n * This function gives the canonical purl of an OSV package, with no version. For an ecosystem with no purl type, or\n * a bad name, it gives `undefined`.\n */\nexport function osvPurl(ecosystem: string, name: string): string | undefined {\n const base = ecosystem.split(\":\")[0]!;\n const type = Object.hasOwn(OSV_PURL_TYPES, base) ? OSV_PURL_TYPES[base] : undefined;\n if (type === undefined || name === \"\") return undefined;\n const names = split(type, name);\n if (names === undefined) return undefined;\n const distribution = Object.hasOwn(DISTRIBUTION, base) ? DISTRIBUTION[base] : undefined;\n const namespace = distribution ?? names.namespace;\n return formatPurl({ type, ...(namespace === undefined ? {} : { namespace }), name: names.name });\n}\n\n/**\n * This function gives the purl of a package of an OSV record, with no version, qualifiers or subpath. A valid purl\n * of the record wins. Else the function builds the purl from the ecosystem and the name.\n */\nexport function osvPackagePurl(pkg: { readonly ecosystem: string; readonly name: string; readonly purl?: string }): string | undefined {\n const own = pkg.purl === undefined ? undefined : packagePurlOf(pkg.purl);\n return own ?? osvPurl(pkg.ecosystem, pkg.name);\n}\n\n/** One event of an OSV range, as the OSV schema writes it: each event has one of the four fields. */\nexport interface OsvEvent {\n readonly introduced?: string;\n readonly fixed?: string;\n readonly last_affected?: string;\n readonly limit?: string;\n}\n\n/** A range of an OSV record: its type (`SEMVER`, `ECOSYSTEM` or `GIT`) and its events. */\nexport interface OsvRange {\n readonly type: string;\n readonly events: readonly OsvEvent[];\n}\n\n/**\n * This function gives the `vers` range of an OSV range. A range of the type `SEMVER` has the scheme `semver`. A range\n * of the type `ECOSYSTEM` has the purl type of its ecosystem as its scheme. A `GIT` range, an ecosystem with no purl type\n * or an event with no version gives `undefined`.\n *\n * The events come in the order of their versions, as the OSV schema tells, when the scheme has a known order. Else they\n * keep the order of the record. The event `introduced 0` is the start of each version, so it gives no constraint.\n */\nexport function osvRangeVers(ecosystem: string, range: OsvRange): Vers | undefined {\n const base = ecosystem.split(\":\")[0]!;\n const type = Object.hasOwn(OSV_PURL_TYPES, base) ? OSV_PURL_TYPES[base] : undefined;\n const scheme = range.type === \"SEMVER\" ? \"semver\" : range.type === \"ECOSYSTEM\" ? type : undefined;\n if (scheme === undefined) return undefined;\n const constraints: VersConstraint[] = [];\n let all = false;\n for (const event of range.events) {\n const constraint = eventConstraint(event);\n if (constraint === undefined) return undefined;\n if (constraint === \"start\") all = true;\n else if (constraint !== \"none\") constraints.push(constraint);\n }\n if (constraints.length === 0) return all ? { scheme, all: true, constraints: [] } : undefined;\n return { scheme, all: false, constraints: sortEvents(scheme, constraints) };\n}\n\n// The constraint of one event: \"start\" for `introduced 0`, \"none\" for `limit *` (no limit).\nfunction eventConstraint(event: OsvEvent): VersConstraint | \"start\" | \"none\" | undefined {\n if (event.introduced !== undefined) return event.introduced === \"0\" ? \"start\" : { comparator: \">=\", version: event.introduced };\n if (event.fixed !== undefined) return { comparator: \"<\", version: event.fixed };\n if (event.last_affected !== undefined) return { comparator: \"<=\", version: event.last_affected };\n if (event.limit !== undefined) return event.limit === \"*\" ? \"none\" : { comparator: \"<\", version: event.limit };\n return undefined;\n}\n\n// The constraints in the order of their versions, or in their own order when the scheme has no known order.\nfunction sortEvents(scheme: string, constraints: readonly VersConstraint[]): VersConstraint[] {\n if (versionScheme(scheme) === undefined) return [...constraints];\n let unknown = false;\n const sorted = [...constraints].sort((a, b) => {\n const c = compareVersions(scheme, a.version, b.version);\n if (c === undefined) unknown = true;\n return c ?? 0;\n });\n return unknown ? [...constraints] : sorted;\n}\n","/**\n * Version ranges in the `vers` format of the purl specification, for example `vers:npm/>=1.0.0|<1.2.3`. The functions\n * parse a range, format it and tell if a version is in it, with the version order of the scheme.\n */\nimport { compareVersions } from \"./version.ts\";\n\n/** The comparators of a `vers` constraint. */\nexport type VersComparator = \"=\" | \"!=\" | \"<\" | \"<=\" | \">\" | \">=\";\n\n/** One constraint of a range: a comparator and a version. */\nexport interface VersConstraint {\n readonly comparator: VersComparator;\n readonly version: string;\n}\n\n/** A version range. A range with the constraint `*` holds each version, and its list of constraints is empty. */\nexport interface Vers {\n /** The version scheme, for example `npm`, `pypi` or `deb`. */\n readonly scheme: string;\n /** True: the range is `*`, so it holds each version. */\n readonly all: boolean;\n readonly constraints: readonly VersConstraint[];\n}\n\n// The longer comparators come first, so `<=` is not read as `<` and a version that starts with `=`.\nconst COMPARATORS: readonly VersComparator[] = [\"!=\", \"<=\", \">=\", \"<\", \">\", \"=\"];\n\n/** This function reads one constraint, for example `>=1.0.0`. A constraint with no comparator has the comparator `=`. */\nfunction parseConstraint(text: string): VersConstraint | undefined {\n const trimmed = text.trim();\n const comparator = COMPARATORS.find((c) => trimmed.startsWith(c)) ?? \"=\";\n const raw = trimmed.slice(trimmed.startsWith(comparator) ? comparator.length : 0).trim();\n if (raw === \"\") return undefined;\n let version: string;\n try {\n version = decodeURIComponent(raw);\n } catch {\n return undefined;\n }\n return { comparator, version };\n}\n\n/** This function reads a `vers` text. A text that is not a range gives `undefined`. */\nexport function parseVers(text: string): Vers | undefined {\n const match = /^vers:([A-Za-z0-9.+-]+)\\/(.+)$/.exec(text.replace(/\\s+/g, \"\"));\n if (match === null) return undefined;\n const scheme = match[1]!.toLowerCase();\n const body = match[2]!;\n if (body === \"*\") return { scheme, all: true, constraints: [] };\n const constraints: VersConstraint[] = [];\n for (const part of body.split(\"|\")) {\n const constraint = parseConstraint(part);\n if (constraint === undefined) return undefined;\n constraints.push(constraint);\n }\n return { scheme, all: false, constraints };\n}\n\n// The characters that a version keeps in a `vers` text: the others are percent-encoded.\nconst encodeVersion = (version: string): string => version.replace(/[^A-Za-z0-9.+~_:-]/g, (c) => encodeURIComponent(c));\n\n/**\n * This function gives the `vers` text of a range. The constraints come in the order of the versions, when the scheme\n * has a known order. The comparator `=` has no sign, as the specification tells.\n */\nexport function formatVers(vers: Vers): string {\n if (vers.all) return `vers:${vers.scheme}/*`;\n const sorted = sortConstraints(vers.scheme, vers.constraints) ?? vers.constraints;\n const body = sorted.map((c) => `${c.comparator === \"=\" ? \"\" : c.comparator}${encodeVersion(c.version)}`).join(\"|\");\n return `vers:${vers.scheme}/${body}`;\n}\n\n// The constraints in the order of their versions, or `undefined` when a version is not a version of the scheme.\nfunction sortConstraints(scheme: string, constraints: readonly VersConstraint[]): VersConstraint[] | undefined {\n let unknown = false;\n const sorted = [...constraints].sort((a, b) => {\n const c = compareVersions(scheme, a.version, b.version);\n if (c === undefined) unknown = true;\n return c ?? 0;\n });\n return unknown ? undefined : sorted;\n}\n\n/**\n * This function tells if a version is in a range, with the algorithm of the `vers` specification. The result is\n * `undefined` when the scheme has no known order, or when a version is not a version of the scheme. Thus a caller\n * does not take an unknown result as a match or as no match.\n */\nexport function versContains(vers: Vers, version: string): boolean | undefined {\n if (vers.all) return true;\n const compare = (a: string, b: string): number | undefined => compareVersions(vers.scheme, a, b);\n for (const constraint of vers.constraints) {\n const c = compare(version, constraint.version);\n if (c === undefined) return undefined;\n if (c === 0 && [\"=\", \"<=\", \">=\"].includes(constraint.comparator)) return true;\n if (c === 0 && constraint.comparator === \"!=\") return false;\n }\n const ranged = sortConstraints(\n vers.scheme,\n vers.constraints.filter((c) => c.comparator !== \"=\" && c.comparator !== \"!=\"),\n );\n if (ranged === undefined) return undefined;\n if (ranged.length === 0) {\n // Only `!=` constraints that the version does not equal: the version is in the range.\n return vers.constraints.some((c) => c.comparator === \"!=\");\n }\n const below = (c: VersConstraint): boolean => c.comparator === \"<\" || c.comparator === \"<=\";\n const above = (c: VersConstraint): boolean => c.comparator === \">\" || c.comparator === \">=\";\n const first = ranged[0]!;\n const last = ranged[ranged.length - 1]!;\n if (below(first) && compare(version, first.version)! < 0) return true;\n if (above(last) && compare(version, last.version)! > 0) return true;\n for (let i = 0; i + 1 < ranged.length; i++) {\n const low = ranged[i]!;\n const high = ranged[i + 1]!;\n if (above(low) && below(high) && compare(version, low.version)! > 0 && compare(version, high.version)! < 0) return true;\n }\n return false;\n}\n\n/**\n * This function gives the end of the part of a range that holds a version, when that end is a constraint `<`. For the\n * range of an advisory, it is the first fixed version above the version. The result is `undefined` for a version out\n * of the range, or for an unknown order. It is also `undefined` for a part with no such end: `<=`, an open end or `=`.\n */\nexport function versEnd(vers: Vers, version: string): string | undefined {\n if (vers.all || versContains(vers, version) !== true) return undefined;\n if (vers.constraints.some((c) => c.comparator === \"=\" && compareVersions(vers.scheme, version, c.version) === 0)) return undefined;\n const ranged = sortConstraints(\n vers.scheme,\n vers.constraints.filter((c) => c.comparator !== \"=\" && c.comparator !== \"!=\"),\n );\n const next = ranged?.find((c) => compareVersions(vers.scheme, version, c.version)! < 0);\n return next?.comparator === \"<\" ? next.version : undefined;\n}\n"],"mappings":";;AAwBA,MAAM,OAAO;;AAGb,MAAM,MAAM;;;;;AAMZ,MAAM,2CAAgD,IAAI,IAAI;CAAC;CAAQ;CAAO;CAAa;CAAY;CAAO;CAAU;CAAU;AAAK,CAAC;;AAGxI,MAAM,6BAAkC,IAAI,IAAI;CAAC;CAAO;CAAO;AAAM,CAAC;;AAGtE,SAAS,OAAO,MAAsB;CACpC,OAAO,mBAAmB,IAAI,CAAC,CAC5B,QAAQ,aAAa,cAAc,IAAI,UAAU,WAAW,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,YAAY,GAAG,CAAC,CAC5F,QAAQ,QAAQ,GAAG;AACxB;;AAGA,SAAS,OAAO,MAAkC;CAChD,IAAI;EACF,OAAO,mBAAmB,IAAI;CAChC,QAAQ;EACN;CACF;AACF;;AAGA,SAAS,SAAS,MAAoC;CACpD,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,OAAO,KAAK,MAAM,GAAG,GAAG;EACjC,IAAI,QAAQ,IAAI;EAChB,MAAM,OAAO,OAAO,GAAG;EACvB,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;EAC/B,MAAM,KAAK,IAAI;CACjB;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,cAAc,MAA8B;CAC1D,MAAM,OAAO,KAAK,KAAK,YAAY;CACnC,IAAI,CAAC,KAAK,KAAK,IAAI,GAAG,OAAO,KAAA;CAC7B,MAAM,WAAW,yBAAyB,IAAI,IAAI;CAElD,IAAI,OADc,YAAY,WAAW,IAAI,IAAI,IAC1B,KAAK,KAAK,YAAY,IAAI,KAAK;CACtD,IAAI,SAAS,QAAQ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MAAM,OAAO,IAAK,GAAG,OAAO;CACjE,IAAI,MAAM,IAAI,KAAK,QAAQ,SAAS,KAAK,OAAO,IAAK,GAAG,OAAO;CAC/D,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,OAAO,QAAQ,KAAK;EAC1C,MAAM,MAAM,OAAO;EACnB,MAAM,OAAO,OAAO,IAAI;EACxB,IAAI,MAAM,GAAG,KAAK,MAAM,IAAI,KAAK,QAAQ,SAAS,IAAI,OAAO,IAAK,KAAK,QAAQ,SAAS,KAAK,OAAO,IAAK,GAAG,OAAO;CACrH;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,QAAQ,MAAY,SAAqC;CACvE,IAAI,KAAK,OAAO,aAAa,MAAM,OAAO,MAAM,MAAM,OAAO,KAAA;CAC7D,IAAI,KAAK,YAAY,MAAM,MAAM,EAAE,eAAe,OAAO,gBAAgB,KAAK,QAAQ,SAAS,EAAE,OAAO,MAAM,CAAC,GAAG,OAAO,KAAA;CAKzH,MAAM,OAJS,gBACb,KAAK,QACL,KAAK,YAAY,QAAQ,MAAM,EAAE,eAAe,OAAO,EAAE,eAAe,IAAI,CAE5D,CAAC,EAAE,MAAM,MAAM,gBAAgB,KAAK,QAAQ,SAAS,EAAE,OAAO,IAAK,CAAC;CACtF,OAAO,MAAM,eAAe,MAAM,KAAK,UAAU,KAAA;AACnD"}
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
+ "$schema": "https://json.schemastore.org/package",
2
3
  "name": "@mark1russell7/package-id",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
4
+ "version": "0.0.2",
5
+ "description": "Package URLs (purl), the purl of each OSV ecosystem, the version order of each ecosystem and version ranges (vers). Plain functions with no fetch.",
6
+ "keywords": [
7
+ "purl",
8
+ "package-url",
9
+ "osv",
10
+ "sbom",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://github.com/mark1russell7/package-id#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/mark1russell7/package-id/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/mark1russell7/package-id.git",
20
+ "directory": "packages/package-id"
21
+ },
22
+ "license": "MIT",
23
+ "author": "Mark Russell (https://github.com/mark1russell7)",
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "main": "./build/index.js",
27
+ "types": "./build/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./build/index.d.ts",
31
+ "default": "./build/index.js"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "files": [
36
+ "build",
37
+ "src",
38
+ "!src/**/*.test.ts"
39
+ ],
40
+ "engines": {
41
+ "node": ">=22.12"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "devDependencies": {
47
+ "@mark1russell7/cue": "^2.0.0",
48
+ "@types/node": "^26.6.5",
49
+ "@vitest/coverage-v8": "^5.0.3",
50
+ "esbuild": "^0.28.2",
51
+ "tsdown": "^0.23.7",
52
+ "typescript": "^7.0.2",
53
+ "vitest": "^5.0.3"
54
+ },
55
+ "scripts": {
56
+ "build": "tsdown",
57
+ "test": "vitest run",
58
+ "test:watch": "vitest",
59
+ "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json"
60
+ }
6
61
  }
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Package identities: package URLs (purl), the purl of each OSV ecosystem, the version order of each ecosystem and version ranges (vers). The functions are plain functions with
3
+ * no fetch.
4
+ */
5
+
6
+ export { formatPurl, normalizePurl, packagePurlOf, parsePurl, type Purl } from "./purl.ts";
7
+ export { OSV_PURL_TYPES, osvPackagePurl, osvPurl, osvRangeVers, type OsvEvent, type OsvRange } from "./osv.ts";
8
+ export {
9
+ compareDebian,
10
+ compareGo,
11
+ comparePep440,
12
+ compareRpm,
13
+ compareSemver,
14
+ compareVersions,
15
+ versionScheme,
16
+ type VersionScheme,
17
+ } from "./version.ts";
18
+ export { formatVers, parseVers, versContains, versEnd, type Vers, type VersComparator, type VersConstraint } from "./vers.ts";
package/src/osv.ts ADDED
@@ -0,0 +1,140 @@
1
+ /**
2
+ * The map from the ecosystems of OSV (`https://ossf.github.io/osv-schema/`) to purl types, and the purl of a package
3
+ * of an OSV record.
4
+ */
5
+
6
+ import { formatPurl, packagePurlOf } from "./purl.ts";
7
+ import type { Vers, VersConstraint } from "./vers.ts";
8
+ import { compareVersions, versionScheme } from "./version.ts";
9
+
10
+ /**
11
+ * The purl type of each OSV ecosystem that has one. An ecosystem that is not in the table has no purl.
12
+ * For a Linux distribution, the table key is the part of the ecosystem before the first `:`.
13
+ */
14
+ export const OSV_PURL_TYPES: Readonly<Record<string, string>> = {
15
+ npm: "npm",
16
+ PyPI: "pypi",
17
+ "crates.io": "cargo",
18
+ RubyGems: "gem",
19
+ NuGet: "nuget",
20
+ Go: "golang",
21
+ Maven: "maven",
22
+ Packagist: "composer",
23
+ Pub: "pub",
24
+ Hex: "hex",
25
+ Hackage: "hackage",
26
+ CRAN: "cran",
27
+ "GitHub Actions": "github",
28
+ Debian: "deb",
29
+ Ubuntu: "deb",
30
+ Alpine: "apk",
31
+ };
32
+
33
+ /** The purl namespace of each OSV ecosystem of a Linux distribution: the name of the distribution. */
34
+ const DISTRIBUTION: Readonly<Record<string, string>> = { Debian: "debian", Ubuntu: "ubuntu", Alpine: "alpine" };
35
+
36
+ /** This function gives the namespace and the name of an OSV package name, as the purl type of its ecosystem splits them. */
37
+ function split(type: string, name: string): { readonly namespace?: string; readonly name: string } | undefined {
38
+ switch (type) {
39
+ case "npm": {
40
+ const slash = name.indexOf("/");
41
+ return name.startsWith("@") && slash > 1 ? { namespace: name.slice(0, slash), name: name.slice(slash + 1) } : { name };
42
+ }
43
+ case "golang":
44
+ case "composer":
45
+ case "github": {
46
+ const slash = name.lastIndexOf("/");
47
+ return slash > 0 ? { namespace: name.slice(0, slash), name: name.slice(slash + 1) } : { name };
48
+ }
49
+ case "maven": {
50
+ const colon = name.indexOf(":");
51
+ return colon > 0 ? { namespace: name.slice(0, colon), name: name.slice(colon + 1) } : undefined;
52
+ }
53
+ default:
54
+ return { name };
55
+ }
56
+ }
57
+
58
+ /**
59
+ * This function gives the canonical purl of an OSV package, with no version. For an ecosystem with no purl type, or
60
+ * a bad name, it gives `undefined`.
61
+ */
62
+ export function osvPurl(ecosystem: string, name: string): string | undefined {
63
+ const base = ecosystem.split(":")[0]!;
64
+ const type = Object.hasOwn(OSV_PURL_TYPES, base) ? OSV_PURL_TYPES[base] : undefined;
65
+ if (type === undefined || name === "") return undefined;
66
+ const names = split(type, name);
67
+ if (names === undefined) return undefined;
68
+ const distribution = Object.hasOwn(DISTRIBUTION, base) ? DISTRIBUTION[base] : undefined;
69
+ const namespace = distribution ?? names.namespace;
70
+ return formatPurl({ type, ...(namespace === undefined ? {} : { namespace }), name: names.name });
71
+ }
72
+
73
+ /**
74
+ * This function gives the purl of a package of an OSV record, with no version, qualifiers or subpath. A valid purl
75
+ * of the record wins. Else the function builds the purl from the ecosystem and the name.
76
+ */
77
+ export function osvPackagePurl(pkg: { readonly ecosystem: string; readonly name: string; readonly purl?: string }): string | undefined {
78
+ const own = pkg.purl === undefined ? undefined : packagePurlOf(pkg.purl);
79
+ return own ?? osvPurl(pkg.ecosystem, pkg.name);
80
+ }
81
+
82
+ /** One event of an OSV range, as the OSV schema writes it: each event has one of the four fields. */
83
+ export interface OsvEvent {
84
+ readonly introduced?: string;
85
+ readonly fixed?: string;
86
+ readonly last_affected?: string;
87
+ readonly limit?: string;
88
+ }
89
+
90
+ /** A range of an OSV record: its type (`SEMVER`, `ECOSYSTEM` or `GIT`) and its events. */
91
+ export interface OsvRange {
92
+ readonly type: string;
93
+ readonly events: readonly OsvEvent[];
94
+ }
95
+
96
+ /**
97
+ * This function gives the `vers` range of an OSV range. A range of the type `SEMVER` has the scheme `semver`. A range
98
+ * of the type `ECOSYSTEM` has the purl type of its ecosystem as its scheme. A `GIT` range, an ecosystem with no purl type
99
+ * or an event with no version gives `undefined`.
100
+ *
101
+ * The events come in the order of their versions, as the OSV schema tells, when the scheme has a known order. Else they
102
+ * keep the order of the record. The event `introduced 0` is the start of each version, so it gives no constraint.
103
+ */
104
+ export function osvRangeVers(ecosystem: string, range: OsvRange): Vers | undefined {
105
+ const base = ecosystem.split(":")[0]!;
106
+ const type = Object.hasOwn(OSV_PURL_TYPES, base) ? OSV_PURL_TYPES[base] : undefined;
107
+ const scheme = range.type === "SEMVER" ? "semver" : range.type === "ECOSYSTEM" ? type : undefined;
108
+ if (scheme === undefined) return undefined;
109
+ const constraints: VersConstraint[] = [];
110
+ let all = false;
111
+ for (const event of range.events) {
112
+ const constraint = eventConstraint(event);
113
+ if (constraint === undefined) return undefined;
114
+ if (constraint === "start") all = true;
115
+ else if (constraint !== "none") constraints.push(constraint);
116
+ }
117
+ if (constraints.length === 0) return all ? { scheme, all: true, constraints: [] } : undefined;
118
+ return { scheme, all: false, constraints: sortEvents(scheme, constraints) };
119
+ }
120
+
121
+ // The constraint of one event: "start" for `introduced 0`, "none" for `limit *` (no limit).
122
+ function eventConstraint(event: OsvEvent): VersConstraint | "start" | "none" | undefined {
123
+ if (event.introduced !== undefined) return event.introduced === "0" ? "start" : { comparator: ">=", version: event.introduced };
124
+ if (event.fixed !== undefined) return { comparator: "<", version: event.fixed };
125
+ if (event.last_affected !== undefined) return { comparator: "<=", version: event.last_affected };
126
+ if (event.limit !== undefined) return event.limit === "*" ? "none" : { comparator: "<", version: event.limit };
127
+ return undefined;
128
+ }
129
+
130
+ // The constraints in the order of their versions, or in their own order when the scheme has no known order.
131
+ function sortEvents(scheme: string, constraints: readonly VersConstraint[]): VersConstraint[] {
132
+ if (versionScheme(scheme) === undefined) return [...constraints];
133
+ let unknown = false;
134
+ const sorted = [...constraints].sort((a, b) => {
135
+ const c = compareVersions(scheme, a.version, b.version);
136
+ if (c === undefined) unknown = true;
137
+ return c ?? 0;
138
+ });
139
+ return unknown ? [...constraints] : sorted;
140
+ }
package/src/purl.ts ADDED
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Package URLs (purl): parse, format and normalize, as the purl specification tells
3
+ * (`https://github.com/package-url/purl-spec`). The form is `pkg:type/namespace/name@version?qualifiers#subpath`.
4
+ *
5
+ * The functions are plain functions with no fetch and no state.
6
+ */
7
+
8
+ /** A package URL as its parts. Each text part is decoded: it has no percent-encoding. */
9
+ export interface Purl {
10
+ /** The type of the package, in lower case, for example `npm` or `pypi`. */
11
+ readonly type: string;
12
+ /** The namespace, with `/` between its segments, or `undefined` when the purl has no namespace. */
13
+ readonly namespace?: string;
14
+ /** The name of the package. */
15
+ readonly name: string;
16
+ /** The version, or `undefined` when the purl has no version. */
17
+ readonly version?: string;
18
+ /** The qualifiers, with lower-case keys. A qualifier with an empty value is not in the record. */
19
+ readonly qualifiers?: Readonly<Record<string, string>>;
20
+ /** The subpath, with `/` between its segments, or `undefined` when the purl has no subpath. */
21
+ readonly subpath?: string;
22
+ }
23
+
24
+ /** The pattern of a type: a letter first, then letters, digits, `.`, `+` or `-`. */
25
+ const TYPE = /^[a-z][a-z0-9.+-]*$/;
26
+
27
+ /** The pattern of a qualifier key: a letter first, then letters, digits, `.`, `-` or `_`. */
28
+ const KEY = /^[a-z][a-z0-9._-]*$/;
29
+
30
+ /**
31
+ * The types whose namespace and name are not case sensitive. The canonical form of these parts is lower case.
32
+ * The list comes from the type definitions of the purl specification.
33
+ */
34
+ const LOWER_NAMESPACE_AND_NAME: ReadonlySet<string> = new Set(["alpm", "apk", "bitbucket", "composer", "deb", "github", "golang", "npm"]);
35
+
36
+ /** The types whose name only is not case sensitive. The canonical form of the name is lower case. */
37
+ const LOWER_NAME: ReadonlySet<string> = new Set(["hex", "pub", "pypi"]);
38
+
39
+ /** This function percent-encodes one part of a purl. A letter, a digit, `.-_~` and `:` stay as they are. */
40
+ function encode(text: string): string {
41
+ return encodeURIComponent(text)
42
+ .replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`)
43
+ .replace(/%3A/g, ":");
44
+ }
45
+
46
+ /** This function decodes one part of a purl, or gives `undefined` for a bad percent-encoding. */
47
+ function decode(text: string): string | undefined {
48
+ try {
49
+ return decodeURIComponent(text);
50
+ } catch {
51
+ return undefined;
52
+ }
53
+ }
54
+
55
+ /** This function splits a path into its decoded segments. It discards each empty segment. */
56
+ function segments(text: string): string[] | undefined {
57
+ const parts: string[] = [];
58
+ for (const raw of text.split("/")) {
59
+ if (raw === "") continue;
60
+ const part = decode(raw);
61
+ if (part === undefined) return undefined;
62
+ parts.push(part);
63
+ }
64
+ return parts;
65
+ }
66
+
67
+ /**
68
+ * This function gives the canonical parts of a purl. The type and the qualifier keys are in lower case. The parts
69
+ * follow the case rules of the type, and no part is empty.
70
+ * It gives `undefined` when a part breaks a rule of the specification.
71
+ */
72
+ export function normalizePurl(purl: Purl): Purl | undefined {
73
+ const type = purl.type.toLowerCase();
74
+ if (!TYPE.test(type)) return undefined;
75
+ const lowerAll = LOWER_NAMESPACE_AND_NAME.has(type);
76
+ const lowerName = lowerAll || LOWER_NAME.has(type);
77
+ let name = lowerName ? purl.name.toLowerCase() : purl.name;
78
+ if (type === "pypi") name = name.replace(/_/g, "-");
79
+ if (name === "") return undefined;
80
+ const space = purl.namespace?.split("/").filter((segment) => segment !== "").join("/");
81
+ const namespace = space === undefined || space === "" ? undefined : lowerAll ? space.toLowerCase() : space;
82
+ if (type === "maven" && namespace === undefined) return undefined;
83
+ const qualifiers: Record<string, string> = {};
84
+ for (const [key, value] of Object.entries(purl.qualifiers ?? {})) {
85
+ const lower = key.toLowerCase();
86
+ if (!KEY.test(lower)) return undefined;
87
+ if (value !== "") qualifiers[lower] = value;
88
+ }
89
+ const subpath = purl.subpath
90
+ ?.split("/")
91
+ .filter((segment) => segment !== "" && segment !== "." && segment !== "..")
92
+ .join("/");
93
+ return {
94
+ type,
95
+ ...(namespace === undefined ? {} : { namespace }),
96
+ name,
97
+ ...(purl.version === undefined || purl.version === "" ? {} : { version: purl.version }),
98
+ ...(Object.keys(qualifiers).length === 0 ? {} : { qualifiers }),
99
+ ...(subpath === undefined || subpath === "" ? {} : { subpath }),
100
+ };
101
+ }
102
+
103
+ /**
104
+ * This function reads a purl text into its parts, as the parse steps of the specification tell, and normalizes them.
105
+ * It gives `undefined` when the text is not a valid purl.
106
+ */
107
+ export function parsePurl(text: string): Purl | undefined {
108
+ let rest = text.trim();
109
+ let subpath: string | undefined;
110
+ const hash = rest.indexOf("#");
111
+ if (hash >= 0) {
112
+ const parts = segments(rest.slice(hash + 1));
113
+ if (parts === undefined) return undefined;
114
+ subpath = parts.filter((segment) => segment !== "." && segment !== "..").join("/");
115
+ rest = rest.slice(0, hash);
116
+ }
117
+ let qualifiers: Record<string, string> | undefined;
118
+ const question = rest.indexOf("?");
119
+ if (question >= 0) {
120
+ qualifiers = {};
121
+ for (const pair of rest.slice(question + 1).split("&")) {
122
+ if (pair === "") continue;
123
+ const equal = pair.indexOf("=");
124
+ if (equal <= 0) return undefined;
125
+ const key = pair.slice(0, equal).toLowerCase();
126
+ const value = decode(pair.slice(equal + 1));
127
+ if (value === undefined || key in qualifiers) return undefined;
128
+ qualifiers[key] = value;
129
+ }
130
+ rest = rest.slice(0, question);
131
+ }
132
+ const colon = rest.indexOf(":");
133
+ if (colon < 0 || rest.slice(0, colon).toLowerCase() !== "pkg") return undefined;
134
+ rest = rest.slice(colon + 1).replace(/^\/+/, "");
135
+ const slash = rest.indexOf("/");
136
+ if (slash <= 0) return undefined;
137
+ const type = rest.slice(0, slash);
138
+ rest = rest.slice(slash + 1);
139
+ let version: string | undefined;
140
+ const at = rest.lastIndexOf("@");
141
+ // An npm scope in a purl is `%40`, so a raw `@` starts the version. A raw `@` at the start of the
142
+ // namespace is not a version.
143
+ if (at > 0) {
144
+ version = decode(rest.slice(at + 1));
145
+ if (version === undefined) return undefined;
146
+ rest = rest.slice(0, at);
147
+ }
148
+ const path = segments(rest);
149
+ if (path === undefined || path.length === 0) return undefined;
150
+ const name = path[path.length - 1]!;
151
+ const namespace = path.length > 1 ? path.slice(0, -1).join("/") : undefined;
152
+ return normalizePurl({
153
+ type,
154
+ ...(namespace === undefined ? {} : { namespace }),
155
+ name,
156
+ ...(version === undefined ? {} : { version }),
157
+ ...(qualifiers === undefined ? {} : { qualifiers }),
158
+ ...(subpath === undefined ? {} : { subpath }),
159
+ });
160
+ }
161
+
162
+ /**
163
+ * This function writes the canonical text of a purl: the parts normalized, each part percent-encoded and the
164
+ * qualifiers in the order of their keys. It gives `undefined` when a part breaks a rule of the specification.
165
+ */
166
+ export function formatPurl(purl: Purl): string | undefined {
167
+ const canonical = normalizePurl(purl);
168
+ if (canonical === undefined) return undefined;
169
+ let text = `pkg:${canonical.type}/`;
170
+ if (canonical.namespace !== undefined) text += `${canonical.namespace.split("/").map(encode).join("/")}/`;
171
+ text += encode(canonical.name);
172
+ if (canonical.version !== undefined) text += `@${encode(canonical.version)}`;
173
+ const keys = Object.keys(canonical.qualifiers ?? {}).sort();
174
+ // A qualifier value keeps its `/`, as the test suite of the specification does with `repository_url`.
175
+ if (keys.length > 0) text += `?${keys.map((key) => `${key}=${encode(canonical.qualifiers![key]!).replace(/%2F/g, "/")}`).join("&")}`;
176
+ if (canonical.subpath !== undefined) text += `#${canonical.subpath.split("/").map(encode).join("/")}`;
177
+ return text;
178
+ }
179
+
180
+ /**
181
+ * This function gives the canonical purl of the package with no version, no qualifiers and no subpath. A person who
182
+ * names a package with this text names each version of it. It gives `undefined` when the text is not a valid purl.
183
+ */
184
+ export function packagePurlOf(text: string): string | undefined {
185
+ const purl = parsePurl(text);
186
+ return purl === undefined ? undefined : formatPurl({ type: purl.type, ...(purl.namespace === undefined ? {} : { namespace: purl.namespace }), name: purl.name });
187
+ }