@dmptool/types 1.0.1 → 1.0.3

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.
Files changed (52) hide show
  1. package/README.md +96 -29
  2. package/dist/answers/__tests__/answers.spec.js +65 -60
  3. package/dist/answers/answer.d.ts +15 -2
  4. package/dist/answers/answer.js +5 -2
  5. package/dist/answers/dateAnswers.d.ts +31 -4
  6. package/dist/answers/dateAnswers.js +3 -3
  7. package/dist/answers/graphQLAnswers.d.ts +32 -4
  8. package/dist/answers/graphQLAnswers.js +3 -3
  9. package/dist/answers/index.d.ts +524 -36
  10. package/dist/answers/index.js +17 -17
  11. package/dist/answers/optionBasedAnswers.d.ts +51 -9
  12. package/dist/answers/optionBasedAnswers.js +5 -5
  13. package/dist/answers/primitiveAnswers.d.ts +112 -14
  14. package/dist/answers/primitiveAnswers.js +8 -8
  15. package/dist/answers/tableAnswers.d.ts +525 -37
  16. package/dist/answers/tableAnswers.js +18 -18
  17. package/dist/questions/__tests__/dateQuestions.spec.js +6 -6
  18. package/dist/questions/__tests__/graphQLQuestions.spec.js +4 -4
  19. package/dist/questions/__tests__/optionBasedQuestions.spec.js +6 -6
  20. package/dist/questions/__tests__/primitiveQuestions.spec.js +14 -14
  21. package/dist/questions/dateQuestions.d.ts +4 -4
  22. package/dist/questions/dateQuestions.js +5 -5
  23. package/dist/questions/graphQLQuestions.d.ts +4 -4
  24. package/dist/questions/graphQLQuestions.js +3 -3
  25. package/dist/questions/index.d.ts +2 -2
  26. package/dist/questions/index.js +17 -17
  27. package/dist/questions/optionBasedQuestions.d.ts +6 -6
  28. package/dist/questions/optionBasedQuestions.js +11 -11
  29. package/dist/questions/primitiveQuestions.d.ts +14 -14
  30. package/dist/questions/primitiveQuestions.js +8 -8
  31. package/dist/questions/question.d.ts +2 -2
  32. package/dist/questions/question.js +2 -2
  33. package/dist/questions/tableQuestions.d.ts +4 -4
  34. package/dist/questions/tableQuestions.js +18 -18
  35. package/dist/schemas/anyAnswer.schema.json +89 -16
  36. package/dist/schemas/anyTableColumnAnswer.schema.json +84 -15
  37. package/dist/schemas/booleanAnswer.schema.json +15 -1
  38. package/dist/schemas/checkboxesAnswer.schema.json +15 -1
  39. package/dist/schemas/currencyAnswer.schema.json +15 -1
  40. package/dist/schemas/datePickerAnswer.schema.json +15 -1
  41. package/dist/schemas/dateRangeAnswer.schema.json +15 -1
  42. package/dist/schemas/emailAnswer.schema.json +15 -1
  43. package/dist/schemas/filteredSearchAnswer.schema.json +15 -1
  44. package/dist/schemas/numberAnswer.schema.json +15 -1
  45. package/dist/schemas/radioButtonsAnswer.schema.json +15 -1
  46. package/dist/schemas/selectBoxAnswer.schema.json +19 -2
  47. package/dist/schemas/tableAnswer.schema.json +89 -16
  48. package/dist/schemas/textAnswer.schema.json +15 -1
  49. package/dist/schemas/textAreaAnswer.schema.json +15 -1
  50. package/dist/schemas/typeaheadSearchAnswer.schema.json +15 -1
  51. package/dist/schemas/urlAnswer.schema.json +15 -1
  52. package/package.json +1 -1
package/README.md CHANGED
@@ -4,8 +4,104 @@ 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
+ 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
+
7
67
  ## Usage
8
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
+
9
105
  To run tests: `npm run test`
10
106
 
11
107
  To run linter checks: `npm run lint`
@@ -41,32 +137,3 @@ latest: 1.0.0
41
137
 
42
138
  published 6 minutes ago by npm-user-name <email-address>
