@ng-org/shex-orm 0.1.2-alpha.6 → 0.1.2-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,11 +23,11 @@ npx rdf-orm build --input ./src/shapes/shex --output ./src/shapes/orm
23
23
  The input directory needs to contain shex files with one or more shape definitions each, for example:
24
24
 
25
25
  ```shex
26
- PREFIX ex: <http://example.org/>
26
+ PREFIX ex: <did:ng:z:>
27
27
  PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
28
28
 
29
29
  ex:ExpenseShape {
30
- a [ex:Person] ; # Required type <http://example.org/Person>
30
+ a [ex:Person] ; # Required type <did:ng:z:Person>
31
31
  ex:name xsd:string ; # Required string
32
32
  ex:email xsd:string * ; # Zero or more strings (set)
33
33
  ex:height xsd:float ; # Required number
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=schemaTransformer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaTransformer.test.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/__tests__/schemaTransformer.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,209 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import parser from "@shexjs/parser";
3
+ import annotateReadablePredicates from "../util/annotateReadablePredicates.js";
4
+ import { shexJConverter } from "../converter.js";
5
+ // Generated with Claude Opus 4.6
6
+ const TYPE_IRI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
7
+ const BASE_IRI = "http://example.org/";
8
+ /** Parse ShEx text → ShExJ → annotate → convert → return flattened schema. */
9
+ async function buildSchema(shex) {
10
+ // @ts-ignore
11
+ const shexJ = parser.construct(BASE_IRI).parse(shex);
12
+ // @ts-ignore
13
+ annotateReadablePredicates(shexJ);
14
+ const [, schema] = await shexJConverter(shexJ);
15
+ return schema;
16
+ }
17
+ /** Find a predicate by its IRI in a shape. */
18
+ function findPredicate(shape, predicateIri) {
19
+ return shape.predicates.find((p) => p.iri === predicateIri);
20
+ }
21
+ // ---------------------------------------------------------------------------
22
+ // Common prefixes used in all test schemas
23
+ // ---------------------------------------------------------------------------
24
+ const PREFIXES = `
25
+ PREFIX ex: <http://example.org/>
26
+ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
27
+ `;
28
+ // ---------------------------------------------------------------------------
29
+ // Tests
30
+ // ---------------------------------------------------------------------------
31
+ describe("ShexJSchemaTransformer", () => {
32
+ // Single shape reference via @
33
+ it("converts a single @-prefixed shape reference to valType 'shape'", async () => {
34
+ const schema = await buildSchema(`
35
+ ${PREFIXES}
36
+ ex:ItemShape {
37
+ ex:name xsd:string ;
38
+ ex:category @ex:CategoryShape ;
39
+ }
40
+ ex:CategoryShape EXTRA a {
41
+ a [ ex:Category ] ;
42
+ ex:name xsd:string ;
43
+ }
44
+ `);
45
+ const item = schema["http://example.org/ItemShape"];
46
+ const pred = findPredicate(item, "http://example.org/category");
47
+ expect(pred).toBeDefined();
48
+ expect(pred.dataTypes).toHaveLength(1);
49
+ expect(pred.dataTypes[0]).toEqual({
50
+ valType: "shape",
51
+ shape: "http://example.org/CategoryShape",
52
+ });
53
+ });
54
+ // Shape reference without @ (datatype-like IRI) → valType "iri"
55
+ it("converts an unrecognized datatype IRI to valType 'iri'", async () => {
56
+ const schema = await buildSchema(`
57
+ ${PREFIXES}
58
+ ex:ItemShape {
59
+ ex:name xsd:string ;
60
+ ex:category ex:CategoryShape ;
61
+ }
62
+ ex:CategoryShape EXTRA a {
63
+ a [ ex:Category ] ;
64
+ ex:name xsd:string ;
65
+ }
66
+ `);
67
+ const item = schema["http://example.org/ItemShape"];
68
+ const pred = findPredicate(item, "http://example.org/category");
69
+ expect(pred).toBeDefined();
70
+ expect(pred.dataTypes).toHaveLength(1);
71
+ expect(pred.dataTypes[0].valType).toBe("iri");
72
+ });
73
+ // ShapeOr with multiple shape references
74
+ it("converts ShapeOr with two shape references to two shape DataTypes", async () => {
75
+ const schema = await buildSchema(`
76
+ ${PREFIXES}
77
+ ex:ItemShape {
78
+ ex:name xsd:string ;
79
+ ex:category (@ex:CategoryShape OR @ex:TagShape) ;
80
+ }
81
+ ex:CategoryShape EXTRA a {
82
+ a [ ex:Category ] ;
83
+ ex:name xsd:string ;
84
+ }
85
+ ex:TagShape EXTRA a {
86
+ a [ ex:Tag ] ;
87
+ ex:label xsd:string ;
88
+ }
89
+ `);
90
+ const item = schema["http://example.org/ItemShape"];
91
+ const pred = findPredicate(item, "http://example.org/category");
92
+ expect(pred).toBeDefined();
93
+ expect(pred.dataTypes).toHaveLength(2);
94
+ expect(pred.dataTypes[0]).toEqual({
95
+ valType: "shape",
96
+ shape: "http://example.org/CategoryShape",
97
+ });
98
+ expect(pred.dataTypes[1]).toEqual({
99
+ valType: "shape",
100
+ shape: "http://example.org/TagShape",
101
+ });
102
+ });
103
+ // ShapeOr mixing primitive and shape reference
104
+ it("converts ShapeOr mixing a primitive and a shape reference", async () => {
105
+ const schema = await buildSchema(`
106
+ ${PREFIXES}
107
+ ex:ItemShape {
108
+ ex:name xsd:string ;
109
+ ex:catOrString xsd:string OR @ex:CategoryShape ;
110
+ }
111
+ ex:CategoryShape EXTRA a {
112
+ a [ ex:Category ] ;
113
+ ex:name xsd:string ;
114
+ }
115
+ `);
116
+ const item = schema["http://example.org/ItemShape"];
117
+ const pred = findPredicate(item, "http://example.org/catOrString");
118
+ expect(pred).toBeDefined();
119
+ expect(pred.dataTypes).toHaveLength(2);
120
+ const types = pred.dataTypes.map((d) => d.valType);
121
+ expect(types).toContain("string");
122
+ expect(types).toContain("shape");
123
+ const shapeDt = pred.dataTypes.find((d) => d.valType === "shape");
124
+ expect(shapeDt.shape).toBe("http://example.org/CategoryShape");
125
+ });
126
+ // Anonymous inline shape → flattened to root with derived IRI
127
+ it("flattens anonymous inline shapes to root with a derived IRI", async () => {
128
+ const schema = await buildSchema(`
129
+ ${PREFIXES}
130
+ ex:ItemShape {
131
+ ex:name xsd:string ;
132
+ ex:category EXTRA a {
133
+ a [ ex:Category ] ;
134
+ ex:name xsd:string ;
135
+ } ;
136
+ }
137
+ `);
138
+ const derivedIri = "http://example.org/ItemShape||http://example.org/category";
139
+ // The parent predicate should reference the derived IRI
140
+ const item = schema["http://example.org/ItemShape"];
141
+ const pred = findPredicate(item, "http://example.org/category");
142
+ expect(pred).toBeDefined();
143
+ expect(pred.dataTypes).toHaveLength(1);
144
+ expect(pred.dataTypes[0]).toEqual({
145
+ valType: "shape",
146
+ shape: derivedIri,
147
+ });
148
+ // The anonymous shape should exist as a root-level entry
149
+ const flattenedShape = schema[derivedIri];
150
+ expect(flattenedShape).toBeDefined();
151
+ expect(flattenedShape.iri).toBe(derivedIri);
152
+ const namePred = findPredicate(flattenedShape, "http://example.org/name");
153
+ expect(namePred).toBeDefined();
154
+ });
155
+ // IRI value set (enumeration)
156
+ it("converts IRI value sets to multiple iri DataTypes with literals", async () => {
157
+ const schema = await buildSchema(`
158
+ ${PREFIXES}
159
+ ex:ItemShape {
160
+ ex:name xsd:string ;
161
+ ex:status [ex:Active ex:Archived ex:Deleted] ;
162
+ }
163
+ `);
164
+ const item = schema["http://example.org/ItemShape"];
165
+ const pred = findPredicate(item, "http://example.org/status");
166
+ expect(pred).toBeDefined();
167
+ expect(pred.dataTypes).toHaveLength(3);
168
+ expect(pred.dataTypes[0]).toEqual({
169
+ valType: "iri",
170
+ literals: ["http://example.org/Active"],
171
+ });
172
+ expect(pred.dataTypes[1]).toEqual({
173
+ valType: "iri",
174
+ literals: ["http://example.org/Archived"],
175
+ });
176
+ expect(pred.dataTypes[2]).toEqual({
177
+ valType: "iri",
178
+ literals: ["http://example.org/Deleted"],
179
+ });
180
+ });
181
+ // Single-predicate shape (no EachOf wrapper)
182
+ it("handles shapes with only one predicate", async () => {
183
+ const schema = await buildSchema(`
184
+ ${PREFIXES}
185
+ ex:ItemShape {
186
+ ex:name xsd:string ;
187
+ }
188
+ `);
189
+ const item = schema["http://example.org/ItemShape"];
190
+ expect(item).toBeDefined();
191
+ expect(item.predicates).toHaveLength(1);
192
+ expect(item.predicates[0].iri).toBe("http://example.org/name");
193
+ expect(item.predicates[0].dataTypes[0].valType).toBe("string");
194
+ });
195
+ // EXTRA predicate
196
+ it("marks EXTRA predicates with extra: true", async () => {
197
+ const schema = await buildSchema(`
198
+ ${PREFIXES}
199
+ ex:CategoryShape EXTRA a {
200
+ a [ ex:Category ] ;
201
+ ex:name xsd:string ;
202
+ }
203
+ `);
204
+ const cat = schema["http://example.org/CategoryShape"];
205
+ const typePred = findPredicate(cat, TYPE_IRI);
206
+ expect(typePred).toBeDefined();
207
+ expect(typePred.extra).toBe(true);
208
+ });
209
+ });
@@ -5,4 +5,4 @@ import type { Schema } from "@ng-org/shex-orm";
5
5
  * <%- fileName %>Schema: Schema for <%- fileName %>
6
6
  * =============================================================================
7
7
  */
8
- export const <%- fileName %>Schema: Schema = <%- compactSchema %>;
8
+ export const <%- fileName %>Schema = <%- compactSchema %> as const satisfies Schema;
@@ -1,14 +1,15 @@
1
1
  import type { ShapeType } from "@ng-org/shex-orm";
2
- import { <%- fileName %>Schema } from "./<%- fileName %>.schema";
2
+ import { <%- fileName %>Schema } from "./<%- fileName %>.schema.ts";
3
3
  import type {
4
4
  <% typings.forEach((typing)=> { if (!/Id$/.test(typing.dts.name)) { -%>
5
5
  <%- typing.dts.name %>,
6
- <% } }); -%>} from "./<%- fileName %>.typings";
6
+ <% } }); -%>} from "./<%- fileName %>.typings.ts";
7
7
 
8
8
  // ShapeTypes for <%- fileName %>
9
9
  <% typings.forEach((typing)=> { if (!/Id$/.test(typing.dts.name)) { -%>
10
- export const <%- typing.dts.name %>ShapeType: ShapeType<<%- typing.dts.name %>> = {
11
- schema: <%- fileName %>Schema,
12
- shape: "<%- typing.dts.shapeId %>",
13
- };
10
+ export const <%- typing.dts.name %>ShapeType = {
11
+ schema: <%- fileName %>Schema,
12
+ shape: "<%- typing.dts.shapeId %>",
13
+ } as const satisfies ShapeType<<%- typing.dts.name %>>;
14
+
14
15
  <% } }); -%>
@@ -1 +1 @@
1
- {"version":3,"file":"ShexJSchemaTransformer.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/transformers/ShexJSchemaTransformer.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAyDjE,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,GAAG,QAAQ,EAAE,CAAA;KAAE;aACxC;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;QA+OtC,CAAC"}
1
+ {"version":3,"file":"ShexJSchemaTransformer.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/transformers/ShexJSchemaTransformer.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAyDjE,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,GAAG,QAAQ,EAAE,CAAA;KAAE;aACxC;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;QAgRtC,CAAC"}
@@ -59,7 +59,7 @@ const rdfDataTypeToBasic = (dataType) => {
59
59
  case "http://www.w3.org/2001/XMLSchema#anyURI":
60
60
  return "iri";
61
61
  default:
62
- return "string";
62
+ return "iri";
63
63
  }
64
64
  };
65
65
  export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer({
@@ -81,7 +81,12 @@ export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer({
81
81
  // TODO: We don't handles those
82
82
  _shape.closed;
83
83
  const transformedChildren = await getTransformedChildren();
84
- const compactShape = transformedChildren.expression;
84
+ const expr = transformedChildren.expression;
85
+ // EachOf returns a Shape ({ iri, predicates }), but a single
86
+ // TripleConstraint returns a bare Predicate. Normalize both.
87
+ const compactShape = expr && "predicates" in expr
88
+ ? expr
89
+ : { iri: "", predicates: [expr] };
85
90
  for (const extra of _shape.extra || []) {
86
91
  const extraPredicate = compactShape.predicates.find((p) => p.iri === extra);
87
92
  if (extraPredicate)
@@ -128,12 +133,25 @@ export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer({
128
133
  }
129
134
  else if (transformedChildren.valueExpr &&
130
135
  transformedChildren.valueExpr.predicates) {
131
- // Nested object
136
+ const resolvedShape = transformedChildren.valueExpr;
137
+ if (resolvedShape.iri) {
138
+ // Named shape reference: Use the IRI string.
139
+ return {
140
+ dataTypes: [
141
+ {
142
+ valType: "shape",
143
+ shape: resolvedShape.iri,
144
+ },
145
+ ],
146
+ ...commonProperties,
147
+ };
148
+ }
149
+ // Anonymous inline shape: Pass as shape object for flattenSchema to convert.
132
150
  return {
133
151
  dataTypes: [
134
152
  {
135
153
  valType: "shape",
136
- shape: transformedChildren.valueExpr,
154
+ shape: resolvedShape, // Make type fit as any (object will be flattened).
137
155
  },
138
156
  ],
139
157
  ...commonProperties,
@@ -248,7 +266,24 @@ export const ShexJSchemaTransformerCompact = ShexJTraverser.createTransformer({
248
266
  // or a DataType[] (from NodeConstraint with multiple types).
249
267
  // We need to flatten arrays to get a single DataType[].
250
268
  const exprs = Array.isArray(shapeExprs) ? shapeExprs : [shapeExprs];
251
- return exprs.flatMap((expr) => Array.isArray(expr) ? expr : [expr]);
269
+ return exprs.flatMap((expr) => {
270
+ if (Array.isArray(expr))
271
+ return expr;
272
+ // Resolved shape reference: Convert to DataType with shape IRI.
273
+ if (expr && typeof expr === "object" && "predicates" in expr) {
274
+ return [
275
+ {
276
+ valType: "shape",
277
+ shape: expr.iri,
278
+ },
279
+ ];
280
+ }
281
+ // String shape reference
282
+ if (typeof expr === "string") {
283
+ return [{ valType: "shape", shape: expr }];
284
+ }
285
+ return [expr];
286
+ });
252
287
  },
253
288
  },
254
289
  // Transformer from ShapeAnd
@@ -1 +1 @@
1
- {"version":3,"file":"ShexJTypingTransformer.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/transformers/ShexJTypingTransformer.ts"],"names":[],"mappings":"AAcA,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;AAyPD,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,21 +32,9 @@ export function toCamelCase(text) {
32
32
  * Name functions
33
33
  */
34
34
  export function iriToName(iri) {
35
- try {
36
- const url = new URL(iri);
37
- let name;
38
- if (url.hash) {
39
- name = url.hash.slice(1);
40
- }
41
- else {
42
- const splitPathname = url.pathname.split("/");
43
- name = splitPathname[splitPathname.length - 1];
44
- }
45
- return name.replace(/(?<!^)Shape$/, "");
46
- }
47
- catch (err) {
48
- return iri;
49
- }
35
+ const lastSegment = iri.split(/[\/:#?@&=]/).at(-1);
36
+ // Remove *Shape part of name, if it exists.
37
+ return lastSegment.replace(/(?<!^)Shape$/, "");
50
38
  }
51
39
  export function nameFromAnnotationOrId(obj) {
52
40
  const labelAnnotationObject = obj.annotations?.find((annotation) => annotation.predicate ===
@@ -536,6 +524,31 @@ export const ShexJTypingTransformerCompact = ShexJTraverser.createTransformer({
536
524
  transformer: async (nodeConstraint) => {
537
525
  if (nodeConstraint.datatype) {
538
526
  switch (nodeConstraint.datatype) {
527
+ case "http://www.w3.org/2001/XMLSchema#string":
528
+ case "http://www.w3.org/2001/XMLSchema#ENTITIES":
529
+ case "http://www.w3.org/2001/XMLSchema#ENTITY":
530
+ case "http://www.w3.org/2001/XMLSchema#ID":
531
+ case "http://www.w3.org/2001/XMLSchema#IDREF":
532
+ case "http://www.w3.org/2001/XMLSchema#IDREFS":
533
+ case "http://www.w3.org/2001/XMLSchema#language":
534
+ case "http://www.w3.org/2001/XMLSchema#Name":
535
+ case "http://www.w3.org/2001/XMLSchema#NCName":
536
+ case "http://www.w3.org/2001/XMLSchema#NMTOKEN":
537
+ case "http://www.w3.org/2001/XMLSchema#NMTOKENS":
538
+ case "http://www.w3.org/2001/XMLSchema#normalizedString":
539
+ case "http://www.w3.org/2001/XMLSchema#QName":
540
+ case "http://www.w3.org/2001/XMLSchema#token":
541
+ case "http://www.w3.org/2001/XMLSchema#date":
542
+ case "http://www.w3.org/2001/XMLSchema#dateTime":
543
+ case "http://www.w3.org/2001/XMLSchema#duration":
544
+ case "http://www.w3.org/2001/XMLSchema#gDay":
545
+ case "http://www.w3.org/2001/XMLSchema#gMonth":
546
+ case "http://www.w3.org/2001/XMLSchema#gMonthDay":
547
+ case "http://www.w3.org/2001/XMLSchema#gYear":
548
+ case "http://www.w3.org/2001/XMLSchema#gYearMonth":
549
+ case "http://www.w3.org/2001/XMLSchema#time":
550
+ case "http://www.w3.org/2001/XMLSchema#hexBinary":
551
+ return dom.type.string;
539
552
  case "http://www.w3.org/2001/XMLSchema#boolean":
540
553
  return dom.type.boolean;
541
554
  case "http://www.w3.org/2001/XMLSchema#byte":
@@ -556,7 +569,7 @@ export const ShexJTypingTransformerCompact = ShexJTraverser.createTransformer({
556
569
  case "http://www.w3.org/2001/XMLSchema#unsignedByte":
557
570
  return dom.type.number;
558
571
  default:
559
- return dom.type.string; // treat most as string
572
+ return dom.create.namedTypeReference("IRI"); // treat others / references as IRI
560
573
  }
561
574
  }
562
575
  if (nodeConstraint.nodeKind) {
package/dist/types.d.ts CHANGED
@@ -26,9 +26,9 @@ export interface Shape {
26
26
  /** An allowed data type or literal. */
27
27
  export type DataType = {
28
28
  /** The required literal value(s). Additional values are allowed, if `extra` is true. */
29
- literals?: number[] | string[] | boolean;
30
- /** If `valType` is `"shape"`, the nested shape or its reference. Use reference for serialization. */
31
- shape?: string | Shape;
29
+ literals?: number[] | string[] | boolean[];
30
+ /** If `valType` is `"shape"`, the IRI of the nested shape. */
31
+ shape?: string;
32
32
  /** The type of object value for a triple constraint. */
33
33
  valType: "number" | "string" | "boolean" | "iri" | "shape";
34
34
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,QAAQ;IACzC,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,6DAA6D;AAC7D,MAAM,WAAW,Q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Q,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACjD,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;CAIjB;AAED,MAAM,MAAM,MAAM,GAAG;IACjB,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC;CACvB,CAAC;AAEF,0BAA0B;AAC1B,MAAM,WAAW,KAAK;IAClB,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,UAAU,EAAE,SAAS,EAAE,CAAC;CAC3B;AAED,uCAAuC;AACvC,MAAM,MAAM,QAAQ,GAAG;IACnB,wFAAwF;IACxF,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;IAC3C,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,OAAO,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC;CAC9D,CAAC;AAEF,gCAAgC;AAChC,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,yCAAyC;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-org/shex-orm",
3
- "version": "0.1.2-alpha.6",
3
+ "version": "0.1.2-alpha.8",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,9 +18,12 @@
18
18
  "@types/fs-extra": "^9.0.13",
19
19
  "@types/jsonld": "^1.5.15",
20
20
  "@types/shexj": "^2.1.4",
21
- "typescript": "^5.9.2",
21
+ "typescript": "^5.9.3",
22
22
  "vitest": "^3.2.4"
23
23
  },
24
+ "peerDependencies": {
25
+ "typescript": "^4.9.0 || ^5.0.0 || ^6.0.0"
26
+ },
24
27
  "dependencies": {
25
28
  "@ldo/traverser-shexj": "1.0.0-alpha.28",
26
29
  "@ldo/type-traverser": "1.0.0-alpha.28",