@shaclmate/compiler 4.0.5 → 4.0.7

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 (79) hide show
  1. package/dist/generators/ts/AbstractLazyObjectType.js +2 -2
  2. package/dist/generators/ts/AbstractType.d.ts +6 -6
  3. package/dist/generators/ts/LazyObjectOptionType.js +1 -1
  4. package/dist/generators/ts/LazyObjectSetType.js +1 -1
  5. package/dist/generators/ts/LazyObjectType.js +1 -1
  6. package/dist/generators/ts/ObjectType.js +19 -6
  7. package/dist/generators/ts/ObjectUnionType.js +23 -11
  8. package/dist/generators/ts/ZodGenerator.d.ts +7 -0
  9. package/dist/generators/ts/ZodGenerator.js +37 -0
  10. package/dist/generators/ts/_ObjectType/IdentifierProperty.js +1 -0
  11. package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclarations.d.ts +4 -0
  12. package/dist/generators/ts/_ObjectType/{ObjectType_jsonFunctionDeclarations.js → ObjectType_fromJsonFunctionDeclarations.js} +8 -64
  13. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfFunctionDeclaration.d.ts +5 -0
  14. package/dist/generators/ts/_ObjectType/ObjectType_fromRdfFunctionDeclaration.js +27 -0
  15. package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.d.ts +5 -0
  16. package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js +14 -0
  17. package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.d.ts +5 -0
  18. package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js +18 -0
  19. package/dist/generators/ts/_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.d.ts +5 -0
  20. package/dist/generators/ts/_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.js +30 -0
  21. package/dist/generators/ts/_ObjectType/ObjectType_propertiesFromRdfFunctionDeclaration.d.ts +5 -0
  22. package/dist/generators/ts/_ObjectType/{ObjectType_rdfFunctionDeclarations.js → ObjectType_propertiesFromRdfFunctionDeclaration.js} +5 -37
  23. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.d.ts +5 -1
  24. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js +35 -5
  25. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts +4 -1
  26. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.js +7 -3
  27. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  28. package/dist/generators/ts/_ObjectType/ObjectType_sparqlConstructTriplesFunctionDeclaration.js +57 -0
  29. package/dist/generators/ts/_ObjectType/ObjectType_sparqlWherePatternsFunctionDeclarations.d.ts +5 -0
  30. package/dist/generators/ts/_ObjectType/ObjectType_sparqlWherePatternsFunctionDeclarations.js +106 -0
  31. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromJsonFunctionDeclaration.d.ts +5 -0
  32. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromJsonFunctionDeclaration.js +19 -0
  33. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromRdfFunctionDeclarations.d.ts +5 -0
  34. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_fromRdfFunctionDeclarations.js +20 -0
  35. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.d.ts +5 -0
  36. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.js +14 -0
  37. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
  38. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.js +15 -0
  39. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlWherePatternsFunctionDeclaration.d.ts +5 -0
  40. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlWherePatternsFunctionDeclaration.js +35 -0
  41. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toJsonFunctionDeclaration.d.ts +5 -0
  42. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toJsonFunctionDeclaration.js +26 -0
  43. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_toRdfFunctionDeclarations.d.ts +5 -0
  44. package/dist/generators/ts/_ObjectUnionType/{ObjectUnionType_rdfFunctionDeclarations.js → ObjectUnionType_toRdfFunctionDeclarations.js} +6 -23
  45. package/dist/generators/ts/_snippets/snippets_LazyObject.js +4 -4
  46. package/dist/generators/ts/_snippets/snippets_LazyObjectOption.js +4 -4
  47. package/dist/generators/ts/_snippets/snippets_LazyObjectSet.js +4 -4
  48. package/dist/generators/ts/_snippets/snippets_SparqlConstructTriplesFunctionParameters.js +2 -2
  49. package/dist/generators/ts/_snippets/snippets_SparqlWherePatternsFunctionParameters.js +3 -3
  50. package/dist/generators/ts/_snippets/snippets_booleanSparqlWherePatterns.js +1 -1
  51. package/dist/generators/ts/_snippets/snippets_dateSparqlWherePatterns.js +1 -1
  52. package/dist/generators/ts/_snippets/snippets_defaultValueSparqlWherePatterns.js +1 -1
  53. package/dist/generators/ts/_snippets/snippets_iriSparqlWherePatterns.js +1 -1
  54. package/dist/generators/ts/_snippets/snippets_listSparqlConstructTriples.js +5 -5
  55. package/dist/generators/ts/_snippets/snippets_listSparqlWherePatterns.js +2 -0
  56. package/dist/generators/ts/_snippets/snippets_maybeSparqlConstructTriples.js +1 -1
  57. package/dist/generators/ts/_snippets/snippets_maybeSparqlWherePatterns.js +3 -3
  58. package/dist/generators/ts/_snippets/snippets_numericSparqlWherePatterns.js +1 -1
  59. package/dist/generators/ts/_snippets/snippets_setSparqlConstructTriples.js +1 -1
  60. package/dist/generators/ts/_snippets/snippets_setSparqlWherePatterns.js +1 -1
  61. package/dist/generators/ts/_snippets/snippets_shaclPropertySparqlConstructTriples.js +2 -2
  62. package/dist/generators/ts/_snippets/snippets_shaclPropertySparqlWherePatterns.js +3 -3
  63. package/dist/generators/ts/_snippets/snippets_stringSparqlWherePatterns.js +1 -1
  64. package/dist/generators/ts/objectSetInterfaceDeclaration.js +1 -0
  65. package/dist/generators/ts/objectSetMethodSignatures.js +1 -1
  66. package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +13 -8
  67. package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +6 -6
  68. package/dist/index.d.ts +1 -0
  69. package/dist/index.js +1 -0
  70. package/package.json +2 -2
  71. package/dist/generators/ts/_ObjectType/ObjectType_jsonFunctionDeclarations.d.ts +0 -4
  72. package/dist/generators/ts/_ObjectType/ObjectType_rdfFunctionDeclarations.d.ts +0 -4
  73. package/dist/generators/ts/_ObjectType/ObjectType_sparqlFunctionDeclarations.d.ts +0 -4
  74. package/dist/generators/ts/_ObjectType/ObjectType_sparqlFunctionDeclarations.js +0 -143
  75. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonFunctionDeclarations.d.ts +0 -4
  76. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_jsonFunctionDeclarations.js +0 -50
  77. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_rdfFunctionDeclarations.d.ts +0 -4
  78. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlFunctionDeclarations.d.ts +0 -4
  79. package/dist/generators/ts/_ObjectUnionType/ObjectUnionType_sparqlFunctionDeclarations.js +0 -45
