@pikku/cli 0.7.6 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/bin/pikku-all.ts +87 -48
- package/bin/pikku-fetch.ts +5 -37
- package/bin/pikku-nextjs.ts +7 -112
- package/bin/pikku-openapi.ts +6 -53
- package/bin/pikku-queue-service.ts +24 -0
- package/bin/pikku-schemas.ts +6 -32
- package/bin/pikku-websocket.ts +6 -40
- package/bin/pikku.ts +2 -0
- package/dist/bin/pikku-all.d.ts +1 -1
- package/dist/bin/pikku-all.js +68 -48
- package/dist/bin/pikku-fetch.d.ts +1 -3
- package/dist/bin/pikku-fetch.js +4 -14
- package/dist/bin/pikku-nextjs.d.ts +1 -4
- package/dist/bin/pikku-nextjs.js +5 -39
- package/dist/bin/pikku-openapi.d.ts +0 -3
- package/dist/bin/pikku-openapi.js +5 -23
- package/dist/bin/pikku-queue-service.d.ts +4 -0
- package/dist/bin/pikku-queue-service.js +15 -0
- package/dist/bin/pikku-schemas.d.ts +0 -3
- package/dist/bin/pikku-schemas.js +5 -11
- package/dist/bin/pikku-websocket.d.ts +1 -3
- package/dist/bin/pikku-websocket.js +4 -17
- package/dist/bin/pikku.js +2 -0
- package/dist/src/events/channels/pikku-channels.d.ts +2 -0
- package/dist/src/events/channels/pikku-channels.js +9 -0
- package/dist/src/events/channels/pikku-command-channels-map.d.ts +2 -0
- package/dist/src/events/channels/pikku-command-channels-map.js +8 -0
- package/dist/src/events/channels/pikku-command-channels.d.ts +2 -0
- package/dist/src/events/channels/pikku-command-channels.js +9 -0
- package/dist/src/events/channels/pikku-command-websocket-typed.d.ts +2 -0
- package/dist/src/events/channels/pikku-command-websocket-typed.js +15 -0
- package/dist/src/{serialize-typed-channel-map.js → events/channels/serialize-typed-channel-map.js} +2 -2
- package/dist/src/events/fetch/index.d.ts +2 -0
- package/dist/src/events/fetch/index.js +12 -0
- package/dist/src/events/functions/pikku-command-function-types.d.ts +2 -0
- package/dist/src/events/functions/pikku-command-function-types.js +13 -0
- package/dist/src/events/functions/pikku-command-functions.d.ts +6 -0
- package/dist/src/events/functions/pikku-command-functions.js +35 -0
- package/dist/src/events/functions/pikku-function-types.d.ts +2 -0
- package/dist/{bin → src/events/functions}/pikku-function-types.js +6 -6
- package/dist/src/events/functions/pikku-functions.d.ts +6 -0
- package/dist/{bin → src/events/functions}/pikku-functions.js +5 -5
- package/dist/src/events/http/pikku-command-http-map.d.ts +2 -0
- package/dist/src/events/http/pikku-command-http-map.js +8 -0
- package/dist/src/events/http/pikku-command-http-routes.d.ts +2 -0
- package/dist/src/events/http/pikku-command-http-routes.js +9 -0
- package/dist/src/events/http/pikku-command-nextjs.d.ts +2 -0
- package/dist/src/events/http/pikku-command-nextjs.js +36 -0
- package/dist/src/events/http/pikku-command-openapi.d.ts +2 -0
- package/dist/src/events/http/pikku-command-openapi.js +20 -0
- package/dist/src/events/http/pikku-http-routes.d.ts +2 -0
- package/dist/src/events/http/pikku-http-routes.js +9 -0
- package/dist/src/{serialize-typed-http-map.js → events/http/serialize-typed-http-map.js} +1 -1
- package/dist/src/events/mcp/pikku-command-mcp-json.d.ts +2 -0
- package/dist/src/events/mcp/pikku-command-mcp-json.js +13 -0
- package/dist/src/events/mcp/pikku-command-mcp.d.ts +2 -0
- package/dist/src/events/mcp/pikku-command-mcp.js +54 -0
- package/dist/src/events/mcp/serialize-mcp-json.d.ts +5 -0
- package/dist/src/events/mcp/serialize-mcp-json.js +101 -0
- package/dist/src/events/queue/pikku-command-queue-map.d.ts +2 -0
- package/dist/src/events/queue/pikku-command-queue-map.js +8 -0
- package/dist/src/events/queue/pikku-command-queue-service.d.ts +2 -0
- package/dist/src/events/queue/pikku-command-queue-service.js +12 -0
- package/dist/src/events/queue/pikku-command-queue.d.ts +2 -0
- package/dist/src/events/queue/pikku-command-queue.js +10 -0
- package/dist/src/events/queue/pikku-queue-map.d.ts +2 -0
- package/dist/src/events/queue/pikku-queue-map.js +8 -0
- package/dist/src/events/queue/pikku-queue.d.ts +2 -0
- package/dist/src/events/queue/pikku-queue.js +10 -0
- package/dist/src/events/queue/serialize-queue-map.d.ts +4 -0
- package/dist/src/events/queue/serialize-queue-map.js +77 -0
- package/dist/src/events/queue/serialize-queue-meta.d.ts +2 -0
- package/dist/src/events/queue/serialize-queue-meta.js +6 -0
- package/dist/src/events/queue/serialize-queue-wrapper.d.ts +1 -0
- package/dist/src/events/queue/serialize-queue-wrapper.js +35 -0
- package/dist/src/events/rpc/pikku-command-rpc-map.d.ts +2 -0
- package/dist/src/events/rpc/pikku-command-rpc-map.js +8 -0
- package/dist/src/events/rpc/pikku-command-rpc.d.ts +2 -0
- package/dist/src/events/rpc/pikku-command-rpc.js +6 -0
- package/dist/src/events/rpc/pikku-rpc.d.ts +2 -0
- package/dist/src/events/rpc/pikku-rpc.js +6 -0
- package/dist/src/{serialize-typed-rpc-map.d.ts → events/rpc/serialize-typed-rpc-map.d.ts} +1 -1
- package/dist/src/{serialize-typed-rpc-map.js → events/rpc/serialize-typed-rpc-map.js} +2 -2
- package/dist/src/events/scheduler/pikku-command-scheduler.d.ts +2 -0
- package/dist/src/events/scheduler/pikku-command-scheduler.js +10 -0
- package/dist/src/inspector-glob.d.ts +1 -1
- package/dist/src/inspector-glob.js +3 -3
- package/dist/src/pikku-cli-config.d.ts +8 -1
- package/dist/src/pikku-cli-config.js +59 -22
- package/dist/src/pikku-command-schemas.d.ts +2 -0
- package/dist/src/pikku-command-schemas.js +8 -0
- package/dist/src/runtimes/nextjs/pikku-command-nextjs.d.ts +2 -0
- package/dist/src/runtimes/nextjs/pikku-command-nextjs.js +36 -0
- package/dist/src/{serialize-nextjs-http-wrapper.js → runtimes/nextjs/serialize-nextjs-http-wrapper.js} +1 -2
- package/dist/src/schema-generator.d.ts +3 -2
- package/dist/src/schema-generator.js +7 -7
- package/dist/src/schemas.d.ts +2 -0
- package/dist/src/schemas.js +8 -0
- package/dist/src/{utils/serialize-import-map.js → serialize-import-map.js} +3 -0
- package/dist/src/serialize-pikku-types.js +378 -1
- package/dist/src/types.d.ts +5 -0
- package/dist/src/types.js +1 -0
- package/dist/src/{utils/utils.d.ts → utils.d.ts} +17 -7
- package/dist/src/{utils/utils.js → utils.js} +47 -29
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/{bin → src/events/channels}/pikku-channels.ts +8 -3
- package/src/events/channels/pikku-command-channels-map.ts +26 -0
- package/src/events/channels/pikku-command-channels.ts +38 -0
- package/src/events/channels/pikku-command-websocket-typed.ts +36 -0
- package/src/{serialize-typed-channel-map.ts → events/channels/serialize-typed-channel-map.ts} +2 -2
- package/src/events/fetch/index.ts +33 -0
- package/src/events/functions/pikku-command-function-types.ts +48 -0
- package/src/events/functions/pikku-command-functions.ts +84 -0
- package/{bin → src/events/functions}/pikku-function-types.ts +12 -15
- package/{bin → src/events/functions}/pikku-functions.ts +9 -6
- package/src/events/http/pikku-command-http-map.ts +27 -0
- package/src/events/http/pikku-command-http-routes.ts +40 -0
- package/src/events/http/pikku-command-nextjs.ts +111 -0
- package/src/events/http/pikku-command-openapi.ts +54 -0
- package/{bin → src/events/http}/pikku-http-routes.ts +8 -3
- package/src/{serialize-typed-http-map.ts → events/http/serialize-typed-http-map.ts} +1 -1
- package/src/events/mcp/pikku-command-mcp-json.ts +33 -0
- package/src/events/mcp/pikku-command-mcp.ts +110 -0
- package/src/events/mcp/serialize-mcp-json.ts +159 -0
- package/src/events/queue/pikku-command-queue-map.ts +26 -0
- package/src/events/queue/pikku-command-queue-service.ts +33 -0
- package/src/events/queue/pikku-command-queue.ts +42 -0
- package/src/events/queue/pikku-queue-map.ts +26 -0
- package/src/events/queue/pikku-queue.ts +40 -0
- package/src/events/queue/serialize-queue-map.ts +119 -0
- package/src/events/queue/serialize-queue-meta.ts +10 -0
- package/src/events/queue/serialize-queue-wrapper.ts +35 -0
- package/src/events/rpc/pikku-command-rpc-map.ts +26 -0
- package/src/events/rpc/pikku-command-rpc.ts +22 -0
- package/{bin → src/events/rpc}/pikku-rpc.ts +8 -6
- package/src/{serialize-typed-rpc-map.ts → events/rpc/serialize-typed-rpc-map.ts} +4 -3
- package/{bin/pikku-scheduler.ts → src/events/scheduler/pikku-command-scheduler.ts} +11 -8
- package/src/inspector-glob.ts +3 -1
- package/src/pikku-cli-config.ts +93 -32
- package/src/pikku-command-schemas.ts +33 -0
- package/src/runtimes/nextjs/pikku-command-nextjs.ts +110 -0
- package/src/{serialize-nextjs-http-wrapper.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.ts} +1 -2
- package/src/schema-generator.ts +8 -3
- package/src/schemas.ts +33 -0
- package/src/{utils/serialize-import-map.ts → serialize-import-map.ts} +5 -0
- package/src/serialize-pikku-types.ts +378 -1
- package/src/types.ts +16 -0
- package/src/{utils/utils.ts → utils.ts} +55 -31
- package/tsconfig.json +1 -1
- package/bin/pikku-channels-map.ts +0 -25
- package/bin/pikku-http-map.ts +0 -26
- package/bin/pikku-nextjs.test.ts +0 -279
- package/bin/pikku-rpc-map.ts +0 -25
- package/dist/bin/pikku-channels-map.d.ts +0 -3
- package/dist/bin/pikku-channels-map.js +0 -8
- package/dist/bin/pikku-channels.d.ts +0 -3
- package/dist/bin/pikku-channels.js +0 -9
- package/dist/bin/pikku-function-types.d.ts +0 -4
- package/dist/bin/pikku-functions.d.ts +0 -7
- package/dist/bin/pikku-http-map.d.ts +0 -3
- package/dist/bin/pikku-http-map.js +0 -8
- package/dist/bin/pikku-http-routes.d.ts +0 -3
- package/dist/bin/pikku-http-routes.js +0 -9
- package/dist/bin/pikku-rpc-map.d.ts +0 -3
- package/dist/bin/pikku-rpc-map.js +0 -8
- package/dist/bin/pikku-rpc.d.ts +0 -3
- package/dist/bin/pikku-rpc.js +0 -6
- package/dist/bin/pikku-scheduler.d.ts +0 -3
- package/dist/bin/pikku-scheduler.js +0 -10
- /package/dist/src/{serialize-typed-channel-map.d.ts → events/channels/serialize-typed-channel-map.d.ts} +0 -0
- /package/dist/src/{serialize-websocket-wrapper.d.ts → events/channels/serialize-websocket-wrapper.d.ts} +0 -0
- /package/dist/src/{serialize-websocket-wrapper.js → events/channels/serialize-websocket-wrapper.js} +0 -0
- /package/dist/src/{openapi-spec-generator.d.ts → events/http/openapi-spec-generator.d.ts} +0 -0
- /package/dist/src/{openapi-spec-generator.js → events/http/openapi-spec-generator.js} +0 -0
- /package/dist/src/{serialize-fetch-wrapper.d.ts → events/http/serialize-fetch-wrapper.d.ts} +0 -0
- /package/dist/src/{serialize-fetch-wrapper.js → events/http/serialize-fetch-wrapper.js} +0 -0
- /package/dist/src/{serialize-typed-http-map.d.ts → events/http/serialize-typed-http-map.d.ts} +0 -0
- /package/dist/src/{serialize-scheduler-meta.d.ts → events/scheduler/serialize-scheduler-meta.d.ts} +0 -0
- /package/dist/src/{serialize-scheduler-meta.js → events/scheduler/serialize-scheduler-meta.js} +0 -0
- /package/dist/src/{serialize-nextjs-backend-wrapper.d.ts → runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts} +0 -0
- /package/dist/src/{serialize-nextjs-backend-wrapper.js → runtimes/nextjs/serialize-nextjs-backend-wrapper.js} +0 -0
- /package/dist/src/{serialize-nextjs-http-wrapper.d.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.d.ts} +0 -0
- /package/dist/src/{utils/serialize-import-map.d.ts → serialize-import-map.d.ts} +0 -0
- /package/src/{serialize-websocket-wrapper.ts → events/channels/serialize-websocket-wrapper.ts} +0 -0
- /package/src/{openapi-spec-generator.ts → events/http/openapi-spec-generator.ts} +0 -0
- /package/src/{serialize-fetch-wrapper.ts → events/http/serialize-fetch-wrapper.ts} +0 -0
- /package/src/{serialize-scheduler-meta.ts → events/scheduler/serialize-scheduler-meta.ts} +0 -0
- /package/src/{serialize-nextjs-backend-wrapper.ts → runtimes/nextjs/serialize-nextjs-backend-wrapper.ts} +0 -0
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { logCommandInfoAndTime, writeFileInDir } from '../src/utils/utils.js'
|
|
1
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js'
|
|
2
|
+
import { PikkuCommand } from '../../types.js'
|
|
4
3
|
|
|
5
|
-
export const pikkuRPC = async (
|
|
6
|
-
|
|
7
|
-
{
|
|
4
|
+
export const pikkuRPC: PikkuCommand = async (
|
|
5
|
+
logger,
|
|
6
|
+
{ rpcMetaFile },
|
|
7
|
+
{ rpc }
|
|
8
8
|
) => {
|
|
9
9
|
return await logCommandInfoAndTime(
|
|
10
|
+
logger,
|
|
10
11
|
'Finding RPCs tasks',
|
|
11
12
|
'Found RPCs',
|
|
12
13
|
[false],
|
|
13
14
|
async () => {
|
|
14
15
|
await writeFileInDir(
|
|
16
|
+
logger,
|
|
15
17
|
rpcMetaFile,
|
|
16
18
|
`import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`
|
|
17
19
|
)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RPCMeta } from '@pikku/core/rpc'
|
|
2
|
+
|
|
3
|
+
import { serializeImportMap } from '../../serialize-import-map.js'
|
|
2
4
|
import { TypesMap } from '@pikku/inspector'
|
|
3
5
|
import { FunctionsMeta } from '@pikku/core'
|
|
4
|
-
import { generateCustomTypes } from '
|
|
5
|
-
import { RPCMeta } from '../../core/src/rpc/rpc-types.js'
|
|
6
|
+
import { generateCustomTypes } from '../../utils.js'
|
|
6
7
|
|
|
7
8
|
export const serializeTypedRPCMap = (
|
|
8
9
|
relativeToPath: string,
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { PikkuCLIConfig } from '../src/pikku-cli-config.js'
|
|
2
|
-
import { InspectorState } from '@pikku/inspector'
|
|
3
1
|
import {
|
|
4
2
|
logCommandInfoAndTime,
|
|
5
3
|
serializeFileImports,
|
|
6
4
|
writeFileInDir,
|
|
7
|
-
} from '
|
|
8
|
-
import { serializeSchedulerMeta } from '
|
|
5
|
+
} from '../../utils.js'
|
|
6
|
+
import { serializeSchedulerMeta } from './serialize-scheduler-meta.js'
|
|
7
|
+
import { PikkuCommand } from '../../types.js'
|
|
9
8
|
|
|
10
|
-
export const pikkuScheduler = async (
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export const pikkuScheduler: PikkuCommand = async (
|
|
10
|
+
logger,
|
|
11
|
+
cliConfig,
|
|
12
|
+
visitState
|
|
13
13
|
) => {
|
|
14
14
|
return await logCommandInfoAndTime(
|
|
15
|
+
logger,
|
|
15
16
|
'Finding scheduled tasks',
|
|
16
17
|
'Found scheduled tasks',
|
|
17
18
|
[visitState.scheduledTasks.files.size === 0],
|
|
@@ -19,13 +20,15 @@ export const pikkuScheduler = async (
|
|
|
19
20
|
const { schedulersFile, schedulersMetaFile, packageMappings } = cliConfig
|
|
20
21
|
const { scheduledTasks } = visitState
|
|
21
22
|
await writeFileInDir(
|
|
23
|
+
logger,
|
|
22
24
|
schedulersMetaFile,
|
|
23
25
|
serializeSchedulerMeta(scheduledTasks.meta)
|
|
24
26
|
)
|
|
25
27
|
await writeFileInDir(
|
|
28
|
+
logger,
|
|
26
29
|
schedulersFile,
|
|
27
30
|
serializeFileImports(
|
|
28
|
-
'
|
|
31
|
+
'addScheduledTasks',
|
|
29
32
|
schedulersFile,
|
|
30
33
|
scheduledTasks.files,
|
|
31
34
|
packageMappings
|
package/src/inspector-glob.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import * as path from 'path'
|
|
2
2
|
import { glob } from 'tinyglobby'
|
|
3
3
|
import { InspectorFilters, InspectorState, inspect } from '@pikku/inspector'
|
|
4
|
-
import { logCommandInfoAndTime } from './utils
|
|
4
|
+
import { logCommandInfoAndTime } from './utils.js'
|
|
5
5
|
|
|
6
6
|
export const inspectorGlob = async (
|
|
7
|
+
logger,
|
|
7
8
|
rootDir: string,
|
|
8
9
|
srcDirectories: string[],
|
|
9
10
|
filters: InspectorFilters
|
|
10
11
|
) => {
|
|
11
12
|
let result: InspectorState
|
|
12
13
|
await logCommandInfoAndTime(
|
|
14
|
+
logger,
|
|
13
15
|
'Inspecting codebase',
|
|
14
16
|
'Inspected codebase',
|
|
15
17
|
[false],
|
package/src/pikku-cli-config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join, dirname, resolve, isAbsolute } from 'path'
|
|
2
2
|
import { readdir, readFile } from 'fs/promises'
|
|
3
|
-
import { OpenAPISpecInfo } from './openapi-spec-generator.js'
|
|
3
|
+
import { OpenAPISpecInfo } from './events/http/openapi-spec-generator.js'
|
|
4
4
|
import { InspectorFilters } from '@pikku/inspector'
|
|
5
5
|
import { PikkuEventTypes } from '@pikku/core'
|
|
6
6
|
|
|
@@ -34,6 +34,15 @@ export interface PikkuCLICoreOutputFiles {
|
|
|
34
34
|
schedulersFile: string
|
|
35
35
|
schedulersMetaFile: string
|
|
36
36
|
|
|
37
|
+
// Queue processors
|
|
38
|
+
queueWorkersFile: string
|
|
39
|
+
queueWorkersMetaFile: string
|
|
40
|
+
queueMapDeclarationFile: string
|
|
41
|
+
|
|
42
|
+
// MCP
|
|
43
|
+
mcpEndpointsFile: string
|
|
44
|
+
mcpEndpointsMetaFile: string
|
|
45
|
+
|
|
37
46
|
// Application bootstrap
|
|
38
47
|
bootstrapFile: string
|
|
39
48
|
bootstrapFiles: Record<PikkuEventTypes, string>
|
|
@@ -56,6 +65,8 @@ export type PikkuCLIConfig = {
|
|
|
56
65
|
nextHTTPFile?: string
|
|
57
66
|
fetchFile?: string
|
|
58
67
|
websocketFile?: string
|
|
68
|
+
queueFile?: string
|
|
69
|
+
mcpJsonFile?: string
|
|
59
70
|
|
|
60
71
|
openAPI?: {
|
|
61
72
|
outputFile: string
|
|
@@ -70,6 +81,8 @@ const CONFIG_DIR_FILES = [
|
|
|
70
81
|
'nextHTTPFile',
|
|
71
82
|
'fetchFile',
|
|
72
83
|
'websocketFile',
|
|
84
|
+
'queueFile',
|
|
85
|
+
'mcpJsonFile',
|
|
73
86
|
]
|
|
74
87
|
|
|
75
88
|
export const getPikkuCLIConfig = async (
|
|
@@ -142,9 +155,21 @@ const _getPikkuCLIConfig = async (
|
|
|
142
155
|
}
|
|
143
156
|
|
|
144
157
|
if (result.outDir) {
|
|
158
|
+
// Create transport/event directories
|
|
159
|
+
const httpDir = join(result.outDir, 'http')
|
|
160
|
+
const channelsDir = join(result.outDir, 'channels')
|
|
161
|
+
const rpcDir = join(result.outDir, 'rpc')
|
|
162
|
+
const schedulerDir = join(result.outDir, 'scheduler')
|
|
163
|
+
const queueDir = join(result.outDir, 'queue')
|
|
164
|
+
const mcpDir = join(result.outDir, 'mcp')
|
|
165
|
+
|
|
166
|
+
// Create directories if they don't exist (will be done lazily when files are written)
|
|
167
|
+
|
|
145
168
|
if (!result.schemaDirectory) {
|
|
146
|
-
result.schemaDirectory = join(result.outDir, '
|
|
169
|
+
result.schemaDirectory = join(result.outDir, 'schemas')
|
|
147
170
|
}
|
|
171
|
+
|
|
172
|
+
// Functions
|
|
148
173
|
if (!result.functionsFile) {
|
|
149
174
|
result.functionsFile = join(result.outDir, 'pikku-functions.gen.ts')
|
|
150
175
|
}
|
|
@@ -154,65 +179,101 @@ const _getPikkuCLIConfig = async (
|
|
|
154
179
|
'pikku-functions-meta.gen.ts'
|
|
155
180
|
)
|
|
156
181
|
}
|
|
157
|
-
if (!result.
|
|
158
|
-
result.
|
|
159
|
-
}
|
|
160
|
-
if (!result.rpcMapDeclarationFile) {
|
|
161
|
-
result.rpcMapDeclarationFile = join(
|
|
162
|
-
result.outDir,
|
|
163
|
-
'pikku-rpc-map.gen.ts'
|
|
164
|
-
)
|
|
182
|
+
if (!result.typesDeclarationFile) {
|
|
183
|
+
result.typesDeclarationFile = join(result.outDir, 'pikku-types.gen.ts')
|
|
165
184
|
}
|
|
185
|
+
|
|
186
|
+
// HTTP
|
|
166
187
|
if (!result.httpRoutesFile) {
|
|
167
|
-
result.httpRoutesFile = join(
|
|
188
|
+
result.httpRoutesFile = join(httpDir, 'pikku-http-routes.gen.ts')
|
|
168
189
|
}
|
|
169
190
|
if (!result.httpRoutesMetaFile) {
|
|
170
191
|
result.httpRoutesMetaFile = join(
|
|
171
|
-
|
|
192
|
+
httpDir,
|
|
172
193
|
'pikku-http-routes-meta.gen.ts'
|
|
173
194
|
)
|
|
174
195
|
}
|
|
175
|
-
if (!result.
|
|
176
|
-
result.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
result.schedulersMetaFile = join(
|
|
180
|
-
result.outDir,
|
|
181
|
-
'pikku-schedules-meta.gen.ts'
|
|
196
|
+
if (!result.httpRoutesMapDeclarationFile) {
|
|
197
|
+
result.httpRoutesMapDeclarationFile = join(
|
|
198
|
+
httpDir,
|
|
199
|
+
'pikku-http-routes-map.gen.d.ts'
|
|
182
200
|
)
|
|
183
201
|
}
|
|
202
|
+
|
|
203
|
+
// Channels/WebSocket
|
|
184
204
|
if (!result.channelsFile) {
|
|
185
|
-
result.channelsFile = join(
|
|
205
|
+
result.channelsFile = join(channelsDir, 'pikku-channels.gen.ts')
|
|
186
206
|
}
|
|
187
207
|
if (!result.channelsMetaFile) {
|
|
188
208
|
result.channelsMetaFile = join(
|
|
189
|
-
|
|
209
|
+
channelsDir,
|
|
190
210
|
'pikku-channels-meta.gen.ts'
|
|
191
211
|
)
|
|
192
212
|
}
|
|
193
|
-
if (!result.typesDeclarationFile) {
|
|
194
|
-
result.typesDeclarationFile = join(result.outDir, 'pikku-types.gen.ts')
|
|
195
|
-
}
|
|
196
|
-
if (!result.httpRoutesMapDeclarationFile) {
|
|
197
|
-
result.httpRoutesMapDeclarationFile = join(
|
|
198
|
-
result.outDir,
|
|
199
|
-
'pikku-routes-map.gen.d.ts'
|
|
200
|
-
)
|
|
201
|
-
}
|
|
202
213
|
if (!result.channelsMapDeclarationFile) {
|
|
203
214
|
result.channelsMapDeclarationFile = join(
|
|
204
|
-
|
|
215
|
+
channelsDir,
|
|
205
216
|
'pikku-channels-map.gen.d.ts'
|
|
206
217
|
)
|
|
207
218
|
}
|
|
219
|
+
|
|
220
|
+
// RPC
|
|
221
|
+
if (!result.rpcMetaFile) {
|
|
222
|
+
result.rpcMetaFile = join(rpcDir, 'pikku-rpc-meta.gen.ts')
|
|
223
|
+
}
|
|
224
|
+
if (!result.rpcMapDeclarationFile) {
|
|
225
|
+
result.rpcMapDeclarationFile = join(rpcDir, 'pikku-rpc-map.gen.ts')
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Scheduler
|
|
229
|
+
if (!result.schedulersFile) {
|
|
230
|
+
result.schedulersFile = join(schedulerDir, 'pikku-schedules.gen.ts')
|
|
231
|
+
}
|
|
232
|
+
if (!result.schedulersMetaFile) {
|
|
233
|
+
result.schedulersMetaFile = join(
|
|
234
|
+
schedulerDir,
|
|
235
|
+
'pikku-schedules-meta.gen.ts'
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Queue
|
|
240
|
+
if (!result.queueWorkersFile) {
|
|
241
|
+
result.queueWorkersFile = join(queueDir, 'pikku-queue-workers.gen.ts')
|
|
242
|
+
}
|
|
243
|
+
if (!result.queueWorkersMetaFile) {
|
|
244
|
+
result.queueWorkersMetaFile = join(
|
|
245
|
+
queueDir,
|
|
246
|
+
'pikku-queue-workers-meta.gen.ts'
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
if (!result.queueMapDeclarationFile) {
|
|
250
|
+
result.queueMapDeclarationFile = join(
|
|
251
|
+
queueDir,
|
|
252
|
+
'pikku-queue-map.gen.ts'
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Bootstrap files
|
|
208
257
|
if (!result.bootstrapFile) {
|
|
209
258
|
result.bootstrapFile = join(result.outDir, 'pikku-bootstrap.gen.ts')
|
|
210
259
|
}
|
|
211
260
|
|
|
261
|
+
// MCP
|
|
262
|
+
if (!result.mcpEndpointsMetaFile) {
|
|
263
|
+
result.mcpEndpointsMetaFile = join(mcpDir, 'mcp-endpoints-meta.gen.ts')
|
|
264
|
+
}
|
|
265
|
+
if (!result.mcpEndpointsFile) {
|
|
266
|
+
result.mcpEndpointsFile = join(mcpDir, 'mcp-endpoints.gen.ts')
|
|
267
|
+
}
|
|
268
|
+
if (!result.mcpJsonFile) {
|
|
269
|
+
result.mcpJsonFile = join(mcpDir, 'mcp.gen.json')
|
|
270
|
+
}
|
|
271
|
+
|
|
212
272
|
result.bootstrapFiles = result.bootstrapFiles || {}
|
|
213
273
|
for (const key of Object.keys(PikkuEventTypes)) {
|
|
274
|
+
const eventDir = join(result.outDir, key.toLowerCase())
|
|
214
275
|
result.bootstrapFiles[key] = join(
|
|
215
|
-
|
|
276
|
+
eventDir,
|
|
216
277
|
`pikku-bootstrap-${key}.gen.ts`
|
|
217
278
|
)
|
|
218
279
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { generateSchemas, saveSchemas } from './schema-generator.js'
|
|
2
|
+
import { logCommandInfoAndTime } from './utils.js'
|
|
3
|
+
import { PikkuCommand } from './types.js'
|
|
4
|
+
|
|
5
|
+
export const pikkuSchemas: PikkuCommand = async (
|
|
6
|
+
logger,
|
|
7
|
+
{ tsconfig, schemaDirectory, supportsImportAttributes },
|
|
8
|
+
{ functions, http }
|
|
9
|
+
) => {
|
|
10
|
+
return await logCommandInfoAndTime(
|
|
11
|
+
logger,
|
|
12
|
+
'Creating schemas',
|
|
13
|
+
'Created schemas',
|
|
14
|
+
[false],
|
|
15
|
+
async () => {
|
|
16
|
+
const schemas = await generateSchemas(
|
|
17
|
+
logger,
|
|
18
|
+
tsconfig,
|
|
19
|
+
functions.typesMap,
|
|
20
|
+
functions.meta,
|
|
21
|
+
http.meta
|
|
22
|
+
)
|
|
23
|
+
await saveSchemas(
|
|
24
|
+
logger,
|
|
25
|
+
schemaDirectory,
|
|
26
|
+
schemas,
|
|
27
|
+
functions.typesMap,
|
|
28
|
+
functions.meta,
|
|
29
|
+
supportsImportAttributes
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logCommandInfoAndTime,
|
|
3
|
+
getPikkuFilesAndMethods,
|
|
4
|
+
getFileImportRelativePath,
|
|
5
|
+
writeFileInDir,
|
|
6
|
+
} from '../../utils.js'
|
|
7
|
+
import { serializeNextJsBackendWrapper as serializeNextBackendWrapper } from './serialize-nextjs-backend-wrapper.js'
|
|
8
|
+
import { serializeNextJsHTTPWrapper as serializeNextHTTPWrapper } from './serialize-nextjs-http-wrapper.js'
|
|
9
|
+
import { PikkuCommand } from '../../types.js'
|
|
10
|
+
|
|
11
|
+
export const pikkuNext: PikkuCommand = async (
|
|
12
|
+
logger,
|
|
13
|
+
{
|
|
14
|
+
nextBackendFile,
|
|
15
|
+
nextHTTPFile,
|
|
16
|
+
httpRoutesMapDeclarationFile,
|
|
17
|
+
packageMappings,
|
|
18
|
+
fetchFile,
|
|
19
|
+
bootstrapFiles,
|
|
20
|
+
},
|
|
21
|
+
visitState,
|
|
22
|
+
options = {}
|
|
23
|
+
) => {
|
|
24
|
+
return await logCommandInfoAndTime(
|
|
25
|
+
logger,
|
|
26
|
+
'Generating nextjs wrapper',
|
|
27
|
+
'Generated nextjs wrapper',
|
|
28
|
+
[
|
|
29
|
+
nextBackendFile === undefined && nextHTTPFile === undefined,
|
|
30
|
+
'nextjs outfile is not defined',
|
|
31
|
+
],
|
|
32
|
+
async () => {
|
|
33
|
+
if (!nextBackendFile && !nextHTTPFile) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
'nextBackendFile or nextHTTPFile is required in pikku config for nextJS'
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (nextHTTPFile && !fetchFile) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
'fetchFile is required in pikku config in order for nextJS http wrapper to work'
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (nextBackendFile) {
|
|
46
|
+
const {
|
|
47
|
+
pikkuConfigFactory,
|
|
48
|
+
singletonServicesFactory,
|
|
49
|
+
sessionServicesFactory,
|
|
50
|
+
} = await getPikkuFilesAndMethods(
|
|
51
|
+
logger,
|
|
52
|
+
visitState,
|
|
53
|
+
packageMappings,
|
|
54
|
+
nextBackendFile,
|
|
55
|
+
options,
|
|
56
|
+
{
|
|
57
|
+
config: true,
|
|
58
|
+
singletonServicesFactory: true,
|
|
59
|
+
sessionServicesFactory: true,
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextBackendFile, pikkuConfigFactory.file, packageMappings)}'`
|
|
64
|
+
const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextBackendFile, singletonServicesFactory.file, packageMappings)}'`
|
|
65
|
+
const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextBackendFile, sessionServicesFactory.file, packageMappings)}'`
|
|
66
|
+
|
|
67
|
+
const httpBootstrapPath = getFileImportRelativePath(
|
|
68
|
+
nextBackendFile,
|
|
69
|
+
bootstrapFiles.http,
|
|
70
|
+
packageMappings
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const routesMapDeclarationPath = getFileImportRelativePath(
|
|
74
|
+
nextBackendFile,
|
|
75
|
+
httpRoutesMapDeclarationFile,
|
|
76
|
+
packageMappings
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
const content = serializeNextBackendWrapper(
|
|
80
|
+
httpBootstrapPath,
|
|
81
|
+
routesMapDeclarationPath,
|
|
82
|
+
pikkuConfigImport,
|
|
83
|
+
singletonServicesImport,
|
|
84
|
+
sessionServicesImport
|
|
85
|
+
)
|
|
86
|
+
await writeFileInDir(logger, nextBackendFile, content)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (nextHTTPFile && fetchFile) {
|
|
90
|
+
const routesMapDeclarationPath = getFileImportRelativePath(
|
|
91
|
+
nextHTTPFile,
|
|
92
|
+
httpRoutesMapDeclarationFile,
|
|
93
|
+
packageMappings
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
const fetchPath = getFileImportRelativePath(
|
|
97
|
+
nextHTTPFile,
|
|
98
|
+
fetchFile,
|
|
99
|
+
packageMappings
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
const content = serializeNextHTTPWrapper(
|
|
103
|
+
routesMapDeclarationPath,
|
|
104
|
+
fetchPath
|
|
105
|
+
)
|
|
106
|
+
await writeFileInDir(logger, nextHTTPFile, content)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
}
|
package/src/{serialize-nextjs-http-wrapper.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.ts}
RENAMED
|
@@ -10,11 +10,10 @@ export const serializeNextJsHTTPWrapper = (
|
|
|
10
10
|
*/
|
|
11
11
|
import { CorePikkuFetchOptions } from '@pikku/fetch'
|
|
12
12
|
import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
|
|
13
|
+
import { PikkuFetch } from '${pikkuFetchImport}'
|
|
13
14
|
|
|
14
15
|
let _pikku: PikkuFetch | undefined
|
|
15
16
|
|
|
16
|
-
${pikkuFetchImport}
|
|
17
|
-
|
|
18
17
|
/**
|
|
19
18
|
* Initializes and returns an instance of PikkuNextJS with helper methods for handling route requests.
|
|
20
19
|
*
|
package/src/schema-generator.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createGenerator, RootlessError } from 'ts-json-schema-generator'
|
|
2
|
-
import {
|
|
2
|
+
import { CLILogger, writeFileInDir } from './utils.js'
|
|
3
3
|
import { mkdir, writeFile } from 'fs/promises'
|
|
4
4
|
import { FunctionsMeta, JSONValue } from '@pikku/core'
|
|
5
5
|
import { HTTPRoutesMeta } from '@pikku/core/http'
|
|
6
6
|
import { TypesMap } from '@pikku/inspector'
|
|
7
7
|
|
|
8
8
|
export async function generateSchemas(
|
|
9
|
+
logger: CLILogger,
|
|
9
10
|
tsconfig: string,
|
|
10
11
|
typesMap: TypesMap,
|
|
11
12
|
functionMeta: FunctionsMeta,
|
|
@@ -63,6 +64,7 @@ export async function generateSchemas(
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
export async function saveSchemas(
|
|
67
|
+
logger: CLILogger,
|
|
66
68
|
schemaParentDir: string,
|
|
67
69
|
schemas: Record<string, JSONValue>,
|
|
68
70
|
typesMap: TypesMap,
|
|
@@ -70,6 +72,7 @@ export async function saveSchemas(
|
|
|
70
72
|
supportsImportAttributes: boolean
|
|
71
73
|
) {
|
|
72
74
|
await writeFileInDir(
|
|
75
|
+
logger,
|
|
73
76
|
`${schemaParentDir}/register.gen.ts`,
|
|
74
77
|
'export const empty = null;'
|
|
75
78
|
)
|
|
@@ -90,7 +93,7 @@ export async function saveSchemas(
|
|
|
90
93
|
])
|
|
91
94
|
|
|
92
95
|
if (desiredSchemas.size === 0) {
|
|
93
|
-
|
|
96
|
+
logger.info(`• Skipping schemas since none found.\x1b[0m`)
|
|
94
97
|
return
|
|
95
98
|
}
|
|
96
99
|
|
|
@@ -117,8 +120,10 @@ addSchema('${schema}', ${schema})
|
|
|
117
120
|
.join('\n')
|
|
118
121
|
|
|
119
122
|
await writeFileInDir(
|
|
123
|
+
logger,
|
|
120
124
|
`${schemaParentDir}/register.gen.ts`,
|
|
121
125
|
`import { addSchema } from '@pikku/core/schema'
|
|
122
|
-
${schemaImports}
|
|
126
|
+
${schemaImports}`,
|
|
127
|
+
{ logWrite: true }
|
|
123
128
|
)
|
|
124
129
|
}
|
package/src/schemas.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { saveSchemas, generateSchemas } from './schema-generator.js'
|
|
2
|
+
import { logCommandInfoAndTime } from './utils.js'
|
|
3
|
+
import { PikkuCommand } from './types.js'
|
|
4
|
+
|
|
5
|
+
export const pikkuSchemas: PikkuCommand = async (
|
|
6
|
+
logger,
|
|
7
|
+
{ tsconfig, schemaDirectory, supportsImportAttributes },
|
|
8
|
+
{ functions, http }
|
|
9
|
+
) => {
|
|
10
|
+
return await logCommandInfoAndTime(
|
|
11
|
+
logger,
|
|
12
|
+
'Creating schemas',
|
|
13
|
+
'Created schemas',
|
|
14
|
+
[false],
|
|
15
|
+
async () => {
|
|
16
|
+
const schemas = await generateSchemas(
|
|
17
|
+
logger,
|
|
18
|
+
tsconfig,
|
|
19
|
+
functions.typesMap,
|
|
20
|
+
functions.meta,
|
|
21
|
+
http.meta
|
|
22
|
+
)
|
|
23
|
+
await saveSchemas(
|
|
24
|
+
logger,
|
|
25
|
+
schemaDirectory,
|
|
26
|
+
schemas,
|
|
27
|
+
functions.typesMap,
|
|
28
|
+
functions.meta,
|
|
29
|
+
supportsImportAttributes
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
}
|