@neverblink/linkml 0.9.2 → 0.10.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.
Files changed (5) hide show
  1. package/README.md +41 -11
  2. package/index.d.ts +47 -28
  3. package/main.js +20310 -20240
  4. package/main.js.map +4 -4
  5. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @neverblink/linkml
2
2
 
3
- JavaScript / TypeScript bindings for [LinkML-Scala](https://github.com/NeverBlink-OSS/linkml-scala) —
3
+ JavaScript / TypeScript bindings for [LinkML-Scala](https://github.com/NeverBlink-OSS/linkml-scala) –
4
4
  LinkML schema validation and multi-format code generation (JSON Schema, SHACL, RDFS, Scala),
5
5
  compiled from Scala 3 to JavaScript via [Scala.js](https://www.scala-js.org/).
6
6
 
@@ -34,23 +34,53 @@ classes:
34
34
  range: integer
35
35
  `;
36
36
 
37
- // The second argument is an import map (filename -> YAML source) for any
38
- // models referenced via LinkML \`imports:\`. Pass {} when there are none.
39
- const jsonSchema = LinkML.jsonSchema(schema, {});
37
+ // Parse the schema once into a reusable handle. The second argument
38
+ // is an import map (filename -> YAML source) for any models referenced
39
+ // via LinkML \`imports:\`. Pass {} when there are none.
40
+ const view = LinkML.loadFromString(schema, {});
41
+
42
+ // Then run any generator against the loaded schema.
43
+ const jsonSchema = LinkML.jsonSchema(view);
40
44
  console.log(jsonSchema);
45
+
46
+ const shacl = LinkML.shacl(view);
47
+ console.log(shacl);
48
+ ```
49
+
50
+ ### Loading
51
+
52
+ There are two ways to load a schema into a `SchemaView` handle:
53
+
54
+ - `loadFromString(schema, importMap)` – start from the schema's YAML text. Imported models
55
+ must be provided in the import map (filename → YAML).
56
+ - `loadFromPath(path, importMap)` – start from a path into the import map. The root schema is
57
+ read from `importMap[path]` (paths behave like file paths, `.yaml` is appended when missing).
58
+ Because the root is tracked from the start of import resolution, this variant is immune to
59
+ cyclic imports that reference the root schema back.
60
+
61
+ ```js no-test
62
+ // loadFromPath: the root lives in the import map under its own path.
63
+ const view = LinkML.loadFromPath("model.yaml", {
64
+ "model.yaml": schema,
65
+ "person.yaml": personSchema, // referenced via `imports: - person`
66
+ });
41
67
  ```
42
68
 
43
69
  ### Available functions
44
70
 
71
+ Load a schema into a `SchemaView` handle (see above), then pass that handle to any generator:
72
+
45
73
  | Function | Returns | Notes |
46
74
  | --- | --- | --- |
47
- | `jsonSchema(schema, importMap, open?, treeRootOverride?)` | `string` | JSON Schema |
48
- | `shacl(schema, importMap, open?, onlyClassesFromRootSchema?)` | `string` | SHACL shapes in N-Triples |
49
- | `rdfs(schema, importMap, onlyClassesFromRootSchema?)` | `string` | RDFS in N-Triples |
50
- | `linkml(schema, importMap, pruningMode?, skipDerivation?, treeRoot?, outFormat?)` | `string` | derived/pruned LinkML schema |
51
- | `scala(schema, importMap, packageName)` | `Record<string, string>` | filename → generated Scala |
52
- | `tableSchema(schema, importMap, treeRoot?)` | `string` | Frictionless Table Schema (JSON) |
53
- | `lint(schema, importMap, maxProblems?, verbose?)` | `string` | problem summary, empty if valid |
75
+ | `loadFromString(schema, importMap)` | `SchemaView` | parse from YAML text; reuse the handle |
76
+ | `loadFromPath(path, importMap)` | `SchemaView` | parse from a path in the import map; cycle-safe for the root |
77
+ | `jsonSchema(view, open?, treeRootOverride?)` | `string` | JSON Schema |
78
+ | `shacl(view, open?, onlyClassesFromRootSchema?)` | `string` | SHACL shapes in N-Triples |
79
+ | `rdfs(view, onlyClassesFromRootSchema?)` | `string` | RDFS in N-Triples |
80
+ | `linkml(view, pruningMode?, skipDerivation?, treeRoot?, outFormat?)` | `string` | derived/pruned LinkML schema |
81
+ | `scala(view, packageName)` | `Record<string, string>` | filename → generated Scala |
82
+ | `tableSchema(view, treeRoot?)` | `string` | Frictionless Table Schema (JSON) |
83
+ | `lint(view, maxProblems?, verbose?)` | `string` | problem summary, empty if valid |
54
84
 
55
85
  See [`index.d.ts`](./index.d.ts) for full type signatures.
56
86
 
package/index.d.ts CHANGED
@@ -1,75 +1,94 @@
1
1
  // AUTO-GENERATED from generator/src-js/eu/neverblink/linkml/js/LinkMlJsApi.scala.
2
- // Do not edit by hand — regenerate with ./mill uiTypes (or generator.js.npmPackage).
2
+ // Do not edit by hand – regenerate with ./mill uiTypes (or generator.js.npmPackage).
3
+
4
+ /**
5
+ * Opaque handle to a loaded, import-resolved LinkML schema. Create one with
6
+ * {@link LinkMLApi.load} and pass it to the generator functions. Parse a schema
7
+ * once and reuse the handle, instead of re-parsing the YAML on every call.
8
+ */
9
+ export interface SchemaView {
10
+ /** @internal Nominal brand – do not access. */
11
+ readonly __linkmlSchemaView: unique symbol;
12
+ }
3
13
 
4
14
  export interface LinkMLApi {
5
15
  /**
6
- * Generate JSON Schema from the provided LinkML model
16
+ * 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.
7
17
  * @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]].
8
18
  * @param importMap JS dictionary (object) containing a mapping from filename to LinkML models (in YAML format)
19
+ * @returns An opaque [[SchemaView]] handle to pass to the generator functions.
20
+ */
21
+ loadFromString(mainSchema: string, importMap: Record<string, string>): SchemaView;
22
+
23
+ /**
24
+ * 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
+ * @param path Path of the main LinkML model within the [[importMap]] (e.g. `"model.yaml"`).
26
+ * @param importMap JS dictionary (object) containing a mapping from path to LinkML models (in YAML format), including the main schema itself under [[path]].
27
+ * @returns An opaque [[SchemaView]] handle to pass to the generator functions.
28
+ */
29
+ loadFromPath(path: string, importMap: Record<string, string>): SchemaView;
30
+
31
+ /**
32
+ * Generate JSON Schema from a loaded LinkML schema.
33
+ * @param schema A [[SchemaView]] handle created with [[loadFromString]] or [[loadFromPath]].
9
34
  * @param open Whether the JSON Schema should allow `additionalProperties` or not.
10
35
  * @param treeRootOverride Override for the LinkML `tree_root` class which will be at the root of the JSON Schema.
11
36
  * @returns Serialized JSON Schema
12
37
  */
13
- jsonSchema(mainSchema: string, importMap: Record<string, string>, open?: boolean, treeRootOverride?: string): string;
38
+ jsonSchema(schema: SchemaView, open?: boolean, treeRootOverride?: string): string;
14
39
 
15
40
  /**
16
- * Generate SHACL shapes (in N-Triples format) from the provided LinkML model
17
- * @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
- * @param importMap JS dictionary (object) containing a mapping from filename to LinkML models (in YAML format)
41
+ * Generate SHACL shapes (in N-Triples format) from a loaded LinkML schema.
42
+ * @param schema A [[SchemaView]] handle created with [[loadFromString]] or [[loadFromPath]].
19
43
  * @param open Whether the SHACL shapes should be open (`_:b sh:closed false .`, allowing additional properties).
20
44
  * @param onlyClassesFromRootSchema Whether to include only classes from the root schema (turned off by default). This is useful if you intend to generate SHACL shapes for each schema file separately, and you don't need the imported classes to be included in the generated SHACL shapes.
21
45
  * @returns SHACL shapes in N-Triples format
22
46
  */
23
- shacl(mainSchema: string, importMap: Record<string, string>, open?: boolean, onlyClassesFromRootSchema?: boolean): string;
47
+ shacl(schema: SchemaView, open?: boolean, onlyClassesFromRootSchema?: boolean): string;
24
48
 
25
49
  /**
26
- * Generate Scala code from the provided LinkML model. This is primarily used for the metamodel
27
- * @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]].
28
- * @param importMap JS dictionary (object) containing a mapping from filename to LinkML models (in YAML format)
50
+ * Generate Scala code from a loaded LinkML schema. This is primarily used for the metamodel
51
+ * @param schema A [[SchemaView]] handle created with [[loadFromString]] or [[loadFromPath]].
29
52
  * @param packageName Package to generate the classes in
30
53
  * @returns JS dictionary (object) containing a mapping from filename to the generated Scala code.
31
54
  */
32
- scala(mainSchema: string, importMap: Record<string, string>, packageName: string): Record<string, string>;
55
+ scala(schema: SchemaView, packageName: string): Record<string, string>;
33
56
 
34
57
  /**
35
- * Generate RDFS from the provided LinkML model.
36
- * @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]].
37
- * @param importMap JS dictionary (object) containing a mapping from filename to LinkML models (in YAML format)
58
+ * Generate RDFS from a loaded LinkML schema.
59
+ * @param schema A [[SchemaView]] handle created with [[loadFromString]] or [[loadFromPath]].
38
60
  * @param onlyClassesFromRootSchema Whether to include only classes from the root schema (turned off by default). This is useful if you intend to generate SHACL shapes for each schema file separately, and you don't need the imported classes to be included in the generated SHACL shapes.
39
- * @returns JS dictionary (object) containing a mapping from filename to the generated Scala code.
61
+ * @returns RDFS in N-Triples format
40
62
  */
41
- rdfs(mainSchema: string, importMap: Record<string, string>, onlyClassesFromRootSchema: boolean): string;
63
+ rdfs(schema: SchemaView, onlyClassesFromRootSchema?: boolean): string;
42
64
 
43
65
  /**
44
- * Materialize a derived LinkML schema from a LinkML model. Resolves imports, derives classes, and prunes unreachable elements.
45
- * @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]].
46
- * @param importMap JS dictionary (object) containing a mapping from filename to LinkML models (in YAML format)
66
+ * Materialize a derived LinkML schema from a loaded LinkML schema. Derives classes and prunes unreachable elements.
67
+ * @param schema A [[SchemaView]] handle created with [[loadFromString]] or [[loadFromPath]].
47
68
  * @param pruningMode Pruning mode to use for removing unused elements (classes, types, enums). One of treeRoot|schemaRoot|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
48
69
  * @param skipDerivation If true, will not derive classes and instead copy them as-is.
49
70
  * @param treeRoot Tree root class name to use instead of the schema defined tree_root. Does nothing if not in tree root pruning mode.
50
71
  * @param outFormat Output serialization format to use. One of yaml|json. Default: yaml
51
72
  * @returns The derived [[SchemaDefinition]] serialized in the specified format.
52
73
  */
53
- linkml(mainSchema: string, importMap: Record<string, string>, pruningMode?: string, skipDerivation?: boolean, treeRoot?: string, outFormat?: string): string;
74
+ linkml(schema: SchemaView, pruningMode?: string, skipDerivation?: boolean, treeRoot?: string, outFormat?: string): string;
54
75
 
55
76
  /**
56
- * Generate a Frictionless Table Schema from a LinkML model.
57
- * @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]].
58
- * @param importMap JS dictionary (object) containing a mapping from filename to LinkML models (in YAML format)
77
+ * Generate a Frictionless Table Schema from a loaded LinkML schema.
78
+ * @param schema A [[SchemaView]] handle created with [[loadFromString]] or [[loadFromPath]].
59
79
  * @param treeRoot Tree root class name to use instead of the schema defined tree_root.
60
80
  * @returns Table Schema, serialized as a JSON
61
81
  */
62
- tableSchema(mainSchema: string, importMap: Record<string, string>, treeRoot?: string): string;
82
+ tableSchema(schema: SchemaView, treeRoot?: string): string;
63
83
 
64
84
  /**
65
- * Lint the provided LinkML model, finding problems that may cause issues when using the model.
66
- * @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]].
67
- * @param importMap JS dictionary (object) containing a mapping from filename to LinkML models (in YAML format)
85
+ * Lint a loaded LinkML schema, finding problems that may cause issues when using the model.
86
+ * @param schema A [[SchemaView]] handle created with [[loadFromString]] or [[loadFromPath]].
68
87
  * @param maxProblems Maximum number of problems to include in the summary
69
88
  * @param verbose Whether to use the more verbose problem descriptions
70
89
  * @returns The summary of detected problems, or an empty string if everything is correct
71
90
  */
72
- lint(mainSchema: string, importMap: Record<string, string>, maxProblems?: number, verbose?: boolean): string;
91
+ lint(schema: SchemaView, maxProblems?: number, verbose?: boolean): string;
73
92
  }
74
93
 
75
94
  export declare const LinkML: LinkMLApi;