@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.
Files changed (99) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/function/function-runner.d.ts +13 -8
  3. package/dist/function/function-runner.js +49 -37
  4. package/dist/index.d.ts +3 -1
  5. package/dist/index.js +3 -1
  6. package/dist/middleware-runner.d.ts +61 -40
  7. package/dist/middleware-runner.js +118 -66
  8. package/dist/permissions.js +1 -0
  9. package/dist/pikku-state.d.ts +26 -1
  10. package/dist/pikku-state.js +10 -1
  11. package/dist/services/content-service.d.ts +2 -3
  12. package/dist/services/index.d.ts +0 -1
  13. package/dist/services/index.js +0 -1
  14. package/dist/services/local-content.d.ts +2 -4
  15. package/dist/types/core.types.d.ts +51 -2
  16. package/dist/types/core.types.js +21 -0
  17. package/dist/wirings/channel/channel-handler.d.ts +2 -2
  18. package/dist/wirings/channel/channel-handler.js +12 -9
  19. package/dist/wirings/channel/channel-runner.d.ts +0 -2
  20. package/dist/wirings/channel/channel-runner.js +2 -3
  21. package/dist/wirings/channel/channel.types.d.ts +5 -3
  22. package/dist/wirings/channel/local/local-channel-runner.js +12 -12
  23. package/dist/wirings/channel/serverless/serverless-channel-runner.js +7 -8
  24. package/dist/wirings/cli/channel/cli-channel-runner.d.ts +12 -0
  25. package/dist/wirings/cli/channel/cli-channel-runner.js +80 -0
  26. package/dist/wirings/cli/channel/index.d.ts +1 -0
  27. package/dist/wirings/cli/channel/index.js +1 -0
  28. package/dist/wirings/cli/cli-runner.d.ts +32 -0
  29. package/dist/wirings/cli/cli-runner.js +328 -0
  30. package/dist/wirings/cli/cli.types.d.ts +177 -0
  31. package/dist/wirings/cli/cli.types.js +1 -0
  32. package/dist/wirings/cli/command-parser.d.ts +19 -0
  33. package/dist/wirings/cli/command-parser.js +373 -0
  34. package/dist/wirings/cli/index.d.ts +5 -0
  35. package/dist/wirings/cli/index.js +5 -0
  36. package/dist/wirings/http/http-runner.d.ts +29 -10
  37. package/dist/wirings/http/http-runner.js +103 -131
  38. package/dist/wirings/http/http.types.d.ts +10 -10
  39. package/dist/wirings/http/index.d.ts +1 -1
  40. package/dist/wirings/http/index.js +1 -1
  41. package/dist/wirings/http/pikku-fetch-http-response.js +3 -1
  42. package/dist/wirings/http/routers/http-router.d.ts +0 -2
  43. package/dist/wirings/http/routers/path-to-regex.d.ts +1 -1
  44. package/dist/wirings/http/routers/path-to-regex.js +5 -34
  45. package/dist/wirings/mcp/mcp-runner.d.ts +4 -5
  46. package/dist/wirings/mcp/mcp-runner.js +30 -34
  47. package/dist/wirings/mcp/mcp.types.d.ts +11 -8
  48. package/dist/wirings/queue/queue-runner.d.ts +2 -2
  49. package/dist/wirings/queue/queue-runner.js +25 -27
  50. package/dist/wirings/queue/queue.types.d.ts +6 -5
  51. package/dist/wirings/rpc/index.d.ts +1 -1
  52. package/dist/wirings/rpc/index.js +1 -1
  53. package/dist/wirings/rpc/rpc-runner.d.ts +6 -18
  54. package/dist/wirings/rpc/rpc-runner.js +13 -8
  55. package/dist/wirings/scheduler/scheduler-runner.d.ts +2 -2
  56. package/dist/wirings/scheduler/scheduler-runner.js +37 -35
  57. package/dist/wirings/scheduler/scheduler.types.d.ts +4 -3
  58. package/package.json +4 -3
  59. package/src/function/function-runner.test.ts +73 -23
  60. package/src/function/function-runner.ts +74 -55
  61. package/src/index.ts +8 -1
  62. package/src/middleware-runner.test.ts +24 -16
  63. package/src/middleware-runner.ts +136 -83
  64. package/src/permissions.ts +1 -0
  65. package/src/pikku-state.ts +47 -2
  66. package/src/services/content-service.ts +5 -4
  67. package/src/services/index.ts +0 -1
  68. package/src/services/local-content.ts +9 -4
  69. package/src/types/core.types.ts +74 -3
  70. package/src/wirings/channel/channel-handler.ts +9 -13
  71. package/src/wirings/channel/channel-runner.ts +2 -6
  72. package/src/wirings/channel/channel.types.ts +5 -1
  73. package/src/wirings/channel/local/local-channel-runner.ts +25 -15
  74. package/src/wirings/channel/serverless/serverless-channel-runner.ts +15 -17
  75. package/src/wirings/cli/channel/cli-channel-runner.ts +118 -0
  76. package/src/wirings/cli/channel/index.ts +1 -0
  77. package/src/wirings/cli/cli-runner.test.ts +382 -0
  78. package/src/wirings/cli/cli-runner.ts +503 -0
  79. package/src/wirings/cli/cli.types.ts +320 -0
  80. package/src/wirings/cli/command-parser.test.ts +440 -0
  81. package/src/wirings/cli/command-parser.ts +470 -0
  82. package/src/wirings/cli/index.ts +12 -0
  83. package/src/wirings/http/http-runner.test.ts +8 -7
  84. package/src/wirings/http/http-runner.ts +126 -159
  85. package/src/wirings/http/http.types.ts +56 -11
  86. package/src/wirings/http/index.ts +1 -1
  87. package/src/wirings/http/pikku-fetch-http-response.ts +3 -1
  88. package/src/wirings/http/routers/http-router.ts +0 -2
  89. package/src/wirings/http/routers/path-to-regex.test.ts +4 -5
  90. package/src/wirings/http/routers/path-to-regex.ts +6 -43
  91. package/src/wirings/mcp/mcp-runner.ts +56 -55
  92. package/src/wirings/mcp/mcp.types.ts +23 -8
  93. package/src/wirings/queue/queue-runner.ts +44 -47
  94. package/src/wirings/queue/queue.types.ts +10 -6
  95. package/src/wirings/rpc/index.ts +1 -1
  96. package/src/wirings/rpc/rpc-runner.ts +27 -9
  97. package/src/wirings/scheduler/scheduler-runner.ts +57 -56
  98. package/src/wirings/scheduler/scheduler.types.ts +9 -2
  99. 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 mockServices: CoreServices = {
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 → funcMiddlewarefuncTags', async () => {
46
+ test('should execute middleware in correct order: wiringTags → wiringMiddleware → funcTagsfuncMiddleware', 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
- middleware: [createMiddleware('wiringMiddleware')],
67
- tags: ['wiringTag'],
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: wiringTags, wiringMiddleware, funcMiddleware, funcTags
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
- middleware: [wiringMiddleware],
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
- session: testSession,
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
- session,
49
+ userSession,
50
+ auth: wiringAuth,
53
51
  permissions: wiringPermissions,
54
- middleware: wiringMiddleware,
52
+ inheritedMiddleware,
53
+ wireMiddleware,
55
54
  coerceDataFromSchema,
56
55
  tags = [],
56
+ interaction,
57
57
  }: {
58
- getAllServices: () => Promise<CoreServices> | CoreServices
59
- data: In
60
- session?: CoreUserSession
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
- middleware?: CorePikkuMiddleware[]
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
- if (funcConfig.auth && !session) {
77
- throw new ForbiddenError(
78
- `Function ${funcName} requires authentication even though transport does not`
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
- const allServices = await getAllServices()
98
+ // Evaluate the data from the lazy function
99
+ const actualData = await data()
83
100
 
84
- const inputSchemaName = funcMeta.inputSchemaName
85
- if (inputSchemaName) {
86
- // Validate request data against the defined schema, if any
87
- await validateSchema(
88
- allServices.logger,
89
- allServices.schema,
90
- inputSchemaName,
91
- data
92
- )
93
- // Coerce (top level) query string parameters or date objects if specified by the schema
94
- if (coerceDataFromSchema) {
95
- coerceTopLevelDataFromSchema(inputSchemaName, data)
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
- // Run permission checks in the specified order
100
- await runPermissions(wireType, wireId, {
101
- wiringTags: tags,
102
- wiringPermissions,
103
- funcTags: funcConfig.tags,
104
- funcPermissions: funcConfig.permissions,
105
- allServices,
106
- data,
107
- session,
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: wiring tags wiring middleware func middleware → func tags
130
+ // Combine all middleware: inheritedMiddlewarewireMiddlewarefuncMiddleware
111
131
  const allMiddleware = combineMiddleware(wireType, wireId, {
112
- wiringTags: tags,
113
- wiringMiddleware,
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
- http: allServices.http,
123
- mcp: allServices.mcp,
124
- rpc: allServices.rpc,
141
+ ...singletonServices,
142
+ userSession,
125
143
  },
144
+ interaction,
126
145
  allMiddleware,
127
- async () => await funcConfig.func(allServices, data, session!)
146
+ executeFunction
128
147
  )) as Out
129
148
  }
130
149
 
131
- return (await funcConfig.func(allServices, data, session!)) as Out
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 { addMiddleware, runMiddleware } from './middleware-runner.js'
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
- wiringMiddleware: [mockMiddleware1, mockMiddleware2],
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: wiringTagswiringMiddlewarefuncMiddlewarefuncTags', () => {
96
+ test('should execute middleware in correct order: wireInheritedMiddleware (tags) wireMiddlewarefuncInheritedMiddleware (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
- wiringMiddleware: [wiringMiddleware],
136
- wiringTags: ['wiringTag'],
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: wiringTags, wiringMiddleware, funcMiddleware, funcTags
144
- assert.equal(result[0], wiringTagMiddleware) // wiringTags first
145
- assert.equal(result[1], wiringMiddleware) // wiringMiddleware second
146
- assert.equal(result[2], funcMiddleware) // funcMiddleware third
147
- assert.equal(result[3], funcTagMiddleware) // funcTags last
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
- wiringTags: ['testTag'],
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
- funcTags: ['funcTestTag'],
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
- wiringTags: ['tag1', 'tag2'],
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
- wiringTags: ['existingTag', 'nonExistentTag'],
244
- funcTags: ['anotherNonExistentTag'],
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
- wiringMiddleware: [middleware1, middleware2, middleware1, middleware2],
287
+ wireMiddleware: [middleware1, middleware2, middleware1, middleware2],
280
288
  }),
281
289
  async () => {
282
290
  executionOrder.push('main')