@pikku/core 0.12.3 → 0.12.4

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 (218) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/services/in-memory-workflow-service.d.ts +15 -2
  3. package/dist/services/in-memory-workflow-service.js +49 -0
  4. package/lcov.info +18891 -0
  5. package/package.json +1 -1
  6. package/src/crypto-utils.test.ts +0 -214
  7. package/src/crypto-utils.ts +0 -213
  8. package/src/errors/error-handler.ts +0 -62
  9. package/src/errors/error.test.ts +0 -195
  10. package/src/errors/errors.ts +0 -374
  11. package/src/errors/index.ts +0 -2
  12. package/src/factory-functions.test.ts +0 -109
  13. package/src/function/function-runner.test.ts +0 -536
  14. package/src/function/function-runner.ts +0 -365
  15. package/src/function/functions.types.ts +0 -304
  16. package/src/function/index.ts +0 -5
  17. package/src/handle-error.test.ts +0 -424
  18. package/src/handle-error.ts +0 -69
  19. package/src/index.ts +0 -118
  20. package/src/internal.ts +0 -6
  21. package/src/middleware/auth-apikey.test.ts +0 -363
  22. package/src/middleware/auth-apikey.ts +0 -47
  23. package/src/middleware/auth-bearer.test.ts +0 -450
  24. package/src/middleware/auth-bearer.ts +0 -72
  25. package/src/middleware/auth-cookie.test.ts +0 -528
  26. package/src/middleware/auth-cookie.ts +0 -80
  27. package/src/middleware/cors.test.ts +0 -424
  28. package/src/middleware/cors.ts +0 -104
  29. package/src/middleware/index.ts +0 -5
  30. package/src/middleware/remote-auth.test.ts +0 -488
  31. package/src/middleware/remote-auth.ts +0 -68
  32. package/src/middleware/timeout.ts +0 -15
  33. package/src/middleware-runner.test.ts +0 -418
  34. package/src/middleware-runner.ts +0 -234
  35. package/src/permissions.test.ts +0 -434
  36. package/src/permissions.ts +0 -319
  37. package/src/pikku-request.ts +0 -23
  38. package/src/pikku-response.ts +0 -5
  39. package/src/pikku-state.test.ts +0 -224
  40. package/src/pikku-state.ts +0 -216
  41. package/src/run-tests-script.test.ts +0 -49
  42. package/src/schema.test.ts +0 -249
  43. package/src/schema.ts +0 -151
  44. package/src/services/ai-agent-runner-service.ts +0 -41
  45. package/src/services/ai-run-state-service.ts +0 -20
  46. package/src/services/ai-storage-service.ts +0 -39
  47. package/src/services/content-service.ts +0 -76
  48. package/src/services/deployment-service.ts +0 -22
  49. package/src/services/gateway-service.ts +0 -20
  50. package/src/services/gopass-secrets.ts +0 -98
  51. package/src/services/in-memory-ai-run-state-service.ts +0 -73
  52. package/src/services/in-memory-trigger-service.ts +0 -64
  53. package/src/services/in-memory-workflow-service.test.ts +0 -351
  54. package/src/services/in-memory-workflow-service.ts +0 -438
  55. package/src/services/index.ts +0 -56
  56. package/src/services/jwt-service.ts +0 -30
  57. package/src/services/local-content.ts +0 -120
  58. package/src/services/local-gateway-service.ts +0 -62
  59. package/src/services/local-secrets.test.ts +0 -80
  60. package/src/services/local-secrets.ts +0 -94
  61. package/src/services/local-variables.test.ts +0 -61
  62. package/src/services/local-variables.ts +0 -39
  63. package/src/services/logger-console.test.ts +0 -118
  64. package/src/services/logger-console.ts +0 -98
  65. package/src/services/logger.ts +0 -57
  66. package/src/services/scheduler-service.ts +0 -86
  67. package/src/services/schema-service.ts +0 -33
  68. package/src/services/scoped-secret-service.test.ts +0 -74
  69. package/src/services/scoped-secret-service.ts +0 -41
  70. package/src/services/secret-service.ts +0 -38
  71. package/src/services/trigger-service.ts +0 -17
  72. package/src/services/typed-secret-service.test.ts +0 -93
  73. package/src/services/typed-secret-service.ts +0 -70
  74. package/src/services/typed-variables-service.test.ts +0 -73
  75. package/src/services/typed-variables-service.ts +0 -81
  76. package/src/services/user-session-service.test.ts +0 -113
  77. package/src/services/user-session-service.ts +0 -86
  78. package/src/services/variables-service.ts +0 -11
  79. package/src/services/workflow-service.ts +0 -95
  80. package/src/testing/index.ts +0 -2
  81. package/src/testing/service-tests.ts +0 -873
  82. package/src/time-utils.test.ts +0 -56
  83. package/src/time-utils.ts +0 -107
  84. package/src/types/core.types.ts +0 -478
  85. package/src/types/state.types.ts +0 -188
  86. package/src/utils/hash.test.ts +0 -68
  87. package/src/utils/hash.ts +0 -26
  88. package/src/utils.test.ts +0 -350
  89. package/src/utils.ts +0 -129
  90. package/src/version.test.ts +0 -80
  91. package/src/version.ts +0 -25
  92. package/src/wirings/ai-agent/agent-dynamic-workflow.ts +0 -469
  93. package/src/wirings/ai-agent/ai-agent-helpers.test.ts +0 -152
  94. package/src/wirings/ai-agent/ai-agent-helpers.ts +0 -76
  95. package/src/wirings/ai-agent/ai-agent-memory.ts +0 -310
  96. package/src/wirings/ai-agent/ai-agent-model-config.test.ts +0 -115
  97. package/src/wirings/ai-agent/ai-agent-model-config.ts +0 -43
  98. package/src/wirings/ai-agent/ai-agent-prepare.ts +0 -636
  99. package/src/wirings/ai-agent/ai-agent-registry.test.ts +0 -37
  100. package/src/wirings/ai-agent/ai-agent-registry.ts +0 -82
  101. package/src/wirings/ai-agent/ai-agent-runner.test.ts +0 -319
  102. package/src/wirings/ai-agent/ai-agent-runner.ts +0 -773
  103. package/src/wirings/ai-agent/ai-agent-stream.test.ts +0 -859
  104. package/src/wirings/ai-agent/ai-agent-stream.ts +0 -1153
  105. package/src/wirings/ai-agent/ai-agent.types.ts +0 -382
  106. package/src/wirings/ai-agent/index.ts +0 -37
  107. package/src/wirings/channel/channel-common.ts +0 -90
  108. package/src/wirings/channel/channel-handler.ts +0 -250
  109. package/src/wirings/channel/channel-middleware-runner.ts +0 -120
  110. package/src/wirings/channel/channel-runner.ts +0 -166
  111. package/src/wirings/channel/channel-store.ts +0 -29
  112. package/src/wirings/channel/channel.types.ts +0 -172
  113. package/src/wirings/channel/define-channel-routes.ts +0 -25
  114. package/src/wirings/channel/eventhub-service.ts +0 -34
  115. package/src/wirings/channel/eventhub-store.ts +0 -13
  116. package/src/wirings/channel/index.ts +0 -24
  117. package/src/wirings/channel/local/index.ts +0 -3
  118. package/src/wirings/channel/local/local-channel-handler.ts +0 -81
  119. package/src/wirings/channel/local/local-channel-runner.test.ts +0 -215
  120. package/src/wirings/channel/local/local-channel-runner.ts +0 -210
  121. package/src/wirings/channel/local/local-eventhub-service.test.ts +0 -95
  122. package/src/wirings/channel/local/local-eventhub-service.ts +0 -101
  123. package/src/wirings/channel/log-channels.ts +0 -20
  124. package/src/wirings/channel/pikku-abstract-channel-handler.test.ts +0 -54
  125. package/src/wirings/channel/pikku-abstract-channel-handler.ts +0 -45
  126. package/src/wirings/channel/serverless/index.ts +0 -5
  127. package/src/wirings/channel/serverless/serverless-channel-runner.ts +0 -289
  128. package/src/wirings/cli/channel/cli-channel-runner.ts +0 -136
  129. package/src/wirings/cli/channel/index.ts +0 -1
  130. package/src/wirings/cli/cli-runner.test.ts +0 -403
  131. package/src/wirings/cli/cli-runner.ts +0 -529
  132. package/src/wirings/cli/cli.types.ts +0 -358
  133. package/src/wirings/cli/command-parser.test.ts +0 -445
  134. package/src/wirings/cli/command-parser.ts +0 -504
  135. package/src/wirings/cli/define-cli-commands.ts +0 -24
  136. package/src/wirings/cli/index.ts +0 -19
  137. package/src/wirings/gateway/gateway-runner.test.ts +0 -474
  138. package/src/wirings/gateway/gateway-runner.ts +0 -411
  139. package/src/wirings/gateway/gateway.types.ts +0 -149
  140. package/src/wirings/gateway/index.ts +0 -13
  141. package/src/wirings/http/http-routes.test.ts +0 -322
  142. package/src/wirings/http/http-routes.ts +0 -197
  143. package/src/wirings/http/http-runner.test.ts +0 -144
  144. package/src/wirings/http/http-runner.ts +0 -588
  145. package/src/wirings/http/http.types.ts +0 -369
  146. package/src/wirings/http/index.ts +0 -28
  147. package/src/wirings/http/log-http-routes.ts +0 -22
  148. package/src/wirings/http/pikku-fetch-http-request.test.ts +0 -237
  149. package/src/wirings/http/pikku-fetch-http-request.ts +0 -170
  150. package/src/wirings/http/pikku-fetch-http-response.test.ts +0 -82
  151. package/src/wirings/http/pikku-fetch-http-response.ts +0 -147
  152. package/src/wirings/http/routers/http-router.ts +0 -13
  153. package/src/wirings/http/routers/path-to-regex.test.ts +0 -319
  154. package/src/wirings/http/routers/path-to-regex.ts +0 -126
  155. package/src/wirings/http/web-request.test.ts +0 -236
  156. package/src/wirings/http/web-request.ts +0 -104
  157. package/src/wirings/mcp/index.ts +0 -27
  158. package/src/wirings/mcp/mcp-endpoint-registry.test.ts +0 -389
  159. package/src/wirings/mcp/mcp-endpoint-registry.ts +0 -159
  160. package/src/wirings/mcp/mcp-runner.ts +0 -323
  161. package/src/wirings/mcp/mcp.types.ts +0 -216
  162. package/src/wirings/node/index.ts +0 -2
  163. package/src/wirings/node/node.types.ts +0 -23
  164. package/src/wirings/oauth2/index.ts +0 -3
  165. package/src/wirings/oauth2/oauth2-client.test.ts +0 -929
  166. package/src/wirings/oauth2/oauth2-client.ts +0 -335
  167. package/src/wirings/oauth2/oauth2.types.ts +0 -69
  168. package/src/wirings/oauth2/wire-oauth2-credential.ts +0 -23
  169. package/src/wirings/queue/index.ts +0 -31
  170. package/src/wirings/queue/queue-runner.test.ts +0 -710
  171. package/src/wirings/queue/queue-runner.ts +0 -192
  172. package/src/wirings/queue/queue.types.ts +0 -189
  173. package/src/wirings/queue/register-queue-helper.ts +0 -60
  174. package/src/wirings/queue/validate-worker-config.test.ts +0 -108
  175. package/src/wirings/queue/validate-worker-config.ts +0 -116
  176. package/src/wirings/rpc/index.ts +0 -4
  177. package/src/wirings/rpc/rpc-runner.ts +0 -460
  178. package/src/wirings/rpc/rpc-types.ts +0 -56
  179. package/src/wirings/rpc/wire-addon.ts +0 -21
  180. package/src/wirings/scheduler/index.ts +0 -11
  181. package/src/wirings/scheduler/log-schedulers.ts +0 -20
  182. package/src/wirings/scheduler/scheduler-runner.test.ts +0 -660
  183. package/src/wirings/scheduler/scheduler-runner.ts +0 -133
  184. package/src/wirings/scheduler/scheduler.types.ts +0 -53
  185. package/src/wirings/secret/index.ts +0 -9
  186. package/src/wirings/secret/secret.types.ts +0 -32
  187. package/src/wirings/secret/validate-secret-definitions.test.ts +0 -140
  188. package/src/wirings/secret/validate-secret-definitions.ts +0 -82
  189. package/src/wirings/trigger/index.ts +0 -10
  190. package/src/wirings/trigger/pikku-trigger-service.ts +0 -112
  191. package/src/wirings/trigger/trigger-runner.test.ts +0 -79
  192. package/src/wirings/trigger/trigger-runner.ts +0 -135
  193. package/src/wirings/trigger/trigger.types.ts +0 -178
  194. package/src/wirings/variable/index.ts +0 -8
  195. package/src/wirings/variable/validate-variable-definitions.test.ts +0 -91
  196. package/src/wirings/variable/validate-variable-definitions.ts +0 -69
  197. package/src/wirings/variable/variable.types.ts +0 -22
  198. package/src/wirings/workflow/dsl/index.ts +0 -31
  199. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +0 -320
  200. package/src/wirings/workflow/dsl/workflow-runner.ts +0 -28
  201. package/src/wirings/workflow/graph/graph-node.ts +0 -222
  202. package/src/wirings/workflow/graph/graph-runner.test.ts +0 -487
  203. package/src/wirings/workflow/graph/graph-runner.ts +0 -816
  204. package/src/wirings/workflow/graph/graph-validation.test.ts +0 -170
  205. package/src/wirings/workflow/graph/graph-validation.ts +0 -237
  206. package/src/wirings/workflow/graph/index.ts +0 -19
  207. package/src/wirings/workflow/graph/template.test.ts +0 -49
  208. package/src/wirings/workflow/graph/template.ts +0 -42
  209. package/src/wirings/workflow/graph/wire-workflow-graph.ts +0 -29
  210. package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -104
  211. package/src/wirings/workflow/index.ts +0 -82
  212. package/src/wirings/workflow/pikku-workflow-service.test.ts +0 -200
  213. package/src/wirings/workflow/pikku-workflow-service.ts +0 -1176
  214. package/src/wirings/workflow/workflow-helpers.test.ts +0 -129
  215. package/src/wirings/workflow/workflow-helpers.ts +0 -79
  216. package/src/wirings/workflow/workflow.types.ts +0 -274
  217. package/tsconfig.json +0 -14
  218. package/tsconfig.tsbuildinfo +0 -1
@@ -1,192 +0,0 @@
1
- import type { PikkuWire } from '../../types/core.types.js'
2
- import type { CoreQueueWorker, QueueJob, PikkuQueue } from './queue.types.js'
3
- import type {
4
- CorePikkuFunctionConfig,
5
- CorePikkuFunctionSessionless,
6
- } from '../../function/functions.types.js'
7
- import { getErrorResponse, PikkuError } from '../../errors/error-handler.js'
8
- import { PikkuMissingMetaError } from '../../errors/errors.js'
9
- import {
10
- getSingletonServices,
11
- getCreateWireServices,
12
- pikkuState,
13
- } from '../../pikku-state.js'
14
- import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
15
-
16
- /**
17
- * Error class for queue processor not found
18
- */
19
- class QueueWorkerNotFoundError extends PikkuError {
20
- constructor(name: string) {
21
- super(`Queue processor not found: ${name}`)
22
- }
23
- }
24
-
25
- /**
26
- * Error class for when a queue job is explicitly failed
27
- */
28
- export class QueueJobFailedError extends PikkuError {
29
- constructor(jobId: string, reason?: string) {
30
- super(`Queue job ${jobId} failed${reason ? `: ${reason}` : ''}`)
31
- this.name = 'QueueJobFailedError'
32
- }
33
- }
34
-
35
- /**
36
- * Error class for when a queue job is explicitly discarded
37
- */
38
- export class QueueJobDiscardedError extends PikkuError {
39
- constructor(jobId: string, reason?: string) {
40
- super(`Queue job ${jobId} discarded${reason ? `: ${reason}` : ''}`)
41
- this.name = 'QueueJobDiscardedError'
42
- }
43
- }
44
- /**
45
- * Add a queue processor to the system
46
- */
47
- export const wireQueueWorker = <
48
- InputData = any,
49
- OutputData = any,
50
- PikkuFunctionConfig extends CorePikkuFunctionConfig<
51
- CorePikkuFunctionSessionless<InputData, OutputData>
52
- > = CorePikkuFunctionConfig<
53
- CorePikkuFunctionSessionless<InputData, OutputData>
54
- >,
55
- >(
56
- queueWorker: CoreQueueWorker<PikkuFunctionConfig>
57
- ) => {
58
- // Get processor metadata
59
- const meta = pikkuState(null, 'queue', 'meta')
60
- const processorMeta = meta[queueWorker.name]
61
- if (!processorMeta) {
62
- throw new PikkuMissingMetaError(
63
- `Missing generated metadata for queue worker '${queueWorker.name}'`
64
- )
65
- }
66
-
67
- // Register the function with pikku
68
- addFunction(processorMeta.pikkuFuncId, {
69
- func: queueWorker.func.func,
70
- auth: queueWorker.func.auth,
71
- permissions: queueWorker.func.permissions,
72
- middleware: queueWorker.func.middleware as any,
73
- tags: queueWorker.func.tags,
74
- })
75
-
76
- // Store processor definition in state - runtime adapters will pick this up
77
- const registrations = pikkuState(null, 'queue', 'registrations')
78
- registrations.set(queueWorker.name, queueWorker)
79
- }
80
-
81
- /**
82
- * Get all registered queue processors
83
- */
84
- export function getQueueWorkers(): Map<string, CoreQueueWorker> {
85
- return pikkuState(null, 'queue', 'registrations')
86
- }
87
-
88
- /**
89
- * Stop and remove a queue processor
90
- */
91
- export async function removeQueueWorker(name: string): Promise<void> {
92
- const registrations = pikkuState(null, 'queue', 'registrations')
93
- const registration = registrations.get(name)
94
-
95
- if (!registration) {
96
- throw new QueueWorkerNotFoundError(name)
97
- }
98
-
99
- registrations.delete(name)
100
- }
101
-
102
- /**
103
- * Process a single queue job - this function is called by queue consumers
104
- */
105
- export async function runQueueJob({
106
- job,
107
- updateProgress,
108
- }: {
109
- job: QueueJob
110
- updateProgress?: (progress: number | string | object) => Promise<void>
111
- }): Promise<void> {
112
- const singletonServices = getSingletonServices()
113
- const createWireServices = getCreateWireServices()
114
- const logger = singletonServices.logger
115
-
116
- const meta = pikkuState(null, 'queue', 'meta')
117
- const processorMeta = meta[job.queueName]
118
- if (!processorMeta) {
119
- throw new PikkuMissingMetaError(
120
- `Missing generated metadata for queue worker '${job.queueName}'`
121
- )
122
- }
123
-
124
- // Get the queue worker registration to access middleware
125
- const registrations = pikkuState(null, 'queue', 'registrations')
126
- const queueWorker = registrations.get(job.queueName)
127
- if (!queueWorker) {
128
- throw new Error(`Queue worker registration not found for: ${job.queueName}`)
129
- }
130
-
131
- // Create the queue wire object
132
- const queue: PikkuQueue = {
133
- queueName: job.queueName,
134
- jobId: job.id,
135
- updateProgress:
136
- updateProgress ||
137
- (async (progress: number | string | object) => {
138
- logger.info(`Job ${job.id} progress: ${progress}`)
139
- // Default implementation - just log the progress
140
- }),
141
- fail: async (reason?: string) => {
142
- throw new QueueJobFailedError(job.id, reason)
143
- },
144
- discard: async (reason?: string) => {
145
- throw new QueueJobDiscardedError(job.id, reason)
146
- },
147
- }
148
-
149
- try {
150
- logger.info(`Processing job ${job.id} in queue ${job.queueName}`)
151
-
152
- const wire: PikkuWire = {
153
- queue,
154
- }
155
-
156
- // Execute the pikku function with the job data
157
- const result = await runPikkuFunc(
158
- 'queue',
159
- job.queueName,
160
- processorMeta.pikkuFuncId,
161
- {
162
- singletonServices,
163
- createWireServices,
164
- auth: false,
165
- data: () => job.data,
166
- inheritedMiddleware: processorMeta.middleware,
167
- wireMiddleware: queueWorker.middleware,
168
- tags: queueWorker.tags,
169
- wire,
170
- }
171
- )
172
-
173
- logger.debug(
174
- `Successfully processed job ${job.id} in queue ${job.queueName}`
175
- )
176
-
177
- return result
178
- } catch (error: any) {
179
- logger.error(
180
- `Error processing job ${job.id} in queue ${job.queueName}:`,
181
- error
182
- )
183
-
184
- const errorResponse = getErrorResponse(error)
185
- if (errorResponse != null) {
186
- logger.error('Processed error response:', errorResponse)
187
- }
188
-
189
- // Re-throw the error so the queue service can handle retries/DLQ
190
- throw error
191
- }
192
- }
@@ -1,189 +0,0 @@
1
- import type { CommonWireMeta } from '../../types/core.types.js'
2
- import type { CorePikkuFunctionConfig } from '../../function/functions.types.js'
3
- import type { QueueConfigMapping } from './validate-worker-config.js'
4
-
5
- /**
6
- * Configuration for queue workers - how jobs are processed
7
- */
8
- /**
9
- * Configuration for queue workers - how jobs are processed
10
- */
11
- export interface PikkuWorkerConfig {
12
- /** Optional worker name for identification and monitoring */
13
- name?: string
14
- /** Number of messages to process in batch / in parallel */
15
- batchSize?: number
16
- /** Number of messages to prefetch for efficiency */
17
- prefetch?: number
18
- /** Polling interval for pull-based queues in ms */
19
- pollInterval?: number
20
- /** Message visibility timeout in seconds */
21
- visibilityTimeout?: number
22
- /** Duration of job lock in milliseconds */
23
- lockDuration?: number
24
- /** Number of seconds to wait when queue is empty before polling again */
25
- drainDelay?: number
26
- /** Keep N completed jobs for inspection */
27
- removeOnComplete?: number
28
- /** Keep N failed jobs for inspection */
29
- removeOnFail?: number
30
- /** Maximum number of times a job can be recovered from stalled state */
31
- maxStalledCount?: number
32
- /** Condition to start processor at instance creation */
33
- autorun?: boolean
34
- }
35
-
36
- /**
37
- * Configuration for individual jobs - how jobs behave
38
- */
39
- export interface PikkuJobConfig {
40
- /** Maximum retry attempts for failed jobs */
41
- retryAttempts?: number
42
- /** Initial retry delay in milliseconds */
43
- retryDelay?: number
44
- /** Retry backoff strategy */
45
- retryBackoff?: 'linear' | 'exponential' | 'fixed'
46
- /** Queue for failed messages after max retries */
47
- deadLetterQueue?: string
48
- /** How long to retain completed jobs in seconds */
49
- messageRetention?: number
50
- /** Job priority (higher numbers = higher priority) */
51
- priority?: number
52
- /** Enable FIFO ordering where supported */
53
- fifo?: boolean
54
- /** Job timeout in milliseconds */
55
- timeout?: number
56
- /** Delay before job execution in milliseconds */
57
- delay?: number
58
- }
59
-
60
- /**
61
- * Configuration validation result with warnings and fallbacks
62
- */
63
- export interface ConfigValidationResult {
64
- applied: Partial<PikkuWorkerConfig>
65
- ignored: Partial<PikkuWorkerConfig>
66
- warnings: string[]
67
- fallbacks: { [key: string]: any }
68
- }
69
-
70
- /**
71
- * Queue job representation
72
- */
73
- export type QueueJobStatus =
74
- | 'waiting'
75
- | 'active'
76
- | 'completed'
77
- | 'failed'
78
- | 'delayed'
79
-
80
- export type QueueJobMetadata = {
81
- progress?: number | string | object | undefined | boolean
82
- attemptsMade?: number
83
- maxAttempts?: number
84
- processedAt?: Date
85
- completedAt?: Date
86
- failedAt?: Date
87
- error?: string
88
- createdAt: Date
89
- }
90
-
91
- export interface QueueJob<T = any, R = any> {
92
- id: string
93
- queueName: string
94
- status: () => Promise<QueueJobStatus> | QueueJobStatus
95
- data: T
96
- result?: R
97
- waitForCompletion?: (ttl?: number) => Promise<R>
98
- metadata?: () => Promise<QueueJobMetadata> | QueueJobMetadata
99
- }
100
-
101
- /**
102
- * Job options for queue operations
103
- */
104
- export interface JobOptions {
105
- priority?: number
106
- delay?: number
107
- attempts?: number
108
- backoff?: string | { type: string; delay?: number }
109
- removeOnComplete?: number
110
- removeOnFail?: number
111
- jobId?: string
112
- }
113
-
114
- /**
115
- * Queue provider interface for job publishing operations
116
- */
117
- export interface QueueService {
118
- /** Whether this queue provider supports job results */
119
- readonly supportsResults: boolean
120
-
121
- /** Add a job to the queue with type safety */
122
- add<T>(queueName: string, data: T, options?: JobOptions): Promise<string>
123
-
124
- /** Get job status and result */
125
- getJob<T, R>(queueName: string, jobId: string): Promise<QueueJob<T, R> | null>
126
- }
127
-
128
- /**
129
- * Queue service interface that queue adapters implement
130
- */
131
- export interface QueueWorkers {
132
- /** Service name identifier */
133
- name: string
134
-
135
- /** Whether this queue service supports job results */
136
- supportsResults: boolean
137
-
138
- /** Configuration mapping for validation */
139
- configMappings: QueueConfigMapping
140
-
141
- /** Scan state and register all compatible processors */
142
- registerQueues(): Promise<Record<string, ConfigValidationResult[]>>
143
- }
144
-
145
- /**
146
- * Queue processor metadata
147
- */
148
- export type QueueWorkersMeta = Record<
149
- string,
150
- CommonWireMeta & {
151
- name: string
152
- config?: PikkuWorkerConfig
153
- }
154
- >
155
-
156
- /**
157
- * Core queue processor definition
158
- */
159
- export type CoreQueueWorker<
160
- PikkuFunctionConfig extends CorePikkuFunctionConfig<
161
- any,
162
- any,
163
- any
164
- > = CorePikkuFunctionConfig<any, any, any>,
165
- > = {
166
- name: string
167
- func: PikkuFunctionConfig
168
- config?: PikkuWorkerConfig
169
- errors?: string[]
170
- tags?: string[]
171
- middleware?: PikkuFunctionConfig['middleware']
172
- }
173
-
174
- /**
175
- * Represents a queue wire object for middleware
176
- * Provides information and actions for the current queue job execution
177
- */
178
- export interface PikkuQueue {
179
- /** The name of the queue being processed */
180
- queueName: string
181
- /** The current job ID */
182
- jobId: string
183
- /** Update job progress (0-100 or custom value) */
184
- updateProgress: (progress: number | string | object) => Promise<void>
185
- /** Fail the current job with optional reason */
186
- fail: (reason?: string) => Promise<void>
187
- /** Discard/delete the job without retrying */
188
- discard: (reason?: string) => Promise<void>
189
- }
@@ -1,60 +0,0 @@
1
- import type { ConfigValidationResult, CoreQueueWorker } from './queue.types.js'
2
- import { getQueueWorkers } from './queue-runner.js'
3
- import type { QueueConfigMapping } from './validate-worker-config.js'
4
- import { validateWorkerConfig } from './validate-worker-config.js'
5
- import type { Logger } from '../../services/logger.js'
6
-
7
- /**
8
- * Queue processor registration callback
9
- */
10
- export type QueueRegistrationCallback<T = any> = (
11
- queueName: string,
12
- processor: CoreQueueWorker
13
- ) => Promise<T>
14
-
15
- /**
16
- * Helper function to register queue processors with validation
17
- * This centralizes the common logic for looping over processors and validating configs
18
- *
19
- * @param configMappings - Configuration mapping for the queue implementation
20
- * @param registerCallback - Callback to register each individual queue processor
21
- * @param logger - Optional logger for info/error messages
22
- * @returns Record of validation results by queue name
23
- */
24
- export async function registerQueueWorkers<T = any>(
25
- configMappings: QueueConfigMapping,
26
- logger: Logger,
27
- registerCallback: QueueRegistrationCallback<T>
28
- ): Promise<Record<string, ConfigValidationResult[]>> {
29
- const configValidation: Record<string, ConfigValidationResult[]> = {}
30
- const queueWorkers = getQueueWorkers()
31
-
32
- for (const [queueName, processor] of queueWorkers) {
33
- logger?.info(`Registering queue processor: ${queueName}`)
34
- // Validate the processor configuration
35
- const validationResult = validateWorkerConfig(
36
- configMappings,
37
- processor.config
38
- )
39
-
40
- // Store validation results
41
- configValidation[queueName] = configValidation[queueName] || []
42
- configValidation[queueName].push(validationResult)
43
-
44
- if (validationResult.warnings.length > 0) {
45
- logger?.warn(
46
- `Configuration warnings for queue ${queueName}:`,
47
- validationResult.warnings
48
- )
49
- }
50
-
51
- try {
52
- await registerCallback(queueName, processor)
53
- logger?.info(`Successfully registered queue processor: ${queueName}`)
54
- } catch (error) {
55
- logger?.error(`Failed to register queue processor ${queueName}:`, error)
56
- }
57
- }
58
-
59
- return configValidation
60
- }
@@ -1,108 +0,0 @@
1
- import { describe, test } from 'node:test'
2
- import assert from 'node:assert'
3
- import { validateWorkerConfig } from './validate-worker-config.js'
4
- import type { QueueConfigMapping } from './validate-worker-config.js'
5
-
6
- const createTestMapping = (): QueueConfigMapping => ({
7
- supported: {
8
- concurrency: {
9
- queueProperty: 'concurrency',
10
- description: 'Number of concurrent workers',
11
- },
12
- maxRetries: {
13
- queueProperty: 'maxRetries',
14
- description: 'Maximum retry attempts',
15
- },
16
- },
17
- unsupported: {
18
- rateLimitMax: {
19
- reason: 'Not supported',
20
- explanation: 'This queue does not support rate limiting',
21
- },
22
- },
23
- fallbacks: {
24
- retryDelay: {
25
- reason: 'Partial support',
26
- explanation: 'Uses fixed delay instead of exponential',
27
- fallbackValue: '1000ms fixed',
28
- },
29
- },
30
- })
31
-
32
- describe('validateWorkerConfig', () => {
33
- test('should return empty results for empty config', () => {
34
- const mapping = createTestMapping()
35
- const result = validateWorkerConfig(mapping, {})
36
- assert.deepStrictEqual(result.applied, {})
37
- assert.deepStrictEqual(result.ignored, {})
38
- assert.deepStrictEqual(result.warnings, [])
39
- assert.deepStrictEqual(result.fallbacks, {})
40
- })
41
-
42
- test('should return empty results for undefined config', () => {
43
- const mapping = createTestMapping()
44
- const result = validateWorkerConfig(mapping)
45
- assert.deepStrictEqual(result.applied, {})
46
- assert.deepStrictEqual(result.ignored, {})
47
- })
48
-
49
- test('should apply supported configurations', () => {
50
- const mapping = createTestMapping()
51
- const result = validateWorkerConfig(mapping, { concurrency: 5 } as any)
52
- assert.deepStrictEqual(result.applied, { concurrency: 5 })
53
- assert.deepStrictEqual(result.ignored, {})
54
- assert.strictEqual(result.warnings.length, 0)
55
- })
56
-
57
- test('should ignore unsupported configurations with warning', () => {
58
- const mapping = createTestMapping()
59
- const result = validateWorkerConfig(mapping, { rateLimitMax: 100 } as any)
60
- assert.deepStrictEqual(result.ignored, { rateLimitMax: 100 })
61
- assert.strictEqual(result.warnings.length, 1)
62
- assert.ok(result.warnings[0].includes('Not supported'))
63
- })
64
-
65
- test('should handle fallback configurations', () => {
66
- const mapping = createTestMapping()
67
- const result = validateWorkerConfig(mapping, { retryDelay: 2000 } as any)
68
- assert.deepStrictEqual(result.applied, { retryDelay: 2000 })
69
- assert.deepStrictEqual(result.fallbacks, { retryDelay: '1000ms fixed' })
70
- assert.strictEqual(result.warnings.length, 1)
71
- assert.ok(result.warnings[0].includes('Partial support'))
72
- })
73
-
74
- test('should warn about unknown configurations', () => {
75
- const mapping = createTestMapping()
76
- const result = validateWorkerConfig(mapping, {
77
- unknownOption: 'val',
78
- } as any)
79
- assert.deepStrictEqual(result.ignored, { unknownOption: 'val' })
80
- assert.strictEqual(result.warnings.length, 1)
81
- assert.ok(result.warnings[0].includes('Unknown configuration'))
82
- })
83
-
84
- test('should skip undefined values', () => {
85
- const mapping = createTestMapping()
86
- const result = validateWorkerConfig(mapping, {
87
- concurrency: undefined,
88
- } as any)
89
- assert.deepStrictEqual(result.applied, {})
90
- })
91
-
92
- test('should handle mixed supported and unsupported configs', () => {
93
- const mapping = createTestMapping()
94
- const result = validateWorkerConfig(mapping, {
95
- concurrency: 3,
96
- maxRetries: 5,
97
- rateLimitMax: 100,
98
- retryDelay: 1000,
99
- } as any)
100
- assert.deepStrictEqual(result.applied, {
101
- concurrency: 3,
102
- maxRetries: 5,
103
- retryDelay: 1000,
104
- })
105
- assert.deepStrictEqual(result.ignored, { rateLimitMax: 100 })
106
- assert.strictEqual(result.warnings.length, 2)
107
- })
108
- })
@@ -1,116 +0,0 @@
1
- import type {
2
- PikkuWorkerConfig,
3
- ConfigValidationResult,
4
- } from './queue.types.js'
5
-
6
- /**
7
- * Configuration mapping structure for queue implementations
8
- */
9
- export interface QueueConfigMapping {
10
- /** Configurations that are directly supported */
11
- supported: Partial<
12
- Record<
13
- keyof PikkuWorkerConfig,
14
- {
15
- /** The property name in the underlying queue system */
16
- queueProperty?: string
17
- /** Optional transform function for the value */
18
- transform?: (value: any) => any
19
- /** Description of what this configuration does */
20
- description: string
21
- }
22
- >
23
- >
24
-
25
- /** Configurations that are not supported */
26
- unsupported: Partial<
27
- Record<
28
- keyof PikkuWorkerConfig,
29
- {
30
- /** Why this configuration is not supported */
31
- reason: string
32
- /** Detailed explanation of what the queue system does instead */
33
- explanation: string
34
- }
35
- >
36
- >
37
-
38
- /** Configurations that have partial support or workarounds */
39
- fallbacks: Partial<
40
- Record<
41
- keyof PikkuWorkerConfig,
42
- {
43
- /** Why this configuration uses a fallback */
44
- reason: string
45
- /** Detailed explanation of the fallback behavior */
46
- explanation: string
47
- /** The fallback value or description */
48
- fallbackValue: string
49
- }
50
- >
51
- >
52
- }
53
-
54
- /**
55
- * Validates worker configuration using a mapping table
56
- * This provides a flexible, maintainable way to validate configurations
57
- * across different queue implementations
58
- *
59
- * @param config - The worker configuration to validate
60
- * @param configMapping - The mapping table defining supported/unsupported configurations
61
- * @returns Validation result with applied, ignored, warnings, and fallbacks
62
- */
63
- export function validateWorkerConfig(
64
- configMapping: QueueConfigMapping,
65
- config: PikkuWorkerConfig = {}
66
- ): ConfigValidationResult {
67
- const applied: Partial<PikkuWorkerConfig> = {}
68
- const ignored: Partial<PikkuWorkerConfig> = {}
69
- const warnings: string[] = []
70
- const fallbacks: { [key: string]: any } = {}
71
-
72
- // Process each configuration property
73
- for (const [key, value] of Object.entries(config)) {
74
- if (value === undefined) continue
75
-
76
- const configKey = key as keyof PikkuWorkerConfig
77
-
78
- // Check if it's a supported configuration
79
- if (configKey in configMapping.supported) {
80
- applied[configKey] = value
81
- continue
82
- }
83
-
84
- // Check if it's a fallback configuration
85
- if (configKey in configMapping.fallbacks) {
86
- const fallbackMapping = configMapping.fallbacks[configKey]!
87
- applied[configKey] = value
88
- fallbacks[key] = fallbackMapping.fallbackValue
89
- warnings.push(
90
- `${key}: ${fallbackMapping.reason}. ${fallbackMapping.explanation}`
91
- )
92
- continue
93
- }
94
-
95
- // Check if it's an unsupported configuration
96
- if (configKey in configMapping.unsupported) {
97
- ignored[configKey] = value
98
- const mapping = configMapping.unsupported[configKey]!
99
- warnings.push(`${key}: ${mapping.reason}. ${mapping.explanation}`)
100
- continue
101
- }
102
-
103
- // Unknown configuration
104
- ignored[configKey] = value
105
- warnings.push(
106
- `${key}: Unknown configuration option for this queue implementation`
107
- )
108
- }
109
-
110
- return {
111
- applied,
112
- ignored,
113
- warnings,
114
- fallbacks,
115
- }
116
- }
@@ -1,4 +0,0 @@
1
- export { PikkuRPCService, rpcService, RPCNotFoundError } from './rpc-runner.js'
2
- export type { PikkuRPC, RPCMeta } from './rpc-types.js'
3
- export { wireAddon } from './wire-addon.js'
4
- export type { WireAddonConfig } from './wire-addon.js'