0.0.9 • Published 8 months ago

ts-schemaregistry v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

npm badge

ts-schemaregistry

is a fully typed REST API client for the confluent-schema-registry. It enables seamless interaction with the Confluent Schema Registry service using TypeScript. Build with zod, ts-rest, and axios.

Features

  • Type-safe API interactions with the Confluent Schema Registry.
  • Validation of request and response payloads using Zod schemas.
  • Simple and easy-to-use interface for managing schemas.
  • Built-in confluent errors for easy error handling.

Usage

Create the client using the SchemaRegistryClient class. This class exposes the complete and type-safe API and API-contract of the Confluent Schema Registry.

import { SchemaRegistryClient } from 'ts-schemaregistry';

const registry = new SchemaRegistryClient({
  baseUrl: 'http://localhost:8081',
});

A simple get request to list all subjects can be done like this. The result is typed with statuscodes and response bodies. Therefore, the type can be narrowed down by checking the statuscode.

const result = await registry.client
    .subjects.get();

if(result.status === 200) {// result.body as z.array(z.string)
  console.log(result.body) // ['subject1', 'subject2', ...]
} else if(result.status === 404) { // result.body as SchemaRegistryErrors[40401]
  console.log(result.body) // { errorCode: 40401, message: 'Subject not found.' }
}

The type of the request and response can be inferred from the API-contract.

const request: SchemaRegistryClientInferRequest<
    typeof this.registry.contract
        .subjects.subject.versions.version.get
> = {
    params: { 
        subject: subjectName, 
        version: version 
    },
};

const result = await this.registry.client
    .subjects.subject.versions.version.get(request);

if(result.status === 200) { 
    // Do something with result.body
} else if(result.status === 404) {
    //Throw a built-in ConfluentError with the request and response
    throw new ConfluentError(
        this.registry.contract
            .subjects.subject.versions.version.get,
        request,
        response,
    );
}

Future Work v1

  • Bundling & Polishing & Documenting & Testing
  • Extend types for Metadata, Rules, and Raw Schemas
0.0.9

8 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago