@pikku/core 0.9.1 → 0.9.3
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 +25 -0
- package/dist/function/function-runner.d.ts +4 -4
- package/dist/function/function-runner.js +7 -4
- package/dist/function/functions.types.d.ts +6 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/middleware/auth-apikey.d.ts +2 -2
- package/dist/middleware/auth-bearer.d.ts +2 -2
- package/dist/middleware/auth-cookie.d.ts +2 -2
- package/dist/middleware/timeout.d.ts +2 -2
- package/dist/middleware-runner.d.ts +2 -2
- package/dist/pikku-state.d.ts +3 -4
- package/dist/types/core.types.d.ts +14 -11
- package/dist/wirings/channel/channel.types.d.ts +4 -4
- package/dist/wirings/http/http-runner.d.ts +8 -8
- package/dist/wirings/http/http-runner.js +7 -9
- package/dist/wirings/http/http.types.d.ts +10 -10
- package/dist/wirings/mcp/mcp-runner.js +3 -9
- package/dist/wirings/queue/queue-runner.js +1 -3
- package/dist/wirings/queue/queue.types.d.ts +3 -3
- package/dist/wirings/rpc/rpc-runner.js +15 -3
- package/dist/wirings/rpc/rpc-types.d.ts +1 -1
- package/dist/wirings/scheduler/scheduler-runner.js +1 -3
- package/dist/wirings/scheduler/scheduler.types.d.ts +3 -3
- package/package.json +7 -7
- package/src/function/function-runner.ts +16 -8
- package/src/function/functions.types.ts +13 -5
- package/src/index.ts +1 -1
- package/src/middleware/auth-apikey.ts +2 -2
- package/src/middleware/auth-bearer.ts +3 -3
- package/src/middleware/auth-cookie.ts +3 -3
- package/src/middleware/timeout.ts +6 -2
- package/src/middleware-runner.ts +2 -7
- package/src/pikku-state.ts +3 -4
- package/src/types/core.types.ts +21 -24
- package/src/wirings/channel/channel.types.ts +5 -5
- package/src/wirings/http/http-runner.test.ts +2 -2
- package/src/wirings/http/http-runner.ts +12 -14
- package/src/wirings/http/http.types.ts +11 -11
- package/src/wirings/mcp/mcp-runner.ts +3 -9
- package/src/wirings/queue/queue-runner.ts +1 -3
- package/src/wirings/queue/queue.types.ts +3 -3
- package/src/wirings/rpc/rpc-runner.ts +16 -4
- package/src/wirings/rpc/rpc-types.ts +1 -1
- package/src/wirings/scheduler/scheduler-runner.ts +1 -3
- package/src/wirings/scheduler/scheduler.types.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"author": "yasser.fadl@gmail.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"./types": "./dist/types/index.d.ts"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@types/cookie": "^0.
|
|
37
|
+
"@types/cookie": "^1.0.0",
|
|
38
38
|
"@types/uuid": "^10.0.0",
|
|
39
|
-
"cookie": "^1.0.
|
|
39
|
+
"cookie": "^1.0.2",
|
|
40
40
|
"path-to-regexp": "^8.2.0",
|
|
41
|
-
"picoquery": "^2.
|
|
41
|
+
"picoquery": "^2.5.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@types/node": "^
|
|
45
|
-
"tsx": "^4.
|
|
46
|
-
"typescript": "^5.
|
|
44
|
+
"@types/node": "^24.2.1",
|
|
45
|
+
"tsx": "^4.20.4",
|
|
46
|
+
"typescript": "^5.9"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=18"
|
|
@@ -6,17 +6,25 @@ import { coerceTopLevelDataFromSchema, validateSchema } from '../schema.js'
|
|
|
6
6
|
import {
|
|
7
7
|
CoreServices,
|
|
8
8
|
CoreUserSession,
|
|
9
|
-
|
|
9
|
+
CorePikkuMiddleware,
|
|
10
10
|
} from '../types/core.types.js'
|
|
11
11
|
import {
|
|
12
12
|
CorePermissionGroup,
|
|
13
|
+
CorePikkuFunction,
|
|
13
14
|
CorePikkuFunctionConfig,
|
|
15
|
+
CorePikkuFunctionSessionless,
|
|
14
16
|
} from './functions.types.js'
|
|
15
17
|
|
|
16
18
|
export const addFunction = (
|
|
17
19
|
funcName: string,
|
|
18
|
-
funcConfig:
|
|
20
|
+
funcConfig:
|
|
21
|
+
| CorePikkuFunctionConfig<any, any>
|
|
22
|
+
| CorePikkuFunctionSessionless<any, any>
|
|
23
|
+
| CorePikkuFunction<any, any>
|
|
19
24
|
) => {
|
|
25
|
+
if (funcConfig instanceof Function) {
|
|
26
|
+
funcConfig = { func: funcConfig }
|
|
27
|
+
}
|
|
20
28
|
pikkuState('function', 'functions').set(funcName, funcConfig)
|
|
21
29
|
}
|
|
22
30
|
|
|
@@ -47,7 +55,7 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
47
55
|
data: In
|
|
48
56
|
session?: CoreUserSession
|
|
49
57
|
permissions?: CorePermissionGroup
|
|
50
|
-
middleware?:
|
|
58
|
+
middleware?: CorePikkuMiddleware[]
|
|
51
59
|
coerceDataFromSchema?: boolean
|
|
52
60
|
}
|
|
53
61
|
): Promise<Out> => {
|
|
@@ -68,18 +76,18 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
68
76
|
|
|
69
77
|
const allServices = await getAllServices()
|
|
70
78
|
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
79
|
+
const inputSchemaName = funcMeta.inputSchemaName
|
|
80
|
+
if (inputSchemaName) {
|
|
73
81
|
// Validate request data against the defined schema, if any
|
|
74
82
|
await validateSchema(
|
|
75
83
|
allServices.logger,
|
|
76
84
|
allServices.schema,
|
|
77
|
-
|
|
85
|
+
inputSchemaName,
|
|
78
86
|
data
|
|
79
87
|
)
|
|
80
88
|
// Coerce (top level) query string parameters or date objects if specified by the schema
|
|
81
89
|
if (coerceDataFromSchema) {
|
|
82
|
-
coerceTopLevelDataFromSchema(
|
|
90
|
+
coerceTopLevelDataFromSchema(inputSchemaName, data)
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
|
|
@@ -106,7 +114,7 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
106
114
|
}
|
|
107
115
|
|
|
108
116
|
if (transportMiddleware || funcConfig.middleware) {
|
|
109
|
-
return (await runMiddleware<
|
|
117
|
+
return (await runMiddleware<CorePikkuMiddleware>(
|
|
110
118
|
allServices,
|
|
111
119
|
{
|
|
112
120
|
http: allServices.http,
|
|
@@ -3,7 +3,8 @@ import type {
|
|
|
3
3
|
CoreServices,
|
|
4
4
|
CoreSingletonServices,
|
|
5
5
|
CoreUserSession,
|
|
6
|
-
|
|
6
|
+
PikkuDocs,
|
|
7
|
+
CorePikkuMiddleware,
|
|
7
8
|
} from '../types/core.types.js'
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -79,12 +80,19 @@ export type CorePermissionGroup<PikkuPermission = CorePikkuPermission<any>> =
|
|
|
79
80
|
|
|
80
81
|
export type CorePikkuFunctionConfig<
|
|
81
82
|
PikkuFunction extends
|
|
82
|
-
| CorePikkuFunction<any, any>
|
|
83
|
-
| CorePikkuFunctionSessionless<any, any>,
|
|
84
|
-
PikkuPermission extends CorePikkuPermission<
|
|
83
|
+
| CorePikkuFunction<any, any, any, any, any>
|
|
84
|
+
| CorePikkuFunctionSessionless<any, any, any, any, any>,
|
|
85
|
+
PikkuPermission extends CorePikkuPermission<
|
|
86
|
+
any,
|
|
87
|
+
any,
|
|
88
|
+
any
|
|
89
|
+
> = CorePikkuPermission<any>,
|
|
85
90
|
> = {
|
|
91
|
+
name?: string
|
|
92
|
+
expose?: boolean
|
|
86
93
|
func: PikkuFunction
|
|
87
94
|
auth?: boolean
|
|
88
95
|
permissions?: CorePermissionGroup<PikkuPermission>
|
|
89
|
-
middleware?:
|
|
96
|
+
middleware?: CorePikkuMiddleware[]
|
|
97
|
+
docs?: PikkuDocs
|
|
90
98
|
}
|
package/src/index.ts
CHANGED
|
@@ -22,7 +22,7 @@ export * from './time-utils.js'
|
|
|
22
22
|
export * from './utils.js'
|
|
23
23
|
export { pikkuState } from './pikku-state.js'
|
|
24
24
|
export { runMiddleware } from './middleware-runner.js'
|
|
25
|
-
export { wireHTTP,
|
|
25
|
+
export { wireHTTP, addHTTPMiddleware } from './wirings/http/http-runner.js'
|
|
26
26
|
export { wireChannel } from './wirings/channel/channel-runner.js'
|
|
27
27
|
export { wireScheduler } from './wirings/scheduler/scheduler-runner.js'
|
|
28
28
|
export { wireQueueWorker } from './wirings/queue/queue-runner.js'
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
CoreConfig,
|
|
3
3
|
CoreSingletonServices,
|
|
4
4
|
CoreUserSession,
|
|
5
|
-
|
|
5
|
+
CorePikkuMiddleware,
|
|
6
6
|
} from '../types/core.types.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -32,7 +32,7 @@ export const authAPIKey = <
|
|
|
32
32
|
jwt?: false
|
|
33
33
|
}
|
|
34
34
|
)) => {
|
|
35
|
-
const middleware:
|
|
35
|
+
const middleware: CorePikkuMiddleware = async (services, { http }, next) => {
|
|
36
36
|
const { userSession: userSessionService, jwt: jwtService } = services as any
|
|
37
37
|
if (!http?.request || userSessionService.get()) {
|
|
38
38
|
return next()
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
CoreConfig,
|
|
4
4
|
CoreSingletonServices,
|
|
5
5
|
CoreUserSession,
|
|
6
|
-
|
|
6
|
+
CorePikkuMiddleware,
|
|
7
7
|
} from '../types/core.types.js'
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -26,8 +26,8 @@ export const authBearer = <
|
|
|
26
26
|
services: SingletonServices,
|
|
27
27
|
token: string
|
|
28
28
|
) => Promise<UserSession> | UserSession
|
|
29
|
-
} = {}):
|
|
30
|
-
const middleware:
|
|
29
|
+
} = {}): CorePikkuMiddleware => {
|
|
30
|
+
const middleware: CorePikkuMiddleware = async (services, { http }, next) => {
|
|
31
31
|
const { userSession: userSessionService, jwt: jwtService } = services as any
|
|
32
32
|
// Skip if session already exists.
|
|
33
33
|
if (!http?.request || userSessionService.get()) {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
CoreConfig,
|
|
4
4
|
CoreSingletonServices,
|
|
5
5
|
CoreUserSession,
|
|
6
|
-
|
|
6
|
+
CorePikkuMiddleware,
|
|
7
7
|
} from '../types/core.types.js'
|
|
8
8
|
import {
|
|
9
9
|
getRelativeTimeOffsetFromNow,
|
|
@@ -42,8 +42,8 @@ export const authCookie = <
|
|
|
42
42
|
getSessionForCookieValue?: undefined
|
|
43
43
|
jwt: true
|
|
44
44
|
}
|
|
45
|
-
)):
|
|
46
|
-
const middleware:
|
|
45
|
+
)): CorePikkuMiddleware => {
|
|
46
|
+
const middleware: CorePikkuMiddleware = async (services, { http }, next) => {
|
|
47
47
|
const {
|
|
48
48
|
userSession: userSessionService,
|
|
49
49
|
jwt: jwtService,
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { RequestTimeoutError } from '../errors/errors.js'
|
|
2
|
-
import {
|
|
2
|
+
import { CorePikkuMiddleware } from '../types/core.types.js'
|
|
3
3
|
|
|
4
4
|
export const timeout = (timeout: number) => {
|
|
5
|
-
const middleware:
|
|
5
|
+
const middleware: CorePikkuMiddleware = async (
|
|
6
|
+
_services,
|
|
7
|
+
_interaction,
|
|
8
|
+
next
|
|
9
|
+
) => {
|
|
6
10
|
setTimeout(() => {
|
|
7
11
|
throw new RequestTimeoutError()
|
|
8
12
|
}, timeout)
|
package/src/middleware-runner.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { UserSessionService } from './services/user-session-service.js'
|
|
2
2
|
import {
|
|
3
3
|
CoreSingletonServices,
|
|
4
|
-
PikkuFunctionMiddleware,
|
|
5
4
|
PikkuInteraction,
|
|
6
|
-
|
|
5
|
+
CorePikkuMiddleware,
|
|
7
6
|
} from './types/core.types.js'
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -23,11 +22,7 @@ import {
|
|
|
23
22
|
* async () => { return await runMain(); }
|
|
24
23
|
* );
|
|
25
24
|
*/
|
|
26
|
-
export const runMiddleware = async <
|
|
27
|
-
Middleware extends
|
|
28
|
-
| PikkuMiddleware
|
|
29
|
-
| PikkuFunctionMiddleware = PikkuMiddleware,
|
|
30
|
-
>(
|
|
25
|
+
export const runMiddleware = async <Middleware extends CorePikkuMiddleware>(
|
|
31
26
|
services: CoreSingletonServices & {
|
|
32
27
|
userSession?: UserSessionService<any>
|
|
33
28
|
},
|
package/src/pikku-state.ts
CHANGED
|
@@ -4,14 +4,13 @@ import {
|
|
|
4
4
|
HTTPMethod,
|
|
5
5
|
HTTPWiringsMeta,
|
|
6
6
|
} from './wirings/http/http.types.js'
|
|
7
|
-
import { FunctionsMeta,
|
|
7
|
+
import { FunctionsMeta, CorePikkuMiddleware } from './types/core.types.js'
|
|
8
8
|
import {
|
|
9
9
|
CoreScheduledTask,
|
|
10
10
|
ScheduledTasksMeta,
|
|
11
11
|
} from './wirings/scheduler/scheduler.types.js'
|
|
12
12
|
import { ErrorDetails, PikkuError } from './errors/error-handler.js'
|
|
13
13
|
import { CorePikkuFunctionConfig } from './function/functions.types.js'
|
|
14
|
-
import { RPCMeta } from './wirings/rpc/rpc-types.js'
|
|
15
14
|
import {
|
|
16
15
|
queueWorkersMeta,
|
|
17
16
|
CoreQueueWorker,
|
|
@@ -31,7 +30,7 @@ interface PikkuState {
|
|
|
31
30
|
functions: Map<string, CorePikkuFunctionConfig<any, any>>
|
|
32
31
|
}
|
|
33
32
|
rpc: {
|
|
34
|
-
meta: Record<string,
|
|
33
|
+
meta: Record<string, string>
|
|
35
34
|
files: Map<
|
|
36
35
|
string,
|
|
37
36
|
{
|
|
@@ -41,7 +40,7 @@ interface PikkuState {
|
|
|
41
40
|
>
|
|
42
41
|
}
|
|
43
42
|
http: {
|
|
44
|
-
middleware: Array<{ route: string; middleware:
|
|
43
|
+
middleware: Array<{ route: string; middleware: CorePikkuMiddleware[] }>
|
|
45
44
|
routes: Map<HTTPMethod, Map<string, CoreHTTPFunctionWiring<any, any, any>>>
|
|
46
45
|
meta: HTTPWiringsMeta
|
|
47
46
|
}
|
package/src/types/core.types.ts
CHANGED
|
@@ -21,17 +21,28 @@ export interface FunctionServicesMeta {
|
|
|
21
21
|
services: string[]
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export type
|
|
25
|
-
string
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
export type FunctionRuntimeMeta = {
|
|
25
|
+
pikkuFuncName: string
|
|
26
|
+
inputSchemaName: string | null
|
|
27
|
+
outputSchemaName: string | null
|
|
28
|
+
expose?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type FunctionMeta = FunctionRuntimeMeta &
|
|
32
|
+
Partial<{
|
|
33
|
+
name: string
|
|
29
34
|
services: FunctionServicesMeta
|
|
30
|
-
schemaName: string | null
|
|
31
35
|
inputs: string[] | null
|
|
32
36
|
outputs: string[] | null
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
tags: string[]
|
|
38
|
+
docs: PikkuDocs
|
|
39
|
+
isDirectFunction: boolean // true if it's pikkuFunc(fn), false if it's pikkuFunc({ func: fn })
|
|
40
|
+
}>
|
|
41
|
+
|
|
42
|
+
export type FunctionsRuntimeMeta = Record<string, FunctionRuntimeMeta>
|
|
43
|
+
export type FunctionsMeta = Record<string, FunctionMeta>
|
|
44
|
+
|
|
45
|
+
// Optimized runtime metadata with only essential fields
|
|
35
46
|
|
|
36
47
|
export type MakeRequired<T, K extends keyof T> = Omit<T, K> &
|
|
37
48
|
Required<Pick<T, K>>
|
|
@@ -110,21 +121,7 @@ export interface PikkuInteraction {
|
|
|
110
121
|
/**
|
|
111
122
|
* A function that can wrap an interaction and be called before or after
|
|
112
123
|
*/
|
|
113
|
-
export type
|
|
114
|
-
SingletonServices extends CoreSingletonServices = CoreSingletonServices,
|
|
115
|
-
UserSession extends CoreUserSession = CoreUserSession,
|
|
116
|
-
> = (
|
|
117
|
-
services: SingletonServices & {
|
|
118
|
-
userSession?: UserSessionService<UserSession>
|
|
119
|
-
},
|
|
120
|
-
interactions: PikkuInteraction,
|
|
121
|
-
next: () => Promise<void>
|
|
122
|
-
) => Promise<void>
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* A function that can wrap an interaction and be called before or after
|
|
126
|
-
*/
|
|
127
|
-
export type PikkuMiddleware<
|
|
124
|
+
export type CorePikkuMiddleware<
|
|
128
125
|
SingletonServices extends CoreSingletonServices = CoreSingletonServices,
|
|
129
126
|
UserSession extends CoreUserSession = CoreUserSession,
|
|
130
127
|
> = (
|
|
@@ -190,7 +187,7 @@ export type CreateConfig<Config extends CoreConfig> = (
|
|
|
190
187
|
/**
|
|
191
188
|
* Represents the documentation for a route, including summary, description, tags, and errors.
|
|
192
189
|
*/
|
|
193
|
-
export type
|
|
190
|
+
export type PikkuDocs = {
|
|
194
191
|
summary?: string
|
|
195
192
|
description?: string
|
|
196
193
|
tags?: string[]
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
PikkuHTTPResponse,
|
|
6
6
|
} from '../http/http.types.js'
|
|
7
7
|
import {
|
|
8
|
-
|
|
8
|
+
PikkuDocs,
|
|
9
9
|
CoreSingletonServices,
|
|
10
10
|
CreateSessionServices,
|
|
11
|
-
|
|
11
|
+
CorePikkuMiddleware,
|
|
12
12
|
} from '../../types/core.types.js'
|
|
13
13
|
import {
|
|
14
14
|
CorePikkuFunction,
|
|
@@ -34,7 +34,7 @@ export type RunChannelParams<ChannelData> = {
|
|
|
34
34
|
|
|
35
35
|
export interface ChannelMessageMeta {
|
|
36
36
|
pikkuFuncName: string
|
|
37
|
-
docs?:
|
|
37
|
+
docs?: PikkuDocs
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export interface ChannelMeta {
|
|
@@ -48,7 +48,7 @@ export interface ChannelMeta {
|
|
|
48
48
|
disconnect: ChannelMessageMeta | null
|
|
49
49
|
message: ChannelMessageMeta | null
|
|
50
50
|
messageWirings: Record<string, Record<string, ChannelMessageMeta>>
|
|
51
|
-
docs?:
|
|
51
|
+
docs?: PikkuDocs
|
|
52
52
|
tags?: string[]
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -91,7 +91,7 @@ export type CoreChannel<
|
|
|
91
91
|
}
|
|
92
92
|
>
|
|
93
93
|
>
|
|
94
|
-
middleware?:
|
|
94
|
+
middleware?: CorePikkuMiddleware[]
|
|
95
95
|
permissions?: Record<string, PikkuPermission[] | PikkuPermission>
|
|
96
96
|
auth?: boolean
|
|
97
97
|
docs?: Partial<{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test, describe, beforeEach, afterEach } from 'node:test'
|
|
2
2
|
import * as assert from 'assert'
|
|
3
3
|
import { NotFoundError } from '../../errors/errors.js'
|
|
4
|
-
import { JSONValue,
|
|
4
|
+
import { JSONValue, CorePikkuMiddleware } from '../../types/core.types.js'
|
|
5
5
|
import { fetch, wireHTTP } from './http-runner.js'
|
|
6
6
|
import { pikkuState, resetPikkuState } from '../../pikku-state.js'
|
|
7
7
|
import {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '../channel/local/local-channel-runner.test.js'
|
|
11
11
|
import { addFunction } from '../../function/function-runner.js'
|
|
12
12
|
|
|
13
|
-
const sessionMiddleware:
|
|
13
|
+
const sessionMiddleware: CorePikkuMiddleware = async (services, _, next) => {
|
|
14
14
|
services.userSession.set({ userId: 'test' } as any)
|
|
15
15
|
await next()
|
|
16
16
|
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from './http.types.js'
|
|
11
11
|
import {
|
|
12
12
|
CoreUserSession,
|
|
13
|
-
|
|
13
|
+
CorePikkuMiddleware,
|
|
14
14
|
SessionServices,
|
|
15
15
|
} from '../../types/core.types.js'
|
|
16
16
|
import { match } from 'path-to-regexp'
|
|
@@ -40,13 +40,13 @@ import { rpcService } from '../rpc/rpc-runner.js'
|
|
|
40
40
|
* is applied only to that route. Otherwise, if an array is provided, it is treated
|
|
41
41
|
* as global middleware (applied to all routes).
|
|
42
42
|
*
|
|
43
|
-
* @template
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
43
|
+
* @template PikkuMiddleware The middleware type.
|
|
44
|
+
* @param {PikkuMiddleware[] | string} routeOrMiddleware - Either a global middleware array or a route pattern string.
|
|
45
|
+
* @param {PikkuMiddleware[]} [middleware] - The middleware array to apply when a route pattern is specified.
|
|
46
46
|
*/
|
|
47
|
-
export const
|
|
48
|
-
routeOrMiddleware:
|
|
49
|
-
middleware?:
|
|
47
|
+
export const addHTTPMiddleware = <PikkuMiddleware extends CorePikkuMiddleware>(
|
|
48
|
+
routeOrMiddleware: PikkuMiddleware[] | string,
|
|
49
|
+
middleware?: PikkuMiddleware[]
|
|
50
50
|
) => {
|
|
51
51
|
const middlewareStore = pikkuState('http', 'middleware')
|
|
52
52
|
|
|
@@ -90,8 +90,8 @@ export const addMiddleware = <APIMiddleware extends PikkuMiddleware>(
|
|
|
90
90
|
* @template PikkuFunction Type for the route handler function.
|
|
91
91
|
* @template PikkuFunctionSessionless Type for a sessionless handler.
|
|
92
92
|
* @template PikkuPermissionGroup Type representing required permissions.
|
|
93
|
-
* @template
|
|
94
|
-
* @param {CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermission,
|
|
93
|
+
* @template PikkuMiddleware Middleware type to be used with the route.
|
|
94
|
+
* @param {CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware>} httpWiring - The HTTP wiring configuration object.
|
|
95
95
|
*/
|
|
96
96
|
export const wireHTTP = <
|
|
97
97
|
In,
|
|
@@ -100,7 +100,7 @@ export const wireHTTP = <
|
|
|
100
100
|
PikkuFunction,
|
|
101
101
|
PikkuFunctionSessionless,
|
|
102
102
|
PikkuPermissionGroup,
|
|
103
|
-
|
|
103
|
+
PikkuMiddleware,
|
|
104
104
|
>(
|
|
105
105
|
httpWiring: CoreHTTPFunctionWiring<
|
|
106
106
|
In,
|
|
@@ -109,7 +109,7 @@ export const wireHTTP = <
|
|
|
109
109
|
PikkuFunction,
|
|
110
110
|
PikkuFunctionSessionless,
|
|
111
111
|
PikkuPermissionGroup,
|
|
112
|
-
|
|
112
|
+
PikkuMiddleware
|
|
113
113
|
>
|
|
114
114
|
) => {
|
|
115
115
|
const httpMeta = pikkuState('http', 'meta')
|
|
@@ -120,9 +120,7 @@ export const wireHTTP = <
|
|
|
120
120
|
if (!routeMeta) {
|
|
121
121
|
throw new Error('Route metadata not found')
|
|
122
122
|
}
|
|
123
|
-
addFunction(routeMeta.pikkuFuncName,
|
|
124
|
-
func: httpWiring.func,
|
|
125
|
-
})
|
|
123
|
+
addFunction(routeMeta.pikkuFuncName, httpWiring.func as any)
|
|
126
124
|
const routes = pikkuState('http', 'routes')
|
|
127
125
|
if (!routes.has(httpWiring.method)) {
|
|
128
126
|
routes.set(httpWiring.method, new Map())
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { SerializeOptions } from 'cookie'
|
|
2
2
|
import type { PikkuError } from '../../errors/error-handler.js'
|
|
3
3
|
import type {
|
|
4
|
-
|
|
4
|
+
PikkuDocs,
|
|
5
5
|
CoreServices,
|
|
6
6
|
CoreSingletonServices,
|
|
7
7
|
CoreUserSession,
|
|
8
8
|
CreateSessionServices,
|
|
9
|
-
|
|
9
|
+
CorePikkuMiddleware,
|
|
10
10
|
} from '../../types/core.types.js'
|
|
11
11
|
import type {
|
|
12
12
|
CorePikkuFunction,
|
|
@@ -119,7 +119,7 @@ export type CoreHTTPFunctionWiring<
|
|
|
119
119
|
PikkuFunction = CorePikkuFunction<In, Out>,
|
|
120
120
|
PikkuFunctionSessionless = CorePikkuFunctionSessionless<In, Out>,
|
|
121
121
|
PikkuPermission = CorePikkuPermission<In>,
|
|
122
|
-
|
|
122
|
+
PikkuMiddleware = CorePikkuMiddleware,
|
|
123
123
|
> =
|
|
124
124
|
| (CoreHTTPFunction & {
|
|
125
125
|
route: R
|
|
@@ -128,7 +128,7 @@ export type CoreHTTPFunctionWiring<
|
|
|
128
128
|
permissions?: CorePermissionGroup<PikkuPermission>
|
|
129
129
|
auth?: true
|
|
130
130
|
tags?: string[]
|
|
131
|
-
middleware?:
|
|
131
|
+
middleware?: PikkuMiddleware[]
|
|
132
132
|
sse?: undefined
|
|
133
133
|
})
|
|
134
134
|
| (CoreHTTPFunction & {
|
|
@@ -138,7 +138,7 @@ export type CoreHTTPFunctionWiring<
|
|
|
138
138
|
permissions?: undefined
|
|
139
139
|
auth?: false
|
|
140
140
|
tags?: string[]
|
|
141
|
-
middleware?:
|
|
141
|
+
middleware?: PikkuMiddleware[]
|
|
142
142
|
sse?: undefined
|
|
143
143
|
})
|
|
144
144
|
| (CoreHTTPFunction & {
|
|
@@ -149,7 +149,7 @@ export type CoreHTTPFunctionWiring<
|
|
|
149
149
|
auth?: true
|
|
150
150
|
sse?: boolean
|
|
151
151
|
tags?: string[]
|
|
152
|
-
middleware?:
|
|
152
|
+
middleware?: PikkuMiddleware[]
|
|
153
153
|
})
|
|
154
154
|
| (CoreHTTPFunction & {
|
|
155
155
|
route: R
|
|
@@ -159,7 +159,7 @@ export type CoreHTTPFunctionWiring<
|
|
|
159
159
|
auth?: false
|
|
160
160
|
sse?: boolean
|
|
161
161
|
tags?: string[]
|
|
162
|
-
middleware?:
|
|
162
|
+
middleware?: PikkuMiddleware[]
|
|
163
163
|
})
|
|
164
164
|
| (CoreHTTPFunction & {
|
|
165
165
|
route: R
|
|
@@ -169,7 +169,7 @@ export type CoreHTTPFunctionWiring<
|
|
|
169
169
|
auth?: true
|
|
170
170
|
query?: Array<keyof In>
|
|
171
171
|
tags?: string[]
|
|
172
|
-
middleware?:
|
|
172
|
+
middleware?: PikkuMiddleware[]
|
|
173
173
|
sse?: undefined
|
|
174
174
|
})
|
|
175
175
|
| (CoreHTTPFunction & {
|
|
@@ -180,7 +180,7 @@ export type CoreHTTPFunctionWiring<
|
|
|
180
180
|
auth?: false
|
|
181
181
|
query?: Array<keyof In>
|
|
182
182
|
tags?: string[]
|
|
183
|
-
middleware?:
|
|
183
|
+
middleware?: PikkuMiddleware[]
|
|
184
184
|
sse?: undefined
|
|
185
185
|
})
|
|
186
186
|
|
|
@@ -203,7 +203,7 @@ export type HTTPWiringMeta = {
|
|
|
203
203
|
params?: string[]
|
|
204
204
|
query?: string[]
|
|
205
205
|
inputTypes?: HTTPFunctionMetaInputTypes
|
|
206
|
-
docs?:
|
|
206
|
+
docs?: PikkuDocs
|
|
207
207
|
tags?: string[]
|
|
208
208
|
sse?: true
|
|
209
209
|
}
|
|
@@ -217,7 +217,7 @@ export type HTTPFunctionsMeta = Array<{
|
|
|
217
217
|
|
|
218
218
|
export type HTTPWiringMiddleware = {
|
|
219
219
|
route: string
|
|
220
|
-
middleware:
|
|
220
|
+
middleware: CorePikkuMiddleware[]
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
export interface PikkuHTTPRequest<In = unknown> {
|
|
@@ -56,9 +56,7 @@ export const wireMCPResource = <
|
|
|
56
56
|
if (!mcpResourceMeta) {
|
|
57
57
|
throw new Error(`MCP resource metadata not found for '${mcpResource.uri}'`)
|
|
58
58
|
}
|
|
59
|
-
addFunction(mcpResourceMeta.pikkuFuncName,
|
|
60
|
-
func: mcpResource.func,
|
|
61
|
-
})
|
|
59
|
+
addFunction(mcpResourceMeta.pikkuFuncName, mcpResource.func)
|
|
62
60
|
const resources = pikkuState('mcp', 'resources')
|
|
63
61
|
if (resources.has(mcpResource.uri)) {
|
|
64
62
|
throw new Error(`MCP resource already exists: ${mcpResource.uri}`)
|
|
@@ -76,9 +74,7 @@ export const wireMCPTool = <
|
|
|
76
74
|
if (!mcpToolMeta) {
|
|
77
75
|
throw new Error(`MCP tool metadata not found for '${mcpTool.name}'`)
|
|
78
76
|
}
|
|
79
|
-
addFunction(mcpToolMeta.pikkuFuncName,
|
|
80
|
-
func: mcpTool.func,
|
|
81
|
-
})
|
|
77
|
+
addFunction(mcpToolMeta.pikkuFuncName, mcpTool.func as any)
|
|
82
78
|
const tools = pikkuState('mcp', 'tools')
|
|
83
79
|
if (tools.has(mcpTool.name)) {
|
|
84
80
|
throw new Error(`MCP tool already exists: ${mcpTool.name}`)
|
|
@@ -96,9 +92,7 @@ export const wireMCPPrompt = <
|
|
|
96
92
|
if (!mcpPromptMeta) {
|
|
97
93
|
throw new Error(`MCP prompt metadata not found for '${mcpPrompt.name}'`)
|
|
98
94
|
}
|
|
99
|
-
addFunction(mcpPromptMeta.pikkuFuncName,
|
|
100
|
-
func: mcpPrompt.func,
|
|
101
|
-
})
|
|
95
|
+
addFunction(mcpPromptMeta.pikkuFuncName, mcpPrompt.func as any)
|
|
102
96
|
const prompts = pikkuState('mcp', 'prompts')
|
|
103
97
|
if (prompts.has(mcpPrompt.name)) {
|
|
104
98
|
throw new Error(`MCP prompt already exists: ${mcpPrompt.name}`)
|
|
@@ -37,9 +37,7 @@ export const wireQueueWorker = <
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Register the function with pikku
|
|
40
|
-
addFunction(processorMeta.pikkuFuncName,
|
|
41
|
-
func: queueWorker.func,
|
|
42
|
-
})
|
|
40
|
+
addFunction(processorMeta.pikkuFuncName, queueWorker.func)
|
|
43
41
|
|
|
44
42
|
// Store processor definition in state - runtime adapters will pick this up
|
|
45
43
|
const registrations = pikkuState('queue', 'registrations')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PikkuDocs } from '../../types/core.types.js'
|
|
2
2
|
import { CorePikkuFunctionSessionless } from '../../function/functions.types.js'
|
|
3
3
|
import { QueueConfigMapping } from './validate-worker-config.js'
|
|
4
4
|
|
|
@@ -155,7 +155,7 @@ export type queueWorkersMeta = Record<
|
|
|
155
155
|
schemaName?: string
|
|
156
156
|
queueName: string
|
|
157
157
|
session?: undefined
|
|
158
|
-
docs?:
|
|
158
|
+
docs?: PikkuDocs
|
|
159
159
|
tags?: string[]
|
|
160
160
|
config?: PikkuWorkerConfig
|
|
161
161
|
}
|
|
@@ -170,7 +170,7 @@ export type CoreQueueWorker<
|
|
|
170
170
|
queueName: string
|
|
171
171
|
func: PikkuFunction
|
|
172
172
|
config?: PikkuWorkerConfig
|
|
173
|
-
docs?:
|
|
173
|
+
docs?: PikkuDocs
|
|
174
174
|
session?: undefined
|
|
175
175
|
tags?: string[]
|
|
176
176
|
}
|