@pikku/cli 0.9.0 → 0.9.2

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 (96) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/bin/pikku-all.ts +9 -4
  3. package/bin/pikku-nextjs.ts +3 -3
  4. package/dist/bin/pikku-all.js +9 -4
  5. package/dist/bin/pikku-nextjs.js +3 -3
  6. package/dist/bin/pikku.js +0 -0
  7. package/dist/src/serialize-pikku-types.js +28 -25
  8. package/dist/src/utils.d.ts +5 -1
  9. package/dist/src/utils.js +17 -6
  10. package/dist/src/wirings/rpc/pikku-command-rpc-client.js +1 -1
  11. package/dist/tsconfig.tsbuildinfo +1 -1
  12. package/package.json +11 -11
  13. package/src/serialize-pikku-types.ts +28 -25
  14. package/src/utils.ts +26 -6
  15. package/src/wirings/rpc/pikku-command-rpc-client.ts +1 -1
  16. package/dist/src/events/channels/pikku-channels.d.ts +0 -2
  17. package/dist/src/events/channels/pikku-channels.js +0 -9
  18. package/dist/src/events/channels/pikku-command-channels-map.d.ts +0 -2
  19. package/dist/src/events/channels/pikku-command-channels-map.js +0 -8
  20. package/dist/src/events/channels/pikku-command-channels.d.ts +0 -2
  21. package/dist/src/events/channels/pikku-command-channels.js +0 -9
  22. package/dist/src/events/channels/pikku-command-websocket-typed.d.ts +0 -2
  23. package/dist/src/events/channels/pikku-command-websocket-typed.js +0 -15
  24. package/dist/src/events/channels/serialize-typed-channel-map.d.ts +0 -4
  25. package/dist/src/events/channels/serialize-typed-channel-map.js +0 -111
  26. package/dist/src/events/channels/serialize-websocket-wrapper.d.ts +0 -1
  27. package/dist/src/events/channels/serialize-websocket-wrapper.js +0 -75
  28. package/dist/src/events/fetch/index.d.ts +0 -2
  29. package/dist/src/events/fetch/index.js +0 -12
  30. package/dist/src/events/functions/pikku-command-function-types.d.ts +0 -2
  31. package/dist/src/events/functions/pikku-command-function-types.js +0 -13
  32. package/dist/src/events/functions/pikku-command-functions.d.ts +0 -6
  33. package/dist/src/events/functions/pikku-command-functions.js +0 -35
  34. package/dist/src/events/functions/pikku-command-services.d.ts +0 -3
  35. package/dist/src/events/functions/pikku-command-services.js +0 -73
  36. package/dist/src/events/functions/pikku-function-types.d.ts +0 -2
  37. package/dist/src/events/functions/pikku-function-types.js +0 -13
  38. package/dist/src/events/functions/pikku-functions.d.ts +0 -6
  39. package/dist/src/events/functions/pikku-functions.js +0 -35
  40. package/dist/src/events/http/openapi-spec-generator.d.ts +0 -79
  41. package/dist/src/events/http/openapi-spec-generator.js +0 -145
  42. package/dist/src/events/http/pikku-command-http-map.d.ts +0 -2
  43. package/dist/src/events/http/pikku-command-http-map.js +0 -8
  44. package/dist/src/events/http/pikku-command-http-routes.d.ts +0 -2
  45. package/dist/src/events/http/pikku-command-http-routes.js +0 -9
  46. package/dist/src/events/http/pikku-command-nextjs.d.ts +0 -2
  47. package/dist/src/events/http/pikku-command-nextjs.js +0 -36
  48. package/dist/src/events/http/pikku-command-openapi.d.ts +0 -2
  49. package/dist/src/events/http/pikku-command-openapi.js +0 -20
  50. package/dist/src/events/http/pikku-http-routes.d.ts +0 -2
  51. package/dist/src/events/http/pikku-http-routes.js +0 -9
  52. package/dist/src/events/http/serialize-fetch-wrapper.d.ts +0 -1
  53. package/dist/src/events/http/serialize-fetch-wrapper.js +0 -67
  54. package/dist/src/events/http/serialize-typed-http-map.d.ts +0 -4
  55. package/dist/src/events/http/serialize-typed-http-map.js +0 -100
  56. package/dist/src/events/mcp/pikku-command-mcp-json.d.ts +0 -2
  57. package/dist/src/events/mcp/pikku-command-mcp-json.js +0 -13
  58. package/dist/src/events/mcp/pikku-command-mcp.d.ts +0 -2
  59. package/dist/src/events/mcp/pikku-command-mcp.js +0 -54
  60. package/dist/src/events/mcp/serialize-mcp-json.d.ts +0 -5
  61. package/dist/src/events/mcp/serialize-mcp-json.js +0 -101
  62. package/dist/src/events/queue/pikku-command-queue-map.d.ts +0 -2
  63. package/dist/src/events/queue/pikku-command-queue-map.js +0 -8
  64. package/dist/src/events/queue/pikku-command-queue-service.d.ts +0 -2
  65. package/dist/src/events/queue/pikku-command-queue-service.js +0 -12
  66. package/dist/src/events/queue/pikku-command-queue.d.ts +0 -2
  67. package/dist/src/events/queue/pikku-command-queue.js +0 -10
  68. package/dist/src/events/queue/pikku-queue-map.d.ts +0 -2
  69. package/dist/src/events/queue/pikku-queue-map.js +0 -8
  70. package/dist/src/events/queue/pikku-queue.d.ts +0 -2
  71. package/dist/src/events/queue/pikku-queue.js +0 -10
  72. package/dist/src/events/queue/serialize-queue-map.d.ts +0 -4
  73. package/dist/src/events/queue/serialize-queue-map.js +0 -77
  74. package/dist/src/events/queue/serialize-queue-meta.d.ts +0 -2
  75. package/dist/src/events/queue/serialize-queue-meta.js +0 -6
  76. package/dist/src/events/queue/serialize-queue-wrapper.d.ts +0 -1
  77. package/dist/src/events/queue/serialize-queue-wrapper.js +0 -35
  78. package/dist/src/events/rpc/index.d.ts +0 -2
  79. package/dist/src/events/rpc/index.js +0 -12
  80. package/dist/src/events/rpc/pikku-command-rpc-client.d.ts +0 -2
  81. package/dist/src/events/rpc/pikku-command-rpc-client.js +0 -12
  82. package/dist/src/events/rpc/pikku-command-rpc-map.d.ts +0 -2
  83. package/dist/src/events/rpc/pikku-command-rpc-map.js +0 -8
  84. package/dist/src/events/rpc/pikku-command-rpc.d.ts +0 -2
  85. package/dist/src/events/rpc/pikku-command-rpc.js +0 -6
  86. package/dist/src/events/rpc/pikku-rpc.d.ts +0 -2
  87. package/dist/src/events/rpc/pikku-rpc.js +0 -6
  88. package/dist/src/events/rpc/serialize-rpc-wrapper.d.ts +0 -1
  89. package/dist/src/events/rpc/serialize-rpc-wrapper.js +0 -68
  90. package/dist/src/events/rpc/serialize-typed-rpc-map.d.ts +0 -4
  91. package/dist/src/events/rpc/serialize-typed-rpc-map.js +0 -66
  92. package/dist/src/events/scheduler/pikku-command-scheduler.d.ts +0 -2
  93. package/dist/src/events/scheduler/pikku-command-scheduler.js +0 -10
  94. package/dist/src/events/scheduler/serialize-scheduler-meta.d.ts +0 -2
  95. package/dist/src/events/scheduler/serialize-scheduler-meta.js +0 -10
  96. package/lcov.info +0 -582
