confluent-schema-registry 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. package/.dockerignore +2 -0
  2. package/.prettierrc.js +8 -0
  3. package/CHANGELOG.md +166 -0
  4. package/Dockerfile +10 -0
  5. package/LICENSE +21 -0
  6. package/README.md +44 -0
  7. package/bin/avdlToAVSC.sh +9 -0
  8. package/dist/@types.d.ts +93 -0
  9. package/dist/@types.js +10 -0
  10. package/dist/@types.js.map +1 -0
  11. package/dist/AvroHelper.d.ts +12 -0
  12. package/dist/AvroHelper.js +67 -0
  13. package/dist/AvroHelper.js.map +1 -0
  14. package/dist/JsonHelper.d.ts +7 -0
  15. package/dist/JsonHelper.js +20 -0
  16. package/dist/JsonHelper.js.map +1 -0
  17. package/dist/JsonSchema.d.ts +31 -0
  18. package/dist/JsonSchema.js +58 -0
  19. package/dist/JsonSchema.js.map +1 -0
  20. package/dist/ProtoHelper.d.ts +7 -0
  21. package/dist/ProtoHelper.js +23 -0
  22. package/dist/ProtoHelper.js.map +1 -0
  23. package/dist/ProtoSchema.d.ts +14 -0
  24. package/dist/ProtoSchema.js +66 -0
  25. package/dist/ProtoSchema.js.map +1 -0
  26. package/dist/SchemaRegistry.d.ts +48 -0
  27. package/dist/SchemaRegistry.js +250 -0
  28. package/dist/SchemaRegistry.js.map +1 -0
  29. package/dist/api/index.d.ts +43 -0
  30. package/dist/api/index.js +90 -0
  31. package/dist/api/index.js.map +1 -0
  32. package/dist/api/middleware/confluentEncoderMiddleware.d.ts +3 -0
  33. package/dist/api/middleware/confluentEncoderMiddleware.js +31 -0
  34. package/dist/api/middleware/confluentEncoderMiddleware.js.map +1 -0
  35. package/dist/api/middleware/errorMiddleware.d.ts +3 -0
  36. package/dist/api/middleware/errorMiddleware.js +20 -0
  37. package/dist/api/middleware/errorMiddleware.js.map +1 -0
  38. package/dist/api/middleware/userAgent.d.ts +3 -0
  39. package/dist/api/middleware/userAgent.js +18 -0
  40. package/dist/api/middleware/userAgent.js.map +1 -0
  41. package/dist/cache.d.ts +20 -0
  42. package/dist/cache.js +24 -0
  43. package/dist/cache.js.map +1 -0
  44. package/dist/constants.d.ts +11 -0
  45. package/dist/constants.js +15 -0
  46. package/dist/constants.js.map +1 -0
  47. package/dist/errors.d.ts +14 -0
  48. package/dist/errors.js +26 -0
  49. package/dist/errors.js.map +1 -0
  50. package/dist/index.d.ts +4 -0
  51. package/dist/index.js +13 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/schemaTypeResolver.d.ts +4 -0
  54. package/dist/schemaTypeResolver.js +80 -0
  55. package/dist/schemaTypeResolver.js.map +1 -0
  56. package/dist/utils/avdlToAVSC.d.ts +2 -0
  57. package/dist/utils/avdlToAVSC.js +85 -0
  58. package/dist/utils/avdlToAVSC.js.map +1 -0
  59. package/dist/utils/index.d.ts +2 -0
  60. package/dist/utils/index.js +9 -0
  61. package/dist/utils/index.js.map +1 -0
  62. package/dist/utils/readAVSC.d.ts +3 -0
  63. package/dist/utils/readAVSC.js +33 -0
  64. package/dist/utils/readAVSC.js.map +1 -0
  65. package/dist/wireDecoder.d.ts +7 -0
  66. package/dist/wireDecoder.js +8 -0
  67. package/dist/wireDecoder.js.map +1 -0
  68. package/dist/wireEncoder.d.ts +3 -0
  69. package/dist/wireEncoder.js +10 -0
  70. package/dist/wireEncoder.js.map +1 -0
  71. package/dockest-error.json +11 -0
  72. package/dockest.ts +30 -0
  73. package/jest.setup.ts +60 -0
  74. package/package.json +56 -0
  75. package/release/CHANGELOG.md +166 -0
  76. package/release/LICENSE +21 -0
  77. package/release/README.md +44 -0
  78. package/release/dist/@types.d.ts +93 -0
  79. package/release/dist/@types.js +10 -0
  80. package/release/dist/@types.js.map +1 -0
  81. package/release/dist/AvroHelper.d.ts +12 -0
  82. package/release/dist/AvroHelper.js +67 -0
  83. package/release/dist/AvroHelper.js.map +1 -0
  84. package/release/dist/JsonHelper.d.ts +7 -0
  85. package/release/dist/JsonHelper.js +20 -0
  86. package/release/dist/JsonHelper.js.map +1 -0
  87. package/release/dist/JsonSchema.d.ts +31 -0
  88. package/release/dist/JsonSchema.js +58 -0
  89. package/release/dist/JsonSchema.js.map +1 -0
  90. package/release/dist/ProtoHelper.d.ts +7 -0
  91. package/release/dist/ProtoHelper.js +23 -0
  92. package/release/dist/ProtoHelper.js.map +1 -0
  93. package/release/dist/ProtoSchema.d.ts +14 -0
  94. package/release/dist/ProtoSchema.js +66 -0
  95. package/release/dist/ProtoSchema.js.map +1 -0
  96. package/release/dist/SchemaRegistry.d.ts +48 -0
  97. package/release/dist/SchemaRegistry.js +250 -0
  98. package/release/dist/SchemaRegistry.js.map +1 -0
  99. package/release/dist/api/index.d.ts +43 -0
  100. package/release/dist/api/index.js +90 -0
  101. package/release/dist/api/index.js.map +1 -0
  102. package/release/dist/api/middleware/confluentEncoderMiddleware.d.ts +3 -0
  103. package/release/dist/api/middleware/confluentEncoderMiddleware.js +31 -0
  104. package/release/dist/api/middleware/confluentEncoderMiddleware.js.map +1 -0
  105. package/release/dist/api/middleware/errorMiddleware.d.ts +3 -0
  106. package/release/dist/api/middleware/errorMiddleware.js +20 -0
  107. package/release/dist/api/middleware/errorMiddleware.js.map +1 -0
  108. package/release/dist/api/middleware/userAgent.d.ts +3 -0
  109. package/release/dist/api/middleware/userAgent.js +18 -0
  110. package/release/dist/api/middleware/userAgent.js.map +1 -0
  111. package/release/dist/cache.d.ts +20 -0
  112. package/release/dist/cache.js +24 -0
  113. package/release/dist/cache.js.map +1 -0
  114. package/release/dist/constants.d.ts +11 -0
  115. package/release/dist/constants.js +15 -0
  116. package/release/dist/constants.js.map +1 -0
  117. package/release/dist/errors.d.ts +14 -0
  118. package/release/dist/errors.js +26 -0
  119. package/release/dist/errors.js.map +1 -0
  120. package/release/dist/index.d.ts +4 -0
  121. package/release/dist/index.js +13 -0
  122. package/release/dist/index.js.map +1 -0
  123. package/release/dist/schemaTypeResolver.d.ts +4 -0
  124. package/release/dist/schemaTypeResolver.js +80 -0
  125. package/release/dist/schemaTypeResolver.js.map +1 -0
  126. package/release/dist/utils/avdlToAVSC.d.ts +2 -0
  127. package/release/dist/utils/avdlToAVSC.js +85 -0
  128. package/release/dist/utils/avdlToAVSC.js.map +1 -0
  129. package/release/dist/utils/index.d.ts +2 -0
  130. package/release/dist/utils/index.js +9 -0
  131. package/release/dist/utils/index.js.map +1 -0
  132. package/release/dist/utils/readAVSC.d.ts +3 -0
  133. package/release/dist/utils/readAVSC.js +33 -0
  134. package/release/dist/utils/readAVSC.js.map +1 -0
  135. package/release/dist/wireDecoder.d.ts +7 -0
  136. package/release/dist/wireDecoder.js +8 -0
  137. package/release/dist/wireDecoder.js.map +1 -0
  138. package/release/dist/wireEncoder.d.ts +3 -0
  139. package/release/dist/wireEncoder.js +10 -0
  140. package/release/dist/wireEncoder.js.map +1 -0
  141. package/release/package.json +56 -0
  142. package/src/@types.ts +105 -0
  143. package/src/AvroHelper.ts +91 -0
  144. package/src/JsonHelper.ts +35 -0
  145. package/src/JsonSchema.ts +80 -0
  146. package/src/ProtoHelper.ts +38 -0
  147. package/src/ProtoSchema.ts +80 -0
  148. package/src/SchemaRegistry.avro.spec.ts +558 -0
  149. package/src/SchemaRegistry.json.spec.ts +364 -0
  150. package/src/SchemaRegistry.newApi.spec.ts +622 -0
  151. package/src/SchemaRegistry.protobuf.spec.ts +372 -0
  152. package/src/SchemaRegistry.spec.ts +252 -0
  153. package/src/SchemaRegistry.ts +387 -0
  154. package/src/api/index.spec.ts +23 -0
  155. package/src/api/index.ts +121 -0
  156. package/src/api/middleware/confluentEncoderMiddleware.ts +36 -0
  157. package/src/api/middleware/errorMiddleware.spec.ts +67 -0
  158. package/src/api/middleware/errorMiddleware.ts +37 -0
  159. package/src/api/middleware/userAgent.spec.ts +53 -0
  160. package/src/api/middleware/userAgent.ts +19 -0
  161. package/src/cache.ts +34 -0
  162. package/src/constants.ts +13 -0
  163. package/src/errors.ts +26 -0
  164. package/src/index.ts +4 -0
  165. package/src/schemaTypeResolver.ts +101 -0
  166. package/src/utils/avdlToAVSC.spec.ts +79 -0
  167. package/src/utils/avdlToAVSC.ts +106 -0
  168. package/src/utils/index.ts +2 -0
  169. package/src/utils/readAVSC.spec.ts +23 -0
  170. package/src/utils/readAVSC.ts +36 -0
  171. package/src/wireDecoder.ts +5 -0
  172. package/src/wireEncoder.ts +10 -0
  173. package/tsconfig.json +22 -0
