-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.d.ts
148 lines (148 loc) · 5.84 KB
/
classes.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import type { AnswerInterface, AnswerLike, AnswerProperties, AnswerRow, AnswerValidator, AnswerValidatorFunction, AnswerValidationIssue, CounterInterface, CounterOperation, CounterSetInterface, ItemInterface, ItemLike, ItemProperties, ItemValidator, ItemValidatorFunction, ItemValidationIssue, NextItemFun, OptionInterface, OptionLike, OptionProperties, ProcessAnswerFun, QuestionnaireInterface, QuestionnaireProperties, ValidationIssue } from "./types";
import { AnswerType, ContentChangeSource, ValidationIssueLevel } from "./types";
export declare class Questionnaire implements QuestionnaireInterface {
readonly name: string;
readonly introduction: string;
readonly citation?: string;
readonly version?: string;
readonly counters: CounterSet;
readonly items: Item[];
readonly onComplete: (state: Questionnaire) => void;
reset_items_on_back: boolean;
private _data;
current_item: Item | undefined;
item_history: Item[];
validation_issues: ValidationIssue[];
constructor(props: QuestionnaireProperties);
next_q(): void;
last_q(): void;
getItemById(id: string): Item;
get data(): any;
set data(content: any);
get next_item_in_sequence_id(): string | null;
check_validation(): ValidationIssue[];
}
export declare class Counter implements CounterInterface {
_name: string;
_operations: CounterOperation[];
_initial_content: number;
constructor(name: string, initial_content?: number);
set name(s: string);
get name(): string;
/**
* Register an Item's setting of the counter content
*/
set_content(new_content: number, source: Item): void;
get content(): number;
/**
* Register an Item's incrementing of the counter content
*/
increment_content(increment: number, source: Item): void;
/**
* Remove all operations associated with an Item
*/
revert(source: Item): void;
}
export declare class CounterSet implements CounterSetInterface {
counters: Counter[];
private readonly _state;
constructor(state: Questionnaire);
_find_counter(name: string): Counter;
_create_counter(name: string, initial_content: number): Counter;
/**
* Return the content of a counter, or default_content if the counter
* does not exist yet. If default_content is null and the counter
* does not yet exist, throw an error.
*/
get(name: string, default_content?: number | null): number;
/**
* Register Item setting Counter to content
*/
set(name: string, content: number, source?: Item): void;
/**
* Register Item incrementing Counter by content
*/
increment(name: string, content?: number, source?: Item): void;
/**
* Remove all Item's actions for all counters
*/
revert(source: Item): void;
}
export declare class Item implements ItemInterface {
readonly id: string;
readonly question: string;
readonly handleAnswer: ProcessAnswerFun;
readonly getNextItemId: NextItemFun;
readonly conditional_routing: boolean;
answers: Answer[];
answer_utc_time?: string;
validators: ItemValidator[];
own_validation_issues: ItemValidationIssue[];
validation_issues: ValidationIssue[];
constructor(props: ItemProperties);
next_item(last_changed_answer: Answer | undefined, current_item: Item, state: Questionnaire): (Item | undefined);
get answer(): Answer;
get last_changed_answer(): Answer | undefined;
check_validation(state: Questionnaire, include_children?: boolean): ValidationIssue[];
get as_rows(): AnswerRow[];
}
export declare const item_validator: (fn: ItemValidatorFunction, level?: ValidationIssueLevel) => ItemValidator;
export declare const ItemValidatorsWithProps: {
[name: string]: (props: any) => ItemValidator;
};
export declare const ItemValidators: {
[name: string]: ItemValidator;
};
export declare const answer_validator: (fn: AnswerValidatorFunction, level?: ValidationIssueLevel) => AnswerValidator;
export declare const AnswerValidators: {
[name: string]: AnswerValidator;
};
export declare const AnswerValidatorsWithProps: {
[name: string]: (props: any) => AnswerValidator;
};
export declare class Answer implements AnswerInterface {
readonly id: string;
readonly data_id?: string;
type: AnswerType;
default_content: any;
content_history: {
utc_time: string;
content: any;
source: ContentChangeSource;
}[];
validators: AnswerValidator[];
validation_issues: AnswerValidationIssue[];
own_validation_issues: AnswerValidationIssue[];
extra_answers: Answer[];
[key: string]: any;
constructor(props: AnswerProperties, id: string);
get raw_content(): any;
get content(): any;
set content(v: any);
reset_content(): void;
get content_changed(): boolean;
get selected_option(): Option | undefined;
check_validation(current_item: Item, state: Questionnaire, include_children?: boolean): AnswerValidationIssue[];
get last_answer_utc_time(): string | undefined;
to_row: (include_children?: boolean) => AnswerRow | AnswerRow[];
}
export declare class Option implements OptionInterface {
readonly id: string;
content: string | number | boolean;
extra_answers: Answer[];
[key: string]: any;
constructor(props: OptionProperties, id: string);
}
/**
* Props should be Answer, AnswerProperties, or arrays with those contents.
*/
export declare const as_answers: (props: AnswerLike | AnswerLike[], parent_id: string) => Answer[] | [];
/**
* Props should be Option, OptionProperties, or arrays with those contents.
*/
export declare const as_options: (props: OptionLike | OptionLike[], parent_id: string) => Option[] | [];
/**
* Props should be Item, ItemProperties, or arrays with those contents.
*/
export declare const as_items: (props: ItemLike | ItemLike[]) => Item[] | [];
export declare const get_type_name: (t: AnswerType) => string;