Skip to content

Commit 490b51f

Browse files
authored
Merge pull request #96 from klerick/some-fix-after-project
New Version:)
2 parents e405f37 + e76d32c commit 490b51f

File tree

86 files changed

+10514
-7861
lines changed

Some content is hidden

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

86 files changed

+10514
-7861
lines changed

.eslintrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
"jest": true
3434
},
3535
"rules": {}
36+
},
37+
{
38+
"files": ["*.ts"],
39+
"rules": {
40+
"@angular-eslint/prefer-standalone": "off"
41+
}
3642
}
3743
],
3844
"extends": ["./.eslintrc.base.json"]

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ testem.log
3939
Thumbs.db
4040

4141
.nx/cache
42+
.nx/workspace-data
4243
.angular
4344
.dev.env

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
/coverage
44
/.nx/cache
55
.angular
6+
7+
/.nx/workspace-data

README.md

+1-15
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,10 @@ $ npm run seed:run
2323
## Running the example app
2424

2525
```bash
26-
# build plugin
27-
$ npm run json-api-nestjs:build
28-
2926
# dev server
30-
$ npm run example:serve
27+
$ npm run demo:json-api
3128

3229
```
33-
34-
## Test
35-
36-
```bash
37-
# unit tests
38-
$ nx test json-api-nestjs
39-
40-
# test coverage
41-
$ nx test json-api-nestjs --coverage
42-
```
43-
4430
## License
4531

4632
The plugin is [MIT licensed](LICENSE).

apps/json-api-front/.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"prefix": "nestjs-json-api",
2525
"style": "kebab-case"
2626
}
27-
]
27+
],
28+
"@angular-eslint/prefer-standalone": "off"
2829
}
2930
},
3031
{

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Component, inject, OnInit } from '@angular/core';
22
import { NxWelcomeComponent } from './nx-welcome.component';
33
import { JsonApiSdkService } from 'json-api-nestjs-sdk';
4-
import { AtomicFactory } from 'json-api-nestjs-sdk/json-api-nestjs-sdk.module';
4+
import { AtomicFactory } from 'json-api-nestjs-sdk/ngModule';
55
import {
66
JSON_RPC,
77
RPC_BATCH,
88
Rpc,
9-
} from '@klerick/nestjs-json-rpc-sdk/json-rpc-sdk.module';
9+
} from '@klerick/nestjs-json-rpc-sdk/ngModule';
1010

1111
import { RpcService as IRpcService } from '@nestjs-json-api/type-for-rpc';
1212
import { switchMap } from 'rxjs';
@@ -16,11 +16,11 @@ type RpcMap = {
1616
};
1717

1818
@Component({
19-
standalone: true,
2019
imports: [NxWelcomeComponent],
2120
selector: 'nestjs-json-api-root',
2221
templateUrl: './app.component.html',
2322
styleUrl: './app.component.css',
23+
standalone: true,
2424
})
2525
export class AppComponent implements OnInit {
2626
private JsonApiSdkService = inject(JsonApiSdkService);

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

+17-23
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1+
import { ApplicationConfig, InjectionToken } from '@angular/core';
2+
import { provideJsonApi } from 'json-api-nestjs-sdk/ngModule';
13
import {
2-
ApplicationConfig,
3-
importProvidersFrom,
4-
InjectionToken,
5-
} from '@angular/core';
6-
import { JsonApiAngular } from 'json-api-nestjs-sdk/json-api-nestjs-sdk.module';
7-
import {
8-
JsonRpcAngular,
94
JsonRpcAngularConfig,
105
TransportType,
11-
} from '@klerick/nestjs-json-rpc-sdk/json-rpc-sdk.module';
6+
provideJsonRpc,
7+
} from '@klerick/nestjs-json-rpc-sdk/ngModule';
128
import { Subject } from 'rxjs';
139
import { webSocket } from 'rxjs/webSocket';
1410
import { io } from 'socket.io-client';
11+
import { provideHttpClient, withFetch } from '@angular/common/http';
1512

