@pikku/core 0.9.0 → 0.9.2
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 +23 -0
- package/dist/function/function-runner.d.ts +2 -2
- 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 +2 -2
- package/dist/types/core.types.d.ts +5 -8
- 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 +6 -6
- package/dist/wirings/http/http.types.d.ts +10 -10
- package/dist/wirings/mcp/mcp-runner.js +1 -1
- package/dist/wirings/queue/queue.types.d.ts +3 -3
- package/dist/wirings/scheduler/scheduler.types.d.ts +3 -3
- package/package.json +7 -7
- package/src/function/function-runner.ts +3 -3
- 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 +2 -2
- package/src/types/core.types.ts +5 -16
- 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 +11 -11
- package/src/wirings/http/http.types.ts +11 -11
- package/src/wirings/queue/queue.types.ts +3 -3
- package/src/wirings/scheduler/scheduler.types.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/lcov.info +0 -5680
- package/src/wirings/mcp/mcp-endpoint-registry.test.js +0 -338
- package/src/wirings/mcp/mcp-endpoint-registry.test.js.map +0 -1
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,7 +4,7 @@ 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,
|
|
@@ -41,7 +41,7 @@ interface PikkuState {
|
|
|
41
41
|
>
|
|
42
42
|
}
|
|
43
43
|
http: {
|
|
44
|
-
middleware: Array<{ route: string; middleware:
|
|
44
|
+
middleware: Array<{ route: string; middleware: CorePikkuMiddleware[] }>
|
|
45
45
|
routes: Map<HTTPMethod, Map<string, CoreHTTPFunctionWiring<any, any, any>>>
|
|
46
46
|
meta: HTTPWiringsMeta
|
|
47
47
|
}
|
package/src/types/core.types.ts
CHANGED
|
@@ -30,6 +30,9 @@ export type FunctionsMeta = Record<
|
|
|
30
30
|
schemaName: string | null
|
|
31
31
|
inputs: string[] | null
|
|
32
32
|
outputs: string[] | null
|
|
33
|
+
expose?: boolean
|
|
34
|
+
tags?: string[]
|
|
35
|
+
docs?: PikkuDocs
|
|
33
36
|
}
|
|
34
37
|
>
|
|
35
38
|
|
|
@@ -110,21 +113,7 @@ export interface PikkuInteraction {
|
|
|
110
113
|
/**
|
|
111
114
|
* A function that can wrap an interaction and be called before or after
|
|
112
115
|
*/
|
|
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<
|
|
116
|
+
export type CorePikkuMiddleware<
|
|
128
117
|
SingletonServices extends CoreSingletonServices = CoreSingletonServices,
|
|
129
118
|
UserSession extends CoreUserSession = CoreUserSession,
|
|
130
119
|
> = (
|
|
@@ -190,7 +179,7 @@ export type CreateConfig<Config extends CoreConfig> = (
|
|
|
190
179
|
/**
|
|
191
180
|
* Represents the documentation for a route, including summary, description, tags, and errors.
|
|
192
181
|
*/
|
|
193
|
-
export type
|
|
182
|
+
export type PikkuDocs = {
|
|
194
183
|
summary?: string
|
|
195
184
|
description?: string
|
|
196
185
|
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')
|
|
@@ -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> {
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PikkuDocs, CoreUserSession } from '../../types/core.types.js'
|
|
2
2
|
import { CorePikkuFunctionSessionless } from '../../function/functions.types.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -12,7 +12,7 @@ export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> =
|
|
|
12
12
|
name: string
|
|
13
13
|
schedule: string
|
|
14
14
|
session?: UserSession
|
|
15
|
-
docs?:
|
|
15
|
+
docs?: PikkuDocs
|
|
16
16
|
tags?: string[]
|
|
17
17
|
}
|
|
18
18
|
>
|
|
@@ -26,6 +26,6 @@ export type CoreScheduledTask<
|
|
|
26
26
|
name: string
|
|
27
27
|
schedule: string
|
|
28
28
|
func: PikkuFunction
|
|
29
|
-
docs?:
|
|
29
|
+
docs?: PikkuDocs
|
|
30
30
|
tags?: string[]
|
|
31
31
|
}
|