@rglabs/butterfly 2.0.1

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.
Files changed (117) hide show
  1. package/CLAUDE.md +201 -0
  2. package/README.md +371 -0
  3. package/dist/commands/add.d.ts +23 -0
  4. package/dist/commands/add.js +303 -0
  5. package/dist/commands/code.d.ts +11 -0
  6. package/dist/commands/code.js +72 -0
  7. package/dist/commands/create-object.d.ts +6 -0
  8. package/dist/commands/create-object.js +293 -0
  9. package/dist/commands/create-report.d.ts +6 -0
  10. package/dist/commands/create-report.js +154 -0
  11. package/dist/commands/diff.d.ts +4 -0
  12. package/dist/commands/diff.js +238 -0
  13. package/dist/commands/download.d.ts +4 -0
  14. package/dist/commands/download.js +374 -0
  15. package/dist/commands/layout.d.ts +12 -0
  16. package/dist/commands/layout.js +83 -0
  17. package/dist/commands/record.d.ts +21 -0
  18. package/dist/commands/record.js +483 -0
  19. package/dist/commands/run-poc.d.ts +3 -0
  20. package/dist/commands/run-poc.js +18 -0
  21. package/dist/commands/setup.d.ts +3 -0
  22. package/dist/commands/setup.js +66 -0
  23. package/dist/commands/start-poc.d.ts +3 -0
  24. package/dist/commands/start-poc.js +55 -0
  25. package/dist/commands/sync-docs.d.ts +3 -0
  26. package/dist/commands/sync-docs.js +27 -0
  27. package/dist/commands/translate.d.ts +13 -0
  28. package/dist/commands/translate.js +401 -0
  29. package/dist/commands/upload.d.ts +3 -0
  30. package/dist/commands/upload.js +150 -0
  31. package/dist/commands/workflow-info.d.ts +13 -0
  32. package/dist/commands/workflow-info.js +161 -0
  33. package/dist/components/ConflictResolver.d.ts +12 -0
  34. package/dist/components/ConflictResolver.js +77 -0
  35. package/dist/components/DiffView.d.ts +11 -0
  36. package/dist/components/DiffView.js +101 -0
  37. package/dist/components/DownloadProgress.d.ts +11 -0
  38. package/dist/components/DownloadProgress.js +29 -0
  39. package/dist/components/RecordPreview.d.ts +11 -0
  40. package/dist/components/RecordPreview.js +91 -0
  41. package/dist/components/SetupForm.d.ts +8 -0
  42. package/dist/components/SetupForm.js +56 -0
  43. package/dist/components/UploadProgress.d.ts +13 -0
  44. package/dist/components/UploadProgress.js +42 -0
  45. package/dist/diff/adapters/index.d.ts +8 -0
  46. package/dist/diff/adapters/index.js +18 -0
  47. package/dist/diff/adapters/objectsAdapter.d.ts +13 -0
  48. package/dist/diff/adapters/objectsAdapter.js +177 -0
  49. package/dist/diff/adapters/reportsAdapter.d.ts +14 -0
  50. package/dist/diff/adapters/reportsAdapter.js +212 -0
  51. package/dist/diff/adapters/types.d.ts +19 -0
  52. package/dist/diff/adapters/types.js +2 -0
  53. package/dist/diff/engine.d.ts +19 -0
  54. package/dist/diff/engine.js +57 -0
  55. package/dist/diff/types.d.ts +34 -0
  56. package/dist/diff/types.js +110 -0
  57. package/dist/index.d.ts +3 -0
  58. package/dist/index.js +117 -0
  59. package/dist/types/index.d.ts +18 -0
  60. package/dist/types/index.js +2 -0
  61. package/dist/utils/api.d.ts +85 -0
  62. package/dist/utils/api.js +1031 -0
  63. package/dist/utils/auth.d.ts +4 -0
  64. package/dist/utils/auth.js +22 -0
  65. package/dist/utils/bfySplitter.d.ts +12 -0
  66. package/dist/utils/bfySplitter.js +151 -0
  67. package/dist/utils/docs.d.ts +16 -0
  68. package/dist/utils/docs.js +186 -0
  69. package/dist/utils/errorLogger.d.ts +6 -0
  70. package/dist/utils/errorLogger.js +29 -0
  71. package/dist/utils/files.d.ts +14 -0
  72. package/dist/utils/files.js +772 -0
  73. package/dist/utils/lockManager.d.ts +15 -0
  74. package/dist/utils/lockManager.js +126 -0
  75. package/dist/utils/resourceHandlers.d.ts +50 -0
  76. package/dist/utils/resourceHandlers.js +684 -0
  77. package/dist/utils/resourceMapping.d.ts +32 -0
  78. package/dist/utils/resourceMapping.js +210 -0
  79. package/dist/utils/singleResourceDownload.d.ts +14 -0
  80. package/dist/utils/singleResourceDownload.js +261 -0
  81. package/dist/utils/summaryGenerator.d.ts +2 -0
  82. package/dist/utils/summaryGenerator.js +183 -0
  83. package/dist/utils/uploadHandler.d.ts +31 -0
  84. package/dist/utils/uploadHandler.js +263 -0
  85. package/docs/AI_API.md +93 -0
  86. package/docs/CLAUDE.md +216 -0
  87. package/docs/PROJECT_SPECIFIC.md +1 -0
  88. package/docs/RECORD_COMMAND.md +262 -0
  89. package/docs/WORKFLOW_API.md +480 -0
  90. package/docs/bfy-splitting.md +126 -0
  91. package/docs/cli-commands.md +333 -0
  92. package/docs/examples/README.md +95 -0
  93. package/docs/examples/order-system.md +147 -0
  94. package/docs/examples/product-catalog.md +195 -0
  95. package/docs/examples/reports.md +187 -0
  96. package/docs/excel-export.md +216 -0
  97. package/docs/field-types/README.md +29 -0
  98. package/docs/field-types/calculated.md +147 -0
  99. package/docs/field-types/code-mappings.md +84 -0
  100. package/docs/field-types/custom.md +340 -0
  101. package/docs/object-specs/README.md +136 -0
  102. package/docs/object-specs/code-parameters.md +151 -0
  103. package/docs/object-specs/creating.md +203 -0
  104. package/docs/object-specs/js-code-examples.md +208 -0
  105. package/docs/object-specs/js-field-updates.md +168 -0
  106. package/docs/objects/README.md +89 -0
  107. package/docs/objects/creating.md +127 -0
  108. package/docs/page-layout.md +361 -0
  109. package/docs/permissions.md +260 -0
  110. package/docs/reports.md +197 -0
  111. package/docs/state-machines.md +544 -0
  112. package/docs/tasks/create-object.md +81 -0
  113. package/docs/translations.md +346 -0
  114. package/docs/twig-helpers.md +283 -0
  115. package/docs/webservices.md +159 -0
  116. package/docs/workspaces.md +176 -0
  117. package/package.json +59 -0
