@pikku/inspector 0.9.5 → 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/CHANGELOG.md +14 -0
- package/dist/add/add-channel.d.ts +17 -0
- package/dist/{add-channel.js → add/add-channel.js} +60 -34
- package/dist/add/add-cli.d.ts +9 -0
- package/dist/add/add-cli.js +566 -0
- package/dist/{add-file-extends-core-type.d.ts → add/add-file-extends-core-type.d.ts} +2 -2
- package/dist/{add-file-extends-core-type.js → add/add-file-extends-core-type.js} +17 -4
- package/dist/{add-file-with-config.d.ts → add/add-file-with-config.d.ts} +1 -1
- package/dist/{add-file-with-config.js → add/add-file-with-config.js} +1 -1
- package/dist/{add-file-with-factory.d.ts → add/add-file-with-factory.d.ts} +2 -2
- package/dist/{add-file-with-factory.js → add/add-file-with-factory.js} +38 -5
- package/dist/add/add-functions.d.ts +6 -0
- package/dist/{add-functions.js → add/add-functions.js} +77 -10
- package/dist/{add-http-route.d.ts → add/add-http-route.d.ts} +2 -3
- package/dist/{add-http-route.js → add/add-http-route.js} +26 -13
- package/dist/add/add-mcp-prompt.d.ts +2 -0
- package/dist/add/add-mcp-prompt.js +74 -0
- package/dist/add/add-mcp-resource.d.ts +2 -0
- package/dist/add/add-mcp-resource.js +84 -0
- package/dist/add/add-mcp-tool.d.ts +2 -0
- package/dist/add/add-mcp-tool.js +80 -0
- package/dist/add/add-middleware.d.ts +5 -0
- package/dist/add/add-middleware.js +290 -0
- package/dist/add/add-permission.d.ts +5 -0
- package/dist/add/add-permission.js +292 -0
- package/dist/add/add-queue-worker.d.ts +2 -0
- package/dist/add/add-queue-worker.js +52 -0
- package/dist/{add-rpc-invocations.d.ts → add/add-rpc-invocations.d.ts} +1 -1
- package/dist/add/add-schedule.d.ts +2 -0
- package/dist/{add-schedule.js → add/add-schedule.js} +16 -11
- package/dist/error-codes.d.ts +35 -0
- package/dist/error-codes.js +40 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/inspector.d.ts +2 -3
- package/dist/inspector.js +38 -8
- package/dist/types.d.ts +108 -1
- package/dist/utils/ensure-function-metadata.d.ts +6 -0
- package/dist/utils/ensure-function-metadata.js +18 -0
- package/dist/utils/extract-function-name.d.ts +31 -0
- package/dist/{utils.js → utils/extract-function-name.js} +35 -149
- package/dist/utils/extract-services.d.ts +6 -0
- package/dist/utils/extract-services.js +29 -0
- package/dist/utils/filter-inspector-state.d.ts +6 -0
- package/dist/utils/filter-inspector-state.js +382 -0
- package/dist/utils/filter-utils.d.ts +19 -0
- package/dist/utils/filter-utils.js +109 -0
- package/dist/utils/find-root-dir.d.ts +23 -0
- package/dist/utils/find-root-dir.js +55 -0
- package/dist/utils/get-files-and-methods.d.ts +22 -0
- package/dist/utils/get-files-and-methods.js +61 -0
- package/dist/utils/get-property-value.d.ts +12 -0
- package/dist/{get-property-value.js → utils/get-property-value.js} +20 -0
- package/dist/utils/middleware.d.ts +39 -0
- package/dist/utils/middleware.js +157 -0
- package/dist/utils/permissions.d.ts +43 -0
- package/dist/utils/permissions.js +178 -0
- package/dist/utils/post-process.d.ts +16 -0
- package/dist/utils/post-process.js +132 -0
- package/dist/utils/serialize-inspector-state.d.ts +179 -0
- package/dist/utils/serialize-inspector-state.js +170 -0
- package/dist/utils/type-utils.d.ts +3 -0
- package/dist/utils/type-utils.js +50 -0
- package/dist/visit.d.ts +3 -3
- package/dist/visit.js +35 -31
- package/package.json +5 -6
- package/src/{add-channel.ts → add/add-channel.ts} +108 -56
- package/src/add/add-cli.ts +822 -0
- package/src/{add-file-extends-core-type.ts → add/add-file-extends-core-type.ts} +23 -5
- package/src/{add-file-with-config.ts → add/add-file-with-config.ts} +2 -2
- package/src/{add-file-with-factory.ts → add/add-file-with-factory.ts} +49 -6
- package/src/{add-functions.ts → add/add-functions.ts} +89 -19
- package/src/{add-http-route.ts → add/add-http-route.ts} +66 -32
- package/src/add/add-mcp-prompt.ts +128 -0
- package/src/add/add-mcp-prompt.ts.tmp +0 -0
- package/src/add/add-mcp-resource.ts +145 -0
- package/src/add/add-mcp-resource.ts.tmp +0 -0
- package/src/add/add-mcp-tool.ts +137 -0
- package/src/add/add-middleware.ts +385 -0
- package/src/add/add-permission.ts +391 -0
- package/src/add/add-queue-worker.ts +92 -0
- package/src/{add-rpc-invocations.ts → add/add-rpc-invocations.ts} +1 -1
- package/src/{add-schedule.ts → add/add-schedule.ts} +30 -28
- package/src/error-codes.ts +43 -0
- package/src/index.ts +12 -0
- package/src/inspector.ts +41 -17
- package/src/types.ts +128 -1
- package/src/utils/ensure-function-metadata.ts +24 -0
- package/src/{utils.ts → utils/extract-function-name.ts} +44 -206
- package/src/utils/extract-services.ts +35 -0
- package/src/utils/filter-inspector-state.test.ts +1433 -0
- package/src/utils/filter-inspector-state.ts +526 -0
- package/src/{utils.test.ts → utils/filter-utils.test.ts} +351 -2
- package/src/utils/filter-utils.ts +152 -0
- package/src/utils/find-root-dir.ts +68 -0
- package/src/utils/get-files-and-methods.ts +151 -0
- package/src/{get-property-value.ts → utils/get-property-value.ts} +27 -0
- package/src/utils/middleware.ts +241 -0
- package/src/utils/permissions.test.ts +327 -0
- package/src/utils/permissions.ts +262 -0
- package/src/utils/post-process.ts +178 -0
- package/src/utils/serialize-inspector-state.ts +375 -0
- package/src/utils/test-data/inspector-state.json +1680 -0
- package/src/utils/type-utils.ts +74 -0
- package/src/visit.ts +50 -34
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/add-channel.d.ts +0 -13
- package/dist/add-functions.d.ts +0 -7
- package/dist/add-mcp-prompt.d.ts +0 -3
- package/dist/add-mcp-prompt.js +0 -61
- package/dist/add-mcp-resource.d.ts +0 -3
- package/dist/add-mcp-resource.js +0 -68
- package/dist/add-mcp-tool.d.ts +0 -3
- package/dist/add-mcp-tool.js +0 -64
- package/dist/add-middleware.d.ts +0 -7
- package/dist/add-middleware.js +0 -35
- package/dist/add-permission.d.ts +0 -7
- package/dist/add-permission.js +0 -35
- package/dist/add-queue-worker.d.ts +0 -3
- package/dist/add-queue-worker.js +0 -48
- package/dist/add-schedule.d.ts +0 -3
- package/dist/get-property-value.d.ts +0 -3
- package/dist/utils.d.ts +0 -39
- package/src/add-mcp-prompt.ts +0 -104
- package/src/add-mcp-resource.ts +0 -116
- package/src/add-mcp-tool.ts +0 -107
- package/src/add-middleware.ts +0 -51
- package/src/add-permission.ts +0 -53
- package/src/add-queue-worker.ts +0 -92
- /package/dist/{add-rpc-invocations.js → add/add-rpc-invocations.js} +0 -0
- /package/dist/{does-type-extend-core-type.d.ts → utils/does-type-extend-core-type.d.ts} +0 -0
- /package/dist/{does-type-extend-core-type.js → utils/does-type-extend-core-type.js} +0 -0
- /package/src/{does-type-extend-core-type.ts → utils/does-type-extend-core-type.ts} +0 -0
package/src/add-middleware.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript'
|
|
2
|
-
import { InspectorLogger, InspectorState } from './types.js'
|
|
3
|
-
import { extractFunctionName, extractServicesFromFunction } from './utils.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Inspect pikkuMiddleware calls and extract first-arg destructuring
|
|
7
|
-
* for tree shaking optimization.
|
|
8
|
-
*/
|
|
9
|
-
export function addMiddleware(
|
|
10
|
-
node: ts.Node,
|
|
11
|
-
checker: ts.TypeChecker,
|
|
12
|
-
state: InspectorState,
|
|
13
|
-
logger: InspectorLogger
|
|
14
|
-
) {
|
|
15
|
-
if (!ts.isCallExpression(node)) return
|
|
16
|
-
|
|
17
|
-
const { expression, arguments: args } = node
|
|
18
|
-
|
|
19
|
-
// only handle calls like pikkuMiddleware(...)
|
|
20
|
-
if (!ts.isIdentifier(expression)) {
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (expression.text !== 'pikkuMiddleware') {
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const handlerNode = args[0]
|
|
29
|
-
if (!handlerNode) return
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
!ts.isArrowFunction(handlerNode) &&
|
|
33
|
-
!ts.isFunctionExpression(handlerNode)
|
|
34
|
-
) {
|
|
35
|
-
logger.error(`• Handler for pikkuMiddleware is not a function.`)
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const services = extractServicesFromFunction(handlerNode)
|
|
40
|
-
const { pikkuFuncName, exportedName } = extractFunctionName(node, checker)
|
|
41
|
-
state.middleware.meta[pikkuFuncName] = {
|
|
42
|
-
services,
|
|
43
|
-
sourceFile: node.getSourceFile().fileName,
|
|
44
|
-
position: node.getStart(),
|
|
45
|
-
exportedName,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
logger.debug(
|
|
49
|
-
`• Found middleware with services: ${services.services.join(', ')}`
|
|
50
|
-
)
|
|
51
|
-
}
|
package/src/add-permission.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript'
|
|
2
|
-
import { InspectorLogger, InspectorState } from './types.js'
|
|
3
|
-
import { extractFunctionName, extractServicesFromFunction } from './utils.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Inspect pikkuPermission calls and extract first-arg destructuring
|
|
7
|
-
* for tree shaking optimization.
|
|
8
|
-
*/
|
|
9
|
-
export function addPermission(
|
|
10
|
-
node: ts.Node,
|
|
11
|
-
checker: ts.TypeChecker,
|
|
12
|
-
state: InspectorState,
|
|
13
|
-
logger: InspectorLogger
|
|
14
|
-
) {
|
|
15
|
-
if (!ts.isCallExpression(node)) return
|
|
16
|
-
|
|
17
|
-
const { expression, arguments: args } = node
|
|
18
|
-
|
|
19
|
-
// only handle calls like pikkuPermission(...)
|
|
20
|
-
if (!ts.isIdentifier(expression)) {
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (expression.text !== 'pikkuPermission') {
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const handlerNode = args[0]
|
|
29
|
-
if (!handlerNode) return
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
!ts.isArrowFunction(handlerNode) &&
|
|
33
|
-
!ts.isFunctionExpression(handlerNode)
|
|
34
|
-
) {
|
|
35
|
-
logger.error(`• Handler for pikkuPermission is not a function.`)
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const services = extractServicesFromFunction(handlerNode)
|
|
40
|
-
|
|
41
|
-
const { pikkuFuncName, exportedName } = extractFunctionName(node, checker)
|
|
42
|
-
|
|
43
|
-
state.permissions.meta[pikkuFuncName] = {
|
|
44
|
-
services,
|
|
45
|
-
sourceFile: node.getSourceFile().fileName,
|
|
46
|
-
position: node.getStart(),
|
|
47
|
-
exportedName,
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
logger.debug(
|
|
51
|
-
`• Found permission with services: ${services.services.join(', ')}`
|
|
52
|
-
)
|
|
53
|
-
}
|
package/src/add-queue-worker.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript'
|
|
2
|
-
import { getPropertyValue } from './get-property-value.js'
|
|
3
|
-
import { PikkuDocs, PikkuWiringTypes } from '@pikku/core'
|
|
4
|
-
import { InspectorFilters, InspectorState, InspectorLogger } from './types.js'
|
|
5
|
-
import {
|
|
6
|
-
extractFunctionName,
|
|
7
|
-
getPropertyAssignmentInitializer,
|
|
8
|
-
matchesFilters,
|
|
9
|
-
} from './utils.js'
|
|
10
|
-
|
|
11
|
-
export const addQueueWorker = (
|
|
12
|
-
node: ts.Node,
|
|
13
|
-
checker: ts.TypeChecker,
|
|
14
|
-
state: InspectorState,
|
|
15
|
-
filters: InspectorFilters,
|
|
16
|
-
logger: InspectorLogger
|
|
17
|
-
) => {
|
|
18
|
-
if (!ts.isCallExpression(node)) {
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const args = node.arguments
|
|
23
|
-
const firstArg = args[0]
|
|
24
|
-
const expression = node.expression
|
|
25
|
-
|
|
26
|
-
// Check if the call is to addQueueWorker
|
|
27
|
-
if (!ts.isIdentifier(expression) || expression.text !== 'wireQueueWorker') {
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!firstArg) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (ts.isObjectLiteralExpression(firstArg)) {
|
|
36
|
-
const obj = firstArg
|
|
37
|
-
|
|
38
|
-
const queueName = getPropertyValue(obj, 'queueName') as string | null
|
|
39
|
-
const docs = (getPropertyValue(obj, 'docs') as PikkuDocs) || undefined
|
|
40
|
-
const tags = (getPropertyValue(obj, 'tags') as string[]) || undefined
|
|
41
|
-
|
|
42
|
-
// --- find the referenced function ---
|
|
43
|
-
const funcInitializer = getPropertyAssignmentInitializer(
|
|
44
|
-
obj,
|
|
45
|
-
'func',
|
|
46
|
-
true,
|
|
47
|
-
checker
|
|
48
|
-
)
|
|
49
|
-
if (!funcInitializer) {
|
|
50
|
-
console.error(
|
|
51
|
-
`• No valid 'func' property for queue processor '${queueName}'.`
|
|
52
|
-
)
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const pikkuFuncName = extractFunctionName(
|
|
57
|
-
funcInitializer,
|
|
58
|
-
checker
|
|
59
|
-
).pikkuFuncName
|
|
60
|
-
|
|
61
|
-
if (!queueName) {
|
|
62
|
-
console.error(
|
|
63
|
-
`• No 'queueName' provided for queue processor function '${pikkuFuncName}'.`
|
|
64
|
-
)
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const filePath = node.getSourceFile().fileName
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
!matchesFilters(
|
|
72
|
-
filters,
|
|
73
|
-
{ tags },
|
|
74
|
-
{ type: PikkuWiringTypes.queue, name: queueName, filePath },
|
|
75
|
-
logger
|
|
76
|
-
)
|
|
77
|
-
) {
|
|
78
|
-
console.info(
|
|
79
|
-
`• Skipping queue processor '${pikkuFuncName}' for queue '${queueName}' due to filter mismatch.`
|
|
80
|
-
)
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
state.queueWorkers.files.add(node.getSourceFile().fileName)
|
|
85
|
-
state.queueWorkers.meta[queueName] = {
|
|
86
|
-
pikkuFuncName,
|
|
87
|
-
queueName,
|
|
88
|
-
docs,
|
|
89
|
-
tags,
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|