1 | import {DocumentListBuilder, DocumentListInput, PartialDocumentList} from './DocumentList'
|
2 | import {SchemaType} from './parts/Schema'
|
3 | import {Child} from './StructureNodes'
|
4 | import {DEFAULT_INTENT_HANDLER} from './documentTypeListItems'
|
5 |
|
6 |
|
7 |
|
8 | export class DocumentTypeListBuilder extends DocumentListBuilder {
|
9 | protected spec: PartialDocumentList
|
10 |
|
11 | constructor(spec?: DocumentListInput) {
|
12 | super()
|
13 | this.spec = spec ? spec : {}
|
14 | }
|
15 |
|
16 | filter(filter: string): DocumentListBuilder {
|
17 | return this.cloneWithoutDefaultIntentHandler({
|
18 | options: {...(this.spec.options || {}), filter}
|
19 | })
|
20 | }
|
21 |
|
22 | params(params: {}): DocumentListBuilder {
|
23 | return this.cloneWithoutDefaultIntentHandler({
|
24 | options: {...(this.spec.options || {filter: ''}), params}
|
25 | })
|
26 | }
|
27 |
|
28 | schemaType(type: SchemaType | string): DocumentListBuilder {
|
29 | return this.cloneWithoutDefaultIntentHandler({
|
30 | schemaTypeName: typeof type === 'string' ? type : type.name
|
31 | })
|
32 | }
|
33 |
|
34 | child(child: Child) {
|
35 | return this.cloneWithoutDefaultIntentHandler({child})
|
36 | }
|
37 |
|
38 | clone(withSpec?: PartialDocumentList): DocumentTypeListBuilder {
|
39 | const builder = new DocumentTypeListBuilder()
|
40 | builder.spec = {...this.spec, ...(withSpec || {})}
|
41 | return builder
|
42 | }
|
43 |
|
44 | cloneWithoutDefaultIntentHandler(withSpec?: PartialDocumentList): DocumentTypeListBuilder {
|
45 | const builder = new DocumentTypeListBuilder()
|
46 | const canHandleIntent = this.spec.canHandleIntent
|
47 | const shouldOverride = canHandleIntent && canHandleIntent.identity === DEFAULT_INTENT_HANDLER
|
48 | const override = shouldOverride ? {canHandleIntent: undefined} : {}
|
49 | builder.spec = {...this.spec, ...(withSpec || {}), ...override}
|
50 | return builder
|
51 | }
|
52 | }
|