@pikku/cli 0.6.12 → 0.6.14

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 (51) hide show
  1. package/CHANGELOG.md +21 -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/channels/serialize-channels.js +2 -2
  30. package/dist/src/core/serialize-pikku-types.d.ts +1 -1
  31. package/dist/src/core/serialize-pikku-types.js +11 -9
  32. package/dist/src/http/serialize-route-meta.js +2 -2
  33. package/dist/src/inspector-glob.d.ts +2 -2
  34. package/dist/src/inspector-glob.js +2 -2
  35. package/dist/src/nextjs/serialize-nextjs-wrapper.d.ts +1 -1
  36. package/dist/src/nextjs/serialize-nextjs-wrapper.js +60 -12
  37. package/dist/src/pikku-cli-config.d.ts +3 -1
  38. package/dist/src/pikku-cli-config.js +8 -4
  39. package/dist/src/scheduler/serialize-schedulers.js +2 -2
  40. package/dist/src/utils.d.ts +4 -1
  41. package/dist/src/utils.js +5 -3
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/package.json +3 -3
  44. package/src/channels/serialize-channels.ts +2 -2
  45. package/src/core/serialize-pikku-types.ts +12 -8
  46. package/src/http/serialize-route-meta.ts +2 -2
  47. package/src/inspector-glob.ts +4 -3
  48. package/src/nextjs/serialize-nextjs-wrapper.ts +61 -12
  49. package/src/pikku-cli-config.ts +12 -0
  50. package/src/scheduler/serialize-schedulers.ts +2 -4
  51. package/src/utils.ts +15 -3
@@ -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
  }
@@ -1,6 +1,7 @@
1
1
  import { join, dirname, resolve, isAbsolute } from 'path'
2
2
  import { readdir, readFile } from 'fs/promises'
3
3
  import { OpenAPISpecInfo } from './openapi/openapi-spec-generator.js'
4
+ import { InspectorFilters } from '@pikku/inspector'
4
5
 
5
6
  export interface PikkuCLICoreOutputFiles {
6
7
  outDir?: string
@@ -35,6 +36,8 @@ export type PikkuCLIConfig = {
35
36
  outputFile: string
36
37
  additionalInfo: OpenAPISpecInfo
37
38
  }
39
+
40
+ filters: InspectorFilters
38
41
  } & PikkuCLICoreOutputFiles
39
42
 
40
43
  const CONFIG_DIR_FILES = ['nextJSfile', 'fetchFile', 'websocketFile']
