@ng-org/shex-orm 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +240 -0
  2. package/dist/ShexJTypes.d.ts +542 -0
  3. package/dist/ShexJTypes.d.ts.map +1 -0
  4. package/dist/ShexJTypes.js +10 -0
  5. package/dist/build.d.ts +8 -0
  6. package/dist/build.d.ts.map +1 -0
  7. package/dist/build.js +72 -0
  8. package/dist/cli.d.ts +3 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +15 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +1 -0
  14. package/dist/schema-converter/__tests__/typingTransformer.test.d.ts +2 -0
  15. package/dist/schema-converter/__tests__/typingTransformer.test.d.ts.map +1 -0
  16. package/dist/schema-converter/__tests__/typingTransformer.test.js +76 -0
  17. package/dist/schema-converter/converter.d.ts +12 -0
  18. package/dist/schema-converter/converter.d.ts.map +1 -0
  19. package/dist/schema-converter/converter.js +79 -0
  20. package/dist/schema-converter/templates/schema.ejs +8 -0
  21. package/dist/schema-converter/templates/shapeTypes.ejs +14 -0
  22. package/dist/schema-converter/templates/typings.ejs +14 -0
  23. package/dist/schema-converter/transformers/ShexJSchemaTransformer.d.ts +348 -0
  24. package/dist/schema-converter/transformers/ShexJSchemaTransformer.d.ts.map +1 -0
  25. package/dist/schema-converter/transformers/ShexJSchemaTransformer.js +239 -0
  26. package/dist/schema-converter/transformers/ShexJTypingTransformer.d.ts +366 -0
  27. package/dist/schema-converter/transformers/ShexJTypingTransformer.d.ts.map +1 -0
  28. package/dist/schema-converter/transformers/ShexJTypingTransformer.js +623 -0
  29. package/dist/schema-converter/util/ShapeInterfaceDeclaration.d.ts +5 -0
  30. package/dist/schema-converter/util/ShapeInterfaceDeclaration.d.ts.map +1 -0
  31. package/dist/schema-converter/util/ShapeInterfaceDeclaration.js +1 -0
  32. package/dist/schema-converter/util/annotateReadablePredicates.d.ts +8 -0
  33. package/dist/schema-converter/util/annotateReadablePredicates.d.ts.map +1 -0
  34. package/dist/schema-converter/util/annotateReadablePredicates.js +148 -0
  35. package/dist/schema-converter/util/dedupeObjectTypeMembers.d.ts +3 -0
  36. package/dist/schema-converter/util/dedupeObjectTypeMembers.d.ts.map +1 -0
  37. package/dist/schema-converter/util/dedupeObjectTypeMembers.js +47 -0
  38. package/dist/schema-converter/util/getRdfTypesForTripleConstraint.d.ts +4 -0
  39. package/dist/schema-converter/util/getRdfTypesForTripleConstraint.d.ts.map +1 -0
  40. package/dist/schema-converter/util/getRdfTypesForTripleConstraint.js +98 -0
  41. package/dist/types.d.ts +37 -0
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/types.js +10 -0
  44. package/dist/util/forAllShapes.d.ts +2 -0
  45. package/dist/util/forAllShapes.d.ts.map +1 -0
  46. package/dist/util/forAllShapes.js +25 -0
  47. package/package.json +67 -0
  48. package/src/ShexJTypes.ts +616 -0
  49. package/src/build.ts +106 -0
  50. package/src/cli.ts +23 -0
  51. package/src/index.ts +1 -0
  52. package/src/schema-converter/__tests__/typingTransformer.test.ts +85 -0
  53. package/src/schema-converter/converter.ts +128 -0
  54. package/src/schema-converter/templates/schema.ejs +8 -0
  55. package/src/schema-converter/templates/shapeTypes.ejs +14 -0
  56. package/src/schema-converter/templates/typings.ejs +14 -0
  57. package/src/schema-converter/transformers/ShexJSchemaTransformer.ts +284 -0
  58. package/src/schema-converter/transformers/ShexJTypingTransformer.ts +807 -0
  59. package/src/schema-converter/util/ShapeInterfaceDeclaration.ts +5 -0
  60. package/src/schema-converter/util/annotateReadablePredicates.ts +173 -0
  61. package/src/schema-converter/util/dedupeObjectTypeMembers.ts +61 -0
  62. package/src/schema-converter/util/getRdfTypesForTripleConstraint.ts +153 -0
  63. package/src/types.ts +51 -0
  64. package/src/util/forAllShapes.ts +39 -0
@@ -0,0 +1,148 @@
1
+ // Copyright (c) 2025 Laurin Weger, Par le Peuple, NextGraph.org developers
2
+ // All rights reserved.
3
+ // Licensed under the Apache License, Version 2.0
4
+ // <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
5
+ // or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
6
+ // at your option. All files in the project carrying such
7
+ // notice may not be copied, modified, or distributed except
8
+ // according to those terms.
9
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
10
+ // Split IRI by colon, slash and hash; drop empties
11
+ const splitIriTokens = (iri) => iri.split(/[:/#]+/).filter(Boolean);
12
+ // Keep dots and dashes (so 0.1 stays as 0.1) but sanitize everything else
13
+ const sanitize = (s) => s.replace(/[^\w.\-]/g, "_");
14
+ /**
15
+ * Annotate EachOf-level TripleConstraints with a collision-free readablePredicate.
16
+ * Rule: for any group that shares the same local token, rename all members using
17
+ * prefix-first `${prefix}_${local}` from right to left; fallback to composite.
18
+ */
19
+ export default function annotateReadablePredicates(schema) {
20
+ const shapes = schema.shapes ?? [];
21
+ const annotateEachOf = (eachOf) => {
22
+ if (!eachOf ||
23
+ eachOf.type !== "EachOf" ||
24
+ !Array.isArray(eachOf.expressions))
25
+ return;
26
+ const tcs = eachOf.expressions.filter((e) => typeof e === "object" &&
27
+ e !== null &&
28
+ e.type === "TripleConstraint");
29
+ if (tcs.length > 0) {
30
+ // Group by local token (last segment of IRI) and set a base readablePredicate for all
31
+ const readableNameToPredicatesMap = new Map();
32
+ for (const tripleConstraint of tcs) {
33
+ // Use the name based on the IRI ending.
34
+ let readableName;
35
+ // Special case rdfs:type => @type
36
+ if (tripleConstraint.predicate ===
37
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") {
38
+ readableName = "@type";
39
+ }
40
+ else {
41
+ const tokens = splitIriTokens(tripleConstraint.predicate);
42
+ readableName = tokens.length
43
+ ? tokens[tokens.length - 1]
44
+ : tripleConstraint.predicate;
45
+ }
46
+ // default base name for non-colliders
47
+ tripleConstraint.readablePredicate = readableName;
48
+ const groupMembers = readableNameToPredicatesMap.get(readableName) ?? [];
49
+ groupMembers.push(tripleConstraint);
50
+ readableNameToPredicatesMap.set(readableName, groupMembers);
51
+ }
52
+ // Resolve each group (rename all in collisions)
53
+ for (const [, groupMembers] of readableNameToPredicatesMap) {
54
+ if (groupMembers.length <= 1)
55
+ continue;
56
+ const used = new Set();
57
+ const local = splitIriTokens(groupMembers[0].predicate).slice(-1)[0] ??
58
+ "";
59
+ for (const tc of groupMembers) {
60
+ const tokens = splitIriTokens(tc.predicate);
61
+ let localIdx = tokens.lastIndexOf(local);
62
+ if (localIdx === -1)
63
+ localIdx = Math.max(tokens.length - 1, 0);
64
+ let prefixIdx = localIdx - 1;
65
+ let assigned = false;
66
+ while (prefixIdx >= 0) {
67
+ const cand = `${sanitize(tokens[prefixIdx])}_${sanitize(tokens[localIdx])}`;
68
+ if (!used.has(cand)) {
69
+ tc.readablePredicate = cand;
70
+ used.add(cand);
71
+ assigned = true;
72
+ break;
73
+ }
74
+ prefixIdx -= 1;
75
+ }
76
+ if (!assigned) {
77
+ const iriNoProto = tc.predicate.replace(/^[a-z]+:\/\//i, "");
78
+ const composite = sanitize(iriNoProto
79
+ .split(/[:/#]+/)
80
+ .slice(0, -1)
81
+ .join("_") || "iri");
82
+ let cand = `${composite}_${sanitize(tokens[localIdx] || local)}`;
83
+ let n = 1;
84
+ while (used.has(cand))
85
+ cand = `${cand}_${n++}`;
86
+ tc.readablePredicate = cand;
87
+ used.add(cand);
88
+ }
89
+ }
90
+ }
91
+ // Recurse into nested valueExpr shapes of each TC
92
+ for (const tc of tcs) {
93
+ const ve = tc.valueExpr;
94
+ if (ve && typeof ve === "object") {
95
+ const t = ve.type;
96
+ if (t === "Shape" && ve.expression)
97
+ annotateEachOf(ve.expression);
98
+ else if (t === "EachOf")
99
+ annotateEachOf(ve);
100
+ else if (t === "ShapeOr" &&
101
+ Array.isArray(ve.shapeExprs)) {
102
+ for (const sub of ve.shapeExprs)
103
+ annotateFromExpr(sub);
104
+ }
105
+ else if (t === "ShapeAnd" &&
106
+ Array.isArray(ve.shapeExprs)) {
107
+ for (const sub of ve.shapeExprs)
108
+ annotateFromExpr(sub);
109
+ }
110
+ }
111
+ }
112
+ }
113
+ // Also recurse into any inline sub-EachOf/Shape expressions found directly in expressions
114
+ for (const ex of eachOf.expressions) {
115
+ if (ex && typeof ex === "object")
116
+ annotateFromExpr(ex);
117
+ }
118
+ };
119
+ const annotateFromExpr = (expr) => {
120
+ if (!expr || typeof expr !== "object")
121
+ return;
122
+ const t = expr.type;
123
+ if (t === "Shape" && expr.expression)
124
+ annotateEachOf(expr.expression);
125
+ else if (t === "EachOf")
126
+ annotateEachOf(expr);
127
+ else if (t === "ShapeOr" && Array.isArray(expr.shapeExprs)) {
128
+ for (const sub of expr.shapeExprs)
129
+ annotateFromExpr(sub);
130
+ }
131
+ else if (t === "ShapeAnd" &&
132
+ Array.isArray(expr.shapeExprs)) {
133
+ for (const sub of expr.shapeExprs)
134
+ annotateFromExpr(sub);
135
+ }
136
+ else if (t === "TripleConstraint") {
137
+ const ve = expr.valueExpr;
138
+ if (ve && typeof ve === "object")
139
+ annotateFromExpr(ve);
140
+ }
141
+ };
142
+ for (const s of shapes) {
143
+ const sd = s;
144
+ const shape = (sd.shapeExpr || sd);
145
+ if (shape?.expression)
146
+ annotateFromExpr(shape);
147
+ }
148
+ }
@@ -0,0 +1,3 @@
1
+ import type { ObjectTypeMember } from "dts-dom";
2
+ export declare function dedupeObjectTypeMembers(memberList: ObjectTypeMember[]): ObjectTypeMember[];
3
+ //# sourceMappingURL=dedupeObjectTypeMembers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dedupeObjectTypeMembers.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/util/dedupeObjectTypeMembers.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGhD,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,gBAAgB,EAAE,GAC7B,gBAAgB,EAAE,CAoCpB"}
@@ -0,0 +1,47 @@
1
+ // Copyright (c) 2025 Laurin Weger, Par le Peuple, NextGraph.org developers
2
+ // All rights reserved.
3
+ // Licensed under the Apache License, Version 2.0
4
+ // <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
5
+ // or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
6
+ // at your option. All files in the project carrying such
7
+ // notice may not be copied, modified, or distributed except
8
+ // according to those terms.
9
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
10
+ import * as dom from "dts-dom";
11
+ export function dedupeObjectTypeMembers(memberList) {
12
+ const properties = {};
13
+ memberList.forEach((expression) => {
14
+ const propertyDeclaration = expression;
15
+ // Combine properties if they're duplicates
16
+ if (properties[propertyDeclaration.name]) {
17
+ const oldPropertyDeclaration = properties[propertyDeclaration.name];
18
+ const oldPropertyType = isLdSetType(oldPropertyDeclaration.type)
19
+ ? oldPropertyDeclaration.type.typeArguments[0]
20
+ : oldPropertyDeclaration.type;
21
+ const propertyType = isLdSetType(propertyDeclaration.type)
22
+ ? propertyDeclaration.type.typeArguments[0]
23
+ : propertyDeclaration.type;
24
+ const isOptional = propertyDeclaration.flags === dom.DeclarationFlags.Optional ||
25
+ oldPropertyDeclaration.flags === dom.DeclarationFlags.Optional;
26
+ properties[propertyDeclaration.name] = dom.create.property(propertyDeclaration.name, {
27
+ kind: "name",
28
+ name: "LdSet",
29
+ typeArguments: [dom.create.union([oldPropertyType, propertyType])],
30
+ }, isOptional ? dom.DeclarationFlags.Optional : dom.DeclarationFlags.None);
31
+ // Set JS Comment
32
+ properties[propertyDeclaration.name].jsDocComment =
33
+ oldPropertyDeclaration.jsDocComment && propertyDeclaration.jsDocComment
34
+ ? `${oldPropertyDeclaration.jsDocComment} | ${propertyDeclaration.jsDocComment}`
35
+ : oldPropertyDeclaration.jsDocComment ||
36
+ propertyDeclaration.jsDocComment;
37
+ }
38
+ else {
39
+ properties[propertyDeclaration.name] = propertyDeclaration;
40
+ }
41
+ });
42
+ return Object.values(properties);
43
+ }
44
+ function isLdSetType(potentialLdSet) {
45
+ return (potentialLdSet.kind === "name" &&
46
+ potentialLdSet.name === "LdSet");
47
+ }
@@ -0,0 +1,4 @@
1
+ import type { ShexJTraverserTypes } from "@ldo/traverser-shexj";
2
+ import type { InterfaceInstanceNode } from "@ldo/type-traverser";
3
+ export declare function getRdfTypesForTripleConstraint(tripleConstraintNode: InterfaceInstanceNode<ShexJTraverserTypes, "TripleConstraint", ShexJTraverserTypes["TripleConstraint"]>): string[] | undefined[];
4
+ //# sourceMappingURL=getRdfTypesForTripleConstraint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRdfTypesForTripleConstraint.d.ts","sourceRoot":"","sources":["../../../src/schema-converter/util/getRdfTypesForTripleConstraint.ts"],"names":[],"mappings":"AAUA,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"}
@@ -0,0 +1,98 @@
1
+ // Copyright (c) 2025 Laurin Weger, Par le Peuple, NextGraph.org developers
2
+ // All rights reserved.
3
+ // Licensed under the Apache License, Version 2.0
4
+ // <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
5
+ // or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
6
+ // at your option. All files in the project carrying such
7
+ // notice may not be copied, modified, or distributed except
8
+ // according to those terms.
9
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
10
+ function addRdfTypeFromTripleExpr(tripleExpr, rdfTypeSet) {
11
+ if (typeof tripleExpr === "object" &&
12
+ tripleExpr.type === "TripleConstraint" &&
13
+ tripleExpr.predicate ===
14
+ "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" &&
15
+ typeof tripleExpr.valueExpr === "object" &&
16
+ tripleExpr.valueExpr.type === "NodeConstraint" &&
17
+ tripleExpr.valueExpr.values) {
18
+ tripleExpr.valueExpr.values.forEach((val) => {
19
+ if (typeof val === "string")
20
+ rdfTypeSet.add(val);
21
+ // TODO handle other edge cases like IRIStem
22
+ });
23
+ }
24
+ }
25
+ function recursivelyGatherTypesFromShapeNodes(shapeNode, rdfTypeSet) {
26
+ const tripleExpr = shapeNode.instance.expression;
27
+ if (tripleExpr)
28
+ addRdfTypeFromTripleExpr(tripleExpr, rdfTypeSet);
29
+ shapeNode.parent("shapeExpr").forEach((parentShapeExpr) => {
30
+ parentShapeExpr
31
+ .parent("ShapeDecl", "shapeExpr")
32
+ .forEach((parentShapeDecl) => {
33
+ parentShapeDecl
34
+ .parent("shapeDeclRef")
35
+ .forEach((parentShapeDeclOrRef) => {
36
+ parentShapeDeclOrRef
37
+ .parent("shapeExprOrRef")
38
+ .forEach((parentShapeExprOrRef) => {
39
+ parentShapeExprOrRef
40
+ .parent("Shape", "extends")
41
+ .forEach((parentShape) => {
42
+ recursivelyGatherTypesFromShapeNodes(parentShape, rdfTypeSet);
43
+ const childExpressionNode = parentShape.child("expression");
44
+ if (!childExpressionNode)
45
+ return;
46
+ const childEachOf = childExpressionNode
47
+ .child()
48
+ .child();
49
+ if (childEachOf.typeName === "EachOf") {
50
+ recursivelyGatherTypesFromEachOfNodes(childEachOf, rdfTypeSet);
51
+ }
52
+ });
53
+ });
54
+ });
55
+ });
56
+ });
57
+ }
58
+ function recursivelyGatherTypesFromEachOfNodes(eachOfNode, rdfTypeSet) {
59
+ const tripleExprs = eachOfNode.instance.expressions;
60
+ tripleExprs.forEach((tripleExpr) => {
61
+ addRdfTypeFromTripleExpr(tripleExpr, rdfTypeSet);
62
+ });
63
+ eachOfNode.parent("tripleExpr").forEach((tripleExprNode) => {
64
+ const tripleExprOrRefNodes = tripleExprNode.parent("tripleExprOrRef");
65
+ tripleExprOrRefNodes.forEach((tripleExprOrRdfNode) => {
66
+ const parentEachOfs = tripleExprOrRdfNode.parent("EachOf", "expressions");
67
+ parentEachOfs.forEach((parentEachOf) => {
68
+ recursivelyGatherTypesFromEachOfNodes(parentEachOf, rdfTypeSet);
69
+ });
70
+ // Deal with shape extends
71
+ const parentShapes = tripleExprOrRdfNode.parent("Shape", "expression");
72
+ parentShapes.forEach((parentShape) => recursivelyGatherTypesFromShapeNodes(parentShape, rdfTypeSet));
73
+ });
74
+ });
75
+ }
76
+ export function getRdfTypesForTripleConstraint(tripleConstraintNode) {
77
+ // Check that there's a triple constraint that is a type at the
78
+ // same level if there is, use that as an rdfType
79
+ const rdfTypeSet = new Set();
80
+ tripleConstraintNode.parent("tripleExpr").forEach((tripleExprParents) => {
81
+ tripleExprParents
82
+ .parent("tripleExprOrRef")
83
+ .forEach((tripleExprOrRefParent) => {
84
+ tripleExprOrRefParent
85
+ .parent("EachOf", "expressions")
86
+ .forEach((eachOfParent) => {
87
+ recursivelyGatherTypesFromEachOfNodes(eachOfParent, rdfTypeSet);
88
+ });
89
+ tripleExprOrRefParent
90
+ .parent("Shape", "expression")
91
+ .forEach((shapeParent) => {
92
+ recursivelyGatherTypesFromShapeNodes(shapeParent, rdfTypeSet);
93
+ });
94
+ });
95
+ });
96
+ const rdfTypes = rdfTypeSet.size > 0 ? Array.from(rdfTypeSet) : [undefined];
97
+ return rdfTypes;
98
+ }
@@ -0,0 +1,37 @@
1
+ export interface ShapeType<T extends BaseType> {
2
+ schema: Schema;
3
+ shape: string;
4
+ }
5
+ export interface BaseType extends Record<string, any> {
6
+ "@id": string;
7
+ }
8
+ export type Schema = {
9
+ [id: string]: Shape;
10
+ };
11
+ export interface Shape {
12
+ iri: string;
13
+ predicates: Predicate[];
14
+ }
15
+ export type DataType = {
16
+ /** The required literal value(s), if type is `literal`. Others are allowed, if `extra` is true. */
17
+ literals?: number[] | string[] | boolean;
18
+ /** If `valType` is `"shape"`, the nested shape or its reference. Use reference for serialization. */
19
+ shape?: string | Shape;
20
+ /** The type of object value for a triple constraint. */
21
+ valType: "number" | "string" | "boolean" | "iri" | "literal" | "shape";
22
+ };
23
+ export interface Predicate {
24
+ /** Allowed type of object. If more than one is present, either of them is allowed. */
25
+ dataTypes: DataType[];
26
+ /** The RDF predicate URI. */
27
+ iri: string;
28
+ /** The alias of the `predicateUri` when serialized to a JSON object. */
29
+ readablePredicate: string;
30
+ /** Maximum allowed number of values. `-1` means infinite. */
31
+ maxCardinality: number;
32
+ /** Minimum required number of values */
33
+ minCardinality: number;
34
+ /** If other (additional) values are permitted. Useful for literals. */
35
+ extra?: boolean;
36
+ }
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAUA,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,KAAK,EAAE,MAAM,CAAC;CACjB;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"}
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
1
+ // Copyright (c) 2025 Laurin Weger, Par le Peuple, NextGraph.org developers
2
+ // All rights reserved.
3
+ // Licensed under the Apache License, Version 2.0
4
+ // <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
5
+ // or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
6
+ // at your option. All files in the project carrying such
7
+ // notice may not be copied, modified, or distributed except
8
+ // according to those terms.
9
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
10
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function forAllShapes(shapePath: string, callback: (filename: string, shape: string) => Promise<void>): Promise<void>;
2
+ //# sourceMappingURL=forAllShapes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forAllShapes.d.ts","sourceRoot":"","sources":["../../src/util/forAllShapes.ts"],"names":[],"mappings":"AAYA,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"}
@@ -0,0 +1,25 @@
1
+ // Copyright (c) 2023 Jackson Morgan
2
+ // Licensed under the Apache License, Version 2.0
3
+ // <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
4
+ // or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
5
+ // at your option. All files in the project carrying such
6
+ // notice may not be copied, modified, or distributed except
7
+ // according to those terms.
8
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
9
+ import fs from "fs";
10
+ import path from "node:path";
11
+ export async function forAllShapes(shapePath, callback) {
12
+ const shapeDir = await fs.promises.readdir(shapePath, {
13
+ withFileTypes: true,
14
+ });
15
+ // Filter out non-shex documents
16
+ const shexFiles = shapeDir.filter((file) => file.isFile() && file.name.endsWith(".shex"));
17
+ const shexPromise = Promise.all(shexFiles.map(async (file) => {
18
+ const fileName = path.parse(file.name).name;
19
+ // Get the content of each document
20
+ const shexC = await fs.promises.readFile(path.join(shapePath, file.name), "utf8");
21
+ await callback(fileName, shexC);
22
+ }));
23
+ // Note: SHACL conversion omitted here.
24
+ await Promise.all([shexPromise]);
25
+ }
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@ng-org/shex-orm",
3
+ "version": "0.1.2",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "bin": {
8
+ "rdf-orm": "./src/cli.ts"
9
+ },
10
+ "scripts": {
11
+ "build": "pnpm run build:ts",
12
+ "build:ts": "rm -rf dist && tsc && pnpm run update-permission && pnpm copy-templates",
13
+ "copy-templates": "mkdir -p dist && rsync -qav --include=\"*/\" --include=\"*.ejs\" --exclude=\"*\" src/ dist/",
14
+ "update-permission": "chmod +x ./dist/cli.js",
15
+ "test": "vitest run",
16
+ "prepublishOnly": " npm run build",
17
+ "lint": "eslint src/** --fix --no-error-on-unmatched-pattern",
18
+ "test:init": "rm -rf ./example-init && cp -R ./example-init-placeholder ./example-init && cd ./example-init && ../dist/index.js init",
19
+ "test:create": "rm -rf ./example-create && ./dist/index.js create ./example-create"
20
+ },
21
+ "authors": [
22
+ "Laurin Weger",
23
+ "Jackson Morgan"
24
+ ],
25
+ "license": "MIT/Apache-2.0",
26
+ "devDependencies": {
27
+ "@types/child-process-promise": "^2.2.2",
28
+ "@types/ejs": "^3.1.1",
29
+ "@types/fs-extra": "^9.0.13",
30
+ "@types/jsonld": "^1.5.15",
31
+ "@types/prompts": "^2.4.9",
32
+ "@types/shexj": "^2.1.4",
33
+ "typescript": "^5.9.2",
34
+ "vitest": "^3.2.4"
35
+ },
36
+ "dependencies": {
37
+ "@jeswr/shacl2shex": "^1.1.0",
38
+ "@ldo/traverser-shexj": "1.0.0-alpha.28",
39
+ "@ldo/type-traverser": "1.0.0-alpha.28",
40
+ "@shexjs/parser": "^1.0.0-alpha.24",
41
+ "child-process-promise": "^2.2.1",
42
+ "commander": "^14.0.1",
43
+ "dts-dom": "~3.6.0",
44
+ "ejs": "^3.1.8",
45
+ "fs-extra": "^10.1.0",
46
+ "jsonld2graphobject": "^0.0.5",
47
+ "loading-cli": "^1.1.0",
48
+ "prettier": "^3.0.3",
49
+ "prompts": "^2.4.2",
50
+ "rdf-dereference-store": "^1.4.0",
51
+ "rdf-namespaces": "^1.13.1",
52
+ "ts-morph": "^24.0.0",
53
+ "type-fest": "^2.19.0"
54
+ },
55
+ "files": [
56
+ "dist",
57
+ "src"
58
+ ],
59
+ "publishConfig": {
60
+ "bin": {
61
+ "rdf-orm": "./dist/cli.js"
62
+ },
63
+ "access": "public",
64
+ "main": "./dist/index.js",
65
+ "types": "./dist/index.d.ts"
66
+ }
67
+ }