Skip to content

Commit 4dfcf0a

Browse files
authored
Merge pull request #8 from klerick/beta
new version sdk
2 parents 6595e83 + 11be692 commit 4dfcf0a

Some content is hidden

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

65 files changed

+11591
-867
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
</p>
1717

1818
- *[json-api-nestjs](https://github.com/klerick/nestjs-json-api/tree/master/libs/json-api-nestjs)* - plugin for create CRUD overs JSON API
19-
- *json-api-nestjs-sdk* - tool for client, call api over *json-api-nestjs*(coming soon...)
20-
- *kson-api-nestjs-acl* - tool for acl over *json-api-nestjs*(coming soon...)
19+
- *[json-api-nestjs-sdk](https://github.com/klerick/nestjs-json-api/tree/master/libs/json-api-nestjs-sdk)* - tool for client, call api over *json-api-nestjs*
20+
- *json-api-nestjs-acl* - tool for acl over *json-api-nestjs*(coming soon...)
2121
## Installation
2222

2323
```bash

apps/example-angular-client/project.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
"prefix": "nestjs-json-api",
77
"targets": {
88
"build": {
9-
"executor": "@angular-devkit/build-angular:browser",
9+
"executor": "@angular-builders/custom-webpack:browser",
1010
"outputs": ["{options.outputPath}"],
1111
"options": {
12+
"customWebpackConfig": {
13+
"path": "apps/example-angular-client/webpack.config.ts",
14+
"mergeRules": {
15+
"externals": "replace"
16+
}
17+
},
1218
"outputPath": "dist/apps/example-angular-client",
1319
"index": "apps/example-angular-client/src/index.html",
1420
"main": "apps/example-angular-client/src/main.ts",
@@ -55,7 +61,7 @@
5561
"defaultConfiguration": "production"
5662
},
5763
"serve": {
58-
"executor": "@angular-devkit/build-angular:dev-server",
64+
"executor": "@angular-builders/custom-webpack:dev-server",
5965
"configurations": {
6066
"production": {
6167
"browserTarget": "example-angular-client:build:production"
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
<nestjs-json-api-nx-welcome></nestjs-json-api-nx-welcome>
1+
<div>
2+
<pre>{{dataItem | async | json}}</pre>
3+
</div>
4+
<div>
5+
<pre>{{dataList | async | json}}</pre>
6+
</div>
Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,113 @@
1-
import { Component } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
2+
import { JsonApiSdkService, EmptyArrayRelation } from 'json-api-nestjs-sdk';
3+
import { Users, BookList, Addresses } from 'database/entity';
4+
import { map, switchMap } from 'rxjs';
5+
6+
const user = new Users();
7+
user.id = 17;
28

39
@Component({
410
selector: 'nestjs-json-api-root',
511
templateUrl: './app.component.html',
612
styleUrls: ['./app.component.css'],
13+
changeDetection: ChangeDetectionStrategy.OnPush,
714
})
8-
export class AppComponent {
15+
export class AppComponent implements OnInit {
916
title = 'example-angular-client';
17+
dataList = this.jsonApiSdkService.getAll<Users>(
18+
Users,
19+
{
20+
filter: {
21+
target: {
22+
isActive: {
23+
eq: 'true',
24+
},
25+
},
26+
},
27+
include: ['comments', 'addresses'],
28+
page: {
29+
size: 5,
30+
number: 1,
31+
},
32+
},
33+
true
34+
);
35+
dataItem = this.jsonApiSdkService.getOne<Users>(
36+
Users,
37+
17,
38+
{
39+
fields: {
40+
target: ['login'],
41+
addresses: ['city', 'state'],
42+
comments: ['text', 'kind'],
43+
},
44+
include: ['comments', 'addresses'],
45+
},
46+
true
47+
);
48+
49+
constructor(private jsonApiSdkService: JsonApiSdkService) {}
50+
51+
ngOnInit(): void {
52+
this.jsonApiSdkService
53+
.getOne<Users>(
54+
Users,
55+
17,
56+
{
57+
fields: {
58+
target: ['login'],
59+
addresses: ['city', 'state'],
60+
comments: ['text', 'kind'],
61+
},
62+
include: ['comments', 'addresses'],
63+
},
64+
true
65+
)
66+
.pipe(
67+
switchMap(({ entity, meta }) => {
68+
const bookList = new BookList();
69+
bookList.users = [entity];
70+
bookList.text = 'Book list';
71+
return this.jsonApiSdkService.postOne<BookList>(bookList, true);
72+
}),
73+
switchMap(({ entity, meta }) => {
74+
const bookList = new BookList();
75+
bookList.id = entity.id;
76+
bookList.users = new EmptyArrayRelation();
77+
bookList.text = 'Change Text';
78+
return this.jsonApiSdkService.patchOne(bookList, true);
79+
}),
80+
switchMap(({ entity, meta }) => {
81+
return this.jsonApiSdkService.deleteOne(entity);
82+
})
83+
)
84+
.subscribe((r) => console.log(r));
85+
86+
this.jsonApiSdkService
87+
.getRelationships(user, 'addresses')
88+
.subscribe((r) => console.log(r));
89+
this.jsonApiSdkService
90+
.getRelationships(user, 'comments')
91+
.subscribe((r) => console.log(r));
92+
93+
this.jsonApiSdkService
94+
.getAll<Addresses>(Addresses)
95+
.pipe(
96+
map((r) => r[0]),
97+
switchMap((addresses) => {
98+
return this.jsonApiSdkService
99+
.getOne<Users>(Users, 18, { include: ['comments', 'addresses'] })
100+
.pipe(
101+
switchMap((user) => {
102+
user.addresses = addresses;
103+
return this.jsonApiSdkService.patchRelationships<Users>(
104+
user,
105+
'addresses'
106+
);
107+
})
108+
);
109+
})
110+
)
111+
.subscribe((r) => console.log(r));
112+
}
10113
}

apps/example-angular-client/src/app/app.module.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
23
import { BrowserModule } from '@angular/platform-browser';
4+
import { JsonApiNestjsSdkModule } from 'json-api-nestjs-sdk';
5+
import { BookList, Users, Roles, Comments, Addresses } from 'database/entity';
36

47
import { AppComponent } from './app.component';
58
import { NxWelcomeComponent } from './nx-welcome.component';
69

710
@NgModule({
811
declarations: [AppComponent, NxWelcomeComponent],
9-
imports: [BrowserModule],
12+
imports: [
13+
CommonModule,
14+
BrowserModule,
15+
JsonApiNestjsSdkModule.forRoot(
16+
{
17+
apiPrefix: '/api/v1',
18+
apiHost: window.location.origin,
19+
},
20+
{ BookList, Users, Roles, Comments, Addresses }
21+
),
22+
],
1023
providers: [],
1124
bootstrap: [AppComponent],
1225
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Configuration } from 'webpack';
2+
import { CustomWebpackBrowserSchema, TargetOptions } from '@angular-builders/custom-webpack';
3+
import {resolve} from 'path';
4+
5+
export default function webPackConfig(
6+
config: Configuration,
7+
options: CustomWebpackBrowserSchema,
8+
targetOptions: TargetOptions): Configuration {
9+
10+
(config.resolve || {}).alias = {
11+
typeorm: resolve(__dirname, "../../node_modules/typeorm/typeorm-model-shim"),
12+
validator: resolve(__dirname, "../../node_modules/validator/es")
13+
}
14+
15+
return config;
16+
}
17+

apps/example-react-client/.babelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets": [
3+
[
4+
"@nrwl/react/babel",
5+
{
6+
"runtime": "automatic"
7+
}
8+
]
9+
],
10+
"plugins": []
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file is used by:
2+
# 1. autoprefixer to adjust CSS to support the below specified browsers
3+
# 2. babel preset-env to adjust included polyfills
4+
#
5+
# For additional information regarding the format and rule options, please see:
6+
# https://github.com/browserslist/browserslist#queries
7+
#
8+
# If you need to support different browsers in production, you may tweak the list below.
9+
10+
last 1 Chrome version
11+
last 1 Firefox version
12+
last 2 Edge major versions
13+
last 2 Safari major version
14+
last 2 iOS major versions
15+
Firefox ESR
16+
not IE 9-11 # For IE 9-11 support, remove 'not'.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.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+
}
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: 'example-react-client',
4+
preset: '../../jest.preset.js',
5+
transform: {
6+
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
7+
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/react/babel'] }],
8+
},
9+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
10+
coverageDirectory: '../../coverage/apps/example-react-client',
11+
};

0 commit comments

Comments
 (0)