@pikku/cli 0.7.7 → 0.8.1
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 +43 -0
- package/bin/pikku-all.ts +188 -91
- package/bin/pikku-fetch.ts +10 -38
- package/bin/pikku-nextjs.ts +12 -113
- package/bin/pikku-openapi.ts +9 -54
- package/bin/pikku-queue-service.ts +28 -0
- package/bin/pikku-schemas.ts +6 -32
- package/bin/pikku-websocket.ts +11 -41
- package/bin/pikku.ts +2 -0
- package/cli.schema.json +113 -10
- package/dist/bin/pikku-all.d.ts +1 -1
- package/dist/bin/pikku-all.js +105 -84
- package/dist/bin/pikku-fetch.d.ts +1 -3
- package/dist/bin/pikku-fetch.js +9 -15
- package/dist/bin/pikku-nextjs.d.ts +1 -4
- package/dist/bin/pikku-nextjs.js +10 -40
- package/dist/bin/pikku-openapi.d.ts +0 -3
- package/dist/bin/pikku-openapi.js +8 -24
- package/dist/bin/pikku-queue-service.d.ts +4 -0
- package/dist/bin/pikku-queue-service.js +19 -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 +9 -18
- 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-command-services.d.ts +3 -0
- package/dist/src/events/functions/pikku-command-services.js +73 -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-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.d.ts → events/http/serialize-typed-http-map.d.ts} +0 -1
- package/dist/src/{serialize-typed-http-map.js → events/http/serialize-typed-http-map.js} +2 -15
- 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-client.d.ts +2 -0
- package/dist/src/events/rpc/pikku-command-rpc-client.js +12 -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/events/rpc/serialize-rpc-wrapper.d.ts +1 -0
- package/dist/src/events/rpc/serialize-rpc-wrapper.js +29 -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} +3 -3
- 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 +4 -4
- package/dist/src/pikku-cli-config.d.ts +12 -2
- package/dist/src/pikku-cli-config.js +79 -30
- 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 +9 -9
- 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} +20 -7
- package/dist/src/{utils/utils.js → utils.js} +56 -32
- 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/src/events/functions/pikku-command-services.ts +125 -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-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} +2 -19
- 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-client.ts +33 -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/events/rpc/serialize-rpc-wrapper.ts +29 -0
- package/src/{serialize-typed-rpc-map.ts → events/rpc/serialize-typed-rpc-map.ts} +5 -4
- package/{bin/pikku-scheduler.ts → src/events/scheduler/pikku-command-scheduler.ts} +11 -8
- package/src/inspector-glob.ts +4 -2
- package/src/pikku-cli-config.ts +119 -42
- package/src/pikku-command-schemas.ts +33 -0
- package/src/runtimes/nextjs/pikku-command-nextjs.ts +110 -0
- package/src/schema-generator.ts +10 -5
- 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} +68 -34
- 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-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,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;
|
|
@@ -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,12 @@
|
|
|
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
|
+
};
|
|
@@ -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,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,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 @@
|
|
|
1
|
+
export declare const serializeRPCWrapper: (rpcMapPath: string) => string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const serializeRPCWrapper = (rpcMapPath) => {
|
|
2
|
+
return `
|
|
3
|
+
import { PikkuFetch } from "./pikku-fetch.gen.js"
|
|
4
|
+
import type { RPCInvoke } from '${rpcMapPath}'
|
|
5
|
+
|
|
6
|
+
export class PikkuRPC {
|
|
7
|
+
pikkuFetch = new PikkuFetch()
|
|
8
|
+
|
|
9
|
+
setPikkuFetch(pikkuFetch: PikkuFetch): void {
|
|
10
|
+
this.pikkuFetch = pikkuFetch
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setServerUrl(serverUrl: string): void {
|
|
14
|
+
this.pikkuFetch.setServerUrl(serverUrl)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
setAuthorizationJWT(jwt: string | null): void {
|
|
18
|
+
this.pikkuFetch.setAuthorizationJWT(jwt)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Generic RPC invoke method
|
|
22
|
+
invoke: RPCInvoke = async (name, data) => {
|
|
23
|
+
return await this.pikkuFetch.post('/rpc', { name, data })
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const pikkuRPC = new PikkuRPC();
|
|
28
|
+
`;
|
|
29
|
+
};
|
|
@@ -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 '
|
|
2
|
-
import { generateCustomTypes } from '
|
|
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);
|
|
@@ -19,7 +19,7 @@ interface RPCHandler<I, O> {
|
|
|
19
19
|
|
|
20
20
|
${serializedRPCs}
|
|
21
21
|
|
|
22
|
-
type RPCInvoke = <Name extends keyof RPCMap>(
|
|
22
|
+
export type RPCInvoke = <Name extends keyof RPCMap>(
|
|
23
23
|
name: Name,
|
|
24
24
|
data: RPCMap[Name]['input'],
|
|
25
25
|
options?: {
|
|
@@ -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,12 +1,12 @@
|
|
|
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
|
|
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
|
-
result = await inspect(routeFiles, filters);
|
|
9
|
+
result = await inspect(logger, routeFiles, filters);
|
|
10
10
|
});
|
|
11
11
|
return result;
|
|
12
12
|
};
|
|
@@ -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,12 @@ 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;
|
|
25
|
+
servicesFile: string;
|
|
20
26
|
bootstrapFile: string;
|
|
21
27
|
bootstrapFiles: Record<PikkuEventTypes, string>;
|
|
22
28
|
}
|
|
@@ -33,11 +39,15 @@ export type PikkuCLIConfig = {
|
|
|
33
39
|
nextHTTPFile?: string;
|
|
34
40
|
fetchFile?: string;
|
|
35
41
|
websocketFile?: string;
|
|
42
|
+
rpcFile?: string;
|
|
43
|
+
queueFile?: string;
|
|
44
|
+
mcpJsonFile?: string;
|
|
36
45
|
openAPI?: {
|
|
37
46
|
outputFile: string;
|
|
38
47
|
additionalInfo: OpenAPISpecInfo;
|
|
39
48
|
};
|
|
49
|
+
middlewareServices?: string[];
|
|
40
50
|
filters: InspectorFilters;
|
|
41
51
|
} & PikkuCLICoreOutputFiles;
|
|
42
|
-
export declare const getPikkuCLIConfig: (configFile: string | undefined, requiredFields: Array<keyof PikkuCLIConfig>,
|
|
52
|
+
export declare const getPikkuCLIConfig: (configFile: string | undefined, requiredFields: Array<keyof PikkuCLIConfig>, filters?: InspectorFilters, exitProcess?: boolean) => Promise<PikkuCLIConfig>;
|
|
43
53
|
export declare const validateCLIConfig: (cliConfig: PikkuCLIConfig, required: Array<keyof PikkuCLIConfig>) => void;
|
|
@@ -6,12 +6,15 @@ const CONFIG_DIR_FILES = [
|
|
|
6
6
|
'nextHTTPFile',
|
|
7
7
|
'fetchFile',
|
|
8
8
|
'websocketFile',
|
|
9
|
+
'rpcFile',
|
|
10
|
+
'queueFile',
|
|
11
|
+
'mcpJsonFile',
|
|
9
12
|
];
|
|
10
|
-
export const getPikkuCLIConfig = async (configFile = undefined, requiredFields,
|
|
11
|
-
const config = await _getPikkuCLIConfig(configFile, requiredFields,
|
|
13
|
+
export const getPikkuCLIConfig = async (configFile = undefined, requiredFields, filters = {}, exitProcess = false) => {
|
|
14
|
+
const config = await _getPikkuCLIConfig(configFile, requiredFields, filters, exitProcess);
|
|
12
15
|
return config;
|
|
13
16
|
};
|
|
14
|
-
const _getPikkuCLIConfig = async (configFile = undefined, requiredFields,
|
|
17
|
+
const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, filters = {}, exitProcess = false) => {
|
|
15
18
|
if (!configFile) {
|
|
16
19
|
let execDirectory = process.cwd();
|
|
17
20
|
const files = await readdir(execDirectory);
|
|
@@ -32,7 +35,7 @@ const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags =
|
|
|
32
35
|
const configDir = dirname(configFile);
|
|
33
36
|
const config = JSON.parse(file);
|
|
34
37
|
if (config.extends) {
|
|
35
|
-
const extendedConfig = await getPikkuCLIConfig(resolve(configDir, config.extends), [],
|
|
38
|
+
const extendedConfig = await getPikkuCLIConfig(resolve(configDir, config.extends), [], filters, exitProcess);
|
|
36
39
|
result = {
|
|
37
40
|
...extendedConfig,
|
|
38
41
|
...config,
|
|
@@ -54,54 +57,94 @@ const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags =
|
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
if (result.outDir) {
|
|
60
|
+
// Create transport/event directories
|
|
61
|
+
const functionDir = join(result.outDir, 'function');
|
|
62
|
+
const httpDir = join(result.outDir, 'http');
|
|
63
|
+
const channelDir = join(result.outDir, 'channel');
|
|
64
|
+
const rpcDir = join(result.outDir, 'rpc');
|
|
65
|
+
const schedulerDir = join(result.outDir, 'scheduler');
|
|
66
|
+
const queueDir = join(result.outDir, 'queue');
|
|
67
|
+
const mcpDir = join(result.outDir, 'mcp');
|
|
68
|
+
// Create directories if they don't exist (will be done lazily when files are written)
|
|
57
69
|
if (!result.schemaDirectory) {
|
|
58
|
-
result.schemaDirectory = join(result.outDir, '
|
|
70
|
+
result.schemaDirectory = join(result.outDir, 'schemas');
|
|
59
71
|
}
|
|
72
|
+
// Functions
|
|
60
73
|
if (!result.functionsFile) {
|
|
61
|
-
result.functionsFile = join(
|
|
74
|
+
result.functionsFile = join(functionDir, 'pikku-functions.gen.ts');
|
|
62
75
|
}
|
|
63
76
|
if (!result.functionsMetaFile) {
|
|
64
|
-
result.functionsMetaFile = join(
|
|
77
|
+
result.functionsMetaFile = join(functionDir, 'pikku-functions-meta.gen.ts');
|
|
65
78
|
}
|
|
66
|
-
if (!result.
|
|
67
|
-
result.
|
|
68
|
-
}
|
|
69
|
-
if (!result.rpcMapDeclarationFile) {
|
|
70
|
-
result.rpcMapDeclarationFile = join(result.outDir, 'pikku-rpc-map.gen.ts');
|
|
79
|
+
if (!result.typesDeclarationFile) {
|
|
80
|
+
result.typesDeclarationFile = join(result.outDir, 'pikku-types.gen.ts');
|
|
71
81
|
}
|
|
82
|
+
// HTTP
|
|
72
83
|
if (!result.httpRoutesFile) {
|
|
73
|
-
result.httpRoutesFile = join(
|
|
84
|
+
result.httpRoutesFile = join(httpDir, 'pikku-http-routes.gen.ts');
|
|
74
85
|
}
|
|
75
86
|
if (!result.httpRoutesMetaFile) {
|
|
76
|
-
result.httpRoutesMetaFile = join(
|
|
77
|
-
}
|
|
78
|
-
if (!result.schedulersFile) {
|
|
79
|
-
result.schedulersFile = join(result.outDir, 'pikku-schedules.gen.ts');
|
|
87
|
+
result.httpRoutesMetaFile = join(httpDir, 'pikku-http-routes-meta.gen.ts');
|
|
80
88
|
}
|
|
81
|
-
if (!result.
|
|
82
|
-
result.
|
|
89
|
+
if (!result.httpRoutesMapDeclarationFile) {
|
|
90
|
+
result.httpRoutesMapDeclarationFile = join(httpDir, 'pikku-http-routes-map.gen.d.ts');
|
|
83
91
|
}
|
|
92
|
+
// Channels/WebSocket
|
|
84
93
|
if (!result.channelsFile) {
|
|
85
|
-
result.channelsFile = join(
|
|
94
|
+
result.channelsFile = join(channelDir, 'pikku-channels.gen.ts');
|
|
86
95
|
}
|
|
87
96
|
if (!result.channelsMetaFile) {
|
|
88
|
-
result.channelsMetaFile = join(
|
|
97
|
+
result.channelsMetaFile = join(channelDir, 'pikku-channels-meta.gen.ts');
|
|
89
98
|
}
|
|
90
|
-
if (!result.
|
|
91
|
-
result.
|
|
99
|
+
if (!result.channelsMapDeclarationFile) {
|
|
100
|
+
result.channelsMapDeclarationFile = join(channelDir, 'pikku-channels-map.gen.d.ts');
|
|
92
101
|
}
|
|
93
|
-
|
|
94
|
-
|
|
102
|
+
// RPC
|
|
103
|
+
if (!result.rpcMetaFile) {
|
|
104
|
+
result.rpcMetaFile = join(rpcDir, 'pikku-rpc-meta.gen.ts');
|
|
95
105
|
}
|
|
96
|
-
if (!result.
|
|
97
|
-
result.
|
|
106
|
+
if (!result.rpcMapDeclarationFile) {
|
|
107
|
+
result.rpcMapDeclarationFile = join(rpcDir, 'pikku-rpc-map.gen.ts');
|
|
108
|
+
}
|
|
109
|
+
// Scheduler
|
|
110
|
+
if (!result.schedulersFile) {
|
|
111
|
+
result.schedulersFile = join(schedulerDir, 'pikku-scheduler.gen.ts');
|
|
112
|
+
}
|
|
113
|
+
if (!result.schedulersMetaFile) {
|
|
114
|
+
result.schedulersMetaFile = join(schedulerDir, 'pikku-scheduler-meta.gen.ts');
|
|
115
|
+
}
|
|
116
|
+
// Queue
|
|
117
|
+
if (!result.queueWorkersFile) {
|
|
118
|
+
result.queueWorkersFile = join(queueDir, 'pikku-queue-workers.gen.ts');
|
|
119
|
+
}
|
|
120
|
+
if (!result.queueWorkersMetaFile) {
|
|
121
|
+
result.queueWorkersMetaFile = join(queueDir, 'pikku-queue-workers-meta.gen.ts');
|
|
98
122
|
}
|
|
123
|
+
if (!result.queueMapDeclarationFile) {
|
|
124
|
+
result.queueMapDeclarationFile = join(queueDir, 'pikku-queue-map.gen.ts');
|
|
125
|
+
}
|
|
126
|
+
// Services
|
|
127
|
+
if (!result.servicesFile) {
|
|
128
|
+
result.servicesFile = join(result.outDir, 'pikku-services.gen.ts');
|
|
129
|
+
}
|
|
130
|
+
// Bootstrap files
|
|
99
131
|
if (!result.bootstrapFile) {
|
|
100
132
|
result.bootstrapFile = join(result.outDir, 'pikku-bootstrap.gen.ts');
|
|
101
133
|
}
|
|
134
|
+
// MCP
|
|
135
|
+
if (!result.mcpEndpointsMetaFile) {
|
|
136
|
+
result.mcpEndpointsMetaFile = join(mcpDir, 'mcp-endpoints-meta.gen.ts');
|
|
137
|
+
}
|
|
138
|
+
if (!result.mcpEndpointsFile) {
|
|
139
|
+
result.mcpEndpointsFile = join(mcpDir, 'mcp-endpoints.gen.ts');
|
|
140
|
+
}
|
|
141
|
+
if (!result.mcpJsonFile) {
|
|
142
|
+
result.mcpJsonFile = join(mcpDir, 'mcp.gen.json');
|
|
143
|
+
}
|
|
102
144
|
result.bootstrapFiles = result.bootstrapFiles || {};
|
|
103
145
|
for (const key of Object.keys(PikkuEventTypes)) {
|
|
104
|
-
|
|
146
|
+
const eventDir = join(result.outDir, key.toLowerCase());
|
|
147
|
+
result.bootstrapFiles[key] = join(eventDir, `pikku-bootstrap-${key}.gen.ts`);
|
|
105
148
|
}
|
|
106
149
|
}
|
|
107
150
|
if (requiredFields.length > 0) {
|
|
@@ -120,8 +163,14 @@ const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags =
|
|
|
120
163
|
}
|
|
121
164
|
}
|
|
122
165
|
result.filters = result.filters || {};
|
|
123
|
-
if (tags.length > 0) {
|
|
124
|
-
result.filters.tags = tags;
|
|
166
|
+
if (filters.tags && filters.tags.length > 0) {
|
|
167
|
+
result.filters.tags = filters.tags;
|
|
168
|
+
}
|
|
169
|
+
if (filters.types && filters.types.length > 0) {
|
|
170
|
+
result.filters.types = filters.types;
|
|
171
|
+
}
|
|
172
|
+
if (filters.directories && filters.directories.length > 0) {
|
|
173
|
+
result.filters.directories = filters.directories;
|
|
125
174
|
}
|
|
126
175
|
if (!isAbsolute(result.tsconfig)) {
|
|
127
176
|
result.tsconfig = join(result.rootDir, result.tsconfig);
|
|
@@ -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,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 {
|
|
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 || [])];
|
|
@@ -43,16 +43,16 @@ export async function generateSchemas(tsconfig, typesMap, functionMeta, httpRout
|
|
|
43
43
|
catch (e) {
|
|
44
44
|
// Ignore rootless errors
|
|
45
45
|
if (e instanceof RootlessError) {
|
|
46
|
-
|
|
46
|
+
logger.error(`Error generating schema since it has no root: ${schema}`);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
logger.error(`Error generating schema: ${schema}`);
|
|
50
50
|
}
|
|
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
|
-
|
|
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,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
|
}
|