@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.
Files changed (133) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/add/add-channel.d.ts +17 -0
  3. package/dist/{add-channel.js → add/add-channel.js} +60 -34
  4. package/dist/add/add-cli.d.ts +9 -0
  5. package/dist/add/add-cli.js +566 -0
  6. package/dist/{add-file-extends-core-type.d.ts → add/add-file-extends-core-type.d.ts} +2 -2
  7. package/dist/{add-file-extends-core-type.js → add/add-file-extends-core-type.js} +17 -4
  8. package/dist/{add-file-with-config.d.ts → add/add-file-with-config.d.ts} +1 -1
  9. package/dist/{add-file-with-config.js → add/add-file-with-config.js} +1 -1
  10. package/dist/{add-file-with-factory.d.ts → add/add-file-with-factory.d.ts} +2 -2
  11. package/dist/{add-file-with-factory.js → add/add-file-with-factory.js} +38 -5
  12. package/dist/add/add-functions.d.ts +6 -0
  13. package/dist/{add-functions.js → add/add-functions.js} +77 -10
  14. package/dist/{add-http-route.d.ts → add/add-http-route.d.ts} +2 -3
  15. package/dist/{add-http-route.js → add/add-http-route.js} +26 -13
  16. package/dist/add/add-mcp-prompt.d.ts +2 -0
  17. package/dist/add/add-mcp-prompt.js +74 -0
  18. package/dist/add/add-mcp-resource.d.ts +2 -0
  19. package/dist/add/add-mcp-resource.js +84 -0
  20. package/dist/add/add-mcp-tool.d.ts +2 -0
  21. package/dist/add/add-mcp-tool.js +80 -0
  22. package/dist/add/add-middleware.d.ts +5 -0
  23. package/dist/add/add-middleware.js +290 -0
  24. package/dist/add/add-permission.d.ts +5 -0
  25. package/dist/add/add-permission.js +292 -0
  26. package/dist/add/add-queue-worker.d.ts +2 -0
  27. package/dist/add/add-queue-worker.js +52 -0
  28. package/dist/{add-rpc-invocations.d.ts → add/add-rpc-invocations.d.ts} +1 -1
  29. package/dist/add/add-schedule.d.ts +2 -0
  30. package/dist/{add-schedule.js → add/add-schedule.js} +16 -11
  31. package/dist/error-codes.d.ts +35 -0
  32. package/dist/error-codes.js +40 -0
  33. package/dist/index.d.ts +6 -0
  34. package/dist/index.js +4 -0
  35. package/dist/inspector.d.ts +2 -3
  36. package/dist/inspector.js +38 -8
  37. package/dist/types.d.ts +108 -1
  38. package/dist/utils/ensure-function-metadata.d.ts +6 -0
  39. package/dist/utils/ensure-function-metadata.js +18 -0
  40. package/dist/utils/extract-function-name.d.ts +31 -0
  41. package/dist/{utils.js → utils/extract-function-name.js} +35 -149
  42. package/dist/utils/extract-services.d.ts +6 -0
  43. package/dist/utils/extract-services.js +29 -0
  44. package/dist/utils/filter-inspector-state.d.ts +6 -0
  45. package/dist/utils/filter-inspector-state.js +382 -0
  46. package/dist/utils/filter-utils.d.ts +19 -0
  47. package/dist/utils/filter-utils.js +109 -0
  48. package/dist/utils/find-root-dir.d.ts +23 -0
  49. package/dist/utils/find-root-dir.js +55 -0
  50. package/dist/utils/get-files-and-methods.d.ts +22 -0
  51. package/dist/utils/get-files-and-methods.js +61 -0
  52. package/dist/utils/get-property-value.d.ts +12 -0
  53. package/dist/{get-property-value.js → utils/get-property-value.js} +20 -0
  54. package/dist/utils/middleware.d.ts +39 -0
  55. package/dist/utils/middleware.js +157 -0
  56. package/dist/utils/permissions.d.ts +43 -0
  57. package/dist/utils/permissions.js +178 -0
  58. package/dist/utils/post-process.d.ts +16 -0
  59. package/dist/utils/post-process.js +132 -0
  60. package/dist/utils/serialize-inspector-state.d.ts +179 -0
  61. package/dist/utils/serialize-inspector-state.js +170 -0
  62. package/dist/utils/type-utils.d.ts +3 -0
  63. package/dist/utils/type-utils.js +50 -0
  64. package/dist/visit.d.ts +3 -3
  65. package/dist/visit.js +35 -31
  66. package/package.json +5 -6
  67. package/src/{add-channel.ts → add/add-channel.ts} +108 -56
  68. package/src/add/add-cli.ts +822 -0
  69. package/src/{add-file-extends-core-type.ts → add/add-file-extends-core-type.ts} +23 -5
  70. package/src/{add-file-with-config.ts → add/add-file-with-config.ts} +2 -2
  71. package/src/{add-file-with-factory.ts → add/add-file-with-factory.ts} +49 -6
  72. package/src/{add-functions.ts → add/add-functions.ts} +89 -19
  73. package/src/{add-http-route.ts → add/add-http-route.ts} +66 -32
  74. package/src/add/add-mcp-prompt.ts +128 -0
  75. package/src/add/add-mcp-prompt.ts.tmp +0 -0
  76. package/src/add/add-mcp-resource.ts +145 -0
  77. package/src/add/add-mcp-resource.ts.tmp +0 -0
  78. package/src/add/add-mcp-tool.ts +137 -0
  79. package/src/add/add-middleware.ts +385 -0
  80. package/src/add/add-permission.ts +391 -0
  81. package/src/add/add-queue-worker.ts +92 -0
  82. package/src/{add-rpc-invocations.ts → add/add-rpc-invocations.ts} +1 -1
  83. package/src/{add-schedule.ts → add/add-schedule.ts} +30 -28
  84. package/src/error-codes.ts +43 -0
  85. package/src/index.ts +12 -0
  86. package/src/inspector.ts +41 -17
  87. package/src/types.ts +128 -1
  88. package/src/utils/ensure-function-metadata.ts +24 -0
  89. package/src/{utils.ts → utils/extract-function-name.ts} +44 -206
  90. package/src/utils/extract-services.ts +35 -0
  91. package/src/utils/filter-inspector-state.test.ts +1433 -0
  92. package/src/utils/filter-inspector-state.ts +526 -0
  93. package/src/{utils.test.ts → utils/filter-utils.test.ts} +351 -2
  94. package/src/utils/filter-utils.ts +152 -0
  95. package/src/utils/find-root-dir.ts +68 -0
  96. package/src/utils/get-files-and-methods.ts +151 -0
  97. package/src/{get-property-value.ts → utils/get-property-value.ts} +27 -0
  98. package/src/utils/middleware.ts +241 -0
  99. package/src/utils/permissions.test.ts +327 -0
  100. package/src/utils/permissions.ts +262 -0
  101. package/src/utils/post-process.ts +178 -0
  102. package/src/utils/serialize-inspector-state.ts +375 -0
  103. package/src/utils/test-data/inspector-state.json +1680 -0
  104. package/src/utils/type-utils.ts +74 -0
  105. package/src/visit.ts +50 -34
  106. package/tsconfig.tsbuildinfo +1 -1
  107. package/dist/add-channel.d.ts +0 -13
  108. package/dist/add-functions.d.ts +0 -7
  109. package/dist/add-mcp-prompt.d.ts +0 -3
  110. package/dist/add-mcp-prompt.js +0 -61
  111. package/dist/add-mcp-resource.d.ts +0 -3
  112. package/dist/add-mcp-resource.js +0 -68
  113. package/dist/add-mcp-tool.d.ts +0 -3
  114. package/dist/add-mcp-tool.js +0 -64
  115. package/dist/add-middleware.d.ts +0 -7
  116. package/dist/add-middleware.js +0 -35
  117. package/dist/add-permission.d.ts +0 -7
  118. package/dist/add-permission.js +0 -35
  119. package/dist/add-queue-worker.d.ts +0 -3
  120. package/dist/add-queue-worker.js +0 -48
  121. package/dist/add-schedule.d.ts +0 -3
  122. package/dist/get-property-value.d.ts +0 -3
  123. package/dist/utils.d.ts +0 -39
  124. package/src/add-mcp-prompt.ts +0 -104
  125. package/src/add-mcp-resource.ts +0 -116
  126. package/src/add-mcp-tool.ts +0 -107
  127. package/src/add-middleware.ts +0 -51
  128. package/src/add-permission.ts +0 -53
  129. package/src/add-queue-worker.ts +0 -92
  130. /package/dist/{add-rpc-invocations.js → add/add-rpc-invocations.js} +0 -0
  131. /package/dist/{does-type-extend-core-type.d.ts → utils/does-type-extend-core-type.d.ts} +0 -0
  132. /package/dist/{does-type-extend-core-type.js → utils/does-type-extend-core-type.js} +0 -0
  133. /package/src/{does-type-extend-core-type.ts → utils/does-type-extend-core-type.ts} +0 -0
@@ -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
- }
@@ -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
- }
@@ -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
- }