@lde/docgen 0.1.0 → 0.2.1
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/dist/cli.js +1 -1
- package/frames/shacl.frame.jsonld +3 -0
- package/package.json +1 -1
- package/dist/framing.d.ts +0 -4
- package/dist/framing.d.ts.map +0 -1
- package/dist/framing.js +0 -7
- package/dist/jsonld-to-ts.d.ts +0 -12
- package/dist/jsonld-to-ts.d.ts.map +0 -1
- package/dist/jsonld-to-ts.js +0 -55
- package/dist/parser.d.ts +0 -3
- package/dist/parser.d.ts.map +0 -1
- package/dist/parser.js +0 -14
- package/dist/renderer.d.ts +0 -3
- package/dist/renderer.d.ts.map +0 -1
- package/dist/renderer.js +0 -48
- package/dist/schema-plain.d.ts +0 -22
- package/dist/schema-plain.d.ts.map +0 -1
- package/dist/schema-plain.js +0 -136
- package/dist/schema.d.ts +0 -59
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -88
- package/dist/sparql.d.ts +0 -3
- package/dist/sparql.d.ts.map +0 -1
- package/dist/sparql.js +0 -64
- package/dist/types.d.ts +0 -73
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1
package/dist/cli.js
CHANGED
|
@@ -18,7 +18,7 @@ program
|
|
|
18
18
|
.option('-f --frame <json-ld-frame-file>', 'Path to a JSON-LD Frame file', __dirname + '/../frames/shacl.frame.jsonld')
|
|
19
19
|
.addHelpText('after', `
|
|
20
20
|
Example:
|
|
21
|
-
$ docgen shacl.ttl template.liquid
|
|
21
|
+
$ npx @lde/docgen@latest from-shacl shacl.ttl template.liquid
|
|
22
22
|
`)
|
|
23
23
|
.action(async (rdfFile, templateFile, { frame }) => {
|
|
24
24
|
try {
|
package/package.json
CHANGED
package/dist/framing.d.ts
DELETED
package/dist/framing.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"framing.d.ts","sourceRoot":"","sources":["../src/framing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,wBAAsB,KAAK,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,8BAI/D"}
|
package/dist/framing.js
DELETED
package/dist/jsonld-to-ts.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Loads a JSON-LD file and parses it into a deeply nested JS/TS object structure.
|
|
3
|
-
* Supports nested JSON-LD objects (e.g., objects with @id, @type, etc.).
|
|
4
|
-
* @param jsonldPath Path to the JSON-LD file
|
|
5
|
-
*/
|
|
6
|
-
export declare function parseJsonLdToObject(jsonldPath: string): Promise<any>;
|
|
7
|
-
/**
|
|
8
|
-
* Recursively convert expanded JSON-LD to a TypeScript object tree,
|
|
9
|
-
* supporting nested objects and arrays.
|
|
10
|
-
*/
|
|
11
|
-
export declare function expandedJsonLdToTsObjects(expanded: any): any;
|
|
12
|
-
//# sourceMappingURL=jsonld-to-ts.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonld-to-ts.d.ts","sourceRoot":"","sources":["../src/jsonld-to-ts.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAc1E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,CAiB5D"}
|
package/dist/jsonld-to-ts.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import jsonld from 'jsonld';
|
|
3
|
-
/**
|
|
4
|
-
* Loads a JSON-LD file and parses it into a deeply nested JS/TS object structure.
|
|
5
|
-
* Supports nested JSON-LD objects (e.g., objects with @id, @type, etc.).
|
|
6
|
-
* @param jsonldPath Path to the JSON-LD file
|
|
7
|
-
*/
|
|
8
|
-
export async function parseJsonLdToObject(jsonldPath) {
|
|
9
|
-
const jsonldRaw = readFileSync(jsonldPath, 'utf8');
|
|
10
|
-
const jsonldDoc = JSON.parse(jsonldRaw);
|
|
11
|
-
const context = jsonldDoc['@context'];
|
|
12
|
-
context['@vocab'] = 'http://www.w3.org/ns/shacl#';
|
|
13
|
-
// const context = { '@vocab': 'http://www.w3.org/ns/shacl#' };
|
|
14
|
-
// Expand JSON-LD to full IRI form, preserving nested objects
|
|
15
|
-
const expanded = await jsonld.expand(jsonldDoc);
|
|
16
|
-
// Optionally flatten, but for nested structure, we return expanded
|
|
17
|
-
const compacted = await jsonld.compact(expanded, context);
|
|
18
|
-
return compacted;
|
|
19
|
-
// return expanded;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Recursively convert expanded JSON-LD to a TypeScript object tree,
|
|
23
|
-
* supporting nested objects and arrays.
|
|
24
|
-
*/
|
|
25
|
-
export function expandedJsonLdToTsObjects(expanded) {
|
|
26
|
-
if (Array.isArray(expanded)) {
|
|
27
|
-
return expanded.map(expandedJsonLdToTsObjects);
|
|
28
|
-
}
|
|
29
|
-
if (typeof expanded === 'object' && expanded !== null) {
|
|
30
|
-
const obj = {};
|
|
31
|
-
for (const [key, value] of Object.entries(expanded)) {
|
|
32
|
-
// Handle @id, @type, etc. as normal fields
|
|
33
|
-
if (Array.isArray(value) && value.length === 1) {
|
|
34
|
-
obj[key] = expandedJsonLdToTsObjects(value[0]);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
obj[key] = expandedJsonLdToTsObjects(value);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return obj;
|
|
41
|
-
}
|
|
42
|
-
return expanded;
|
|
43
|
-
}
|
|
44
|
-
// Quick test: run if this file is executed directly (ESM compatible)
|
|
45
|
-
const isMain = import.meta &&
|
|
46
|
-
import.meta.url &&
|
|
47
|
-
process.argv[1] &&
|
|
48
|
-
import.meta.url.endsWith(process.argv[1]);
|
|
49
|
-
if (isMain) {
|
|
50
|
-
(async () => {
|
|
51
|
-
const expanded = await parseJsonLdToObject(new URL('../test/fixtures/shape.jsonld', import.meta.url).pathname);
|
|
52
|
-
const tsObjects = expandedJsonLdToTsObjects(expanded);
|
|
53
|
-
console.dir(tsObjects, { depth: null });
|
|
54
|
-
})();
|
|
55
|
-
}
|
package/dist/parser.d.ts
DELETED
package/dist/parser.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAa7E"}
|
package/dist/parser.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { rdfDereferencer } from 'rdf-dereference';
|
|
2
|
-
import jsonld from 'jsonld';
|
|
3
|
-
export async function parseRdfToJsonLd(filePath) {
|
|
4
|
-
const { data } = await rdfDereferencer.dereference(filePath, {
|
|
5
|
-
localFiles: true,
|
|
6
|
-
});
|
|
7
|
-
const quads = [];
|
|
8
|
-
for await (const quad of data) {
|
|
9
|
-
quads.push(quad);
|
|
10
|
-
}
|
|
11
|
-
return jsonld.fromRDF(quads, {
|
|
12
|
-
useNativeTypes: true, // Convert xsd:integer to Number etc.
|
|
13
|
-
});
|
|
14
|
-
}
|
package/dist/renderer.d.ts
DELETED
package/dist/renderer.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,wBAAsB,MAAM,CAC1B,MAAM,EAAE,UAAU,EAClB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CA8DjB"}
|
package/dist/renderer.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Liquid } from 'liquidjs';
|
|
2
|
-
import { dirname } from 'path';
|
|
3
|
-
export async function render(shapes, templatePath) {
|
|
4
|
-
const templatesDir = dirname(templatePath);
|
|
5
|
-
const engine = new Liquid({
|
|
6
|
-
root: templatesDir,
|
|
7
|
-
extname: '.liquid',
|
|
8
|
-
});
|
|
9
|
-
engine.registerFilter('lang', (nodes, language) => {
|
|
10
|
-
if (nodes === undefined) {
|
|
11
|
-
return '';
|
|
12
|
-
}
|
|
13
|
-
const filtered = [nodes]
|
|
14
|
-
.flat()
|
|
15
|
-
.filter((node) => node['@language'] === language);
|
|
16
|
-
return filtered[0]?.['@value'] ?? '';
|
|
17
|
-
});
|
|
18
|
-
engine.registerFilter('filterByProperty', (nodes, property, value) => {
|
|
19
|
-
if (!Array.isArray(nodes))
|
|
20
|
-
return [];
|
|
21
|
-
return (nodes.filter((node) => {
|
|
22
|
-
return node[property] === value;
|
|
23
|
-
}) ?? [][0]);
|
|
24
|
-
});
|
|
25
|
-
engine.registerFilter('mergePropertiesByPath', (properties) => {
|
|
26
|
-
if (!Array.isArray(properties))
|
|
27
|
-
return [];
|
|
28
|
-
const grouped = properties.reduce((acc, propertyShape) => {
|
|
29
|
-
const path = propertyShape.path;
|
|
30
|
-
acc[path] ??= [];
|
|
31
|
-
acc[path].push(propertyShape);
|
|
32
|
-
return acc;
|
|
33
|
-
}, {});
|
|
34
|
-
return Object.entries(grouped).map(([_path, propertyShapes]) => {
|
|
35
|
-
const result = {};
|
|
36
|
-
for (const propertyShape of propertyShapes) {
|
|
37
|
-
for (const key in propertyShape) {
|
|
38
|
-
if (result[key] === undefined && propertyShape[key] !== undefined) {
|
|
39
|
-
result[key] = propertyShape[key];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
const templateName = templatePath.split('/').pop() || templatePath;
|
|
47
|
-
return engine.renderFile(templateName, { nodeShapes: shapes['@graph'] });
|
|
48
|
-
}
|
package/dist/schema-plain.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface PropertyShape {
|
|
2
|
-
name?: string;
|
|
3
|
-
path?: string;
|
|
4
|
-
minCount?: number;
|
|
5
|
-
maxCount?: number;
|
|
6
|
-
datatype?: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
or?: PropertyShape[];
|
|
9
|
-
class?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface NodeShape {
|
|
12
|
-
id: string;
|
|
13
|
-
name?: string;
|
|
14
|
-
targetClass?: string;
|
|
15
|
-
nodeKind?: string;
|
|
16
|
-
pattern?: string;
|
|
17
|
-
description?: string;
|
|
18
|
-
properties: PropertyShape[];
|
|
19
|
-
seeAlso?: string;
|
|
20
|
-
}
|
|
21
|
-
export declare function loadShapesFromTurtle(ttlFilePath: string): NodeShape[];
|
|
22
|
-
//# sourceMappingURL=schema-plain.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-plain.d.ts","sourceRoot":"","sources":["../src/schema-plain.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAgHD,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE,CA2DrE"}
|
package/dist/schema-plain.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { Parser, Store } from 'n3';
|
|
4
|
-
// Helper function to get literal value from N3 term
|
|
5
|
-
function getLiteralValue(term) {
|
|
6
|
-
return term && term.termType === 'Literal' ? term.value : undefined;
|
|
7
|
-
}
|
|
8
|
-
// Helper function to get id from N3 term
|
|
9
|
-
function getId(term) {
|
|
10
|
-
return term ? term.id : undefined;
|
|
11
|
-
}
|
|
12
|
-
// Recursively parse a PropertyShape node
|
|
13
|
-
function parsePropertyShape(store, node, SH) {
|
|
14
|
-
const name = getLiteralValue(store.getObjects(node, SH + 'name', null)[0]);
|
|
15
|
-
const path = getId(store.getObjects(node, SH + 'path', null)[0]);
|
|
16
|
-
const minCount = parseInt(getLiteralValue(store.getObjects(node, SH + 'minCount', null)[0]) || '', 10);
|
|
17
|
-
const maxCount = parseInt(getLiteralValue(store.getObjects(node, SH + 'maxCount', null)[0]) || '', 10);
|
|
18
|
-
const datatypes = store
|
|
19
|
-
.getObjects(node, SH + 'datatype', null)
|
|
20
|
-
.map(getId)
|
|
21
|
-
.filter(Boolean);
|
|
22
|
-
const description = getLiteralValue(store.getObjects(node, SH + 'description', null)[0]);
|
|
23
|
-
const classIri = getId(store.getObjects(node, SH + 'class', null)[0]);
|
|
24
|
-
const orNodes = store.getObjects(node, SH + 'or', null);
|
|
25
|
-
let or = undefined;
|
|
26
|
-
if (orNodes.length > 0) {
|
|
27
|
-
// sh:or is an RDF list, get the elements
|
|
28
|
-
const listNodes = getRdfList(store, orNodes[0]);
|
|
29
|
-
console.log('or', orNodes, 'list', listNodes);
|
|
30
|
-
or = listNodes.map((n) => parsePropertyShape(store, n, SH));
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
name,
|
|
34
|
-
path,
|
|
35
|
-
minCount: isNaN(minCount) ? undefined : minCount,
|
|
36
|
-
maxCount: isNaN(maxCount) ? undefined : maxCount,
|
|
37
|
-
datatype: datatypes.length === 1 ? datatypes[0] : undefined,
|
|
38
|
-
// Optionally: datatypes: datatypes.length > 1 ? datatypes : undefined,
|
|
39
|
-
description,
|
|
40
|
-
...(or ? { or } : {}),
|
|
41
|
-
...(classIri ? { class: classIri } : {}),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
// Helper to parse RDF lists (returns array of nodes)
|
|
45
|
-
function getRdfList(store, listNode) {
|
|
46
|
-
const RDF_FIRST = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first';
|
|
47
|
-
const RDF_REST = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest';
|
|
48
|
-
const RDF_NIL = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil';
|
|
49
|
-
const result = [];
|
|
50
|
-
let node = listNode;
|
|
51
|
-
while (node && node.value !== RDF_NIL) {
|
|
52
|
-
const first = store.getObjects(node, RDF_FIRST, null)[0];
|
|
53
|
-
if (first)
|
|
54
|
-
result.push(first);
|
|
55
|
-
const rest = store.getObjects(node, RDF_REST, null)[0];
|
|
56
|
-
if (!rest)
|
|
57
|
-
break;
|
|
58
|
-
node = rest;
|
|
59
|
-
// if (node.value === RDF_NIL) break;
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
// Helper to get all triples for a resource (recursively, infinite depth)
|
|
64
|
-
function resolveAllTriples(node, visited = new Set()) {
|
|
65
|
-
if (visited.has(node.value))
|
|
66
|
-
return [];
|
|
67
|
-
visited.add(node.value);
|
|
68
|
-
// const triples: */ExampleTriple[] = [];
|
|
69
|
-
for (const quad of store.getQuads(subjectId, null, null, null)) {
|
|
70
|
-
const pred = typeof quad.predicate === 'string'
|
|
71
|
-
? quad.predicate
|
|
72
|
-
: quad.predicate.id || quad.predicate.value;
|
|
73
|
-
let obj;
|
|
74
|
-
if (quad.object.termType === 'Literal') {
|
|
75
|
-
obj = quad.object.value;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
obj = quad.object.id || quad.object.value;
|
|
79
|
-
}
|
|
80
|
-
triples.push({ subject: subjectId, predicate: pred, object: obj });
|
|
81
|
-
// If object is a blank node or named node, recurse
|
|
82
|
-
if (quad.object.termType === 'BlankNode' ||
|
|
83
|
-
quad.object.termType === 'NamedNode') {
|
|
84
|
-
triples.push(...resolveAllTriples(obj, visited));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return triples;
|
|
88
|
-
}
|
|
89
|
-
// Main function to parse shape.ttl and return NodeShapes
|
|
90
|
-
export function loadShapesFromTurtle(ttlFilePath) {
|
|
91
|
-
const ttlFullPath = path.resolve(__dirname, ttlFilePath);
|
|
92
|
-
const ttlData = readFileSync(ttlFullPath, 'utf8');
|
|
93
|
-
const parser = new Parser();
|
|
94
|
-
const quads = parser.parse(ttlData);
|
|
95
|
-
const store = new Store(quads);
|
|
96
|
-
// Find all NodeShapes
|
|
97
|
-
const nodeShapes = [];
|
|
98
|
-
const SH = 'http://www.w3.org/ns/shacl#';
|
|
99
|
-
const RDF_TYPE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
|
|
100
|
-
const RDFS_SEEALSO = 'http://www.w3.org/2000/01/rdf-schema#seeAlso';
|
|
101
|
-
for (const subject of store.getSubjects(RDF_TYPE, SH + 'NodeShape', null)) {
|
|
102
|
-
const id = getId(subject) || '';
|
|
103
|
-
const name = getLiteralValue(store.getObjects(subject, SH + 'name', null)[0]);
|
|
104
|
-
const targetClass = getId(store.getObjects(subject, SH + 'targetClass', null)[0]);
|
|
105
|
-
const nodeKind = getId(store.getObjects(subject, SH + 'nodeKind', null)[0]);
|
|
106
|
-
const pattern = getLiteralValue(store.getObjects(subject, SH + 'pattern', null)[0]);
|
|
107
|
-
const description = getLiteralValue(store.getObjects(subject, SH + 'description', null)[0]);
|
|
108
|
-
// Find property shapes (blank nodes)
|
|
109
|
-
const propertyNodes = store.getObjects(subject, SH + 'property', null);
|
|
110
|
-
const properties = propertyNodes.map((node) => parsePropertyShape(store, node, SH));
|
|
111
|
-
const seeAlsos = store.getObjects(subject, RDFS_SEEALSO, null);
|
|
112
|
-
for (const seeAlso of seeAlsos) {
|
|
113
|
-
// Resolve the seeAlso node and all its properties
|
|
114
|
-
}
|
|
115
|
-
nodeShapes.push({
|
|
116
|
-
id,
|
|
117
|
-
name,
|
|
118
|
-
targetClass,
|
|
119
|
-
nodeKind,
|
|
120
|
-
pattern,
|
|
121
|
-
description,
|
|
122
|
-
properties,
|
|
123
|
-
seeAlsos,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
// After all shapes are loaded, add exampleTriples to each shape if seeAlso is present
|
|
127
|
-
// for (const shape of nodeShapes) {
|
|
128
|
-
// if (shape.seeAlso) {
|
|
129
|
-
// shape.exampleTriples = resolveAllTriples(shape.seeAlso);
|
|
130
|
-
// }
|
|
131
|
-
// }
|
|
132
|
-
return nodeShapes;
|
|
133
|
-
}
|
|
134
|
-
// Example usage (uncomment to test)
|
|
135
|
-
// const shapes = loadShapesFromTurtle('../test/fixtures/shape.ttl');
|
|
136
|
-
// console.dir(shapes, { depth: null });
|
package/dist/schema.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export declare const Schema: {
|
|
2
|
-
readonly '@type': "shNodeShape";
|
|
3
|
-
readonly name: {
|
|
4
|
-
'@id': "shname";
|
|
5
|
-
'@optional': boolean;
|
|
6
|
-
};
|
|
7
|
-
readonly targetClass: "shtargetClass";
|
|
8
|
-
readonly nodeKind: {
|
|
9
|
-
readonly '@id': "shnodeKind";
|
|
10
|
-
readonly '@optional': true;
|
|
11
|
-
};
|
|
12
|
-
readonly pattern: {
|
|
13
|
-
readonly '@id': "shpattern";
|
|
14
|
-
readonly '@optional': true;
|
|
15
|
-
};
|
|
16
|
-
readonly description: {
|
|
17
|
-
readonly '@id': "shdescription";
|
|
18
|
-
readonly '@optional': true;
|
|
19
|
-
};
|
|
20
|
-
readonly property: {
|
|
21
|
-
readonly '@id': "shproperty";
|
|
22
|
-
readonly '@array': true;
|
|
23
|
-
readonly '@schema': {
|
|
24
|
-
readonly '@type': "shPropertyShape";
|
|
25
|
-
readonly name: {
|
|
26
|
-
'@id': "shname";
|
|
27
|
-
'@optional': boolean;
|
|
28
|
-
};
|
|
29
|
-
readonly path: {
|
|
30
|
-
readonly '@id': "shpath";
|
|
31
|
-
};
|
|
32
|
-
readonly minCount: {
|
|
33
|
-
readonly '@id': "shminCount";
|
|
34
|
-
readonly '@type': "xsd:nonNegativeInteger";
|
|
35
|
-
readonly '@optional': true;
|
|
36
|
-
};
|
|
37
|
-
readonly maxCount: {
|
|
38
|
-
readonly '@id': "shmaxCount";
|
|
39
|
-
readonly '@type': "xsd:nonNegativeInteger";
|
|
40
|
-
readonly '@optional': true;
|
|
41
|
-
};
|
|
42
|
-
readonly datatype: {
|
|
43
|
-
readonly '@id': "shdatatype";
|
|
44
|
-
readonly '@type': "rdfs:Datatype";
|
|
45
|
-
readonly '@optional': true;
|
|
46
|
-
};
|
|
47
|
-
readonly or: {
|
|
48
|
-
readonly '@id': "shor";
|
|
49
|
-
readonly '@optional': true;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
export declare const shapes: () => Promise<{
|
|
55
|
-
[x: string]: never;
|
|
56
|
-
[x: number]: never;
|
|
57
|
-
$id: string;
|
|
58
|
-
}[]>;
|
|
59
|
-
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AA+DA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqBT,CAAC;AASX,eAAO,MAAM,MAAM;;;;IAA0B,CAAC"}
|
package/dist/schema.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { createNamespace, createLens } from 'ldkit';
|
|
2
|
-
import { rdfs, xsd } from 'ldkit/namespaces';
|
|
3
|
-
import { QueryEngine } from '@comunica/query-sparql-file';
|
|
4
|
-
const sh = createNamespace({
|
|
5
|
-
iri: 'http://www.w3.org/ns/shacl#',
|
|
6
|
-
prefix: 'sh',
|
|
7
|
-
terms: [
|
|
8
|
-
'NodeShape',
|
|
9
|
-
'NodeKind',
|
|
10
|
-
'PropertyShape',
|
|
11
|
-
'targetClass',
|
|
12
|
-
'nodeKind',
|
|
13
|
-
'datatype',
|
|
14
|
-
'description',
|
|
15
|
-
'minCount',
|
|
16
|
-
'maxCount',
|
|
17
|
-
'name',
|
|
18
|
-
'or',
|
|
19
|
-
'pattern',
|
|
20
|
-
'path',
|
|
21
|
-
'property',
|
|
22
|
-
],
|
|
23
|
-
});
|
|
24
|
-
const NameShape = {
|
|
25
|
-
'@id': sh.name,
|
|
26
|
-
'@optional': true,
|
|
27
|
-
};
|
|
28
|
-
const PropertyShape = {
|
|
29
|
-
'@type': sh.PropertyShape,
|
|
30
|
-
name: NameShape,
|
|
31
|
-
path: {
|
|
32
|
-
'@id': sh.path,
|
|
33
|
-
},
|
|
34
|
-
minCount: {
|
|
35
|
-
'@id': sh.minCount,
|
|
36
|
-
'@type': xsd.nonNegativeInteger,
|
|
37
|
-
'@optional': true,
|
|
38
|
-
},
|
|
39
|
-
maxCount: {
|
|
40
|
-
'@id': sh.maxCount,
|
|
41
|
-
'@type': xsd.nonNegativeInteger,
|
|
42
|
-
'@optional': true,
|
|
43
|
-
},
|
|
44
|
-
datatype: {
|
|
45
|
-
'@id': sh.datatype,
|
|
46
|
-
'@type': rdfs.Datatype,
|
|
47
|
-
'@optional': true,
|
|
48
|
-
},
|
|
49
|
-
or: {
|
|
50
|
-
// '@type': rdf.CompoundLiteral,
|
|
51
|
-
// '@array': true,
|
|
52
|
-
'@id': sh.or,
|
|
53
|
-
'@optional': true,
|
|
54
|
-
// '@schema': {
|
|
55
|
-
// '@type': rdf.List,
|
|
56
|
-
// '@array': true,
|
|
57
|
-
// },
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
export const Schema = {
|
|
61
|
-
'@type': sh.NodeShape,
|
|
62
|
-
name: NameShape,
|
|
63
|
-
targetClass: sh.targetClass,
|
|
64
|
-
nodeKind: {
|
|
65
|
-
'@id': sh.nodeKind,
|
|
66
|
-
'@optional': true,
|
|
67
|
-
},
|
|
68
|
-
pattern: {
|
|
69
|
-
'@id': sh.pattern,
|
|
70
|
-
'@optional': true,
|
|
71
|
-
},
|
|
72
|
-
description: {
|
|
73
|
-
'@id': sh.description,
|
|
74
|
-
'@optional': true,
|
|
75
|
-
},
|
|
76
|
-
property: {
|
|
77
|
-
'@id': sh.property,
|
|
78
|
-
'@array': true,
|
|
79
|
-
'@schema': PropertyShape,
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
const engine = new QueryEngine();
|
|
83
|
-
const options = {
|
|
84
|
-
sources: [{ type: 'file', value: 'test/fixtures/shape.ttl' }], // ['text/fixtures/shape.ttl'],
|
|
85
|
-
engine,
|
|
86
|
-
};
|
|
87
|
-
const lens = createLens(Schema, options);
|
|
88
|
-
export const shapes = async () => lens.find();
|
package/dist/sparql.d.ts
DELETED
package/dist/sparql.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sparql.d.ts","sourceRoot":"","sources":["../src/sparql.ts"],"names":[],"mappings":"AAKA,wBAAgB,gBAAgB,IAAI,MAAM,CAgCzC;AAED,wBAAgB,6BAA6B,IAAI,MAAM,CA6BtD"}
|
package/dist/sparql.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Generator, Parser } from 'sparqljs';
|
|
2
|
-
const generator = new Generator();
|
|
3
|
-
const parser = new Parser();
|
|
4
|
-
export function buildSparqlQuery() {
|
|
5
|
-
// Use a string-based approach and parse it to ensure correct types
|
|
6
|
-
const queryString = `
|
|
7
|
-
PREFIX sh: <http://www.w3.org/ns/shacl#>
|
|
8
|
-
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
9
|
-
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
10
|
-
PREFIX schema: <https://schema.org/>
|
|
11
|
-
PREFIX dcat: <http://www.w3.org/ns/dcat#>
|
|
12
|
-
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
13
|
-
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
|
14
|
-
PREFIX dc: <http://purl.org/dc/terms/>
|
|
15
|
-
|
|
16
|
-
CONSTRUCT {
|
|
17
|
-
?shape rdf:type sh:NodeShape ;
|
|
18
|
-
?shapeProp ?shapeValue ;
|
|
19
|
-
sh:property ?property .
|
|
20
|
-
?property rdf:type sh:PropertyShape ;
|
|
21
|
-
?propProp ?propValue .
|
|
22
|
-
}
|
|
23
|
-
WHERE {
|
|
24
|
-
?shape rdf:type sh:NodeShape .
|
|
25
|
-
?shape ?shapeProp ?shapeValue .
|
|
26
|
-
|
|
27
|
-
OPTIONAL {
|
|
28
|
-
?shape sh:property ?property .
|
|
29
|
-
?property ?propProp ?propValue .
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
`;
|
|
33
|
-
const parsed = parser.parse(queryString);
|
|
34
|
-
return generator.stringify(parsed);
|
|
35
|
-
}
|
|
36
|
-
export function buildPropertyConstraintsQuery() {
|
|
37
|
-
// Additional query to handle nested constraints like sh:or, sh:and
|
|
38
|
-
const queryString = `
|
|
39
|
-
PREFIX sh: <http://www.w3.org/ns/shacl#>
|
|
40
|
-
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
41
|
-
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
42
|
-
PREFIX schema: <https://schema.org/>
|
|
43
|
-
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
44
|
-
|
|
45
|
-
CONSTRUCT {
|
|
46
|
-
?property sh:or ?orList .
|
|
47
|
-
?property sh:and ?andList .
|
|
48
|
-
?constraint ?constraintProp ?constraintValue .
|
|
49
|
-
}
|
|
50
|
-
WHERE {
|
|
51
|
-
{
|
|
52
|
-
?property sh:or ?orList .
|
|
53
|
-
} UNION {
|
|
54
|
-
?property sh:and ?andList .
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
OPTIONAL {
|
|
58
|
-
?constraint ?constraintProp ?constraintValue .
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
`;
|
|
62
|
-
const parsed = parser.parse(queryString);
|
|
63
|
-
return generator.stringify(parsed);
|
|
64
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export type LocalizedString = string | Record<string, string>;
|
|
2
|
-
export type Severity = 'sh:Violation' | 'sh:Warning' | 'sh:Info';
|
|
3
|
-
export interface Constraint {
|
|
4
|
-
'@type'?: string;
|
|
5
|
-
datatype?: string;
|
|
6
|
-
class?: string;
|
|
7
|
-
nodeKind?: string;
|
|
8
|
-
pattern?: string;
|
|
9
|
-
minLength?: number;
|
|
10
|
-
maxLength?: number;
|
|
11
|
-
minInclusive?: number;
|
|
12
|
-
maxInclusive?: number;
|
|
13
|
-
minExclusive?: number;
|
|
14
|
-
maxExclusive?: number;
|
|
15
|
-
}
|
|
16
|
-
export interface PropertyShape {
|
|
17
|
-
'@id': string;
|
|
18
|
-
'@type'?: 'sh:PropertyShape';
|
|
19
|
-
path: string;
|
|
20
|
-
name?: LocalizedString;
|
|
21
|
-
description?: LocalizedString;
|
|
22
|
-
minCount?: number;
|
|
23
|
-
maxCount?: number;
|
|
24
|
-
severity?: Severity;
|
|
25
|
-
message?: LocalizedString;
|
|
26
|
-
datatype?: string;
|
|
27
|
-
class?: string;
|
|
28
|
-
nodeKind?: string;
|
|
29
|
-
pattern?: string;
|
|
30
|
-
uniqueLang?: boolean;
|
|
31
|
-
or?: Constraint[];
|
|
32
|
-
and?: Constraint[];
|
|
33
|
-
node?: NodeShape;
|
|
34
|
-
}
|
|
35
|
-
export interface NodeShape {
|
|
36
|
-
'@id': string;
|
|
37
|
-
'@type': 'sh:NodeShape';
|
|
38
|
-
targetClass?: string;
|
|
39
|
-
class?: string;
|
|
40
|
-
nodeKind?: string;
|
|
41
|
-
pattern?: string;
|
|
42
|
-
label?: LocalizedString;
|
|
43
|
-
comment?: LocalizedString;
|
|
44
|
-
properties: PropertyShape[];
|
|
45
|
-
severity?: Severity;
|
|
46
|
-
}
|
|
47
|
-
export interface DocumentationConfig {
|
|
48
|
-
shapes: NodeShape[];
|
|
49
|
-
language?: string;
|
|
50
|
-
includeInferred?: boolean;
|
|
51
|
-
}
|
|
52
|
-
export interface TemplateData {
|
|
53
|
-
shapes: ProcessedShape[];
|
|
54
|
-
config: DocumentationConfig;
|
|
55
|
-
}
|
|
56
|
-
export interface ProcessedShape {
|
|
57
|
-
id: string;
|
|
58
|
-
name: string;
|
|
59
|
-
description?: string;
|
|
60
|
-
targetClass?: string;
|
|
61
|
-
properties: ProcessedProperty[];
|
|
62
|
-
}
|
|
63
|
-
export interface ProcessedProperty {
|
|
64
|
-
path: string;
|
|
65
|
-
name: string;
|
|
66
|
-
description?: string;
|
|
67
|
-
cardinality: string;
|
|
68
|
-
usage: 'Required' | 'Recommended' | 'Optional';
|
|
69
|
-
datatype?: string;
|
|
70
|
-
class?: string;
|
|
71
|
-
constraints?: string[];
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@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