Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Version:) #96

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c3b9322
feat(nestjs-json-rpc): Add support soft delete
klerick Dec 5, 2024
28d3efc
feat(nestjs-json-rpc-sdk): Skip empty element in response
klerick Dec 5, 2024
7953371
feat(json-api-nestjs-sdk,nestjs-json-rpc-sdk): Change export
klerick Dec 5, 2024
9bbe9fd
fix(json-api-nestjs-sdk): Fix check for relation and add type for met…
klerick Dec 5, 2024
8e498a8
feat(json-api-nestjs): Add wrapper transaction options
klerick Dec 5, 2024
9e0f066
feat(json-api-nestjs): Allow call interceptor for each operation in a…
klerick Dec 5, 2024
a8c6f83
feat(json-api-nestjs): Extend validate for array, json and datetime, …
klerick Dec 5, 2024
81fd183
chore: Some changes for developing
klerick Dec 5, 2024
6202c22
feat(json-api-nestjs): Allow set id from request for postOne
klerick Dec 5, 2024
1b61fb3
feat(json-api-nestjs): Return meta info in atomic operation
klerick Dec 5, 2024
4c5284f
chore(json-api-nestjs): Fix types
klerick Dec 5, 2024
7063fb4
test: Update test
klerick Dec 5, 2024
1ff78cd
chore: Bump for nx 19
klerick Dec 5, 2024
33f8d2b
chore: Update package-lock.json
klerick Dec 5, 2024
53c13bc
chore: change db host for e2e
klerick Dec 5, 2024
d0277e7
test: Fix e2e test
klerick Dec 5, 2024
519e3c0
fix(json-api-nestjs): Fix review comment
klerick Dec 5, 2024
08e3bb5
refactor(nestjs-json-rpc-sdk,json-api-nestjs-sdk): Remove Angular module
klerick Dec 7, 2024
aa15c28
chore(json-api-nestjs,json-api-nestjs-sdk,nestjs-json-rpc,nestjs-json…
klerick Dec 7, 2024
e76d32c
chore: Update package-lock.json
klerick Dec 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ testem.log
Thumbs.db

.nx/cache
.nx/workspace-data
.angular
.dev.env
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/coverage
/.nx/cache
.angular

/.nx/workspace-data
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,10 @@ $ npm run seed:run
## Running the example app

```bash
# build plugin
$ npm run json-api-nestjs:build

# dev server
$ npm run example:serve
$ npm run demo:json-api

```

## Test

```bash
# unit tests
$ nx test json-api-nestjs

# test coverage
$ nx test json-api-nestjs --coverage
```

## License

The plugin is [MIT licensed](LICENSE).
4 changes: 2 additions & 2 deletions apps/json-api-front/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Component, inject, OnInit } from '@angular/core';
import { NxWelcomeComponent } from './nx-welcome.component';
import { JsonApiSdkService } from 'json-api-nestjs-sdk';
import { AtomicFactory } from 'json-api-nestjs-sdk/json-api-nestjs-sdk.module';
import { AtomicFactory } from 'json-api-nestjs-sdk/ngModule';
import {
JSON_RPC,
RPC_BATCH,
Rpc,
} from '@klerick/nestjs-json-rpc-sdk/json-rpc-sdk.module';
} from '@klerick/nestjs-json-rpc-sdk/ngModule';

import { RpcService as IRpcService } from '@nestjs-json-api/type-for-rpc';
import { switchMap } from 'rxjs';
Expand Down
6 changes: 4 additions & 2 deletions apps/json-api-front/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import {
importProvidersFrom,
InjectionToken,
} from '@angular/core';
import { JsonApiAngular } from 'json-api-nestjs-sdk/json-api-nestjs-sdk.module';
import { JsonApiAngular, provideJsonApi } from 'json-api-nestjs-sdk/ngModule';
import {
JsonRpcAngular,
JsonRpcAngularConfig,
TransportType,
} from '@klerick/nestjs-json-rpc-sdk/json-rpc-sdk.module';
provideJsonRpc,
} from '@klerick/nestjs-json-rpc-sdk/ngModule';
import { Subject } from 'rxjs';
import { webSocket } from 'rxjs/webSocket';
import { io } from 'socket.io-client';
import { provideHttpClient, withInterceptors } from '@angular/common/http';

