@neverblink/linkml 0.11.2 → 0.12.0
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 +15 -13
- package/index.d.ts +29 -10
- package/main.js +57201 -44545
- package/main.js.map +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,8 @@ classes:
|
|
|
37
37
|
// Parse the schema once into a reusable handle. The second argument
|
|
38
38
|
// is an import map (filename -> YAML source) for any models referenced
|
|
39
39
|
// via LinkML \`imports:\`. Pass {} when there are none.
|
|
40
|
-
const view = LinkML.loadFromString(schema, {});
|
|
40
|
+
const { view, report } = LinkML.loadFromString(schema, {});
|
|
41
|
+
if (!view) throw new Error(JSON.stringify(report, null, 2)); // fatal problems: nothing to generate from
|
|
41
42
|
|
|
42
43
|
// Then run any generator against the loaded schema.
|
|
43
44
|
const jsonSchema = LinkML.jsonSchema(view);
|
|
@@ -60,7 +61,7 @@ There are two ways to load a schema into a `SchemaView` handle:
|
|
|
60
61
|
|
|
61
62
|
```js no-test
|
|
62
63
|
// loadFromPath: the root lives in the import map under its own path.
|
|
63
|
-
const view = LinkML.loadFromPath("model.yaml", {
|
|
64
|
+
const { view } = LinkML.loadFromPath("model.yaml", {
|
|
64
65
|
"model.yaml": schema,
|
|
65
66
|
"person.yaml": personSchema, // referenced via `imports: - person`
|
|
66
67
|
});
|
|
@@ -70,17 +71,18 @@ const view = LinkML.loadFromPath("model.yaml", {
|
|
|
70
71
|
|
|
71
72
|
Load a schema into a `SchemaView` handle (see above), then pass that handle to any generator:
|
|
72
73
|
|
|
73
|
-
| Function
|
|
74
|
-
|
|
75
|
-
| `loadFromString(schema, importMap)`
|
|
76
|
-
| `loadFromPath(path, importMap)`
|
|
77
|
-
| `jsonSchema(view, open?, treeRootOverride?)`
|
|
78
|
-
| `shacl(view, open?, onlyClassesFromRootSchema?)`
|
|
79
|
-
| `rdfs(view, onlyClassesFromRootSchema?)`
|
|
80
|
-
| `linkml(view, pruningMode?, skipDerivation?, treeRoot?, outFormat?)` | `string` | derived/pruned LinkML schema
|
|
81
|
-
| `scala(view, packageName)`
|
|
82
|
-
| `tableSchema(view, treeRoot?)`
|
|
83
|
-
| `
|
|
74
|
+
| Function | Returns | Notes |
|
|
75
|
+
|----------------------------------------------------------------------| --- |--------------------------------------------------------------|
|
|
76
|
+
| `loadFromString(schema, importMap, inferMessages?)` | `LoadResult` | parse from YAML text; `{ view?, report }` |
|
|
77
|
+
| `loadFromPath(path, importMap, inferMessages?)` | `LoadResult` | parse from a path in the import map; cycle-safe for the root |
|
|
78
|
+
| `jsonSchema(view, open?, treeRootOverride?)` | `string` | JSON Schema |
|
|
79
|
+
| `shacl(view, open?, onlyClassesFromRootSchema?)` | `string` | SHACL shapes in N-Triples |
|
|
80
|
+
| `rdfs(view, onlyClassesFromRootSchema?)` | `string` | RDFS in N-Triples |
|
|
81
|
+
| `linkml(view, pruningMode?, skipDerivation?, treeRoot?, outFormat?)` | `string` | derived/pruned LinkML schema |
|
|
82
|
+
| `scala(view, packageName)` | `Record<string, string>` | filename → generated Scala |
|
|
83
|
+
| `tableSchema(view, treeRoot?)` | `string` | Frictionless Table Schema (JSON) |
|
|
84
|
+
| `graphQl(view, pruningMode?, treeRoot?)` | `string` | GraphQL |
|
|
85
|
+
| `lint(view, inferMessages?)` | `object` | `SchemaValidationReport` (JSON) |
|
|
84
86
|
|
|
85
87
|
See [`index.d.ts`](./index.d.ts) for full type signatures.
|
|
86
88
|
|
package/index.d.ts
CHANGED
|
@@ -11,22 +11,33 @@ export interface SchemaView {
|
|
|
11
11
|
readonly __linkmlSchemaView: unique symbol;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* What loading a schema produced. There is always a report - loading is validating - and a
|
|
16
|
+
* `view` unless the schema had fatal problems.
|
|
17
|
+
*/
|
|
18
|
+
export interface LoadResult {
|
|
19
|
+
readonly view?: SchemaView;
|
|
20
|
+
readonly report: any;
|
|
21
|
+
}
|
|
22
|
+
|
|
14
23
|
export interface LinkMLApi {
|
|
15
24
|
/**
|
|
16
25
|
* Load and resolve a LinkML schema into a reusable [[SchemaView]] handle, starting from the schema's YAML text. The main schema is parsed directly from `mainSchema`, so it has no path of its own. If one of its imports (transitively) imports the main schema back by filename, that import cannot be matched against the root and the main schema will be loaded a second time. Use [[loadFromPath]] instead when the root schema takes part in an import cycle.
|
|
17
26
|
* @param mainSchema Main LinkML model in YAML format. It may import other models using LinkML `imports`, but all imports must be made available in the [[importMap]].
|
|
18
27
|
* @param importMap JS dictionary (object) containing a mapping from filename to LinkML models (in YAML format)
|
|
19
|
-
* @
|
|
28
|
+
* @param inferMessages Whether to fill in each issue's human-readable `message` and `details`.
|
|
29
|
+
* @returns The validation report, and a handle to pass to the generator functions unless the schema had fatal problems.
|
|
20
30
|
*/
|
|
21
|
-
loadFromString(mainSchema: string, importMap: Record<string, string
|
|
31
|
+
loadFromString(mainSchema: string, importMap: Record<string, string>, inferMessages?: boolean): LoadResult;
|
|
22
32
|
|
|
23
33
|
/**
|
|
24
34
|
* Load and resolve a LinkML schema into a reusable [[SchemaView]] handle, starting from a path into the [[importMap]]. Unlike [[loadFromString]], the main schema is read through the import map by its own path, so it is tracked from the start of import resolution. This makes it immune to cyclic imports involving the root schema: an import that (transitively) references the root back by path resolves to the already-loaded root instead of loading it again. Paths behave like file paths: a `.yaml` extension is appended when missing, and relative imports are resolved against the directory of their importing schema. The [[importMap]] keys must therefore be the paths as seen from the root (e.g. `"model.yaml"`, `"nested/person.yaml"`).
|
|
25
35
|
* @param path Path of the main LinkML model within the [[importMap]] (e.g. `"model.yaml"`).
|
|
26
36
|
* @param importMap JS dictionary (object) containing a mapping from path to LinkML models (in YAML format), including the main schema itself under [[path]].
|
|
27
|
-
* @
|
|
37
|
+
* @param inferMessages Whether to fill in each issue's human-readable `message` and `details`.
|
|
38
|
+
* @returns The validation report, and a handle to pass to the generator functions unless the schema had fatal problems.
|
|
28
39
|
*/
|
|
29
|
-
loadFromPath(path: string, importMap: Record<string, string
|
|
40
|
+
loadFromPath(path: string, importMap: Record<string, string>, inferMessages?: boolean): LoadResult;
|
|
30
41
|
|
|
31
42
|
/**
|
|
32
43
|
* Generate JSON Schema from a loaded LinkML schema.
|
|
@@ -65,7 +76,7 @@ export interface LinkMLApi {
|
|
|
65
76
|
/**
|
|
66
77
|
* Materialize a derived LinkML schema from a loaded LinkML schema. Derives classes and prunes unreachable elements.
|
|
67
78
|
* @param schema A [[SchemaView]] handle created with [[loadFromString]] or [[loadFromPath]].
|
|
68
|
-
* @param pruningMode Pruning mode to use for removing unused elements (classes, types, enums). One of treeRoot|
|
|
79
|
+
* @param pruningMode Pruning mode to use for removing unused elements (classes, types, enums). One of treeRoot|schema|skip. treeRoot - remove all elements unreachable from the tree_root class. schema - remove all elements unreachable from any of the classes defined in the root schema. skip - do not remove unused elements. Default: treeRoot
|
|
69
80
|
* @param skipDerivation If true, will not derive classes and instead copy them as-is.
|
|
70
81
|
* @param treeRoot Tree root class name to use instead of the schema defined tree_root. Does nothing if not in tree root pruning mode.
|
|
71
82
|
* @param outFormat Output serialization format to use. One of yaml|json. Default: yaml
|
|
@@ -82,13 +93,21 @@ export interface LinkMLApi {
|
|
|
82
93
|
tableSchema(schema: SchemaView, treeRoot?: string): string;
|
|
83
94
|
|
|
84
95
|
/**
|
|
85
|
-
*
|
|
96
|
+
* Generate a GraphQL Schema from a loaded LinkML schema. Only types/interfaces/scalar/enums, queries must be provided for a specific implementation.
|
|
97
|
+
* @param schema A [[SchemaView]] handle created with [[loadFromString]] or [[loadFromPath]].
|
|
98
|
+
* @param pruningMode Pruning mode to use for removing unused elements (classes, types, enums). One of treeRoot|schema|skip. treeRoot - remove all elements unreachable from the tree_root class. schema - remove all elements unreachable from any of the classes defined in the root schema. skip - do not remove unused elements. Default: treeRoot
|
|
99
|
+
* @param treeRoot Tree root class name to use instead of the schema defined tree_root.
|
|
100
|
+
* @returns Table Schema, serialized as a JSON
|
|
101
|
+
*/
|
|
102
|
+
graphQl(schema: SchemaView, pruningMode?: string, treeRoot?: string): string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Lint a loaded LinkML schema, finding problems that may cause issues when using the model. This method returns a structured JSON that follows the validation-report.yaml model. TODO: consider typing the return value in TypeScript using a TypeScript generator. See: https://github.com/NeverBlink-OSS/linkml-scala/issues/127
|
|
86
106
|
* @param schema A [[SchemaView]] handle created with [[loadFromString]] or [[loadFromPath]].
|
|
87
|
-
* @param
|
|
88
|
-
* @
|
|
89
|
-
* @returns The summary of detected problems, or an empty string if everything is correct
|
|
107
|
+
* @param inferMessages Whether to fill in each issue's human-readable `message` and `details` from the model's `equals_expression`s. Turn it off to get only the structured fields.
|
|
108
|
+
* @returns A `SchemaValidationReport` as a plain JS object. `issues` is empty if the schema is clean.
|
|
90
109
|
*/
|
|
91
|
-
lint(schema: SchemaView,
|
|
110
|
+
lint(schema: SchemaView, inferMessages?: boolean): any;
|
|
92
111
|
}
|
|
93
112
|
|
|
94
113
|
export declare const LinkML: LinkMLApi;
|