cadenlane-cli-2 1.0.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 (206) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE +21 -0
  3. package/README.md +333 -0
  4. package/bin.js +2 -0
  5. package/dist/application/config/config.manager.d.ts +62 -0
  6. package/dist/application/config/config.manager.d.ts.map +1 -0
  7. package/dist/application/config/config.manager.js +146 -0
  8. package/dist/application/config/config.manager.js.map +1 -0
  9. package/dist/application/services/application.service.d.ts +35 -0
  10. package/dist/application/services/application.service.d.ts.map +1 -0
  11. package/dist/application/services/application.service.js +174 -0
  12. package/dist/application/services/application.service.js.map +1 -0
  13. package/dist/application/services/download.service.d.ts +27 -0
  14. package/dist/application/services/download.service.d.ts.map +1 -0
  15. package/dist/application/services/download.service.js +197 -0
  16. package/dist/application/services/download.service.js.map +1 -0
  17. package/dist/application/services/file-naming.service.d.ts +34 -0
  18. package/dist/application/services/file-naming.service.d.ts.map +1 -0
  19. package/dist/application/services/file-naming.service.js +142 -0
  20. package/dist/application/services/file-naming.service.js.map +1 -0
  21. package/dist/application/services/queue.service.d.ts +53 -0
  22. package/dist/application/services/queue.service.d.ts.map +1 -0
  23. package/dist/application/services/queue.service.js +82 -0
  24. package/dist/application/services/queue.service.js.map +1 -0
  25. package/dist/cli/commands/start.command.d.ts +39 -0
  26. package/dist/cli/commands/start.command.d.ts.map +1 -0
  27. package/dist/cli/commands/start.command.js +196 -0
  28. package/dist/cli/commands/start.command.js.map +1 -0
  29. package/dist/cli/index.d.ts +3 -0
  30. package/dist/cli/index.d.ts.map +1 -0
  31. package/dist/cli/index.js +86 -0
  32. package/dist/cli/index.js.map +1 -0
  33. package/dist/domain/constants/config.constants.d.ts +54 -0
  34. package/dist/domain/constants/config.constants.d.ts.map +1 -0
  35. package/dist/domain/constants/config.constants.js +142 -0
  36. package/dist/domain/constants/config.constants.js.map +1 -0
  37. package/dist/domain/dtos/index.d.ts +4 -0
  38. package/dist/domain/dtos/index.d.ts.map +1 -0
  39. package/dist/domain/dtos/index.js +10 -0
  40. package/dist/domain/dtos/index.js.map +1 -0
  41. package/dist/domain/dtos/log-entry.dto.d.ts +15 -0
  42. package/dist/domain/dtos/log-entry.dto.d.ts.map +1 -0
  43. package/dist/domain/dtos/log-entry.dto.js +64 -0
  44. package/dist/domain/dtos/log-entry.dto.js.map +1 -0
  45. package/dist/domain/dtos/message.dto.d.ts +27 -0
  46. package/dist/domain/dtos/message.dto.d.ts.map +1 -0
  47. package/dist/domain/dtos/message.dto.js +140 -0
  48. package/dist/domain/dtos/message.dto.js.map +1 -0
  49. package/dist/domain/dtos/queue-message.dto.d.ts +10 -0
  50. package/dist/domain/dtos/queue-message.dto.d.ts.map +1 -0
  51. package/dist/domain/dtos/queue-message.dto.js +39 -0
  52. package/dist/domain/dtos/queue-message.dto.js.map +1 -0
  53. package/dist/domain/entities/cli-instance.entity.d.ts +55 -0
  54. package/dist/domain/entities/cli-instance.entity.d.ts.map +1 -0
  55. package/dist/domain/entities/cli-instance.entity.js +132 -0
  56. package/dist/domain/entities/cli-instance.entity.js.map +1 -0
  57. package/dist/domain/entities/index.d.ts +3 -0
  58. package/dist/domain/entities/index.d.ts.map +1 -0
  59. package/dist/domain/entities/index.js +8 -0
  60. package/dist/domain/entities/index.js.map +1 -0
  61. package/dist/domain/entities/log-entry.entity.d.ts +60 -0
  62. package/dist/domain/entities/log-entry.entity.d.ts.map +1 -0
  63. package/dist/domain/entities/log-entry.entity.js +101 -0
  64. package/dist/domain/entities/log-entry.entity.js.map +1 -0
  65. package/dist/domain/entities/message.entity.d.ts +64 -0
  66. package/dist/domain/entities/message.entity.d.ts.map +1 -0
  67. package/dist/domain/entities/message.entity.js +110 -0
  68. package/dist/domain/entities/message.entity.js.map +1 -0
  69. package/dist/domain/enums/error-category.enum.d.ts +11 -0
  70. package/dist/domain/enums/error-category.enum.d.ts.map +1 -0
  71. package/dist/domain/enums/error-category.enum.js +15 -0
  72. package/dist/domain/enums/error-category.enum.js.map +1 -0
  73. package/dist/domain/enums/index.d.ts +4 -0
  74. package/dist/domain/enums/index.d.ts.map +1 -0
  75. package/dist/domain/enums/index.js +10 -0
  76. package/dist/domain/enums/index.js.map +1 -0
  77. package/dist/domain/enums/log-level.enum.d.ts +11 -0
  78. package/dist/domain/enums/log-level.enum.d.ts.map +1 -0
  79. package/dist/domain/enums/log-level.enum.js +15 -0
  80. package/dist/domain/enums/log-level.enum.js.map +1 -0
  81. package/dist/domain/enums/message-status.enum.d.ts +11 -0
  82. package/dist/domain/enums/message-status.enum.d.ts.map +1 -0
  83. package/dist/domain/enums/message-status.enum.js +15 -0
  84. package/dist/domain/enums/message-status.enum.js.map +1 -0
  85. package/dist/domain/interfaces/adapters/ifilesystem.adapter.d.ts +34 -0
  86. package/dist/domain/interfaces/adapters/ifilesystem.adapter.d.ts.map +1 -0
  87. package/dist/domain/interfaces/adapters/ifilesystem.adapter.js +3 -0
  88. package/dist/domain/interfaces/adapters/ifilesystem.adapter.js.map +1 -0
  89. package/dist/domain/interfaces/adapters/ihttp.adapter.d.ts +22 -0
  90. package/dist/domain/interfaces/adapters/ihttp.adapter.d.ts.map +1 -0
  91. package/dist/domain/interfaces/adapters/ihttp.adapter.js +3 -0
  92. package/dist/domain/interfaces/adapters/ihttp.adapter.js.map +1 -0
  93. package/dist/domain/interfaces/adapters/index.d.ts +4 -0
  94. package/dist/domain/interfaces/adapters/index.d.ts.map +1 -0
  95. package/dist/domain/interfaces/adapters/index.js +3 -0
  96. package/dist/domain/interfaces/adapters/index.js.map +1 -0
  97. package/dist/domain/interfaces/adapters/isupabase.adapter.d.ts +27 -0
  98. package/dist/domain/interfaces/adapters/isupabase.adapter.d.ts.map +1 -0
  99. package/dist/domain/interfaces/adapters/isupabase.adapter.js +3 -0
  100. package/dist/domain/interfaces/adapters/isupabase.adapter.js.map +1 -0
  101. package/dist/domain/interfaces/repositories/ilog.repository.d.ts +32 -0
  102. package/dist/domain/interfaces/repositories/ilog.repository.d.ts.map +1 -0
  103. package/dist/domain/interfaces/repositories/ilog.repository.js +3 -0
  104. package/dist/domain/interfaces/repositories/ilog.repository.js.map +1 -0
  105. package/dist/domain/interfaces/repositories/imessage.repository.d.ts +39 -0
  106. package/dist/domain/interfaces/repositories/imessage.repository.d.ts.map +1 -0
  107. package/dist/domain/interfaces/repositories/imessage.repository.js +3 -0
  108. package/dist/domain/interfaces/repositories/imessage.repository.js.map +1 -0
  109. package/dist/domain/interfaces/repositories/index.d.ts +4 -0
  110. package/dist/domain/interfaces/repositories/index.d.ts.map +1 -0
  111. package/dist/domain/interfaces/repositories/index.js +3 -0
  112. package/dist/domain/interfaces/repositories/index.js.map +1 -0
  113. package/dist/domain/interfaces/repositories/iqueue.repository.d.ts +75 -0
  114. package/dist/domain/interfaces/repositories/iqueue.repository.d.ts.map +1 -0
  115. package/dist/domain/interfaces/repositories/iqueue.repository.js +3 -0
  116. package/dist/domain/interfaces/repositories/iqueue.repository.js.map +1 -0
  117. package/dist/domain/interfaces/services/idownload.service.d.ts +28 -0
  118. package/dist/domain/interfaces/services/idownload.service.d.ts.map +1 -0
  119. package/dist/domain/interfaces/services/idownload.service.js +3 -0
  120. package/dist/domain/interfaces/services/idownload.service.js.map +1 -0
  121. package/dist/domain/interfaces/services/iqueue.service.d.ts +35 -0
  122. package/dist/domain/interfaces/services/iqueue.service.d.ts.map +1 -0
  123. package/dist/domain/interfaces/services/iqueue.service.js +3 -0
  124. package/dist/domain/interfaces/services/iqueue.service.js.map +1 -0
  125. package/dist/domain/services/path-resolver.service.d.ts +94 -0
  126. package/dist/domain/services/path-resolver.service.d.ts.map +1 -0
  127. package/dist/domain/services/path-resolver.service.js +332 -0
  128. package/dist/domain/services/path-resolver.service.js.map +1 -0
  129. package/dist/domain/validators/index.d.ts +4 -0
  130. package/dist/domain/validators/index.d.ts.map +1 -0
  131. package/dist/domain/validators/index.js +10 -0
  132. package/dist/domain/validators/index.js.map +1 -0
  133. package/dist/domain/validators/message.validator.d.ts +20 -0
  134. package/dist/domain/validators/message.validator.d.ts.map +1 -0
  135. package/dist/domain/validators/message.validator.js +31 -0
  136. package/dist/domain/validators/message.validator.js.map +1 -0
  137. package/dist/domain/validators/path.validator.d.ts +44 -0
  138. package/dist/domain/validators/path.validator.d.ts.map +1 -0
  139. package/dist/domain/validators/path.validator.js +156 -0
  140. package/dist/domain/validators/path.validator.js.map +1 -0
  141. package/dist/domain/validators/url.validator.d.ts +19 -0
  142. package/dist/domain/validators/url.validator.d.ts.map +1 -0
  143. package/dist/domain/validators/url.validator.js +46 -0
  144. package/dist/domain/validators/url.validator.js.map +1 -0
  145. package/dist/index.d.ts +11 -0
  146. package/dist/index.d.ts.map +1 -0
  147. package/dist/index.js +27 -0
  148. package/dist/index.js.map +1 -0
  149. package/dist/infrastructure/adapters/filesystem.adapter.d.ts +35 -0
  150. package/dist/infrastructure/adapters/filesystem.adapter.d.ts.map +1 -0
  151. package/dist/infrastructure/adapters/filesystem.adapter.js +103 -0
  152. package/dist/infrastructure/adapters/filesystem.adapter.js.map +1 -0
  153. package/dist/infrastructure/adapters/http.adapter.d.ts +15 -0
  154. package/dist/infrastructure/adapters/http.adapter.d.ts.map +1 -0
  155. package/dist/infrastructure/adapters/http.adapter.js +80 -0
  156. package/dist/infrastructure/adapters/http.adapter.js.map +1 -0
  157. package/dist/infrastructure/adapters/index.d.ts +4 -0
  158. package/dist/infrastructure/adapters/index.d.ts.map +1 -0
  159. package/dist/infrastructure/adapters/index.js +10 -0
  160. package/dist/infrastructure/adapters/index.js.map +1 -0
  161. package/dist/infrastructure/adapters/pgmq.adapter.d.ts +29 -0
  162. package/dist/infrastructure/adapters/pgmq.adapter.d.ts.map +1 -0
  163. package/dist/infrastructure/adapters/pgmq.adapter.js +84 -0
  164. package/dist/infrastructure/adapters/pgmq.adapter.js.map +1 -0
  165. package/dist/infrastructure/adapters/supabase.adapter.d.ts +79 -0
  166. package/dist/infrastructure/adapters/supabase.adapter.d.ts.map +1 -0
  167. package/dist/infrastructure/adapters/supabase.adapter.js +97 -0
  168. package/dist/infrastructure/adapters/supabase.adapter.js.map +1 -0
  169. package/dist/infrastructure/database/supabase.client.d.ts +20 -0
  170. package/dist/infrastructure/database/supabase.client.d.ts.map +1 -0
  171. package/dist/infrastructure/database/supabase.client.js +36 -0
  172. package/dist/infrastructure/database/supabase.client.js.map +1 -0
  173. package/dist/infrastructure/di/container.d.ts +18 -0
  174. package/dist/infrastructure/di/container.d.ts.map +1 -0
  175. package/dist/infrastructure/di/container.js +103 -0
  176. package/dist/infrastructure/di/container.js.map +1 -0
  177. package/dist/infrastructure/repositories/cli-instance.repository.d.ts +64 -0
  178. package/dist/infrastructure/repositories/cli-instance.repository.d.ts.map +1 -0
  179. package/dist/infrastructure/repositories/cli-instance.repository.js +154 -0
  180. package/dist/infrastructure/repositories/cli-instance.repository.js.map +1 -0
  181. package/dist/infrastructure/repositories/config.repository.d.ts +52 -0
  182. package/dist/infrastructure/repositories/config.repository.d.ts.map +1 -0
  183. package/dist/infrastructure/repositories/config.repository.js +130 -0
  184. package/dist/infrastructure/repositories/config.repository.js.map +1 -0
  185. package/dist/infrastructure/repositories/index.d.ts +4 -0
  186. package/dist/infrastructure/repositories/index.d.ts.map +1 -0
  187. package/dist/infrastructure/repositories/index.js +10 -0
  188. package/dist/infrastructure/repositories/index.js.map +1 -0
  189. package/dist/infrastructure/repositories/log.repository.d.ts +44 -0
  190. package/dist/infrastructure/repositories/log.repository.d.ts.map +1 -0
  191. package/dist/infrastructure/repositories/log.repository.js +108 -0
  192. package/dist/infrastructure/repositories/log.repository.js.map +1 -0
  193. package/dist/infrastructure/repositories/message.repository.d.ts +51 -0
  194. package/dist/infrastructure/repositories/message.repository.d.ts.map +1 -0
  195. package/dist/infrastructure/repositories/message.repository.js +161 -0
  196. package/dist/infrastructure/repositories/message.repository.js.map +1 -0
  197. package/dist/infrastructure/repositories/queue.repository.d.ts +69 -0
  198. package/dist/infrastructure/repositories/queue.repository.d.ts.map +1 -0
  199. package/dist/infrastructure/repositories/queue.repository.js +130 -0
  200. package/dist/infrastructure/repositories/queue.repository.js.map +1 -0
  201. package/dist/infrastructure/utils/connection-health.util.d.ts +23 -0
  202. package/dist/infrastructure/utils/connection-health.util.d.ts.map +1 -0
  203. package/dist/infrastructure/utils/connection-health.util.js +64 -0
  204. package/dist/infrastructure/utils/connection-health.util.js.map +1 -0
  205. package/package.json +105 -0
  206. package/pm2.config.js +104 -0
