@shaclmate/compiler 4.0.31 → 4.0.32

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.
@@ -104,6 +104,7 @@ export declare class Snippets {
104
104
  get parseBlankNode(): Snippet;
105
105
  get parseIdentifier(): Snippet;
106
106
  get parseIri(): Snippet;
107
+ get sequenceRecord(): Snippet;
107
108
  get setSparqlConstructTriples(): Snippet;
108
109
  get setSparqlWherePatterns(): Snippet;
109
110
  get shaclPropertyFromRdf(): Snippet;
@@ -93,6 +93,7 @@ import { snippets_SparqlPattern } from "./_snippets/snippets_SparqlPattern.js";
93
93
  import { snippets_SparqlPattern_isSolutionGenerating } from "./_snippets/snippets_SparqlPattern_isSolutionGenerating.js";
94
94
  import { snippets_StringFilter } from "./_snippets/snippets_StringFilter.js";
95
95
  import { snippets_StringSchema } from "./_snippets/snippets_StringSchema.js";
96
+ import { snippets_sequenceRecord } from "./_snippets/snippets_sequenceRecord.js";
96
97
  import { snippets_setSparqlConstructTriples } from "./_snippets/snippets_setSparqlConstructTriples.js";
97
98
  import { snippets_setSparqlWherePatterns } from "./_snippets/snippets_setSparqlWherePatterns.js";
98
99
  import { snippets_shaclPropertyFromRdf } from "./_snippets/snippets_shaclPropertyFromRdf.js";
@@ -427,6 +428,9 @@ export class Snippets {
427
428
  get parseIri() {
428
429
  return this.snippet(snippets_parseIri);
429
430
  }
431
+ get sequenceRecord() {
432
+ return this.snippet(snippets_sequenceRecord);
433
+ }
430
434
  get setSparqlConstructTriples() {
431
435
  return this.snippet(snippets_setSparqlConstructTriples);
432
436
  }
@@ -774,6 +778,9 @@ __decorate([
774
778
  __decorate([
775
779
  Memoize()
776
780
  ], Snippets.prototype, "parseIri", null);
781
+ __decorate([
782
+ Memoize()
783
+ ], Snippets.prototype, "sequenceRecord", null);
777
784
  __decorate([
778
785
  Memoize()
779
786
  ], Snippets.prototype, "setSparqlConstructTriples", null);
@@ -14,8 +14,8 @@ const variables = {
14
14
  const propertyFromRdfResourceValuesExpressionVariable = {
15
15
  context: variables.context,
16
16
  graph: variables.graph,
17
- preferredLanguages: variables.preferredLanguages,
18
17
  objectSet: variables.objectSet,
18
+ preferredLanguages: variables.preferredLanguages,
19
19
  resource: variables.resource,
20
20
  };
21
21
  export function NamedObjectType_fromRdfResourceFunctionDeclaration() {
@@ -23,13 +23,13 @@ export function NamedObjectType_fromRdfResourceFunctionDeclaration() {
23
23
  return Maybe.empty();
24
24
  }
25
25
  const chains = [];
26
- const initializers = [];
26
+ const partials = [];
27
27
  this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
28
28
  chains.push({
29
29
  expression: code `${parentObjectType.name}._fromRdfResource(${variables.resource}, { ...${optionsVariable}, ignoreRdfType: true })`,
30
- variable: `${syntheticNamePrefix}super${parentObjectTypeI}`,
30
+ variable: `super${parentObjectTypeI}`,
31
31
  });
32
- initializers.push(code `...${syntheticNamePrefix}super${parentObjectTypeI}`);
32
+ partials.push(`super${parentObjectTypeI}`);
33
33
  });
34
34
  this.fromRdfType.ifJust((fromRdfType) => {
35
35
  const fromRdfTypeVariable = this.fromRdfTypeVariable.unsafeCoerce();
@@ -57,24 +57,41 @@ export function NamedObjectType_fromRdfResourceFunctionDeclaration() {
57
57
 
58
58
  return ${this.reusables.imports.Left}(new Error(\`\${${variables.resource}.identifier} has unexpected RDF type (actual: \${actualRdfType.value}, expected: ${fromRdfType.value})\`));
59
59
  }) : ${this.reusables.imports.Right}(true as const)`,
60
- variable: "_rdfTypeCheck",
60
+ variable: `_rdfTypeCheck`,
61
61
  });
62
62
  });
63
+ const propertyFromRdfResourceValuesExpressions = {};
63
64
  for (const property of this.properties) {
64
65
  property
65
66
  .fromRdfResourceValuesExpression({
66
67
  variables: propertyFromRdfResourceValuesExpressionVariable,
67
68
  })
68
- .ifJust((propertyFromRdfExpression) => {
69
- chains.push({
70
- expression: propertyFromRdfExpression,
71
- variable: property.name,
72
- });
73
- initializers.push(code `${property.name}`);
69
+ .ifJust((propertyFromRdfResourceValuesExpression) => {
70
+ propertyFromRdfResourceValuesExpressions[property.name] =
71
+ propertyFromRdfResourceValuesExpression;
72
+ });
73
+ }
74
+ if (Object.keys(propertyFromRdfResourceValuesExpressions).length > 0) {
75
+ chains.push({
76
+ expression: code `${this.reusables.snippets.sequenceRecord}(${propertyFromRdfResourceValuesExpressions})`,
77
+ variable: "properties",
74
78
  });
79
+ partials.push("properties");
80
+ }
81
+ let partialsJoined;
82
+ switch (partials.length) {
83
+ case 0:
84
+ partialsJoined = code `{}`;
85
+ break;
86
+ case 1:
87
+ partialsJoined = code `${partials[0]}`;
88
+ break;
89
+ default:
90
+ partialsJoined = code `{ ${partials.map((partial) => `...${partial}`).join(", ")} }`;
91
+ break;
75
92
  }
76
93
  const statements = [];
77
- const resultExpression = code `${this.name}.create({ ${joinCode(initializers, { on: "," })} })`;
94
+ const resultExpression = code `create(${partialsJoined})`;
78
95
  if (chains.length === 0) {
79
96
  statements.push(code `return ${this.reusables.imports.Right}(${resultExpression});`);
80
97
  }
@@ -0,0 +1,3 @@
1
+ import type { SnippetFactory } from "../SnippetFactory.js";
2
+ export declare const snippets_sequenceRecord: SnippetFactory;
3
+ //# sourceMappingURL=snippets_sequenceRecord.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
2
+ export const snippets_sequenceRecord = ({ imports, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}sequenceRecord`, code `\
3
+ function ${syntheticNamePrefix}sequenceRecord<T extends Record<string, unknown>>(
4
+ record: { [K in keyof T]: ${imports.Either}<Error, T[K]> }
5
+ ): ${imports.Either}<Error, T> {
6
+ const result: { [K in keyof T]?: T[K] } = {};
7
+
8
+ for (const key of globalThis.Object.keys(record) as Array<keyof T>) {
9
+ const either = record[key];
10
+ if (either.isLeft()) {
11
+ return either as unknown as ${imports.Either}<Error, T>;
12
+ }
13
+ result[key] = either.extract() as T[typeof key];
14
+ }
15
+
16
+ return ${imports.Right}(result as T);
17
+ }`);
18
+ //# sourceMappingURL=snippets_sequenceRecord.js.map