UNPKG

node-test-bed-adapter

Version:

An adapter to connect a node.js application to the Test-bed's Common Information Space or Common Simulation Space.

122 lines (121 loc) 3.93 kB
import avsc from 'avsc'; import { ITestBedOptions } from '../models/index.mjs'; export interface ISchema { version: number | string; topic: string; type?: avsc.Type; schemaType: string; schemaTopicRaw: string; responseRaw: { schema: string; id: number; }; } export interface ISchemaTopic { version: string; schemaTopic: string; } export type SchemaInfo = { srId: number; type: avsc.Type; }; export declare class SchemaRegistry { private options; /** * A dict containing the instance of the "avsc" package, and key the SR schema id. * Keys are in the form 'schema-[SCHEMA_ID]' */ schemaTypeById: { [key: string]: avsc.Type; }; /** * A dict containing all the key schemas with key the bare topic name and * value the instance of the "avsc" package. */ keySchemas: { [topic: string]: SchemaInfo; }; /** * A dict containing all the value schemas with value the instance of the "avsc" package. * It not only contains schemas for topics with key/value pairs, but also for topics with * only a schema. */ valueSchemas: { [topic: string]: SchemaInfo; }; private log; private selectedTopics; private fetchAllVersions; /** List of schema topics with -value, -key annotations */ private schemaTopics; /** * A dict containing all the value schemas metadata, with key the bare * topic name and value the SR response on that topic: * * 'subject' {string} The full topic name, including the '-value' suffix. * 'version' {number} The version number of the schema. * 'id' {number} The schema id. * 'schema' {string} JSON serialized schema. * * @type {Object} */ private schemaMeta; private wrapUnions; constructor(options: ITestBedOptions); init(): Promise<void>; /** Register a new topic */ registerNewTopic(newTopic: string): Promise<boolean>; unregisterTopic(topic: string): void; private processSelectedTopics; /** Get all the topics that are registered with the schema registry */ private fetchAllSchemaTopics; private registerSchemaLatest; private storeTopics; /** Fetch the latest version of a topic */ private fetchLatestVersion; /** * After the initial schema registration is complete check if it is required to * fetch all the past versions for each topic and concatenate those results. * * @param {ISchema[]} registeredSchemas The registered schemas from the first op. * @return {Promise(Array.<Object>)} The same schemas plus all the versions if requested. * @private */ private checkForAllVersions; private wrapUnionType; /** * Register the provided schema locally using avro. * * @param {Object} schemaObj Schema object as produced by fetchSchema(). * @return {Promise(Array.<Object>)} A Promise with the object received * augmented with the "type" property which stores the parsed avro schema. * @private */ private registerSchema; /** * Fetch all available versions for a subject from the SR. * * @return {Promise(Array.<Object>)} A Promise with an array of objects * containing the topic name and version number. * @private */ private fetchAllSchemaVersions; /** * Flatten the array of arrays produced by fetchAllSchemaVersions(). * * @param results Results as produced by fetchAllSchemaVersions(). * @return Flattened results. * @private */ private flattenResults; /** * A master wrapper method to determine if all topics or just specific ones * need to be fetched. * * @return A Promise with an arrray of string topics. * @private */ private fetchTopics; private fetchSchema; private suppressAxiosError; }