@pikku/cli 0.9.0 → 0.9.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 +10 -0
- package/bin/pikku-all.ts +6 -1
- package/dist/bin/pikku-all.js +6 -1
- package/dist/bin/pikku.js +0 -0
- package/dist/src/utils.d.ts +5 -1
- package/dist/src/utils.js +17 -6
- package/package.json +3 -3
- package/src/utils.ts +26 -6
- package/dist/src/events/channels/pikku-channels.d.ts +0 -2
- package/dist/src/events/channels/pikku-channels.js +0 -9
- package/dist/src/events/channels/pikku-command-channels-map.d.ts +0 -2
- package/dist/src/events/channels/pikku-command-channels-map.js +0 -8
- package/dist/src/events/channels/pikku-command-channels.d.ts +0 -2
- package/dist/src/events/channels/pikku-command-channels.js +0 -9
- package/dist/src/events/channels/pikku-command-websocket-typed.d.ts +0 -2
- package/dist/src/events/channels/pikku-command-websocket-typed.js +0 -15
- package/dist/src/events/channels/serialize-typed-channel-map.d.ts +0 -4
- package/dist/src/events/channels/serialize-typed-channel-map.js +0 -111
- package/dist/src/events/channels/serialize-websocket-wrapper.d.ts +0 -1
- package/dist/src/events/channels/serialize-websocket-wrapper.js +0 -75
- package/dist/src/events/fetch/index.d.ts +0 -2
- package/dist/src/events/fetch/index.js +0 -12
- package/dist/src/events/functions/pikku-command-function-types.d.ts +0 -2
- package/dist/src/events/functions/pikku-command-function-types.js +0 -13
- package/dist/src/events/functions/pikku-command-functions.d.ts +0 -6
- package/dist/src/events/functions/pikku-command-functions.js +0 -35
- package/dist/src/events/functions/pikku-command-services.d.ts +0 -3
- package/dist/src/events/functions/pikku-command-services.js +0 -73
- package/dist/src/events/functions/pikku-function-types.d.ts +0 -2
- package/dist/src/events/functions/pikku-function-types.js +0 -13
- package/dist/src/events/functions/pikku-functions.d.ts +0 -6
- package/dist/src/events/functions/pikku-functions.js +0 -35
- package/dist/src/events/http/openapi-spec-generator.d.ts +0 -79
- package/dist/src/events/http/openapi-spec-generator.js +0 -145
- package/dist/src/events/http/pikku-command-http-map.d.ts +0 -2
- package/dist/src/events/http/pikku-command-http-map.js +0 -8
- package/dist/src/events/http/pikku-command-http-routes.d.ts +0 -2
- package/dist/src/events/http/pikku-command-http-routes.js +0 -9
- package/dist/src/events/http/pikku-command-nextjs.d.ts +0 -2
- package/dist/src/events/http/pikku-command-nextjs.js +0 -36
- package/dist/src/events/http/pikku-command-openapi.d.ts +0 -2
- package/dist/src/events/http/pikku-command-openapi.js +0 -20
- package/dist/src/events/http/pikku-http-routes.d.ts +0 -2
- package/dist/src/events/http/pikku-http-routes.js +0 -9
- package/dist/src/events/http/serialize-fetch-wrapper.d.ts +0 -1
- package/dist/src/events/http/serialize-fetch-wrapper.js +0 -67
- package/dist/src/events/http/serialize-typed-http-map.d.ts +0 -4
- package/dist/src/events/http/serialize-typed-http-map.js +0 -100
- package/dist/src/events/mcp/pikku-command-mcp-json.d.ts +0 -2
- package/dist/src/events/mcp/pikku-command-mcp-json.js +0 -13
- package/dist/src/events/mcp/pikku-command-mcp.d.ts +0 -2
- package/dist/src/events/mcp/pikku-command-mcp.js +0 -54
- package/dist/src/events/mcp/serialize-mcp-json.d.ts +0 -5
- package/dist/src/events/mcp/serialize-mcp-json.js +0 -101
- package/dist/src/events/queue/pikku-command-queue-map.d.ts +0 -2
- package/dist/src/events/queue/pikku-command-queue-map.js +0 -8
- package/dist/src/events/queue/pikku-command-queue-service.d.ts +0 -2
- package/dist/src/events/queue/pikku-command-queue-service.js +0 -12
- package/dist/src/events/queue/pikku-command-queue.d.ts +0 -2
- package/dist/src/events/queue/pikku-command-queue.js +0 -10
- package/dist/src/events/queue/pikku-queue-map.d.ts +0 -2
- package/dist/src/events/queue/pikku-queue-map.js +0 -8
- package/dist/src/events/queue/pikku-queue.d.ts +0 -2
- package/dist/src/events/queue/pikku-queue.js +0 -10
- package/dist/src/events/queue/serialize-queue-map.d.ts +0 -4
- package/dist/src/events/queue/serialize-queue-map.js +0 -77
- package/dist/src/events/queue/serialize-queue-meta.d.ts +0 -2
- package/dist/src/events/queue/serialize-queue-meta.js +0 -6
- package/dist/src/events/queue/serialize-queue-wrapper.d.ts +0 -1
- package/dist/src/events/queue/serialize-queue-wrapper.js +0 -35
- package/dist/src/events/rpc/index.d.ts +0 -2
- package/dist/src/events/rpc/index.js +0 -12
- package/dist/src/events/rpc/pikku-command-rpc-client.d.ts +0 -2
- package/dist/src/events/rpc/pikku-command-rpc-client.js +0 -12
- package/dist/src/events/rpc/pikku-command-rpc-map.d.ts +0 -2
- package/dist/src/events/rpc/pikku-command-rpc-map.js +0 -8
- package/dist/src/events/rpc/pikku-command-rpc.d.ts +0 -2
- package/dist/src/events/rpc/pikku-command-rpc.js +0 -6
- package/dist/src/events/rpc/pikku-rpc.d.ts +0 -2
- package/dist/src/events/rpc/pikku-rpc.js +0 -6
- package/dist/src/events/rpc/serialize-rpc-wrapper.d.ts +0 -1
- package/dist/src/events/rpc/serialize-rpc-wrapper.js +0 -68
- package/dist/src/events/rpc/serialize-typed-rpc-map.d.ts +0 -4
- package/dist/src/events/rpc/serialize-typed-rpc-map.js +0 -66
- package/dist/src/events/scheduler/pikku-command-scheduler.d.ts +0 -2
- package/dist/src/events/scheduler/pikku-command-scheduler.js +0 -10
- package/dist/src/events/scheduler/serialize-scheduler-meta.d.ts +0 -2
- package/dist/src/events/scheduler/serialize-scheduler-meta.js +0 -10
- package/lcov.info +0 -582
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @pikku/cli
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fdb1593: feat: adding silent option to cli
|
|
8
|
+
- fdb1593: core: bumping everything with a patch to sync up the major release inconsistencies in dependencies
|
|
9
|
+
- Updated dependencies [fdb1593]
|
|
10
|
+
- @pikku/core@0.9.1
|
|
11
|
+
- @pikku/inspector@0.9.1
|
|
12
|
+
|
|
3
13
|
## 0.9.0
|
|
4
14
|
|
|
5
15
|
### Breaking Changes
|
package/bin/pikku-all.ts
CHANGED
|
@@ -262,7 +262,11 @@ const watch = (
|
|
|
262
262
|
watcher.on('ready', async () => {
|
|
263
263
|
const handle = async () => {
|
|
264
264
|
try {
|
|
265
|
+
const start = Date.now()
|
|
265
266
|
await runAll(logger, cliConfig, options)
|
|
267
|
+
if (options.silent) {
|
|
268
|
+
logger.timing(`✓ Generated in ${Date.now() - start}ms`)
|
|
269
|
+
}
|
|
266
270
|
} catch (err) {
|
|
267
271
|
console.error(err)
|
|
268
272
|
console.info()
|
|
@@ -291,7 +295,7 @@ const watch = (
|
|
|
291
295
|
}
|
|
292
296
|
|
|
293
297
|
export const action = async (options: PikkuCLIOptions): Promise<void> => {
|
|
294
|
-
const logger = new CLILogger({ logLogo: true })
|
|
298
|
+
const logger = new CLILogger({ logLogo: true, silent: options.silent })
|
|
295
299
|
|
|
296
300
|
const cliConfig = await getPikkuCLIConfig(
|
|
297
301
|
options.config,
|
|
@@ -332,5 +336,6 @@ export const all = (program: Command): void => {
|
|
|
332
336
|
)
|
|
333
337
|
.option('--directories <directories...>', 'Which directories to filter by')
|
|
334
338
|
.option('-w | --watch', 'Whether to watch file changes')
|
|
339
|
+
.option('-s | --silent', 'Silent mode - only show errors')
|
|
335
340
|
.action(action)
|
|
336
341
|
}
|
package/dist/bin/pikku-all.js
CHANGED
|
@@ -132,7 +132,11 @@ const watch = (logger, cliConfig, options) => {
|
|
|
132
132
|
watcher.on('ready', async () => {
|
|
133
133
|
const handle = async () => {
|
|
134
134
|
try {
|
|
135
|
+
const start = Date.now();
|
|
135
136
|
await runAll(logger, cliConfig, options);
|
|
137
|
+
if (options.silent) {
|
|
138
|
+
logger.timing(`✓ Generated in ${Date.now() - start}ms`);
|
|
139
|
+
}
|
|
136
140
|
}
|
|
137
141
|
catch (err) {
|
|
138
142
|
console.error(err);
|
|
@@ -156,7 +160,7 @@ const watch = (logger, cliConfig, options) => {
|
|
|
156
160
|
configWatcher.on('change', generatorWatcher);
|
|
157
161
|
};
|
|
158
162
|
export const action = async (options) => {
|
|
159
|
-
const logger = new CLILogger({ logLogo: true });
|
|
163
|
+
const logger = new CLILogger({ logLogo: true, silent: options.silent });
|
|
160
164
|
const cliConfig = await getPikkuCLIConfig(options.config, [], {
|
|
161
165
|
tags: options.tags,
|
|
162
166
|
types: options.types,
|
|
@@ -181,5 +185,6 @@ export const all = (program) => {
|
|
|
181
185
|
.option('--types <types...>', 'Which types to filter by (http, channel, queue, scheduler, rpc, mcp)')
|
|
182
186
|
.option('--directories <directories...>', 'Which directories to filter by')
|
|
183
187
|
.option('-w | --watch', 'Whether to watch file changes')
|
|
188
|
+
.option('-s | --silent', 'Silent mode - only show errors')
|
|
184
189
|
.action(action);
|
|
185
190
|
};
|
package/dist/bin/pikku.js
CHANGED
|
File without changes
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { InspectorState, TypesMap } from '@pikku/inspector';
|
|
2
2
|
export declare class CLILogger {
|
|
3
|
-
|
|
3
|
+
private silent;
|
|
4
|
+
constructor({ logLogo, silent, }: {
|
|
4
5
|
logLogo: boolean;
|
|
6
|
+
silent?: boolean;
|
|
5
7
|
});
|
|
6
8
|
primary(message: string): void;
|
|
7
9
|
success(message: string): void;
|
|
@@ -9,6 +11,7 @@ export declare class CLILogger {
|
|
|
9
11
|
error(message: string): void;
|
|
10
12
|
warn(message: string): void;
|
|
11
13
|
debug(message: string): void;
|
|
14
|
+
timing(message: string): void;
|
|
12
15
|
private logPikkuLogo;
|
|
13
16
|
}
|
|
14
17
|
export declare const getFileImportRelativePath: (from: string, to: string, packageMappings: Record<string, string>) => string;
|
|
@@ -36,6 +39,7 @@ export interface PikkuCLIOptions {
|
|
|
36
39
|
tags?: string[];
|
|
37
40
|
types?: string[];
|
|
38
41
|
directories?: string[];
|
|
42
|
+
silent?: boolean;
|
|
39
43
|
}
|
|
40
44
|
export declare const getPikkuFilesAndMethods: (logger: CLILogger, { singletonServicesTypeImportMap, sessionServicesTypeImportMap, userSessionTypeImportMap, sessionServicesFactories, singletonServicesFactories, configFactories, }: InspectorState, packageMappings: Record<string, string>, outputFile: string, { configFileType, singletonServicesFactoryType, sessionServicesFactoryType, }: PikkuCLIOptions, requires?: Partial<{
|
|
41
45
|
config: boolean;
|
package/dist/src/utils.js
CHANGED
|
@@ -13,19 +13,27 @@ const logo = `
|
|
|
13
13
|
|_| |_|_| \_)_| \_)____/
|
|
14
14
|
`;
|
|
15
15
|
export class CLILogger {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
silent;
|
|
17
|
+
constructor({ logLogo, silent = false, }) {
|
|
18
|
+
this.silent = silent;
|
|
19
|
+
if (logLogo && !silent) {
|
|
18
20
|
this.logPikkuLogo();
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
primary(message) {
|
|
22
|
-
|
|
24
|
+
if (!this.silent) {
|
|
25
|
+
console.log(chalk.green(message));
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
28
|
success(message) {
|
|
25
|
-
|
|
29
|
+
if (!this.silent) {
|
|
30
|
+
console.log(chalk.green(message));
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
info(message) {
|
|
28
|
-
|
|
34
|
+
if (!this.silent) {
|
|
35
|
+
console.log(chalk.blue(message));
|
|
36
|
+
}
|
|
29
37
|
}
|
|
30
38
|
error(message) {
|
|
31
39
|
console.error(chalk.red(message));
|
|
@@ -34,10 +42,13 @@ export class CLILogger {
|
|
|
34
42
|
console.error(chalk.yellow(message));
|
|
35
43
|
}
|
|
36
44
|
debug(message) {
|
|
37
|
-
if (process.env.DEBUG) {
|
|
45
|
+
if (process.env.DEBUG && !this.silent) {
|
|
38
46
|
console.log(chalk.gray(message));
|
|
39
47
|
}
|
|
40
48
|
}
|
|
49
|
+
timing(message) {
|
|
50
|
+
console.log(chalk.gray(message));
|
|
51
|
+
}
|
|
41
52
|
logPikkuLogo() {
|
|
42
53
|
this.primary(logo);
|
|
43
54
|
const packageJson = JSON.parse(readFileSync(`${dirname(__filename)}/../../package.json`, 'utf-8'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"author": "yasser.fadl@gmail.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@openapi-contrib/json-schema-to-openapi-schema": "^3.0.2",
|
|
25
|
-
"@pikku/core": "^0.9.
|
|
26
|
-
"@pikku/inspector": "^0.9.
|
|
25
|
+
"@pikku/core": "^0.9.1",
|
|
26
|
+
"@pikku/inspector": "^0.9.1",
|
|
27
27
|
"@types/cookie": "^0.6.0",
|
|
28
28
|
"@types/uuid": "^10.0.0",
|
|
29
29
|
"chalk": "^5.4.1",
|
package/src/utils.ts
CHANGED
|
@@ -17,20 +17,35 @@ const logo = `
|
|
|
17
17
|
`
|
|
18
18
|
|
|
19
19
|
export class CLILogger {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
private silent: boolean
|
|
21
|
+
|
|
22
|
+
constructor({
|
|
23
|
+
logLogo,
|
|
24
|
+
silent = false,
|
|
25
|
+
}: {
|
|
26
|
+
logLogo: boolean
|
|
27
|
+
silent?: boolean
|
|
28
|
+
}) {
|
|
29
|
+
this.silent = silent
|
|
30
|
+
if (logLogo && !silent) {
|
|
22
31
|
this.logPikkuLogo()
|
|
23
32
|
}
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
primary(message: string) {
|
|
27
|
-
|
|
36
|
+
if (!this.silent) {
|
|
37
|
+
console.log(chalk.green(message))
|
|
38
|
+
}
|
|
28
39
|
}
|
|
29
40
|
success(message: string) {
|
|
30
|
-
|
|
41
|
+
if (!this.silent) {
|
|
42
|
+
console.log(chalk.green(message))
|
|
43
|
+
}
|
|
31
44
|
}
|
|
32
45
|
info(message: string) {
|
|
33
|
-
|
|
46
|
+
if (!this.silent) {
|
|
47
|
+
console.log(chalk.blue(message))
|
|
48
|
+
}
|
|
34
49
|
}
|
|
35
50
|
error(message: string) {
|
|
36
51
|
console.error(chalk.red(message))
|
|
@@ -39,11 +54,15 @@ export class CLILogger {
|
|
|
39
54
|
console.error(chalk.yellow(message))
|
|
40
55
|
}
|
|
41
56
|
debug(message: string) {
|
|
42
|
-
if (process.env.DEBUG) {
|
|
57
|
+
if (process.env.DEBUG && !this.silent) {
|
|
43
58
|
console.log(chalk.gray(message))
|
|
44
59
|
}
|
|
45
60
|
}
|
|
46
61
|
|
|
62
|
+
timing(message: string) {
|
|
63
|
+
console.log(chalk.gray(message))
|
|
64
|
+
}
|
|
65
|
+
|
|
47
66
|
private logPikkuLogo() {
|
|
48
67
|
this.primary(logo)
|
|
49
68
|
const packageJson = JSON.parse(
|
|
@@ -129,6 +148,7 @@ export interface PikkuCLIOptions {
|
|
|
129
148
|
tags?: string[]
|
|
130
149
|
types?: string[]
|
|
131
150
|
directories?: string[]
|
|
151
|
+
silent?: boolean
|
|
132
152
|
}
|
|
133
153
|
|
|
134
154
|
const getMetaTypes = (
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { logCommandInfoAndTime, serializeFileImports, writeFileInDir, } from '../../utils.js';
|
|
2
|
-
export const pikkuChannels = async (logger, cliConfig, visitState) => {
|
|
3
|
-
return await logCommandInfoAndTime(logger, 'Finding Channels', 'Found channels', [visitState.channels.files.size === 0], async () => {
|
|
4
|
-
const { channelsWiringFile, channelsWiringMetaFile, packageMappings } = cliConfig;
|
|
5
|
-
const { channels } = visitState;
|
|
6
|
-
await writeFileInDir(logger, channelsWiringFile, serializeFileImports('addChannel', channelsWiringFile, channels.files, packageMappings));
|
|
7
|
-
await writeFileInDir(logger, channelsWiringMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('channel', 'meta', ${JSON.stringify(channels.meta, null, 2)})`);
|
|
8
|
-
});
|
|
9
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js';
|
|
2
|
-
import { serializeTypedChannelsMap } from './serialize-typed-channel-map.js';
|
|
3
|
-
export const pikkuChannelsMap = async (logger, { channelsMapDeclarationFile, packageMappings }, state) => {
|
|
4
|
-
return await logCommandInfoAndTime(logger, 'Creating channels map', 'Created channels map', [state.channels.files.size === 0], async () => {
|
|
5
|
-
const content = serializeTypedChannelsMap(channelsMapDeclarationFile, packageMappings, state.functions.typesMap, state.functions.meta, state.channels.meta);
|
|
6
|
-
await writeFileInDir(logger, channelsMapDeclarationFile, content);
|
|
7
|
-
});
|
|
8
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { logCommandInfoAndTime, serializeFileImports, writeFileInDir, } from '../../utils.js';
|
|
2
|
-
export const pikkuChannels = async (logger, cliConfig, visitState) => {
|
|
3
|
-
return await logCommandInfoAndTime(logger, 'Finding Channels', 'Found channels', [visitState.channels.files.size === 0], async () => {
|
|
4
|
-
const { channelsWiringFile, channelsWiringMetaFile, packageMappings } = cliConfig;
|
|
5
|
-
const { channels } = visitState;
|
|
6
|
-
await writeFileInDir(logger, channelsWiringFile, serializeFileImports('addChannel', channelsWiringFile, channels.files, packageMappings));
|
|
7
|
-
await writeFileInDir(logger, channelsWiringMetaFile, `import { pikkuState } from '@pikku/core'\npikkuState('channel', 'meta', ${JSON.stringify(channels.meta, null, 2)})`);
|
|
8
|
-
});
|
|
9
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { logCommandInfoAndTime, getFileImportRelativePath, writeFileInDir, } from '../../utils.js';
|
|
2
|
-
import { serializeWebsocketWrapper } from './serialize-websocket-wrapper.js';
|
|
3
|
-
export const pikkuWebSocketTyped = async (logger, { websocketFile, channelsMapDeclarationFile, packageMappings }) => {
|
|
4
|
-
return await logCommandInfoAndTime(logger, 'Generating websocket wrapper', 'Generated websocket wrapper', [
|
|
5
|
-
websocketFile === undefined,
|
|
6
|
-
"websocketFile isn't set in the pikku config",
|
|
7
|
-
], async () => {
|
|
8
|
-
if (!websocketFile) {
|
|
9
|
-
throw new Error("fetchFile is isn't set in the pikku config");
|
|
10
|
-
}
|
|
11
|
-
const channelsMapDeclarationPath = getFileImportRelativePath(websocketFile, channelsMapDeclarationFile, packageMappings);
|
|
12
|
-
const content = [serializeWebsocketWrapper(channelsMapDeclarationPath)];
|
|
13
|
-
await writeFileInDir(logger, websocketFile, content.join('\n'));
|
|
14
|
-
});
|
|
15
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ChannelsMeta } from '@pikku/core/channel';
|
|
2
|
-
import { TypesMap } from '@pikku/inspector';
|
|
3
|
-
import { FunctionsMeta } from '@pikku/core';
|
|
4
|
-
export declare const serializeTypedChannelsMap: (relativeToPath: string, packageMappings: Record<string, string>, typesMap: TypesMap, functionsMeta: FunctionsMeta, channelsMeta: ChannelsMeta) => string;
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { serializeImportMap } from '../../serialize-import-map.js';
|
|
2
|
-
import { generateCustomTypes } from '../../utils.js';
|
|
3
|
-
export const serializeTypedChannelsMap = (relativeToPath, packageMappings, typesMap, functionsMeta, channelsMeta) => {
|
|
4
|
-
const { channels, requiredTypes } = generateChannels(functionsMeta, channelsMeta);
|
|
5
|
-
typesMap.customTypes.forEach(({ references }) => {
|
|
6
|
-
for (const reference of references) {
|
|
7
|
-
requiredTypes.add(reference);
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
const imports = serializeImportMap(relativeToPath, packageMappings, typesMap, requiredTypes);
|
|
11
|
-
const serializedCustomTypes = generateCustomTypes(typesMap, requiredTypes);
|
|
12
|
-
return `/**
|
|
13
|
-
* This provides the structure needed for TypeScript to be aware of channels
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
${imports}
|
|
17
|
-
${serializedCustomTypes}
|
|
18
|
-
|
|
19
|
-
interface ChannelHandler<I, O> {
|
|
20
|
-
input: I;
|
|
21
|
-
output: O;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
${channels}
|
|
25
|
-
|
|
26
|
-
export type ChannelDefaultHandlerOf<Channel extends keyof ChannelsMap> =
|
|
27
|
-
ChannelsMap[Channel]['defaultMessage'] extends { input: infer I; output: infer O }
|
|
28
|
-
? ChannelHandler<I, O>
|
|
29
|
-
: never;
|
|
30
|
-
|
|
31
|
-
export type ChannelRouteHandlerOf<
|
|
32
|
-
Channel extends keyof ChannelsMap,
|
|
33
|
-
Route extends keyof ChannelsMap[Channel]['routes'],
|
|
34
|
-
Method extends keyof ChannelsMap[Channel]['routes'][Route],
|
|
35
|
-
> =
|
|
36
|
-
ChannelsMap[Channel]['routes'][Route][Method] extends { input: infer I; output: infer O }
|
|
37
|
-
? ChannelHandler<I, O>
|
|
38
|
-
: never;
|
|
39
|
-
`;
|
|
40
|
-
};
|
|
41
|
-
function generateChannels(functionsMeta, channelsMeta) {
|
|
42
|
-
const requiredTypes = new Set();
|
|
43
|
-
const channelsObject = {};
|
|
44
|
-
for (const meta of Object.values(channelsMeta)) {
|
|
45
|
-
const { name, messageWirings, message } = meta;
|
|
46
|
-
if (!channelsObject[name]) {
|
|
47
|
-
channelsObject[name] = { message: null, routes: {} };
|
|
48
|
-
}
|
|
49
|
-
if (message) {
|
|
50
|
-
const func = functionsMeta[message.pikkuFuncName];
|
|
51
|
-
if (!func) {
|
|
52
|
-
throw new Error(`Function ${message.pikkuFuncName} not found in functionsMeta for channel ${name}`);
|
|
53
|
-
}
|
|
54
|
-
const inputTypes = func.inputs || null;
|
|
55
|
-
const outputTypes = func.outputs || null;
|
|
56
|
-
channelsObject[name].message = {
|
|
57
|
-
inputs: inputTypes,
|
|
58
|
-
outputs: outputTypes,
|
|
59
|
-
};
|
|
60
|
-
inputTypes?.forEach((type) => requiredTypes.add(type));
|
|
61
|
-
outputTypes?.forEach((type) => requiredTypes.add(type));
|
|
62
|
-
}
|
|
63
|
-
for (const [key, route] of Object.entries(messageWirings)) {
|
|
64
|
-
if (!channelsObject[name].routes[key]) {
|
|
65
|
-
channelsObject[name].routes[key] = {};
|
|
66
|
-
}
|
|
67
|
-
for (const [method, { pikkuFuncName }] of Object.entries(route)) {
|
|
68
|
-
const func = functionsMeta[pikkuFuncName];
|
|
69
|
-
if (!func) {
|
|
70
|
-
throw new Error(`Function ${pikkuFuncName} not found in functionsMeta for channel ${name}, route ${key}, method ${method}`);
|
|
71
|
-
}
|
|
72
|
-
const inputTypes = func.inputs || null;
|
|
73
|
-
const outputTypes = func.outputs || null;
|
|
74
|
-
channelsObject[name].routes[key][method] = {
|
|
75
|
-
inputTypes,
|
|
76
|
-
outputTypes,
|
|
77
|
-
};
|
|
78
|
-
inputTypes?.forEach((type) => requiredTypes.add(type));
|
|
79
|
-
outputTypes?.forEach((type) => requiredTypes.add(type));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
let routesStr = 'export type ChannelsMap = {\n';
|
|
84
|
-
for (const [channelPath, { routes, message }] of Object.entries(channelsObject)) {
|
|
85
|
-
routesStr += ` readonly '${channelPath}': {\n`;
|
|
86
|
-
// Add `routes` object
|
|
87
|
-
routesStr += ` readonly routes: {\n`;
|
|
88
|
-
for (const [key, methods] of Object.entries(routes)) {
|
|
89
|
-
routesStr += ` readonly ${key}: {\n`;
|
|
90
|
-
for (const [method, handler] of Object.entries(methods)) {
|
|
91
|
-
routesStr += ` readonly ${method}: ChannelHandler<${formatTypeArray(handler.inputTypes) || 'void'}, ${formatTypeArray(handler.outputTypes) || 'never'}>,\n`;
|
|
92
|
-
}
|
|
93
|
-
routesStr += ' },\n';
|
|
94
|
-
}
|
|
95
|
-
routesStr += ' },\n';
|
|
96
|
-
// Add `defaultMessage` outside `routes`
|
|
97
|
-
if (message) {
|
|
98
|
-
routesStr += ` readonly defaultMessage: ChannelHandler<${formatTypeArray(message.inputs)}, ${formatTypeArray(message.outputs)}>,\n`;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
routesStr += ` readonly defaultMessage: never,\n`;
|
|
102
|
-
}
|
|
103
|
-
routesStr += ' },\n';
|
|
104
|
-
}
|
|
105
|
-
routesStr += '};';
|
|
106
|
-
return { channels: routesStr, requiredTypes };
|
|
107
|
-
}
|
|
108
|
-
// Utility to format type arrays
|
|
109
|
-
function formatTypeArray(types) {
|
|
110
|
-
return types ? types.join(' | ') : 'null';
|
|
111
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const serializeWebsocketWrapper: (channelsMapPath: string) => string;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
export const serializeWebsocketWrapper = (channelsMapPath) => {
|
|
2
|
-
return `import { CorePikkuWebsocket, CorePikkuRouteHandler } from '@pikku/websocket'
|
|
3
|
-
import { ChannelDefaultHandlerOf, ChannelRouteHandlerOf, ChannelsMap } from '${channelsMapPath}';
|
|
4
|
-
|
|
5
|
-
class PikkuWebSocketRoute<Channel extends keyof ChannelsMap, Route extends keyof ChannelsMap[Channel]['routes']> extends CorePikkuRouteHandler {
|
|
6
|
-
public subscribe<
|
|
7
|
-
Method extends keyof ChannelsMap[Channel]['routes'][Route],
|
|
8
|
-
Data extends ChannelRouteHandlerOf<Channel, Route, Method>['output']
|
|
9
|
-
>(method: Method, callback: (data: Data) => void
|
|
10
|
-
) {
|
|
11
|
-
super.subscribe(method.toString(), callback)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public unsubscribe<
|
|
15
|
-
Method extends keyof ChannelsMap[Channel]['routes'][Route],
|
|
16
|
-
Data extends ChannelRouteHandlerOf<Channel, Route, Method>['output']
|
|
17
|
-
>(method: Method, callback?: (data: Data) => void) {
|
|
18
|
-
super.unsubscribe(method.toString(), callback)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public send<
|
|
22
|
-
Method extends keyof ChannelsMap[Channel]['routes'][Route],
|
|
23
|
-
Data extends ChannelRouteHandlerOf<Channel, Route, Method>['input']
|
|
24
|
-
>(method: Method, data: Data) {
|
|
25
|
-
super.send(method.toString(), data)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class PikkuWebSocket<Channel extends keyof ChannelsMap, Topics extends Record<string, any> = {}> extends CorePikkuWebsocket {
|
|
30
|
-
/**
|
|
31
|
-
* Send a message to a specific route and method.
|
|
32
|
-
* Validates the input data type.
|
|
33
|
-
*/
|
|
34
|
-
public getRoute<Route extends keyof ChannelsMap[Channel]['routes']>(route: Route): PikkuWebSocketRoute<Channel, Route> {
|
|
35
|
-
return super.getRoute(route)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Subscribe to a specific route and method.
|
|
40
|
-
*/
|
|
41
|
-
public subscribe<Data extends ChannelDefaultHandlerOf<Channel>['output']>(
|
|
42
|
-
callback: (data: Data) => void
|
|
43
|
-
) {
|
|
44
|
-
super.subscribe(callback)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Subscribe to a specific route and method.
|
|
49
|
-
*/
|
|
50
|
-
public unsubscribe<Data extends ChannelDefaultHandlerOf<Channel>['output']>(
|
|
51
|
-
callback?: (data: Data) => void
|
|
52
|
-
) {
|
|
53
|
-
super.unsubscribe(callback)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public send(data: ChannelDefaultHandlerOf<Channel>['input']) {
|
|
57
|
-
super.send(data)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Subscribe to a topic from the EventHub system with strong typing.
|
|
62
|
-
*/
|
|
63
|
-
public subscribeToEventHub<Topic extends keyof EventHubTopics>(
|
|
64
|
-
topic: Topic,
|
|
65
|
-
callback: (data: EventHubTopics[Topic]) => void
|
|
66
|
-
) {
|
|
67
|
-
super.subscribe((data) => {
|
|
68
|
-
if (data.topic === topic) {
|
|
69
|
-
callback(data as EventHubTopics[Topic])
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
`;
|
|
75
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { serializeFetchWrapper } from '../http/serialize-fetch-wrapper.js';
|
|
2
|
-
import { getFileImportRelativePath, logCommandInfoAndTime, writeFileInDir, } from '../../utils.js';
|
|
3
|
-
export const pikkuFetch = async (logger, { fetchFile, httpMapDeclarationFile, 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, httpMapDeclarationFile, packageMappings);
|
|
9
|
-
const content = [serializeFetchWrapper(routesMapDeclarationPath)];
|
|
10
|
-
await writeFileInDir(logger, fetchFile, content.join('\n'));
|
|
11
|
-
});
|
|
12
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
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,35 +0,0 @@
|
|
|
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,3 +0,0 @@
|
|
|
1
|
-
import { PikkuCommand } from '../../types.js';
|
|
2
|
-
export declare const serializeServicesMap: (functionsMetaData: Record<string, any>, middlewareServices: string[] | undefined, servicesImport: string, sessionServicesImport: string) => string;
|
|
3
|
-
export declare const pikkuServices: PikkuCommand;
|