Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ONE.Interfaces.ProtocolBuffers
Submodule ONE.Interfaces.ProtocolBuffers updated 86 files
+5 −1 proto/one/common/configuration/configuration_note.proto
+12 −3 proto/one/common/core/content.proto
+2 −2 proto/one/common/core/jsonTicksDateTime.proto
+17 −0 proto/one/common/core/localization.proto
+16 −0 proto/one/common/core/translation.proto
+37 −0 proto/one/common/event/cloud_event.proto
+22 −0 proto/one/common/remoting/enum_serialization_method.proto
+26 −0 proto/one/common/remoting/serialized_remoting_message.proto
+3 −0 proto/one/enterprise/data/report_definition_json_v2.proto
+1 −0 proto/one/enterprise/report/enum_rendering_engine.proto
+10 −0 proto/one/enterprise/report/enum_report_file_output_type.proto
+39 −0 proto/one/instrument/core/instrument_detail_summary.proto
+30 −0 proto/one/instrument/core/instrument_manifest_summary.proto
+29 −0 proto/one/instrument/core/instrument_measurement_definition_summary.proto
+41 −0 proto/one/instrument/core/instrument_measurement_summary.proto
+25 −0 proto/one/instrument/core/instrument_prognosys_summary.proto
+42 −0 proto/one/instrument/core/instrument_status_summary.proto
+32 −0 proto/one/instrument/core/instrument_summary.proto
+24 −0 proto/one/instrument/data/diagnostic/instrument_diagnostic.proto
+12 −0 proto/one/instrument/data/diagnostic/instrument_diagnostic_value.proto
+23 −0 proto/one/instrument/data/event/instrument_event_data.proto
+15 −0 proto/one/instrument/data/event/instrument_event_metadata.proto
+53 −0 proto/one/instrument/data/instrument_data.proto
+34 −0 proto/one/instrument/data/measurement/instrument_measurement.proto
+31 −0 proto/one/instrument/data/measurement/instrument_measurement_data.proto
+17 −0 proto/one/instrument/data/performance/instrument_performance.proto
+18 −0 proto/one/instrument/data/setting/instrument_settings.proto
+34 −0 proto/one/instrument/data/status/instrument_status.proto
+24 −0 proto/one/instrument/data/status/instrument_status_metadata.proto
+37 −0 proto/one/instrument/data/status/instrument_status_prognosys.proto
+18 −0 proto/one/instrument/instrument_health.proto
+9 −0 proto/one/instrument/twin/enum_connection_status.proto
+10 −0 proto/one/instrument/twin/enum_instrument_registry_status.proto
+18 −0 proto/one/instrument/twin/external/claros_i18nkey_text_reference.proto
+27 −0 proto/one/instrument/twin/external/claros_jsonTicksDateTime.proto
+17 −0 proto/one/instrument/twin/external/claros_key_value.proto
+36 −0 proto/one/instrument/twin/instrument.proto
+19 −0 proto/one/instrument/twin/instrument_identifier.proto
+31 −0 proto/one/instrument/twin/instrument_reference.proto
+43 −0 proto/one/instrument/twin/instrument_twin.proto
+14 −0 proto/one/instrument/twin/instrument_twin_detail.proto
+31 −0 proto/one/instrument/twin/instrument_twin_sub_type.proto
+25 −0 proto/one/instrument/twin/instrument_twin_type.proto
+27 −0 proto/one/instrument/twin/instrument_twin_update.proto
+11 −0 proto/one/instrument/twin/manifest/enum_instrument_data_attribute_priority.proto
+10 −0 proto/one/instrument/twin/manifest/enum_instrument_tag_definition_type.proto
+14 −0 proto/one/instrument/twin/manifest/enum_registry_type.proto
+16 −0 proto/one/instrument/twin/manifest/instrument_error_capability.proto
+16 −0 proto/one/instrument/twin/manifest/instrument_file_transfer_capability.proto
+26 −0 proto/one/instrument/twin/manifest/instrument_file_transfer_definition.proto
+25 −0 proto/one/instrument/twin/manifest/instrument_group.proto
+62 −0 proto/one/instrument/twin/manifest/instrument_manifest.proto
+18 −0 proto/one/instrument/twin/manifest/instrument_measurement_capability.proto
+36 −0 proto/one/instrument/twin/manifest/instrument_parameter_definition.proto
+19 −0 proto/one/instrument/twin/manifest/instrument_platform_capability.proto
+17 −0 proto/one/instrument/twin/manifest/instrument_prognosys_capability.proto
+17 −0 proto/one/instrument/twin/manifest/instrument_settings_capability.proto
+10 −0 proto/one/instrument/twin/manifest/instrument_settings_component_based_menu.proto
+31 −0 proto/one/instrument/twin/manifest/instrument_settings_definition.proto
+13 −0 proto/one/instrument/twin/manifest/instrument_settings_definition_based_menu.proto
+20 −0 proto/one/instrument/twin/manifest/instrument_status_definition.proto
+17 −0 proto/one/instrument/twin/manifest/instrument_tag_capability.proto
+48 −0 proto/one/instrument/twin/manifest/instrument_tag_definition.proto
+21 −0 proto/one/instrument/twin/manifest/instrument_tag_identifier.proto
+57 −0 proto/one/instrument/twin/manifest/instrument_type.proto
+16 −0 proto/one/instrument/twin/manifest/instrument_warning_capability.proto
+23 −0 proto/one/instrument/twin/manifest/prognosys_definition.proto
+18 −0 proto/one/instrument/twin/manifest/prognosys_identifier.proto
+21 −0 proto/one/operations/model/external/delphi_configuration_execution.proto
+5 −2 proto/one/operations/model/external/delphi_details_parameter.proto
+5 −2 proto/one/operations/model/external/delphi_execution_parameter.proto
+38 −0 proto/one/operations/model/external/delphi_model_details.proto
+42 −0 proto/one/operations/model/external/delphi_model_execution.proto
+20 −0 proto/one/operations/model/external/delphi_scenario_configuration.proto
+13 −0 proto/one/operations/model/external/enum_delphi_model_mode.proto
+43 −0 proto/one/operations/model/external/enum_delphi_model_tag_scenario.proto
+14 −0 proto/one/operations/model/external/enum_delphi_model_tag_sumo24.proto
+13 −0 proto/one/operations/model/model_detail.proto
+0 −30 proto/one/operations/model/model_execution.proto
+12 −23 proto/one/operations/model/model_template.proto
+6 −1 proto/one/operations/spreadsheet/column.proto
+3 −0 proto/one/operations/spreadsheet/computation_binding.proto
+37 −0 proto/one/operations/spreadsheet/computation_execution.proto
+11 −0 proto/one/operations/spreadsheet/enum_one_cascade_rule.proto
+12 −2 proto/one/operations/spreadsheet/historian_binding.proto
+43 −0 proto/one/operations/workmanager/equipment.proto
15 changes: 13 additions & 2 deletions generation/generateJS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ npm install
PROTOPATHS=`find ../one.interfaces.protocolbuffers -type d -print | xargs -n 1 -I {} echo "-p {}" | xargs echo`

