@pikku/cli 0.9.16-next.0 → 0.10.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/.pikku/channel/pikku-channel-types.gen.ts +28 -29
- package/.pikku/channel/pikku-channels-map.gen.d.ts +44 -0
- package/.pikku/channel/pikku-channels-meta.gen.ts +5 -0
- package/.pikku/channel/pikku-channels.gen.ts +4 -0
- package/.pikku/cli/pikku-cli-channel.gen.ts +34 -0
- package/.pikku/cli/pikku-cli-client.gen.ts +43 -0
- package/.pikku/cli/pikku-cli-types.gen.ts +14 -15
- package/.pikku/cli/pikku-cli-wirings-meta.gen.ts +142 -2
- package/.pikku/cli/pikku-cli-wirings.gen.ts +4 -2
- package/.pikku/cli/pikku-cli.gen.ts +41 -0
- package/.pikku/function/pikku-function-types.gen.ts +167 -19
- package/.pikku/function/pikku-functions-meta.gen.ts +220 -192
- package/.pikku/function/pikku-functions-meta.min.gen.ts +61 -56
- package/.pikku/function/pikku-functions.gen.ts +3 -1
- package/.pikku/http/pikku-http-types.gen.ts +28 -3
- package/.pikku/http/pikku-http-wirings-map.gen.d.ts +43 -0
- package/.pikku/http/pikku-http-wirings-meta.gen.ts +13 -0
- package/.pikku/http/pikku-http-wirings.gen.ts +4 -0
- package/.pikku/mcp/pikku-mcp-types.gen.ts +15 -13
- package/.pikku/mcp/pikku-mcp-wirings-meta.gen.ts +7 -0
- package/.pikku/mcp/pikku-mcp-wirings.gen.ts +4 -0
- package/.pikku/mcp/pikku-mcp.gen.json +5 -0
- package/.pikku/pikku-bootstrap.gen.ts +11 -1
- package/.pikku/pikku-services.gen.ts +1 -5
- package/.pikku/pikku-types.gen.ts +1 -2
- package/.pikku/pikku-websocket.gen.ts +76 -0
- package/.pikku/queue/pikku-queue-types.gen.ts +1 -2
- package/.pikku/queue/pikku-queue-workers-wirings-map.gen.d.ts +57 -0
- package/.pikku/queue/pikku-queue-workers-wirings-meta.gen.ts +5 -0
- package/.pikku/queue/pikku-queue-workers-wirings.gen.ts +4 -0
- package/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +5 -4
- package/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +19 -17
- package/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.ts +15 -14
- package/.pikku/scheduler/pikku-scheduler-types.gen.ts +1 -2
- package/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.ts +5 -0
- package/.pikku/scheduler/pikku-schedulers-wirings.gen.ts +4 -0
- package/.pikku/schemas/register.gen.ts +15 -11
- package/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -0
- package/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
- package/CHANGELOG.md +6 -0
- package/bin/pikku.ts +63 -11
- package/build.sh +1 -1
- package/cli.schema.json +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +11 -20
- package/dist/.pikku/channel/pikku-channel-types.gen.js +9 -11
- package/dist/.pikku/channel/pikku-channels-meta.gen.d.ts +1 -0
- package/dist/.pikku/channel/pikku-channels-meta.gen.js +5 -0
- package/dist/.pikku/channel/pikku-channels.gen.d.ts +4 -0
- package/dist/.pikku/channel/pikku-channels.gen.js +5 -0
- package/dist/.pikku/cli/pikku-cli-channel.gen.d.ts +1 -0
- package/dist/.pikku/cli/pikku-cli-channel.gen.js +33 -0
- package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +10 -0
- package/dist/.pikku/cli/pikku-cli-client.gen.js +34 -0
- package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +9 -12
- package/dist/.pikku/cli/pikku-cli-types.gen.js +5 -4
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +142 -2
- package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +3 -2
- package/dist/.pikku/cli/pikku-cli-wirings.gen.js +4 -3
- package/dist/.pikku/cli/pikku-cli.gen.d.ts +10 -0
- package/dist/.pikku/cli/pikku-cli.gen.js +38 -0
- package/dist/.pikku/function/pikku-function-types.gen.d.ts +141 -20
- package/dist/.pikku/function/pikku-function-types.gen.js +108 -12
- package/dist/.pikku/function/pikku-functions-meta.gen.js +220 -192
- package/dist/.pikku/function/pikku-functions-meta.min.gen.js +61 -56
- package/dist/.pikku/function/pikku-functions.gen.js +3 -1
- package/dist/.pikku/http/pikku-http-types.gen.d.ts +21 -2
- package/dist/.pikku/http/pikku-http-types.gen.js +24 -3
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +13 -0
- package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +4 -0
- package/dist/.pikku/http/pikku-http-wirings.gen.js +5 -0
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +11 -8
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js +6 -6
- package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.js +7 -0
- package/dist/.pikku/mcp/pikku-mcp-wirings.gen.d.ts +4 -0
- package/dist/.pikku/mcp/pikku-mcp-wirings.gen.js +5 -0
- package/dist/.pikku/pikku-bootstrap.gen.d.ts +11 -1
- package/dist/.pikku/pikku-bootstrap.gen.js +11 -1
- package/dist/.pikku/pikku-services.gen.d.ts +1 -4
- package/dist/.pikku/pikku-services.gen.js +0 -6
- package/dist/.pikku/pikku-types.gen.d.ts +1 -2
- package/dist/.pikku/pikku-types.gen.js +1 -2
- package/dist/.pikku/pikku-websocket.gen.d.ts +31 -0
- package/dist/.pikku/pikku-websocket.gen.js +49 -0
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -2
- package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -2
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +5 -0
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +4 -0
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +5 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +15 -14
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -2
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -2
- package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.js +5 -0
- package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.d.ts +4 -0
- package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.js +5 -0
- package/dist/.pikku/schemas/register.gen.js +9 -7
- package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
- package/dist/bin/pikku.d.ts +1 -1
- package/dist/bin/pikku.js +37 -6
- package/dist/src/cli.wiring.js +99 -75
- package/dist/src/functions/commands/all.js +10 -0
- package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.js +10 -8
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts +1 -1
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +2 -2
- package/dist/src/functions/wirings/channels/pikku-channels.js +0 -5
- package/dist/src/functions/wirings/channels/pikku-command-channel-types.js +0 -2
- package/dist/src/functions/wirings/channels/pikku-command-channels-map.js +0 -5
- package/dist/src/functions/wirings/channels/pikku-command-channels.js +0 -5
- package/dist/src/functions/wirings/channels/pikku-command-websocket-typed.js +6 -3
- package/dist/src/functions/wirings/channels/serialize-channel-types.js +27 -28
- package/dist/src/functions/wirings/channels/serialize-typed-channel-map.js +4 -1
- package/dist/src/functions/wirings/cli/pikku-command-cli-entry.js +31 -8
- package/dist/src/functions/wirings/cli/pikku-command-cli-types.js +0 -2
- package/dist/src/functions/wirings/cli/pikku-command-cli.js +0 -2
- package/dist/src/functions/wirings/cli/serialize-channel-cli-client.d.ts +6 -2
- package/dist/src/functions/wirings/cli/serialize-channel-cli-client.js +88 -11
- package/dist/src/functions/wirings/cli/serialize-channel-cli.d.ts +1 -1
- package/dist/src/functions/wirings/cli/serialize-channel-cli.js +1 -18
- package/dist/src/functions/wirings/cli/serialize-cli-types.js +13 -14
- package/dist/src/functions/wirings/cli/serialize-local-cli-bootstrap.js +19 -14
- package/dist/src/functions/wirings/fetch/index.js +6 -3
- package/dist/src/functions/wirings/functions/pikku-command-function-types-split.js +6 -5
- package/dist/src/functions/wirings/functions/pikku-command-function-types.js +0 -2
- package/dist/src/functions/wirings/functions/pikku-command-functions.js +0 -2
- package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-services.js +11 -21
- package/dist/src/functions/wirings/functions/pikku-function-types.js +0 -2
- package/dist/src/functions/wirings/functions/schemas.js +0 -2
- package/dist/src/functions/wirings/functions/serialize-function-types.d.ts +1 -1
- package/dist/src/functions/wirings/functions/serialize-function-types.js +167 -19
- package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.js +0 -1
- package/dist/src/functions/wirings/http/openapi-spec-generator.d.ts +2 -1
- package/dist/src/functions/wirings/http/pikku-command-http-map.js +0 -5
- package/dist/src/functions/wirings/http/pikku-command-http-routes.js +0 -5
- package/dist/src/functions/wirings/http/pikku-command-http-types.js +0 -2
- package/dist/src/functions/wirings/http/pikku-command-openapi.js +7 -4
- package/dist/src/functions/wirings/http/pikku-http-routes.js +0 -5
- package/dist/src/functions/wirings/http/serialize-http-types.js +27 -2
- package/dist/src/functions/wirings/mcp/pikku-command-mcp-json.js +0 -5
- package/dist/src/functions/wirings/mcp/pikku-command-mcp-types.js +0 -2
- package/dist/src/functions/wirings/mcp/pikku-command-mcp.js +0 -5
- package/dist/src/functions/wirings/mcp/serialize-mcp-json.d.ts +1 -1
- package/dist/src/functions/wirings/mcp/serialize-mcp-types.js +14 -12
- package/dist/src/functions/wirings/middleware/pikku-command-middleware.js +0 -2
- package/dist/src/functions/wirings/middleware/serialize-middleware-groups-meta.js +1 -7
- package/dist/src/functions/wirings/permissions/pikku-command-permissions.d.ts +1 -0
- package/dist/src/functions/wirings/permissions/pikku-command-permissions.js +28 -0
- package/dist/src/functions/wirings/permissions/serialize-permissions-imports.d.ts +2 -0
- package/dist/src/functions/wirings/permissions/serialize-permissions-imports.js +43 -0
- package/dist/src/functions/wirings/queue/pikku-command-queue-map.js +0 -5
- package/dist/src/functions/wirings/queue/pikku-command-queue-service.js +6 -3
- package/dist/src/functions/wirings/queue/pikku-command-queue-types.js +0 -2
- package/dist/src/functions/wirings/queue/pikku-command-queue.js +0 -5
- package/dist/src/functions/wirings/queue/pikku-queue-map.js +0 -5
- package/dist/src/functions/wirings/queue/pikku-queue.js +1 -5
- package/dist/src/functions/wirings/queue/serialize-queue-meta.d.ts +1 -1
- package/dist/src/functions/wirings/queue/serialize-queue-types.js +0 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.js +5 -3
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.js +0 -4
- package/dist/src/functions/wirings/rpc/pikku-command-rpc.js +0 -2
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler-types.js +0 -2
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.js +0 -5
- package/dist/src/functions/wirings/scheduler/serialize-scheduler-types.js +0 -1
- package/dist/src/middleware/log-command-info-and-time.d.ts +2 -8
- package/dist/src/middleware/log-command-info-and-time.js +2 -14
- package/dist/src/services/cli-logger-forwarder.service.d.ts +6 -2
- package/dist/src/services/cli-logger-forwarder.service.js +9 -0
- package/dist/src/services/cli-logger.service.d.ts +4 -0
- package/dist/src/services/cli-logger.service.js +11 -0
- package/dist/src/services.d.ts +5 -0
- package/dist/src/services.js +111 -13
- package/dist/src/utils/custom-types-generator.js +8 -2
- package/dist/src/utils/file-writer.d.ts +4 -1
- package/dist/src/utils/file-writer.js +13 -3
- package/dist/src/utils/get-cli-version.d.ts +5 -0
- package/dist/src/utils/get-cli-version.js +27 -0
- package/dist/src/utils/pikku-cli-config.d.ts +1 -2
- package/dist/src/utils/pikku-cli-config.js +9 -28
- package/dist/src/utils/schema-generator.js +3 -2
- package/dist/src/utils/serialize-import-map.js +0 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -8
- package/pikku.config.json +4 -2
- package/src/cli.wiring.ts +101 -74
- package/src/functions/commands/all.ts +12 -0
- package/src/functions/runtimes/nextjs/pikku-command-nextjs.ts +12 -12
- package/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.ts +2 -2
- package/src/functions/wirings/channels/pikku-channels.ts +0 -5
- package/src/functions/wirings/channels/pikku-command-channel-types.ts +0 -2
- package/src/functions/wirings/channels/pikku-command-channels-map.ts +0 -5
- package/src/functions/wirings/channels/pikku-command-channels.ts +0 -5
- package/src/functions/wirings/channels/pikku-command-websocket-typed.ts +7 -3
- package/src/functions/wirings/channels/serialize-channel-types.ts +27 -28
- package/src/functions/wirings/channels/serialize-typed-channel-map.ts +4 -1
- package/src/functions/wirings/cli/pikku-command-cli-entry.ts +52 -9
- package/src/functions/wirings/cli/pikku-command-cli-types.ts +0 -2
- package/src/functions/wirings/cli/pikku-command-cli.ts +0 -2
- package/src/functions/wirings/cli/serialize-channel-cli-client.ts +111 -12
- package/src/functions/wirings/cli/serialize-channel-cli.ts +2 -23
- package/src/functions/wirings/cli/serialize-cli-types.ts +13 -14
- package/src/functions/wirings/cli/serialize-local-cli-bootstrap.ts +19 -14
- package/src/functions/wirings/fetch/index.ts +7 -3
- package/src/functions/wirings/functions/pikku-command-function-types-split.ts +14 -5
- package/src/functions/wirings/functions/pikku-command-function-types.ts +0 -2
- package/src/functions/wirings/functions/pikku-command-functions.ts +0 -2
- package/src/functions/wirings/functions/pikku-command-services.ts +13 -24
- package/src/functions/wirings/functions/pikku-function-types.ts +0 -2
- package/src/functions/wirings/functions/schemas.ts +0 -2
- package/src/functions/wirings/functions/serialize-function-types.ts +169 -19
- package/src/functions/wirings/functions/serialize-pikku-types-hub.ts +0 -1
- package/src/functions/wirings/http/openapi-spec-generator.ts +2 -1
- package/src/functions/wirings/http/pikku-command-http-map.ts +0 -5
- package/src/functions/wirings/http/pikku-command-http-routes.ts +0 -5
- package/src/functions/wirings/http/pikku-command-http-types.ts +0 -2
- package/src/functions/wirings/http/pikku-command-openapi.ts +9 -4
- package/src/functions/wirings/http/pikku-http-routes.ts +0 -5
- package/src/functions/wirings/http/serialize-http-types.ts +27 -2
- package/src/functions/wirings/mcp/pikku-command-mcp-json.ts +0 -5
- package/src/functions/wirings/mcp/pikku-command-mcp-types.ts +0 -2
- package/src/functions/wirings/mcp/pikku-command-mcp.ts +0 -5
- package/src/functions/wirings/mcp/serialize-mcp-json.ts +1 -1
- package/src/functions/wirings/mcp/serialize-mcp-types.ts +14 -12
- package/src/functions/wirings/middleware/pikku-command-middleware.ts +0 -2
- package/src/functions/wirings/middleware/serialize-middleware-groups-meta.ts +1 -7
- package/src/functions/wirings/permissions/pikku-command-permissions.ts +49 -0
- package/src/functions/wirings/permissions/serialize-permissions-imports.test.ts +274 -0
- package/src/functions/wirings/permissions/serialize-permissions-imports.ts +78 -0
- package/src/functions/wirings/queue/pikku-command-queue-map.ts +0 -5
- package/src/functions/wirings/queue/pikku-command-queue-service.ts +7 -3
- package/src/functions/wirings/queue/pikku-command-queue-types.ts +0 -2
- package/src/functions/wirings/queue/pikku-command-queue.ts +0 -5
- package/src/functions/wirings/queue/pikku-queue-map.ts +0 -5
- package/src/functions/wirings/queue/pikku-queue.ts +3 -6
- package/src/functions/wirings/queue/serialize-queue-meta.ts +1 -1
- package/src/functions/wirings/queue/serialize-queue-types.ts +0 -1
- package/src/functions/wirings/rpc/pikku-command-rpc-client.ts +6 -3
- package/src/functions/wirings/rpc/pikku-command-rpc-map.ts +0 -4
- package/src/functions/wirings/rpc/pikku-command-rpc.ts +0 -2
- package/src/functions/wirings/scheduler/pikku-command-scheduler-types.ts +0 -2
- package/src/functions/wirings/scheduler/pikku-command-scheduler.ts +0 -5
- package/src/functions/wirings/scheduler/serialize-scheduler-types.ts +0 -1
- package/src/middleware/log-command-info-and-time.ts +2 -28
- package/src/services/cli-logger-forwarder.service.ts +15 -2
- package/src/services/cli-logger.service.ts +15 -0
- package/src/services.ts +148 -19
- package/src/utils/custom-types-generator.ts +8 -2
- package/src/utils/file-writer.ts +19 -3
- package/src/utils/get-cli-version.ts +28 -0
- package/src/utils/pikku-cli-config.ts +6 -35
- package/src/utils/schema-generator.ts +7 -3
- package/src/utils/serialize-import-map.ts +0 -4
- package/types/application-types.d.ts +4 -1
- package/types/config.d.ts +15 -3
- package/dist/.pikku/rpc/pikku-bootstrap-rpc.gen.d.ts +0 -6
- package/dist/.pikku/rpc/pikku-bootstrap-rpc.gen.js +0 -6
- package/dist/src/serialize-pikku-types.d.ts +0 -4
- package/dist/src/serialize-pikku-types.js +0 -605
- package/src/serialize-pikku-types.ts +0 -613
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This file was generated by
|
|
2
|
+
* This file was generated by @pikku/cli@0.10.0
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* This file was generated by the @pikku/cli
|
|
6
5
|
* Core function, middleware, and permission types for all wirings
|
|
7
6
|
*/
|
|
8
7
|
|
|
9
|
-
import { CorePikkuFunctionConfig, CorePikkuPermission, CorePikkuMiddleware, addMiddleware as addMiddlewareCore, addPermission as addPermissionCore } from '@pikku/core'
|
|
8
|
+
import { CorePikkuFunctionConfig, CorePikkuPermission, CorePikkuMiddleware, CorePermissionGroup, addMiddleware as addMiddlewareCore, addPermission as addPermissionCore } from '@pikku/core'
|
|
10
9
|
import { CorePikkuFunction, CorePikkuFunctionSessionless } from '@pikku/core/function'
|
|
11
|
-
import { PikkuChannel
|
|
10
|
+
import { PikkuChannel } from '@pikku/core/channel'
|
|
11
|
+
import { PikkuMCP } from '@pikku/core/mcp'
|
|
12
12
|
|
|
13
13
|
import type { UserSession } from '../../types/application-types.d.js'
|
|
14
14
|
import type { SingletonServices } from '../../types/application-types.d.js'
|
|
15
15
|
import type { Services } from '../../types/application-types.d.js'
|
|
16
|
+
import type { Config } from '../../types/application-types.d.js'
|
|
16
17
|
import type { TypedPikkuRPC } from '../rpc/pikku-rpc-wirings-map.internal.gen.d.js'
|
|
18
|
+
import type { RequiredSingletonServices, RequiredSessionServices } from '../pikku-services.gen.js'
|
|
17
19
|
|
|
18
20
|
|
|
19
21
|
|
|
20
22
|
type Session = UserSession
|
|
21
23
|
|
|
24
|
+
|
|
22
25
|
/**
|
|
23
26
|
* Type-safe API permission definition that integrates with your application's session type.
|
|
24
27
|
* Use this to define authorization logic for your API endpoints.
|
|
@@ -36,35 +39,84 @@ export type PikkuPermission<In = unknown, RequiredServices extends Services = Se
|
|
|
36
39
|
*/
|
|
37
40
|
export type PikkuMiddleware<RequiredServices extends SingletonServices = SingletonServices> = CorePikkuMiddleware<RequiredServices, Session>
|
|
38
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Configuration object for creating a permission with metadata
|
|
44
|
+
*/
|
|
45
|
+
export type PikkuPermissionConfig<In = unknown, RequiredServices extends Services = Services> = {
|
|
46
|
+
/** The permission function */
|
|
47
|
+
func: PikkuPermission<In, RequiredServices>
|
|
48
|
+
/** Optional human-readable name for the permission */
|
|
49
|
+
name?: string
|
|
50
|
+
/** Optional description of what the permission checks */
|
|
51
|
+
description?: string
|
|
52
|
+
}
|
|
53
|
+
|
|
39
54
|
/**
|
|
40
55
|
* Factory function for creating permissions with tree-shaking support.
|
|
41
|
-
*
|
|
56
|
+
* Supports both direct function and configuration object syntax.
|
|
42
57
|
*
|
|
43
58
|
* @example
|
|
44
59
|
* ```typescript
|
|
60
|
+
* // Direct function syntax
|
|
45
61
|
* const permission = pikkuPermission(({ logger }, data, session) => {
|
|
46
|
-
* return session?.
|
|
62
|
+
* return session?.role === 'admin'
|
|
63
|
+
* })
|
|
64
|
+
*
|
|
65
|
+
* // Configuration object syntax with metadata
|
|
66
|
+
* const adminPermission = pikkuPermission({
|
|
67
|
+
* name: 'Admin Permission',
|
|
68
|
+
* description: 'Checks if user has admin role',
|
|
69
|
+
* func: async ({ logger }, data, session) => {
|
|
70
|
+
* return session?.role === 'admin'
|
|
71
|
+
* }
|
|
47
72
|
* })
|
|
48
73
|
* ```
|
|
49
74
|
*/
|
|
50
|
-
export const pikkuPermission = <In>(
|
|
51
|
-
|
|
75
|
+
export const pikkuPermission = <In>(
|
|
76
|
+
permission: PikkuPermission<In> | PikkuPermissionConfig<In>
|
|
77
|
+
): PikkuPermission<In> => {
|
|
78
|
+
return typeof permission === 'function' ? permission : permission.func
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Configuration object for creating middleware with metadata
|
|
83
|
+
*/
|
|
84
|
+
export type PikkuMiddlewareConfig<RequiredServices extends SingletonServices = SingletonServices> = {
|
|
85
|
+
/** The middleware function */
|
|
86
|
+
func: PikkuMiddleware<RequiredServices>
|
|
87
|
+
/** Optional human-readable name for the middleware */
|
|
88
|
+
name?: string
|
|
89
|
+
/** Optional description of what the middleware does */
|
|
90
|
+
description?: string
|
|
52
91
|
}
|
|
53
92
|
|
|
54
93
|
/**
|
|
55
94
|
* Factory function for creating middleware with tree-shaking support.
|
|
56
|
-
*
|
|
95
|
+
* Supports both direct function and configuration object syntax.
|
|
57
96
|
*
|
|
58
97
|
* @example
|
|
59
98
|
* ```typescript
|
|
99
|
+
* // Direct function syntax
|
|
60
100
|
* const middleware = pikkuMiddleware(({ logger }, interactions, next) => {
|
|
61
101
|
* logger.info('Middleware executed')
|
|
62
102
|
* await next()
|
|
63
103
|
* })
|
|
104
|
+
*
|
|
105
|
+
* // Configuration object syntax with metadata
|
|
106
|
+
* const logMiddleware = pikkuMiddleware({
|
|
107
|
+
* name: 'Request Logger',
|
|
108
|
+
* description: 'Logs all incoming requests',
|
|
109
|
+
* func: async ({ logger }, interactions, next) => {
|
|
110
|
+
* logger.info('Request started')
|
|
111
|
+
* await next()
|
|
112
|
+
* }
|
|
113
|
+
* })
|
|
64
114
|
* ```
|
|
65
115
|
*/
|
|
66
|
-
export const pikkuMiddleware =
|
|
67
|
-
|
|
116
|
+
export const pikkuMiddleware = <RequiredServices extends SingletonServices = SingletonServices>(
|
|
117
|
+
middleware: PikkuMiddleware<RequiredServices> | PikkuMiddlewareConfig<RequiredServices>
|
|
118
|
+
): PikkuMiddleware<RequiredServices> => {
|
|
119
|
+
return typeof middleware === 'function' ? middleware : middleware.func
|
|
68
120
|
}
|
|
69
121
|
|
|
70
122
|
/**
|
|
@@ -90,6 +142,31 @@ export const pikkuMiddlewareFactory = <In = any>(
|
|
|
90
142
|
return factory
|
|
91
143
|
}
|
|
92
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Factory function for creating permission factories
|
|
147
|
+
* Use this when your permission needs configuration/input parameters
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* export const requireRole = pikkuPermissionFactory<{ role: string }>(({
|
|
152
|
+
* role
|
|
153
|
+
* }) => {
|
|
154
|
+
* return pikkuPermission(async ({ logger }, data, session) => {
|
|
155
|
+
* if (!session || session.role !== role) {
|
|
156
|
+
* logger.warn(`Permission denied: required role '${role}'`)
|
|
157
|
+
* return false
|
|
158
|
+
* }
|
|
159
|
+
* return true
|
|
160
|
+
* })
|
|
161
|
+
* })
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export const pikkuPermissionFactory = <In = any>(
|
|
165
|
+
factory: (input: In) => PikkuPermission<any>
|
|
166
|
+
): ((input: In) => PikkuPermission<any>) => {
|
|
167
|
+
return factory
|
|
168
|
+
}
|
|
169
|
+
|
|
93
170
|
/**
|
|
94
171
|
* A sessionless API function that doesn't require user authentication.
|
|
95
172
|
* Use this for public endpoints, health checks, or operations that don't need user context.
|
|
@@ -105,7 +182,7 @@ export type PikkuFunctionSessionless<
|
|
|
105
182
|
Out = never,
|
|
106
183
|
ChannelData = null, // null means optional channel
|
|
107
184
|
MCPData = null, // null means optional MCP
|
|
108
|
-
RequiredServices extends Services = Services &
|
|
185
|
+
RequiredServices extends Services = Omit<Services, 'rpc' | 'channel' | 'mcp'> &
|
|
109
186
|
{ rpc: TypedPikkuRPC } & (
|
|
110
187
|
[ChannelData] extends [null]
|
|
111
188
|
? { channel?: PikkuChannel<unknown, Out> } // Optional channel
|
|
@@ -131,7 +208,7 @@ export type PikkuFunction<
|
|
|
131
208
|
Out = never,
|
|
132
209
|
ChannelData = null, // null means optional channel
|
|
133
210
|
MCPData = null, // null means optional MCP
|
|
134
|
-
RequiredServices extends Services = Omit<Services, 'rpc'> &
|
|
211
|
+
RequiredServices extends Services = Omit<Services, 'rpc' | 'channel' | 'mcp'> &
|
|
135
212
|
{ rpc: TypedPikkuRPC } & (
|
|
136
213
|
[ChannelData] extends [null]
|
|
137
214
|
? { channel?: PikkuChannel<unknown, Out> } // Optional channel
|
|
@@ -148,12 +225,16 @@ export type PikkuFunction<
|
|
|
148
225
|
*
|
|
149
226
|
* @template In - The input type
|
|
150
227
|
* @template Out - The output type
|
|
228
|
+
* @template ChannelData - Channel data type
|
|
229
|
+
* @template MCPData - MCP data type
|
|
151
230
|
* @template PikkuFunc - The function type (can be narrowed to PikkuFunction or PikkuFunctionSessionless)
|
|
152
231
|
*/
|
|
153
232
|
export type PikkuFunctionConfig<
|
|
154
233
|
In = unknown,
|
|
155
234
|
Out = unknown,
|
|
156
|
-
|
|
235
|
+
ChannelData = unknown,
|
|
236
|
+
MCPData = unknown,
|
|
237
|
+
PikkuFunc extends PikkuFunction<In, Out, ChannelData, MCPData> | PikkuFunctionSessionless<In, Out, ChannelData, MCPData> = PikkuFunction<In, Out, ChannelData, MCPData> | PikkuFunctionSessionless<In, Out, ChannelData, MCPData>
|
|
157
238
|
> = CorePikkuFunctionConfig<PikkuFunc, PikkuPermission<In>, PikkuMiddleware>
|
|
158
239
|
|
|
159
240
|
/**
|
|
@@ -180,7 +261,7 @@ export type PikkuFunctionConfig<
|
|
|
180
261
|
export const pikkuFunc = <In, Out = unknown>(
|
|
181
262
|
func:
|
|
182
263
|
| PikkuFunction<In, Out>
|
|
183
|
-
| CorePikkuFunctionConfig<PikkuFunction<In, Out>, PikkuPermission<In
|
|
264
|
+
| CorePikkuFunctionConfig<PikkuFunction<In, Out>, PikkuPermission<In>, PikkuMiddleware>
|
|
184
265
|
) => {
|
|
185
266
|
return typeof func === 'function' ? { func } : func
|
|
186
267
|
}
|
|
@@ -237,6 +318,73 @@ export const pikkuVoidFunc = (
|
|
|
237
318
|
return typeof func === 'function' ? { func } : func
|
|
238
319
|
}
|
|
239
320
|
|
|
321
|
+
/**
|
|
322
|
+
* Creates a Pikku config factory.
|
|
323
|
+
* Use this to define your application's configuration factory.
|
|
324
|
+
*
|
|
325
|
+
* @param func - Config factory function that returns your application's config
|
|
326
|
+
* @returns The config factory function
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* ```typescript
|
|
330
|
+
* export const createConfig = pikkuConfig(async () => {
|
|
331
|
+
* return {
|
|
332
|
+
* apiUrl: process.env.API_URL || 'http://localhost:3000',
|
|
333
|
+
* dbUrl: process.env.DATABASE_URL
|
|
334
|
+
* }
|
|
335
|
+
* })
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
export const pikkuConfig = (
|
|
339
|
+
func: (variables?: any, ...args: any[]) => Promise<Config>
|
|
340
|
+
) => func
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Creates a Pikku singleton services factory.
|
|
344
|
+
* Use this to define services that are created once and shared across all requests.
|
|
345
|
+
*
|
|
346
|
+
* @param func - Singleton services factory function
|
|
347
|
+
* @returns The singleton services factory function
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* export const createSingletonServices = pikkuServices(async (config, existingServices) => {
|
|
352
|
+
* return {
|
|
353
|
+
* config,
|
|
354
|
+
* logger: new CustomLogger(),
|
|
355
|
+
* db: await createDatabaseConnection(config.dbUrl)
|
|
356
|
+
* }
|
|
357
|
+
* })
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
export const pikkuServices = (
|
|
361
|
+
func: (config: Config, existingServices?: Partial<SingletonServices>) => Promise<RequiredSingletonServices>
|
|
362
|
+
) => func
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Creates a Pikku session services factory.
|
|
366
|
+
* Use this to define services that are created per-request/session.
|
|
367
|
+
*
|
|
368
|
+
* @param func - Session services factory function
|
|
369
|
+
* @returns The session services factory function
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```typescript
|
|
373
|
+
* export const createSessionServices = pikkuSessionServices(async (services, interaction, session) => {
|
|
374
|
+
* return {
|
|
375
|
+
* userCache: new UserCache(session?.userId)
|
|
376
|
+
* }
|
|
377
|
+
* })
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
export const pikkuSessionServices = (
|
|
381
|
+
func: (
|
|
382
|
+
services: SingletonServices,
|
|
383
|
+
interaction: any,
|
|
384
|
+
session: Session | undefined
|
|
385
|
+
) => Promise<RequiredSessionServices>
|
|
386
|
+
) => func
|
|
387
|
+
|
|
240
388
|
/**
|
|
241
389
|
* Adds global middleware for a specific tag.
|
|
242
390
|
*
|
|
@@ -271,7 +419,7 @@ export const addMiddleware = (tag: string, middleware: PikkuMiddleware[]) => {
|
|
|
271
419
|
* any wiring (HTTP, Channel, Queue, Scheduler, MCP) that includes the matching tag.
|
|
272
420
|
*
|
|
273
421
|
* @param tag - The tag that the permissions should apply to.
|
|
274
|
-
* @param permissions - The permissions array to apply for the specified tag.
|
|
422
|
+
* @param permissions - The permissions array or object to apply for the specified tag.
|
|
275
423
|
*
|
|
276
424
|
* @throws Error if permissions for the tag already exist.
|
|
277
425
|
*
|
|
@@ -283,10 +431,10 @@ export const addMiddleware = (tag: string, middleware: PikkuMiddleware[]) => {
|
|
|
283
431
|
* // Add authentication permissions for auth endpoints
|
|
284
432
|
* addPermission('auth', [authPermission])
|
|
285
433
|
*
|
|
286
|
-
* // Add read permissions for all API endpoints
|
|
287
|
-
* addPermission('api',
|
|
434
|
+
* // Add read permissions for all API endpoints (as object)
|
|
435
|
+
* addPermission('api', { read: readPermission })
|
|
288
436
|
* ```
|
|
289
437
|
*/
|
|
290
|
-
export const addPermission = <In = unknown>(tag: string, permissions: PikkuPermission<In>[]) => {
|
|
438
|
+
export const addPermission = <In = unknown>(tag: string, permissions: CorePermissionGroup<PikkuPermission<In>> | PikkuPermission<In>[]) => {
|
|
291
439
|
addPermissionCore(tag, permissions as any)
|
|
292
440
|
}
|