@shaclmate/compiler 4.0.101 → 4.0.103

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.
@@ -39,11 +39,14 @@ export class BigDecimalType extends AbstractTypedLiteralType {
39
39
  filterFunction = new BuiltinCallable(this.reusables.snippets.filterBigDecimal);
40
40
  filterType = code `${this.reusables.snippets.NumericFilter}<${this.reusables.imports.BigDecimal}>`;
41
41
  fromJsonObjectFunction = new BuiltinCallable(this.reusables.snippets.bigDecimalFromJsonObject);
42
- fromJsonValueFunction = new BuiltinCallable(this.reusables.snippets.bigDecimalFromJsonString);
42
+ fromJsonValueFunction = new BuiltinCallable(this.reusables.snippets.bigDecimalFromJsonValue);
43
43
  fromRdfResourceValuesFunction = new BuiltinCallable(this.reusables.snippets.bigDecimalFromRdfResourceValues);
44
44
  graphqlType = new AbstractTypedLiteralType.GraphqlType(code `${this.reusables.imports.GraphQLString}`, this.reusables);
45
45
  hashFunction = new BuiltinCallable(this.reusables.snippets.hashBigDecimal);
46
- jsonValueType = this.jsonTypeFactory.createJsonStringType();
46
+ jsonValueType = this.jsonTypeFactory.createJsonUnionType([
47
+ this.jsonTypeFactory.createJsonNumberType(),
48
+ this.jsonTypeFactory.createJsonStringType(),
49
+ ]);
47
50
  kind = "BigDecimal";
48
51
  toJsonObjectFunction = new BuiltinCallable(code `${this.reusables.snippets.bigDecimalToJsonObject}(${this.rdfjsTermExpression(this.datatype)})`);
49
52
  toJsonValueFunction = new BuiltinCallable(this.reusables.snippets.bigDecimalToJsonString);
@@ -33,15 +33,20 @@ export class BigIntType extends AbstractNumericType {
33
33
  ],
34
34
  });
35
35
  graphqlType = new AbstractNumericType.GraphqlType(code `${this.reusables.imports.GraphQLBigInt}`, this.reusables);
36
- jsonValueType = this.jsonTypeFactory.createJsonStringType({
37
- in_: this.decodedIn.map((in_) => in_.toString()),
38
- });
36
+ jsonValueType = this.jsonTypeFactory.createJsonUnionType([
37
+ this.jsonTypeFactory.createJsonNumberType({
38
+ in_: this.decodedIn.map((in_) => Number(in_)),
39
+ }),
40
+ this.jsonTypeFactory.createJsonStringType({
41
+ in_: this.decodedIn.map((in_) => in_.toString()),
42
+ }),
43
+ ]);
39
44
  kind = "BigInt";
40
45
  get fromJsonObjectFunction() {
41
46
  return new BuiltinCallable(code `${this.reusables.snippets.bigIntFromJsonObject}<${this.expression}>`);
42
47
  }
43
48
  get fromJsonValueFunction() {
44
- return new BuiltinCallable(code `${this.reusables.snippets.bigIntFromJsonString}<${this.jsonValueType.expression}, ${this.expression}>`);
49
+ return new BuiltinCallable(code `${this.reusables.snippets.bigIntFromJsonValue}<${this.jsonValueType.expression}, ${this.expression}>`);
45
50
  }
