@pikku/inspector 0.11.0 → 0.11.1
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 +16 -1
- package/dist/add/add-channel.js +11 -10
- package/dist/add/add-file-with-factory.js +10 -10
- package/dist/add/add-functions.js +57 -43
- package/dist/add/add-http-route.js +5 -4
- package/dist/add/add-mcp-prompt.js +6 -5
- package/dist/add/add-mcp-resource.js +6 -5
- package/dist/add/add-mcp-tool.js +6 -5
- package/dist/add/add-middleware.js +1 -1
- package/dist/add/add-permission.js +1 -1
- package/dist/add/add-queue-worker.js +6 -5
- package/dist/add/add-schedule.js +5 -4
- package/dist/add/add-workflow.d.ts +1 -1
- package/dist/add/add-workflow.js +92 -66
- package/dist/error-codes.d.ts +1 -0
- package/dist/error-codes.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/inspector.js +10 -6
- package/dist/types.d.ts +21 -8
- package/dist/utils/extract-function-node.d.ts +10 -0
- package/dist/utils/extract-function-node.js +38 -0
- package/dist/utils/extract-node-value.d.ts +8 -0
- package/dist/utils/extract-node-value.js +24 -0
- package/dist/utils/extract-service-metadata.d.ts +19 -0
- package/dist/utils/extract-service-metadata.js +244 -0
- package/dist/utils/get-files-and-methods.d.ts +3 -3
- package/dist/utils/get-files-and-methods.js +3 -3
- package/dist/utils/get-property-value.d.ts +13 -6
- package/dist/utils/get-property-value.js +51 -43
- package/dist/utils/post-process.d.ts +9 -0
- package/dist/utils/post-process.js +30 -3
- package/dist/utils/serialize-inspector-state.d.ts +18 -5
- package/dist/utils/serialize-inspector-state.js +12 -10
- package/dist/utils/write-service-metadata.d.ts +13 -0
- package/dist/utils/write-service-metadata.js +37 -0
- package/dist/visit.js +2 -2
- package/dist/workflow/extract-simple-workflow.d.ts +15 -0
- package/dist/workflow/extract-simple-workflow.js +803 -0
- package/dist/workflow/patterns.d.ts +39 -0
- package/dist/workflow/patterns.js +138 -0
- package/dist/workflow/validation.d.ts +28 -0
- package/dist/workflow/validation.js +124 -0
- package/package.json +4 -4
- package/src/add/add-channel.ts +37 -17
- package/src/add/add-file-with-factory.ts +10 -10
- package/src/add/add-functions.ts +72 -56
- package/src/add/add-http-route.ts +10 -5
- package/src/add/add-mcp-prompt.ts +11 -7
- package/src/add/add-mcp-resource.ts +11 -7
- package/src/add/add-mcp-tool.ts +11 -7
- package/src/add/add-middleware.ts +1 -1
- package/src/add/add-permission.ts +1 -1
- package/src/add/add-queue-worker.ts +11 -12
- package/src/add/add-schedule.ts +10 -5
- package/src/add/add-workflow.ts +120 -110
- package/src/error-codes.ts +1 -0
- package/src/index.ts +2 -0
- package/src/inspector.ts +16 -6
- package/src/types.ts +18 -8
- package/src/utils/extract-function-node.ts +58 -0
- package/src/utils/extract-node-value.ts +31 -0
- package/src/utils/extract-service-metadata.ts +353 -0
- package/src/utils/filter-inspector-state.test.ts +3 -3
- package/src/utils/filter-utils.test.ts +45 -51
- package/src/utils/get-files-and-methods.ts +11 -11
- package/src/utils/get-property-value.ts +60 -53
- package/src/utils/permissions.test.ts +3 -3
- package/src/utils/post-process.ts +56 -3
- package/src/utils/serialize-inspector-state.ts +28 -18
- package/src/utils/test-data/inspector-state.json +9 -9
- package/src/utils/write-service-metadata.ts +51 -0
- package/src/visit.ts +3 -3
- package/src/workflow/extract-simple-workflow.ts +1035 -0
- package/src/workflow/patterns.ts +182 -0
- package/src/workflow/validation.ts +153 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as ts from 'typescript'
|
|
1
2
|
import { InspectorState } from '../types.js'
|
|
2
3
|
import {
|
|
3
4
|
FunctionServicesMeta,
|
|
@@ -5,6 +6,10 @@ import {
|
|
|
5
6
|
PermissionMetadata,
|
|
6
7
|
} from '@pikku/core'
|
|
7
8
|
import { extractTypeKeys } from './type-utils.js'
|
|
9
|
+
import {
|
|
10
|
+
extractAllServiceMetadata,
|
|
11
|
+
ServiceMetadata,
|
|
12
|
+
} from './extract-service-metadata.js'
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Helper to extract wire-level middleware/permission names from metadata.
|
|
@@ -82,9 +87,9 @@ function extractAllServices(
|
|
|
82
87
|
const servicesTypes = state.typesLookup.get('Services')
|
|
83
88
|
if (servicesTypes && servicesTypes.length > 0) {
|
|
84
89
|
const allServiceNames = extractTypeKeys(servicesTypes[0])
|
|
85
|
-
//
|
|
90
|
+
// Wire services are those in Services but not in SingletonServices
|
|
86
91
|
const singletonSet = new Set(state.serviceAggregation.allSingletonServices)
|
|
87
|
-
state.serviceAggregation.
|
|
92
|
+
state.serviceAggregation.allWireServices = allServiceNames
|
|
88
93
|
.filter((name) => !singletonSet.has(name))
|
|
89
94
|
.sort()
|
|
90
95
|
}
|
|
@@ -206,7 +211,7 @@ export function aggregateRequiredServices(
|
|
|
206
211
|
}
|
|
207
212
|
|
|
208
213
|
// 5. Services from session service factories
|
|
209
|
-
for (const singletonServices of state.
|
|
214
|
+
for (const singletonServices of state.wireServicesMeta.values()) {
|
|
210
215
|
singletonServices.forEach((service) => {
|
|
211
216
|
if (!internalServices.has(service)) {
|
|
212
217
|
requiredServices.add(service)
|
|
@@ -214,3 +219,51 @@ export function aggregateRequiredServices(
|
|
|
214
219
|
})
|
|
215
220
|
}
|
|
216
221
|
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Extract service interface metadata for all user-defined services.
|
|
225
|
+
* This extracts metadata for services in SingletonServices and Services types
|
|
226
|
+
* to generate documentation for AI consumption.
|
|
227
|
+
*
|
|
228
|
+
* Must be called after aggregateRequiredServices() to ensure types are loaded.
|
|
229
|
+
*/
|
|
230
|
+
export function extractServiceInterfaceMetadata(
|
|
231
|
+
state: InspectorState | Omit<InspectorState, 'typesLookup'>,
|
|
232
|
+
checker: ts.TypeChecker
|
|
233
|
+
): void {
|
|
234
|
+
if (!('typesLookup' in state)) {
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const allMetadata: ServiceMetadata[] = []
|
|
239
|
+
|
|
240
|
+
const singletonServicesTypes = state.typesLookup.get('SingletonServices')
|
|
241
|
+
if (singletonServicesTypes && singletonServicesTypes.length > 0) {
|
|
242
|
+
const singletonMeta = extractAllServiceMetadata(
|
|
243
|
+
singletonServicesTypes[0],
|
|
244
|
+
checker,
|
|
245
|
+
state.rootDir
|
|
246
|
+
)
|
|
247
|
+
allMetadata.push(...singletonMeta)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const servicesTypes = state.typesLookup.get('Services')
|
|
251
|
+
if (servicesTypes && servicesTypes.length > 0) {
|
|
252
|
+
const wireServicesMeta = extractAllServiceMetadata(
|
|
253
|
+
servicesTypes[0],
|
|
254
|
+
checker,
|
|
255
|
+
state.rootDir
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
const singletonNames = new Set(
|
|
259
|
+
state.serviceAggregation.allSingletonServices
|
|
260
|
+
)
|
|
261
|
+
const uniqueWireServices = wireServicesMeta.filter(
|
|
262
|
+
(meta) => !singletonNames.has(meta.name)
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
allMetadata.push(...uniqueWireServices)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
state.serviceMetadata = allMetadata
|
|
269
|
+
}
|
|
@@ -13,7 +13,7 @@ export interface SerializableInspectorState {
|
|
|
13
13
|
{ variable: string; type: string | null; typePath: string | null }[],
|
|
14
14
|
]
|
|
15
15
|
>
|
|
16
|
-
|
|
16
|
+
wireServicesTypeImportMap: Array<
|
|
17
17
|
[
|
|
18
18
|
string,
|
|
19
19
|
{ variable: string; type: string | null; typePath: string | null }[],
|
|
@@ -37,13 +37,13 @@ export interface SerializableInspectorState {
|
|
|
37
37
|
{ variable: string; type: string | null; typePath: string | null }[],
|
|
38
38
|
]
|
|
39
39
|
>
|
|
40
|
-
|
|
40
|
+
wireServicesFactories: Array<
|
|
41
41
|
[
|
|
42
42
|
string,
|
|
43
43
|
{ variable: string; type: string | null; typePath: string | null }[],
|
|
44
44
|
]
|
|
45
45
|
>
|
|
46
|
-
|
|
46
|
+
wireServicesMeta: Array<[string, string[]]>
|
|
47
47
|
configFactories: Array<
|
|
48
48
|
[
|
|
49
49
|
string,
|
|
@@ -114,7 +114,7 @@ export interface SerializableInspectorState {
|
|
|
114
114
|
}
|
|
115
115
|
workflows: {
|
|
116
116
|
meta: InspectorState['workflows']['meta']
|
|
117
|
-
files: string
|
|
117
|
+
files: Array<[string, { path: string; exportedName: string }]>
|
|
118
118
|
}
|
|
119
119
|
rpc: {
|
|
120
120
|
internalMeta: InspectorState['rpc']['internalMeta']
|
|
@@ -167,8 +167,18 @@ export interface SerializableInspectorState {
|
|
|
167
167
|
usedMiddleware: string[]
|
|
168
168
|
usedPermissions: string[]
|
|
169
169
|
allSingletonServices: string[]
|
|
170
|
-
|
|
170
|
+
allWireServices: string[]
|
|
171
171
|
}
|
|
172
|
+
serviceMetadata: Array<{
|
|
173
|
+
name: string
|
|
174
|
+
summary: string
|
|
175
|
+
description: string
|
|
176
|
+
package: string
|
|
177
|
+
path: string
|
|
178
|
+
version: string
|
|
179
|
+
interface: string
|
|
180
|
+
expandedProperties: Record<string, string>
|
|
181
|
+
}>
|
|
172
182
|
}
|
|
173
183
|
|
|
174
184
|
/**
|
|
@@ -204,8 +214,8 @@ export function serializeInspectorState(
|
|
|
204
214
|
singletonServicesTypeImportMap: Array.from(
|
|
205
215
|
state.singletonServicesTypeImportMap.entries()
|
|
206
216
|
),
|
|
207
|
-
|
|
208
|
-
state.
|
|
217
|
+
wireServicesTypeImportMap: Array.from(
|
|
218
|
+
state.wireServicesTypeImportMap.entries()
|
|
209
219
|
),
|
|
210
220
|
userSessionTypeImportMap: Array.from(
|
|
211
221
|
state.userSessionTypeImportMap.entries()
|
|
@@ -214,10 +224,8 @@ export function serializeInspectorState(
|
|
|
214
224
|
singletonServicesFactories: Array.from(
|
|
215
225
|
state.singletonServicesFactories.entries()
|
|
216
226
|
),
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
),
|
|
220
|
-
sessionServicesMeta: Array.from(state.sessionServicesMeta.entries()),
|
|
227
|
+
wireServicesFactories: Array.from(state.wireServicesFactories.entries()),
|
|
228
|
+
wireServicesMeta: Array.from(state.wireServicesMeta.entries()),
|
|
221
229
|
configFactories: Array.from(state.configFactories.entries()),
|
|
222
230
|
filesAndMethods: state.filesAndMethods,
|
|
223
231
|
filesAndMethodsErrors: Array.from(
|
|
@@ -249,7 +257,7 @@ export function serializeInspectorState(
|
|
|
249
257
|
},
|
|
250
258
|
workflows: {
|
|
251
259
|
meta: state.workflows.meta,
|
|
252
|
-
files: Array.from(state.workflows.files),
|
|
260
|
+
files: Array.from(state.workflows.files.entries()),
|
|
253
261
|
},
|
|
254
262
|
rpc: {
|
|
255
263
|
internalMeta: state.rpc.internalMeta,
|
|
@@ -282,8 +290,9 @@ export function serializeInspectorState(
|
|
|
282
290
|
usedMiddleware: Array.from(state.serviceAggregation.usedMiddleware),
|
|
283
291
|
usedPermissions: Array.from(state.serviceAggregation.usedPermissions),
|
|
284
292
|
allSingletonServices: state.serviceAggregation.allSingletonServices,
|
|
285
|
-
|
|
293
|
+
allWireServices: state.serviceAggregation.allWireServices,
|
|
286
294
|
},
|
|
295
|
+
serviceMetadata: state.serviceMetadata,
|
|
287
296
|
}
|
|
288
297
|
}
|
|
289
298
|
|
|
@@ -314,12 +323,12 @@ export function deserializeInspectorState(
|
|
|
314
323
|
singletonServicesTypeImportMap: new Map(
|
|
315
324
|
data.singletonServicesTypeImportMap
|
|
316
325
|
),
|
|
317
|
-
|
|
326
|
+
wireServicesTypeImportMap: new Map(data.wireServicesTypeImportMap),
|
|
318
327
|
userSessionTypeImportMap: new Map(data.userSessionTypeImportMap),
|
|
319
328
|
configTypeImportMap: new Map(data.configTypeImportMap),
|
|
320
329
|
singletonServicesFactories: new Map(data.singletonServicesFactories),
|
|
321
|
-
|
|
322
|
-
|
|
330
|
+
wireServicesFactories: new Map(data.wireServicesFactories),
|
|
331
|
+
wireServicesMeta: new Map(data.wireServicesMeta),
|
|
323
332
|
configFactories: new Map(data.configFactories),
|
|
324
333
|
filesAndMethods: data.filesAndMethods,
|
|
325
334
|
filesAndMethodsErrors: new Map(
|
|
@@ -354,7 +363,7 @@ export function deserializeInspectorState(
|
|
|
354
363
|
},
|
|
355
364
|
workflows: {
|
|
356
365
|
meta: data.workflows.meta,
|
|
357
|
-
files: new
|
|
366
|
+
files: new Map(data.workflows.files),
|
|
358
367
|
},
|
|
359
368
|
rpc: {
|
|
360
369
|
internalMeta: data.rpc.internalMeta,
|
|
@@ -387,7 +396,8 @@ export function deserializeInspectorState(
|
|
|
387
396
|
usedMiddleware: new Set(data.serviceAggregation.usedMiddleware),
|
|
388
397
|
usedPermissions: new Set(data.serviceAggregation.usedPermissions),
|
|
389
398
|
allSingletonServices: data.serviceAggregation.allSingletonServices,
|
|
390
|
-
|
|
399
|
+
allWireServices: data.serviceAggregation.allWireServices,
|
|
391
400
|
},
|
|
401
|
+
serviceMetadata: data.serviceMetadata || [],
|
|
392
402
|
}
|
|
393
403
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
]
|
|
13
13
|
]
|
|
14
14
|
],
|
|
15
|
-
"
|
|
15
|
+
"wireServicesTypeImportMap": [
|
|
16
16
|
[
|
|
17
17
|
"/Users/yasser/git/pikku/pikku/templates/functions/types/application-types.d.ts",
|
|
18
18
|
[
|
|
@@ -60,19 +60,19 @@
|
|
|
60
60
|
]
|
|
61
61
|
]
|
|
62
62
|
],
|
|
63
|
-
"
|
|
63
|
+
"wireServicesFactories": [
|
|
64
64
|
[
|
|
65
65
|
"src/services.ts",
|
|
66
66
|
[
|
|
67
67
|
{
|
|
68
|
-
"variable": "
|
|
69
|
-
"type": "
|
|
68
|
+
"variable": "createWireServices",
|
|
69
|
+
"type": "CreateWireServices",
|
|
70
70
|
"typePath": "src/services.ts"
|
|
71
71
|
}
|
|
72
72
|
]
|
|
73
73
|
]
|
|
74
74
|
],
|
|
75
|
-
"
|
|
75
|
+
"wireServicesMeta": [["createWireServices", []]],
|
|
76
76
|
"configFactories": [
|
|
77
77
|
[
|
|
78
78
|
"src/services.ts",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"variable": "SingletonServices",
|
|
99
99
|
"typePath": "/Users/yasser/git/pikku/pikku/templates/functions/types/application-types.d.ts"
|
|
100
100
|
},
|
|
101
|
-
"
|
|
101
|
+
"wireServicesType": {
|
|
102
102
|
"file": "/Users/yasser/git/pikku/pikku/templates/functions/types/application-types.d.ts",
|
|
103
103
|
"type": "Services",
|
|
104
104
|
"variable": "Services",
|
|
@@ -122,10 +122,10 @@
|
|
|
122
122
|
"variable": "createSingletonServices",
|
|
123
123
|
"typePath": "src/services.ts"
|
|
124
124
|
},
|
|
125
|
-
"
|
|
125
|
+
"wireServicesFactory": {
|
|
126
126
|
"file": "src/services.ts",
|
|
127
|
-
"type": "
|
|
128
|
-
"variable": "
|
|
127
|
+
"type": "CreateWireServices",
|
|
128
|
+
"variable": "createWireServices",
|
|
129
129
|
"typePath": "src/services.ts"
|
|
130
130
|
}
|
|
131
131
|
},
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as fs from 'fs'
|
|
2
|
+
import * as path from 'path'
|
|
3
|
+
import { ServiceMetadata } from './extract-service-metadata.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Write service metadata to a JSON file in .pikku/services directory
|
|
7
|
+
*/
|
|
8
|
+
export function writeServiceMetadata(
|
|
9
|
+
serviceMeta: ServiceMetadata,
|
|
10
|
+
outDir: string
|
|
11
|
+
): void {
|
|
12
|
+
const servicesDir = path.join(outDir, 'services')
|
|
13
|
+
|
|
14
|
+
if (!fs.existsSync(servicesDir)) {
|
|
15
|
+
fs.mkdirSync(servicesDir, { recursive: true })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const fileName = `${serviceMeta.name}.gen.json`
|
|
19
|
+
const filePath = path.join(servicesDir, fileName)
|
|
20
|
+
|
|
21
|
+
const jsonContent = JSON.stringify(serviceMeta, null, 2)
|
|
22
|
+
fs.writeFileSync(filePath, jsonContent, 'utf-8')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Write all service metadata files
|
|
27
|
+
*/
|
|
28
|
+
export function writeAllServiceMetadata(
|
|
29
|
+
servicesMetadata: ServiceMetadata[],
|
|
30
|
+
outDir: string
|
|
31
|
+
): void {
|
|
32
|
+
for (const serviceMeta of servicesMetadata) {
|
|
33
|
+
writeServiceMetadata(serviceMeta, outDir)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Clean up services directory (remove old service JSON files)
|
|
39
|
+
*/
|
|
40
|
+
export function cleanServicesDirectory(outDir: string): void {
|
|
41
|
+
const servicesDir = path.join(outDir, 'services')
|
|
42
|
+
|
|
43
|
+
if (fs.existsSync(servicesDir)) {
|
|
44
|
+
const files = fs.readdirSync(servicesDir)
|
|
45
|
+
for (const file of files) {
|
|
46
|
+
if (file.endsWith('.gen.json')) {
|
|
47
|
+
fs.unlinkSync(path.join(servicesDir, file))
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/visit.ts
CHANGED
|
@@ -34,7 +34,7 @@ export const visitSetup = (
|
|
|
34
34
|
addFileExtendsCoreType(
|
|
35
35
|
node,
|
|
36
36
|
checker,
|
|
37
|
-
state.
|
|
37
|
+
state.wireServicesTypeImportMap,
|
|
38
38
|
'CoreServices',
|
|
39
39
|
state
|
|
40
40
|
)
|
|
@@ -65,8 +65,8 @@ export const visitSetup = (
|
|
|
65
65
|
addFileWithFactory(
|
|
66
66
|
node,
|
|
67
67
|
checker,
|
|
68
|
-
state.
|
|
69
|
-
'
|
|
68
|
+
state.wireServicesFactories,
|
|
69
|
+
'CreateWireServices',
|
|
70
70
|
state
|
|
71
71
|
)
|
|
72
72
|
|