package/.dockerignore ADDED
@@ -0,0 +1,2 @@
1
+ */node_modules
2
+ *.log
package/.prettierrc.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ 'max-len': 'off',
3
+ printWidth: 100,
4
+ semi: false,
5
+ singleQuote: true,
6
+ tabWidth: 2,
7
+ trailingComma: 'all',
8
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,166 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [3.3.0] - 2022-10-04
9
+
10
+ ### Added
11
+
12
+ - Support [schema references](https://docs.confluent.io/platform/current/schema-registry/serdes-develop/index.html#schema-references) for Avro, Protocol Buffer, and JSON schema [#197](https://github.com/kafkajs/confluent-schema-registry/pull/197)
13
+
14
+ ### Fixed
15
+
16
+ - Fix Apicurio compatibility with register function [#201](https://github.com/kafkajs/confluent-schema-registry/pull/201)
17
+
18
+ ## [3.2.1] - 2022-01-28
19
+
20
+ ### Fixed
21
+
22
+ - Don't swallow error message from client-side errors from registry requests [#176](https://github.com/kafkajs/confluent-schema-registry/pull/176)
23
+
24
+ ## [3.2.0] - 2021-11-22
25
+
26
+ ### Added
27
+
28
+ - Add reader schema option when decoding Avro messages [#166](https://github.com/kafkajs/confluent-schema-registry/pull/166)
29
+
30
+ ## [3.1.1] - 2021-11-03
31
+
32
+ ### Fixed
33
+
34
+ - Support backwards incompatible changes in Ajv 8 when passing in Ajv instance in JSON Schema options [#163](https://github.com/kafkajs/confluent-schema-registry/pull/163)
35
+
36
+ ## [3.1.0] - 2021-11-03
37
+
38
+ ### Added
39
+
40
+ - Allow passing in Ajv instance in JSON Schema options [#133](https://github.com/kafkajs/confluent-schema-registry/pull/133)
41
+
42
+ ### Fixed
43
+
44
+ - Fix backwards compatibility with older Schema Registry versions [#158](https://github.com/kafkajs/confluent-schema-registry/pull/158)
45
+
46
+ ### Fixed
47
+
48
+ - Fix gateway config for when setting HTTP agent [#127](https://github.com/kafkajs/confluent-schema-registry/pull/127)
49
+
50
+ ## [3.0.1] - 2021-06-11
51
+ ### Fixed
52
+
53
+ - Fix gateway config for when setting HTTP agent [#127](https://github.com/kafkajs/confluent-schema-registry/pull/127)
54
+
55
+ ## [3.0.0] - 2021-05-20
56
+
57
+ This version is non-breaking for the overwhelming majority of users.
58
+
59
+ When creating an instance of SchemaRegistry for Protobuf without the [`messageName`
60
+ parameter](https://kafkajs.github.io/confluent-schema-registry/docs/usage#protobuf-1)
61
+ confluent-schema-registry would, under certain circumstances, default
62
+ to the wrong message type in the schema. Specifically, instead of defaulting to
63
+ the first message type in the schema it would erroneously default to the first
64
+ message type that did not define a nested type.
65
+
66
+ **If you were relying on this behavior may need to either**:
67
+
68
+ * Start passing [the `messageName` parameter](https://kafkajs.github.io/confluent-schema-registry/docs/usage#protobuf-1) instead of relying on the default behavior
69
+ * Update your schemas and re-ingest messages accordingly
70
+
71
+ See issue [#112](https://github.com/kafkajs/confluent-schema-registry/issues/112) for
72
+ more info
73
+
74
+ ### Added
75
+
76
+ - Allow setting HTTP agent [#108](https://github.com/kafkajs/confluent-schema-registry/pull/108)
77
+
78
+ ### Fixed
79
+
80
+ - Fix default nested Protobuf type [#113](https://github.com/kafkajs/confluent-schema-registry/pull/113)
81
+
82
+ ## [2.0.1] - 2021-04-02
83
+
84
+ - Fix export of SchemaType [#100](https://github.com/kafkajs/confluent-schema-registry/pull/100)
85
+
86
+ ## [2.0.0] - 2021-02-28
87
+
88
+ This version adds support for Protobuf and JSON Schema, in addition to the already
89
+ supported Avro format!
90
+
91
+ See [Migrating to v2](https://kafkajs.github.io/confluent-schema-registry/docs/v2)
92
+ for information on how to adapt your application to the new API. For most users,
93
+ the change should be rather minor.
94
+
95
+ Big thanks to @dskatz22 and @Malkiz for their significant contributions!
96
+
97
+ ### Added
98
+
99
+ - Support Protobuf and JSON Schema [#93](https://github.com/kafkajs/confluent-schema-registry/pull/93)
100
+
101
+ ## [1.0.6] - 2020-07-02
102
+
103
+ ### Added
104
+
105
+ - Support pre registered schemas by adding method `getRegistryIdBySchema` [#58](https://github.com/kafkajs/confluent-schema-registry/pull/58)
106
+
107
+ ## [1.0.5] - 2020-03-18
108
+
109
+ ### Added
110
+
111
+ - Prevent Unnecessary Requests on Cache Misses [#48](https://github.com/kafkajs/confluent-schema-registry/pull/48)
112
+
113
+ ## [1.0.4] - 2020-03-07
114
+
115
+ ### Added
116
+
117
+ - Support ForSchemaOption to call avro.Type.forSchema() [#47](https://github.com/kafkajs/confluent-schema-registry/pull/47)
118
+
119
+ ## [1.0.3] - 2020-02-11
120
+
121
+ ### Added
122
+
123
+ - Support sharing of types between protocols [#43](https://github.com/kafkajs/confluent-schema-registry/pull/43)
124
+
125
+ ### Fixed
126
+
127
+ - Fix SchemaRegistry host port [#40](https://github.com/kafkajs/confluent-schema-registry/pull/40)
128
+ - Add string as possible type for subject version [#38](https://github.com/kafkajs/confluent-schema-registry/pull/38)
129
+
130
+ ## [1.0.2] - 2019-11-28
131
+
132
+ ### Added
133
+
134
+ - Allow for specifying subjects explicitly [#19](https://github.com/kafkajs/confluent-schema-registry/pull/19)
135
+
136
+ ### Fixed
137
+
138
+ - Fix `@types/jest` issue [#29](https://github.com/kafkajs/confluent-schema-registry/pull/29)
139
+ - Fix `es-abstract` version issue [28](https://github.com/kafkajs/confluent-schema-registry/pull/28)
140
+
141
+ ## [1.0.1] - 2019-10-25
142
+
143
+ ### Added
144
+
145
+ - Added the schema compatibility remaining constants [#14](https://github.com/kafkajs/confluent-schema-registry/pull/14)
146
+ - Added method to fetch latest schema id by subject [#17](https://github.com/kafkajs/confluent-schema-registry/issues/17)
147
+ - Added method to get the schemaID based on subject [#18](https://github.com/kafkajs/confluent-schema-registry/pull/18)
148
+ - Support basic auth authentication [#21](https://github.com/kafkajs/confluent-schema-registry/pull/21)
149
+
150
+ ## [1.0.0] - 2019-09-13
151
+
152
+ ### Changed
153
+
154
+ - See `0.2.0` version
155
+
156
+ ## [0.2.0] - 2019-09-13
157
+
158
+ ### Changed
159
+
160
+ - Version `0.1.0` didn't transpile the Typescript files
161
+
162
+ ## [0.1.0] - 2019-09-12
163
+
164
+ ### Added
165
+
166
+ - Encode, decode and sync operations
package/Dockerfile ADDED
@@ -0,0 +1,10 @@
1
+ FROM node:8.11.4
2
+
3
+ WORKDIR /app/website
4
+
5
+ EXPOSE 3000 35729
6
+ COPY ./docs /app/docs
7
+ COPY ./website /app/website
8
+ RUN yarn install
9
+
10
+ CMD ["yarn", "start"]
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Erik Engervall (erik.engervall@gmail.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # confluent-schema-registry
2
+
3
+ `@kafkajs/confluent-schema-registry` 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 and Confluent's [wire format](https://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html#wire-format).
4
+
5
+ [![Build Status](https://dev.azure.com/tulios/ConfluentSchemaRegistry/_apis/build/status/kafkajs.confluent-schema-registry?branchName=master)](https://dev.azure.com/tulios/ConfluentSchemaRegistry/_build/latest?definitionId=3&branchName=master)
6
+
7
+ ## Getting started
8
+
9
+ ```sh
10
+ npm install @kafkajs/confluent-schema-registry
11
+ # yarn add @kafkajs/confluent-schema-registry
12
+ ```
13
+
14
+ ```javascript
15
+ const { Kafka } = require('kafkajs')
16
+ const { SchemaRegistry } = require('@kafkajs/confluent-schema-registry')
17
+
18
+ const kafka = new Kafka({ clientId: 'my-app', brokers: ['kafka1:9092'] })
19
+ const registry = new SchemaRegistry({ host: 'http://registry:8081/' })
20
+ const consumer = kafka.consumer({ groupId: 'test-group' })
21
+
22
+ const run = async () => {
23
+ await consumer.connect()
24
+ await consumer.subscribe({ topic: 'test-topic', fromBeginning: true })
25
+
26
+ await consumer.run({
27
+ eachMessage: async ({ topic, partition, message }) => {
28
+ const decodedKey = await registry.decode(message.key)
29
+ const decodedValue = await registry.decode(message.value)
30
+ console.log({ decodedKey, decodedValue })
31
+ },
32
+ })
33
+ }
34
+
35
+ run().catch(console.error)
36
+ ```
37
+
38
+ ## Documentation
39
+
40
+ Learn more about using [KafkaJS Confluent Schema registry on the official site!](https://kafkajs.github.io/confluent-schema-registry/)
41
+
42
+ ## License
43
+
44
+ See [LICENSE](https://github.com/kafkajs/confluent-schema-registry/blob/master/LICENSE) for more details.
@@ -0,0 +1,9 @@
1
+ avdl_path=$1
2
+ avsc_name=$2
3
+
4
+ if [ -z "${avdl_path}" ]; then
5
+ echo "AVDL path not defined. e.g. ./bin/protocolToSchema.sh /path/to.avdl"
6
+ exit;
7
+ fi
8
+
9
+ docker run --rm -v ${PWD}:/share coderfi/avro-tools:1.7.7 idl2schemata ${avdl_path} tmp && cat tmp/${avsc_name}.avsc
@@ -0,0 +1,93 @@
1
+ /// <reference types="node" />
2
+ import { Resolver, ForSchemaOptions, Type } from 'avsc';
3
+ import { ValidateFunction } from './JsonSchema';
4
+ import Ajv from 'ajv';
5
+ export declare 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(referencedSchemas: ConfluentSchema[], options?: ProtocolOptions): ProtocolOptions;
16
+ }
17
+ export declare type AvroOptions = Partial<ForSchemaOptions> & {
18
+ referencedSchemas?: AvroConfluentSchema[];
19
+ };
20
+ export declare type JsonOptions = ConstructorParameters<typeof Ajv>[0] & {
21
+ ajvInstance?: {
22
+ addSchema: Ajv['addSchema'];
23
+ compile: (schema: any) => ValidateFunction;
24
+ };
25
+ referencedSchemas?: JsonConfluentSchema[];
26
+ };
27
+ export declare type ProtoOptions = {
28
+ messageName?: string;
29
+ referencedSchemas?: ProtoConfluentSchema[];
30
+ };
31
+ export interface LegacyOptions {
32
+ forSchemaOptions?: AvroOptions;
33
+ }
34
+ export interface ProtocolOptions {
35
+ [SchemaType.AVRO]?: AvroOptions;
36
+ [SchemaType.JSON]?: JsonOptions;
37
+ [SchemaType.PROTOBUF]?: ProtoOptions;
38
+ }
39
+ export declare type SchemaRegistryAPIClientOptions = ProtocolOptions | LegacyOptions;
40
+ export interface Schema {
41
+ toBuffer(payload: object): Buffer;
42
+ fromBuffer(buffer: Buffer, resolver?: Resolver, noCheck?: boolean): any;
43
+ isValid(payload: object, opts?: {
44
+ errorHook: (path: Array<string>, value: any, type?: any) => void;
45
+ }): boolean;
46
+ }
47
+ export interface RawAvroSchema {
48
+ name: string;
49
+ namespace?: string;
50
+ type: 'record';
51
+ fields: any[];
52
+ }
53
+ export interface AvroSchema extends Schema, RawAvroSchema, Pick<Type, 'equals' | 'createResolver'> {
54
+ }
55
+ export interface ConfluentSubject {
56
+ name: string;
57
+ }
58
+ export interface AvroConfluentSchema {
59
+ type: SchemaType.AVRO;
60
+ schema: string | RawAvroSchema;
61
+ references?: SchemaReference[];
62
+ }
63
+ export declare type SchemaReference = {
64
+ name: string;
65
+ subject: string;
66
+ version: number;
67
+ };
68
+ export interface ProtoConfluentSchema {
69
+ type: SchemaType.PROTOBUF;
70
+ schema: string;
71
+ references?: SchemaReference[];
72
+ }
73
+ export interface JsonConfluentSchema {
74
+ type: SchemaType.JSON;
75
+ schema: string;
76
+ references?: SchemaReference[];
77
+ }
78
+ export interface SchemaResponse {
79
+ schema: string;
80
+ schemaType: string;
81
+ references?: SchemaReference[];
82
+ }
83
+ export declare type ConfluentSchema = AvroConfluentSchema | ProtoConfluentSchema | JsonConfluentSchema;
84
+ declare global {
85
+ namespace jest {
86
+ interface Matchers<R, T = {}> {
87
+ toMatchConfluentEncodedPayload(args: {
88
+ registryId: number;
89
+ payload: Buffer;
90
+ }): R;
91
+ }
92
+ }
93
+ }
package/dist/@types.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var SchemaType;
4
+ (function (SchemaType) {
5
+ SchemaType["AVRO"] = "AVRO";
6
+ SchemaType["JSON"] = "JSON";
7
+ SchemaType["PROTOBUF"] = "PROTOBUF";
8
+ SchemaType["UNKNOWN"] = "UNKNOWN";
9
+ })(SchemaType = exports.SchemaType || (exports.SchemaType = {}));
10
+ //# sourceMappingURL=@types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"@types.js","sourceRoot":"","sources":["../src/@types.ts"],"names":[],"mappings":";;AAIA,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,2BAAa,CAAA;IACb,mCAAqB,CAAA;IACrB,iCAAmB,CAAA;AACrB,CAAC,EALW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAKrB"}
@@ -0,0 +1,12 @@
1
+ import { AvroSchema, RawAvroSchema, AvroOptions, ConfluentSchema, SchemaHelper, ConfluentSubject, ProtocolOptions, AvroConfluentSchema } from './@types';
2
+ import avro from 'avsc';
3
+ import { SchemaResponse } from './@types';
4
+ export default class AvroHelper implements SchemaHelper {
5
+ private getRawAvroSchema;
6
+ getAvroSchema(schema: ConfluentSchema | RawAvroSchema, opts?: AvroOptions): avro.Type;
7
+ validate(avroSchema: AvroSchema): void;
8
+ getSubject(schema: AvroConfluentSchema, avroSchema: AvroSchema, separator: string): ConfluentSubject;
9
+ private isRawAvroSchema;
10
+ toConfluentSchema(data: SchemaResponse): AvroConfluentSchema;
11
+ updateOptionsFromSchemaReferences(referencedSchemas: AvroConfluentSchema[], options?: ProtocolOptions): ProtocolOptions;
12
+ }
@@ -0,0 +1,67 @@
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 errors_1 = require("./errors");
7
+ const avsc_1 = __importDefault(require("avsc"));
8
+ const _types_1 = require("./@types");
9
+ class AvroHelper {
10
+ getRawAvroSchema(schema) {
11
+ return (typeof schema.schema === 'string'
12
+ ? JSON.parse(schema.schema)
13
+ : schema.schema);
14
+ }
15
+ getAvroSchema(schema, opts) {
16
+ const rawSchema = this.isRawAvroSchema(schema)
17
+ ? schema
18
+ : this.getRawAvroSchema(schema);
19
+ // @ts-ignore TODO: Fix typings for Schema...
20
+ const addReferencedSchemas = (userHook) => (schema, opts) => {
21
+ var _a;
22
+ const avroOpts = opts;
23
+ (_a = avroOpts === null || avroOpts === void 0 ? void 0 : avroOpts.referencedSchemas) === null || _a === void 0 ? void 0 : _a.forEach(subSchema => {
24
+ const rawSubSchema = this.getRawAvroSchema(subSchema);
25
+ avroOpts.typeHook = userHook;
26
+ avsc_1.default.Type.forSchema(rawSubSchema, avroOpts);
27
+ });
28
+ if (userHook) {
29
+ return userHook(schema, opts);
30
+ }
31
+ };
32
+ const avroSchema = avsc_1.default.Type.forSchema(rawSchema, {
33
+ ...opts,
34
+ typeHook: addReferencedSchemas(opts === null || opts === void 0 ? void 0 : opts.typeHook),
35
+ });
36
+ return avroSchema;
37
+ }
38
+ validate(avroSchema) {
39
+ if (!avroSchema.name) {
40
+ throw new errors_1.ConfluentSchemaRegistryArgumentError(`Invalid name: ${avroSchema.name}`);
41
+ }
42
+ }
43
+ getSubject(schema,
44
+ // @ts-ignore
45
+ avroSchema, separator) {
46
+ const rawSchema = this.getRawAvroSchema(schema);
47
+ if (!rawSchema.namespace) {
48
+ throw new errors_1.ConfluentSchemaRegistryArgumentError(`Invalid namespace: ${rawSchema.namespace}`);
49
+ }
50
+ const subject = {
51
+ name: [rawSchema.namespace, rawSchema.name].join(separator),
52
+ };
53
+ return subject;
54
+ }
55
+ isRawAvroSchema(schema) {
56
+ const asRawAvroSchema = schema;
57
+ return asRawAvroSchema.name != null && asRawAvroSchema.type != null;
58
+ }
59
+ toConfluentSchema(data) {
60
+ return { type: _types_1.SchemaType.AVRO, schema: data.schema, references: data.references };
61
+ }
62
+ updateOptionsFromSchemaReferences(referencedSchemas, options = {}) {
63
+ return { ...options, [_types_1.SchemaType.AVRO]: { ...options[_types_1.SchemaType.AVRO], referencedSchemas } };
64
+ }
65
+ }
66
+ exports.default = AvroHelper;
67
+ //# sourceMappingURL=AvroHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Avro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9F,CAAC;CACF;AA3ED,6BA2EC"}
@@ -0,0 +1,7 @@
1
+ import { Schema, SchemaHelper, ConfluentSubject, SchemaResponse, ProtocolOptions, JsonConfluentSchema } from './@types';
2
+ export default class JsonHelper implements SchemaHelper {
3
+ validate(_schema: Schema): void;
4
+ getSubject(_confluentSchema: JsonConfluentSchema, _schema: Schema, _separator: string): ConfluentSubject;
5
+ toConfluentSchema(data: SchemaResponse): JsonConfluentSchema;
6
+ updateOptionsFromSchemaReferences(referencedSchemas: JsonConfluentSchema[], options?: ProtocolOptions): ProtocolOptions;
7
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const _types_1 = require("./@types");
4
+ const errors_1 = require("./errors");
5
+ class JsonHelper {
6
+ validate(_schema) {
7
+ return;
8
+ }
9
+ getSubject(_confluentSchema, _schema, _separator) {
10
+ throw new errors_1.ConfluentSchemaRegistryError('not implemented yet');
11
+ }
12
+ toConfluentSchema(data) {
13
+ return { type: _types_1.SchemaType.JSON, schema: data.schema, references: data.references };
14
+ }
15
+ updateOptionsFromSchemaReferences(referencedSchemas, options = {}) {
16
+ return { ...options, [_types_1.SchemaType.JSON]: { ...options[_types_1.SchemaType.JSON], referencedSchemas } };
17
+ }
18
+ }
19
+ exports.default = JsonHelper;
20
+ //# sourceMappingURL=JsonHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonHelper.js","sourceRoot":"","sources":["../src/JsonHelper.ts"],"names":[],"mappings":";;AAAA,qCAQiB;AACjB,qCAAuD;AAEvD,MAAqB,UAAU;IACtB,QAAQ,CAAC,OAAe;QAC7B,OAAM;IACR,CAAC;IAEM,UAAU,CACf,gBAAqC,EACrC,OAAe,EACf,UAAkB;QAElB,MAAM,IAAI,qCAA4B,CAAC,qBAAqB,CAAC,CAAA;IAC/D,CAAC;IAEM,iBAAiB,CAAC,IAAoB;QAC3C,OAAO,EAAE,IAAI,EAAE,mBAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAA;IACpF,CAAC;IAED,iCAAiC,CAC/B,iBAAwC,EACxC,UAA2B,EAAE;QAE7B,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,mBAAU,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAU,CAAC,IAAI,CAAC,EAAE,iBAAiB,EAAE,EAAE,CAAA;IAC9F,CAAC;CACF;AAvBD,6BAuBC"}
@@ -0,0 +1,31 @@
1
+ /// <reference types="node" />
2
+ import { Schema, JsonOptions, JsonConfluentSchema } from './@types';
3
+ interface BaseAjvValidationError {
4
+ data?: unknown;
5
+ schema?: unknown;
6
+ }
7
+ interface OldAjvValidationError extends BaseAjvValidationError {
8
+ dataPath: string;
9
+ instancePath?: string;
10
+ }
11
+ interface NewAjvValidationError extends BaseAjvValidationError {
12
+ instancePath: string;
13
+ }
14
+ declare type AjvValidationError = OldAjvValidationError | NewAjvValidationError;
15
+ export interface ValidateFunction {
16
+ (this: any, data: any): boolean;
17
+ errors?: null | AjvValidationError[];
18
+ }
19
+ export default class JsonSchema implements Schema {
20
+ private validate;
21
+ constructor(schema: JsonConfluentSchema, opts?: JsonOptions);
22
+ private getJsonSchema;
23
+ private validatePayload;
24
+ toBuffer(payload: object): Buffer;
25
+ fromBuffer(buffer: Buffer): any;
26
+ isValid(payload: object, opts?: {
27
+ errorHook: (path: Array<string>, value: any, type?: any) => void;
28
+ }): boolean;
29
+ private isOldAjvValidationError;
30
+ }
31
+ export {};
@@ -0,0 +1,58 @@
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 ajv_1 = __importDefault(require("ajv"));
7
+ const errors_1 = require("./errors");
8
+ class JsonSchema {
9
+ constructor(schema, opts) {
10
+ this.validate = this.getJsonSchema(schema, opts);
11
+ }
12
+ getJsonSchema(schema, opts) {
13
+ var _a;
14
+ const ajv = (_a = opts === null || opts === void 0 ? void 0 : opts.ajvInstance) !== null && _a !== void 0 ? _a : new ajv_1.default(opts);
15
+ const referencedSchemas = opts === null || opts === void 0 ? void 0 : opts.referencedSchemas;
16
+ if (referencedSchemas) {
17
+ referencedSchemas.forEach(rawSchema => {
18
+ const $schema = JSON.parse(rawSchema.schema);
19
+ ajv.addSchema($schema, $schema['$id']);
20
+ });
21
+ }
22
+ const validate = ajv.compile(JSON.parse(schema.schema));
23
+ return validate;
24
+ }
25
+ validatePayload(payload) {
26
+ const paths = [];
27
+ if (!this.isValid(payload, { errorHook: path => paths.push(path) })) {
28
+ throw new errors_1.ConfluentSchemaRegistryValidationError('invalid payload', paths);
29
+ }
30
+ }
31
+ toBuffer(payload) {
32
+ this.validatePayload(payload);
33
+ return Buffer.from(JSON.stringify(payload));
34
+ }
35
+ fromBuffer(buffer) {
36
+ const payload = JSON.parse(buffer.toString());
37
+ this.validatePayload(payload);
38
+ return payload;
39
+ }
40
+ isValid(payload, opts) {
41
+ var _a;
42
+ if (!this.validate(payload)) {
43
+ if (opts === null || opts === void 0 ? void 0 : opts.errorHook) {
44
+ for (const err of (_a = this.validate.errors) !== null && _a !== void 0 ? _a : []) {
45
+ const path = this.isOldAjvValidationError(err) ? err.dataPath : err.instancePath;
46
+ opts === null || opts === void 0 ? void 0 : opts.errorHook([path], err.data, err.schema);
47
+ }
48
+ }
49
+ return false;
50
+ }
51
+ return true;
52
+ }
53
+ isOldAjvValidationError(error) {
54
+ return error.dataPath != null;
55
+ }
56
+ }
57
+ exports.default = JsonSchema;
58
+ //# sourceMappingURL=JsonSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonSchema.js","sourceRoot":"","sources":["../src/JsonSchema.ts"],"names":[],"mappings":";;;;;AACA,8CAAqB;AACrB,qCAAiE;AAoBjE,MAAqB,UAAU;IAG7B,YAAY,M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AEM,UAAU,CAAC,MAAc;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC7C,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QAC7B,OAAO,OAAO,CAAA;IAChB,CAAC;IAEM,OAAO,CACZ,OAAe,EACf,IAA2E;;QAE3E,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC3B,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE;gBAC9D,KAAK,MAAM,GAAG,UAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,mCAAE,EAAE,EAAE;oBAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAA;oBAChF,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAC;iBAC9C;aACF;YACD,OAAO,KAAK,CAAA;SACb;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,uBAAuB,CAAC,KAAyB;QACvD,OAAQ,KAA+B,CAAC,QAAQ,IAAI,IAAI,CAAA;IAC1D,CAAC;CACF;AAzDD,6BAyDC"}
@@ -0,0 +1,7 @@
1
+ import { Schema, SchemaHelper, ConfluentSubject, SchemaResponse, ProtocolOptions, ProtoConfluentSchema } from './@types';
2
+ export default class ProtoHelper implements SchemaHelper {
3
+ validate(_schema: Schema): void;
4
+ getSubject(_confluentSchema: ProtoConfluentSchema, _schema: Schema, _separator: string): ConfluentSubject;
5
+ toConfluentSchema(data: SchemaResponse): ProtoConfluentSchema;
6
+ updateOptionsFromSchemaReferences(referencedSchemas: ProtoConfluentSchema[], options?: ProtocolOptions): ProtocolOptions;
7
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const _types_1 = require("./@types");
4
+ const errors_1 = require("./errors");
5
+ class ProtoHelper {
6
+ validate(_schema) {
7
+ return;
8
+ }
9
+ getSubject(_confluentSchema, _schema, _separator) {
10
+ throw new errors_1.ConfluentSchemaRegistryError('not implemented yet');
11
+ }
12
+ toConfluentSchema(data) {
13
+ return { type: _types_1.SchemaType.PROTOBUF, schema: data.schema, references: data.references };
14
+ }
15
+ updateOptionsFromSchemaReferences(referencedSchemas, options = {}) {
16
+ return {
17
+ ...options,
18
+ [_types_1.SchemaType.PROTOBUF]: { ...options[_types_1.SchemaType.PROTOBUF], referencedSchemas },
19
+ };
20
+ }
21
+ }
22
+ exports.default = ProtoHelper;
23
+ //# sourceMappingURL=ProtoHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProtoHelper.js","sourceRoot":"","sources":["../src/ProtoHelper.ts"],"names":[],"mappings":";;AAAA,qCAQiB;AACjB,qCAAuD;AAEvD,MAAqB,WAAW;IACvB,QAAQ,CAAC,OAAe;QAC7B,OAAM;IACR,CAAC;IAEM,UAAU,CACf,gBAAsC,EACtC,OAAe,EACf,UAAkB;QAElB,MAAM,IAAI,qCAA4B,CAAC,qBAAqB,CAAC,CAAA;IAC/D,CAAC;IAEM,iBAAiB,CAAC,IAAoB;QAC3C,OAAO,EAAE,IAAI,EAAE,mBAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAA;IACxF,CAAC;IAED,iCAAiC,CAC/B,iBAAyC,EACzC,UAA2B,EAAE;QAE7B,OAAO;YACL,GAAG,OAAO;YACV,CAAC,mBAAU,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAU,CAAC,QAAQ,CAAC,EAAE,iBAAiB,EAAE;SAC9E,CAAA;IACH,CAAC;CACF;AA1BD,8BA0BC"}
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import { Schema, ProtoOptions, ProtoConfluentSchema } from './@types';
3
+ export default class ProtoSchema implements Schema {
4
+ private message;
5
+ constructor(schema: ProtoConfluentSchema, opts?: ProtoOptions);
6
+ private getNestedTypeName;
7
+ private getTypeName;
8
+ private trimStart;
9
+ toBuffer(payload: object): Buffer;
10
+ fromBuffer(buffer: Buffer): any;
11
+ isValid(payload: object, opts?: {
12
+ errorHook: (path: Array<string>, value: any, type?: any) => void;
13
+ }): boolean;
14
+ }