Skip to content

Commit 7cb892e

Browse files
authored
Merge pull request #10 from manudss/wip-update-ngx
Update to last version of angular 16 + add tests -> Updates to Angular 16, and compile libs to ivy -> change to nx workspace -> Add unit tests
2 parents 7759ead + 7794f56 commit 7cb892e

File tree

152 files changed

+12085
-36821
lines changed

Some content is hidden

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

152 files changed

+12085
-36821
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.eslintrc.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"root": true,
3+
"ignorePatterns": ["**/*"],
4+
"plugins": ["@nx"],
5+
"overrides": [
6+
{
7+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
8+
"rules": {
9+
"@nx/enforce-module-boundaries": [
10+
"error",
11+
{
12+
"enforceBuildableLibDependency": true,
13+
"allow": [],
14+
"depConstraints": [
15+
{
16+
"sourceTag": "*",
17+
"onlyDependOnLibsWithTags": ["*"]
18+
}
19+
]
20+
}
21+
]
22+
}
23+
},
24+
{
25+
"files": ["*.ts", "*.tsx"],
26+
"extends": ["plugin:@nx/typescript"],
27+
"rules": {}
28+
},
29+
{
30+
"files": ["*.js", "*.jsx"],
31+
"extends": ["plugin:@nx/javascript"],
32+
"rules": {}
33+
},
34+
{
35+
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
36+
"env": {
37+
"jest": true
38+
},
39+
"rules": {}
40+
}
41+
]
42+
}

.github/workflows/npmpublish.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Node.js Package
55

66
on:
77
release:
8-
types: [created]
8+
types: [created,edited]
99

1010
jobs:
1111
build:
@@ -14,9 +14,9 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-node@v1
1616
with:
17-
node-version: 12
18-
- run: npm install
19-
- run: npm run build
17+
node-version: 16
18+
- run: yarn
19+
- run: yarn run build
2020

2121
publish-npm:
2222
needs: build
@@ -25,11 +25,11 @@ jobs:
2525
- uses: actions/checkout@v2
2626
- uses: actions/setup-node@v1
2727
with:
28-
node-version: 12
28+
node-version: 16
2929
registry-url: https://registry.npmjs.org/
30-
- run: npm install
31-
- run: npm run package
32-
- run: npm run publish
30+
- run: yarn
31+
- run: yarn run package
32+
- run: yarn run publish
3333
env:
34-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
34+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
3535

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/out-tsc
77

88
# dependencies
9-
/node_modules
9+
node_modules
1010

1111
# IDEs and editors
1212
/.idea
@@ -25,6 +25,7 @@
2525
!.vscode/extensions.json
2626

2727
# misc
28+
/.angular/cache
2829
/.sass-cache
2930
/connect.lock
3031
/coverage
@@ -37,5 +38,5 @@ testem.log
3738
# System Files
3839
.DS_Store
3940
Thumbs.db
40-
/dist/
41-
/dist/ngx-http-annotations/
41+
42+
.angular

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Add files here to ignore them from prettier formatting
2+
3+
/dist
4+
/coverage

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

.vscode/extensions.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"recommendations": [
3+
"angular.ng-template",
4+
"nrwl.angular-console",
5+
"esbenp.prettier-vscode",
6+
"firsttris.vscode-jest-runner",
7+
"dbaeumer.vscode-eslint"
8+
]
9+
}

0.34.0

Lines changed: 0 additions & 69 deletions
This file was deleted.

README.md

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
This library allows to interact with rest api in your angular app.
44
It contains:
55

6-
- Annotations for http methods (@GET, @POST, @PUT, @DELETE, @OPTIONS, @HEAD, @PATCH)
7-
- Annotations for adding headers, setting produces results and intercepting response
8-
- Params annotations
9-
10-
forked from : https://github.com/Mixalloff/ngx-http-rest
6+
- Annotations for http methods (@GET, @POST, @PUT, @DELETE, @OPTIONS, @HEAD, @PATCH)
7+
- Annotations for adding headers, setting produces results and intercepting response
8+
- Params annotations
9+
10+
forked from : https://github.com/Mixalloff/ngx-http-rest
1111

