@dmptool/types 1.0.0 → 1.0.1

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 (47) hide show
  1. package/README.md +33 -2
  2. package/dist/answers/__tests__/answers.spec.d.ts +1 -0
  3. package/dist/answers/__tests__/answers.spec.js +122 -0
  4. package/dist/answers/answer.d.ts +12 -0
  5. package/dist/answers/answer.js +10 -0
  6. package/dist/answers/dateAnswers.d.ts +39 -0
  7. package/dist/answers/dateAnswers.js +16 -0
  8. package/dist/answers/graphQLAnswers.d.ts +23 -0
  9. package/dist/answers/graphQLAnswers.js +14 -0
  10. package/dist/{answers.d.ts → answers/index.d.ts} +102 -268
  11. package/dist/answers/index.js +48 -0
  12. package/dist/answers/optionBasedAnswers.d.ts +34 -0
  13. package/dist/answers/optionBasedAnswers.js +18 -0
  14. package/dist/answers/primitiveAnswers.d.ts +78 -0
  15. package/dist/answers/primitiveAnswers.js +34 -0
  16. package/dist/answers/tableAnswers.d.ts +388 -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 +110 -47
  40. package/dist/schemas/anyTableColumnAnswer.schema.json +267 -0
  41. package/dist/schemas/anyTableColumnQuestion.schema.json +637 -0
  42. package/dist/schemas/tableAnswer.schema.json +2 -2
  43. package/package.json +8 -1
  44. package/dist/answers.js +0 -87
  45. /package/dist/{dateQuestions.d.ts → questions/dateQuestions.d.ts} +0 -0
  46. /package/dist/{graphQLQuestions.d.ts → questions/graphQLQuestions.d.ts} +0 -0
  47. /package/dist/{optionBasedQuestions.d.ts → questions/optionBasedQuestions.d.ts} +0 -0
package/README.md CHANGED
@@ -2,15 +2,45 @@
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
+
5
7
  ## Usage
6
8
 
7
9
  To run tests: `npm run test`
8
10
 
9
11
  To run linter checks: `npm run lint`
10
12
 
11
- To generate JSON schemas from the Zod schemas: `npm run generate`
13
+ To just generate JSON schemas from the Zod schemas: `npm run generate`
14
+
15
+ To build the Types, Zod schemas and JSON schemas all at once: `npm run build`
16
+
17
+ To publish changes:
18
+ - Increment the `version` in `package.json`
19
+ - Run `npm login` and login to you npm account
20
+ - Run `npm publish --access public`
21
+
22
+ To view the current published version run `npm view @dmptool/types`. You should see something like this:
23
+ ```
24
+ @dmptool/types@1.0.0 | MIT | deps: 3 | versions: 1
25
+ TypeScript types for DMPTool
26
+
27
+ dist
28
+ .tarball: https://registry.npmjs.org/@dmptool/types/-/types-1.0.0.tgz
29
+ .shasum: e9b4200e487ed2e4ae0ef342ca75f90bf6bdd335
30
+ .integrity: sha512-wFhYELbbM17VGx7REVaDXi0TJKMXnGJRiwszfXqnKY46QeQvPnktwgYDDuuWaupFZV1jJaSq7cfs6vK1oHeOyA==
31
+ .unpackedSize: 286.4 kB
32
+
33
+ dependencies:
34
+ fs: ^0.0.1-security zod-to-json-schema: ^3.24.5 zod: ^3.24.4
35
+
36
+ maintainers:
37
+ - npm-user-name <email-address>
38
+
39
+ dist-tags:
40
+ latest: 1.0.0
12
41
 
13
- To build the Types, Zod schemas and JSON schemas: `npm run build`
42
+ published 6 minutes ago by npm-user-name <email-address>
43
+ ```
14
44
 
15
45
  ## Types/Schemas
16
46
 
@@ -18,6 +48,7 @@ If you want to work with DMP Templates or Answers to template questions, the fol
18
48
  - CURRENT_SCHEMA_VERSION (the current version of the schemas)
19
49
  - QuestionTypesEnum (Contains the `type` for each Question/Answer below)
20
50
  - AnyQuestion & AnyAnswer (Union of all types below)
51
+ - AnyTableColumnQuestion & AnyTableColumnAnswer (Union of all types except table. Tables cannot be nested)
21
52
  - BooleanQuestion & Boolean Answer
22
53
  - CheckboxesQuestion & Checkboxes Answer
