mdmodels-core 0.1.7 → 0.2.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 CHANGED
@@ -1,13 +1,25 @@
1
-
2
1
  # MD-Models
3
2
 
4
- ![Build Status](https://github.com/JR-1991/sdrdm.rs/actions/workflows/test.yml/badge.svg)
3
+ ![Crates.io Version](https://img.shields.io/crates/v/mdmodels) ![NPM Version](https://img.shields.io/npm/v/mdmodels-core)
4
+ ![PyPI - Version](https://img.shields.io/pypi/v/mdmodels-core)
5
+ ![Build Status](https://github.com/JR-1991/sdrdm.rs/actions/workflows/test.yml/badge.svg)
5
6
 
6
- Welcome to Markdown Models (MD-Models), a powerful framework for research data management that prioritizes flexibility and efficiency.
7
+ Welcome to Markdown Models (MD-Models), a powerful framework for research data management that prioritizes narrative and readability for data models.
7
8
 
8
9
  With an adaptable markdown-based schema language, MD-Models automatically generates schemas and programming language representations. This markdown schema forms the foundation for object-oriented models, enabling seamless cross-format compatibility and simplifying modifications to data structures.
9
10
 
10
- Check out the [documentation](https://fairchemistry.github.io/md-models/) for more information.
11
+ ## Core Philosophy
12
+
13
+ The primary motivation behind MD-Models is to reduce cognitive overhead and maintenance burden by unifying documentation and structural definition into a single source of truth. Traditional approaches often require maintaining separate artifacts:
14
+
15
+ 1. Technical schemas (JSON Schema, XSD, ShEx, SHACL)
16
+ 2. Programming language implementations
17
+ 3. Documentation for domain experts
18
+ 4. API documentation
19
+
20
+ This separation frequently leads to documentation drift and increases the cognitive load on both developers and domain experts.
21
+
22
+ Check out the [documentation and graph editor](https://mdmodels.vercel.app/?about) for more information.
11
23
 
12
24
  ### Example
13
25
 
@@ -71,10 +83,42 @@ The following templates are available:
71
83
  - `python-dataclass`: Python dataclass implementation with JSON-LD support
72
84
  - `python-pydantic`: PyDantic implementation with JSON-LD support
73
85
  - `python-pydantic-xml`: PyDantic implementation with XML support
86
+ - `typescript`: TypeScript interface definitions with JSON-LD support
87
+ - `typescript-zod`: TypeScript Zod schema definitions
88
+ - `rust`: Rust struct definitions with serde support
89
+ - `golang`: Go struct definitions
90
+ - `protobuf`: Protocol Buffer schema definition
91
+ - `graphql`: GraphQL schema definition
74
92
  - `xml-schema`: XML schema definition
75
93
  - `json-schema`: JSON schema definition
94
+ - `json-schema-all`: Multiple JSON schema definitions (one per object)
76
95
  - `shacl`: SHACL shapes definition
77
96
  - `shex`: ShEx shapes definition
97
+ - `compact-markdown`: Compact markdown representation
98
+ - `mkdocs`: MkDocs documentation format
99
+ - `linkml`: LinkML schema definition
100
+
101
+ ## Installation options
102
+
103
+ The main Rust crate is compiled to Python and WebAssembly, allowing the usage beyond the command line tool. These are the main packages:
104
+
105
+ - **[Core Python Package](https://pypi.org/project/mdmodels-core/)**: Install via pip:
106
+ ```bash
107
+ # Mainly used to access the core functionality of the library
108
+ pip install mdmodels-core
109
+ ```
110
+
111
+ - **[Python Package](https://github.com/FAIRChemistry/py-mdmodels/tree/master)**: Install via pip:
112
+ ```bash
113
+ # Provides in-memory data models, database support, LLM support, etc.
114
+ pip install mdmodels
115
+ ```
116
+
117
+ - **[NPM Package](https://www.npmjs.com/package/mdmodels-core)**: Install via npm:
118
+ ```bash
119
+ # Mainly used to access the core functionality of the library
120
+ npm install mdmodels-core
121
+ ```
78
122
 
79
123
  ## Development
80
124
 
@@ -9,11 +9,9 @@
9
9
  *
10
10
  * # Returns
11
11
  *
12
- * A `Result` which is:
13
- * - `Ok(JsValue)` if the parsing and serialization are successful.
14
- * - `Err(JsValue)` if there is an error during parsing or serialization.
12
+ * A `DataModel` or an error `JsError`.
15
13
  */
16
- export function parse_model(markdown_content: string): any;
14
+ export function parse_model(markdown_content: string): DataModel;
17
15
  /**
18
16
  * Converts the given markdown content into a specified template format.
19
17
  *
@@ -46,7 +44,7 @@ export function convert_to(markdown_content: string, template: Templates): strin
46
44
  */
47
45
  export function json_schema(markdown_content: string, root: string | undefined, openai: boolean): string;
48
46
  /**
49
- * Validates the given markdown content and returns the validation result as a `JsValue`.
47
+ * Validates the given markdown content and returns the validation result as a `Validator`.
50
48
  *
51
49
  * # Arguments
52
50
  *
@@ -54,11 +52,9 @@ export function json_schema(markdown_content: string, root: string | undefined,
54
52
  *
55
53
  * # Returns
56
54
  *
57
- * A `Result` which is:
58
- * - `Ok(JsValue)` if the validation is successful.
59
- * - `Err(JsValue)` if there is an error during parsing or validation.
55
+ * Either an empty `Validator` or an error `Validator`.
60
56
  */
61
- export function validate(markdown_content: string): any;
57
+ export function validate(markdown_content: string): Validator;
62
58
  /**
63
59
  * Enumeration of available templates.
64
60
  */
@@ -76,4 +72,225 @@ export enum Templates {
76
72
  MkDocs = 10,
77
73
  Internal = 11,
78
74
  Typescript = 12,
75
+ TypescriptZod = 13,
76
+ Rust = 14,
77
+ Protobuf = 15,
78
+ Graphql = 16,
79
+ Golang = 17,
80
+ Linkml = 18,
81
+ }
82
+ /**
83
+ * Validator for checking the integrity of a data model.
84
+ */
85
+ export interface Validator {
86
+ is_valid: boolean;
87
+ errors: ValidationError[];
88
+ }
89
+
90
+ /**
91
+ * Enum representing the type of validation error.
92
+ */
93
+ export type ErrorType = "NameError" | "TypeError" | "DuplicateError" | "GlobalError";
94
+
95
+ /**
96
+ * Represents a validation error in the data model.
97
+ */
98
+ export interface ValidationError {
99
+ message: string;
100
+ object: string | undefined;
101
+ attribute: string | undefined;
102
+ location: string;
103
+ error_type: ErrorType;
104
+ positions: Position[];
105
+ }
106
+
107
+ export interface PositionRange {
108
+ start: number;
109
+ end: number;
110
+ }
111
+
112
+ export interface Position {
113
+ line: number;
114
+ column: PositionRange;
115
+ offset: PositionRange;
116
+ }
117
+
118
+ /**
119
+ * Represents the front matter data of a markdown file.
120
+ */
121
+ export interface FrontMatter {
122
+ /**
123
+ * A boolean field with a default value, renamed from `id-field`.
124
+ */
125
+ "id-field"?: boolean;
126
+ /**
127
+ * Optional hashmap of prefixes.
128
+ */
129
+ prefixes: Map<string, string> | undefined;
130
+ /**
131
+ * Optional namespace map.
132
+ */
133
+ nsmap: Map<string, string> | undefined;
134
+ /**
135
+ * A string field with a default value representing the repository URL.
136
+ */
137
+ repo?: string;
138
+ /**
139
+ * A string field with a default value representing the prefix.
140
+ */
141
+ prefix?: string;
142
+ }
143
+
144
+ export type DataType = { Boolean: boolean } | { Integer: number } | { Float: number } | { String: string };
145
+
146
+ /**
147
+ * Represents an attribute with various properties and options.
148
+ */
149
+ export interface Attribute {
150
+ /**
151
+ * The name of the attribute.
152
+ */
153
+ name: string;
154
+ /**
155
+ * Indicates if the attribute is an array.
156
+ */
157
+ multiple: boolean;
158
+ /**
159
+ * Is an identifier or not
160
+ */
161
+ is_id: boolean;
162
+ /**
163
+ * Data types associated with the attribute.
164
+ */
165
+ dtypes: string[];
166
+ /**
167
+ * Documentation string for the attribute.
168
+ */
169
+ docstring: string;
170
+ /**
171
+ * List of additional options for the attribute.
172
+ */
173
+ options: AttrOption[];
174
+ /**
175
+ * Term associated with the attribute, if any.
176
+ */
177
+ term: string | undefined;
178
+ /**
179
+ * Indicates if the attribute is required.
180
+ */
181
+ required: boolean;
182
+ /**
183
+ * Default value for the attribute.
184
+ */
185
+ default?: DataType;
186
+ /**
187
+ * XML type information for the attribute.
188
+ */
189
+ xml?: XMLType;
190
+ /**
191
+ * Is an enumeration or not
192
+ */
193
+ is_enum: boolean;
194
+ /**
195
+ * The line number of the attribute
196
+ */
197
+ position: Position | undefined;
79
198
  }
199
+
200
+ export interface DataModel {
201
+ name?: string;
202
+ objects: Object[];
203
+ enums: Enumeration[];
204
+ config?: FrontMatter;
205
+ }
206
+
207
+ /**
208
+ * Represents an enumeration with a name and mappings.
209
+ */
210
+ export interface Enumeration {
211
+ /**
212
+ * Name of the enumeration.
213
+ */
214
+ name: string;
215
+ /**
216
+ * Mappings associated with the enumeration.
217
+ */
218
+ mappings: Map<string, string>;
219
+ /**
220
+ * Documentation string for the enumeration.
221
+ */
222
+ docstring: string;
223
+ /**
224
+ * The line number of the enumeration
225
+ */
226
+ position: Position | undefined;
227
+ }
228
+
229
+ /**
230
+ * Represents an object with a name, attributes, docstring, and an optional term.
231
+ */
232
+ export interface Object {
233
+ /**
234
+ * Name of the object.
235
+ */
236
+ name: string;
237
+ /**
238
+ * List of attributes associated with the object.
239
+ */
240
+ attributes: Attribute[];
241
+ /**
242
+ * Documentation string for the object.
243
+ */
244
+ docstring: string;
245
+ /**
246
+ * Optional term associated with the object.
247
+ */
248
+ term?: string;
249
+ /**
250
+ * Parent object of the object.
251
+ */
252
+ parent?: string;
253
+ /**
254
+ * The line number of the object
255
+ */
256
+ position?: Position;
257
+ }
258
+
259
+ /**
260
+ * Represents an XML type, either an attribute or an element.
261
+ */
262
+ export type XMLType = { Attribute: { is_attr: boolean; name: string } } | { Element: { is_attr: boolean; name: string } };
263
+
264
+ /**
265
+ * A raw key-value representation of an attribute option.
266
+ *
267
+ * This struct provides a simple string-based representation of options,
268
+ * which is useful for serialization/deserialization and when working
269
+ * with untyped data.
270
+ */
271
+ export interface RawOption {
272
+ /**
273
+ * The key/name of the option
274
+ */
275
+ key: string;
276
+ /**
277
+ * The string value of the option
278
+ */
279
+ value: string;
280
+ }
281
+
282
+ /**
283
+ * Represents an option for an attribute in a data model.
284
+ *
285
+ * This enum provides a strongly-typed representation of various attribute options
286
+ * that can be used to configure and constrain attributes in a data model.
287
+ *
288
+ * The options are grouped into several categories:
289
+ * - JSON Schema validation options (e.g., minimum/maximum values, length constraints)
290
+ * - SQL database options (e.g., primary key)
291
+ * - LinkML specific options (e.g., readonly, recommended)
292
+ * - Custom options via the `Other` variant
293
+ *
294
+ */
295
+ export type AttrOption = { Example: string } | { MinimumValue: number } | { MaximumValue: number } | { MinItems: number } | { MaxItems: number } | { MinLength: number } | { MaxLength: number } | { Pattern: string } | { Unique: boolean } | { MultipleOf: number } | { ExclusiveMinimum: number } | { ExclusiveMaximum: number } | { PrimaryKey: boolean } | { ReadOnly: boolean } | { Recommended: boolean } | { Other: { key: string; value: string } };
296
+
@@ -105,11 +105,9 @@ function takeFromExternrefTable0(idx) {
105
105
  *
106
106
  * # Returns
107
107
  *
108
- * A `Result` which is:
109
- * - `Ok(JsValue)` if the parsing and serialization are successful.
110
- * - `Err(JsValue)` if there is an error during parsing or serialization.
108
+ * A `DataModel` or an error `JsError`.
111
109
  * @param {string} markdown_content
112
- * @returns {any}
110
+ * @returns {DataModel}
113
111
  */
114
112
  export function parse_model(markdown_content) {
115
113
  const ptr0 = passStringToWasm0(markdown_content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -205,7 +203,7 @@ export function json_schema(markdown_content, root, openai) {
205
203
  }
206
204
 
207
205
  /**
208
- * Validates the given markdown content and returns the validation result as a `JsValue`.
206
+ * Validates the given markdown content and returns the validation result as a `Validator`.
209
207
  *
210
208
  * # Arguments
211
209
  *
@@ -213,25 +211,20 @@ export function json_schema(markdown_content, root, openai) {
213
211
  *
214
212
  * # Returns
215
213
  *
216
- * A `Result` which is:
217
- * - `Ok(JsValue)` if the validation is successful.
218
- * - `Err(JsValue)` if there is an error during parsing or validation.
214
+ * Either an empty `Validator` or an error `Validator`.
219
215
  * @param {string} markdown_content
220
- * @returns {any}
216
+ * @returns {Validator}
221
217
  */
222
218
  export function validate(markdown_content) {
223
219
  const ptr0 = passStringToWasm0(markdown_content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
224
220
  const len0 = WASM_VECTOR_LEN;
225
221
  const ret = wasm.validate(ptr0, len0);
226
- if (ret[2]) {
227
- throw takeFromExternrefTable0(ret[1]);
228
- }
229
- return takeFromExternrefTable0(ret[0]);
222
+ return ret;
230
223
  }
231
224
 
232
225
  /**
233
226
  * Enumeration of available templates.
234
- * @enum {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12}
227
+ * @enum {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18}
235
228
  */
236
229
  export const Templates = Object.freeze({
237
230
  XmlSchema: 0, "0": "XmlSchema",
@@ -247,6 +240,12 @@ export const Templates = Object.freeze({
247
240
  MkDocs: 10, "10": "MkDocs",
248
241
  Internal: 11, "11": "Internal",
249
242
  Typescript: 12, "12": "Typescript",
243
+ TypescriptZod: 13, "13": "TypescriptZod",
244
+ Rust: 14, "14": "Rust",
245
+ Protobuf: 15, "15": "Protobuf",
246
+ Graphql: 16, "16": "Graphql",
247
+ Golang: 17, "17": "Golang",
248
+ Linkml: 18, "18": "Linkml",
250
249
  });
251
250
 
252
251
  export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) {
@@ -257,10 +256,6 @@ export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) {
257
256
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
258
257
  };
259
258
 
260
- export function __wbg_log_bdcc137b879aea04(arg0, arg1) {
261
- console.log(getStringFromWasm0(arg0, arg1));
262
- };
263
-
264
259
  export function __wbg_new_254fa9eac11932ae() {
265
260
  const ret = new Array();
266
261
  return ret;
@@ -294,6 +289,11 @@ export function __wbindgen_bigint_from_i64(arg0) {
294
289
  return ret;
295
290
  };
296
291
 
292
+ export function __wbindgen_bigint_from_u64(arg0) {
293
+ const ret = BigInt.asUintN(64, arg0);
294
+ return ret;
295
+ };
296
+
297
297
  export function __wbindgen_error_new(arg0, arg1) {
298
298
  const ret = new Error(getStringFromWasm0(arg0, arg1));
299
299
  return ret;
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Jan Range <jan.range@simtech.uni-stuttgart.de>"
6
6
  ],
7
7
  "description": "A tool to generate models, code and schemas from markdown files",
8
- "version": "0.1.7",
8
+ "version": "0.2.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",