@@ -42,11 +45,13 @@ const CONFIG_DIR_FILES = ['nextJSfile', 'fetchFile', 'websocketFile']
42
45
  export const getPikkuCLIConfig = async (
43
46
  configFile: string | undefined = undefined,
44
47
  requiredFields: Array<keyof PikkuCLIConfig>,
48
+ tags: string[] = [],
45
49
  exitProcess: boolean = false
46
50
  ): Promise<PikkuCLIConfig> => {
47
51
  const config = await _getPikkuCLIConfig(
48
52
  configFile,
49
53
  requiredFields,
54
+ tags,
50
55
  exitProcess
51
56
  )
52
57
  return config
@@ -55,6 +60,7 @@ export const getPikkuCLIConfig = async (
55
60
  const _getPikkuCLIConfig = async (
56
61
  configFile: string | undefined = undefined,
57
62
  requiredFields: Array<keyof PikkuCLIConfig>,
63
+ tags: string[] = [],
58
64
  exitProcess: boolean = false
59
65
  ): Promise<PikkuCLIConfig> => {
60
66
  if (!configFile) {
@@ -82,6 +88,7 @@ const _getPikkuCLIConfig = async (
82
88
  const extendedConfig = await getPikkuCLIConfig(
83
89
  resolve(configDir, config.extends),
84
90
  [],
91
+ tags,
85
92
  exitProcess
86
93
  )
87
94
  result = {
@@ -154,6 +161,11 @@ const _getPikkuCLIConfig = async (
154
161
  }
155
162
  }
156
163
 
164
+ result.filters = result.filters || {}
165
+ if (tags.length > 0) {
166
+ result.filters.tags = tags
167
+ }
168
+
157
169
  if (!isAbsolute(result.tsconfig)) {
158
170
  result.tsconfig = join(result.rootDir, result.tsconfig)
159
171
  }
@@ -28,11 +28,9 @@ export const serializeSchedulerMeta = (
28
28
  scheduledTasksMeta: ScheduledTasksMeta
29
29
  ) => {
30
30
  const serializedOutput: string[] = []
31
+ serializedOutput.push("import { pikkuState } from '@pikku/core'")
31
32
  serializedOutput.push(
32
- "import { setScheduledTasksMeta } from '@pikku/core/scheduler'"
33
- )
34
- serializedOutput.push(
35
- `setScheduledTasksMeta(${JSON.stringify(scheduledTasksMeta, null, 2)})`
33
+ `pikkuState('scheduler', 'meta', ${JSON.stringify(scheduledTasksMeta, null, 2)})`
36
34
  )
37
35
  if (scheduledTasksMeta.length > 0) {
38
36
  serializedOutput.push(
package/src/utils.ts CHANGED
@@ -52,6 +52,7 @@ interface Meta {
52
52
  export type FilesAndMethods = {
53
53
  userSessionType: Meta
54
54
  sessionServicesType: Meta
55
+ singletonServicesType: Meta
55
56
  pikkuConfigFactory: Meta
56
57
  singletonServicesFactory: Meta
57
58
  sessionServicesFactory: Meta
@@ -63,6 +64,7 @@ export interface PikkuCLIOptions {
63
64
  userSessionType?: string
64
65
  singletonServicesFactoryType?: string
65
66
  sessionServicesFactoryType?: string
67
+ tags?: string[]
66
68
  }
67
69
 
68
70
  const getMetaTypes = (
@@ -102,7 +104,8 @@ const getMetaTypes = (
102
104
 
103
105
  export const getPikkuFilesAndMethods = async (
104
106
  {
105
- sessionServicesTypeImportMap: httpSessionServicesTypeImportMap,
107
+ singletonServicesTypeImportMap,
108
+ sessionServicesTypeImportMap,
106
109
  userSessionTypeImportMap,
107
110
  sessionServicesFactories,
108
111
  singletonServicesFactories,
@@ -118,11 +121,13 @@ export const getPikkuFilesAndMethods = async (
118
121
  requires: Partial<{
119
122
  config: boolean
120
123
  sessionServiceType: boolean
124
+ singletonServicesType: boolean
121
125
  userSessionType: boolean
122
126
  singletonServicesFactory: boolean
123
127
  sessionServicesFactory: boolean
124
128
  }> = {
125
129
  config: false,
130
+ singletonServicesType: false,
126
131
  sessionServiceType: false,
127
132
  userSessionType: false,
128
133
  singletonServicesFactory: false,
@@ -138,10 +143,15 @@ export const getPikkuFilesAndMethods = async (
138
143
  userSessionTypeImportMap,
139
144
  configFileType
140
145
  ),
146
+ singletonServicesType: getMetaTypes(
147
+ 'CoreSingletonServices',
148
+ requires.singletonServicesType ? errors : new Map(),
149
+ singletonServicesTypeImportMap
150
+ ),
141
151
  sessionServicesType: getMetaTypes(
142
152
  'CoreServices',
143
153
  requires.sessionServiceType ? errors : new Map(),
144
- httpSessionServicesTypeImportMap
154
+ sessionServicesTypeImportMap
145
155
  ),
146
156
  pikkuConfigFactory: getMetaTypes(
147
157
  'CoreConfig',
@@ -210,7 +220,9 @@ export const logCommandInfoAndTime = async (
210
220
  callback: (...args: any[]) => Promise<unknown>
211
221
  ): Promise<boolean> => {
212
222
  if (skipCondition === true) {
213
- logInfo(`• Skipping ${commandStart} since ${skipMessage}.`)
223
+ logInfo(
224
+ `• Skipping ${commandStart.charAt(0).toLocaleLowerCase()}${commandStart.slice(1)} since ${skipMessage}.`
225
+ )
214
226
  return false
215
227
  }
216
228