@aws-lambda-powertools/kafka 0.0.0 → 2.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +299 -2
  3. package/lib/cjs/constants.d.ts +10 -0
  4. package/lib/cjs/constants.d.ts.map +1 -0
  5. package/lib/cjs/constants.js +12 -0
  6. package/lib/cjs/consumer.d.ts +42 -0
  7. package/lib/cjs/consumer.d.ts.map +1 -0
  8. package/lib/cjs/consumer.js +250 -0
  9. package/lib/cjs/deserializer/avro.d.ts +9 -0
  10. package/lib/cjs/deserializer/avro.d.ts.map +1 -0
  11. package/lib/cjs/deserializer/avro.js +25 -0
  12. package/lib/cjs/deserializer/json.d.ts +9 -0
  13. package/lib/cjs/deserializer/json.d.ts.map +1 -0
  14. package/lib/cjs/deserializer/json.js +25 -0
  15. package/lib/cjs/deserializer/primitive.d.ts +10 -0
  16. package/lib/cjs/deserializer/primitive.d.ts.map +1 -0
  17. package/lib/cjs/deserializer/primitive.js +16 -0
  18. package/lib/cjs/deserializer/protobuf.d.ts +12 -0
  19. package/lib/cjs/deserializer/protobuf.d.ts.map +1 -0
  20. package/lib/cjs/deserializer/protobuf.js +80 -0
  21. package/lib/cjs/errors.d.ts +27 -0
  22. package/lib/cjs/errors.d.ts.map +1 -0
  23. package/lib/cjs/errors.js +44 -0
  24. package/lib/cjs/index.d.ts +3 -0
  25. package/lib/cjs/index.d.ts.map +1 -0
  26. package/lib/cjs/index.js +7 -0
  27. package/lib/cjs/package.json +1 -0
  28. package/lib/cjs/types/index.d.ts +2 -0
  29. package/lib/cjs/types/index.d.ts.map +1 -0
  30. package/lib/cjs/types/index.js +2 -0
  31. package/lib/cjs/types/types.d.ts +244 -0
  32. package/lib/cjs/types/types.d.ts.map +1 -0
  33. package/lib/cjs/types/types.js +2 -0
  34. package/lib/esm/constants.d.ts +10 -0
  35. package/lib/esm/constants.d.ts.map +1 -0
  36. package/lib/esm/constants.js +9 -0
  37. package/lib/esm/consumer.d.ts +42 -0
  38. package/lib/esm/consumer.d.ts.map +1 -0
  39. package/lib/esm/consumer.js +214 -0
  40. package/lib/esm/deserializer/avro.d.ts +9 -0
  41. package/lib/esm/deserializer/avro.d.ts.map +1 -0
  42. package/lib/esm/deserializer/avro.js +19 -0
  43. package/lib/esm/deserializer/json.d.ts +9 -0
  44. package/lib/esm/deserializer/json.d.ts.map +1 -0
  45. package/lib/esm/deserializer/json.js +22 -0
  46. package/lib/esm/deserializer/primitive.d.ts +10 -0
  47. package/lib/esm/deserializer/primitive.d.ts.map +1 -0
  48. package/lib/esm/deserializer/primitive.js +13 -0
  49. package/lib/esm/deserializer/protobuf.d.ts +12 -0
  50. package/lib/esm/deserializer/protobuf.d.ts.map +1 -0
  51. package/lib/esm/deserializer/protobuf.js +77 -0
  52. package/lib/esm/errors.d.ts +27 -0
  53. package/lib/esm/errors.d.ts.map +1 -0
  54. package/lib/esm/errors.js +38 -0
  55. package/lib/esm/index.d.ts +3 -0
  56. package/lib/esm/index.d.ts.map +1 -0
  57. package/lib/esm/index.js +2 -0
  58. package/lib/esm/package.json +1 -0
  59. package/lib/esm/types/index.d.ts +2 -0
  60. package/lib/esm/types/index.d.ts.map +1 -0
  61. package/lib/esm/types/index.js +1 -0
  62. package/lib/esm/types/types.d.ts +244 -0
  63. package/lib/esm/types/types.d.ts.map +1 -0
  64. package/lib/esm/types/types.js +1 -0
  65. package/package.json +77 -19
  66. package/lib/index.d.ts +0 -0
  67. package/lib/index.js +0 -3
@@ -0,0 +1,214 @@
1
+ import { isNull, isRecord } from '@aws-lambda-powertools/commons/typeutils';
2
+ import { deserialize as deserializeJson } from './deserializer/json.js';
3
+ import { deserialize as deserializePrimitive } from './deserializer/primitive.js';
4
+ import { KafkaConsumerDeserializationError, KafkaConsumerError, KafkaConsumerMissingSchemaError, KafkaConsumerParserError, } from './errors.js';
5
+ /**
6
+ * Type guard to assert that the event is a valid {@link MSKEvent | `MSKEvent`}.
7
+ *
8
+ * @param event - The event to validate, expected to be an MSKEvent.
9
+ */
10
+ const assertIsMSKEvent = (event) => {
11
+ if (!isRecord(event) ||
12
+ !isRecord(event.records) ||
13
+ !Object.values(event.records).every((arr) => Array.isArray(arr))) {
14
+ throw new KafkaConsumerError('Event is not a valid MSKEvent. Expected an object with a "records" property.');
15
+ }
16
+ return true;
17
+ };
18
+ /**
19
+ * Deserialize Kafka message headers from an array of header objects.
20
+ *
21
+ * It returns `null` if the headers are `null`, or an array of header objects
22
+ * where each header value is decoded as a UTF-8 string.
23
+ *
24
+ * @param headers - An array of header objects, where each object maps header keys (string)
25
+ * to header values (`number[]`), representing the raw bytes of each header value -
26
+ * i.e. `[{ "headerKey": [104, 101, 108, 108, 111] }]`
27
+ */
28
+ const deserializeHeaders = (headers) => {
29
+ if (headers === null) {
30
+ return null;
31
+ }
32
+ const result = [];
33
+ for (const header of headers) {
34
+ const entries = [];
35
+ for (const [headerKey, headerValue] of Object.entries(header)) {
36
+ entries.push([headerKey, Buffer.from(headerValue).toString('utf-8')]);
37
+ }
38
+ result.push(Object.fromEntries(entries));
39
+ }
40
+ return result;
41
+ };
42
+ /**
43
+ * Deserialize a base64-encoded value using the provided schema configuration.
44
+ *
45
+ * It returns the deserialized value, which may be a string, object, or other type depending on the schema type.
46
+ *
47
+ * @param value - The base64-encoded string to deserialize.
48
+ * @param config - The schema configuration to use for deserialization. See {@link SchemaConfigValue | `SchemaConfigValue`}.
49
+ * If not provided, the value is decoded as a UTF-8 string.
50
+ */
51
+ const deserialize = ({ value, deserializer, config, schemaMetadata, }) => {
52
+ if (config === undefined) {
53
+ return deserializer(value);
54
+ }
55
+ if (config.type === 'json') {
56
+ return deserializer(value);
57
+ }
58
+ if (config.type === 'avro') {
59
+ if (!config.schema) {
60
+ throw new KafkaConsumerMissingSchemaError('Schema string is required for avro deserialization');
61
+ }
62
+ return deserializer(value, config.schema);
63
+ }
64
+ if (config.type === 'protobuf') {
65
+ if (!config.schema) {
66
+ throw new KafkaConsumerMissingSchemaError('Schema string is required for protobuf deserialization');
67
+ }
68
+ return deserializer(value, config.schema, schemaMetadata);
69
+ }
70
+ };
71
+ /**
72
+ * Get the deserializer function based on the provided type.
73
+ *
74
+ * @param type - The type of deserializer to use. Supported types are: `json`, `avro`, `protobuf`, or `undefined`.
75
+ * If `undefined`, it defaults to deserializing as a primitive string.
76
+ */
77
+ const getDeserializer = async (type) => {
78
+ if (!type) {
79
+ return deserializePrimitive;
80
+ }
81
+ if (type === 'json') {
82
+ return deserializeJson;
83
+ }
84
+ if (type === 'protobuf') {
85
+ const deserializer = await import('./deserializer/protobuf.js');
86
+ return deserializer.deserialize;
87
+ }
88
+ if (type === 'avro') {
89
+ const deserializer = await import('./deserializer/avro.js');
90
+ return deserializer.deserialize;
91
+ }
92
+ throw new KafkaConsumerDeserializationError(`Unsupported deserialization type: ${type}. Supported types are: json, avro, protobuf.`);
93
+ };
94
+ /**
95
+ * Parse a value against a provided schema using the `~standard` property for validation.
96
+ *
97
+ * @param value - The value to parse against the schema.
98
+ * @param schema - The schema to validate against, which should be a {@link StandardSchemaV1 | `Standard Schema V1`} object.
99
+ */
100
+ const parseSchema = (value, schema) => {
101
+ const result = schema['~standard'].validate(value);
102
+ /* v8 ignore start */
103
+ if (result instanceof Promise)
104
+ throw new KafkaConsumerParserError('Schema parsing supports only synchronous validation');
105
+ /* v8 ignore stop */
106
+ if (result.issues) {
107
+ throw new KafkaConsumerParserError('Schema validation failed', {
108
+ cause: result.issues,
109
+ });
110
+ }
111
+ return result.value;
112
+ };
113
+ /**
114
+ * Deserialize a single record from an MSK event.
115
+ *
116
+ * @param record - A single record from the MSK event.
117
+ * @param config - The schema configuration for deserializing the record's key and value.
118
+ */
119
+ const deserializeRecord = async (record, config) => {
120
+ const { key, value, headers, valueSchemaMetadata, keySchemaMetadata, ...rest } = record;
121
+ const { key: keyConfig, value: valueConfig } = config || {};
122
+ const deserializerKey = await getDeserializer(keyConfig?.type);
123
+ const deserializerValue = await getDeserializer(valueConfig?.type);
124
+ return {
125
+ ...rest,
126
+ get key() {
127
+ if (key === undefined || key === '') {
128
+ return undefined;
129
+ }
130
+ if (isNull(key))
131
+ return null;
132
+ const deserializedKey = deserialize({
133
+ value: key,
134
+ deserializer: deserializerKey,
135
+ config: keyConfig,
136
+ schemaMetadata: keySchemaMetadata,
137
+ });
138
+ return keyConfig?.parserSchema
139
+ ? parseSchema(deserializedKey, keyConfig.parserSchema)
140
+ : deserializedKey;
141
+ },
142
+ originalKey: key,
143
+ get value() {
144
+ const deserializedValue = deserialize({
145
+ value: value,
146
+ deserializer: deserializerValue,
147
+ config: valueConfig,
148
+ schemaMetadata: valueSchemaMetadata,
149
+ });
150
+ return valueConfig?.parserSchema
151
+ ? parseSchema(deserializedValue, valueConfig.parserSchema)
152
+ : deserializedValue;
153
+ },
154
+ originalValue: value,
155
+ get headers() {
156
+ return deserializeHeaders(headers);
157
+ },
158
+ originalHeaders: headers,
159
+ valueSchemaMetadata,
160
+ keySchemaMetadata,
161
+ };
162
+ };
163
+ /**
164
+ * Wrap a handler function to automatically deserialize and validate Kafka records from an MSK event.
165
+ *
166
+ * The returned function will:
167
+ * - Deserialize the key and value of each record using the provided schema config.
168
+ * - Validate the deserialized key and value using Zod schemas if provided.
169
+ * - Replace the `records` property in the event with an array of deserialized and validated records.
170
+ * - Call the original handler with the modified event and original context/arguments.
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * import { kafkaConsumer } from '@aws-lambda-powertools/kafka';
175
+ * import { z } from 'zod';
176
+ *
177
+ * const keySchema = z.string();
178
+ * const valueSchema = z.object({
179
+ * id: z.number(),
180
+ * });
181
+ *
182
+ * export const handler = kafkaConsumer<z.infer<keySchema>, z.infer<valueSchema>>(async (event, context) => {
183
+ * // event.records is now an array of deserialized and validated records
184
+ * for (const record of event.records) {
185
+ * console.log(record.key, record.value);
186
+ * }
187
+ * }, {
188
+ * key: { type: 'json', parserSchema: keySchema },
189
+ * value: { type: 'json', parserSchema: valueSchema },
190
+ * });
191
+ * ```
192
+ *
193
+ * @typeParam K - Optional type of the deserialized key - defaults to `unknown`.
194
+ * @typeParam V - Optional type of the deserialized value - defaults to `unknown`.
195
+ *
196
+ * @param handler - The original handler function to wrap. It should accept the deserialized event as its first argument.
197
+ * @param config - The schema configuration for deserializing and validating record keys and values.
198
+ */
199
+ const kafkaConsumer = (handler, config) => {
200
+ return async (event, context) => {
201
+ assertIsMSKEvent(event);
202
+ const consumerRecords = [];
203
+ for (const recordsArray of Object.values(event.records)) {
204
+ for (const record of recordsArray) {
205
+ consumerRecords.push((await deserializeRecord(record, config)));
206
+ }
207
+ }
208
+ return handler({
209
+ ...event,
210
+ records: consumerRecords,
211
+ }, context);
212
+ };
213
+ };
214
+ export { kafkaConsumer };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Deserialize an Avro message from a base64-encoded string using the provided Avro schema.
3
+ *
4
+ * @param data - The base64-encoded string representing the Avro binary data.
5
+ * @param schema - The Avro schema as a JSON string.
6
+ */
7
+ declare const deserialize: (data: string, schema: string) => unknown;
8
+ export { deserialize };
9
+ //# sourceMappingURL=avro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avro.d.ts","sourceRoot":"","sources":["../../../src/deserializer/avro.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,QAAA,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,YAUhD,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,19 @@
1
+ import avro from 'avro-js';
2
+ import { KafkaConsumerDeserializationError } from '../errors.js';
3
+ /**
4
+ * Deserialize an Avro message from a base64-encoded string using the provided Avro schema.
5
+ *
6
+ * @param data - The base64-encoded string representing the Avro binary data.
7
+ * @param schema - The Avro schema as a JSON string.
8
+ */
9
+ const deserialize = (data, schema) => {
10
+ try {
11
+ const type = avro.parse(schema);
12
+ const buffer = Buffer.from(data, 'base64');
13
+ return type.fromBuffer(buffer);
14
+ }
15
+ catch (error) {
16
+ throw new KafkaConsumerDeserializationError(`Failed to deserialize Avro message: ${error}, message: ${data}, schema: ${schema}`);
17
+ }
18
+ };
19
+ export { deserialize };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Deserialize a base64 encoded string into either a JSON object or plain string
3
+ *
4
+ * @param data - The base64 encoded string to deserialize
5
+ * @returns The deserialized data as either a JSON object or string
6
+ */
7
+ declare const deserialize: (data: string) => any;
8
+ export { deserialize };
9
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../src/deserializer/json.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,QAAA,MAAM,WAAW,GAAI,MAAM,MAAM,QAYhC,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { deserialize as deserializePrimitive } from './primitive.js';
2
+ /**
3
+ * Deserialize a base64 encoded string into either a JSON object or plain string
4
+ *
5
+ * @param data - The base64 encoded string to deserialize
6
+ * @returns The deserialized data as either a JSON object or string
7
+ */
8
+ const deserialize = (data) => {
9
+ const plainText = deserializePrimitive(data);
10
+ try {
11
+ // Attempt to parse the decoded data as JSON
12
+ // we assume it's a JSON but it can also be a string, we don't know
13
+ return JSON.parse(plainText);
14
+ }
15
+ catch (error) {
16
+ // If JSON parsing fails, log the error and return the decoded string
17
+ // in case we could not parse it we return the base64 decoded value
18
+ console.error(`Failed to parse JSON from base64 value: ${data}`, error);
19
+ return plainText;
20
+ }
21
+ };
22
+ export { deserialize };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Deserialize a base64-encoded primitive value (string).
3
+ *
4
+ * When customers don't provide a schema configuration, we assume the value is a base64-encoded string.
5
+ *
6
+ * @param data - The base64-encoded string to deserialize.
7
+ */
8
+ declare const deserialize: (data: string) => string;
9
+ export { deserialize };
10
+ //# sourceMappingURL=primitive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive.d.ts","sourceRoot":"","sources":["../../../src/deserializer/primitive.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,QAAA,MAAM,WAAW,GAAI,MAAM,MAAM,WAEhC,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { fromBase64 } from '@aws-lambda-powertools/commons/utils/base64';
2
+ const decoder = new TextDecoder('utf-8');
3
+ /**
4
+ * Deserialize a base64-encoded primitive value (string).
5
+ *
6
+ * When customers don't provide a schema configuration, we assume the value is a base64-encoded string.
7
+ *
8
+ * @param data - The base64-encoded string to deserialize.
9
+ */
10
+ const deserialize = (data) => {
11
+ return decoder.decode(fromBase64(data, 'base64'));
12
+ };
13
+ export { deserialize };
@@ -0,0 +1,12 @@
1
+ import type { ProtobufMessage, SchemaMetadata } from '../types/types.js';
2
+ /**
3
+ * Deserialize a Protobuf message from a base64-encoded string.
4
+ *
5
+ * @template T - The type of the deserialized message object.
6
+ *
7
+ * @param data - The base64-encoded string representing the Protobuf binary data.
8
+ * @param messageType - The Protobuf message type definition - see {@link Message | `Message`} from {@link https://www.npmjs.com/package/protobufjs | `protobufjs`}.
9
+ */
10
+ declare const deserialize: <T>(data: string, messageType: ProtobufMessage<T>, schemaMetadata: SchemaMetadata) => T;
11
+ export { deserialize };
12
+ //# sourceMappingURL=protobuf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf.d.ts","sourceRoot":"","sources":["../../../src/deserializer/protobuf.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOzE;;;;;;;GAOG;AACH,QAAA,MAAM,WAAW,GAAI,CAAC,EACpB,MAAM,MAAM,EACZ,aAAa,eAAe,CAAC,CAAC,CAAC,EAC/B,gBAAgB,cAAc,KAC7B,CAiDF,CAAC;AAuBF,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { BufferReader } from 'protobufjs';
2
+ import { KafkaConsumerDeserializationError } from '../errors.js';
3
+ /**
4
+ * Default order of varint types used in Protobuf to attempt deserializing Confluent Schema Registry messages.
5
+ */
6
+ const varintOrder = ['int32', 'sint32'];
7
+ /**
8
+ * Deserialize a Protobuf message from a base64-encoded string.
9
+ *
10
+ * @template T - The type of the deserialized message object.
11
+ *
12
+ * @param data - The base64-encoded string representing the Protobuf binary data.
13
+ * @param messageType - The Protobuf message type definition - see {@link Message | `Message`} from {@link https://www.npmjs.com/package/protobufjs | `protobufjs`}.
14
+ */
15
+ const deserialize = (data, messageType, schemaMetadata) => {
16
+ const buffer = Buffer.from(data, 'base64');
17
+ try {
18
+ if (schemaMetadata.schemaId === undefined) {
19
+ return messageType.decode(buffer, buffer.length);
20
+ }
21
+ /**
22
+ * If `schemaId` is longer than 10 chars, it's an UUID, otherwise it's a numeric ID.
23
+ *
24
+ * When this is the case, we know the schema is coming from Glue Schema Registry,
25
+ * and the first byte of the buffer is a magic byte that we need to remove before
26
+ * decoding the message.
27
+ */
28
+ if (schemaMetadata.schemaId.length > 10) {
29
+ // remove the first byte from the buffer
30
+ const reader = new BufferReader(buffer);
31
+ reader.uint32();
32
+ return messageType.decode(reader);
33
+ }
34
+ }
35
+ catch (error) {
36
+ throw new KafkaConsumerDeserializationError(`Failed to deserialize Protobuf message: ${error}, message: ${data}, messageType: ${messageType}`);
37
+ }
38
+ /**
39
+ * If schemaId is numeric, inferred from its length, we know it's coming from Confluent Schema Registry,
40
+ * so we need to remove the MessageIndex bytes.
41
+ * We don't know the type of the index, so we try both `int32` and `sint32`. If both fail, we throw an error.
42
+ */
43
+ try {
44
+ const newBuffer = clipConfluentSchemaRegistryBuffer(buffer, varintOrder[0]);
45
+ return messageType.decode(newBuffer);
46
+ }
47
+ catch (error) {
48
+ try {
49
+ const newBuffer = clipConfluentSchemaRegistryBuffer(buffer, varintOrder[1]);
50
+ const decoded = messageType.decode(newBuffer);
51
+ // swap varint order if the first attempt failed so we can use the correct one for subsequent messages
52
+ varintOrder.reverse();
53
+ return decoded;
54
+ }
55
+ catch {
56
+ throw new KafkaConsumerDeserializationError(`Failed to deserialize Protobuf message: ${error}, message: ${data}, messageType: ${messageType}`);
57
+ }
58
+ }
59
+ };
60
+ /**
61
+ * Clip the Confluent Schema Registry buffer to remove the index bytes.
62
+ *
63
+ * @param buffer - The buffer to clip.
64
+ * @param intType - The type of the integer to read from the buffer, either 'int32' or 'sint32'.
65
+ */
66
+ const clipConfluentSchemaRegistryBuffer = (buffer, intType) => {
67
+ const reader = new BufferReader(buffer);
68
+ /**
69
+ * Read the first varint byte to get the index count or 0.
70
+ * Doing so, also advances the reader position to the next byte after the index count.
71
+ */
72
+ const indexCount = intType === 'int32' ? reader.int32() : reader.sint32();
73
+ // Skip the index bytes
74
+ reader.skip(indexCount);
75
+ return reader;
76
+ };
77
+ export { deserialize };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Base error class for Kafka consumer-related errors.
3
+ * All Kafka consumer errors should extend this class.
4
+ */
5
+ declare class KafkaConsumerError extends Error {
6
+ constructor(message: string, options?: ErrorOptions);
7
+ }
8
+ /**
9
+ * Error thrown when deserialization of a Kafka message fails.
10
+ */
11
+ declare class KafkaConsumerDeserializationError extends KafkaConsumerError {
12
+ constructor(message: string, options?: ErrorOptions);
13
+ }
14
+ /**
15
+ * Error thrown when a required Avro schema is missing during Kafka message consumption.
16
+ */
17
+ declare class KafkaConsumerMissingSchemaError extends KafkaConsumerError {
18
+ constructor(message: string, options?: ErrorOptions);
19
+ }
20
+ /**
21
+ * Error thrown when parsing a Kafka message fails.
22
+ */
23
+ declare class KafkaConsumerParserError extends KafkaConsumerError {
24
+ constructor(message: string, options?: ErrorOptions);
25
+ }
26
+ export { KafkaConsumerError, KafkaConsumerMissingSchemaError, KafkaConsumerDeserializationError, KafkaConsumerParserError, };
27
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAM,kBAAmB,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED;;GAEG;AACH,cAAM,iCAAkC,SAAQ,kBAAkB;gBACpD,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED;;GAEG;AACH,cAAM,+BAAgC,SAAQ,kBAAkB;gBAClD,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED;;GAEG;AACH,cAAM,wBAAyB,SAAQ,kBAAkB;gBAC3C,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED,OAAO,EACL,kBAAkB,EAClB,+BAA+B,EAC/B,iCAAiC,EACjC,wBAAwB,GACzB,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Base error class for Kafka consumer-related errors.
3
+ * All Kafka consumer errors should extend this class.
4
+ */
5
+ class KafkaConsumerError extends Error {
6
+ constructor(message, options) {
7
+ super(message, options);
8
+ this.name = 'KafkaConsumerError';
9
+ }
10
+ }
11
+ /**
12
+ * Error thrown when deserialization of a Kafka message fails.
13
+ */
14
+ class KafkaConsumerDeserializationError extends KafkaConsumerError {
15
+ constructor(message, options) {
16
+ super(message, options);
17
+ this.name = 'KafkaConsumerDeserializationError';
18
+ }
19
+ }
20
+ /**
21
+ * Error thrown when a required Avro schema is missing during Kafka message consumption.
22
+ */
23
+ class KafkaConsumerMissingSchemaError extends KafkaConsumerError {
24
+ constructor(message, options) {
25
+ super(message, options);
26
+ this.name = 'KafkaConsumerMissingSchemaError';
27
+ }
28
+ }
29
+ /**
30
+ * Error thrown when parsing a Kafka message fails.
31
+ */
32
+ class KafkaConsumerParserError extends KafkaConsumerError {
33
+ constructor(message, options) {
34
+ super(message, options);
35
+ this.name = 'KafkaConsumerParserError';
36
+ }
37
+ }
38
+ export { KafkaConsumerError, KafkaConsumerMissingSchemaError, KafkaConsumerDeserializationError, KafkaConsumerParserError, };
@@ -0,0 +1,3 @@
1
+ export { SchemaType } from './constants.js';
2
+ export { kafkaConsumer } from './consumer.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { SchemaType } from './constants.js';
2
+ export { kafkaConsumer } from './consumer.js';
@@ -0,0 +1 @@
1
+ { "type": "module" }
@@ -0,0 +1,2 @@
1
+ export type { ConsumerRecord, ConsumerRecords, MSKEvent, ProtobufMessage, Record, RecordHeader, SchemaType, SchemaConfig, SchemaConfigValue, SchemaMetadata, } from './types.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,cAAc,EACd,eAAe,EACf,QAAQ,EACR,eAAe,EACf,MAAM,EACN,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,cAAc,GACf,MAAM,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ export {};