@dmptool/types 1.0.4 → 1.0.6

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.
package/README.md CHANGED
@@ -69,8 +69,9 @@ DMP Tool specific extensions to the RDA Common Standard for DMPs
69
69
  Add the DMP Tool types to your `package.json` by running `npm add @dmptool/types`
70
70
 
71
71
  Once added, you can then import the Types and Zod shemas like this:
72
- `import { BooleanQuestion, BooleanQuestionType, CURRENT_SCHEMA_VERSION } from '@dmptool/types';`
72
+ `import { BooleanQuestionSchema, BooleanQuestionType, CURRENT_SCHEMA_VERSION } from '@dmptool/types';`
73
73
 
74
+ // Use the available Type to help define the JSON object
74
75
  const boolQ: BooleanQuestionType = {
75
76
  type: "boolean",
76
77
  attributes: {
@@ -81,13 +82,34 @@ const boolQ: BooleanQuestionType = {
81
82
  }
82
83
  }
83
84
 
84
- const isBoolQ = BooleanQuestion.parse(boolQ);
85
+ // Use the Zod Schema to validate the JSON
86
+ const isBoolQ = BooleanQuestionSchema.parse(boolQ);
85
87
  console.log('isBoolQ', isBoolQ);
86
- console.log(BooleanQuestion.parse(123));
87
88
 
89
+ // Force an error to see (see below for what a Zod error message looks like)
90
+ try {
91
+ BooleanQuestionSchema.parse(123);
92
+ } catch (e) {
93
+ console.log(e.message);
94
+ }
95
+
96
+ // Use the Schema Maps to get the correct Schema for the specificed question type
97
+ try {
98
+ // Validate the questionJSON against the Zod schema
99
+ QuestionSchemaMap[boolQ.type]?.parse(boolQ);
100
+ } catch (e) {
101
+ console.log(e.message);
102
+ }
88
103
 
104
+ // Use the Any unions to generically define a Question or Answer type
105
+ public questionJSON: AnyQuestionType;
106
+
107
+ // Use the QuestionTypesEnum to fetch a list of all the valid question types
108
+ console.log(QuestionTypeEnums);
109
+ ```
89
110
 
90
111
 
112
+ Example Zod error:
91
113
  ```
92
114
  ZodError: [
93
115
  {
@@ -12,7 +12,7 @@ export declare const DatePickerQuestionSchema: z.ZodObject<{
12
12
  }>;
13
13
  } & {
14
14
  type: z.ZodLiteral<"datePicker">;
15
- attributes: z.ZodObject<{
15
+ attributes: z.ZodOptional<z.ZodObject<{
16
16
  max: z.ZodOptional<z.ZodString>;
17
17
  min: z.ZodOptional<z.ZodString>;
18
18
  step: z.ZodOptional<z.ZodNumber>;
@@ -24,29 +24,29 @@ export declare const DatePickerQuestionSchema: z.ZodObject<{
24
24
  max?: string | undefined;
25
25
  min?: string | undefined;
26
26
  step?: number | undefined;
27
- }>;
27
+ }>>;
28
28
  }, "strip", z.ZodTypeAny, {
29
29
  type: "datePicker";
30
30
  meta: {
31
31
  schemaVersion: "1.0";
32
32
  labelTranslationKey?: string | undefined;
33
33
  };
34
- attributes: {
34
+ attributes?: {
35
35
  max?: string | undefined;
36
36
  min?: string | undefined;
37
37
  step?: number | undefined;
38
- };
38
+ } | undefined;
39
39
  }, {
40
40
  type: "datePicker";
41
41
  meta: {
42
42
  schemaVersion: "1.0";
43
43
  labelTranslationKey?: string | undefined;
44
44
  };
45
- attributes: {
45
+ attributes?: {
46
46
  max?: string | undefined;
47
47
  min?: string | undefined;
48
48
  step?: number | undefined;
49
- };
49
+ } | undefined;
50
50
  }>;
51
51
  export declare const DateRangeQuestionSchema: z.ZodObject<{
52
52
  meta: z.ZodObject<{
@@ -10,7 +10,7 @@ exports.DatePickerQuestionSchema = question_1.QuestionSchema.merge(zod_1.z.objec
10
10
  max: zod_1.z.string().optional(), // The maximum date (no default)
11
11
  min: zod_1.z.string().optional(), // The minimum date (no default)
12
12
  step: zod_1.z.number().optional() // The step value (default is 1 day)
13
- })
13
+ }).optional(),
14
14
  }));
15
15
  // Date range question and answer
16
16
  exports.DateRangeQuestionSchema = question_1.QuestionSchema.merge(zod_1.z.object({
@@ -29,7 +29,7 @@ export declare const FilteredSearchQuestionSchema: z.ZodObject<{
29
29
  localQueryId: z.ZodOptional<z.ZodString>;
30
30
  query: z.ZodOptional<z.ZodString>;
31
31
  responseField: z.ZodString;
32
- variables: z.ZodArray<z.ZodObject<{
32
+ variables: z.ZodOptional<z.ZodArray<z.ZodObject<{
33
33
  minLength: z.ZodOptional<z.ZodNumber>;
34
34
  label: z.ZodOptional<z.ZodString>;
35
35
  labelTranslationKey: z.ZodOptional<z.ZodString>;
@@ -50,7 +50,7 @@ export declare const FilteredSearchQuestionSchema: z.ZodObject<{
50
50
  minLength?: number | undefined;
51
51
  label?: string | undefined;
52
52
  defaultValue?: string | undefined;
53
- }>, "many">;
53
+ }>, "many">>;
54
54
  }, "strip", z.ZodTypeAny, {
55
55
  displayFields: {
56
56
  label: string;
@@ -58,16 +58,16 @@ export declare const FilteredSearchQuestionSchema: z.ZodObject<{
58
58
  labelTranslationKey?: string | undefined;
59
59
  }[];
60
60
  responseField: string;
61
- variables: {
61
+ localQueryId?: string | undefined;
62
+ query?: string | undefined;
63
+ variables?: {
62
64
  type: string;
63
65
  name: string;
64
66
  labelTranslationKey?: string | undefined;
65
67
  minLength?: number | undefined;
66
68
  label?: string | undefined;
67
69
  defaultValue?: string | undefined;
68
- }[];
69
- localQueryId?: string | undefined;
70
- query?: string | undefined;
70
+ }[] | undefined;
71
71
  }, {
72
72
  displayFields: {
73
73
  label: string;
@@ -75,16 +75,16 @@ export declare const FilteredSearchQuestionSchema: z.ZodObject<{
75
75
  labelTranslationKey?: string | undefined;
76
76
  }[];
77
77
  responseField: string;
78
- variables: {
78
+ localQueryId?: string | undefined;
79
+ query?: string | undefined;
80
+ variables?: {
79
81
  type: string;
80
82
  name: string;
81
83
  labelTranslationKey?: string | undefined;
82
84
  minLength?: number | undefined;
83
85
  label?: string | undefined;
84
86
  defaultValue?: string | undefined;
85
- }[];
86
- localQueryId?: string | undefined;
87
- query?: string | undefined;
87
+ }[] | undefined;
88
88
  }>;
89
89
  attributes: z.ZodObject<{
90
90
  multiple: z.ZodOptional<z.ZodBoolean>;
@@ -109,16 +109,16 @@ export declare const FilteredSearchQuestionSchema: z.ZodObject<{
109
109
  labelTranslationKey?: string | undefined;
110
110
  }[];
111
111
  responseField: string;
112
- variables: {
112
+ localQueryId?: string | undefined;
113
+ query?: string | undefined;
114
+ variables?: {
113
115
  type: string;
114
116
  name: string;
115
117
  labelTranslationKey?: string | undefined;
116
118
  minLength?: number | undefined;
117
119
  label?: string | undefined;
118
120
  defaultValue?: string | undefined;
119
- }[];
120
- localQueryId?: string | undefined;
121
- query?: string | undefined;
121
+ }[] | undefined;
122
122
  };
123
123
  }, {
124
124
  type: "filteredSearch";
@@ -136,16 +136,16 @@ export declare const FilteredSearchQuestionSchema: z.ZodObject<{
136
136
  labelTranslationKey?: string | undefined;
137
137
  }[];
138
138
  responseField: string;
139
- variables: {
139
+ localQueryId?: string | undefined;
140
+ query?: string | undefined;
141
+ variables?: {
140
142
  type: string;
141
143
  name: string;
142
144
  labelTranslationKey?: string | undefined;
143
145
  minLength?: number | undefined;
144
146
  label?: string | undefined;
145
147
  defaultValue?: string | undefined;
146
- }[];
147
- localQueryId?: string | undefined;
148
- query?: string | undefined;
148
+ }[] | undefined;
149
149
  };
150
150
  }>;
151
151
  export declare const TypeaheadSearchQuestionSchema: z.ZodObject<{
@@ -178,7 +178,7 @@ export declare const TypeaheadSearchQuestionSchema: z.ZodObject<{
178
178
  localQueryId: z.ZodOptional<z.ZodString>;
179
179
  query: z.ZodOptional<z.ZodString>;
180
180
  responseField: z.ZodString;
181
- variables: z.ZodArray<z.ZodObject<{
181
+ variables: z.ZodOptional<z.ZodArray<z.ZodObject<{
182
182
  minLength: z.ZodOptional<z.ZodNumber>;
183
183
  label: z.ZodOptional<z.ZodString>;
184
184
  labelTranslationKey: z.ZodOptional<z.ZodString>;
@@ -199,7 +199,7 @@ export declare const TypeaheadSearchQuestionSchema: z.ZodObject<{
199
199
  minLength?: number | undefined;
200
200
  label?: string | undefined;
201
201
  defaultValue?: string | undefined;
202
- }>, "many">;
202
+ }>, "many">>;
203
203
  }, "strip", z.ZodTypeAny, {
204
204
  displayFields: {
205
205
  label: string;
@@ -207,16 +207,16 @@ export declare const TypeaheadSearchQuestionSchema: z.ZodObject<{
207
207
  labelTranslationKey?: string | undefined;
208
208
  }[];
209
209
  responseField: string;
210
- variables: {
210
+ localQueryId?: string | undefined;
211
+ query?: string | undefined;
212
+ variables?: {
211
213
  type: string;
212
214
  name: string;
213
215
  labelTranslationKey?: string | undefined;
214
216
  minLength?: number | undefined;
215
217
  label?: string | undefined;
216
218
  defaultValue?: string | undefined;
217
- }[];
218
- localQueryId?: string | undefined;
219
- query?: string | undefined;
219
+ }[] | undefined;
220
220
  }, {
221
221
  displayFields: {
222
222
  label: string;
@@ -224,16 +224,16 @@ export declare const TypeaheadSearchQuestionSchema: z.ZodObject<{
224
224
  labelTranslationKey?: string | undefined;
225
225
  }[];
226
226
  responseField: string;
227
- variables: {
227
+ localQueryId?: string | undefined;
228
+ query?: string | undefined;
229
+ variables?: {
228
230
  type: string;
229
231
  name: string;
230
232
  labelTranslationKey?: string | undefined;
231
233
  minLength?: number | undefined;
232
234
  label?: string | undefined;
233
235
  defaultValue?: string | undefined;
234
- }[];
235
- localQueryId?: string | undefined;
236
- query?: string | undefined;
236
+ }[] | undefined;
237
237
  }>;
238
238
  }, "strip", z.ZodTypeAny, {
239
239
  type: "typeaheadSearch";
@@ -248,16 +248,16 @@ export declare const TypeaheadSearchQuestionSchema: z.ZodObject<{
248
248
  labelTranslationKey?: string | undefined;
249
249
  }[];
250
250
  responseField: string;
251
- variables: {
251
+ localQueryId?: string | undefined;
252
+ query?: string | undefined;
253
+ variables?: {
252
254
  type: string;
253
255
  name: string;
254
256
  labelTranslationKey?: string | undefined;
255
257
  minLength?: number | undefined;
256
258
  label?: string | undefined;
257
259
  defaultValue?: string | undefined;
258
- }[];
259
- localQueryId?: string | undefined;
260
- query?: string | undefined;
260
+ }[] | undefined;
261
261
  };
262
262
  }, {
263
263
  type: "typeaheadSearch";
@@ -272,16 +272,16 @@ export declare const TypeaheadSearchQuestionSchema: z.ZodObject<{
272
272
  labelTranslationKey?: string | undefined;
273
273
  }[];
274
274
  responseField: string;
275
- variables: {
275
+ localQueryId?: string | undefined;
276
+ query?: string | undefined;
277
+ variables?: {
276
278
  type: string;
277
279
  name: string;
278
280
  labelTranslationKey?: string | undefined;
279
281
  minLength?: number | undefined;
280
282
  label?: string | undefined;
281
283
  defaultValue?: string | undefined;
282
- }[];
283
- localQueryId?: string | undefined;
284
- query?: string | undefined;
284
+ }[] | undefined;
285
285
  };
286
286
  }>;
287
287
  export type FilteredSearchQuestionType = z.infer<typeof FilteredSearchQuestionSchema>;
@@ -24,7 +24,7 @@ const GraphQLQuery = zod_1.z.object({
24
24
  localQueryId: zod_1.z.string().optional(), // The ID of the query (required if no query)
25
25
  query: zod_1.z.string().optional(), // The GraphQL query to execute (required if no localQueryId)
26
26
  responseField: zod_1.z.string(), // How to get at the location of displayFields in the response
27
- variables: zod_1.z.array(GraphQLVariable) // The variables for the query
27
+ variables: zod_1.z.array(GraphQLVariable).optional() // The variables for the query
28
28
  });
29
29
  // Filtered search question and answer
30
30
  exports.FilteredSearchQuestionSchema = question_1.QuestionSchema.merge(zod_1.z.object({