mxrb 0.1.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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.de-DE.md +108 -0
- data/README.md +172 -0
- data/README.pt-BR.md +109 -0
- data/bin/mxrb +1613 -0
- data/docs/README.md +10 -0
- data/docs/de-DE/README.md +24 -0
- data/docs/de-DE/architectural-patterns.md +26 -0
- data/docs/de-DE/architectural-standard.md +48 -0
- data/docs/de-DE/architecture.md +76 -0
- data/docs/de-DE/compiler.md +162 -0
- data/docs/de-DE/conventions.md +19 -0
- data/docs/de-DE/design-system.md +52 -0
- data/docs/de-DE/entity-dsl.md +53 -0
- data/docs/de-DE/native-runtime-quality-report.md +74 -0
- data/docs/de-DE/oql-sql.md +211 -0
- data/docs/de-DE/platform-api-integration.md +36 -0
- data/docs/de-DE/platform-operations.md +243 -0
- data/docs/de-DE/project-structure.md +32 -0
- data/docs/de-DE/ruby-first-roadmap.md +116 -0
- data/docs/de-DE/scaffolds.md +59 -0
- data/docs/de-DE/semantic-refactoring.md +56 -0
- data/docs/de-DE/team-server.md +33 -0
- data/docs/de-DE/validation-matrix.md +64 -0
- data/docs/de-DE/vetclinic-acceptance.md +24 -0
- data/docs/de-DE/writing.md +138 -0
- data/docs/en-US/README.md +24 -0
- data/docs/en-US/architectural-patterns.md +151 -0
- data/docs/en-US/architectural-standard.md +89 -0
- data/docs/en-US/architecture.md +170 -0
- data/docs/en-US/compiler.md +157 -0
- data/docs/en-US/conventions.md +82 -0
- data/docs/en-US/design-system.md +163 -0
- data/docs/en-US/entity-dsl.md +53 -0
- data/docs/en-US/native-runtime-quality-report.md +73 -0
- data/docs/en-US/oql-sql.md +201 -0
- data/docs/en-US/platform-api-integration.md +36 -0
- data/docs/en-US/platform-operations.md +244 -0
- data/docs/en-US/project-structure.md +49 -0
- data/docs/en-US/ruby-first-roadmap.md +186 -0
- data/docs/en-US/scaffolds.md +57 -0
- data/docs/en-US/semantic-refactoring.md +198 -0
- data/docs/en-US/team-server.md +32 -0
- data/docs/en-US/validation-matrix.md +257 -0
- data/docs/en-US/vetclinic-acceptance.md +23 -0
- data/docs/en-US/writing.md +655 -0
- data/docs/pt-BR/README.md +24 -0
- data/docs/pt-BR/architectural-patterns.md +25 -0
- data/docs/pt-BR/architectural-standard.md +533 -0
- data/docs/pt-BR/architecture.md +300 -0
- data/docs/pt-BR/compiler.md +162 -0
- data/docs/pt-BR/conventions.md +19 -0
- data/docs/pt-BR/design-system.md +65 -0
- data/docs/pt-BR/entity-dsl.md +116 -0
- data/docs/pt-BR/native-runtime-quality-report.md +73 -0
- data/docs/pt-BR/oql-sql.md +208 -0
- data/docs/pt-BR/platform-api-integration.md +36 -0
- data/docs/pt-BR/platform-operations.md +260 -0
- data/docs/pt-BR/project-structure.md +32 -0
- data/docs/pt-BR/ruby-first-roadmap.md +239 -0
- data/docs/pt-BR/scaffolds.md +104 -0
- data/docs/pt-BR/semantic-refactoring.md +55 -0
- data/docs/pt-BR/team-server.md +59 -0
- data/docs/pt-BR/validation-matrix.md +86 -0
- data/docs/pt-BR/vetclinic-acceptance.md +50 -0
- data/docs/pt-BR/writing.md +177 -0
- data/examples/sudoku_evaluation.rb +14 -0
- data/examples/sudoku_functional_test.rb +28 -0
- data/lib/mxrb/architecture/graph.rb +124 -0
- data/lib/mxrb/architecture/validator.rb +98 -0
- data/lib/mxrb/benchmark.rb +33 -0
- data/lib/mxrb/compare.rb +390 -0
- data/lib/mxrb/compiler/adapter.rb +96 -0
- data/lib/mxrb/compiler/artifact_document_compiler.rb +102 -0
- data/lib/mxrb/compiler/artifact_materializer.rb +53 -0
- data/lib/mxrb/compiler/client_model_materializer.rb +42 -0
- data/lib/mxrb/compiler/code_action_document_compiler.rb +64 -0
- data/lib/mxrb/compiler/code_action_materializer.rb +35 -0
- data/lib/mxrb/compiler/code_action_type_compiler.rb +32 -0
- data/lib/mxrb/compiler/combo_box_bundle_compiler.rb +314 -0
- data/lib/mxrb/compiler/compatibility_analyzer.rb +169 -0
- data/lib/mxrb/compiler/constants_materializer.rb +111 -0
- data/lib/mxrb/compiler/data_grid_bundle_compiler.rb +290 -0
- data/lib/mxrb/compiler/database_connector_action_compiler.rb +280 -0
- data/lib/mxrb/compiler/deployment_asset_copier.rb +60 -0
- data/lib/mxrb/compiler/deployment_bootstrapper.rb +208 -0
- data/lib/mxrb/compiler/deployment_materializer.rb +43 -0
- data/lib/mxrb/compiler/deployment_metadata.rb +64 -0
- data/lib/mxrb/compiler/domain_document_compiler.rb +153 -0
- data/lib/mxrb/compiler/domain_model_materializer.rb +35 -0
- data/lib/mxrb/compiler/domain_security_compiler.rb +82 -0
- data/lib/mxrb/compiler/gallery_bundle_compiler.rb +190 -0
- data/lib/mxrb/compiler/generic_widget_bundle_compiler.rb +281 -0
- data/lib/mxrb/compiler/image_bundle_compiler.rb +216 -0
- data/lib/mxrb/compiler/java_proxy_generator.rb +509 -0
- data/lib/mxrb/compiler/legacy_data_grid_compiler.rb +267 -0
- data/lib/mxrb/compiler/legacy_page_builder.rb +287 -0
- data/lib/mxrb/compiler/mda.rb +99 -0
- data/lib/mxrb/compiler/microflow_document_compiler.rb +85 -0
- data/lib/mxrb/compiler/microflow_materializer.rb +48 -0
- data/lib/mxrb/compiler/microflow_node_compiler.rb +250 -0
- data/lib/mxrb/compiler/model_package.rb +116 -0
- data/lib/mxrb/compiler/model_values.rb +67 -0
- data/lib/mxrb/compiler/nanoflow_program_compiler.rb +483 -0
- data/lib/mxrb/compiler/navigation_document_compiler.rb +93 -0
- data/lib/mxrb/compiler/packager.rb +100 -0
- data/lib/mxrb/compiler/page_bundle_builder.rb +56 -0
- data/lib/mxrb/compiler/page_bundle_compiler.rb +2004 -0
- data/lib/mxrb/compiler/page_document_compiler.rb +77 -0
- data/lib/mxrb/compiler/portable_packager.rb +356 -0
- data/lib/mxrb/compiler/project_jar_archive.rb +84 -0
- data/lib/mxrb/compiler/project_jar_builder.rb +121 -0
- data/lib/mxrb/compiler/project_materializer.rb +139 -0
- data/lib/mxrb/compiler/project_model_orderer.rb +52 -0
- data/lib/mxrb/compiler/runtime_data_types.rb +31 -0
- data/lib/mxrb/compiler/runtime_model_schema.rb +90 -0
- data/lib/mxrb/compiler/schemas/runtime-10.24.0.73019.json +1052 -0
- data/lib/mxrb/compiler/schemas/runtime-11.json +1215 -0
- data/lib/mxrb/compiler/schemas/runtime-6.10.8.json +1148 -0
- data/lib/mxrb/compiler/schemas/runtime-7.17.0.json +1144 -0
- data/lib/mxrb/compiler/schemas/runtime-7.5.0.json +1215 -0
- data/lib/mxrb/compiler/schemas/runtime-9.6.1.29396.json +868 -0
- data/lib/mxrb/compiler/schemas/system-model-10.24.0.73019.b64 +1135 -0
- data/lib/mxrb/compiler/schemas/system-model-11.12.1.b64 +815 -0
- data/lib/mxrb/compiler/schemas/system-model-6.10.8.b64 +497 -0
- data/lib/mxrb/compiler/schemas/system-model-7.17.0.b64 +519 -0
- data/lib/mxrb/compiler/schemas/system-model-7.5.0.b64 +504 -0
- data/lib/mxrb/compiler/schemas/system-model-9.6.1.29396.b64 +816 -0
- data/lib/mxrb/compiler/security_materializer.rb +104 -0
- data/lib/mxrb/compiler/settings_document_compiler.rb +45 -0
- data/lib/mxrb/compiler/settings_materializer.rb +25 -0
- data/lib/mxrb/compiler/source_model.rb +128 -0
- data/lib/mxrb/compiler/system_model_seed.rb +88 -0
- data/lib/mxrb/compiler/system_queue_materializer.rb +54 -0
- data/lib/mxrb/compiler/system_text_materializer.rb +49 -0
- data/lib/mxrb/compiler/translation_materializer.rb +95 -0
- data/lib/mxrb/compiler/web_bundle_builder.rb +155 -0
- data/lib/mxrb/compiler/web_list_data_source.rb +139 -0
- data/lib/mxrb/compiler/web_operation_compiler.rb +614 -0
- data/lib/mxrb/compiler/web_shell_materializer.rb +194 -0
- data/lib/mxrb/compiler/widget_package_extractor.rb +63 -0
- data/lib/mxrb/doctor.rb +116 -0
- data/lib/mxrb/dsl/builder.rb +1636 -0
- data/lib/mxrb/errors.rb +18 -0
- data/lib/mxrb/evaluation.rb +131 -0
- data/lib/mxrb/exporter.rb +1716 -0
- data/lib/mxrb/frontend/migrator.rb +775 -0
- data/lib/mxrb/functional.rb +307 -0
- data/lib/mxrb/github/annotator.rb +161 -0
- data/lib/mxrb/initializer.rb +257 -0
- data/lib/mxrb/integrity/validator.rb +136 -0
- data/lib/mxrb/io/bson_codec.rb +145 -0
- data/lib/mxrb/io/mpr_file.rb +558 -0
- data/lib/mxrb/io/mxunit_codec.rb +42 -0
- data/lib/mxrb/marketplace.rb +380 -0
- data/lib/mxrb/model/association.rb +98 -0
- data/lib/mxrb/model/attribute.rb +100 -0
- data/lib/mxrb/model/connector.rb +17 -0
- data/lib/mxrb/model/design_materializer.rb +133 -0
- data/lib/mxrb/model/design_migration.rb +126 -0
- data/lib/mxrb/model/design_system.rb +111 -0
- data/lib/mxrb/model/domain_model.rb +51 -0
- data/lib/mxrb/model/entity.rb +180 -0
- data/lib/mxrb/model/menu.rb +38 -0
- data/lib/mxrb/model/microflow.rb +100 -0
- data/lib/mxrb/model/module.rb +142 -0
- data/lib/mxrb/model/navigation.rb +127 -0
- data/lib/mxrb/model/page.rb +410 -0
- data/lib/mxrb/model/project.rb +187 -0
- data/lib/mxrb/model/unit.rb +48 -0
- data/lib/mxrb/module_initializer.rb +75 -0
- data/lib/mxrb/official_marketplace/content_api.rb +292 -0
- data/lib/mxrb/official_marketplace/dependency_resolver.rb +329 -0
- data/lib/mxrb/official_marketplace/lifecycle.rb +367 -0
- data/lib/mxrb/official_marketplace/module_package_importer.rb +318 -0
- data/lib/mxrb/official_marketplace/widget_package_installer.rb +414 -0
- data/lib/mxrb/official_marketplace.rb +720 -0
- data/lib/mxrb/oql/analyzer.rb +155 -0
- data/lib/mxrb/oql/index_advisor.rb +85 -0
- data/lib/mxrb/oql/plan_analyzer.rb +185 -0
- data/lib/mxrb/oql/server.rb +132 -0
- data/lib/mxrb/oql/sql_server_plan_analyzer.rb +190 -0
- data/lib/mxrb/oql/sql_server_workload_analyzer.rb +80 -0
- data/lib/mxrb/oql/workload_analyzer.rb +175 -0
- data/lib/mxrb/oql/workload_baseline.rb +60 -0
- data/lib/mxrb/oql.rb +424 -0
- data/lib/mxrb/project_lifecycle.rb +76 -0
- data/lib/mxrb/protocols/plan.rb +86 -0
- data/lib/mxrb/protocols.rb +123 -0
- data/lib/mxrb/runtime/database_workspace.rb +677 -0
- data/lib/mxrb/runtime/docker_executor.rb +41 -0
- data/lib/mxrb/runtime/docker_workspace.rb +29 -0
- data/lib/mxrb/runtime/executor.rb +169 -0
- data/lib/mxrb/runtime/java_locator.rb +26 -0
- data/lib/mxrb/runtime/native.rb +474 -0
- data/lib/mxrb/runtime/sql_server_database.rb +146 -0
- data/lib/mxrb/runtime/toolchain.rb +82 -0
- data/lib/mxrb/scaffold/cli.rb +113 -0
- data/lib/mxrb/scaffold/generator.rb +246 -0
- data/lib/mxrb/scaffold/help.rb +80 -0
- data/lib/mxrb/scaffold/page_templates.rb +54 -0
- data/lib/mxrb/scaffold/recipes.rb +198 -0
- data/lib/mxrb/scaffold/registry.rb +82 -0
- data/lib/mxrb/scaffold/templates.rb +723 -0
- data/lib/mxrb/scaffold/transaction.rb +84 -0
- data/lib/mxrb/schema/tables.rb +55 -0
- data/lib/mxrb/semantic/analyzer.rb +473 -0
- data/lib/mxrb/semantic/batch_plan.rb +68 -0
- data/lib/mxrb/semantic/domain_mutator.rb +419 -0
- data/lib/mxrb/semantic/embedder.rb +51 -0
- data/lib/mxrb/semantic/extractor.rb +290 -0
- data/lib/mxrb/semantic/index.rb +623 -0
- data/lib/mxrb/semantic/inliner.rb +216 -0
- data/lib/mxrb/semantic/mover.rb +153 -0
- data/lib/mxrb/semantic/onnx_embedder.rb +34 -0
- data/lib/mxrb/semantic/remover.rb +70 -0
- data/lib/mxrb/semantic/renamer.rb +211 -0
- data/lib/mxrb/semantic/tfidf_embedder.rb +46 -0
- data/lib/mxrb/semantic/vec_store.rb +75 -0
- data/lib/mxrb/team_server.rb +390 -0
- data/lib/mxrb/templates/project/10.24.0.73019.json +32 -0
- data/lib/mxrb/templates/project/11.12.1.json +32 -0
- data/lib/mxrb/templates/project/6.10.8.json +50 -0
- data/lib/mxrb/templates/project/7.17.0.json +50 -0
- data/lib/mxrb/templates/project/7.5.0.json +50 -0
- data/lib/mxrb/templates/project/9.6.1.29396.json +50 -0
- data/lib/mxrb/version.rb +5 -0
- data/lib/mxrb/widget_package.rb +338 -0
- data/lib/mxrb/widget_synchronizer.rb +31 -0
- data/lib/mxrb/writer.rb +3775 -0
- data/lib/mxrb.rb +188 -0
- data/marketplace/catalog.json +10 -0
- data/marketplace/modules/shared-kernel/domain/README.md +4 -0
- data/marketplace/modules/shared-kernel/module.rb +5 -0
- data/marketplace/modules/shared-kernel/mxrb-module.json +9 -0
- metadata +447 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rexml/document'
|
|
4
|
+
require 'zip'
|
|
5
|
+
|
|
6
|
+
module Mxrb
|
|
7
|
+
# Reads pluggable-widget metadata directly from installed MPK files and builds
|
|
8
|
+
# the embedded Mendix WidgetType/WidgetObject pair without Studio Pro.
|
|
9
|
+
class WidgetPackage # rubocop:disable Metrics/ClassLength
|
|
10
|
+
TYPE_MAP = {
|
|
11
|
+
'attribute' => 'Attribute', 'expression' => 'Expression',
|
|
12
|
+
'texttemplate' => 'TextTemplate', 'widgets' => 'Widgets',
|
|
13
|
+
'enumeration' => 'Enumeration', 'boolean' => 'Boolean',
|
|
14
|
+
'integer' => 'Integer', 'datasource' => 'DataSource', 'action' => 'Action',
|
|
15
|
+
'selection' => 'Selection', 'association' => 'Association', 'object' => 'Object',
|
|
16
|
+
'string' => 'String', 'decimal' => 'Decimal', 'icon' => 'Icon',
|
|
17
|
+
'image' => 'Image', 'file' => 'File'
|
|
18
|
+
}.freeze
|
|
19
|
+
|
|
20
|
+
Definition = Data.define(
|
|
21
|
+
:id, :name, :description, :help_url, :studio_category, :studio_pro_category,
|
|
22
|
+
:platform, :offline, :needs_context, :plugin, :properties
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def self.find(root, widget_id)
|
|
26
|
+
Dir.glob(File.join(File.expand_path(root), 'widgets', '*.mpk')).sort.each do |path|
|
|
27
|
+
definition = new(path).definition(widget_id)
|
|
28
|
+
return definition if definition
|
|
29
|
+
rescue Zip::Error, REXML::ParseException
|
|
30
|
+
next
|
|
31
|
+
end
|
|
32
|
+
nil
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.template(definition) = allocate.template(definition)
|
|
36
|
+
|
|
37
|
+
def initialize(path)
|
|
38
|
+
@path = path
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def definition(widget_id)
|
|
42
|
+
Zip::File.open(@path) do |archive|
|
|
43
|
+
widget_entries(archive).each do |entry|
|
|
44
|
+
root = REXML::Document.new(entry.get_input_stream.read).root
|
|
45
|
+
next unless root&.attributes&.[]('id') == widget_id
|
|
46
|
+
|
|
47
|
+
return build_definition(root)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def template(definition) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
54
|
+
object_type_id = SecureRandom.uuid
|
|
55
|
+
property_types = []
|
|
56
|
+
properties = []
|
|
57
|
+
definition.properties.each do |property|
|
|
58
|
+
property_type, value = property_pair(property)
|
|
59
|
+
property_types << property_type
|
|
60
|
+
properties << value if value
|
|
61
|
+
end
|
|
62
|
+
type = {
|
|
63
|
+
'$ID' => SecureRandom.uuid, '$Type' => 'CustomWidgets$CustomWidgetType',
|
|
64
|
+
'HelpUrl' => definition.help_url,
|
|
65
|
+
'ObjectType' => {
|
|
66
|
+
'$ID' => object_type_id, '$Type' => 'CustomWidgets$WidgetObjectType',
|
|
67
|
+
'PropertyTypes' => IO::BsonCodec.build_array(property_types, marker: 2)
|
|
68
|
+
},
|
|
69
|
+
'OfflineCapable' => definition.offline,
|
|
70
|
+
'StudioCategory' => definition.studio_category,
|
|
71
|
+
'StudioProCategory' => definition.studio_pro_category,
|
|
72
|
+
'SupportedPlatform' => definition.platform,
|
|
73
|
+
'WidgetDescription' => definition.description,
|
|
74
|
+
'WidgetId' => definition.id, 'WidgetName' => definition.name,
|
|
75
|
+
'WidgetNeedsEntityContext' => definition.needs_context,
|
|
76
|
+
'WidgetPluginWidget' => definition.plugin
|
|
77
|
+
}
|
|
78
|
+
object = {
|
|
79
|
+
'$ID' => SecureRandom.uuid, '$Type' => 'CustomWidgets$WidgetObject',
|
|
80
|
+
'Properties' => IO::BsonCodec.build_array(properties, marker: 2),
|
|
81
|
+
'TypePointer' => object_type_id
|
|
82
|
+
}
|
|
83
|
+
[type, object]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
def widget_entries(archive)
|
|
89
|
+
package = archive.find_entry('package.xml')
|
|
90
|
+
return archive.select { _1.file? && _1.name.downcase.end_with?('.xml') } unless package
|
|
91
|
+
|
|
92
|
+
document = REXML::Document.new(package.get_input_stream.read)
|
|
93
|
+
paths = elements(document.root, 'widgetFile').filter_map { _1.attributes['path'] }
|
|
94
|
+
paths.filter_map { archive.find_entry(_1) }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def build_definition(root) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
98
|
+
properties_root = child(root, 'properties')
|
|
99
|
+
properties = properties_root ? property_groups(properties_root, nil) : []
|
|
100
|
+
Definition.new(
|
|
101
|
+
id: root.attributes['id'], name: text(root, 'name'),
|
|
102
|
+
description: text(root, 'description'), help_url: text(root, 'helpUrl'),
|
|
103
|
+
studio_category: text(root, 'studioCategory'),
|
|
104
|
+
studio_pro_category: text(root, 'studioProCategory'),
|
|
105
|
+
platform: root.attributes['supportedPlatform'].to_s.empty? ? 'Web' : root.attributes['supportedPlatform'],
|
|
106
|
+
offline: root.attributes['offlineCapable'] == 'true',
|
|
107
|
+
needs_context: root.attributes['needsEntityContext'] == 'true',
|
|
108
|
+
plugin: root.attributes['pluginWidget'] == 'true', properties:
|
|
109
|
+
)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def property_groups(parent, category)
|
|
113
|
+
parent.elements.to_a.flat_map do |element|
|
|
114
|
+
property_member(element, category)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def property_member(element, category)
|
|
119
|
+
case element.name
|
|
120
|
+
when 'property' then [property(element, category.to_s.empty? ? 'General' : category.to_s)]
|
|
121
|
+
when 'systemProperty' then [system_property(element, category.to_s.empty? ? 'General' : category.to_s)]
|
|
122
|
+
when 'propertyGroup'
|
|
123
|
+
nested = [category, element.attributes['caption']].compact.reject(&:empty?).join('::')
|
|
124
|
+
property_groups(element, nested)
|
|
125
|
+
else []
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def property(element, category) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
130
|
+
{
|
|
131
|
+
key: element.attributes['key'], type: TYPE_MAP[element.attributes['type'].to_s.downcase],
|
|
132
|
+
caption: text(element, 'caption'), description: text(element, 'description'), category:,
|
|
133
|
+
required: element.attributes['required'] != 'false',
|
|
134
|
+
default: element.attributes['defaultValue'].to_s,
|
|
135
|
+
list: element.attributes['isList'] == 'true', multiline: element.attributes['multiline'] == 'true',
|
|
136
|
+
data_source: element.attributes['dataSource'].to_s,
|
|
137
|
+
on_change: element.attributes['onChange'].to_s,
|
|
138
|
+
default_type: element.attributes['defaultType'].to_s,
|
|
139
|
+
linked: element.attributes['isLinked'] == 'true',
|
|
140
|
+
metadata: element.attributes['isMetaData'] == 'true',
|
|
141
|
+
selectable_objects: element.attributes['selectableObjects'].to_s,
|
|
142
|
+
set_label: element.attributes['setLabel'] == 'true',
|
|
143
|
+
action_variables: nested_elements(element, 'actionVariables', 'actionVariable').map do |variable|
|
|
144
|
+
{
|
|
145
|
+
key: variable.attributes['key'].to_s, caption: variable.attributes['caption'].to_s,
|
|
146
|
+
type: variable.attributes['type'].to_s
|
|
147
|
+
}
|
|
148
|
+
end,
|
|
149
|
+
allowed_types: nested_element_names(element, 'attributeTypes', 'attributeType'),
|
|
150
|
+
association_types: nested_element_names(element, 'associationTypes', 'associationType'),
|
|
151
|
+
selection_types: nested_element_names(element, 'selectionTypes', 'selectionType'),
|
|
152
|
+
enum_values: nested_elements(element, 'enumerationValues', 'enumerationValue').map do |value|
|
|
153
|
+
[value.attributes['key'].to_s, value.text.to_s.strip]
|
|
154
|
+
end,
|
|
155
|
+
translations: nested_elements(element, 'translations', 'translation').map do |translation|
|
|
156
|
+
[translation.attributes['lang'].to_s, translation.text.to_s.strip]
|
|
157
|
+
end,
|
|
158
|
+
return_type: return_type(element), children: nested_properties(element)
|
|
159
|
+
}
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def system_property(element, category)
|
|
163
|
+
{ key: element.attributes['key'], type: 'System', caption: "<system:#{element.attributes['key']}>",
|
|
164
|
+
description: '', category:, required: false, default: '', list: false, multiline: false,
|
|
165
|
+
data_source: '', on_change: '', allowed_types: [], association_types: [], selection_types: [],
|
|
166
|
+
enum_values: [], translations: [], return_type: nil, children: [], system: true,
|
|
167
|
+
default_type: '', linked: false, metadata: false, selectable_objects: '', set_label: false,
|
|
168
|
+
action_variables: [] }
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def nested_properties(element)
|
|
172
|
+
root = child(element, 'properties')
|
|
173
|
+
root ? property_groups(root, nil).reject { _1[:system] } : []
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def return_type(element)
|
|
177
|
+
node = child(element, 'returnType')
|
|
178
|
+
return unless node
|
|
179
|
+
|
|
180
|
+
{ type: node.attributes['type'].to_s.empty? ? 'None' : node.attributes['type'],
|
|
181
|
+
assignable_to: node.attributes['assignableTo'].to_s }
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def property_pair(property) # rubocop:disable Metrics/MethodLength
|
|
185
|
+
property_type_id = SecureRandom.uuid
|
|
186
|
+
value_type = value_type(property)
|
|
187
|
+
property_type = {
|
|
188
|
+
'$ID' => property_type_id, '$Type' => 'CustomWidgets$WidgetPropertyType',
|
|
189
|
+
'Caption' => property[:caption], 'Category' => property[:category],
|
|
190
|
+
'Description' => property[:description], 'IsDefault' => false,
|
|
191
|
+
'PropertyKey' => property[:key], 'ValueType' => value_type
|
|
192
|
+
}
|
|
193
|
+
return [property_type, nil] if property[:system]
|
|
194
|
+
|
|
195
|
+
value = widget_value(value_type, property)
|
|
196
|
+
widget_property = {
|
|
197
|
+
'$ID' => SecureRandom.uuid, '$Type' => 'CustomWidgets$WidgetProperty',
|
|
198
|
+
'TypePointer' => property_type_id, 'Value' => value
|
|
199
|
+
}
|
|
200
|
+
[property_type, widget_property]
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def value_type(property) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
204
|
+
type = property[:type]
|
|
205
|
+
{
|
|
206
|
+
'$ID' => SecureRandom.uuid, '$Type' => 'CustomWidgets$WidgetValueType',
|
|
207
|
+
'ActionVariables' => action_variables(property[:action_variables]),
|
|
208
|
+
'AllowedTypes' => IO::BsonCodec.build_array(property[:allowed_types], marker: 1),
|
|
209
|
+
'AllowNonPersistableEntities' => false, 'AllowUpload' => false,
|
|
210
|
+
'AssociationTypes' => IO::BsonCodec.build_array(property[:association_types], marker: 1),
|
|
211
|
+
'DataSourceProperty' => property[:data_source],
|
|
212
|
+
'DefaultType' => property[:default_type].empty? ? 'None' : property[:default_type],
|
|
213
|
+
'DefaultValue' => property[:default], 'EntityProperty' => '',
|
|
214
|
+
'EnumerationValues' => enumeration_values(property[:enum_values]),
|
|
215
|
+
'IsLinked' => property[:linked], 'IsList' => property[:list], 'IsMetaData' => property[:metadata],
|
|
216
|
+
'IsPath' => 'No', 'Multiline' => property[:multiline],
|
|
217
|
+
'ObjectType' => object_type(property[:children]), 'OnChangeProperty' => property[:on_change],
|
|
218
|
+
'ParameterIsList' => false, 'PathType' => 'None', 'Required' => property[:required],
|
|
219
|
+
'ReturnType' => widget_return_type(property[:return_type]),
|
|
220
|
+
'SelectableObjectsProperty' => property[:selectable_objects],
|
|
221
|
+
'SelectionTypes' => IO::BsonCodec.build_array(property[:selection_types], marker: 1),
|
|
222
|
+
'SetLabel' => property[:set_label], 'Translations' => widget_translations(property[:translations]),
|
|
223
|
+
'Type' => type
|
|
224
|
+
}
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def object_type(children)
|
|
228
|
+
return if children.empty?
|
|
229
|
+
|
|
230
|
+
types = children.map { property_pair(_1).first }
|
|
231
|
+
{
|
|
232
|
+
'$ID' => SecureRandom.uuid, '$Type' => 'CustomWidgets$WidgetObjectType',
|
|
233
|
+
'PropertyTypes' => IO::BsonCodec.build_array(types, marker: 2)
|
|
234
|
+
}
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def enumeration_values(values)
|
|
238
|
+
IO::BsonCodec.build_array(values.map do |key, caption|
|
|
239
|
+
{ '$ID' => SecureRandom.uuid, '$Type' => 'CustomWidgets$WidgetEnumerationValue',
|
|
240
|
+
'_Key' => key, 'Caption' => caption }
|
|
241
|
+
end, marker: 2)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def widget_translations(values)
|
|
245
|
+
IO::BsonCodec.build_array(values.map do |language, value|
|
|
246
|
+
{ '$ID' => SecureRandom.uuid, '$Type' => 'CustomWidgets$WidgetTranslation',
|
|
247
|
+
'LanguageCode' => language, 'Text' => value }
|
|
248
|
+
end, marker: 2)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def action_variables(values)
|
|
252
|
+
IO::BsonCodec.build_array(values.map do |variable|
|
|
253
|
+
{
|
|
254
|
+
'$ID' => SecureRandom.uuid, '$Type' => 'CustomWidgets$WidgetActionVariable',
|
|
255
|
+
'Caption' => variable.fetch(:caption), 'Key' => variable.fetch(:key),
|
|
256
|
+
'Type' => variable.fetch(:type)
|
|
257
|
+
}
|
|
258
|
+
end, marker: 2)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def widget_return_type(value)
|
|
262
|
+
return unless value
|
|
263
|
+
|
|
264
|
+
{ '$ID' => SecureRandom.uuid, '$Type' => 'CustomWidgets$WidgetReturnType',
|
|
265
|
+
'AssignableTo' => value[:assignable_to], 'EntityProperty' => '',
|
|
266
|
+
'IsList' => false, 'Type' => value[:type] }
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def widget_value(value_type, property) # rubocop:disable Metrics/MethodLength
|
|
270
|
+
value = {
|
|
271
|
+
'$ID' => SecureRandom.uuid, '$Type' => 'CustomWidgets$WidgetValue',
|
|
272
|
+
'Action' => { '$ID' => SecureRandom.uuid, '$Type' => 'Forms$NoAction',
|
|
273
|
+
'DisabledDuringExecution' => true },
|
|
274
|
+
'AttributeRef' => nil, 'DataSource' => nil, 'EntityRef' => nil, 'Expression' => '',
|
|
275
|
+
'Form' => '', 'Icon' => nil, 'Image' => '', 'Microflow' => '', 'Nanoflow' => '',
|
|
276
|
+
'Objects' => IO::BsonCodec.build_array([], marker: 2), 'PrimitiveValue' => '',
|
|
277
|
+
'Selection' => 'None', 'SourceVariable' => nil, 'TextTemplate' => nil,
|
|
278
|
+
'TranslatableValue' => nil, 'TypePointer' => value_type.fetch('$ID'),
|
|
279
|
+
'Widgets' => IO::BsonCodec.build_array([], marker: 2), 'XPathConstraint' => ''
|
|
280
|
+
}
|
|
281
|
+
default_widget_value(value, property)
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
285
|
+
# rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
286
|
+
def default_widget_value(value, property)
|
|
287
|
+
case property[:type]
|
|
288
|
+
when 'Boolean' then value['PrimitiveValue'] = property[:default].empty? ? 'false' : property[:default]
|
|
289
|
+
when 'Integer' then value['PrimitiveValue'] = property[:default].empty? ? '0' : property[:default]
|
|
290
|
+
when 'Enumeration' then value['PrimitiveValue'] = property[:default]
|
|
291
|
+
when 'String', 'Decimal' then value['PrimitiveValue'] = property[:default]
|
|
292
|
+
when 'Expression' then value['Expression'] = property[:default]
|
|
293
|
+
when 'Selection'
|
|
294
|
+
value['Selection'] = property[:default].empty? ? property[:selection_types].first || 'None' : property[:default]
|
|
295
|
+
when 'TextTemplate'
|
|
296
|
+
value['TextTemplate'] = client_template(property[:translations]) \
|
|
297
|
+
if property[:required] || !property[:default].empty? || !property[:translations].empty?
|
|
298
|
+
end
|
|
299
|
+
value
|
|
300
|
+
end
|
|
301
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
302
|
+
# rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
303
|
+
|
|
304
|
+
def client_template(translations)
|
|
305
|
+
items = translations.map do |language, value|
|
|
306
|
+
{ '$ID' => SecureRandom.uuid, '$Type' => 'Texts$Translation',
|
|
307
|
+
'LanguageCode' => language, 'Text' => value }
|
|
308
|
+
end
|
|
309
|
+
{ '$ID' => SecureRandom.uuid, '$Type' => 'Forms$ClientTemplate',
|
|
310
|
+
'Fallback' => { '$ID' => SecureRandom.uuid, '$Type' => 'Texts$Text',
|
|
311
|
+
'Items' => IO::BsonCodec.build_array([]) },
|
|
312
|
+
'Parameters' => IO::BsonCodec.build_array([], marker: 2),
|
|
313
|
+
'Template' => { '$ID' => SecureRandom.uuid, '$Type' => 'Texts$Text',
|
|
314
|
+
'Items' => IO::BsonCodec.build_array(items) } }
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def elements(root, name)
|
|
318
|
+
found = []
|
|
319
|
+
root&.each_recursive { found << _1 if _1.is_a?(REXML::Element) && _1.name == name }
|
|
320
|
+
found
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
def element_names(root, name) = elements(root, name).filter_map { _1.attributes['name'] }
|
|
324
|
+
|
|
325
|
+
def nested_elements(root, container, name)
|
|
326
|
+
wrapper = child(root, container)
|
|
327
|
+
wrapper ? wrapper.elements.to_a.select { _1.name == name } : []
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def nested_element_names(root, container, name)
|
|
331
|
+
nested_elements(root, container, name).filter_map { _1.attributes['name'] }
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def child(root, name) = root.elements.to_a.find { _1.name == name }
|
|
335
|
+
|
|
336
|
+
def text(root, name) = child(root, name)&.text.to_s
|
|
337
|
+
end
|
|
338
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mxrb
|
|
4
|
+
# Generates a project around Mendix's widget schema synchronization pass.
|
|
5
|
+
class WidgetSynchronizer
|
|
6
|
+
Result = Data.define(:definition, :project, :mx_path)
|
|
7
|
+
|
|
8
|
+
def initialize(definition, project)
|
|
9
|
+
@definition = File.expand_path(definition)
|
|
10
|
+
@project = File.expand_path(project)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def sync!
|
|
14
|
+
raise ArgumentError, "definition not found: #{@definition}" unless File.file?(@definition)
|
|
15
|
+
|
|
16
|
+
generate
|
|
17
|
+
generate
|
|
18
|
+
Result.new(@definition, @project, 'native MPK schemas')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def generate
|
|
24
|
+
previous = ENV['MXRB_OUTPUT_PATH']
|
|
25
|
+
ENV['MXRB_OUTPUT_PATH'] = @project
|
|
26
|
+
load @definition
|
|
27
|
+
ensure
|
|
28
|
+
previous ? ENV['MXRB_OUTPUT_PATH'] = previous : ENV.delete('MXRB_OUTPUT_PATH')
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|