@rdfx/resource 0.0.19 → 0.0.21
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/MistypedDateValueError.d.ts +12 -0
- package/dist/MistypedDateValueError.js +14 -0
- package/dist/MistypedPrimitiveValueError.d.ts +1 -1
- package/dist/Value.d.ts +5 -1
- package/dist/Value.js +17 -1
- package/dist/vocabularies.d.ts +1 -0
- package/dist/vocabularies.js +1 -0
- package/package.json +4 -4
- package/dist/Primitive.d.ts +0 -2
- package/dist/Primitive.js +0 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MistypedValueError } from "./MistypedValueError.js";
|
|
2
|
+
import { PropertyPath } from "./PropertyPath.js";
|
|
3
|
+
import type { Resource } from "./Resource.js";
|
|
4
|
+
export declare class MistypedDateValueError extends MistypedValueError<Date> {
|
|
5
|
+
constructor({ actualValue, expectedValueType, focusResource, propertyPath, }: {
|
|
6
|
+
actualValue: Date;
|
|
7
|
+
expectedValueType: string;
|
|
8
|
+
focusResource: Resource;
|
|
9
|
+
propertyPath: PropertyPath;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=MistypedDateValueError.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MistypedValueError } from "./MistypedValueError.js";
|
|
2
|
+
import { PropertyPath } from "./PropertyPath.js";
|
|
3
|
+
export class MistypedDateValueError extends MistypedValueError {
|
|
4
|
+
constructor({ actualValue, expectedValueType, focusResource, propertyPath, }) {
|
|
5
|
+
super({
|
|
6
|
+
actualValue,
|
|
7
|
+
expectedValueType,
|
|
8
|
+
focusResource,
|
|
9
|
+
message: `expected ${focusResource.identifier} ${PropertyPath.toString(propertyPath)} to be a ${expectedValueType}, was ${typeof actualValue}`,
|
|
10
|
+
propertyPath,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=MistypedDateValueError.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Primitive } from "@rdfx/literal";
|
|
1
2
|
import { MistypedValueError } from "./MistypedValueError.js";
|
|
2
|
-
import type { Primitive } from "./Primitive.js";
|
|
3
3
|
import { PropertyPath } from "./PropertyPath.js";
|
|
4
4
|
import type { Resource } from "./Resource.js";
|
|
5
5
|
export declare class MistypedPrimitiveValueError extends MistypedValueError<Primitive> {
|
package/dist/Value.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BlankNode, DataFactory, Literal, NamedNode, Quad_Graph, Variable } from "@rdfjs/types";
|
|
2
|
+
import { type Primitive } from "@rdfx/literal";
|
|
2
3
|
import { Either } from "purify-ts";
|
|
3
4
|
import type { Identifier } from "./Identifier.js";
|
|
4
|
-
import type { Primitive } from "./Primitive.js";
|
|
5
5
|
import type { PropertyPath } from "./PropertyPath.js";
|
|
6
6
|
import { Resource } from "./Resource.js";
|
|
7
7
|
import type { Term } from "./Term.js";
|
|
@@ -59,6 +59,10 @@ export declare class Value<TermT extends Term = Term> {
|
|
|
59
59
|
*/
|
|
60
60
|
toIri(): Either<Error, NamedNode>;
|
|
61
61
|
toIri<T extends NamedNode>(in_: readonly T[]): Either<Error, T>;
|
|
62
|
+
/**
|
|
63
|
+
* Try to convert this term to an rdf:langString Literal.
|
|
64
|
+
*/
|
|
65
|
+
toLangString(in_?: readonly Literal[]): Either<Error, Literal>;
|
|
62
66
|
/**
|
|
63
67
|
* Try to convert this term to an RDF list.
|
|
64
68
|
*/
|
package/dist/Value.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { LiteralDecoder } from "@rdfx/literal";
|
|
2
2
|
import { NTriplesTerm } from "@rdfx/string";
|
|
3
3
|
import { Either, Left } from "purify-ts";
|
|
4
|
+
import { MistypedDateValueError } from "./MistypedDateValueError.js";
|
|
4
5
|
import { MistypedPrimitiveValueError } from "./MistypedPrimitiveValueError.js";
|
|
5
6
|
import { MistypedTermValueError } from "./MistypedTermValueError.js";
|
|
6
7
|
import { Resource } from "./Resource.js";
|
|
7
8
|
import { Values } from "./Values.js";
|
|
9
|
+
import { rdf } from "./vocabularies.js";
|
|
8
10
|
export class Value {
|
|
9
11
|
dataFactory;
|
|
10
12
|
focusResource;
|
|
@@ -78,6 +80,20 @@ export class Value {
|
|
|
78
80
|
}
|
|
79
81
|
return this.constrainTerm(this.term, in_);
|
|
80
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Try to convert this term to an rdf:langString Literal.
|
|
85
|
+
*/
|
|
86
|
+
toLangString(in_) {
|
|
87
|
+
return this.toLiteral(in_).chain((literal) => {
|
|
88
|
+
if (!literal.datatype.equals(rdf.langString)) {
|
|
89
|
+
return Left(this.newMistypedTermValueError("rdf:langString"));
|
|
90
|
+
}
|
|
91
|
+
if (literal.language.length === 0) {
|
|
92
|
+
return Left(this.newMistypedTermValueError("rdf:langString"));
|
|
93
|
+
}
|
|
94
|
+
return Either.of(literal);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
81
97
|
/**
|
|
82
98
|
* Try to convert this term to an RDF list.
|
|
83
99
|
*/
|
|
@@ -136,7 +152,7 @@ export class Value {
|
|
|
136
152
|
}
|
|
137
153
|
constrainDate(value, in_) {
|
|
138
154
|
if (in_ && !in_.some((check) => value.getTime() === check.getTime())) {
|
|
139
|
-
return Left(new
|
|
155
|
+
return Left(new MistypedDateValueError({
|
|
140
156
|
actualValue: value,
|
|
141
157
|
expectedValueType: in_.map((_) => _.toISOString()).join(" | "),
|
|
142
158
|
focusResource: this.focusResource,
|
package/dist/vocabularies.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare namespace rdf {
|
|
2
2
|
const first: import("@rdfx/data-factory/dist/NamedNode.js").NamedNode<"http://www.w3.org/1999/02/22-rdf-syntax-ns#first">;
|
|
3
|
+
const langString: import("@rdfx/data-factory/dist/NamedNode.js").NamedNode<"http://www.w3.org/1999/02/22-rdf-syntax-ns#langString">;
|
|
3
4
|
const nil: import("@rdfx/data-factory/dist/NamedNode.js").NamedNode<"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil">;
|
|
4
5
|
const rest: import("@rdfx/data-factory/dist/NamedNode.js").NamedNode<"http://www.w3.org/1999/02/22-rdf-syntax-ns#rest">;
|
|
5
6
|
const type: import("@rdfx/data-factory/dist/NamedNode.js").NamedNode<"http://www.w3.org/1999/02/22-rdf-syntax-ns#type">;
|
package/dist/vocabularies.js
CHANGED
|
@@ -2,6 +2,7 @@ import dataFactory from "@rdfx/data-factory";
|
|
|
2
2
|
export var rdf;
|
|
3
3
|
(function (rdf) {
|
|
4
4
|
rdf.first = dataFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#first");
|
|
5
|
+
rdf.langString = dataFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
|
|
5
6
|
rdf.nil = dataFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
|
|
6
7
|
rdf.rest = dataFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest");
|
|
7
8
|
rdf.type = dataFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@rdfx/literal": "0.0.
|
|
4
|
-
"@rdfx/string": "0.0.
|
|
3
|
+
"@rdfx/literal": "0.0.21",
|
|
4
|
+
"@rdfx/string": "0.0.21",
|
|
5
5
|
"@rdfjs/term-set": "~2.0.3",
|
|
6
6
|
"@rdfjs/types": "~2.0.1",
|
|
7
7
|
"@types/rdfjs__term-set": "~2.0.9",
|
|
8
8
|
"purify-ts": "~2.1.4"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@rdfx/data-factory": "0.0.
|
|
11
|
+
"@rdfx/data-factory": "0.0.21",
|
|
12
12
|
"@rdfjs/dataset": "~2.0.2",
|
|
13
13
|
"@tpluscode/rdf-ns-builders": "~4.3.0",
|
|
14
14
|
"@types/rdfjs__dataset": "~2.0.7",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
},
|
|
41
41
|
"type": "module",
|
|
42
42
|
"types": "./dist/index.d.ts",
|
|
43
|
-
"version": "0.0.
|
|
43
|
+
"version": "0.0.21"
|
|
44
44
|
}
|
package/dist/Primitive.d.ts
DELETED
package/dist/Primitive.js
DELETED