@@ -59,10 +59,10 @@ export class AbstractLazyObjectType extends AbstractType {
59
59
  }}`;
60
60
  }
61
61
  get sparqlConstructTriplesFunction() {
62
- return code `(({ schema, ...otherParameters }) => ${this.partialType.sparqlConstructTriplesFunction}({ schema: schema.partial(), ...otherParameters }))`;
62
+ return code `(({ schema, ...otherParameters }) => ${this.partialType.sparqlConstructTriplesFunction}({ ...otherParameters, schema: schema.partial() }))`;
63
63
  }
64
64
  get sparqlWherePatternsFunction() {
65
- return code `(({ schema, ...otherParameters }) => ${this.partialType.sparqlWherePatternsFunction}({ schema: schema.partial(), ...otherParameters }))`;
65
+ return code `(({ schema, ...otherParameters }) => ${this.partialType.sparqlWherePatternsFunction}({ ...otherParameters, schema: schema.partial() }))`;
66
66
  }
67
67
  get schemaObject() {
68
68
  return {
@@ -69,23 +69,23 @@ export declare abstract class AbstractType {
69
69
  * A SparqlConstructTriplesFunction (reference or declaration) that returns an array of sparqljs.Triple's for a property of this type.
70
70
  *
71
71
  * The function takes a parameters object (type: SparqlConstructTriplesFunctionParameters) with the following parameters:
72
- * - filter?: an instance of filterType
73
- * - ignoreRdfType?: boolean
72
+ * - filter: an instance of filterType | undefined
73
+ * - ignoreRdfType: boolean
74
74
  * - schema: instance of this.schemaType
75
75
  * - valueVariable: rdfjs.Variable of the value of this type
76
- * - variablePrefix: prefix to use for new variables
76
+ * - variablePrefix: string prefix to use for new variables
77
77
  */
78
78
  abstract readonly sparqlConstructTriplesFunction: Code;
79
79
  /**
80
80
  * A SparqlWherePatternsFunction (reference or declaration) that returns an array of SparqlPattern's for a property of this type.
81
81
  *
82
82
  * The function takes a parameters object (type: SparqlWherePatternsFunctionParameters) with the following parameters:
83
- * - filter?: an instance of filterType
84
- * - preferredLanguages: array of preferred language code (strings); may be empty
83
+ * - filter: an instance of filterType | undefined
84
+ * - preferredLanguages: array of preferred language code (strings) | undefined
85
85
  * - propertyPatterns: array of sparqljs.Pattern's for the property; may be empty
86
86
  * - schema: instance of this.schemaType
87
87
  * - valueVariable: rdfjs.Variable of the value of this type
88
- * - variablePrefix: prefix to use for new variables
88
+ * - variablePrefix: string prefix to use for new variables
89
89
  */
90
90
  abstract readonly sparqlWherePatternsFunction: Code;
91
91
  /**
@@ -75,7 +75,7 @@ export class LazyObjectOptionType extends Super {
75
75
  }
76
76
  fromRdfExpression(parameters) {
77
77
  const { variables } = parameters;
78
- return code `${this.partialType.fromRdfExpression(parameters)}.map(values => values.map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: (identifier) => ${variables.objectSet}.${this.resolveType.itemType.objectSetMethodNames.object}(identifier) })))`;
78
+ return code `${this.partialType.fromRdfExpression(parameters)}.map(values => values.map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: (identifier, options) => ${variables.objectSet}.${this.resolveType.itemType.objectSetMethodNames.object}(identifier, options) })))`;
79
79
  }
80
80
  graphqlResolveExpression({ variables, }) {
81
81
  return code `${variables.value}.resolve().then(either => either.unsafeCoerce().extractNullable())`;
@@ -66,7 +66,7 @@ export class LazyObjectSetType extends AbstractLazyObjectType {
66
66
  }
67
67
  fromRdfExpression(parameters) {
68
68
  const { variables } = parameters;
69
- return code `${this.partialType.fromRdfExpression(parameters)}.map(values => values.map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: (identifiers) => ${variables.objectSet}.${this.resolveType.itemType.objectSetMethodNames.objects}({ identifiers }) })))`;
69
+ return code `${this.partialType.fromRdfExpression(parameters)}.map(values => values.map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: (identifiers, options) => ${variables.objectSet}.${this.resolveType.itemType.objectSetMethodNames.objects}({ identifiers, ...options }) })))`;
70
70
  }
71
71
  graphqlResolveExpression({ variables, }) {
72
72
  return code `(${variables.value}.resolve({ limit: ${variables.args}.limit, offset: ${variables.args}.offset })).then(either => either.unsafeCoerce())`;
@@ -50,7 +50,7 @@ export class LazyObjectType extends AbstractLazyObjectType {
50
50
  }
51
51
  fromRdfExpression(parameters) {
52
52
  const { variables } = parameters;
53
- return code `${this.partialType.fromRdfExpression(parameters)}.map(values => values.map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: (identifier) => ${variables.objectSet}.${this.resolveType.objectSetMethodNames.object}(identifier) })))`;
53
+ return code `${this.partialType.fromRdfExpression(parameters)}.map(values => values.map(${this.runtimeClass.partialPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.partialPropertyName}, resolver: (identifier, options) => ${variables.objectSet}.${this.resolveType.objectSetMethodNames.object}(identifier, options) })))`;
54
54
  }
55
55
  graphqlResolveExpression({ variables, }) {
56
56
  return code `${variables.value}.resolve().then(either => either.unsafeCoerce())`;
@@ -16,17 +16,26 @@ import { ObjectType_createFunctionDeclaration } from "./_ObjectType/ObjectType_c
16
16
  import { ObjectType_equalsFunctionOrMethodDeclaration } from "./_ObjectType/ObjectType_equalsFunctionOrMethodDeclaration.js";
17
17
  import { ObjectType_filterFunctionDeclaration } from "./_ObjectType/ObjectType_filterFunctionDeclaration.js";
18
18
  import { ObjectType_filterTypeDeclaration } from "./_ObjectType/ObjectType_filterTypeDeclaration.js";
19
+ import { ObjectType_fromJsonFunctionDeclarations } from "./_ObjectType/ObjectType_fromJsonFunctionDeclarations.js";
20
+ import { ObjectType_fromRdfFunctionDeclaration } from "./_ObjectType/ObjectType_fromRdfFunctionDeclaration.js";
19
21
  import { ObjectType_fromRdfTypeVariableStatement } from "./_ObjectType/ObjectType_fromRdfTypeVariableStatement.js";
20
22
  import { ObjectType_graphqlTypeVariableStatement } from "./_ObjectType/ObjectType_graphqlTypeVariableStatement.js";
21
23
  import { ObjectType_hashFunctionOrMethodDeclarations } from "./_ObjectType/ObjectType_hashFunctionOrMethodDeclarations.js";
22
24
  import { ObjectType_interfaceDeclaration } from "./_ObjectType/ObjectType_interfaceDeclaration.js";
23
25
  import { ObjectType_isTypeFunctionDeclaration } from "./_ObjectType/ObjectType_isTypeFunctionDeclaration.js";
24
- import { ObjectType_jsonFunctionDeclarations } from "./_ObjectType/ObjectType_jsonFunctionDeclarations.js";
26
+ import { ObjectType_jsonSchemaFunctionDeclaration } from "./_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js";
25
27
  import { ObjectType_jsonTypeAliasDeclaration } from "./_ObjectType/ObjectType_jsonTypeAliasDeclaration.js";
28
+ import { ObjectType_jsonUiSchemaFunctionDeclaration } from "./_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js";
29
+ import { ObjectType_jsonZodSchemaFunctionDeclaration } from "./_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.js";
26
30
  import { ObjectType_objectSetMethodNames } from "./_ObjectType/ObjectType_objectSetMethodNames.js";
27
- import { ObjectType_rdfFunctionDeclarations } from "./_ObjectType/ObjectType_rdfFunctionDeclarations.js";
31
+ import { ObjectType_propertiesFromRdfFunctionDeclaration } from "./_ObjectType/ObjectType_propertiesFromRdfFunctionDeclaration.js";
28
32
  import { ObjectType_schemaVariableStatement } from "./_ObjectType/ObjectType_schemaVariableStatement.js";
29
- import { ObjectType_sparqlFunctionDeclarations } from "./_ObjectType/ObjectType_sparqlFunctionDeclarations.js";
33
+ import { ObjectType_sparqlConstructQueryFunctionDeclaration } from "./_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js";
34
+ import { ObjectType_sparqlConstructQueryStringFunctionDeclaration } from "./_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.js";
35
+ import { ObjectType_sparqlConstructTriplesFunctionDeclaration } from "./_ObjectType/ObjectType_sparqlConstructTriplesFunctionDeclaration.js";
36
+ import { ObjectType_sparqlWherePatternsFunctionDeclaration } from "./_ObjectType/ObjectType_sparqlWherePatternsFunctionDeclarations.js";
37
+ import { ObjectType_toJsonFunctionOrMethodDeclaration } from "./_ObjectType/ObjectType_toJsonFunctionOrMethodDeclaration.js";
38
+ import { ObjectType_toRdfFunctionOrMethodDeclaration } from "./_ObjectType/ObjectType_toRdfFunctionOrMethodDeclaration.js";
30
39
  import { ShaclProperty as _ShaclProperty } from "./_ObjectType/ShaclProperty.js";
31
40
  import { TypeDiscriminantProperty as _TypeDiscriminantProperty } from "./_ObjectType/TypeDiscriminantProperty.js";
32
41
  import { AbstractDeclaredType } from "./AbstractDeclaredType.js";
@@ -108,7 +117,11 @@ export class ObjectType extends AbstractDeclaredType {
108
117
  break;
109
118
  }
110
119
  }
111
- staticModuleDeclarations.push(ObjectType_filterFunctionDeclaration.bind(this)(), ObjectType_filterTypeDeclaration.bind(this)(), ...ObjectType_fromRdfTypeVariableStatement.bind(this)().toList(), ...ObjectType_graphqlTypeVariableStatement.bind(this)().toList(), ...identifierTypeDeclarations.bind(this)(), ...ObjectType_jsonFunctionDeclarations.bind(this)(), ...ObjectType_jsonTypeAliasDeclaration.bind(this)().toList(), ObjectType_isTypeFunctionDeclaration.bind(this)(), ...ObjectType_rdfFunctionDeclarations.bind(this)(), ObjectType_schemaVariableStatement.bind(this)(), ...ObjectType_sparqlFunctionDeclarations.bind(this)());
120
+ staticModuleDeclarations.push(...ObjectType_graphqlTypeVariableStatement.bind(this)().toList(), ...identifierTypeDeclarations.bind(this)(), ...ObjectType_jsonTypeAliasDeclaration.bind(this)().toList(), ObjectType_filterFunctionDeclaration.bind(this)(), ObjectType_filterTypeDeclaration.bind(this)(), ...ObjectType_fromJsonFunctionDeclarations.bind(this)(), ...ObjectType_fromRdfFunctionDeclaration.bind(this)().toList(), ...ObjectType_fromRdfTypeVariableStatement.bind(this)().toList(), ObjectType_isTypeFunctionDeclaration.bind(this)(), ...ObjectType_jsonSchemaFunctionDeclaration.bind(this)().toList(), ...ObjectType_jsonUiSchemaFunctionDeclaration.bind(this)().toList(), ...ObjectType_jsonZodSchemaFunctionDeclaration.bind(this)().toList(), ...ObjectType_propertiesFromRdfFunctionDeclaration.bind(this)().toList(), ObjectType_schemaVariableStatement.bind(this)(), ...ObjectType_sparqlConstructQueryFunctionDeclaration.bind(this)().toList(), ...ObjectType_sparqlConstructQueryStringFunctionDeclaration.bind(this)().toList(), ...ObjectType_sparqlConstructTriplesFunctionDeclaration.bind(this)().toList(), ...ObjectType_sparqlWherePatternsFunctionDeclaration.bind(this)().toList(), ...(this.declarationType === "interface"
121
+ ? ObjectType_toJsonFunctionOrMethodDeclaration.bind(this)().toList()
122
+ : []), ...(this.declarationType === "interface"
123
+ ? ObjectType_toRdfFunctionOrMethodDeclaration.bind(this)().toList()
124
+ : []));
112
125
  if (staticModuleDeclarations.length > 0) {
113
126
  declarations.push(code `\
