@dmptool/types 1.0.8 → 1.1.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.
Files changed (56) hide show
  1. package/dist/answers/__tests__/answers.spec.js +18 -17
  2. package/dist/answers/index.d.ts +50 -25
  3. package/dist/answers/index.js +19 -17
  4. package/dist/answers/{primitiveAnswers.d.ts → numberAnswers.d.ts} +0 -100
  5. package/dist/answers/numberAnswers.js +25 -0
  6. package/dist/answers/tableAnswers.d.ts +48 -48
  7. package/dist/answers/tableAnswers.js +9 -8
  8. package/dist/answers/textAnswers.d.ts +101 -0
  9. package/dist/answers/textAnswers.js +22 -0
  10. package/dist/questions/__tests__/dateQuestions.spec.js +20 -74
  11. package/dist/questions/__tests__/graphQLQuestions.spec.js +6 -0
  12. package/dist/questions/__tests__/numberQuestions.spec.js +156 -0
  13. package/dist/questions/__tests__/optionBasedQuestions.spec.js +41 -54
  14. package/dist/questions/__tests__/tableQuestion.spec.js +2 -0
  15. package/dist/questions/__tests__/textQuestions.spec.d.ts +1 -0
  16. package/dist/questions/__tests__/textQuestions.spec.js +120 -0
  17. package/dist/questions/dateQuestions.d.ts +159 -178
  18. package/dist/questions/dateQuestions.js +9 -15
  19. package/dist/questions/graphQLQuestions.d.ts +67 -38
  20. package/dist/questions/graphQLQuestions.js +3 -2
  21. package/dist/questions/index.d.ts +1616 -1356
  22. package/dist/questions/index.js +21 -19
  23. package/dist/questions/numberQuestions.d.ts +343 -0
  24. package/dist/questions/numberQuestions.js +34 -0
  25. package/dist/questions/optionBasedQuestions.d.ts +136 -158
  26. package/dist/questions/optionBasedQuestions.js +11 -20
  27. package/dist/questions/question.d.ts +29 -11
  28. package/dist/questions/question.js +10 -4
  29. package/dist/questions/tableQuestions.d.ts +2377 -2030
  30. package/dist/questions/tableQuestions.js +12 -10
  31. package/dist/questions/textQuestions.d.ts +261 -0
  32. package/dist/questions/textQuestions.js +42 -0
  33. package/dist/schemas/anyQuestion.schema.json +237 -239
  34. package/dist/schemas/anyTableColumnQuestion.schema.json +207 -217
  35. package/dist/schemas/booleanQuestion.schema.json +17 -12
  36. package/dist/schemas/checkboxesQuestion.schema.json +24 -27
  37. package/dist/schemas/currencyQuestion.schema.json +23 -18
  38. package/dist/schemas/dateQuestion.schema.json +21 -16
  39. package/dist/schemas/dateRangeQuestion.schema.json +31 -56
  40. package/dist/schemas/emailQuestion.schema.json +24 -19
  41. package/dist/schemas/filteredSearchQuestion.schema.json +18 -13
  42. package/dist/schemas/numberQuestion.schema.json +21 -16
  43. package/dist/schemas/numberRangeQuestion.schema.json +31 -56
  44. package/dist/schemas/radioButtonsQuestion.schema.json +24 -27
  45. package/dist/schemas/selectBoxQuestion.schema.json +27 -36
  46. package/dist/schemas/tableQuestion.schema.json +233 -235
  47. package/dist/schemas/textAreaQuestion.schema.json +22 -16
  48. package/dist/schemas/textQuestion.schema.json +21 -16
  49. package/dist/schemas/typeaheadSearchQuestion.schema.json +15 -4
  50. package/dist/schemas/urlQuestion.schema.json +21 -16
  51. package/package.json +1 -1
  52. package/dist/answers/primitiveAnswers.js +0 -41
  53. package/dist/questions/__tests__/primitiveQuestions.spec.js +0 -281
  54. package/dist/questions/primitiveQuestions.d.ts +0 -555
  55. package/dist/questions/primitiveQuestions.js +0 -86
  56. /package/dist/questions/__tests__/{primitiveQuestions.spec.d.ts → numberQuestions.spec.d.ts} +0 -0
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const numberQuestions_1 = require("../numberQuestions");
4
+ describe("Number Questions Zod Schemas", () => {
5
+ it('optional fields should not throw an error if the value is undefined', () => {
6
+ const validBooleanQuestion = {
7
+ type: "boolean",
8
+ meta: {
9
+ schemaVersion: "1.0",
10
+ },
11
+ attributes: {
12
+ checked: undefined, // Valid value
13
+ },
14
+ };
15
+ expect(() => numberQuestions_1.BooleanQuestionSchema.parse(validBooleanQuestion)).not.toThrow();
16
+ });
17
+ it('optional fields should throw an error if the value is null', () => {
18
+ const invalidBooleanQuestion = {
19
+ type: "boolean",
20
+ meta: {
21
+ schemaVersion: "1.0",
22
+ },
23
+ attributes: {
24
+ checked: null, // Invalid value
25
+ },
26
+ };
27
+ expect(() => numberQuestions_1.BooleanQuestionSchema.parse(invalidBooleanQuestion)).toThrow();
28
+ });
29
+ it("should validate a valid BooleanQuestion", () => {
30
+ const validBooleanQuestion = {
31
+ type: "boolean",
32
+ meta: {
33
+ schemaVersion: "1.0",
34
+ },
35
+ attributes: {
36
+ checked: true,
37
+ },
38
+ };
39
+ expect(() => numberQuestions_1.BooleanQuestionSchema.parse(validBooleanQuestion)).not.toThrow();
40
+ });
41
+ it("should invalidate an invalid BooleanQuestion", () => {
42
+ const invalidBooleanQuestion = {
43
+ type: "boolean",
44
+ meta: {
45
+ schemaVersion: "1.0",
46
+ },
47
+ attributes: {
48
+ checked: "true", // Invalid type
49
+ },
50
+ };
51
+ expect(() => numberQuestions_1.BooleanQuestionSchema.parse(invalidBooleanQuestion)).toThrow();
52
+ });
53
+ it("should validate a valid CurrencyQuestion", () => {
54
+ const validCurrencyQuestion = {
55
+ type: "currency",
56
+ meta: {
57
+ schemaVersion: "1.0",
58
+ denomination: "USD",
59
+ },
60
+ attributes: {
61
+ max: 100,
62
+ min: 1,
63
+ step: 0.01,
64
+ },
65
+ };
66
+ expect(() => numberQuestions_1.CurrencyQuestionSchema.parse(validCurrencyQuestion)).not.toThrow();
67
+ });
68
+ it("should invalidate an invalid CurrencyQuestion", () => {
69
+ const invalidCurrencyQuestion = {
70
+ type: "currency",
71
+ meta: {
72
+ schemaVersion: "1.0",
73
+ },
74
+ attributes: {
75
+ max: "100", // Invalid type
76
+ },
77
+ };
78
+ expect(() => numberQuestions_1.CurrencyQuestionSchema.parse(invalidCurrencyQuestion)).toThrow();
79
+ });
80
+ it("should validate a valid NumberQuestion", () => {
81
+ const validNumberQuestion = {
82
+ type: "number",
83
+ meta: {
84
+ schemaVersion: "1.0",
85
+ },
86
+ attributes: {
87
+ max: 100,
88
+ min: 0,
89
+ step: 1,
90
+ },
91
+ };
92
+ expect(() => numberQuestions_1.NumberQuestionSchema.parse(validNumberQuestion)).not.toThrow();
93
+ });
94
+ it("should invalidate an invalid NumberQuestion", () => {
95
+ const invalidNumberQuestion = {
96
+ type: "number",
97
+ meta: {
98
+ schemaVersion: "1.0",
99
+ },
100
+ attributes: {
101
+ step: "1", // Invalid type
102
+ },
103
+ };
104
+ expect(() => numberQuestions_1.NumberQuestionSchema.parse(invalidNumberQuestion)).toThrow();
105
+ });
106
+ it("should validate a valid NumberRangeQuestion", () => {
107
+ const validNumberRangeQuestion = {
108
+ type: "numberRange",
109
+ meta: {
110
+ schemaVersion: "1.0",
111
+ },
112
+ attributes: {
113
+ label: "Range",
114
+ help: "Enter a range"
115
+ },
116
+ columns: {
117
+ start: {
118
+ label: "Start",
119
+ help: "Enter a starting number",
120
+ min: 0,
121
+ max: 50,
122
+ step: 1,
123
+ },
124
+ end: {
125
+ label: "End",
126
+ help: "Enter an ending number",
127
+ min: 50,
128
+ max: 100,
129
+ step: 1,
130
+ },
131
+ },
132
+ };
133
+ expect(() => numberQuestions_1.NumberRangeQuestionSchema.parse(validNumberRangeQuestion)).not.toThrow();
134
+ });
135
+ it("should invalidate an invalid NumberRangeQuestion", () => {
136
+ const invalidNumberRangeQuestion = {
137
+ type: "numberRange",
138
+ meta: {
139
+ schemaVersion: "1.0",
140
+ },
141
+ columns: {
142
+ start: {
143
+ min: 0,
144
+ max: 50,
145
+ },
146
+ end: {
147
+ label: "End",
148
+ min: 50,
149
+ max: "100",
150
+ step: 1,
151
+ },
152
+ },
153
+ };
154
+ expect(() => numberQuestions_1.NumberRangeQuestionSchema.parse(invalidNumberRangeQuestion)).toThrow();
155
+ });
156
+ });
@@ -6,21 +6,19 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
6
6
  (0, globals_1.it)("should validate a valid CheckboxesQuestion object", () => {
7
7
  const validCheckboxesQuestion = {
8
8
  type: "checkBoxes",
9
+ attributes: {
10
+ label: "Fruits",
11
+ help: "Select all fruits you like",
12
+ },
9
13
  options: [
10
14
  {
11
- type: "option",
12
- attributes: {
13
- label: "Apple",
14
- value: "apple",
15
- checked: true,
16
- },
15
+ label: "Apple",
16
+ value: "apple",
17
+ checked: true,
17
18
  },
18
19
  {
19
- type: "option",
20
- attributes: {
21
- label: "Banana",
22
- value: "banana",
23
- },
20
+ label: "Banana",
21
+ value: "banana",
24
22
  },
25
23
  ],
26
24
  meta: {
@@ -32,14 +30,15 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
32
30
  (0, globals_1.it)("should throw an error for an invalid CheckboxesQuestion object", () => {
33
31
  const invalidCheckboxesQuestion = {
34
32
  type: "checkBoxes",
33
+ attributes: {
34
+ label: "Has an apple?",
35
+ help: "Whether or not you have an apple in your fridge.",
36
+ },
35
37
  options: [
36
38
  {
37
- type: "option",
38
- attributes: {
39
- label: "Apple",
40
- value: "apple",
41
- checked: "true", // Invalid type for checked
42
- },
39
+ label: "Apple",
40
+ value: "apple",
41
+ checked: "true", // Invalid type for checked
43
42
  },
44
43
  ],
45
44
  meta: {
@@ -53,21 +52,19 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
53
52
  (0, globals_1.it)("should validate a valid RadioButtonsQuestion object", () => {
54
53
  const validRadioButtonsQuestion = {
55
54
  type: "radioButtons",
55
+ attributes: {
56
+ label: "Fruits",
57
+ help: "Select all fruits you like",
58
+ },
56
59
  options: [
57
60
  {
58
- type: "option",
59
- attributes: {
60
- label: "Male",
61
- value: "male",
62
- selected: true,
63
- },
61
+ label: "Male",
62
+ value: "male",
63
+ selected: true,
64
64
  },
65
65
  {
66
- type: "option",
67
- attributes: {
68
- label: "Female",
69
- value: "female",
70
- },
66
+ label: "Female",
67
+ value: "female",
71
68
  },
72
69
  ],
73
70
  meta: {
@@ -81,12 +78,9 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
81
78
  type: "radioButtons",
82
79
  options: [
83
80
  {
84
- type: "option",
85
- attributes: {
86
- label: "Male",
87
- value: "male",
88
- selected: "true", // Invalid type for selected
89
- },
81
+ label: "Male",
82
+ value: "male",
83
+ selected: "true", // Invalid type for selected
90
84
  },
91
85
  ],
92
86
  meta: {
@@ -100,26 +94,22 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
100
94
  (0, globals_1.it)("should validate a valid SelectBoxQuestion object", () => {
101
95
  const validSelectBoxQuestion = {
102
96
  type: "selectBox",
97
+ attributes: {
98
+ label: "Fruits",
99
+ help: "Select all fruits you like",
100
+ multiple: true,
101
+ },
103
102
  options: [
104
103
  {
105
- type: "option",
106
- attributes: {
107
- label: "USA",
108
- value: "usa",
109
- selected: true,
110
- },
104
+ label: "USA",
105
+ value: "us",
106
+ selected: true,
111
107
  },
112
108
  {
113
- type: "option",
114
- attributes: {
115
- label: "Canada",
116
- value: "canada",
117
- },
109
+ label: "Canada",
110
+ value: "ca",
118
111
  },
119
112
  ],
120
- attributes: {
121
- multiple: true,
122
- },
123
113
  meta: {
124
114
  schemaVersion: "1.0"
125
115
  }
@@ -132,12 +122,9 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
132
122
  questionText: "Select your country",
133
123
  options: [
134
124
  {
135
- type: "option",
136
- attributes: {
137
- label: "USA",
138
- value: "usa",
139
- selected: "true", // Invalid type for selected
140
- },
125
+ label: "USA",
126
+ value: "us",
127
+ selected: "true", // Invalid type for selected
141
128
  },
142
129
  ],
143
130
  attributes: {
@@ -20,6 +20,8 @@ describe("TableQuestionSchema", () => {
20
20
  content: {
21
21
  type: "number",
22
22
  attributes: {
23
+ label: "Age",
24
+ help: "Enter your age",
23
25
  min: 18,
24
26
  max: 65,
25
27
  step: 1,
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const textQuestions_1 = require("../textQuestions");
4
+ describe("Primitive Questions Zod Schemas", () => {
5
+ it("should validate a valid EmailQuestion", () => {
6
+ const validEmailQuestion = {
7
+ type: "email",
8
+ meta: {
9
+ schemaVersion: "1.0",
10
+ },
11
+ attributes: {
12
+ label: "Email",
13
+ help: "Enter your email address",
14
+ maxLength: 50,
15
+ minLength: 5,
16
+ multiple: true,
17
+ pattern: "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$",
18
+ },
19
+ };
20
+ expect(() => textQuestions_1.EmailQuestionSchema.parse(validEmailQuestion)).not.toThrow();
21
+ });
22
+ it("should invalidate an invalid EmailQuestion", () => {
23
+ const invalidEmailQuestion = {
24
+ type: "email",
25
+ meta: {
26
+ schemaVersion: "1.0",
27
+ },
28
+ attributes: {
29
+ maxLength: "50", // Invalid type
30
+ },
31
+ };
32
+ expect(() => textQuestions_1.EmailQuestionSchema.parse(invalidEmailQuestion)).toThrow();
33
+ });
34
+ it("should validate a valid TextAreaQuestion", () => {
35
+ const validTextAreaQuestion = {
36
+ type: "textArea",
37
+ meta: {
38
+ schemaVersion: "1.0",
39
+ asRichText: true,
40
+ },
41
+ attributes: {
42
+ label: "Description",
43
+ help: "Enter a description of your project",
44
+ cols: 30,
45
+ rows: 5,
46
+ maxLength: 500,
47
+ minLength: 10,
48
+ },
49
+ };
50
+ expect(() => textQuestions_1.TextAreaQuestionSchema.parse(validTextAreaQuestion)).not.toThrow();
51
+ });
52
+ it("should invalidate an invalid TextAreaQuestion", () => {
53
+ const invalidTextAreaQuestion = {
54
+ type: "textArea",
55
+ meta: {
56
+ schemaVersion: "1.0",
57
+ },
58
+ attributes: {
59
+ cols: "30", // Invalid type
60
+ },
61
+ };
62
+ expect(() => textQuestions_1.TextAreaQuestionSchema.parse(invalidTextAreaQuestion)).toThrow();
63
+ });
64
+ it("should validate a valid TextQuestion", () => {
65
+ const validTextQuestion = {
66
+ type: "text",
67
+ meta: {
68
+ schemaVersion: "1.0",
69
+ },
70
+ attributes: {
71
+ label: "Name",
72
+ help: "Enter your name",
73
+ maxLength: 100,
74
+ minLength: 1,
75
+ pattern: "^[a-zA-Z]+$",
76
+ },
77
+ };
78
+ expect(() => textQuestions_1.TextQuestionSchema.parse(validTextQuestion)).not.toThrow();
79
+ });
80
+ it("should invalidate an invalid TextQuestion", () => {
81
+ const invalidTextQuestion = {
82
+ type: "text",
83
+ meta: {
84
+ schemaVersion: "1.0",
85
+ },
86
+ attributes: {
87
+ maxLength: "100", // Invalid type
88
+ },
89
+ };
90
+ expect(() => textQuestions_1.TextQuestionSchema.parse(invalidTextQuestion)).toThrow();
91
+ });
92
+ it("should validate a valid URLQuestion", () => {
93
+ const validURLQuestion = {
94
+ type: "url",
95
+ meta: {
96
+ schemaVersion: "1.0",
97
+ },
98
+ attributes: {
99
+ label: "URL",
100
+ help: "Enter a URL",
101
+ maxLength: 200,
102
+ minLength: 10,
103
+ pattern: "https?://.+",
104
+ },
105
+ };
106
+ expect(() => textQuestions_1.URLQuestionSchema.parse(validURLQuestion)).not.toThrow();
107
+ });
108
+ it("should invalidate an invalid URLQuestion", () => {
109
+ const invalidURLQuestion = {
110
+ type: "url",
111
+ meta: {
112
+ schemaVersion: "1.0",
113
+ },
114
+ attributes: {
115
+ maxLength: "200", // Invalid type
116
+ },
117
+ };
118
+ expect(() => textQuestions_1.URLQuestionSchema.parse(invalidURLQuestion)).toThrow();
119
+ });
120
+ });