@pikku/core 0.10.2 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/errors/errors.d.ts +1 -1
- package/dist/errors/errors.js +3 -3
- package/dist/function/function-runner.d.ts +6 -7
- package/dist/function/function-runner.js +35 -16
- package/dist/function/functions.types.d.ts +23 -30
- package/dist/function/functions.types.js +9 -6
- package/dist/handle-error.d.ts +1 -1
- package/dist/handle-error.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/middleware/auth-apikey.d.ts +1 -0
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +1 -0
- package/dist/middleware/auth-bearer.js +3 -3
- package/dist/middleware/auth-cookie.d.ts +1 -0
- package/dist/middleware/auth-cookie.js +5 -5
- package/dist/middleware/timeout.d.ts +1 -0
- package/dist/middleware/timeout.js +3 -2
- package/dist/middleware-runner.d.ts +3 -6
- package/dist/middleware-runner.js +11 -11
- package/dist/permissions.d.ts +6 -6
- package/dist/permissions.js +15 -15
- package/dist/pikku-state.d.ts +7 -2
- package/dist/pikku-state.js +4 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/scheduler-service.d.ts +63 -0
- package/dist/services/scheduler-service.js +6 -0
- package/dist/services/user-session-service.d.ts +7 -3
- package/dist/services/user-session-service.js +8 -1
- package/dist/time-utils.d.ts +14 -0
- package/dist/time-utils.js +62 -0
- package/dist/types/core.types.d.ts +48 -35
- package/dist/types/core.types.js +3 -13
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +3 -3
- package/dist/wirings/channel/channel-common.js +2 -3
- package/dist/wirings/channel/channel-handler.d.ts +3 -2
- package/dist/wirings/channel/channel-handler.js +6 -9
- package/dist/wirings/channel/channel-runner.d.ts +2 -2
- package/dist/wirings/channel/channel.types.d.ts +10 -5
- package/dist/wirings/channel/local/local-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/local/local-channel-runner.js +19 -26
- package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +41 -46
- package/dist/wirings/cli/channel/cli-channel-runner.js +1 -1
- package/dist/wirings/cli/cli-runner.d.ts +5 -5
- package/dist/wirings/cli/cli-runner.js +11 -29
- package/dist/wirings/cli/cli.types.d.ts +15 -11
- package/dist/wirings/http/http-runner.d.ts +6 -6
- package/dist/wirings/http/http-runner.js +25 -39
- package/dist/wirings/http/http.types.d.ts +5 -10
- package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
- package/dist/wirings/mcp/mcp-runner.js +12 -19
- package/dist/wirings/mcp/mcp.types.d.ts +6 -0
- package/dist/wirings/queue/queue-runner.d.ts +3 -3
- package/dist/wirings/queue/queue-runner.js +7 -14
- package/dist/wirings/queue/queue.types.d.ts +4 -13
- package/dist/wirings/rpc/index.d.ts +1 -1
- package/dist/wirings/rpc/index.js +1 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +13 -7
- package/dist/wirings/rpc/rpc-runner.js +50 -26
- package/dist/wirings/rpc/rpc-types.d.ts +1 -0
- package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
- package/dist/wirings/scheduler/scheduler-runner.js +13 -24
- package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
- package/dist/wirings/workflow/index.d.ts +15 -0
- package/dist/wirings/workflow/index.js +14 -0
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +160 -0
- package/dist/wirings/workflow/pikku-workflow-service.js +430 -0
- package/dist/wirings/workflow/workflow-runner.d.ts +34 -0
- package/dist/wirings/workflow/workflow-runner.js +65 -0
- package/dist/wirings/workflow/workflow.types.d.ts +332 -0
- package/dist/wirings/workflow/workflow.types.js +1 -0
- package/package.json +3 -4
- package/src/errors/errors.ts +3 -3
- package/src/factory-functions.test.ts +9 -36
- package/src/function/function-runner.test.ts +57 -68
- package/src/function/function-runner.ts +51 -28
- package/src/function/function-runner.ts.bak +188 -0
- package/src/function/functions.types.ts +69 -51
- package/src/handle-error.ts +1 -1
- package/src/index.ts +2 -0
- package/src/middleware/auth-apikey.test.ts +360 -0
- package/src/middleware/auth-apikey.ts +3 -7
- package/src/middleware/auth-bearer.test.ts +447 -0
- package/src/middleware/auth-bearer.ts +27 -33
- package/src/middleware/auth-cookie.test.ts +525 -0
- package/src/middleware/auth-cookie.ts +6 -6
- package/src/middleware/timeout.ts +4 -2
- package/src/middleware-runner.test.ts +58 -127
- package/src/middleware-runner.ts +13 -15
- package/src/permissions.test.ts +41 -45
- package/src/permissions.ts +21 -20
- package/src/pikku-state.ts +14 -2
- package/src/services/index.ts +1 -0
- package/src/services/scheduler-service.ts +76 -0
- package/src/services/user-session-service.ts +14 -4
- package/src/time-utils.ts +75 -0
- package/src/types/core.types.ts +92 -51
- package/src/utils.ts +4 -4
- package/src/wirings/channel/channel-common.ts +4 -7
- package/src/wirings/channel/channel-handler.ts +16 -22
- package/src/wirings/channel/channel-runner.ts +2 -2
- package/src/wirings/channel/channel.types.ts +14 -11
- package/src/wirings/channel/local/local-channel-runner.test.ts +5 -3
- package/src/wirings/channel/local/local-channel-runner.ts +23 -38
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +51 -77
- package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +7 -7
- package/src/wirings/cli/cli-runner.ts +25 -63
- package/src/wirings/cli/cli.types.ts +22 -16
- package/src/wirings/http/http-runner.test.ts +8 -8
- package/src/wirings/http/http-runner.ts +29 -56
- package/src/wirings/http/http.types.ts +5 -14
- package/src/wirings/mcp/mcp-runner.ts +23 -48
- package/src/wirings/mcp/mcp.types.ts +6 -0
- package/src/wirings/queue/queue-runner.test.ts +641 -0
- package/src/wirings/queue/queue-runner.ts +10 -24
- package/src/wirings/queue/queue.types.ts +5 -15
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +71 -32
- package/src/wirings/rpc/rpc-types.ts +1 -0
- package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
- package/src/wirings/scheduler/scheduler-runner.ts +24 -50
- package/src/wirings/scheduler/scheduler.types.ts +3 -9
- package/src/wirings/workflow/index.ts +43 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +746 -0
- package/src/wirings/workflow/workflow-runner.ts +72 -0
- package/src/wirings/workflow/workflow.types.ts +422 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/services/file-channel-store.d.ts +0 -19
- package/dist/services/file-channel-store.js +0 -69
- package/dist/services/file-eventhub-store.d.ts +0 -17
- package/dist/services/file-eventhub-store.js +0 -71
- package/src/services/file-channel-store.ts +0 -86
- 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, PikkuWire } from '../../types/core.types.js'
|
|
2
2
|
import type { CoreQueueWorker, QueueJob, PikkuQueue } from './queue.types.js'
|
|
3
3
|
import type {
|
|
4
4
|
CorePikkuFunctionConfig,
|
|
@@ -7,10 +7,7 @@ import type {
|
|
|
7
7
|
import { getErrorResponse, PikkuError } from '../../errors/error-handler.js'
|
|
8
8
|
import { pikkuState } from '../../pikku-state.js'
|
|
9
9
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
|
|
10
|
-
import {
|
|
11
|
-
CreateSessionServices,
|
|
12
|
-
PikkuWiringTypes,
|
|
13
|
-
} from '../../types/core.types.js'
|
|
10
|
+
import { CreateWireServices } from '../../types/core.types.js'
|
|
14
11
|
|
|
15
12
|
/**
|
|
16
13
|
* Error class for queue processor not found
|
|
@@ -70,7 +67,6 @@ export const wireQueueWorker = <
|
|
|
70
67
|
permissions: queueWorker.func.permissions,
|
|
71
68
|
middleware: queueWorker.func.middleware as any,
|
|
72
69
|
tags: queueWorker.func.tags,
|
|
73
|
-
docs: queueWorker.func.docs as any,
|
|
74
70
|
})
|
|
75
71
|
|
|
76
72
|
// Store processor definition in state - runtime adapters will pick this up
|
|
@@ -104,12 +100,12 @@ export async function removeQueueWorker(name: string): Promise<void> {
|
|
|
104
100
|
*/
|
|
105
101
|
export async function runQueueJob({
|
|
106
102
|
singletonServices,
|
|
107
|
-
|
|
103
|
+
createWireServices,
|
|
108
104
|
job,
|
|
109
105
|
updateProgress,
|
|
110
106
|
}: {
|
|
111
107
|
singletonServices: CoreServices
|
|
112
|
-
|
|
108
|
+
createWireServices?: CreateWireServices
|
|
113
109
|
job: QueueJob
|
|
114
110
|
updateProgress?: (progress: number | string | object) => Promise<void>
|
|
115
111
|
}): Promise<void> {
|
|
@@ -128,7 +124,7 @@ export async function runQueueJob({
|
|
|
128
124
|
throw new Error(`Queue worker registration not found for: ${job.queueName}`)
|
|
129
125
|
}
|
|
130
126
|
|
|
131
|
-
// Create the queue
|
|
127
|
+
// Create the queue wire object
|
|
132
128
|
const queue: PikkuQueue = {
|
|
133
129
|
queueName: job.queueName,
|
|
134
130
|
jobId: job.id,
|
|
@@ -149,34 +145,24 @@ export async function runQueueJob({
|
|
|
149
145
|
try {
|
|
150
146
|
logger.info(`Processing job ${job.id} in queue ${job.queueName}`)
|
|
151
147
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const sessionServices = await createSessionServices?.(
|
|
155
|
-
singletonServices,
|
|
156
|
-
{ queue },
|
|
157
|
-
undefined
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
return {
|
|
161
|
-
...singletonServices,
|
|
162
|
-
...sessionServices,
|
|
163
|
-
}
|
|
148
|
+
const wire: PikkuWire = {
|
|
149
|
+
queue,
|
|
164
150
|
}
|
|
165
151
|
|
|
166
152
|
// Execute the pikku function with the job data
|
|
167
153
|
const result = await runPikkuFunc(
|
|
168
|
-
|
|
154
|
+
'queue',
|
|
169
155
|
job.queueName,
|
|
170
156
|
processorMeta.pikkuFuncName,
|
|
171
157
|
{
|
|
172
158
|
singletonServices,
|
|
173
|
-
|
|
159
|
+
createWireServices,
|
|
174
160
|
auth: false,
|
|
175
161
|
data: () => job.data,
|
|
176
162
|
inheritedMiddleware: processorMeta.middleware,
|
|
177
163
|
wireMiddleware: queueWorker.middleware,
|
|
178
164
|
tags: queueWorker.tags,
|
|
179
|
-
|
|
165
|
+
wire,
|
|
180
166
|
}
|
|
181
167
|
)
|
|
182
168
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommonWireMeta } from '../../types/core.types.js'
|
|
2
2
|
import { CorePikkuFunctionConfig } from '../../function/functions.types.js'
|
|
3
3
|
import { QueueConfigMapping } from './validate-worker-config.js'
|
|
4
4
|
|
|
@@ -140,25 +140,16 @@ 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
|
|
148
|
+
export type QueueWorkersMeta = Record<
|
|
152
149
|
string,
|
|
153
|
-
{
|
|
154
|
-
pikkuFuncName: string
|
|
155
|
-
schemaName?: string
|
|
150
|
+
CommonWireMeta & {
|
|
156
151
|
queueName: string
|
|
157
|
-
session?: undefined
|
|
158
|
-
docs?: PikkuDocs
|
|
159
|
-
tags?: string[]
|
|
160
152
|
config?: PikkuWorkerConfig
|
|
161
|
-
middleware?: MiddlewareMetadata[] // Pre-resolved middleware chain (tag + explicit)
|
|
162
153
|
}
|
|
163
154
|
>
|
|
164
155
|
|
|
@@ -175,14 +166,13 @@ export type CoreQueueWorker<
|
|
|
175
166
|
queueName: string
|
|
176
167
|
func: PikkuFunctionConfig
|
|
177
168
|
config?: PikkuWorkerConfig
|
|
178
|
-
|
|
179
|
-
session?: undefined
|
|
169
|
+
errors?: string[]
|
|
180
170
|
tags?: string[]
|
|
181
171
|
middleware?: PikkuFunctionConfig['middleware']
|
|
182
172
|
}
|
|
183
173
|
|
|
184
174
|
/**
|
|
185
|
-
* Represents a queue
|
|
175
|
+
* Represents a queue wire object for middleware
|
|
186
176
|
* Provides information and actions for the current queue job execution
|
|
187
177
|
*/
|
|
188
178
|
export interface PikkuQueue {
|
package/src/wirings/rpc/index.ts
CHANGED
|
@@ -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'
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CoreServices,
|
|
3
|
-
PikkuInteraction,
|
|
4
|
-
PikkuWiringTypes,
|
|
5
|
-
} from '../../types/core.types.js'
|
|
1
|
+
import { CoreServices, PikkuWire } from '../../types/core.types.js'
|
|
6
2
|
import { runPikkuFunc } from '../../function/function-runner.js'
|
|
7
3
|
import { pikkuState } from '../../pikku-state.js'
|
|
8
4
|
import { ForbiddenError } from '../../errors/errors.js'
|
|
@@ -26,7 +22,7 @@ const getPikkuFunctionName = (rpcName: string): string => {
|
|
|
26
22
|
export class ContextAwareRPCService {
|
|
27
23
|
constructor(
|
|
28
24
|
private services: CoreServices,
|
|
29
|
-
private
|
|
25
|
+
private wire: PikkuWire,
|
|
30
26
|
private options: {
|
|
31
27
|
coerceDataFromSchema?: boolean
|
|
32
28
|
requiresAuth?: boolean
|
|
@@ -48,32 +44,77 @@ export class ContextAwareRPCService {
|
|
|
48
44
|
funcName: string,
|
|
49
45
|
data: In
|
|
50
46
|
): Promise<Out> {
|
|
51
|
-
const rpcDepth = this.
|
|
52
|
-
const
|
|
47
|
+
const rpcDepth = this.wire.rpc?.depth || 0
|
|
48
|
+
const updatedWire: PikkuWire = {
|
|
49
|
+
...this.wire,
|
|
50
|
+
rpc: this.wire.rpc
|
|
51
|
+
? {
|
|
52
|
+
...this.wire.rpc,
|
|
53
|
+
depth: rpcDepth + 1,
|
|
54
|
+
global: false,
|
|
55
|
+
}
|
|
56
|
+
: undefined,
|
|
57
|
+
}
|
|
58
|
+
return runPikkuFunc<In, Out>(
|
|
59
|
+
'rpc',
|
|
60
|
+
funcName,
|
|
61
|
+
getPikkuFunctionName(funcName),
|
|
62
|
+
{
|
|
63
|
+
auth: this.options.requiresAuth,
|
|
64
|
+
// TODO: this is a hack since services have already been created
|
|
65
|
+
// but is valid since we don't want to keep creating new wire services
|
|
66
|
+
singletonServices: this.services,
|
|
67
|
+
data: () => data,
|
|
68
|
+
coerceDataFromSchema: this.options.coerceDataFromSchema,
|
|
69
|
+
wire: updatedWire,
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public async rpcWithWire<In = any, Out = any>(
|
|
75
|
+
rpcName: string,
|
|
76
|
+
data: In,
|
|
77
|
+
wire: PikkuWire
|
|
78
|
+
): Promise<Out> {
|
|
79
|
+
const rpcDepth = this.wire.rpc?.depth || 0
|
|
80
|
+
const mergedWire: PikkuWire = {
|
|
81
|
+
...this.wire,
|
|
82
|
+
...wire,
|
|
83
|
+
rpc: this.wire.rpc
|
|
84
|
+
? {
|
|
85
|
+
...this.wire.rpc,
|
|
86
|
+
depth: rpcDepth + 1,
|
|
87
|
+
global: false,
|
|
88
|
+
}
|
|
89
|
+
: undefined,
|
|
90
|
+
}
|
|
53
91
|
return runPikkuFunc<In, Out>(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
92
|
+
'rpc',
|
|
93
|
+
rpcName,
|
|
94
|
+
getPikkuFunctionName(rpcName),
|
|
57
95
|
{
|
|
58
96
|
auth: this.options.requiresAuth,
|
|
59
97
|
singletonServices: this.services,
|
|
60
|
-
getAllServices: () => {
|
|
61
|
-
this.services.rpc = this.services.rpc
|
|
62
|
-
? ({
|
|
63
|
-
...this.services.rpc,
|
|
64
|
-
depth: rpcDepth + 1,
|
|
65
|
-
global: false,
|
|
66
|
-
} as any)
|
|
67
|
-
: undefined
|
|
68
|
-
return this.services
|
|
69
|
-
},
|
|
70
98
|
data: () => data,
|
|
71
|
-
userSession: this.services.userSession,
|
|
72
99
|
coerceDataFromSchema: this.options.coerceDataFromSchema,
|
|
73
|
-
|
|
100
|
+
wire: mergedWire,
|
|
74
101
|
}
|
|
75
102
|
)
|
|
76
103
|
}
|
|
104
|
+
|
|
105
|
+
public async startWorkflow<In = any>(
|
|
106
|
+
workflowName: string,
|
|
107
|
+
input: In
|
|
108
|
+
): Promise<{ runId: string }> {
|
|
109
|
+
if (!this.services.workflowService) {
|
|
110
|
+
throw new Error('WorkflowService service not available')
|
|
111
|
+
}
|
|
112
|
+
return this.services.workflowService.startWorkflow(
|
|
113
|
+
workflowName,
|
|
114
|
+
input,
|
|
115
|
+
this
|
|
116
|
+
)
|
|
117
|
+
}
|
|
77
118
|
}
|
|
78
119
|
|
|
79
120
|
// RPC Service class for the global interface
|
|
@@ -89,26 +130,24 @@ export class PikkuRPCService<
|
|
|
89
130
|
}
|
|
90
131
|
|
|
91
132
|
// Convenience function for initializing
|
|
92
|
-
|
|
133
|
+
getContextRPCService(
|
|
93
134
|
services: Services,
|
|
94
|
-
|
|
135
|
+
wire: PikkuWire,
|
|
95
136
|
requiresAuth?: boolean | undefined,
|
|
96
137
|
depth: number = 0
|
|
97
|
-
):
|
|
98
|
-
const
|
|
99
|
-
...services,
|
|
100
|
-
}
|
|
101
|
-
const serviceRPC = new ContextAwareRPCService(serviceCopy, interaction, {
|
|
138
|
+
): TypedRPC {
|
|
139
|
+
const serviceRPC = new ContextAwareRPCService(services, wire, {
|
|
102
140
|
coerceDataFromSchema: this.config?.coerceDataFromSchema,
|
|
103
141
|
requiresAuth,
|
|
104
142
|
})
|
|
105
|
-
|
|
143
|
+
return {
|
|
106
144
|
depth,
|
|
107
145
|
global: false,
|
|
108
146
|
invoke: serviceRPC.rpc.bind(serviceRPC),
|
|
109
147
|
invokeExposed: serviceRPC.rpc.bind(serviceRPC),
|
|
148
|
+
startWorkflow: serviceRPC.startWorkflow.bind(serviceRPC),
|
|
149
|
+
rpcWithWire: serviceRPC.rpcWithWire.bind(serviceRPC),
|
|
110
150
|
} as any
|
|
111
|
-
return serviceCopy as Services & { rpc: TypedRPC }
|
|
112
151
|
}
|
|
113
152
|
}
|
|
114
153
|
|