Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new @iiif/parser/strict for converting P3 #17

Closed
wants to merge 1 commit into from

Conversation

stephenwf
Copy link
Member

Adds new utility for validating and fixing Presentation 3 that may not be valid.

Note: this will not automatically upgrade Presentation 2.

import { presentation3StrictUpgrade } from '@iiif/parser/strict';

const manifest = fetch('https://example.org/manifest').then(r => r.json());

const upgradedManifest = presentation3StrictUpgrade(manifest);

// Should now be valid Presentation 3

You can also get a list of issues with the second argument.

const manifest = {
  id: 'https://example.org',
  type: 'Manifest',
  label: 'Wrong label',
};

const state = { warnings: [] as string[] };
const upgraded = presentation3StrictUpgrade(manifest as any, state);

upgraded.label; // { none: ['Wrong label'] }
state.warnings[0]; // "label" should be a language map instead found a string

Currently supported:

  • Various invalid language map formats
    • single strings {"label": "some label"}
    • arrays of strings {"label": ["some label"]}
    • maps without values {"label": {"en": "some label"}}
    • maps with objects {"label": { en: { INVALID: 'this is not valid' } }}
  • Properties that should be arrays are wrapped (e.g. behavior)
  • Properties that shouldn't be arrays are unwrapped (e.g. format)
  • Ensures that heights and widths are JSON numbers and not floats
  • Ensures that duration is a valid float
  • Ensures that required statements and metadata have both labels and values
  • Ensures rights statement starts with http (may be flaky with custom values)
  • Validates navDate against regular expression from W3C (and removes whitespace)
  • Ensures Manifests only contain Canvases
  • Ensures Canvases only contain Annotation Pages
  • Ensures Annotation Pages only contain Annotations
  • Ensures accompanyingCanvas and placeholderCanvas are type Canvas (only warning)

This is built to be expanded on, and improved if there are other common pitfalls out there. Any fix should be accompanied with a descriptive warning that can be picked up. This allows it to be used both for compatibility and for validation.

There are also other possible validations that may not be possible to fix, but could be worth warning:

  • Duration on a canvas without duration supporting resources
  • Image resources without height/width
  • Audio/Video without duration
  • Audio/Video with duration that is out of bounds
  • Painting Annotations that target different canvases

@stephenwf stephenwf added this to the 2.0 milestone Jul 26, 2022
stephenwf pushed a commit that referenced this pull request Jul 26, 2022
Previously, when a resource that was already previously normalized is
encountered during traversal, it would overwrite all of the old values.
This led to issues such as #17, where a reference would overwrite the
actual entity.
With this change, such entities are instead *merged* with the previously
encountered entity, so that only values that were previously empty or
not set will be set on the existing entity. In the case of objects and
arrays, both the old and the new values will be combined, with the
values for the existing entity taking precedence over the new values.
@stephenwf
Copy link
Member Author

part of: #19

@stephenwf stephenwf closed this Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant