@themainstack/communication 1.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.
@@ -0,0 +1,31 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { status } from '@grpc/grpc-js';
3
+ import { handleGrpcError, GrpcError } from '../../src/grpc/errors';
4
+
5
+ describe('handleGrpcError', () => {
6
+ it('should throw a GrpcError when a service error is passed', () => {
7
+ const error = {
8
+ code: status.NOT_FOUND,
9
+ message: 'User not found',
10
+ details: 'Details here',
11
+ };
12
+
13
+ try {
14
+ handleGrpcError(error);
15
+ } catch (e: any) {
16
+ expect(e).toBeInstanceOf(GrpcError);
17
+ expect(e.code).toBe(status.NOT_FOUND);
18
+ expect(e.message).toBe('User not found');
19
+ expect(e.details).toBe('Details here');
20
+ }
21
+ });
22
+
23
+ it('should throw a GrpcError with UNKNOWN when an unknown error is passed', () => {
24
+ try {
25
+ handleGrpcError("some string error");
26
+ } catch (e: any) {
27
+ expect(e).toBeInstanceOf(GrpcError);
28
+ expect(e.code).toBe(status.UNKNOWN);
29
+ }
30
+ });
31
+ });
@@ -0,0 +1,29 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import {
3
+ generateProtoFromMethods,
4
+ GrpcServerFactory,
5
+ GrpcClientFactory,
6
+ handleGrpcError
7
+ } from '../src/index';
8
+
9
+ describe('@themainstack/communication exports', () => {
10
+ it('should export generateProtoFromMethods', () => {
11
+ expect(generateProtoFromMethods).toBeDefined();
12
+ expect(typeof generateProtoFromMethods).toBe('function');
13
+ });
14
+
15
+ it('should export GrpcServerFactory', () => {
16
+ expect(GrpcServerFactory).toBeDefined();
17
+ expect(typeof GrpcServerFactory.createServer).toBe('function');
18
+ });
19
+
20
+ it('should export GrpcClientFactory', () => {
21
+ expect(GrpcClientFactory).toBeDefined();
22
+ expect(typeof GrpcClientFactory.createClient).toBe('function');
23
+ });
24
+
25
+ it('should export handleGrpcError', () => {
26
+ expect(handleGrpcError).toBeDefined();
27
+ expect(typeof handleGrpcError).toBe('function');
28
+ });
29
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "declaration": true,
6
+ "module": "CommonJS",
7
+ "target": "ES2020",
8
+ "strict": true,
9
+ "esModuleInterop": true
10
+ },
11
+ "include": ["src"],
12
+ "exclude": ["node_modules", "dist", "tests"]
13
+ }