From c82862046ecff91e014f99450e9b563c3640af93 Mon Sep 17 00:00:00 2001 From: Theo Beers <32523293+theodore-s-beers@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:47:33 +0200 Subject: [PATCH] Add CRediT role IDs --- SCHEMATA/project_schema.ts | 38 +++++++++++++++++++++----------------- TESTS/schema_tests.ts | 18 +++++++++++++++++- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/SCHEMATA/project_schema.ts b/SCHEMATA/project_schema.ts index 6dcc532c0..889d23786 100644 --- a/SCHEMATA/project_schema.ts +++ b/SCHEMATA/project_schema.ts @@ -15,24 +15,28 @@ export const keywords = Object.values(keywordsObj).flat(); // Make keywords list into Zod enum const keywordsEnum: [string, ...string[]] = [keywords[0], ...keywords.slice(1)]; -// List of valid roles in the CRediT taxonomy -const creditRoles: [string, ...string[]] = [ - "conceptualization", - "data curation", - "formal analysis", - "funding acquisition", - "investigation", - "methodology", - "project administration", - "resources", - "software", - "supervision", - "validation", - "visualization", - "writing – original draft", - "writing – review & editing", +// List of valid roles (name, id) in the CRediT taxonomy +export const creditRoles: [string, string][] = [ + ["conceptualization", "8b73531f-db56-4914-9502-4cc4d4d8ed73"], + ["data curation", "f93e0f44-f2a4-4ea1-824a-4e0853b05c9d"], + ["formal analysis", "95394cbd-4dc8-4735-b589-7e5f9e622b3f"], + ["funding acquisition", "34ff6d68-132f-4438-a1f4-fba61ccf364a"], + ["investigation", "2451924d-425e-4778-9f4c-36c848ca70c2"], + ["methodology", "f21e2be9-4e38-4ab7-8691-d6f72d5d5843"], + ["project administration", "a693fe76-ea33-49ad-9dcc-5e4f3ac5f938"], + ["resources", "ebd781f0-bf79-492c-ac21-b31b9c3c990c"], + ["software", "f89c5233-01b0-4778-93e9-cc7d107aa2c8"], + ["supervision", "0c8ca7d4-06ad-4527-9cea-a8801fcb8746"], + ["validation", "4b1bf348-faf2-4fc4-bd66-4cd3a84b9d44"], + ["visualization", "76b9d56a-e430-4e0a-84c9-59c11be343ae"], + ["writing – original draft", "43ebbd94-98b4-42f1-866b-c930cef228ca"], + ["writing – review & editing", "d3aead86-f2a2-47f7-bb99-79de6421164d"], ]; +// Make roles list into Zod enum of role names +const roleNames = creditRoles.map((x) => x[0]); +const rolesEnum: [string, ...string[]] = [roleNames[0], ...roleNames.slice(1)]; + // // SCHEMA // @@ -176,7 +180,7 @@ export const projectSchema = z }) .strict(), roles: z - .array(z.enum(creditRoles)) + .array(z.enum(rolesEnum)) .describe( "Roles held by the contact (following the CRediT taxonomy)", ), diff --git a/TESTS/schema_tests.ts b/TESTS/schema_tests.ts index 50af9fb12..d8c197484 100644 --- a/TESTS/schema_tests.ts +++ b/TESTS/schema_tests.ts @@ -1,6 +1,10 @@ import { assertEquals } from "https://deno.land/std@0.201.0/assert/mod.ts"; import { v4 } from "https://deno.land/std@0.201.0/uuid/mod.ts"; -import { keywords, projectSchema } from "../SCHEMATA/project_schema.ts"; +import { + creditRoles, + keywords, + projectSchema, +} from "../SCHEMATA/project_schema.ts"; Deno.test("ensure no duplicate keywords", () => { const keywordsSet = new Set(keywords); @@ -19,6 +23,18 @@ Deno.test("validate project template", () => { projectSchema.parse(template); }); +Deno.test("ensure no duplicate CRediT role IDs", () => { + const ids = creditRoles.map(([, id]) => id); + const idSet = new Set(ids); + assertEquals(idSet.size, 14); // There are 14 roles +}); + +for (const [_, id] of creditRoles) { + Deno.test(`validate CRediT role ID ${id}`, () => { + assertEquals(v4.validate(id), true); + }); +} + // Get list of project files const projectsFile = Deno.readTextFileSync("PROJECTS.json"); const projectsObj = JSON.parse(projectsFile);