@rdfx/resource 0.0.1

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.
Files changed (43) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +42 -0
  3. package/dist/DatasetValues.d.ts +24 -0
  4. package/dist/DatasetValues.js +172 -0
  5. package/dist/Identifier.d.ts +10 -0
  6. package/dist/Identifier.js +26 -0
  7. package/dist/ListStructureError.d.ts +4 -0
  8. package/dist/ListStructureError.js +4 -0
  9. package/dist/LiteralDecoder.d.ts +20 -0
  10. package/dist/LiteralDecoder.js +213 -0
  11. package/dist/LiteralFactory.d.ts +19 -0
  12. package/dist/LiteralFactory.js +183 -0
  13. package/dist/MissingValueError.d.ts +10 -0
  14. package/dist/MissingValueError.js +13 -0
  15. package/dist/MistypedPrimitiveValueError.d.ts +13 -0
  16. package/dist/MistypedPrimitiveValueError.js +15 -0
  17. package/dist/MistypedTermValueError.d.ts +13 -0
  18. package/dist/MistypedTermValueError.js +15 -0
  19. package/dist/MistypedValueError.d.ts +15 -0
  20. package/dist/MistypedValueError.js +13 -0
  21. package/dist/Primitive.d.ts +2 -0
  22. package/dist/Primitive.js +2 -0
  23. package/dist/PropertyPath.d.ts +46 -0
  24. package/dist/PropertyPath.js +179 -0
  25. package/dist/Resource.d.ts +112 -0
  26. package/dist/Resource.js +354 -0
  27. package/dist/ResourceSet.d.ts +24 -0
  28. package/dist/ResourceSet.js +76 -0
  29. package/dist/Term.d.ts +6 -0
  30. package/dist/Term.js +31 -0
  31. package/dist/Value.d.ts +103 -0
  32. package/dist/Value.js +173 -0
  33. package/dist/ValueError.d.ts +12 -0
  34. package/dist/ValueError.js +8 -0
  35. package/dist/Values.d.ts +114 -0
  36. package/dist/Values.js +221 -0
  37. package/dist/index.d.ts +4 -0
  38. package/dist/index.js +4 -0
  39. package/dist/literalDatatypeDefinitions.d.ts +24 -0
  40. package/dist/literalDatatypeDefinitions.js +116 -0
  41. package/dist/vocabularies.d.ts +36 -0
  42. package/dist/vocabularies.js +41 -0
  43. package/package.json +42 -0
