@pikku/inspector 0.10.2 → 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 +23 -0
- package/dist/add/add-channel.js +11 -10
- package/dist/add/add-file-with-factory.js +10 -10
- package/dist/add/add-functions.js +65 -44
- 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 +6 -0
- package/dist/add/add-workflow.js +178 -0
- package/dist/error-codes.d.ts +5 -1
- package/dist/error-codes.js +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/inspector.js +13 -5
- package/dist/types.d.ts +27 -9
- 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 +32 -0
- package/dist/utils/extract-node-value.js +103 -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 +21 -4
- package/dist/utils/serialize-inspector-state.js +18 -8
- package/dist/utils/type-utils.d.ts +4 -0
- package/dist/utils/type-utils.js +55 -0
- package/dist/utils/write-service-metadata.d.ts +13 -0
- package/dist/utils/write-service-metadata.js +37 -0
- package/dist/visit.js +4 -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 +81 -57
- 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 +241 -0
- package/src/error-codes.ts +6 -0
- package/src/index.ts +2 -0
- package/src/inspector.ts +19 -5
- package/src/types.ts +24 -9
- package/src/utils/extract-function-node.ts +58 -0
- package/src/utils/extract-node-value.ts +132 -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 +37 -15
- package/src/utils/test-data/inspector-state.json +13 -9
- package/src/utils/type-utils.ts +69 -0
- package/src/utils/write-service-metadata.ts +51 -0
- package/src/visit.ts +5 -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
- package/src/add/add-mcp-prompt.ts.tmp +0 -0
- package/src/add/add-mcp-resource.ts.tmp +0 -0
package/dist/utils/type-utils.js
CHANGED
|
@@ -2,6 +2,61 @@ import * as ts from 'typescript';
|
|
|
2
2
|
export const extractTypeKeys = (type) => {
|
|
3
3
|
return type.getProperties().map((symbol) => symbol.getName());
|
|
4
4
|
};
|
|
5
|
+
/**
|
|
6
|
+
* Resolve an identifier or call expression to the actual function declaration
|
|
7
|
+
*/
|
|
8
|
+
export function resolveFunctionDeclaration(node, checker) {
|
|
9
|
+
// If it's already a function-like node, return it
|
|
10
|
+
if (ts.isFunctionDeclaration(node) ||
|
|
11
|
+
ts.isFunctionExpression(node) ||
|
|
12
|
+
ts.isArrowFunction(node)) {
|
|
13
|
+
return node;
|
|
14
|
+
}
|
|
15
|
+
// If it's a call expression (e.g., pikkuWorkflowFunc(...)), get its first argument
|
|
16
|
+
if (ts.isCallExpression(node) && node.arguments.length > 0) {
|
|
17
|
+
const firstArg = node.arguments[0];
|
|
18
|
+
if (ts.isFunctionExpression(firstArg) || ts.isArrowFunction(firstArg)) {
|
|
19
|
+
return firstArg;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// If it's an identifier, resolve to declaration
|
|
23
|
+
if (ts.isIdentifier(node)) {
|
|
24
|
+
const symbol = checker.getSymbolAtLocation(node);
|
|
25
|
+
if (!symbol)
|
|
26
|
+
return null;
|
|
27
|
+
// Try valueDeclaration first, then fallback to declarations[0]
|
|
28
|
+
const decl = symbol.valueDeclaration || symbol.declarations?.[0];
|
|
29
|
+
if (!decl)
|
|
30
|
+
return null;
|
|
31
|
+
// If it's an import specifier, resolve the aliased symbol
|
|
32
|
+
if (ts.isImportSpecifier(decl)) {
|
|
33
|
+
const aliasedSymbol = checker.getAliasedSymbol(symbol);
|
|
34
|
+
if (aliasedSymbol) {
|
|
35
|
+
const aliasedDecl = aliasedSymbol.valueDeclaration || aliasedSymbol.declarations?.[0];
|
|
36
|
+
if (aliasedDecl) {
|
|
37
|
+
// For variable declarations, get the initializer
|
|
38
|
+
if (ts.isVariableDeclaration(aliasedDecl) &&
|
|
39
|
+
aliasedDecl.initializer) {
|
|
40
|
+
return resolveFunctionDeclaration(aliasedDecl.initializer, checker);
|
|
41
|
+
}
|
|
42
|
+
// For function declarations, return directly
|
|
43
|
+
if (ts.isFunctionDeclaration(aliasedDecl)) {
|
|
44
|
+
return aliasedDecl;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// If it's a variable declaration, get the initializer
|
|
50
|
+
if (ts.isVariableDeclaration(decl) && decl.initializer) {
|
|
51
|
+
return resolveFunctionDeclaration(decl.initializer, checker);
|
|
52
|
+
}
|
|
53
|
+
// If it's a function declaration
|
|
54
|
+
if (ts.isFunctionDeclaration(decl)) {
|
|
55
|
+
return decl;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
5
60
|
export function getPropertyAssignmentInitializer(obj, propName, followShorthand = false, checker) {
|
|
6
61
|
for (const prop of obj.properties) {
|
|
7
62
|
// ① foo: () => {}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ServiceMetadata } from './extract-service-metadata.js';
|
|
2
|
+
/**
|
|
3
|
+
* Write service metadata to a JSON file in .pikku/services directory
|
|
4
|
+
*/
|
|
5
|
+
export declare function writeServiceMetadata(serviceMeta: ServiceMetadata, outDir: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Write all service metadata files
|
|
8
|
+
*/
|
|
9
|
+
export declare function writeAllServiceMetadata(servicesMetadata: ServiceMetadata[], outDir: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* Clean up services directory (remove old service JSON files)
|
|
12
|
+
*/
|
|
13
|
+
export declare function cleanServicesDirectory(outDir: string): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Write service metadata to a JSON file in .pikku/services directory
|
|
5
|
+
*/
|
|
6
|
+
export function writeServiceMetadata(serviceMeta, outDir) {
|
|
7
|
+
const servicesDir = path.join(outDir, 'services');
|
|
8
|
+
if (!fs.existsSync(servicesDir)) {
|
|
9
|
+
fs.mkdirSync(servicesDir, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
const fileName = `${serviceMeta.name}.gen.json`;
|
|
12
|
+
const filePath = path.join(servicesDir, fileName);
|
|
13
|
+
const jsonContent = JSON.stringify(serviceMeta, null, 2);
|
|
14
|
+
fs.writeFileSync(filePath, jsonContent, 'utf-8');
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Write all service metadata files
|
|
18
|
+
*/
|
|
19
|
+
export function writeAllServiceMetadata(servicesMetadata, outDir) {
|
|
20
|
+
for (const serviceMeta of servicesMetadata) {
|
|
21
|
+
writeServiceMetadata(serviceMeta, outDir);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Clean up services directory (remove old service JSON files)
|
|
26
|
+
*/
|
|
27
|
+
export function cleanServicesDirectory(outDir) {
|
|
28
|
+
const servicesDir = path.join(outDir, 'services');
|
|
29
|
+
if (fs.existsSync(servicesDir)) {
|
|
30
|
+
const files = fs.readdirSync(servicesDir);
|
|
31
|
+
for (const file of files) {
|
|
32
|
+
if (file.endsWith('.gen.json')) {
|
|
33
|
+
fs.unlinkSync(path.join(servicesDir, file));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
package/dist/visit.js
CHANGED
|
@@ -4,6 +4,7 @@ import { addFileExtendsCoreType } from './add/add-file-extends-core-type.js';
|
|
|
4
4
|
import { addHTTPRoute } from './add/add-http-route.js';
|
|
5
5
|
import { addSchedule } from './add/add-schedule.js';
|
|
6
6
|
import { addQueueWorker } from './add/add-queue-worker.js';
|
|
7
|
+
import { addWorkflow } from './add/add-workflow.js';
|
|
7
8
|
import { addMCPResource } from './add/add-mcp-resource.js';
|
|
8
9
|
import { addMCPTool } from './add/add-mcp-tool.js';
|
|
9
10
|
import { addMCPPrompt } from './add/add-mcp-prompt.js';
|
|
@@ -15,15 +16,16 @@ import { addPermission } from './add/add-permission.js';
|
|
|
15
16
|
import { addCLI, addCLIRenderers } from './add/add-cli.js';
|
|
16
17
|
export const visitSetup = (logger, checker, node, state, options) => {
|
|
17
18
|
addFileExtendsCoreType(node, checker, state.singletonServicesTypeImportMap, 'CoreSingletonServices', state);
|
|
18
|
-
addFileExtendsCoreType(node, checker, state.
|
|
19
|
+
addFileExtendsCoreType(node, checker, state.wireServicesTypeImportMap, 'CoreServices', state);
|
|
19
20
|
addFileExtendsCoreType(node, checker, state.userSessionTypeImportMap, 'CoreUserSession', state);
|
|
20
21
|
addFileExtendsCoreType(node, checker, state.configTypeImportMap, 'CoreConfig', state);
|
|
21
22
|
addFileWithFactory(node, checker, state.singletonServicesFactories, 'CreateSingletonServices');
|
|
22
|
-
addFileWithFactory(node, checker, state.
|
|
23
|
+
addFileWithFactory(node, checker, state.wireServicesFactories, 'CreateWireServices', state);
|
|
23
24
|
addFileWithFactory(node, checker, state.configFactories, 'CreateConfig');
|
|
24
25
|
addRPCInvocations(node, state, logger);
|
|
25
26
|
addMiddleware(logger, node, checker, state, options);
|
|
26
27
|
addPermission(logger, node, checker, state, options);
|
|
28
|
+
addWorkflow(logger, node, checker, state, options);
|
|
27
29
|
ts.forEachChild(node, (child) => visitSetup(logger, checker, child, state, options));
|
|
28
30
|
};
|
|
29
31
|
export const visitRoutes = (logger, checker, node, state, options) => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { WorkflowStepMeta } from '@pikku/core/workflow';
|
|
3
|
+
/**
|
|
4
|
+
* Result of simple workflow extraction
|
|
5
|
+
*/
|
|
6
|
+
export interface ExtractionResult {
|
|
7
|
+
status: 'ok' | 'error';
|
|
8
|
+
steps?: WorkflowStepMeta[];
|
|
9
|
+
reason?: string;
|
|
10
|
+
simple?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Extract simple workflow metadata from a function declaration
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractSimpleWorkflow(funcNode: ts.Node, checker: ts.TypeChecker): ExtractionResult;
|