@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.
Files changed (62) hide show
  1. package/README.md +127 -29
  2. package/dist/answers/__tests__/answers.spec.d.ts +1 -0
  3. package/dist/answers/__tests__/answers.spec.js +127 -0
  4. package/dist/answers/answer.d.ts +25 -0
  5. package/dist/answers/answer.js +13 -0
  6. package/dist/answers/dateAnswers.d.ts +66 -0
  7. package/dist/answers/dateAnswers.js +16 -0
  8. package/dist/answers/graphQLAnswers.d.ts +51 -0
  9. package/dist/answers/graphQLAnswers.js +14 -0
  10. package/dist/answers/index.d.ts +880 -0
  11. package/dist/answers/index.js +48 -0
  12. package/dist/answers/optionBasedAnswers.d.ts +76 -0
  13. package/dist/answers/optionBasedAnswers.js +18 -0
  14. package/dist/answers/primitiveAnswers.d.ts +176 -0
  15. package/dist/answers/primitiveAnswers.js +34 -0
  16. package/dist/answers/tableAnswers.d.ts +876 -0
  17. package/dist/answers/tableAnswers.js +31 -0
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.js +19 -0
  20. package/dist/questions/__tests__/dateQuestions.spec.d.ts +1 -0
  21. package/dist/questions/__tests__/dateQuestions.spec.js +149 -0
  22. package/dist/questions/__tests__/graphQLQuestions.spec.d.ts +1 -0
  23. package/dist/questions/__tests__/graphQLQuestions.spec.js +87 -0
  24. package/dist/questions/__tests__/optionBasedQuestions.spec.d.ts +1 -0
  25. package/dist/questions/__tests__/optionBasedQuestions.spec.js +152 -0
  26. package/dist/questions/__tests__/primitiveQuestions.spec.d.ts +1 -0
  27. package/dist/questions/__tests__/primitiveQuestions.spec.js +189 -0
  28. package/dist/{dateQuestions.js → questions/dateQuestions.js} +3 -3
  29. package/dist/{graphQLQuestions.js → questions/graphQLQuestions.js} +3 -3
  30. package/dist/{tableQuestions.d.ts → questions/index.d.ts} +97 -1650
  31. package/dist/questions/index.js +48 -0
  32. package/dist/{optionBasedQuestions.js → questions/optionBasedQuestions.js} +4 -4
  33. package/dist/{primitiveQuestions.d.ts → questions/primitiveQuestions.d.ts} +0 -27
  34. package/dist/{primitiveQuestions.js → questions/primitiveQuestions.js} +8 -35
  35. package/dist/questions/question.d.ts +29 -0
  36. package/dist/questions/question.js +32 -0
  37. package/dist/questions/tableQuestions.d.ts +2638 -0
  38. package/dist/{tableQuestions.js → questions/tableQuestions.js} +5 -22
  39. package/dist/schemas/anyAnswer.schema.json +195 -59
  40. package/dist/schemas/anyTableColumnAnswer.schema.json +336 -0
  41. package/dist/schemas/anyTableColumnQuestion.schema.json +637 -0
  42. package/dist/schemas/booleanAnswer.schema.json +15 -1
  43. package/dist/schemas/checkboxesAnswer.schema.json +15 -1
  44. package/dist/schemas/currencyAnswer.schema.json +15 -1
  45. package/dist/schemas/datePickerAnswer.schema.json +15 -1
  46. package/dist/schemas/dateRangeAnswer.schema.json +15 -1
  47. package/dist/schemas/emailAnswer.schema.json +15 -1
  48. package/dist/schemas/filteredSearchAnswer.schema.json +15 -1
  49. package/dist/schemas/numberAnswer.schema.json +15 -1
  50. package/dist/schemas/radioButtonsAnswer.schema.json +15 -1
  51. package/dist/schemas/selectBoxAnswer.schema.json +19 -2
  52. package/dist/schemas/tableAnswer.schema.json +91 -18
  53. package/dist/schemas/textAnswer.schema.json +15 -1
  54. package/dist/schemas/textAreaAnswer.schema.json +15 -1
  55. package/dist/schemas/typeaheadSearchAnswer.schema.json +15 -1
  56. package/dist/schemas/urlAnswer.schema.json +15 -1
  57. package/package.json +8 -1
  58. package/dist/answers.d.ts +0 -558
  59. package/dist/answers.js +0 -87
  60. /package/dist/{dateQuestions.d.ts → questions/dateQuestions.d.ts} +0 -0
  61. /package/dist/{graphQLQuestions.d.ts → questions/graphQLQuestions.d.ts} +0 -0
  62. /package/dist/{optionBasedQuestions.d.ts → questions/optionBasedQuestions.d.ts} +0 -0
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TableAnswer = exports.AnyTableColumnAnswer = void 0;
4
+ const zod_1 = require("zod");
5
+ const answer_1 = require("./answer");
6
+ const optionBasedAnswers_1 = require("./optionBasedAnswers");
7
+ const dateAnswers_1 = require("./dateAnswers");
8
+ const graphQLAnswers_1 = require("./graphQLAnswers");
9
+ const primitiveAnswers_1 = require("./primitiveAnswers");
10
+ // Answers to Table Column Question Types (note that TableAnswer is not included here because we don't allow nested tables)
11
+ exports.AnyTableColumnAnswer = zod_1.z.discriminatedUnion('type', [
12
+ primitiveAnswers_1.BooleanAnswer,
13
+ optionBasedAnswers_1.CheckboxesAnswer,
14
+ primitiveAnswers_1.CurrencyAnswer,
15
+ dateAnswers_1.DatePickerAnswer,
16
+ dateAnswers_1.DateRangeAnswer,
17
+ primitiveAnswers_1.EmailAnswer,
18
+ graphQLAnswers_1.FilteredSearchAnswer,
19
+ primitiveAnswers_1.NumberAnswer,
20
+ optionBasedAnswers_1.RadioButtonsAnswer,
21
+ optionBasedAnswers_1.SelectBoxAnswer,
22
+ primitiveAnswers_1.TextAnswer,
23
+ primitiveAnswers_1.TextAreaAnswer,
24
+ graphQLAnswers_1.TypeaheadSearchAnswer,
25
+ primitiveAnswers_1.URLAnswer
26
+ ]);
27
+ // Answers to Table Question Types
28
+ exports.TableAnswer = answer_1.Answer.merge(zod_1.z.object({
29
+ type: zod_1.z.literal('table'), // The type of answer
30
+ answer: zod_1.z.array(exports.AnyTableColumnAnswer) // The answer to the question (array of answers)
31
+ }));
@@ -0,0 +1,2 @@
1
+ export * from './answers';
2
+ export * from './questions';
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Export All the Zod schemas and types
18
+ __exportStar(require("./answers"), exports);
19
+ __exportStar(require("./questions"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dateQuestions_1 = require("../dateQuestions");
4
+ describe("DatePickerQuestion", () => {
5
+ it("should validate a valid DatePickerQuestion object", () => {
6
+ const validDatePicker = {
7
+ type: "datePicker",
8
+ attributes: {
9
+ max: "2023-12-31",
10
+ min: "2023-01-01",
11
+ step: 1,
12
+ },
13
+ meta: {
14
+ schemaVersion: "1.0"
15
+ }
16
+ };
17
+ expect(() => dateQuestions_1.DatePickerQuestion.parse(validDatePicker)).not.toThrow();
18
+ });
19
+ it("should throw an error for an invalid DatePickerQuestion object", () => {
20
+ const invalidDatePicker = {
21
+ type: "datePicker",
22
+ attributes: {
23
+ max: 123, // Invalid type for max
24
+ min: "2023-01-01",
25
+ step: "one", // Invalid type for step
26
+ },
27
+ meta: {
28
+ schemaVersion: "1.0"
29
+ }
30
+ };
31
+ expect(() => dateQuestions_1.DatePickerQuestion.parse(invalidDatePicker)).toThrow();
32
+ });
33
+ it("should allow optional attributes in DatePickerQuestion", () => {
34
+ const validDatePicker = {
35
+ type: "datePicker",
36
+ attributes: {},
37
+ meta: {
38
+ schemaVersion: "1.0"
39
+ }
40
+ };
41
+ expect(() => dateQuestions_1.DatePickerQuestion.parse(validDatePicker)).not.toThrow();
42
+ });
43
+ });
44
+ describe("DateRangeQuestion", () => {
45
+ it("should validate a valid DateRangeQuestion object", () => {
46
+ const validDateRange = {
47
+ type: "dateRange",
48
+ columns: {
49
+ start: {
50
+ type: "datePicker",
51
+ attributes: {
52
+ label: "Start Date",
53
+ max: "2023-12-31",
54
+ min: "2023-01-01",
55
+ step: 1,
56
+ },
57
+ meta: {
58
+ schemaVersion: "1.0"
59
+ }
60
+ },
61
+ end: {
62
+ type: "datePicker",
63
+ attributes: {
64
+ label: "End Date",
65
+ max: "2023-12-31",
66
+ min: "2023-01-01",
67
+ step: 1,
68
+ },
69
+ meta: {
70
+ schemaVersion: "1.0"
71
+ }
72
+ },
73
+ },
74
+ meta: {
75
+ schemaVersion: "1.0"
76
+ }
77
+ };
78
+ expect(() => dateQuestions_1.DateRangeQuestion.parse(validDateRange)).not.toThrow();
79
+ });
80
+ it("should throw an error for an invalid DateRangeQuestion object", () => {
81
+ const invalidDateRange = {
82
+ type: "dateRange",
83
+ columns: {
84
+ start: {
85
+ type: "datePicker",
86
+ attributes: {
87
+ label: "Start Date",
88
+ max: "2023-12-31",
89
+ min: "2023-01-01",
90
+ step: 1,
91
+ },
92
+ meta: {
93
+ schemaVersion: "1.0"
94
+ }
95
+ },
96
+ end: {
97
+ type: "datePicker",
98
+ attributes: {
99
+ label: 123, // Invalid type for label
100
+ max: "2023-12-31",
101
+ min: "2023-01-01",
102
+ step: 1,
103
+ },
104
+ meta: {
105
+ schemaVersion: "1.0"
106
+ }
107
+ },
108
+ },
109
+ meta: {
110
+ schemaVersion: "1.0"
111
+ }
112
+ };
113
+ expect(() => dateQuestions_1.DateRangeQuestion.parse(invalidDateRange)).toThrow();
114
+ });
115
+ it("should require labels for start and end date pickers", () => {
116
+ const invalidDateRange = {
117
+ type: "dateRange",
118
+ columns: {
119
+ start: {
120
+ type: "datePicker",
121
+ attributes: {
122
+ max: "2023-12-31",
123
+ min: "2023-01-01",
124
+ step: 1,
125
+ },
126
+ meta: {
127
+ schemaVersion: "1.0"
128
+ }
129
+ },
130
+ end: {
131
+ type: "datePicker",
132
+ attributes: {
133
+ label: "End Date",
134
+ max: "2023-12-31",
135
+ min: "2023-01-01",
136
+ step: 1,
137
+ },
138
+ meta: {
139
+ schemaVersion: "1.0"
140
+ }
141
+ },
142
+ },
143
+ meta: {
144
+ schemaVersion: "1.0"
145
+ }
146
+ };
147
+ expect(() => dateQuestions_1.DateRangeQuestion.parse(invalidDateRange)).toThrow();
148
+ });
149
+ });
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const globals_1 = require("@jest/globals");
4
+ const graphQLQuestions_1 = require("../graphQLQuestions");
5
+ (0, globals_1.describe)("FilteredSearchQuestion schema", () => {
6
+ (0, globals_1.it)("should validate a correct FilteredSearchQuestion object", () => {
7
+ const validData = {
8
+ type: "filteredSearch",
9
+ graphQL: {
10
+ displayFields: [
11
+ { propertyName: "name", label: "Name" },
12
+ { propertyName: "age", label: "Age", labelTranslationKey: "age_key" },
13
+ ],
14
+ query: "query($searchTerm: String!, $minAge: Int!) { users(searchTerm: $searchTerm, minAge: $minAge) { name age } }",
15
+ responseField: "data",
16
+ variables: [
17
+ { name: "searchTerm", type: "string", defaultValue: "default" },
18
+ { name: "minAge", type: "number", minLength: 1 },
19
+ ],
20
+ },
21
+ attributes: {
22
+ multiple: true,
23
+ },
24
+ meta: {
25
+ schemaVersion: "1.0"
26
+ }
27
+ };
28
+ (0, globals_1.expect)(() => graphQLQuestions_1.FilteredSearchQuestion.parse(validData)).not.toThrow();
29
+ });
30
+ (0, globals_1.it)("should throw an error for an invalid FilteredSearchQuestion object", () => {
31
+ const invalidData = {
32
+ type: "filteredSearch",
33
+ graphQL: {
34
+ displayFields: [
35
+ { propertyName: "name", label: "Name" },
36
+ ],
37
+ responseField: "data",
38
+ variables: [
39
+ { name: "searchTerm", type: "string" },
40
+ ],
41
+ },
42
+ attributes: {
43
+ multiple: "notABoolean", // Invalid type
44
+ },
45
+ meta: {
46
+ schemaVersion: "1.0"
47
+ }
48
+ };
49
+ (0, globals_1.expect)(() => graphQLQuestions_1.FilteredSearchQuestion.parse(invalidData)).toThrow();
50
+ });
51
+ });
52
+ (0, globals_1.describe)("TypeaheadSearchQuestion schema", () => {
53
+ (0, globals_1.it)("should validate a correct TypeaheadSearchQuestion object", () => {
54
+ const validData = {
55
+ type: "typeaheadSearch",
56
+ graphQL: {
57
+ displayFields: [
58
+ { propertyName: "title", label: "Title" },
59
+ ],
60
+ localQueryId: "12345",
61
+ responseField: "results",
62
+ variables: [
63
+ { name: "query", type: "string" },
64
+ ],
65
+ },
66
+ meta: {
67
+ schemaVersion: "1.0"
68
+ }
69
+ };
70
+ (0, globals_1.expect)(() => graphQLQuestions_1.TypeaheadSearchQuestion.parse(validData)).not.toThrow();
71
+ });
72
+ (0, globals_1.it)("should throw an error for an invalid TypeaheadSearchQuestion object", () => {
73
+ const invalidData = {
74
+ type: "typeaheadSearch",
75
+ graphQL: {
76
+ displayFields: [
77
+ { propertyName: "title", label: "Title" },
78
+ ],
79
+ responseField: "results",
80
+ variables: [
81
+ { name: "query", type: 123 }, // Invalid type
82
+ ],
83
+ },
84
+ };
85
+ (0, globals_1.expect)(() => graphQLQuestions_1.TypeaheadSearchQuestion.parse(invalidData)).toThrow();
86
+ });
87
+ });
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const globals_1 = require("@jest/globals");
4
+ const optionBasedQuestions_1 = require("../optionBasedQuestions");
5
+ (0, globals_1.describe)("CheckboxesQuestion", () => {
6
+ (0, globals_1.it)("should validate a valid CheckboxesQuestion object", () => {
7
+ const validCheckboxesQuestion = {
8
+ type: "checkBoxes",
9
+ options: [
10
+ {
11
+ type: "option",
12
+ attributes: {
13
+ label: "Apple",
14
+ value: "apple",
15
+ checked: true,
16
+ },
17
+ },
18
+ {
19
+ type: "option",
20
+ attributes: {
21
+ label: "Banana",
22
+ value: "banana",
23
+ },
24
+ },
25
+ ],
26
+ meta: {
27
+ schemaVersion: "1.0"
28
+ }
29
+ };
30
+ (0, globals_1.expect)(() => optionBasedQuestions_1.CheckboxesQuestion.parse(validCheckboxesQuestion)).not.toThrow();
31
+ });
32
+ (0, globals_1.it)("should throw an error for an invalid CheckboxesQuestion object", () => {
33
+ const invalidCheckboxesQuestion = {
34
+ type: "checkBoxes",
35
+ options: [
36
+ {
37
+ type: "option",
38
+ attributes: {
39
+ label: "Apple",
40
+ value: "apple",
41
+ checked: "true", // Invalid type for checked
42
+ },
43
+ },
44
+ ],
45
+ meta: {
46
+ schemaVersion: "1.0"
47
+ }
48
+ };
49
+ (0, globals_1.expect)(() => optionBasedQuestions_1.CheckboxesQuestion.parse(invalidCheckboxesQuestion)).toThrow();
50
+ });
51
+ });
52
+ (0, globals_1.describe)("RadioButtonsQuestion", () => {
53
+ (0, globals_1.it)("should validate a valid RadioButtonsQuestion object", () => {
54
+ const validRadioButtonsQuestion = {
55
+ type: "radioButtons",
56
+ options: [
57
+ {
58
+ type: "option",
59
+ attributes: {
60
+ label: "Male",
61
+ value: "male",
62
+ selected: true,
63
+ },
64
+ },
65
+ {
66
+ type: "option",
67
+ attributes: {
68
+ label: "Female",
69
+ value: "female",
70
+ },
71
+ },
72
+ ],
73
+ meta: {
74
+ schemaVersion: "1.0"
75
+ }
76
+ };
77
+ (0, globals_1.expect)(() => optionBasedQuestions_1.RadioButtonsQuestion.parse(validRadioButtonsQuestion)).not.toThrow();
78
+ });
79
+ (0, globals_1.it)("should throw an error for an invalid RadioButtonsQuestion object", () => {
80
+ const invalidRadioButtonsQuestion = {
81
+ type: "radioButtons",
82
+ options: [
83
+ {
84
+ type: "option",
85
+ attributes: {
86
+ label: "Male",
87
+ value: "male",
88
+ selected: "true", // Invalid type for selected
89
+ },
90
+ },
91
+ ],
92
+ meta: {
93
+ schemaVersion: "1.0"
94
+ }
95
+ };
96
+ (0, globals_1.expect)(() => optionBasedQuestions_1.RadioButtonsQuestion.parse(invalidRadioButtonsQuestion)).toThrow();
97
+ });
98
+ });
99
+ (0, globals_1.describe)("SelectBoxQuestion", () => {
100
+ (0, globals_1.it)("should validate a valid SelectBoxQuestion object", () => {
101
+ const validSelectBoxQuestion = {
102
+ type: "selectBox",
103
+ options: [
104
+ {
105
+ type: "option",
106
+ attributes: {
107
+ label: "USA",
108
+ value: "usa",
109
+ selected: true,
110
+ },
111
+ },
112
+ {
113
+ type: "option",
114
+ attributes: {
115
+ label: "Canada",
116
+ value: "canada",
117
+ },
118
+ },
119
+ ],
120
+ attributes: {
121
+ multiple: true,
122
+ },
123
+ meta: {
124
+ schemaVersion: "1.0"
125
+ }
126
+ };
127
+ (0, globals_1.expect)(() => optionBasedQuestions_1.SelectBoxQuestion.parse(validSelectBoxQuestion)).not.toThrow();
128
+ });
129
+ (0, globals_1.it)("should throw an error for an invalid SelectBoxQuestion object", () => {
130
+ const invalidSelectBoxQuestion = {
131
+ type: "selectBox",
132
+ questionText: "Select your country",
133
+ options: [
134
+ {
135
+ type: "option",
136
+ attributes: {
137
+ label: "USA",
138
+ value: "usa",
139
+ selected: "true", // Invalid type for selected
140
+ },
141
+ },
142
+ ],
143
+ attributes: {
144
+ multiple: "true", // Invalid type for multiple
145
+ },
146
+ meta: {
147
+ schemaVersion: "1.0"
148
+ }
149
+ };
150
+ (0, globals_1.expect)(() => optionBasedQuestions_1.SelectBoxQuestion.parse(invalidSelectBoxQuestion)).toThrow();
151
+ });
152
+ });
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const primitiveQuestions_1 = require("../primitiveQuestions");
4
+ describe("Primitive Questions Zod Schemas", () => {
5
+ it("should validate a valid BooleanQuestion", () => {
6
+ const validBooleanQuestion = {
7
+ type: "boolean",
8
+ meta: {
9
+ schemaVersion: "1.0",
10
+ },
11
+ attributes: {
12
+ checked: true,
13
+ },
14
+ };
15
+ expect(() => primitiveQuestions_1.BooleanQuestion.parse(validBooleanQuestion)).not.toThrow();
16
+ });
17
+ it("should invalidate an invalid BooleanQuestion", () => {
18
+ const invalidBooleanQuestion = {
19
+ type: "boolean",
20
+ meta: {
21
+ schemaVersion: "1.0",
22
+ },
23
+ attributes: {
24
+ checked: "true", // Invalid type
25
+ },
26
+ };
27
+ expect(() => primitiveQuestions_1.BooleanQuestion.parse(invalidBooleanQuestion)).toThrow();
28
+ });
29
+ it("should validate a valid CurrencyQuestion", () => {
30
+ const validCurrencyQuestion = {
31
+ type: "currency",
32
+ meta: {
33
+ schemaVersion: "1.0",
34
+ denomination: "USD",
35
+ },
36
+ attributes: {
37
+ max: 100,
38
+ min: 1,
39
+ step: 0.01,
40
+ },
41
+ };
42
+ expect(() => primitiveQuestions_1.CurrencyQuestion.parse(validCurrencyQuestion)).not.toThrow();
43
+ });
44
+ it("should invalidate an invalid CurrencyQuestion", () => {
45
+ const invalidCurrencyQuestion = {
46
+ type: "currency",
47
+ meta: {
48
+ schemaVersion: "1.0",
49
+ },
50
+ attributes: {
51
+ max: "100", // Invalid type
52
+ },
53
+ };
54
+ expect(() => primitiveQuestions_1.CurrencyQuestion.parse(invalidCurrencyQuestion)).toThrow();
55
+ });
56
+ it("should validate a valid EmailQuestion", () => {
57
+ const validEmailQuestion = {
58
+ type: "email",
59
+ meta: {
60
+ schemaVersion: "1.0",
61
+ },
62
+ attributes: {
63
+ maxLength: 50,
64
+ minLength: 5,
65
+ multiple: true,
66
+ pattern: "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$",
67
+ },
68
+ };
69
+ expect(() => primitiveQuestions_1.EmailQuestion.parse(validEmailQuestion)).not.toThrow();
70
+ });
71
+ it("should invalidate an invalid EmailQuestion", () => {
72
+ const invalidEmailQuestion = {
73
+ type: "email",
74
+ meta: {
75
+ schemaVersion: "1.0",
76
+ },
77
+ attributes: {
78
+ maxLength: "50", // Invalid type
79
+ },
80
+ };
81
+ expect(() => primitiveQuestions_1.EmailQuestion.parse(invalidEmailQuestion)).toThrow();
82
+ });
83
+ it("should validate a valid NumberQuestion", () => {
84
+ const validNumberQuestion = {
85
+ type: "number",
86
+ meta: {
87
+ schemaVersion: "1.0",
88
+ },
89
+ attributes: {
90
+ max: 100,
91
+ min: 0,
92
+ step: 1,
93
+ },
94
+ };
95
+ expect(() => primitiveQuestions_1.NumberQuestion.parse(validNumberQuestion)).not.toThrow();
96
+ });
97
+ it("should invalidate an invalid NumberQuestion", () => {
98
+ const invalidNumberQuestion = {
99
+ type: "number",
100
+ meta: {
101
+ schemaVersion: "1.0",
102
+ },
103
+ attributes: {
104
+ step: "1", // Invalid type
105
+ },
106
+ };
107
+ expect(() => primitiveQuestions_1.NumberQuestion.parse(invalidNumberQuestion)).toThrow();
108
+ });
109
+ it("should validate a valid TextAreaQuestion", () => {
110
+ const validTextAreaQuestion = {
111
+ type: "textArea",
112
+ meta: {
113
+ schemaVersion: "1.0",
114
+ asRichText: true,
115
+ },
116
+ attributes: {
117
+ cols: 30,
118
+ rows: 5,
119
+ maxLength: 500,
120
+ minLength: 10,
121
+ },
122
+ };
123
+ expect(() => primitiveQuestions_1.TextAreaQuestion.parse(validTextAreaQuestion)).not.toThrow();
124
+ });
125
+ it("should invalidate an invalid TextAreaQuestion", () => {
126
+ const invalidTextAreaQuestion = {
127
+ type: "textArea",
128
+ meta: {
129
+ schemaVersion: "1.0",
130
+ },
131
+ attributes: {
132
+ cols: "30", // Invalid type
133
+ },
134
+ };
135
+ expect(() => primitiveQuestions_1.TextAreaQuestion.parse(invalidTextAreaQuestion)).toThrow();
136
+ });
137
+ it("should validate a valid TextQuestion", () => {
138
+ const validTextQuestion = {
139
+ type: "text",
140
+ meta: {
141
+ schemaVersion: "1.0",
142
+ },
143
+ attributes: {
144
+ maxLength: 100,
145
+ minLength: 1,
146
+ pattern: "^[a-zA-Z]+$",
147
+ },
148
+ };
149
+ expect(() => primitiveQuestions_1.TextQuestion.parse(validTextQuestion)).not.toThrow();
150
+ });
151
+ it("should invalidate an invalid TextQuestion", () => {
152
+ const invalidTextQuestion = {
153
+ type: "text",
154
+ meta: {
155
+ schemaVersion: "1.0",
156
+ },
157
+ attributes: {
158
+ maxLength: "100", // Invalid type
159
+ },
160
+ };
161
+ expect(() => primitiveQuestions_1.TextQuestion.parse(invalidTextQuestion)).toThrow();
162
+ });
163
+ it("should validate a valid URLQuestion", () => {
164
+ const validURLQuestion = {
165
+ type: "url",
166
+ meta: {
167
+ schemaVersion: "1.0",
168
+ },
169
+ attributes: {
170
+ maxLength: 200,
171
+ minLength: 10,
172
+ pattern: "https?://.+",
173
+ },
174
+ };
175
+ expect(() => primitiveQuestions_1.URLQuestion.parse(validURLQuestion)).not.toThrow();
176
+ });
177
+ it("should invalidate an invalid URLQuestion", () => {
178
+ const invalidURLQuestion = {
179
+ type: "url",
180
+ meta: {
181
+ schemaVersion: "1.0",
182
+ },
183
+ attributes: {
184
+ maxLength: "200", // Invalid type
185
+ },
186
+ };
187
+ expect(() => primitiveQuestions_1.URLQuestion.parse(invalidURLQuestion)).toThrow();
188
+ });
189
+ });
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DateRangeQuestion = exports.DatePickerQuestion = void 0;
4
4
  const zod_1 = require("zod");
5
- const primitiveQuestions_1 = require("./primitiveQuestions");
5
+ const question_1 = require("./question");
6
6
  // Date picker question and answer
7
- exports.DatePickerQuestion = primitiveQuestions_1.Question.merge(zod_1.z.object({
7
+ exports.DatePickerQuestion = question_1.Question.merge(zod_1.z.object({
8
8
  type: zod_1.z.literal('datePicker'), // The type of question
9
9
  attributes: zod_1.z.object({
10
10
  max: zod_1.z.string().optional(), // The maximum date (no default)
@@ -13,7 +13,7 @@ exports.DatePickerQuestion = primitiveQuestions_1.Question.merge(zod_1.z.object(
13
13
  })
14
14
  }));
15
15
  // Date range question and answer
16
- exports.DateRangeQuestion = primitiveQuestions_1.Question.merge(zod_1.z.object({
16
+ exports.DateRangeQuestion = question_1.Question.merge(zod_1.z.object({
17
17
  type: zod_1.z.literal('dateRange'), // The type of question
18
18
  columns: zod_1.z.object({
19
19
  start: exports.DatePickerQuestion.merge(zod_1.z.object({