@daffodil/search 0.0.0-PLACEHOLDER
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/.eslintrc.js +52 -0
- package/README.md +11 -0
- package/driver/federated/README.md +3 -0
- package/driver/federated/ng-package.json +8 -0
- package/driver/federated/package.json +3 -0
- package/driver/federated/src/config/default.ts +6 -0
- package/driver/federated/src/config/interface.ts +21 -0
- package/driver/federated/src/config/public_api.ts +5 -0
- package/driver/federated/src/index.ts +1 -0
- package/driver/federated/src/injection-tokens/drivers.token.spec.ts +64 -0
- package/driver/federated/src/injection-tokens/drivers.token.ts +37 -0
- package/driver/federated/src/public_api.ts +4 -0
- package/driver/federated/src/search-driver.module.ts +62 -0
- package/driver/federated/src/search.service.spec.ts +86 -0
- package/driver/federated/src/search.service.ts +49 -0
- package/driver/in-memory/ng-package.json +8 -0
- package/driver/in-memory/package.json +3 -0
- package/driver/in-memory/src/backend/search.service.spec.ts +111 -0
- package/driver/in-memory/src/backend/search.service.ts +83 -0
- package/driver/in-memory/src/driver/search-driver.module.ts +33 -0
- package/driver/in-memory/src/driver/search.service.spec.ts +75 -0
- package/driver/in-memory/src/driver/search.service.ts +33 -0
- package/driver/in-memory/src/index.ts +1 -0
- package/driver/in-memory/src/injection-tokens/backends.token.spec.ts +69 -0
- package/driver/in-memory/src/injection-tokens/backends.token.ts +36 -0
- package/driver/in-memory/src/interfaces/get-backend.interface.ts +17 -0
- package/driver/in-memory/src/interfaces/public_api.ts +1 -0
- package/driver/in-memory/src/public_api.ts +7 -0
- package/driver/ng-package.json +8 -0
- package/driver/package.json +3 -0
- package/driver/src/errors/invalid-api-response.ts +17 -0
- package/driver/src/errors/map.ts +16 -0
- package/driver/src/errors/public_api.ts +9 -0
- package/driver/src/errors/query-too-short.ts +17 -0
- package/driver/src/index.ts +1 -0
- package/driver/src/interfaces/response.interface.ts +18 -0
- package/driver/src/interfaces/search-service-kinded.interface.ts +17 -0
- package/driver/src/interfaces/search-service.interface.ts +42 -0
- package/driver/src/public_api.ts +9 -0
- package/driver/testing/ng-package.json +8 -0
- package/driver/testing/package.json +3 -0
- package/driver/testing/src/drivers/public_api.ts +2 -0
- package/driver/testing/src/drivers/search-driver.module.ts +31 -0
- package/driver/testing/src/drivers/search.service.spec.ts +29 -0
- package/driver/testing/src/drivers/search.service.ts +37 -0
- package/driver/testing/src/index.ts +1 -0
- package/driver/testing/src/public_api.ts +1 -0
- package/karma.conf.js +11 -0
- package/ng-package.json +7 -0
- package/ng-package.prod.json +7 -0
- package/package.json +40 -0
- package/routing/ng-package.json +8 -0
- package/routing/package.json +3 -0
- package/routing/src/index.ts +1 -0
- package/routing/src/injection-tokens/public_api.ts +6 -0
- package/routing/src/injection-tokens/search-options/builder.token.ts +10 -0
- package/routing/src/injection-tokens/search-options/builders.token.spec.ts +35 -0
- package/routing/src/injection-tokens/search-options/builders.token.ts +42 -0
- package/routing/src/module.ts +26 -0
- package/routing/src/public_api.ts +3 -0
- package/routing/src/resolvers/public_api.ts +1 -0
- package/routing/src/resolvers/search/search.resolver.spec.ts +166 -0
- package/routing/src/resolvers/search/search.resolver.ts +65 -0
- package/src/index.ts +1 -0
- package/src/injection-tokens/error-matcher.token.ts +12 -0
- package/src/injection-tokens/public_api.ts +1 -0
- package/src/models/public_api.ts +2 -0
- package/src/models/search-result-collection.type.ts +6 -0
- package/src/models/search-result.type.ts +10 -0
- package/src/public_api.ts +3 -0
- package/src/transforms/public_api.ts +1 -0
- package/src/transforms/results-to-collection.spec.ts +28 -0
- package/src/transforms/results-to-collection.ts +14 -0
- package/state/ng-package.json +8 -0
- package/state/package.json +3 -0
- package/state/src/actions/search.actions.ts +93 -0
- package/state/src/config/default.ts +10 -0
- package/state/src/config/interface.ts +20 -0
- package/state/src/config/public_api.ts +3 -0
- package/state/src/config/token.ts +11 -0
- package/state/src/effects/incremental.effects.spec.ts +205 -0
- package/state/src/effects/incremental.effects.ts +74 -0
- package/state/src/effects/page.effects.spec.ts +179 -0
- package/state/src/effects/page.effects.ts +57 -0
- package/state/src/facades/public_api.ts +4 -0
- package/state/src/facades/search/base.facade.spec.ts +148 -0
- package/state/src/facades/search/base.facade.ts +53 -0
- package/state/src/facades/search/incremental.facade.ts +25 -0
- package/state/src/facades/search/page.facade.ts +25 -0
- package/state/src/facades/search/search-facade.interface.ts +38 -0
- package/state/src/incremental.module.ts +35 -0
- package/state/src/index.ts +1 -0
- package/state/src/page.module.ts +15 -0
- package/state/src/public_api.ts +9 -0
- package/state/src/reducers/incremental/public_api.ts +1 -0
- package/state/src/reducers/incremental/reducer.spec.ts +142 -0
- package/state/src/reducers/incremental/reducer.ts +34 -0
- package/state/src/reducers/page/public_api.ts +1 -0
- package/state/src/reducers/page/reducer.spec.ts +142 -0
- package/state/src/reducers/page/reducer.ts +34 -0
- package/state/src/reducers/public_api.ts +11 -0
- package/state/src/reducers/reducers.interface.ts +19 -0
- package/state/src/reducers/reducers.spec.ts +16 -0
- package/state/src/reducers/reducers.ts +13 -0
- package/state/src/reducers/search/adapter.spec.ts +130 -0
- package/state/src/reducers/search/adapter.ts +71 -0
- package/state/src/reducers/search/initial-state.ts +11 -0
- package/state/src/reducers/search/interface.ts +26 -0
- package/state/src/reducers/search/public_api.ts +3 -0
- package/state/src/reducers/store-feature-key.ts +4 -0
- package/state/src/reducers/token/extra.token.spec.ts +35 -0
- package/state/src/reducers/token/extra.token.ts +44 -0
- package/state/src/reducers/token/public_api.ts +4 -0
- package/state/src/reducers/token/reducers.token.spec.ts +51 -0
- package/state/src/reducers/token/reducers.token.ts +33 -0
- package/state/src/search.module.ts +15 -0
- package/state/src/selectors/incremental/selectors.ts +21 -0
- package/state/src/selectors/page/selectors.ts +21 -0
- package/state/src/selectors/public_api.ts +4 -0
- package/state/src/selectors/search-feature.selector.ts +27 -0
- package/state/src/selectors/search.selector.spec.ts +137 -0
- package/state/src/selectors/search.selector.ts +78 -0
- package/state/testing/ng-package.json +8 -0
- package/state/testing/package.json +3 -0
- package/state/testing/src/index.ts +1 -0
- package/state/testing/src/mock-search-facade.ts +24 -0
- package/state/testing/src/public_api.ts +2 -0
- package/state/testing/src/search-testing.module.ts +19 -0
- package/test.ts +23 -0
- package/testing/ng-package.json +8 -0
- package/testing/package.json +3 -0
- package/testing/src/factories/kind.factory.spec.ts +57 -0
- package/testing/src/factories/kind.factory.ts +37 -0
- package/testing/src/factories/public_api.ts +2 -0
- package/testing/src/factories/search-result.factory.spec.ts +39 -0
- package/testing/src/factories/search-result.factory.ts +26 -0
- package/testing/src/index.ts +1 -0
- package/testing/src/injection-tokens/factories/kind.token.spec.ts +51 -0
- package/testing/src/injection-tokens/factories/kind.token.ts +43 -0
- package/testing/src/injection-tokens/public_api.ts +4 -0
- package/testing/src/public_api.ts +4 -0
- package/testing/src/testing.module.ts +18 -0
- package/tsconfig.json +38 -0
- package/tsconfig.lib.json +28 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +17 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HttpTestingController,
|
|
3
|
+
HttpClientTestingModule,
|
|
4
|
+
} from '@angular/common/http/testing';
|
|
5
|
+
import { TestBed } from '@angular/core/testing';
|
|
6
|
+
import { Observable } from '@apollo/client/core';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
DaffSearchResult,
|
|
10
|
+
DaffSearchResultCollection,
|
|
11
|
+
daffSearchTransformResultsToCollection,
|
|
12
|
+
} from '@daffodil/search';
|
|
13
|
+
import { DaffSearchDriverResponse } from '@daffodil/search/driver';
|
|
14
|
+
import { DaffSearchResultFactory } from '@daffodil/search/testing';
|
|
15
|
+
|
|
16
|
+
import { DaffInMemorySearchDriver } from './search.service';
|
|
17
|
+
|
|
18
|
+
describe('@daffodil/search/driver/in-memory | DaffInMemorySearchDriver', () => {
|
|
19
|
+
let service: DaffInMemorySearchDriver;
|
|
20
|
+
let httpMock: HttpTestingController;
|
|
21
|
+
let searchResultFactory: DaffSearchResultFactory;
|
|
22
|
+
let mockResponse: DaffSearchDriverResponse;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
TestBed.configureTestingModule({
|
|
26
|
+
imports: [
|
|
27
|
+
HttpClientTestingModule,
|
|
28
|
+
],
|
|
29
|
+
providers: [
|
|
30
|
+
DaffInMemorySearchDriver,
|
|
31
|
+
],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
httpMock = TestBed.inject(HttpTestingController);
|
|
35
|
+
service = TestBed.inject(DaffInMemorySearchDriver);
|
|
36
|
+
searchResultFactory = TestBed.inject(DaffSearchResultFactory);
|
|
37
|
+
|
|
38
|
+
mockResponse = {
|
|
39
|
+
collection: daffSearchTransformResultsToCollection(searchResultFactory.createMany(4)),
|
|
40
|
+
metadata: {},
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
httpMock.verify();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should be created', () => {
|
|
49
|
+
expect(service).toBeTruthy();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('search', () => {
|
|
53
|
+
let query: string;
|
|
54
|
+
let url: string;
|
|
55
|
+
let result: ReturnType<DaffInMemorySearchDriver['search']>;
|
|
56
|
+
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
query = 'query';
|
|
59
|
+
url = `${service.url}?query=${query}`;
|
|
60
|
+
result = service.search(query);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should send a get request and return a collection of search results', done => {
|
|
64
|
+
result.subscribe((resp) => {
|
|
65
|
+
expect(resp).toEqual(mockResponse);
|
|
66
|
+
done();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const req = httpMock.expectOne(url);
|
|
70
|
+
expect(req.request.method).toBe('GET');
|
|
71
|
+
|
|
72
|
+
req.flush(mockResponse);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Injectable } from '@angular/core';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DaffSearchDriverInterface,
|
|
7
|
+
DaffSearchDriverOptions,
|
|
8
|
+
DaffSearchDriverResponse,
|
|
9
|
+
} from '@daffodil/search/driver';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The search inmemory driver to mock the search backend service.
|
|
13
|
+
*
|
|
14
|
+
* @inheritdoc
|
|
15
|
+
*/
|
|
16
|
+
@Injectable({
|
|
17
|
+
providedIn: 'root',
|
|
18
|
+
})
|
|
19
|
+
export class DaffInMemorySearchDriver implements DaffSearchDriverInterface {
|
|
20
|
+
/**
|
|
21
|
+
* @docs-private
|
|
22
|
+
*/
|
|
23
|
+
url = '/api/search';
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private http: HttpClient,
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
search(query: string, options: DaffSearchDriverOptions = {}): Observable<DaffSearchDriverResponse> {
|
|
30
|
+
// TODO: handle options
|
|
31
|
+
return this.http.get<DaffSearchDriverResponse>(`${this.url}?query=${query}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Injectable,
|
|
3
|
+
Type,
|
|
4
|
+
} from '@angular/core';
|
|
5
|
+
import { TestBed } from '@angular/core/testing';
|
|
6
|
+
import {
|
|
7
|
+
RequestInfo,
|
|
8
|
+
STATUS,
|
|
9
|
+
} from 'angular-in-memory-web-api';
|
|
10
|
+
|
|
11
|
+
import { DaffSearchInMemoryChildBackend } from '@daffodil/search/driver/in-memory';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
daffProvideSearchInMemoryBackends,
|
|
15
|
+
DAFF_SEARCH_IN_MEMORY_BACKENDS,
|
|
16
|
+
} from './backends.token';
|
|
17
|
+
|
|
18
|
+
@Injectable({
|
|
19
|
+
providedIn: 'root',
|
|
20
|
+
})
|
|
21
|
+
class TestBackend1 implements DaffSearchInMemoryChildBackend {
|
|
22
|
+
kind = 'TestBackend1';
|
|
23
|
+
|
|
24
|
+
get(reqInfo: RequestInfo) {
|
|
25
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
26
|
+
body: [],
|
|
27
|
+
status: STATUS.OK,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Injectable({
|
|
33
|
+
providedIn: 'root',
|
|
34
|
+
})
|
|
35
|
+
class TestBackend2 implements DaffSearchInMemoryChildBackend {
|
|
36
|
+
kind = 'TestBackend2';
|
|
37
|
+
|
|
38
|
+
get(reqInfo: RequestInfo) {
|
|
39
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
40
|
+
body: [],
|
|
41
|
+
status: STATUS.OK,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe('@daffodil/search/driver/in-memory | daffProvideSearchInMemoryBackends', () => {
|
|
47
|
+
let backends: Type<DaffSearchInMemoryChildBackend>[];
|
|
48
|
+
let result: DaffSearchInMemoryChildBackend[];
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
backends = [
|
|
52
|
+
TestBackend1,
|
|
53
|
+
TestBackend2,
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
TestBed.configureTestingModule({
|
|
57
|
+
providers: [
|
|
58
|
+
...daffProvideSearchInMemoryBackends(...backends),
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
result = TestBed.inject(DAFF_SEARCH_IN_MEMORY_BACKENDS);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should provide driver instances to the token', () => {
|
|
66
|
+
expect(result).toContain(jasmine.any(TestBackend1));
|
|
67
|
+
expect(result).toContain(jasmine.any(TestBackend2));
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InjectionToken,
|
|
3
|
+
Provider,
|
|
4
|
+
Type,
|
|
5
|
+
} from '@angular/core';
|
|
6
|
+
|
|
7
|
+
import { DaffSearchInMemoryChildBackend } from '../interfaces/public_api';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A multi-provider injection token for providing feature-specific search in-memory backends.
|
|
11
|
+
* Feature/search "join" packages should provide a backend here to interface
|
|
12
|
+
* with their feature backend for realistic search behavior.
|
|
13
|
+
*/
|
|
14
|
+
export const DAFF_SEARCH_IN_MEMORY_BACKENDS = new InjectionToken<DaffSearchInMemoryChildBackend[]>(
|
|
15
|
+
'DAFF_SEARCH_IN_MEMORY_BACKENDS',
|
|
16
|
+
{ factory: () => []},
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Provides child feature backends for the search in-memory backend.
|
|
21
|
+
*
|
|
22
|
+
* See {@link DAFF_SEARCH_IN_MEMORY_BACKENDS}.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* providers: [
|
|
26
|
+
* ...daffProvideSearchInMemoryBackends(MySearchFeatureBackend)
|
|
27
|
+
* ]
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function daffProvideSearchInMemoryBackends(...drivers: Type<DaffSearchInMemoryChildBackend>[]): Provider[] {
|
|
31
|
+
return drivers.map(driver => ({
|
|
32
|
+
provide: DAFF_SEARCH_IN_MEMORY_BACKENDS,
|
|
33
|
+
useExisting: driver,
|
|
34
|
+
multi: true,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HttpResponse } from '@angular/common/http';
|
|
2
|
+
import { RequestInfo } from 'angular-in-memory-web-api';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
import { DaffSearchDriverResponse } from '@daffodil/search/driver';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The child backends to which the search in-memory backend will delegate search queries.
|
|
9
|
+
*/
|
|
10
|
+
export interface DaffSearchInMemoryChildBackend {
|
|
11
|
+
readonly kind: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Search for entities and get the results.
|
|
15
|
+
*/
|
|
16
|
+
get(reqInfo: RequestInfo): Observable<HttpResponse<DaffSearchDriverResponse>>;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DaffSearchInMemoryChildBackend } from './get-backend.interface';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DaffInMemoryBackendSearchDriver } from './backend/search.service';
|
|
2
|
+
export { DaffInMemorySearchDriver } from './driver/search.service';
|
|
3
|
+
export { DaffSearchInMemoryDriverModule } from './driver/search-driver.module';
|
|
4
|
+
|
|
5
|
+
export * from './interfaces/get-backend.interface';
|
|
6
|
+
export * from './injection-tokens/backends.token';
|
|
7
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DaffError,
|
|
3
|
+
DaffInheritableError,
|
|
4
|
+
} from '@daffodil/core';
|
|
5
|
+
|
|
6
|
+
export const DAFF_SEARCH_INVALID_API_RESPONSE_ERROR_CODE = 'DAFF_SEARCH_INVALID_API_RESPONSE';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A general error indicating that the platform returned a response which cannot be processed.
|
|
10
|
+
*/
|
|
11
|
+
export class DaffSearchInvalidAPIResponseError extends DaffInheritableError implements DaffError {
|
|
12
|
+
public readonly code: string = DAFF_SEARCH_INVALID_API_RESPONSE_ERROR_CODE;
|
|
13
|
+
|
|
14
|
+
constructor(public message: string) {
|
|
15
|
+
super(message);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DaffSearchInvalidAPIResponseError,
|
|
3
|
+
DAFF_SEARCH_INVALID_API_RESPONSE_ERROR_CODE,
|
|
4
|
+
} from './invalid-api-response';
|
|
5
|
+
import {
|
|
6
|
+
DAFF_SEARCH_QUERY_TOO_SHORT_ERROR_CODE,
|
|
7
|
+
DaffSearchQueryTooShortError,
|
|
8
|
+
} from './query-too-short';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A mapping from error codes to error class constructors.
|
|
12
|
+
*/
|
|
13
|
+
export const DaffSearchDriverErrorMap = {
|
|
14
|
+
[DAFF_SEARCH_INVALID_API_RESPONSE_ERROR_CODE]: DaffSearchInvalidAPIResponseError,
|
|
15
|
+
[DAFF_SEARCH_QUERY_TOO_SHORT_ERROR_CODE]: DaffSearchQueryTooShortError,
|
|
16
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export {
|
|
2
|
+
DaffSearchInvalidAPIResponseError,
|
|
3
|
+
DAFF_SEARCH_INVALID_API_RESPONSE_ERROR_CODE,
|
|
4
|
+
} from './invalid-api-response';
|
|
5
|
+
export { DaffSearchDriverErrorMap } from './map';
|
|
6
|
+
export {
|
|
7
|
+
DaffSearchQueryTooShortError,
|
|
8
|
+
DAFF_SEARCH_QUERY_TOO_SHORT_ERROR_CODE,
|
|
9
|
+
} from './query-too-short';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DaffError,
|
|
3
|
+
DaffInheritableError,
|
|
4
|
+
} from '@daffodil/core';
|
|
5
|
+
|
|
6
|
+
export const DAFF_SEARCH_QUERY_TOO_SHORT_ERROR_CODE = 'DAFF_SEARCH_QUERY_TOO_SHORT';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Thrown when the specified search query is too short.
|
|
10
|
+
*/
|
|
11
|
+
export class DaffSearchQueryTooShortError extends DaffInheritableError implements DaffError {
|
|
12
|
+
public readonly code: string = DAFF_SEARCH_QUERY_TOO_SHORT_ERROR_CODE;
|
|
13
|
+
|
|
14
|
+
constructor(public message: string) {
|
|
15
|
+
super(message);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DaffSearchResult,
|
|
3
|
+
DaffSearchResultCollection,
|
|
4
|
+
} from '@daffodil/search';
|
|
5
|
+
|
|
6
|
+
export interface DaffSearchDriverResponse<
|
|
7
|
+
T extends DaffSearchResult = DaffSearchResult,
|
|
8
|
+
> {
|
|
9
|
+
/**
|
|
10
|
+
* The collection of search result entities.
|
|
11
|
+
*/
|
|
12
|
+
collection: DaffSearchResultCollection<T>;
|
|
13
|
+
/**
|
|
14
|
+
* A place for specific drivers to return extra info that applies to the entire response.
|
|
15
|
+
* For example, this could be pagination, sorting, or filtering.
|
|
16
|
+
*/
|
|
17
|
+
metadata: unknown;
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DaffSearchResult } from '@daffodil/search';
|
|
2
|
+
|
|
3
|
+
import { DaffSearchDriverInterface } from './search-service.interface';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A driver interface for search feature drivers of a specific kind.
|
|
7
|
+
* Search results are chunked per kind and feature drivers should associate
|
|
8
|
+
* themselves with a specific kind.
|
|
9
|
+
*/
|
|
10
|
+
export interface DaffSearchDriverKindedInterface<
|
|
11
|
+
T extends DaffSearchResult = DaffSearchResult,
|
|
12
|
+
> extends DaffSearchDriverInterface<T> {
|
|
13
|
+
/**
|
|
14
|
+
* The kind of entity for which this driver can search.
|
|
15
|
+
*/
|
|
16
|
+
readonly kind: T['kind'];
|
|
17
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
import { DaffSearchResult } from '@daffodil/search';
|
|
5
|
+
|
|
6
|
+
import type { DaffSearchDriverResponse } from './response.interface';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An injection token for the search driver.
|
|
10
|
+
*/
|
|
11
|
+
export const DaffSearchDriver = new InjectionToken<DaffSearchDriverInterface>('DaffSearchDriver');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The options for making a search.
|
|
15
|
+
*/
|
|
16
|
+
export interface DaffSearchDriverOptions {
|
|
17
|
+
/**
|
|
18
|
+
* The number of results to request from the platform.
|
|
19
|
+
*
|
|
20
|
+
* There is an important caveat for this option.
|
|
21
|
+
* This value only controls the requested number of results
|
|
22
|
+
* from the platform *per request*.
|
|
23
|
+
*
|
|
24
|
+
* For drivers that might make multiple requests in the background, e.g. the federated driver,
|
|
25
|
+
* this value will not match the actual number of results returned.
|
|
26
|
+
*
|
|
27
|
+
* This should be used as a performance option rather than controlling the result list size.
|
|
28
|
+
*/
|
|
29
|
+
limit?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The search driver is responsible for interfacing with a platform to search for entites.
|
|
34
|
+
*/
|
|
35
|
+
export interface DaffSearchDriverInterface<
|
|
36
|
+
T extends DaffSearchResult = DaffSearchResult,
|
|
37
|
+
> {
|
|
38
|
+
/**
|
|
39
|
+
* Searches for entities according to the specified query.
|
|
40
|
+
*/
|
|
41
|
+
search(query: string, options?: DaffSearchDriverOptions): Observable<DaffSearchDriverResponse<T>>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export {
|
|
2
|
+
DaffSearchDriver,
|
|
3
|
+
DaffSearchDriverInterface,
|
|
4
|
+
DaffSearchDriverOptions,
|
|
5
|
+
} from './interfaces/search-service.interface';
|
|
6
|
+
export { DaffSearchDriverKindedInterface } from './interfaces/search-service-kinded.interface';
|
|
7
|
+
export { DaffSearchDriverResponse } from './interfaces/response.interface';
|
|
8
|
+
|
|
9
|
+
export * from './errors/public_api';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import {
|
|
3
|
+
NgModule,
|
|
4
|
+
ModuleWithProviders,
|
|
5
|
+
} from '@angular/core';
|
|
6
|
+
|
|
7
|
+
import { DaffSearchDriver } from '@daffodil/search/driver';
|
|
8
|
+
|
|
9
|
+
import { DaffTestingSearchDriver } from './search.service';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Provides the {@link DaffTestingSearchDriver} as the {@link DaffSearchDriver}.
|
|
13
|
+
*/
|
|
14
|
+
@NgModule({
|
|
15
|
+
imports: [
|
|
16
|
+
CommonModule,
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
export class DaffSearchTestingDriverModule {
|
|
20
|
+
static forRoot(): ModuleWithProviders<DaffSearchTestingDriverModule> {
|
|
21
|
+
return {
|
|
22
|
+
ngModule: DaffSearchTestingDriverModule,
|
|
23
|
+
providers: [
|
|
24
|
+
{
|
|
25
|
+
provide: DaffSearchDriver,
|
|
26
|
+
useExisting: DaffTestingSearchDriver,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { cold } from 'jasmine-marbles';
|
|
3
|
+
|
|
4
|
+
import { DaffTestingSearchDriver } from './search.service';
|
|
5
|
+
|
|
6
|
+
describe('@daffodil/driver/testing | DaffTestingSearchDriver', () => {
|
|
7
|
+
let service: DaffTestingSearchDriver;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
TestBed.configureTestingModule({
|
|
11
|
+
providers: [
|
|
12
|
+
DaffTestingSearchDriver,
|
|
13
|
+
],
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
service = TestBed.inject(DaffTestingSearchDriver);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should be created', () => {
|
|
20
|
+
expect(service).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('search', () => {
|
|
24
|
+
it('should return a DaffSearchResultCollection', () => {
|
|
25
|
+
const expected = cold('(a|)', { a: jasmine.notEmpty() });
|
|
26
|
+
expect(service.search('query')).toBeObservable(expected);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import {
|
|
3
|
+
Observable,
|
|
4
|
+
of,
|
|
5
|
+
} from 'rxjs';
|
|
6
|
+
|
|
7
|
+
import { daffSearchTransformResultsToCollection } from '@daffodil/search';
|
|
8
|
+
import {
|
|
9
|
+
DaffSearchDriverInterface,
|
|
10
|
+
DaffSearchDriverOptions,
|
|
11
|
+
DaffSearchDriverResponse,
|
|
12
|
+
} from '@daffodil/search/driver';
|
|
13
|
+
import { DaffSearchResultKindFactory } from '@daffodil/search/testing';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A basic search driver that creates mock search results of different kinds.
|
|
17
|
+
* For testing purposes.
|
|
18
|
+
*
|
|
19
|
+
* @inheritdoc
|
|
20
|
+
*/
|
|
21
|
+
@Injectable({
|
|
22
|
+
providedIn: 'root',
|
|
23
|
+
})
|
|
24
|
+
export class DaffTestingSearchDriver implements DaffSearchDriverInterface {
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
private searchResultFactory: DaffSearchResultKindFactory,
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
search(query: string, options: DaffSearchDriverOptions = {}): Observable<DaffSearchDriverResponse> {
|
|
31
|
+
const limit = options.limit || 5;
|
|
32
|
+
return of({
|
|
33
|
+
collection: daffSearchTransformResultsToCollection(this.searchResultFactory.createMany(limit)),
|
|
34
|
+
metadata: {},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './drivers/public_api';
|
package/karma.conf.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
baseConfiguration = require('../../tools/karma/karma.conf');
|
|
2
|
+
|
|
3
|
+
module.exports = function (config) {
|
|
4
|
+
baseConfiguration(config);
|
|
5
|
+
config.set({
|
|
6
|
+
coverageIstanbulReporter: {
|
|
7
|
+
dir: require('path').join(__dirname, '../../coverage/libs/search'),
|
|
8
|
+
},
|
|
9
|
+
restartOnFileChange: true
|
|
10
|
+
});
|
|
11
|
+
};
|
package/ng-package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@daffodil/search",
|
|
3
|
+
"version": "0.0.0-PLACEHOLDER",
|
|
4
|
+
"description": "A client-side Angular package for managing ecommerce orders agnostic to the ecommerce platform.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/graycoreio/daffodil"
|
|
8
|
+
},
|
|
9
|
+
"author": "Graycore LLC",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/graycoreio/daffodil/issues"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "ng build search --prod",
|
|
16
|
+
"lint": "cd ../.. && ng lint search",
|
|
17
|
+
"lint:fix": "npm run lint -- --fix",
|
|
18
|
+
"test": "ng test search --watch=false --browsers=ChromeHeadless",
|
|
19
|
+
"prepublish": "cd ../../dist/search",
|
|
20
|
+
"publish": "npm publish --access=public"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/graycoreio/daffodil",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@angular/common": "0.0.0-PLACEHOLDER",
|
|
25
|
+
"@angular/core": "0.0.0-PLACEHOLDER",
|
|
26
|
+
"@daffodil/core": "0.0.0-PLACEHOLDER",
|
|
27
|
+
"@ngrx/effects": "0.0.0-PLACEHOLDER",
|
|
28
|
+
"@ngrx/store": "0.0.0-PLACEHOLDER",
|
|
29
|
+
"rxjs": "0.0.0-PLACEHOLDER"
|
|
30
|
+
},
|
|
31
|
+
"optionalDependencies": {
|
|
32
|
+
"@apollo/client": "0.0.0-PLACEHOLDER",
|
|
33
|
+
"@daffodil/driver": "0.0.0-PLACEHOLDER",
|
|
34
|
+
"apollo-angular": "0.0.0-PLACEHOLDER",
|
|
35
|
+
"@faker-js/faker": "0.0.0-PLACEHOLDER"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@daffodil/core": "0.0.0-PLACEHOLDER"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
import { DaffSearchRoutingOptionBuilder } from './builders.token';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An internal token to combine the {@link DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS} into a single builder.
|
|
7
|
+
*/
|
|
8
|
+
export const DAFF_SEARCH_ROUTING_OPTIONS_BUILDER = new InjectionToken<DaffSearchRoutingOptionBuilder>(
|
|
9
|
+
'DAFF_SEARCH_ROUTING_OPTIONS_BUILDER',
|
|
10
|
+
);
|