forked from mendixlabs/mxcli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelsdk.go
More file actions
156 lines (135 loc) · 3.95 KB
/
modelsdk.go
File metadata and controls
156 lines (135 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// SPDX-License-Identifier: Apache-2.0
// Package modelsdk provides a Go library for reading and modifying Mendix projects.
//
// This library is a Go alternative to the Mendix Model SDK and Mendix Platform SDK,
// allowing direct manipulation of Mendix project files (.mpr) on disk.
//
// # Overview
//
// Mendix projects are stored in .mpr files which are SQLite databases containing
// BSON-encoded model elements. This library provides:
//
// - Reading and parsing MPR files (both v1 and v2 formats)
// - Type-safe access to all Mendix model elements
// - Creating, updating, and deleting model elements
// - Exporting models to JSON format
//
// # Quick Start
//
// package main
//
// import (
// "fmt"
// "github.com/mendixlabs/mxcli"
// )
//
// func main() {
// // Open a Mendix project via the public modelsdk API.
// reader, err := modelsdk.Open("/path/to/MyApp.mpr")
// if err != nil {
// panic(err)
// }
// defer reader.Close()
//
// // List all modules
// modules, err := reader.ListModules()
// if err != nil {
// panic(err)
// }
//
// for _, m := range modules {
// fmt.Printf("Module: %s\n", m.Name)
// }
// }
//
// # MPR File Formats
//
// The library supports both MPR v1 (single file) and MPR v2 (with mprcontents folder)
// formats. MPR v2 was introduced in Mendix Studio Pro 10.18.
//
// # Model Structure
//
// The Mendix model is organized hierarchically:
//
// - Project
// - Modules
// - Domain Models (Entities, Attributes, Associations)
// - Microflows and Nanoflows
// - Pages, Layouts, and Snippets
// - Enumerations and Constants
// - Scheduled Events
//
// Each element has a unique ID and belongs to a container element.
//
// # Thread Safety
//
// The Reader is safe for concurrent read access. The Writer should only be used
// from a single goroutine. For concurrent modifications, use transactions.
//
// # Error Handling
//
// All functions that can fail return an error. Errors include:
//
// - File not found
// - Invalid MPR format
// - Element not found
// - BSON parsing errors
// - SQLite errors
package modelsdk
import (
"github.com/mendixlabs/mxcli/model"
genMf "github.com/mendixlabs/mxcli/modelsdk/gen/microflows"
genPg "github.com/mendixlabs/mxcli/modelsdk/gen/pages"
mmpr "github.com/mendixlabs/mxcli/modelsdk/mpr"
)
// Version is the library version.
const Version = "0.1.0"
// Re-export commonly used types for convenience.
type (
// ID is a unique identifier for model elements.
ID = model.ID
// Module represents a Mendix module.
Module = model.Module
// Project represents a Mendix project.
Project = model.Project
// Enumeration represents an enumeration type.
Enumeration = model.Enumeration
// Constant represents a constant value.
Constant = model.Constant
// ConstantDataType represents the data type of a constant.
ConstantDataType = model.ConstantDataType
// ScheduledEvent represents a scheduled event.
ScheduledEvent = model.ScheduledEvent
// Microflow represents a microflow (modelsdk gen-typed).
Microflow = genMf.Microflow
// Nanoflow represents a nanoflow (modelsdk gen-typed).
Nanoflow = genMf.Nanoflow
// Page represents a page.
Page = genPg.Page
// Layout represents a layout.
Layout = genPg.Layout
// Snippet represents a page snippet.
Snippet = genPg.Snippet
// Reader provides read-only access to Mendix project files.
Reader = mmpr.Reader
// Writer provides read-write access to Mendix project files.
Writer = mmpr.Writer
)
// Open opens an MPR file for reading.
func Open(path string) (*Reader, error) {
return mmpr.Open(path)
}
// OpenForWriting opens an MPR file for reading and writing.
func OpenForWriting(path string) (*Writer, error) {
return mmpr.NewWriter(path)
}
// NewPage creates a new page.
func NewPage(name string) *Page {
p := genPg.NewPage()
p.SetName(name)
return p
}
// GenerateID generates a new unique ID for model elements.
func GenerateID() ID {
return ID(mmpr.GenerateID())
}