@dmptool/types 1.1.2 → 1.2.0
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 +20 -28
- package/dist/answers/__tests__/usage.spec.d.ts +1 -0
- package/dist/answers/__tests__/usage.spec.js +175 -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 +25 -25
- package/dist/answers/graphQLAnswers.js +4 -4
- package/dist/answers/index.d.ts +860 -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 +811 -1772
- 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 +6 -4
- package/dist/questions/__tests__/optionBasedQuestions.spec.js +4 -12
- 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 +90 -101
- package/dist/questions/dateQuestions.js +15 -34
- package/dist/questions/graphQLQuestions.d.ts +176 -182
- package/dist/questions/graphQLQuestions.js +44 -45
- package/dist/questions/index.d.ts +1791 -2170
- package/dist/questions/index.js +2 -2
- package/dist/questions/numberQuestions.d.ts +126 -142
- package/dist/questions/numberQuestions.js +11 -45
- package/dist/questions/optionBasedQuestions.d.ts +197 -225
- package/dist/questions/optionBasedQuestions.js +24 -88
- package/dist/questions/question.d.ts +24 -56
- package/dist/questions/question.js +78 -18
- package/dist/questions/tableQuestions.d.ts +2637 -2930
- package/dist/questions/tableQuestions.js +9 -21
- package/dist/questions/textQuestions.d.ts +125 -145
- package/dist/questions/textQuestions.js +16 -57
- package/dist/schemas/affiliationSearchAnswer.schema.json +9 -12
- package/dist/schemas/affiliationSearchQuestion.schema.json +57 -50
- package/dist/schemas/anyAnswer.schema.json +228 -237
- package/dist/schemas/anyQuestion.schema.json +349 -517
- package/dist/schemas/anyTableColumnAnswer.schema.json +93 -106
- package/dist/schemas/anyTableColumnQuestion.schema.json +259 -382
- package/dist/schemas/booleanAnswer.schema.json +8 -11
- package/dist/schemas/booleanQuestion.schema.json +9 -15
- package/dist/schemas/checkboxesAnswer.schema.json +13 -14
- package/dist/schemas/checkboxesQuestion.schema.json +18 -24
- package/dist/schemas/currencyAnswer.schema.json +8 -11
- package/dist/schemas/currencyQuestion.schema.json +13 -17
- package/dist/schemas/dateAnswer.schema.json +8 -11
- package/dist/schemas/dateQuestion.schema.json +9 -15
- package/dist/schemas/dateRangeAnswer.schema.json +16 -21
- package/dist/schemas/dateRangeQuestion.schema.json +40 -21
- package/dist/schemas/emailAnswer.schema.json +8 -11
- package/dist/schemas/emailQuestion.schema.json +11 -16
- package/dist/schemas/filteredSearchQuestion.schema.json +0 -3
- package/dist/schemas/multiselectBoxAnswer.schema.json +13 -14
- package/dist/schemas/multiselectBoxQuestion.schema.json +20 -25
- package/dist/schemas/numberAnswer.schema.json +8 -11
- package/dist/schemas/numberQuestion.schema.json +11 -16
- package/dist/schemas/numberRangeAnswer.schema.json +17 -22
- package/dist/schemas/numberRangeQuestion.schema.json +22 -21
- package/dist/schemas/radioButtonsAnswer.schema.json +8 -11
- package/dist/schemas/radioButtonsQuestion.schema.json +18 -24
- package/dist/schemas/selectBoxAnswer.schema.json +8 -11
- package/dist/schemas/selectBoxQuestion.schema.json +20 -25
- package/dist/schemas/tableAnswer.schema.json +337 -343
- package/dist/schemas/tableQuestion.schema.json +279 -416
- package/dist/schemas/textAnswer.schema.json +8 -11
- package/dist/schemas/textAreaAnswer.schema.json +8 -11
- package/dist/schemas/textAreaQuestion.schema.json +13 -17
- package/dist/schemas/textQuestion.schema.json +9 -15
- package/dist/schemas/urlAnswer.schema.json +8 -11
- package/dist/schemas/urlQuestion.schema.json +9 -15
- 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,10 @@ 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 = { type: '
|
|
114
|
+
const validData = { type: 'affiliationSearch', answer: 'Search term', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
115
115
|
(0, globals_1.expect)(() => graphQLAnswers_1.AffiliationSearchAnswerSchema.parse(validData)).not.toThrow();
|
|
116
|
-
const invalidData = { type: '
|
|
117
|
-
(0, globals_1.expect)(() =>
|
|
116
|
+
const invalidData = { type: 'affiliationSearch', answer: 12345, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
117
|
+
(0, globals_1.expect)(() => graphQLAnswers_1.AffiliationSearchAnswerSchema.parse(invalidData)).toThrow();
|
|
118
118
|
});
|
|
119
119
|
(0, globals_1.it)('should validate URLAnswer', () => {
|
|
120
120
|
const validData = { type: 'url', answer: 'https://example.com', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
@@ -125,44 +125,36 @@ const questions_1 = require("../../questions");
|
|
|
125
125
|
(0, globals_1.it)('should validate TableAnswer', () => {
|
|
126
126
|
const validData = {
|
|
127
127
|
type: 'table',
|
|
128
|
+
columnHeadings: [
|
|
129
|
+
'Name',
|
|
130
|
+
'Age',
|
|
131
|
+
],
|
|
128
132
|
answer: [
|
|
129
133
|
{
|
|
130
134
|
columns: [
|
|
131
135
|
{
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
answer: 'Leia Organa',
|
|
136
|
-
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
137
|
-
}
|
|
136
|
+
type: 'text',
|
|
137
|
+
answer: 'Leia Organa',
|
|
138
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
138
139
|
},
|
|
139
140
|
{
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
145
|
-
}
|
|
146
|
-
}
|
|
141
|
+
type: 'number',
|
|
142
|
+
answer: 28,
|
|
143
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
144
|
+
},
|
|
147
145
|
]
|
|
148
146
|
},
|
|
149
147
|
{
|
|
150
148
|
columns: [
|
|
151
149
|
{
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
answer: 'Han Solo',
|
|
156
|
-
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
157
|
-
}
|
|
150
|
+
type: 'text',
|
|
151
|
+
answer: 'Han Solo',
|
|
152
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
158
153
|
},
|
|
159
154
|
{
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
answer: 35,
|
|
164
|
-
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
165
|
-
}
|
|
155
|
+
type: 'number',
|
|
156
|
+
answer: 35,
|
|
157
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
166
158
|
}
|
|
167
159
|
]
|
|
168
160
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,175 @@
|
|
|
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
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
22
|
+
};
|
|
23
|
+
expect(json).toEqual(expectedJSON);
|
|
24
|
+
});
|
|
25
|
+
it('for boolean question format', () => {
|
|
26
|
+
const json = defaultJSON('boolean');
|
|
27
|
+
const expectedJSON = {
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
answer: false,
|
|
30
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
31
|
+
};
|
|
32
|
+
expect(json).toEqual(expectedJSON);
|
|
33
|
+
});
|
|
34
|
+
it('for checkBoxes question format', () => {
|
|
35
|
+
const json = defaultJSON('checkBoxes');
|
|
36
|
+
const expectedJSON = {
|
|
37
|
+
type: 'checkBoxes',
|
|
38
|
+
answer: [''],
|
|
39
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
40
|
+
};
|
|
41
|
+
expect(json).toEqual(expectedJSON);
|
|
42
|
+
});
|
|
43
|
+
it('for currency question format', () => {
|
|
44
|
+
const json = defaultJSON('currency');
|
|
45
|
+
const expectedJSON = {
|
|
46
|
+
type: 'currency',
|
|
47
|
+
answer: 0,
|
|
48
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
49
|
+
};
|
|
50
|
+
expect(json).toEqual(expectedJSON);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it('for date question format', () => {
|
|
54
|
+
const json = defaultJSON('date');
|
|
55
|
+
const expectedJSON = {
|
|
56
|
+
type: 'date',
|
|
57
|
+
answer: '',
|
|
58
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
59
|
+
};
|
|
60
|
+
expect(json).toEqual(expectedJSON);
|
|
61
|
+
});
|
|
62
|
+
it('for dateRange question format', () => {
|
|
63
|
+
const json = defaultJSON('dateRange');
|
|
64
|
+
const expectedJSON = {
|
|
65
|
+
type: 'dateRange',
|
|
66
|
+
answer: {
|
|
67
|
+
start: '',
|
|
68
|
+
end: '',
|
|
69
|
+
},
|
|
70
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
71
|
+
};
|
|
72
|
+
expect(json).toEqual(expectedJSON);
|
|
73
|
+
});
|
|
74
|
+
it('for email question format', () => {
|
|
75
|
+
const json = defaultJSON('email');
|
|
76
|
+
const expectedJSON = {
|
|
77
|
+
type: 'email',
|
|
78
|
+
answer: '',
|
|
79
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
80
|
+
};
|
|
81
|
+
expect(json).toEqual(expectedJSON);
|
|
82
|
+
});
|
|
83
|
+
it('for multiselectBox question format', () => {
|
|
84
|
+
const json = defaultJSON('multiselectBox');
|
|
85
|
+
const expectedJSON = {
|
|
86
|
+
type: 'multiselectBox',
|
|
87
|
+
answer: [''],
|
|
88
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
89
|
+
};
|
|
90
|
+
expect(json).toEqual(expectedJSON);
|
|
91
|
+
});
|
|
92
|
+
it('for number question format', () => {
|
|
93
|
+
const json = defaultJSON('number');
|
|
94
|
+
const expectedJSON = {
|
|
95
|
+
type: 'number',
|
|
96
|
+
answer: 0,
|
|
97
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
98
|
+
};
|
|
99
|
+
expect(json).toEqual(expectedJSON);
|
|
100
|
+
});
|
|
101
|
+
it('for numberRange format', () => {
|
|
102
|
+
const json = defaultJSON('numberRange');
|
|
103
|
+
const expectedJSON = {
|
|
104
|
+
type: 'numberRange',
|
|
105
|
+
answer: {
|
|
106
|
+
start: 0,
|
|
107
|
+
end: 0,
|
|
108
|
+
},
|
|
109
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
110
|
+
};
|
|
111
|
+
expect(json).toEqual(expectedJSON);
|
|
112
|
+
});
|
|
113
|
+
it('for radioButtons question format', () => {
|
|
114
|
+
const json = defaultJSON('radioButtons');
|
|
115
|
+
const expectedJSON = {
|
|
116
|
+
type: 'radioButtons',
|
|
117
|
+
answer: '',
|
|
118
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
119
|
+
};
|
|
120
|
+
expect(json).toEqual(expectedJSON);
|
|
121
|
+
});
|
|
122
|
+
it('for selectBox question format', () => {
|
|
123
|
+
const json = defaultJSON('selectBox');
|
|
124
|
+
const expectedJSON = {
|
|
125
|
+
type: 'selectBox',
|
|
126
|
+
answer: '',
|
|
127
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
128
|
+
};
|
|
129
|
+
expect(json).toEqual(expectedJSON);
|
|
130
|
+
});
|
|
131
|
+
it('for table question format', () => {
|
|
132
|
+
const json = defaultJSON('table');
|
|
133
|
+
const expectedJSON = {
|
|
134
|
+
type: 'table',
|
|
135
|
+
columnHeadings: [
|
|
136
|
+
'Column A',
|
|
137
|
+
],
|
|
138
|
+
answer: [{
|
|
139
|
+
columns: [{
|
|
140
|
+
type: 'textArea',
|
|
141
|
+
answer: '',
|
|
142
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
143
|
+
}],
|
|
144
|
+
}],
|
|
145
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
146
|
+
};
|
|
147
|
+
expect(json).toEqual(expectedJSON);
|
|
148
|
+
});
|
|
149
|
+
it('for text question format', () => {
|
|
150
|
+
const json = defaultJSON('text');
|
|
151
|
+
const expectedJSON = {
|
|
152
|
+
type: 'text',
|
|
153
|
+
answer: '',
|
|
154
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
155
|
+
};
|
|
156
|
+
expect(json).toEqual(expectedJSON);
|
|
157
|
+
});
|
|
158
|
+
it('for textArea question format', () => {
|
|
159
|
+
const json = defaultJSON('textArea');
|
|
160
|
+
const expectedJSON = {
|
|
161
|
+
type: 'textArea',
|
|
162
|
+
answer: '',
|
|
163
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
164
|
+
};
|
|
165
|
+
expect(json).toEqual(expectedJSON);
|
|
166
|
+
});
|
|
167
|
+
it('for url question format', () => {
|
|
168
|
+
const json = defaultJSON('url');
|
|
169
|
+
const expectedJSON = {
|
|
170
|
+
type: 'url',
|
|
171
|
+
answer: '',
|
|
172
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION },
|
|
173
|
+
};
|
|
174
|
+
expect(json).toEqual(expectedJSON);
|
|
175
|
+
});
|
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>;
|
|
@@ -5,12 +5,13 @@ const zod_1 = require("zod");
|
|
|
5
5
|
const answer_1 = require("./answer");
|
|
6
6
|
// Answers to Date Question Types
|
|
7
7
|
exports.DateAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
|
|
8
|
-
type: zod_1.z.literal('date'),
|
|
8
|
+
type: zod_1.z.literal('date'),
|
|
9
|
+
answer: zod_1.z.string().default('')
|
|
9
10
|
}));
|
|
10
11
|
exports.DateRangeAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
|
|
11
|
-
type: zod_1.z.literal('dateRange'),
|
|
12
|
+
type: zod_1.z.literal('dateRange'),
|
|
12
13
|
answer: zod_1.z.object({
|
|
13
|
-
start: zod_1.z.string(), // The start date (string)
|
|
14
|
-
end: zod_1.z.string() // The end date (string)
|
|
15
|
-
})
|
|
14
|
+
start: zod_1.z.string().default(''), // The start date (string)
|
|
15
|
+
end: zod_1.z.string().default('') // The end date (string)
|
|
16
|
+
}).default({})
|
|
16
17
|
}));
|