@mondaydotcomorg/atp-compiler 0.17.16 → 0.18.4-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/unit/default-compiler.test.ts +259 -0
- package/__tests__/unit/plugin-system.test.ts +401 -0
- package/dist/atp-compiler/src/index.d.ts +8 -0
- package/dist/atp-compiler/src/index.d.ts.map +1 -1
- package/dist/atp-compiler/src/index.js +9 -0
- package/dist/atp-compiler/src/index.js.map +1 -1
- package/dist/atp-compiler/src/plugin-system/create-default-compiler.d.ts +40 -0
- package/dist/atp-compiler/src/plugin-system/create-default-compiler.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/create-default-compiler.js +40 -0
- package/dist/atp-compiler/src/plugin-system/create-default-compiler.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/array-transformer-plugin.d.ts +18 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/array-transformer-plugin.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/array-transformer-plugin.js +45 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/array-transformer-plugin.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/detection-plugin.d.ts +17 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/detection-plugin.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/detection-plugin.js +33 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/detection-plugin.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/index.d.ts +11 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/index.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/index.js +11 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/index.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/loop-transformer-plugin.d.ts +17 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/loop-transformer-plugin.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/loop-transformer-plugin.js +36 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/loop-transformer-plugin.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/promise-transformer-plugin.d.ts +19 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/promise-transformer-plugin.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/promise-transformer-plugin.js +49 -0
- package/dist/atp-compiler/src/plugin-system/default-plugins/promise-transformer-plugin.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/examples/loop-transformer-plugin.d.ts +31 -0
- package/dist/atp-compiler/src/plugin-system/examples/loop-transformer-plugin.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/examples/loop-transformer-plugin.js +60 -0
- package/dist/atp-compiler/src/plugin-system/examples/loop-transformer-plugin.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/examples/security-validator-plugin.d.ts +48 -0
- package/dist/atp-compiler/src/plugin-system/examples/security-validator-plugin.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/examples/security-validator-plugin.js +108 -0
- package/dist/atp-compiler/src/plugin-system/examples/security-validator-plugin.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/examples/timeout-plugin.d.ts +53 -0
- package/dist/atp-compiler/src/plugin-system/examples/timeout-plugin.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/examples/timeout-plugin.js +106 -0
- package/dist/atp-compiler/src/plugin-system/examples/timeout-plugin.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/index.d.ts +14 -0
- package/dist/atp-compiler/src/plugin-system/index.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/index.js +16 -0
- package/dist/atp-compiler/src/plugin-system/index.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/pluggable-compiler.d.ts +102 -0
- package/dist/atp-compiler/src/plugin-system/pluggable-compiler.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/pluggable-compiler.js +280 -0
- package/dist/atp-compiler/src/plugin-system/pluggable-compiler.js.map +1 -0
- package/dist/atp-compiler/src/plugin-system/plugin-api.d.ts +165 -0
- package/dist/atp-compiler/src/plugin-system/plugin-api.d.ts.map +1 -0
- package/dist/atp-compiler/src/plugin-system/plugin-api.js +180 -0
- package/dist/atp-compiler/src/plugin-system/plugin-api.js.map +1 -0
- package/dist/atp-compiler/src/transformer/array-transformer-utils.d.ts +2 -2
- package/dist/atp-compiler/src/transformer/array-transformer-utils.d.ts.map +1 -1
- package/dist/atp-compiler/src/transformer/array-transformer-utils.js +2 -2
- package/dist/atp-compiler/src/transformer/array-transformer-utils.js.map +1 -1
- package/dist/atp-compiler/src/transformer/index.d.ts +15 -1
- package/dist/atp-compiler/src/transformer/index.d.ts.map +1 -1
- package/dist/atp-compiler/src/transformer/index.js +17 -0
- package/dist/atp-compiler/src/transformer/index.js.map +1 -1
- package/dist/atp-compiler/src/transformer/loop-transformer.d.ts +0 -4
- package/dist/atp-compiler/src/transformer/loop-transformer.d.ts.map +1 -1
- package/dist/atp-compiler/src/transformer/loop-transformer.js +5 -60
- package/dist/atp-compiler/src/transformer/loop-transformer.js.map +1 -1
- package/dist/atp-compiler/src/transformer/utils.d.ts +4 -0
- package/dist/atp-compiler/src/transformer/utils.d.ts.map +1 -1
- package/dist/atp-compiler/src/transformer/utils.js +15 -0
- package/dist/atp-compiler/src/transformer/utils.js.map +1 -1
- package/dist/atp-compiler/src/types/compiler-interface.d.ts +61 -0
- package/dist/atp-compiler/src/types/compiler-interface.d.ts.map +1 -0
- package/dist/atp-compiler/src/types/compiler-interface.js +18 -0
- package/dist/atp-compiler/src/types/compiler-interface.js.map +1 -0
- package/dist/runtime/src/approval/index.js +2 -1
- package/dist/runtime/src/approval/index.js.map +1 -1
- package/dist/runtime/src/index.d.ts +1 -1
- package/dist/runtime/src/index.d.ts.map +1 -1
- package/dist/runtime/src/index.js +1 -1
- package/dist/runtime/src/index.js.map +1 -1
- package/dist/runtime/src/llm/index.d.ts +1 -1
- package/dist/runtime/src/llm/index.d.ts.map +1 -1
- package/dist/runtime/src/llm/index.js +1 -1
- package/dist/runtime/src/llm/index.js.map +1 -1
- package/dist/runtime/src/llm/replay.d.ts +75 -0
- package/dist/runtime/src/llm/replay.d.ts.map +1 -1
- package/dist/runtime/src/llm/replay.js +187 -5
- package/dist/runtime/src/llm/replay.js.map +1 -1
- package/dist/runtime/src/metadata/generated.d.ts.map +1 -1
- package/dist/runtime/src/metadata/generated.js +189 -189
- package/dist/runtime/src/metadata/generated.js.map +1 -1
- package/dist/runtime/src/metadata/index.js +2 -2
- package/dist/runtime/src/metadata/index.js.map +1 -1
- package/dist/runtime/src/metadata/types.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +14 -5
- package/project.json +1 -3
- package/src/index.ts +26 -0
- package/src/plugin-system/create-default-compiler.ts +57 -0
- package/src/plugin-system/default-plugins/array-transformer-plugin.ts +57 -0
- package/src/plugin-system/default-plugins/detection-plugin.ts +41 -0
- package/src/plugin-system/default-plugins/index.ts +12 -0
- package/src/plugin-system/default-plugins/loop-transformer-plugin.ts +47 -0
- package/src/plugin-system/default-plugins/promise-transformer-plugin.ts +63 -0
- package/src/plugin-system/examples/loop-transformer-plugin.ts +76 -0
- package/src/plugin-system/examples/security-validator-plugin.ts +168 -0
- package/src/plugin-system/examples/timeout-plugin.ts +158 -0
- package/src/plugin-system/index.ts +19 -0
- package/src/plugin-system/pluggable-compiler.ts +318 -0
- package/src/plugin-system/plugin-api.ts +330 -0
- package/src/transformer/array-transformer-utils.ts +3 -7
- package/src/transformer/index.ts +21 -1
- package/src/transformer/loop-transformer.ts +5 -66
- package/src/transformer/utils.ts +14 -0
- package/src/types/compiler-interface.ts +79 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example Plugin: Security Validator
|
|
3
|
+
*
|
|
4
|
+
* Validates code for security issues before transformation
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const compiler = new PluggableCompiler();
|
|
8
|
+
* compiler.use(new SecurityValidatorPlugin({
|
|
9
|
+
* forbiddenPatterns: [/eval\s*\(/],
|
|
10
|
+
* maxComplexity: 20
|
|
11
|
+
* }));
|
|
12
|
+
*/
|
|
13
|
+
import _traverse from '@babel/traverse';
|
|
14
|
+
const traverse = _traverse.default || _traverse;
|
|
15
|
+
export class SecurityValidatorPlugin {
|
|
16
|
+
name = 'security-validator';
|
|
17
|
+
version = '1.0.0';
|
|
18
|
+
priority = 100; // Run first
|
|
19
|
+
options;
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.options = {
|
|
22
|
+
forbiddenPatterns: options.forbiddenPatterns || [
|
|
23
|
+
/\beval\s*\(/,
|
|
24
|
+
/new\s+Function\s*\(/,
|
|
25
|
+
/constructor\s*\[\s*['"`]constructor['"`]\s*\]/,
|
|
26
|
+
],
|
|
27
|
+
maxComplexity: options.maxComplexity || 50,
|
|
28
|
+
maxNesting: options.maxNesting || 10,
|
|
29
|
+
forbiddenGlobals: options.forbiddenGlobals || [
|
|
30
|
+
'process',
|
|
31
|
+
'require',
|
|
32
|
+
'__dirname',
|
|
33
|
+
'__filename',
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async validate(code, ast, phase) {
|
|
38
|
+
// Only validate before transformation
|
|
39
|
+
if (phase === 'post') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// 1. Check forbidden patterns
|
|
43
|
+
for (const pattern of this.options.forbiddenPatterns) {
|
|
44
|
+
if (pattern.test(code)) {
|
|
45
|
+
throw new SecurityValidationError(`Forbidden pattern detected: ${pattern}`, 'forbidden-pattern');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// 2. Check complexity and nesting
|
|
49
|
+
let maxNestingFound = 0;
|
|
50
|
+
let complexityScore = 0;
|
|
51
|
+
traverse(ast, {
|
|
52
|
+
enter(path) {
|
|
53
|
+
const depth = path.scope.path.node ? getDepth(path) : 0;
|
|
54
|
+
maxNestingFound = Math.max(maxNestingFound, depth);
|
|
55
|
+
// Increment complexity for control flow
|
|
56
|
+
if (path.isIfStatement() ||
|
|
57
|
+
path.isWhileStatement() ||
|
|
58
|
+
path.isForStatement() ||
|
|
59
|
+
path.isForOfStatement() ||
|
|
60
|
+
path.isSwitchCase() ||
|
|
61
|
+
path.isCatchClause()) {
|
|
62
|
+
complexityScore++;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
// 3. Check forbidden globals
|
|
66
|
+
Identifier: (path) => {
|
|
67
|
+
if (this.options.forbiddenGlobals.includes(path.node.name) &&
|
|
68
|
+
!path.scope.hasBinding(path.node.name)) {
|
|
69
|
+
throw new SecurityValidationError(`Access to forbidden global: ${path.node.name}`, 'forbidden-global');
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
if (maxNestingFound > this.options.maxNesting) {
|
|
74
|
+
throw new SecurityValidationError(`Maximum nesting depth exceeded: ${maxNestingFound} > ${this.options.maxNesting}`, 'max-nesting');
|
|
75
|
+
}
|
|
76
|
+
if (complexityScore > this.options.maxComplexity) {
|
|
77
|
+
throw new SecurityValidationError(`Maximum complexity exceeded: ${complexityScore} > ${this.options.maxComplexity}`, 'max-complexity');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Security validation error
|
|
83
|
+
*/
|
|
84
|
+
export class SecurityValidationError extends Error {
|
|
85
|
+
code;
|
|
86
|
+
constructor(message, code) {
|
|
87
|
+
super(message);
|
|
88
|
+
this.code = code;
|
|
89
|
+
this.name = 'SecurityValidationError';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get nesting depth of a path
|
|
94
|
+
*/
|
|
95
|
+
function getDepth(path) {
|
|
96
|
+
let depth = 0;
|
|
97
|
+
let current = path;
|
|
98
|
+
while (current.parentPath) {
|
|
99
|
+
if (current.isBlockStatement() ||
|
|
100
|
+
current.isFunctionDeclaration() ||
|
|
101
|
+
current.isArrowFunctionExpression()) {
|
|
102
|
+
depth++;
|
|
103
|
+
}
|
|
104
|
+
current = current.parentPath;
|
|
105
|
+
}
|
|
106
|
+
return depth;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=security-validator-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-validator-plugin.js","sourceRoot":"","sources":["../../../../../src/plugin-system/examples/security-validator-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,MAAM,QAAQ,GAAI,SAAiB,CAAC,OAAO,IAAI,SAAS,CAAC;AA0BzD,MAAM,OAAO,uBAAuB;IACnC,IAAI,GAAG,oBAAoB,CAAC;IAC5B,OAAO,GAAG,OAAO,CAAC;IAClB,QAAQ,GAAG,GAAG,CAAC,CAAC,YAAY;IAEpB,OAAO,CAA2B;IAE1C,YAAY,UAAoC,EAAE;QACjD,IAAI,CAAC,OAAO,GAAG;YACd,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI;gBAC/C,aAAa;gBACb,qBAAqB;gBACrB,+CAA+C;aAC/C;YACD,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,EAAE;YAC1C,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE;YACpC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI;gBAC7C,SAAS;gBACT,SAAS;gBACT,WAAW;gBACX,YAAY;aACZ;SACD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAY,EAAE,GAAW,EAAE,KAAqB;QAC9D,sCAAsC;QACtC,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;YACtB,OAAO;QACR,CAAC;QAED,8BAA8B;QAC9B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,OAA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e,GAAG,IAAI,CAAC,OAAO,CAAC,UAAW,EAAE,CAAC;YAChD,MAAM,IAAI,uBAAuB,CAChC,mCAAmC,eAAe,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EACjF,aAAa,CACb,CAAC;QACH,CAAC;QAED,IAAI,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,aAAc,EAAE,CAAC;YACnD,MAAM,IAAI,uBAAuB,CAChC,gCAAgC,eAAe,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,EACjF,gBAAgB,CAChB,CAAC;QACH,CAAC;IACF,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAGzC;IAFR,YACC,OAAe,EACR,IAAY;QAEnB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFR,SAAI,GAAJ,IAAI,CAAQ;QAGnB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD;AAED;;GAEG;AACH,SAAS,QAAQ,CAAC,IAAS;IAC1B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,OAAO,GAAG,IAAI,CAAC;IAEnB,OAAO,OAAO,CAAC,UAAU,EAAE,CAAC;QAC3B,IACC,OAAO,CAAC,gBAAgB,EAAE;YAC1B,OAAO,CAAC,qBAAqB,EAAE;YAC/B,OAAO,CAAC,yBAAyB,EAAE,EAClC,CAAC;YACF,KAAK,EAAE,CAAC;QACT,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IAC9B,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example Plugin: Async Timeout Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Automatically wraps await expressions with timeout protection
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Before:
|
|
8
|
+
* const result = await fetch('https://api.example.com');
|
|
9
|
+
*
|
|
10
|
+
* // After:
|
|
11
|
+
* const result = await Promise.race([
|
|
12
|
+
* fetch('https://api.example.com'),
|
|
13
|
+
* new Promise((_, reject) =>
|
|
14
|
+
* setTimeout(() => reject(new Error('Timeout')), 5000)
|
|
15
|
+
* )
|
|
16
|
+
* ]);
|
|
17
|
+
*/
|
|
18
|
+
import type { TransformationPlugin, BabelVisitor } from '../plugin-api.js';
|
|
19
|
+
import type { CompilerConfig, TransformMetadata } from '../../types.js';
|
|
20
|
+
export interface TimeoutPluginOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Default timeout in milliseconds
|
|
23
|
+
*/
|
|
24
|
+
timeout?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Patterns to match (namespace.method)
|
|
27
|
+
*/
|
|
28
|
+
patterns?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Whether to add timeout to all await expressions
|
|
31
|
+
*/
|
|
32
|
+
wrapAll?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare class AsyncTimeoutPlugin implements TransformationPlugin {
|
|
35
|
+
name: string;
|
|
36
|
+
version: string;
|
|
37
|
+
priority: number;
|
|
38
|
+
private options;
|
|
39
|
+
private transformCount;
|
|
40
|
+
constructor(options?: TimeoutPluginOptions);
|
|
41
|
+
getVisitor(config: CompilerConfig): BabelVisitor;
|
|
42
|
+
getMetadata(): Partial<TransformMetadata>;
|
|
43
|
+
reset(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Check if this await should be wrapped with timeout
|
|
46
|
+
*/
|
|
47
|
+
private shouldWrap;
|
|
48
|
+
/**
|
|
49
|
+
* Get function name from call expression
|
|
50
|
+
*/
|
|
51
|
+
private getFunctionName;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=timeout-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout-plugin.d.ts","sourceRoot":"","sources":["../../../../../src/plugin-system/examples/timeout-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExE,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,qBAAa,kBAAmB,YAAW,oBAAoB;IAC9D,IAAI,SAAmB;IACvB,OAAO,SAAW;IAClB,QAAQ,SAAM;IAEd,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,cAAc,CAAK;gBAEf,OAAO,GAAE,oBAAyB;IAQ9C,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY;IAgDhD,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAUzC,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,OAAO,CAAC,UAAU;IAmBlB;;OAEG;IACH,OAAO,CAAC,eAAe;CAavB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example Plugin: Async Timeout Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Automatically wraps await expressions with timeout protection
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Before:
|
|
8
|
+
* const result = await fetch('https://api.example.com');
|
|
9
|
+
*
|
|
10
|
+
* // After:
|
|
11
|
+
* const result = await Promise.race([
|
|
12
|
+
* fetch('https://api.example.com'),
|
|
13
|
+
* new Promise((_, reject) =>
|
|
14
|
+
* setTimeout(() => reject(new Error('Timeout')), 5000)
|
|
15
|
+
* )
|
|
16
|
+
* ]);
|
|
17
|
+
*/
|
|
18
|
+
import * as t from '@babel/types';
|
|
19
|
+
export class AsyncTimeoutPlugin {
|
|
20
|
+
name = 'async-timeout';
|
|
21
|
+
version = '1.0.0';
|
|
22
|
+
priority = 40; // Run after main transformations
|
|
23
|
+
options;
|
|
24
|
+
transformCount = 0;
|
|
25
|
+
constructor(options = {}) {
|
|
26
|
+
this.options = {
|
|
27
|
+
timeout: options.timeout || 5000,
|
|
28
|
+
patterns: options.patterns || ['fetch', 'axios.*', 'http.*'],
|
|
29
|
+
wrapAll: options.wrapAll || false,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
getVisitor(config) {
|
|
33
|
+
return {
|
|
34
|
+
AwaitExpression: (path) => {
|
|
35
|
+
// Check if should wrap this await
|
|
36
|
+
if (!this.shouldWrap(path.node.argument)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Create timeout promise
|
|
40
|
+
const timeoutPromise = t.newExpression(t.identifier('Promise'), [
|
|
41
|
+
t.arrowFunctionExpression([t.identifier('_'), t.identifier('reject')], t.blockStatement([
|
|
42
|
+
t.expressionStatement(t.callExpression(t.identifier('setTimeout'), [
|
|
43
|
+
t.arrowFunctionExpression([], t.callExpression(t.identifier('reject'), [
|
|
44
|
+
t.newExpression(t.identifier('Error'), [
|
|
45
|
+
t.stringLiteral(`Timeout after ${this.options.timeout}ms`),
|
|
46
|
+
]),
|
|
47
|
+
])),
|
|
48
|
+
t.numericLiteral(this.options.timeout),
|
|
49
|
+
])),
|
|
50
|
+
])),
|
|
51
|
+
]);
|
|
52
|
+
// Wrap in Promise.race
|
|
53
|
+
const raceCall = t.callExpression(t.memberExpression(t.identifier('Promise'), t.identifier('race')), [t.arrayExpression([path.node.argument, timeoutPromise])]);
|
|
54
|
+
// Replace await expression
|
|
55
|
+
path.node.argument = raceCall;
|
|
56
|
+
this.transformCount++;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
getMetadata() {
|
|
61
|
+
return {
|
|
62
|
+
// Custom metadata
|
|
63
|
+
loopCount: 0,
|
|
64
|
+
arrayMethodCount: 0,
|
|
65
|
+
parallelCallCount: this.transformCount,
|
|
66
|
+
batchableCount: 0,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
reset() {
|
|
70
|
+
this.transformCount = 0;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Check if this await should be wrapped with timeout
|
|
74
|
+
*/
|
|
75
|
+
shouldWrap(node) {
|
|
76
|
+
if (this.options.wrapAll) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
// Check if matches patterns
|
|
80
|
+
if (t.isCallExpression(node)) {
|
|
81
|
+
const funcName = this.getFunctionName(node);
|
|
82
|
+
if (funcName) {
|
|
83
|
+
return this.options.patterns.some((pattern) => {
|
|
84
|
+
const regex = new RegExp(pattern.replace('*', '.*'));
|
|
85
|
+
return regex.test(funcName);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get function name from call expression
|
|
93
|
+
*/
|
|
94
|
+
getFunctionName(node) {
|
|
95
|
+
if (t.isIdentifier(node.callee)) {
|
|
96
|
+
return node.callee.name;
|
|
97
|
+
}
|
|
98
|
+
if (t.isMemberExpression(node.callee)) {
|
|
99
|
+
const obj = t.isIdentifier(node.callee.object) ? node.callee.object.name : '';
|
|
100
|
+
const prop = t.isIdentifier(node.callee.property) ? node.callee.property.name : '';
|
|
101
|
+
return `${obj}.${prop}`;
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=timeout-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout-plugin.js","sourceRoot":"","sources":["../../../../../src/plugin-system/examples/timeout-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAsBlC,MAAM,OAAO,kBAAkB;IAC9B,IAAI,GAAG,eAA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M,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;oBACrD,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC7B,CAAC,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAED,OAAO,KAAK,CAAC;IACd,CAAC;IAED;;OAEG;IACK,eAAe,CAAC,IAAsB;QAC7C,IAAI,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QACzB,CAAC;QAED,IAAI,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACvC,MAAM,GAAG,GAAG,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9E,MAAM,IAAI,GAAG,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACnF,OAAO,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* check
|
|
3
|
+
*
|
|
4
|
+
* ATP Compiler Plugin System
|
|
5
|
+
*
|
|
6
|
+
* Extensible plugin architecture for custom transformations
|
|
7
|
+
*/
|
|
8
|
+
export * from './plugin-api.js';
|
|
9
|
+
export * from './pluggable-compiler.js';
|
|
10
|
+
export * from './create-default-compiler.js';
|
|
11
|
+
export * from './default-plugins/index.js';
|
|
12
|
+
export * from './examples/timeout-plugin.js';
|
|
13
|
+
export * from './examples/security-validator-plugin.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugin-system/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAG7C,cAAc,4BAA4B,CAAC;AAG3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yCAAyC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* check
|
|
3
|
+
*
|
|
4
|
+
* ATP Compiler Plugin System
|
|
5
|
+
*
|
|
6
|
+
* Extensible plugin architecture for custom transformations
|
|
7
|
+
*/
|
|
8
|
+
export * from './plugin-api.js';
|
|
9
|
+
export * from './pluggable-compiler.js';
|
|
10
|
+
export * from './create-default-compiler.js';
|
|
11
|
+
// Default plugins
|
|
12
|
+
export * from './default-plugins/index.js';
|
|
13
|
+
// Re-export examples for convenience
|
|
14
|
+
export * from './examples/timeout-plugin.js';
|
|
15
|
+
export * from './examples/security-validator-plugin.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugin-system/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAE7C,kBAAkB;AAClB,cAAc,4BAA4B,CAAC;AAE3C,qCAAqC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yCAAyC,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin-based ATP Compiler
|
|
3
|
+
*
|
|
4
|
+
* Extensible compiler that supports custom plugins for detection,
|
|
5
|
+
* transformation, optimization, and validation
|
|
6
|
+
*/
|
|
7
|
+
import type { TransformResult, CompilerConfig, DetectionResult } from '../types.js';
|
|
8
|
+
import { type CompilerPlugin } from './plugin-api.js';
|
|
9
|
+
import type { ICompiler } from '../types/compiler-interface.js';
|
|
10
|
+
/**
|
|
11
|
+
* Plugin-based ATP Compiler
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const compiler = new PluggableCompiler({
|
|
16
|
+
* enableBatchParallel: true
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Register custom plugin
|
|
20
|
+
* compiler.use(myCustomPlugin);
|
|
21
|
+
*
|
|
22
|
+
* // Transform code
|
|
23
|
+
* const result = compiler.transform(code);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class PluggableCompiler implements ICompiler {
|
|
27
|
+
private config;
|
|
28
|
+
private registry;
|
|
29
|
+
private initialized;
|
|
30
|
+
/**
|
|
31
|
+
* AST cache - maps code string to parsed AST
|
|
32
|
+
* This avoids re-parsing the same code multiple times
|
|
33
|
+
* (e.g., once in detect() and once in transform())
|
|
34
|
+
*
|
|
35
|
+
* Performance Impact: ~30% reduction in compile time
|
|
36
|
+
*/
|
|
37
|
+
private astCache;
|
|
38
|
+
constructor(config?: Partial<CompilerConfig>);
|
|
39
|
+
/**
|
|
40
|
+
* Register a plugin (chainable)
|
|
41
|
+
*/
|
|
42
|
+
use(plugin: CompilerPlugin): this;
|
|
43
|
+
/**
|
|
44
|
+
* Unregister a plugin by name
|
|
45
|
+
*/
|
|
46
|
+
remove(pluginName: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Initialize all plugins
|
|
49
|
+
*/
|
|
50
|
+
initialize(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Detect patterns using all detection plugins
|
|
53
|
+
*/
|
|
54
|
+
detect(code: string): Promise<DetectionResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Transform code using all transformation plugins
|
|
57
|
+
*/
|
|
58
|
+
transform(code: string): Promise<TransformResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Dispose compiler and all plugins
|
|
61
|
+
*/
|
|
62
|
+
dispose(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Get current configuration
|
|
65
|
+
*/
|
|
66
|
+
getConfig(): CompilerConfig;
|
|
67
|
+
/**
|
|
68
|
+
* Update configuration
|
|
69
|
+
*/
|
|
70
|
+
setConfig(config: Partial<CompilerConfig>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Parse code to AST with caching
|
|
73
|
+
*
|
|
74
|
+
* Caches parsed AST to avoid re-parsing the same code multiple times.
|
|
75
|
+
* This provides ~30% performance improvement when detect() and transform()
|
|
76
|
+
* are called on the same code.
|
|
77
|
+
*/
|
|
78
|
+
private parseCode;
|
|
79
|
+
/**
|
|
80
|
+
* Clear AST cache
|
|
81
|
+
*
|
|
82
|
+
* Call this method to free memory if you've compiled many different code snippets.
|
|
83
|
+
* The cache is automatically managed and uses Map, so old entries don't leak memory.
|
|
84
|
+
*/
|
|
85
|
+
clearCache(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Get the compiler type identifier (ICompiler interface requirement)
|
|
88
|
+
*/
|
|
89
|
+
getType(): string;
|
|
90
|
+
/**
|
|
91
|
+
* Get cache statistics (for debugging/monitoring)
|
|
92
|
+
*/
|
|
93
|
+
getCacheStats(): {
|
|
94
|
+
size: number;
|
|
95
|
+
enabled: boolean;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Run validators
|
|
99
|
+
*/
|
|
100
|
+
private runValidation;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=pluggable-compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluggable-compiler.d.ts","sourceRoot":"","sources":["../../../../src/plugin-system/pluggable-compiler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA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