Skip to content

Add CloudKit record name validation to DataSourceMetadata #133

@leogdion

Description

@leogdion

Severity: 🟡 Minor
File: Sources/BushelFoundation/DataSourceMetadata.swift:60
PR: #126

Issue

The recordName computed property is composed from sourceName and recordTypeName without validation. CloudKit record names have strict requirements:

  • Must be ASCII-only
  • No longer than 255 characters
  • Cannot contain empty strings

While current test values are well-formed, the code should validate that sourceName and recordTypeName meet these constraints.

Current Code

public var recordName: String {
  "metadata-\(sourceName)-\(recordTypeName)"
}

Recommendation

Add input validation during initialization to ensure:

  1. Neither sourceName nor recordTypeName is empty
  2. Each string's unicodeScalars are ASCII (e.g., unicodeScalars.allSatisfy { $0.isASCII })
  3. The full recordName does not exceed 255 bytes/characters

Implement this in the DataSourceMetadata initializer and fail fast (throw a validation error or use precondition) so invalid values cannot be instantiated.

CodeRabbit Suggestion

In @Sources/BushelFoundation/DataSourceMetadata.swift around lines 57-60,
Validate sourceName and recordTypeName at construction instead of only in
recordName: ensure neither is empty, each string's unicodeScalars are ASCII
(e.g. unicodeScalars.allSatisfy { $0.isASCII }), and that the full recordName
computed in recordName ("metadata-\(sourceName)-\(recordTypeName)") does not
exceed 255 bytes/characters; implement this in the DataSourceMetadata
initializer (init(sourceName:recordTypeName:)) and fail fast (throw a validation
error or use precondition) so invalid values cannot be instantiated, and keep
the computed var recordName as-is.

Source: CodeRabbit AI review of PR #126

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions