Documentation
¶
Overview ¶
pkg/identifiers/identifiers.go
Index ¶
- func CandidateForms(value string) []string
- func DuplicateTypeError(identifierType string) error
- func Key(identifierType, value string) string
- func NormalizeISBN(value string) string
- func NormalizeValue(identifierType, value string) string
- func ReconcileSources(existing, incoming []*models.FileIdentifier) (unchanged bool)
- func ValidateISBN10(isbn string) bool
- func ValidateISBN13(isbn string) bool
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CandidateForms ¶ added in v0.0.30
CandidateForms returns all plausible canonical forms of a user-provided identifier value for lookup purposes. Because the type is not known at query time (a user may search by ISBN, ASIN, or UUID without specifying which), this enumerates the normalized variants across the supported types so a single query can match legacy rows stored in any format. The raw input is always included as the first element. Duplicates are removed. Returns nil for an empty or whitespace-only input.
Each candidate form is only added if the input plausibly represents that type. This prevents false positives like `"ref-9780316769488-v2"` — a vendor id whose digits happen to contain a valid ISBN substring — from matching real ISBN rows. Specifically:
- ISBN candidate is added only if the raw input consists exclusively of digits/hyphens/spaces (with optional leading "ISBN"/"ISBN:") AND the normalized form passes an ISBN-10 or ISBN-13 checksum.
- Uppercased ASIN candidate is added only if the uppercased form matches the ASIN pattern.
- Lowercased UUID candidate (with `urn:uuid:` prefix stripped) is added only if the stripped form matches the UUID pattern.
func DuplicateTypeError ¶ added in v0.1.0
DuplicateTypeError is the 422 for an identifier collection that lists a type twice. The file update and plugin apply routes both reject it before writing, so they share one message.
func Key ¶ added in v0.0.30
Key returns a stable comparison key for an identifier, using the canonical form of the value. Two identifiers with semantically identical values but cosmetic differences (hyphens, prefixes, case) produce the same Key, so diff-based code (e.g. scan reconciliation) can tell when a set has actually changed without treating "978-0-316-76948-8" and "9780316769488" as distinct.
func NormalizeISBN ¶
NormalizeISBN removes hyphens, spaces, and common prefixes from an ISBN.
func NormalizeValue ¶ added in v0.0.30
NormalizeValue returns a canonical form of an identifier value for storage, based on its type. ISBN-10/13 values are stripped of hyphens/spaces/prefixes; ASINs are uppercased; UUIDs are lowercased with any urn:uuid: prefix removed; all other types are returned with surrounding whitespace trimmed.
func ReconcileSources ¶ added in v0.0.51
func ReconcileSources(existing, incoming []*models.FileIdentifier) (unchanged bool)
ReconcileSources gives each incoming identifier the per-entry source it should be stored with, and reports whether the incoming collection is the same set of identifiers as the existing one.
An incoming entry whose (type, normalized value) already exists keeps the stored entry's source, because re-submitting an identifier says nothing new about where it came from. Every other entry keeps the source the caller assigned: manual for a hand-written value, or a plugin source for a Proposal Acceptance. Both sides are keyed on the normalized value so a stored value that predates normalization, or an incoming value the user typed with hyphens or in a different case, still matches.
The Edit form and Identify share this helper so per-entry provenance is preserved identically by both endpoints (ADR 0006).
func ValidateISBN10 ¶
ValidateISBN10 validates an ISBN-10 checksum. ISBN-10 uses modulo 11 with weights 10,9,8,7,6,5,4,3,2,1.
func ValidateISBN13 ¶
ValidateISBN13 validates an ISBN-13 checksum. ISBN-13 uses alternating weights of 1 and 3.
Types ¶
type Type ¶
type Type string
Type represents the type of identifier.
func DetectType ¶
DetectType determines the identifier type from a value and optional scheme. If the scheme is recognized, it takes precedence. Unknown or empty schemes fall through to value-based pattern matching so we still pick up identifiers emitted with vendor-specific scheme names (e.g. Calibre's "MOBI-ASIN", or arbitrary publisher tags) when the value itself is unambiguous.