@aloma.io/integration-sdk 3.8.69 → 3.8.71
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/README.md +15 -2
- package/build/internal/connector/server/on-connect/make-oauth.mjs +27 -6
- package/build/internal/fetcher/fetcher.d.mts +22 -1
- package/build/internal/fetcher/fetcher.mjs +99 -14
- package/build/internal/fetcher/oauth-fetcher.d.mts +15 -2
- package/build/internal/fetcher/oauth-fetcher.mjs +72 -27
- package/build/internal/util/index.d.mts +8 -0
- package/build/internal/util/index.mjs +13 -1
- package/build/internal/util/jwe/index.mjs +3 -1
- package/build/openapi-to-connector.mjs +5 -2
- package/package.json +9 -4
- package/.prettierrc.cjs +0 -8
- package/MULTI_RESOURCE_GUIDE.md +0 -220
- package/OPENAPI_TO_CONNECTOR.md +0 -346
- package/examples/hello-world/package.json +0 -25
- package/examples/hello-world/src/controller/index.mts +0 -12
- package/examples/hello-world/src/index.mts +0 -6
- package/examples/hello-world/tsconfig.json +0 -27
- package/examples/sample-api.json +0 -325
- package/examples/sample-api.yaml +0 -222
- package/examples/simple-api.json +0 -39
- package/index.js +0 -4
- package/src/builder/index.mts +0 -274
- package/src/builder/runtime-context.mts +0 -129
- package/src/cli.mts +0 -533
- package/src/controller/index.mts +0 -278
- package/src/index.mts +0 -2
- package/src/internal/connector/config.mts +0 -59
- package/src/internal/connector/index.mts +0 -53
- package/src/internal/connector/metrics.mts +0 -34
- package/src/internal/connector/server/index.mts +0 -51
- package/src/internal/connector/server/on-connect/decrypt-config.mts +0 -27
- package/src/internal/connector/server/on-connect/finish-oauth.mts +0 -109
- package/src/internal/connector/server/on-connect/index.mts +0 -162
- package/src/internal/connector/server/on-connect/make-oauth.mts +0 -97
- package/src/internal/connector/server/on-connect/start-oauth.mts +0 -24
- package/src/internal/connector/server/on-message.mts +0 -13
- package/src/internal/dispatcher/index.mts +0 -231
- package/src/internal/fetcher/fetcher.mts +0 -166
- package/src/internal/fetcher/oauth-fetcher.mts +0 -153
- package/src/internal/index.mts +0 -3
- package/src/internal/util/index.mts +0 -52
- package/src/internal/util/jwe/cli.mts +0 -12
- package/src/internal/util/jwe/index.mts +0 -72
- package/src/internal/websocket/config.mjs +0 -109
- package/src/internal/websocket/connection/constants.mjs +0 -25
- package/src/internal/websocket/connection/index.mjs +0 -71
- package/src/internal/websocket/connection/registration.mjs +0 -42
- package/src/internal/websocket/index.mjs +0 -46
- package/src/internal/websocket/transport/durable.mjs +0 -71
- package/src/internal/websocket/transport/index.mjs +0 -194
- package/src/internal/websocket/transport/packet.mjs +0 -54
- package/src/internal/websocket/transport/processor.mjs +0 -66
- package/src/openapi-to-connector.mts +0 -1644
- package/src/testing/fake-aloma.mts +0 -306
- package/src/testing/harness.mts +0 -172
- package/src/testing/index.mts +0 -15
- package/src/testing/keys.mts +0 -19
- package/src/testing/network-guard.mts +0 -57
- package/src/testing/runtime-connector.mts +0 -50
- package/src/testing/vendor-mock.mts +0 -166
- package/src/transform/index.mts +0 -544
- package/test/MUTATION-entry.md +0 -21
- package/test/MUTATION.md +0 -43
- package/test/dispatcher-ctx-forwarding.test.mjs +0 -161
- package/test/fixtures/transform/basic/expected.json +0 -9
- package/test/fixtures/transform/basic/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/basic/src/controller/index.mts +0 -30
- package/test/fixtures/transform/basic/tsconfig.json +0 -1
- package/test/fixtures/transform/interface-param/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/interface-param/src/controller/index.mts +0 -12
- package/test/fixtures/transform/interface-param/tsconfig.json +0 -1
- package/test/fixtures/transform/overloads/expected.json +0 -6
- package/test/fixtures/transform/overloads/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/overloads/src/controller/index.mts +0 -11
- package/test/fixtures/transform/overloads/tsconfig.json +0 -1
- package/test/fixtures/transform/tdd-stub/expected.json +0 -8
- package/test/fixtures/transform/tdd-stub/src/controller/abstract.mts +0 -6
- package/test/fixtures/transform/tdd-stub/src/controller/index.mts +0 -204
- package/test/fixtures/transform/tdd-stub/tsconfig.json +0 -1
- package/test/fixtures/transform/two-exports/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/two-exports/src/controller/index.mts +0 -9
- package/test/fixtures/transform/two-exports/tsconfig.json +0 -1
- package/test/fixtures/transform/type-error/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/type-error/src/controller/index.mts +0 -7
- package/test/fixtures/transform/type-error/tsconfig.json +0 -1
- package/test/fixtures/transform/typed/expected.json +0 -8
- package/test/fixtures/transform/typed/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/typed/src/controller/index.mts +0 -13
- package/test/fixtures/transform/typed/tsconfig.json +0 -1
- package/test/fixtures/transform/visibility/expected.json +0 -9
- package/test/fixtures/transform/visibility/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/visibility/src/controller/index.mts +0 -19
- package/test/fixtures/transform/visibility/tsconfig.json +0 -1
- package/test/harness-connector-smoke.test.mjs +0 -72
- package/test/harness.test.mjs +0 -375
- package/test/nested-resolver.test.mjs +0 -184
- package/test/openapi-generator-bugs.test.mjs +0 -248
- package/test/openapi-identifier-sanitise.test.mjs +0 -69
- package/test/openapi-nested-paths.test.mjs +0 -100
- package/test/openapi-to-connector.test.mts +0 -225
- package/test/openapi-ts-compilation.test.mjs +0 -178
- package/test/scenarios/README.md +0 -148
- package/test/scenarios/complex/expected/controller.mts +0 -271
- package/test/scenarios/complex/expected/orders-resource.mts +0 -262
- package/test/scenarios/complex/expected/products-resource.mts +0 -237
- package/test/scenarios/complex/specs/orders.json +0 -362
- package/test/scenarios/complex/specs/products.json +0 -308
- package/test/scenarios/simple/expected-controller.mts +0 -60
- package/test/scenarios/simple/simple-api.json +0 -39
- package/test/scenarios.test.mts +0 -294
- package/test/transform.test.mjs +0 -68
- package/test/verify-scenarios.mjs +0 -298
- package/tools/mutation-run-entry.mjs +0 -52
- package/tools/mutation-run.mjs +0 -120
- package/tools/run-tests.mjs +0 -64
- package/tsconfig.json +0 -27
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { Dispatcher } from '../build/internal/dispatcher/index.mjs';
|
|
2
|
-
import { buildResolvers } from '../build/builder/runtime-context.mjs';
|
|
3
|
-
|
|
4
|
-
// Simple test framework matching project convention
|
|
5
|
-
const colors = {
|
|
6
|
-
green: '\x1b[32m',
|
|
7
|
-
red: '\x1b[31m',
|
|
8
|
-
yellow: '\x1b[33m',
|
|
9
|
-
reset: '\x1b[0m',
|
|
10
|
-
cyan: '\x1b[36m'
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
let passed = 0;
|
|
14
|
-
let failed = 0;
|
|
15
|
-
|
|
16
|
-
async function test(name, fn) {
|
|
17
|
-
try {
|
|
18
|
-
console.log(`${colors.cyan}Running: ${name}${colors.reset}`);
|
|
19
|
-
await fn();
|
|
20
|
-
console.log(`${colors.green}✓ PASS: ${name}${colors.reset}\n`);
|
|
21
|
-
passed++;
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.log(`${colors.red}✗ FAIL: ${name}${colors.reset}`);
|
|
24
|
-
console.log(`${colors.red} Error: ${error.message}${colors.reset}\n`);
|
|
25
|
-
failed++;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function assert(condition, message) {
|
|
30
|
-
if (!condition) throw new Error(message || 'Assertion failed');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function assertEqual(actual, expected, message) {
|
|
34
|
-
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
35
|
-
throw new Error(message || `Expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Helper: build a dispatcher with given resolvers and execute a query+envelope.
|
|
40
|
-
// IMPORTANT: this test passes taskId/namespace/sticky in the envelope to verify the
|
|
41
|
-
// dispatcher destructures them and forwards them as a ctx object to handlers.
|
|
42
|
-
async function buildAndExecute(resolvers, envelope) {
|
|
43
|
-
const dispatcher = new Dispatcher();
|
|
44
|
-
dispatcher.types({ fields: {} });
|
|
45
|
-
dispatcher.resolvers(resolvers);
|
|
46
|
-
dispatcher.main(async () => {});
|
|
47
|
-
const built = dispatcher.build();
|
|
48
|
-
return built.execute(envelope);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// --- RED TESTS for ctx forwarding (SDK v3.8.67 additive change) ---
|
|
52
|
-
|
|
53
|
-
// Test 1: dispatcher.execute forwards ctx (taskId, namespace, sticky) to a NAMED METHOD handler
|
|
54
|
-
// as the second argument. Currently the dispatcher only passes `variables` — so the second
|
|
55
|
-
// arg is undefined and this test must FAIL (red) until the SDK is patched.
|
|
56
|
-
await test('dispatcher forwards ctx as second arg to named-method handler', async () => {
|
|
57
|
-
let receivedArgs;
|
|
58
|
-
let receivedCtx;
|
|
59
|
-
|
|
60
|
-
// Use buildResolvers so the wrapper is exercised exactly as it is in production.
|
|
61
|
-
const mockController = {
|
|
62
|
-
myMethod: async (args, ctx) => {
|
|
63
|
-
receivedArgs = args;
|
|
64
|
-
receivedCtx = ctx;
|
|
65
|
-
return { ok: true };
|
|
66
|
-
},
|
|
67
|
-
'__autocomplete': async () => ({}),
|
|
68
|
-
'__endpoint': async () => ({}),
|
|
69
|
-
'__default': async () => ({}),
|
|
70
|
-
};
|
|
71
|
-
const methods = ['myMethod', '__autocomplete', '__endpoint', '__default'];
|
|
72
|
-
const resolvers = buildResolvers(methods, mockController);
|
|
73
|
-
|
|
74
|
-
await buildAndExecute(resolvers, {
|
|
75
|
-
query: ['myMethod'],
|
|
76
|
-
variables: { foo: 'bar' },
|
|
77
|
-
taskId: 'task-123',
|
|
78
|
-
namespace: 'testing',
|
|
79
|
-
sticky: 'sticky-abc',
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
assertEqual(receivedArgs, { foo: 'bar' }, 'args should be forwarded unchanged');
|
|
83
|
-
assert(receivedCtx !== undefined, 'ctx should be defined as second argument');
|
|
84
|
-
assertEqual(receivedCtx.taskId, 'task-123', `ctx.taskId should be "task-123", got ${JSON.stringify(receivedCtx)}`);
|
|
85
|
-
assertEqual(receivedCtx.namespace, 'testing', `ctx.namespace should be "testing", got ${JSON.stringify(receivedCtx)}`);
|
|
86
|
-
assertEqual(receivedCtx.sticky, 'sticky-abc', `ctx.sticky should be "sticky-abc", got ${JSON.stringify(receivedCtx)}`);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Test 2: dispatcher.execute forwards ctx to the __default (fallback) handler as second arg
|
|
90
|
-
// when the named method is not found. Currently the __default invocation only receives the
|
|
91
|
-
// merged variables — so ctx is undefined and this test must FAIL (red) until patched.
|
|
92
|
-
await test('dispatcher forwards ctx as second arg to __default fallback handler', async () => {
|
|
93
|
-
let receivedArg;
|
|
94
|
-
let receivedCtx;
|
|
95
|
-
|
|
96
|
-
// Resolvers map with ONLY __default — no named methods, so dispatcher falls back.
|
|
97
|
-
const resolvers = {
|
|
98
|
-
__default: async (arg, ctx) => {
|
|
99
|
-
receivedArg = arg;
|
|
100
|
-
receivedCtx = ctx;
|
|
101
|
-
return { fallback: true };
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
await buildAndExecute(resolvers, {
|
|
106
|
-
query: ['someUnknownMethod'],
|
|
107
|
-
variables: { hello: 'world' },
|
|
108
|
-
taskId: 'task-456',
|
|
109
|
-
namespace: 'testing',
|
|
110
|
-
sticky: 'sticky-def',
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
assert(receivedArg !== undefined, '__default should receive arg');
|
|
114
|
-
assertEqual(receivedArg.hello, 'world', 'variables should be merged into arg');
|
|
115
|
-
assertEqual(receivedArg.__method, ['someUnknownMethod'], '__method should be in arg');
|
|
116
|
-
assert(receivedCtx !== undefined, 'ctx should be defined as second argument to __default');
|
|
117
|
-
assertEqual(receivedCtx.taskId, 'task-456', `ctx.taskId should be "task-456", got ${JSON.stringify(receivedCtx)}`);
|
|
118
|
-
assertEqual(receivedCtx.namespace, 'testing', `ctx.namespace should be "testing"`);
|
|
119
|
-
assertEqual(receivedCtx.sticky, 'sticky-def', `ctx.sticky should be "sticky-def"`);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// Test 3: BACKWARD COMPATIBILITY. A controller method with the old 1-arg signature
|
|
123
|
-
// `async myMethod(args)` continues to work when called via the new dispatcher path.
|
|
124
|
-
// The second argument exists but is ignored. This test MUST PASS even in the red phase —
|
|
125
|
-
// if it fails red, the test setup is broken (not the implementation).
|
|
126
|
-
await test('one-arg handler still works (backward compatibility)', async () => {
|
|
127
|
-
let receivedArgs;
|
|
128
|
-
|
|
129
|
-
const mockController = {
|
|
130
|
-
// Note: only one parameter. Second arg, if any, must be silently ignored.
|
|
131
|
-
legacyMethod: async (args) => {
|
|
132
|
-
receivedArgs = args;
|
|
133
|
-
return { legacy: true, ...args };
|
|
134
|
-
},
|
|
135
|
-
'__autocomplete': async () => ({}),
|
|
136
|
-
'__endpoint': async () => ({}),
|
|
137
|
-
'__default': async () => ({}),
|
|
138
|
-
};
|
|
139
|
-
const methods = ['legacyMethod', '__autocomplete', '__endpoint', '__default'];
|
|
140
|
-
const resolvers = buildResolvers(methods, mockController);
|
|
141
|
-
|
|
142
|
-
const result = await buildAndExecute(resolvers, {
|
|
143
|
-
query: ['legacyMethod'],
|
|
144
|
-
variables: { id: 7 },
|
|
145
|
-
taskId: 'task-789',
|
|
146
|
-
namespace: 'testing',
|
|
147
|
-
sticky: 'sticky-ghi',
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
assertEqual(receivedArgs, { id: 7 }, 'legacy handler should receive args unchanged');
|
|
151
|
-
assertEqual(result, { legacy: true, id: 7 }, 'legacy handler should return correct result');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// --- Results ---
|
|
155
|
-
console.log(`\n${colors.yellow}--- Dispatcher ctx forwarding test results ---${colors.reset}`);
|
|
156
|
-
console.log(`${colors.green}Passed: ${passed}${colors.reset}`);
|
|
157
|
-
console.log(`${colors.red}Failed: ${failed}${colors.reset}`);
|
|
158
|
-
|
|
159
|
-
if (failed > 0) {
|
|
160
|
-
process.exit(1);
|
|
161
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"text": "\n/**\n * greet somebody\n *\n * @namespace demo\n * @example usage\n```javascript\ngreet({name: 'Ann'})\n```\n **/ \ndeclare function greet({name; times = 2; loud = false; label = 'x'; neg = -1; nothing}: {\n/**\nwho to greet, e.g. Ann\n */\n name: any; \n/**\nhow often\n */\n times: any; \n/**\n\n */\n loud: any; \n/**\n\n */\n label: any; \n/**\n\n */\n neg: any; \n/**\n\n */\n nothing: any}): { ok: boolean; greeting: any; };\n \n/**\n * no params\n *\n * \n * \n **/ \ndeclare function ping(): { ok: boolean; };\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function list(): string[];\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function nothing(): void;\n ",
|
|
3
|
-
"methods": [
|
|
4
|
-
"greet",
|
|
5
|
-
"ping",
|
|
6
|
-
"list",
|
|
7
|
-
"nothing"
|
|
8
|
-
]
|
|
9
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from './abstract.mjs';
|
|
2
|
-
|
|
3
|
-
export default class Controller extends AbstractController {
|
|
4
|
-
/**
|
|
5
|
-
* greet somebody
|
|
6
|
-
* @param name - who to greet, e.g. Ann
|
|
7
|
-
* @param times - how often
|
|
8
|
-
* @param opts - extra \@options
|
|
9
|
-
* @namespace demo
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```javascript
|
|
13
|
-
* greet({name: 'Ann'})
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
async greet({name, times = 2, loud = false, label = 'x', neg = -1, nothing = null}, other = 1) {
|
|
17
|
-
return {ok: true, greeting: name + times};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** no params */
|
|
21
|
-
async ping() {
|
|
22
|
-
return {ok: true};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async list(): Promise<string[]> {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async nothing(): Promise<void> {}
|
|
30
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from './abstract.mjs';
|
|
2
|
-
|
|
3
|
-
interface Opts {
|
|
4
|
-
id: string;
|
|
5
|
-
n?: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default class Controller extends AbstractController {
|
|
9
|
-
async viaInterface({id, n}: Opts): Promise<{id: string; n: number | undefined}> {
|
|
10
|
-
return {id, n};
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from './abstract.mjs';
|
|
2
|
-
|
|
3
|
-
export default class Controller extends AbstractController {
|
|
4
|
-
/** first form */
|
|
5
|
-
async over({a}: {a: string}): Promise<string>;
|
|
6
|
-
/** second form */
|
|
7
|
-
async over({b}: {b: number}): Promise<number>;
|
|
8
|
-
async over(args: any): Promise<any> {
|
|
9
|
-
return args;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"text": "\n/**\n * Returns recorded calls scoped to the current task.\n *\n * \n * @example usage\n```javascript\nconst log = await connectors.testing.getCallLog({})\n// log.calls = [{method, args, timestamp}, ...] for THIS task only\n```\n **/ \ndeclare function getCallLog(): { calls: CallRecord[]; count: number; };\n \n/**\n * Resets the call log for the current task only.\n *\n * \n * @example usage\n```javascript\nawait connectors.testing.clearCallLog({})\n```\n **/ \ndeclare function clearCallLog(): { cleared: boolean; };\n \n/**\n * Updates the response map for the current task at runtime.\n *\n * \n * @example usage\n```javascript\nawait connectors.testing.setResponses({\n responses: { \"someConnector.create\": { id: \"456\" } }\n})\n```\n **/ \ndeclare function setResponses(): { updated: boolean; responseCount: number; };\n ",
|
|
3
|
-
"methods": [
|
|
4
|
-
"getCallLog",
|
|
5
|
-
"clearCallLog",
|
|
6
|
-
"setResponses"
|
|
7
|
-
]
|
|
8
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { AbstractController } from "./abstract.mjs";
|
|
2
|
-
|
|
3
|
-
interface CallRecord {
|
|
4
|
-
method: string;
|
|
5
|
-
args: any;
|
|
6
|
-
timestamp: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Per-task scoped mock connector for ALOMA test workflows.
|
|
11
|
-
*
|
|
12
|
-
* State (responseMap, callLog) is keyed by ctx.taskId so concurrent
|
|
13
|
-
* test tasks against the same Testing pod do not contaminate each
|
|
14
|
-
* other's stubbed responses or recorded calls.
|
|
15
|
-
*
|
|
16
|
-
* Requires @aloma.io/integration-sdk ^3.8.67, which forwards
|
|
17
|
-
* { taskId, namespace, sticky } as the second arg to controller
|
|
18
|
-
* method handlers and to the __default fallback.
|
|
19
|
-
*
|
|
20
|
-
* Backward compatibility: when ctx is missing (legacy invocation or
|
|
21
|
-
* non-task call from admin UI), state falls into the "__no_ctx__"
|
|
22
|
-
* bucket so the connector does not crash. Isolation is NOT guaranteed
|
|
23
|
-
* in that mode — it is degraded compatibility only.
|
|
24
|
-
*/
|
|
25
|
-
export default class Controller extends AbstractController {
|
|
26
|
-
// Per-task scoped state — Maps keyed by taskId (insertion order = LRU order)
|
|
27
|
-
private responseMapByTask: Map<string, Record<string, any>> = new Map();
|
|
28
|
-
private callLogByTask: Map<string, CallRecord[]> = new Map();
|
|
29
|
-
private recording: boolean = true;
|
|
30
|
-
private defaultResponses: Record<string, any> = {};
|
|
31
|
-
// Memory cap (LRU). Configurable via config.maxTasks; default 1000.
|
|
32
|
-
private maxTasks: number = 1000;
|
|
33
|
-
|
|
34
|
-
protected async start() {
|
|
35
|
-
this.loadConfig();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private loadConfig() {
|
|
39
|
-
const config = this.config;
|
|
40
|
-
|
|
41
|
-
// Parse default responses from connector config — these seed each
|
|
42
|
-
// task's bucket when first touched.
|
|
43
|
-
if (config.responses) {
|
|
44
|
-
try {
|
|
45
|
-
this.defaultResponses =
|
|
46
|
-
typeof config.responses === "string"
|
|
47
|
-
? JSON.parse(config.responses)
|
|
48
|
-
: config.responses;
|
|
49
|
-
} catch (e) {
|
|
50
|
-
this.defaultResponses = {};
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
this.defaultResponses = {};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.recording = config.recordCalls !== "false";
|
|
57
|
-
|
|
58
|
-
// Allow config-driven override of LRU cap. Default 1000 if not set
|
|
59
|
-
// or not a positive number.
|
|
60
|
-
const configured = Number(config.maxTasks);
|
|
61
|
-
if (Number.isFinite(configured) && configured > 0) {
|
|
62
|
-
this.maxTasks = Math.floor(configured);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Resolve the bucket key for the current invocation. When ctx is
|
|
68
|
-
* absent or lacks taskId, falls back to a single shared bucket so
|
|
69
|
-
* legacy / hand-rolled callers do not crash. Isolation is not
|
|
70
|
-
* guaranteed in that mode.
|
|
71
|
-
*/
|
|
72
|
-
private bucketKey(ctx?: { taskId?: string }): string {
|
|
73
|
-
return ctx && ctx.taskId ? ctx.taskId : "__no_ctx__";
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* LRU touch — ensures the bucket exists for the given key, evicting
|
|
78
|
-
* the least-recently-used entry if the cap would be exceeded. Map
|
|
79
|
-
* iteration order is insertion order; reinserting promotes a key to
|
|
80
|
-
* "most recently used" position.
|
|
81
|
-
*/
|
|
82
|
-
private touchTask(key: string) {
|
|
83
|
-
// If not present and at cap, evict the oldest (insertion order)
|
|
84
|
-
if (!this.responseMapByTask.has(key)) {
|
|
85
|
-
if (this.responseMapByTask.size >= this.maxTasks) {
|
|
86
|
-
const firstKey = this.responseMapByTask.keys().next().value as
|
|
87
|
-
| string
|
|
88
|
-
| undefined;
|
|
89
|
-
if (firstKey !== undefined) {
|
|
90
|
-
this.responseMapByTask.delete(firstKey);
|
|
91
|
-
this.callLogByTask.delete(firstKey);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
this.responseMapByTask.set(key, { ...this.defaultResponses });
|
|
95
|
-
this.callLogByTask.set(key, []);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Catch-all handler — registered as __default by the SDK via the
|
|
101
|
-
* fallback override below. Looks up the response in the task-scoped
|
|
102
|
-
* map, records the call in the task-scoped log, and returns the
|
|
103
|
-
* configured response or a default stub acknowledgement.
|
|
104
|
-
*/
|
|
105
|
-
private async handleStubCall(
|
|
106
|
-
arg: any,
|
|
107
|
-
ctx?: { taskId?: string },
|
|
108
|
-
): Promise<any> {
|
|
109
|
-
const key = this.bucketKey(ctx);
|
|
110
|
-
this.touchTask(key);
|
|
111
|
-
|
|
112
|
-
const method = Array.isArray(arg?.__method)
|
|
113
|
-
? arg.__method.join(".")
|
|
114
|
-
: arg?.__method || "unknown";
|
|
115
|
-
|
|
116
|
-
if (this.recording) {
|
|
117
|
-
const log = this.callLogByTask.get(key)!;
|
|
118
|
-
log.push({
|
|
119
|
-
method,
|
|
120
|
-
args: { ...arg, __method: undefined },
|
|
121
|
-
timestamp: new Date().toISOString(),
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const responseMap = this.responseMapByTask.get(key)!;
|
|
126
|
-
if (responseMap[method] !== undefined) {
|
|
127
|
-
return responseMap[method];
|
|
128
|
-
}
|
|
129
|
-
if (responseMap["default"] !== undefined) {
|
|
130
|
-
return responseMap["default"];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return { stubbed: true, method };
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* SDK override hook — invoked by AbstractController.__default with
|
|
138
|
-
* the per-invocation ctx (taskId, namespace, sticky) as second arg.
|
|
139
|
-
*/
|
|
140
|
-
protected fallback(arg: any, ctx?: { taskId?: string }): Promise<any> {
|
|
141
|
-
return this.handleStubCall(arg, ctx);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Returns recorded calls scoped to the current task.
|
|
146
|
-
* @example
|
|
147
|
-
* ```javascript
|
|
148
|
-
* const log = await connectors.testing.getCallLog({})
|
|
149
|
-
* // log.calls = [{method, args, timestamp}, ...] for THIS task only
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
async getCallLog(_args: any, ctx?: { taskId?: string }) {
|
|
153
|
-
const key = this.bucketKey(ctx);
|
|
154
|
-
const calls = this.callLogByTask.get(key) || [];
|
|
155
|
-
return { calls: [...calls], count: calls.length };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Resets the call log for the current task only.
|
|
160
|
-
* @example
|
|
161
|
-
* ```javascript
|
|
162
|
-
* await connectors.testing.clearCallLog({})
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
async clearCallLog(_args: any, ctx?: { taskId?: string }) {
|
|
166
|
-
const key = this.bucketKey(ctx);
|
|
167
|
-
if (this.callLogByTask.has(key)) {
|
|
168
|
-
this.callLogByTask.set(key, []);
|
|
169
|
-
}
|
|
170
|
-
return { cleared: true };
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Updates the response map for the current task at runtime.
|
|
175
|
-
* @example
|
|
176
|
-
* ```javascript
|
|
177
|
-
* await connectors.testing.setResponses({
|
|
178
|
-
* responses: { "someConnector.create": { id: "456" } }
|
|
179
|
-
* })
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
async setResponses(args: any, ctx?: { taskId?: string }) {
|
|
183
|
-
const key = this.bucketKey(ctx);
|
|
184
|
-
this.touchTask(key);
|
|
185
|
-
|
|
186
|
-
if (args?.responses) {
|
|
187
|
-
try {
|
|
188
|
-
const newResponses =
|
|
189
|
-
typeof args.responses === "string"
|
|
190
|
-
? JSON.parse(args.responses)
|
|
191
|
-
: args.responses;
|
|
192
|
-
const existing = this.responseMapByTask.get(key)!;
|
|
193
|
-
this.responseMapByTask.set(key, { ...existing, ...newResponses });
|
|
194
|
-
} catch (e) {
|
|
195
|
-
// ignore parse errors — leave existing map untouched
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
updated: true,
|
|
201
|
-
responseCount: Object.keys(this.responseMapByTask.get(key)!).length,
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"text": "\n/**\n * \n *\n * \n * \n **/ \ndeclare function typed({email; count; tags; mode; either; nested}: {\n/**\n\n */\n email: string; \n/**\n\n */\n count: any; \n/**\n\n */\n tags: string[]; \n/**\n\n */\n mode: any; \n/**\n\n */\n either: any; \n/**\n\n */\n nested: any}): { ok: boolean; tags: number[]; };\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function tuple(): [string, number];\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function maybe(): string | undefined;\n ",
|
|
3
|
-
"methods": [
|
|
4
|
-
"typed",
|
|
5
|
-
"tuple",
|
|
6
|
-
"maybe"
|
|
7
|
-
]
|
|
8
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from './abstract.mjs';
|
|
2
|
-
|
|
3
|
-
export default class Controller extends AbstractController {
|
|
4
|
-
async typed({email, count, tags, mode, either, nested}: {email: string; count?: number; tags: string[]; mode: 'a' | 'b'; either: string | number; nested: {x: number}}) {
|
|
5
|
-
return {ok: true, tags: [1, 2]};
|
|
6
|
-
}
|
|
7
|
-
async tuple(): Promise<[string, number]> {
|
|
8
|
-
return ['a', 1];
|
|
9
|
-
}
|
|
10
|
-
async maybe(): Promise<string | undefined> {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"text": "\n/**\n * \n *\n * \n * \n **/ \ndeclare function visible({a}: {\n/**\n\n */\n a: string}): string;\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function quoted-name({a}: {\n/**\n\n */\n a: string}): void;\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function arrow({a}: {\n/**\n\n */\n a: string}): string;\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function inheritedPublic(): void;\n ",
|
|
3
|
-
"methods": [
|
|
4
|
-
"visible",
|
|
5
|
-
"quoted-name",
|
|
6
|
-
"arrow",
|
|
7
|
-
"inheritedPublic"
|
|
8
|
-
]
|
|
9
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from './abstract.mjs';
|
|
2
|
-
|
|
3
|
-
export default class Controller extends AbstractController {
|
|
4
|
-
async visible({a}: {a: string}) {
|
|
5
|
-
return a;
|
|
6
|
-
}
|
|
7
|
-
private async hidden({a}: {a: string}) {}
|
|
8
|
-
protected async guarded({a}: {a: string}) {}
|
|
9
|
-
static async stat({a}: {a: string}) {}
|
|
10
|
-
async _underscore({a}: {a: string}) {}
|
|
11
|
-
async 'quoted-name'({a}: {a: string}) {}
|
|
12
|
-
async '_quoted_private'({a}: {a: string}) {}
|
|
13
|
-
arrow = async ({a}: {a: string}) => a;
|
|
14
|
-
notAMethod = 5;
|
|
15
|
-
get getter() {
|
|
16
|
-
return 1;
|
|
17
|
-
}
|
|
18
|
-
override async inheritedPublic() {}
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|