lambder 1.0.147 → 2.0.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.
Files changed (39) hide show
  1. package/Readme.md +355 -410
  2. package/dist/Lambder.d.ts +47 -21
  3. package/dist/Lambder.js +79 -24
  4. package/dist/LambderApiContract.d.ts +10 -42
  5. package/dist/LambderApiContract.js +2 -22
  6. package/dist/LambderCaller.js +2 -2
  7. package/dist/LambderMSW.js +0 -4
  8. package/dist/LambderResolver.d.ts +16 -17
  9. package/dist/LambderResponseBuilder.d.ts +2 -3
  10. package/dist/LambderResponseBuilder.js +1 -3
  11. package/dist/LambderUtils.js +1 -3
  12. package/dist/index.d.ts +1 -1
  13. package/docs/LAMBDER_MSW.md +6 -6
  14. package/docs/TYPE_SAFE_QUICK_START.md +54 -177
  15. package/examples/msw-testing-example.ts +36 -33
  16. package/examples/secure-session-example.ts +50 -34
  17. package/examples/zod-chained-api-example.ts +63 -0
  18. package/package.json +3 -2
  19. package/src/Lambder.ts +124 -83
  20. package/src/LambderApiContract.ts +7 -50
  21. package/src/LambderCaller.ts +2 -2
  22. package/src/LambderMSW.ts +0 -7
  23. package/src/LambderResolver.ts +21 -24
  24. package/src/LambderResponseBuilder.ts +4 -7
  25. package/src/LambderUtils.ts +1 -3
  26. package/src/index.ts +0 -3
  27. package/tests/UNTESTED_FEATURES.md +263 -0
  28. package/tests/error-handling.test.ts +585 -0
  29. package/tests/hooks.test.ts +561 -0
  30. package/tests/output-type-runtime.test.ts +80 -64
  31. package/tests/routes.test.ts +542 -0
  32. package/tests/session.test.ts +38 -24
  33. package/tests/type-safety.test.ts +147 -97
  34. package/tests/use-plugin.test.ts +437 -0
  35. package/OUTPUT_TYPE_ENFORCEMENT_SUMMARY.md +0 -90
  36. package/examples/output-type-enforcement-example.ts +0 -218
  37. package/examples/simplified-typed-api-example.ts +0 -365
  38. package/examples/test-output-type-enforcement.ts +0 -101
  39. package/test-type-enforcement.ts +0 -111
@@ -1,111 +0,0 @@
1
- // Test file to verify LambderMSW type enforcement
2
- import LambderMSW from './src/LambderMSW';
3
- import type { ApiContract } from './src/LambderApiContract';
4
-
5
- // Define a test API contract
6
- type TestContract = ApiContract<{
7
- 'public.getInitialPageData': {
8
- input: void;
9
- output: {
10
- userLocationData: {
11
- country: string;
12
- region: string;
13
- regionCode: string;
14
- city: string;
15
- zipCode: string;
16
- lat: number;
17
- lng: number;
18
- };
19
- sessionUser: {
20
- id: string;
21
- username: string;
22
- email: string;
23
- name: string;
24
- bio: string;
25
- // NOTE: 's' property should NOT be here
26
- };
27
- };
28
- };
29
- }>;
30
-
31
- const apiMocker = new LambderMSW<TestContract>({
32
- apiPath: '/secure',
33
- });
34
-
35
- // TEST 1: Extra properties - TypeScript allows this due to structural typing
36
- const handler1 = apiMocker.mockApi(
37
- 'public.getInitialPageData',
38
- async () => {
39
- return {
40
- userLocationData: {
41
- country: 'United States',
42
- region: 'California',
43
- regionCode: 'CA',
44
- city: 'San Francisco',
45
- zipCode: '94102',
46
- lat: 37.7749,
47
- lng: -122.4194,
48
- },
49
- sessionUser: {
50
- id: 'mock-user-123',
51
- username: 'mockuser',
52
- email: 'mock@example.com',
53
- name: 'Mock User',
54
- bio: 'This is a mock user for development',
55
- s: 43 // ⚠️ Extra property - TypeScript structural typing allows this
56
- },
57
- };
58
- }
59
- );
60
-
61
- // TEST 2: Missing required property - THIS WILL CAUSE AN ERROR!
62
- const handler2 = apiMocker.mockApi(
63
- 'public.getInitialPageData',
64
- async () => {
65
- return {
66
- userLocationData: {
67
- country: 'United States',
68
- region: 'California',
69
- regionCode: 'CA',
70
- city: 'San Francisco',
71
- zipCode: '94102',
72
- lat: 37.7749,
73
- lng: -122.4194,
74
- },
75
- sessionUser: {
76
- id: 'mock-user-123',
77
- username: 'mockuser',
78
- email: 'mock@example.com',
79
- name: 'Mock User',
80
- // bio: 'This is a mock user for development', // ❌ Missing required property - ERROR!
81
- },
82
- };
83
- }
84
- );
85
-
86
- // TEST 3: Wrong type - THIS WILL CAUSE AN ERROR!
87
- const handler3 = apiMocker.mockApi(
88
- 'public.getInitialPageData',
89
- async () => {
90
- return {
91
- userLocationData: {
92
- country: 'United States',
93
- region: 'California',
94
- regionCode: 'CA',
95
- city: 'San Francisco',
96
- zipCode: '94102',
97
- lat: 37.7749,
98
- lng: -122.4194,
99
- },
100
- sessionUser: {
101
- id: 123, // ❌ Wrong type - should be string - ERROR!
102
- username: 'mockuser',
103
- email: 'mock@example.com',
104
- name: 'Mock User',
105
- bio: 'This is a mock user for development',
106
- },
107
- };
108
- }
109
- );
110
-
111
- console.log('Check for TypeScript errors above!');