@orion-js/http 4.3.0 → 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 +62 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -11
- package/dist/index.d.ts +13 -11
- package/dist/index.js +61 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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: () =>
|
|
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/
|
|
88
|
-
var
|
|
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 =
|
|
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 =
|
|
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,14 +278,14 @@ function createRoute(options) {
|
|
|
249
278
|
var route = createRoute;
|
|
250
279
|
|
|
251
280
|
// src/service/index.ts
|
|
252
|
-
var
|
|
281
|
+
var import_services2 = require("@orion-js/services");
|
|
253
282
|
var serviceMetadata = /* @__PURE__ */ new WeakMap();
|
|
254
283
|
var routeMetadata = /* @__PURE__ */ new WeakMap();
|
|
255
284
|
var routeEntriesByClass = /* @__PURE__ */ new Map();
|
|
256
285
|
var pendingRouteEntries = {};
|
|
257
286
|
function Routes() {
|
|
258
287
|
return (target, context) => {
|
|
259
|
-
(0,
|
|
288
|
+
(0, import_services2.Service)()(target, context);
|
|
260
289
|
serviceMetadata.set(target, { _serviceType: "routes" });
|
|
261
290
|
if (Object.keys(pendingRouteEntries).length > 0) {
|
|
262
291
|
routeEntriesByClass.set(target, pendingRouteEntries);
|
|
@@ -289,7 +318,7 @@ function initializeRoutesIfNeeded(instance) {
|
|
|
289
318
|
routeMetadata.set(instance, routes);
|
|
290
319
|
}
|
|
291
320
|
function getServiceRoutes(target) {
|
|
292
|
-
const instance = (0,
|
|
321
|
+
const instance = (0, import_services2.getInstance)(target);
|
|
293
322
|
if (!serviceMetadata.has(instance.constructor)) {
|
|
294
323
|
throw new Error("You must pass a class decorated with @Routes to getServiceRoutes");
|
|
295
324
|
}
|
|
@@ -303,8 +332,8 @@ function getServiceRoutes(target) {
|
|
|
303
332
|
}
|
|
304
333
|
|
|
305
334
|
// src/index.ts
|
|
306
|
-
var { json, raw, text, urlencoded } =
|
|
307
|
-
var
|
|
335
|
+
var { json, raw, text, urlencoded } = import_body_parser3.default;
|
|
336
|
+
var bodyParser3 = { json, raw, text, urlencoded };
|
|
308
337
|
// Annotate the CommonJS export names for ESM import in node:
|
|
309
338
|
0 && (module.exports = {
|
|
310
339
|
Route,
|
|
@@ -317,6 +346,7 @@ var bodyParser2 = { json, raw, text, urlencoded };
|
|
|
317
346
|
getServiceRoutes,
|
|
318
347
|
getViewer,
|
|
319
348
|
onError,
|
|
349
|
+
registerReplEndpoint,
|
|
320
350
|
registerRoute,
|
|
321
351
|
registerRoutes,
|
|
322
352
|
route,
|
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>>()\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;A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c,OAAO,QAAQ,IAAI;AAEvC,QAAI,QAAQ,SAAS,UAAU;AAC7B,0BAAoB,WAAW,IAAI,CAAC,aAClC,YAAY;AAAA,QACV,GAAG;AAAA,QACH,SAAS,SAAS,WAAW,EAAE,KAAK,QAAQ;AAAA,MAC9C,CAAC;AAAA,IACL;AAEA,QAAI,QAAQ,SAAS,SAAS;AAC5B,0BAAoB,WAAW,IAAI,CAAC,aAAkB,SAAS,WAAW;AAAA,IAC5E;AAEA,WAAO;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,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"]}
|
|
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,UAAU;AACrB,QAAI,KAAK,IAAI;AAEb,UAAM,OAAO;AACb,yBAAO,MAAM,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AAC;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
|
@@ -7,16 +7,6 @@ type onErrorFunction = (req: express.Request, res: express.Response, error: any)
|
|
|
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
|
@@ -7,16 +7,6 @@ type onErrorFunction = (req: express.Request, res: express.Response, error: any)
|
|
|
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/
|
|
38
|
-
import
|
|
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 =
|
|
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 =
|
|
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,7 +229,7 @@ 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();
|
|
205
235
|
var routeEntriesByClass = /* @__PURE__ */ new Map();
|
|
@@ -239,7 +269,7 @@ function initializeRoutesIfNeeded(instance) {
|
|
|
239
269
|
routeMetadata.set(instance, routes);
|
|
240
270
|
}
|
|
241
271
|
function getServiceRoutes(target) {
|
|
242
|
-
const instance =
|
|
272
|
+
const instance = getInstance2(target);
|
|
243
273
|
if (!serviceMetadata.has(instance.constructor)) {
|
|
244
274
|
throw new Error("You must pass a class decorated with @Routes to getServiceRoutes");
|
|
245
275
|
}
|
|
@@ -254,11 +284,11 @@ function getServiceRoutes(target) {
|
|
|
254
284
|
|
|
255
285
|
// src/index.ts
|
|
256
286
|
var { json, raw, text, urlencoded } = bodyParserLib;
|
|
257
|
-
var
|
|
287
|
+
var bodyParser3 = { json, raw, text, urlencoded };
|
|
258
288
|
export {
|
|
259
289
|
Route,
|
|
260
290
|
Routes,
|
|
261
|
-
|
|
291
|
+
bodyParser3 as bodyParser,
|
|
262
292
|
createRoute,
|
|
263
293
|
express2 as express,
|
|
264
294
|
getApp,
|
|
@@ -266,6 +296,7 @@ export {
|
|
|
266
296
|
getServiceRoutes,
|
|
267
297
|
getViewer,
|
|
268
298
|
onError,
|
|
299
|
+
registerReplEndpoint,
|
|
269
300
|
registerRoute,
|
|
270
301
|
registerRoutes,
|
|
271
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>>()\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,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,QAAu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AAgB,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;;;AL9DA,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;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,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