confluent-schema-registry 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
- package/.dockerignore +2 -0
- package/.prettierrc.js +8 -0
- package/CHANGELOG.md +166 -0
- package/Dockerfile +10 -0
- package/LICENSE +21 -0
- package/README.md +44 -0
- package/bin/avdlToAVSC.sh +9 -0
- package/dist/@types.d.ts +93 -0
- package/dist/@types.js +10 -0
- package/dist/@types.js.map +1 -0
- package/dist/AvroHelper.d.ts +12 -0
- package/dist/AvroHelper.js +67 -0
- package/dist/AvroHelper.js.map +1 -0
- package/dist/JsonHelper.d.ts +7 -0
- package/dist/JsonHelper.js +20 -0
- package/dist/JsonHelper.js.map +1 -0
- package/dist/JsonSchema.d.ts +31 -0
- package/dist/JsonSchema.js +58 -0
- package/dist/JsonSchema.js.map +1 -0
- package/dist/ProtoHelper.d.ts +7 -0
- package/dist/ProtoHelper.js +23 -0
- package/dist/ProtoHelper.js.map +1 -0
- package/dist/ProtoSchema.d.ts +14 -0
- package/dist/ProtoSchema.js +66 -0
- package/dist/ProtoSchema.js.map +1 -0
- package/dist/SchemaRegistry.d.ts +48 -0
- package/dist/SchemaRegistry.js +250 -0
- package/dist/SchemaRegistry.js.map +1 -0
- package/dist/api/index.d.ts +43 -0
- package/dist/api/index.js +90 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/middleware/confluentEncoderMiddleware.d.ts +3 -0
- package/dist/api/middleware/confluentEncoderMiddleware.js +31 -0
- package/dist/api/middleware/confluentEncoderMiddleware.js.map +1 -0
- package/dist/api/middleware/errorMiddleware.d.ts +3 -0
- package/dist/api/middleware/errorMiddleware.js +20 -0
- package/dist/api/middleware/errorMiddleware.js.map +1 -0
- package/dist/api/middleware/userAgent.d.ts +3 -0
- package/dist/api/middleware/userAgent.js +18 -0
- package/dist/api/middleware/userAgent.js.map +1 -0
- package/dist/cache.d.ts +20 -0
- package/dist/cache.js +24 -0
- package/dist/cache.js.map +1 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +26 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/schemaTypeResolver.d.ts +4 -0
- package/dist/schemaTypeResolver.js +80 -0
- package/dist/schemaTypeResolver.js.map +1 -0
- package/dist/utils/avdlToAVSC.d.ts +2 -0
- package/dist/utils/avdlToAVSC.js +85 -0
- package/dist/utils/avdlToAVSC.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/readAVSC.d.ts +3 -0
- package/dist/utils/readAVSC.js +33 -0
- package/dist/utils/readAVSC.js.map +1 -0
- package/dist/wireDecoder.d.ts +7 -0
- package/dist/wireDecoder.js +8 -0
- package/dist/wireDecoder.js.map +1 -0
- package/dist/wireEncoder.d.ts +3 -0
- package/dist/wireEncoder.js +10 -0
- package/dist/wireEncoder.js.map +1 -0
- package/dockest-error.json +11 -0
- package/dockest.ts +30 -0
- package/jest.setup.ts +60 -0
- package/package.json +56 -0
- package/release/CHANGELOG.md +166 -0
- package/release/LICENSE +21 -0
- package/release/README.md +44 -0
- package/release/dist/@types.d.ts +93 -0
- package/release/dist/@types.js +10 -0
- package/release/dist/@types.js.map +1 -0
- package/release/dist/AvroHelper.d.ts +12 -0
- package/release/dist/AvroHelper.js +67 -0
- package/release/dist/AvroHelper.js.map +1 -0
- package/release/dist/JsonHelper.d.ts +7 -0
- package/release/dist/JsonHelper.js +20 -0
- package/release/dist/JsonHelper.js.map +1 -0
- package/release/dist/JsonSchema.d.ts +31 -0
- package/release/dist/JsonSchema.js +58 -0
- package/release/dist/JsonSchema.js.map +1 -0
- package/release/dist/ProtoHelper.d.ts +7 -0
- package/release/dist/ProtoHelper.js +23 -0
- package/release/dist/ProtoHelper.js.map +1 -0
- package/release/dist/ProtoSchema.d.ts +14 -0
- package/release/dist/ProtoSchema.js +66 -0
- package/release/dist/ProtoSchema.js.map +1 -0
- package/release/dist/SchemaRegistry.d.ts +48 -0
- package/release/dist/SchemaRegistry.js +250 -0
- package/release/dist/SchemaRegistry.js.map +1 -0
- package/release/dist/api/index.d.ts +43 -0
- package/release/dist/api/index.js +90 -0
- package/release/dist/api/index.js.map +1 -0
- package/release/dist/api/middleware/confluentEncoderMiddleware.d.ts +3 -0
- package/release/dist/api/middleware/confluentEncoderMiddleware.js +31 -0
- package/release/dist/api/middleware/confluentEncoderMiddleware.js.map +1 -0
- package/release/dist/api/middleware/errorMiddleware.d.ts +3 -0
- package/release/dist/api/middleware/errorMiddleware.js +20 -0
- package/release/dist/api/middleware/errorMiddleware.js.map +1 -0
- package/release/dist/api/middleware/userAgent.d.ts +3 -0
- package/release/dist/api/middleware/userAgent.js +18 -0
- package/release/dist/api/middleware/userAgent.js.map +1 -0
- package/release/dist/cache.d.ts +20 -0
- package/release/dist/cache.js +24 -0
- package/release/dist/cache.js.map +1 -0
- package/release/dist/constants.d.ts +11 -0
- package/release/dist/constants.js +15 -0
- package/release/dist/constants.js.map +1 -0
- package/release/dist/errors.d.ts +14 -0
- package/release/dist/errors.js +26 -0
- package/release/dist/errors.js.map +1 -0
- package/release/dist/index.d.ts +4 -0
- package/release/dist/index.js +13 -0
- package/release/dist/index.js.map +1 -0
- package/release/dist/schemaTypeResolver.d.ts +4 -0
- package/release/dist/schemaTypeResolver.js +80 -0
- package/release/dist/schemaTypeResolver.js.map +1 -0
- package/release/dist/utils/avdlToAVSC.d.ts +2 -0
- package/release/dist/utils/avdlToAVSC.js +85 -0
- package/release/dist/utils/avdlToAVSC.js.map +1 -0
- package/release/dist/utils/index.d.ts +2 -0
- package/release/dist/utils/index.js +9 -0
- package/release/dist/utils/index.js.map +1 -0
- package/release/dist/utils/readAVSC.d.ts +3 -0
- package/release/dist/utils/readAVSC.js +33 -0
- package/release/dist/utils/readAVSC.js.map +1 -0
- package/release/dist/wireDecoder.d.ts +7 -0
- package/release/dist/wireDecoder.js +8 -0
- package/release/dist/wireDecoder.js.map +1 -0
- package/release/dist/wireEncoder.d.ts +3 -0
- package/release/dist/wireEncoder.js +10 -0
- package/release/dist/wireEncoder.js.map +1 -0
- package/release/package.json +56 -0
- package/src/@types.ts +105 -0
- package/src/AvroHelper.ts +91 -0
- package/src/JsonHelper.ts +35 -0
- package/src/JsonSchema.ts +80 -0
- package/src/ProtoHelper.ts +38 -0
- package/src/ProtoSchema.ts +80 -0
- package/src/SchemaRegistry.avro.spec.ts +558 -0
- package/src/SchemaRegistry.json.spec.ts +364 -0
- package/src/SchemaRegistry.newApi.spec.ts +622 -0
- package/src/SchemaRegistry.protobuf.spec.ts +372 -0
- package/src/SchemaRegistry.spec.ts +252 -0
- package/src/SchemaRegistry.ts +387 -0
- package/src/api/index.spec.ts +23 -0
- package/src/api/index.ts +121 -0
- package/src/api/middleware/confluentEncoderMiddleware.ts +36 -0
- package/src/api/middleware/errorMiddleware.spec.ts +67 -0
- package/src/api/middleware/errorMiddleware.ts +37 -0
- package/src/api/middleware/userAgent.spec.ts +53 -0
- package/src/api/middleware/userAgent.ts +19 -0
- package/src/cache.ts +34 -0
- package/src/constants.ts +13 -0
- package/src/errors.ts +26 -0
- package/src/index.ts +4 -0
- package/src/schemaTypeResolver.ts +101 -0
- package/src/utils/avdlToAVSC.spec.ts +79 -0
- package/src/utils/avdlToAVSC.ts +106 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/readAVSC.spec.ts +23 -0
- package/src/utils/readAVSC.ts +36 -0
- package/src/wireDecoder.ts +5 -0
- package/src/wireEncoder.ts +10 -0
- package/tsconfig.json +22 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
class Cache {
|
4
|
+
constructor() {
|
5
|
+
this.getLatestRegistryId = (subject) => this.registryIdBySubject[subject];
|
6
|
+
this.setLatestRegistryId = (subject, id) => {
|
7
|
+
this.registryIdBySubject[subject] = id;
|
8
|
+
return this.registryIdBySubject[subject];
|
9
|
+
};
|
10
|
+
this.getSchema = (registryId) => this.schemasByRegistryId[registryId];
|
11
|
+
this.setSchema = (registryId, type, schema) => {
|
12
|
+
this.schemasByRegistryId[registryId] = { type, schema };
|
13
|
+
return this.schemasByRegistryId[registryId];
|
14
|
+
};
|
15
|
+
this.clear = () => {
|
16
|
+
this.registryIdBySubject = {};
|
17
|
+
this.schemasByRegistryId = {};
|
18
|
+
};
|
19
|
+
this.registryIdBySubject = {};
|
20
|
+
this.schemasByRegistryId = {};
|
21
|
+
}
|
22
|
+
}
|
23
|
+
exports.default = Cache;
|
24
|
+
//# sourceMappingURL=cache.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";;AAIA,MAAqB,KAAK;IAIxB;QAKA,wBAAmB,GAAG,CAAC,OAAe,EAAsB,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAA;QAEhG,wBAAmB,GAAG,CAAC,OAAe,EAAE,EAAU,EAAU,EAAE;YAC5D,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAA;YAEtC,OAAO,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAA;QAC1C,CAAC,CAAA;QAED,cAAS,GAAG,CAAC,UAAkB,EAA0B,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAA;QAEhG,cAAS,GAAG,CAAC,UAAkB,EAAE,IAAgB,EAAE,MAAc,EAAc,EAAE;YAC/E,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;YAEvD,OAAO,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAA;QAC7C,CAAC,CAAA;QAED,UAAK,GAAG,GAAS,EAAE;YACjB,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAA;YAC7B,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAA;QAC/B,CAAC,CAAA;QAvBC,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAA;QAC7B,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAA;IAC/B,CAAC;CAsBF;AA7BD,wBA6BC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export declare enum COMPATIBILITY {
|
2
|
+
NONE = "NONE",
|
3
|
+
FULL = "FULL",
|
4
|
+
BACKWARD = "BACKWARD",
|
5
|
+
FORWARD = "FORWARD",
|
6
|
+
BACKWARD_TRANSITIVE = "BACKWARD_TRANSITIVE",
|
7
|
+
FORWARD_TRANSITIVE = "FORWARD_TRANSITIVE",
|
8
|
+
FULL_TRANSITIVE = "FULL_TRANSITIVE"
|
9
|
+
}
|
10
|
+
export declare const DEFAULT_SEPERATOR = ".";
|
11
|
+
export declare const DEFAULT_API_CLIENT_ID = "Confluent_Schema_Registry";
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
var COMPATIBILITY;
|
4
|
+
(function (COMPATIBILITY) {
|
5
|
+
COMPATIBILITY["NONE"] = "NONE";
|
6
|
+
COMPATIBILITY["FULL"] = "FULL";
|
7
|
+
COMPATIBILITY["BACKWARD"] = "BACKWARD";
|
8
|
+
COMPATIBILITY["FORWARD"] = "FORWARD";
|
9
|
+
COMPATIBILITY["BACKWARD_TRANSITIVE"] = "BACKWARD_TRANSITIVE";
|
10
|
+
COMPATIBILITY["FORWARD_TRANSITIVE"] = "FORWARD_TRANSITIVE";
|
11
|
+
COMPATIBILITY["FULL_TRANSITIVE"] = "FULL_TRANSITIVE";
|
12
|
+
})(COMPATIBILITY = exports.COMPATIBILITY || (exports.COMPATIBILITY = {}));
|
13
|
+
exports.DEFAULT_SEPERATOR = '.';
|
14
|
+
exports.DEFAULT_API_CLIENT_ID = 'Confluent_Schema_Registry';
|
15
|
+
//# sourceMappingURL=constants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;AAAA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,8BAAa,CAAA;IACb,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;IACnB,4DAA2C,CAAA;IAC3C,0DAAyC,CAAA;IACzC,oDAAmC,CAAA;AACrC,CAAC,EARW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAQxB;AAEY,QAAA,iBAAiB,GAAG,GAAG,CAAA;AAEvB,QAAA,qBAAqB,GAAG,2BAA2B,CAAA"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
declare class ConfluentSchemaRegistryError extends Error {
|
2
|
+
constructor(error: any);
|
3
|
+
}
|
4
|
+
declare class ConfluentSchemaRegistryArgumentError extends ConfluentSchemaRegistryError {
|
5
|
+
}
|
6
|
+
declare class ConfluentSchemaRegistryCompatibilityError extends ConfluentSchemaRegistryError {
|
7
|
+
}
|
8
|
+
declare class ConfluentSchemaRegistryInvalidSchemaError extends ConfluentSchemaRegistryError {
|
9
|
+
}
|
10
|
+
declare class ConfluentSchemaRegistryValidationError extends ConfluentSchemaRegistryError {
|
11
|
+
paths: string[][];
|
12
|
+
constructor(error: any, paths: string[][]);
|
13
|
+
}
|
14
|
+
export { ConfluentSchemaRegistryError, ConfluentSchemaRegistryArgumentError, ConfluentSchemaRegistryCompatibilityError, ConfluentSchemaRegistryInvalidSchemaError, ConfluentSchemaRegistryValidationError, };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
class ConfluentSchemaRegistryError extends Error {
|
4
|
+
constructor(error) {
|
5
|
+
super(error.message || error);
|
6
|
+
this.name = this.constructor.name;
|
7
|
+
}
|
8
|
+
}
|
9
|
+
exports.ConfluentSchemaRegistryError = ConfluentSchemaRegistryError;
|
10
|
+
class ConfluentSchemaRegistryArgumentError extends ConfluentSchemaRegistryError {
|
11
|
+
}
|
12
|
+
exports.ConfluentSchemaRegistryArgumentError = ConfluentSchemaRegistryArgumentError;
|
13
|
+
class ConfluentSchemaRegistryCompatibilityError extends ConfluentSchemaRegistryError {
|
14
|
+
}
|
15
|
+
exports.ConfluentSchemaRegistryCompatibilityError = ConfluentSchemaRegistryCompatibilityError;
|
16
|
+
class ConfluentSchemaRegistryInvalidSchemaError extends ConfluentSchemaRegistryError {
|
17
|
+
}
|
18
|
+
exports.ConfluentSchemaRegistryInvalidSchemaError = ConfluentSchemaRegistryInvalidSchemaError;
|
19
|
+
class ConfluentSchemaRegistryValidationError extends ConfluentSchemaRegistryError {
|
20
|
+
constructor(error, paths) {
|
21
|
+
super(error);
|
22
|
+
this.paths = paths;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
exports.ConfluentSchemaRegistryValidationError = ConfluentSchemaRegistryValidationError;
|
26
|
+
//# sourceMappingURL=errors.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;AAAA,MAAM,4BAA6B,SAAQ,KAAK;IAC9C,YAAY,KAAU;QACpB,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAA;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IACnC,CAAC;CACF;AAeC,oEAA4B;AAb9B,MAAM,oCAAqC,SAAQ,4BAA4B;CAAG;AAchF,oFAAoC;AAbtC,MAAM,yCAA0C,SAAQ,4BAA4B;CAAG;AAcrF,8FAAyC;AAb3C,MAAM,yCAA0C,SAAQ,4BAA4B;CAAG;AAcrF,8FAAyC;AAb3C,MAAM,sCAAuC,SAAQ,4BAA4B;IAG/E,YAAY,KAAU,EAAE,KAAiB;QACvC,KAAK,CAAC,KAAK,CAAC,CAAA;QACZ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF;AAOC,wFAAsC"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
function __export(m) {
|
3
|
+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
4
|
+
}
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
var SchemaRegistry_1 = require("./SchemaRegistry");
|
7
|
+
exports.SchemaRegistry = SchemaRegistry_1.default;
|
8
|
+
__export(require("./utils"));
|
9
|
+
var _types_1 = require("./@types");
|
10
|
+
exports.SchemaType = _types_1.SchemaType;
|
11
|
+
var constants_1 = require("./constants");
|
12
|
+
exports.COMPATIBILITY = constants_1.COMPATIBILITY;
|
13
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,mDAA4D;AAAnD,0CAAA,OAAO,CAAkB;AAClC,6BAAuB;AACvB,mCAAqC;AAA5B,8BAAA,UAAU,CAAA;AACnB,yCAA2C;AAAlC,oCAAA,aAAa,CAAA"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { SchemaType, SchemaHelper, ConfluentSchema, LegacyOptions, ProtocolOptions, Schema, AvroSchema } from './@types';
|
2
|
+
export declare const schemaTypeFromString: (schemaTypeString: string) => SchemaType;
|
3
|
+
export declare const helperTypeFromSchemaType: (schemaType?: SchemaType) => SchemaHelper;
|
4
|
+
export declare const schemaFromConfluentSchema: (confluentSchema: ConfluentSchema, options?: ProtocolOptions | LegacyOptions | undefined) => Schema | AvroSchema;
|
@@ -0,0 +1,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const AvroHelper_1 = __importDefault(require("./AvroHelper"));
|
7
|
+
const JsonHelper_1 = __importDefault(require("./JsonHelper"));
|
8
|
+
const JsonSchema_1 = __importDefault(require("./JsonSchema"));
|
9
|
+
const ProtoHelper_1 = __importDefault(require("./ProtoHelper"));
|
10
|
+
const ProtoSchema_1 = __importDefault(require("./ProtoSchema"));
|
11
|
+
const _types_1 = require("./@types");
|
12
|
+
const errors_1 = require("./errors");
|
13
|
+
const helperTypeFromSchemaTypeMap = {};
|
14
|
+
exports.schemaTypeFromString = (schemaTypeString) => {
|
15
|
+
switch (schemaTypeString) {
|
16
|
+
case 'AVRO':
|
17
|
+
case undefined:
|
18
|
+
return _types_1.SchemaType.AVRO;
|
19
|
+
case 'JSON':
|
20
|
+
return _types_1.SchemaType.JSON;
|
21
|
+
case 'PROTOBUF':
|
22
|
+
return _types_1.SchemaType.PROTOBUF;
|
23
|
+
default:
|
24
|
+
return _types_1.SchemaType.UNKNOWN;
|
25
|
+
}
|
26
|
+
};
|
27
|
+
exports.helperTypeFromSchemaType = (schemaType = _types_1.SchemaType.AVRO) => {
|
28
|
+
const schemaTypeStr = schemaType.toString();
|
29
|
+
if (!helperTypeFromSchemaTypeMap[schemaTypeStr]) {
|
30
|
+
let helper;
|
31
|
+
switch (schemaType) {
|
32
|
+
case _types_1.SchemaType.AVRO: {
|
33
|
+
helper = new AvroHelper_1.default();
|
34
|
+
break;
|
35
|
+
}
|
36
|
+
case _types_1.SchemaType.JSON: {
|
37
|
+
helper = new JsonHelper_1.default();
|
38
|
+
break;
|
39
|
+
}
|
40
|
+
case _types_1.SchemaType.PROTOBUF: {
|
41
|
+
helper = new ProtoHelper_1.default();
|
42
|
+
break;
|
43
|
+
}
|
44
|
+
default:
|
45
|
+
throw new errors_1.ConfluentSchemaRegistryArgumentError('invalid schemaType');
|
46
|
+
}
|
47
|
+
helperTypeFromSchemaTypeMap[schemaTypeStr] = helper;
|
48
|
+
}
|
49
|
+
return helperTypeFromSchemaTypeMap[schemaTypeStr];
|
50
|
+
};
|
51
|
+
exports.schemaFromConfluentSchema = (confluentSchema, options) => {
|
52
|
+
var _a, _b, _c, _d;
|
53
|
+
try {
|
54
|
+
let schema;
|
55
|
+
switch (confluentSchema.type) {
|
56
|
+
case _types_1.SchemaType.AVRO: {
|
57
|
+
const opts = ((_a = options) === null || _a === void 0 ? void 0 : _a.forSchemaOptions) || ((_b = options) === null || _b === void 0 ? void 0 : _b[_types_1.SchemaType.AVRO]);
|
58
|
+
schema = exports.helperTypeFromSchemaType(confluentSchema.type).getAvroSchema(confluentSchema, opts);
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
case _types_1.SchemaType.JSON: {
|
62
|
+
const opts = (_c = options) === null || _c === void 0 ? void 0 : _c[_types_1.SchemaType.JSON];
|
63
|
+
schema = new JsonSchema_1.default(confluentSchema, opts);
|
64
|
+
break;
|
65
|
+
}
|
66
|
+
case _types_1.SchemaType.PROTOBUF: {
|
67
|
+
const opts = (_d = options) === null || _d === void 0 ? void 0 : _d[_types_1.SchemaType.PROTOBUF];
|
68
|
+
schema = new ProtoSchema_1.default(confluentSchema, opts);
|
69
|
+
break;
|
70
|
+
}
|
71
|
+
default:
|
72
|
+
throw new errors_1.ConfluentSchemaRegistryArgumentError('invalid schemaType');
|
73
|
+
}
|
74
|
+
return schema;
|
75
|
+
}
|
76
|
+
catch (err) {
|
77
|
+
throw new errors_1.ConfluentSchemaRegistryArgumentError(err.message);
|
78
|
+
}
|
79
|
+
};
|
80
|
+
//# sourceMappingURL=schemaTypeResolver.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"schemaTypeResolver.js","sourceRoot":"","sources":["../src/schemaTypeResolver.ts"],"names":[],"mappings":";;;;;AAAA,8DAAqC;AACrC,8DAAqC;AACrC,8DAAqC;AACrC,gEAAuC;AACvC,gEAAuC;AACvC,qCAYiB;AACjB,qCAA+D;AAE/D,MAAM,2BAA2B,GAAiC,EAAE,CAAA;AAEvD,QAAA,oBAAoB,GAAG,CAAC,gBAAwB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OAAC,OAAyB,0CAAE,gBAAgB,YAC3C,OAA2B,0CAAG,mBAAU,CAAC,IAAI,EAAC,CAAA;gBACjD,MAAM,GAAI,gCAAwB,CAAC,eAAe,CAAC,IAAI,CAAgB,CAAC,aAAa,CACnF,eAAe,EACf,IAAI,CACL,CAAA;gBACD,MAAK;aACN;YACD,KAAK,mBAAU,CAAC,IAAI,CAAC,CAAC;gBACpB,MAAM,IAAI,SAA6B,OAA2B,0CAAG,mBAAU,CAAC,IAAI,CAAC,CAAA;gBACrF,MAAM,GAAG,IAAI,oBAAU,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;gBAC9C,MAAK;aACN;YACD,KAAK,mBAAU,CAAC,QAAQ,CAAC,CAAC;gBACxB,MAAM,IAAI,SAA8B,OAA2B,0CAAG,mBAAU,CAAC,QAAQ,CAAC,CAAA;gBAC1F,MAAM,GAAG,IAAI,qBAAW,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;gBAC/C,MAAK;aACN;YACD;gBACE,MAAM,IAAI,6CAAoC,CAAC,oBAAoB,CAAC,CAAA;SACvE;QAED,OAAO,MAAM,CAAA;KACd;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAI,6CAAoC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;KAC5D;AACH,CAAC,CAAA"}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
3
|
+
if (mod && mod.__esModule) return mod;
|
4
|
+
var result = {};
|
5
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
6
|
+
result["default"] = mod;
|
7
|
+
return result;
|
8
|
+
};
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
10
|
+
const fs = __importStar(require("fs"));
|
11
|
+
const avsc_1 = require("avsc");
|
12
|
+
const errors_1 = require("../errors");
|
13
|
+
let cache;
|
14
|
+
const merge = Object.assign;
|
15
|
+
const isObject = (obj) => obj && typeof obj === 'object';
|
16
|
+
const isIterable = (obj) => isObject(obj) && typeof obj.map !== 'undefined';
|
17
|
+
const isFieldArray = (field) => isObject(field) && isObject(field.type) && field.type.type === 'array';
|
18
|
+
const combine = (rootType, types) => {
|
19
|
+
if (!rootType.fields) {
|
20
|
+
return rootType;
|
21
|
+
}
|
22
|
+
const find = (name) => {
|
23
|
+
if (typeof name === 'string') {
|
24
|
+
name = name.toLowerCase();
|
25
|
+
}
|
26
|
+
const typeToCombine = types.find((t) => {
|
27
|
+
const names = [];
|
28
|
+
if (t.namespace) {
|
29
|
+
names.push(`${t.namespace}.`);
|
30
|
+
}
|
31
|
+
names.push(t.name.toLowerCase());
|
32
|
+
return names.join('') === name;
|
33
|
+
});
|
34
|
+
if (!typeToCombine || cache[typeToCombine.name]) {
|
35
|
+
return null;
|
36
|
+
}
|
37
|
+
cache[typeToCombine.name] = 1;
|
38
|
+
return combine(typeToCombine, types);
|
39
|
+
};
|
40
|
+
const combinedFields = rootType.fields.map((field) => {
|
41
|
+
if (isFieldArray(field)) {
|
42
|
+
const typeToCombine = find(field.type.items);
|
43
|
+
return typeToCombine
|
44
|
+
? merge(field, { type: merge(field.type, { items: typeToCombine }) })
|
45
|
+
: field;
|
46
|
+
}
|
47
|
+
else if (isIterable(field.type)) {
|
48
|
+
const type = field.type.map((unionType) => {
|
49
|
+
if (isObject(unionType)) {
|
50
|
+
const typeToCombine = find(unionType.items);
|
51
|
+
return typeToCombine ? merge(unionType, { items: typeToCombine }) : unionType;
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
return find(unionType) || unionType;
|
55
|
+
}
|
56
|
+
});
|
57
|
+
return merge(field, { type });
|
58
|
+
}
|
59
|
+
const typeToCombine = find(field.type);
|
60
|
+
return typeToCombine ? merge(field, { type: typeToCombine }) : field;
|
61
|
+
});
|
62
|
+
return merge(rootType, { fields: combinedFields });
|
63
|
+
};
|
64
|
+
function avdlToAVSC(path) {
|
65
|
+
cache = {};
|
66
|
+
const protocol = avsc_1.readProtocol(fs.readFileSync(path, 'utf8'));
|
67
|
+
return merge({ namespace: protocol.namespace }, combine(protocol.types.pop(), protocol.types));
|
68
|
+
}
|
69
|
+
exports.avdlToAVSC = avdlToAVSC;
|
70
|
+
async function avdlToAVSCAsync(path) {
|
71
|
+
cache = {};
|
72
|
+
const protocol = await new Promise((resolve, reject) => {
|
73
|
+
avsc_1.assembleProtocol(path, (err, schema) => {
|
74
|
+
if (err) {
|
75
|
+
reject(new errors_1.ConfluentSchemaRegistryError(`${err.message}. Caused by: ${err.path}`));
|
76
|
+
}
|
77
|
+
else {
|
78
|
+
resolve(schema);
|
79
|
+
}
|
80
|
+
});
|
81
|
+
});
|
82
|
+
return merge({ namespace: protocol.namespace }, combine(protocol.types.pop(), protocol.types));
|
83
|
+
}
|
84
|
+
exports.avdlToAVSCAsync = avdlToAVSCAsync;
|
85
|
+
//# sourceMappingURL=avdlToAVSC.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"avdlToAVSC.js","sourceRoot":"","sources":["../../src/utils/avdlToAVSC.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAwB;AACxB,+BAAqD;AAErD,sCAAwD;AAkBxD,IAAI,KAAU,CAAA;AACd,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAA;AAC3B,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAc,EAAE,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAA;AAC7E,MAAM,UAAU,GAAG,CAAC,GAAY,EAAmB,EAAE,CACnD,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,GAAG,KAAK,WAAW,CAAA;AACjD,MAAM,YAAY,GAAG,CAAC,KAAc,EAAkB,EAAE,CACtD,QAAQ,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAA;AAExE,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QAAQ,CAAC,KAAK,CAAC,CAAC,CAAA;AAChG,CAAC;AALD,gCAKC;AAEM,KAAK,UAAU,eAAe,CAAC,IAAY;IAChD,KAAK,GAAG,EAAE,CAAA;IAEV,MAAM,QAAQ,GAA2B,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7E,uBAAgB,CAAC,IAAI,EAAE,CAAC,GAA0B,EAAE,MAAM,EAAE,EAAE;YAC5D,IAAI,GAAG,EAAE;gBACP,MAAM,CAAC,IAAI,qCAA4B,CAAC,GAAG,GAAG,CAAC,OAAO,gBAAgB,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;aACnF;iBAAM;gBACL,OAAO,CAAC,MAAM,CAAC,CAAA;aAChB;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAA;AAChG,CAAC;AAdD,0CAcC"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
var avdlToAVSC_1 = require("./avdlToAVSC");
|
4
|
+
exports.avdlToAVSC = avdlToAVSC_1.avdlToAVSC;
|
5
|
+
exports.avdlToAVSCAsync = avdlToAVSC_1.avdlToAVSCAsync;
|
6
|
+
var readAVSC_1 = require("./readAVSC");
|
7
|
+
exports.readAVSC = readAVSC_1.readAVSC;
|
8
|
+
exports.readAVSCAsync = readAVSC_1.readAVSCAsync;
|
9
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;AAAA,2CAA0D;AAAjD,kCAAA,UAAU,CAAA;AAAE,uCAAA,eAAe,CAAA;AACpC,uCAAoD;AAA3C,8BAAA,QAAQ,CAAA;AAAE,mCAAA,aAAa,CAAA"}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
7
|
+
const util_1 = require("util");
|
8
|
+
const errors_1 = require("../errors");
|
9
|
+
const readFileAsync = util_1.promisify(fs_1.default.readFile);
|
10
|
+
const ENCODING = 'utf-8';
|
11
|
+
function isValidSchema(rawSchema) {
|
12
|
+
return ('name' in rawSchema &&
|
13
|
+
'type' in rawSchema &&
|
14
|
+
rawSchema.type === 'record' &&
|
15
|
+
'fields' in rawSchema);
|
16
|
+
}
|
17
|
+
function validatedSchema(path, rawSchema) {
|
18
|
+
if (!isValidSchema(rawSchema)) {
|
19
|
+
throw new errors_1.ConfluentSchemaRegistryInvalidSchemaError(`${path} is not recognized as a valid AVSC file (expecting valid top-level name, type and fields attributes)`);
|
20
|
+
}
|
21
|
+
return rawSchema;
|
22
|
+
}
|
23
|
+
function readAVSC(path) {
|
24
|
+
const rawSchema = JSON.parse(fs_1.default.readFileSync(path, ENCODING));
|
25
|
+
return validatedSchema(path, rawSchema);
|
26
|
+
}
|
27
|
+
exports.readAVSC = readAVSC;
|
28
|
+
async function readAVSCAsync(path) {
|
29
|
+
const rawSchema = JSON.parse(await readFileAsync(path, ENCODING));
|
30
|
+
return validatedSchema(path, rawSchema);
|
31
|
+
}
|
32
|
+
exports.readAVSCAsync = readAVSCAsync;
|
33
|
+
//# sourceMappingURL=readAVSC.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"readAVSC.js","sourceRoot":"","sources":["../../src/utils/readAVSC.ts"],"names":[],"mappings":";;;;;AAAA,4CAAmB;AACnB,+BAAgC;AAGhC,sCAAqE;AAErE,MAAM,aAAa,GAAG,gBAAS,CAAC,YAAE,CAAC,QAAQ,CAAC,CAAA;AAC5C,MAAM,QAAQ,GAAG,OAAO,CAAA;AAExB,SAAS,aAAa,CAAC,SAAc;IACnC,OAAO,CACL,MAAM,IAAI,SAAS;QACnB,MAAM,IAAI,SAAS;QACnB,SAAS,CAAC,IAAI,KAAK,QAAQ;QAC3B,QAAQ,IAAI,SAAS,CACtB,CAAA;AACH,CAAC;AAED,SAAS,eAAe,CAAC,IAAY,EAAE,SAAc;IACnD,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE;QAC7B,MAAM,IAAI,kDAAyC,CACjD,GAAG,IAAI,sGAAsG,CAC9G,CAAA;KACF;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,SAAgB,QAAQ,CAAC,IAAY;IACnC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAA;IAC7D,OAAO,eAAe,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AACzC,CAAC;AAHD,4BAGC;AAEM,KAAK,UAAU,aAAa,CAAC,IAAY;IAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAA;IACjE,OAAO,eAAe,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AACzC,CAAC;AAHD,sCAGC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = (buffer) => ({
|
4
|
+
magicByte: buffer.slice(0, 1),
|
5
|
+
registryId: buffer.slice(1, 5).readInt32BE(0),
|
6
|
+
payload: buffer.slice(5, buffer.length),
|
7
|
+
});
|
8
|
+
//# sourceMappingURL=wireDecoder.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"wireDecoder.js","sourceRoot":"","sources":["../src/wireDecoder.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC;CACxC,CAAC,CAAA"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const DEFAULT_OFFSET = 0;
|
4
|
+
exports.MAGIC_BYTE = Buffer.alloc(1);
|
5
|
+
exports.encode = (registryId, payload) => {
|
6
|
+
const registryIdBuffer = Buffer.alloc(4);
|
7
|
+
registryIdBuffer.writeInt32BE(registryId, DEFAULT_OFFSET);
|
8
|
+
return Buffer.concat([exports.MAGIC_BYTE, registryIdBuffer, payload]);
|
9
|
+
};
|
10
|
+
//# sourceMappingURL=wireEncoder.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"wireEncoder.js","sourceRoot":"","sources":["../src/wireEncoder.ts"],"names":[],"mappings":";;AAAA,MAAM,cAAc,GAAG,CAAC,CAAA;AAEX,QAAA,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAE5B,QAAA,MAAM,GAAG,CAAC,UAAkB,EAAE,OAAe,EAAE,EAAE;IAC5D,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACxC,gBAAgB,CAAC,YAAY,CAAC,UAAU,EAAE,cAAc,CAAC,CAAA;IAEzD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,kBAAU,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAA;AAC/D,CAAC,CAAA"}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
{
|
2
|
+
"name": "@kafkajs/confluent-schema-registry",
|
3
|
+
"version": "3.3.1",
|
4
|
+
"main": "dist/index.js",
|
5
|
+
"description": "ConfluentSchemaRegistry is a library that makes it easier to interact with the Confluent schema registry, it provides convenient methods to encode, decode and register new schemas using the Apache Avro serialization format.",
|
6
|
+
"keywords": [
|
7
|
+
"confluent schema registry",
|
8
|
+
"kafka"
|
9
|
+
],
|
10
|
+
"repository": {
|
11
|
+
"type": "git",
|
12
|
+
"url": "https://github.com/kafkajs/confluent-schema-registry.git"
|
13
|
+
},
|
14
|
+
"scripts": {
|
15
|
+
"prepare:release": "./pipeline/prepareRelease.sh",
|
16
|
+
"build": "rm -rf ./dist && tsc",
|
17
|
+
"build:watch": "rm -rf ./dist && tsc --watch",
|
18
|
+
"test:unit:watch": "yarn test:unit --watch",
|
19
|
+
"test:unit": "jest",
|
20
|
+
"test": "ts-node ./dockest.ts",
|
21
|
+
"test:debug": "ts-node ./dockest.ts debug",
|
22
|
+
"lint": "eslint './src/**/*.ts'",
|
23
|
+
"format": "yarn lint --fix"
|
24
|
+
},
|
25
|
+
"dependencies": {
|
26
|
+
"ajv": "^7.1.0",
|
27
|
+
"avsc": ">= 5.4.13 < 6",
|
28
|
+
"mappersmith": ">= 2.30.1 < 3",
|
29
|
+
"protobufjs": "^6.11.4"
|
30
|
+
},
|
31
|
+
"devDependencies": {
|
32
|
+
"@types/execa": "^2.0.0",
|
33
|
+
"@types/fs-extra": "^8.0.0",
|
34
|
+
"@types/jest": "^25.2.1",
|
35
|
+
"@types/node": "^12.7.3",
|
36
|
+
"@types/prettier": "^1.18.2",
|
37
|
+
"@types/uuid": "^3.4.5",
|
38
|
+
"@typescript-eslint/eslint-plugin": "^2.1.0",
|
39
|
+
"@typescript-eslint/parser": "^2.1.0",
|
40
|
+
"@typescript-eslint/typescript-estree": "^2.1.0",
|
41
|
+
"ajv8": "npm:ajv@^8.6.3",
|
42
|
+
"dockest": "^2.1.0",
|
43
|
+
"eslint": "^6.3.0",
|
44
|
+
"eslint-config-prettier": "^6.1.0",
|
45
|
+
"eslint-plugin-no-only-tests": "^2.3.1",
|
46
|
+
"eslint-plugin-prettier": "^3.1.0",
|
47
|
+
"execa": "^2.0.4",
|
48
|
+
"fs-extra": "^8.1.0",
|
49
|
+
"jest": "^25.2.7",
|
50
|
+
"prettier": "^1.18.2",
|
51
|
+
"ts-jest": "^24.0.2",
|
52
|
+
"ts-node": "^8.3.0",
|
53
|
+
"typescript": "^3.6.2",
|
54
|
+
"uuid": "^3.3.3"
|
55
|
+
}
|
56
|
+
}
|
package/src/@types.ts
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
import { Resolver, ForSchemaOptions, Type } from 'avsc'
|
2
|
+
import { ValidateFunction } from './JsonSchema'
|
3
|
+
import Ajv from 'ajv'
|
4
|
+
|
5
|
+
export enum SchemaType {
|
6
|
+
AVRO = 'AVRO',
|
7
|
+
JSON = 'JSON',
|
8
|
+
PROTOBUF = 'PROTOBUF',
|
9
|
+
UNKNOWN = 'UNKNOWN',
|
10
|
+
}
|
11
|
+
export interface SchemaHelper {
|
12
|
+
validate(schema: Schema): void
|
13
|
+
getSubject(confluentSchema: ConfluentSchema, schema: Schema, separator: string): ConfluentSubject
|
14
|
+
toConfluentSchema(data: SchemaResponse): ConfluentSchema
|
15
|
+
updateOptionsFromSchemaReferences(
|
16
|
+
referencedSchemas: ConfluentSchema[],
|
17
|
+
options?: ProtocolOptions,
|
18
|
+
): ProtocolOptions
|
19
|
+
}
|
20
|
+
|
21
|
+
export type AvroOptions = Partial<ForSchemaOptions> & {
|
22
|
+
referencedSchemas?: AvroConfluentSchema[]
|
23
|
+
}
|
24
|
+
|
25
|
+
export type JsonOptions = ConstructorParameters<typeof Ajv>[0] & {
|
26
|
+
ajvInstance?: {
|
27
|
+
addSchema: Ajv['addSchema']
|
28
|
+
compile: (schema: any) => ValidateFunction
|
29
|
+
}
|
30
|
+
referencedSchemas?: JsonConfluentSchema[]
|
31
|
+
}
|
32
|
+
export type ProtoOptions = { messageName?: string; referencedSchemas?: ProtoConfluentSchema[] }
|
33
|
+
|
34
|
+
export interface LegacyOptions {
|
35
|
+
forSchemaOptions?: AvroOptions
|
36
|
+
}
|
37
|
+
export interface ProtocolOptions {
|
38
|
+
[SchemaType.AVRO]?: AvroOptions
|
39
|
+
[SchemaType.JSON]?: JsonOptions
|
40
|
+
[SchemaType.PROTOBUF]?: ProtoOptions
|
41
|
+
}
|
42
|
+
export type SchemaRegistryAPIClientOptions = ProtocolOptions | LegacyOptions
|
43
|
+
|
44
|
+
export interface Schema {
|
45
|
+
toBuffer(payload: object): Buffer // FIXME:
|
46
|
+
fromBuffer(buffer: Buffer, resolver?: Resolver, noCheck?: boolean): any
|
47
|
+
isValid(
|
48
|
+
payload: object,
|
49
|
+
opts?: { errorHook: (path: Array<string>, value: any, type?: any) => void },
|
50
|
+
): boolean
|
51
|
+
}
|
52
|
+
|
53
|
+
export interface RawAvroSchema {
|
54
|
+
name: string
|
55
|
+
namespace?: string
|
56
|
+
type: 'record'
|
57
|
+
fields: any[]
|
58
|
+
}
|
59
|
+
|
60
|
+
export interface AvroSchema
|
61
|
+
extends Schema,
|
62
|
+
RawAvroSchema,
|
63
|
+
Pick<Type, 'equals' | 'createResolver'> {}
|
64
|
+
|
65
|
+
export interface ConfluentSubject {
|
66
|
+
name: string
|
67
|
+
}
|
68
|
+
|
69
|
+
export interface AvroConfluentSchema {
|
70
|
+
type: SchemaType.AVRO
|
71
|
+
schema: string | RawAvroSchema
|
72
|
+
references?: SchemaReference[]
|
73
|
+
}
|
74
|
+
|
75
|
+
export type SchemaReference = {
|
76
|
+
name: string
|
77
|
+
subject: string
|
78
|
+
version: number
|
79
|
+
}
|
80
|
+
export interface ProtoConfluentSchema {
|
81
|
+
type: SchemaType.PROTOBUF
|
82
|
+
schema: string
|
83
|
+
references?: SchemaReference[]
|
84
|
+
}
|
85
|
+
export interface JsonConfluentSchema {
|
86
|
+
type: SchemaType.JSON
|
87
|
+
schema: string
|
88
|
+
references?: SchemaReference[]
|
89
|
+
}
|
90
|
+
export interface SchemaResponse {
|
91
|
+
schema: string
|
92
|
+
schemaType: string
|
93
|
+
references?: SchemaReference[]
|
94
|
+
}
|
95
|
+
|
96
|
+
export type ConfluentSchema = AvroConfluentSchema | ProtoConfluentSchema | JsonConfluentSchema
|
97
|
+
|
98
|
+
declare global {
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
100
|
+
namespace jest {
|
101
|
+
interface Matchers<R, T = {}> {
|
102
|
+
toMatchConfluentEncodedPayload(args: { registryId: number; payload: Buffer }): R
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|