first version using ng library without deps on ng core.
This commit is contained in:
parent
a4feb24311
commit
f13052a041
35
angular.json
35
angular.json
@ -120,6 +120,41 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@poweredsoft/data": {
|
||||
"projectType": "library",
|
||||
"root": "projects/poweredsoft/data",
|
||||
"sourceRoot": "projects/poweredsoft/data/src",
|
||||
"prefix": "lib",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-ng-packagr:build",
|
||||
"options": {
|
||||
"tsConfig": "projects/poweredsoft/data/tsconfig.lib.json",
|
||||
"project": "projects/poweredsoft/data/ng-package.json"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular-devkit/build-angular:karma",
|
||||
"options": {
|
||||
"main": "projects/poweredsoft/data/src/test.ts",
|
||||
"tsConfig": "projects/poweredsoft/data/tsconfig.spec.json",
|
||||
"karmaConfig": "projects/poweredsoft/data/karma.conf.js"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": [
|
||||
"projects/poweredsoft/data/tsconfig.lib.json",
|
||||
"projects/poweredsoft/data/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}},
|
||||
"defaultProject": "data"
|
||||
}
|
1142
package-lock.json
generated
1142
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -19,12 +19,13 @@
|
||||
"@angular/platform-browser": "~8.2.4",
|
||||
"@angular/platform-browser-dynamic": "~8.2.4",
|
||||
"@angular/router": "~8.2.4",
|
||||
"rxjs": "~6.4.0",
|
||||
"rxjs": "~6.5.3",
|
||||
"tslib": "^1.10.0",
|
||||
"zone.js": "~0.9.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "~0.803.3",
|
||||
"@angular-devkit/build-ng-packagr": "~0.803.3",
|
||||
"@angular/cli": "~8.3.3",
|
||||
"@angular/compiler-cli": "~8.2.4",
|
||||
"@angular/language-service": "~8.2.4",
|
||||
@ -39,8 +40,10 @@
|
||||
"karma-coverage-istanbul-reporter": "~2.0.1",
|
||||
"karma-jasmine": "~2.0.1",
|
||||
"karma-jasmine-html-reporter": "^1.4.0",
|
||||
"ng-packagr": "^5.4.0",
|
||||
"protractor": "~5.4.0",
|
||||
"ts-node": "~7.0.0",
|
||||
"tsickle": "^0.37.0",
|
||||
"tslint": "~5.15.0",
|
||||
"typescript": "~3.5.3"
|
||||
}
|
||||
|
24
projects/poweredsoft/data/README.md
Normal file
24
projects/poweredsoft/data/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Data
|
||||
|
||||
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.2.4.
|
||||
|
||||
## Code scaffolding
|
||||
|
||||
Run `ng generate component component-name --project data` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project data`.
|
||||
> Note: Don't forget to add `--project data` or else it will be added to the default project in your `angular.json` file.
|
||||
|
||||
## Build
|
||||
|
||||
Run `ng build data` to build the project. The build artifacts will be stored in the `dist/` directory.
|
||||
|
||||
## Publishing
|
||||
|
||||
After building your library with `ng build data`, go to the dist folder `cd dist/data` and run `npm publish`.
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `ng test data` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
||||
|
||||
## Further help
|
||||
|
||||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
|
32
projects/poweredsoft/data/karma.conf.js
Normal file
32
projects/poweredsoft/data/karma.conf.js
Normal file
@ -0,0 +1,32 @@
|
||||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
basePath: '',
|
||||
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||
plugins: [
|
||||
require('karma-jasmine'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-jasmine-html-reporter'),
|
||||
require('karma-coverage-istanbul-reporter'),
|
||||
require('@angular-devkit/build-angular/plugins/karma')
|
||||
],
|
||||
client: {
|
||||
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||
},
|
||||
coverageIstanbulReporter: {
|
||||
dir: require('path').join(__dirname, '../../../coverage/poweredsoft/data'),
|
||||
reports: ['html', 'lcovonly', 'text-summary'],
|
||||
fixWebpackSourcePaths: true
|
||||
},
|
||||
reporters: ['progress', 'kjhtml'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: config.LOG_INFO,
|
||||
autoWatch: true,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: false,
|
||||
restartOnFileChange: true
|
||||
});
|
||||
};
|
7
projects/poweredsoft/data/ng-package.json
Normal file
7
projects/poweredsoft/data/ng-package.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
|
||||
"dest": "../../../dist/poweredsoft/data",
|
||||
"lib": {
|
||||
"entryFile": "src/public-api.ts"
|
||||
}
|
||||
}
|
7
projects/poweredsoft/data/package.json
Normal file
7
projects/poweredsoft/data/package.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "@poweredsoft/data",
|
||||
"version": "0.0.13",
|
||||
"peerDependencies": {
|
||||
"rxjs": "^6.5.3"
|
||||
}
|
||||
}
|
110
projects/poweredsoft/data/src/lib/DataSource.ts
Normal file
110
projects/poweredsoft/data/src/lib/DataSource.ts
Normal file
@ -0,0 +1,110 @@
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { IDataSource } from './IDataSource';
|
||||
import { IQueryExecutionResult, IQueryExecutionGroupResult, IFilter, ISort, IAggregate, IGroup, IQueryCriteria } from './models';
|
||||
import { IDataSourceOptions } from './IDataSourceOptions';
|
||||
import { IResolveCommandModelEvent } from './IResolveCommandModelEvent';
|
||||
|
||||
export class DataSource<TModel> implements IDataSource<TModel>
|
||||
{
|
||||
data: IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel> = null;
|
||||
|
||||
protected _page: number = 0;
|
||||
protected _pageSize: number = 0;
|
||||
protected _filters: IFilter[] = [];
|
||||
protected _sorts: ISort[] = [];
|
||||
protected _aggregates: IAggregate[] = [];
|
||||
protected _groups: IGroup[] = [];
|
||||
|
||||
constructor(public options: IDataSourceOptions<TModel>) {
|
||||
|
||||
}
|
||||
|
||||
resolveCommandModelByName<T extends any>(event: IResolveCommandModelEvent<TModel>) : Observable<T> {
|
||||
|
||||
if (!this.options.transport.commands.hasOwnProperty(name))
|
||||
return Observable.throw(`command with name ${name} not found`);
|
||||
|
||||
const commandOptions = this.options.transport.commands[name];
|
||||
if (commandOptions.resolveCommandModel)
|
||||
return commandOptions.resolveCommandModel(event);
|
||||
|
||||
return of<T>(event.model as any as T);
|
||||
}
|
||||
|
||||
executeCommandByName<TCommand, TResult>(name: string, command: TCommand) : Observable<TResult> {
|
||||
|
||||
if (!this.options.transport.commands.hasOwnProperty(name))
|
||||
return Observable.throw(`command with name ${name} not found`);
|
||||
|
||||
return this.options.transport.commands[name].adapter.handle(command);
|
||||
}
|
||||
|
||||
query<TQuery extends IQueryCriteria>(query: TQuery) : Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>> {
|
||||
return this.options.transport.query.adapter.handle(query);
|
||||
}
|
||||
|
||||
public refresh() {
|
||||
return this.query({
|
||||
sorts: this._sorts,
|
||||
filters: this._filters,
|
||||
groups: this._groups,
|
||||
aggregates: this._aggregates,
|
||||
pageSize: this._pageSize,
|
||||
page: this._page
|
||||
});
|
||||
}
|
||||
|
||||
get sorts() {
|
||||
return this._sorts;
|
||||
}
|
||||
|
||||
set sorts(value: ISort[]) {
|
||||
this._sorts = value;
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
get filters() {
|
||||
return this._filters;
|
||||
}
|
||||
|
||||
set filters(value: IFilter[]) {
|
||||
this._filters = value;
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
get groups() {
|
||||
return this._groups;
|
||||
}
|
||||
|
||||
set groups(value: IGroup[]) {
|
||||
this._groups = value;
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
get aggregates() {
|
||||
return this._aggregates;
|
||||
}
|
||||
|
||||
set aggregates(value: IAggregate[]) {
|
||||
this._aggregates = value;
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
get pageSize() {
|
||||
return this._pageSize;
|
||||
}
|
||||
|
||||
set pageSize(value: number) {
|
||||
this._pageSize = value;
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
get page() {
|
||||
return this._page;
|
||||
}
|
||||
|
||||
set page(value: number) {
|
||||
this._page = value;
|
||||
this.refresh();
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
import { IQueryCriteria, IQueryExecutionResult, IQueryExecutionGroupResult } from './models';
|
||||
import { IQueryAdapter } from "./IQueryAdapter";
|
||||
export interface IAdvanceQueryAdapter<TQuery extends IQueryCriteria, TResult> extends IQueryAdapter<TQuery, IQueryExecutionResult<TResult> & IQueryExecutionGroupResult<TResult>> {
|
||||
}
|
4
projects/poweredsoft/data/src/lib/ICommandAdapter.ts
Normal file
4
projects/poweredsoft/data/src/lib/ICommandAdapter.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { Observable } from 'rxjs';
|
||||
export interface ICommandAdapter<TCommand, TResult> {
|
||||
handle(command: TCommand): Observable<TResult>;
|
||||
}
|
19
projects/poweredsoft/data/src/lib/IDataSource.ts
Normal file
19
projects/poweredsoft/data/src/lib/IDataSource.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Observable } from "rxjs";
|
||||
import { ISort, IFilter, IGroup, IAggregate, IQueryExecutionResult, IQueryExecutionGroupResult, IQueryCriteria } from "./models";
|
||||
import { IResolveCommandModelEvent } from "./IResolveCommandModelEvent";
|
||||
|
||||
export interface IDataSource<TModel>
|
||||
{
|
||||
resolveCommandModelByName<T extends any>(event: IResolveCommandModelEvent<TModel>) : Observable<T>;
|
||||
executeCommandByName<TCommand, TResult>(name: string, command: TCommand) : Observable<TResult>;
|
||||
query<TQuery extends IQueryCriteria>(query: TQuery) : Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>;
|
||||
|
||||
data: IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>;
|
||||
|
||||
sorts: ISort[];
|
||||
filters: IFilter[];
|
||||
groups: IGroup[];
|
||||
aggregates: IAggregate[];
|
||||
pageSize: number;
|
||||
page: number;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
import { Observable } from "rxjs";
|
||||
import { ICommandAdapter } from "./ICommandAdapter";
|
||||
import { IResolveCommandModelEvent } from "./IResolveCommandModelEvent";
|
||||
export interface IDataSourceCommandAdapterOptions<TModel> {
|
||||
adapter: ICommandAdapter<any, any>;
|
||||
resolveCommandModel?: (event: IResolveCommandModelEvent<TModel>) => Observable<any>;
|
||||
}
|
16
projects/poweredsoft/data/src/lib/IDataSourceOptions.ts
Normal file
16
projects/poweredsoft/data/src/lib/IDataSourceOptions.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { IDataSourceQueryAdapterOptions } from "./IDataSourceQueryAdapterOptions";
|
||||
import { IDataSourceCommandAdapterOptions } from "./IDataSourceCommandAdapterOptions";
|
||||
import { IQueryCriteria } from "./models";
|
||||
|
||||
|
||||
export interface IDataSourceOptions<TModel> {
|
||||
transport: IDataSourceTransportOptions<TModel>;
|
||||
defaultCriteria: IQueryCriteria;
|
||||
}
|
||||
|
||||
export interface IDataSourceTransportOptions<TModel> {
|
||||
query: IDataSourceQueryAdapterOptions<TModel>;
|
||||
commands: {
|
||||
[name: string]: IDataSourceCommandAdapterOptions<TModel>;
|
||||
};
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
import { IAdvanceQueryAdapter } from "./IAdvanceQueryAdapter";
|
||||
|
||||
export interface IDataSourceQueryAdapterOptions<TModel> {
|
||||
adapter: IAdvanceQueryAdapter<any, TModel>;
|
||||
}
|
4
projects/poweredsoft/data/src/lib/IQueryAdapter.ts
Normal file
4
projects/poweredsoft/data/src/lib/IQueryAdapter.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { Observable } from 'rxjs';
|
||||
export interface IQueryAdapter<TQuery, TResult> {
|
||||
handle(query: TQuery): Observable<TResult>;
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
export interface IResolveCommandModelEvent<TModel> {
|
||||
command: string;
|
||||
model: TModel;
|
||||
}
|
67
projects/poweredsoft/data/src/lib/models.ts
Normal file
67
projects/poweredsoft/data/src/lib/models.ts
Normal file
@ -0,0 +1,67 @@
|
||||
export interface IAggregate {
|
||||
path: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface ISort {
|
||||
path: string;
|
||||
ascending?: boolean;
|
||||
}
|
||||
|
||||
export interface ISimpleFilter extends IFilter {
|
||||
path: string;
|
||||
value: any;
|
||||
}
|
||||
|
||||
export interface IQueryResult<TModel> {
|
||||
aggregates?: IAggregateResult[];
|
||||
data?: TModel[];
|
||||
}
|
||||
|
||||
export interface IQueryExecutionResultPaging {
|
||||
totalRecords: number;
|
||||
numberOfPages?: number;
|
||||
}
|
||||
|
||||
export interface IQueryExecutionResult<TRecord> extends IQueryResult<TRecord>, IQueryExecutionResultPaging {
|
||||
}
|
||||
|
||||
export interface IQueryExecutionGroupResult<TModel> extends IQueryExecutionResult<TModel> {
|
||||
groups: IGroupQueryResult<TModel>[];
|
||||
}
|
||||
|
||||
export interface IQueryCriteria {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
sorts?: ISort[];
|
||||
groups?: IGroup[];
|
||||
aggregates?: IAggregate[];
|
||||
filters?: IFilter[];
|
||||
}
|
||||
|
||||
export interface IGroupQueryResult<TModel> extends IQueryResult<TModel> {
|
||||
groupPath: string;
|
||||
groupValue: any;
|
||||
hasSubGroups: boolean;
|
||||
subGroups?: IGroupQueryResult<TModel>[];
|
||||
}
|
||||
|
||||
export interface IGroup {
|
||||
path: string;
|
||||
ascending?: boolean;
|
||||
}
|
||||
|
||||
export interface IFilter {
|
||||
type: string;
|
||||
and?: boolean;
|
||||
}
|
||||
|
||||
export interface IAggregateResult {
|
||||
path: string;
|
||||
type: string;
|
||||
value: any;
|
||||
}
|
||||
|
||||
export interface ICompositeFilter extends IFilter {
|
||||
filters: IFilter[];
|
||||
}
|
14
projects/poweredsoft/data/src/public-api.ts
Normal file
14
projects/poweredsoft/data/src/public-api.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Public API Surface of data
|
||||
*/
|
||||
|
||||
export * from './lib/models';
|
||||
export * from './lib/DataSource';
|
||||
export * from './lib/IAdvanceQueryAdapter';
|
||||
export * from './lib/ICommandAdapter';
|
||||
export * from './lib/IDataSource';
|
||||
export * from './lib/IDataSourceOptions';
|
||||
export * from './lib/IDataSourceQueryAdapterOptions';
|
||||
export * from './lib/IQueryAdapter';
|
||||
export * from './lib/IResolveCommandModelEvent';
|
||||
|
26
projects/poweredsoft/data/tsconfig.lib.json
Normal file
26
projects/poweredsoft/data/tsconfig.lib.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../out-tsc/lib",
|
||||
"target": "es2015",
|
||||
"declaration": true,
|
||||
"inlineSources": true,
|
||||
"types": [],
|
||||
"lib": [
|
||||
"dom",
|
||||
"es2018"
|
||||
]
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"annotateForClosureCompiler": true,
|
||||
"skipTemplateCodegen": true,
|
||||
"strictMetadataEmit": true,
|
||||
"fullTemplateTypeCheck": true,
|
||||
"strictInjectionParameters": true,
|
||||
"enableResourceInlining": true
|
||||
},
|
||||
"exclude": [
|
||||
"src/test.ts",
|
||||
"**/*.spec.ts"
|
||||
]
|
||||
}
|
17
projects/poweredsoft/data/tsconfig.spec.json
Normal file
17
projects/poweredsoft/data/tsconfig.spec.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../out-tsc/spec",
|
||||
"types": [
|
||||
"jasmine",
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"src/test.ts"
|
||||
],
|
||||
"include": [
|
||||
"**/*.spec.ts",
|
||||
"**/*.d.ts"
|
||||
]
|
||||
}
|
17
projects/poweredsoft/data/tslint.json
Normal file
17
projects/poweredsoft/data/tslint.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../../../tslint.json",
|
||||
"rules": {
|
||||
"directive-selector": [
|
||||
true,
|
||||
"attribute",
|
||||
"lib",
|
||||
"camelCase"
|
||||
],
|
||||
"component-selector": [
|
||||
true,
|
||||
"element",
|
||||
"lib",
|
||||
"kebab-case"
|
||||
]
|
||||
}
|
||||
}
|
@ -17,10 +17,18 @@
|
||||
"lib": [
|
||||
"es2018",
|
||||
"dom"
|
||||
]
|
||||
],
|
||||
"paths": {
|
||||
"@poweredsoft/data": [
|
||||
"dist/poweredsoft/data"
|
||||
],
|
||||
"@poweredsoft/data/*": [
|
||||
"dist/poweredsoft/data/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"fullTemplateTypeCheck": true,
|
||||
"strictInjectionParameters": true
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user