@@ -0,0 +1,197 @@
1
+ # Reports Guide
2
+
3
+ Reports in Butterfly are created using the `cms_reports` table with queries in `cms_report_queries`.
4
+
5
+ > **Important:** Always use `cms_report_queries` for Twig query code. The `query` field in `cms_reports` is **deprecated**.
6
+
7
+ ## Creating a Report
8
+
9
+ ### 1. Create Report Record
10
+
11
+ ```bash
12
+ butterfly-cli record add cms_reports --data '{
13
+ "title": "Sales Report",
14
+ "alias": "sales-report",
15
+ "category_id": 1
16
+ }'
17
+ ```
18
+
19
+ ### 2. Add Report Query
20
+
21
+ ```bash
22
+ butterfly-cli record add cms_report_queries --data '{
23
+ "cms_report_id": <REPORT_ID>,
24
+ "name": "Sales Data",
25
+ "system_name": "sales_data",
26
+ "column_size": "1",
27
+ "query": "{% set records = db().table(\"orders\").where(\"status\", \"completed\").get() %}"
28
+ }'
29
+ ```
30
+
31
+ ## Report Query Fields
32
+
33
+ | Field | Description |
34
+ |-------|-------------|
35
+ | `cms_report_id` | Parent report ID |
36
+ | `name` | Display name |
37
+ | `system_name` | System identifier |
38
+ | `query` | Twig query code |
39
+ | `column_size` | Layout width: `1`, `1/2`, `1/3`, `2/3`, `1/4`, `3/4` |
40
+ | `js_code` | Optional JavaScript processing code |
41
+
42
+ ## Query Code Examples
43
+
44
+ ### Basic Query
45
+
46
+ ```twig
47
+ {% set records = db()
48
+ .table('orders')
49
+ .where('status', 'completed')
50
+ .orderByDesc('created_at')
51
+ .get()
52
+ %}
53
+ ```
54
+
55
+ ### With Parameters
56
+
57
+ ```twig
58
+ {% set startDate = getParameter('start_date') %}
59
+ {% set endDate = getParameter('end_date') %}
60
+
61
+ {% set records = db()
62
+ .table('orders')
63
+ .where('created_at', '>=', startDate)
64
+ .where('created_at', '<=', endDate)
65
+ .get()
66
+ %}
67
+ ```
68
+
69
+ ### With Joins
70
+
71
+ ```twig
72
+ {% set records = db()
73
+ .table('orders')
74
+ .join('users', 'users.id', '=', 'orders.user_id')
75
+ .join('products', 'products.id', '=', 'orders.product_id')
76
+ .select(
77
+ 'orders.*',
78
+ 'users.name as customer_name',
79
+ 'products.title as product_name'
80
+ )
81
+ .get()
82
+ %}
83
+ ```
84
+
85
+ ### Aggregations
86
+
87
+ ```twig
88
+ {% set summary = db()
89
+ .table('orders')
90
+ .select(
91
+ 'status',
92
+ 'COUNT(*) as count',
93
+ 'SUM(total) as total_amount'
94
+ )
95
+ .groupBy('status')
96
+ .get()
97
+ %}
98
+ ```
99
+
100
+ ### Current User Filter
101
+
102
+ ```twig
103
+ {% set userId = currentUser('id') %}
104
+
105
+ {% set records = db()
106
+ .table('tasks')
107
+ .where('assigned_to', userId)
108
+ .get()
109
+ %}
110
+ ```
111
+
112
+ ## Report Specs
113
+
114
+ Report specs use the same field types as object specs. Add filter fields to reports:
115
+
116
+ ```bash
117
+ butterfly-cli record add cms_report_specs --data '{
118
+ "cms_report_id": <REPORT_ID>,
119
+ "name": "Status Filter",
120
+ "column_name": "status_filter",
121
+ "type": "from_list",
122
+ "val_1": "all:All|pending:Pending|completed:Completed"
123
+ }'
124
+ ```
125
+
126
+ Use in query:
127
+
128
+ ```twig
129
+ {% set statusFilter = getParameter('status_filter') %}
130
+
131
+ {% set query = db().table('orders') %}
132
+
133
+ {% if statusFilter and statusFilter != 'all' %}
134
+ {% set query = query.where('status', statusFilter) %}
135
+ {% endif %}
136
+
137
+ {% set records = query.get() %}
138
+ ```
139
+
140
+ ## File Structure
141
+
142
+ Downloaded reports are stored in:
143
+
144
+ ```
145
+ butterfly-resources/
146
+ └── reports/
147
+ └── [report-alias]/
148
+ ├── report.json # Report definition
149
+ ├── queries/
150
+ │ └── [query-name]/
151
+ │ ├── query.json
152
+ │ ├── query_code.bfy # Twig query code
153
+ │ └── script.js # Optional JS code
154
+ └── specs/
155
+ └── [field-name]/
156
+ ├── spec.json
157
+ └── code.js # Optional JS code
158
+ ```
159
+
160
+ ## JavaScript Code (js_code)
161
+
162
+ Process data client-side after query execution:
163
+
164
+ ```javascript
165
+ // Access query results
166
+ var data = window.reportData.sales_data;
167
+
168
+ // Process or transform data
169
+ data.forEach(function(row) {
170
+ row.formatted_total = '$' + row.total.toFixed(2);
171
+ });
172
+ ```
173
+
174
+ ## Best Practices
175
+
176
+ 1. **Use `cms_report_queries`** - Never use the deprecated `query` field in `cms_reports`
177
+ 2. **Add parameters** - Use `getParameter()` for user-configurable filters
178
+ 3. **Limit results** - Use `.limit()` for large datasets
179
+ 4. **Check errors** - Monitor `.butterfly/error_log.txt` for query errors
180
+ 5. **Test queries** - Use `butterfly-cli code` to test before deploying
181
+
182
+ ### Testing Queries
183
+
184
+ ```bash
185
+ butterfly-cli code -c "{% set records = db().table('orders').limit(5).get() %}{{ dump(records) }}"
186
+ ```
187
+
188
+ ## Column Sizes
189
+
190
+ | Value | Width |
191
+ |-------|-------|
192
+ | `1` | Full width |
193
+ | `1/2` | Half width |
194
+ | `1/3` | One third |
195
+ | `2/3` | Two thirds |
196
+ | `1/4` | One quarter |
197
+ | `3/4` | Three quarters |