1212
### Installation
1313

@@ -25,23 +25,23 @@ Example of using library.
2525
1) Plug the HttpRestModule into your AppModule
2626

2727
```typescript
28-
import { HttpRestModule } from 'ngx-http-annotations';
28+
import { NgxHttpAnnotationsModule } from 'ngx-http-annotations';
2929
import { NgModule } from '@angular/core';
3030

3131
@NgModule({
3232
imports: [
33-
HttpRestModule
33+
NgxHttpAnnotationsModule
3434
]
3535
})
3636
export class AppModule {
3737
}
3838
```
3939

40-
2) Create a service to work with rest api. Inherit it from HttpRestService from 'ngx-http-rest'. Put annotations on the class, methods and params.
40+
2) Create a service to work with rest api. Put annotations on the class, methods and params.
4141

4242

4343
```typescript
44-
import { HttpRestService, GET, POST, DELETE, Path, PathParam, Body, QueryParam, QueryParams, ResponseObservable } from 'ngx-http-annotations';
44+
import { GET, POST, DELETE, Path, PathParam, Body, QueryParam, QueryParams, ResponseObservable } from 'ngx-http-annotations';
4545
import { Injectable } from '@angular/core';
4646
import RestConfig from 'app/core/configs/rest.config';
4747

@@ -60,7 +60,7 @@ interface GoodsItem {
6060
'someHeader2': 'headerValue2'
6161
})
6262
@Path(`/test/goods`)
63-
export class SomeRestService extends HttpRestService {
63+
export class SomeRestService {
6464

6565
@GET
6666
getGoods(@QueryParams /* Object with queryParams { [name: string]: [value: any] } */ queryObj?: any): any {}
@@ -126,24 +126,24 @@ export class TestComponent implements OnInit {
126126
### Description
127127
Available annotations:
128128
1) Request methods
129-
@GET, @POST, @PUT, @DELETE, @OPTIONS, @HEAD, @PATCH - marks methods implementing the corresponding requests
129+
@GET, @POST, @PUT, @DELETE, @OPTIONS, @HEAD, @PATCH - marks methods implementing the corresponding requests
130130
2) Added settings
131-
- @Path - set path of url for request. Combined class @Path annotation value and current method @Path. Path params passed with ":". For example @Path('/someurl/:someParam')
132-
- @Headers - set headers for request (if annotate class, then all class methods getting this headers. method Headers merge with class Headers)
133-
- @Produces - setting expected response type. By default Reponse transformed by .json() method
134-
- @Observes - setting http observes.
135-
3) Parameters
136-
- @PathParam (or @Path) - pass current parameter by name to collected url. Example: someFunc(@PathParam('id') itemId: number) {}
137-
- @Body - pass body object into request. Ex.: someMethod(@Body bodyObject: any){}
138-
- @QueryParam - pass single query parameters into request. Ex.: someMethod(@QueryParam('a') a: any, @QueryParam('b') b: any) {}. someMethod(1, 2) -> ..requested_url..?a=1&b=2
139-
- @QueryParams - pass object with few query params. Ex.: someMethod(@QueryParams queryObj: any){}. someMethod({x: 1, y: 2, z: 3}) -> ..requested_url..?x=1&y=2&z=3
140-
- @ResponseObservable - specify in witch function params, the response observable will be added. Ex.: someMethod(@ResponseObservable res: Observable<any> = undefined){ /* transform request */ return res; }. need to initialise as undefined to pass compile error, and return a response.
141-
142-
143-
#### Transform response with all rxjs function
144-
145-
By adding the parameters @ResponseObservable you can specify, where add the observable response,
146-
131+
- @Path - set path of url for request. Combined class @Path annotation value and current method @Path. Path params passed with ":". For example @Path('/someurl/:someParam')
132+
- @Headers - set headers for request (if annotate class, then all class methods getting this headers. method Headers merge with class Headers)
133+
- @Produces - setting expected response type. By default Reponse transformed by .json() method
134+
- @Observes - setting http observes.
135+
3) Parameters
136+
- @PathParam (or @Path) - pass current parameter by name to collected url. Example: someFunc(@PathParam('id') itemId: number) {}
137+
- @Body - pass body object into request. Ex.: someMethod(@Body bodyObject: any){}
138+
- @QueryParam - pass single query parameters into request. Ex.: someMethod(@QueryParam('a') a: any, @QueryParam('b') b: any) {}. someMethod(1, 2) -> ..requested_url..?a=1&b=2
139+
- @QueryParams - pass object with few query params. Ex.: someMethod(@QueryParams queryObj: any){}. someMethod({x: 1, y: 2, z: 3}) -> ..requested_url..?x=1&y=2&z=3
140+
- @ResponseObservable - specify in witch function params, the response observable will be added. Ex.: someMethod(@ResponseObservable res: Observable<any> = undefined){ /* transform request */ return res; }. need to initialise as undefined to pass compile error, and return a response.
141+
142+
143+
#### Transform response with all rxjs function
144+
145+
By adding the parameters @ResponseObservable you can specify, where add the observable response,
146+
147147
```typescript
148148

