@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.
Files changed (47) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/function/function-runner.d.ts +4 -4
  3. package/dist/function/function-runner.js +7 -4
  4. package/dist/function/functions.types.d.ts +6 -3
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/middleware/auth-apikey.d.ts +2 -2
  8. package/dist/middleware/auth-bearer.d.ts +2 -2
  9. package/dist/middleware/auth-cookie.d.ts +2 -2
  10. package/dist/middleware/timeout.d.ts +2 -2
  11. package/dist/middleware-runner.d.ts +2 -2
  12. package/dist/pikku-state.d.ts +3 -4
  13. package/dist/types/core.types.d.ts +14 -11
  14. package/dist/wirings/channel/channel.types.d.ts +4 -4
  15. package/dist/wirings/http/http-runner.d.ts +8 -8
  16. package/dist/wirings/http/http-runner.js +7 -9
  17. package/dist/wirings/http/http.types.d.ts +10 -10
  18. package/dist/wirings/mcp/mcp-runner.js +3 -9
  19. package/dist/wirings/queue/queue-runner.js +1 -3
  20. package/dist/wirings/queue/queue.types.d.ts +3 -3
  21. package/dist/wirings/rpc/rpc-runner.js +15 -3
  22. package/dist/wirings/rpc/rpc-types.d.ts +1 -1
  23. package/dist/wirings/scheduler/scheduler-runner.js +1 -3
  24. package/dist/wirings/scheduler/scheduler.types.d.ts +3 -3
  25. package/package.json +7 -7
  26. package/src/function/function-runner.ts +16 -8
  27. package/src/function/functions.types.ts +13 -5
  28. package/src/index.ts +1 -1
  29. package/src/middleware/auth-apikey.ts +2 -2
  30. package/src/middleware/auth-bearer.ts +3 -3
  31. package/src/middleware/auth-cookie.ts +3 -3
  32. package/src/middleware/timeout.ts +6 -2
  33. package/src/middleware-runner.ts +2 -7
  34. package/src/pikku-state.ts +3 -4
  35. package/src/types/core.types.ts +21 -24
  36. package/src/wirings/channel/channel.types.ts +5 -5
  37. package/src/wirings/http/http-runner.test.ts +2 -2
  38. package/src/wirings/http/http-runner.ts +12 -14
  39. package/src/wirings/http/http.types.ts +11 -11
  40. package/src/wirings/mcp/mcp-runner.ts +3 -9
  41. package/src/wirings/queue/queue-runner.ts +1 -3
  42. package/src/wirings/queue/queue.types.ts +3 -3
  43. package/src/wirings/rpc/rpc-runner.ts +16 -4
  44. package/src/wirings/rpc/rpc-types.ts +1 -1
  45. package/src/wirings/scheduler/scheduler-runner.ts +1 -3
  46. package/src/wirings/scheduler/scheduler.types.ts +3 -3
  47. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  ## 0.9.0
2
2
 
