mdmodels-core 0.1.8 → 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/README.md CHANGED
@@ -1,15 +1,25 @@
1
-
2
1
  # MD-Models
3
2
 
4
3
  ![Crates.io Version](https://img.shields.io/crates/v/mdmodels) ![NPM Version](https://img.shields.io/npm/v/mdmodels-core)
5
4
  ![PyPI - Version](https://img.shields.io/pypi/v/mdmodels-core)
6
5
  ![Build Status](https://github.com/JR-1991/sdrdm.rs/actions/workflows/test.yml/badge.svg)
7
6
 
8
- 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.
9
8
 
10
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.
11
10
 
12
- 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.
13
23
 
14
24
  ### Example
15
25
 
@@ -73,10 +83,21 @@ The following templates are available:
73
83
  - `python-dataclass`: Python dataclass implementation with JSON-LD support
74
84
  - `python-pydantic`: PyDantic implementation with JSON-LD support
75
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
+ - `julia`: Julia struct definitions
91
+ - `protobuf`: Protocol Buffer schema definition
92
+ - `graphql`: GraphQL schema definition
76
93
  - `xml-schema`: XML schema definition
77
94
  - `json-schema`: JSON schema definition
95
+ - `json-schema-all`: Multiple JSON schema definitions (one per object)
78
96
  - `shacl`: SHACL shapes definition
79
97
  - `shex`: ShEx shapes definition
98
+ - `compact-markdown`: Compact markdown representation
99
+ - `mkdocs`: MkDocs documentation format
100
+ - `linkml`: LinkML schema definition
80
101
 
81
102
  ## Installation options
82
103
 
@@ -88,7 +109,7 @@ The main Rust crate is compiled to Python and WebAssembly, allowing the usage be
88
109
  pip install mdmodels-core
89
110
  ```
90
111
 
91
- - **[Python Package](https://pypi.org/project/mdmodels/)**: Install via pip:
112
+ - **[Python Package](https://github.com/FAIRChemistry/py-mdmodels/tree/master)**: Install via pip:
92
113
  ```bash
93
114
  # Provides in-memory data models, database support, LLM support, etc.
94
115
  pip install mdmodels
@@ -72,86 +72,29 @@ export enum Templates {
72
72
  MkDocs = 10,
73
73
  Internal = 11,
74
74
  Typescript = 12,
75
+ TypescriptZod = 13,
76
+ Rust = 14,
77
+ Protobuf = 15,
78
+ Graphql = 16,
79
+ Golang = 17,
80
+ Linkml = 18,
81
+ Julia = 19,
75
82
  }
76
83
  /**
77
- * Represents an XML type, either an attribute or an element.
84
+ * Represents different types of model imports.
85
+ *
86
+ * Can be either a remote URL or a local file path.
78
87
  */
79
- export type XMLType = { Attribute: { is_attr: boolean; name: string } } | { Element: { is_attr: boolean; name: string } };
80
-
81
- /**
82
- * Represents an enumeration with a name and mappings.
83
- */
84
- export interface Enumeration {
85
- /**
86
- * Name of the enumeration.
87
- */
88
- name: string;
89
- /**
90
- * Mappings associated with the enumeration.
91
- */
92
- mappings: Map<string, string>;
93
- /**
94
- * Documentation string for the enumeration.
95
- */
96
- docstring: string;
97
- /**
98
- * The line number of the enumeration
99
- */
100
- position: Position | undefined;
101
- }
102
-
103
- /**
104
- * Represents an object with a name, attributes, docstring, and an optional term.
105
- */
106
- export interface Object {
107
- /**
108
- * Name of the object.
109
- */
110
- name: string;
111
- /**
112
- * List of attributes associated with the object.
113
- */
114
- attributes: Attribute[];
115
- /**
116
- * Documentation string for the object.
117
- */
118
- docstring: string;
119
- /**
120
- * Optional term associated with the object.
121
- */
122
- term?: string;
123
- /**
124
- * Parent object of the object.
125
- */
126
- parent?: string;
127
- /**
128
- * The line number of the object
129
- */
130
- position?: Position;
131
- }
132
-
133
- export interface DataModel {
134
- name?: string;
135
- objects: Object[];
136
- enums: Enumeration[];
137
- config?: FrontMatter;
138
- }
139
-
140
- export interface PositionRange {
141
- start: number;
142
- end: number;
143
- }
144
-
145
- export interface Position {
146
- line: number;
147
- column: PositionRange;
148
- offset: PositionRange;
149
- }
88
+ export type ImportType = { Remote: string } | { Local: string };
150
89
 
151
90
  /**
152
91
  * Represents the front matter data of a markdown file.
153
92
  */
154
93
  export interface FrontMatter {
94
+ /**
95
+ * Identifier field of the model.
96
+ */
97
+ id: string | undefined;
155
98
  /**
156
99
  * A boolean field with a default value, renamed from `id-field`.
157
100
  */
@@ -172,24 +115,25 @@ export interface FrontMatter {
172
115
  * A string field with a default value representing the prefix.
173
116
  */
174
117
  prefix?: string;
175
- }
176
-
177
- export type DataType = { Boolean: boolean } | { Integer: number } | { Float: number } | { String: string };
178
-
179
- /**
180
- * Represents an option for an attribute.
181
- */
182
- export interface AttrOption {
183
118
  /**
184
- * The key of the option.
119
+ * Import remote or local models.
185
120
  */
186
- key: string;
121
+ imports?: Map<string, ImportType>;
187
122
  /**
188
- * The value of the option.
123
+ * Allow empty models.
189
124
  */
190
- value: string;
125
+ "allow-empty"?: boolean;
126
+ }
127
+
128
+ export interface DataModel {
129
+ name?: string;
130
+ objects: Object[];
131
+ enums: Enumeration[];
132
+ config?: FrontMatter;
191
133
  }
192
134
 
135
+ export type DataType = { Boolean: boolean } | { Integer: number } | { Float: number } | { String: string };
136
+
193
137
  /**
194
138
  * Represents an attribute with various properties and options.
195
139
  */
@@ -242,6 +186,111 @@ export interface Attribute {
242
186
  * The line number of the attribute
243
187
  */
244
188
  position: Position | undefined;
189
+ /**
190
+ * The prefix of the attribute, if it is an import
191
+ */
192
+ import_prefix?: string;
193
+ }
194
+
195
+ /**
196
+ * Represents an XML type, either an attribute or an element.
197
+ */
198
+ export type XMLType = { Attribute: { is_attr: boolean; name: string } } | { Element: { is_attr: boolean; name: string } } | { Wrapped: { is_attr: boolean; name: string; wrapped: string[] | undefined } };
199
+
200
+ export interface PositionRange {
201
+ start: number;
202
+ end: number;
203
+ }
204
+
205
+ export interface Position {
206
+ line: number;
207
+ column: PositionRange;
208
+ offset: PositionRange;
209
+ }
210
+
211
+ /**
212
+ * A raw key-value representation of an attribute option.
213
+ *
214
+ * This struct provides a simple string-based representation of options,
215
+ * which is useful for serialization/deserialization and when working
216
+ * with untyped data.
217
+ */
218
+ export interface RawOption {
219
+ /**
220
+ * The key/name of the option
221
+ */
222
+ key: string;
223
+ /**
224
+ * The string value of the option
225
+ */
226
+ value: string;
227
+ }
228
+
229
+ /**
230
+ * Represents an option for an attribute in a data model.
231
+ *
232
+ * This enum provides a strongly-typed representation of various attribute options
233
+ * that can be used to configure and constrain attributes in a data model.
234
+ *
235
+ * The options are grouped into several categories:
236
+ * - JSON Schema validation options (e.g., minimum/maximum values, length constraints)
237
+ * - SQL database options (e.g., primary key)
238
+ * - LinkML specific options (e.g., readonly, recommended)
239
+ * - Custom options via the `Other` variant
240
+ *
241
+ */
242
+ 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 } };
243
+
244
+ /**
245
+ * Represents an enumeration with a name and mappings.
246
+ */
247
+ export interface Enumeration {
248
+ /**
249
+ * Name of the enumeration.
250
+ */
251
+ name: string;
252
+ /**
253
+ * Mappings associated with the enumeration.
254
+ */
255
+ mappings: Map<string, string>;
256
+ /**
257
+ * Documentation string for the enumeration.
258
+ */
259
+ docstring: string;
260
+ /**
261
+ * The line number of the enumeration
262
+ */
263
+ position: Position | undefined;
264
+ }
265
+
266
+ /**
267
+ * Represents an object with a name, attributes, docstring, and an optional term.
268
+ */
269
+ export interface Object {
270
+ /**
271
+ * Name of the object.
272
+ */
273
+ name: string;
274
+ /**
275
+ * List of attributes associated with the object.
276
+ */
277
+ attributes: Attribute[];
278
+ /**
279
+ * Documentation string for the object.
280
+ */
281
+ docstring: string;
282
+ /**
283
+ * Optional term associated with the object.
284
+ */
285
+ term?: string;
286
+ /**
287
+ * Parent object of the object.
288
+ */
289
+ parent?: string;
290
+ /**
291
+ * The line number of the object
292
+ */
293
+ position?: Position;
245
294
  }
246
295
 
247
296
  /**
@@ -255,7 +304,7 @@ export interface Validator {
255
304
  /**
256
305
  * Enum representing the type of validation error.
257
306
  */
258
- export type ErrorType = "NameError" | "TypeError" | "DuplicateError" | "GlobalError";
307
+ export type ErrorType = "NameError" | "TypeError" | "DuplicateError" | "GlobalError" | "XMLError" | "ObjectError";
259
308
 
260
309
  /**
261
310
  * Represents a validation error in the data model.
@@ -265,6 +314,7 @@ export interface ValidationError {
265
314
  object: string | undefined;
266
315
  attribute: string | undefined;
267
316
  location: string;
317
+ solution: string | undefined;
268
318
  error_type: ErrorType;
269
319
  positions: Position[];
270
320
  }
@@ -224,7 +224,7 @@ export function validate(markdown_content) {
224
224
 
225
225
  /**
226
226
  * Enumeration of available templates.
227
- * @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 | 19}
228
228
  */
229
229
  export const Templates = Object.freeze({
230
230
  XmlSchema: 0, "0": "XmlSchema",
@@ -240,6 +240,13 @@ export const Templates = Object.freeze({
240
240
  MkDocs: 10, "10": "MkDocs",
241
241
  Internal: 11, "11": "Internal",
242
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",
249
+ Julia: 19, "19": "Julia",
243
250
  });
244
251
 
245
252
  export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) {
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.8",
8
+ "version": "0.2.1",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",