parent
d2d9c665f6
commit
ce82867563
@ -1,542 +0,0 @@ |
|||||||
export {}; |
|
||||||
/** |
|
||||||
* Structure for expressing a Shape Expression schema. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-shapes-schema">ShEx Schema definition</a> |
|
||||||
*/ |
|
||||||
export interface Schema { |
|
||||||
/** |
|
||||||
* Mandatory type "Schema". |
|
||||||
*/ |
|
||||||
type: "Schema"; |
|
||||||
/** |
|
||||||
* JSON-LD <a href="https://www.w3.org/TR/json-ld11/#the-context">@context</a> for ShEx. |
|
||||||
*/ |
|
||||||
"@context"?: "http://www.w3.org/ns/shex.jsonld" | undefined; |
|
||||||
/** |
|
||||||
* List of semantic actions to be executed when evaluating conformance. |
|
||||||
*/ |
|
||||||
startActs?: SemAct[] | undefined; |
|
||||||
/** |
|
||||||
* Identifies default starting shape expression. |
|
||||||
*/ |
|
||||||
start?: shapeExprOrRef | undefined; |
|
||||||
/** |
|
||||||
* List of ShEx schemas to <a href="http://shex.io/shex-semantics/#import">import</a> when processing this schema. |
|
||||||
*/ |
|
||||||
imports?: IRIREF[] | undefined; |
|
||||||
/** |
|
||||||
* The list of {@link ShapeDecl}s defined in this schema. Each MUST include and {@link ShapeOr#id}. |
|
||||||
*/ |
|
||||||
shapes?: ShapeDecl[] | undefined; |
|
||||||
} |
|
||||||
export interface semactsAndAnnotations { |
|
||||||
/** |
|
||||||
* List of semantic actions to be executed when evaluating conformance. |
|
||||||
*/ |
|
||||||
semActs?: SemAct[] | undefined; |
|
||||||
/** |
|
||||||
* List of {@link SemAct#predicate}/{@link SemAct#object} annotations. |
|
||||||
*/ |
|
||||||
annotations?: Annotation[] | undefined; |
|
||||||
} |
|
||||||
/** |
|
||||||
* A declaration for a shapeExpr with added inheritance constraints. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-shapedecl">ShEx ShapeDecl definition</a> |
|
||||||
*/ |
|
||||||
export interface ShapeDecl { |
|
||||||
/** |
|
||||||
* Mandatory type "ShapeDecl". |
|
||||||
*/ |
|
||||||
type: "ShapeDecl"; |
|
||||||
/** |
|
||||||
* The identifier is an <a href="https://www.w3.org/TR/json-ld11/#node-identifiers">IRI</a> or a <a href="https://www.w3.org/TR/json-ld11/#identifying-blank-nodes">BlankNode</a> |
|
||||||
* as expressed in <a href="https://www.w3.org/TR/json-ld11/">JSON-LD 1.1</a>. |
|
||||||
*/ |
|
||||||
id: shapeDeclLabel; |
|
||||||
/** |
|
||||||
* Whether this ShapeDecl participates in <a href="http://shex.io/shex-semantics/#dfn-inheritanceSubstitution">inheritance substitution</a>. |
|
||||||
*/ |
|
||||||
abstract?: BOOL | undefined; |
|
||||||
/** |
|
||||||
* The list of {@link shapeExprOrRef}s that a neighborhood MUST conform to in order to conform to this ShapeDecl. |
|
||||||
*/ |
|
||||||
restricts?: shapeExprOrRef[] | undefined; |
|
||||||
/** |
|
||||||
* The {@link shapeExpr} to which this neighborhood MUST also conform. |
|
||||||
*/ |
|
||||||
shapeExpr: shapeExpr; |
|
||||||
} |
|
||||||
/** |
|
||||||
* Union of shape expression types. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-shapeexpr">ShEx shapeExpr definition</a> |
|
||||||
*/ |
|
||||||
export type shapeExpr = ShapeOr | ShapeAnd | ShapeNot | NodeConstraint | Shape | ShapeExternal; |
|
||||||
/** |
|
||||||
* Union of shapeExpr and shapeDeclRef. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-shapeexpr">ShEx shapeExpr definition</a> |
|
||||||
*/ |
|
||||||
export type shapeExprOrRef = shapeExpr | shapeDeclRef; |
|
||||||
/** |
|
||||||
* A non-exclusive choice of shape expressions; considered conformant if any of {@link #shapeExprs} conforms. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-shapeor">ShEx shapeExpr definition</a> |
|
||||||
*/ |
|
||||||
export interface ShapeOr { |
|
||||||
/** |
|
||||||
* Mandatory type "ShapeOr". |
|
||||||
*/ |
|
||||||
type: "ShapeOr"; |
|
||||||
/** |
|
||||||
* List of two or more {@link shapeExprOrRef}s in this disjunction. |
|
||||||
*/ |
|
||||||
shapeExprs: shapeExprOrRef[]; |
|
||||||
} |
|
||||||
/** |
|
||||||
* A conjunction of shape expressions; considered conformant if each conjunct conforms. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-shapeor">ShEx shapeExpr definition</a> |
|
||||||
*/ |
|
||||||
export interface ShapeAnd { |
|
||||||
/** |
|
||||||
* Mandatory type "ShapeAnd". |
|
||||||
*/ |
|
||||||
type: "ShapeAnd"; |
|
||||||
/** |
|
||||||
* List of two or more {@link shapeExprOrRef}s in this conjunction. |
|
||||||
*/ |
|
||||||
shapeExprs: shapeExprOrRef[]; |
|
||||||
} |
|
||||||
/** |
|
||||||
* A negated shape expressions; considered conformant if {@link #shapeExpr} is not conformant. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-shapenot">ShEx shapeExpr definition</a> |
|
||||||
*/ |
|
||||||
export interface ShapeNot { |
|
||||||
/** |
|
||||||
* Mandatory type "ShapeNot". |
|
||||||
*/ |
|
||||||
type: "ShapeNot"; |
|
||||||
/** |
|
||||||
* The {@link shapeExprOrRef} that must be non-conformant for this shape expression to be conformant. |
|
||||||
*/ |
|
||||||
shapeExpr: shapeExprOrRef; |
|
||||||
} |
|
||||||
/** |
|
||||||
* A shape expression not defined in this schema or in any imported schema. The definition of this shape expression is NOT defined by ShEx. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-shapeexternal">ShEx shapeExpr definition</a> |
|
||||||
*/ |
|
||||||
export interface ShapeExternal { |
|
||||||
/** |
|
||||||
* Mandatory type "ShapeExternal". |
|
||||||
*/ |
|
||||||
type: "ShapeExternal"; |
|
||||||
} |
|
||||||
/** |
|
||||||
* A reference a shape expression. |
|
||||||
* The reference is an <a href="https://www.w3.org/TR/json-ld11/#node-identifiers">IRI</a> or a <a href="https://www.w3.org/TR/json-ld11/#identifying-blank-nodes">BlankNode</a> |
|
||||||
* as expressed in <a href="https://www.w3.org/TR/json-ld11/">JSON-LD 1.1</a>. |
|
||||||
* This is modified to also include the possibility of ShapeDecl |
|
||||||
*/ |
|
||||||
export type shapeDeclRef = shapeDeclLabel | ShapeDecl; |
|
||||||
/** |
|
||||||
* An identifier for a shape expression. |
|
||||||
* The identifier is an <a href="https://www.w3.org/TR/json-ld11/#node-identifiers">IRI</a> or a <a href="https://www.w3.org/TR/json-ld11/#identifying-blank-nodes">BlankNode</a> |
|
||||||
* as expressed in <a href="https://www.w3.org/TR/json-ld11/">JSON-LD 1.1</a>. |
|
||||||
*/ |
|
||||||
export type shapeDeclLabel = IRIREF | BNODE; |
|
||||||
export type nodeKind = "iri" | "bnode" | "nonliteral" | "literal"; |
|
||||||
/** |
|
||||||
* A collection of constraints on <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-node">RDF Term</a>s expected for conformance. |
|
||||||
* The identifier is an <a href="https://www.w3.org/TR/json-ld11/#node-identifiers">IRI</a> or a <a href="https://www.w3.org/TR/json-ld11/#identifying-blank-nodes">BlankNode</a> |
|
||||||
* as expressed in <a href="https://www.w3.org/TR/json-ld11/">JSON-LD 1.1</a>. |
|
||||||
*/ |
|
||||||
export interface NodeConstraint extends xsFacets, semactsAndAnnotations { |
|
||||||
/** |
|
||||||
* Mandatory type "NodeConstraint". |
|
||||||
*/ |
|
||||||
type: "NodeConstraint"; |
|
||||||
/** |
|
||||||
* Type of <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-node">RDF Term</a> expected for a conformant RDF node. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#nodeKind">ShEx nodeKind definition</a> |
|
||||||
*/ |
|
||||||
nodeKind?: nodeKind | undefined; |
|
||||||
/** |
|
||||||
* The <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri">RDF Literal datatype IRITerm</a> expected for a conformant RDF node. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#datatype">ShEx datatype definition</a> |
|
||||||
*/ |
|
||||||
datatype?: IRIREF | undefined; |
|
||||||
/** |
|
||||||
* The set of permissible values. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#values">ShEx values definition</a> |
|
||||||
*/ |
|
||||||
values?: valueSetValue[] | undefined; |
|
||||||
} |
|
||||||
/** |
|
||||||
* The set of XML Schema Facets supported in ShEx; defers to {@link stringFacets} and {@link numericFacets}. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#xs-string">ShEx String Facet Constraints</a> and <a href="http://shex.io/shex-semantics/#xs-numeric">ShEx Numeric Facet Constraints</a>. |
|
||||||
*/ |
|
||||||
export interface xsFacets extends stringFacets, numericFacets { |
|
||||||
} |
|
||||||
/** |
|
||||||
* The set of <a href="https://www.w3.org/TR/xmlschema-2/#facets">XML Schema Facets</a> applying to <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form">lexical forms of RDF terms</a>. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#xs-string">ShEx String Facet Constraints</a>. |
|
||||||
*/ |
|
||||||
export interface stringFacets { |
|
||||||
/** |
|
||||||
* Expected length of the lexical form of an RDF Term. |
|
||||||
*/ |
|
||||||
length?: INTEGER | undefined; |
|
||||||
/** |
|
||||||
* Expected minimum length of the lexical form of an RDF Term. |
|
||||||
*/ |
|
||||||
minlength?: INTEGER | undefined; |
|
||||||
/** |
|
||||||
* Expected maximum length of the lexical form of an RDF Term. |
|
||||||
*/ |
|
||||||
maxlength?: INTEGER | undefined; |
|
||||||
/** |
|
||||||
* Regular expression which the lexical forn of an RDF Term must match. |
|
||||||
*/ |
|
||||||
pattern?: STRING | undefined; |
|
||||||
/** |
|
||||||
* Optional flags for the regular expression in {@link pattern}. |
|
||||||
*/ |
|
||||||
flags?: STRING | undefined; |
|
||||||
} |
|
||||||
/** |
|
||||||
* The set of <a href="https://www.w3.org/TR/xmlschema-2/#facets">XML Schema Facets</a> applying to <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-value-space">numeric values of RDF terms</a>. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#xs-numeric">ShEx Numeric Facet Constraints</a>. |
|
||||||
*/ |
|
||||||
export interface numericFacets { |
|
||||||
/** |
|
||||||
* Conformant <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF Literal</a> has as a numeric value <= {@link mininclusive}. |
|
||||||
*/ |
|
||||||
mininclusive?: numericLiteral | undefined; |
|
||||||
/** |
|
||||||
* Conformant <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF Literal</a> has as a numeric value < {@link minexclusive}. |
|
||||||
*/ |
|
||||||
minexclusive?: numericLiteral | undefined; |
|
||||||
/** |
|
||||||
* Conformant <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF Literal</a> has as a numeric value > {@link maxinclusive}. |
|
||||||
*/ |
|
||||||
maxinclusive?: numericLiteral | undefined; |
|
||||||
/** |
|
||||||
* Conformant <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF Literal</a> has as a numeric value >= {@link maxexclusive}. |
|
||||||
*/ |
|
||||||
maxexclusive?: numericLiteral | undefined; |
|
||||||
/** |
|
||||||
* Conformant <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF Literal</a> has as a numeric value whose canonical form has {@link totaldigits} digits. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#nodeSatisfies-totaldigits">ShEx totalDigits definition</a> |
|
||||||
*/ |
|
||||||
totaldigits?: INTEGER | undefined; |
|
||||||
/** |
|
||||||
* Conformant <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF Literal</a> has as a numeric value whose canonical form has {@link fractiondigits} digits. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#nodeSatisfies-fractiondigits">ShEx fractionDigits definition</a> |
|
||||||
*/ |
|
||||||
fractiondigits?: INTEGER | undefined; |
|
||||||
} |
|
||||||
/** |
|
||||||
* Union of numeric types in ShEx used in {@link numericFacets}s. |
|
||||||
*/ |
|
||||||
export type numericLiteral = INTEGER | DECIMAL | DOUBLE; |
|
||||||
/** |
|
||||||
* Union of numeric types that may appear in a value set. |
|
||||||
* @see {@link NodeConstraint#values}. |
|
||||||
*/ |
|
||||||
export type valueSetValue = objectValue | IriStem | IriStemRange | LiteralStem | LiteralStemRange | Language | LanguageStem | LanguageStemRange; |
|
||||||
/** |
|
||||||
* JSON-LD representation of a URL or a Literal. |
|
||||||
*/ |
|
||||||
export type objectValue = IRIREF | ObjectLiteral; |
|
||||||
/** |
|
||||||
* A <a href="https://www.w3.org/TR/json-ld11/#value-objects">JSON-LD Value Object</a> used to express an <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF Literal</a>. |
|
||||||
*/ |
|
||||||
export interface ObjectLiteral { |
|
||||||
/** |
|
||||||
* The <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form">lexical form</a> of an RDF Literal. |
|
||||||
*/ |
|
||||||
value: STRING; |
|
||||||
/** |
|
||||||
* The <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-language-tag">language tag</a> of an RDF Literal. |
|
||||||
*/ |
|
||||||
language?: STRING | undefined; |
|
||||||
/** |
|
||||||
* The <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-datatype">datatype</a> of an RDF Literal. |
|
||||||
*/ |
|
||||||
type?: STRING | undefined; |
|
||||||
} |
|
||||||
/** |
|
||||||
* Matchs an <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-iri">RDF IRI</a> starting with the character sequence in {@link stem}. |
|
||||||
*/ |
|
||||||
export interface IriStem { |
|
||||||
/** |
|
||||||
* Mandatory type "IriStem". |
|
||||||
*/ |
|
||||||
type: "IriStem"; |
|
||||||
/** |
|
||||||
* substring of IRI to be matched. |
|
||||||
*/ |
|
||||||
stem: IRIREF; |
|
||||||
} |
|
||||||
export type iriRangeStem = IRIREF | Wildcard; |
|
||||||
export type iriRangeExclusion = IRIREF | IriStem; |
|
||||||
/** |
|
||||||
* Filters a matching <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-iri">RDF IRI</a>s through a list of exclusions. |
|
||||||
* The initial match is made on an IRI stem per {@link IriStem} or a {@link Wildcard} to accept any IRI. |
|
||||||
* The {@link exclusion}s are either specific IRIs or {@link IRIStem}s. |
|
||||||
*/ |
|
||||||
export interface IriStemRange { |
|
||||||
/** |
|
||||||
* Mandatory type "IriStemRange". |
|
||||||
*/ |
|
||||||
type: "IriStemRange"; |
|
||||||
/** |
|
||||||
* substring of IRI to be matched or a {@link Wildcard} matching any IRI. |
|
||||||
*/ |
|
||||||
stem: iriRangeStem; |
|
||||||
/** |
|
||||||
* IRIs or {@link IRIStem}s to exclude. |
|
||||||
*/ |
|
||||||
exclusions: iriRangeExclusion[]; |
|
||||||
} |
|
||||||
/** |
|
||||||
* Matchs an <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF Literal</a> starting with the character sequence in {@link stem}. |
|
||||||
*/ |
|
||||||
export interface LiteralStem { |
|
||||||
/** |
|
||||||
* Mandatory type "LiteralStem". |
|
||||||
*/ |
|
||||||
type: "LiteralStem"; |
|
||||||
/** |
|
||||||
* substring of Literal to be matched. |
|
||||||
*/ |
|
||||||
stem: STRING; |
|
||||||
} |
|
||||||
export type literalRangeStem = string | Wildcard; |
|
||||||
export type literalRangeExclusion = string | LiteralStem; |
|
||||||
/** |
|
||||||
* Filters a matching <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-literal">RDF Literal</a>s through a list of exclusions. |
|
||||||
* The initial match is made on an Literal stem per {@link LiteralStem} or a {@link Wildcard} to accept any Literal. |
|
||||||
* The {@link exclusion}s are either specific Literals or {@link LiteralStem}s. |
|
||||||
*/ |
|
||||||
export interface LiteralStemRange { |
|
||||||
/** |
|
||||||
* Mandatory type "LiteralStemRange". |
|
||||||
*/ |
|
||||||
type: "LiteralStemRange"; |
|
||||||
/** |
|
||||||
* substring of Literal to be matched or a {@link Wildcard} matching any Literal. |
|
||||||
*/ |
|
||||||
stem: literalRangeStem; |
|
||||||
/** |
|
||||||
* Literals or {@link LiteralStem}s to exclude. |
|
||||||
*/ |
|
||||||
exclusions: literalRangeExclusion[]; |
|
||||||
} |
|
||||||
/** |
|
||||||
* An <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-language-tag">RDF Language Tag</a>. |
|
||||||
*/ |
|
||||||
export interface Language { |
|
||||||
/** |
|
||||||
* Mandatory type "Language". |
|
||||||
*/ |
|
||||||
type: "Language"; |
|
||||||
/** |
|
||||||
* The <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form">lexical representation</a> of an RDF Language Tag. |
|
||||||
*/ |
|
||||||
languageTag: LANGTAG; |
|
||||||
} |
|
||||||
/** |
|
||||||
* Matchs an <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-language-tag">RDF Language Tag</a> starting with the character sequence in {@link stem}. |
|
||||||
*/ |
|
||||||
export interface LanguageStem { |
|
||||||
/** |
|
||||||
* Mandatory type "LanguageStem". |
|
||||||
*/ |
|
||||||
type: "LanguageStem"; |
|
||||||
/** |
|
||||||
* substring of Language Tag to be matched. |
|
||||||
*/ |
|
||||||
stem: LANGTAG; |
|
||||||
} |
|
||||||
export type languageRangeStem = string | Wildcard; |
|
||||||
export type languageRangeExclusion = string | LanguageStem; |
|
||||||
/** |
|
||||||
* Filters a matching <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-langugae-tag">RDF Language Tag</a>s through a list of exclusions. |
|
||||||
* The initial match is made on an Language Tag stem per {@link Language TagStem} or a {@link Wildcard} to accept any Language Tag. |
|
||||||
* The {@link exclusion}s are either specific Language Tags or {@link Language TagStem}s. |
|
||||||
*/ |
|
||||||
export interface LanguageStemRange { |
|
||||||
/** |
|
||||||
* Mandatory type "LanguageStemRange". |
|
||||||
*/ |
|
||||||
type: "LanguageStemRange"; |
|
||||||
/** |
|
||||||
* substring of Language-Tag to be matched or a {@link Wildcard} matching any Language Tag. |
|
||||||
*/ |
|
||||||
stem: languageRangeStem; |
|
||||||
/** |
|
||||||
* Language Tags or {@link LanguageStem}s to exclude. |
|
||||||
*/ |
|
||||||
exclusions: languageRangeExclusion[]; |
|
||||||
} |
|
||||||
/** |
|
||||||
* An empty object signifying than any item may be matched. |
|
||||||
* This is used in {@link IriStemRange}, {@link LiteralStemRange} and {@link LanguageStemRange}. |
|
||||||
*/ |
|
||||||
export interface Wildcard { |
|
||||||
/** |
|
||||||
* Mandatory type "Wildcard". |
|
||||||
*/ |
|
||||||
type: "Wildcard"; |
|
||||||
} |
|
||||||
/** |
|
||||||
* A collection of {@link tripleExpr}s which must be matched by <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-triple">RDF Triple</a>s in conformance data. |
|
||||||
*/ |
|
||||||
export interface Shape extends semactsAndAnnotations { |
|
||||||
/** |
|
||||||
* Mandatory type "Shape". |
|
||||||
*/ |
|
||||||
type: "Shape"; |
|
||||||
/** |
|
||||||
* Only the predicates mentioned in the {@link expression} may appear in conformant data. |
|
||||||
*/ |
|
||||||
closed?: BOOL | undefined; |
|
||||||
/** |
|
||||||
* Permit extra triples with these predicates to appear in triples which don't match any {@link TripleConstraint}s mentioned in the {@link expression}. |
|
||||||
*/ |
|
||||||
extra?: IRIREF[] | undefined; |
|
||||||
/** |
|
||||||
* List of one or more {@link shapeExprOrRef}s that a neighborhood must satisfy in order to conform to this shape. |
|
||||||
*/ |
|
||||||
extends?: shapeExprOrRef[]; |
|
||||||
/** |
|
||||||
* A tree of {@link tripleExpr}s specifying a set triples into or out of conformant <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-node">RDF Nodes</a>. |
|
||||||
*/ |
|
||||||
expression?: tripleExprOrRef | undefined; |
|
||||||
} |
|
||||||
/** |
|
||||||
* Union of triple expression types. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-tripleexpr">ShEx tripleExpr definition</a> |
|
||||||
*/ |
|
||||||
export type tripleExpr = EachOf | OneOf | TripleConstraint; |
|
||||||
/** |
|
||||||
* A tripleExpr or a label to one. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-tripleexpr">ShEx tripleExpr definition</a> |
|
||||||
*/ |
|
||||||
export type tripleExprOrRef = tripleExpr | tripleExprRef; |
|
||||||
/** |
|
||||||
* Common attributes appearing in every form of {@link tripleExpr}. |
|
||||||
*/ |
|
||||||
export interface tripleExprBase extends semactsAndAnnotations { |
|
||||||
/** |
|
||||||
* Optional identifier for {@link tripleExpr}s for reference by {@link tripleExprRef}. |
|
||||||
* The identifier is an <a href="https://www.w3.org/TR/json-ld11/#node-identifiers">IRI</a> or a <a href="https://www.w3.org/TR/json-ld11/#identifying-blank-nodes">BlankNode</a> |
|
||||||
* as expressed in <a href="https://www.w3.org/TR/json-ld11/">JSON-LD 1.1</a>. |
|
||||||
*/ |
|
||||||
id?: tripleExprLabel | undefined; |
|
||||||
/** |
|
||||||
* Minimum number of times matching triples must appear in conformant data. |
|
||||||
*/ |
|
||||||
min?: INTEGER | undefined; |
|
||||||
/** |
|
||||||
* Maximum number of times matching triples must appear in conformant data. |
|
||||||
*/ |
|
||||||
max?: INTEGER | undefined; |
|
||||||
} |
|
||||||
/** |
|
||||||
* A list of of triple expressions; considered conformant if there is some conforming mapping of the examined triples to the {@link #tripleExprs}. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-eachof">ShEx EachOf definition</a> |
|
||||||
*/ |
|
||||||
export interface EachOf extends tripleExprBase { |
|
||||||
/** |
|
||||||
* Mandatory type "EachOf". |
|
||||||
*/ |
|
||||||
type: "EachOf"; |
|
||||||
expressions: tripleExprOrRef[]; |
|
||||||
} |
|
||||||
/** |
|
||||||
* An exclusive choice of triple expressions; considered conformant if exactly one of {@link #shapeExprs} conforms. |
|
||||||
* @see <a href="http://shex.io/shex-semantics/#dfn-oneof">ShEx OneOf definition</a> |
|
||||||
*/ |
|
||||||
export interface OneOf extends tripleExprBase { |
|
||||||
/** |
|
||||||
* Mandatory type "OneOf". |
|
||||||
*/ |
|
||||||
type: "OneOf"; |
|
||||||
expressions: tripleExprOrRef[]; |
|
||||||
} |
|
||||||
/** |
|
||||||
* A template matching a number of triples attached to the node being validated. |
|
||||||
*/ |
|
||||||
export interface TripleConstraint extends tripleExprBase { |
|
||||||
/** |
|
||||||
* Mandatory type "TripleConstraint". |
|
||||||
*/ |
|
||||||
type: "TripleConstraint"; |
|
||||||
/** |
|
||||||
* If false, the TripleConstraint matches the a triple composed of a focus node, the {@link predicate} and an object matching the (optional) {@link shapeExpr}. |
|
||||||
* If true, the TripleConstraint matches the a triple composed of a subject matching the (optional) {@link shapeExpr}, the {@link predicate} and focus node. |
|
||||||
*/ |
|
||||||
inverse?: BOOL | undefined; |
|
||||||
/** |
|
||||||
* The predicate expected in a matching <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-triple">RDF Triple</a>. |
|
||||||
*/ |
|
||||||
predicate: IRIREF; |
|
||||||
/** |
|
||||||
* A {@link shapeExpr} matching a conformant <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-triple">RDF Triple</a>s subject or object, depending on the value of {@link inverse}. |
|
||||||
*/ |
|
||||||
valueExpr?: shapeExprOrRef | undefined; |
|
||||||
/** |
|
||||||
* The property name used for creating the JSON object. |
|
||||||
*/ |
|
||||||
readablePredicate: string; |
|
||||||
} |
|
||||||
/** |
|
||||||
* A reference a triple expression. |
|
||||||
* The reference is an <a href="https://www.w3.org/TR/json-ld11/#node-identifiers">IRI</a> or a <a href="https://www.w3.org/TR/json-ld11/#identifying-blank-nodes">BlankNode</a> |
|
||||||
* as expressed in <a href="https://www.w3.org/TR/json-ld11/">JSON-LD 1.1</a>. |
|
||||||
*/ |
|
||||||
export type tripleExprRef = tripleExprLabel; |
|
||||||
/** |
|
||||||
* An identifier for a triple expression. |
|
||||||
* The identifier is an <a href="https://www.w3.org/TR/json-ld11/#node-identifiers">IRI</a> or a <a href="https://www.w3.org/TR/json-ld11/#identifying-blank-nodes">BlankNode</a> |
|
||||||
* as expressed in <a href="https://www.w3.org/TR/json-ld11/">JSON-LD 1.1</a>. |
|
||||||
*/ |
|
||||||
export type tripleExprLabel = IRIREF | BNODE; |
|
||||||
/** |
|
||||||
* An extension point for Shape Expressions allowing external code to be invoked during validation. |
|
||||||
*/ |
|
||||||
export interface SemAct { |
|
||||||
/** |
|
||||||
* Mandatory type "SemAct". |
|
||||||
*/ |
|
||||||
type: "SemAct"; |
|
||||||
name: IRIREF; |
|
||||||
code?: STRING | undefined; |
|
||||||
} |
|
||||||
/** |
|
||||||
* An assertion about some part of a ShEx schema which has no affect on conformance checking. |
|
||||||
* These can be useful for documentation, provenance tracking, form generation, etch. |
|
||||||
*/ |
|
||||||
export interface Annotation { |
|
||||||
/** |
|
||||||
* Mandatory type "Annotation". |
|
||||||
*/ |
|
||||||
type: "Annotation"; |
|
||||||
/** |
|
||||||
* The <a href="https://www.w3.org/TR/json-ld11/#node-identifiers">RDF Predicate</a> of the annotation. |
|
||||||
*/ |
|
||||||
predicate: IRI; |
|
||||||
/** |
|
||||||
* A value for the above {@link predicate}. |
|
||||||
*/ |
|
||||||
object: objectValue; |
|
||||||
} |
|
||||||
export type IRIREF = string; |
|
||||||
export type BNODE = string; |
|
||||||
export type INTEGER = number; |
|
||||||
export type STRING = string; |
|
||||||
export type DECIMAL = number; |
|
||||||
export type DOUBLE = number; |
|
||||||
export type LANGTAG = string; |
|
||||||
export type BOOL = boolean; |
|
||||||
export type IRI = string; |
|
||||||
//# sourceMappingURL=ShexJTypes.d.ts.map
|
|
||||||
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@ |
|||||||
export {}; |
|
||||||
@ -1,8 +0,0 @@ |
|||||||
interface BuildOptions { |
|
||||||
input: string; |
|
||||||
output: string; |
|
||||||
baseIRI?: string; |
|
||||||
} |
|
||||||
export declare function build({ input: inputFile, output: outputFile, baseIRI, }: BuildOptions): Promise<void>; |
|
||||||
export {}; |
|
||||||
//# sourceMappingURL=build.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAiBA,UAAU,YAAY;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,KAAK,CAAC,EACxB,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,UAAU,EAClB,OAAyC,GAC5C,EAAE,YAAY,iBAmEd"} |
|
||||||
@ -1,62 +0,0 @@ |
|||||||
import fs from "fs-extra"; |
|
||||||
import path from "path"; |
|
||||||
import parser from "@shexjs/parser"; |
|
||||||
import { shexJConverter } from "./schema-converter/converter.js"; |
|
||||||
import { renderFile } from "ejs"; |
|
||||||
import prettier from "prettier"; |
|
||||||
import loading from "loading-cli"; |
|
||||||
import { dirname } from "node:path"; |
|
||||||
import { fileURLToPath } from "node:url"; |
|
||||||
import { forAllShapes } from "./util/forAllShapes.js"; |
|
||||||
import annotateReadablePredicates from "./schema-converter/util/annotateReadablePredicates.js"; |
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url)); |
|
||||||
export async function build({ input: inputFile, output: outputFile, baseIRI = "https://nextgraph.org/shapes#", }) { |
|
||||||
const load = loading("Preparing Environment"); |
|
||||||
load.start(); |
|
||||||
// Prepare new folder by clearing/and/or creating it
|
|
||||||
if (fs.existsSync(outputFile)) { |
|
||||||
await fs.promises.rm(outputFile, { recursive: true }); |
|
||||||
} |
|
||||||
await fs.promises.mkdir(outputFile); |
|
||||||
const fileTemplates = []; |
|
||||||
// Pre-annotate schema with readablePredicate to unify naming across outputs
|
|
||||||
fileTemplates.push("schema", "typings", "shapeTypes"); |
|
||||||
load.text = "Generating Schema Documents"; |
|
||||||
await forAllShapes(inputFile, async (fileName, shexC) => { |
|
||||||
// Convert to ShexJ
|
|
||||||
let schema; |
|
||||||
try { |
|
||||||
// Prase Shex schema to JSON.
|
|
||||||
// TODO: Do we need the base IRI?
|
|
||||||
// @ts-ignore ...
|
|
||||||
schema = parser.construct(baseIRI).parse(shexC); |
|
||||||
} |
|
||||||
catch (err) { |
|
||||||
const errMessage = err instanceof Error |
|
||||||
? err.message |
|
||||||
: typeof err === "string" |
|
||||||
? err |
|
||||||
: "Unknown Error"; |
|
||||||
console.error(`Error processing ${fileName}: ${errMessage}`); |
|
||||||
return; |
|
||||||
} |
|
||||||
// Add readable predicates to schema as the single source of truth.
|
|
||||||
// @ts-ignore ...
|
|
||||||
annotateReadablePredicates(schema); |
|
||||||
const [typings, compactSchema] = await shexJConverter(schema); |
|
||||||
await Promise.all(fileTemplates.map(async (templateName) => { |
|
||||||
const finalContent = await renderFile(path.join(__dirname, "schema-converter", "templates", `${templateName}.ejs`), { |
|
||||||
typings: typings.typings, |
|
||||||
fileName, |
|
||||||
schema: JSON.stringify(schema, null, 2), |
|
||||||
compactSchema: JSON.stringify(compactSchema, null, 2), |
|
||||||
}); |
|
||||||
await fs.promises.writeFile(path.join(outputFile, `${fileName}.${templateName}.ts`), await prettier.format(finalContent, { |
|
||||||
parser: "typescript", |
|
||||||
})); |
|
||||||
})); |
|
||||||
}); |
|
||||||
load.stop(); |
|
||||||
} |
|
||||||
@ -1,3 +0,0 @@ |
|||||||
#!/usr/bin/env node |
|
||||||
export {}; |
|
||||||
//# sourceMappingURL=cli.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""} |
|
||||||
@ -1,15 +0,0 @@ |
|||||||
#!/usr/bin/env node
|
|
||||||
import { program } from "commander"; |
|
||||||
import { build } from "./build.js"; |
|
||||||
program |
|
||||||
.name("NG-ORM") |
|
||||||
.description("CLI to some JavaScript string utilities") |
|
||||||
.version("0.1.0"); |
|
||||||
program |
|
||||||
.command("build") |
|
||||||
.description("Build contents of a shex folder into Shape Types") |
|
||||||
.option("-i, --input <inputPath>", "Provide the input path", "./.shapes") |
|
||||||
.option("-o, --output <outputPath>", "Provide the output path", "./.orm") |
|
||||||
.option("-b, --baseIRI <baseIri>", "The base IRI for anonymous shapes", "https://nextgraph.org/shapes#") |
|
||||||
.action(build); |
|
||||||
program.parse(); |
|
||||||
@ -1,2 +0,0 @@ |
|||||||
export * from "../src/types.ts"; |
|
||||||
//# sourceMappingURL=index.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"} |
|
||||||
@ -1 +0,0 @@ |
|||||||
export * from "./types.js"; |
|
||||||
@ -1,12 +0,0 @@ |
|||||||
import type { Schema } from "@ldo/traverser-shexj"; |
|
||||||
import * as dom from "dts-dom"; |
|
||||||
import type { Schema as ShapeSchema } from "../types.ts"; |
|
||||||
export interface TypingReturn { |
|
||||||
typingsString: string; |
|
||||||
typings: { |
|
||||||
typingString: string; |
|
||||||
dts: dom.TopLevelDeclaration; |
|
||||||
}[]; |
|
||||||
} |
|
||||||
export declare function shexJConverter(shexj: Schema): Promise<[TypingReturn, ShapeSchema]>; |
|
||||||
//# sourceMappingURL=converter.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"converter.d.ts","sourceRoot":"","sources":["../../src/schema-converter/converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,KAAK,GAAG,MAAM,SAAS,CAAC;AAM/B,OAAO,KAAK,EAAE,MAAM,IAAI,WAAW,EAAS,MAAM,aAAa,CAAC;AAEhE,MAAM,WAAW,YAAY;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,GAAG,EAAE,GAAG,CAAC,mBAAmB,CAAC;KAChC,EAAE,CAAC;CACP;AAED,wBAAsB,cAAc,CAChC,KAAK,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAkDtC"} |
|
||||||
@ -1,69 +0,0 @@ |
|||||||
import { jsonld2graphobject } from "jsonld2graphobject"; |
|
||||||
import * as dom from "dts-dom"; |
|
||||||
import { ShexJTypingTransformerCompact, additionalCompactEnumAliases, } from "./transformers/ShexJTypingTransformer.js"; |
|
||||||
import { ShexJSchemaTransformerCompact } from "./transformers/ShexJSchemaTransformer.js"; |
|
||||||
export async function shexJConverter(shexj) { |
|
||||||
// Prepare processed schema (names still rely on context visitor)
|
|
||||||
const processedShexj = (await jsonld2graphobject({ |
|
||||||
...shexj, |
|
||||||
"@id": "SCHEMA", |
|
||||||
"@context": "http://www.w3.org/ns/shex.jsonld", |
|
||||||
}, "SCHEMA")); |
|
||||||
additionalCompactEnumAliases.clear(); |
|
||||||
const declarations = await ShexJTypingTransformerCompact.transform(processedShexj, "Schema", null); |
|
||||||
const compactSchemaShapesUnflattened = await ShexJSchemaTransformerCompact.transform(processedShexj, "Schema", null); |
|
||||||
const compactSchema = flattenSchema(compactSchemaShapesUnflattened); |
|
||||||
// Append only enum aliases (no interface Id aliases in compact format now)
|
|
||||||
const hasName = (d) => typeof d.name === "string"; |
|
||||||
additionalCompactEnumAliases.forEach((alias) => { |
|
||||||
const exists = declarations.some((d) => hasName(d) && d.name === alias); |
|
||||||
if (!exists) |
|
||||||
declarations.push(dom.create.alias(alias, dom.create.namedTypeReference("IRI"))); |
|
||||||
}); |
|
||||||
const typings = declarations.map((declaration) => ({ |
|
||||||
typingString: dom |
|
||||||
.emit(declaration, { |
|
||||||
rootFlags: dom.ContextFlags.InAmbientNamespace, |
|
||||||
}) |
|
||||||
.replace(/\r\n/g, "\n"), |
|
||||||
dts: declaration, |
|
||||||
})); |
|
||||||
const header = `export type IRI = string;\n\n`; |
|
||||||
const typingsString = header + typings.map((t) => `export ${t.typingString}`).join(""); |
|
||||||
return [{ typingsString, typings }, compactSchema]; |
|
||||||
} |
|
||||||
/** Shapes may be nested. Put all to their root and give nested ones ids. */ |
|
||||||
function flattenSchema(shapes) { |
|
||||||
let schema = {}; |
|
||||||
for (const shape of shapes) { |
|
||||||
schema[shape.iri] = shape; |
|
||||||
// Find nested, unflattened (i.e. anonymous) schemas in predicates' dataTypes.
|
|
||||||
for (const pred of shape.predicates) { |
|
||||||
for (let i = 0; i < pred.dataTypes.length; i++) { |
|
||||||
const dt = pred.dataTypes[i]; |
|
||||||
if (dt.valType === "shape" && |
|
||||||
typeof dt.shape === "object" && |
|
||||||
dt.shape !== null) { |
|
||||||
// create a deterministic id for the nested shape; include index if multiple shape entries exist
|
|
||||||
const shapeCount = pred.dataTypes.filter((d) => d.valType === "shape").length; |
|
||||||
const newId = shape.iri + |
|
||||||
"||" + |
|
||||||
pred.iri + |
|
||||||
(shapeCount > 1 ? `||${i}` : ""); |
|
||||||
// Recurse
|
|
||||||
const flattened = flattenSchema([ |
|
||||||
{ |
|
||||||
...dt.shape, |
|
||||||
iri: newId, |
|
||||||
}, |
|
||||||
]); |
|
||||||
// Replace the nested schema with its new id.
|
|
||||||
dt.shape = newId; |
|
||||||
schema = { ...schema, ...flattened }; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
// Flatten / Recurse
|
|
||||||
} |
|
||||||
return schema; |
|
||||||
} |
|
||||||
@ -1,8 +0,0 @@ |
|||||||
import type { Schema } from "@ng-org/shex-orm"; |
|
||||||
|
|
||||||
/** |
|
||||||
* ============================================================================= |
|
||||||
* <%- fileName %>Schema: Schema for <%- fileName %> |
|
||||||
* ============================================================================= |
|
||||||
*/ |
|
||||||
export const <%- fileName %>Schema: Schema = <%- compactSchema %>; |
|
||||||
@ -1,14 +0,0 @@ |
|||||||
import type { ShapeType } from "@ng-org/shex-orm"; |
|
||||||
import { <%- fileName %>Schema } from "./<%- fileName %>.schema"; |
|
||||||
import type { |
|
||||||
<% typings.forEach((typing)=> { if (!/Id$/.test(typing.dts.name)) { -%> |
|
||||||
<%- typing.dts.name %>, |
|
||||||
<% } }); -%>} from "./<%- fileName %>.typings"; |
|
||||||
|
|
||||||
// ShapeTypes for <%- fileName %> |
|
||||||
<% typings.forEach((typing)=> { if (!/Id$/.test(typing.dts.name)) { -%> |
|
||||||
export const <%- typing.dts.name %>ShapeType: ShapeType<<%- typing.dts.name %>> = { |
|
||||||
schema: <%- fileName %>Schema, |
|
||||||
shape: "<%- typing.dts.shapeId %>", |
|
||||||
}; |
|
||||||
<% } }); -%> |
|
||||||
@ -1,14 +0,0 @@ |
|||||||
export type IRI = string; |
|
||||||
|
|
||||||
/** |
|
||||||
* ============================================================================= |
|
||||||
* Typescript Typings for <%- fileName %> |
|
||||||
* ============================================================================= |
|
||||||
*/ |
|
||||||
|
|
||||||
<% typings.forEach((typing)=> { -%> |
|
||||||
/** |
|
||||||
* <%- typing.dts.name %> Type |
|
||||||
*/ |
|
||||||
export <%- typing.typingString -%> |
|
||||||
<% }); -%> |
|
||||||
@ -1,348 +0,0 @@ |
|||||||
import type { Predicate, DataType, Shape } from "../../types.ts"; |
|
||||||
export declare const ShexJSchemaTransformerCompact: import("@ldo/type-traverser").Transformer<{ |
|
||||||
Schema: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").Schema; |
|
||||||
properties: { |
|
||||||
startActs: "SemAct"; |
|
||||||
start: "shapeExprOrRef"; |
|
||||||
imports: "IRIREF"; |
|
||||||
shapes: "ShapeDecl"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
ShapeDecl: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ShapeDecl; |
|
||||||
properties: { |
|
||||||
id: "shapeDeclLabel"; |
|
||||||
abstract: "BOOL"; |
|
||||||
restricts: "shapeExprOrRef"; |
|
||||||
shapeExpr: "shapeExpr"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
shapeExpr: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").shapeExpr; |
|
||||||
typeNames: "ShapeOr" | "ShapeAnd" | "ShapeNot" | "NodeConstraint" | "Shape" | "ShapeExternal"; |
|
||||||
}; |
|
||||||
shapeExprOrRef: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").shapeExprOrRef; |
|
||||||
typeNames: "shapeExpr" | "shapeDeclRef"; |
|
||||||
}; |
|
||||||
ShapeOr: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ShapeOr; |
|
||||||
properties: { |
|
||||||
shapeExprs: "shapeExprOrRef"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
ShapeAnd: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ShapeAnd; |
|
||||||
properties: { |
|
||||||
shapeExprs: "shapeExprOrRef"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
ShapeNot: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ShapeNot; |
|
||||||
properties: { |
|
||||||
shapeExpr: "shapeExprOrRef"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
ShapeExternal: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ShapeExternal; |
|
||||||
properties: Record<string, never>; |
|
||||||
}; |
|
||||||
shapeDeclRef: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").shapeDeclRef; |
|
||||||
typeNames: "shapeDeclLabel" | "ShapeDecl"; |
|
||||||
}; |
|
||||||
shapeDeclLabel: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").shapeDeclLabel; |
|
||||||
typeNames: "IRIREF" | "BNODE"; |
|
||||||
}; |
|
||||||
NodeConstraint: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").NodeConstraint; |
|
||||||
properties: { |
|
||||||
datatype: "IRIREF"; |
|
||||||
values: "valueSetValue"; |
|
||||||
length: "INTEGER"; |
|
||||||
minlength: "INTEGER"; |
|
||||||
maxlength: "INTEGER"; |
|
||||||
pattern: "STRING"; |
|
||||||
flags: "STRING"; |
|
||||||
mininclusive: "numericLiteral"; |
|
||||||
minexclusive: "numericLiteral"; |
|
||||||
totaldigits: "INTEGER"; |
|
||||||
fractiondigits: "INTEGER"; |
|
||||||
semActs: "SemAct"; |
|
||||||
annotations: "Annotation"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
numericLiteral: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").numericLiteral; |
|
||||||
typeNames: "INTEGER" | "DECIMAL" | "DOUBLE"; |
|
||||||
}; |
|
||||||
valueSetValue: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").valueSetValue; |
|
||||||
typeNames: "objectValue" | "IriStem" | "IriStemRange" | "LiteralStem" | "LiteralStemRange" | "Language" | "LanguageStem" | "LanguageStemRange"; |
|
||||||
}; |
|
||||||
objectValue: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").objectValue; |
|
||||||
typeNames: "IRIREF" | "ObjectLiteral"; |
|
||||||
}; |
|
||||||
ObjectLiteral: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ObjectLiteral; |
|
||||||
properties: { |
|
||||||
value: "STRING"; |
|
||||||
language: "STRING"; |
|
||||||
type: "STRING"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
IriStem: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").IriStem; |
|
||||||
properties: { |
|
||||||
stem: "IRIREF"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
IriStemRange: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").IriStemRange; |
|
||||||
properties: { |
|
||||||
stem: "IRIREF"; |
|
||||||
exclusions: "IriStemRangeExclusions"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
IriStemRangeExclusions: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").IRIREF | import("@ldo/traverser-shexj").IriStem; |
|
||||||
typeNames: "IRIREF" | "IriStem"; |
|
||||||
}; |
|
||||||
LiteralStem: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").LiteralStem; |
|
||||||
properties: { |
|
||||||
stem: "STRING"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
LiteralStemRange: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").LiteralStemRange; |
|
||||||
properties: { |
|
||||||
stem: "LiteralStemRangeStem"; |
|
||||||
exclusions: "LiteralStemRangeExclusions"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
LiteralStemRangeStem: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").STRING | import("@ldo/traverser-shexj").Wildcard; |
|
||||||
typeNames: "STRING" | "Wildcard"; |
|
||||||
}; |
|
||||||
LiteralStemRangeExclusions: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").STRING | import("@ldo/traverser-shexj").LiteralStem; |
|
||||||
typeNames: "STRING" | "LiteralStem"; |
|
||||||
}; |
|
||||||
Language: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").Language; |
|
||||||
properties: { |
|
||||||
languageTag: "LANGTAG"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
LanguageStem: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").LanguageStem; |
|
||||||
properties: { |
|
||||||
stem: "LANGTAG"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
LanguageStemRange: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").LanguageStemRange; |
|
||||||
properties: { |
|
||||||
stem: "LanguageStemRangeStem"; |
|
||||||
exclusions: "LanguageStemRangeExclusions"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
LanguageStemRangeStem: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").LANGTAG | import("@ldo/traverser-shexj").Wildcard; |
|
||||||
typeNames: "LANGTAG" | "Wildcard"; |
|
||||||
}; |
|
||||||
LanguageStemRangeExclusions: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").LANGTAG | import("@ldo/traverser-shexj").LanguageStem; |
|
||||||
typeNames: "LANGTAG" | "LanguageStem"; |
|
||||||
}; |
|
||||||
Wildcard: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").Wildcard; |
|
||||||
properties: Record<string, never>; |
|
||||||
}; |
|
||||||
Shape: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").Shape; |
|
||||||
properties: { |
|
||||||
closed: "BOOL"; |
|
||||||
extra: "IRIREF"; |
|
||||||
extends: "shapeExprOrRef"; |
|
||||||
expression: "tripleExprOrRef"; |
|
||||||
semActs: "SemAct"; |
|
||||||
annotations: "Annotation"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
tripleExpr: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").tripleExpr; |
|
||||||
typeNames: "EachOf" | "OneOf" | "TripleConstraint"; |
|
||||||
}; |
|
||||||
tripleExprOrRef: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").tripleExprOrRef; |
|
||||||
typeNames: "tripleExpr" | "tripleExprRef"; |
|
||||||
}; |
|
||||||
EachOf: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").EachOf; |
|
||||||
properties: { |
|
||||||
id: "tripleExprLabel"; |
|
||||||
min: "INTEGER"; |
|
||||||
max: "INTEGER"; |
|
||||||
expressions: "tripleExprOrRef"; |
|
||||||
semActs: "SemAct"; |
|
||||||
annotations: "Annotation"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
OneOf: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").OneOf; |
|
||||||
properties: { |
|
||||||
id: "tripleExprLabel"; |
|
||||||
min: "INTEGER"; |
|
||||||
max: "INTEGER"; |
|
||||||
expressions: "tripleExprOrRef"; |
|
||||||
semActs: "SemAct"; |
|
||||||
annotations: "Annotation"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
TripleConstraint: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").TripleConstraint; |
|
||||||
properties: { |
|
||||||
id: "tripleExprLabel"; |
|
||||||
min: "INTEGER"; |
|
||||||
max: "INTEGER"; |
|
||||||
inverse: "BOOL"; |
|
||||||
predicate: "IRIREF"; |
|
||||||
valueExpr: "shapeExprOrRef"; |
|
||||||
semActs: "SemAct"; |
|
||||||
annotations: "Annotation"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
tripleExprRef: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").tripleExprRef; |
|
||||||
typeNames: "tripleExprLabel"; |
|
||||||
}; |
|
||||||
tripleExprLabel: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").tripleExprLabel; |
|
||||||
typeNames: "IRIREF" | "BNODE"; |
|
||||||
}; |
|
||||||
SemAct: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").SemAct; |
|
||||||
properties: { |
|
||||||
name: "IRIREF"; |
|
||||||
code: "STRING"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
Annotation: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").Annotation; |
|
||||||
properties: { |
|
||||||
predicate: "IRI"; |
|
||||||
object: "objectValue"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
IRIREF: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").IRIREF; |
|
||||||
}; |
|
||||||
BNODE: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").BNODE; |
|
||||||
}; |
|
||||||
INTEGER: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").INTEGER; |
|
||||||
}; |
|
||||||
STRING: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").STRING; |
|
||||||
}; |
|
||||||
DECIMAL: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").DECIMAL; |
|
||||||
}; |
|
||||||
DOUBLE: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").DOUBLE; |
|
||||||
}; |
|
||||||
LANGTAG: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").LANGTAG; |
|
||||||
}; |
|
||||||
BOOL: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").BOOL; |
|
||||||
}; |
|
||||||
IRI: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").IRI; |
|
||||||
}; |
|
||||||
}, { |
|
||||||
Schema: { |
|
||||||
return: Shape[]; |
|
||||||
}; |
|
||||||
ShapeDecl: { |
|
||||||
return: Shape; |
|
||||||
}; |
|
||||||
Shape: { |
|
||||||
return: Shape; |
|
||||||
}; |
|
||||||
EachOf: { |
|
||||||
return: Shape; |
|
||||||
}; |
|
||||||
TripleConstraint: { |
|
||||||
return: Predicate; |
|
||||||
}; |
|
||||||
NodeConstraint: { |
|
||||||
return: DataType; |
|
||||||
}; |
|
||||||
ShapeOr: { |
|
||||||
return: DataType[]; |
|
||||||
}; |
|
||||||
ShapeAnd: { |
|
||||||
return: never; |
|
||||||
}; |
|
||||||
ShapeNot: { |
|
||||||
return: never; |
|
||||||
}; |
|
||||||
ShapeExternal: { |
|
||||||
return: never; |
|
||||||
}; |
|
||||||
}, null>; |
|
||||||
//# sourceMappingURL=ShexJSchemaTransformer.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"ShexJSchemaTransformer.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/transformers/ShexJSchemaTransformer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AA0DjE,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAE1B;QAAE,MAAM,EAAE,KAAK,EAAE,CAAA;KAAE;eAChB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;WACrB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;YAChB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;sBACP;QAAE,MAAM,EAAE,SAAS,CAAA;KAAE;oBACvB;QAAE,MAAM,EAAE,QAAQ,CAAA;KAAE;aAC3B;QAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;KAAE;cACrB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;cACjB;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;mBACZ;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;QAqLtC,CAAC"} |
|
||||||
@ -1,208 +0,0 @@ |
|||||||
import ShexJTraverser from "@ldo/traverser-shexj"; |
|
||||||
const rdfDataTypeToBasic = (dataType) => { |
|
||||||
switch (dataType) { |
|
||||||
case "http://www.w3.org/2001/XMLSchema#string": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#ENTITIES": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#ENTITY": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#ID": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#IDREF": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#IDREFS": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#language": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#Name": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#NCName": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#NMTOKEN": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#NMTOKENS": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#normalizedString": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#QName": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#token": |
|
||||||
return "string"; |
|
||||||
case "http://www.w3.org/2001/XMLSchema#date": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#dateTime": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#duration": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#gDay": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#gMonth": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#gMonthDay": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#gYear": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#gYearMonth": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#time": |
|
||||||
return "string"; |
|
||||||
case "http://www.w3.org/2001/XMLSchema#byte": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#decimal": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#double": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#float": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#int": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#integer": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#long": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#negativeInteger": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#nonNegativeInteger": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#nonPositiveInteger": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#positiveInteger": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#short": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#unsignedLong": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#unsignedInt": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#unsignedShort": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#unsignedByte": |
|
||||||
return "number"; |
|
||||||
case "http://www.w3.org/2001/XMLSchema#boolean": |
|
||||||
return "boolean"; |
|
||||||
case "http://www.w3.org/2001/XMLSchema#hexBinary": |
|
||||||
return "string"; |
|
||||||
case "http://www.w3.org/2001/XMLSchema#anyURI": |
|
||||||
return "iri"; |
|
||||||
default: |
|
||||||
return "string"; |
|
||||||
} |
|
||||||
}; |
|
||||||
export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer({ |
|
||||||
Schema: { |
|
||||||
transformer: async (_schema, getTransformedChildren) => { |
|
||||||
const transformedChildren = await getTransformedChildren(); |
|
||||||
return transformedChildren.shapes || []; |
|
||||||
}, |
|
||||||
}, |
|
||||||
ShapeDecl: { |
|
||||||
transformer: async (shapeDecl, getTransformedChildren) => { |
|
||||||
const schema = await getTransformedChildren(); |
|
||||||
const shape = schema.shapeExpr; |
|
||||||
return { ...shape, iri: shapeDecl.id }; |
|
||||||
}, |
|
||||||
}, |
|
||||||
Shape: { |
|
||||||
transformer: async (_shape, getTransformedChildren) => { |
|
||||||
// TODO: We don't handles those
|
|
||||||
_shape.closed; |
|
||||||
const transformedChildren = await getTransformedChildren(); |
|
||||||
const compactShape = transformedChildren.expression; |
|
||||||
for (const extra of _shape.extra || []) { |
|
||||||
const extraPredicate = compactShape.predicates.find((p) => p.iri === extra); |
|
||||||
if (extraPredicate) |
|
||||||
extraPredicate.extra = true; |
|
||||||
} |
|
||||||
return compactShape; |
|
||||||
}, |
|
||||||
}, |
|
||||||
// EachOf contains the `expressions` array of properties (TripleConstraint)
|
|
||||||
EachOf: { |
|
||||||
transformer: async (eachOf, getTransformedChildren) => { |
|
||||||
const transformedChildren = await getTransformedChildren(); |
|
||||||
return { |
|
||||||
iri: "", |
|
||||||
predicates: transformedChildren.expressions.map( |
|
||||||
// We disregard cases where properties are referenced (strings)
|
|
||||||
// or where they consist of Unions or Intersections (not supported).
|
|
||||||
(expr) => expr), |
|
||||||
}; |
|
||||||
}, |
|
||||||
}, |
|
||||||
TripleConstraint: { |
|
||||||
transformer: async (tripleConstraint, getTransformedChildren, _setReturnPointer) => { |
|
||||||
const transformedChildren = await getTransformedChildren(); |
|
||||||
const commonProperties = { |
|
||||||
maxCardinality: tripleConstraint.max ?? 1, |
|
||||||
minCardinality: tripleConstraint.min ?? 1, |
|
||||||
iri: tripleConstraint.predicate, |
|
||||||
// @ts-expect-error The ldo library does not have our modded readablePredicate property.
|
|
||||||
readablePredicate: tripleConstraint.readablePredicate, |
|
||||||
}; |
|
||||||
// Make property based on object type which is either a parsed schema, literal or type.
|
|
||||||
if (typeof transformedChildren.valueExpr === "string") { |
|
||||||
// Reference to nested object
|
|
||||||
return { |
|
||||||
dataTypes: [ |
|
||||||
{ |
|
||||||
valType: "shape", |
|
||||||
shape: transformedChildren.valueExpr, |
|
||||||
}, |
|
||||||
], |
|
||||||
...commonProperties, |
|
||||||
}; |
|
||||||
} |
|
||||||
else if (transformedChildren.valueExpr && |
|
||||||
transformedChildren.valueExpr.predicates) { |
|
||||||
// Nested object
|
|
||||||
return { |
|
||||||
dataTypes: [ |
|
||||||
{ |
|
||||||
valType: "shape", |
|
||||||
shape: transformedChildren.valueExpr, |
|
||||||
}, |
|
||||||
], |
|
||||||
...commonProperties, |
|
||||||
}; |
|
||||||
} |
|
||||||
else if (Array.isArray(transformedChildren.valueExpr)) { |
|
||||||
return { |
|
||||||
dataTypes: transformedChildren.valueExpr, // DataType[]
|
|
||||||
...commonProperties, |
|
||||||
}; |
|
||||||
} |
|
||||||
else { |
|
||||||
// type or literal
|
|
||||||
const nodeConstraint = transformedChildren.valueExpr; |
|
||||||
return { |
|
||||||
dataTypes: [ |
|
||||||
{ |
|
||||||
valType: nodeConstraint.valType, |
|
||||||
literals: nodeConstraint.literals, |
|
||||||
}, |
|
||||||
], |
|
||||||
...commonProperties, |
|
||||||
}; |
|
||||||
} |
|
||||||
}, |
|
||||||
}, |
|
||||||
NodeConstraint: { |
|
||||||
transformer: async (nodeConstraint) => { |
|
||||||
if (nodeConstraint.datatype) { |
|
||||||
return { |
|
||||||
valType: rdfDataTypeToBasic(nodeConstraint.datatype), |
|
||||||
}; |
|
||||||
} |
|
||||||
if (nodeConstraint.nodeKind) { |
|
||||||
// Something reference-like.
|
|
||||||
return { valType: "iri" }; |
|
||||||
} |
|
||||||
if (nodeConstraint.values) { |
|
||||||
return { |
|
||||||
valType: "literal", |
|
||||||
literals: nodeConstraint.values.map( |
|
||||||
// TODO: We do not convert them to number or boolean or lang tag.
|
|
||||||
// And we don't have an annotation of the literal's type.
|
|
||||||
// @ts-expect-error
|
|
||||||
(valueRecord) => valueRecord.value || valueRecord.id), |
|
||||||
}; |
|
||||||
} |
|
||||||
// Maybe we should throw instead...
|
|
||||||
throw { |
|
||||||
error: new Error("Could not parse Node Constraint"), |
|
||||||
nodeConstraint, |
|
||||||
}; |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from ShapeOr
|
|
||||||
ShapeOr: { |
|
||||||
transformer: async (shapeOr, getTransformedChildren) => { |
|
||||||
const { shapeExprs } = await getTransformedChildren(); |
|
||||||
// Either a shape IRI, a nested shape or a node CompactSchemaValue (node constraint).
|
|
||||||
return (Array.isArray(shapeExprs) ? shapeExprs : [shapeExprs]); |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from ShapeAnd
|
|
||||||
ShapeAnd: { |
|
||||||
transformer: async () => { |
|
||||||
throw new Error("ShapeAnd not supported (compact)"); |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from ShapeNot - not supported.
|
|
||||||
ShapeNot: { |
|
||||||
transformer: async () => { |
|
||||||
throw new Error("ShapeNot not supported (compact)"); |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from ShapeExternal - not supported.
|
|
||||||
ShapeExternal: { |
|
||||||
transformer: async () => { |
|
||||||
throw new Error("ShapeExternal not supported (compact)"); |
|
||||||
}, |
|
||||||
}, |
|
||||||
}); |
|
||||||
@ -1,366 +0,0 @@ |
|||||||
import type { Annotation } from "shexj"; |
|
||||||
import * as dom from "dts-dom"; |
|
||||||
import type { InterfaceDeclaration } from "dts-dom"; |
|
||||||
export interface ShapeInterfaceDeclaration extends InterfaceDeclaration { |
|
||||||
shapeId?: string; |
|
||||||
} |
|
||||||
export declare const additionalCompactEnumAliases: Set<string>; |
|
||||||
export interface CompactTransformerContext { |
|
||||||
getNameFromIri: (iri: string, rdfType?: string) => string; |
|
||||||
} |
|
||||||
export declare function toCamelCase(text: string): string; |
|
||||||
/** |
|
||||||
* Name functions |
|
||||||
*/ |
|
||||||
export declare function iriToName(iri: string): string; |
|
||||||
export declare function nameFromAnnotationOrId(obj: { |
|
||||||
id?: string; |
|
||||||
annotations?: Annotation[]; |
|
||||||
}): string | undefined; |
|
||||||
export declare const ShexJTypingTransformerCompact: import("@ldo/type-traverser").Transformer<{ |
|
||||||
Schema: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").Schema; |
|
||||||
properties: { |
|
||||||
startActs: "SemAct"; |
|
||||||
start: "shapeExprOrRef"; |
|
||||||
imports: "IRIREF"; |
|
||||||
shapes: "ShapeDecl"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
ShapeDecl: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ShapeDecl; |
|
||||||
properties: { |
|
||||||
id: "shapeDeclLabel"; |
|
||||||
abstract: "BOOL"; |
|
||||||
restricts: "shapeExprOrRef"; |
|
||||||
shapeExpr: "shapeExpr"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
shapeExpr: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").shapeExpr; |
|
||||||
typeNames: "ShapeOr" | "ShapeAnd" | "ShapeNot" | "NodeConstraint" | "Shape" | "ShapeExternal"; |
|
||||||
}; |
|
||||||
shapeExprOrRef: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").shapeExprOrRef; |
|
||||||
typeNames: "shapeExpr" | "shapeDeclRef"; |
|
||||||
}; |
|
||||||
ShapeOr: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ShapeOr; |
|
||||||
properties: { |
|
||||||
shapeExprs: "shapeExprOrRef"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
ShapeAnd: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ShapeAnd; |
|
||||||
properties: { |
|
||||||
shapeExprs: "shapeExprOrRef"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
ShapeNot: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ShapeNot; |
|
||||||
properties: { |
|
||||||
shapeExpr: "shapeExprOrRef"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
ShapeExternal: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ShapeExternal; |
|
||||||
properties: Record<string, never>; |
|
||||||
}; |
|
||||||
shapeDeclRef: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").shapeDeclRef; |
|
||||||
typeNames: "shapeDeclLabel" | "ShapeDecl"; |
|
||||||
}; |
|
||||||
shapeDeclLabel: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").shapeDeclLabel; |
|
||||||
typeNames: "IRIREF" | "BNODE"; |
|
||||||
}; |
|
||||||
NodeConstraint: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").NodeConstraint; |
|
||||||
properties: { |
|
||||||
datatype: "IRIREF"; |
|
||||||
values: "valueSetValue"; |
|
||||||
length: "INTEGER"; |
|
||||||
minlength: "INTEGER"; |
|
||||||
maxlength: "INTEGER"; |
|
||||||
pattern: "STRING"; |
|
||||||
flags: "STRING"; |
|
||||||
mininclusive: "numericLiteral"; |
|
||||||
minexclusive: "numericLiteral"; |
|
||||||
totaldigits: "INTEGER"; |
|
||||||
fractiondigits: "INTEGER"; |
|
||||||
semActs: "SemAct"; |
|
||||||
annotations: "Annotation"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
numericLiteral: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").numericLiteral; |
|
||||||
typeNames: "INTEGER" | "DECIMAL" | "DOUBLE"; |
|
||||||
}; |
|
||||||
valueSetValue: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").valueSetValue; |
|
||||||
typeNames: "objectValue" | "IriStem" | "IriStemRange" | "LiteralStem" | "LiteralStemRange" | "Language" | "LanguageStem" | "LanguageStemRange"; |
|
||||||
}; |
|
||||||
objectValue: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").objectValue; |
|
||||||
typeNames: "IRIREF" | "ObjectLiteral"; |
|
||||||
}; |
|
||||||
ObjectLiteral: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").ObjectLiteral; |
|
||||||
properties: { |
|
||||||
value: "STRING"; |
|
||||||
language: "STRING"; |
|
||||||
type: "STRING"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
IriStem: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").IriStem; |
|
||||||
properties: { |
|
||||||
stem: "IRIREF"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
IriStemRange: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").IriStemRange; |
|
||||||
properties: { |
|
||||||
stem: "IRIREF"; |
|
||||||
exclusions: "IriStemRangeExclusions"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
IriStemRangeExclusions: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").IRIREF | import("@ldo/traverser-shexj").IriStem; |
|
||||||
typeNames: "IRIREF" | "IriStem"; |
|
||||||
}; |
|
||||||
LiteralStem: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").LiteralStem; |
|
||||||
properties: { |
|
||||||
stem: "STRING"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
LiteralStemRange: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").LiteralStemRange; |
|
||||||
properties: { |
|
||||||
stem: "LiteralStemRangeStem"; |
|
||||||
exclusions: "LiteralStemRangeExclusions"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
LiteralStemRangeStem: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").STRING | import("@ldo/traverser-shexj").Wildcard; |
|
||||||
typeNames: "STRING" | "Wildcard"; |
|
||||||
}; |
|
||||||
LiteralStemRangeExclusions: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").STRING | import("@ldo/traverser-shexj").LiteralStem; |
|
||||||
typeNames: "STRING" | "LiteralStem"; |
|
||||||
}; |
|
||||||
Language: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").Language; |
|
||||||
properties: { |
|
||||||
languageTag: "LANGTAG"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
LanguageStem: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").LanguageStem; |
|
||||||
properties: { |
|
||||||
stem: "LANGTAG"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
LanguageStemRange: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").LanguageStemRange; |
|
||||||
properties: { |
|
||||||
stem: "LanguageStemRangeStem"; |
|
||||||
exclusions: "LanguageStemRangeExclusions"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
LanguageStemRangeStem: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").LANGTAG | import("@ldo/traverser-shexj").Wildcard; |
|
||||||
typeNames: "LANGTAG" | "Wildcard"; |
|
||||||
}; |
|
||||||
LanguageStemRangeExclusions: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").LANGTAG | import("@ldo/traverser-shexj").LanguageStem; |
|
||||||
typeNames: "LANGTAG" | "LanguageStem"; |
|
||||||
}; |
|
||||||
Wildcard: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").Wildcard; |
|
||||||
properties: Record<string, never>; |
|
||||||
}; |
|
||||||
Shape: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").Shape; |
|
||||||
properties: { |
|
||||||
closed: "BOOL"; |
|
||||||
extra: "IRIREF"; |
|
||||||
extends: "shapeExprOrRef"; |
|
||||||
expression: "tripleExprOrRef"; |
|
||||||
semActs: "SemAct"; |
|
||||||
annotations: "Annotation"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
tripleExpr: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").tripleExpr; |
|
||||||
typeNames: "EachOf" | "OneOf" | "TripleConstraint"; |
|
||||||
}; |
|
||||||
tripleExprOrRef: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").tripleExprOrRef; |
|
||||||
typeNames: "tripleExpr" | "tripleExprRef"; |
|
||||||
}; |
|
||||||
EachOf: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").EachOf; |
|
||||||
properties: { |
|
||||||
id: "tripleExprLabel"; |
|
||||||
min: "INTEGER"; |
|
||||||
max: "INTEGER"; |
|
||||||
expressions: "tripleExprOrRef"; |
|
||||||
semActs: "SemAct"; |
|
||||||
annotations: "Annotation"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
OneOf: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").OneOf; |
|
||||||
properties: { |
|
||||||
id: "tripleExprLabel"; |
|
||||||
min: "INTEGER"; |
|
||||||
max: "INTEGER"; |
|
||||||
expressions: "tripleExprOrRef"; |
|
||||||
semActs: "SemAct"; |
|
||||||
annotations: "Annotation"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
TripleConstraint: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").TripleConstraint; |
|
||||||
properties: { |
|
||||||
id: "tripleExprLabel"; |
|
||||||
min: "INTEGER"; |
|
||||||
max: "INTEGER"; |
|
||||||
inverse: "BOOL"; |
|
||||||
predicate: "IRIREF"; |
|
||||||
valueExpr: "shapeExprOrRef"; |
|
||||||
semActs: "SemAct"; |
|
||||||
annotations: "Annotation"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
tripleExprRef: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").tripleExprRef; |
|
||||||
typeNames: "tripleExprLabel"; |
|
||||||
}; |
|
||||||
tripleExprLabel: { |
|
||||||
kind: "union"; |
|
||||||
type: import("@ldo/traverser-shexj").tripleExprLabel; |
|
||||||
typeNames: "IRIREF" | "BNODE"; |
|
||||||
}; |
|
||||||
SemAct: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").SemAct; |
|
||||||
properties: { |
|
||||||
name: "IRIREF"; |
|
||||||
code: "STRING"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
Annotation: { |
|
||||||
kind: "interface"; |
|
||||||
type: import("@ldo/traverser-shexj").Annotation; |
|
||||||
properties: { |
|
||||||
predicate: "IRI"; |
|
||||||
object: "objectValue"; |
|
||||||
}; |
|
||||||
}; |
|
||||||
IRIREF: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").IRIREF; |
|
||||||
}; |
|
||||||
BNODE: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").BNODE; |
|
||||||
}; |
|
||||||
INTEGER: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").INTEGER; |
|
||||||
}; |
|
||||||
STRING: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").STRING; |
|
||||||
}; |
|
||||||
DECIMAL: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").DECIMAL; |
|
||||||
}; |
|
||||||
DOUBLE: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").DOUBLE; |
|
||||||
}; |
|
||||||
LANGTAG: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").LANGTAG; |
|
||||||
}; |
|
||||||
BOOL: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").BOOL; |
|
||||||
}; |
|
||||||
IRI: { |
|
||||||
kind: "primitive"; |
|
||||||
type: import("@ldo/traverser-shexj").IRI; |
|
||||||
}; |
|
||||||
}, { |
|
||||||
Schema: { |
|
||||||
return: dom.TopLevelDeclaration[]; |
|
||||||
}; |
|
||||||
ShapeDecl: { |
|
||||||
return: dom.InterfaceDeclaration; |
|
||||||
}; |
|
||||||
Shape: { |
|
||||||
return: dom.InterfaceDeclaration; |
|
||||||
}; |
|
||||||
EachOf: { |
|
||||||
return: dom.ObjectType | dom.InterfaceDeclaration; |
|
||||||
}; |
|
||||||
TripleConstraint: { |
|
||||||
return: dom.PropertyDeclaration; |
|
||||||
}; |
|
||||||
NodeConstraint: { |
|
||||||
return: dom.Type; |
|
||||||
}; |
|
||||||
ShapeOr: { |
|
||||||
return: dom.UnionType; |
|
||||||
}; |
|
||||||
ShapeAnd: { |
|
||||||
return: dom.IntersectionType; |
|
||||||
}; |
|
||||||
ShapeNot: { |
|
||||||
return: never; |
|
||||||
}; |
|
||||||
ShapeExternal: { |
|
||||||
return: never; |
|
||||||
}; |
|
||||||
}, null>; |
|
||||||
//# sourceMappingURL=ShexJTypingTransformer.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"ShexJTypingTransformer.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/transformers/ShexJTypingTransformer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,GAAG,MAAM,SAAS,CAAC;AAC/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAGD,eAAO,MAAM,4BAA4B,aAAoB,CAAC;AAE9D,MAAM,WAAW,yBAAyB;IACtC,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;CAC7D;AAeD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAOvC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAc7C;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE;IACxC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC9B,GAAG,MAAM,GAAG,SAAS,CAgBrB;AAyMD,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAE1B;QAAE,MAAM,EAAE,GAAG,CAAC,mBAAmB,EAAE,CAAA;KAAE;eAClC;QAAE,MAAM,EAAE,GAAG,CAAC,oBAAoB,CAAA;KAAE;WACxC;QAAE,MAAM,EAAE,GAAG,CAAC,oBAAoB,CAAA;KAAE;YACnC;QAAE,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,oBAAoB,CAAA;KAAE;sBAC3C;QAAE,MAAM,EAAE,GAAG,CAAC,mBAAmB,CAAA;KAAE;oBACrC;QAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAA;KAAE;aAC3B;QAAE,MAAM,EAAE,GAAG,CAAC,SAAS,CAAA;KAAE;cACxB;QAAE,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAA;KAAE;cAChC;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;mBACZ;QAAE,MAAM,EAAE,KAAK,CAAA;KAAE;QAmatC,CAAC"} |
|
||||||
@ -1,550 +0,0 @@ |
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */ |
|
||||||
import ShexJTraverser from "@ldo/traverser-shexj"; |
|
||||||
import * as dom from "dts-dom"; |
|
||||||
// Collected enum alias names (e.g., AuthenticatedAgentId) to emit at end
|
|
||||||
export const additionalCompactEnumAliases = new Set(); |
|
||||||
function commentFromAnnotations(annotations) { |
|
||||||
const commentAnnotationObject = annotations?.find((annotation) => annotation.predicate === |
|
||||||
"http://www.w3.org/2000/01/rdf-schema#comment")?.object; |
|
||||||
if (typeof commentAnnotationObject === "string") |
|
||||||
return commentAnnotationObject; |
|
||||||
return commentAnnotationObject?.value; |
|
||||||
} |
|
||||||
export function toCamelCase(text) { |
|
||||||
return text |
|
||||||
.replace(/([-_ ]){1,}/g, " ") |
|
||||||
.split(/[-_ ]/) |
|
||||||
.reduce((cur, acc) => { |
|
||||||
return cur + acc[0].toUpperCase() + acc.substring(1); |
|
||||||
}); |
|
||||||
} |
|
||||||
/** |
|
||||||
* Name functions |
|
||||||
*/ |
|
||||||
export function iriToName(iri) { |
|
||||||
try { |
|
||||||
const url = new URL(iri); |
|
||||||
let name; |
|
||||||
if (url.hash) { |
|
||||||
name = url.hash.slice(1); |
|
||||||
} |
|
||||||
else { |
|
||||||
const splitPathname = url.pathname.split("/"); |
|
||||||
name = splitPathname[splitPathname.length - 1]; |
|
||||||
} |
|
||||||
return name.replace(/(?<!^)Shape$/, ""); |
|
||||||
} |
|
||||||
catch (err) { |
|
||||||
return iri; |
|
||||||
} |
|
||||||
} |
|
||||||
export function nameFromAnnotationOrId(obj) { |
|
||||||
const labelAnnotationObject = obj.annotations?.find((annotation) => annotation.predicate === |
|
||||||
"http://www.w3.org/2000/01/rdf-schema#label")?.object; |
|
||||||
if (labelAnnotationObject && typeof labelAnnotationObject === "string") { |
|
||||||
return toCamelCase(iriToName(labelAnnotationObject)); |
|
||||||
} |
|
||||||
else if (labelAnnotationObject && |
|
||||||
typeof labelAnnotationObject !== "string") { |
|
||||||
return toCamelCase(labelAnnotationObject.value); |
|
||||||
} |
|
||||||
else if (obj.id) { |
|
||||||
return toCamelCase(iriToName(obj.id)); |
|
||||||
} |
|
||||||
} |
|
||||||
// Helper: classify a dom.Type into categories we care about.
|
|
||||||
function isObjectLike(t) { |
|
||||||
return (t.kind === "object" || |
|
||||||
t.kind === "interface"); |
|
||||||
} |
|
||||||
function isPrimitiveLike(t) { |
|
||||||
const kind = t?.kind; |
|
||||||
if (kind === "name") |
|
||||||
return true; // named references and intrinsic tokens
|
|
||||||
if (kind === "union") { |
|
||||||
return t.members.every(isPrimitiveLike); |
|
||||||
} |
|
||||||
if (kind === "type-parameter") |
|
||||||
return true; |
|
||||||
// Fallback: treat scalar intrinsic tokens as primitive
|
|
||||||
const intrinsicKinds = new Set([ |
|
||||||
"string", |
|
||||||
"number", |
|
||||||
"boolean", |
|
||||||
"undefined", |
|
||||||
]); |
|
||||||
return intrinsicKinds.has(kind || ""); |
|
||||||
} |
|
||||||
// Small helpers for unions and alias naming
|
|
||||||
function isUnionType(t) { |
|
||||||
return t?.kind === "union"; |
|
||||||
} |
|
||||||
function unionOf(types) { |
|
||||||
const flat = []; |
|
||||||
const collect = (tt) => { |
|
||||||
if (isUnionType(tt)) |
|
||||||
tt.members.forEach(collect); |
|
||||||
else |
|
||||||
flat.push(tt); |
|
||||||
}; |
|
||||||
types.forEach(collect); |
|
||||||
const seen = new Set(); |
|
||||||
const unique = []; |
|
||||||
flat.forEach((m) => { |
|
||||||
const key = m.name || |
|
||||||
m.value || |
|
||||||
m.kind + JSON.stringify(m); |
|
||||||
if (!seen.has(key)) { |
|
||||||
seen.add(key); |
|
||||||
unique.push(m); |
|
||||||
} |
|
||||||
}); |
|
||||||
if (unique.length === 0) |
|
||||||
return dom.type.any; |
|
||||||
if (unique.length === 1) |
|
||||||
return unique[0]; |
|
||||||
return dom.create.union(unique); |
|
||||||
} |
|
||||||
function setOf(inner) { |
|
||||||
return { |
|
||||||
kind: "name", |
|
||||||
name: "Set", |
|
||||||
typeArguments: [inner], |
|
||||||
}; |
|
||||||
} |
|
||||||
function recordOf(key, value) { |
|
||||||
return { |
|
||||||
kind: "name", |
|
||||||
name: "Record", |
|
||||||
typeArguments: [key, value], |
|
||||||
}; |
|
||||||
} |
|
||||||
// Note: aliasing helpers previously used in earlier versions were removed.
|
|
||||||
// Property name collision resolution using predicate IRI mapping
|
|
||||||
const predicateIriByProp = new WeakMap(); |
|
||||||
// Note: collisions are handled by annotateReadablePredicates pre-pass.
|
|
||||||
// Merge duplicate properties without introducing LdSet. If a property appears multiple
|
|
||||||
// times (e.g., via EXTENDS or grouped expressions) we:
|
|
||||||
// - union the types (flattening existing unions)
|
|
||||||
// - if one side is Set<T> and the other is plain U, produce Set<T|U>
|
|
||||||
// - if both are Set<A>, Set<B> -> Set<A|B>
|
|
||||||
// - preserve optional flag if any occurrence optional
|
|
||||||
function dedupeCompactProperties(props) { |
|
||||||
const isSetRef = (t) => t.kind === "name" && t.name === "Set"; |
|
||||||
const getSetInner = (t) => isSetRef(t) ? t.typeArguments[0] : t; |
|
||||||
// Group by composite key (name + predicate IRI)
|
|
||||||
const groups = new Map(); |
|
||||||
for (const p of props) { |
|
||||||
const pred = predicateIriByProp.get(p) || ""; |
|
||||||
const key = `${p.name}\u0000${pred}`; |
|
||||||
if (!groups.has(key)) |
|
||||||
groups.set(key, []); |
|
||||||
groups.get(key).push(p); |
|
||||||
} |
|
||||||
const merged = []; |
|
||||||
for (const [, group] of groups) { |
|
||||||
if (group.length === 1) { |
|
||||||
merged.push(group[0]); |
|
||||||
continue; |
|
||||||
} |
|
||||||
let acc = group[0]; |
|
||||||
for (let i = 1; i < group.length; i++) { |
|
||||||
const next = group[i]; |
|
||||||
const accSet = isSetRef(acc.type); |
|
||||||
const nextSet = isSetRef(next.type); |
|
||||||
let mergedType; |
|
||||||
if (accSet && nextSet) { |
|
||||||
mergedType = setOf(unionOf([getSetInner(acc.type), getSetInner(next.type)])); |
|
||||||
} |
|
||||||
else if (accSet && !nextSet) { |
|
||||||
mergedType = setOf(unionOf([getSetInner(acc.type), next.type])); |
|
||||||
} |
|
||||||
else if (!accSet && nextSet) { |
|
||||||
mergedType = setOf(unionOf([acc.type, getSetInner(next.type)])); |
|
||||||
} |
|
||||||
else { |
|
||||||
mergedType = unionOf([acc.type, next.type]); |
|
||||||
} |
|
||||||
const optional = acc.flags === dom.DeclarationFlags.Optional || |
|
||||||
next.flags === dom.DeclarationFlags.Optional |
|
||||||
? dom.DeclarationFlags.Optional |
|
||||||
: dom.DeclarationFlags.None; |
|
||||||
const mergedProp = dom.create.property(acc.name, mergedType, optional); |
|
||||||
mergedProp.jsDocComment = |
|
||||||
acc.jsDocComment && next.jsDocComment |
|
||||||
? `${acc.jsDocComment} | ${next.jsDocComment}` |
|
||||||
: acc.jsDocComment || next.jsDocComment; |
|
||||||
const pred = predicateIriByProp.get(acc) || predicateIriByProp.get(next); |
|
||||||
if (pred) |
|
||||||
predicateIriByProp.set(mergedProp, pred); |
|
||||||
acc = mergedProp; |
|
||||||
} |
|
||||||
merged.push(acc); |
|
||||||
} |
|
||||||
return merged; |
|
||||||
} |
|
||||||
// Helpers to add id: IRI to anonymous object(-union) types
|
|
||||||
function ensureIdOnMembers(members) { |
|
||||||
if (!members) |
|
||||||
return; |
|
||||||
const props = (members.filter?.((m) => m?.kind === "property") || |
|
||||||
[]); |
|
||||||
if (!props.some((m) => m.name === "id")) { |
|
||||||
members.unshift(dom.create.property("id", dom.create.namedTypeReference("IRI"), dom.DeclarationFlags.None)); |
|
||||||
} |
|
||||||
} |
|
||||||
function withIdOnAnonymousObject(t) { |
|
||||||
if (t?.kind === "object") { |
|
||||||
const mems = t.members; |
|
||||||
ensureIdOnMembers(mems); |
|
||||||
return t; |
|
||||||
} |
|
||||||
return t; |
|
||||||
} |
|
||||||
function withIdInUnionObjectMembers(t) { |
|
||||||
if (!isUnionType(t)) |
|
||||||
return t; |
|
||||||
const members = t.members.map((m) => m?.kind === "object" ? withIdOnAnonymousObject(m) : m); |
|
||||||
return dom.create.union(members); |
|
||||||
} |
|
||||||
// Create property and attach predicate IRI and annotations consistently
|
|
||||||
function createProperty(name, type, flags, predicateIri, annotations) { |
|
||||||
const prop = dom.create.property(name, type, flags); |
|
||||||
if (predicateIri) |
|
||||||
predicateIriByProp.set(prop, predicateIri); |
|
||||||
const cmt = commentFromAnnotations(annotations) || ""; |
|
||||||
prop.jsDocComment = cmt |
|
||||||
? `${cmt}\n\nOriginal IRI: ${predicateIri ?? ""}`.trim() |
|
||||||
: `Original IRI: ${predicateIri ?? ""}`; |
|
||||||
return prop; |
|
||||||
} |
|
||||||
export const ShexJTypingTransformerCompact = ShexJTraverser.createTransformer({ |
|
||||||
// Transformer from Schema to interfaces
|
|
||||||
Schema: { |
|
||||||
transformer: async (_schema, getTransformedChildren) => { |
|
||||||
const transformedChildren = await getTransformedChildren(); |
|
||||||
const interfaces = []; |
|
||||||
transformedChildren.shapes?.forEach((shape) => { |
|
||||||
if (typeof shape !== "string" && |
|
||||||
shape.kind === "interface") { |
|
||||||
interfaces.push(shape); |
|
||||||
} |
|
||||||
}); |
|
||||||
return interfaces; |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from ShapeDecl to interface
|
|
||||||
ShapeDecl: { |
|
||||||
transformer: async (shapeDecl, getTransformedChildren) => { |
|
||||||
const shapeName = nameFromAnnotationOrId(shapeDecl) || "Shape"; |
|
||||||
const { shapeExpr } = await getTransformedChildren(); |
|
||||||
if (shapeExpr.kind === "interface") { |
|
||||||
const shapeInterface = shapeExpr; |
|
||||||
shapeInterface.name = shapeName; |
|
||||||
// Preserve shape id for downstream shapeTypes generation
|
|
||||||
// (mirrors standard transformer behavior)
|
|
||||||
shapeInterface.shapeId = shapeDecl.id; |
|
||||||
if (!shapeInterface.members.find((m) => m.kind === "property" && m.name === "id")) { |
|
||||||
shapeInterface.members.unshift(dom.create.property("id", dom.create.namedTypeReference("IRI"),
|
|
||||||
// Root interfaces should have mandatory id
|
|
||||||
dom.DeclarationFlags.None)); |
|
||||||
} |
|
||||||
return shapeInterface; |
|
||||||
} |
|
||||||
throw new Error("Unsupported direct shape expression on ShapeDecl for compact format."); |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from Shape to interface
|
|
||||||
Shape: { |
|
||||||
transformer: async (_shape, getTransformedChildren, setReturnPointer) => { |
|
||||||
const newInterface = dom.create.interface(""); |
|
||||||
setReturnPointer(newInterface); |
|
||||||
const transformedChildren = await getTransformedChildren(); |
|
||||||
if (typeof transformedChildren.expression !== "string" && |
|
||||||
transformedChildren.expression && |
|
||||||
(transformedChildren.expression.kind === |
|
||||||
"object" || |
|
||||||
transformedChildren.expression |
|
||||||
.kind === "interface")) { |
|
||||||
newInterface.members.push(...transformedChildren.expression |
|
||||||
.members); |
|
||||||
} |
|
||||||
else if (transformedChildren.expression |
|
||||||
?.kind === "property") { |
|
||||||
newInterface.members.push(transformedChildren.expression); |
|
||||||
} |
|
||||||
if (transformedChildren.extends) { |
|
||||||
transformedChildren.extends.forEach((ext) => { |
|
||||||
const extInt = ext; |
|
||||||
if (extInt.kind === "interface") { |
|
||||||
const merged = [ |
|
||||||
...extInt.members.filter((m) => !(m.kind === "property" && m.name === "id")), |
|
||||||
...newInterface.members, |
|
||||||
].filter((m) => m.kind === "property"); |
|
||||||
newInterface.members = dedupeCompactProperties(merged); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
// Final pass: ensure only a single id property
|
|
||||||
const idSeen = new Set(); |
|
||||||
newInterface.members = newInterface.members.filter((m, idx) => { |
|
||||||
if (m.kind !== "property" || m.name !== "id") |
|
||||||
return true; |
|
||||||
if (idSeen.size === 0) { |
|
||||||
idSeen.add(idx); |
|
||||||
// normalize id type to IRI
|
|
||||||
m.type = dom.create.namedTypeReference("IRI"); |
|
||||||
return true; |
|
||||||
} |
|
||||||
return false; |
|
||||||
}); |
|
||||||
return newInterface; |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from EachOf to object type. EachOf contains the `expressions` array of properties (TripleConstraint)
|
|
||||||
EachOf: { |
|
||||||
transformer: async (eachOf, getTransformedChildren, setReturnPointer) => { |
|
||||||
const transformedChildren = await getTransformedChildren(); |
|
||||||
const name = nameFromAnnotationOrId(eachOf); |
|
||||||
const objectType = name |
|
||||||
? dom.create.interface(name) |
|
||||||
: dom.create.objectType([]); |
|
||||||
setReturnPointer(objectType); |
|
||||||
const inputProps = []; |
|
||||||
transformedChildren.expressions.forEach((expr) => { |
|
||||||
if (!expr || typeof expr === "string") |
|
||||||
return; |
|
||||||
const kind = expr.kind; |
|
||||||
if (kind === "property") { |
|
||||||
inputProps.push(expr); |
|
||||||
} |
|
||||||
else if (kind === "object" || kind === "interface") { |
|
||||||
const mlist = expr.members; |
|
||||||
mlist.forEach((m) => { |
|
||||||
if (m.kind === "property") { |
|
||||||
inputProps.push(m); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
}); |
|
||||||
const deduped = dedupeCompactProperties(inputProps); |
|
||||||
objectType.members.push(...deduped); |
|
||||||
return objectType; |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from triple constraints to type properties.
|
|
||||||
TripleConstraint: { |
|
||||||
transformer: async (tripleConstraint, getTransformedChildren, _setReturnPointer, node) => { |
|
||||||
const transformedChildren = await getTransformedChildren(); |
|
||||||
const baseName = tripleConstraint |
|
||||||
.readablePredicate; |
|
||||||
const max = tripleConstraint.max; |
|
||||||
const isPlural = max === -1 || (max !== undefined && max !== 1); |
|
||||||
const isOptional = tripleConstraint.min === 0; |
|
||||||
let valueType = dom.type.any; |
|
||||||
if (transformedChildren.valueExpr) |
|
||||||
valueType = transformedChildren.valueExpr; |
|
||||||
// Generic: If valueExpr is a NodeConstraint with concrete `values`,
|
|
||||||
// build a union of named alias references derived from those values.
|
|
||||||
// Works for any predicate (not only rdf:type).
|
|
||||||
const originalValueExpr = tripleConstraint?.valueExpr; |
|
||||||
if (originalValueExpr && |
|
||||||
typeof originalValueExpr === "object" && |
|
||||||
originalValueExpr.type === "NodeConstraint" && |
|
||||||
Array.isArray(originalValueExpr.values) && |
|
||||||
originalValueExpr.values.length > 0) { |
|
||||||
const aliasRefs = []; |
|
||||||
for (const v of originalValueExpr.values) { |
|
||||||
// valueSetValue can be string IRIREF or ObjectLiteral or other stems; handle IRIREF and ObjectLiteral
|
|
||||||
if (typeof v === "string") { |
|
||||||
// For concrete IRIREF values, use a string literal of the IRI
|
|
||||||
aliasRefs.push(dom.type.stringLiteral(v)); |
|
||||||
} |
|
||||||
else if (v && typeof v === "object") { |
|
||||||
// ObjectLiteral has `value`; use that literal as alias base
|
|
||||||
const literalVal = v.value; |
|
||||||
if (literalVal) { |
|
||||||
// For explicit literal values, use a string literal type
|
|
||||||
aliasRefs.push(dom.type.stringLiteral(literalVal)); |
|
||||||
} |
|
||||||
// For other union members (IriStem, ranges, Language, etc.), skip here; fall back covered below if none collected
|
|
||||||
} |
|
||||||
} |
|
||||||
if (aliasRefs.length > 0) { |
|
||||||
const union = unionOf(aliasRefs); |
|
||||||
const final = isPlural ? setOf(union) : union; |
|
||||||
return createProperty(baseName, final, isOptional |
|
||||||
? dom.DeclarationFlags.Optional |
|
||||||
: dom.DeclarationFlags.None, tripleConstraint.predicate, tripleConstraint.annotations); |
|
||||||
} |
|
||||||
} |
|
||||||
if (valueType.kind === "interface" && |
|
||||||
!valueType.name) { |
|
||||||
valueType = dom.create.objectType(valueType |
|
||||||
.members); |
|
||||||
} |
|
||||||
// Normalize NodeConstraint returned object forms for IRIs into IRI
|
|
||||||
// Heuristic: existing transformer (compact) returns string/number/boolean OR object/interface.
|
|
||||||
// We treat any simple string/number/boolean/name as primitive.
|
|
||||||
// Determine category
|
|
||||||
const objLike = isObjectLike(valueType); |
|
||||||
const isUnion = valueType?.kind === "union"; |
|
||||||
const unionMembers = isUnion |
|
||||||
? valueType.members |
|
||||||
: []; |
|
||||||
const unionAllObjLike = isUnion && |
|
||||||
unionMembers.length > 0 && |
|
||||||
unionMembers.every(isObjectLike); |
|
||||||
const primLike = isPrimitiveLike(valueType); |
|
||||||
if (!primLike && |
|
||||||
!objLike && |
|
||||||
valueType.kind === "union") { |
|
||||||
const u = valueType; |
|
||||||
const hasObj = u.members.some(isObjectLike); |
|
||||||
const hasPrim = u.members.some(isPrimitiveLike); |
|
||||||
if (isPlural && hasObj && hasPrim) { |
|
||||||
throw new Error(`Mixed plural union (object + primitive) not supported for predicate ${tripleConstraint.predicate}`); |
|
||||||
} |
|
||||||
} |
|
||||||
let finalType; |
|
||||||
if (isPlural) { |
|
||||||
if (objLike || unionAllObjLike) { |
|
||||||
if (valueType.kind === |
|
||||||
"interface" && |
|
||||||
valueType.name) { |
|
||||||
const ifaceName = valueType.name; |
|
||||||
// Dictionary of full object instances keyed by IRI
|
|
||||||
finalType = recordOf(dom.create.namedTypeReference("IRI"), dom.create.namedTypeReference(ifaceName)); |
|
||||||
} |
|
||||||
else { |
|
||||||
// Anonymous object or union of anonymous/interface objects
|
|
||||||
let valueForRecord = valueType; |
|
||||||
if (unionAllObjLike) { |
|
||||||
// Ensure each union member has id?: IRI if anonymous object
|
|
||||||
valueForRecord = |
|
||||||
withIdInUnionObjectMembers(valueType); |
|
||||||
} |
|
||||||
else { |
|
||||||
valueForRecord = withIdOnAnonymousObject(valueType); |
|
||||||
} |
|
||||||
finalType = recordOf(dom.create.namedTypeReference("IRI"), valueForRecord); |
|
||||||
} |
|
||||||
} |
|
||||||
else { |
|
||||||
finalType = setOf(valueType); |
|
||||||
} |
|
||||||
} |
|
||||||
else { |
|
||||||
// Singular
|
|
||||||
// If anonymous object or union of object-like types, ensure id: IRI is present (mandatory)
|
|
||||||
if (objLike) { |
|
||||||
if (valueType.kind === "object") { |
|
||||||
valueType = withIdOnAnonymousObject(valueType); |
|
||||||
} |
|
||||||
} |
|
||||||
else if (isUnion && unionAllObjLike) { |
|
||||||
valueType = withIdInUnionObjectMembers(valueType); |
|
||||||
} |
|
||||||
// Singular: always the interface/object type itself (never Id union)
|
|
||||||
if (valueType.kind === |
|
||||||
"interface" && |
|
||||||
valueType.name) { |
|
||||||
finalType = dom.create.namedTypeReference(valueType.name); |
|
||||||
} |
|
||||||
else { |
|
||||||
finalType = valueType; |
|
||||||
} |
|
||||||
} |
|
||||||
return createProperty(baseName, finalType, isOptional |
|
||||||
? dom.DeclarationFlags.Optional |
|
||||||
: dom.DeclarationFlags.None, tripleConstraint.predicate, tripleConstraint.annotations); |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from node constraint to type
|
|
||||||
NodeConstraint: { |
|
||||||
transformer: async (nodeConstraint) => { |
|
||||||
if (nodeConstraint.datatype) { |
|
||||||
switch (nodeConstraint.datatype) { |
|
||||||
case "http://www.w3.org/2001/XMLSchema#boolean": |
|
||||||
return dom.type.boolean; |
|
||||||
case "http://www.w3.org/2001/XMLSchema#byte": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#decimal": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#double": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#float": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#int": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#integer": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#long": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#negativeInteger": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#nonNegativeInteger": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#nonPositiveInteger": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#positiveInteger": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#short": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#unsignedLong": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#unsignedInt": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#unsignedShort": |
|
||||||
case "http://www.w3.org/2001/XMLSchema#unsignedByte": |
|
||||||
return dom.type.number; |
|
||||||
default: |
|
||||||
return dom.type.string; // treat most as string
|
|
||||||
} |
|
||||||
} |
|
||||||
if (nodeConstraint.nodeKind) { |
|
||||||
switch (nodeConstraint.nodeKind) { |
|
||||||
case "iri": |
|
||||||
return dom.create.namedTypeReference("IRI"); |
|
||||||
case "bnode": |
|
||||||
return dom.type.string; // opaque id as string
|
|
||||||
case "nonliteral": |
|
||||||
return dom.create.namedTypeReference("IRI"); |
|
||||||
case "literal": |
|
||||||
default: |
|
||||||
return dom.type.string; |
|
||||||
} |
|
||||||
} |
|
||||||
if (nodeConstraint.values) { |
|
||||||
const u = dom.create.union([]); |
|
||||||
nodeConstraint.values.forEach((v) => { |
|
||||||
if (typeof v === "string") |
|
||||||
u.members.push(dom.type.stringLiteral(v)); |
|
||||||
}); |
|
||||||
if (!u.members.length) |
|
||||||
return dom.type.string; |
|
||||||
if (u.members.length === 1) |
|
||||||
return u.members[0]; |
|
||||||
return u; |
|
||||||
} |
|
||||||
return dom.type.any; |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from ShapeOr to union type
|
|
||||||
ShapeOr: { |
|
||||||
transformer: async (_shapeOr, getTransformedChildren) => { |
|
||||||
const tc = await getTransformedChildren(); |
|
||||||
return dom.create.union(tc.shapeExprs); |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from ShapeAnd to intersection type
|
|
||||||
ShapeAnd: { |
|
||||||
transformer: async (_shapeAnd, getTransformedChildren) => { |
|
||||||
const tc = await getTransformedChildren(); |
|
||||||
const valid = []; |
|
||||||
tc.shapeExprs.forEach((t) => { |
|
||||||
if (typeof t === "object") |
|
||||||
valid.push(t); |
|
||||||
}); |
|
||||||
return dom.create.intersection(valid); |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from ShapeNot to type - not supported.
|
|
||||||
ShapeNot: { |
|
||||||
transformer: async () => { |
|
||||||
throw new Error("ShapeNot not supported (compact)"); |
|
||||||
}, |
|
||||||
}, |
|
||||||
// Transformer from ShapeExternal to type - not supported.
|
|
||||||
ShapeExternal: { |
|
||||||
transformer: async () => { |
|
||||||
throw new Error("ShapeExternal not supported (compact)"); |
|
||||||
}, |
|
||||||
}, |
|
||||||
}); |
|
||||||
@ -1,5 +0,0 @@ |
|||||||
import type { InterfaceDeclaration } from "dts-dom"; |
|
||||||
export interface ShapeInterfaceDeclaration extends InterfaceDeclaration { |
|
||||||
shapeId?: string; |
|
||||||
} |
|
||||||
//# sourceMappingURL=ShapeInterfaceDeclaration.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"ShapeInterfaceDeclaration.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/util/ShapeInterfaceDeclaration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"} |
|
||||||
@ -1 +0,0 @@ |
|||||||
export {}; |
|
||||||
@ -1,8 +0,0 @@ |
|||||||
import type { Schema } from "shexj"; |
|
||||||
/** |
|
||||||
* Annotate EachOf-level TripleConstraints with a collision-free readablePredicate. |
|
||||||
* Rule: for any group that shares the same local token, rename all members using |
|
||||||
* prefix-first `${prefix}_${local}` from right to left; fallback to composite. |
|
||||||
*/ |
|
||||||
export default function annotateReadablePredicates(schema: Schema): void; |
|
||||||
//# sourceMappingURL=annotateReadablePredicates.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"annotateReadablePredicates.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/util/annotateReadablePredicates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA8C,MAAM,OAAO,CAAC;AAUhF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAoIvE"} |
|
||||||
@ -1,129 +0,0 @@ |
|||||||
// Split IRI by colon, slash and hash; drop empties
|
|
||||||
const splitIriTokens = (iri) => iri.split(/[:/#]+/).filter(Boolean); |
|
||||||
// Keep dots and dashes (so 0.1 stays as 0.1) but sanitize everything else
|
|
||||||
const sanitize = (s) => s.replace(/[^\w.\-]/g, "_"); |
|
||||||
/** |
|
||||||
* Annotate EachOf-level TripleConstraints with a collision-free readablePredicate. |
|
||||||
* Rule: for any group that shares the same local token, rename all members using |
|
||||||
* prefix-first `${prefix}_${local}` from right to left; fallback to composite. |
|
||||||
*/ |
|
||||||
export default function annotateReadablePredicates(schema) { |
|
||||||
const shapes = schema.shapes ?? []; |
|
||||||
const annotateEachOf = (eachOf) => { |
|
||||||
if (!eachOf || |
|
||||||
eachOf.type !== "EachOf" || |
|
||||||
!Array.isArray(eachOf.expressions)) |
|
||||||
return; |
|
||||||
const tcs = eachOf.expressions.filter((e) => typeof e === "object" && |
|
||||||
e !== null && |
|
||||||
e.type === "TripleConstraint"); |
|
||||||
if (tcs.length > 0) { |
|
||||||
// Group by local token (last segment of IRI) and set a base readablePredicate for all
|
|
||||||
const groups = new Map(); |
|
||||||
for (const tc of tcs) { |
|
||||||
const tokens = splitIriTokens(tc.predicate); |
|
||||||
const local = tokens.length |
|
||||||
? tokens[tokens.length - 1] |
|
||||||
: tc.predicate; |
|
||||||
// default base name for non-colliders
|
|
||||||
tc.readablePredicate = local; |
|
||||||
const arr = groups.get(local) ?? []; |
|
||||||
arr.push(tc); |
|
||||||
groups.set(local, arr); |
|
||||||
} |
|
||||||
// Resolve each group (rename all in collisions)
|
|
||||||
for (const [, arr] of groups) { |
|
||||||
if (arr.length <= 1) |
|
||||||
continue; |
|
||||||
const used = new Set(); |
|
||||||
const local = splitIriTokens(arr[0].predicate).slice(-1)[0] ?? ""; |
|
||||||
for (const tc of arr) { |
|
||||||
const tokens = splitIriTokens(tc.predicate); |
|
||||||
let localIdx = tokens.lastIndexOf(local); |
|
||||||
if (localIdx === -1) |
|
||||||
localIdx = Math.max(tokens.length - 1, 0); |
|
||||||
let prefixIdx = localIdx - 1; |
|
||||||
let assigned = false; |
|
||||||
while (prefixIdx >= 0) { |
|
||||||
const cand = `${sanitize(tokens[prefixIdx])}_${sanitize(tokens[localIdx])}`; |
|
||||||
if (!used.has(cand)) { |
|
||||||
tc.readablePredicate = cand; |
|
||||||
used.add(cand); |
|
||||||
assigned = true; |
|
||||||
break; |
|
||||||
} |
|
||||||
prefixIdx -= 1; |
|
||||||
} |
|
||||||
if (!assigned) { |
|
||||||
const iriNoProto = tc.predicate.replace(/^[a-z]+:\/\//i, ""); |
|
||||||
const composite = sanitize(iriNoProto |
|
||||||
.split(/[:/#]+/) |
|
||||||
.slice(0, -1) |
|
||||||
.join("_") || "iri"); |
|
||||||
let cand = `${composite}_${sanitize(tokens[localIdx] || local)}`; |
|
||||||
let n = 1; |
|
||||||
while (used.has(cand)) |
|
||||||
cand = `${cand}_${n++}`; |
|
||||||
tc.readablePredicate = cand; |
|
||||||
used.add(cand); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
// Recurse into nested valueExpr shapes of each TC
|
|
||||||
for (const tc of tcs) { |
|
||||||
const ve = tc.valueExpr; |
|
||||||
if (ve && typeof ve === "object") { |
|
||||||
const t = ve.type; |
|
||||||
if (t === "Shape" && ve.expression) |
|
||||||
annotateEachOf(ve.expression); |
|
||||||
else if (t === "EachOf") |
|
||||||
annotateEachOf(ve); |
|
||||||
else if (t === "ShapeOr" && |
|
||||||
Array.isArray(ve.shapeExprs)) { |
|
||||||
for (const sub of ve.shapeExprs) |
|
||||||
annotateFromExpr(sub); |
|
||||||
} |
|
||||||
else if (t === "ShapeAnd" && |
|
||||||
Array.isArray(ve.shapeExprs)) { |
|
||||||
for (const sub of ve.shapeExprs) |
|
||||||
annotateFromExpr(sub); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
// Also recurse into any inline sub-EachOf/Shape expressions found directly in expressions
|
|
||||||
for (const ex of eachOf.expressions) { |
|
||||||
if (ex && typeof ex === "object") |
|
||||||
annotateFromExpr(ex); |
|
||||||
} |
|
||||||
}; |
|
||||||
const annotateFromExpr = (expr) => { |
|
||||||
if (!expr || typeof expr !== "object") |
|
||||||
return; |
|
||||||
const t = expr.type; |
|
||||||
if (t === "Shape" && expr.expression) |
|
||||||
annotateEachOf(expr.expression); |
|
||||||
else if (t === "EachOf") |
|
||||||
annotateEachOf(expr); |
|
||||||
else if (t === "ShapeOr" && Array.isArray(expr.shapeExprs)) { |
|
||||||
for (const sub of expr.shapeExprs) |
|
||||||
annotateFromExpr(sub); |
|
||||||
} |
|
||||||
else if (t === "ShapeAnd" && |
|
||||||
Array.isArray(expr.shapeExprs)) { |
|
||||||
for (const sub of expr.shapeExprs) |
|
||||||
annotateFromExpr(sub); |
|
||||||
} |
|
||||||
else if (t === "TripleConstraint") { |
|
||||||
const ve = expr.valueExpr; |
|
||||||
if (ve && typeof ve === "object") |
|
||||||
annotateFromExpr(ve); |
|
||||||
} |
|
||||||
}; |
|
||||||
for (const s of shapes) { |
|
||||||
const sd = s; |
|
||||||
const shape = (sd.shapeExpr || sd); |
|
||||||
if (shape?.expression) |
|
||||||
annotateFromExpr(shape); |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,3 +0,0 @@ |
|||||||
import type { ObjectTypeMember } from "dts-dom"; |
|
||||||
export declare function dedupeObjectTypeMembers(memberList: ObjectTypeMember[]): ObjectTypeMember[]; |
|
||||||
//# sourceMappingURL=dedupeObjectTypeMembers.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"dedupeObjectTypeMembers.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/util/dedupeObjectTypeMembers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGhD,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,gBAAgB,EAAE,GAC7B,gBAAgB,EAAE,CAoCpB"} |
|
||||||
@ -1,38 +0,0 @@ |
|||||||
import * as dom from "dts-dom"; |
|
||||||
export function dedupeObjectTypeMembers(memberList) { |
|
||||||
const properties = {}; |
|
||||||
memberList.forEach((expression) => { |
|
||||||
const propertyDeclaration = expression; |
|
||||||
// Combine properties if they're duplicates
|
|
||||||
if (properties[propertyDeclaration.name]) { |
|
||||||
const oldPropertyDeclaration = properties[propertyDeclaration.name]; |
|
||||||
const oldPropertyType = isLdSetType(oldPropertyDeclaration.type) |
|
||||||
? oldPropertyDeclaration.type.typeArguments[0] |
|
||||||
: oldPropertyDeclaration.type; |
|
||||||
const propertyType = isLdSetType(propertyDeclaration.type) |
|
||||||
? propertyDeclaration.type.typeArguments[0] |
|
||||||
: propertyDeclaration.type; |
|
||||||
const isOptional = propertyDeclaration.flags === dom.DeclarationFlags.Optional || |
|
||||||
oldPropertyDeclaration.flags === dom.DeclarationFlags.Optional; |
|
||||||
properties[propertyDeclaration.name] = dom.create.property(propertyDeclaration.name, { |
|
||||||
kind: "name", |
|
||||||
name: "LdSet", |
|
||||||
typeArguments: [dom.create.union([oldPropertyType, propertyType])], |
|
||||||
}, isOptional ? dom.DeclarationFlags.Optional : dom.DeclarationFlags.None); |
|
||||||
// Set JS Comment
|
|
||||||
properties[propertyDeclaration.name].jsDocComment = |
|
||||||
oldPropertyDeclaration.jsDocComment && propertyDeclaration.jsDocComment |
|
||||||
? `${oldPropertyDeclaration.jsDocComment} | ${propertyDeclaration.jsDocComment}` |
|
||||||
: oldPropertyDeclaration.jsDocComment || |
|
||||||
propertyDeclaration.jsDocComment; |
|
||||||
} |
|
||||||
else { |
|
||||||
properties[propertyDeclaration.name] = propertyDeclaration; |
|
||||||
} |
|
||||||
}); |
|
||||||
return Object.values(properties); |
|
||||||
} |
|
||||||
function isLdSetType(potentialLdSet) { |
|
||||||
return (potentialLdSet.kind === "name" && |
|
||||||
potentialLdSet.name === "LdSet"); |
|
||||||
} |
|
||||||
@ -1,4 +0,0 @@ |
|||||||
import type { ShexJTraverserTypes } from "@ldo/traverser-shexj"; |
|
||||||
import type { InterfaceInstanceNode } from "@ldo/type-traverser"; |
|
||||||
export declare function getRdfTypesForTripleConstraint(tripleConstraintNode: InterfaceInstanceNode<ShexJTraverserTypes, "TripleConstraint", ShexJTraverserTypes["TripleConstraint"]>): string[] | undefined[]; |
|
||||||
//# sourceMappingURL=getRdfTypesForTripleConstraint.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"getRdfTypesForTripleConstraint.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/util/getRdfTypesForTripleConstraint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,mBAAmB,EAEtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAwGjE,wBAAgB,8BAA8B,CAC1C,oBAAoB,EAAE,qBAAqB,CACvC,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,CAAC,kBAAkB,CAAC,CAC1C,GACF,MAAM,EAAE,GAAG,SAAS,EAAE,CA4BxB"} |
|
||||||
@ -1,89 +0,0 @@ |
|||||||
function addRdfTypeFromTripleExpr(tripleExpr, rdfTypeSet) { |
|
||||||
if (typeof tripleExpr === "object" && |
|
||||||
tripleExpr.type === "TripleConstraint" && |
|
||||||
tripleExpr.predicate === |
|
||||||
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type" && |
|
||||||
typeof tripleExpr.valueExpr === "object" && |
|
||||||
tripleExpr.valueExpr.type === "NodeConstraint" && |
|
||||||
tripleExpr.valueExpr.values) { |
|
||||||
tripleExpr.valueExpr.values.forEach((val) => { |
|
||||||
if (typeof val === "string") |
|
||||||
rdfTypeSet.add(val); |
|
||||||
// TODO handle other edge cases like IRIStem
|
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
||||||
function recursivelyGatherTypesFromShapeNodes(shapeNode, rdfTypeSet) { |
|
||||||
const tripleExpr = shapeNode.instance.expression; |
|
||||||
if (tripleExpr) |
|
||||||
addRdfTypeFromTripleExpr(tripleExpr, rdfTypeSet); |
|
||||||
shapeNode.parent("shapeExpr").forEach((parentShapeExpr) => { |
|
||||||
parentShapeExpr |
|
||||||
.parent("ShapeDecl", "shapeExpr") |
|
||||||
.forEach((parentShapeDecl) => { |
|
||||||
parentShapeDecl |
|
||||||
.parent("shapeDeclRef") |
|
||||||
.forEach((parentShapeDeclOrRef) => { |
|
||||||
parentShapeDeclOrRef |
|
||||||
.parent("shapeExprOrRef") |
|
||||||
.forEach((parentShapeExprOrRef) => { |
|
||||||
parentShapeExprOrRef |
|
||||||
.parent("Shape", "extends") |
|
||||||
.forEach((parentShape) => { |
|
||||||
recursivelyGatherTypesFromShapeNodes(parentShape, rdfTypeSet); |
|
||||||
const childExpressionNode = parentShape.child("expression"); |
|
||||||
if (!childExpressionNode) |
|
||||||
return; |
|
||||||
const childEachOf = childExpressionNode |
|
||||||
.child() |
|
||||||
.child(); |
|
||||||
if (childEachOf.typeName === "EachOf") { |
|
||||||
recursivelyGatherTypesFromEachOfNodes(childEachOf, rdfTypeSet); |
|
||||||
} |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
||||||
} |
|
||||||
function recursivelyGatherTypesFromEachOfNodes(eachOfNode, rdfTypeSet) { |
|
||||||
const tripleExprs = eachOfNode.instance.expressions; |
|
||||||
tripleExprs.forEach((tripleExpr) => { |
|
||||||
addRdfTypeFromTripleExpr(tripleExpr, rdfTypeSet); |
|
||||||
}); |
|
||||||
eachOfNode.parent("tripleExpr").forEach((tripleExprNode) => { |
|
||||||
const tripleExprOrRefNodes = tripleExprNode.parent("tripleExprOrRef"); |
|
||||||
tripleExprOrRefNodes.forEach((tripleExprOrRdfNode) => { |
|
||||||
const parentEachOfs = tripleExprOrRdfNode.parent("EachOf", "expressions"); |
|
||||||
parentEachOfs.forEach((parentEachOf) => { |
|
||||||
recursivelyGatherTypesFromEachOfNodes(parentEachOf, rdfTypeSet); |
|
||||||
}); |
|
||||||
// Deal with shape extends
|
|
||||||
const parentShapes = tripleExprOrRdfNode.parent("Shape", "expression"); |
|
||||||
parentShapes.forEach((parentShape) => recursivelyGatherTypesFromShapeNodes(parentShape, rdfTypeSet)); |
|
||||||
}); |
|
||||||
}); |
|
||||||
} |
|
||||||
export function getRdfTypesForTripleConstraint(tripleConstraintNode) { |
|
||||||
// Check that there's a triple constraint that is a type at the
|
|
||||||
// same level if there is, use that as an rdfType
|
|
||||||
const rdfTypeSet = new Set(); |
|
||||||
tripleConstraintNode.parent("tripleExpr").forEach((tripleExprParents) => { |
|
||||||
tripleExprParents |
|
||||||
.parent("tripleExprOrRef") |
|
||||||
.forEach((tripleExprOrRefParent) => { |
|
||||||
tripleExprOrRefParent |
|
||||||
.parent("EachOf", "expressions") |
|
||||||
.forEach((eachOfParent) => { |
|
||||||
recursivelyGatherTypesFromEachOfNodes(eachOfParent, rdfTypeSet); |
|
||||||
}); |
|
||||||
tripleExprOrRefParent |
|
||||||
.parent("Shape", "expression") |
|
||||||
.forEach((shapeParent) => { |
|
||||||
recursivelyGatherTypesFromShapeNodes(shapeParent, rdfTypeSet); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
||||||
const rdfTypes = rdfTypeSet.size > 0 ? Array.from(rdfTypeSet) : [undefined]; |
|
||||||
return rdfTypes; |
|
||||||
} |
|
||||||
@ -1,37 +0,0 @@ |
|||||||
export interface ShapeType<T extends BaseType> { |
|
||||||
schema: Schema; |
|
||||||
shape: string; |
|
||||||
} |
|
||||||
export interface BaseType extends Record<string, any> { |
|
||||||
id: string; |
|
||||||
} |
|
||||||
export type Schema = { |
|
||||||
[id: string]: Shape; |
|
||||||
}; |
|
||||||
export interface Shape { |
|
||||||
iri: string; |
|
||||||
predicates: Predicate[]; |
|
||||||
} |
|
||||||
export type DataType = { |
|
||||||
/** The required literal value(s), if type is `literal`. Others are allowed, if `extra` is true. */ |
|
||||||
literals?: number[] | string[] | boolean; |
|
||||||
/** If `valType` is `"shape"`, the nested shape or its reference. Use reference for serialization. */ |
|
||||||
shape?: string | Shape; |
|
||||||
/** The type of object value for a triple constraint. */ |
|
||||||
valType: "number" | "string" | "boolean" | "iri" | "literal" | "shape"; |
|
||||||
}; |
|
||||||
export interface Predicate { |
|
||||||
/** Allowed type of object. If more than one is present, either of them is allowed. */ |
|
||||||
dataTypes: DataType[]; |
|
||||||
/** The RDF predicate URI. */ |
|
||||||
iri: string; |
|
||||||
/** The alias of the `predicateUri` when serialized to a JSON object. */ |
|
||||||
readablePredicate: string; |
|
||||||
/** Maximum allowed number of values. `-1` means infinite. */ |
|
||||||
maxCardinality: number; |
|
||||||
/** Minimum required number of values */ |
|
||||||
minCardinality: number; |
|
||||||
/** If other (additional) values are permitted. Useful for literals. */ |
|
||||||
extra?: boolean; |
|
||||||
} |
|
||||||
//# sourceMappingURL=types.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,QAAQ;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAS,SAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACjD,EAAE,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,MAAM,GAAG;IACjB,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC;CACvB,CAAC;AAEF,MAAM,WAAW,KAAK;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,SAAS,EAAE,CAAC;CAC3B;AAED,MAAM,MAAM,QAAQ,GAAG;IACnB,mGAAmG;IACnG,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC;IACzC,qGAAqG;IACrG,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,wDAAwD;IACxD,OAAO,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,CAAC;CAC1E,CAAC;AAEF,MAAM,WAAW,SAAS;IACtB,sFAAsF;IACtF,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,6DAA6D;IAC7D,cAAc,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,cAAc,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB"} |
|
||||||
@ -1 +0,0 @@ |
|||||||
export {}; |
|
||||||
@ -1,2 +0,0 @@ |
|||||||
export declare function forAllShapes(shapePath: string, callback: (filename: string, shape: string) => Promise<void>): Promise<void>; |
|
||||||
//# sourceMappingURL=forAllShapes.d.ts.map
|
|
||||||
@ -1 +0,0 @@ |
|||||||
{"version":3,"file":"forAllShapes.d.ts","sourceRoot":"","sources":["../../src/util/forAllShapes.ts"],"names":[],"mappings":"AAGA,wBAAsB,YAAY,CAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAC7D,OAAO,CAAC,IAAI,CAAC,CAuBf"} |
|
||||||
@ -1,17 +0,0 @@ |
|||||||
import fs from "fs"; |
|
||||||
import path from "node:path"; |
|
||||||
export async function forAllShapes(shapePath, callback) { |
|
||||||
const shapeDir = await fs.promises.readdir(shapePath, { |
|
||||||
withFileTypes: true, |
|
||||||
}); |
|
||||||
// Filter out non-shex documents
|
|
||||||
const shexFiles = shapeDir.filter((file) => file.isFile() && file.name.endsWith(".shex")); |
|
||||||
const shexPromise = Promise.all(shexFiles.map(async (file) => { |
|
||||||
const fileName = path.parse(file.name).name; |
|
||||||
// Get the content of each document
|
|
||||||
const shexC = await fs.promises.readFile(path.join(shapePath, file.name), "utf8"); |
|
||||||
await callback(fileName, shexC); |
|
||||||
})); |
|
||||||
// Note: SHACL conversion omitted here.
|
|
||||||
await Promise.all([shexPromise]); |
|
||||||
} |
|
||||||
Loading…
Reference in new issue