onecore 0.0.25 → 0.0.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -74,8 +74,11 @@ import { ViewRepository } from './repository/ViewRepository';
74
74
  import { GenericService } from './service/GenericService';
75
75
  import { ViewService } from './service/ViewService';
76
76
 
77
+ export type Search<T, F> = (s: F, limit?: number, offset?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
78
+ export type SearchFunc<T, F> = Search<T, F>;
79
+
77
80
  export class ViewManager<T, ID> implements ViewService<T, ID> {
78
- constructor(private repo: ViewRepository<T, ID>) {
81
+ constructor(private r: ViewRepository<T, ID>) {
79
82
  this.metadata = this.metadata.bind(this);
80
83
  this.keys = this.keys.bind(this);
81
84
  this.all = this.all.bind(this);
@@ -83,19 +86,19 @@ export class ViewManager<T, ID> implements ViewService<T, ID> {
83
86
  this.exist = this.exist.bind(this);
84
87
  }
85
88
  metadata(): Attributes|undefined {
86
- return (this.repo.metadata ? this.repo.metadata() : undefined);
89
+ return (this.r.metadata ? this.r.metadata() : undefined);
87
90
  }
88
91
  keys(): string[] {
89
- return (this.repo.keys ? this.repo.keys() : []);
92
+ return (this.r.keys ? this.r.keys() : []);
90
93
  }
91
94
  all(ctx?: any): Promise<T[]> {
92
- return (this.repo.all ? this.repo.all() : Promise.resolve([]));
95
+ return (this.r.all ? this.r.all() : Promise.resolve([]));
93
96
  }
94
97
  load(id: ID, ctx?: any): Promise<T | null> {
95
- return this.repo.load(id, ctx);
98
+ return this.r.load(id, ctx);
96
99
  }
97
100
  exist(id: ID, ctx?: any): Promise<boolean> {
98
- return (this.repo.exist ? this.repo.exist(id, ctx) : Promise.resolve(false));
101
+ return (this.r.exist ? this.r.exist(id, ctx) : Promise.resolve(false));
99
102
  }
100
103
  }
101
104
  export class GenericManager<T, ID> extends ViewManager<T, ID> implements GenericService<T, ID, number> {
@@ -123,12 +126,12 @@ export class GenericManager<T, ID> extends ViewManager<T, ID> implements Generic
123
126
  return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
124
127
  }
125
128
  }
126
- export class Manager<T, ID, S extends Filter> extends GenericManager<T, ID> implements GenericSearchService<T, ID, number, S> {
127
- constructor(public find: (s: S, offset?: number, skip?: number|string, fields?: string[]) => Promise<SearchResult<T>>, repo: GenericRepository<T, ID>) {
129
+ export class Manager<T, ID, F extends Filter> extends GenericManager<T, ID> implements GenericSearchService<T, ID, number, F> {
130
+ constructor(public find: Search<T, F>, repo: GenericRepository<T, ID>) {
128
131
  super(repo);
129
132
  this.search = this.search.bind(this);
130
133
  }
131
- search(s: S, limit?: number, offset?: number|string, fields?: string[]): Promise<SearchResult<T>> {
134
+ search(s: F, limit?: number, offset?: number|string, fields?: string[]): Promise<SearchResult<T>> {
132
135
  return this.find(s, limit, offset, fields);
133
136
  }
134
137
  }
@@ -2,6 +2,6 @@ import {Filter} from '../model';
2
2
  import {GenericRepository} from './GenericRepository';
3
3
  import {SearchRepository} from './SearchRepository';
4
4
 
5
- export interface GenericSearchRepository<T, ID, S extends Filter>
6
- extends GenericRepository<T, ID>, SearchRepository<T, S> {
5
+ export interface GenericSearchRepository<T, ID, F extends Filter>
6
+ extends GenericRepository<T, ID>, SearchRepository<T, F> {
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import {Filter} from '../model';
2
2
  import {SearchResult} from '../model';
3
3
 
4
- export interface SearchRepository<T, S extends Filter> {
5
- search(s: S, limit?: number, offset?: number|string, fields?: string[], ctx?: any): Promise<SearchResult<T>>;
4
+ export interface SearchRepository<T, F extends Filter> {
5
+ search(s: F, limit?: number, offset?: number|string, fields?: string[], ctx?: any): Promise<SearchResult<T>>;
6
6
  }
@@ -2,6 +2,6 @@ import {Filter} from '../model';
2
2
  import {SearchRepository} from './SearchRepository';
3
3
  import {ViewRepository} from './ViewRepository';
4
4
 
5
- export interface ViewSearchRepository<T, ID, S extends Filter>
6
- extends ViewRepository<T, ID>, SearchRepository<T, S> {
5
+ export interface ViewSearchRepository<T, ID, F extends Filter>
6
+ extends ViewRepository<T, ID>, SearchRepository<T, F> {
7
7
  }
@@ -2,6 +2,6 @@ import {Filter} from '../model';
2
2
  import {DiffApprService} from './DiffApprService';
3
3
  import {GenericSearchService} from './GenericSearchService';
4
4
 
5
- export interface GenericSearchDiffApprService<T, ID, R, S extends Filter> extends GenericSearchService<T, ID, R, S>, DiffApprService<T, ID> {
5
+ export interface GenericSearchDiffApprService<T, ID, R, F extends Filter> extends GenericSearchService<T, ID, R, F>, DiffApprService<T, ID> {
6
6
 
7
7
  }
@@ -2,6 +2,6 @@ import {Filter} from '../model';
2
2
  import {GenericService} from './GenericService';
3
3
  import {SearchService} from './SearchService';
4
4
 
5
- export interface GenericSearchService<T, ID, R, S extends Filter>
6
- extends GenericService<T, ID, R>, SearchService<T, S> {
5
+ export interface GenericSearchService<T, ID, R, F extends Filter>
6
+ extends GenericService<T, ID, R>, SearchService<T, F> {
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import {Filter} from '../model';
2
2
  import {SearchResult} from '../model';
3
3
 
4
- export interface SearchService<T, S extends Filter> {
4
+ export interface SearchService<T, F extends Filter> {
5
5
  keys?(): string[];
6
- search(s: S, limit?: number, offset?: number|string, fields?: string[], ctx?: any): Promise<SearchResult<T>>;
6
+ search(s: F, limit?: number, offset?: number|string, fields?: string[], ctx?: any): Promise<SearchResult<T>>;
7
7
  }
@@ -2,6 +2,6 @@ import {Filter} from '../model';
2
2
  import {SearchService} from './SearchService';
3
3
  import {ViewService} from './ViewService';
4
4
 
5
- export interface ViewSearchService<T, ID, S extends Filter>
6
- extends ViewService<T, ID>, SearchService<T, S> {
5
+ export interface ViewSearchService<T, ID, F extends Filter>
6
+ extends ViewService<T, ID>, SearchService<T, F> {
7
7
  }