-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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"):
- returns
scheme._registryif set; - otherwise iterates over
scheme.APIand instantiates a provider for the first matching endpoint; result is cached bytype+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?
}
): ObjectSemantics
- If
preferRegistryis 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 === devBackward compatibility
- No behavior changes unless
optsare passed. - Existing code continues to prefer
scheme.APIexactly as today.
Docs
A short note in the README (or JSDoc) explaining:
- Why
registryForSchemeprefersscheme.API. - How to keep a dev run on dev (show
preferRegistryand “call your registry” pattern).