@mondaydotcomorg/atp-server 0.17.14 → 0.18.2
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/aggregator/index.d.ts +11 -1
- package/dist/aggregator/index.d.ts.map +1 -1
- package/dist/aggregator/index.js +4 -3
- package/dist/aggregator/index.js.map +1 -1
- package/dist/client-sessions.d.ts +5 -1
- package/dist/client-sessions.d.ts.map +1 -1
- package/dist/client-sessions.js +1 -0
- package/dist/client-sessions.js.map +1 -1
- package/dist/create-server.d.ts +1 -0
- package/dist/create-server.d.ts.map +1 -1
- package/dist/create-server.js +25 -0
- package/dist/create-server.js.map +1 -1
- package/dist/executor/error-handler.d.ts.map +1 -1
- package/dist/executor/error-handler.js +8 -0
- package/dist/executor/error-handler.js.map +1 -1
- package/dist/executor/execution-error-handler.d.ts.map +1 -1
- package/dist/executor/execution-error-handler.js +1 -1
- package/dist/executor/execution-error-handler.js.map +1 -1
- package/dist/executor/executor.d.ts +1 -1
- package/dist/executor/executor.d.ts.map +1 -1
- package/dist/executor/executor.js +14 -9
- package/dist/executor/executor.js.map +1 -1
- package/dist/http/request-handler.d.ts.map +1 -1
- package/dist/http/request-handler.js +3 -2
- package/dist/http/request-handler.js.map +1 -1
- package/dist/http/router.d.ts.map +1 -1
- package/dist/http/router.js +3 -0
- package/dist/http/router.js.map +1 -1
- package/dist/instrumentation/state-manager.d.ts.map +1 -1
- package/dist/instrumentation/state-manager.js +3 -1
- package/dist/instrumentation/state-manager.js.map +1 -1
- package/dist/instrumentation/transformer.d.ts.map +1 -1
- package/dist/instrumentation/transformer.js +23 -8
- package/dist/instrumentation/transformer.js.map +1 -1
- package/dist/openapi-loader.d.ts.map +1 -1
- package/dist/openapi-loader.js.map +1 -1
- package/dist/utils/context.d.ts.map +1 -1
- package/dist/utils/context.js +5 -2
- package/dist/utils/context.js.map +1 -1
- package/package.json +22 -10
- package/src/aggregator/index.ts +13 -3
- package/src/client-sessions.ts +10 -1
- package/src/create-server.ts +32 -0
- package/src/executor/error-handler.ts +10 -0
- package/src/executor/execution-error-handler.ts +1 -4
- package/src/executor/executor.ts +29 -24
- package/src/http/request-handler.ts +3 -2
- package/src/http/router.ts +2 -0
- package/src/instrumentation/state-manager.ts +3 -1
- package/src/instrumentation/transformer.ts +31 -12
- package/src/openapi-loader.ts +2 -3
- package/src/utils/context.ts +6 -2
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
* Code Instrumentation Engine
|
|
3
3
|
*/
|
|
4
4
|
import { parse } from '@babel/parser';
|
|
5
|
-
import
|
|
6
|
-
|
|
5
|
+
import _traverse from '@babel/traverse';
|
|
6
|
+
// @ts-ignore - CommonJS/ESM compatibility
|
|
7
|
+
const traverse =
|
|
8
|
+
typeof (_traverse as any).default === 'function' ? (_traverse as any).default : _traverse;
|
|
9
|
+
import _generate from '@babel/generator';
|
|
10
|
+
// @ts-ignore - CommonJS/ESM compatibility
|
|
11
|
+
const generate = (_generate as any).default || _generate;
|
|
7
12
|
import * as t from '@babel/types';
|
|
8
13
|
import type { InstrumentedCode, InstrumentationMetadata } from './types.js';
|
|
9
14
|
|
|
@@ -16,12 +21,26 @@ export class CodeInstrumentor {
|
|
|
16
21
|
instrument(code: string): InstrumentedCode {
|
|
17
22
|
this.statementId = 0;
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
let ast;
|
|
25
|
+
try {
|
|
26
|
+
ast = parse(code, {
|
|
27
|
+
sourceType: 'module',
|
|
28
|
+
plugins: ['typescript'],
|
|
29
|
+
allowAwaitOutsideFunction: true,
|
|
30
|
+
allowReturnOutsideFunction: true,
|
|
31
|
+
});
|
|
32
|
+
} catch (parseError) {
|
|
33
|
+
const error = parseError as Error;
|
|
34
|
+
const positionMatch = error.message.match(/\((\d+):(\d+)\)/);
|
|
35
|
+
const position =
|
|
36
|
+
positionMatch && positionMatch[1] && positionMatch[2]
|
|
37
|
+
? { line: parseInt(positionMatch[1], 10), column: parseInt(positionMatch[2], 10) }
|
|
38
|
+
: null;
|
|
39
|
+
|
|
40
|
+
throw new SyntaxError(
|
|
41
|
+
`Failed to parse code for instrumentation: ${error.message}${position ? ` at line ${position.line}, column ${position.column}` : ''}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
25
44
|
|
|
26
45
|
const metadata: InstrumentationMetadata = {
|
|
27
46
|
statements: [],
|
|
@@ -30,15 +49,15 @@ export class CodeInstrumentor {
|
|
|
30
49
|
};
|
|
31
50
|
|
|
32
51
|
traverse(ast, {
|
|
33
|
-
VariableDeclaration: (path) => {
|
|
34
|
-
path.node.declarations.forEach((decl) => {
|
|
52
|
+
VariableDeclaration: (path: any) => {
|
|
53
|
+
path.node.declarations.forEach((decl: any) => {
|
|
35
54
|
if (t.isIdentifier(decl.id)) {
|
|
36
55
|
metadata.variables.add(decl.id.name);
|
|
37
56
|
}
|
|
38
57
|
});
|
|
39
58
|
},
|
|
40
59
|
|
|
41
|
-
FunctionDeclaration: (path) => {
|
|
60
|
+
FunctionDeclaration: (path: any) => {
|
|
42
61
|
if (path.node.id) {
|
|
43
62
|
metadata.functions.push({
|
|
44
63
|
name: path.node.id.name,
|
|
@@ -47,7 +66,7 @@ export class CodeInstrumentor {
|
|
|
47
66
|
}
|
|
48
67
|
},
|
|
49
68
|
|
|
50
|
-
Statement: (path) => {
|
|
69
|
+
Statement: (path: any) => {
|
|
51
70
|
if (
|
|
52
71
|
t.isFunctionDeclaration(path.node) ||
|
|
53
72
|
t.isClassDeclaration(path.node) ||
|
package/src/openapi-loader.ts
CHANGED
|
@@ -180,8 +180,7 @@ export async function loadOpenAPI(
|
|
|
180
180
|
if (!baseURL) {
|
|
181
181
|
if (isOpenAPI3(spec) && spec.servers && spec.servers[0]) {
|
|
182
182
|
baseURL = spec.servers[0].url;
|
|
183
|
-
}
|
|
184
|
-
else if (isSwagger2(spec) && spec.host) {
|
|
183
|
+
} else if (isSwagger2(spec) && spec.host) {
|
|
185
184
|
const scheme = spec.schemes?.[0] || 'https';
|
|
186
185
|
const host = spec.host;
|
|
187
186
|
const basePath = spec.basePath || '';
|
|
@@ -462,7 +461,7 @@ function convertOperation(
|
|
|
462
461
|
const basePath = baseUrlObj.pathname.replace(/\/$/, '');
|
|
463
462
|
const fullPath = basePath + requestPath;
|
|
464
463
|
const url = new URL(fullPath, baseUrlObj.origin);
|
|
465
|
-
|
|
464
|
+
|
|
466
465
|
for (const [key, value] of Object.entries(queryParams)) {
|
|
467
466
|
url.searchParams.append(key, value);
|
|
468
467
|
}
|
package/src/utils/context.ts
CHANGED
|
@@ -22,10 +22,14 @@ export function createContext(options: CreateContextOptions): RequestContext {
|
|
|
22
22
|
const clientId = (req.headers['x-client-id'] as string) || undefined;
|
|
23
23
|
const userId = (req.headers['x-user-id'] as string) || undefined;
|
|
24
24
|
|
|
25
|
+
const url = req.url || '/';
|
|
26
|
+
const queryIndex = url.indexOf('?');
|
|
27
|
+
const path = queryIndex === -1 ? url : url.substring(0, queryIndex);
|
|
28
|
+
|
|
25
29
|
return {
|
|
26
30
|
method: req.method || 'GET',
|
|
27
|
-
path
|
|
28
|
-
query: parseQuery(
|
|
31
|
+
path,
|
|
32
|
+
query: parseQuery(url),
|
|
29
33
|
headers: req.headers as Record<string, string>,
|
|
30
34
|
body: null,
|
|
31
35
|
status: 200,
|