confluent-schema-registry 3.3.5 → 3.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/bin/avdlToAVSC.sh +1 -1
  3. package/dist/JsonSchema.js +1 -1
  4. package/dist/JsonSchema.js.map +1 -1
  5. package/dockest-error.json +3 -7
  6. package/jest.setup.ts +23 -13
  7. package/package.json +11 -17
  8. package/src/@types.ts +6 -13
  9. package/src/AvroHelper.ts +2 -3
  10. package/src/JsonSchema.ts +27 -15
  11. package/src/SchemaRegistry.json.spec.ts +18 -1
  12. package/src/SchemaRegistry.newApi.spec.ts +1 -1
  13. package/src/SchemaRegistry.spec.ts +15 -0
  14. package/src/SchemaRegistry.ts +16 -17
  15. package/src/api/index.spec.ts +24 -2
  16. package/src/api/index.ts +11 -2
  17. package/src/api/middleware/errorMiddleware.ts +1 -1
  18. package/src/constants.ts +1 -1
  19. package/src/index.ts +2 -1
  20. package/src/schemaTypeResolver.ts +2 -1
  21. package/src/utils/avdlToAVSC.spec.ts +28 -5
  22. package/src/utils/avdlToAVSC.ts +3 -3
  23. package/tmp/Array.avsc +22 -0
  24. package/tmp/Array1.avsc +28 -0
  25. package/tmp/Array2.avsc +17 -0
  26. package/tmp/Array3.avsc +17 -0
  27. package/tmp/ArrayUnion.avsc +23 -0
  28. package/tmp/Bam.avsc +9 -0
  29. package/tmp/Bar.avsc +46 -0
  30. package/tmp/Baz.avsc +39 -0
  31. package/tmp/Complex.avsc +81 -0
  32. package/tmp/Enum.avsc +13 -0
  33. package/tmp/EnumUnion.avsc +14 -0
  34. package/tmp/Foos.avsc +6 -0
  35. package/tmp/ImportMultipleNamespaces.avsc +35 -0
  36. package/tmp/KeyValue.avsc +12 -0
  37. package/tmp/Metadata.avsc +27 -0
  38. package/tmp/Multiple.avsc +26 -0
  39. package/tmp/MultipleNamespaces.avsc +44 -0
  40. package/tmp/MultipleUnion.avsc +28 -0
  41. package/tmp/Simple.avsc +9 -0
  42. package/tmp/Two.avsc +19 -0
  43. package/tmp/Union.avsc +20 -0
  44. package/dockest.ts +0 -30
@@ -1,7 +1,7 @@
1
1
  import path from 'path'
2
- import fs from 'fs-extra'
3
- import execa from 'execa'
4
2
  import avro from 'avsc'
3
+ import { exec } from 'child_process'
4
+ import fs from 'node:fs'
5
5
 
6
6
  import SchemaRegistry from '../SchemaRegistry'
7
7
  import { avdlToAVSCAsync } from './avdlToAVSC'
@@ -9,13 +9,26 @@ import { avdlToAVSCAsync } from './avdlToAVSC'
9
9
  const registry = new SchemaRegistry({ host: 'http://localhost:8982' })
10
10
  const absolutePath = (...paths: string[]) => path.join(__dirname, '../..', ...paths)
11
11
 