46
51
  get fromRdfResourceValuesFunction() {
47
52
  return new BuiltinCallable(code `${this.reusables.snippets.bigIntFromRdfResourceValues}<${this.expression}>`);
@@ -88,14 +88,14 @@ export declare class Snippets {
88
88
  get arrayIntersection(): Snippet;
89
89
  get arrayToJsonArray(): Snippet;
90
90
  get bigDecimalFromJsonObject(): Snippet;
91
- get bigDecimalFromJsonString(): Snippet;
91
+ get bigDecimalFromJsonValue(): Snippet;
92
92
  get bigDecimalFromRdfResourceValues(): Snippet;
93
93
  get bigDecimalLiteral(): Snippet;
94
94
  get bigDecimalSparqlWherePatterns(): Snippet;
95
95
  get bigDecimalToJsonObject(): Snippet;
96
96
  get bigDecimalToJsonString(): Snippet;
97
97
  get bigIntFromJsonObject(): Snippet;
98
- get bigIntFromJsonString(): Snippet;
98
+ get bigIntFromJsonValue(): Snippet;
99
99
  get bigIntFromRdfResourceValues(): Snippet;
100
100
  get bigIntToJsonObject(): Snippet;
101
101
  get bigIntToJsonString(): Snippet;
@@ -82,14 +82,14 @@ import { snippets_arrayFromJsonArray } from "./_snippets/snippets_arrayFromJsonA
82
82
  import { snippets_arrayIntersection } from "./_snippets/snippets_arrayIntersection.js";
83
83
  import { snippets_arrayToJsonArray } from "./_snippets/snippets_arrayToJsonArray.js";
84
84
  import { snippets_bigDecimalFromJsonObject } from "./_snippets/snippets_bigDecimalFromJsonObject.js";
85
- import { snippets_bigDecimalFromJsonString } from "./_snippets/snippets_bigDecimalFromJsonString.js";
85
+ import { snippets_bigDecimalFromJsonValue } from "./_snippets/snippets_bigDecimalFromJsonValue.js";
86
86
  import { snippets_bigDecimalFromRdfResourceValues } from "./_snippets/snippets_bigDecimalFromRdfResourceValues.js";
87
87
  import { snippets_bigDecimalLiteral } from "./_snippets/snippets_bigDecimalLiteral.js";
88
88
  import { snippets_bigDecimalSparqlWherePatterns } from "./_snippets/snippets_bigDecimalSparqlWherePatterns.js";
89
89
  import { snippets_bigDecimalToJsonObject } from "./_snippets/snippets_bigDecimalToJsonObject.js";
90
90
  import { snippets_bigDecimalToJsonString } from "./_snippets/snippets_bigDecimalToJsonString.js";
91
91
  import { snippets_bigIntFromJsonObject } from "./_snippets/snippets_bigIntFromJsonObject.js";
92
- import { snippets_bigIntFromJsonString } from "./_snippets/snippets_bigIntFromJsonString.js";
92
+ import { snippets_bigIntFromJsonValue } from "./_snippets/snippets_bigIntFromJsonValue.js";
93
93
  import { snippets_bigIntFromRdfResourceValues } from "./_snippets/snippets_bigIntFromRdfResourceValues.js";
94
94
  import { snippets_bigIntToJsonObject } from "./_snippets/snippets_bigIntToJsonObject.js";
95
95
  import { snippets_bigIntToJsonString } from "./_snippets/snippets_bigIntToJsonString.js";
@@ -488,8 +488,8 @@ export class Snippets {
488
488
  get bigDecimalFromJsonObject() {
489
489
  return this.snippet(snippets_bigDecimalFromJsonObject);
490
490
  }
491
- get bigDecimalFromJsonString() {
492
- return this.snippet(snippets_bigDecimalFromJsonString);
491
+ get bigDecimalFromJsonValue() {
492
+ return this.snippet(snippets_bigDecimalFromJsonValue);
493
493
  }
494
494
  get bigDecimalFromRdfResourceValues() {
495
495
  return this.snippet(snippets_bigDecimalFromRdfResourceValues);
@@ -509,8 +509,8 @@ export class Snippets {
509
509
  get bigIntFromJsonObject() {
510
510
  return this.snippet(snippets_bigIntFromJsonObject);
511
511
  }
512
- get bigIntFromJsonString() {
513
- return this.snippet(snippets_bigIntFromJsonString);
512
+ get bigIntFromJsonValue() {
513
+ return this.snippet(snippets_bigIntFromJsonValue);
514
514
  }
515
515
  get bigIntFromRdfResourceValues() {
516
516
  return this.snippet(snippets_bigIntFromRdfResourceValues);
@@ -1297,7 +1297,7 @@ __decorate([
1297
1297
  ], Snippets.prototype, "bigDecimalFromJsonObject", null);
1298
1298
  __decorate([
1299
1299
  Memoize()
1300
- ], Snippets.prototype, "bigDecimalFromJsonString", null);
1300
+ ], Snippets.prototype, "bigDecimalFromJsonValue", null);
1301
1301
  __decorate([
1302
1302
  Memoize()
1303
1303
  ], Snippets.prototype, "bigDecimalFromRdfResourceValues", null);
@@ -1318,7 +1318,7 @@ __decorate([
1318
1318
  ], Snippets.prototype, "bigIntFromJsonObject", null);
1319
1319
  __decorate([
1320
1320
  Memoize()
1321
- ], Snippets.prototype, "bigIntFromJsonString", null);
1321
+ ], Snippets.prototype, "bigIntFromJsonValue", null);
1322
1322
  __decorate([
1323
1323
  Memoize()
1324
1324
  ], Snippets.prototype, "bigIntFromRdfResourceValues", null);
@@ -94,14 +94,14 @@ declare class JsonObjectType extends AbstractJsonType {
94
94
  } & ConstructorParameters<typeof AbstractJsonType>[0]);
95
95
  protected get inlineExpression(): Code;
96
96
  protected get schemaExpression(): Code;
97
- protected schemaTypeExpression({ unqualifiedName, }: {
98
- unqualifiedName: string;
99
- }): Code;
100
97
  private get uiSchemaFunctionExpression();
101
98
  uiSchemaElement({ variables, }: Parameters<AbstractJsonType["uiSchemaElement"]>[0]): Maybe<Code>;
102
99
  protected moduleDeclarations(parameters: {
103
100
  unqualifiedName: string;
104
101
  }): Code[];
102
+ protected schemaTypeExpression({ unqualifiedName, }: {
103
+ unqualifiedName: string;
104
+ }): Code;
105
105
  private memberType;
106
106
  }
107
107
  declare class JsonStringType extends AbstractJsonPrimitiveType<string> {
@@ -163,8 +163,23 @@ declare class JsonTypeFactory {
163
163
  name?: AbstractJsonType.Name;
164
164
  snippet?: Snippet;
165
165
  }): JsonStringType;
166
+ createJsonUnionType(memberTypes: readonly JsonType[], options?: {
167
+ name?: AbstractJsonType.Name;
168
+ recursive?: boolean;
169
+ snippet?: Snippet;
170
+ }): JsonUnionType;
171
+ }
172
+ declare class JsonUnionType extends AbstractJsonType {
173
+ readonly kind = "JsonUnion";
174
+ readonly memberTypes: readonly JsonType[];
175
+ constructor({ memberTypes, ...superParameters }: {
176
+ memberTypes: readonly JsonType[];
177
+ recursive: boolean;
178
+ } & ConstructorParameters<typeof AbstractJsonType>[0]);
179
+ protected get inlineExpression(): Code;
180
+ protected get schemaExpression(): Code;
166
181
  }
167
- type JsonType = JsonArrayType | JsonBooleanType | JsonDiscriminatedUnionType | JsonIntersectionType | JsonNumberType | JsonObjectType | JsonStringType;
182
+ type JsonType = JsonArrayType | JsonBooleanType | JsonDiscriminatedUnionType | JsonIntersectionType | JsonNumberType | JsonObjectType | JsonStringType | JsonUnionType;
168
183
  export type AbstractType_JsonType = JsonType;
169
184
  export type AbstractType_JsonTypeFactory = JsonTypeFactory;
170
185
  declare namespace JsonDiscriminatedUnionType {
@@ -252,11 +252,6 @@ class JsonObjectType extends AbstractJsonType {
252
252
  })
253
253
  .orDefault(objectSchema);
254
254
  }
