diff --git a/libs/json-api/json-api-nestjs-sdk/README.md b/libs/json-api/json-api-nestjs-sdk/README.md index 7d355e6..15f7fbc 100644 --- a/libs/json-api/json-api-nestjs-sdk/README.md +++ b/libs/json-api/json-api-nestjs-sdk/README.md @@ -93,7 +93,11 @@ const [addressPost, managerPost, rolesPost, userPost] = await jsonSdk ``` or you can use Angular module: ```typescript -import { JsonApiAngular, AtomicFactory, JsonApiSdkService } from 'json-api-nestjs-sdk/ngModule'; +import { provideJsonApi, AtomicFactory, JsonApiSdkService } from 'json-api-nestjs-sdk/ngModule'; +import { + provideHttpClient, + withFetch, +} from '@angular/common/http'; @Component({ standalone: true, @@ -115,9 +119,8 @@ const angularConfig: JsonSdkConfig = { bootstrapApplication(AppComponent, { providers: [ - importProvidersFrom( - JsonApiAngular.forRoot(angularConfig) - ), + provideHttpClient(withFetch()), + provideJsonApi(angularConfig) ], }).catch((err) => console.error(err) diff --git a/libs/json-api/json-api-nestjs-sdk/package.json b/libs/json-api/json-api-nestjs-sdk/package.json index a1cd573..f816958 100644 --- a/libs/json-api/json-api-nestjs-sdk/package.json +++ b/libs/json-api/json-api-nestjs-sdk/package.json @@ -4,7 +4,7 @@ "engines": { "node": ">= 16.0.0" }, - "description": "JsonAPi Plugin for NestJs", + "description": "Helper for client JsonAPi Plugin for NestJs", "contributors": [ { "email": "klerick666@gmain.com", @@ -28,5 +28,12 @@ "json-api", "typeorm", "CRUD" - ] + ], + "peerDependencies": { + "@angular/common": ">=19.0.0 <20.0.0", + "@angular/core": ">=19.0.0 <20.0.0", + "axios": "^1.6.0", + "reflect-metadata": "^0.1.13", + "tslib": "^2.3.0" + } } diff --git a/libs/json-api/json-api-nestjs-sdk/project.json b/libs/json-api/json-api-nestjs-sdk/project.json index 68eeddc..bba5638 100644 --- a/libs/json-api/json-api-nestjs-sdk/project.json +++ b/libs/json-api/json-api-nestjs-sdk/project.json @@ -29,8 +29,7 @@ "outputPath": "dist/libs/json-api/json-api-nestjs-sdk", "commands": [ "node tools/scripts/preparation-hybrid-npm-package.mjs json-api-nestjs-sdk", - "node tools/scripts/preparation-npm-package.mjs json-api-nestjs-sdk", - "node tools/scripts/prepare-for-angular.mjs json-api-nestjs-sdk json-api-angular" + "node tools/scripts/preparation-npm-package.mjs json-api-nestjs-sdk" ], "cwd": "./", "parallel": false diff --git a/libs/json-api/json-api-nestjs-sdk/src/lib/json-api-angular.ts b/libs/json-api/json-api-nestjs-sdk/src/lib/json-api-angular.ts index 2998a53..4b7bfe0 100644 --- a/libs/json-api/json-api-nestjs-sdk/src/lib/json-api-angular.ts +++ b/libs/json-api/json-api-nestjs-sdk/src/lib/json-api-angular.ts @@ -1,14 +1,5 @@ -import { - NgModule, - ModuleWithProviders, - inject, - makeEnvironmentProviders, -} from '@angular/core'; -import { - HttpClient, - provideHttpClient, - withInterceptorsFromDi, -} from '@angular/common/http'; +import { inject, makeEnvironmentProviders } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; import { HttpInnerClient, JsonSdkConfig } from './types'; import { AtomicFactory, JSON_API_SDK_CONFIG } from './token'; import { resultConfig } from './utils'; @@ -57,17 +48,4 @@ export const getProviders = (config: JsonSdkConfig) => [ export const provideJsonApi = (config: JsonSdkConfig) => makeEnvironmentProviders(getProviders(config)); -@NgModule({ - imports: [], - providers: [provideHttpClient(withInterceptorsFromDi())], -}) -export class JsonApiAngular { - static forRoot(config: JsonSdkConfig): ModuleWithProviders<JsonApiAngular> { - return { - ngModule: JsonApiAngular, - providers: getProviders(config), - }; - } -} - export { AtomicFactory, JSON_API_SDK_CONFIG } from './token'; diff --git a/libs/json-api/json-api-nestjs-sdk/src/ngModule.ts b/libs/json-api/json-api-nestjs-sdk/src/ngModule.ts index d7a6493..29276e1 100644 --- a/libs/json-api/json-api-nestjs-sdk/src/ngModule.ts +++ b/libs/json-api/json-api-nestjs-sdk/src/ngModule.ts @@ -1,5 +1,4 @@ export { - JsonApiAngular, AtomicFactory, provideJsonApi, JSON_API_SDK_CONFIG, diff --git a/libs/json-api/json-api-nestjs/package.json b/libs/json-api/json-api-nestjs/package.json index e48b5fe..cee6a35 100644 --- a/libs/json-api/json-api-nestjs/package.json +++ b/libs/json-api/json-api-nestjs/package.json @@ -28,5 +28,9 @@ "json-api", "typeorm", "CRUD" - ] + ], + "peerDependencies": { + "reflect-metadata": "^0.1.13", + "tslib": "^2.3.0" + } } diff --git a/libs/json-rpc/nestjs-json-rpc-sdk/README.md b/libs/json-rpc/nestjs-json-rpc-sdk/README.md index a53a6b2..e26ed3d 100644 --- a/libs/json-rpc/nestjs-json-rpc-sdk/README.md +++ b/libs/json-rpc/nestjs-json-rpc-sdk/README.md @@ -214,10 +214,14 @@ You can use Angular module: ```typescript import { - JsonRpcAngular, + provideJsonRpc, JsonRpcAngularConfig, TransportType, } from '@klerick/nestjs-json-rpc-sdk/ngModule' +import { + provideHttpClient, + withFetch, +} from '@angular/common/http'; import { Subject } from 'rxjs'; import { io } from 'socket.io-client'; import { @@ -275,9 +279,8 @@ const ioConfig: JsonRpcAngularConfig = { bootstrapApplication(AppComponent, { providers: [ - importProvidersFrom( - JsonRpcAngular.forRoot(httpConfig) - ), + provideHttpClient(withFetch()), + provideJsonRpc(httpConfig), ], }).catch((err) => console.error(err) diff --git a/libs/json-rpc/nestjs-json-rpc-sdk/project.json b/libs/json-rpc/nestjs-json-rpc-sdk/project.json index 3ce8bd8..0e9067d 100644 --- a/libs/json-rpc/nestjs-json-rpc-sdk/project.json +++ b/libs/json-rpc/nestjs-json-rpc-sdk/project.json @@ -29,15 +29,7 @@ "outputPath": "dist/libs/json-rpc/nestjs-json-rpc-sdk", "commands": [ "node tools/scripts/preparation-hybrid-npm-package.mjs nestjs-json-rpc-sdk", - "node tools/scripts/preparation-npm-package.mjs nestjs-json-rpc-sdk", - { - "command": "nx run nestjs-json-rpc-sdk:compile-for-angular", - "forwardAllArgs": false - }, - { - "command": "cp tmp/angular-lib/nestjs-json-rpc-sdk/esm2022/lib/angular/json-rpc-angular.module.mjs dist/libs/json-rpc/nestjs-json-rpc-sdk/mjs/src/lib/angular/json-rpc-angular.module.js", - "forwardAllArgs": false - } + "node tools/scripts/preparation-npm-package.mjs nestjs-json-rpc-sdk" ], "cwd": "./", "parallel": false diff --git a/libs/json-rpc/nestjs-json-rpc-sdk/src/lib/angular/json-rpc-angular.module.ts b/libs/json-rpc/nestjs-json-rpc-sdk/src/lib/angular/json-rpc-angular.module.ts index 01700c4..c79261a 100644 --- a/libs/json-rpc/nestjs-json-rpc-sdk/src/lib/angular/json-rpc-angular.module.ts +++ b/libs/json-rpc/nestjs-json-rpc-sdk/src/lib/angular/json-rpc-angular.module.ts @@ -1,12 +1,4 @@ -import { - makeEnvironmentProviders, - ModuleWithProviders, - NgModule, -} from '@angular/core'; -import { - provideHttpClient, - withInterceptorsFromDi, -} from '@angular/common/http'; +import { makeEnvironmentProviders } from '@angular/core'; import { JSON_RPC_SDK_CONFIG } from './tokens'; import { JsonRpcAngularConfig } from '../types'; @@ -18,23 +10,3 @@ export const provideJsonRpc = (config: JsonRpcAngularConfig) => provide: JSON_RPC_SDK_CONFIG, }, ]); - -@NgModule({ - imports: [], - providers: [provideHttpClient(withInterceptorsFromDi())], -}) -export class JsonRpcAngular { - static forRoot( - config: JsonRpcAngularConfig - ): ModuleWithProviders<JsonRpcAngular> { - return { - ngModule: JsonRpcAngular, - providers: [ - { - useValue: config, - provide: JSON_RPC_SDK_CONFIG, - }, - ], - }; - } -} diff --git a/libs/json-rpc/nestjs-json-rpc-sdk/src/lib/json-rpc-angular.ts b/libs/json-rpc/nestjs-json-rpc-sdk/src/lib/json-rpc-angular.ts index 8f538e0..7ea8cf9 100644 --- a/libs/json-rpc/nestjs-json-rpc-sdk/src/lib/json-rpc-angular.ts +++ b/libs/json-rpc/nestjs-json-rpc-sdk/src/lib/json-rpc-angular.ts @@ -1,6 +1,3 @@ -export { - JsonRpcAngular, - provideJsonRpc, -} from './angular/json-rpc-angular.module'; +export { provideJsonRpc } from './angular/json-rpc-angular.module'; export { JsonRpcAngularConfig, TransportType, Rpc } from './types'; export { JSON_RPC, RPC_BATCH } from './angular/tokens'; diff --git a/tools/scripts/prepare-for-angular.mjs b/tools/scripts/prepare-for-angular.mjs deleted file mode 100644 index 2e59965..0000000 --- a/tools/scripts/prepare-for-angular.mjs +++ /dev/null @@ -1,42 +0,0 @@ -import devkit from '@nx/devkit'; -import { readFileSync, writeFileSync, unlinkSync } from 'fs'; -import { exec } from 'child_process'; -import { promisify } from 'util'; - -const { readCachedProjectGraph } = devkit; - -const [, , name, angularName] = process.argv; - -const graph = readCachedProjectGraph(); -const project = graph.nodes[name]; - -const outputPath = project.data?.targets?.build?.options?.outputPath; -const sourceRoot = project.data?.sourceRoot; - -const packageJson = JSON.parse( - readFileSync(`${outputPath}/package.json`).toString() -); -const angularFile = Object.keys(packageJson.exports) - .filter((i) => !['./package.json', '.'].includes(i)) - .pop() - .replace('./', ''); -const [_, ...pathToModule] = sourceRoot.split('/'); - -const [nameSpace] = pathToModule; - -const TEMP_FILE_PATH = 'libs/index.ts'; -const ANGULAR_MODULE_PATH = `tmp/angular-lib/ngModule/esm2022/${nameSpace}/${name}/src/lib/${angularName}.mjs`; -const LIB_ANGULAR_MODULE_PATH = `${outputPath}/mjs/src/lib/${angularName}.js`; - -writeFileSync( - TEMP_FILE_PATH, - `export * from './${pathToModule.join('/')}/${angularFile}';` -); - -promisify(exec)(`nx run ${name}:compile-for-angular`) - .then((r) => { - writeFileSync(LIB_ANGULAR_MODULE_PATH, readFileSync(ANGULAR_MODULE_PATH)); - }) - .finally(() => { - unlinkSync(TEMP_FILE_PATH); - });