@confluentinc/schemaregistry
Version:
Node.js client for Confluent Schema Registry
437 lines (436 loc) • 17.4 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 RulePhase {
MIGRATION = "MIGRATION",
DOMAIN = "DOMAIN",
ENCODING = "ENCODING"
}
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;
guid?: string;
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[];
encodingRules?: Rule[];
enableAt?: string;
}
/**
* 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;
}
/**
* LifecyclePolicy represents the lifecycle policy for an association
*/
export declare enum LifecyclePolicy {
STRONG = "STRONG",
WEAK = "WEAK"
}
/**
* Association represents an association between a subject and a resource
*/
export interface Association {
subject: string;
guid?: string;
resourceName: string;
resourceNamespace: string;
resourceId?: string;
resourceType: string;
associationType: string;
lifecycle?: LifecyclePolicy;
frozen?: boolean;
}
/**
* AssociationInfo represents association info returned in a response
*/
export interface AssociationInfo {
subject?: string;
associationType?: string;
lifecycle?: LifecyclePolicy;
frozen?: boolean;
schema?: SchemaInfo;
}
/**
* AssociationCreateOrUpdateInfo represents an association to create or update
*/
export interface AssociationCreateOrUpdateInfo {
subject?: string;
associationType?: string;
lifecycle?: LifecyclePolicy;
frozen?: boolean;
schema?: SchemaInfo;
normalize?: boolean;
}
/**
* AssociationCreateOrUpdateRequest represents a request to create or update associations
*/
export interface AssociationCreateOrUpdateRequest {
resourceName?: string;
resourceNamespace?: string;
resourceId?: string;
resourceType?: string;
associations?: AssociationCreateOrUpdateInfo[];
}
/**
* AssociationResponse represents a response from creating/updating associations
*/
export interface AssociationResponse {
resourceName?: string;
resourceNamespace?: string;
resourceId?: string;
resourceType?: string;
associations?: AssociationInfo[];
}
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>;
getByGuid(guid: string, format?: string): Promise<SchemaInfo>;
getId(subject: string, schema: SchemaInfo, normalize: boolean): Promise<number>;
getIdFullResponse(subject: string, schema: SchemaInfo, normalize: boolean): Promise<SchemaMetadata>;
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>;
getAssociationsByResourceName(resourceName: string, resourceNamespace: string, resourceType: string | null, associationTypes: string[], lifecycle: LifecyclePolicy | null, offset: number, limit: number): Promise<Association[]>;
createAssociation(request: AssociationCreateOrUpdateRequest): Promise<AssociationResponse>;
deleteAssociations(resourceId: string, resourceType: string | null, associationTypes: string[] | null, cascadeLifecycle: boolean): Promise<void>;
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 idToSchemaInfoCache;
private guidToSchemaInfoCache;
private infoToSchemaCache;
private latestToSchemaCache;
private schemaToVersionCache;
private versionToSchemaCache;
private metadataToSchemaCache;
private schemaToIdMutex;
private idToSchemaInfoMutex;
private guidToSchemaInfoMutex;
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 a schema by GUID.
* @param guid - The schema GUID.
* @param format - The format of the schema.
*/
getByGuid(guid: string, 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 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.
*/
getIdFullResponse(subject: string, schema: SchemaInfo, normalize?: boolean): Promise<SchemaMetadata>;
/**
* 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>;
/**
* Get associations by resource name.
* @param resourceName - The resource name to query.
* @param resourceNamespace - The resource namespace.
* @param resourceType - The resource type (optional).
* @param associationTypes - The association types to filter by.
* @param lifecycle - The lifecycle policy to filter by (optional).
* @param offset - The offset for pagination.
* @param limit - The limit for pagination (-1 for no limit).
*/
getAssociationsByResourceName(resourceName: string, resourceNamespace: string, resourceType: string | null, associationTypes: string[], lifecycle: LifecyclePolicy | null, offset: number, limit: number): Promise<Association[]>;
/**
* Create an association between a subject and a resource.
* @param request - The association create or update request.
*/
createAssociation(request: AssociationCreateOrUpdateRequest): Promise<AssociationResponse>;
/**
* Delete associations for a resource.
* @param resourceId - The resource identifier.
* @param resourceType - The type of resource (e.g., "topic"). Can be null.
* @param associationTypes - The types of associations to delete (e.g., "key", "value"). Can be null to delete all.
* @param cascadeLifecycle - Whether to cascade the lifecycle policy to dependent schemas.
*/
deleteAssociations(resourceId: string, resourceType: string | null, associationTypes: string[] | null, cascadeLifecycle: boolean): Promise<void>;
/**
* 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>;
addToGuidToSchemaInfoCache(guid: string, schema: SchemaInfo): Promise<void>;
getInfoToSchemaCacheSize(): Promise<number>;
getSchemaToVersionCacheSize(): Promise<number>;
getVersionToSchemaCacheSize(): Promise<number>;
getIdToSchemaInfoCacheSize(): Promise<number>;
getGuidToSchemaInfoCacheSize(): Promise<number>;
}