43
139
  ```
44
-
45
- ## Types/Schemas
46
-
47
- If you want to work with DMP Templates or Answers to template questions, the following :
48
- - CURRENT_SCHEMA_VERSION (the current version of the schemas)
49
- - QuestionTypesEnum (Contains the `type` for each Question/Answer below)
50
- - AnyQuestion & AnyAnswer (Union of all types below)
51
- - AnyTableColumnQuestion & AnyTableColumnAnswer (Union of all types except table. Tables cannot be nested)
52
- - BooleanQuestion & Boolean Answer
53
- - CheckboxesQuestion & Checkboxes Answer
54
- - CurrencyQuestion & CurrencyAnswer
55
- - DatePickerQuestion & DatePickerAnswer
56
- - DateRangeQuestion & DateRangeAnswer
57
- - EmailQuestion & EmailAnswer
58
- - FilteredSearchQuestion & FilteredSearchAnswer
59
- - NumberQuestion & NumberAnswer
60
- - RadioButtonsQuestion & RadioButtonsAnswer
61
- - SelectBoxQuestion & SelectBoxAnswer
62
- - TableQuestion & TableAnswer
63
- - TextAreaQuestion & TextAreaAnswer
64
- - TextQuestion & TextAnswer
65
- - TypeaheadSearchQuestion & TypeaheadSearchAnswer
66
- - URLQuestion & URLAnswer
67
-
68
- ### Coming soon
69
-
70
- RDA Common Standard for DMPs
71
-
72
- DMP Tool specific extensions to the RDA Common Standard for DMPs
@@ -7,116 +7,121 @@ const optionBasedAnswers_1 = require("../optionBasedAnswers");
7
7
  const primitiveAnswers_1 = require("../primitiveAnswers");
8
8
  const tableAnswers_1 = require("../tableAnswers");
9
9
  const __1 = require("..");
10
+ const questions_1 = require("../../questions");
10
11
  (0, globals_1.describe)('Answer Type Validations', () => {
11
12
  (0, globals_1.it)('should validate BooleanAnswer', () => {
12
- const validData = { type: 'boolean', answer: true };
13
- (0, globals_1.expect)(() => primitiveAnswers_1.BooleanAnswer.parse(validData)).not.toThrow();
13
+ const validData = { type: 'boolean', answer: true, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
14
+ (0, globals_1.expect)(() => primitiveAnswers_1.BooleanAnswerSchema.parse(validData)).not.toThrow();
14
15
  const invalidData = { type: 'boolean', answer: 'true' };
15
- (0, globals_1.expect)(() => primitiveAnswers_1.BooleanAnswer.parse(invalidData)).toThrow();
16
+ (0, globals_1.expect)(() => primitiveAnswers_1.BooleanAnswerSchema.parse(invalidData)).toThrow();
16
17
  });
17
18
  (0, globals_1.it)('should validate CheckboxesAnswer', () => {
18
- const validData = { type: 'checkBoxes', answer: ['option1', 'option2'] };
19
- (0, globals_1.expect)(() => optionBasedAnswers_1.CheckboxesAnswer.parse(validData)).not.toThrow();
20
- const invalidData = { type: 'checkBoxes', answer: 'option1' };
21
- (0, globals_1.expect)(() => optionBasedAnswers_1.CheckboxesAnswer.parse(invalidData)).toThrow();
19
+ const validData = { type: 'checkBoxes', answer: ['option1', 'option2'], meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
20
+ (0, globals_1.expect)(() => optionBasedAnswers_1.CheckboxesAnswerSchema.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.CheckboxesAnswerSchema.parse(invalidData)).toThrow();
22
23
  });
23
24
  (0, globals_1.it)('should validate CurrencyAnswer', () => {
24
- const validData = { type: 'currency', answer: 100.5 };
25
- (0, globals_1.expect)(() => primitiveAnswers_1.CurrencyAnswer.parse(validData)).not.toThrow();
26
- const invalidData = { type: 'currency', answer: '100.5' };
27
- (0, globals_1.expect)(() => primitiveAnswers_1.CurrencyAnswer.parse(invalidData)).toThrow();
25
+ const validData = { type: 'currency', answer: 100.5, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
26
+ (0, globals_1.expect)(() => primitiveAnswers_1.CurrencyAnswerSchema.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.CurrencyAnswerSchema.parse(invalidData)).toThrow();
28
29
  });
29
30
  (0, globals_1.it)('should validate DatePickerAnswer', () => {
30
- const validData = { type: 'datePicker', answer: '2023-10-01' };
31
- (0, globals_1.expect)(() => dateAnswers_1.DatePickerAnswer.parse(validData)).not.toThrow();
32
- const invalidData = { type: 'datePicker', answer: 12345 };
33
- (0, globals_1.expect)(() => dateAnswers_1.DatePickerAnswer.parse(invalidData)).toThrow();
31
+ const validData = { type: 'datePicker', answer: '2023-10-01', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
32
+ (0, globals_1.expect)(() => dateAnswers_1.DatePickerAnswerSchema.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.DatePickerAnswerSchema.parse(invalidData)).toThrow();
34
35
  });
35
36
  (0, globals_1.it)('should validate DateRangeAnswer', () => {
36
37
  const validData = {
37
38
  type: 'dateRange',
38
39
  answer: { start: '2023-10-01', end: '2023-10-31' },
40
+ meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
39
41
  };
40
- (0, globals_1.expect)(() => dateAnswers_1.DateRangeAnswer.parse(validData)).not.toThrow();
42
+ (0, globals_1.expect)(() => dateAnswers_1.DateRangeAnswerSchema.parse(validData)).not.toThrow();
41
43
  const invalidData = {
42
44
  type: 'dateRange',
43
45
  answer: { start: '2023-10-01', end: 12345 },
46
+ meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
44
47
  };
45
- (0, globals_1.expect)(() => dateAnswers_1.DateRangeAnswer.parse(invalidData)).toThrow();
48
+ (0, globals_1.expect)(() => dateAnswers_1.DateRangeAnswerSchema.parse(invalidData)).toThrow();
46
49
  });
47
50
  (0, globals_1.it)('should validate EmailAnswer', () => {
48
- const validData = { type: 'email', answer: 'test@example.com' };
49
- (0, globals_1.expect)(() => primitiveAnswers_1.EmailAnswer.parse(validData)).not.toThrow();
51
+ const validData = { type: 'email', answer: 'test@example.com', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
52
+ (0, globals_1.expect)(() => primitiveAnswers_1.EmailAnswerSchema.parse(validData)).not.toThrow();
50
53
  const invalidData = { type: 'email', answer: 12345 };
51
- (0, globals_1.expect)(() => primitiveAnswers_1.EmailAnswer.parse(invalidData)).toThrow();
54
+ (0, globals_1.expect)(() => primitiveAnswers_1.EmailAnswerSchema.parse(invalidData)).toThrow();
52
55
  });
53
56
  (0, globals_1.it)('should validate FilteredSearchAnswer', () => {
54
- const validData = { type: 'filteredSearch', answer: ['item1', 'item2'] };
55
- (0, globals_1.expect)(() => graphQLAnswers_1.FilteredSearchAnswer.parse(validData)).not.toThrow();
56
- const invalidData = { type: 'filteredSearch', answer: 'item1' };
57
- (0, globals_1.expect)(() => graphQLAnswers_1.FilteredSearchAnswer.parse(invalidData)).toThrow();
57
+ const validData = { type: 'filteredSearch', answer: ['item1', 'item2'], meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
58
+ (0, globals_1.expect)(() => graphQLAnswers_1.FilteredSearchAnswerSchema.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.FilteredSearchAnswerSchema.parse(invalidData)).toThrow();
58
61
  });
59
62
  (0, globals_1.it)('should validate NumberAnswer', () => {
60
- const validData = { type: 'number', answer: 42 };
61
- (0, globals_1.expect)(() => primitiveAnswers_1.NumberAnswer.parse(validData)).not.toThrow();
62
- const invalidData = { type: 'number', answer: '42' };
63
- (0, globals_1.expect)(() => primitiveAnswers_1.NumberAnswer.parse(invalidData)).toThrow();
63
+ const validData = { type: 'number', answer: 42, meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
64
+ (0, globals_1.expect)(() => primitiveAnswers_1.NumberAnswerSchema.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.NumberAnswerSchema.parse(invalidData)).toThrow();
64
67
  });
65
68
  (0, globals_1.it)('should validate RadioButtonsAnswer', () => {
66
- const validData = { type: 'radioButtons', answer: 'option1' };
67
- (0, globals_1.expect)(() => optionBasedAnswers_1.RadioButtonsAnswer.parse(validData)).not.toThrow();
68
- const invalidData = { type: 'radioButtons', answer: ['option1'] };
69
- (0, globals_1.expect)(() => optionBasedAnswers_1.RadioButtonsAnswer.parse(invalidData)).toThrow();
69
+ const validData = { type: 'radioButtons', answer: 'option1', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
70
+ (0, globals_1.expect)(() => optionBasedAnswers_1.RadioButtonsAnswerSchema.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.RadioButtonsAnswerSchema.parse(invalidData)).toThrow();
70
73
  });
71
74
  (0, globals_1.it)('should validate SelectBoxAnswer', () => {
72
- const validData = { type: 'selectBox', answer: 'option1' };
73
- (0, globals_1.expect)(() => optionBasedAnswers_1.SelectBoxAnswer.parse(validData)).not.toThrow();
74
- const invalidData = { type: 'selectBox', answer: ['option1'] };
75
- (0, globals_1.expect)(() => optionBasedAnswers_1.SelectBoxAnswer.parse(invalidData)).toThrow();
75
+ const validData = { type: 'selectBox', answer: ['option1'], meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
76
+ (0, globals_1.expect)(() => optionBasedAnswers_1.SelectBoxAnswerSchema.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.SelectBoxAnswerSchema.parse(invalidData)).toThrow();
76
79
  });
77
80
  (0, globals_1.it)('should validate TextAnswer', () => {
78
- const validData = { type: 'text', answer: 'Some text' };
79
- (0, globals_1.expect)(() => primitiveAnswers_1.TextAnswer.parse(validData)).not.toThrow();
80
- const invalidData = { type: 'text', answer: 12345 };
81
- (0, globals_1.expect)(() => primitiveAnswers_1.TextAnswer.parse(invalidData)).toThrow();
81
+ const validData = { type: 'text', answer: 'Some text', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
82
+ (0, globals_1.expect)(() => primitiveAnswers_1.TextAnswerSchema.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.TextAnswerSchema.parse(invalidData)).toThrow();
82
85
  });
83
86
  (0, globals_1.it)('should validate TextAreaAnswer', () => {
84
- const validData = { type: 'textArea', answer: 'Some long text' };
85
- (0, globals_1.expect)(() => primitiveAnswers_1.TextAreaAnswer.parse(validData)).not.toThrow();
86
- const invalidData = { type: 'textArea', answer: 12345 };
87
- (0, globals_1.expect)(() => primitiveAnswers_1.TextAreaAnswer.parse(invalidData)).toThrow();
87
+ const validData = { type: 'textArea', answer: 'Some long text', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
88
+ (0, globals_1.expect)(() => primitiveAnswers_1.TextAreaAnswerSchema.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.TextAreaAnswerSchema.parse(invalidData)).toThrow();
88
91
  });
89
92
  (0, globals_1.it)('should validate TypeaheadSearchAnswer', () => {
90
- const validData = { type: 'typeaheadSearch', answer: 'Search term' };
91
- (0, globals_1.expect)(() => graphQLAnswers_1.TypeaheadSearchAnswer.parse(validData)).not.toThrow();
92
- const invalidData = { type: 'typeaheadSearch', answer: 12345 };
93
- (0, globals_1.expect)(() => graphQLAnswers_1.TypeaheadSearchAnswer.parse(invalidData)).toThrow();
93
+ const validData = { type: 'typeaheadSearch', answer: 'Search term', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
94
+ (0, globals_1.expect)(() => graphQLAnswers_1.TypeaheadSearchAnswerSchema.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.TypeaheadSearchAnswerSchema.parse(invalidData)).toThrow();
94
97
  });
95
98
  (0, globals_1.it)('should validate URLAnswer', () => {
96
- const validData = { type: 'url', answer: 'https://example.com' };
97
- (0, globals_1.expect)(() => primitiveAnswers_1.URLAnswer.parse(validData)).not.toThrow();
98
- const invalidData = { type: 'url', answer: 12345 };
99
- (0, globals_1.expect)(() => primitiveAnswers_1.URLAnswer.parse(invalidData)).toThrow();
99
+ const validData = { type: 'url', answer: 'https://example.com', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
100
+ (0, globals_1.expect)(() => primitiveAnswers_1.URLAnswerSchema.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.URLAnswerSchema.parse(invalidData)).toThrow();
100
103
  });
101
104
  (0, globals_1.it)('should validate TableAnswer', () => {
102
105
  const validData = {
103
106
  type: 'table',
104
107
  answer: [
105
- { type: 'text', answer: 'Row 1' },
106
- { type: 'number', answer: 42 },
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 } },
107
110
  ],
111
+ meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
108
112
  };
109
- (0, globals_1.expect)(() => tableAnswers_1.TableAnswer.parse(validData)).not.toThrow();
113
+ (0, globals_1.expect)(() => tableAnswers_1.TableAnswerSchema.parse(validData)).not.toThrow();
110
114
  const invalidData = {
111
115
  type: 'table',
112
116
  answer: [{ type: 'text', answer: 12345 }],
117
+ meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION }
113
118
  };
114
- (0, globals_1.expect)(() => tableAnswers_1.TableAnswer.parse(invalidData)).toThrow();
119
+ (0, globals_1.expect)(() => tableAnswers_1.TableAnswerSchema.parse(invalidData)).toThrow();
115
120
  });
116
121
  (0, globals_1.it)('should validate AnyAnswer', () => {
117
- const validData = { type: 'text', answer: 'Some text' };
118
- (0, globals_1.expect)(() => __1.AnyAnswer.parse(validData)).not.toThrow();
119
- const invalidData = { type: 'unknown', answer: 'Some text' };
120
- (0, globals_1.expect)(() => __1.AnyAnswer.parse(invalidData)).toThrow();
122
+ const validData = { type: 'text', answer: 'Some text', meta: { schemaVersion: questions_1.CURRENT_SCHEMA_VERSION } };
123
+ (0, globals_1.expect)(() => __1.AnyAnswerSchema.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.AnyAnswerSchema.parse(invalidData)).toThrow();
121
126
  });
122
127
  });
@@ -1,12 +1,25 @@
1
1
  import { z } from 'zod';
2
- export declare const Answer: z.ZodObject<{
2
+ export declare const AnswerSchema: z.ZodObject<{
3
3
  type: z.ZodEnum<["boolean", "checkBoxes", "currency", "datePicker", "dateRange", "email", "filteredSearch", "number", "option", "radioButtons", "selectBox", "table", "text", "textArea", "typeaheadSearch", "url"]>;
4
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
+ }>;
5
12
  }, "strip", z.ZodTypeAny, {
6
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
+ };
7
17
  answer: string;
8
18
  }, {
9
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
+ };
10
23
  answer: string;
11
24
  }>;
12
- export type AnswerType = z.infer<typeof Answer>;
25
+ export type AnswerType = z.infer<typeof AnswerSchema>;
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Answer = void 0;
3
+ exports.AnswerSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const question_1 = require("../questions/question");
6
6
  // Abstract base schema for all answers
7
- exports.Answer = zod_1.z.object({
7
+ exports.AnswerSchema = zod_1.z.object({
8
8
  type: question_1.QuestionTypesEnum, // The type of answer
9
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
+ })
10
13
  });
@@ -1,16 +1,37 @@
1
1
  import { z } from 'zod';
2
- export declare const DatePickerAnswer: z.ZodObject<{
2
+ export declare const DatePickerAnswerSchema: z.ZodObject<{
3
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
+ }>;
4
11
  } & {
5
12
  type: z.ZodLiteral<"datePicker">;
6
13
  }, "strip", z.ZodTypeAny, {
7
14
  type: "datePicker";
15
+ meta: {
16
+ schemaVersion: "1.0";
17
+ };
8
18
  answer: string;
9
19
  }, {
10
20
  type: "datePicker";
21
+ meta: {
22
+ schemaVersion: "1.0";
23
+ };
11
24
  answer: string;
12
25
  }>;
13
- export declare const DateRangeAnswer: z.ZodObject<{} & {
26
+ export declare const DateRangeAnswerSchema: 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
+ } & {
14
35
  type: z.ZodLiteral<"dateRange">;
15
36
  answer: z.ZodObject<{
16
37
  start: z.ZodString;
@@ -24,16 +45,22 @@ export declare const DateRangeAnswer: z.ZodObject<{} & {
24
45
  }>;
25
46
  }, "strip", z.ZodTypeAny, {
26
47
  type: "dateRange";
48
+ meta: {
49
+ schemaVersion: "1.0";
50
+ };
27
51
  answer: {
28
52
  start: string;
29
53
  end: string;
30
54
  };
31
55
  }, {
32
56
  type: "dateRange";
57
+ meta: {
58
+ schemaVersion: "1.0";
59
+ };
33
60
  answer: {
34
61
  start: string;
35
62
  end: string;
36
63
  };
37
64
  }>;
38
- export type DatePickerAnswerType = z.infer<typeof DatePickerAnswer>;
39
- export type DateRangeAnswerType = z.infer<typeof DateRangeAnswer>;
65
+ export type DatePickerAnswerType = z.infer<typeof DatePickerAnswerSchema>;
66
+ export type DateRangeAnswerType = z.infer<typeof DateRangeAnswerSchema>;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DateRangeAnswer = exports.DatePickerAnswer = void 0;
3
+ exports.DateRangeAnswerSchema = exports.DatePickerAnswerSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const answer_1 = require("./answer");
6
6
  // Answers to Date Question Types
7
- exports.DatePickerAnswer = answer_1.Answer.merge(zod_1.z.object({
7
+ exports.DatePickerAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
8
8
  type: zod_1.z.literal('datePicker'), // The type of question
9
9
  }));
10
- exports.DateRangeAnswer = answer_1.Answer.merge(zod_1.z.object({
10
+ exports.DateRangeAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
11
11
  type: zod_1.z.literal('dateRange'), // The type of answer
12
12
  answer: zod_1.z.object({
13
13
  start: zod_1.z.string(), // The start date (string)
@@ -1,23 +1,51 @@
1
1
  import { z } from 'zod';
2
- export declare const FilteredSearchAnswer: z.ZodObject<{} & {
2
+ export declare const FilteredSearchAnswerSchema: 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
+ } & {
3
11
  type: z.ZodLiteral<"filteredSearch">;
4
12
  answer: z.ZodArray<z.ZodString, "many">;
5
13
  }, "strip", z.ZodTypeAny, {
6
14
  type: "filteredSearch";
15
+ meta: {
16
+ schemaVersion: "1.0";
17
+ };
7
18
  answer: string[];
8
19
  }, {
9
20
  type: "filteredSearch";
21
+ meta: {
22
+ schemaVersion: "1.0";
23
+ };
10
24
  answer: string[];
11
25
  }>;
12
- export declare const TypeaheadSearchAnswer: z.ZodObject<{} & {
26
+ export declare const TypeaheadSearchAnswerSchema: 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
+ } & {
13
35
  type: z.ZodLiteral<"typeaheadSearch">;
14
36
  answer: z.ZodString;
15
37
  }, "strip", z.ZodTypeAny, {
16
38
  type: "typeaheadSearch";
39
+ meta: {
40
+ schemaVersion: "1.0";
41
+ };
17
42
  answer: string;
18
43
  }, {
19
44
  type: "typeaheadSearch";
45
+ meta: {
46
+ schemaVersion: "1.0";
47
+ };
20
48
  answer: string;
21
49
  }>;
22
- export type FilteredSearchAnswerType = z.infer<typeof FilteredSearchAnswer>;
23
- export type TypeaheadSearchAnswerType = z.infer<typeof TypeaheadSearchAnswer>;
50
+ export type FilteredSearchAnswerType = z.infer<typeof FilteredSearchAnswerSchema>;
51
+ export type TypeaheadSearchAnswerType = z.infer<typeof TypeaheadSearchAnswerSchema>;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeaheadSearchAnswer = exports.FilteredSearchAnswer = void 0;
3
+ exports.TypeaheadSearchAnswerSchema = exports.FilteredSearchAnswerSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const answer_1 = require("./answer");
6
6
  // Answers to GraphQL Question Types
7
- exports.FilteredSearchAnswer = answer_1.Answer.merge(zod_1.z.object({
7
+ exports.FilteredSearchAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
8
8
  type: zod_1.z.literal('filteredSearch'), // The type of answer
9
9
  answer: zod_1.z.array(zod_1.z.string()) // The answer to the filtered search (array of strings)
10
10
  }));
11
- exports.TypeaheadSearchAnswer = answer_1.Answer.merge(zod_1.z.object({
11
+ exports.TypeaheadSearchAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
12
12
  type: zod_1.z.literal('typeaheadSearch'), // The type of answer
13
13
  answer: zod_1.z.string() // The answer to the typeahead search (string)
14
14
  }));