@digitalculture/ochre-sdk 0.16.1 → 0.16.2
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.d.mts +15 -14
- package/dist/index.mjs +27 -44
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -88,7 +88,7 @@ type Person = {
|
|
|
88
88
|
category: "person";
|
|
89
89
|
belongsTo: {
|
|
90
90
|
uuid: string;
|
|
91
|
-
|
|
91
|
+
abbreviation: string;
|
|
92
92
|
} | null;
|
|
93
93
|
metadata: Metadata | null;
|
|
94
94
|
publicationDateTime: Date | null;
|
|
@@ -296,7 +296,7 @@ type Resource = {
|
|
|
296
296
|
category: "resource";
|
|
297
297
|
belongsTo: {
|
|
298
298
|
uuid: string;
|
|
299
|
-
|
|
299
|
+
abbreviation: string;
|
|
300
300
|
} | null;
|
|
301
301
|
metadata: Metadata | null;
|
|
302
302
|
publicationDateTime: Date | null;
|
|
@@ -334,7 +334,7 @@ type SpatialUnit = {
|
|
|
334
334
|
category: "spatialUnit";
|
|
335
335
|
belongsTo: {
|
|
336
336
|
uuid: string;
|
|
337
|
-
|
|
337
|
+
abbreviation: string;
|
|
338
338
|
} | null;
|
|
339
339
|
metadata: Metadata | null;
|
|
340
340
|
publicationDateTime: Date | null;
|
|
@@ -365,7 +365,7 @@ type Concept = {
|
|
|
365
365
|
category: "concept";
|
|
366
366
|
belongsTo: {
|
|
367
367
|
uuid: string;
|
|
368
|
-
|
|
368
|
+
abbreviation: string;
|
|
369
369
|
} | null;
|
|
370
370
|
metadata: Metadata | null;
|
|
371
371
|
publicationDateTime: Date | null;
|
|
@@ -389,7 +389,7 @@ type Set<U extends DataCategory = DataCategory> = {
|
|
|
389
389
|
category: "set";
|
|
390
390
|
belongsTo: {
|
|
391
391
|
uuid: string;
|
|
392
|
-
|
|
392
|
+
abbreviation: string;
|
|
393
393
|
} | null;
|
|
394
394
|
metadata: Metadata | null;
|
|
395
395
|
itemCategories: Array<U>;
|
|
@@ -414,7 +414,7 @@ type Bibliography = {
|
|
|
414
414
|
category: "bibliography";
|
|
415
415
|
belongsTo: {
|
|
416
416
|
uuid: string;
|
|
417
|
-
|
|
417
|
+
abbreviation: string;
|
|
418
418
|
} | null;
|
|
419
419
|
metadata: Metadata | null;
|
|
420
420
|
publicationDateTime: Date | null;
|
|
@@ -454,7 +454,7 @@ type Period = {
|
|
|
454
454
|
category: "period";
|
|
455
455
|
belongsTo: {
|
|
456
456
|
uuid: string;
|
|
457
|
-
|
|
457
|
+
abbreviation: string;
|
|
458
458
|
} | null;
|
|
459
459
|
metadata: Metadata | null;
|
|
460
460
|
publicationDateTime: Date | null;
|
|
@@ -473,7 +473,7 @@ type PropertyValue = {
|
|
|
473
473
|
category: "propertyValue";
|
|
474
474
|
belongsTo: {
|
|
475
475
|
uuid: string;
|
|
476
|
-
|
|
476
|
+
abbreviation: string;
|
|
477
477
|
} | null;
|
|
478
478
|
metadata: Metadata | null;
|
|
479
479
|
persistentUrl: string | null;
|
|
@@ -528,7 +528,7 @@ type Text = {
|
|
|
528
528
|
category: "text";
|
|
529
529
|
belongsTo: {
|
|
530
530
|
uuid: string;
|
|
531
|
-
|
|
531
|
+
abbreviation: string;
|
|
532
532
|
} | null;
|
|
533
533
|
metadata: Metadata | null;
|
|
534
534
|
publicationDateTime: Date | null;
|
|
@@ -572,7 +572,7 @@ type Tree<U extends Exclude<DataCategory, "tree"> = Exclude<DataCategory, "tree"
|
|
|
572
572
|
category: "tree";
|
|
573
573
|
belongsTo: {
|
|
574
574
|
uuid: string;
|
|
575
|
-
|
|
575
|
+
abbreviation: string;
|
|
576
576
|
} | null;
|
|
577
577
|
metadata: Metadata | null;
|
|
578
578
|
publicationDateTime: Date | null;
|
|
@@ -666,12 +666,13 @@ type Scope = {
|
|
|
666
666
|
type Website = {
|
|
667
667
|
uuid: string;
|
|
668
668
|
version: 1 | 2;
|
|
669
|
+
belongsTo: {
|
|
670
|
+
uuid: string;
|
|
671
|
+
abbreviation: string;
|
|
672
|
+
} | null;
|
|
673
|
+
metadata: Metadata;
|
|
669
674
|
publicationDateTime: Date | null;
|
|
670
675
|
identification: Identification;
|
|
671
|
-
project: {
|
|
672
|
-
name: string;
|
|
673
|
-
website: string | null;
|
|
674
|
-
};
|
|
675
676
|
creators: Array<Person>;
|
|
676
677
|
license: License | null;
|
|
677
678
|
pages: Array<Webpage>;
|
package/dist/index.mjs
CHANGED
|
@@ -3153,7 +3153,7 @@ function parseContexts(contexts) {
|
|
|
3153
3153
|
}
|
|
3154
3154
|
return contextsParsed;
|
|
3155
3155
|
}
|
|
3156
|
-
function parseWebsite(websiteTree,
|
|
3156
|
+
function parseWebsite(websiteTree, metadata, belongsTo, { isVersion2 = false } = {}) {
|
|
3157
3157
|
if (!websiteTree.properties) throw new Error("Website properties not found");
|
|
3158
3158
|
const properties = parseWebsiteProperties(Array.isArray(websiteTree.properties.property) ? websiteTree.properties.property : [websiteTree.properties.property], websiteTree);
|
|
3159
3159
|
if (typeof websiteTree.items === "string" || !("resource" in websiteTree.items)) throw new Error("Website pages not found");
|
|
@@ -3163,12 +3163,10 @@ function parseWebsite(websiteTree, projectName, website, { isVersion2 = false }
|
|
|
3163
3163
|
return {
|
|
3164
3164
|
uuid: websiteTree.uuid,
|
|
3165
3165
|
version: isVersion2 ? 2 : 1,
|
|
3166
|
+
belongsTo: belongsTo ?? null,
|
|
3167
|
+
metadata: parseMetadata(metadata),
|
|
3166
3168
|
publicationDateTime: websiteTree.publicationDateTime ? new Date(websiteTree.publicationDateTime) : null,
|
|
3167
3169
|
identification: parseIdentification(websiteTree.identification),
|
|
3168
|
-
project: {
|
|
3169
|
-
name: parseFakeString(projectName),
|
|
3170
|
-
website: website !== null ? parseFakeString(website) : null
|
|
3171
|
-
},
|
|
3172
3170
|
creators: websiteTree.creators ? parsePersons(Array.isArray(websiteTree.creators.creator) ? websiteTree.creators.creator : [websiteTree.creators.creator]) : [],
|
|
3173
3171
|
license: parseLicense(websiteTree.availability),
|
|
3174
3172
|
sidebar,
|
|
@@ -3323,78 +3321,55 @@ async function fetchItem(uuid, category, itemCategory, options) {
|
|
|
3323
3321
|
});
|
|
3324
3322
|
if (error !== null) throw new Error(error);
|
|
3325
3323
|
const categoryKey = getItemCategory(Object.keys(data.ochre));
|
|
3324
|
+
const belongsTo = {
|
|
3325
|
+
uuid: data.ochre.uuidBelongsTo,
|
|
3326
|
+
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
3327
|
+
};
|
|
3326
3328
|
const metadata = parseMetadata(data.ochre.metadata);
|
|
3327
3329
|
let item;
|
|
3328
3330
|
switch (categoryKey) {
|
|
3329
3331
|
case "resource":
|
|
3330
3332
|
if (!("resource" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'resource' key");
|
|
3331
|
-
item = parseResource(data.ochre.resource, metadata, data.ochre.persistentUrl,
|
|
3332
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
3333
|
-
name: parseFakeString(data.ochre.belongsTo)
|
|
3334
|
-
});
|
|
3333
|
+
item = parseResource(data.ochre.resource, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3335
3334
|
break;
|
|
3336
3335
|
case "spatialUnit":
|
|
3337
3336
|
if (!("spatialUnit" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'spatialUnit' key");
|
|
3338
|
-
item = parseSpatialUnit(data.ochre.spatialUnit, metadata, data.ochre.persistentUrl,
|
|
3339
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
3340
|
-
name: parseFakeString(data.ochre.belongsTo)
|
|
3341
|
-
});
|
|
3337
|
+
item = parseSpatialUnit(data.ochre.spatialUnit, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3342
3338
|
break;
|
|
3343
3339
|
case "concept":
|
|
3344
3340
|
if (!("concept" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'concept' key");
|
|
3345
|
-
item = parseConcept(data.ochre.concept, metadata, data.ochre.persistentUrl,
|
|
3346
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
3347
|
-
name: parseFakeString(data.ochre.belongsTo)
|
|
3348
|
-
});
|
|
3341
|
+
item = parseConcept(data.ochre.concept, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3349
3342
|
break;
|
|
3350
3343
|
case "period":
|
|
3351
3344
|
if (!("period" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'period' key");
|
|
3352
3345
|
item = parsePeriod(data.ochre.period, metadata, data.ochre.persistentUrl, {
|
|
3353
3346
|
uuid: data.ochre.uuidBelongsTo,
|
|
3354
|
-
|
|
3347
|
+
abbreviation: parseFakeString(data.ochre.belongsTo)
|
|
3355
3348
|
});
|
|
3356
3349
|
break;
|
|
3357
3350
|
case "bibliography":
|
|
3358
3351
|
if (!("bibliography" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'bibliography' key");
|
|
3359
|
-
item = parseBibliography(data.ochre.bibliography, metadata, data.ochre.persistentUrl,
|
|
3360
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
3361
|
-
name: parseFakeString(data.ochre.belongsTo)
|
|
3362
|
-
});
|
|
3352
|
+
item = parseBibliography(data.ochre.bibliography, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3363
3353
|
break;
|
|
3364
3354
|
case "person":
|
|
3365
3355
|
if (!("person" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'person' key");
|
|
3366
|
-
item = parsePerson(data.ochre.person, metadata, data.ochre.persistentUrl,
|
|
3367
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
3368
|
-
name: parseFakeString(data.ochre.belongsTo)
|
|
3369
|
-
});
|
|
3356
|
+
item = parsePerson(data.ochre.person, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3370
3357
|
break;
|
|
3371
3358
|
case "propertyValue":
|
|
3372
3359
|
if (!("propertyValue" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'propertyValue' key");
|
|
3373
|
-
item = parsePropertyValue(data.ochre.propertyValue, metadata, data.ochre.persistentUrl,
|
|
3374
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
3375
|
-
name: parseFakeString(data.ochre.belongsTo)
|
|
3376
|
-
});
|
|
3360
|
+
item = parsePropertyValue(data.ochre.propertyValue, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3377
3361
|
break;
|
|
3378
3362
|
case "text":
|
|
3379
3363
|
if (!("text" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'text' key");
|
|
3380
|
-
item = parseText(data.ochre.text, metadata, data.ochre.persistentUrl,
|
|
3381
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
3382
|
-
name: parseFakeString(data.ochre.belongsTo)
|
|
3383
|
-
});
|
|
3364
|
+
item = parseText(data.ochre.text, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3384
3365
|
break;
|
|
3385
3366
|
case "set":
|
|
3386
3367
|
if (!("set" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'set' key");
|
|
3387
|
-
item = parseSet(data.ochre.set, itemCategory, metadata, data.ochre.persistentUrl,
|
|
3388
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
3389
|
-
name: parseFakeString(data.ochre.belongsTo)
|
|
3390
|
-
});
|
|
3368
|
+
item = parseSet(data.ochre.set, itemCategory, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3391
3369
|
break;
|
|
3392
3370
|
case "tree":
|
|
3393
3371
|
if (!("tree" in data.ochre)) throw new Error("Invalid OCHRE data: API response missing 'tree' key");
|
|
3394
|
-
item = parseTree(data.ochre.tree, itemCategory, metadata, data.ochre.persistentUrl,
|
|
3395
|
-
uuid: data.ochre.uuidBelongsTo,
|
|
3396
|
-
name: parseFakeString(data.ochre.belongsTo)
|
|
3397
|
-
});
|
|
3372
|
+
item = parseTree(data.ochre.tree, itemCategory, metadata, data.ochre.persistentUrl, belongsTo);
|
|
3398
3373
|
break;
|
|
3399
3374
|
default: throw new Error("Invalid category");
|
|
3400
3375
|
}
|
|
@@ -3628,6 +3603,7 @@ async function fetchWebsite(abbreviation, options) {
|
|
|
3628
3603
|
const isVersion2 = cleanAbbreviation.endsWith("-v2") ? true : options?.isVersion2 ?? false;
|
|
3629
3604
|
let metadata = null;
|
|
3630
3605
|
let tree = null;
|
|
3606
|
+
let belongsTo = null;
|
|
3631
3607
|
if (isVersion2) {
|
|
3632
3608
|
const response = await (customFetch ?? fetch)(`https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery=${encodeURIComponent(`collection('ochre/tree')/ochre[tree/identification/abbreviation/content/string='${cleanAbbreviation.replace("-v2", "")}']`)}&format=json&lang="*"`);
|
|
3633
3609
|
if (!response.ok) throw new Error("Failed to fetch website");
|
|
@@ -3635,6 +3611,10 @@ async function fetchWebsite(abbreviation, options) {
|
|
|
3635
3611
|
if (Array.isArray(data.result) || !("tree" in data.result.ochre)) throw new Error("Failed to fetch website");
|
|
3636
3612
|
metadata = data.result.ochre.metadata;
|
|
3637
3613
|
tree = data.result.ochre.tree;
|
|
3614
|
+
belongsTo = {
|
|
3615
|
+
uuid: data.result.ochre.uuidBelongsTo,
|
|
3616
|
+
abbreviation: parseFakeString(data.result.ochre.belongsTo)
|
|
3617
|
+
};
|
|
3638
3618
|
} else {
|
|
3639
3619
|
const uuid = KNOWN_ABBREVIATIONS[cleanAbbreviation];
|
|
3640
3620
|
const response = await (customFetch ?? fetch)(uuid != null ? `https://ochre.lib.uchicago.edu/ochre?uuid=${uuid}&format=json` : `https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(`for $q in input()/ochre[tree[@type='lesson'][identification/abbreviation='${cleanAbbreviation}']] return $q`)}&format=json`);
|
|
@@ -3644,9 +3624,12 @@ async function fetchWebsite(abbreviation, options) {
|
|
|
3644
3624
|
if (result == null || !("tree" in result.ochre)) throw new Error("Failed to fetch website");
|
|
3645
3625
|
metadata = result.ochre.metadata;
|
|
3646
3626
|
tree = result.ochre.tree;
|
|
3627
|
+
belongsTo = {
|
|
3628
|
+
uuid: result.ochre.uuidBelongsTo,
|
|
3629
|
+
abbreviation: parseFakeString(result.ochre.belongsTo)
|
|
3630
|
+
};
|
|
3647
3631
|
}
|
|
3648
|
-
|
|
3649
|
-
return [null, parseWebsite(tree, projectIdentification?.label ?? "", metadata.project?.identification.website ?? null, { isVersion2 })];
|
|
3632
|
+
return [null, parseWebsite(tree, metadata, belongsTo, { isVersion2 })];
|
|
3650
3633
|
} catch (error) {
|
|
3651
3634
|
console.error(error);
|
|
3652
3635
|
return [error instanceof Error ? error.message : "Unknown error", null];
|
package/package.json
CHANGED