@iqb/metadata-resolver 0.1.1 → 0.2.1
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/index.cjs +24 -7
- package/dist/index.d.cts +8 -45
- package/dist/index.d.mts +8 -45
- package/dist/index.d.ts +133 -0
- package/dist/index.mjs +23 -7
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
|
|
2
3
|
//#region src/metadata-resolver.ts
|
|
3
4
|
var MetadataResolver = class {
|
|
@@ -67,7 +68,7 @@ var MetadataResolver = class {
|
|
|
67
68
|
const urls = /* @__PURE__ */ new Set();
|
|
68
69
|
profile.groups?.forEach((group) => {
|
|
69
70
|
group.entries?.forEach((entry) => {
|
|
70
|
-
if (entry.type === "
|
|
71
|
+
if (entry.type.toUpperCase() === "VOCABULARY" && entry.parameters) {
|
|
71
72
|
const params = entry.parameters;
|
|
72
73
|
if (params.url) urls.add(params.url);
|
|
73
74
|
}
|
|
@@ -82,10 +83,11 @@ var MetadataResolver = class {
|
|
|
82
83
|
async loadVocabulary(url) {
|
|
83
84
|
if (this.useCache && this.vocabulariesStore.has(url)) return this.vocabulariesStore.get(url);
|
|
84
85
|
try {
|
|
86
|
+
console.log(`Loading vocabulary: ${url}`);
|
|
85
87
|
const jsonLdUrl = await this.resolveJsonLdUrl(url);
|
|
86
|
-
if (jsonLdUrl !== url) {}
|
|
88
|
+
if (jsonLdUrl !== url) console.log(` Resolved to: ${jsonLdUrl}`);
|
|
87
89
|
const fetchUrl = this.corsProxy ? `${this.corsProxy}${encodeURIComponent(jsonLdUrl)}` : jsonLdUrl;
|
|
88
|
-
if (this.corsProxy)
|
|
90
|
+
if (this.corsProxy) console.log(" Using CORS proxy");
|
|
89
91
|
let response;
|
|
90
92
|
try {
|
|
91
93
|
response = await fetch(fetchUrl, { signal: AbortSignal.timeout(this.requestTimeout) });
|
|
@@ -139,6 +141,7 @@ var MetadataResolver = class {
|
|
|
139
141
|
dictionary
|
|
140
142
|
};
|
|
141
143
|
if (this.useCache) this.vocabulariesStore.set(url, resolved);
|
|
144
|
+
console.log(` Loaded: ${data.hasTopConcept.length} concepts, ${Object.keys(dictionary).length} entries`);
|
|
142
145
|
return resolved;
|
|
143
146
|
} catch (error) {
|
|
144
147
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
@@ -156,7 +159,9 @@ var MetadataResolver = class {
|
|
|
156
159
|
*/
|
|
157
160
|
async loadVocabularies(profile) {
|
|
158
161
|
const urls = this.extractVocabularyUrls(profile);
|
|
159
|
-
|
|
162
|
+
const vocabularies = (await Promise.allSettled(urls.map((url) => this.loadVocabulary(url)))).filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
163
|
+
console.log(`Loaded ${vocabularies.length} vocabularies (${this.vocabulariesStore.size} total in store)`);
|
|
164
|
+
return vocabularies;
|
|
160
165
|
}
|
|
161
166
|
/**
|
|
162
167
|
* Build a dictionary from vocabulary data
|
|
@@ -196,7 +201,10 @@ var MetadataResolver = class {
|
|
|
196
201
|
*/
|
|
197
202
|
async resolveJsonLdUrl(originalUrl) {
|
|
198
203
|
try {
|
|
204
|
+
console.log(`Resolving URL: ${originalUrl}`);
|
|
205
|
+
console.log(` CORS proxy: ${this.corsProxy || "disabled"}`);
|
|
199
206
|
const fetchUrl = this.corsProxy ? `${this.corsProxy}${encodeURIComponent(originalUrl)}` : originalUrl;
|
|
207
|
+
console.log(` Fetching: ${fetchUrl}`);
|
|
200
208
|
const res = await fetch(fetchUrl, {
|
|
201
209
|
method: "GET",
|
|
202
210
|
redirect: "follow",
|
|
@@ -212,7 +220,10 @@ var MetadataResolver = class {
|
|
|
212
220
|
if ((await fetch(this.corsProxy ? `${this.corsProxy}${encodeURIComponent(jsonldUrl)}` : jsonldUrl, {
|
|
213
221
|
method: "HEAD",
|
|
214
222
|
signal: AbortSignal.timeout(this.requestTimeout)
|
|
215
|
-
})).ok)
|
|
223
|
+
})).ok) {
|
|
224
|
+
console.log(` Found JSON-LD: ${jsonldUrl}`);
|
|
225
|
+
return jsonldUrl;
|
|
226
|
+
}
|
|
216
227
|
} catch (err) {
|
|
217
228
|
console.log(` JSON-LD not available: ${err instanceof Error ? err.message : String(err)}`);
|
|
218
229
|
}
|
|
@@ -221,7 +232,10 @@ var MetadataResolver = class {
|
|
|
221
232
|
if ((await fetch(this.corsProxy ? `${this.corsProxy}${encodeURIComponent(jsonUrl)}` : jsonUrl, {
|
|
222
233
|
method: "HEAD",
|
|
223
234
|
signal: AbortSignal.timeout(this.requestTimeout)
|
|
224
|
-
})).ok)
|
|
235
|
+
})).ok) {
|
|
236
|
+
console.log(` Found JSON: ${jsonUrl}`);
|
|
237
|
+
return jsonUrl;
|
|
238
|
+
}
|
|
225
239
|
} catch (err) {
|
|
226
240
|
console.log(` JSON not available: ${err instanceof Error ? err.message : String(err)}`);
|
|
227
241
|
}
|
|
@@ -231,7 +245,10 @@ var MetadataResolver = class {
|
|
|
231
245
|
if ((await fetch(this.corsProxy ? `${this.corsProxy}${encodeURIComponent(candidate)}` : candidate, {
|
|
232
246
|
method: "HEAD",
|
|
233
247
|
signal: AbortSignal.timeout(this.requestTimeout)
|
|
234
|
-
})).ok)
|
|
248
|
+
})).ok) {
|
|
249
|
+
console.log(` Found: ${candidate}`);
|
|
250
|
+
return candidate;
|
|
251
|
+
}
|
|
235
252
|
} catch (err) {
|
|
236
253
|
console.log(` Not available: ${candidate} - ${err instanceof Error ? err.message : String(err)}`);
|
|
237
254
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,34 +1,12 @@
|
|
|
1
|
-
import { MDProfile } from "@
|
|
1
|
+
import { LanguageCodedText, MDProfile, MDProfile as MDProfile$1 } from "@iqbspecs/metadata-profile";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Configuration options for the MetadataResolver
|
|
6
|
-
*/
|
|
7
4
|
interface LoaderOptions {
|
|
8
|
-
/**
|
|
9
|
-
* CORS proxy URL (e.g., 'https://corsproxy.io/?')
|
|
10
|
-
* If provided, all fetch requests will be proxied through this URL
|
|
11
|
-
*/
|
|
12
5
|
corsProxy?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Enable caching of loaded resources
|
|
15
|
-
* @default true
|
|
16
|
-
*/
|
|
17
6
|
cache?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Preferred language for vocabulary labels
|
|
20
|
-
* @default 'de'
|
|
21
|
-
*/
|
|
22
7
|
preferredLanguage?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Request timeout in milliseconds
|
|
25
|
-
* @default 10000
|
|
26
|
-
*/
|
|
27
8
|
requestTimeout?: number;
|
|
28
9
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Vocabulary concept node structure
|
|
31
|
-
*/
|
|
32
10
|
interface VocabConcept {
|
|
33
11
|
id: string;
|
|
34
12
|
notation?: string[];
|
|
@@ -40,9 +18,6 @@ interface VocabConcept {
|
|
|
40
18
|
description?: string;
|
|
41
19
|
narrower?: VocabConcept[];
|
|
42
20
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Raw vocabulary data structure from vocabulary JSON files
|
|
45
|
-
*/
|
|
46
21
|
interface VocabularyData {
|
|
47
22
|
id?: string;
|
|
48
23
|
type?: string;
|
|
@@ -54,45 +29,33 @@ interface VocabularyEntry {
|
|
|
54
29
|
name: string;
|
|
55
30
|
notation: string[];
|
|
56
31
|
description?: string;
|
|
57
|
-
text:
|
|
32
|
+
text: LanguageCodedText[];
|
|
58
33
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Resolved vocabulary with data and lookup dictionary
|
|
61
|
-
*/
|
|
62
34
|
interface ResolvedVocabulary {
|
|
63
35
|
url: string;
|
|
64
36
|
data: VocabularyData;
|
|
65
37
|
dictionary: Record<string, VocabularyEntry>;
|
|
66
38
|
error?: string;
|
|
67
39
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Profile loaded with all its vocabularies
|
|
70
|
-
*/
|
|
71
40
|
interface ProfileWithVocabularies {
|
|
72
|
-
profile: MDProfile;
|
|
41
|
+
profile: MDProfile$1;
|
|
73
42
|
vocabularies: ResolvedVocabulary[];
|
|
74
43
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Complete metadata package with profile, metadata, and vocabularies
|
|
77
|
-
*/
|
|
78
44
|
interface MetadataWithProfile {
|
|
79
|
-
profile: MDProfile;
|
|
45
|
+
profile: MDProfile$1;
|
|
80
46
|
metadata: unknown;
|
|
81
47
|
vocabularies: ResolvedVocabulary[];
|
|
82
48
|
}
|
|
83
49
|
/**
|
|
84
|
-
*
|
|
50
|
+
* @deprecated Use LanguageCodedText instead.
|
|
85
51
|
*/
|
|
86
|
-
|
|
87
|
-
lang: string;
|
|
88
|
-
value: string;
|
|
89
|
-
}
|
|
52
|
+
type TextWithLanguage = LanguageCodedText;
|
|
90
53
|
/**
|
|
91
|
-
*
|
|
54
|
+
* @deprecated Will be removed when values spec is adopted.
|
|
92
55
|
*/
|
|
93
56
|
interface TextWithLanguageAndId {
|
|
94
57
|
id: string;
|
|
95
|
-
text:
|
|
58
|
+
text: LanguageCodedText[];
|
|
96
59
|
}
|
|
97
60
|
//#endregion
|
|
98
61
|
//#region src/metadata-resolver.d.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,34 +1,12 @@
|
|
|
1
|
-
import { MDProfile } from "@
|
|
1
|
+
import { LanguageCodedText, MDProfile, MDProfile as MDProfile$1 } from "@iqbspecs/metadata-profile";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Configuration options for the MetadataResolver
|
|
6
|
-
*/
|
|
7
4
|
interface LoaderOptions {
|
|
8
|
-
/**
|
|
9
|
-
* CORS proxy URL (e.g., 'https://corsproxy.io/?')
|
|
10
|
-
* If provided, all fetch requests will be proxied through this URL
|
|
11
|
-
*/
|
|
12
5
|
corsProxy?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Enable caching of loaded resources
|
|
15
|
-
* @default true
|
|
16
|
-
*/
|
|
17
6
|
cache?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Preferred language for vocabulary labels
|
|
20
|
-
* @default 'de'
|
|
21
|
-
*/
|
|
22
7
|
preferredLanguage?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Request timeout in milliseconds
|
|
25
|
-
* @default 10000
|
|
26
|
-
*/
|
|
27
8
|
requestTimeout?: number;
|
|
28
9
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Vocabulary concept node structure
|
|
31
|
-
*/
|
|
32
10
|
interface VocabConcept {
|
|
33
11
|
id: string;
|
|
34
12
|
notation?: string[];
|
|
@@ -40,9 +18,6 @@ interface VocabConcept {
|
|
|
40
18
|
description?: string;
|
|
41
19
|
narrower?: VocabConcept[];
|
|
42
20
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Raw vocabulary data structure from vocabulary JSON files
|
|
45
|
-
*/
|
|
46
21
|
interface VocabularyData {
|
|
47
22
|
id?: string;
|
|
48
23
|
type?: string;
|
|
@@ -54,45 +29,33 @@ interface VocabularyEntry {
|
|
|
54
29
|
name: string;
|
|
55
30
|
notation: string[];
|
|
56
31
|
description?: string;
|
|
57
|
-
text:
|
|
32
|
+
text: LanguageCodedText[];
|
|
58
33
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Resolved vocabulary with data and lookup dictionary
|
|
61
|
-
*/
|
|
62
34
|
interface ResolvedVocabulary {
|
|
63
35
|
url: string;
|
|
64
36
|
data: VocabularyData;
|
|
65
37
|
dictionary: Record<string, VocabularyEntry>;
|
|
66
38
|
error?: string;
|
|
67
39
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Profile loaded with all its vocabularies
|
|
70
|
-
*/
|
|
71
40
|
interface ProfileWithVocabularies {
|
|
72
|
-
profile: MDProfile;
|
|
41
|
+
profile: MDProfile$1;
|
|
73
42
|
vocabularies: ResolvedVocabulary[];
|
|
74
43
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Complete metadata package with profile, metadata, and vocabularies
|
|
77
|
-
*/
|
|
78
44
|
interface MetadataWithProfile {
|
|
79
|
-
profile: MDProfile;
|
|
45
|
+
profile: MDProfile$1;
|
|
80
46
|
metadata: unknown;
|
|
81
47
|
vocabularies: ResolvedVocabulary[];
|
|
82
48
|
}
|
|
83
49
|
/**
|
|
84
|
-
*
|
|
50
|
+
* @deprecated Use LanguageCodedText instead.
|
|
85
51
|
*/
|
|
86
|
-
|
|
87
|
-
lang: string;
|
|
88
|
-
value: string;
|
|
89
|
-
}
|
|
52
|
+
type TextWithLanguage = LanguageCodedText;
|
|
90
53
|
/**
|
|
91
|
-
*
|
|
54
|
+
* @deprecated Will be removed when values spec is adopted.
|
|
92
55
|
*/
|
|
93
56
|
interface TextWithLanguageAndId {
|
|
94
57
|
id: string;
|
|
95
|
-
text:
|
|
58
|
+
text: LanguageCodedText[];
|
|
96
59
|
}
|
|
97
60
|
//#endregion
|
|
98
61
|
//#region src/metadata-resolver.d.ts
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { LanguageCodedText, MDProfile, MDProfile as MDProfile$1 } from "@iqbspecs/metadata-profile";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
interface LoaderOptions {
|
|
5
|
+
corsProxy?: string;
|
|
6
|
+
cache?: boolean;
|
|
7
|
+
preferredLanguage?: string;
|
|
8
|
+
requestTimeout?: number;
|
|
9
|
+
}
|
|
10
|
+
interface VocabConcept {
|
|
11
|
+
id: string;
|
|
12
|
+
notation?: string[];
|
|
13
|
+
prefLabel?: {
|
|
14
|
+
de?: string;
|
|
15
|
+
en?: string;
|
|
16
|
+
[key: string]: string | undefined;
|
|
17
|
+
};
|
|
18
|
+
description?: string;
|
|
19
|
+
narrower?: VocabConcept[];
|
|
20
|
+
}
|
|
21
|
+
interface VocabularyData {
|
|
22
|
+
id?: string;
|
|
23
|
+
type?: string;
|
|
24
|
+
title?: Record<string, string>;
|
|
25
|
+
hasTopConcept?: VocabConcept[];
|
|
26
|
+
}
|
|
27
|
+
interface VocabularyEntry {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
notation: string[];
|
|
31
|
+
description?: string;
|
|
32
|
+
text: LanguageCodedText[];
|
|
33
|
+
}
|
|
34
|
+
interface ResolvedVocabulary {
|
|
35
|
+
url: string;
|
|
36
|
+
data: VocabularyData;
|
|
37
|
+
dictionary: Record<string, VocabularyEntry>;
|
|
38
|
+
error?: string;
|
|
39
|
+
}
|
|
40
|
+
interface ProfileWithVocabularies {
|
|
41
|
+
profile: MDProfile$1;
|
|
42
|
+
vocabularies: ResolvedVocabulary[];
|
|
43
|
+
}
|
|
44
|
+
interface MetadataWithProfile {
|
|
45
|
+
profile: MDProfile$1;
|
|
46
|
+
metadata: unknown;
|
|
47
|
+
vocabularies: ResolvedVocabulary[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Use LanguageCodedText instead.
|
|
51
|
+
*/
|
|
52
|
+
type TextWithLanguage = LanguageCodedText;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Will be removed when values spec is adopted.
|
|
55
|
+
*/
|
|
56
|
+
interface TextWithLanguageAndId {
|
|
57
|
+
id: string;
|
|
58
|
+
text: LanguageCodedText[];
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/metadata-resolver.d.ts
|
|
62
|
+
declare class MetadataResolver {
|
|
63
|
+
private corsProxy;
|
|
64
|
+
private cache;
|
|
65
|
+
private vocabulariesStore;
|
|
66
|
+
private useCache;
|
|
67
|
+
private preferredLanguage;
|
|
68
|
+
private requestTimeout;
|
|
69
|
+
constructor(options?: LoaderOptions);
|
|
70
|
+
setCorsProxy(proxy: string | undefined): void;
|
|
71
|
+
/**
|
|
72
|
+
* Load a profile from a URL
|
|
73
|
+
*/
|
|
74
|
+
loadProfile(url: string): Promise<MDProfile>;
|
|
75
|
+
/**
|
|
76
|
+
* Load metadata from a URL
|
|
77
|
+
*/
|
|
78
|
+
loadMetadata(url: string): Promise<unknown>;
|
|
79
|
+
/**
|
|
80
|
+
* Extract vocabulary URLs from a profile
|
|
81
|
+
*/
|
|
82
|
+
extractVocabularyUrls(profile: MDProfile): string[];
|
|
83
|
+
/**
|
|
84
|
+
* Load a single vocabulary from URL
|
|
85
|
+
* Uses vocabulariesStore as the cache
|
|
86
|
+
*/
|
|
87
|
+
loadVocabulary(url: string): Promise<ResolvedVocabulary>;
|
|
88
|
+
/**
|
|
89
|
+
* Load all vocabularies referenced in a profile
|
|
90
|
+
*/
|
|
91
|
+
loadVocabularies(profile: MDProfile): Promise<ResolvedVocabulary[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Build a dictionary from vocabulary data
|
|
94
|
+
*/
|
|
95
|
+
private buildVocabularyDictionary;
|
|
96
|
+
/**
|
|
97
|
+
* Load a profile and all its vocabularies
|
|
98
|
+
*/
|
|
99
|
+
loadProfileWithVocabularies(profileUrl: string): Promise<ProfileWithVocabularies>;
|
|
100
|
+
/**
|
|
101
|
+
* Resolve a URL to its JSON-LD representation
|
|
102
|
+
*/
|
|
103
|
+
private resolveJsonLdUrl;
|
|
104
|
+
/**
|
|
105
|
+
* Load both profile with vocabularies and metadata
|
|
106
|
+
*/
|
|
107
|
+
loadAll(profileUrl: string, metadataUrl: string): Promise<MetadataWithProfile>;
|
|
108
|
+
/**
|
|
109
|
+
* Extract text from a label (string or multilingual array)
|
|
110
|
+
*/
|
|
111
|
+
static extractLabelText(label: string | Array<{
|
|
112
|
+
lang: string;
|
|
113
|
+
value: string;
|
|
114
|
+
}>, preferredLanguage?: string): string;
|
|
115
|
+
/**
|
|
116
|
+
* Clear all caches (profiles, metadata, and vocabularies)
|
|
117
|
+
*/
|
|
118
|
+
clearCache(): void;
|
|
119
|
+
/**
|
|
120
|
+
* Get all loaded vocabularies
|
|
121
|
+
*/
|
|
122
|
+
getVocabularies(): ResolvedVocabulary[];
|
|
123
|
+
/**
|
|
124
|
+
* Get a specific vocabulary by URL
|
|
125
|
+
*/
|
|
126
|
+
getVocabulary(url: string): ResolvedVocabulary | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Get combined dictionary of all vocabulary entries
|
|
129
|
+
*/
|
|
130
|
+
getVocabularyDictionary(): Record<string, VocabularyEntry>;
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
export { type LoaderOptions, MetadataResolver, type MetadataWithProfile, type ProfileWithVocabularies, type ResolvedVocabulary, type TextWithLanguage, type TextWithLanguageAndId, type VocabConcept, type VocabularyData, type VocabularyEntry };
|
package/dist/index.mjs
CHANGED
|
@@ -66,7 +66,7 @@ var MetadataResolver = class {
|
|
|
66
66
|
const urls = /* @__PURE__ */ new Set();
|
|
67
67
|
profile.groups?.forEach((group) => {
|
|
68
68
|
group.entries?.forEach((entry) => {
|
|
69
|
-
if (entry.type === "
|
|
69
|
+
if (entry.type.toUpperCase() === "VOCABULARY" && entry.parameters) {
|
|
70
70
|
const params = entry.parameters;
|
|
71
71
|
if (params.url) urls.add(params.url);
|
|
72
72
|
}
|
|
@@ -81,10 +81,11 @@ var MetadataResolver = class {
|
|
|
81
81
|
async loadVocabulary(url) {
|
|
82
82
|
if (this.useCache && this.vocabulariesStore.has(url)) return this.vocabulariesStore.get(url);
|
|
83
83
|
try {
|
|
84
|
+
console.log(`Loading vocabulary: ${url}`);
|
|
84
85
|
const jsonLdUrl = await this.resolveJsonLdUrl(url);
|
|
85
|
-
if (jsonLdUrl !== url) {}
|
|
86
|
+
if (jsonLdUrl !== url) console.log(` Resolved to: ${jsonLdUrl}`);
|
|
86
87
|
const fetchUrl = this.corsProxy ? `${this.corsProxy}${encodeURIComponent(jsonLdUrl)}` : jsonLdUrl;
|
|
87
|
-
if (this.corsProxy)
|
|
88
|
+
if (this.corsProxy) console.log(" Using CORS proxy");
|
|
88
89
|
let response;
|
|
89
90
|
try {
|
|
90
91
|
response = await fetch(fetchUrl, { signal: AbortSignal.timeout(this.requestTimeout) });
|
|
@@ -138,6 +139,7 @@ var MetadataResolver = class {
|
|
|
138
139
|
dictionary
|
|
139
140
|
};
|
|
140
141
|
if (this.useCache) this.vocabulariesStore.set(url, resolved);
|
|
142
|
+
console.log(` Loaded: ${data.hasTopConcept.length} concepts, ${Object.keys(dictionary).length} entries`);
|
|
141
143
|
return resolved;
|
|
142
144
|
} catch (error) {
|
|
143
145
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
@@ -155,7 +157,9 @@ var MetadataResolver = class {
|
|
|
155
157
|
*/
|
|
156
158
|
async loadVocabularies(profile) {
|
|
157
159
|
const urls = this.extractVocabularyUrls(profile);
|
|
158
|
-
|
|
160
|
+
const vocabularies = (await Promise.allSettled(urls.map((url) => this.loadVocabulary(url)))).filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
161
|
+
console.log(`Loaded ${vocabularies.length} vocabularies (${this.vocabulariesStore.size} total in store)`);
|
|
162
|
+
return vocabularies;
|
|
159
163
|
}
|
|
160
164
|
/**
|
|
161
165
|
* Build a dictionary from vocabulary data
|
|
@@ -195,7 +199,10 @@ var MetadataResolver = class {
|
|
|
195
199
|
*/
|
|
196
200
|
async resolveJsonLdUrl(originalUrl) {
|
|
197
201
|
try {
|
|
202
|
+
console.log(`Resolving URL: ${originalUrl}`);
|
|
203
|
+
console.log(` CORS proxy: ${this.corsProxy || "disabled"}`);
|
|
198
204
|
const fetchUrl = this.corsProxy ? `${this.corsProxy}${encodeURIComponent(originalUrl)}` : originalUrl;
|
|
205
|
+
console.log(` Fetching: ${fetchUrl}`);
|
|
199
206
|
const res = await fetch(fetchUrl, {
|
|
200
207
|
method: "GET",
|
|
201
208
|
redirect: "follow",
|
|
@@ -211,7 +218,10 @@ var MetadataResolver = class {
|
|
|
211
218
|
if ((await fetch(this.corsProxy ? `${this.corsProxy}${encodeURIComponent(jsonldUrl)}` : jsonldUrl, {
|
|
212
219
|
method: "HEAD",
|
|
213
220
|
signal: AbortSignal.timeout(this.requestTimeout)
|
|
214
|
-
})).ok)
|
|
221
|
+
})).ok) {
|
|
222
|
+
console.log(` Found JSON-LD: ${jsonldUrl}`);
|
|
223
|
+
return jsonldUrl;
|
|
224
|
+
}
|
|
215
225
|
} catch (err) {
|
|
216
226
|
console.log(` JSON-LD not available: ${err instanceof Error ? err.message : String(err)}`);
|
|
217
227
|
}
|
|
@@ -220,7 +230,10 @@ var MetadataResolver = class {
|
|
|
220
230
|
if ((await fetch(this.corsProxy ? `${this.corsProxy}${encodeURIComponent(jsonUrl)}` : jsonUrl, {
|
|
221
231
|
method: "HEAD",
|
|
222
232
|
signal: AbortSignal.timeout(this.requestTimeout)
|
|
223
|
-
})).ok)
|
|
233
|
+
})).ok) {
|
|
234
|
+
console.log(` Found JSON: ${jsonUrl}`);
|
|
235
|
+
return jsonUrl;
|
|
236
|
+
}
|
|
224
237
|
} catch (err) {
|
|
225
238
|
console.log(` JSON not available: ${err instanceof Error ? err.message : String(err)}`);
|
|
226
239
|
}
|
|
@@ -230,7 +243,10 @@ var MetadataResolver = class {
|
|
|
230
243
|
if ((await fetch(this.corsProxy ? `${this.corsProxy}${encodeURIComponent(candidate)}` : candidate, {
|
|
231
244
|
method: "HEAD",
|
|
232
245
|
signal: AbortSignal.timeout(this.requestTimeout)
|
|
233
|
-
})).ok)
|
|
246
|
+
})).ok) {
|
|
247
|
+
console.log(` Found: ${candidate}`);
|
|
248
|
+
return candidate;
|
|
249
|
+
}
|
|
234
250
|
} catch (err) {
|
|
235
251
|
console.log(` Not available: ${candidate} - ${err instanceof Error ? err.message : String(err)}`);
|
|
236
252
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iqb/metadata-resolver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Framework-agnostic metadata and vocabulary resolver for IQB metadata profiles",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "tsdown src/index.ts --format cjs,esm --dts --clean",
|
|
12
|
+
"build": "tsdown src/index.ts --format cjs,esm --dts --clean && cp dist/index.d.mts dist/index.d.ts",
|
|
13
13
|
"dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
|
|
14
14
|
"test": "vitest run",
|
|
15
15
|
"lint": "eslint src",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"author": "IQB",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@
|
|
30
|
+
"@iqbspecs/metadata-profile": "^0.11.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^25.0.10",
|