@pikku/cli 0.6.12 → 0.6.13

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/bin/pikku-all.ts +15 -6
  3. package/bin/pikku-channels-map.ts +8 -6
  4. package/bin/pikku-channels.ts +7 -6
  5. package/bin/pikku-fetch.ts +1 -0
  6. package/bin/pikku-function-types.ts +18 -10
  7. package/bin/{pikku-routes.ts → pikku-http.ts} +11 -10
  8. package/bin/pikku-nextjs.ts +7 -2
  9. package/bin/pikku-openapi.ts +8 -9
  10. package/bin/pikku-routes-map.ts +7 -6
  11. package/bin/pikku-scheduler.ts +8 -7
  12. package/bin/pikku-schemas.ts +2 -1
  13. package/bin/pikku-websocket.ts +1 -0
  14. package/bin/pikku.ts +1 -1
  15. package/dist/bin/pikku-all.js +7 -6
  16. package/dist/bin/pikku-channels-map.js +2 -6
  17. package/dist/bin/pikku-channels.js +2 -6
  18. package/dist/bin/pikku-fetch.js +1 -1
  19. package/dist/bin/pikku-function-types.js +10 -10
  20. package/dist/bin/{pikku-routes.d.ts → pikku-http.d.ts} +1 -1
  21. package/dist/bin/{pikku-routes.js → pikku-http.js} +5 -9
  22. package/dist/bin/pikku-nextjs.js +5 -4
  23. package/dist/bin/pikku-openapi.js +3 -9
  24. package/dist/bin/pikku-routes-map.js +2 -6
  25. package/dist/bin/pikku-scheduler.js +3 -7
  26. package/dist/bin/pikku-schemas.js +1 -1
  27. package/dist/bin/pikku-websocket.js +1 -1
  28. package/dist/bin/pikku.js +1 -1
  29. package/dist/src/core/serialize-pikku-types.d.ts +1 -1
  30. package/dist/src/core/serialize-pikku-types.js +11 -9
  31. package/dist/src/inspector-glob.d.ts +2 -2
  32. package/dist/src/inspector-glob.js +2 -2
  33. package/dist/src/nextjs/serialize-nextjs-wrapper.d.ts +1 -1
  34. package/dist/src/nextjs/serialize-nextjs-wrapper.js +60 -12
  35. package/dist/src/pikku-cli-config.d.ts +3 -1
  36. package/dist/src/pikku-cli-config.js +8 -4
  37. package/dist/src/utils.d.ts +4 -1
  38. package/dist/src/utils.js +5 -3
  39. package/dist/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +3 -3
  41. package/src/core/serialize-pikku-types.ts +12 -8
  42. package/src/inspector-glob.ts +4 -3
  43. package/src/nextjs/serialize-nextjs-wrapper.ts +61 -12
  44. package/src/pikku-cli-config.ts +12 -0
  45. package/src/utils.ts +15 -3
@@ -15,7 +15,7 @@ async function action({ config }) {
15
15
  'schemaDirectory',
16
16
  'tsconfig',
17
17
  ]);
18
- const visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories);
18
+ const visitState = await inspectorGlob(cliConfig.rootDir, cliConfig.routeDirectories, cliConfig.filters);
19
19
  await pikkuSchemas(cliConfig, visitState);
20
20
  }