# == compile with protobufjs ==
for P in `find ../one.interfaces.protocolbuffers/proto/one -name "*.proto"`
for P in `find ../one.interfaces.protocolbuffers/proto/flat -name "*.proto"`
do
PROTO=`basename -s .proto ${P}`
echo "=== ${P} :: (${PROTO})"

node_modules/protobufjs/cli/bin/pbjs -t static-module -w commonjs ${PROTOPATHS} -o ./out/js/${PROTO}.js ${P}
# Special handling for apiresponse to include all enum files
if [ "$PROTO" = "apiresponse" ]; then
echo "=== Including all enum files for apiresponse ==="
ENUM_FILES=`find ../one.interfaces.protocolbuffers/proto/flat -name "enum_*.proto" | xargs echo`
node_modules/protobufjs/cli/bin/pbjs -t static-module -w commonjs ${PROTOPATHS} -o ./out/js/${PROTO}.js ${P} ${ENUM_FILES}
else
node_modules/protobufjs/cli/bin/pbjs -t static-module -w commonjs ${PROTOPATHS} -o ./out/js/${PROTO}.js ${P}
fi

done

# == post-process files to move enums to bottom ==
echo "=== Post-processing files to move enums to bottom ==="
node reorganize-enums.js
181 changes: 181 additions & 0 deletions generation/reorganize-enums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
const fs = require('fs');
const path = require('path');

console.log('=== Enum Reorganization Script ===');

const outputDir = './out/js';
if (!fs.existsSync(outputDir)) {
console.log('Output directory does not exist. Run the full generation first.');
process.exit(1);
}

const files = fs.readdirSync(outputDir).filter(f => f.endsWith('.js'));
console.log(`Found ${files.length} JS files to process`);