@@ -0,0 +1,213 @@
1
+ import { Either, Left } from "purify-ts";
2
+ import { literalDatatypeDefinitions } from "./literalDatatypeDefinitions.js";
3
+ /**
4
+ * Decode other types from RDF/JS Literals.
5
+ *
6
+ * Partially adapted from rdf-literal.js (https://github.com/rubensworks/rdf-literal.js), MIT license.
7
+ */
8
+ export var LiteralDecoder;
9
+ (function (LiteralDecoder) {
10
+ const BIGINT_NUMBER_MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
11
+ const BIGINT_NUMBER_MIN_SAFE_INTEGER = BigInt(Number.MIN_SAFE_INTEGER);
12
+ function convertBigIntToNumber(literal, value) {
13
+ if (value >= BIGINT_NUMBER_MIN_SAFE_INTEGER &&
14
+ value <= BIGINT_NUMBER_MAX_SAFE_INTEGER) {
15
+ return Either.of(Number(value));
16
+ }
17
+ return Left(new LiteralValueError(literal, `bigint ${value} is outside number's safe integer range [${Number.MIN_SAFE_INTEGER}, ${Number.MAX_SAFE_INTEGER}]`));
18
+ }
19
+ function convertNumberToBigInt(literal, value) {
20
+ if (Number.isInteger(value)) {
21
+ return Either.of(BigInt(value));
22
+ }
23
+ return Left(new LiteralValueError(literal, `number ${value} is not an integer`));
24
+ }
25
+ function decodeBigIntLiteral(literal) {
26
+ const literalDatatypeDefinition = literalDatatypeDefinitions[literal.datatype.value];
27
+ if (!literalDatatypeDefinition) {
28
+ return Left(new LiteralDatatypeError(literal));
29
+ }
30
+ switch (literalDatatypeDefinition.kind) {
31
+ case "bigint":
32
+ return decodeBigIntLiteralValue(literal);
33
+ case "float":
34
+ return decodeFloatLiteralValue(literal).chain((value) => convertNumberToBigInt(literal, value));
35
+ case "int":
36
+ return decodeIntLiteralValue(literal).chain((value) => convertNumberToBigInt(literal, value));
37
+ default:
38
+ return Left(new LiteralDatatypeError(literal));
39
+ }
40
+ }
41
+ LiteralDecoder.decodeBigIntLiteral = decodeBigIntLiteral;
42
+ function decodeBigIntLiteralValue(literal) {
43
+ return Either.encase(() => BigInt(literal.value));
44
+ }
45
+ function decodeBooleanLiteral(literal) {
46
+ if (literalDatatypeDefinitions[literal.datatype.value]?.kind === "boolean") {
47
+ return decodeBooleanLiteralValue(literal);
48
+ }
49
+ return Left(new LiteralDatatypeError(literal));
50
+ }
51
+ LiteralDecoder.decodeBooleanLiteral = decodeBooleanLiteral;
52
+ function decodeBooleanLiteralValue(literal) {
53
+ switch (literal.value) {
54
+ case "false":
55
+ case "0":
56
+ return Either.of(false);
57
+ case "true":
58
+ case "1":
59
+ return Either.of(true);
60
+ default:
61
+ return Left(new LiteralValueError(literal));
62
+ }
63
+ }
64
+ function decodeDateLiteral(literal) {
65
+ if (literalDatatypeDefinitions[literal.datatype.value]?.kind === "date") {
66
+ return decodeDateLiteralValue(literal);
67
+ }
68
+ return Left(new LiteralDatatypeError(literal));
69
+ }
70
+ LiteralDecoder.decodeDateLiteral = decodeDateLiteral;
71
+ function decodeDateLiteralValue(literal) {
72
+ if (!literal.value.match(/^[0-9]+-[0-9][0-9]-[0-9][0-9]Z?$/)) {
73
+ return Left(new LiteralValueError(literal));
74
+ }
75
+ return Either.of(new Date(literal.value));
76
+ }
77
+ function decodeDateTimeLiteral(literal) {
78
+ if (literalDatatypeDefinitions[literal.datatype.value]?.kind === "datetime") {
79
+ return decodeDateTimeLiteralValue(literal);
80
+ }
81
+ return Left(new LiteralDatatypeError(literal));
82
+ }
83
+ LiteralDecoder.decodeDateTimeLiteral = decodeDateTimeLiteral;
84
+ function decodeDateTimeLiteralValue(literal) {
85
+ if (!literal.value.match(/^[0-9]+-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9](\.[0-9][0-9][0-9])?((Z?)|([+-][0-9][0-9]:[0-9][0-9]))$/)) {
86
+ return Left(new LiteralValueError(literal));
87
+ }
88
+ return Either.of(new Date(literal.value));
89
+ }
90
+ function decodeFloatLiteral(literal) {
91
+ const literalDatatypeDefinition = literalDatatypeDefinitions[literal.datatype.value];
92
+ if (!literalDatatypeDefinition) {
93
+ return Left(new LiteralDatatypeError(literal));
94
+ }
95
+ switch (literalDatatypeDefinition.kind) {
96
+ case "bigint":
97
+ return decodeBigIntLiteral(literal).chain((value) => convertBigIntToNumber(literal, value));
98
+ case "float":
99
+ case "int":
100
+ return decodeFloatLiteralValue(literal);
101
+ default:
102
+ return Left(new LiteralDatatypeError(literal));
103
+ }
104
+ }
105
+ LiteralDecoder.decodeFloatLiteral = decodeFloatLiteral;
106
+ function decodeFloatLiteralValue(literal) {
107
+ return Either.encase(() => {
108
+ switch (literal.value.toUpperCase()) {
109
+ case "NAN":
110
+ return NaN;
111
+ case "INF":
112
+ case "+INF":
113
+ return Infinity;
114
+ case "-INF":
115
+ return -Infinity;
116
+ }
117
+ const value = Number.parseFloat(literal.value);
118
+ if (Number.isNaN(value)) {
119
+ throw new LiteralValueError(literal, "not a number");
120
+ }
121
+ return value;
122
+ });
123
+ }
124
+ function decodeIntLiteral(literal) {
125
+ const literalDatatypeDefinition = literalDatatypeDefinitions[literal.datatype.value];
126
+ if (!literalDatatypeDefinition) {
127
+ return Left(new LiteralDatatypeError(literal));
128
+ }
129
+ switch (literalDatatypeDefinition.kind) {
130
+ case "bigint":
131
+ return decodeBigIntLiteral(literal).chain((value) => convertBigIntToNumber(literal, value));
132
+ case "float":
133
+ case "int":
134
+ return decodeIntLiteralValue(literal);
135
+ default:
136
+ return Left(new LiteralDatatypeError(literal));
137
+ }
138
+ }
139
+ LiteralDecoder.decodeIntLiteral = decodeIntLiteral;
140
+ function decodeIntLiteralValue(literal) {
141
+ return decodeFloatLiteralValue(literal).chain((value) => {
142
+ if (Number.isInteger(value)) {
143
+ return Either.of(value);
144
+ }
145
+ return Left(new LiteralValueError(literal, `${value} is not an integer`));
146
+ });
147
+ }
148
+ function decodeNumberLiteral(literal) {
149
+ const literalDatatypeDefinition = literalDatatypeDefinitions[literal.datatype.value];
150
+ if (!literalDatatypeDefinition) {
151
+ return Left(new LiteralDatatypeError(literal));
152
+ }
153
+ switch (literalDatatypeDefinition.kind) {
154
+ case "bigint":
155
+ return decodeBigIntLiteralValue(literal).chain((value) => convertBigIntToNumber(literal, value));
156
+ case "float":
157
+ return decodeFloatLiteralValue(literal);
158
+ case "int":
159
+ return decodeIntLiteralValue(literal);
160
+ default:
161
+ return Left(new LiteralDatatypeError(literal));
162
+ }
163
+ }
164
+ LiteralDecoder.decodeNumberLiteral = decodeNumberLiteral;
165
+ function decodePrimitiveLiteral(literal) {
166
+ const literalDatatypeDefinition = literalDatatypeDefinitions[literal.datatype.value];
167
+ if (!literalDatatypeDefinition) {
168
+ return Left(new LiteralDatatypeError(literal));
169
+ }
170
+ switch (literalDatatypeDefinition.kind) {
171
+ case "bigdecimal":
172
+ return Left(new LiteralDatatypeError(literal, "unable to decode bigdecimal Literal"));
173
+ case "bigint":
174
+ return decodeBigIntLiteralValue(literal);
175
+ case "boolean":
176
+ return decodeBooleanLiteralValue(literal);
177
+ case "date":
178
+ return decodeDateLiteralValue(literal);
179
+ case "datetime":
180
+ return decodeDateTimeLiteralValue(literal);
181
+ case "float":
182
+ return decodeFloatLiteralValue(literal);
183
+ case "int":
184
+ return decodeIntLiteralValue(literal);
185
+ case "string":
186
+ return decodeStringLiteralValue(literal);
187
+ }
188
+ }
189
+ LiteralDecoder.decodePrimitiveLiteral = decodePrimitiveLiteral;
190
+ function decodeStringLiteral(literal) {
191
+ if (literalDatatypeDefinitions[literal.datatype.value]?.kind === "string") {
192
+ return decodeStringLiteralValue(literal);
193
+ }
194
+ return Left(new LiteralDatatypeError(literal));
195
+ }
196
+ LiteralDecoder.decodeStringLiteral = decodeStringLiteral;
197
+ function decodeStringLiteralValue(literal) {
198
+ return Either.of(literal.value);
199
+ }
200
+ class LiteralDatatypeError extends Error {
201
+ constructor(literal, message) {
202
+ super(message ?? `unrecognized Literal datatype: ${literal.datatype.value}`);
203
+ this.literal = literal;
204
+ }
205
+ }
206
+ class LiteralValueError extends Error {
207
+ constructor(literal, message) {
208
+ super(message);
209
+ this.literal = literal;
210
+ }
211
+ }
212
+ })(LiteralDecoder || (LiteralDecoder = {}));
213
+ //# sourceMappingURL=LiteralDecoder.js.map
@@ -0,0 +1,19 @@
1
+ import type { DataFactory, Literal, NamedNode } from "@rdfjs/types";
2
+ import type { Primitive } from "./Primitive.js";
3
+ /**
4
+ * Factory with methods for creating RDF/JS Literals from other types.
5
+ */
6
+ export declare class LiteralFactory {
7
+ private readonly dataFactory;
8
+ constructor(options?: {
9
+ dataFactory?: DataFactory;
10
+ });
11
+ bigint(value: bigint, datatype?: NamedNode): Literal;
12
+ boolean(value: boolean, datatype?: NamedNode): Literal;
13
+ date(value: Date, datatype?: NamedNode): Literal;
14
+ number(value: number, datatype?: NamedNode): Literal;
15
+ private numeric;
16
+ primitive(value: Primitive, datatype?: NamedNode): Literal;
17
+ string(value: string, datatype?: NamedNode): Literal;
18
+ }
19
+ //# sourceMappingURL=LiteralFactory.d.ts.map
@@ -0,0 +1,183 @@
1
+ import DefaultDataFactory from "@rdfjs/data-model";
2
+ import { literalDatatypeDefinitions } from "./literalDatatypeDefinitions.js";
3
+ import { xsd } from "./vocabularies.js";
4
+ class DatatypeRangeError extends RangeError {
5
+ constructor(datatype) {
6
+ super(`datatype out of range: ${datatype.value}`);
7
+ this.datatype = datatype;
8
+ }
9
+ }
10
+ /**
11
+ * Factory with methods for creating RDF/JS Literals from other types.
12
+ */
13
+ export class LiteralFactory {
14
+ constructor(options) {
15
+ this.dataFactory = options?.dataFactory ?? DefaultDataFactory;
16
+ }
17
+ bigint(value, datatype) {
18
+ return this.numeric(value, datatype ?? xsd.integer);
19
+ }
20
+ boolean(value, datatype) {
21
+ if (!datatype) {
22
+ datatype = xsd.boolean;
23
+ }
24
+ const datatypeDefinition = literalDatatypeDefinitions[datatype.value];
25
+ if (datatypeDefinition && datatypeDefinition.kind !== "boolean") {
26
+ throw new DatatypeRangeError(datatype);
27
+ }
28
+ return this.dataFactory.literal(value.toString(), datatype);
29
+ }
30
+ date(value, datatype) {
31
+ if (!datatype) {
32
+ datatype = xsd.dateTime;
33
+ }
34
+ const datatypeDefinition = literalDatatypeDefinitions[datatype.value];
35
+ if (datatypeDefinition) {
36
+ switch (datatypeDefinition.kind) {
37
+ case "date":
38
+ return this.dataFactory.literal(value.toISOString().replace(/T.*$/, ""), datatype);
39
+ case "datetime":
40
+ return this.dataFactory.literal(value.toISOString(), datatype);
41
+ default:
42
+ throw new DatatypeRangeError(datatype);
43
+ }
44
+ }
45
+ // case "http://www.w3.org/2001/XMLSchema#gDay":
46
+ // return this.dataFactory.literal(
47
+ // value.getUTCDate().toString(),
48
+ // datatype,
49
+ // );
50
+ // case "http://www.w3.org/2001/XMLSchema#gMonthDay":
51
+ // return this.dataFactory.literal(
52
+ // `${value.getUTCMonth() + 1}-${value.getUTCDate()}`,
53
+ // datatype,
54
+ // );
55
+ // case "http://www.w3.org/2001/XMLSchema#gYear":
56
+ // return this.dataFactory.literal(
57
+ // value.getUTCFullYear().toString(),
58
+ // datatype,
59
+ // );
60
+ // case "http://www.w3.org/2001/XMLSchema#gYearMonth":
61
+ // return this.dataFactory.literal(
62
+ // `${value.getUTCFullYear()}-${value.getUTCMonth() + 1}`,
63
+ // datatype,
64
+ // );
65
+ return this.dataFactory.literal(value.toISOString(), datatype);
66
+ }
67
+ number(value, datatype) {
68
+ if (!datatype) {
69
+ if (Number.isInteger(value)) {
70
+ if (value < 0) {
71
+ datatype = [xsd.byte, xsd.short, xsd.int].find((checkDatatype) => {
72
+ const checkDatatypeDefinition = literalDatatypeDefinitions[checkDatatype.value];
73
+ if (checkDatatypeDefinition?.kind !== "int") {
74
+ throw new Error("should never happen");
75
+ }
76
+ return value >= checkDatatypeDefinition.range[0];
77
+ });
78
+ }
79
+ else {
80
+ datatype = [
81
+ xsd.unsignedByte,
82
+ xsd.unsignedShort,
83
+ xsd.unsignedInt,
84
+ ].find((checkDatatype) => {
85
+ const checkDatatypeDefinition = literalDatatypeDefinitions[checkDatatype.value];
86
+ if (checkDatatypeDefinition?.kind !== "int") {
87
+ throw new Error("should never happen");
88
+ }
89
+ return value <= checkDatatypeDefinition.range[1];
90
+ });
91
+ }
92
+ if (!datatype) {
93
+ datatype = xsd.integer;
94
+ }
95
+ }
96
+ else {
97
+ datatype = xsd.double;
98
+ }
99
+ }
100
+ return this.numeric(value, datatype);
101
+ }
102
+ numeric(value, datatype) {
103
+ let valueString;
104
+ const datatypeDefinition = literalDatatypeDefinitions[datatype.value];
105
+ if (datatypeDefinition) {
106
+ if (Number.isNaN(value) || value === Infinity || value === -Infinity) {
107
+ if (datatypeDefinition.kind !== "float") {
108
+ throw new RangeError(`NaN/INF/-INF values only supported by xsd:double and xsd:float`);
109
+ }
110
+ }
111
+ else {
112
+ switch (datatypeDefinition.kind) {
113
+ case "bigdecimal":
114
+ case "bigint":
115
+ case "float":
116
+ case "int": {
117
+ const [min, max] = datatypeDefinition.range;
118
+ if ((min !== undefined && value < min) ||
119
+ (max !== undefined && value > max)) {
120
+ throw new RangeError(`value (${value}) outside range [${min}, ${max}] of ${datatype.value}`);
121
+ }
122
+ break;
123
+ }
124
+ default:
125
+ throw new DatatypeRangeError(datatype);
126
+ }
127
+ if (datatypeDefinition.kind === "float") {
128
+ // Convert the number to scientific notation so Turtle will recognize it as an double without ^^
129
+ // Example: 1 -> 1e0
130
+ // Assume this coercion to number won't lose anything since we checked the range above.
131
+ let [mantissa, exponent] = Number(value).toExponential().split("e");
132
+ exponent = exponent.replace(/^\+/, "").replace(/^(-?)0+(\d)/, "$1$2");
133
+ valueString = `${mantissa}e${exponent}`;
134
+ }
135
+ }
136
+ }
137
+ if (!valueString) {
138
+ if (typeof value === "number") {
139
+ if (Number.isNaN(value)) {
140
+ valueString = "NaN";
141
+ }
142
+ else if (value === Infinity) {
143
+ valueString = "INF";
144
+ }
145
+ else if (value === -Infinity) {
146
+ valueString = "-INF";
147
+ }
148
+ }
149
+ if (!valueString) {
150
+ valueString = value.toString(10);
151
+ }
152
+ }
153
+ return this.dataFactory.literal(valueString, datatype);
154
+ }
155
+ primitive(value, datatype) {
156
+ switch (typeof value) {
157
+ case "bigint":
158
+ return this.bigint(value, datatype);
159
+ case "boolean":
160
+ return this.boolean(value, datatype);
161
+ case "object": {
162
+ if (value instanceof Date) {
163
+ return this.date(value, datatype);
164
+ }
165
+ throw new Error("not implemented");
166
+ }
167
+ case "number":
168
+ return this.number(value, datatype);
169
+ case "string":
170
+ return this.string(value, datatype);
171
+ }
172
+ }
173
+ string(value, datatype) {
174
+ if (datatype) {
175
+ const datatypeDefinition = literalDatatypeDefinitions[datatype.value];
176
+ if (datatypeDefinition && datatypeDefinition.kind !== "string") {
177
+ throw new DatatypeRangeError(datatype);
178
+ }
179
+ }
180
+ return this.dataFactory.literal(value, datatype);
181
+ }
182
+ }
183
+ //# sourceMappingURL=LiteralFactory.js.map
@@ -0,0 +1,10 @@
1
+ import { PropertyPath } from "./PropertyPath.js";
2
+ import type { Resource } from "./Resource.js";
3
+ import { ValueError } from "./ValueError.js";
4
+ export declare class MissingValueError extends ValueError {
5
+ constructor({ focusResource, propertyPath, }: {
6
+ focusResource: Resource;
7
+ propertyPath: PropertyPath;
8
+ });
9
+ }
10
+ //# sourceMappingURL=MissingValueError.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { Identifier } from "./Identifier.js";
2
+ import { PropertyPath } from "./PropertyPath.js";
3
+ import { ValueError } from "./ValueError.js";
4
+ export class MissingValueError extends ValueError {
5
+ constructor({ focusResource, propertyPath, }) {
6
+ super({
7
+ focusResource,
8
+ message: `${Identifier.toString(focusResource.identifier)} missing ${PropertyPath.toString(propertyPath)}`,
9
+ propertyPath,
10
+ });
11
+ }
12
+ }
13
+ //# sourceMappingURL=MissingValueError.js.map
@@ -0,0 +1,13 @@
1
+ import { MistypedValueError } from "./MistypedValueError.js";
2
+ import type { Primitive } from "./Primitive.js";
3
+ import { PropertyPath } from "./PropertyPath.js";
4
+ import type { Resource } from "./Resource.js";
5
+ export declare class MistypedPrimitiveValueError extends MistypedValueError<Primitive> {
6
+ constructor({ actualValue, expectedValueType, focusResource, propertyPath, }: {
7
+ actualValue: Primitive;
8
+ expectedValueType: string;
9
+ focusResource: Resource;
10
+ propertyPath: PropertyPath;
11
+ });
12
+ }
13
+ //# sourceMappingURL=MistypedPrimitiveValueError.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { Identifier } from "./Identifier.js";
2
+ import { MistypedValueError } from "./MistypedValueError.js";
3
+ import { PropertyPath } from "./PropertyPath.js";
4
+ export class MistypedPrimitiveValueError extends MistypedValueError {
5
+ constructor({ actualValue, expectedValueType, focusResource, propertyPath, }) {
6
+ super({
7
+ actualValue,
8
+ expectedValueType,
9
+ focusResource,
10
+ message: `expected ${Identifier.toString(focusResource.identifier)} ${PropertyPath.toString(propertyPath)} to be a ${expectedValueType}, was ${typeof actualValue}`,
11
+ propertyPath,
12
+ });
13
+ }
14
+ }
15
+ //# sourceMappingURL=MistypedPrimitiveValueError.js.map
@@ -0,0 +1,13 @@
1
+ import type { BlankNode, Literal, NamedNode, Quad, Variable } from "@rdfjs/types";
2
+ import { MistypedValueError } from "./MistypedValueError.js";
3
+ import { PropertyPath } from "./PropertyPath.js";
4
+ import type { Resource } from "./Resource.js";
5
+ export declare class MistypedTermValueError extends MistypedValueError<BlankNode | Literal | NamedNode | Quad | Variable> {
6
+ constructor({ actualValue, expectedValueType, focusResource, propertyPath, }: {
7
+ actualValue: BlankNode | Literal | NamedNode | Quad | Variable;
8
+ expectedValueType: string;
9
+ focusResource: Resource;
10
+ propertyPath: PropertyPath;
11
+ });
12
+ }
13
+ //# sourceMappingURL=MistypedTermValueError.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { Identifier } from "./Identifier.js";
2
+ import { MistypedValueError } from "./MistypedValueError.js";
3
+ import { PropertyPath } from "./PropertyPath.js";
4
+ export class MistypedTermValueError extends MistypedValueError {
5
+ constructor({ actualValue, expectedValueType, focusResource, propertyPath, }) {
6
+ super({
7
+ actualValue,
8
+ expectedValueType,
9
+ focusResource,
10
+ message: `expected ${Identifier.toString(focusResource.identifier)} ${PropertyPath.toString(propertyPath)} to be a ${expectedValueType}, was ${actualValue.termType}`,
11
+ propertyPath,
12
+ });
13
+ }
14
+ }
15
+ //# sourceMappingURL=MistypedTermValueError.js.map
@@ -0,0 +1,15 @@
1
+ import type { PropertyPath } from "./PropertyPath.js";
2
+ import type { Resource } from "./Resource.js";
3
+ import { ValueError } from "./ValueError.js";
4
+ export declare abstract class MistypedValueError<T> extends ValueError {
5
+ readonly actualValue: T;
6
+ readonly expectedValueType: string;
7
+ constructor({ actualValue, expectedValueType, focusResource, message, propertyPath, }: {
8
+ actualValue: T;
9
+ expectedValueType: string;
10
+ message: string;
11
+ focusResource: Resource;
12
+ propertyPath: PropertyPath;
13
+ });
14
+ }
15
+ //# sourceMappingURL=MistypedValueError.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { ValueError } from "./ValueError.js";
2
+ export class MistypedValueError extends ValueError {
3
+ constructor({ actualValue, expectedValueType, focusResource, message, propertyPath, }) {
4
+ super({
5
+ focusResource,
6
+ message,
7
+ propertyPath,
8
+ });
9
+ this.actualValue = actualValue;
10
+ this.expectedValueType = expectedValueType;
11
+ }
12
+ }
13
+ //# sourceMappingURL=MistypedValueError.js.map
@@ -0,0 +1,2 @@
1
+ export type Primitive = bigint | boolean | Date | number | string;
2
+ //# sourceMappingURL=Primitive.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Primitive.js.map
@@ -0,0 +1,46 @@
1
+ import type { NamedNode, Quad_Graph, Variable } from "@rdfjs/types";
2
+ import { Either } from "purify-ts";
3
+ import { Resource } from "./Resource.js";
4
+ import { ResourceSet } from "./ResourceSet.js";
5
+ interface AlternativePath {
6
+ readonly termType: "AlternativePath";
7
+ readonly members: readonly PropertyPath[];
8
+ }
9
+ interface InversePath {
10
+ readonly termType: "InversePath";
11
+ readonly path: PropertyPath;
12
+ }
13
+ interface OneOrMorePath {
14
+ readonly termType: "OneOrMorePath";
15
+ readonly path: PropertyPath;
16
+ }
17
+ type PredicatePath = NamedNode;
18
+ interface SequencePath {
19
+ readonly termType: "SequencePath";
20
+ readonly members: readonly PropertyPath[];
21
+ }
22
+ interface ZeroOrMorePath {
23
+ readonly termType: "ZeroOrMorePath";
24
+ readonly path: PropertyPath;
25
+ }
26
+ interface ZeroOrOnePath {
27
+ readonly termType: "ZeroOrOnePath";
28
+ readonly path: PropertyPath;
29
+ }
30
+ /**
31
+ * A SHACL property path.
32
+ */
33
+ export type PropertyPath = AlternativePath | InversePath | OneOrMorePath | PredicatePath | SequencePath | ZeroOrMorePath | ZeroOrOnePath;
34
+ export declare namespace PropertyPath {
35
+ function equals(left: PropertyPath, right: PropertyPath): boolean;
36
+ function fromResource(resource: Resource, options?: {
37
+ graph?: Exclude<Quad_Graph, Variable>;
38
+ }): Either<Error, PropertyPath>;
39
+ function toResource(propertyPath: PropertyPath, options?: {
40
+ graph?: Exclude<Quad_Graph, Variable>;
41
+ resourceSet?: ResourceSet;
42
+ }): Resource;
43
+ function toString(propertyPath: PropertyPath): string;
44
+ }
45
+ export {};
46
+ //# sourceMappingURL=PropertyPath.d.ts.map