@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
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const serializeChannelTypes = (functionTypesImportPath) => {
|
|
5
5
|
return `/**
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
* Channel-specific type definitions for tree-shaking optimization
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { CoreChannel, wireChannel as wireChannelCore } from '@pikku/core/channel'
|
|
11
11
|
import { CorePikkuFunctionConfig } from '@pikku/core'
|
|
12
12
|
import { AssertHTTPWiringParams } from '@pikku/core/http'
|
|
13
|
-
import type {
|
|
13
|
+
import type { PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware } from '${functionTypesImportPath}'
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Type definition for WebSocket channels with typed data exchange.
|
|
@@ -19,64 +19,63 @@ import type { PikkuFunction, PikkuFunctionSessionless, PikkuPermission, PikkuMid
|
|
|
19
19
|
* @template ChannelData - Type of data exchanged through the channel
|
|
20
20
|
* @template Channel - String literal type for the channel name
|
|
21
21
|
*/
|
|
22
|
-
type
|
|
23
|
-
|
|
22
|
+
type ChannelWiring<ChannelData, Channel extends string> = CoreChannel<
|
|
23
|
+
ChannelData,
|
|
24
|
+
Channel,
|
|
25
|
+
CorePikkuFunctionConfig<PikkuFunctionSessionless<void, any, ChannelData>, PikkuPermission<void>, PikkuMiddleware>,
|
|
26
|
+
CorePikkuFunctionConfig<PikkuFunctionSessionless<void, void, ChannelData>, PikkuPermission<void>, PikkuMiddleware>,
|
|
27
|
+
CorePikkuFunctionConfig<PikkuFunctionSessionless<any, any, ChannelData>, PikkuPermission<any>, PikkuMiddleware>,
|
|
28
|
+
PikkuPermission,
|
|
29
|
+
PikkuMiddleware
|
|
30
|
+
>
|
|
24
31
|
|
|
25
32
|
/**
|
|
26
33
|
* Creates a function that handles WebSocket channel connections.
|
|
27
34
|
* Called when a client connects to a channel.
|
|
28
35
|
*
|
|
29
36
|
* @template Out - Output type for connection response
|
|
30
|
-
* @template ChannelData - Type of data associated with the channel
|
|
31
37
|
* @param func - Function definition, either direct function or configuration object
|
|
32
|
-
* @returns The
|
|
38
|
+
* @returns The normalized configuration object
|
|
33
39
|
*/
|
|
34
|
-
export const pikkuChannelConnectionFunc = <Out = unknown
|
|
40
|
+
export const pikkuChannelConnectionFunc = <Out = unknown>(
|
|
35
41
|
func:
|
|
36
|
-
| PikkuFunctionSessionless<void, Out,
|
|
37
|
-
|
|
|
38
|
-
func: PikkuFunctionSessionless<void, Out, ChannelData>
|
|
39
|
-
name?: string
|
|
40
|
-
}
|
|
42
|
+
| PikkuFunctionSessionless<void, Out, unknown>
|
|
43
|
+
| CorePikkuFunctionConfig<PikkuFunctionSessionless<void, Out, unknown>, PikkuPermission<void>, PikkuMiddleware>
|
|
41
44
|
) => {
|
|
42
|
-
return typeof func === 'function' ? func : func
|
|
45
|
+
return typeof func === 'function' ? { func } : func
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
/**
|
|
46
49
|
* Creates a function that handles WebSocket channel disconnections.
|
|
47
50
|
* Called when a client disconnects from a channel.
|
|
48
51
|
*
|
|
49
|
-
* @template ChannelData - Type of data associated with the channel
|
|
50
52
|
* @param func - Function definition, either direct function or configuration object
|
|
51
|
-
* @returns The
|
|
53
|
+
* @returns The normalized configuration object
|
|
52
54
|
*/
|
|
53
|
-
export const pikkuChannelDisconnectionFunc =
|
|
55
|
+
export const pikkuChannelDisconnectionFunc = (
|
|
54
56
|
func:
|
|
55
|
-
| PikkuFunctionSessionless<void, void,
|
|
56
|
-
|
|
|
57
|
-
func: PikkuFunction<void, void, ChannelData>
|
|
58
|
-
name?: string
|
|
59
|
-
}
|
|
57
|
+
| PikkuFunctionSessionless<void, void, unknown>
|
|
58
|
+
| CorePikkuFunctionConfig<PikkuFunctionSessionless<void, void, unknown>, PikkuPermission<void>, PikkuMiddleware>
|
|
60
59
|
) => {
|
|
61
|
-
return typeof func === 'function' ? func : func
|
|
60
|
+
return typeof func === 'function' ? { func } : func
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
/**
|
|
65
64
|
* Creates a function that handles WebSocket channel messages.
|
|
66
65
|
* Called when a message is received on a channel.
|
|
66
|
+
* This is the same as pikkuSessionlessFunc but with ChannelData = unknown by default.
|
|
67
67
|
*
|
|
68
68
|
* @template In - Input type for channel messages
|
|
69
69
|
* @template Out - Output type for channel responses
|
|
70
|
-
* @template ChannelData - Type of data associated with the channel
|
|
71
70
|
* @param func - Function definition, either direct function or configuration object
|
|
72
|
-
* @returns The
|
|
71
|
+
* @returns The normalized configuration object
|
|
73
72
|
*/
|
|
74
|
-
export const pikkuChannelFunc = <In
|
|
73
|
+
export const pikkuChannelFunc = <In, Out = unknown>(
|
|
75
74
|
func:
|
|
76
|
-
| PikkuFunctionSessionless<In, Out,
|
|
77
|
-
| CorePikkuFunctionConfig<
|
|
75
|
+
| PikkuFunctionSessionless<In, Out, unknown>
|
|
76
|
+
| CorePikkuFunctionConfig<PikkuFunctionSessionless<In, Out, unknown>, PikkuPermission<In>, PikkuMiddleware>
|
|
78
77
|
) => {
|
|
79
|
-
return typeof func === 'function' ? func : func
|
|
78
|
+
return typeof func === 'function' ? { func } : func
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
/**
|
|
@@ -4,7 +4,10 @@ export const serializeTypedChannelsMap = (relativeToPath, packageMappings, types
|
|
|
4
4
|
const { channels, requiredTypes } = generateChannels(functionsMeta, channelsMeta);
|
|
5
5
|
typesMap.customTypes.forEach(({ references }) => {
|
|
6
6
|
for (const reference of references) {
|
|
7
|
-
|
|
7
|
+
// Skip __object types (placeholder types for invalid/broken functions)
|
|
8
|
+
if (reference !== '__object' && !reference.startsWith('__object_')) {
|
|
9
|
+
requiredTypes.add(reference);
|
|
10
|
+
}
|
|
8
11
|
}
|
|
9
12
|
});
|
|
10
13
|
const imports = serializeImportMap(relativeToPath, packageMappings, typesMap, requiredTypes);
|
|
@@ -5,7 +5,10 @@ import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-
|
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { serializeLocalCLIBootstrap } from './serialize-local-cli-bootstrap.js';
|
|
7
7
|
import { serializeChannelCLI } from './serialize-channel-cli.js';
|
|
8
|
-
import { serializeChannelCLIClient } from './serialize-channel-cli-client.js';
|
|
8
|
+
import { serializeChannelCLIClient, collectRendererNames, } from './serialize-channel-cli-client.js';
|
|
9
|
+
import { existsSync } from 'fs';
|
|
10
|
+
import { rm } from 'fs/promises';
|
|
11
|
+
import { ErrorCode } from '@pikku/inspector';
|
|
9
12
|
export const pikkuCLIEntry = pikkuSessionlessFunc({
|
|
10
13
|
func: async ({ logger, config, getInspectorState }) => {
|
|
11
14
|
const visitState = await getInspectorState();
|
|
@@ -20,7 +23,7 @@ export const pikkuCLIEntry = pikkuSessionlessFunc({
|
|
|
20
23
|
}
|
|
21
24
|
// Generate bootstrap files for each configured entrypoint
|
|
22
25
|
for (const [programName, entrypointConfigs] of Object.entries(config.cli.entrypoints)) {
|
|
23
|
-
const programMeta = visitState.cli.meta[programName];
|
|
26
|
+
const programMeta = visitState.cli.meta.programs[programName];
|
|
24
27
|
if (!programMeta) {
|
|
25
28
|
logger.warn(`CLI program '${programName}' not found in metadata, skipping`);
|
|
26
29
|
continue;
|
|
@@ -51,7 +54,32 @@ export const pikkuCLIEntry = pikkuSessionlessFunc({
|
|
|
51
54
|
// Generate client code if clientPath is provided
|
|
52
55
|
if (channelClientPath) {
|
|
53
56
|
const channelClientFile = join(config.rootDir, channelClientPath);
|
|
54
|
-
|
|
57
|
+
// Validate that renderers don't depend on services (client-side renderers can't access server services)
|
|
58
|
+
const rendererNames = collectRendererNames(programMeta);
|
|
59
|
+
const problematicRenderers = [];
|
|
60
|
+
for (const rendererName of rendererNames) {
|
|
61
|
+
const rendererMeta = visitState.cli.meta.renderers[rendererName];
|
|
62
|
+
if (rendererMeta?.services?.services?.length > 0) {
|
|
63
|
+
problematicRenderers.push({
|
|
64
|
+
name: rendererName,
|
|
65
|
+
services: rendererMeta.services.services,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// If any renderers depend on services, abort client generation
|
|
70
|
+
if (problematicRenderers.length > 0) {
|
|
71
|
+
const details = problematicRenderers
|
|
72
|
+
.map((r) => ` - ${r.name} depends on: ${r.services.join(', ')}`)
|
|
73
|
+
.join('\n');
|
|
74
|
+
logger.critical(ErrorCode.CLI_CLIENTSIDE_RENDERER_HAS_SERVICES, `Cannot generate CLI channel client for '${programName}': renderers cannot depend on services (client-side execution)\n${details}\n\nRenderers used in CLI-over-channel must be service-free since they execute on the client.`);
|
|
75
|
+
// Delete existing client file if it exists
|
|
76
|
+
if (existsSync(channelClientFile)) {
|
|
77
|
+
await rm(channelClientFile);
|
|
78
|
+
logger.debug(`Deleted existing CLI channel client: ${channelClientFile}`);
|
|
79
|
+
}
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const clientCode = serializeChannelCLIClient(programName, programMeta, channelClientFile, config, config.bootstrapFile, channelRoute, visitState.cli.meta.renderers);
|
|
55
83
|
await writeFileInDir(logger, channelClientFile, clientCode);
|
|
56
84
|
logger.debug(`Serialized CLI channel client for ${programName}: ${channelClientFile}`);
|
|
57
85
|
}
|
|
@@ -90,11 +118,6 @@ export const pikkuCLIEntry = pikkuSessionlessFunc({
|
|
|
90
118
|
logCommandInfoAndTime({
|
|
91
119
|
commandStart: 'Serializing CLI',
|
|
92
120
|
commandEnd: 'Serialized CLI',
|
|
93
|
-
skipCondition: async ({ getInspectorState }) => {
|
|
94
|
-
const visitState = await getInspectorState();
|
|
95
|
-
return visitState.cli.files.size === 0;
|
|
96
|
-
},
|
|
97
|
-
skipMessage: 'none found',
|
|
98
121
|
}),
|
|
99
122
|
],
|
|
100
123
|
});
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { CLIProgramMeta } from '@pikku/core';
|
|
1
|
+
import { CLIProgramMeta } from '@pikku/core/cli';
|
|
2
2
|
import { Config } from '../../../../types/application-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Collect all unique renderer names from CLI metadata (populated by inspector)
|
|
5
|
+
*/
|
|
6
|
+
export declare function collectRendererNames(programMeta: CLIProgramMeta): Set<string>;
|
|
3
7
|
/**
|
|
4
8
|
* Serializes a CLI-over-Channel client bootstrap file
|
|
5
9
|
* Similar to local CLI bootstrap but uses WebSocket connection
|
|
6
10
|
*/
|
|
7
|
-
export declare function serializeChannelCLIClient(programName: string, programMeta: CLIProgramMeta, clientFile: string, config: Config, cliBootstrapPath: string, channelRoute?: string): string;
|
|
11
|
+
export declare function serializeChannelCLIClient(programName: string, programMeta: CLIProgramMeta, clientFile: string, config: Config, cliBootstrapPath: string, channelRoute?: string, renderersMeta?: Record<string, any>): string;
|
|
@@ -1,22 +1,99 @@
|
|
|
1
1
|
import { getFileImportRelativePath } from '../../../utils/file-import-path.js';
|
|
2
|
+
/**
|
|
3
|
+
* Collect all unique renderer names from CLI metadata (populated by inspector)
|
|
4
|
+
*/
|
|
5
|
+
export function collectRendererNames(programMeta) {
|
|
6
|
+
const rendererNames = new Set();
|
|
7
|
+
// Add program-level default renderer
|
|
8
|
+
if (programMeta.defaultRenderName) {
|
|
9
|
+
rendererNames.add(programMeta.defaultRenderName);
|
|
10
|
+
}
|
|
11
|
+
// Recursively collect renderer names from commands
|
|
12
|
+
function collectFromCommand(command) {
|
|
13
|
+
if (command.renderName) {
|
|
14
|
+
rendererNames.add(command.renderName);
|
|
15
|
+
}
|
|
16
|
+
// Recursively process subcommands
|
|
17
|
+
if (command.subcommands) {
|
|
18
|
+
for (const subCommand of Object.values(command.subcommands)) {
|
|
19
|
+
collectFromCommand(subCommand);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Process all commands
|
|
24
|
+
for (const command of Object.values(programMeta.commands)) {
|
|
25
|
+
collectFromCommand(command);
|
|
26
|
+
}
|
|
27
|
+
return rendererNames;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build a renderers map for CLI commands
|
|
31
|
+
*/
|
|
32
|
+
function buildRenderersMap(programMeta) {
|
|
33
|
+
const entries = [];
|
|
34
|
+
// Build map entries for each command that has a renderer
|
|
35
|
+
function addCommandRenderer(command, path) {
|
|
36
|
+
const commandId = path.join('.');
|
|
37
|
+
if (command.renderName) {
|
|
38
|
+
entries.push(` '${commandId}': ${command.renderName}`);
|
|
39
|
+
}
|
|
40
|
+
// Recursively process subcommands
|
|
41
|
+
if (command.subcommands) {
|
|
42
|
+
for (const [subName, subCommand] of Object.entries(command.subcommands)) {
|
|
43
|
+
addCommandRenderer(subCommand, [...path, subName]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Process all commands
|
|
48
|
+
for (const [commandName, command] of Object.entries(programMeta.commands)) {
|
|
49
|
+
addCommandRenderer(command, [commandName]);
|
|
50
|
+
}
|
|
51
|
+
if (entries.length === 0) {
|
|
52
|
+
return '{}';
|
|
53
|
+
}
|
|
54
|
+
return `{\n${entries.join(',\n')}\n }`;
|
|
55
|
+
}
|
|
2
56
|
/**
|
|
3
57
|
* Serializes a CLI-over-Channel client bootstrap file
|
|
4
58
|
* Similar to local CLI bootstrap but uses WebSocket connection
|
|
5
59
|
*/
|
|
6
|
-
export function serializeChannelCLIClient(programName, programMeta, clientFile, config, cliBootstrapPath, channelRoute) {
|
|
60
|
+
export function serializeChannelCLIClient(programName, programMeta, clientFile, config, cliBootstrapPath, channelRoute, renderersMeta) {
|
|
7
61
|
const capitalizedName = programName.charAt(0).toUpperCase() + programName.slice(1).replace(/-/g, '');
|
|
8
62
|
const finalChannelRoute = channelRoute || `/cli/${programName}`;
|
|
9
63
|
// Get relative import path to CLI bootstrap (for metadata)
|
|
10
64
|
const bootstrapImportPath = getFileImportRelativePath(clientFile, cliBootstrapPath, config.packageMappings);
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
65
|
+
// Collect all unique renderer names from CLI metadata (populated by inspector)
|
|
66
|
+
const rendererNames = collectRendererNames(programMeta);
|
|
67
|
+
// Generate renderer imports from their source files
|
|
68
|
+
let rendererImports = '';
|
|
69
|
+
if (rendererNames.size > 0 && renderersMeta) {
|
|
70
|
+
const importsByFile = new Map();
|
|
71
|
+
for (const rendererName of rendererNames) {
|
|
72
|
+
const meta = renderersMeta[rendererName];
|
|
73
|
+
if (meta?.exportedName && meta?.filePath) {
|
|
74
|
+
const relativePath = getFileImportRelativePath(clientFile, meta.filePath, config.packageMappings);
|
|
75
|
+
if (!importsByFile.has(relativePath)) {
|
|
76
|
+
importsByFile.set(relativePath, []);
|
|
77
|
+
}
|
|
78
|
+
importsByFile.get(relativePath).push(meta.exportedName);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Generate import statements
|
|
82
|
+
for (const [path, names] of importsByFile) {
|
|
83
|
+
rendererImports += `import { ${names.join(', ')} } from '${path}'\n`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Build renderers map
|
|
87
|
+
const renderersMap = buildRenderersMap(programMeta);
|
|
88
|
+
// Determine default renderer
|
|
89
|
+
const defaultRendererCode = programMeta.defaultRenderName
|
|
90
|
+
? `,\n defaultRenderer: ${programMeta.defaultRenderName}`
|
|
91
|
+
: '';
|
|
92
|
+
return `
|
|
16
93
|
import { executeCLIViaChannel } from '@pikku/core/cli/channel'
|
|
17
94
|
import { CorePikkuWebsocket } from '@pikku/websocket'
|
|
18
95
|
import '${bootstrapImportPath}'
|
|
19
|
-
|
|
96
|
+
${rendererImports}
|
|
20
97
|
/**
|
|
21
98
|
* ${capitalizedName} CLI Client (via WebSocket Channel)
|
|
22
99
|
* Executes CLI commands over a WebSocket connection
|
|
@@ -28,14 +105,14 @@ export async function ${capitalizedName}CLIClient(
|
|
|
28
105
|
// Create WebSocket connection
|
|
29
106
|
const pikkuWS = new CorePikkuWebsocket(url)
|
|
30
107
|
|
|
31
|
-
//
|
|
32
|
-
const renderers = {}
|
|
108
|
+
// Register renderers for CLI commands
|
|
109
|
+
const renderers = ${renderersMap}
|
|
33
110
|
|
|
34
111
|
await executeCLIViaChannel({
|
|
35
112
|
programName: '${programName}',
|
|
36
113
|
pikkuWS,
|
|
37
114
|
args,
|
|
38
|
-
renderers,
|
|
115
|
+
renderers${defaultRendererCode},
|
|
39
116
|
})
|
|
40
117
|
}
|
|
41
118
|
|
|
@@ -45,7 +122,7 @@ export default ${capitalizedName}CLIClient
|
|
|
45
122
|
// For direct execution (if this file is run directly)
|
|
46
123
|
if (import.meta.url === \`file://\${process.argv[1]}\`) {
|
|
47
124
|
const url = process.env.PIKKU_WS_URL || 'ws://localhost:3000${finalChannelRoute}'
|
|
48
|
-
${capitalizedName}CLIClient(url).catch(error => {
|
|
125
|
+
${capitalizedName}CLIClient(url, process.argv.slice(2)).catch(error => {
|
|
49
126
|
console.error('Fatal error:', error.message)
|
|
50
127
|
process.exit(1)
|
|
51
128
|
})
|
|
@@ -44,35 +44,18 @@ export function serializeChannelCLI(programName, programMeta, channelFile, funct
|
|
|
44
44
|
return `import { ${fileInfo.exportedName} } from '${importPath}'`;
|
|
45
45
|
})
|
|
46
46
|
.join('\n');
|
|
47
|
-
// Get relative
|
|
47
|
+
// Get relative path to channel types file
|
|
48
48
|
const channelTypesPath = getFileImportRelativePath(channelFile, channelTypesFile, packageMappings);
|
|
49
|
-
const functionTypesPath = getFileImportRelativePath(channelFile, functionTypesFile, packageMappings);
|
|
50
49
|
return `/**
|
|
51
|
-
* This file was generated by the @pikku/cli
|
|
52
50
|
* WebSocket channel backend for '${programName}' CLI commands
|
|
53
51
|
*/
|
|
54
52
|
import { wireChannel } from '${channelTypesPath}'
|
|
55
|
-
import { PikkuMiddleware } from '${functionTypesPath}'
|
|
56
53
|
${imports}
|
|
57
54
|
|
|
58
|
-
// Middleware to close channel after command execution
|
|
59
|
-
const closeAfterExecution: PikkuMiddleware = async (_services, interaction, next) => {
|
|
60
|
-
try {
|
|
61
|
-
const result = await next()
|
|
62
|
-
return result
|
|
63
|
-
} finally {
|
|
64
|
-
// Close the channel after function completes
|
|
65
|
-
if (interaction.channel) {
|
|
66
|
-
await interaction.channel.close()
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
55
|
wireChannel({
|
|
72
56
|
name: '${finalChannelName}',
|
|
73
57
|
route: '${finalChannelRoute}',
|
|
74
58
|
auth: false,
|
|
75
|
-
middleware: [closeAfterExecution],
|
|
76
59
|
onMessageWiring: {
|
|
77
60
|
command: {
|
|
78
61
|
${commandEntries}
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const serializeCLITypes = (functionTypesImportPath, userSessionTypeImport, userSessionTypeName, singletonServicesTypeImport, singletonServicesTypeName) => {
|
|
5
5
|
return `/**
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
* CLI-specific type definitions for tree-shaking optimization
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { CoreCLI, wireCLI as wireCLICore, CorePikkuCLIRender, CoreCLICommandConfig } from '@pikku/core'
|
|
10
|
+
import { CoreCLI, wireCLI as wireCLICore, CorePikkuCLIRender, CoreCLICommandConfig } from '@pikku/core/cli'
|
|
11
11
|
import type { PikkuFunctionConfig, PikkuMiddleware } from '${functionTypesImportPath}'
|
|
12
12
|
${userSessionTypeImport}
|
|
13
13
|
${singletonServicesTypeImport}
|
|
@@ -28,12 +28,7 @@ type PikkuCLIRender<Data, RequiredServices extends SingletonServices = Singleton
|
|
|
28
28
|
* CLI command configuration with project-specific types.
|
|
29
29
|
* Uses CoreCLICommandConfig from @pikku/core with local middleware and render types.
|
|
30
30
|
*/
|
|
31
|
-
type CLICommandConfig<Func extends PikkuFunctionConfig<any, any
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Result type for CLI command configuration
|
|
35
|
-
*/
|
|
36
|
-
type CLICommandResult<Func extends PikkuFunctionConfig<any, any>> = CLICommandConfig<Func>
|
|
31
|
+
type CLICommandConfig<Func extends PikkuFunctionConfig<In, Out>, In = any, Out = any, Params extends string = string> = CoreCLICommandConfig<Func, PikkuMiddleware, PikkuCLIRender<any>, Params>
|
|
37
32
|
|
|
38
33
|
/**
|
|
39
34
|
* Type definition for CLI applications with commands and global options.
|
|
@@ -41,7 +36,7 @@ type CLICommandResult<Func extends PikkuFunctionConfig<any, any>> = CLICommandCo
|
|
|
41
36
|
* @template Commands - Type describing the command structure
|
|
42
37
|
* @template GlobalOptions - Type for global CLI options
|
|
43
38
|
*/
|
|
44
|
-
type CLIWiring<Commands extends Record<string, CoreCLICommandConfig<any, PikkuMiddleware, PikkuCLIRender<any
|
|
39
|
+
type CLIWiring<Commands extends Record<string, CoreCLICommandConfig<any, PikkuMiddleware, PikkuCLIRender<any>, any>>, GlobalOptions> = CoreCLI<Commands, GlobalOptions, PikkuMiddleware, PikkuCLIRender<any>>
|
|
45
40
|
|
|
46
41
|
/**
|
|
47
42
|
* Registers a CLI application with the Pikku framework.
|
|
@@ -51,7 +46,7 @@ type CLIWiring<Commands extends Record<string, CoreCLICommandConfig<any, PikkuMi
|
|
|
51
46
|
* @template GlobalOptions - Type for global CLI options
|
|
52
47
|
* @param cli - CLI definition with program name, commands, and global options
|
|
53
48
|
*/
|
|
54
|
-
export const wireCLI = <Commands extends Record<string, CoreCLICommandConfig<any, PikkuMiddleware, PikkuCLIRender<any
|
|
49
|
+
export const wireCLI = <Commands extends Record<string, CoreCLICommandConfig<any, PikkuMiddleware, PikkuCLIRender<any>, any>>, GlobalOptions>(
|
|
55
50
|
cli: CLIWiring<Commands, GlobalOptions>
|
|
56
51
|
) => {
|
|
57
52
|
wireCLICore(cli as any)
|
|
@@ -61,13 +56,17 @@ export const wireCLI = <Commands extends Record<string, CoreCLICommandConfig<any
|
|
|
61
56
|
* Creates a CLI command definition with automatic option inference from the function's input type.
|
|
62
57
|
* This allows TypeScript to automatically derive CLI options from the function signature.
|
|
63
58
|
*
|
|
64
|
-
* @template
|
|
59
|
+
* @template FuncConfig - The Pikku function config type
|
|
60
|
+
* @template Params - The parameters string literal type
|
|
65
61
|
* @param config - CLI command configuration
|
|
66
62
|
* @returns CLI command configuration with inferred types
|
|
67
63
|
*/
|
|
68
|
-
export const pikkuCLICommand = <
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
export const pikkuCLICommand = <
|
|
65
|
+
FuncConfig extends PikkuFunctionConfig<any, any>,
|
|
66
|
+
Params extends string
|
|
67
|
+
>(
|
|
68
|
+
config: CLICommandConfig<FuncConfig, any, any, Params>
|
|
69
|
+
): CoreCLICommandConfig<FuncConfig, PikkuMiddleware, PikkuCLIRender<any>, string> => {
|
|
71
70
|
return config as any
|
|
72
71
|
}
|
|
73
72
|
`;
|
|
@@ -8,11 +8,9 @@ export function serializeLocalCLIBootstrap(programName, _programMeta, bootstrapF
|
|
|
8
8
|
const pikkuConfigPath = getFileImportRelativePath(bootstrapFile, pikkuConfigFactory.file, config.packageMappings);
|
|
9
9
|
const singletonServicesPath = getFileImportRelativePath(bootstrapFile, singletonServicesFactory.file, config.packageMappings);
|
|
10
10
|
const sessionServicesPath = getFileImportRelativePath(bootstrapFile, sessionServicesFactory.file, config.packageMappings);
|
|
11
|
-
const cliBootstrapPath = getFileImportRelativePath(bootstrapFile, config.
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
import { executeCLI } from '@pikku/core'
|
|
11
|
+
const cliBootstrapPath = getFileImportRelativePath(bootstrapFile, config.bootstrapFile, config.packageMappings);
|
|
12
|
+
return `
|
|
13
|
+
import { executeCLI, CLIError } from '@pikku/core/cli'
|
|
16
14
|
import { ${pikkuConfigFactory.variable} as createConfig } from '${pikkuConfigPath}'
|
|
17
15
|
import { ${singletonServicesFactory.variable} as createSingletonServices } from '${singletonServicesPath}'
|
|
18
16
|
import { ${sessionServicesFactory.variable} as createSessionServices } from '${sessionServicesPath}'
|
|
@@ -22,14 +20,21 @@ import '${cliBootstrapPath}'
|
|
|
22
20
|
* ${capitalizedName} CLI function
|
|
23
21
|
* Handles command line arguments and executes the appropriate function
|
|
24
22
|
*/
|
|
25
|
-
export async function ${capitalizedName}CLI(args
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
export async function ${capitalizedName}CLI(args: string[]): Promise<void> {
|
|
24
|
+
try {
|
|
25
|
+
await executeCLI({
|
|
26
|
+
programName: '${programName}',
|
|
27
|
+
args: args || process.argv.slice(2),
|
|
28
|
+
createConfig,
|
|
29
|
+
createSingletonServices,
|
|
30
|
+
createSessionServices,
|
|
31
|
+
})
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (error instanceof CLIError) {
|
|
34
|
+
process.exit(error.exitCode)
|
|
35
|
+
}
|
|
36
|
+
throw error
|
|
37
|
+
}
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
// Export as default for easy importing
|
|
@@ -37,7 +42,7 @@ export default ${capitalizedName}CLI
|
|
|
37
42
|
|
|
38
43
|
// For direct execution (if this file is run directly)
|
|
39
44
|
if (import.meta.url === \`file://\${process.argv[1]}\`) {
|
|
40
|
-
${capitalizedName}CLI().catch(error => {
|
|
45
|
+
${capitalizedName}CLI(process.argv.slice(2)).catch(error => {
|
|
41
46
|
console.error('Fatal error:', error.message)
|
|
42
47
|
process.exit(1)
|
|
43
48
|
})
|
|
@@ -6,8 +6,13 @@ import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-
|
|
|
6
6
|
export const pikkuFetch = pikkuSessionlessFunc({
|
|
7
7
|
func: async ({ logger, config }) => {
|
|
8
8
|
const { fetchFile, httpMapDeclarationFile, packageMappings } = config;
|
|
9
|
+
// If fetchFile is not set, clean up any existing file and return
|
|
9
10
|
if (!fetchFile) {
|
|
10
|
-
|
|
11
|
+
logger.info({
|
|
12
|
+
message: "Skipping generating fetch wrapper since fetchFile isn't set in the pikku config.",
|
|
13
|
+
type: 'skip',
|
|
14
|
+
});
|
|
15
|
+
return;
|
|
11
16
|
}
|
|
12
17
|
const routesMapDeclarationPath = getFileImportRelativePath(fetchFile, httpMapDeclarationFile, packageMappings);
|
|
13
18
|
const content = [serializeFetchWrapper(routesMapDeclarationPath)];
|
|
@@ -17,8 +22,6 @@ export const pikkuFetch = pikkuSessionlessFunc({
|
|
|
17
22
|
logCommandInfoAndTime({
|
|
18
23
|
commandStart: 'Generating fetch wrapper',
|
|
19
24
|
commandEnd: 'Generated fetch wrapper',
|
|
20
|
-
skipCondition: ({ config }) => config.fetchFile === undefined,
|
|
21
|
-
skipMessage: "fetchFile isn't set in the pikku config",
|
|
22
25
|
}),
|
|
23
26
|
],
|
|
24
27
|
});
|
|
@@ -7,26 +7,27 @@ import { serializeFunctionTypes } from './serialize-function-types.js';
|
|
|
7
7
|
export const pikkuFunctionTypesSplit = pikkuSessionlessFunc({
|
|
8
8
|
func: async ({ logger, config, getInspectorState }) => {
|
|
9
9
|
const visitState = await getInspectorState();
|
|
10
|
-
const { functionTypesFile, packageMappings, rpcInternalMapDeclarationFile, } = config;
|
|
10
|
+
const { functionTypesFile, packageMappings, rpcInternalMapDeclarationFile, servicesFile, } = config;
|
|
11
11
|
// Check for required types
|
|
12
12
|
checkRequiredTypes(visitState.filesAndMethodsErrors, {
|
|
13
13
|
userSessionType: true,
|
|
14
14
|
sessionServiceType: true,
|
|
15
15
|
singletonServicesType: true,
|
|
16
16
|
});
|
|
17
|
-
const { userSessionType, sessionServicesType, singletonServicesType } = visitState.filesAndMethods;
|
|
17
|
+
const { userSessionType, sessionServicesType, singletonServicesType, pikkuConfigType, } = visitState.filesAndMethods;
|
|
18
18
|
if (!userSessionType || !sessionServicesType || !singletonServicesType) {
|
|
19
19
|
throw new Error('Required types not found');
|
|
20
20
|
}
|
|
21
|
-
const
|
|
21
|
+
const configTypeImport = pikkuConfigType
|
|
22
|
+
? `import type { ${pikkuConfigType.type} } from '${getFileImportRelativePath(functionTypesFile, pikkuConfigType.typePath, packageMappings)}'`
|
|
23
|
+
: '// Config type not found, will use fallback';
|
|
24
|
+
const content = serializeFunctionTypes(`import type { ${userSessionType.type} } from '${getFileImportRelativePath(functionTypesFile, userSessionType.typePath, packageMappings)}'`, userSessionType.type, `import type { ${singletonServicesType.type} } from '${getFileImportRelativePath(functionTypesFile, singletonServicesType.typePath, packageMappings)}'`, singletonServicesType.type, `import type { ${sessionServicesType.type} } from '${getFileImportRelativePath(functionTypesFile, sessionServicesType.typePath, packageMappings)}'`, sessionServicesType.type, `import type { TypedPikkuRPC } from '${getFileImportRelativePath(functionTypesFile, rpcInternalMapDeclarationFile, packageMappings)}'`, `import type { RequiredSingletonServices, RequiredSessionServices } from '${getFileImportRelativePath(functionTypesFile, servicesFile, packageMappings)}'`, configTypeImport);
|
|
22
25
|
await writeFileInDir(logger, functionTypesFile, content);
|
|
23
26
|
},
|
|
24
27
|
middleware: [
|
|
25
28
|
logCommandInfoAndTime({
|
|
26
29
|
commandStart: 'Creating function types',
|
|
27
30
|
commandEnd: 'Created function types',
|
|
28
|
-
skipCondition: false,
|
|
29
|
-
skipMessage: '',
|
|
30
31
|
}),
|
|
31
32
|
],
|
|
32
33
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const serializeServicesMap: (
|
|
1
|
+
export declare const serializeServicesMap: (requiredServices: Set<string>, forceRequiredServices: string[] | undefined, servicesImport: string, sessionServicesImport: string) => string;
|
|
2
2
|
export declare const pikkuServices: any;
|