@dmptool/types 1.1.3 → 1.2.1
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/README.md +119 -47
- package/dist/answers/__tests__/answers.spec.js +27 -28
- package/dist/answers/__tests__/usage.spec.d.ts +1 -0
- package/dist/answers/__tests__/usage.spec.js +178 -0
- package/dist/answers/answer.d.ts +12 -15
- package/dist/answers/answer.js +3 -4
- package/dist/answers/dateAnswers.d.ts +30 -30
- package/dist/answers/dateAnswers.js +6 -5
- package/dist/answers/graphQLAnswers.d.ts +41 -26
- package/dist/answers/graphQLAnswers.js +7 -4
- package/dist/answers/index.d.ts +887 -1088
- package/dist/answers/index.js +2 -2
- package/dist/answers/numberAnswers.d.ts +41 -41
- package/dist/answers/numberAnswers.js +8 -8
- package/dist/answers/optionBasedAnswers.d.ts +55 -55
- package/dist/answers/optionBasedAnswers.js +10 -10
- package/dist/answers/tableAnswers.d.ts +880 -1778
- package/dist/answers/tableAnswers.js +12 -8
- package/dist/answers/textAnswers.d.ts +44 -44
- package/dist/answers/textAnswers.js +8 -8
- package/dist/questions/__tests__/graphQLQuestions.spec.js +1 -1
- package/dist/questions/__tests__/usage.spec.d.ts +8 -0
- package/dist/questions/__tests__/usage.spec.js +312 -0
- package/dist/questions/dateQuestions.d.ts +81 -82
- package/dist/questions/dateQuestions.js +12 -16
- package/dist/questions/graphQLQuestions.d.ts +142 -142
- package/dist/questions/graphQLQuestions.js +35 -30
- package/dist/questions/index.d.ts +1492 -1672
- package/dist/questions/index.js +2 -2
- package/dist/questions/numberQuestions.d.ts +97 -98
- package/dist/questions/numberQuestions.js +7 -19
- package/dist/questions/optionBasedQuestions.d.ts +163 -166
- package/dist/questions/optionBasedQuestions.js +20 -36
- package/dist/questions/question.d.ts +24 -48
- package/dist/questions/question.js +78 -17
- package/dist/questions/tableQuestions.d.ts +2215 -2227
- package/dist/questions/tableQuestions.js +6 -11
- package/dist/questions/textQuestions.d.ts +104 -104
- package/dist/questions/textQuestions.js +6 -23
- package/dist/schemas/affiliationSearchAnswer.schema.json +20 -12
- package/dist/schemas/affiliationSearchQuestion.schema.json +30 -36
- package/dist/schemas/anyAnswer.schema.json +235 -233
- package/dist/schemas/anyQuestion.schema.json +292 -493
- package/dist/schemas/anyTableColumnAnswer.schema.json +104 -106
- package/dist/schemas/anyTableColumnQuestion.schema.json +164 -325
- package/dist/schemas/booleanAnswer.schema.json +8 -11
- package/dist/schemas/booleanQuestion.schema.json +7 -10
- package/dist/schemas/checkboxesAnswer.schema.json +13 -14
- package/dist/schemas/checkboxesQuestion.schema.json +12 -13
- package/dist/schemas/currencyAnswer.schema.json +8 -11
- package/dist/schemas/currencyQuestion.schema.json +7 -10
- package/dist/schemas/dateAnswer.schema.json +8 -11
- package/dist/schemas/dateQuestion.schema.json +7 -10
- package/dist/schemas/dateRangeAnswer.schema.json +16 -21
- package/dist/schemas/dateRangeQuestion.schema.json +38 -20
- package/dist/schemas/emailAnswer.schema.json +8 -11
- package/dist/schemas/emailQuestion.schema.json +7 -10
- package/dist/schemas/multiselectBoxAnswer.schema.json +13 -14
- package/dist/schemas/multiselectBoxQuestion.schema.json +14 -14
- package/dist/schemas/numberAnswer.schema.json +8 -11
- package/dist/schemas/numberQuestion.schema.json +7 -10
- package/dist/schemas/numberRangeAnswer.schema.json +17 -22
- package/dist/schemas/numberRangeQuestion.schema.json +18 -19
- package/dist/schemas/radioButtonsAnswer.schema.json +8 -11
- package/dist/schemas/radioButtonsQuestion.schema.json +12 -13
- package/dist/schemas/selectBoxAnswer.schema.json +8 -11
- package/dist/schemas/selectBoxQuestion.schema.json +18 -15
- package/dist/schemas/tableAnswer.schema.json +343 -338
- package/dist/schemas/tableQuestion.schema.json +178 -352
- package/dist/schemas/textAnswer.schema.json +8 -11
- package/dist/schemas/textAreaAnswer.schema.json +8 -11
- package/dist/schemas/textAreaQuestion.schema.json +7 -10
- package/dist/schemas/textQuestion.schema.json +7 -10
- package/dist/schemas/urlAnswer.schema.json +8 -11
- package/dist/schemas/urlQuestion.schema.json +7 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,62 +4,61 @@ This package provides Types, Zod schemas and JSON schemas to aide in integration
|
|
|
4
4
|
|
|
5
5
|
[Zod](https://www.npmjs.com/package/zod) schemas and Typescript Types can be found in the `src/` directory and JSON schemas can be found in the `schemas/` directory.
|
|
6
6
|
|
|
7
|
-
## Available Schemas/Types
|
|
8
|
-
|
|
9
7
|
The current version of the schemas can always be found in `CURRENT_SCHEMA_VERSION`. You will need to include the version is any object you create using the types in this file.
|
|
10
8
|
|
|
11
9
|
Naming conventions:
|
|
12
10
|
- Zod schemas do not include the word `Type` (e.g. `BooleanQuestion`, `CheckboxesAnswer`)
|
|
13
11
|
- Types include the word `Type` (e.g. `BooleanQuestionType`, `CheckboxesAnswerType`)
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
## DMP Template Support
|
|
16
14
|
|
|
17
|
-
The `
|
|
15
|
+
The `QuestionFormatsEnum` contains a list of all the possible question types currently supported by the DMP Tool. These values correspond with the `type` property of a question type. For example, the `BooleanQuestion` has `type: 'boolean'` and the `SelectBoxQuestion` has `type: 'selectBoxes'`.
|
|
18
16
|
|
|
19
17
|
The available question schemas/types are:
|
|
20
18
|
- `AnyQuestion` A Union of all the question types
|
|
21
19
|
- `AnyTableColumnQuestion` A subset of `AnyQuestion`. All of the question types that can be part of a table
|
|
20
|
+
- `AffiliationSearch` A typeahead style field that allows the user to search for affiliations.
|
|
22
21
|
- `BooleanQuestion` A Yes/No True/False question.
|
|
23
22
|
- `CheckboxesQuestion` A question type that supports an array of `option` objects. The user may "check" multiple options.
|
|
24
23
|
- `CurrencyQuestion` A number field that supports the defintiion of a `denomination`.
|
|
25
24
|
- `DateQuestion` A date field. Supports `YYYY-MM-DD` format.
|
|
26
25
|
- `DateRangeQuestion` A series of 2 date fields. Meant to capture "From" and "To" or "Start" and "End" dates.
|
|
27
26
|
- `EmailQuestion` An email address. Supports multiple emails that are comma separated.
|
|
28
|
-
- `
|
|
27
|
+
- `MultiselectBoxQuestion` A select box that allows for multiple selections
|
|
29
28
|
- `NumberQuestion` A numeric field. Supports both integers and floats.
|
|
30
29
|
- `NumberRangeQuestion` A series of 2 number fields. Meant to capture "From" and "To" or "Min" and "Max" numbers.
|
|
31
30
|
- `RadioButtonsQuestion` A question type that supports an array of `option` objects. The user may "select" a single option.
|
|
32
31
|
- `SelectBoxQuestion` A drop down select box that supports an array of `option` objects. A `multiple` flag can be set to allow multi-select.
|
|
33
32
|
- `TableQuestion` A table question type. Each column in the table can be any one of the `AnyTableColumnQuestion` types.
|
|
34
|
-
- `TextAreaQuestion` A text area field. If the `isRichText` flag is set, the user should see a WYSIWYG editor.
|
|
35
33
|
- `TextQuestion` A simple text field
|
|
36
|
-
- `
|
|
34
|
+
- `TextAreaQuestion` A text area field. If the `isRichText` flag is set, the user should see a WYSIWYG editor.
|
|
37
35
|
- `URLQuestion` A simple URL field.
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
## DMP Support
|
|
40
38
|
|
|
41
39
|
Each of the question types above has a corresponding answer. The `type` in each answer type must match the `type` of the related question. For example `BooleanAnswer` has `type: 'boolean'` and and the `SelectBoxAnswer` has `type: 'checkboxes'`.
|
|
42
40
|
|
|
43
41
|
The available answer schemas/types are:
|
|
44
42
|
- `AnyAnswer` A Union of all the answer types
|
|
45
43
|
- `AnyTableColumnAnswer` A subset of `AnyAnswer`. All of the answer types that can be part of a table
|
|
44
|
+
- `AffiliationSearch` The URI of the selected affiliation.
|
|
46
45
|
- `BooleanAnswer` A Yes/No True/False answer.
|
|
47
46
|
- `CheckboxesAnswer` A answer type that supports an array of `option` objects. The user may "check" multiple options.
|
|
48
47
|
- `CurrencyAnswer` A number field that supports the defintiion of a `denomination`.
|
|
49
48
|
- `DateAnswer` A date field. Supports `YYYY-MM-DD` format.
|
|
50
49
|
- `DateRangeAnswer` A series of 2 date fields. Meant to capture "From" and "To" or "Start" and "End" dates.
|
|
51
50
|
- `EmailAnswer` An email address. Supports multiple emails that are comma separated.
|
|
52
|
-
- `
|
|
51
|
+
- `MultiselectAnswer` An array of `option` objects each containing the value of a selected entry.
|
|
53
52
|
- `NumberAnswer` A numeric field. Supports both integers and floats.
|
|
53
|
+
- `DateRangeAnswer` A series of 2 numbers. Meant to capture "From" and "To" or "Start" and "End".
|
|
54
54
|
- `RadioButtonsAnswer` A answer type that supports an array of `option` objects. The user may "select" a single option.
|
|
55
|
-
- `SelectBoxAnswer`
|
|
55
|
+
- `SelectBoxAnswer` The value the user selected.
|
|
56
56
|
- `TableAnswer` A table answer type. Each column in the table can be any one of the `AnyTableColumnAnswer` types.
|
|
57
|
-
- `TextAreaAnswer` A text area field. If the `isRichText` flag is set, the user should see a WYSIWYG editor.
|
|
58
57
|
- `TextAnswer` A simple text field
|
|
59
|
-
- `
|
|
58
|
+
- `TextAreaAnswer` A text area field. If the `isRichText` flag is set, the user should see a WYSIWYG editor.
|
|
60
59
|
- `URLAnswer` A simple URL field.
|
|
61
60
|
|
|
62
|
-
|
|
61
|
+
### Coming soon
|
|
63
62
|
|
|
64
63
|
RDA Common Standard for DMPs
|
|
65
64
|
|
|
@@ -69,50 +68,123 @@ DMP Tool specific extensions to the RDA Common Standard for DMPs
|
|
|
69
68
|
|
|
70
69
|
Add the DMP Tool types to your `package.json` by running `npm add @dmptool/types`
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
Use the provided enum for the list of available question/answer formats.
|
|
72
|
+
```
|
|
73
|
+
import { QuestionFormatsEnum } from "../question";
|
|
74
|
+
|
|
75
|
+
// Display all of the available Question formats
|
|
76
|
+
console.log(Object.values(QuestionFormatsEnum));
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Fetch the usage information for a given question format. This can be used to present your users determine which question format to use:
|
|
80
|
+
```
|
|
81
|
+
import {
|
|
82
|
+
QuestionFormatsEnum,
|
|
83
|
+
QuestionFormatsUsage,
|
|
84
|
+
QuestionFormatsUsageInterface
|
|
85
|
+
} from "@dmptool/types";
|
|
86
|
+
|
|
87
|
+
// Infer the Types for all of the question formats
|
|
88
|
+
type QuestionType = z.infer<typeof QuestionFormatsEnum>
|
|
89
|
+
|
|
90
|
+
// List all of the usage information for each question format
|
|
91
|
+
// e.g. {
|
|
92
|
+
// title: 'Text Field',
|
|
93
|
+
// usageDecription: 'For questions that require short, simple answers.'
|
|
94
|
+
// }
|
|
95
|
+
const name: 'text';
|
|
96
|
+
const usage: QuestionFormatsUsageInterface = QuestionFormatsUsage[name as QuestionType];
|
|
97
|
+
|
|
98
|
+
console.log(usage);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Validate a question's JSON
|
|
102
|
+
```
|
|
103
|
+
import { QuestionSchemaMap } from "@dmptool/types";
|
|
74
104
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
type: "boolean",
|
|
105
|
+
const json = {
|
|
106
|
+
type: 'email',
|
|
78
107
|
attributes: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
checked: true
|
|
108
|
+
maxLength: 2000,
|
|
109
|
+
multiple: true
|
|
82
110
|
},
|
|
83
111
|
meta: {
|
|
84
|
-
|
|
112
|
+
echemaVersion: '1.0'
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// First verify that the question format (`type`) is a known format.
|
|
117
|
+
if (Object.keys(QuestionSchemaMap).includes(json['type'])) {
|
|
118
|
+
// Validate the json against the Zod schema and if valid, set the questionType
|
|
119
|
+
try {
|
|
120
|
+
const result = QuestionSchemaMap[json['type']]?.safeParse(json);
|
|
121
|
+
if (result && !result.success) {
|
|
122
|
+
// If there are validation errors, add them to the errors object
|
|
123
|
+
console.log(result.error.errors);
|
|
124
|
+
}
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.log(e.message);
|
|
85
127
|
}
|
|
86
128
|
}
|
|
129
|
+
```
|
|
87
130
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
131
|
+
Fetch the default JSON for a given question format:
|
|
132
|
+
```
|
|
133
|
+
import {
|
|
134
|
+
AnyQuestionType,
|
|
135
|
+
QuestionFormatsEnum,
|
|
136
|
+
QuestionSchemaMap,
|
|
137
|
+
} from "@dmptool/types";
|
|
138
|
+
|
|
139
|
+
// Infer the Types for all of the question formats
|
|
140
|
+
type QuestionType = z.infer<typeof QuestionFormatsEnum>
|
|
141
|
+
|
|
142
|
+
// Fetch the Zod schema for the question format and then parse it with
|
|
143
|
+
// only the question format type as an input
|
|
144
|
+
// e.g. {
|
|
145
|
+
// type: 'text',
|
|
146
|
+
// attributes: {
|
|
147
|
+
// maxLength: 255,
|
|
148
|
+
// },
|
|
149
|
+
// meta: {
|
|
150
|
+
// schemaVersion: CURRENT_SCHEMA_VERSION
|
|
151
|
+
// },
|
|
152
|
+
// }
|
|
153
|
+
const name: 'text';
|
|
154
|
+
const schema: z.ZodTypeAny = QuestionSchemaMap[name as QuestionType];
|
|
155
|
+
const parsedSchema: AnyQuestionType = schema.parse({ type: name });
|
|
156
|
+
|
|
157
|
+
console.log(parsedSchema);
|
|
112
158
|
```
|
|
113
159
|
|
|
160
|
+
Fetch the default JSON for a given answer format:
|
|
161
|
+
```
|
|
162
|
+
import {
|
|
163
|
+
AnyAnswerType,
|
|
164
|
+
AnswerSchemaMap,
|
|
165
|
+
QuestionFormatsEnum,
|
|
166
|
+
} from "@dmptool/types";
|
|
167
|
+
|
|
168
|
+
// Infer the Types for all of the question formats
|
|
169
|
+
type AnswerType = z.infer<typeof QuestionFormatsEnum>
|
|
170
|
+
|
|
171
|
+
// Fetch the Zod schema for the question format and then parse it with
|
|
172
|
+
// only the question format type as an input
|
|
173
|
+
// e.g. {
|
|
174
|
+
// type: 'text',
|
|
175
|
+
// answer: '',
|
|
176
|
+
// meta: {
|
|
177
|
+
// schemaVersion: CURRENT_SCHEMA_VERSION
|
|
178
|
+
// },
|
|
179
|
+
// }
|
|
180
|
+
const name: 'text';
|
|
181
|
+
const schema: z.ZodTypeAny = AnswerSchemaMap[name as AnswerType];
|
|
182
|
+
const parsedSchema: AnyAnswerType = schema.parse({ type: name });
|
|
183
|
+
|
|
184
|
+
console.log(parsedSchema);
|
|
185
|
+
```
|
|
114
186
|
|
|
115
|
-
Example Zod error:
|
|
187
|
+
Example Zod error thrown while parsing:
|
|
116
188
|
```
|
|
117
189
|
ZodError: [
|
|
118
190
|
{
|
|
@@ -111,10 +111,17 @@ const questions_1 = require("../../questions");
|
|
|
111
111
|
(0, globals_1.expect)(() => textAnswers_1.TextAreaAnswerSchema.parse(invalidData)).toThrow();
|
|
112
112
|
});
|
|
113
113
|
(0, globals_1.it)('should validate AffiliationSearchAnswer', () => {
|
|
114
|
-
const validData = {
|
|
114
|
+
const validData = {
|
|
115
|
+
type: 'affiliationSearch',
|
|
116
|
+
answer: {
|
|
117
|
+
affiliationId: '12345',
|
|
118
|
+
affilationName: 'Search term'
|
|
119
|
+
},
|
|
120
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
121
|
+
};
|
|
115
122
|
(0, globals_1.expect)(() => graphQLAnswers_1.AffiliationSearchAnswerSchema.parse(validData)).not.toThrow();
|
|
116
|
-
const invalidData = { type: '
|
|
117
|
-
(0, globals_1.expect)(() =>
|
|
123
|
+
const invalidData = { type: 'affiliationSearch', answer: 12345, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
124
|
+
(0, globals_1.expect)(() => graphQLAnswers_1.AffiliationSearchAnswerSchema.parse(invalidData)).toThrow();
|
|
118
125
|
});
|
|
119
126
|
(0, globals_1.it)('should validate URLAnswer', () => {
|
|
120
127
|
const validData = { type: 'url', answer: 'https://example.com', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
@@ -125,44 +132,36 @@ const questions_1 = require("../../questions");
|
|
|
125
132
|
(0, globals_1.it)('should validate TableAnswer', () => {
|
|
126
133
|
const validData = {
|
|
127
134
|
type: 'table',
|
|
135
|
+
columnHeadings: [
|
|
136
|
+
'Name',
|
|
137
|
+
'Age',
|
|
138
|
+
],
|
|
128
139
|
answer: [
|
|
129
140
|
{
|
|
130
141
|
columns: [
|
|
131
142
|
{
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
answer: 'Leia Organa',
|
|
136
|
-
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
137
|
-
}
|
|
143
|
+
type: 'text',
|
|
144
|
+
answer: 'Leia Organa',
|
|
145
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
138
146
|
},
|
|
139
147
|
{
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
145
|
-
}
|
|
146
|
-
}
|
|
148
|
+
type: 'number',
|
|
149
|
+
answer: 28,
|
|
150
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
151
|
+
},
|
|
147
152
|
]
|
|
148
153
|
},
|
|
149
154
|
{
|
|
150
155
|
columns: [
|
|
151
156
|
{
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
answer: 'Han Solo',
|
|
156
|
-
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
157
|
-
}
|
|
157
|
+
type: 'text',
|
|
158
|
+
answer: 'Han Solo',
|
|
159
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
158
160
|
},
|
|
159
161
|
{
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
answer: 35,
|
|
164
|
-
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
165
|
-
}
|
|
162
|
+
type: 'number',
|
|
163
|
+
answer: 35,
|
|
164
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
166
165
|
}
|
|
167
166
|
]
|
|
168
167
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const questions_1 = require("../../questions");
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
// Parse the Zod schema with no input to generate the default JSON schemas
|
|
6
|
+
function defaultJSON(name) {
|
|
7
|
+
if (name in index_1.AnswerSchemaMap) {
|
|
8
|
+
const schema = index_1.AnswerSchemaMap[name];
|
|
9
|
+
return schema.parse({ type: name });
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
describe('Get question answer defaultJSON', () => {
|
|
16
|
+
it('for affiliationSearch question format', () => {
|
|
17
|
+
const json = defaultJSON('affiliationSearch');
|
|
18
|
+
const expectedJSON = {
|
|
19
|
+
type: 'affiliationSearch',
|
|
20
|
+
answer: {
|
|
21
|
+
affiliationId: '',
|
|
22
|
+
affiliationName: '',
|
|
23
|
+
},
|
|
24
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
25
|
+
};
|
|
26
|
+
expect(json).toEqual(expectedJSON);
|
|
27
|
+
});
|
|
28
|
+
it('for boolean question format', () => {
|
|
29
|
+
const json = defaultJSON('boolean');
|
|
30
|
+
const expectedJSON = {
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
answer: false,
|
|
33
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
34
|
+
};
|
|
35
|
+
expect(json).toEqual(expectedJSON);
|
|
36
|
+
});
|
|
37
|
+
it('for checkBoxes question format', () => {
|
|
38
|
+
const json = defaultJSON('checkBoxes');
|
|
39
|
+
const expectedJSON = {
|
|
40
|
+
type: 'checkBoxes',
|
|
41
|
+
answer: [''],
|
|
42
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
43
|
+
};
|
|
44
|
+
expect(json).toEqual(expectedJSON);
|
|
45
|
+
});
|
|
46
|
+
it('for currency question format', () => {
|
|
47
|
+
const json = defaultJSON('currency');
|
|
48
|
+
const expectedJSON = {
|
|
49
|
+
type: 'currency',
|
|
50
|
+
answer: 0,
|
|
51
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
52
|
+
};
|
|
53
|
+
expect(json).toEqual(expectedJSON);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
it('for date question format', () => {
|
|
57
|
+
const json = defaultJSON('date');
|
|
58
|
+
const expectedJSON = {
|
|
59
|
+
type: 'date',
|
|
60
|
+
answer: '',
|
|
61
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
62
|
+
};
|
|
63
|
+
expect(json).toEqual(expectedJSON);
|
|
64
|
+
});
|
|
65
|
+
it('for dateRange question format', () => {
|
|
66
|
+
const json = defaultJSON('dateRange');
|
|
67
|
+
const expectedJSON = {
|
|
68
|
+
type: 'dateRange',
|
|
69
|
+
answer: {
|
|
70
|
+
start: '',
|
|
71
|
+
end: '',
|
|
72
|
+
},
|
|
73
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
74
|
+
};
|
|
75
|
+
expect(json).toEqual(expectedJSON);
|
|
76
|
+
});
|
|
77
|
+
it('for email question format', () => {
|
|
78
|
+
const json = defaultJSON('email');
|
|
79
|
+
const expectedJSON = {
|
|
80
|
+
type: 'email',
|
|
81
|
+
answer: '',
|
|
82
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
83
|
+
};
|
|
84
|
+
expect(json).toEqual(expectedJSON);
|
|
85
|
+
});
|
|
86
|
+
it('for multiselectBox question format', () => {
|
|
87
|
+
const json = defaultJSON('multiselectBox');
|
|
88
|
+
const expectedJSON = {
|
|
89
|
+
type: 'multiselectBox',
|
|
90
|
+
answer: [''],
|
|
91
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
92
|
+
};
|
|
93
|
+
expect(json).toEqual(expectedJSON);
|
|
94
|
+
});
|
|
95
|
+
it('for number question format', () => {
|
|
96
|
+
const json = defaultJSON('number');
|
|
97
|
+
const expectedJSON = {
|
|
98
|
+
type: 'number',
|
|
99
|
+
answer: 0,
|
|
100
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
101
|
+
};
|
|
102
|
+
expect(json).toEqual(expectedJSON);
|
|
103
|
+
});
|
|
104
|
+
it('for numberRange format', () => {
|
|
105
|
+
const json = defaultJSON('numberRange');
|
|
106
|
+
const expectedJSON = {
|
|
107
|
+
type: 'numberRange',
|
|
108
|
+
answer: {
|
|
109
|
+
start: 0,
|
|
110
|
+
end: 0,
|
|
111
|
+
},
|
|
112
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
113
|
+
};
|
|
114
|
+
expect(json).toEqual(expectedJSON);
|
|
115
|
+
});
|
|
116
|
+
it('for radioButtons question format', () => {
|
|
117
|
+
const json = defaultJSON('radioButtons');
|
|
118
|
+
const expectedJSON = {
|
|
119
|
+
type: 'radioButtons',
|
|
120
|
+
answer: '',
|
|
121
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
122
|
+
};
|
|
123
|
+
expect(json).toEqual(expectedJSON);
|
|
124
|
+
});
|
|
125
|
+
it('for selectBox question format', () => {
|
|
126
|
+
const json = defaultJSON('selectBox');
|
|
127
|
+
const expectedJSON = {
|
|
128
|
+
type: 'selectBox',
|
|
129
|
+
answer: '',
|
|
130
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
131
|
+
};
|
|
132
|
+
expect(json).toEqual(expectedJSON);
|
|
133
|
+
});
|
|
134
|
+
it('for table question format', () => {
|
|
135
|
+
const json = defaultJSON('table');
|
|
136
|
+
const expectedJSON = {
|
|
137
|
+
type: 'table',
|
|
138
|
+
columnHeadings: [
|
|
139
|
+
'Column A',
|
|
140
|
+
],
|
|
141
|
+
answer: [{
|
|
142
|
+
columns: [{
|
|
143
|
+
type: 'textArea',
|
|
144
|
+
answer: '',
|
|
145
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
146
|
+
}],
|
|
147
|
+
}],
|
|
148
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
149
|
+
};
|
|
150
|
+
expect(json).toEqual(expectedJSON);
|
|
151
|
+
});
|
|
152
|
+
it('for text question format', () => {
|
|
153
|
+
const json = defaultJSON('text');
|
|
154
|
+
const expectedJSON = {
|
|
155
|
+
type: 'text',
|
|
156
|
+
answer: '',
|
|
157
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
158
|
+
};
|
|
159
|
+
expect(json).toEqual(expectedJSON);
|
|
160
|
+
});
|
|
161
|
+
it('for textArea question format', () => {
|
|
162
|
+
const json = defaultJSON('textArea');
|
|
163
|
+
const expectedJSON = {
|
|
164
|
+
type: 'textArea',
|
|
165
|
+
answer: '',
|
|
166
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
167
|
+
};
|
|
168
|
+
expect(json).toEqual(expectedJSON);
|
|
169
|
+
});
|
|
170
|
+
it('for url question format', () => {
|
|
171
|
+
const json = defaultJSON('url');
|
|
172
|
+
const expectedJSON = {
|
|
173
|
+
type: 'url',
|
|
174
|
+
answer: '',
|
|
175
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
176
|
+
};
|
|
177
|
+
expect(json).toEqual(expectedJSON);
|
|
178
|
+
});
|
package/dist/answers/answer.d.ts
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const AnswerSchema: z.ZodObject<{
|
|
3
|
-
type: z.ZodEnum<["affiliationSearch", "boolean", "checkBoxes", "currency", "date", "dateRange", "email", "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
schemaVersion: z.ZodLiteral<"1.0">;
|
|
3
|
+
type: z.ZodEnum<["affiliationSearch", "boolean", "checkBoxes", "currency", "date", "dateRange", "email", "multiselectBox", "number", "numberRange", "radioButtons", "selectBox", "table", "text", "textArea", "url"]>;
|
|
4
|
+
meta: z.ZodDefault<z.ZodObject<{
|
|
5
|
+
schemaVersion: z.ZodDefault<z.ZodString>;
|
|
7
6
|
}, "strip", z.ZodTypeAny, {
|
|
8
|
-
schemaVersion:
|
|
7
|
+
schemaVersion: string;
|
|
9
8
|
}, {
|
|
10
|
-
schemaVersion
|
|
11
|
-
}
|
|
9
|
+
schemaVersion?: string | undefined;
|
|
10
|
+
}>>;
|
|
12
11
|
}, "strip", z.ZodTypeAny, {
|
|
13
|
-
type: "number" | "boolean" | "affiliationSearch" | "checkBoxes" | "currency" | "date" | "dateRange" | "email" | "
|
|
12
|
+
type: "number" | "boolean" | "affiliationSearch" | "checkBoxes" | "currency" | "date" | "dateRange" | "email" | "multiselectBox" | "numberRange" | "radioButtons" | "selectBox" | "table" | "text" | "textArea" | "url";
|
|
14
13
|
meta: {
|
|
15
|
-
schemaVersion:
|
|
14
|
+
schemaVersion: string;
|
|
16
15
|
};
|
|
17
|
-
answer: string;
|
|
18
16
|
}, {
|
|
19
|
-
type: "number" | "boolean" | "affiliationSearch" | "checkBoxes" | "currency" | "date" | "dateRange" | "email" | "
|
|
20
|
-
meta
|
|
21
|
-
schemaVersion
|
|
22
|
-
};
|
|
23
|
-
answer: string;
|
|
17
|
+
type: "number" | "boolean" | "affiliationSearch" | "checkBoxes" | "currency" | "date" | "dateRange" | "email" | "multiselectBox" | "numberRange" | "radioButtons" | "selectBox" | "table" | "text" | "textArea" | "url";
|
|
18
|
+
meta?: {
|
|
19
|
+
schemaVersion?: string | undefined;
|
|
20
|
+
} | undefined;
|
|
24
21
|
}>;
|
|
25
22
|
export type AnswerType = z.infer<typeof AnswerSchema>;
|
package/dist/answers/answer.js
CHANGED
|
@@ -5,9 +5,8 @@ const zod_1 = require("zod");
|
|
|
5
5
|
const question_1 = require("../questions/question");
|
|
6
6
|
// Abstract base schema for all answers
|
|
7
7
|
exports.AnswerSchema = zod_1.z.object({
|
|
8
|
-
type: question_1.
|
|
9
|
-
answer: zod_1.z.string(), // The answer to the question (string)
|
|
8
|
+
type: question_1.QuestionFormatsEnum, // The type of answer
|
|
10
9
|
meta: zod_1.z.object({
|
|
11
|
-
schemaVersion: zod_1.z.
|
|
12
|
-
})
|
|
10
|
+
schemaVersion: zod_1.z.string().default(question_1.CURRENT_SCHEMA_VERSION), // The schema version of the answer
|
|
11
|
+
}).default({})
|
|
13
12
|
});
|
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const DateAnswerSchema: z.ZodObject<{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
schemaVersion: z.ZodLiteral<"1.0">;
|
|
3
|
+
meta: z.ZodDefault<z.ZodObject<{
|
|
4
|
+
schemaVersion: z.ZodDefault<z.ZodString>;
|
|
6
5
|
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
schemaVersion:
|
|
6
|
+
schemaVersion: string;
|
|
8
7
|
}, {
|
|
9
|
-
schemaVersion
|
|
10
|
-
}
|
|
8
|
+
schemaVersion?: string | undefined;
|
|
9
|
+
}>>;
|
|
11
10
|
} & {
|
|
12
11
|
type: z.ZodLiteral<"date">;
|
|
12
|
+
answer: z.ZodDefault<z.ZodString>;
|
|
13
13
|
}, "strip", z.ZodTypeAny, {
|
|
14
14
|
type: "date";
|
|
15
15
|
meta: {
|
|
16
|
-
schemaVersion:
|
|
16
|
+
schemaVersion: string;
|
|
17
17
|
};
|
|
18
18
|
answer: string;
|
|
19
19
|
}, {
|
|
20
20
|
type: "date";
|
|
21
|
-
meta
|
|
22
|
-
schemaVersion
|
|
23
|
-
};
|
|
24
|
-
answer
|
|
21
|
+
meta?: {
|
|
22
|
+
schemaVersion?: string | undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
answer?: string | undefined;
|
|
25
25
|
}>;
|
|
26
26
|
export declare const DateRangeAnswerSchema: z.ZodObject<{
|
|
27
|
-
meta: z.ZodObject<{
|
|
28
|
-
schemaVersion: z.
|
|
27
|
+
meta: z.ZodDefault<z.ZodObject<{
|
|
28
|
+
schemaVersion: z.ZodDefault<z.ZodString>;
|
|
29
29
|
}, "strip", z.ZodTypeAny, {
|
|
30
|
-
schemaVersion:
|
|
30
|
+
schemaVersion: string;
|
|
31
31
|
}, {
|
|
32
|
-
schemaVersion
|
|
33
|
-
}
|
|
32
|
+
schemaVersion?: string | undefined;
|
|
33
|
+
}>>;
|
|
34
34
|
} & {
|
|
35
35
|
type: z.ZodLiteral<"dateRange">;
|
|
36
|
-
answer: z.ZodObject<{
|
|
37
|
-
start: z.ZodString
|
|
38
|
-
end: z.ZodString
|
|
36
|
+
answer: z.ZodDefault<z.ZodObject<{
|
|
37
|
+
start: z.ZodDefault<z.ZodString>;
|
|
38
|
+
end: z.ZodDefault<z.ZodString>;
|
|
39
39
|
}, "strip", z.ZodTypeAny, {
|
|
40
40
|
start: string;
|
|
41
41
|
end: string;
|
|
42
42
|
}, {
|
|
43
|
-
start
|
|
44
|
-
end
|
|
45
|
-
}
|
|
43
|
+
start?: string | undefined;
|
|
44
|
+
end?: string | undefined;
|
|
45
|
+
}>>;
|
|
46
46
|
}, "strip", z.ZodTypeAny, {
|
|
47
47
|
type: "dateRange";
|
|
48
48
|
meta: {
|
|
49
|
-
schemaVersion:
|
|
49
|
+
schemaVersion: string;
|
|
50
50
|
};
|
|
51
51
|
answer: {
|
|
52
52
|
start: string;
|
|
@@ -54,13 +54,13 @@ export declare const DateRangeAnswerSchema: z.ZodObject<{
|
|
|
54
54
|
};
|
|
55
55
|
}, {
|
|
56
56
|
type: "dateRange";
|
|
57
|
-
meta
|
|
58
|
-
schemaVersion
|
|
59
|
-
};
|
|
60
|
-
answer
|
|
61
|
-
start
|
|
62
|
-
end
|
|
63
|
-
};
|
|
57
|
+
meta?: {
|
|
58
|
+
schemaVersion?: string | undefined;
|
|
59
|
+
} | undefined;
|
|
60
|
+
answer?: {
|
|
61
|
+
start?: string | undefined;
|
|
62
|
+
end?: string | undefined;
|
|
63
|
+
} | undefined;
|
|
64
64
|
}>;
|
|
65
65
|
export type DateAnswerType = z.infer<typeof DateAnswerSchema>;
|
|
66
66
|
export type DateRangeAnswerType = z.infer<typeof DateRangeAnswerSchema>;
|