How eyelevelai/groundx-typescript works
Project type and purpose
• This is an open-source TypeScript SDK (client library) for interacting with the GroundX REST API.
• The library exports a single entry point (GroundXClient) plus a set of resource-specific clients, request/response types, core HTTP-fetch logic, and error classes.
File structure
• Top-level files: package.json, tsconfig.json, README.md, reference.md, jest.config.js, CI workflow.
• src/ contains:
• index.ts & version.ts: library entry point exports
• Client.ts & Wrapper.ts: public API surface (GroundXClient) wraps internal logic
• api/: resource clients and type definitions organized by resource (buckets, customer, documents, groups, health, search)
• core/: HTTP-fetcher abstraction (Fetcher, retries, timeout, request/response parsing, stream wrappers)
• errors/: custom error classes (GroundXError, GroundXTimeoutError)
• environments.ts: runtime feature flags
• tests/: unit tests for core fetcher logic and custom integration tests
Key README insights
• GroundXClient instantiation with apiKey, request options (headers, retries, timeout, abort signals).
• Public API methods (e.g., ingest, search, list buckets) delegate to resource-specific clients.
• Automatic retries, raw responses, runtime compatibility, custom fetch injection.
Main components
a. Entry point: GroundXClient (src/Client.ts)
b. Resource modules: api/resources/* (Client classes & requests)
c. Core HTTP layer: core/fetcher (Fetcher, makeRequest, retries, stream wrappers)
d. Types module: api/types (TypeScript interfaces for requests/responses)
e. Error handling: errors/GroundXError, GroundXTimeoutError
f. External systems:
• GroundX REST API (HTTP endpoint)
• Underlying HTTP client (node-fetch, global fetch, or user-supplied fetcher)
Relationships and interactions
• GroundXClient exposes methods that call Wrapper.ts
• Wrapper constructs request payloads and delegates to api/resources/* Client classes
• Resource clients build typed requests (using api/types) and call core/fetcher.makeRequest()
• core/fetcher resolves which Fetch implementation to use (Node, Undici, browser fetch), applies headers, timeout, retries
• HTTP request is sent over the network to the GroundX API endpoint
• Response body is parsed; on 2xx returns typed response, on error status codes throws GroundXError (or subclass)
• Consumers can call .asRaw() or pass abort signals/custom headers
Architectural patterns and design principles
• Layered architecture:
• Public API layer (Client.ts, Wrapper.ts)
• Resource client layer (api/resources)
• HTTP abstraction layer (core/fetcher)
• Type definitions layer (api/types)
• Error handling layer (errors)
• Dependency injection for Fetch client to support multiple runtimes
• Single responsibility: each module handles a specific concern
• Typed interfaces for strong compile-time guarantees