mdmodels-core 0.1.3

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/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2024 Jan Range
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+
2
+ # MD-Models
3
+
4
+ ![Build Status](https://github.com/JR-1991/sdrdm.rs/actions/workflows/test.yml/badge.svg)
5
+
6
+ Welcome to Markdown Models (MD-Models), a powerful framework for research data management that prioritizes flexibility and efficiency.
7
+
8
+ 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
+ Check out the [documentation](https://fairchemistry.github.io/md-models/) for more information.
11
+
12
+ ### Example
13
+
14
+ The schema syntax uses Markdown to define data models in a clear and structured way. Each object is introduced with a header, followed by its attributes. Attributes are described with their type, a brief explanation, and optional metadata like terms. Nested or related objects are represented using array types or references to other objects.
15
+
16
+ ```markdown
17
+ ---
18
+ prefixes:
19
+ schema: http://schema.org/
20
+ ---
21
+
22
+ ### Person
23
+
24
+ - **name**
25
+ - Type: string
26
+ - Description: The name of the person
27
+ - Term: schema:name
28
+ - age
29
+ - Type: integer
30
+ - Description: The age of the person
31
+ - Term: schema:age
32
+ - addresses
33
+ - Type: Address[]
34
+ - Description: The address of the person
35
+
36
+ ### Address
37
+
38
+ - street
39
+ - Type: string
40
+ - Description: The street of the address
41
+ ```
42
+
43
+ ## Installation
44
+
45
+ In order to install the command line tool, you can use the following command:
46
+
47
+ ```bash
48
+ git clone https://github.com/JR-1991/md-models
49
+ cd md-models
50
+ cargo install --path .
51
+ ```
52
+
53
+ ## Command line usage
54
+
55
+ The command line tool can be used to convert markdown files to various formats. The following command will convert a markdown file to Python code:
56
+
57
+ ```bash
58
+ md-models convert -i model.md -o lib.py -l python-dataclass
59
+ ```
60
+
61
+ This will read the input file `model.md` and write the output to `lib.py` using the Python dataclass template. Alternatively, you can also pass a URL as input to fetch the model remotely. For an overview of all available templates, you can use the following command:
62
+
63
+ ```bash
64
+ md-models --help
65
+ ```
66
+
67
+ ## Available templates
68
+
69
+ The following templates are available:
70
+
71
+ - `python-dataclass`: Python dataclass implementation with JSON-LD support
72
+ - `python-pydantic`: PyDantic implementation with JSON-LD support
73
+ - `python-pydantic-xml`: PyDantic implementation with XML support
74
+ - `xml-schema`: XML schema definition
75
+ - `json-schema`: JSON schema definition
76
+ - `shacl`: SHACL shapes definition
77
+ - `shex`: ShEx shapes definition
78
+
79
+ ## Development
80
+
81
+ This project uses GitHub Actions for continuous integration. The tests can be run using the following command:
82
+
83
+ ```bash
84
+ cargo test
85
+ cargo clippy
86
+ ```
@@ -0,0 +1,70 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Parses the given markdown content into a `DataModel` and returns it as a `JsValue`.
5
+ *
6
+ * # Arguments
7
+ *
8
+ * * `markdown_content` - A string slice that holds the markdown content to be parsed.
9
+ *
10
+ * # Returns
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.
15
+ * @param {string} markdown_content
16
+ * @returns {any}
17
+ */
18
+ export function parse_model(markdown_content: string): any;
19
+ /**
20
+ * Converts the given markdown content into a specified template format.
21
+ *
22
+ * # Arguments
23
+ *
24
+ * * `markdown_content` - A string slice that holds the markdown content to be converted.
25
+ * * `template` - The template format to convert the markdown content into.
26
+ *
27
+ * # Returns
28
+ *
29
+ * A `Result` which is:
30
+ * - `Ok(String)` if the conversion is successful.
31
+ * - `Err(JsValue)` if there is an error during parsing or conversion.
32
+ * @param {string} markdown_content
33
+ * @param {Templates} template
34
+ * @returns {string}
35
+ */
36
+ export function convert_to(markdown_content: string, template: Templates): string;
37
+ /**
38
+ * Validates the given markdown content and returns the validation result as a `JsValue`.
39
+ *
40
+ * # Arguments
41
+ *
42
+ * * `markdown_content` - A string slice that holds the markdown content to be validated.
43
+ *
44
+ * # Returns
45
+ *
46
+ * A `Result` which is:
47
+ * - `Ok(JsValue)` if the validation is successful.
48
+ * - `Err(JsValue)` if there is an error during parsing or validation.
49
+ * @param {string} markdown_content
50
+ * @returns {any}
51
+ */
52
+ export function validate(markdown_content: string): any;
53
+ /**
54
+ * Enumeration of available templates.
55
+ */
56
+ export enum Templates {
57
+ XmlSchema = 0,
58
+ Markdown = 1,
59
+ CompactMarkdown = 2,
60
+ Shacl = 3,
61
+ JsonSchema = 4,
62
+ JsonSchemaAll = 5,
63
+ Shex = 6,
64
+ PythonDataclass = 7,
65
+ PythonPydanticXML = 8,
66
+ PythonPydantic = 9,
67
+ MkDocs = 10,
68
+ Internal = 11,
69
+ Typescript = 12,
70
+ }
@@ -0,0 +1,5 @@
1
+ import * as wasm from "./mdmodels-core_bg.wasm";
2
+ export * from "./mdmodels-core_bg.js";
3
+ import { __wbg_set_wasm } from "./mdmodels-core_bg.js";
4
+ __wbg_set_wasm(wasm);
5
+ wasm.__wbindgen_start();
@@ -0,0 +1,274 @@
1
+ let wasm;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
4
+ }
5
+
6
+
7
+ const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
8
+
9
+ let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
10
+
11
+ cachedTextDecoder.decode();
12
+
13
+ let cachedUint8ArrayMemory0 = null;
14
+
15
+ function getUint8ArrayMemory0() {
16
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
17
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
18
+ }
19
+ return cachedUint8ArrayMemory0;
20
+ }
21
+
22
+ function getStringFromWasm0(ptr, len) {
23
+ ptr = ptr >>> 0;
24
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
25
+ }
26
+
27
+ let WASM_VECTOR_LEN = 0;
28
+
29
+ const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
30
+
31
+ let cachedTextEncoder = new lTextEncoder('utf-8');
32
+
33
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
34
+ ? function (arg, view) {
35
+ return cachedTextEncoder.encodeInto(arg, view);
36
+ }
37
+ : function (arg, view) {
38
+ const buf = cachedTextEncoder.encode(arg);
39
+ view.set(buf);
40
+ return {
41
+ read: arg.length,
42
+ written: buf.length
43
+ };
44
+ });
45
+
46
+ function passStringToWasm0(arg, malloc, realloc) {
47
+
48
+ if (realloc === undefined) {
49
+ const buf = cachedTextEncoder.encode(arg);
50
+ const ptr = malloc(buf.length, 1) >>> 0;
51
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
52
+ WASM_VECTOR_LEN = buf.length;
53
+ return ptr;
54
+ }
55
+
56
+ let len = arg.length;
57
+ let ptr = malloc(len, 1) >>> 0;
58
+
59
+ const mem = getUint8ArrayMemory0();
60
+
61
+ let offset = 0;
62
+
63
+ for (; offset < len; offset++) {
64
+ const code = arg.charCodeAt(offset);
65
+ if (code > 0x7F) break;
66
+ mem[ptr + offset] = code;
67
+ }
68
+
69
+ if (offset !== len) {
70
+ if (offset !== 0) {
71
+ arg = arg.slice(offset);
72
+ }
73
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
74
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
75
+ const ret = encodeString(arg, view);
76
+
77
+ offset += ret.written;
78
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
79
+ }
80
+
81
+ WASM_VECTOR_LEN = offset;
82
+ return ptr;
83
+ }
84
+
85
+ function takeFromExternrefTable0(idx) {
86
+ const value = wasm.__wbindgen_export_0.get(idx);
87
+ wasm.__externref_table_dealloc(idx);
88
+ return value;
89
+ }
90
+ /**
91
+ * Parses the given markdown content into a `DataModel` and returns it as a `JsValue`.
92
+ *
93
+ * # Arguments
94
+ *
95
+ * * `markdown_content` - A string slice that holds the markdown content to be parsed.
96
+ *
97
+ * # Returns
98
+ *
99
+ * A `Result` which is:
100
+ * - `Ok(JsValue)` if the parsing and serialization are successful.
101
+ * - `Err(JsValue)` if there is an error during parsing or serialization.
102
+ * @param {string} markdown_content
103
+ * @returns {any}
104
+ */
105
+ export function parse_model(markdown_content) {
106
+ const ptr0 = passStringToWasm0(markdown_content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
107
+ const len0 = WASM_VECTOR_LEN;
108
+ const ret = wasm.parse_model(ptr0, len0);
109
+ if (ret[2]) {
110
+ throw takeFromExternrefTable0(ret[1]);
111
+ }
112
+ return takeFromExternrefTable0(ret[0]);
113
+ }
114
+
115
+ /**
116
+ * Converts the given markdown content into a specified template format.
117
+ *
118
+ * # Arguments
119
+ *
120
+ * * `markdown_content` - A string slice that holds the markdown content to be converted.
121
+ * * `template` - The template format to convert the markdown content into.
122
+ *
123
+ * # Returns
124
+ *
125
+ * A `Result` which is:
126
+ * - `Ok(String)` if the conversion is successful.
127
+ * - `Err(JsValue)` if there is an error during parsing or conversion.
128
+ * @param {string} markdown_content
129
+ * @param {Templates} template
130
+ * @returns {string}
131
+ */
132
+ export function convert_to(markdown_content, template) {
133
+ let deferred3_0;
134
+ let deferred3_1;
135
+ try {
136
+ const ptr0 = passStringToWasm0(markdown_content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
137
+ const len0 = WASM_VECTOR_LEN;
138
+ const ret = wasm.convert_to(ptr0, len0, template);
139
+ var ptr2 = ret[0];
140
+ var len2 = ret[1];
141
+ if (ret[3]) {
142
+ ptr2 = 0; len2 = 0;
143
+ throw takeFromExternrefTable0(ret[2]);
144
+ }
145
+ deferred3_0 = ptr2;
146
+ deferred3_1 = len2;
147
+ return getStringFromWasm0(ptr2, len2);
148
+ } finally {
149
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Validates the given markdown content and returns the validation result as a `JsValue`.
155
+ *
156
+ * # Arguments
157
+ *
158
+ * * `markdown_content` - A string slice that holds the markdown content to be validated.
159
+ *
160
+ * # Returns
161
+ *
162
+ * A `Result` which is:
163
+ * - `Ok(JsValue)` if the validation is successful.
164
+ * - `Err(JsValue)` if there is an error during parsing or validation.
165
+ * @param {string} markdown_content
166
+ * @returns {any}
167
+ */
168
+ export function validate(markdown_content) {
169
+ const ptr0 = passStringToWasm0(markdown_content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
170
+ const len0 = WASM_VECTOR_LEN;
171
+ const ret = wasm.validate(ptr0, len0);
172
+ if (ret[2]) {
173
+ throw takeFromExternrefTable0(ret[1]);
174
+ }
175
+ return takeFromExternrefTable0(ret[0]);
176
+ }
177
+
178
+ let cachedDataViewMemory0 = null;
179
+
180
+ function getDataViewMemory0() {
181
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
182
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
183
+ }
184
+ return cachedDataViewMemory0;
185
+ }
186
+ /**
187
+ * Enumeration of available templates.
188
+ */
189
+ export const Templates = Object.freeze({ XmlSchema:0,"0":"XmlSchema",Markdown:1,"1":"Markdown",CompactMarkdown:2,"2":"CompactMarkdown",Shacl:3,"3":"Shacl",JsonSchema:4,"4":"JsonSchema",JsonSchemaAll:5,"5":"JsonSchemaAll",Shex:6,"6":"Shex",PythonDataclass:7,"7":"PythonDataclass",PythonPydanticXML:8,"8":"PythonPydanticXML",PythonPydantic:9,"9":"PythonPydantic",MkDocs:10,"10":"MkDocs",Internal:11,"11":"Internal",Typescript:12,"12":"Typescript", });
190
+
191
+ const __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
192
+
193
+ const __wbindgen_enum_RequestMode = ["same-origin", "no-cors", "cors", "navigate"];
194
+
195
+ export function __wbindgen_error_new(arg0, arg1) {
196
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
197
+ return ret;
198
+ };
199
+
200
+ export function __wbindgen_number_new(arg0) {
201
+ const ret = arg0;
202
+ return ret;
203
+ };
204
+
205
+ export function __wbindgen_string_new(arg0, arg1) {
206
+ const ret = getStringFromWasm0(arg0, arg1);
207
+ return ret;
208
+ };
209
+
210
+ export function __wbg_log_babdc861f1e14f89(arg0, arg1) {
211
+ console.log(getStringFromWasm0(arg0, arg1));
212
+ };
213
+
214
+ export function __wbindgen_is_string(arg0) {
215
+ const ret = typeof(arg0) === 'string';
216
+ return ret;
217
+ };
218
+
219
+ export function __wbg_String_b9412f8799faab3e(arg0, arg1) {
220
+ const ret = String(arg1);
221
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
222
+ const len1 = WASM_VECTOR_LEN;
223
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
224
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
225
+ };
226
+
227
+ export function __wbindgen_bigint_from_i64(arg0) {
228
+ const ret = arg0;
229
+ return ret;
230
+ };
231
+
232
+ export function __wbg_set_f975102236d3c502(arg0, arg1, arg2) {
233
+ arg0[arg1] = arg2;
234
+ };
235
+
236
+ export function __wbg_new_16b304a2cfa7ff4a() {
237
+ const ret = new Array();
238
+ return ret;
239
+ };
240
+
241
+ export function __wbg_new_d9bc3a0147634640() {
242
+ const ret = new Map();
243
+ return ret;
244
+ };
245
+
246
+ export function __wbg_new_72fb9a18b5ae2624() {
247
+ const ret = new Object();
248
+ return ret;
249
+ };
250
+
251
+ export function __wbg_set_d4638f722068f043(arg0, arg1, arg2) {
252
+ arg0[arg1 >>> 0] = arg2;
253
+ };
254
+
255
+ export function __wbg_set_8417257aaedc936b(arg0, arg1, arg2) {
256
+ const ret = arg0.set(arg1, arg2);
257
+ return ret;
258
+ };
259
+
260
+ export function __wbindgen_throw(arg0, arg1) {
261
+ throw new Error(getStringFromWasm0(arg0, arg1));
262
+ };
263
+
264
+ export function __wbindgen_init_externref_table() {
265
+ const table = wasm.__wbindgen_export_0;
266
+ const offset = table.grow(4);
267
+ table.set(0, undefined);
268
+ table.set(offset + 0, undefined);
269
+ table.set(offset + 1, null);
270
+ table.set(offset + 2, true);
271
+ table.set(offset + 3, false);
272
+ ;
273
+ };
274
+
Binary file
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "mdmodels-core",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Jan Range <jan.range@simtech.uni-stuttgart.de>"
6
+ ],
7
+ "description": "A tool to generate models, code and schemas from markdown files",
8
+ "version": "0.1.3",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/FAIRChemistry/md-models"
13
+ },
14
+ "files": [
15
+ "mdmodels-core_bg.wasm",
16
+ "mdmodels-core.js",
17
+ "mdmodels-core_bg.js",
18
+ "mdmodels-core.d.ts"
19
+ ],
20
+ "main": "mdmodels-core.js",
21
+ "types": "mdmodels-core.d.ts",
22
+ "sideEffects": [
23
+ "./mdmodels-core.js",
24
+ "./snippets/*"
25
+ ]
26
+ }