1613
const destroySubject = new Subject<boolean>();
1714
setTimeout(() => {
@@ -58,21 +55,18 @@ const ioConfig: JsonRpcAngularConfig = {
5855

5956
export const appConfig: ApplicationConfig = {
6057
providers: [
61-
importProvidersFrom(
62-
JsonApiAngular.forRoot({
63-
apiHost: 'http://localhost:4200',
64-
idKey: 'id',
65-
apiPrefix: 'api',
66-
operationUrl: 'operation',
67-
})
68-
),
69-
importProvidersFrom(
70-
JsonRpcAngular.forRoot(
71-
// httpConfig
72-
// wsConfig
73-
// wsConfigWithToken,
74-
ioConfig
75-
)
58+
provideHttpClient(withFetch()),
59+
provideJsonApi({
60+
apiHost: 'http://localhost:4200',
61+
idKey: 'id',
62+
apiPrefix: 'api',
63+
operationUrl: 'operation',
64+
}),
65+
provideJsonRpc(
66+
// httpConfig
67+
// wsConfig
68+
// wsConfigWithToken,
69+
ioConfig
7670
),
7771
],
7872
};

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { CommonModule } from '@angular/common';
33

44
@Component({
55
selector: 'nestjs-json-api-nx-welcome',
6-
standalone: true,
76
imports: [CommonModule],
7+
standalone: true,
88
template: `
99
<!--
1010
* * * * * * * * * * * * * * * * * * * * * * * * * * * *

apps/json-api-server-e2e/project.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
],
1414
"options": {
1515
"jestConfig": "apps/json-api-server-e2e/jest.config.ts",
16-
"passWithNoTests": true
16+
"passWithNoTests": true,
17+
"parallel": 1
1718
}
1819
}
1920
}

apps/json-api-server-e2e/src/json-api/json-api-sdk/atomic-sdk.spec.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,25 @@ describe('Atomic method:', () => {
8686
);
8787
}
8888

89-
await Promise.all(
90-
[...usersArray, ...addressArray, ...commentsArray, ...rolesArray].map(
91-
(i) => jsonSdk.jonApiSdkService.deleteOne(i)
92-
)
93-
);
89+
for (const item of [
90+
...usersArray,
91+
...addressArray,
92+
...commentsArray,
93+
...rolesArray,
94+
]) {
95+
await jsonSdk.jonApiSdkService.deleteOne(item);
96+
}
97+
});
98+
99+
it('Try check intreceptor', async () => {
100+
const newUser = getUser();
101+
newUser.addresses = addressArray[0];
102+
try {
103+
const result = await jsonSdk.atomicFactory().postOne(newUser).run();
104+
usersId.push(result[0].id);
105+
} catch (e) {
106+
console.log(e);
107+
}
94108
});
95109

96110
it('Should be correct work', async () => {

apps/json-api-server-e2e/src/json-api/json-api-sdk/get-method.spec.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { faker } from '@faker-js/faker';
55
import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk';
66
import { getUser } from '../utils/data-utils';
77
import { creatSdk, run } from '../utils/run-application';
8+
import { AxiosError } from 'axios';
89

910
let app: INestApplication;
1011

@@ -90,9 +91,10 @@ describe('GET method:', () => {
9091
return Promise.all(tmp);
9192
})
9293
);
94+
await Promise.all(addressArray);
9395
await Promise.all(
94-
[...usersArray, ...addressArray, ...commentsArray, ...rolesArray].map(
95-
(i) => jsonSdk.jonApiSdkService.deleteOne(i)
96+
[...usersArray, ...commentsArray, ...rolesArray].map((i) =>
97+
jsonSdk.jonApiSdkService.deleteOne(i)
9698
)
9799
);
98100
});

apps/json-api-server/src/app/resources/controllers/extend-user/extend-user.controller.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
HttpExceptionMethodFilter,
3030
} from '../../service/http-exception.filter';
3131
import { GuardService, EntityName } from '../../service/guard.service';
32+
import { AtomicInterceptor } from '../../service/atomic.interceptor';
3233

3334
@UseGuards(GuardService)
3435
@UseFilters(new HttpExceptionFilter())
@@ -52,6 +53,7 @@ export class ExtendUserController extends JsonBaseController<Users> {
5253
return super.patchRelationship(id, relName, input);
5354
}
5455

56+
// @UseInterceptors(AtomicInterceptor)
5557
postOne(inputData: PostData<Users>): Promise<ResourceObject<Users>> {
5658
return super.postOne(inputData);
5759
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {
2+
CallHandler,
3+
ExecutionContext,
4+
NestInterceptor,
5+
Injectable,
6+
} from '@nestjs/common';
7+
import { Observable } from 'rxjs';
8+
9+
@Injectable()
10+
export class AtomicInterceptor<T> implements NestInterceptor {
11+
intercept(context: ExecutionContext, next: CallHandler<T>): Observable<T> {
12+
const isAtomic = context.getArgByIndex(3);
13+
if (isAtomic) {
14+
console.log('call from atomic operation');
15+
}
16+
return next.handle();
17+
}
18+
}

apps/json-api-server/src/main.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ async function bootstrap() {
2525
SwaggerModule.setup(
2626
'swagger',
2727
app,
28-
() => SwaggerModule.createDocument(app, config),
28+
() => ({
29+
...SwaggerModule.createDocument(app, config),
30+
openapi: '3.1.0',
31+
}),
2932
{}
3033
);
3134
await app.init();

jest.config.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getJestProjects } from '@nx/jest';
1+
import { getJestProjectsAsync } from '@nx/jest';
22

3-
export default {
4-
projects: getJestProjects()
5-
};
3+
export default async () => ({
4+
projects: await getJestProjectsAsync()
5+
});

libs/database/src/lib/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
22

33
import { config as ormConfig } from './config-cli';
4-
import { Roles, Comments, Users, Addresses, BookList } from './entities';
4+
import * as allEntities from './entities';
55

66
export const config: TypeOrmModuleOptions = {
77
...ormConfig,
88
...{
9-
entities: [Roles, Comments, Users, Addresses, BookList],
9+
entities: Object.values(allEntities) as any,
1010
},
1111
};

libs/json-api/json-api-nestjs-sdk/.eslintrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
"rules": {
2121
"@nx/dependency-checks": "error"
2222
}
23+
},
24+
{
25+
"files": ["*.ts"],
26+
"rules": {
27+
"@angular-eslint/prefer-standalone": "off"
28+
}
2329
}
2430
]
2531
}

libs/json-api/json-api-nestjs-sdk/README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ const [addressPost, managerPost, rolesPost, userPost] = await jsonSdk
9393
```
9494
or you can use Angular module:
9595
```typescript
96-
import { JsonApiAngular, AtomicFactory } from 'json-api-nestjs-sdk/json-api-nestjs-sdk.module';
97-
import { JsonApiSdkService } from 'json-api-nestjs-sdk';
96+
import { provideJsonApi, AtomicFactory, JsonApiSdkService } from 'json-api-nestjs-sdk/ngModule';
97+
import {
98+
provideHttpClient,
99+
withFetch,
100+
} from '@angular/common/http';
98101

99102
@Component({
100103
standalone: true,
@@ -116,9 +119,8 @@ const angularConfig: JsonSdkConfig = {
116119

117120
bootstrapApplication(AppComponent, {
118121
providers: [
119-
importProvidersFrom(
120-
JsonApiAngular.forRoot(angularConfig)
121-
),
122+
provideHttpClient(withFetch()),
123+
provideJsonApi(angularConfig)
122124
],
123125
}).catch((err) =>
124126
console.error(err)

libs/json-api/json-api-nestjs-sdk/ng-package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3-
"dest": "../../../tmp/angular-lib/json-api-nestjs-sdk",
3+
"dest": "../../../tmp/angular-lib/ngModule",
44
"lib": {
55
"entryFile": "../../index.ts"
66
}

libs/json-api/json-api-nestjs-sdk/package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"engines": {
55
"node": ">= 16.0.0"
66
},
7-
"description": "JsonAPi Plugin for NestJs",
7+
"description": "Helper for client JsonAPi Plugin for NestJs",
88
"contributors": [
99
{
1010
"email": "[email protected]",
@@ -28,5 +28,12 @@
2828
"json-api",
2929
"typeorm",
3030
"CRUD"
31-
]
31+
],
32+
"peerDependencies": {
33+
"@angular/common": ">=19.0.0 <20.0.0",
34+
"@angular/core": ">=19.0.0 <20.0.0",
35+
"axios": "^1.6.0",
36+
"reflect-metadata": "^0.1.13",
37+
"tslib": "^2.3.0"
38+
}
3239
}

libs/json-api/json-api-nestjs-sdk/project.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"outputPath": "dist/libs/json-api/json-api-nestjs-sdk",
3030
"commands": [
3131
"node tools/scripts/preparation-hybrid-npm-package.mjs json-api-nestjs-sdk",
32-
"node tools/scripts/preparation-npm-package.mjs json-api-nestjs-sdk",
33-
"node tools/scripts/prepare-for-angular.mjs json-api-nestjs-sdk json-api-angular"
32+
"node tools/scripts/preparation-npm-package.mjs json-api-nestjs-sdk"
3433
],
3534
"cwd": "./",
3635
"parallel": false
@@ -51,7 +50,7 @@
5150
"updateBuildableProjectDepsInPackageJson": true,
5251
"buildableProjectDepsInPackageJsonType": "peerDependencies",
5352
"additionalEntryPoints": [
54-
"libs/json-api/json-api-nestjs-sdk/src/json-api-nestjs-sdk.module.ts"
53+
"libs/json-api/json-api-nestjs-sdk/src/ngModule.ts"
5554
],
5655
"generateExportsField": true
5756
}
@@ -68,7 +67,7 @@
6867
"updateBuildableProjectDepsInPackageJson": true,
6968
"buildableProjectDepsInPackageJsonType": "peerDependencies",
7069
"additionalEntryPoints": [
71-
"libs/json-api/json-api-nestjs-sdk/src/json-api-nestjs-sdk.module.ts"
70+
"libs/json-api/json-api-nestjs-sdk/src/ngModule.ts"
7271
],
7372
"generateExportsField": true
7473
}

0 commit comments

Comments
 (0)