@pikku/cli 0.6.16 → 0.6.18

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,23 @@
1
1
  # @pikku/cli
2
2
 
3
+ ## 0.6.18
4
+
5
+ ### Patch Changes
6
+
7
+ - 60b2265: refactor: supporting request and response objects
8
+ - Updated dependencies [60b2265]
9
+ - @pikku/inspector@0.6.4
10
+ - @pikku/core@0.6.22
11
+
12
+ ## 0.6.17
13
+
14
+ ### Patch Changes
15
+
16
+ - 57f5d8c: refactor: moving getSession out of nextjs wrapper since it bundles all routes and only needs middleware
17
+ - 141d690: feat: creating a nextJS http wrapper for proxying
18
+ - e5a5a12: feat: adding watch command (pikki all --watch)
19
+ - 0ad27a2: chore: switching from glon to tinyblobby
20
+
3
21
  ## 0.6.16
4
22
 
5
23
  ### Patch Changes
package/bin/pikku-all.ts CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  PikkuCLIOptions,
7
7
  writeFileInDir,
8
8
  } from '../src/utils.js'
9
- import { getPikkuCLIConfig } from '../src/pikku-cli-config.js'
9
+ import { getPikkuCLIConfig, PikkuCLIConfig } from '../src/pikku-cli-config.js'
10
10
  import { pikkuHTTP } from './pikku-http.js'
11
11
  import { pikkuFunctionTypes } from './pikku-function-types.js'
12
12
  import { pikkuHTTPMap } from './pikku-routes-map.js'
@@ -20,10 +20,9 @@ import { pikkuScheduler } from './pikku-scheduler.js'
20
20
  import { pikkuSchemas } from './pikku-schemas.js'
21
21
  import { pikkuWebSocket } from './pikku-websocket.js'
22
22
  import { inspectorGlob } from '../src/inspector-glob.js'
23
+ import chokidar from 'chokidar'
23
24
 
24
- export const action = async (options: PikkuCLIOptions): Promise<void> => {
25
- logPikkuLogo()
26
-
25
+ const runAll = async (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
27
26
  const imports: string[] = []
28
27
  const addImport = (from: string) => {
29
28
  imports.push(
@@ -31,13 +30,6 @@ export const action = async (options: PikkuCLIOptions): Promise<void> => {
31
30
  )
32
31
  }
33
32
 
34
- const cliConfig = await getPikkuCLIConfig(
35
- options.config,
36
- [],
37
- options.tags,
38
- true
39
- )
40
-
41
33
  let typesDeclarationFileExists = true
42
34
  let visitState = await inspectorGlob(
43
35
  cliConfig.rootDir,
@@ -84,7 +76,9 @@ export const action = async (options: PikkuCLIOptions): Promise<void> => {
84
76
  addImport(`${cliConfig.schemaDirectory}/register.gen.ts`)
85
77
  }
86
78
 
87
- await pikkuNext(cliConfig, visitState, options)
79
+ if (cliConfig.nextBackendFile || cliConfig.nextHTTPFile) {
80
+ await pikkuNext(cliConfig, visitState, options)
81
+ }
88
82
 
89
83
  if (cliConfig.openAPI) {
90
84
  logInfo(`• OpenAPI requires a reinspection to pickup new generated types..`)
@@ -99,6 +93,73 @@ export const action = async (options: PikkuCLIOptions): Promise<void> => {
99
93
  await writeFileInDir(cliConfig.bootstrapFile, imports.join('\n'))
100
94
  }
101
95
 
96
+ const watch = (cliConfig: PikkuCLIConfig, options: PikkuCLIOptions) => {
97
+ const configWatcher = chokidar.watch(cliConfig.routeDirectories, {
98
+ ignoreInitial: true,
99
+ ignored: /.*\.gen\.tsx?/,
100
+ })
101
+
102
+ let watcher = new chokidar.FSWatcher({})
103
+
104
+ const generatorWatcher = () => {
105
+ watcher.close()
106
+
107
+ logInfo(
108
+ `• Watching directories: \n - ${cliConfig.routeDirectories.join('\n - ')}`
109
+ )
110
+ watcher = chokidar.watch(cliConfig.routeDirectories, {
111
+ ignoreInitial: true,
112
+ ignored: /.*\.gen\.ts/,
113
+ })
114
+
115
+ watcher.on('ready', async () => {
116
+ const handle = async () => {
117
+ try {
118
+ await runAll(cliConfig, options)
119
+ } catch (err) {
120
+ console.error(err)
121
+ console.info()
122
+ }
123
+ }
124
+
125
+ await handle()
126
+
127
+ let timeout: ReturnType<typeof setTimeout> | undefined
128
+
129
+ const deduped = (_file: string) => {
130
+ if (timeout) {
131
+ clearTimeout(timeout)
132
+ }
133
+ timeout = setTimeout(handle, 10)
134
+ }
135
+
136
+ watcher.on('change', deduped)
137
+ watcher.on('add', deduped)
138
+ watcher.on('unlink', deduped)
139
+ })
140
+ }
141
+
142
+ configWatcher.on('ready', generatorWatcher)
143
+ configWatcher.on('change', generatorWatcher)
144
+ }
145
+
146
+ export const action = async (options: PikkuCLIOptions): Promise<void> => {
147
+ logPikkuLogo()
148
+
149
+ const cliConfig = await getPikkuCLIConfig(
150
+ options.config,
151
+ [],
152
+ options.tags,
153
+ true
154
+ )
155
+
156
+ if (options.watch) {
157
+ watch(cliConfig, options)
158
+ } else {
159
+ await runAll(cliConfig, options)
160
+ }
161
+ }
162
+
102
163
  export const all = (program: Command): void => {
103
164
  program
104
165
  .command('all', { isDefault: true })
@@ -114,5 +175,6 @@ export const all = (program: Command): void => {
114
175
  )
115
176
  .option('-c | --config <string>', 'The path to pikku cli config file')
116
177
  .option('-t | --tags <tags...>', 'Which tags to filter by')
178
+ .option('-w | --watch', 'Whether to watch file changes')
117
179
  .action(action)
118
180
  }
@@ -1,5 +1,6 @@
1
1
  import { Command } from 'commander'
2
- import { serializeNextJsWrapper } from '../src/nextjs/serialize-nextjs-wrapper.js'
2
+ import { serializeNextJsBackendWrapper as serializeNextBackendWrapper } from '../src/nextjs/serialize-nextjs-backend-wrapper.js'
3
+ import { serializeNextJsHTTPWrapper as serializeNextHTTPWrapper } from '../src/nextjs/serialize-nextjs-http-wrapper.js'
3
4
  import {
4
5
  getFileImportRelativePath,
5
6
  getPikkuFilesAndMethods,
@@ -14,11 +15,13 @@ import { inspectorGlob } from '../src/inspector-glob.js'
14
15
 
15
16
  export const pikkuNext = async (
16
17
  {
17
- nextJSfile,
18
+ nextBackendFile,
19
+ nextHTTPFile,
18
20
  routesFile,
19
21
  routesMapDeclarationFile,
20
22
  schemaDirectory,
21
23
  packageMappings,
24
+ fetchFile,
22
25
  }: PikkuCLIConfig,
23
26
  visitState: InspectorState,
24
27
  options: PikkuCLIOptions
@@ -26,60 +29,91 @@ export const pikkuNext = async (
26
29
  return await logCommandInfoAndTime(
27
30
  'Generating nextjs wrapper',
28
31
  'Generated nextjs wrapper',
29
- [nextJSfile === undefined, 'nextjs outfile is not defined'],
32
+ [
33
+ nextBackendFile === undefined && nextHTTPFile === undefined,
34
+ 'nextjs outfile is not defined',
35
+ ],
30
36
  async () => {
31
- if (!nextJSfile) {
32
- throw new Error('nextJSfile is required in pikku config')
37
+ if (!nextBackendFile && !nextHTTPFile) {
38
+ throw new Error(
39
+ 'nextBackendFile or nextHTTPFile is required in pikku config for nextJS'
40
+ )
33
41
  }
34
42
 
35
- const {
36
- pikkuConfigFactory,
37
- singletonServicesFactory,
38
- sessionServicesFactory,
39
- userSessionType,
40
- } = await getPikkuFilesAndMethods(
41
- visitState,
42
- packageMappings,
43
- nextJSfile,
44
- options,
45
- {
46
- config: true,
47
- singletonServicesFactory: true,
48
- sessionServicesFactory: true,
49
- }
50
- )
43
+ if (nextHTTPFile && !fetchFile) {
44
+ throw new Error(
45
+ 'fetchFile is required in pikku config in order for nextJS http wrapper to work'
46
+ )
47
+ }
48
+
49
+ if (nextBackendFile) {
50
+ const {
51
+ pikkuConfigFactory,
52
+ singletonServicesFactory,
53
+ sessionServicesFactory,
54
+ } = await getPikkuFilesAndMethods(
55
+ visitState,
56
+ packageMappings,
57
+ nextBackendFile,
58
+ options,
59
+ {
60
+ config: true,
61
+ singletonServicesFactory: true,
62
+ sessionServicesFactory: true,
63
+ }
64
+ )
65
+
66
+ const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextBackendFile, pikkuConfigFactory.file, packageMappings)}'`
67
+ const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextBackendFile, singletonServicesFactory.file, packageMappings)}'`
68
+ const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextBackendFile, sessionServicesFactory.file, packageMappings)}'`
69
+
70
+ const routesPath = getFileImportRelativePath(
71
+ nextBackendFile,
72
+ routesFile,
73
+ packageMappings
74
+ )
51
75
 
52
- const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextJSfile, pikkuConfigFactory.file, packageMappings)}'`
53
- const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextJSfile, singletonServicesFactory.file, packageMappings)}'`
54
- const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextJSfile, sessionServicesFactory.file, packageMappings)}'`
55
- const userSessionImport = `import type { ${userSessionType.type} as UserSession } from '${getFileImportRelativePath(nextJSfile, userSessionType.file, packageMappings)}'`
76
+ const routesMapDeclarationPath = getFileImportRelativePath(
77
+ nextBackendFile,
78
+ routesMapDeclarationFile,
79
+ packageMappings
80
+ )
81
+ const schemasPath = getFileImportRelativePath(
82
+ nextBackendFile,
83
+ `${schemaDirectory}/register.gen.ts`,
84
+ packageMappings
85
+ )
56
86
 
57
- const routesPath = getFileImportRelativePath(
58
- nextJSfile,
59
- routesFile,
60
- packageMappings
61
- )
62
- const routesMapDeclarationPath = getFileImportRelativePath(
63
- nextJSfile,
64
- routesMapDeclarationFile,
65
- packageMappings
66
- )
67
- const schemasPath = getFileImportRelativePath(
68
- nextJSfile,
69
- `${schemaDirectory}/register.gen.ts`,
70
- packageMappings
71
- )
87
+ const content = serializeNextBackendWrapper(
88
+ routesPath,
89
+ routesMapDeclarationPath,
90
+ schemasPath,
91
+ pikkuConfigImport,
92
+ singletonServicesImport,
93
+ sessionServicesImport
94
+ )
95
+ await writeFileInDir(nextBackendFile, content)
96
+ }
97
+
98
+ if (nextHTTPFile) {
99
+ const routesPath = getFileImportRelativePath(
100
+ nextHTTPFile,
101
+ routesFile,
102
+ packageMappings
103
+ )
72
104
 
73
- const content = serializeNextJsWrapper(
74
- routesPath,
75
- routesMapDeclarationPath,
76
- schemasPath,
77
- pikkuConfigImport,
78
- singletonServicesImport,
79
- sessionServicesImport,
80
- userSessionImport
81
- )
82
- await writeFileInDir(nextJSfile, content)
105
+ const routesMapDeclarationPath = getFileImportRelativePath(
106
+ nextHTTPFile,
107
+ routesMapDeclarationFile,
108
+ packageMappings
109
+ )
110
+
111
+ const content = serializeNextHTTPWrapper(
112
+ routesPath,
113
+ routesMapDeclarationPath
114
+ )
115
+ await writeFileInDir(nextHTTPFile, content)
116
+ }
83
117
  }
84
118
  )
85
119
  }
