mongodash 2.0.0 → 2.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.
Files changed (163) hide show
  1. package/README.md +40 -22
  2. package/dist/dashboard/index.html +40 -0
  3. package/dist/lib/playground/server.js +131 -0
  4. package/dist/lib/playground/server.js.map +1 -0
  5. package/dist/lib/src/ConcurrentRunner.js +148 -0
  6. package/dist/lib/src/ConcurrentRunner.js.map +1 -0
  7. package/dist/lib/{OnError.js → src/OnError.js} +3 -3
  8. package/dist/lib/src/OnError.js.map +1 -0
  9. package/dist/lib/{OnInfo.js → src/OnInfo.js} +6 -3
  10. package/dist/lib/src/OnInfo.js.map +1 -0
  11. package/dist/lib/{createContinuousLock.js → src/createContinuousLock.js} +5 -3
  12. package/dist/lib/src/createContinuousLock.js.map +1 -0
  13. package/dist/lib/{cronTasks.js → src/cronTasks.js} +129 -73
  14. package/dist/lib/src/cronTasks.js.map +1 -0
  15. package/dist/lib/{getCollection.js → src/getCollection.js} +2 -2
  16. package/dist/lib/src/getCollection.js.map +1 -0
  17. package/dist/lib/{getMongoClient.js → src/getMongoClient.js} +2 -2
  18. package/dist/lib/src/getMongoClient.js.map +1 -0
  19. package/dist/lib/src/globalsCollection.js +10 -0
  20. package/dist/lib/src/globalsCollection.js.map +1 -0
  21. package/dist/lib/src/index.js +101 -0
  22. package/dist/lib/src/index.js.map +1 -0
  23. package/dist/lib/{initPromise.js → src/initPromise.js} +2 -3
  24. package/dist/lib/src/initPromise.js.map +1 -0
  25. package/dist/lib/src/mongoCompatibility.js +10 -0
  26. package/dist/lib/src/mongoCompatibility.js.map +1 -0
  27. package/dist/lib/src/parseInterval.js +60 -0
  28. package/dist/lib/src/parseInterval.js.map +1 -0
  29. package/dist/lib/src/prefixFilterKeys.js +69 -0
  30. package/dist/lib/src/prefixFilterKeys.js.map +1 -0
  31. package/dist/lib/src/processInBatches.js +46 -0
  32. package/dist/lib/src/processInBatches.js.map +1 -0
  33. package/dist/lib/src/reactiveTasks/LeaderElector.js +155 -0
  34. package/dist/lib/src/reactiveTasks/LeaderElector.js.map +1 -0
  35. package/dist/lib/src/reactiveTasks/MetricsCollector.js +410 -0
  36. package/dist/lib/src/reactiveTasks/MetricsCollector.js.map +1 -0
  37. package/dist/lib/src/reactiveTasks/ReactiveTaskManager.js +288 -0
  38. package/dist/lib/src/reactiveTasks/ReactiveTaskManager.js.map +1 -0
  39. package/dist/lib/src/reactiveTasks/ReactiveTaskOps.js +185 -0
  40. package/dist/lib/src/reactiveTasks/ReactiveTaskOps.js.map +1 -0
  41. package/dist/lib/src/reactiveTasks/ReactiveTaskPlanner.js +443 -0
  42. package/dist/lib/src/reactiveTasks/ReactiveTaskPlanner.js.map +1 -0
  43. package/dist/lib/src/reactiveTasks/ReactiveTaskReconciler.js +218 -0
  44. package/dist/lib/src/reactiveTasks/ReactiveTaskReconciler.js.map +1 -0
  45. package/dist/lib/src/reactiveTasks/ReactiveTaskRegistry.js +184 -0
  46. package/dist/lib/src/reactiveTasks/ReactiveTaskRegistry.js.map +1 -0
  47. package/dist/lib/src/reactiveTasks/ReactiveTaskRepository.js +355 -0
  48. package/dist/lib/src/reactiveTasks/ReactiveTaskRepository.js.map +1 -0
  49. package/dist/lib/src/reactiveTasks/ReactiveTaskRetryStrategy.js +153 -0
  50. package/dist/lib/src/reactiveTasks/ReactiveTaskRetryStrategy.js.map +1 -0
  51. package/dist/lib/src/reactiveTasks/ReactiveTaskTypes.js +34 -0
  52. package/dist/lib/src/reactiveTasks/ReactiveTaskTypes.js.map +1 -0
  53. package/dist/lib/src/reactiveTasks/ReactiveTaskWorker.js +186 -0
  54. package/dist/lib/src/reactiveTasks/ReactiveTaskWorker.js.map +1 -0
  55. package/dist/lib/src/reactiveTasks/compileWatchProjection.js +65 -0
  56. package/dist/lib/src/reactiveTasks/compileWatchProjection.js.map +1 -0
  57. package/dist/lib/src/reactiveTasks/index.js +298 -0
  58. package/dist/lib/src/reactiveTasks/index.js.map +1 -0
  59. package/dist/lib/src/reactiveTasks/queryToExpression.js +160 -0
  60. package/dist/lib/src/reactiveTasks/queryToExpression.js.map +1 -0
  61. package/dist/lib/src/reactiveTasks/validateTaskFilter.js +88 -0
  62. package/dist/lib/src/reactiveTasks/validateTaskFilter.js.map +1 -0
  63. package/dist/lib/src/task-management/OperationalTaskController.js +162 -0
  64. package/dist/lib/src/task-management/OperationalTaskController.js.map +1 -0
  65. package/dist/lib/src/task-management/index.js +27 -0
  66. package/dist/lib/src/task-management/index.js.map +1 -0
  67. package/dist/lib/src/task-management/serveDashboard.js +149 -0
  68. package/dist/lib/src/task-management/serveDashboard.js.map +1 -0
  69. package/dist/lib/src/task-management/types.js +10 -0
  70. package/dist/lib/src/task-management/types.js.map +1 -0
  71. package/dist/lib/{withLock.js → src/withLock.js} +3 -4
  72. package/dist/lib/src/withLock.js.map +1 -0
  73. package/dist/lib/{withTransaction.js → src/withTransaction.js} +4 -4
  74. package/dist/lib/src/withTransaction.js.map +1 -0
  75. package/dist/lib/tools/check-db-connection.js +28 -0
  76. package/dist/lib/tools/check-db-connection.js.map +1 -0
  77. package/dist/lib/tools/clean-testing-databases.js +12 -0
  78. package/dist/lib/tools/clean-testing-databases.js.map +1 -0
  79. package/dist/lib/tools/prepare-republish.js +27 -0
  80. package/dist/lib/tools/prepare-republish.js.map +1 -0
  81. package/dist/lib/tools/test-matrix-local.js +212 -0
  82. package/dist/lib/tools/test-matrix-local.js.map +1 -0
  83. package/dist/lib/tools/testingDatabase.js +55 -0
  84. package/dist/lib/tools/testingDatabase.js.map +1 -0
  85. package/dist/types/playground/server.d.ts +1 -0
  86. package/dist/types/src/ConcurrentRunner.d.ts +30 -0
  87. package/dist/types/{OnInfo.d.ts → src/OnInfo.d.ts} +1 -1
  88. package/dist/types/{cronTasks.d.ts → src/cronTasks.d.ts} +44 -1
  89. package/dist/types/src/globalsCollection.d.ts +4 -0
  90. package/dist/types/src/index.d.ts +28 -0
  91. package/dist/types/src/mongoCompatibility.d.ts +29 -0
  92. package/dist/types/src/parseInterval.d.ts +12 -0
  93. package/dist/types/src/prefixFilterKeys.d.ts +11 -0
  94. package/dist/types/src/processInBatches.d.ts +10 -0
  95. package/dist/types/src/reactiveTasks/LeaderElector.d.ts +42 -0
  96. package/dist/types/src/reactiveTasks/MetricsCollector.d.ts +73 -0
  97. package/dist/types/src/reactiveTasks/ReactiveTaskManager.d.ts +18 -0
  98. package/dist/types/src/reactiveTasks/ReactiveTaskOps.d.ts +17 -0
  99. package/dist/types/src/reactiveTasks/ReactiveTaskPlanner.d.ts +62 -0
  100. package/dist/types/src/reactiveTasks/ReactiveTaskReconciler.d.ts +29 -0
  101. package/dist/types/src/reactiveTasks/ReactiveTaskRegistry.d.ts +34 -0
  102. package/dist/types/src/reactiveTasks/ReactiveTaskRepository.d.ts +59 -0
  103. package/dist/types/src/reactiveTasks/ReactiveTaskRetryStrategy.d.ts +21 -0
  104. package/dist/types/src/reactiveTasks/ReactiveTaskTypes.d.ts +389 -0
  105. package/dist/types/src/reactiveTasks/ReactiveTaskWorker.d.ts +36 -0
  106. package/dist/types/src/reactiveTasks/compileWatchProjection.d.ts +12 -0
  107. package/dist/types/src/reactiveTasks/index.d.ts +82 -0
  108. package/dist/types/src/reactiveTasks/queryToExpression.d.ts +13 -0
  109. package/dist/types/src/reactiveTasks/validateTaskFilter.d.ts +10 -0
  110. package/dist/types/src/task-management/OperationalTaskController.d.ts +59 -0
  111. package/dist/types/src/task-management/index.d.ts +3 -0
  112. package/dist/types/src/task-management/serveDashboard.d.ts +12 -0
  113. package/dist/types/src/task-management/types.d.ts +95 -0
  114. package/dist/types/tools/check-db-connection.d.ts +2 -0
  115. package/dist/types/tools/clean-testing-databases.d.ts +1 -0
  116. package/dist/types/tools/prepare-republish.d.ts +2 -0
  117. package/dist/types/tools/test-matrix-local.d.ts +1 -0
  118. package/dist/types/tools/testingDatabase.d.ts +2 -0
  119. package/docs/.vitepress/cache/deps/_metadata.json +31 -0
  120. package/docs/.vitepress/cache/deps/chunk-LE5NDSFD.js +12824 -0
  121. package/docs/.vitepress/cache/deps/chunk-LE5NDSFD.js.map +7 -0
  122. package/docs/.vitepress/cache/deps/package.json +3 -0
  123. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4505 -0
  124. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
  125. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +9731 -0
  126. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
  127. package/docs/.vitepress/cache/deps/vue.js +347 -0
  128. package/docs/.vitepress/cache/deps/vue.js.map +7 -0
  129. package/docs/.vitepress/config.mts +48 -0
  130. package/docs/.vitepress/theme/index.ts +4 -0
  131. package/docs/.vitepress/theme/style.css +16 -0
  132. package/docs/assets/dashboard.png +0 -0
  133. package/docs/cron-tasks.md +172 -0
  134. package/docs/dashboard.md +117 -0
  135. package/docs/getters.md +31 -0
  136. package/docs/getting-started.md +120 -0
  137. package/docs/index.md +29 -0
  138. package/docs/initialization.md +59 -0
  139. package/docs/process-in-batches.md +73 -0
  140. package/docs/reactive-tasks.md +914 -0
  141. package/docs/with-lock.md +45 -0
  142. package/docs/with-transaction.md +65 -0
  143. package/grafana/reactive_tasks.json +765 -0
  144. package/package.json +127 -116
  145. package/dist/lib/OnError.js.map +0 -1
  146. package/dist/lib/OnInfo.js.map +0 -1
  147. package/dist/lib/createContinuousLock.js.map +0 -1
  148. package/dist/lib/cronTasks.js.map +0 -1
  149. package/dist/lib/getCollection.js.map +0 -1
  150. package/dist/lib/getMongoClient.js.map +0 -1
  151. package/dist/lib/index.js +0 -64
  152. package/dist/lib/index.js.map +0 -1
  153. package/dist/lib/initPromise.js.map +0 -1
  154. package/dist/lib/withLock.js.map +0 -1
  155. package/dist/lib/withTransaction.js.map +0 -1
  156. package/dist/types/index.d.ts +0 -17
  157. /package/dist/types/{OnError.d.ts → src/OnError.d.ts} +0 -0
  158. /package/dist/types/{createContinuousLock.d.ts → src/createContinuousLock.d.ts} +0 -0
  159. /package/dist/types/{getCollection.d.ts → src/getCollection.d.ts} +0 -0
  160. /package/dist/types/{getMongoClient.d.ts → src/getMongoClient.d.ts} +0 -0
  161. /package/dist/types/{initPromise.d.ts → src/initPromise.d.ts} +0 -0
  162. /package/dist/types/{withLock.d.ts → src/withLock.d.ts} +0 -0
  163. /package/dist/types/{withTransaction.d.ts → src/withTransaction.d.ts} +0 -0
