Class: OmnifocusMcp::Tools::Generators::QueryOmnifocusDebug
- Inherits:
-
Object
- Object
- OmnifocusMcp::Tools::Generators::QueryOmnifocusDebug
- Defined in:
- lib/omnifocus_mcp/tools/generators/query_omnifocus_debug.rb
Overview
Debug variant of ‘QueryOmnifocus` that returns raw field information for a single sample item. Useful for understanding what fields are actually exposed by the OmniFocus JS API.
Class Method Summary collapse
- .call(entity) ⇒ Object
-
.generate_debug_script(entity) ⇒ Object
Build the OmniJS debug script for the given entity.
Class Method Details
.call(entity) ⇒ Object
19 20 21 22 23 |
# File 'lib/omnifocus_mcp/tools/generators/query_omnifocus_debug.rb', line 19 def call(entity) require_relative "../operations/query_omnifocus_debug" Operations::QueryOmnifocusDebug.call(entity) end |
.generate_debug_script(entity) ⇒ Object
Build the OmniJS debug script for the given entity.
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 |
# File 'lib/omnifocus_mcp/tools/generators/query_omnifocus_debug.rb', line 27 def generate_debug_script(entity) <<~JS (() => { try { let item; const entityType = "#{entity}"; if (entityType === "task") { item = flattenedTasks[0]; } else if (entityType === "project") { item = flattenedProjects[0]; } else if (entityType === "folder") { item = flattenedFolders[0]; } if (!item) { return JSON.stringify({ error: "No items found" }); } const properties = {}; const skipProps = ['constructor', 'toString', 'valueOf']; for (let prop in item) { if (skipProps.includes(prop)) continue; try { const value = item[prop]; const valueType = typeof value; if (value === null) { properties[prop] = { type: 'null', value: null }; } else if (value === undefined) { properties[prop] = { type: 'undefined', value: undefined }; } else if (valueType === 'function') { properties[prop] = { type: 'function', value: '[Function]' }; } else if (value instanceof Date) { properties[prop] = { type: 'Date', value: value.toISOString() }; } else if (Array.isArray(value)) { properties[prop] = { type: 'Array', length: value.length, sample: value.length > 0 ? value[0] : null }; } else if (valueType === 'object') { if (value.id && value.id.primaryKey) { properties[prop] = { type: 'OFObject', id: value.id.primaryKey, name: value.name || null }; } else { properties[prop] = { type: 'object', keys: Object.keys(value) }; } } else { properties[prop] = { type: valueType, value: value }; } } catch (e) { properties[prop] = { type: 'error', error: e.toString() }; } } const checkProps = [ 'id', 'name', 'note', 'flagged', 'dueDate', 'deferDate', 'estimatedMinutes', 'modificationDate', 'creationDate', 'completionDate', 'taskStatus', 'status', 'tasks', 'projects', 'containingProject', 'parentFolder', 'parent', 'children' ]; const expectedProps = {}; checkProps.forEach(prop => { try { const value = item[prop]; if (value !== undefined) { if (value && value.id && value.id.primaryKey) { expectedProps[prop] = { exists: true, type: 'OFObject', id: value.id.primaryKey }; } else if (value instanceof Date) { expectedProps[prop] = { exists: true, type: 'Date', value: value.toISOString() }; } else if (Array.isArray(value)) { expectedProps[prop] = { exists: true, type: 'Array', length: value.length }; } else { expectedProps[prop] = { exists: true, type: typeof value, value: value }; } } else { expectedProps[prop] = { exists: false }; } } catch (e) { expectedProps[prop] = { exists: false, error: e.toString() }; } }); return JSON.stringify({ entityType: entityType, itemName: item.name || 'Unnamed', allProperties: properties, expectedProperties: expectedProps }, null, 2); } catch (error) { return JSON.stringify({ error: error.toString() }); } })(); JS end |