Skip to content

bug(sdk): importing defineServices in a browser auto-registers the server KV cache provider #1462

Description

@rickylabs

Version

@netscript/sdk@0.0.5, Deno 2.9.5.

Problem

defineServices is exported only from the SDK root, but importing that root in browser-shared code also imports src/cache/mod.ts, whose top-level setCacheProvider(cacheQuery) registers the server KV cache provider. queryOptions() then sees hasCacheProvider() === true, takes the server cache path, and KvCacheStore dynamically imports @netscript/kv in a browser bundle.

Focused query imports do not have this side effect.

Minimal reproduction

deno eval --no-config --no-lock "import { hasCacheProvider } from 'jsr:@netscript/sdk@0.0.5'; console.log(hasCacheProvider())"
# true

deno eval --no-config --no-lock "import { hasCacheProvider } from 'jsr:@netscript/sdk@0.0.5/query'; console.log(hasCacheProvider())"
# false

The published package has no browser-safe ./presets/defineServices subpath.

Exact source chain

  • root mod.ts exports both defineServices and ./src/cache/mod.ts;
  • src/cache/mod.ts performs top-level setCacheProvider(cacheQuery);
  • src/query/query-factory.ts chooses its server cache path when hasCacheProvider() is true;
  • KvCacheStore.resolve() dynamically imports @netscript/kv.

Consumer impact

A consumer following the service-preset API in a dashboard/shared module silently changes query execution semantics and pulls a server KV adapter toward the client build. EIS-Chat must keep separate focused @netscript/sdk/client and /query imports instead of adopting the intended defineServices seam.

Expected

  • Export defineServices from a browser-safe, side-effect-free subpath; or make the SDK root side-effect-free.
  • Server bootstrap should explicitly opt into cache-provider registration.
  • Browser queryOptions() should use the typed client directly and never load @netscript/kv.

Acceptance

  • Browser/Vite import of the defineServices entry leaves hasCacheProvider() false.
  • Browser queryOptions().queryFn() calls an injected typed client and never loads @netscript/kv.
  • Production client chunks contain no server KV adapter.
  • defineFreshApp/server bootstrap still registers the provider explicitly.
  • Server cache miss/hit/invalidation tests remain green.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions