@neverblink/linkml 0.8.7-5-25b1515-SNAPSHOT
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 +62 -0
- package/index.d.ts +65 -0
- package/main.js +104896 -0
- package/main.js.map +8 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @neverblink/linkml
|
|
2
|
+
|
|
3
|
+
JavaScript / TypeScript bindings for [LinkML-Scala](https://github.com/NeverBlink-OSS/linkml-scala) —
|
|
4
|
+
LinkML schema validation and multi-format code generation (JSON Schema, SHACL, RDFS, Scala),
|
|
5
|
+
compiled from Scala 3 to JavaScript via [Scala.js](https://www.scala-js.org/).
|
|
6
|
+
|
|
7
|
+
The package ships a single self-contained ES module. It has no runtime dependencies.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
npm install @neverblink/linkml
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { LinkML } from "@neverblink/linkml";
|
|
19
|
+
|
|
20
|
+
const schema = `
|
|
21
|
+
id: https://example.org/my-schema
|
|
22
|
+
name: my-schema
|
|
23
|
+
default_range: string
|
|
24
|
+
classes:
|
|
25
|
+
Person:
|
|
26
|
+
attributes:
|
|
27
|
+
name:
|
|
28
|
+
age:
|
|
29
|
+
range: integer
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
// The second argument is an import map (filename -> YAML source) for any
|
|
33
|
+
// models referenced via LinkML \`imports:\`. Pass {} when there are none.
|
|
34
|
+
const jsonSchema = LinkML.jsonSchema(schema, {});
|
|
35
|
+
console.log(jsonSchema);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Available functions
|
|
39
|
+
|
|
40
|
+
| Function | Returns | Notes |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| `jsonSchema(schema, importMap, open?, treeRootOverride?)` | `string` | JSON Schema |
|
|
43
|
+
| `shacl(schema, importMap, open?)` | `string` | SHACL shapes in N-Triples |
|
|
44
|
+
| `scala(schema, importMap, packageName)` | `Record<string, string>` | filename → generated Scala |
|
|
45
|
+
| `lint(schema, importMap, maxProblems?, verbose?)` | `string` | problem summary, empty if valid |
|
|
46
|
+
|
|
47
|
+
See [`index.d.ts`](./index.d.ts) for full type signatures.
|
|
48
|
+
|
|
49
|
+
## Browser use
|
|
50
|
+
|
|
51
|
+
The module works in Node.js as-is. In the browser it references `process.cwd`
|
|
52
|
+
once, so provide a minimal shim before importing:
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<script>
|
|
56
|
+
var process = { cwd: () => "/" };
|
|
57
|
+
</script>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
Apache-2.0 © [NeverBlink](https://neverblink.eu)
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript declarations for the LinkML-Scala JS library (`@neverblink/linkml`).
|
|
3
|
+
*
|
|
4
|
+
* The implementation is generated from Scala by Scala.js; this file is
|
|
5
|
+
* hand-maintained and must be kept in sync with
|
|
6
|
+
* `generator/src-js/eu/neverblink/linkml/js/LinkMlJsApi.scala`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Mapping from imported model filename to its LinkML model source (YAML).
|
|
11
|
+
* Every `imports:` entry referenced by the main schema must have a matching
|
|
12
|
+
* entry here.
|
|
13
|
+
*/
|
|
14
|
+
export type ImportMap = Record<string, string>;
|
|
15
|
+
|
|
16
|
+
export interface LinkMLApi {
|
|
17
|
+
/**
|
|
18
|
+
* Generate JSON Schema from the provided LinkML model.
|
|
19
|
+
*
|
|
20
|
+
* @param mainSchema Main LinkML model in YAML format.
|
|
21
|
+
* @param importMap Mapping from filename to LinkML models (YAML) for imports.
|
|
22
|
+
* @param open Whether the JSON Schema should allow `additionalProperties`. Defaults to `false`.
|
|
23
|
+
* @param treeRootOverride Override for the LinkML `tree_root` class at the root of the schema.
|
|
24
|
+
* @returns Serialized JSON Schema.
|
|
25
|
+
*/
|
|
26
|
+
jsonSchema(
|
|
27
|
+
mainSchema: string,
|
|
28
|
+
importMap: ImportMap,
|
|
29
|
+
open?: boolean,
|
|
30
|
+
treeRootOverride?: string,
|
|
31
|
+
): string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Generate SHACL shapes (in N-Triples format) from the provided LinkML model.
|
|
35
|
+
*
|
|
36
|
+
* @param mainSchema Main LinkML model in YAML format.
|
|
37
|
+
* @param importMap Mapping from filename to LinkML models (YAML) for imports.
|
|
38
|
+
* @param open Whether the SHACL shapes should be open (allowing additional properties). Defaults to `false`.
|
|
39
|
+
* @returns SHACL shapes in N-Triples format.
|
|
40
|
+
*/
|
|
41
|
+
shacl(mainSchema: string, importMap: ImportMap, open?: boolean): string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generate Scala code from the provided LinkML model.
|
|
45
|
+
*
|
|
46
|
+
* @param mainSchema Main LinkML model in YAML format.
|
|
47
|
+
* @param importMap Mapping from filename to LinkML models (YAML) for imports.
|
|
48
|
+
* @param packageName Package to generate the classes in.
|
|
49
|
+
* @returns Mapping from filename to the generated Scala source.
|
|
50
|
+
*/
|
|
51
|
+
scala(mainSchema: string, importMap: ImportMap, packageName: string): Record<string, string>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Lint the provided LinkML model, reporting problems that may cause issues.
|
|
55
|
+
*
|
|
56
|
+
* @param mainSchema Main LinkML model in YAML format.
|
|
57
|
+
* @param importMap Mapping from filename to LinkML models (YAML) for imports.
|
|
58
|
+
* @param maxProblems Maximum number of problems to include in the summary. Defaults to `5`.
|
|
59
|
+
* @param verbose Whether to use the more verbose problem descriptions. Defaults to `false`.
|
|
60
|
+
* @returns The summary of detected problems, or an empty string if everything is correct.
|
|
61
|
+
*/
|
|
62
|
+
lint(mainSchema: string, importMap: ImportMap, maxProblems?: number, verbose?: boolean): string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export declare const LinkML: LinkMLApi;
|