Skip to content

Phase 8 / D1b: Add endpoint.csapi(id) (additive — no removals) #183

Closed

Description

@Sam-Bolling

Sub-task of #179. Additive pass: introduce endpoint.csapi(id): Promise<CSAPIQueryBuilder> mirroring endpoint.edr(id). Does NOT re-privatize anything yet — the existing public surface stays intact so this lands as a pure addition.

Goal

Land a working endpoint.csapi(id) entry point with dynamic import and EndpointError wrapping. Tests for the new path. After this commit, both the new factory entry AND the old endpoint.root + manual factory call paths still work.

Tasks

  1. Add csapi(id: string): Promise<CSAPIQueryBuilder> method on OgcApiEndpoint mirroring the edr(id) shape exactly (same dynamic-import pattern, same error-wrapping convention).
  2. Use await import('./csapi/factory.js') to preserve issue P6 Task 6: Modify endpoint.ts — Remove CSAPI Coupling #122's dependency-edge contract.
  3. Wrap network-await throws with EndpointError (the piece deferred from B2).
  4. Add unit tests for the new method — happy path, unknown collection id, network error wrapping.
  5. Optional: smoke-test fixture exercising endpoint.csapi(id) against cs-go.

Acceptance

  • endpoint.csapi(id) exists, mirrors endpoint.edr(id) style
  • Dynamic import preserves P6 Task 6: Modify endpoint.ts — Remove CSAPI Coupling #122's contract (verified by existing import-graph test, if any)
  • Network errors thrown from inside the factory are instanceof EndpointError
  • New unit tests green
  • npm run typecheck / npm run lint / npm run test:browser all clean
  • No removals — root, getCollectionDocument, isCollectionInfo cast all still in place

Out of scope

  • Re-privatizing root or getCollectionDocument — that is D1c
  • Removing the isCollectionInfo runtime cast — that is D1c
  • Migrating any internal call site away from root — that is D1c

Dependencies

Blocks: D1c
Blocked by: D1a (recon fact sheet)

Parent

Refines #179.

Activity

  1. Sam-Bolling commented on Apr 30, 2026

    @Sam-Bolling
    Author

    D1b shipped in commit a41ce07.

    Changes:

    • src/ogc-api/endpoint.ts — added public async csapi(collectionId): Promise<CSAPIQueryBuilder> mirroring edr() but with: dynamic await import(''./csapi/factory.js'') and await import(''./csapi/helpers.js'') (preserves P6 Task 6: Modify endpoint.ts — Remove CSAPI Coupling #122''s dependency-edge contract), capability gate if (!(await this.hasConnectedSystems)) (no missing-await bug), and try/catch wrapping non-EndpointError failures into EndpointError while re-throwing existing EndpointErrors as-is (no double-wrap).
    • src/ogc-api/csapi/factory.ts — reshaped createCSAPIBuilder from async (endpoint, collectionId) to pure (collection: CSAPICollectionRef, resourceUrls: ReadonlyMap<string,string>): CSAPIQueryBuilder. No I/O, no await, no error paths. Defensive new Map(resourceUrls) for the ReadonlyMap contract.
    • src/ogc-api/csapi/factory.spec.ts — full rewrite. Removed all fake-OgcApiEndpoint test doubles. 5 value-shaped tests covering availableResources extraction, ReadonlyMap defensive copy, builder independence, and pure-synchronous behavior. Net: −136 LOC + 117 LOC = −19 LOC overall (cleaner than estimated).
    • src/ogc-api/endpoint.spec.ts — new describe(''csapi()'') block with 5 tests: happy path (3-resource collection), empty-resources collection, no-CSAPI-support EndpointError, network-error wrapping (TypeError → EndpointError), EndpointError pass-through (no double-wrap).

    Deviation from implementation guide §4.6 step 3: the guide''s snippet routes through getCollectionInfo(), but parseBaseCollectionInfo() at src/ogc-api/info.ts:130 strips links via destructuring (const { links, ...props } = doc;). CSAPIQueryBuilder.extractAvailableResources depends on collection.links, so routing through getCollectionInfo breaks availableResources. csapi() instead shapes the raw collection document into a CSAPICollectionRef directly:

    const collection: CSAPICollectionRef = {
      id: typeof collectionDoc.id === ''string'' ? collectionDoc.id : collectionId,
      title: typeof collectionDoc.title === ''string'' ? collectionDoc.title : undefined,
      links: Array.isArray(collectionDoc.links) ? collectionDoc.links : [],
    };

    This matches the guide''s intent (typed value-shaped factory input) while preserving correctness. Documented inline at the call site.

    Verification:

    • npx tsc --noEmit → clean
    • npx eslint src/ogc-api/{endpoint,csapi/factory}{,.spec}.ts → clean
    • npx prettier --check (same set) → clean
    • Scoped: npx jest "src/ogc-api/csapi/factory.spec" "src/ogc-api/endpoint.spec" → 94/94 passed
    • Regression: npx jest src/ogc-api src/shared/mime-type --forceExit → 1520/1520 passed, 36 suites

    Deferred to D1c (#184):

    • Re-privatize OgcApiEndpoint.root and getCollectionDocument
    • Delete isCollectionInfo from factory.ts (already gone — file no longer imports OgcApiEndpoint or OgcApiCollectionInfo since the reshape; the runtime narrowing now lives at the csapi() call site as plain field-shape construction)
    • Migrate endpoint.spec.ts:2868''s getCollectionDocument-shape assertion onto getCollectionInfo (or re-target via csapi() since csapi() now exposes the same path)

    Sub-finding for D1c: the isCollectionInfo cast is already gone as of this commit (git grep -n isCollectionInfo -- src/ returns 0 matches). D1c''s acceptance gate on that line is satisfied; D1c remains responsible for the visibility flips and the one external test-caller migration.

    Closing as completed. Proceeding to D1c/#184.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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