Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce scopes #35

Merged
merged 4 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Import the `CrudModule` and `HttpClientModule` inside your `AppModule`:
```typescript
import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { CrudModule } from 'ngx-crud';
import { CrudModule } from 'ngx-crud/core';

@NgModule(
{
Expand All @@ -51,7 +51,7 @@ Extend the `ExampleService` from the `CrudService`:

```typescript
import { Injectable } from '@angular/core';
import { CrudService } from 'ngx-crud';
import { CrudService } from 'ngx-crud/core';
import { ExampleInterface } from './example.interface';

import { environment } from '@env';
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ngx-crud",
"description": "CRUD services in Angular with effortless aborting, batching and caching",
"version": "8.0.0-next.2",
"version": "8.0.0-next.3",
"license": "MIT",
"keywords":
[
Expand Down Expand Up @@ -62,7 +62,7 @@
"lint": "eslint src/**/*.ts tests/**/*.ts",
"fix": "eslint src/**/*.ts tests/**/*.ts --fix",
"test": "mocha",
"build": "ng-packagr --project package.json",
"build": "ng-packagr --project=package.json",
"prepublishOnly": "exit 1"
},
"ngPackage":
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/abort.interface.ts → src/abort/abort.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Subject } from 'rxjs';
import { UniversalMethodType } from './common.type';
import { UniversalMethodType } from '../common/common.type';

export interface StoreInterface
{
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/abort/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { AbortInterceptor } from './abort.interceptor';
export { AbortService } from './abort.service';
File renamed without changes.
2 changes: 1 addition & 1 deletion src/cache.interface.ts → src/cache/cache.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { UniversalMethodType } from './common.type';
import { UniversalMethodType } from '../common/common.type';

export interface StoreInterface
{
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/cache/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { CacheInterceptor } from './cache.interceptor';
export { CacheService } from './cache.service';
File renamed without changes.
8 changes: 4 additions & 4 deletions src/common.service.ts → src/common/common.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { HttpClient, HttpContext, HttpContextToken, HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable, Injector } from '@angular/core';
import { AbortService } from './abort.service';
import { CacheService } from './cache.service';
import { ObserveService } from './observe.service';
import { AbortService } from '../abort/abort.service';
import { CacheService } from '../cache/cache.service';
import { ObserveService } from '../observe/observe.service';
import { ContextInterface, OptionInterface } from './common.interface';
import { UniversalMethodType } from './common.type';
import { createUrl } from './helper';
import { createUrl } from '../core/helper';

@Injectable()
export class CommonService
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { BodyInterface, OptionInterface, OptionWithBodyInterface } from './common.interface';
export { CommonService } from './common.service';
export { IdType, MethodType, UniversalMethodType } from './common.type';
4 changes: 2 additions & 2 deletions src/crud.interface.ts → src/core/crud.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable, ObservableInput } from 'rxjs';
import { BodyInterface, OptionInterface, OptionWithBodyInterface } from './common.interface';
import { IdType, MethodType } from './common.type';
import { BodyInterface, OptionInterface, OptionWithBodyInterface } from '../common/common.interface';
import { IdType, MethodType } from '../common/common.type';

export interface CrudInterface<T>
{
Expand Down
16 changes: 8 additions & 8 deletions src/crud.module.ts → src/core/crud.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { AbortInterceptor } from './abort.interceptor';
import { AbortService } from './abort.service';
import { BatchService } from './batch.service';
import { CacheInterceptor } from './cache.interceptor';
import { CacheService } from './cache.service';
import { AbortInterceptor } from '../abort/abort.interceptor';
import { AbortService } from '../abort/abort.service';
import { CacheInterceptor } from '../cache/cache.interceptor';
import { CacheService } from '../cache/cache.service';
import { DeleteService } from './delete.service';
import { FindService } from './find.service';
import { GetService } from './get.service';
import { ObserveInterceptor } from './observe.interceptor';
import { ObserveService } from './observe.service';
import { ObserveInterceptor } from '../observe/observe.interceptor';
import { ObserveService } from '../observe/observe.service';
import { ParallelService } from './parallel.service';
import { PatchService } from './patch.service';
import { PostService } from './post.service';
import { PutService } from './put.service';
Expand All @@ -35,12 +35,12 @@ import { RequestService } from './request.service';
useClass: ObserveInterceptor
},
AbortService,
BatchService,
CacheService,
DeleteService,
FindService,
GetService,
ObserveService,
ParallelService,
PatchService,
PostService,
PutService,
Expand Down
14 changes: 7 additions & 7 deletions src/crud.service.ts → src/core/crud.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable, Injector } from '@angular/core';
import { Observable, ObservableInput } from 'rxjs';
import { BodyInterface, OptionInterface, OptionWithBodyInterface } from './common.interface';
import { CommonService } from './common.service';
import { IdType, MethodType } from './common.type';
import { BatchService } from './batch.service';
import { BodyInterface, OptionInterface, OptionWithBodyInterface } from '../common/common.interface';
import { CommonService } from '../common/common.service';
import { IdType, MethodType } from '../common/common.type';
import { DeleteService } from './delete.service';
import { FindService } from './find.service';
import { GetService } from './get.service';
import { ParallelService } from './parallel.service';
import { PatchService } from './patch.service';
import { PostService } from './post.service';
import { PutService } from './put.service';
Expand All @@ -16,10 +16,10 @@ import { CrudInterface } from './crud.interface';
@Injectable()
export class CrudService<T> extends CommonService implements CrudInterface<T>
{
protected batchService : BatchService<T>;
protected deleteService : DeleteService<T>;
protected findService : FindService<T>;
protected getService : GetService<T>;
protected parallelService : ParallelService<T>;
protected patchService : PatchService<T>;
protected postService : PostService<T>;
protected putService : PutService<T>;
Expand All @@ -28,10 +28,10 @@ export class CrudService<T> extends CommonService implements CrudInterface<T>
constructor(protected injector : Injector)
{
super(injector);
this.batchService = injector.get<BatchService<T>>(BatchService);
this.deleteService = injector.get<DeleteService<T>>(DeleteService);
this.findService = injector.get<FindService<T>>(FindService);
this.getService = injector.get<GetService<T>>(GetService);
this.parallelService = injector.get<ParallelService<T>>(ParallelService);
this.patchService = injector.get<PatchService<T>>(PatchService);
this.postService = injector.get<PostService<T>>(PostService);
this.putService = injector.get<PutService<T>>(PutService);
Expand Down Expand Up @@ -163,6 +163,6 @@ export class CrudService<T> extends CommonService implements CrudInterface<T>

public parallel<$ = T>(requestArray : ObservableInput<$>[]) : Observable<$[]>
{
return this.batchService.parallel<$>(requestArray);
return this.parallelService.parallel<$>(requestArray);
}
}
File renamed without changes.
6 changes: 3 additions & 3 deletions src/delete.service.ts → src/core/delete.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { OptionInterface } from './common.interface';
import { CommonService } from './common.service';
import { IdType } from './common.type';
import { OptionInterface } from '../common/common.interface';
import { CommonService } from '../common/common.service';
import { IdType } from '../common/common.type';
import { createUrlWithId } from './helper';

@Injectable()
Expand Down
4 changes: 2 additions & 2 deletions src/find.service.ts → src/core/find.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { OptionInterface } from './common.interface';
import { CommonService } from './common.service';
import { OptionInterface } from '../common/common.interface';
import { CommonService } from '../common/common.service';
import { createUrl } from './helper';

@Injectable()
Expand Down
6 changes: 3 additions & 3 deletions src/get.service.ts → src/core/get.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { OptionInterface } from './common.interface';
import { CommonService } from './common.service';
import { IdType } from './common.type';
import { OptionInterface } from '../common/common.interface';
import { CommonService } from '../common/common.service';
import { IdType } from '../common/common.type';
import { createUrlWithId } from './helper';

@Injectable()
Expand Down
2 changes: 1 addition & 1 deletion src/helper.ts → src/core/helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IdType } from './common.type';
import { IdType } from '../common/common.type';