255
- schemaTypeExpression({ unqualifiedName, }) {
256
- return this.shorthand
257
- .map((shorthand) => code `${this.reusables.imports.z}.ZodType<${unqualifiedName}, ${unqualifiedName} | ${shorthand.type.expression}>`)
258
- .orDefault(super.schemaTypeExpression({ unqualifiedName }));
259
- }
260
255
  get uiSchemaFunctionExpression() {
261
256
  const variables = { scopePrefix: code `(_options?.scopePrefix ?? "#")` };
262
257
  const uiSchema = {
@@ -283,6 +278,11 @@ class JsonObjectType extends AbstractJsonType {
283
278
  }
284
279
  return moduleDeclarations;
285
280
  }
281
+ schemaTypeExpression({ unqualifiedName, }) {
282
+ return this.shorthand
283
+ .map((shorthand) => code `${this.reusables.imports.z}.ZodType<${unqualifiedName}, ${unqualifiedName} | ${shorthand.type.expression}>`)
284
+ .orDefault(super.schemaTypeExpression({ unqualifiedName }));
285
+ }
286
286
  memberType(memberI) {
287
287
  if (this.cachedMemberTypes[memberI] === null) {
288
288
  this.cachedMemberTypes[memberI] =
@@ -436,6 +436,35 @@ class JsonTypeFactory {
436
436
  snippet: Maybe.fromNullable(options?.snippet),
437
437
  });
438
438
  }
439
+ createJsonUnionType(memberTypes, options) {
440
+ return new JsonUnionType({
441
+ ...this.constructorParameters,
442
+ memberTypes,
443
+ name: Maybe.fromNullable(options?.name),
444
+ recursive: !!options?.recursive,
445
+ snippet: Maybe.fromNullable(options?.snippet),
446
+ });
447
+ }
439
448
  }