const destroySubject = new Subject<boolean>();
setTimeout(() => {
Expand Down
3 changes: 2 additions & 1 deletion apps/json-api-server-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
],
"options": {
"jestConfig": "apps/json-api-server-e2e/jest.config.ts",
"passWithNoTests": true
"passWithNoTests": true,
"parallel": 1
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,25 @@ describe('Atomic method:', () => {
);
}

await Promise.all(
[...usersArray, ...addressArray, ...commentsArray, ...rolesArray].map(
(i) => jsonSdk.jonApiSdkService.deleteOne(i)
)
);
for (const item of [
...usersArray,
...addressArray,
...commentsArray,
...rolesArray,
]) {
await jsonSdk.jonApiSdkService.deleteOne(item);
}
});

it('Try check intreceptor', async () => {
const newUser = getUser();
newUser.addresses = addressArray[0];
try {
const result = await jsonSdk.atomicFactory().postOne(newUser).run();
usersId.push(result[0].id);
} catch (e) {
console.log(e);
}
});

it('Should be correct work', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { faker } from '@faker-js/faker';
import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk';
import { getUser } from '../utils/data-utils';
import { creatSdk, run } from '../utils/run-application';
import { AxiosError } from 'axios';

let app: INestApplication;

Expand Down Expand Up @@ -90,9 +91,10 @@ describe('GET method:', () => {
return Promise.all(tmp);
})
);
await Promise.all(addressArray);
await Promise.all(
[...usersArray, ...addressArray, ...commentsArray, ...rolesArray].map(
(i) => jsonSdk.jonApiSdkService.deleteOne(i)
[...usersArray, ...commentsArray, ...rolesArray].map((i) =>
jsonSdk.jonApiSdkService.deleteOne(i)
)
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
HttpExceptionMethodFilter,
} from '../../service/http-exception.filter';
import { GuardService, EntityName } from '../../service/guard.service';
import { AtomicInterceptor } from '../../service/atomic.interceptor';

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

// @UseInterceptors(AtomicInterceptor)
postOne(inputData: PostData<Users>): Promise<ResourceObject<Users>> {
return super.postOne(inputData);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
CallHandler,
ExecutionContext,
NestInterceptor,
Injectable,
} from '@nestjs/common';
import { Observable } from 'rxjs';

@Injectable()
export class AtomicInterceptor<T> implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler<T>): Observable<T> {
const isAtomic = context.getArgByIndex(3);
if (isAtomic) {
console.log('call from atomic operation');
}
return next.handle();
}
}
5 changes: 4 additions & 1 deletion apps/json-api-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ async function bootstrap() {
SwaggerModule.setup(
'swagger',
app,
() => SwaggerModule.createDocument(app, config),
() => ({
...SwaggerModule.createDocument(app, config),
openapi: '3.1.0',
}),
{}
);
await app.init();
Expand Down
4 changes: 2 additions & 2 deletions libs/database/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TypeOrmModuleOptions } from '@nestjs/typeorm';

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

export const config: TypeOrmModuleOptions = {
...ormConfig,
...{
entities: [Roles, Comments, Users, Addresses, BookList],
entities: Object.values(allEntities) as any,
},
};
3 changes: 1 addition & 2 deletions libs/json-api/json-api-nestjs-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ const [addressPost, managerPost, rolesPost, userPost] = await jsonSdk
```
or you can use Angular module:
```typescript
import { JsonApiAngular, AtomicFactory } from 'json-api-nestjs-sdk/json-api-nestjs-sdk.module';
import { JsonApiSdkService } from 'json-api-nestjs-sdk';
import { JsonApiAngular, AtomicFactory, JsonApiSdkService } from 'json-api-nestjs-sdk/ngModule';

