@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
## 0.9.0
|
|
2
2
|
|
|
3
|
+
## 0.9.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1256238: feat: pikkufunc in types extends function config to include all the different params
|
|
8
|
+
- 6cf8efd: feat: Adding PikkuDocs to function definition
|
|
9
|
+
|
|
10
|
+
refactor: renaming APIDocs to PikkuDocs
|
|
11
|
+
|
|
12
|
+
- d3a9a09: refactor: change addMiddleware to addHTTPMiddleware due to route support'
|
|
13
|
+
|
|
14
|
+
chore: export addHTTPMiddleware from pikku-types for consistency
|
|
15
|
+
|
|
16
|
+
- 840e078: refactor: change APIMiddleware type to PikkuMiddleware
|
|
17
|
+
- 667d23c: feat: adding expose to function config (although it isn't yet wired up)
|
|
18
|
+
- a5905a9: chore: updating all dependencies
|
|
19
|
+
|
|
20
|
+
## 0.9.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- fdb1593: core: bumping everything with a patch to sync up the major release inconsistencies in dependencies
|
|
25
|
+
|
|
3
26
|
### Breaking Changes
|
|
4
27
|
|
|
5
28
|
- Normalized all transports to use "wirings" instead of events/routes/transports for consistency across the framework
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreServices, CoreUserSession,
|
|
1
|
+
import { CoreServices, CoreUserSession, CorePikkuMiddleware } from '../types/core.types.js';
|
|
2
2
|
import { CorePermissionGroup, CorePikkuFunctionConfig } from './functions.types.js';
|
|
3
3
|
export declare const addFunction: (funcName: string, funcConfig: CorePikkuFunctionConfig<any, any>) => void;
|
|
4
4
|
export declare const runPikkuFuncDirectly: <In, Out>(funcName: string, allServices: CoreServices, data: In, session?: CoreUserSession) => Promise<Out>;
|
|
@@ -7,6 +7,6 @@ export declare const runPikkuFunc: <In = any, Out = any>(funcName: string, { get
|
|
|
7
7
|
data: In;
|
|
8
8
|
session?: CoreUserSession;
|
|
9
9
|
permissions?: CorePermissionGroup;
|
|
10
|
-
middleware?:
|
|
10
|
+
middleware?: CorePikkuMiddleware[];
|
|
11
11
|
coerceDataFromSchema?: boolean;
|
|
12
12
|
}) => Promise<Out>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PikkuChannel } from '../wirings/channel/channel.types.js';
|
|
2
|
-
import type { CoreServices, CoreSingletonServices, CoreUserSession,
|
|
2
|
+
import type { CoreServices, CoreSingletonServices, CoreUserSession, PikkuDocs, CorePikkuMiddleware } from '../types/core.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Represents a core API function that performs an operation using core services and a user session.
|
|
5
5
|
*
|
|
@@ -35,9 +35,12 @@ export type CorePikkuFunctionSessionless<In, Out, ChannelData extends unknown |
|
|
|
35
35
|
*/
|
|
36
36
|
export type CorePikkuPermission<In = any, Services extends CoreSingletonServices = CoreServices, Session extends CoreUserSession = CoreUserSession> = (services: Services, data: In, session?: Session) => Promise<boolean>;
|
|
37
37
|
export type CorePermissionGroup<PikkuPermission = CorePikkuPermission<any>> = Record<string, PikkuPermission | PikkuPermission[]> | undefined;
|
|
38
|
-
export type CorePikkuFunctionConfig<PikkuFunction extends CorePikkuFunction<any, any> | CorePikkuFunctionSessionless<any, any>, PikkuPermission extends CorePikkuPermission<any> = CorePikkuPermission<any>> = {
|
|
38
|
+
export type CorePikkuFunctionConfig<PikkuFunction extends CorePikkuFunction<any, any, any, any, any> | CorePikkuFunctionSessionless<any, any, any, any, any>, PikkuPermission extends CorePikkuPermission<any, any, any> = CorePikkuPermission<any>> = {
|
|
39
|
+
name?: string;
|
|
40
|
+
expose?: boolean;
|
|
39
41
|
func: PikkuFunction;
|
|
40
42
|
auth?: boolean;
|
|
41
43
|
permissions?: CorePermissionGroup<PikkuPermission>;
|
|
42
|
-
middleware?:
|
|
44
|
+
middleware?: CorePikkuMiddleware[];
|
|
45
|
+
docs?: PikkuDocs;
|
|
43
46
|
};
|
package/dist/index.d.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';
|
package/dist/index.js
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';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreConfig, CoreSingletonServices, CoreUserSession,
|
|
1
|
+
import { CoreConfig, CoreSingletonServices, CoreUserSession, CorePikkuMiddleware } from '../types/core.types.js';
|
|
2
2
|
/**
|
|
3
3
|
* API key middleware that retrieves a session from the 'x-api-key' header using a provided callback.
|
|
4
4
|
*
|
|
@@ -12,4 +12,4 @@ export declare const authAPIKey: <SingletonServices extends CoreSingletonService
|
|
|
12
12
|
} | {
|
|
13
13
|
getSessionForAPIKey: (services: SingletonServices, apiKey: string) => Promise<any>;
|
|
14
14
|
jwt?: false;
|
|
15
|
-
})) =>
|
|
15
|
+
})) => CorePikkuMiddleware;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreConfig, CoreSingletonServices, CoreUserSession,
|
|
1
|
+
import { CoreConfig, CoreSingletonServices, CoreUserSession, CorePikkuMiddleware } from '../types/core.types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Extracts the Bearer token from the Authorization header
|
|
4
4
|
*/
|
|
@@ -9,4 +9,4 @@ export declare const authBearer: <SingletonServices extends CoreSingletonService
|
|
|
9
9
|
};
|
|
10
10
|
jwt?: boolean;
|
|
11
11
|
getSession?: (services: SingletonServices, token: string) => Promise<UserSession> | UserSession;
|
|
12
|
-
}) =>
|
|
12
|
+
}) => CorePikkuMiddleware;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SerializeOptions } from 'cookie';
|
|
2
|
-
import { CoreConfig, CoreSingletonServices, CoreUserSession,
|
|
2
|
+
import { CoreConfig, CoreSingletonServices, CoreUserSession, CorePikkuMiddleware } from '../types/core.types.js';
|
|
3
3
|
import { RelativeTimeInput } from '../time-utils.js';
|
|
4
4
|
/**
|
|
5
5
|
* Cookie middleware that extracts a session from cookies.
|
|
@@ -17,4 +17,4 @@ export declare const authCookie: <SingletonServices extends CoreSingletonService
|
|
|
17
17
|
} | {
|
|
18
18
|
getSessionForCookieValue?: undefined;
|
|
19
19
|
jwt: true;
|
|
20
|
-
})) =>
|
|
20
|
+
})) => CorePikkuMiddleware;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const timeout: (timeout: number) =>
|
|
1
|
+
import { CorePikkuMiddleware } from '../types/core.types.js';
|
|
2
|
+
export declare const timeout: (timeout: number) => CorePikkuMiddleware;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserSessionService } from './services/user-session-service.js';
|
|
2
|
-
import { CoreSingletonServices,
|
|
2
|
+
import { CoreSingletonServices, PikkuInteraction, CorePikkuMiddleware } from './types/core.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Runs a chain of middleware functions in sequence before executing the main function.
|
|
5
5
|
*
|
|
@@ -17,6 +17,6 @@ import { CoreSingletonServices, PikkuFunctionMiddleware, PikkuInteraction, Pikku
|
|
|
17
17
|
* async () => { return await runMain(); }
|
|
18
18
|
* );
|
|
19
19
|
*/
|
|
20
|
-
export declare const runMiddleware: <Middleware extends
|
|
20
|
+
export declare const runMiddleware: <Middleware extends CorePikkuMiddleware>(services: CoreSingletonServices & {
|
|
21
21
|
userSession?: UserSessionService<any>;
|
|
22
22
|
}, interaction: PikkuInteraction, middlewares: Middleware[], main?: () => Promise<unknown>) => Promise<unknown>;
|
package/dist/pikku-state.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChannelsMeta, CoreChannel } from './wirings/channel/channel.types.js';
|
|
2
2
|
import { CoreHTTPFunctionWiring, HTTPMethod, HTTPWiringsMeta } from './wirings/http/http.types.js';
|
|
3
|
-
import { FunctionsMeta,
|
|
3
|
+
import { FunctionsMeta, CorePikkuMiddleware } from './types/core.types.js';
|
|
4
4
|
import { CoreScheduledTask, ScheduledTasksMeta } from './wirings/scheduler/scheduler.types.js';
|
|
5
5
|
import { ErrorDetails, PikkuError } from './errors/error-handler.js';
|
|
6
6
|
import { CorePikkuFunctionConfig } from './function/functions.types.js';
|
|
@@ -22,7 +22,7 @@ interface PikkuState {
|
|
|
22
22
|
http: {
|
|
23
23
|
middleware: Array<{
|
|
24
24
|
route: string;
|
|
25
|
-
middleware:
|
|
25
|
+
middleware: CorePikkuMiddleware[];
|
|
26
26
|
}>;
|
|
27
27
|
routes: Map<HTTPMethod, Map<string, CoreHTTPFunctionWiring<any, any, any>>>;
|
|
28
28
|
meta: HTTPWiringsMeta;
|
|
@@ -25,6 +25,9 @@ export type FunctionsMeta = Record<string, {
|
|
|
25
25
|
schemaName: string | null;
|
|
26
26
|
inputs: string[] | null;
|
|
27
27
|
outputs: string[] | null;
|
|
28
|
+
expose?: boolean;
|
|
29
|
+
tags?: string[];
|
|
30
|
+
docs?: PikkuDocs;
|
|
28
31
|
}>;
|
|
29
32
|
export type MakeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
30
33
|
/**
|
|
@@ -89,13 +92,7 @@ export interface PikkuInteraction {
|
|
|
89
92
|
/**
|
|
90
93
|
* A function that can wrap an interaction and be called before or after
|
|
91
94
|
*/
|
|
92
|
-
export type
|
|
93
|
-
userSession?: UserSessionService<UserSession>;
|
|
94
|
-
}, interactions: PikkuInteraction, next: () => Promise<void>) => Promise<void>;
|
|
95
|
-
/**
|
|
96
|
-
* A function that can wrap an interaction and be called before or after
|
|
97
|
-
*/
|
|
98
|
-
export type PikkuMiddleware<SingletonServices extends CoreSingletonServices = CoreSingletonServices, UserSession extends CoreUserSession = CoreUserSession> = (services: SingletonServices & {
|
|
95
|
+
export type CorePikkuMiddleware<SingletonServices extends CoreSingletonServices = CoreSingletonServices, UserSession extends CoreUserSession = CoreUserSession> = (services: SingletonServices & {
|
|
99
96
|
userSession: UserSessionService<UserSession>;
|
|
100
97
|
}, interactions: PikkuInteraction, next: () => Promise<void>) => Promise<void>;
|
|
101
98
|
/**
|
|
@@ -123,7 +120,7 @@ export type CreateConfig<Config extends CoreConfig> = (variables?: VariablesServ
|
|
|
123
120
|
/**
|
|
124
121
|
* Represents the documentation for a route, including summary, description, tags, and errors.
|
|
125
122
|
*/
|
|
126
|
-
export type
|
|
123
|
+
export type PikkuDocs = {
|
|
127
124
|
summary?: string;
|
|
128
125
|
description?: string;
|
|
129
126
|
tags?: string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PikkuError } from '../../errors/error-handler.js';
|
|
2
2
|
import { HTTPFunctionMetaInputTypes, PikkuHTTPRequest, PikkuHTTPResponse } from '../http/http.types.js';
|
|
3
|
-
import {
|
|
3
|
+
import { PikkuDocs, CoreSingletonServices, CreateSessionServices, CorePikkuMiddleware } from '../../types/core.types.js';
|
|
4
4
|
import { CorePikkuFunction, CorePikkuFunctionSessionless, CorePikkuPermission } from '../../function/functions.types.js';
|
|
5
5
|
export type RunChannelOptions = Partial<{
|
|
6
6
|
skipUserSession: boolean;
|
|
@@ -18,7 +18,7 @@ export type RunChannelParams<ChannelData> = {
|
|
|
18
18
|
};
|
|
19
19
|
export interface ChannelMessageMeta {
|
|
20
20
|
pikkuFuncName: string;
|
|
21
|
-
docs?:
|
|
21
|
+
docs?: PikkuDocs;
|
|
22
22
|
}
|
|
23
23
|
export interface ChannelMeta {
|
|
24
24
|
name: string;
|
|
@@ -31,7 +31,7 @@ export interface ChannelMeta {
|
|
|
31
31
|
disconnect: ChannelMessageMeta | null;
|
|
32
32
|
message: ChannelMessageMeta | null;
|
|
33
33
|
messageWirings: Record<string, Record<string, ChannelMessageMeta>>;
|
|
34
|
-
docs?:
|
|
34
|
+
docs?: PikkuDocs;
|
|
35
35
|
tags?: string[];
|
|
36
36
|
}
|
|
37
37
|
export type ChannelsMeta = Record<string, ChannelMeta>;
|
|
@@ -50,7 +50,7 @@ export type CoreChannel<ChannelData, Channel extends string, ChannelConnect = Co
|
|
|
50
50
|
permissions?: Record<string, PikkuPermission[] | PikkuPermission>;
|
|
51
51
|
auth?: boolean;
|
|
52
52
|
}>>;
|
|
53
|
-
middleware?:
|
|
53
|
+
middleware?: CorePikkuMiddleware[];
|
|
54
54
|
permissions?: Record<string, PikkuPermission[] | PikkuPermission>;
|
|
55
55
|
auth?: boolean;
|
|
56
56
|
docs?: Partial<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CoreHTTPFunctionWiring, RunHTTPWiringOptions, RunHTTPWiringParams, PikkuHTTP, PikkuHTTPRequest, PikkuHTTPResponse } from './http.types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { CorePikkuMiddleware } from '../../types/core.types.js';
|
|
3
3
|
import { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js';
|
|
4
4
|
/**
|
|
5
5
|
* Registers middleware either globally or for a specific route.
|
|
@@ -8,11 +8,11 @@ import { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js';
|
|
|
8
8
|
* is applied only to that route. Otherwise, if an array is provided, it is treated
|
|
9
9
|
* as global middleware (applied to all routes).
|
|
10
10
|
*
|
|
11
|
-
* @template
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
11
|
+
* @template PikkuMiddleware The middleware type.
|
|
12
|
+
* @param {PikkuMiddleware[] | string} routeOrMiddleware - Either a global middleware array or a route pattern string.
|
|
13
|
+
* @param {PikkuMiddleware[]} [middleware] - The middleware array to apply when a route pattern is specified.
|
|
14
14
|
*/
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const addHTTPMiddleware: <PikkuMiddleware extends CorePikkuMiddleware>(routeOrMiddleware: PikkuMiddleware[] | string, middleware?: PikkuMiddleware[]) => void;
|
|
16
16
|
/**
|
|
17
17
|
* Adds a new route to the global HTTP route registry.
|
|
18
18
|
*
|
|
@@ -25,10 +25,10 @@ export declare const addMiddleware: <APIMiddleware extends PikkuMiddleware>(rout
|
|
|
25
25
|
* @template PikkuFunction Type for the route handler function.
|
|
26
26
|
* @template PikkuFunctionSessionless Type for a sessionless handler.
|
|
27
27
|
* @template PikkuPermissionGroup Type representing required permissions.
|
|
28
|
-
* @template
|
|
29
|
-
* @param {CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermission,
|
|
28
|
+
* @template PikkuMiddleware Middleware type to be used with the route.
|
|
29
|
+
* @param {CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware>} httpWiring - The HTTP wiring configuration object.
|
|
30
30
|
*/
|
|
31
|
-
export declare const wireHTTP: <In, Out, Route extends string, PikkuFunction, PikkuFunctionSessionless, PikkuPermissionGroup,
|
|
31
|
+
export declare const wireHTTP: <In, Out, Route extends string, PikkuFunction, PikkuFunctionSessionless, PikkuPermissionGroup, PikkuMiddleware>(httpWiring: CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermissionGroup, PikkuMiddleware>) => void;
|
|
32
32
|
/**
|
|
33
33
|
* Combines the request and response objects into a single HTTP interaction object.
|
|
34
34
|
*
|
|
@@ -16,11 +16,11 @@ import { rpcService } from '../rpc/rpc-runner.js';
|
|
|
16
16
|
* is applied only to that route. Otherwise, if an array is provided, it is treated
|
|
17
17
|
* as global middleware (applied to all routes).
|
|
18
18
|
*
|
|
19
|
-
* @template
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
19
|
+
* @template PikkuMiddleware The middleware type.
|
|
20
|
+
* @param {PikkuMiddleware[] | string} routeOrMiddleware - Either a global middleware array or a route pattern string.
|
|
21
|
+
* @param {PikkuMiddleware[]} [middleware] - The middleware array to apply when a route pattern is specified.
|
|
22
22
|
*/
|
|
23
|
-
export const
|
|
23
|
+
export const addHTTPMiddleware = (routeOrMiddleware, middleware) => {
|
|
24
24
|
const middlewareStore = pikkuState('http', 'middleware');
|
|
25
25
|
if (typeof routeOrMiddleware === 'string' && middleware) {
|
|
26
26
|
const route = routeOrMiddleware;
|
|
@@ -55,8 +55,8 @@ export const addMiddleware = (routeOrMiddleware, middleware) => {
|
|
|
55
55
|
* @template PikkuFunction Type for the route handler function.
|
|
56
56
|
* @template PikkuFunctionSessionless Type for a sessionless handler.
|
|
57
57
|
* @template PikkuPermissionGroup Type representing required permissions.
|
|
58
|
-
* @template
|
|
59
|
-
* @param {CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermission,
|
|
58
|
+
* @template PikkuMiddleware Middleware type to be used with the route.
|
|
59
|
+
* @param {CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware>} httpWiring - The HTTP wiring configuration object.
|
|
60
60
|
*/
|
|
61
61
|
export const wireHTTP = (httpWiring) => {
|
|
62
62
|
const httpMeta = pikkuState('http', 'meta');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SerializeOptions } from 'cookie';
|
|
2
2
|
import type { PikkuError } from '../../errors/error-handler.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { PikkuDocs, CoreServices, CoreSingletonServices, CoreUserSession, CreateSessionServices, CorePikkuMiddleware } from '../../types/core.types.js';
|
|
4
4
|
import type { CorePikkuFunction, CorePikkuFunctionSessionless, CorePikkuPermission, CorePermissionGroup } from '../../function/functions.types.js';
|
|
5
5
|
type ExtractHTTPWiringParams<S extends string> = S extends `${string}:${infer Param}/${infer Rest}` ? Param | ExtractHTTPWiringParams<`/${Rest}`> : S extends `${string}:${infer Param}` ? Param : never;
|
|
6
6
|
export type AssertHTTPWiringParams<In, HTTPWiring extends string> = ExtractHTTPWiringParams<HTTPWiring> extends keyof In ? unknown : [
|
|
@@ -67,14 +67,14 @@ export type PikkuQuery<T = Record<string, string | undefined>> = Record<string,
|
|
|
67
67
|
* @template PikkuFunctionSessionless - The sessionless API function type, defaults to `CorePikkuFunctionSessionless`.
|
|
68
68
|
* @template PikkuPermission - The permission function type, defaults to `CorePikkuPermission`.
|
|
69
69
|
*/
|
|
70
|
-
export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction = CorePikkuFunction<In, Out>, PikkuFunctionSessionless = CorePikkuFunctionSessionless<In, Out>, PikkuPermission = CorePikkuPermission<In>,
|
|
70
|
+
export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction = CorePikkuFunction<In, Out>, PikkuFunctionSessionless = CorePikkuFunctionSessionless<In, Out>, PikkuPermission = CorePikkuPermission<In>, PikkuMiddleware = CorePikkuMiddleware> = (CoreHTTPFunction & {
|
|
71
71
|
route: R;
|
|
72
72
|
method: HTTPMethod;
|
|
73
73
|
func: PikkuFunction;
|
|
74
74
|
permissions?: CorePermissionGroup<PikkuPermission>;
|
|
75
75
|
auth?: true;
|
|
76
76
|
tags?: string[];
|
|
77
|
-
middleware?:
|
|
77
|
+
middleware?: PikkuMiddleware[];
|
|
78
78
|
sse?: undefined;
|
|
79
79
|
}) | (CoreHTTPFunction & {
|
|
80
80
|
route: R;
|
|
@@ -83,7 +83,7 @@ export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction = Co
|
|
|
83
83
|
permissions?: undefined;
|
|
84
84
|
auth?: false;
|
|
85
85
|
tags?: string[];
|
|
86
|
-
middleware?:
|
|
86
|
+
middleware?: PikkuMiddleware[];
|
|
87
87
|
sse?: undefined;
|
|
88
88
|
}) | (CoreHTTPFunction & {
|
|
89
89
|
route: R;
|
|
@@ -93,7 +93,7 @@ export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction = Co
|
|
|
93
93
|
auth?: true;
|
|
94
94
|
sse?: boolean;
|
|
95
95
|
tags?: string[];
|
|
96
|
-
middleware?:
|
|
96
|
+
middleware?: PikkuMiddleware[];
|
|
97
97
|
}) | (CoreHTTPFunction & {
|
|
98
98
|
route: R;
|
|
99
99
|
method: 'get';
|
|
@@ -102,7 +102,7 @@ export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction = Co
|
|
|
102
102
|
auth?: false;
|
|
103
103
|
sse?: boolean;
|
|
104
104
|
tags?: string[];
|
|
105
|
-
middleware?:
|
|
105
|
+
middleware?: PikkuMiddleware[];
|
|
106
106
|
}) | (CoreHTTPFunction & {
|
|
107
107
|
route: R;
|
|
108
108
|
method: 'post';
|
|
@@ -111,7 +111,7 @@ export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction = Co
|
|
|
111
111
|
auth?: true;
|
|
112
112
|
query?: Array<keyof In>;
|
|
113
113
|
tags?: string[];
|
|
114
|
-
middleware?:
|
|
114
|
+
middleware?: PikkuMiddleware[];
|
|
115
115
|
sse?: undefined;
|
|
116
116
|
}) | (CoreHTTPFunction & {
|
|
117
117
|
route: R;
|
|
@@ -121,7 +121,7 @@ export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction = Co
|
|
|
121
121
|
auth?: false;
|
|
122
122
|
query?: Array<keyof In>;
|
|
123
123
|
tags?: string[];
|
|
124
|
-
middleware?:
|
|
124
|
+
middleware?: PikkuMiddleware[];
|
|
125
125
|
sse?: undefined;
|
|
126
126
|
});
|
|
127
127
|
/**
|
|
@@ -142,7 +142,7 @@ export type HTTPWiringMeta = {
|
|
|
142
142
|
params?: string[];
|
|
143
143
|
query?: string[];
|
|
144
144
|
inputTypes?: HTTPFunctionMetaInputTypes;
|
|
145
|
-
docs?:
|
|
145
|
+
docs?: PikkuDocs;
|
|
146
146
|
tags?: string[];
|
|
147
147
|
sse?: true;
|
|
148
148
|
};
|
|
@@ -154,7 +154,7 @@ export type HTTPFunctionsMeta = Array<{
|
|
|
154
154
|
}>;
|
|
155
155
|
export type HTTPWiringMiddleware = {
|
|
156
156
|
route: string;
|
|
157
|
-
middleware:
|
|
157
|
+
middleware: CorePikkuMiddleware[];
|
|
158
158
|
};
|
|
159
159
|
export interface PikkuHTTPRequest<In = unknown> {
|
|
160
160
|
method(): HTTPMethod;
|
|
@@ -47,7 +47,7 @@ export const wireMCPPrompt = (mcpPrompt) => {
|
|
|
47
47
|
const promptsMeta = pikkuState('mcp', 'promptsMeta');
|
|
48
48
|
const mcpPromptMeta = promptsMeta[mcpPrompt.name];
|
|
49
49
|
if (!mcpPromptMeta) {
|
|
50
|
-
throw new Error(`MCP prompt metadata not found for '${mcpPrompt.name}'
|
|
50
|
+
throw new Error(`MCP prompt metadata not found for '${mcpPrompt.name}'`);
|
|
51
51
|
}
|
|
52
52
|
addFunction(mcpPromptMeta.pikkuFuncName, {
|
|
53
53
|
func: mcpPrompt.func,
|
|
@@ -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
|
/**
|
|
@@ -137,7 +137,7 @@ export type queueWorkersMeta = Record<string, {
|
|
|
137
137
|
schemaName?: string;
|
|
138
138
|
queueName: string;
|
|
139
139
|
session?: undefined;
|
|
140
|
-
docs?:
|
|
140
|
+
docs?: PikkuDocs;
|
|
141
141
|
tags?: string[];
|
|
142
142
|
config?: PikkuWorkerConfig;
|
|
143
143
|
}>;
|
|
@@ -148,7 +148,7 @@ export type CoreQueueWorker<PikkuFunction = CorePikkuFunctionSessionless<any, an
|
|
|
148
148
|
queueName: string;
|
|
149
149
|
func: PikkuFunction;
|
|
150
150
|
config?: PikkuWorkerConfig;
|
|
151
|
-
docs?:
|
|
151
|
+
docs?: PikkuDocs;
|
|
152
152
|
session?: undefined;
|
|
153
153
|
tags?: string[];
|
|
154
154
|
};
|
|
@@ -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
|
* Represents metadata for scheduled tasks, including title, schedule, and documentation.
|
|
@@ -8,7 +8,7 @@ export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> = Reco
|
|
|
8
8
|
name: string;
|
|
9
9
|
schedule: string;
|
|
10
10
|
session?: UserSession;
|
|
11
|
-
docs?:
|
|
11
|
+
docs?: PikkuDocs;
|
|
12
12
|
tags?: string[];
|
|
13
13
|
}>;
|
|
14
14
|
/**
|
|
@@ -18,6 +18,6 @@ export type CoreScheduledTask<PikkuFunction = CorePikkuFunctionSessionless<void,
|
|
|
18
18
|
name: string;
|
|
19
19
|
schedule: string;
|
|
20
20
|
func: PikkuFunction;
|
|
21
|
-
docs?:
|
|
21
|
+
docs?: PikkuDocs;
|
|
22
22
|
tags?: string[];
|
|
23
23
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
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,7 +6,7 @@ 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,
|
|
@@ -47,7 +47,7 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
47
47
|
data: In
|
|
48
48
|
session?: CoreUserSession
|
|
49
49
|
permissions?: CorePermissionGroup
|
|
50
|
-
middleware?:
|
|
50
|
+
middleware?: CorePikkuMiddleware[]
|
|
51
51
|
coerceDataFromSchema?: boolean
|
|
52
52
|
}
|
|
53
53
|
): Promise<Out> => {
|
|
@@ -106,7 +106,7 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
if (transportMiddleware || funcConfig.middleware) {
|
|
109
|
-
return (await runMiddleware<
|
|
109
|
+
return (await runMiddleware<CorePikkuMiddleware>(
|
|
110
110
|
allServices,
|
|
111
111
|
{
|
|
112
112
|
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)
|