449
+ class JsonUnionType extends AbstractJsonType {
450
+ kind = "JsonUnion";
451
+ memberTypes;
452
+ constructor({ memberTypes, ...superParameters }) {
453
+ super(superParameters);
454
+ this.memberTypes = memberTypes;
455
+ }
456
+ get inlineExpression() {
457
+ return code `(${joinCode(this.memberTypes.map((memberType) => memberType.expression), { on: " | " })})`;
458
+ }
459
+ get schemaExpression() {
460
+ return joinCode(this.memberTypes.map((memberType, memberI) => memberI === 0 ? memberType.schema : code `.or(${memberType.schema})`));
461
+ }
462
+ }
463
+ __decorate([
464
+ Memoize()
465
+ ], JsonUnionType.prototype, "inlineExpression", null);
466
+ __decorate([
467
+ Memoize()
468
+ ], JsonUnionType.prototype, "schemaExpression", null);
440
469
  export const AbstractType_JsonTypeFactory = JsonTypeFactory;
441
470
  //# sourceMappingURL=AbstractType_JsonType.js.map
@@ -0,0 +1,3 @@
1
+ import type { SnippetFactory } from "../SnippetFactory.js";
2
+ export declare const snippets_bigDecimalFromJsonValue: SnippetFactory;
3
+ //# sourceMappingURL=snippets_bigDecimalFromJsonValue.d.ts.map
@@ -0,0 +1,5 @@
1
+ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
2
+ export const snippets_bigDecimalFromJsonValue = ({ imports, snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}bigDecimalFromJsonValue`, code `\
3
+ const ${syntheticNamePrefix}bigDecimalFromJsonValue: ${snippets.FromJsonFunction}<number | string, ${imports.BigDecimal}, ${snippets.NumericSchema}<${imports.BigDecimal}>> =
4
+ (jsonValue) => ${imports.Either}.encase(() => new ${imports.BigDecimal}(jsonValue));`);
5
+ //# sourceMappingURL=snippets_bigDecimalFromJsonValue.js.map
@@ -0,0 +1,3 @@
1
+ import type { SnippetFactory } from "../SnippetFactory.js";
2
+ export declare const snippets_bigIntFromJsonValue: SnippetFactory;
3
+ //# sourceMappingURL=snippets_bigIntFromJsonValue.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
2
+ export const snippets_bigIntFromJsonValue = ({ imports, snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}bigIntFromJsonString`, code `\
3
+ function ${syntheticNamePrefix}bigIntFromJsonString<JsonValueT extends number | string, BigIntT extends bigint>(jsonValue: JsonValueT, options: Parameters<${snippets.FromJsonFunction}<string, BigIntT, ${snippets.NumericSchema}<BigIntT>>>[1]): ${imports.Either}<Error, BigIntT> {
4
+ const { schema } = options;
5
+ return ${imports.Either}.encase(() => BigInt(jsonValue) as BigIntT)
6
+ .chain(value => ${snippets.constrainPrimitive}<BigIntT, bigint>(value, schema.in)) as ${imports.Either}<Error, BigIntT>;
7
+ }`);
8
+ //# sourceMappingURL=snippets_bigIntFromJsonValue.js.map
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "4.0.101",
3
+ "@shaclmate/shacl-ast": "4.0.103",
4
4
  "@rdfjs/types": "~2.0.1",
5
- "@rdfx/collection": "0.0.62",
6
- "@rdfx/curie": "0.0.62",
7
- "@rdfx/data-factory": "0.0.62",
8
- "@rdfx/literal": "0.0.62",
9
- "@rdfx/logger": "0.0.62",
10
- "@rdfx/resource": "0.0.62",
11
- "@rdfx/string": "0.0.62",
5
+ "@rdfx/collection": "0.0.63",
6
+ "@rdfx/curie": "0.0.63",
7
+ "@rdfx/data-factory": "0.0.63",
8
+ "@rdfx/literal": "0.0.63",
9
+ "@rdfx/logger": "0.0.63",
10
+ "@rdfx/resource": "0.0.63",
11
+ "@rdfx/string": "0.0.63",
12
12
  "@sindresorhus/base62": "~0.1.0",
13
13
  "@tpluscode/rdf-ns-builders": "~4.3.0",
14
14
  "change-case": "~5.4.4",
@@ -22,7 +22,7 @@
22
22
  "uri-template": "~2.0.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@rdfx/fs": "0.0.62",
25
+ "@rdfx/fs": "0.0.63",
26
26
  "typescript": "6.0.3"
27
27
  },
