@platformatic/kafka 1.26.0 → 1.27.0-alpha.2

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 (49) hide show
  1. package/README.md +58 -0
  2. package/dist/clients/consumer/consumer.js +24 -1
  3. package/dist/clients/consumer/messages-stream.js +66 -10
  4. package/dist/clients/consumer/options.d.ts +24 -0
  5. package/dist/clients/consumer/options.js +3 -1
  6. package/dist/clients/consumer/types.d.ts +4 -1
  7. package/dist/clients/producer/options.d.ts +2 -18
  8. package/dist/clients/producer/options.js +3 -1
  9. package/dist/clients/producer/producer.js +75 -15
  10. package/dist/clients/producer/types.d.ts +4 -1
  11. package/dist/clients/serde.d.ts +11 -6
  12. package/dist/errors.d.ts +5 -1
  13. package/dist/errors.js +8 -0
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.js +2 -0
  16. package/dist/network/connection.d.ts +7 -6
  17. package/dist/protocol/definitions.js +1 -1
  18. package/dist/protocol/reader.js +1 -1
  19. package/dist/protocol/records.d.ts +7 -18
  20. package/dist/protocol/records.js +2 -6
  21. package/dist/protocol/sasl/oauth-bearer.d.ts +3 -3
  22. package/dist/protocol/sasl/plain.d.ts +3 -3
  23. package/dist/protocol/sasl/scram-sha.d.ts +3 -3
  24. package/dist/protocol/sasl/utils.d.ts +3 -3
  25. package/dist/protocol/writer.js +1 -1
  26. package/dist/registries/abstract.d.ts +22 -0
  27. package/dist/registries/abstract.js +38 -0
  28. package/dist/registries/confluent-schema-registry.d.ts +41 -0
  29. package/dist/registries/confluent-schema-registry.js +222 -0
  30. package/dist/registries/index.d.ts +2 -0
  31. package/dist/registries/index.js +2 -0
  32. package/dist/typescript-4/dist/clients/consumer/options.d.ts +24 -0
  33. package/dist/typescript-4/dist/clients/consumer/types.d.ts +4 -1
  34. package/dist/typescript-4/dist/clients/producer/options.d.ts +2 -18
  35. package/dist/typescript-4/dist/clients/producer/types.d.ts +4 -1
  36. package/dist/typescript-4/dist/clients/serde.d.ts +11 -6
  37. package/dist/typescript-4/dist/errors.d.ts +5 -1
  38. package/dist/typescript-4/dist/index.d.ts +2 -1
  39. package/dist/typescript-4/dist/network/connection.d.ts +7 -6
  40. package/dist/typescript-4/dist/protocol/records.d.ts +7 -18
  41. package/dist/typescript-4/dist/protocol/sasl/oauth-bearer.d.ts +3 -3
  42. package/dist/typescript-4/dist/protocol/sasl/plain.d.ts +3 -3
  43. package/dist/typescript-4/dist/protocol/sasl/scram-sha.d.ts +3 -3
  44. package/dist/typescript-4/dist/protocol/sasl/utils.d.ts +3 -3
  45. package/dist/typescript-4/dist/registries/abstract.d.ts +22 -0
  46. package/dist/typescript-4/dist/registries/confluent-schema-registry.d.ts +41 -0
  47. package/dist/typescript-4/dist/registries/index.d.ts +2 -0
  48. package/dist/version.js +1 -1
  49. package/package.json +4 -3
@@ -5,4 +5,5 @@ export * from "./utils";
5
5
  export * from "./network/index";
6
6
  export * from "./protocol/index";
7
7
  export * from "./apis/index";
8
- export * from "./clients/index";
8
+ export * from "./clients/index";
9
+ export * from "./registries/index";
@@ -20,18 +20,19 @@ export interface ConnectionEvents extends TypedEvents {
20
20
  'sasl:authentication:extended': (authBytes?: Buffer) => void;
21
21
  drain: () => void;
22
22
  }
23
- export type SASLCredentialProvider<T = string> = () => T | Promise<T>;
23
+ export type CredentialProvider<T = string> = () => T | Promise<T>;
24
+ export type SASLCredentialProvider<T> = CredentialProvider<T>;
24
25
  export interface Broker {
25
26
  host: string;
26
27
  port: number;
27
28
  }
28
- export type SASLCustomAuthenticator = (mechanism: SASLMechanismValue, connection: Connection, authenticate: SASLAuthenticationAPI, usernameProvider: string | SASLCredentialProvider | undefined, passwordProvider: string | SASLCredentialProvider | undefined, tokenProvider: string | SASLCredentialProvider | undefined, callback: CallbackWithPromise<SaslAuthenticateResponse>) => void;
29
+ export type SASLCustomAuthenticator = (mechanism: SASLMechanismValue, connection: Connection, authenticate: SASLAuthenticationAPI, usernameProvider: string | CredentialProvider | undefined, passwordProvider: string | CredentialProvider | undefined, tokenProvider: string | CredentialProvider | undefined, callback: CallbackWithPromise<SaslAuthenticateResponse>) => void;
29
30
  export interface SASLOptions {
30
31
  mechanism: SASLMechanismValue;
31
- username?: string | SASLCredentialProvider;
32
- password?: string | SASLCredentialProvider;
33
- token?: string | SASLCredentialProvider;
34
- oauthBearerExtensions?: Record<string, string> | SASLCredentialProvider<Record<string, string>>;
32
+ username?: string | CredentialProvider;
33
+ password?: string | CredentialProvider;
34
+ token?: string | CredentialProvider;
35
+ oauthBearerExtensions?: Record<string, string> | CredentialProvider<Record<string, string>>;
35
36
  authenticate?: SASLCustomAuthenticator;
36
37
  authBytesValidator?: (authBytes: Buffer, callback: CallbackWithPromise<Buffer>) => void;
37
38
  }
@@ -17,6 +17,7 @@ export interface MessageBase<Key = Buffer, Value = Buffer> {
17
17
  }
18
18
  export interface MessageToProduce<Key = Buffer, Value = Buffer, HeaderKey = Buffer, HeaderValue = Buffer> extends MessageBase<Key, Value> {
19
19
  headers?: Map<HeaderKey, HeaderValue> | Record<string, HeaderValue>;
20
+ metadata?: unknown;
20
21
  }
21
22
  export interface MessageConsumerMetadata {
22
23
  coordinatorId: number;
@@ -67,6 +68,10 @@ export interface KafkaRecord {
67
68
  value: Buffer;
68
69
  headers: [Buffer, Buffer][];
69
70
  }
71
+ export interface MessageToConsume extends KafkaRecord {
72
+ topic: string;
73
+ partition: number;
74
+ }
70
75
  export interface RecordsBatch {
71
76
  firstOffset: bigint;
72
77
  length: number;
@@ -85,24 +90,8 @@ export interface RecordsBatch {
85
90
  export declare const messageSchema: {
86
91
  type: string;
87
92
  properties: {
88
- key: {
89
- oneOf: ({
90
- type: string;
91
- buffer?: undefined;
92
- } | {
93
- buffer: boolean;
94
- type?: undefined;
95
- })[];
96
- };
97
- value: {
98
- oneOf: ({
99
- type: string;
100
- buffer?: undefined;
101
- } | {
102
- buffer: boolean;
103
- type?: undefined;
104
- })[];
105
- };
93
+ key: boolean;
94
+ value: boolean;
106
95
  headers: {
107
96
  anyOf: ({
108
97
  map: boolean;
@@ -1,6 +1,6 @@
1
1
  import { type CallbackWithPromise } from "../../apis/callbacks";
2
2
  import { type SASLAuthenticationAPI, type SaslAuthenticateResponse } from "../../apis/security/sasl-authenticate-v2";
3
- import { type Connection, type SASLCredentialProvider } from "../../network/connection";
3
+ import { type Connection, type CredentialProvider } from "../../network/connection";
4
4
  export declare function jwtValidateAuthenticationBytes(authBytes: Buffer, callback: CallbackWithPromise<Buffer>): void;
5
- export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, tokenOrProvider: string | SASLCredentialProvider, extensions: Record<string, string> | SASLCredentialProvider<Record<string, string>>, callback: CallbackWithPromise<SaslAuthenticateResponse>): void;
6
- export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, tokenOrProvider: string | SASLCredentialProvider, extensions: Record<string, string> | SASLCredentialProvider<Record<string, string>>): Promise<SaslAuthenticateResponse>;
5
+ export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, tokenOrProvider: string | CredentialProvider, extensions: Record<string, string> | CredentialProvider<Record<string, string>>, callback: CallbackWithPromise<SaslAuthenticateResponse>): void;
6
+ export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, tokenOrProvider: string | CredentialProvider, extensions: Record<string, string> | CredentialProvider<Record<string, string>>): Promise<SaslAuthenticateResponse>;
@@ -1,5 +1,5 @@
1
1
  import { type CallbackWithPromise } from "../../apis/callbacks";
2
2
  import { type SASLAuthenticationAPI, type SaslAuthenticateResponse } from "../../apis/security/sasl-authenticate-v2";
3
- import { type Connection, type SASLCredentialProvider } from "../../network/connection";
4
- export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, usernameProvider: string | SASLCredentialProvider, passwordProvider: string | SASLCredentialProvider, callback: CallbackWithPromise<SaslAuthenticateResponse>): void;
5
- export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, usernameProvider: string | SASLCredentialProvider, passwordProvider: string | SASLCredentialProvider): Promise<SaslAuthenticateResponse>;
3
+ import { type Connection, type CredentialProvider } from "../../network/connection";
4
+ export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, usernameProvider: string | CredentialProvider, passwordProvider: string | CredentialProvider, callback: CallbackWithPromise<SaslAuthenticateResponse>): void;
5
+ export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, usernameProvider: string | CredentialProvider, passwordProvider: string | CredentialProvider): Promise<SaslAuthenticateResponse>;
@@ -1,6 +1,6 @@
1
1
  import { type CallbackWithPromise } from "../../apis/callbacks";
2
2
  import { type SASLAuthenticationAPI, type SaslAuthenticateResponse } from "../../apis/security/sasl-authenticate-v2";
3
- import { type Connection, type SASLCredentialProvider } from "../../network/connection";
3
+ import { type Connection, type CredentialProvider } from "../../network/connection";
4
4
  export interface ScramAlgorithmDefinition {
5
5
  keyLength: number;
6
6
  algorithm: string;
@@ -35,5 +35,5 @@ export declare function hi(definition: ScramAlgorithmDefinition, password: strin
35
35
  export declare function hmac(definition: ScramAlgorithmDefinition, key: Buffer, data: string | Buffer): Buffer;
36
36
  export declare function xor(a: Buffer, b: Buffer): Buffer;
37
37
  export declare const defaultCrypto: ScramCryptoModule;
38
- export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, algorithm: ScramAlgorithm, usernameProvider: string | SASLCredentialProvider, passwordProvider: string | SASLCredentialProvider, crypto: ScramCryptoModule, callback: CallbackWithPromise<SaslAuthenticateResponse>): void;
39
- export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, algorithm: ScramAlgorithm, usernameProvider: string | SASLCredentialProvider, passwordProvider: string | SASLCredentialProvider, crypto?: ScramCryptoModule): Promise<SaslAuthenticateResponse>;
38
+ export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, algorithm: ScramAlgorithm, usernameProvider: string | CredentialProvider, passwordProvider: string | CredentialProvider, crypto: ScramCryptoModule, callback: CallbackWithPromise<SaslAuthenticateResponse>): void;
39
+ export declare function authenticate(authenticateAPI: SASLAuthenticationAPI, connection: Connection, algorithm: ScramAlgorithm, usernameProvider: string | CredentialProvider, passwordProvider: string | CredentialProvider, crypto?: ScramCryptoModule): Promise<SaslAuthenticateResponse>;
@@ -1,4 +1,4 @@
1
1
  import { type CallbackWithPromise } from "../../apis/index";
2
- import { type SASLCredentialProvider } from "../../network/connection";
3
- export declare function getCredential<T>(label: string, credentialOrProvider: T | SASLCredentialProvider<T>, callback: CallbackWithPromise<T>): void;
4
- export declare function getCredential<T>(label: string, credentialOrProvider: T | SASLCredentialProvider<T>): Promise<T>;
2
+ import { type CredentialProvider } from "../../network/connection";
3
+ export declare function getCredential<T>(label: string, credentialOrProvider: T | CredentialProvider<T>, callback: CallbackWithPromise<T>): void;
4
+ export declare function getCredential<T>(label: string, credentialOrProvider: T | CredentialProvider<T>): Promise<T>;
@@ -0,0 +1,22 @@
1
+ import { type Callback } from "../apis/definitions";
2
+ import { type BeforeDeserializationHook, type BeforeHookPayloadType, type BeforeSerializationHook, type Deserializers, type Serializers } from "../clients/serde";
3
+ import { type MessageToProduce } from "../protocol/records";
4
+ export interface SchemaRegistry<Id = unknown, Schema = unknown, Key = Buffer, Value = Buffer, HeaderKey = Buffer, HeaderValue = Buffer> {
5
+ get(id: Id): Schema | undefined;
6
+ fetch(id: Id, callback?: (error?: Error) => void): void | Promise<void>;
7
+ getSchemaId(payload: Buffer | MessageToProduce<Key, Value, HeaderKey, HeaderValue>, type?: BeforeHookPayloadType): Id;
8
+ getSerializers(): Serializers<Key, Value, HeaderKey, HeaderValue>;
9
+ getDeserializers(): Deserializers<Key, Value, HeaderKey, HeaderValue>;
10
+ getBeforeSerializationHook(): BeforeSerializationHook<Key, Value, HeaderKey, HeaderValue>;
11
+ getBeforeDeserializationHook(): BeforeDeserializationHook;
12
+ }
13
+ export declare function runAsyncSeries<V>(operation: (item: V, cb: Callback<void>) => void | Promise<void>, collection: V[], index: number, callback: Callback<void>): void;
14
+ export declare class AbstractSchemaRegistry<Id = unknown, Schema = unknown, Key = Buffer, Value = Buffer, HeaderKey = Buffer, HeaderValue = Buffer> implements SchemaRegistry<Id, Schema, Key, Value, HeaderKey, HeaderValue> {
15
+ get(_: Id): Schema | undefined;
16
+ fetch(_i: unknown, _c?: (error?: Error) => void): void | Promise<void>;
17
+ getSchemaId(_p: Buffer | MessageToProduce<Key, Value, HeaderKey, HeaderValue>, _t?: BeforeHookPayloadType): Id;
18
+ getSerializers(): Serializers<Key, Value, HeaderKey, HeaderValue>;
19
+ getDeserializers(): Deserializers<Key, Value, HeaderKey, HeaderValue>;
20
+ getBeforeSerializationHook(): BeforeSerializationHook<Key, Value, HeaderKey, HeaderValue>;
21
+ getBeforeDeserializationHook(): BeforeDeserializationHook;
22
+ }
@@ -0,0 +1,41 @@
1
+ import { type ValidateFunction } from 'ajv';
2
+ import { type Type } from 'avsc';
3
+ import { type Root } from 'protobufjs';
4
+ import { type Callback } from "../apis/definitions";
5
+ import { type BeforeDeserializationHook, type BeforeHookPayloadType, type BeforeSerializationHook, type Deserializers, type Serializers } from "../clients/serde";
6
+ import { type CredentialProvider } from "../index";
7
+ import { type MessageToConsume, type MessageToProduce } from "../protocol/records";
8
+ import { AbstractSchemaRegistry } from "./abstract";
9
+ type ConfluentSchemaRegistryMessageToProduce = MessageToProduce<unknown, unknown, unknown, unknown>;
10
+ export interface ConfluentSchemaRegistryMetadata {
11
+ schemas?: Record<BeforeHookPayloadType, number>;
12
+ }
13
+ export type ConfluentSchemaRegistryProtobufTypeMapper = (id: number, type: BeforeHookPayloadType, context: ConfluentSchemaRegistryMessageToProduce | MessageToConsume) => string;
14
+ export interface ConfluentSchemaRegistryOptions {
15
+ url: string;
16
+ auth?: {
17
+ username?: string | CredentialProvider;
18
+ password?: string | CredentialProvider;
19
+ token?: string | CredentialProvider;
20
+ };
21
+ protobufTypeMapper?: ConfluentSchemaRegistryProtobufTypeMapper;
22
+ jsonValidateSend?: boolean;
23
+ }
24
+ export interface Schema {
25
+ id: number;
26
+ type: 'avro' | 'protobuf' | 'json';
27
+ schema: Type | Root | ValidateFunction;
28
+ }
29
+ export declare function defaultProtobufTypeMapper(_: number, type: BeforeHookPayloadType, context: ConfluentSchemaRegistryMessageToProduce | MessageToConsume): string;
30
+ export declare class ConfluentSchemaRegistry<Key = Buffer, Value = Buffer, HeaderKey = Buffer, HeaderValue = Buffer> extends AbstractSchemaRegistry<number | undefined, Schema, Key, Value, HeaderKey, HeaderValue> {
31
+ #private;
32
+ constructor(options: ConfluentSchemaRegistryOptions);
33
+ getSchemaId(message: Buffer | MessageToProduce<Key, Value, HeaderKey, HeaderValue>, type?: BeforeHookPayloadType): number | undefined;
34
+ get(id: number): Schema | undefined;
35
+ fetchSchema(id: number, callback: Callback<void>): Promise<void>;
36
+ getSerializers(): Serializers<Key, Value, HeaderKey, HeaderValue>;
37
+ getDeserializers(): Deserializers<Key, Value, HeaderKey, HeaderValue>;
38
+ getBeforeSerializationHook(): BeforeSerializationHook<Key, Value, HeaderKey, HeaderValue>;
39
+ getBeforeDeserializationHook(): BeforeDeserializationHook;
40
+ }
41
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./abstract";
2
+ export * from "./confluent-schema-registry";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = "@platformatic/kafka";
2
- export const version = "1.26.0";
2
+ export const version = "1.27.0-alpha.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/kafka",
3
- "version": "1.26.0",
3
+ "version": "1.27.0-alpha.2",
4
4
  "description": "Modern and performant client for Apache Kafka",
5
5
  "homepage": "https://github.com/platformatic/kafka",
6
6
  "author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
@@ -34,6 +34,7 @@
34
34
  "optionalDependencies": {
35
35
  "@node-rs/crc32": "^1.10.6",
36
36
  "lz4-napi": "^2.9.0",
37
+ "protobufjs": "^8.0.0",
37
38
  "snappy": "^7.3.3"
38
39
  },
39
40
  "devDependencies": {
@@ -64,8 +65,8 @@
64
65
  "kerberos": "^2.2.2",
65
66
  "neostandard": "^0.12.2",
66
67
  "parse5": "^7.3.0",
67
- "prettier": "^3.6.2",
68
- "prettier-plugin-space-before-function-paren": "^0.0.8",
68
+ "prettier": "^3.8.1",
69
+ "prettier-plugin-space-before-function-paren": "^0.0.10",
69
70
  "prom-client": "^15.1.3",
70
71
  "semver": "^7.7.2",
71
72
  "table": "^6.9.0",