@pikku/core 0.10.2 → 0.11.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 (65) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/function/functions.types.d.ts +1 -0
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +2 -0
  5. package/dist/middleware/auth-apikey.d.ts +1 -0
  6. package/dist/middleware/auth-bearer.d.ts +1 -0
  7. package/dist/middleware/auth-cookie.d.ts +1 -0
  8. package/dist/middleware/timeout.d.ts +1 -0
  9. package/dist/middleware-runner.js +1 -0
  10. package/dist/permissions.js +1 -0
  11. package/dist/pikku-state.d.ts +7 -2
  12. package/dist/pikku-state.js +4 -0
  13. package/dist/services/index.d.ts +1 -0
  14. package/dist/services/index.js +1 -0
  15. package/dist/services/scheduler-service.d.ts +63 -0
  16. package/dist/services/scheduler-service.js +6 -0
  17. package/dist/time-utils.d.ts +14 -0
  18. package/dist/time-utils.js +62 -0
  19. package/dist/types/core.types.d.ts +24 -2
  20. package/dist/types/core.types.js +1 -0
  21. package/dist/wirings/cli/channel/cli-channel-runner.js +1 -1
  22. package/dist/wirings/cli/cli-runner.js +1 -1
  23. package/dist/wirings/queue/queue-runner.js +6 -3
  24. package/dist/wirings/queue/queue.types.d.ts +1 -3
  25. package/dist/wirings/rpc/index.d.ts +1 -1
  26. package/dist/wirings/rpc/index.js +1 -1
  27. package/dist/wirings/rpc/rpc-runner.d.ts +4 -0
  28. package/dist/wirings/rpc/rpc-runner.js +37 -2
  29. package/dist/wirings/rpc/rpc-types.d.ts +1 -0
  30. package/dist/wirings/workflow/index.d.ts +6 -0
  31. package/dist/wirings/workflow/index.js +6 -0
  32. package/dist/wirings/workflow/pikku-workflow-service.d.ts +152 -0
  33. package/dist/wirings/workflow/pikku-workflow-service.js +448 -0
  34. package/dist/wirings/workflow/workflow-runner.d.ts +35 -0
  35. package/dist/wirings/workflow/workflow-runner.js +68 -0
  36. package/dist/wirings/workflow/workflow.types.d.ts +247 -0
  37. package/dist/wirings/workflow/workflow.types.js +1 -0
  38. package/package.json +2 -3
  39. package/src/function/functions.types.ts +1 -0
  40. package/src/index.ts +2 -0
  41. package/src/middleware-runner.ts +1 -0
  42. package/src/permissions.ts +1 -0
  43. package/src/pikku-state.ts +14 -2
  44. package/src/services/index.ts +1 -0
  45. package/src/services/scheduler-service.ts +76 -0
  46. package/src/time-utils.ts +75 -0
  47. package/src/types/core.types.ts +30 -1
  48. package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
  49. package/src/wirings/cli/cli-runner.ts +1 -1
  50. package/src/wirings/queue/queue-runner.ts +14 -6
  51. package/src/wirings/queue/queue.types.ts +1 -4
  52. package/src/wirings/rpc/index.ts +1 -1
  53. package/src/wirings/rpc/rpc-runner.ts +56 -3
  54. package/src/wirings/rpc/rpc-types.ts +1 -0
  55. package/src/wirings/workflow/index.ts +22 -0
  56. package/src/wirings/workflow/pikku-workflow-service.ts +756 -0
  57. package/src/wirings/workflow/workflow-runner.ts +85 -0
  58. package/src/wirings/workflow/workflow.types.ts +332 -0
  59. package/tsconfig.tsbuildinfo +1 -1
  60. package/dist/services/file-channel-store.d.ts +0 -19
  61. package/dist/services/file-channel-store.js +0 -69
  62. package/dist/services/file-eventhub-store.d.ts +0 -17
  63. package/dist/services/file-eventhub-store.js +0 -71
  64. package/src/services/file-channel-store.ts +0 -86
  65. package/src/services/file-eventhub-store.ts +0 -90
@@ -1,4 +1,4 @@
1
- import type { CoreServices } from '../../types/core.types.js'
1
+ import type { CoreServices, PikkuInteraction } from '../../types/core.types.js'
2
2
  import type { CoreQueueWorker, QueueJob, PikkuQueue } from './queue.types.js'
3
3
  import type {
4
4
  CorePikkuFunctionConfig,
@@ -11,6 +11,7 @@ import {
11
11
  CreateSessionServices,
12
12
  PikkuWiringTypes,
13
13
  } from '../../types/core.types.js'
14
+ import { rpcService } from '../rpc/rpc-runner.js'
14
15
 
15
16
  /**
16
17
  * Error class for queue processor not found
@@ -149,6 +150,7 @@ export async function runQueueJob({
149
150
  try {
150
151
  logger.info(`Processing job ${job.id} in queue ${job.queueName}`)
151
152
 
153
+ const interaction: PikkuInteraction = { queue }
152
154
  // Use provided singleton services
153
155
  const getAllServices = async () => {
154
156
  const sessionServices = await createSessionServices?.(
@@ -157,10 +159,16 @@ export async function runQueueJob({
157
159
  undefined
158
160
  )
159
161
 
160
- return {
161
- ...singletonServices,
162
- ...sessionServices,
163
- }
162
+ const services = rpcService.injectRPCService(
163
+ {
164
+ ...singletonServices,
165
+ ...sessionServices,
166
+ },
167
+ interaction,
168
+ false
169
+ )
170
+
171
+ return services
164
172
  }
165
173
 
166
174
  // Execute the pikku function with the job data
@@ -176,7 +184,7 @@ export async function runQueueJob({
176
184
  inheritedMiddleware: processorMeta.middleware,
177
185
  wireMiddleware: queueWorker.middleware,
178
186
  tags: queueWorker.tags,
179
- interaction: { queue },
187
+ interaction,
180
188
  }
181
189
  )
182
190
 
@@ -140,15 +140,12 @@ export interface QueueWorkers {
140
140
 
141
141
  /** Scan state and register all compatible processors */
142
142
  registerQueues(): Promise<Record<string, ConfigValidationResult[]>>
143
-
144
- /** Close all queues and connections */
145
- close(): Promise<void>
146
143
  }
147
144
 
148
145
  /**
149
146
  * Queue processor metadata
150
147
  */
151
- export type queueWorkersMeta = Record<
148
+ export type QueueWorkersMeta = Record<
152
149
  string,
153
150
  {
154
151
  pikkuFuncName: string
@@ -1,2 +1,2 @@
1
- export { initialize, PikkuRPCService } from './rpc-runner.js'
1
+ export { initialize, PikkuRPCService, rpcService } from './rpc-runner.js'
2
2
  export type { PikkuRPC, RPCMeta } from './rpc-types.js'
@@ -49,11 +49,10 @@ export class ContextAwareRPCService {
49
49
  data: In
50
50
  ): Promise<Out> {
51
51
  const rpcDepth = this.services.rpc?.depth || 0
52
- const pikkuFuncName = getPikkuFunctionName(funcName)
53
52
  return runPikkuFunc<In, Out>(
54
53
  PikkuWiringTypes.rpc,
55
- pikkuFuncName,
56
- pikkuFuncName,
54
+ funcName,
55
+ getPikkuFunctionName(funcName),
57
56
  {
58
57
  auth: this.options.requiresAuth,
59
58
  singletonServices: this.services,
@@ -74,6 +73,58 @@ export class ContextAwareRPCService {
74
73
  }
75
74
  )
76
75
  }
76
+
77
+ public async rpcWithInteraction<In = any, Out = any>(
78
+ funcName: string,
79
+ data: In,
80
+ interaction: PikkuInteraction
81
+ ): Promise<Out> {
82
+ const rpcDepth = this.services.rpc?.depth || 0
83
+ const mergedInteraction = {
84
+ ...this.interaction,
85
+ ...interaction,
86
+ }
87
+ return runPikkuFunc<In, Out>(
88
+ PikkuWiringTypes.rpc,
89
+ funcName,
90
+ getPikkuFunctionName(funcName),
91
+ {
92
+ auth: this.options.requiresAuth,
93
+ singletonServices: this.services,
94
+ getAllServices: () => {
95
+ this.services.rpc = this.services.rpc
96
+ ? ({
97
+ ...this.services.rpc,
98
+ depth: rpcDepth + 1,
99
+ global: false,
100
+ } as any)
101
+ : undefined
102
+ return {
103
+ ...this.services,
104
+ ...mergedInteraction,
105
+ }
106
+ },
107
+ data: () => data,
108
+ userSession: this.services.userSession,
109
+ coerceDataFromSchema: this.options.coerceDataFromSchema,
110
+ interaction: mergedInteraction,
111
+ }
112
+ )
113
+ }
114
+
115
+ public async startWorkflow<In = any>(
116
+ workflowName: string,
117
+ input: In
118
+ ): Promise<{ runId: string }> {
119
+ if (!this.services.workflowService) {
120
+ throw new Error('WorkflowService service not available')
121
+ }
122
+ return this.services.workflowService.startWorkflow(
123
+ workflowName,
124
+ input,
125
+ this
126
+ )
127
+ }
77
128
  }
78
129
 
79
130
  // RPC Service class for the global interface
@@ -107,6 +158,8 @@ export class PikkuRPCService<
107
158
  global: false,
108
159
  invoke: serviceRPC.rpc.bind(serviceRPC),
109
160
  invokeExposed: serviceRPC.rpc.bind(serviceRPC),
161
+ startWorkflow: serviceRPC.startWorkflow.bind(serviceRPC),
162
+ rpcWithInteraction: serviceRPC.rpcWithInteraction.bind(serviceRPC),
110
163
  } as any
111
164
  return serviceCopy as Services & { rpc: TypedRPC }
112
165
  }
@@ -7,6 +7,7 @@ export type PikkuRPC<invoke extends Function = any> = {
7
7
  export type RPCMeta = {
8
8
  pikkuFuncName: string
9
9
  expose: boolean
10
+ internal?: boolean
10
11
  }
11
12
 
12
13
  /**
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Workflow module exports
3
+ */
4
+
5
+ // Types
6
+ export type {
7
+ CoreWorkflow,
8
+ WorkflowStepOptions,
9
+ WorkflowStepMeta,
10
+ PikkuWorkflowInteraction,
11
+ PikkuWorkflow,
12
+ WorkflowsMeta,
13
+ WorkflowRun,
14
+ StepState,
15
+ WorkflowStatus,
16
+ StepStatus,
17
+ } from './workflow.types.js'
18
+
19
+ export { PikkuWorkflowService } from './pikku-workflow-service.js'
20
+
21
+ // Functions
22
+ export { wireWorkflow } from './workflow-runner.js'