@facetlayer/prism-framework 0.4.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 (42) hide show
  1. package/.claude/settings.local.json +20 -0
  2. package/CHANGELOG +28 -0
  3. package/CLAUDE.md +44 -0
  4. package/README.md +47 -0
  5. package/build.mts +8 -0
  6. package/dist/call-command.d.ts +13 -0
  7. package/dist/call-command.d.ts.map +1 -0
  8. package/dist/cli.d.ts +3 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +475 -0
  11. package/dist/config/ConfigFile.d.ts +7 -0
  12. package/dist/config/ConfigFile.d.ts.map +1 -0
  13. package/dist/config/index.d.ts +4 -0
  14. package/dist/config/index.d.ts.map +1 -0
  15. package/dist/config/loadConfig.d.ts +11 -0
  16. package/dist/config/loadConfig.d.ts.map +1 -0
  17. package/dist/generate-api-clients.d.ts +6 -0
  18. package/dist/generate-api-clients.d.ts.map +1 -0
  19. package/dist/getPorts.d.ts +10 -0
  20. package/dist/getPorts.d.ts.map +1 -0
  21. package/dist/list-endpoints-command.d.ts +5 -0
  22. package/dist/list-endpoints-command.d.ts.map +1 -0
  23. package/dist/loadEnv.d.ts +12 -0
  24. package/dist/loadEnv.d.ts.map +1 -0
  25. package/docs/endpoint-tools.md +116 -0
  26. package/docs/env-files.md +64 -0
  27. package/docs/generate-api-clients-config.md +84 -0
  28. package/docs/getting-started.md +86 -0
  29. package/package.json +43 -0
  30. package/src/call-command.ts +147 -0
  31. package/src/cli.ts +163 -0
  32. package/src/config/ConfigFile.ts +7 -0
  33. package/src/config/index.ts +3 -0
  34. package/src/config/loadConfig.ts +58 -0
  35. package/src/generate-api-clients.ts +203 -0
  36. package/src/getPorts.ts +39 -0
  37. package/src/list-endpoints-command.ts +34 -0
  38. package/src/loadEnv.ts +59 -0
  39. package/test/call-command.test.ts +96 -0
  40. package/test/generate-api-clients.test.ts +33 -0
  41. package/test/generate-api-clients.test.ts.disabled +75 -0
  42. package/tsconfig.json +21 -0
@@ -0,0 +1,33 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { convertToExpressPath } from '../src/generate-api-clients';
3
+
4
+ describe('convertToExpressPath', () => {
5
+ it('should convert single path parameter', () => {
6
+ expect(convertToExpressPath('/users/{id}')).toBe('/users/:id');
7
+ });
8
+
9
+ it('should convert multiple path parameters', () => {
10
+ expect(convertToExpressPath('/users/{userId}/posts/{postId}')).toBe('/users/:userId/posts/:postId');
11
+ });
12
+
13
+ it('should handle paths without parameters', () => {
14
+ expect(convertToExpressPath('/users')).toBe('/users');
15
+ expect(convertToExpressPath('/api/health')).toBe('/api/health');
16
+ });
17
+
18
+ it('should handle root path', () => {
19
+ expect(convertToExpressPath('/')).toBe('/');
20
+ });
21
+
22
+ it('should handle complex parameter names', () => {
23
+ expect(convertToExpressPath('/designs/{designId}/nodes/{nodeId}')).toBe('/designs/:designId/nodes/:nodeId');
24
+ });
25
+
26
+ it('should handle parameter at the end of path', () => {
27
+ expect(convertToExpressPath('/api/items/{id}')).toBe('/api/items/:id');
28
+ });
29
+
30
+ it('should handle parameter with underscores', () => {
31
+ expect(convertToExpressPath('/api/{user_id}/profile')).toBe('/api/:user_id/profile');
32
+ });
33
+ });
@@ -0,0 +1,75 @@
1
+ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
2
+ import { generateApiClients } from '../src/generate-api-clients';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+
6
+ describe('generateApiClients', () => {
7
+ const testOutputDir = path.join(__dirname, 'temp');
8
+ const testOutputPath = path.join(testOutputDir, 'src/api/api-client-types.ts');
9
+
10
+ beforeAll(() => {
11
+ // Ensure test directory exists
12
+ if (!fs.existsSync(testOutputDir)) {
13
+ fs.mkdirSync(testOutputDir, { recursive: true });
14
+ }
15
+ });
16
+
17
+ afterAll(() => {
18
+ // Clean up test files
19
+ if (fs.existsSync(testOutputPath)) {
20
+ fs.unlinkSync(testOutputPath);
21
+ }
22
+ });
23
+
24
+ it('should generate API client types from OpenAPI schema', async () => {
25
+ // This test requires a running Prism server
26
+ // Read the base URL from environment or use default
27
+ const baseUrl = process.env.PRISM_API_URL || 'http://localhost:3000';
28
+
29
+ // Change working directory to test output directory
30
+ const originalCwd = process.cwd();
31
+ process.chdir(testOutputDir);
32
+
33
+ try {
34
+ await generateApiClients(baseUrl);
35
+
36
+ // Check that the file was created
37
+ expect(fs.existsSync(testOutputPath)).toBe(true);
38
+
39
+ // Read the generated file
40
+ const content = fs.readFileSync(testOutputPath, 'utf-8');
41
+
42
+ // Verify header comment
43
+ expect(content).toContain('// Generated API client types');
44
+ expect(content).toContain('// Auto-generated from OpenAPI schema - do not edit manually');
45
+
46
+ // Verify it contains endpoint types
47
+ expect(content).toContain('// Endpoint Types');
48
+
49
+ // Verify it contains generic RequestType
50
+ expect(content).toContain('export type RequestType<T extends string>');
51
+
52
+ // Verify it contains generic ResponseType
53
+ expect(content).toContain('export type ResponseType<T extends string>');
54
+
55
+ console.log('\n📄 Generated file content preview:');
56
+ console.log(content.slice(0, 500) + '...\n');
57
+ } finally {
58
+ // Restore original working directory
59
+ process.chdir(originalCwd);
60
+ }
61
+ });
62
+
63
+ it('should handle fetch errors gracefully', async () => {
64
+ const invalidUrl = 'http://localhost:99999';
65
+
66
+ const originalCwd = process.cwd();
67
+ process.chdir(testOutputDir);
68
+
69
+ try {
70
+ await expect(generateApiClients(invalidUrl)).rejects.toThrow();
71
+ } finally {
72
+ process.chdir(originalCwd);
73
+ }
74
+ });
75
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "esnext",
5
+ "lib": ["ES2020"],
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "outDir": "./dist",
9
+ "rootDir": "./src",
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "skipLibCheck": true,
13
+ "noEmit": true,
14
+ "allowImportingTsExtensions": true,
15
+ "forceConsistentCasingInFileNames": true,
16
+ "moduleResolution": "bundler",
17
+ "resolveJsonModule": true
18
+ },
19
+ "include": ["src/**/*"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }