Skip to content

Commit eaa48e6

Browse files
committed
feat(nestjs-json-rpc-sdk): sdk for rpc
- http transport - factory for native js - angular module Closes: #77
1 parent f89f7cf commit eaa48e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1117
-90
lines changed

apps/json-api-front/src/app/app.component.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,23 @@ import { Component, inject, OnInit } from '@angular/core';
22
import { NxWelcomeComponent } from './nx-welcome.component';
33
import { JsonApiSdkService } from 'json-api-nestjs-sdk';
44
import { AtomicFactory } from 'json-api-nestjs-sdk/json-api-nestjs-sdk.module';
5+
import {
6+
JSON_RPC,
7+
RPC_BATCH,
8+
Rpc,
9+
} from '@klerick/nestjs-json-rpc-sdk/json-rpc-sdk.module';
10+
511
import { switchMap } from 'rxjs';
612

13+
interface TestRpc {
14+
test(a: number, b: number): Promise<number>;
15+
test2(firstArg: string, secondArg: number): Promise<string>;
16+
}
17+
18+
type RpcMap = {
19+
TestRpc: TestRpc;
20+
};
21+
722
@Component({
823
standalone: true,
924
imports: [NxWelcomeComponent],
@@ -14,14 +29,19 @@ import { switchMap } from 'rxjs';
1429
export class AppComponent implements OnInit {
1530
private JsonApiSdkService = inject(JsonApiSdkService);
1631
private atomicFactory = inject(AtomicFactory);
32+
private rpc = inject<Rpc<RpcMap>>(JSON_RPC);
33+
private rpcBatch = inject(RPC_BATCH);
1734

1835
ngOnInit(): void {
19-
// this.JsonApiSdkService.getAll(class Users {}, {
20-
// page: {
21-
// size: 2,
22-
// number: 1,
23-
// },
24-
// }).subscribe((r) => console.log(r));
36+
const rpc1 = this.rpc.TestRpc.test(1, 2);
37+
const rpc2 = this.rpc.TestRpc.test2('string', 2);
38+
this.rpcBatch(rpc2, rpc1).subscribe(([r2, r1]) => console.log(r1, r2));
39+
this.JsonApiSdkService.getAll(class Users {}, {
40+
page: {
41+
size: 2,
42+
number: 1,
43+
},
44+
}).subscribe((r) => console.log(r));
2545

2646
class Addresses {
2747
id = 1;

apps/json-api-front/src/app/app.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { ApplicationConfig, importProvidersFrom } from '@angular/core';
22
import { JsonApiAngular } from 'json-api-nestjs-sdk/json-api-nestjs-sdk.module';
3+
import {
4+
JsonRpcAngular,
5+
TransportType,
6+
} from '@klerick/nestjs-json-rpc-sdk/json-rpc-sdk.module';
37

48
export const appConfig: ApplicationConfig = {
59
providers: [
@@ -11,5 +15,12 @@ export const appConfig: ApplicationConfig = {
1115
operationUrl: 'operation',
1216
})
1317
),
18+
importProvidersFrom(
19+
JsonRpcAngular.forRoot({
20+
transport: TransportType.HTTP,
21+
rpcPath: 'rpc',
22+
rpcHost: 'http://localhost:4200',
23+
})
24+
),
1425
],
1526
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": ["../../../.eslintrc.base.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
},
17+
{
18+
"files": ["*.json"],
19+
"parser": "jsonc-eslint-parser",
20+
"rules": {
21+
"@nx/dependency-checks": "error"
22+
}
23+
}
24+
]
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# nestjs-json-rpc-sdk
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Building
6+
7+
Run `nx build nestjs-json-rpc-sdk` to build the library.
8+
9+
## Running unit tests
10+
11+
Run `nx test nestjs-json-rpc-sdk` to execute the unit tests via [Jest](https://jestjs.io).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'nestjs-json-rpc-sdk',
4+
preset: '../../../jest.preset.js',
5+
testEnvironment: 'node',
6+
transform: {
7+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
8+
},
9+
moduleFileExtensions: ['ts', 'js', 'html'],
10+
coverageDirectory: '../../../coverage/libs/json-rpc/nestjs-json-rpc-sdk',
11+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "@klerick/nestjs-json-rpc-sdk",
3+
"version": "0.0.1",
4+
"dependencies": {
5+
"tslib": "^2.3.0"
6+
}
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "nestjs-json-rpc-sdk",
3+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/json-rpc/nestjs-json-rpc-sdk/src",
5+
"projectType": "library",
6+
"targets": {
7+
"build": {
8+
"executor": "@nx/js:tsc",
9+
"outputs": ["{options.outputPath}"],
10+
"options": {
11+
"outputPath": "dist/libs/json-rpc/nestjs-json-rpc-sdk",
12+
"main": "libs/json-rpc/nestjs-json-rpc-sdk/src/index.ts",
13+
"tsConfig": "libs/json-rpc/nestjs-json-rpc-sdk/tsconfig.lib.json",
14+
"assets": ["libs/json-rpc/nestjs-json-rpc-sdk/*.md"]
15+
}
16+
},
17+
"publish": {
18+
"command": "node tools/scripts/publish.mjs nestjs-json-rpc-sdk {args.ver} {args.tag}",
19+
"dependsOn": ["build"]
20+
}
21+
},
22+
"tags": []
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/nestjs-json-rpc-sdk';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/json-rpc-angular';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const JSON_RPC_VERSION = '2.0';

0 commit comments

Comments
 (0)