@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
|
@@ -8,7 +8,7 @@ import { addFunction } from '../../function/function-runner.js'
|
|
|
8
8
|
|
|
9
9
|
describe('CLI Runner', () => {
|
|
10
10
|
let singletonServices: any
|
|
11
|
-
let
|
|
11
|
+
let createWireServices: any
|
|
12
12
|
|
|
13
13
|
beforeEach(() => {
|
|
14
14
|
resetPikkuState()
|
|
@@ -21,7 +21,7 @@ describe('CLI Runner', () => {
|
|
|
21
21
|
},
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
createWireServices = async () => ({})
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
afterEach(() => {
|
|
@@ -30,7 +30,7 @@ describe('CLI Runner', () => {
|
|
|
30
30
|
|
|
31
31
|
describe('runCLICommand', () => {
|
|
32
32
|
test('should throw NotFoundError when program not found', async () => {
|
|
33
|
-
pikkuState('cli', 'meta', { programs: {}, renderers: {} })
|
|
33
|
+
pikkuState(null, 'cli', 'meta', { programs: {}, renderers: {} })
|
|
34
34
|
|
|
35
35
|
await assert.rejects(
|
|
36
36
|
async () =>
|
|
@@ -45,7 +45,7 @@ describe('CLI Runner', () => {
|
|
|
45
45
|
})
|
|
46
46
|
|
|
47
47
|
test('should throw NotFoundError when command not found', async () => {
|
|
48
|
-
pikkuState('cli', 'meta', {
|
|
48
|
+
pikkuState(null, 'cli', 'meta', {
|
|
49
49
|
programs: {
|
|
50
50
|
'test-cli': {
|
|
51
51
|
program: 'test-cli',
|
|
@@ -56,7 +56,7 @@ describe('CLI Runner', () => {
|
|
|
56
56
|
renderers: {},
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
-
pikkuState('cli', 'programs', {
|
|
59
|
+
pikkuState(null, 'cli', 'programs', {
|
|
60
60
|
'test-cli': {
|
|
61
61
|
defaultRenderer: undefined,
|
|
62
62
|
middleware: [],
|
|
@@ -78,13 +78,13 @@ describe('CLI Runner', () => {
|
|
|
78
78
|
|
|
79
79
|
test('should execute command function with merged data', async () => {
|
|
80
80
|
let receivedData: any
|
|
81
|
-
const testFunc = async (_services: any, data: any) => {
|
|
81
|
+
const testFunc = async (_services: any, data: any, _wire: any) => {
|
|
82
82
|
receivedData = data
|
|
83
83
|
return { success: true }
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
// Setup metadata
|
|
87
|
-
pikkuState('cli', 'meta', {
|
|
87
|
+
pikkuState(null, 'cli', 'meta', {
|
|
88
88
|
programs: {
|
|
89
89
|
'test-cli': {
|
|
90
90
|
program: 'test-cli',
|
|
@@ -102,7 +102,7 @@ describe('CLI Runner', () => {
|
|
|
102
102
|
renderers: {},
|
|
103
103
|
})
|
|
104
104
|
|
|
105
|
-
pikkuState('cli', 'programs', {
|
|
105
|
+
pikkuState(null, 'cli', 'programs', {
|
|
106
106
|
'test-cli': {
|
|
107
107
|
defaultRenderer: undefined,
|
|
108
108
|
middleware: [],
|
|
@@ -110,7 +110,7 @@ describe('CLI Runner', () => {
|
|
|
110
110
|
},
|
|
111
111
|
})
|
|
112
112
|
|
|
113
|
-
pikkuState('function', 'meta', {
|
|
113
|
+
pikkuState(null, 'function', 'meta', {
|
|
114
114
|
greetFunc: {
|
|
115
115
|
pikkuFuncName: 'greetFunc',
|
|
116
116
|
inputSchemaName: null,
|
|
@@ -136,7 +136,7 @@ describe('CLI Runner', () => {
|
|
|
136
136
|
|
|
137
137
|
const testMiddleware: CorePikkuMiddleware = async (
|
|
138
138
|
_services,
|
|
139
|
-
|
|
139
|
+
_wire,
|
|
140
140
|
next
|
|
141
141
|
) => {
|
|
142
142
|
executionOrder.push('middleware')
|
|
@@ -148,7 +148,7 @@ describe('CLI Runner', () => {
|
|
|
148
148
|
return { success: true }
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
pikkuState('cli', 'meta', {
|
|
151
|
+
pikkuState(null, 'cli', 'meta', {
|
|
152
152
|
programs: {
|
|
153
153
|
'test-cli': {
|
|
154
154
|
program: 'test-cli',
|
|
@@ -166,7 +166,7 @@ describe('CLI Runner', () => {
|
|
|
166
166
|
renderers: {},
|
|
167
167
|
})
|
|
168
168
|
|
|
169
|
-
pikkuState('cli', 'programs', {
|
|
169
|
+
pikkuState(null, 'cli', 'programs', {
|
|
170
170
|
'test-cli': {
|
|
171
171
|
defaultRenderer: undefined,
|
|
172
172
|
middleware: [testMiddleware],
|
|
@@ -174,7 +174,7 @@ describe('CLI Runner', () => {
|
|
|
174
174
|
},
|
|
175
175
|
})
|
|
176
176
|
|
|
177
|
-
pikkuState('function', 'meta', {
|
|
177
|
+
pikkuState(null, 'function', 'meta', {
|
|
178
178
|
testFunc: {
|
|
179
179
|
pikkuFuncName: 'testFunc',
|
|
180
180
|
inputSchemaName: null,
|
|
@@ -199,16 +199,16 @@ describe('CLI Runner', () => {
|
|
|
199
199
|
|
|
200
200
|
const testMiddleware: CorePikkuMiddleware = async (
|
|
201
201
|
_services,
|
|
202
|
-
|
|
202
|
+
wire,
|
|
203
203
|
next
|
|
204
204
|
) => {
|
|
205
|
-
cliContext =
|
|
205
|
+
cliContext = wire.cli
|
|
206
206
|
await next()
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
const testFunc = async () => ({ success: true })
|
|
210
210
|
|
|
211
|
-
pikkuState('cli', 'meta', {
|
|
211
|
+
pikkuState(null, 'cli', 'meta', {
|
|
212
212
|
programs: {
|
|
213
213
|
'test-cli': {
|
|
214
214
|
program: 'test-cli',
|
|
@@ -226,7 +226,7 @@ describe('CLI Runner', () => {
|
|
|
226
226
|
renderers: {},
|
|
227
227
|
})
|
|
228
228
|
|
|
229
|
-
pikkuState('cli', 'programs', {
|
|
229
|
+
pikkuState(null, 'cli', 'programs', {
|
|
230
230
|
'test-cli': {
|
|
231
231
|
defaultRenderer: undefined,
|
|
232
232
|
middleware: [testMiddleware],
|
|
@@ -234,7 +234,7 @@ describe('CLI Runner', () => {
|
|
|
234
234
|
},
|
|
235
235
|
})
|
|
236
236
|
|
|
237
|
-
pikkuState('function', 'meta', {
|
|
237
|
+
pikkuState(null, 'function', 'meta', {
|
|
238
238
|
greetFunc: {
|
|
239
239
|
pikkuFuncName: 'greetFunc',
|
|
240
240
|
inputSchemaName: null,
|
|
@@ -260,7 +260,7 @@ describe('CLI Runner', () => {
|
|
|
260
260
|
test('should throw error when auth required but no session', async () => {
|
|
261
261
|
const testFunc = async () => ({ success: true })
|
|
262
262
|
|
|
263
|
-
pikkuState('cli', 'meta', {
|
|
263
|
+
pikkuState(null, 'cli', 'meta', {
|
|
264
264
|
programs: {
|
|
265
265
|
'test-cli': {
|
|
266
266
|
program: 'test-cli',
|
|
@@ -278,7 +278,7 @@ describe('CLI Runner', () => {
|
|
|
278
278
|
renderers: {},
|
|
279
279
|
})
|
|
280
280
|
|
|
281
|
-
pikkuState('function', 'meta', {
|
|
281
|
+
pikkuState(null, 'function', 'meta', {
|
|
282
282
|
secureFunc: {
|
|
283
283
|
pikkuFuncName: 'secureFunc',
|
|
284
284
|
inputSchemaName: null,
|
|
@@ -295,7 +295,7 @@ describe('CLI Runner', () => {
|
|
|
295
295
|
commandPath: ['secure'],
|
|
296
296
|
data: {},
|
|
297
297
|
singletonServices,
|
|
298
|
-
|
|
298
|
+
createWireServices,
|
|
299
299
|
}),
|
|
300
300
|
/Authentication required/
|
|
301
301
|
)
|
|
@@ -306,7 +306,7 @@ describe('CLI Runner', () => {
|
|
|
306
306
|
test('should register CLI program and commands', () => {
|
|
307
307
|
const greetFunc = async () => 'Hello'
|
|
308
308
|
|
|
309
|
-
pikkuState('cli', 'meta', {
|
|
309
|
+
pikkuState(null, 'cli', 'meta', {
|
|
310
310
|
programs: {
|
|
311
311
|
'my-cli': {
|
|
312
312
|
program: 'my-cli',
|
|
@@ -337,7 +337,7 @@ describe('CLI Runner', () => {
|
|
|
337
337
|
},
|
|
338
338
|
})
|
|
339
339
|
|
|
340
|
-
const programs = pikkuState('cli', 'programs')
|
|
340
|
+
const programs = pikkuState(null, 'cli', 'programs')
|
|
341
341
|
assert.ok(programs['my-cli'])
|
|
342
342
|
assert.strictEqual(programs['my-cli'].middleware.length, 0)
|
|
343
343
|
})
|
|
@@ -347,7 +347,7 @@ describe('CLI Runner', () => {
|
|
|
347
347
|
await next()
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
-
pikkuState('cli', 'meta', {
|
|
350
|
+
pikkuState(null, 'cli', 'meta', {
|
|
351
351
|
programs: {
|
|
352
352
|
'my-cli': {
|
|
353
353
|
program: 'my-cli',
|
|
@@ -364,13 +364,13 @@ describe('CLI Runner', () => {
|
|
|
364
364
|
middleware: [middleware],
|
|
365
365
|
})
|
|
366
366
|
|
|
367
|
-
const programs = pikkuState('cli', 'programs')
|
|
367
|
+
const programs = pikkuState(null, 'cli', 'programs')
|
|
368
368
|
assert.strictEqual(programs['my-cli'].middleware.length, 1)
|
|
369
369
|
assert.strictEqual(programs['my-cli'].middleware[0], middleware)
|
|
370
370
|
})
|
|
371
371
|
|
|
372
372
|
test('should throw error when CLI metadata not found', () => {
|
|
373
|
-
pikkuState('cli', 'meta', { programs: {}, renderers: {} })
|
|
373
|
+
pikkuState(null, 'cli', 'meta', { programs: {}, renderers: {} })
|
|
374
374
|
|
|
375
375
|
assert.throws(() => {
|
|
376
376
|
wireCLI({
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { NotFoundError } from '../../errors/errors.js'
|
|
2
2
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
|
|
3
3
|
import { pikkuState } from '../../pikku-state.js'
|
|
4
|
-
import {
|
|
5
|
-
CorePikkuMiddleware,
|
|
6
|
-
CoreUserSession,
|
|
7
|
-
SessionServices,
|
|
8
|
-
PikkuWiringTypes,
|
|
9
|
-
} from '../../types/core.types.js'
|
|
10
|
-
import { closeSessionServices } from '../../utils.js'
|
|
4
|
+
import { CorePikkuMiddleware, CoreUserSession } from '../../types/core.types.js'
|
|
11
5
|
import {
|
|
12
6
|
CoreCLI,
|
|
13
7
|
CLICommandMeta,
|
|
@@ -20,14 +14,13 @@ import {
|
|
|
20
14
|
import type {
|
|
21
15
|
CoreSingletonServices,
|
|
22
16
|
CoreServices,
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
CreateWireServices,
|
|
18
|
+
PikkuWire,
|
|
25
19
|
CreateConfig,
|
|
26
20
|
CreateSingletonServices,
|
|
27
21
|
} from '../../types/core.types.js'
|
|
28
22
|
import { PikkuChannel } from '../channel/channel.types.js'
|
|
29
|
-
import {
|
|
30
|
-
import { PikkuUserSessionService } from '../../services/user-session-service.js'
|
|
23
|
+
import { PikkuSessionService } from '../../services/user-session-service.js'
|
|
31
24
|
import { LocalVariablesService } from '../../services/local-variables.js'
|
|
32
25
|
import { generateCommandHelp, parseCLIArguments } from './command-parser.js'
|
|
33
26
|
|
|
@@ -64,7 +57,7 @@ export const wireCLI = <
|
|
|
64
57
|
cli: CoreCLI<Commands, GlobalOptions, PikkuMiddleware, GlobalOutput>
|
|
65
58
|
) => {
|
|
66
59
|
// Get the existing metadata that was generated during inspection
|
|
67
|
-
const cliMeta = pikkuState('cli', 'meta') || {}
|
|
60
|
+
const cliMeta = pikkuState(null, 'cli', 'meta') || {}
|
|
68
61
|
|
|
69
62
|
if (!cliMeta.programs?.[cli.program]) {
|
|
70
63
|
throw new Error(
|
|
@@ -74,7 +67,7 @@ export const wireCLI = <
|
|
|
74
67
|
|
|
75
68
|
// Get existing programs state and add this program
|
|
76
69
|
const programs: Record<string, CLIProgramState> =
|
|
77
|
-
pikkuState('cli', 'programs') || {}
|
|
70
|
+
pikkuState(null, 'cli', 'programs') || {}
|
|
78
71
|
programs[cli.program] = {
|
|
79
72
|
defaultRenderer: (cli.render ||
|
|
80
73
|
defaultJSONRenderer) as CorePikkuCLIRender<any>,
|
|
@@ -82,7 +75,7 @@ export const wireCLI = <
|
|
|
82
75
|
renderers: {},
|
|
83
76
|
tags: cli.tags,
|
|
84
77
|
}
|
|
85
|
-
pikkuState('cli', 'programs', programs)
|
|
78
|
+
pikkuState(null, 'cli', 'programs', programs)
|
|
86
79
|
|
|
87
80
|
// Register all command functions recursively
|
|
88
81
|
registerCLICommands(
|
|
@@ -137,7 +130,7 @@ function registerCLICommands(
|
|
|
137
130
|
program: string
|
|
138
131
|
) {
|
|
139
132
|
// Get the CLI metadata to find actual function names
|
|
140
|
-
const cliMeta = pikkuState('cli', 'meta').programs[program]
|
|
133
|
+
const cliMeta = pikkuState(null, 'cli', 'meta').programs[program]
|
|
141
134
|
|
|
142
135
|
for (const [name, command] of Object.entries(commands)) {
|
|
143
136
|
const fullPath = [...path, name]
|
|
@@ -173,6 +166,7 @@ function registerCLICommands(
|
|
|
173
166
|
|
|
174
167
|
// Store the options and middleware in program state for use during execution
|
|
175
168
|
const programs: Record<string, CLIProgramState> = pikkuState(
|
|
169
|
+
null,
|
|
176
170
|
'cli',
|
|
177
171
|
'programs'
|
|
178
172
|
)
|
|
@@ -215,10 +209,10 @@ function pluckCLIData(
|
|
|
215
209
|
funcName: string,
|
|
216
210
|
availableOptions: Record<string, CLIOption>
|
|
217
211
|
): Record<string, any> {
|
|
218
|
-
const funcMeta = pikkuState('function', 'meta')[funcName]
|
|
212
|
+
const funcMeta = pikkuState(null, 'function', 'meta')[funcName]
|
|
219
213
|
const schemaName = funcMeta?.inputSchemaName
|
|
220
214
|
const schema = schemaName
|
|
221
|
-
? pikkuState('misc', 'schemas').get(schemaName)
|
|
215
|
+
? pikkuState(null, 'misc', 'schemas').get(schemaName)
|
|
222
216
|
: null
|
|
223
217
|
|
|
224
218
|
if (schema && schema.properties) {
|
|
@@ -247,16 +241,16 @@ export async function runCLICommand({
|
|
|
247
241
|
commandPath,
|
|
248
242
|
data,
|
|
249
243
|
singletonServices,
|
|
250
|
-
|
|
244
|
+
createWireServices,
|
|
251
245
|
}: {
|
|
252
246
|
program: string
|
|
253
247
|
commandPath: string[]
|
|
254
248
|
data: Record<string, any>
|
|
255
249
|
singletonServices: CoreSingletonServices
|
|
256
|
-
|
|
250
|
+
createWireServices?: CreateWireServices
|
|
257
251
|
}): Promise<any> {
|
|
258
252
|
// Get the command metadata to find the function name
|
|
259
|
-
const cliMeta = pikkuState('cli', 'meta')
|
|
253
|
+
const cliMeta = pikkuState(null, 'cli', 'meta')
|
|
260
254
|
const programMeta = cliMeta.programs?.[program]
|
|
261
255
|
if (!programMeta) {
|
|
262
256
|
throw new NotFoundError(`Program not found: ${program}`)
|
|
@@ -282,7 +276,7 @@ export async function runCLICommand({
|
|
|
282
276
|
|
|
283
277
|
// Get program-specific data
|
|
284
278
|
const programs: Record<string, CLIProgramState> =
|
|
285
|
-
pikkuState('cli', 'programs') || {}
|
|
279
|
+
pikkuState(null, 'cli', 'programs') || {}
|
|
286
280
|
const programData = programs[program]
|
|
287
281
|
|
|
288
282
|
// Combine program middleware + command middleware from the hierarchy
|
|
@@ -329,57 +323,31 @@ export async function runCLICommand({
|
|
|
329
323
|
state: 'open',
|
|
330
324
|
}
|
|
331
325
|
|
|
332
|
-
const userSession = new
|
|
333
|
-
let sessionServices: SessionServices | undefined
|
|
326
|
+
const userSession = new PikkuSessionService<CoreUserSession>()
|
|
334
327
|
|
|
335
|
-
const
|
|
328
|
+
const wire: PikkuWire = {
|
|
336
329
|
cli: {
|
|
337
330
|
program,
|
|
338
331
|
command: commandPath,
|
|
339
332
|
data: pluckedData,
|
|
340
333
|
channel,
|
|
341
334
|
},
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const getAllServices = async (session?: CoreUserSession) => {
|
|
345
|
-
// Create session-specific services for handling the command
|
|
346
|
-
sessionServices = await createSessionServices?.(
|
|
347
|
-
singletonServices,
|
|
348
|
-
interaction,
|
|
349
|
-
session
|
|
350
|
-
)
|
|
351
|
-
|
|
352
|
-
return rpcService.injectRPCService(
|
|
353
|
-
{
|
|
354
|
-
...singletonServices,
|
|
355
|
-
...sessionServices,
|
|
356
|
-
userSession,
|
|
357
|
-
channel,
|
|
358
|
-
},
|
|
359
|
-
interaction,
|
|
360
|
-
false
|
|
361
|
-
)
|
|
335
|
+
session: userSession,
|
|
362
336
|
}
|
|
363
337
|
|
|
364
338
|
try {
|
|
365
|
-
const result = await runPikkuFunc(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
inheritedPermissions: currentCommand.permissions,
|
|
378
|
-
wirePermissions: undefined,
|
|
379
|
-
tags: programData?.tags,
|
|
380
|
-
interaction,
|
|
381
|
-
}
|
|
382
|
-
)
|
|
339
|
+
const result = await runPikkuFunc('cli', commandId, funcName, {
|
|
340
|
+
singletonServices,
|
|
341
|
+
createWireServices,
|
|
342
|
+
data: pluckedData,
|
|
343
|
+
auth: false,
|
|
344
|
+
inheritedMiddleware: currentCommand.middleware,
|
|
345
|
+
wireMiddleware: allWireMiddleware,
|
|
346
|
+
inheritedPermissions: currentCommand.permissions,
|
|
347
|
+
wirePermissions: undefined,
|
|
348
|
+
tags: programData?.tags,
|
|
349
|
+
wire,
|
|
350
|
+
})
|
|
383
351
|
|
|
384
352
|
// Apply renderer one final time with the final output (if renderer exists)
|
|
385
353
|
if (renderer) {
|
|
@@ -392,11 +360,6 @@ export async function runCLICommand({
|
|
|
392
360
|
} finally {
|
|
393
361
|
// Close the channel
|
|
394
362
|
channel.close()
|
|
395
|
-
|
|
396
|
-
// Clean up session services
|
|
397
|
-
if (sessionServices) {
|
|
398
|
-
await closeSessionServices(singletonServices.logger, sessionServices)
|
|
399
|
-
}
|
|
400
363
|
}
|
|
401
364
|
}
|
|
402
365
|
|
|
@@ -428,13 +391,13 @@ export async function executeCLI({
|
|
|
428
391
|
args,
|
|
429
392
|
createConfig,
|
|
430
393
|
createSingletonServices,
|
|
431
|
-
|
|
394
|
+
createWireServices,
|
|
432
395
|
}: {
|
|
433
396
|
programName: string
|
|
434
397
|
args?: string[]
|
|
435
398
|
createConfig: CreateConfig<any, any>
|
|
436
399
|
createSingletonServices: CreateSingletonServices<any, any>
|
|
437
|
-
|
|
400
|
+
createWireServices?: CreateWireServices<any, any, any>
|
|
438
401
|
}): Promise<void> {
|
|
439
402
|
if (!args) {
|
|
440
403
|
throw new Error(
|
|
@@ -444,7 +407,7 @@ export async function executeCLI({
|
|
|
444
407
|
|
|
445
408
|
try {
|
|
446
409
|
// Get CLI metadata from state
|
|
447
|
-
const allCLIMeta = pikkuState('cli', 'meta') as unknown as
|
|
410
|
+
const allCLIMeta = pikkuState(null, 'cli', 'meta') as unknown as
|
|
448
411
|
| CLIMeta
|
|
449
412
|
| undefined
|
|
450
413
|
if (!allCLIMeta) {
|
|
@@ -518,7 +481,7 @@ export async function executeCLI({
|
|
|
518
481
|
commandPath: parsed.commandPath,
|
|
519
482
|
data,
|
|
520
483
|
singletonServices,
|
|
521
|
-
|
|
484
|
+
createWireServices,
|
|
522
485
|
})
|
|
523
486
|
} catch (error: any) {
|
|
524
487
|
// Re-throw CLIError as-is
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
CorePikkuMiddleware,
|
|
3
3
|
CoreSingletonServices,
|
|
4
4
|
CoreUserSession,
|
|
5
|
-
PikkuDocs,
|
|
6
5
|
CoreServices,
|
|
7
6
|
MiddlewareMetadata,
|
|
8
7
|
PermissionMetadata,
|
|
@@ -44,7 +43,7 @@ export interface CLIPositional {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
/**
|
|
47
|
-
* CLI
|
|
46
|
+
* CLI wire context
|
|
48
47
|
*/
|
|
49
48
|
export type PikkuCLI = {
|
|
50
49
|
program: string
|
|
@@ -74,8 +73,9 @@ export interface CLICommandMeta {
|
|
|
74
73
|
positionals: CLIPositional[]
|
|
75
74
|
options: Record<string, CLIOption>
|
|
76
75
|
renderName?: string
|
|
76
|
+
summary?: string
|
|
77
77
|
description?: string
|
|
78
|
-
|
|
78
|
+
errors?: string[]
|
|
79
79
|
tags?: string[]
|
|
80
80
|
subcommands?: Record<string, CLICommandMeta>
|
|
81
81
|
middleware?: MiddlewareMetadata[] // Pre-resolved middleware chain (tag + explicit)
|
|
@@ -131,8 +131,8 @@ export type CorePikkuCLIRender<
|
|
|
131
131
|
export type ExtractFunctionInput<Func> =
|
|
132
132
|
Func extends CorePikkuFunctionConfig<infer FuncType, any, any>
|
|
133
133
|
? FuncType extends
|
|
134
|
-
| CorePikkuFunction<infer Input, any, any, any
|
|
135
|
-
| CorePikkuFunctionSessionless<infer Input, any, any, any
|
|
134
|
+
| CorePikkuFunction<infer Input, any, any, any>
|
|
135
|
+
| CorePikkuFunctionSessionless<infer Input, any, any, any>
|
|
136
136
|
? Input
|
|
137
137
|
: never
|
|
138
138
|
: never
|
|
@@ -198,8 +198,8 @@ export type ValidateParameters<Params extends string, Input> =
|
|
|
198
198
|
export type ExtractFunctionOutput<Func> =
|
|
199
199
|
Func extends CorePikkuFunctionConfig<infer FuncType, any, any>
|
|
200
200
|
? FuncType extends
|
|
201
|
-
| CorePikkuFunction<any, infer Output, any, any
|
|
202
|
-
| CorePikkuFunctionSessionless<any, infer Output, any, any
|
|
201
|
+
| CorePikkuFunction<any, infer Output, any, any>
|
|
202
|
+
| CorePikkuFunctionSessionless<any, infer Output, any, any>
|
|
203
203
|
? Output
|
|
204
204
|
: never
|
|
205
205
|
: never
|
|
@@ -210,7 +210,10 @@ export type ExtractFunctionOutput<Func> =
|
|
|
210
210
|
*/
|
|
211
211
|
export type CoreCLICommandConfig<
|
|
212
212
|
FuncConfig,
|
|
213
|
-
PikkuMiddleware extends CorePikkuMiddleware<any> = CorePikkuMiddleware<
|
|
213
|
+
PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<
|
|
214
|
+
any,
|
|
215
|
+
any
|
|
216
|
+
>,
|
|
214
217
|
PikkuCLIRender extends CorePikkuCLIRender<any, any, any> = CorePikkuCLIRender<
|
|
215
218
|
any,
|
|
216
219
|
any
|
|
@@ -219,6 +222,7 @@ export type CoreCLICommandConfig<
|
|
|
219
222
|
> = {
|
|
220
223
|
parameters?: ValidateParameters<Params, ExtractFunctionInput<FuncConfig>>
|
|
221
224
|
func?: FuncConfig
|
|
225
|
+
title?: string
|
|
222
226
|
description?: string
|
|
223
227
|
render?: PikkuCLIRender
|
|
224
228
|
options?: {
|
|
@@ -245,8 +249,8 @@ export interface CoreCLICommand<
|
|
|
245
249
|
In,
|
|
246
250
|
Out,
|
|
247
251
|
PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
248
|
-
| CorePikkuFunction<In, Out, any, any
|
|
249
|
-
| CorePikkuFunctionSessionless<In, Out, any, any
|
|
252
|
+
| CorePikkuFunction<In, Out, any, any>
|
|
253
|
+
| CorePikkuFunctionSessionless<In, Out, any, any>
|
|
250
254
|
>,
|
|
251
255
|
PikkuPermission extends CorePikkuPermission<any, any, any>,
|
|
252
256
|
PikkuMiddleware extends CorePikkuMiddleware,
|
|
@@ -264,7 +268,9 @@ export interface CoreCLICommand<
|
|
|
264
268
|
middleware?: PikkuMiddleware[]
|
|
265
269
|
permissions?: Record<string, PikkuPermission | PikkuPermission[]>
|
|
266
270
|
auth?: boolean
|
|
267
|
-
|
|
271
|
+
summary?: string
|
|
272
|
+
errors?: string[]
|
|
273
|
+
tags?: string[]
|
|
268
274
|
subcommands?: Subcommands
|
|
269
275
|
isDefault?: boolean
|
|
270
276
|
}
|
|
@@ -276,8 +282,8 @@ export type CLICommandShorthand<
|
|
|
276
282
|
In,
|
|
277
283
|
Out,
|
|
278
284
|
PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
279
|
-
| CorePikkuFunction<In, Out, any, any
|
|
280
|
-
| CorePikkuFunctionSessionless<In, Out, any, any
|
|
285
|
+
| CorePikkuFunction<In, Out, any, any>
|
|
286
|
+
| CorePikkuFunctionSessionless<In, Out, any, any>
|
|
281
287
|
>,
|
|
282
288
|
> = PikkuFunctionConfig
|
|
283
289
|
|
|
@@ -288,8 +294,8 @@ export type CLICommandDefinition<
|
|
|
288
294
|
In,
|
|
289
295
|
Out,
|
|
290
296
|
PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
291
|
-
| CorePikkuFunction<In, Out, any, any
|
|
292
|
-
| CorePikkuFunctionSessionless<In, Out, any, any
|
|
297
|
+
| CorePikkuFunction<In, Out, any, any>
|
|
298
|
+
| CorePikkuFunctionSessionless<In, Out, any, any>
|
|
293
299
|
>,
|
|
294
300
|
PikkuPermission extends CorePikkuPermission<any, any, any>,
|
|
295
301
|
PikkuMiddleware extends CorePikkuMiddleware,
|
|
@@ -325,7 +331,8 @@ export interface CoreCLI<
|
|
|
325
331
|
options?: CLIOptions<Options>
|
|
326
332
|
middleware?: PikkuMiddleware[]
|
|
327
333
|
render?: PikkuCLIRender
|
|
328
|
-
|
|
334
|
+
summary?: string
|
|
335
|
+
errors?: string[]
|
|
329
336
|
tags?: string[]
|
|
330
337
|
}
|
|
331
338
|
|