@confluentinc/schemaregistry
Version:
Node.js client for Confluent Schema Registry
322 lines (321 loc) • 12.6 kB
TypeScript
import { ClientConfig } from './rest-service';
export declare enum Compatibility {
NONE = "NONE",
BACKWARD = "BACKWARD",
FORWARD = "FORWARD",
FULL = "FULL",
BACKWARD_TRANSITIVE = "BACKWARD_TRANSITIVE",
FORWARD_TRANSITIVE = "FORWARD_TRANSITIVE",
FULL_TRANSITIVE = "FULL_TRANSITIVE"
}
export interface CompatibilityLevel {
compatibility?: Compatibility;
compatibilityLevel?: Compatibility;
}
/**
* Rule represents a data contract rule
*/
export interface Rule {
name: string;
doc?: string;
kind?: string;
mode?: RuleMode;
type: string;
tags?: string[];
params?: {
[key: string]: string;
};
expr?: string;
onSuccess?: string;
onFailure?: string;
disabled?: boolean;
}
export declare enum RuleMode {
UPGRADE = "UPGRADE",
DOWNGRADE = "DOWNGRADE",
UPDOWN = "UPDOWN",
WRITE = "WRITE",
READ = "READ",
WRITEREAD = "WRITEREAD"
}
/**
* SchemaInfo represents a schema and its associated information
*/
export interface SchemaInfo {
schema: string;
schemaType?: string;
references?: Reference[];
metadata?: Metadata;
ruleSet?: RuleSet;
}
export declare function minimize(info: SchemaInfo): SchemaInfo;
/**
* SchemaMetadata extends SchemaInfo with additional metadata
*/
export interface SchemaMetadata extends SchemaInfo {
id: number;
subject?: string;
version?: number;
}
/**
* Reference represents a schema reference
*/
export interface Reference {
name: string;
subject: string;
version: number;
}
/**
* Metadata represents user-defined metadata
*/
export interface Metadata {
tags?: {
[key: string]: string[];
};
properties?: {
[key: string]: string;
};
sensitive?: string[];
}
/**
* RuleSet represents a data contract rule set
*/
export interface RuleSet {
migrationRules?: Rule[];
domainRules?: Rule[];
}
/**
* ServerConfig represents config params for Schema Registry
*/
export interface ServerConfig {
alias?: string;
normalize?: boolean;
compatibility?: Compatibility;
compatibilityLevel?: Compatibility;
compatibilityGroup?: string;
defaultMetadata?: Metadata;
overrideMetadata?: Metadata;
defaultRuleSet?: RuleSet;
overrideRuleSet?: RuleSet;
}
export interface isCompatibleResponse {
is_compatible: boolean;
}
/**
* Client is an interface for clients interacting with the Confluent Schema Registry.
* The Schema Registry's REST interface is further explained in Confluent's Schema Registry API documentation
* https://github.com/confluentinc/schema-registry/blob/master/client/src/main/java/io/confluent/kafka/schemaregistry/client/SchemaRegistryClient.java
*/
export interface Client {
config(): ClientConfig;
register(subject: string, schema: SchemaInfo, normalize: boolean): Promise<number>;
registerFullResponse(subject: string, schema: SchemaInfo, normalize: boolean): Promise<SchemaMetadata>;
getBySubjectAndId(subject: string, id: number, format?: string): Promise<SchemaInfo>;
getId(subject: string, schema: SchemaInfo, normalize: boolean): Promise<number>;
getLatestSchemaMetadata(subject: string, format?: string): Promise<SchemaMetadata>;
getSchemaMetadata(subject: string, version: number, deleted: boolean, format?: string): Promise<SchemaMetadata>;
getLatestWithMetadata(subject: string, metadata: {
[key: string]: string;
}, deleted: boolean, format?: string): Promise<SchemaMetadata>;
getAllVersions(subject: string): Promise<number[]>;
getVersion(subject: string, schema: SchemaInfo, normalize: boolean, deleted: boolean): Promise<number>;
getAllSubjects(): Promise<string[]>;
deleteSubject(subject: string, permanent: boolean): Promise<number[]>;
deleteSubjectVersion(subject: string, version: number, permanent: boolean): Promise<number>;
testSubjectCompatibility(subject: string, schema: SchemaInfo): Promise<boolean>;
testCompatibility(subject: string, version: number, schema: SchemaInfo): Promise<boolean>;
getCompatibility(subject: string): Promise<Compatibility>;
updateCompatibility(subject: string, update: Compatibility): Promise<Compatibility>;
getDefaultCompatibility(): Promise<Compatibility>;
updateDefaultCompatibility(update: Compatibility): Promise<Compatibility>;
getConfig(subject: string): Promise<ServerConfig>;
updateConfig(subject: string, update: ServerConfig): Promise<ServerConfig>;
getDefaultConfig(): Promise<ServerConfig>;
updateDefaultConfig(update: ServerConfig): Promise<ServerConfig>;
clearLatestCaches(): void;
clearCaches(): void;
close(): void;
}
/**
* SchemaRegistryClient is a client for interacting with the Confluent Schema Registry.
* This client will cache responses from Schema Registry to reduce network requests.
*/
export declare class SchemaRegistryClient implements Client {
private clientConfig;
private restService;
private schemaToIdCache;
private idToSchemaInfoCache;
private infoToSchemaCache;
private latestToSchemaCache;
private schemaToVersionCache;
private versionToSchemaCache;
private metadataToSchemaCache;
private schemaToIdMutex;
private idToSchemaInfoMutex;
private infoToSchemaMutex;
private latestToSchemaMutex;
private schemaToVersionMutex;
private versionToSchemaMutex;
private metadataToSchemaMutex;
/**
* Create a new Schema Registry client.
* @param config - The client configuration.
*/
constructor(config: ClientConfig);
static newClient(config: ClientConfig): Client;
config(): ClientConfig;
/**
* Register a schema with the Schema Registry and return the schema ID.
* @param subject - The subject under which to register the schema.
* @param schema - The schema to register.
* @param normalize - Whether to normalize the schema before registering.
*/
register(subject: string, schema: SchemaInfo, normalize?: boolean): Promise<number>;
/**
* Register a schema with the Schema Registry and return the full response.
* @param subject - The subject under which to register the schema.
* @param schema - The schema to register.
* @param normalize - Whether to normalize the schema before registering.
*/
registerFullResponse(subject: string, schema: SchemaInfo, normalize?: boolean): Promise<SchemaMetadata>;
/**
* Get a schema by subject and ID.
* @param subject - The subject under which the schema is registered.
* @param id - The schema ID.
* @param format - The format of the schema.
*/
getBySubjectAndId(subject: string, id: number, format?: string): Promise<SchemaInfo>;
/**
* Get the ID for a schema.
* @param subject - The subject under which the schema is registered.
* @param schema - The schema whose ID to get.
* @param normalize - Whether to normalize the schema before getting the ID.
*/
getId(subject: string, schema: SchemaInfo, normalize?: boolean): Promise<number>;
/**
* Get the latest schema metadata for a subject.
* @param subject - The subject for which to get the latest schema metadata.
* @param format - The format of the schema.
*/
getLatestSchemaMetadata(subject: string, format?: string): Promise<SchemaMetadata>;
/**
* Get the schema metadata for a subject and version.
* @param subject - The subject for which to get the schema metadata.
* @param version - The version of the schema.
* @param deleted - Whether to include deleted schemas.
* @param format - The format of the schema.
*/
getSchemaMetadata(subject: string, version: number, deleted?: boolean, format?: string): Promise<SchemaMetadata>;
/**
* Get the latest schema metadata for a subject with the given metadata.
* @param subject - The subject for which to get the latest schema metadata.
* @param metadata - The metadata to match.
* @param deleted - Whether to include deleted schemas.
* @param format - The format of the schema.
*/
getLatestWithMetadata(subject: string, metadata: {
[key: string]: string;
}, deleted?: boolean, format?: string): Promise<SchemaMetadata>;
/**
* Get all versions of a schema for a subject.
* @param subject - The subject for which to get all versions.
*/
getAllVersions(subject: string): Promise<number[]>;
/**
* Get the version of a schema for a subject.
* @param subject - The subject for which to get the version.
* @param schema - The schema for which to get the version.
* @param normalize - Whether to normalize the schema before getting the version.
*/
getVersion(subject: string, schema: SchemaInfo, normalize?: boolean, deleted?: boolean): Promise<number>;
/**
* Get all subjects in the Schema Registry.
*/
getAllSubjects(): Promise<string[]>;
/**
* Delete a subject from the Schema Registry.
* @param subject - The subject to delete.
* @param permanent - Whether to permanently delete the subject.
*/
deleteSubject(subject: string, permanent?: boolean): Promise<number[]>;
/**
* Delete a version of a subject from the Schema Registry.
* @param subject - The subject to delete.
* @param version - The version to delete.
* @param permanent - Whether to permanently delete the version.
*/
deleteSubjectVersion(subject: string, version: number, permanent?: boolean): Promise<number>;
/**
* Test the compatibility of a schema with the latest schema for a subject.
* @param subject - The subject for which to test compatibility.
* @param schema - The schema to test compatibility.
*/
testSubjectCompatibility(subject: string, schema: SchemaInfo): Promise<boolean>;
/**
* Test the compatibility of a schema with a specific version of a subject.
* @param subject - The subject for which to test compatibility.
* @param version - The version of the schema for which to test compatibility.
* @param schema - The schema to test compatibility.
*/
testCompatibility(subject: string, version: number, schema: SchemaInfo): Promise<boolean>;
/**
* Get the compatibility level for a subject.
* @param subject - The subject for which to get the compatibility level.
*/
getCompatibility(subject: string): Promise<Compatibility>;
/**
* Update the compatibility level for a subject.
* @param subject - The subject for which to update the compatibility level.
* @param update - The compatibility level to update to.
*/
updateCompatibility(subject: string, update: Compatibility): Promise<Compatibility>;
/**
* Get the default/global compatibility level.
*/
getDefaultCompatibility(): Promise<Compatibility>;
/**
* Update the default/global compatibility level.
* @param update - The compatibility level to update to.
*/
updateDefaultCompatibility(update: Compatibility): Promise<Compatibility>;
/**
* Get the config for a subject.
* @param subject - The subject for which to get the config.
*/
getConfig(subject: string): Promise<ServerConfig>;
/**
* Update the config for a subject.
* @param subject - The subject for which to update the config.
* @param update - The config to update to.
*/
updateConfig(subject: string, update: ServerConfig): Promise<ServerConfig>;
/**
* Get the default/global config.
*/
getDefaultConfig(): Promise<ServerConfig>;
/**
* Update the default/global config.
* @param update - The config to update to.
*/
updateDefaultConfig(update: ServerConfig): Promise<ServerConfig>;
/**
* Clear the latest caches.
*/
clearLatestCaches(): void;
/**
* Clear all caches.
*/
clearCaches(): void;
/**
* Close the client.
*/
close(): Promise<void>;
addToInfoToSchemaCache(subject: string, schema: SchemaInfo, metadata: SchemaMetadata): Promise<void>;
addToSchemaToVersionCache(subject: string, schema: SchemaInfo, version: number): Promise<void>;
addToVersionToSchemaCache(subject: string, version: number, metadata: SchemaMetadata): Promise<void>;
addToIdToSchemaInfoCache(subject: string, id: number, schema: SchemaInfo): Promise<void>;
getInfoToSchemaCacheSize(): Promise<number>;
getSchemaToVersionCacheSize(): Promise<number>;
getVersionToSchemaCacheSize(): Promise<number>;
getIdToSchemaInfoCacheSize(): Promise<number>;
}