@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.
Files changed (190) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/bin/pikku-all.ts +87 -48
  3. package/bin/pikku-fetch.ts +5 -37
  4. package/bin/pikku-nextjs.ts +7 -112
  5. package/bin/pikku-openapi.ts +6 -53
  6. package/bin/pikku-queue-service.ts +24 -0
  7. package/bin/pikku-schemas.ts +6 -32
  8. package/bin/pikku-websocket.ts +6 -40
  9. package/bin/pikku.ts +2 -0
  10. package/dist/bin/pikku-all.d.ts +1 -1
  11. package/dist/bin/pikku-all.js +68 -48
  12. package/dist/bin/pikku-fetch.d.ts +1 -3
  13. package/dist/bin/pikku-fetch.js +4 -14
  14. package/dist/bin/pikku-nextjs.d.ts +1 -4
  15. package/dist/bin/pikku-nextjs.js +5 -39
  16. package/dist/bin/pikku-openapi.d.ts +0 -3
  17. package/dist/bin/pikku-openapi.js +5 -23
  18. package/dist/bin/pikku-queue-service.d.ts +4 -0
  19. package/dist/bin/pikku-queue-service.js +15 -0
  20. package/dist/bin/pikku-schemas.d.ts +0 -3
  21. package/dist/bin/pikku-schemas.js +5 -11
  22. package/dist/bin/pikku-websocket.d.ts +1 -3
  23. package/dist/bin/pikku-websocket.js +4 -17
  24. package/dist/bin/pikku.js +2 -0
  25. package/dist/src/events/channels/pikku-channels.d.ts +2 -0
  26. package/dist/src/events/channels/pikku-channels.js +9 -0
  27. package/dist/src/events/channels/pikku-command-channels-map.d.ts +2 -0
  28. package/dist/src/events/channels/pikku-command-channels-map.js +8 -0
  29. package/dist/src/events/channels/pikku-command-channels.d.ts +2 -0
  30. package/dist/src/events/channels/pikku-command-channels.js +9 -0
  31. package/dist/src/events/channels/pikku-command-websocket-typed.d.ts +2 -0
  32. package/dist/src/events/channels/pikku-command-websocket-typed.js +15 -0
  33. package/dist/src/{serialize-typed-channel-map.js → events/channels/serialize-typed-channel-map.js} +2 -2
  34. package/dist/src/events/fetch/index.d.ts +2 -0
  35. package/dist/src/events/fetch/index.js +12 -0
  36. package/dist/src/events/functions/pikku-command-function-types.d.ts +2 -0
  37. package/dist/src/events/functions/pikku-command-function-types.js +13 -0
  38. package/dist/src/events/functions/pikku-command-functions.d.ts +6 -0
  39. package/dist/src/events/functions/pikku-command-functions.js +35 -0
  40. package/dist/src/events/functions/pikku-function-types.d.ts +2 -0
  41. package/dist/{bin → src/events/functions}/pikku-function-types.js +6 -6
  42. package/dist/src/events/functions/pikku-functions.d.ts +6 -0
  43. package/dist/{bin → src/events/functions}/pikku-functions.js +5 -5
  44. package/dist/src/events/http/pikku-command-http-map.d.ts +2 -0
  45. package/dist/src/events/http/pikku-command-http-map.js +8 -0
  46. package/dist/src/events/http/pikku-command-http-routes.d.ts +2 -0
  47. package/dist/src/events/http/pikku-command-http-routes.js +9 -0
  48. package/dist/src/events/http/pikku-command-nextjs.d.ts +2 -0
  49. package/dist/src/events/http/pikku-command-nextjs.js +36 -0
  50. package/dist/src/events/http/pikku-command-openapi.d.ts +2 -0
  51. package/dist/src/events/http/pikku-command-openapi.js +20 -0
  52. package/dist/src/events/http/pikku-http-routes.d.ts +2 -0
  53. package/dist/src/events/http/pikku-http-routes.js +9 -0
  54. package/dist/src/{serialize-typed-http-map.js → events/http/serialize-typed-http-map.js} +1 -1
  55. package/dist/src/events/mcp/pikku-command-mcp-json.d.ts +2 -0
  56. package/dist/src/events/mcp/pikku-command-mcp-json.js +13 -0
  57. package/dist/src/events/mcp/pikku-command-mcp.d.ts +2 -0
  58. package/dist/src/events/mcp/pikku-command-mcp.js +54 -0
  59. package/dist/src/events/mcp/serialize-mcp-json.d.ts +5 -0
  60. package/dist/src/events/mcp/serialize-mcp-json.js +101 -0
  61. package/dist/src/events/queue/pikku-command-queue-map.d.ts +2 -0
  62. package/dist/src/events/queue/pikku-command-queue-map.js +8 -0
  63. package/dist/src/events/queue/pikku-command-queue-service.d.ts +2 -0
  64. package/dist/src/events/queue/pikku-command-queue-service.js +12 -0
  65. package/dist/src/events/queue/pikku-command-queue.d.ts +2 -0
  66. package/dist/src/events/queue/pikku-command-queue.js +10 -0
  67. package/dist/src/events/queue/pikku-queue-map.d.ts +2 -0
  68. package/dist/src/events/queue/pikku-queue-map.js +8 -0
  69. package/dist/src/events/queue/pikku-queue.d.ts +2 -0
  70. package/dist/src/events/queue/pikku-queue.js +10 -0
  71. package/dist/src/events/queue/serialize-queue-map.d.ts +4 -0
  72. package/dist/src/events/queue/serialize-queue-map.js +77 -0
  73. package/dist/src/events/queue/serialize-queue-meta.d.ts +2 -0
  74. package/dist/src/events/queue/serialize-queue-meta.js +6 -0
  75. package/dist/src/events/queue/serialize-queue-wrapper.d.ts +1 -0
  76. package/dist/src/events/queue/serialize-queue-wrapper.js +35 -0
  77. package/dist/src/events/rpc/pikku-command-rpc-map.d.ts +2 -0
  78. package/dist/src/events/rpc/pikku-command-rpc-map.js +8 -0
  79. package/dist/src/events/rpc/pikku-command-rpc.d.ts +2 -0
  80. package/dist/src/events/rpc/pikku-command-rpc.js +6 -0
  81. package/dist/src/events/rpc/pikku-rpc.d.ts +2 -0
  82. package/dist/src/events/rpc/pikku-rpc.js +6 -0
  83. package/dist/src/{serialize-typed-rpc-map.d.ts → events/rpc/serialize-typed-rpc-map.d.ts} +1 -1
  84. package/dist/src/{serialize-typed-rpc-map.js → events/rpc/serialize-typed-rpc-map.js} +2 -2
  85. package/dist/src/events/scheduler/pikku-command-scheduler.d.ts +2 -0
  86. package/dist/src/events/scheduler/pikku-command-scheduler.js +10 -0
  87. package/dist/src/inspector-glob.d.ts +1 -1
  88. package/dist/src/inspector-glob.js +3 -3
  89. package/dist/src/pikku-cli-config.d.ts +8 -1
  90. package/dist/src/pikku-cli-config.js +59 -22
  91. package/dist/src/pikku-command-schemas.d.ts +2 -0
  92. package/dist/src/pikku-command-schemas.js +8 -0
  93. package/dist/src/runtimes/nextjs/pikku-command-nextjs.d.ts +2 -0
  94. package/dist/src/runtimes/nextjs/pikku-command-nextjs.js +36 -0
  95. package/dist/src/{serialize-nextjs-http-wrapper.js → runtimes/nextjs/serialize-nextjs-http-wrapper.js} +1 -2
  96. package/dist/src/schema-generator.d.ts +3 -2
  97. package/dist/src/schema-generator.js +7 -7
  98. package/dist/src/schemas.d.ts +2 -0
  99. package/dist/src/schemas.js +8 -0
  100. package/dist/src/{utils/serialize-import-map.js → serialize-import-map.js} +3 -0
  101. package/dist/src/serialize-pikku-types.js +378 -1
  102. package/dist/src/types.d.ts +5 -0
  103. package/dist/src/types.js +1 -0
  104. package/dist/src/{utils/utils.d.ts → utils.d.ts} +17 -7
  105. package/dist/src/{utils/utils.js → utils.js} +47 -29
  106. package/dist/tsconfig.tsbuildinfo +1 -1
  107. package/package.json +3 -3
  108. package/{bin → src/events/channels}/pikku-channels.ts +8 -3
  109. package/src/events/channels/pikku-command-channels-map.ts +26 -0
  110. package/src/events/channels/pikku-command-channels.ts +38 -0
  111. package/src/events/channels/pikku-command-websocket-typed.ts +36 -0
  112. package/src/{serialize-typed-channel-map.ts → events/channels/serialize-typed-channel-map.ts} +2 -2
  113. package/src/events/fetch/index.ts +33 -0
  114. package/src/events/functions/pikku-command-function-types.ts +48 -0
  115. package/src/events/functions/pikku-command-functions.ts +84 -0
  116. package/{bin → src/events/functions}/pikku-function-types.ts +12 -15
  117. package/{bin → src/events/functions}/pikku-functions.ts +9 -6
  118. package/src/events/http/pikku-command-http-map.ts +27 -0
  119. package/src/events/http/pikku-command-http-routes.ts +40 -0
  120. package/src/events/http/pikku-command-nextjs.ts +111 -0
  121. package/src/events/http/pikku-command-openapi.ts +54 -0
  122. package/{bin → src/events/http}/pikku-http-routes.ts +8 -3
  123. package/src/{serialize-typed-http-map.ts → events/http/serialize-typed-http-map.ts} +1 -1
  124. package/src/events/mcp/pikku-command-mcp-json.ts +33 -0
  125. package/src/events/mcp/pikku-command-mcp.ts +110 -0
  126. package/src/events/mcp/serialize-mcp-json.ts +159 -0
  127. package/src/events/queue/pikku-command-queue-map.ts +26 -0
  128. package/src/events/queue/pikku-command-queue-service.ts +33 -0
  129. package/src/events/queue/pikku-command-queue.ts +42 -0
  130. package/src/events/queue/pikku-queue-map.ts +26 -0
  131. package/src/events/queue/pikku-queue.ts +40 -0
  132. package/src/events/queue/serialize-queue-map.ts +119 -0
  133. package/src/events/queue/serialize-queue-meta.ts +10 -0
  134. package/src/events/queue/serialize-queue-wrapper.ts +35 -0
  135. package/src/events/rpc/pikku-command-rpc-map.ts +26 -0
  136. package/src/events/rpc/pikku-command-rpc.ts +22 -0
  137. package/{bin → src/events/rpc}/pikku-rpc.ts +8 -6
  138. package/src/{serialize-typed-rpc-map.ts → events/rpc/serialize-typed-rpc-map.ts} +4 -3
  139. package/{bin/pikku-scheduler.ts → src/events/scheduler/pikku-command-scheduler.ts} +11 -8
  140. package/src/inspector-glob.ts +3 -1
  141. package/src/pikku-cli-config.ts +93 -32
  142. package/src/pikku-command-schemas.ts +33 -0
  143. package/src/runtimes/nextjs/pikku-command-nextjs.ts +110 -0
  144. package/src/{serialize-nextjs-http-wrapper.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.ts} +1 -2
  145. package/src/schema-generator.ts +8 -3
  146. package/src/schemas.ts +33 -0
  147. package/src/{utils/serialize-import-map.ts → serialize-import-map.ts} +5 -0
  148. package/src/serialize-pikku-types.ts +378 -1
  149. package/src/types.ts +16 -0
  150. package/src/{utils/utils.ts → utils.ts} +55 -31
  151. package/tsconfig.json +1 -1
  152. package/bin/pikku-channels-map.ts +0 -25
  153. package/bin/pikku-http-map.ts +0 -26
  154. package/bin/pikku-nextjs.test.ts +0 -279
  155. package/bin/pikku-rpc-map.ts +0 -25
  156. package/dist/bin/pikku-channels-map.d.ts +0 -3
  157. package/dist/bin/pikku-channels-map.js +0 -8
  158. package/dist/bin/pikku-channels.d.ts +0 -3
  159. package/dist/bin/pikku-channels.js +0 -9
  160. package/dist/bin/pikku-function-types.d.ts +0 -4
  161. package/dist/bin/pikku-functions.d.ts +0 -7
  162. package/dist/bin/pikku-http-map.d.ts +0 -3
  163. package/dist/bin/pikku-http-map.js +0 -8
  164. package/dist/bin/pikku-http-routes.d.ts +0 -3
  165. package/dist/bin/pikku-http-routes.js +0 -9
  166. package/dist/bin/pikku-rpc-map.d.ts +0 -3
  167. package/dist/bin/pikku-rpc-map.js +0 -8
  168. package/dist/bin/pikku-rpc.d.ts +0 -3
  169. package/dist/bin/pikku-rpc.js +0 -6
  170. package/dist/bin/pikku-scheduler.d.ts +0 -3
  171. package/dist/bin/pikku-scheduler.js +0 -10
  172. /package/dist/src/{serialize-typed-channel-map.d.ts → events/channels/serialize-typed-channel-map.d.ts} +0 -0
  173. /package/dist/src/{serialize-websocket-wrapper.d.ts → events/channels/serialize-websocket-wrapper.d.ts} +0 -0
  174. /package/dist/src/{serialize-websocket-wrapper.js → events/channels/serialize-websocket-wrapper.js} +0 -0
  175. /package/dist/src/{openapi-spec-generator.d.ts → events/http/openapi-spec-generator.d.ts} +0 -0
  176. /package/dist/src/{openapi-spec-generator.js → events/http/openapi-spec-generator.js} +0 -0
  177. /package/dist/src/{serialize-fetch-wrapper.d.ts → events/http/serialize-fetch-wrapper.d.ts} +0 -0
  178. /package/dist/src/{serialize-fetch-wrapper.js → events/http/serialize-fetch-wrapper.js} +0 -0
  179. /package/dist/src/{serialize-typed-http-map.d.ts → events/http/serialize-typed-http-map.d.ts} +0 -0
  180. /package/dist/src/{serialize-scheduler-meta.d.ts → events/scheduler/serialize-scheduler-meta.d.ts} +0 -0
  181. /package/dist/src/{serialize-scheduler-meta.js → events/scheduler/serialize-scheduler-meta.js} +0 -0
  182. /package/dist/src/{serialize-nextjs-backend-wrapper.d.ts → runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts} +0 -0
  183. /package/dist/src/{serialize-nextjs-backend-wrapper.js → runtimes/nextjs/serialize-nextjs-backend-wrapper.js} +0 -0
  184. /package/dist/src/{serialize-nextjs-http-wrapper.d.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.d.ts} +0 -0
  185. /package/dist/src/{utils/serialize-import-map.d.ts → serialize-import-map.d.ts} +0 -0
  186. /package/src/{serialize-websocket-wrapper.ts → events/channels/serialize-websocket-wrapper.ts} +0 -0
  187. /package/src/{openapi-spec-generator.ts → events/http/openapi-spec-generator.ts} +0 -0
  188. /package/src/{serialize-fetch-wrapper.ts → events/http/serialize-fetch-wrapper.ts} +0 -0
  189. /package/src/{serialize-scheduler-meta.ts → events/scheduler/serialize-scheduler-meta.ts} +0 -0
  190. /package/src/{serialize-nextjs-backend-wrapper.ts → runtimes/nextjs/serialize-nextjs-backend-wrapper.ts} +0 -0
