@biorate/schema-registry 2.2.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/{index.js → cjs/index.js} +0 -1
  2. package/dist/cjs/package.json +3 -0
  3. package/dist/{src → cjs/src}/api.js +8 -5
  4. package/dist/{src → cjs/src}/errors.js +0 -1
  5. package/dist/{src → cjs/src}/index.js +0 -1
  6. package/dist/{src → cjs/src}/interfaces.js +0 -1
  7. package/dist/esm/index.js +1 -0
  8. package/dist/esm/package.json +3 -0
  9. package/dist/esm/src/api.js +201 -0
  10. package/dist/esm/src/errors.js +13 -0
  11. package/dist/esm/src/index.js +33 -0
  12. package/dist/esm/src/interfaces.js +1 -0
  13. package/dist/types/src/api.d.ts +61 -0
  14. package/dist/types/src/errors.d.ts +7 -0
  15. package/dist/types/src/index.d.ts +11 -0
  16. package/dist/types/src/interfaces.d.ts +9 -0
  17. package/package.json +35 -10
  18. package/.nyc_output/2ab817d0-505c-454e-bed2-1750a6e607a4.json +0 -1
  19. package/.nyc_output/97ca74bd-bff5-4f5e-b84c-68ea3601b0d6.json +0 -1
  20. package/.nyc_output/c03eee38-4fa7-4d46-973b-4d91dcc18bca.json +0 -1
  21. package/.nyc_output/processinfo/2ab817d0-505c-454e-bed2-1750a6e607a4.json +0 -1
  22. package/.nyc_output/processinfo/97ca74bd-bff5-4f5e-b84c-68ea3601b0d6.json +0 -1
  23. package/.nyc_output/processinfo/c03eee38-4fa7-4d46-973b-4d91dcc18bca.json +0 -1
  24. package/.nyc_output/processinfo/index.json +0 -1
  25. package/CHANGELOG.md +0 -1026
  26. package/allure-results/090d63d4-5302-44e6-a431-1f0bb56b01a4-result.json +0 -1
  27. package/allure-results/13f0ae5c-3043-4bdb-b6b1-327953028f5b-result.json +0 -1
  28. package/allure-results/1ac1fd37-8bf9-42f0-a808-976f1b58a5e1-container.json +0 -1
  29. package/allure-results/41a93db0-4085-4b31-8c34-5016fe756a73-result.json +0 -1
  30. package/allure-results/5059215a-e888-471e-b61d-2231e86df801-result.json +0 -1
  31. package/allure-results/5afc98f7-ce6c-4d4a-b23c-94fa74a96e14-result.json +0 -1
  32. package/allure-results/5f57981e-3ffa-4b13-8aab-c93c93d494a1-result.json +0 -1
  33. package/allure-results/8298dd4f-c79c-44eb-b6a9-ee86fe498e22-result.json +0 -1
  34. package/allure-results/aee745b7-2ca7-4d13-b780-f39c3c647e31-result.json +0 -1
  35. package/allure-results/b3c2840e-8a5c-492c-9704-e2c82e0311b5-result.json +0 -1
  36. package/allure-results/c591d6cd-6548-4899-827d-cb9575581d95-result.json +0 -1
  37. package/allure-results/d3a22bb1-3c24-4c25-b226-3c4b3c5e4bc1-result.json +0 -1
  38. package/allure-results/e015e709-764f-42c2-96a3-26b31fe144d3-container.json +0 -1
  39. package/coverage/base.css +0 -224
  40. package/coverage/block-navigation.js +0 -87
  41. package/coverage/clover.xml +0 -120
  42. package/coverage/coverage-final.json +0 -7
  43. package/coverage/favicon.png +0 -0
  44. package/coverage/index.html +0 -146
  45. package/coverage/prettify.css +0 -1
  46. package/coverage/prettify.js +0 -2
  47. package/coverage/sort-arrow-sprite.png +0 -0
  48. package/coverage/sorter.js +0 -210
  49. package/coverage/src/api.ts.html +0 -802
  50. package/coverage/src/errors.ts.html +0 -130
  51. package/coverage/src/index.html +0 -161
  52. package/coverage/src/index.ts.html +0 -379
  53. package/coverage/src/interfaces.ts.html +0 -154
  54. package/coverage/tests/__mocks__/index.html +0 -116
  55. package/coverage/tests/__mocks__/index.ts.html +0 -145
  56. package/coverage/tests/index.html +0 -116
  57. package/coverage/tests/test.avsc.json.html +0 -142
  58. package/dist/index.js.map +0 -1
  59. package/dist/src/api.js.map +0 -1
  60. package/dist/src/errors.js.map +0 -1
  61. package/dist/src/index.js.map +0 -1
  62. package/dist/src/interfaces.js.map +0 -1
  63. package/dist/tsconfig.build.tsbuildinfo +0 -1
  64. package/index.d.ts +0 -12
  65. package/src/api.ts +0 -239
  66. package/src/errors.ts +0 -15
  67. package/src/index.ts +0 -98
  68. package/src/interfaces.ts +0 -23
  69. package/tsconfig.build.json +0 -5
  70. package/tsconfig.json +0 -9
  71. /package/{index.ts → dist/types/index.d.ts} +0 -0
package/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { Connector, IConnector } from '@biorate/connector';
2
- import { ISchemaRegistryConfig, ISchemaRegistryConnection } from './src';
3
-
4
- declare module '@biorate/schema-registry' {
5
- export class SchemaRegistryConnector extends Connector<
6
- ISchemaRegistryConfig,
7
- ISchemaRegistryConnection
8
- > {
9
- protected readonly namespace: string;
10
- protected connect(config: ISchemaRegistryConfig): Promise<ISchemaRegistryConnection>;
11
- }
12
- }
package/src/api.ts DELETED
@@ -1,239 +0,0 @@
1
- import { AxiosPrometheus, AxiosInstance } from '@biorate/axios-prometheus';
2
- import { Type } from 'avsc';
3
- import { ICompatibilities, ISchemaRegistryConfig } from './interfaces';
4
- import { SchemaRegistryAvroSchemaParseError } from './errors';
5
-
6
- export const create = (config: ISchemaRegistryConfig) => {
7
- const cache = new Map<number, Type>();
8
-
9
- class SchemaRegistryApi extends AxiosPrometheus {
10
- public baseURL = config.baseURL;
11
- public headers = config.headers;
12
- public url: string;
13
- public method: string;
14
- private '#client': AxiosInstance;
15
- }
16
-
17
- class Ping extends SchemaRegistryApi {
18
- public url = '/';
19
- public method = 'get';
20
-
21
- public static fetch() {
22
- return this._fetch<Record<string, unknown>>({});
23
- }
24
- }
25
-
26
- class GetSchemasById extends SchemaRegistryApi {
27
- public url = '/schemas/ids/:id';
28
- public method = 'get';
29
-
30
- public static fetch(id: number) {
31
- return this._fetch<{ schema: string }>({ path: { id } });
32
- }
33
- }
34
-
35
- class GetSchemasTypes extends SchemaRegistryApi {
36
- public url = '/schemas/types';
37
- public method = 'get';
38
-
39
- public static fetch() {
40
- return this._fetch<string[]>({});
41
- }
42
- }
43
-
44
- class GetSchemasVersionsById extends SchemaRegistryApi {
45
- public url = '/schemas/ids/:id/versions';
46
- public method = 'get';
47
-
48
- public static fetch(id: number) {
49
- return this._fetch<{ subject: string; version: number }[]>({ path: { id } });
50
- }
51
- }
52
-
53
- class GetSubjects extends SchemaRegistryApi {
54
- public url = '/subjects';
55
- public method = 'get';
56
-
57
- public static fetch() {
58
- return this._fetch<string[]>({});
59
- }
60
- }
61
-
62
- class GetSubjectsVersions extends SchemaRegistryApi {
63
- public url = '/subjects/:subject/versions';
64
- public method = 'get';
65
-
66
- public static fetch(subject: string) {
67
- return this._fetch<number[]>({ path: { subject } });
68
- }
69
- }
70
-
71
- class DeleteSubjects extends SchemaRegistryApi {
72
- public url = '/subjects/:subject';
73
- public method = 'delete';
74
-
75
- public static fetch(data: { subject: string; permanent?: boolean }) {
76
- return this._fetch<number[]>({
77
- path: { subject: data.subject },
78
- params: { permanent: !!data.permanent },
79
- });
80
- }
81
- }
82
-
83
- class GetSubjectsByVersion extends SchemaRegistryApi {
84
- public url = '/subjects/:subject/versions/:version';
85
- public method = 'get';
86
-
87
- public static fetch(data: { subject: string; version: number | string }) {
88
- return this._fetch<{
89
- subject: string;
90
- id: number;
91
- version: number;
92
- schemaType: string;
93
- schema: string;
94
- }>({ path: data });
95
- }
96
- }
97
-
98
- class GetSchemaBySubjectsAndVersion extends SchemaRegistryApi {
99
- public url = '/subjects/:subject/versions/:version/schema';
100
- public method = 'get';
101
-
102
- public static fetch(data: { subject: string; version: number | string }) {
103
- return this._fetch<unknown>({ path: data });
104
- }
105
- }
106
-
107
- class PostSubjectsVersions extends SchemaRegistryApi {
108
- public url = '/subjects/:subject/versions';
109
- public method = 'post';
110
-
111
- public static fetch(data: {
112
- subject: string;
113
- schema: string | Record<string, any>;
114
- schemaType?: string;
115
- reference?: string;
116
- normalize?: boolean;
117
- }) {
118
- return this._fetch<{ id: number }>({
119
- path: { subject: data.subject },
120
- params: { normalize: !!data.normalize },
121
- data: {
122
- schema: toStringData(data.schema),
123
- schemaType: data.schemaType,
124
- reference: data.reference,
125
- },
126
- });
127
- }
128
- }
129
-
130
- class PostSubjects extends SchemaRegistryApi {
131
- public url = '/subjects/:subject';
132
- public method = 'post';
133
-
134
- public static fetch(data: {
135
- subject: string;
136
- schema: string | Record<string, any>;
137
- schemaType?: string;
138
- reference?: string;
139
- normalize?: boolean;
140
- }) {
141
- return this._fetch<{
142
- subject: string;
143
- id: number;
144
- version: number;
145
- schema: string;
146
- }>({
147
- path: { subject: data.subject },
148
- params: { normalize: !!data.normalize },
149
- data: {
150
- schema: toStringData(data.schema),
151
- schemaType: data.schemaType,
152
- reference: data.reference,
153
- },
154
- });
155
- }
156
- }
157
-
158
- class PutConfig extends SchemaRegistryApi {
159
- public url = '/config/:subject';
160
- public method = 'put';
161
-
162
- public static fetch(data: { subject: string; compatibility: ICompatibilities }) {
163
- return this._fetch<{
164
- compatibility: ICompatibilities;
165
- }>({
166
- path: { subject: data.subject },
167
- data: { compatibility: data.compatibility },
168
- });
169
- }
170
- }
171
-
172
- async function encode(
173
- subject: string,
174
- data: Record<string, any>,
175
- version: string | number = 'latest',
176
- ) {
177
- const errors: string[] = [];
178
- const response = await GetSubjectsByVersion.fetch({ subject, version });
179
- const header = Buffer.alloc(5);
180
- const schema = Type.forSchema(JSON.parse(response.data.schema));
181
- schema.isValid(data, {
182
- errorHook: (path: string[], value: unknown) => {
183
- errors.push(`${path.join('.')}: ${value} (${typeof value})`);
184
- },
185
- });
186
- if (errors.length) throw new SchemaRegistryAvroSchemaParseError(errors);
187
- header.writeInt32BE(response.data.id, 1);
188
- return Buffer.concat([header, schema.toBuffer(data)]);
189
- }
190
-
191
- async function decode(buffer: Buffer) {
192
- const id = buffer.readInt32BE(1);
193
- let data: Type | undefined = cache.get(id);
194
- if (!data) {
195
- const response = await GetSchemasById.fetch(id);
196
- data = Type.forSchema(JSON.parse(response.data.schema));
197
- cache.set(id, data);
198
- }
199
- const schema = Type.forSchema(data);
200
- return schema.fromBuffer(buffer.slice(5));
201
- }
202
-
203
- function toStringData(data: string | Record<string, any>) {
204
- return typeof data === 'string' ? data : JSON.stringify(data);
205
- }
206
-
207
- return {
208
- ping: <typeof Ping.fetch>Ping.fetch.bind(Ping),
209
- getSchemasById: <typeof GetSchemasById.fetch>(
210
- GetSchemasById.fetch.bind(GetSchemasById)
211
- ),
212
- getSchemasTypes: <typeof GetSchemasTypes.fetch>(
213
- GetSchemasTypes.fetch.bind(GetSchemasTypes)
214
- ),
215
- getSchemasVersionsById: <typeof GetSchemasVersionsById.fetch>(
216
- GetSchemasVersionsById.fetch.bind(GetSchemasVersionsById)
217
- ),
218
- getSubjects: <typeof GetSubjects.fetch>GetSubjects.fetch.bind(GetSubjects),
219
- getSubjectsVersions: <typeof GetSubjectsVersions.fetch>(
220
- GetSubjectsVersions.fetch.bind(GetSubjectsVersions)
221
- ),
222
- deleteSubjects: <typeof DeleteSubjects.fetch>(
223
- DeleteSubjects.fetch.bind(DeleteSubjects)
224
- ),
225
- getSubjectsByVersion: <typeof GetSubjectsByVersion.fetch>(
226
- GetSubjectsByVersion.fetch.bind(GetSubjectsByVersion)
227
- ),
228
- getSchemaBySubjectsAndVersion: <typeof GetSchemaBySubjectsAndVersion.fetch>(
229
- GetSchemaBySubjectsAndVersion.fetch.bind(GetSchemaBySubjectsAndVersion)
230
- ),
231
- postSubjects: <typeof PostSubjects.fetch>PostSubjects.fetch.bind(PostSubjects),
232
- postSubjectsVersions: <typeof PostSubjectsVersions.fetch>(
233
- PostSubjectsVersions.fetch.bind(PostSubjectsVersions)
234
- ),
235
- putConfig: <typeof PutConfig.fetch>PutConfig.fetch.bind(PutConfig),
236
- encode,
237
- decode,
238
- };
239
- };
package/src/errors.ts DELETED
@@ -1,15 +0,0 @@
1
- import { BaseError } from '@biorate/errors';
2
-
3
- export class SchemaRegistryCantConnectError extends BaseError {
4
- public constructor(e: Error) {
5
- super(`Can't connect to schema registry: [%s]`, [e.message]);
6
- }
7
- }
8
-
9
- export class SchemaRegistryAvroSchemaParseError extends BaseError {
10
- public constructor(errors: string[]) {
11
- super('%s', [errors.join('; ')], {
12
- status: 400,
13
- });
14
- }
15
- }
package/src/index.ts DELETED
@@ -1,98 +0,0 @@
1
- import { injectable } from '@biorate/inversion';
2
- import { ISchemaRegistryConfig, ISchemaRegistryConnection } from './interfaces';
3
- import { Connector } from '@biorate/connector';
4
- import { SchemaRegistryCantConnectError } from './errors';
5
- import { create } from './api';
6
- export * from './api';
7
- export * from './errors';
8
- export * from './interfaces';
9
-
10
- /**
11
- * @description Schema registry connector
12
- *
13
- * ### Features:
14
- * - connector manager for schema registry
15
- *
16
- * @example
17
- * ```
18
- * import { inject, container, Types, Core } from '@biorate/inversion';
19
- * import { IConfig, Config } from '@biorate/config';
20
- * import { IConnector } from '@biorate/connector';
21
- * import { SchemaRegistryConnector, ISchemaRegistryConnector } from '@biorate/schema-registry';
22
- *
23
- * export class Root extends Core() {
24
- * @inject(SchemaRegistryConnector) public connector: ISchemaRegistryConnector;
25
- * }
26
- *
27
- * container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
28
- * container
29
- * .bind<ISchemaRegistryConnector>(SchemaRegistryConnector)
30
- * .toSelf()
31
- * .inSingletonScope();
32
- * container.bind<Root>(Root).toSelf().inSingletonScope();
33
- *
34
- * container.get<IConfig>(Types.Config).merge({
35
- * SchemaRegistry: [{ name: 'connection', baseURL: 'http://localhost:8085' }],
36
- * });
37
- *
38
- * (async () => {
39
- * const root = container.get<Root>(Root);
40
- * await root.$run();
41
- *
42
- * const { PostSubjectsVersions } = root.connector.connection('connection');
43
- * const { data } = await PostSubjectsVersions.fetch({
44
- * subject: 'test',
45
- * schema: {
46
- * type: 'record',
47
- * name: 'Test',
48
- * namespace: 'test',
49
- * fields: [
50
- * {
51
- * name: 'firstName',
52
- * type: 'string',
53
- * },
54
- * {
55
- * name: 'lastName',
56
- * type: 'string',
57
- * },
58
- * {
59
- * name: 'age',
60
- * type: 'int',
61
- * },
62
- * ],
63
- * },
64
- * });
65
- * console.log(data); // { id: 1 }
66
- * })();
67
- * ```
68
- */
69
- @injectable()
70
- export class SchemaRegistryConnector extends Connector<
71
- ISchemaRegistryConfig,
72
- ISchemaRegistryConnection
73
- > {
74
- /**
75
- * @description Private connections storage
76
- */
77
- private '#connections': Map<string, ISchemaRegistryConnection>;
78
- /**
79
- * @description Private link to selected (used) connection
80
- */
81
- private '#current': ISchemaRegistryConnection | undefined;
82
- /**
83
- * @description Namespace path for fetching configuration
84
- */
85
- protected readonly namespace = 'SchemaRegistry';
86
- /**
87
- * @description Create connection
88
- */
89
- protected async connect(config: ISchemaRegistryConfig) {
90
- const connection = create(config);
91
- try {
92
- await connection.ping();
93
- } catch (e: unknown) {
94
- throw new SchemaRegistryCantConnectError(<Error>e);
95
- }
96
- return connection;
97
- }
98
- }
package/src/interfaces.ts DELETED
@@ -1,23 +0,0 @@
1
- import { IConnectorConfig, IConnector } from '@biorate/connector';
2
- import { create } from './api';
3
-
4
- export type ISchemaRegistryConnection = ReturnType<typeof create>;
5
-
6
- export interface ISchemaRegistryConfig extends IConnectorConfig {
7
- baseURL: string;
8
- headers: Record<string, string>;
9
- }
10
-
11
- export type ISchemaRegistryConnector = IConnector<
12
- ISchemaRegistryConfig,
13
- ISchemaRegistryConnection
14
- >;
15
-
16
- export type ICompatibilities =
17
- | 'BACKWARD'
18
- | 'BACKWARD_TRANSITIVE'
19
- | 'FORWARD'
20
- | 'FORWARD_TRANSITIVE'
21
- | 'FULL'
22
- | 'FULL_TRANSITIVE'
23
- | 'NONE';
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "include": ["index.ts", "src/**/*"],
4
- "exclude": ["node_modules", "dist", "tests", "**/*spec.ts"]
5
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.json",
3
- "compilerOptions": {
4
- "strict": true,
5
- "strictPropertyInitialization": false
6
- },
7
- "include": ["index.ts", "src/**/*", "tests/**/*"],
8
- "exclude": ["node_modules", "dist"]
9
- }
File without changes