114
127
  export namespace ${def(this.staticModuleName)} {
@@ -201,10 +214,10 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
201
214
  return code `typeof ${this.schema}`;
202
215
  }
203
216
  get sparqlConstructTriplesFunction() {
204
- return code `(({ filter, ignoreRdfType, valueVariable, variablePrefix }: ${snippets.SparqlConstructTriplesFunctionParameters}<${this.filterType}, ${this.schemaType}>) => ${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTriples({ filter, focusIdentifier: valueVariable, ignoreRdfType: ignoreRdfType ?? true, variablePrefix }))`;
217
+ return code `(({ filter, ignoreRdfType, valueVariable, variablePrefix }: ${snippets.SparqlConstructTriplesFunctionParameters}<${this.filterType}, ${this.schemaType}>) => ${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTriples({ filter, focusIdentifier: valueVariable, ignoreRdfType, variablePrefix }))`;
205
218
  }
206
219
  get sparqlWherePatternsFunction() {
207
- return code `(({ filter, ignoreRdfType, propertyPatterns, valueVariable, variablePrefix }: ${snippets.SparqlWherePatternsFunctionParameters}<${this.filterType}, ${this.schemaType}>) => (propertyPatterns as readonly ${snippets.SparqlPattern}[]).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ filter, focusIdentifier: valueVariable, ignoreRdfType: ignoreRdfType ?? true, variablePrefix })))`;
220
+ return code `(({ filter, ignoreRdfType, preferredLanguages, propertyPatterns, valueVariable, variablePrefix }: ${snippets.SparqlWherePatternsFunctionParameters}<${this.filterType}, ${this.schemaType}>) => (propertyPatterns as readonly ${snippets.SparqlPattern}[]).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ filter, focusIdentifier: valueVariable, ignoreRdfType, preferredLanguages, variablePrefix })))`;
208
221
  }
209
222
  get toRdfjsResourceType() {
210
223
  if (this.parentObjectTypes.length > 0) {
@@ -9,19 +9,25 @@ import { Maybe, NonEmptyList } from "purify-ts";
9
9
  import { invariant } from "ts-invariant";
10
10
  import { Memoize } from "typescript-memoize";
11
11
  import { ObjectType_objectSetMethodNames } from "./_ObjectType/ObjectType_objectSetMethodNames.js";
12
+ import { ObjectType_sparqlConstructQueryFunctionDeclaration } from "./_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js";
13
+ import { ObjectType_sparqlConstructQueryStringFunctionDeclaration } from "./_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.js";
12
14
  import { MemberType } from "./_ObjectUnionType/MemberType.js";
13
15
  import { ObjectUnionType_equalsFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_equalsFunctionDeclaration.js";
14
16
  import { ObjectUnionType_filterFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_filterFunctionDeclaration.js";
15
17
  import { ObjectUnionType_filterTypeDeclaration } from "./_ObjectUnionType/ObjectUnionType_filterTypeDeclaration.js";
18
+ import { ObjectUnionType_fromJsonFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_fromJsonFunctionDeclaration.js";
19
+ import { ObjectUnionType_fromRdfFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_fromRdfFunctionDeclarations.js";
16
20
  import { ObjectUnionType_graphqlTypeVariableStatement } from "./_ObjectUnionType/ObjectUnionType_graphqlTypeVariableStatement.js";
17
21
  import { ObjectUnionType_hashFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_hashFunctionDeclaration.js";
18
22
  import { ObjectUnionType_identifierTypeDeclarations } from "./_ObjectUnionType/ObjectUnionType_identifierTypeDeclarations.js";
19
23
  import { ObjectUnionType_isTypeFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_isTypeFunctionDeclaration.js";
20
- import { jsonFunctionDeclarations } from "./_ObjectUnionType/ObjectUnionType_jsonFunctionDeclarations.js";
21
24
  import { ObjectUnionType_jsonTypeAliasDeclaration } from "./_ObjectUnionType/ObjectUnionType_jsonTypeAliasDeclaration.js";
22
- import { rdfFunctionDeclarations } from "./_ObjectUnionType/ObjectUnionType_rdfFunctionDeclarations.js";
25
+ import { ObjectUnionType_jsonZodSchemaFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.js";
23
26
  import { ObjectUnionType_schemaVariableStatement } from "./_ObjectUnionType/ObjectUnionType_schemaVariableStatement.js";
24
- import { ObjectUnionType_sparqlFunctionDeclarations } from "./_ObjectUnionType/ObjectUnionType_sparqlFunctionDeclarations.js";
27
+ import { ObjectUnionType_sparqlConstructTriplesFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.js";
28
+ import { ObjectUnionType_sparqlWherePatternsFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_sparqlWherePatternsFunctionDeclaration.js";
29
+ import { ObjectUnionType_toJsonFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_toJsonFunctionDeclaration.js";
30
+ import { ObjectUnionType_toRdfFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_toRdfFunctionDeclarations.js";
25
31
  import { ObjectUnionType_typeAliasDeclaration } from "./_ObjectUnionType/ObjectUnionType_typeAliasDeclaration.js";
26
32
  import { AbstractDeclaredType } from "./AbstractDeclaredType.js";
27
33
  import { imports } from "./imports.js";
@@ -68,18 +74,24 @@ export class ObjectUnionType extends AbstractDeclaredType {
68
74
  ObjectUnionType_typeAliasDeclaration.bind(this)(),
69
75
  ];
70
76
  const staticModuleDeclarations = [
77
+ ...ObjectUnionType_graphqlTypeVariableStatement.bind(this)().toList(),
78
+ ...ObjectUnionType_identifierTypeDeclarations.bind(this)(),
79
+ ...ObjectUnionType_jsonTypeAliasDeclaration.bind(this)().toList(),
71
80
  ...ObjectUnionType_equalsFunctionDeclaration.bind(this)().toList(),
72
81
  ObjectUnionType_filterFunctionDeclaration.bind(this)(),
73
82
  ObjectUnionType_filterTypeDeclaration.bind(this)(),
74
- ...ObjectUnionType_graphqlTypeVariableStatement.bind(this)().toList(),
75
83
  ...ObjectUnionType_hashFunctionDeclaration.bind(this)().toList(),
76
- ...ObjectUnionType_identifierTypeDeclarations.bind(this)(),
77
- ...jsonFunctionDeclarations.bind(this)(),
78
- ...ObjectUnionType_jsonTypeAliasDeclaration.bind(this)().toList(),
84
+ ...ObjectUnionType_fromJsonFunctionDeclaration.bind(this)().toList(),
85
+ ...ObjectUnionType_fromRdfFunctionDeclaration.bind(this)().toList(),
79
86
  ...ObjectUnionType_isTypeFunctionDeclaration.bind(this)().toList(),
87
+ ...ObjectUnionType_jsonZodSchemaFunctionDeclaration.bind(this)().toList(),
80
88
  ObjectUnionType_schemaVariableStatement.bind(this)(),
81
- ...rdfFunctionDeclarations.bind(this)(),
82
- ...ObjectUnionType_sparqlFunctionDeclarations.bind(this)(),
89
+ ...ObjectType_sparqlConstructQueryFunctionDeclaration.bind(this)().toList(),
90
+ ...ObjectType_sparqlConstructQueryStringFunctionDeclaration.bind(this)().toList(),
91
+ ...ObjectUnionType_sparqlConstructTriplesFunctionDeclaration.bind(this)().toList(),
92
+ ...ObjectUnionType_sparqlWherePatternsFunctionDeclaration.bind(this)().toList(),
93
+ ...ObjectUnionType_toJsonFunctionDeclaration.bind(this)().toList(),
94
+ ...ObjectUnionType_toRdfFunctionDeclaration.bind(this)().toList(),
83
95
  ];
84
96
  if (staticModuleDeclarations.length > 0) {
85
97
  declarations.push(code `\
@@ -120,10 +132,10 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
120
132
  return code `typeof ${this.schema}`;
121
133
  }
122
134
  get sparqlConstructTriplesFunction() {
123
- return code `(({ ignoreRdfType, schema, ...otherParameters }: ${snippets.SparqlConstructTriplesFunctionParameters}<${this.filterType}, ${this.schemaType}>) => ${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTriples(otherParameters))`;
135
+ return code `(({ ignoreRdfType, schema, valueVariable, ...otherParameters }: ${snippets.SparqlConstructTriplesFunctionParameters}<${this.filterType}, ${this.schemaType}>) => ${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTriples({ ...otherParameters, focusIdentifier: valueVariable, ignoreRdfType: false }))`;
124
136
  }
125
137
  get sparqlWherePatternsFunction() {
126
- return code `(({ ignoreRdfType, propertyPatterns, schema, valueVariable, ...otherParameters }: ${snippets.SparqlWherePatternsFunctionParameters}<${this.filterType}, ${this.schemaType}>) => (propertyPatterns as readonly ${snippets.SparqlPattern}[]).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ focusIdentifier: valueVariable, ...otherParameters })))`;
138
+ return code `(({ ignoreRdfType, propertyPatterns, schema, valueVariable, ...otherParameters }: ${snippets.SparqlWherePatternsFunctionParameters}<${this.filterType}, ${this.schemaType}>) => (propertyPatterns as readonly ${snippets.SparqlPattern}[]).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ ...otherParameters, focusIdentifier: valueVariable, ignoreRdfType: false })))`;
127
139
  }
128
140
  get staticModuleName() {
129
141
  return this.name;
@@ -0,0 +1,7 @@
1
+ import * as ast from "../../ast/index.js";
2
+ import type { Generator } from "../Generator.js";
3
+ export declare class ZodGenerator implements Generator {
4
+ private readonly typeFactory;
5
+ generate(ast_: ast.Ast): string;
6
+ }
7
+ //# sourceMappingURL=ZodGenerator.d.ts.map
@@ -0,0 +1,37 @@
1
+ import * as ast from "../../ast/index.js";
2
+ import { ObjectType_jsonTypeAliasDeclaration } from "./_ObjectType/ObjectType_jsonTypeAliasDeclaration.js";
3
+ import { ObjectType_jsonZodSchemaFunctionDeclaration } from "./_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.js";
4
+ import { ObjectUnionType_jsonTypeAliasDeclaration } from "./_ObjectUnionType/ObjectUnionType_jsonTypeAliasDeclaration.js";
5
+ import { ObjectUnionType_jsonZodSchemaFunctionDeclaration } from "./_ObjectUnionType/ObjectUnionType_jsonZodSchemaFunctionDeclaration.js";
6
+ import { snippets } from "./snippets.js";
7
+ import { TypeFactory } from "./TypeFactory.js";
8
+ import { code, joinCode } from "./ts-poet-wrapper.js";
9
+ export class ZodGenerator {
10
+ typeFactory = new TypeFactory();
11
+ generate(ast_) {
12
+ const declarations = [];
13
+ for (const objectType of ast.ObjectType.toposort(ast_.objectTypes).map((astObjectType) => this.typeFactory.createObjectType(astObjectType))) {
14
+ declarations.push(code `\
15
+ export namespace ${objectType.staticModuleName} {
16
+ ${joinCode([
17
+ ...ObjectType_jsonTypeAliasDeclaration.bind(objectType)().toList(),
18
+ ...ObjectType_jsonZodSchemaFunctionDeclaration.bind(objectType)().toList(),
19
+ ], { on: "\n\n" })}
20
+ }`);
21
+ }
22
+ for (const objectUnionType of ast_.objectUnionTypes.map((astObjectUnionType) => this.typeFactory.createObjectUnionType(astObjectUnionType))) {
23
+ declarations.push(code `\
24
+ export namespace ${objectUnionType.staticModuleName} {
25
+ ${joinCode([
26
+ ...ObjectUnionType_jsonTypeAliasDeclaration.bind(objectUnionType)().toList(),
27
+ ...ObjectUnionType_jsonZodSchemaFunctionDeclaration.bind(objectUnionType)().toList(),
28
+ ], { on: "\n\n" })}
29
+ }`);
30
+ }
31
+ declarations.splice(0, 0, joinCode(Object.values(snippets)
32
+ .sort((left, right) => left.usageSiteName.localeCompare(right.usageSiteName))
33
+ .map((snippet) => code `${snippet.ifUsed}`), { on: "\n\n" }));
34
+ return joinCode(declarations, { on: "\n\n" }).toString({});
35
+ }
36
+ }
37
+ //# sourceMappingURL=ZodGenerator.js.map
@@ -300,6 +300,7 @@ export class IdentifierProperty extends AbstractProperty {
300
300
  condition: code `${variables.focusIdentifier}.termType === "Variable"`,
301
301
  patterns: code `${this.type.sparqlWherePatternsFunction}(${{
302
302
  filter: code `${variables.filter}?.${this.name}`,
303
+ ignoreRdfType: true, // Unused
303
304
  preferredLanguages: variables.preferredLanguages,
304
305
  propertyPatterns: code `[]`,
305
306
  schema: code `${this.objectType.staticModuleName}.${syntheticNamePrefix}schema.properties.${this.objectType.identifierProperty.name}.type()`,
@@ -0,0 +1,4 @@
1
+ import type { ObjectType } from "../ObjectType.js";
2
+ import { type Code } from "../ts-poet-wrapper.js";
3
+ export declare function ObjectType_fromJsonFunctionDeclarations(this: ObjectType): readonly Code[];
4
+ //# sourceMappingURL=ObjectType_fromJsonFunctionDeclarations.d.ts.map
@@ -1,10 +1,14 @@
1
- import { Maybe } from "purify-ts";
2
1
  import { imports } from "../imports.js";
3
2
  import { snippets } from "../snippets.js";
4
3
  import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
5
4
  import { code, joinCode } from "../ts-poet-wrapper.js";
6
- import { ObjectType_toJsonFunctionOrMethodDeclaration } from "./ObjectType_toJsonFunctionOrMethodDeclaration.js";
7
- function ObjectType_fromJsonFunctionDeclarations() {
5
+ const variables = {
6
+ jsonObject: code `${syntheticNamePrefix}jsonObject`,
7
+ };
8
+ export function ObjectType_fromJsonFunctionDeclarations() {
9
+ if (!this.features.has("json")) {
10
+ return [];
11
+ }
8
12
  const initializers = [];
9
13
  const propertiesFromJsonReturnType = [];
10
14
  const propertiesFromJsonStatements = [];
@@ -59,64 +63,4 @@ export function ${syntheticNamePrefix}fromJson(json: unknown): ${imports.Either}
59
63
  }`);
60
64
  return functionDeclarations;
61
65
  }
62
- function ObjectType_jsonSchemaFunctionDeclaration() {
63
- return code `\
64
- export function ${syntheticNamePrefix}jsonSchema() {
65
- return ${imports.z}.toJSONSchema(${syntheticNamePrefix}jsonZodSchema());
66
- }`;
67
- }
68
- function ObjectType_jsonUiSchemaFunctionDeclaration() {
69
- const variables = { scopePrefix: code `scopePrefix` };
70
- const elements = this.parentObjectTypes
71
- .map((parentObjectType) => code `${parentObjectType.staticModuleName}.${syntheticNamePrefix}jsonUiSchema({ scopePrefix })`)
72
- .concat(this.ownProperties.flatMap((property) => property.jsonUiSchemaElement({ variables }).toList()));
73
- return code `\
74
- export function ${syntheticNamePrefix}jsonUiSchema(parameters?: { scopePrefix?: string }): any {
75
- const scopePrefix = parameters?.scopePrefix ?? "#";
76
- return { "elements": [ ${joinCode(elements, { on: "," })} ], label: "${this.label.orDefault(this.name)}", type: "Group" };
77
- }`;
78
- }
79
- function ObjectType_jsonZodSchemaFunctionDeclaration() {
80
- const mergeZodObjectSchemas = [];
81
- for (const parentObjectType of this.parentObjectTypes) {
82
- mergeZodObjectSchemas.push(parentObjectType.jsonZodSchema({ context: "type" }));
83
- }
84
- if (this.properties.length > 0) {
85
- mergeZodObjectSchemas.push(code `${imports.z}.object({ ${joinCode(this.properties
86
- .flatMap((property) => property.jsonZodSchema.toList())
87
- .map(({ key, schema }) => code `"${key}": ${schema}`), { on: "," })} })`);
88
- }
89
- return code `\
90
- export function ${syntheticNamePrefix}jsonZodSchema() {
91
- return ${mergeZodObjectSchemas.length > 0
92
- ? mergeZodObjectSchemas.reduce((merged, zodObjectSchema) => {
93
- if (merged === null) {
94
- return zodObjectSchema;
95
- }
96
- return code `${merged}.merge(${zodObjectSchema})`;
97
- }, null)
98
- : `${imports.z}.object()`} satisfies ${imports.z}.ZodType<${syntheticNamePrefix}Json>;
99
- }`;
100
- }
101
- function ObjectType_toJsonFunctionDeclaration() {
102
- if (this.declarationType !== "interface") {
103
- return Maybe.empty();
104
- }
105
- return ObjectType_toJsonFunctionOrMethodDeclaration.bind(this)();
106
- }
107
- export function ObjectType_jsonFunctionDeclarations() {
108
- if (!this.features.has("json")) {
109
- return [];
110
- }
111
- return [
112
- ...ObjectType_fromJsonFunctionDeclarations.bind(this)(),
113
- ObjectType_jsonSchemaFunctionDeclaration.bind(this)(),
114
- ObjectType_jsonUiSchemaFunctionDeclaration.bind(this)(),
115
- ...ObjectType_toJsonFunctionDeclaration.bind(this)().toList(),
116
- ObjectType_jsonZodSchemaFunctionDeclaration.bind(this)(),
117
- ];
118
- }
119
- const variables = {
120
- jsonObject: code `${syntheticNamePrefix}jsonObject`,
121
- };
122
- //# sourceMappingURL=ObjectType_jsonFunctionDeclarations.js.map
66
+ //# sourceMappingURL=ObjectType_fromJsonFunctionDeclarations.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { ObjectType } from "../ObjectType.js";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ export declare function ObjectType_fromRdfFunctionDeclaration(this: ObjectType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectType_fromRdfFunctionDeclaration.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { imports } from "../imports.js";
3
+ import { snippets } from "../snippets.js";
4
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
5
+ import { code, joinCode } from "../ts-poet-wrapper.js";
6
+ export function ObjectType_fromRdfFunctionDeclaration() {
7
+ if (!this.features.has("rdf")) {
8
+ return Maybe.empty();
9
+ }
10
+ if (this.abstract) {
11
+ return Maybe.empty();
12
+ }
13
+ const statements = [
14
+ code `let { context, ignoreRdfType = false, objectSet, preferredLanguages } = (options ?? {});`,
15
+ code `if (!objectSet) { objectSet = new ${syntheticNamePrefix}RdfjsDatasetObjectSet(resource.dataset); }`,
16
+ ];
17
+ let propertiesFromRdfExpression = code `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf({ context, ignoreRdfType, objectSet, preferredLanguages, resource })`;
18
+ if (this.declarationType === "class") {
19
+ propertiesFromRdfExpression = code `${propertiesFromRdfExpression}.map(properties => new ${this.name}(properties))`;
20
+ }
21
+ statements.push(code `return ${propertiesFromRdfExpression};`);
22
+ return Maybe.of(code `\
23
+ export function ${syntheticNamePrefix}fromRdf(resource: ${imports.Resource}, options?: ${snippets.FromRdfOptions}): ${imports.Either}<Error, ${this.name}> {
24
+ ${joinCode(statements)}
25
+ }`);
26
+ }
27
+ //# sourceMappingURL=ObjectType_fromRdfFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { ObjectType } from "../ObjectType.js";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ export declare function ObjectType_jsonSchemaFunctionDeclaration(this: ObjectType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectType_jsonSchemaFunctionDeclaration.d.ts.map
@@ -0,0 +1,14 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { imports } from "../imports.js";
3
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
4
+ import { code } from "../ts-poet-wrapper.js";
5
+ export function ObjectType_jsonSchemaFunctionDeclaration() {
6
+ if (!this.features.has("json")) {
7
+ return Maybe.empty();
8
+ }
9
+ return Maybe.of(code `\
10
+ export function ${syntheticNamePrefix}jsonSchema() {
11
+ return ${imports.z}.toJSONSchema(${syntheticNamePrefix}jsonZodSchema());
12
+ }`);
13
+ }
14
+ //# sourceMappingURL=ObjectType_jsonSchemaFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { ObjectType } from "../ObjectType.js";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ export declare function ObjectType_jsonUiSchemaFunctionDeclaration(this: ObjectType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectType_jsonUiSchemaFunctionDeclaration.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
3
+ import { code, joinCode } from "../ts-poet-wrapper.js";
4
+ export function ObjectType_jsonUiSchemaFunctionDeclaration() {
5
+ if (!this.features.has("json")) {
6
+ return Maybe.empty();
7
+ }
8
+ const variables = { scopePrefix: code `scopePrefix` };
9
+ const elements = this.parentObjectTypes
10
+ .map((parentObjectType) => code `${parentObjectType.staticModuleName}.${syntheticNamePrefix}jsonUiSchema({ scopePrefix })`)
11
+ .concat(this.ownProperties.flatMap((property) => property.jsonUiSchemaElement({ variables }).toList()));
12
+ return Maybe.of(code `\
13
+ export function ${syntheticNamePrefix}jsonUiSchema(parameters?: { scopePrefix?: string }): any {
14
+ const scopePrefix = parameters?.scopePrefix ?? "#";
15
+ return { "elements": [ ${joinCode(elements, { on: "," })} ], label: "${this.label.orDefault(this.name)}", type: "Group" };
16
+ }`);
17
+ }
18
+ //# sourceMappingURL=ObjectType_jsonUiSchemaFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { ObjectType } from "../ObjectType.js";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ export declare function ObjectType_jsonZodSchemaFunctionDeclaration(this: ObjectType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectType_jsonZodSchemaFunctionDeclaration.d.ts.map
@@ -0,0 +1,30 @@
1
+ import { Maybe } from "purify-ts";
2
+ import { imports } from "../imports.js";
3
+ import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
4
+ import { code, joinCode } from "../ts-poet-wrapper.js";
5
+ export function ObjectType_jsonZodSchemaFunctionDeclaration() {
6
+ if (!this.features.has("json")) {
7
+ return Maybe.empty();
8
+ }
9
+ const mergeZodObjectSchemas = [];
10
+ for (const parentObjectType of this.parentObjectTypes) {
11
+ mergeZodObjectSchemas.push(parentObjectType.jsonZodSchema({ context: "type" }));
12
+ }
13
+ if (this.properties.length > 0) {
14
+ mergeZodObjectSchemas.push(code `${imports.z}.object({ ${joinCode(this.properties
15
+ .flatMap((property) => property.jsonZodSchema.toList())
16
+ .map(({ key, schema }) => code `"${key}": ${schema}`), { on: "," })} })`);
17
+ }
18
+ return Maybe.of(code `\
19
+ export function ${syntheticNamePrefix}jsonZodSchema() {
20
+ return ${mergeZodObjectSchemas.length > 0
21
+ ? mergeZodObjectSchemas.reduce((merged, zodObjectSchema) => {
22
+ if (merged === null) {
23
+ return zodObjectSchema;
24
+ }
25
+ return code `${merged}.merge(${zodObjectSchema})`;
26
+ }, null)
27
+ : `${imports.z}.object()`} satisfies ${imports.z}.ZodType<${syntheticNamePrefix}Json>;
28
+ }`);
29
+ }
30
+ //# sourceMappingURL=ObjectType_jsonZodSchemaFunctionDeclaration.js.map
@@ -0,0 +1,5 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { ObjectType } from "../ObjectType.js";
3
+ import { type Code } from "../ts-poet-wrapper.js";
4
+ export declare function ObjectType_propertiesFromRdfFunctionDeclaration(this: ObjectType): Maybe<Code>;
5
+ //# sourceMappingURL=ObjectType_propertiesFromRdfFunctionDeclaration.d.ts.map
@@ -5,26 +5,10 @@ import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
5
5
  import { snippets } from "../snippets.js";
6
6
  import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
7
7
  import { code, joinCode } from "../ts-poet-wrapper.js";
8
- import { ObjectType_toRdfFunctionOrMethodDeclaration } from "./ObjectType_toRdfFunctionOrMethodDeclaration.js";
9
- function ObjectType_fromRdfFunctionDeclaration() {
10
- if (this.abstract) {
8
+ export function ObjectType_propertiesFromRdfFunctionDeclaration() {
9
+ if (!this.features.has("rdf")) {
11
10
  return Maybe.empty();
12
11
  }
13
- const statements = [
14
- code `let { context, ignoreRdfType = false, objectSet, preferredLanguages } = (options ?? {});`,
15
- code `if (!objectSet) { objectSet = new ${syntheticNamePrefix}RdfjsDatasetObjectSet(resource.dataset); }`,
16
- ];
17
- let propertiesFromRdfExpression = code `${this.staticModuleName}.${syntheticNamePrefix}propertiesFromRdf({ context, ignoreRdfType, objectSet, preferredLanguages, resource })`;
18
- if (this.declarationType === "class") {
19
- propertiesFromRdfExpression = code `${propertiesFromRdfExpression}.map(properties => new ${this.name}(properties))`;
20
- }
21
- statements.push(code `return ${propertiesFromRdfExpression};`);
22
- return Maybe.of(code `\
23
- export function ${syntheticNamePrefix}fromRdf(resource: ${imports.Resource}, options?: ${snippets.FromRdfOptions}): ${imports.Either}<Error, ${this.name}> {
24
- ${joinCode(statements)}
25
- }`);
26
- }
27
- function ObjectType_propertiesFromRdfFunctionDeclaration() {
28
12
  const chains = [];
29
13
  const initializers = [];
30
14
  const propertySignatures = [];
@@ -108,25 +92,9 @@ function ObjectType_propertiesFromRdfFunctionDeclaration() {
108
92
  if (propertySignatures.length > 0) {
109
93
  returnType.splice(0, 0, code `{ ${joinCode(propertySignatures, { on: " " })} }`);
110
94
  }
111
- return code `\
95
+ return Maybe.of(code `\
112
96
  export function ${syntheticNamePrefix}propertiesFromRdf(${syntheticNamePrefix}parameters: ${snippets.PropertiesFromRdfParameters}): ${imports.Either}<Error, ${joinCode(returnType, { on: " & " })}> {
113
97
  ${joinCode(statements)}
114
- }`;
115
- }
116
- export function ObjectType_rdfFunctionDeclarations() {
117
- if (!this.features.has("rdf")) {
118
- return [];
119
- }
120
- return [
121
- ...ObjectType_fromRdfFunctionDeclaration.bind(this)().toList(),
122
- ObjectType_propertiesFromRdfFunctionDeclaration.bind(this)(),
123
- ...ObjectType_toRdfFunctionDeclaration.bind(this)().toList(),
124
- ];
125
- }
126
- function ObjectType_toRdfFunctionDeclaration() {
127
- if (this.declarationType !== "interface") {
128
- return Maybe.empty();
129
- }
130
- return ObjectType_toRdfFunctionOrMethodDeclaration.bind(this)();
98
+ }`);
131
99
  }
132
- //# sourceMappingURL=ObjectType_rdfFunctionDeclarations.js.map
100
+ //# sourceMappingURL=ObjectType_propertiesFromRdfFunctionDeclaration.js.map
@@ -1,6 +1,10 @@
1
+ import { Maybe } from "purify-ts";
2
+ import type { TsFeature } from "../../../enums/TsFeature.js";
1
3
  import { type Code } from "../ts-poet-wrapper.js";
2
4
  export declare function ObjectType_sparqlConstructQueryFunctionDeclaration(this: {
5
+ readonly features: ReadonlySet<TsFeature>;
3
6
  readonly filterType: Code;
7
+ readonly name: string;
4
8
  readonly staticModuleName: string;
5
- }): Code;
9
+ }): Maybe<Code>;
6
10
  //# sourceMappingURL=ObjectType_sparqlConstructQueryFunctionDeclaration.d.ts.map
@@ -1,12 +1,42 @@
1
+ import { camelCase } from "change-case";
2
+ import { Maybe } from "purify-ts";
1
3
  import { imports } from "../imports.js";
2
4
  import { snippets } from "../snippets.js";
3
5
  import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
4
6
  import { code } from "../ts-poet-wrapper.js";
5
7
  export function ObjectType_sparqlConstructQueryFunctionDeclaration() {
6
- return code `\
7
- export function ${syntheticNamePrefix}sparqlConstructQuery(parameters?: { filter?: ${this.filterType}; ignoreRdfType?: boolean; prefixes?: { [prefix: string]: string }; preferredLanguages?: readonly string[]; subject?: ${imports.NamedNode} | ${imports.Variable} } & Omit<${imports.sparqljs}.ConstructQuery, "prefixes" | "queryType" | "type">): ${imports.sparqljs}.ConstructQuery {
8
- const { filter, ignoreRdfType, preferredLanguages, subject, ...queryParameters } = parameters ?? {};
9
- return { ...queryParameters, prefixes: parameters?.prefixes ?? {}, queryType: "CONSTRUCT", template: (queryParameters.template ?? []).concat(${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTriples({ filter, focusIdentifier: subject, ignoreRdfType })), type: "query", where: (queryParameters.where ?? []).concat(${snippets.normalizeSparqlWherePatterns}(${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({ filter, focusIdentifier: subject, ignoreRdfType, preferredLanguages }))) };
10
- }`;
8
+ if (!this.features.has("sparql")) {
9
+ return Maybe.empty();
10
+ }
11
+ return Maybe.of(code `\
12
+ export function ${syntheticNamePrefix}sparqlConstructQuery({ filter, ignoreRdfType, preferredLanguages, prefixes, subject, ...queryParameters }: { filter?: ${this.filterType}; ignoreRdfType?: boolean; prefixes?: { [prefix: string]: string }; preferredLanguages?: readonly string[]; subject: ${imports.NamedNode} | ${imports.Variable} } & Omit<${imports.sparqljs}.ConstructQuery, "prefixes" | "queryType" | "type">): ${imports.sparqljs}.ConstructQuery {
13
+ const variablePrefix = subject.termType === "Variable" ? subject.value : "${camelCase(this.name)}";
14
+
15
+ return {
16
+ ...queryParameters,
17
+ prefixes: prefixes ?? {},
18
+ queryType: "CONSTRUCT",
19
+ template: (queryParameters.template ?? []).concat(
20
+ ${this.staticModuleName}.${syntheticNamePrefix}sparqlConstructTriples({
21
+ filter,
22
+ focusIdentifier: subject,
23
+ ignoreRdfType: !!ignoreRdfType,
24
+ variablePrefix
25
+ })
26
+ ),
27
+ type: "query",
28
+ where: (queryParameters.where ?? []).concat(
29
+ ${snippets.normalizeSparqlWherePatterns}(
30
+ ${this.staticModuleName}.${syntheticNamePrefix}sparqlWherePatterns({
31
+ filter,
32
+ focusIdentifier: subject,
33
+ ignoreRdfType: !!ignoreRdfType,
34
+ preferredLanguages,
35
+ variablePrefix
36
+ })
37
+ )
38
+ )
39
+ };
40
+ }`);
11
41
  }
12
42
  //# sourceMappingURL=ObjectType_sparqlConstructQueryFunctionDeclaration.js.map