23
54
  - CurrencyQuestion & CurrencyAnswer
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,122 @@
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
+ (0, globals_1.describe)('Answer Type Validations', () => {
11
+ (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();
14
+ const invalidData = { type: 'boolean', answer: 'true' };
15
+ (0, globals_1.expect)(() => primitiveAnswers_1.BooleanAnswer.parse(invalidData)).toThrow();
16
+ });
17
+ (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();
22
+ });
23
+ (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();
28
+ });
29
+ (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();
34
+ });
35
+ (0, globals_1.it)('should validate DateRangeAnswer', () => {
36
+ const validData = {
37
+ type: 'dateRange',
38
+ answer: { start: '2023-10-01', end: '2023-10-31' },
39
+ };
40
+ (0, globals_1.expect)(() => dateAnswers_1.DateRangeAnswer.parse(validData)).not.toThrow();
41
+ const invalidData = {
42
+ type: 'dateRange',
43
+ answer: { start: '2023-10-01', end: 12345 },
44
+ };
45
+ (0, globals_1.expect)(() => dateAnswers_1.DateRangeAnswer.parse(invalidData)).toThrow();
46
+ });
47
+ (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();
50
+ const invalidData = { type: 'email', answer: 12345 };
51
+ (0, globals_1.expect)(() => primitiveAnswers_1.EmailAnswer.parse(invalidData)).toThrow();
52
+ });
53
+ (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();
58
+ });
59
+ (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();
64
+ });
65
+ (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();
70
+ });
71
+ (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();
76
+ });
77
+ (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();
82
+ });
83
+ (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();
88
+ });
89
+ (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();
94
+ });
95
+ (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();
100
+ });
101
+ (0, globals_1.it)('should validate TableAnswer', () => {
102
+ const validData = {
103
+ type: 'table',
104
+ answer: [
105
+ { type: 'text', answer: 'Row 1' },
106
+ { type: 'number', answer: 42 },
107
+ ],
108
+ };
109
+ (0, globals_1.expect)(() => tableAnswers_1.TableAnswer.parse(validData)).not.toThrow();
110
+ const invalidData = {
111
+ type: 'table',
112
+ answer: [{ type: 'text', answer: 12345 }],
113
+ };
114
+ (0, globals_1.expect)(() => tableAnswers_1.TableAnswer.parse(invalidData)).toThrow();
115
+ });
116
+ (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();
121
+ });
122
+ });
@@ -0,0 +1,12 @@
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
+ }, "strip", z.ZodTypeAny, {
6
+ type: "number" | "boolean" | "checkBoxes" | "currency" | "datePicker" | "dateRange" | "email" | "filteredSearch" | "option" | "radioButtons" | "selectBox" | "table" | "text" | "textArea" | "typeaheadSearch" | "url";
7
+ answer: string;
8
+ }, {
9
+ type: "number" | "boolean" | "checkBoxes" | "currency" | "datePicker" | "dateRange" | "email" | "filteredSearch" | "option" | "radioButtons" | "selectBox" | "table" | "text" | "textArea" | "typeaheadSearch" | "url";
10
+ answer: string;
11
+ }>;
12
+ export type AnswerType = z.infer<typeof Answer>;
@@ -0,0 +1,10 @@
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
+ });
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ export declare const DatePickerAnswer: z.ZodObject<{
3
+ answer: z.ZodString;
4
+ } & {
5
+ type: z.ZodLiteral<"datePicker">;
6
+ }, "strip", z.ZodTypeAny, {
7
+ type: "datePicker";
8
+ answer: string;
9
+ }, {
10
+ type: "datePicker";
11
+ answer: string;
12
+ }>;
13
+ export declare const DateRangeAnswer: z.ZodObject<{} & {
14
+ type: z.ZodLiteral<"dateRange">;
15
+ answer: z.ZodObject<{
16
+ start: z.ZodString;
17
+ end: z.ZodString;
18
+ }, "strip", z.ZodTypeAny, {
19
+ start: string;
20
+ end: string;
21
+ }, {
22
+ start: string;
23
+ end: string;
24
+ }>;
25
+ }, "strip", z.ZodTypeAny, {
26
+ type: "dateRange";
27
+ answer: {
28
+ start: string;
29
+ end: string;
30
+ };
31
+ }, {
32
+ type: "dateRange";
33
+ answer: {
34
+ start: string;
35
+ end: string;
36
+ };
37
+ }>;
38
+ export type DatePickerAnswerType = z.infer<typeof DatePickerAnswer>;
39
+ 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,23 @@
1
+ import { z } from 'zod';
2
+ export declare const FilteredSearchAnswer: z.ZodObject<{} & {
3
+ type: z.ZodLiteral<"filteredSearch">;
4
+ answer: z.ZodArray<z.ZodString, "many">;
5
+ }, "strip", z.ZodTypeAny, {
6
+ type: "filteredSearch";
7
+ answer: string[];
8
+ }, {
9
+ type: "filteredSearch";
10
+ answer: string[];
11
+ }>;
12
+ export declare const TypeaheadSearchAnswer: z.ZodObject<{} & {
13
+ type: z.ZodLiteral<"typeaheadSearch">;
14
+ answer: z.ZodString;
15
+ }, "strip", z.ZodTypeAny, {
16
+ type: "typeaheadSearch";
17
+ answer: string;
18
+ }, {
19
+ type: "typeaheadSearch";
20
+ answer: string;
21
+ }>;
22
+ export type FilteredSearchAnswerType = z.infer<typeof FilteredSearchAnswer>;
23
+ 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
+ }));