-
Notifications
You must be signed in to change notification settings - Fork 0
Description
[Description]
Identification of ThingModels
Thing Models need to be unambiguously identified for the purpose of referencing them within the context of Thing Model Catalog (TMC) (e.g. search results, fetching from TMC) or outside the TMC (e.g. TDs or other TMs in the field.
This proposal intends to describe how TMC is going to handle identification of TMs.
Note that the w3c TD standard does not provide guidance on this so far (see w3c/wot-thing-description#1905). Hence, whatever solution we implement, it might become incompatible with the standard later.
Context
Each TM within the catalog will include manufacturer's name, manufacturer part number, author's name, and version (together - identifying fields). These data, apart from version, will have to be provided at import (and their presence will be enforced by the importing API).
The version may be included in the TM or it may need to be generated automatically when importing a TM.
Requirements for identification system
- different versions of TMs for the same device need to be unambiguously identifiable so that fetching a TM from TMC can be reliably reproduced
- IDs should be valid relative IRI references
- IDs should be human-readable and include manufacturer, part number, and author
- A TMC may or may not be exposed over HTTP API. The IDs should be usable regardless.
Use cases to be considered
- A user should be able to import a TM definition into TMC from a local file
- The search function should present the user with a list of found TMs including their IDs. The user can directly copy/paste these IDs into a command to fetch the TMs.
- A remote repository can be added at any time to the TMC and the IDs of TMs should never be the same for TMs that have different content. In case there are the same IDs in multiple remotes and the file contents are the same, there's no real conflict between them
[How]
Proposed Identification
Each TM within the catalog is uniquely identified by the combination of identifying fields.
The id field of a TM is composed of these fields as follows:
id: [author_name "/"] manufacturer_name "/" mpn "/" ([ optional_path_part "/" ])* version ".tm.json"
author_name, manufacturer_name, and mpn must be present in the TM at the following paths, respectively: $/schema:author/name, $/schema:manufacturer/name, $/schema:mpn. These fields are defined by https://schema.org/author, https://schema.org/manufacturer, and https://schema.org/mpn. All three fields are sanitized for use as parts of URI path by replacing all consequent whitespace and special characters not allowed in base file names with "-".
When author_name and manufacturer_name are the same, the author_name is omitted from the id.
Optional path parts may be added by the author when importing to TMC.
This id schema can be closely followed by the storage schema. It lets a contributor define her own hierarchy for TMs and any additional files that may be provided along with the TMs.
Handling of the version field
The version field of the id closely follows the format of Golang modules' pseudo-version numbers. It has the following format:
version: base_version "-" timestamp "-" content_hash
- base_version (vX.Y.Z) is a value derived from the value of
$/version/modelfield, if present and can be parsed as semver, or else is set to "v0.0.0". - timestamp (yymmddhhmmss) is the UTC time of when the file was uploaded to TMC.
- content_hash is the 12 character prefix of the sha1 hash of TM file contents. The hash is calculated after first removing the
$/idfield from the file, so that the contents except the id, which contains a timestamp can be compared.
Details on implementing specific use cases
Importing a TM
Importing presents two distinct sub-cases with regard to identifying the TM after it's been imported:
- The TM being imported has no id
Generate an id as described above.
- The TM already has an id.
If the id does not conform to the TM id schema described above, move the original id to a link relation of type "original". Generate an id as per TM id schema. Do the same if the id does conform to this schema, but identifying fields in the id are not equal to those in the TM.
If the id does conform to the TM id schema, generate the new version value.
After the id of the TM being imported has been determined, compare it with existing TMs. For this purpose, versions with the same base version and the same content hash are considered equal, irrespectful of the timestamp value. The TMC CLI/API may abort importing if the TMC already contains the same TM with equivalent contents apart from version timestamp.
Identifying a TM in search results
Search results will print out the name of the remote where the result has been found and the id, including the version.
Fetching a TM
The id with version as returned by the search should be enough to fetch a TM.
A TM can also be fetched by an incomplete ID, where the version field is skipped (referring to the latest version), or the version field contains only the base semantic version (refers to the latest of versions with the same base version part)
Referencing a TM
It is up to the Consumer to refer to a TM by its id as provided in the TM file (i.e. relative IRI), or by resolved absolute IRI.
Privacy Considerations
With regards to Privacy Considerations outlined in WoT TD standard (https://www.w3.org/TR/wot-thing-description11/#sec-privacy-consideration), a Consumer working in a privacy-sensitive
context SHOULD NOT include the link to the TM in generated TDs. In this way, leaking of potentially private information contained in a TM's id will be avoided.
[Documentation]
<--- OPTIONAL: if you feel it is needed, provide a related documentation as described in the README.md of the repository --->
cc => @hadjian @andrisciu