@dmptool/types 2.3.2 → 3.0.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.
- package/dist/dmp/index.d.ts +2 -2
- package/dist/dmp/index.js +65 -50
- package/dist/questions/__tests__/defaults.spec.js +12 -12
- package/dist/questions/__tests__/optionBasedQuestions.spec.js +3 -3
- package/dist/questions/index.d.ts +22 -5
- package/dist/questions/index.js +2 -2
- package/dist/questions/optionBasedQuestions.d.ts +8 -2
- package/dist/questions/optionBasedQuestions.js +6 -6
- package/dist/questions/tableQuestions.d.ts +77 -8
- package/dist/questions/tableQuestions.js +3 -3
- package/dist/questions/textQuestions.d.ts +8 -0
- package/dist/questions/textQuestions.js +1 -1
- package/dist/schemas/anyQuestion.schema.json +64 -9
- package/dist/schemas/anyTableColumnQuestion.schema.json +22 -3
- package/dist/schemas/checkboxesQuestion.schema.json +2 -3
- package/dist/schemas/emailQuestion.schema.json +3 -0
- package/dist/schemas/multiselectBoxQuestion.schema.json +4 -0
- package/dist/schemas/radioButtonsQuestion.schema.json +4 -0
- package/dist/schemas/researchOutputTableQuestion.schema.json +1455 -61
- package/dist/schemas/selectBoxQuestion.schema.json +4 -0
- package/dist/schemas/tableQuestion.schema.json +22 -3
- package/dist/schemas/textAreaQuestion.schema.json +3 -0
- package/dist/schemas/textQuestion.schema.json +3 -0
- package/dist/schemas/urlQuestion.schema.json +3 -0
- package/package.json +2 -2
- package/schemas/anyQuestion.schema.json +64 -9
- package/schemas/anyTableColumnQuestion.schema.json +22 -3
- package/schemas/checkboxesQuestion.schema.json +2 -3
- package/schemas/emailQuestion.schema.json +3 -0
- package/schemas/multiselectBoxQuestion.schema.json +4 -0
- package/schemas/radioButtonsQuestion.schema.json +4 -0
- package/schemas/researchOutputTableQuestion.schema.json +1455 -61
- package/schemas/selectBoxQuestion.schema.json +4 -0
- package/schemas/tableQuestion.schema.json +22 -3
- package/schemas/textAreaQuestion.schema.json +3 -0
- package/schemas/textQuestion.schema.json +3 -0
- package/schemas/urlQuestion.schema.json +3 -0
package/dist/dmp/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { z } from "zod";
|
|
|
2
2
|
import { FromSchema } from "json-schema-to-ts";
|
|
3
3
|
import { ExtensionSchema } from "./extension";
|
|
4
4
|
export declare const RDA_COMMON_STANDARD_VERSION = "1.2";
|
|
5
|
-
declare
|
|
5
|
+
declare let rdaSchemaJson: any;
|
|
6
6
|
export declare const RDACommonStandardDMPJSONSchema: any;
|
|
7
|
-
export type RDACommonStandardDMPType = FromSchema<typeof
|
|
7
|
+
export type RDACommonStandardDMPType = FromSchema<typeof rdaSchemaJson>;
|
|
8
8
|
export type DMPToolExtensionType = z.infer<typeof ExtensionSchema>;
|
|
9
9
|
export declare const DMPToolExtensionSchema: z.ZodObject<{
|
|
10
10
|
rda_schema_version: z.ZodDefault<z.ZodString>;
|
package/dist/dmp/index.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.ExtensionJSONSchema = exports.DMPToolExtensionSchema = exports.RDACommonStandardDMPJSONSchema = exports.RDA_COMMON_STANDARD_VERSION = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
4
|
const zod_1 = require("zod");
|
|
10
5
|
const extension_1 = require("./extension");
|
|
11
6
|
// The RDA Common Standard for DMPs JSON schema is automatically downloaded by
|
|
@@ -23,57 +18,77 @@ const extension_1 = require("./extension");
|
|
|
23
18
|
// to work with a reference to this constant (or any variable really and
|
|
24
19
|
// requires all defaults be hard-coded values!), so be sure to update the
|
|
25
20
|
// `extension.ts` file to set the version there as well.
|
|
21
|
+
// Define the curret version of the RDA Common Standard
|
|
26
22
|
exports.RDA_COMMON_STANDARD_VERSION = "1.2";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
24
|
+
let rdaSchemaJson;
|
|
25
|
+
try {
|
|
26
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
27
|
+
rdaSchemaJson = require("../schemas/dmp.schema.json");
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
// Fallback for environments that need runtime resolution
|
|
31
|
+
if (typeof window === 'undefined') {
|
|
32
|
+
// Only try fs operations on server
|
|
33
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
34
|
+
const fs = require("fs");
|
|
35
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
36
|
+
const path = require("path");
|
|
37
|
+
// Convert the downloaded JSON schema into types
|
|
38
|
+
// First try resolving via the package export (works when installed from GitHub branch or npm)
|
|
39
|
+
function resolveSchemaPath() {
|
|
40
|
+
try {
|
|
41
|
+
// require.resolve respects the "exports" map in package.json
|
|
42
|
+
const resolved = require.resolve("@dmptool/types/schemas/dmp.schema.json");
|
|
43
|
+
if (fs.existsSync(resolved)) {
|
|
44
|
+
return resolved;
|
|
45
|
+
}
|
|
46
|
+
// If require.resolve found a path but it doesn't exist, log it for debugging
|
|
47
|
+
console.warn(`[dmptool-types] require.resolve found path but it doesn't exist: ${resolved}`);
|
|
48
|
+
}
|
|
49
|
+
catch (_a) {
|
|
50
|
+
// ignore and fall back to local paths below
|
|
51
|
+
}
|
|
52
|
+
// Fallbacks based on local file structure when running from source or built dist
|
|
53
|
+
// This handles multiple installation scenarios:
|
|
54
|
+
// 1. npm/published package with dist/schemas
|
|
55
|
+
// 2. Source code with ts-node/ts-node-dev
|
|
56
|
+
// 3. GitHub branch installation where dist is gitignored but schemas/ is committed
|
|
57
|
+
const schemaCandidatePaths = [
|
|
58
|
+
// When running compiled code from dist: dist/dmp/index.js -> dist/schemas/dmp.schema.json
|
|
59
|
+
path.resolve(__dirname, "..", "schemas", "dmp.schema.json"),
|
|
60
|
+
// When running from source with ts-node: src/dmp/index.ts -> compiled as dist/dmp/index.js -> schemas/dmp.schema.json at repo root
|
|
61
|
+
path.resolve(__dirname, "..", "..", "schemas", "dmp.schema.json"),
|
|
62
|
+
// When installed as node_module from GitHub: node_modules/@dmptool/types/dist/dmp/index.js
|
|
63
|
+
// Go up to package root, then into schemas: dist/dmp -> dist -> package_root -> schemas
|
|
64
|
+
path.resolve(__dirname, "..", "..", "..", "schemas", "dmp.schema.json"),
|
|
65
|
+
];
|
|
66
|
+
// Remove duplicates while preserving order
|
|
67
|
+
const uniquePaths = Array.from(new Set(schemaCandidatePaths));
|
|
68
|
+
return uniquePaths.find((candidate) => fs.existsSync(candidate));
|
|
69
|
+
}
|
|
70
|
+
const RDA_COMMON_STANDARD_JSON_FILE = resolveSchemaPath();
|
|
71
|
+
if (!RDA_COMMON_STANDARD_JSON_FILE) {
|
|
72
|
+
const attemptedPaths = [
|
|
73
|
+
path.resolve(__dirname, "..", "schemas", "dmp.schema.json"),
|
|
74
|
+
path.resolve(__dirname, "..", "..", "schemas", "dmp.schema.json"),
|
|
75
|
+
path.resolve(__dirname, "..", "..", "..", "schemas", "dmp.schema.json"),
|
|
76
|
+
];
|
|
77
|
+
throw new Error(`Unable to locate dmp.schema.json. Current __dirname: ${__dirname}. Attempted paths: ${attemptedPaths.join(", ")}`);
|
|
78
|
+
}
|
|
79
|
+
// Double-check the file exists before trying to read it
|
|
80
|
+
if (!fs.existsSync(RDA_COMMON_STANDARD_JSON_FILE)) {
|
|
81
|
+
throw new Error(`Schema file path was resolved to ${RDA_COMMON_STANDARD_JSON_FILE} but the file does not exist. This may indicate an issue with the package installation or build process.`);
|
|
36
82
|
}
|
|
37
|
-
|
|
38
|
-
console.warn(`[dmptool-types] require.resolve found path but it doesn't exist: ${resolved}`);
|
|
83
|
+
rdaSchemaJson = JSON.parse(fs.readFileSync(RDA_COMMON_STANDARD_JSON_FILE, "utf8"));
|
|
39
84
|
}
|
|
40
|
-
|
|
41
|
-
|
|
85
|
+
else {
|
|
86
|
+
throw new Error("Schema must be bundled for browser use or the package must include schemas/ directory");
|
|
42
87
|
}
|
|
43
|
-
// Fallbacks based on local file structure when running from source or built dist
|
|
44
|
-
// This handles multiple installation scenarios:
|
|
45
|
-
// 1. npm/published package with dist/schemas
|
|
46
|
-
// 2. Source code with ts-node/ts-node-dev
|
|
47
|
-
// 3. GitHub branch installation where dist is gitignored but schemas/ is committed
|
|
48
|
-
const schemaCandidatePaths = [
|
|
49
|
-
// When running compiled code from dist: dist/dmp/index.js -> dist/schemas/dmp.schema.json
|
|
50
|
-
path_1.default.resolve(__dirname, "..", "schemas", "dmp.schema.json"),
|
|
51
|
-
// When running from source with ts-node: src/dmp/index.ts -> compiled as dist/dmp/index.js -> schemas/dmp.schema.json at repo root
|
|
52
|
-
path_1.default.resolve(__dirname, "..", "..", "schemas", "dmp.schema.json"),
|
|
53
|
-
// When installed as node_module from GitHub: node_modules/@dmptool/types/dist/dmp/index.js
|
|
54
|
-
// Go up to package root, then into schemas: dist/dmp -> dist -> package_root -> schemas
|
|
55
|
-
path_1.default.resolve(__dirname, "..", "..", "..", "schemas", "dmp.schema.json"),
|
|
56
|
-
];
|
|
57
|
-
// Remove duplicates while preserving order
|
|
58
|
-
const uniquePaths = Array.from(new Set(schemaCandidatePaths));
|
|
59
|
-
return uniquePaths.find((candidate) => fs_1.default.existsSync(candidate));
|
|
60
|
-
}
|
|
61
|
-
const RDA_COMMON_STANDARD_JSON_FILE = resolveSchemaPath();
|
|
62
|
-
if (!RDA_COMMON_STANDARD_JSON_FILE) {
|
|
63
|
-
const attemptedPaths = [
|
|
64
|
-
path_1.default.resolve(__dirname, "..", "schemas", "dmp.schema.json"),
|
|
65
|
-
path_1.default.resolve(__dirname, "..", "..", "schemas", "dmp.schema.json"),
|
|
66
|
-
path_1.default.resolve(__dirname, "..", "..", "..", "schemas", "dmp.schema.json"),
|
|
67
|
-
];
|
|
68
|
-
throw new Error(`Unable to locate dmp.schema.json. Current __dirname: ${__dirname}. Attempted paths: ${attemptedPaths.join(", ")}`);
|
|
69
|
-
}
|
|
70
|
-
// Double-check the file exists before trying to read it
|
|
71
|
-
if (!fs_1.default.existsSync(RDA_COMMON_STANDARD_JSON_FILE)) {
|
|
72
|
-
throw new Error(`Schema file path was resolved to ${RDA_COMMON_STANDARD_JSON_FILE} but the file does not exist. This may indicate an issue with the package installation or build process.`);
|
|
73
88
|
}
|
|
74
89
|
// Ignoring ESLint here because it doesn't like that we're only using jsonSchema as a Type
|
|
75
90
|
// but that's exactly what we want to do.
|
|
76
|
-
|
|
77
|
-
|
|
91
|
+
exports.RDACommonStandardDMPJSONSchema = rdaSchemaJson;
|
|
92
|
+
;
|
|
78
93
|
exports.DMPToolExtensionSchema = extension_1.ExtensionSchema;
|
|
79
94
|
exports.ExtensionJSONSchema = zod_1.z.toJSONSchema(extension_1.ExtensionSchema);
|
|
@@ -53,7 +53,7 @@ describe('questions return the expected defaults', () => {
|
|
|
53
53
|
type: "checkBoxes",
|
|
54
54
|
attributes: {},
|
|
55
55
|
meta: { schemaVersion: "1.0" },
|
|
56
|
-
options: [{ label: 'Option A',
|
|
56
|
+
options: [{ label: 'Option A', selected: false, value: 'a' }]
|
|
57
57
|
};
|
|
58
58
|
(0, globals_1.expect)(optionBasedQuestions_1.DefaultCheckboxesQuestion).toEqual(expected);
|
|
59
59
|
});
|
|
@@ -194,7 +194,7 @@ describe('questions return the expected defaults', () => {
|
|
|
194
194
|
type: "multiselectBox",
|
|
195
195
|
attributes: { multiple: true },
|
|
196
196
|
meta: { schemaVersion: "1.0" },
|
|
197
|
-
options: [{ label: 'Option A', value: 'a' }]
|
|
197
|
+
options: [{ label: 'Option A', value: 'a', selected: false }]
|
|
198
198
|
};
|
|
199
199
|
(0, globals_1.expect)(optionBasedQuestions_1.DefaultMultiselectBoxQuestion).toEqual(expected);
|
|
200
200
|
});
|
|
@@ -231,7 +231,7 @@ describe('questions return the expected defaults', () => {
|
|
|
231
231
|
type: "radioButtons",
|
|
232
232
|
attributes: {},
|
|
233
233
|
meta: { schemaVersion: "1.0" },
|
|
234
|
-
options: [{ label: 'Option A', value: 'a' }]
|
|
234
|
+
options: [{ label: 'Option A', value: 'a', selected: false }]
|
|
235
235
|
};
|
|
236
236
|
(0, globals_1.expect)(optionBasedQuestions_1.DefaultRadioButtonsQuestion).toEqual(expected);
|
|
237
237
|
});
|
|
@@ -284,9 +284,9 @@ describe('questions return the expected defaults', () => {
|
|
|
284
284
|
type: "selectBox",
|
|
285
285
|
attributes: { multiple: false },
|
|
286
286
|
options: [
|
|
287
|
-
{ label: 'Dataset', value: 'dataset' },
|
|
288
|
-
{ label: 'Software', value: 'software' },
|
|
289
|
-
{ label: 'Other', value: 'other' }
|
|
287
|
+
{ label: 'Dataset', value: 'dataset', selected: false },
|
|
288
|
+
{ label: 'Software', value: 'software', selected: false },
|
|
289
|
+
{ label: 'Other', value: 'other', selected: false }
|
|
290
290
|
],
|
|
291
291
|
meta: { schemaVersion: "1.0" }
|
|
292
292
|
}
|
|
@@ -305,12 +305,12 @@ describe('questions return the expected defaults', () => {
|
|
|
305
305
|
{
|
|
306
306
|
label: 'May contain sensitive data?',
|
|
307
307
|
value: 'sensitive',
|
|
308
|
-
|
|
308
|
+
selected: false
|
|
309
309
|
},
|
|
310
310
|
{
|
|
311
311
|
label: 'May contain personally identifiable information?',
|
|
312
312
|
value: 'personal',
|
|
313
|
-
|
|
313
|
+
selected: false
|
|
314
314
|
},
|
|
315
315
|
]
|
|
316
316
|
}
|
|
@@ -326,9 +326,9 @@ describe('questions return the expected defaults', () => {
|
|
|
326
326
|
meta: { schemaVersion: "1.0" },
|
|
327
327
|
attributes: {},
|
|
328
328
|
options: [
|
|
329
|
-
{ label: 'Open Access', value: 'open' },
|
|
330
|
-
{ label: 'Restricted Access', value: 'restricted' },
|
|
331
|
-
{ label: 'Other', value: 'closed' },
|
|
329
|
+
{ label: 'Open Access', value: 'open', selected: false },
|
|
330
|
+
{ label: 'Restricted Access', value: 'restricted', selected: false },
|
|
331
|
+
{ label: 'Other', value: 'closed', selected: false },
|
|
332
332
|
]
|
|
333
333
|
}
|
|
334
334
|
},
|
|
@@ -640,7 +640,7 @@ describe('questions return the expected defaults', () => {
|
|
|
640
640
|
type: "selectBox",
|
|
641
641
|
attributes: { multiple: false },
|
|
642
642
|
meta: { schemaVersion: "1.0" },
|
|
643
|
-
options: [{ label: 'Option A', value: 'a' }]
|
|
643
|
+
options: [{ label: 'Option A', value: 'a', selected: false }]
|
|
644
644
|
};
|
|
645
645
|
(0, globals_1.expect)(optionBasedQuestions_1.DefaultSelectBoxQuestion).toEqual(expected);
|
|
646
646
|
});
|
|
@@ -53,12 +53,12 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
53
53
|
{
|
|
54
54
|
label: "Apple",
|
|
55
55
|
value: "apple",
|
|
56
|
-
|
|
56
|
+
selected: true,
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
label: "Banana",
|
|
60
60
|
value: "banana",
|
|
61
|
-
|
|
61
|
+
selected: false,
|
|
62
62
|
},
|
|
63
63
|
],
|
|
64
64
|
meta: {
|
|
@@ -79,7 +79,7 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
79
79
|
{
|
|
80
80
|
label: "Apple",
|
|
81
81
|
value: "apple",
|
|
82
|
-
|
|
82
|
+
selected: "true", // Invalid type for checked
|
|
83
83
|
},
|
|
84
84
|
],
|
|
85
85
|
meta: {
|
|
@@ -5,7 +5,7 @@ import { DefaultEmailQuestion, DefaultTextAreaQuestion, DefaultTextQuestion, Def
|
|
|
5
5
|
import { DateQuestionType, DateRangeQuestionType, DefaultDateQuestion, DefaultDateRangeQuestion } from "./dateQuestions";
|
|
6
6
|
import { BooleanQuestionType, CheckboxesQuestionType, RadioButtonsQuestionType, SelectBoxQuestionType, MultiselectBoxQuestionType, DefaultCheckboxesQuestion, DefaultMultiselectBoxQuestion, DefaultRadioButtonsQuestion, DefaultSelectBoxQuestion, DefaultBooleanQuestion } from './optionBasedQuestions';
|
|
7
7
|
import { AffiliationSearchQuestionType, DefaultAffiliationSearchQuestion, DefaultLicenseSearchQuestion, DefaultMetadataStandardSearchQuestion, DefaultRepositorySearchQuestion, LicenseSearchQuestionType, MetadataStandardSearchQuestionType, RepositorySearchQuestionType } from './graphQLQuestions';
|
|
8
|
-
import { TableQuestionType, ResearchOutputTableQuestionType, DefaultResearchOutputTableQuestion, DefaultTableQuestion } from './tableQuestions';
|
|
8
|
+
import { TableQuestionType, ResearchOutputTableQuestionType, DefaultResearchOutputTableQuestion, DefaultTableQuestion, DefaultResearchOutputCustomColumn } from './tableQuestions';
|
|
9
9
|
export * from './question';
|
|
10
10
|
export * from './dateQuestions';
|
|
11
11
|
export * from './graphQLQuestions';
|
|
@@ -60,10 +60,10 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
60
60
|
}, z.core.$strip>, z.ZodObject<{
|
|
61
61
|
type: z.ZodLiteral<"checkBoxes">;
|
|
62
62
|
options: z.ZodArray<z.ZodObject<{
|
|
63
|
-
checked: z.ZodDefault<z.ZodBoolean>;
|
|
64
63
|
label: z.ZodDefault<z.ZodString>;
|
|
65
64
|
value: z.ZodDefault<z.ZodString>;
|
|
66
65
|
description: z.ZodOptional<z.ZodString>;
|
|
66
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
67
67
|
}, z.core.$strip>>;
|
|
68
68
|
showCommentField: z.ZodOptional<z.ZodBoolean>;
|
|
69
69
|
attributes: z.ZodObject<{
|
|
@@ -147,6 +147,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
147
147
|
maxLength: z.ZodDefault<z.ZodNumber>;
|
|
148
148
|
minLength: z.ZodOptional<z.ZodNumber>;
|
|
149
149
|
pattern: z.ZodOptional<z.ZodString>;
|
|
150
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
150
151
|
label: z.ZodOptional<z.ZodString>;
|
|
151
152
|
help: z.ZodOptional<z.ZodString>;
|
|
152
153
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
@@ -227,6 +228,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
227
228
|
label: z.ZodDefault<z.ZodString>;
|
|
228
229
|
value: z.ZodDefault<z.ZodString>;
|
|
229
230
|
description: z.ZodOptional<z.ZodString>;
|
|
231
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
230
232
|
}, z.core.$strip>>;
|
|
231
233
|
attributes: z.ZodObject<{
|
|
232
234
|
multiple: z.ZodLiteral<true>;
|
|
@@ -293,6 +295,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
293
295
|
label: z.ZodDefault<z.ZodString>;
|
|
294
296
|
value: z.ZodDefault<z.ZodString>;
|
|
295
297
|
description: z.ZodOptional<z.ZodString>;
|
|
298
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
296
299
|
}, z.core.$strip>>;
|
|
297
300
|
showCommentField: z.ZodOptional<z.ZodBoolean>;
|
|
298
301
|
attributes: z.ZodObject<{
|
|
@@ -350,6 +353,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
350
353
|
maxLength: z.ZodDefault<z.ZodNumber>;
|
|
351
354
|
minLength: z.ZodOptional<z.ZodNumber>;
|
|
352
355
|
pattern: z.ZodOptional<z.ZodString>;
|
|
356
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
353
357
|
label: z.ZodOptional<z.ZodString>;
|
|
354
358
|
help: z.ZodOptional<z.ZodString>;
|
|
355
359
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
@@ -374,6 +378,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
374
378
|
maxLength: z.ZodDefault<z.ZodNumber>;
|
|
375
379
|
minLength: z.ZodOptional<z.ZodNumber>;
|
|
376
380
|
pattern: z.ZodOptional<z.ZodString>;
|
|
381
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
377
382
|
label: z.ZodOptional<z.ZodString>;
|
|
378
383
|
help: z.ZodOptional<z.ZodString>;
|
|
379
384
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
@@ -397,6 +402,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
397
402
|
label: z.ZodDefault<z.ZodString>;
|
|
398
403
|
value: z.ZodDefault<z.ZodString>;
|
|
399
404
|
description: z.ZodOptional<z.ZodString>;
|
|
405
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
400
406
|
}, z.core.$strip>>;
|
|
401
407
|
attributes: z.ZodObject<{
|
|
402
408
|
multiple: z.ZodLiteral<false>;
|
|
@@ -420,10 +426,10 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
420
426
|
content: z.ZodObject<{
|
|
421
427
|
type: z.ZodLiteral<"checkBoxes">;
|
|
422
428
|
options: z.ZodArray<z.ZodObject<{
|
|
423
|
-
checked: z.ZodDefault<z.ZodBoolean>;
|
|
424
429
|
label: z.ZodDefault<z.ZodString>;
|
|
425
430
|
value: z.ZodDefault<z.ZodString>;
|
|
426
431
|
description: z.ZodOptional<z.ZodString>;
|
|
432
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
427
433
|
}, z.core.$strip>>;
|
|
428
434
|
showCommentField: z.ZodOptional<z.ZodBoolean>;
|
|
429
435
|
attributes: z.ZodObject<{
|
|
@@ -449,6 +455,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
449
455
|
label: z.ZodDefault<z.ZodString>;
|
|
450
456
|
value: z.ZodDefault<z.ZodString>;
|
|
451
457
|
description: z.ZodOptional<z.ZodString>;
|
|
458
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
452
459
|
}, z.core.$strip>>;
|
|
453
460
|
showCommentField: z.ZodOptional<z.ZodBoolean>;
|
|
454
461
|
attributes: z.ZodObject<{
|
|
@@ -688,6 +695,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
688
695
|
label: z.ZodDefault<z.ZodString>;
|
|
689
696
|
value: z.ZodDefault<z.ZodString>;
|
|
690
697
|
description: z.ZodOptional<z.ZodString>;
|
|
698
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
691
699
|
}, z.core.$strip>>;
|
|
692
700
|
attributes: z.ZodObject<{
|
|
693
701
|
multiple: z.ZodLiteral<false>;
|
|
@@ -755,10 +763,10 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
755
763
|
}, z.core.$strip>, z.ZodObject<{
|
|
756
764
|
type: z.ZodLiteral<"checkBoxes">;
|
|
757
765
|
options: z.ZodArray<z.ZodObject<{
|
|
758
|
-
checked: z.ZodDefault<z.ZodBoolean>;
|
|
759
766
|
label: z.ZodDefault<z.ZodString>;
|
|
760
767
|
value: z.ZodDefault<z.ZodString>;
|
|
761
768
|
description: z.ZodOptional<z.ZodString>;
|
|
769
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
762
770
|
}, z.core.$strip>>;
|
|
763
771
|
showCommentField: z.ZodOptional<z.ZodBoolean>;
|
|
764
772
|
attributes: z.ZodObject<{
|
|
@@ -842,6 +850,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
842
850
|
maxLength: z.ZodDefault<z.ZodNumber>;
|
|
843
851
|
minLength: z.ZodOptional<z.ZodNumber>;
|
|
844
852
|
pattern: z.ZodOptional<z.ZodString>;
|
|
853
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
845
854
|
label: z.ZodOptional<z.ZodString>;
|
|
846
855
|
help: z.ZodOptional<z.ZodString>;
|
|
847
856
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
@@ -960,6 +969,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
960
969
|
label: z.ZodDefault<z.ZodString>;
|
|
961
970
|
value: z.ZodDefault<z.ZodString>;
|
|
962
971
|
description: z.ZodOptional<z.ZodString>;
|
|
972
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
963
973
|
}, z.core.$strip>>;
|
|
964
974
|
showCommentField: z.ZodOptional<z.ZodBoolean>;
|
|
965
975
|
attributes: z.ZodObject<{
|
|
@@ -1010,6 +1020,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1010
1020
|
label: z.ZodDefault<z.ZodString>;
|
|
1011
1021
|
value: z.ZodDefault<z.ZodString>;
|
|
1012
1022
|
description: z.ZodOptional<z.ZodString>;
|
|
1023
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
1013
1024
|
}, z.core.$strip>>;
|
|
1014
1025
|
attributes: z.ZodObject<{
|
|
1015
1026
|
multiple: z.ZodLiteral<false>;
|
|
@@ -1032,6 +1043,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1032
1043
|
maxLength: z.ZodDefault<z.ZodNumber>;
|
|
1033
1044
|
minLength: z.ZodOptional<z.ZodNumber>;
|
|
1034
1045
|
pattern: z.ZodOptional<z.ZodString>;
|
|
1046
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
1035
1047
|
label: z.ZodOptional<z.ZodString>;
|
|
1036
1048
|
help: z.ZodOptional<z.ZodString>;
|
|
1037
1049
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
@@ -1047,6 +1059,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1047
1059
|
maxLength: z.ZodDefault<z.ZodNumber>;
|
|
1048
1060
|
minLength: z.ZodOptional<z.ZodNumber>;
|
|
1049
1061
|
pattern: z.ZodOptional<z.ZodString>;
|
|
1062
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
1050
1063
|
label: z.ZodOptional<z.ZodString>;
|
|
1051
1064
|
help: z.ZodOptional<z.ZodString>;
|
|
1052
1065
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
@@ -1062,6 +1075,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1062
1075
|
maxLength: z.ZodDefault<z.ZodNumber>;
|
|
1063
1076
|
minLength: z.ZodOptional<z.ZodNumber>;
|
|
1064
1077
|
pattern: z.ZodOptional<z.ZodString>;
|
|
1078
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
1065
1079
|
label: z.ZodOptional<z.ZodString>;
|
|
1066
1080
|
help: z.ZodOptional<z.ZodString>;
|
|
1067
1081
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
@@ -1098,6 +1112,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1098
1112
|
maxLength: z.ZodDefault<z.ZodNumber>;
|
|
1099
1113
|
minLength: z.ZodOptional<z.ZodNumber>;
|
|
1100
1114
|
pattern: z.ZodOptional<z.ZodString>;
|
|
1115
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
1101
1116
|
label: z.ZodOptional<z.ZodString>;
|
|
1102
1117
|
help: z.ZodOptional<z.ZodString>;
|
|
1103
1118
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
@@ -1113,6 +1128,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1113
1128
|
maxLength: z.ZodDefault<z.ZodNumber>;
|
|
1114
1129
|
minLength: z.ZodOptional<z.ZodNumber>;
|
|
1115
1130
|
pattern: z.ZodOptional<z.ZodString>;
|
|
1131
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
1116
1132
|
label: z.ZodOptional<z.ZodString>;
|
|
1117
1133
|
help: z.ZodOptional<z.ZodString>;
|
|
1118
1134
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
@@ -1128,6 +1144,7 @@ export declare const AnyQuestionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1128
1144
|
maxLength: z.ZodDefault<z.ZodNumber>;
|
|
1129
1145
|
minLength: z.ZodOptional<z.ZodNumber>;
|
|
1130
1146
|
pattern: z.ZodOptional<z.ZodString>;
|
|
1147
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
1131
1148
|
label: z.ZodOptional<z.ZodString>;
|
|
1132
1149
|
help: z.ZodOptional<z.ZodString>;
|
|
1133
1150
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
@@ -1163,7 +1180,7 @@ export interface QuestionTypeMap {
|
|
|
1163
1180
|
textArea: TextAreaQuestionType;
|
|
1164
1181
|
url: URLQuestionType;
|
|
1165
1182
|
}
|
|
1166
|
-
export type AllDefaultQuestionTypes = typeof DefaultAffiliationSearchQuestion | typeof DefaultBooleanQuestion | typeof DefaultCheckboxesQuestion | typeof DefaultCurrencyQuestion | typeof DefaultDateQuestion | typeof DefaultDateRangeQuestion | typeof DefaultEmailQuestion | typeof DefaultLicenseSearchQuestion | typeof DefaultMetadataStandardSearchQuestion | typeof DefaultMultiselectBoxQuestion | typeof DefaultNumberQuestion | typeof DefaultNumberRangeQuestion | typeof DefaultNumberWithContextQuestion | typeof DefaultRadioButtonsQuestion | typeof DefaultRepositorySearchQuestion | typeof DefaultResearchOutputTableQuestion | typeof DefaultSelectBoxQuestion | typeof DefaultTableQuestion | typeof DefaultTextAreaQuestion | typeof DefaultTextQuestion | typeof DefaultURLQuestion;
|
|
1183
|
+
export type AllDefaultQuestionTypes = typeof DefaultAffiliationSearchQuestion | typeof DefaultBooleanQuestion | typeof DefaultCheckboxesQuestion | typeof DefaultCurrencyQuestion | typeof DefaultDateQuestion | typeof DefaultDateRangeQuestion | typeof DefaultEmailQuestion | typeof DefaultLicenseSearchQuestion | typeof DefaultMetadataStandardSearchQuestion | typeof DefaultMultiselectBoxQuestion | typeof DefaultNumberQuestion | typeof DefaultNumberRangeQuestion | typeof DefaultNumberWithContextQuestion | typeof DefaultRadioButtonsQuestion | typeof DefaultRepositorySearchQuestion | typeof DefaultResearchOutputTableQuestion | typeof DefaultResearchOutputCustomColumn | typeof DefaultSelectBoxQuestion | typeof DefaultTableQuestion | typeof DefaultTextAreaQuestion | typeof DefaultTextQuestion | typeof DefaultURLQuestion;
|
|
1167
1184
|
export declare const QuestionDefaultMap: Record<z.infer<typeof QuestionFormatsEnum>, AllDefaultQuestionTypes>;
|
|
1168
1185
|
export type AnyQuestionType = z.infer<typeof AnyQuestionSchema>;
|
|
1169
1186
|
export declare const AnyQuestionJSONSchema: z.core.JSONSchema.JSONSchema;
|
package/dist/questions/index.js
CHANGED
|
@@ -80,7 +80,7 @@ exports.QuestionSchemaMap = {
|
|
|
80
80
|
// Export a mapping between the Types and their corresponding default structures
|
|
81
81
|
exports.QuestionDefaultMap = {
|
|
82
82
|
affiliationSearch: graphQLQuestions_1.DefaultAffiliationSearchQuestion,
|
|
83
|
-
boolean:
|
|
83
|
+
boolean: optionBasedQuestions_1.DefaultBooleanQuestion,
|
|
84
84
|
checkBoxes: optionBasedQuestions_1.DefaultCheckboxesQuestion,
|
|
85
85
|
currency: numberQuestions_1.DefaultCurrencyQuestion,
|
|
86
86
|
date: dateQuestions_1.DefaultDateQuestion,
|
|
@@ -96,7 +96,7 @@ exports.QuestionDefaultMap = {
|
|
|
96
96
|
repositorySearch: graphQLQuestions_1.DefaultRepositorySearchQuestion,
|
|
97
97
|
researchOutputTable: tableQuestions_1.DefaultResearchOutputTableQuestion,
|
|
98
98
|
selectBox: optionBasedQuestions_1.DefaultSelectBoxQuestion,
|
|
99
|
-
table: tableQuestions_1.
|
|
99
|
+
table: tableQuestions_1.DefaultTableQuestion,
|
|
100
100
|
text: textQuestions_1.DefaultTextQuestion,
|
|
101
101
|
textArea: textQuestions_1.DefaultTextAreaQuestion,
|
|
102
102
|
url: textQuestions_1.DefaultURLQuestion,
|
|
@@ -28,10 +28,10 @@ export declare const DefaultBooleanQuestion: {
|
|
|
28
28
|
export declare const CheckboxesQuestionSchema: z.ZodObject<{
|
|
29
29
|
type: z.ZodLiteral<"checkBoxes">;
|
|
30
30
|
options: z.ZodArray<z.ZodObject<{
|
|
31
|
-
checked: z.ZodDefault<z.ZodBoolean>;
|
|
32
31
|
label: z.ZodDefault<z.ZodString>;
|
|
33
32
|
value: z.ZodDefault<z.ZodString>;
|
|
34
33
|
description: z.ZodOptional<z.ZodString>;
|
|
34
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
35
35
|
}, z.core.$strip>>;
|
|
36
36
|
showCommentField: z.ZodOptional<z.ZodBoolean>;
|
|
37
37
|
attributes: z.ZodObject<{
|
|
@@ -48,10 +48,10 @@ export declare const CheckboxesQuestionSchema: z.ZodObject<{
|
|
|
48
48
|
export declare const DefaultCheckboxesQuestion: {
|
|
49
49
|
type: "checkBoxes";
|
|
50
50
|
options: {
|
|
51
|
-
checked: boolean;
|
|
52
51
|
label: string;
|
|
53
52
|
value: string;
|
|
54
53
|
description?: string | undefined;
|
|
54
|
+
selected?: boolean | undefined;
|
|
55
55
|
}[];
|
|
56
56
|
attributes: {
|
|
57
57
|
label?: string | undefined;
|
|
@@ -71,6 +71,7 @@ export declare const RadioButtonsQuestionSchema: z.ZodObject<{
|
|
|
71
71
|
label: z.ZodDefault<z.ZodString>;
|
|
72
72
|
value: z.ZodDefault<z.ZodString>;
|
|
73
73
|
description: z.ZodOptional<z.ZodString>;
|
|
74
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
74
75
|
}, z.core.$strip>>;
|
|
75
76
|
showCommentField: z.ZodOptional<z.ZodBoolean>;
|
|
76
77
|
attributes: z.ZodObject<{
|
|
@@ -90,6 +91,7 @@ export declare const DefaultRadioButtonsQuestion: {
|
|
|
90
91
|
label: string;
|
|
91
92
|
value: string;
|
|
92
93
|
description?: string | undefined;
|
|
94
|
+
selected?: boolean | undefined;
|
|
93
95
|
}[];
|
|
94
96
|
attributes: {
|
|
95
97
|
label?: string | undefined;
|
|
@@ -109,6 +111,7 @@ export declare const SelectBoxQuestionSchema: z.ZodObject<{
|
|
|
109
111
|
label: z.ZodDefault<z.ZodString>;
|
|
110
112
|
value: z.ZodDefault<z.ZodString>;
|
|
111
113
|
description: z.ZodOptional<z.ZodString>;
|
|
114
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
112
115
|
}, z.core.$strip>>;
|
|
113
116
|
attributes: z.ZodObject<{
|
|
114
117
|
multiple: z.ZodLiteral<false>;
|
|
@@ -129,6 +132,7 @@ export declare const DefaultSelectBoxQuestion: {
|
|
|
129
132
|
label: string;
|
|
130
133
|
value: string;
|
|
131
134
|
description?: string | undefined;
|
|
135
|
+
selected?: boolean | undefined;
|
|
132
136
|
}[];
|
|
133
137
|
attributes: {
|
|
134
138
|
multiple: false;
|
|
@@ -149,6 +153,7 @@ export declare const MultiselectBoxQuestionSchema: z.ZodObject<{
|
|
|
149
153
|
label: z.ZodDefault<z.ZodString>;
|
|
150
154
|
value: z.ZodDefault<z.ZodString>;
|
|
151
155
|
description: z.ZodOptional<z.ZodString>;
|
|
156
|
+
selected: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
152
157
|
}, z.core.$strip>>;
|
|
153
158
|
attributes: z.ZodObject<{
|
|
154
159
|
multiple: z.ZodLiteral<true>;
|
|
@@ -169,6 +174,7 @@ export declare const DefaultMultiselectBoxQuestion: {
|
|
|
169
174
|
label: string;
|
|
170
175
|
value: string;
|
|
171
176
|
description?: string | undefined;
|
|
177
|
+
selected?: boolean | undefined;
|
|
172
178
|
}[];
|
|
173
179
|
attributes: {
|
|
174
180
|
multiple: true;
|
|
@@ -5,19 +5,19 @@ const zod_1 = require("zod");
|
|
|
5
5
|
const question_1 = require("./question");
|
|
6
6
|
// A select box, radio buttons, or checkboxes option
|
|
7
7
|
// NOTE: Question option shapes are intentionally minimal: they describe the configurable
|
|
8
|
-
// properties of each option (label, value, description).
|
|
9
|
-
//
|
|
10
|
-
// user response state and belong in answer objects/schemas (not in the question configuration).
|
|
8
|
+
// properties of each option (label, value, description). However, we deliberately included
|
|
9
|
+
// `selected` on question definitions in order to save default selection state for options.
|
|
11
10
|
// For checkboxes we include a `checked` default on the question option to allow a configured
|
|
12
|
-
// default checked state. Radio/select/multiselect questions
|
|
13
|
-
//
|
|
11
|
+
// default checked state. Radio/select/multiselect questions SHOULD include `selected`;
|
|
12
|
+
// in order to save which options should be selected by default.
|
|
14
13
|
const OptionSchema = zod_1.z.object({
|
|
15
14
|
label: zod_1.z.string().default('Option A'),
|
|
16
15
|
value: zod_1.z.string().default('a'),
|
|
17
16
|
description: zod_1.z.string().optional(),
|
|
17
|
+
selected: zod_1.z.boolean().default(false).optional() // For setting default selected option(s)
|
|
18
18
|
});
|
|
19
19
|
const DefaultOption = OptionSchema.parse({});
|
|
20
|
-
const CheckedOptionSchema = zod_1.z.object(Object.assign(
|
|
20
|
+
const CheckedOptionSchema = zod_1.z.object(Object.assign({}, OptionSchema.shape));
|
|
21
21
|
const DefaultCheckedOption = CheckedOptionSchema.parse({});
|
|
22
22
|
const selectBoxAttributes = zod_1.z.object(Object.assign(Object.assign({}, question_1.BaseAttributesSchema.shape), { multiple: zod_1.z.literal(false) }));
|
|
23
23
|
const DefaultSelectBoxAttributes = selectBoxAttributes.parse({
|