@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,35 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { DaffSearchRoutingOptionBuilder } from '@daffodil/search/routing';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
daffProvideSearchRoutingOptionBuilders,
|
|
7
|
+
DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS,
|
|
8
|
+
} from './builders.token';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
describe('daffProvideSearchRoutingOptionBuilders', () => {
|
|
12
|
+
let builders: DaffSearchRoutingOptionBuilder[];
|
|
13
|
+
let result: DaffSearchRoutingOptionBuilder[];
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
builders = [
|
|
17
|
+
() => null,
|
|
18
|
+
() => null,
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
TestBed.configureTestingModule({
|
|
22
|
+
providers: [
|
|
23
|
+
...daffProvideSearchRoutingOptionBuilders(...builders),
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
result = TestBed.inject(DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should provide the builders to the token', () => {
|
|
31
|
+
builders.forEach(builder => {
|
|
32
|
+
expect(result).toContain(builder);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InjectionToken,
|
|
3
|
+
ValueProvider,
|
|
4
|
+
} from '@angular/core';
|
|
5
|
+
import { ActivatedRouteSnapshot } from '@angular/router';
|
|
6
|
+
|
|
7
|
+
import { DaffSearchDriverOptions } from '@daffodil/search/driver';
|
|
8
|
+
|
|
9
|
+
export type DaffSearchRoutingOptionBuilder<T extends DaffSearchDriverOptions = DaffSearchDriverOptions> = (route: ActivatedRouteSnapshot) => T;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A multi-provider injection token for search option builders.
|
|
13
|
+
* These builders are called with the requested route during the resolve step
|
|
14
|
+
* and return options to pass to the search driver.
|
|
15
|
+
*/
|
|
16
|
+
export const DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS = new InjectionToken<DaffSearchRoutingOptionBuilder[]>(
|
|
17
|
+
'DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS',
|
|
18
|
+
{ factory: () => []},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Provides search option builders for the routing layer.
|
|
23
|
+
*
|
|
24
|
+
* See {@link DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS}.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* providers: [
|
|
28
|
+
* ...daffProvideSearchRoutingOptionBuilders(
|
|
29
|
+
* route => ({
|
|
30
|
+
* limit: route.queryParams.limit
|
|
31
|
+
* })
|
|
32
|
+
* )
|
|
33
|
+
* ]
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function daffProvideSearchRoutingOptionBuilders(...builders: DaffSearchRoutingOptionBuilder[]): ValueProvider[] {
|
|
37
|
+
return builders.map(builder => ({
|
|
38
|
+
provide: DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS,
|
|
39
|
+
useValue: builder,
|
|
40
|
+
multi: true,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
inject,
|
|
3
|
+
NgModule,
|
|
4
|
+
} from '@angular/core';
|
|
5
|
+
import { ActivatedRouteSnapshot } from '@angular/router';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
DAFF_SEARCH_ROUTING_OPTIONS_BUILDER,
|
|
9
|
+
DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS,
|
|
10
|
+
} from './injection-tokens/public_api';
|
|
11
|
+
import { DaffSearchPageResolver } from './resolvers/public_api';
|
|
12
|
+
|
|
13
|
+
@NgModule({
|
|
14
|
+
providers: [
|
|
15
|
+
{
|
|
16
|
+
provide: DAFF_SEARCH_ROUTING_OPTIONS_BUILDER,
|
|
17
|
+
useFactory: () => {
|
|
18
|
+
const builders = inject(DAFF_SEARCH_ROUTING_OPTIONS_BUILDERS);
|
|
19
|
+
return (route: ActivatedRouteSnapshot) =>
|
|
20
|
+
Object.assign({}, ...builders.map(builder => builder(route)));
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
DaffSearchPageResolver,
|
|
24
|
+
],
|
|
25
|
+
})
|
|
26
|
+
export class DaffSearchRoutingModule {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DaffSearchPageResolver } from './search/search.resolver';
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ɵPLATFORM_BROWSER_ID,
|
|
3
|
+
ɵPLATFORM_SERVER_ID,
|
|
4
|
+
} from '@angular/common';
|
|
5
|
+
import { PLATFORM_ID } from '@angular/core';
|
|
6
|
+
import {
|
|
7
|
+
TestBed,
|
|
8
|
+
waitForAsync,
|
|
9
|
+
} from '@angular/core/testing';
|
|
10
|
+
import {
|
|
11
|
+
ActivatedRoute,
|
|
12
|
+
ActivatedRouteSnapshot,
|
|
13
|
+
} from '@angular/router';
|
|
14
|
+
import { RouterTestingModule } from '@angular/router/testing';
|
|
15
|
+
import { provideMockActions } from '@ngrx/effects/testing';
|
|
16
|
+
import {
|
|
17
|
+
StoreModule,
|
|
18
|
+
combineReducers,
|
|
19
|
+
Store,
|
|
20
|
+
ActionsSubject,
|
|
21
|
+
} from '@ngrx/store';
|
|
22
|
+
import { Observable } from 'rxjs';
|
|
23
|
+
|
|
24
|
+
import { DaffSearchDriverOptions } from '@daffodil/search/driver';
|
|
25
|
+
import {
|
|
26
|
+
DaffSearchRoutingOptionBuilder,
|
|
27
|
+
DAFF_SEARCH_ROUTING_OPTIONS_BUILDER,
|
|
28
|
+
} from '@daffodil/search/routing';
|
|
29
|
+
import {
|
|
30
|
+
daffSearchReducers,
|
|
31
|
+
DaffSearchLoad,
|
|
32
|
+
DaffSearchLoadSuccess,
|
|
33
|
+
DaffSearchLoadFailure,
|
|
34
|
+
DaffSearchStateRootSlice,
|
|
35
|
+
DAFF_SEARCH_STORE_FEATURE_KEY,
|
|
36
|
+
} from '@daffodil/search/state';
|
|
37
|
+
|
|
38
|
+
import { DaffSearchPageResolver } from './search.resolver';
|
|
39
|
+
|
|
40
|
+
describe('@daffodil/search/routing | DaffSearchPageResolver', () => {
|
|
41
|
+
let actions$: ActionsSubject;
|
|
42
|
+
let searchResolver: DaffSearchPageResolver;
|
|
43
|
+
let store: Store<DaffSearchStateRootSlice>;
|
|
44
|
+
let route: ActivatedRoute;
|
|
45
|
+
let query: string;
|
|
46
|
+
let options: DaffSearchDriverOptions;
|
|
47
|
+
let builder: DaffSearchRoutingOptionBuilder;
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
query = 'query';
|
|
51
|
+
options = {
|
|
52
|
+
limit: 5,
|
|
53
|
+
};
|
|
54
|
+
builder = r => options;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('resolve - on server', () => {
|
|
58
|
+
beforeEach(waitForAsync(() => {
|
|
59
|
+
TestBed.configureTestingModule({
|
|
60
|
+
imports: [
|
|
61
|
+
StoreModule.forRoot({
|
|
62
|
+
[DAFF_SEARCH_STORE_FEATURE_KEY]: combineReducers(daffSearchReducers),
|
|
63
|
+
}),
|
|
64
|
+
RouterTestingModule,
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
store = TestBed.inject(Store);
|
|
69
|
+
route = TestBed.inject(ActivatedRoute);
|
|
70
|
+
actions$ = new ActionsSubject();
|
|
71
|
+
searchResolver = new DaffSearchPageResolver(
|
|
72
|
+
ɵPLATFORM_SERVER_ID,
|
|
73
|
+
store,
|
|
74
|
+
actions$,
|
|
75
|
+
builder,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
spyOn(store, 'dispatch');
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
it('should dispatch a DaffSearchLoad action with the correct search query', () => {
|
|
82
|
+
searchResolver.resolve(<ActivatedRouteSnapshot><unknown>{
|
|
83
|
+
...route.snapshot,
|
|
84
|
+
queryParams: {
|
|
85
|
+
query,
|
|
86
|
+
},
|
|
87
|
+
}).subscribe();
|
|
88
|
+
expect(store.dispatch).toHaveBeenCalledWith(
|
|
89
|
+
new DaffSearchLoad(query, options),
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should resolve when DaffSearchLoadSuccess is dispatched', done => {
|
|
94
|
+
searchResolver.resolve(route.snapshot).subscribe(value => {
|
|
95
|
+
expect(value).toEqual(true);
|
|
96
|
+
done();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
actions$.next(new DaffSearchLoadSuccess({
|
|
100
|
+
collection: {},
|
|
101
|
+
metadata: {},
|
|
102
|
+
}));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should resolve when DaffCartLoadFailure is dispatched', done => {
|
|
106
|
+
searchResolver.resolve(route.snapshot).subscribe(value => {
|
|
107
|
+
expect(value).toEqual(true);
|
|
108
|
+
done();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
actions$.next(new DaffSearchLoadFailure(null));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should not resolve without a search load success or failure', () => {
|
|
115
|
+
searchResolver.resolve(route.snapshot).subscribe(() => {
|
|
116
|
+
fail();
|
|
117
|
+
});
|
|
118
|
+
expect(true).toBeTruthy();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('resolve - in the browser', () => {
|
|
123
|
+
|
|
124
|
+
beforeEach(() => {
|
|
125
|
+
TestBed.configureTestingModule({
|
|
126
|
+
imports: [
|
|
127
|
+
StoreModule.forRoot({
|
|
128
|
+
[DAFF_SEARCH_STORE_FEATURE_KEY]: combineReducers(daffSearchReducers),
|
|
129
|
+
}),
|
|
130
|
+
RouterTestingModule,
|
|
131
|
+
],
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
store = TestBed.inject(Store);
|
|
135
|
+
route = TestBed.inject(ActivatedRoute);
|
|
136
|
+
actions$ = new ActionsSubject();
|
|
137
|
+
searchResolver = new DaffSearchPageResolver(
|
|
138
|
+
ɵPLATFORM_BROWSER_ID,
|
|
139
|
+
store,
|
|
140
|
+
actions$,
|
|
141
|
+
builder,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
spyOn(store, 'dispatch');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should dispatch a DaffSearchLoad action with the correct search query and options', () => {
|
|
148
|
+
searchResolver.resolve(<ActivatedRouteSnapshot><unknown>{
|
|
149
|
+
...route.snapshot,
|
|
150
|
+
queryParams: {
|
|
151
|
+
query,
|
|
152
|
+
},
|
|
153
|
+
}).subscribe();
|
|
154
|
+
expect(store.dispatch).toHaveBeenCalledWith(
|
|
155
|
+
new DaffSearchLoad(query, options),
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should resolve without a search load success or failure', done => {
|
|
160
|
+
searchResolver.resolve(route.snapshot).subscribe(value => {
|
|
161
|
+
expect(value).toBeTruthy();
|
|
162
|
+
done();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
2
|
+
import {
|
|
3
|
+
Inject,
|
|
4
|
+
Injectable,
|
|
5
|
+
PLATFORM_ID,
|
|
6
|
+
} from '@angular/core';
|
|
7
|
+
import {
|
|
8
|
+
ActivatedRouteSnapshot,
|
|
9
|
+
Resolve,
|
|
10
|
+
RouterStateSnapshot,
|
|
11
|
+
} from '@angular/router';
|
|
12
|
+
import { ofType } from '@ngrx/effects';
|
|
13
|
+
import {
|
|
14
|
+
ActionsSubject,
|
|
15
|
+
Store,
|
|
16
|
+
} from '@ngrx/store';
|
|
17
|
+
import {
|
|
18
|
+
Observable,
|
|
19
|
+
of,
|
|
20
|
+
} from 'rxjs';
|
|
21
|
+
import {
|
|
22
|
+
map,
|
|
23
|
+
take,
|
|
24
|
+
} from 'rxjs/operators';
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
DaffSearchLoad,
|
|
28
|
+
DaffSearchStateRootSlice,
|
|
29
|
+
} from '@daffodil/search/state';
|
|
30
|
+
import { DaffSearchActionTypes } from '@daffodil/search/state';
|
|
31
|
+
|
|
32
|
+
import { DaffSearchRoutingOptionBuilder } from '../../injection-tokens/public_api';
|
|
33
|
+
import { DAFF_SEARCH_ROUTING_OPTIONS_BUILDER } from '../../injection-tokens/search-options/builder.token';
|
|
34
|
+
|
|
35
|
+
const getQuery = (route: ActivatedRouteSnapshot): string => route.queryParams.q || route.queryParams.query;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Resolves search data for search pages, and will only resolve the url after a search request succeeds or fails. This resolver expects a url
|
|
39
|
+
* of the form `some/url/{id}` where `{id}` is the search id.
|
|
40
|
+
*/
|
|
41
|
+
@Injectable()
|
|
42
|
+
export class DaffSearchPageResolver implements Resolve<Observable<boolean>> {
|
|
43
|
+
constructor(
|
|
44
|
+
@Inject(PLATFORM_ID) private platformId: string,
|
|
45
|
+
private store: Store<DaffSearchStateRootSlice>,
|
|
46
|
+
private dispatcher: ActionsSubject,
|
|
47
|
+
@Inject(DAFF_SEARCH_ROUTING_OPTIONS_BUILDER) private builder: DaffSearchRoutingOptionBuilder,
|
|
48
|
+
) {}
|
|
49
|
+
|
|
50
|
+
resolve(route: ActivatedRouteSnapshot): Observable<boolean> {
|
|
51
|
+
const query = getQuery(route);
|
|
52
|
+
if (query) {
|
|
53
|
+
this.store.dispatch(new DaffSearchLoad(query, this.builder(route)));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return isPlatformBrowser(this.platformId) ? of(true) : this.dispatcher.pipe(
|
|
57
|
+
ofType(
|
|
58
|
+
DaffSearchActionTypes.SearchLoadSuccessAction,
|
|
59
|
+
DaffSearchActionTypes.SearchLoadFailureAction,
|
|
60
|
+
),
|
|
61
|
+
map(() => true),
|
|
62
|
+
take(1),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
import { daffTransformErrorToStateError } from '@daffodil/core/state';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transforms `DaffError`s into `DaffStateError`s before they are serialized into state.
|
|
7
|
+
* Can be used to further refine Daffodil errors into more specific app errors.
|
|
8
|
+
*/
|
|
9
|
+
export const DAFF_SEARCH_ERROR_MATCHER = new InjectionToken<typeof daffTransformErrorToStateError>(
|
|
10
|
+
'DAFF_SEARCH_ERROR_MATCHER',
|
|
11
|
+
{ factory: () => daffTransformErrorToStateError },
|
|
12
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DAFF_SEARCH_ERROR_MATCHER } from './error-matcher.token';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { daffSearchTransformResultsToCollection } from './results-to-collection';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { DaffSearchResultFactory } from '@daffodil/search/testing';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DaffSearchResult,
|
|
7
|
+
DaffSearchResultCollection,
|
|
8
|
+
} from '../models/public_api';
|
|
9
|
+
import { daffSearchTransformResultsToCollection } from './results-to-collection';
|
|
10
|
+
|
|
11
|
+
describe('@daffodil/search | daffSearchTransformResultsToCollection', () => {
|
|
12
|
+
let results: DaffSearchResult[];
|
|
13
|
+
let resultFactory: DaffSearchResultFactory;
|
|
14
|
+
let collection: DaffSearchResultCollection;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
resultFactory = TestBed.inject(DaffSearchResultFactory);
|
|
18
|
+
results = resultFactory.createMany(5);
|
|
19
|
+
|
|
20
|
+
collection = daffSearchTransformResultsToCollection(results);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should create and return a collection from the search results', () => {
|
|
24
|
+
results.forEach(result => {
|
|
25
|
+
expect(collection[result.kind]).toContain(result);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DaffSearchResult,
|
|
3
|
+
DaffSearchResultCollection,
|
|
4
|
+
} from '../models/public_api';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Transforms a list of search results into a collection, keying by the result kind.
|
|
8
|
+
*/
|
|
9
|
+
export const daffSearchTransformResultsToCollection = <T extends DaffSearchResult = DaffSearchResult>(searchResults: T[]): DaffSearchResultCollection<T> =>
|
|
10
|
+
searchResults.reduce((collection, result) => {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
12
|
+
collection[result.kind] ? collection[result.kind].push(result) : collection[result.kind] = [result];
|
|
13
|
+
return collection;
|
|
14
|
+
}, <DaffSearchResultCollection<T>>{});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Action } from '@ngrx/store';
|
|
2
|
+
|
|
3
|
+
import { DaffStateError } from '@daffodil/core/state';
|
|
4
|
+
import { DaffSearchResult } from '@daffodil/search';
|
|
5
|
+
import {
|
|
6
|
+
DaffSearchDriverOptions,
|
|
7
|
+
DaffSearchDriverResponse,
|
|
8
|
+
} from '@daffodil/search/driver';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The search action types enum.
|
|
12
|
+
*/
|
|
13
|
+
export enum DaffSearchActionTypes {
|
|
14
|
+
SearchLoadAction = '[@daffodil/search] Search Load Action',
|
|
15
|
+
SearchLoadSuccessAction = '[@daffodil/search] Search Load Success Action',
|
|
16
|
+
SearchLoadFailureAction = '[@daffodil/search] Search Load Failure Action',
|
|
17
|
+
SearchIncrementalAction = '[@daffodil/search] Search Incremental Action',
|
|
18
|
+
SearchIncrementalSuccessAction = '[@daffodil/search] Search Incremental Success Action',
|
|
19
|
+
SearchIncrementalFailureAction = '[@daffodil/search] Search Incremental Failure Action',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Searches for the specified phrase.
|
|
24
|
+
*
|
|
25
|
+
* @param query The search query.
|
|
26
|
+
*/
|
|
27
|
+
export class DaffSearchLoad implements Action {
|
|
28
|
+
readonly type = DaffSearchActionTypes.SearchLoadAction;
|
|
29
|
+
|
|
30
|
+
constructor(public query: string, public options: DaffSearchDriverOptions = {}) {}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A successful search with the dictionary of results.
|
|
35
|
+
*/
|
|
36
|
+
export class DaffSearchLoadSuccess<T extends DaffSearchResult = DaffSearchResult> implements Action {
|
|
37
|
+
readonly type = DaffSearchActionTypes.SearchLoadSuccessAction;
|
|
38
|
+
|
|
39
|
+
constructor(public payload: DaffSearchDriverResponse<T>) {}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A failed search with the error message.
|
|
44
|
+
*/
|
|
45
|
+
export class DaffSearchLoadFailure implements Action {
|
|
46
|
+
readonly type = DaffSearchActionTypes.SearchLoadFailureAction;
|
|
47
|
+
|
|
48
|
+
constructor(public payload: DaffStateError) {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Searches for the specified phrase.
|
|
53
|
+
* Automatically applies a result limit and
|
|
54
|
+
* does not save the search query in state.
|
|
55
|
+
*
|
|
56
|
+
* @param query The search query.
|
|
57
|
+
*/
|
|
58
|
+
export class DaffSearchIncremental implements Action {
|
|
59
|
+
readonly type = DaffSearchActionTypes.SearchIncrementalAction;
|
|
60
|
+
|
|
61
|
+
constructor(public query: string, public options: DaffSearchDriverOptions = {}) {}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A successful search with the dictionary of results.
|
|
66
|
+
*/
|
|
67
|
+
export class DaffSearchIncrementalSuccess<T extends DaffSearchResult = DaffSearchResult> implements Action {
|
|
68
|
+
readonly type = DaffSearchActionTypes.SearchIncrementalSuccessAction;
|
|
69
|
+
|
|
70
|
+
constructor(public payload: DaffSearchDriverResponse<T>) {}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A failed search with the error message.
|
|
75
|
+
*/
|
|
76
|
+
export class DaffSearchIncrementalFailure implements Action {
|
|
77
|
+
readonly type = DaffSearchActionTypes.SearchIncrementalFailureAction;
|
|
78
|
+
|
|
79
|
+
constructor(public payload: DaffStateError) {}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A union of the search action types.
|
|
84
|
+
*/
|
|
85
|
+
export type DaffSearchActions<
|
|
86
|
+
T extends DaffSearchResult = DaffSearchResult,
|
|
87
|
+
> =
|
|
88
|
+
| DaffSearchLoad
|
|
89
|
+
| DaffSearchLoadSuccess<T>
|
|
90
|
+
| DaffSearchLoadFailure
|
|
91
|
+
| DaffSearchIncremental
|
|
92
|
+
| DaffSearchIncrementalSuccess<T>
|
|
93
|
+
| DaffSearchIncrementalFailure;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DaffSearchStateConfig } from './interface';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The default configuration for the {@link DaffSearchStateConfig}.
|
|
5
|
+
*/
|
|
6
|
+
export const DAFF_SEARCH_STATE_CONFIG_DEFAULT: DaffSearchStateConfig = {
|
|
7
|
+
incrementalResultLimit: 5,
|
|
8
|
+
// TODO: figure out how to implement
|
|
9
|
+
// recentSearchLimit: 10,
|
|
10
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* An interface for providing @daffodil/search/state with necessary config values.
|
|
4
|
+
*/
|
|
5
|
+
export interface DaffSearchStateConfig {
|
|
6
|
+
/**
|
|
7
|
+
* The result limit to pass to the driver during an incremental search.
|
|
8
|
+
* See {@link DaffSearchDriverOptions#limit}
|
|
9
|
+
*
|
|
10
|
+
* Defaults to 5.
|
|
11
|
+
*/
|
|
12
|
+
incrementalResultLimit?: number;
|
|
13
|
+
/**
|
|
14
|
+
* The number of recent search queries to store.
|
|
15
|
+
*
|
|
16
|
+
* Defaults to 10.
|
|
17
|
+
*/
|
|
18
|
+
// TODO: figure out how to implement
|
|
19
|
+
// recentSearchLimit?: number;
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
import { DAFF_SEARCH_STATE_CONFIG_DEFAULT } from './default';
|
|
4
|
+
import { DaffSearchStateConfig } from './interface';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The token used to provide @daffodil/search/state config data.
|
|
8
|
+
*/
|
|
9
|
+
export const DAFF_SEARCH_STATE_CONFIG = new InjectionToken<DaffSearchStateConfig>('DAFF_SEARCH_STATE_CONFIG', {
|
|
10
|
+
factory: () => DAFF_SEARCH_STATE_CONFIG_DEFAULT,
|
|
11
|
+
});
|