@pikku/core 0.11.0 → 0.11.2
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 +35 -1
- package/dist/errors/error-handler.js +3 -3
- package/dist/errors/errors.d.ts +1 -1
- package/dist/errors/errors.js +3 -3
- package/dist/function/function-runner.d.ts +8 -8
- package/dist/function/function-runner.js +88 -23
- package/dist/function/functions.types.d.ts +104 -33
- package/dist/function/functions.types.js +50 -7
- package/dist/handle-error.d.ts +1 -1
- package/dist/handle-error.js +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +5 -2
- package/dist/middleware/auth-apikey.d.ts +1 -1
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +1 -1
- package/dist/middleware/auth-bearer.js +3 -3
- package/dist/middleware/auth-cookie.d.ts +1 -1
- package/dist/middleware/auth-cookie.js +5 -5
- package/dist/middleware/timeout.d.ts +1 -1
- package/dist/middleware/timeout.js +3 -2
- package/dist/middleware-runner.d.ts +6 -20
- package/dist/middleware-runner.js +19 -20
- package/dist/permissions.d.ts +6 -89
- package/dist/permissions.js +24 -81
- package/dist/pikku-state.d.ts +32 -104
- package/dist/pikku-state.js +140 -66
- package/dist/schema.d.ts +8 -6
- package/dist/schema.js +25 -13
- package/dist/services/user-session-service.d.ts +7 -3
- package/dist/services/user-session-service.js +8 -1
- package/dist/services/workflow-service.d.ts +38 -0
- package/dist/services/workflow-service.js +1 -0
- package/dist/types/core.types.d.ts +40 -41
- package/dist/types/core.types.js +4 -15
- package/dist/types/state.types.d.ts +135 -0
- package/dist/types/state.types.js +1 -0
- package/dist/utils.d.ts +9 -1
- package/dist/utils.js +48 -3
- package/dist/wirings/channel/channel-common.js +2 -3
- package/dist/wirings/channel/channel-handler.d.ts +3 -2
- package/dist/wirings/channel/channel-handler.js +7 -10
- package/dist/wirings/channel/channel-runner.d.ts +2 -2
- package/dist/wirings/channel/channel-runner.js +5 -5
- package/dist/wirings/channel/channel.types.d.ts +10 -5
- package/dist/wirings/channel/local/local-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/local/local-channel-runner.js +19 -26
- package/dist/wirings/channel/log-channels.js +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +43 -48
- package/dist/wirings/cli/channel/cli-channel-runner.js +3 -2
- package/dist/wirings/cli/cli-runner.d.ts +5 -5
- package/dist/wirings/cli/cli-runner.js +20 -38
- package/dist/wirings/cli/cli.types.d.ts +16 -11
- package/dist/wirings/forge-node/forge-node.types.d.ts +120 -0
- package/dist/wirings/forge-node/forge-node.types.js +38 -0
- package/dist/wirings/forge-node/index.d.ts +1 -0
- package/dist/wirings/forge-node/index.js +1 -0
- package/dist/wirings/http/http-runner.d.ts +8 -8
- package/dist/wirings/http/http-runner.js +46 -51
- package/dist/wirings/http/http.types.d.ts +19 -11
- package/dist/wirings/http/log-http-routes.js +1 -1
- package/dist/wirings/http/routers/path-to-regex.js +2 -2
- package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
- package/dist/wirings/mcp/mcp-runner.js +33 -40
- package/dist/wirings/mcp/mcp.types.d.ts +6 -0
- package/dist/wirings/queue/queue-runner.d.ts +3 -3
- package/dist/wirings/queue/queue-runner.js +13 -23
- package/dist/wirings/queue/queue.types.d.ts +4 -11
- package/dist/wirings/rpc/index.d.ts +1 -1
- package/dist/wirings/rpc/index.js +1 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +17 -16
- package/dist/wirings/rpc/rpc-runner.js +98 -61
- package/dist/wirings/rpc/rpc-types.d.ts +7 -0
- package/dist/wirings/scheduler/log-schedulers.js +1 -1
- package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
- package/dist/wirings/scheduler/scheduler-runner.js +18 -29
- package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
- package/dist/wirings/trigger/index.d.ts +2 -0
- package/dist/wirings/trigger/index.js +2 -0
- package/dist/wirings/trigger/trigger-runner.d.ts +29 -0
- package/dist/wirings/trigger/trigger-runner.js +57 -0
- package/dist/wirings/trigger/trigger.types.d.ts +42 -0
- package/dist/wirings/trigger/trigger.types.js +1 -0
- package/dist/wirings/workflow/dsl/index.d.ts +5 -0
- package/dist/wirings/workflow/dsl/index.js +4 -0
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +286 -0
- package/dist/wirings/workflow/dsl/workflow-dsl.types.js +5 -0
- package/dist/wirings/workflow/dsl/workflow-runner.d.ts +5 -0
- package/dist/wirings/workflow/dsl/workflow-runner.js +22 -0
- package/dist/wirings/workflow/graph/graph-node.d.ts +122 -0
- package/dist/wirings/workflow/graph/graph-node.js +58 -0
- package/dist/wirings/workflow/graph/graph-runner.d.ts +35 -0
- package/dist/wirings/workflow/graph/graph-runner.js +452 -0
- package/dist/wirings/workflow/graph/index.d.ts +3 -0
- package/dist/wirings/workflow/graph/index.js +3 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +95 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.js +15 -0
- package/dist/wirings/workflow/index.d.ts +7 -3
- package/dist/wirings/workflow/index.js +6 -3
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +108 -10
- package/dist/wirings/workflow/pikku-workflow-service.js +274 -165
- package/dist/wirings/workflow/wire-workflow.d.ts +42 -0
- package/dist/wirings/workflow/wire-workflow.js +53 -0
- package/dist/wirings/workflow/workflow-utils.d.ts +23 -0
- package/dist/wirings/workflow/workflow-utils.js +66 -0
- package/dist/wirings/workflow/workflow.types.d.ts +135 -128
- package/package.json +11 -2
- package/src/errors/error-handler.ts +3 -3
- package/src/errors/errors.ts +3 -3
- package/src/factory-functions.test.ts +9 -36
- package/src/function/function-runner.test.ts +58 -69
- package/src/function/function-runner.ts +130 -37
- package/src/function/functions.types.ts +193 -54
- package/src/handle-error.ts +1 -1
- package/src/index.ts +10 -5
- package/src/middleware/auth-apikey.test.ts +360 -0
- package/src/middleware/auth-apikey.ts +3 -7
- package/src/middleware/auth-bearer.test.ts +447 -0
- package/src/middleware/auth-bearer.ts +27 -33
- package/src/middleware/auth-cookie.test.ts +525 -0
- package/src/middleware/auth-cookie.ts +6 -6
- package/src/middleware/timeout.ts +4 -2
- package/src/middleware-runner.test.ts +58 -127
- package/src/middleware-runner.ts +29 -25
- package/src/permissions.test.ts +68 -130
- package/src/permissions.ts +41 -100
- package/src/pikku-state.ts +156 -201
- package/src/schema.ts +42 -13
- package/src/services/user-session-service.ts +14 -4
- package/src/services/workflow-service.ts +74 -0
- package/src/types/core.types.ts +79 -58
- package/src/types/state.types.ts +195 -0
- package/src/utils.ts +59 -4
- package/src/wirings/channel/channel-common.ts +4 -7
- package/src/wirings/channel/channel-handler.ts +17 -23
- package/src/wirings/channel/channel-runner.ts +7 -7
- package/src/wirings/channel/channel.types.ts +14 -11
- package/src/wirings/channel/local/local-channel-runner.test.ts +8 -4
- package/src/wirings/channel/local/local-channel-runner.ts +23 -38
- package/src/wirings/channel/log-channels.ts +1 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +53 -79
- package/src/wirings/cli/channel/cli-channel-runner.ts +4 -3
- package/src/wirings/cli/cli-runner.test.ts +26 -26
- package/src/wirings/cli/cli-runner.ts +34 -71
- package/src/wirings/cli/cli.types.ts +23 -16
- package/src/wirings/forge-node/forge-node.types.ts +135 -0
- package/src/wirings/forge-node/index.ts +1 -0
- package/src/wirings/http/http-runner.test.ts +10 -10
- package/src/wirings/http/http-runner.ts +56 -66
- package/src/wirings/http/http.types.ts +19 -14
- package/src/wirings/http/log-http-routes.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.test.ts +30 -19
- package/src/wirings/http/routers/path-to-regex.ts +2 -2
- package/src/wirings/mcp/mcp-runner.ts +44 -69
- package/src/wirings/mcp/mcp.types.ts +6 -0
- package/src/wirings/queue/queue-runner.test.ts +641 -0
- package/src/wirings/queue/queue-runner.ts +16 -38
- package/src/wirings/queue/queue.types.ts +4 -11
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +129 -77
- package/src/wirings/rpc/rpc-types.ts +8 -0
- package/src/wirings/scheduler/log-schedulers.ts +1 -1
- package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
- package/src/wirings/scheduler/scheduler-runner.ts +29 -55
- package/src/wirings/scheduler/scheduler.types.ts +3 -9
- package/src/wirings/trigger/index.ts +2 -0
- package/src/wirings/trigger/trigger-runner.ts +96 -0
- package/src/wirings/trigger/trigger.types.ts +56 -0
- package/src/wirings/workflow/dsl/index.ts +30 -0
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +312 -0
- package/src/wirings/workflow/dsl/workflow-runner.ts +27 -0
- package/src/wirings/workflow/graph/graph-node.ts +227 -0
- package/src/wirings/workflow/graph/graph-runner.ts +694 -0
- package/src/wirings/workflow/graph/index.ts +3 -0
- package/src/wirings/workflow/graph/workflow-graph.types.ts +126 -0
- package/src/wirings/workflow/index.ts +60 -12
- package/src/wirings/workflow/pikku-workflow-service.ts +401 -195
- package/src/wirings/workflow/wire-workflow.ts +94 -0
- package/src/wirings/workflow/workflow-utils.ts +120 -0
- package/src/wirings/workflow/workflow.types.ts +167 -188
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/wirings/workflow/workflow-runner.d.ts +0 -35
- package/dist/wirings/workflow/workflow-runner.js +0 -68
- package/src/wirings/workflow/workflow-runner.ts +0 -85
package/dist/pikku-state.d.ts
CHANGED
|
@@ -1,106 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { CoreScheduledTask, ScheduledTasksMeta } from './wirings/scheduler/scheduler.types.js';
|
|
5
|
-
import { ErrorDetails, PikkuError } from './errors/error-handler.js';
|
|
6
|
-
import { CorePermissionGroup, CorePikkuFunctionConfig, CorePikkuPermission } from './function/functions.types.js';
|
|
7
|
-
import { QueueWorkersMeta, CoreQueueWorker } from './wirings/queue/queue.types.js';
|
|
8
|
-
import { CoreMCPResource, CoreMCPTool, CoreMCPPrompt, MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from './wirings/mcp/mcp.types.js';
|
|
9
|
-
import { CLIMeta, CLIProgramState } from './wirings/cli/cli.types.js';
|
|
10
|
-
import { CoreWorkflow, WorkflowsMeta } from './wirings/workflow/workflow.types.js';
|
|
11
|
-
interface PikkuState {
|
|
12
|
-
function: {
|
|
13
|
-
meta: FunctionsMeta;
|
|
14
|
-
functions: Map<string, CorePikkuFunctionConfig<any, any>>;
|
|
15
|
-
};
|
|
16
|
-
rpc: {
|
|
17
|
-
meta: Record<string, string>;
|
|
18
|
-
files: Map<string, {
|
|
19
|
-
exportedName: string;
|
|
20
|
-
path: string;
|
|
21
|
-
}>;
|
|
22
|
-
};
|
|
23
|
-
http: {
|
|
24
|
-
middleware: Map<string, CorePikkuMiddleware<any, any>[]>;
|
|
25
|
-
permissions: Map<string, CorePermissionGroup | CorePikkuPermission[]>;
|
|
26
|
-
routes: Map<HTTPMethod, Map<string, CoreHTTPFunctionWiring<any, any, any>>>;
|
|
27
|
-
meta: HTTPWiringsMeta;
|
|
28
|
-
};
|
|
29
|
-
channel: {
|
|
30
|
-
channels: Map<string, CoreChannel<any, any>>;
|
|
31
|
-
meta: ChannelsMeta;
|
|
32
|
-
};
|
|
33
|
-
scheduler: {
|
|
34
|
-
tasks: Map<string, CoreScheduledTask>;
|
|
35
|
-
meta: ScheduledTasksMeta;
|
|
36
|
-
};
|
|
37
|
-
queue: {
|
|
38
|
-
registrations: Map<string, CoreQueueWorker>;
|
|
39
|
-
meta: QueueWorkersMeta;
|
|
40
|
-
};
|
|
41
|
-
workflows: {
|
|
42
|
-
registrations: Map<string, CoreWorkflow>;
|
|
43
|
-
meta: WorkflowsMeta;
|
|
44
|
-
};
|
|
45
|
-
mcp: {
|
|
46
|
-
resources: Map<string, CoreMCPResource>;
|
|
47
|
-
resourcesMeta: MCPResourceMeta;
|
|
48
|
-
tools: Map<string, CoreMCPTool>;
|
|
49
|
-
toolsMeta: MCPToolMeta;
|
|
50
|
-
prompts: Map<string, CoreMCPPrompt>;
|
|
51
|
-
promptsMeta: MCPPromptMeta;
|
|
52
|
-
};
|
|
53
|
-
cli: {
|
|
54
|
-
meta: CLIMeta | Record<string, any>;
|
|
55
|
-
programs: Record<string, CLIProgramState>;
|
|
56
|
-
};
|
|
57
|
-
middleware: {
|
|
58
|
-
tagGroup: Record<string, CorePikkuMiddlewareGroup>;
|
|
59
|
-
httpGroup: Record<string, CorePikkuMiddlewareGroup>;
|
|
60
|
-
tagGroupMeta: Record<string, {
|
|
61
|
-
exportName: string | null;
|
|
62
|
-
sourceFile: string;
|
|
63
|
-
position: number;
|
|
64
|
-
services: FunctionServicesMeta;
|
|
65
|
-
middlewareCount: number;
|
|
66
|
-
isFactory: boolean;
|
|
67
|
-
}>;
|
|
68
|
-
httpGroupMeta: Record<string, {
|
|
69
|
-
exportName: string | null;
|
|
70
|
-
sourceFile: string;
|
|
71
|
-
position: number;
|
|
72
|
-
services: FunctionServicesMeta;
|
|
73
|
-
middlewareCount: number;
|
|
74
|
-
isFactory: boolean;
|
|
75
|
-
}>;
|
|
76
|
-
};
|
|
77
|
-
permissions: {
|
|
78
|
-
tagGroup: Record<string, CorePermissionGroup | CorePikkuPermission[]>;
|
|
79
|
-
httpGroup: Record<string, CorePermissionGroup | CorePikkuPermission[]>;
|
|
80
|
-
tagGroupMeta: Record<string, {
|
|
81
|
-
exportName: string | null;
|
|
82
|
-
sourceFile: string;
|
|
83
|
-
position: number;
|
|
84
|
-
services: FunctionServicesMeta;
|
|
85
|
-
permissionCount: number;
|
|
86
|
-
isFactory: boolean;
|
|
87
|
-
}>;
|
|
88
|
-
httpGroupMeta: Record<string, {
|
|
89
|
-
exportName: string | null;
|
|
90
|
-
sourceFile: string;
|
|
91
|
-
position: number;
|
|
92
|
-
services: FunctionServicesMeta;
|
|
93
|
-
permissionCount: number;
|
|
94
|
-
isFactory: boolean;
|
|
95
|
-
}>;
|
|
96
|
-
};
|
|
97
|
-
misc: {
|
|
98
|
-
errors: Map<PikkuError, ErrorDetails>;
|
|
99
|
-
schemas: Map<string, any>;
|
|
100
|
-
middleware: Record<string, CorePikkuMiddleware[]>;
|
|
101
|
-
permissions: Record<string, CorePermissionGroup | CorePikkuPermission[]>;
|
|
102
|
-
};
|
|
1
|
+
import { PikkuPackageState } from './index.js';
|
|
2
|
+
declare global {
|
|
3
|
+
var pikkuState: Map<string, PikkuPackageState> | undefined;
|
|
103
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* Get or set package-scoped pikku state
|
|
7
|
+
*
|
|
8
|
+
* @param packageName - Package name (null for main package, '@scope/package' for external packages)
|
|
9
|
+
* @param type - State category (function, rpc, http, etc.)
|
|
10
|
+
* @param content - Content key within the category
|
|
11
|
+
* @param value - Optional value to set
|
|
12
|
+
* @returns The current value of the state
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Main package
|
|
16
|
+
* pikkuState(null, 'function', 'functions').get(funcName)
|
|
17
|
+
*
|
|
18
|
+
* // External package
|
|
19
|
+
* pikkuState('@acme/stripe-functions', 'rpc', 'meta')
|
|
20
|
+
*/
|
|
21
|
+
export declare const pikkuState: <Type extends keyof PikkuPackageState, Content extends keyof PikkuPackageState[Type]>(packageName: string | null, type: Type, content: Content, value?: PikkuPackageState[Type][Content]) => PikkuPackageState[Type][Content];
|
|
22
|
+
/**
|
|
23
|
+
* Initialize state for a new package
|
|
24
|
+
*/
|
|
25
|
+
export declare const initializePikkuState: (packageName: string) => void;
|
|
104
26
|
export declare const resetPikkuState: () => void;
|
|
105
|
-
|
|
106
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Register service factories for an external package.
|
|
29
|
+
* These factories are used to create services when the package's functions are invoked.
|
|
30
|
+
*
|
|
31
|
+
* @param packageName - The package name (e.g., '@pikku/templates-function-external')
|
|
32
|
+
* @param factories - The service factory functions
|
|
33
|
+
*/
|
|
34
|
+
export declare const addPackageServiceFactories: (packageName: string, factories: NonNullable<PikkuPackageState["package"]["factories"]>) => void;
|
package/dist/pikku-state.js
CHANGED
|
@@ -1,72 +1,146 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
httpGroup: {},
|
|
53
|
-
tagGroupMeta: {},
|
|
54
|
-
httpGroupMeta: {},
|
|
55
|
-
},
|
|
56
|
-
misc: {
|
|
57
|
-
errors: globalThis.pikkuState?.misc?.errors || new Map(),
|
|
58
|
-
schemas: new Map(),
|
|
59
|
-
middleware: {},
|
|
60
|
-
permissions: {},
|
|
1
|
+
/**
|
|
2
|
+
* Get or set package-scoped pikku state
|
|
3
|
+
*
|
|
4
|
+
* @param packageName - Package name (null for main package, '@scope/package' for external packages)
|
|
5
|
+
* @param type - State category (function, rpc, http, etc.)
|
|
6
|
+
* @param content - Content key within the category
|
|
7
|
+
* @param value - Optional value to set
|
|
8
|
+
* @returns The current value of the state
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Main package
|
|
12
|
+
* pikkuState(null, 'function', 'functions').get(funcName)
|
|
13
|
+
*
|
|
14
|
+
* // External package
|
|
15
|
+
* pikkuState('@acme/stripe-functions', 'rpc', 'meta')
|
|
16
|
+
*/
|
|
17
|
+
export const pikkuState = (packageName, type, content, value) => {
|
|
18
|
+
const resolvedPackageName = packageName ?? '__main__';
|
|
19
|
+
// Initialize package state if it doesn't exist
|
|
20
|
+
if (!globalThis.pikkuState ||
|
|
21
|
+
!globalThis.pikkuState.has(resolvedPackageName)) {
|
|
22
|
+
initializePikkuState(resolvedPackageName);
|
|
23
|
+
}
|
|
24
|
+
const packageState = globalThis.pikkuState.get(resolvedPackageName);
|
|
25
|
+
if (value !== undefined) {
|
|
26
|
+
packageState[type][content] = value;
|
|
27
|
+
}
|
|
28
|
+
return packageState[type][content];
|
|
29
|
+
};
|
|
30
|
+
const createEmptyPackageState = () => ({
|
|
31
|
+
function: {
|
|
32
|
+
meta: {},
|
|
33
|
+
functions: new Map(),
|
|
34
|
+
},
|
|
35
|
+
rpc: {
|
|
36
|
+
meta: {},
|
|
37
|
+
files: new Map(),
|
|
38
|
+
externalPackages: new Map(),
|
|
39
|
+
},
|
|
40
|
+
http: {
|
|
41
|
+
middleware: new Map(),
|
|
42
|
+
permissions: new Map(),
|
|
43
|
+
routes: new Map(),
|
|
44
|
+
meta: {
|
|
45
|
+
post: {},
|
|
46
|
+
get: {},
|
|
47
|
+
delete: {},
|
|
48
|
+
patch: {},
|
|
49
|
+
head: {},
|
|
50
|
+
put: {},
|
|
51
|
+
options: {},
|
|
61
52
|
},
|
|
62
|
-
}
|
|
53
|
+
},
|
|
54
|
+
channel: {
|
|
55
|
+
channels: new Map(),
|
|
56
|
+
meta: {},
|
|
57
|
+
},
|
|
58
|
+
scheduler: {
|
|
59
|
+
tasks: new Map(),
|
|
60
|
+
meta: [],
|
|
61
|
+
},
|
|
62
|
+
queue: {
|
|
63
|
+
registrations: new Map(),
|
|
64
|
+
meta: {},
|
|
65
|
+
},
|
|
66
|
+
workflows: {
|
|
67
|
+
registrations: new Map(),
|
|
68
|
+
graphRegistrations: new Map(),
|
|
69
|
+
wirings: new Map(),
|
|
70
|
+
graphWirings: new Map(),
|
|
71
|
+
meta: {},
|
|
72
|
+
},
|
|
73
|
+
trigger: {
|
|
74
|
+
triggers: new Map(),
|
|
75
|
+
meta: {},
|
|
76
|
+
},
|
|
77
|
+
mcp: {
|
|
78
|
+
resources: new Map(),
|
|
79
|
+
resourcesMeta: {},
|
|
80
|
+
tools: new Map(),
|
|
81
|
+
toolsMeta: {},
|
|
82
|
+
prompts: new Map(),
|
|
83
|
+
promptsMeta: {},
|
|
84
|
+
},
|
|
85
|
+
cli: {
|
|
86
|
+
meta: { programs: {}, renderers: {} },
|
|
87
|
+
programs: {},
|
|
88
|
+
},
|
|
89
|
+
middleware: {
|
|
90
|
+
tagGroup: {},
|
|
91
|
+
httpGroup: {},
|
|
92
|
+
tagGroupMeta: {},
|
|
93
|
+
httpGroupMeta: {},
|
|
94
|
+
},
|
|
95
|
+
permissions: {
|
|
96
|
+
tagGroup: {},
|
|
97
|
+
httpGroup: {},
|
|
98
|
+
tagGroupMeta: {},
|
|
99
|
+
httpGroupMeta: {},
|
|
100
|
+
},
|
|
101
|
+
misc: {
|
|
102
|
+
errors: new Map(),
|
|
103
|
+
schemas: new Map(),
|
|
104
|
+
middleware: {},
|
|
105
|
+
permissions: {},
|
|
106
|
+
},
|
|
107
|
+
package: {
|
|
108
|
+
factories: null,
|
|
109
|
+
singletonServices: null,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* Initialize state for a new package
|
|
114
|
+
*/
|
|
115
|
+
export const initializePikkuState = (packageName) => {
|
|
116
|
+
if (!globalThis.pikkuState) {
|
|
117
|
+
globalThis.pikkuState = new Map();
|
|
118
|
+
}
|
|
119
|
+
if (!globalThis.pikkuState.has(packageName)) {
|
|
120
|
+
globalThis.pikkuState.set(packageName, createEmptyPackageState());
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
export const resetPikkuState = () => {
|
|
124
|
+
// Preserve the errors map before resetting
|
|
125
|
+
const existingErrors = globalThis.pikkuState?.get('__main__')?.misc.errors;
|
|
126
|
+
globalThis.pikkuState = new Map();
|
|
127
|
+
initializePikkuState('__main__');
|
|
128
|
+
// Restore the errors map if it existed
|
|
129
|
+
if (existingErrors) {
|
|
130
|
+
const mainState = globalThis.pikkuState.get('__main__');
|
|
131
|
+
mainState.misc.errors = existingErrors;
|
|
132
|
+
}
|
|
63
133
|
};
|
|
64
134
|
if (!globalThis.pikkuState) {
|
|
65
135
|
resetPikkuState();
|
|
66
136
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Register service factories for an external package.
|
|
139
|
+
* These factories are used to create services when the package's functions are invoked.
|
|
140
|
+
*
|
|
141
|
+
* @param packageName - The package name (e.g., '@pikku/templates-function-external')
|
|
142
|
+
* @param factories - The service factory functions
|
|
143
|
+
*/
|
|
144
|
+
export const addPackageServiceFactories = (packageName, factories) => {
|
|
145
|
+
pikkuState(packageName, 'package', 'factories', factories);
|
|
72
146
|
};
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import { Logger } from './services/logger.js';
|
|
2
2
|
import { SchemaService } from './services/schema-service.js';
|
|
3
3
|
/**
|
|
4
|
-
* Adds a schema to the
|
|
4
|
+
* Adds a schema to the schemas map for a specific package.
|
|
5
5
|
* @param name - The name of the schema.
|
|
6
6
|
* @param value - The schema value.
|
|
7
|
+
* @param packageName - The package name (null for main package, '@scope/package' for external packages).
|
|
7
8
|
* @ignore
|
|
8
9
|
*/
|
|
9
|
-
export declare const addSchema: (name: string, value: any) => void;
|
|
10
|
+
export declare const addSchema: (name: string, value: any, packageName?: string | null) => void;
|
|
10
11
|
/**
|
|
11
|
-
* Retrieves a schema from the
|
|
12
|
+
* Retrieves a schema from the schemas map for a specific package.
|
|
12
13
|
* @param name - The name of the schema.
|
|
14
|
+
* @param packageName - The package name (null for main package, '@scope/package' for external packages).
|
|
13
15
|
* @returns The schema value or undefined if not found.
|
|
14
16
|
* @ignore
|
|
15
17
|
*/
|
|
16
|
-
export declare const getSchema: (name: string) => Record<string, unknown> | undefined;
|
|
18
|
+
export declare const getSchema: (name: string, packageName?: string | null) => Record<string, unknown> | undefined;
|
|
17
19
|
/**
|
|
18
20
|
* Loads a schema and compiles it into a validator.
|
|
19
21
|
* @param logger - A logger for logging information.
|
|
20
22
|
*/
|
|
21
23
|
export declare const compileAllSchemas: (logger: Logger, schemaService?: SchemaService) => void;
|
|
22
|
-
export declare const coerceTopLevelDataFromSchema: (schemaName: string, data: any) => void;
|
|
23
|
-
export declare const validateSchema: (logger: Logger, schemaService: SchemaService | undefined, schemaName: string | undefined | null, data: any) => Promise<void>;
|
|
24
|
+
export declare const coerceTopLevelDataFromSchema: (schemaName: string, data: any, packageName?: string | null) => void;
|
|
25
|
+
export declare const validateSchema: (logger: Logger, schemaService: SchemaService | undefined, schemaName: string | undefined | null, data: any, packageName?: string | null) => Promise<void>;
|
package/dist/schema.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { UnprocessableContentError } from './errors/errors.js';
|
|
2
2
|
import { pikkuState } from './pikku-state.js';
|
|
3
3
|
/**
|
|
4
|
-
* Adds a schema to the
|
|
4
|
+
* Adds a schema to the schemas map for a specific package.
|
|
5
5
|
* @param name - The name of the schema.
|
|
6
6
|
* @param value - The schema value.
|
|
7
|
+
* @param packageName - The package name (null for main package, '@scope/package' for external packages).
|
|
7
8
|
* @ignore
|
|
8
9
|
*/
|
|
9
|
-
export const addSchema = (name, value) => {
|
|
10
|
-
pikkuState('misc', 'schemas').set(name, value);
|
|
10
|
+
export const addSchema = (name, value, packageName = null) => {
|
|
11
|
+
pikkuState(packageName, 'misc', 'schemas').set(name, value);
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
|
-
* Retrieves a schema from the
|
|
14
|
+
* Retrieves a schema from the schemas map for a specific package.
|
|
14
15
|
* @param name - The name of the schema.
|
|
16
|
+
* @param packageName - The package name (null for main package, '@scope/package' for external packages).
|
|
15
17
|
* @returns The schema value or undefined if not found.
|
|
16
18
|
* @ignore
|
|
17
19
|
*/
|
|
18
|
-
export const getSchema = (name) => {
|
|
19
|
-
return pikkuState('misc', 'schemas').get(name);
|
|
20
|
+
export const getSchema = (name, packageName = null) => {
|
|
21
|
+
return pikkuState(packageName, 'misc', 'schemas').get(name);
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* Loads a schema and compiles it into a validator.
|
|
@@ -26,19 +28,20 @@ export const compileAllSchemas = (logger, schemaService) => {
|
|
|
26
28
|
if (!schemaService) {
|
|
27
29
|
throw new Error('SchemaService needs to be defined to load schemas');
|
|
28
30
|
}
|
|
29
|
-
const schemas = pikkuState('misc', 'schemas');
|
|
31
|
+
const schemas = pikkuState(null, 'misc', 'schemas');
|
|
30
32
|
for (const [name, schema] of schemas) {
|
|
31
33
|
schemaService.compileSchema(name, schema);
|
|
32
34
|
}
|
|
33
35
|
validateAllSchemasLoaded(logger, schemaService);
|
|
34
36
|
};
|
|
35
37
|
const validateAllSchemasLoaded = (logger, schemaService) => {
|
|
36
|
-
const routesMeta = pikkuState('http', 'meta');
|
|
38
|
+
const routesMeta = pikkuState(null, 'http', 'meta');
|
|
37
39
|
const validators = schemaService.getSchemaNames();
|
|
38
40
|
const missingSchemas = [];
|
|
39
41
|
for (const routePaths of Object.values(routesMeta)) {
|
|
40
42
|
for (const meta of Object.values(routePaths)) {
|
|
41
|
-
const inputs = pikkuState('function', 'meta')[meta.pikkuFuncName]
|
|
43
|
+
const inputs = pikkuState(null, 'function', 'meta')[meta.pikkuFuncName]
|
|
44
|
+
?.inputs;
|
|
42
45
|
const input = inputs?.[0];
|
|
43
46
|
if (!input || validators.has(input)) {
|
|
44
47
|
continue;
|
|
@@ -55,8 +58,8 @@ const validateAllSchemasLoaded = (logger, schemaService) => {
|
|
|
55
58
|
logger.info('All schemas loaded');
|
|
56
59
|
}
|
|
57
60
|
};
|
|
58
|
-
export const coerceTopLevelDataFromSchema = (schemaName, data) => {
|
|
59
|
-
const schema = pikkuState('misc', 'schemas').get(schemaName);
|
|
61
|
+
export const coerceTopLevelDataFromSchema = (schemaName, data, packageName = null) => {
|
|
62
|
+
const schema = pikkuState(packageName, 'misc', 'schemas').get(schemaName);
|
|
60
63
|
for (const key in schema.properties) {
|
|
61
64
|
const property = schema.properties[key];
|
|
62
65
|
if (typeof property === 'boolean') {
|
|
@@ -74,7 +77,7 @@ export const coerceTopLevelDataFromSchema = (schemaName, data) => {
|
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
};
|
|
77
|
-
export const validateSchema = async (logger, schemaService, schemaName, data) => {
|
|
80
|
+
export const validateSchema = async (logger, schemaService, schemaName, data, packageName = null) => {
|
|
78
81
|
if (schemaService) {
|
|
79
82
|
if (!schemaName) {
|
|
80
83
|
if (data && (data.length > 0 || Object.keys(data).length > 0)) {
|
|
@@ -85,7 +88,16 @@ export const validateSchema = async (logger, schemaService, schemaName, data) =>
|
|
|
85
88
|
return;
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
|
-
|
|
91
|
+
logger.debug(`[validateSchema] Validating schema '${schemaName}' for package '${packageName ?? 'main'}' with data:`, JSON.stringify(data));
|
|
92
|
+
const schemas = pikkuState(packageName, 'misc', 'schemas');
|
|
93
|
+
const schema = schemas.get(schemaName);
|
|
94
|
+
if (schema === undefined) {
|
|
95
|
+
const availableSchemas = Array.from(schemas.keys());
|
|
96
|
+
logger.error(`Schema '${schemaName}' not found for package '${packageName ?? 'main'}'. Available schemas: ${availableSchemas.join(', ') || '(none)'}`);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
logger.debug(`[validateSchema] Found schema '${schemaName}':`, JSON.stringify(schema));
|
|
100
|
+
}
|
|
89
101
|
await schemaService.compileSchema(schemaName, schema);
|
|
90
102
|
await schemaService.validateSchema(schemaName, data);
|
|
91
103
|
}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { ChannelStore } from '../wirings/channel/channel-store.js';
|
|
2
2
|
import { CoreUserSession } from '../types/core.types.js';
|
|
3
|
-
export interface
|
|
3
|
+
export interface SessionService<UserSession extends CoreUserSession> {
|
|
4
4
|
sessionChanged: boolean;
|
|
5
|
+
initial: UserSession | undefined;
|
|
5
6
|
setInitial(session: UserSession): void;
|
|
7
|
+
freezeInitial(): UserSession | undefined;
|
|
6
8
|
set(session: UserSession): Promise<void> | void;
|
|
7
9
|
clear(): Promise<void> | void;
|
|
8
|
-
get(): Promise<UserSession
|
|
10
|
+
get(): Promise<UserSession> | UserSession | undefined;
|
|
9
11
|
}
|
|
10
|
-
export declare class
|
|
12
|
+
export declare class PikkuSessionService<UserSession extends CoreUserSession> implements SessionService<UserSession> {
|
|
11
13
|
private channelStore?;
|
|
12
14
|
private channelId?;
|
|
13
15
|
sessionChanged: boolean;
|
|
16
|
+
initial: UserSession | undefined;
|
|
14
17
|
private session;
|
|
15
18
|
constructor(channelStore?: ChannelStore<unknown, unknown, UserSession> | undefined, channelId?: string | undefined);
|
|
16
19
|
setInitial(session: UserSession): void;
|
|
20
|
+
freezeInitial(): UserSession | undefined;
|
|
17
21
|
set(session: UserSession): void | Promise<void> | undefined;
|
|
18
22
|
clear(): void | Promise<void> | undefined;
|
|
19
23
|
get(): Promise<UserSession> | UserSession | undefined;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class PikkuSessionService {
|
|
2
2
|
channelStore;
|
|
3
3
|
channelId;
|
|
4
4
|
sessionChanged = false;
|
|
5
|
+
initial;
|
|
5
6
|
session;
|
|
6
7
|
constructor(channelStore, channelId) {
|
|
7
8
|
this.channelStore = channelStore;
|
|
@@ -13,6 +14,12 @@ export class PikkuUserSessionService {
|
|
|
13
14
|
setInitial(session) {
|
|
14
15
|
this.session = session;
|
|
15
16
|
}
|
|
17
|
+
freezeInitial() {
|
|
18
|
+
if (this.initial === undefined) {
|
|
19
|
+
this.initial = this.session;
|
|
20
|
+
}
|
|
21
|
+
return this.initial;
|
|
22
|
+
}
|
|
16
23
|
set(session) {
|
|
17
24
|
this.sessionChanged = true;
|
|
18
25
|
this.session = session;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SerializedError, CoreSingletonServices, CreateWireServices, CoreConfig } from '../types/core.types.js';
|
|
2
|
+
import { WorkflowRun, StepState, WorkflowStatus } from '../wirings/workflow/workflow.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for workflow orchestration
|
|
5
|
+
* Handles workflow execution, replay, orchestration logic, and run-level state
|
|
6
|
+
*/
|
|
7
|
+
export interface WorkflowService {
|
|
8
|
+
createRun(workflowName: string, input: any, inline?: boolean): Promise<string>;
|
|
9
|
+
getRun(id: string): Promise<WorkflowRun | null>;
|
|
10
|
+
getRunHistory(runId: string): Promise<Array<StepState & {
|
|
11
|
+
stepName: string;
|
|
12
|
+
}>>;
|
|
13
|
+
updateRunStatus(id: string, status: WorkflowStatus, output?: any, error?: SerializedError): Promise<void>;
|
|
14
|
+
withRunLock<T>(id: string, fn: () => Promise<T>): Promise<T>;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
resumeWorkflow(runId: string): Promise<void>;
|
|
17
|
+
setServices(singletonServices: CoreSingletonServices, createWireServices: CreateWireServices, config: CoreConfig): void;
|
|
18
|
+
startWorkflow<I>(name: string, input: I, rpcService: any, options?: {
|
|
19
|
+
inline?: boolean;
|
|
20
|
+
startNode?: string;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
runId: string;
|
|
23
|
+
}>;
|
|
24
|
+
runWorkflowJob(runId: string, rpcService: any): Promise<void>;
|
|
25
|
+
orchestrateWorkflow(runId: string, rpcService: any): Promise<void>;
|
|
26
|
+
executeWorkflowSleepCompleted(runId: string, stepId: string): Promise<void>;
|
|
27
|
+
insertStepState(runId: string, stepName: string, rpcName: string, data: any, stepOptions?: {
|
|
28
|
+
retries?: number;
|
|
29
|
+
retryDelay?: string | number;
|
|
30
|
+
}): Promise<StepState>;
|
|
31
|
+
getStepState(runId: string, stepName: string): Promise<StepState>;
|
|
32
|
+
setStepRunning(stepId: string): Promise<void>;
|
|
33
|
+
setStepScheduled(stepId: string): Promise<void>;
|
|
34
|
+
setStepResult(stepId: string, result: any): Promise<void>;
|
|
35
|
+
setStepError(stepId: string, error: Error): Promise<void>;
|
|
36
|
+
createRetryAttempt(stepId: string, status: 'pending' | 'running'): Promise<StepState>;
|
|
37
|
+
executeWorkflowStep(runId: string, stepName: string, rpcName: string | null, data: any, rpcService: any): Promise<void>;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|