@@ -1,17 +1,19 @@
1
- import { PikkuCLIConfig } from '../src/pikku-cli-config.js'
2
- import { InspectorState } from '@pikku/inspector'
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
- { rpcMetaFile }: PikkuCLIConfig,
7
- { rpc }: InspectorState
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 { serializeImportMap } from './utils/serialize-import-map.js'
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 './utils/utils.js'
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 '../src/utils/utils.js'
8
- import { serializeSchedulerMeta } from '../src/serialize-scheduler-meta.js'
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
- cliConfig: PikkuCLIConfig,
12
- visitState: InspectorState
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
- 'addSerializedTasks',
31
+ 'addScheduledTasks',
29
32
  schedulersFile,
30
33
  scheduledTasks.files,
31
34
  packageMappings
@@ -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/utils.js'
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],
@@ -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, 'pikku-schemas')
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.rpcMetaFile) {
158
- result.rpcMetaFile = join(result.outDir, 'pikku-rpc-meta.gen.ts')
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(result.outDir, 'pikku-http-routes.gen.ts')
188
+ result.httpRoutesFile = join(httpDir, 'pikku-http-routes.gen.ts')
168
189
  }
169
190
  if (!result.httpRoutesMetaFile) {
170
191
  result.httpRoutesMetaFile = join(
171
- result.outDir,
192
+ httpDir,
172
193
  'pikku-http-routes-meta.gen.ts'
173
194
  )
174
195
  }
175
- if (!result.schedulersFile) {
176
- result.schedulersFile = join(result.outDir, 'pikku-schedules.gen.ts')
177
- }
178
- if (!result.schedulersMetaFile) {
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(result.outDir, 'pikku-channels.gen.ts')
205
+ result.channelsFile = join(channelsDir, 'pikku-channels.gen.ts')
186
206
  }
187
207
  if (!result.channelsMetaFile) {
188
208
  result.channelsMetaFile = join(
189
- result.outDir,
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
- result.outDir,
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
- result.outDir,
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
+ }
@@ -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
  *
@@ -1,11 +1,12 @@
1
1
  import { createGenerator, RootlessError } from 'ts-json-schema-generator'
2
- import { logInfo, writeFileInDir } from './utils/utils.js'
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
- logInfo(`• Skipping schemas since none found.\x1b[0m`)
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
+ }
@@ -16,6 +16,11 @@ export const serializeImportMap = (
16
16
  return
17
17
  }
18
18
  const variables = paths.get(path) || []
19
+
20
+ if (uniqueName === '__object') {
21
+ return
22
+ }
23
+
19
24
  if (originalName === uniqueName) {
20
25
  variables.push(originalName)
21
26
  } else {