149149
@GET
@@ -157,13 +157,13 @@ Available annotations:
157157
```
158158
### Mocks calls
159159

160-
To have a feature to enable mocks api. When enabled, will call directly the function rather than call the http request.
160+
To have a feature to enable mocks api. When enabled, will call directly the function rather than call the http request.
161161

162162
To enable Mocks : in a module provider use this :
163163
```typescript
164164
providers: [{ provide: HTTP_ANNOTATIONS_USE_MOCKS, useValue: true }]
165165
```
166-
You can specify a boolean value, or have a specific function, that will be used to know if the apps will use mock.
166+
You can specify a boolean value, or have a specific function, that will be used to know if the apps will use mock.
167167
This could help you to define mock only for specific call.
168168

169169

@@ -174,7 +174,7 @@ providers: [{ provide: HTTP_ANNOTATIONS_USE_MOCKS, useValue: (url, requestType,
174174
} }]
175175
```
176176

177-
define your mocks by return a fake observable, with your mock data.
177+
define your mocks by return a fake observable, with your mock data.
178178

179179
```typescript
180180
@GET
@@ -184,25 +184,33 @@ define your mocks by return a fake observable, with your mock data.
184184
}
185185
```
186186

187-
### Change logs
187+
### Change logs
188188

189189
0.6.x
190190

191-
-> updates to latest versions of Angular
192-
-> Rename library to ngx-http-annotations
193-
-> add @ResponseObservable to transform response.
194-
195-
0.6.2 et 0.6.3
191+
-> updates to the latest versions of Angular
192+
-> Rename library to ngx-http-annotations
193+
-> add @ResponseObservable to transform response.
196194

197-
-> update to build library with angular, to avoid error when build in --prod
195+
0.6.2 et 0.6.3
198196

199-
0.7.x
197+
-> update to build the library with angular, to avoid error when build in --prod
200198

201-
-> Add a mock feature.
202-
-> Update dependency to latest
203-
199+
0.7.x
204200

205-
### Source and issues
201+
-> Add a mock feature.
202+
-> Update dependency to latest
206203

207-
Code are located in github : https://github.com/manudss/ngx-http-annotations
204+
0.7.3
205+
-> Add delay: Add a beta feature, to add a delay to all requests, or have a function that returns this delay. This could be useful, in the mock feature. By default, all mock, will have a default delay. But could be also added without mock, to simulate long request.
206+
-> Use all httpClient methods rather than use request method, use the corresponding method (get, put, delete ...). In order, to avoid issue with request method that throw a first empty error.
207+
-> Update dependencies: Update to version 13 of Angular.
208+
209+
0.8.0
210+
-> Updates to Angular 16, and compile libs to ivy
211+
-> change to nx workspace
212+
-> Add unit tests
208213

214+
### Source and issues
215+
216+
Code are located in github : https://github.com/manudss/ngx-http-annotations

0 commit comments

Comments
 (0)