Skip to content

Commit

Permalink
refactor(w3c/groups): improve docs + typescript (#4624)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres authored Jan 6, 2024
1 parent ba4de30 commit bd552d2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/type-helper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,20 @@ interface Conf {
};
/** The title of the document */
title?: string;

/** W3C Group - see https://respec.org/w3c/groups */
group?: string | string[];
}

type GroupDetails = {
wgId: number;
wg: string;
wgURI: string;
wgPatentURI: string;
wgPatentPolicy: string;
groupType: string;
};

type LicenseInfo = {
/**
* The name of the license.
Expand Down
25 changes: 16 additions & 9 deletions src/w3c/group.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// @ts-check
/**
* @module w3c/group
*
* `group` is a shorthand configuration option for specifying `wg`, `wgId`,
* `wgURI`, and `wgPatentURI` options.
* The purpose of this module is to fetch and set the working group configuration details.
*/

import { docLink, fetchAndCache, showError } from "../core/utils.js";

export const name = "w3c/group";

const W3C_GROUPS_API = "https://respec.org/w3c/groups/";

/**
* Fetches the group configuration details and adds them to the document's configuration.
* @param {Conf} conf The document configuration object.
* @return {Promise<void>} Resolves after setting the group configuration details.
*/
export async function run(conf) {
if (!conf.group) {
return;
Expand All @@ -23,7 +26,11 @@ export async function run(conf) {
Object.assign(conf, groupDetails);
}

/** @param {string[]} groups */
/**
* Fetches configuration details for multiple groups concurrently.
* @param {string[]} groups An array of group identifiers.
* @return {Promise<object>} Resolves to an object containing the configuration details for each group.
*/
async function getMultipleGroupDetails(groups) {
const details = await Promise.all(groups.map(getGroupDetails));
/** @type {{ [key in keyof GroupDetails]: GroupDetails[key][] }} */
Expand All @@ -35,7 +42,7 @@ async function getMultipleGroupDetails(groups) {
wgPatentPolicy: [],
groupType: [],
};
for (const groupDetails of details.filter(o => o)) {
for (const groupDetails of details.filter(Boolean)) {
for (const key of Object.keys(result)) {
result[key].push(groupDetails[key]);
}
Expand All @@ -44,9 +51,9 @@ async function getMultipleGroupDetails(groups) {
}

/**
* @param {string} group
* @typedef {{ wgId: number, wg: string, wgURI: string, wgPatentURI: string, wgPatentPolicy: string, groupType: W3CGroupType }} GroupDetails
* @returns {Promise<GroupDetails|undefined>}
* Fetches configuration details for a single group.
* @param {string} group A group identifier.
* @return {Promise<GroupDetails|undefined>} Resolves to an object containing the group's configuration details, or undefined if the group could not be fetched.
*/
async function getGroupDetails(group) {
let type = "";
Expand Down

0 comments on commit bd552d2

Please sign in to comment.