@@ -0,0 +1,53 @@
1
+ import { IQueueService } from '../../domain/interfaces/services/iqueue.service';
2
+ import { PgmqMessage } from '../../domain/interfaces/repositories';
3
+ import { QueueRepository } from '../../infrastructure/repositories/queue.repository';
4
+ import { AppConfig } from '../config/config.manager';
5
+ /**
6
+ * Queue Service
7
+ * Handles queue operations and message lifecycle
8
+ */
9
+ export declare class QueueService implements IQueueService {
10
+ private queueRepository;
11
+ private config;
12
+ constructor(queueRepository: QueueRepository, config: AppConfig);
13
+ /**
14
+ * Polls the queue for a new message (non-blocking)
15
+ * @returns PGMQ message or null if queue is empty
16
+ */
17
+ pollMessage(): Promise<PgmqMessage | null>;
18
+ /**
19
+ * Polls the queue for a new message with blocking wait (event-driven)
20
+ * Waits up to pollTimeoutSeconds for a message to arrive
21
+ * @param pollTimeoutSeconds - How long to wait for a message (default: 5s)
22
+ * @returns PGMQ message or null if timeout reached
23
+ */
24
+ pollMessageWithWait(pollTimeoutSeconds?: number): Promise<PgmqMessage | null>;
25
+ /**
26
+ * Acknowledges successful message processing by deleting from queue
27
+ * @param messageId - PGMQ message ID
28
+ * @returns true if deleted, false otherwise
29
+ */
30
+ acknowledgeMessage(messageId: number): Promise<boolean>;
31
+ /**
32
+ * Gets queue metrics
33
+ * @returns Queue metrics
34
+ */
35
+ getQueueMetrics(): Promise<{
36
+ queue_name: string;
37
+ queue_length: number;
38
+ newest_msg_age_sec: number | null;
39
+ oldest_msg_age_sec: number | null;
40
+ total_messages: number;
41
+ }>;
42
+ /**
43
+ * Creates the queue for this CLI instance (idempotent)
44
+ * @returns true if created or already exists
45
+ */
46
+ createQueue(): Promise<boolean>;
47
+ /**
48
+ * Gets the queue name for this CLI instance
49
+ * @returns Queue name
50
+ */
51
+ getQueueName(): string;
52
+ }
53
+ //# sourceMappingURL=queue.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.service.d.ts","sourceRoot":"","sources":["../../../src/application/services/queue.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD;;;GAGG;AACH,qBACa,YAAa,YAAW,aAAa;IAErB,OAAO,CAAC,eAAe;IAC3B,OAAO,CAAC,MAAM;gBADF,eAAe,EAAE,eAAe,EACpC,MAAM,EAAE,SAAS;IAGhD;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAOhD;;;;;OAKG;IACG,mBAAmB,CAAC,kBAAkB,GAAE,MAAU,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAQtF;;;;OAIG;IACG,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAO7D;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;QACrB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;QAClC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;QAClC,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;IAIF;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;OAGG;IACH,YAAY,IAAI,MAAM;CAGvB"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.QueueService = void 0;
16
+ const tsyringe_1 = require("tsyringe");
17
+ const queue_repository_1 = require("../../infrastructure/repositories/queue.repository");
18
+ /**
19
+ * Queue Service
20
+ * Handles queue operations and message lifecycle
21
+ */
22
+ let QueueService = class QueueService {
23
+ queueRepository;
24
+ config;
25
+ constructor(queueRepository, config) {
26
+ this.queueRepository = queueRepository;
27
+ this.config = config;
28
+ }
29
+ /**
30
+ * Polls the queue for a new message (non-blocking)
31
+ * @returns PGMQ message or null if queue is empty
32
+ */
33
+ async pollMessage() {
34
+ return await this.queueRepository.readMessage(this.config.queue.name, this.config.queue.visibilityTimeoutSeconds);
35
+ }
36
+ /**
37
+ * Polls the queue for a new message with blocking wait (event-driven)
38
+ * Waits up to pollTimeoutSeconds for a message to arrive
39
+ * @param pollTimeoutSeconds - How long to wait for a message (default: 5s)
40
+ * @returns PGMQ message or null if timeout reached
41
+ */
42
+ async pollMessageWithWait(pollTimeoutSeconds = 5) {
43
+ return await this.queueRepository.readMessageWithPoll(this.config.queue.name, this.config.queue.visibilityTimeoutSeconds, pollTimeoutSeconds);
44
+ }
45
+ /**
46
+ * Acknowledges successful message processing by deleting from queue
47
+ * @param messageId - PGMQ message ID
48
+ * @returns true if deleted, false otherwise
49
+ */
50
+ async acknowledgeMessage(messageId) {
51
+ return await this.queueRepository.deleteMessage(this.config.queue.name, messageId);
52
+ }
53
+ /**
54
+ * Gets queue metrics
55
+ * @returns Queue metrics
56
+ */
57
+ async getQueueMetrics() {
58
+ return await this.queueRepository.getMetrics(this.config.queue.name);
59
+ }
60
+ /**
61
+ * Creates the queue for this CLI instance (idempotent)
62
+ * @returns true if created or already exists
63
+ */
64
+ async createQueue() {
65
+ return await this.queueRepository.createQueue(this.config.queue.name);
66
+ }
67
+ /**
68
+ * Gets the queue name for this CLI instance
69
+ * @returns Queue name
70
+ */
71
+ getQueueName() {
72
+ return this.config.queue.name;
73
+ }
74
+ };
75
+ exports.QueueService = QueueService;
76
+ exports.QueueService = QueueService = __decorate([
77
+ (0, tsyringe_1.injectable)(),
78
+ __param(0, (0, tsyringe_1.inject)(queue_repository_1.QueueRepository)),
79
+ __param(1, (0, tsyringe_1.inject)('AppConfig')),
80
+ __metadata("design:paramtypes", [queue_repository_1.QueueRepository, Object])
81
+ ], QueueService);
82
+ //# sourceMappingURL=queue.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.service.js","sourceRoot":"","sources":["../../../src/application/services/queue.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAA8C;AAG9C,qFAAiF;AAGjF;;;GAGG;AAEI,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEY;IACJ;IAF/B,YACmC,eAAgC,EACpC,MAAiB;QADb,oBAAe,GAAf,eAAe,CAAiB;QACpC,WAAM,GAAN,MAAM,CAAW;IAC7C,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,WAAW;QACf,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,WAAW,CAC3C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAC3C,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,mBAAmB,CAAC,qBAA6B,CAAC;QACtD,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,mBAAmB,CACnD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAC1C,kBAAkB,CACnB,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,kBAAkB,CAAC,SAAiB;QACxC,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EACtB,SAAS,CACV,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe;QAOnB,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACvE,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,WAAW;QACf,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACxE,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;IAChC,CAAC;CACF,CAAA;AAxEY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,qBAAU,GAAE;IAGR,WAAA,IAAA,iBAAM,EAAC,kCAAe,CAAC,CAAA;IACvB,WAAA,IAAA,iBAAM,EAAC,WAAW,CAAC,CAAA;qCAD8B,kCAAe;GAFxD,YAAY,CAwExB"}
@@ -0,0 +1,39 @@
1
+ import { Command } from 'commander';
2
+ import { ApplicationService } from '../../application/services/application.service';
3
+ import { QueueService } from '../../application/services/queue.service';
4
+ /**
5
+ * Start Command
6
+ * Starts the image download worker using event-driven blocking reads
7
+ */
8
+ export declare class StartCommand {
9
+ private applicationService;
10
+ private queueService;
11
+ private running;
12
+ private blockingPollTimeoutSeconds;
13
+ constructor(applicationService: ApplicationService, queueService: QueueService, blockingPollTimeoutSeconds: number);
14
+ /**
15
+ * Creates and configures the start command
16
+ */
17
+ static create(): Command;
18
+ /**
19
+ * Executes the start command
20
+ */
21
+ execute(): Promise<void>;
22
+ /**
23
+ * Main processing loop using simple polling
24
+ */
25
+ private processLoop;
26
+ /**
27
+ * Process a single message
28
+ */
29
+ private processMessage;
30
+ /**
31
+ * Sets up graceful shutdown handlers
32
+ */
33
+ private setupGracefulShutdown;
34
+ /**
35
+ * Sleep utility
36
+ */
37
+ private sleep;
38
+ }
39
+ //# sourceMappingURL=start.command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/start.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEpE;;;GAGG;AACH,qBAAa,YAAY;IAKrB,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,YAAY;IALtB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,0BAA0B,CAAS;gBAGjC,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY,EAClC,0BAA0B,EAAE,MAAM;IAKpC;;OAEG;IACH,MAAM,CAAC,MAAM,IAAI,OAAO;IA2BxB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAoD9B;;OAEG;YACW,WAAW;IA2EzB;;OAEG;YACW,cAAc;IAU5B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAU7B;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd"}
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StartCommand = void 0;
4
+ const commander_1 = require("commander");
5
+ const container_1 = require("../../infrastructure/di/container");
6
+ const application_service_1 = require("../../application/services/application.service");
7
+ const queue_service_1 = require("../../application/services/queue.service");
8
+ /**
9
+ * Start Command
10
+ * Starts the image download worker using event-driven blocking reads
11
+ */
12
+ class StartCommand {
13
+ applicationService;
14
+ queueService;
15
+ running = false;
16
+ blockingPollTimeoutSeconds;
17
+ constructor(applicationService, queueService, blockingPollTimeoutSeconds) {
18
+ this.applicationService = applicationService;
19
+ this.queueService = queueService;
20
+ this.blockingPollTimeoutSeconds = blockingPollTimeoutSeconds;
21
+ }
22
+ /**
23
+ * Creates and configures the start command
24
+ */
25
+ static create() {
26
+ const command = new commander_1.Command('start');
27
+ command
28
+ .description('Start the image download worker')
29
+ .option('-t, --timeout <seconds>', 'Blocking poll timeout in seconds (how long to wait for messages)', '5')
30
+ .action(async (options) => {
31
+ try {
32
+ // Setup DI container (now async)
33
+ const container = await container_1.DIContainer.setup();
34
+ const applicationService = container.resolve(application_service_1.ApplicationService);
35
+ const queueService = container.resolve(queue_service_1.QueueService);
36
+ // Use timeout from options or default to 5 seconds
37
+ const pollTimeout = parseInt(options.timeout, 10) || 5;
38
+ const startCommand = new StartCommand(applicationService, queueService, pollTimeout);
39
+ await startCommand.execute();
40
+ }
41
+ catch (error) {
42
+ console.error('Failed to start worker:', error);
43
+ process.exit(1);
44
+ }
45
+ });
46
+ return command;
47
+ }
48
+ /**
49
+ * Executes the start command
50
+ */
51
+ async execute() {
52
+ console.log('🚀 Starting image download worker (event-driven mode)...');
53
+ console.log(`📊 Blocking poll timeout: ${this.blockingPollTimeoutSeconds}s`);
54
+ console.log('⚡ Worker will wait for messages instead of polling');
55
+ // Create instance-specific queue (idempotent)
56
+ try {
57
+ console.log('📬 Creating instance-specific queue...');
58
+ await this.queueService.createQueue();
59
+ console.log('✅ Queue ready');
60
+ }
61
+ catch (error) {
62
+ const errorMessage = error instanceof Error ? error.message : String(error);
63
+ const errorStack = error instanceof Error ? error.stack : '';
64
+ console.error('❌ Queue creation failed:', errorMessage);
65
+ if (errorStack) {
66
+ console.error('Stack trace:', errorStack);
67
+ }
68
+ throw error; // Don't continue if queue creation fails
69
+ }
70
+ // Display queue name for API testing
71
+ const queueName = this.queueService.getQueueName();
72
+ const supabaseUrl = process.env.SUPABASE_URL || 'http://127.0.0.1:54321';
73
+ console.log('');
74
+ console.log('═══════════════════════════════════════════════════════════');
75
+ console.log('📮 QUEUE NAME: ' + queueName);
76
+ console.log('═══════════════════════════════════════════════════════════');
77
+ console.log('');
78
+ console.log('To send a message via API, use:');
79
+ console.log('');
80
+ console.log(`curl -X POST '${supabaseUrl}/rest/v1/rpc/pgmq_send_message' \\`);
81
+ console.log(` -H "Content-Type: application/json" \\`);
82
+ console.log(` -d '{`);
83
+ console.log(` "queue_name": "${queueName}",`);
84
+ console.log(` "msg": {`);
85
+ console.log(` "file_url": "https://picsum.photos/800/600",`);
86
+ console.log(` "target_folder": "/tmp/downloads"`);
87
+ console.log(` }`);
88
+ console.log(` }'`);
89
+ console.log('');
90
+ console.log('═══════════════════════════════════════════════════════════');
91
+ console.log('');
92
+ this.running = true;
93
+ // Setup graceful shutdown
94
+ this.setupGracefulShutdown();
95
+ // Start processing loop
96
+ await this.processLoop();
97
+ }
98
+ /**
99
+ * Main processing loop using simple polling
100
+ */
101
+ async processLoop() {
102
+ console.log('🔄 Starting message processing loop...');
103
+ let consecutiveErrors = 0;
104
+ const maxConsecutiveErrors = 5;
105
+ while (this.running) {
106
+ try {
107
+ // Use non-blocking read
108
+ const queueMessage = await this.queueService.pollMessage();
109
+ if (!queueMessage) {
110
+ // No message available - wait before next poll
111
+ await this.sleep(this.blockingPollTimeoutSeconds * 1000);
112
+ consecutiveErrors = 0; // Reset error counter on successful poll
113
+ continue;
114
+ }
115
+ // Process the message
116
+ await this.processMessage(queueMessage);
117
+ consecutiveErrors = 0; // Reset error counter on successful processing
118
+ }
119
+ catch (error) {
120
+ consecutiveErrors++;
121
+ const errorMessage = error instanceof Error ? error.message : String(error);
122
+ console.error(`❌ Error in processing loop (${consecutiveErrors}/${maxConsecutiveErrors}):`, errorMessage);
123
+ // Check for database termination errors
124
+ if (errorMessage.includes('Database connection terminated') ||
125
+ errorMessage.includes('db_termination') ||
126
+ errorMessage.includes('shutdown')) {
127
+ console.error('');
128
+ console.error('═══════════════════════════════════════════════════════════');
129
+ console.error('⚠️ DATABASE CONNECTION LOST');
130
+ console.error('═══════════════════════════════════════════════════════════');
131
+ console.error('');
132
+ console.error('Your Supabase database connection was terminated.');
133
+ console.error('');
134
+ console.error('Common causes:');
135
+ console.error(' 1. Supabase project is paused (free tier auto-pauses after inactivity)');
136
+ console.error(' 2. Connection was idle for too long');
137
+ console.error(' 3. Database credentials changed');
138
+ console.error('');
139
+ console.error('Solutions:');
140
+ console.error(' 1. Go to https://supabase.com/dashboard');
141
+ console.error(' 2. Find your project and click "Restore" if it\'s paused');
142
+ console.error(' 3. Wait for the project to wake up (~1-2 minutes)');
143
+ console.error(' 4. Restart this CLI worker');
144
+ console.error('');
145
+ console.error('═══════════════════════════════════════════════════════════');
146
+ console.error('');
147
+ // Stop the worker gracefully
148
+ this.running = false;
149
+ break;
150
+ }
151
+ // Stop if too many consecutive errors
152
+ if (consecutiveErrors >= maxConsecutiveErrors) {
153
+ console.error('');
154
+ console.error(`❌ Too many consecutive errors (${maxConsecutiveErrors}). Stopping worker.`);
155
+ console.error('💡 Please check your database connection and configuration.');
156
+ this.running = false;
157
+ break;
158
+ }
159
+ // Exponential backoff: wait longer after each error
160
+ const backoffMs = Math.min(1000 * Math.pow(2, consecutiveErrors - 1), 30000);
161
+ console.log(`⏳ Waiting ${backoffMs / 1000}s before retry...`);
162
+ await this.sleep(backoffMs);
163
+ }
164
+ }
165
+ console.log('👋 Worker stopped gracefully');
166
+ }
167
+ /**
168
+ * Process a single message
169
+ */
170
+ async processMessage(queueMessage) {
171
+ const pgmqMessageId = queueMessage.msg_id;
172
+ const { image_url } = queueMessage.message;
173
+ console.log(`📥 Processing message ${pgmqMessageId}: ${image_url}`);
174
+ // Process the pre-fetched message
175
+ await this.applicationService.processMessage(queueMessage);
176
+ }
177
+ /**
178
+ * Sets up graceful shutdown handlers
179
+ */
180
+ setupGracefulShutdown() {
181
+ const shutdown = () => {
182
+ console.log('\n⚠️ Shutdown signal received, stopping worker...');
183
+ this.running = false;
184
+ };
185
+ process.on('SIGINT', shutdown);
186
+ process.on('SIGTERM', shutdown);
187
+ }
188
+ /**
189
+ * Sleep utility
190
+ */
191
+ sleep(ms) {
192
+ return new Promise((resolve) => setTimeout(resolve, ms));
193
+ }
194
+ }
195
+ exports.StartCommand = StartCommand;
196
+ //# sourceMappingURL=start.command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start.command.js","sourceRoot":"","sources":["../../../src/cli/commands/start.command.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AACpC,6DAA4D;AAC5D,oFAAgF;AAChF,wEAAoE;AAEpE;;;GAGG;AACH,MAAa,YAAY;IAKb;IACA;IALF,OAAO,GAAG,KAAK,CAAC;IAChB,0BAA0B,CAAS;IAE3C,YACU,kBAAsC,EACtC,YAA0B,EAClC,0BAAkC;QAF1B,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,iBAAY,GAAZ,YAAY,CAAc;QAGlC,IAAI,CAAC,0BAA0B,GAAG,0BAA0B,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM;QACX,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,OAAO,CAAC,CAAC;QAErC,OAAO;aACJ,WAAW,CAAC,iCAAiC,CAAC;aAC9C,MAAM,CAAC,yBAAyB,EAAE,kEAAkE,EAAE,GAAG,CAAC;aAC1G,MAAM,CAAC,KAAK,EAAE,OAA4B,EAAE,EAAE;YAC7C,IAAI,CAAC;gBACH,iCAAiC;gBACjC,MAAM,SAAS,GAAG,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,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;YAClE,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACvB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AA/MD,oCA+MC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import 'reflect-metadata';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,kBAAkB,CAAC"}
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ require("reflect-metadata");
8
+ const dotenv_1 = __importDefault(require("dotenv"));
9
+ const commander_1 = require("commander");
10
+ const start_command_1 = require("./commands/start.command");
11
+ const fs_1 = require("fs");
12
+ const path_1 = require("path");
13
+ const os_1 = require("os");
14
+ // Load .env with priority chain:
15
+ // 1. ./.env (current working directory - highest priority)
16
+ // 2. ./.env.local (local development overrides)
17
+ // 3. ~/.cadenlane-cli-2/.env (home directory config)
18
+ const loadEnvironment = () => {
19
+ const configDir = (0, path_1.join)((0, os_1.homedir)(), '.cadenlane-cli-2');
20
+ const cwdEnvPath = (0, path_1.join)(process.cwd(), '.env');
21
+ const localEnvPath = (0, path_1.join)(process.cwd(), '.env.local');
22
+ const homeEnvPath = (0, path_1.join)(configDir, '.env');
23
+ if ((0, fs_1.existsSync)(cwdEnvPath)) {
24
+ console.log(`[Config] Loading environment from: ${cwdEnvPath}`);
25
+ dotenv_1.default.config({ path: cwdEnvPath });
26
+ }
27
+ else if ((0, fs_1.existsSync)(localEnvPath)) {
28
+ console.log(`[Config] Loading environment from: ${localEnvPath}`);
29
+ dotenv_1.default.config({ path: localEnvPath });
30
+ }
31
+ else if ((0, fs_1.existsSync)(homeEnvPath)) {
32
+ console.log(`[Config] Loading environment from: ${homeEnvPath}`);
33
+ dotenv_1.default.config({ path: homeEnvPath });
34
+ }
35
+ else {
36
+ console.warn('[Config] No .env file found. Using system environment variables only.');
37
+ console.warn(`[Config] Searched locations:`);
38
+ console.warn(` 1. ${cwdEnvPath}`);
39
+ console.warn(` 2. ${localEnvPath}`);
40
+ console.warn(` 3. ${homeEnvPath}`);
41
+ }
42
+ };
43
+ // Load environment before anything else
44
+ loadEnvironment();
45
+ // Load package.json at runtime to work correctly when installed via npm
46
+ const getPackageJson = () => {
47
+ // Try multiple possible locations
48
+ const possiblePaths = [
49
+ (0, path_1.join)(__dirname, '..', '..', 'package.json'), // From src/cli (ts-node)
50
+ (0, path_1.join)(__dirname, '..', '..', '..', 'package.json'), // From dist/src/cli (compiled)
51
+ (0, path_1.join)(process.cwd(), 'package.json'), // From project root
52
+ ];
53
+ for (const packagePath of possiblePaths) {
54
+ if ((0, fs_1.existsSync)(packagePath)) {
55
+ try {
56
+ return JSON.parse((0, fs_1.readFileSync)(packagePath, 'utf-8'));
57
+ }
58
+ catch (error) {
59
+ // Continue to next path
60
+ }
61
+ }
62
+ }
63
+ // Fallback version if package.json not found
64
+ return { version: '1.0.0' };
65
+ };
66
+ /**
67
+ * CLI Application Entry Point
68
+ */
69
+ async function main() {
70
+ const packageJson = getPackageJson();
71
+ const program = new commander_1.Command();
72
+ program
73
+ .name('cadenlane-cli-2')
74
+ .description('Image Download Automation System - Processes images from Supabase PGMQ queue')
75
+ .version(packageJson.version);
76
+ // Register commands
77
+ program.addCommand(start_command_1.StartCommand.create());
78
+ // Parse arguments
79
+ await program.parseAsync(process.argv);
80
+ }
81
+ // Run the CLI
82
+ main().catch((error) => {
83
+ console.error('Fatal error:', error);
84
+ process.exit(1);
85
+ });
86
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;;;AACA,4BAA0B;AAC1B,oDAA4B;AAC5B,yCAAoC;AACpC,4DAAwD;AACxD,2BAA8C;AAC9C,+BAA4B;AAC5B,2BAA6B;AAE7B,iCAAiC;AACjC,2DAA2D;AAC3D,gDAAgD;AAChD,qDAAqD;AACrD,MAAM,eAAe,GAAG,GAAG,EAAE;IAC3B,MAAM,SAAS,GAAG,IAAA,WAAI,EAAC,IAAA,YAAO,GAAE,EAAE,kBAAkB,CAAC,CAAC;IACtD,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;IAC/C,MAAM,YAAY,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;IACvD,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAE5C,IAAI,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,sCAAsC,UAAU,EAAE,CAAC,CAAC;QAChE,gBAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,IAAA,eAAU,EAAC,YAAY,CAAC,EAAE,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,sCAAsC,YAAY,EAAE,CAAC,CAAC;QAClE,gBAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;IACxC,CAAC;SAAM,IA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C;IAED,6CAA6C;IAC7C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC,CAAC;AAEF;;GAEG;AACH,KAAK,UAAU,IAAI;IACjB,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;IAE9B,OAAO;SACJ,IAAI,CAAC,iBAAiB,CAAC;SACvB,WAAW,CAAC,8EAA8E,CAAC;SAC3F,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEhC,oBAAoB;IACpB,OAAO,CAAC,UAAU,CAAC,4BAAY,CAAC,MAAM,EAAE,CAAC,CAAC;IAE1C,kBAAkB;IAClB,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC;AAED,cAAc;AACd,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Default configuration constants
3
+ * These values are used when environment variables are not set
4
+ */
5
+ export declare const CONFIG_CONSTANTS: {
6
+ readonly DEFAULT_VISIBILITY_TIMEOUT_SECONDS: 30;
7
+ readonly DEFAULT_POLL_INTERVAL_MS: 1000;
8
+ readonly DEFAULT_DOWNLOAD_TIMEOUT_MS: 30000;
9
+ readonly DEFAULT_MAX_RETRIES: 3;
10
+ readonly MAX_FILE_SIZE_MB: 50;
11
+ readonly LOG_LEVEL: "INFO";
12
+ };
13
+ /**
14
+ * Platform-specific default paths
15
+ * These are used when no custom path is configured in the database
16
+ */
17
+ export declare const PLATFORM_DEFAULTS: {
18
+ /**
19
+ * Get default download path for current platform
20
+ */
21
+ readonly getDefaultDownloadPath: () => string;
22
+ /**
23
+ * Get platform-specific path examples for documentation/UI
24
+ */
25
+ readonly getPathExamples: () => Record<string, string>;
26
+ /**
27
+ * Get current platform information
28
+ */
29
+ readonly getPlatformInfo: () => {
30
+ platform: string;
31
+ isWindows: boolean;
32
+ isMac: boolean;
33
+ isLinux: boolean;
34
+ separator: string;
35
+ };
36
+ };
37
+ /**
38
+ * Database configuration keys for platform-specific settings
39
+ */
40
+ export declare const CONFIG_KEYS: {
41
+ readonly DOWNLOAD_DEFAULT_PATH: "download.default_path";
42
+ readonly DOWNLOAD_FALLBACK_PATH: "download.fallback_path";
43
+ readonly QUEUE_NAME: "queue.name";
44
+ readonly QUEUE_VISIBILITY_TIMEOUT: "queue.visibility_timeout_seconds";
45
+ readonly QUEUE_POLL_INTERVAL: "queue.poll_interval_ms";
46
+ readonly DOWNLOAD_TIMEOUT: "download.timeout_ms";
47
+ readonly DOWNLOAD_MAX_RETRIES: "download.max_retries";
48
+ readonly DOWNLOAD_MAX_FILE_SIZE: "download.max_file_size_mb";
49
+ };
50
+ /**
51
+ * Required environment variables
52
+ */
53
+ export declare const REQUIRED_ENV_VARS: readonly ["SUPABASE_URL", "SUPABASE_SERVICE_ROLE_KEY"];
54
+ //# sourceMappingURL=config.constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.constants.d.ts","sourceRoot":"","sources":["../../../src/domain/constants/config.constants.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;CAOnB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,iBAAiB;IAC5B;;OAEG;2CACuB,MAAM;IAgBhC;;OAEG;oCACgB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IA8BzC;;OAEG;oCACgB;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,OAAO,CAAC;QACnB,KAAK,EAAE,OAAO,CAAC;QACf,OAAO,EAAE,OAAO,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB;CAUO,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;CAcd,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,iBAAiB,wDAAyD,CAAC"}