@pikku/core 0.7.7 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -1
- package/dist/errors/error-handler.d.ts +2 -0
- package/dist/errors/errors.js +2 -0
- package/dist/{channel → events/channel}/channel-handler.d.ts +1 -1
- package/dist/{channel → events/channel}/channel-handler.js +2 -2
- package/dist/{channel → events/channel}/channel-runner.d.ts +1 -1
- package/dist/{channel → events/channel}/channel-runner.js +8 -8
- package/dist/{channel → events/channel}/channel-store.d.ts +1 -1
- package/dist/{channel → events/channel}/channel.types.d.ts +5 -9
- package/dist/{channel → events/channel}/local/local-channel-runner.js +10 -10
- package/dist/{channel → events/channel}/log-channels.d.ts +1 -1
- package/dist/{channel → events/channel}/log-channels.js +1 -1
- package/dist/{channel → events/channel}/serverless/serverless-channel-runner.js +11 -11
- package/dist/{http → events/http}/http-runner.d.ts +2 -2
- package/dist/{http → events/http}/http-runner.js +30 -19
- package/dist/{http → events/http}/http.types.d.ts +4 -3
- package/dist/{http → events/http}/index.d.ts +0 -1
- package/dist/{http → events/http}/index.js +0 -1
- package/dist/{http → events/http}/log-http-routes.d.ts +1 -1
- package/dist/{http → events/http}/log-http-routes.js +1 -1
- package/dist/{http → events/http}/pikku-fetch-http-request.js +1 -1
- package/dist/events/mcp/index.d.ts +2 -0
- package/dist/events/mcp/index.js +2 -0
- package/dist/events/mcp/mcp-runner.d.ts +30 -0
- package/dist/events/mcp/mcp-runner.js +192 -0
- package/dist/events/mcp/mcp.types.d.ts +117 -0
- package/dist/events/queue/index.d.ts +6 -0
- package/dist/events/queue/index.js +6 -0
- package/dist/events/queue/queue-runner.d.ts +24 -0
- package/dist/events/queue/queue-runner.js +83 -0
- package/dist/events/queue/queue.types.d.ts +154 -0
- package/dist/events/queue/register-queue-helper.d.ts +17 -0
- package/dist/events/queue/register-queue-helper.js +34 -0
- package/dist/events/queue/validate-worker-config.d.ts +41 -0
- package/dist/events/queue/validate-worker-config.js +50 -0
- package/dist/events/rpc/index.d.ts +2 -0
- package/dist/events/rpc/rpc-runner.d.ts +28 -0
- package/dist/{rpc → events/rpc}/rpc-runner.js +2 -2
- package/dist/events/scheduler/index.d.ts +3 -0
- package/dist/events/scheduler/index.js +3 -0
- package/dist/{scheduler → events/scheduler}/log-schedulers.d.ts +1 -1
- package/dist/{scheduler → events/scheduler}/log-schedulers.js +1 -1
- package/dist/{scheduler → events/scheduler}/scheduler-runner.d.ts +4 -3
- package/dist/{scheduler → events/scheduler}/scheduler-runner.js +7 -4
- package/dist/{scheduler → events/scheduler}/scheduler.types.d.ts +3 -4
- package/dist/function/function-runner.js +8 -0
- package/dist/function/functions.types.d.ts +3 -2
- package/dist/handle-error.d.ts +2 -2
- package/dist/handle-error.js +1 -1
- package/dist/index.d.ts +10 -6
- package/dist/index.js +10 -6
- package/dist/middleware-runner.d.ts +4 -4
- package/dist/middleware-runner.js +4 -2
- package/dist/pikku-state.d.ts +18 -4
- package/dist/pikku-state.js +12 -0
- package/dist/services/user-session-service.d.ts +1 -1
- package/dist/types/core.types.d.ts +22 -4
- package/dist/types/core.types.js +9 -1
- package/lcov.info +3557 -3476
- package/package.json +8 -7
- package/src/errors/error-handler.ts +2 -1
- package/src/errors/errors.ts +2 -0
- package/src/{channel → events/channel}/channel-handler.ts +3 -3
- package/src/{channel → events/channel}/channel-runner.ts +9 -9
- package/src/{channel → events/channel}/channel-store.ts +1 -1
- package/src/{channel → events/channel}/channel.types.ts +5 -9
- package/src/{channel → events/channel}/local/local-channel-runner.test.ts +1 -1
- package/src/{channel → events/channel}/local/local-channel-runner.ts +11 -11
- package/src/{channel → events/channel}/local/local-eventhub-service.test.ts +1 -1
- package/src/{channel → events/channel}/log-channels.ts +2 -2
- package/src/{channel → events/channel}/serverless/serverless-channel-runner.ts +12 -12
- package/src/{http → events/http}/http-runner.test.ts +4 -4
- package/src/{http → events/http}/http-runner.ts +39 -20
- package/src/{http → events/http}/http.types.ts +4 -3
- package/src/{http → events/http}/index.ts +0 -1
- package/src/{http → events/http}/log-http-routes.ts +2 -2
- package/src/{http → events/http}/pikku-fetch-http-request.ts +1 -1
- package/src/events/mcp/index.ts +2 -0
- package/src/events/mcp/mcp-runner.ts +321 -0
- package/src/events/mcp/mcp.types.ts +150 -0
- package/src/events/queue/index.ts +18 -0
- package/src/events/queue/queue-runner.ts +125 -0
- package/src/events/queue/queue.types.ts +176 -0
- package/src/events/queue/register-queue-helper.ts +62 -0
- package/src/events/queue/validate-worker-config.ts +113 -0
- package/src/events/rpc/index.ts +2 -0
- package/src/{rpc → events/rpc}/rpc-runner.ts +3 -3
- package/src/events/scheduler/index.ts +9 -0
- package/src/{scheduler → events/scheduler}/log-schedulers.ts +2 -2
- package/src/{scheduler → events/scheduler}/scheduler-runner.ts +11 -10
- package/src/{scheduler → events/scheduler}/scheduler.types.ts +2 -4
- package/src/function/function-runner.ts +19 -1
- package/src/function/functions.types.ts +3 -1
- package/src/handle-error.ts +2 -2
- package/src/index.ts +23 -6
- package/src/middleware-runner.ts +14 -7
- package/src/pikku-state.ts +40 -4
- package/src/services/user-session-service.ts +1 -1
- package/src/types/core.types.ts +31 -4
- package/tsconfig.json +3 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/rpc/index.d.ts +0 -2
- package/dist/rpc/rpc-runner.d.ts +0 -27
- package/dist/scheduler/index.d.ts +0 -3
- package/dist/scheduler/index.js +0 -3
- package/src/http/incomingmessage-to-request-convertor.ts +0 -0
- package/src/rpc/index.ts +0 -2
- package/src/scheduler/index.ts +0 -5
- /package/dist/{channel → events/channel}/channel-store.js +0 -0
- /package/dist/{channel → events/channel}/channel.types.js +0 -0
- /package/dist/{channel → events/channel}/eventhub-service.d.ts +0 -0
- /package/dist/{channel → events/channel}/eventhub-service.js +0 -0
- /package/dist/{channel → events/channel}/eventhub-store.d.ts +0 -0
- /package/dist/{channel → events/channel}/eventhub-store.js +0 -0
- /package/dist/{channel → events/channel}/index.d.ts +0 -0
- /package/dist/{channel → events/channel}/index.js +0 -0
- /package/dist/{channel → events/channel}/local/index.d.ts +0 -0
- /package/dist/{channel → events/channel}/local/index.js +0 -0
- /package/dist/{channel → events/channel}/local/local-channel-handler.d.ts +0 -0
- /package/dist/{channel → events/channel}/local/local-channel-handler.js +0 -0
- /package/dist/{channel → events/channel}/local/local-channel-runner.d.ts +0 -0
- /package/dist/{channel → events/channel}/local/local-eventhub-service.d.ts +0 -0
- /package/dist/{channel → events/channel}/local/local-eventhub-service.js +0 -0
- /package/dist/{channel → events/channel}/pikku-abstract-channel-handler.d.ts +0 -0
- /package/dist/{channel → events/channel}/pikku-abstract-channel-handler.js +0 -0
- /package/dist/{channel → events/channel}/serverless/index.d.ts +0 -0
- /package/dist/{channel → events/channel}/serverless/index.js +0 -0
- /package/dist/{channel → events/channel}/serverless/serverless-channel-runner.d.ts +0 -0
- /package/dist/{http → events/http}/http.types.js +0 -0
- /package/dist/{http → events/http}/pikku-fetch-http-request.d.ts +0 -0
- /package/dist/{http → events/http}/pikku-fetch-http-response.d.ts +0 -0
- /package/dist/{http → events/http}/pikku-fetch-http-response.js +0 -0
- /package/dist/{http/incomingmessage-to-request-convertor.d.ts → events/mcp/mcp.types.js} +0 -0
- /package/dist/{http/incomingmessage-to-request-convertor.js → events/queue/queue.types.js} +0 -0
- /package/dist/{rpc → events/rpc}/index.js +0 -0
- /package/dist/{rpc → events/rpc}/rpc-types.d.ts +0 -0
- /package/dist/{rpc → events/rpc}/rpc-types.js +0 -0
- /package/dist/{scheduler → events/scheduler}/scheduler.types.js +0 -0
- /package/src/{channel → events/channel}/eventhub-service.ts +0 -0
- /package/src/{channel → events/channel}/eventhub-store.ts +0 -0
- /package/src/{channel → events/channel}/index.ts +0 -0
- /package/src/{channel → events/channel}/local/index.ts +0 -0
- /package/src/{channel → events/channel}/local/local-channel-handler.ts +0 -0
- /package/src/{channel → events/channel}/local/local-eventhub-service.ts +0 -0
- /package/src/{channel → events/channel}/pikku-abstract-channel-handler.test.ts +0 -0
- /package/src/{channel → events/channel}/pikku-abstract-channel-handler.ts +0 -0
- /package/src/{channel → events/channel}/serverless/index.ts +0 -0
- /package/src/{http → events/http}/pikku-fetch-http-request.test.ts +0 -0
- /package/src/{http → events/http}/pikku-fetch-http-response.test.ts +0 -0
- /package/src/{http → events/http}/pikku-fetch-http-response.ts +0 -0
- /package/src/{rpc → events/rpc}/rpc-types.ts +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates worker configuration using a mapping table
|
|
3
|
+
* This provides a flexible, maintainable way to validate configurations
|
|
4
|
+
* across different queue implementations
|
|
5
|
+
*
|
|
6
|
+
* @param config - The worker configuration to validate
|
|
7
|
+
* @param configMapping - The mapping table defining supported/unsupported configurations
|
|
8
|
+
* @returns Validation result with applied, ignored, warnings, and fallbacks
|
|
9
|
+
*/
|
|
10
|
+
export function validateWorkerConfig(configMapping, config = {}) {
|
|
11
|
+
const applied = {};
|
|
12
|
+
const ignored = {};
|
|
13
|
+
const warnings = [];
|
|
14
|
+
const fallbacks = {};
|
|
15
|
+
// Process each configuration property
|
|
16
|
+
for (const [key, value] of Object.entries(config)) {
|
|
17
|
+
if (value === undefined)
|
|
18
|
+
continue;
|
|
19
|
+
const configKey = key;
|
|
20
|
+
// Check if it's a supported configuration
|
|
21
|
+
if (configKey in configMapping.supported) {
|
|
22
|
+
applied[configKey] = value;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
// Check if it's a fallback configuration
|
|
26
|
+
if (configKey in configMapping.fallbacks) {
|
|
27
|
+
const fallbackMapping = configMapping.fallbacks[configKey];
|
|
28
|
+
applied[configKey] = value;
|
|
29
|
+
fallbacks[key] = fallbackMapping.fallbackValue;
|
|
30
|
+
warnings.push(`${key}: ${fallbackMapping.reason}. ${fallbackMapping.explanation}`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
// Check if it's an unsupported configuration
|
|
34
|
+
if (configKey in configMapping.unsupported) {
|
|
35
|
+
ignored[configKey] = value;
|
|
36
|
+
const mapping = configMapping.unsupported[configKey];
|
|
37
|
+
warnings.push(`${key}: ${mapping.reason}. ${mapping.explanation}`);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// Unknown configuration
|
|
41
|
+
ignored[configKey] = value;
|
|
42
|
+
warnings.push(`${key}: Unknown configuration option for this queue implementation`);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
applied,
|
|
46
|
+
ignored,
|
|
47
|
+
warnings,
|
|
48
|
+
fallbacks,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CoreServices } from '../../types/core.types.js';
|
|
2
|
+
type RPCServiceConfig = {
|
|
3
|
+
coerceDataFromSchema: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare class PikkuRPCService {
|
|
6
|
+
private config?;
|
|
7
|
+
initialize(config: RPCServiceConfig): void;
|
|
8
|
+
injectRPCService(coreServices: CoreServices, depth?: number): {
|
|
9
|
+
jwt?: import("../../index.js").JWTService;
|
|
10
|
+
schema?: import("../../index.js").SchemaService;
|
|
11
|
+
config: {
|
|
12
|
+
logLevel?: import("../../index.js").LogLevel;
|
|
13
|
+
secrets?: {};
|
|
14
|
+
};
|
|
15
|
+
logger: import("../../index.js").Logger;
|
|
16
|
+
variables: import("../../index.js").VariablesService;
|
|
17
|
+
eventHub?: import("../channel/eventhub-service.js").EventHubService<unknown>;
|
|
18
|
+
secrets?: import("../../index.js").SecretService;
|
|
19
|
+
http?: import("../http/http.types.js").PikkuHTTP;
|
|
20
|
+
mcp?: import("../mcp/mcp.types.js").PikkuMCP;
|
|
21
|
+
rpc?: import("./rpc-types.js").PikkuRPC;
|
|
22
|
+
userSession?: import("../../index.js").UserSessionService<import("../../types/core.types.js").CoreUserSession> | undefined;
|
|
23
|
+
channel?: import("../channel/channel.types.js").PikkuChannel<unknown, unknown>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare const rpcService: PikkuRPCService;
|
|
27
|
+
export declare const initialize: (config: RPCServiceConfig) => void;
|
|
28
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { runPikkuFunc } from '
|
|
2
|
-
import { pikkuState } from '
|
|
1
|
+
import { runPikkuFunc } from '../../function/function-runner.js';
|
|
2
|
+
import { pikkuState } from '../../pikku-state.js';
|
|
3
3
|
const getRPCMeta = (rpcName) => {
|
|
4
4
|
const rpc = pikkuState('rpc', 'meta');
|
|
5
5
|
const rpcMeta = rpc[rpcName];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CoreServices, CoreSingletonServices, CoreUserSession, CreateSessionServices } from '
|
|
1
|
+
import type { CoreServices, CoreSingletonServices, CoreUserSession, CreateSessionServices } from '../../types/core.types.js';
|
|
2
2
|
import type { CoreScheduledTask } from './scheduler.types.js';
|
|
3
|
-
import type { CoreAPIFunctionSessionless } from '
|
|
3
|
+
import type { CoreAPIFunctionSessionless } from '../../function/functions.types.js';
|
|
4
4
|
export type RunScheduledTasksParams = {
|
|
5
5
|
name: string;
|
|
6
6
|
session?: CoreUserSession;
|
|
@@ -8,4 +8,5 @@ export type RunScheduledTasksParams = {
|
|
|
8
8
|
createSessionServices?: CreateSessionServices<CoreSingletonServices, CoreServices<CoreSingletonServices>, CoreUserSession>;
|
|
9
9
|
};
|
|
10
10
|
export declare const addScheduledTask: <APIFunction extends CoreAPIFunctionSessionless<void, void>>(scheduledTask: CoreScheduledTask<APIFunction>) => void;
|
|
11
|
-
export declare function runScheduledTask
|
|
11
|
+
export declare function runScheduledTask({ name, session, singletonServices, createSessionServices, }: RunScheduledTasksParams): Promise<void>;
|
|
12
|
+
export declare const getScheduledTasks: () => Map<string, CoreScheduledTask>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getErrorResponse } from '
|
|
2
|
-
import { closeSessionServices } from '
|
|
3
|
-
import { pikkuState } from '
|
|
4
|
-
import { addFunction, runPikkuFunc } from '
|
|
1
|
+
import { getErrorResponse } from '../../errors/error-handler.js';
|
|
2
|
+
import { closeSessionServices } from '../../utils.js';
|
|
3
|
+
import { pikkuState } from '../../pikku-state.js';
|
|
4
|
+
import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
|
|
5
5
|
import { rpcService } from '../rpc/rpc-runner.js';
|
|
6
6
|
export const addScheduledTask = (scheduledTask) => {
|
|
7
7
|
const meta = pikkuState('scheduler', 'meta');
|
|
@@ -64,3 +64,6 @@ export async function runScheduledTask({ name, session, singletonServices, creat
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
export const getScheduledTasks = () => {
|
|
68
|
+
return pikkuState('scheduler', 'tasks');
|
|
69
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { APIDocs, CoreUserSession } from '
|
|
2
|
-
import { CoreAPIFunctionSessionless } from '
|
|
1
|
+
import { APIDocs, CoreUserSession } from '../../types/core.types.js';
|
|
2
|
+
import { CoreAPIFunctionSessionless } from '../../function/functions.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Represents metadata for scheduled tasks, including title, schedule, and documentation.
|
|
5
5
|
*/
|
|
@@ -14,11 +14,10 @@ export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> = Reco
|
|
|
14
14
|
/**
|
|
15
15
|
* Represents a core scheduled task.
|
|
16
16
|
*/
|
|
17
|
-
export type CoreScheduledTask<APIFunction = CoreAPIFunctionSessionless<void, void
|
|
17
|
+
export type CoreScheduledTask<APIFunction = CoreAPIFunctionSessionless<void, void>> = {
|
|
18
18
|
name: string;
|
|
19
19
|
schedule: string;
|
|
20
20
|
func: APIFunction;
|
|
21
21
|
docs?: APIDocs;
|
|
22
|
-
session?: UserSession;
|
|
23
22
|
tags?: string[];
|
|
24
23
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ForbiddenError } from '../errors/errors.js';
|
|
2
|
+
import { runMiddleware } from '../middleware-runner.js';
|
|
2
3
|
import { verifyPermissions } from '../permissions.js';
|
|
3
4
|
import { pikkuState } from '../pikku-state.js';
|
|
4
5
|
import { coerceTopLevelDataFromSchema, validateSchema } from '../schema.js';
|
|
@@ -76,5 +77,12 @@ export const runPikkuFunc = async (funcName, { getAllServices, data, session, pe
|
|
|
76
77
|
if (permissioned === false) {
|
|
77
78
|
throw new ForbiddenError('Permission denied');
|
|
78
79
|
}
|
|
80
|
+
if (funcConfig.middleware) {
|
|
81
|
+
return (await runMiddleware(allServices, {
|
|
82
|
+
http: allServices.http,
|
|
83
|
+
mcp: allServices.mcp,
|
|
84
|
+
rpc: allServices.rpc,
|
|
85
|
+
}, funcConfig.middleware, async () => await funcConfig.func(allServices, data, session)));
|
|
86
|
+
}
|
|
79
87
|
return (await funcConfig.func(allServices, data, session));
|
|
80
88
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PikkuChannel } from '../channel/channel.types.js';
|
|
2
|
-
import type { CoreServices, CoreSingletonServices, CoreUserSession } from '../types/core.types.js';
|
|
1
|
+
import { PikkuChannel } from '../events/channel/channel.types.js';
|
|
2
|
+
import type { CoreServices, CoreSingletonServices, CoreUserSession, PikkuFunctionMiddleware } 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
|
*
|
|
@@ -39,4 +39,5 @@ export type CorePikkuFunctionConfig<APIFunction extends CoreAPIFunction<any, any
|
|
|
39
39
|
func: APIFunction;
|
|
40
40
|
auth?: boolean;
|
|
41
41
|
permissions?: CorePermissionGroup<APIPermission>;
|
|
42
|
+
middleware?: PikkuFunctionMiddleware[];
|
|
42
43
|
};
|
package/dist/handle-error.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger } from './services/logger.js';
|
|
2
|
-
import { PikkuHTTP } from './http/http.types.js';
|
|
2
|
+
import { PikkuHTTP } from './events/http/http.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Handle errors that occur during route processing
|
|
5
5
|
*
|
|
@@ -11,4 +11,4 @@ import { PikkuHTTP } from './http/http.types.js';
|
|
|
11
11
|
* @param {boolean} respondWith404 - Whether to respond with 404 for NotFoundError
|
|
12
12
|
* @param {boolean} bubbleError - Whether to throw the error after handling
|
|
13
13
|
*/
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const handleHTTPError: (e: any, http: PikkuHTTP | undefined, trackerId: string | undefined, logger: Logger, logWarningsForStatusCodes: number[], respondWith404: boolean, bubbleError: boolean) => void;
|
package/dist/handle-error.js
CHANGED
|
@@ -11,7 +11,7 @@ import { NotFoundError } from './errors/errors.js';
|
|
|
11
11
|
* @param {boolean} respondWith404 - Whether to respond with 404 for NotFoundError
|
|
12
12
|
* @param {boolean} bubbleError - Whether to throw the error after handling
|
|
13
13
|
*/
|
|
14
|
-
export const
|
|
14
|
+
export const handleHTTPError = (e, http, trackerId, logger, logWarningsForStatusCodes, respondWith404, bubbleError) => {
|
|
15
15
|
// Skip 404 handling if configured to do so
|
|
16
16
|
if (e instanceof NotFoundError && !respondWith404) {
|
|
17
17
|
return;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,15 +6,19 @@ export * from './function/index.js';
|
|
|
6
6
|
export * from './pikku-request.js';
|
|
7
7
|
export * from './pikku-response.js';
|
|
8
8
|
export * from './services/index.js';
|
|
9
|
-
export * from './http/index.js';
|
|
10
|
-
export * from './channel/index.js';
|
|
11
|
-
export * from './scheduler/index.js';
|
|
9
|
+
export * from './events/http/index.js';
|
|
10
|
+
export * from './events/channel/index.js';
|
|
11
|
+
export * from './events/scheduler/index.js';
|
|
12
|
+
export * from './events/rpc/index.js';
|
|
13
|
+
export * from './events/queue/index.js';
|
|
14
|
+
export * from './events/mcp/index.js';
|
|
12
15
|
export * from './errors/index.js';
|
|
13
16
|
export * from './middleware/index.js';
|
|
14
17
|
export * from './time-utils.js';
|
|
15
18
|
export * from './utils.js';
|
|
16
19
|
export { pikkuState } from './pikku-state.js';
|
|
17
20
|
export { runMiddleware } from './middleware-runner.js';
|
|
18
|
-
export { addHTTPRoute, addMiddleware } from './http/http-runner.js';
|
|
19
|
-
export { addChannel } from './channel/channel-runner.js';
|
|
20
|
-
export { addScheduledTask } from './scheduler/scheduler-runner.js';
|
|
21
|
+
export { addHTTPRoute, addMiddleware } from './events/http/http-runner.js';
|
|
22
|
+
export { addChannel } from './events/channel/channel-runner.js';
|
|
23
|
+
export { addScheduledTask } from './events/scheduler/scheduler-runner.js';
|
|
24
|
+
export { addMCPResource, addMCPTool, addMCPPrompt, runMCPResource, runMCPTool, runMCPPrompt, getMCPTools, getMCPResources, getMCPPrompts, getMCPResourcesMeta, getMCPToolsMeta, getMCPPromptsMeta, } from './events/mcp/mcp-runner.js';
|
package/dist/index.js
CHANGED
|
@@ -6,15 +6,19 @@ export * from './function/index.js';
|
|
|
6
6
|
export * from './pikku-request.js';
|
|
7
7
|
export * from './pikku-response.js';
|
|
8
8
|
export * from './services/index.js';
|
|
9
|
-
export * from './http/index.js';
|
|
10
|
-
export * from './channel/index.js';
|
|
11
|
-
export * from './scheduler/index.js';
|
|
9
|
+
export * from './events/http/index.js';
|
|
10
|
+
export * from './events/channel/index.js';
|
|
11
|
+
export * from './events/scheduler/index.js';
|
|
12
|
+
export * from './events/rpc/index.js';
|
|
13
|
+
export * from './events/queue/index.js';
|
|
14
|
+
export * from './events/mcp/index.js';
|
|
12
15
|
export * from './errors/index.js';
|
|
13
16
|
export * from './middleware/index.js';
|
|
14
17
|
export * from './time-utils.js';
|
|
15
18
|
export * from './utils.js';
|
|
16
19
|
export { pikkuState } from './pikku-state.js';
|
|
17
20
|
export { runMiddleware } from './middleware-runner.js';
|
|
18
|
-
export { addHTTPRoute, addMiddleware } from './http/http-runner.js';
|
|
19
|
-
export { addChannel } from './channel/channel-runner.js';
|
|
20
|
-
export { addScheduledTask } from './scheduler/scheduler-runner.js';
|
|
21
|
+
export { addHTTPRoute, addMiddleware } from './events/http/http-runner.js';
|
|
22
|
+
export { addChannel } from './events/channel/channel-runner.js';
|
|
23
|
+
export { addScheduledTask } from './events/scheduler/scheduler-runner.js';
|
|
24
|
+
export { addMCPResource, addMCPTool, addMCPPrompt, runMCPResource, runMCPTool, runMCPPrompt, getMCPTools, getMCPResources, getMCPPrompts, getMCPResourcesMeta, getMCPToolsMeta, getMCPPromptsMeta, } from './events/mcp/mcp-runner.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserSessionService } from './services/user-session-service.js';
|
|
2
|
-
import { CoreSingletonServices, PikkuInteraction, PikkuMiddleware } from './types/core.types.js';
|
|
2
|
+
import { CoreSingletonServices, PikkuFunctionMiddleware, PikkuInteraction, PikkuMiddleware } 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, PikkuInteraction, PikkuMiddleware } from './type
|
|
|
17
17
|
* async () => { return await runMain(); }
|
|
18
18
|
* );
|
|
19
19
|
*/
|
|
20
|
-
export declare const runMiddleware: (services: CoreSingletonServices & {
|
|
21
|
-
userSession
|
|
22
|
-
}, interaction: PikkuInteraction, middlewares:
|
|
20
|
+
export declare const runMiddleware: <Middleware extends PikkuMiddleware | PikkuFunctionMiddleware = PikkuMiddleware>(services: CoreSingletonServices & {
|
|
21
|
+
userSession?: UserSessionService<any>;
|
|
22
|
+
}, interaction: PikkuInteraction, middlewares: Middleware[], main?: () => Promise<unknown>) => Promise<unknown>;
|
|
@@ -16,13 +16,15 @@
|
|
|
16
16
|
* );
|
|
17
17
|
*/
|
|
18
18
|
export const runMiddleware = async (services, interaction, middlewares, main) => {
|
|
19
|
+
let result;
|
|
19
20
|
const dispatch = async (index) => {
|
|
20
21
|
if (middlewares && index < middlewares.length) {
|
|
21
|
-
await middlewares[index](services, interaction, () => dispatch(index + 1));
|
|
22
|
+
return await middlewares[index](services, interaction, () => dispatch(index + 1));
|
|
22
23
|
}
|
|
23
24
|
else if (main) {
|
|
24
|
-
|
|
25
|
+
result = await main();
|
|
25
26
|
}
|
|
26
27
|
};
|
|
27
28
|
await dispatch(0);
|
|
29
|
+
return result;
|
|
28
30
|
};
|
package/dist/pikku-state.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { ChannelsMeta, CoreAPIChannel } from './channel/channel.types.js';
|
|
2
|
-
import { CoreHTTPFunctionRoute, HTTPMethod, HTTPRoutesMeta } from './http/http.types.js';
|
|
1
|
+
import { ChannelsMeta, CoreAPIChannel } from './events/channel/channel.types.js';
|
|
2
|
+
import { CoreHTTPFunctionRoute, HTTPMethod, HTTPRoutesMeta } from './events/http/http.types.js';
|
|
3
3
|
import { FunctionsMeta, PikkuMiddleware } from './types/core.types.js';
|
|
4
|
-
import { CoreScheduledTask, ScheduledTasksMeta } from './scheduler/scheduler.types.js';
|
|
4
|
+
import { CoreScheduledTask, ScheduledTasksMeta } from './events/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 './rpc/rpc-types.js';
|
|
7
|
+
import { RPCMeta } from './events/rpc/rpc-types.js';
|
|
8
|
+
import { queueWorkersMeta, CoreQueueWorker } from './events/queue/queue.types.js';
|
|
9
|
+
import { CoreMCPResource, CoreMCPTool, CoreMCPPrompt, MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from './events/mcp/mcp.types.js';
|
|
8
10
|
interface PikkuState {
|
|
9
11
|
function: {
|
|
10
12
|
meta: FunctionsMeta;
|
|
@@ -33,6 +35,18 @@ interface PikkuState {
|
|
|
33
35
|
tasks: Map<string, CoreScheduledTask>;
|
|
34
36
|
meta: ScheduledTasksMeta;
|
|
35
37
|
};
|
|
38
|
+
queue: {
|
|
39
|
+
registrations: Map<string, CoreQueueWorker>;
|
|
40
|
+
meta: queueWorkersMeta;
|
|
41
|
+
};
|
|
42
|
+
mcp: {
|
|
43
|
+
resources: Map<string, CoreMCPResource>;
|
|
44
|
+
resourcesMeta: MCPResourceMeta;
|
|
45
|
+
tools: Map<string, CoreMCPTool>;
|
|
46
|
+
toolsMeta: MCPToolMeta;
|
|
47
|
+
prompts: Map<string, CoreMCPPrompt>;
|
|
48
|
+
promptsMeta: MCPPromptMeta;
|
|
49
|
+
};
|
|
36
50
|
misc: {
|
|
37
51
|
errors: Map<PikkuError, ErrorDetails>;
|
|
38
52
|
schemas: Map<string, any>;
|
package/dist/pikku-state.js
CHANGED
|
@@ -21,6 +21,18 @@ export const resetPikkuState = () => {
|
|
|
21
21
|
tasks: new Map(),
|
|
22
22
|
meta: [],
|
|
23
23
|
},
|
|
24
|
+
queue: {
|
|
25
|
+
registrations: new Map(),
|
|
26
|
+
meta: {},
|
|
27
|
+
},
|
|
28
|
+
mcp: {
|
|
29
|
+
resources: new Map(),
|
|
30
|
+
resourcesMeta: {},
|
|
31
|
+
tools: new Map(),
|
|
32
|
+
toolsMeta: {},
|
|
33
|
+
prompts: new Map(),
|
|
34
|
+
promptsMeta: {},
|
|
35
|
+
},
|
|
24
36
|
misc: {
|
|
25
37
|
errors: globalThis.pikkuState?.misc?.errors || new Map(),
|
|
26
38
|
schemas: globalThis.pikkuState?.misc?.schema || new Map(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChannelStore } from '../channel/channel-store.js';
|
|
1
|
+
import { ChannelStore } from '../events/channel/channel-store.js';
|
|
2
2
|
import { CoreUserSession } from '../types/core.types.js';
|
|
3
3
|
export interface UserSessionService<UserSession extends CoreUserSession> {
|
|
4
4
|
sessionChanged: boolean;
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import type { Logger, LogLevel } from '../services/logger.js';
|
|
2
2
|
import { VariablesService } from '../services/variables-service.js';
|
|
3
|
-
import { EventHubService } from '../channel/eventhub-service.js';
|
|
3
|
+
import { EventHubService } from '../events/channel/eventhub-service.js';
|
|
4
4
|
import { SchemaService } from '../services/schema-service.js';
|
|
5
|
-
import { PikkuHTTP } from '../http/http.types.js';
|
|
5
|
+
import { PikkuHTTP } from '../events/http/http.types.js';
|
|
6
6
|
import { UserSessionService } from '../services/user-session-service.js';
|
|
7
7
|
import { JWTService } from '../services/jwt-service.js';
|
|
8
8
|
import { SecretService } from '../services/secret-service.js';
|
|
9
|
-
import { PikkuChannel } from '../channel/channel.types.js';
|
|
10
|
-
import { PikkuRPC } from '../rpc/rpc-types.js';
|
|
9
|
+
import { PikkuChannel } from '../events/channel/channel.types.js';
|
|
10
|
+
import { PikkuRPC } from '../events/rpc/rpc-types.js';
|
|
11
|
+
import { PikkuMCP } from '../events/mcp/mcp.types.js';
|
|
12
|
+
export declare enum PikkuEventTypes {
|
|
13
|
+
http = "http",
|
|
14
|
+
scheduled = "scheduled",
|
|
15
|
+
channel = "channel",
|
|
16
|
+
rpc = "rpc",
|
|
17
|
+
queue = "queue",
|
|
18
|
+
mcp = "mcp"
|
|
19
|
+
}
|
|
11
20
|
export interface FunctionServicesMeta {
|
|
12
21
|
optimized: boolean;
|
|
13
22
|
services: string[];
|
|
@@ -83,7 +92,15 @@ export interface CoreSingletonServices<Config extends CoreConfig = CoreConfig> {
|
|
|
83
92
|
*/
|
|
84
93
|
export interface PikkuInteraction {
|
|
85
94
|
http?: PikkuHTTP;
|
|
95
|
+
mcp?: PikkuMCP;
|
|
96
|
+
rpc?: PikkuRPC;
|
|
86
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* A function that can wrap an interaction and be called before or after
|
|
100
|
+
*/
|
|
101
|
+
export type PikkuFunctionMiddleware<SingletonServices extends CoreSingletonServices = CoreSingletonServices, UserSession extends CoreUserSession = CoreUserSession> = (services: SingletonServices & {
|
|
102
|
+
userSession?: UserSessionService<UserSession>;
|
|
103
|
+
}, interactions: PikkuInteraction, next: () => Promise<void>) => Promise<void>;
|
|
87
104
|
/**
|
|
88
105
|
* A function that can wrap an interaction and be called before or after
|
|
89
106
|
*/
|
|
@@ -94,6 +111,7 @@ export type PikkuMiddleware<SingletonServices extends CoreSingletonServices = Co
|
|
|
94
111
|
* Represents the core services used by Pikku, including singleton services and the request/response interaction.
|
|
95
112
|
*/
|
|
96
113
|
export type CoreServices<SingletonServices = CoreSingletonServices, UserSession extends CoreUserSession = CoreUserSession, CoreServices extends Record<string, unknown> = {}> = SingletonServices & PikkuInteraction & {
|
|
114
|
+
mcp?: PikkuMCP;
|
|
97
115
|
rpc?: PikkuRPC;
|
|
98
116
|
userSession?: UserSessionService<UserSession>;
|
|
99
117
|
channel?: PikkuChannel<unknown, unknown>;
|
package/dist/types/core.types.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var PikkuEventTypes;
|
|
2
|
+
(function (PikkuEventTypes) {
|
|
3
|
+
PikkuEventTypes["http"] = "http";
|
|
4
|
+
PikkuEventTypes["scheduled"] = "scheduled";
|
|
5
|
+
PikkuEventTypes["channel"] = "channel";
|
|
6
|
+
PikkuEventTypes["rpc"] = "rpc";
|
|
7
|
+
PikkuEventTypes["queue"] = "queue";
|
|
8
|
+
PikkuEventTypes["mcp"] = "mcp";
|
|
9
|
+
})(PikkuEventTypes || (PikkuEventTypes = {}));
|