@platformatic/kafka 2.5.0 → 2.6.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.
@@ -1,4 +1,4 @@
1
- import { type ValidateFunction } from 'ajv';
1
+ import { type Options, type ValidateFunction } from 'ajv';
2
2
  import { type Type } from 'avsc';
3
3
  import { type Root } from 'protobufjs';
4
4
  import { type Callback } from '../apis/definitions.ts';
@@ -20,6 +20,7 @@ export interface ConfluentSchemaRegistryOptions {
20
20
  };
21
21
  protobufTypeMapper?: ConfluentSchemaRegistryProtobufTypeMapper;
22
22
  jsonValidateSend?: boolean;
23
+ jsonAjvOptions?: Options;
23
24
  }
24
25
  export interface Schema {
25
26
  id: number;
@@ -1,7 +1,8 @@
1
+ import { Ajv2020 } from 'ajv/dist/2020.js';
1
2
  import avro from 'avsc';
2
3
  import { createRequire } from 'node:module';
3
4
  import { jsonDeserializer, jsonSerializer, stringDeserializer, stringSerializer } from "../clients/serde.js";
4
- import { ajv, EMPTY_BUFFER, UnsupportedFormatError, UserError } from "../index.js";
5
+ import { EMPTY_BUFFER, UnsupportedFormatError, UserError } from "../index.js";
5
6
  import { getCredential } from "../protocol/sasl/utils.js";
6
7
  import { AbstractSchemaRegistry } from "./abstract.js";
7
8
  const require = createRequire(import.meta.url);
@@ -17,6 +18,7 @@ export class ConfluentSchemaRegistry extends AbstractSchemaRegistry {
17
18
  #protobufParse;
18
19
  #protobufTypeMapper;
19
20
  #jsonValidateSend;
21
+ #jsonAjv;
20
22
  #auth;
21
23
  constructor(options) {
22
24
  super();
@@ -24,6 +26,7 @@ export class ConfluentSchemaRegistry extends AbstractSchemaRegistry {
24
26
  this.#schemas = new Map();
25
27
  this.#protobufTypeMapper = options.protobufTypeMapper ?? defaultProtobufTypeMapper;
26
28
  this.#jsonValidateSend = options.jsonValidateSend ?? false;
29
+ this.#jsonAjv = new Ajv2020({ allErrors: true, coerceTypes: false, strict: true, ...options.jsonAjvOptions });
27
30
  this.#auth = options.auth;
28
31
  }
29
32
  getSchemaId(message, type) {
@@ -75,7 +78,7 @@ export class ConfluentSchemaRegistry extends AbstractSchemaRegistry {
75
78
  this.#schemas.set(id, { id, type: 'protobuf', schema: this.#protobufParse(schema).root });
76
79
  break;
77
80
  case 'JSON':
78
- this.#schemas.set(id, { id, type: 'json', schema: ajv.compile(JSON.parse(schema)) });
81
+ this.#schemas.set(id, { id, type: 'json', schema: this.#jsonAjv.compile(JSON.parse(schema)) });
79
82
  break;
80
83
  }
81
84
  process.nextTick(callback);
@@ -169,7 +172,7 @@ export class ConfluentSchemaRegistry extends AbstractSchemaRegistry {
169
172
  const validate = schema.schema;
170
173
  const valid = validate(data);
171
174
  if (!valid) {
172
- throw new UserError(`JSON Schema validation failed before serialization: ${ajv.errorsText(validate.errors)}`, { type, data, headers, validationErrors: validate.errors });
175
+ throw new UserError(`JSON Schema validation failed before serialization: ${this.#jsonAjv.errorsText(validate.errors)}`, { type, data, headers, validationErrors: validate.errors });
173
176
  }
174
177
  }
175
178
  encodedMessage = Buffer.from(JSON.stringify(data));
@@ -208,7 +211,7 @@ export class ConfluentSchemaRegistry extends AbstractSchemaRegistry {
208
211
  const validate = schema.schema;
209
212
  const valid = validate(parsed);
210
213
  if (!valid) {
211
- throw new UserError(`JSON Schema validation failed before deserialization: ${ajv.errorsText(validate.errors)}`, { type, data: parsed, headers, validationErrors: validate.errors });
214
+ throw new UserError(`JSON Schema validation failed before deserialization: ${this.#jsonAjv.errorsText(validate.errors)}`, { type, data: parsed, headers, validationErrors: validate.errors });
212
215
  }
213
216
  return parsed;
214
217
  }
@@ -1,4 +1,4 @@
1
- import { type ValidateFunction } from 'ajv';
1
+ import { type Options, type ValidateFunction } from 'ajv';
2
2
  import { type Type } from 'avsc';
3
3
  import { type Root } from 'protobufjs';
4
4
  import { type Callback } from "../apis/definitions";
@@ -20,6 +20,7 @@ export interface ConfluentSchemaRegistryOptions {
20
20
  };
21
21
  protobufTypeMapper?: ConfluentSchemaRegistryProtobufTypeMapper;
22
22
  jsonValidateSend?: boolean;
23
+ jsonAjvOptions?: Options;
23
24
  }
24
25
  export interface Schema {
25
26
  id: number;
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = "@platformatic/kafka";
2
- export const version = "2.5.0";
2
+ export const version = "2.6.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/kafka",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
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)",