@rdfx/resource 0.0.21 → 0.0.23

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.
@@ -1,13 +1,12 @@
1
- import type { PropertyPath } from "./PropertyPath.js";
1
+ import { PropertyPath } from "./PropertyPath.js";
2
2
  import type { Resource } from "./Resource.js";
3
3
  import { ValueError } from "./ValueError.js";
4
- export declare abstract class MistypedValueError<T> extends ValueError {
4
+ export declare class MistypedValueError<T> extends ValueError {
5
5
  readonly actualValue: T;
6
6
  readonly expectedValueType: string;
7
- constructor({ actualValue, expectedValueType, focusResource, message, propertyPath, }: {
7
+ constructor({ actualValue, expectedValueType, focusResource, propertyPath, }: {
8
8
  actualValue: T;
9
9
  expectedValueType: string;
10
- message: string;
11
10
  focusResource: Resource;
12
11
  propertyPath: PropertyPath;
13
12
  });
@@ -1,11 +1,12 @@
1
+ import { PropertyPath } from "./PropertyPath.js";
1
2
  import { ValueError } from "./ValueError.js";
2
3
  export class MistypedValueError extends ValueError {
3
4
  actualValue;
4
5
  expectedValueType;
5
- constructor({ actualValue, expectedValueType, focusResource, message, propertyPath, }) {
6
+ constructor({ actualValue, expectedValueType, focusResource, propertyPath, }) {
6
7
  super({
7
8
  focusResource,
8
- message,
9
+ message: `expected ${focusResource.identifier} ${PropertyPath.toString(propertyPath)} to be a ${expectedValueType}, was ${actualValue}`,
9
10
  propertyPath,
10
11
  });
11
12
  this.actualValue = actualValue;
@@ -2,7 +2,8 @@ import type { BlankNode, DataFactory, DatasetCore, Literal, NamedNode, Quad_Grap
2
2
  import { Either } from "purify-ts";
3
3
  import type { Identifier as _Identifier, Identifier } from "./Identifier.js";
4
4
  import { ListStructureError as _ListStructureError } from "./ListStructureError.js";
5
- import { MistypedTermValueError as _MistypedTermValueError } from "./MistypedTermValueError.js";
5
+ import { MissingValueError as _MissingValueError } from "./MissingValueError.js";
6
+ import { MistypedValueError as _MistypedValueError } from "./MistypedValueError.js";
6
7
  import type { PropertyPath } from "./PropertyPath.js";
7
8
  import type { Term } from "./Term.js";
8
9
  import { Value as _Value } from "./Value.js";
@@ -94,8 +95,10 @@ export declare namespace Resource {
94
95
  type Identifier = _Identifier;
95
96
  const ListStructureError: typeof _ListStructureError;
96
97
  type ListStructureError = _ListStructureError;
97
- const MistypedTermValueError: typeof _MistypedTermValueError;
98
- type MistypedTermValueError = _MistypedTermValueError;
98
+ const MissingValueError: typeof _MissingValueError;
99
+ type MissingValueError = _MissingValueError;
100
+ const MistypedValueError: typeof _MistypedValueError;
101
+ type MistypedValueError<T> = _MistypedValueError<T>;
99
102
  const ValueError: typeof _ValueError;
100
103
  type ValueError = _ValueError;
101
104
  const Value: typeof _Value;
package/dist/Resource.js CHANGED
@@ -2,7 +2,8 @@ import TermSet from "@rdfjs/term-set";
2
2
  import { Either, Left } from "purify-ts";
3
3
  import { DatasetValues } from "./DatasetValues.js";
4
4
  import { ListStructureError as _ListStructureError } from "./ListStructureError.js";
5
- import { MistypedTermValueError as _MistypedTermValueError } from "./MistypedTermValueError.js";
5
+ import { MissingValueError as _MissingValueError } from "./MissingValueError.js";
6
+ import { MistypedValueError as _MistypedValueError } from "./MistypedValueError.js";
6
7
  import { Value as _Value } from "./Value.js";
7
8
  import { ValueError as _ValueError } from "./ValueError.js";
8
9
  import { Values as _Values } from "./Values.js";
@@ -253,7 +254,7 @@ export class Resource {
253
254
  case "NamedNode":
254
255
  break;
255
256
  default:
256
- return Left(new Resource.MistypedTermValueError({
257
+ return Left(new Resource.MistypedValueError({
257
258
  actualValue: firstObject,
258
259
  expectedValueType: "BlankNode | Literal | NamedNode",
259
260
  focusResource: this,
@@ -283,7 +284,7 @@ export class Resource {
283
284
  case "NamedNode":
284
285
  break;
285
286
  default:
286
- return Left(new Resource.MistypedTermValueError({
287
+ return Left(new Resource.MistypedValueError({
287
288
  actualValue: restObject,
288
289
  expectedValueType: "BlankNode | NamedNode",
289
290
  focusResource: this,
@@ -324,7 +325,8 @@ export class Resource {
324
325
  }
325
326
  (function (Resource) {
326
327
  Resource.ListStructureError = _ListStructureError;
327
- Resource.MistypedTermValueError = _MistypedTermValueError;
328
+ Resource.MissingValueError = _MissingValueError;
329
+ Resource.MistypedValueError = _MistypedValueError;
328
330
  Resource.ValueError = _ValueError;
329
331
  Resource.Value = _Value;
330
332
  Resource.Values = _Values;
package/dist/Value.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { BlankNode, DataFactory, Literal, NamedNode, Quad_Graph, Variable } from "@rdfjs/types";
2
2
  import { type Primitive } from "@rdfx/literal";
3
+ import type { Decimal } from "decimal.js";
3
4
  import { Either } from "purify-ts";
4
5
  import type { Identifier } from "./Identifier.js";
5
6
  import type { PropertyPath } from "./PropertyPath.js";
@@ -17,6 +18,10 @@ export declare class Value<TermT extends Term = Term> {
17
18
  propertyPath: PropertyPath;
18
19
  term: TermT;
19
20
  });
21
+ /**
22
+ * Try to convert this term to a bigint.
23
+ */
24
+ toBigDecimal(in_?: readonly Decimal[]): Either<Error, Decimal>;
20
25
  /**
21
26
  * Try to convert this term to a bigint.
22
27
  */
package/dist/Value.js CHANGED
@@ -1,9 +1,7 @@
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";
5
- import { MistypedPrimitiveValueError } from "./MistypedPrimitiveValueError.js";
6
- import { MistypedTermValueError } from "./MistypedTermValueError.js";
4
+ import { MistypedValueError } from "./MistypedValueError.js";
7
5
  import { Resource } from "./Resource.js";
8
6
  import { Values } from "./Values.js";
9
7
  import { rdf } from "./vocabularies.js";
@@ -18,6 +16,25 @@ export class Value {
18
16
  this.propertyPath = propertyPath;
19
17
  this.term = term;
20
18
  }
19
+ /**
20
+ * Try to convert this term to a bigint.
21
+ */
22
+ toBigDecimal(in_) {
23
+ return this.toLiteral()
24
+ .chain(LiteralDecoder.decodeBigDecimalLiteral)
25
+ .mapLeft(() => this.newMistypedTermValueError(in_ ? in_.map((_) => _.toString()).join(" | ") : "Decimal"))
26
+ .chain((value) => {
27
+ if (in_ && !in_.some((check) => value.equals(check))) {
28
+ return Left(new MistypedValueError({
29
+ actualValue: value,
30
+ expectedValueType: in_.map((_) => _.toString()).join(" | "),
31
+ focusResource: this.focusResource,
32
+ propertyPath: this.propertyPath,
33
+ }));
34
+ }
35
+ return Either.of(value);
36
+ });
37
+ }
21
38
  toBigInt(in_) {
22
39
  return this.toLiteral()
23
40
  .chain(LiteralDecoder.decodeBigIntLiteral)
@@ -152,7 +169,7 @@ export class Value {
152
169
  }
153
170
  constrainDate(value, in_) {
154
171
  if (in_ && !in_.some((check) => value.getTime() === check.getTime())) {
155
- return Left(new MistypedDateValueError({
172
+ return Left(new MistypedValueError({
156
173
  actualValue: value,
157
174
  expectedValueType: in_.map((_) => _.toISOString()).join(" | "),
158
175
  focusResource: this.focusResource,
@@ -163,7 +180,7 @@ export class Value {
163
180
  }
164
181
  constrainPrimitive(value, in_) {
165
182
  if (in_ && !in_.some((check) => value === check)) {
166
- return Left(new MistypedPrimitiveValueError({
183
+ return Left(new MistypedValueError({
167
184
  actualValue: value,
168
185
  expectedValueType: in_.map((_) => _.toString()).join(" | "),
169
186
  focusResource: this.focusResource,
@@ -174,7 +191,7 @@ export class Value {
174
191
  }
175
192
  constrainTerm(value, in_) {
176
193
  if (in_ && !in_.some((check) => value.equals(check))) {
177
- return Left(new MistypedTermValueError({
194
+ return Left(new MistypedValueError({
178
195
  actualValue: value,
179
196
  expectedValueType: in_.map(NTriplesTerm.stringify).join(" | "),
180
197
  focusResource: this.focusResource,
@@ -184,7 +201,7 @@ export class Value {
184
201
  return Either.of(value);
185
202
  }
186
203
  newMistypedTermValueError(expectedValueType) {
187
- return new MistypedTermValueError({
204
+ return new MistypedValueError({
188
205
  actualValue: this.term,
189
206
  expectedValueType,
190
207
  focusResource: this.focusResource,
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "dependencies": {
3
- "@rdfx/literal": "0.0.21",
4
- "@rdfx/string": "0.0.21",
3
+ "@rdfx/literal": "0.0.23",
4
+ "@rdfx/string": "0.0.23",
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
+ "decimal.js": "~10.6.0",
8
9
  "purify-ts": "~2.1.4"
9
10
  },
10
11
  "devDependencies": {
11
- "@rdfx/data-factory": "0.0.21",
12
+ "@rdfx/data-factory": "0.0.23",
12
13
  "@rdfjs/dataset": "~2.0.2",
13
14
  "@tpluscode/rdf-ns-builders": "~4.3.0",
14
15
  "@types/rdfjs__dataset": "~2.0.7",
@@ -40,5 +41,5 @@
40
41
  },
41
42
  "type": "module",
42
43
  "types": "./dist/index.d.ts",
43
- "version": "0.0.21"
44
+ "version": "0.0.23"
44
45
  }
@@ -1,12 +0,0 @@
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
@@ -1,14 +0,0 @@
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,13 +0,0 @@
1
- import type { Primitive } from "@rdfx/literal";
2
- import { MistypedValueError } from "./MistypedValueError.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
@@ -1,14 +0,0 @@
1
- import { MistypedValueError } from "./MistypedValueError.js";
2
- import { PropertyPath } from "./PropertyPath.js";
3
- export class MistypedPrimitiveValueError 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=MistypedPrimitiveValueError.js.map
@@ -1,13 +0,0 @@
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
@@ -1,14 +0,0 @@
1
- import { MistypedValueError } from "./MistypedValueError.js";
2
- import { PropertyPath } from "./PropertyPath.js";
3
- export class MistypedTermValueError 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 ${actualValue.termType}`,
10
- propertyPath,
11
- });
12
- }
13
- }
14
- //# sourceMappingURL=MistypedTermValueError.js.map