@pikku/cli 0.8.3 → 0.9.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/CHANGELOG.md +16 -0
- package/bin/pikku-all.ts +47 -33
- package/bin/pikku-fetch.ts +1 -1
- package/bin/pikku-openapi.ts +2 -2
- package/bin/pikku-queue-service.ts +2 -2
- package/bin/pikku-websocket.ts +1 -1
- package/cli.schema.json +30 -30
- package/dist/bin/pikku-all.js +38 -33
- package/dist/bin/pikku-fetch.js +1 -1
- package/dist/bin/pikku-openapi.js +2 -2
- package/dist/bin/pikku-queue-service.js +2 -2
- package/dist/bin/pikku-websocket.js +1 -1
- package/dist/src/inspector-glob.js +2 -2
- package/dist/src/pikku-cli-config.d.ts +17 -17
- package/dist/src/pikku-cli-config.js +31 -31
- package/dist/src/runtimes/nextjs/pikku-command-nextjs.js +3 -3
- package/dist/src/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +29 -29
- package/dist/src/runtimes/nextjs/serialize-nextjs-http-wrapper.js +28 -28
- package/dist/src/schema-generator.d.ts +2 -2
- package/dist/src/schema-generator.js +2 -2
- package/dist/src/serialize-pikku-types.js +67 -67
- package/dist/src/utils.d.ts +5 -1
- package/dist/src/utils.js +17 -6
- package/dist/src/wirings/channels/pikku-channels.js +9 -0
- package/dist/src/wirings/channels/pikku-command-channels.js +9 -0
- package/dist/src/{events → wirings}/channels/serialize-typed-channel-map.js +3 -3
- package/dist/src/{events → wirings}/channels/serialize-websocket-wrapper.js +19 -5
- package/dist/src/{events → wirings}/fetch/index.js +2 -2
- package/dist/src/{events → wirings}/http/openapi-spec-generator.d.ts +2 -2
- package/dist/src/wirings/http/pikku-command-http-map.js +8 -0
- package/dist/src/{events → wirings}/http/pikku-command-http-routes.js +3 -3
- package/dist/src/{events → wirings}/http/pikku-http-routes.js +3 -3
- package/dist/src/wirings/http/serialize-fetch-wrapper.js +67 -0
- package/dist/src/wirings/http/serialize-typed-http-map.d.ts +4 -0
- package/dist/src/{events → wirings}/http/serialize-typed-http-map.js +13 -13
- package/dist/src/{events → wirings}/mcp/pikku-command-mcp.js +3 -3
- package/dist/src/wirings/queue/pikku-command-queue-service.js +15 -0
- package/dist/src/{events → wirings}/queue/pikku-command-queue.js +3 -3
- package/dist/src/{events → wirings}/queue/pikku-queue.js +3 -3
- package/dist/src/wirings/rpc/pikku-command-rpc-client.js +15 -0
- package/dist/src/wirings/rpc/pikku-command-rpc.js +6 -0
- package/dist/src/wirings/rpc/pikku-rpc.js +6 -0
- package/dist/src/wirings/rpc/serialize-rpc-wrapper.js +68 -0
- package/dist/src/{events → wirings}/scheduler/pikku-command-scheduler.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/inspector-glob.ts +2 -2
- package/src/pikku-cli-config.ts +67 -52
- package/src/runtimes/nextjs/pikku-command-nextjs.ts +3 -3
- package/src/runtimes/nextjs/serialize-nextjs-backend-wrapper.ts +29 -29
- package/src/runtimes/nextjs/serialize-nextjs-http-wrapper.ts +28 -28
- package/src/schema-generator.ts +3 -3
- package/src/serialize-pikku-types.ts +67 -67
- package/src/utils.ts +26 -6
- package/src/{events → wirings}/channels/pikku-channels.ts +5 -4
- package/src/{events → wirings}/channels/pikku-command-channels.ts +5 -4
- package/src/{events → wirings}/channels/serialize-typed-channel-map.ts +3 -3
- package/src/{events → wirings}/channels/serialize-websocket-wrapper.ts +19 -5
- package/src/{events → wirings}/fetch/index.ts +2 -2
- package/src/{events → wirings}/http/openapi-spec-generator.ts +3 -3
- package/src/{events → wirings}/http/pikku-command-http-map.ts +5 -5
- package/src/{events → wirings}/http/pikku-command-http-routes.ts +5 -5
- package/src/{events → wirings}/http/pikku-http-routes.ts +5 -5
- package/src/wirings/http/serialize-fetch-wrapper.ts +67 -0
- package/src/{events → wirings}/http/serialize-typed-http-map.ts +17 -17
- package/src/{events → wirings}/mcp/pikku-command-mcp.ts +5 -5
- package/src/{events → wirings}/queue/pikku-command-queue-service.ts +9 -6
- package/src/{events → wirings}/queue/pikku-command-queue.ts +8 -5
- package/src/{events → wirings}/queue/pikku-queue.ts +8 -5
- package/src/{events → wirings}/rpc/pikku-command-rpc-client.ts +9 -6
- package/src/{events → wirings}/rpc/pikku-command-rpc.ts +2 -2
- package/src/{events → wirings}/rpc/pikku-rpc.ts +2 -2
- package/src/wirings/rpc/serialize-rpc-wrapper.ts +68 -0
- package/src/{events → wirings}/scheduler/pikku-command-scheduler.ts +8 -4
- package/dist/src/events/channels/pikku-channels.js +0 -9
- package/dist/src/events/channels/pikku-command-channels.js +0 -9
- package/dist/src/events/http/pikku-command-http-map.js +0 -8
- package/dist/src/events/http/serialize-fetch-wrapper.js +0 -67
- package/dist/src/events/http/serialize-typed-http-map.d.ts +0 -4
- package/dist/src/events/queue/pikku-command-queue-service.js +0 -12
- package/dist/src/events/rpc/pikku-command-rpc-client.js +0 -12
- package/dist/src/events/rpc/pikku-command-rpc.js +0 -6
- package/dist/src/events/rpc/pikku-rpc.js +0 -6
- package/dist/src/events/rpc/serialize-rpc-wrapper.js +0 -29
- package/src/events/http/serialize-fetch-wrapper.ts +0 -67
- package/src/events/rpc/serialize-rpc-wrapper.ts +0 -29
- /package/dist/src/{events → wirings}/channels/pikku-channels.d.ts +0 -0
- /package/dist/src/{events → wirings}/channels/pikku-command-channels-map.d.ts +0 -0
- /package/dist/src/{events → wirings}/channels/pikku-command-channels-map.js +0 -0
- /package/dist/src/{events → wirings}/channels/pikku-command-channels.d.ts +0 -0
- /package/dist/src/{events → wirings}/channels/pikku-command-websocket-typed.d.ts +0 -0
- /package/dist/src/{events → wirings}/channels/pikku-command-websocket-typed.js +0 -0
- /package/dist/src/{events → wirings}/channels/serialize-typed-channel-map.d.ts +0 -0
- /package/dist/src/{events → wirings}/channels/serialize-websocket-wrapper.d.ts +0 -0
- /package/dist/src/{events → wirings}/fetch/index.d.ts +0 -0
- /package/dist/src/{events → wirings}/functions/pikku-command-function-types.d.ts +0 -0
- /package/dist/src/{events → wirings}/functions/pikku-command-function-types.js +0 -0
- /package/dist/src/{events → wirings}/functions/pikku-command-functions.d.ts +0 -0
- /package/dist/src/{events → wirings}/functions/pikku-command-functions.js +0 -0
- /package/dist/src/{events → wirings}/functions/pikku-command-services.d.ts +0 -0
- /package/dist/src/{events → wirings}/functions/pikku-command-services.js +0 -0
- /package/dist/src/{events → wirings}/functions/pikku-function-types.d.ts +0 -0
- /package/dist/src/{events → wirings}/functions/pikku-function-types.js +0 -0
- /package/dist/src/{events → wirings}/functions/pikku-functions.d.ts +0 -0
- /package/dist/src/{events → wirings}/functions/pikku-functions.js +0 -0
- /package/dist/src/{events → wirings}/http/openapi-spec-generator.js +0 -0
- /package/dist/src/{events → wirings}/http/pikku-command-http-map.d.ts +0 -0
- /package/dist/src/{events → wirings}/http/pikku-command-http-routes.d.ts +0 -0
- /package/dist/src/{events → wirings}/http/pikku-command-openapi.d.ts +0 -0
- /package/dist/src/{events → wirings}/http/pikku-command-openapi.js +0 -0
- /package/dist/src/{events → wirings}/http/pikku-http-routes.d.ts +0 -0
- /package/dist/src/{events → wirings}/http/serialize-fetch-wrapper.d.ts +0 -0
- /package/dist/src/{events → wirings}/mcp/pikku-command-mcp-json.d.ts +0 -0
- /package/dist/src/{events → wirings}/mcp/pikku-command-mcp-json.js +0 -0
- /package/dist/src/{events → wirings}/mcp/pikku-command-mcp.d.ts +0 -0
- /package/dist/src/{events → wirings}/mcp/serialize-mcp-json.d.ts +0 -0
- /package/dist/src/{events → wirings}/mcp/serialize-mcp-json.js +0 -0
- /package/dist/src/{events → wirings}/queue/pikku-command-queue-map.d.ts +0 -0
- /package/dist/src/{events → wirings}/queue/pikku-command-queue-map.js +0 -0
- /package/dist/src/{events → wirings}/queue/pikku-command-queue-service.d.ts +0 -0
- /package/dist/src/{events → wirings}/queue/pikku-command-queue.d.ts +0 -0
- /package/dist/src/{events → wirings}/queue/pikku-queue-map.d.ts +0 -0
- /package/dist/src/{events → wirings}/queue/pikku-queue-map.js +0 -0
- /package/dist/src/{events → wirings}/queue/pikku-queue.d.ts +0 -0
- /package/dist/src/{events → wirings}/queue/serialize-queue-map.d.ts +0 -0
- /package/dist/src/{events → wirings}/queue/serialize-queue-map.js +0 -0
- /package/dist/src/{events → wirings}/queue/serialize-queue-meta.d.ts +0 -0
- /package/dist/src/{events → wirings}/queue/serialize-queue-meta.js +0 -0
- /package/dist/src/{events → wirings}/queue/serialize-queue-wrapper.d.ts +0 -0
- /package/dist/src/{events → wirings}/queue/serialize-queue-wrapper.js +0 -0
- /package/dist/src/{events → wirings}/rpc/pikku-command-rpc-client.d.ts +0 -0
- /package/dist/src/{events → wirings}/rpc/pikku-command-rpc-map.d.ts +0 -0
- /package/dist/src/{events → wirings}/rpc/pikku-command-rpc-map.js +0 -0
- /package/dist/src/{events → wirings}/rpc/pikku-command-rpc.d.ts +0 -0
- /package/dist/src/{events → wirings}/rpc/pikku-rpc.d.ts +0 -0
- /package/dist/src/{events → wirings}/rpc/serialize-rpc-wrapper.d.ts +0 -0
- /package/dist/src/{events → wirings}/rpc/serialize-typed-rpc-map.d.ts +0 -0
- /package/dist/src/{events → wirings}/rpc/serialize-typed-rpc-map.js +0 -0
- /package/dist/src/{events → wirings}/scheduler/pikku-command-scheduler.d.ts +0 -0
- /package/dist/src/{events → wirings}/scheduler/serialize-scheduler-meta.d.ts +0 -0
- /package/dist/src/{events → wirings}/scheduler/serialize-scheduler-meta.js +0 -0
- /package/src/{events → wirings}/channels/pikku-command-channels-map.ts +0 -0
- /package/src/{events → wirings}/channels/pikku-command-websocket-typed.ts +0 -0
- /package/src/{events → wirings}/functions/pikku-command-function-types.ts +0 -0
- /package/src/{events → wirings}/functions/pikku-command-functions.ts +0 -0
- /package/src/{events → wirings}/functions/pikku-command-services.ts +0 -0
- /package/src/{events → wirings}/functions/pikku-function-types.ts +0 -0
- /package/src/{events → wirings}/functions/pikku-functions.ts +0 -0
- /package/src/{events → wirings}/http/pikku-command-openapi.ts +0 -0
- /package/src/{events → wirings}/mcp/pikku-command-mcp-json.ts +0 -0
- /package/src/{events → wirings}/mcp/serialize-mcp-json.ts +0 -0
- /package/src/{events → wirings}/queue/pikku-command-queue-map.ts +0 -0
- /package/src/{events → wirings}/queue/pikku-queue-map.ts +0 -0
- /package/src/{events → wirings}/queue/serialize-queue-map.ts +0 -0
- /package/src/{events → wirings}/queue/serialize-queue-meta.ts +0 -0
- /package/src/{events → wirings}/queue/serialize-queue-wrapper.ts +0 -0
- /package/src/{events → wirings}/rpc/pikku-command-rpc-map.ts +0 -0
- /package/src/{events → wirings}/rpc/serialize-typed-rpc-map.ts +0 -0
- /package/src/{events → wirings}/scheduler/serialize-scheduler-meta.ts +0 -0
package/src/utils.ts
CHANGED
|
@@ -17,20 +17,35 @@ const logo = `
|
|
|
17
17
|
`
|
|
18
18
|
|
|
19
19
|
export class CLILogger {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
private silent: boolean
|
|
21
|
+
|
|
22
|
+
constructor({
|
|
23
|
+
logLogo,
|
|
24
|
+
silent = false,
|
|
25
|
+
}: {
|
|
26
|
+
logLogo: boolean
|
|
27
|
+
silent?: boolean
|
|
28
|
+
}) {
|
|
29
|
+
this.silent = silent
|
|
30
|
+
if (logLogo && !silent) {
|
|
22
31
|
this.logPikkuLogo()
|
|
23
32
|
}
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
primary(message: string) {
|
|
27
|
-
|
|
36
|
+
if (!this.silent) {
|
|
37
|
+
console.log(chalk.green(message))
|
|
38
|
+
}
|
|
28
39
|
}
|
|
29
40
|
success(message: string) {
|
|
30
|
-
|
|
41
|
+
if (!this.silent) {
|
|
42
|
+
console.log(chalk.green(message))
|
|
43
|
+
}
|
|
31
44
|
}
|
|
32
45
|
info(message: string) {
|
|
33
|
-
|
|
46
|
+
if (!this.silent) {
|
|
47
|
+
console.log(chalk.blue(message))
|
|
48
|
+
}
|
|
34
49
|
}
|
|
35
50
|
error(message: string) {
|
|
36
51
|
console.error(chalk.red(message))
|
|
@@ -39,11 +54,15 @@ export class CLILogger {
|
|
|
39
54
|
console.error(chalk.yellow(message))
|
|
40
55
|
}
|
|
41
56
|
debug(message: string) {
|
|
42
|
-
if (process.env.DEBUG) {
|
|
57
|
+
if (process.env.DEBUG && !this.silent) {
|
|
43
58
|
console.log(chalk.gray(message))
|
|
44
59
|
}
|
|
45
60
|
}
|
|
46
61
|
|
|
62
|
+
timing(message: string) {
|
|
63
|
+
console.log(chalk.gray(message))
|
|
64
|
+
}
|
|
65
|
+
|
|
47
66
|
private logPikkuLogo() {
|
|
48
67
|
this.primary(logo)
|
|
49
68
|
const packageJson = JSON.parse(
|
|
@@ -129,6 +148,7 @@ export interface PikkuCLIOptions {
|
|
|
129
148
|
tags?: string[]
|
|
130
149
|
types?: string[]
|
|
131
150
|
directories?: string[]
|
|
151
|
+
silent?: boolean
|
|
132
152
|
}
|
|
133
153
|
|
|
134
154
|
const getMetaTypes = (
|
|
@@ -18,21 +18,22 @@ export const pikkuChannels: PikkuCommand = async (
|
|
|
18
18
|
'Found channels',
|
|
19
19
|
[visitState.channels.files.size === 0],
|
|
20
20
|
async () => {
|
|
21
|
-
const {
|
|
21
|
+
const { channelsWiringFile, channelsWiringMetaFile, packageMappings } =
|
|
22
|
+
cliConfig
|
|
22
23
|
const { channels } = visitState
|
|
23
24
|
await writeFileInDir(
|
|
24
25
|
logger,
|
|
25
|
-
|
|
26
|
+
channelsWiringFile,
|
|
26
27
|
serializeFileImports(
|
|
27
28
|
'addChannel',
|
|
28
|
-
|
|
29
|
+
channelsWiringFile,
|
|
29
30
|
channels.files,
|
|
30
31
|
packageMappings
|
|
31
32
|
)
|
|
32
33
|
)
|
|
33
34
|
await writeFileInDir(
|
|
34
35
|
logger,
|
|
35
|
-
|
|
36
|
+
channelsWiringMetaFile,
|
|
36
37
|
`import { pikkuState } from '@pikku/core'\npikkuState('channel', 'meta', ${JSON.stringify(channels.meta, null, 2)})`
|
|
37
38
|
)
|
|
38
39
|
}
|
|
@@ -16,21 +16,22 @@ export const pikkuChannels: PikkuCommand = async (
|
|
|
16
16
|
'Found channels',
|
|
17
17
|
[visitState.channels.files.size === 0],
|
|
18
18
|
async () => {
|
|
19
|
-
const {
|
|
19
|
+
const { channelsWiringFile, channelsWiringMetaFile, packageMappings } =
|
|
20
|
+
cliConfig
|
|
20
21
|
const { channels } = visitState
|
|
21
22
|
await writeFileInDir(
|
|
22
23
|
logger,
|
|
23
|
-
|
|
24
|
+
channelsWiringFile,
|
|
24
25
|
serializeFileImports(
|
|
25
26
|
'addChannel',
|
|
26
|
-
|
|
27
|
+
channelsWiringFile,
|
|
27
28
|
channels.files,
|
|
28
29
|
packageMappings
|
|
29
30
|
)
|
|
30
31
|
)
|
|
31
32
|
await writeFileInDir(
|
|
32
33
|
logger,
|
|
33
|
-
|
|
34
|
+
channelsWiringMetaFile,
|
|
34
35
|
`import { pikkuState } from '@pikku/core'\npikkuState('channel', 'meta', ${JSON.stringify(channels.meta, null, 2)})`
|
|
35
36
|
)
|
|
36
37
|
}
|
|
@@ -46,7 +46,7 @@ export type ChannelDefaultHandlerOf<Channel extends keyof ChannelsMap> =
|
|
|
46
46
|
? ChannelHandler<I, O>
|
|
47
47
|
: never;
|
|
48
48
|
|
|
49
|
-
export type
|
|
49
|
+
export type ChannelWiringHandlerOf<
|
|
50
50
|
Channel extends keyof ChannelsMap,
|
|
51
51
|
Route extends keyof ChannelsMap[Channel]['routes'],
|
|
52
52
|
Method extends keyof ChannelsMap[Channel]['routes'][Route],
|
|
@@ -80,7 +80,7 @@ function generateChannels(
|
|
|
80
80
|
> = {}
|
|
81
81
|
|
|
82
82
|
for (const meta of Object.values(channelsMeta)) {
|
|
83
|
-
const { name,
|
|
83
|
+
const { name, messageWirings, message } = meta
|
|
84
84
|
|
|
85
85
|
if (!channelsObject[name]) {
|
|
86
86
|
channelsObject[name] = { message: null, routes: {} }
|
|
@@ -103,7 +103,7 @@ function generateChannels(
|
|
|
103
103
|
outputTypes?.forEach((type) => requiredTypes.add(type))
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
for (const [key, route] of Object.entries(
|
|
106
|
+
for (const [key, route] of Object.entries(messageWirings)) {
|
|
107
107
|
if (!channelsObject[name].routes[key]) {
|
|
108
108
|
channelsObject[name].routes[key] = {}
|
|
109
109
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export const serializeWebsocketWrapper = (channelsMapPath: string) => {
|
|
2
2
|
return `import { CorePikkuWebsocket, CorePikkuRouteHandler } from '@pikku/websocket'
|
|
3
|
-
import { ChannelDefaultHandlerOf,
|
|
3
|
+
import { ChannelDefaultHandlerOf, ChannelWiringHandlerOf, ChannelsMap } from '${channelsMapPath}';
|
|
4
4
|
|
|
5
5
|
class PikkuWebSocketRoute<Channel extends keyof ChannelsMap, Route extends keyof ChannelsMap[Channel]['routes']> extends CorePikkuRouteHandler {
|
|
6
6
|
public subscribe<
|
|
7
7
|
Method extends keyof ChannelsMap[Channel]['routes'][Route],
|
|
8
|
-
Data extends
|
|
8
|
+
Data extends ChannelWiringHandlerOf<Channel, Route, Method>['output']
|
|
9
9
|
>(method: Method, callback: (data: Data) => void
|
|
10
10
|
) {
|
|
11
11
|
super.subscribe(method.toString(), callback)
|
|
@@ -13,20 +13,20 @@ class PikkuWebSocketRoute<Channel extends keyof ChannelsMap, Route extends keyof
|
|
|
13
13
|
|
|
14
14
|
public unsubscribe<
|
|
15
15
|
Method extends keyof ChannelsMap[Channel]['routes'][Route],
|
|
16
|
-
Data extends
|
|
16
|
+
Data extends ChannelWiringHandlerOf<Channel, Route, Method>['output']
|
|
17
17
|
>(method: Method, callback?: (data: Data) => void) {
|
|
18
18
|
super.unsubscribe(method.toString(), callback)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
public send<
|
|
22
22
|
Method extends keyof ChannelsMap[Channel]['routes'][Route],
|
|
23
|
-
Data extends
|
|
23
|
+
Data extends ChannelWiringHandlerOf<Channel, Route, Method>['input']
|
|
24
24
|
>(method: Method, data: Data) {
|
|
25
25
|
super.send(method.toString(), data)
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export class PikkuWebSocket<Channel extends keyof ChannelsMap> extends CorePikkuWebsocket {
|
|
29
|
+
export class PikkuWebSocket<Channel extends keyof ChannelsMap, EventHubTopics extends Record<string, any> = {}> extends CorePikkuWebsocket {
|
|
30
30
|
/**
|
|
31
31
|
* Send a message to a specific route and method.
|
|
32
32
|
* Validates the input data type.
|
|
@@ -56,6 +56,20 @@ export class PikkuWebSocket<Channel extends keyof ChannelsMap> extends CorePikku
|
|
|
56
56
|
public send(data: ChannelDefaultHandlerOf<Channel>['input']) {
|
|
57
57
|
super.send(data)
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to a topic from the EventHub system with strong typing.
|
|
62
|
+
*/
|
|
63
|
+
public subscribeToEventHub<Topic extends keyof EventHubTopics>(
|
|
64
|
+
topic: Topic,
|
|
65
|
+
callback: (data: EventHubTopics[Topic]) => void
|
|
66
|
+
) {
|
|
67
|
+
super.subscribe((data) => {
|
|
68
|
+
if (data.topic === topic) {
|
|
69
|
+
callback(data as EventHubTopics[Topic])
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
}
|
|
59
73
|
}
|
|
60
74
|
`
|
|
61
75
|
}
|
|
@@ -8,7 +8,7 @@ import { PikkuCommandWithoutState } from '../../types.js'
|
|
|
8
8
|
|
|
9
9
|
export const pikkuFetch: PikkuCommandWithoutState = async (
|
|
10
10
|
logger,
|
|
11
|
-
{ fetchFile,
|
|
11
|
+
{ fetchFile, httpMapDeclarationFile, packageMappings }
|
|
12
12
|
) => {
|
|
13
13
|
return await logCommandInfoAndTime(
|
|
14
14
|
logger,
|
|
@@ -22,7 +22,7 @@ export const pikkuFetch: PikkuCommandWithoutState = async (
|
|
|
22
22
|
|
|
23
23
|
const routesMapDeclarationPath = getFileImportRelativePath(
|
|
24
24
|
fetchFile,
|
|
25
|
-
|
|
25
|
+
httpMapDeclarationFile,
|
|
26
26
|
packageMappings
|
|
27
27
|
)
|
|
28
28
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FunctionsMeta,
|
|
1
|
+
import { FunctionsMeta, HTTPWiringsMeta, pikkuState } from '@pikku/core'
|
|
2
2
|
import _convertSchema from '@openapi-contrib/json-schema-to-openapi-schema'
|
|
3
3
|
const convertSchema =
|
|
4
4
|
'default' in _convertSchema ? (_convertSchema.default as any) : _convertSchema
|
|
@@ -76,7 +76,7 @@ const getErrorResponseForConstructorName = (constructorName: string) => {
|
|
|
76
76
|
|
|
77
77
|
const convertSchemasToBodyPayloads = async (
|
|
78
78
|
functionsMeta: FunctionsMeta,
|
|
79
|
-
routesMeta:
|
|
79
|
+
routesMeta: HTTPWiringsMeta,
|
|
80
80
|
schemas: Record<string, any>
|
|
81
81
|
) => {
|
|
82
82
|
const requiredSchemas = new Set(
|
|
@@ -105,7 +105,7 @@ const convertSchemasToBodyPayloads = async (
|
|
|
105
105
|
|
|
106
106
|
export async function generateOpenAPISpec(
|
|
107
107
|
functionsMeta: FunctionsMeta,
|
|
108
|
-
routeMeta:
|
|
108
|
+
routeMeta: HTTPWiringsMeta,
|
|
109
109
|
schemas: Record<string, any>,
|
|
110
110
|
additionalInfo: OpenAPISpecInfo
|
|
111
111
|
): Promise<OpenAPISpec> {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js'
|
|
2
|
-
import {
|
|
2
|
+
import { serializeTypedHTTPWiringsMap } from './serialize-typed-http-map.js'
|
|
3
3
|
import { PikkuCommand } from '../../types.js'
|
|
4
4
|
|
|
5
5
|
export const pikkuHTTPMap: PikkuCommand = async (
|
|
6
6
|
logger,
|
|
7
|
-
{
|
|
7
|
+
{ httpMapDeclarationFile, packageMappings },
|
|
8
8
|
{ http, functions }
|
|
9
9
|
) => {
|
|
10
10
|
return await logCommandInfoAndTime(
|
|
@@ -13,15 +13,15 @@ export const pikkuHTTPMap: PikkuCommand = async (
|
|
|
13
13
|
'Created HTTP map',
|
|
14
14
|
[http.files.size === 0],
|
|
15
15
|
async () => {
|
|
16
|
-
const content =
|
|
17
|
-
|
|
16
|
+
const content = serializeTypedHTTPWiringsMap(
|
|
17
|
+
httpMapDeclarationFile,
|
|
18
18
|
packageMappings,
|
|
19
19
|
functions.typesMap,
|
|
20
20
|
functions.meta,
|
|
21
21
|
http.meta,
|
|
22
22
|
http.metaInputTypes
|
|
23
23
|
)
|
|
24
|
-
await writeFileInDir(logger,
|
|
24
|
+
await writeFileInDir(logger, httpMapDeclarationFile, content)
|
|
25
25
|
}
|
|
26
26
|
)
|
|
27
27
|
}
|
|
@@ -18,21 +18,21 @@ export const pikkuHTTP: PikkuCommand = async (
|
|
|
18
18
|
'Found HTTP routes',
|
|
19
19
|
[visitState.http.files.size === 0],
|
|
20
20
|
async () => {
|
|
21
|
-
const {
|
|
21
|
+
const { httpWiringsFile, httpWiringMetaFile, packageMappings } = cliConfig
|
|
22
22
|
const { http } = visitState
|
|
23
23
|
await writeFileInDir(
|
|
24
24
|
logger,
|
|
25
|
-
|
|
25
|
+
httpWiringsFile,
|
|
26
26
|
serializeFileImports(
|
|
27
|
-
'
|
|
28
|
-
|
|
27
|
+
'wireHTTP',
|
|
28
|
+
httpWiringsFile,
|
|
29
29
|
http.files,
|
|
30
30
|
packageMappings
|
|
31
31
|
)
|
|
32
32
|
)
|
|
33
33
|
await writeFileInDir(
|
|
34
34
|
logger,
|
|
35
|
-
|
|
35
|
+
httpWiringMetaFile,
|
|
36
36
|
`import { pikkuState } from '@pikku/core'\npikkuState('http', 'meta', ${JSON.stringify(http.meta, null, 2)})`
|
|
37
37
|
)
|
|
38
38
|
}
|
|
@@ -18,21 +18,21 @@ export const pikkuHTTP: PikkuCommand = async (
|
|
|
18
18
|
'Found HTTP routes',
|
|
19
19
|
[visitState.http.files.size === 0],
|
|
20
20
|
async () => {
|
|
21
|
-
const {
|
|
21
|
+
const { httpWiringsFile, httpWiringMetaFile, packageMappings } = cliConfig
|
|
22
22
|
const { http } = visitState
|
|
23
23
|
await writeFileInDir(
|
|
24
24
|
logger,
|
|
25
|
-
|
|
25
|
+
httpWiringsFile,
|
|
26
26
|
serializeFileImports(
|
|
27
|
-
'
|
|
28
|
-
|
|
27
|
+
'wireHTTP',
|
|
28
|
+
httpWiringsFile,
|
|
29
29
|
http.files,
|
|
30
30
|
packageMappings
|
|
31
31
|
)
|
|
32
32
|
)
|
|
33
33
|
await writeFileInDir(
|
|
34
34
|
logger,
|
|
35
|
-
|
|
35
|
+
httpWiringMetaFile,
|
|
36
36
|
`import { pikkuState } from '@pikku/core'\npikkuState('http', 'meta', ${JSON.stringify(http.meta, null, 2)})`
|
|
37
37
|
)
|
|
38
38
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export const serializeFetchWrapper = (routesMapPath: string) => {
|
|
2
|
+
return `
|
|
3
|
+
import { CorePikkuFetch, HTTPMethod } from '@pikku/fetch'
|
|
4
|
+
import type { HTTPWiringsMap, HTTPWiringHandlerOf, HTTPWiringsWithMethod } from '${routesMapPath}'
|
|
5
|
+
|
|
6
|
+
export class PikkuFetch extends CorePikkuFetch {
|
|
7
|
+
public async post<Route extends HTTPWiringsWithMethod<'POST'>>(
|
|
8
|
+
route: Route,
|
|
9
|
+
...args: null extends HTTPWiringHandlerOf<Route, 'POST'>['input']
|
|
10
|
+
? [data?: Exclude<HTTPWiringHandlerOf<Route, 'POST'>['input'], null>, options?: Omit<RequestInit, 'body'>]
|
|
11
|
+
: [data: HTTPWiringHandlerOf<Route, 'POST'>['input'], options?: Omit<RequestInit, 'body'>]
|
|
12
|
+
): Promise<HTTPWiringHandlerOf<Route, 'POST'>['output']> {
|
|
13
|
+
const [data, options] = args;
|
|
14
|
+
return super.api(route, 'POST', data, options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public async get<Route extends HTTPWiringsWithMethod<'GET'>>(
|
|
18
|
+
route: Route,
|
|
19
|
+
...args: null extends HTTPWiringHandlerOf<Route, 'GET'>['input']
|
|
20
|
+
? [data?: Exclude<HTTPWiringHandlerOf<Route, 'GET'>['input'], null>, options?: Omit<RequestInit, 'body'>]
|
|
21
|
+
: [data: HTTPWiringHandlerOf<Route, 'GET'>['input'], options?: Omit<RequestInit, 'body'>]
|
|
22
|
+
): Promise<HTTPWiringHandlerOf<Route, 'GET'>['output']> {
|
|
23
|
+
const [data, options] = args;
|
|
24
|
+
return super.api(route, 'GET', data, options);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async patch<Route extends HTTPWiringsWithMethod<'PATCH'>>(
|
|
28
|
+
route: Route,
|
|
29
|
+
...args: null extends HTTPWiringHandlerOf<Route, 'PATCH'>['input']
|
|
30
|
+
? [data?: Exclude<HTTPWiringHandlerOf<Route, 'PATCH'>['input'], null>, options?: Omit<RequestInit, 'body'>]
|
|
31
|
+
: [data: HTTPWiringHandlerOf<Route, 'PATCH'>['input'], options?: Omit<RequestInit, 'body'>]
|
|
32
|
+
): Promise<HTTPWiringHandlerOf<Route, 'PATCH'>['output']> {
|
|
33
|
+
const [data, options] = args;
|
|
34
|
+
return super.api(route, 'PATCH', data, options);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public async head<Route extends HTTPWiringsWithMethod<'HEAD'>>(
|
|
38
|
+
route: Route,
|
|
39
|
+
...args: null extends HTTPWiringHandlerOf<Route, 'HEAD'>['input']
|
|
40
|
+
? [data?: Exclude<HTTPWiringHandlerOf<Route, 'HEAD'>['input'], null>, options?: Omit<RequestInit, 'body'>]
|
|
41
|
+
: [data: HTTPWiringHandlerOf<Route, 'HEAD'>['input'], options?: Omit<RequestInit, 'body'>]
|
|
42
|
+
): Promise<HTTPWiringHandlerOf<Route, 'HEAD'>['output']> {
|
|
43
|
+
const [data, options] = args;
|
|
44
|
+
return super.api(route, 'HEAD', data, options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public async delete<Route extends HTTPWiringsWithMethod<'DELETE'>>(
|
|
48
|
+
route: Route,
|
|
49
|
+
...args: null extends HTTPWiringHandlerOf<Route, 'DELETE'>['input']
|
|
50
|
+
? [data?: Exclude<HTTPWiringHandlerOf<Route, 'DELETE'>['input'], null>, options?: Omit<RequestInit, 'body'>]
|
|
51
|
+
: [data: HTTPWiringHandlerOf<Route, 'DELETE'>['input'], options?: Omit<RequestInit, 'body'>]
|
|
52
|
+
): Promise<HTTPWiringHandlerOf<Route, 'DELETE'>['output']> {
|
|
53
|
+
const [data, options] = args;
|
|
54
|
+
return super.api(route, 'DELETE', data, options);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public async fetch<
|
|
58
|
+
Route extends keyof HTTPWiringsMap,
|
|
59
|
+
Method extends keyof HTTPWiringsMap[Route]
|
|
60
|
+
>(route: Route, method: Method, data: HTTPWiringHandlerOf<Route, Method>['input'], options?: Omit<RequestInit, 'body'>): Promise<Response> {
|
|
61
|
+
return await super.fetch(route, method as HTTPMethod, data, options);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const pikkuFetch = new PikkuFetch();
|
|
66
|
+
`
|
|
67
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTTPWiringsMeta } from '@pikku/core/http'
|
|
2
2
|
import { serializeImportMap } from '../../serialize-import-map.js'
|
|
3
3
|
import { MetaInputTypes, TypesMap } from '@pikku/inspector'
|
|
4
4
|
import { FunctionsMeta } from '@pikku/core'
|
|
5
5
|
import { generateCustomTypes } from '../../utils.js'
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const serializeTypedHTTPWiringsMap = (
|
|
8
8
|
relativeToPath: string,
|
|
9
9
|
packageMappings: Record<string, string>,
|
|
10
10
|
typesMap: TypesMap,
|
|
11
11
|
functionsMeta: FunctionsMeta,
|
|
12
|
-
|
|
12
|
+
wiringsMeta: HTTPWiringsMeta,
|
|
13
13
|
metaTypes: MetaInputTypes
|
|
14
14
|
) => {
|
|
15
15
|
const requiredTypes = new Set<string>()
|
|
16
16
|
const serializedCustomTypes = generateCustomTypes(typesMap, requiredTypes)
|
|
17
17
|
const serializedMetaTypes = generateMetaTypes(metaTypes, typesMap)
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const serializedHTTPWirings = generateHTTPWirings(
|
|
19
|
+
wiringsMeta,
|
|
20
20
|
functionsMeta,
|
|
21
21
|
typesMap,
|
|
22
22
|
requiredTypes
|
|
@@ -37,26 +37,26 @@ ${serializedImportMap}
|
|
|
37
37
|
${serializedCustomTypes}
|
|
38
38
|
${serializedMetaTypes}
|
|
39
39
|
|
|
40
|
-
interface
|
|
40
|
+
interface HTTPWiringHandler<I, O> {
|
|
41
41
|
input: I;
|
|
42
42
|
output: O;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
${
|
|
45
|
+
${serializedHTTPWirings}
|
|
46
46
|
|
|
47
|
-
export type
|
|
48
|
-
|
|
49
|
-
?
|
|
47
|
+
export type HTTPWiringHandlerOf<HTTPWiring extends keyof HTTPWiringsMap, Method extends keyof HTTPWiringsMap[HTTPWiring]> =
|
|
48
|
+
HTTPWiringsMap[HTTPWiring][Method] extends { input: infer I; output: infer O }
|
|
49
|
+
? HTTPWiringHandler<I, O>
|
|
50
50
|
: never;
|
|
51
51
|
|
|
52
|
-
export type
|
|
53
|
-
[
|
|
54
|
-
}[keyof
|
|
52
|
+
export type HTTPWiringsWithMethod<Method extends string> = {
|
|
53
|
+
[HTTPWiring in keyof HTTPWiringsMap]: Method extends keyof HTTPWiringsMap[HTTPWiring] ? HTTPWiring : never;
|
|
54
|
+
}[keyof HTTPWiringsMap];
|
|
55
55
|
`
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function
|
|
59
|
-
routesMeta:
|
|
58
|
+
function generateHTTPWirings(
|
|
59
|
+
routesMeta: HTTPWiringsMeta,
|
|
60
60
|
functionsMeta: FunctionsMeta,
|
|
61
61
|
typesMap: TypesMap,
|
|
62
62
|
requiredTypes: Set<string>
|
|
@@ -98,12 +98,12 @@ function generateRoutes(
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
// Build the routes object as a string
|
|
101
|
-
let routesStr = 'export type
|
|
101
|
+
let routesStr = 'export type HTTPWiringsMap = {\n'
|
|
102
102
|
|
|
103
103
|
for (const [routePath, methods] of Object.entries(routesObj)) {
|
|
104
104
|
routesStr += ` readonly '${routePath}': {\n`
|
|
105
105
|
for (const [method, handler] of Object.entries(methods)) {
|
|
106
|
-
routesStr += ` readonly ${method.toUpperCase()}:
|
|
106
|
+
routesStr += ` readonly ${method.toUpperCase()}: HTTPWiringHandler<${handler.inputType}, ${handler.outputType}>,\n`
|
|
107
107
|
}
|
|
108
108
|
routesStr += ' },\n'
|
|
109
109
|
}
|
|
@@ -62,7 +62,7 @@ const generateArgumentsFromSchema = async (
|
|
|
62
62
|
|
|
63
63
|
export const pikkuMCP: PikkuCommand = async (
|
|
64
64
|
logger,
|
|
65
|
-
{
|
|
65
|
+
{ mcpWiringsFile, mcpWiringsMetaFile, packageMappings, schemaDirectory },
|
|
66
66
|
{ mcpEndpoints, functions }
|
|
67
67
|
) => {
|
|
68
68
|
return await logCommandInfoAndTime(
|
|
@@ -73,10 +73,10 @@ export const pikkuMCP: PikkuCommand = async (
|
|
|
73
73
|
async () => {
|
|
74
74
|
await writeFileInDir(
|
|
75
75
|
logger,
|
|
76
|
-
|
|
76
|
+
mcpWiringsFile,
|
|
77
77
|
serializeFileImports(
|
|
78
|
-
'
|
|
79
|
-
|
|
78
|
+
'wireMCPResource or wireMCPTool',
|
|
79
|
+
mcpWiringsFile,
|
|
80
80
|
mcpEndpoints.files,
|
|
81
81
|
packageMappings
|
|
82
82
|
)
|
|
@@ -99,7 +99,7 @@ export const pikkuMCP: PikkuCommand = async (
|
|
|
99
99
|
|
|
100
100
|
await writeFileInDir(
|
|
101
101
|
logger,
|
|
102
|
-
|
|
102
|
+
mcpWiringsMetaFile,
|
|
103
103
|
`import { pikkuState } from '@pikku/core'
|
|
104
104
|
pikkuState('mcp', 'resourcesMeta', ${JSON.stringify(mcpEndpoints.resourcesMeta, null, 2)})
|
|
105
105
|
pikkuState('mcp', 'toolsMeta', ${JSON.stringify(mcpEndpoints.toolsMeta, null, 2)})
|
|
@@ -8,26 +8,29 @@ import { PikkuCommandWithoutState } from '../../types.js'
|
|
|
8
8
|
|
|
9
9
|
export const pikkuQueueService: PikkuCommandWithoutState = async (
|
|
10
10
|
logger,
|
|
11
|
-
{
|
|
11
|
+
{ queueWiringsFile, queueMapDeclarationFile, packageMappings }
|
|
12
12
|
) => {
|
|
13
13
|
return await logCommandInfoAndTime(
|
|
14
14
|
logger,
|
|
15
15
|
'Generating queue service wrapper',
|
|
16
16
|
'Generated queue service wrapper',
|
|
17
|
-
[
|
|
17
|
+
[
|
|
18
|
+
queueWiringsFile === undefined,
|
|
19
|
+
"queueWiringsFile isn't set in the pikku config",
|
|
20
|
+
],
|
|
18
21
|
async () => {
|
|
19
|
-
if (!
|
|
20
|
-
throw new Error("
|
|
22
|
+
if (!queueWiringsFile) {
|
|
23
|
+
throw new Error("queueWiringsFile is isn't set in the pikku config")
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
const queueMapDeclarationPath = getFileImportRelativePath(
|
|
24
|
-
|
|
27
|
+
queueWiringsFile,
|
|
25
28
|
queueMapDeclarationFile,
|
|
26
29
|
packageMappings
|
|
27
30
|
)
|
|
28
31
|
|
|
29
32
|
const content = [serializeQueueWrapper(queueMapDeclarationPath)]
|
|
30
|
-
await writeFileInDir(logger,
|
|
33
|
+
await writeFileInDir(logger, queueWiringsFile, content.join('\n'))
|
|
31
34
|
}
|
|
32
35
|
)
|
|
33
36
|
}
|
|
@@ -19,20 +19,23 @@ export const pikkuQueue: PikkuCommand = async (
|
|
|
19
19
|
'Found queue',
|
|
20
20
|
[visitState.queueWorkers.files.size === 0],
|
|
21
21
|
async () => {
|
|
22
|
-
const {
|
|
23
|
-
|
|
22
|
+
const {
|
|
23
|
+
queueWorkersWiringFile,
|
|
24
|
+
queueWorkersWiringMetaFile,
|
|
25
|
+
packageMappings,
|
|
26
|
+
} = cliConfig
|
|
24
27
|
const { queueWorkers } = visitState
|
|
25
28
|
await writeFileInDir(
|
|
26
29
|
logger,
|
|
27
|
-
|
|
30
|
+
queueWorkersWiringMetaFile,
|
|
28
31
|
serializeQueueMeta(queueWorkers.meta)
|
|
29
32
|
)
|
|
30
33
|
await writeFileInDir(
|
|
31
34
|
logger,
|
|
32
|
-
|
|
35
|
+
queueWorkersWiringFile,
|
|
33
36
|
serializeFileImports(
|
|
34
37
|
'addQueueWorkers',
|
|
35
|
-
|
|
38
|
+
queueWorkersWiringFile,
|
|
36
39
|
queueWorkers.files,
|
|
37
40
|
packageMappings
|
|
38
41
|
)
|
|
@@ -17,20 +17,23 @@ export const pikkuQueue: PikkuCommand = async (
|
|
|
17
17
|
'Found queue',
|
|
18
18
|
[visitState.queueWorkers.files.size === 0],
|
|
19
19
|
async () => {
|
|
20
|
-
const {
|
|
21
|
-
|
|
20
|
+
const {
|
|
21
|
+
queueWorkersWiringFile,
|
|
22
|
+
queueWorkersWiringMetaFile,
|
|
23
|
+
packageMappings,
|
|
24
|
+
} = cliConfig
|
|
22
25
|
const { queueWorkers } = visitState
|
|
23
26
|
await writeFileInDir(
|
|
24
27
|
logger,
|
|
25
|
-
|
|
28
|
+
queueWorkersWiringMetaFile,
|
|
26
29
|
serializeQueueMeta(queueWorkers.meta)
|
|
27
30
|
)
|
|
28
31
|
await writeFileInDir(
|
|
29
32
|
logger,
|
|
30
|
-
|
|
33
|
+
queueWorkersWiringFile,
|
|
31
34
|
serializeFileImports(
|
|
32
35
|
'addQueueWorkers',
|
|
33
|
-
|
|
36
|
+
queueWorkersWiringFile,
|
|
34
37
|
queueWorkers.files,
|
|
35
38
|
packageMappings
|
|
36
39
|
)
|
|
@@ -8,26 +8,29 @@ import { PikkuCommandWithoutState } from '../../types.js'
|
|
|
8
8
|
|
|
9
9
|
export const pikkuRPCClient: PikkuCommandWithoutState = async (
|
|
10
10
|
logger,
|
|
11
|
-
{
|
|
11
|
+
{ rpcWiringsFile, rpcMapDeclarationFile, packageMappings }
|
|
12
12
|
) => {
|
|
13
13
|
return await logCommandInfoAndTime(
|
|
14
14
|
logger,
|
|
15
15
|
'Generating RPC wrapper',
|
|
16
16
|
'Generated RPC wrapper',
|
|
17
|
-
[
|
|
17
|
+
[
|
|
18
|
+
rpcWiringsFile === undefined,
|
|
19
|
+
"rpcWiringsFile isn't set in the pikku config",
|
|
20
|
+
],
|
|
18
21
|
async () => {
|
|
19
|
-
if (!
|
|
20
|
-
throw new Error("
|
|
22
|
+
if (!rpcWiringsFile) {
|
|
23
|
+
throw new Error("rpcWiringsFile isn't set in the pikku config")
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
const rpcMapDeclarationPath = getFileImportRelativePath(
|
|
24
|
-
|
|
27
|
+
rpcWiringsFile,
|
|
25
28
|
rpcMapDeclarationFile,
|
|
26
29
|
packageMappings
|
|
27
30
|
)
|
|
28
31
|
|
|
29
32
|
const content = [serializeRPCWrapper(rpcMapDeclarationPath)]
|
|
30
|
-
await writeFileInDir(logger,
|
|
33
|
+
await writeFileInDir(logger, rpcWiringsFile, content.join('\n'))
|
|
31
34
|
}
|
|
32
35
|
)
|
|
33
36
|
}
|