@engjts/nexus 0.1.7 → 0.1.9
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/advanced/playground/generatePlaygroundHTML.d.ts.map +1 -1
- package/dist/advanced/playground/generatePlaygroundHTML.js +107 -0
- package/dist/advanced/playground/generatePlaygroundHTML.js.map +1 -1
- package/dist/advanced/playground/playground.d.ts +19 -0
- package/dist/advanced/playground/playground.d.ts.map +1 -1
- package/dist/advanced/playground/playground.js +70 -0
- package/dist/advanced/playground/playground.js.map +1 -1
- package/dist/advanced/playground/types.d.ts +20 -0
- package/dist/advanced/playground/types.d.ts.map +1 -1
- package/dist/core/application.d.ts +14 -0
- package/dist/core/application.d.ts.map +1 -1
- package/dist/core/application.js +173 -71
- package/dist/core/application.js.map +1 -1
- package/dist/core/context-pool.d.ts +2 -13
- package/dist/core/context-pool.d.ts.map +1 -1
- package/dist/core/context-pool.js +7 -45
- package/dist/core/context-pool.js.map +1 -1
- package/dist/core/context.d.ts +108 -5
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +449 -53
- package/dist/core/context.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +9 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/middleware.d.ts +6 -0
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/middleware.js +83 -84
- package/dist/core/middleware.js.map +1 -1
- package/dist/core/performance/fast-json.d.ts +149 -0
- package/dist/core/performance/fast-json.d.ts.map +1 -0
- package/dist/core/performance/fast-json.js +473 -0
- package/dist/core/performance/fast-json.js.map +1 -0
- package/dist/core/router/file-router.d.ts +20 -7
- package/dist/core/router/file-router.d.ts.map +1 -1
- package/dist/core/router/file-router.js +41 -13
- package/dist/core/router/file-router.js.map +1 -1
- package/dist/core/router/index.d.ts +6 -0
- package/dist/core/router/index.d.ts.map +1 -1
- package/dist/core/router/index.js +33 -6
- package/dist/core/router/index.js.map +1 -1
- package/dist/core/router/radix-tree.d.ts +4 -1
- package/dist/core/router/radix-tree.d.ts.map +1 -1
- package/dist/core/router/radix-tree.js +7 -3
- package/dist/core/router/radix-tree.js.map +1 -1
- package/dist/core/serializer.d.ts +251 -0
- package/dist/core/serializer.d.ts.map +1 -0
- package/dist/core/serializer.js +290 -0
- package/dist/core/serializer.js.map +1 -0
- package/dist/core/types.d.ts +39 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
- package/documentation/01-getting-started.md +0 -240
- package/documentation/02-context.md +0 -335
- package/documentation/03-routing.md +0 -397
- package/documentation/04-middleware.md +0 -483
- package/documentation/05-validation.md +0 -514
- package/documentation/06-error-handling.md +0 -465
- package/documentation/07-performance.md +0 -364
- package/documentation/08-adapters.md +0 -470
- package/documentation/09-api-reference.md +0 -548
- package/documentation/10-examples.md +0 -582
- package/documentation/11-deployment.md +0 -477
- package/documentation/12-sentry.md +0 -620
- package/documentation/13-sentry-data-storage.md +0 -996
- package/documentation/14-sentry-data-reference.md +0 -457
- package/documentation/15-sentry-summary.md +0 -409
- package/documentation/16-alerts-system.md +0 -745
- package/documentation/17-alert-adapters.md +0 -696
- package/documentation/18-alerts-implementation-summary.md +0 -385
- package/documentation/19-class-based-routing.md +0 -840
- package/documentation/20-websocket-realtime.md +0 -813
- package/documentation/21-cache-system.md +0 -510
- package/documentation/22-job-queue.md +0 -772
- package/documentation/23-sentry-plugin.md +0 -551
- package/documentation/24-testing-utilities.md +0 -1287
- package/documentation/25-api-versioning.md +0 -533
- package/documentation/26-context-store.md +0 -607
- package/documentation/27-dependency-injection.md +0 -329
- package/documentation/28-lifecycle-hooks.md +0 -521
- package/documentation/29-package-structure.md +0 -196
- package/documentation/30-plugin-system.md +0 -414
- package/documentation/31-jwt-authentication.md +0 -597
- package/documentation/32-cli.md +0 -268
- package/documentation/ALERTS-COMPLETE-SUMMARY.md +0 -429
- package/documentation/ALERTS-INDEX.md +0 -330
- package/documentation/ALERTS-QUICK-REFERENCE.md +0 -286
- package/documentation/README.md +0 -178
- package/documentation/index.html +0 -34
- package/modern_framework_paper.md +0 -1870
- package/public/css/style.css +0 -87
- package/public/index.html +0 -34
- package/public/js/app.js +0 -27
- package/src/advanced/cache/InMemoryCacheStore.ts +0 -68
- package/src/advanced/cache/MultiTierCache.ts +0 -194
- package/src/advanced/cache/RedisCacheStore.ts +0 -341
- package/src/advanced/cache/index.ts +0 -5
- package/src/advanced/cache/types.ts +0 -40
- package/src/advanced/graphql/SimpleDataLoader.ts +0 -42
- package/src/advanced/graphql/index.ts +0 -22
- package/src/advanced/graphql/server.ts +0 -252
- package/src/advanced/graphql/types.ts +0 -42
- package/src/advanced/jobs/InMemoryQueueStore.ts +0 -68
- package/src/advanced/jobs/JobQueue.ts +0 -556
- package/src/advanced/jobs/RedisQueueStore.ts +0 -367
- package/src/advanced/jobs/index.ts +0 -5
- package/src/advanced/jobs/types.ts +0 -70
- package/src/advanced/observability/APMManager.ts +0 -163
- package/src/advanced/observability/AlertManager.ts +0 -109
- package/src/advanced/observability/MetricRegistry.ts +0 -151
- package/src/advanced/observability/ObservabilityCenter.ts +0 -304
- package/src/advanced/observability/StructuredLogger.ts +0 -154
- package/src/advanced/observability/TracingManager.ts +0 -117
- package/src/advanced/observability/adapters.ts +0 -304
- package/src/advanced/observability/createObservabilityMiddleware.ts +0 -63
- package/src/advanced/observability/index.ts +0 -11
- package/src/advanced/observability/types.ts +0 -174
- package/src/advanced/playground/extractPathParams.ts +0 -6
- package/src/advanced/playground/generateFieldExample.ts +0 -31
- package/src/advanced/playground/generatePlaygroundHTML.ts +0 -1849
- package/src/advanced/playground/generateSummary.ts +0 -19
- package/src/advanced/playground/getTagFromPath.ts +0 -9
- package/src/advanced/playground/index.ts +0 -8
- package/src/advanced/playground/playground.ts +0 -170
- package/src/advanced/playground/types.ts +0 -20
- package/src/advanced/playground/zodToExample.ts +0 -16
- package/src/advanced/playground/zodToParams.ts +0 -15
- package/src/advanced/postman/buildAuth.ts +0 -31
- package/src/advanced/postman/buildBody.ts +0 -15
- package/src/advanced/postman/buildQueryParams.ts +0 -27
- package/src/advanced/postman/buildRequestItem.ts +0 -36
- package/src/advanced/postman/buildResponses.ts +0 -11
- package/src/advanced/postman/buildUrl.ts +0 -33
- package/src/advanced/postman/capitalize.ts +0 -4
- package/src/advanced/postman/generateCollection.ts +0 -59
- package/src/advanced/postman/generateEnvironment.ts +0 -34
- package/src/advanced/postman/generateExampleFromZod.ts +0 -21
- package/src/advanced/postman/generateFieldExample.ts +0 -45
- package/src/advanced/postman/generateName.ts +0 -20
- package/src/advanced/postman/generateUUID.ts +0 -11
- package/src/advanced/postman/getTagFromPath.ts +0 -10
- package/src/advanced/postman/index.ts +0 -28
- package/src/advanced/postman/postman.ts +0 -156
- package/src/advanced/postman/slugify.ts +0 -7
- package/src/advanced/postman/types.ts +0 -140
- package/src/advanced/realtime/index.ts +0 -18
- package/src/advanced/realtime/websocket.ts +0 -231
- package/src/advanced/sentry/index.ts +0 -1236
- package/src/advanced/sentry/types.ts +0 -355
- package/src/advanced/static/generateDirectoryListing.ts +0 -47
- package/src/advanced/static/generateETag.ts +0 -7
- package/src/advanced/static/getMimeType.ts +0 -9
- package/src/advanced/static/index.ts +0 -32
- package/src/advanced/static/isSafePath.ts +0 -13
- package/src/advanced/static/publicDir.ts +0 -21
- package/src/advanced/static/serveStatic.ts +0 -225
- package/src/advanced/static/spa.ts +0 -24
- package/src/advanced/static/types.ts +0 -159
- package/src/advanced/swagger/SwaggerGenerator.ts +0 -66
- package/src/advanced/swagger/buildOperation.ts +0 -61
- package/src/advanced/swagger/buildParameters.ts +0 -61
- package/src/advanced/swagger/buildRequestBody.ts +0 -21
- package/src/advanced/swagger/buildResponses.ts +0 -54
- package/src/advanced/swagger/capitalize.ts +0 -5
- package/src/advanced/swagger/convertPath.ts +0 -9
- package/src/advanced/swagger/createSwagger.ts +0 -12
- package/src/advanced/swagger/generateOperationId.ts +0 -21
- package/src/advanced/swagger/generateSpec.ts +0 -105
- package/src/advanced/swagger/generateSummary.ts +0 -24
- package/src/advanced/swagger/generateSwaggerUI.ts +0 -70
- package/src/advanced/swagger/generateThemeCss.ts +0 -53
- package/src/advanced/swagger/index.ts +0 -25
- package/src/advanced/swagger/swagger.ts +0 -237
- package/src/advanced/swagger/types.ts +0 -206
- package/src/advanced/swagger/zodFieldToOpenAPI.ts +0 -94
- package/src/advanced/swagger/zodSchemaToOpenAPI.ts +0 -50
- package/src/advanced/swagger/zodToOpenAPI.ts +0 -22
- package/src/advanced/testing/factory.ts +0 -509
- package/src/advanced/testing/harness.ts +0 -612
- package/src/advanced/testing/index.ts +0 -430
- package/src/advanced/testing/load-test.ts +0 -618
- package/src/advanced/testing/mock-server.ts +0 -498
- package/src/advanced/testing/mock.ts +0 -670
- package/src/cli/bin.ts +0 -9
- package/src/cli/cli.ts +0 -158
- package/src/cli/commands/add.ts +0 -178
- package/src/cli/commands/build.ts +0 -73
- package/src/cli/commands/create.ts +0 -166
- package/src/cli/commands/dev.ts +0 -85
- package/src/cli/commands/generate.ts +0 -99
- package/src/cli/commands/help.ts +0 -95
- package/src/cli/commands/init.ts +0 -91
- package/src/cli/commands/version.ts +0 -38
- package/src/cli/index.ts +0 -6
- package/src/cli/templates/generators.ts +0 -359
- package/src/cli/templates/index.ts +0 -680
- package/src/cli/utils/exec.ts +0 -52
- package/src/cli/utils/file-system.ts +0 -78
- package/src/cli/utils/logger.ts +0 -111
- package/src/core/adapter.ts +0 -88
- package/src/core/application.ts +0 -1335
- package/src/core/context-pool.ts +0 -127
- package/src/core/context.ts +0 -412
- package/src/core/index.ts +0 -80
- package/src/core/middleware.ts +0 -262
- package/src/core/performance/buffer-pool.ts +0 -108
- package/src/core/performance/middleware-optimizer.ts +0 -162
- package/src/core/plugin/PluginManager.ts +0 -435
- package/src/core/plugin/builder.ts +0 -358
- package/src/core/plugin/index.ts +0 -50
- package/src/core/plugin/types.ts +0 -214
- package/src/core/router/file-router.ts +0 -594
- package/src/core/router/index.ts +0 -227
- package/src/core/router/radix-tree.ts +0 -226
- package/src/core/store/index.ts +0 -30
- package/src/core/store/registry.ts +0 -178
- package/src/core/store/request-store.ts +0 -240
- package/src/core/store/types.ts +0 -233
- package/src/core/types.ts +0 -574
- package/src/database/adapter.ts +0 -35
- package/src/database/adapters/index.ts +0 -1
- package/src/database/adapters/mysql.ts +0 -669
- package/src/database/database.ts +0 -70
- package/src/database/dialect.ts +0 -388
- package/src/database/index.ts +0 -12
- package/src/database/migrations.ts +0 -86
- package/src/database/optimizer.ts +0 -125
- package/src/database/query-builder.ts +0 -404
- package/src/database/realtime.ts +0 -53
- package/src/database/schema.ts +0 -71
- package/src/database/transactions.ts +0 -56
- package/src/database/types.ts +0 -87
- package/src/deployment/cluster.ts +0 -471
- package/src/deployment/config.ts +0 -454
- package/src/deployment/docker.ts +0 -599
- package/src/deployment/graceful-shutdown.ts +0 -373
- package/src/deployment/index.ts +0 -56
- package/src/index.ts +0 -264
- package/src/security/adapter.ts +0 -318
- package/src/security/auth/JWTPlugin.ts +0 -234
- package/src/security/auth/JWTProvider.ts +0 -316
- package/src/security/auth/adapter.ts +0 -12
- package/src/security/auth/jwt.ts +0 -234
- package/src/security/auth/middleware.ts +0 -188
- package/src/security/csrf.ts +0 -220
- package/src/security/headers.ts +0 -108
- package/src/security/index.ts +0 -60
- package/src/security/rate-limit/adapter.ts +0 -7
- package/src/security/rate-limit/memory.ts +0 -108
- package/src/security/rate-limit/middleware.ts +0 -181
- package/src/security/sanitization.ts +0 -75
- package/src/security/types.ts +0 -240
- package/src/security/utils.ts +0 -52
- package/tsconfig.json +0 -39
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HTTPMethod } from '../../core/types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function generateSummary(method: HTTPMethod, path: string): string {
|
|
6
|
-
const parts = path.split('/').filter(Boolean);
|
|
7
|
-
const resource = parts.find(p => !p.startsWith(':')) || 'resource';
|
|
8
|
-
const hasId = parts.some(p => p.startsWith(':'));
|
|
9
|
-
const actions: Record<HTTPMethod, string> = {
|
|
10
|
-
'GET': hasId ? `Get ${resource}` : `List ${resource}`,
|
|
11
|
-
'POST': `Create ${resource}`,
|
|
12
|
-
'PUT': `Update ${resource}`,
|
|
13
|
-
'PATCH': `Patch ${resource}`,
|
|
14
|
-
'DELETE': `Delete ${resource}`,
|
|
15
|
-
'HEAD': `Head ${resource}`,
|
|
16
|
-
'OPTIONS': `Options ${resource}`
|
|
17
|
-
};
|
|
18
|
-
return actions[method] || `${method} ${path}`;
|
|
19
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function getTagFromPath(path: string): string {
|
|
4
|
-
const firstSegment = path.split('/').filter(Boolean)[0];
|
|
5
|
-
if (firstSegment && !firstSegment.startsWith(':')) {
|
|
6
|
-
return firstSegment.charAt(0).toUpperCase() + firstSegment.slice(1);
|
|
7
|
-
}
|
|
8
|
-
return 'General';
|
|
9
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { extractPathParams } from './extractPathParams';
|
|
2
|
-
import { zodToParams } from './zodToParams';
|
|
3
|
-
import { zodToExample } from './zodToExample';
|
|
4
|
-
import { getTagFromPath } from './getTagFromPath';
|
|
5
|
-
import { generateSummary } from './generateSummary';
|
|
6
|
-
import { generatePlaygroundHTML } from './generatePlaygroundHTML';
|
|
7
|
-
import { Application } from '../../core/application';
|
|
8
|
-
import { RouteConfig, HTTPMethod, Context, Plugin, SchemaConfig, RouteMeta } from '../../core/types';
|
|
9
|
-
import { PlaygroundConfig, StoredRoute } from './types';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export function playground(config: PlaygroundConfig = {}): Plugin {
|
|
13
|
-
const resolvedConfig: PlaygroundConfig = {
|
|
14
|
-
path: '/playground',
|
|
15
|
-
title: 'API Playground',
|
|
16
|
-
theme: 'dark',
|
|
17
|
-
enableHistory: true,
|
|
18
|
-
maxHistory: 50,
|
|
19
|
-
enableVariables: true,
|
|
20
|
-
defaultHeaders: { 'Content-Type': 'application/json' },
|
|
21
|
-
variables: { baseUrl: 'http://localhost:3000', token: '' },
|
|
22
|
-
...config
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const routes: StoredRoute[] = [];
|
|
26
|
-
let detectedBaseUrl = '';
|
|
27
|
-
let appInstance: Application | null = null;
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
name: 'playground',
|
|
31
|
-
version: '1.0.0',
|
|
32
|
-
|
|
33
|
-
install(app: Application) {
|
|
34
|
-
appInstance = app;
|
|
35
|
-
const originalRoute = app.route.bind(app);
|
|
36
|
-
const originalGet = app.get.bind(app);
|
|
37
|
-
const originalPost = app.post.bind(app);
|
|
38
|
-
const originalPut = app.put.bind(app);
|
|
39
|
-
const originalDelete = app.delete.bind(app);
|
|
40
|
-
const originalPatch = app.patch.bind(app);
|
|
41
|
-
|
|
42
|
-
app.route = function (routeConfig: RouteConfig) {
|
|
43
|
-
routes.push({
|
|
44
|
-
method: routeConfig.method,
|
|
45
|
-
path: routeConfig.path,
|
|
46
|
-
schema: routeConfig.schema,
|
|
47
|
-
meta: routeConfig.meta
|
|
48
|
-
});
|
|
49
|
-
return originalRoute(routeConfig);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const wrapMethod = (method: HTTPMethod, original: Function) => {
|
|
53
|
-
return function (pathOrRoute: string | any, handlerOrConfig?: any) {
|
|
54
|
-
// Class-based routing
|
|
55
|
-
if (typeof pathOrRoute === 'object' && 'pathName' in pathOrRoute) {
|
|
56
|
-
const route = pathOrRoute;
|
|
57
|
-
routes.push({
|
|
58
|
-
method,
|
|
59
|
-
path: route.pathName,
|
|
60
|
-
schema: route.schema?.(),
|
|
61
|
-
meta: route.meta?.()
|
|
62
|
-
});
|
|
63
|
-
return original(pathOrRoute);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const path = pathOrRoute;
|
|
67
|
-
if (typeof handlerOrConfig !== 'function' && handlerOrConfig) {
|
|
68
|
-
routes.push({ method, path, schema: handlerOrConfig.schema, meta: handlerOrConfig.meta });
|
|
69
|
-
} else {
|
|
70
|
-
routes.push({ method, path });
|
|
71
|
-
}
|
|
72
|
-
return original(path, handlerOrConfig);
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
app.get = wrapMethod('GET', originalGet);
|
|
77
|
-
app.post = wrapMethod('POST', originalPost);
|
|
78
|
-
app.put = wrapMethod('PUT', originalPut);
|
|
79
|
-
app.delete = wrapMethod('DELETE', originalDelete);
|
|
80
|
-
app.patch = wrapMethod('PATCH', originalPatch);
|
|
81
|
-
|
|
82
|
-
const basePath = resolvedConfig.path!;
|
|
83
|
-
|
|
84
|
-
originalGet(basePath, async (ctx: any) => {
|
|
85
|
-
if (!detectedBaseUrl && ctx.raw?.req) {
|
|
86
|
-
const req = ctx.raw.req;
|
|
87
|
-
const protocol = req.headers['x-forwarded-proto'] || 'http';
|
|
88
|
-
const host = req.headers.host || 'localhost:3000';
|
|
89
|
-
detectedBaseUrl = `${protocol}://${host}`;
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
statusCode: 200,
|
|
93
|
-
headers: { 'Content-Type': 'text/html; charset=utf-8' },
|
|
94
|
-
body: generatePlaygroundHTML(resolvedConfig, detectedBaseUrl)
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
originalGet(basePath + '/api/routes', async (ctx: Context) => {
|
|
99
|
-
// Combine intercepted routes with routes from router (for file-based routing)
|
|
100
|
-
const allRoutes = getAllRoutes(routes, appInstance, basePath);
|
|
101
|
-
|
|
102
|
-
const routesData = allRoutes.map(r => ({
|
|
103
|
-
method: r.method,
|
|
104
|
-
path: r.path,
|
|
105
|
-
summary: r.meta?.summary || generateSummary(r.method as HTTPMethod, r.path),
|
|
106
|
-
description: r.meta?.description,
|
|
107
|
-
tags: r.meta?.tags || [getTagFromPath(r.path)],
|
|
108
|
-
deprecated: r.meta?.deprecated,
|
|
109
|
-
responses: r.meta?.responses,
|
|
110
|
-
example: r.meta?.example,
|
|
111
|
-
schema: {
|
|
112
|
-
body: r.schema?.body ? zodToExample(r.schema.body) : null,
|
|
113
|
-
query: r.schema?.query ? zodToParams(r.schema.query) : null,
|
|
114
|
-
params: extractPathParams(r.path)
|
|
115
|
-
}
|
|
116
|
-
}));
|
|
117
|
-
return ctx.json(routesData);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Get all routes by combining intercepted routes with routes from the router
|
|
125
|
-
* This ensures file-based routes are also included
|
|
126
|
-
*/
|
|
127
|
-
function getAllRoutes(
|
|
128
|
-
interceptedRoutes: StoredRoute[],
|
|
129
|
-
app: Application | null,
|
|
130
|
-
basePath: string
|
|
131
|
-
): StoredRoute[] {
|
|
132
|
-
// Create a Set of already tracked route keys (method + path)
|
|
133
|
-
const trackedKeys = new Set(
|
|
134
|
-
interceptedRoutes.map(r => `${r.method}:${r.path}`)
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
// Start with intercepted routes (filtered)
|
|
138
|
-
const allRoutes: StoredRoute[] = interceptedRoutes.filter(
|
|
139
|
-
r => !r.path.startsWith(basePath)
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
// Get routes from router (includes file-based routes)
|
|
143
|
-
if (app) {
|
|
144
|
-
const routerRoutes = app.getRoutes() as Array<{
|
|
145
|
-
method: string;
|
|
146
|
-
path: string;
|
|
147
|
-
schema?: SchemaConfig;
|
|
148
|
-
meta?: RouteMeta;
|
|
149
|
-
}>;
|
|
150
|
-
|
|
151
|
-
for (const route of routerRoutes) {
|
|
152
|
-
const key = `${route.method}:${route.path}`;
|
|
153
|
-
|
|
154
|
-
// Skip if already tracked or is playground route
|
|
155
|
-
if (trackedKeys.has(key) || route.path.startsWith(basePath)) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
allRoutes.push({
|
|
160
|
-
method: route.method as HTTPMethod,
|
|
161
|
-
path: route.path,
|
|
162
|
-
schema: route.schema,
|
|
163
|
-
meta: route.meta
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Sort routes by path for consistent ordering
|
|
169
|
-
return allRoutes.sort((a, b) => a.path.localeCompare(b.path));
|
|
170
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { HTTPMethod, RouteMeta, SchemaConfig } from "../../core/types";
|
|
2
|
-
|
|
3
|
-
export interface PlaygroundConfig {
|
|
4
|
-
path?: string;
|
|
5
|
-
title?: string;
|
|
6
|
-
theme?: 'dark' | 'light';
|
|
7
|
-
defaultHeaders?: Record<string, string>;
|
|
8
|
-
enableHistory?: boolean;
|
|
9
|
-
maxHistory?: number;
|
|
10
|
-
enableVariables?: boolean;
|
|
11
|
-
variables?: Record<string, string>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export interface StoredRoute {
|
|
16
|
-
method: HTTPMethod;
|
|
17
|
-
path: string;
|
|
18
|
-
schema?: SchemaConfig;
|
|
19
|
-
meta?: RouteMeta;
|
|
20
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { generateFieldExample } from './generateFieldExample';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function zodToExample(schema: any): any {
|
|
6
|
-
if (!schema?._def) return {};
|
|
7
|
-
try {
|
|
8
|
-
const shape = schema._def?.shape?.() || schema.shape;
|
|
9
|
-
if (!shape) return {};
|
|
10
|
-
const example: Record<string, any> = {};
|
|
11
|
-
for (const [key, value] of Object.entries(shape)) {
|
|
12
|
-
example[key] = generateFieldExample(value, key);
|
|
13
|
-
}
|
|
14
|
-
return example;
|
|
15
|
-
} catch { return {}; }
|
|
16
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function zodToParams(schema: any): Array<{ name: string; optional: boolean; }> {
|
|
4
|
-
const params: Array<{ name: string; optional: boolean; }> = [];
|
|
5
|
-
try {
|
|
6
|
-
const shape = schema._def?.shape?.() || schema.shape;
|
|
7
|
-
if (shape) {
|
|
8
|
-
for (const [key, value] of Object.entries(shape)) {
|
|
9
|
-
const def = (value as any)?._def;
|
|
10
|
-
params.push({ name: key, optional: def?.typeName === 'ZodOptional' });
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
} catch { }
|
|
14
|
-
return params;
|
|
15
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { PostmanAuth } from './types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function buildAuth(auth: PostmanAuth): any {
|
|
5
|
-
switch (auth.type) {
|
|
6
|
-
case 'bearer':
|
|
7
|
-
return {
|
|
8
|
-
type: 'bearer',
|
|
9
|
-
bearer: [{ key: 'token', value: auth.bearer?.token || '{{token}}', type: 'string' }]
|
|
10
|
-
};
|
|
11
|
-
case 'apikey':
|
|
12
|
-
return {
|
|
13
|
-
type: 'apikey',
|
|
14
|
-
apikey: [
|
|
15
|
-
{ key: 'key', value: auth.apikey?.key || 'X-API-Key', type: 'string' },
|
|
16
|
-
{ key: 'value', value: auth.apikey?.value || '{{apiKey}}', type: 'string' },
|
|
17
|
-
{ key: 'in', value: auth.apikey?.in || 'header', type: 'string' }
|
|
18
|
-
]
|
|
19
|
-
};
|
|
20
|
-
case 'basic':
|
|
21
|
-
return {
|
|
22
|
-
type: 'basic',
|
|
23
|
-
basic: [
|
|
24
|
-
{ key: 'username', value: auth.basic?.username || '{{username}}', type: 'string' },
|
|
25
|
-
{ key: 'password', value: auth.basic?.password || '{{password}}', type: 'string' }
|
|
26
|
-
]
|
|
27
|
-
};
|
|
28
|
-
default:
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { generateExampleFromZod } from './generateExampleFromZod';
|
|
2
|
-
import { PostmanBody } from './types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function buildBody(bodySchema: any): PostmanBody {
|
|
6
|
-
const example = generateExampleFromZod(bodySchema);
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
mode: 'raw',
|
|
10
|
-
raw: JSON.stringify(example, null, 2),
|
|
11
|
-
options: {
|
|
12
|
-
raw: { language: 'json' }
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { PostmanQuery } from './types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function buildQueryParams(querySchema: any): PostmanQuery[] {
|
|
5
|
-
const params: PostmanQuery[] = [];
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
const shape = querySchema._def?.shape?.() || querySchema.shape;
|
|
9
|
-
if (shape) {
|
|
10
|
-
for (const [key, value] of Object.entries(shape)) {
|
|
11
|
-
const def = (value as any)?._def;
|
|
12
|
-
const isOptional = def?.typeName === 'ZodOptional';
|
|
13
|
-
|
|
14
|
-
params.push({
|
|
15
|
-
key,
|
|
16
|
-
value: '',
|
|
17
|
-
disabled: isOptional,
|
|
18
|
-
description: isOptional ? '(optional)' : undefined
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
} catch {
|
|
23
|
-
// Ignore errors
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return params;
|
|
27
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { buildBody } from './buildBody';
|
|
2
|
-
import { buildResponses } from './buildResponses';
|
|
3
|
-
import { buildUrl } from './buildUrl';
|
|
4
|
-
import { generateName } from './generateName';
|
|
5
|
-
import { StoredRoute, PostmanConfig, PostmanItem } from './types';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export function buildRequestItem(route: StoredRoute, config: PostmanConfig): PostmanItem {
|
|
9
|
-
const meta = route.meta || {};
|
|
10
|
-
const name = meta.summary || generateName(route.method, route.path);
|
|
11
|
-
|
|
12
|
-
const item: PostmanItem = {
|
|
13
|
-
name,
|
|
14
|
-
request: {
|
|
15
|
-
method: route.method,
|
|
16
|
-
header: [
|
|
17
|
-
{ key: 'Content-Type', value: 'application/json', type: 'text' },
|
|
18
|
-
{ key: 'Accept', value: 'application/json', type: 'text' }
|
|
19
|
-
],
|
|
20
|
-
url: buildUrl(route),
|
|
21
|
-
description: meta.description
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// Add request body for POST/PUT/PATCH
|
|
26
|
-
if (route.schema?.body && ['POST', 'PUT', 'PATCH'].includes(route.method)) {
|
|
27
|
-
item.request!.body = buildBody(route.schema.body);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Add example responses
|
|
31
|
-
if (config.includeExamples && meta.responses) {
|
|
32
|
-
item.response = buildResponses(meta.responses, name);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return item;
|
|
36
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PostmanResponse } from './types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function buildResponses(responses: Record<number, string>, requestName: string): PostmanResponse[] {
|
|
5
|
-
return Object.entries(responses).map(([code, description]) => ({
|
|
6
|
-
name: `${requestName} - ${description}`,
|
|
7
|
-
status: description,
|
|
8
|
-
code: parseInt(code),
|
|
9
|
-
body: JSON.stringify({ message: description }, null, 2)
|
|
10
|
-
}));
|
|
11
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { buildQueryParams } from './buildQueryParams';
|
|
2
|
-
import { capitalize } from './capitalize';
|
|
3
|
-
import { StoredRoute, PostmanUrl } from './types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export function buildUrl(route: StoredRoute): PostmanUrl {
|
|
7
|
-
// Convert :param to {{param}} for Postman
|
|
8
|
-
const pathWithVars = route.path.replace(/:(\w+)/g, '{{$1}}');
|
|
9
|
-
const pathParts = pathWithVars.split('/').filter(Boolean);
|
|
10
|
-
|
|
11
|
-
const url: PostmanUrl = {
|
|
12
|
-
raw: '{{baseUrl}}' + pathWithVars,
|
|
13
|
-
host: ['{{baseUrl}}'],
|
|
14
|
-
path: pathParts
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Add path variables
|
|
18
|
-
const pathParams = route.path.match(/:(\w+)/g);
|
|
19
|
-
if (pathParams) {
|
|
20
|
-
url.variable = pathParams.map(p => ({
|
|
21
|
-
key: p.slice(1),
|
|
22
|
-
value: '',
|
|
23
|
-
description: `${capitalize(p.slice(1))} parameter`
|
|
24
|
-
}));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Add query parameters from schema
|
|
28
|
-
if (route.schema?.query) {
|
|
29
|
-
url.query = buildQueryParams(route.schema.query);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return url;
|
|
33
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { buildAuth } from './buildAuth';
|
|
2
|
-
import { buildRequestItem } from './buildRequestItem';
|
|
3
|
-
import { generateUUID } from './generateUUID';
|
|
4
|
-
import { getTagFromPath } from './getTagFromPath';
|
|
5
|
-
import { StoredRoute, PostmanConfig, PostmanCollection, PostmanItem } from './types';
|
|
6
|
-
|
|
7
|
-
// ============================================
|
|
8
|
-
// COLLECTION GENERATION
|
|
9
|
-
// ============================================
|
|
10
|
-
|
|
11
|
-
export function generateCollection(
|
|
12
|
-
routes: StoredRoute[],
|
|
13
|
-
config: PostmanConfig,
|
|
14
|
-
baseUrl: string
|
|
15
|
-
): PostmanCollection {
|
|
16
|
-
const collection: PostmanCollection = {
|
|
17
|
-
info: {
|
|
18
|
-
_postman_id: generateUUID(),
|
|
19
|
-
name: config.name!,
|
|
20
|
-
description: config.description,
|
|
21
|
-
schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
|
22
|
-
},
|
|
23
|
-
item: [],
|
|
24
|
-
variable: [
|
|
25
|
-
{ key: 'baseUrl', value: baseUrl, type: 'string' }
|
|
26
|
-
]
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// Add auth if configured
|
|
30
|
-
if (config.auth) {
|
|
31
|
-
collection.auth = buildAuth(config.auth);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Group routes by tags
|
|
35
|
-
const grouped = new Map<string, StoredRoute[]>();
|
|
36
|
-
|
|
37
|
-
for (const route of routes) {
|
|
38
|
-
// Skip postman's own endpoints
|
|
39
|
-
if (route.path.startsWith(config.path!)) continue;
|
|
40
|
-
|
|
41
|
-
const tag = route.meta?.tags?.[0] || getTagFromPath(route.path);
|
|
42
|
-
|
|
43
|
-
if (!grouped.has(tag)) {
|
|
44
|
-
grouped.set(tag, []);
|
|
45
|
-
}
|
|
46
|
-
grouped.get(tag)!.push(route);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Build folder structure
|
|
50
|
-
for (const [tag, tagRoutes] of grouped) {
|
|
51
|
-
const folder: PostmanItem = {
|
|
52
|
-
name: tag,
|
|
53
|
-
item: tagRoutes.map(route => buildRequestItem(route, config))
|
|
54
|
-
};
|
|
55
|
-
collection.item.push(folder);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return collection;
|
|
59
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { generateUUID } from './generateUUID';
|
|
2
|
-
import { PostmanConfig, PostmanEnvironment, PostmanEnvVariable } from './types';
|
|
3
|
-
|
|
4
|
-
// ============================================
|
|
5
|
-
// ENVIRONMENT GENERATION
|
|
6
|
-
// ============================================
|
|
7
|
-
|
|
8
|
-
export function generateEnvironment(config: PostmanConfig, baseUrl: string): PostmanEnvironment {
|
|
9
|
-
const variables: PostmanEnvVariable[] = [
|
|
10
|
-
{ key: 'baseUrl', value: baseUrl, type: 'default', enabled: true },
|
|
11
|
-
{ key: 'token', value: '', type: 'secret', enabled: true },
|
|
12
|
-
{ key: 'apiKey', value: '', type: 'secret', enabled: true }
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
// Add custom variables
|
|
16
|
-
if (config.variables) {
|
|
17
|
-
for (const [key, value] of Object.entries(config.variables)) {
|
|
18
|
-
variables.push({
|
|
19
|
-
key,
|
|
20
|
-
value,
|
|
21
|
-
type: key.toLowerCase().includes('secret') || key.toLowerCase().includes('key')
|
|
22
|
-
? 'secret' : 'default',
|
|
23
|
-
enabled: true
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
id: generateUUID(),
|
|
30
|
-
name: config.environmentName!,
|
|
31
|
-
values: variables,
|
|
32
|
-
_postman_variable_scope: 'environment'
|
|
33
|
-
};
|
|
34
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { generateFieldExample } from './generateFieldExample';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function generateExampleFromZod(schema: any): any {
|
|
5
|
-
if (!schema?._def) return {};
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
const shape = schema._def?.shape?.() || schema.shape;
|
|
9
|
-
if (!shape) return {};
|
|
10
|
-
|
|
11
|
-
const example: Record<string, any> = {};
|
|
12
|
-
|
|
13
|
-
for (const [key, value] of Object.entries(shape)) {
|
|
14
|
-
example[key] = generateFieldExample(value, key);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return example;
|
|
18
|
-
} catch {
|
|
19
|
-
return {};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { generateExampleFromZod } from './generateExampleFromZod';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function generateFieldExample(field: any, fieldName: string): any {
|
|
5
|
-
if (!field?._def) return '';
|
|
6
|
-
|
|
7
|
-
const def = field._def;
|
|
8
|
-
const typeName = def.typeName;
|
|
9
|
-
|
|
10
|
-
switch (typeName) {
|
|
11
|
-
case 'ZodString': {
|
|
12
|
-
// Check for specific formats
|
|
13
|
-
for (const check of def.checks || []) {
|
|
14
|
-
if (check.kind === 'email') return 'user@example.com';
|
|
15
|
-
if (check.kind === 'url') return 'https://example.com';
|
|
16
|
-
if (check.kind === 'uuid') return '550e8400-e29b-41d4-a716-446655440000';
|
|
17
|
-
}
|
|
18
|
-
// Generate based on field name
|
|
19
|
-
if (fieldName.toLowerCase().includes('email')) return 'user@example.com';
|
|
20
|
-
if (fieldName.toLowerCase().includes('password')) return 'password123';
|
|
21
|
-
if (fieldName.toLowerCase().includes('name')) return 'John Doe';
|
|
22
|
-
if (fieldName.toLowerCase().includes('username')) return 'johndoe';
|
|
23
|
-
if (fieldName.toLowerCase().includes('phone')) return '+1234567890';
|
|
24
|
-
if (fieldName.toLowerCase().includes('token')) return 'your-token-here';
|
|
25
|
-
return 'string';
|
|
26
|
-
}
|
|
27
|
-
case 'ZodNumber':
|
|
28
|
-
return 0;
|
|
29
|
-
case 'ZodBoolean':
|
|
30
|
-
return true;
|
|
31
|
-
case 'ZodArray':
|
|
32
|
-
return [generateFieldExample(def.type, 'item')];
|
|
33
|
-
case 'ZodObject':
|
|
34
|
-
return generateExampleFromZod(field);
|
|
35
|
-
case 'ZodEnum':
|
|
36
|
-
return def.values?.[0] || 'enum';
|
|
37
|
-
case 'ZodOptional':
|
|
38
|
-
case 'ZodNullable':
|
|
39
|
-
return generateFieldExample(def.innerType, fieldName);
|
|
40
|
-
case 'ZodDefault':
|
|
41
|
-
return def.defaultValue();
|
|
42
|
-
default:
|
|
43
|
-
return '';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { HTTPMethod } from '../../core/types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function generateName(method: HTTPMethod, path: string): string {
|
|
5
|
-
const parts = path.split('/').filter(Boolean);
|
|
6
|
-
const resource = parts.find(p => !p.startsWith(':')) || 'resource';
|
|
7
|
-
const hasId = parts.some(p => p.startsWith(':'));
|
|
8
|
-
|
|
9
|
-
const actions: Record<HTTPMethod, string> = {
|
|
10
|
-
'GET': hasId ? `Get ${resource} by ID` : `List ${resource}`,
|
|
11
|
-
'POST': `Create ${resource}`,
|
|
12
|
-
'PUT': `Update ${resource}`,
|
|
13
|
-
'PATCH': `Patch ${resource}`,
|
|
14
|
-
'DELETE': `Delete ${resource}`,
|
|
15
|
-
'HEAD': `Head ${resource}`,
|
|
16
|
-
'OPTIONS': `Options ${resource}`
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
return actions[method] || `${method} ${path}`;
|
|
20
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// ============================================
|
|
2
|
-
// UTILITIES
|
|
3
|
-
// ============================================
|
|
4
|
-
|
|
5
|
-
export function generateUUID(): string {
|
|
6
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
7
|
-
const r = Math.random() * 16 | 0;
|
|
8
|
-
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
9
|
-
return v.toString(16);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { capitalize } from './capitalize';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function getTagFromPath(path: string): string {
|
|
5
|
-
const firstSegment = path.split('/').filter(Boolean)[0];
|
|
6
|
-
if (firstSegment && !firstSegment.startsWith(':')) {
|
|
7
|
-
return capitalize(firstSegment);
|
|
8
|
-
}
|
|
9
|
-
return 'General';
|
|
10
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Postman Collection Generator for Nexus Framework
|
|
3
|
-
* Auto-generate Postman collection & environment from routes
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* import { createApp, postman } from 'nexus';
|
|
8
|
-
*
|
|
9
|
-
* const app = createApp();
|
|
10
|
-
*
|
|
11
|
-
* // Zero config
|
|
12
|
-
* app.plugin(postman());
|
|
13
|
-
*
|
|
14
|
-
* // With config
|
|
15
|
-
* app.plugin(postman({
|
|
16
|
-
* path: '/postman',
|
|
17
|
-
* name: 'My API',
|
|
18
|
-
* baseUrl: 'http://localhost:3000'
|
|
19
|
-
* }));
|
|
20
|
-
*
|
|
21
|
-
* // Access:
|
|
22
|
-
* // GET /postman → Download collection.json
|
|
23
|
-
* // GET /postman/environment → Download environment.json
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import { postman } from './postman';
|
|
28
|
-
export default postman;
|