21
21
  export const schemas = (program) => {
@@ -16,7 +16,7 @@ export const pikkuWebSocket = async ({ websocketFile, channelsMapDeclarationFile
16
16
  };
17
17
  export const action = async (options) => {
18
18
  logPikkuLogo();
19
- const cliConfig = await getPikkuCLIConfig(options.config, ['rootDir', 'schemaDirectory', 'configDir', 'fetchFile'], true);
19
+ const cliConfig = await getPikkuCLIConfig(options.config, ['rootDir', 'schemaDirectory', 'configDir', 'fetchFile'], options.tags, true);
20
20
  await pikkuWebSocket(cliConfig);
21
21
  };
22
22
  export const websocket = (program) => {
package/dist/bin/pikku.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
3
  import { schemas } from './pikku-schemas.js';
4
- import { routes } from './pikku-routes.js';
4
+ import { routes } from './pikku-http.js';
5
5
  import { nextjs } from './pikku-nextjs.js';
6
6
  import { all } from './pikku-all.js';
7
7
  import { functionTypes } from './pikku-function-types.js';
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  *
3
3
  */
4
- export declare const serializePikkuTypes: (userSessionTypeImport: string, userSessionTypeName: string, sessionServicesTypeImport: string, servicesTypeName: string) => string;
4
+ export declare const serializePikkuTypes: (userSessionTypeImport: string, userSessionTypeName: string, singletonServicesTypeImport: string, singletonServicesTypeName: string, sessionServicesTypeImport: string, servicesTypeName: string) => string;
@@ -1,28 +1,30 @@
1
1
  /**
2
2
  *
3
3
  */
4
- export const serializePikkuTypes = (userSessionTypeImport, userSessionTypeName, sessionServicesTypeImport, servicesTypeName) => {
4
+ export const serializePikkuTypes = (userSessionTypeImport, userSessionTypeName, singletonServicesTypeImport, singletonServicesTypeName, sessionServicesTypeImport, servicesTypeName) => {
5
5
  return `/**
6
6
  * This is used to provide the application types in the typescript project
7
7
  */
8
8
 
9
- import { CoreAPIFunction, CoreAPIFunctionSessionless, CoreAPIPermission } from '@pikku/core'
9
+ import { CoreAPIFunction, CoreAPIFunctionSessionless, CoreAPIPermission, PikkuMiddleware } from '@pikku/core'
10
10
  import { CoreHTTPFunctionRoute, AssertRouteParams, addRoute as addCoreHTTP } from '@pikku/core/http'
11
11
  import { CoreScheduledTask, addScheduledTask as addCoreScheduledTask } from '@pikku/core/scheduler'
12
12
  import { CoreAPIChannel, PikkuChannel, addChannel as addCoreChannel } from '@pikku/core/channel'
13
13
 
14
14
  ${userSessionTypeImport}
15
+ ${singletonServicesTypeImport}
15
16
  ${sessionServicesTypeImport}
16
17
 
17
- export type APIPermission<In = unknown, RequiredServices = ${servicesTypeName}> = CoreAPIPermission<In, RequiredServices, ${userSessionTypeName}>
18
+ export type APIPermission<In = unknown, RequiredServices extends ${singletonServicesTypeName} = ${singletonServicesTypeName}> = CoreAPIPermission<In, RequiredServices, ${userSessionTypeName}>
19
+ export type APIMiddleware<RequiredServices extends ${singletonServicesTypeName} = ${singletonServicesTypeName}> = PikkuMiddleware<RequiredServices, ${userSessionTypeName}>
18
20
 
19
- export type APIFunctionSessionless<In = unknown, Out = never, RequiredServices = ${servicesTypeName}> = CoreAPIFunctionSessionless<In, Out, RequiredServices, ${userSessionTypeName}>
20
- export type APIFunction<In = unknown, Out = never, RequiredServices = ${servicesTypeName}> = CoreAPIFunction<In, Out, RequiredServices, ${userSessionTypeName}>
21
- type APIRoute<In, Out, Route extends string> = CoreHTTPFunctionRoute<In, Out, Route, APIFunction<In, Out>, APIFunctionSessionless<In, Out>, APIPermission<In>>
21
+ export type APIFunctionSessionless<In = unknown, Out = never, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = CoreAPIFunctionSessionless<In, Out, RequiredServices, ${userSessionTypeName}>
22
+ export type APIFunction<In = unknown, Out = never, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = CoreAPIFunction<In, Out, RequiredServices, ${userSessionTypeName}>
23
+ type APIRoute<In, Out, Route extends string> = CoreHTTPFunctionRoute<In, Out, Route, APIFunction<In, Out>, APIFunctionSessionless<In, Out>, APIPermission<In>, APIMiddleware>
22
24
 
23
- export type ChannelConnection<Out = unknown, ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<${userSessionTypeName}, ChannelData, Out>) => Promise<void>
24
- export type ChannelDisconnection<ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<${userSessionTypeName}, ChannelData, never>) => Promise<void>
25
- export type ChannelMessage<In, Out = unknown, ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<${userSessionTypeName}, ChannelData, Out>, data: In) => Promise<Out | void>
25
+ export type ChannelConnection<Out = unknown, ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<ChannelData, Out>) => Promise<void>
26
+ export type ChannelDisconnection<ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<ChannelData, never>) => Promise<void>
27
+ export type ChannelMessage<In, Out = unknown, ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<ChannelData, Out>, data: In) => Promise<Out | void>
26
28
  type APIChannel<ChannelData, Channel extends string> = CoreAPIChannel<ChannelData, Channel, ChannelConnection, ChannelDisconnection, ChannelMessage<any, any, ChannelData>, ChannelMessage<any, any, ChannelData>, APIPermission>
27
29
 
28
30
  type ScheduledTask = CoreScheduledTask<APIFunctionSessionless<void, void>, ${userSessionTypeName}>
@@ -1,2 +1,2 @@
1
- import { InspectorState } from '@pikku/inspector';
2
- export declare const inspectorGlob: (rootDir: string, routeDirectories: string[]) => Promise<InspectorState>;
1
+ import { InspectorFilters, InspectorState } from '@pikku/inspector';
2
+ export declare const inspectorGlob: (rootDir: string, routeDirectories: string[], filters: InspectorFilters) => Promise<InspectorState>;
@@ -2,11 +2,11 @@ import * as path from 'path';
2
2
  import { glob } from 'glob';
3
3
  import { inspect } from '@pikku/inspector';
4
4
  import { logCommandInfoAndTime } from './utils.js';
5
- export const inspectorGlob = async (rootDir, routeDirectories) => {
5
+ export const inspectorGlob = async (rootDir, routeDirectories, filters) => {
6
6
  let result;
7
7
  await logCommandInfoAndTime('Inspecting codebase', 'Inspected codebase', [false], async () => {
8
8
  const routeFiles = (await Promise.all(routeDirectories.map((dir) => glob(`${path.join(rootDir, dir)}/**/*.ts`)))).flat();
9
- result = await inspect(routeFiles);
9
+ result = await inspect(routeFiles, filters);
10
10
  });
11
11
  return result;
12
12
  };
@@ -1 +1 @@
1
- export declare const serializeNextJsWrapper: (routesPath: string, routesMapPath: string, schemasPath: string, configImport: string, singleServicesFactoryImport: string, sessionServicesImport: string) => string;
1
+ export declare const serializeNextJsWrapper: (routesPath: string, routesMapPath: string, schemasPath: string, configImport: string, singleServicesFactoryImport: string, sessionServicesImport: string, userSessionTypeImport: string) => string;
@@ -1,16 +1,18 @@
1
- export const serializeNextJsWrapper = (routesPath, routesMapPath, schemasPath, configImport, singleServicesFactoryImport, sessionServicesImport) => {
1
+ export const serializeNextJsWrapper = (routesPath, routesMapPath, schemasPath, configImport, singleServicesFactoryImport, sessionServicesImport, userSessionTypeImport) => {
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
- * This ensures type safety for route handling methods when integrating with the \`@pikku/core\` framework.
6
+ * It ensures type safety for route handling methods when integrating with the @pikku/core framework.
7
7
  */
8
- import { PikkuNextJS } from '@pikku/next'
8
+ import { PikkuMiddleware } from '@pikku/core'
9
+ import { PikkuNextJS, PikkuNextRequest } from '@pikku/next'
9
10
  import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
10
11
 
11
12
  ${configImport}
12
13
  ${singleServicesFactoryImport}
13
14
  ${sessionServicesImport}
15
+ ${userSessionTypeImport}
14
16
 
15
17
  import '${routesPath}'
16
18
  import '${schemasPath}'
@@ -20,7 +22,7 @@ let _pikku: PikkuNextJS | undefined
20
22
  /**
21
23
  * Initializes and returns an instance of PikkuNextJS with helper methods for handling route requests.
22
24
  *
23
- * @returns An object containing methods for making dynamic and static action requests.
25
+ * @returns An object containing methods for making dynamic and static action requests, as well as session retrieval.
24
26
  */
25
27
  export const pikku = () => {
26
28
  if (!_pikku) {
@@ -31,14 +33,28 @@ export const pikku = () => {
31
33
  )
32
34
  }
33
35
 
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
+
34
50
  /**
35
51
  * Makes a dynamic action request for a specified route and method.
36
- * Dynamic requests may access headers and cookies, making them unsuitable for precompile stages.
52
+ * Dynamic requests may access headers and cookies and are therefore unsuitable for precompile stages.
37
53
  *
38
54
  * @template Route - The route key from the RoutesMap.
39
55
  * @template Method - The method key from the specified route.
40
- * @param route - The route to make the request to.
41
- * @param method - The method to be used for the request.
56
+ * @param route - The route identifier.
57
+ * @param method - The HTTP method to be used for the request.
42
58
  * @param data - The input data for the request, defaults to null.
43
59
  * @returns A promise that resolves to the output of the route handler.
44
60
  */
@@ -59,8 +75,8 @@ export const pikku = () => {
59
75
  *
60
76
  * @template Route - The route key from the RoutesMap.
61
77
  * @template Method - The method key from the specified route.
62
- * @param route - The route to make the request to.
63
- * @param method - The method to be used for the request.
78
+ * @param route - The route identifier.
79
+ * @param method - The HTTP method to be used for the request.
64
80
  * @param data - The input data for the request, defaults to null.
65
81
  * @returns A promise that resolves to the output of the route handler.
66
82
  */
@@ -77,6 +93,11 @@ export const pikku = () => {
77
93
 
78
94
  /**
79
95
  * Makes a dynamic POST request for a specified route.
96
+ *
97
+ * @template Route - The route key with the POST method.
98
+ * @param route - The route identifier.
99
+ * @param data - The input data for the POST request, defaults to null.
100
+ * @returns A promise that resolves to the output of the POST handler.
80
101
  */
81
102
  const dynamicPost = <Route extends RoutesWithMethod<'POST'>>(
82
103
  route: Route,
@@ -87,6 +108,11 @@ export const pikku = () => {
87
108
 
88
109
  /**
89
110
  * Makes a dynamic GET request for a specified route.
111
+ *
112
+ * @template Route - The route key with the GET method.
113
+ * @param route - The route identifier.
114
+ * @param data - The input data for the GET request, defaults to null.
115
+ * @returns A promise that resolves to the output of the GET handler.
90
116
  */
91
117
  const dynamicGet = <Route extends RoutesWithMethod<'GET'>>(
92
118
  route: Route,
@@ -97,6 +123,11 @@ export const pikku = () => {
97
123
 
98
124
  /**
99
125
  * Makes a dynamic PATCH request for a specified route.
126
+ *
127
+ * @template Route - The route key with the PATCH method.
128
+ * @param route - The route identifier.
129
+ * @param data - The input data for the PATCH request, defaults to null.
130
+ * @returns A promise that resolves to the output of the PATCH handler.
100
131
  */
101
132
  const dynamicPatch = <Route extends RoutesWithMethod<'PATCH'>>(
102
133
  route: Route,
@@ -107,6 +138,11 @@ export const pikku = () => {
107
138
 
108
139
  /**
109
140
  * Makes a dynamic DELETE request for a specified route.
141
+ *
142
+ * @template Route - The route key with the DELETE method.
143
+ * @param route - The route identifier.
144
+ * @param data - The input data for the DELETE request, defaults to null.
145
+ * @returns A promise that resolves to the output of the DELETE handler.
110
146
  */
111
147
  const dynamicDel = <Route extends RoutesWithMethod<'DELETE'>>(
112
148
  route: Route,
@@ -115,10 +151,15 @@ export const pikku = () => {
115
151
  return dynamicActionRequest(route, 'DELETE', data)
116
152
  }
117
153
 
118
- // Static
154
+ // Static Requests
119
155
 
120
156
  /**
121
157
  * Makes a static POST request for a specified route.
158
+ *
159
+ * @template Route - The route key with the POST method.
160
+ * @param route - The route identifier.
161
+ * @param data - The input data for the POST request, defaults to null.
162
+ * @returns A promise that resolves to the output of the POST handler.
122
163
  */
123
164
  const staticPost = <Route extends RoutesWithMethod<'POST'>>(
124
165
  route: Route,
@@ -129,6 +170,11 @@ export const pikku = () => {
129
170
 
130
171
  /**
131
172
  * Makes a static GET request for a specified route.
173
+ *
174
+ * @template Route - The route key with the GET method.
175
+ * @param route - The route identifier.
176
+ * @param data - The input data for the GET request, defaults to null.
177
+ * @returns A promise that resolves to the output of the GET handler.
132
178
  */
133
179
  const staticGet = <Route extends RoutesWithMethod<'GET'>>(
134
180
  route: Route,
@@ -138,6 +184,7 @@ export const pikku = () => {
138
184
  }
139
185
 
140
186
  return {
187
+ getSession,
141
188
  get: dynamicGet,
142
189
  post: dynamicPost,
143
190
  patch: dynamicPatch,
@@ -145,5 +192,6 @@ export const pikku = () => {
145
192
  staticGet,
146
193
  staticPost
147
194
  }
148
- }`;
195
+ }
196
+ `;
149
197
  };
@@ -1,4 +1,5 @@
1
1
  import { OpenAPISpecInfo } from './openapi/openapi-spec-generator.js';
2
+ import { InspectorFilters } from '@pikku/inspector';
2
3
  export interface PikkuCLICoreOutputFiles {
3
4
  outDir?: string;
4
5
  routesFile: string;
@@ -26,6 +27,7 @@ export type PikkuCLIConfig = {
26
27
  outputFile: string;
27
28
  additionalInfo: OpenAPISpecInfo;
28
29
  };
30
+ filters: InspectorFilters;
29
31
  } & PikkuCLICoreOutputFiles;
30
- export declare const getPikkuCLIConfig: (configFile: string | undefined, requiredFields: Array<keyof PikkuCLIConfig>, exitProcess?: boolean) => Promise<PikkuCLIConfig>;
32
+ export declare const getPikkuCLIConfig: (configFile: string | undefined, requiredFields: Array<keyof PikkuCLIConfig>, tags?: string[], exitProcess?: boolean) => Promise<PikkuCLIConfig>;
31
33
  export declare const validateCLIConfig: (cliConfig: PikkuCLIConfig, required: Array<keyof PikkuCLIConfig>) => void;
@@ -1,11 +1,11 @@
1
1
  import { join, dirname, resolve, isAbsolute } from 'path';
2
2
  import { readdir, readFile } from 'fs/promises';
3
3
  const CONFIG_DIR_FILES = ['nextJSfile', 'fetchFile', 'websocketFile'];
4
- export const getPikkuCLIConfig = async (configFile = undefined, requiredFields, exitProcess = false) => {
5
- const config = await _getPikkuCLIConfig(configFile, requiredFields, exitProcess);
4
+ export const getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags = [], exitProcess = false) => {
5
+ const config = await _getPikkuCLIConfig(configFile, requiredFields, tags, exitProcess);
6
6
  return config;
7
7
  };
8
- const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, exitProcess = false) => {
8
+ const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, tags = [], exitProcess = false) => {
9
9
  if (!configFile) {
10
10
  let execDirectory = process.cwd();
11
11
  const files = await readdir(execDirectory);
@@ -26,7 +26,7 @@ const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, exitPr
26
26
  const configDir = dirname(configFile);
27
27
  const config = JSON.parse(file);
28
28
  if (config.extends) {
29
- const extendedConfig = await getPikkuCLIConfig(resolve(configDir, config.extends), [], exitProcess);
29
+ const extendedConfig = await getPikkuCLIConfig(resolve(configDir, config.extends), [], tags, exitProcess);
30
30
  result = {
31
31
  ...extendedConfig,
32
32
  ...config,
@@ -88,6 +88,10 @@ const _getPikkuCLIConfig = async (configFile = undefined, requiredFields, exitPr
88
88
  }
89
89
  }
90
90
  }
91
+ result.filters = result.filters || {};
92
+ if (tags.length > 0) {
93
+ result.filters.tags = tags;
94
+ }
91
95
  if (!isAbsolute(result.tsconfig)) {
92
96
  result.tsconfig = join(result.rootDir, result.tsconfig);
93
97
  }
@@ -12,6 +12,7 @@ interface Meta {
12
12
  export type FilesAndMethods = {
13
13
  userSessionType: Meta;
14
14
  sessionServicesType: Meta;
15
+ singletonServicesType: Meta;
15
16
  pikkuConfigFactory: Meta;
16
17
  singletonServicesFactory: Meta;
17
18
  sessionServicesFactory: Meta;
@@ -22,10 +23,12 @@ export interface PikkuCLIOptions {
22
23
  userSessionType?: string;
23
24
  singletonServicesFactoryType?: string;
24
25
  sessionServicesFactoryType?: string;
26
+ tags?: string[];
25
27
  }
26
- export declare const getPikkuFilesAndMethods: ({ sessionServicesTypeImportMap: httpSessionServicesTypeImportMap, userSessionTypeImportMap, sessionServicesFactories, singletonServicesFactories, configFactories, }: InspectorState, packageMappings: Record<string, string>, outputFile: string, { configFileType, singletonServicesFactoryType, sessionServicesFactoryType, }: PikkuCLIOptions, requires?: Partial<{
28
+ export declare const getPikkuFilesAndMethods: ({ singletonServicesTypeImportMap, sessionServicesTypeImportMap, userSessionTypeImportMap, sessionServicesFactories, singletonServicesFactories, configFactories, }: InspectorState, packageMappings: Record<string, string>, outputFile: string, { configFileType, singletonServicesFactoryType, sessionServicesFactoryType, }: PikkuCLIOptions, requires?: Partial<{
27
29
  config: boolean;
28
30
  sessionServiceType: boolean;
31
+ singletonServicesType: boolean;
29
32
  userSessionType: boolean;
30
33
  singletonServicesFactory: boolean;
31
34
  sessionServicesFactory: boolean;
package/dist/src/utils.js CHANGED
@@ -60,8 +60,9 @@ const getMetaTypes = (type, errors, map, desiredType) => {
60
60
  }
61
61
  return undefined;
62
62
  };
63
- export const getPikkuFilesAndMethods = async ({ sessionServicesTypeImportMap: httpSessionServicesTypeImportMap, userSessionTypeImportMap, sessionServicesFactories, singletonServicesFactories, configFactories, }, packageMappings, outputFile, { configFileType, singletonServicesFactoryType, sessionServicesFactoryType, }, requires = {
63
+ export const getPikkuFilesAndMethods = async ({ singletonServicesTypeImportMap, sessionServicesTypeImportMap, userSessionTypeImportMap, sessionServicesFactories, singletonServicesFactories, configFactories, }, packageMappings, outputFile, { configFileType, singletonServicesFactoryType, sessionServicesFactoryType, }, requires = {
64
64
  config: false,
65
+ singletonServicesType: false,
65
66
  sessionServiceType: false,
66
67
  userSessionType: false,
67
68
  singletonServicesFactory: false,
@@ -70,7 +71,8 @@ export const getPikkuFilesAndMethods = async ({ sessionServicesTypeImportMap: ht
70
71
  let errors = new Map();
71
72
  const result = {
72
73
  userSessionType: getMetaTypes('CoreUserSession', requires.userSessionType ? errors : new Map(), userSessionTypeImportMap, configFileType),
73
- sessionServicesType: getMetaTypes('CoreServices', requires.sessionServiceType ? errors : new Map(), httpSessionServicesTypeImportMap),
74
+ singletonServicesType: getMetaTypes('CoreSingletonServices', requires.singletonServicesType ? errors : new Map(), singletonServicesTypeImportMap),
75
+ sessionServicesType: getMetaTypes('CoreServices', requires.sessionServiceType ? errors : new Map(), sessionServicesTypeImportMap),
74
76
  pikkuConfigFactory: getMetaTypes('CoreConfig', requires.config ? errors : new Map(), configFactories, configFileType),
75
77
  singletonServicesFactory: getMetaTypes('CreateSingletonServices', requires.singletonServicesFactory ? errors : new Map(), singletonServicesFactories, singletonServicesFactoryType),
76
78
  sessionServicesFactory: getMetaTypes('CreateSessionServices', requires.sessionServicesFactory ? errors : new Map(), sessionServicesFactories, sessionServicesFactoryType),
@@ -102,7 +104,7 @@ export const writeFileInDir = async (path, content, ignoreModifyComment = false)
102
104
  };
103
105
  export const logCommandInfoAndTime = async (commandStart, commandEnd, [skipCondition, skipMessage = 'none found'], callback) => {
104
106
  if (skipCondition === true) {
105
- logInfo(`• Skipping ${commandStart} since ${skipMessage}.`);
107
+ logInfo(`• Skipping ${commandStart.charAt(0).toLocaleLowerCase()}${commandStart.slice(1)} since ${skipMessage}.`);
106
108
  return false;
107
109
  }
108
110
  const start = Date.now();
@@ -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-nextjs.ts","../bin/pikku-openapi.ts","../bin/pikku-routes-map.ts","../bin/pikku-routes.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-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.12",
3
+ "version": "0.6.13",
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.6.13",
26
- "@pikku/inspector": "^0.6.2",
25
+ "@pikku/core": "^0.6.14",
26
+ "@pikku/inspector": "^0.6.3",
27
27
  "@types/cookie": "^0.6.0",
28
28
  "@types/uuid": "^10.0.0",
29
29
  "chalk": "^5.4.1",
@@ -4,6 +4,8 @@
4
4
  export const serializePikkuTypes = (
5
5
  userSessionTypeImport: string,
6
6
  userSessionTypeName: string,
7
+ singletonServicesTypeImport: string,
8
+ singletonServicesTypeName: string,
7
9
  sessionServicesTypeImport: string,
8
10
  servicesTypeName: string
9
11
  ) => {
@@ -11,23 +13,25 @@ export const serializePikkuTypes = (
11
13
  * This is used to provide the application types in the typescript project
12
14
  */
13
15
 
14
- import { CoreAPIFunction, CoreAPIFunctionSessionless, CoreAPIPermission } from '@pikku/core'
16
+ import { CoreAPIFunction, CoreAPIFunctionSessionless, CoreAPIPermission, PikkuMiddleware } from '@pikku/core'
15
17
  import { CoreHTTPFunctionRoute, AssertRouteParams, addRoute as addCoreHTTP } from '@pikku/core/http'
16
18
  import { CoreScheduledTask, addScheduledTask as addCoreScheduledTask } from '@pikku/core/scheduler'
17
19
  import { CoreAPIChannel, PikkuChannel, addChannel as addCoreChannel } from '@pikku/core/channel'
18
20
 
19
21
  ${userSessionTypeImport}
22
+ ${singletonServicesTypeImport}
20
23
  ${sessionServicesTypeImport}
21
24
 
22
- export type APIPermission<In = unknown, RequiredServices = ${servicesTypeName}> = CoreAPIPermission<In, RequiredServices, ${userSessionTypeName}>
25
+ export type APIPermission<In = unknown, RequiredServices extends ${singletonServicesTypeName} = ${singletonServicesTypeName}> = CoreAPIPermission<In, RequiredServices, ${userSessionTypeName}>
26
+ export type APIMiddleware<RequiredServices extends ${singletonServicesTypeName} = ${singletonServicesTypeName}> = PikkuMiddleware<RequiredServices, ${userSessionTypeName}>
23
27
 
24
- export type APIFunctionSessionless<In = unknown, Out = never, RequiredServices = ${servicesTypeName}> = CoreAPIFunctionSessionless<In, Out, RequiredServices, ${userSessionTypeName}>
25
- export type APIFunction<In = unknown, Out = never, RequiredServices = ${servicesTypeName}> = CoreAPIFunction<In, Out, RequiredServices, ${userSessionTypeName}>
26
- type APIRoute<In, Out, Route extends string> = CoreHTTPFunctionRoute<In, Out, Route, APIFunction<In, Out>, APIFunctionSessionless<In, Out>, APIPermission<In>>
28
+ export type APIFunctionSessionless<In = unknown, Out = never, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = CoreAPIFunctionSessionless<In, Out, RequiredServices, ${userSessionTypeName}>
29
+ export type APIFunction<In = unknown, Out = never, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = CoreAPIFunction<In, Out, RequiredServices, ${userSessionTypeName}>
30
+ type APIRoute<In, Out, Route extends string> = CoreHTTPFunctionRoute<In, Out, Route, APIFunction<In, Out>, APIFunctionSessionless<In, Out>, APIPermission<In>, APIMiddleware>
27
31
 
28
- export type ChannelConnection<Out = unknown, ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<${userSessionTypeName}, ChannelData, Out>) => Promise<void>
29
- export type ChannelDisconnection<ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<${userSessionTypeName}, ChannelData, never>) => Promise<void>
30
- export type ChannelMessage<In, Out = unknown, ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<${userSessionTypeName}, ChannelData, Out>, data: In) => Promise<Out | void>
32
+ export type ChannelConnection<Out = unknown, ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<ChannelData, Out>) => Promise<void>
33
+ export type ChannelDisconnection<ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<ChannelData, never>) => Promise<void>
34
+ export type ChannelMessage<In, Out = unknown, ChannelData = unknown, RequiredServices extends ${servicesTypeName} = ${servicesTypeName}> = (services: RequiredServices, channel: PikkuChannel<ChannelData, Out>, data: In) => Promise<Out | void>
31
35
  type APIChannel<ChannelData, Channel extends string> = CoreAPIChannel<ChannelData, Channel, ChannelConnection, ChannelDisconnection, ChannelMessage<any, any, ChannelData>, ChannelMessage<any, any, ChannelData>, APIPermission>
32
36
 
33
37
  type ScheduledTask = CoreScheduledTask<APIFunctionSessionless<void, void>, ${userSessionTypeName}>
@@ -1,11 +1,12 @@
1
1
  import * as path from 'path'
2
2
  import { glob } from 'glob'
3
- import { InspectorState, inspect } from '@pikku/inspector'
3
+ import { InspectorFilters, InspectorState, inspect } from '@pikku/inspector'
4
4
  import { logCommandInfoAndTime } from './utils.js'
5
5
 
6
6
  export const inspectorGlob = async (
7
7
  rootDir: string,
8
- routeDirectories: string[]
8
+ routeDirectories: string[],
9
+ filters: InspectorFilters
9
10
  ) => {
10
11
  let result: InspectorState
11
12
  await logCommandInfoAndTime(
@@ -20,7 +21,7 @@ export const inspectorGlob = async (
20
21
  )
21
22
  )
22
23
  ).flat()
23
- result = await inspect(routeFiles)
24
+ result = await inspect(routeFiles, filters)
24
25
  }
25
26
  )
26
27
  return result!
@@ -4,20 +4,23 @@ export const serializeNextJsWrapper = (
4
4
  schemasPath: string,
5
5
  configImport: string,
6
6
  singleServicesFactoryImport: string,
7
- sessionServicesImport: string
7
+ sessionServicesImport: string,
8
+ userSessionTypeImport: string
8
9
  ) => {
9
10
  return `'server-only'
10
-
11
+
11
12
  /**
12
13
  * This file provides a wrapper around the PikkuNextJS class to allow for methods to be type checked against your routes.
13
- * This ensures type safety for route handling methods when integrating with the \`@pikku/core\` framework.
14
+ * It ensures type safety for route handling methods when integrating with the @pikku/core framework.
14
15
  */
15
- import { PikkuNextJS } from '@pikku/next'
16
+ import { PikkuMiddleware } from '@pikku/core'
17
+ import { PikkuNextJS, PikkuNextRequest } from '@pikku/next'
16
18
  import type { RoutesMap, RouteHandlerOf, RoutesWithMethod } from '${routesMapPath}'
17
19
 
18
20
  ${configImport}
19
21
  ${singleServicesFactoryImport}
20
22
  ${sessionServicesImport}
23
+ ${userSessionTypeImport}
21
24
 
22
25
  import '${routesPath}'
23
26
  import '${schemasPath}'
@@ -27,7 +30,7 @@ let _pikku: PikkuNextJS | undefined
27
30
  /**
28
31
  * Initializes and returns an instance of PikkuNextJS with helper methods for handling route requests.
29
32
  *
30
- * @returns An object containing methods for making dynamic and static action requests.
33
+ * @returns An object containing methods for making dynamic and static action requests, as well as session retrieval.
31
34
  */
32
35
  export const pikku = () => {
33
36
  if (!_pikku) {
@@ -38,14 +41,28 @@ export const pikku = () => {
38
41
  )
39
42
  }
40
43
 
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
+
41
58
  /**
42
59
  * Makes a dynamic action request for a specified route and method.
43
- * Dynamic requests may access headers and cookies, making them unsuitable for precompile stages.
60
+ * Dynamic requests may access headers and cookies and are therefore unsuitable for precompile stages.
44
61
  *
45
62
  * @template Route - The route key from the RoutesMap.
46
63
  * @template Method - The method key from the specified route.
47
- * @param route - The route to make the request to.
48
- * @param method - The method to be used for the request.
64
+ * @param route - The route identifier.
65
+ * @param method - The HTTP method to be used for the request.
49
66
  * @param data - The input data for the request, defaults to null.
50
67
  * @returns A promise that resolves to the output of the route handler.
51
68
  */
@@ -66,8 +83,8 @@ export const pikku = () => {
66
83
  *
67
84
  * @template Route - The route key from the RoutesMap.
68
85
  * @template Method - The method key from the specified route.
69
- * @param route - The route to make the request to.
70
- * @param method - The method to be used for the request.
86
+ * @param route - The route identifier.
87
+ * @param method - The HTTP method to be used for the request.
71
88
  * @param data - The input data for the request, defaults to null.
72
89
  * @returns A promise that resolves to the output of the route handler.
73
90
  */
@@ -84,6 +101,11 @@ export const pikku = () => {
84
101
 
85
102
  /**
86
103
  * Makes a dynamic POST request for a specified route.
104
+ *
105
+ * @template Route - The route key with the POST method.
106
+ * @param route - The route identifier.
107
+ * @param data - The input data for the POST request, defaults to null.
108
+ * @returns A promise that resolves to the output of the POST handler.
87
109
  */
88
110
  const dynamicPost = <Route extends RoutesWithMethod<'POST'>>(
89
111
  route: Route,
@@ -94,6 +116,11 @@ export const pikku = () => {
94
116
 
95
117
  /**
96
118
  * Makes a dynamic GET request for a specified route.
119
+ *
120
+ * @template Route - The route key with the GET method.
121
+ * @param route - The route identifier.
122
+ * @param data - The input data for the GET request, defaults to null.
123
+ * @returns A promise that resolves to the output of the GET handler.
97
124
  */
98
125
  const dynamicGet = <Route extends RoutesWithMethod<'GET'>>(
99
126
  route: Route,
@@ -104,6 +131,11 @@ export const pikku = () => {
104
131
 
105
132
  /**
106
133
  * Makes a dynamic PATCH request for a specified route.
134
+ *
135
+ * @template Route - The route key with the PATCH method.
136
+ * @param route - The route identifier.
137
+ * @param data - The input data for the PATCH request, defaults to null.
138
+ * @returns A promise that resolves to the output of the PATCH handler.
107
139
  */
108
140
  const dynamicPatch = <Route extends RoutesWithMethod<'PATCH'>>(
109
141
  route: Route,
@@ -114,6 +146,11 @@ export const pikku = () => {
114
146
 
115
147
  /**
116
148
  * Makes a dynamic DELETE request for a specified route.
149
+ *
150
+ * @template Route - The route key with the DELETE method.
151
+ * @param route - The route identifier.
152
+ * @param data - The input data for the DELETE request, defaults to null.
153
+ * @returns A promise that resolves to the output of the DELETE handler.
117
154
  */
118
155
  const dynamicDel = <Route extends RoutesWithMethod<'DELETE'>>(
119
156
  route: Route,
@@ -122,10 +159,15 @@ export const pikku = () => {
122
159
  return dynamicActionRequest(route, 'DELETE', data)
123
160
  }
124
161
 
125
- // Static
162
+ // Static Requests
126
163
 
127
164
  /**
128
165
  * Makes a static POST request for a specified route.
166
+ *
167
+ * @template Route - The route key with the POST method.
168
+ * @param route - The route identifier.
169
+ * @param data - The input data for the POST request, defaults to null.
170
+ * @returns A promise that resolves to the output of the POST handler.
129
171
  */
130
172
  const staticPost = <Route extends RoutesWithMethod<'POST'>>(
131
173
  route: Route,
@@ -136,6 +178,11 @@ export const pikku = () => {
136
178
 
137
179
  /**
138
180
  * Makes a static GET request for a specified route.
181
+ *
182
+ * @template Route - The route key with the GET method.
183
+ * @param route - The route identifier.
184
+ * @param data - The input data for the GET request, defaults to null.
185
+ * @returns A promise that resolves to the output of the GET handler.
139
186
  */
140
187
  const staticGet = <Route extends RoutesWithMethod<'GET'>>(
141
188
  route: Route,
@@ -145,6 +192,7 @@ export const pikku = () => {
145
192
  }
146
193
 
147
194
  return {
195
+ getSession,
148
196
  get: dynamicGet,
149
197
  post: dynamicPost,
150
198
  patch: dynamicPatch,
@@ -152,5 +200,6 @@ export const pikku = () => {
152
200
  staticGet,
153
201
  staticPost
154
202
  }
155
- }`
203
+ }
204
+ `
156
205
  }