@@ -88,7 +122,7 @@ export const action = async (options: PikkuCLIOptions): Promise<void> => {
88
122
  logPikkuLogo()
89
123
  const cliConfig = await getPikkuCLIConfig(
90
124
  options.config,
91
- ['rootDir', 'schemaDirectory', 'configDir', 'nextJSfile'],
125
+ ['rootDir', 'schemaDirectory', 'configDir'],
92
126
  options.tags,
93
127
  true
94
128
  )
@@ -10,6 +10,7 @@ export const pikkuSchemas = async (
10
10
  { tsconfig, schemaDirectory, supportsImportAttributes }: PikkuCLIConfig,
11
11
  { http }: InspectorState
12
12
  ) => {
13
+ console.log('Generating schemas...', supportsImportAttributes)
13
14
  return await logCommandInfoAndTime(
14
15
  'Creating schemas',
15
16
  'Created schemas',
package/cli.schema.json CHANGED
@@ -138,7 +138,10 @@
138
138
  "fetchFile": {
139
139
  "type": "string"
140
140
  },
141
- "nextJSfile": {
141
+ "nextBackendFile": {
142
+ "type": "string"
143
+ },
144
+ "nextHTTPFile": {
142
145
  "type": "string"
143
146
  },
144
147
  "openAPI": {
@@ -13,13 +13,12 @@ import { pikkuScheduler } from './pikku-scheduler.js';
13
13
  import { pikkuSchemas } from './pikku-schemas.js';
14
14
  import { pikkuWebSocket } from './pikku-websocket.js';
15
15
  import { inspectorGlob } from '../src/inspector-glob.js';
16
- export const action = async (options) => {
17
- logPikkuLogo();
16
+ import chokidar from 'chokidar';
17
+ const runAll = async (cliConfig, options) => {
18
18
  const imports = [];
19
19
  const addImport = (from) => {
20
20
  imports.push(`import '${getFileImportRelativePath(cliConfig.bootstrapFile, from, cliConfig.packageMappings)}'`);
21
21
  };
22
- const cliConfig = await getPikkuCLIConfig(options.config, [], options.tags, true);
23
22
  let typesDeclarationFileExists = true;
24
23
  let visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories, cliConfig.filters);
25
24
  if (!existsSync(cliConfig.typesDeclarationFile)) {
@@ -51,7 +50,9 @@ export const action = async (options) => {
51
50
  if (schemas) {
52
51
  addImport(`${cliConfig.schemaDirectory}/register.gen.ts`);
53
52
  }
54
- await pikkuNext(cliConfig, visitState, options);
53
+ if (cliConfig.nextBackendFile || cliConfig.nextHTTPFile) {
54
+ await pikkuNext(cliConfig, visitState, options);
55
+ }
55
56
  if (cliConfig.openAPI) {
56
57
  logInfo(`• OpenAPI requires a reinspection to pickup new generated types..`);
57
58
  visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories, cliConfig.filters);
@@ -59,6 +60,55 @@ export const action = async (options) => {
59
60
  }
60
61
  await writeFileInDir(cliConfig.bootstrapFile, imports.join('\n'));
61
62
  };
63
+ const watch = (cliConfig, options) => {
64
+ const configWatcher = chokidar.watch(cliConfig.routeDirectories, {
65
+ ignoreInitial: true,
66
+ ignored: /.*\.gen\.tsx?/,
67
+ });
68
+ let watcher = new chokidar.FSWatcher({});
69
+ const generatorWatcher = () => {
70
+ watcher.close();
71
+ logInfo(`• Watching directories: \n - ${cliConfig.routeDirectories.join('\n - ')}`);
72
+ watcher = chokidar.watch(cliConfig.routeDirectories, {
73
+ ignoreInitial: true,
74
+ ignored: /.*\.gen\.ts/,
75
+ });
76
+ watcher.on('ready', async () => {
77
+ const handle = async () => {
78
+ try {
79
+ await runAll(cliConfig, options);
80
+ }
81
+ catch (err) {
82
+ console.error(err);
83
+ console.info();
84
+ }
85
+ };
86
+ await handle();
87
+ let timeout;
88
+ const deduped = (_file) => {
89
+ if (timeout) {
90
+ clearTimeout(timeout);
91
+ }
92
+ timeout = setTimeout(handle, 10);
93
+ };
94
+ watcher.on('change', deduped);
95
+ watcher.on('add', deduped);
96
+ watcher.on('unlink', deduped);
97
+ });
98
+ };
99
+ configWatcher.on('ready', generatorWatcher);
100
+ configWatcher.on('change', generatorWatcher);
101
+ };
102
+ export const action = async (options) => {
103
+ logPikkuLogo();
104
+ const cliConfig = await getPikkuCLIConfig(options.config, [], options.tags, true);
105
+ if (options.watch) {
106
+ watch(cliConfig, options);
107
+ }
108
+ else {
109
+ await runAll(cliConfig, options);
110
+ }
111
+ };
62
112
  export const all = (program) => {
63
113
  program
64
114
  .command('all', { isDefault: true })
@@ -68,5 +118,6 @@ export const all = (program) => {
68
118
  .option('-se | --session-services-factory-type', 'The type of your session services factory')
69
119
  .option('-c | --config <string>', 'The path to pikku cli config file')
70
120
  .option('-t | --tags <tags...>', 'Which tags to filter by')
121
+ .option('-w | --watch', 'Whether to watch file changes')
71
122
  .action(action);
72
123
  };
@@ -2,6 +2,6 @@ import { Command } from 'commander';
2
2
  import { PikkuCLIOptions } from '../src/utils.js';
3
3
  import { PikkuCLIConfig } from '../src/pikku-cli-config.js';
4
4
  import { InspectorState } from '@pikku/inspector';
5
- export declare const pikkuNext: ({ nextJSfile, routesFile, routesMapDeclarationFile, schemaDirectory, packageMappings, }: PikkuCLIConfig, visitState: InspectorState, options: PikkuCLIOptions) => Promise<boolean>;
5
+ export declare const pikkuNext: ({ nextBackendFile, nextHTTPFile, routesFile, routesMapDeclarationFile, schemaDirectory, packageMappings, fetchFile, }: 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;
@@ -1,31 +1,45 @@
1
- import { serializeNextJsWrapper } from '../src/nextjs/serialize-nextjs-wrapper.js';
1
+ import { serializeNextJsBackendWrapper as serializeNextBackendWrapper } from '../src/nextjs/serialize-nextjs-backend-wrapper.js';
2
+ import { serializeNextJsHTTPWrapper as serializeNextHTTPWrapper } from '../src/nextjs/serialize-nextjs-http-wrapper.js';
2
3
  import { getFileImportRelativePath, getPikkuFilesAndMethods, logCommandInfoAndTime, logPikkuLogo, writeFileInDir, } from '../src/utils.js';
3
4
  import { getPikkuCLIConfig } from '../src/pikku-cli-config.js';
4
5
  import { inspectorGlob } from '../src/inspector-glob.js';
5
- export const pikkuNext = async ({ nextJSfile, routesFile, routesMapDeclarationFile, schemaDirectory, packageMappings, }, visitState, options) => {
6
- return await logCommandInfoAndTime('Generating nextjs wrapper', 'Generated nextjs wrapper', [nextJSfile === undefined, 'nextjs outfile is not defined'], async () => {
7
- if (!nextJSfile) {
8
- throw new Error('nextJSfile is required in pikku config');
6
+ export const pikkuNext = async ({ nextBackendFile, nextHTTPFile, routesFile, routesMapDeclarationFile, schemaDirectory, packageMappings, fetchFile, }, visitState, options) => {
7
+ return await logCommandInfoAndTime('Generating nextjs wrapper', 'Generated nextjs wrapper', [
8
+ nextBackendFile === undefined && nextHTTPFile === undefined,
9
+ 'nextjs outfile is not defined',
10
+ ], async () => {
11
+ if (!nextBackendFile && !nextHTTPFile) {
12
+ throw new Error('nextBackendFile or nextHTTPFile is required in pikku config for nextJS');
13
+ }
14
+ if (nextHTTPFile && !fetchFile) {
15
+ throw new Error('fetchFile is required in pikku config in order for nextJS http wrapper to work');
16
+ }
17
+ if (nextBackendFile) {
18
+ const { pikkuConfigFactory, singletonServicesFactory, sessionServicesFactory, } = await getPikkuFilesAndMethods(visitState, packageMappings, nextBackendFile, options, {
19
+ config: true,
20
+ singletonServicesFactory: true,
21
+ sessionServicesFactory: true,
22
+ });
23
+ const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextBackendFile, pikkuConfigFactory.file, packageMappings)}'`;
24
+ const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextBackendFile, singletonServicesFactory.file, packageMappings)}'`;
25
+ const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextBackendFile, sessionServicesFactory.file, packageMappings)}'`;
26
+ const routesPath = getFileImportRelativePath(nextBackendFile, routesFile, packageMappings);
27
+ const routesMapDeclarationPath = getFileImportRelativePath(nextBackendFile, routesMapDeclarationFile, packageMappings);
28
+ const schemasPath = getFileImportRelativePath(nextBackendFile, `${schemaDirectory}/register.gen.ts`, packageMappings);
29
+ const content = serializeNextBackendWrapper(routesPath, routesMapDeclarationPath, schemasPath, pikkuConfigImport, singletonServicesImport, sessionServicesImport);
30
+ await writeFileInDir(nextBackendFile, content);
31
+ }
32
+ if (nextHTTPFile) {
33
+ const routesPath = getFileImportRelativePath(nextHTTPFile, routesFile, packageMappings);
34
+ const routesMapDeclarationPath = getFileImportRelativePath(nextHTTPFile, routesMapDeclarationFile, packageMappings);
35
+ const content = serializeNextHTTPWrapper(routesPath, routesMapDeclarationPath);
36
+ await writeFileInDir(nextHTTPFile, content);
9
37
  }
10
- const { pikkuConfigFactory, singletonServicesFactory, sessionServicesFactory, userSessionType, } = await getPikkuFilesAndMethods(visitState, packageMappings, nextJSfile, options, {
11
- config: true,
12
- singletonServicesFactory: true,
13
- sessionServicesFactory: true,
14
- });
15
- const pikkuConfigImport = `import { ${pikkuConfigFactory.variable} as createConfig } from '${getFileImportRelativePath(nextJSfile, pikkuConfigFactory.file, packageMappings)}'`;
16
- const singletonServicesImport = `import { ${singletonServicesFactory.variable} as createSingletonServices } from '${getFileImportRelativePath(nextJSfile, singletonServicesFactory.file, packageMappings)}'`;
17
- const sessionServicesImport = `import { ${sessionServicesFactory.variable} as createSessionServices } from '${getFileImportRelativePath(nextJSfile, sessionServicesFactory.file, packageMappings)}'`;
18
- const userSessionImport = `import type { ${userSessionType.type} as UserSession } from '${getFileImportRelativePath(nextJSfile, userSessionType.file, packageMappings)}'`;
19
- const routesPath = getFileImportRelativePath(nextJSfile, routesFile, packageMappings);
20
- const routesMapDeclarationPath = getFileImportRelativePath(nextJSfile, routesMapDeclarationFile, packageMappings);
21
- const schemasPath = getFileImportRelativePath(nextJSfile, `${schemaDirectory}/register.gen.ts`, packageMappings);
22
- const content = serializeNextJsWrapper(routesPath, routesMapDeclarationPath, schemasPath, pikkuConfigImport, singletonServicesImport, sessionServicesImport, userSessionImport);
23
- await writeFileInDir(nextJSfile, content);
24
38
  });
25
39
  };
26
40
  export const action = async (options) => {
27
41
  logPikkuLogo();
28
- const cliConfig = await getPikkuCLIConfig(options.config, ['rootDir', 'schemaDirectory', 'configDir', 'nextJSfile'], options.tags, true);
42
+ const cliConfig = await getPikkuCLIConfig(options.config, ['rootDir', 'schemaDirectory', 'configDir'], options.tags, true);
29
43
  const visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories, cliConfig.filters);
30
44
  await pikkuNext(cliConfig, visitState, options);
31
45
  };
@@ -3,6 +3,7 @@ import { getPikkuCLIConfig } from '../src/pikku-cli-config.js';
3
3
  import { logCommandInfoAndTime, logPikkuLogo } from '../src/utils.js';
4
4
  import { inspectorGlob } from '../src/inspector-glob.js';
5
5
  export const pikkuSchemas = async ({ tsconfig, schemaDirectory, supportsImportAttributes }, { http }) => {
6
+ console.log('Generating schemas...', supportsImportAttributes);
6
7
  return await logCommandInfoAndTime('Creating schemas', 'Created schemas', [false], async () => {
7
8
  const schemas = await generateSchemas(tsconfig, http.typesMap, http.meta);
8
9
  await saveSchemas(schemaDirectory, schemas, http.typesMap, http.meta, supportsImportAttributes);
@@ -1,5 +1,5 @@
1
1
  import * as path from 'path';
2
- import { glob } from 'glob';
2
+ import { glob } from 'tinyglobby';
3
3
  import { inspect } from '@pikku/inspector';
4
4
  import { logCommandInfoAndTime } from './utils.js';
5
5
  export const inspectorGlob = async (rootDir, routeDirectories, filters) => {
@@ -0,0 +1 @@
1
+ export declare const serializeNextJsBackendWrapper: (routesPath: string, routesMapPath: string, schemasPath: string, configImport: string, singleServicesFactoryImport: string, sessionServicesImport: string) => string;
@@ -1,18 +1,16 @@
1
- export const serializeNextJsWrapper = (routesPath, routesMapPath, schemasPath, configImport, singleServicesFactoryImport, sessionServicesImport, userSessionTypeImport) => {
1
+ export const serializeNextJsBackendWrapper = (routesPath, routesMapPath, schemasPath, configImport, singleServicesFactoryImport, sessionServicesImport) => {
2
2
  return `'server-only'
3
3
 
4
4
  /**
5
5
  * This file provides a wrapper around the PikkuNextJS class to allow for methods to be type checked against your routes.
6
6
  * It ensures type safety for route handling methods when integrating with the @pikku/core framework.
7
7
  */
8
- import { PikkuMiddleware } from '@pikku/core'
9
- import { PikkuNextJS, PikkuNextRequest } from '@pikku/next'
8
+ import { PikkuNextJS } from '@pikku/next'
10
9
  import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
11
10
 
12
11
  ${configImport}
13
12
  ${singleServicesFactoryImport}
14
13
  ${sessionServicesImport}
15
- ${userSessionTypeImport}
16
14
 
17
15
  import '${routesPath}'
18
16
  import '${schemasPath}'
@@ -24,7 +22,7 @@ let _pikku: PikkuNextJS | undefined
24
22
  *
25
23
  * @returns An object containing methods for making dynamic and static action requests, as well as session retrieval.
26
24
  */
27
- export const pikku = () => {
25
+ export const pikku = (_options?: any) => {
28
26
  if (!_pikku) {
29
27
  _pikku = new PikkuNextJS(
30
28
  createConfig as any,
@@ -33,20 +31,6 @@ export const pikku = () => {
33
31
  )
34
32
  }
35
33
 
36
- /**
37
- * Retrieves the user session using the current PikkuNextJS instance.
38
- *
39
- * @param request - The Next.js request object.
40
- * @param middleware - An array of middleware functions to process the request.
41
- * @returns A promise that resolves to the user session.
42
- */
43
- const getSession = async (
44
- request: PikkuNextRequest,
45
- middleware: PikkuMiddleware[]
46
- ): Promise<UserSession | undefined> => {
47
- return _pikku!.getSession(request, middleware) as any
48
- }
49
-
50
34
  /**
51
35
  * Makes a dynamic action request for a specified route and method.
52
36
  * Dynamic requests may access headers and cookies and are therefore unsuitable for precompile stages.
@@ -184,7 +168,6 @@ export const pikku = () => {
184
168
  }
185
169
 
186
170
  return {
187
- getSession,
188
171
  get: dynamicGet,
189
172
  post: dynamicPost,
190
173
  patch: dynamicPatch,
@@ -0,0 +1 @@
1
+ export declare const serializeNextJsHTTPWrapper: (routesMapPath: string, pikkuFetchImport: string) => string;
@@ -0,0 +1,160 @@
1
+ export const serializeNextJsHTTPWrapper = (routesMapPath, pikkuFetchImport) => {
2
+ return `'server-only'
3
+
4
+ /**
5
+ * This file provides a wrapper around the PikkuNextJS class to allow for methods to be type checked against your routes.
6
+ * It ensures type safety for route handling methods when integrating with the @pikku/core framework.
7
+ */
8
+ import { CorePikkuFetchOptions } from '@pikku/fetch'
9
+ import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
10
+
11
+ let _pikku: PikkuFetch | undefined
12
+
13
+ ${pikkuFetchImport}
14
+
15
+ /**
16
+ * Initializes and returns an instance of PikkuNextJS with helper methods for handling route requests.
17
+ *
18
+ * @returns An object containing methods for making dynamic and static action requests, as well as session retrieval.
19
+ */
20
+ export const pikku = (options?: CorePikkuFetchOptions) => {
21
+ if (!_pikku) {
22
+ _pikku = new PikkuFetch(options)
23
+ }
24
+
25
+ const dynamicActionRequest = async <
26
+ Route extends keyof RoutesMap,
27
+ Method extends keyof RoutesMap[Route]
28
+ >(
29
+ route: Route,
30
+ method: Method,
31
+ data: RouteHandlerOf<Route, Method>['input'] = null
32
+ ): Promise<RouteHandlerOf<Route, Method>['output']> => {
33
+ return (_pikku! as any)[(method as string).toLowerCase()](route, data as any)
34
+ }
35
+
36
+ /**
37
+ * Makes a static action request for a specified route and method.
38
+ * Static requests do not depend on headers or cookies and are suitable for precompile stages.
39
+ *
40
+ * @template Route - The route key from the RoutesMap.
41
+ * @template Method - The method key from the specified route.
42
+ * @param route - The route identifier.
43
+ * @param method - The HTTP method to be used for the request.
44
+ * @param data - The input data for the request, defaults to null.
45
+ * @returns A promise that resolves to the output of the route handler.
46
+ */
47
+ const staticActionRequest = async <
48
+ Route extends keyof RoutesMap,
49
+ Method extends keyof RoutesMap[Route]
50
+ >(
51
+ route: Route,
52
+ method: Method,
53
+ data: RouteHandlerOf<Route, Method>['input'] = null
54
+ ): Promise<RouteHandlerOf<Route, Method>['output']> => {
55
+ return (_pikku! as any)[(method as string).toLowerCase()](route, data as any)
56
+ }
57
+
58
+ /**
59
+ * Makes a dynamic POST request for a specified route.
60
+ *
61
+ * @template Route - The route key with the POST method.
62
+ * @param route - The route identifier.
63
+ * @param data - The input data for the POST request, defaults to null.
64
+ * @returns A promise that resolves to the output of the POST handler.
65
+ */
66
+ const dynamicPost = <Route extends RoutesWithMethod<'POST'>>(
67
+ route: Route,
68
+ data: RouteHandlerOf<Route, 'POST'>['input'] = null
69
+ ): Promise<RouteHandlerOf<Route, 'POST'>['output']> => {
70
+ return dynamicActionRequest(route, 'POST', data)
71
+ }
72
+
73
+ /**
74
+ * Makes a dynamic GET request for a specified route.
75
+ *
76
+ * @template Route - The route key with the GET method.
77
+ * @param route - The route identifier.
78
+ * @param data - The input data for the GET request, defaults to null.
79
+ * @returns A promise that resolves to the output of the GET handler.
80
+ */
81
+ const dynamicGet = <Route extends RoutesWithMethod<'GET'>>(
82
+ route: Route,
83
+ data: RouteHandlerOf<Route, 'GET'>['input'] = null
84
+ ): Promise<RouteHandlerOf<Route, 'GET'>['output']> => {
85
+ return dynamicActionRequest(route, 'GET', data)
86
+ }
87
+
88
+ /**
89
+ * Makes a dynamic PATCH request for a specified route.
90
+ *
91
+ * @template Route - The route key with the PATCH method.
92
+ * @param route - The route identifier.
93
+ * @param data - The input data for the PATCH request, defaults to null.
94
+ * @returns A promise that resolves to the output of the PATCH handler.
95
+ */
96
+ const dynamicPatch = <Route extends RoutesWithMethod<'PATCH'>>(
97
+ route: Route,
98
+ data: RouteHandlerOf<Route, 'PATCH'>['input'] = null
99
+ ): Promise<RouteHandlerOf<Route, 'PATCH'>['output']> => {
100
+ return dynamicActionRequest(route, 'PATCH', data)
101
+ }
102
+
103
+ /**
104
+ * Makes a dynamic DELETE request for a specified route.
105
+ *
106
+ * @template Route - The route key with the DELETE method.
107
+ * @param route - The route identifier.
108
+ * @param data - The input data for the DELETE request, defaults to null.
109
+ * @returns A promise that resolves to the output of the DELETE handler.
110
+ */
111
+ const dynamicDel = <Route extends RoutesWithMethod<'DELETE'>>(
112
+ route: Route,
113
+ data: RouteHandlerOf<Route, 'DELETE'>['input'] = null
114
+ ): Promise<RouteHandlerOf<Route, 'DELETE'>['output']> => {
115
+ return dynamicActionRequest(route, 'DELETE', data)
116
+ }
117
+
118
+ // Static Requests
119
+
120
+ /**
121
+ * Makes a static POST request for a specified route.
122
+ *
123
+ * @template Route - The route key with the POST method.
124
+ * @param route - The route identifier.
125
+ * @param data - The input data for the POST request, defaults to null.
126
+ * @returns A promise that resolves to the output of the POST handler.
127
+ */
128
+ const staticPost = <Route extends RoutesWithMethod<'POST'>>(
129
+ route: Route,
130
+ data: RouteHandlerOf<Route, 'POST'>['input'] = null
131
+ ): Promise<RouteHandlerOf<Route, 'POST'>['output']> => {
132
+ return staticActionRequest(route, 'POST', data)
133
+ }
134
+
135
+ /**
136
+ * Makes a static GET request for a specified route.
137
+ *
138
+ * @template Route - The route key with the GET method.
139
+ * @param route - The route identifier.
140
+ * @param data - The input data for the GET request, defaults to null.
141
+ * @returns A promise that resolves to the output of the GET handler.
142
+ */
143
+ const staticGet = <Route extends RoutesWithMethod<'GET'>>(
144
+ route: Route,
145
+ data: RouteHandlerOf<Route, 'GET'>['input'] = null
146
+ ): Promise<RouteHandlerOf<Route, 'GET'>['output']> => {
147
+ return staticActionRequest(route, 'GET', data)
148
+ }
149
+
150
+ return {
151
+ get: dynamicGet,
152
+ post: dynamicPost,
153
+ patch: dynamicPatch,
154
+ del: dynamicDel,
155
+ staticGet,
156
+ staticPost
157
+ }
158
+ }
159
+ `;
160
+ };
@@ -20,7 +20,8 @@ export type PikkuCLIConfig = {
20
20
  supportsImportAttributes: boolean;
21
21
  configDir: string;
22
22
  tsconfig: string;
23
- nextJSfile?: string;
23
+ nextBackendFile?: string;
24
+ nextHTTPFile?: string;
24
25
  fetchFile?: string;
25
26
  websocketFile?: string;
26
27
  openAPI?: {
@@ -1,6 +1,11 @@
1
1
  import { join, dirname, resolve, isAbsolute } from 'path';
2
2
  import { readdir, readFile } from 'fs/promises';
3
- const CONFIG_DIR_FILES = ['nextJSfile', 'fetchFile', 'websocketFile'];
3
+ const CONFIG_DIR_FILES = [
4
+ 'nextBackendFile',
5
+ 'nextHTTPFile',
6
+ 'fetchFile',
7
+ 'websocketFile',
8
+ ];
4
9
  export const getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags = [], exitProcess = false) => {
5
10
  const config = await _getPikkuCLIConfig(configFile, requiredFields, tags, exitProcess);
6
11
  return config;
@@ -69,11 +69,8 @@ export async function saveSchemas(schemaParentDir, schemas, typesMap, routesMeta
69
69
  .map((schema) => `
70
70
  import * as ${schema} from './schemas/${schema}.schema.json' ${supportsImportAttributes ? `with { type: 'json' }` : ''}
71
71
  addSchema('${schema}', ${schema})
72
- // addSchema('${schema}', require('./schemas/${schema}.schema.json'))
73
72
  `)
74
73
  .join('\n');
75
74
  await writeFileInDir(`${schemaParentDir}/register.gen.ts`, `import { addSchema } from '@pikku/core/schema'
76
- // import { createRequire } from "module"
77
- // const require = createRequire(import.meta.url)
78
75
  ${schemaImports}`);
79
76
  }
@@ -18,6 +18,7 @@ export type FilesAndMethods = {
18
18
  sessionServicesFactory: Meta;
19
19
  };
20
20
  export interface PikkuCLIOptions {
21
+ watch?: boolean;
21
22
  config?: string;
22
23
  configFileType?: string;
23
24
  userSessionType?: string;
@@ -1 +1 @@
1
- {"root":["../bin/pikku-all.ts","../bin/pikku-channels-map.ts","../bin/pikku-channels.ts","../bin/pikku-fetch.ts","../bin/pikku-function-types.ts","../bin/pikku-http.ts","../bin/pikku-nextjs.ts","../bin/pikku-openapi.ts","../bin/pikku-routes-map.ts","../bin/pikku-scheduler.ts","../bin/pikku-schemas.ts","../bin/pikku-websocket.ts","../bin/pikku.ts","../src/inspector-glob.ts","../src/pikku-cli-config.ts","../src/utils.ts","../src/channels/serialize-channels.ts","../src/channels/serialize-typed-channel-map.ts","../src/channels/serialize-websocket-wrapper.ts","../src/core/serialize-import-map.ts","../src/core/serialize-pikku-types.ts","../src/http/serialize-fetch-wrapper.ts","../src/http/serialize-route-imports.ts","../src/http/serialize-route-meta.ts","../src/http/serialize-typed-route-map.ts","../src/nextjs/serialize-nextjs-wrapper.ts","../src/openapi/openapi-spec-generator.ts","../src/scheduler/serialize-schedulers.ts","../src/schema/schema-generator.ts"],"version":"5.7.3"}
1
+ {"root":["../bin/pikku-all.ts","../bin/pikku-channels-map.ts","../bin/pikku-channels.ts","../bin/pikku-fetch.ts","../bin/pikku-function-types.ts","../bin/pikku-http.ts","../bin/pikku-nextjs.ts","../bin/pikku-openapi.ts","../bin/pikku-routes-map.ts","../bin/pikku-scheduler.ts","../bin/pikku-schemas.ts","../bin/pikku-websocket.ts","../bin/pikku.ts","../src/inspector-glob.ts","../src/pikku-cli-config.ts","../src/utils.ts","../src/channels/serialize-channels.ts","../src/channels/serialize-typed-channel-map.ts","../src/channels/serialize-websocket-wrapper.ts","../src/core/serialize-import-map.ts","../src/core/serialize-pikku-types.ts","../src/http/serialize-fetch-wrapper.ts","../src/http/serialize-route-imports.ts","../src/http/serialize-route-meta.ts","../src/http/serialize-typed-route-map.ts","../src/nextjs/serialize-nextjs-backend-wrapper.ts","../src/nextjs/serialize-nextjs-http-wrapper.ts","../src/openapi/openapi-spec-generator.ts","../src/scheduler/serialize-schedulers.ts","../src/schema/schema-generator.ts"],"version":"5.7.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/cli",
3
- "version": "0.6.16",
3
+ "version": "0.6.18",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -22,14 +22,15 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@openapi-contrib/json-schema-to-openapi-schema": "^3.0.2",
25
- "@pikku/core": "^0.6.19",
26
- "@pikku/inspector": "^0.6.3",
25
+ "@pikku/core": "^0.6.22",
26
+ "@pikku/inspector": "^0.6.4",
27
27
  "@types/cookie": "^0.6.0",
28
28
  "@types/uuid": "^10.0.0",
29
29
  "chalk": "^5.4.1",
30
+ "chokidar": "^4.0.3",
30
31
  "commander": "^12",
31
- "glob": "^10",
32
32
  "path-to-regexp": "^8.2.0",
33
+ "tinyglobby": "^0.2.12",
33
34
  "ts-json-schema-generator": "^2.3.0",
34
35
  "typescript": "^5.6",
35
36
  "yaml": "^2.6.0"
@@ -1,5 +1,5 @@
1
1
  import * as path from 'path'
2
- import { glob } from 'glob'
2
+ import { glob } from 'tinyglobby'
3
3
  import { InspectorFilters, InspectorState, inspect } from '@pikku/inspector'
4
4
  import { logCommandInfoAndTime } from './utils.js'
5
5
 
@@ -1,11 +1,10 @@
1
- export const serializeNextJsWrapper = (
1
+ export const serializeNextJsBackendWrapper = (
2
2
  routesPath: string,
3
3
  routesMapPath: string,
4
4
  schemasPath: string,
5
5
  configImport: string,
6
6
  singleServicesFactoryImport: string,
7
- sessionServicesImport: string,
8
- userSessionTypeImport: string
7
+ sessionServicesImport: string
9
8
  ) => {
10
9
  return `'server-only'
11
10
 
@@ -13,14 +12,12 @@ export const serializeNextJsWrapper = (
13
12
  * This file provides a wrapper around the PikkuNextJS class to allow for methods to be type checked against your routes.
14
13
  * It ensures type safety for route handling methods when integrating with the @pikku/core framework.
15
14
  */
16
- import { PikkuMiddleware } from '@pikku/core'
17
- import { PikkuNextJS, PikkuNextRequest } from '@pikku/next'
15
+ import { PikkuNextJS } from '@pikku/next'
18
16
  import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
19
17
 
20
18
  ${configImport}
21
19
  ${singleServicesFactoryImport}
22
20
  ${sessionServicesImport}
23
- ${userSessionTypeImport}
24
21
 
25
22
  import '${routesPath}'
26
23
  import '${schemasPath}'
@@ -32,7 +29,7 @@ let _pikku: PikkuNextJS | undefined
32
29
  *
33
30
  * @returns An object containing methods for making dynamic and static action requests, as well as session retrieval.
34
31
  */
35
- export const pikku = () => {
32
+ export const pikku = (_options?: any) => {
36
33
  if (!_pikku) {
37
34
  _pikku = new PikkuNextJS(
38
35
  createConfig as any,
@@ -41,20 +38,6 @@ export const pikku = () => {
41
38
  )
42
39
  }
43
40
 
44
- /**
45
- * Retrieves the user session using the current PikkuNextJS instance.
46
- *
47
- * @param request - The Next.js request object.
48
- * @param middleware - An array of middleware functions to process the request.
49
- * @returns A promise that resolves to the user session.
50
- */
51
- const getSession = async (
52
- request: PikkuNextRequest,
53
- middleware: PikkuMiddleware[]
54
- ): Promise<UserSession | undefined> => {
55
- return _pikku!.getSession(request, middleware) as any
56
- }
57
-
58
41
  /**
59
42
  * Makes a dynamic action request for a specified route and method.
60
43
  * Dynamic requests may access headers and cookies and are therefore unsuitable for precompile stages.
@@ -192,7 +175,6 @@ export const pikku = () => {
192
175
  }
193
176
 
194
177
  return {
195
- getSession,
196
178
  get: dynamicGet,
197
179
  post: dynamicPost,
198
180
  patch: dynamicPatch,
@@ -0,0 +1,163 @@
1
+ export const serializeNextJsHTTPWrapper = (
2
+ routesMapPath: string,
3
+ pikkuFetchImport: string
4
+ ) => {
5
+ return `'server-only'
6
+
7
+ /**
8
+ * This file provides a wrapper around the PikkuNextJS class to allow for methods to be type checked against your routes.
9
+ * It ensures type safety for route handling methods when integrating with the @pikku/core framework.
10
+ */
11
+ import { CorePikkuFetchOptions } from '@pikku/fetch'
12
+ import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
13
+
14
+ let _pikku: PikkuFetch | undefined
15
+
16
+ ${pikkuFetchImport}
17
+
18
+ /**
19
+ * Initializes and returns an instance of PikkuNextJS with helper methods for handling route requests.
20
+ *
21
+ * @returns An object containing methods for making dynamic and static action requests, as well as session retrieval.
22
+ */
23
+ export const pikku = (options?: CorePikkuFetchOptions) => {
24
+ if (!_pikku) {
25
+ _pikku = new PikkuFetch(options)
26
+ }
27
+
28
+ const dynamicActionRequest = async <
29
+ Route extends keyof RoutesMap,
30
+ Method extends keyof RoutesMap[Route]
31
+ >(
32
+ route: Route,
33
+ method: Method,
34
+ data: RouteHandlerOf<Route, Method>['input'] = null
35
+ ): Promise<RouteHandlerOf<Route, Method>['output']> => {
36
+ return (_pikku! as any)[(method as string).toLowerCase()](route, data as any)
37
+ }
38
+
39
+ /**
40
+ * Makes a static action request for a specified route and method.
41
+ * Static requests do not depend on headers or cookies and are suitable for precompile stages.
42
+ *
43
+ * @template Route - The route key from the RoutesMap.
44
+ * @template Method - The method key from the specified route.
45
+ * @param route - The route identifier.
46
+ * @param method - The HTTP method to be used for the request.
47
+ * @param data - The input data for the request, defaults to null.
48
+ * @returns A promise that resolves to the output of the route handler.
49
+ */
50
+ const staticActionRequest = async <
51
+ Route extends keyof RoutesMap,
52
+ Method extends keyof RoutesMap[Route]
53
+ >(
54
+ route: Route,
55
+ method: Method,
56
+ data: RouteHandlerOf<Route, Method>['input'] = null
57
+ ): Promise<RouteHandlerOf<Route, Method>['output']> => {
58
+ return (_pikku! as any)[(method as string).toLowerCase()](route, data as any)
59
+ }
60
+
61
+ /**
62
+ * Makes a dynamic POST request for a specified route.
63
+ *
64
+ * @template Route - The route key with the POST method.
65
+ * @param route - The route identifier.
66
+ * @param data - The input data for the POST request, defaults to null.
67
+ * @returns A promise that resolves to the output of the POST handler.
68
+ */
69
+ const dynamicPost = <Route extends RoutesWithMethod<'POST'>>(
70
+ route: Route,
71
+ data: RouteHandlerOf<Route, 'POST'>['input'] = null
72
+ ): Promise<RouteHandlerOf<Route, 'POST'>['output']> => {
73
+ return dynamicActionRequest(route, 'POST', data)
74
+ }
75
+
76
+ /**
77
+ * Makes a dynamic GET request for a specified route.
78
+ *
79
+ * @template Route - The route key with the GET method.
80
+ * @param route - The route identifier.
81
+ * @param data - The input data for the GET request, defaults to null.
82
+ * @returns A promise that resolves to the output of the GET handler.
83
+ */
84
+ const dynamicGet = <Route extends RoutesWithMethod<'GET'>>(
85
+ route: Route,
86
+ data: RouteHandlerOf<Route, 'GET'>['input'] = null
87
+ ): Promise<RouteHandlerOf<Route, 'GET'>['output']> => {
88
+ return dynamicActionRequest(route, 'GET', data)
89
+ }
90
+
91
+ /**
92
+ * Makes a dynamic PATCH request for a specified route.
93
+ *
94
+ * @template Route - The route key with the PATCH method.
95
+ * @param route - The route identifier.
96
+ * @param data - The input data for the PATCH request, defaults to null.
97
+ * @returns A promise that resolves to the output of the PATCH handler.
98
+ */
99
+ const dynamicPatch = <Route extends RoutesWithMethod<'PATCH'>>(
100
+ route: Route,
101
+ data: RouteHandlerOf<Route, 'PATCH'>['input'] = null
102
+ ): Promise<RouteHandlerOf<Route, 'PATCH'>['output']> => {
103
+ return dynamicActionRequest(route, 'PATCH', data)
104
+ }
105
+
106
+ /**
107
+ * Makes a dynamic DELETE request for a specified route.
108
+ *
109
+ * @template Route - The route key with the DELETE method.
110
+ * @param route - The route identifier.
111
+ * @param data - The input data for the DELETE request, defaults to null.
112
+ * @returns A promise that resolves to the output of the DELETE handler.
113
+ */
114
+ const dynamicDel = <Route extends RoutesWithMethod<'DELETE'>>(
115
+ route: Route,
116
+ data: RouteHandlerOf<Route, 'DELETE'>['input'] = null
117
+ ): Promise<RouteHandlerOf<Route, 'DELETE'>['output']> => {
118
+ return dynamicActionRequest(route, 'DELETE', data)
119
+ }
120
+
121
+ // Static Requests
122
+
123
+ /**
124
+ * Makes a static POST request for a specified route.
125
+ *
126
+ * @template Route - The route key with the POST method.
127
+ * @param route - The route identifier.
128
+ * @param data - The input data for the POST request, defaults to null.
129
+ * @returns A promise that resolves to the output of the POST handler.
130
+ */
131
+ const staticPost = <Route extends RoutesWithMethod<'POST'>>(
132
+ route: Route,
133
+ data: RouteHandlerOf<Route, 'POST'>['input'] = null
134
+ ): Promise<RouteHandlerOf<Route, 'POST'>['output']> => {
135
+ return staticActionRequest(route, 'POST', data)
136
+ }
137
+
138
+ /**
139
+ * Makes a static GET request for a specified route.
140
+ *
141
+ * @template Route - The route key with the GET method.
142
+ * @param route - The route identifier.
143
+ * @param data - The input data for the GET request, defaults to null.
144
+ * @returns A promise that resolves to the output of the GET handler.
145
+ */
146
+ const staticGet = <Route extends RoutesWithMethod<'GET'>>(
147
+ route: Route,
148
+ data: RouteHandlerOf<Route, 'GET'>['input'] = null
149
+ ): Promise<RouteHandlerOf<Route, 'GET'>['output']> => {
150
+ return staticActionRequest(route, 'GET', data)
151
+ }
152
+
153
+ return {
154
+ get: dynamicGet,
155
+ post: dynamicPost,
156
+ patch: dynamicPatch,
157
+ del: dynamicDel,
158
+ staticGet,
159
+ staticPost
160
+ }
161
+ }
162
+ `
163
+ }
@@ -28,7 +28,8 @@ export type PikkuCLIConfig = {
28
28
  configDir: string
29
29
  tsconfig: string
30
30
 
31
- nextJSfile?: string
31
+ nextBackendFile?: string
32
+ nextHTTPFile?: string
32
33
  fetchFile?: string
33
34
  websocketFile?: string
34
35
 
@@ -40,7 +41,12 @@ export type PikkuCLIConfig = {
40
41
  filters: InspectorFilters
41
42
  } & PikkuCLICoreOutputFiles
42
43
 
43
- const CONFIG_DIR_FILES = ['nextJSfile', 'fetchFile', 'websocketFile']
44
+ const CONFIG_DIR_FILES = [
45
+ 'nextBackendFile',
46
+ 'nextHTTPFile',
47
+ 'fetchFile',
48
+ 'websocketFile',
49
+ ]
44
50
 
45
51
  export const getPikkuCLIConfig = async (
46
52
  configFile: string | undefined = undefined,
@@ -102,7 +102,6 @@ export async function saveSchemas(
102
102
  (schema) => `
103
103
  import * as ${schema} from './schemas/${schema}.schema.json' ${supportsImportAttributes ? `with { type: 'json' }` : ''}
104
104
  addSchema('${schema}', ${schema})
105
- // addSchema('${schema}', require('./schemas/${schema}.schema.json'))
106
105
  `
107
106
  )
108
107
  .join('\n')
@@ -110,8 +109,6 @@ addSchema('${schema}', ${schema})
110
109
  await writeFileInDir(
111
110
  `${schemaParentDir}/register.gen.ts`,
112
111
  `import { addSchema } from '@pikku/core/schema'
113
- // import { createRequire } from "module"
114
- // const require = createRequire(import.meta.url)
115
112
  ${schemaImports}`
116
113
  )
117
114
  }
package/src/utils.ts CHANGED
@@ -59,6 +59,7 @@ export type FilesAndMethods = {
59
59
  }
60
60
 
61
61
  export interface PikkuCLIOptions {
62
+ watch?: boolean
62
63
  config?: string
63
64
  configFileType?: string
64
65
  userSessionType?: string
@@ -1 +0,0 @@
1
- export declare const serializeNextJsWrapper: (routesPath: string, routesMapPath: string, schemasPath: string, configImport: string, singleServicesFactoryImport: string, sessionServicesImport: string, userSessionTypeImport: string) => string;