@pikku/core 0.9.11 → 0.9.12-next.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 +6 -0
- package/dist/function/function-runner.d.ts +13 -8
- package/dist/function/function-runner.js +49 -37
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/middleware-runner.d.ts +61 -40
- package/dist/middleware-runner.js +118 -66
- package/dist/permissions.js +1 -0
- package/dist/pikku-state.d.ts +26 -1
- package/dist/pikku-state.js +10 -1
- package/dist/services/content-service.d.ts +2 -3
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.js +0 -1
- package/dist/services/local-content.d.ts +2 -4
- package/dist/types/core.types.d.ts +51 -2
- package/dist/types/core.types.js +21 -0
- package/dist/wirings/channel/channel-handler.d.ts +2 -2
- package/dist/wirings/channel/channel-handler.js +12 -9
- package/dist/wirings/channel/channel-runner.d.ts +0 -2
- package/dist/wirings/channel/channel-runner.js +2 -3
- package/dist/wirings/channel/channel.types.d.ts +5 -3
- package/dist/wirings/channel/local/local-channel-runner.js +12 -12
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +7 -8
- package/dist/wirings/cli/channel/cli-channel-runner.d.ts +12 -0
- package/dist/wirings/cli/channel/cli-channel-runner.js +80 -0
- package/dist/wirings/cli/channel/index.d.ts +1 -0
- package/dist/wirings/cli/channel/index.js +1 -0
- package/dist/wirings/cli/cli-runner.d.ts +32 -0
- package/dist/wirings/cli/cli-runner.js +328 -0
- package/dist/wirings/cli/cli.types.d.ts +177 -0
- package/dist/wirings/cli/cli.types.js +1 -0
- package/dist/wirings/cli/command-parser.d.ts +19 -0
- package/dist/wirings/cli/command-parser.js +373 -0
- package/dist/wirings/cli/index.d.ts +5 -0
- package/dist/wirings/cli/index.js +5 -0
- package/dist/wirings/http/http-runner.d.ts +29 -10
- package/dist/wirings/http/http-runner.js +103 -131
- package/dist/wirings/http/http.types.d.ts +10 -10
- package/dist/wirings/http/index.d.ts +1 -1
- package/dist/wirings/http/index.js +1 -1
- package/dist/wirings/http/pikku-fetch-http-response.js +3 -1
- package/dist/wirings/http/routers/http-router.d.ts +0 -2
- package/dist/wirings/http/routers/path-to-regex.d.ts +1 -1
- package/dist/wirings/http/routers/path-to-regex.js +5 -34
- package/dist/wirings/mcp/mcp-runner.d.ts +4 -5
- package/dist/wirings/mcp/mcp-runner.js +30 -34
- package/dist/wirings/mcp/mcp.types.d.ts +11 -8
- package/dist/wirings/queue/queue-runner.d.ts +2 -2
- package/dist/wirings/queue/queue-runner.js +25 -27
- package/dist/wirings/queue/queue.types.d.ts +6 -5
- 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 +6 -18
- package/dist/wirings/rpc/rpc-runner.js +13 -8
- package/dist/wirings/scheduler/scheduler-runner.d.ts +2 -2
- package/dist/wirings/scheduler/scheduler-runner.js +37 -35
- package/dist/wirings/scheduler/scheduler.types.d.ts +4 -3
- package/package.json +4 -3
- package/src/function/function-runner.test.ts +73 -23
- package/src/function/function-runner.ts +74 -55
- package/src/index.ts +8 -1
- package/src/middleware-runner.test.ts +24 -16
- package/src/middleware-runner.ts +136 -83
- package/src/permissions.ts +1 -0
- package/src/pikku-state.ts +47 -2
- package/src/services/content-service.ts +5 -4
- package/src/services/index.ts +0 -1
- package/src/services/local-content.ts +9 -4
- package/src/types/core.types.ts +74 -3
- package/src/wirings/channel/channel-handler.ts +9 -13
- package/src/wirings/channel/channel-runner.ts +2 -6
- package/src/wirings/channel/channel.types.ts +5 -1
- package/src/wirings/channel/local/local-channel-runner.ts +25 -15
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +15 -17
- package/src/wirings/cli/channel/cli-channel-runner.ts +118 -0
- package/src/wirings/cli/channel/index.ts +1 -0
- package/src/wirings/cli/cli-runner.test.ts +382 -0
- package/src/wirings/cli/cli-runner.ts +503 -0
- package/src/wirings/cli/cli.types.ts +320 -0
- package/src/wirings/cli/command-parser.test.ts +440 -0
- package/src/wirings/cli/command-parser.ts +470 -0
- package/src/wirings/cli/index.ts +12 -0
- package/src/wirings/http/http-runner.test.ts +8 -7
- package/src/wirings/http/http-runner.ts +126 -159
- package/src/wirings/http/http.types.ts +56 -11
- package/src/wirings/http/index.ts +1 -1
- package/src/wirings/http/pikku-fetch-http-response.ts +3 -1
- package/src/wirings/http/routers/http-router.ts +0 -2
- package/src/wirings/http/routers/path-to-regex.test.ts +4 -5
- package/src/wirings/http/routers/path-to-regex.ts +6 -43
- package/src/wirings/mcp/mcp-runner.ts +56 -55
- package/src/wirings/mcp/mcp.types.ts +23 -8
- package/src/wirings/queue/queue-runner.ts +44 -47
- package/src/wirings/queue/queue.types.ts +10 -6
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +27 -9
- package/src/wirings/scheduler/scheduler-runner.ts +57 -56
- package/src/wirings/scheduler/scheduler.types.ts +9 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -17,14 +17,19 @@ beforeEach(() => {
|
|
|
17
17
|
// Helper function to add function with metadata for tests
|
|
18
18
|
const addTestFunction = (funcName: string, funcConfig: any) => {
|
|
19
19
|
addFunction(funcName, funcConfig)
|
|
20
|
+
// Convert tags to middleware metadata
|
|
21
|
+
const middleware = funcConfig.tags
|
|
22
|
+
? funcConfig.tags.map((tag: string) => ({ type: 'tag' as const, tag }))
|
|
23
|
+
: undefined
|
|
20
24
|
pikkuState('function', 'meta')[funcName] = {
|
|
21
25
|
pikkuFuncName: funcName,
|
|
22
26
|
inputSchemaName: null,
|
|
23
27
|
outputSchemaName: null,
|
|
28
|
+
middleware,
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
const
|
|
32
|
+
const mockSingletonServices = {
|
|
28
33
|
logger: {
|
|
29
34
|
info: () => {},
|
|
30
35
|
warn: () => {},
|
|
@@ -33,8 +38,12 @@ const mockServices: CoreServices = {
|
|
|
33
38
|
},
|
|
34
39
|
} as any
|
|
35
40
|
|
|
41
|
+
const mockServices: CoreServices = {
|
|
42
|
+
...mockSingletonServices,
|
|
43
|
+
} as any
|
|
44
|
+
|
|
36
45
|
describe('runPikkuFunc - Integration Tests', () => {
|
|
37
|
-
test('should execute middleware in correct order: wiringTags → wiringMiddleware →
|
|
46
|
+
test('should execute middleware in correct order: wiringTags → wiringMiddleware → funcTags → funcMiddleware', async () => {
|
|
38
47
|
const executionOrder: string[] = []
|
|
39
48
|
const createMiddleware = (name: string): CorePikkuMiddleware => {
|
|
40
49
|
return async (services, interaction, next) => {
|
|
@@ -61,20 +70,23 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
61
70
|
Math.random().toString(),
|
|
62
71
|
'testFunc',
|
|
63
72
|
{
|
|
73
|
+
singletonServices: mockSingletonServices,
|
|
64
74
|
getAllServices: () => mockServices,
|
|
65
|
-
data: {},
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
data: () => ({}),
|
|
76
|
+
wireMiddleware: [createMiddleware('wiringMiddleware')],
|
|
77
|
+
inheritedMiddleware: [{ type: 'tag', tag: 'wiringTag' }],
|
|
78
|
+
auth: false,
|
|
79
|
+
interaction: {},
|
|
68
80
|
}
|
|
69
81
|
)
|
|
70
82
|
|
|
71
83
|
assert.equal(result, 'success')
|
|
72
|
-
// Order:
|
|
84
|
+
// Order: wireInheritedMiddleware (tags), wireMiddleware, funcInheritedMiddleware (tags), funcMiddleware
|
|
73
85
|
assert.deepEqual(executionOrder, [
|
|
74
86
|
'wiringTag',
|
|
75
87
|
'wiringMiddleware',
|
|
76
|
-
'funcMiddleware',
|
|
77
88
|
'funcTag',
|
|
89
|
+
'funcMiddleware',
|
|
78
90
|
'main',
|
|
79
91
|
])
|
|
80
92
|
})
|
|
@@ -128,10 +140,13 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
128
140
|
Math.random().toString(),
|
|
129
141
|
'testFunc',
|
|
130
142
|
{
|
|
143
|
+
singletonServices: mockSingletonServices,
|
|
131
144
|
getAllServices: () => mockServices,
|
|
132
|
-
data: {},
|
|
145
|
+
data: () => ({}),
|
|
133
146
|
permissions: wiringPermissions,
|
|
134
147
|
tags: ['wiringTag'],
|
|
148
|
+
auth: false,
|
|
149
|
+
interaction: {},
|
|
135
150
|
}
|
|
136
151
|
)
|
|
137
152
|
|
|
@@ -157,9 +172,12 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
157
172
|
|
|
158
173
|
await assert.rejects(
|
|
159
174
|
runPikkuFunc(PikkuWiringTypes.rpc, Math.random().toString(), 'testFunc', {
|
|
175
|
+
singletonServices: mockSingletonServices,
|
|
160
176
|
getAllServices: () => mockServices,
|
|
161
|
-
data: {},
|
|
177
|
+
data: () => ({}),
|
|
162
178
|
tags: ['wiringTag'],
|
|
179
|
+
auth: false,
|
|
180
|
+
interaction: {},
|
|
163
181
|
}),
|
|
164
182
|
{
|
|
165
183
|
message: 'Permission denied',
|
|
@@ -178,9 +196,12 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
178
196
|
|
|
179
197
|
await assert.rejects(
|
|
180
198
|
runPikkuFunc(PikkuWiringTypes.rpc, Math.random().toString(), 'testFunc', {
|
|
199
|
+
singletonServices: mockSingletonServices,
|
|
181
200
|
getAllServices: () => mockServices,
|
|
182
|
-
data: {},
|
|
201
|
+
data: () => ({}),
|
|
183
202
|
permissions: wiringPermissions,
|
|
203
|
+
auth: false,
|
|
204
|
+
interaction: {},
|
|
184
205
|
}),
|
|
185
206
|
{
|
|
186
207
|
message: 'Permission denied',
|
|
@@ -200,8 +221,11 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
200
221
|
|
|
201
222
|
await assert.rejects(
|
|
202
223
|
runPikkuFunc(PikkuWiringTypes.rpc, Math.random().toString(), 'testFunc', {
|
|
224
|
+
singletonServices: mockSingletonServices,
|
|
203
225
|
getAllServices: () => mockServices,
|
|
204
|
-
data: {},
|
|
226
|
+
data: () => ({}),
|
|
227
|
+
auth: false,
|
|
228
|
+
interaction: {},
|
|
205
229
|
}),
|
|
206
230
|
{
|
|
207
231
|
message: 'Permission denied',
|
|
@@ -221,8 +245,11 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
221
245
|
|
|
222
246
|
await assert.rejects(
|
|
223
247
|
runPikkuFunc(PikkuWiringTypes.rpc, Math.random().toString(), 'testFunc', {
|
|
248
|
+
singletonServices: mockSingletonServices,
|
|
224
249
|
getAllServices: () => mockServices,
|
|
225
|
-
data: {},
|
|
250
|
+
data: () => ({}),
|
|
251
|
+
auth: false,
|
|
252
|
+
interaction: {},
|
|
226
253
|
}),
|
|
227
254
|
{
|
|
228
255
|
message: 'Permission denied',
|
|
@@ -256,8 +283,11 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
256
283
|
Math.random().toString(),
|
|
257
284
|
'testFunc',
|
|
258
285
|
{
|
|
286
|
+
singletonServices: mockSingletonServices,
|
|
259
287
|
getAllServices: () => mockServices,
|
|
260
|
-
data: {},
|
|
288
|
+
data: () => ({}),
|
|
289
|
+
auth: false,
|
|
290
|
+
interaction: {},
|
|
261
291
|
}
|
|
262
292
|
)
|
|
263
293
|
|
|
@@ -305,8 +335,11 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
305
335
|
Math.random().toString(),
|
|
306
336
|
'testFunc',
|
|
307
337
|
{
|
|
338
|
+
singletonServices: mockSingletonServices,
|
|
308
339
|
getAllServices: () => mockServices,
|
|
309
|
-
data: {},
|
|
340
|
+
data: () => ({}),
|
|
341
|
+
auth: false,
|
|
342
|
+
interaction: {},
|
|
310
343
|
}
|
|
311
344
|
)
|
|
312
345
|
|
|
@@ -330,8 +363,11 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
330
363
|
Math.random().toString(),
|
|
331
364
|
'simpleFunc',
|
|
332
365
|
{
|
|
366
|
+
singletonServices: mockSingletonServices,
|
|
333
367
|
getAllServices: () => mockServices,
|
|
334
|
-
data: {},
|
|
368
|
+
data: () => ({}),
|
|
369
|
+
auth: false,
|
|
370
|
+
interaction: {},
|
|
335
371
|
}
|
|
336
372
|
)
|
|
337
373
|
|
|
@@ -371,17 +407,21 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
371
407
|
Math.random().toString(),
|
|
372
408
|
'testFunc',
|
|
373
409
|
{
|
|
410
|
+
singletonServices: mockSingletonServices,
|
|
374
411
|
getAllServices: () => mockServices,
|
|
375
|
-
data: {},
|
|
376
|
-
|
|
412
|
+
data: () => ({}),
|
|
413
|
+
wireMiddleware: [wiringMiddleware],
|
|
377
414
|
permissions: wiringPermissions,
|
|
415
|
+
auth: false,
|
|
416
|
+
interaction: {},
|
|
378
417
|
}
|
|
379
418
|
)
|
|
380
419
|
|
|
381
420
|
assert.equal(result, 'success')
|
|
421
|
+
// Permissions run after middleware (middleware can set/modify session)
|
|
382
422
|
assert.deepEqual(executionOrder, [
|
|
383
|
-
'wiringPermission',
|
|
384
423
|
'wiringMiddleware',
|
|
424
|
+
'wiringPermission',
|
|
385
425
|
'main',
|
|
386
426
|
])
|
|
387
427
|
})
|
|
@@ -421,15 +461,19 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
421
461
|
Math.random().toString(),
|
|
422
462
|
'testFunc',
|
|
423
463
|
{
|
|
464
|
+
singletonServices: mockSingletonServices,
|
|
424
465
|
getAllServices: () => mockServices,
|
|
425
|
-
data: {},
|
|
466
|
+
data: () => ({}),
|
|
467
|
+
auth: false,
|
|
468
|
+
interaction: {},
|
|
426
469
|
}
|
|
427
470
|
)
|
|
428
471
|
|
|
429
472
|
assert.equal(result, 'success')
|
|
473
|
+
// Permissions run after middleware (middleware can set/modify session)
|
|
430
474
|
assert.deepEqual(executionOrder, [
|
|
431
|
-
'funcPermission',
|
|
432
475
|
'funcMiddleware',
|
|
476
|
+
'funcPermission',
|
|
433
477
|
'main',
|
|
434
478
|
])
|
|
435
479
|
})
|
|
@@ -456,9 +500,12 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
456
500
|
Math.random().toString(),
|
|
457
501
|
'testFunc',
|
|
458
502
|
{
|
|
503
|
+
singletonServices: mockSingletonServices,
|
|
459
504
|
getAllServices: () => mockServices,
|
|
460
|
-
data: testData,
|
|
461
|
-
|
|
505
|
+
data: () => testData,
|
|
506
|
+
userSession: { get: () => testSession, set: () => {} } as any,
|
|
507
|
+
auth: false,
|
|
508
|
+
interaction: {},
|
|
462
509
|
}
|
|
463
510
|
)
|
|
464
511
|
|
|
@@ -488,8 +535,11 @@ describe('runPikkuFunc - Integration Tests', () => {
|
|
|
488
535
|
Math.random().toString(),
|
|
489
536
|
'testFunc',
|
|
490
537
|
{
|
|
538
|
+
singletonServices: mockSingletonServices,
|
|
491
539
|
getAllServices: asyncGetServices,
|
|
492
|
-
data: {},
|
|
540
|
+
data: () => ({}),
|
|
541
|
+
auth: false,
|
|
542
|
+
interaction: {},
|
|
493
543
|
}
|
|
494
544
|
)
|
|
495
545
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ForbiddenError } from '../errors/errors.js'
|
|
2
1
|
import { runMiddleware, combineMiddleware } from '../middleware-runner.js'
|
|
3
2
|
import { runPermissions } from '../permissions.js'
|
|
4
3
|
import { pikkuState } from '../pikku-state.js'
|
|
@@ -8,24 +7,21 @@ import {
|
|
|
8
7
|
CoreUserSession,
|
|
9
8
|
CorePikkuMiddleware,
|
|
10
9
|
PikkuWiringTypes,
|
|
10
|
+
CoreSingletonServices,
|
|
11
|
+
PikkuInteraction,
|
|
12
|
+
MiddlewareMetadata,
|
|
11
13
|
} from '../types/core.types.js'
|
|
12
14
|
import {
|
|
13
15
|
CorePermissionGroup,
|
|
14
|
-
CorePikkuFunction,
|
|
15
16
|
CorePikkuFunctionConfig,
|
|
16
|
-
CorePikkuFunctionSessionless,
|
|
17
17
|
} from './functions.types.js'
|
|
18
|
+
import { UserSessionService } from '../services/user-session-service.js'
|
|
19
|
+
import { ForbiddenError } from '../errors/errors.js'
|
|
18
20
|
|
|
19
21
|
export const addFunction = (
|
|
20
22
|
funcName: string,
|
|
21
|
-
funcConfig:
|
|
22
|
-
| CorePikkuFunctionConfig<any, any>
|
|
23
|
-
| CorePikkuFunctionSessionless<any, any>
|
|
24
|
-
| CorePikkuFunction<any, any>
|
|
23
|
+
funcConfig: CorePikkuFunctionConfig<any, any>
|
|
25
24
|
) => {
|
|
26
|
-
if (funcConfig instanceof Function) {
|
|
27
|
-
funcConfig = { func: funcConfig }
|
|
28
|
-
}
|
|
29
25
|
pikkuState('function', 'functions').set(funcName, funcConfig)
|
|
30
26
|
}
|
|
31
27
|
|
|
@@ -48,20 +44,30 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
48
44
|
funcName: string,
|
|
49
45
|
{
|
|
50
46
|
getAllServices,
|
|
47
|
+
singletonServices,
|
|
51
48
|
data,
|
|
52
|
-
|
|
49
|
+
userSession,
|
|
50
|
+
auth: wiringAuth,
|
|
53
51
|
permissions: wiringPermissions,
|
|
54
|
-
|
|
52
|
+
inheritedMiddleware,
|
|
53
|
+
wireMiddleware,
|
|
55
54
|
coerceDataFromSchema,
|
|
56
55
|
tags = [],
|
|
56
|
+
interaction,
|
|
57
57
|
}: {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
singletonServices: CoreSingletonServices
|
|
59
|
+
getAllServices: (
|
|
60
|
+
session?: CoreUserSession
|
|
61
|
+
) => Promise<CoreServices> | CoreServices
|
|
62
|
+
userSession?: UserSessionService<CoreUserSession>
|
|
63
|
+
data: () => Promise<In> | In
|
|
64
|
+
auth?: boolean
|
|
61
65
|
permissions?: CorePermissionGroup
|
|
62
|
-
|
|
66
|
+
inheritedMiddleware?: MiddlewareMetadata[]
|
|
67
|
+
wireMiddleware?: CorePikkuMiddleware[]
|
|
63
68
|
coerceDataFromSchema?: boolean
|
|
64
69
|
tags?: string[]
|
|
70
|
+
interaction: PikkuInteraction
|
|
65
71
|
}
|
|
66
72
|
): Promise<Out> => {
|
|
67
73
|
const funcConfig = pikkuState('function', 'functions').get(funcName)
|
|
@@ -73,60 +79,73 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
73
79
|
throw new Error(`Function meta not found: ${funcName}`)
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
)
|
|
80
|
-
|
|
82
|
+
// Helper function to run permissions and execute the function
|
|
83
|
+
const executeFunction = async () => {
|
|
84
|
+
const session = userSession?.get()
|
|
85
|
+
if (wiringAuth === true || funcConfig.auth === true) {
|
|
86
|
+
// This means it was explicitly enabled in either wiring or function and has to be respected
|
|
87
|
+
if (!session) {
|
|
88
|
+
throw new ForbiddenError('Authentication required')
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (wiringAuth === undefined && funcConfig.auth === undefined) {
|
|
92
|
+
// We always default to requiring auth unless explicitly disabled
|
|
93
|
+
if (!session) {
|
|
94
|
+
throw new ForbiddenError('Authentication required')
|
|
95
|
+
}
|
|
96
|
+
}
|
|
81
97
|
|
|
82
|
-
|
|
98
|
+
// Evaluate the data from the lazy function
|
|
99
|
+
const actualData = await data()
|
|
83
100
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
// Validate and coerce data if schema is defined
|
|
102
|
+
const inputSchemaName = funcMeta.inputSchemaName
|
|
103
|
+
if (inputSchemaName) {
|
|
104
|
+
// Validate request data against the defined schema, if any
|
|
105
|
+
await validateSchema(
|
|
106
|
+
singletonServices.logger,
|
|
107
|
+
singletonServices.schema,
|
|
108
|
+
inputSchemaName,
|
|
109
|
+
actualData
|
|
110
|
+
)
|
|
111
|
+
// Coerce (top level) query string parameters or date objects if specified by the schema
|
|
112
|
+
if (coerceDataFromSchema) {
|
|
113
|
+
coerceTopLevelDataFromSchema(inputSchemaName, actualData)
|
|
114
|
+
}
|
|
96
115
|
}
|
|
97
|
-
}
|
|
98
116
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
117
|
+
const allServices = await getAllServices(session)
|
|
118
|
+
await runPermissions(wireType, wireId, {
|
|
119
|
+
wiringTags: tags,
|
|
120
|
+
wiringPermissions,
|
|
121
|
+
funcTags: funcConfig.tags,
|
|
122
|
+
funcPermissions: funcConfig.permissions,
|
|
123
|
+
allServices,
|
|
124
|
+
data: actualData,
|
|
125
|
+
session,
|
|
126
|
+
})
|
|
127
|
+
return await funcConfig.func(allServices, actualData, session!)
|
|
128
|
+
}
|
|
109
129
|
|
|
110
|
-
// Combine all middleware:
|
|
130
|
+
// Combine all middleware: inheritedMiddleware → wireMiddleware → funcMiddleware
|
|
111
131
|
const allMiddleware = combineMiddleware(wireType, wireId, {
|
|
112
|
-
|
|
113
|
-
|
|
132
|
+
wireInheritedMiddleware: inheritedMiddleware,
|
|
133
|
+
wireMiddleware,
|
|
134
|
+
funcInheritedMiddleware: funcMeta.middleware,
|
|
114
135
|
funcMiddleware: funcConfig.middleware,
|
|
115
|
-
funcTags: funcConfig.tags,
|
|
116
136
|
})
|
|
117
137
|
|
|
118
138
|
if (allMiddleware.length > 0) {
|
|
119
139
|
return (await runMiddleware<CorePikkuMiddleware>(
|
|
120
|
-
allServices,
|
|
121
140
|
{
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
rpc: allServices.rpc,
|
|
141
|
+
...singletonServices,
|
|
142
|
+
userSession,
|
|
125
143
|
},
|
|
144
|
+
interaction,
|
|
126
145
|
allMiddleware,
|
|
127
|
-
|
|
146
|
+
executeFunction
|
|
128
147
|
)) as Out
|
|
129
148
|
}
|
|
130
149
|
|
|
131
|
-
return (await
|
|
150
|
+
return (await executeFunction()) as Out
|
|
132
151
|
}
|
package/src/index.ts
CHANGED
|
@@ -16,12 +16,18 @@ export * from './wirings/scheduler/index.js'
|
|
|
16
16
|
export * from './wirings/rpc/index.js'
|
|
17
17
|
export * from './wirings/queue/index.js'
|
|
18
18
|
export * from './wirings/mcp/index.js'
|
|
19
|
+
export * from './wirings/cli/index.js'
|
|
19
20
|
export * from './errors/index.js'
|
|
20
21
|
export * from './middleware/index.js'
|
|
21
22
|
export * from './utils.js'
|
|
22
23
|
export * from './time-utils.js'
|
|
23
24
|
export { pikkuState } from './pikku-state.js'
|
|
24
|
-
export {
|
|
25
|
+
export {
|
|
26
|
+
runMiddleware,
|
|
27
|
+
registerMiddleware,
|
|
28
|
+
getMiddlewareByName,
|
|
29
|
+
addMiddleware,
|
|
30
|
+
} from './middleware-runner.js'
|
|
25
31
|
export { addPermission } from './permissions.js'
|
|
26
32
|
export { wireHTTP, addHTTPMiddleware } from './wirings/http/http-runner.js'
|
|
27
33
|
export { wireChannel } from './wirings/channel/channel-runner.js'
|
|
@@ -41,3 +47,4 @@ export {
|
|
|
41
47
|
getMCPToolsMeta,
|
|
42
48
|
getMCPPromptsMeta,
|
|
43
49
|
} from './wirings/mcp/mcp-runner.js'
|
|
50
|
+
export { wireCLI, runCLICommand } from './wirings/cli/cli-runner.js'
|
|
@@ -55,7 +55,7 @@ describe('combineMiddleware', () => {
|
|
|
55
55
|
PikkuWiringTypes.http,
|
|
56
56
|
Math.random().toString(),
|
|
57
57
|
{
|
|
58
|
-
|
|
58
|
+
wireMiddleware: [mockMiddleware1, mockMiddleware2],
|
|
59
59
|
}
|
|
60
60
|
)
|
|
61
61
|
|
|
@@ -93,7 +93,7 @@ describe('combineMiddleware', () => {
|
|
|
93
93
|
assert.equal(result[1], mockMiddleware2)
|
|
94
94
|
})
|
|
95
95
|
|
|
96
|
-
test('should execute middleware in correct order:
|
|
96
|
+
test('should execute middleware in correct order: wireInheritedMiddleware (tags) → wireMiddleware → funcInheritedMiddleware (tags) → funcMiddleware', () => {
|
|
97
97
|
// Setup tagged middleware
|
|
98
98
|
const wiringTagMiddleware: CorePikkuMiddleware = async (
|
|
99
99
|
services,
|
|
@@ -132,19 +132,19 @@ describe('combineMiddleware', () => {
|
|
|
132
132
|
PikkuWiringTypes.http,
|
|
133
133
|
Math.random().toString(),
|
|
134
134
|
{
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
wireInheritedMiddleware: [{ type: 'tag', tag: 'wiringTag' }],
|
|
136
|
+
wireMiddleware: [wiringMiddleware],
|
|
137
|
+
funcInheritedMiddleware: [{ type: 'tag', tag: 'funcTag' }],
|
|
137
138
|
funcMiddleware: [funcMiddleware],
|
|
138
|
-
funcTags: ['funcTag'],
|
|
139
139
|
}
|
|
140
140
|
)
|
|
141
141
|
|
|
142
142
|
assert.equal(result.length, 4)
|
|
143
|
-
// Order:
|
|
144
|
-
assert.equal(result[0], wiringTagMiddleware) //
|
|
145
|
-
assert.equal(result[1], wiringMiddleware) //
|
|
146
|
-
assert.equal(result[2],
|
|
147
|
-
assert.equal(result[3],
|
|
143
|
+
// Order: wireInheritedMiddleware (tags), wireMiddleware, funcInheritedMiddleware (tags), funcMiddleware
|
|
144
|
+
assert.equal(result[0], wiringTagMiddleware) // wireInheritedMiddleware tags first
|
|
145
|
+
assert.equal(result[1], wiringMiddleware) // wireMiddleware second
|
|
146
|
+
assert.equal(result[2], funcTagMiddleware) // funcInheritedMiddleware tags third
|
|
147
|
+
assert.equal(result[3], funcMiddleware) // funcMiddleware last
|
|
148
148
|
})
|
|
149
149
|
|
|
150
150
|
test('should handle wiring tags only', () => {
|
|
@@ -162,7 +162,7 @@ describe('combineMiddleware', () => {
|
|
|
162
162
|
PikkuWiringTypes.http,
|
|
163
163
|
Math.random().toString(),
|
|
164
164
|
{
|
|
165
|
-
|
|
165
|
+
wireInheritedMiddleware: [{ type: 'tag', tag: 'testTag' }],
|
|
166
166
|
}
|
|
167
167
|
)
|
|
168
168
|
|
|
@@ -185,7 +185,7 @@ describe('combineMiddleware', () => {
|
|
|
185
185
|
PikkuWiringTypes.http,
|
|
186
186
|
Math.random().toString(),
|
|
187
187
|
{
|
|
188
|
-
|
|
188
|
+
funcInheritedMiddleware: [{ type: 'tag', tag: 'funcTestTag' }],
|
|
189
189
|
}
|
|
190
190
|
)
|
|
191
191
|
|
|
@@ -216,7 +216,10 @@ describe('combineMiddleware', () => {
|
|
|
216
216
|
PikkuWiringTypes.http,
|
|
217
217
|
Math.random().toString(),
|
|
218
218
|
{
|
|
219
|
-
|
|
219
|
+
wireInheritedMiddleware: [
|
|
220
|
+
{ type: 'tag', tag: 'tag1' },
|
|
221
|
+
{ type: 'tag', tag: 'tag2' },
|
|
222
|
+
],
|
|
220
223
|
}
|
|
221
224
|
)
|
|
222
225
|
|
|
@@ -240,8 +243,13 @@ describe('combineMiddleware', () => {
|
|
|
240
243
|
PikkuWiringTypes.http,
|
|
241
244
|
Math.random().toString(),
|
|
242
245
|
{
|
|
243
|
-
|
|
244
|
-
|
|
246
|
+
wireInheritedMiddleware: [
|
|
247
|
+
{ type: 'tag', tag: 'existingTag' },
|
|
248
|
+
{ type: 'tag', tag: 'nonExistentTag' },
|
|
249
|
+
],
|
|
250
|
+
funcInheritedMiddleware: [
|
|
251
|
+
{ type: 'tag', tag: 'anotherNonExistentTag' },
|
|
252
|
+
],
|
|
245
253
|
}
|
|
246
254
|
)
|
|
247
255
|
|
|
@@ -276,7 +284,7 @@ describe('runMiddleware', () => {
|
|
|
276
284
|
{} as any,
|
|
277
285
|
{} as any,
|
|
278
286
|
combineMiddleware(PikkuWiringTypes.rpc, Math.random().toString(), {
|
|
279
|
-
|
|
287
|
+
wireMiddleware: [middleware1, middleware2, middleware1, middleware2],
|
|
280
288
|
}),
|
|
281
289
|
async () => {
|
|
282
290
|
executionOrder.push('main')
|