@pikku/cli 0.7.7 → 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 +14 -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/schema-generator.d.ts +3 -2
  96. package/dist/src/schema-generator.js +7 -7
  97. package/dist/src/schemas.d.ts +2 -0
  98. package/dist/src/schemas.js +8 -0
  99. package/dist/src/{utils/serialize-import-map.js → serialize-import-map.js} +3 -0
  100. package/dist/src/serialize-pikku-types.js +378 -1
  101. package/dist/src/types.d.ts +5 -0
  102. package/dist/src/types.js +1 -0
  103. package/dist/src/{utils/utils.d.ts → utils.d.ts} +17 -7
  104. package/dist/src/{utils/utils.js → utils.js} +47 -29
  105. package/dist/tsconfig.tsbuildinfo +1 -1
  106. package/package.json +3 -3
  107. package/{bin → src/events/channels}/pikku-channels.ts +8 -3
  108. package/src/events/channels/pikku-command-channels-map.ts +26 -0
  109. package/src/events/channels/pikku-command-channels.ts +38 -0
  110. package/src/events/channels/pikku-command-websocket-typed.ts +36 -0
  111. package/src/{serialize-typed-channel-map.ts → events/channels/serialize-typed-channel-map.ts} +2 -2
  112. package/src/events/fetch/index.ts +33 -0
  113. package/src/events/functions/pikku-command-function-types.ts +48 -0
  114. package/src/events/functions/pikku-command-functions.ts +84 -0
  115. package/{bin → src/events/functions}/pikku-function-types.ts +12 -15
  116. package/{bin → src/events/functions}/pikku-functions.ts +9 -6
  117. package/src/events/http/pikku-command-http-map.ts +27 -0
  118. package/src/events/http/pikku-command-http-routes.ts +40 -0
  119. package/src/events/http/pikku-command-nextjs.ts +111 -0
  120. package/src/events/http/pikku-command-openapi.ts +54 -0
  121. package/{bin → src/events/http}/pikku-http-routes.ts +8 -3
  122. package/src/{serialize-typed-http-map.ts → events/http/serialize-typed-http-map.ts} +1 -1
  123. package/src/events/mcp/pikku-command-mcp-json.ts +33 -0
  124. package/src/events/mcp/pikku-command-mcp.ts +110 -0
  125. package/src/events/mcp/serialize-mcp-json.ts +159 -0
  126. package/src/events/queue/pikku-command-queue-map.ts +26 -0
  127. package/src/events/queue/pikku-command-queue-service.ts +33 -0
  128. package/src/events/queue/pikku-command-queue.ts +42 -0
  129. package/src/events/queue/pikku-queue-map.ts +26 -0
  130. package/src/events/queue/pikku-queue.ts +40 -0
  131. package/src/events/queue/serialize-queue-map.ts +119 -0
  132. package/src/events/queue/serialize-queue-meta.ts +10 -0
  133. package/src/events/queue/serialize-queue-wrapper.ts +35 -0
  134. package/src/events/rpc/pikku-command-rpc-map.ts +26 -0
  135. package/src/events/rpc/pikku-command-rpc.ts +22 -0
  136. package/{bin → src/events/rpc}/pikku-rpc.ts +8 -6
  137. package/src/{serialize-typed-rpc-map.ts → events/rpc/serialize-typed-rpc-map.ts} +4 -3
  138. package/{bin/pikku-scheduler.ts → src/events/scheduler/pikku-command-scheduler.ts} +11 -8
  139. package/src/inspector-glob.ts +3 -1
  140. package/src/pikku-cli-config.ts +93 -32
  141. package/src/pikku-command-schemas.ts +33 -0
  142. package/src/runtimes/nextjs/pikku-command-nextjs.ts +110 -0
  143. package/src/schema-generator.ts +8 -3
  144. package/src/schemas.ts +33 -0
  145. package/src/{utils/serialize-import-map.ts → serialize-import-map.ts} +5 -0
  146. package/src/serialize-pikku-types.ts +378 -1
  147. package/src/types.ts +16 -0
  148. package/src/{utils/utils.ts → utils.ts} +55 -31
  149. package/tsconfig.json +1 -1
  150. package/bin/pikku-channels-map.ts +0 -25
  151. package/bin/pikku-http-map.ts +0 -26
  152. package/bin/pikku-nextjs.test.ts +0 -279
  153. package/bin/pikku-rpc-map.ts +0 -25
  154. package/dist/bin/pikku-channels-map.d.ts +0 -3
  155. package/dist/bin/pikku-channels-map.js +0 -8
  156. package/dist/bin/pikku-channels.d.ts +0 -3
  157. package/dist/bin/pikku-channels.js +0 -9
  158. package/dist/bin/pikku-function-types.d.ts +0 -4
  159. package/dist/bin/pikku-functions.d.ts +0 -7
  160. package/dist/bin/pikku-http-map.d.ts +0 -3
  161. package/dist/bin/pikku-http-map.js +0 -8
  162. package/dist/bin/pikku-http-routes.d.ts +0 -3
  163. package/dist/bin/pikku-http-routes.js +0 -9
  164. package/dist/bin/pikku-rpc-map.d.ts +0 -3
  165. package/dist/bin/pikku-rpc-map.js +0 -8
  166. package/dist/bin/pikku-rpc.d.ts +0 -3
  167. package/dist/bin/pikku-rpc.js +0 -6
  168. package/dist/bin/pikku-scheduler.d.ts +0 -3
  169. package/dist/bin/pikku-scheduler.js +0 -10
  170. /package/dist/src/{serialize-typed-channel-map.d.ts → events/channels/serialize-typed-channel-map.d.ts} +0 -0
  171. /package/dist/src/{serialize-websocket-wrapper.d.ts → events/channels/serialize-websocket-wrapper.d.ts} +0 -0
  172. /package/dist/src/{serialize-websocket-wrapper.js → events/channels/serialize-websocket-wrapper.js} +0 -0
  173. /package/dist/src/{openapi-spec-generator.d.ts → events/http/openapi-spec-generator.d.ts} +0 -0
  174. /package/dist/src/{openapi-spec-generator.js → events/http/openapi-spec-generator.js} +0 -0
  175. /package/dist/src/{serialize-fetch-wrapper.d.ts → events/http/serialize-fetch-wrapper.d.ts} +0 -0
  176. /package/dist/src/{serialize-fetch-wrapper.js → events/http/serialize-fetch-wrapper.js} +0 -0
  177. /package/dist/src/{serialize-typed-http-map.d.ts → events/http/serialize-typed-http-map.d.ts} +0 -0
  178. /package/dist/src/{serialize-scheduler-meta.d.ts → events/scheduler/serialize-scheduler-meta.d.ts} +0 -0
  179. /package/dist/src/{serialize-scheduler-meta.js → events/scheduler/serialize-scheduler-meta.js} +0 -0
  180. /package/dist/src/{serialize-nextjs-backend-wrapper.d.ts → runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts} +0 -0
  181. /package/dist/src/{serialize-nextjs-backend-wrapper.js → runtimes/nextjs/serialize-nextjs-backend-wrapper.js} +0 -0
  182. /package/dist/src/{serialize-nextjs-http-wrapper.d.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.d.ts} +0 -0
  183. /package/dist/src/{serialize-nextjs-http-wrapper.js → runtimes/nextjs/serialize-nextjs-http-wrapper.js} +0 -0
  184. /package/dist/src/{utils/serialize-import-map.d.ts → serialize-import-map.d.ts} +0 -0
  185. /package/src/{serialize-websocket-wrapper.ts → events/channels/serialize-websocket-wrapper.ts} +0 -0
  186. /package/src/{openapi-spec-generator.ts → events/http/openapi-spec-generator.ts} +0 -0
  187. /package/src/{serialize-fetch-wrapper.ts → events/http/serialize-fetch-wrapper.ts} +0 -0
  188. /package/src/{serialize-scheduler-meta.ts → events/scheduler/serialize-scheduler-meta.ts} +0 -0
  189. /package/src/{serialize-nextjs-backend-wrapper.ts → runtimes/nextjs/serialize-nextjs-backend-wrapper.ts} +0 -0
  190. /package/src/{serialize-nextjs-http-wrapper.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.ts} +0 -0
@@ -0,0 +1,35 @@
1
+ export const serializeQueueWrapper = (queueMapPath) => {
2
+ return `
3
+ import type { QueueService, QueueJob } from '@pikku/core/queue'
4
+ import type { QueueMap, TypedPikkuQueue } from '${queueMapPath}'
5
+
6
+ export class PikkuQueue implements TypedPikkuQueue {
7
+ constructor(private queueService: QueueService) {}
8
+
9
+ public async add<Name extends keyof QueueMap>(
10
+ queueName: Name,
11
+ data: QueueMap[Name]['input'],
12
+ options?: {
13
+ priority?: number
14
+ delay?: number
15
+ attempts?: number
16
+ removeOnComplete?: number
17
+ removeOnFail?: number
18
+ jobId?: string
19
+ }
20
+ ): Promise<string> {
21
+ return this.queueService.add(queueName as string, data, options);
22
+ }
23
+
24
+ public async getJob<Name extends keyof QueueMap>(
25
+ queueName: Name,
26
+ jobId: string
27
+ ): Promise<QueueJob<QueueMap[Name]['input'], QueueMap[Name]['output']> | null> {
28
+ return this.queueService.getJob<QueueMap[Name]['input'], QueueMap[Name]['output']>(
29
+ queueName as string,
30
+ jobId
31
+ );
32
+ }
33
+ }
34
+ `;
35
+ };
@@ -0,0 +1,2 @@
1
+ import { PikkuCommand } from '../../types.js';
2
+ export declare const pikkuRPCMap: PikkuCommand;
@@ -0,0 +1,8 @@
1
+ import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
2
+ import { serializeTypedRPCMap } from './serialize-typed-rpc-map.js';
3
+ export const pikkuRPCMap = async (logger, { rpcMapDeclarationFile, packageMappings }, { functions, rpc }) => {
4
+ return await logCommandInfoAndTime(logger, 'Creating RPC map', 'Created RPC map', [false], async () => {
5
+ const content = serializeTypedRPCMap(rpcMapDeclarationFile, packageMappings, functions.typesMap, functions.meta, rpc.meta);
6
+ await writeFileInDir(logger, rpcMapDeclarationFile, content);
7
+ });
8
+ };
@@ -0,0 +1,2 @@
1
+ import { PikkuCommand } from '../../types.js';
2
+ export declare const pikkuRPC: PikkuCommand;
@@ -0,0 +1,6 @@
1
+ import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
2
+ export const pikkuRPC = async (logger, { rpcMetaFile }, { rpc }) => {
3
+ return await logCommandInfoAndTime(logger, 'Finding RPCs tasks', 'Found RPCs', [false], async () => {
4
+ await writeFileInDir(logger, rpcMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`);
5
+ });
6
+ };
@@ -0,0 +1,2 @@
1
+ import { PikkuCommand } from '../../types.js';
2
+ export declare const pikkuRPC: PikkuCommand;
@@ -0,0 +1,6 @@
1
+ import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
2
+ export const pikkuRPC = async (logger, { rpcMetaFile }, { rpc }) => {
3
+ return await logCommandInfoAndTime(logger, 'Finding RPCs tasks', 'Found RPCs', [false], async () => {
4
+ await writeFileInDir(logger, rpcMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`);
5
+ });
6
+ };
@@ -1,4 +1,4 @@
1
+ import type { RPCMeta } from '@pikku/core/rpc';
1
2
  import { TypesMap } from '@pikku/inspector';
