UNPKG

@awesomeniko/kafka-trail

Version:

A Node.js library for managing message queue with Kafka

99 lines (98 loc) 3.79 kB
import { GetSchemaVersionCommand } from "@aws-sdk/client-glue"; import type { KTCodec, KTSchemaMeta } from "../schema-codec.js"; import type { AjvCompilerLike, AjvSchemaLike } from "./ajv-adapter.js"; import type { ZodSchemaLike } from "./zod-adapter.js"; export type AwsGlueSchemaLookup = { registryName?: string; schemaName: string; schemaArn?: string; schemaVersionId?: string; schemaVersionNumber?: string | number; }; export type AwsGlueSchemaFetcherResult = { schemaDefinition: string | AjvSchemaLike; schemaName?: string; schemaVersionId?: string; schemaVersionNumber?: string | number; schemaArn?: string; dataFormat?: string; }; export type AwsGlueSchemaFetcherLike = { getSchema: (lookup: AwsGlueSchemaLookup) => Promise<AwsGlueSchemaFetcherResult>; }; export type AwsGlueCodecCacheOptions = { store?: Map<string, AwsGlueResolvedSchemaCacheEntry>; ttlMs?: number; }; export type AwsGlueResolvedSchemaCacheEntry = { schema: AjvSchemaLike; schemaMeta: KTSchemaMeta; expiresAt: number | null; }; export type AwsGlueCompiledSchemaCacheEntry = AwsGlueResolvedSchemaCacheEntry; export type AwsGlueClientLike = { send: (command: GetSchemaVersionCommand) => Promise<{ SchemaDefinition?: string; SchemaVersionId?: string; VersionNumber?: number; SchemaArn?: string; DataFormat?: string; }>; destroy?: () => void; }; export type AwsGlueStaticCredentials = { accessKeyId: string; secretAccessKey: string; sessionToken?: string; }; export type AwsGlueAdapterPreload = { schemas: AwsGlueSchemaLookup[]; cache?: AwsGlueCodecCacheOptions; }; export type CreateAwsGlueSchemaRegistryAdapterParams = { region: string; credentials?: AwsGlueStaticCredentials; profile?: string; endpoint?: string; preload?: AwsGlueAdapterPreload; client?: AwsGlueClientLike; }; export type AwsGlueSchemaRegistryAdapter = AwsGlueSchemaFetcherLike & { preloadSchemas: (schemas: AwsGlueSchemaLookup[], options?: { cache?: AwsGlueCodecCacheOptions; }) => Promise<void>; destroy: () => void; }; type CreateAwsGlueCodecParamsBase = { glue: AwsGlueSchemaFetcherLike; schema: AwsGlueSchemaLookup; schemaMeta?: KTSchemaMeta; cache?: AwsGlueCodecCacheOptions; }; export type AwsGlueZodSchemaFactoryParams = { schema: AjvSchemaLike; lookup: AwsGlueSchemaLookup; fetchedSchema: AwsGlueSchemaFetcherResult; schemaMeta: KTSchemaMeta; }; export type AwsGlueZodSchemaFactory<Payload extends object> = (params: AwsGlueZodSchemaFactoryParams) => ZodSchemaLike<Payload>; type CreateAwsGlueCodecWithAjvParams<Payload extends object> = CreateAwsGlueCodecParamsBase & { validator?: "ajv"; ajv: AjvCompilerLike<Payload>; serialize?: (data: Payload) => string; parse?: (data: string) => unknown; }; type CreateAwsGlueCodecWithZodParams<Payload extends object> = CreateAwsGlueCodecParamsBase & { validator: "zod"; zodSchemaFactory: AwsGlueZodSchemaFactory<Payload>; }; type CreateAwsGlueCodecParams<Payload extends object> = CreateAwsGlueCodecWithAjvParams<Payload> | CreateAwsGlueCodecWithZodParams<Payload>; export declare const clearAwsGlueSchemaCache: (store?: Map<string, AwsGlueResolvedSchemaCacheEntry>) => void; export declare const preloadAwsGlueSchemas: (params: { glue: AwsGlueSchemaFetcherLike; schemas: AwsGlueSchemaLookup[]; cache?: AwsGlueCodecCacheOptions; }) => Promise<void>; export declare const createAwsGlueSchemaRegistryAdapter: (params: CreateAwsGlueSchemaRegistryAdapterParams) => Promise<AwsGlueSchemaRegistryAdapter>; export declare const createAwsGlueCodec: <Payload extends object>(params: CreateAwsGlueCodecParams<Payload>) => Promise<KTCodec<Payload>>; export {};