This can be recorded as a VoID property and is necessary for converting
I·R·I’s back into their identifiers.
* generating the value of `TagSystem::Tag`. It isn’t possible to
* access this function in its unbound form from outside this module.
*
* generating the value of `TagSystem::Tag`. It isn’t possible to
* access this function in its unbound form from outside this module.
*
+ * ☡ This function throws if the I·R·I is not in the `.iriSpace` of
+ * the `TagSystem` associated with this constructor.
+ *
* ※ If the I·R·I is not recognized, this function returns `null`.
*/
static fromIRI(system, storage, iri) {
const name = `${iri}`;
* ※ If the I·R·I is not recognized, this function returns `null`.
*/
static fromIRI(system, storage, iri) {
const name = `${iri}`;
- const prefix =
- `https://${system.authorityName}/tag:${system.taggingEntity}:`;
+ const prefix = `${system.iriSpace}`;
if (!name.startsWith(prefix)) {
// The I·R·I does not begin with the expected prefix.
if (!name.startsWith(prefix)) {
// The I·R·I does not begin with the expected prefix.
+ throw new RangeError(
+ `I·R·I did not begin with the expected prefix: ${iri}`,
+ );
} else {
// The I·R·I begins with the expected prefix.
const identifier = name.substring(prefix.length);
} else {
// The I·R·I begins with the expected prefix.
const identifier = name.substring(prefix.length);
if (!tagName.startsWith(tagPrefix)) {
// The Tag U·R·I does not begin with the expected prefix.
throw new RangeError(
if (!tagName.startsWith(tagPrefix)) {
// The Tag U·R·I does not begin with the expected prefix.
throw new RangeError(
- `Tag U·R·I did not begin with the expected prefix: ${tagName}`,
+ `Tag U·R·I did not begin with the expected prefix: ${tagURI}`,
);
} else {
// The I·R·I begins with the expected prefix.
);
} else {
// The I·R·I begins with the expected prefix.
/** Returns the I·R·I for this `Tag`. */
get iri() {
/** Returns the I·R·I for this `Tag`. */
get iri() {
- const tagURI = this.tagURI;
- return tagURI == null
- ? null
- : `https://${this.authorityName}/${tagURI}`;
+ const { identifier, iriSpace } = this;
+ return identifier == null ? null : `${iriSpace}${identifier}`;
+ }
+
+ /** Returns the I·R·I space for this `Tag`. */
+ get iriSpace() {
+ return this.#system.iriSpace;
}
/** Returns the kind of this `Tag`. */
}
/** Returns the kind of this `Tag`. */
/** Returns the I·R·I for this `TagSystem`. */
get iri() {
/** Returns the I·R·I for this `TagSystem`. */
get iri() {
- return `https://${this.authorityName}/${this.tagURI}`;
+ return `${this.iriSpace}${this.identifier}`;
+ }
+
+ /**
+ * Returns the prefix used for I·R·I’s of `Tag`s in this `TagSystem`.
+ */
+ get iriSpace() {
+ return `https://${this.authorityName}/tag:${this.taggingEntity}:`;
}
/** Returns the Tag U·R·I for this `TagSystem`. */
}
/** Returns the Tag U·R·I for this `TagSystem`. */
- it("[[Call]] returns null if passed an invalid I·R·I", () => {
- assertStrictEquals(Tag.fromIRI(`bad iri`), null);
+ it("[[Call]] throws if passed an invalid I·R·I", () => {
+ assertThrows(() => {Tag.fromIRI(`bad iri`)});
it("[[Call]] returns null if no tag with the given Tag U·R·I has been persisted", () => {
assertStrictEquals(
it("[[Call]] returns null if no tag with the given Tag U·R·I has been persisted", () => {
assertStrictEquals(
- Tag.fromIRI(`tag:${system.taggingEntity}:`),
+ Tag.fromTagURI(`tag:${system.taggingEntity}:`),
null,
);
assertStrictEquals(
null,
);
assertStrictEquals(
- Tag.fromIRI(`tag:${system.taggingEntity}:000-0000`),
+ Tag.fromTagURI(`tag:${system.taggingEntity}:000-0000`),
// `::iri` is tested by a `.fromIRI`.
// `::iri` is tested by a `.fromIRI`.
+ // `::iriSpace` is tested by a `.fromIRI`.
+
// `::kind` is tested by the constructor.
describe("::narrowerTags", () => {
// `::kind` is tested by the constructor.
describe("::narrowerTags", () => {
+ describe("::iriSpace", () => {
+ it("[[Get]] returns the I·R·I space", () => {
+ const system = new TagSystem("etaoin.example", "1972-12-31");
+ assertStrictEquals(
+ system.iriSpace,
+ "https://etaoin.example/tag:etaoin.example,1972-12-31:",
+ );
+ const system2 = new TagSystem(
+ "etaoin.example",
+ "1972-12-31",
+ "etaoin",
+ );
+ assertStrictEquals(
+ system2.iriSpace,
+ "https://etaoin.example/tag:etaoin.example,1972-12-31:",
+ );
+ });
+ });
+
describe("::tagURI", () => {
it("[[Get]] returns the Tag U·R·I", () => {
const system = new TagSystem("etaoin.example", "1972-12-31");
describe("::tagURI", () => {
it("[[Get]] returns the Tag U·R·I", () => {
const system = new TagSystem("etaoin.example", "1972-12-31");