lambder 2.0.3 → 2.0.4
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/dist/Lambder.d.ts +1 -1
- package/package.json +1 -1
- package/src/Lambder.ts +2 -2
- package/tests/use-plugin.test.ts +22 -1
package/dist/Lambder.d.ts
CHANGED
|
@@ -115,7 +115,7 @@ export default class Lambder<TSessionData = any, _TContract extends Record<strin
|
|
|
115
115
|
private handleNoMatchedAction;
|
|
116
116
|
addRoute(condition: Path | ConditionFunction | RegExp, actionFn: ActionFunction): this;
|
|
117
117
|
addSessionRoute(condition: Path | ConditionFunction | RegExp, actionFn: SessionActionFunction<TSessionData>): this;
|
|
118
|
-
use<_TNewContract extends Record<string, any>>(plugin: (lambder: Lambder<TSessionData, _TContract>) => Lambder<TSessionData, _TNewContract>): Lambder<TSessionData, _TNewContract>;
|
|
118
|
+
use<_TNewContract extends Record<string, any>>(plugin: (lambder: Lambder<TSessionData, _TContract>) => Lambder<TSessionData, _TNewContract>): Lambder<TSessionData, _TNewContract extends _TContract ? _TNewContract : (_TContract & _TNewContract)>;
|
|
119
119
|
addApi<TName extends string, TInput extends z.ZodTypeAny, TOutput extends z.ZodTypeAny>(name: TName, schema: {
|
|
120
120
|
input: TInput;
|
|
121
121
|
output: TOutput;
|
package/package.json
CHANGED
package/src/Lambder.ts
CHANGED
|
@@ -285,8 +285,8 @@ export default class Lambder<TSessionData = any, _TContract extends Record<strin
|
|
|
285
285
|
// Plugin system
|
|
286
286
|
public use<_TNewContract extends Record<string, any>>(
|
|
287
287
|
plugin: (lambder: Lambder<TSessionData, _TContract>) => Lambder<TSessionData, _TNewContract>
|
|
288
|
-
): Lambder<TSessionData, _TNewContract> {
|
|
289
|
-
return plugin(this);
|
|
288
|
+
): Lambder<TSessionData, _TNewContract extends _TContract ? _TNewContract : (_TContract & _TNewContract)> {
|
|
289
|
+
return plugin(this) as any;
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
// Typed API with Zod
|
package/tests/use-plugin.test.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This file tests the plugin system that allows modular API composition
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { describe, it, expect } from 'vitest';
|
|
7
|
+
import { describe, it, expect, expectTypeOf } from 'vitest';
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import Lambder from '../src/Lambder.js';
|
|
10
10
|
import LambderCaller from '../src/LambderCaller.js';
|
|
@@ -435,3 +435,24 @@ describe('Plugin System - Type Safety', () => {
|
|
|
435
435
|
expect(caller).toBeDefined();
|
|
436
436
|
});
|
|
437
437
|
});
|
|
438
|
+
|
|
439
|
+
// ============================================================================
|
|
440
|
+
// Test 7: Non-Generic Plugin Type Accumulation
|
|
441
|
+
// ============================================================================
|
|
442
|
+
|
|
443
|
+
describe('Plugin System - Non-Generic Plugins', () => {
|
|
444
|
+
it('should accumulate types correctly when using non-generic plugins', () => {
|
|
445
|
+
const plugin1 = (l: Lambder) => l.addApi('api1', { input: z.void(), output: z.void() }, async (ctx, res) => res.raw({ statusCode: 200, body: '' }));
|
|
446
|
+
const plugin2 = (l: Lambder) => l.addApi('api2', { input: z.void(), output: z.void() }, async (ctx, res) => res.raw({ statusCode: 200, body: '' }));
|
|
447
|
+
|
|
448
|
+
const lambder = new Lambder({ publicPath: '', apiPath: '' })
|
|
449
|
+
.use(plugin1)
|
|
450
|
+
.use(plugin2);
|
|
451
|
+
|
|
452
|
+
type Contract = typeof lambder.ApiContractType;
|
|
453
|
+
|
|
454
|
+
// Check if both api1 and api2 exist in Contract
|
|
455
|
+
expectTypeOf<Contract>().toHaveProperty('api1');
|
|
456
|
+
expectTypeOf<Contract>().toHaveProperty('api2');
|
|
457
|
+
});
|
|
458
|
+
});
|