@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
@@ -8,28 +8,18 @@
8
8
  "type": "string",
9
9
  "const": "textArea"
10
10
  },
11
- "meta": {
11
+ "attributes": {
12
12
  "type": "object",
13
13
  "properties": {
14
- "schemaVersion": {
15
- "type": "string",
16
- "const": "1.0"
14
+ "label": {
15
+ "type": "string"
16
+ },
17
+ "help": {
18
+ "type": "string"
17
19
  },
18
20
  "labelTranslationKey": {
19
21
  "type": "string"
20
22
  },
21
- "asRichText": {
22
- "type": "boolean"
23
- }
24
- },
25
- "required": [
26
- "schemaVersion"
27
- ],
28
- "additionalProperties": false
29
- },
30
- "attributes": {
31
- "type": "object",
32
- "properties": {
33
23
  "cols": {
34
24
  "type": "number"
35
25
  },
@@ -44,6 +34,22 @@
44
34
  }
45
35
  },
46
36
  "additionalProperties": false
37
+ },
38
+ "meta": {
39
+ "type": "object",
40
+ "properties": {
41
+ "schemaVersion": {
42
+ "type": "string",
43
+ "const": "1.0"
44
+ },
45
+ "asRichText": {
46
+ "type": "boolean"
47
+ }
48
+ },
49
+ "required": [
50
+ "schemaVersion"
51
+ ],
52
+ "additionalProperties": false
47
53
  }
48
54
  },
49
55
  "required": [
@@ -8,25 +8,18 @@
8
8
  "type": "string",
9
9
  "const": "text"
10
10
  },
11
- "meta": {
11
+ "attributes": {
12
12
  "type": "object",
13
13
  "properties": {
14
- "schemaVersion": {
15
- "type": "string",
16
- "const": "1.0"
14
+ "label": {
15
+ "type": "string"
16
+ },
17
+ "help": {
18
+ "type": "string"
17
19
  },
18
20
  "labelTranslationKey": {
19
21
  "type": "string"
20
- }
21
- },
22
- "required": [
23
- "schemaVersion"
24
- ],
25
- "additionalProperties": false
26
- },
27
- "attributes": {
28
- "type": "object",
29
- "properties": {
22
+ },
30
23
  "maxLength": {
31
24
  "type": "number"
32
25
  },
@@ -38,11 +31,23 @@
38
31
  }
39
32
  },
40
33
  "additionalProperties": false
34
+ },
35
+ "meta": {
36
+ "type": "object",
37
+ "properties": {
38
+ "schemaVersion": {
39
+ "type": "string",
40
+ "const": "1.0"
41
+ }
42
+ },
43
+ "required": [
44
+ "schemaVersion"
45
+ ],
46
+ "additionalProperties": false
41
47
  }
42
48
  },
43
49
  "required": [
44
- "type",
45
- "meta"
50
+ "type"
46
51
  ],
47
52
  "additionalProperties": false
48
53
  }
@@ -8,15 +8,27 @@
8
8
  "type": "string",
9
9
  "const": "typeaheadSearch"
10
10
  },
11
+ "attributes": {
12
+ "type": "object",
13
+ "properties": {
14
+ "label": {
15
+ "type": "string"
16
+ },
17
+ "help": {
18
+ "type": "string"
19
+ },
20
+ "labelTranslationKey": {
21
+ "type": "string"
22
+ }
23
+ },
24
+ "additionalProperties": false
25
+ },
11
26
  "meta": {
12
27
  "type": "object",
13
28
  "properties": {
14
29
  "schemaVersion": {
15
30
  "type": "string",
16
31
  "const": "1.0"
17
- },
18
- "labelTranslationKey": {
19
- "type": "string"
20
32
  }
21
33
  },
22
34
  "required": [
@@ -99,7 +111,6 @@
99
111
  },
100
112
  "required": [
101
113
  "type",
102
- "meta",
103
114
  "graphQL"
104
115
  ],
105
116
  "additionalProperties": false
@@ -8,25 +8,18 @@
8
8
  "type": "string",
9
9
  "const": "url"
10
10
  },
11
- "meta": {
11
+ "attributes": {
12
12
  "type": "object",
13
13
  "properties": {
14
- "schemaVersion": {
15
- "type": "string",
16
- "const": "1.0"
14
+ "label": {
15
+ "type": "string"
16
+ },
17
+ "help": {
18
+ "type": "string"
17
19
  },
18
20
  "labelTranslationKey": {
19
21
  "type": "string"
20
- }
21
- },
22
- "required": [
23
- "schemaVersion"
24
- ],
25
- "additionalProperties": false
26
- },
27
- "attributes": {
28
- "type": "object",
29
- "properties": {
22
+ },
30
23
  "maxLength": {
31
24
  "type": "number"
32
25
  },
@@ -38,11 +31,23 @@
38
31
  }
39
32
  },
40
33
  "additionalProperties": false
34
+ },
35
+ "meta": {
36
+ "type": "object",
37
+ "properties": {
38
+ "schemaVersion": {
39
+ "type": "string",
40
+ "const": "1.0"
41
+ }
42
+ },
43
+ "required": [
44
+ "schemaVersion"
45
+ ],
46
+ "additionalProperties": false
41
47
  }
