ng2-rest 21.0.59 → 21.0.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -131
- package/VERIFIED-BUILD-DATA.jsonc +3 -3
- package/bin/ng2-rest +0 -0
- package/bin/ng2-rest-debug +0 -0
- package/bin/ng2-rest-debug-brk +0 -0
- package/bin/start.js +36 -36
- package/browser/README.md +24 -24
- package/browser/fesm2022/ng2-rest-browser.mjs +83 -91
- package/browser/fesm2022/ng2-rest-browser.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/browser/types/ng2-rest-browser.d.ts +2 -6
- package/browser-prod/README.md +24 -24
- package/browser-prod/fesm2022/ng2-rest-browser-prod.mjs +83 -91
- package/browser-prod/fesm2022/ng2-rest-browser-prod.mjs.map +1 -1
- package/browser-prod/package.json +1 -1
- package/browser-prod/types/ng2-rest-browser-prod.d.ts +2 -6
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/env/env.angular-node-app.d.ts +1 -0
- package/lib/env/env.angular-node-app.js +6 -2
- package/lib/env/env.angular-node-app.js.map +1 -1
- package/lib/env/env.docs-webapp.d.ts +1 -0
- package/lib/env/env.docs-webapp.js +6 -2
- package/lib/env/env.docs-webapp.js.map +1 -1
- package/lib/env/env.electron-app.d.ts +1 -0
- package/lib/env/env.electron-app.js +6 -2
- package/lib/env/env.electron-app.js.map +1 -1
- package/lib/env/env.mobile-app.d.ts +1 -0
- package/lib/env/env.mobile-app.js +6 -2
- package/lib/env/env.mobile-app.js.map +1 -1
- package/lib/env/env.npm-lib-and-cli-tool.d.ts +1 -0
- package/lib/env/env.npm-lib-and-cli-tool.js +6 -2
- package/lib/env/env.npm-lib-and-cli-tool.js.map +1 -1
- package/lib/env/env.vscode-plugin.d.ts +1 -0
- package/lib/env/env.vscode-plugin.js +6 -2
- package/lib/env/env.vscode-plugin.js.map +1 -1
- package/lib/new-mapping.js +26 -0
- package/lib/new-mapping.js.map +1 -1
- package/lib/new-mapping.test.d.ts +1 -1
- package/lib/ng2-rest.d.ts +4 -8
- package/lib/ng2-rest.js +54 -91
- package/lib/ng2-rest.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib-esm/app.electron.js +1 -81
- package/lib-esm/app.electron.js.map +1 -1
- package/lib-esm/app.hosts.d.ts +0 -3
- package/lib-esm/app.hosts.js +1 -52
- package/lib-esm/app.hosts.js.map +1 -1
- package/lib-esm/app.js +1 -317
- package/lib-esm/app.js.map +1 -1
- package/lib-esm/app.vscode.js +1 -46
- package/lib-esm/app.vscode.js.map +1 -1
- package/lib-esm/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib-esm/lib/build-info._auto-generated_.js +1 -1
- package/lib-esm/lib/env/env.angular-node-app.d.ts +1 -0
- package/lib-esm/lib/env/env.angular-node-app.js +3 -0
- package/lib-esm/lib/env/env.angular-node-app.js.map +1 -1
- package/lib-esm/lib/env/env.docs-webapp.d.ts +1 -0
- package/lib-esm/lib/env/env.docs-webapp.js +3 -0
- package/lib-esm/lib/env/env.docs-webapp.js.map +1 -1
- package/lib-esm/lib/env/env.electron-app.d.ts +1 -0
- package/lib-esm/lib/env/env.electron-app.js +3 -0
- package/lib-esm/lib/env/env.electron-app.js.map +1 -1
- package/lib-esm/lib/env/env.mobile-app.d.ts +1 -0
- package/lib-esm/lib/env/env.mobile-app.js +3 -0
- package/lib-esm/lib/env/env.mobile-app.js.map +1 -1
- package/lib-esm/lib/env/env.npm-lib-and-cli-tool.d.ts +1 -0
- package/lib-esm/lib/env/env.npm-lib-and-cli-tool.js +3 -0
- package/lib-esm/lib/env/env.npm-lib-and-cli-tool.js.map +1 -1
- package/lib-esm/lib/env/env.vscode-plugin.d.ts +1 -0
- package/lib-esm/lib/env/env.vscode-plugin.js +3 -0
- package/lib-esm/lib/env/env.vscode-plugin.js.map +1 -1
- package/lib-esm/lib/new-mapping.js +26 -0
- package/lib-esm/lib/new-mapping.js.map +1 -1
- package/lib-esm/lib/ng2-rest.d.ts +2 -6
- package/lib-esm/lib/ng2-rest.js +52 -91
- package/lib-esm/lib/ng2-rest.js.map +1 -1
- package/lib-prod/build-info._auto-generated_.d.ts +1 -1
- package/lib-prod/build-info._auto-generated_.js +1 -1
- package/lib-prod/env/env.angular-node-app.d.ts +1 -0
- package/lib-prod/env/env.angular-node-app.js +3 -0
- package/lib-prod/env/env.angular-node-app.js.map +1 -1
- package/lib-prod/env/env.docs-webapp.d.ts +1 -0
- package/lib-prod/env/env.docs-webapp.js +3 -0
- package/lib-prod/env/env.docs-webapp.js.map +1 -1
- package/lib-prod/env/env.electron-app.d.ts +1 -0
- package/lib-prod/env/env.electron-app.js +3 -0
- package/lib-prod/env/env.electron-app.js.map +1 -1
- package/lib-prod/env/env.mobile-app.d.ts +1 -0
- package/lib-prod/env/env.mobile-app.js +3 -0
- package/lib-prod/env/env.mobile-app.js.map +1 -1
- package/lib-prod/env/env.npm-lib-and-cli-tool.d.ts +1 -0
- package/lib-prod/env/env.npm-lib-and-cli-tool.js +3 -0
- package/lib-prod/env/env.npm-lib-and-cli-tool.js.map +1 -1
- package/lib-prod/env/env.vscode-plugin.d.ts +1 -0
- package/lib-prod/env/env.vscode-plugin.js +3 -0
- package/lib-prod/env/env.vscode-plugin.js.map +1 -1
- package/lib-prod/new-mapping.js +26 -0
- package/lib-prod/new-mapping.js.map +1 -1
- package/lib-prod/ng2-rest.d.ts +2 -6
- package/lib-prod/ng2-rest.js +54 -91
- package/lib-prod/ng2-rest.js.map +1 -1
- package/lib-prod/package.json +1 -1
- package/package.json +1 -1
- package/websql/README.md +24 -24
- package/websql/fesm2022/ng2-rest-websql.mjs +83 -91
- package/websql/fesm2022/ng2-rest-websql.mjs.map +1 -1
- package/websql/package.json +1 -1
- package/websql/types/ng2-rest-websql.d.ts +2 -6
- package/websql-prod/README.md +24 -24
- package/websql-prod/fesm2022/ng2-rest-websql-prod.mjs +83 -91
- package/websql-prod/fesm2022/ng2-rest-websql-prod.mjs.map +1 -1
- package/websql-prod/package.json +1 -1
- package/websql-prod/types/ng2-rest-websql-prod.d.ts +2 -6
package/README.md
CHANGED
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
|
|
2
|
-
## ng2-rest ##
|
|
3
|
-
|
|
4
|
-
Robust isomorphic REST framework
|
|
5
|
-
- for browser (Angular, React etc.)
|
|
6
|
-
- for backend Taon apps/libs (NodeJS/TypeScript)
|
|
7
|
-
(part of [taon.dev](https://github.com/darekf77/taon)).
|
|
8
|
-
|
|
9
|
-
Features:
|
|
10
|
-
- Compatible with Angular (2+) (newest 13,14 also...) , React, Vue , NodeJS (works everywhere)
|
|
11
|
-
- Compatible with RxJS operators (exhaustMap, switchMap, request cancelation etc.)
|
|
12
|
-
- Based on [axios](https://axios-http.com/) => excellent alternative to Angular's [HttpClient](https://angular.io/api/common/http/HttpClient)
|
|
13
|
-
- JSONP api request handling
|
|
14
|
-
- Transfer class instance from server to client and back
|
|
15
|
-
- Elegant way of dealing with REST api ( *similar to ExpressJS routes definitions* )
|
|
16
|
-
|
|
17
|
-
(more documentation soon... )
|
|
18
|
-
|
|
19
|
-
To install this package run:
|
|
20
|
-
|
|
21
|
-
npm install ng2-rest --save
|
|
22
|
-
|
|
23
|
-
Import Resource class:
|
|
24
|
-
```ts
|
|
25
|
-
import { Resource } from 'ng2-rest/browser';
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Resource
|
|
29
|
-
========
|
|
30
|
-
|
|
31
|
-
Fit you existing API (not only REST) into new fluent objects with **Resource**
|
|
32
|
-
class observables. Use power of **async** in new angular templates;
|
|
33
|
-
|
|
34
|
-
**template.html**
|
|
35
|
-
```html
|
|
36
|
-
Users:
|
|
37
|
-
<ul *ngIf="model.allUsers() | async; else loader; let users" >
|
|
38
|
-
|
|
39
|
-
<li *ngFor="let user of users">
|
|
40
|
-
{{user.id}} {{user.fullName()}}
|
|
41
|
-
<br>
|
|
42
|
-
<input type="name" [(NgModel)]="user.name" >
|
|
43
|
-
<button (click)="model.update(user)" > Update </button>
|
|
44
|
-
</li>
|
|
45
|
-
|
|
46
|
-
</ul>
|
|
47
|
-
|
|
48
|
-
<ng-template #loader> loading users... </ng-template>
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
**component.ts**
|
|
52
|
-
```ts
|
|
53
|
-
class User {
|
|
54
|
-
name: string;
|
|
55
|
-
surname: string;
|
|
56
|
-
id: number;
|
|
57
|
-
|
|
58
|
-
fullName() {
|
|
59
|
-
return `Surname: ${this.surname}, Name: ${this.name}`;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Express.js style url endpoint model
|
|
64
|
-
// you can ommit "<User>" part is you don't wanna see response interface
|
|
65
|
-
// also you can ommit third argument ",User" is you don't wanna
|
|
66
|
-
// map response object to User class objects
|
|
67
|
-
const rest = Resource.create<User>("http://yourbackend.com/api","users/:id",{'':User} )
|
|
68
|
-
|
|
69
|
-
class UserComponent {
|
|
70
|
-
|
|
71
|
-
// Prepare your beautiful interface
|
|
72
|
-
model = {
|
|
73
|
-
allUsers: () => rest.model()
|
|
74
|
-
.array
|
|
75
|
-
.get()
|
|
76
|
-
.observable // Observable resposnse (useful for Angular 2+ html templates)
|
|
77
|
-
.pipe( map({ body } => body.json) ) // get all users, body.json => User[]
|
|
78
|
-
|
|
79
|
-
userBy: (id) => rest.model({id})
|
|
80
|
-
.get() // Promise response by default
|
|
81
|
-
.then({ body } => console.log(body.json)) // get user by id, body.json => User
|
|
82
|
-
|
|
83
|
-
update: async (user:User) =>{
|
|
84
|
-
try {
|
|
85
|
-
await rest.model({id:user.id}).put(user) // Promise response by default
|
|
86
|
-
|
|
87
|
-
alert('Update sucess')
|
|
88
|
-
} catch(e) {
|
|
89
|
-
alert(e)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
constructor() { }
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Specification
|
|
100
|
-
============
|
|
101
|
-
Example **UrlParams[]** :
|
|
102
|
-
`[ { sort: true },{ filter: 'id,5' }, { filter: 'name,test' } ]`
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
| Name | Parameters | Description |
|
|
106
|
-
| :---: | --- | ---: |
|
|
107
|
-
| **array** | changes response type to array |
|
|
108
|
-
| **get** | `model, UrlParams[] ` | get data |
|
|
109
|
-
| **post** | `model, UrlParams[] ` | create data |
|
|
110
|
-
| **patch** | `model, UrlParams[] ` | change data <br>(effect of changing data may be diffrent with each request) |
|
|
111
|
-
| **put** | `model, UrlParams[]` | change data <br>(can be done multiple times with same effect) |
|
|
112
|
-
| **head** | `model, UrlParams[]` | check data |
|
|
113
|
-
| **delete** | `model, UrlParams[] ` | remove data |
|
|
114
|
-
| **jsonp** | `model, UrlParams[] ` | get jsonp data |
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
# Production mode
|
|
119
|
-
===
|
|
120
|
-
Nice things to do in production mode:
|
|
121
|
-
|
|
122
|
-
**1. Disable warnings.**
|
|
123
|
-
|
|
124
|
-
If you don't wanna see warning, disable it like this:
|
|
125
|
-
```ts
|
|
126
|
-
if (environment.production) {
|
|
127
|
-
Resource.enableWarnings = false;
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
|
|
1
|
+
|
|
2
|
+
## ng2-rest ##
|
|
3
|
+
|
|
4
|
+
Robust isomorphic REST framework
|
|
5
|
+
- for browser (Angular, React etc.)
|
|
6
|
+
- for backend Taon apps/libs (NodeJS/TypeScript)
|
|
7
|
+
(part of [taon.dev](https://github.com/darekf77/taon)).
|
|
8
|
+
|
|
9
|
+
Features:
|
|
10
|
+
- Compatible with Angular (2+) (newest 13,14 also...) , React, Vue , NodeJS (works everywhere)
|
|
11
|
+
- Compatible with RxJS operators (exhaustMap, switchMap, request cancelation etc.)
|
|
12
|
+
- Based on [axios](https://axios-http.com/) => excellent alternative to Angular's [HttpClient](https://angular.io/api/common/http/HttpClient)
|
|
13
|
+
- JSONP api request handling
|
|
14
|
+
- Transfer class instance from server to client and back
|
|
15
|
+
- Elegant way of dealing with REST api ( *similar to ExpressJS routes definitions* )
|
|
16
|
+
|
|
17
|
+
(more documentation soon... )
|
|
18
|
+
|
|
19
|
+
To install this package run:
|
|
20
|
+
|
|
21
|
+
npm install ng2-rest --save
|
|
22
|
+
|
|
23
|
+
Import Resource class:
|
|
24
|
+
```ts
|
|
25
|
+
import { Resource } from 'ng2-rest/browser';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Resource
|
|
29
|
+
========
|
|
30
|
+
|
|
31
|
+
Fit you existing API (not only REST) into new fluent objects with **Resource**
|
|
32
|
+
class observables. Use power of **async** in new angular templates;
|
|
33
|
+
|
|
34
|
+
**template.html**
|
|
35
|
+
```html
|
|
36
|
+
Users:
|
|
37
|
+
<ul *ngIf="model.allUsers() | async; else loader; let users" >
|
|
38
|
+
|
|
39
|
+
<li *ngFor="let user of users">
|
|
40
|
+
{{user.id}} {{user.fullName()}}
|
|
41
|
+
<br>
|
|
42
|
+
<input type="name" [(NgModel)]="user.name" >
|
|
43
|
+
<button (click)="model.update(user)" > Update </button>
|
|
44
|
+
</li>
|
|
45
|
+
|
|
46
|
+
</ul>
|
|
47
|
+
|
|
48
|
+
<ng-template #loader> loading users... </ng-template>
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
**component.ts**
|
|
52
|
+
```ts
|
|
53
|
+
class User {
|
|
54
|
+
name: string;
|
|
55
|
+
surname: string;
|
|
56
|
+
id: number;
|
|
57
|
+
|
|
58
|
+
fullName() {
|
|
59
|
+
return `Surname: ${this.surname}, Name: ${this.name}`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Express.js style url endpoint model
|
|
64
|
+
// you can ommit "<User>" part is you don't wanna see response interface
|
|
65
|
+
// also you can ommit third argument ",User" is you don't wanna
|
|
66
|
+
// map response object to User class objects
|
|
67
|
+
const rest = Resource.create<User>("http://yourbackend.com/api","users/:id",{'':User} )
|
|
68
|
+
|
|
69
|
+
class UserComponent {
|
|
70
|
+
|
|
71
|
+
// Prepare your beautiful interface
|
|
72
|
+
model = {
|
|
73
|
+
allUsers: () => rest.model()
|
|
74
|
+
.array
|
|
75
|
+
.get()
|
|
76
|
+
.observable // Observable resposnse (useful for Angular 2+ html templates)
|
|
77
|
+
.pipe( map({ body } => body.json) ) // get all users, body.json => User[]
|
|
78
|
+
|
|
79
|
+
userBy: (id) => rest.model({id})
|
|
80
|
+
.get() // Promise response by default
|
|
81
|
+
.then({ body } => console.log(body.json)) // get user by id, body.json => User
|
|
82
|
+
|
|
83
|
+
update: async (user:User) =>{
|
|
84
|
+
try {
|
|
85
|
+
await rest.model({id:user.id}).put(user) // Promise response by default
|
|
86
|
+
|
|
87
|
+
alert('Update sucess')
|
|
88
|
+
} catch(e) {
|
|
89
|
+
alert(e)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
constructor() { }
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Specification
|
|
100
|
+
============
|
|
101
|
+
Example **UrlParams[]** :
|
|
102
|
+
`[ { sort: true },{ filter: 'id,5' }, { filter: 'name,test' } ]`
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
| Name | Parameters | Description |
|
|
106
|
+
| :---: | --- | ---: |
|
|
107
|
+
| **array** | changes response type to array |
|
|
108
|
+
| **get** | `model, UrlParams[] ` | get data |
|
|
109
|
+
| **post** | `model, UrlParams[] ` | create data |
|
|
110
|
+
| **patch** | `model, UrlParams[] ` | change data <br>(effect of changing data may be diffrent with each request) |
|
|
111
|
+
| **put** | `model, UrlParams[]` | change data <br>(can be done multiple times with same effect) |
|
|
112
|
+
| **head** | `model, UrlParams[]` | check data |
|
|
113
|
+
| **delete** | `model, UrlParams[] ` | remove data |
|
|
114
|
+
| **jsonp** | `model, UrlParams[] ` | get jsonp data |
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# Production mode
|
|
119
|
+
===
|
|
120
|
+
Nice things to do in production mode:
|
|
121
|
+
|
|
122
|
+
**1. Disable warnings.**
|
|
123
|
+
|
|
124
|
+
If you don't wanna see warning, disable it like this:
|
|
125
|
+
```ts
|
|
126
|
+
if (environment.production) {
|
|
127
|
+
Resource.enableWarnings = false;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"commitHash": "
|
|
3
|
-
"commitName": "
|
|
4
|
-
"commitDate": "
|
|
2
|
+
"commitHash": "5d3f0ee896a720b8f325c00902600faef4561220",
|
|
3
|
+
"commitName": "feat: prevent overriding getters for mapping",
|
|
4
|
+
"commitDate": "26-09-2026 22:06:37"
|
|
5
5
|
}
|
package/bin/ng2-rest
CHANGED
|
File without changes
|
package/bin/ng2-rest-debug
CHANGED
|
File without changes
|
package/bin/ng2-rest-debug-brk
CHANGED
|
File without changes
|
package/bin/start.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
global.frameworkName = 'ng2-rest';
|
|
2
|
-
Error.stackTraceLimit = 100;
|
|
3
|
-
global.i0 = {
|
|
4
|
-
defineInjectable: function () { }
|
|
5
|
-
}
|
|
6
|
-
const process= require('process');
|
|
7
|
-
global.currentTaonScriptStartDateTime = process.hrtime.bigint();
|
|
8
|
-
|
|
9
|
-
process.removeAllListeners('warning');
|
|
10
|
-
var argv = process.argv;
|
|
11
|
-
|
|
12
|
-
global.hideLog = true;
|
|
13
|
-
global.verboseLevel = 0;
|
|
14
|
-
var verboseLevel = argv.find(a => a.startsWith('-verbose='));
|
|
15
|
-
if (typeof verboseLevel !== 'undefined') {
|
|
16
|
-
global.hideLog = false;
|
|
17
|
-
verboseLevel = Number(verboseLevel.replace('-verbose=', ''));
|
|
18
|
-
if (!isNaN(verboseLevel)) {
|
|
19
|
-
global.verboseLevel = verboseLevel;
|
|
20
|
-
}
|
|
21
|
-
argv = argv.filter(a => !a.startsWith('-verbose='));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (argv.includes('-verbose')) {
|
|
25
|
-
global.hideLog = false;
|
|
26
|
-
argv = argv.filter(a => a !== '-verbose');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const fs = require('fs');
|
|
30
|
-
const path = require('path');
|
|
31
|
-
var pathToCliJS = {
|
|
32
|
-
distDev: path.join(__dirname, '../dist/cli.js'),
|
|
33
|
-
localOrNPm: path.join(__dirname, '../cli.js')
|
|
34
|
-
}
|
|
35
|
-
var p = fs.existsSync(pathToCliJS.distDev) ? pathToCliJS.distDev : pathToCliJS.localOrNPm;
|
|
36
|
-
global.globalSystemToolMode = true;
|
|
37
|
-
var run = require(p).startCli;
|
|
2
|
+
Error.stackTraceLimit = 100;
|
|
3
|
+
global.i0 = {
|
|
4
|
+
defineInjectable: function () { }
|
|
5
|
+
}
|
|
6
|
+
const process= require('process');
|
|
7
|
+
global.currentTaonScriptStartDateTime = process.hrtime.bigint();
|
|
8
|
+
|
|
9
|
+
process.removeAllListeners('warning');
|
|
10
|
+
var argv = process.argv;
|
|
11
|
+
|
|
12
|
+
global.hideLog = true;
|
|
13
|
+
global.verboseLevel = 0;
|
|
14
|
+
var verboseLevel = argv.find(a => a.startsWith('-verbose='));
|
|
15
|
+
if (typeof verboseLevel !== 'undefined') {
|
|
16
|
+
global.hideLog = false;
|
|
17
|
+
verboseLevel = Number(verboseLevel.replace('-verbose=', ''));
|
|
18
|
+
if (!isNaN(verboseLevel)) {
|
|
19
|
+
global.verboseLevel = verboseLevel;
|
|
20
|
+
}
|
|
21
|
+
argv = argv.filter(a => !a.startsWith('-verbose='));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (argv.includes('-verbose')) {
|
|
25
|
+
global.hideLog = false;
|
|
26
|
+
argv = argv.filter(a => a !== '-verbose');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const fs = require('fs');
|
|
30
|
+
const path = require('path');
|
|
31
|
+
var pathToCliJS = {
|
|
32
|
+
distDev: path.join(__dirname, '../dist/cli.js'),
|
|
33
|
+
localOrNPm: path.join(__dirname, '../cli.js')
|
|
34
|
+
}
|
|
35
|
+
var p = fs.existsSync(pathToCliJS.distDev) ? pathToCliJS.distDev : pathToCliJS.localOrNPm;
|
|
36
|
+
global.globalSystemToolMode = true;
|
|
37
|
+
var run = require(p).startCli;
|
|
38
38
|
run(argv,__filename);
|
package/browser/README.md
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
# MyLib
|
|
2
|
-
|
|
3
|
-
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.2.0.
|
|
4
|
-
|
|
5
|
-
## Code scaffolding
|
|
6
|
-
|
|
7
|
-
Run `ng generate component component-name --project my-lib` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project my-lib`.
|
|
8
|
-
> Note: Don't forget to add `--project my-lib` or else it will be added to the default project in your `angular.json` file.
|
|
9
|
-
|
|
10
|
-
## Build
|
|
11
|
-
|
|
12
|
-
Run `ng build my-lib` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
13
|
-
|
|
14
|
-
## Publishing
|
|
15
|
-
|
|
16
|
-
After building your library with `ng build my-lib`, go to the dist folder `cd dist/my-lib` and run `npm publish`.
|
|
17
|
-
|
|
18
|
-
## Running unit tests
|
|
19
|
-
|
|
20
|
-
Run `ng test my-lib` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
21
|
-
|
|
22
|
-
## Further help
|
|
23
|
-
|
|
24
|
-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
|
1
|
+
# MyLib
|
|
2
|
+
|
|
3
|
+
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.2.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Run `ng generate component component-name --project my-lib` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project my-lib`.
|
|
8
|
+
> Note: Don't forget to add `--project my-lib` or else it will be added to the default project in your `angular.json` file.
|
|
9
|
+
|
|
10
|
+
## Build
|
|
11
|
+
|
|
12
|
+
Run `ng build my-lib` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
13
|
+
|
|
14
|
+
## Publishing
|
|
15
|
+
|
|
16
|
+
After building your library with `ng build my-lib`, go to the dist folder `cd dist/my-lib` and run `npm publish`.
|
|
17
|
+
|
|
18
|
+
## Running unit tests
|
|
19
|
+
|
|
20
|
+
Run `ng test my-lib` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
21
|
+
|
|
22
|
+
## Further help
|
|
23
|
+
|
|
24
|
+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
|
@@ -9,6 +9,27 @@ import { CLASS } from 'typescript-class-helpers/browser';
|
|
|
9
9
|
//#region constatns
|
|
10
10
|
const mappingStore = new WeakMap();
|
|
11
11
|
const defaultValueStore = new WeakMap();
|
|
12
|
+
/**
|
|
13
|
+
* Checks whether assigning to a property would override
|
|
14
|
+
* a getter-only property somewhere in the prototype chain.
|
|
15
|
+
*/
|
|
16
|
+
const canAssignProperty = (target, key) => {
|
|
17
|
+
let current = target;
|
|
18
|
+
while (current) {
|
|
19
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
20
|
+
if (descriptor) {
|
|
21
|
+
// Accessor property
|
|
22
|
+
if ('get' in descriptor || 'set' in descriptor) {
|
|
23
|
+
return typeof descriptor.set === 'function';
|
|
24
|
+
}
|
|
25
|
+
// Normal property
|
|
26
|
+
return descriptor.writable !== false;
|
|
27
|
+
}
|
|
28
|
+
current = Object.getPrototypeOf(current);
|
|
29
|
+
}
|
|
30
|
+
// Property doesn't exist yet -> safe to create
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
12
33
|
//#endregion
|
|
13
34
|
//#region decorators
|
|
14
35
|
function DefaultMapping(mapping) {
|
|
@@ -292,6 +313,11 @@ const encodeMappingFn = (input, schema, circular, parentPath = '') => {
|
|
|
292
313
|
}
|
|
293
314
|
for (const key of Object.keys(input)) {
|
|
294
315
|
const value = input[key];
|
|
316
|
+
// Don't try to overwrite getter-only / readonly properties.
|
|
317
|
+
if (!canAssignProperty(instance, key)) {
|
|
318
|
+
// console.log({keyNot:key})
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
295
321
|
const fullPath = parentPath ? `${parentPath}.${key}` : key;
|
|
296
322
|
const rule = schema[fullPath];
|
|
297
323
|
if (!rule) {
|
|
@@ -322,72 +348,37 @@ var _a;
|
|
|
322
348
|
//#endregion
|
|
323
349
|
const log = Log.create('ng2-rest', Level.WARN, Level.ERROR);
|
|
324
350
|
const listenErrorsSrc = new Subject();
|
|
325
|
-
//#region cookie
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
// }
|
|
357
|
-
// }
|
|
358
|
-
// // 2) proceed
|
|
359
|
-
// const sub = next.handle(req).subscribe({
|
|
360
|
-
// next: res => {
|
|
361
|
-
// // 3) store Set-Cookie back into jar
|
|
362
|
-
// const setCookie = (res.headers as any)?.['set-cookie'];
|
|
363
|
-
// const cookies: string[] =
|
|
364
|
-
// typeof setCookie === 'string'
|
|
365
|
-
// ? [setCookie]
|
|
366
|
-
// : Array.isArray(setCookie)
|
|
367
|
-
// ? setCookie
|
|
368
|
-
// : [];
|
|
369
|
-
// if (!cookies.length) {
|
|
370
|
-
// subscriber.next(res);
|
|
371
|
-
// return;
|
|
372
|
-
// }
|
|
373
|
-
// let pending = cookies.length;
|
|
374
|
-
// for (const c of cookies) {
|
|
375
|
-
// this.jar.setCookie(c, url, () => {
|
|
376
|
-
// pending--;
|
|
377
|
-
// if (pending === 0) {
|
|
378
|
-
// subscriber.next(res);
|
|
379
|
-
// }
|
|
380
|
-
// });
|
|
381
|
-
// }
|
|
382
|
-
// },
|
|
383
|
-
// error: e => subscriber.error(e),
|
|
384
|
-
// complete: () => subscriber.complete(),
|
|
385
|
-
// });
|
|
386
|
-
// return () => sub.unsubscribe();
|
|
387
|
-
// });
|
|
388
|
-
// });
|
|
389
|
-
// }
|
|
390
|
-
// }
|
|
351
|
+
//#region cookie jar
|
|
352
|
+
/* */
|
|
353
|
+
/* */
|
|
354
|
+
/* */
|
|
355
|
+
/* */
|
|
356
|
+
/* */
|
|
357
|
+
/* */
|
|
358
|
+
/* */
|
|
359
|
+
/* */
|
|
360
|
+
/* */
|
|
361
|
+
/* */
|
|
362
|
+
/* */
|
|
363
|
+
/* */
|
|
364
|
+
/* */
|
|
365
|
+
/* */
|
|
366
|
+
/* */
|
|
367
|
+
/* */
|
|
368
|
+
/* */
|
|
369
|
+
/* */
|
|
370
|
+
/* */
|
|
371
|
+
/* */
|
|
372
|
+
/* */
|
|
373
|
+
/* */
|
|
374
|
+
/* */
|
|
375
|
+
/* */
|
|
376
|
+
/* */
|
|
377
|
+
/* */
|
|
378
|
+
/* */
|
|
379
|
+
/* */
|
|
380
|
+
/* */
|
|
381
|
+
/* */
|
|
391
382
|
class Cookie {
|
|
392
383
|
static get Instance() {
|
|
393
384
|
if (!Cookie.__instance) {
|
|
@@ -946,6 +937,7 @@ class HttpResponseError extends BaseResponse {
|
|
|
946
937
|
this.body = new ErrorBody(url, responseText);
|
|
947
938
|
}
|
|
948
939
|
}
|
|
940
|
+
//#endregion
|
|
949
941
|
//#region default headers
|
|
950
942
|
const HeaderKeyContentType = 'Content-Type';
|
|
951
943
|
const HeaderKeyAccept = 'Accept';
|
|
@@ -1003,6 +995,17 @@ class ResourceResponse {
|
|
|
1003
995
|
this.methodsInterceptors = methodsInterceptors;
|
|
1004
996
|
this[_a] = 'Promise';
|
|
1005
997
|
}
|
|
998
|
+
async makeRequestWithGlobalErrorHandling(abortSignal) {
|
|
999
|
+
try {
|
|
1000
|
+
return await this.makeRequest(abortSignal);
|
|
1001
|
+
}
|
|
1002
|
+
catch (error) {
|
|
1003
|
+
// if (error instanceof HttpResponseError) {
|
|
1004
|
+
listenErrorsSrc.next(error);
|
|
1005
|
+
// }
|
|
1006
|
+
throw error;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1006
1009
|
/**
|
|
1007
1010
|
* ✅ Explicit cancel (useful for "promise style")
|
|
1008
1011
|
*/
|
|
@@ -1015,7 +1018,7 @@ class ResourceResponse {
|
|
|
1015
1018
|
get promise() {
|
|
1016
1019
|
if (!this._promise) {
|
|
1017
1020
|
this._promiseAbort = new AbortController();
|
|
1018
|
-
this._promise = this.
|
|
1021
|
+
this._promise = this.makeRequestWithGlobalErrorHandling(this._promiseAbort.signal);
|
|
1019
1022
|
}
|
|
1020
1023
|
return this._promise;
|
|
1021
1024
|
}
|
|
@@ -1038,18 +1041,19 @@ class ResourceResponse {
|
|
|
1038
1041
|
if (!this._observable) {
|
|
1039
1042
|
this._observable = new Observable(subscriber => {
|
|
1040
1043
|
const ac = new AbortController();
|
|
1041
|
-
this.
|
|
1044
|
+
this.makeRequestWithGlobalErrorHandling(ac.signal)
|
|
1042
1045
|
.then(res => {
|
|
1043
|
-
if (res instanceof HttpResponseError) {
|
|
1044
|
-
subscriber.error(res);
|
|
1045
|
-
return;
|
|
1046
|
-
}
|
|
1047
1046
|
subscriber.next(res);
|
|
1048
1047
|
subscriber.complete();
|
|
1049
1048
|
})
|
|
1050
|
-
.catch(err =>
|
|
1049
|
+
.catch(err => {
|
|
1050
|
+
subscriber.error(err);
|
|
1051
|
+
});
|
|
1051
1052
|
return () => ac.abort('rxjs-unsubscribe');
|
|
1052
|
-
}).pipe(shareReplay({
|
|
1053
|
+
}).pipe(shareReplay({
|
|
1054
|
+
bufferSize: 1,
|
|
1055
|
+
refCount: true,
|
|
1056
|
+
}));
|
|
1053
1057
|
}
|
|
1054
1058
|
return this._observable;
|
|
1055
1059
|
}
|
|
@@ -1067,6 +1071,11 @@ class ResourceResponse {
|
|
|
1067
1071
|
//#region resource reponse http strategy
|
|
1068
1072
|
class ResourceResponseHttp extends ResourceResponse {
|
|
1069
1073
|
async makeRequest(abortSignal) {
|
|
1074
|
+
/* */
|
|
1075
|
+
/* */
|
|
1076
|
+
/* */
|
|
1077
|
+
/* */
|
|
1078
|
+
/* */
|
|
1070
1079
|
const url = this.creatUrl(this.urlParams, !!this.axiosOptions?.doNotSerializeParams);
|
|
1071
1080
|
const method = this.httpMethodName;
|
|
1072
1081
|
log.d(`Requesting ${method} ${url}`);
|
|
@@ -1114,23 +1123,6 @@ class ResourceResponseHttp extends ResourceResponse {
|
|
|
1114
1123
|
catchedError?.name === 'CanceledError') {
|
|
1115
1124
|
throw new HttpResponseError(url, method, JSON.stringify({ message: 'Request canceled' }), this.options, RestHeaders.from(), 0, this.isArray);
|
|
1116
1125
|
}
|
|
1117
|
-
//#region handle global error listener for notificaitons
|
|
1118
|
-
if (typeof catchedError === 'object' &&
|
|
1119
|
-
catchedError.response &&
|
|
1120
|
-
catchedError.response.data) {
|
|
1121
|
-
const err = catchedError.response.data;
|
|
1122
|
-
const msg = catchedError.response.data.message || '';
|
|
1123
|
-
// console.log({
|
|
1124
|
-
// 'err.stack': err?.stack
|
|
1125
|
-
// })
|
|
1126
|
-
let stack = (err.stack || '').split('\n');
|
|
1127
|
-
listenErrorsSrc.next({
|
|
1128
|
-
msg,
|
|
1129
|
-
stack,
|
|
1130
|
-
data: catchedError.response.data,
|
|
1131
|
-
});
|
|
1132
|
-
}
|
|
1133
|
-
//#endregion
|
|
1134
1126
|
const status = catchedError?.response?.status ?? 0; // ✅ FIX: you used "status" before defining it
|
|
1135
1127
|
const data = catchedError?.response?.data ?? catchedError?.message ?? catchedError;
|
|
1136
1128
|
const responseText = typeof data === 'string' ? data : JSON.stringify(data);
|