@orion-js/http 4.2.3 → 4.3.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.
- package/dist/index.cjs +26 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +26 -16
- package/dist/index.js.map +1 -1
- package/package.json +17 -18
- package/LICENSE +0 -21
package/dist/index.cjs
CHANGED
|
@@ -252,33 +252,42 @@ var route = createRoute;
|
|
|
252
252
|
var import_services = require("@orion-js/services");
|
|
253
253
|
var serviceMetadata = /* @__PURE__ */ new WeakMap();
|
|
254
254
|
var routeMetadata = /* @__PURE__ */ new WeakMap();
|
|
255
|
+
var routeEntriesByClass = /* @__PURE__ */ new Map();
|
|
256
|
+
var pendingRouteEntries = {};
|
|
255
257
|
function Routes() {
|
|
256
258
|
return (target, context) => {
|
|
257
259
|
(0, import_services.Service)()(target, context);
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
260
|
+
serviceMetadata.set(target, { _serviceType: "routes" });
|
|
261
|
+
if (Object.keys(pendingRouteEntries).length > 0) {
|
|
262
|
+
routeEntriesByClass.set(target, pendingRouteEntries);
|
|
263
|
+
pendingRouteEntries = {};
|
|
264
|
+
}
|
|
261
265
|
};
|
|
262
266
|
}
|
|
263
267
|
function Route(options) {
|
|
264
268
|
return (method, context) => {
|
|
265
269
|
const propertyKey = String(context.name);
|
|
266
|
-
context.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
routes[propertyKey] = this[propertyKey];
|
|
276
|
-
}
|
|
277
|
-
routeMetadata.set(this, routes);
|
|
278
|
-
});
|
|
270
|
+
if (context.kind === "method") {
|
|
271
|
+
pendingRouteEntries[propertyKey] = (instance) => createRoute({
|
|
272
|
+
...options,
|
|
273
|
+
resolve: instance[propertyKey].bind(instance)
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
if (context.kind === "field") {
|
|
277
|
+
pendingRouteEntries[propertyKey] = (instance) => instance[propertyKey];
|
|
278
|
+
}
|
|
279
279
|
return method;
|
|
280
280
|
};
|
|
281
281
|
}
|
|
282
|
+
function initializeRoutesIfNeeded(instance) {
|
|
283
|
+
if (routeMetadata.has(instance)) return;
|
|
284
|
+
const entries = routeEntriesByClass.get(instance.constructor) || {};
|
|
285
|
+
const routes = {};
|
|
286
|
+
for (const [key, setup] of Object.entries(entries)) {
|
|
287
|
+
routes[key] = setup(instance);
|
|
288
|
+
}
|
|
289
|
+
routeMetadata.set(instance, routes);
|
|
290
|
+
}
|
|
282
291
|
function getServiceRoutes(target) {
|
|
283
292
|
const instance = (0, import_services.getInstance)(target);
|
|
284
293
|
if (!serviceMetadata.has(instance.constructor)) {
|
|
@@ -288,6 +297,7 @@ function getServiceRoutes(target) {
|
|
|
288
297
|
if (instanceMetadata._serviceType !== "routes") {
|
|
289
298
|
throw new Error("You must pass a class decorated with @Routes to getServiceRoutes");
|
|
290
299
|
}
|
|
300
|
+
initializeRoutesIfNeeded(instance);
|
|
291
301
|
const routesMap = routeMetadata.get(instance) || {};
|
|
292
302
|
return routesMap;
|
|
293
303
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/viewer.ts","../src/start.ts","../src/routes/registerRoute.ts","../src/routes/executeRequest.ts","../src/routes/registerRoutes.ts","../src/routes/route.ts","../src/service/index.ts"],"sourcesContent":["import {setOnError, onError} from './errors'\nimport {getViewer, setGetViewer} from './viewer'\nimport {startServer, getApp, getServer} from './start'\nimport express from 'express'\nimport registerRoute from './routes/registerRoute'\nimport registerRoutes from './routes/registerRoutes'\nimport bodyParserLib from 'body-parser'\nimport {RequestHandler} from 'express'\n\nexport * from './routes/route'\n\nconst {json, raw, text, urlencoded} = bodyParserLib\n\nconst bodyParser: {\n json: () => RequestHandler\n raw: () => RequestHandler\n text: () => RequestHandler\n urlencoded: (options?: {extended: boolean}) => RequestHandler\n} = {json, raw, text, urlencoded}\n\nexport {\n express,\n startServer,\n getApp,\n getServer,\n getViewer,\n setGetViewer,\n setOnError,\n onError,\n registerRoute,\n registerRoutes,\n bodyParser,\n}\n\nexport * from './types'\nexport * from './service'\n","import crypto from 'node:crypto'\nimport {logger} from '@orion-js/logger'\nimport express from 'express'\n\ntype onErrorFunction = (req: express.Request, res: express.Response, error: any) => Promise<void>\n\nconst defaultOnError: onErrorFunction = async (req, res, error) => {\n if (error.isOrionError) {\n let statusCode = 400\n if (error.code === 'AuthError') {\n statusCode = 401\n } else {\n logger.error(`[route/handler] OrionError in ${req.path}:`, {error})\n }\n\n const data = error.getInfo()\n\n res.status(statusCode)\n res.json(data)\n } else if (error.isGraphQLError) {\n res.writeHead(error.statusCode)\n res.end(error.message)\n logger.error(`[route/handler] GraphQLError in ${req.path}:`, {error})\n } else {\n const hash = crypto\n .createHash('sha1')\n .update(error.message, 'utf8')\n .digest('hex')\n .substring(0, 10)\n const statusCode = 500\n const data = {error: 500, message: 'Internal server error', hash}\n\n res.status(statusCode)\n res.json(data)\n\n error.hash = hash\n logger.error('[route/handler] Internal server error', {error, url: req.url, hash})\n }\n}\n\nlet onErrorRef: onErrorFunction = defaultOnError\n\nexport const onError: onErrorFunction = async (req, res, error) => {\n return onErrorRef(req, res, error)\n}\n\nexport const setOnError = (onErrorFunc: onErrorFunction): void => {\n onErrorRef = onErrorFunc\n}\n","import express from 'express'\nimport {UserError} from '@orion-js/helpers'\n\nglobal.getViewerRef = () => null\n\nexport const getViewer = async (req: express.Request): Promise<any> => {\n try {\n const viewer = await global.getViewerRef(req)\n if (!viewer) return {}\n return viewer\n } catch (err) {\n throw new UserError('AuthError', err.message)\n }\n}\n\nexport const setGetViewer = (getViewerFunc: (req: express.Request) => any): void => {\n global.getViewerRef = getViewerFunc\n}\n","import {internalGetEnv} from '@orion-js/env'\nimport express from 'express'\n\nglobal.appRef = null\nglobal.serverRef = null\n\nexport interface StartOrionOptions {\n keepAliveTimeout?: number\n}\n\nexport const startServer = (\n port: number = Number(internalGetEnv('http_port', 'PORT')),\n otherOptions: StartOrionOptions = {},\n) => {\n const app = getApp()\n\n const server = app.listen(port)\n global.serverRef = server\n\n if (otherOptions.keepAliveTimeout) {\n server.keepAliveTimeout = otherOptions.keepAliveTimeout // Ensure all inactive connections are terminated by the ALB, by setting this a few seconds higher than the ALB idle timeout\n server.headersTimeout = otherOptions.keepAliveTimeout + 1000\n }\n\n return app\n}\n\nexport const getApp = (): express.Express => {\n if (global.appRef) return global.appRef as express.Express\n\n const app = express()\n\n global.appRef = app\n\n return app\n}\n\nexport const getServer = () => {\n return global.serverRef\n}\n","import bodyParser from 'body-parser'\nimport express from 'express'\nimport {getApp} from './../start'\nimport {RouteType} from '../types'\nimport {executeRequest} from './executeRequest'\n\nconst appRegisteredRoutes = new WeakMap<express.Application, WeakSet<RouteType>>()\n\nfunction getRegisteredRoutes(app: express.Application) {\n if (appRegisteredRoutes.has(app)) {\n return appRegisteredRoutes.get(app)\n }\n\n const routes = new WeakSet<RouteType>()\n appRegisteredRoutes.set(app, routes)\n return routes\n}\n\nexport default function registerRoute(route: RouteType): void {\n const app = route.app || getApp()\n const registeredRoutes = getRegisteredRoutes(app)\n if (registeredRoutes.has(route)) return\n\n const method = route.method\n\n const handler: express.RequestHandler = (req, res) => {\n void executeRequest(route, req as any, res)\n }\n\n const handlers: Array<express.RequestHandler> = [handler]\n\n if (route.bodyParser) {\n const parser = bodyParser[route.bodyParser](route.bodyParserOptions)\n handlers.unshift(parser)\n }\n\n if (!route.bodyParser && route.bodyParams) {\n const parser = bodyParser.json(route.bodyParserOptions)\n handlers.unshift(parser)\n }\n\n if (route.middlewares) {\n handlers.unshift(...route.middlewares)\n }\n\n app[method](route.path, ...handlers)\n registeredRoutes.add(route)\n}\n","import {internalGetEnv} from '@orion-js/env'\nimport {sleep} from '@orion-js/helpers'\nimport {runWithOrionAsyncContext, updateOrionAsyncContext} from '@orion-js/logger'\nimport {cleanAndValidate} from '@orion-js/schema'\nimport express from 'express'\nimport {onError} from '../errors'\nimport {OrionRequest, RouteType} from './../types'\nimport {getViewer} from './../viewer'\n\nconst simulateLatency = internalGetEnv('simulate_latency', 'SIMULATE_LATENCY')\nconst simulateLatencyMs = Number.parseInt(simulateLatency, 10)\nconst hasSimulateLatency = Number.isFinite(simulateLatencyMs) && simulateLatencyMs > 0\nconst latencyMinMs = hasSimulateLatency ? Math.floor(simulateLatencyMs * 0.9) : 0\nconst latencyMaxMs = hasSimulateLatency ? Math.ceil(simulateLatencyMs * 1.1) : 0\n\nconst objectToString = Object.prototype.toString\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return objectToString.call(value) === '[object Object]'\n}\n\nexport async function executeRequest(\n route: RouteType<any>,\n req: OrionRequest,\n res: express.Response,\n) {\n try {\n if (hasSimulateLatency) {\n const delay = Math.floor(Math.random() * (latencyMaxMs - latencyMinMs + 1)) + latencyMinMs\n await sleep(delay)\n }\n\n const viewer = await getViewer(req)\n\n if (route.queryParams) {\n req.query = await cleanAndValidate(route.queryParams, req.query)\n }\n\n if (route.bodyParams) {\n req.body = await cleanAndValidate(route.bodyParams, req.body)\n }\n\n const context = {\n controllerType: 'route' as const,\n routeName: route.path,\n pathname: req.path,\n viewer,\n params: {\n body: req.body,\n query: req.query,\n params: req.params,\n },\n }\n\n const result = await runWithOrionAsyncContext(context, () => {\n updateOrionAsyncContext({viewer})\n return route.resolve(req, res, viewer)\n })\n if (!result) return\n\n // add status code to response\n if (result.statusCode) {\n res.status(result.statusCode)\n }\n\n // add headers to response\n if (result.headers) {\n res.set(result.headers)\n }\n\n // add body to response\n if (result.body !== null && result.body !== undefined) {\n let body = result.body\n\n if (route.returns) {\n body = await cleanAndValidate(route.returns, result.body)\n }\n\n if (isPlainObject(body)) {\n res.json(body)\n } else {\n res.send(body)\n }\n }\n } catch (error) {\n await onError(req, res, error)\n }\n}\n","import {RoutesMap} from '../types'\nimport registerRoute from './registerRoute'\n\nexport default function registerRoutes(routesMap: RoutesMap): void {\n for (const routeName in routesMap) {\n registerRoute(routesMap[routeName])\n }\n}\n","import {Schema, SchemaFieldType} from '@orion-js/schema'\nimport {RouteType, OrionRouteOptions} from '../types'\n\nexport function createRoute<\n TPath extends string,\n TQueryParamsSchema extends Schema | undefined,\n TBodyParamsSchema extends Schema | undefined,\n TReturnsSchema extends SchemaFieldType | undefined,\n>(\n options: OrionRouteOptions<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema>,\n): RouteType<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema> {\n return {\n ...options,\n }\n}\n\n/**\n * @deprecated Use createRoute instead\n */\nexport const route = createRoute\n","import {getInstance, Service} from '@orion-js/services'\nimport {createRoute} from '../routes/route'\nimport {OrionRouteOptions, RoutesMap} from '../types'\n\n// Define metadata storage using WeakMaps\nconst serviceMetadata = new WeakMap<any, {_serviceType: string}>()\nconst routeMetadata = new WeakMap<any, Record<string, any>>()\n\nexport function Routes() {\n return (target: any, context: ClassDecoratorContext<any>) => {\n Service()(target, context)\n\n context.addInitializer(function (this) {\n serviceMetadata.set(this, {_serviceType: 'routes'})\n })\n }\n}\n\nexport function Route(): (method: any, context: ClassFieldDecoratorContext) => any\nexport function Route(\n options?: Omit<OrionRouteOptions<any, any, any, any>, 'resolve'>,\n): (method: any, context: ClassMethodDecoratorContext) => any\nexport function Route(options?: Omit<OrionRouteOptions<any, any, any, any>, 'resolve'>) {\n return (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => {\n const propertyKey = String(context.name)\n\n context.addInitializer(function (this) {\n const routes = routeMetadata.get(this) || {}\n\n if (context.kind === 'method') {\n routes[propertyKey] = createRoute({\n ...options,\n resolve: this[propertyKey].bind(this),\n })\n }\n\n if (context.kind === 'field') {\n routes[propertyKey] = this[propertyKey]\n }\n\n routeMetadata.set(this, routes)\n })\n\n return method\n }\n}\n\nexport function getServiceRoutes(target: any): RoutesMap {\n const instance = getInstance(target)\n\n if (!serviceMetadata.has(instance.constructor)) {\n throw new Error('You must pass a class decorated with @Routes to getServiceRoutes')\n }\n\n const instanceMetadata = serviceMetadata.get(instance.constructor)\n if (instanceMetadata._serviceType !== 'routes') {\n throw new Error('You must pass a class decorated with @Routes to getServiceRoutes')\n }\n\n const routesMap = routeMetadata.get(instance) || {}\n\n return routesMap\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAAA;AAAA,EAAA;AAAA,iCAAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAAmB;AACnB,oBAAqB;AAKrB,IAAM,iBAAkC,OAAO,KAAK,KAAK,UAAU;AACjE,MAAI,MAAM,cAAc;AACtB,QAAI,aAAa;AACjB,QAAI,MAAM,SAAS,aAAa;AAC9B,mBAAa;AAAA,IACf,OAAO;AACL,2BAAO,MAAM,iCAAiC,IAAI,IAAI,KAAK,EAAC,MAAK,CAAC;AAAA,IACpE;AAEA,UAAM,OAAO,MAAM,QAAQ;AAE3B,QAAI,OAAO,UAAU;AACrB,QAAI,KAAK,IAAI;AAAA,EACf,WAAW,MAAM,gBAAgB;AAC/B,QAAI,UAAU,MAAM,UAAU;AAC9B,QAAI,IAAI,MAAM,OAAO;AACrB,yBAAO,MAAM,mCAAmC,IAAI,IAAI,KAAK,EAAC,MAAK,CAAC;AAAA,EACtE,OAAO;AACL,UAAM,OAAO,mBAAAC,QACV,WAAW,MAAM,EACjB,OAAO,MAAM,SAAS,MAAM,EAC5B,OAAO,KAAK,EACZ,UAAU,GAAG,EAAE;AAClB,UAAM,aAAa;AACnB,UAAM,OAAO,EAAC,OAAO,KAAK,SAAS,yBAAyB,KAAI;AAEhE,QAAI,OAAO,UAAU;AACrB,QAAI,KAAK,IAAI;AAEb,UAA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M,IAAI,MAAM,kEAAkE;AAAA,EACpF;AAEA,QAAM,mBAAmB,gBAAgB,IAAI,SAAS,WAAW;AACjE,MAAI,iBAAiB,iBAAiB,UAAU;AAC9C,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AAEA,QAAM,YAAY,cAAc,IAAI,QAAQ,KAAK,CAAC;AAElD,SAAO;AACT;;;ARnDA,IAAM,EAAC,MAAM,KAAK,MAAM,WAAU,IAAI,oBAAAC;AAEtC,IAAMC,cAKF,EAAC,MAAM,KAAK,MAAM,WAAU;","names":["bodyParser","express","crypto","express","import_express","import_env","import_helpers","import_logger","route","route","bodyParser","import_body_parser","bodyParserLib","bodyParser"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/viewer.ts","../src/start.ts","../src/routes/registerRoute.ts","../src/routes/executeRequest.ts","../src/routes/registerRoutes.ts","../src/routes/route.ts","../src/service/index.ts"],"sourcesContent":["import {setOnError, onError} from './errors'\nimport {getViewer, setGetViewer} from './viewer'\nimport {startServer, getApp, getServer} from './start'\nimport express from 'express'\nimport registerRoute from './routes/registerRoute'\nimport registerRoutes from './routes/registerRoutes'\nimport bodyParserLib from 'body-parser'\nimport {RequestHandler} from 'express'\n\nexport * from './routes/route'\n\nconst {json, raw, text, urlencoded} = bodyParserLib\n\nconst bodyParser: {\n json: () => RequestHandler\n raw: () => RequestHandler\n text: () => RequestHandler\n urlencoded: (options?: {extended: boolean}) => RequestHandler\n} = {json, raw, text, urlencoded}\n\nexport {\n express,\n startServer,\n getApp,\n getServer,\n getViewer,\n setGetViewer,\n setOnError,\n onError,\n registerRoute,\n registerRoutes,\n bodyParser,\n}\n\nexport * from './types'\nexport * from './service'\n","import crypto from 'node:crypto'\nimport {logger} from '@orion-js/logger'\nimport express from 'express'\n\ntype onErrorFunction = (req: express.Request, res: express.Response, error: any) => Promise<void>\n\nconst defaultOnError: onErrorFunction = async (req, res, error) => {\n if (error.isOrionError) {\n let statusCode = 400\n if (error.code === 'AuthError') {\n statusCode = 401\n } else {\n logger.error(`[route/handler] OrionError in ${req.path}:`, {error})\n }\n\n const data = error.getInfo()\n\n res.status(statusCode)\n res.json(data)\n } else if (error.isGraphQLError) {\n res.writeHead(error.statusCode)\n res.end(error.message)\n logger.error(`[route/handler] GraphQLError in ${req.path}:`, {error})\n } else {\n const hash = crypto\n .createHash('sha1')\n .update(error.message, 'utf8')\n .digest('hex')\n .substring(0, 10)\n const statusCode = 500\n const data = {error: 500, message: 'Internal server error', hash}\n\n res.status(statusCode)\n res.json(data)\n\n error.hash = hash\n logger.error('[route/handler] Internal server error', {error, url: req.url, hash})\n }\n}\n\nlet onErrorRef: onErrorFunction = defaultOnError\n\nexport const onError: onErrorFunction = async (req, res, error) => {\n return onErrorRef(req, res, error)\n}\n\nexport const setOnError = (onErrorFunc: onErrorFunction): void => {\n onErrorRef = onErrorFunc\n}\n","import express from 'express'\nimport {UserError} from '@orion-js/helpers'\n\nglobal.getViewerRef = () => null\n\nexport const getViewer = async (req: express.Request): Promise<any> => {\n try {\n const viewer = await global.getViewerRef(req)\n if (!viewer) return {}\n return viewer\n } catch (err) {\n throw new UserError('AuthError', err.message)\n }\n}\n\nexport const setGetViewer = (getViewerFunc: (req: express.Request) => any): void => {\n global.getViewerRef = getViewerFunc\n}\n","import {internalGetEnv} from '@orion-js/env'\nimport express from 'express'\n\nglobal.appRef = null\nglobal.serverRef = null\n\nexport interface StartOrionOptions {\n keepAliveTimeout?: number\n}\n\nexport const startServer = (\n port: number = Number(internalGetEnv('http_port', 'PORT')),\n otherOptions: StartOrionOptions = {},\n) => {\n const app = getApp()\n\n const server = app.listen(port)\n global.serverRef = server\n\n if (otherOptions.keepAliveTimeout) {\n server.keepAliveTimeout = otherOptions.keepAliveTimeout // Ensure all inactive connections are terminated by the ALB, by setting this a few seconds higher than the ALB idle timeout\n server.headersTimeout = otherOptions.keepAliveTimeout + 1000\n }\n\n return app\n}\n\nexport const getApp = (): express.Express => {\n if (global.appRef) return global.appRef as express.Express\n\n const app = express()\n\n global.appRef = app\n\n return app\n}\n\nexport const getServer = () => {\n return global.serverRef\n}\n","import bodyParser from 'body-parser'\nimport express from 'express'\nimport {getApp} from './../start'\nimport {RouteType} from '../types'\nimport {executeRequest} from './executeRequest'\n\nconst appRegisteredRoutes = new WeakMap<express.Application, WeakSet<RouteType>>()\n\nfunction getRegisteredRoutes(app: express.Application) {\n if (appRegisteredRoutes.has(app)) {\n return appRegisteredRoutes.get(app)\n }\n\n const routes = new WeakSet<RouteType>()\n appRegisteredRoutes.set(app, routes)\n return routes\n}\n\nexport default function registerRoute(route: RouteType): void {\n const app = route.app || getApp()\n const registeredRoutes = getRegisteredRoutes(app)\n if (registeredRoutes.has(route)) return\n\n const method = route.method\n\n const handler: express.RequestHandler = (req, res) => {\n void executeRequest(route, req as any, res)\n }\n\n const handlers: Array<express.RequestHandler> = [handler]\n\n if (route.bodyParser) {\n const parser = bodyParser[route.bodyParser](route.bodyParserOptions)\n handlers.unshift(parser)\n }\n\n if (!route.bodyParser && route.bodyParams) {\n const parser = bodyParser.json(route.bodyParserOptions)\n handlers.unshift(parser)\n }\n\n if (route.middlewares) {\n handlers.unshift(...route.middlewares)\n }\n\n app[method](route.path, ...handlers)\n registeredRoutes.add(route)\n}\n","import {internalGetEnv} from '@orion-js/env'\nimport {sleep} from '@orion-js/helpers'\nimport {runWithOrionAsyncContext, updateOrionAsyncContext} from '@orion-js/logger'\nimport {cleanAndValidate} from '@orion-js/schema'\nimport express from 'express'\nimport {onError} from '../errors'\nimport {OrionRequest, RouteType} from './../types'\nimport {getViewer} from './../viewer'\n\nconst simulateLatency = internalGetEnv('simulate_latency', 'SIMULATE_LATENCY')\nconst simulateLatencyMs = Number.parseInt(simulateLatency, 10)\nconst hasSimulateLatency = Number.isFinite(simulateLatencyMs) && simulateLatencyMs > 0\nconst latencyMinMs = hasSimulateLatency ? Math.floor(simulateLatencyMs * 0.9) : 0\nconst latencyMaxMs = hasSimulateLatency ? Math.ceil(simulateLatencyMs * 1.1) : 0\n\nconst objectToString = Object.prototype.toString\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return objectToString.call(value) === '[object Object]'\n}\n\nexport async function executeRequest(\n route: RouteType<any>,\n req: OrionRequest,\n res: express.Response,\n) {\n try {\n if (hasSimulateLatency) {\n const delay = Math.floor(Math.random() * (latencyMaxMs - latencyMinMs + 1)) + latencyMinMs\n await sleep(delay)\n }\n\n const viewer = await getViewer(req)\n\n if (route.queryParams) {\n req.query = await cleanAndValidate(route.queryParams, req.query)\n }\n\n if (route.bodyParams) {\n req.body = await cleanAndValidate(route.bodyParams, req.body)\n }\n\n const context = {\n controllerType: 'route' as const,\n routeName: route.path,\n pathname: req.path,\n viewer,\n params: {\n body: req.body,\n query: req.query,\n params: req.params,\n },\n }\n\n const result = await runWithOrionAsyncContext(context, () => {\n updateOrionAsyncContext({viewer})\n return route.resolve(req, res, viewer)\n })\n if (!result) return\n\n // add status code to response\n if (result.statusCode) {\n res.status(result.statusCode)\n }\n\n // add headers to response\n if (result.headers) {\n res.set(result.headers)\n }\n\n // add body to response\n if (result.body !== null && result.body !== undefined) {\n let body = result.body\n\n if (route.returns) {\n body = await cleanAndValidate(route.returns, result.body)\n }\n\n if (isPlainObject(body)) {\n res.json(body)\n } else {\n res.send(body)\n }\n }\n } catch (error) {\n await onError(req, res, error)\n }\n}\n","import {RoutesMap} from '../types'\nimport registerRoute from './registerRoute'\n\nexport default function registerRoutes(routesMap: RoutesMap): void {\n for (const routeName in routesMap) {\n registerRoute(routesMap[routeName])\n }\n}\n","import {Schema, SchemaFieldType} from '@orion-js/schema'\nimport {RouteType, OrionRouteOptions} from '../types'\n\nexport function createRoute<\n TPath extends string,\n TQueryParamsSchema extends Schema | undefined,\n TBodyParamsSchema extends Schema | undefined,\n TReturnsSchema extends SchemaFieldType | undefined,\n>(\n options: OrionRouteOptions<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema>,\n): RouteType<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema> {\n return {\n ...options,\n }\n}\n\n/**\n * @deprecated Use createRoute instead\n */\nexport const route = createRoute\n","import {getInstance, Service} from '@orion-js/services'\nimport {createRoute} from '../routes/route'\nimport {OrionRouteOptions, RoutesMap} from '../types'\n\n// Define metadata storage using WeakMaps\nconst serviceMetadata = new WeakMap<any, {_serviceType: string}>()\nconst routeMetadata = new WeakMap<any, Record<string, any>>()\nconst routeEntriesByClass = new Map<Function, Record<string, (instance: any) => any>>()\nlet pendingRouteEntries: Record<string, (instance: any) => any> = {}\n\nexport function Routes() {\n return (target: any, context: ClassDecoratorContext<any>) => {\n Service()(target, context)\n serviceMetadata.set(target, {_serviceType: 'routes'})\n\n if (Object.keys(pendingRouteEntries).length > 0) {\n routeEntriesByClass.set(target, pendingRouteEntries)\n pendingRouteEntries = {}\n }\n }\n}\n\nexport function Route(): (method: any, context: ClassFieldDecoratorContext) => any\nexport function Route(\n options?: Omit<OrionRouteOptions<any, any, any, any>, 'resolve'>,\n): (method: any, context: ClassMethodDecoratorContext) => any\nexport function Route(options?: Omit<OrionRouteOptions<any, any, any, any>, 'resolve'>) {\n return (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => {\n const propertyKey = String(context.name)\n\n if (context.kind === 'method') {\n pendingRouteEntries[propertyKey] = (instance: any) =>\n createRoute({\n ...options,\n resolve: instance[propertyKey].bind(instance),\n })\n }\n\n if (context.kind === 'field') {\n pendingRouteEntries[propertyKey] = (instance: any) => instance[propertyKey]\n }\n\n return method\n }\n}\n\nfunction initializeRoutesIfNeeded(instance: any) {\n if (routeMetadata.has(instance)) return\n const entries = routeEntriesByClass.get(instance.constructor) || {}\n const routes: Record<string, any> = {}\n for (const [key, setup] of Object.entries(entries)) {\n routes[key] = setup(instance)\n }\n routeMetadata.set(instance, routes)\n}\n\nexport function getServiceRoutes(target: any): RoutesMap {\n const instance = getInstance(target)\n\n if (!serviceMetadata.has(instance.constructor)) {\n throw new Error('You must pass a class decorated with @Routes to getServiceRoutes')\n }\n\n const instanceMetadata = serviceMetadata.get(instance.constructor)\n if (instanceMetadata._serviceType !== 'routes') {\n throw new Error('You must pass a class decorated with @Routes to getServiceRoutes')\n }\n\n initializeRoutesIfNeeded(instance)\n\n const routesMap = routeMetadata.get(instance) || {}\n\n return routesMap\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAAA;AAAA,EAAA;AAAA,iCAAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAAmB;AACnB,oBAAqB;AAKrB,IAAM,iBAAkC,OAAO,KAAK,KAAK,UAAU;AACjE,MAAI,MAAM,cAAc;AACtB,QAAI,aAAa;AACjB,QAAI,MAAM,SAAS,aAAa;AAC9B,mBAAa;AAAA,IACf,OAAO;AACL,2BAAO,MAAM,iCAAiC,IAAI,IAAI,KAAK,EAAC,MAAK,CAAC;AAAA,IACpE;AAEA,UAAM,OAAO,MAAM,QAAQ;AAE3B,QAAI,OAAO,UAAU;AACrB,QAAI,KAAK,IAAI;AAAA,EACf,WAAW,MAAM,gBAAgB;AAC/B,QAAI,UAAU,MAAM,UAAU;AAC9B,QAAI,IAAI,MAAM,OAAO;AACrB,yBAAO,MAAM,mCAAmC,IAAI,IAAI,KAAK,EAAC,MAAK,CAAC;AAAA,EACtE,OAAO;AACL,UAAM,OAAO,mBAAAC,QACV,WAAW,MAAM,EACjB,OAAO,MAAM,SAAS,MAAM,EAC5B,OAAO,KAAK,EACZ,UAAU,GAAG,EAAE;AAClB,UAAM,aAAa;AACnB,UAAM,OAAO,EAAC,OAAO,KAAK,SAAS,yBAAyB,KAAI;AAEhE,QAAI,OAAO,UAAU;AACrB,QAAI,KAAK,IAAI;AAEb,UAAM,OAAO;AACb,yBAAO,MAAM,yCAAyC,EAAC,OAAO,KAAK,IAAI,KAAK,KAAI,CAAC;AAAA,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AW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,WAAO,GAAG,IAAI,MAAM,QAAQ;AAAA,EAC9B;AACA,gBAAc,IAAI,UAAU,MAAM;AACpC;AAEO,SAAS,iBAAiB,QAAwB;AACvD,QAAM,eAAW,6BAAY,MAAM;AAEnC,MAAI,CAAC,gBAAgB,IAAI,SAAS,WAAW,GAAG;AAC9C,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AAEA,QAAM,mBAAmB,gBAAgB,IAAI,SAAS,WAAW;AACjE,MAAI,iBAAiB,iBAAiB,UAAU;AAC9C,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AAEA,2BAAyB,QAAQ;AAEjC,QAAM,YAAY,cAAc,IAAI,QAAQ,KAAK,CAAC;AAElD,SAAO;AACT;;;AR9DA,IAAM,EAAC,MAAM,KAAK,MAAM,WAAU,IAAI,oBAAAC;AAEtC,IAAMC,cAKF,EAAC,MAAM,KAAK,MAAM,WAAU;","names":["bodyParser","express","crypto","express","import_express","import_env","import_helpers","import_logger","route","route","bodyParser","import_body_parser","bodyParserLib","bodyParser"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express, { RequestHandler } from 'express';
|
|
2
2
|
export { default as express } from 'express';
|
|
3
3
|
import { OptionsJson, OptionsText, OptionsUrlencoded } from 'body-parser';
|
|
4
|
-
import { Schema,
|
|
4
|
+
import { Schema, InferSchemaType, SchemaFieldType } from '@orion-js/schema';
|
|
5
5
|
|
|
6
6
|
type onErrorFunction = (req: express.Request, res: express.Response, error: any) => Promise<void>;
|
|
7
7
|
declare const onError: onErrorFunction;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express, { RequestHandler } from 'express';
|
|
2
2
|
export { default as express } from 'express';
|
|
3
3
|
import { OptionsJson, OptionsText, OptionsUrlencoded } from 'body-parser';
|
|
4
|
-
import { Schema,
|
|
4
|
+
import { Schema, InferSchemaType, SchemaFieldType } from '@orion-js/schema';
|
|
5
5
|
|
|
6
6
|
type onErrorFunction = (req: express.Request, res: express.Response, error: any) => Promise<void>;
|
|
7
7
|
declare const onError: onErrorFunction;
|
package/dist/index.js
CHANGED
|
@@ -202,33 +202,42 @@ var route = createRoute;
|
|
|
202
202
|
import { getInstance, Service } from "@orion-js/services";
|
|
203
203
|
var serviceMetadata = /* @__PURE__ */ new WeakMap();
|
|
204
204
|
var routeMetadata = /* @__PURE__ */ new WeakMap();
|
|
205
|
+
var routeEntriesByClass = /* @__PURE__ */ new Map();
|
|
206
|
+
var pendingRouteEntries = {};
|
|
205
207
|
function Routes() {
|
|
206
208
|
return (target, context) => {
|
|
207
209
|
Service()(target, context);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
210
|
+
serviceMetadata.set(target, { _serviceType: "routes" });
|
|
211
|
+
if (Object.keys(pendingRouteEntries).length > 0) {
|
|
212
|
+
routeEntriesByClass.set(target, pendingRouteEntries);
|
|
213
|
+
pendingRouteEntries = {};
|
|
214
|
+
}
|
|
211
215
|
};
|
|
212
216
|
}
|
|
213
217
|
function Route(options) {
|
|
214
218
|
return (method, context) => {
|
|
215
219
|
const propertyKey = String(context.name);
|
|
216
|
-
context.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
routes[propertyKey] = this[propertyKey];
|
|
226
|
-
}
|
|
227
|
-
routeMetadata.set(this, routes);
|
|
228
|
-
});
|
|
220
|
+
if (context.kind === "method") {
|
|
221
|
+
pendingRouteEntries[propertyKey] = (instance) => createRoute({
|
|
222
|
+
...options,
|
|
223
|
+
resolve: instance[propertyKey].bind(instance)
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
if (context.kind === "field") {
|
|
227
|
+
pendingRouteEntries[propertyKey] = (instance) => instance[propertyKey];
|
|
228
|
+
}
|
|
229
229
|
return method;
|
|
230
230
|
};
|
|
231
231
|
}
|
|
232
|
+
function initializeRoutesIfNeeded(instance) {
|
|
233
|
+
if (routeMetadata.has(instance)) return;
|
|
234
|
+
const entries = routeEntriesByClass.get(instance.constructor) || {};
|
|
235
|
+
const routes = {};
|
|
236
|
+
for (const [key, setup] of Object.entries(entries)) {
|
|
237
|
+
routes[key] = setup(instance);
|
|
238
|
+
}
|
|
239
|
+
routeMetadata.set(instance, routes);
|
|
240
|
+
}
|
|
232
241
|
function getServiceRoutes(target) {
|
|
233
242
|
const instance = getInstance(target);
|
|
234
243
|
if (!serviceMetadata.has(instance.constructor)) {
|
|
@@ -238,6 +247,7 @@ function getServiceRoutes(target) {
|
|
|
238
247
|
if (instanceMetadata._serviceType !== "routes") {
|
|
239
248
|
throw new Error("You must pass a class decorated with @Routes to getServiceRoutes");
|
|
240
249
|
}
|
|
250
|
+
initializeRoutesIfNeeded(instance);
|
|
241
251
|
const routesMap = routeMetadata.get(instance) || {};
|
|
242
252
|
return routesMap;
|
|
243
253
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/viewer.ts","../src/start.ts","../src/index.ts","../src/routes/registerRoute.ts","../src/routes/executeRequest.ts","../src/routes/registerRoutes.ts","../src/routes/route.ts","../src/service/index.ts"],"sourcesContent":["import crypto from 'node:crypto'\nimport {logger} from '@orion-js/logger'\nimport express from 'express'\n\ntype onErrorFunction = (req: express.Request, res: express.Response, error: any) => Promise<void>\n\nconst defaultOnError: onErrorFunction = async (req, res, error) => {\n if (error.isOrionError) {\n let statusCode = 400\n if (error.code === 'AuthError') {\n statusCode = 401\n } else {\n logger.error(`[route/handler] OrionError in ${req.path}:`, {error})\n }\n\n const data = error.getInfo()\n\n res.status(statusCode)\n res.json(data)\n } else if (error.isGraphQLError) {\n res.writeHead(error.statusCode)\n res.end(error.message)\n logger.error(`[route/handler] GraphQLError in ${req.path}:`, {error})\n } else {\n const hash = crypto\n .createHash('sha1')\n .update(error.message, 'utf8')\n .digest('hex')\n .substring(0, 10)\n const statusCode = 500\n const data = {error: 500, message: 'Internal server error', hash}\n\n res.status(statusCode)\n res.json(data)\n\n error.hash = hash\n logger.error('[route/handler] Internal server error', {error, url: req.url, hash})\n }\n}\n\nlet onErrorRef: onErrorFunction = defaultOnError\n\nexport const onError: onErrorFunction = async (req, res, error) => {\n return onErrorRef(req, res, error)\n}\n\nexport const setOnError = (onErrorFunc: onErrorFunction): void => {\n onErrorRef = onErrorFunc\n}\n","import express from 'express'\nimport {UserError} from '@orion-js/helpers'\n\nglobal.getViewerRef = () => null\n\nexport const getViewer = async (req: express.Request): Promise<any> => {\n try {\n const viewer = await global.getViewerRef(req)\n if (!viewer) return {}\n return viewer\n } catch (err) {\n throw new UserError('AuthError', err.message)\n }\n}\n\nexport const setGetViewer = (getViewerFunc: (req: express.Request) => any): void => {\n global.getViewerRef = getViewerFunc\n}\n","import {internalGetEnv} from '@orion-js/env'\nimport express from 'express'\n\nglobal.appRef = null\nglobal.serverRef = null\n\nexport interface StartOrionOptions {\n keepAliveTimeout?: number\n}\n\nexport const startServer = (\n port: number = Number(internalGetEnv('http_port', 'PORT')),\n otherOptions: StartOrionOptions = {},\n) => {\n const app = getApp()\n\n const server = app.listen(port)\n global.serverRef = server\n\n if (otherOptions.keepAliveTimeout) {\n server.keepAliveTimeout = otherOptions.keepAliveTimeout // Ensure all inactive connections are terminated by the ALB, by setting this a few seconds higher than the ALB idle timeout\n server.headersTimeout = otherOptions.keepAliveTimeout + 1000\n }\n\n return app\n}\n\nexport const getApp = (): express.Express => {\n if (global.appRef) return global.appRef as express.Express\n\n const app = express()\n\n global.appRef = app\n\n return app\n}\n\nexport const getServer = () => {\n return global.serverRef\n}\n","import {setOnError, onError} from './errors'\nimport {getViewer, setGetViewer} from './viewer'\nimport {startServer, getApp, getServer} from './start'\nimport express from 'express'\nimport registerRoute from './routes/registerRoute'\nimport registerRoutes from './routes/registerRoutes'\nimport bodyParserLib from 'body-parser'\nimport {RequestHandler} from 'express'\n\nexport * from './routes/route'\n\nconst {json, raw, text, urlencoded} = bodyParserLib\n\nconst bodyParser: {\n json: () => RequestHandler\n raw: () => RequestHandler\n text: () => RequestHandler\n urlencoded: (options?: {extended: boolean}) => RequestHandler\n} = {json, raw, text, urlencoded}\n\nexport {\n express,\n startServer,\n getApp,\n getServer,\n getViewer,\n setGetViewer,\n setOnError,\n onError,\n registerRoute,\n registerRoutes,\n bodyParser,\n}\n\nexport * from './types'\nexport * from './service'\n","import bodyParser from 'body-parser'\nimport express from 'express'\nimport {getApp} from './../start'\nimport {RouteType} from '../types'\nimport {executeRequest} from './executeRequest'\n\nconst appRegisteredRoutes = new WeakMap<express.Application, WeakSet<RouteType>>()\n\nfunction getRegisteredRoutes(app: express.Application) {\n if (appRegisteredRoutes.has(app)) {\n return appRegisteredRoutes.get(app)\n }\n\n const routes = new WeakSet<RouteType>()\n appRegisteredRoutes.set(app, routes)\n return routes\n}\n\nexport default function registerRoute(route: RouteType): void {\n const app = route.app || getApp()\n const registeredRoutes = getRegisteredRoutes(app)\n if (registeredRoutes.has(route)) return\n\n const method = route.method\n\n const handler: express.RequestHandler = (req, res) => {\n void executeRequest(route, req as any, res)\n }\n\n const handlers: Array<express.RequestHandler> = [handler]\n\n if (route.bodyParser) {\n const parser = bodyParser[route.bodyParser](route.bodyParserOptions)\n handlers.unshift(parser)\n }\n\n if (!route.bodyParser && route.bodyParams) {\n const parser = bodyParser.json(route.bodyParserOptions)\n handlers.unshift(parser)\n }\n\n if (route.middlewares) {\n handlers.unshift(...route.middlewares)\n }\n\n app[method](route.path, ...handlers)\n registeredRoutes.add(route)\n}\n","import {internalGetEnv} from '@orion-js/env'\nimport {sleep} from '@orion-js/helpers'\nimport {runWithOrionAsyncContext, updateOrionAsyncContext} from '@orion-js/logger'\nimport {cleanAndValidate} from '@orion-js/schema'\nimport express from 'express'\nimport {onError} from '../errors'\nimport {OrionRequest, RouteType} from './../types'\nimport {getViewer} from './../viewer'\n\nconst simulateLatency = internalGetEnv('simulate_latency', 'SIMULATE_LATENCY')\nconst simulateLatencyMs = Number.parseInt(simulateLatency, 10)\nconst hasSimulateLatency = Number.isFinite(simulateLatencyMs) && simulateLatencyMs > 0\nconst latencyMinMs = hasSimulateLatency ? Math.floor(simulateLatencyMs * 0.9) : 0\nconst latencyMaxMs = hasSimulateLatency ? Math.ceil(simulateLatencyMs * 1.1) : 0\n\nconst objectToString = Object.prototype.toString\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return objectToString.call(value) === '[object Object]'\n}\n\nexport async function executeRequest(\n route: RouteType<any>,\n req: OrionRequest,\n res: express.Response,\n) {\n try {\n if (hasSimulateLatency) {\n const delay = Math.floor(Math.random() * (latencyMaxMs - latencyMinMs + 1)) + latencyMinMs\n await sleep(delay)\n }\n\n const viewer = await getViewer(req)\n\n if (route.queryParams) {\n req.query = await cleanAndValidate(route.queryParams, req.query)\n }\n\n if (route.bodyParams) {\n req.body = await cleanAndValidate(route.bodyParams, req.body)\n }\n\n const context = {\n controllerType: 'route' as const,\n routeName: route.path,\n pathname: req.path,\n viewer,\n params: {\n body: req.body,\n query: req.query,\n params: req.params,\n },\n }\n\n const result = await runWithOrionAsyncContext(context, () => {\n updateOrionAsyncContext({viewer})\n return route.resolve(req, res, viewer)\n })\n if (!result) return\n\n // add status code to response\n if (result.statusCode) {\n res.status(result.statusCode)\n }\n\n // add headers to response\n if (result.headers) {\n res.set(result.headers)\n }\n\n // add body to response\n if (result.body !== null && result.body !== undefined) {\n let body = result.body\n\n if (route.returns) {\n body = await cleanAndValidate(route.returns, result.body)\n }\n\n if (isPlainObject(body)) {\n res.json(body)\n } else {\n res.send(body)\n }\n }\n } catch (error) {\n await onError(req, res, error)\n }\n}\n","import {RoutesMap} from '../types'\nimport registerRoute from './registerRoute'\n\nexport default function registerRoutes(routesMap: RoutesMap): void {\n for (const routeName in routesMap) {\n registerRoute(routesMap[routeName])\n }\n}\n","import {Schema, SchemaFieldType} from '@orion-js/schema'\nimport {RouteType, OrionRouteOptions} from '../types'\n\nexport function createRoute<\n TPath extends string,\n TQueryParamsSchema extends Schema | undefined,\n TBodyParamsSchema extends Schema | undefined,\n TReturnsSchema extends SchemaFieldType | undefined,\n>(\n options: OrionRouteOptions<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema>,\n): RouteType<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema> {\n return {\n ...options,\n }\n}\n\n/**\n * @deprecated Use createRoute instead\n */\nexport const route = createRoute\n","import {getInstance, Service} from '@orion-js/services'\nimport {createRoute} from '../routes/route'\nimport {OrionRouteOptions, RoutesMap} from '../types'\n\n// Define metadata storage using WeakMaps\nconst serviceMetadata = new WeakMap<any, {_serviceType: string}>()\nconst routeMetadata = new WeakMap<any, Record<string, any>>()\n\nexport function Routes() {\n return (target: any, context: ClassDecoratorContext<any>) => {\n Service()(target, context)\n\n context.addInitializer(function (this) {\n serviceMetadata.set(this, {_serviceType: 'routes'})\n })\n }\n}\n\nexport function Route(): (method: any, context: ClassFieldDecoratorContext) => any\nexport function Route(\n options?: Omit<OrionRouteOptions<any, any, any, any>, 'resolve'>,\n): (method: any, context: ClassMethodDecoratorContext) => any\nexport function Route(options?: Omit<OrionRouteOptions<any, any, any, any>, 'resolve'>) {\n return (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => {\n const propertyKey = String(context.name)\n\n context.addInitializer(function (this) {\n const routes = routeMetadata.get(this) || {}\n\n if (context.kind === 'method') {\n routes[propertyKey] = createRoute({\n ...options,\n resolve: this[propertyKey].bind(this),\n })\n }\n\n if (context.kind === 'field') {\n routes[propertyKey] = this[propertyKey]\n }\n\n routeMetadata.set(this, routes)\n })\n\n return method\n }\n}\n\nexport function getServiceRoutes(target: any): RoutesMap {\n const instance = getInstance(target)\n\n if (!serviceMetadata.has(instance.constructor)) {\n throw new Error('You must pass a class decorated with @Routes to getServiceRoutes')\n }\n\n const instanceMetadata = serviceMetadata.get(instance.constructor)\n if (instanceMetadata._serviceType !== 'routes') {\n throw new Error('You must pass a class decorated with @Routes to getServiceRoutes')\n }\n\n const routesMap = routeMetadata.get(instance) || {}\n\n return routesMap\n}\n"],"mappings":";AAAA,OAAO,YAAY;AACnB,SAAQ,cAAa;AAKrB,IAAM,iBAAkC,OAAO,KAAK,KAAK,UAAU;AACjE,MAAI,MAAM,cAAc;AACtB,QAAI,aAAa;AACjB,QAAI,MAAM,SAAS,aAAa;AAC9B,mBAAa;AAAA,IACf,OAAO;AACL,aAAO,MAAM,iCAAiC,IAAI,IAAI,KAAK,EAAC,MAAK,CAAC;AAAA,IACpE;AAEA,UAAM,OAAO,MAAM,QAAQ;AAE3B,QAAI,OAAO,UAAU;AACrB,QAAI,KAAK,IAAI;AAAA,EACf,WAAW,MAAM,gBAAgB;AAC/B,QAAI,UAAU,MAAM,UAAU;AAC9B,QAAI,IAAI,MAAM,OAAO;AACrB,WAAO,MAAM,mCAAmC,IAAI,IAAI,KAAK,EAAC,MAAK,CAAC;AAAA,EACtE,OAAO;AACL,UAAM,OAAO,OACV,WAAW,MAAM,EACjB,OAAO,MAAM,SAAS,MAAM,EAC5B,OAAO,KAAK,EACZ,UAAU,GAAG,EAAE;AAClB,UAAM,aAAa;AACnB,UAAM,OAAO,EAAC,OAAO,KAAK,SAAS,yBAAyB,KAAI;AAEhE,QAAI,OAAO,UAAU;AACrB,QAAI,KAAK,IAAI;AAEb,UAAM,OAAO;AACb,WAAO,MAAM,yCAAyC,EAAC,OAAO,KAAK,IAAI,KAAK,KAAI,CAAC;AAAA,EACnF;AACF;AAEA,IAAI,aAA8B;AAE3B,IAAM,UAA2B,OAAO,KAAK,KAAK,UAAU;AACjE,SAAO,WAAW,KAAK,KAAK,KAAK;AACnC;AAEO,IAAM,aAAa,CAAC,gBAAuC;AAChE,eAAa;AACf;;;AC/CA,SAAQ,iBAAgB;AAExB,OAAO,eAAe,MAAM;AAErB,IAAM,YAAY,OAAO,QA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EAAC,MAAM,KAAK,MAAM,WAAU;","names":["express","internalGetEnv","internalGetEnv","route","route","bodyParser"]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/viewer.ts","../src/start.ts","../src/index.ts","../src/routes/registerRoute.ts","../src/routes/executeRequest.ts","../src/routes/registerRoutes.ts","../src/routes/route.ts","../src/service/index.ts"],"sourcesContent":["import crypto from 'node:crypto'\nimport {logger} from '@orion-js/logger'\nimport express from 'express'\n\ntype onErrorFunction = (req: express.Request, res: express.Response, error: any) => Promise<void>\n\nconst defaultOnError: onErrorFunction = async (req, res, error) => {\n if (error.isOrionError) {\n let statusCode = 400\n if (error.code === 'AuthError') {\n statusCode = 401\n } else {\n logger.error(`[route/handler] OrionError in ${req.path}:`, {error})\n }\n\n const data = error.getInfo()\n\n res.status(statusCode)\n res.json(data)\n } else if (error.isGraphQLError) {\n res.writeHead(error.statusCode)\n res.end(error.message)\n logger.error(`[route/handler] GraphQLError in ${req.path}:`, {error})\n } else {\n const hash = crypto\n .createHash('sha1')\n .update(error.message, 'utf8')\n .digest('hex')\n .substring(0, 10)\n const statusCode = 500\n const data = {error: 500, message: 'Internal server error', hash}\n\n res.status(statusCode)\n res.json(data)\n\n error.hash = hash\n logger.error('[route/handler] Internal server error', {error, url: req.url, hash})\n }\n}\n\nlet onErrorRef: onErrorFunction = defaultOnError\n\nexport const onError: onErrorFunction = async (req, res, error) => {\n return onErrorRef(req, res, error)\n}\n\nexport const setOnError = (onErrorFunc: onErrorFunction): void => {\n onErrorRef = onErrorFunc\n}\n","import express from 'express'\nimport {UserError} from '@orion-js/helpers'\n\nglobal.getViewerRef = () => null\n\nexport const getViewer = async (req: express.Request): Promise<any> => {\n try {\n const viewer = await global.getViewerRef(req)\n if (!viewer) return {}\n return viewer\n } catch (err) {\n throw new UserError('AuthError', err.message)\n }\n}\n\nexport const setGetViewer = (getViewerFunc: (req: express.Request) => any): void => {\n global.getViewerRef = getViewerFunc\n}\n","import {internalGetEnv} from '@orion-js/env'\nimport express from 'express'\n\nglobal.appRef = null\nglobal.serverRef = null\n\nexport interface StartOrionOptions {\n keepAliveTimeout?: number\n}\n\nexport const startServer = (\n port: number = Number(internalGetEnv('http_port', 'PORT')),\n otherOptions: StartOrionOptions = {},\n) => {\n const app = getApp()\n\n const server = app.listen(port)\n global.serverRef = server\n\n if (otherOptions.keepAliveTimeout) {\n server.keepAliveTimeout = otherOptions.keepAliveTimeout // Ensure all inactive connections are terminated by the ALB, by setting this a few seconds higher than the ALB idle timeout\n server.headersTimeout = otherOptions.keepAliveTimeout + 1000\n }\n\n return app\n}\n\nexport const getApp = (): express.Express => {\n if (global.appRef) return global.appRef as express.Express\n\n const app = express()\n\n global.appRef = app\n\n return app\n}\n\nexport const getServer = () => {\n return global.serverRef\n}\n","import {setOnError, onError} from './errors'\nimport {getViewer, setGetViewer} from './viewer'\nimport {startServer, getApp, getServer} from './start'\nimport express from 'express'\nimport registerRoute from './routes/registerRoute'\nimport registerRoutes from './routes/registerRoutes'\nimport bodyParserLib from 'body-parser'\nimport {RequestHandler} from 'express'\n\nexport * from './routes/route'\n\nconst {json, raw, text, urlencoded} = bodyParserLib\n\nconst bodyParser: {\n json: () => RequestHandler\n raw: () => RequestHandler\n text: () => RequestHandler\n urlencoded: (options?: {extended: boolean}) => RequestHandler\n} = {json, raw, text, urlencoded}\n\nexport {\n express,\n startServer,\n getApp,\n getServer,\n getViewer,\n setGetViewer,\n setOnError,\n onError,\n registerRoute,\n registerRoutes,\n bodyParser,\n}\n\nexport * from './types'\nexport * from './service'\n","import bodyParser from 'body-parser'\nimport express from 'express'\nimport {getApp} from './../start'\nimport {RouteType} from '../types'\nimport {executeRequest} from './executeRequest'\n\nconst appRegisteredRoutes = new WeakMap<express.Application, WeakSet<RouteType>>()\n\nfunction getRegisteredRoutes(app: express.Application) {\n if (appRegisteredRoutes.has(app)) {\n return appRegisteredRoutes.get(app)\n }\n\n const routes = new WeakSet<RouteType>()\n appRegisteredRoutes.set(app, routes)\n return routes\n}\n\nexport default function registerRoute(route: RouteType): void {\n const app = route.app || getApp()\n const registeredRoutes = getRegisteredRoutes(app)\n if (registeredRoutes.has(route)) return\n\n const method = route.method\n\n const handler: express.RequestHandler = (req, res) => {\n void executeRequest(route, req as any, res)\n }\n\n const handlers: Array<express.RequestHandler> = [handler]\n\n if (route.bodyParser) {\n const parser = bodyParser[route.bodyParser](route.bodyParserOptions)\n handlers.unshift(parser)\n }\n\n if (!route.bodyParser && route.bodyParams) {\n const parser = bodyParser.json(route.bodyParserOptions)\n handlers.unshift(parser)\n }\n\n if (route.middlewares) {\n handlers.unshift(...route.middlewares)\n }\n\n app[method](route.path, ...handlers)\n registeredRoutes.add(route)\n}\n","import {internalGetEnv} from '@orion-js/env'\nimport {sleep} from '@orion-js/helpers'\nimport {runWithOrionAsyncContext, updateOrionAsyncContext} from '@orion-js/logger'\nimport {cleanAndValidate} from '@orion-js/schema'\nimport express from 'express'\nimport {onError} from '../errors'\nimport {OrionRequest, RouteType} from './../types'\nimport {getViewer} from './../viewer'\n\nconst simulateLatency = internalGetEnv('simulate_latency', 'SIMULATE_LATENCY')\nconst simulateLatencyMs = Number.parseInt(simulateLatency, 10)\nconst hasSimulateLatency = Number.isFinite(simulateLatencyMs) && simulateLatencyMs > 0\nconst latencyMinMs = hasSimulateLatency ? Math.floor(simulateLatencyMs * 0.9) : 0\nconst latencyMaxMs = hasSimulateLatency ? Math.ceil(simulateLatencyMs * 1.1) : 0\n\nconst objectToString = Object.prototype.toString\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return objectToString.call(value) === '[object Object]'\n}\n\nexport async function executeRequest(\n route: RouteType<any>,\n req: OrionRequest,\n res: express.Response,\n) {\n try {\n if (hasSimulateLatency) {\n const delay = Math.floor(Math.random() * (latencyMaxMs - latencyMinMs + 1)) + latencyMinMs\n await sleep(delay)\n }\n\n const viewer = await getViewer(req)\n\n if (route.queryParams) {\n req.query = await cleanAndValidate(route.queryParams, req.query)\n }\n\n if (route.bodyParams) {\n req.body = await cleanAndValidate(route.bodyParams, req.body)\n }\n\n const context = {\n controllerType: 'route' as const,\n routeName: route.path,\n pathname: req.path,\n viewer,\n params: {\n body: req.body,\n query: req.query,\n params: req.params,\n },\n }\n\n const result = await runWithOrionAsyncContext(context, () => {\n updateOrionAsyncContext({viewer})\n return route.resolve(req, res, viewer)\n })\n if (!result) return\n\n // add status code to response\n if (result.statusCode) {\n res.status(result.statusCode)\n }\n\n // add headers to response\n if (result.headers) {\n res.set(result.headers)\n }\n\n // add body to response\n if (result.body !== null && result.body !== undefined) {\n let body = result.body\n\n if (route.returns) {\n body = await cleanAndValidate(route.returns, result.body)\n }\n\n if (isPlainObject(body)) {\n res.json(body)\n } else {\n res.send(body)\n }\n }\n } catch (error) {\n await onError(req, res, error)\n }\n}\n","import {RoutesMap} from '../types'\nimport registerRoute from './registerRoute'\n\nexport default function registerRoutes(routesMap: RoutesMap): void {\n for (const routeName in routesMap) {\n registerRoute(routesMap[routeName])\n }\n}\n","import {Schema, SchemaFieldType} from '@orion-js/schema'\nimport {RouteType, OrionRouteOptions} from '../types'\n\nexport function createRoute<\n TPath extends string,\n TQueryParamsSchema extends Schema | undefined,\n TBodyParamsSchema extends Schema | undefined,\n TReturnsSchema extends SchemaFieldType | undefined,\n>(\n options: OrionRouteOptions<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema>,\n): RouteType<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema> {\n return {\n ...options,\n }\n}\n\n/**\n * @deprecated Use createRoute instead\n */\nexport const route = createRoute\n","import {getInstance, Service} from '@orion-js/services'\nimport {createRoute} from '../routes/route'\nimport {OrionRouteOptions, RoutesMap} from '../types'\n\n// Define metadata storage using WeakMaps\nconst serviceMetadata = new WeakMap<any, {_serviceType: string}>()\nconst routeMetadata = new WeakMap<any, Record<string, any>>()\nconst routeEntriesByClass = new Map<Function, Record<string, (instance: any) => any>>()\nlet pendingRouteEntries: Record<string, (instance: any) => any> = {}\n\nexport function Routes() {\n return (target: any, context: ClassDecoratorContext<any>) => {\n Service()(target, context)\n serviceMetadata.set(target, {_serviceType: 'routes'})\n\n if (Object.keys(pendingRouteEntries).length > 0) {\n routeEntriesByClass.set(target, pendingRouteEntries)\n pendingRouteEntries = {}\n }\n }\n}\n\nexport function Route(): (method: any, context: ClassFieldDecoratorContext) => any\nexport function Route(\n options?: Omit<OrionRouteOptions<any, any, any, any>, 'resolve'>,\n): (method: any, context: ClassMethodDecoratorContext) => any\nexport function Route(options?: Omit<OrionRouteOptions<any, any, any, any>, 'resolve'>) {\n return (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => {\n const propertyKey = String(context.name)\n\n if (context.kind === 'method') {\n pendingRouteEntries[propertyKey] = (instance: any) =>\n createRoute({\n ...options,\n resolve: instance[propertyKey].bind(instance),\n })\n }\n\n if (context.kind === 'field') {\n pendingRouteEntries[propertyKey] = (instance: any) => instance[propertyKey]\n }\n\n return method\n }\n}\n\nfunction initializeRoutesIfNeeded(instance: any) {\n if (routeMetadata.has(instance)) return\n const entries = routeEntriesByClass.get(instance.constructor) || {}\n const routes: Record<string, any> = {}\n for (const [key, setup] of Object.entries(entries)) {\n routes[key] = setup(instance)\n }\n routeMetadata.set(instance, routes)\n}\n\nexport function getServiceRoutes(target: any): RoutesMap {\n const instance = getInstance(target)\n\n if (!serviceMetadata.has(instance.constructor)) {\n throw new Error('You must pass a class decorated with @Routes to getServiceRoutes')\n }\n\n const instanceMetadata = serviceMetadata.get(instance.constructor)\n if (instanceMetadata._serviceType !== 'routes') {\n throw new Error('You must pass a class decorated with @Routes to getServiceRoutes')\n }\n\n initializeRoutesIfNeeded(instance)\n\n const routesMap = routeMetadata.get(instance) || {}\n\n return routesMap\n}\n"],"mappings":";AAAA,OAAO,YAAY;AACnB,SAAQ,cAAa;AAKrB,IAAM,iBAAkC,OAAO,KAAK,KAAK,UAAU;AACjE,MAAI,MAAM,cAAc;AACtB,QAAI,aAAa;AACjB,QAAI,MAAM,SAA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9DA,IAAM,EAAC,MAAM,KAAK,MAAM,WAAU,IAAI;AAEtC,IAAMC,cAKF,EAAC,MAAM,KAAK,MAAM,WAAU;","names":["express","internalGetEnv","internalGetEnv","route","route","bodyParser"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/http",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -8,17 +8,24 @@
|
|
|
8
8
|
],
|
|
9
9
|
"author": "nicolaslopezj",
|
|
10
10
|
"license": "MIT",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "bun test",
|
|
13
|
+
"prepare": "bun run build",
|
|
14
|
+
"clean": "rm -rf ./dist",
|
|
15
|
+
"build": "tsup",
|
|
16
|
+
"dev": "tsup --watch"
|
|
17
|
+
},
|
|
11
18
|
"dependencies": {
|
|
19
|
+
"@orion-js/env": "4.3.0",
|
|
20
|
+
"@orion-js/helpers": "4.3.0",
|
|
21
|
+
"@orion-js/resolvers": "4.3.0",
|
|
22
|
+
"@orion-js/schema": "4.3.0",
|
|
23
|
+
"@orion-js/services": "4.3.0",
|
|
12
24
|
"body-parser": "1.20.3",
|
|
13
|
-
"express": "4.21.2"
|
|
14
|
-
"@orion-js/env": "4.2.1",
|
|
15
|
-
"@orion-js/schema": "4.2.1",
|
|
16
|
-
"@orion-js/resolvers": "4.2.1",
|
|
17
|
-
"@orion-js/services": "4.2.0",
|
|
18
|
-
"@orion-js/helpers": "4.2.0"
|
|
25
|
+
"express": "4.21.2"
|
|
19
26
|
},
|
|
20
27
|
"peerDependencies": {
|
|
21
|
-
"@orion-js/logger": "4.
|
|
28
|
+
"@orion-js/logger": "4.3.0"
|
|
22
29
|
},
|
|
23
30
|
"devDependencies": {
|
|
24
31
|
"@types/body-parser": "^1.19.1",
|
|
@@ -28,8 +35,7 @@
|
|
|
28
35
|
"superagent": "^10.2.0",
|
|
29
36
|
"supertest": "^7.0.0",
|
|
30
37
|
"tsup": "^8.0.1",
|
|
31
|
-
"typescript": "^5.4.5"
|
|
32
|
-
"vitest": "^3.0.8"
|
|
38
|
+
"typescript": "^5.4.5"
|
|
33
39
|
},
|
|
34
40
|
"publishConfig": {
|
|
35
41
|
"access": "public"
|
|
@@ -41,12 +47,5 @@
|
|
|
41
47
|
"types": "./dist/index.d.ts",
|
|
42
48
|
"import": "./dist/index.js",
|
|
43
49
|
"require": "./dist/index.cjs"
|
|
44
|
-
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"test": "vitest run",
|
|
47
|
-
"clean": "rm -rf ./dist",
|
|
48
|
-
"build": "tsup",
|
|
49
|
-
"upgrade-interactive": "pnpm upgrade --interactive",
|
|
50
|
-
"dev": "tsup --watch"
|
|
51
50
|
}
|
|
52
|
-
}
|
|
51
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Orionjs Team
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|