@Component({
standalone: true,
Expand Down
2 changes: 1 addition & 1 deletion libs/json-api/json-api-nestjs-sdk/ng-package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../tmp/angular-lib/json-api-nestjs-sdk",
"dest": "../../../tmp/angular-lib/ngModule",
"lib": {
"entryFile": "../../index.ts"
}
Expand Down
4 changes: 2 additions & 2 deletions libs/json-api/json-api-nestjs-sdk/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"updateBuildableProjectDepsInPackageJson": true,
"buildableProjectDepsInPackageJsonType": "peerDependencies",
"additionalEntryPoints": [
"libs/json-api/json-api-nestjs-sdk/src/json-api-nestjs-sdk.module.ts"
"libs/json-api/json-api-nestjs-sdk/src/ngModule.ts"
],
"generateExportsField": true
}
Expand All @@ -68,7 +68,7 @@
"updateBuildableProjectDepsInPackageJson": true,
"buildableProjectDepsInPackageJsonType": "peerDependencies",
"additionalEntryPoints": [
"libs/json-api/json-api-nestjs-sdk/src/json-api-nestjs-sdk.module.ts"
"libs/json-api/json-api-nestjs-sdk/src/ngModule.ts"
],
"generateExportsField": true
}
Expand Down
9 changes: 8 additions & 1 deletion libs/json-api/json-api-nestjs-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export { JsonApiUtilsService, JsonApiSdkService } from './lib/service';
export * from './lib/json-api-js';
export { adapterForAxios } from './lib/utils';
export { FilterOperand } from './lib/types';
export {
FilterOperand,
ResourceObject,
AtomicOperations,
Operands,
QueryField,
QueryParams,
} from './lib/types';

This file was deleted.

94 changes: 54 additions & 40 deletions libs/json-api/json-api-nestjs-sdk/src/lib/json-api-angular.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { NgModule, ModuleWithProviders, inject } from '@angular/core';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import {
NgModule,
ModuleWithProviders,
inject,
makeEnvironmentProviders,
} from '@angular/core';
import {
HttpClient,
provideHttpClient,
withInterceptorsFromDi,
} from '@angular/common/http';
import { HttpInnerClient, JsonSdkConfig } from './types';
import { AtomicFactory, JSON_API_SDK_CONFIG } from './token';
import { resultConfig } from './utils';
Expand All @@ -9,51 +18,56 @@ import {
AtomicOperationsService,
} from './service';

export const getProviders = (config: JsonSdkConfig) => [
{
provide: JSON_API_SDK_CONFIG,
useValue: resultConfig(config),
},
{
provide: JsonApiUtilsService,
useFactory: () => new JsonApiUtilsService(inject(JSON_API_SDK_CONFIG)),
},
{
provide: JsonApiSdkService,
useFactory: () =>
new JsonApiSdkService(
inject<HttpInnerClient>(HttpClient as any),
inject(JsonApiUtilsService),
inject(JSON_API_SDK_CONFIG)
),
},
{
provide: AtomicFactory,
useFactory: () => {
const jsonApiUtilsService = inject(JsonApiUtilsService);
const config = inject(JSON_API_SDK_CONFIG);
const httpClient = inject<HttpInnerClient>(HttpClient as any);

return () => {
return new AtomicOperationsService(
jsonApiUtilsService,
config,
httpClient
);
};
},
},
];

export const provideJsonApi = (config: JsonSdkConfig) =>
makeEnvironmentProviders(getProviders(config));

@NgModule({
imports: [HttpClientModule],
imports: [],
providers: [provideHttpClient(withInterceptorsFromDi())],
})
export class JsonApiAngular {
static forRoot(config: JsonSdkConfig): ModuleWithProviders<JsonApiAngular> {
return {
ngModule: JsonApiAngular,
providers: [
{
provide: JSON_API_SDK_CONFIG,
useValue: resultConfig(config),
},
{
provide: JsonApiUtilsService,
useFactory: () =>
new JsonApiUtilsService(inject(JSON_API_SDK_CONFIG)),
},
{
provide: JsonApiSdkService,
useFactory: () =>
new JsonApiSdkService(
inject<HttpInnerClient>(HttpClient as any),
inject(JsonApiUtilsService),
inject(JSON_API_SDK_CONFIG)
),
},
{
provide: AtomicFactory,
useFactory: () => {
const jsonApiUtilsService = inject(JsonApiUtilsService);
const config = inject(JSON_API_SDK_CONFIG);
const httpClient = inject<HttpInnerClient>(HttpClient as any);

return () => {
return new AtomicOperationsService(
jsonApiUtilsService,
config,
httpClient
);
};
},
},
],
providers: getProviders(config),
};
}
}

export { AtomicFactory } from './token';
export { AtomicFactory, JSON_API_SDK_CONFIG } from './token';
Loading
Loading