Skip to content

Commit 9180a7e

Browse files
committedApr 8, 2021
FE-256-fix-force-ttl-0 auto-commit
2 parents 8bd34ed + 1eb25eb commit 9180a7e

33 files changed

+472
-225
lines changed
 

‎CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
### Fixed
1010

1111
- when ttl 0 was set, a request to the server was not made again, it brought it from memory, it was corrected in the isLive function of common.
12+
## [2.2.1] - 2020-10-17
13+
14+
### Fixed
15+
16+
- Warning: Entry point 'ngx-jsonapi' contains deep imports into 'node_modules/rxjs/internal/util/noop'. This is probably not a problem, but may cause the compilation of entry points to be out of order.
17+
- lodash dependency missing.
18+
19+
## [2.2.0] - 2020-10-17
20+
21+
### Changed
22+
23+
- Local cache store is disabled by default.
24+
- Only used lodash functions are included on base script. 69.44 KB to 7.5 KB, 89% saved!
25+
- Store support is optional.
26+
27+
![image](https://user-images.githubusercontent.com/938894/96340064-d58a7500-106e-11eb-9181-464186f9e2f1.png)
28+
29+
### Removed
30+
31+
- config.cachestore_support
1232

1333
## [2.1.19] - 2020-08-25
1434

‎README.md

+32-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ yarn add ngx-jsonapi@2.0.0-rc.4 --save
5555
3. Inject JsonapiCore somewhere before you extend any class from `Jsonapi.Resource`.
5656

5757
```typescript
58-
import { NgModule } from '@angular/core';
58+
/* .. */
5959
import { NgxJsonapiModule } from 'ngx-jsonapi';
6060

6161
@NgModule({
@@ -68,6 +68,37 @@ import { NgxJsonapiModule } from 'ngx-jsonapi';
6868
export class AppModule {}
6969
```
7070

71+
### Enable Local Cache
72+
73+
Library cache anything memory. With Local Store, also store all on IndexDb on browser. Faster apps when we reuse a lot of data.
74+
75+
```typescript
76+
/* .. */
77+
import { NgxJsonapiModule } from 'ngx-jsonapi';
78+
import { JSONAPI_RIPPER_SERVICE, JSONAPI_STORE_SERVICE } from './core';
79+
import { StoreService } from 'ngx-jsonapi/sources/store.service';
80+
import { JsonRipper } from 'ngx-jsonapi/services/json-ripper';
81+
82+
@NgModule({
83+
imports: [
84+
NgxJsonapiModule.forRoot({
85+
url: '//jsonapiplayground.reyesoft.com/v2/'
86+
})
87+
],
88+
providers: [
89+
{
90+
provide: JSONAPI_RIPPER_SERVICE,
91+
useClass: JsonRipperFake
92+
},
93+
{
94+
provide: JSONAPI_STORE_SERVICE,
95+
useClass: StoreFakeService
96+
}
97+
]
98+
})
99+
export class AppModule {}
100+
```
101+
71102
## Examples
72103

73104
Like you know, the better way is with examples. Lets go! 🚀

‎angular.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@
111111
"prefix": "bc"
112112
}
113113
}
114-
}
114+
}

‎demo/app/app.module.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { BrowserModule } from '@angular/platform-browser';
33
import { RouterModule, Routes } from '@angular/router';
44
import { HttpClientModule } from '@angular/common/http';
55
import { environment } from '../environments/environment';
6-
import { NgxJsonapiModule } from 'ngx-jsonapi';
6+
import { NgxJsonapiModule, JSONAPI_RIPPER_SERVICE, JSONAPI_STORE_SERVICE } from 'ngx-jsonapi';
77

88
import { AppComponent } from './app.component';
99
import { AuthorsService } from './authors/authors.service';
1010
import { BooksService } from './books/books.service';
1111
import { PhotosService } from './photos/photos.service';
1212
import { SharedModule } from './shared/shared.module';
1313