files.forEach(filename => {
const filepath = path.join(outputDir, filename);
const content = fs.readFileSync(filepath, 'utf8');

console.log(`Processing ${filename}...`);

// Check if file has already been processed
if (content.includes('// === ENUMS SECTION - All enums moved to bottom ===')) {
console.log(` - Already processed, skipping ${filename}`);
return;
}

const lines = content.split('\n');
const cleanLines = [];
const enumBlocks = [];
let i = 0;

// First pass: Find all enum definitions and their JSDoc comments
while (i < lines.length) {
const line = lines[i];

// Check if this is an enum definition
if (line.match(/^\$root\.Enum.*= \(function\(\)/)) {
const enumNameMatch = line.match(/^\$root\.(Enum\w+)/);
const enumName = enumNameMatch ? enumNameMatch[1] : null;

console.log(` Found enum: ${enumName}`);

// Find the end of the enum definition
let enumLines = [line];
let braceCount = 1;
let j = i + 1;

while (j < lines.length && braceCount > 0) {
const nextLine = lines[j];
enumLines.push(nextLine);

// Count braces
const openBraces = (nextLine.match(/\(/g) || []).length;
const closeBraces = (nextLine.match(/\)/g) || []).length;
braceCount += openBraces - closeBraces;

if (braceCount === 0 && nextLine.match(/^\}\)\(\);/)) {
break;
}
j++;
}

// Look for JSDoc comment for this enum (search backwards from current position first, then forwards)
let enumComment = null;

// Search backwards first (more likely to be nearby)
for (let k = i - 1; k >= 0; k--) {
if (lines[k] && lines[k].includes(`@exports ${enumName}`)) {
// Found the JSDoc comment, find its boundaries
let commentStart = k;
while (commentStart > 0 && lines[commentStart] && !lines[commentStart].match(/^\s*\/\*\*/)) {
commentStart--;
}

let commentEnd = k;
while (commentEnd < lines.length && lines[commentEnd] && !lines[commentEnd].match(/^\s*\*\//)) {
commentEnd++;
}

if (commentStart >= 0 && commentEnd < lines.length && lines[commentStart] && lines[commentEnd]) {
enumComment = lines.slice(commentStart, commentEnd + 1).join('\n');
console.log(` Found JSDoc comment for ${enumName} (backward search)`);
}
break;
}
}

// If not found backwards, search forwards
if (!enumComment) {
for (let k = j + 1; k < lines.length; k++) {
if (lines[k] && lines[k].includes(`@exports ${enumName}`)) {
// Found the JSDoc comment, find its boundaries
let commentStart = k;
while (commentStart > 0 && lines[commentStart] && !lines[commentStart].match(/^\s*\/\*\*/)) {
commentStart--;
}

let commentEnd = k;
while (commentEnd < lines.length && lines[commentEnd] && !lines[commentEnd].match(/^\s*\*\//)) {
commentEnd++;
}

if (commentStart >= 0 && commentEnd < lines.length && lines[commentStart] && lines[commentEnd]) {
enumComment = lines.slice(commentStart, commentEnd + 1).join('\n');
console.log(` Found JSDoc comment for ${enumName} (forward search)`);
}
break;
}
}
}

// Create the complete enum block
let enumBlock = '';
if (enumComment) {
enumBlock = enumComment + '\n' + enumLines.join('\n');
} else {
enumBlock = enumLines.join('\n');
console.log(` No JSDoc comment found for ${enumName}`);
}

enumBlocks.push(enumBlock);

// Skip past this enum definition
i = j + 1;
continue;
}

// Check if this line is part of an enum JSDoc comment (to be removed)
if (line.match(/^\s*\/\*\*/) || line.match(/^\s*\*\s*@exports\s+Enum/)) {
// This might be an enum JSDoc comment, check if it's for an enum
let isEnumComment = false;
let commentEnd = i;

// Find the end of this comment block
while (commentEnd < lines.length && !lines[commentEnd].match(/^\s*\*\//)) {
if (lines[commentEnd].match(/^\s*\*\s*@exports\s+Enum/)) {
isEnumComment = true;
}
commentEnd++;
}

if (isEnumComment) {
console.log(` Removing orphaned enum JSDoc comment at line ${i + 1}`);
// Skip this entire comment block
i = commentEnd + 1;
continue;
}
}

// This is a regular line, keep it
cleanLines.push(line);
i++;
}

console.log(` Found ${enumBlocks.length} enum blocks`);

// Reconstruct file with enums at bottom
if (enumBlocks.length > 0) {
// Remove the last module.exports line if it exists
while (cleanLines.length > 0 && (cleanLines[cleanLines.length - 1].trim() === '' || cleanLines[cleanLines.length - 1].includes('module.exports'))) {
cleanLines.pop();
}

const newContent = [
...cleanLines,
'',
'// === ENUMS SECTION - All enums moved to bottom ===',
'',
...enumBlocks,
'',
'module.exports = $root;'
].join('\n');

fs.writeFileSync(filepath, newContent);
console.log(` ✓ Moved ${enumBlocks.length} enum(s) to bottom in ${filename}`);
} else {
console.log(` - No enums found in ${filename}`);
}
});

console.log('=== Enum reorganization complete ===');
4 changes: 2 additions & 2 deletions lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aquaticinformatics/claros_protobuf",
"version": "15.2.0",
"description": "Claros Protocol Buffers for JavaScript (& TypeScript). Version 6.13.0 of ONE.Interfaces.ProtocolBuffers",
"version": "15.7.0",
"description": "Claros Protocol Buffers for JavaScript (& TypeScript). Version 7.12.0 of ONE.Interfaces.ProtocolBuffers",
"license": "UNLICENSED",
"main": "src/apiresponse.js",
"types": "types.d.ts",
Expand Down