@pikku/cli 0.9.16-next.0 → 0.10.1
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 +15 -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/check-required-types.js +11 -1
- 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/check-required-types.ts +16 -1
- 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
|
@@ -3,23 +3,18 @@ import { getFileImportRelativePath } from '../../../utils/file-import-path.js';
|
|
|
3
3
|
import { checkRequiredTypes } from '../../../utils/check-required-types.js';
|
|
4
4
|
import { writeFileInDir } from '../../../utils/file-writer.js';
|
|
5
5
|
import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js';
|
|
6
|
-
export const serializeServicesMap = (
|
|
7
|
-
//
|
|
8
|
-
|
|
6
|
+
export const serializeServicesMap = (requiredServices, forceRequiredServices = [], servicesImport, sessionServicesImport) => {
|
|
7
|
+
// Use pre-aggregated services from inspector state
|
|
8
|
+
// This includes services from:
|
|
9
|
+
// - Wired functions (HTTP, channels, queues, schedulers, MCP, CLI, RPC)
|
|
10
|
+
// - Middleware used by wired functions
|
|
11
|
+
// - Permissions used by wired functions
|
|
12
|
+
// - Session factories
|
|
13
|
+
const usedServices = new Set(requiredServices);
|
|
9
14
|
// Internal services that are created internally and not via the create service script
|
|
10
15
|
const internalServices = new Set(['rpc', 'mcp', 'channel', 'userSession']);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
funcMeta.services.services.forEach((service) => {
|
|
14
|
-
// Only include services that are not internal
|
|
15
|
-
if (!internalServices.has(service)) {
|
|
16
|
-
usedServices.add(service);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
// Add middleware services that might not be detected from function inspection
|
|
22
|
-
middlewareServices.forEach((service) => {
|
|
16
|
+
// Add force-required services that might not be detected from function inspection
|
|
17
|
+
forceRequiredServices.forEach((service) => {
|
|
23
18
|
if (!internalServices.has(service)) {
|
|
24
19
|
usedServices.add(service);
|
|
25
20
|
}
|
|
@@ -40,10 +35,6 @@ export const serializeServicesMap = (functionsMetaData, middlewareServices = [],
|
|
|
40
35
|
// This will be resolved at compile time based on what's actually in the SingletonServices interface
|
|
41
36
|
// We don't need to hardcode which services are singletons beyond the core framework ones
|
|
42
37
|
const code = [
|
|
43
|
-
'/**',
|
|
44
|
-
' * This file was generated by the @pikku/cli',
|
|
45
|
-
' */',
|
|
46
|
-
'',
|
|
47
38
|
servicesImport,
|
|
48
39
|
sessionServicesImport,
|
|
49
40
|
"import type { PikkuInteraction } from '@pikku/core'",
|
|
@@ -77,14 +68,13 @@ export const pikkuServices = pikkuSessionlessFunc({
|
|
|
77
68
|
}
|
|
78
69
|
const servicesImport = `import type { ${singletonServicesType.type} } from '${getFileImportRelativePath(config.typesDeclarationFile, singletonServicesType.typePath, config.packageMappings)}'`;
|
|
79
70
|
const sessionServicesImport = `import type { ${sessionServicesType.type} } from '${getFileImportRelativePath(config.typesDeclarationFile, sessionServicesType.typePath, config.packageMappings)}'`;
|
|
80
|
-
const servicesCode = serializeServicesMap(visitState.
|
|
71
|
+
const servicesCode = serializeServicesMap(visitState.serviceAggregation.requiredServices, config.forceRequiredServices, servicesImport, sessionServicesImport);
|
|
81
72
|
await writeFileInDir(logger, config.servicesFile, servicesCode);
|
|
82
73
|
},
|
|
83
74
|
middleware: [
|
|
84
75
|
logCommandInfoAndTime({
|
|
85
76
|
commandStart: 'Generating Pikku services map',
|
|
86
77
|
commandEnd: 'Generated Pikku services map',
|
|
87
|
-
skipMessage: '',
|
|
88
78
|
}),
|
|
89
79
|
],
|
|
90
80
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates core function, middleware, and permission type definitions
|
|
3
3
|
*/
|
|
4
|
-
export declare const serializeFunctionTypes: (userSessionTypeImport: string, userSessionTypeName: string, singletonServicesTypeImport: string, singletonServicesTypeName: string, sessionServicesTypeImport: string, sessionServicesTypeName: string, rpcMapTypeImport: string) => string;
|
|
4
|
+
export declare const serializeFunctionTypes: (userSessionTypeImport: string, userSessionTypeName: string, singletonServicesTypeImport: string, singletonServicesTypeName: string, sessionServicesTypeImport: string, sessionServicesTypeName: string, rpcMapTypeImport: string, requiredServicesTypeImport: string, configTypeImport: string) => string;
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates core function, middleware, and permission type definitions
|
|
3
3
|
*/
|
|
4
|
-
export const serializeFunctionTypes = (userSessionTypeImport, userSessionTypeName, singletonServicesTypeImport, singletonServicesTypeName, sessionServicesTypeImport, sessionServicesTypeName, rpcMapTypeImport) => {
|
|
4
|
+
export const serializeFunctionTypes = (userSessionTypeImport, userSessionTypeName, singletonServicesTypeImport, singletonServicesTypeName, sessionServicesTypeImport, sessionServicesTypeName, rpcMapTypeImport, requiredServicesTypeImport, configTypeImport) => {
|
|
5
5
|
return `/**
|
|
6
|
-
* This file was generated by the @pikku/cli
|
|
7
6
|
* Core function, middleware, and permission types for all wirings
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
|
-
import { CorePikkuFunctionConfig, CorePikkuPermission, CorePikkuMiddleware, addMiddleware as addMiddlewareCore, addPermission as addPermissionCore } from '@pikku/core'
|
|
9
|
+
import { CorePikkuFunctionConfig, CorePikkuPermission, CorePikkuMiddleware, CorePermissionGroup, addMiddleware as addMiddlewareCore, addPermission as addPermissionCore } from '@pikku/core'
|
|
11
10
|
import { CorePikkuFunction, CorePikkuFunctionSessionless } from '@pikku/core/function'
|
|
12
|
-
import { PikkuChannel
|
|
11
|
+
import { PikkuChannel } from '@pikku/core/channel'
|
|
12
|
+
import { PikkuMCP } from '@pikku/core/mcp'
|
|
13
13
|
|
|
14
14
|
${userSessionTypeImport}
|
|
15
15
|
${singletonServicesTypeImport}
|
|
16
16
|
${sessionServicesTypeImport}
|
|
17
|
+
${configTypeImport}
|
|
17
18
|
${rpcMapTypeImport}
|
|
19
|
+
${requiredServicesTypeImport}
|
|
18
20
|
|
|
19
21
|
${singletonServicesTypeName !== 'SingletonServices' ? `type SingletonServices = ${singletonServicesTypeName}` : ''}
|
|
20
22
|
${sessionServicesTypeName !== 'Services' ? `type Services = ${sessionServicesTypeName}` : ''}
|
|
21
23
|
${userSessionTypeName !== 'Session' ? `type Session = ${userSessionTypeName}` : ''}
|
|
24
|
+
${configTypeImport.includes('Config type not found') ? 'type Config = any' : ''}
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* Type-safe API permission definition that integrates with your application's session type.
|
|
@@ -37,35 +40,84 @@ export type PikkuPermission<In = unknown, RequiredServices extends Services = Se
|
|
|
37
40
|
*/
|
|
38
41
|
export type PikkuMiddleware<RequiredServices extends SingletonServices = SingletonServices> = CorePikkuMiddleware<RequiredServices, Session>
|
|
39
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Configuration object for creating a permission with metadata
|
|
45
|
+
*/
|
|
46
|
+
export type PikkuPermissionConfig<In = unknown, RequiredServices extends Services = Services> = {
|
|
47
|
+
/** The permission function */
|
|
48
|
+
func: PikkuPermission<In, RequiredServices>
|
|
49
|
+
/** Optional human-readable name for the permission */
|
|
50
|
+
name?: string
|
|
51
|
+
/** Optional description of what the permission checks */
|
|
52
|
+
description?: string
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
/**
|
|
41
56
|
* Factory function for creating permissions with tree-shaking support.
|
|
42
|
-
*
|
|
57
|
+
* Supports both direct function and configuration object syntax.
|
|
43
58
|
*
|
|
44
59
|
* @example
|
|
45
60
|
* \`\`\`typescript
|
|
61
|
+
* // Direct function syntax
|
|
46
62
|
* const permission = pikkuPermission(({ logger }, data, session) => {
|
|
47
|
-
* return session?.
|
|
63
|
+
* return session?.role === 'admin'
|
|
64
|
+
* })
|
|
65
|
+
*
|
|
66
|
+
* // Configuration object syntax with metadata
|
|
67
|
+
* const adminPermission = pikkuPermission({
|
|
68
|
+
* name: 'Admin Permission',
|
|
69
|
+
* description: 'Checks if user has admin role',
|
|
70
|
+
* func: async ({ logger }, data, session) => {
|
|
71
|
+
* return session?.role === 'admin'
|
|
72
|
+
* }
|
|
48
73
|
* })
|
|
49
74
|
* \`\`\`
|
|
50
75
|
*/
|
|
51
|
-
export const pikkuPermission = <In>(
|
|
52
|
-
|
|
76
|
+
export const pikkuPermission = <In>(
|
|
77
|
+
permission: PikkuPermission<In> | PikkuPermissionConfig<In>
|
|
78
|
+
): PikkuPermission<In> => {
|
|
79
|
+
return typeof permission === 'function' ? permission : permission.func
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Configuration object for creating middleware with metadata
|
|
84
|
+
*/
|
|
85
|
+
export type PikkuMiddlewareConfig<RequiredServices extends SingletonServices = SingletonServices> = {
|
|
86
|
+
/** The middleware function */
|
|
87
|
+
func: PikkuMiddleware<RequiredServices>
|
|
88
|
+
/** Optional human-readable name for the middleware */
|
|
89
|
+
name?: string
|
|
90
|
+
/** Optional description of what the middleware does */
|
|
91
|
+
description?: string
|
|
53
92
|
}
|
|
54
93
|
|
|
55
94
|
/**
|
|
56
95
|
* Factory function for creating middleware with tree-shaking support.
|
|
57
|
-
*
|
|
96
|
+
* Supports both direct function and configuration object syntax.
|
|
58
97
|
*
|
|
59
98
|
* @example
|
|
60
99
|
* \`\`\`typescript
|
|
100
|
+
* // Direct function syntax
|
|
61
101
|
* const middleware = pikkuMiddleware(({ logger }, interactions, next) => {
|
|
62
102
|
* logger.info('Middleware executed')
|
|
63
103
|
* await next()
|
|
64
104
|
* })
|
|
105
|
+
*
|
|
106
|
+
* // Configuration object syntax with metadata
|
|
107
|
+
* const logMiddleware = pikkuMiddleware({
|
|
108
|
+
* name: 'Request Logger',
|
|
109
|
+
* description: 'Logs all incoming requests',
|
|
110
|
+
* func: async ({ logger }, interactions, next) => {
|
|
111
|
+
* logger.info('Request started')
|
|
112
|
+
* await next()
|
|
113
|
+
* }
|
|
114
|
+
* })
|
|
65
115
|
* \`\`\`
|
|
66
116
|
*/
|
|
67
|
-
export const pikkuMiddleware =
|
|
68
|
-
|
|
117
|
+
export const pikkuMiddleware = <RequiredServices extends SingletonServices = SingletonServices>(
|
|
118
|
+
middleware: PikkuMiddleware<RequiredServices> | PikkuMiddlewareConfig<RequiredServices>
|
|
119
|
+
): PikkuMiddleware<RequiredServices> => {
|
|
120
|
+
return typeof middleware === 'function' ? middleware : middleware.func
|
|
69
121
|
}
|
|
70
122
|
|
|
71
123
|
/**
|
|
@@ -91,6 +143,31 @@ export const pikkuMiddlewareFactory = <In = any>(
|
|
|
91
143
|
return factory
|
|
92
144
|
}
|
|
93
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Factory function for creating permission factories
|
|
148
|
+
* Use this when your permission needs configuration/input parameters
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* \`\`\`typescript
|
|
152
|
+
* export const requireRole = pikkuPermissionFactory<{ role: string }>(({
|
|
153
|
+
* role
|
|
154
|
+
* }) => {
|
|
155
|
+
* return pikkuPermission(async ({ logger }, data, session) => {
|
|
156
|
+
* if (!session || session.role !== role) {
|
|
157
|
+
* logger.warn(\`Permission denied: required role '\${role}'\`)
|
|
158
|
+
* return false
|
|
159
|
+
* }
|
|
160
|
+
* return true
|
|
161
|
+
* })
|
|
162
|
+
* })
|
|
163
|
+
* \`\`\`
|
|
164
|
+
*/
|
|
165
|
+
export const pikkuPermissionFactory = <In = any>(
|
|
166
|
+
factory: (input: In) => PikkuPermission<any>
|
|
167
|
+
): ((input: In) => PikkuPermission<any>) => {
|
|
168
|
+
return factory
|
|
169
|
+
}
|
|
170
|
+
|
|
94
171
|
/**
|
|
95
172
|
* A sessionless API function that doesn't require user authentication.
|
|
96
173
|
* Use this for public endpoints, health checks, or operations that don't need user context.
|
|
@@ -106,7 +183,7 @@ export type PikkuFunctionSessionless<
|
|
|
106
183
|
Out = never,
|
|
107
184
|
ChannelData = null, // null means optional channel
|
|
108
185
|
MCPData = null, // null means optional MCP
|
|
109
|
-
RequiredServices extends Services = Services &
|
|
186
|
+
RequiredServices extends Services = Omit<Services, 'rpc' | 'channel' | 'mcp'> &
|
|
110
187
|
{ rpc: TypedPikkuRPC } & (
|
|
111
188
|
[ChannelData] extends [null]
|
|
112
189
|
? { channel?: PikkuChannel<unknown, Out> } // Optional channel
|
|
@@ -132,7 +209,7 @@ export type PikkuFunction<
|
|
|
132
209
|
Out = never,
|
|
133
210
|
ChannelData = null, // null means optional channel
|
|
134
211
|
MCPData = null, // null means optional MCP
|
|
135
|
-
RequiredServices extends Services = Omit<Services, 'rpc'> &
|
|
212
|
+
RequiredServices extends Services = Omit<Services, 'rpc' | 'channel' | 'mcp'> &
|
|
136
213
|
{ rpc: TypedPikkuRPC } & (
|
|
137
214
|
[ChannelData] extends [null]
|
|
138
215
|
? { channel?: PikkuChannel<unknown, Out> } // Optional channel
|
|
@@ -149,12 +226,16 @@ export type PikkuFunction<
|
|
|
149
226
|
*
|
|
150
227
|
* @template In - The input type
|
|
151
228
|
* @template Out - The output type
|
|
229
|
+
* @template ChannelData - Channel data type
|
|
230
|
+
* @template MCPData - MCP data type
|
|
152
231
|
* @template PikkuFunc - The function type (can be narrowed to PikkuFunction or PikkuFunctionSessionless)
|
|
153
232
|
*/
|
|
154
233
|
export type PikkuFunctionConfig<
|
|
155
234
|
In = unknown,
|
|
156
235
|
Out = unknown,
|
|
157
|
-
|
|
236
|
+
ChannelData = unknown,
|
|
237
|
+
MCPData = unknown,
|
|
238
|
+
PikkuFunc extends PikkuFunction<In, Out, ChannelData, MCPData> | PikkuFunctionSessionless<In, Out, ChannelData, MCPData> = PikkuFunction<In, Out, ChannelData, MCPData> | PikkuFunctionSessionless<In, Out, ChannelData, MCPData>
|
|
158
239
|
> = CorePikkuFunctionConfig<PikkuFunc, PikkuPermission<In>, PikkuMiddleware>
|
|
159
240
|
|
|
160
241
|
/**
|
|
@@ -181,7 +262,7 @@ export type PikkuFunctionConfig<
|
|
|
181
262
|
export const pikkuFunc = <In, Out = unknown>(
|
|
182
263
|
func:
|
|
183
264
|
| PikkuFunction<In, Out>
|
|
184
|
-
| CorePikkuFunctionConfig<PikkuFunction<In, Out>, PikkuPermission<In
|
|
265
|
+
| CorePikkuFunctionConfig<PikkuFunction<In, Out>, PikkuPermission<In>, PikkuMiddleware>
|
|
185
266
|
) => {
|
|
186
267
|
return typeof func === 'function' ? { func } : func
|
|
187
268
|
}
|
|
@@ -238,6 +319,73 @@ export const pikkuVoidFunc = (
|
|
|
238
319
|
return typeof func === 'function' ? { func } : func
|
|
239
320
|
}
|
|
240
321
|
|
|
322
|
+
/**
|
|
323
|
+
* Creates a Pikku config factory.
|
|
324
|
+
* Use this to define your application's configuration factory.
|
|
325
|
+
*
|
|
326
|
+
* @param func - Config factory function that returns your application's config
|
|
327
|
+
* @returns The config factory function
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* \`\`\`typescript
|
|
331
|
+
* export const createConfig = pikkuConfig(async () => {
|
|
332
|
+
* return {
|
|
333
|
+
* apiUrl: process.env.API_URL || 'http://localhost:3000',
|
|
334
|
+
* dbUrl: process.env.DATABASE_URL
|
|
335
|
+
* }
|
|
336
|
+
* })
|
|
337
|
+
* \`\`\`
|
|
338
|
+
*/
|
|
339
|
+
export const pikkuConfig = (
|
|
340
|
+
func: (variables?: any, ...args: any[]) => Promise<Config>
|
|
341
|
+
) => func
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Creates a Pikku singleton services factory.
|
|
345
|
+
* Use this to define services that are created once and shared across all requests.
|
|
346
|
+
*
|
|
347
|
+
* @param func - Singleton services factory function
|
|
348
|
+
* @returns The singleton services factory function
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* \`\`\`typescript
|
|
352
|
+
* export const createSingletonServices = pikkuServices(async (config, existingServices) => {
|
|
353
|
+
* return {
|
|
354
|
+
* config,
|
|
355
|
+
* logger: new CustomLogger(),
|
|
356
|
+
* db: await createDatabaseConnection(config.dbUrl)
|
|
357
|
+
* }
|
|
358
|
+
* })
|
|
359
|
+
* \`\`\`
|
|
360
|
+
*/
|
|
361
|
+
export const pikkuServices = (
|
|
362
|
+
func: (config: Config, existingServices?: Partial<SingletonServices>) => Promise<RequiredSingletonServices>
|
|
363
|
+
) => func
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Creates a Pikku session services factory.
|
|
367
|
+
* Use this to define services that are created per-request/session.
|
|
368
|
+
*
|
|
369
|
+
* @param func - Session services factory function
|
|
370
|
+
* @returns The session services factory function
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* \`\`\`typescript
|
|
374
|
+
* export const createSessionServices = pikkuSessionServices(async (services, interaction, session) => {
|
|
375
|
+
* return {
|
|
376
|
+
* userCache: new UserCache(session?.userId)
|
|
377
|
+
* }
|
|
378
|
+
* })
|
|
379
|
+
* \`\`\`
|
|
380
|
+
*/
|
|
381
|
+
export const pikkuSessionServices = (
|
|
382
|
+
func: (
|
|
383
|
+
services: SingletonServices,
|
|
384
|
+
interaction: any,
|
|
385
|
+
session: Session | undefined
|
|
386
|
+
) => Promise<RequiredSessionServices>
|
|
387
|
+
) => func
|
|
388
|
+
|
|
241
389
|
/**
|
|
242
390
|
* Adds global middleware for a specific tag.
|
|
243
391
|
*
|
|
@@ -272,7 +420,7 @@ export const addMiddleware = (tag: string, middleware: PikkuMiddleware[]) => {
|
|
|
272
420
|
* any wiring (HTTP, Channel, Queue, Scheduler, MCP) that includes the matching tag.
|
|
273
421
|
*
|
|
274
422
|
* @param tag - The tag that the permissions should apply to.
|
|
275
|
-
* @param permissions - The permissions array to apply for the specified tag.
|
|
423
|
+
* @param permissions - The permissions array or object to apply for the specified tag.
|
|
276
424
|
*
|
|
277
425
|
* @throws Error if permissions for the tag already exist.
|
|
278
426
|
*
|
|
@@ -284,11 +432,11 @@ export const addMiddleware = (tag: string, middleware: PikkuMiddleware[]) => {
|
|
|
284
432
|
* // Add authentication permissions for auth endpoints
|
|
285
433
|
* addPermission('auth', [authPermission])
|
|
286
434
|
*
|
|
287
|
-
* // Add read permissions for all API endpoints
|
|
288
|
-
* addPermission('api',
|
|
435
|
+
* // Add read permissions for all API endpoints (as object)
|
|
436
|
+
* addPermission('api', { read: readPermission })
|
|
289
437
|
* \`\`\`
|
|
290
438
|
*/
|
|
291
|
-
export const addPermission = <In = unknown>(tag: string, permissions: PikkuPermission<In>[]) => {
|
|
439
|
+
export const addPermission = <In = unknown>(tag: string, permissions: CorePermissionGroup<PikkuPermission<In>> | PikkuPermission<In>[]) => {
|
|
292
440
|
addPermissionCore(tag, permissions as any)
|
|
293
441
|
}
|
|
294
442
|
`;
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const serializePikkuTypesHub = (functionTypesImportPath, httpTypesImportPath, channelTypesImportPath, schedulerTypesImportPath, queueTypesImportPath, mcpTypesImportPath, cliTypesImportPath) => {
|
|
5
5
|
return `/**
|
|
6
|
-
* This file was generated by the @pikku/cli
|
|
7
6
|
* Main type export hub - re-exports all wiring-specific types
|
|
8
7
|
*/
|
|
9
8
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FunctionsMeta
|
|
1
|
+
import { FunctionsMeta } from '@pikku/core';
|
|
2
|
+
import { HTTPWiringsMeta } from '@pikku/core/http';
|
|
2
3
|
import { CLILogger } from '../../../services/cli-logger.service.js';
|
|
3
4
|
interface OpenAPISpec {
|
|
4
5
|
openapi: string;
|
|
@@ -13,11 +13,6 @@ export const pikkuHTTPMap = pikkuSessionlessFunc({
|
|
|
13
13
|
logCommandInfoAndTime({
|
|
14
14
|
commandStart: 'Creating HTTP map',
|
|
15
15
|
commandEnd: 'Created HTTP map',
|
|
16
|
-
skipCondition: async ({ getInspectorState }) => {
|
|
17
|
-
const { http } = await getInspectorState();
|
|
18
|
-
return http.files.size === 0;
|
|
19
|
-
},
|
|
20
|
-
skipMessage: 'none found',
|
|
21
16
|
}),
|
|
22
17
|
],
|
|
23
18
|
});
|
|
@@ -15,11 +15,6 @@ export const pikkuHTTP = pikkuSessionlessFunc({
|
|
|
15
15
|
logCommandInfoAndTime({
|
|
16
16
|
commandStart: 'Finding HTTP routes',
|
|
17
17
|
commandEnd: 'Found HTTP routes',
|
|
18
|
-
skipCondition: async ({ getInspectorState }) => {
|
|
19
|
-
const visitState = await getInspectorState();
|
|
20
|
-
return visitState.http.files.size === 0;
|
|
21
|
-
},
|
|
22
|
-
skipMessage: 'none found',
|
|
23
18
|
}),
|
|
24
19
|
],
|
|
25
20
|
});
|
|
@@ -6,11 +6,16 @@ import { generateOpenAPISpec } from './openapi-spec-generator.js';
|
|
|
6
6
|
import { stringify } from 'yaml';
|
|
7
7
|
export const pikkuOpenAPI = pikkuSessionlessFunc({
|
|
8
8
|
func: async ({ logger, config, getInspectorState }) => {
|
|
9
|
-
const { http, functions } = await getInspectorState();
|
|
10
9
|
const { tsconfig, openAPI, schemasFromTypes } = config;
|
|
10
|
+
// If openAPI outputFile is not defined, clean up any existing file and return
|
|
11
11
|
if (!openAPI?.outputFile) {
|
|
12
|
-
|
|
12
|
+
logger.info({
|
|
13
|
+
message: 'Skipping creating OpenAPI spec since openAPI outfile is not defined.',
|
|
14
|
+
type: 'skip',
|
|
15
|
+
});
|
|
16
|
+
return;
|
|
13
17
|
}
|
|
18
|
+
const { http, functions } = await getInspectorState();
|
|
14
19
|
const schemas = await generateSchemas(logger, tsconfig, functions.typesMap, functions.meta, http.meta, schemasFromTypes);
|
|
15
20
|
const openAPISpec = await generateOpenAPISpec(logger, functions.meta, http.meta, schemas, openAPI.additionalInfo);
|
|
16
21
|
if (openAPI.outputFile.endsWith('.json')) {
|
|
@@ -27,8 +32,6 @@ export const pikkuOpenAPI = pikkuSessionlessFunc({
|
|
|
27
32
|
logCommandInfoAndTime({
|
|
28
33
|
commandStart: 'Creating OpenAPI spec',
|
|
29
34
|
commandEnd: 'Created OpenAPI spec',
|
|
30
|
-
skipCondition: ({ config }) => config.openAPI?.outputFile === undefined,
|
|
31
|
-
skipMessage: 'openAPI outfile is not defined',
|
|
32
35
|
}),
|
|
33
36
|
],
|
|
34
37
|
});
|
|
@@ -15,11 +15,6 @@ export const pikkuHTTP = pikkuSessionlessFunc({
|
|
|
15
15
|
logCommandInfoAndTime({
|
|
16
16
|
commandStart: 'Finding HTTP routes',
|
|
17
17
|
commandEnd: 'Found HTTP routes',
|
|
18
|
-
skipCondition: async ({ getInspectorState }) => {
|
|
19
|
-
const visitState = await getInspectorState();
|
|
20
|
-
return visitState.http.files.size === 0;
|
|
21
|
-
},
|
|
22
|
-
skipMessage: 'none found',
|
|
23
18
|
}),
|
|
24
19
|
],
|
|
25
20
|
});
|
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const serializeHTTPTypes = (functionTypesImportPath) => {
|
|
5
5
|
return `/**
|
|
6
|
-
* This file was generated by the @pikku/cli
|
|
7
6
|
* HTTP-specific type definitions for tree-shaking optimization
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
|
-
import { AssertHTTPWiringParams, wireHTTP as wireHTTPCore, addHTTPMiddleware as addHTTPMiddlewareCore } from '@pikku/core/http'
|
|
9
|
+
import { AssertHTTPWiringParams, wireHTTP as wireHTTPCore, addHTTPMiddleware as addHTTPMiddlewareCore, addHTTPPermission as addHTTPPermissionCore } from '@pikku/core/http'
|
|
11
10
|
import type { PikkuFunction, PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware } from '${functionTypesImportPath}'
|
|
12
11
|
import type { CoreHTTPFunctionWiring } from '@pikku/core/http'
|
|
13
12
|
|
|
@@ -60,5 +59,31 @@ export const addHTTPMiddleware = (
|
|
|
60
59
|
) => {
|
|
61
60
|
addHTTPMiddlewareCore(routeOrMiddleware as any, middleware as any)
|
|
62
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Registers HTTP permissions either globally or for a specific route pattern.
|
|
65
|
+
*
|
|
66
|
+
* When a string route pattern is provided along with permissions, the permissions
|
|
67
|
+
* are applied only to that route. Permissions can be passed as an array or as a
|
|
68
|
+
* permission group object.
|
|
69
|
+
*
|
|
70
|
+
* @param pattern - Route pattern string (e.g., '*' for all routes, '/api/*' for specific routes)
|
|
71
|
+
* @param permissions - The permissions to apply for the specified route pattern
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* \`\`\`typescript
|
|
75
|
+
* // Add global HTTP permissions
|
|
76
|
+
* addHTTPPermission('*', { global: globalPermission })
|
|
77
|
+
*
|
|
78
|
+
* // Add route-specific permissions
|
|
79
|
+
* addHTTPPermission('/api/admin/*', { admin: adminPermission })
|
|
80
|
+
* \`\`\`
|
|
81
|
+
*/
|
|
82
|
+
export const addHTTPPermission = <In = unknown>(
|
|
83
|
+
pattern: string,
|
|
84
|
+
permissions: Record<string, PikkuPermission<In>> | PikkuPermission<In>[]
|
|
85
|
+
) => {
|
|
86
|
+
addHTTPPermissionCore(pattern, permissions as any)
|
|
87
|
+
}
|
|
63
88
|
`;
|
|
64
89
|
};
|
|
@@ -18,11 +18,6 @@ export const pikkuMCPJSON = pikkuSessionlessFunc({
|
|
|
18
18
|
logCommandInfoAndTime({
|
|
19
19
|
commandStart: 'Generating MCP JSON',
|
|
20
20
|
commandEnd: 'Generated MCP JSON',
|
|
21
|
-
skipCondition: async ({ getInspectorState, config }) => {
|
|
22
|
-
const { mcpEndpoints } = await getInspectorState();
|
|
23
|
-
return mcpEndpoints.files.size === 0 || !config.mcpJsonFile;
|
|
24
|
-
},
|
|
25
|
-
skipMessage: 'none found or mcpJsonFile not set',
|
|
26
21
|
}),
|
|
27
22
|
],
|
|
28
23
|
});
|
|
@@ -61,11 +61,6 @@ pikkuState('mcp', 'promptsMeta', ${JSON.stringify(promptsMetaWithArguments, null
|
|
|
61
61
|
logCommandInfoAndTime({
|
|
62
62
|
commandStart: 'Finding MCP endpoints',
|
|
63
63
|
commandEnd: 'Found MCP endpoints',
|
|
64
|
-
skipCondition: async ({ getInspectorState }) => {
|
|
65
|
-
const { mcpEndpoints } = await getInspectorState();
|
|
66
|
-
return mcpEndpoints.files.size === 0;
|
|
67
|
-
},
|
|
68
|
-
skipMessage: 'none found',
|
|
69
64
|
}),
|
|
70
65
|
],
|
|
71
66
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from '@pikku/core';
|
|
1
|
+
import { MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from '@pikku/core/mcp';
|
|
2
2
|
import { FunctionsMeta } from '@pikku/core';
|
|
3
3
|
import { TypesMap } from '@pikku/inspector';
|
|
4
4
|
import { CLILogger } from '../../../services/cli-logger.service.js';
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const serializeMCPTypes = (functionTypesImportPath) => {
|
|
5
5
|
return `/**
|
|
6
|
-
* This file was generated by the @pikku/cli
|
|
7
6
|
* MCP-specific type definitions for tree-shaking optimization
|
|
8
7
|
*/
|
|
9
8
|
|
|
@@ -16,8 +15,9 @@ import {
|
|
|
16
15
|
wireMCPPrompt as wireMCPPromptCore,
|
|
17
16
|
MCPResourceResponse,
|
|
18
17
|
MCPToolResponse,
|
|
19
|
-
MCPPromptResponse
|
|
20
|
-
|
|
18
|
+
MCPPromptResponse,
|
|
19
|
+
AssertMCPResourceURIParams
|
|
20
|
+
} from '@pikku/core/mcp'
|
|
21
21
|
|
|
22
22
|
import type { PikkuFunctionConfig, PikkuFunctionSessionless } from '${functionTypesImportPath}'
|
|
23
23
|
|
|
@@ -25,8 +25,9 @@ import type { PikkuFunctionConfig, PikkuFunctionSessionless } from '${functionTy
|
|
|
25
25
|
* Type definition for MCP resources that provide data to AI models.
|
|
26
26
|
*
|
|
27
27
|
* @template In - Input type for the resource request
|
|
28
|
+
* @template URI - URI template string type for compile-time parameter validation
|
|
28
29
|
*/
|
|
29
|
-
type MCPResourceWiring<In> = CoreMCPResource<PikkuFunctionConfig<In, MCPResourceResponse>>
|
|
30
|
+
type MCPResourceWiring<In, URI extends string> = CoreMCPResource<PikkuFunctionConfig<In, MCPResourceResponse>> & { uri: URI }
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* Type definition for MCP tools that AI models can invoke.
|
|
@@ -47,10 +48,11 @@ type MCPPromptWiring<In> = CoreMCPPrompt<PikkuFunctionConfig<In, MCPPromptRespon
|
|
|
47
48
|
* Resources provide data that AI models can access.
|
|
48
49
|
*
|
|
49
50
|
* @template In - Input type for the resource request
|
|
51
|
+
* @template URI - URI template string for compile-time parameter validation
|
|
50
52
|
* @param mcpResource - MCP resource definition with data provider function
|
|
51
53
|
*/
|
|
52
|
-
export const wireMCPResource = <In>(
|
|
53
|
-
mcpResource: MCPResourceWiring<In>
|
|
54
|
+
export const wireMCPResource = <In, URI extends string>(
|
|
55
|
+
mcpResource: MCPResourceWiring<In, URI> & AssertMCPResourceURIParams<In, URI>
|
|
54
56
|
) => {
|
|
55
57
|
wireMCPResourceCore(mcpResource as any)
|
|
56
58
|
}
|
|
@@ -96,8 +98,8 @@ export const pikkuMCPPromptFunc = <In>(
|
|
|
96
98
|
func: PikkuFunctionSessionless<In, MCPPromptResponse>
|
|
97
99
|
name?: string
|
|
98
100
|
}
|
|
99
|
-
) => {
|
|
100
|
-
return typeof func === 'function' ? func : func
|
|
101
|
+
): PikkuFunctionConfig<In, MCPPromptResponse> => {
|
|
102
|
+
return typeof func === 'function' ? { func } : func
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
/**
|
|
@@ -115,8 +117,8 @@ export const pikkuMCPToolFunc = <In>(
|
|
|
115
117
|
func: PikkuFunctionSessionless<In, MCPToolResponse, null, true>
|
|
116
118
|
name?: string
|
|
117
119
|
}
|
|
118
|
-
) => {
|
|
119
|
-
return typeof func === 'function' ? func : func
|
|
120
|
+
): PikkuFunctionConfig<In, MCPToolResponse> => {
|
|
121
|
+
return typeof func === 'function' ? { func } : func
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
/**
|
|
@@ -134,8 +136,8 @@ export const pikkuMCPResourceFunc = <In>(
|
|
|
134
136
|
func: PikkuFunctionSessionless<In, MCPResourceResponse, null, true>
|
|
135
137
|
name?: string
|
|
136
138
|
}
|
|
137
|
-
) => {
|
|
138
|
-
return typeof func === 'function' ? func : func
|
|
139
|
+
): PikkuFunctionConfig<In, MCPResourceResponse> => {
|
|
140
|
+
return typeof func === 'function' ? { func } : func
|
|
139
141
|
}
|
|
140
142
|
`;
|
|
141
143
|
};
|