12
+ const promisifiedExec = async (command: string): Promise<string> => {
13
+ return new Promise((resolve, reject) => {
14
+ exec(command, (error, stdout) => {
15
+ if (error) {
16
+ return reject(error)
17
+ }
18
+
19
+ return resolve(stdout)
20
+ })
21
+ })
22
+ }
23
+
12
24
  const compareWithJavaImplementation = (avdlPath: string, name: string) => async () => {
13
25
  const absolutePathToAvdlToAVSC = absolutePath('./bin/avdlToAVSC.sh')
14
- const execaArgs = [`./fixtures/avdl/${avdlPath}`, name]
15
26
 
16
27
  let expectedAVSC
17
28
  try {
18
- const { stdout: result } = await execa(absolutePathToAvdlToAVSC, execaArgs)
29
+ const result = await promisifiedExec(
30
+ `${absolutePathToAvdlToAVSC} ./fixtures/avdl/${avdlPath} ${name}`,
31
+ )
19
32
  expectedAVSC = JSON.parse(result)
20
33
  } catch (error) {
21
34
  console.error(`Error when running ${absolutePathToAvdlToAVSC}`, error) // eslint-disable-line no-console
@@ -31,7 +44,17 @@ const compareWithJavaImplementation = (avdlPath: string, name: string) => async
31
44
 
32
45
  beforeAll(async () => {
33
46
  jest.setTimeout(10000)
34
- await fs.emptyDir(absolutePath('./tmp'))
47
+
48
+ // deletes all the files from tmp dir
49
+ const tmpDirectory = absolutePath('./tmp')
50
+ try {
51
+ fs.statSync(tmpDirectory)
52
+ } catch (e) {
53
+ fs.mkdirSync(tmpDirectory)
54
+ }
55
+ for (const file of fs.readdirSync(tmpDirectory)) {
56
+ fs.unlinkSync(path.join(tmpDirectory, file))
57
+ }
35
58
  })
36
59
 
37
60
  test('simple protocol', compareWithJavaImplementation('simple.avdl', 'Simple'))
@@ -21,7 +21,7 @@ interface Field {
21
21
 
22
22
  let cache: any
23
23
  const merge = Object.assign
24
- const isObject = (obj: unknown): obj is Obj => obj && typeof obj === 'object'
24
+ const isObject = (obj: unknown): obj is Obj => !!obj && typeof obj === 'object'
25
25
  const isIterable = (obj: unknown): obj is Iterable =>
26
26
  isObject(obj) && typeof obj.map !== 'undefined'
27
27
  const isFieldArray = (field: unknown): field is Field =>
@@ -92,12 +92,12 @@ export function avdlToAVSC(path: any) {
92
92
  export async function avdlToAVSCAsync(path: string) {
93
93
  cache = {}
94
94
 
95
- const protocol: { [key: string]: any } = await new Promise((resolve, reject) => {
95
+ const protocol: Record<string, any> = await new Promise((resolve, reject) => {
96
96
  assembleProtocol(path, (err: AssembleProtocolError, schema) => {
97
97
  if (err) {
98
98
  reject(new ConfluentSchemaRegistryError(`${err.message}. Caused by: ${err.path}`))
99
99
  } else {
100
- resolve(schema)
100
+ resolve(schema as Record<string, any>)
101
101
  }
102
102
  })
103
103
  })
package/tmp/Array.avsc ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Array",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "properties",
7
+ "type" : {
8
+ "type" : "array",
9
+ "items" : {
10
+ "type" : "record",
11
+ "name" : "KeyValue",
12
+ "fields" : [ {
13
+ "name" : "key",
14
+ "type" : "string"
15
+ }, {
16
+ "name" : "value",
17
+ "type" : "string"
18
+ } ]
19
+ }
20
+ }
21
+ } ]
22
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Array1",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "array2",
7
+ "type" : [ "null", {
8
+ "type" : "array",
9
+ "items" : {
10
+ "type" : "record",
11
+ "name" : "Array2",
12
+ "fields" : [ {
13
+ "name" : "array2_name",
14
+ "type" : "string"
15
+ }, {
16
+ "name" : "foos",
17
+ "type" : [ "null", {
18
+ "type" : "enum",
19
+ "name" : "Foos",
20
+ "symbols" : [ "foo", "bar", "baz" ]
21
+ } ],
22
+ "default" : null
23
+ } ]
24
+ }
25
+ } ],
26
+ "default" : null
27
+ } ]
28
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Array2",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "array2_name",
7
+ "type" : "string"
8
+ }, {
9
+ "name" : "foos",
10
+ "type" : [ "null", {
11
+ "type" : "enum",
12
+ "name" : "Foos",
13
+ "symbols" : [ "foo", "bar", "baz" ]
14
+ } ],
15
+ "default" : null
16
+ } ]
17
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Array3",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "bam",
7
+ "type" : [ "null", {
8
+ "type" : "record",
9
+ "name" : "Bam",
10
+ "fields" : [ {
11
+ "name" : "bam",
12
+ "type" : "string"
13
+ } ]
14
+ } ],
15
+ "default" : null
16
+ } ]
17
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "ArrayUnion",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "properties",
7
+ "type" : [ "null", {
8
+ "type" : "array",
9
+ "items" : {
10
+ "type" : "record",
11
+ "name" : "KeyValue",
12
+ "fields" : [ {
13
+ "name" : "key",
14
+ "type" : "string"
15
+ }, {
16
+ "name" : "value",
17
+ "type" : "string"
18
+ } ]
19
+ }
20
+ } ],
21
+ "default" : null
22
+ } ]
23
+ }
package/tmp/Bam.avsc ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Bam",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "bam",
7
+ "type" : "string"
8
+ } ]
9
+ }
package/tmp/Bar.avsc ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Bar",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "baz",
7
+ "type" : {
8
+ "type" : "record",
9
+ "name" : "Baz",
10
+ "fields" : [ {
11
+ "name" : "array1",
12
+ "type" : [ "null", {
13
+ "type" : "array",
14
+ "items" : {
15
+ "type" : "record",
16
+ "name" : "Array1",
17
+ "fields" : [ {
18
+ "name" : "array2",
19
+ "type" : [ "null", {
20
+ "type" : "array",
21
+ "items" : {
22
+ "type" : "record",
23
+ "name" : "Array2",
24
+ "fields" : [ {
25
+ "name" : "array2_name",
26
+ "type" : "string"
27
+ }, {
28
+ "name" : "foos",
29
+ "type" : [ "null", {
30
+ "type" : "enum",
31
+ "name" : "Foos",
32
+ "symbols" : [ "foo", "bar", "baz" ]
33
+ } ],
34
+ "default" : null
35
+ } ]
36
+ }
37
+ } ],
38
+ "default" : null
39
+ } ]
40
+ }
41
+ } ],
42
+ "default" : null
43
+ } ]
44
+ }
45
+ } ]
46
+ }
package/tmp/Baz.avsc ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Baz",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "array1",
7
+ "type" : [ "null", {
8
+ "type" : "array",
9
+ "items" : {
10
+ "type" : "record",
11
+ "name" : "Array1",
12
+ "fields" : [ {
13
+ "name" : "array2",
14
+ "type" : [ "null", {
15
+ "type" : "array",
16
+ "items" : {
17
+ "type" : "record",
18
+ "name" : "Array2",
19
+ "fields" : [ {
20
+ "name" : "array2_name",
21
+ "type" : "string"
22
+ }, {
23
+ "name" : "foos",
24
+ "type" : [ "null", {
25
+ "type" : "enum",
26
+ "name" : "Foos",
27
+ "symbols" : [ "foo", "bar", "baz" ]
28
+ } ],
29
+ "default" : null
30
+ } ]
31
+ }
32
+ } ],
33
+ "default" : null
34
+ } ]
35
+ }
36
+ } ],
37
+ "default" : null
38
+ } ]
39
+ }
@@ -0,0 +1,81 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Complex",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "array1",
7
+ "type" : [ "null", {
8
+ "type" : "array",
9
+ "items" : {
10
+ "type" : "record",
11
+ "name" : "Array1",
12
+ "fields" : [ {
13
+ "name" : "array2",
14
+ "type" : [ "null", {
15
+ "type" : "array",
16
+ "items" : {
17
+ "type" : "record",
18
+ "name" : "Array2",
19
+ "fields" : [ {
20
+ "name" : "array2_name",
21
+ "type" : "string"
22
+ }, {
23
+ "name" : "foos",
24
+ "type" : [ "null", {
25
+ "type" : "enum",
26
+ "name" : "Foos",
27
+ "symbols" : [ "foo", "bar", "baz" ]
28
+ } ],
29
+ "default" : null
30
+ } ]
31
+ }
32
+ } ],
33
+ "default" : null
34
+ } ]
35
+ }
36
+ } ],
37
+ "default" : null
38
+ }, {
39
+ "name" : "array3",
40
+ "type" : {
41
+ "type" : "array",
42
+ "items" : {
43
+ "type" : "record",
44
+ "name" : "Array3",
45
+ "fields" : [ {
46
+ "name" : "bam",
47
+ "type" : [ "null", {
48
+ "type" : "record",
49
+ "name" : "Bam",
50
+ "fields" : [ {
51
+ "name" : "bam",
52
+ "type" : "string"
53
+ } ]
54
+ } ],
55
+ "default" : null
56
+ } ]
57
+ }
58
+ }
59
+ }, {
60
+ "name" : "bar",
61
+ "type" : {
62
+ "type" : "record",
63
+ "name" : "Bar",
64
+ "fields" : [ {
65
+ "name" : "baz",
66
+ "type" : {
67
+ "type" : "record",
68
+ "name" : "Baz",
69
+ "fields" : [ {
70
+ "name" : "array1",
71
+ "type" : [ "null", {
72
+ "type" : "array",
73
+ "items" : "Array1"
74
+ } ],
75
+ "default" : null
76
+ } ]
77
+ }
78
+ } ]
79
+ }
80
+ } ]
81
+ }
package/tmp/Enum.avsc ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Enum",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "foos",
7
+ "type" : {
8
+ "type" : "enum",
9
+ "name" : "Foos",
10
+ "symbols" : [ "foo", "bar", "baz" ]
11
+ }
12
+ } ]
13
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "EnumUnion",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "foos",
7
+ "type" : [ "null", {
8
+ "type" : "enum",
9
+ "name" : "Foos",
10
+ "symbols" : [ "foo", "bar", "baz" ]
11
+ } ],
12
+ "default" : null
13
+ } ]
14
+ }
package/tmp/Foos.avsc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "type" : "enum",
3
+ "name" : "Foos",
4
+ "namespace" : "com.org.app.track",
5
+ "symbols" : [ "foo", "bar", "baz" ]
6
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "ImportMultipleNamespaces",
4
+ "namespace" : "com.org.domain.fixtures",
5
+ "fields" : [ {
6
+ "name" : "metadata",
7
+ "type" : {
8
+ "type" : "record",
9
+ "name" : "Metadata",
10
+ "namespace" : "com.org.messaging",
11
+ "fields" : [ {
12
+ "name" : "event_id",
13
+ "type" : "string"
14
+ }, {
15
+ "name" : "publisher_system_id",
16
+ "type" : "string"
17
+ }, {
18
+ "name" : "occurred_at",
19
+ "type" : {
20
+ "type" : "long",
21
+ "logicalType" : "timestamp-millis"
22
+ }
23
+ }, {
24
+ "name" : "published_at",
25
+ "type" : {
26
+ "type" : "long",
27
+ "logicalType" : "timestamp-millis"
28
+ }
29
+ }, {
30
+ "name" : "correlation_id",
31
+ "type" : "string"
32
+ } ]
33
+ }
34
+ } ]
35
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "KeyValue",
4
+ "namespace" : "com.org.app.track",
5
+ "fields" : [ {
6
+ "name" : "key",
7
+ "type" : "string"
8
+ }, {
9
+ "name" : "value",
10
+ "type" : "string"
11
+ } ]
12
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Metadata",
4
+ "namespace" : "com.org.messaging",
5
+ "fields" : [ {
6
+ "name" : "event_id",
7
+ "type" : "string"
8
+ }, {
9
+ "name" : "publisher_system_id",
10
+ "type" : "string"
11
+ }, {
12
+ "name" : "occurred_at",
13
+ "type" : {
14
+ "type" : "long",
15
+ "logicalType" : "timestamp-millis"
16
+ }
17
+ }, {
18
+ "name" : "published_at",
19
+ "type" : {
20
+ "type" : "long",
21
+ "logicalType" : "timestamp-millis"
22
+ }
23
+ }, {
24
+ "name" : "correlation_id",
25
+ "type" : "string"
26
+ } ]
27
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Multiple",
4
+ "namespace" : "com.org.domain.fixtures",
5
+ "fields" : [ {
6
+ "name" : "foo",
7
+ "type" : "string"
8
+ }, {
9
+ "name" : "bar",
10
+ "type" : {
11
+ "type" : "record",
12
+ "name" : "Bar",
13
+ "fields" : [ {
14
+ "name" : "baz",
15
+ "type" : {
16
+ "type" : "record",
17
+ "name" : "Baz",
18
+ "fields" : [ {
19
+ "name" : "bam",
20
+ "type" : "string"
21
+ } ]
22
+ }
23
+ } ]
24
+ }
25
+ } ]
26
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "MultipleNamespaces",
4
+ "namespace" : "com.org.confluentschemaregistry",
5
+ "fields" : [ {
6
+ "name" : "metadata",
7
+ "type" : {
8
+ "type" : "record",
9
+ "name" : "Metadata",
10
+ "namespace" : "com.org.messaging",
11
+ "fields" : [ {
12
+ "name" : "event_id",
13
+ "type" : "string"
14
+ }, {
15
+ "name" : "publisher_system_id",
16
+ "type" : "string"
17
+ }, {
18
+ "name" : "occurred_at",
19
+ "type" : {
20
+ "type" : "long",
21
+ "logicalType" : "timestamp-millis"
22
+ }
23
+ }, {
24
+ "name" : "published_at",
25
+ "type" : {
26
+ "type" : "long",
27
+ "logicalType" : "timestamp-millis"
28
+ }
29
+ }, {
30
+ "name" : "correlation_id",
31
+ "type" : "string"
32
+ } ]
33
+ }
34
+ }, {
35
+ "name" : "id",
36
+ "type" : "string"
37
+ }, {
38
+ "name" : "amount",
39
+ "type" : "int"
40
+ }, {
41
+ "name" : "description",
42
+ "type" : "string"
43
+ } ]
44
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "MultipleUnion",
4
+ "namespace" : "com.org.domain.fixtures",
5
+ "fields" : [ {
6
+ "name" : "foo",
7
+ "type" : "string"
8
+ }, {
9
+ "name" : "bar",
10
+ "type" : [ "null", {
11
+ "type" : "record",
12
+ "name" : "Bar",
13
+ "fields" : [ {
14
+ "name" : "baz",
15
+ "type" : [ "null", {
16
+ "type" : "record",
17
+ "name" : "Baz",
18
+ "fields" : [ {
19
+ "name" : "bam",
20
+ "type" : "string"
21
+ } ]
22
+ } ],
23
+ "default" : null
24
+ } ]
25
+ } ],
26
+ "default" : null
27
+ } ]
28
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Simple",
4
+ "namespace" : "com.org.domain.fixtures",
5
+ "fields" : [ {
6
+ "name" : "foo",
7
+ "type" : "string"
8
+ } ]
9
+ }
package/tmp/Two.avsc ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Two",
4
+ "namespace" : "com.org.domain.fixtures",
5
+ "fields" : [ {
6
+ "name" : "foo",
7
+ "type" : "string"
8
+ }, {
9
+ "name" : "bar",
10
+ "type" : {
11
+ "type" : "record",
12
+ "name" : "Bar",
13
+ "fields" : [ {
14
+ "name" : "baz",
15
+ "type" : "string"
16
+ } ]
17
+ }
18
+ } ]
19
+ }
package/tmp/Union.avsc ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "type" : "record",
3
+ "name" : "Union",
4
+ "namespace" : "com.org.domain.fixtures",
5
+ "fields" : [ {
6
+ "name" : "foo",
7
+ "type" : "string"
8
+ }, {
9
+ "name" : "bar",
10
+ "type" : [ "null", {
11
+ "type" : "record",
12
+ "name" : "Bar",
13
+ "fields" : [ {
14
+ "name" : "baz",
15
+ "type" : "string"
16
+ } ]
17
+ } ],
18
+ "default" : null
19
+ } ]
20
+ }
package/dockest.ts DELETED
@@ -1,30 +0,0 @@
1
- import { Dockest, sleepWithLog, logLevel } from 'dockest'
2
- import { DockestService } from 'dockest/dist/@types'
3
-
4
- const dockest = new Dockest({
5
- composeFile: 'docker-compose.yml',
6
- dumpErrors: true,
7
- jestLib: require('jest'),
8
- jestOpts: {
9
- updateSnapshot: true,
10
- },
11
- logLevel: logLevel.DEBUG,
12
- })
13
-
14
- const dockestServices: DockestService[] = [
15
- {
16
- serviceName: 'zooKeeper',
17
- dependents: [
18
- {
19
- serviceName: 'kafka',
20
- readinessCheck: () => sleepWithLog(10, `Sleeping for Kafka`),
21
- },
22
- ],
23
- },
24
- {
25
- serviceName: 'schemaRegistry',
26
- readinessCheck: () => sleepWithLog(35, `Sleeping for Schema Registry`),
27
- },
28
- ]
29
-
30
- dockest.run(dockestServices)