@nodestackapp/server 2.5.0 → 2.6.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.
Files changed (221) hide show
  1. package/README.md +40 -28
  2. package/dist/NodeStack.d.ts +1 -1
  3. package/dist/NodeStack.d.ts.map +1 -1
  4. package/dist/NodeStack.js +73 -12
  5. package/dist/NodeStack.js.map +1 -1
  6. package/dist/admin/AdminUIBundler.d.ts.map +1 -1
  7. package/dist/admin/AdminUIBundler.js +1 -0
  8. package/dist/admin/AdminUIBundler.js.map +1 -1
  9. package/dist/admin/ui/css/main.css +34 -0
  10. package/dist/admin/ui/css/webhooks.css +8 -0
  11. package/dist/admin/ui/index.html +19150 -17212
  12. package/dist/admin/ui/js/api-keys.js +1381 -0
  13. package/dist/admin/ui/js/app.js +667 -641
  14. package/dist/admin/ui/js/apps.js +496 -489
  15. package/dist/admin/ui/js/collections.js +486 -484
  16. package/dist/admin/ui/js/command-palette.js +683 -673
  17. package/dist/admin/ui/js/flows-designer.js +1125 -1076
  18. package/dist/admin/ui/js/flows.js +908 -890
  19. package/dist/admin/ui/js/functions-tester.js +1 -1
  20. package/dist/admin/ui/js/functions-workbench.js +1144 -1101
  21. package/dist/admin/ui/js/functions.js +980 -979
  22. package/dist/admin/ui/js/rules.js +1080 -775
  23. package/dist/admin/ui/js/schema.js +346 -304
  24. package/dist/admin/ui/js/views.js +1 -1
  25. package/dist/apps/AppManager.d.ts +1 -1
  26. package/dist/apps/AppManager.d.ts.map +1 -1
  27. package/dist/apps/AppManager.js +4 -18
  28. package/dist/apps/AppManager.js.map +1 -1
  29. package/dist/apps/AppRegistry.d.ts +1 -0
  30. package/dist/apps/AppRegistry.d.ts.map +1 -1
  31. package/dist/apps/AppRegistry.js +78 -23
  32. package/dist/apps/AppRegistry.js.map +1 -1
  33. package/dist/apps/AppScope.d.ts +0 -1
  34. package/dist/apps/AppScope.d.ts.map +1 -1
  35. package/dist/apps/AppScope.js +5 -15
  36. package/dist/apps/AppScope.js.map +1 -1
  37. package/dist/auth/ApiKeyService.d.ts +62 -2
  38. package/dist/auth/ApiKeyService.d.ts.map +1 -1
  39. package/dist/auth/ApiKeyService.js +503 -8
  40. package/dist/auth/ApiKeyService.js.map +1 -1
  41. package/dist/auth/AuthService.d.ts +30 -1
  42. package/dist/auth/AuthService.d.ts.map +1 -1
  43. package/dist/auth/AuthService.js +468 -65
  44. package/dist/auth/AuthService.js.map +1 -1
  45. package/dist/auth/oauth/AppleProvider.d.ts +2 -0
  46. package/dist/auth/oauth/AppleProvider.d.ts.map +1 -1
  47. package/dist/auth/oauth/AppleProvider.js +40 -3
  48. package/dist/auth/oauth/AppleProvider.js.map +1 -1
  49. package/dist/auth/oauth/BaseOAuthProvider.d.ts +3 -2
  50. package/dist/auth/oauth/BaseOAuthProvider.d.ts.map +1 -1
  51. package/dist/auth/oauth/BaseOAuthProvider.js +29 -3
  52. package/dist/auth/oauth/BaseOAuthProvider.js.map +1 -1
  53. package/dist/auth/oauth/DiscordProvider.d.ts.map +1 -1
  54. package/dist/auth/oauth/DiscordProvider.js +4 -1
  55. package/dist/auth/oauth/DiscordProvider.js.map +1 -1
  56. package/dist/auth/oauth/GitHubProvider.d.ts.map +1 -1
  57. package/dist/auth/oauth/GitHubProvider.js +4 -1
  58. package/dist/auth/oauth/GitHubProvider.js.map +1 -1
  59. package/dist/auth/oauth/GoogleProvider.d.ts.map +1 -1
  60. package/dist/auth/oauth/GoogleProvider.js +4 -1
  61. package/dist/auth/oauth/GoogleProvider.js.map +1 -1
  62. package/dist/auth/oauth/MicrosoftProvider.d.ts.map +1 -1
  63. package/dist/auth/oauth/MicrosoftProvider.js +4 -1
  64. package/dist/auth/oauth/MicrosoftProvider.js.map +1 -1
  65. package/dist/auth/oauth/OAuthProviderRegistry.d.ts +6 -2
  66. package/dist/auth/oauth/OAuthProviderRegistry.d.ts.map +1 -1
  67. package/dist/auth/oauth/OAuthProviderRegistry.js +25 -10
  68. package/dist/auth/oauth/OAuthProviderRegistry.js.map +1 -1
  69. package/dist/auth/oauth/types.d.ts +4 -2
  70. package/dist/auth/oauth/types.d.ts.map +1 -1
  71. package/dist/cli/cli.d.ts.map +1 -1
  72. package/dist/cli/cli.js +228 -12
  73. package/dist/cli/cli.js.map +1 -1
  74. package/dist/core/config/ConfigService.d.ts.map +1 -1
  75. package/dist/core/config/ConfigService.js +5 -3
  76. package/dist/core/config/ConfigService.js.map +1 -1
  77. package/dist/core/config/EnvLoader.d.ts +14 -0
  78. package/dist/core/config/EnvLoader.d.ts.map +1 -1
  79. package/dist/core/config/EnvLoader.js +44 -0
  80. package/dist/core/config/EnvLoader.js.map +1 -1
  81. package/dist/core/container/Container.d.ts +14 -0
  82. package/dist/core/container/Container.d.ts.map +1 -1
  83. package/dist/core/container/Container.js +32 -0
  84. package/dist/core/container/Container.js.map +1 -1
  85. package/dist/core/errors/AppError.d.ts +7 -7
  86. package/dist/core/errors/AppError.d.ts.map +1 -1
  87. package/dist/core/errors/AppError.js +18 -14
  88. package/dist/core/errors/AppError.js.map +1 -1
  89. package/dist/core/events/EventBus.d.ts.map +1 -1
  90. package/dist/core/events/EventBus.js +36 -6
  91. package/dist/core/events/EventBus.js.map +1 -1
  92. package/dist/core/maintenance/MaintenanceGate.d.ts +47 -0
  93. package/dist/core/maintenance/MaintenanceGate.d.ts.map +1 -1
  94. package/dist/core/maintenance/MaintenanceGate.js +265 -7
  95. package/dist/core/maintenance/MaintenanceGate.js.map +1 -1
  96. package/dist/core/plugins/PluginManager.d.ts +20 -1
  97. package/dist/core/plugins/PluginManager.d.ts.map +1 -1
  98. package/dist/core/plugins/PluginManager.js +231 -146
  99. package/dist/core/plugins/PluginManager.js.map +1 -1
  100. package/dist/core/plugins/types.d.ts +48 -31
  101. package/dist/core/plugins/types.d.ts.map +1 -1
  102. package/dist/database/DatabaseService.d.ts +1 -0
  103. package/dist/database/DatabaseService.d.ts.map +1 -1
  104. package/dist/database/DatabaseService.js +24 -6
  105. package/dist/database/DatabaseService.js.map +1 -1
  106. package/dist/database/drivers/DriverRegistry.d.ts +1 -0
  107. package/dist/database/drivers/DriverRegistry.d.ts.map +1 -1
  108. package/dist/database/drivers/DriverRegistry.js +29 -0
  109. package/dist/database/drivers/DriverRegistry.js.map +1 -1
  110. package/dist/database/drivers/IDatabaseDriver.d.ts +1 -0
  111. package/dist/database/drivers/IDatabaseDriver.d.ts.map +1 -1
  112. package/dist/database/drivers/MssqlDriver.d.ts.map +1 -1
  113. package/dist/database/drivers/MssqlDriver.js +8 -2
  114. package/dist/database/drivers/MssqlDriver.js.map +1 -1
  115. package/dist/database/drivers/NodeSqliteDriver.d.ts.map +1 -1
  116. package/dist/database/drivers/NodeSqliteDriver.js +15 -1
  117. package/dist/database/drivers/NodeSqliteDriver.js.map +1 -1
  118. package/dist/database/migrations/SystemMigrations.d.ts.map +1 -1
  119. package/dist/database/migrations/SystemMigrations.js +62 -5
  120. package/dist/database/migrations/SystemMigrations.js.map +1 -1
  121. package/dist/flows/FlowEngine.js.map +1 -1
  122. package/dist/flows/FlowService.d.ts +7 -1
  123. package/dist/flows/FlowService.d.ts.map +1 -1
  124. package/dist/flows/FlowService.js +126 -12
  125. package/dist/flows/FlowService.js.map +1 -1
  126. package/dist/flows/FlowValidator.d.ts +1 -0
  127. package/dist/flows/FlowValidator.d.ts.map +1 -1
  128. package/dist/flows/FlowValidator.js +76 -1
  129. package/dist/flows/FlowValidator.js.map +1 -1
  130. package/dist/flows/types.d.ts +14 -2
  131. package/dist/flows/types.d.ts.map +1 -1
  132. package/dist/functions/FunctionService.d.ts +5 -1
  133. package/dist/functions/FunctionService.d.ts.map +1 -1
  134. package/dist/functions/FunctionService.js +84 -33
  135. package/dist/functions/FunctionService.js.map +1 -1
  136. package/dist/functions/runtime/QuickJsWasmRuntime.d.ts.map +1 -1
  137. package/dist/functions/runtime/QuickJsWasmRuntime.js +19 -10
  138. package/dist/functions/runtime/QuickJsWasmRuntime.js.map +1 -1
  139. package/dist/functions/types.d.ts +16 -2
  140. package/dist/functions/types.d.ts.map +1 -1
  141. package/dist/http/HttpServer.d.ts +3 -0
  142. package/dist/http/HttpServer.d.ts.map +1 -1
  143. package/dist/http/HttpServer.js +153 -6
  144. package/dist/http/HttpServer.js.map +1 -1
  145. package/dist/http/controllers/ApiKeyController.d.ts +1 -0
  146. package/dist/http/controllers/ApiKeyController.d.ts.map +1 -1
  147. package/dist/http/controllers/ApiKeyController.js +47 -1
  148. package/dist/http/controllers/ApiKeyController.js.map +1 -1
  149. package/dist/http/controllers/AuthController.d.ts +12 -0
  150. package/dist/http/controllers/AuthController.d.ts.map +1 -1
  151. package/dist/http/controllers/AuthController.js +40 -2
  152. package/dist/http/controllers/AuthController.js.map +1 -1
  153. package/dist/http/controllers/FlowController.d.ts.map +1 -1
  154. package/dist/http/controllers/FlowController.js +45 -4
  155. package/dist/http/controllers/FlowController.js.map +1 -1
  156. package/dist/http/controllers/FunctionController.d.ts.map +1 -1
  157. package/dist/http/controllers/FunctionController.js +16 -2
  158. package/dist/http/controllers/FunctionController.js.map +1 -1
  159. package/dist/http/controllers/HealthController.js +2 -2
  160. package/dist/http/middleware/AppResolutionMiddleware.d.ts +1 -1
  161. package/dist/http/middleware/AppResolutionMiddleware.d.ts.map +1 -1
  162. package/dist/http/middleware/AppResolutionMiddleware.js +2 -3
  163. package/dist/http/middleware/AppResolutionMiddleware.js.map +1 -1
  164. package/dist/http/middleware/AuthMiddleware.d.ts.map +1 -1
  165. package/dist/http/middleware/AuthMiddleware.js +6 -3
  166. package/dist/http/middleware/AuthMiddleware.js.map +1 -1
  167. package/dist/http/middleware/ChaosMiddleware.js +6 -6
  168. package/dist/http/middleware/ChaosMiddleware.js.map +1 -1
  169. package/dist/index.d.ts +2 -2
  170. package/dist/index.d.ts.map +1 -1
  171. package/dist/index.js +6 -2
  172. package/dist/index.js.map +1 -1
  173. package/dist/queue/QueueService.d.ts +9 -0
  174. package/dist/queue/QueueService.d.ts.map +1 -1
  175. package/dist/queue/QueueService.js +143 -60
  176. package/dist/queue/QueueService.js.map +1 -1
  177. package/dist/queue/drivers/SqliteQueueDriver.d.ts +3 -0
  178. package/dist/queue/drivers/SqliteQueueDriver.d.ts.map +1 -1
  179. package/dist/queue/drivers/SqliteQueueDriver.js +315 -255
  180. package/dist/queue/drivers/SqliteQueueDriver.js.map +1 -1
  181. package/dist/records/FtsService.d.ts +7 -3
  182. package/dist/records/FtsService.d.ts.map +1 -1
  183. package/dist/records/FtsService.js +69 -5
  184. package/dist/records/FtsService.js.map +1 -1
  185. package/dist/records/QueryFilterParser.d.ts.map +1 -1
  186. package/dist/records/QueryFilterParser.js +58 -20
  187. package/dist/records/QueryFilterParser.js.map +1 -1
  188. package/dist/records/RecordSanitizer.d.ts.map +1 -1
  189. package/dist/records/RecordSanitizer.js +32 -4
  190. package/dist/records/RecordSanitizer.js.map +1 -1
  191. package/dist/records/RecordService.d.ts +6 -0
  192. package/dist/records/RecordService.d.ts.map +1 -1
  193. package/dist/records/RecordService.js +95 -14
  194. package/dist/records/RecordService.js.map +1 -1
  195. package/dist/records/RecordValidator.d.ts +10 -0
  196. package/dist/records/RecordValidator.d.ts.map +1 -1
  197. package/dist/records/RecordValidator.js +110 -2
  198. package/dist/records/RecordValidator.js.map +1 -1
  199. package/dist/records/fts/IFtsDriver.d.ts +7 -6
  200. package/dist/records/fts/IFtsDriver.d.ts.map +1 -1
  201. package/dist/records/fts/MssqlFtsDriver.d.ts +5 -1
  202. package/dist/records/fts/MssqlFtsDriver.d.ts.map +1 -1
  203. package/dist/records/fts/MssqlFtsDriver.js +35 -3
  204. package/dist/records/fts/MssqlFtsDriver.js.map +1 -1
  205. package/dist/records/fts/PostgresFtsDriver.d.ts +9 -2
  206. package/dist/records/fts/PostgresFtsDriver.d.ts.map +1 -1
  207. package/dist/records/fts/PostgresFtsDriver.js +116 -11
  208. package/dist/records/fts/PostgresFtsDriver.js.map +1 -1
  209. package/dist/records/fts/SqliteFts5Driver.d.ts +7 -1
  210. package/dist/records/fts/SqliteFts5Driver.d.ts.map +1 -1
  211. package/dist/records/fts/SqliteFts5Driver.js +66 -6
  212. package/dist/records/fts/SqliteFts5Driver.js.map +1 -1
  213. package/dist/schema/OpenApiGenerator.d.ts.map +1 -1
  214. package/dist/schema/OpenApiGenerator.js +103 -3
  215. package/dist/schema/OpenApiGenerator.js.map +1 -1
  216. package/dist/schema/models/Field.d.ts +1 -0
  217. package/dist/schema/models/Field.d.ts.map +1 -1
  218. package/dist/templates/definitions/ecommerce.js +6 -6
  219. package/dist/templates/definitions/ecommerce.js.map +1 -1
  220. package/dist/webhooks/WebhookService.js +1 -1
  221. package/package.json +4 -3