14+
import { StoreService } from 'ngx-jsonapi/sources/store.service';
15+
import { JsonRipper } from 'ngx-jsonapi/services/json-ripper';
16+
1417
const appRoutes: Routes = [
1518
{
1619
path: '',
@@ -28,7 +31,19 @@ const appRoutes: Routes = [
2831
];
2932

3033
@NgModule({
31-
providers: [AuthorsService, BooksService, PhotosService],
34+
providers: [
35+
{
36+
provide: JSONAPI_RIPPER_SERVICE,
37+
useClass: JsonRipper
38+
},
39+
{
40+
provide: JSONAPI_STORE_SERVICE,
41+
useClass: StoreService
42+
},
43+
AuthorsService,
44+
BooksService,
45+
PhotosService
46+
],
3247
imports: [
3348
BrowserModule,
3449
HttpClientModule,

‎demo/tsconfig.app.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"baseUrl": ".",
1717
"rootDir": "../",
1818
"paths": {
19-
"ngx-jsonapi": [ "../src" ]
19+
"ngx-jsonapi": [ "../src" ],
20+
"ngx-jsonapi/*": [ "../src/*" ]
2021
}
2122
},
2223
"exclude": [

‎src/cloned-resource.spec.ts

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import { ReflectiveInjector } from '@angular/core';
2+
import { StoreService } from './sources/store.service';
3+
import { Core, JSONAPI_RIPPER_SERVICE, JSONAPI_STORE_SERVICE } from './core';
14
import { JsonRipper } from './services/json-ripper';
2-
import { IDataResource } from './interfaces/data-resource';
3-
import { CacheMemory } from './services/cachememory';
4-
import { Core } from './core';
5-
import { StoreService as JsonapiStore } from './sources/store.service';
65
import { Http as JsonapiHttpImported } from './sources/http.service';
76
import { HttpClient, HttpEvent, HttpHandler, HttpHeaders, HttpRequest, HttpResponse } from '@angular/common/http';
87
import { JsonapiConfig } from './jsonapi-config';
@@ -20,6 +19,16 @@ class HttpHandlerMock implements HttpHandler {
2019
}
2120
}
2221
let test_response_subject = new BehaviorSubject(new HttpResponse());
22+
let injector = ReflectiveInjector.resolveAndCreate([
23+
{
24+
provide: JSONAPI_RIPPER_SERVICE,
25+
useClass: JsonRipper
26+
},
27+
{
28+
provide: JSONAPI_STORE_SERVICE,
29+
useClass: StoreService
30+
}
31+
]);
2332

2433
describe('ClonedResource save', () => {
2534
let core: Core;
@@ -28,11 +37,7 @@ describe('ClonedResource save', () => {
2837
let books_service: BooksService;
2938

3039
beforeAll(async () => {
31-
core = new Core(
32-
new JsonapiConfig(),
33-
new JsonapiStore(),
34-
new JsonapiHttpImported(new HttpClient(new HttpHandlerMock()), new JsonapiConfig())
35-
);
40+
core = new Core(new JsonapiConfig(), new JsonapiHttpImported(new HttpClient(new HttpHandlerMock()), new JsonapiConfig()), injector);
3641
authors_service = new AuthorsService();
3742
authors_service.register();
3843

@@ -180,11 +185,7 @@ describe('CloneResource properties changes', () => {
180185
let books_service: BooksService;
181186

182187
beforeAll(async () => {
183-
core = new Core(
184-
new JsonapiConfig(),
185-
new JsonapiStore(),
186-
new JsonapiHttpImported(new HttpClient(new HttpHandlerMock()), new JsonapiConfig())
187-
);
188+
core = new Core(new JsonapiConfig(), new JsonapiHttpImported(new HttpClient(new HttpHandlerMock()), new JsonapiConfig()), injector);
188189
authors_service = new AuthorsService();
189190
authors_service.register();
190191

‎src/core.spec.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// WARNING: this test is not correctly isolated
22

3+
import { StoreService } from './sources/store.service';
4+
import { JsonRipper } from './services/json-ripper';
5+
import { ReflectiveInjector } from '@angular/core';
6+
import { Core, JSONAPI_RIPPER_SERVICE, JSONAPI_STORE_SERVICE } from './core';
37
import { HttpClient, HttpHandler, HttpRequest, HttpEvent, HttpResponse } from '@angular/common/http';
48
import { DocumentCollection } from './document-collection';
59
import { DocumentResource } from './document-resource';
@@ -8,7 +12,6 @@ import { Service } from './service';
812
import { Http as JsonapiHttpImported } from './sources/http.service';
913
import { JsonapiConfig } from './jsonapi-config';
1014
import { StoreService as JsonapiStore } from './sources/store.service';
11-
import { Core } from './core';
1215
import { Observable, BehaviorSubject } from 'rxjs';
1316

1417
class HttpHandlerMock implements HttpHandler {
@@ -39,15 +42,22 @@ class CustomResourceService extends Service<CustomResource> {
3942
}
4043
}
4144

45+
let injector = ReflectiveInjector.resolveAndCreate([
46+
{
47+
provide: JSONAPI_RIPPER_SERVICE,
48+
useClass: JsonRipper
49+
},
50+
{
51+
provide: JSONAPI_STORE_SERVICE,
52+
useClass: StoreService
53+
}
54+
]);
55+
4256
describe('core methods', () => {
4357
let core: Core;
4458
it('should crete core service instance', () => {
4559
spyOn<any>(JsonapiStore.prototype, 'constructor');
46-
core = new Core(
47-
new JsonapiConfig(),
48-
new JsonapiStore(),
49-
new JsonapiHttpImported(new HttpClient(new HttpHandlerMock()), new JsonapiConfig())
50-
);
60+
core = new Core(new JsonapiConfig(), new JsonapiHttpImported(new HttpClient(new HttpHandlerMock()), new JsonapiConfig()), injector);
5161
expect(core).toBeTruthy();
5262
});
5363
it('when exec method s response is an error, it should return a correctly formatted jsonapi error', () => {

‎src/core.ts

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
import { JsonRipper } from './services/json-ripper';
1+
import { IStoreService } from './sources/store-service.interface';
2+
import { IRipper } from './services/json-ripper.interface';
3+
import { Injector, Injectable, Optional, isDevMode } from '@angular/core';
24
import { CacheMemory } from './services/cachememory';
3-
import { Injectable, Optional, isDevMode } from '@angular/core';
45
import { serviceIsRegistered } from './common';
56
import { PathBuilder } from './services/path-builder';
67
import { Service } from './service';
78
import { Resource } from './resource';
89
import { JsonapiConfig } from './jsonapi-config';
910
import { Http as JsonapiHttpImported } from './sources/http.service';
10-
import { StoreService as JsonapiStore } from './sources/store.service';
1111
import { IDocumentResource } from './interfaces/data-object';
12-
import { noop } from 'rxjs/internal/util/noop';
13-
import { Observable, throwError } from 'rxjs';
12+
import { Observable, throwError, noop } from 'rxjs';
1413
import { tap, catchError } from 'rxjs/operators';
1514
import { IDocumentData } from './interfaces/document';
1615

16+
export const JSONAPI_RIPPER_SERVICE = 'jsonapi_ripper_service';
17+
export const JSONAPI_STORE_SERVICE = 'jsonapi_store_service';
18+
1719
@Injectable()
1820
export class Core {
1921
public static me: Core;
2022
public static injectedServices: {
21-
JsonapiStoreService: JsonapiStore;
23+
JsonapiStoreService: IStoreService;
2224
JsonapiHttp: JsonapiHttpImported;
25+
json_ripper: IRipper;
2326
rsJsonapiConfig: JsonapiConfig;
2427
};
2528
public loadingsCounter: number = 0;
@@ -31,16 +34,17 @@ export class Core {
3134

3235
private resourceServices: { [type: string]: Service } = {};
3336

34-
public constructor(@Optional() user_config: JsonapiConfig, jsonapiStoreService: JsonapiStore, jsonapiHttp: JsonapiHttpImported) {
37+
public constructor(@Optional() user_config: JsonapiConfig, jsonapiHttp: JsonapiHttpImported, injector: Injector) {
3538
this.config = new JsonapiConfig();
3639
for (let k in this.config) {
3740
(<any>this.config)[k] = user_config[k] !== undefined ? user_config[k] : (<any>this.config)[k];
3841
}
3942

4043
Core.me = this;
4144
Core.injectedServices = {
42-
JsonapiStoreService: jsonapiStoreService,
45+
JsonapiStoreService: injector.get<IStoreService>(<any>JSONAPI_STORE_SERVICE),
4346
JsonapiHttp: jsonapiHttp,
47+
json_ripper: injector.get<IRipper>(<any>JSONAPI_RIPPER_SERVICE),
4448
rsJsonapiConfig: this.config
4549
};
4650
}
@@ -110,17 +114,13 @@ export class Core {
110114
@serviceIsRegistered
111115
public static removeCachedResource(resource_type: string, resource_id: string): void {
112116
CacheMemory.getInstance().removeResource(resource_type, resource_id);
113-
if (Core.injectedServices.rsJsonapiConfig.cachestore_support) {
114-
// TODO: FE-85 ---> add method on JsonRipper
115-
}
117+
// TODO: FE-85 ---> add method on JsonRipper, if store is enabled
116118
}
117119

118120
@serviceIsRegistered
119121
public static setCachedResource(resource: Resource): void {
120122
CacheMemory.getInstance().setResource(resource, true);
121-
if (Core.injectedServices.rsJsonapiConfig.cachestore_support) {
122-
// TODO: FE-85 ---> add method on JsonRipper
123-
}
123+
// TODO: FE-85 ---> add method on JsonRipper, if store is enabled
124124
}
125125

126126
@serviceIsRegistered
@@ -129,9 +129,7 @@ export class Core {
129129
let path = new PathBuilder();
130130
path.applyParams(service);
131131
CacheMemory.getInstance().deprecateCollections(path.getForCache());
132-
if (Core.injectedServices.rsJsonapiConfig.cachestore_support) {
133-
// TODO: FE-85 ---> add method on JsonRipper
134-
}
132+
// TODO: FE-85 ---> add method on JsonRipper, if store is enabled
135133
}
136134

137135
public refreshLoadings(factor: number): void {
@@ -146,9 +144,8 @@ export class Core {
146144
public async clearCache(): Promise<boolean> {
147145
Core.injectedServices.JsonapiStoreService.clearCache();
148146
CacheMemory.getInstance().clearCache();
149-
let json_ripper = new JsonRipper();
150147

151-
return json_ripper.deprecateCollection('').then(() => true);
148+
return Core.injectedServices.json_ripper.deprecateCollection('').then(() => true);
152149
}
153150

154151
// just an helper

‎src/document-resource.spec.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { JsonRipper } from './services/json-ripper';
2+
import { ReflectiveInjector } from '@angular/core';
3+
import { StoreService } from './sources/store.service';
4+
import { Core, JSONAPI_RIPPER_SERVICE, JSONAPI_STORE_SERVICE } from './core';
15
import { DocumentResource } from './document-resource';
26
import { Resource } from './resource';
37
import { Page } from './services/page';
4-
import { Core } from './core';
58
import { StoreService as JsonapiStore } from './sources/store.service';
69
import { Http as JsonapiHttpImported } from './sources/http.service';
710
import { HttpClient, HttpEvent, HttpHandler, HttpRequest, HttpResponse } from '@angular/common/http';
@@ -19,15 +22,22 @@ class HttpHandlerMock implements HttpHandler {
1922
}
2023
}
2124

25+
let injector = ReflectiveInjector.resolveAndCreate([
26+
{
27+
provide: JSONAPI_RIPPER_SERVICE,
28+
useClass: JsonRipper
29+
},
30+
{
31+
provide: JSONAPI_STORE_SERVICE,
32+
useClass: StoreService
33+
}
34+
]);
35+
2236
describe('resource basic methods', () => {
2337
let core: Core;
2438
let service: AuthorsService;
2539
beforeAll(async () => {
26-
core = new Core(
27-
new JsonapiConfig(),
28-
new JsonapiStore(),
29-
new JsonapiHttpImported(new HttpClient(new HttpHandlerMock()), new JsonapiConfig())
30-
);
40+
core = new Core(new JsonapiConfig(), new JsonapiHttpImported(new HttpClient(new HttpHandlerMock()), new JsonapiConfig()), injector);
3141
service = new AuthorsService();
3242
});
3343

‎src/jsonapi-config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export class JsonapiConfig {
33
public params_separator? = '?';
44
public unify_concurrency? = true;
55
public cache_prerequests? = true;
6-
public cachestore_support? = true;
76
public parameters? = {
87
page: {
98
number: 'page[number]',

0 commit comments

Comments
 (0)