@pikku/core 0.8.2 → 0.9.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 +7 -1
- package/dist/function/functions.types.d.ts +9 -9
- package/dist/handle-error.d.ts +1 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.js +11 -10
- package/dist/pikku-state.d.ts +9 -9
- package/dist/services/user-session-service.d.ts +1 -1
- package/dist/types/core.types.d.ts +5 -5
- package/dist/types/core.types.js +9 -9
- package/dist/wirings/channel/channel-handler.d.ts +3 -0
- package/dist/{events → wirings}/channel/channel-handler.js +3 -3
- package/dist/wirings/channel/channel-runner.d.ts +14 -0
- package/dist/{events → wirings}/channel/channel-runner.js +13 -13
- package/dist/{events → wirings}/channel/channel.types.d.ts +7 -7
- package/dist/{events → wirings}/channel/eventhub-service.d.ts +4 -4
- package/dist/wirings/channel/eventhub-store.d.ts +5 -0
- package/dist/wirings/channel/local/local-channel-runner.d.ts +3 -0
- package/dist/{events → wirings}/channel/local/local-eventhub-service.d.ts +4 -4
- package/dist/{events → wirings}/channel/local/local-eventhub-service.js +1 -1
- package/dist/{events → wirings}/channel/serverless/serverless-channel-runner.d.ts +2 -2
- package/dist/{events → wirings}/http/http-runner.d.ts +12 -12
- package/dist/{events → wirings}/http/http-runner.js +15 -15
- package/dist/{events → wirings}/http/http.types.d.ts +32 -27
- package/dist/{events → wirings}/http/index.d.ts +1 -1
- package/dist/{events → wirings}/http/index.js +1 -1
- package/dist/{events → wirings}/mcp/mcp-runner.d.ts +4 -4
- package/dist/{events → wirings}/mcp/mcp-runner.js +4 -4
- package/dist/{events → wirings}/mcp/mcp.types.d.ts +7 -7
- package/dist/{events → wirings}/queue/index.d.ts +1 -1
- package/dist/{events → wirings}/queue/index.js +1 -1
- package/dist/{events → wirings}/queue/queue-runner.d.ts +2 -2
- package/dist/{events → wirings}/queue/queue-runner.js +1 -1
- package/dist/{events → wirings}/queue/queue.types.d.ts +3 -3
- package/dist/wirings/scheduler/index.d.ts +3 -0
- package/dist/wirings/scheduler/index.js +3 -0
- package/dist/{events → wirings}/scheduler/scheduler-runner.d.ts +2 -2
- package/dist/{events → wirings}/scheduler/scheduler-runner.js +1 -1
- package/dist/{events → wirings}/scheduler/scheduler.types.d.ts +3 -3
- package/lcov.info +5680 -0
- package/package.json +9 -9
- package/src/function/functions.types.ts +13 -13
- package/src/handle-error.ts +1 -1
- package/src/index.ts +14 -13
- package/src/pikku-state.ts +11 -11
- package/src/services/user-session-service.ts +1 -1
- package/src/types/core.types.ts +5 -5
- package/src/{events → wirings}/channel/channel-handler.ts +5 -5
- package/src/{events → wirings}/channel/channel-runner.ts +18 -18
- package/src/{events → wirings}/channel/channel.types.ts +16 -16
- package/src/{events → wirings}/channel/eventhub-service.ts +12 -8
- package/src/wirings/channel/eventhub-store.ts +13 -0
- package/src/{events → wirings}/channel/local/local-channel-runner.test.ts +2 -2
- package/src/{events → wirings}/channel/local/local-channel-runner.ts +2 -2
- package/src/{events → wirings}/channel/local/local-eventhub-service.ts +16 -10
- package/src/{events → wirings}/channel/serverless/serverless-channel-runner.ts +2 -2
- package/src/{events → wirings}/http/http-runner.test.ts +4 -4
- package/src/{events → wirings}/http/http-runner.ts +32 -31
- package/src/{events → wirings}/http/http.types.ts +40 -35
- package/src/{events → wirings}/http/index.ts +1 -1
- package/src/wirings/mcp/mcp-endpoint-registry.test.js +338 -0
- package/src/wirings/mcp/mcp-endpoint-registry.test.js.map +1 -0
- package/src/{events → wirings}/mcp/mcp-runner.ts +10 -10
- package/src/{events → wirings}/mcp/mcp.types.ts +9 -7
- package/src/{events → wirings}/queue/index.ts +1 -1
- package/src/{events → wirings}/queue/queue-runner.ts +5 -5
- package/src/{events → wirings}/queue/queue.types.ts +3 -3
- package/src/{events → wirings}/scheduler/index.ts +1 -1
- package/src/{events → wirings}/scheduler/scheduler-runner.ts +4 -4
- package/src/{events → wirings}/scheduler/scheduler.types.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/events/channel/channel-handler.d.ts +0 -3
- package/dist/events/channel/channel-runner.d.ts +0 -14
- package/dist/events/channel/eventhub-store.d.ts +0 -5
- package/dist/events/channel/local/local-channel-runner.d.ts +0 -3
- package/dist/events/scheduler/index.d.ts +0 -3
- package/dist/events/scheduler/index.js +0 -3
- package/src/events/channel/eventhub-store.ts +0 -8
- /package/dist/{events → wirings}/channel/channel-store.d.ts +0 -0
- /package/dist/{events → wirings}/channel/channel-store.js +0 -0
- /package/dist/{events → wirings}/channel/channel.types.js +0 -0
- /package/dist/{events → wirings}/channel/eventhub-service.js +0 -0
- /package/dist/{events → wirings}/channel/eventhub-store.js +0 -0
- /package/dist/{events → wirings}/channel/index.d.ts +0 -0
- /package/dist/{events → wirings}/channel/index.js +0 -0
- /package/dist/{events → wirings}/channel/local/index.d.ts +0 -0
- /package/dist/{events → wirings}/channel/local/index.js +0 -0
- /package/dist/{events → wirings}/channel/local/local-channel-handler.d.ts +0 -0
- /package/dist/{events → wirings}/channel/local/local-channel-handler.js +0 -0
- /package/dist/{events → wirings}/channel/local/local-channel-runner.js +0 -0
- /package/dist/{events → wirings}/channel/log-channels.d.ts +0 -0
- /package/dist/{events → wirings}/channel/log-channels.js +0 -0
- /package/dist/{events → wirings}/channel/pikku-abstract-channel-handler.d.ts +0 -0
- /package/dist/{events → wirings}/channel/pikku-abstract-channel-handler.js +0 -0
- /package/dist/{events → wirings}/channel/serverless/index.d.ts +0 -0
- /package/dist/{events → wirings}/channel/serverless/index.js +0 -0
- /package/dist/{events → wirings}/channel/serverless/serverless-channel-runner.js +0 -0
- /package/dist/{events → wirings}/http/http.types.js +0 -0
- /package/dist/{events → wirings}/http/log-http-routes.d.ts +0 -0
- /package/dist/{events → wirings}/http/log-http-routes.js +0 -0
- /package/dist/{events → wirings}/http/pikku-fetch-http-request.d.ts +0 -0
- /package/dist/{events → wirings}/http/pikku-fetch-http-request.js +0 -0
- /package/dist/{events → wirings}/http/pikku-fetch-http-response.d.ts +0 -0
- /package/dist/{events → wirings}/http/pikku-fetch-http-response.js +0 -0
- /package/dist/{events → wirings}/mcp/index.d.ts +0 -0
- /package/dist/{events → wirings}/mcp/index.js +0 -0
- /package/dist/{events → wirings}/mcp/mcp-endpoint-registry.d.ts +0 -0
- /package/dist/{events → wirings}/mcp/mcp-endpoint-registry.js +0 -0
- /package/dist/{events → wirings}/mcp/mcp.types.js +0 -0
- /package/dist/{events → wirings}/queue/queue.types.js +0 -0
- /package/dist/{events → wirings}/queue/register-queue-helper.d.ts +0 -0
- /package/dist/{events → wirings}/queue/register-queue-helper.js +0 -0
- /package/dist/{events → wirings}/queue/validate-worker-config.d.ts +0 -0
- /package/dist/{events → wirings}/queue/validate-worker-config.js +0 -0
- /package/dist/{events → wirings}/rpc/index.d.ts +0 -0
- /package/dist/{events → wirings}/rpc/index.js +0 -0
- /package/dist/{events → wirings}/rpc/rpc-runner.d.ts +0 -0
- /package/dist/{events → wirings}/rpc/rpc-runner.js +0 -0
- /package/dist/{events → wirings}/rpc/rpc-types.d.ts +0 -0
- /package/dist/{events → wirings}/rpc/rpc-types.js +0 -0
- /package/dist/{events → wirings}/scheduler/log-schedulers.d.ts +0 -0
- /package/dist/{events → wirings}/scheduler/log-schedulers.js +0 -0
- /package/dist/{events → wirings}/scheduler/scheduler.types.js +0 -0
- /package/src/{events → wirings}/channel/channel-store.ts +0 -0
- /package/src/{events → wirings}/channel/index.ts +0 -0
- /package/src/{events → wirings}/channel/local/index.ts +0 -0
- /package/src/{events → wirings}/channel/local/local-channel-handler.ts +0 -0
- /package/src/{events → wirings}/channel/local/local-eventhub-service.test.ts +0 -0
- /package/src/{events → wirings}/channel/log-channels.ts +0 -0
- /package/src/{events → wirings}/channel/pikku-abstract-channel-handler.test.ts +0 -0
- /package/src/{events → wirings}/channel/pikku-abstract-channel-handler.ts +0 -0
- /package/src/{events → wirings}/channel/serverless/index.ts +0 -0
- /package/src/{events → wirings}/http/log-http-routes.ts +0 -0
- /package/src/{events → wirings}/http/pikku-fetch-http-request.test.ts +0 -0
- /package/src/{events → wirings}/http/pikku-fetch-http-request.ts +0 -0
- /package/src/{events → wirings}/http/pikku-fetch-http-response.test.ts +0 -0
- /package/src/{events → wirings}/http/pikku-fetch-http-response.ts +0 -0
- /package/src/{events → wirings}/mcp/index.ts +0 -0
- /package/src/{events → wirings}/mcp/mcp-endpoint-registry.test.d.ts +0 -0
- /package/src/{events → wirings}/mcp/mcp-endpoint-registry.test.ts +0 -0
- /package/src/{events → wirings}/mcp/mcp-endpoint-registry.ts +0 -0
- /package/src/{events → wirings}/queue/register-queue-helper.ts +0 -0
- /package/src/{events → wirings}/queue/validate-worker-config.ts +0 -0
- /package/src/{events → wirings}/rpc/index.ts +0 -0
- /package/src/{events → wirings}/rpc/rpc-runner.ts +0 -0
- /package/src/{events → wirings}/rpc/rpc-types.ts +0 -0
- /package/src/{events → wirings}/scheduler/log-schedulers.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"author": "yasser.fadl@gmail.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
".": "./dist/index.js",
|
|
21
21
|
"./middleware": "./dist/middleware/index.js",
|
|
22
22
|
"./function": "./dist/function/index.js",
|
|
23
|
-
"./channel": "./dist/
|
|
24
|
-
"./channel/local": "./dist/
|
|
25
|
-
"./channel/serverless": "./dist/
|
|
26
|
-
"./http": "./dist/
|
|
27
|
-
"./queue": "./dist/
|
|
28
|
-
"./scheduler": "./dist/
|
|
29
|
-
"./rpc": "./dist/
|
|
30
|
-
"./mcp": "./dist/
|
|
23
|
+
"./channel": "./dist/wirings/channel/index.js",
|
|
24
|
+
"./channel/local": "./dist/wirings/channel/local/index.js",
|
|
25
|
+
"./channel/serverless": "./dist/wirings/channel/serverless/index.js",
|
|
26
|
+
"./http": "./dist/wirings/http/index.js",
|
|
27
|
+
"./queue": "./dist/wirings/queue/index.js",
|
|
28
|
+
"./scheduler": "./dist/wirings/scheduler/index.js",
|
|
29
|
+
"./rpc": "./dist/wirings/rpc/index.js",
|
|
30
|
+
"./mcp": "./dist/wirings/mcp/index.js",
|
|
31
31
|
"./errors": "./dist/errors/index.js",
|
|
32
32
|
"./services": "./dist/services/index.js",
|
|
33
33
|
"./schema": "./dist/schema.js",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PikkuChannel } from '../
|
|
1
|
+
import { PikkuChannel } from '../wirings/channel/channel.types.js'
|
|
2
2
|
import type {
|
|
3
3
|
CoreServices,
|
|
4
4
|
CoreSingletonServices,
|
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
* @template Services - The services type, defaults to `CoreServices`.
|
|
15
15
|
* @template Session - The session type, defaults to `CoreUserSession`.
|
|
16
16
|
*/
|
|
17
|
-
export type
|
|
17
|
+
export type CorePikkuFunction<
|
|
18
18
|
In,
|
|
19
19
|
Out,
|
|
20
20
|
ChannelData extends unknown | null = null,
|
|
@@ -41,7 +41,7 @@ export type CoreAPIFunction<
|
|
|
41
41
|
* @template Services - The services type, defaults to `CoreServices`.
|
|
42
42
|
* @template Session - The session type, defaults to `CoreUserSession`.
|
|
43
43
|
*/
|
|
44
|
-
export type
|
|
44
|
+
export type CorePikkuFunctionSessionless<
|
|
45
45
|
In,
|
|
46
46
|
Out,
|
|
47
47
|
ChannelData extends unknown | null = null,
|
|
@@ -61,30 +61,30 @@ export type CoreAPIFunctionSessionless<
|
|
|
61
61
|
) => ChannelData extends null ? Promise<Out> : Promise<Out> | Promise<void>
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
* Represents a function that checks permissions for a given
|
|
64
|
+
* Represents a function that checks permissions for a given operation.
|
|
65
65
|
*
|
|
66
66
|
* @template In - The input type.
|
|
67
67
|
* @template Services - The services type, defaults to `CoreServices`.
|
|
68
68
|
* @template Session - The session type, defaults to `CoreUserSession`.
|
|
69
69
|
*/
|
|
70
|
-
export type
|
|
70
|
+
export type CorePikkuPermission<
|
|
71
71
|
In = any,
|
|
72
72
|
Services extends CoreSingletonServices = CoreServices,
|
|
73
73
|
Session extends CoreUserSession = CoreUserSession,
|
|
74
74
|
> = (services: Services, data: In, session?: Session) => Promise<boolean>
|
|
75
75
|
|
|
76
|
-
export type CorePermissionGroup<
|
|
77
|
-
| Record<string,
|
|
76
|
+
export type CorePermissionGroup<PikkuPermission = CorePikkuPermission<any>> =
|
|
77
|
+
| Record<string, PikkuPermission | PikkuPermission[]>
|
|
78
78
|
| undefined
|
|
79
79
|
|
|
80
80
|
export type CorePikkuFunctionConfig<
|
|
81
|
-
|
|
82
|
-
|
|
|
83
|
-
|
|
|
84
|
-
|
|
81
|
+
PikkuFunction extends
|
|
82
|
+
| CorePikkuFunction<any, any>
|
|
83
|
+
| CorePikkuFunctionSessionless<any, any>,
|
|
84
|
+
PikkuPermission extends CorePikkuPermission<any> = CorePikkuPermission<any>,
|
|
85
85
|
> = {
|
|
86
|
-
func:
|
|
86
|
+
func: PikkuFunction
|
|
87
87
|
auth?: boolean
|
|
88
|
-
permissions?: CorePermissionGroup<
|
|
88
|
+
permissions?: CorePermissionGroup<PikkuPermission>
|
|
89
89
|
middleware?: PikkuFunctionMiddleware[]
|
|
90
90
|
}
|
package/src/handle-error.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getErrorResponse } from './errors/error-handler.js'
|
|
2
2
|
import { NotFoundError } from './errors/errors.js'
|
|
3
3
|
import { Logger } from './services/logger.js'
|
|
4
|
-
import { PikkuHTTP } from './
|
|
4
|
+
import { PikkuHTTP } from './wirings/http/http.types.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Handle errors that occur during route processing
|
package/src/index.ts
CHANGED
|
@@ -10,25 +10,26 @@ export * from './services/schema-service.js'
|
|
|
10
10
|
export * from './services/jwt-service.js'
|
|
11
11
|
export * from './services/secret-service.js'
|
|
12
12
|
export * from './services/user-session-service.js'
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './
|
|
18
|
-
export * from './
|
|
13
|
+
export * from './wirings/http/index.js'
|
|
14
|
+
export * from './wirings/channel/index.js'
|
|
15
|
+
export * from './wirings/scheduler/index.js'
|
|
16
|
+
export * from './wirings/rpc/index.js'
|
|
17
|
+
export * from './wirings/queue/index.js'
|
|
18
|
+
export * from './wirings/mcp/index.js'
|
|
19
19
|
export * from './errors/index.js'
|
|
20
20
|
export * from './middleware/index.js'
|
|
21
21
|
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 {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
25
|
+
export { wireHTTP, addMiddleware } from './wirings/http/http-runner.js'
|
|
26
|
+
export { wireChannel } from './wirings/channel/channel-runner.js'
|
|
27
|
+
export { wireScheduler } from './wirings/scheduler/scheduler-runner.js'
|
|
28
|
+
export { wireQueueWorker } from './wirings/queue/queue-runner.js'
|
|
28
29
|
export {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
wireMCPResource,
|
|
31
|
+
wireMCPTool,
|
|
32
|
+
wireMCPPrompt,
|
|
32
33
|
runMCPResource,
|
|
33
34
|
runMCPTool,
|
|
34
35
|
runMCPPrompt,
|
|
@@ -38,4 +39,4 @@ export {
|
|
|
38
39
|
getMCPResourcesMeta,
|
|
39
40
|
getMCPToolsMeta,
|
|
40
41
|
getMCPPromptsMeta,
|
|
41
|
-
} from './
|
|
42
|
+
} from './wirings/mcp/mcp-runner.js'
|
package/src/pikku-state.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { ChannelsMeta,
|
|
1
|
+
import { ChannelsMeta, CoreChannel } from './wirings/channel/channel.types.js'
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
CoreHTTPFunctionWiring,
|
|
4
4
|
HTTPMethod,
|
|
5
|
-
|
|
6
|
-
} from './
|
|
5
|
+
HTTPWiringsMeta,
|
|
6
|
+
} from './wirings/http/http.types.js'
|
|
7
7
|
import { FunctionsMeta, PikkuMiddleware } from './types/core.types.js'
|
|
8
8
|
import {
|
|
9
9
|
CoreScheduledTask,
|
|
10
10
|
ScheduledTasksMeta,
|
|
11
|
-
} from './
|
|
11
|
+
} from './wirings/scheduler/scheduler.types.js'
|
|
12
12
|
import { ErrorDetails, PikkuError } from './errors/error-handler.js'
|
|
13
13
|
import { CorePikkuFunctionConfig } from './function/functions.types.js'
|
|
14
|
-
import { RPCMeta } from './
|
|
14
|
+
import { RPCMeta } from './wirings/rpc/rpc-types.js'
|
|
15
15
|
import {
|
|
16
16
|
queueWorkersMeta,
|
|
17
17
|
CoreQueueWorker,
|
|
18
|
-
} from './
|
|
18
|
+
} from './wirings/queue/queue.types.js'
|
|
19
19
|
import {
|
|
20
20
|
CoreMCPResource,
|
|
21
21
|
CoreMCPTool,
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
MCPResourceMeta,
|
|
24
24
|
MCPToolMeta,
|
|
25
25
|
MCPPromptMeta,
|
|
26
|
-
} from './
|
|
26
|
+
} from './wirings/mcp/mcp.types.js'
|
|
27
27
|
|
|
28
28
|
interface PikkuState {
|
|
29
29
|
function: {
|
|
@@ -42,11 +42,11 @@ interface PikkuState {
|
|
|
42
42
|
}
|
|
43
43
|
http: {
|
|
44
44
|
middleware: Array<{ route: string; middleware: PikkuMiddleware[] }>
|
|
45
|
-
routes: Map<HTTPMethod, Map<string,
|
|
46
|
-
meta:
|
|
45
|
+
routes: Map<HTTPMethod, Map<string, CoreHTTPFunctionWiring<any, any, any>>>
|
|
46
|
+
meta: HTTPWiringsMeta
|
|
47
47
|
}
|
|
48
48
|
channel: {
|
|
49
|
-
channels: Map<string,
|
|
49
|
+
channels: Map<string, CoreChannel<any, any>>
|
|
50
50
|
meta: ChannelsMeta
|
|
51
51
|
}
|
|
52
52
|
scheduler: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChannelStore } from '../
|
|
1
|
+
import { ChannelStore } from '../wirings/channel/channel-store.js'
|
|
2
2
|
import { CoreUserSession } from '../types/core.types.js'
|
|
3
3
|
|
|
4
4
|
export interface UserSessionService<UserSession extends CoreUserSession> {
|
package/src/types/core.types.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Logger, LogLevel } from '../services/logger.js'
|
|
2
2
|
import { VariablesService } from '../services/variables-service.js'
|
|
3
3
|
import { SchemaService } from '../services/schema-service.js'
|
|
4
|
-
import { PikkuHTTP } from '../
|
|
4
|
+
import { PikkuHTTP } from '../wirings/http/http.types.js'
|
|
5
5
|
import { UserSessionService } from '../services/user-session-service.js'
|
|
6
|
-
import { PikkuChannel } from '../
|
|
7
|
-
import { PikkuRPC } from '../
|
|
8
|
-
import { PikkuMCP } from '../
|
|
6
|
+
import { PikkuChannel } from '../wirings/channel/channel.types.js'
|
|
7
|
+
import { PikkuRPC } from '../wirings/rpc/rpc-types.js'
|
|
8
|
+
import { PikkuMCP } from '../wirings/mcp/mcp.types.js'
|
|
9
9
|
|
|
10
|
-
export enum
|
|
10
|
+
export enum PikkuWiringTypes {
|
|
11
11
|
http = 'http',
|
|
12
12
|
scheduler = 'scheduler',
|
|
13
13
|
channel = 'channel',
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from '../../types/core.types.js'
|
|
6
6
|
import {
|
|
7
7
|
ChannelMessageMeta,
|
|
8
|
-
|
|
8
|
+
CoreChannel,
|
|
9
9
|
PikkuChannelHandler,
|
|
10
10
|
} from './channel.types.js'
|
|
11
11
|
import { pikkuState } from '../../pikku-state.js'
|
|
@@ -31,7 +31,7 @@ const getRouteMeta = (
|
|
|
31
31
|
`Channel ${channelName} requires a router value for ${routingProperty}`
|
|
32
32
|
)
|
|
33
33
|
}
|
|
34
|
-
const route = channelMeta.
|
|
34
|
+
const route = channelMeta.messageWirings[routingProperty]?.[routerValue]
|
|
35
35
|
if (!route) {
|
|
36
36
|
throw new Error(
|
|
37
37
|
`Channel ${channelName} has no route for ${routingProperty}:${routerValue}`
|
|
@@ -61,7 +61,7 @@ const validateAuth = (
|
|
|
61
61
|
export const processMessageHandlers = (
|
|
62
62
|
services: CoreServices,
|
|
63
63
|
session: CoreUserSession | undefined,
|
|
64
|
-
channelConfig:
|
|
64
|
+
channelConfig: CoreChannel<any, any>,
|
|
65
65
|
channelHandler: PikkuChannelHandler
|
|
66
66
|
) => {
|
|
67
67
|
const logger = services.logger
|
|
@@ -115,10 +115,10 @@ export const processMessageHandlers = (
|
|
|
115
115
|
let processed = false
|
|
116
116
|
|
|
117
117
|
// Route-specific handling
|
|
118
|
-
if (typeof rawData === 'string' && channelConfig.
|
|
118
|
+
if (typeof rawData === 'string' && channelConfig.onMessageWiring) {
|
|
119
119
|
try {
|
|
120
120
|
const messageData = JSON.parse(rawData)
|
|
121
|
-
const entries = Object.entries(channelConfig.
|
|
121
|
+
const entries = Object.entries(channelConfig.onMessageWiring)
|
|
122
122
|
for (const [routingProperty, routes] of entries) {
|
|
123
123
|
const routerValue = messageData[routingProperty]
|
|
124
124
|
if (routerValue && routes[routerValue]) {
|
|
@@ -5,7 +5,7 @@ import { coerceTopLevelDataFromSchema, validateSchema } from '../../schema.js'
|
|
|
5
5
|
import { UserSessionService } from '../../services/user-session-service.js'
|
|
6
6
|
import {
|
|
7
7
|
ChannelMeta,
|
|
8
|
-
|
|
8
|
+
CoreChannel,
|
|
9
9
|
RunChannelOptions,
|
|
10
10
|
RunChannelParams,
|
|
11
11
|
} from './channel.types.js'
|
|
@@ -15,14 +15,14 @@ import { match } from 'path-to-regexp'
|
|
|
15
15
|
* Adds a channel and registers all functions referenced in it using the
|
|
16
16
|
* function names already stored in the channel metadata
|
|
17
17
|
*/
|
|
18
|
-
export const
|
|
18
|
+
export const wireChannel = <
|
|
19
19
|
In,
|
|
20
20
|
Channel extends string,
|
|
21
21
|
ChannelFunction,
|
|
22
22
|
ChannelFunctionSessionless,
|
|
23
|
-
|
|
23
|
+
PikkuPermission,
|
|
24
24
|
>(
|
|
25
|
-
channel:
|
|
25
|
+
channel: CoreChannel<In, Channel, ChannelFunction, PikkuPermission>
|
|
26
26
|
) => {
|
|
27
27
|
// Get the channel metadata
|
|
28
28
|
const channelsMeta = pikkuState('channel', 'meta')
|
|
@@ -58,20 +58,20 @@ export const addChannel = <
|
|
|
58
58
|
})
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
// Register functions in
|
|
62
|
-
if (channel.
|
|
63
|
-
// Iterate through each channel in
|
|
64
|
-
Object.entries(channel.
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
61
|
+
// Register functions in onMessageWiring
|
|
62
|
+
if (channel.onMessageWiring && channelMeta.messageWirings) {
|
|
63
|
+
// Iterate through each channel in onMessageWiring
|
|
64
|
+
Object.entries(channel.onMessageWiring).forEach(([channelKey, wirings]) => {
|
|
65
|
+
const channelWirings = channelMeta.messageWirings[channelKey]
|
|
66
|
+
if (!channelWirings) return
|
|
67
67
|
|
|
68
|
-
// Iterate through each
|
|
69
|
-
Object.entries(
|
|
70
|
-
const
|
|
71
|
-
if (!
|
|
68
|
+
// Iterate through each wiring in the channel
|
|
69
|
+
Object.entries(wirings).forEach(([wiringKey, handler]) => {
|
|
70
|
+
const wiringMeta = channelWirings[wiringKey]
|
|
71
|
+
if (!wiringMeta) return
|
|
72
72
|
|
|
73
73
|
// Extract the function from the handler
|
|
74
|
-
const
|
|
74
|
+
const wiringFunc =
|
|
75
75
|
typeof handler === 'function'
|
|
76
76
|
? { func: handler }
|
|
77
77
|
: {
|
|
@@ -81,7 +81,7 @@ export const addChannel = <
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// Register the function using the pikku name from metadata
|
|
84
|
-
addFunction(
|
|
84
|
+
addFunction(wiringMeta.pikkuFuncName, wiringFunc)
|
|
85
85
|
})
|
|
86
86
|
})
|
|
87
87
|
}
|
|
@@ -122,12 +122,12 @@ export const openChannel = async ({
|
|
|
122
122
|
singletonServices,
|
|
123
123
|
coerceDataFromSchema = true,
|
|
124
124
|
request,
|
|
125
|
-
}: Pick<
|
|
125
|
+
}: Pick<CoreChannel<unknown, string>, 'route'> &
|
|
126
126
|
RunChannelParams<unknown> & {
|
|
127
127
|
userSession: UserSessionService<any>
|
|
128
128
|
} & RunChannelOptions): Promise<{
|
|
129
129
|
openingData: unknown
|
|
130
|
-
channelConfig:
|
|
130
|
+
channelConfig: CoreChannel<unknown, any>
|
|
131
131
|
meta: ChannelMeta
|
|
132
132
|
}> => {
|
|
133
133
|
const matchingChannel = getMatchingChannelConfig(route)
|
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
PikkuMiddleware,
|
|
12
12
|
} from '../../types/core.types.js'
|
|
13
13
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
CorePikkuFunction,
|
|
15
|
+
CorePikkuFunctionSessionless,
|
|
16
|
+
CorePikkuPermission,
|
|
17
17
|
} from '../../function/functions.types.js'
|
|
18
18
|
|
|
19
19
|
export type RunChannelOptions = Partial<{
|
|
@@ -47,26 +47,26 @@ export interface ChannelMeta {
|
|
|
47
47
|
connect: ChannelMessageMeta | null
|
|
48
48
|
disconnect: ChannelMessageMeta | null
|
|
49
49
|
message: ChannelMessageMeta | null
|
|
50
|
-
|
|
50
|
+
messageWirings: Record<string, Record<string, ChannelMessageMeta>>
|
|
51
51
|
docs?: APIDocs
|
|
52
52
|
tags?: string[]
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export type ChannelsMeta = Record<string, ChannelMeta>
|
|
56
56
|
|
|
57
|
-
export type
|
|
57
|
+
export type CoreChannel<
|
|
58
58
|
ChannelData,
|
|
59
59
|
Channel extends string,
|
|
60
60
|
ChannelConnect =
|
|
61
|
-
|
|
|
62
|
-
|
|
|
61
|
+
| CorePikkuFunction<void, unknown, ChannelData>
|
|
62
|
+
| CorePikkuFunctionSessionless<void, unknown, ChannelData>,
|
|
63
63
|
ChannelDisconnect =
|
|
64
|
-
|
|
|
65
|
-
|
|
|
64
|
+
| CorePikkuFunction<void, void, ChannelData>
|
|
65
|
+
| CorePikkuFunctionSessionless<void, void, ChannelData>,
|
|
66
66
|
ChannelFunctionMessage =
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
|
|
67
|
+
| CorePikkuFunction<unknown, unknown, ChannelData>
|
|
68
|
+
| CorePikkuFunctionSessionless<unknown, unknown, ChannelData>,
|
|
69
|
+
PikkuPermission = CorePikkuPermission<ChannelData>,
|
|
70
70
|
> = {
|
|
71
71
|
name: string
|
|
72
72
|
route: Channel
|
|
@@ -75,24 +75,24 @@ export type CoreAPIChannel<
|
|
|
75
75
|
onMessage?:
|
|
76
76
|
| {
|
|
77
77
|
func: ChannelFunctionMessage
|
|
78
|
-
permissions?: Record<string,
|
|
78
|
+
permissions?: Record<string, PikkuPermission[] | PikkuPermission>
|
|
79
79
|
auth?: boolean
|
|
80
80
|
}
|
|
81
81
|
| ChannelFunctionMessage
|
|
82
|
-
|
|
82
|
+
onMessageWiring?: Record<
|
|
83
83
|
string,
|
|
84
84
|
Record<
|
|
85
85
|
string,
|
|
86
86
|
| ChannelFunctionMessage
|
|
87
87
|
| {
|
|
88
88
|
func: ChannelFunctionMessage
|
|
89
|
-
permissions?: Record<string,
|
|
89
|
+
permissions?: Record<string, PikkuPermission[] | PikkuPermission>
|
|
90
90
|
auth?: boolean
|
|
91
91
|
}
|
|
92
92
|
>
|
|
93
93
|
>
|
|
94
94
|
middleware?: PikkuMiddleware[]
|
|
95
|
-
permissions?: Record<string,
|
|
95
|
+
permissions?: Record<string, PikkuPermission[] | PikkuPermission>
|
|
96
96
|
auth?: boolean
|
|
97
97
|
docs?: Partial<{
|
|
98
98
|
description: string
|
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Interface defining the methods of a EventHub Service.
|
|
3
3
|
*/
|
|
4
|
-
export interface EventHubService<
|
|
4
|
+
export interface EventHubService<Topics extends Record<string, any>> {
|
|
5
5
|
/**
|
|
6
6
|
* Subscribes a connection to a specific topic.
|
|
7
7
|
* @param topic - The topic to subscribe to.
|
|
8
8
|
* @param channelId - The unique ID of the connection to subscribe.
|
|
9
9
|
*/
|
|
10
|
-
subscribe
|
|
11
|
-
|
|
10
|
+
subscribe<T extends keyof Topics>(
|
|
11
|
+
topic: T,
|
|
12
|
+
channelId: string
|
|
13
|
+
): Promise<void> | void
|
|
12
14
|
/**
|
|
13
15
|
* Unsubscribes a connection from a specific topic.
|
|
14
16
|
* @param topic - The topic to unsubscribe from.
|
|
15
17
|
* @param channelId - The unique ID of the connection to unsubscribe.
|
|
16
18
|
*/
|
|
17
|
-
unsubscribe
|
|
18
|
-
|
|
19
|
+
unsubscribe<T extends keyof Topics>(
|
|
20
|
+
topic: T,
|
|
21
|
+
channelId: string
|
|
22
|
+
): Promise<void> | void
|
|
19
23
|
/**
|
|
20
24
|
* Sends data to all connections subscribed to a topic.
|
|
21
25
|
* @param topic - The topic to send data to.
|
|
22
26
|
* @param data - The data to send to the subscribers.
|
|
23
27
|
*/
|
|
24
|
-
publish(
|
|
25
|
-
topic:
|
|
28
|
+
publish<T extends keyof Topics>(
|
|
29
|
+
topic: T,
|
|
26
30
|
channelId: string | null,
|
|
27
|
-
data:
|
|
31
|
+
data: Topics[T],
|
|
28
32
|
isBinary?: boolean
|
|
29
33
|
): Promise<void> | void
|
|
30
34
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export abstract class EventHubStore<
|
|
2
|
+
EventTopics extends Record<string, any> = {},
|
|
3
|
+
> {
|
|
4
|
+
public abstract getChannelIdsForTopic(topic: string): Promise<string[]>
|
|
5
|
+
public abstract subscribe<T extends keyof EventTopics>(
|
|
6
|
+
topic: T,
|
|
7
|
+
channelId: string
|
|
8
|
+
): Promise<boolean>
|
|
9
|
+
public abstract unsubscribe<T extends keyof EventTopics>(
|
|
10
|
+
topic: T,
|
|
11
|
+
channelId: string
|
|
12
|
+
): Promise<boolean>
|
|
13
|
+
}
|
|
@@ -2,7 +2,7 @@ import { test, beforeEach, afterEach } from 'node:test'
|
|
|
2
2
|
import * as assert from 'node:assert/strict'
|
|
3
3
|
import { runLocalChannel } from './local-channel-runner.js'
|
|
4
4
|
import { pikkuState, resetPikkuState } from '../../../pikku-state.js'
|
|
5
|
-
import {
|
|
5
|
+
import { wireChannel } from '../channel-runner.js'
|
|
6
6
|
import {
|
|
7
7
|
HTTPMethod,
|
|
8
8
|
PikkuHTTPRequest,
|
|
@@ -133,7 +133,7 @@ test('runChannel should return a channel handler if channel matches and no auth
|
|
|
133
133
|
route: '/test-channel',
|
|
134
134
|
},
|
|
135
135
|
} as any)
|
|
136
|
-
|
|
136
|
+
wireChannel({
|
|
137
137
|
name: 'test',
|
|
138
138
|
route: '/test-channel',
|
|
139
139
|
auth: false,
|
|
@@ -3,7 +3,7 @@ import { createHTTPInteraction } from '../../http/http-runner.js'
|
|
|
3
3
|
import { closeSessionServices } from '../../../utils.js'
|
|
4
4
|
import { processMessageHandlers } from '../channel-handler.js'
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
CoreChannel,
|
|
7
7
|
RunChannelOptions,
|
|
8
8
|
RunChannelParams,
|
|
9
9
|
} from '../channel.types.js'
|
|
@@ -28,7 +28,7 @@ export const runLocalChannel = async ({
|
|
|
28
28
|
coerceDataFromSchema = true,
|
|
29
29
|
logWarningsForStatusCodes = [],
|
|
30
30
|
bubbleErrors = false,
|
|
31
|
-
}: Partial<Pick<
|
|
31
|
+
}: Partial<Pick<CoreChannel<unknown, any>, 'route'>> &
|
|
32
32
|
RunChannelOptions &
|
|
33
33
|
RunChannelParams<unknown>): Promise<PikkuLocalChannelHandler | void> => {
|
|
34
34
|
let sessionServices: SessionServices<typeof singletonServices> | undefined
|
|
@@ -5,7 +5,7 @@ import { EventHubService } from '../eventhub-service.js'
|
|
|
5
5
|
* Implementation of the SubscriptionService interface.
|
|
6
6
|
* Manages subscriptions and publishes messages to subscribers.
|
|
7
7
|
*/
|
|
8
|
-
export class LocalEventHubService<Data =
|
|
8
|
+
export class LocalEventHubService<Data extends Record<string, any> = {}>
|
|
9
9
|
implements EventHubService<Data>
|
|
10
10
|
{
|
|
11
11
|
private channels = new Map<string, PikkuChannelHandler>()
|
|
@@ -13,7 +13,7 @@ export class LocalEventHubService<Data = unknown>
|
|
|
13
13
|
/**
|
|
14
14
|
* A map storing topics and their associated connection IDs.
|
|
15
15
|
*/
|
|
16
|
-
private subscriptions: Map<
|
|
16
|
+
private subscriptions: Map<keyof Data, Set<string>> = new Map()
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Subscribes a connection to a specific topic.
|
|
@@ -21,7 +21,10 @@ export class LocalEventHubService<Data = unknown>
|
|
|
21
21
|
* @param topic - The topic to subscribe to.
|
|
22
22
|
* @param channelId - The unique ID of the connection to subscribe.
|
|
23
23
|
*/
|
|
24
|
-
public subscribe
|
|
24
|
+
public subscribe<T extends keyof Data>(
|
|
25
|
+
topic: T,
|
|
26
|
+
channelId: string
|
|
27
|
+
): void | Promise<void> {
|
|
25
28
|
if (!this.subscriptions.has(topic)) {
|
|
26
29
|
this.subscriptions.set(topic, new Set())
|
|
27
30
|
}
|
|
@@ -34,12 +37,15 @@ export class LocalEventHubService<Data = unknown>
|
|
|
34
37
|
* @param topic - The topic to unsubscribe from.
|
|
35
38
|
* @param channelId - The unique ID of the connection to unsubscribe.
|
|
36
39
|
*/
|
|
37
|
-
public unsubscribe
|
|
40
|
+
public unsubscribe<T extends keyof Data>(
|
|
41
|
+
topic: T,
|
|
42
|
+
channelId: string
|
|
43
|
+
): void | Promise<void> {
|
|
38
44
|
const topicSubscriptions = this.subscriptions.get(topic)
|
|
39
45
|
if (topicSubscriptions) {
|
|
40
46
|
topicSubscriptions.delete(channelId)
|
|
41
47
|
if (topicSubscriptions.size === 0) {
|
|
42
|
-
this.subscriptions.delete(topic)
|
|
48
|
+
this.subscriptions.delete(topic)
|
|
43
49
|
}
|
|
44
50
|
}
|
|
45
51
|
}
|
|
@@ -49,12 +55,12 @@ export class LocalEventHubService<Data = unknown>
|
|
|
49
55
|
* @param topic - The topic to send data to.
|
|
50
56
|
* @param data - The data to send to the subscribers.
|
|
51
57
|
*/
|
|
52
|
-
public publish(
|
|
53
|
-
topic:
|
|
54
|
-
channelId: string,
|
|
55
|
-
data: Data,
|
|
58
|
+
public publish<T extends keyof Data>(
|
|
59
|
+
topic: T,
|
|
60
|
+
channelId: string | null,
|
|
61
|
+
data: Data[T],
|
|
56
62
|
isBinary?: boolean
|
|
57
|
-
): void {
|
|
63
|
+
): void | Promise<void> {
|
|
58
64
|
const subscribedChannelIds = this.subscriptions.get(topic)
|
|
59
65
|
if (!subscribedChannelIds) {
|
|
60
66
|
return
|
|
@@ -3,7 +3,7 @@ import { closeSessionServices } from '../../../utils.js'
|
|
|
3
3
|
import { processMessageHandlers } from '../channel-handler.js'
|
|
4
4
|
import { openChannel } from '../channel-runner.js'
|
|
5
5
|
import type {
|
|
6
|
-
|
|
6
|
+
CoreChannel,
|
|
7
7
|
RunChannelOptions,
|
|
8
8
|
RunChannelParams,
|
|
9
9
|
PikkuChannelHandlerFactory,
|
|
@@ -73,7 +73,7 @@ export const runChannelConnect = async ({
|
|
|
73
73
|
logWarningsForStatusCodes = [],
|
|
74
74
|
respondWith404 = true,
|
|
75
75
|
bubbleErrors = false,
|
|
76
|
-
}: Pick<
|
|
76
|
+
}: Pick<CoreChannel<unknown, any>, 'route'> &
|
|
77
77
|
RunChannelOptions &
|
|
78
78
|
RunServerlessChannelParams<unknown>) => {
|
|
79
79
|
let sessionServices: SessionServices | undefined
|
|
@@ -2,7 +2,7 @@ import { test, describe, beforeEach, afterEach } from 'node:test'
|
|
|
2
2
|
import * as assert from 'assert'
|
|
3
3
|
import { NotFoundError } from '../../errors/errors.js'
|
|
4
4
|
import { JSONValue, PikkuMiddleware } from '../../types/core.types.js'
|
|
5
|
-
import { fetch,
|
|
5
|
+
import { fetch, wireHTTP } from './http-runner.js'
|
|
6
6
|
import { pikkuState, resetPikkuState } from '../../pikku-state.js'
|
|
7
7
|
import {
|
|
8
8
|
PikkuMockRequest,
|
|
@@ -78,7 +78,7 @@ describe('fetch', () => {
|
|
|
78
78
|
const routeFunc = async () => ({ success: true })
|
|
79
79
|
setHTTPFunctionMap(routeFunc)
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
wireHTTP({
|
|
82
82
|
route: 'test',
|
|
83
83
|
method: 'get',
|
|
84
84
|
func: routeFunc,
|
|
@@ -98,7 +98,7 @@ describe('fetch', () => {
|
|
|
98
98
|
const routeFunc = async () => ({ success: true })
|
|
99
99
|
setHTTPFunctionMap(routeFunc)
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
wireHTTP({
|
|
102
102
|
route: 'test',
|
|
103
103
|
method: 'get',
|
|
104
104
|
func: routeFunc,
|
|
@@ -120,7 +120,7 @@ describe('fetch', () => {
|
|
|
120
120
|
throw error
|
|
121
121
|
}
|
|
122
122
|
setHTTPFunctionMap(routeFunc)
|
|
123
|
-
|
|
123
|
+
wireHTTP({
|
|
124
124
|
route: 'test',
|
|
125
125
|
method: 'get',
|
|
126
126
|
func: routeFunc,
|