3
+ ## 0.9.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 9691aba: fix: add-functions should support both functions only and objects
8
+ - 2ab0278: refactor: no longer import ALL functions, only the ones used by rpcs
9
+ - 81005ba: feat: creating a smaller meta file for functions to reduce size
10
+
11
+ ## 0.9.2
12
+
13
+ ### Patch Changes
14
+
15
+ - 1256238: feat: pikkufunc in types extends function config to include all the different params
16
+ - 6cf8efd: feat: Adding PikkuDocs to function definition
17
+
18
+ refactor: renaming APIDocs to PikkuDocs
19
+
20
+ - d3a9a09: refactor: change addMiddleware to addHTTPMiddleware due to route support'
21
+
22
+ chore: export addHTTPMiddleware from pikku-types for consistency
23
+
24
+ - 840e078: refactor: change APIMiddleware type to PikkuMiddleware
25
+ - 667d23c: feat: adding expose to function config (although it isn't yet wired up)
26
+ - a5905a9: chore: updating all dependencies
27
+
3
28
  ## 0.9.1
4
29
 
5
30
  ### Patch Changes
@@ -1,12 +1,12 @@
1
- import { CoreServices, CoreUserSession, PikkuFunctionMiddleware } from '../types/core.types.js';
2
- import { CorePermissionGroup, CorePikkuFunctionConfig } from './functions.types.js';
3
- export declare const addFunction: (funcName: string, funcConfig: CorePikkuFunctionConfig<any, any>) => void;
1
+ import { CoreServices, CoreUserSession, CorePikkuMiddleware } from '../types/core.types.js';
2
+ import { CorePermissionGroup, CorePikkuFunction, CorePikkuFunctionConfig, CorePikkuFunctionSessionless } from './functions.types.js';
3
+ export declare const addFunction: (funcName: string, funcConfig: CorePikkuFunctionConfig<any, any> | CorePikkuFunctionSessionless<any, any> | CorePikkuFunction<any, any>) => void;
4
4
  export declare const runPikkuFuncDirectly: <In, Out>(funcName: string, allServices: CoreServices, data: In, session?: CoreUserSession) => Promise<Out>;
5
5
  export declare const runPikkuFunc: <In = any, Out = any>(funcName: string, { getAllServices, data, session, permissions: transportPermissions, middleware: transportMiddleware, coerceDataFromSchema, }: {
6
6
  getAllServices: () => Promise<CoreServices> | CoreServices;
7
7
  data: In;
8
8
  session?: CoreUserSession;
9
9
  permissions?: CorePermissionGroup;
10
- middleware?: PikkuFunctionMiddleware[];
10
+ middleware?: CorePikkuMiddleware[];
11
11
  coerceDataFromSchema?: boolean;
12
12
  }) => Promise<Out>;
@@ -4,6 +4,9 @@ import { verifyPermissions } from '../permissions.js';
4
4
  import { pikkuState } from '../pikku-state.js';
5
5
  import { coerceTopLevelDataFromSchema, validateSchema } from '../schema.js';
6
6
  export const addFunction = (funcName, funcConfig) => {
7
+ if (funcConfig instanceof Function) {
8
+ funcConfig = { func: funcConfig };
9
+ }
7
10
  pikkuState('function', 'functions').set(funcName, funcConfig);
8
11
  };
9
12
  export const runPikkuFuncDirectly = async (funcName, allServices, data, session) => {
@@ -26,13 +29,13 @@ export const runPikkuFunc = async (funcName, { getAllServices, data, session, pe
26
29
  throw new ForbiddenError(`Function ${funcName} requires authentication even though transport does not`);
27
30
  }
28
31
  const allServices = await getAllServices();
29
- const schemaName = funcMeta.schemaName;
30
- if (schemaName) {
32
+ const inputSchemaName = funcMeta.inputSchemaName;
33
+ if (inputSchemaName) {
31
34
  // Validate request data against the defined schema, if any
32
- await validateSchema(allServices.logger, allServices.schema, schemaName, data);
35
+ await validateSchema(allServices.logger, allServices.schema, inputSchemaName, data);
33
36
  // Coerce (top level) query string parameters or date objects if specified by the schema
34
37
  if (coerceDataFromSchema) {
35
- coerceTopLevelDataFromSchema(schemaName, data);
38
+ coerceTopLevelDataFromSchema(inputSchemaName, data);
36
39
  }
37
40
  }
38
41
  let permissioned = true;
@@ -1,5 +1,5 @@
1
1
  import { PikkuChannel } from '../wirings/channel/channel.types.js';
2
- import type { CoreServices, CoreSingletonServices, CoreUserSession, PikkuFunctionMiddleware } from '../types/core.types.js';
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?: PikkuFunctionMiddleware[];
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, addMiddleware } from './wirings/http/http-runner.js';
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, addMiddleware } from './wirings/http/http-runner.js';
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, PikkuMiddleware } from '../types/core.types.js';
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
- })) => PikkuMiddleware;
15
+ })) => CorePikkuMiddleware;
@@ -1,4 +1,4 @@
1
- import { CoreConfig, CoreSingletonServices, CoreUserSession, PikkuMiddleware } from '../types/core.types.js';
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
- }) => PikkuMiddleware;
12
+ }) => CorePikkuMiddleware;
@@ -1,5 +1,5 @@
1
1
  import { SerializeOptions } from 'cookie';
