bunsane 0.3.0 → 0.3.2
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.
- package/.claude/scheduled_tasks.lock +1 -0
- package/CHANGELOG.md +104 -0
- package/CLAUDE.md +20 -0
- package/config/cache.config.ts +35 -1
- package/core/App.ts +24 -1060
- package/core/ArcheType.ts +78 -2110
- package/core/Entity.ts +136 -41
- package/core/RequestContext.ts +85 -36
- package/core/RequestLoaders.ts +89 -31
- package/core/SchedulerManager.ts +13 -13
- package/core/app/bootstrap.ts +133 -0
- package/core/app/cors.ts +94 -0
- package/core/app/graphqlSetup.ts +56 -0
- package/core/app/healthEndpoints.ts +31 -0
- package/core/app/metricsCollector.ts +27 -0
- package/core/app/preparedStatementWarmup.ts +55 -0
- package/core/app/processHandlers.ts +43 -0
- package/core/app/requestRouter.ts +309 -0
- package/core/app/restRegistry.ts +72 -0
- package/core/app/shutdown.ts +97 -0
- package/core/app/studioRouter.ts +83 -0
- package/core/archetype/customTypes.ts +100 -0
- package/core/archetype/decorators.ts +171 -0
- package/core/archetype/fieldResolvers.ts +621 -0
- package/core/archetype/helpers.ts +29 -0
- package/core/archetype/relationLoader.ts +118 -0
- package/core/archetype/schemaBuilder.ts +141 -0
- package/core/archetype/weaver.ts +218 -0
- package/core/archetype/zodSchemaBuilder.ts +527 -0
- package/core/cache/CacheManager.ts +144 -9
- package/core/components/BaseComponent.ts +12 -2
- package/core/middleware/AccessLog.ts +8 -1
- package/database/PreparedStatementCache.ts +17 -16
- package/database/cancellable.ts +22 -0
- package/database/instrumentedDb.ts +141 -0
- package/docs/RFC_APP_REFACTOR.md +248 -0
- package/docs/RFC_REFACTOR_TARGETS.md +251 -0
- package/package.json +1 -1
- package/query/ComponentInclusionNode.ts +5 -5
- package/query/Query.ts +65 -48
- package/service/ServiceRegistry.ts +7 -1
- package/service/index.ts +4 -2
- package/tests/integration/loaders/RequestLoaders.abort.test.ts +82 -0
- package/tests/integration/query/Query.abort.test.ts +66 -0
- package/tests/unit/cache/CacheManager.test.ts +152 -1
- package/tests/unit/database/cancellable.test.ts +81 -0
- package/tests/unit/database/instrumentedDb.test.ts +160 -0
- package/tests/unit/entity/Entity.components.test.ts +73 -0
- package/tests/unit/entity/Entity.drainSideEffects.test.ts +51 -0
- package/tests/unit/entity/Entity.reload.test.ts +63 -0
- package/tests/unit/entity/Entity.requireComponents.test.ts +72 -0
- package/tests/unit/query/Query.emptyString.test.ts +69 -0
- package/tests/unit/query/Query.test.ts +6 -4
- package/tests/unit/scheduler/SchedulerManager.timeBased.test.ts +95 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for SchedulerManager time-based (entity-less) tasks.
|
|
3
|
+
* Covers BUNSANE-002: @ScheduledTask without query/componentTarget.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
|
|
6
|
+
import { SchedulerManager } from '../../../core/SchedulerManager';
|
|
7
|
+
import { ScheduleInterval } from '../../../types/scheduler.types';
|
|
8
|
+
|
|
9
|
+
describe('SchedulerManager time-based tasks', () => {
|
|
10
|
+
let scheduler: SchedulerManager;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
scheduler = SchedulerManager.getInstance();
|
|
14
|
+
scheduler.updateConfig({
|
|
15
|
+
enabled: true,
|
|
16
|
+
enableLogging: false,
|
|
17
|
+
runOnStart: false,
|
|
18
|
+
distributedLocking: false,
|
|
19
|
+
maxConcurrentTasks: 5,
|
|
20
|
+
defaultTimeout: 5000,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(async () => {
|
|
25
|
+
await scheduler.stop().catch(() => {});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('registers task with no query / no componentTarget', () => {
|
|
29
|
+
let called = 0;
|
|
30
|
+
const service = {
|
|
31
|
+
tick: async () => {
|
|
32
|
+
called++;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
expect(() =>
|
|
37
|
+
scheduler.registerTask({
|
|
38
|
+
id: 'test.timebased.register',
|
|
39
|
+
name: 'timebased-register',
|
|
40
|
+
interval: ScheduleInterval.MINUTE,
|
|
41
|
+
options: {},
|
|
42
|
+
service,
|
|
43
|
+
methodName: 'tick',
|
|
44
|
+
nextExecution: new Date(),
|
|
45
|
+
executionCount: 0,
|
|
46
|
+
isRunning: false,
|
|
47
|
+
enabled: true,
|
|
48
|
+
})
|
|
49
|
+
).not.toThrow();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('executes handler with no entity argument', async () => {
|
|
53
|
+
const receivedArgsBox: { args: unknown[] | null } = { args: null };
|
|
54
|
+
const service = {
|
|
55
|
+
tick: async (...args: unknown[]) => {
|
|
56
|
+
receivedArgsBox.args = args;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
scheduler.registerTask({
|
|
61
|
+
id: 'test.timebased.exec',
|
|
62
|
+
name: 'timebased-exec',
|
|
63
|
+
interval: ScheduleInterval.MINUTE,
|
|
64
|
+
options: {},
|
|
65
|
+
service,
|
|
66
|
+
methodName: 'tick',
|
|
67
|
+
nextExecution: new Date(),
|
|
68
|
+
executionCount: 0,
|
|
69
|
+
isRunning: false,
|
|
70
|
+
enabled: true,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const ok = await scheduler.executeTaskNow('test.timebased.exec');
|
|
74
|
+
expect(ok).toBe(true);
|
|
75
|
+
expect(receivedArgsBox.args).toEqual([]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('rejects task still missing required fields', () => {
|
|
79
|
+
const service = { tick: async () => {} };
|
|
80
|
+
expect(() =>
|
|
81
|
+
scheduler.registerTask({
|
|
82
|
+
// missing id
|
|
83
|
+
name: 'bad',
|
|
84
|
+
interval: ScheduleInterval.MINUTE,
|
|
85
|
+
options: {},
|
|
86
|
+
service,
|
|
87
|
+
methodName: 'tick',
|
|
88
|
+
nextExecution: new Date(),
|
|
89
|
+
executionCount: 0,
|
|
90
|
+
isRunning: false,
|
|
91
|
+
enabled: true,
|
|
92
|
+
} as any)
|
|
93
|
+
).toThrow(/missing required fields/);
|
|
94
|
+
});
|
|
95
|
+
});
|