@t1mmen/srtd 0.0.0-next-20251227000343

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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +363 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +50 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/apply.d.ts +2 -0
  7. package/dist/commands/apply.js +105 -0
  8. package/dist/commands/apply.js.map +1 -0
  9. package/dist/commands/build.d.ts +2 -0
  10. package/dist/commands/build.js +134 -0
  11. package/dist/commands/build.js.map +1 -0
  12. package/dist/commands/clear.d.ts +2 -0
  13. package/dist/commands/clear.js +161 -0
  14. package/dist/commands/clear.js.map +1 -0
  15. package/dist/commands/init.d.ts +2 -0
  16. package/dist/commands/init.js +91 -0
  17. package/dist/commands/init.js.map +1 -0
  18. package/dist/commands/menu.d.ts +4 -0
  19. package/dist/commands/menu.js +76 -0
  20. package/dist/commands/menu.js.map +1 -0
  21. package/dist/commands/promote.d.ts +2 -0
  22. package/dist/commands/promote.js +181 -0
  23. package/dist/commands/promote.js.map +1 -0
  24. package/dist/commands/register.d.ts +2 -0
  25. package/dist/commands/register.js +192 -0
  26. package/dist/commands/register.js.map +1 -0
  27. package/dist/commands/watch.d.ts +14 -0
  28. package/dist/commands/watch.js +190 -0
  29. package/dist/commands/watch.js.map +1 -0
  30. package/dist/constants.d.ts +1 -0
  31. package/dist/constants.js +2 -0
  32. package/dist/constants.js.map +1 -0
  33. package/dist/services/DatabaseService.d.ts +113 -0
  34. package/dist/services/DatabaseService.js +343 -0
  35. package/dist/services/DatabaseService.js.map +1 -0
  36. package/dist/services/FileSystemService.d.ts +100 -0
  37. package/dist/services/FileSystemService.js +237 -0
  38. package/dist/services/FileSystemService.js.map +1 -0
  39. package/dist/services/MigrationBuilder.d.ts +106 -0
  40. package/dist/services/MigrationBuilder.js +193 -0
  41. package/dist/services/MigrationBuilder.js.map +1 -0
  42. package/dist/services/Orchestrator.d.ts +155 -0
  43. package/dist/services/Orchestrator.js +622 -0
  44. package/dist/services/Orchestrator.js.map +1 -0
  45. package/dist/services/StateService.d.ts +169 -0
  46. package/dist/services/StateService.js +463 -0
  47. package/dist/services/StateService.js.map +1 -0
  48. package/dist/types.d.ts +48 -0
  49. package/dist/types.js +2 -0
  50. package/dist/types.js.map +1 -0
  51. package/dist/ui/badge.d.ts +14 -0
  52. package/dist/ui/badge.js +28 -0
  53. package/dist/ui/badge.js.map +1 -0
  54. package/dist/ui/branding.d.ts +9 -0
  55. package/dist/ui/branding.js +35 -0
  56. package/dist/ui/branding.js.map +1 -0
  57. package/dist/ui/index.d.ts +4 -0
  58. package/dist/ui/index.js +5 -0
  59. package/dist/ui/index.js.map +1 -0
  60. package/dist/ui/results.d.ts +10 -0
  61. package/dist/ui/results.js +62 -0
  62. package/dist/ui/results.js.map +1 -0
  63. package/dist/ui/spinner.d.ts +5 -0
  64. package/dist/ui/spinner.js +8 -0
  65. package/dist/ui/spinner.js.map +1 -0
  66. package/dist/utils/config.d.ts +12 -0
  67. package/dist/utils/config.js +67 -0
  68. package/dist/utils/config.js.map +1 -0
  69. package/dist/utils/createEmptyBuildLog.d.ts +1 -0
  70. package/dist/utils/createEmptyBuildLog.js +10 -0
  71. package/dist/utils/createEmptyBuildLog.js.map +1 -0
  72. package/dist/utils/ensureDirectories.d.ts +4 -0
  73. package/dist/utils/ensureDirectories.js +23 -0
  74. package/dist/utils/ensureDirectories.js.map +1 -0
  75. package/dist/utils/fileExists.d.ts +1 -0
  76. package/dist/utils/fileExists.js +11 -0
  77. package/dist/utils/fileExists.js.map +1 -0
  78. package/dist/utils/findProjectRoot.d.ts +1 -0
  79. package/dist/utils/findProjectRoot.js +25 -0
  80. package/dist/utils/findProjectRoot.js.map +1 -0
  81. package/dist/utils/getErrorMessage.d.ts +9 -0
  82. package/dist/utils/getErrorMessage.js +14 -0
  83. package/dist/utils/getErrorMessage.js.map +1 -0
  84. package/dist/utils/getNextTimestamp.d.ts +2 -0
  85. package/dist/utils/getNextTimestamp.js +12 -0
  86. package/dist/utils/getNextTimestamp.js.map +1 -0
  87. package/dist/utils/isWipTemplate.d.ts +1 -0
  88. package/dist/utils/isWipTemplate.js +6 -0
  89. package/dist/utils/isWipTemplate.js.map +1 -0
  90. package/dist/utils/logger.d.ts +9 -0
  91. package/dist/utils/logger.js +12 -0
  92. package/dist/utils/logger.js.map +1 -0
  93. package/dist/utils/safeCreate.d.ts +1 -0
  94. package/dist/utils/safeCreate.js +16 -0
  95. package/dist/utils/safeCreate.js.map +1 -0
  96. package/package.json +106 -0
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Orchestrator Service - Central coordinator for unidirectional data flow
3
+ * Manages coordination between FileSystemService, StateService, DatabaseService, and MigrationBuilder
4
+ * Implements the flow: FileSystem Event → Orchestrator → StateService (check) → Action → StateService (update)
5
+ */
6
+ import EventEmitter from 'node:events';
7
+ import type { CLIConfig, ProcessedTemplateResult, TemplateStatus } from '../types.js';
8
+ export interface OrchestratorEvent {
9
+ templateChanged: TemplateStatus;
10
+ templateApplied: TemplateStatus;
11
+ templateBuilt: TemplateStatus;
12
+ templateError: {
13
+ template: TemplateStatus;
14
+ error: string;
15
+ };
16
+ operationComplete: ProcessedTemplateResult;
17
+ }
18
+ export interface ApplyOptions {
19
+ force?: boolean;
20
+ templatePaths?: string[];
21
+ silent?: boolean;
22
+ }
23
+ export interface BuildOptions {
24
+ force?: boolean;
25
+ bundle?: boolean;
26
+ templatePaths?: string[];
27
+ silent?: boolean;
28
+ }
29
+ export interface WatchOptions {
30
+ silent?: boolean;
31
+ initialProcess?: boolean;
32
+ }
33
+ export interface OrchestratorConfig {
34
+ baseDir: string;
35
+ cliConfig: CLIConfig;
36
+ silent?: boolean;
37
+ }
38
+ export declare class Orchestrator extends EventEmitter implements Disposable {
39
+ private fileSystemService;
40
+ private stateService;
41
+ private databaseService;
42
+ private migrationBuilder;
43
+ private config;
44
+ private processQueue;
45
+ private pendingRecheck;
46
+ private processingTemplate;
47
+ private processing;
48
+ private watching;
49
+ constructor(config: OrchestratorConfig);
50
+ /**
51
+ * Initialize the orchestrator and all services
52
+ */
53
+ initialize(): Promise<void>;
54
+ /**
55
+ * Initialize all coordinated services
56
+ */
57
+ private initializeServices;
58
+ /**
59
+ * Set up event listeners for service coordination
60
+ */
61
+ private setupEventListeners;
62
+ /**
63
+ * Handle FileSystem events - Entry point for unidirectional flow
64
+ * Uses queue + pendingRecheck to prevent race conditions from rapid file changes
65
+ */
66
+ private handleFileSystemEvent;
67
+ /**
68
+ * Process the next template in the queue
69
+ */
70
+ private processNextTemplate;
71
+ /**
72
+ * Process a single template through the unidirectional flow
73
+ */
74
+ private processTemplate;
75
+ /**
76
+ * Get template status by coordinating between services
77
+ */
78
+ private getTemplateStatus;
79
+ /**
80
+ * Execute apply operation for a template
81
+ */
82
+ private executeApplyTemplate;
83
+ /**
84
+ * Command handler: Apply templates to database
85
+ */
86
+ apply(options?: ApplyOptions): Promise<ProcessedTemplateResult>;
87
+ /**
88
+ * Command handler: Build migration files from templates
89
+ */
90
+ build(options?: BuildOptions): Promise<ProcessedTemplateResult>;
91
+ /**
92
+ * Execute bundled migration build
93
+ */
94
+ private executeBundledBuild;
95
+ /**
96
+ * Execute individual migration builds
97
+ */
98
+ private executeIndividualBuilds;
99
+ /**
100
+ * Build a single template migration file
101
+ */
102
+ private executeBuildTemplate;
103
+ /**
104
+ * Command handler: Start watching for template changes
105
+ */
106
+ watch(options?: WatchOptions): Promise<{
107
+ close: () => Promise<void>;
108
+ }>;
109
+ /**
110
+ * Find all templates using FileSystemService
111
+ */
112
+ findTemplates(): Promise<string[]>;
113
+ /**
114
+ * Get template status for external consumers
115
+ */
116
+ getTemplateStatusExternal(templatePath: string): Promise<TemplateStatus>;
117
+ /**
118
+ * Register a template in the build log without building it
119
+ * Used when importing existing migrations that should be tracked
120
+ */
121
+ registerTemplate(templatePath: string): Promise<void>;
122
+ /**
123
+ * Promote a WIP template by renaming it and updating build logs
124
+ * @returns The new path after promotion
125
+ */
126
+ promoteTemplate(templatePath: string): Promise<string>;
127
+ /**
128
+ * Clear build logs via StateService (single source of truth)
129
+ * @param type - 'local' clears local only, 'shared' clears shared only, 'both' clears all
130
+ */
131
+ clearBuildLogs(type: 'local' | 'shared' | 'both'): Promise<void>;
132
+ /**
133
+ * Logging utility
134
+ */
135
+ private log;
136
+ /**
137
+ * Dispose of all services and clean up (async version for proper cleanup)
138
+ */
139
+ dispose(): Promise<void>;
140
+ /**
141
+ * Async dispose for await using statement - ensures cleanup completes
142
+ */
143
+ [Symbol.asyncDispose](): Promise<void>;
144
+ /**
145
+ * Synchronous dispose for using statement - schedules async cleanup
146
+ * Note: For proper cleanup, prefer await using with Symbol.asyncDispose
147
+ */
148
+ [Symbol.dispose](): void;
149
+ /**
150
+ * Create orchestrator from CLI configuration
151
+ */
152
+ static create(baseDir: string, cliConfig: CLIConfig, options?: {
153
+ silent?: boolean;
154
+ }): Promise<Orchestrator>;
155
+ }