@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.
- package/CHANGELOG.md +14 -0
- package/dist/add/add-channel.d.ts +17 -0
- package/dist/{add-channel.js → add/add-channel.js} +60 -34
- package/dist/add/add-cli.d.ts +9 -0
- package/dist/add/add-cli.js +566 -0
- package/dist/{add-file-extends-core-type.d.ts → add/add-file-extends-core-type.d.ts} +2 -2
- package/dist/{add-file-extends-core-type.js → add/add-file-extends-core-type.js} +17 -4
- package/dist/{add-file-with-config.d.ts → add/add-file-with-config.d.ts} +1 -1
- package/dist/{add-file-with-config.js → add/add-file-with-config.js} +1 -1
- package/dist/{add-file-with-factory.d.ts → add/add-file-with-factory.d.ts} +2 -2
- package/dist/{add-file-with-factory.js → add/add-file-with-factory.js} +38 -5
- package/dist/add/add-functions.d.ts +6 -0
- package/dist/{add-functions.js → add/add-functions.js} +77 -10
- package/dist/{add-http-route.d.ts → add/add-http-route.d.ts} +2 -3
- package/dist/{add-http-route.js → add/add-http-route.js} +26 -13
- package/dist/add/add-mcp-prompt.d.ts +2 -0
- package/dist/add/add-mcp-prompt.js +74 -0
- package/dist/add/add-mcp-resource.d.ts +2 -0
- package/dist/add/add-mcp-resource.js +84 -0
- package/dist/add/add-mcp-tool.d.ts +2 -0
- package/dist/add/add-mcp-tool.js +80 -0
- package/dist/add/add-middleware.d.ts +5 -0
- package/dist/add/add-middleware.js +290 -0
- package/dist/add/add-permission.d.ts +5 -0
- package/dist/add/add-permission.js +292 -0
- package/dist/add/add-queue-worker.d.ts +2 -0
- package/dist/add/add-queue-worker.js +52 -0
- package/dist/{add-rpc-invocations.d.ts → add/add-rpc-invocations.d.ts} +1 -1
- package/dist/add/add-schedule.d.ts +2 -0
- package/dist/{add-schedule.js → add/add-schedule.js} +16 -11
- package/dist/error-codes.d.ts +35 -0
- package/dist/error-codes.js +40 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/inspector.d.ts +2 -3
- package/dist/inspector.js +38 -8
- package/dist/types.d.ts +108 -1
- package/dist/utils/ensure-function-metadata.d.ts +6 -0
- package/dist/utils/ensure-function-metadata.js +18 -0
- package/dist/utils/extract-function-name.d.ts +31 -0
- package/dist/{utils.js → utils/extract-function-name.js} +35 -149
- package/dist/utils/extract-services.d.ts +6 -0
- package/dist/utils/extract-services.js +29 -0
- package/dist/utils/filter-inspector-state.d.ts +6 -0
- package/dist/utils/filter-inspector-state.js +382 -0
- package/dist/utils/filter-utils.d.ts +19 -0
- package/dist/utils/filter-utils.js +109 -0
- package/dist/utils/find-root-dir.d.ts +23 -0
- package/dist/utils/find-root-dir.js +55 -0
- package/dist/utils/get-files-and-methods.d.ts +22 -0
- package/dist/utils/get-files-and-methods.js +61 -0
- package/dist/utils/get-property-value.d.ts +12 -0
- package/dist/{get-property-value.js → utils/get-property-value.js} +20 -0
- package/dist/utils/middleware.d.ts +39 -0
- package/dist/utils/middleware.js +157 -0
- package/dist/utils/permissions.d.ts +43 -0
- package/dist/utils/permissions.js +178 -0
- package/dist/utils/post-process.d.ts +16 -0
- package/dist/utils/post-process.js +132 -0
- package/dist/utils/serialize-inspector-state.d.ts +179 -0
- package/dist/utils/serialize-inspector-state.js +170 -0
- package/dist/utils/type-utils.d.ts +3 -0
- package/dist/utils/type-utils.js +50 -0
- package/dist/visit.d.ts +3 -3
- package/dist/visit.js +35 -31
- package/package.json +5 -6
- package/src/{add-channel.ts → add/add-channel.ts} +108 -56
- package/src/add/add-cli.ts +822 -0
- package/src/{add-file-extends-core-type.ts → add/add-file-extends-core-type.ts} +23 -5
- package/src/{add-file-with-config.ts → add/add-file-with-config.ts} +2 -2
- package/src/{add-file-with-factory.ts → add/add-file-with-factory.ts} +49 -6
- package/src/{add-functions.ts → add/add-functions.ts} +89 -19
- package/src/{add-http-route.ts → add/add-http-route.ts} +66 -32
- package/src/add/add-mcp-prompt.ts +128 -0
- package/src/add/add-mcp-prompt.ts.tmp +0 -0
- package/src/add/add-mcp-resource.ts +145 -0
- package/src/add/add-mcp-resource.ts.tmp +0 -0
- package/src/add/add-mcp-tool.ts +137 -0
- package/src/add/add-middleware.ts +385 -0
- package/src/add/add-permission.ts +391 -0
- package/src/add/add-queue-worker.ts +92 -0
- package/src/{add-rpc-invocations.ts → add/add-rpc-invocations.ts} +1 -1
- package/src/{add-schedule.ts → add/add-schedule.ts} +30 -28
- package/src/error-codes.ts +43 -0
- package/src/index.ts +12 -0
- package/src/inspector.ts +41 -17
- package/src/types.ts +128 -1
- package/src/utils/ensure-function-metadata.ts +24 -0
- package/src/{utils.ts → utils/extract-function-name.ts} +44 -206
- package/src/utils/extract-services.ts +35 -0
- package/src/utils/filter-inspector-state.test.ts +1433 -0
- package/src/utils/filter-inspector-state.ts +526 -0
- package/src/{utils.test.ts → utils/filter-utils.test.ts} +351 -2
- package/src/utils/filter-utils.ts +152 -0
- package/src/utils/find-root-dir.ts +68 -0
- package/src/utils/get-files-and-methods.ts +151 -0
- package/src/{get-property-value.ts → utils/get-property-value.ts} +27 -0
- package/src/utils/middleware.ts +241 -0
- package/src/utils/permissions.test.ts +327 -0
- package/src/utils/permissions.ts +262 -0
- package/src/utils/post-process.ts +178 -0
- package/src/utils/serialize-inspector-state.ts +375 -0
- package/src/utils/test-data/inspector-state.json +1680 -0
- package/src/utils/type-utils.ts +74 -0
- package/src/visit.ts +50 -34
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/add-channel.d.ts +0 -13
- package/dist/add-functions.d.ts +0 -7
- package/dist/add-mcp-prompt.d.ts +0 -3
- package/dist/add-mcp-prompt.js +0 -61
- package/dist/add-mcp-resource.d.ts +0 -3
- package/dist/add-mcp-resource.js +0 -68
- package/dist/add-mcp-tool.d.ts +0 -3
- package/dist/add-mcp-tool.js +0 -64
- package/dist/add-middleware.d.ts +0 -7
- package/dist/add-middleware.js +0 -35
- package/dist/add-permission.d.ts +0 -7
- package/dist/add-permission.js +0 -35
- package/dist/add-queue-worker.d.ts +0 -3
- package/dist/add-queue-worker.js +0 -48
- package/dist/add-schedule.d.ts +0 -3
- package/dist/get-property-value.d.ts +0 -3
- package/dist/utils.d.ts +0 -39
- package/src/add-mcp-prompt.ts +0 -104
- package/src/add-mcp-resource.ts +0 -116
- package/src/add-mcp-tool.ts +0 -107
- package/src/add-middleware.ts +0 -51
- package/src/add-permission.ts +0 -53
- package/src/add-queue-worker.ts +0 -92
- /package/dist/{add-rpc-invocations.js → add/add-rpc-invocations.js} +0 -0
- /package/dist/{does-type-extend-core-type.d.ts → utils/does-type-extend-core-type.d.ts} +0 -0
- /package/dist/{does-type-extend-core-type.js → utils/does-type-extend-core-type.js} +0 -0
- /package/src/{does-type-extend-core-type.ts → utils/does-type-extend-core-type.ts} +0 -0
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
import { getPropertyValue } from '
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
2
|
+
import { getPropertyValue, getPropertyTags, } from '../utils/get-property-value.js';
|
|
3
|
+
import { extractFunctionName } from '../utils/extract-function-name.js';
|
|
4
|
+
import { getPropertyAssignmentInitializer } from '../utils/type-utils.js';
|
|
5
|
+
import { resolveMiddleware } from '../utils/middleware.js';
|
|
6
|
+
import { extractWireNames } from '../utils/post-process.js';
|
|
7
|
+
import { ErrorCode } from '../error-codes.js';
|
|
8
|
+
export const addSchedule = (logger, node, checker, state, options) => {
|
|
6
9
|
if (!ts.isCallExpression(node)) {
|
|
7
10
|
return;
|
|
8
11
|
}
|
|
@@ -21,20 +24,21 @@ export const addSchedule = (node, checker, state, filters, logger) => {
|
|
|
21
24
|
const nameValue = getPropertyValue(obj, 'name');
|
|
22
25
|
const scheduleValue = getPropertyValue(obj, 'schedule');
|
|
23
26
|
const docs = getPropertyValue(obj, 'docs') || undefined;
|
|
24
|
-
const tags =
|
|
27
|
+
const tags = getPropertyTags(obj, 'Scheduler', nameValue, logger);
|
|
25
28
|
const funcInitializer = getPropertyAssignmentInitializer(obj, 'func', true, checker);
|
|
26
29
|
if (!funcInitializer) {
|
|
27
|
-
|
|
30
|
+
logger.critical(ErrorCode.MISSING_FUNC, `No valid 'func' property for scheduled task '${nameValue}'.`);
|
|
28
31
|
return;
|
|
29
32
|
}
|
|
30
|
-
const pikkuFuncName = extractFunctionName(funcInitializer, checker).pikkuFuncName;
|
|
33
|
+
const pikkuFuncName = extractFunctionName(funcInitializer, checker, state.rootDir).pikkuFuncName;
|
|
31
34
|
if (!nameValue || !scheduleValue) {
|
|
32
35
|
return;
|
|
33
36
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
// --- resolve middleware ---
|
|
38
|
+
const middleware = resolveMiddleware(state, obj, tags, checker);
|
|
39
|
+
// --- track used functions/middleware for service aggregation ---
|
|
40
|
+
state.serviceAggregation.usedFunctions.add(pikkuFuncName);
|
|
41
|
+
extractWireNames(middleware).forEach((name) => state.serviceAggregation.usedMiddleware.add(name));
|
|
38
42
|
state.scheduledTasks.files.add(node.getSourceFile().fileName);
|
|
39
43
|
state.scheduledTasks.meta[nameValue] = {
|
|
40
44
|
pikkuFuncName,
|
|
@@ -42,6 +46,7 @@ export const addSchedule = (node, checker, state, filters, logger) => {
|
|
|
42
46
|
schedule: scheduleValue,
|
|
43
47
|
docs,
|
|
44
48
|
tags,
|
|
49
|
+
middleware,
|
|
45
50
|
};
|
|
46
51
|
}
|
|
47
52
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error code system for Pikku CLI and Inspector
|
|
3
|
+
*
|
|
4
|
+
* Each error has a unique code and links to documentation at pikku.dev
|
|
5
|
+
*
|
|
6
|
+
* Error codes use random 3-digit numbers to avoid implying a sequential order.
|
|
7
|
+
* Each code links to detailed documentation and troubleshooting steps.
|
|
8
|
+
*/
|
|
9
|
+
export declare enum ErrorCode {
|
|
10
|
+
MISSING_NAME = "PKU111",
|
|
11
|
+
MISSING_DESCRIPTION = "PKU123",
|
|
12
|
+
MISSING_URI = "PKU220",
|
|
13
|
+
MISSING_FUNC = "PKU236",
|
|
14
|
+
INVALID_TAGS_TYPE = "PKU247",
|
|
15
|
+
INVALID_HANDLER = "PKU300",
|
|
16
|
+
MISSING_TITLE = "PKU370",
|
|
17
|
+
MISSING_QUEUE_NAME = "PKU384",
|
|
18
|
+
MISSING_CHANNEL_NAME = "PKU400",
|
|
19
|
+
CLI_CLIENTSIDE_RENDERER_HAS_SERVICES = "PKU672",
|
|
20
|
+
CONFIG_TYPE_NOT_FOUND = "PKU426",
|
|
21
|
+
CONFIG_TYPE_UNDEFINED = "PKU427",
|
|
22
|
+
SCHEMA_NO_ROOT = "PKU431",
|
|
23
|
+
SCHEMA_GENERATION_ERROR = "PKU456",
|
|
24
|
+
SCHEMA_LOAD_ERROR = "PKU488",
|
|
25
|
+
FUNCTION_METADATA_NOT_FOUND = "PKU559",
|
|
26
|
+
HANDLER_NOT_RESOLVED = "PKU568",
|
|
27
|
+
MIDDLEWARE_HANDLER_INVALID = "PKU685",
|
|
28
|
+
MIDDLEWARE_TAG_INVALID = "PKU715",
|
|
29
|
+
MIDDLEWARE_EMPTY_ARRAY = "PKU736",
|
|
30
|
+
MIDDLEWARE_PATTERN_INVALID = "PKU787",
|
|
31
|
+
PERMISSION_HANDLER_INVALID = "PKU835",
|
|
32
|
+
PERMISSION_TAG_INVALID = "PKU836",
|
|
33
|
+
PERMISSION_EMPTY_ARRAY = "PKU937",
|
|
34
|
+
PERMISSION_PATTERN_INVALID = "PKU975"
|
|
35
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error code system for Pikku CLI and Inspector
|
|
3
|
+
*
|
|
4
|
+
* Each error has a unique code and links to documentation at pikku.dev
|
|
5
|
+
*
|
|
6
|
+
* Error codes use random 3-digit numbers to avoid implying a sequential order.
|
|
7
|
+
* Each code links to detailed documentation and troubleshooting steps.
|
|
8
|
+
*/
|
|
9
|
+
export var ErrorCode;
|
|
10
|
+
(function (ErrorCode) {
|
|
11
|
+
// Validation errors
|
|
12
|
+
ErrorCode["MISSING_NAME"] = "PKU111";
|
|
13
|
+
ErrorCode["MISSING_DESCRIPTION"] = "PKU123";
|
|
14
|
+
ErrorCode["MISSING_URI"] = "PKU220";
|
|
15
|
+
ErrorCode["MISSING_FUNC"] = "PKU236";
|
|
16
|
+
ErrorCode["INVALID_TAGS_TYPE"] = "PKU247";
|
|
17
|
+
ErrorCode["INVALID_HANDLER"] = "PKU300";
|
|
18
|
+
ErrorCode["MISSING_TITLE"] = "PKU370";
|
|
19
|
+
ErrorCode["MISSING_QUEUE_NAME"] = "PKU384";
|
|
20
|
+
ErrorCode["MISSING_CHANNEL_NAME"] = "PKU400";
|
|
21
|
+
ErrorCode["CLI_CLIENTSIDE_RENDERER_HAS_SERVICES"] = "PKU672";
|
|
22
|
+
// Configuration errors
|
|
23
|
+
ErrorCode["CONFIG_TYPE_NOT_FOUND"] = "PKU426";
|
|
24
|
+
ErrorCode["CONFIG_TYPE_UNDEFINED"] = "PKU427";
|
|
25
|
+
ErrorCode["SCHEMA_NO_ROOT"] = "PKU431";
|
|
26
|
+
ErrorCode["SCHEMA_GENERATION_ERROR"] = "PKU456";
|
|
27
|
+
ErrorCode["SCHEMA_LOAD_ERROR"] = "PKU488";
|
|
28
|
+
// Function errors
|
|
29
|
+
ErrorCode["FUNCTION_METADATA_NOT_FOUND"] = "PKU559";
|
|
30
|
+
ErrorCode["HANDLER_NOT_RESOLVED"] = "PKU568";
|
|
31
|
+
// Middleware/Permission errors
|
|
32
|
+
ErrorCode["MIDDLEWARE_HANDLER_INVALID"] = "PKU685";
|
|
33
|
+
ErrorCode["MIDDLEWARE_TAG_INVALID"] = "PKU715";
|
|
34
|
+
ErrorCode["MIDDLEWARE_EMPTY_ARRAY"] = "PKU736";
|
|
35
|
+
ErrorCode["MIDDLEWARE_PATTERN_INVALID"] = "PKU787";
|
|
36
|
+
ErrorCode["PERMISSION_HANDLER_INVALID"] = "PKU835";
|
|
37
|
+
ErrorCode["PERMISSION_TAG_INVALID"] = "PKU836";
|
|
38
|
+
ErrorCode["PERMISSION_EMPTY_ARRAY"] = "PKU937";
|
|
39
|
+
ErrorCode["PERMISSION_PATTERN_INVALID"] = "PKU975";
|
|
40
|
+
})(ErrorCode || (ErrorCode = {}));
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export { inspect } from './inspector.js';
|
|
2
|
+
export { getFilesAndMethods } from './utils/get-files-and-methods.js';
|
|
2
3
|
export type { TypesMap } from './types-map.js';
|
|
3
4
|
export type * from './types.js';
|
|
4
5
|
export type { InspectorState } from './types.js';
|
|
6
|
+
export type { FilesAndMethods, FilesAndMethodsErrors, } from './utils/get-files-and-methods.js';
|
|
7
|
+
export { ErrorCode } from './error-codes.js';
|
|
8
|
+
export { serializeInspectorState, deserializeInspectorState, } from './utils/serialize-inspector-state.js';
|
|
9
|
+
export type { SerializableInspectorState } from './utils/serialize-inspector-state.js';
|
|
10
|
+
export { filterInspectorState } from './utils/filter-inspector-state.js';
|
package/dist/index.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
1
|
export { inspect } from './inspector.js';
|
|
2
|
+
export { getFilesAndMethods } from './utils/get-files-and-methods.js';
|
|
3
|
+
export { ErrorCode } from './error-codes.js';
|
|
4
|
+
export { serializeInspectorState, deserializeInspectorState, } from './utils/serialize-inspector-state.js';
|
|
5
|
+
export { filterInspectorState } from './utils/filter-inspector-state.js';
|
package/dist/inspector.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { InspectorState,
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const inspect: (logger: InspectorLogger, routeFiles: string[], filters: InspectorFilters) => InspectorState;
|
|
1
|
+
import { InspectorState, InspectorLogger, InspectorOptions } from './types.js';
|
|
2
|
+
export declare const inspect: (logger: InspectorLogger, routeFiles: string[], options?: InspectorOptions) => InspectorState;
|
package/dist/inspector.js
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
2
|
import { visitSetup, visitRoutes } from './visit.js';
|
|
3
3
|
import { TypesMap } from './types-map.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
export const inspect = (logger, routeFiles,
|
|
4
|
+
import { getFilesAndMethods } from './utils/get-files-and-methods.js';
|
|
5
|
+
import { findCommonAncestor } from './utils/find-root-dir.js';
|
|
6
|
+
import { aggregateRequiredServices } from './utils/post-process.js';
|
|
7
|
+
export const inspect = (logger, routeFiles, options = {}) => {
|
|
8
8
|
const program = ts.createProgram(routeFiles, {
|
|
9
9
|
target: ts.ScriptTarget.ESNext,
|
|
10
10
|
module: ts.ModuleKind.CommonJS,
|
|
11
11
|
});
|
|
12
12
|
const checker = program.getTypeChecker();
|
|
13
13
|
const sourceFiles = program.getSourceFiles();
|
|
14
|
+
// Infer root directory from source files
|
|
15
|
+
const rootDir = findCommonAncestor(routeFiles);
|
|
14
16
|
const state = {
|
|
17
|
+
rootDir,
|
|
15
18
|
singletonServicesTypeImportMap: new Map(),
|
|
16
19
|
sessionServicesTypeImportMap: new Map(),
|
|
17
20
|
userSessionTypeImportMap: new Map(),
|
|
21
|
+
configTypeImportMap: new Map(),
|
|
18
22
|
singletonServicesFactories: new Map(),
|
|
19
23
|
sessionServicesFactories: new Map(),
|
|
24
|
+
sessionServicesMeta: new Map(),
|
|
20
25
|
configFactories: new Map(),
|
|
26
|
+
filesAndMethods: {},
|
|
27
|
+
filesAndMethodsErrors: new Map(),
|
|
28
|
+
typesLookup: new Map(),
|
|
21
29
|
functions: {
|
|
22
30
|
typesMap: new TypesMap(),
|
|
23
31
|
meta: {},
|
|
32
|
+
files: new Map(),
|
|
24
33
|
},
|
|
25
34
|
http: {
|
|
26
35
|
metaInputTypes: new Map(),
|
|
@@ -34,6 +43,8 @@ export const inspect = (logger, routeFiles, filters) => {
|
|
|
34
43
|
options: {},
|
|
35
44
|
},
|
|
36
45
|
files: new Set(),
|
|
46
|
+
routeMiddleware: new Map(),
|
|
47
|
+
routePermissions: new Map(),
|
|
37
48
|
},
|
|
38
49
|
channels: {
|
|
39
50
|
files: new Set(),
|
|
@@ -60,22 +71,41 @@ export const inspect = (logger, routeFiles, filters) => {
|
|
|
60
71
|
promptsMeta: {},
|
|
61
72
|
files: new Set(),
|
|
62
73
|
},
|
|
74
|
+
cli: {
|
|
75
|
+
meta: {
|
|
76
|
+
programs: {},
|
|
77
|
+
renderers: {},
|
|
78
|
+
},
|
|
79
|
+
files: new Set(),
|
|
80
|
+
},
|
|
63
81
|
middleware: {
|
|
64
82
|
meta: {},
|
|
83
|
+
tagMiddleware: new Map(),
|
|
65
84
|
},
|
|
66
85
|
permissions: {
|
|
67
86
|
meta: {},
|
|
87
|
+
tagPermissions: new Map(),
|
|
88
|
+
},
|
|
89
|
+
serviceAggregation: {
|
|
90
|
+
requiredServices: new Set(),
|
|
91
|
+
usedFunctions: new Set(),
|
|
92
|
+
usedMiddleware: new Set(),
|
|
93
|
+
usedPermissions: new Set(),
|
|
68
94
|
},
|
|
69
95
|
};
|
|
70
96
|
// First sweep: add all functions
|
|
71
97
|
for (const sourceFile of sourceFiles) {
|
|
72
|
-
ts.forEachChild(sourceFile, (child) => visitSetup(checker, child, state,
|
|
98
|
+
ts.forEachChild(sourceFile, (child) => visitSetup(logger, checker, child, state, options));
|
|
73
99
|
}
|
|
74
100
|
// Second sweep: add all transports
|
|
75
101
|
for (const sourceFile of sourceFiles) {
|
|
76
|
-
ts.forEachChild(sourceFile, (child) => visitRoutes(checker, child, state,
|
|
102
|
+
ts.forEachChild(sourceFile, (child) => visitRoutes(logger, checker, child, state, options));
|
|
77
103
|
}
|
|
78
|
-
//
|
|
79
|
-
|
|
104
|
+
// Populate filesAndMethods
|
|
105
|
+
const { result, errors } = getFilesAndMethods(state, options.types);
|
|
106
|
+
state.filesAndMethods = result;
|
|
107
|
+
state.filesAndMethodsErrors = errors;
|
|
108
|
+
// Post-processing: Aggregate required services from wired functions/middleware/permissions
|
|
109
|
+
aggregateRequiredServices(state);
|
|
80
110
|
return state;
|
|
81
111
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
1
2
|
import { ChannelsMeta } from '@pikku/core/channel';
|
|
2
3
|
import { HTTPWiringsMeta } from '@pikku/core/http';
|
|
3
4
|
import { ScheduledTasksMeta } from '@pikku/core/scheduler';
|
|
4
5
|
import { queueWorkersMeta } from '@pikku/core/queue';
|
|
5
|
-
import { MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from '@pikku/core';
|
|
6
|
+
import { MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from '@pikku/core/mcp';
|
|
7
|
+
import { CLIMeta } from '@pikku/core/cli';
|
|
6
8
|
import { TypesMap } from './types-map.js';
|
|
7
9
|
import { FunctionsMeta, FunctionServicesMeta } from '@pikku/core';
|
|
10
|
+
import { ErrorCode } from './error-codes.js';
|
|
8
11
|
export type PathToNameAndType = Map<string, {
|
|
9
12
|
variable: string;
|
|
10
13
|
type: string | null;
|
|
@@ -15,14 +18,36 @@ export type MetaInputTypes = Map<string, {
|
|
|
15
18
|
params: string[] | undefined;
|
|
16
19
|
body: string[] | undefined;
|
|
17
20
|
}>;
|
|
21
|
+
export interface MiddlewareGroupMeta {
|
|
22
|
+
exportName: string | null;
|
|
23
|
+
sourceFile: string;
|
|
24
|
+
position: number;
|
|
25
|
+
services: FunctionServicesMeta;
|
|
26
|
+
middlewareCount: number;
|
|
27
|
+
isFactory: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface PermissionGroupMeta {
|
|
30
|
+
exportName: string | null;
|
|
31
|
+
sourceFile: string;
|
|
32
|
+
position: number;
|
|
33
|
+
services: FunctionServicesMeta;
|
|
34
|
+
permissionCount: number;
|
|
35
|
+
isFactory: boolean;
|
|
36
|
+
}
|
|
18
37
|
export interface InspectorHTTPState {
|
|
19
38
|
metaInputTypes: MetaInputTypes;
|
|
20
39
|
meta: HTTPWiringsMeta;
|
|
21
40
|
files: Set<string>;
|
|
41
|
+
routeMiddleware: Map<string, MiddlewareGroupMeta>;
|
|
42
|
+
routePermissions: Map<string, PermissionGroupMeta>;
|
|
22
43
|
}
|
|
23
44
|
export interface InspectorFunctionState {
|
|
24
45
|
typesMap: TypesMap;
|
|
25
46
|
meta: FunctionsMeta;
|
|
47
|
+
files: Map<string, {
|
|
48
|
+
path: string;
|
|
49
|
+
exportedName: string;
|
|
50
|
+
}>;
|
|
26
51
|
}
|
|
27
52
|
export interface InspectorChannelState {
|
|
28
53
|
meta: ChannelsMeta;
|
|
@@ -34,7 +59,11 @@ export interface InspectorMiddlewareState {
|
|
|
34
59
|
sourceFile: string;
|
|
35
60
|
position: number;
|
|
36
61
|
exportedName: string | null;
|
|
62
|
+
factory?: boolean;
|
|
63
|
+
name?: string;
|
|
64
|
+
description?: string;
|
|
37
65
|
}>;
|
|
66
|
+
tagMiddleware: Map<string, MiddlewareGroupMeta>;
|
|
38
67
|
}
|
|
39
68
|
export interface InspectorPermissionState {
|
|
40
69
|
meta: Record<string, {
|
|
@@ -42,26 +71,94 @@ export interface InspectorPermissionState {
|
|
|
42
71
|
sourceFile: string;
|
|
43
72
|
position: number;
|
|
44
73
|
exportedName: string | null;
|
|
74
|
+
factory?: boolean;
|
|
75
|
+
name?: string;
|
|
76
|
+
description?: string;
|
|
45
77
|
}>;
|
|
78
|
+
tagPermissions: Map<string, PermissionGroupMeta>;
|
|
46
79
|
}
|
|
47
80
|
export type InspectorFilters = {
|
|
81
|
+
names?: string[];
|
|
48
82
|
tags?: string[];
|
|
49
83
|
types?: string[];
|
|
50
84
|
directories?: string[];
|
|
85
|
+
httpRoutes?: string[];
|
|
86
|
+
httpMethods?: string[];
|
|
51
87
|
};
|
|
88
|
+
export type InspectorOptions = Partial<{
|
|
89
|
+
types: Partial<{
|
|
90
|
+
configFileType: string;
|
|
91
|
+
userSessionType: string;
|
|
92
|
+
singletonServicesFactoryType: string;
|
|
93
|
+
sessionServicesFactoryType: string;
|
|
94
|
+
}>;
|
|
95
|
+
}>;
|
|
52
96
|
export interface InspectorLogger {
|
|
53
97
|
info: (message: string) => void;
|
|
54
98
|
error: (message: string) => void;
|
|
55
99
|
warn: (message: string) => void;
|
|
56
100
|
debug: (message: string) => void;
|
|
101
|
+
critical: (code: ErrorCode, message: string) => void;
|
|
102
|
+
hasCriticalErrors: () => boolean;
|
|
103
|
+
}
|
|
104
|
+
export type AddWiring = (logger: InspectorLogger, node: ts.Node, checker: ts.TypeChecker, state: InspectorState, options: InspectorOptions) => void;
|
|
105
|
+
export interface InspectorFilesAndMethods {
|
|
106
|
+
userSessionType?: {
|
|
107
|
+
file: string;
|
|
108
|
+
variable: string;
|
|
109
|
+
type: string;
|
|
110
|
+
typePath: string;
|
|
111
|
+
};
|
|
112
|
+
sessionServicesType?: {
|
|
113
|
+
file: string;
|
|
114
|
+
variable: string;
|
|
115
|
+
type: string;
|
|
116
|
+
typePath: string;
|
|
117
|
+
};
|
|
118
|
+
singletonServicesType?: {
|
|
119
|
+
file: string;
|
|
120
|
+
variable: string;
|
|
121
|
+
type: string;
|
|
122
|
+
typePath: string;
|
|
123
|
+
};
|
|
124
|
+
pikkuConfigType?: {
|
|
125
|
+
file: string;
|
|
126
|
+
variable: string;
|
|
127
|
+
type: string;
|
|
128
|
+
typePath: string;
|
|
129
|
+
};
|
|
130
|
+
pikkuConfigFactory?: {
|
|
131
|
+
file: string;
|
|
132
|
+
variable: string;
|
|
133
|
+
type: string;
|
|
134
|
+
typePath: string;
|
|
135
|
+
};
|
|
136
|
+
singletonServicesFactory?: {
|
|
137
|
+
file: string;
|
|
138
|
+
variable: string;
|
|
139
|
+
type: string;
|
|
140
|
+
typePath: string;
|
|
141
|
+
};
|
|
142
|
+
sessionServicesFactory?: {
|
|
143
|
+
file: string;
|
|
144
|
+
variable: string;
|
|
145
|
+
type: string;
|
|
146
|
+
typePath: string;
|
|
147
|
+
};
|
|
57
148
|
}
|
|
58
149
|
export interface InspectorState {
|
|
150
|
+
rootDir: string;
|
|
59
151
|
singletonServicesTypeImportMap: PathToNameAndType;
|
|
60
152
|
sessionServicesTypeImportMap: PathToNameAndType;
|
|
61
153
|
userSessionTypeImportMap: PathToNameAndType;
|
|
154
|
+
configTypeImportMap: PathToNameAndType;
|
|
62
155
|
singletonServicesFactories: PathToNameAndType;
|
|
63
156
|
sessionServicesFactories: PathToNameAndType;
|
|
157
|
+
sessionServicesMeta: Map<string, string[]>;
|
|
64
158
|
configFactories: PathToNameAndType;
|
|
159
|
+
filesAndMethods: InspectorFilesAndMethods;
|
|
160
|
+
filesAndMethodsErrors: Map<string, PathToNameAndType>;
|
|
161
|
+
typesLookup: Map<string, ts.Type[]>;
|
|
65
162
|
http: InspectorHTTPState;
|
|
66
163
|
functions: InspectorFunctionState;
|
|
67
164
|
channels: InspectorChannelState;
|
|
@@ -92,6 +189,16 @@ export interface InspectorState {
|
|
|
92
189
|
promptsMeta: MCPPromptMeta;
|
|
93
190
|
files: Set<string>;
|
|
94
191
|
};
|
|
192
|
+
cli: {
|
|
193
|
+
meta: CLIMeta;
|
|
194
|
+
files: Set<string>;
|
|
195
|
+
};
|
|
95
196
|
middleware: InspectorMiddlewareState;
|
|
96
197
|
permissions: InspectorPermissionState;
|
|
198
|
+
serviceAggregation: {
|
|
199
|
+
requiredServices: Set<string>;
|
|
200
|
+
usedFunctions: Set<string>;
|
|
201
|
+
usedMiddleware: Set<string>;
|
|
202
|
+
usedPermissions: Set<string>;
|
|
203
|
+
};
|
|
97
204
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InspectorState } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that function metadata exists for a given pikkuFuncName.
|
|
4
|
+
* Creates stub metadata if it doesn't exist (useful for inline functions).
|
|
5
|
+
*/
|
|
6
|
+
export declare function ensureFunctionMetadata(state: InspectorState, pikkuFuncName: string, fallbackName?: string): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensures that function metadata exists for a given pikkuFuncName.
|
|
3
|
+
* Creates stub metadata if it doesn't exist (useful for inline functions).
|
|
4
|
+
*/
|
|
5
|
+
export function ensureFunctionMetadata(state, pikkuFuncName, fallbackName) {
|
|
6
|
+
if (!state.functions.meta[pikkuFuncName]) {
|
|
7
|
+
state.functions.meta[pikkuFuncName] = {
|
|
8
|
+
pikkuFuncName,
|
|
9
|
+
name: fallbackName || pikkuFuncName,
|
|
10
|
+
services: { optimized: false, services: [] },
|
|
11
|
+
inputSchemaName: null,
|
|
12
|
+
outputSchemaName: null,
|
|
13
|
+
inputs: [],
|
|
14
|
+
outputs: [],
|
|
15
|
+
middleware: undefined,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
export type ExtractedFunctionName = {
|
|
3
|
+
pikkuFuncName: string;
|
|
4
|
+
name: string;
|
|
5
|
+
explicitName: string | null;
|
|
6
|
+
exportedName: string | null;
|
|
7
|
+
localName: string | null;
|
|
8
|
+
propertyName: string | null;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Generate a deterministic "anonymous" name for any expression node,
|
|
12
|
+
* but if it's an Identifier pointing to a function, resolve it back
|
|
13
|
+
* to the function's declaration (so you get the true source location).
|
|
14
|
+
*/
|
|
15
|
+
export declare function makeDeterministicAnonName(start: ts.Node, checker: ts.TypeChecker, rootDir: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Updated function to extract and prioritize function names correctly
|
|
18
|
+
* This function follows the priority:
|
|
19
|
+
* 1. Object with a name property
|
|
20
|
+
* 2. Exported name
|
|
21
|
+
* 3. Fallback to deterministic name
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractFunctionName(callExpr: ts.Node, checker: ts.TypeChecker, rootDir: string): ExtractedFunctionName;
|
|
24
|
+
/**
|
|
25
|
+
* Helper function to populate the 'name' field based on priority
|
|
26
|
+
*/
|
|
27
|
+
export declare function populateNameByPriority(result: ExtractedFunctionName): void;
|
|
28
|
+
/**
|
|
29
|
+
* Helper function to check if a variable declaration is a named export
|
|
30
|
+
*/
|
|
31
|
+
export declare function isNamedExport(declaration: ts.VariableDeclaration): boolean;
|