Skip to content

Commit c42c7d6

Browse files
committed
hal takes more options
1 parent 43eeeb1 commit c42c7d6

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

charter-assistant.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ <h2>Interest Groups</h2>
3838
async function populate() {
3939
const wgs = [];
4040
const igs = [];
41-
for await (const group of hal("groups", `${config.w3cAPI}/groups`, true)) {
41+
for await (const group of hal("groups", `${config.w3cAPI}/groups`, { embed: true })) {
4242
if (group.type === "working group") {
4343
wgs.push({
4444
name: group.name,

lib/2026.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,12 @@ async function compute(group, template, deliverables, charter) {
407407
head.appendChild(scriptConfig);
408408
if (config.debug) console.log(config);
409409
}
410-
410+
411411
// clean up if needed
412412
draft.querySelectorAll('.remove').forEach(s => s.remove());
413-
413+
414414
status('Done. Get ready to review the charter draft.');
415-
415+
416416
return draft;
417417
}
418418

@@ -502,7 +502,7 @@ async function fetchGroupData() {
502502
if (url) {
503503
targetObject[targetProperty] = [];
504504
try {
505-
const items = await hal(targetProperty, url, true, postFunction);
505+
const items = await hal(targetProperty, url, { embed: true, adapter: postFunction, fetch: { signal: abortSignal() } } );
506506
for await (const service of items) {
507507
targetObject[targetProperty].push(service);
508508
}
@@ -541,11 +541,11 @@ async function fetchGroupData() {
541541
async function w3cgroups() {
542542
const groups = [];
543543
async function* listGroups() {
544-
for await (const v of hal("groups", `${config.w3cAPI}/groups`, true))
544+
for await (const v of hal("groups", `${config.w3cAPI}/groups`, { embed: true }))
545545
yield v;
546546
}
547547
for await (const group of listGroups()) {
548-
groups.push(group);
549-
}
550-
return groups;
548+
groups.push(group);
549+
}
550+
return groups;
551551
}

lib/hal.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,33 @@ import { json } from './fetch.js';
1010
*
1111
* @param {string} propertyTarget - The property name to extract from _embedded or _links.
1212
* @param {string} link - The initial API endpoint URL.
13-
* @param {boolean} embed - Whether to use embedded resources or links.
14-
* @param {Function} [objFct] - Optional function to transform each resource.
13+
* @param {Object} [options={}] - Optional settings.
14+
* @param {boolean} [options.embed=false] - Whether to use embedded resources.
15+
* @param {Object} [options.fetch={}] - Custom fetch options.
16+
* @param {Function} [options.adapter] - Optional function to transform each resource.
1517
* @yields {Object} The resources from the HAL API.
1618
*/
1719
export
18-
async function* hal(propertyTarget, link, embed, objFct) {
20+
async function* hal(propertyTarget, link, options = {}) {
1921
while (true) {
2022
let apiURL = new URL(link);
21-
if (embed === true) {
23+
if (options.embed === true) {
2224
apiURL.searchParams.set("embed", "1"); // grab everything
2325
}
24-
let data = await json(apiURL);
25-
if (embed) {
26+
let data = await json(apiURL, options.fetch);
27+
if (options.embed) {
2628
for (const target of data._embedded[propertyTarget]) {
27-
if (objFct) {
28-
yield objFct(target);
29+
if (options.adapter) {
30+
yield options.adapter(target);
2931
} else {
3032
yield target;
3133
}
3234
}
3335
} else {
3436
if (data._links[propertyTarget]) {
3537
for (const target of data._links[propertyTarget]) {
36-
if (objFct) {
37-
yield objFct(target);
38+
if (options.adapter) {
39+
yield options.adapter(target);
3840
} else {
3941
yield target;
4042
}

0 commit comments

Comments
 (0)