@@ -0,0 +1,347 @@
1
+ import {
2
+ BaseTransition,
3
+ BaseTransitionPropsValidators,
4
+ Comment,
5
+ DeprecationTypes,
6
+ EffectScope,
7
+ ErrorCodes,
8
+ ErrorTypeStrings,
9
+ Fragment,
10
+ KeepAlive,
11
+ ReactiveEffect,
12
+ Static,
13
+ Suspense,
14
+ Teleport,
15
+ Text,
16
+ TrackOpTypes,
17
+ Transition,
18
+ TransitionGroup,
19
+ TriggerOpTypes,
20
+ VueElement,
21
+ assertNumber,
22
+ callWithAsyncErrorHandling,
23
+ callWithErrorHandling,
24
+ camelize,
25
+ capitalize,
26
+ cloneVNode,
27
+ compatUtils,
28
+ compile,
29
+ computed,
30
+ createApp,
31
+ createBaseVNode,
32
+ createBlock,
33
+ createCommentVNode,
34
+ createElementBlock,
35
+ createHydrationRenderer,
36
+ createPropsRestProxy,
37
+ createRenderer,
38
+ createSSRApp,
39
+ createSlots,
40
+ createStaticVNode,
41
+ createTextVNode,
42
+ createVNode,
43
+ customRef,
44
+ defineAsyncComponent,
45
+ defineComponent,
46
+ defineCustomElement,
47
+ defineEmits,
48
+ defineExpose,
49
+ defineModel,
50
+ defineOptions,
51
+ defineProps,
52
+ defineSSRCustomElement,
53
+ defineSlots,
54
+ devtools,
55
+ effect,
56
+ effectScope,
57
+ getCurrentInstance,
58
+ getCurrentScope,
59
+ getCurrentWatcher,
60
+ getTransitionRawChildren,
61
+ guardReactiveProps,
62
+ h,
63
+ handleError,
64
+ hasInjectionContext,
65
+ hydrate,
66
+ hydrateOnIdle,
67
+ hydrateOnInteraction,
68
+ hydrateOnMediaQuery,
69
+ hydrateOnVisible,
70
+ initCustomFormatter,
71
+ initDirectivesForSSR,
72
+ inject,
73
+ isMemoSame,
74
+ isProxy,
75
+ isReactive,
76
+ isReadonly,
77
+ isRef,
78
+ isRuntimeOnly,
79
+ isShallow,
80
+ isVNode,
81
+ markRaw,
82
+ mergeDefaults,
83
+ mergeModels,
84
+ mergeProps,
85
+ nextTick,
86
+ nodeOps,
87
+ normalizeClass,
88
+ normalizeProps,
89
+ normalizeStyle,
90
+ onActivated,
91
+ onBeforeMount,
92
+ onBeforeUnmount,
93
+ onBeforeUpdate,
94
+ onDeactivated,
95
+ onErrorCaptured,
96
+ onMounted,
97
+ onRenderTracked,
98
+ onRenderTriggered,
99
+ onScopeDispose,
100
+ onServerPrefetch,
101
+ onUnmounted,
102
+ onUpdated,
103
+ onWatcherCleanup,
104
+ openBlock,
105
+ patchProp,
106
+ popScopeId,
107
+ provide,
108
+ proxyRefs,
109
+ pushScopeId,
110
+ queuePostFlushCb,
111
+ reactive,
112
+ readonly,
113
+ ref,
114
+ registerRuntimeCompiler,
115
+ render,
116
+ renderList,
117
+ renderSlot,
118
+ resolveComponent,
119
+ resolveDirective,
120
+ resolveDynamicComponent,
121
+ resolveFilter,
122
+ resolveTransitionHooks,
123
+ setBlockTracking,
124
+ setDevtoolsHook,
125
+ setTransitionHooks,
126
+ shallowReactive,
127
+ shallowReadonly,
128
+ shallowRef,
129
+ ssrContextKey,
130
+ ssrUtils,
131
+ stop,
132
+ toDisplayString,
133
+ toHandlerKey,
134
+ toHandlers,
135
+ toRaw,
136
+ toRef,
137
+ toRefs,
138
+ toValue,
139
+ transformVNodeArgs,
140
+ triggerRef,
141
+ unref,
142
+ useAttrs,
143
+ useCssModule,
144
+ useCssVars,
145
+ useHost,
146
+ useId,
147
+ useModel,
148
+ useSSRContext,
149
+ useShadowRoot,
150
+ useSlots,
151
+ useTemplateRef,
152
+ useTransitionState,
153
+ vModelCheckbox,
154
+ vModelDynamic,
155
+ vModelRadio,
156
+ vModelSelect,
157
+ vModelText,
158
+ vShow,
159
+ version,
160
+ warn,
161
+ watch,
162
+ watchEffect,
163
+ watchPostEffect,
164
+ watchSyncEffect,
165
+ withAsyncContext,
166
+ withCtx,
167
+ withDefaults,
168
+ withDirectives,
169
+ withKeys,
170
+ withMemo,
171
+ withModifiers,
172
+ withScopeId
173
+ } from "./chunk-LE5NDSFD.js";
174
+ export {
175
+ BaseTransition,
176
+ BaseTransitionPropsValidators,
177
+ Comment,
178
+ DeprecationTypes,
179
+ EffectScope,
180
+ ErrorCodes,
181
+ ErrorTypeStrings,
182
+ Fragment,
183
+ KeepAlive,
184
+ ReactiveEffect,
185
+ Static,
186
+ Suspense,
187
+ Teleport,
188
+ Text,
189
+ TrackOpTypes,
190
+ Transition,
191
+ TransitionGroup,
192
+ TriggerOpTypes,
193
+ VueElement,
194
+ assertNumber,
195
+ callWithAsyncErrorHandling,
196
+ callWithErrorHandling,
197
+ camelize,
198
+ capitalize,
199
+ cloneVNode,
200
+ compatUtils,
201
+ compile,
202
+ computed,
203
+ createApp,
204
+ createBlock,
205
+ createCommentVNode,
206
+ createElementBlock,
207
+ createBaseVNode as createElementVNode,
208
+ createHydrationRenderer,
209
+ createPropsRestProxy,
210
+ createRenderer,
211
+ createSSRApp,
212
+ createSlots,
213
+ createStaticVNode,
214
+ createTextVNode,
215
+ createVNode,
216
+ customRef,
217
+ defineAsyncComponent,
218
+ defineComponent,
219
+ defineCustomElement,
220
+ defineEmits,
221
+ defineExpose,
222
+ defineModel,
223
+ defineOptions,
224
+ defineProps,
225
+ defineSSRCustomElement,
226
+ defineSlots,
227
+ devtools,
228
+ effect,
229
+ effectScope,
230
+ getCurrentInstance,
231
+ getCurrentScope,
232
+ getCurrentWatcher,
233
+ getTransitionRawChildren,
234
+ guardReactiveProps,
235
+ h,
236
+ handleError,
237
+ hasInjectionContext,
238
+ hydrate,
239
+ hydrateOnIdle,
240
+ hydrateOnInteraction,
241
+ hydrateOnMediaQuery,
242
+ hydrateOnVisible,
243
+ initCustomFormatter,
244
+ initDirectivesForSSR,
245
+ inject,
246
+ isMemoSame,
247
+ isProxy,
248
+ isReactive,
249
+ isReadonly,
250
+ isRef,
251
+ isRuntimeOnly,
252
+ isShallow,
253
+ isVNode,
254
+ markRaw,
255
+ mergeDefaults,
256
+ mergeModels,
257
+ mergeProps,
258
+ nextTick,
259
+ nodeOps,
260
+ normalizeClass,
261
+ normalizeProps,
262
+ normalizeStyle,
263
+ onActivated,
264
+ onBeforeMount,
265
+ onBeforeUnmount,
266
+ onBeforeUpdate,
267
+ onDeactivated,
268
+ onErrorCaptured,
269
+ onMounted,
270
+ onRenderTracked,
271
+ onRenderTriggered,
272
+ onScopeDispose,
273
+ onServerPrefetch,
274
+ onUnmounted,
275
+ onUpdated,
276
+ onWatcherCleanup,
277
+ openBlock,
278
+ patchProp,
279
+ popScopeId,
280
+ provide,
281
+ proxyRefs,
282
+ pushScopeId,
283
+ queuePostFlushCb,
284
+ reactive,
285
+ readonly,
286
+ ref,
287
+ registerRuntimeCompiler,
288
+ render,
289
+ renderList,
290
+ renderSlot,
291
+ resolveComponent,
292
+ resolveDirective,
293
+ resolveDynamicComponent,
294
+ resolveFilter,
295
+ resolveTransitionHooks,
296
+ setBlockTracking,
297
+ setDevtoolsHook,
298
+ setTransitionHooks,
299
+ shallowReactive,
300
+ shallowReadonly,
301
+ shallowRef,
302
+ ssrContextKey,
303
+ ssrUtils,
304
+ stop,
305
+ toDisplayString,
306
+ toHandlerKey,
307
+ toHandlers,
308
+ toRaw,
309
+ toRef,
310
+ toRefs,
311
+ toValue,
312
+ transformVNodeArgs,
313
+ triggerRef,
314
+ unref,
315
+ useAttrs,
316
+ useCssModule,
317
+ useCssVars,
318
+ useHost,
319
+ useId,
320
+ useModel,
321
+ useSSRContext,
322
+ useShadowRoot,
323
+ useSlots,
324
+ useTemplateRef,
325
+ useTransitionState,
326
+ vModelCheckbox,
327
+ vModelDynamic,
328
+ vModelRadio,
329
+ vModelSelect,
330
+ vModelText,
331
+ vShow,
332
+ version,
333
+ warn,
334
+ watch,
335
+ watchEffect,
336
+ watchPostEffect,
337
+ watchSyncEffect,
338
+ withAsyncContext,
339
+ withCtx,
340
+ withDefaults,
341
+ withDirectives,
342
+ withKeys,
343
+ withMemo,
344
+ withModifiers,
345
+ withScopeId
346
+ };
347
+ //# sourceMappingURL=vue.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,48 @@
1
+ import { defineConfig } from 'vitepress'
2
+
3
+ export default defineConfig({
4
+ base: '/mongodash/',
5
+ title: "Mongodash",
6
+ description: "A modern JavaScript & Typescript MongoDB-based utility library",
7
+ cleanUrls: true,
8
+ themeConfig: {
9
+ nav: [
10
+ { text: 'Home', link: '/' },
11
+ { text: 'Getting Started', link: '/getting-started' },
12
+ { text: 'GitHub', link: 'https://github.com/VaclavObornik/mongodash' }
13
+ ],
14
+
15
+ sidebar: [
16
+ {
17
+ text: 'Introduction',
18
+ items: [
19
+ { text: 'Getting Started', link: '/getting-started' },
20
+ { text: 'Initialization', link: '/initialization' }
21
+ ]
22
+ },
23
+ {
24
+ text: 'Core Features',
25
+ items: [
26
+ { text: 'Reactive Tasks', link: '/reactive-tasks' },
27
+ { text: 'Cron Tasks', link: '/cron-tasks' },
28
+ { text: 'Dashboard', link: '/dashboard' },
29
+ { text: 'Concurrency Control', link: '/with-lock' },
30
+ { text: 'Transactions', link: '/with-transaction' },
31
+ ]
32
+ },
33
+ {
34
+ text: 'Utilities',
35
+ items: [
36
+ { text: 'Process In Batches', link: '/process-in-batches' },
37
+ { text: 'Getters', link: '/getters' }
38
+ ]
39
+ }
40
+ ],
41
+
42
+ socialLinks: [
43
+ { icon: 'github', link: 'https://github.com/VaclavObornik/mongodash' }
44
+ ],
45
+
46
+ outline: [2, 3]
47
+ }
48
+ })
@@ -0,0 +1,4 @@
1
+ import DefaultTheme from 'vitepress/theme'
2
+ import './style.css'
3
+
4
+ export default DefaultTheme
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Custom Theme Colors - Vibrant Violet/Purple
3
+ */
4
+ :root {
5
+ --vp-c-brand-1: #8e44ad;
6
+ --vp-c-brand-2: #9b59b6;
7
+ --vp-c-brand-3: #a569bd;
8
+ --vp-c-brand-soft: rgba(142, 68, 173, 0.16);
9
+
10
+ --vp-home-hero-name-color: transparent;
11
+ --vp-home-hero-name-background: -webkit-linear-gradient(120deg, #bd34fe 30%, #41d1ff);
12
+ }
13
+
14
+ .VPImage.image-src {
15
+ filter: drop-shadow(0 0 2em #bd34feaa);
16
+ }
Binary file
@@ -0,0 +1,172 @@
1
+ # Cron tasks
2
+
3
+ ## Usable even in scalable (multi-instance) applications
4
+
5
+ Usable even in scalable (multi-instance) applications thanks to task registration in MongoDB.
6
+ Mongodash will ensure each task is processed by only one instance at a time.
7
+
8
+ You can see a short history of recent task runs here or even [manually trigger a task](#manual-task-run) if you need to!
9
+
10
+ Also, check out the **[Dashboard](./dashboard.md)** for a visual interface to manage your tasks.
11
+ ```
12
+ cronTasks
13
+ ```
14
+
15
+ ## cronTask(taskId, interval, taskFunction) => Promise
16
+
17
+ ```typescript
18
+ cronTask(taskId, interval, taskFunction) => Promise
19
+ ```
20
+
21
+ Register a cron task.
22
+
23
+ ```typescript
24
+ import { cronTask } from 'mongodash';
25
+
26
+ cronTask('my-task-id', '5m 20s', async () => {
27
+ console.log('Hurray the task is running!');
28
+ });
29
+ ```
30
+
31
+ That's it! Now the task will run every 5 minutes and 20 seconds!
32
+
33
+ ## First task registration also starts the internal loop
34
+
35
+ First task registration also starts the internal loop watching for a task to run.
36
+ This can be prevented by calling [`stopCronTasks()`](#stopcrontasks--void) or passing `runCronTasks: false` option to [mongodash init](#initialization-options-optional).
37
+
38
+ ## Valid values for interval argument
39
+
40
+ The interval can be specified in several formats:
41
+
42
+ * **Duration string**: supported by [parse-duration](https://www.npmjs.com/package/parse-duration)
43
+ ```typescript
44
+ "5m 20s"
45
+ ```
46
+ * **Number**: milliseconds
47
+ ```typescript
48
+ 5 * 60 * 1000
49
+ ```
50
+ * **CRON expression**: supported by [cron-parser](https://www.npmjs.com/package/cron-parser). **Must start with the `CRON ` prefix**.
51
+ ```typescript
52
+ "CRON */5 * * * *"
53
+ ```
54
+
55
+ It also supports functions returning dynamic next run times:
56
+
57
+ ```typescript
58
+ () => new Date() // next run at specific date
59
+ ```
60
+
61
+ ```typescript
62
+ () => "5m 20s" // dynamic interval
63
+ ```
64
+
65
+ ```typescript
66
+ () => "CRON */5 * * * *"
67
+ ```
68
+
69
+ ```typescript
70
+ () => 5 * 60 * 1000
71
+ ```
72
+
73
+ ## scheduleCronTaskImmediately(taskId) => Promise
74
+
75
+ ```typescript
76
+ scheduleCronTaskImmediately(taskId) => Promise
77
+ ```
78
+
79
+ Schedule the task to run as soon as possible. Handy for cases when you need to hurry up a task based on another task or an API call.
80
+
81
+ ```typescript
82
+ import { scheduleCronTaskImmediately } from 'mongodash';
83
+ scheduleCronTaskImmediately('my-task-id');
84
+ ```
85
+
86
+ ## runCronTask(taskId) => Promise
87
+
88
+ ```typescript
89
+ runCronTask(taskId) => Promise
90
+ ```
91
+
92
+ Run a task and return a promise. The promise is resolved as soon as the task is done. The main purpose of the function is to easily test the tasks in automated tests.
93
+
94
+ ```typescript
95
+ import { runCronTask } from 'mongodash';
96
+ runCronTask('my-task-id');
97
+ ```
98
+
99
+ ## Do not use the runCronTask method inside a cron task
100
+
101
+ **Do not use the runCronTask method inside a cron task.**
102
+ It will not work. Use non-blocking [`scheduleCronTaskImmediately`](#schedulecrontaskimmediatelytaskid--promise) instead.
103
+
104
+ ## stopCronTasks() => void
105
+
106
+ ```typescript
107
+ stopCronTasks() => void
108
+ ```
109
+
110
+ Stop triggering registered tasks. Useful for automated tests, where is usually not desired to run tasks in the background. Calling stopCronTasks function before the first cronTask registration will prevent running any task.
111
+
112
+ ```typescript
113
+ import { stopCronTasks } from 'mongodash';
114
+ stopCronTasks();
115
+ ```
116
+
117
+ ## startCronTasks() => void
118
+
119
+ ```typescript
120
+ startCronTasks() => void
121
+ ```
122
+
123
+ Start triggering registered tasks. Usually not needed to call, since the registered tasks run automatically after the registration unless stopCronTasks is called or the mongodash is initialized with `runCronTasks: false`.
124
+
125
+ ```typescript
126
+ import { startCronTasks } from 'mongodash';
127
+ startCronTasks();
128
+ ```
129
+
130
+ ## Initialization options (optional)
131
+
132
+ ```typescript
133
+ import mongodash from 'mongodash';
134
+
135
+ mongodash.init({
136
+ // database connection
137
+ uri: 'mongodb://mongodb0.example.com:27017',
138
+
139
+ // true by default
140
+ runCronTasks: false,
141
+
142
+ // valid only if CRON expressions used
143
+ // see https://www.npmjs.com/package/cron-parser for valid options
144
+ cronExpressionParserOptions: {
145
+ tz: 'Europe/Athens',
146
+ },
147
+ });
148
+ ```
149
+
150
+ ## Manual task run
151
+
152
+ Need to manually trigger a task outside the application? Mongodash Cron tasks allow you to speed up task processing by setting `runImmediately` flag to true. Just find and update the task document in `cronTasks` collection. This is helpful in a deployment environment to speed up a process.
153
+
154
+ ```typescript
155
+ // In cronTasks collection
156
+ {
157
+ _id: "my-task-id",
158
+ runImmediately: true
159
+ }
160
+ ```
161
+
162
+ ## Performance & Scalability
163
+
164
+ ### Distributed Locking
165
+ The system handles concurrency by locking tasks in MongoDB.
166
+ - **Default Lock Duration**: 5 minutes.
167
+ - **Auto-Renewal**: For long-running tasks, the lock is automatically refreshed every 15 seconds to prevent other instances from picking up the task while it's still running.
168
+
169
+ ### Execution History
170
+ The system maintains a brief execution history in the database:
171
+ - **Limit**: Only the **last 5 runs** are stored in the `runLog` of the task document.
172
+ - Use this to monitor recent successes or failures.
@@ -0,0 +1,117 @@
1
+ # Mongodash Dashboard
2
+
3
+ The Mongodash Dashboard is a built-in administration interface for monitoring and managing your Reactive and Cron tasks. It is framework-agnostic and can be easily integrated into your existing Node.js application (Express, Koa, Fastify, or plain `http`).
4
+
5
+ ## Purpose
6
+
7
+ The dashboard provides a visual overview of your task system's health and operational state. It allows you to:
8
+ - **Monitor** the status of all reactive and cron tasks (pending, processing, completed, failed).
9
+ - **Debug** issues by viewing error messages and stack traces directly in the UI.
10
+ - **Retry** failed reactive tasks manually or in bulk based on filters.
11
+ - **Trigger** cron tasks immediately for testing or ad-hoc execution.
12
+ - **Analyze** performance by viewing execution history and last observed values (internal state is hidden by default).
13
+
14
+ ## Look and Feel
15
+ ![Dashboard Screenshot](./assets/dashboard.png)
16
+
17
+ The dashboard features a clean, responsive UI with two main sections:
18
+
19
+ ### 1. Sidebar Navigation
20
+ - **Task Collections**: Quickly navigate between reactive tasks grouped by their source collection.
21
+ - **Live Stats**: See real-time counts of pending, processing, and failed tasks for each collection.
22
+ - **Error Counts**: An orange badge indicates the total number of errors encountered by tasks in that group.
23
+ - **Cron Tasks**: View next run times for scheduled jobs directly in the sidebar.
24
+
25
+ ### 2. Reactive Tasks View
26
+ Displays a paginated list of all reactive tasks.
27
+ - **Filters**: Filter tasks by Name, Status (e.g., `failed`, `pending`), Error Message, and **Source Document ID**.
28
+ - **URL Sync**: All filters are automatically synchronized with the URL query parameters, making it easy to share specific views (e.g., "Show me all failed email tasks").
29
+ - **Source Doc ID Filter**: A smart search that accepts exact strings, ObjectIDs, or numbers to find tasks related to a specific source document.
30
+ - **Bulk Actions**:
31
+ - **Retry Matching**: A button to retry all tasks that match the current filters.
32
+
33
+ ### 3. Cron Tasks View
34
+ Displays a list of all registered cron tasks.
35
+ - **Status**: Shows the next scheduled run time (relative time) and the last execution status.
36
+ - **Actions**:
37
+ - **Trigger Now**: A button to immediately execute a cron task, regardless of its schedule.
38
+
39
+ ## Integration
40
+
41
+ You can mount the dashboard on any route in your application. The `serveDashboard` function handles both API requests and static asset serving.
42
+
43
+ ### Express
44
+ ```typescript
45
+ import * as express from 'express';
46
+ import { serveDashboard } from 'mongodash';
47
+
48
+ const app = express();
49
+
50
+ app.use('/dashboard', async (req, res, next) => {
51
+ // Check if mongodash handled the request
52
+ const handled = await serveDashboard(req, res);
53
+ if (!handled) {
54
+ next();
55
+ }
56
+ });
57
+
58
+ app.listen(3000);
59
+ ```
60
+
61
+ ### Koa
62
+ ```typescript
63
+ import * as Koa from 'koa';
64
+ import { serveDashboard } from 'mongodash';
65
+
66
+ const app = new Koa();
67
+
68
+ app.use(async (ctx, next) => {
69
+ // Koa's ctx.req and ctx.res are the native Node.js objects
70
+ // serveDashboard is mounted at root or check ctx.path manually if needed
71
+ if (ctx.path.startsWith('/dashboard')) {
72
+ const handled = await serveDashboard(ctx.req, ctx.res);
73
+ if (handled) return;
74
+ }
75
+ await next();
76
+ });
77
+
78
+ app.listen(3000);
79
+ ```
80
+
81
+ ### Native HTTP
82
+ ```typescript
83
+ import * as http from 'http';
84
+ import { serveDashboard } from 'mongodash';
85
+
86
+ const server = http.createServer(async (req, res) => {
87
+ // Mount at /dashboard
88
+ if (req.url?.startsWith('/dashboard')) {
89
+ const handled = await serveDashboard(req, res);
90
+ if (handled) return;
91
+ }
92
+
93
+ res.statusCode = 404;
94
+ res.end('Not Found');
95
+ });
96
+
97
+ server.listen(3000);
98
+ ```
99
+
100
+ ## Manual Triggering & Retries
101
+
102
+ While the system is autonomous, manual intervention might sometimes be handy.
103
+
104
+ - **Reactive Tasks**: If tasks fail (e.g., due to a bug or temporary external outage), you can use the **Retry Matching** feature in the dashboard.
105
+ 1. Filter for the failed tasks (e.g., Status: `failed`, Error: `Timeout`).
106
+ 2. Click "**Retry now**".
107
+ 3. Confirm the action.
108
+ - This will reschedule the tasks to `now` and reset their status to `pending`, allowing workers to pick them up immediately.
109
+ - **History Preserved**: Unlike a full reset, this action **preserves** the task's error history (attempt count, first error timestamp) for auditing purposes. The attempts count will only be reset if the task subsequently succeeds or if the source document changes (depending on `resetRetriesOnDataChange` policy).
110
+
111
+ - **Cron Tasks**: You can force a cron task to run immediately via the **Trigger** button. This is helpful for testing cron logic without waiting for the schedule.
112
+
113
+ ## Architecture Notes
114
+
115
+ ### Read Preference
116
+ - **Sidebar Statistics**: By default, the dashboard fetches statistics (counts, Sidebar badges) using `secondaryPreferred` read preference to minimize load on the Primary node.
117
+ - **Task Lists**: The main task lists (table views) use the default read preference of your MongoDB connection (usually `primary`).