2
- import { CoreConfig, CoreSingletonServices, CoreUserSession, PikkuMiddleware } from '../types/core.types.js';
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
- })) => PikkuMiddleware;
20
+ })) => CorePikkuMiddleware;
@@ -1,2 +1,2 @@
1
- import { PikkuMiddleware } from '../types/core.types.js';
2
- export declare const timeout: (timeout: number) => PikkuMiddleware;
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, PikkuFunctionMiddleware, PikkuInteraction, PikkuMiddleware } from './types/core.types.js';
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 PikkuMiddleware | PikkuFunctionMiddleware = PikkuMiddleware>(services: CoreSingletonServices & {
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>;
@@ -1,10 +1,9 @@
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, PikkuMiddleware } from './types/core.types.js';
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';
7
- import { RPCMeta } from './wirings/rpc/rpc-types.js';
8
7
  import { queueWorkersMeta, CoreQueueWorker } from './wirings/queue/queue.types.js';
9
8
  import { CoreMCPResource, CoreMCPTool, CoreMCPPrompt, MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from './wirings/mcp/mcp.types.js';
10
9
  interface PikkuState {
@@ -13,7 +12,7 @@ interface PikkuState {
13
12
  functions: Map<string, CorePikkuFunctionConfig<any, any>>;
14
13
  };
15
14
  rpc: {
16
- meta: Record<string, RPCMeta>;
15
+ meta: Record<string, string>;
17
16
  files: Map<string, {
18
17
  exportedName: string;
19
18
  path: string;
@@ -22,7 +21,7 @@ interface PikkuState {
22
21
  http: {
23
22
  middleware: Array<{
24
23
  route: string;
25
- middleware: PikkuMiddleware[];
24
+ middleware: CorePikkuMiddleware[];
26
25
  }>;
27
26
  routes: Map<HTTPMethod, Map<string, CoreHTTPFunctionWiring<any, any, any>>>;
28
27
  meta: HTTPWiringsMeta;
@@ -18,14 +18,23 @@ export interface FunctionServicesMeta {
18
18
  optimized: boolean;
19
19
  services: string[];
20
20
  }
21
- export type FunctionsMeta = Record<string, {
21
+ export type FunctionRuntimeMeta = {
22
22
  pikkuFuncName: string;
23
- name?: string;
23
+ inputSchemaName: string | null;
24
+ outputSchemaName: string | null;
25
+ expose?: boolean;
26
+ };
27
+ export type FunctionMeta = FunctionRuntimeMeta & Partial<{
28
+ name: string;
24
29
  services: FunctionServicesMeta;
25
- schemaName: string | null;
26
30
  inputs: string[] | null;
27
31
  outputs: string[] | null;
32
+ tags: string[];
33
+ docs: PikkuDocs;
34
+ isDirectFunction: boolean;
28
35
  }>;
36
+ export type FunctionsRuntimeMeta = Record<string, FunctionRuntimeMeta>;
37
+ export type FunctionsMeta = Record<string, FunctionMeta>;
29
38
  export type MakeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
30
39
  /**
31
40
  * Represents a JSON primitive type which can be a string, number, boolean, null, or undefined.
@@ -89,13 +98,7 @@ export interface PikkuInteraction {
89
98
  /**
90
99
  * A function that can wrap an interaction and be called before or after
91
100
  */
92
- export type PikkuFunctionMiddleware<SingletonServices extends CoreSingletonServices = CoreSingletonServices, UserSession extends CoreUserSession = CoreUserSession> = (services: SingletonServices & {
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 & {
101
+ export type CorePikkuMiddleware<SingletonServices extends CoreSingletonServices = CoreSingletonServices, UserSession extends CoreUserSession = CoreUserSession> = (services: SingletonServices & {
99
102
  userSession: UserSessionService<UserSession>;
100
103
  }, interactions: PikkuInteraction, next: () => Promise<void>) => Promise<void>;
101
104
  /**
@@ -123,7 +126,7 @@ export type CreateConfig<Config extends CoreConfig> = (variables?: VariablesServ
123
126
  /**
124
127
  * Represents the documentation for a route, including summary, description, tags, and errors.
125
128
  */
126
- export type APIDocs = {
129
+ export type PikkuDocs = {
127
130
  summary?: string;
128
131
  description?: string;
129
132
  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 { APIDocs, CoreSingletonServices, CreateSessionServices, PikkuMiddleware } from '../../types/core.types.js';
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?: APIDocs;
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?: APIDocs;
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?: PikkuMiddleware[];
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 { PikkuMiddleware } from '../../types/core.types.js';
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 APIMiddleware The middleware type.
12
- * @param {APIMiddleware[] | string} routeOrMiddleware - Either a global middleware array or a route pattern string.
13
- * @param {APIMiddleware[]} [middleware] - The middleware array to apply when a route pattern is specified.
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 addMiddleware: <APIMiddleware extends PikkuMiddleware>(routeOrMiddleware: APIMiddleware[] | string, middleware?: APIMiddleware[]) => void;
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 APIMiddleware Middleware type to be used with the route.
29
- * @param {CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermission, APIMiddleware>} httpWiring - The HTTP wiring configuration object.
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, APIMiddleware>(httpWiring: CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermissionGroup, APIMiddleware>) => void;
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 APIMiddleware The middleware type.
20
- * @param {APIMiddleware[] | string} routeOrMiddleware - Either a global middleware array or a route pattern string.
21
- * @param {APIMiddleware[]} [middleware] - The middleware array to apply when a route pattern is specified.
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 addMiddleware = (routeOrMiddleware, middleware) => {
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 APIMiddleware Middleware type to be used with the route.
59
- * @param {CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermission, APIMiddleware>} httpWiring - The HTTP wiring configuration object.
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');
@@ -64,9 +64,7 @@ export const wireHTTP = (httpWiring) => {
64
64
  if (!routeMeta) {
65
65
  throw new Error('Route metadata not found');
66
66
  }
67
- addFunction(routeMeta.pikkuFuncName, {
68
- func: httpWiring.func,
69
- });
67
+ addFunction(routeMeta.pikkuFuncName, httpWiring.func);
70
68
  const routes = pikkuState('http', 'routes');
71
69
  if (!routes.has(httpWiring.method)) {
72
70
  routes.set(httpWiring.method, new Map());
@@ -1,6 +1,6 @@
1
1
  import type { SerializeOptions } from 'cookie';
2
2
  import type { PikkuError } from '../../errors/error-handler.js';
3
- import type { APIDocs, CoreServices, CoreSingletonServices, CoreUserSession, CreateSessionServices, PikkuMiddleware } from '../../types/core.types.js';
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>, APIMiddleware = PikkuMiddleware> = (CoreHTTPFunction & {
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?: APIMiddleware[];
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?: APIMiddleware[];
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?: APIMiddleware[];
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?: APIMiddleware[];
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?: APIMiddleware[];
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?: APIMiddleware[];
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?: APIDocs;
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: PikkuMiddleware[];
157
+ middleware: CorePikkuMiddleware[];
158
158
  };
159
159
  export interface PikkuHTTPRequest<In = unknown> {
160
160
  method(): HTTPMethod;
@@ -19,9 +19,7 @@ export const wireMCPResource = (mcpResource) => {
19
19
  if (!mcpResourceMeta) {
20
20
  throw new Error(`MCP resource metadata not found for '${mcpResource.uri}'`);
21
21
  }
22
- addFunction(mcpResourceMeta.pikkuFuncName, {
23
- func: mcpResource.func,
24
- });
22
+ addFunction(mcpResourceMeta.pikkuFuncName, mcpResource.func);
25
23
  const resources = pikkuState('mcp', 'resources');
26
24
  if (resources.has(mcpResource.uri)) {
27
25
  throw new Error(`MCP resource already exists: ${mcpResource.uri}`);
@@ -34,9 +32,7 @@ export const wireMCPTool = (mcpTool) => {
34
32
  if (!mcpToolMeta) {
35
33
  throw new Error(`MCP tool metadata not found for '${mcpTool.name}'`);
36
34
  }
37
- addFunction(mcpToolMeta.pikkuFuncName, {
38
- func: mcpTool.func,
39
- });
35
+ addFunction(mcpToolMeta.pikkuFuncName, mcpTool.func);
40
36
  const tools = pikkuState('mcp', 'tools');
41
37
  if (tools.has(mcpTool.name)) {
42
38
  throw new Error(`MCP tool already exists: ${mcpTool.name}`);
@@ -49,9 +45,7 @@ export const wireMCPPrompt = (mcpPrompt) => {
49
45
  if (!mcpPromptMeta) {
50
46
  throw new Error(`MCP prompt metadata not found for '${mcpPrompt.name}'`);
51
47
  }
52
- addFunction(mcpPromptMeta.pikkuFuncName, {
53
- func: mcpPrompt.func,
54
- });
48
+ addFunction(mcpPromptMeta.pikkuFuncName, mcpPrompt.func);
55
49
  const prompts = pikkuState('mcp', 'prompts');
56
50
  if (prompts.has(mcpPrompt.name)) {
57
51
  throw new Error(`MCP prompt already exists: ${mcpPrompt.name}`);
@@ -20,9 +20,7 @@ export const wireQueueWorker = (queueWorker) => {
20
20
  throw new Error(`Queue processor metadata not found for '${queueWorker.queueName}'. Make sure to run the CLI to generate metadata.`);
21
21
  }
22
22
  // Register the function with pikku
23
- addFunction(processorMeta.pikkuFuncName, {
24
- func: queueWorker.func,
25
- });
23
+ addFunction(processorMeta.pikkuFuncName, queueWorker.func);
26
24
  // Store processor definition in state - runtime adapters will pick this up
27
25
  const registrations = pikkuState('queue', 'registrations');
28
26
  registrations.set(queueWorker.queueName, queueWorker);
@@ -1,4 +1,4 @@
1
- import { APIDocs } from '../../types/core.types.js';
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?: APIDocs;
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?: APIDocs;
151
+ docs?: PikkuDocs;
152
152
  session?: undefined;
153
153
  tags?: string[];
154
154
  };
@@ -1,6 +1,7 @@
1
1
  import { runPikkuFunc } from '../../function/function-runner.js';
2
2
  import { pikkuState } from '../../pikku-state.js';
3
- const getRPCMeta = (rpcName) => {
3
+ import { ForbiddenError } from '../../errors/errors.js';
4
+ const getPikkuFunctionName = (rpcName) => {
4
5
  const rpc = pikkuState('rpc', 'meta');
5
6
  const rpcMeta = rpc[rpcName];
6
7
  if (!rpcMeta) {
@@ -16,11 +17,21 @@ class ContextAwareRPCService {
16
17
  this.services = services;
17
18
  this.options = options;
18
19
  }
20
+ async rpcExposed(funcName, data) {
21
+ const functionMeta = pikkuState('function', 'meta')[funcName];
22
+ if (!functionMeta) {
23
+ throw new Error(`Function not found: ${funcName}`);
24
+ }
25
+ if (!functionMeta.expose) {
26
+ throw new ForbiddenError();
27
+ }
28
+ return await this.rpc(funcName, data);
29
+ }
19
30
  async rpc(funcName, data) {
20
31
  const session = await this.services.userSession?.get();
21
32
  const rpcDepth = this.services.rpc?.depth || 0;
22
- const rpcMeta = getRPCMeta(funcName);
23
- return runPikkuFunc(rpcMeta.pikkuFuncName, {
33
+ const pikkuFuncName = getPikkuFunctionName(funcName);
34
+ return runPikkuFunc(pikkuFuncName, {
24
35
  getAllServices: () => {
25
36
  this.services.rpc = this.services.rpc
26
37
  ? {
@@ -56,6 +67,7 @@ export class PikkuRPCService {
56
67
  depth,
57
68
  global: false,
58
69
  invoke: serviceRPC.rpc.bind(serviceRPC),
70
+ invokeExposed: serviceRPC.rpc.bind(serviceRPC),
59
71
  };
60
72
  return serviceCopy;
61
73
  }
@@ -5,7 +5,7 @@ export type PikkuRPC<invoke extends Function = any> = {
5
5
  };
6
6
  export type RPCMeta = {
7
7
  pikkuFuncName: string;
8
- exposed: boolean;
8
+ expose: boolean;
9
9
  };
10
10
  /**
11
11
  * Type for RPC handlers
@@ -9,9 +9,7 @@ export const wireScheduler = (scheduledTask) => {
9
9
  if (!taskMeta) {
10
10
  throw new Error('Task metadata not found');
11
11
  }
12
- addFunction(taskMeta.pikkuFuncName, {
13
- func: scheduledTask.func,
14
- });
12
+ addFunction(taskMeta.pikkuFuncName, scheduledTask.func);
15
13
  const tasks = pikkuState('scheduler', 'tasks');
16
14
  if (tasks.has(scheduledTask.name)) {
17
15
  throw new Error(`Scheduled task already exists: ${scheduledTask.name}`);
@@ -1,4 +1,4 @@
1
- import { APIDocs, CoreUserSession } from '../../types/core.types.js';
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?: APIDocs;
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?: APIDocs;
21
+ docs?: PikkuDocs;
22
22
  tags?: string[];
23
23
  };