@pikku/inspector 0.11.1 → 0.12.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 +26 -1
- package/OPTIMIZATION-PLAN.md +195 -0
- package/dist/add/add-ai-agent.d.ts +2 -0
- package/dist/add/add-ai-agent.js +314 -0
- package/dist/add/add-channel.js +69 -61
- package/dist/add/add-cli.js +36 -18
- package/dist/add/add-file-with-factory.js +2 -0
- package/dist/add/add-functions.js +327 -59
- package/dist/add/add-http-route.d.ts +19 -10
- package/dist/add/add-http-route.js +153 -44
- package/dist/add/add-http-routes.d.ts +5 -0
- package/dist/add/add-http-routes.js +159 -0
- package/dist/add/add-keyed-wiring.d.ts +12 -0
- package/dist/add/add-keyed-wiring.js +97 -0
- package/dist/add/add-mcp-prompt.js +14 -9
- package/dist/add/add-mcp-resource.js +14 -9
- package/dist/add/add-middleware.d.ts +1 -4
- package/dist/add/add-middleware.js +364 -79
- package/dist/add/add-permission.d.ts +1 -1
- package/dist/add/add-permission.js +152 -40
- package/dist/add/add-queue-worker.js +18 -12
- package/dist/add/add-rpc-invocations.d.ts +3 -0
- package/dist/add/add-rpc-invocations.js +65 -25
- package/dist/add/add-schedule.js +11 -5
- package/dist/add/add-secret.d.ts +3 -0
- package/dist/add/add-secret.js +82 -0
- package/dist/add/add-trigger.d.ts +2 -0
- package/dist/add/add-trigger.js +87 -0
- package/dist/add/add-variable.d.ts +1 -0
- package/dist/add/add-variable.js +8 -0
- package/dist/add/add-workflow-graph.d.ts +7 -0
- package/dist/add/add-workflow-graph.js +396 -0
- package/dist/add/add-workflow.js +124 -26
- package/dist/error-codes.d.ts +16 -1
- package/dist/error-codes.js +21 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.js +5 -2
- package/dist/inspector.d.ts +1 -1
- package/dist/inspector.js +106 -13
- package/dist/schema-generator.d.ts +1 -0
- package/dist/schema-generator.js +1 -0
- package/dist/types-map.js +10 -1
- package/dist/types.d.ts +180 -30
- package/dist/utils/compute-required-schemas.d.ts +4 -0
- package/dist/utils/compute-required-schemas.js +41 -0
- package/dist/utils/contract-hashes.d.ts +35 -0
- package/dist/utils/contract-hashes.js +202 -0
- package/dist/utils/custom-types-generator.d.ts +9 -0
- package/dist/utils/custom-types-generator.js +71 -0
- package/dist/utils/detect-schema-vendor.d.ts +22 -0
- package/dist/utils/detect-schema-vendor.js +76 -0
- package/dist/utils/ensure-function-metadata.d.ts +5 -2
- package/dist/utils/ensure-function-metadata.js +220 -6
- package/dist/utils/extract-function-name.d.ts +5 -16
- package/dist/utils/extract-function-name.js +93 -298
- package/dist/utils/extract-services.d.ts +2 -1
- package/dist/utils/extract-services.js +25 -1
- package/dist/utils/filter-inspector-state.js +107 -23
- package/dist/utils/get-property-value.d.ts +8 -2
- package/dist/utils/get-property-value.js +33 -4
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +23 -0
- package/dist/utils/middleware.d.ts +7 -30
- package/dist/utils/middleware.js +80 -66
- package/dist/utils/permissions.d.ts +2 -2
- package/dist/utils/permissions.js +10 -10
- package/dist/utils/post-process.d.ts +9 -10
- package/dist/utils/post-process.js +231 -24
- package/dist/utils/resolve-external-package.d.ts +12 -0
- package/dist/utils/resolve-external-package.js +34 -0
- package/dist/utils/resolve-function-types.d.ts +6 -0
- package/dist/utils/resolve-function-types.js +29 -0
- package/dist/utils/resolve-identifier.d.ts +10 -0
- package/dist/utils/resolve-identifier.js +36 -0
- package/dist/utils/resolve-versions.d.ts +2 -0
- package/dist/utils/resolve-versions.js +78 -0
- package/dist/utils/schema-generator.d.ts +9 -0
- package/dist/utils/schema-generator.js +209 -0
- package/dist/utils/serialize-inspector-state.d.ts +73 -13
- package/dist/utils/serialize-inspector-state.js +102 -6
- package/dist/utils/serialize-mcp-json.d.ts +2 -0
- package/dist/utils/serialize-mcp-json.js +99 -0
- package/dist/utils/serialize-middleware-groups-meta.d.ts +12 -0
- package/dist/utils/serialize-middleware-groups-meta.js +28 -0
- package/dist/utils/serialize-openapi-json.d.ts +85 -0
- package/dist/utils/serialize-openapi-json.js +151 -0
- package/dist/utils/serialize-permissions-groups-meta.d.ts +6 -0
- package/dist/utils/serialize-permissions-groups-meta.js +31 -0
- package/dist/utils/workflow/dsl/deserialize-dsl-workflow.d.ts +24 -0
- package/dist/utils/workflow/dsl/deserialize-dsl-workflow.js +830 -0
- package/dist/{workflow/extract-simple-workflow.d.ts → utils/workflow/dsl/extract-dsl-workflow.d.ts} +4 -2
- package/dist/{workflow/extract-simple-workflow.js → utils/workflow/dsl/extract-dsl-workflow.js} +572 -72
- package/dist/utils/workflow/dsl/index.d.ts +7 -0
- package/dist/utils/workflow/dsl/index.js +7 -0
- package/dist/{workflow → utils/workflow/dsl}/patterns.d.ts +21 -0
- package/dist/{workflow → utils/workflow/dsl}/patterns.js +90 -10
- package/dist/{workflow → utils/workflow/dsl}/validation.d.ts +2 -0
- package/dist/{workflow → utils/workflow/dsl}/validation.js +25 -7
- package/dist/utils/workflow/graph/convert-dsl-to-graph.d.ts +13 -0
- package/dist/utils/workflow/graph/convert-dsl-to-graph.js +318 -0
- package/dist/utils/workflow/graph/finalize-workflow-wires.d.ts +3 -0
- package/dist/utils/workflow/graph/finalize-workflow-wires.js +276 -0
- package/dist/utils/workflow/graph/finalize-workflows.d.ts +2 -0
- package/dist/utils/workflow/graph/finalize-workflows.js +75 -0
- package/dist/utils/workflow/graph/index.d.ts +8 -0
- package/dist/utils/workflow/graph/index.js +8 -0
- package/dist/utils/workflow/graph/serialize-workflow-graph.d.ts +35 -0
- package/dist/utils/workflow/graph/serialize-workflow-graph.js +150 -0
- package/dist/utils/workflow/graph/workflow-graph.types.d.ts +203 -0
- package/dist/utils/workflow/graph/workflow-graph.types.js +38 -0
- package/dist/visit.js +13 -2
- package/package.json +26 -4
- package/src/add/add-ai-agent.ts +468 -0
- package/src/add/add-channel.ts +82 -79
- package/src/add/add-cli.ts +49 -20
- package/src/add/add-file-with-factory.ts +2 -0
- package/src/add/add-functions.ts +429 -71
- package/src/add/add-http-route.ts +246 -65
- package/src/add/add-http-routes.ts +228 -0
- package/src/add/add-keyed-wiring.ts +151 -0
- package/src/add/add-mcp-prompt.ts +26 -15
- package/src/add/add-mcp-resource.ts +27 -15
- package/src/add/add-middleware.ts +482 -80
- package/src/add/add-permission.ts +199 -40
- package/src/add/add-queue-worker.ts +24 -19
- package/src/add/add-rpc-invocations.ts +78 -31
- package/src/add/add-schedule.ts +16 -11
- package/src/add/add-secret.ts +140 -0
- package/src/add/add-trigger.ts +154 -0
- package/src/add/add-variable.ts +9 -0
- package/src/add/add-workflow-graph.ts +522 -0
- package/src/add/add-workflow.ts +117 -30
- package/src/error-codes.ts +26 -1
- package/src/index.ts +27 -8
- package/src/inspector.ts +145 -17
- package/src/schema-generator.ts +1 -0
- package/src/types-map.ts +12 -1
- package/src/types.ts +192 -51
- package/src/utils/compute-required-schemas.ts +49 -0
- package/src/utils/contract-hashes.test.ts +528 -0
- package/src/utils/contract-hashes.ts +290 -0
- package/src/utils/custom-types-generator.ts +88 -0
- package/src/utils/detect-schema-vendor.ts +90 -0
- package/src/utils/ensure-function-metadata.ts +324 -7
- package/src/utils/extract-function-name.ts +108 -358
- package/src/utils/extract-services.ts +35 -2
- package/src/utils/filter-inspector-state.test.ts +34 -20
- package/src/utils/filter-inspector-state.ts +140 -31
- package/src/utils/get-property-value.ts +50 -5
- package/src/utils/hash.ts +26 -0
- package/src/utils/middleware.test.ts +204 -0
- package/src/utils/middleware.ts +129 -67
- package/src/utils/permissions.test.ts +35 -12
- package/src/utils/permissions.ts +10 -10
- package/src/utils/post-process.ts +283 -43
- package/src/utils/resolve-external-package.ts +42 -0
- package/src/utils/resolve-function-types.ts +42 -0
- package/src/utils/resolve-identifier.ts +46 -0
- package/src/utils/resolve-versions.test.ts +249 -0
- package/src/utils/resolve-versions.ts +105 -0
- package/src/utils/schema-generator.ts +329 -0
- package/src/utils/serialize-inspector-state.ts +181 -20
- package/src/utils/serialize-mcp-json.ts +145 -0
- package/src/utils/serialize-middleware-groups-meta.ts +33 -0
- package/src/utils/serialize-openapi-json.ts +277 -0
- package/src/utils/serialize-permissions-groups-meta.ts +35 -0
- package/src/utils/test-data/inspector-state.json +69 -66
- package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +1104 -0
- package/src/{workflow/extract-simple-workflow.ts → utils/workflow/dsl/extract-dsl-workflow.ts} +678 -85
- package/src/utils/workflow/dsl/index.ts +11 -0
- package/src/{workflow → utils/workflow/dsl}/patterns.ts +108 -11
- package/src/{workflow → utils/workflow/dsl}/validation.ts +34 -7
- package/src/utils/workflow/graph/convert-dsl-to-graph.ts +422 -0
- package/src/utils/workflow/graph/finalize-workflow-wires.ts +310 -0
- package/src/utils/workflow/graph/finalize-workflows.ts +100 -0
- package/src/utils/workflow/graph/index.ts +11 -0
- package/src/utils/workflow/graph/serialize-workflow-graph.ts +216 -0
- package/src/utils/workflow/graph/workflow-graph.types.ts +231 -0
- package/src/visit.ts +14 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/add/add-mcp-tool.d.ts +0 -2
- package/dist/add/add-mcp-tool.js +0 -81
- package/dist/utils/extract-service-metadata.d.ts +0 -19
- package/dist/utils/extract-service-metadata.js +0 -244
- package/dist/utils/write-service-metadata.d.ts +0 -13
- package/dist/utils/write-service-metadata.js +0 -37
- package/src/add/add-mcp-tool.ts +0 -141
- package/src/utils/extract-service-metadata.ts +0 -353
- package/src/utils/write-service-metadata.ts +0 -51
|
@@ -1,18 +1,254 @@
|
|
|
1
|
+
import * as ts from 'typescript'
|
|
1
2
|
import { InspectorState } from '../types.js'
|
|
3
|
+
import { funcIdToTypeName } from './extract-function-name.js'
|
|
4
|
+
import { getCommonWireMetaData } from './get-property-value.js'
|
|
5
|
+
import { resolveMiddleware } from './middleware.js'
|
|
6
|
+
import { resolvePermissions } from './permissions.js'
|
|
7
|
+
|
|
8
|
+
function isVoidLike(type: ts.Type): boolean {
|
|
9
|
+
return !!(
|
|
10
|
+
type.flags &
|
|
11
|
+
(ts.TypeFlags.Void | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike)
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isPromiseOfVoid(checker: ts.TypeChecker, type: ts.Type): boolean {
|
|
16
|
+
if (!type?.symbol) return false
|
|
17
|
+
const isPromise =
|
|
18
|
+
type.symbol.name === 'Promise' &&
|
|
19
|
+
checker.getFullyQualifiedName(type.symbol).includes('Promise')
|
|
20
|
+
if (!isPromise) return false
|
|
21
|
+
const inner =
|
|
22
|
+
type.aliasTypeArguments?.[0] ??
|
|
23
|
+
(type as ts.TypeReference).typeArguments?.[0]
|
|
24
|
+
return !!inner && isVoidLike(inner)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function unwrapPromise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
|
|
28
|
+
if (type.isUnion()) {
|
|
29
|
+
const nonVoid = type.types.filter(
|
|
30
|
+
(t) => !isVoidLike(t) && !isPromiseOfVoid(checker, t)
|
|
31
|
+
)
|
|
32
|
+
if (nonVoid.length === 1) {
|
|
33
|
+
return unwrapPromise(checker, nonVoid[0]!)
|
|
34
|
+
}
|
|
35
|
+
if (nonVoid.length > 1) {
|
|
36
|
+
return unwrapPromise(checker, nonVoid[0]!)
|
|
37
|
+
}
|
|
38
|
+
return type
|
|
39
|
+
}
|
|
40
|
+
if (!type?.symbol) return type
|
|
41
|
+
const isPromise =
|
|
42
|
+
type.symbol.name === 'Promise' &&
|
|
43
|
+
checker.getFullyQualifiedName(type.symbol).includes('Promise')
|
|
44
|
+
if (isPromise && type.aliasTypeArguments?.length === 1) {
|
|
45
|
+
return type.aliasTypeArguments[0]!
|
|
46
|
+
}
|
|
47
|
+
if (isPromise && (type as ts.TypeReference).typeArguments?.length === 1) {
|
|
48
|
+
return (type as ts.TypeReference).typeArguments![0]!
|
|
49
|
+
}
|
|
50
|
+
return type
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function resolveTypeName(
|
|
54
|
+
checker: ts.TypeChecker,
|
|
55
|
+
type: ts.Type,
|
|
56
|
+
state: InspectorState,
|
|
57
|
+
funcName: string,
|
|
58
|
+
direction: 'Input' | 'Output'
|
|
59
|
+
): string | null {
|
|
60
|
+
if (type.flags & (ts.TypeFlags.VoidLike | ts.TypeFlags.Null)) return null
|
|
61
|
+
|
|
62
|
+
const typeStr = checker.typeToString(
|
|
63
|
+
type,
|
|
64
|
+
undefined,
|
|
65
|
+
ts.TypeFormatFlags.NoTruncation
|
|
66
|
+
)
|
|
67
|
+
if (
|
|
68
|
+
!typeStr ||
|
|
69
|
+
typeStr === 'void' ||
|
|
70
|
+
typeStr === 'undefined' ||
|
|
71
|
+
typeStr === 'null'
|
|
72
|
+
)
|
|
73
|
+
return null
|
|
74
|
+
|
|
75
|
+
const isSimpleName = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(typeStr)
|
|
76
|
+
if (isSimpleName) {
|
|
77
|
+
const symbol = type.aliasSymbol || type.getSymbol()
|
|
78
|
+
if (symbol) {
|
|
79
|
+
const decl = symbol.getDeclarations()?.[0]
|
|
80
|
+
if (decl) {
|
|
81
|
+
const path = decl.getSourceFile().fileName
|
|
82
|
+
if (!state.functions.typesMap.exists(typeStr, path)) {
|
|
83
|
+
state.functions.typesMap.addType(typeStr, path)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return typeStr
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const aliasName = funcIdToTypeName(funcName) + direction
|
|
91
|
+
state.functions.typesMap.addCustomType(aliasName, typeStr, [])
|
|
92
|
+
return aliasName
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function getFirstCallSignature(type: ts.Type): ts.Signature | undefined {
|
|
96
|
+
const sigs = type.getCallSignatures()
|
|
97
|
+
if (sigs.length > 0) return sigs[0]
|
|
98
|
+
if (type.isUnion()) {
|
|
99
|
+
for (const member of type.types) {
|
|
100
|
+
const memberSigs = member.getCallSignatures()
|
|
101
|
+
if (memberSigs.length > 0) return memberSigs[0]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return undefined
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function resolveFromConfigTypeArgs(
|
|
108
|
+
state: InspectorState,
|
|
109
|
+
pikkuFuncId: string,
|
|
110
|
+
configType: ts.Type,
|
|
111
|
+
checker: ts.TypeChecker,
|
|
112
|
+
meta: NonNullable<InspectorState['functions']['meta'][string]>
|
|
113
|
+
): void {
|
|
114
|
+
const typeArgs =
|
|
115
|
+
configType.aliasTypeArguments ??
|
|
116
|
+
(configType as ts.TypeReference).typeArguments
|
|
117
|
+
if (!typeArgs || typeArgs.length < 2) return
|
|
118
|
+
|
|
119
|
+
const inputType = typeArgs[0]!
|
|
120
|
+
const outputType = typeArgs[1]!
|
|
121
|
+
|
|
122
|
+
if (!meta.inputs || meta.inputs.length === 0) {
|
|
123
|
+
const inputName = resolveTypeName(
|
|
124
|
+
checker,
|
|
125
|
+
inputType,
|
|
126
|
+
state,
|
|
127
|
+
pikkuFuncId,
|
|
128
|
+
'Input'
|
|
129
|
+
)
|
|
130
|
+
if (inputName) {
|
|
131
|
+
meta.inputs = [inputName]
|
|
132
|
+
meta.inputSchemaName = inputName
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (!meta.outputs || meta.outputs.length === 0) {
|
|
137
|
+
const resolvedOutput = unwrapPromise(checker, outputType)
|
|
138
|
+
const outputName = resolveTypeName(
|
|
139
|
+
checker,
|
|
140
|
+
resolvedOutput,
|
|
141
|
+
state,
|
|
142
|
+
pikkuFuncId,
|
|
143
|
+
'Output'
|
|
144
|
+
)
|
|
145
|
+
if (outputName) {
|
|
146
|
+
meta.outputs = [outputName]
|
|
147
|
+
meta.outputSchemaName = outputName
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function resolveFuncConfigTypes(
|
|
153
|
+
state: InspectorState,
|
|
154
|
+
pikkuFuncId: string,
|
|
155
|
+
funcInitializer: ts.Node,
|
|
156
|
+
checker: ts.TypeChecker
|
|
157
|
+
): void {
|
|
158
|
+
const meta = state.functions.meta[pikkuFuncId]
|
|
159
|
+
if (!meta || (meta.inputs && meta.inputs.length > 0)) return
|
|
160
|
+
|
|
161
|
+
const configType = checker.getTypeAtLocation(funcInitializer)
|
|
162
|
+
const funcProp = configType.getProperty('func')
|
|
163
|
+
if (!funcProp) return
|
|
164
|
+
|
|
165
|
+
const funcType = checker.getTypeOfSymbolAtLocation(funcProp, funcInitializer)
|
|
166
|
+
const sig = getFirstCallSignature(funcType)
|
|
167
|
+
if (!sig) return
|
|
168
|
+
const params = sig.getParameters()
|
|
169
|
+
if (params.length >= 2) {
|
|
170
|
+
const inputType = checker.getTypeOfSymbolAtLocation(
|
|
171
|
+
params[1]!,
|
|
172
|
+
funcInitializer
|
|
173
|
+
)
|
|
174
|
+
const inputName = resolveTypeName(
|
|
175
|
+
checker,
|
|
176
|
+
inputType,
|
|
177
|
+
state,
|
|
178
|
+
pikkuFuncId,
|
|
179
|
+
'Input'
|
|
180
|
+
)
|
|
181
|
+
if (inputName) {
|
|
182
|
+
meta.inputs = [inputName]
|
|
183
|
+
meta.inputSchemaName = inputName
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const rawReturnType = checker.getReturnTypeOfSignature(sig)
|
|
188
|
+
const outputType = unwrapPromise(checker, rawReturnType)
|
|
189
|
+
const outputName = resolveTypeName(
|
|
190
|
+
checker,
|
|
191
|
+
outputType,
|
|
192
|
+
state,
|
|
193
|
+
pikkuFuncId,
|
|
194
|
+
'Output'
|
|
195
|
+
)
|
|
196
|
+
if (outputName) {
|
|
197
|
+
meta.outputs = [outputName]
|
|
198
|
+
meta.outputSchemaName = outputName
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
resolveFromConfigTypeArgs(state, pikkuFuncId, configType, checker, meta)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function resolveToPikkuFuncCall(
|
|
205
|
+
node: ts.Node,
|
|
206
|
+
checker: ts.TypeChecker
|
|
207
|
+
): ts.CallExpression | null {
|
|
208
|
+
if (
|
|
209
|
+
ts.isCallExpression(node) &&
|
|
210
|
+
ts.isIdentifier(node.expression) &&
|
|
211
|
+
node.expression.text.startsWith('pikku')
|
|
212
|
+
) {
|
|
213
|
+
return node
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (ts.isIdentifier(node)) {
|
|
217
|
+
const sym = checker.getSymbolAtLocation(node)
|
|
218
|
+
if (sym) {
|
|
219
|
+
let resolved = sym
|
|
220
|
+
if (resolved.flags & ts.SymbolFlags.Alias) {
|
|
221
|
+
resolved = checker.getAliasedSymbol(resolved) ?? resolved
|
|
222
|
+
}
|
|
223
|
+
const decl = resolved.declarations?.[0]
|
|
224
|
+
if (decl && ts.isVariableDeclaration(decl) && decl.initializer) {
|
|
225
|
+
return resolveToPikkuFuncCall(decl.initializer, checker)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return null
|
|
231
|
+
}
|
|
2
232
|
|
|
3
233
|
/**
|
|
4
|
-
* Ensures that function metadata exists for a given
|
|
234
|
+
* Ensures that function metadata exists for a given pikkuFuncId.
|
|
5
235
|
* Creates stub metadata if it doesn't exist (useful for inline functions).
|
|
236
|
+
* When funcInitializer and checker are provided, resolves types and
|
|
237
|
+
* extracts tags/middleware/permissions from the pikkuFunc() config.
|
|
6
238
|
*/
|
|
7
239
|
export function ensureFunctionMetadata(
|
|
8
240
|
state: InspectorState,
|
|
9
|
-
|
|
10
|
-
fallbackName?: string
|
|
241
|
+
pikkuFuncId: string,
|
|
242
|
+
fallbackName?: string,
|
|
243
|
+
funcInitializer?: ts.Node,
|
|
244
|
+
checker?: ts.TypeChecker,
|
|
245
|
+
isHelper?: boolean
|
|
11
246
|
): void {
|
|
12
|
-
if (!state.functions.meta[
|
|
13
|
-
state.functions.meta[
|
|
14
|
-
|
|
15
|
-
|
|
247
|
+
if (!state.functions.meta[pikkuFuncId]) {
|
|
248
|
+
state.functions.meta[pikkuFuncId] = {
|
|
249
|
+
pikkuFuncId,
|
|
250
|
+
functionType: isHelper ? 'helper' : 'inline',
|
|
251
|
+
name: fallbackName || pikkuFuncId,
|
|
16
252
|
services: { optimized: false, services: [] },
|
|
17
253
|
inputSchemaName: null,
|
|
18
254
|
outputSchemaName: null,
|
|
@@ -21,4 +257,85 @@ export function ensureFunctionMetadata(
|
|
|
21
257
|
middleware: undefined,
|
|
22
258
|
}
|
|
23
259
|
}
|
|
260
|
+
|
|
261
|
+
const meta = state.functions.meta[pikkuFuncId]!
|
|
262
|
+
|
|
263
|
+
if (funcInitializer && checker) {
|
|
264
|
+
let pikkuFuncCall: ts.CallExpression | null = null
|
|
265
|
+
|
|
266
|
+
if (ts.isCallExpression(funcInitializer)) {
|
|
267
|
+
pikkuFuncCall = funcInitializer
|
|
268
|
+
resolveFuncConfigTypes(state, pikkuFuncId, pikkuFuncCall, checker)
|
|
269
|
+
if (!state.typesLookup.has(pikkuFuncId)) {
|
|
270
|
+
populateTypesLookup(state, pikkuFuncId, pikkuFuncCall, checker)
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
pikkuFuncCall = resolveToPikkuFuncCall(funcInitializer, checker)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (pikkuFuncCall) {
|
|
277
|
+
const firstArg = pikkuFuncCall.arguments[0]
|
|
278
|
+
if (firstArg && ts.isObjectLiteralExpression(firstArg)) {
|
|
279
|
+
if (!meta.tags) {
|
|
280
|
+
const { tags } = getCommonWireMetaData(
|
|
281
|
+
firstArg,
|
|
282
|
+
'Function',
|
|
283
|
+
fallbackName || pikkuFuncId
|
|
284
|
+
)
|
|
285
|
+
if (tags) {
|
|
286
|
+
meta.tags = tags
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (!meta.middleware) {
|
|
290
|
+
meta.middleware = resolveMiddleware(
|
|
291
|
+
state,
|
|
292
|
+
firstArg,
|
|
293
|
+
meta.tags,
|
|
294
|
+
checker
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
if (!meta.permissions) {
|
|
298
|
+
meta.permissions = resolvePermissions(
|
|
299
|
+
state,
|
|
300
|
+
firstArg,
|
|
301
|
+
meta.tags,
|
|
302
|
+
checker
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function populateTypesLookup(
|
|
311
|
+
state: InspectorState,
|
|
312
|
+
pikkuFuncId: string,
|
|
313
|
+
funcInitializer: ts.CallExpression,
|
|
314
|
+
checker: ts.TypeChecker
|
|
315
|
+
): void {
|
|
316
|
+
const typeArgs = funcInitializer.typeArguments
|
|
317
|
+
if (typeArgs && typeArgs.length >= 1) {
|
|
318
|
+
const inputType = checker.getTypeFromTypeNode(typeArgs[0]!)
|
|
319
|
+
state.typesLookup.set(pikkuFuncId, [inputType])
|
|
320
|
+
return
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const configType = checker.getTypeAtLocation(funcInitializer)
|
|
324
|
+
const funcProp = configType.getProperty('func')
|
|
325
|
+
if (!funcProp) return
|
|
326
|
+
|
|
327
|
+
const funcType = checker.getTypeOfSymbolAtLocation(funcProp, funcInitializer)
|
|
328
|
+
const sig = getFirstCallSignature(funcType)
|
|
329
|
+
if (!sig) return
|
|
330
|
+
|
|
331
|
+
const params = sig.getParameters()
|
|
332
|
+
if (params.length >= 2) {
|
|
333
|
+
const inputType = checker.getTypeOfSymbolAtLocation(
|
|
334
|
+
params[1]!,
|
|
335
|
+
funcInitializer
|
|
336
|
+
)
|
|
337
|
+
if (!(inputType.flags & ts.TypeFlags.VoidLike)) {
|
|
338
|
+
state.typesLookup.set(pikkuFuncId, [inputType])
|
|
339
|
+
}
|
|
340
|
+
}
|
|
24
341
|
}
|