@pikku/core 0.9.11 → 0.10.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.
- package/CHANGELOG.md +14 -0
- package/dist/errors/errors.d.ts +2 -0
- package/dist/errors/errors.js +6 -0
- package/dist/function/function-runner.d.ts +15 -9
- package/dist/function/function-runner.js +55 -37
- package/dist/function/functions.types.d.ts +67 -1
- package/dist/function/functions.types.js +43 -1
- package/dist/index.d.ts +2 -6
- package/dist/index.js +2 -6
- package/dist/middleware/auth-apikey.d.ts +19 -11
- package/dist/middleware/auth-apikey.js +33 -33
- package/dist/middleware/auth-bearer.d.ts +34 -7
- package/dist/middleware/auth-bearer.js +53 -36
- package/dist/middleware/auth-cookie.d.ts +30 -12
- package/dist/middleware/auth-cookie.js +51 -43
- package/dist/middleware/timeout.d.ts +6 -2
- package/dist/middleware/timeout.js +7 -9
- package/dist/middleware-runner.d.ts +46 -43
- package/dist/middleware-runner.js +100 -69
- package/dist/permissions.d.ts +82 -20
- package/dist/permissions.js +176 -62
- package/dist/pikku-state.d.ts +46 -1
- package/dist/pikku-state.js +16 -1
- package/dist/services/content-service.d.ts +2 -3
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.js +0 -1
- package/dist/services/local-content.d.ts +2 -4
- package/dist/types/core.types.d.ts +110 -4
- package/dist/types/core.types.js +44 -1
- package/dist/utils.d.ts +1 -1
- package/dist/wirings/channel/channel-handler.d.ts +2 -2
- package/dist/wirings/channel/channel-handler.js +16 -12
- package/dist/wirings/channel/channel-runner.d.ts +2 -2
- package/dist/wirings/channel/channel-runner.js +6 -24
- package/dist/wirings/channel/channel.types.d.ts +15 -14
- package/dist/wirings/channel/local/local-channel-runner.js +12 -12
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +7 -8
- package/dist/wirings/cli/channel/cli-channel-runner.d.ts +12 -0
- package/dist/wirings/cli/channel/cli-channel-runner.js +83 -0
- package/dist/wirings/cli/channel/index.d.ts +1 -0
- package/dist/wirings/cli/channel/index.js +1 -0
- package/dist/wirings/cli/cli-runner.d.ts +42 -0
- package/dist/wirings/cli/cli-runner.js +352 -0
- package/dist/wirings/cli/cli.types.d.ts +204 -0
- package/dist/wirings/cli/cli.types.js +1 -0
- package/dist/wirings/cli/command-parser.d.ts +19 -0
- package/dist/wirings/cli/command-parser.js +403 -0
- package/dist/wirings/cli/index.d.ts +5 -0
- package/dist/wirings/cli/index.js +5 -0
- package/dist/wirings/http/http-runner.d.ts +59 -10
- package/dist/wirings/http/http-runner.js +138 -131
- package/dist/wirings/http/http.types.d.ts +11 -10
- package/dist/wirings/http/index.d.ts +1 -1
- package/dist/wirings/http/index.js +1 -1
- package/dist/wirings/http/pikku-fetch-http-response.js +3 -1
- package/dist/wirings/http/routers/http-router.d.ts +0 -2
- package/dist/wirings/http/routers/path-to-regex.d.ts +1 -1
- package/dist/wirings/http/routers/path-to-regex.js +5 -34
- package/dist/wirings/mcp/mcp-endpoint-registry.d.ts +1 -1
- package/dist/wirings/mcp/mcp-runner.d.ts +4 -5
- package/dist/wirings/mcp/mcp-runner.js +32 -34
- package/dist/wirings/mcp/mcp.types.d.ts +38 -14
- package/dist/wirings/queue/queue-runner.d.ts +2 -2
- package/dist/wirings/queue/queue-runner.js +25 -27
- package/dist/wirings/queue/queue.types.d.ts +6 -5
- 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 +6 -18
- package/dist/wirings/rpc/rpc-runner.js +13 -8
- package/dist/wirings/scheduler/scheduler-runner.d.ts +2 -2
- package/dist/wirings/scheduler/scheduler-runner.js +38 -35
- package/dist/wirings/scheduler/scheduler.types.d.ts +5 -4
- package/package.json +9 -7
- package/src/errors/errors.ts +6 -0
- package/src/factory-functions.test.ts +60 -1
- package/src/function/function-runner.test.ts +81 -26
- package/src/function/function-runner.ts +89 -57
- package/src/function/functions.types.ts +85 -2
- package/src/index.ts +6 -19
- package/src/middleware/auth-apikey.ts +42 -57
- package/src/middleware/auth-bearer.ts +66 -49
- package/src/middleware/auth-cookie.ts +63 -82
- package/src/middleware/timeout.ts +10 -14
- package/src/middleware-runner.test.ts +24 -16
- package/src/middleware-runner.ts +115 -87
- package/src/permissions.test.ts +26 -27
- package/src/permissions.ts +216 -104
- package/src/pikku-state.ts +79 -2
- package/src/services/content-service.ts +5 -4
- package/src/services/index.ts +0 -1
- package/src/services/local-content.ts +9 -4
- package/src/types/core.types.ts +143 -5
- package/src/utils.ts +1 -1
- package/src/wirings/channel/channel-handler.ts +18 -21
- package/src/wirings/channel/channel-runner.ts +19 -32
- package/src/wirings/channel/channel.types.ts +29 -16
- package/src/wirings/channel/local/local-channel-runner.ts +25 -15
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +15 -17
- package/src/wirings/cli/channel/cli-channel-runner.ts +123 -0
- package/src/wirings/cli/channel/index.ts +1 -0
- package/src/wirings/cli/cli-runner.test.ts +403 -0
- package/src/wirings/cli/cli-runner.ts +539 -0
- package/src/wirings/cli/cli.types.ts +350 -0
- package/src/wirings/cli/command-parser.test.ts +445 -0
- package/src/wirings/cli/command-parser.ts +504 -0
- package/src/wirings/cli/index.ts +13 -0
- package/src/wirings/http/http-runner.test.ts +8 -7
- package/src/wirings/http/http-runner.ts +165 -158
- package/src/wirings/http/http.types.ts +58 -11
- package/src/wirings/http/index.ts +7 -1
- package/src/wirings/http/pikku-fetch-http-response.ts +3 -1
- package/src/wirings/http/routers/http-router.ts +0 -2
- package/src/wirings/http/routers/path-to-regex.test.ts +4 -5
- package/src/wirings/http/routers/path-to-regex.ts +6 -43
- package/src/wirings/mcp/mcp-endpoint-registry.ts +1 -1
- package/src/wirings/mcp/mcp-runner.ts +58 -55
- package/src/wirings/mcp/mcp.types.ts +65 -14
- package/src/wirings/queue/queue-runner.ts +44 -47
- package/src/wirings/queue/queue.types.ts +10 -6
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +27 -9
- package/src/wirings/scheduler/scheduler-runner.ts +58 -56
- package/src/wirings/scheduler/scheduler.types.ts +10 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CoreServices,
|
|
3
|
+
PikkuInteraction,
|
|
4
|
+
PikkuWiringTypes,
|
|
5
|
+
} from '../../types/core.types.js'
|
|
2
6
|
import { runPikkuFunc } from '../../function/function-runner.js'
|
|
3
7
|
import { pikkuState } from '../../pikku-state.js'
|
|
4
8
|
import { ForbiddenError } from '../../errors/errors.js'
|
|
9
|
+
import { PikkuRPC } from './rpc-types.js'
|
|
5
10
|
|
|
6
11
|
// Type for the RPC service configuration
|
|
7
12
|
type RPCServiceConfig = {
|
|
@@ -21,8 +26,10 @@ const getPikkuFunctionName = (rpcName: string): string => {
|
|
|
21
26
|
class ContextAwareRPCService {
|
|
22
27
|
constructor(
|
|
23
28
|
private services: CoreServices,
|
|
29
|
+
private interaction: PikkuInteraction,
|
|
24
30
|
private options: {
|
|
25
31
|
coerceDataFromSchema?: boolean
|
|
32
|
+
requiresAuth?: boolean
|
|
26
33
|
}
|
|
27
34
|
) {}
|
|
28
35
|
|
|
@@ -41,7 +48,6 @@ class ContextAwareRPCService {
|
|
|
41
48
|
funcName: string,
|
|
42
49
|
data: In
|
|
43
50
|
): Promise<Out> {
|
|
44
|
-
const session = await this.services.userSession?.get()
|
|
45
51
|
const rpcDepth = this.services.rpc?.depth || 0
|
|
46
52
|
const pikkuFuncName = getPikkuFunctionName(funcName)
|
|
47
53
|
return runPikkuFunc<In, Out>(
|
|
@@ -49,6 +55,8 @@ class ContextAwareRPCService {
|
|
|
49
55
|
pikkuFuncName,
|
|
50
56
|
pikkuFuncName,
|
|
51
57
|
{
|
|
58
|
+
auth: this.options.requiresAuth,
|
|
59
|
+
singletonServices: this.services,
|
|
52
60
|
getAllServices: () => {
|
|
53
61
|
this.services.rpc = this.services.rpc
|
|
54
62
|
? ({
|
|
@@ -59,16 +67,20 @@ class ContextAwareRPCService {
|
|
|
59
67
|
: undefined
|
|
60
68
|
return this.services
|
|
61
69
|
},
|
|
62
|
-
data,
|
|
63
|
-
|
|
70
|
+
data: () => data,
|
|
71
|
+
userSession: this.services.userSession,
|
|
64
72
|
coerceDataFromSchema: this.options.coerceDataFromSchema,
|
|
73
|
+
interaction: this.interaction,
|
|
65
74
|
}
|
|
66
75
|
)
|
|
67
76
|
}
|
|
68
77
|
}
|
|
69
78
|
|
|
70
79
|
// RPC Service class for the global interface
|
|
71
|
-
export class PikkuRPCService
|
|
80
|
+
export class PikkuRPCService<
|
|
81
|
+
Services extends CoreServices,
|
|
82
|
+
TypedRPC = PikkuRPC,
|
|
83
|
+
> {
|
|
72
84
|
private config?: RPCServiceConfig
|
|
73
85
|
|
|
74
86
|
// Initialize the RPC service with configuration
|
|
@@ -77,12 +89,18 @@ export class PikkuRPCService {
|
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
// Convenience function for initializing
|
|
80
|
-
injectRPCService(
|
|
92
|
+
injectRPCService(
|
|
93
|
+
services: Services,
|
|
94
|
+
interaction: PikkuInteraction,
|
|
95
|
+
requiresAuth?: boolean | undefined,
|
|
96
|
+
depth: number = 0
|
|
97
|
+
): Services & { rpc: TypedRPC } {
|
|
81
98
|
const serviceCopy = {
|
|
82
|
-
...
|
|
99
|
+
...services,
|
|
83
100
|
}
|
|
84
|
-
const serviceRPC = new ContextAwareRPCService(serviceCopy, {
|
|
101
|
+
const serviceRPC = new ContextAwareRPCService(serviceCopy, interaction, {
|
|
85
102
|
coerceDataFromSchema: this.config?.coerceDataFromSchema,
|
|
103
|
+
requiresAuth,
|
|
86
104
|
})
|
|
87
105
|
serviceCopy.rpc = {
|
|
88
106
|
depth,
|
|
@@ -90,7 +108,7 @@ export class PikkuRPCService {
|
|
|
90
108
|
invoke: serviceRPC.rpc.bind(serviceRPC),
|
|
91
109
|
invokeExposed: serviceRPC.rpc.bind(serviceRPC),
|
|
92
110
|
} as any
|
|
93
|
-
return serviceCopy
|
|
111
|
+
return serviceCopy as Services & { rpc: TypedRPC }
|
|
94
112
|
}
|
|
95
113
|
}
|
|
96
114
|
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
+
PikkuInteraction,
|
|
2
3
|
PikkuWiringTypes,
|
|
3
4
|
type CoreServices,
|
|
4
5
|
type CoreSingletonServices,
|
|
5
6
|
type CoreUserSession,
|
|
6
7
|
type CreateSessionServices,
|
|
7
8
|
} from '../../types/core.types.js'
|
|
8
|
-
import type {
|
|
9
|
-
CoreScheduledTask,
|
|
10
|
-
PikkuScheduledTask,
|
|
11
|
-
} from './scheduler.types.js'
|
|
12
|
-
import type { CorePikkuFunctionSessionless } from '../../function/functions.types.js'
|
|
9
|
+
import type { CoreScheduledTask } from './scheduler.types.js'
|
|
13
10
|
import { getErrorResponse, PikkuError } from '../../errors/error-handler.js'
|
|
14
11
|
import { closeSessionServices } from '../../utils.js'
|
|
15
12
|
import { pikkuState } from '../../pikku-state.js'
|
|
16
13
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
|
|
17
14
|
import { rpcService } from '../rpc/rpc-runner.js'
|
|
18
|
-
import {
|
|
15
|
+
import { PikkuUserSessionService } from '../../services/user-session-service.js'
|
|
16
|
+
import {
|
|
17
|
+
CorePikkuFunctionConfig,
|
|
18
|
+
CorePikkuFunctionSessionless,
|
|
19
|
+
} from '../../function/functions.types.js'
|
|
19
20
|
|
|
20
21
|
export type RunScheduledTasksParams = {
|
|
21
22
|
name: string
|
|
@@ -29,16 +30,25 @@ export type RunScheduledTasksParams = {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
export const wireScheduler = <
|
|
32
|
-
|
|
33
|
+
PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
34
|
+
CorePikkuFunctionSessionless<void, void>
|
|
35
|
+
>,
|
|
33
36
|
>(
|
|
34
|
-
scheduledTask: CoreScheduledTask<
|
|
37
|
+
scheduledTask: CoreScheduledTask<PikkuFunctionConfig>
|
|
35
38
|
) => {
|
|
36
39
|
const meta = pikkuState('scheduler', 'meta')
|
|
37
40
|
const taskMeta = meta[scheduledTask.name]
|
|
38
41
|
if (!taskMeta) {
|
|
39
42
|
throw new Error('Task metadata not found')
|
|
40
43
|
}
|
|
41
|
-
addFunction(taskMeta.pikkuFuncName,
|
|
44
|
+
addFunction(taskMeta.pikkuFuncName, {
|
|
45
|
+
func: scheduledTask.func.func,
|
|
46
|
+
auth: scheduledTask.func.auth,
|
|
47
|
+
permissions: scheduledTask.func.permissions,
|
|
48
|
+
middleware: scheduledTask.func.middleware as any,
|
|
49
|
+
tags: scheduledTask.func.tags,
|
|
50
|
+
docs: scheduledTask.func.docs as any,
|
|
51
|
+
})
|
|
42
52
|
|
|
43
53
|
const tasks = pikkuState('scheduler', 'tasks')
|
|
44
54
|
if (tasks.has(scheduledTask.name)) {
|
|
@@ -72,6 +82,11 @@ export async function runScheduledTask({
|
|
|
72
82
|
const task = pikkuState('scheduler', 'tasks').get(name)
|
|
73
83
|
const meta = pikkuState('scheduler', 'meta')[name]
|
|
74
84
|
|
|
85
|
+
const userSession = new PikkuUserSessionService()
|
|
86
|
+
if (session) {
|
|
87
|
+
userSession.set(session)
|
|
88
|
+
}
|
|
89
|
+
|
|
75
90
|
if (!task) {
|
|
76
91
|
throw new ScheduledTaskNotFoundError(`Scheduled task not found: ${name}`)
|
|
77
92
|
}
|
|
@@ -82,12 +97,14 @@ export async function runScheduledTask({
|
|
|
82
97
|
}
|
|
83
98
|
|
|
84
99
|
// Create the scheduled task interaction object
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
100
|
+
const interaction: PikkuInteraction = {
|
|
101
|
+
scheduledTask: {
|
|
102
|
+
name,
|
|
103
|
+
schedule: task.schedule,
|
|
104
|
+
executionTime: new Date(),
|
|
105
|
+
skip: (reason?: string) => {
|
|
106
|
+
throw new ScheduledTaskSkippedError(name, reason)
|
|
107
|
+
},
|
|
91
108
|
},
|
|
92
109
|
}
|
|
93
110
|
|
|
@@ -96,52 +113,37 @@ export async function runScheduledTask({
|
|
|
96
113
|
`Running schedule task: ${name} | schedule: ${task.schedule}`
|
|
97
114
|
)
|
|
98
115
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const services = await createSessionServices(
|
|
106
|
-
singletonServices,
|
|
107
|
-
{ scheduledTask },
|
|
108
|
-
session
|
|
109
|
-
)
|
|
110
|
-
sessionServices = services
|
|
111
|
-
return rpcService.injectRPCService({
|
|
112
|
-
...singletonServices,
|
|
113
|
-
...services,
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
return singletonServices
|
|
117
|
-
}
|
|
116
|
+
const getAllServices = async () => {
|
|
117
|
+
sessionServices = await createSessionServices?.(
|
|
118
|
+
singletonServices,
|
|
119
|
+
interaction,
|
|
120
|
+
session
|
|
121
|
+
)
|
|
118
122
|
|
|
119
|
-
|
|
120
|
-
PikkuWiringTypes.scheduler,
|
|
121
|
-
meta.name,
|
|
122
|
-
meta.pikkuFuncName,
|
|
123
|
+
return rpcService.injectRPCService(
|
|
123
124
|
{
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
125
|
+
...singletonServices,
|
|
126
|
+
...sessionServices,
|
|
127
|
+
},
|
|
128
|
+
interaction
|
|
129
129
|
)
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
132
|
+
const result = await runPikkuFunc(
|
|
133
|
+
PikkuWiringTypes.scheduler,
|
|
134
|
+
meta.name,
|
|
135
|
+
meta.pikkuFuncName,
|
|
136
|
+
{
|
|
137
|
+
singletonServices,
|
|
138
|
+
getAllServices,
|
|
139
|
+
userSession,
|
|
140
|
+
auth: false,
|
|
141
|
+
data: () => undefined,
|
|
142
|
+
inheritedMiddleware: meta.middleware,
|
|
143
|
+
wireMiddleware: task.middleware,
|
|
144
|
+
tags: task.tags,
|
|
145
|
+
interaction,
|
|
146
|
+
}
|
|
145
147
|
)
|
|
146
148
|
|
|
147
149
|
return result
|
|
@@ -2,8 +2,12 @@ import {
|
|
|
2
2
|
PikkuDocs,
|
|
3
3
|
CoreUserSession,
|
|
4
4
|
CorePikkuMiddleware,
|
|
5
|
+
MiddlewareMetadata,
|
|
5
6
|
} from '../../types/core.types.js'
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
CorePikkuFunctionConfig,
|
|
9
|
+
CorePikkuFunctionSessionless,
|
|
10
|
+
} from '../../function/functions.types.js'
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Represents metadata for scheduled tasks, including title, schedule, and documentation.
|
|
@@ -18,6 +22,7 @@ export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> =
|
|
|
18
22
|
session?: UserSession
|
|
19
23
|
docs?: PikkuDocs
|
|
20
24
|
tags?: string[]
|
|
25
|
+
middleware?: MiddlewareMetadata[] // Pre-resolved middleware chain (tag + explicit)
|
|
21
26
|
}
|
|
22
27
|
>
|
|
23
28
|
|
|
@@ -25,12 +30,14 @@ export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> =
|
|
|
25
30
|
* Represents a core scheduled task.
|
|
26
31
|
*/
|
|
27
32
|
export type CoreScheduledTask<
|
|
28
|
-
|
|
33
|
+
PikkuFunctionConfig = CorePikkuFunctionConfig<
|
|
34
|
+
CorePikkuFunctionSessionless<void, void>
|
|
35
|
+
>,
|
|
29
36
|
PikkuMiddleware = CorePikkuMiddleware<any>,
|
|
30
37
|
> = {
|
|
31
38
|
name: string
|
|
32
39
|
schedule: string
|
|
33
|
-
func:
|
|
40
|
+
func: PikkuFunctionConfig
|
|
34
41
|
docs?: PikkuDocs
|
|
35
42
|
tags?: string[]
|
|
36
43
|
middleware?: PikkuMiddleware[]
|