@pikku/cli 0.7.5 → 0.7.7
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 +20 -0
- package/bin/pikku-all.ts +48 -23
- package/bin/pikku-channels-map.ts +1 -0
- package/bin/pikku-nextjs.ts +11 -18
- package/dist/bin/pikku-all.js +37 -19
- package/dist/bin/pikku-channels-map.js +1 -1
- package/dist/bin/pikku-nextjs.d.ts +1 -1
- package/dist/bin/pikku-nextjs.js +6 -7
- package/dist/src/pikku-cli-config.d.ts +2 -0
- package/dist/src/pikku-cli-config.js +6 -1
- package/dist/src/schema-generator.js +6 -0
- package/dist/src/serialize-nextjs-backend-wrapper.d.ts +1 -1
- package/dist/src/serialize-nextjs-backend-wrapper.js +2 -3
- package/dist/src/serialize-nextjs-http-wrapper.js +1 -2
- package/dist/src/serialize-typed-channel-map.d.ts +2 -1
- package/dist/src/serialize-typed-channel-map.js +25 -7
- package/package.json +3 -3
- package/src/pikku-cli-config.ts +11 -1
- package/src/schema-generator.ts +6 -0
- package/src/serialize-nextjs-backend-wrapper.ts +2 -4
- package/src/serialize-nextjs-http-wrapper.ts +1 -2
- package/src/serialize-typed-channel-map.ts +37 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @pikku/cli
|
|
2
2
|
|
|
3
|
+
## 0.7.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a5e3903: fix: PikkuFetch import fix
|
|
8
|
+
|
|
9
|
+
## 0.7.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 8b4f52e: refactor: moving schemas in channels to functions
|
|
14
|
+
- 1d70184: feat: adding multiple bootstrap files for different transports
|
|
15
|
+
- 5c4f56f: fix: adding more options to schema generator to support complex types
|
|
16
|
+
- a9427b8: fix: import bootstrap file to include all rpc/function code in nextjs wrapper
|
|
17
|
+
- Updated dependencies [8b4f52e]
|
|
18
|
+
- Updated dependencies [8b4f52e]
|
|
19
|
+
- Updated dependencies [1d70184]
|
|
20
|
+
- @pikku/core@0.7.8
|
|
21
|
+
- @pikku/inspector@0.7.7
|
|
22
|
+
|
|
3
23
|
## 0.7.5
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/bin/pikku-all.ts
CHANGED
|
@@ -24,16 +24,39 @@ import chokidar from 'chokidar'
|
|
|
24
24
|
import { pikkuFunctions } from './pikku-functions.js'
|
|
25
25
|
import { pikkuRPC } from './pikku-rpc.js'
|
|
26
26
|
import { pikkuRPCMap } from './pikku-rpc-map.js'
|
|
27
|
+
import { PikkuEventTypes } from '@pikku/core'
|
|
27
28
|
|
|
28
29
|
const runAll = async (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const boostrapImports: Partial<
|
|
31
|
+
Record<PikkuEventTypes, { meta: string[]; events: string[] }>
|
|
32
|
+
> & { all: { meta: string[]; events: string[] } } = {
|
|
33
|
+
all: { meta: [], events: [] },
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const addImport = (
|
|
37
|
+
from: string,
|
|
38
|
+
type: 'meta' | 'events' | 'other',
|
|
39
|
+
addTo?: PikkuEventTypes[]
|
|
40
|
+
) => {
|
|
32
41
|
const statement = `import '${getFileImportRelativePath(cliConfig.bootstrapFile, from, cliConfig.packageMappings)}'`
|
|
33
42
|
if (type === 'meta') {
|
|
34
|
-
|
|
43
|
+
boostrapImports.all.meta.push(statement)
|
|
35
44
|
} else {
|
|
36
|
-
|
|
45
|
+
boostrapImports.all.events.push(statement)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (const transport of Object.keys(PikkuEventTypes)) {
|
|
49
|
+
if (!addTo || addTo?.includes(transport as PikkuEventTypes)) {
|
|
50
|
+
boostrapImports[transport] = boostrapImports[transport] || {
|
|
51
|
+
meta: [],
|
|
52
|
+
events: [],
|
|
53
|
+
}
|
|
54
|
+
if (type === 'meta') {
|
|
55
|
+
boostrapImports[transport].meta.push(statement)
|
|
56
|
+
} else {
|
|
57
|
+
boostrapImports[transport].events.push(statement)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
37
60
|
}
|
|
38
61
|
}
|
|
39
62
|
|
|
@@ -69,33 +92,33 @@ const runAll = async (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
|
|
|
69
92
|
|
|
70
93
|
await pikkuRPC(cliConfig, visitState)
|
|
71
94
|
await pikkuRPCMap(cliConfig, visitState)
|
|
72
|
-
addImport(cliConfig.rpcMetaFile, 'meta')
|
|
95
|
+
addImport(cliConfig.rpcMetaFile, 'meta', [PikkuEventTypes.rpc])
|
|
96
|
+
|
|
97
|
+
const schemas = await pikkuSchemas(cliConfig, visitState)
|
|
98
|
+
if (schemas) {
|
|
99
|
+
addImport(`${cliConfig.schemaDirectory}/register.gen.ts`, 'other')
|
|
100
|
+
}
|
|
73
101
|
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
102
|
+
const http = await pikkuHTTP(cliConfig, visitState)
|
|
103
|
+
if (http) {
|
|
76
104
|
await pikkuHTTPMap(cliConfig, visitState)
|
|
77
105
|
await pikkuFetch(cliConfig)
|
|
78
|
-
addImport(cliConfig.httpRoutesMetaFile, 'meta')
|
|
79
|
-
addImport(cliConfig.httpRoutesFile, 'events')
|
|
106
|
+
addImport(cliConfig.httpRoutesMetaFile, 'meta', [PikkuEventTypes.http])
|
|
107
|
+
addImport(cliConfig.httpRoutesFile, 'events', [PikkuEventTypes.http])
|
|
80
108
|
}
|
|
81
109
|
|
|
82
110
|
const scheduled = await pikkuScheduler(cliConfig, visitState)
|
|
83
111
|
if (scheduled) {
|
|
84
|
-
addImport(cliConfig.schedulersMetaFile, 'meta')
|
|
85
|
-
addImport(cliConfig.schedulersFile, 'events')
|
|
112
|
+
addImport(cliConfig.schedulersMetaFile, 'meta', [PikkuEventTypes.scheduled])
|
|
113
|
+
addImport(cliConfig.schedulersFile, 'events', [PikkuEventTypes.scheduled])
|
|
86
114
|
}
|
|
87
115
|
|
|
88
116
|
const channels = await pikkuChannels(cliConfig, visitState)
|
|
89
117
|
if (channels) {
|
|
90
118
|
await pikkuChannelsMap(cliConfig, visitState)
|
|
91
119
|
await pikkuWebSocket(cliConfig)
|
|
92
|
-
addImport(cliConfig.channelsMetaFile, 'meta')
|
|
93
|
-
addImport(cliConfig.channelsFile, 'events')
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const schemas = await pikkuSchemas(cliConfig, visitState)
|
|
97
|
-
if (schemas) {
|
|
98
|
-
addImport(`${cliConfig.schemaDirectory}/register.gen.ts`, 'other')
|
|
120
|
+
addImport(cliConfig.channelsMetaFile, 'meta', [PikkuEventTypes.channel])
|
|
121
|
+
addImport(cliConfig.channelsFile, 'events', [PikkuEventTypes.channel])
|
|
99
122
|
}
|
|
100
123
|
|
|
101
124
|
if (cliConfig.nextBackendFile || cliConfig.nextHTTPFile) {
|
|
@@ -112,10 +135,12 @@ const runAll = async (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
|
|
|
112
135
|
await pikkuOpenAPI(cliConfig, visitState)
|
|
113
136
|
}
|
|
114
137
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
for (const [type, { meta, events }] of Object.entries(boostrapImports)) {
|
|
139
|
+
await writeFileInDir(
|
|
140
|
+
type === 'all' ? cliConfig.bootstrapFile : cliConfig.bootstrapFiles[type],
|
|
141
|
+
[...meta, ...events].join('\n')
|
|
142
|
+
)
|
|
143
|
+
}
|
|
119
144
|
}
|
|
120
145
|
|
|
121
146
|
const watch = (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
|
package/bin/pikku-nextjs.ts
CHANGED
|
@@ -17,11 +17,10 @@ export const pikkuNext = async (
|
|
|
17
17
|
{
|
|
18
18
|
nextBackendFile,
|
|
19
19
|
nextHTTPFile,
|
|
20
|
-
httpRoutesFile,
|
|
21
20
|
httpRoutesMapDeclarationFile,
|
|
22
|
-
schemaDirectory,
|
|
23
21
|
packageMappings,
|
|
24
22
|
fetchFile,
|
|
23
|
+
bootstrapFiles,
|
|
25
24
|
}: PikkuCLIConfig,
|
|
26
25
|
visitState: InspectorState,
|
|
27
26
|
options: PikkuCLIOptions
|
|
@@ -67,9 +66,9 @@ export const pikkuNext = async (
|
|
|
67
66
|
const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextBackendFile, singletonServicesFactory.file, packageMappings)}'`
|
|
68
67
|
const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextBackendFile, sessionServicesFactory.file, packageMappings)}'`
|
|
69
68
|
|
|
70
|
-
const
|
|
69
|
+
const httpBootstrapPath = getFileImportRelativePath(
|
|
71
70
|
nextBackendFile,
|
|
72
|
-
|
|
71
|
+
bootstrapFiles.http,
|
|
73
72
|
packageMappings
|
|
74
73
|
)
|
|
75
74
|
|
|
@@ -78,16 +77,10 @@ export const pikkuNext = async (
|
|
|
78
77
|
httpRoutesMapDeclarationFile,
|
|
79
78
|
packageMappings
|
|
80
79
|
)
|
|
81
|
-
const schemasPath = getFileImportRelativePath(
|
|
82
|
-
nextBackendFile,
|
|
83
|
-
`${schemaDirectory}/register.gen.ts`,
|
|
84
|
-
packageMappings
|
|
85
|
-
)
|
|
86
80
|
|
|
87
81
|
const content = serializeNextBackendWrapper(
|
|
88
|
-
|
|
82
|
+
httpBootstrapPath,
|
|
89
83
|
routesMapDeclarationPath,
|
|
90
|
-
schemasPath,
|
|
91
84
|
pikkuConfigImport,
|
|
92
85
|
singletonServicesImport,
|
|
93
86
|
sessionServicesImport
|
|
@@ -95,22 +88,22 @@ export const pikkuNext = async (
|
|
|
95
88
|
await writeFileInDir(nextBackendFile, content)
|
|
96
89
|
}
|
|
97
90
|
|
|
98
|
-
if (nextHTTPFile) {
|
|
99
|
-
const
|
|
91
|
+
if (nextHTTPFile && fetchFile) {
|
|
92
|
+
const routesMapDeclarationPath = getFileImportRelativePath(
|
|
100
93
|
nextHTTPFile,
|
|
101
|
-
|
|
94
|
+
httpRoutesMapDeclarationFile,
|
|
102
95
|
packageMappings
|
|
103
96
|
)
|
|
104
97
|
|
|
105
|
-
const
|
|
98
|
+
const fetchPath = getFileImportRelativePath(
|
|
106
99
|
nextHTTPFile,
|
|
107
|
-
|
|
100
|
+
fetchFile,
|
|
108
101
|
packageMappings
|
|
109
102
|
)
|
|
110
103
|
|
|
111
104
|
const content = serializeNextHTTPWrapper(
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
routesMapDeclarationPath,
|
|
106
|
+
fetchPath
|
|
114
107
|
)
|
|
115
108
|
await writeFileInDir(nextHTTPFile, content)
|
|
116
109
|
}
|
package/dist/bin/pikku-all.js
CHANGED
|
@@ -17,16 +17,32 @@ import chokidar from 'chokidar';
|
|
|
17
17
|
import { pikkuFunctions } from './pikku-functions.js';
|
|
18
18
|
import { pikkuRPC } from './pikku-rpc.js';
|
|
19
19
|
import { pikkuRPCMap } from './pikku-rpc-map.js';
|
|
20
|
+
import { PikkuEventTypes } from '@pikku/core';
|
|
20
21
|
const runAll = async (cliConfig, options) => {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const boostrapImports = {
|
|
23
|
+
all: { meta: [], events: [] },
|
|
24
|
+
};
|
|
25
|
+
const addImport = (from, type, addTo) => {
|
|
24
26
|
const statement = `import '${getFileImportRelativePath(cliConfig.bootstrapFile, from, cliConfig.packageMappings)}'`;
|
|
25
27
|
if (type === 'meta') {
|
|
26
|
-
|
|
28
|
+
boostrapImports.all.meta.push(statement);
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
|
-
|
|
31
|
+
boostrapImports.all.events.push(statement);
|
|
32
|
+
}
|
|
33
|
+
for (const transport of Object.keys(PikkuEventTypes)) {
|
|
34
|
+
if (!addTo || addTo?.includes(transport)) {
|
|
35
|
+
boostrapImports[transport] = boostrapImports[transport] || {
|
|
36
|
+
meta: [],
|
|
37
|
+
events: [],
|
|
38
|
+
};
|
|
39
|
+
if (type === 'meta') {
|
|
40
|
+
boostrapImports[transport].meta.push(statement);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
boostrapImports[transport].events.push(statement);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
30
46
|
}
|
|
31
47
|
};
|
|
32
48
|
let typesDeclarationFileExists = true;
|
|
@@ -49,29 +65,29 @@ const runAll = async (cliConfig, options) => {
|
|
|
49
65
|
addImport(cliConfig.functionsFile, 'events');
|
|
50
66
|
await pikkuRPC(cliConfig, visitState);
|
|
51
67
|
await pikkuRPCMap(cliConfig, visitState);
|
|
52
|
-
addImport(cliConfig.rpcMetaFile, 'meta');
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
68
|
+
addImport(cliConfig.rpcMetaFile, 'meta', [PikkuEventTypes.rpc]);
|
|
69
|
+
const schemas = await pikkuSchemas(cliConfig, visitState);
|
|
70
|
+
if (schemas) {
|
|
71
|
+
addImport(`${cliConfig.schemaDirectory}/register.gen.ts`, 'other');
|
|
72
|
+
}
|
|
73
|
+
const http = await pikkuHTTP(cliConfig, visitState);
|
|
74
|
+
if (http) {
|
|
55
75
|
await pikkuHTTPMap(cliConfig, visitState);
|
|
56
76
|
await pikkuFetch(cliConfig);
|
|
57
|
-
addImport(cliConfig.httpRoutesMetaFile, 'meta');
|
|
58
|
-
addImport(cliConfig.httpRoutesFile, 'events');
|
|
77
|
+
addImport(cliConfig.httpRoutesMetaFile, 'meta', [PikkuEventTypes.http]);
|
|
78
|
+
addImport(cliConfig.httpRoutesFile, 'events', [PikkuEventTypes.http]);
|
|
59
79
|
}
|
|
60
80
|
const scheduled = await pikkuScheduler(cliConfig, visitState);
|
|
61
81
|
if (scheduled) {
|
|
62
|
-
addImport(cliConfig.schedulersMetaFile, 'meta');
|
|
63
|
-
addImport(cliConfig.schedulersFile, 'events');
|
|
82
|
+
addImport(cliConfig.schedulersMetaFile, 'meta', [PikkuEventTypes.scheduled]);
|
|
83
|
+
addImport(cliConfig.schedulersFile, 'events', [PikkuEventTypes.scheduled]);
|
|
64
84
|
}
|
|
65
85
|
const channels = await pikkuChannels(cliConfig, visitState);
|
|
66
86
|
if (channels) {
|
|
67
87
|
await pikkuChannelsMap(cliConfig, visitState);
|
|
68
88
|
await pikkuWebSocket(cliConfig);
|
|
69
|
-
addImport(cliConfig.channelsMetaFile, 'meta');
|
|
70
|
-
addImport(cliConfig.channelsFile, 'events');
|
|
71
|
-
}
|
|
72
|
-
const schemas = await pikkuSchemas(cliConfig, visitState);
|
|
73
|
-
if (schemas) {
|
|
74
|
-
addImport(`${cliConfig.schemaDirectory}/register.gen.ts`, 'other');
|
|
89
|
+
addImport(cliConfig.channelsMetaFile, 'meta', [PikkuEventTypes.channel]);
|
|
90
|
+
addImport(cliConfig.channelsFile, 'events', [PikkuEventTypes.channel]);
|
|
75
91
|
}
|
|
76
92
|
if (cliConfig.nextBackendFile || cliConfig.nextHTTPFile) {
|
|
77
93
|
await pikkuNext(cliConfig, visitState, options);
|
|
@@ -81,7 +97,9 @@ const runAll = async (cliConfig, options) => {
|
|
|
81
97
|
visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.srcDirectories, cliConfig.filters);
|
|
82
98
|
await pikkuOpenAPI(cliConfig, visitState);
|
|
83
99
|
}
|
|
84
|
-
|
|
100
|
+
for (const [type, { meta, events }] of Object.entries(boostrapImports)) {
|
|
101
|
+
await writeFileInDir(type === 'all' ? cliConfig.bootstrapFile : cliConfig.bootstrapFiles[type], [...meta, ...events].join('\n'));
|
|
102
|
+
}
|
|
85
103
|
};
|
|
86
104
|
const watch = (cliConfig, options) => {
|
|
87
105
|
const configWatcher = chokidar.watch(cliConfig.srcDirectories, {
|
|
@@ -2,7 +2,7 @@ import { logCommandInfoAndTime, writeFileInDir } from '../src/utils/utils.js';
|
|
|
2
2
|
import { serializeTypedChannelsMap } from '../src/serialize-typed-channel-map.js';
|
|
3
3
|
export const pikkuChannelsMap = async ({ channelsMapDeclarationFile, packageMappings }, state) => {
|
|
4
4
|
return await logCommandInfoAndTime('Creating channels map', 'Created channels map', [state.channels.files.size === 0], async () => {
|
|
5
|
-
const content = serializeTypedChannelsMap(channelsMapDeclarationFile, packageMappings, state.functions.typesMap, state.channels.meta);
|
|
5
|
+
const content = serializeTypedChannelsMap(channelsMapDeclarationFile, packageMappings, state.functions.typesMap, state.functions.meta, state.channels.meta);
|
|
6
6
|
await writeFileInDir(channelsMapDeclarationFile, content);
|
|
7
7
|
});
|
|
8
8
|
};
|
|
@@ -2,6 +2,6 @@ import { Command } from 'commander';
|
|
|
2
2
|
import { PikkuCLIOptions } from '../src/utils/utils.js';
|
|
3
3
|
import { PikkuCLIConfig } from '../src/pikku-cli-config.js';
|
|
4
4
|
import { InspectorState } from '@pikku/inspector';
|
|
5
|
-
export declare const pikkuNext: ({ nextBackendFile, nextHTTPFile,
|
|
5
|
+
export declare const pikkuNext: ({ nextBackendFile, nextHTTPFile, httpRoutesMapDeclarationFile, packageMappings, fetchFile, bootstrapFiles, }: PikkuCLIConfig, visitState: InspectorState, options: PikkuCLIOptions) => Promise<boolean>;
|
|
6
6
|
export declare const action: (options: PikkuCLIOptions) => Promise<void>;
|
|
7
7
|
export declare const nextjs: (program: Command) => void;
|
package/dist/bin/pikku-nextjs.js
CHANGED
|
@@ -3,7 +3,7 @@ import { serializeNextJsHTTPWrapper as serializeNextHTTPWrapper } from '../src/s
|
|
|
3
3
|
import { getFileImportRelativePath, getPikkuFilesAndMethods, logCommandInfoAndTime, logPikkuLogo, writeFileInDir, } from '../src/utils/utils.js';
|
|
4
4
|
import { getPikkuCLIConfig } from '../src/pikku-cli-config.js';
|
|
5
5
|
import { inspectorGlob } from '../src/inspector-glob.js';
|
|
6
|
-
export const pikkuNext = async ({ nextBackendFile, nextHTTPFile,
|
|
6
|
+
export const pikkuNext = async ({ nextBackendFile, nextHTTPFile, httpRoutesMapDeclarationFile, packageMappings, fetchFile, bootstrapFiles, }, visitState, options) => {
|
|
7
7
|
return await logCommandInfoAndTime('Generating nextjs wrapper', 'Generated nextjs wrapper', [
|
|
8
8
|
nextBackendFile === undefined && nextHTTPFile === undefined,
|
|
9
9
|
'nextjs outfile is not defined',
|
|
@@ -23,16 +23,15 @@ export const pikkuNext = async ({ nextBackendFile, nextHTTPFile, httpRoutesFile,
|
|
|
23
23
|
const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextBackendFile, pikkuConfigFactory.file, packageMappings)}'`;
|
|
24
24
|
const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextBackendFile, singletonServicesFactory.file, packageMappings)}'`;
|
|
25
25
|
const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextBackendFile, sessionServicesFactory.file, packageMappings)}'`;
|
|
26
|
-
const
|
|
26
|
+
const httpBootstrapPath = getFileImportRelativePath(nextBackendFile, bootstrapFiles.http, packageMappings);
|
|
27
27
|
const routesMapDeclarationPath = getFileImportRelativePath(nextBackendFile, httpRoutesMapDeclarationFile, packageMappings);
|
|
28
|
-
const
|
|
29
|
-
const content = serializeNextBackendWrapper(routesPath, routesMapDeclarationPath, schemasPath, pikkuConfigImport, singletonServicesImport, sessionServicesImport);
|
|
28
|
+
const content = serializeNextBackendWrapper(httpBootstrapPath, routesMapDeclarationPath, pikkuConfigImport, singletonServicesImport, sessionServicesImport);
|
|
30
29
|
await writeFileInDir(nextBackendFile, content);
|
|
31
30
|
}
|
|
32
|
-
if (nextHTTPFile) {
|
|
33
|
-
const routesPath = getFileImportRelativePath(nextHTTPFile, httpRoutesFile, packageMappings);
|
|
31
|
+
if (nextHTTPFile && fetchFile) {
|
|
34
32
|
const routesMapDeclarationPath = getFileImportRelativePath(nextHTTPFile, httpRoutesMapDeclarationFile, packageMappings);
|
|
35
|
-
const
|
|
33
|
+
const fetchPath = getFileImportRelativePath(nextHTTPFile, fetchFile, packageMappings);
|
|
34
|
+
const content = serializeNextHTTPWrapper(routesMapDeclarationPath, fetchPath);
|
|
36
35
|
await writeFileInDir(nextHTTPFile, content);
|
|
37
36
|
}
|
|
38
37
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OpenAPISpecInfo } from './openapi-spec-generator.js';
|
|
2
2
|
import { InspectorFilters } from '@pikku/inspector';
|
|
3
|
+
import { PikkuEventTypes } from '@pikku/core';
|
|
3
4
|
export interface PikkuCLICoreOutputFiles {
|
|
4
5
|
outDir?: string;
|
|
5
6
|
schemaDirectory: string;
|
|
@@ -17,6 +18,7 @@ export interface PikkuCLICoreOutputFiles {
|
|
|
17
18
|
schedulersFile: string;
|
|
18
19
|
schedulersMetaFile: string;
|
|
19
20
|
bootstrapFile: string;
|
|
21
|
+
bootstrapFiles: Record<PikkuEventTypes, string>;
|
|
20
22
|
}
|
|
21
23
|
export type PikkuCLIConfig = {
|
|
22
24
|
$schema?: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join, dirname, resolve, isAbsolute } from 'path';
|
|
2
2
|
import { readdir, readFile } from 'fs/promises';
|
|
3
|
+
import { PikkuEventTypes } from '@pikku/core';
|
|
3
4
|
const CONFIG_DIR_FILES = [
|
|
4
5
|
'nextBackendFile',
|
|
5
6
|
'nextHTTPFile',
|
|
@@ -90,7 +91,7 @@ const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags =
|
|
|
90
91
|
result.typesDeclarationFile = join(result.outDir, 'pikku-types.gen.ts');
|
|
91
92
|
}
|
|
92
93
|
if (!result.httpRoutesMapDeclarationFile) {
|
|
93
|
-
result.httpRoutesMapDeclarationFile = join(result.outDir, 'pikku-routes-map.gen.d.ts');
|
|
94
|
+
result.httpRoutesMapDeclarationFile = join(result.outDir, 'pikku-http-routes-map.gen.d.ts');
|
|
94
95
|
}
|
|
95
96
|
if (!result.channelsMapDeclarationFile) {
|
|
96
97
|
result.channelsMapDeclarationFile = join(result.outDir, 'pikku-channels-map.gen.d.ts');
|
|
@@ -98,6 +99,10 @@ const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags =
|
|
|
98
99
|
if (!result.bootstrapFile) {
|
|
99
100
|
result.bootstrapFile = join(result.outDir, 'pikku-bootstrap.gen.ts');
|
|
100
101
|
}
|
|
102
|
+
result.bootstrapFiles = result.bootstrapFiles || {};
|
|
103
|
+
for (const key of Object.keys(PikkuEventTypes)) {
|
|
104
|
+
result.bootstrapFiles[key] = join(result.outDir, `pikku-bootstrap-${key}.gen.ts`);
|
|
105
|
+
}
|
|
101
106
|
}
|
|
102
107
|
if (requiredFields.length > 0) {
|
|
103
108
|
validateCLIConfig(result, requiredFields);
|
|
@@ -28,6 +28,12 @@ export async function generateSchemas(tsconfig, typesMap, functionMeta, httpRout
|
|
|
28
28
|
skipTypeCheck: true,
|
|
29
29
|
topRef: false,
|
|
30
30
|
discriminatorType: 'open-api',
|
|
31
|
+
expose: 'export',
|
|
32
|
+
jsDoc: 'extended',
|
|
33
|
+
sortProps: true,
|
|
34
|
+
strictTuples: false,
|
|
35
|
+
encodeRefs: false,
|
|
36
|
+
additionalProperties: false,
|
|
31
37
|
});
|
|
32
38
|
const schemas = {};
|
|
33
39
|
schemasSet.forEach((schema) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const serializeNextJsBackendWrapper: (
|
|
1
|
+
export declare const serializeNextJsBackendWrapper: (httpBootstrapPath: string, routesMapPath: string, configImport: string, singleServicesFactoryImport: string, sessionServicesImport: string) => string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const serializeNextJsBackendWrapper = (
|
|
1
|
+
export const serializeNextJsBackendWrapper = (httpBootstrapPath, routesMapPath, configImport, singleServicesFactoryImport, sessionServicesImport) => {
|
|
2
2
|
return `'server-only'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -12,8 +12,7 @@ ${configImport}
|
|
|
12
12
|
${singleServicesFactoryImport}
|
|
13
13
|
${sessionServicesImport}
|
|
14
14
|
|
|
15
|
-
import '${
|
|
16
|
-
import '${schemasPath}'
|
|
15
|
+
import '${httpBootstrapPath}'
|
|
17
16
|
|
|
18
17
|
let _pikku: PikkuNextJS | undefined
|
|
19
18
|
|
|
@@ -7,11 +7,10 @@ export const serializeNextJsHTTPWrapper = (routesMapPath, pikkuFetchImport) => {
|
|
|
7
7
|
*/
|
|
8
8
|
import { CorePikkuFetchOptions } from '@pikku/fetch'
|
|
9
9
|
import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
|
|
10
|
+
import { PikkuFetch } from '${pikkuFetchImport}'
|
|
10
11
|
|
|
11
12
|
let _pikku: PikkuFetch | undefined
|
|
12
13
|
|
|
13
|
-
${pikkuFetchImport}
|
|
14
|
-
|
|
15
14
|
/**
|
|
16
15
|
* Initializes and returns an instance of PikkuNextJS with helper methods for handling route requests.
|
|
17
16
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ChannelsMeta } from '@pikku/core/channel';
|
|
2
2
|
import { TypesMap } from '@pikku/inspector';
|
|
3
|
-
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import { serializeImportMap } from './utils/serialize-import-map.js';
|
|
2
2
|
import { generateCustomTypes } from './utils/utils.js';
|
|
3
|
-
export const serializeTypedChannelsMap = (relativeToPath, packageMappings, typesMap, channelsMeta) => {
|
|
4
|
-
const { channels, requiredTypes } = generateChannels(channelsMeta);
|
|
3
|
+
export const serializeTypedChannelsMap = (relativeToPath, packageMappings, typesMap, functionsMeta, channelsMeta) => {
|
|
4
|
+
const { channels, requiredTypes } = generateChannels(functionsMeta, channelsMeta);
|
|
5
5
|
typesMap.customTypes.forEach(({ references }) => {
|
|
6
6
|
for (const reference of references) {
|
|
7
7
|
requiredTypes.add(reference);
|
|
@@ -38,21 +38,39 @@ export type ChannelRouteHandlerOf<
|
|
|
38
38
|
: never;
|
|
39
39
|
`;
|
|
40
40
|
};
|
|
41
|
-
function generateChannels(channelsMeta) {
|
|
41
|
+
function generateChannels(functionsMeta, channelsMeta) {
|
|
42
42
|
const requiredTypes = new Set();
|
|
43
43
|
const channelsObject = {};
|
|
44
44
|
for (const meta of Object.values(channelsMeta)) {
|
|
45
45
|
const { name, messageRoutes, message } = meta;
|
|
46
46
|
if (!channelsObject[name]) {
|
|
47
|
-
channelsObject[name] = { message, routes: {} };
|
|
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));
|
|
48
62
|
}
|
|
49
63
|
for (const [key, route] of Object.entries(messageRoutes)) {
|
|
50
64
|
if (!channelsObject[name].routes[key]) {
|
|
51
65
|
channelsObject[name].routes[key] = {};
|
|
52
66
|
}
|
|
53
|
-
for (const [method, {
|
|
54
|
-
const
|
|
55
|
-
|
|
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;
|
|
56
74
|
channelsObject[name].routes[key][method] = {
|
|
57
75
|
inputTypes,
|
|
58
76
|
outputTypes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
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.7.
|
|
26
|
-
"@pikku/inspector": "^0.7.
|
|
25
|
+
"@pikku/core": "^0.7.8",
|
|
26
|
+
"@pikku/inspector": "^0.7.7",
|
|
27
27
|
"@types/cookie": "^0.6.0",
|
|
28
28
|
"@types/uuid": "^10.0.0",
|
|
29
29
|
"chalk": "^5.4.1",
|
package/src/pikku-cli-config.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { join, dirname, resolve, isAbsolute } from 'path'
|
|
|
2
2
|
import { readdir, readFile } from 'fs/promises'
|
|
3
3
|
import { OpenAPISpecInfo } from './openapi-spec-generator.js'
|
|
4
4
|
import { InspectorFilters } from '@pikku/inspector'
|
|
5
|
+
import { PikkuEventTypes } from '@pikku/core'
|
|
5
6
|
|
|
6
7
|
export interface PikkuCLICoreOutputFiles {
|
|
7
8
|
// Base directory
|
|
@@ -35,6 +36,7 @@ export interface PikkuCLICoreOutputFiles {
|
|
|
35
36
|
|
|
36
37
|
// Application bootstrap
|
|
37
38
|
bootstrapFile: string
|
|
39
|
+
bootstrapFiles: Record<PikkuEventTypes, string>
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export type PikkuCLIConfig = {
|
|
@@ -194,7 +196,7 @@ const _getPikkuCLIConfig = async (
|
|
|
194
196
|
if (!result.httpRoutesMapDeclarationFile) {
|
|
195
197
|
result.httpRoutesMapDeclarationFile = join(
|
|
196
198
|
result.outDir,
|
|
197
|
-
'pikku-routes-map.gen.d.ts'
|
|
199
|
+
'pikku-http-routes-map.gen.d.ts'
|
|
198
200
|
)
|
|
199
201
|
}
|
|
200
202
|
if (!result.channelsMapDeclarationFile) {
|
|
@@ -206,6 +208,14 @@ const _getPikkuCLIConfig = async (
|
|
|
206
208
|
if (!result.bootstrapFile) {
|
|
207
209
|
result.bootstrapFile = join(result.outDir, 'pikku-bootstrap.gen.ts')
|
|
208
210
|
}
|
|
211
|
+
|
|
212
|
+
result.bootstrapFiles = result.bootstrapFiles || {}
|
|
213
|
+
for (const key of Object.keys(PikkuEventTypes)) {
|
|
214
|
+
result.bootstrapFiles[key] = join(
|
|
215
|
+
result.outDir,
|
|
216
|
+
`pikku-bootstrap-${key}.gen.ts`
|
|
217
|
+
)
|
|
218
|
+
}
|
|
209
219
|
}
|
|
210
220
|
|
|
211
221
|
if (requiredFields.length > 0) {
|
package/src/schema-generator.ts
CHANGED
|
@@ -38,6 +38,12 @@ export async function generateSchemas(
|
|
|
38
38
|
skipTypeCheck: true,
|
|
39
39
|
topRef: false,
|
|
40
40
|
discriminatorType: 'open-api',
|
|
41
|
+
expose: 'export',
|
|
42
|
+
jsDoc: 'extended',
|
|
43
|
+
sortProps: true,
|
|
44
|
+
strictTuples: false,
|
|
45
|
+
encodeRefs: false,
|
|
46
|
+
additionalProperties: false,
|
|
41
47
|
})
|
|
42
48
|
const schemas: Record<string, JSONValue> = {}
|
|
43
49
|
schemasSet.forEach((schema) => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export const serializeNextJsBackendWrapper = (
|
|
2
|
-
|
|
2
|
+
httpBootstrapPath: string,
|
|
3
3
|
routesMapPath: string,
|
|
4
|
-
schemasPath: string,
|
|
5
4
|
configImport: string,
|
|
6
5
|
singleServicesFactoryImport: string,
|
|
7
6
|
sessionServicesImport: string
|
|
@@ -19,8 +18,7 @@ ${configImport}
|
|
|
19
18
|
${singleServicesFactoryImport}
|
|
20
19
|
${sessionServicesImport}
|
|
21
20
|
|
|
22
|
-
import '${
|
|
23
|
-
import '${schemasPath}'
|
|
21
|
+
import '${httpBootstrapPath}'
|
|
24
22
|
|
|
25
23
|
let _pikku: PikkuNextJS | undefined
|
|
26
24
|
|
|
@@ -10,11 +10,10 @@ export const serializeNextJsHTTPWrapper = (
|
|
|
10
10
|
*/
|
|
11
11
|
import { CorePikkuFetchOptions } from '@pikku/fetch'
|
|
12
12
|
import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
|
|
13
|
+
import { PikkuFetch } from '${pikkuFetchImport}'
|
|
13
14
|
|
|
14
15
|
let _pikku: PikkuFetch | undefined
|
|
15
16
|
|
|
16
|
-
${pikkuFetchImport}
|
|
17
|
-
|
|
18
17
|
/**
|
|
19
18
|
* Initializes and returns an instance of PikkuNextJS with helper methods for handling route requests.
|
|
20
19
|
*
|
|
@@ -2,14 +2,19 @@ import { ChannelsMeta } from '@pikku/core/channel'
|
|
|
2
2
|
import { serializeImportMap } from './utils/serialize-import-map.js'
|
|
3
3
|
import { TypesMap } from '@pikku/inspector'
|
|
4
4
|
import { generateCustomTypes } from './utils/utils.js'
|
|
5
|
+
import { FunctionsMeta } from '@pikku/core'
|
|
5
6
|
|
|
6
7
|
export const serializeTypedChannelsMap = (
|
|
7
8
|
relativeToPath: string,
|
|
8
9
|
packageMappings: Record<string, string>,
|
|
9
10
|
typesMap: TypesMap,
|
|
11
|
+
functionsMeta: FunctionsMeta,
|
|
10
12
|
channelsMeta: ChannelsMeta
|
|
11
13
|
): string => {
|
|
12
|
-
const { channels, requiredTypes } = generateChannels(
|
|
14
|
+
const { channels, requiredTypes } = generateChannels(
|
|
15
|
+
functionsMeta,
|
|
16
|
+
channelsMeta
|
|
17
|
+
)
|
|
13
18
|
typesMap.customTypes.forEach(({ references }) => {
|
|
14
19
|
for (const reference of references) {
|
|
15
20
|
requiredTypes.add(reference)
|
|
@@ -52,7 +57,10 @@ export type ChannelRouteHandlerOf<
|
|
|
52
57
|
`
|
|
53
58
|
}
|
|
54
59
|
|
|
55
|
-
function generateChannels(
|
|
60
|
+
function generateChannels(
|
|
61
|
+
functionsMeta: FunctionsMeta,
|
|
62
|
+
channelsMeta: ChannelsMeta
|
|
63
|
+
) {
|
|
56
64
|
const requiredTypes = new Set<string>()
|
|
57
65
|
const channelsObject: Record<
|
|
58
66
|
string,
|
|
@@ -75,16 +83,39 @@ function generateChannels(channelsMeta: ChannelsMeta) {
|
|
|
75
83
|
const { name, messageRoutes, message } = meta
|
|
76
84
|
|
|
77
85
|
if (!channelsObject[name]) {
|
|
78
|
-
channelsObject[name] = { message, routes: {} }
|
|
86
|
+
channelsObject[name] = { message: null, routes: {} }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (message) {
|
|
90
|
+
const func = functionsMeta[message.pikkuFuncName]
|
|
91
|
+
if (!func) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Function ${message.pikkuFuncName} not found in functionsMeta for channel ${name}`
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
const inputTypes = func.inputs || null
|
|
97
|
+
const outputTypes = func.outputs || null
|
|
98
|
+
channelsObject[name].message = {
|
|
99
|
+
inputs: inputTypes,
|
|
100
|
+
outputs: outputTypes,
|
|
101
|
+
}
|
|
102
|
+
inputTypes?.forEach((type) => requiredTypes.add(type))
|
|
103
|
+
outputTypes?.forEach((type) => requiredTypes.add(type))
|
|
79
104
|
}
|
|
80
105
|
|
|
81
106
|
for (const [key, route] of Object.entries(messageRoutes)) {
|
|
82
107
|
if (!channelsObject[name].routes[key]) {
|
|
83
108
|
channelsObject[name].routes[key] = {}
|
|
84
109
|
}
|
|
85
|
-
for (const [method, {
|
|
86
|
-
const
|
|
87
|
-
|
|
110
|
+
for (const [method, { pikkuFuncName }] of Object.entries(route)) {
|
|
111
|
+
const func = functionsMeta[pikkuFuncName]
|
|
112
|
+
if (!func) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
`Function ${pikkuFuncName} not found in functionsMeta for channel ${name}, route ${key}, method ${method}`
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
const inputTypes = func.inputs || null
|
|
118
|
+
const outputTypes = func.outputs || null
|
|
88
119
|
channelsObject[name].routes[key][method] = {
|
|
89
120
|
inputTypes,
|
|
90
121
|
outputTypes,
|