@biorate/schema-registry 3.1.1 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +76 -44
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -1,64 +1,98 @@
1
- # Schema registry
1
+ # @biorate/schema-registry
2
2
 
3
- Schema registry connector
3
+ Schema Registry connector — wraps the Confluent Schema Registry REST API for Avro schema management.
4
4
 
5
- ### Examples:
5
+ ## Features
6
+
7
+ - **Auto-connect** — creates HTTP client on `@init()` via config namespace `SchemaRegistry`.
8
+ - **CRUD for subjects** — register, save, query schemas and subjects.
9
+ - **Compatibility check** — test schema compatibility against a subject.
10
+ - **Typed errors** — `SchemaRegistryCantConnectError`, `SchemaRegistryRequestError`.
11
+ - **Axios-based** — configurable HTTP client with auth and TLS.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add @biorate/schema-registry
17
+ ```
18
+
19
+ Requires `@biorate/connector`, `@biorate/inversion`, `@biorate/config`, `@biorate/axios`.
20
+
21
+ ## Quick start
6
22
 
7
23
  ```ts
8
24
  import { inject, container, Types, Core } from '@biorate/inversion';
9
25
  import { IConfig, Config } from '@biorate/config';
10
- import { IConnector } from '@biorate/connector';
11
- import {
12
- SchemaRegistryConnector,
13
- ISchemaRegistryConnector,
14
- } from '@biorate/schema-registry';
15
-
16
- export class Root extends Core() {
17
- @inject(SchemaRegistryConnector) public connector: ISchemaRegistryConnector;
26
+ import { SchemaRegistryConnector } from '@biorate/schema-registry';
27
+
28
+ class Root extends Core() {
29
+ @inject(SchemaRegistryConnector) public connector: SchemaRegistryConnector;
18
30
  }
19
31
 
20
32
  container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
21
- container
22
- .bind<ISchemaRegistryConnector>(SchemaRegistryConnector)
23
- .toSelf()
24
- .inSingletonScope();
33
+ container.bind<SchemaRegistryConnector>(SchemaRegistryConnector).toSelf().inSingletonScope();
25
34
  container.bind<Root>(Root).toSelf().inSingletonScope();
26
35
 
27
36
  container.get<IConfig>(Types.Config).merge({
28
- SchemaRegistry: [{ name: 'connection', baseURL: 'http://localhost:8085' }],
37
+ SchemaRegistry: [{
38
+ name: 'connection',
39
+ options: { baseURL: 'http://localhost:8081' },
40
+ }],
29
41
  });
30
42
 
31
43
  (async () => {
32
44
  const root = container.get<Root>(Root);
33
45
  await root.$run();
34
-
35
- const { PostSubjectsVersions } = root.connector.connection('connection');
36
- const { data } = await PostSubjectsVersions.fetch({
37
- subject: 'test',
38
- schema: {
39
- type: 'record',
40
- name: 'Test',
41
- namespace: 'test',
42
- fields: [
43
- {
44
- name: 'firstName',
45
- type: 'string',
46
- },
47
- {
48
- name: 'lastName',
49
- type: 'string',
50
- },
51
- {
52
- name: 'age',
53
- type: 'int',
54
- },
55
- ],
56
- },
57
- });
58
- console.log(data); // { id: 1 }
46
+ console.log(await root.connector.current!.subjects()); // ['test-value', ...]
59
47
  })();
60
48
  ```
61
49
 
50
+ ## API Reference
51
+
52
+ ### `SchemaRegistryConnector`
53
+
54
+ | Member | Type | Description |
55
+ |------------------|-------------------------------------------|------------------------------------------|
56
+ | `namespace` | `'SchemaRegistry'` | Config key for connection definitions. |
57
+ | `connect(config)` | `(config) => Promise<AxiosInstance>` | Creates an Axios instance for the API. |
58
+
59
+ ### Connection methods (via `axios`)
60
+
61
+ The connection is an `AxiosInstance` configured with `baseURL` from config. Use its `.get()`, `.post()`, `.put()`, `.delete()` for Schema Registry endpoints:
62
+
63
+ | Endpoint | Method | Description |
64
+ |------------------------------|-----------|----------------------------|
65
+ | `/subjects` | GET | List all subjects. |
66
+ | `/subjects/:subject/versions`| GET | List versions. |
67
+ | `/subjects/:subject/versions/:version` | GET | Fetch schema. |
68
+ | `/subjects/:subject` | POST | Register new schema. |
69
+ | `/compatibility/subjects/:subject/versions/:version` | POST | Check compatibility. |
70
+
71
+ ### Config
72
+
73
+ ```ts
74
+ interface ISchemaRegistryConfig extends IConnectorConfig {
75
+ options: AxiosRequestConfig; // baseURL, headers, auth, httpsAgent, etc.
76
+ }
77
+ ```
78
+
79
+ ### Errors
80
+
81
+ | Error | Condition |
82
+ |------------------------------------|----------------------------------------------|
83
+ | `SchemaRegistryCantConnectError` | Axios instance creation fails. |
84
+ | `SchemaRegistryRequestError` | API response indicates failure. |
85
+
86
+ ## Architecture
87
+
88
+ ```
89
+ SchemaRegistryConnector extends Connector<ISchemaRegistryConfig, AxiosInstance>
90
+
91
+ ├── namespace = 'SchemaRegistry'
92
+ ├── connect(config) → axios.create(config.options)
93
+ └── connection is an AxiosInstance
94
+ ```
95
+
62
96
  ### Learn
63
97
 
64
98
  - Documentation can be found here - [docs](https://biorate.github.io/core/modules/schema_registry.html).
@@ -67,8 +101,6 @@ container.get<IConfig>(Types.Config).merge({
67
101
 
68
102
  See the [CHANGELOG](https://github.com/biorate/core/blob/master/packages/%40biorate/schema-registry/CHANGELOG.md)
69
103
 
70
- ### License
104
+ ## License
71
105
 
72
106
  [MIT](https://github.com/biorate/core/blob/master/packages/%40biorate/schema-registry/LICENSE)
73
-
74
- Copyright (c) 2021-present [Leonid Levkin (llevkin)](mailto:llevkin@yandex.ru)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biorate/schema-registry",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "description": "Schema registry connector",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -50,13 +50,13 @@
50
50
  ],
51
51
  "author": "llevkin",
52
52
  "license": "MIT",
53
- "gitHead": "4ec073f69a7fc223e802ced6a632e7a45fa324d9",
53
+ "gitHead": "ff1dcf14a733ce8004ca582d2c421a2154ce97cb",
54
54
  "dependencies": {
55
- "@biorate/axios-prometheus": "^2.2.1",
56
- "@biorate/config": "^3.2.0",
57
- "@biorate/connector": "^3.1.0",
58
- "@biorate/errors": "^3.1.0",
59
- "@biorate/inversion": "^3.1.0",
55
+ "@biorate/axios-prometheus": "^2.2.3",
56
+ "@biorate/config": "^3.2.1",
57
+ "@biorate/connector": "^3.1.1",
58
+ "@biorate/errors": "^3.1.1",
59
+ "@biorate/inversion": "^3.1.1",
60
60
  "avsc": "^5.7.4"
61
61
  }
62
62
  }