cozy-iiif 0.8.1 → 0.8.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.js +7 -3
- package/dist/types.d.ts +4 -2
- package/package.json +2 -2
- package/src/Cozy.ts +4 -0
- package/src/types.ts +6 -2
- package/test/Cozy.test.ts +14 -1
- package/test/fixtures.ts +3 -0
package/dist/index.js
CHANGED
|
@@ -848,9 +848,12 @@ var Ge = async (e) => {
|
|
|
848
848
|
message: "JSON resource is not a recognized IIIF format"
|
|
849
849
|
};
|
|
850
850
|
}, Ke = (t, n) => {
|
|
851
|
-
let r = (
|
|
852
|
-
let
|
|
853
|
-
return new e({
|
|
851
|
+
let r = (n) => {
|
|
852
|
+
let r = [];
|
|
853
|
+
return new e({
|
|
854
|
+
collection: [(e) => e.id !== s(t, "id") && r.push(e)],
|
|
855
|
+
manifest: [(e) => r.push(e)]
|
|
856
|
+
}).traverseCollection(n), r.map((e) => ({
|
|
854
857
|
id: e.id,
|
|
855
858
|
type: e.type,
|
|
856
859
|
getLabel: p(e),
|
|
@@ -858,6 +861,7 @@ var Ge = async (e) => {
|
|
|
858
861
|
}));
|
|
859
862
|
}, i = n === 2 ? Z(t) : t, a = r(i);
|
|
860
863
|
return {
|
|
864
|
+
type: "Collection",
|
|
861
865
|
source: i,
|
|
862
866
|
id: i.id,
|
|
863
867
|
majorVersion: n,
|
package/dist/types.d.ts
CHANGED
|
@@ -26,16 +26,18 @@ export interface CozyCollection {
|
|
|
26
26
|
readonly majorVersion: number;
|
|
27
27
|
readonly source: Collection;
|
|
28
28
|
readonly id: string;
|
|
29
|
+
readonly type: 'Collection';
|
|
29
30
|
readonly items: CozyCollectionItem[];
|
|
30
31
|
getLabel(locale?: string): string | undefined;
|
|
31
32
|
getMetadata(locale?: string): CozyMetadata[];
|
|
32
33
|
}
|
|
33
|
-
export interface
|
|
34
|
+
export interface CozyCollectionManifestItem {
|
|
34
35
|
readonly id: string;
|
|
35
|
-
readonly type:
|
|
36
|
+
readonly type: 'Manifest';
|
|
36
37
|
readonly source: any;
|
|
37
38
|
getLabel(locale?: string): string | undefined;
|
|
38
39
|
}
|
|
40
|
+
export type CozyCollectionItem = CozyCollectionManifestItem | CozyCollection;
|
|
39
41
|
export interface CozyManifest {
|
|
40
42
|
readonly majorVersion: number;
|
|
41
43
|
readonly source: Manifest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-iiif",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "A developer-friendly collection of abstractions and utilities built on top of @iiif/presentation-3 and @iiif/parser",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Rainer Simon",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "^6.0.3",
|
|
32
|
-
"vite": "^8.0.
|
|
32
|
+
"vite": "^8.0.11",
|
|
33
33
|
"vitest": "^4.1.5"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
package/src/Cozy.ts
CHANGED
|
@@ -158,6 +158,9 @@ const parseCollectionResource = (resource: any, majorVersion: number): CozyColle
|
|
|
158
158
|
const items: any[] = [];
|
|
159
159
|
|
|
160
160
|
const modelBuilder = new Traverse({
|
|
161
|
+
// The model builder fires on the collection ITSELF - we don't want that, but want
|
|
162
|
+
// to collect sub-collections
|
|
163
|
+
collection: [item => item.id !== getPropertyValue(resource, 'id') && items.push(item)],
|
|
161
164
|
manifest: [item => items.push(item)]
|
|
162
165
|
});
|
|
163
166
|
|
|
@@ -176,6 +179,7 @@ const parseCollectionResource = (resource: any, majorVersion: number): CozyColle
|
|
|
176
179
|
const items = parseV3(v3);
|
|
177
180
|
|
|
178
181
|
return {
|
|
182
|
+
type: 'Collection',
|
|
179
183
|
source: v3,
|
|
180
184
|
id: v3.id,
|
|
181
185
|
majorVersion,
|
package/src/types.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface CozyCollection {
|
|
|
28
28
|
|
|
29
29
|
readonly id: string;
|
|
30
30
|
|
|
31
|
+
readonly type: 'Collection';
|
|
32
|
+
|
|
31
33
|
readonly items: CozyCollectionItem[];
|
|
32
34
|
|
|
33
35
|
getLabel(locale?: string): string | undefined;
|
|
@@ -36,11 +38,11 @@ export interface CozyCollection {
|
|
|
36
38
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
export interface
|
|
41
|
+
export interface CozyCollectionManifestItem {
|
|
40
42
|
|
|
41
43
|
readonly id: string;
|
|
42
44
|
|
|
43
|
-
readonly type:
|
|
45
|
+
readonly type: 'Manifest';
|
|
44
46
|
|
|
45
47
|
readonly source: any;
|
|
46
48
|
|
|
@@ -48,6 +50,8 @@ export interface CozyCollectionItem {
|
|
|
48
50
|
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
export type CozyCollectionItem = CozyCollectionManifestItem | CozyCollection;
|
|
54
|
+
|
|
51
55
|
export interface CozyManifest {
|
|
52
56
|
|
|
53
57
|
readonly majorVersion: number;
|
package/test/Cozy.test.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { Cozy, CozyManifest, DynamicImageServiceResource } from '../src';
|
|
2
|
+
import { Cozy, CozyCollection, CozyManifest, DynamicImageServiceResource } from '../src';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
COLLECTION,
|
|
6
|
+
NESTED_COLLECTION,
|
|
6
7
|
INFO_JSON_V3,
|
|
7
8
|
WITH_MULTI_IMAGE,
|
|
8
9
|
WITH_STRUCTURES,
|
|
@@ -14,6 +15,18 @@ describe('Cozy', () => {
|
|
|
14
15
|
it('should parse collection manifests correctly', async () => {
|
|
15
16
|
const result = await Cozy.parseURL(COLLECTION);
|
|
16
17
|
expect(result.type).toBe('collection');
|
|
18
|
+
|
|
19
|
+
const collection = (result as any).resource as CozyCollection;
|
|
20
|
+
expect(collection.items.length).toBe(16);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should parse nested collection manifests correctly', async () => {
|
|
24
|
+
const result = await Cozy.parseURL(NESTED_COLLECTION);
|
|
25
|
+
expect(result.type).toBe('collection');
|
|
26
|
+
|
|
27
|
+
const collection = (result as any).resource as CozyCollection;
|
|
28
|
+
expect(collection.items.length).toBe(7);
|
|
29
|
+
expect(collection.items.every(item => item.type === 'Collection'))
|
|
17
30
|
});
|
|
18
31
|
|
|
19
32
|
it('should parse structures in presentation manifests', async () => {
|
package/test/fixtures.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export const COLLECTION =
|
|
2
2
|
'https://www.davidrumsey.com/luna/servlet/iiif/collection/s/1k986a';
|
|
3
3
|
|
|
4
|
+
export const NESTED_COLLECTION =
|
|
5
|
+
'https://image-ub.bgo1.test.rail.uib.no/iiif/presentation/na/fragmenter/collection.json';
|
|
6
|
+
|
|
4
7
|
export const WITH_STRUCTURES =
|
|
5
8
|
'https://lib.is/IE19255085/manifest';
|
|
6
9
|
|