/**
* create the url
Expand Down
14 changes: 14 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export { CrudModule } from './crud.module';
export { CrudInterface } from './crud.interface';
export { CrudService } from './crud.service';
export { DeleteService } from './delete.service';
export { FindService } from './find.service';
export { GetService } from './get.service';
export { PatchService } from './patch.service';
export { PostService } from './post.service';
export { ParallelService } from './parallel.service';
export { PutService } from './put.service';
export { RequestService } from './request.service';

export { ApiUrl, Endpoint } from './decorator';
export { createUrl, createUrlWithId } from './helper';
4 changes: 2 additions & 2 deletions src/batch.service.ts → src/core/parallel.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable } from '@angular/core';
import { forkJoin, Observable, ObservableInput } from 'rxjs';
import { CommonService } from './common.service';
import { CommonService } from '../common/common.service';

@Injectable()
export class BatchService<T> extends CommonService
export class ParallelService<T> extends CommonService
{
/**
* fires multiple requests in parallel
Expand Down
6 changes: 3 additions & 3 deletions src/patch.service.ts → src/core/patch.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { BodyInterface, OptionInterface } from './common.interface';
import { CommonService } from './common.service';
import { IdType } from './common.type';
import { BodyInterface, OptionInterface } from '../common/common.interface';
import { CommonService } from '../common/common.service';
import { IdType } from '../common/common.type';
import { createUrlWithId } from './helper';

@Injectable()
Expand Down
4 changes: 2 additions & 2 deletions src/post.service.ts → src/core/post.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { BodyInterface, OptionInterface } from './common.interface';
import { CommonService } from './common.service';
import { BodyInterface, OptionInterface } from '../common/common.interface';
import { CommonService } from '../common/common.service';
import { createUrl } from './helper';

@Injectable()
Expand Down
6 changes: 3 additions & 3 deletions src/put.service.ts → src/core/put.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { BodyInterface, OptionInterface } from './common.interface';
import { CommonService } from './common.service';
import { IdType } from './common.type';
import { BodyInterface, OptionInterface } from '../common/common.interface';
import { CommonService } from '../common/common.service';
import { IdType } from '../common/common.type';
import { createUrlWithId } from './helper';

@Injectable()
Expand Down
6 changes: 3 additions & 3 deletions src/request.service.ts → src/core/request.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { OptionWithBodyInterface } from './common.interface';
import { CommonService } from './common.service';
import { MethodType } from './common.type';
import { OptionWithBodyInterface } from '../common/common.interface';
import { CommonService } from '../common/common.service';
import { MethodType } from '../common/common.type';
import { createUrl } from './helper';

@Injectable()
Expand Down
29 changes: 4 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
export { AbortInterceptor } from './abort.interceptor';
export { AbortService } from './abort.service';
export { BatchService } from './batch.service';
export { CacheInterceptor } from './cache.interceptor';
export { CacheService } from './cache.service';
export { BodyInterface, OptionInterface, OptionWithBodyInterface } from './common.interface';
export { CommonService } from './common.service';
export { IdType, MethodType, UniversalMethodType } from './common.type';
export { CrudModule } from './crud.module';
export { CrudInterface } from './crud.interface';
export { CrudService } from './crud.service';
export { DeleteService } from './delete.service';
export { FindService } from './find.service';
export { GetService } from './get.service';
export { ObserveInterceptor } from './observe.interceptor';
export { ObserveService } from './observe.service';
export { EffectInterface } from './observe.interface';
export { EFFECT_SERVICE } from './observe.token';
export { StateType } from './observe.type';
export { PatchService } from './patch.service';
export { PostService } from './post.service';
export { PutService } from './put.service';
export { RequestService } from './request.service';
export { ApiUrl, Endpoint } from './decorator';
export { createUrl, createUrlWithId } from './helper';
import './abort';
import './cache';
import './core';
import './observe';
3 changes: 0 additions & 3 deletions src/observe.token.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/observe/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { ObserveInterceptor } from './observe.interceptor';
export { EffectInterface } from './observe.interface';
export { ObserveService } from './observe.service';
export { EFFECT_SERVICE } from './observe.token';
export { StateType } from './observe.type';
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class ObserveInterceptor implements HttpInterceptor
return next
.handle(request)
.pipe(
tap((event : HttpEvent<T>) => this.observeService.effect<T>(event)),
tap((event : HttpEvent<T>) => this.observeService.effect(event)),
finalize(() => this.observeService.end(request))
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpEvent } from '@angular/common/http';
import { UniversalMethodType } from './common.type';
import { UniversalMethodType } from '../common/common.type';

export interface ContextInterface
{
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions src/observe/observe.token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { InjectionToken } from '@angular/core';
import { EffectInterface } from './observe.interface';

export const EFFECT_SERVICE : InjectionToken<EffectInterface> = new InjectionToken<EffectInterface>('NGX_CRUD__OBSERVE__EFFECT_SERVICE');
File renamed without changes.
5 changes: 3 additions & 2 deletions tests/abort.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { expect } from 'chai';
import { AbortService, CrudModule } from '../src';
import { mockRequest } from './helper';
import { CrudModule } from '../src/core';
import { AbortService } from '../src/abort';
import { TestService } from './test.service';
import { mockRequest } from './helper';

before(() =>
{
Expand Down
5 changes: 3 additions & 2 deletions tests/cache.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { expect } from 'chai';
import { delay } from 'rxjs/operators';
import { CacheService, CrudModule } from '../src';
import { mockRequest } from './helper';
import { CrudModule } from '../src/core';
import { CacheService } from '../src/cache';
import { TestService } from './test.service';
import { mockRequest } from './helper';

before(() =>
{
Expand Down
3 changes: 2 additions & 1 deletion tests/common.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { expect } from 'chai';
import { CommonService, CrudModule } from '../src';
import { CommonService } from '../src/common';
import { CrudModule } from '../src/core';
import { TestService } from './test.service';

before(() =>
Expand Down
3 changes: 1 addition & 2 deletions tests/crud.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpClientModule } from '@angular/common/http';
import { inject, TestBed } from '@angular/core/testing';
import { expect } from 'chai';
import { CommonService, CrudModule } from '../src';
import { CrudModule } from '../src/core';
import { TestService } from './test.service';

before(() =>
Expand All @@ -16,7 +16,6 @@ before(() =>
],
providers:
[
CommonService,
TestService
]
});
Expand Down
Loading