@pikku/inspector 0.11.2 → 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 +11 -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 +250 -75
- package/dist/add/add-http-route.d.ts +19 -10
- package/dist/add/add-http-route.js +152 -66
- 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.js +14 -0
- 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 +3 -2
- package/dist/add/add-workflow-graph.js +143 -406
- package/dist/add/add-workflow.js +6 -4
- package/dist/error-codes.d.ts +14 -1
- package/dist/error-codes.js +19 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.js +5 -4
- package/dist/inspector.d.ts +1 -1
- package/dist/inspector.js +91 -14
- 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 +163 -39
- 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 +86 -291
- 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 +6 -1
- package/dist/utils/get-property-value.js +28 -3
- 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 +59 -22
- package/dist/utils/serialize-inspector-state.js +92 -20
- 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.js +34 -102
- package/dist/utils/workflow/dsl/extract-dsl-workflow.js +23 -4
- package/dist/utils/workflow/graph/convert-dsl-to-graph.js +12 -10
- 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 +2 -0
- package/dist/utils/workflow/graph/index.js +2 -0
- package/dist/utils/workflow/graph/serialize-workflow-graph.d.ts +0 -8
- package/dist/utils/workflow/graph/serialize-workflow-graph.js +1 -3
- package/dist/utils/workflow/graph/workflow-graph.types.d.ts +53 -79
- package/dist/utils/workflow/graph/workflow-graph.types.js +1 -1
- package/dist/visit.js +11 -6
- package/package.json +14 -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 +330 -86
- package/src/add/add-http-route.ts +245 -88
- 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 +17 -0
- 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 +180 -522
- package/src/add/add-workflow.ts +5 -4
- package/src/error-codes.ts +24 -1
- package/src/index.ts +22 -13
- package/src/inspector.ts +129 -17
- package/src/schema-generator.ts +1 -0
- package/src/types-map.ts +12 -1
- package/src/types.ts +175 -58
- 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 +101 -351
- 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 +42 -4
- 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 +163 -40
- 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 +43 -119
- package/src/utils/workflow/dsl/extract-dsl-workflow.ts +24 -4
- package/src/utils/workflow/graph/convert-dsl-to-graph.ts +17 -10
- 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 +5 -0
- package/src/utils/workflow/graph/serialize-workflow-graph.ts +1 -8
- package/src/utils/workflow/graph/workflow-graph.types.ts +29 -78
- package/src/visit.ts +12 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/add/add-forge-credential.d.ts +0 -8
- package/dist/add/add-forge-credential.js +0 -77
- package/dist/add/add-forge-node.d.ts +0 -7
- package/dist/add/add-forge-node.js +0 -77
- 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-forge-credential.ts +0 -119
- package/src/add/add-forge-node.ts +0 -132
- 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
package/src/add/add-channel.ts
CHANGED
|
@@ -5,12 +5,19 @@ import {
|
|
|
5
5
|
getCommonWireMetaData,
|
|
6
6
|
} from '../utils/get-property-value.js'
|
|
7
7
|
import { pathToRegexp } from 'path-to-regexp'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
extractFunctionName,
|
|
10
|
+
makeContextBasedId,
|
|
11
|
+
} from '../utils/extract-function-name.js'
|
|
9
12
|
import { getPropertyAssignmentInitializer } from '../utils/type-utils.js'
|
|
10
13
|
import type { ChannelMessageMeta, ChannelMeta } from '@pikku/core/channel'
|
|
11
14
|
import type { InspectorState, AddWiring } from '../types.js'
|
|
12
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
resolveMiddleware,
|
|
17
|
+
resolveChannelMiddleware,
|
|
18
|
+
} from '../utils/middleware.js'
|
|
13
19
|
import { extractWireNames } from '../utils/post-process.js'
|
|
20
|
+
import { resolveIdentifier } from '../utils/resolve-identifier.js'
|
|
14
21
|
|
|
15
22
|
/**
|
|
16
23
|
* Safely get the "initializer" expression of a property-like AST node:
|
|
@@ -61,31 +68,31 @@ function getHandlerNameFromExpression(
|
|
|
61
68
|
ts.isFunctionExpression(decl.initializer)
|
|
62
69
|
) {
|
|
63
70
|
// Extract function name from the declaration's initializer
|
|
64
|
-
const {
|
|
71
|
+
const { pikkuFuncId } = extractFunctionName(
|
|
65
72
|
decl.initializer,
|
|
66
73
|
checker,
|
|
67
74
|
rootDir
|
|
68
75
|
)
|
|
69
|
-
return
|
|
76
|
+
return pikkuFuncId
|
|
70
77
|
}
|
|
71
78
|
}
|
|
72
79
|
// For function declarations, use directly
|
|
73
80
|
else if (ts.isFunctionDeclaration(decl)) {
|
|
74
|
-
const {
|
|
75
|
-
return
|
|
81
|
+
const { pikkuFuncId } = extractFunctionName(decl, checker, rootDir)
|
|
82
|
+
return pikkuFuncId
|
|
76
83
|
}
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
86
|
|
|
80
87
|
// Fallback: try to extract directly from the identifier
|
|
81
|
-
const {
|
|
82
|
-
return
|
|
88
|
+
const { pikkuFuncId } = extractFunctionName(expr, checker, rootDir)
|
|
89
|
+
return pikkuFuncId
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
// Handle call expressions
|
|
86
93
|
if (ts.isCallExpression(expr)) {
|
|
87
|
-
const {
|
|
88
|
-
return
|
|
94
|
+
const { pikkuFuncId } = extractFunctionName(expr, checker, rootDir)
|
|
95
|
+
return pikkuFuncId
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
// Handle object literals with 'func' property
|
|
@@ -125,8 +132,20 @@ export function addMessagesRoutes(
|
|
|
125
132
|
return result
|
|
126
133
|
|
|
127
134
|
for (const chanElem of onMsgRouteProp.properties) {
|
|
128
|
-
|
|
129
|
-
if (!chanInit
|
|
135
|
+
let chanInit = getInitializerOf(chanElem)
|
|
136
|
+
if (!chanInit) continue
|
|
137
|
+
|
|
138
|
+
// If the value is an identifier, resolve it (handles defineChannelRoutes)
|
|
139
|
+
if (ts.isIdentifier(chanInit)) {
|
|
140
|
+
const resolved = resolveIdentifier(chanInit, checker, [
|
|
141
|
+
'defineChannelRoutes',
|
|
142
|
+
])
|
|
143
|
+
if (resolved && ts.isObjectLiteralExpression(resolved)) {
|
|
144
|
+
chanInit = resolved
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!ts.isObjectLiteralExpression(chanInit)) continue
|
|
130
149
|
|
|
131
150
|
const channelKey = chanElem.name!.getText()
|
|
132
151
|
result[channelKey] = {}
|
|
@@ -193,12 +212,12 @@ export function addMessagesRoutes(
|
|
|
193
212
|
ts.isFunctionExpression(importDecl.initializer) ||
|
|
194
213
|
ts.isCallExpression(importDecl.initializer)
|
|
195
214
|
) {
|
|
196
|
-
const {
|
|
215
|
+
const { pikkuFuncId } = extractFunctionName(
|
|
197
216
|
importDecl.initializer,
|
|
198
217
|
checker,
|
|
199
218
|
state.rootDir
|
|
200
219
|
)
|
|
201
|
-
const handlerName =
|
|
220
|
+
const handlerName = pikkuFuncId
|
|
202
221
|
|
|
203
222
|
// Look up in the registry
|
|
204
223
|
const fnMeta = state.functions.meta[handlerName]
|
|
@@ -217,7 +236,7 @@ export function addMessagesRoutes(
|
|
|
217
236
|
: undefined
|
|
218
237
|
|
|
219
238
|
result[channelKey]![routeKey] = {
|
|
220
|
-
|
|
239
|
+
pikkuFuncId: handlerName,
|
|
221
240
|
middleware: routeMiddleware,
|
|
222
241
|
}
|
|
223
242
|
continue
|
|
@@ -225,12 +244,12 @@ export function addMessagesRoutes(
|
|
|
225
244
|
}
|
|
226
245
|
} else if (ts.isFunctionDeclaration(importDecl)) {
|
|
227
246
|
// Extract from the function declaration
|
|
228
|
-
const {
|
|
247
|
+
const { pikkuFuncId } = extractFunctionName(
|
|
229
248
|
importDecl,
|
|
230
249
|
checker,
|
|
231
250
|
state.rootDir
|
|
232
251
|
)
|
|
233
|
-
const handlerName =
|
|
252
|
+
const handlerName = pikkuFuncId
|
|
234
253
|
|
|
235
254
|
// Look up in the registry
|
|
236
255
|
const fnMeta = state.functions.meta[handlerName]
|
|
@@ -249,7 +268,7 @@ export function addMessagesRoutes(
|
|
|
249
268
|
: undefined
|
|
250
269
|
|
|
251
270
|
result[channelKey]![routeKey] = {
|
|
252
|
-
|
|
271
|
+
pikkuFuncId: handlerName,
|
|
253
272
|
middleware: routeMiddleware,
|
|
254
273
|
}
|
|
255
274
|
continue
|
|
@@ -275,12 +294,12 @@ export function addMessagesRoutes(
|
|
|
275
294
|
ts.isVariableDeclaration(exportDecl) &&
|
|
276
295
|
exportDecl.initializer
|
|
277
296
|
) {
|
|
278
|
-
const {
|
|
297
|
+
const { pikkuFuncId } = extractFunctionName(
|
|
279
298
|
exportDecl.initializer,
|
|
280
299
|
checker,
|
|
281
300
|
state.rootDir
|
|
282
301
|
)
|
|
283
|
-
const handlerName =
|
|
302
|
+
const handlerName = pikkuFuncId
|
|
284
303
|
|
|
285
304
|
const fnMeta = state.functions.meta[handlerName]
|
|
286
305
|
if (fnMeta) {
|
|
@@ -300,18 +319,18 @@ export function addMessagesRoutes(
|
|
|
300
319
|
: undefined
|
|
301
320
|
|
|
302
321
|
result[channelKey]![routeKey] = {
|
|
303
|
-
|
|
322
|
+
pikkuFuncId: handlerName,
|
|
304
323
|
middleware: routeMiddleware,
|
|
305
324
|
}
|
|
306
325
|
continue
|
|
307
326
|
}
|
|
308
327
|
} else if (ts.isFunctionDeclaration(exportDecl)) {
|
|
309
|
-
const {
|
|
328
|
+
const { pikkuFuncId } = extractFunctionName(
|
|
310
329
|
exportDecl,
|
|
311
330
|
checker,
|
|
312
331
|
state.rootDir
|
|
313
332
|
)
|
|
314
|
-
const handlerName =
|
|
333
|
+
const handlerName = pikkuFuncId
|
|
315
334
|
|
|
316
335
|
const fnMeta = state.functions.meta[handlerName]
|
|
317
336
|
if (fnMeta) {
|
|
@@ -331,7 +350,7 @@ export function addMessagesRoutes(
|
|
|
331
350
|
: undefined
|
|
332
351
|
|
|
333
352
|
result[channelKey]![routeKey] = {
|
|
334
|
-
|
|
353
|
+
pikkuFuncId: handlerName,
|
|
335
354
|
middleware: routeMiddleware,
|
|
336
355
|
}
|
|
337
356
|
continue
|
|
@@ -365,7 +384,7 @@ export function addMessagesRoutes(
|
|
|
365
384
|
continue
|
|
366
385
|
}
|
|
367
386
|
result[channelKey]![routeKey] = {
|
|
368
|
-
|
|
387
|
+
pikkuFuncId: possibleMatch,
|
|
369
388
|
}
|
|
370
389
|
continue
|
|
371
390
|
}
|
|
@@ -392,12 +411,12 @@ export function addMessagesRoutes(
|
|
|
392
411
|
// If we found the actual function, extract its name
|
|
393
412
|
if (actualFunction) {
|
|
394
413
|
// Extract the function name directly from the actual function
|
|
395
|
-
const {
|
|
414
|
+
const { pikkuFuncId } = extractFunctionName(
|
|
396
415
|
actualFunction,
|
|
397
416
|
checker,
|
|
398
417
|
state.rootDir
|
|
399
418
|
)
|
|
400
|
-
const handlerName =
|
|
419
|
+
const handlerName = pikkuFuncId
|
|
401
420
|
|
|
402
421
|
// Now use this handlerName to look up in the registry
|
|
403
422
|
const fnMeta = state.functions.meta[handlerName]
|
|
@@ -417,7 +436,7 @@ export function addMessagesRoutes(
|
|
|
417
436
|
: undefined
|
|
418
437
|
|
|
419
438
|
result[channelKey]![routeKey] = {
|
|
420
|
-
|
|
439
|
+
pikkuFuncId: handlerName,
|
|
421
440
|
middleware: routeMiddleware,
|
|
422
441
|
}
|
|
423
442
|
continue // Skip the normal processing below
|
|
@@ -459,7 +478,7 @@ export function addMessagesRoutes(
|
|
|
459
478
|
: undefined
|
|
460
479
|
|
|
461
480
|
result[channelKey]![routeKey] = {
|
|
462
|
-
|
|
481
|
+
pikkuFuncId: handlerName,
|
|
463
482
|
middleware: routeMiddleware,
|
|
464
483
|
}
|
|
465
484
|
}
|
|
@@ -501,12 +520,11 @@ export const addChannel: AddWiring = (
|
|
|
501
520
|
.map((k) => k.name)
|
|
502
521
|
: []
|
|
503
522
|
|
|
504
|
-
const { tags, summary, description, errors } =
|
|
505
|
-
obj,
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
)
|
|
523
|
+
const { disabled, tags, summary, description, errors } =
|
|
524
|
+
getCommonWireMetaData(obj, 'Channel', name, logger)
|
|
525
|
+
|
|
526
|
+
if (disabled) return
|
|
527
|
+
|
|
510
528
|
const query = getPropertyValue(obj, 'query') as string[] | []
|
|
511
529
|
|
|
512
530
|
const connect = getPropertyAssignmentInitializer(
|
|
@@ -532,21 +550,20 @@ export const addChannel: AddWiring = (
|
|
|
532
550
|
)
|
|
533
551
|
|
|
534
552
|
if (onMsgProp) {
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
const fnMeta = state.functions.meta[pikkuFuncName]
|
|
553
|
+
const extracted = extractFunctionName(onMsgProp, checker, state.rootDir)
|
|
554
|
+
const msgFuncId = extracted.pikkuFuncId.startsWith('__temp_')
|
|
555
|
+
? makeContextBasedId('channel', name, 'message')
|
|
556
|
+
: extracted.pikkuFuncId
|
|
557
|
+
const fnMeta = state.functions.meta[msgFuncId]
|
|
541
558
|
if (!fnMeta) {
|
|
542
559
|
logger.critical(
|
|
543
560
|
ErrorCode.FUNCTION_METADATA_NOT_FOUND,
|
|
544
|
-
`No function metadata found for onMessage handler '${
|
|
561
|
+
`No function metadata found for onMessage handler '${msgFuncId}'`
|
|
545
562
|
)
|
|
546
563
|
return
|
|
547
564
|
}
|
|
548
565
|
message = {
|
|
549
|
-
|
|
566
|
+
pikkuFuncId: msgFuncId,
|
|
550
567
|
}
|
|
551
568
|
}
|
|
552
569
|
|
|
@@ -555,40 +572,45 @@ export const addChannel: AddWiring = (
|
|
|
555
572
|
|
|
556
573
|
// --- resolve middleware ---
|
|
557
574
|
const middleware = resolveMiddleware(state, obj, tags, checker)
|
|
575
|
+
const channelMiddleware = resolveChannelMiddleware(state, obj, tags, checker)
|
|
558
576
|
|
|
559
577
|
// --- track used functions/middleware for service aggregation ---
|
|
560
578
|
// Track connect/disconnect/message handlers
|
|
579
|
+
let connectFuncId: string | undefined
|
|
561
580
|
if (connect) {
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
)
|
|
567
|
-
state.serviceAggregation.usedFunctions.add(connectFuncName)
|
|
581
|
+
const extracted = extractFunctionName(connect, checker, state.rootDir)
|
|
582
|
+
connectFuncId = extracted.pikkuFuncId.startsWith('__temp_')
|
|
583
|
+
? makeContextBasedId('channel', name, 'connect')
|
|
584
|
+
: extracted.pikkuFuncId
|
|
585
|
+
state.serviceAggregation.usedFunctions.add(connectFuncId)
|
|
568
586
|
}
|
|
587
|
+
|
|
588
|
+
let disconnectFuncId: string | undefined
|
|
569
589
|
if (disconnect) {
|
|
570
|
-
const
|
|
590
|
+
const extracted = extractFunctionName(
|
|
571
591
|
disconnect as any,
|
|
572
592
|
checker,
|
|
573
593
|
state.rootDir
|
|
574
|
-
)
|
|
575
|
-
|
|
594
|
+
)
|
|
595
|
+
disconnectFuncId = extracted.pikkuFuncId.startsWith('__temp_')
|
|
596
|
+
? makeContextBasedId('channel', name, 'disconnect')
|
|
597
|
+
: extracted.pikkuFuncId
|
|
598
|
+
state.serviceAggregation.usedFunctions.add(disconnectFuncId)
|
|
576
599
|
}
|
|
600
|
+
|
|
577
601
|
if (message) {
|
|
578
|
-
state.serviceAggregation.usedFunctions.add(message.
|
|
602
|
+
state.serviceAggregation.usedFunctions.add(message.pikkuFuncId)
|
|
579
603
|
}
|
|
580
|
-
|
|
604
|
+
|
|
581
605
|
for (const channelHandlers of Object.values(messageWirings)) {
|
|
582
606
|
for (const handler of Object.values(channelHandlers)) {
|
|
583
|
-
state.serviceAggregation.usedFunctions.add(handler.
|
|
607
|
+
state.serviceAggregation.usedFunctions.add(handler.pikkuFuncId)
|
|
584
608
|
}
|
|
585
609
|
}
|
|
586
|
-
// Track middleware
|
|
587
610
|
extractWireNames(middleware).forEach((name) =>
|
|
588
611
|
state.serviceAggregation.usedMiddleware.add(name)
|
|
589
612
|
)
|
|
590
613
|
|
|
591
|
-
// record into state
|
|
592
614
|
state.channels.files.add(node.getSourceFile().fileName)
|
|
593
615
|
state.channels.meta[name] = {
|
|
594
616
|
name,
|
|
@@ -596,28 +618,8 @@ export const addChannel: AddWiring = (
|
|
|
596
618
|
input: null,
|
|
597
619
|
params: params.length ? params : undefined,
|
|
598
620
|
query: query?.length ? query : undefined,
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
// 'get',
|
|
602
|
-
// null, // TODO
|
|
603
|
-
// query,
|
|
604
|
-
// params
|
|
605
|
-
// ),
|
|
606
|
-
connect: connect
|
|
607
|
-
? {
|
|
608
|
-
pikkuFuncName: extractFunctionName(connect, checker, state.rootDir)
|
|
609
|
-
.pikkuFuncName,
|
|
610
|
-
}
|
|
611
|
-
: null,
|
|
612
|
-
disconnect: disconnect
|
|
613
|
-
? {
|
|
614
|
-
pikkuFuncName: extractFunctionName(
|
|
615
|
-
disconnect as any,
|
|
616
|
-
checker,
|
|
617
|
-
state.rootDir
|
|
618
|
-
).pikkuFuncName,
|
|
619
|
-
}
|
|
620
|
-
: null,
|
|
621
|
+
connect: connectFuncId ? { pikkuFuncId: connectFuncId } : null,
|
|
622
|
+
disconnect: disconnectFuncId ? { pikkuFuncId: disconnectFuncId } : null,
|
|
621
623
|
message,
|
|
622
624
|
messageWirings,
|
|
623
625
|
summary,
|
|
@@ -625,5 +627,6 @@ export const addChannel: AddWiring = (
|
|
|
625
627
|
errors,
|
|
626
628
|
tags: tags ?? undefined,
|
|
627
629
|
middleware,
|
|
630
|
+
channelMiddleware,
|
|
628
631
|
}
|
|
629
632
|
}
|
package/src/add/add-cli.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { extractFunctionName } from '../utils/extract-function-name.js'
|
|
|
10
10
|
import { resolveMiddleware } from '../utils/middleware.js'
|
|
11
11
|
import { extractWireNames } from '../utils/post-process.js'
|
|
12
12
|
import { getPropertyValue } from '../utils/get-property-value.js'
|
|
13
|
+
import { resolveIdentifier } from '../utils/resolve-identifier.js'
|
|
13
14
|
|
|
14
15
|
// Track if we've warned about missing Config type to avoid duplicate warnings
|
|
15
16
|
const configTypeWarningShown = new Set<string>()
|
|
@@ -106,6 +107,10 @@ function processCLIConfig(
|
|
|
106
107
|
return null
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
if (getPropertyValue(node, 'disabled') === true) {
|
|
111
|
+
return null
|
|
112
|
+
}
|
|
113
|
+
|
|
109
114
|
// Second pass: process other properties with program tags available
|
|
110
115
|
for (const prop of node.properties) {
|
|
111
116
|
if (!ts.isPropertyAssignment(prop)) continue
|
|
@@ -152,7 +157,7 @@ function processCLIConfig(
|
|
|
152
157
|
prop.initializer,
|
|
153
158
|
typeChecker,
|
|
154
159
|
inspectorState.rootDir
|
|
155
|
-
).
|
|
160
|
+
).pikkuFuncId
|
|
156
161
|
break
|
|
157
162
|
}
|
|
158
163
|
}
|
|
@@ -177,6 +182,30 @@ function processCommands(
|
|
|
177
182
|
let defaultCommandName: string | null = null
|
|
178
183
|
|
|
179
184
|
for (const prop of node.properties) {
|
|
185
|
+
// Handle spread assignments: { ...externalCommands }
|
|
186
|
+
if (ts.isSpreadAssignment(prop)) {
|
|
187
|
+
let spreadTarget: ts.Node | undefined = prop.expression
|
|
188
|
+
if (ts.isIdentifier(prop.expression)) {
|
|
189
|
+
spreadTarget = resolveIdentifier(prop.expression, typeChecker, [
|
|
190
|
+
'defineCLICommands',
|
|
191
|
+
])
|
|
192
|
+
}
|
|
193
|
+
if (spreadTarget && ts.isObjectLiteralExpression(spreadTarget)) {
|
|
194
|
+
const spreadCommands = processCommands(
|
|
195
|
+
logger,
|
|
196
|
+
spreadTarget,
|
|
197
|
+
sourceFile,
|
|
198
|
+
typeChecker,
|
|
199
|
+
programName,
|
|
200
|
+
inspectorState,
|
|
201
|
+
options,
|
|
202
|
+
programTags
|
|
203
|
+
)
|
|
204
|
+
Object.assign(commands, spreadCommands)
|
|
205
|
+
}
|
|
206
|
+
continue
|
|
207
|
+
}
|
|
208
|
+
|
|
180
209
|
if (!ts.isPropertyAssignment(prop)) continue
|
|
181
210
|
|
|
182
211
|
const commandName = getPropertyName(prop)
|
|
@@ -243,11 +272,11 @@ function processCommand(
|
|
|
243
272
|
ts.isFunctionExpression(node)
|
|
244
273
|
) {
|
|
245
274
|
return {
|
|
246
|
-
|
|
275
|
+
pikkuFuncId: extractFunctionName(
|
|
247
276
|
node,
|
|
248
277
|
typeChecker,
|
|
249
278
|
inspectorState.rootDir
|
|
250
|
-
).
|
|
279
|
+
).pikkuFuncId,
|
|
251
280
|
positionals: [],
|
|
252
281
|
options: {},
|
|
253
282
|
}
|
|
@@ -285,13 +314,13 @@ function processCommand(
|
|
|
285
314
|
}
|
|
286
315
|
|
|
287
316
|
const meta: CLICommandMeta = {
|
|
288
|
-
|
|
317
|
+
pikkuFuncId: '',
|
|
289
318
|
positionals: [],
|
|
290
319
|
options: {},
|
|
291
320
|
}
|
|
292
321
|
|
|
293
|
-
// First pass: extract
|
|
294
|
-
let
|
|
322
|
+
// First pass: extract pikkuFuncId and tags so we can use them when processing options/middleware
|
|
323
|
+
let pikkuFuncId: string | undefined
|
|
295
324
|
let optionsNode: ts.ObjectLiteralExpression | undefined
|
|
296
325
|
let tags: string[] | undefined
|
|
297
326
|
|
|
@@ -302,12 +331,12 @@ function processCommand(
|
|
|
302
331
|
const propName = prop.name.text
|
|
303
332
|
|
|
304
333
|
if (propName === 'func') {
|
|
305
|
-
|
|
334
|
+
pikkuFuncId = extractFunctionName(
|
|
306
335
|
prop.initializer,
|
|
307
336
|
typeChecker,
|
|
308
337
|
inspectorState.rootDir
|
|
309
|
-
).
|
|
310
|
-
meta.
|
|
338
|
+
).pikkuFuncId
|
|
339
|
+
meta.pikkuFuncId = pikkuFuncId
|
|
311
340
|
} else if (
|
|
312
341
|
propName === 'options' &&
|
|
313
342
|
ts.isObjectLiteralExpression(prop.initializer)
|
|
@@ -367,11 +396,11 @@ function processCommand(
|
|
|
367
396
|
prop.initializer,
|
|
368
397
|
typeChecker,
|
|
369
398
|
inspectorState.rootDir
|
|
370
|
-
).
|
|
399
|
+
).pikkuFuncId
|
|
371
400
|
break
|
|
372
401
|
|
|
373
402
|
case 'options':
|
|
374
|
-
// Process with
|
|
403
|
+
// Process with pikkuFuncId from first pass
|
|
375
404
|
if (optionsNode) {
|
|
376
405
|
meta.options = processOptions(
|
|
377
406
|
logger,
|
|
@@ -379,7 +408,7 @@ function processCommand(
|
|
|
379
408
|
typeChecker,
|
|
380
409
|
inspectorState,
|
|
381
410
|
options,
|
|
382
|
-
|
|
411
|
+
pikkuFuncId
|
|
383
412
|
)
|
|
384
413
|
}
|
|
385
414
|
break
|
|
@@ -425,7 +454,7 @@ function processCommand(
|
|
|
425
454
|
}
|
|
426
455
|
|
|
427
456
|
// --- track used functions/middleware for service aggregation ---
|
|
428
|
-
inspectorState.serviceAggregation.usedFunctions.add(meta.
|
|
457
|
+
inspectorState.serviceAggregation.usedFunctions.add(meta.pikkuFuncId)
|
|
429
458
|
extractWireNames(meta.middleware).forEach((name) =>
|
|
430
459
|
inspectorState.serviceAggregation.usedMiddleware.add(name)
|
|
431
460
|
)
|
|
@@ -443,7 +472,7 @@ function processOptions(
|
|
|
443
472
|
typeChecker: TypeChecker,
|
|
444
473
|
inspectorState: InspectorState,
|
|
445
474
|
inspectorOptions: InspectorOptions,
|
|
446
|
-
|
|
475
|
+
pikkuFuncId?: string
|
|
447
476
|
): Record<string, any> {
|
|
448
477
|
const options: Record<string, any> = {}
|
|
449
478
|
|
|
@@ -506,10 +535,10 @@ function processOptions(
|
|
|
506
535
|
}
|
|
507
536
|
|
|
508
537
|
// Extract enum values from the function input type if available
|
|
509
|
-
// Get the input type if we have a
|
|
538
|
+
// Get the input type if we have a pikkuFuncId
|
|
510
539
|
let inputTypes: ts.Type[] | undefined
|
|
511
|
-
if (
|
|
512
|
-
inputTypes = inspectorState.typesLookup.get(
|
|
540
|
+
if (pikkuFuncId) {
|
|
541
|
+
inputTypes = inspectorState.typesLookup.get(pikkuFuncId)
|
|
513
542
|
}
|
|
514
543
|
|
|
515
544
|
let derivedChoices: string[] | null = null
|
|
@@ -772,7 +801,7 @@ export const addCLIRenderers: AddWiring = (
|
|
|
772
801
|
if (args.length === 0) return
|
|
773
802
|
|
|
774
803
|
// Extract renderer name
|
|
775
|
-
const {
|
|
804
|
+
const { pikkuFuncId, exportedName } = extractFunctionName(
|
|
776
805
|
node,
|
|
777
806
|
typeChecker,
|
|
778
807
|
inspectorState.rootDir
|
|
@@ -808,8 +837,8 @@ export const addCLIRenderers: AddWiring = (
|
|
|
808
837
|
}
|
|
809
838
|
|
|
810
839
|
// Store renderer metadata
|
|
811
|
-
inspectorState.cli.meta.renderers[
|
|
812
|
-
name:
|
|
840
|
+
inspectorState.cli.meta.renderers[pikkuFuncId] = {
|
|
841
|
+
name: pikkuFuncId,
|
|
813
842
|
exportedName: exportedName ?? undefined,
|
|
814
843
|
services,
|
|
815
844
|
filePath,
|
|
@@ -5,7 +5,9 @@ import { extractServicesFromFunction } from '../utils/extract-services.js'
|
|
|
5
5
|
// Mapping of wrapper function names to their corresponding types
|
|
6
6
|
const wrapperFunctionMap: Record<string, string> = {
|
|
7
7
|
pikkuConfig: 'CreateConfig',
|
|
8
|
+
pikkuExternalConfig: 'CreateConfig',
|
|
8
9
|
pikkuServices: 'CreateSingletonServices',
|
|
10
|
+
pikkuExternalServices: 'CreateSingletonServices',
|
|
9
11
|
pikkuWireServices: 'CreateWireServices',
|
|
10
12
|
}
|
|
11
13
|
|