@@ -1,2 +0,0 @@
1
- import { queueWorkersMeta } from '@pikku/core';
2
- export declare const serializeQueueMeta: (queueWorkersMeta: queueWorkersMeta) => string;
@@ -1,6 +0,0 @@
1
- export const serializeQueueMeta = (queueWorkersMeta) => {
2
- const serializedOutput = [];
3
- serializedOutput.push("import { pikkuState } from '@pikku/core'");
4
- serializedOutput.push(`pikkuState('queue', 'meta', ${JSON.stringify(queueWorkersMeta, null, 2)})`);
5
- return serializedOutput.join('\n');
6
- };
@@ -1 +0,0 @@
1
- export declare const serializeQueueWrapper: (queueMapPath: string) => string;
@@ -1,35 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import { PikkuCommandWithoutState } from '../../types.js';
2
- export declare const pikkuRPCClient: PikkuCommandWithoutState;
@@ -1,12 +0,0 @@
1
- import { serializeRPCWrapper } from './serialize-rpc-wrapper.js';
2
- import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
3
- export const pikkuRPCClient = async (logger, { rpcFile, rpcMapDeclarationFile, packageMappings }) => {
4
- return await logCommandInfoAndTime(logger, 'Generating RPC wrapper', 'Generated RPC wrapper', [rpcFile === undefined, "rpcFile isn't set in the pikku config"], async () => {
5
- if (!rpcFile) {
6
- throw new Error("rpcFile isn't set in the pikku config");
7
- }
8
- const rpcMapDeclarationPath = getFileImportRelativePath(rpcFile, rpcMapDeclarationFile, packageMappings);
9
- const content = [serializeRPCWrapper(rpcMapDeclarationPath)];
10
- await writeFileInDir(logger, rpcFile, content.join('\n'));
11
- });
12
- };
@@ -1,2 +0,0 @@
1
- import { PikkuCommandWithoutState } from '../../types.js';
2
- export declare const pikkuRPCClient: PikkuCommandWithoutState;
@@ -1,12 +0,0 @@
1
- import { serializeRPCWrapper } from './serialize-rpc-wrapper.js';
2
- import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
3
- export const pikkuRPCClient = async (logger, { rpcWiringsFile, rpcMapDeclarationFile, packageMappings }) => {
4
- return await logCommandInfoAndTime(logger, 'Generating RPC wrapper', 'Generated RPC wrapper', [rpcWiringsFile === undefined, "rpcWiringsFile isn't set in the pikku config"], async () => {
5
- if (!rpcWiringsFile) {
6
- throw new Error("rpcWiringsFile isn't set in the pikku config");
7
- }
8
- const rpcMapDeclarationPath = getFileImportRelativePath(rpcWiringsFile, rpcMapDeclarationFile, packageMappings);
9
- const content = [serializeRPCWrapper(rpcMapDeclarationPath)];
10
- await writeFileInDir(logger, rpcWiringsFile, content.join('\n'));
11
- });
12
- };
@@ -1,2 +0,0 @@
1
- import { PikkuCommand } from '../../types.js';
2
- export declare const pikkuRPCMap: PikkuCommand;
@@ -1,8 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import { PikkuCommand } from '../../types.js';
2
- export declare const pikkuRPC: PikkuCommand;
@@ -1,6 +0,0 @@
1
- import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
2
- export const pikkuRPC = async (logger, { rpcWiringMetaFile }, { rpc }) => {
3
- return await logCommandInfoAndTime(logger, 'Finding RPCs tasks', 'Found RPCs', [false], async () => {
4
- await writeFileInDir(logger, rpcWiringMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`);
5
- });
6
- };
@@ -1,2 +0,0 @@
1
- import { PikkuCommand } from '../../types.js';
2
- export declare const pikkuRPC: PikkuCommand;
@@ -1,6 +0,0 @@
1
- import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
2
- export const pikkuRPC = async (logger, { rpcWiringMetaFile }, { rpc }) => {
3
- return await logCommandInfoAndTime(logger, 'Finding RPCs tasks', 'Found RPCs', [false], async () => {
4
- await writeFileInDir(logger, rpcWiringMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('rpc', 'meta', ${JSON.stringify(rpc.meta, null, 2)})`);
5
- });
6
- };
@@ -1 +0,0 @@
1
- export declare const serializeRPCWrapper: (rpcMapPath: string) => string;
@@ -1,68 +0,0 @@
1
- export const serializeRPCWrapper = (rpcMapPath) => {
2
- return `
3
- import { PikkuFetch } from "./pikku-fetch.gen.js"
4
- import type { RPCInvoke } from '${rpcMapPath}'
5
-
6
- /**
7
- * PikkuRPC provides a type-safe client for making Remote Procedure Calls (RPC)
8
- * to your Pikku server. It wraps the underlying HTTP client and provides a
9
- * simple interface for invoking server-side functions.
10
- */
11
- export class PikkuRPC {
12
- /** The underlying HTTP client used for making RPC calls */
13
- pikkuFetch = new PikkuFetch()
14
-
15
- /**
16
- * Sets a custom PikkuFetch instance to use for RPC calls.
17
- * This allows you to configure custom settings or use a shared client instance.
18
- *
19
- * @param pikkuFetch - The PikkuFetch instance to use
20
- */
21
- setPikkuFetch(pikkuFetch: PikkuFetch): void {
22
- this.pikkuFetch = pikkuFetch
23
- }
24
-
25
- /**
26
- * Sets the base server URL for all RPC calls.
27
- *
28
- * @param serverUrl - The base URL of your Pikku server (e.g., 'https://api.example.com')
29
- */
30
- setServerUrl(serverUrl: string): void {
31
- this.pikkuFetch.setServerUrl(serverUrl)
32
- }
33
-
34
- /**
35
- * Sets the JWT token for authorization on all RPC calls.
36
- *
37
- * @param jwt - The JWT token to use for authorization, or null to remove authorization
38
- */
39
- setAuthorizationJWT(jwt: string | null): void {
40
- this.pikkuFetch.setAuthorizationJWT(jwt)
41
- }
42
-
43
- /**
44
- * Sets the API key for authorization on all RPC calls.
45
- *
46
- * @param apiKey - The API key to use for authorization, or null to remove the API key
47
- */
48
- setAPIKey(apiKey: string | null): void {
49
- this.pikkuFetch.setAPIKey(apiKey)
50
- }
51
-
52
- /**
53
- * Invokes a remote procedure call on the server.
54
- * This is a generic method that routes to the appropriate server function
55
- * based on the function name and passes the provided data.
56
- *
57
- * @param name - The name of the server function to invoke
58
- * @param data - The data to pass to the server function
59
- * @returns A promise that resolves with the function's return value
60
- */
61
- invoke: RPCInvoke = async (name, data) => {
62
- return await this.pikkuFetch.post('/rpc', { name, data })
63
- }
64
- }
65
-
66
- export const pikkuRPC = new PikkuRPC();
67
- `;
68
- };
@@ -1,4 +0,0 @@
1
- import type { RPCMeta } from '@pikku/core/rpc';
2
- import { TypesMap } from '@pikku/inspector';
3
- import { FunctionsMeta } from '@pikku/core';
4
- export declare const serializeTypedRPCMap: (relativeToPath: string, packageMappings: Record<string, string>, typesMap: TypesMap, functionsMeta: FunctionsMeta, rpcMeta: Record<string, RPCMeta>) => string;
@@ -1,66 +0,0 @@
1
- import { serializeImportMap } from '../../serialize-import-map.js';
2
- import { generateCustomTypes } from '../../utils.js';
3
- export const serializeTypedRPCMap = (relativeToPath, packageMappings, typesMap, functionsMeta, rpcMeta) => {
4
- const requiredTypes = new Set();
5
- const serializedCustomTypes = generateCustomTypes(typesMap, requiredTypes);
6
- const serializedRPCs = generateRPCs(rpcMeta, functionsMeta, typesMap, requiredTypes);
7
- const serializedImportMap = serializeImportMap(relativeToPath, packageMappings, typesMap, requiredTypes);
8
- return `/**
9
- * This provides the structure needed for typescript to be aware of RPCs and their return types
10
- */
11
-
12
- ${serializedImportMap}
13
- ${serializedCustomTypes}
14
-
15
- interface RPCHandler<I, O> {
16
- input: I;
17
- output: O;
18
- }
19
-
20
- ${serializedRPCs}
21
-
22
- export type RPCInvoke = <Name extends keyof RPCMap>(
23
- name: Name,
24
- data: RPCMap[Name]['input'],
25
- options?: {
26
- location?: 'local' | 'remote' | 'auto'
27
- }
28
- ) => Promise<RPCMap[Name]['output']>
29
-
30
- export type TypedPikkuRPC = {
31
- depth: number;
32
- global: boolean;
33
- invoke: RPCInvoke;
34
- }
35
- `;
36
- };
37
- function generateRPCs(rpcMeta, functionsMeta, typesMap, requiredTypes) {
38
- // Initialize an object to collect RPCs
39
- const rpcsObj = {};
40
- // Iterate through RPC metadata
41
- for (const [funcName, { pikkuFuncName }] of Object.entries(rpcMeta)) {
42
- const functionMeta = functionsMeta[pikkuFuncName];
43
- if (!functionMeta) {
44
- throw new Error(`Function ${funcName} not found in functionsMeta. Please check your configuration.`);
45
- }
46
- const input = functionMeta.inputs ? functionMeta.inputs[0] : undefined;
47
- const output = functionMeta.outputs ? functionMeta.outputs[0] : undefined;
48
- // Store the input and output types for RPCHandler
49
- const inputType = input ? typesMap.getTypeMeta(input).uniqueName : 'null';
50
- const outputType = output ? typesMap.getTypeMeta(output).uniqueName : 'null';
51
- requiredTypes.add(inputType);
52
- requiredTypes.add(outputType);
53
- // Add RPC entry
54
- rpcsObj[funcName] = {
55
- inputType,
56
- outputType,
57
- };
58
- }
59
- // Build the RPCs object as a string
60
- let rpcsStr = 'export type RPCMap = {\n';
61
- for (const [funcName, handler] of Object.entries(rpcsObj)) {
62
- rpcsStr += ` readonly '${funcName}': RPCHandler<${handler.inputType}, ${handler.outputType}>,\n`;
63
- }
64
- rpcsStr += '};\n';
65
- return rpcsStr;
66
- }
@@ -1,2 +0,0 @@
1
- import { PikkuCommand } from '../../types.js';
2
- export declare const pikkuScheduler: PikkuCommand;
@@ -1,10 +0,0 @@
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 { schedulersWiringFile, schedulersWiringMetaFile, packageMappings } = cliConfig;
6
- const { scheduledTasks } = visitState;
7
- await writeFileInDir(logger, schedulersWiringMetaFile, serializeSchedulerMeta(scheduledTasks.meta));
8
- await writeFileInDir(logger, schedulersWiringFile, serializeFileImports('addScheduledTasks', schedulersWiringFile, scheduledTasks.files, packageMappings));
9
- });
10
- };
@@ -1,2 +0,0 @@
1
- import { ScheduledTasksMeta } from '@pikku/core/scheduler';
2
- export declare const serializeSchedulerMeta: (scheduledTasksMeta: ScheduledTasksMeta) => string;
@@ -1,10 +0,0 @@
1
- export const serializeSchedulerMeta = (scheduledTasksMeta) => {
2
- const serializedOutput = [];
3
- serializedOutput.push("import { pikkuState } from '@pikku/core'");
4
- serializedOutput.push(`pikkuState('scheduler', 'meta', ${JSON.stringify(scheduledTasksMeta, null, 2)})`);
5
- const scheduledTasksMetaValues = Object.values(scheduledTasksMeta);
6
- if (scheduledTasksMetaValues.length > 0) {
7
- serializedOutput.push(`export type ScheduledTaskNames = '${scheduledTasksMetaValues.map((s) => s.name).join("' | '")}'`);
8
- }
9
- return serializedOutput.join('\n');
10
- };