@orion-js/http 4.2.4 → 4.3.1

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 CHANGED
@@ -31,7 +31,7 @@ var index_exports = {};
31
31
  __export(index_exports, {
32
32
  Route: () => Route,
33
33
  Routes: () => Routes,
34
- bodyParser: () => bodyParser2,
34
+ bodyParser: () => bodyParser3,
35
35
  createRoute: () => createRoute,
36
36
  express: () => import_express2.default,
37
37
  getApp: () => getApp,
@@ -39,6 +39,7 @@ __export(index_exports, {
39
39
  getServiceRoutes: () => getServiceRoutes,
40
40
  getViewer: () => getViewer,
41
41
  onError: () => onError,
42
+ registerReplEndpoint: () => registerReplEndpoint,
42
43
  registerRoute: () => registerRoute,
43
44
  registerRoutes: () => registerRoutes,
44
45
  route: () => route,
@@ -47,6 +48,8 @@ __export(index_exports, {
47
48
  startServer: () => startServer
48
49
  });
49
50
  module.exports = __toCommonJS(index_exports);
51
+ var import_body_parser3 = __toESM(require("body-parser"), 1);
52
+ var import_express2 = __toESM(require("express"), 1);
50
53
 
51
54
  // src/errors.ts
52
55
  var import_node_crypto = __toESM(require("crypto"), 1);
@@ -84,25 +87,34 @@ var setOnError = (onErrorFunc) => {
84
87
  onErrorRef = onErrorFunc;
85
88
  };
86
89
 
87
- // src/viewer.ts
88
- var import_helpers = require("@orion-js/helpers");
89
- global.getViewerRef = () => null;
90
- var getViewer = async (req) => {
91
- try {
92
- const viewer = await global.getViewerRef(req);
93
- if (!viewer) return {};
94
- return viewer;
95
- } catch (err) {
96
- throw new import_helpers.UserError("AuthError", err.message);
97
- }
98
- };
99
- var setGetViewer = (getViewerFunc) => {
100
- global.getViewerRef = getViewerFunc;
101
- };
90
+ // src/routes/registerRoute.ts
91
+ var import_body_parser2 = __toESM(require("body-parser"), 1);
102
92
 
103
93
  // src/start.ts
94
+ var import_node_fs = require("fs");
104
95
  var import_env = require("@orion-js/env");
105
96
  var import_express = __toESM(require("express"), 1);
97
+
98
+ // src/repl.ts
99
+ var import_services = require("@orion-js/services");
100
+ var import_body_parser = __toESM(require("body-parser"), 1);
101
+ function registerReplEndpoint() {
102
+ const app = getApp();
103
+ app.post("/__repl", import_body_parser.default.json(), async (req, res) => {
104
+ try {
105
+ const { expression } = req.body;
106
+ const AsyncFunction = Object.getPrototypeOf(async () => {
107
+ }).constructor;
108
+ const fn = new AsyncFunction("getInstance", expression);
109
+ const result = await fn(import_services.getInstance);
110
+ res.json({ success: true, result });
111
+ } catch (error) {
112
+ res.json({ success: false, error: error.message, stack: error.stack });
113
+ }
114
+ });
115
+ }
116
+
117
+ // src/start.ts
106
118
  global.appRef = null;
107
119
  global.serverRef = null;
108
120
  var startServer = (port = Number((0, import_env.internalGetEnv)("http_port", "PORT")), otherOptions = {}) => {
@@ -113,6 +125,14 @@ var startServer = (port = Number((0, import_env.internalGetEnv)("http_port", "PO
113
125
  server.keepAliveTimeout = otherOptions.keepAliveTimeout;
114
126
  server.headersTimeout = otherOptions.keepAliveTimeout + 1e3;
115
127
  }
128
+ if (process.env.ORION_REPL) {
129
+ registerReplEndpoint();
130
+ try {
131
+ (0, import_node_fs.mkdirSync)(".orion", { recursive: true });
132
+ (0, import_node_fs.writeFileSync)(".orion/port", String(port));
133
+ } catch {
134
+ }
135
+ }
116
136
  return app;
117
137
  };
118
138
  var getApp = () => {
@@ -125,17 +145,29 @@ var getServer = () => {
125
145
  return global.serverRef;
126
146
  };
127
147
 
128
- // src/index.ts
129
- var import_express2 = __toESM(require("express"), 1);
130
-
131
- // src/routes/registerRoute.ts
132
- var import_body_parser = __toESM(require("body-parser"), 1);
133
-
134
148
  // src/routes/executeRequest.ts
135
149
  var import_env2 = require("@orion-js/env");
136
150
  var import_helpers2 = require("@orion-js/helpers");
137
151
  var import_logger2 = require("@orion-js/logger");
138
152
  var import_schema = require("@orion-js/schema");
153
+
154
+ // src/viewer.ts
155
+ var import_helpers = require("@orion-js/helpers");
156
+ global.getViewerRef = () => null;
157
+ var getViewer = async (req) => {
158
+ try {
159
+ const viewer = await global.getViewerRef(req);
160
+ if (!viewer) return {};
161
+ return viewer;
162
+ } catch (err) {
163
+ throw new import_helpers.UserError("AuthError", err.message);
164
+ }
165
+ };
166
+ var setGetViewer = (getViewerFunc) => {
167
+ global.getViewerRef = getViewerFunc;
168
+ };
169
+
170
+ // src/routes/executeRequest.ts
139
171
  var simulateLatency = (0, import_env2.internalGetEnv)("simulate_latency", "SIMULATE_LATENCY");
140
172
  var simulateLatencyMs = Number.parseInt(simulateLatency, 10);
141
173
  var hasSimulateLatency = Number.isFinite(simulateLatencyMs) && simulateLatencyMs > 0;
@@ -216,11 +248,11 @@ function registerRoute(route2) {
216
248
  };
217
249
  const handlers = [handler];
218
250
  if (route2.bodyParser) {
219
- const parser = import_body_parser.default[route2.bodyParser](route2.bodyParserOptions);
251
+ const parser = import_body_parser2.default[route2.bodyParser](route2.bodyParserOptions);
220
252
  handlers.unshift(parser);
221
253
  }
222
254
  if (!route2.bodyParser && route2.bodyParams) {
223
- const parser = import_body_parser.default.json(route2.bodyParserOptions);
255
+ const parser = import_body_parser2.default.json(route2.bodyParserOptions);
224
256
  handlers.unshift(parser);
225
257
  }
226
258
  if (route2.middlewares) {
@@ -237,9 +269,6 @@ function registerRoutes(routesMap) {
237
269
  }
238
270
  }
239
271
 
240
- // src/index.ts
241
- var import_body_parser2 = __toESM(require("body-parser"), 1);
242
-
243
272
  // src/routes/route.ts
244
273
  function createRoute(options) {
245
274
  return {
@@ -249,38 +278,47 @@ function createRoute(options) {
249
278
  var route = createRoute;
250
279
 
251
280
  // src/service/index.ts
252
- var import_services = require("@orion-js/services");
281
+ var import_services2 = require("@orion-js/services");
253
282
  var serviceMetadata = /* @__PURE__ */ new WeakMap();
254
283
  var routeMetadata = /* @__PURE__ */ new WeakMap();
284
+ var routeEntriesByClass = /* @__PURE__ */ new Map();
285
+ var pendingRouteEntries = {};
255
286
  function Routes() {
256
287
  return (target, context) => {
257
- (0, import_services.Service)()(target, context);
258
- context.addInitializer(function() {
259
- serviceMetadata.set(this, { _serviceType: "routes" });
260
- });
288
+ (0, import_services2.Service)()(target, context);
289
+ serviceMetadata.set(target, { _serviceType: "routes" });
290
+ if (Object.keys(pendingRouteEntries).length > 0) {
291
+ routeEntriesByClass.set(target, pendingRouteEntries);
292
+ pendingRouteEntries = {};
293
+ }
261
294
  };
262
295
  }
263
296
  function Route(options) {
264
297
  return (method, context) => {
265
298
  const propertyKey = String(context.name);
266
- context.addInitializer(function() {
267
- const routes = routeMetadata.get(this) || {};
268
- if (context.kind === "method") {
269
- routes[propertyKey] = createRoute({
270
- ...options,
271
- resolve: this[propertyKey].bind(this)
272
- });
273
- }
274
- if (context.kind === "field") {
275
- routes[propertyKey] = this[propertyKey];
276
- }
277
- routeMetadata.set(this, routes);
278
- });
299
+ if (context.kind === "method") {
300
+ pendingRouteEntries[propertyKey] = (instance) => createRoute({
301
+ ...options,
302
+ resolve: instance[propertyKey].bind(instance)
303
+ });
304
+ }
305
+ if (context.kind === "field") {
306
+ pendingRouteEntries[propertyKey] = (instance) => instance[propertyKey];
307
+ }
279
308
  return method;
280
309
  };
281
310
  }
311
+ function initializeRoutesIfNeeded(instance) {
312
+ if (routeMetadata.has(instance)) return;
313
+ const entries = routeEntriesByClass.get(instance.constructor) || {};
314
+ const routes = {};
315
+ for (const [key, setup] of Object.entries(entries)) {
316
+ routes[key] = setup(instance);
317
+ }
318
+ routeMetadata.set(instance, routes);
319
+ }
282
320
  function getServiceRoutes(target) {
283
- const instance = (0, import_services.getInstance)(target);
321
+ const instance = (0, import_services2.getInstance)(target);
284
322
  if (!serviceMetadata.has(instance.constructor)) {
285
323
  throw new Error("You must pass a class decorated with @Routes to getServiceRoutes");
286
324
  }
@@ -288,13 +326,14 @@ function getServiceRoutes(target) {
288
326
  if (instanceMetadata._serviceType !== "routes") {
289
327
  throw new Error("You must pass a class decorated with @Routes to getServiceRoutes");
290
328
  }
329
+ initializeRoutesIfNeeded(instance);
291
330
  const routesMap = routeMetadata.get(instance) || {};
292
331
  return routesMap;
293
332
  }
294
333
 
295
334
  // src/index.ts
296
- var { json, raw, text, urlencoded } = import_body_parser2.default;
297
- var bodyParser2 = { json, raw, text, urlencoded };
335
+ var { json, raw, text, urlencoded } = import_body_parser3.default;
336
+ var bodyParser3 = { json, raw, text, urlencoded };
298
337
  // Annotate the CommonJS export names for ESM import in node:
299
338
  0 && (module.exports = {
300
339
  Route,
@@ -307,6 +346,7 @@ var bodyParser2 = { json, raw, text, urlencoded };
307
346
  getServiceRoutes,
308
347
  getViewer,
309
348
  onError,
349
+ registerReplEndpoint,
310
350
  registerRoute,
311
351
  registerRoutes,
312
352
  route,
@@ -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;AAA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AM,gBAAgB,oBAAI,QAAkC;AAErD,SAAS,SAAS;AACvB,SAAO,CAAC,QAAa,YAAwC;AAC3D,iCAAQ,EAAE,QAAQ,OAAO;AAEzB,YAAQ,eAAe,WAAgB;AACrC,sBAAgB,IAAI,MAAM,EAAC,cAAc,SAAQ,CAAC;AAAA,IACpD,CAAC;AAAA,EACH;AACF;AAMO,SAAS,MAAM,SAAkE;AACtF,SAAO,CAAC,QAAa,YAAsE;AACzF,UAAM,cAAc,OAAO,QAAQ,IAAI;AAEvC,YAAQ,eAAe,WAAgB;AACrC,YAAM,SAAS,cAAc,IAAI,IAAI,KAAK,CAAC;AAE3C,UAAI,QAAQ,SAAS,UAAU;AAC7B,eAAO,WAAW,IAAI,YAAY;AAAA,UAChC,GAAG;AAAA,UACH,SAAS,KAAK,WAAW,EAAE,KAAK,IAAI;AAAA,QACtC,CAAC;AAAA,MACH;AAEA,UAAI,QAAQ,SAAS,SAAS;AAC5B,eAAO,WAAW,IAAI,KAAK,WAAW;AAAA,MACxC;AAEA,oBAAc,IAAI,MAAM,MAAM;AAAA,IAChC,CAAC;AAED,WAAO;AAAA,EACT;AACF;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,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/routes/registerRoute.ts","../src/start.ts","../src/repl.ts","../src/routes/executeRequest.ts","../src/viewer.ts","../src/routes/registerRoutes.ts","../src/routes/route.ts","../src/service/index.ts"],"sourcesContent":["import bodyParserLib from 'body-parser'\nimport express, {RequestHandler} from 'express'\nimport {onError, setOnError} from './errors'\nimport registerRoute from './routes/registerRoute'\nimport registerRoutes from './routes/registerRoutes'\nimport {getApp, getServer, startServer} from './start'\nimport {getViewer, setGetViewer} from './viewer'\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 {registerReplEndpoint} from './repl'\nexport * from './service'\nexport * from './types'\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 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 {mkdirSync, writeFileSync} from 'node:fs'\nimport {internalGetEnv} from '@orion-js/env'\nimport express from 'express'\nimport {registerReplEndpoint} from './repl'\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 if (process.env.ORION_REPL) {\n registerReplEndpoint()\n try {\n mkdirSync('.orion', {recursive: true})\n writeFileSync('.orion/port', String(port))\n } catch {}\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 {getInstance} from '@orion-js/services'\nimport bodyParser from 'body-parser'\nimport {getApp} from './start'\n\nexport function registerReplEndpoint() {\n const app = getApp()\n\n app.post('/__repl', bodyParser.json(), async (req, res) => {\n try {\n const {expression} = req.body\n const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor\n const fn = new AsyncFunction('getInstance', expression)\n const result = await fn(getInstance)\n res.json({success: true, result})\n } catch (error) {\n res.json({success: false, error: error.message, stack: error.stack})\n }\n })\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 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 {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;AAAA;AAAA,IAAAC,sBAA0B;AAC1B,IAAAC,kBAAsC;;;ACDtC,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,UAA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,2BAAyB,QAAQ;AAEjC,QAAM,YAAY,cAAc,IAAI,QAAQ,KAAK,CAAC;AAElD,SAAO;AACT;;;AT/DA,IAAM,EAAC,MAAM,KAAK,MAAM,WAAU,IAAI,oBAAAC;AAEtC,IAAMC,cAKF,EAAC,MAAM,KAAK,MAAM,WAAU;","names":["bodyParser","express","import_body_parser","import_express","crypto","import_body_parser","bodyParser","express","import_env","import_helpers","import_logger","route","route","bodyParser","import_services","bodyParserLib","bodyParser"]}
package/dist/index.d.cts CHANGED
@@ -1,22 +1,12 @@
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, SchemaFieldType, InferSchemaType } from '@orion-js/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;
8
8
  declare const setOnError: (onErrorFunc: onErrorFunction) => void;
9
9
 
10
- declare const getViewer: (req: express.Request) => Promise<any>;
11
- declare const setGetViewer: (getViewerFunc: (req: express.Request) => any) => void;
12
-
13
- interface StartOrionOptions {
14
- keepAliveTimeout?: number;
15
- }
16
- declare const startServer: (port?: number, otherOptions?: StartOrionOptions) => express.Express;
17
- declare const getApp: () => express.Express;
18
- declare const getServer: () => any;
19
-
20
10
  interface RouteResponseObject<TReturnsSchema extends SchemaFieldType | undefined = undefined> {
21
11
  statusCode?: number;
22
12
  headers?: {
@@ -92,12 +82,24 @@ declare function registerRoute(route: RouteType): void;
92
82
 
93
83
  declare function registerRoutes(routesMap: RoutesMap): void;
94
84
 
85
+ interface StartOrionOptions {
86
+ keepAliveTimeout?: number;
87
+ }
88
+ declare const startServer: (port?: number, otherOptions?: StartOrionOptions) => express.Express;
89
+ declare const getApp: () => express.Express;
90
+ declare const getServer: () => any;
91
+
92
+ declare const getViewer: (req: express.Request) => Promise<any>;
93
+ declare const setGetViewer: (getViewerFunc: (req: express.Request) => any) => void;
94
+
95
95
  declare function createRoute<TPath extends string, TQueryParamsSchema extends Schema | undefined, TBodyParamsSchema extends Schema | undefined, TReturnsSchema extends SchemaFieldType | undefined>(options: OrionRouteOptions<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema>): RouteType<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema>;
96
96
  /**
97
97
  * @deprecated Use createRoute instead
98
98
  */
99
99
  declare const route: typeof createRoute;
100
100
 
101
+ declare function registerReplEndpoint(): void;
102
+
101
103
  declare function Routes(): (target: any, context: ClassDecoratorContext<any>) => void;
102
104
  declare function Route(): (method: any, context: ClassFieldDecoratorContext) => any;
103
105
  declare function Route(options?: Omit<OrionRouteOptions<any, any, any, any>, 'resolve'>): (method: any, context: ClassMethodDecoratorContext) => any;
@@ -112,4 +114,4 @@ declare const bodyParser: {
112
114
  }) => RequestHandler;
113
115
  };
114
116
 
115
- export { type InferPathParams, type OrionRequest, type OrionRouteOptions, type Request, type Response, Route, type RouteResolve, type RouteResponse, type RouteResponseObject, type RouteType, Routes, type RoutesMap, bodyParser, createRoute, getApp, getServer, getServiceRoutes, getViewer, onError, registerRoute, registerRoutes, route, setGetViewer, setOnError, startServer };
117
+ export { type InferPathParams, type OrionRequest, type OrionRouteOptions, type Request, type Response, Route, type RouteResolve, type RouteResponse, type RouteResponseObject, type RouteType, Routes, type RoutesMap, bodyParser, createRoute, getApp, getServer, getServiceRoutes, getViewer, onError, registerReplEndpoint, registerRoute, registerRoutes, route, setGetViewer, setOnError, startServer };
package/dist/index.d.ts CHANGED
@@ -1,22 +1,12 @@
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, SchemaFieldType, InferSchemaType } from '@orion-js/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;
8
8
  declare const setOnError: (onErrorFunc: onErrorFunction) => void;
9
9
 
10
- declare const getViewer: (req: express.Request) => Promise<any>;
11
- declare const setGetViewer: (getViewerFunc: (req: express.Request) => any) => void;
12
-
13
- interface StartOrionOptions {
14
- keepAliveTimeout?: number;
15
- }
16
- declare const startServer: (port?: number, otherOptions?: StartOrionOptions) => express.Express;
17
- declare const getApp: () => express.Express;
18
- declare const getServer: () => any;
19
-
20
10
  interface RouteResponseObject<TReturnsSchema extends SchemaFieldType | undefined = undefined> {
21
11
  statusCode?: number;
22
12
  headers?: {
@@ -92,12 +82,24 @@ declare function registerRoute(route: RouteType): void;
92
82
 
93
83
  declare function registerRoutes(routesMap: RoutesMap): void;
94
84
 
85
+ interface StartOrionOptions {
86
+ keepAliveTimeout?: number;
87
+ }
88
+ declare const startServer: (port?: number, otherOptions?: StartOrionOptions) => express.Express;
89
+ declare const getApp: () => express.Express;
90
+ declare const getServer: () => any;
91
+
92
+ declare const getViewer: (req: express.Request) => Promise<any>;
93
+ declare const setGetViewer: (getViewerFunc: (req: express.Request) => any) => void;
94
+
95
95
  declare function createRoute<TPath extends string, TQueryParamsSchema extends Schema | undefined, TBodyParamsSchema extends Schema | undefined, TReturnsSchema extends SchemaFieldType | undefined>(options: OrionRouteOptions<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema>): RouteType<TPath, TQueryParamsSchema, TBodyParamsSchema, TReturnsSchema>;
96
96
  /**
97
97
  * @deprecated Use createRoute instead
98
98
  */
99
99
  declare const route: typeof createRoute;
100
100
 
101
+ declare function registerReplEndpoint(): void;
102
+
101
103
  declare function Routes(): (target: any, context: ClassDecoratorContext<any>) => void;
102
104
  declare function Route(): (method: any, context: ClassFieldDecoratorContext) => any;
103
105
  declare function Route(options?: Omit<OrionRouteOptions<any, any, any, any>, 'resolve'>): (method: any, context: ClassMethodDecoratorContext) => any;
@@ -112,4 +114,4 @@ declare const bodyParser: {
112
114
  }) => RequestHandler;
113
115
  };
114
116
 
115
- export { type InferPathParams, type OrionRequest, type OrionRouteOptions, type Request, type Response, Route, type RouteResolve, type RouteResponse, type RouteResponseObject, type RouteType, Routes, type RoutesMap, bodyParser, createRoute, getApp, getServer, getServiceRoutes, getViewer, onError, registerRoute, registerRoutes, route, setGetViewer, setOnError, startServer };
117
+ export { type InferPathParams, type OrionRequest, type OrionRouteOptions, type Request, type Response, Route, type RouteResolve, type RouteResponse, type RouteResponseObject, type RouteType, Routes, type RoutesMap, bodyParser, createRoute, getApp, getServer, getServiceRoutes, getViewer, onError, registerReplEndpoint, registerRoute, registerRoutes, route, setGetViewer, setOnError, startServer };
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ // src/index.ts
2
+ import bodyParserLib from "body-parser";
3
+ import express2 from "express";
4
+
1
5
  // src/errors.ts
2
6
  import crypto from "crypto";
3
7
  import { logger } from "@orion-js/logger";
@@ -34,25 +38,34 @@ var setOnError = (onErrorFunc) => {
34
38
  onErrorRef = onErrorFunc;
35
39
  };
36
40
 
37
- // src/viewer.ts
38
- import { UserError } from "@orion-js/helpers";
39
- global.getViewerRef = () => null;
40
- var getViewer = async (req) => {
41
- try {
42
- const viewer = await global.getViewerRef(req);
43
- if (!viewer) return {};
44
- return viewer;
45
- } catch (err) {
46
- throw new UserError("AuthError", err.message);
47
- }
48
- };
49
- var setGetViewer = (getViewerFunc) => {
50
- global.getViewerRef = getViewerFunc;
51
- };
41
+ // src/routes/registerRoute.ts
42
+ import bodyParser2 from "body-parser";
52
43
 
53
44
  // src/start.ts
45
+ import { mkdirSync, writeFileSync } from "fs";
54
46
  import { internalGetEnv } from "@orion-js/env";
55
47
  import express from "express";
48
+
49
+ // src/repl.ts
50
+ import { getInstance } from "@orion-js/services";
51
+ import bodyParser from "body-parser";
52
+ function registerReplEndpoint() {
53
+ const app = getApp();
54
+ app.post("/__repl", bodyParser.json(), async (req, res) => {
55
+ try {
56
+ const { expression } = req.body;
57
+ const AsyncFunction = Object.getPrototypeOf(async () => {
58
+ }).constructor;
59
+ const fn = new AsyncFunction("getInstance", expression);
60
+ const result = await fn(getInstance);
61
+ res.json({ success: true, result });
62
+ } catch (error) {
63
+ res.json({ success: false, error: error.message, stack: error.stack });
64
+ }
65
+ });
66
+ }
67
+
68
+ // src/start.ts
56
69
  global.appRef = null;
57
70
  global.serverRef = null;
58
71
  var startServer = (port = Number(internalGetEnv("http_port", "PORT")), otherOptions = {}) => {
@@ -63,6 +76,14 @@ var startServer = (port = Number(internalGetEnv("http_port", "PORT")), otherOpti
63
76
  server.keepAliveTimeout = otherOptions.keepAliveTimeout;
64
77
  server.headersTimeout = otherOptions.keepAliveTimeout + 1e3;
65
78
  }
79
+ if (process.env.ORION_REPL) {
80
+ registerReplEndpoint();
81
+ try {
82
+ mkdirSync(".orion", { recursive: true });
83
+ writeFileSync(".orion/port", String(port));
84
+ } catch {
85
+ }
86
+ }
66
87
  return app;
67
88
  };
68
89
  var getApp = () => {
@@ -75,17 +96,29 @@ var getServer = () => {
75
96
  return global.serverRef;
76
97
  };
77
98
 
78
- // src/index.ts
79
- import express2 from "express";
80
-
81
- // src/routes/registerRoute.ts
82
- import bodyParser from "body-parser";
83
-
84
99
  // src/routes/executeRequest.ts
85
100
  import { internalGetEnv as internalGetEnv2 } from "@orion-js/env";
86
101
  import { sleep } from "@orion-js/helpers";
87
102
  import { runWithOrionAsyncContext, updateOrionAsyncContext } from "@orion-js/logger";
88
103
  import { cleanAndValidate } from "@orion-js/schema";
104
+
105
+ // src/viewer.ts
106
+ import { UserError } from "@orion-js/helpers";
107
+ global.getViewerRef = () => null;
108
+ var getViewer = async (req) => {
109
+ try {
110
+ const viewer = await global.getViewerRef(req);
111
+ if (!viewer) return {};
112
+ return viewer;
113
+ } catch (err) {
114
+ throw new UserError("AuthError", err.message);
115
+ }
116
+ };
117
+ var setGetViewer = (getViewerFunc) => {
118
+ global.getViewerRef = getViewerFunc;
119
+ };
120
+
121
+ // src/routes/executeRequest.ts
89
122
  var simulateLatency = internalGetEnv2("simulate_latency", "SIMULATE_LATENCY");
90
123
  var simulateLatencyMs = Number.parseInt(simulateLatency, 10);
91
124
  var hasSimulateLatency = Number.isFinite(simulateLatencyMs) && simulateLatencyMs > 0;
@@ -166,11 +199,11 @@ function registerRoute(route2) {
166
199
  };
167
200
  const handlers = [handler];
168
201
  if (route2.bodyParser) {
169
- const parser = bodyParser[route2.bodyParser](route2.bodyParserOptions);
202
+ const parser = bodyParser2[route2.bodyParser](route2.bodyParserOptions);
170
203
  handlers.unshift(parser);
171
204
  }
172
205
  if (!route2.bodyParser && route2.bodyParams) {
173
- const parser = bodyParser.json(route2.bodyParserOptions);
206
+ const parser = bodyParser2.json(route2.bodyParserOptions);
174
207
  handlers.unshift(parser);
175
208
  }
176
209
  if (route2.middlewares) {
@@ -187,9 +220,6 @@ function registerRoutes(routesMap) {
187
220
  }
188
221
  }
189
222
 
190
- // src/index.ts
191
- import bodyParserLib from "body-parser";
192
-
193
223
  // src/routes/route.ts
194
224
  function createRoute(options) {
195
225
  return {
@@ -199,38 +229,47 @@ function createRoute(options) {
199
229
  var route = createRoute;
200
230
 
201
231
  // src/service/index.ts
202
- import { getInstance, Service } from "@orion-js/services";
232
+ import { getInstance as getInstance2, Service } from "@orion-js/services";
203
233
  var serviceMetadata = /* @__PURE__ */ new WeakMap();
204
234
  var routeMetadata = /* @__PURE__ */ new WeakMap();
235
+ var routeEntriesByClass = /* @__PURE__ */ new Map();
236
+ var pendingRouteEntries = {};
205
237
  function Routes() {
206
238
  return (target, context) => {
207
239
  Service()(target, context);
208
- context.addInitializer(function() {
209
- serviceMetadata.set(this, { _serviceType: "routes" });
210
- });
240
+ serviceMetadata.set(target, { _serviceType: "routes" });
241
+ if (Object.keys(pendingRouteEntries).length > 0) {
242
+ routeEntriesByClass.set(target, pendingRouteEntries);
243
+ pendingRouteEntries = {};
244
+ }
211
245
  };
212
246
  }
213
247
  function Route(options) {
214
248
  return (method, context) => {
215
249
  const propertyKey = String(context.name);
216
- context.addInitializer(function() {
217
- const routes = routeMetadata.get(this) || {};
218
- if (context.kind === "method") {
219
- routes[propertyKey] = createRoute({
220
- ...options,
221
- resolve: this[propertyKey].bind(this)
222
- });
223
- }
224
- if (context.kind === "field") {
225
- routes[propertyKey] = this[propertyKey];
226
- }
227
- routeMetadata.set(this, routes);
228
- });
250
+ if (context.kind === "method") {
251
+ pendingRouteEntries[propertyKey] = (instance) => createRoute({
252
+ ...options,
253
+ resolve: instance[propertyKey].bind(instance)
254
+ });
255
+ }
256
+ if (context.kind === "field") {
257
+ pendingRouteEntries[propertyKey] = (instance) => instance[propertyKey];
258
+ }
229
259
  return method;
230
260
  };
231
261
  }
262
+ function initializeRoutesIfNeeded(instance) {
263
+ if (routeMetadata.has(instance)) return;
264
+ const entries = routeEntriesByClass.get(instance.constructor) || {};
265
+ const routes = {};
266
+ for (const [key, setup] of Object.entries(entries)) {
267
+ routes[key] = setup(instance);
268
+ }
269
+ routeMetadata.set(instance, routes);
270
+ }
232
271
  function getServiceRoutes(target) {
233
- const instance = getInstance(target);
272
+ const instance = getInstance2(target);
234
273
  if (!serviceMetadata.has(instance.constructor)) {
235
274
  throw new Error("You must pass a class decorated with @Routes to getServiceRoutes");
236
275
  }
@@ -238,17 +277,18 @@ function getServiceRoutes(target) {
238
277
  if (instanceMetadata._serviceType !== "routes") {
239
278
  throw new Error("You must pass a class decorated with @Routes to getServiceRoutes");
240
279
  }
280
+ initializeRoutesIfNeeded(instance);
241
281
  const routesMap = routeMetadata.get(instance) || {};
242
282
  return routesMap;
243
283
  }
244
284
 
245
285
  // src/index.ts
246
286
  var { json, raw, text, urlencoded } = bodyParserLib;
247
- var bodyParser2 = { json, raw, text, urlencoded };
287
+ var bodyParser3 = { json, raw, text, urlencoded };
248
288
  export {
249
289
  Route,
250
290
  Routes,
251
- bodyParser2 as bodyParser,
291
+ bodyParser3 as bodyParser,
252
292
  createRoute,
253
293
  express2 as express,
254
294
  getApp,
@@ -256,6 +296,7 @@ export {
256
296
  getServiceRoutes,
257
297
  getViewer,
258
298
  onError,
299
+ registerReplEndpoint,
259
300
  registerRoute,
260
301
  registerRoutes,
261
302
  route,
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;AA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U;AAC7B,eAAO,WAAW,IAAI,YAAY;AAAA,UAChC,GAAG;AAAA,UACH,SAAS,KAAK,WAAW,EAAE,KAAK,IAAI;AAAA,QACtC,CAAC;AAAA,MACH;AAEA,UAAI,QAAQ,SAAS,SAAS;AAC5B,eAAO,WAAW,IAAI,KAAK,WAAW;AAAA,MACxC;AAEA,oBAAc,IAAI,MAAM,MAAM;AAAA,IAChC,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAEO,SAAS,iBAAiB,QAAwB;AACvD,QAAM,WAAW,YAAY,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,QAAM,YAAY,cAAc,IAAI,QAAQ,KAAK,CAAC;AAElD,SAAO;AACT;;;ALnDA,IAAM,EAAC,MAAM,KAAK,MAAM,WAAU,IAAI;AAEtC,IAAMC,cAKF,EAAC,MAAM,KAAK,MAAM,WAAU;","names":["express","internalGetEnv","internalGetEnv","route","route","bodyParser"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/routes/registerRoute.ts","../src/start.ts","../src/repl.ts","../src/routes/executeRequest.ts","../src/viewer.ts","../src/routes/registerRoutes.ts","../src/routes/route.ts","../src/service/index.ts"],"sourcesContent":["import bodyParserLib from 'body-parser'\nimport express, {RequestHandler} from 'express'\nimport {onError, setOnError} from './errors'\nimport registerRoute from './routes/registerRoute'\nimport registerRoutes from './routes/registerRoutes'\nimport {getApp, getServer, startServer} from './start'\nimport {getViewer, setGetViewer} from './viewer'\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 {registerReplEndpoint} from './repl'\nexport * from './service'\nexport * from './types'\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 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 {mkdirSync, writeFileSync} from 'node:fs'\nimport {internalGetEnv} from '@orion-js/env'\nimport express from 'express'\nimport {registerReplEndpoint} from './repl'\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 if (process.env.ORION_REPL) {\n registerReplEndpoint()\n try {\n mkdirSync('.orion', {recursive: true})\n writeFileSync('.orion/port', String(port))\n } catch {}\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 {getInstance} from '@orion-js/services'\nimport bodyParser from 'body-parser'\nimport {getApp} from './start'\n\nexport function registerReplEndpoint() {\n const app = getApp()\n\n app.post('/__repl', bodyParser.json(), async (req, res) => {\n try {\n const {expression} = req.body\n const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor\n const fn = new AsyncFunction('getInstance', expression)\n const result = await fn(getInstance)\n res.json({success: true, result})\n } catch (error) {\n res.json({success: false, error: error.message, stack: error.stack})\n }\n })\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 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 {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,mBAAmB;AAC1B,OAAOA,cAA+B;;;ACDtC,OAAO,YAAY;AACnB,SAAQ,cAAa;AAKrB,IAAM,iBAAkC,OAAO,KAAK,KAAK,UAAU;AACjE,MAAI,MAAM,cAAc;AACtB,QAAI,aAAa;AACjB,QAAI,MAAM,SAAS,aAAa;AA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;AAAA,EACT;AACF;AAEA,SAAS,yBAAyB,UAAe;AAC/C,MAAI,cAAc,IAAI,QAAQ,EAAG;AACjC,QAAM,UAAU,oBAAoB,IAAI,SAAS,WAAW,KAAK,CAAC;AAClE,QAAM,SAA8B,CAAC;AACrC,aAAW,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,WAAWC,aAAY,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;;;AT/DA,IAAM,EAAC,MAAM,KAAK,MAAM,WAAU,IAAI;AAEtC,IAAMC,cAKF,EAAC,MAAM,KAAK,MAAM,WAAU;","names":["express","bodyParser","internalGetEnv","internalGetEnv","route","route","bodyParser","getInstance","getInstance","bodyParser"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/http",
3
- "version": "4.2.4",
3
+ "version": "4.3.1",
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.2",
15
- "@orion-js/helpers": "4.2.0",
16
- "@orion-js/schema": "4.2.1",
17
- "@orion-js/services": "4.2.0",
18
- "@orion-js/resolvers": "4.2.1"
25
+ "express": "4.21.2"
19
26
  },
20
27
  "peerDependencies": {
21
- "@orion-js/logger": "4.2.0"
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.