@dmptool/types 1.0.0 → 1.0.2
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 +127 -29
- package/dist/answers/__tests__/answers.spec.d.ts +1 -0
- package/dist/answers/__tests__/answers.spec.js +127 -0
- package/dist/answers/answer.d.ts +25 -0
- package/dist/answers/answer.js +13 -0
- package/dist/answers/dateAnswers.d.ts +66 -0
- package/dist/answers/dateAnswers.js +16 -0
- package/dist/answers/graphQLAnswers.d.ts +51 -0
- package/dist/answers/graphQLAnswers.js +14 -0
- package/dist/answers/index.d.ts +880 -0
- package/dist/answers/index.js +48 -0
- package/dist/answers/optionBasedAnswers.d.ts +76 -0
- package/dist/answers/optionBasedAnswers.js +18 -0
- package/dist/answers/primitiveAnswers.d.ts +176 -0
- package/dist/answers/primitiveAnswers.js +34 -0
- package/dist/answers/tableAnswers.d.ts +876 -0
- package/dist/answers/tableAnswers.js +31 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +19 -0
- package/dist/questions/__tests__/dateQuestions.spec.d.ts +1 -0
- package/dist/questions/__tests__/dateQuestions.spec.js +149 -0
- package/dist/questions/__tests__/graphQLQuestions.spec.d.ts +1 -0
- package/dist/questions/__tests__/graphQLQuestions.spec.js +87 -0
- package/dist/questions/__tests__/optionBasedQuestions.spec.d.ts +1 -0
- package/dist/questions/__tests__/optionBasedQuestions.spec.js +152 -0
- package/dist/questions/__tests__/primitiveQuestions.spec.d.ts +1 -0
- package/dist/questions/__tests__/primitiveQuestions.spec.js +189 -0
- package/dist/{dateQuestions.js → questions/dateQuestions.js} +3 -3
- package/dist/{graphQLQuestions.js → questions/graphQLQuestions.js} +3 -3
- package/dist/{tableQuestions.d.ts → questions/index.d.ts} +97 -1650
- package/dist/questions/index.js +48 -0
- package/dist/{optionBasedQuestions.js → questions/optionBasedQuestions.js} +4 -4
- package/dist/{primitiveQuestions.d.ts → questions/primitiveQuestions.d.ts} +0 -27
- package/dist/{primitiveQuestions.js → questions/primitiveQuestions.js} +8 -35
- package/dist/questions/question.d.ts +29 -0
- package/dist/questions/question.js +32 -0
- package/dist/questions/tableQuestions.d.ts +2638 -0
- package/dist/{tableQuestions.js → questions/tableQuestions.js} +5 -22
- package/dist/schemas/anyAnswer.schema.json +195 -59
- package/dist/schemas/anyTableColumnAnswer.schema.json +336 -0
- package/dist/schemas/anyTableColumnQuestion.schema.json +637 -0
- package/dist/schemas/booleanAnswer.schema.json +15 -1
- package/dist/schemas/checkboxesAnswer.schema.json +15 -1
- package/dist/schemas/currencyAnswer.schema.json +15 -1
- package/dist/schemas/datePickerAnswer.schema.json +15 -1
- package/dist/schemas/dateRangeAnswer.schema.json +15 -1
- package/dist/schemas/emailAnswer.schema.json +15 -1
- package/dist/schemas/filteredSearchAnswer.schema.json +15 -1
- package/dist/schemas/numberAnswer.schema.json +15 -1
- package/dist/schemas/radioButtonsAnswer.schema.json +15 -1
- package/dist/schemas/selectBoxAnswer.schema.json +19 -2
- package/dist/schemas/tableAnswer.schema.json +91 -18
- package/dist/schemas/textAnswer.schema.json +15 -1
- package/dist/schemas/textAreaAnswer.schema.json +15 -1
- package/dist/schemas/typeaheadSearchAnswer.schema.json +15 -1
- package/dist/schemas/urlAnswer.schema.json +15 -1
- package/package.json +8 -1
- package/dist/answers.d.ts +0 -558
- package/dist/answers.js +0 -87
- /package/dist/{dateQuestions.d.ts → questions/dateQuestions.d.ts} +0 -0
- /package/dist/{graphQLQuestions.d.ts → questions/graphQLQuestions.d.ts} +0 -0
- /package/dist/{optionBasedQuestions.d.ts → questions/optionBasedQuestions.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -2,40 +2,138 @@
|
|
|
2
2
|
|
|
3
3
|
This package provides Types, Zod schemas and JSON schemas to aide in integrations with the DMP Tool.
|
|
4
4
|
|
|
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
|
+
|
|
7
|
+
## Available Schemas/Types
|
|
8
|
+
|
|
9
|
+
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
|
+
|
|
11
|
+
Naming conventions:
|
|
12
|
+
- Zod schemas do not include the word `Type` (e.g. `BooleanQuestion`, `CheckboxesAnswer`)
|
|
13
|
+
- Types include the word `Type` (e.g. `BooleanQuestionType`, `CheckboxesAnswerType`)
|
|
14
|
+
|
|
15
|
+
### DMP Template Support
|
|
16
|
+
|
|
17
|
+
The `QuestionTypesEnum` 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: 'checkboxes'`.
|
|
18
|
+
|
|
19
|
+
The available question schemas/types are:
|
|
20
|
+
- `AnyQuestion` A Union of all the question types
|
|
21
|
+
- `AnyTableColumnQuestion` A subset of `AnyQuestion`. All of the question types that can be part of a table
|
|
22
|
+
- `BooleanQuestion` A Yes/No True/False question.
|
|
23
|
+
- `CheckboxesQuestion` A question type that supports an array of `option` objects. The user may "check" multiple options.
|
|
24
|
+
- `CurrencyQuestion` A number field that supports the defintiion of a `denomination`.
|
|
25
|
+
- `DatePickerQuestion` A date field. Supports `YYYY-MM-DD` format.
|
|
26
|
+
- `DateRangeQuestion` A series of 2 date picker fields. Meant to capture "From" and "To" or "Start" and "End" dates.
|
|
27
|
+
- `EmailQuestion` An email address. Supports multiple emails that are comma separated.
|
|
28
|
+
- `FilteredSearchQuestion` A complex field that allows the user to enter a search term and filters. The field fires a graphQL query and allows the user to potentially select multiple results.
|
|
29
|
+
- `NumberQuestion` A numeric field. Supports both integers and floats.
|
|
30
|
+
- `RadioButtonsQuestion` A question type that supports an array of `option` objects. The user may "select" a single option.
|
|
31
|
+
- `SelectBoxQuestion` A drop down select box that supports an array of `option` objects. A `multiple` flag can be set to allow multi-select.
|
|
32
|
+
- `TableQuestion` A table question type. Each column in the table can be any one of the `AnyTableColumnQuestion` types.
|
|
33
|
+
- `TextAreaQuestion` A text area field. If the `isRichText` flag is set, the user should see a WYSIWYG editor.
|
|
34
|
+
- `TextQuestion` A simple text field
|
|
35
|
+
- `TypeaheadSearchQuestion` A complex question type that allows the user to type into a text field and fires off a graphQL query. The user can select a single result.
|
|
36
|
+
- `URLQuestion` A simple URL field.
|
|
37
|
+
|
|
38
|
+
### DMP Support
|
|
39
|
+
|
|
40
|
+
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'`.
|
|
41
|
+
|
|
42
|
+
The available answer schemas/types are:
|
|
43
|
+
- `AnyAnswer` A Union of all the answer types
|
|
44
|
+
- `AnyTableColumnAnswer` A subset of `AnyAnswer`. All of the answer types that can be part of a table
|
|
45
|
+
- `BooleanAnswer` A Yes/No True/False answer.
|
|
46
|
+
- `CheckboxesAnswer` A answer type that supports an array of `option` objects. The user may "check" multiple options.
|
|
47
|
+
- `CurrencyAnswer` A number field that supports the defintiion of a `denomination`.
|
|
48
|
+
- `DatePickerAnswer` A date field. Supports `YYYY-MM-DD` format.
|
|
49
|
+
- `DateRangeAnswer` A series of 2 date picker fields. Meant to capture "From" and "To" or "Start" and "End" dates.
|
|
50
|
+
- `EmailAnswer` An email address. Supports multiple emails that are comma separated.
|
|
51
|
+
- `FilteredSearchAnswer` A complex field that allows the user to enter a search term and filters. The field fires a graphQL query and allows the user to potentially select multiple results.
|
|
52
|
+
- `NumberAnswer` A numeric field. Supports both integers and floats.
|
|
53
|
+
- `RadioButtonsAnswer` A answer type that supports an array of `option` objects. The user may "select" a single option.
|
|
54
|
+
- `SelectBoxAnswer` A drop down select box that supports an array of `option` objects. A `multiple` flag can be set to allow multi-select.
|
|
55
|
+
- `TableAnswer` A table answer type. Each column in the table can be any one of the `AnyTableColumnAnswer` types.
|
|
56
|
+
- `TextAreaAnswer` A text area field. If the `isRichText` flag is set, the user should see a WYSIWYG editor.
|
|
57
|
+
- `TextAnswer` A simple text field
|
|
58
|
+
- `TypeaheadSearchAnswer` A complex answer type that allows the user to type into a text field and fires off a graphQL query. The user can select a single result.
|
|
59
|
+
- `URLAnswer` A simple URL field.
|
|
60
|
+
|
|
61
|
+
#### Coming soon
|
|
62
|
+
|
|
63
|
+
RDA Common Standard for DMPs
|
|
64
|
+
|
|
65
|
+
DMP Tool specific extensions to the RDA Common Standard for DMPs
|
|
66
|
+
|
|
5
67
|
## Usage
|
|
6
68
|
|
|
69
|
+
Add the DMP Tool types to your `package.json` by running `npm add @dmptool/types`
|
|
70
|
+
|
|
71
|
+
Once added, you can then import the Types and Zod shemas like this:
|
|
72
|
+
`import { BooleanQuestion, BooleanQuestionType, CURRENT_SCHEMA_VERSION } from '@dmptool/types';`
|
|
73
|
+
|
|
74
|
+
const boolQ: BooleanQuestionType = {
|
|
75
|
+
type: "boolean",
|
|
76
|
+
attributes: {
|
|
77
|
+
checked: true
|
|
78
|
+
},
|
|
79
|
+
meta: {
|
|
80
|
+
schemaVersion: CURRENT_SCHEMA_VERSION
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const isBoolQ = BooleanQuestion.parse(boolQ);
|
|
85
|
+
console.log('isBoolQ', isBoolQ);
|
|
86
|
+
console.log(BooleanQuestion.parse(123));
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
ZodError: [
|
|
93
|
+
{
|
|
94
|
+
"code": "invalid_type",
|
|
95
|
+
"expected": "object",
|
|
96
|
+
"received": "number",
|
|
97
|
+
"path": [],
|
|
98
|
+
"message": "Expected object, received number"
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Development
|
|
104
|
+
|
|
7
105
|
To run tests: `npm run test`
|
|
8
106
|
|
|
9
107
|
To run linter checks: `npm run lint`
|
|
10
108
|
|
|
11
|
-
To generate JSON schemas from the Zod schemas: `npm run generate`
|
|
12
|
-
|
|
13
|
-
To build the Types, Zod schemas and JSON schemas: `npm run build`
|
|
14
|
-
|
|
15
|
-
## Types/Schemas
|
|
16
|
-
|
|
17
|
-
If you want to work with DMP Templates or Answers to template questions, the following :
|
|
18
|
-
- CURRENT_SCHEMA_VERSION (the current version of the schemas)
|
|
19
|
-
- QuestionTypesEnum (Contains the `type` for each Question/Answer below)
|
|
20
|
-
- AnyQuestion & AnyAnswer (Union of all types below)
|
|
21
|
-
- BooleanQuestion & Boolean Answer
|
|
22
|
-
- CheckboxesQuestion & Checkboxes Answer
|
|
23
|
-
- CurrencyQuestion & CurrencyAnswer
|
|
24
|
-
- DatePickerQuestion & DatePickerAnswer
|
|
25
|
-
- DateRangeQuestion & DateRangeAnswer
|
|
26
|
-
- EmailQuestion & EmailAnswer
|
|
27
|
-
- FilteredSearchQuestion & FilteredSearchAnswer
|
|
28
|
-
- NumberQuestion & NumberAnswer
|
|
29
|
-
- RadioButtonsQuestion & RadioButtonsAnswer
|
|
30
|
-
- SelectBoxQuestion & SelectBoxAnswer
|
|
31
|
-
- TableQuestion & TableAnswer
|
|
32
|
-
- TextAreaQuestion & TextAreaAnswer
|
|
33
|
-
- TextQuestion & TextAnswer
|
|
34
|
-
- TypeaheadSearchQuestion & TypeaheadSearchAnswer
|
|
35
|
-
- URLQuestion & URLAnswer
|
|
36
|
-
|
|
37
|
-
### Coming soon
|
|
109
|
+
To just generate JSON schemas from the Zod schemas: `npm run generate`
|
|
38
110
|
|
|
39
|
-
|
|
111
|
+
To build the Types, Zod schemas and JSON schemas all at once: `npm run build`
|
|
40
112
|
|
|
41
|
-
|
|
113
|
+
To publish changes:
|
|
114
|
+
- Increment the `version` in `package.json`
|
|
115
|
+
- Run `npm login` and login to you npm account
|
|
116
|
+
- Run `npm publish --access public`
|
|
117
|
+
|
|
118
|
+
To view the current published version run `npm view @dmptool/types`. You should see something like this:
|
|
119
|
+
```
|
|
120
|
+
@dmptool/types@1.0.0 | MIT | deps: 3 | versions: 1
|
|
121
|
+
TypeScript types for DMPTool
|
|
122
|
+
|
|
123
|
+
dist
|
|
124
|
+
.tarball: https://registry.npmjs.org/@dmptool/types/-/types-1.0.0.tgz
|
|
125
|
+
.shasum: e9b4200e487ed2e4ae0ef342ca75f90bf6bdd335
|
|
126
|
+
.integrity: sha512-wFhYELbbM17VGx7REVaDXi0TJKMXnGJRiwszfXqnKY46QeQvPnktwgYDDuuWaupFZV1jJaSq7cfs6vK1oHeOyA==
|
|
127
|
+
.unpackedSize: 286.4 kB
|
|
128
|
+
|
|
129
|
+
dependencies:
|
|
130
|
+
fs: ^0.0.1-security zod-to-json-schema: ^3.24.5 zod: ^3.24.4
|
|
131
|
+
|
|
132
|
+
maintainers:
|
|
133
|
+
- npm-user-name <email-address>
|
|
134
|
+
|
|
135
|
+
dist-tags:
|
|
136
|
+
latest: 1.0.0
|
|
137
|
+
|
|
138
|
+
published 6 minutes ago by npm-user-name <email-address>
|
|
139
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const globals_1 = require("@jest/globals");
|
|
4
|
+
const dateAnswers_1 = require("../dateAnswers");
|
|
5
|
+
const graphQLAnswers_1 = require("../graphQLAnswers");
|
|
6
|
+
const optionBasedAnswers_1 = require("../optionBasedAnswers");
|
|
7
|
+
const primitiveAnswers_1 = require("../primitiveAnswers");
|
|
8
|
+
const tableAnswers_1 = require("../tableAnswers");
|
|
9
|
+
const __1 = require("..");
|
|
10
|
+
const questions_1 = require("../../questions");
|
|
11
|
+
(0, globals_1.describe)('Answer Type Validations', () => {
|
|
12
|
+
(0, globals_1.it)('should validate BooleanAnswer', () => {
|
|
13
|
+
const validData = { type: 'boolean', answer: true, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
14
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.BooleanAnswer.parse(validData)).not.toThrow();
|
|
15
|
+
const invalidData = { type: 'boolean', answer: 'true' };
|
|
16
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.BooleanAnswer.parse(invalidData)).toThrow();
|
|
17
|
+
});
|
|
18
|
+
(0, globals_1.it)('should validate CheckboxesAnswer', () => {
|
|
19
|
+
const validData = { type: 'checkBoxes', answer: ['option1', 'option2'], meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
20
|
+
(0, globals_1.expect)(() => optionBasedAnswers_1.CheckboxesAnswer.parse(validData)).not.toThrow();
|
|
21
|
+
const invalidData = { type: 'checkBoxes', answer: 'option1', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
22
|
+
(0, globals_1.expect)(() => optionBasedAnswers_1.CheckboxesAnswer.parse(invalidData)).toThrow();
|
|
23
|
+
});
|
|
24
|
+
(0, globals_1.it)('should validate CurrencyAnswer', () => {
|
|
25
|
+
const validData = { type: 'currency', answer: 100.5, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
26
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.CurrencyAnswer.parse(validData)).not.toThrow();
|
|
27
|
+
const invalidData = { type: 'currency', answer: '100.5', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
28
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.CurrencyAnswer.parse(invalidData)).toThrow();
|
|
29
|
+
});
|
|
30
|
+
(0, globals_1.it)('should validate DatePickerAnswer', () => {
|
|
31
|
+
const validData = { type: 'datePicker', answer: '2023-10-01', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
32
|
+
(0, globals_1.expect)(() => dateAnswers_1.DatePickerAnswer.parse(validData)).not.toThrow();
|
|
33
|
+
const invalidData = { type: 'datePicker', answer: 12345, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
34
|
+
(0, globals_1.expect)(() => dateAnswers_1.DatePickerAnswer.parse(invalidData)).toThrow();
|
|
35
|
+
});
|
|
36
|
+
(0, globals_1.it)('should validate DateRangeAnswer', () => {
|
|
37
|
+
const validData = {
|
|
38
|
+
type: 'dateRange',
|
|
39
|
+
answer: { start: '2023-10-01', end: '2023-10-31' },
|
|
40
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
41
|
+
};
|
|
42
|
+
(0, globals_1.expect)(() => dateAnswers_1.DateRangeAnswer.parse(validData)).not.toThrow();
|
|
43
|
+
const invalidData = {
|
|
44
|
+
type: 'dateRange',
|
|
45
|
+
answer: { start: '2023-10-01', end: 12345 },
|
|
46
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
47
|
+
};
|
|
48
|
+
(0, globals_1.expect)(() => dateAnswers_1.DateRangeAnswer.parse(invalidData)).toThrow();
|
|
49
|
+
});
|
|
50
|
+
(0, globals_1.it)('should validate EmailAnswer', () => {
|
|
51
|
+
const validData = { type: 'email', answer: 'test@example.com', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
52
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.EmailAnswer.parse(validData)).not.toThrow();
|
|
53
|
+
const invalidData = { type: 'email', answer: 12345 };
|
|
54
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.EmailAnswer.parse(invalidData)).toThrow();
|
|
55
|
+
});
|
|
56
|
+
(0, globals_1.it)('should validate FilteredSearchAnswer', () => {
|
|
57
|
+
const validData = { type: 'filteredSearch', answer: ['item1', 'item2'], meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
58
|
+
(0, globals_1.expect)(() => graphQLAnswers_1.FilteredSearchAnswer.parse(validData)).not.toThrow();
|
|
59
|
+
const invalidData = { type: 'filteredSearch', answer: 'item1', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
60
|
+
(0, globals_1.expect)(() => graphQLAnswers_1.FilteredSearchAnswer.parse(invalidData)).toThrow();
|
|
61
|
+
});
|
|
62
|
+
(0, globals_1.it)('should validate NumberAnswer', () => {
|
|
63
|
+
const validData = { type: 'number', answer: 42, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
64
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.NumberAnswer.parse(validData)).not.toThrow();
|
|
65
|
+
const invalidData = { type: 'number', answer: '42', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
66
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.NumberAnswer.parse(invalidData)).toThrow();
|
|
67
|
+
});
|
|
68
|
+
(0, globals_1.it)('should validate RadioButtonsAnswer', () => {
|
|
69
|
+
const validData = { type: 'radioButtons', answer: 'option1', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
70
|
+
(0, globals_1.expect)(() => optionBasedAnswers_1.RadioButtonsAnswer.parse(validData)).not.toThrow();
|
|
71
|
+
const invalidData = { type: 'radioButtons', answer: ['option1'], meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
72
|
+
(0, globals_1.expect)(() => optionBasedAnswers_1.RadioButtonsAnswer.parse(invalidData)).toThrow();
|
|
73
|
+
});
|
|
74
|
+
(0, globals_1.it)('should validate SelectBoxAnswer', () => {
|
|
75
|
+
const validData = { type: 'selectBox', answer: ['option1'], meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
76
|
+
(0, globals_1.expect)(() => optionBasedAnswers_1.SelectBoxAnswer.parse(validData)).not.toThrow();
|
|
77
|
+
const invalidData = { type: 'selectBox', answer: 'option1', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
78
|
+
(0, globals_1.expect)(() => optionBasedAnswers_1.SelectBoxAnswer.parse(invalidData)).toThrow();
|
|
79
|
+
});
|
|
80
|
+
(0, globals_1.it)('should validate TextAnswer', () => {
|
|
81
|
+
const validData = { type: 'text', answer: 'Some text', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
82
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.TextAnswer.parse(validData)).not.toThrow();
|
|
83
|
+
const invalidData = { type: 'text', answer: 12345, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
84
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.TextAnswer.parse(invalidData)).toThrow();
|
|
85
|
+
});
|
|
86
|
+
(0, globals_1.it)('should validate TextAreaAnswer', () => {
|
|
87
|
+
const validData = { type: 'textArea', answer: 'Some long text', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
88
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.TextAreaAnswer.parse(validData)).not.toThrow();
|
|
89
|
+
const invalidData = { type: 'textArea', answer: 12345, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
90
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.TextAreaAnswer.parse(invalidData)).toThrow();
|
|
91
|
+
});
|
|
92
|
+
(0, globals_1.it)('should validate TypeaheadSearchAnswer', () => {
|
|
93
|
+
const validData = { type: 'typeaheadSearch', answer: 'Search term', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
94
|
+
(0, globals_1.expect)(() => graphQLAnswers_1.TypeaheadSearchAnswer.parse(validData)).not.toThrow();
|
|
95
|
+
const invalidData = { type: 'typeaheadSearch', answer: 12345, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
96
|
+
(0, globals_1.expect)(() => graphQLAnswers_1.TypeaheadSearchAnswer.parse(invalidData)).toThrow();
|
|
97
|
+
});
|
|
98
|
+
(0, globals_1.it)('should validate URLAnswer', () => {
|
|
99
|
+
const validData = { type: 'url', answer: 'https://example.com', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
100
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.URLAnswer.parse(validData)).not.toThrow();
|
|
101
|
+
const invalidData = { type: 'url', answer: 12345, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
102
|
+
(0, globals_1.expect)(() => primitiveAnswers_1.URLAnswer.parse(invalidData)).toThrow();
|
|
103
|
+
});
|
|
104
|
+
(0, globals_1.it)('should validate TableAnswer', () => {
|
|
105
|
+
const validData = {
|
|
106
|
+
type: 'table',
|
|
107
|
+
answer: [
|
|
108
|
+
{ type: 'text', answer: 'Row 1', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } },
|
|
109
|
+
{ type: 'number', answer: 42, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } },
|
|
110
|
+
],
|
|
111
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
112
|
+
};
|
|
113
|
+
(0, globals_1.expect)(() => tableAnswers_1.TableAnswer.parse(validData)).not.toThrow();
|
|
114
|
+
const invalidData = {
|
|
115
|
+
type: 'table',
|
|
116
|
+
answer: [{ type: 'text', answer: 12345 }],
|
|
117
|
+
meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
|
|
118
|
+
};
|
|
119
|
+
(0, globals_1.expect)(() => tableAnswers_1.TableAnswer.parse(invalidData)).toThrow();
|
|
120
|
+
});
|
|
121
|
+
(0, globals_1.it)('should validate AnyAnswer', () => {
|
|
122
|
+
const validData = { type: 'text', answer: 'Some text', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
123
|
+
(0, globals_1.expect)(() => __1.AnyAnswer.parse(validData)).not.toThrow();
|
|
124
|
+
const invalidData = { type: 'unknown', answer: 'Some text', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
|
|
125
|
+
(0, globals_1.expect)(() => __1.AnyAnswer.parse(invalidData)).toThrow();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const Answer: z.ZodObject<{
|
|
3
|
+
type: z.ZodEnum<["boolean", "checkBoxes", "currency", "datePicker", "dateRange", "email", "filteredSearch", "number", "option", "radioButtons", "selectBox", "table", "text", "textArea", "typeaheadSearch", "url"]>;
|
|
4
|
+
answer: z.ZodString;
|
|
5
|
+
meta: z.ZodObject<{
|
|
6
|
+
schemaVersion: z.ZodLiteral<"1.0">;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
schemaVersion: "1.0";
|
|
9
|
+
}, {
|
|
10
|
+
schemaVersion: "1.0";
|
|
11
|
+
}>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
type: "number" | "boolean" | "checkBoxes" | "currency" | "datePicker" | "dateRange" | "email" | "filteredSearch" | "option" | "radioButtons" | "selectBox" | "table" | "text" | "textArea" | "typeaheadSearch" | "url";
|
|
14
|
+
meta: {
|
|
15
|
+
schemaVersion: "1.0";
|
|
16
|
+
};
|
|
17
|
+
answer: string;
|
|
18
|
+
}, {
|
|
19
|
+
type: "number" | "boolean" | "checkBoxes" | "currency" | "datePicker" | "dateRange" | "email" | "filteredSearch" | "option" | "radioButtons" | "selectBox" | "table" | "text" | "textArea" | "typeaheadSearch" | "url";
|
|
20
|
+
meta: {
|
|
21
|
+
schemaVersion: "1.0";
|
|
22
|
+
};
|
|
23
|
+
answer: string;
|
|
24
|
+
}>;
|
|
25
|
+
export type AnswerType = z.infer<typeof Answer>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Answer = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const question_1 = require("../questions/question");
|
|
6
|
+
// Abstract base schema for all answers
|
|
7
|
+
exports.Answer = zod_1.z.object({
|
|
8
|
+
type: question_1.QuestionTypesEnum, // The type of answer
|
|
9
|
+
answer: zod_1.z.string(), // The answer to the question (string)
|
|
10
|
+
meta: zod_1.z.object({
|
|
11
|
+
schemaVersion: zod_1.z.literal(question_1.CURRENT_SCHEMA_VERSION), // The schema version of the answer
|
|
12
|
+
})
|
|
13
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const DatePickerAnswer: z.ZodObject<{
|
|
3
|
+
answer: z.ZodString;
|
|
4
|
+
meta: z.ZodObject<{
|
|
5
|
+
schemaVersion: z.ZodLiteral<"1.0">;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
schemaVersion: "1.0";
|
|
8
|
+
}, {
|
|
9
|
+
schemaVersion: "1.0";
|
|
10
|
+
}>;
|
|
11
|
+
} & {
|
|
12
|
+
type: z.ZodLiteral<"datePicker">;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
type: "datePicker";
|
|
15
|
+
meta: {
|
|
16
|
+
schemaVersion: "1.0";
|
|
17
|
+
};
|
|
18
|
+
answer: string;
|
|
19
|
+
}, {
|
|
20
|
+
type: "datePicker";
|
|
21
|
+
meta: {
|
|
22
|
+
schemaVersion: "1.0";
|
|
23
|
+
};
|
|
24
|
+
answer: string;
|
|
25
|
+
}>;
|
|
26
|
+
export declare const DateRangeAnswer: z.ZodObject<{
|
|
27
|
+
meta: z.ZodObject<{
|
|
28
|
+
schemaVersion: z.ZodLiteral<"1.0">;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
schemaVersion: "1.0";
|
|
31
|
+
}, {
|
|
32
|
+
schemaVersion: "1.0";
|
|
33
|
+
}>;
|
|
34
|
+
} & {
|
|
35
|
+
type: z.ZodLiteral<"dateRange">;
|
|
36
|
+
answer: z.ZodObject<{
|
|
37
|
+
start: z.ZodString;
|
|
38
|
+
end: z.ZodString;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
start: string;
|
|
41
|
+
end: string;
|
|
42
|
+
}, {
|
|
43
|
+
start: string;
|
|
44
|
+
end: string;
|
|
45
|
+
}>;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
type: "dateRange";
|
|
48
|
+
meta: {
|
|
49
|
+
schemaVersion: "1.0";
|
|
50
|
+
};
|
|
51
|
+
answer: {
|
|
52
|
+
start: string;
|
|
53
|
+
end: string;
|
|
54
|
+
};
|
|
55
|
+
}, {
|
|
56
|
+
type: "dateRange";
|
|
57
|
+
meta: {
|
|
58
|
+
schemaVersion: "1.0";
|
|
59
|
+
};
|
|
60
|
+
answer: {
|
|
61
|
+
start: string;
|
|
62
|
+
end: string;
|
|
63
|
+
};
|
|
64
|
+
}>;
|
|
65
|
+
export type DatePickerAnswerType = z.infer<typeof DatePickerAnswer>;
|
|
66
|
+
export type DateRangeAnswerType = z.infer<typeof DateRangeAnswer>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateRangeAnswer = exports.DatePickerAnswer = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const answer_1 = require("./answer");
|
|
6
|
+
// Answers to Date Question Types
|
|
7
|
+
exports.DatePickerAnswer = answer_1.Answer.merge(zod_1.z.object({
|
|
8
|
+
type: zod_1.z.literal('datePicker'), // The type of question
|
|
9
|
+
}));
|
|
10
|
+
exports.DateRangeAnswer = answer_1.Answer.merge(zod_1.z.object({
|
|
11
|
+
type: zod_1.z.literal('dateRange'), // The type of answer
|
|
12
|
+
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
|
+
})
|
|
16
|
+
}));
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const FilteredSearchAnswer: z.ZodObject<{
|
|
3
|
+
meta: z.ZodObject<{
|
|
4
|
+
schemaVersion: z.ZodLiteral<"1.0">;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
schemaVersion: "1.0";
|
|
7
|
+
}, {
|
|
8
|
+
schemaVersion: "1.0";
|
|
9
|
+
}>;
|
|
10
|
+
} & {
|
|
11
|
+
type: z.ZodLiteral<"filteredSearch">;
|
|
12
|
+
answer: z.ZodArray<z.ZodString, "many">;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
type: "filteredSearch";
|
|
15
|
+
meta: {
|
|
16
|
+
schemaVersion: "1.0";
|
|
17
|
+
};
|
|
18
|
+
answer: string[];
|
|
19
|
+
}, {
|
|
20
|
+
type: "filteredSearch";
|
|
21
|
+
meta: {
|
|
22
|
+
schemaVersion: "1.0";
|
|
23
|
+
};
|
|
24
|
+
answer: string[];
|
|
25
|
+
}>;
|
|
26
|
+
export declare const TypeaheadSearchAnswer: z.ZodObject<{
|
|
27
|
+
meta: z.ZodObject<{
|
|
28
|
+
schemaVersion: z.ZodLiteral<"1.0">;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
schemaVersion: "1.0";
|
|
31
|
+
}, {
|
|
32
|
+
schemaVersion: "1.0";
|
|
33
|
+
}>;
|
|
34
|
+
} & {
|
|
35
|
+
type: z.ZodLiteral<"typeaheadSearch">;
|
|
36
|
+
answer: z.ZodString;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
type: "typeaheadSearch";
|
|
39
|
+
meta: {
|
|
40
|
+
schemaVersion: "1.0";
|
|
41
|
+
};
|
|
42
|
+
answer: string;
|
|
43
|
+
}, {
|
|
44
|
+
type: "typeaheadSearch";
|
|
45
|
+
meta: {
|
|
46
|
+
schemaVersion: "1.0";
|
|
47
|
+
};
|
|
48
|
+
answer: string;
|
|
49
|
+
}>;
|
|
50
|
+
export type FilteredSearchAnswerType = z.infer<typeof FilteredSearchAnswer>;
|
|
51
|
+
export type TypeaheadSearchAnswerType = z.infer<typeof TypeaheadSearchAnswer>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeaheadSearchAnswer = exports.FilteredSearchAnswer = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const answer_1 = require("./answer");
|
|
6
|
+
// Answers to GraphQL Question Types
|
|
7
|
+
exports.FilteredSearchAnswer = answer_1.Answer.merge(zod_1.z.object({
|
|
8
|
+
type: zod_1.z.literal('filteredSearch'), // The type of answer
|
|
9
|
+
answer: zod_1.z.array(zod_1.z.string()) // The answer to the filtered search (array of strings)
|
|
10
|
+
}));
|
|
11
|
+
exports.TypeaheadSearchAnswer = answer_1.Answer.merge(zod_1.z.object({
|
|
12
|
+
type: zod_1.z.literal('typeaheadSearch'), // The type of answer
|
|
13
|
+
answer: zod_1.z.string() // The answer to the typeahead search (string)
|
|
14
|
+
}));
|