@pikku/cli 0.7.5 → 0.7.6

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @pikku/cli
2
2
 
3
+ ## 0.7.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 8b4f52e: refactor: moving schemas in channels to functions
8
+ - 1d70184: feat: adding multiple bootstrap files for different transports
9
+ - 5c4f56f: fix: adding more options to schema generator to support complex types
10
+ - a9427b8: fix: import bootstrap file to include all rpc/function code in nextjs wrapper
11
+ - Updated dependencies [8b4f52e]
12
+ - Updated dependencies [8b4f52e]
13
+ - Updated dependencies [1d70184]
14
+ - @pikku/core@0.7.8
15
+ - @pikku/inspector@0.7.7
16
+
3
17
  ## 0.7.5
4
18
 
5
19
  ### 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 metaImports: string[] = []
30
- const imports: string[] = []
31
- const addImport = (from: string, type: 'meta' | 'events' | 'other') => {
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
- metaImports.push(statement)
43
+ boostrapImports.all.meta.push(statement)
35
44
  } else {
36
- imports.push(statement)
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 routes = await pikkuHTTP(cliConfig, visitState)
75
- if (routes) {
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
- await writeFileInDir(
116
- cliConfig.bootstrapFile,
117
- [...metaImports, ...imports].join('\n')
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) => {
@@ -16,6 +16,7 @@ export const pikkuChannelsMap = async (
16
16
  channelsMapDeclarationFile,
17
17
  packageMappings,
18
18
  state.functions.typesMap,
19
+ state.functions.meta,
19
20
  state.channels.meta
20
21
  )
21
22
  await writeFileInDir(channelsMapDeclarationFile, content)
@@ -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 routesPath = getFileImportRelativePath(
69
+ const httpBootstrapPath = getFileImportRelativePath(
71
70
  nextBackendFile,
72
- httpRoutesFile,
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
- routesPath,
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 routesPath = getFileImportRelativePath(
91
+ if (nextHTTPFile && fetchFile) {
92
+ const routesMapDeclarationPath = getFileImportRelativePath(
100
93
  nextHTTPFile,
101
- httpRoutesFile,
94
+ httpRoutesMapDeclarationFile,
102
95
  packageMappings
103
96
  )
104
97
 
105
- const routesMapDeclarationPath = getFileImportRelativePath(
98
+ const fetchPath = getFileImportRelativePath(
106
99
  nextHTTPFile,
107
- httpRoutesMapDeclarationFile,
100
+ fetchFile,
108
101
  packageMappings
109
102
  )
110
103
 
111
104
  const content = serializeNextHTTPWrapper(
112
- routesPath,
113
- routesMapDeclarationPath
105
+ routesMapDeclarationPath,
106
+ fetchPath
114
107
  )
115
108
  await writeFileInDir(nextHTTPFile, content)
116
109
  }
@@ -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 metaImports = [];
22
- const imports = [];
23
- const addImport = (from, type) => {
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
- metaImports.push(statement);
28
+ boostrapImports.all.meta.push(statement);
27
29
  }
28
30
  else {
29
- imports.push(statement);
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 routes = await pikkuHTTP(cliConfig, visitState);
54
- if (routes) {
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
- await writeFileInDir(cliConfig.bootstrapFile, [...metaImports, ...imports].join('\n'));
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, httpRoutesFile, httpRoutesMapDeclarationFile, schemaDirectory, packageMappings, fetchFile, }: PikkuCLIConfig, visitState: InspectorState, options: PikkuCLIOptions) => Promise<boolean>;
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;
@@ -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, httpRoutesFile, httpRoutesMapDeclarationFile, schemaDirectory, packageMappings, fetchFile, }, visitState, options) => {
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 routesPath = getFileImportRelativePath(nextBackendFile, httpRoutesFile, packageMappings);
26
+ const httpBootstrapPath = getFileImportRelativePath(nextBackendFile, bootstrapFiles.http, packageMappings);
27
27
  const routesMapDeclarationPath = getFileImportRelativePath(nextBackendFile, httpRoutesMapDeclarationFile, packageMappings);
28
- const schemasPath = getFileImportRelativePath(nextBackendFile, `${schemaDirectory}/register.gen.ts`, packageMappings);
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 content = serializeNextHTTPWrapper(routesPath, routesMapDeclarationPath);
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',
@@ -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: (routesPath: string, routesMapPath: string, schemasPath: string, configImport: string, singleServicesFactoryImport: string, sessionServicesImport: string) => string;
1
+ export declare const serializeNextJsBackendWrapper: (httpBootstrapPath: string, routesMapPath: string, configImport: string, singleServicesFactoryImport: string, sessionServicesImport: string) => string;
@@ -1,4 +1,4 @@
1
- export const serializeNextJsBackendWrapper = (routesPath, routesMapPath, schemasPath, configImport, singleServicesFactoryImport, sessionServicesImport) => {
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 '${routesPath}'
16
- import '${schemasPath}'
15
+ import '${httpBootstrapPath}'
17
16
 
18
17
  let _pikku: PikkuNextJS | undefined
19
18
 
@@ -1,3 +1,4 @@
1
1
  import { ChannelsMeta } from '@pikku/core/channel';
2
2
  import { TypesMap } from '@pikku/inspector';
3
- export declare const serializeTypedChannelsMap: (relativeToPath: string, packageMappings: Record<string, string>, typesMap: TypesMap, channelsMeta: ChannelsMeta) => string;
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, { inputs, outputs }] of Object.entries(route)) {
54
- const inputTypes = inputs || null;
55
- const outputTypes = outputs || null;
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.5",
3
+ "version": "0.7.6",
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.7",
26
- "@pikku/inspector": "^0.7.6",
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",
@@ -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 = {
@@ -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) {
@@ -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
- routesPath: string,
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 '${routesPath}'
23
- import '${schemasPath}'
21
+ import '${httpBootstrapPath}'
24
22
 
25
23
  let _pikku: PikkuNextJS | undefined
26
24
 
@@ -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(channelsMeta)
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(channelsMeta: ChannelsMeta) {
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, { inputs, outputs }] of Object.entries(route)) {
86
- const inputTypes = inputs || null
87
- const outputTypes = outputs || null
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,