Skip to content

Phase 5, Task 1: Implement parseProperty() + Tests #78

Closed

Description

@Sam-Bolling

Task

Implement parseProperty() in a new property.ts file with 6 test cases covering full, minimal, and edge-case Property parsing.

ROADMAP Reference: Phase 5, Task 1 — parseProperty() + Tests (~1–1.5 hours, Low complexity)


Files to Create or Modify

File Action Est. Lines Purpose
src/ogc-api/csapi/formats/property.ts Create ~30–50 parseProperty() function — transforms flat Property JSON into typed Property object
src/ogc-api/csapi/formats/property.spec.ts Create ~80–120 Unit tests for parseProperty() — 6 test cases with spec-derived fixtures

Blueprint Reference

Follow the tolerant extraction pattern established by extractCSAPIFeature() in src/ogc-api/csapi/formats/geojson.ts (L392+):

  • Input guard (throw if not a non-null object)
  • Cast to Record<string, unknown>
  • Extract fields with type-safe fallbacks
  • Conditional spread for optional fields: ...(typeof obj.field === 'string' ? { field: obj.field } : {})
  • Return typed result using satisfies Property

Also reference the SensorML sub-parser structure in src/ogc-api/csapi/formats/sensorml/physical-system.ts (L504+) for the export function parse*(json: unknown): T signature pattern and JSDoc density.

Scope — What to Implement

parseProperty(json: unknown): Property

Implement a single exported function that transforms a raw JSON object from the /properties endpoint items array into a typed Property object.

Input shape (OGC 23-001, DerivedProperty schema — flat JSON, NOT a GeoJSON Feature):

{
  "uniqueId": "urn:x-ogc:def:property:noaa::AirTemperature",
  "label": "Air Temperature",
  "description": "Temperature of the ambient air",
  "baseProperty": "http://qudt.org/vocab/quantitykind/Temperature",
  "objectType": "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
  "statistic": "http://www.opengis.net/def/property/OGC/0/Mean",
  "links": [
    { "rel": "self", "href": "/properties/air-temp", "type": "application/json" }
  ]
}

Field transformations:

Field Source Type Target Type Transformation
id string | undefined string | undefined Direct pass-through (server-assigned, may be absent)
label string string Direct extraction; fall back to empty string
description string | undefined string | undefined Conditional extraction
uniqueId string string Direct extraction; fall back to empty string
baseProperty string string Direct extraction; fall back to empty string
objectType string | undefined string | undefined Conditional extraction
statistic string | undefined string | undefined Conditional extraction
links array | undefined ResourceLink[] | undefined Extract if array; omit if absent

Key constraints:

  • No validTime — Property is a DerivedProperty (SWE Common AbstractSweIdentifiable), which has no time field per OGC 23-001. Do NOT add validTime parsing. See validTime coverage analysis.
  • No GeoJSON wrapping — Property is the only Part 1 resource that is NOT a GeoJSON Feature. The input is a flat JSON object, not a Feature with properties and geometry.
  • Tolerant extraction — If a field is missing, use the interface default (empty string for required strings, undefined for optional fields). Never throw on malformed data — only throw when input is not an object.

Implementation sketch (from P5 Implementation Guide §4.1):

import type { Property, ResourceLink } from '../model.js';

export function parseProperty(json: unknown): Property {
  if (typeof json !== 'object' || json === null) {
    throw new Error('parseProperty: input must be a non-null object');
  }

  const obj = json as Record<string, unknown>;

  return {
    ...(typeof obj.id === 'string' ? { id: obj.id } : {}),
    label: typeof obj.label === 'string' ? obj.label : '',
    ...(typeof obj.description === 'string' ? { description: obj.description } : {}),
    uniqueId: typeof obj.uniqueId === 'string' ? obj.uniqueId : '',
    baseProperty: typeof obj.baseProperty === 'string' ? obj.baseProperty : '',
    ...(typeof obj.objectType === 'string' ? { objectType: obj.objectType } : {}),
    ...(typeof obj.statistic === 'string' ? { statistic: obj.statistic } : {}),
    ...(Array.isArray(obj.links) ? { links: obj.links as ResourceLink[] } : {}),
  } satisfies Property;
}

JSDoc Requirements

  • Document parseProperty() with:
    • @param json — describes the expected input (raw JSON from /properties items)
    • @returns — Property object with extracted fields
    • @throws — when input is not a non-null object
    • Usage example showing a successful parse
    • Note that no live server currently returns Property data (spec-derived only)
  • Add @see link to OGC 23-001 Property resources section
  • Follow the JSDoc density in src/ogc-api/csapi/formats/sensorml/physical-system.ts (parsePhysicalSystem)

