@dmptool/types 2.0.0 → 2.2.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/README.md +70 -1
- package/dist/answers/__tests__/defaults.spec.js +80 -21
- package/dist/answers/answer.d.ts +2 -0
- package/dist/answers/answer.js +4 -2
- package/dist/answers/dateAnswers.d.ts +4 -0
- package/dist/answers/graphQLAnswers.d.ts +8 -0
- package/dist/answers/index.d.ts +37 -0
- package/dist/answers/numberAnswers.d.ts +8 -0
- package/dist/answers/optionBasedAnswers.d.ts +10 -0
- package/dist/answers/tableAnswers.d.ts +94 -0
- package/dist/answers/textAnswers.d.ts +8 -0
- package/dist/dmp/__tests__/commonStandard.spec.d.ts +1 -0
- package/dist/dmp/__tests__/commonStandard.spec.js +210 -0
- package/dist/dmp/__tests__/extensions.spec.d.ts +1 -0
- package/dist/dmp/__tests__/extensions.spec.js +99 -0
- package/dist/dmp/extension.d.ts +1117 -0
- package/dist/dmp/extension.js +234 -0
- package/dist/dmp/index.d.ts +9 -0
- package/dist/dmp/index.js +69 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/questions/__tests__/defaults.spec.js +2 -2
- package/dist/questions/__tests__/optionBasedQuestions.spec.js +8 -4
- package/dist/questions/dateQuestions.d.ts +4 -0
- package/dist/questions/dateQuestions.js +2 -2
- package/dist/questions/index.d.ts +30 -22
- package/dist/questions/numberQuestions.d.ts +8 -0
- package/dist/questions/numberQuestions.js +4 -4
- package/dist/questions/optionBasedQuestions.d.ts +10 -0
- package/dist/questions/optionBasedQuestions.js +5 -5
- package/dist/questions/tableQuestions.d.ts +393 -25
- package/dist/questions/tableQuestions.js +3 -2
- package/dist/questions/textQuestions.d.ts +4 -0
- package/dist/questions/textQuestions.js +2 -2
- package/dist/schemas/affiliationSearchAnswer.schema.json +50 -0
- package/dist/schemas/affiliationSearchQuestion.schema.json +142 -0
- package/dist/schemas/anyAnswer.schema.json +1537 -0
- package/dist/schemas/anyQuestion.schema.json +4828 -0
- package/dist/schemas/anyTableColumnAnswer.schema.json +741 -0
- package/dist/schemas/anyTableColumnQuestion.schema.json +1560 -0
- package/dist/schemas/booleanAnswer.schema.json +36 -0
- package/dist/schemas/booleanQuestion.schema.json +55 -0
- package/dist/schemas/checkboxesAnswer.schema.json +41 -0
- package/dist/schemas/checkboxesQuestion.schema.json +80 -0
- package/dist/schemas/currencyAnswer.schema.json +36 -0
- package/dist/schemas/currencyQuestion.schema.json +73 -0
- package/dist/schemas/dateAnswer.schema.json +36 -0
- package/dist/schemas/datePickerAnswer.schema.json +37 -0
- package/dist/schemas/datePickerQuestion.schema.json +52 -0
- package/dist/schemas/dateQuestion.schema.json +66 -0
- package/dist/schemas/dateRangeAnswer.schema.json +50 -0
- package/dist/schemas/dateRangeQuestion.schema.json +124 -0
- package/dist/schemas/dmp.schema.json +2070 -0
- package/dist/schemas/dmpExtension.schema.json +1985 -0
- package/dist/schemas/emailAnswer.schema.json +36 -0
- package/dist/schemas/emailQuestion.schema.json +71 -0
- package/dist/schemas/filteredSearchAnswer.schema.json +40 -0
- package/dist/schemas/filteredSearchQuestion.schema.json +130 -0
- package/dist/schemas/licenseSearchAnswer.schema.json +54 -0
- package/dist/schemas/licenseSearchQuestion.schema.json +140 -0
- package/dist/schemas/metadataStandardSearchAnswer.schema.json +54 -0
- package/dist/schemas/metadataStandardSearchQuestion.schema.json +141 -0
- package/dist/schemas/multiselectBoxAnswer.schema.json +41 -0
- package/dist/schemas/multiselectBoxQuestion.schema.json +87 -0
- package/dist/schemas/numberAnswer.schema.json +36 -0
- package/dist/schemas/numberQuestion.schema.json +68 -0
- package/dist/schemas/numberRangeAnswer.schema.json +50 -0
- package/dist/schemas/numberRangeQuestion.schema.json +128 -0
- package/dist/schemas/numberWithContextAnswer.schema.json +50 -0
- package/dist/schemas/numberWithContextQuestion.schema.json +98 -0
- package/dist/schemas/radioButtonsAnswer.schema.json +36 -0
- package/dist/schemas/radioButtonsQuestion.schema.json +80 -0
- package/dist/schemas/repositorySearchAnswer.schema.json +54 -0
- package/dist/schemas/repositorySearchQuestion.schema.json +140 -0
- package/dist/schemas/researchOutputTableAnswer.schema.json +20065 -0
- package/dist/schemas/researchOutputTableQuestion.schema.json +140 -0
- package/dist/schemas/selectBoxAnswer.schema.json +36 -0
- package/dist/schemas/selectBoxQuestion.schema.json +87 -0
- package/dist/schemas/tableAnswer.schema.json +797 -0
- package/dist/schemas/tableQuestion.schema.json +1662 -0
- package/dist/schemas/textAnswer.schema.json +36 -0
- package/dist/schemas/textAreaAnswer.schema.json +36 -0
- package/dist/schemas/textAreaQuestion.schema.json +78 -0
- package/dist/schemas/textQuestion.schema.json +63 -0
- package/dist/schemas/typeaheadSearchAnswer.schema.json +37 -0
- package/dist/schemas/typeaheadSearchQuestion.schema.json +120 -0
- package/dist/schemas/urlAnswer.schema.json +36 -0
- package/dist/schemas/urlQuestion.schema.json +66 -0
- package/package.json +12 -4
- package/schemas/.placeholder +0 -0
- package/schemas/affiliationSearchAnswer.schema.json +50 -0
- package/schemas/affiliationSearchQuestion.schema.json +142 -0
- package/schemas/anyAnswer.schema.json +1537 -0
- package/schemas/anyQuestion.schema.json +4828 -0
- package/schemas/anyTableColumnAnswer.schema.json +741 -0
- package/schemas/anyTableColumnQuestion.schema.json +1560 -0
- package/schemas/booleanAnswer.schema.json +36 -0
- package/schemas/booleanQuestion.schema.json +55 -0
- package/schemas/checkboxesAnswer.schema.json +41 -0
- package/schemas/checkboxesQuestion.schema.json +80 -0
- package/schemas/currencyAnswer.schema.json +36 -0
- package/schemas/currencyQuestion.schema.json +73 -0
- package/schemas/dateAnswer.schema.json +36 -0
- package/schemas/datePickerAnswer.schema.json +37 -0
- package/schemas/datePickerQuestion.schema.json +52 -0
- package/schemas/dateQuestion.schema.json +66 -0
- package/schemas/dateRangeAnswer.schema.json +50 -0
- package/schemas/dateRangeQuestion.schema.json +124 -0
- package/schemas/dmp.schema.json +2070 -0
- package/schemas/dmpExtension.schema.json +1985 -0
- package/schemas/emailAnswer.schema.json +36 -0
- package/schemas/emailQuestion.schema.json +71 -0
- package/schemas/filteredSearchAnswer.schema.json +40 -0
- package/schemas/filteredSearchQuestion.schema.json +130 -0
- package/schemas/licenseSearchAnswer.schema.json +54 -0
- package/schemas/licenseSearchQuestion.schema.json +140 -0
- package/schemas/metadataStandardSearchAnswer.schema.json +54 -0
- package/schemas/metadataStandardSearchQuestion.schema.json +141 -0
- package/schemas/multiselectBoxAnswer.schema.json +41 -0
- package/schemas/multiselectBoxQuestion.schema.json +87 -0
- package/schemas/numberAnswer.schema.json +36 -0
- package/schemas/numberQuestion.schema.json +68 -0
- package/schemas/numberRangeAnswer.schema.json +50 -0
- package/schemas/numberRangeQuestion.schema.json +128 -0
- package/schemas/numberWithContextAnswer.schema.json +50 -0
- package/schemas/numberWithContextQuestion.schema.json +98 -0
- package/schemas/radioButtonsAnswer.schema.json +36 -0
- package/schemas/radioButtonsQuestion.schema.json +80 -0
- package/schemas/repositorySearchAnswer.schema.json +54 -0
- package/schemas/repositorySearchQuestion.schema.json +140 -0
- package/schemas/researchOutputTableAnswer.schema.json +20065 -0
- package/schemas/researchOutputTableQuestion.schema.json +140 -0
- package/schemas/selectBoxAnswer.schema.json +36 -0
- package/schemas/selectBoxQuestion.schema.json +87 -0
- package/schemas/tableAnswer.schema.json +797 -0
- package/schemas/tableQuestion.schema.json +1662 -0
- package/schemas/textAnswer.schema.json +36 -0
- package/schemas/textAreaAnswer.schema.json +36 -0
- package/schemas/textAreaQuestion.schema.json +78 -0
- package/schemas/textQuestion.schema.json +63 -0
- package/schemas/typeaheadSearchAnswer.schema.json +37 -0
- package/schemas/typeaheadSearchQuestion.schema.json +120 -0
- package/schemas/urlAnswer.schema.json +36 -0
- package/schemas/urlQuestion.schema.json +66 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultExtensionSchema = exports.ExtensionSchema = exports.DefaultNarrative = void 0;
|
|
4
|
+
// DMP Tool extensions to the RDA Common Standard
|
|
5
|
+
// See: https://github.com/RDA-DMP-Common/RDA-DMP-Common-Standard
|
|
6
|
+
//
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const answers_1 = require("../answers");
|
|
9
|
+
// the DMP visibility setting (should be used to check authorization)
|
|
10
|
+
const visibilityTypes = [
|
|
11
|
+
'public',
|
|
12
|
+
'private',
|
|
13
|
+
'embargoed',
|
|
14
|
+
];
|
|
15
|
+
// The types of research facilities
|
|
16
|
+
const researchFacilityTypes = [
|
|
17
|
+
'data_center',
|
|
18
|
+
'field_station',
|
|
19
|
+
'laboratory',
|
|
20
|
+
'observatory',
|
|
21
|
+
'other',
|
|
22
|
+
];
|
|
23
|
+
// Relation types are derived from the DataCite schema
|
|
24
|
+
const relationTypes = [
|
|
25
|
+
"is_cited_by",
|
|
26
|
+
"cites",
|
|
27
|
+
"is_supplement_to",
|
|
28
|
+
"is_supplemented_by",
|
|
29
|
+
"is_continued_by",
|
|
30
|
+
"continues",
|
|
31
|
+
"is_described_by",
|
|
32
|
+
"describes",
|
|
33
|
+
"has_metadata",
|
|
34
|
+
"is_metadata_for",
|
|
35
|
+
"has_version",
|
|
36
|
+
"is_version_of",
|
|
37
|
+
"is_new_version_of",
|
|
38
|
+
"is_previous_version_of",
|
|
39
|
+
"is_part_of",
|
|
40
|
+
"has_part",
|
|
41
|
+
"is_published_in",
|
|
42
|
+
"is_referenced_by",
|
|
43
|
+
"references",
|
|
44
|
+
"is_documented_by",
|
|
45
|
+
"documents",
|
|
46
|
+
"is_compiled_by",
|
|
47
|
+
"compiles",
|
|
48
|
+
"is_variant_form_of",
|
|
49
|
+
"is_original_form_of",
|
|
50
|
+
"is_identical_to",
|
|
51
|
+
"is_reviewed_by",
|
|
52
|
+
"reviews",
|
|
53
|
+
"is_derived_from",
|
|
54
|
+
"is_source_of",
|
|
55
|
+
"is_required_by",
|
|
56
|
+
"requires",
|
|
57
|
+
"obsoletes",
|
|
58
|
+
"is_obsoleted_by",
|
|
59
|
+
"is_collected_by",
|
|
60
|
+
"collects",
|
|
61
|
+
"is_translation_of",
|
|
62
|
+
"has_translation"
|
|
63
|
+
];
|
|
64
|
+
// Work types are derived from the DataCite schema
|
|
65
|
+
const workTypes = [
|
|
66
|
+
"audiovisual",
|
|
67
|
+
"book",
|
|
68
|
+
"book_chapter",
|
|
69
|
+
"collection",
|
|
70
|
+
"computational_notebook",
|
|
71
|
+
"conference_paper",
|
|
72
|
+
"conference_proceeding",
|
|
73
|
+
"data_paper",
|
|
74
|
+
"dataset",
|
|
75
|
+
"dissertation",
|
|
76
|
+
"event",
|
|
77
|
+
"image",
|
|
78
|
+
"instrument",
|
|
79
|
+
"interactive_resource",
|
|
80
|
+
"journal",
|
|
81
|
+
"journal_article",
|
|
82
|
+
"model",
|
|
83
|
+
"output_management_plan",
|
|
84
|
+
"peer_review",
|
|
85
|
+
"physical_object",
|
|
86
|
+
"preprint",
|
|
87
|
+
"project",
|
|
88
|
+
"report",
|
|
89
|
+
"service",
|
|
90
|
+
"software",
|
|
91
|
+
"sound",
|
|
92
|
+
"standard",
|
|
93
|
+
"study_registration",
|
|
94
|
+
"text",
|
|
95
|
+
"workflow",
|
|
96
|
+
"other"
|
|
97
|
+
];
|
|
98
|
+
const ResearchDomainSchema = zod_1.z.object({
|
|
99
|
+
// The human-readable name for the research domain
|
|
100
|
+
name: zod_1.z.string(),
|
|
101
|
+
// The identifier for the research domain
|
|
102
|
+
research_domain_identifier: zod_1.z.object({
|
|
103
|
+
identifier: zod_1.z.string().optional(),
|
|
104
|
+
type: zod_1.z.enum(['ark', 'doi', 'handle', 'url', 'other']).default('url')
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
107
|
+
const RelatedIdentifierSchema = zod_1.z.object({
|
|
108
|
+
// The description of how the DMP is related to the work (e.g. the DMP "cites" the work)
|
|
109
|
+
descriptor: zod_1.z.enum(relationTypes).default('cites'),
|
|
110
|
+
// The identifier of the work
|
|
111
|
+
identifier: zod_1.z.string(),
|
|
112
|
+
// The type of identifier
|
|
113
|
+
type: zod_1.z.enum(['ark', 'doi', 'handle', 'url']).default('url'),
|
|
114
|
+
// The type of the work
|
|
115
|
+
work_type: zod_1.z.enum(workTypes).default('dataset'),
|
|
116
|
+
});
|
|
117
|
+
const ResearchFacilitySchema = zod_1.z.object({
|
|
118
|
+
// The human-readable name of the research facility
|
|
119
|
+
name: zod_1.z.string(),
|
|
120
|
+
// The facility type
|
|
121
|
+
type: zod_1.z.enum(researchFacilityTypes).default('other'),
|
|
122
|
+
// The identifier for the research facility
|
|
123
|
+
research_facility_identifier: zod_1.z.object({
|
|
124
|
+
identifier: zod_1.z.string(),
|
|
125
|
+
type: zod_1.z.enum(['ark', 'doi', 'handle', 'url', 'other']).default('url')
|
|
126
|
+
}),
|
|
127
|
+
});
|
|
128
|
+
const FundingOpportunitySchema = zod_1.z.object({
|
|
129
|
+
// The id of the project this opportunity maps to
|
|
130
|
+
project_id: zod_1.z.object({
|
|
131
|
+
identifier: zod_1.z.string(),
|
|
132
|
+
type: zod_1.z.enum(['ark', 'doi', 'handle', 'url', 'other']).default('other')
|
|
133
|
+
}),
|
|
134
|
+
// The id of the funding this opportunity maps to within the project
|
|
135
|
+
funder_id: zod_1.z.object({
|
|
136
|
+
identifier: zod_1.z.string(),
|
|
137
|
+
type: zod_1.z.enum(['ror', 'url', 'other']).default('ror')
|
|
138
|
+
}),
|
|
139
|
+
// The opportunity id
|
|
140
|
+
opportunity_identifier: zod_1.z.object({
|
|
141
|
+
identifier: zod_1.z.string(),
|
|
142
|
+
type: zod_1.z.enum(['ark', 'doi', 'handle', 'url', 'other']).default('url')
|
|
143
|
+
})
|
|
144
|
+
});
|
|
145
|
+
const VersionSchema = zod_1.z.object({
|
|
146
|
+
// URL to fetch the historical version of the DMP
|
|
147
|
+
access_url: zod_1.z.string(),
|
|
148
|
+
// The date of the version
|
|
149
|
+
version_date: zod_1.z.iso.datetime(),
|
|
150
|
+
});
|
|
151
|
+
const NarrativeAnswerSchema = zod_1.z.object({
|
|
152
|
+
id: zod_1.z.number(),
|
|
153
|
+
json: answers_1.AnyAnswerSchema,
|
|
154
|
+
});
|
|
155
|
+
const DefaultAnswer = NarrativeAnswerSchema.parse({
|
|
156
|
+
id: 0,
|
|
157
|
+
json: answers_1.DefaultTextAreaAnswer
|
|
158
|
+
});
|
|
159
|
+
const NarrativeQuestionSchema = zod_1.z.object({
|
|
160
|
+
id: zod_1.z.number(),
|
|
161
|
+
order: zod_1.z.number(),
|
|
162
|
+
text: zod_1.z.string(),
|
|
163
|
+
answer: NarrativeAnswerSchema.optional(),
|
|
164
|
+
});
|
|
165
|
+
const DefaultQuestion = NarrativeQuestionSchema.parse({
|
|
166
|
+
id: 0,
|
|
167
|
+
order: 0,
|
|
168
|
+
text: 'Undefined question text',
|
|
169
|
+
answer: DefaultAnswer
|
|
170
|
+
});
|
|
171
|
+
const NarrativeSectionSchema = zod_1.z.object({
|
|
172
|
+
id: zod_1.z.number(),
|
|
173
|
+
order: zod_1.z.number(),
|
|
174
|
+
title: zod_1.z.string(),
|
|
175
|
+
description: zod_1.z.string().optional(),
|
|
176
|
+
question: zod_1.z.array(NarrativeQuestionSchema)
|
|
177
|
+
});
|
|
178
|
+
const DefaultSection = NarrativeSectionSchema.parse({
|
|
179
|
+
id: 0,
|
|
180
|
+
order: 0,
|
|
181
|
+
title: 'Undefined section',
|
|
182
|
+
question: [DefaultQuestion]
|
|
183
|
+
});
|
|
184
|
+
const NarrativeTemplateSchema = zod_1.z.object({
|
|
185
|
+
id: zod_1.z.number(),
|
|
186
|
+
title: zod_1.z.string(),
|
|
187
|
+
description: zod_1.z.string().optional(),
|
|
188
|
+
version: zod_1.z.string().optional(),
|
|
189
|
+
section: zod_1.z.array(NarrativeSectionSchema)
|
|
190
|
+
});
|
|
191
|
+
const DefaultNarrativeTemplate = NarrativeTemplateSchema.parse({
|
|
192
|
+
id: 0,
|
|
193
|
+
title: 'Undefined template',
|
|
194
|
+
section: [DefaultSection]
|
|
195
|
+
});
|
|
196
|
+
// URLs to fetch the narrative as a document other than JSON
|
|
197
|
+
const NarrativeURLsSchema = zod_1.z.object({
|
|
198
|
+
csv: zod_1.z.string().optional(),
|
|
199
|
+
docx: zod_1.z.string().optional(),
|
|
200
|
+
html: zod_1.z.string().optional(),
|
|
201
|
+
pdf: zod_1.z.string().optional(),
|
|
202
|
+
});
|
|
203
|
+
const NarrativeSchema = zod_1.z.object({
|
|
204
|
+
download_urls: NarrativeURLsSchema.optional(),
|
|
205
|
+
template: NarrativeTemplateSchema.optional(),
|
|
206
|
+
});
|
|
207
|
+
exports.DefaultNarrative = NarrativeSchema.parse({
|
|
208
|
+
template: DefaultNarrativeTemplate
|
|
209
|
+
});
|
|
210
|
+
exports.ExtensionSchema = zod_1.z.object({
|
|
211
|
+
// The name of the system that owns this record
|
|
212
|
+
provenance: zod_1.z.string(),
|
|
213
|
+
// The visibility setting for the DMP
|
|
214
|
+
privacy: zod_1.z.enum(visibilityTypes).default('private'),
|
|
215
|
+
// Whether the DMP is featured on the public plans page of the DMP Tool website
|
|
216
|
+
featured: zod_1.z.enum(['yes', 'no']).default('no'),
|
|
217
|
+
// The date the DMP Id was registered as a DOI with EZID/DataCite
|
|
218
|
+
registered: zod_1.z.iso.datetime().optional(),
|
|
219
|
+
// The narrative content of the DMP expressed as a JSON object
|
|
220
|
+
narrative: NarrativeSchema.optional(),
|
|
221
|
+
// The research domain of the project/DMP
|
|
222
|
+
research_domain: ResearchDomainSchema.optional(),
|
|
223
|
+
// Other works related to the DMP
|
|
224
|
+
related_identifier: zod_1.z.array(RelatedIdentifierSchema).optional(),
|
|
225
|
+
// Research facilities used to collect or process data
|
|
226
|
+
research_facility: zod_1.z.array(ResearchFacilitySchema).optional(),
|
|
227
|
+
// Historical versions of the DMP
|
|
228
|
+
version: zod_1.z.array(VersionSchema).optional(),
|
|
229
|
+
// Funding opportunity / call for grant submissions related to the funding
|
|
230
|
+
funding_opportunity: zod_1.z.array(FundingOpportunitySchema).optional(),
|
|
231
|
+
});
|
|
232
|
+
exports.DefaultExtensionSchema = exports.ExtensionSchema.parse({
|
|
233
|
+
provenance: 'your-application',
|
|
234
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { FromSchema } from "json-schema-to-ts";
|
|
3
|
+
import { ExtensionType } from "./extension";
|
|
4
|
+
declare const jsonSchema: any;
|
|
5
|
+
export declare const RDACommonStandardDMPJSONSchema: any;
|
|
6
|
+
export type RDACommonStandardDMPType = FromSchema<typeof jsonSchema>;
|
|
7
|
+
export type DMPToolDMPType = RDACommonStandardDMPType & ExtensionType;
|
|
8
|
+
export declare const ExtensionJSONSchema: z.core.JSONSchema.JSONSchema;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ExtensionJSONSchema = exports.RDACommonStandardDMPJSONSchema = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const zod_1 = require("zod");
|
|
10
|
+
const extension_1 = require("./extension");
|
|
11
|
+
// The RDA Common Standard for DMPs JSON schema is automatically downloaded by
|
|
12
|
+
// scripts/importRDACommonStandard.ts script. This file fetches the specified
|
|
13
|
+
// version of the schema and places it into the schemas/ directory.
|
|
14
|
+
//
|
|
15
|
+
// At this time, there is a PR to add support for converting a JSON Schema into
|
|
16
|
+
// a Zod schema, but it is not there yet.
|
|
17
|
+
//
|
|
18
|
+
// Convert the downloaded JSON schema into types
|
|
19
|
+
// First try resolving via the package export (works when installed from GitHub branch or npm)
|
|
20
|
+
function resolveSchemaPath() {
|
|
21
|
+
// Try using Node's module resolution against the package export
|
|
22
|
+
try {
|
|
23
|
+
// require.resolve respects the "exports" map in package.json
|
|
24
|
+
const resolved = require.resolve("@dmptool/types/schemas/dmp.schema.json");
|
|
25
|
+
if (resolved && fs_1.default.existsSync(resolved)) {
|
|
26
|
+
return resolved;
|
|
27
|
+
}
|
|
28
|
+
// If require.resolve found a path but it doesn't exist, log it for debugging
|
|
29
|
+
console.warn(`[dmptool-types] require.resolve found path but it doesn't exist: ${resolved}`);
|
|
30
|
+
}
|
|
31
|
+
catch (_a) {
|
|
32
|
+
// ignore and fall back to local paths below
|
|
33
|
+
}
|
|
34
|
+
// Fallbacks based on local file structure when running from source or built dist
|
|
35
|
+
// This handles multiple installation scenarios:
|
|
36
|
+
// 1. npm/published package with dist/schemas
|
|
37
|
+
// 2. Source code with ts-node/ts-node-dev
|
|
38
|
+
// 3. GitHub branch installation where dist is gitignored but schemas/ is committed
|
|
39
|
+
const schemaCandidatePaths = [
|
|
40
|
+
// When running compiled code from dist: dist/dmp/index.js -> dist/schemas/dmp.schema.json
|
|
41
|
+
path_1.default.resolve(__dirname, "..", "schemas", "dmp.schema.json"),
|
|
42
|
+
// When running from source with ts-node: src/dmp/index.ts -> compiled as dist/dmp/index.js -> schemas/dmp.schema.json at repo root
|
|
43
|
+
path_1.default.resolve(__dirname, "..", "..", "schemas", "dmp.schema.json"),
|
|
44
|
+
// When installed as node_module from GitHub: node_modules/@dmptool/types/dist/dmp/index.js
|
|
45
|
+
// Go up to package root, then into schemas: dist/dmp -> dist -> package_root -> schemas
|
|
46
|
+
path_1.default.resolve(__dirname, "..", "..", "..", "schemas", "dmp.schema.json"),
|
|
47
|
+
];
|
|
48
|
+
// Remove duplicates while preserving order
|
|
49
|
+
const uniquePaths = Array.from(new Set(schemaCandidatePaths));
|
|
50
|
+
return uniquePaths.find((candidate) => fs_1.default.existsSync(candidate));
|
|
51
|
+
}
|
|
52
|
+
const RDA_COMMON_STANDARD_JSON_FILE = resolveSchemaPath();
|
|
53
|
+
if (!RDA_COMMON_STANDARD_JSON_FILE) {
|
|
54
|
+
const attemptedPaths = [
|
|
55
|
+
path_1.default.resolve(__dirname, "..", "schemas", "dmp.schema.json"),
|
|
56
|
+
path_1.default.resolve(__dirname, "..", "..", "schemas", "dmp.schema.json"),
|
|
57
|
+
path_1.default.resolve(__dirname, "..", "..", "..", "schemas", "dmp.schema.json"),
|
|
58
|
+
];
|
|
59
|
+
throw new Error(`Unable to locate dmp.schema.json. Current __dirname: ${__dirname}. Attempted paths: ${attemptedPaths.join(", ")}`);
|
|
60
|
+
}
|
|
61
|
+
// Double-check the file exists before trying to read it
|
|
62
|
+
if (!fs_1.default.existsSync(RDA_COMMON_STANDARD_JSON_FILE)) {
|
|
63
|
+
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.`);
|
|
64
|
+
}
|
|
65
|
+
// Ignoring ESLint here because it doesn't like that we're only using jsonSchema as a Type
|
|
66
|
+
// but that's exactly what we want to do.
|
|
67
|
+
const jsonSchema = JSON.parse(fs_1.default.readFileSync(RDA_COMMON_STANDARD_JSON_FILE, "utf8"));
|
|
68
|
+
exports.RDACommonStandardDMPJSONSchema = jsonSchema;
|
|
69
|
+
exports.ExtensionJSONSchema = zod_1.z.toJSONSchema(extension_1.ExtensionSchema);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
// Export All the Zod schemas and types
|
|
18
18
|
__exportStar(require("./answers"), exports);
|
|
19
|
+
__exportStar(require("./dmp"), exports);
|
|
19
20
|
__exportStar(require("./questions"), exports);
|
|
@@ -158,7 +158,7 @@ describe('questions return the expected defaults', () => {
|
|
|
158
158
|
type: "OFFSET",
|
|
159
159
|
name: "paginationOptions",
|
|
160
160
|
label: "Pagination Options",
|
|
161
|
-
labelTranslationKey: "PaginationOptions.label"
|
|
161
|
+
labelTranslationKey: "PaginationOptions.label"
|
|
162
162
|
}
|
|
163
163
|
],
|
|
164
164
|
responseField: "metadataStandards.items",
|
|
@@ -337,7 +337,7 @@ describe('questions return the expected defaults', () => {
|
|
|
337
337
|
attributes: {
|
|
338
338
|
step: 1
|
|
339
339
|
},
|
|
340
|
-
meta: { schemaVersion: "1.0" }
|
|
340
|
+
meta: { schemaVersion: "1.0" }
|
|
341
341
|
}
|
|
342
342
|
},
|
|
343
343
|
{
|
|
@@ -63,7 +63,8 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
63
63
|
],
|
|
64
64
|
meta: {
|
|
65
65
|
schemaVersion: "1.0"
|
|
66
|
-
}
|
|
66
|
+
},
|
|
67
|
+
showCommentField: false
|
|
67
68
|
};
|
|
68
69
|
(0, globals_1.expect)(() => optionBasedQuestions_1.CheckboxesQuestionSchema.parse(validCheckboxesQuestion)).not.toThrow();
|
|
69
70
|
});
|
|
@@ -110,7 +111,8 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
110
111
|
],
|
|
111
112
|
meta: {
|
|
112
113
|
schemaVersion: "1.0"
|
|
113
|
-
}
|
|
114
|
+
},
|
|
115
|
+
showCommentField: false
|
|
114
116
|
};
|
|
115
117
|
(0, globals_1.expect)(() => optionBasedQuestions_1.RadioButtonsQuestionSchema.parse(validRadioButtonsQuestion)).not.toThrow();
|
|
116
118
|
});
|
|
@@ -154,7 +156,8 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
154
156
|
],
|
|
155
157
|
meta: {
|
|
156
158
|
schemaVersion: "1.0"
|
|
157
|
-
}
|
|
159
|
+
},
|
|
160
|
+
showCommentField: false
|
|
158
161
|
};
|
|
159
162
|
(0, globals_1.expect)(() => optionBasedQuestions_1.SelectBoxQuestionSchema.parse(validSelectBoxQuestion)).not.toThrow();
|
|
160
163
|
});
|
|
@@ -202,7 +205,8 @@ const optionBasedQuestions_1 = require("../optionBasedQuestions");
|
|
|
202
205
|
],
|
|
203
206
|
meta: {
|
|
204
207
|
schemaVersion: "1.0"
|
|
205
|
-
}
|
|
208
|
+
},
|
|
209
|
+
showCommentField: false
|
|
206
210
|
};
|
|
207
211
|
(0, globals_1.expect)(() => optionBasedQuestions_1.MultiselectBoxQuestionSchema.parse(validSelectBoxQuestion)).not.toThrow();
|
|
208
212
|
});
|
|
@@ -9,6 +9,7 @@ export declare const DateQuestionSchema: z.ZodObject<{
|
|
|
9
9
|
help: z.ZodOptional<z.ZodString>;
|
|
10
10
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
11
11
|
}, z.core.$strip>;
|
|
12
|
+
showCommentField: z.ZodOptional<z.ZodBoolean>;
|
|
12
13
|
meta: z.ZodObject<{
|
|
13
14
|
schemaVersion: z.ZodDefault<z.ZodString>;
|
|
14
15
|
title: z.ZodOptional<z.ZodString>;
|
|
@@ -30,6 +31,7 @@ export declare const DefaultDateQuestion: {
|
|
|
30
31
|
title?: string | undefined;
|
|
31
32
|
usageDescription?: string | undefined;
|
|
32
33
|
};
|
|
34
|
+
showCommentField?: boolean | undefined;
|
|
33
35
|
};
|
|
34
36
|
export declare const DateRangeQuestionSchema: z.ZodObject<{
|
|
35
37
|
type: z.ZodLiteral<"dateRange">;
|
|
@@ -51,6 +53,7 @@ export declare const DateRangeQuestionSchema: z.ZodObject<{
|
|
|
51
53
|
labelTranslationKey: z.ZodOptional<z.ZodString>;
|
|
52
54
|
}, z.core.$strip>;
|
|
53
55
|
}, z.core.$strip>;
|
|
56
|
+
showCommentField: z.ZodOptional<z.ZodBoolean>;
|
|
54
57
|
attributes: z.ZodObject<{
|
|
55
58
|
label: z.ZodOptional<z.ZodString>;
|
|
56
59
|
help: z.ZodOptional<z.ZodString>;
|
|
@@ -92,6 +95,7 @@ export declare const DefaultDateRangeQuestion: {
|
|
|
92
95
|
title?: string | undefined;
|
|
93
96
|
usageDescription?: string | undefined;
|
|
94
97
|
};
|
|
98
|
+
showCommentField?: boolean | undefined;
|
|
95
99
|
};
|
|
96
100
|
export type DateQuestionType = z.infer<typeof DateQuestionSchema>;
|
|
97
101
|
export type DateRangeQuestionType = z.infer<typeof DateRangeQuestionSchema>;
|
|
@@ -6,7 +6,7 @@ const question_1 = require("./question");
|
|
|
6
6
|
const DateAttributesSchema = zod_1.z.object(Object.assign(Object.assign({}, question_1.BaseAttributesSchema.shape), { max: zod_1.z.string().optional(), min: zod_1.z.string().optional(), step: zod_1.z.number().default(1) }));
|
|
7
7
|
const DefaultDateAttributes = DateAttributesSchema.parse({});
|
|
8
8
|
// Date question and answer
|
|
9
|
-
exports.DateQuestionSchema = zod_1.z.object(Object.assign(Object.assign({}, question_1.QuestionSchema.shape), { type: zod_1.z.literal('date'), attributes: DateAttributesSchema }));
|
|
9
|
+
exports.DateQuestionSchema = zod_1.z.object(Object.assign(Object.assign({}, question_1.QuestionSchema.shape), { type: zod_1.z.literal('date'), attributes: DateAttributesSchema, showCommentField: zod_1.z.boolean().optional() }));
|
|
10
10
|
exports.DefaultDateQuestion = exports.DateQuestionSchema.parse({
|
|
11
11
|
type: 'date',
|
|
12
12
|
attributes: DefaultDateAttributes,
|
|
@@ -18,7 +18,7 @@ const DateRangeEndColumnSchema = zod_1.z.object(Object.assign(Object.assign({},
|
|
|
18
18
|
exports.DateRangeQuestionSchema = zod_1.z.object(Object.assign(Object.assign({}, question_1.QuestionSchema.shape), { type: zod_1.z.literal('dateRange'), columns: zod_1.z.object({
|
|
19
19
|
start: DateRangeStartColumnSchema,
|
|
20
20
|
end: DateRangeEndColumnSchema,
|
|
21
|
-
}) }));
|
|
21
|
+
}), showCommentField: zod_1.z.boolean().optional() }));
|
|
22
22
|
exports.DefaultDateRangeQuestion = exports.DateRangeQuestionSchema.parse({
|
|
23
23
|
type: 'dateRange',
|
|
24
24
|
attributes: question_1.BaseAttributesSchema.parse({}),
|