@pikku/cli 0.9.16-next.0 → 0.10.0
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/.pikku/channel/pikku-channel-types.gen.ts +28 -29
- package/.pikku/channel/pikku-channels-map.gen.d.ts +44 -0
- package/.pikku/channel/pikku-channels-meta.gen.ts +5 -0
- package/.pikku/channel/pikku-channels.gen.ts +4 -0
- package/.pikku/cli/pikku-cli-channel.gen.ts +34 -0
- package/.pikku/cli/pikku-cli-client.gen.ts +43 -0
- package/.pikku/cli/pikku-cli-types.gen.ts +14 -15
- package/.pikku/cli/pikku-cli-wirings-meta.gen.ts +142 -2
- package/.pikku/cli/pikku-cli-wirings.gen.ts +4 -2
- package/.pikku/cli/pikku-cli.gen.ts +41 -0
- package/.pikku/function/pikku-function-types.gen.ts +167 -19
- package/.pikku/function/pikku-functions-meta.gen.ts +220 -192
- package/.pikku/function/pikku-functions-meta.min.gen.ts +61 -56
- package/.pikku/function/pikku-functions.gen.ts +3 -1
- package/.pikku/http/pikku-http-types.gen.ts +28 -3
- package/.pikku/http/pikku-http-wirings-map.gen.d.ts +43 -0
- package/.pikku/http/pikku-http-wirings-meta.gen.ts +13 -0
- package/.pikku/http/pikku-http-wirings.gen.ts +4 -0
- package/.pikku/mcp/pikku-mcp-types.gen.ts +15 -13
- package/.pikku/mcp/pikku-mcp-wirings-meta.gen.ts +7 -0
- package/.pikku/mcp/pikku-mcp-wirings.gen.ts +4 -0
- package/.pikku/mcp/pikku-mcp.gen.json +5 -0
- package/.pikku/pikku-bootstrap.gen.ts +11 -1
- package/.pikku/pikku-services.gen.ts +1 -5
- package/.pikku/pikku-types.gen.ts +1 -2
- package/.pikku/pikku-websocket.gen.ts +76 -0
- package/.pikku/queue/pikku-queue-types.gen.ts +1 -2
- package/.pikku/queue/pikku-queue-workers-wirings-map.gen.d.ts +57 -0
- package/.pikku/queue/pikku-queue-workers-wirings-meta.gen.ts +5 -0
- package/.pikku/queue/pikku-queue-workers-wirings.gen.ts +4 -0
- package/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +5 -4
- package/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +19 -17
- package/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.ts +15 -14
- package/.pikku/scheduler/pikku-scheduler-types.gen.ts +1 -2
- package/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.ts +5 -0
- package/.pikku/scheduler/pikku-schedulers-wirings.gen.ts +4 -0
- package/.pikku/schemas/register.gen.ts +15 -11
- package/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -0
- package/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
- package/CHANGELOG.md +6 -0
- package/bin/pikku.ts +63 -11
- package/build.sh +1 -1
- package/cli.schema.json +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +11 -20
- package/dist/.pikku/channel/pikku-channel-types.gen.js +9 -11
- package/dist/.pikku/channel/pikku-channels-meta.gen.d.ts +1 -0
- package/dist/.pikku/channel/pikku-channels-meta.gen.js +5 -0
- package/dist/.pikku/channel/pikku-channels.gen.d.ts +4 -0
- package/dist/.pikku/channel/pikku-channels.gen.js +5 -0
- package/dist/.pikku/cli/pikku-cli-channel.gen.d.ts +1 -0
- package/dist/.pikku/cli/pikku-cli-channel.gen.js +33 -0
- package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +10 -0
- package/dist/.pikku/cli/pikku-cli-client.gen.js +34 -0
- package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +9 -12
- package/dist/.pikku/cli/pikku-cli-types.gen.js +5 -4
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +142 -2
- package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +3 -2
- package/dist/.pikku/cli/pikku-cli-wirings.gen.js +4 -3
- package/dist/.pikku/cli/pikku-cli.gen.d.ts +10 -0
- package/dist/.pikku/cli/pikku-cli.gen.js +38 -0
- package/dist/.pikku/function/pikku-function-types.gen.d.ts +141 -20
- package/dist/.pikku/function/pikku-function-types.gen.js +108 -12
- package/dist/.pikku/function/pikku-functions-meta.gen.js +220 -192
- package/dist/.pikku/function/pikku-functions-meta.min.gen.js +61 -56
- package/dist/.pikku/function/pikku-functions.gen.js +3 -1
- package/dist/.pikku/http/pikku-http-types.gen.d.ts +21 -2
- package/dist/.pikku/http/pikku-http-types.gen.js +24 -3
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +13 -0
- package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +4 -0
- package/dist/.pikku/http/pikku-http-wirings.gen.js +5 -0
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +11 -8
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js +6 -6
- package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.js +7 -0
- package/dist/.pikku/mcp/pikku-mcp-wirings.gen.d.ts +4 -0
- package/dist/.pikku/mcp/pikku-mcp-wirings.gen.js +5 -0
- package/dist/.pikku/pikku-bootstrap.gen.d.ts +11 -1
- package/dist/.pikku/pikku-bootstrap.gen.js +11 -1
- package/dist/.pikku/pikku-services.gen.d.ts +1 -4
- package/dist/.pikku/pikku-services.gen.js +0 -6
- package/dist/.pikku/pikku-types.gen.d.ts +1 -2
- package/dist/.pikku/pikku-types.gen.js +1 -2
- package/dist/.pikku/pikku-websocket.gen.d.ts +31 -0
- package/dist/.pikku/pikku-websocket.gen.js +49 -0
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -2
- package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -2
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +5 -0
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +4 -0
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +5 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +15 -14
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -2
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -2
- package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.js +5 -0
- package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.d.ts +4 -0
- package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.js +5 -0
- package/dist/.pikku/schemas/register.gen.js +9 -7
- package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
- package/dist/bin/pikku.d.ts +1 -1
- package/dist/bin/pikku.js +37 -6
- package/dist/src/cli.wiring.js +99 -75
- package/dist/src/functions/commands/all.js +10 -0
- package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.js +10 -8
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts +1 -1
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +2 -2
- package/dist/src/functions/wirings/channels/pikku-channels.js +0 -5
- package/dist/src/functions/wirings/channels/pikku-command-channel-types.js +0 -2
- package/dist/src/functions/wirings/channels/pikku-command-channels-map.js +0 -5
- package/dist/src/functions/wirings/channels/pikku-command-channels.js +0 -5
- package/dist/src/functions/wirings/channels/pikku-command-websocket-typed.js +6 -3
- package/dist/src/functions/wirings/channels/serialize-channel-types.js +27 -28
- package/dist/src/functions/wirings/channels/serialize-typed-channel-map.js +4 -1
- package/dist/src/functions/wirings/cli/pikku-command-cli-entry.js +31 -8
- package/dist/src/functions/wirings/cli/pikku-command-cli-types.js +0 -2
- package/dist/src/functions/wirings/cli/pikku-command-cli.js +0 -2
- package/dist/src/functions/wirings/cli/serialize-channel-cli-client.d.ts +6 -2
- package/dist/src/functions/wirings/cli/serialize-channel-cli-client.js +88 -11
- package/dist/src/functions/wirings/cli/serialize-channel-cli.d.ts +1 -1
- package/dist/src/functions/wirings/cli/serialize-channel-cli.js +1 -18
- package/dist/src/functions/wirings/cli/serialize-cli-types.js +13 -14
- package/dist/src/functions/wirings/cli/serialize-local-cli-bootstrap.js +19 -14
- package/dist/src/functions/wirings/fetch/index.js +6 -3
- package/dist/src/functions/wirings/functions/pikku-command-function-types-split.js +6 -5
- package/dist/src/functions/wirings/functions/pikku-command-function-types.js +0 -2
- package/dist/src/functions/wirings/functions/pikku-command-functions.js +0 -2
- package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-services.js +11 -21
- package/dist/src/functions/wirings/functions/pikku-function-types.js +0 -2
- package/dist/src/functions/wirings/functions/schemas.js +0 -2
- package/dist/src/functions/wirings/functions/serialize-function-types.d.ts +1 -1
- package/dist/src/functions/wirings/functions/serialize-function-types.js +167 -19
- package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.js +0 -1
- package/dist/src/functions/wirings/http/openapi-spec-generator.d.ts +2 -1
- package/dist/src/functions/wirings/http/pikku-command-http-map.js +0 -5
- package/dist/src/functions/wirings/http/pikku-command-http-routes.js +0 -5
- package/dist/src/functions/wirings/http/pikku-command-http-types.js +0 -2
- package/dist/src/functions/wirings/http/pikku-command-openapi.js +7 -4
- package/dist/src/functions/wirings/http/pikku-http-routes.js +0 -5
- package/dist/src/functions/wirings/http/serialize-http-types.js +27 -2
- package/dist/src/functions/wirings/mcp/pikku-command-mcp-json.js +0 -5
- package/dist/src/functions/wirings/mcp/pikku-command-mcp-types.js +0 -2
- package/dist/src/functions/wirings/mcp/pikku-command-mcp.js +0 -5
- package/dist/src/functions/wirings/mcp/serialize-mcp-json.d.ts +1 -1
- package/dist/src/functions/wirings/mcp/serialize-mcp-types.js +14 -12
- package/dist/src/functions/wirings/middleware/pikku-command-middleware.js +0 -2
- package/dist/src/functions/wirings/middleware/serialize-middleware-groups-meta.js +1 -7
- package/dist/src/functions/wirings/permissions/pikku-command-permissions.d.ts +1 -0
- package/dist/src/functions/wirings/permissions/pikku-command-permissions.js +28 -0
- package/dist/src/functions/wirings/permissions/serialize-permissions-imports.d.ts +2 -0
- package/dist/src/functions/wirings/permissions/serialize-permissions-imports.js +43 -0
- package/dist/src/functions/wirings/queue/pikku-command-queue-map.js +0 -5
- package/dist/src/functions/wirings/queue/pikku-command-queue-service.js +6 -3
- package/dist/src/functions/wirings/queue/pikku-command-queue-types.js +0 -2
- package/dist/src/functions/wirings/queue/pikku-command-queue.js +0 -5
- package/dist/src/functions/wirings/queue/pikku-queue-map.js +0 -5
- package/dist/src/functions/wirings/queue/pikku-queue.js +1 -5
- package/dist/src/functions/wirings/queue/serialize-queue-meta.d.ts +1 -1
- package/dist/src/functions/wirings/queue/serialize-queue-types.js +0 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.js +5 -3
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.js +0 -4
- package/dist/src/functions/wirings/rpc/pikku-command-rpc.js +0 -2
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler-types.js +0 -2
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.js +0 -5
- package/dist/src/functions/wirings/scheduler/serialize-scheduler-types.js +0 -1
- package/dist/src/middleware/log-command-info-and-time.d.ts +2 -8
- package/dist/src/middleware/log-command-info-and-time.js +2 -14
- package/dist/src/services/cli-logger-forwarder.service.d.ts +6 -2
- package/dist/src/services/cli-logger-forwarder.service.js +9 -0
- package/dist/src/services/cli-logger.service.d.ts +4 -0
- package/dist/src/services/cli-logger.service.js +11 -0
- package/dist/src/services.d.ts +5 -0
- package/dist/src/services.js +111 -13
- package/dist/src/utils/custom-types-generator.js +8 -2
- package/dist/src/utils/file-writer.d.ts +4 -1
- package/dist/src/utils/file-writer.js +13 -3
- package/dist/src/utils/get-cli-version.d.ts +5 -0
- package/dist/src/utils/get-cli-version.js +27 -0
- package/dist/src/utils/pikku-cli-config.d.ts +1 -2
- package/dist/src/utils/pikku-cli-config.js +9 -28
- package/dist/src/utils/schema-generator.js +3 -2
- package/dist/src/utils/serialize-import-map.js +0 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -8
- package/pikku.config.json +4 -2
- package/src/cli.wiring.ts +101 -74
- package/src/functions/commands/all.ts +12 -0
- package/src/functions/runtimes/nextjs/pikku-command-nextjs.ts +12 -12
- package/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.ts +2 -2
- package/src/functions/wirings/channels/pikku-channels.ts +0 -5
- package/src/functions/wirings/channels/pikku-command-channel-types.ts +0 -2
- package/src/functions/wirings/channels/pikku-command-channels-map.ts +0 -5
- package/src/functions/wirings/channels/pikku-command-channels.ts +0 -5
- package/src/functions/wirings/channels/pikku-command-websocket-typed.ts +7 -3
- package/src/functions/wirings/channels/serialize-channel-types.ts +27 -28
- package/src/functions/wirings/channels/serialize-typed-channel-map.ts +4 -1
- package/src/functions/wirings/cli/pikku-command-cli-entry.ts +52 -9
- package/src/functions/wirings/cli/pikku-command-cli-types.ts +0 -2
- package/src/functions/wirings/cli/pikku-command-cli.ts +0 -2
- package/src/functions/wirings/cli/serialize-channel-cli-client.ts +111 -12
- package/src/functions/wirings/cli/serialize-channel-cli.ts +2 -23
- package/src/functions/wirings/cli/serialize-cli-types.ts +13 -14
- package/src/functions/wirings/cli/serialize-local-cli-bootstrap.ts +19 -14
- package/src/functions/wirings/fetch/index.ts +7 -3
- package/src/functions/wirings/functions/pikku-command-function-types-split.ts +14 -5
- package/src/functions/wirings/functions/pikku-command-function-types.ts +0 -2
- package/src/functions/wirings/functions/pikku-command-functions.ts +0 -2
- package/src/functions/wirings/functions/pikku-command-services.ts +13 -24
- package/src/functions/wirings/functions/pikku-function-types.ts +0 -2
- package/src/functions/wirings/functions/schemas.ts +0 -2
- package/src/functions/wirings/functions/serialize-function-types.ts +169 -19
- package/src/functions/wirings/functions/serialize-pikku-types-hub.ts +0 -1
- package/src/functions/wirings/http/openapi-spec-generator.ts +2 -1
- package/src/functions/wirings/http/pikku-command-http-map.ts +0 -5
- package/src/functions/wirings/http/pikku-command-http-routes.ts +0 -5
- package/src/functions/wirings/http/pikku-command-http-types.ts +0 -2
- package/src/functions/wirings/http/pikku-command-openapi.ts +9 -4
- package/src/functions/wirings/http/pikku-http-routes.ts +0 -5
- package/src/functions/wirings/http/serialize-http-types.ts +27 -2
- package/src/functions/wirings/mcp/pikku-command-mcp-json.ts +0 -5
- package/src/functions/wirings/mcp/pikku-command-mcp-types.ts +0 -2
- package/src/functions/wirings/mcp/pikku-command-mcp.ts +0 -5
- package/src/functions/wirings/mcp/serialize-mcp-json.ts +1 -1
- package/src/functions/wirings/mcp/serialize-mcp-types.ts +14 -12
- package/src/functions/wirings/middleware/pikku-command-middleware.ts +0 -2
- package/src/functions/wirings/middleware/serialize-middleware-groups-meta.ts +1 -7
- package/src/functions/wirings/permissions/pikku-command-permissions.ts +49 -0
- package/src/functions/wirings/permissions/serialize-permissions-imports.test.ts +274 -0
- package/src/functions/wirings/permissions/serialize-permissions-imports.ts +78 -0
- package/src/functions/wirings/queue/pikku-command-queue-map.ts +0 -5
- package/src/functions/wirings/queue/pikku-command-queue-service.ts +7 -3
- package/src/functions/wirings/queue/pikku-command-queue-types.ts +0 -2
- package/src/functions/wirings/queue/pikku-command-queue.ts +0 -5
- package/src/functions/wirings/queue/pikku-queue-map.ts +0 -5
- package/src/functions/wirings/queue/pikku-queue.ts +3 -6
- package/src/functions/wirings/queue/serialize-queue-meta.ts +1 -1
- package/src/functions/wirings/queue/serialize-queue-types.ts +0 -1
- package/src/functions/wirings/rpc/pikku-command-rpc-client.ts +6 -3
- package/src/functions/wirings/rpc/pikku-command-rpc-map.ts +0 -4
- package/src/functions/wirings/rpc/pikku-command-rpc.ts +0 -2
- package/src/functions/wirings/scheduler/pikku-command-scheduler-types.ts +0 -2
- package/src/functions/wirings/scheduler/pikku-command-scheduler.ts +0 -5
- package/src/functions/wirings/scheduler/serialize-scheduler-types.ts +0 -1
- package/src/middleware/log-command-info-and-time.ts +2 -28
- package/src/services/cli-logger-forwarder.service.ts +15 -2
- package/src/services/cli-logger.service.ts +15 -0
- package/src/services.ts +148 -19
- package/src/utils/custom-types-generator.ts +8 -2
- package/src/utils/file-writer.ts +19 -3
- package/src/utils/get-cli-version.ts +28 -0
- package/src/utils/pikku-cli-config.ts +6 -35
- package/src/utils/schema-generator.ts +7 -3
- package/src/utils/serialize-import-map.ts +0 -4
- package/types/application-types.d.ts +4 -1
- package/types/config.d.ts +15 -3
- package/dist/.pikku/rpc/pikku-bootstrap-rpc.gen.d.ts +0 -6
- package/dist/.pikku/rpc/pikku-bootstrap-rpc.gen.js +0 -6
- package/dist/src/serialize-pikku-types.d.ts +0 -4
- package/dist/src/serialize-pikku-types.js +0 -605
- package/src/serialize-pikku-types.ts +0 -613
|
@@ -7,13 +7,7 @@ import type { InspectorState } from '@pikku/inspector'
|
|
|
7
7
|
* This includes services, middleware count, factory status, etc.
|
|
8
8
|
*/
|
|
9
9
|
export const serializeMiddlewareGroupsMeta = (state: InspectorState) => {
|
|
10
|
-
const lines: string[] = [
|
|
11
|
-
`/**`,
|
|
12
|
-
` * This file was generated by the @pikku/cli`,
|
|
13
|
-
` */`,
|
|
14
|
-
`import { pikkuState } from '@pikku/core'`,
|
|
15
|
-
``,
|
|
16
|
-
]
|
|
10
|
+
const lines: string[] = [`import { pikkuState } from '@pikku/core'`, ``]
|
|
17
11
|
|
|
18
12
|
// Serialize HTTP middleware groups metadata
|
|
19
13
|
const httpGroups: Record<string, any> = {}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { pikkuSessionlessFunc } from '../../../../.pikku/pikku-types.gen.js'
|
|
2
|
+
import { writeFileInDir } from '../../../utils/file-writer.js'
|
|
3
|
+
import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js'
|
|
4
|
+
import { serializePermissionsImports } from './serialize-permissions-imports.js'
|
|
5
|
+
|
|
6
|
+
export const pikkuPermissions: any = pikkuSessionlessFunc<
|
|
7
|
+
void,
|
|
8
|
+
boolean | undefined
|
|
9
|
+
>({
|
|
10
|
+
func: async ({ logger, config, getInspectorState }) => {
|
|
11
|
+
const state = await getInspectorState()
|
|
12
|
+
const { permissions } = state
|
|
13
|
+
const { permissionsFile, packageMappings } = config
|
|
14
|
+
|
|
15
|
+
let filesGenerated = false
|
|
16
|
+
|
|
17
|
+
// Check if there are any permission group factories
|
|
18
|
+
const hasHTTPFactories = Array.from(
|
|
19
|
+
state.http.routePermissions.values()
|
|
20
|
+
).some((meta) => meta.exportName && meta.isFactory)
|
|
21
|
+
const hasTagFactories = Array.from(
|
|
22
|
+
state.permissions.tagPermissions.values()
|
|
23
|
+
).some((meta) => meta.exportName && meta.isFactory)
|
|
24
|
+
const hasFactories = hasHTTPFactories || hasTagFactories
|
|
25
|
+
|
|
26
|
+
// Generate permissions imports file if there are factories
|
|
27
|
+
if (hasFactories) {
|
|
28
|
+
await writeFileInDir(
|
|
29
|
+
logger,
|
|
30
|
+
permissionsFile,
|
|
31
|
+
serializePermissionsImports(
|
|
32
|
+
permissionsFile,
|
|
33
|
+
permissions,
|
|
34
|
+
state.http,
|
|
35
|
+
packageMappings
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
filesGenerated = true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return filesGenerated
|
|
42
|
+
},
|
|
43
|
+
middleware: [
|
|
44
|
+
logCommandInfoAndTime({
|
|
45
|
+
commandStart: 'Serializing Pikku permissions',
|
|
46
|
+
commandEnd: 'Serialized Pikku permissions',
|
|
47
|
+
}),
|
|
48
|
+
],
|
|
49
|
+
})
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { describe, test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert'
|
|
3
|
+
import { serializePermissionsImports } from './serialize-permissions-imports.js'
|
|
4
|
+
import type {
|
|
5
|
+
InspectorPermissionState,
|
|
6
|
+
InspectorHTTPState,
|
|
7
|
+
PermissionGroupMeta,
|
|
8
|
+
} from '@pikku/inspector'
|
|
9
|
+
|
|
10
|
+
describe('serializePermissionsImports', () => {
|
|
11
|
+
test('should return empty string when no permission factories exist', () => {
|
|
12
|
+
const permissionsState: InspectorPermissionState = {
|
|
13
|
+
meta: {},
|
|
14
|
+
tagPermissions: new Map(),
|
|
15
|
+
}
|
|
16
|
+
const httpState: InspectorHTTPState = {
|
|
17
|
+
metaInputTypes: new Map(),
|
|
18
|
+
meta: {
|
|
19
|
+
get: {},
|
|
20
|
+
post: {},
|
|
21
|
+
put: {},
|
|
22
|
+
delete: {},
|
|
23
|
+
head: {},
|
|
24
|
+
patch: {},
|
|
25
|
+
options: {},
|
|
26
|
+
},
|
|
27
|
+
files: new Set(),
|
|
28
|
+
routeMiddleware: new Map(),
|
|
29
|
+
routePermissions: new Map(),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const result = serializePermissionsImports(
|
|
33
|
+
'/test/output.ts',
|
|
34
|
+
permissionsState,
|
|
35
|
+
httpState
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
assert.strictEqual(result, '')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('should generate imports and calls for HTTP permission factories', () => {
|
|
42
|
+
const permissionsState: InspectorPermissionState = {
|
|
43
|
+
meta: {},
|
|
44
|
+
tagPermissions: new Map(),
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const httpPermissionMeta: PermissionGroupMeta = {
|
|
48
|
+
exportName: 'globalHttpPermissions',
|
|
49
|
+
sourceFile: '/src/permissions/http.ts',
|
|
50
|
+
position: 100,
|
|
51
|
+
services: { services: [], singletons: [] },
|
|
52
|
+
permissionCount: 2,
|
|
53
|
+
isFactory: true,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const httpState: InspectorHTTPState = {
|
|
57
|
+
metaInputTypes: new Map(),
|
|
58
|
+
meta: {
|
|
59
|
+
get: {},
|
|
60
|
+
post: {},
|
|
61
|
+
put: {},
|
|
62
|
+
delete: {},
|
|
63
|
+
head: {},
|
|
64
|
+
patch: {},
|
|
65
|
+
options: {},
|
|
66
|
+
},
|
|
67
|
+
files: new Set(),
|
|
68
|
+
routeMiddleware: new Map(),
|
|
69
|
+
routePermissions: new Map([['*', httpPermissionMeta]]),
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const result = serializePermissionsImports(
|
|
73
|
+
'/test/.pikku/permissions/output.ts',
|
|
74
|
+
permissionsState,
|
|
75
|
+
httpState,
|
|
76
|
+
{}
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
assert.ok(
|
|
80
|
+
result.includes(
|
|
81
|
+
'/* Call permission group factories to register at module evaluation */'
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
assert.ok(result.includes('import { globalHttpPermissions } from'))
|
|
85
|
+
assert.ok(result.includes('globalHttpPermissions()'))
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('should generate imports and calls for tag permission factories', () => {
|
|
89
|
+
const tagPermissionMeta: PermissionGroupMeta = {
|
|
90
|
+
exportName: 'adminPermissions',
|
|
91
|
+
sourceFile: '/src/permissions/admin.ts',
|
|
92
|
+
position: 200,
|
|
93
|
+
services: { services: [], singletons: [] },
|
|
94
|
+
permissionCount: 3,
|
|
95
|
+
isFactory: true,
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const permissionsState: InspectorPermissionState = {
|
|
99
|
+
meta: {},
|
|
100
|
+
tagPermissions: new Map([['admin', tagPermissionMeta]]),
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const httpState: InspectorHTTPState = {
|
|
104
|
+
metaInputTypes: new Map(),
|
|
105
|
+
meta: {
|
|
106
|
+
get: {},
|
|
107
|
+
post: {},
|
|
108
|
+
put: {},
|
|
109
|
+
delete: {},
|
|
110
|
+
head: {},
|
|
111
|
+
patch: {},
|
|
112
|
+
options: {},
|
|
113
|
+
},
|
|
114
|
+
files: new Set(),
|
|
115
|
+
routeMiddleware: new Map(),
|
|
116
|
+
routePermissions: new Map(),
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const result = serializePermissionsImports(
|
|
120
|
+
'/test/.pikku/permissions/output.ts',
|
|
121
|
+
permissionsState,
|
|
122
|
+
httpState,
|
|
123
|
+
{}
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
assert.ok(result.includes('import { adminPermissions } from'))
|
|
127
|
+
assert.ok(result.includes('adminPermissions()'))
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('should deduplicate permission factories used in both HTTP and tag groups', () => {
|
|
131
|
+
const sharedPermissionMeta: PermissionGroupMeta = {
|
|
132
|
+
exportName: 'sharedPermissions',
|
|
133
|
+
sourceFile: '/src/permissions/shared.ts',
|
|
134
|
+
position: 300,
|
|
135
|
+
services: { services: [], singletons: [] },
|
|
136
|
+
permissionCount: 1,
|
|
137
|
+
isFactory: true,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const permissionsState: InspectorPermissionState = {
|
|
141
|
+
meta: {},
|
|
142
|
+
tagPermissions: new Map([['shared', sharedPermissionMeta]]),
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const httpState: InspectorHTTPState = {
|
|
146
|
+
metaInputTypes: new Map(),
|
|
147
|
+
meta: {
|
|
148
|
+
get: {},
|
|
149
|
+
post: {},
|
|
150
|
+
put: {},
|
|
151
|
+
delete: {},
|
|
152
|
+
head: {},
|
|
153
|
+
patch: {},
|
|
154
|
+
options: {},
|
|
155
|
+
},
|
|
156
|
+
files: new Set(),
|
|
157
|
+
routeMiddleware: new Map(),
|
|
158
|
+
routePermissions: new Map([
|
|
159
|
+
['/api/*', { ...sharedPermissionMeta, position: 400 }],
|
|
160
|
+
]),
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const result = serializePermissionsImports(
|
|
164
|
+
'/test/.pikku/permissions/output.ts',
|
|
165
|
+
permissionsState,
|
|
166
|
+
httpState,
|
|
167
|
+
{}
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
// Should only have one import and one call despite being in both maps
|
|
171
|
+
const importMatches = result.match(/import { sharedPermissions }/g)
|
|
172
|
+
const callMatches = result.match(/sharedPermissions\(\)/g)
|
|
173
|
+
|
|
174
|
+
assert.strictEqual(
|
|
175
|
+
importMatches?.length,
|
|
176
|
+
1,
|
|
177
|
+
'Should have exactly one import'
|
|
178
|
+
)
|
|
179
|
+
assert.strictEqual(
|
|
180
|
+
callMatches?.length,
|
|
181
|
+
1,
|
|
182
|
+
'Should have exactly one function call'
|
|
183
|
+
)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('should skip non-factory permission groups', () => {
|
|
187
|
+
const nonFactoryMeta: PermissionGroupMeta = {
|
|
188
|
+
exportName: 'directPermissions',
|
|
189
|
+
sourceFile: '/src/permissions/direct.ts',
|
|
190
|
+
position: 500,
|
|
191
|
+
services: { services: [], singletons: [] },
|
|
192
|
+
permissionCount: 2,
|
|
193
|
+
isFactory: false, // Not a factory
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const permissionsState: InspectorPermissionState = {
|
|
197
|
+
meta: {},
|
|
198
|
+
tagPermissions: new Map([['direct', nonFactoryMeta]]),
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const httpState: InspectorHTTPState = {
|
|
202
|
+
metaInputTypes: new Map(),
|
|
203
|
+
meta: {
|
|
204
|
+
get: {},
|
|
205
|
+
post: {},
|
|
206
|
+
put: {},
|
|
207
|
+
delete: {},
|
|
208
|
+
head: {},
|
|
209
|
+
patch: {},
|
|
210
|
+
options: {},
|
|
211
|
+
},
|
|
212
|
+
files: new Set(),
|
|
213
|
+
routeMiddleware: new Map(),
|
|
214
|
+
routePermissions: new Map(),
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const result = serializePermissionsImports(
|
|
218
|
+
'/test/.pikku/permissions/output.ts',
|
|
219
|
+
permissionsState,
|
|
220
|
+
httpState,
|
|
221
|
+
{}
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
assert.strictEqual(
|
|
225
|
+
result,
|
|
226
|
+
'',
|
|
227
|
+
'Should not generate anything for non-factory permissions'
|
|
228
|
+
)
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
test('should handle package mappings correctly', () => {
|
|
232
|
+
const permissionMeta: PermissionGroupMeta = {
|
|
233
|
+
exportName: 'apiPermissions',
|
|
234
|
+
sourceFile: '/Users/test/project/packages/api/src/permissions.ts',
|
|
235
|
+
position: 600,
|
|
236
|
+
services: { services: [], singletons: [] },
|
|
237
|
+
permissionCount: 1,
|
|
238
|
+
isFactory: true,
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const permissionsState: InspectorPermissionState = {
|
|
242
|
+
meta: {},
|
|
243
|
+
tagPermissions: new Map([['api', permissionMeta]]),
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const httpState: InspectorHTTPState = {
|
|
247
|
+
metaInputTypes: new Map(),
|
|
248
|
+
meta: {
|
|
249
|
+
get: {},
|
|
250
|
+
post: {},
|
|
251
|
+
put: {},
|
|
252
|
+
delete: {},
|
|
253
|
+
head: {},
|
|
254
|
+
patch: {},
|
|
255
|
+
options: {},
|
|
256
|
+
},
|
|
257
|
+
files: new Set(),
|
|
258
|
+
routeMiddleware: new Map(),
|
|
259
|
+
routePermissions: new Map(),
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const result = serializePermissionsImports(
|
|
263
|
+
'/Users/test/project/.pikku/permissions/output.ts',
|
|
264
|
+
permissionsState,
|
|
265
|
+
httpState,
|
|
266
|
+
{ '/Users/test/project/packages/api/src': '@myapp/api' }
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
// Should use package mapping (or relative path if mapping doesn't match)
|
|
270
|
+
// The actual behavior depends on getFileImportRelativePath implementation
|
|
271
|
+
assert.ok(result.includes('import { apiPermissions } from'))
|
|
272
|
+
assert.ok(result.includes('apiPermissions()'))
|
|
273
|
+
})
|
|
274
|
+
})
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getFileImportRelativePath } from '../../../utils/file-import-path.js'
|
|
2
|
+
import type {
|
|
3
|
+
InspectorPermissionState,
|
|
4
|
+
InspectorHTTPState,
|
|
5
|
+
InspectorState,
|
|
6
|
+
} from '@pikku/inspector'
|
|
7
|
+
|
|
8
|
+
export const serializePermissionsImports = (
|
|
9
|
+
outputPath: string,
|
|
10
|
+
permissionsState: InspectorPermissionState,
|
|
11
|
+
httpState: InspectorHTTPState,
|
|
12
|
+
packageMappings: Record<string, string> = {},
|
|
13
|
+
fullState?: InspectorState
|
|
14
|
+
) => {
|
|
15
|
+
const serializedImports: string[] = []
|
|
16
|
+
const serializedFactoryCalls: string[] = []
|
|
17
|
+
|
|
18
|
+
// Collect factory imports and calls for HTTP permission groups
|
|
19
|
+
const httpFactories = new Map<
|
|
20
|
+
string,
|
|
21
|
+
{ exportName: string; filePath: string }
|
|
22
|
+
>()
|
|
23
|
+
for (const [, groupMeta] of httpState.routePermissions.entries()) {
|
|
24
|
+
if (groupMeta.exportName && groupMeta.isFactory) {
|
|
25
|
+
const filePath = getFileImportRelativePath(
|
|
26
|
+
outputPath,
|
|
27
|
+
groupMeta.sourceFile,
|
|
28
|
+
packageMappings
|
|
29
|
+
)
|
|
30
|
+
httpFactories.set(groupMeta.exportName, {
|
|
31
|
+
exportName: groupMeta.exportName,
|
|
32
|
+
filePath,
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Collect factory imports and calls for tag permission groups
|
|
38
|
+
const tagFactories = new Map<
|
|
39
|
+
string,
|
|
40
|
+
{ exportName: string; filePath: string }
|
|
41
|
+
>()
|
|
42
|
+
for (const [, groupMeta] of permissionsState.tagPermissions.entries()) {
|
|
43
|
+
if (groupMeta.exportName && groupMeta.isFactory) {
|
|
44
|
+
const filePath = getFileImportRelativePath(
|
|
45
|
+
outputPath,
|
|
46
|
+
groupMeta.sourceFile,
|
|
47
|
+
packageMappings
|
|
48
|
+
)
|
|
49
|
+
tagFactories.set(groupMeta.exportName, {
|
|
50
|
+
exportName: groupMeta.exportName,
|
|
51
|
+
filePath,
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Combine all factories and deduplicate by exportName (same factory might be used in multiple groups)
|
|
57
|
+
const allFactories = new Map([...httpFactories, ...tagFactories])
|
|
58
|
+
|
|
59
|
+
// Add factory imports and calls
|
|
60
|
+
if (allFactories.size > 0) {
|
|
61
|
+
serializedImports.push(
|
|
62
|
+
'/* Call permission group factories to register at module evaluation */'
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
// Import factories
|
|
66
|
+
for (const [exportName, { filePath }] of allFactories) {
|
|
67
|
+
serializedImports.push(`import { ${exportName} } from '${filePath}'`)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Call factories
|
|
71
|
+
for (const [exportName] of allFactories) {
|
|
72
|
+
serializedFactoryCalls.push(`${exportName}()`)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Return combined output
|
|
77
|
+
return [...serializedImports, ...serializedFactoryCalls].join('\n')
|
|
78
|
+
}
|
|
@@ -21,11 +21,6 @@ export const pikkuQueueMap: any = pikkuSessionlessFunc<void, void>({
|
|
|
21
21
|
logCommandInfoAndTime({
|
|
22
22
|
commandStart: 'Creating Queue map',
|
|
23
23
|
commandEnd: 'Created Queue map',
|
|
24
|
-
skipCondition: async ({ getInspectorState }) => {
|
|
25
|
-
const { queueWorkers } = await getInspectorState()
|
|
26
|
-
return queueWorkers.files.size === 0
|
|
27
|
-
},
|
|
28
|
-
skipMessage: 'none found',
|
|
29
24
|
}),
|
|
30
25
|
],
|
|
31
26
|
})
|
|
@@ -9,8 +9,14 @@ export const pikkuQueueService: any = pikkuSessionlessFunc<void, void>({
|
|
|
9
9
|
const { queueWiringsFile, queueMapDeclarationFile, packageMappings } =
|
|
10
10
|
config
|
|
11
11
|
|
|
12
|
+
// If queueWiringsFile is not set, clean up any existing file and return
|
|
12
13
|
if (!queueWiringsFile) {
|
|
13
|
-
|
|
14
|
+
logger.info({
|
|
15
|
+
message:
|
|
16
|
+
"Skipping generating queue service wrapper since queueWiringsFile isn't set in the pikku config.",
|
|
17
|
+
type: 'skip',
|
|
18
|
+
})
|
|
19
|
+
return
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
const queueMapDeclarationPath = getFileImportRelativePath(
|
|
@@ -26,8 +32,6 @@ export const pikkuQueueService: any = pikkuSessionlessFunc<void, void>({
|
|
|
26
32
|
logCommandInfoAndTime({
|
|
27
33
|
commandStart: 'Generating queue service wrapper',
|
|
28
34
|
commandEnd: 'Generated queue service wrapper',
|
|
29
|
-
skipCondition: ({ config }) => config.queueWiringsFile === undefined,
|
|
30
|
-
skipMessage: "queueWiringsFile isn't set in the pikku config",
|
|
31
35
|
}),
|
|
32
36
|
],
|
|
33
37
|
})
|
|
@@ -36,11 +36,6 @@ export const pikkuQueue: any = pikkuSessionlessFunc<void, boolean | undefined>({
|
|
|
36
36
|
logCommandInfoAndTime({
|
|
37
37
|
commandStart: 'Finding Queues',
|
|
38
38
|
commandEnd: 'Found Queues',
|
|
39
|
-
skipCondition: async ({ getInspectorState }) => {
|
|
40
|
-
const visitState = await getInspectorState()
|
|
41
|
-
return visitState.queueWorkers.files.size === 0
|
|
42
|
-
},
|
|
43
|
-
skipMessage: 'none found',
|
|
44
39
|
}),
|
|
45
40
|
],
|
|
46
41
|
})
|
|
@@ -21,11 +21,6 @@ export const pikkuQueueMap: any = pikkuSessionlessFunc<void, void>({
|
|
|
21
21
|
logCommandInfoAndTime({
|
|
22
22
|
commandStart: 'Creating Queue map',
|
|
23
23
|
commandEnd: 'Created Queue map',
|
|
24
|
-
skipCondition: async ({ getInspectorState }) => {
|
|
25
|
-
const { queueWorkers } = await getInspectorState()
|
|
26
|
-
return queueWorkers.files.size === 0
|
|
27
|
-
},
|
|
28
|
-
skipMessage: 'none found',
|
|
29
24
|
}),
|
|
30
25
|
],
|
|
31
26
|
})
|
|
@@ -4,7 +4,7 @@ import { writeFileInDir } from '../../../utils/file-writer.js'
|
|
|
4
4
|
import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js'
|
|
5
5
|
import { serializeQueueMeta } from './serialize-queue-meta.js'
|
|
6
6
|
|
|
7
|
-
export const pikkuQueue: any = pikkuSessionlessFunc<void,
|
|
7
|
+
export const pikkuQueue: any = pikkuSessionlessFunc<void, boolean>({
|
|
8
8
|
func: async ({ logger, config, getInspectorState }) => {
|
|
9
9
|
const visitState = await getInspectorState()
|
|
10
10
|
const {
|
|
@@ -29,16 +29,13 @@ export const pikkuQueue: any = pikkuSessionlessFunc<void, void>({
|
|
|
29
29
|
packageMappings
|
|
30
30
|
)
|
|
31
31
|
)
|
|
32
|
+
|
|
33
|
+
return true
|
|
32
34
|
},
|
|
33
35
|
middleware: [
|
|
34
36
|
logCommandInfoAndTime({
|
|
35
37
|
commandStart: 'Finding queues',
|
|
36
38
|
commandEnd: 'Found queue',
|
|
37
|
-
skipCondition: async ({ getInspectorState }) => {
|
|
38
|
-
const { queueWorkers } = await getInspectorState()
|
|
39
|
-
return queueWorkers.files.size === 0
|
|
40
|
-
},
|
|
41
|
-
skipMessage: 'none found',
|
|
42
39
|
}),
|
|
43
40
|
],
|
|
44
41
|
})
|
|
@@ -8,9 +8,14 @@ export const pikkuRPCClient: any = pikkuSessionlessFunc<void, void>({
|
|
|
8
8
|
func: async ({ logger, config }) => {
|
|
9
9
|
const { rpcWiringsFile, rpcMapDeclarationFile, packageMappings } = config
|
|
10
10
|
|
|
11
|
+
// If rpcWiringsFile is not set, clean up any existing file and return
|
|
11
12
|
if (!rpcWiringsFile) {
|
|
13
|
+
logger.info({
|
|
14
|
+
message:
|
|
15
|
+
"Skipping generating RPC wrappers since rpcWiringsFile isn't set in the pikku config.",
|
|
16
|
+
type: 'skip',
|
|
17
|
+
})
|
|
12
18
|
return
|
|
13
|
-
// TODO: throw new Error("rpcWiringsFile isn't set in the pikku config")
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
const rpcMapDeclarationPath = getFileImportRelativePath(
|
|
@@ -25,8 +30,6 @@ export const pikkuRPCClient: any = pikkuSessionlessFunc<void, void>({
|
|
|
25
30
|
logCommandInfoAndTime({
|
|
26
31
|
commandStart: 'Generating RPC wrappers',
|
|
27
32
|
commandEnd: 'Generated RPC wrappers',
|
|
28
|
-
skipCondition: ({ config }) => config.rpcWiringsFile === undefined,
|
|
29
|
-
skipMessage: "rpcWiringsFile isn't set in the pikku config",
|
|
30
33
|
}),
|
|
31
34
|
],
|
|
32
35
|
})
|
|
@@ -21,8 +21,6 @@ export const pikkuRPCInternalMap: any = pikkuSessionlessFunc<void, void>({
|
|
|
21
21
|
logCommandInfoAndTime({
|
|
22
22
|
commandStart: 'Creating RPC internal map',
|
|
23
23
|
commandEnd: 'Created RPC internal map',
|
|
24
|
-
skipCondition: false,
|
|
25
|
-
skipMessage: '',
|
|
26
24
|
}),
|
|
27
25
|
],
|
|
28
26
|
})
|
|
@@ -45,8 +43,6 @@ export const pikkuRPCExposedMap: any = pikkuSessionlessFunc<void, void>({
|
|
|
45
43
|
logCommandInfoAndTime({
|
|
46
44
|
commandStart: 'Creating RPC external map',
|
|
47
45
|
commandEnd: 'Created RPC external map',
|
|
48
|
-
skipCondition: false,
|
|
49
|
-
skipMessage: '',
|
|
50
46
|
}),
|
|
51
47
|
],
|
|
52
48
|
})
|
|
@@ -36,11 +36,6 @@ export const pikkuScheduler: any = pikkuSessionlessFunc<
|
|
|
36
36
|
logCommandInfoAndTime({
|
|
37
37
|
commandStart: 'Finding Scheduled tasks',
|
|
38
38
|
commandEnd: 'Found Scheduled tasks',
|
|
39
|
-
skipCondition: async ({ getInspectorState }) => {
|
|
40
|
-
const visitState = await getInspectorState()
|
|
41
|
-
return visitState.scheduledTasks.files.size === 0
|
|
42
|
-
},
|
|
43
|
-
skipMessage: 'none found',
|
|
44
39
|
}),
|
|
45
40
|
],
|
|
46
41
|
})
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SingletonServices,
|
|
3
|
-
Services,
|
|
4
|
-
} from '../../types/application-types.js'
|
|
1
|
+
import type { Services } from '../../types/application-types.js'
|
|
5
2
|
import type { PikkuInteraction } from '@pikku/core'
|
|
6
3
|
|
|
7
4
|
// Middleware type for CLI
|
|
@@ -14,40 +11,17 @@ type PikkuMiddleware = (
|
|
|
14
11
|
export interface LogCommandInfoOptions {
|
|
15
12
|
commandStart: string
|
|
16
13
|
commandEnd: string
|
|
17
|
-
skipCondition?:
|
|
18
|
-
| boolean
|
|
19
|
-
| ((services: SingletonServices) => boolean | Promise<boolean>)
|
|
20
|
-
skipMessage?: string
|
|
21
14
|
}
|
|
22
15
|
|
|
23
16
|
/**
|
|
24
17
|
* Middleware to log command execution timing and status
|
|
25
18
|
* Replaces the logCommandInfoAndTime wrapper function
|
|
26
|
-
*
|
|
27
|
-
* The skipCondition can be:
|
|
28
|
-
* - A boolean valuewe
|
|
29
|
-
* - A function that receives services and returns a boolean (can access getInspectorState)
|
|
30
19
|
*/
|
|
31
20
|
export const logCommandInfoAndTime = ({
|
|
32
21
|
commandStart,
|
|
33
22
|
commandEnd,
|
|
34
|
-
skipCondition = false,
|
|
35
|
-
skipMessage = 'none found',
|
|
36
23
|
}: LogCommandInfoOptions): PikkuMiddleware => {
|
|
37
|
-
return async ({ logger
|
|
38
|
-
// Evaluate skip condition (can be boolean or function)
|
|
39
|
-
const shouldSkip =
|
|
40
|
-
typeof skipCondition === 'function'
|
|
41
|
-
? await skipCondition({ logger, ...services } as any)
|
|
42
|
-
: skipCondition
|
|
43
|
-
|
|
44
|
-
if (shouldSkip === true) {
|
|
45
|
-
logger.info(
|
|
46
|
-
`• Skipping ${commandStart.charAt(0).toLocaleLowerCase()}${commandStart.slice(1)} since ${skipMessage}.`
|
|
47
|
-
)
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
|
|
24
|
+
return async ({ logger }, _interaction, next) => {
|
|
51
25
|
// Log start
|
|
52
26
|
const start = Date.now()
|
|
53
27
|
logger.info(`• ${commandStart}...`)
|