Testing Requirements

  • Create src/ogc-api/csapi/formats/property.spec.ts (~80–120 lines)
  • 6 test cases:
    1. Full Property — all fields present → all fields extracted correctly
    2. Minimal Property — only uniqueId, label, baseProperty → optional fields omitted from output
    3. Missing optional fields — description, objectType, statistic absent → undefined in output
    4. Empty links array — links: [] → empty array in output (not omitted)
    5. Non-object input — null, 42, "string" → throws Error
    6. id absent — no id field (server-assigned, may not be present) → id not in output
  • Fixtures: Spec-derived from OGC 23-001 DerivedProperty schema. No real server returns Property data (confirmed Smoke Test Phase 2.2: Deployments Methods #6). Document fixture source in test file comments.
  • Follow test patterns from existing SensorML parser tests (e.g., physical-system.spec.ts) — describe / it structure, pure function testing, no mocking needed.

Scope — What NOT to Touch

  • ❌ Do NOT modify src/ogc-api/csapi/model.ts — the Property interface already exists (L401–417)
  • ❌ Do NOT add validTime parsing — Property has no validTime per OGC 23-001
  • ❌ Do NOT create part2.ts — that belongs to Task 2
  • ❌ Do NOT create schema-response.ts — that belongs to Task 7
  • ❌ Do NOT modify any SensorML files — that belongs to Task 8
  • ❌ Do NOT modify QueryBuilder call sites or response.ts — that belongs to Task 9 (integration wiring)
  • ❌ Do NOT modify index.ts exports — integration wiring is Task 9's scope
  • ❌ Do NOT modify files outside the "Files to Create or Modify" table above
  • ❌ Do NOT refactor existing code unless required to complete this task

Acceptance Criteria

  • src/ogc-api/csapi/formats/property.ts exists with parseProperty() function extracting all 8 fields per the field transformations table
  • All new code has complete JSDoc documentation (function-level + @see link)
  • src/ogc-api/csapi/formats/property.spec.ts exists with 6 test cases covering full, minimal, missing optional, empty links, non-object throw, and absent id
  • Existing tests still pass (npm test)
  • No lint errors
  • >80% code coverage on property.ts
  • No validTime parsing present in the implementation
  • Fixtures are documented as spec-derived (OGC 23-001 DerivedProperty schema)

Dependencies

Blocked by: Nothing (first task — no dependencies)
Blocks: Task 9 (Integration Wiring — needs all parsers to exist)


Operational Constraints

⚠️ MANDATORY: Before starting work on this issue, review docs/governance/AI_OPERATIONAL_CONSTRAINTS.md.

For Phase 5 issues: Review the P5 Implementation Guide §4.1 for parseProperty() field transformations, input shape, implementation sketch, and test cases. Review Phase 5 parser constraints below.

Key constraints for this task:

  • Precedence: OGC specifications → AI Collaboration Agreement → This issue description → Existing code → Conversational context
  • No scope expansion: Do not infer unstated requirements or add unrequested features
  • No refactoring: Do not rename, restructure, or "improve" code outside this issue's scope
  • Minimal diffs: Prefer the smallest change that satisfies the acceptance criteria
  • Ask when unclear: If intent is ambiguous, stop and ask for clarification

Phase 5 Parser Constraints

  • Tolerant extraction (Postel's Law): Never gate on missing fields. If a field is absent, use the interface default (empty string for required strings, undefined for optional fields). Never throw on malformed data — only throw when input is not an object.
  • Property has no validTime: This is correct per OGC 23-001 (DerivedProperty schema). Do not add validTime parsing. See validTime coverage analysis.
  • No server returns Property data: Both OSH and 52North return 0 items for /properties (confirmed ST#6). Fixtures must be spec-derived from the OGC DerivedProperty schema, not from real server responses.
  • Cross-reference fields are NOT extracted: Not applicable to Property (Property has no @id / @link cross-reference fields).
  • Model interface already exists: The Property interface is defined in model.ts L401–417. Do not redefine or modify it.
  • Consistent patterns: Follow the same error handling, conditional spread, and satisfies typing patterns as extractCSAPIFeature() in geojson.ts.

References

Primary References (must read)

# Document Section/Lines What It Provides
1 P5 Implementation Guide §4.1 parseProperty() (L168–230) Input shape, field transformations, implementation sketch, test cases
2 P5 ROADMAP Task 1 Task definition, deliverables, dependencies
3 P5 Contribution Goal Full document Scope boundary — confirms what is/isn't in Phase 5
4 Parsing Coverage Audit Gap #1 (L186) Source of truth for the gap being addressed

Blueprint References (pattern to follow)

# Document What It Provides
1 src/ogc-api/csapi/formats/geojson.ts L392–472 extractCSAPIFeature() — tolerant extraction pattern, input guard, conditional spread, satisfies typing
2 src/ogc-api/csapi/formats/sensorml/physical-system.ts L504+ parsePhysicalSystem() — parse*(json: unknown): T signature pattern, JSDoc density

Upstream Type/Import References

# Document What to Import
1 src/ogc-api/csapi/model.ts L401–417 Property, ResourceLink interfaces

Specification References (for @see links and field accuracy)

# Document Use
1 OGC API - Connected Systems Part 1 (23-001) Property resource definition, DerivedProperty schema

Research References (context)

# Document What It Provides
1 validTime coverage analysis Why Property has no validTime — full inheritance chain analysis

Convention Quick Reference

Rule Example
Use .js extension for relative imports import { X } from './file.js'
Use import type for interfaces/types import type { Property, ResourceLink } from '../model.js'
Three-tier hierarchy: import from lower tiers only shared → ogc-api → csapi
Named exports for types and utilities export function parseProperty(...)
HTTP mocking: globalThis.fetch = jest.fn() Not needed — parser is a pure function
Meaningful tests only Verify field values, not that code runs without throwing

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions