Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/presentation-3/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
ResourceProvider,
Selector,
Service,
Services,
SpecificResource,
} from "./types";
import type {
Expand Down Expand Up @@ -85,13 +86,13 @@ function mapToEntities(entities: Record<string, Record<string, NormalizedEntity>
if (resource && resource.id && type) {
storeType[resource.id] = storeType[resource.id]
? (mergeEntities(storeType[resource.id]!, resource, {
parent: context.parent,
isTopLevel: topLevel.id === resource.id,
}) as any)
parent: context.parent,
isTopLevel: topLevel.id === resource.id,
}) as any)
: mergeEntities({ id: resource.id, type: resource.type } as any, resource, {
parent: context.parent,
isTopLevel: topLevel.id === resource.id,
});
parent: context.parent,
isTopLevel: topLevel.id === resource.id,
});
return {
id: resource.id,
type: type === "ContentResource" ? type : resource.type,
Expand Down Expand Up @@ -257,8 +258,7 @@ export function mergeEntities(
}

throw new Error(
`Can only merge entities with identical identifiers and type! ${incoming.type}(${incoming.id}) => ${
(existing as any).type
`Can only merge entities with identical identifiers and type! ${incoming.type}(${incoming.id}) => ${(existing as any).type
}(${(existing as any).id})`
);
}
Expand Down Expand Up @@ -308,7 +308,7 @@ function normalizeService(_service: any): any {
}

function recordServiceForLoading(store: CompatibleStore["entities"]) {
return (resource: Service) => {
return (resource: Service | Services) => {
store.Service = store.Service ? store.Service : {};
const id: string = (resource as any).id || (resource as any)["@id"];
const normalizedResource = normalizeService(resource);
Expand Down
9 changes: 6 additions & 3 deletions src/presentation-3/traverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
SpecificResource,
ResourceProvider,
StructuralProperties,
Services,
} from "./types";
import type { GeoJSON } from "../shared/geojson";
import { isSpecificResource } from "../shared/is-specific-resource";
Expand Down Expand Up @@ -50,6 +51,7 @@ export type Presentation3Resource =
| ChoiceBody
| Range
| Service
| Services
| ResourceProvider
| SpecificResource
| GeoJSON;
Expand All @@ -73,7 +75,7 @@ export type TraversalMap = {
contentResource?: Array<Traversal<ContentResource>>;
choice?: Array<Traversal<ChoiceTarget | ChoiceBody>>;
range?: Array<Traversal<Range>>;
service?: Array<Traversal<Service>>;
service?: Array<Traversal<Services>>;
agent?: Array<Traversal<ResourceProvider>>;
specificResource?: Array<Traversal<SpecificResource>>;
geoJson?: Array<Traversal<GeoJSON>>;
Expand Down Expand Up @@ -512,13 +514,14 @@ export class Traverse {
}, object);
}

traverseService<S extends Service | Services>(service: S, parent?: Presentation3Resource): S;
traverseService(service: Service, parent?: Presentation3Resource): Service;
traverseService(service: Service, parent?: any): Service {
traverseService<S extends Service | Services>(service: S, parent?: any): S {
const _service: any = Object.assign({}, service);
if (_service && _service.service) {
_service.service = ensureArray(_service.service).map((innerService: any) => this.traverseService(innerService));
}
return this.traverseType<Service>(_service, { parent }, this.traversals.service);
return this.traverseType<S>(_service, { parent }, this.traversals.service);
}

traverseUnknown(
Expand Down
4 changes: 2 additions & 2 deletions src/presentation-3/types/legacy/src/iiif/linking.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContentResource } from "../resources/contentResource";
import { Service } from "../resources/service";
import { Service, Services } from "../resources/service";
import { Canvas } from "../resources/canvas";
import { AnnotationCollection } from "../resources/annotationCollection";
import { Reference } from "../reference";
Expand Down Expand Up @@ -71,7 +71,7 @@ export type LinkingProperties = {
* A Manifest may have the services property.
* Clients should process services on a Manifest.
*/
services: Service[];
services: Services[];

/**
* A resource that is an alternative, non-IIIF representation of the resource that has the rendering property. Such
Expand Down
4 changes: 3 additions & 1 deletion src/presentation-3/types/legacy/src/resources/service.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { AuthProbeService2 } from "../services/auth-2";
import { AuthAccessService2, AuthProbeService2 } from "../services/auth-2";
import { AuthService } from "../services/auth-service";
import { GeoJsonService } from "../services/geo-json";
import { ImageService } from "../services/image-service";
import { SearchService } from "../services/search";
import { Search2Service } from "../services/search-2";

export type Service = AuthService | GeoJsonService | ImageService | SearchService | AuthProbeService2 | Search2Service;

export type Services = Service | AuthAccessService2;
Loading