2
3
  import { FunctionsMeta } from '@pikku/core';
3
- import { RPCMeta } from '../../core/src/rpc/rpc-types.js';
4
4
  export declare const serializeTypedRPCMap: (relativeToPath: string, packageMappings: Record<string, string>, typesMap: TypesMap, functionsMeta: FunctionsMeta, rpcMeta: Record<string, RPCMeta>) => string;
@@ -1,5 +1,5 @@
1
- import { serializeImportMap } from './utils/serialize-import-map.js';
2
- import { generateCustomTypes } from './utils/utils.js';
1
+ import { serializeImportMap } from '../../serialize-import-map.js';
2
+ import { generateCustomTypes } from '../../utils.js';
3
3
  export const serializeTypedRPCMap = (relativeToPath, packageMappings, typesMap, functionsMeta, rpcMeta) => {
4
4
  const requiredTypes = new Set();
5
5
  const serializedCustomTypes = generateCustomTypes(typesMap, requiredTypes);
@@ -0,0 +1,2 @@
1
+ import { PikkuCommand } from '../../types.js';
2
+ export declare const pikkuScheduler: PikkuCommand;
@@ -0,0 +1,10 @@
1
+ import { logCommandInfoAndTime, serializeFileImports, writeFileInDir, } from '../../utils.js';
2
+ import { serializeSchedulerMeta } from './serialize-scheduler-meta.js';
3
+ export const pikkuScheduler = async (logger, cliConfig, visitState) => {
4
+ return await logCommandInfoAndTime(logger, 'Finding scheduled tasks', 'Found scheduled tasks', [visitState.scheduledTasks.files.size === 0], async () => {
5
+ const { schedulersFile, schedulersMetaFile, packageMappings } = cliConfig;
6
+ const { scheduledTasks } = visitState;
7
+ await writeFileInDir(logger, schedulersMetaFile, serializeSchedulerMeta(scheduledTasks.meta));
8
+ await writeFileInDir(logger, schedulersFile, serializeFileImports('addScheduledTasks', schedulersFile, scheduledTasks.files, packageMappings));
9
+ });
10
+ };
@@ -1,2 +1,2 @@
1
1
  import { InspectorFilters, InspectorState } from '@pikku/inspector';
2
- export declare const inspectorGlob: (rootDir: string, srcDirectories: string[], filters: InspectorFilters) => Promise<InspectorState>;
2
+ export declare const inspectorGlob: (logger: any, rootDir: string, srcDirectories: string[], filters: InspectorFilters) => Promise<InspectorState>;
@@ -1,10 +1,10 @@
1
1
  import * as path from 'path';
2
2
  import { glob } from 'tinyglobby';
3
3
  import { inspect } from '@pikku/inspector';
4
- import { logCommandInfoAndTime } from './utils/utils.js';
5
- export const inspectorGlob = async (rootDir, srcDirectories, filters) => {
4
+ import { logCommandInfoAndTime } from './utils.js';
5
+ export const inspectorGlob = async (logger, rootDir, srcDirectories, filters) => {
6
6
  let result;
7
- await logCommandInfoAndTime('Inspecting codebase', 'Inspected codebase', [false], async () => {
7
+ await logCommandInfoAndTime(logger, 'Inspecting codebase', 'Inspected codebase', [false], async () => {
8
8
  const routeFiles = (await Promise.all(srcDirectories.map((dir) => glob(`${path.join(rootDir, dir)}/**/*.ts`)))).flat();
9
9
  result = await inspect(routeFiles, filters);
10
10
  });
@@ -1,4 +1,4 @@
1
- import { OpenAPISpecInfo } from './openapi-spec-generator.js';
1
+ import { OpenAPISpecInfo } from './events/http/openapi-spec-generator.js';
2
2
  import { InspectorFilters } from '@pikku/inspector';
3
3
  import { PikkuEventTypes } from '@pikku/core';
4
4
  export interface PikkuCLICoreOutputFiles {
@@ -17,6 +17,11 @@ export interface PikkuCLICoreOutputFiles {
17
17
  rpcMapDeclarationFile: string;
18
18
  schedulersFile: string;
19
19
  schedulersMetaFile: string;
20
+ queueWorkersFile: string;
21
+ queueWorkersMetaFile: string;
22
+ queueMapDeclarationFile: string;
23
+ mcpEndpointsFile: string;
24
+ mcpEndpointsMetaFile: string;
20
25
  bootstrapFile: string;
21
26
  bootstrapFiles: Record<PikkuEventTypes, string>;
22
27
  }
@@ -33,6 +38,8 @@ export type PikkuCLIConfig = {
33
38
  nextHTTPFile?: string;
34
39
  fetchFile?: string;
35
40
  websocketFile?: string;
41
+ queueFile?: string;
42
+ mcpJsonFile?: string;
36
43
  openAPI?: {
37
44
  outputFile: string;
38
45
  additionalInfo: OpenAPISpecInfo;
@@ -6,6 +6,8 @@ const CONFIG_DIR_FILES = [
6
6
  'nextHTTPFile',
7
7
  'fetchFile',
8
8
  'websocketFile',
9
+ 'queueFile',
10
+ 'mcpJsonFile',
9
11
  ];
10
12
  export const getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags = [], exitProcess = false) => {
11
13
  const config = await _getPikkuCLIConfig(configFile, requiredFields, tags, exitProcess);
@@ -54,54 +56,89 @@ const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags =
54
56
  };
55
57
  }
56
58
  if (result.outDir) {
59
+ // Create transport/event directories
60
+ const httpDir = join(result.outDir, 'http');
61
+ const channelsDir = join(result.outDir, 'channels');
62
+ const rpcDir = join(result.outDir, 'rpc');
63
+ const schedulerDir = join(result.outDir, 'scheduler');
64
+ const queueDir = join(result.outDir, 'queue');
65
+ const mcpDir = join(result.outDir, 'mcp');
66
+ // Create directories if they don't exist (will be done lazily when files are written)
57
67
  if (!result.schemaDirectory) {
58
- result.schemaDirectory = join(result.outDir, 'pikku-schemas');
68
+ result.schemaDirectory = join(result.outDir, 'schemas');
59
69
  }
70
+ // Functions
60
71
  if (!result.functionsFile) {
61
72
  result.functionsFile = join(result.outDir, 'pikku-functions.gen.ts');
62
73
  }
63
74
  if (!result.functionsMetaFile) {
64
75
  result.functionsMetaFile = join(result.outDir, 'pikku-functions-meta.gen.ts');
65
76
  }
66
- if (!result.rpcMetaFile) {
67
- result.rpcMetaFile = join(result.outDir, 'pikku-rpc-meta.gen.ts');
68
- }
69
- if (!result.rpcMapDeclarationFile) {
70
- result.rpcMapDeclarationFile = join(result.outDir, 'pikku-rpc-map.gen.ts');
77
+ if (!result.typesDeclarationFile) {
78
+ result.typesDeclarationFile = join(result.outDir, 'pikku-types.gen.ts');
71
79
  }
80
+ // HTTP
72
81
  if (!result.httpRoutesFile) {
73
- result.httpRoutesFile = join(result.outDir, 'pikku-http-routes.gen.ts');
82
+ result.httpRoutesFile = join(httpDir, 'pikku-http-routes.gen.ts');
74
83
  }
75
84
  if (!result.httpRoutesMetaFile) {
76
- result.httpRoutesMetaFile = join(result.outDir, 'pikku-http-routes-meta.gen.ts');
77
- }
78
- if (!result.schedulersFile) {
79
- result.schedulersFile = join(result.outDir, 'pikku-schedules.gen.ts');
85
+ result.httpRoutesMetaFile = join(httpDir, 'pikku-http-routes-meta.gen.ts');
80
86
  }
81
- if (!result.schedulersMetaFile) {
82
- result.schedulersMetaFile = join(result.outDir, 'pikku-schedules-meta.gen.ts');
87
+ if (!result.httpRoutesMapDeclarationFile) {
88
+ result.httpRoutesMapDeclarationFile = join(httpDir, 'pikku-http-routes-map.gen.d.ts');
83
89
  }
90
+ // Channels/WebSocket
84
91
  if (!result.channelsFile) {
85
- result.channelsFile = join(result.outDir, 'pikku-channels.gen.ts');
92
+ result.channelsFile = join(channelsDir, 'pikku-channels.gen.ts');
86
93
  }
87
94
  if (!result.channelsMetaFile) {
88
- result.channelsMetaFile = join(result.outDir, 'pikku-channels-meta.gen.ts');
95
+ result.channelsMetaFile = join(channelsDir, 'pikku-channels-meta.gen.ts');
89
96
  }
90
- if (!result.typesDeclarationFile) {
91
- result.typesDeclarationFile = join(result.outDir, 'pikku-types.gen.ts');
97
+ if (!result.channelsMapDeclarationFile) {
98
+ result.channelsMapDeclarationFile = join(channelsDir, 'pikku-channels-map.gen.d.ts');
92
99
  }
93
- if (!result.httpRoutesMapDeclarationFile) {
94
- result.httpRoutesMapDeclarationFile = join(result.outDir, 'pikku-http-routes-map.gen.d.ts');
100
+ // RPC
101
+ if (!result.rpcMetaFile) {
102
+ result.rpcMetaFile = join(rpcDir, 'pikku-rpc-meta.gen.ts');
95
103
  }
96
- if (!result.channelsMapDeclarationFile) {
97
- result.channelsMapDeclarationFile = join(result.outDir, 'pikku-channels-map.gen.d.ts');
104
+ if (!result.rpcMapDeclarationFile) {
105
+ result.rpcMapDeclarationFile = join(rpcDir, 'pikku-rpc-map.gen.ts');
106
+ }
107
+ // Scheduler
108
+ if (!result.schedulersFile) {
109
+ result.schedulersFile = join(schedulerDir, 'pikku-schedules.gen.ts');
110
+ }
111
+ if (!result.schedulersMetaFile) {
112
+ result.schedulersMetaFile = join(schedulerDir, 'pikku-schedules-meta.gen.ts');
98
113
  }
114
+ // Queue
115
+ if (!result.queueWorkersFile) {
116
+ result.queueWorkersFile = join(queueDir, 'pikku-queue-workers.gen.ts');
117
+ }
118
+ if (!result.queueWorkersMetaFile) {
119
+ result.queueWorkersMetaFile = join(queueDir, 'pikku-queue-workers-meta.gen.ts');
120
+ }
121
+ if (!result.queueMapDeclarationFile) {
122
+ result.queueMapDeclarationFile = join(queueDir, 'pikku-queue-map.gen.ts');
123
+ }
124
+ // Bootstrap files
99
125
  if (!result.bootstrapFile) {
100
126
  result.bootstrapFile = join(result.outDir, 'pikku-bootstrap.gen.ts');
101
127
  }
128
+ // MCP
129
+ if (!result.mcpEndpointsMetaFile) {
130
+ result.mcpEndpointsMetaFile = join(mcpDir, 'mcp-endpoints-meta.gen.ts');
131
+ }
132
+ if (!result.mcpEndpointsFile) {
133
+ result.mcpEndpointsFile = join(mcpDir, 'mcp-endpoints.gen.ts');
134
+ }
135
+ if (!result.mcpJsonFile) {
136
+ result.mcpJsonFile = join(mcpDir, 'mcp.gen.json');
137
+ }
102
138
  result.bootstrapFiles = result.bootstrapFiles || {};
103
139
  for (const key of Object.keys(PikkuEventTypes)) {
104
- result.bootstrapFiles[key] = join(result.outDir, `pikku-bootstrap-${key}.gen.ts`);
140
+ const eventDir = join(result.outDir, key.toLowerCase());
141
+ result.bootstrapFiles[key] = join(eventDir, `pikku-bootstrap-${key}.gen.ts`);
105
142
  }
106
143
  }
107
144
  if (requiredFields.length > 0) {
@@ -0,0 +1,2 @@
1
+ import { PikkuCommand } from './types.js';
2
+ export declare const pikkuSchemas: PikkuCommand;
@@ -0,0 +1,8 @@
1
+ import { generateSchemas, saveSchemas } from './schema-generator.js';
2
+ import { logCommandInfoAndTime } from './utils.js';
3
+ export const pikkuSchemas = async (logger, { tsconfig, schemaDirectory, supportsImportAttributes }, { functions, http }) => {
4
+ return await logCommandInfoAndTime(logger, 'Creating schemas', 'Created schemas', [false], async () => {
5
+ const schemas = await generateSchemas(logger, tsconfig, functions.typesMap, functions.meta, http.meta);
6
+ await saveSchemas(logger, schemaDirectory, schemas, functions.typesMap, functions.meta, supportsImportAttributes);
7
+ });
8
+ };
@@ -0,0 +1,2 @@
1
+ import { PikkuCommand } from '../../types.js';
2
+ export declare const pikkuNext: PikkuCommand;
@@ -0,0 +1,36 @@
1
+ import { logCommandInfoAndTime, getPikkuFilesAndMethods, getFileImportRelativePath, writeFileInDir, } from '../../utils.js';
2
+ import { serializeNextJsBackendWrapper as serializeNextBackendWrapper } from './serialize-nextjs-backend-wrapper.js';
3
+ import { serializeNextJsHTTPWrapper as serializeNextHTTPWrapper } from './serialize-nextjs-http-wrapper.js';
4
+ export const pikkuNext = async (logger, { nextBackendFile, nextHTTPFile, httpRoutesMapDeclarationFile, packageMappings, fetchFile, bootstrapFiles, }, visitState, options = {}) => {
5
+ return await logCommandInfoAndTime(logger, 'Generating nextjs wrapper', 'Generated nextjs wrapper', [
6
+ nextBackendFile === undefined && nextHTTPFile === undefined,
7
+ 'nextjs outfile is not defined',
8
+ ], async () => {
9
+ if (!nextBackendFile && !nextHTTPFile) {
10
+ throw new Error('nextBackendFile or nextHTTPFile is required in pikku config for nextJS');
11
+ }
12
+ if (nextHTTPFile && !fetchFile) {
13
+ throw new Error('fetchFile is required in pikku config in order for nextJS http wrapper to work');
14
+ }
15
+ if (nextBackendFile) {
16
+ const { pikkuConfigFactory, singletonServicesFactory, sessionServicesFactory, } = await getPikkuFilesAndMethods(logger, visitState, packageMappings, nextBackendFile, options, {
17
+ config: true,
18
+ singletonServicesFactory: true,
19
+ sessionServicesFactory: true,
20
+ });
21
+ const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextBackendFile, pikkuConfigFactory.file, packageMappings)}'`;
22
+ const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextBackendFile, singletonServicesFactory.file, packageMappings)}'`;
23
+ const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextBackendFile, sessionServicesFactory.file, packageMappings)}'`;
24
+ const httpBootstrapPath = getFileImportRelativePath(nextBackendFile, bootstrapFiles.http, packageMappings);
25
+ const routesMapDeclarationPath = getFileImportRelativePath(nextBackendFile, httpRoutesMapDeclarationFile, packageMappings);
26
+ const content = serializeNextBackendWrapper(httpBootstrapPath, routesMapDeclarationPath, pikkuConfigImport, singletonServicesImport, sessionServicesImport);
27
+ await writeFileInDir(logger, nextBackendFile, content);
28
+ }
29
+ if (nextHTTPFile && fetchFile) {
30
+ const routesMapDeclarationPath = getFileImportRelativePath(nextHTTPFile, httpRoutesMapDeclarationFile, packageMappings);
31
+ const fetchPath = getFileImportRelativePath(nextHTTPFile, fetchFile, packageMappings);
32
+ const content = serializeNextHTTPWrapper(routesMapDeclarationPath, fetchPath);
33
+ await writeFileInDir(logger, nextHTTPFile, content);
34
+ }
35
+ });
36
+ };
@@ -1,5 +1,6 @@
1
+ import { CLILogger } from './utils.js';
1
2
  import { FunctionsMeta, JSONValue } from '@pikku/core';
2
3
  import { HTTPRoutesMeta } from '@pikku/core/http';
3
4
  import { TypesMap } from '@pikku/inspector';
4
- export declare function generateSchemas(tsconfig: string, typesMap: TypesMap, functionMeta: FunctionsMeta, httpRoutesMeta: HTTPRoutesMeta): Promise<Record<string, JSONValue>>;
5
- export declare function saveSchemas(schemaParentDir: string, schemas: Record<string, JSONValue>, typesMap: TypesMap, functionsMeta: FunctionsMeta, supportsImportAttributes: boolean): Promise<void>;
5
+ export declare function generateSchemas(logger: CLILogger, tsconfig: string, typesMap: TypesMap, functionMeta: FunctionsMeta, httpRoutesMeta: HTTPRoutesMeta): Promise<Record<string, JSONValue>>;
6
+ export declare function saveSchemas(logger: CLILogger, schemaParentDir: string, schemas: Record<string, JSONValue>, typesMap: TypesMap, functionsMeta: FunctionsMeta, supportsImportAttributes: boolean): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { createGenerator, RootlessError } from 'ts-json-schema-generator';
2
- import { logInfo, writeFileInDir } from './utils/utils.js';
2
+ import { writeFileInDir } from './utils.js';
3
3
  import { mkdir, writeFile } from 'fs/promises';
4
- export async function generateSchemas(tsconfig, typesMap, functionMeta, httpRoutesMeta) {
4
+ export async function generateSchemas(logger, tsconfig, typesMap, functionMeta, httpRoutesMeta) {
5
5
  const schemasSet = new Set(typesMap.customTypes.keys());
6
6
  for (const { inputs, outputs } of Object.values(functionMeta)) {
7
7
  const types = [...(inputs || []), ...(outputs || [])];
@@ -51,8 +51,8 @@ export async function generateSchemas(tsconfig, typesMap, functionMeta, httpRout
51
51
  });
52
52
  return schemas;
53
53
  }
54
- export async function saveSchemas(schemaParentDir, schemas, typesMap, functionsMeta, supportsImportAttributes) {
55
- await writeFileInDir(`${schemaParentDir}/register.gen.ts`, 'export const empty = null;');
54
+ export async function saveSchemas(logger, schemaParentDir, schemas, typesMap, functionsMeta, supportsImportAttributes) {
55
+ await writeFileInDir(logger, `${schemaParentDir}/register.gen.ts`, 'export const empty = null;');
56
56
  const desiredSchemas = new Set([
57
57
  ...Object.values(functionsMeta)
58
58
  .map(({ inputs, outputs }) => [
@@ -65,7 +65,7 @@ export async function saveSchemas(schemaParentDir, schemas, typesMap, functionsM
65
65
  ...typesMap.customTypes.keys(),
66
66
  ]);
67
67
  if (desiredSchemas.size === 0) {
68
- logInfo(`• Skipping schemas since none found.\x1b[0m`);
68
+ logger.info(`• Skipping schemas since none found.\x1b[0m`);
69
69
  return;
70
70
  }
71
71
  await mkdir(`${schemaParentDir}/schemas`, { recursive: true });
@@ -80,6 +80,6 @@ import * as ${schema} from './schemas/${schema}.schema.json' ${supportsImportAtt
80
80
  addSchema('${schema}', ${schema})
81
81
  `)
82
82
  .join('\n');
83
- await writeFileInDir(`${schemaParentDir}/register.gen.ts`, `import { addSchema } from '@pikku/core/schema'
84
- ${schemaImports}`);
83
+ await writeFileInDir(logger, `${schemaParentDir}/register.gen.ts`, `import { addSchema } from '@pikku/core/schema'
84
+ ${schemaImports}`, { logWrite: true });
85
85
  }
@@ -0,0 +1,2 @@
1
+ import { PikkuCommand } from './types.js';
2
+ export declare const pikkuSchemas: PikkuCommand;
@@ -0,0 +1,8 @@
1
+ import { saveSchemas, generateSchemas } from './schema-generator.js';
2
+ import { logCommandInfoAndTime } from './utils.js';
3
+ export const pikkuSchemas = async (logger, { tsconfig, schemaDirectory, supportsImportAttributes }, { functions, http }) => {
4
+ return await logCommandInfoAndTime(logger, 'Creating schemas', 'Created schemas', [false], async () => {
5
+ const schemas = await generateSchemas(logger, tsconfig, functions.typesMap, functions.meta, http.meta);
6
+ await saveSchemas(logger, schemaDirectory, schemas, functions.typesMap, functions.meta, supportsImportAttributes);
7
+ });
8
+ };
@@ -8,6 +8,9 @@ export const serializeImportMap = (relativeToPath, packageMappings, typesMap, re
8
8
  return;
9
9
  }
10
10
  const variables = paths.get(path) || [];
11
+ if (uniqueName === '__object') {
12
+ return;
13
+ }
11
14
  if (originalName === uniqueName) {
12
15
  variables.push(originalName);
13
16
  }