Skip to content

registryForScheme prefers scheme.API even when the app is configured to use dev. #71

@rodolv-commons

Description

@rodolv-commons

Summary

When an app initializes a ConceptApi registry pointing to a dev API (e.g., https://dev.bartoc.org/api/) and then loads schemes from BARTOC, subsequent operations on those schemes may silently use production instead. This happens because cdk.registryForScheme(scheme) (and helpers that call it, like scheme._getTop()) resolve a registry from scheme.API, which in BARTOC entries typically points at production (https://bartoc.org/api/).

This makes concept browsing/search inconsistent in dev bartoc.org: parts of the UI and scripts hit prod even though the global configuration says dev.

Expected behavior

If the application is configured to use ConceptApi against https://dev.bartoc.org/api/, all vocabulary operations during a dev run should hit dev unless explicitly overridden by the app.

Minimal reproduction

import { cdk, addAllProviders } from "cocoda-sdk"
addAllProviders()

const registry = cdk.initializeRegistry({
  provider: "ConceptApi",
  api: "https://dev.bartoc.org/api/",
})

;(async () => {
  const schemes = await registry.getSchemes({
    params: { uri: "http://bartoc.org/en/node/20002", limit: 10 },
  })
  const scheme = schemes[0]

  console.log("global registry _api:", registry._api)          // -> https://dev.bartoc.org/api/
  console.log("resolved _api:", cdk.registryForScheme(scheme)._api)
  // -> https://bartoc.org/api/ (from scheme.API)

  // This hits prod:
  try {
    const topViaScheme = await scheme._getTop()
    console.log("topViaScheme:", topViaScheme.length)
  } catch (e) {
    console.error(e)
  }

  // This hits dev (only because we explicitly call our registry):
  const topViaDev = await registry.getTop({ scheme })
  console.log("topViaDev:", topViaDev.length)
})()

Root cause

registryForScheme(scheme, dataType="concepts"):

  1. returns scheme._registry if set;
  2. otherwise iterates over scheme.API and instantiates a provider for the first matching endpoint; result is cached by type+url.

In environments where BARTOC records contain prod endpoints (as they should), the resolution pulls the prod provider even in dev runs.

Proposal (backward-compatible)

Add optional overrides to registryForScheme so apps can keep dev fully on dev without forking or monkey-patching.

API

registryForScheme(scheme, dataType: "concepts" | "mappings" | ... = "concepts",
  opts?: {
    /** If provided, return this registry immediately. */
    preferRegistry?
  }
): Object

Semantics

  • If preferRegistry is set, return it directly (highest priority).

Example usage

Prefer the app’s dev registry

const dev = cdk.initializeRegistry({ provider: "ConceptApi", api: "https://dev.bartoc.org/api/" })
const resolved = cdk.registryForScheme(scheme, "concepts", { preferRegistry: dev })
// resolved === dev

Backward compatibility

  • No behavior changes unless opts are passed.
  • Existing code continues to prefer scheme.API exactly as today.

Docs

A short note in the README (or JSDoc) explaining:

  • Why registryForScheme prefers scheme.API.
  • How to keep a dev run on dev (show preferRegistry and “call your registry” pattern).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions