@platformatic/kafka 1.27.0-alpha.1 → 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 (55) 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/compression.js +45 -6
  18. package/dist/protocol/crc32c.js +4 -3
  19. package/dist/protocol/definitions.js +1 -1
  20. package/dist/protocol/reader.js +1 -1
  21. package/dist/protocol/records.d.ts +7 -18
  22. package/dist/protocol/records.js +2 -6
  23. package/dist/protocol/sasl/oauth-bearer.d.ts +3 -3
  24. package/dist/protocol/sasl/plain.d.ts +3 -3
  25. package/dist/protocol/sasl/scram-sha.d.ts +3 -3
  26. package/dist/protocol/sasl/utils.d.ts +3 -3
  27. package/dist/protocol/writer.js +1 -1
  28. package/dist/registries/abstract.d.ts +22 -0
  29. package/dist/registries/abstract.js +38 -0
  30. package/dist/registries/confluent-schema-registry.d.ts +41 -0
  31. package/dist/registries/confluent-schema-registry.js +222 -0
  32. package/dist/registries/index.d.ts +2 -0
  33. package/dist/registries/index.js +2 -0
  34. package/dist/typescript-4/dist/clients/consumer/options.d.ts +24 -0
  35. package/dist/typescript-4/dist/clients/consumer/types.d.ts +4 -1
  36. package/dist/typescript-4/dist/clients/producer/options.d.ts +2 -18
  37. package/dist/typescript-4/dist/clients/producer/types.d.ts +4 -1
  38. package/dist/typescript-4/dist/clients/serde.d.ts +11 -6
  39. package/dist/typescript-4/dist/errors.d.ts +5 -1
  40. package/dist/typescript-4/dist/index.d.ts +2 -1
  41. package/dist/typescript-4/dist/network/connection.d.ts +7 -6
  42. package/dist/typescript-4/dist/protocol/records.d.ts +7 -18
  43. package/dist/typescript-4/dist/protocol/sasl/oauth-bearer.d.ts +3 -3
  44. package/dist/typescript-4/dist/protocol/sasl/plain.d.ts +3 -3
  45. package/dist/typescript-4/dist/protocol/sasl/scram-sha.d.ts +3 -3
  46. package/dist/typescript-4/dist/protocol/sasl/utils.d.ts +3 -3
  47. package/dist/typescript-4/dist/registries/abstract.d.ts +22 -0
  48. package/dist/typescript-4/dist/registries/confluent-schema-registry.d.ts +41 -0
  49. package/dist/typescript-4/dist/registries/index.d.ts +2 -0
  50. package/dist/version.js +1 -1
  51. package/package.json +12 -12
  52. package/dist/native.wasm +0 -0
  53. package/dist/protocol/native.d.ts +0 -8
  54. package/dist/protocol/native.js +0 -48
  55. package/dist/typescript-4/dist/protocol/native.d.ts +0 -8
@@ -121,24 +121,8 @@ export declare const sendOptionsSchema: {
121
121
  items: {
122
122
  type: string;
123
123
  properties: {
124
- key: {
125
- oneOf: ({
126
- type: string;
127
- buffer?: undefined;
128
- } | {
129
- buffer: boolean;
130
- type?: undefined;
131
- })[];
132
- };
133
- value: {
134
- oneOf: ({
135
- type: string;
136
- buffer?: undefined;
137
- } | {
138
- buffer: boolean;
139
- type?: undefined;
140
- })[];
141
- };
124
+ key: boolean;
125
+ value: boolean;
142
126
  headers: {
143
127
  anyOf: ({
144
128
  map: boolean;
@@ -1,7 +1,8 @@
1
1
  import { type CompressionAlgorithmValue } from "../../protocol/compression";
2
2
  import { type MessageToProduce } from "../../protocol/records";
3
+ import { type SchemaRegistry } from "../../registries/abstract";
3
4
  import { type BaseOptions, type TopicWithPartitionAndOffset } from "../base/types";
4
- import { type Serializers } from "../serde";
5
+ import { type BeforeSerializationHook, type Serializers } from "../serde";
5
6
  export interface ProducerInfo {
6
7
  producerId: bigint;
7
8
  producerEpoch: number;
@@ -25,6 +26,8 @@ export interface ProduceOptions<Key, Value, HeaderKey, HeaderValue> {
25
26
  export type ProducerOptions<Key, Value, HeaderKey, HeaderValue> = BaseOptions & ProduceOptions<Key, Value, HeaderKey, HeaderValue> & {
26
27
  transactionalId?: string;
27
28
  serializers?: Partial<Serializers<Key, Value, HeaderKey, HeaderValue>>;
29
+ beforeSerialization?: BeforeSerializationHook<Key, Value, HeaderKey, HeaderValue>;
30
+ registry?: SchemaRegistry<unknown, unknown, Key, Value, HeaderKey, HeaderValue>;
28
31
  };
29
32
  export type SendOptions<Key, Value, HeaderKey, HeaderValue> = {
30
33
  messages: MessageToProduce<Key, Value, HeaderKey, HeaderValue>[];
@@ -1,7 +1,9 @@
1
- export type Serializer<InputType = unknown> = (data?: InputType) => Buffer | undefined;
2
- export type Deserializer<OutputType = unknown> = (data?: Buffer) => OutputType | undefined;
3
- export type SerializerWithHeaders<InputType = unknown, HeaderKey = unknown, HeaderValue = unknown> = (data?: InputType, headers?: Map<HeaderKey, HeaderValue>) => Buffer | undefined;
4
- export type DeserializerWithHeaders<OutputType = unknown, HeaderKey = unknown, HeaderValue = unknown> = (data?: Buffer, headers?: Map<HeaderKey, HeaderValue>) => OutputType | undefined;
1
+ import { type Callback } from "../apis/definitions";
2
+ import { type MessageToConsume, type MessageToProduce } from "../protocol/records";
3
+ export type Serializer<InputType = unknown> = (data?: InputType, metadata?: unknown) => Buffer | undefined;
4
+ export type SerializerWithHeaders<InputType = unknown, HeaderKey = unknown, HeaderValue = unknown> = (data?: InputType, headers?: Map<HeaderKey, HeaderValue>, message?: MessageToProduce<unknown, unknown, unknown, unknown>) => Buffer | undefined;
5
+ export type Deserializer<OutputType = unknown> = (data?: Buffer, message?: MessageToConsume) => OutputType | undefined;
6
+ export type DeserializerWithHeaders<OutputType = unknown, HeaderKey = unknown, HeaderValue = unknown> = (data?: Buffer, headers?: Map<HeaderKey, HeaderValue>, message?: MessageToConsume) => OutputType | undefined;
5
7
  export interface Serializers<Key, Value, HeaderKey, HeaderValue> {
6
8
  key: SerializerWithHeaders<Key, HeaderKey, HeaderValue>;
7
9
  value: SerializerWithHeaders<Value, HeaderKey, HeaderValue>;
@@ -9,11 +11,14 @@ export interface Serializers<Key, Value, HeaderKey, HeaderValue> {
9
11
  headerValue: Serializer<HeaderValue>;
10
12
  }
11
13
  export interface Deserializers<Key, Value, HeaderKey, HeaderValue> {
12
- key: DeserializerWithHeaders<Key>;
13
- value: DeserializerWithHeaders<Value>;
14
+ key: DeserializerWithHeaders<Key, HeaderKey, HeaderValue>;
15
+ value: DeserializerWithHeaders<Value, HeaderKey, HeaderValue>;
14
16
  headerKey: Deserializer<HeaderKey>;
15
17
  headerValue: Deserializer<HeaderValue>;
16
18
  }
19
+ export type BeforeHookPayloadType = 'key' | 'value' | 'headerKey' | 'headerValue';
20
+ export type BeforeDeserializationHook = (payload: Buffer, type: BeforeHookPayloadType, message: MessageToConsume, callback: Callback<void>) => void | Promise<void>;
21
+ export type BeforeSerializationHook<Key, Value, HeaderKey, HeaderValue> = (payload: unknown, type: BeforeHookPayloadType, message: MessageToProduce<Key, Value, HeaderKey, HeaderValue>, callback: Callback<void>) => void | Promise<void>;
17
22
  export declare function stringSerializer(data?: string): Buffer | undefined;
18
23
  export declare function stringDeserializer(data?: string | Buffer): string | undefined;
19
24
  export declare function jsonSerializer<T = Record<string, any>>(data?: T): Buffer | undefined;
@@ -2,7 +2,7 @@ import { type NullableString } from "./protocol/definitions";
2
2
  declare const kGenericError: unique symbol;
3
3
  declare const kMultipleErrors: unique symbol;
4
4
  export declare const ERROR_PREFIX = "PLT_KFK_";
5
- export declare const errorCodes: readonly ["PLT_KFK_AUTHENTICATION", "PLT_KFK_MULTIPLE", "PLT_KFK_NETWORK", "PLT_KFK_OUT_OF_BOUNDS", "PLT_KFK_PROTOCOL", "PLT_KFK_RESPONSE", "PLT_KFK_TIMEOUT", "PLT_KFK_UNEXPECTED_CORRELATION_ID", "PLT_KFK_UNFINISHED_WRITE_BUFFER", "PLT_KFK_UNSUPPORTED_API", "PLT_KFK_UNSUPPORTED_COMPRESSION", "PLT_KFK_UNSUPPORTED", "PLT_KFK_USER"];
5
+ export declare const errorCodes: readonly ["PLT_KFK_AUTHENTICATION", "PLT_KFK_MULTIPLE", "PLT_KFK_NETWORK", "PLT_KFK_OUT_OF_BOUNDS", "PLT_KFK_PROTOCOL", "PLT_KFK_RESPONSE", "PLT_KFK_TIMEOUT", "PLT_KFK_UNEXPECTED_CORRELATION_ID", "PLT_KFK_UNFINISHED_WRITE_BUFFER", "PLT_KFK_UNSUPPORTED_API", "PLT_KFK_UNSUPPORTED_COMPRESSION", "PLT_KFK_UNSUPPORTED_FORMAT", "PLT_KFK_UNSUPPORTED", "PLT_KFK_USER"];
6
6
  export type ErrorCode = (typeof errorCodes)[number];
7
7
  export type ErrorProperties = {
8
8
  cause?: Error;
@@ -73,6 +73,10 @@ export declare class UnsupportedCompressionError extends GenericError {
73
73
  static code: ErrorCode;
74
74
  constructor(message: string, properties?: ErrorProperties);
75
75
  }
76
+ export declare class UnsupportedFormatError extends GenericError {
77
+ static code: ErrorCode;
78
+ constructor(message: string, properties?: ErrorProperties);
79
+ }
76
80
  export declare class UnsupportedError extends GenericError {
77
81
  static code: ErrorCode;
78
82
  constructor(message: string, properties?: ErrorProperties);
@@ -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.27.0-alpha.1";
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.27.0-alpha.1",
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)",
@@ -32,7 +32,10 @@
32
32
  "scule": "^1.3.0"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@node-rs/crc32": "^1.10.6"
35
+ "@node-rs/crc32": "^1.10.6",
36
+ "lz4-napi": "^2.9.0",
37
+ "protobufjs": "^8.0.0",
38
+ "snappy": "^7.3.3"
36
39
  },
37
40
  "devDependencies": {
38
41
  "@babel/generator": "^7.28.5",
@@ -42,12 +45,11 @@
42
45
  "@confluentinc/kafka-javascript": "^1.5.0",
43
46
  "@opentelemetry/instrumentation": "^0.210.0",
44
47
  "@platformatic/rdkafka": "^4.0.0",
45
- "@swc-node/register": "^1.11.1",
46
48
  "@types/babel__generator": "^7.27.0",
47
49
  "@types/babel__traverse": "^7.28.0",
48
50
  "@types/debug": "^4.1.12",
49
51
  "@types/kerberos": "^1.1.5",
50
- "@types/node": "^22.18.8",
52
+ "@types/node": "^22.18.5",
51
53
  "@types/semver": "^7.7.1",
52
54
  "@watchable/unpromise": "^1.0.2",
53
55
  "avsc": "^5.7.9",
@@ -61,14 +63,12 @@
61
63
  "json5": "^2.2.3",
62
64
  "kafkajs": "^2.2.4",
63
65
  "kerberos": "^2.2.2",
64
- "lz4-napi": "^2.9.0",
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
- "snappy": "^7.3.3",
72
72
  "table": "^6.9.0",
73
73
  "typescript": "^5.9.2"
74
74
  },
@@ -84,16 +84,16 @@
84
84
  },
85
85
  "scripts": {
86
86
  "build": "rm -rf dist && tsc -p tsconfig.base.json",
87
- "build:native": "cd native && docker compose up",
88
- "postbuild": "./scripts/node scripts/postbuild.ts && npm run build:native",
87
+ "postbuild": "node scripts/postbuild.ts",
89
88
  "lint": "eslint --cache",
90
89
  "typecheck": "tsc -p . --noEmit",
91
90
  "format": "prettier -w benchmarks playground src test",
92
- "test": "c8 -c test/config/c8-local.json ./scripts/node --test --test-reporter=cleaner-spec-reporter 'test/*.test.ts' 'test/*/*.test.ts' 'test/*/*/*.test.ts'",
93
- "test:ci": "c8 -c test/config/c8-ci.json ./scripts/node --test --test-reporter=cleaner-spec-reporter 'test/*.test.ts' 'test/*/*.test.ts' 'test/*/*/*.test.ts'",
91
+ "test": "c8 -c test/config/c8-local.json node --env-file=test/config/env --no-warnings --test --test-timeout=600000 'test/**/*.test.ts'",
92
+ "test:ci": "c8 -c test/config/c8-ci.json node --env-file=test/config/env --no-warnings --test --test-timeout=600000 'test/**/*.test.ts'",
94
93
  "test:docker:up": "docker-compose up -d --wait",
95
94
  "test:docker:down": "docker-compose down",
96
95
  "ci": "npm run build && npm run lint && npm run test:ci",
96
+ "ci:v20": "npm run lint && rm -rf dist && tsc -p tsconfig.json && node dist/scripts/postbuild.js && cd dist && node --env-file=../test/config/env --no-warnings --test --test-timeout=600000",
97
97
  "generate:apis": "node scripts/generate-apis.ts",
98
98
  "generate:errors": "node scripts/generate-errors.ts",
99
99
  "create:api": "node scripts/create-api.ts"
package/dist/native.wasm DELETED
Binary file
@@ -1,8 +0,0 @@
1
- import { DynamicBuffer } from './dynamic-buffer.ts';
2
- export declare function prepareInput(data: Buffer | Uint8Array | DynamicBuffer): void;
3
- export declare function prepareOutput(combined: bigint): Buffer;
4
- export declare function crc32c(data: Buffer | Uint8Array | DynamicBuffer): number;
5
- export declare function lz4Compress(data: Buffer | DynamicBuffer): Buffer;
6
- export declare function lz4Decompress(data: Buffer | DynamicBuffer): Buffer;
7
- export declare function snappyCompress(data: Buffer | DynamicBuffer): Buffer;
8
- export declare function snappyDecompress(data: Buffer | DynamicBuffer): Buffer;
@@ -1,48 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { DynamicBuffer } from "./dynamic-buffer.js";
3
- // @ts-expect-error - Buffer[Symbol.species] is not typed in Node.js types
4
- const FastBuffer = Buffer[Symbol.species];
5
- const wasm = readFileSync(new URL('../../dist/native.wasm', import.meta.url));
6
- const wasmModule = new WebAssembly.Module(wasm);
7
- const instance = new WebAssembly.Instance(wasmModule);
8
- const { alloc, crc32c: _crc32c, dealloc, lz4_compress: _lz4Compress, lz4_decompress: _lz4Decompress, memory, snappy_compress: _snappyCompress, snappy_decompress: _snappyDecompress } = instance.exports;
9
- let currentBufferLength = 4096;
10
- let currentBufferOffset = alloc(currentBufferLength);
11
- let currentBuffer = new Uint8Array(memory.buffer, currentBufferOffset, currentBufferLength);
12
- export function prepareInput(data) {
13
- const input = DynamicBuffer.isDynamicBuffer(data) ? data.buffer : data;
14
- if (currentBuffer.length < data.length) {
15
- dealloc(currentBufferOffset, currentBufferLength);
16
- currentBufferLength = data.length;
17
- currentBufferOffset = alloc(currentBufferLength);
18
- currentBuffer = new Uint8Array(memory.buffer, currentBufferOffset, currentBufferLength);
19
- }
20
- currentBuffer.set(input);
21
- }
22
- export function prepareOutput(combined) {
23
- const len = Number(BigInt.asUintN(32, combined));
24
- const ptr = Number(combined >> 32n);
25
- const output = Buffer.from(new FastBuffer(memory.buffer, ptr, len));
26
- dealloc(ptr, len);
27
- return output;
28
- }
29
- export function crc32c(data) {
30
- prepareInput(data);
31
- return _crc32c(currentBufferOffset, data.length) >>> 0;
32
- }
33
- export function lz4Compress(data) {
34
- prepareInput(data);
35
- return prepareOutput(_lz4Compress(currentBufferOffset, data.length));
36
- }
37
- export function lz4Decompress(data) {
38
- prepareInput(data);
39
- return prepareOutput(_lz4Decompress(currentBufferOffset, data.length));
40
- }
41
- export function snappyCompress(data) {
42
- prepareInput(data);
43
- return prepareOutput(_snappyCompress(currentBufferOffset, data.length));
44
- }
45
- export function snappyDecompress(data) {
46
- prepareInput(data);
47
- return prepareOutput(_snappyDecompress(currentBufferOffset, data.length));
48
- }
@@ -1,8 +0,0 @@
1
- import { DynamicBuffer } from "./dynamic-buffer";
2
- export declare function prepareInput(data: Buffer | Uint8Array | DynamicBuffer): void;
3
- export declare function prepareOutput(combined: bigint): Buffer;
4
- export declare function crc32c(data: Buffer | Uint8Array | DynamicBuffer): number;
5
- export declare function lz4Compress(data: Buffer | DynamicBuffer): Buffer;
6
- export declare function lz4Decompress(data: Buffer | DynamicBuffer): Buffer;
7
- export declare function snappyCompress(data: Buffer | DynamicBuffer): Buffer;
8
- export declare function snappyDecompress(data: Buffer | DynamicBuffer): Buffer;