@@ -1,484 +1,486 @@
1
- // Collections Management, Sidebar & Hub Views
2
-
3
- function renderCollectionsHubView() {
4
- const target = document.getElementById('collections-detail-pane') || document.getElementById('main-body');
5
- if (!target) return;
6
- const allCols = Array.isArray(state.collections)
7
- ? state.collections
8
- : (state.collections && Array.isArray(state.collections.items) ? state.collections.items : []);
9
- const userCols = allCols.filter(c => !isSystemCollection(c));
10
- const systemCols = allCols.filter(c => isSystemCollection(c));
11
-
12
- target.innerHTML = `
13
- <div class="hub-hero-banner">
14
- <div style="display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:0.75rem;">
15
- <div>
16
- <h2 style="font-size:18px; font-weight:800; color:var(--text-heading); letter-spacing:-0.02em;">Collections & Schema Directory</h2>
17
- <p style="font-size:12px; color:var(--text-muted); margin-top:3px;">
18
- Embedded SQLite database tables with instant REST API, CRUD endpoints, and realtime subscriptions.
19
- </p>
20
- </div>
21
- <div style="display:flex; align-items:center; gap:0.5rem;">
22
- <button class="btn btn-primary btn-sm" onclick="openNewCollectionModal()">+ New Collection</button>
23
- <button class="btn btn-secondary btn-sm" onclick="openTemplatesModal()"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block; vertical-align:-1px; margin-right:4px; color:var(--accent-primary);"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/></svg>Starter Recipes</button>
24
- <button class="btn btn-secondary btn-sm" onclick="openImportJsonModal()"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block; vertical-align:-1px; margin-right:4px; color:var(--accent-primary);"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>Import JSON</button>
25
- </div>
26
- </div>
27
-
28
- <div class="hub-stats-row" style="margin-top:0.5rem;">
29
- <div class="hub-stat-card">
30
- <span style="font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase;">Total Collections</span>
31
- <span style="font-size:20px; font-weight:800; color:var(--text-heading);">${allCols.length}</span>
32
- </div>
33
- <div class="hub-stat-card">
34
- <span style="font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase;">User Collections</span>
35
- <span style="font-size:20px; font-weight:800; color:var(--text-heading);">${userCols.length}</span>
36
- </div>
37
- <div class="hub-stat-card">
38
- <span style="font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase;">System Tables</span>
39
- <span style="font-size:20px; font-weight:800; color:var(--text-heading);">${systemCols.length}</span>
40
- </div>
41
- </div>
42
- </div>
43
-
44
- <div style="font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:0.05em; color:var(--text-muted); margin:0.25rem 0;">
45
- All Registered Collections (${allCols.length})
46
- </div>
47
-
48
- <div class="hub-cards-grid">
49
- ${allCols.map(col => {
50
- const isSys = isSystemCollection(col);
51
- const fieldCount = col.schema ? col.schema.length : 0;
52
- return `
53
- <div class="hub-card" onclick="selectCollection('${escapeHtml(col.name)}')">
54
- <div class="hub-card-header">
55
- <div class="hub-card-title">
56
- ${isSys
57
- ? '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color:var(--text-muted);"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>'
58
- : '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color:var(--accent-primary);"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path></svg>'}
59
- <span>${escapeHtml(col.name)}</span>
60
- </div>
61
- <div style="display:flex; align-items:center; gap:4px;">
62
- <span class="badge ${col.type === 'auth' ? 'badge-post' : 'badge-get'}" style="font-size:10px;">${escapeHtml(col.type)}</span>
63
- ${isSys ? `<span class="badge badge-warning" style="font-size:9.5px;">SYSTEM</span>` : ''}
64
- </div>
65
- </div>
66
- <div class="hub-card-desc">
67
- ${fieldCount} schema fields defined. Managed embedded table with automatic API rules and validation.
68
- </div>
69
- <div class="hub-card-footer">
70
- <button class="btn btn-secondary btn-sm" onclick="event.stopPropagation(); selectCollection('${escapeHtml(col.name)}')">
71
- Open Data Grid ➔
72
- </button>
73
- <button class="btn btn-secondary btn-sm" onclick="event.stopPropagation(); selectCollection('${escapeHtml(col.name)}'); switchCollectionTab('schema');" title="Configure schema">
74
- ⚙️ Schema
75
- </button>
76
- </div>
77
- </div>
78
- `;
79
- }).join('')}
80
- </div>
81
- `;
82
- }
83
-
84
- async function loadCollections() {
85
- try {
86
- const res = await api('/api/collections');
87
- state.collections = res.items || [];
88
- renderCollectionsList();
89
- if (typeof renderPluginNavItems === 'function') {
90
- renderPluginNavItems();
91
- }
92
- } catch (e) {
93
- toast(e.message, 'error');
94
- }
95
- }
96
-
97
- function isSystemCollection(col) {
98
- return Boolean(col.system || (col.name && col.name.startsWith('_')));
99
- }
100
-
101
- function toggleCollectionSection(section) {
102
- if (!state.collapsedSections) {
103
- state.collapsedSections = { user: false, system: false };
104
- }
105
- state.collapsedSections[section] = !state.collapsedSections[section];
106
- renderCollectionsList();
107
- }
108
-
109
- function handleCollectionFilterInput(val) {
110
- state.collectionFilterTerm = (val || '').trim();
111
- const clearBtn = document.getElementById('collection-filter-clear-btn');
112
- if (clearBtn) {
113
- clearBtn.style.display = state.collectionFilterTerm ? 'inline-flex' : 'none';
114
- }
115
- renderCollectionsList();
116
- }
117
-
118
- function clearCollectionFilter() {
119
- state.collectionFilterTerm = '';
120
- const input = document.getElementById('collection-filter-input');
121
- if (input) {
122
- input.value = '';
123
- input.focus();
124
- }
125
- const clearBtn = document.getElementById('collection-filter-clear-btn');
126
- if (clearBtn) {
127
- clearBtn.style.display = 'none';
128
- }
129
- renderCollectionsList();
130
- }
131
-
132
- function renderCollectionItemHtml(col) {
133
- const isActive = state.activeCollection?.name === col.name;
134
- return `
135
- <div class="collection-item ${isActive ? 'active' : ''}" onclick="selectCollection('${escapeHtml(col.name)}')" style="display:flex; align-items:center; justify-content:space-between; gap:4px;">
136
- <span style="overflow:hidden; text-overflow:ellipsis; white-space:nowrap; flex:1;">${escapeHtml(col.name)}</span>
137
- <div style="display:flex; align-items:center; gap:6px; flex-shrink:0;">
138
- <span class="collection-badge">${escapeHtml(col.type)}</span>
139
- ${!col.system ? `
140
- <span class="col-del-btn" title="Delete collection" data-col-name="${escapeHtml(col.name)}" onclick="event.stopPropagation(); openDeleteCollectionModal(this.getAttribute('data-col-name'))" style="cursor:pointer; opacity:0.4; font-size:11px; padding:2px 4px; border-radius:3px; transition:all 0.15s;" onmouseover="this.style.opacity='1'; this.style.color='#ef4444'; this.style.background='rgba(239,68,68,0.15)'" onmouseout="this.style.opacity='0.4'; this.style.color='inherit'; this.style.background='transparent'">
141
- ✕
142
- </span>
143
- ` : ''}
144
- </div>
145
- </div>
146
- `;
147
- }
148
-
149
- function renderCollectionsList() {
150
- const container = document.getElementById('collections-list');
151
- if (!container) return;
152
-
153
- const rawCols = state.collections;
154
- const allCols = Array.isArray(rawCols)
155
- ? rawCols
156
- : (rawCols && Array.isArray(rawCols.items) ? rawCols.items : []);
157
-
158
- const filterTerm = (state.collectionFilterTerm || '').toLowerCase();
159
- const userCols = allCols.filter(c => !isSystemCollection(c));
160
- const systemCols = allCols.filter(c => isSystemCollection(c));
161
-
162
- const filteredUserCols = filterTerm
163
- ? userCols.filter(c => c.name.toLowerCase().includes(filterTerm))
164
- : userCols;
165
-
166
- const filteredSystemCols = filterTerm
167
- ? systemCols.filter(c => c.name.toLowerCase().includes(filterTerm))
168
- : systemCols;
169
-
170
- // When searching, automatically expand sections
171
- const isUserCollapsed = Boolean(filterTerm ? false : state.collapsedSections?.user);
172
- const isSystemCollapsed = Boolean(filterTerm ? false : state.collapsedSections?.system);
173
-
174
- let html = '';
175
-
176
- // 1. User Collections Group
177
- html += `
178
- <div class="collection-group" id="group-user-collections">
179
- <div class="collection-group-header" onclick="toggleCollectionSection('user')" role="button" tabindex="0" aria-expanded="${!isUserCollapsed}" aria-controls="group-items-user" onkeydown="if(event.key==='Enter'||event.key===' '){event.preventDefault();toggleCollectionSection('user');}" title="Toggle User Collections">
180
- <div class="collection-group-title">
181
- <svg class="collection-group-chevron ${isUserCollapsed ? 'collapsed' : ''}" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
182
- <polyline points="6 9 12 15 18 9"></polyline>
183
- </svg>
184
- <span>User Collections</span>
185
- </div>
186
- <span class="collection-group-count">${filteredUserCols.length}</span>
187
- </div>
188
- <div class="collection-group-items ${isUserCollapsed ? 'collapsed' : ''}" id="group-items-user">
189
- ${filteredUserCols.length > 0
190
- ? filteredUserCols.map(col => renderCollectionItemHtml(col)).join('')
191
- : `<div class="collection-group-empty">${filterTerm ? 'No matching collections' : 'No user collections yet'}</div>`
192
- }
193
- </div>
194
- </div>
195
- `;
196
-
197
- // 2. System Tables Group
198
- html += `
199
- <div class="collection-group" id="group-system-tables">
200
- <div class="collection-group-header" onclick="toggleCollectionSection('system')" role="button" tabindex="0" aria-expanded="${!isSystemCollapsed}" aria-controls="group-items-system" onkeydown="if(event.key==='Enter'||event.key===' '){event.preventDefault();toggleCollectionSection('system');}" title="Toggle System Tables">
201
- <div class="collection-group-title">
202
- <svg class="collection-group-chevron ${isSystemCollapsed ? 'collapsed' : ''}" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
203
- <polyline points="6 9 12 15 18 9"></polyline>
204
- </svg>
205
- <span>System Tables</span>
206
- </div>
207
- <span class="collection-group-count">${filteredSystemCols.length}</span>
208
- </div>
209
- <div class="collection-group-items ${isSystemCollapsed ? 'collapsed' : ''}" id="group-items-system">
210
- ${filteredSystemCols.length > 0
211
- ? filteredSystemCols.map(col => renderCollectionItemHtml(col)).join('')
212
- : `<div class="collection-group-empty">${filterTerm ? 'No matching system tables' : 'No system tables'}</div>`
213
- }
214
- </div>
215
- </div>
216
- `;
217
-
218
- container.innerHTML = html;
219
-
220
- const countEl = document.getElementById('sidebar-collections-count');
221
- if (countEl) {
222
- countEl.textContent = String(state.collections ? state.collections.length : 0);
223
- }
224
-
225
- if (state.activeNav === 'collections' && !state.activeCollection) {
226
- renderCollectionsHubView();
227
- }
228
-
229
- if (state.admin) {
230
- const emailEl = document.getElementById('admin-user-email');
231
- if (emailEl) {
232
- emailEl.textContent = `Logout (${state.admin.email})`;
233
- }
234
- }
235
- }
236
-
237
- // Select Collection
238
- async function selectCollection(name, pushState = true) {
239
- state.activeNav = 'collection';
240
- const allCols = Array.isArray(state.collections)
241
- ? state.collections
242
- : (state.collections && Array.isArray(state.collections.items) ? state.collections.items : []);
243
- state.activeCollection = allCols.find(c => c.name === name);
244
- // Reset collection-specific records state
245
- state.recordsPage = 1;
246
- state.recordsFilter = '';
247
- state.recordsSearchTerm = '';
248
- state.recordsSearchField = '_all';
249
- state.recordsSort = '';
250
- state.selectedRecordId = null;
251
- if (typeof closeRecordDrawer === 'function') {
252
- closeRecordDrawer();
253
- }
254
-
255
- showPageView('collections');
256
- clearSidebarNavActive();
257
- document.getElementById('nav-collections')?.classList.add('active');
258
-
259
- renderCollectionsList();
260
-
261
- document.getElementById('collection-tabs').style.display = 'flex';
262
-
263
- document.getElementById('view-title').textContent = state.activeCollection ? state.activeCollection.name : name;
264
- document.getElementById('view-title').style.display = 'inline-block';
265
- const badge = document.getElementById('view-badge');
266
- if (badge && state.activeCollection) {
267
- badge.style.display = 'inline-flex';
268
- badge.textContent = state.activeCollection.type.toUpperCase();
269
- badge.className = 'badge ' + (state.activeCollection.type === 'auth' ? 'badge-post' : 'badge-get');
270
- }
271
-
272
- updateBreadcrumbs();
273
-
274
- if (state.collectionTab === 'records') {
275
- renderRecordsView();
276
- await loadRecords();
277
- } else {
278
- renderSchemaView();
279
- }
280
-
281
- if (pushState) {
282
- const sub = (state.collectionTab === 'schema') ? '/schema' : '';
283
- if (typeof updateUrl === 'function') {
284
- updateUrl('/_/collections/' + encodeURIComponent(name) + sub);
285
- }
286
- }
287
- }
288
-
289
- // Collection Tabs
290
- function switchCollectionTab(tab, pushState = true) {
291
- state.collectionTab = tab;
292
- document.getElementById('tab-records').className = tab === 'records' ? 'tab-btn active' : 'tab-btn';
293
- document.getElementById('tab-schema').className = tab === 'schema' ? 'tab-btn active' : 'tab-btn';
294
-
295
- updateBreadcrumbs();
296
-
297
- if (pushState && state.activeCollection) {
298
- const sub = (tab === 'schema') ? '/schema' : '';
299
- if (typeof updateUrl === 'function') {
300
- updateUrl('/_/collections/' + encodeURIComponent(state.activeCollection.name) + sub);
301
- }
302
- }
303
-
304
- if (tab === 'records') {
305
- renderRecordsView();
306
- loadRecords();
307
- } else {
308
- renderSchemaView();
309
- }
310
- }
311
-
312
- // ==========================================
313
- // Breadcrumb Top Bar
314
- // ==========================================
315
-
316
- function updateBreadcrumbs() {
317
- const trail = document.getElementById('breadcrumb-trail');
318
- if (!trail) return;
319
-
320
- const crumbs = [];
321
-
322
- // 1. NodeStack Root
323
- crumbs.push({
324
- label: 'NodeStack',
325
- clickable: true,
326
- action: () => selectNav('home')
327
- });
328
-
329
- if (state.activeNav === 'collection' && state.activeCollection) {
330
- crumbs.push({
331
- label: 'Collections',
332
- clickable: true,
333
- action: () => selectNav('collections')
334
- });
335
- crumbs.push({
336
- label: state.activeCollection.name,
337
- clickable: state.collectionTab !== 'records',
338
- action: () => switchCollectionTab('records')
339
- });
340
- if (state.collectionTab === 'schema') {
341
- crumbs.push({
342
- label: 'Schema & Rules',
343
- active: true
344
- });
345
- } else {
346
- crumbs.push({
347
- label: 'Records',
348
- active: true
349
- });
350
- }
351
- } else if (state.activeNav === 'collections') {
352
- crumbs.push({ label: 'Collections', active: true });
353
- } else if (state.activeNav === 'plugins') {
354
- crumbs.push({ label: 'Plugins', active: true });
355
- } else if (state.activeNav === 'webhooks') {
356
- if (typeof webhooksState !== 'undefined' && webhooksState.subTab === 'deliveries') {
357
- crumbs.push({ label: 'Webhooks', clickable: true, action: () => { if (typeof switchWebhooksTab === 'function') switchWebhooksTab('webhooks'); } });
358
- crumbs.push({ label: 'Delivery Logs', active: true });
359
- } else {
360
- crumbs.push({ label: 'Webhooks', active: true });
361
- }
362
- } else if (state.activeNav === 'functions') {
363
- if (typeof functionsState !== 'undefined' && functionsState.currentView === 'editor' && functionsState.activeFunctionForEdit) {
364
- crumbs.push({ label: 'Functions', clickable: true, action: () => { if (typeof closeFunctionEditor === 'function') closeFunctionEditor(); } });
365
- const editLabel = functionsState.activeFunctionForEdit.isNew
366
- ? (functionsState.activeFunctionForEdit.name || 'New Function')
367
- : functionsState.activeFunctionForEdit.name;
368
- crumbs.push({ label: editLabel, active: true });
369
- } else if (typeof functionsState !== 'undefined' && functionsState.subTab === 'logs') {
370
- crumbs.push({ label: 'Functions', clickable: true, action: () => { if (typeof switchFunctionsTab === 'function') switchFunctionsTab('functions'); } });
371
- crumbs.push({ label: 'Execution Logs', active: true });
372
- } else {
373
- crumbs.push({ label: 'Functions', active: true });
374
- }
375
- } else if (state.activeNav === 'flows') {
376
- if (typeof flowsState !== 'undefined' && flowsState.currentView === 'designer' && ((typeof designerState !== 'undefined' && designerState.activeFlow) || flowsState.activeFlowForEdit)) {
377
- crumbs.push({ label: 'Flows', clickable: true, action: () => { if (typeof closeFlowDesigner === 'function') closeFlowDesigner(); } });
378
- const currentFlow = (typeof designerState !== 'undefined' && designerState.activeFlow) || flowsState.activeFlowForEdit;
379
- crumbs.push({ label: currentFlow.name || currentFlow.id || 'Flow Designer', active: true });
380
- } else if (typeof flowsState !== 'undefined' && flowsState.subTab === 'executions') {
381
- crumbs.push({ label: 'Flows', clickable: true, action: () => { if (typeof switchFlowsTab === 'function') switchFlowsTab('flows'); } });
382
- crumbs.push({ label: 'Execution History', active: true });
383
- } else {
384
- crumbs.push({ label: 'Flows', active: true });
385
- }
386
- } else if (state.activeNav === 'queues') {
387
- if (typeof queuesState !== 'undefined' && (queuesState.subTab === 'messages' || queuesState.subTab === 'jobs')) {
388
- crumbs.push({ label: 'Queues', clickable: true, action: () => { if (typeof switchQueuesTab === 'function') switchQueuesTab('queues'); } });
389
- crumbs.push({ label: 'Message Inspector', active: true });
390
- } else {
391
- crumbs.push({ label: 'Queues', active: true });
392
- }
393
- } else if (state.activeNav === 'home') {
394
- crumbs.push({ label: 'Overview', active: true });
395
- } else if (state.activeNav === 'analytics') {
396
- crumbs.push({ label: 'Analytics', active: true });
397
- } else if (state.activeNav === 'snapshots') {
398
- crumbs.push({ label: 'Snapshots', active: true });
399
- } else if (state.activeNav === 'database') {
400
- crumbs.push({ label: 'Database Engine', active: true });
401
- } else if (state.activeNav === 'logs') {
402
- crumbs.push({ label: 'Audit Logs', active: true });
403
-
404
- } else if (state.pluginNavItems && state.pluginNavItems.some(p => p.id === state.activeNav)) {
405
- const item = state.pluginNavItems.find(p => p.id === state.activeNav);
406
- crumbs.push({ label: 'Plugins', clickable: true, action: () => selectNav('plugins') });
407
- crumbs.push({ label: item.title, active: true });
408
- }
409
-
410
- trail.innerHTML = crumbs.map((crumb, idx) => {
411
- const isLast = idx === crumbs.length - 1;
412
- let content = '';
413
- if (isLast || crumb.active) {
414
- content = `<span class="breadcrumb-item active" aria-current="page">${escapeHtml(crumb.label)}</span>`;
415
- } else if (crumb.clickable) {
416
- content = `<a href="javascript:void(0)" class="breadcrumb-item breadcrumb-link" onclick="handleBreadcrumbClick(${idx})">${escapeHtml(crumb.label)}</a>`;
417
- } else {
418
- content = `<span class="breadcrumb-item">${escapeHtml(crumb.label)}</span>`;
419
- }
420
-
421
- if (idx < crumbs.length - 1) {
422
- return `<li class="breadcrumb-crumb">${content}<span class="breadcrumb-separator" aria-hidden="true">/</span></li>`;
423
- }
424
- return `<li class="breadcrumb-crumb">${content}</li>`;
425
- }).join('');
426
-
427
- window._currentBreadcrumbs = crumbs;
428
- }
429
-
430
- function handleBreadcrumbClick(idx) {
431
- if (window._currentBreadcrumbs && window._currentBreadcrumbs[idx]?.action) {
432
- window._currentBreadcrumbs[idx].action();
433
- }
434
- }
435
-
436
- // ==========================================
437
- // Collections Create Dropdown Menu (+ New ▾)
438
- // ==========================================
439
-
440
- function toggleCollectionCreateMenu(e) {
441
- if (e) {
442
- e.stopPropagation();
443
- e.preventDefault();
444
- }
445
- const menu = document.getElementById('collection-create-menu');
446
- if (!menu) return;
447
- const isHidden = menu.style.display === 'none' || !menu.style.display;
448
- menu.style.display = isHidden ? 'flex' : 'none';
449
- }
450
-
451
- function closeCollectionCreateMenu() {
452
- const menu = document.getElementById('collection-create-menu');
453
- if (menu) menu.style.display = 'none';
454
- }
455
-
456
- function handleCollectionMenuAction(action) {
457
- closeCollectionCreateMenu();
458
- if (action === 'new') {
459
- openNewCollectionModal();
460
- } else if (action === 'templates') {
461
- openTemplatesModal();
462
- } else if (action === 'import') {
463
- openImportJsonModal();
464
- }
465
- }
466
-
467
- // Expose on window for browser event handlers & test harnesses
468
- if (typeof window !== 'undefined') {
469
- window.renderCollectionsHubView = renderCollectionsHubView;
470
- window.loadCollections = loadCollections;
471
- window.isSystemCollection = isSystemCollection;
472
- window.toggleCollectionSection = toggleCollectionSection;
473
- window.handleCollectionFilterInput = handleCollectionFilterInput;
474
- window.clearCollectionFilter = clearCollectionFilter;
475
- window.renderCollectionItemHtml = renderCollectionItemHtml;
476
- window.renderCollectionsList = renderCollectionsList;
477
- window.selectCollection = selectCollection;
478
- window.switchCollectionTab = switchCollectionTab;
479
- window.updateBreadcrumbs = updateBreadcrumbs;
480
- window.handleBreadcrumbClick = handleBreadcrumbClick;
481
- window.toggleCollectionCreateMenu = toggleCollectionCreateMenu;
482
- window.closeCollectionCreateMenu = closeCollectionCreateMenu;
483
- window.handleCollectionMenuAction = handleCollectionMenuAction;
484
- }
1
+ // Collections Management, Sidebar & Hub Views
2
+
3
+ function renderCollectionsHubView() {
4
+ const target = document.getElementById('collections-detail-pane') || document.getElementById('main-body');
5
+ if (!target) return;
6
+ const allCols = Array.isArray(state.collections)
7
+ ? state.collections
8
+ : (state.collections && Array.isArray(state.collections.items) ? state.collections.items : []);
9
+ const userCols = allCols.filter(c => !isSystemCollection(c));
10
+ const systemCols = allCols.filter(c => isSystemCollection(c));
11
+
12
+ target.innerHTML = `
13
+ <div class="hub-hero-banner">
14
+ <div style="display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:0.75rem;">
15
+ <div>
16
+ <h2 style="font-size:18px; font-weight:800; color:var(--text-heading); letter-spacing:-0.02em;">Collections & Schema Directory</h2>
17
+ <p style="font-size:12px; color:var(--text-muted); margin-top:3px;">
18
+ Embedded SQLite database tables with instant REST API, CRUD endpoints, and realtime subscriptions.
19
+ </p>
20
+ </div>
21
+ <div style="display:flex; align-items:center; gap:0.5rem;">
22
+ <button class="btn btn-primary btn-sm" onclick="openNewCollectionModal()">+ New Collection</button>
23
+ <button class="btn btn-secondary btn-sm" onclick="openTemplatesModal()"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block; vertical-align:-1px; margin-right:4px; color:var(--accent-primary);"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/></svg>Starter Recipes</button>
24
+ <button class="btn btn-secondary btn-sm" onclick="openImportJsonModal()"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block; vertical-align:-1px; margin-right:4px; color:var(--accent-primary);"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>Import JSON</button>
25
+ </div>
26
+ </div>
27
+
28
+ <div class="hub-stats-row" style="margin-top:0.5rem;">
29
+ <div class="hub-stat-card">
30
+ <span style="font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase;">Total Collections</span>
31
+ <span style="font-size:20px; font-weight:800; color:var(--text-heading);">${allCols.length}</span>
32
+ </div>
33
+ <div class="hub-stat-card">
34
+ <span style="font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase;">User Collections</span>
35
+ <span style="font-size:20px; font-weight:800; color:var(--text-heading);">${userCols.length}</span>
36
+ </div>
37
+ <div class="hub-stat-card">
38
+ <span style="font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase;">System Tables</span>
39
+ <span style="font-size:20px; font-weight:800; color:var(--text-heading);">${systemCols.length}</span>
40
+ </div>
41
+ </div>
42
+ </div>
43
+
44
+ <div style="font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:0.05em; color:var(--text-muted); margin:0.25rem 0;">
45
+ All Registered Collections (${allCols.length})
46
+ </div>
47
+
48
+ <div class="hub-cards-grid">
49
+ ${allCols.map(col => {
50
+ const isSys = isSystemCollection(col);
51
+ const fieldCount = col.schema ? col.schema.length : 0;
52
+ return `
53
+ <div class="hub-card" onclick="selectCollection('${escapeHtml(col.name)}')">
54
+ <div class="hub-card-header">
55
+ <div class="hub-card-title">
56
+ ${isSys
57
+ ? '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color:var(--text-muted);"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>'
58
+ : '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color:var(--accent-primary);"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path></svg>'}
59
+ <span>${escapeHtml(col.name)}</span>
60
+ </div>
61
+ <div style="display:flex; align-items:center; gap:4px;">
62
+ <span class="badge ${col.type === 'auth' ? 'badge-post' : 'badge-get'}" style="font-size:10px;">${escapeHtml(col.type)}</span>
63
+ ${isSys ? `<span class="badge badge-warning" style="font-size:9.5px;">SYSTEM</span>` : ''}
64
+ </div>
65
+ </div>
66
+ <div class="hub-card-desc">
67
+ ${fieldCount} schema fields defined. Managed embedded table with automatic API rules and validation.
68
+ </div>
69
+ <div class="hub-card-footer">
70
+ <button class="btn btn-secondary btn-sm" onclick="event.stopPropagation(); selectCollection('${escapeHtml(col.name)}')">
71
+ Open Data Grid ➔
72
+ </button>
73
+ <button class="btn btn-secondary btn-sm" onclick="event.stopPropagation(); selectCollection('${escapeHtml(col.name)}'); switchCollectionTab('schema');" title="Configure schema">
74
+ ⚙️ Schema
75
+ </button>
76
+ </div>
77
+ </div>
78
+ `;
79
+ }).join('')}
80
+ </div>
81
+ `;
82
+ }
83
+
84
+ async function loadCollections() {
85
+ try {
86
+ const res = await api('/api/collections');
87
+ state.collections = res.items || [];
88
+ renderCollectionsList();
89
+ if (typeof renderPluginNavItems === 'function') {
90
+ renderPluginNavItems();
91
+ }
92
+ } catch (e) {
93
+ toast(e.message, 'error');
94
+ }
95
+ }
96
+
97
+ function isSystemCollection(col) {
98
+ return Boolean(col.system || (col.name && col.name.startsWith('_')));
99
+ }
100
+
101
+ function toggleCollectionSection(section) {
102
+ if (!state.collapsedSections) {
103
+ state.collapsedSections = { user: false, system: false };
104
+ }
105
+ state.collapsedSections[section] = !state.collapsedSections[section];
106
+ renderCollectionsList();
107
+ }
108
+
109
+ function handleCollectionFilterInput(val) {
110
+ state.collectionFilterTerm = (val || '').trim();
111
+ const clearBtn = document.getElementById('collection-filter-clear-btn');
112
+ if (clearBtn) {
113
+ clearBtn.style.display = state.collectionFilterTerm ? 'inline-flex' : 'none';
114
+ }
115
+ renderCollectionsList();
116
+ }
117
+
118
+ function clearCollectionFilter() {
119
+ state.collectionFilterTerm = '';
120
+ const input = document.getElementById('collection-filter-input');
121
+ if (input) {
122
+ input.value = '';
123
+ input.focus();
124
+ }
125
+ const clearBtn = document.getElementById('collection-filter-clear-btn');
126
+ if (clearBtn) {
127
+ clearBtn.style.display = 'none';
128
+ }
129
+ renderCollectionsList();
130
+ }
131
+
132
+ function renderCollectionItemHtml(col) {
133
+ const isActive = state.activeCollection?.name === col.name;
134
+ return `
135
+ <div class="collection-item ${isActive ? 'active' : ''}" onclick="selectCollection('${escapeHtml(col.name)}')" style="display:flex; align-items:center; justify-content:space-between; gap:4px;">
136
+ <span style="overflow:hidden; text-overflow:ellipsis; white-space:nowrap; flex:1;">${escapeHtml(col.name)}</span>
137
+ <div style="display:flex; align-items:center; gap:6px; flex-shrink:0;">
138
+ <span class="collection-badge">${escapeHtml(col.type)}</span>
139
+ ${!col.system ? `
140
+ <span class="col-del-btn" title="Delete collection" data-col-name="${escapeHtml(col.name)}" onclick="event.stopPropagation(); openDeleteCollectionModal(this.getAttribute('data-col-name'))" style="cursor:pointer; opacity:0.4; font-size:11px; padding:2px 4px; border-radius:3px; transition:all 0.15s;" onmouseover="this.style.opacity='1'; this.style.color='#ef4444'; this.style.background='rgba(239,68,68,0.15)'" onmouseout="this.style.opacity='0.4'; this.style.color='inherit'; this.style.background='transparent'">
141
+ ✕
142
+ </span>
143
+ ` : ''}
144
+ </div>
145
+ </div>
146
+ `;
147
+ }
148
+
149
+ function renderCollectionsList() {
150
+ const container = document.getElementById('collections-list');
151
+ if (!container) return;
152
+
153
+ const rawCols = state.collections;
154
+ const allCols = Array.isArray(rawCols)
155
+ ? rawCols
156
+ : (rawCols && Array.isArray(rawCols.items) ? rawCols.items : []);
157
+
158
+ const filterTerm = (state.collectionFilterTerm || '').toLowerCase();
159
+ const userCols = allCols.filter(c => !isSystemCollection(c));
160
+ const systemCols = allCols.filter(c => isSystemCollection(c));
161
+
162
+ const filteredUserCols = filterTerm
163
+ ? userCols.filter(c => c.name.toLowerCase().includes(filterTerm))
164
+ : userCols;
165
+
166
+ const filteredSystemCols = filterTerm
167
+ ? systemCols.filter(c => c.name.toLowerCase().includes(filterTerm))
168
+ : systemCols;
169
+
170
+ // When searching, automatically expand sections
171
+ const isUserCollapsed = Boolean(filterTerm ? false : state.collapsedSections?.user);
172
+ const isSystemCollapsed = Boolean(filterTerm ? false : state.collapsedSections?.system);
173
+
174
+ let html = '';
175
+
176
+ // 1. User Collections Group
177
+ html += `
178
+ <div class="collection-group" id="group-user-collections">
179
+ <div class="collection-group-header" onclick="toggleCollectionSection('user')" role="button" tabindex="0" aria-expanded="${!isUserCollapsed}" aria-controls="group-items-user" onkeydown="if(event.key==='Enter'||event.key===' '){event.preventDefault();toggleCollectionSection('user');}" title="Toggle User Collections">
180
+ <div class="collection-group-title">
181
+ <svg class="collection-group-chevron ${isUserCollapsed ? 'collapsed' : ''}" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
182
+ <polyline points="6 9 12 15 18 9"></polyline>
183
+ </svg>
184
+ <span>User Collections</span>
185
+ </div>
186
+ <span class="collection-group-count">${filteredUserCols.length}</span>
187
+ </div>
188
+ <div class="collection-group-items ${isUserCollapsed ? 'collapsed' : ''}" id="group-items-user">
189
+ ${filteredUserCols.length > 0
190
+ ? filteredUserCols.map(col => renderCollectionItemHtml(col)).join('')
191
+ : `<div class="collection-group-empty">${filterTerm ? 'No matching collections' : 'No user collections yet'}</div>`
192
+ }
193
+ </div>
194
+ </div>
195
+ `;
196
+
197
+ // 2. System Tables Group
198
+ html += `
199
+ <div class="collection-group" id="group-system-tables">
200
+ <div class="collection-group-header" onclick="toggleCollectionSection('system')" role="button" tabindex="0" aria-expanded="${!isSystemCollapsed}" aria-controls="group-items-system" onkeydown="if(event.key==='Enter'||event.key===' '){event.preventDefault();toggleCollectionSection('system');}" title="Toggle System Tables">
201
+ <div class="collection-group-title">
202
+ <svg class="collection-group-chevron ${isSystemCollapsed ? 'collapsed' : ''}" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
203
+ <polyline points="6 9 12 15 18 9"></polyline>
204
+ </svg>
205
+ <span>System Tables</span>
206
+ </div>
207
+ <span class="collection-group-count">${filteredSystemCols.length}</span>
208
+ </div>
209
+ <div class="collection-group-items ${isSystemCollapsed ? 'collapsed' : ''}" id="group-items-system">
210
+ ${filteredSystemCols.length > 0
211
+ ? filteredSystemCols.map(col => renderCollectionItemHtml(col)).join('')
212
+ : `<div class="collection-group-empty">${filterTerm ? 'No matching system tables' : 'No system tables'}</div>`
213
+ }
214
+ </div>
215
+ </div>
216
+ `;
217
+
218
+ container.innerHTML = html;
219
+
220
+ const countEl = document.getElementById('sidebar-collections-count');
221
+ if (countEl) {
222
+ countEl.textContent = String(state.collections ? state.collections.length : 0);
223
+ }
224
+
225
+ if (state.activeNav === 'collections' && !state.activeCollection) {
226
+ renderCollectionsHubView();
227
+ }
228
+
229
+ if (state.admin) {
230
+ const emailEl = document.getElementById('admin-user-email');
231
+ if (emailEl) {
232
+ emailEl.textContent = `Logout (${state.admin.email})`;
233
+ }
234
+ }
235
+ }
236
+
237
+ // Select Collection
238
+ async function selectCollection(name, pushState = true) {
239
+ state.activeNav = 'collection';
240
+ const allCols = Array.isArray(state.collections)
241
+ ? state.collections
242
+ : (state.collections && Array.isArray(state.collections.items) ? state.collections.items : []);
243
+ state.activeCollection = allCols.find(c => c.name === name);
244
+ // Reset collection-specific records state
245
+ state.recordsPage = 1;
246
+ state.recordsFilter = '';
247
+ state.recordsSearchTerm = '';
248
+ state.recordsSearchField = '_all';
249
+ state.recordsSort = '';
250
+ state.selectedRecordId = null;
251
+ if (typeof closeRecordDrawer === 'function') {
252
+ closeRecordDrawer();
253
+ }
254
+
255
+ showPageView('collections');
256
+ clearSidebarNavActive();
257
+ document.getElementById('nav-collections')?.classList.add('active');
258
+
259
+ renderCollectionsList();
260
+
261
+ document.getElementById('collection-tabs').style.display = 'flex';
262
+
263
+ document.getElementById('view-title').textContent = state.activeCollection ? state.activeCollection.name : name;
264
+ document.getElementById('view-title').style.display = 'inline-block';
265
+ const badge = document.getElementById('view-badge');
266
+ if (badge && state.activeCollection) {
267
+ badge.style.display = 'inline-flex';
268
+ badge.textContent = state.activeCollection.type.toUpperCase();
269
+ badge.className = 'badge ' + (state.activeCollection.type === 'auth' ? 'badge-post' : 'badge-get');
270
+ }
271
+
272
+ updateBreadcrumbs();
273
+
274
+ if (state.collectionTab === 'records') {
275
+ renderRecordsView();
276
+ await loadRecords();
277
+ } else {
278
+ renderSchemaView();
279
+ }
280
+
281
+ if (pushState) {
282
+ const sub = (state.collectionTab === 'schema') ? '/schema' : '';
283
+ if (typeof updateUrl === 'function') {
284
+ updateUrl('/_/collections/' + encodeURIComponent(name) + sub);
285
+ }
286
+ }
287
+ }
288
+
289
+ // Collection Tabs
290
+ function switchCollectionTab(tab, pushState = true) {
291
+ state.collectionTab = tab;
292
+ document.getElementById('tab-records').className = tab === 'records' ? 'tab-btn active' : 'tab-btn';
293
+ document.getElementById('tab-schema').className = tab === 'schema' ? 'tab-btn active' : 'tab-btn';
294
+
295
+ updateBreadcrumbs();
296
+
297
+ if (pushState && state.activeCollection) {
298
+ const sub = (tab === 'schema') ? '/schema' : '';
299
+ if (typeof updateUrl === 'function') {
300
+ updateUrl('/_/collections/' + encodeURIComponent(state.activeCollection.name) + sub);
301
+ }
302
+ }
303
+
304
+ if (tab === 'records') {
305
+ renderRecordsView();
306
+ loadRecords();
307
+ } else {
308
+ renderSchemaView();
309
+ }
310
+ }
311
+
312
+ // ==========================================
313
+ // Breadcrumb Top Bar
314
+ // ==========================================
315
+
316
+ function updateBreadcrumbs() {
317
+ const trail = document.getElementById('breadcrumb-trail');
318
+ if (!trail) return;
319
+
320
+ const crumbs = [];
321
+
322
+ // 1. NodeStack Root
323
+ crumbs.push({
324
+ label: 'NodeStack',
325
+ clickable: true,
326
+ action: () => selectNav('home')
327
+ });
328
+
329
+ if (state.activeNav === 'collection' && state.activeCollection) {
330
+ crumbs.push({
331
+ label: 'Collections',
332
+ clickable: true,
333
+ action: () => selectNav('collections')
334
+ });
335
+ crumbs.push({
336
+ label: state.activeCollection.name,
337
+ clickable: state.collectionTab !== 'records',
338
+ action: () => switchCollectionTab('records')
339
+ });
340
+ if (state.collectionTab === 'schema') {
341
+ crumbs.push({
342
+ label: 'Schema & Rules',
343
+ active: true
344
+ });
345
+ } else {
346
+ crumbs.push({
347
+ label: 'Records',
348
+ active: true
349
+ });
350
+ }
351
+ } else if (state.activeNav === 'collections') {
352
+ crumbs.push({ label: 'Collections', active: true });
353
+ } else if (state.activeNav === 'plugins') {
354
+ crumbs.push({ label: 'Plugins', active: true });
355
+ } else if (state.activeNav === 'webhooks') {
356
+ if (typeof webhooksState !== 'undefined' && webhooksState.subTab === 'deliveries') {
357
+ crumbs.push({ label: 'Webhooks', clickable: true, action: () => { if (typeof switchWebhooksTab === 'function') switchWebhooksTab('webhooks'); } });
358
+ crumbs.push({ label: 'Delivery Logs', active: true });
359
+ } else {
360
+ crumbs.push({ label: 'Webhooks', active: true });
361
+ }
362
+ } else if (state.activeNav === 'functions') {
363
+ if (typeof functionsState !== 'undefined' && functionsState.currentView === 'editor' && functionsState.activeFunctionForEdit) {
364
+ crumbs.push({ label: 'Functions', clickable: true, action: () => { if (typeof closeFunctionEditor === 'function') closeFunctionEditor(); } });
365
+ const editLabel = functionsState.activeFunctionForEdit.isNew
366
+ ? (functionsState.activeFunctionForEdit.name || 'New Function')
367
+ : functionsState.activeFunctionForEdit.name;
368
+ crumbs.push({ label: editLabel, active: true });
369
+ } else if (typeof functionsState !== 'undefined' && functionsState.subTab === 'logs') {
370
+ crumbs.push({ label: 'Functions', clickable: true, action: () => { if (typeof switchFunctionsTab === 'function') switchFunctionsTab('functions'); } });
371
+ crumbs.push({ label: 'Execution Logs', active: true });
372
+ } else {
373
+ crumbs.push({ label: 'Functions', active: true });
374
+ }
375
+ } else if (state.activeNav === 'flows') {
376
+ if (typeof flowsState !== 'undefined' && flowsState.currentView === 'designer' && ((typeof designerState !== 'undefined' && designerState.activeFlow) || flowsState.activeFlowForEdit)) {
377
+ crumbs.push({ label: 'Flows', clickable: true, action: () => { if (typeof closeFlowDesigner === 'function') closeFlowDesigner(); } });
378
+ const currentFlow = (typeof designerState !== 'undefined' && designerState.activeFlow) || flowsState.activeFlowForEdit;
379
+ crumbs.push({ label: currentFlow.name || currentFlow.id || 'Flow Designer', active: true });
380
+ } else if (typeof flowsState !== 'undefined' && flowsState.subTab === 'executions') {
381
+ crumbs.push({ label: 'Flows', clickable: true, action: () => { if (typeof switchFlowsTab === 'function') switchFlowsTab('flows'); } });
382
+ crumbs.push({ label: 'Execution History', active: true });
383
+ } else {
384
+ crumbs.push({ label: 'Flows', active: true });
385
+ }
386
+ } else if (state.activeNav === 'queues') {
387
+ if (typeof queuesState !== 'undefined' && (queuesState.subTab === 'messages' || queuesState.subTab === 'jobs')) {
388
+ crumbs.push({ label: 'Queues', clickable: true, action: () => { if (typeof switchQueuesTab === 'function') switchQueuesTab('queues'); } });
389
+ crumbs.push({ label: 'Message Inspector', active: true });
390
+ } else {
391
+ crumbs.push({ label: 'Queues', active: true });
392
+ }
393
+ } else if (state.activeNav === 'api-keys') {
394
+ crumbs.push({ label: 'API Keys', active: true });
395
+ } else if (state.activeNav === 'home') {
396
+ crumbs.push({ label: 'Overview', active: true });
397
+ } else if (state.activeNav === 'analytics') {
398
+ crumbs.push({ label: 'Analytics', active: true });
399
+ } else if (state.activeNav === 'snapshots') {
400
+ crumbs.push({ label: 'Snapshots', active: true });
401
+ } else if (state.activeNav === 'database') {
402
+ crumbs.push({ label: 'Database Engine', active: true });
403
+ } else if (state.activeNav === 'logs') {
404
+ crumbs.push({ label: 'Audit Logs', active: true });
405
+
406
+ } else if (state.pluginNavItems && state.pluginNavItems.some(p => p.id === state.activeNav)) {
407
+ const item = state.pluginNavItems.find(p => p.id === state.activeNav);
408
+ crumbs.push({ label: 'Plugins', clickable: true, action: () => selectNav('plugins') });
409
+ crumbs.push({ label: item.title, active: true });
410
+ }
411
+
412
+ trail.innerHTML = crumbs.map((crumb, idx) => {
413
+ const isLast = idx === crumbs.length - 1;
414
+ let content = '';
415
+ if (isLast || crumb.active) {
416
+ content = `<span class="breadcrumb-item active" aria-current="page">${escapeHtml(crumb.label)}</span>`;
417
+ } else if (crumb.clickable) {
418
+ content = `<a href="javascript:void(0)" class="breadcrumb-item breadcrumb-link" onclick="handleBreadcrumbClick(${idx})">${escapeHtml(crumb.label)}</a>`;
419
+ } else {
420
+ content = `<span class="breadcrumb-item">${escapeHtml(crumb.label)}</span>`;
421
+ }
422
+
423
+ if (idx < crumbs.length - 1) {
424
+ return `<li class="breadcrumb-crumb">${content}<span class="breadcrumb-separator" aria-hidden="true">/</span></li>`;
425
+ }
426
+ return `<li class="breadcrumb-crumb">${content}</li>`;
427
+ }).join('');
428
+
429
+ window._currentBreadcrumbs = crumbs;
430
+ }
431
+
432
+ function handleBreadcrumbClick(idx) {
433
+ if (window._currentBreadcrumbs && window._currentBreadcrumbs[idx]?.action) {
434
+ window._currentBreadcrumbs[idx].action();
435
+ }
436
+ }
437
+
438
+ // ==========================================
439
+ // Collections Create Dropdown Menu (+ New ▾)
440
+ // ==========================================
441
+
442
+ function toggleCollectionCreateMenu(e) {
443
+ if (e) {
444
+ e.stopPropagation();
445
+ e.preventDefault();
446
+ }
447
+ const menu = document.getElementById('collection-create-menu');
448
+ if (!menu) return;
449
+ const isHidden = menu.style.display === 'none' || !menu.style.display;
450
+ menu.style.display = isHidden ? 'flex' : 'none';
451
+ }
452
+
453
+ function closeCollectionCreateMenu() {
454
+ const menu = document.getElementById('collection-create-menu');
455
+ if (menu) menu.style.display = 'none';
456
+ }
457
+
458
+ function handleCollectionMenuAction(action) {
459
+ closeCollectionCreateMenu();
460
+ if (action === 'new') {
461
+ openNewCollectionModal();
462
+ } else if (action === 'templates') {
463
+ openTemplatesModal();
464
+ } else if (action === 'import') {
465
+ openImportJsonModal();
466
+ }
467
+ }
468
+
469
+ // Expose on window for browser event handlers & test harnesses
470
+ if (typeof window !== 'undefined') {
471
+ window.renderCollectionsHubView = renderCollectionsHubView;
472
+ window.loadCollections = loadCollections;
473
+ window.isSystemCollection = isSystemCollection;
474
+ window.toggleCollectionSection = toggleCollectionSection;
475
+ window.handleCollectionFilterInput = handleCollectionFilterInput;
476
+ window.clearCollectionFilter = clearCollectionFilter;
477
+ window.renderCollectionItemHtml = renderCollectionItemHtml;
478
+ window.renderCollectionsList = renderCollectionsList;
479
+ window.selectCollection = selectCollection;
480
+ window.switchCollectionTab = switchCollectionTab;
481
+ window.updateBreadcrumbs = updateBreadcrumbs;
482
+ window.handleBreadcrumbClick = handleBreadcrumbClick;
483
+ window.toggleCollectionCreateMenu = toggleCollectionCreateMenu;
484
+ window.closeCollectionCreateMenu = closeCollectionCreateMenu;
485
+ window.handleCollectionMenuAction = handleCollectionMenuAction;
486
+ }