@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.
- package/CHANGELOG.md +14 -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/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/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/{serialize-nextjs-http-wrapper.js → runtimes/nextjs/serialize-nextjs-http-wrapper.js} +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
- /package/src/{serialize-nextjs-http-wrapper.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.ts} +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { serializeFetchWrapper } from '../http/serialize-fetch-wrapper.js';
|
|
2
|
+
import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
|
|
3
|
+
export const pikkuFetch = async (logger, { fetchFile, httpRoutesMapDeclarationFile, packageMappings }) => {
|
|
4
|
+
return await logCommandInfoAndTime(logger, 'Generating fetch wrapper', 'Generated fetch wrapper', [fetchFile === undefined, "fetchFile isn't set in the pikku config"], async () => {
|
|
5
|
+
if (!fetchFile) {
|
|
6
|
+
throw new Error("fetchFile is isn't set in the pikku config");
|
|
7
|
+
}
|
|
8
|
+
const routesMapDeclarationPath = getFileImportRelativePath(fetchFile, httpRoutesMapDeclarationFile, packageMappings);
|
|
9
|
+
const content = [serializeFetchWrapper(routesMapDeclarationPath)];
|
|
10
|
+
await writeFileInDir(logger, fetchFile, content.join('\n'));
|
|
11
|
+
});
|
|
12
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getFileImportRelativePath, getPikkuFilesAndMethods, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
|
|
2
|
+
import { serializePikkuTypes } from '../../serialize-pikku-types.js';
|
|
3
|
+
export const pikkuFunctionTypes = async (logger, { typesDeclarationFile: typesFile, packageMappings, rpcMapDeclarationFile }, visitState, options = {}) => {
|
|
4
|
+
return await logCommandInfoAndTime(logger, 'Creating api types', 'Created api types', [false], async () => {
|
|
5
|
+
const { userSessionType, sessionServicesType, singletonServicesType } = await getPikkuFilesAndMethods(logger, visitState, packageMappings, typesFile, options, {
|
|
6
|
+
userSessionType: true,
|
|
7
|
+
sessionServiceType: true,
|
|
8
|
+
singletonServicesType: true,
|
|
9
|
+
});
|
|
10
|
+
const content = serializePikkuTypes(`import type { ${userSessionType.type} } from '${getFileImportRelativePath(typesFile, userSessionType.typePath, packageMappings)}'`, userSessionType.type, `import type { ${singletonServicesType.type} } from '${getFileImportRelativePath(typesFile, singletonServicesType.typePath, packageMappings)}'`, singletonServicesType.type, `import type { ${sessionServicesType.type} } from '${getFileImportRelativePath(typesFile, sessionServicesType.typePath, packageMappings)}'`, `import type { TypedPikkuRPC } from '${getFileImportRelativePath(typesFile, rpcMapDeclarationFile, packageMappings)}'`);
|
|
11
|
+
await writeFileInDir(logger, typesFile, content);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PikkuCommand } from '../../types.js';
|
|
2
|
+
export declare const serializeFunctionImports: (outputPath: string, functionsMap: Map<string, {
|
|
3
|
+
path: string;
|
|
4
|
+
exportedName: string;
|
|
5
|
+
}>, packageMappings?: Record<string, string>) => string;
|
|
6
|
+
export declare const pikkuFunctions: PikkuCommand;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
|
|
2
|
+
export const serializeFunctionImports = (outputPath, functionsMap, packageMappings = {}) => {
|
|
3
|
+
const serializedImports = [
|
|
4
|
+
`/* Import and register RPCs */`,
|
|
5
|
+
`import { addFunction } from '@pikku/core'`,
|
|
6
|
+
];
|
|
7
|
+
const serializedRegistrations = [];
|
|
8
|
+
// Sort by function name for consistent output
|
|
9
|
+
const sortedEntries = Array.from(functionsMap.entries()).sort((a, b) => a[0].localeCompare(b[0]));
|
|
10
|
+
for (const [name, { path, exportedName }] of sortedEntries) {
|
|
11
|
+
const filePath = getFileImportRelativePath(outputPath, path, packageMappings);
|
|
12
|
+
// For directly exported functions, we can just import and register them
|
|
13
|
+
if (name === exportedName) {
|
|
14
|
+
serializedImports.push(`import { ${exportedName} } from '${filePath}'`);
|
|
15
|
+
serializedRegistrations.push(`addFunction('${name}', { func: ${exportedName} })`);
|
|
16
|
+
}
|
|
17
|
+
// For renamed functions, we need to import and alias them
|
|
18
|
+
else {
|
|
19
|
+
serializedImports.push(`import { ${exportedName} as ${name} } from '${filePath}'`);
|
|
20
|
+
serializedRegistrations.push(`addFunction('${name}', ${name})`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Add a blank line between imports and registrations
|
|
24
|
+
if (serializedImports.length > 0 && serializedRegistrations.length > 0) {
|
|
25
|
+
serializedImports.push('');
|
|
26
|
+
}
|
|
27
|
+
// Combine the imports and registrations
|
|
28
|
+
return [...serializedImports, ...serializedRegistrations].join('\n');
|
|
29
|
+
};
|
|
30
|
+
export const pikkuFunctions = async (logger, { functionsMetaFile, functionsFile, packageMappings }, { functions }) => {
|
|
31
|
+
return await logCommandInfoAndTime(logger, 'Serializing Pikku functions', 'Serialized Pikku functions', [false], async () => {
|
|
32
|
+
await writeFileInDir(logger, functionsFile, serializeFunctionImports(functionsFile, functions.files, packageMappings));
|
|
33
|
+
await writeFileInDir(logger, functionsMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('function', 'meta', ${JSON.stringify(functions.meta, null, 2)})`);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { getFileImportRelativePath, getPikkuFilesAndMethods, logCommandInfoAndTime, writeFileInDir, } from '
|
|
2
|
-
import { serializePikkuTypes } from '
|
|
3
|
-
export const pikkuFunctionTypes = async ({ typesDeclarationFile: typesFile, packageMappings, rpcMapDeclarationFile
|
|
4
|
-
await logCommandInfoAndTime('Creating api types', 'Created api types', [false], async () => {
|
|
5
|
-
const { userSessionType, sessionServicesType, singletonServicesType } = await getPikkuFilesAndMethods(visitState, packageMappings, typesFile, options, {
|
|
1
|
+
import { getFileImportRelativePath, getPikkuFilesAndMethods, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
|
|
2
|
+
import { serializePikkuTypes } from '../../serialize-pikku-types.js';
|
|
3
|
+
export const pikkuFunctionTypes = async (logger, { typesDeclarationFile: typesFile, packageMappings, rpcMapDeclarationFile }, visitState, options = {}) => {
|
|
4
|
+
return await logCommandInfoAndTime(logger, 'Creating api types', 'Created api types', [false], async () => {
|
|
5
|
+
const { userSessionType, sessionServicesType, singletonServicesType } = await getPikkuFilesAndMethods(logger, visitState, packageMappings, typesFile, options, {
|
|
6
6
|
userSessionType: true,
|
|
7
7
|
sessionServiceType: true,
|
|
8
8
|
singletonServicesType: true,
|
|
9
9
|
});
|
|
10
10
|
const content = serializePikkuTypes(`import type { ${userSessionType.type} } from '${getFileImportRelativePath(typesFile, userSessionType.typePath, packageMappings)}'`, userSessionType.type, `import type { ${singletonServicesType.type} } from '${getFileImportRelativePath(typesFile, singletonServicesType.typePath, packageMappings)}'`, singletonServicesType.type, `import type { ${sessionServicesType.type} } from '${getFileImportRelativePath(typesFile, sessionServicesType.typePath, packageMappings)}'`, `import type { TypedPikkuRPC } from '${getFileImportRelativePath(typesFile, rpcMapDeclarationFile, packageMappings)}'`);
|
|
11
|
-
await writeFileInDir(typesFile, content);
|
|
11
|
+
await writeFileInDir(logger, typesFile, content);
|
|
12
12
|
});
|
|
13
13
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PikkuCommand } from '../../types.js';
|
|
2
|
+
export declare const serializeFunctionImports: (outputPath: string, functionsMap: Map<string, {
|
|
3
|
+
path: string;
|
|
4
|
+
exportedName: string;
|
|
5
|
+
}>, packageMappings?: Record<string, string>) => string;
|
|
6
|
+
export declare const pikkuFunctions: PikkuCommand;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '
|
|
1
|
+
import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
|
|
2
2
|
export const serializeFunctionImports = (outputPath, functionsMap, packageMappings = {}) => {
|
|
3
3
|
const serializedImports = [
|
|
4
4
|
`/* Import and register RPCs */`,
|
|
@@ -27,9 +27,9 @@ export const serializeFunctionImports = (outputPath, functionsMap, packageMappin
|
|
|
27
27
|
// Combine the imports and registrations
|
|
28
28
|
return [...serializedImports, ...serializedRegistrations].join('\n');
|
|
29
29
|
};
|
|
30
|
-
export const pikkuFunctions = async ({ functionsMetaFile, functionsFile, packageMappings }, { functions }) => {
|
|
31
|
-
return await logCommandInfoAndTime('Serializing Pikku functions', 'Serialized Pikku functions', [false], async () => {
|
|
32
|
-
await writeFileInDir(functionsFile, serializeFunctionImports(functionsFile, functions.files, packageMappings));
|
|
33
|
-
await writeFileInDir(functionsMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('function', 'meta', ${JSON.stringify(functions.meta, null, 2)})`);
|
|
30
|
+
export const pikkuFunctions = async (logger, { functionsMetaFile, functionsFile, packageMappings }, { functions }) => {
|
|
31
|
+
return await logCommandInfoAndTime(logger, 'Serializing Pikku functions', 'Serialized Pikku functions', [false], async () => {
|
|
32
|
+
await writeFileInDir(logger, functionsFile, serializeFunctionImports(functionsFile, functions.files, packageMappings));
|
|
33
|
+
await writeFileInDir(logger, functionsMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('function', 'meta', ${JSON.stringify(functions.meta, null, 2)})`);
|
|
34
34
|
});
|
|
35
35
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
|
|
2
|
+
import { serializeTypedRoutesMap } from './serialize-typed-http-map.js';
|
|
3
|
+
export const pikkuHTTPMap = async (logger, { httpRoutesMapDeclarationFile, packageMappings }, { http, functions }) => {
|
|
4
|
+
return await logCommandInfoAndTime(logger, 'Creating HTTP map', 'Created HTTP map', [http.files.size === 0], async () => {
|
|
5
|
+
const content = serializeTypedRoutesMap(httpRoutesMapDeclarationFile, packageMappings, functions.typesMap, functions.meta, http.meta, http.metaInputTypes);
|
|
6
|
+
await writeFileInDir(logger, httpRoutesMapDeclarationFile, content);
|
|
7
|
+
});
|
|
8
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, serializeFileImports, writeFileInDir, } from '../../utils.js';
|
|
2
|
+
export const pikkuHTTP = async (logger, cliConfig, visitState) => {
|
|
3
|
+
return await logCommandInfoAndTime(logger, 'Finding HTTP routes', 'Found HTTP routes', [visitState.http.files.size === 0], async () => {
|
|
4
|
+
const { httpRoutesFile, httpRoutesMetaFile, packageMappings } = cliConfig;
|
|
5
|
+
const { http } = visitState;
|
|
6
|
+
await writeFileInDir(logger, httpRoutesFile, serializeFileImports('addHTTPRoute', httpRoutesFile, http.files, packageMappings));
|
|
7
|
+
await writeFileInDir(logger, httpRoutesMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('http', 'meta', ${JSON.stringify(http.meta, null, 2)})`);
|
|
8
|
+
});
|
|
9
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { serializeNextJsBackendWrapper as serializeNextBackendWrapper } from '../../runtimes/nextjs/serialize-nextjs-backend-wrapper.js';
|
|
2
|
+
import { serializeNextJsHTTPWrapper as serializeNextHTTPWrapper } from '../../runtimes/nextjs/serialize-nextjs-http-wrapper.js';
|
|
3
|
+
import { getFileImportRelativePath, getPikkuFilesAndMethods, logCommandInfoAndTime, writeFileInDir, } from '../../utils.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
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
|
|
2
|
+
import { generateSchemas } from '../../schema-generator.js';
|
|
3
|
+
import { generateOpenAPISpec } from './openapi-spec-generator.js';
|
|
4
|
+
import { stringify } from 'yaml';
|
|
5
|
+
export const pikkuOpenAPI = async (logger, { tsconfig, openAPI }, { http, functions }) => {
|
|
6
|
+
return await logCommandInfoAndTime(logger, 'Creating OpenAPI spec', 'Created OpenAPI spec', [openAPI?.outputFile === undefined, 'openAPI outfile is not defined'], async () => {
|
|
7
|
+
if (!openAPI?.outputFile) {
|
|
8
|
+
throw new Error('openAPI is required');
|
|
9
|
+
}
|
|
10
|
+
const schemas = await generateSchemas(logger, tsconfig, functions.typesMap, functions.meta, http.meta);
|
|
11
|
+
const openAPISpec = await generateOpenAPISpec(functions.meta, http.meta, schemas, openAPI.additionalInfo);
|
|
12
|
+
if (openAPI.outputFile.endsWith('.json')) {
|
|
13
|
+
await writeFileInDir(logger, openAPI.outputFile, JSON.stringify(openAPISpec, null, 2), { ignoreModifyComment: true });
|
|
14
|
+
}
|
|
15
|
+
else if (openAPI.outputFile.endsWith('.yaml') ||
|
|
16
|
+
openAPI.outputFile.endsWith('.yml')) {
|
|
17
|
+
await writeFileInDir(logger, openAPI.outputFile, stringify(openAPISpec), { ignoreModifyComment: true });
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, serializeFileImports, writeFileInDir, } from '../../utils.js';
|
|
2
|
+
export const pikkuHTTP = async (logger, cliConfig, visitState) => {
|
|
3
|
+
return await logCommandInfoAndTime(logger, 'Finding HTTP routes', 'Found HTTP routes', [visitState.http.files.size === 0], async () => {
|
|
4
|
+
const { httpRoutesFile, httpRoutesMetaFile, packageMappings } = cliConfig;
|
|
5
|
+
const { http } = visitState;
|
|
6
|
+
await writeFileInDir(logger, httpRoutesFile, serializeFileImports('addHTTPRoute', httpRoutesFile, http.files, packageMappings));
|
|
7
|
+
await writeFileInDir(logger, httpRoutesMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('http', 'meta', ${JSON.stringify(http.meta, null, 2)})`);
|
|
8
|
+
});
|
|
9
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { serializeImportMap } from '
|
|
1
|
+
import { serializeImportMap } from '../../serialize-import-map.js';
|
|
2
2
|
export const serializeTypedRoutesMap = (relativeToPath, packageMappings, typesMap, functionsMeta, routesMeta, metaTypes) => {
|
|
3
3
|
const requiredTypes = new Set();
|
|
4
4
|
const serializedCustomTypes = generateCustomTypes(typesMap, requiredTypes);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
|
|
2
|
+
import { serializeMCPJson } from './serialize-mcp-json.js';
|
|
3
|
+
export const pikkuMCPJSON = async (logger, { mcpJsonFile, schemaDirectory }, { mcpEndpoints, functions }) => {
|
|
4
|
+
return await logCommandInfoAndTime(logger, 'Generating MCP JSON', 'Generated MCP JSON', [mcpEndpoints.files.size === 0 || !mcpJsonFile], async () => {
|
|
5
|
+
// Generate MCP JSON file
|
|
6
|
+
if (mcpJsonFile) {
|
|
7
|
+
const mcpJson = await serializeMCPJson(logger, schemaDirectory, functions.meta, functions.typesMap, mcpEndpoints.resourcesMeta, mcpEndpoints.toolsMeta, mcpEndpoints.promptsMeta);
|
|
8
|
+
await writeFileInDir(logger, mcpJsonFile, mcpJson, {
|
|
9
|
+
ignoreModifyComment: true,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, serializeFileImports, writeFileInDir, } from '../../utils.js';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
// Helper function to generate arguments from schema
|
|
5
|
+
const generateArgumentsFromSchema = async (inputSchema, schemaDirectory, typesMap, logger) => {
|
|
6
|
+
if (!inputSchema)
|
|
7
|
+
return [];
|
|
8
|
+
if (['boolean', 'string', 'number', 'null', 'undefined', 'void'].includes(inputSchema)) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
const uniqueName = typesMap.getUniqueName(inputSchema);
|
|
12
|
+
if (!uniqueName)
|
|
13
|
+
return [];
|
|
14
|
+
try {
|
|
15
|
+
const schemaPath = join(schemaDirectory, 'schemas', `${uniqueName}.schema.json`);
|
|
16
|
+
const schemaContent = await readFile(schemaPath, 'utf-8');
|
|
17
|
+
const schema = JSON.parse(schemaContent);
|
|
18
|
+
const argumentsArray = [];
|
|
19
|
+
if (schema && typeof schema === 'object' && schema.properties) {
|
|
20
|
+
const properties = schema.properties;
|
|
21
|
+
const required = schema.required || [];
|
|
22
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
23
|
+
argumentsArray.push({
|
|
24
|
+
name: propName,
|
|
25
|
+
description: propSchema.description || `${propName} parameter`,
|
|
26
|
+
required: required.includes(propName),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return argumentsArray;
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
logger.warn(`Could not load schema for type: ${uniqueName}`);
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export const pikkuMCP = async (logger, { mcpEndpointsFile, mcpEndpointsMetaFile, packageMappings, schemaDirectory }, { mcpEndpoints, functions }) => {
|
|
38
|
+
return await logCommandInfoAndTime(logger, 'Finding MCP endpoints', 'Found MCP endpoints', [mcpEndpoints.files.size === 0], async () => {
|
|
39
|
+
await writeFileInDir(logger, mcpEndpointsFile, serializeFileImports('addMCPResource or addMCPTool', mcpEndpointsFile, mcpEndpoints.files, packageMappings));
|
|
40
|
+
// Populate arguments for prompts meta before serializing
|
|
41
|
+
const promptsMetaWithArguments = { ...mcpEndpoints.promptsMeta };
|
|
42
|
+
for (const promptMeta of Object.values(promptsMetaWithArguments)) {
|
|
43
|
+
const functionMeta = functions.meta[promptMeta.pikkuFuncName];
|
|
44
|
+
if (functionMeta) {
|
|
45
|
+
const inputType = functionMeta.inputs?.[0];
|
|
46
|
+
promptMeta.arguments = await generateArgumentsFromSchema(inputType || null, schemaDirectory || '', functions.typesMap, logger);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
await writeFileInDir(logger, mcpEndpointsMetaFile, `import { pikkuState } from '@pikku/core'
|
|
50
|
+
pikkuState('mcp', 'resourcesMeta', ${JSON.stringify(mcpEndpoints.resourcesMeta, null, 2)})
|
|
51
|
+
pikkuState('mcp', 'toolsMeta', ${JSON.stringify(mcpEndpoints.toolsMeta, null, 2)})
|
|
52
|
+
pikkuState('mcp', 'promptsMeta', ${JSON.stringify(promptsMetaWithArguments, null, 2)})`);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from '@pikku/core';
|
|
2
|
+
import { FunctionsMeta } from '@pikku/core';
|
|
3
|
+
import { TypesMap } from '@pikku/inspector';
|
|
4
|
+
import { CLILogger } from '../../utils.js';
|
|
5
|
+
export declare const serializeMCPJson: (logger: CLILogger, schemaDirectory: string, functionsMeta: FunctionsMeta, typesMap: TypesMap, mcpResourceMeta: MCPResourceMeta, mcpToolMeta: MCPToolMeta, mcpPromptMeta: MCPPromptMeta) => Promise<string>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
export const serializeMCPJson = async (logger, schemaDirectory, functionsMeta, typesMap, mcpResourceMeta, mcpToolMeta, mcpPromptMeta) => {
|
|
4
|
+
const tools = [];
|
|
5
|
+
const resources = [];
|
|
6
|
+
const prompts = [];
|
|
7
|
+
// Helper function to load schema from file
|
|
8
|
+
const loadSchema = async (typeName) => {
|
|
9
|
+
if (!typeName ||
|
|
10
|
+
['boolean', 'string', 'number', 'null', 'undefined', 'void'].includes(typeName)) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const uniqueName = typesMap.getUniqueName(typeName);
|
|
14
|
+
if (!uniqueName) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const schemaPath = join(schemaDirectory, 'schemas', `${uniqueName}.schema.json`);
|
|
19
|
+
const schemaContent = await readFile(schemaPath, 'utf-8');
|
|
20
|
+
return JSON.parse(schemaContent);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
logger.warn(`Could not load schema for type: ${uniqueName}`);
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
// Process MCP resources
|
|
28
|
+
for (const [name, endpointMeta] of Object.entries(mcpResourceMeta)) {
|
|
29
|
+
const functionMeta = functionsMeta[endpointMeta.pikkuFuncName];
|
|
30
|
+
if (!functionMeta) {
|
|
31
|
+
logger.warn(`Function ${endpointMeta.pikkuFuncName} not found in functionsMeta. Skipping resource ${name}.`);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const inputType = functionMeta.inputs?.[0];
|
|
35
|
+
const outputType = functionMeta.outputs?.[0];
|
|
36
|
+
const parameters = await loadSchema(inputType);
|
|
37
|
+
const returns = await loadSchema(outputType);
|
|
38
|
+
const endpoint = {
|
|
39
|
+
uri: name,
|
|
40
|
+
name,
|
|
41
|
+
description: endpointMeta.description,
|
|
42
|
+
...(parameters && { parameters }),
|
|
43
|
+
...(returns && { returns }),
|
|
44
|
+
...(endpointMeta.streaming && { streaming: true }),
|
|
45
|
+
};
|
|
46
|
+
resources.push(endpoint);
|
|
47
|
+
}
|
|
48
|
+
// Process MCP tools
|
|
49
|
+
for (const [name, endpointMeta] of Object.entries(mcpToolMeta)) {
|
|
50
|
+
const functionMeta = functionsMeta[endpointMeta.pikkuFuncName];
|
|
51
|
+
if (!functionMeta) {
|
|
52
|
+
logger.warn(`Function ${endpointMeta.pikkuFuncName} not found in functionsMeta. Skipping tool ${name}.`);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const inputType = functionMeta.inputs?.[0];
|
|
56
|
+
const outputType = functionMeta.outputs?.[0];
|
|
57
|
+
const parameters = await loadSchema(inputType);
|
|
58
|
+
const returns = await loadSchema(outputType);
|
|
59
|
+
const endpoint = {
|
|
60
|
+
name,
|
|
61
|
+
description: endpointMeta.description,
|
|
62
|
+
...(parameters && { parameters }),
|
|
63
|
+
...(returns && { returns }),
|
|
64
|
+
...(endpointMeta.streaming && { streaming: true }),
|
|
65
|
+
};
|
|
66
|
+
tools.push(endpoint);
|
|
67
|
+
}
|
|
68
|
+
// Process MCP prompts
|
|
69
|
+
for (const [name, endpointMeta] of Object.entries(mcpPromptMeta)) {
|
|
70
|
+
const functionMeta = functionsMeta[endpointMeta.pikkuFuncName];
|
|
71
|
+
if (!functionMeta) {
|
|
72
|
+
logger.warn(`Function ${endpointMeta.pikkuFuncName} not found in functionsMeta. Skipping prompt ${name}.`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const inputType = functionMeta.inputs?.[0];
|
|
76
|
+
// TODO: this needs to be a json schema type, not any
|
|
77
|
+
const inputSchema = await loadSchema(inputType);
|
|
78
|
+
// Generate arguments from input schema
|
|
79
|
+
const argumentsArray = [];
|
|
80
|
+
if (inputSchema &&
|
|
81
|
+
typeof inputSchema === 'object' &&
|
|
82
|
+
inputSchema.properties) {
|
|
83
|
+
const properties = inputSchema.properties;
|
|
84
|
+
const required = inputSchema.required || [];
|
|
85
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
86
|
+
argumentsArray.push({
|
|
87
|
+
name: propName,
|
|
88
|
+
description: propSchema.description || `${propName} parameter`,
|
|
89
|
+
required: required.includes(propName),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const prompt = {
|
|
94
|
+
name,
|
|
95
|
+
description: endpointMeta.description,
|
|
96
|
+
arguments: argumentsArray,
|
|
97
|
+
};
|
|
98
|
+
prompts.push(prompt);
|
|
99
|
+
}
|
|
100
|
+
return JSON.stringify({ tools, resources, prompts }, null, 2);
|
|
101
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
|
|
2
|
+
import { serializeQueueMap } from './serialize-queue-map.js';
|
|
3
|
+
export const pikkuQueueMap = async (logger, { queueMapDeclarationFile, packageMappings }, { queueWorkers, functions }) => {
|
|
4
|
+
return await logCommandInfoAndTime(logger, 'Creating Queue map', 'Created Queue map', [queueWorkers.files.size === 0], async () => {
|
|
5
|
+
const content = serializeQueueMap(queueMapDeclarationFile, packageMappings, functions.typesMap, functions.meta, queueWorkers.meta);
|
|
6
|
+
await writeFileInDir(logger, queueMapDeclarationFile, content);
|
|
7
|
+
});
|
|
8
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { serializeQueueWrapper } from './serialize-queue-wrapper.js';
|
|
2
|
+
import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
|
|
3
|
+
export const pikkuQueueService = async (logger, { queueFile, queueMapDeclarationFile, packageMappings }) => {
|
|
4
|
+
return await logCommandInfoAndTime(logger, 'Generating queue service wrapper', 'Generated queue service wrapper', [queueFile === undefined, "queueFile isn't set in the pikku config"], async () => {
|
|
5
|
+
if (!queueFile) {
|
|
6
|
+
throw new Error("queueFile is isn't set in the pikku config");
|
|
7
|
+
}
|
|
8
|
+
const queueMapDeclarationPath = getFileImportRelativePath(queueFile, queueMapDeclarationFile, packageMappings);
|
|
9
|
+
const content = [serializeQueueWrapper(queueMapDeclarationPath)];
|
|
10
|
+
await writeFileInDir(logger, queueFile, content.join('\n'));
|
|
11
|
+
});
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, serializeFileImports, writeFileInDir, } from '../../utils.js';
|
|
2
|
+
import { serializeQueueMeta } from './serialize-queue-meta.js';
|
|
3
|
+
export const pikkuQueue = async (logger, cliConfig, visitState) => {
|
|
4
|
+
return await logCommandInfoAndTime(logger, 'Finding queues', 'Found queue', [visitState.queueWorkers.files.size === 0], async () => {
|
|
5
|
+
const { queueWorkersFile, queueWorkersMetaFile, packageMappings } = cliConfig;
|
|
6
|
+
const { queueWorkers } = visitState;
|
|
7
|
+
await writeFileInDir(logger, queueWorkersMetaFile, serializeQueueMeta(queueWorkers.meta));
|
|
8
|
+
await writeFileInDir(logger, queueWorkersFile, serializeFileImports('addQueueWorkers', queueWorkersFile, queueWorkers.files, packageMappings));
|
|
9
|
+
});
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
|
|
2
|
+
import { serializeQueueMap } from './serialize-queue-map.js';
|
|
3
|
+
export const pikkuQueueMap = async (logger, { queueMapDeclarationFile, packageMappings }, { queueWorkers, functions }) => {
|
|
4
|
+
return await logCommandInfoAndTime(logger, 'Creating Queue map', 'Created Queue map', [queueWorkers.files.size === 0], async () => {
|
|
5
|
+
const content = serializeQueueMap(queueMapDeclarationFile, packageMappings, functions.typesMap, functions.meta, queueWorkers.meta);
|
|
6
|
+
await writeFileInDir(logger, queueMapDeclarationFile, content);
|
|
7
|
+
});
|
|
8
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, serializeFileImports, writeFileInDir, } from '../../utils.js';
|
|
2
|
+
import { serializeQueueMeta } from './serialize-queue-meta.js';
|
|
3
|
+
export const pikkuQueue = async (logger, cliConfig, visitState) => {
|
|
4
|
+
return await logCommandInfoAndTime(logger, 'Finding queues', 'Found queue', [visitState.queueWorkers.files.size === 0], async () => {
|
|
5
|
+
const { queueWorkersFile, queueWorkersMetaFile, packageMappings } = cliConfig;
|
|
6
|
+
const { queueWorkers } = visitState;
|
|
7
|
+
await writeFileInDir(logger, queueWorkersMetaFile, serializeQueueMeta(queueWorkers.meta));
|
|
8
|
+
await writeFileInDir(logger, queueWorkersFile, serializeFileImports('addQueueWorkers', queueWorkersFile, queueWorkers.files, packageMappings));
|
|
9
|
+
});
|
|
10
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { queueWorkersMeta } from '@pikku/core/queue';
|
|
2
|
+
import { TypesMap } from '@pikku/inspector';
|
|
3
|
+
import { FunctionsMeta } from '@pikku/core';
|
|
4
|
+
export declare const serializeQueueMap: (relativeToPath: string, packageMappings: Record<string, string>, typesMap: TypesMap, functionsMeta: FunctionsMeta, queueWorkersMeta: queueWorkersMeta) => string;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { serializeImportMap } from '../../serialize-import-map.js';
|
|
2
|
+
import { generateCustomTypes } from '../../utils.js';
|
|
3
|
+
export const serializeQueueMap = (relativeToPath, packageMappings, typesMap, functionsMeta, queueWorkersMeta) => {
|
|
4
|
+
const requiredTypes = new Set();
|
|
5
|
+
const serializedCustomTypes = generateCustomTypes(typesMap, requiredTypes);
|
|
6
|
+
const serializedQueues = generateQueues(queueWorkersMeta, 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 Queue workers and their input/output types
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
${serializedImportMap}
|
|
13
|
+
${serializedCustomTypes}
|
|
14
|
+
|
|
15
|
+
import type { QueueJob } from '@pikku/core/queue'
|
|
16
|
+
|
|
17
|
+
interface QueueHandler<I, O> {
|
|
18
|
+
input: I;
|
|
19
|
+
output: O;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
${serializedQueues}
|
|
23
|
+
|
|
24
|
+
type QueueAdd = <Name extends keyof QueueMap>(
|
|
25
|
+
name: Name,
|
|
26
|
+
data: QueueMap[Name]['input'],
|
|
27
|
+
options?: {
|
|
28
|
+
priority?: number
|
|
29
|
+
delay?: number
|
|
30
|
+
attempts?: number
|
|
31
|
+
removeOnComplete?: number
|
|
32
|
+
removeOnFail?: number
|
|
33
|
+
jobId?: string
|
|
34
|
+
}
|
|
35
|
+
) => Promise<string>
|
|
36
|
+
|
|
37
|
+
type QueueGetJob = <Name extends keyof QueueMap>(
|
|
38
|
+
name: Name,
|
|
39
|
+
jobId: string
|
|
40
|
+
) => Promise<QueueJob<QueueMap[Name]['input'], QueueMap[Name]['output']> | null>
|
|
41
|
+
|
|
42
|
+
export type TypedPikkuQueue = {
|
|
43
|
+
add: QueueAdd;
|
|
44
|
+
getJob: QueueGetJob;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
};
|
|
48
|
+
function generateQueues(queueWorkersMeta, functionsMeta, typesMap, requiredTypes) {
|
|
49
|
+
// Initialize an object to collect queues
|
|
50
|
+
const queuesObj = {};
|
|
51
|
+
// Iterate through Queue metadata
|
|
52
|
+
for (const [queueName, { pikkuFuncName }] of Object.entries(queueWorkersMeta)) {
|
|
53
|
+
const functionMeta = functionsMeta[pikkuFuncName];
|
|
54
|
+
if (!functionMeta) {
|
|
55
|
+
throw new Error(`Function ${queueName} not found in functionsMeta. Please check your configuration.`);
|
|
56
|
+
}
|
|
57
|
+
const input = functionMeta.inputs ? functionMeta.inputs[0] : undefined;
|
|
58
|
+
const output = functionMeta.outputs ? functionMeta.outputs[0] : undefined;
|
|
59
|
+
// Store the input and output types for QueueHandler
|
|
60
|
+
const inputType = input ? typesMap.getTypeMeta(input).uniqueName : 'null';
|
|
61
|
+
const outputType = output ? typesMap.getTypeMeta(output).uniqueName : 'null';
|
|
62
|
+
requiredTypes.add(inputType);
|
|
63
|
+
requiredTypes.add(outputType);
|
|
64
|
+
// Add Queue entry
|
|
65
|
+
queuesObj[queueName] = {
|
|
66
|
+
inputType,
|
|
67
|
+
outputType,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// Build the Queues object as a string
|
|
71
|
+
let queuesStr = 'export type QueueMap = {\n';
|
|
72
|
+
for (const [queueName, handler] of Object.entries(queuesObj)) {
|
|
73
|
+
queuesStr += ` readonly '${queueName}': QueueHandler<${handler.inputType}, ${handler.outputType}>,\n`;
|
|
74
|
+
}
|
|
75
|
+
queuesStr += '};\n';
|
|
76
|
+
return queuesStr;
|
|
77
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const serializeQueueWrapper: (queueMapPath: string) => string;
|