28
28
  "files": [
@@ -586,8 +586,8 @@
586
586
  "dist/generators/ts/_snippets/snippets_arrayToJsonArray.js",
587
587
  "dist/generators/ts/_snippets/snippets_bigDecimalFromJsonObject.d.ts",
588
588
  "dist/generators/ts/_snippets/snippets_bigDecimalFromJsonObject.js",
589
- "dist/generators/ts/_snippets/snippets_bigDecimalFromJsonString.d.ts",
590
- "dist/generators/ts/_snippets/snippets_bigDecimalFromJsonString.js",
589
+ "dist/generators/ts/_snippets/snippets_bigDecimalFromJsonValue.d.ts",
590
+ "dist/generators/ts/_snippets/snippets_bigDecimalFromJsonValue.js",
591
591
  "dist/generators/ts/_snippets/snippets_bigDecimalFromRdfResourceValues.d.ts",
592
592
  "dist/generators/ts/_snippets/snippets_bigDecimalFromRdfResourceValues.js",
593
593
  "dist/generators/ts/_snippets/snippets_bigDecimalLiteral.d.ts",
@@ -600,8 +600,8 @@
600
600
  "dist/generators/ts/_snippets/snippets_bigDecimalToJsonString.js",
601
601
  "dist/generators/ts/_snippets/snippets_bigIntFromJsonObject.d.ts",
602
602
  "dist/generators/ts/_snippets/snippets_bigIntFromJsonObject.js",
603
- "dist/generators/ts/_snippets/snippets_bigIntFromJsonString.d.ts",
604
- "dist/generators/ts/_snippets/snippets_bigIntFromJsonString.js",
603
+ "dist/generators/ts/_snippets/snippets_bigIntFromJsonValue.d.ts",
604
+ "dist/generators/ts/_snippets/snippets_bigIntFromJsonValue.js",
605
605
  "dist/generators/ts/_snippets/snippets_bigIntFromRdfResourceValues.d.ts",
606
606
  "dist/generators/ts/_snippets/snippets_bigIntFromRdfResourceValues.js",
607
607
  "dist/generators/ts/_snippets/snippets_bigIntToJsonObject.d.ts",
@@ -976,5 +976,5 @@
976
976
  },
977
977
  "type": "module",
978
978
  "types": "./dist/index.d.ts",
979
- "version": "4.0.101"
979
+ "version": "4.0.103"
980
980
  }
@@ -1,3 +0,0 @@
1
- import type { SnippetFactory } from "../SnippetFactory.js";
2
- export declare const snippets_bigDecimalFromJsonString: SnippetFactory;
3
- //# sourceMappingURL=snippets_bigDecimalFromJsonString.d.ts.map
@@ -1,5 +0,0 @@
1
- import { code, conditionalOutput } from "../ts-poet-wrapper.js";
2
- export const snippets_bigDecimalFromJsonString = ({ imports, snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}bigDecimalFromJsonString`, code `\
3
- const ${syntheticNamePrefix}bigDecimalFromJsonString: ${snippets.FromJsonFunction}<string, ${imports.BigDecimal}, ${snippets.NumericSchema}<${imports.BigDecimal}>> =
4
- (jsonValue) => ${imports.Either}.encase(() => new ${imports.BigDecimal}(jsonValue));`);
5
- //# sourceMappingURL=snippets_bigDecimalFromJsonString.js.map
@@ -1,3 +0,0 @@
1
- import type { SnippetFactory } from "../SnippetFactory.js";
2
- export declare const snippets_bigIntFromJsonString: SnippetFactory;
3
- //# sourceMappingURL=snippets_bigIntFromJsonString.d.ts.map
@@ -1,8 +0,0 @@
1
- import { code, conditionalOutput } from "../ts-poet-wrapper.js";
2
- export const snippets_bigIntFromJsonString = ({ imports, snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}bigIntFromJsonString`, code `\
3
- function ${syntheticNamePrefix}bigIntFromJsonString<JsonValueT extends string, BigIntT extends bigint>(jsonValue: JsonValueT, options: Parameters<${snippets.FromJsonFunction}<string, BigIntT, ${snippets.NumericSchema}<BigIntT>>>[1]): ${imports.Either}<Error, BigIntT> {
4
- const { schema } = options;
5
- return ${imports.Either}.encase(() => BigInt(jsonValue) as BigIntT)
6
- .chain(value => ${snippets.constrainPrimitive}<BigIntT, bigint>(value, schema.in)) as ${imports.Either}<Error, BigIntT>;
7
- }`);
8
- //# sourceMappingURL=snippets_bigIntFromJsonString.js.map