mdmodels-core 0.1.6 → 0.1.8

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,7 +1,9 @@
1
1
 
2
2
  # MD-Models
3
3
 
4
- ![Build Status](https://github.com/JR-1991/sdrdm.rs/actions/workflows/test.yml/badge.svg)
4
+ ![Crates.io Version](https://img.shields.io/crates/v/mdmodels) ![NPM Version](https://img.shields.io/npm/v/mdmodels-core)
5
+ ![PyPI - Version](https://img.shields.io/pypi/v/mdmodels-core)
6
+ ![Build Status](https://github.com/JR-1991/sdrdm.rs/actions/workflows/test.yml/badge.svg)
5
7
 
6
8
  Welcome to Markdown Models (MD-Models), a powerful framework for research data management that prioritizes flexibility and efficiency.
7
9
 
@@ -76,6 +78,28 @@ The following templates are available:
76
78
  - `shacl`: SHACL shapes definition
77
79
  - `shex`: ShEx shapes definition
78
80
 
81
+ ## Installation options
82
+
83
+ The main Rust crate is compiled to Python and WebAssembly, allowing the usage beyond the command line tool. These are the main packages:
84
+
85
+ - **[Core Python Package](https://pypi.org/project/mdmodels-core/)**: Install via pip:
86
+ ```bash
87
+ # Mainly used to access the core functionality of the library
88
+ pip install mdmodels-core
89
+ ```
90
+
91
+ - **[Python Package](https://pypi.org/project/mdmodels/)**: Install via pip:
92
+ ```bash
93
+ # Provides in-memory data models, database support, LLM support, etc.
94
+ pip install mdmodels
95
+ ```
96
+
97
+ - **[NPM Package](https://www.npmjs.com/package/mdmodels-core)**: Install via npm:
98
+ ```bash
99
+ # Mainly used to access the core functionality of the library
100
+ npm install mdmodels-core
101
+ ```
102
+
79
103
  ## Development
80
104
 
81
105
  This project uses GitHub Actions for continuous integration. The tests can be run using the following command:
@@ -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
  */
@@ -77,3 +73,199 @@ export enum Templates {
77
73
  Internal = 11,
78
74
  Typescript = 12,
79
75
  }
76
+ /**
77
+ * Represents an XML type, either an attribute or an element.
78
+ */
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
+ }
150
+
151
+ /**
152
+ * Represents the front matter data of a markdown file.
153
+ */
154
+ export interface FrontMatter {
155
+ /**
156
+ * A boolean field with a default value, renamed from `id-field`.
157
+ */
158
+ "id-field"?: boolean;
159
+ /**
160
+ * Optional hashmap of prefixes.
161
+ */
162
+ prefixes: Map<string, string> | undefined;
163
+ /**
164
+ * Optional namespace map.
165
+ */
166
+ nsmap: Map<string, string> | undefined;
167
+ /**
168
+ * A string field with a default value representing the repository URL.
169
+ */
170
+ repo?: string;
171
+ /**
172
+ * A string field with a default value representing the prefix.
173
+ */
174
+ 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
+ /**
184
+ * The key of the option.
185
+ */
186
+ key: string;
187
+ /**
188
+ * The value of the option.
189
+ */
190
+ value: string;
191
+ }
192
+
193
+ /**
194
+ * Represents an attribute with various properties and options.
195
+ */
196
+ export interface Attribute {
197
+ /**
198
+ * The name of the attribute.
199
+ */
200
+ name: string;
201
+ /**
202
+ * Indicates if the attribute is an array.
203
+ */
204
+ multiple: boolean;
205
+ /**
206
+ * Is an identifier or not
207
+ */
208
+ is_id: boolean;
209
+ /**
210
+ * Data types associated with the attribute.
211
+ */
212
+ dtypes: string[];
213
+ /**
214
+ * Documentation string for the attribute.
215
+ */
216
+ docstring: string;
217
+ /**
218
+ * List of additional options for the attribute.
219
+ */
220
+ options: AttrOption[];
221
+ /**
222
+ * Term associated with the attribute, if any.
223
+ */
224
+ term: string | undefined;
225
+ /**
226
+ * Indicates if the attribute is required.
227
+ */
228
+ required: boolean;
229
+ /**
230
+ * Default value for the attribute.
231
+ */
232
+ default?: DataType;
233
+ /**
234
+ * XML type information for the attribute.
235
+ */
236
+ xml?: XMLType;
237
+ /**
238
+ * Is an enumeration or not
239
+ */
240
+ is_enum: boolean;
241
+ /**
242
+ * The line number of the attribute
243
+ */
244
+ position: Position | undefined;
245
+ }
246
+
247
+ /**
248
+ * Validator for checking the integrity of a data model.
249
+ */
250
+ export interface Validator {
251
+ is_valid: boolean;
252
+ errors: ValidationError[];
253
+ }
254
+
255
+ /**
256
+ * Enum representing the type of validation error.
257
+ */
258
+ export type ErrorType = "NameError" | "TypeError" | "DuplicateError" | "GlobalError";
259
+
260
+ /**
261
+ * Represents a validation error in the data model.
262
+ */
263
+ export interface ValidationError {
264
+ message: string;
265
+ object: string | undefined;
266
+ attribute: string | undefined;
267
+ location: string;
268
+ error_type: ErrorType;
269
+ positions: Position[];
270
+ }
271
+
@@ -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,20 +211,15 @@ 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
  /**
@@ -257,10 +250,6 @@ export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) {
257
250
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
258
251
  };
259
252
 
260
- export function __wbg_log_770029216eb4d401(arg0, arg1) {
261
- console.log(getStringFromWasm0(arg0, arg1));
262
- };
263
-
264
253
  export function __wbg_new_254fa9eac11932ae() {
265
254
  const ret = new Array();
266
255
  return ret;
@@ -294,6 +283,11 @@ export function __wbindgen_bigint_from_i64(arg0) {
294
283
  return ret;
295
284
  };
296
285
 
286
+ export function __wbindgen_bigint_from_u64(arg0) {
287
+ const ret = BigInt.asUintN(64, arg0);
288
+ return ret;
289
+ };
290
+
297
291
  export function __wbindgen_error_new(arg0, arg1) {
298
292
  const ret = new Error(getStringFromWasm0(arg0, arg1));
299
293
  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.6",
8
+ "version": "0.1.8",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",