42
48
  },
43
49
  "required": [
44
- "type",
45
- "meta"
50
+ "type"
46
51
  ],
47
52
  "additionalProperties": false
48
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dmptool/types",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "TypeScript types for DMPTool",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.URLAnswerSchema = exports.TextAreaAnswerSchema = exports.TextAnswerSchema = exports.NumberRangeAnswerSchema = exports.NumberAnswerSchema = exports.EmailAnswerSchema = exports.CurrencyAnswerSchema = exports.BooleanAnswerSchema = void 0;
4
- const zod_1 = require("zod");
5
- const answer_1 = require("./answer");
6
- // Answers to Primitive Question Types
7
- exports.BooleanAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
8
- type: zod_1.z.literal('boolean'), // The type of answer
9
- answer: zod_1.z.boolean() // The answer to the question (true/false)
10
- }));
11
- exports.CurrencyAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
12
- type: zod_1.z.literal('currency'), // The type of answer
13
- answer: zod_1.z.number() // The answer to the question (number)
14
- }));
15
- exports.EmailAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
16
- type: zod_1.z.literal('email'), // The type of question
17
- answer: zod_1.z.string() // The answer to the question (string)
18
- }));
19
- exports.NumberAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
20
- type: zod_1.z.literal('number'), // The type of answer
21
- answer: zod_1.z.number() // The answer to the question (number)
22
- }));
23
- exports.NumberRangeAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
24
- type: zod_1.z.literal('numberRange'), // The type of answer
25
- answer: zod_1.z.object({
26
- start: zod_1.z.number(), // The start number (number)
27
- end: zod_1.z.number() // The end number (number)
28
- })
29
- }));
30
- exports.TextAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
31
- type: zod_1.z.literal('text'), // The type of answer
32
- answer: zod_1.z.string() // The answer to the question (string)
33
- }));
34
- exports.TextAreaAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
35
- type: zod_1.z.literal('textArea'), // The type of answer
36
- answer: zod_1.z.string() // The answer to the question (string)
37
- }));
38
- exports.URLAnswerSchema = answer_1.AnswerSchema.merge(zod_1.z.object({
39
- type: zod_1.z.literal('url'), // The type of answer
40
- answer: zod_1.z.string() // The answer to the question (string)
41
- }));
@@ -1,281 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const primitiveQuestions_1 = require("../primitiveQuestions");
4
- describe("Primitive 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(() => primitiveQuestions_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(() => primitiveQuestions_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(() => primitiveQuestions_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(() => primitiveQuestions_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(() => primitiveQuestions_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(() => primitiveQuestions_1.CurrencyQuestionSchema.parse(invalidCurrencyQuestion)).toThrow();
79
- });
80
- it("should validate a valid EmailQuestion", () => {
81
- const validEmailQuestion = {
82
- type: "email",
83
- meta: {
84
- schemaVersion: "1.0",
85
- },
86
- attributes: {
87
- maxLength: 50,
88
- minLength: 5,
89
- multiple: true,
90
- pattern: "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$",
91
- },
92
- };
93
- expect(() => primitiveQuestions_1.EmailQuestionSchema.parse(validEmailQuestion)).not.toThrow();
94
- });
95
- it("should invalidate an invalid EmailQuestion", () => {
96
- const invalidEmailQuestion = {
97
- type: "email",
98
- meta: {
99
- schemaVersion: "1.0",
100
- },
101
- attributes: {
102
- maxLength: "50", // Invalid type
103
- },
104
- };
105
- expect(() => primitiveQuestions_1.EmailQuestionSchema.parse(invalidEmailQuestion)).toThrow();
106
- });
107
- it("should validate a valid NumberQuestion", () => {
108
- const validNumberQuestion = {
109
- type: "number",
110
- meta: {
111
- schemaVersion: "1.0",
112
- },
113
- attributes: {
114
- max: 100,
115
- min: 0,
116
- step: 1,
117
- },
118
- };
119
- expect(() => primitiveQuestions_1.NumberQuestionSchema.parse(validNumberQuestion)).not.toThrow();
120
- });
121
- it("should invalidate an invalid NumberQuestion", () => {
122
- const invalidNumberQuestion = {
123
- type: "number",
124
- meta: {
125
- schemaVersion: "1.0",
126
- },
127
- attributes: {
128
- step: "1", // Invalid type
129
- },
130
- };
131
- expect(() => primitiveQuestions_1.NumberQuestionSchema.parse(invalidNumberQuestion)).toThrow();
132
- });
133
- it("should validate a valid NumberRangeQuestion", () => {
134
- const validNumberRangeQuestion = {
135
- type: "numberRange",
136
- meta: {
137
- schemaVersion: "1.0",
138
- },
139
- columns: {
140
- start: {
141
- type: "number",
142
- attributes: {
143
- label: "Start",
144
- min: 0,
145
- max: 50,
146
- step: 1,
147
- },
148
- meta: {
149
- schemaVersion: "1.0",
150
- },
151
- },
152
- end: {
153
- type: "number",
154
- attributes: {
155
- label: "End",
156
- min: 50,
157
- max: 100,
158
- step: 1,
159
- },
160
- meta: {
161
- schemaVersion: "1.0",
162
- },
163
- },
164
- },
165
- };
166
- expect(() => primitiveQuestions_1.NumberRangeQuestionSchema.parse(validNumberRangeQuestion)).not.toThrow();
167
- });
168
- it("should invalidate an invalid NumberRangeQuestion", () => {
169
- const invalidNumberRangeQuestion = {
170
- type: "numberRange",
171
- meta: {
172
- schemaVersion: "1.0",
173
- },
174
- columns: {
175
- start: {
176
- type: "number",
177
- attributes: {
178
- min: 0,
179
- max: 50,
180
- },
181
- meta: {
182
- schemaVersion: "1.0",
183
- },
184
- },
185
- end: {
186
- type: "number",
187
- attributes: {
188
- label: "End",
189
- min: 50,
190
- max: 100,
191
- step: 1,
192
- },
193
- meta: {
194
- schemaVersion: "1.0",
195
- },
196
- },
197
- },
198
- };
199
- expect(() => primitiveQuestions_1.NumberRangeQuestionSchema.parse(invalidNumberRangeQuestion)).toThrow();
200
- });
201
- it("should validate a valid TextAreaQuestion", () => {
202
- const validTextAreaQuestion = {
203
- type: "textArea",
204
- meta: {
205
- schemaVersion: "1.0",
206
- asRichText: true,
207
- },
208
- attributes: {
209
- cols: 30,
210
- rows: 5,
211
- maxLength: 500,
212
- minLength: 10,
213
- },
214
- };
215
- expect(() => primitiveQuestions_1.TextAreaQuestionSchema.parse(validTextAreaQuestion)).not.toThrow();
216
- });
217
- it("should invalidate an invalid TextAreaQuestion", () => {
218
- const invalidTextAreaQuestion = {
219
- type: "textArea",
220
- meta: {
221
- schemaVersion: "1.0",
222
- },
223
- attributes: {
224
- cols: "30", // Invalid type
225
- },
226
- };
227
- expect(() => primitiveQuestions_1.TextAreaQuestionSchema.parse(invalidTextAreaQuestion)).toThrow();
228
- });
229
- it("should validate a valid TextQuestion", () => {
230
- const validTextQuestion = {
231
- type: "text",
232
- meta: {
233
- schemaVersion: "1.0",
234
- },
235
- attributes: {
236
- maxLength: 100,
237
- minLength: 1,
238
- pattern: "^[a-zA-Z]+$",
239
- },
240
- };
241
- expect(() => primitiveQuestions_1.TextQuestionSchema.parse(validTextQuestion)).not.toThrow();
242
- });
243
- it("should invalidate an invalid TextQuestion", () => {
244
- const invalidTextQuestion = {
245
- type: "text",
246
- meta: {
247
- schemaVersion: "1.0",
248
- },
249
- attributes: {
250
- maxLength: "100", // Invalid type
251
- },
252
- };
253
- expect(() => primitiveQuestions_1.TextQuestionSchema.parse(invalidTextQuestion)).toThrow();
254
- });
255
- it("should validate a valid URLQuestion", () => {
256
- const validURLQuestion = {
257
- type: "url",
258
- meta: {
259
- schemaVersion: "1.0",
260
- },
261
- attributes: {
262
- maxLength: 200,
263
- minLength: 10,
264
- pattern: "https?://.+",
265
- },
266
- };
267
- expect(() => primitiveQuestions_1.URLQuestionSchema.parse(validURLQuestion)).not.toThrow();
268
- });
269
- it("should invalidate an invalid URLQuestion", () => {
270
- const invalidURLQuestion = {
271
- type: "url",
272
- meta: {
273
- schemaVersion: "1.0",
274
- },
275
- attributes: {
276
- maxLength: "200", // Invalid type
277
- },
278
- };
279
- expect(() => primitiveQuestions_1.URLQuestionSchema.parse(invalidURLQuestion)).toThrow();
280
- });
281
- });