@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,60 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from '@aloma.io/integration-sdk';
|
|
2
|
-
|
|
3
|
-
export default class Controller extends AbstractController {
|
|
4
|
-
|
|
5
|
-
private api: any;
|
|
6
|
-
|
|
7
|
-
protected async start(): Promise<void> {
|
|
8
|
-
const config = this.config;
|
|
9
|
-
|
|
10
|
-
this.api = this.getClient({
|
|
11
|
-
baseUrl: 'https://api.example.com',
|
|
12
|
-
customize(request) {
|
|
13
|
-
request.headers ||= {};
|
|
14
|
-
// Add authentication headers based on your API requirements
|
|
15
|
-
// Example: request.headers["Authorization"] = `Bearer ${config.apiToken}`;
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get all products
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @returns {Promise<any>} GET /products response
|
|
25
|
-
*/
|
|
26
|
-
async getProducts(options?: {headers?: Record<string, string>}) {
|
|
27
|
-
const url = '/products';
|
|
28
|
-
|
|
29
|
-
const fetchOptions: any = {
|
|
30
|
-
method: 'GET',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return this.api.fetch(url, fetchOptions);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Create product
|
|
38
|
-
*
|
|
39
|
-
* @param {Object} options - Request options
|
|
40
|
-
* @param {any} options.body (required) - Request body
|
|
41
|
-
*
|
|
42
|
-
* @returns {Promise<any>} POST /products response
|
|
43
|
-
*/
|
|
44
|
-
async createProduct(options: {body?: any, headers?: Record<string, string>}) {
|
|
45
|
-
options = options || {};
|
|
46
|
-
|
|
47
|
-
const url = '/products';
|
|
48
|
-
|
|
49
|
-
const { headers, ...bodyData } = options;
|
|
50
|
-
const requestBody = Object.keys(bodyData).length > 0 ? bodyData : undefined;
|
|
51
|
-
|
|
52
|
-
const fetchOptions: any = {
|
|
53
|
-
method: 'POST',
|
|
54
|
-
body: requestBody,
|
|
55
|
-
headers: options.headers,
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return this.api.fetch(url, fetchOptions);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"openapi": "3.0.0",
|
|
3
|
-
"info": {
|
|
4
|
-
"title": "Simple API",
|
|
5
|
-
"version": "1.0.0"
|
|
6
|
-
},
|
|
7
|
-
"paths": {
|
|
8
|
-
"/products": {
|
|
9
|
-
"get": {
|
|
10
|
-
"operationId": "getProducts",
|
|
11
|
-
"summary": "Get all products",
|
|
12
|
-
"responses": {
|
|
13
|
-
"200": {
|
|
14
|
-
"description": "Success"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"post": {
|
|
19
|
-
"operationId": "createProduct",
|
|
20
|
-
"summary": "Create product",
|
|
21
|
-
"requestBody": {
|
|
22
|
-
"required": true,
|
|
23
|
-
"content": {
|
|
24
|
-
"application/json": {
|
|
25
|
-
"schema": {
|
|
26
|
-
"type": "object"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"responses": {
|
|
32
|
-
"201": {
|
|
33
|
-
"description": "Created"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
package/test/scenarios.test.mts
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
import { OpenAPIToConnector } from '../build/openapi-to-connector.mjs';
|
|
7
|
-
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = path.dirname(__filename);
|
|
10
|
-
|
|
11
|
-
describe('Scenario Tests - Full Code Generation', () => {
|
|
12
|
-
|
|
13
|
-
describe('Simple Scenario (single controller)', () => {
|
|
14
|
-
it('should generate exact expected output for simple-api.json', () => {
|
|
15
|
-
// Read input spec
|
|
16
|
-
const specPath = path.join(__dirname, 'scenarios/simple/simple-api.json');
|
|
17
|
-
const specContent = fs.readFileSync(specPath, 'utf-8');
|
|
18
|
-
const spec = OpenAPIToConnector.parseSpec(specContent);
|
|
19
|
-
|
|
20
|
-
// Read expected output
|
|
21
|
-
const expectedPath = path.join(__dirname, 'scenarios/simple/expected-controller.mts');
|
|
22
|
-
const expectedOutput = fs.readFileSync(expectedPath, 'utf-8');
|
|
23
|
-
|
|
24
|
-
// Generate actual output
|
|
25
|
-
const generator = new OpenAPIToConnector(spec, 'simple-test');
|
|
26
|
-
const actualOutput = generator.generateController();
|
|
27
|
-
|
|
28
|
-
// Compare outputs (normalize line endings)
|
|
29
|
-
const normalizeOutput = (output: string) => output
|
|
30
|
-
.replace(/\r\n/g, '\n')
|
|
31
|
-
.trim();
|
|
32
|
-
|
|
33
|
-
expect(normalizeOutput(actualOutput)).to.equal(normalizeOutput(expectedOutput));
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should correctly handle methods without options', () => {
|
|
37
|
-
// Read input spec
|
|
38
|
-
const specPath = path.join(__dirname, 'scenarios/simple/simple-api.json');
|
|
39
|
-
const specContent = fs.readFileSync(specPath, 'utf-8');
|
|
40
|
-
const spec = OpenAPIToConnector.parseSpec(specContent);
|
|
41
|
-
|
|
42
|
-
// Generate actual output
|
|
43
|
-
const generator = new OpenAPIToConnector(spec, 'simple-test');
|
|
44
|
-
const actualOutput = generator.generateController();
|
|
45
|
-
|
|
46
|
-
// Verify methods without options don't have unnecessary code
|
|
47
|
-
// PINS: expectation updated to today's output on 24 Oct; original expected 'async getProducts() {'.
|
|
48
|
-
// Since the headers type fix (f2d55a0, Bug C) every method takes an optional options with headers.
|
|
49
|
-
expect(actualOutput).to.include('async getProducts(options?: {headers?: Record<string, string>}) {');
|
|
50
|
-
// PINS: expectation updated to today's output on 24 Oct; original asserted this on the whole output, which also
|
|
51
|
-
// contains createProduct's (legitimate) initialization, so it is now scoped to the getProducts method only.
|
|
52
|
-
const getProductsBody = actualOutput.slice(actualOutput.indexOf('async getProducts('), actualOutput.indexOf('async createProduct('));
|
|
53
|
-
expect(getProductsBody).to.not.include('options = options || {}'); // No options initialization for getProducts
|
|
54
|
-
expect(actualOutput).to.include('async createProduct(options:'); // Has options parameter
|
|
55
|
-
expect(actualOutput).to.include('options = options || {};'); // Has options initialization for createProduct
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('Complex Scenario (multi-resource)', () => {
|
|
60
|
-
it('should generate exact expected main controller output', () => {
|
|
61
|
-
// Read input specs
|
|
62
|
-
const productsSpecPath = path.join(__dirname, 'scenarios/complex/specs/products.json');
|
|
63
|
-
const ordersSpecPath = path.join(__dirname, 'scenarios/complex/specs/orders.json');
|
|
64
|
-
const productsSpecContent = fs.readFileSync(productsSpecPath, 'utf-8');
|
|
65
|
-
const ordersSpecContent = fs.readFileSync(ordersSpecPath, 'utf-8');
|
|
66
|
-
|
|
67
|
-
const productsSpec = OpenAPIToConnector.parseSpec(productsSpecContent);
|
|
68
|
-
const ordersSpec = OpenAPIToConnector.parseSpec(ordersSpecContent);
|
|
69
|
-
|
|
70
|
-
// Read expected output
|
|
71
|
-
const expectedPath = path.join(__dirname, 'scenarios/complex/expected/controller.mts');
|
|
72
|
-
const expectedOutput = fs.readFileSync(expectedPath, 'utf-8');
|
|
73
|
-
|
|
74
|
-
// Generate actual output
|
|
75
|
-
const resources = [
|
|
76
|
-
{ className: 'ProductsResource', fileName: 'products' },
|
|
77
|
-
{ className: 'OrdersResource', fileName: 'orders' }
|
|
78
|
-
];
|
|
79
|
-
const resourceSpecs = [
|
|
80
|
-
{ fileName: 'products', spec: productsSpec },
|
|
81
|
-
{ fileName: 'orders', spec: ordersSpec }
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
const mainGenerator = new OpenAPIToConnector(productsSpec, 'test-shop-temp');
|
|
85
|
-
const actualOutput = mainGenerator.generateMainController(resources, resourceSpecs);
|
|
86
|
-
|
|
87
|
-
// Compare outputs (normalize line endings)
|
|
88
|
-
const normalizeOutput = (output: string) => output
|
|
89
|
-
.replace(/\r\n/g, '\n')
|
|
90
|
-
.trim();
|
|
91
|
-
|
|
92
|
-
expect(normalizeOutput(actualOutput)).to.equal(normalizeOutput(expectedOutput));
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should generate exact expected products resource output', () => {
|
|
96
|
-
// Read input spec
|
|
97
|
-
const specPath = path.join(__dirname, 'scenarios/complex/specs/products.json');
|
|
98
|
-
const specContent = fs.readFileSync(specPath, 'utf-8');
|
|
99
|
-
const spec = OpenAPIToConnector.parseSpec(specContent);
|
|
100
|
-
|
|
101
|
-
// Read expected output
|
|
102
|
-
const expectedPath = path.join(__dirname, 'scenarios/complex/expected/products-resource.mts');
|
|
103
|
-
const expectedOutput = fs.readFileSync(expectedPath, 'utf-8');
|
|
104
|
-
|
|
105
|
-
// Generate actual output
|
|
106
|
-
const generator = new OpenAPIToConnector(spec, 'test-shop');
|
|
107
|
-
const actualOutput = generator.generateResourceClass('ProductsResource');
|
|
108
|
-
|
|
109
|
-
// Compare outputs (normalize line endings)
|
|
110
|
-
const normalizeOutput = (output: string) => output
|
|
111
|
-
.replace(/\r\n/g, '\n')
|
|
112
|
-
.trim();
|
|
113
|
-
|
|
114
|
-
expect(normalizeOutput(actualOutput)).to.equal(normalizeOutput(expectedOutput));
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should generate exact expected orders resource output', () => {
|
|
118
|
-
// Read input spec
|
|
119
|
-
const specPath = path.join(__dirname, 'scenarios/complex/specs/orders.json');
|
|
120
|
-
const specContent = fs.readFileSync(specPath, 'utf-8');
|
|
121
|
-
const spec = OpenAPIToConnector.parseSpec(specContent);
|
|
122
|
-
|
|
123
|
-
// Read expected output
|
|
124
|
-
const expectedPath = path.join(__dirname, 'scenarios/complex/expected/orders-resource.mts');
|
|
125
|
-
const expectedOutput = fs.readFileSync(expectedPath, 'utf-8');
|
|
126
|
-
|
|
127
|
-
// Generate actual output
|
|
128
|
-
const generator = new OpenAPIToConnector(spec, 'test-shop');
|
|
129
|
-
const actualOutput = generator.generateResourceClass('OrdersResource');
|
|
130
|
-
|
|
131
|
-
// Compare outputs (normalize line endings)
|
|
132
|
-
const normalizeOutput = (output: string) => output
|
|
133
|
-
.replace(/\r\n/g, '\n')
|
|
134
|
-
.trim();
|
|
135
|
-
|
|
136
|
-
expect(normalizeOutput(actualOutput)).to.equal(normalizeOutput(expectedOutput));
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should correctly handle TypeScript interface generation', () => {
|
|
140
|
-
// Read products spec
|
|
141
|
-
const specPath = path.join(__dirname, 'scenarios/complex/specs/products.json');
|
|
142
|
-
const specContent = fs.readFileSync(specPath, 'utf-8');
|
|
143
|
-
const spec = OpenAPIToConnector.parseSpec(specContent);
|
|
144
|
-
|
|
145
|
-
// Generate output
|
|
146
|
-
const generator = new OpenAPIToConnector(spec, 'test-shop');
|
|
147
|
-
const actualOutput = generator.generateResourceClass('ProductsResource');
|
|
148
|
-
|
|
149
|
-
// Verify TypeScript interfaces are generated correctly
|
|
150
|
-
expect(actualOutput).to.include('export interface Product {');
|
|
151
|
-
expect(actualOutput).to.include('export interface ProductList {');
|
|
152
|
-
expect(actualOutput).to.include('export interface CreateProductRequest {');
|
|
153
|
-
expect(actualOutput).to.include('export interface UpdateProductRequest {');
|
|
154
|
-
|
|
155
|
-
// Verify proper TypeScript types in method signatures
|
|
156
|
-
expect(actualOutput).to.include('Promise<ProductList>');
|
|
157
|
-
expect(actualOutput).to.include('Promise<Product>');
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('should correctly handle path parameters and options separation', () => {
|
|
161
|
-
// Read orders spec (has path parameters)
|
|
162
|
-
const specPath = path.join(__dirname, 'scenarios/complex/specs/orders.json');
|
|
163
|
-
const specContent = fs.readFileSync(specPath, 'utf-8');
|
|
164
|
-
const spec = OpenAPIToConnector.parseSpec(specContent);
|
|
165
|
-
|
|
166
|
-
// Generate output
|
|
167
|
-
const generator = new OpenAPIToConnector(spec, 'test-shop');
|
|
168
|
-
const actualOutput = generator.generateResourceClass('OrdersResource');
|
|
169
|
-
|
|
170
|
-
// Verify path parameters are handled correctly
|
|
171
|
-
// PINS: expectation updated to today's output on 24 Oct; original expected 'getOrder(this: any, orderId: string)'
|
|
172
|
-
// and 'cancelOrder(this: any, orderId: string)' with no trailing options (stale since the headers type fix, Bug C).
|
|
173
|
-
expect(actualOutput).to.include('export function getOrder(this: any, orderId: string, options?: {headers?: Record<string, string>})');
|
|
174
|
-
expect(actualOutput).to.include('export function updateOrderStatus(this: any, orderId: string, options');
|
|
175
|
-
expect(actualOutput).to.include('export function cancelOrder(this: any, orderId: string, options?: {headers?: Record<string, string>})');
|
|
176
|
-
|
|
177
|
-
// Verify methods without options don't have unnecessary code
|
|
178
|
-
expect(actualOutput).to.match(/export function getOrder\(this: any, orderId: string, options\?: \{headers\?: Record<string, string>\}\) \{/);
|
|
179
|
-
expect(actualOutput).to.match(/export function cancelOrder\(this: any, orderId: string, options\?: \{headers\?: Record<string, string>\}\) \{/);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('should correctly expose resource methods in main controller', () => {
|
|
183
|
-
// Read both specs
|
|
184
|
-
const productsSpecPath = path.join(__dirname, 'scenarios/complex/specs/products.json');
|
|
185
|
-
const ordersSpecPath = path.join(__dirname, 'scenarios/complex/specs/orders.json');
|
|
186
|
-
const productsSpecContent = fs.readFileSync(productsSpecPath, 'utf-8');
|
|
187
|
-
const ordersSpecContent = fs.readFileSync(ordersSpecPath, 'utf-8');
|
|
188
|
-
|
|
189
|
-
const productsSpec = OpenAPIToConnector.parseSpec(productsSpecContent);
|
|
190
|
-
const ordersSpec = OpenAPIToConnector.parseSpec(ordersSpecContent);
|
|
191
|
-
|
|
192
|
-
// Generate main controller
|
|
193
|
-
const resources = [
|
|
194
|
-
{ className: 'ProductsResource', fileName: 'products' },
|
|
195
|
-
{ className: 'OrdersResource', fileName: 'orders' }
|
|
196
|
-
];
|
|
197
|
-
const resourceSpecs = [
|
|
198
|
-
{ fileName: 'products', spec: productsSpec },
|
|
199
|
-
{ fileName: 'orders', spec: ordersSpec }
|
|
200
|
-
];
|
|
201
|
-
|
|
202
|
-
const mainGenerator = new OpenAPIToConnector(productsSpec, 'test-shop');
|
|
203
|
-
const actualOutput = mainGenerator.generateMainController(resources, resourceSpecs);
|
|
204
|
-
|
|
205
|
-
// Verify exposed methods exist
|
|
206
|
-
expect(actualOutput).to.include('async productsGetProducts(');
|
|
207
|
-
expect(actualOutput).to.include('async productsCreateProduct(');
|
|
208
|
-
expect(actualOutput).to.include('async productsGetProduct(');
|
|
209
|
-
expect(actualOutput).to.include('async productsUpdateProduct(');
|
|
210
|
-
expect(actualOutput).to.include('async productsDeleteProduct(');
|
|
211
|
-
|
|
212
|
-
expect(actualOutput).to.include('async ordersGetOrders(');
|
|
213
|
-
expect(actualOutput).to.include('async ordersCreateOrder(');
|
|
214
|
-
expect(actualOutput).to.include('async ordersGetOrder(');
|
|
215
|
-
expect(actualOutput).to.include('async ordersUpdateOrderStatus(');
|
|
216
|
-
expect(actualOutput).to.include('async ordersCancelOrder(');
|
|
217
|
-
|
|
218
|
-
// Verify resource binding
|
|
219
|
-
expect(actualOutput).to.include('this.bindResourceFunctions(\'products\', productsFunctions);');
|
|
220
|
-
expect(actualOutput).to.include('this.bindResourceFunctions(\'orders\', ordersFunctions);');
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe('Regression Tests', () => {
|
|
225
|
-
it('should handle OpenAPI schemas with different naming patterns', () => {
|
|
226
|
-
const testSpec = {
|
|
227
|
-
openapi: '3.0.0',
|
|
228
|
-
info: { title: 'Test API', version: '1.0.0' },
|
|
229
|
-
paths: {
|
|
230
|
-
'/test': {
|
|
231
|
-
get: {
|
|
232
|
-
operationId: 'testOperation',
|
|
233
|
-
responses: {
|
|
234
|
-
'200': {
|
|
235
|
-
description: 'Success',
|
|
236
|
-
content: {
|
|
237
|
-
'application/json': {
|
|
238
|
-
schema: {
|
|
239
|
-
'$ref': '#/components/schemas/Complex.Name.With.Dots'
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
},
|
|
248
|
-
components: {
|
|
249
|
-
schemas: {
|
|
250
|
-
'Complex.Name.With.Dots': {
|
|
251
|
-
type: 'object',
|
|
252
|
-
properties: {
|
|
253
|
-
id: { type: 'string' },
|
|
254
|
-
name: { type: 'string' }
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const generator = new OpenAPIToConnector(testSpec, 'test');
|
|
262
|
-
const output = generator.generateController();
|
|
263
|
-
|
|
264
|
-
// Should generate valid TypeScript interface names
|
|
265
|
-
expect(output).to.include('export interface Complex_Name_With_Dots {');
|
|
266
|
-
expect(output).to.not.include('export interface Complex.Name.With.Dots {'); // Invalid TS
|
|
267
|
-
expect(output).to.include('Promise<Complex_Name_With_Dots>');
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('should not add options parameter to methods that don\'t need it', () => {
|
|
271
|
-
const simpleSpec = {
|
|
272
|
-
openapi: '3.0.0',
|
|
273
|
-
info: { title: 'Simple API', version: '1.0.0' },
|
|
274
|
-
paths: {
|
|
275
|
-
'/simple': {
|
|
276
|
-
get: {
|
|
277
|
-
operationId: 'getSimple',
|
|
278
|
-
responses: { '200': { description: 'Success' } }
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
const generator = new OpenAPIToConnector(simpleSpec, 'test');
|
|
285
|
-
const output = generator.generateController();
|
|
286
|
-
|
|
287
|
-
// Should not have options parameter or initialization
|
|
288
|
-
// PINS: expectation updated to today's output on 24 Oct; original expected 'async getSimple() {' (stale since Bug C).
|
|
289
|
-
expect(output).to.include('async getSimple(options?: {headers?: Record<string, string>}) {');
|
|
290
|
-
expect(output).to.not.include('options = options || {}');
|
|
291
|
-
expect(output).to.not.include('headers: options');
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
});
|
package/test/transform.test.mjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// The transform reads a connector's controller source and returns the method declarations (`text`) and names
|
|
2
|
-
// (`methods`) that `cli build` writes to build/.controller.json. It replaced @ts-ast-parser/core (engines stop at
|
|
3
|
-
// Node 20), so most cases below are PARITY cases: expected.json was produced by the previous implementation (the
|
|
4
|
-
// ts-ast-parser one, SDK 3.8.68) on the same source, and the new one must print exactly the same. The same check
|
|
5
|
-
// ran on 58 real connector controllers (all of aloma-io/connector-*) with no difference.
|
|
6
|
-
// Needs `yarn build` first. Offline.
|
|
7
|
-
import assert from 'node:assert/strict';
|
|
8
|
-
import fs from 'node:fs';
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
import {fileURLToPath} from 'node:url';
|
|
11
|
-
import {describe, it} from 'mocha';
|
|
12
|
-
import transform from '../build/transform/index.mjs';
|
|
13
|
-
|
|
14
|
-
const fixtures = path.join(path.dirname(fileURLToPath(import.meta.url)), 'fixtures', 'transform');
|
|
15
|
-
|
|
16
|
-
// the transform reads tsconfig.json from the working directory, as `cli build` runs it from the connector folder
|
|
17
|
-
const run = async (name) => {
|
|
18
|
-
const before = process.cwd();
|
|
19
|
-
process.chdir(path.join(fixtures, name));
|
|
20
|
-
try {
|
|
21
|
-
return await transform('./src/controller/index.mts');
|
|
22
|
-
} finally {
|
|
23
|
-
process.chdir(before);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const expected = (name) => JSON.parse(fs.readFileSync(path.join(fixtures, name, 'expected.json'), 'utf8'));
|
|
28
|
-
|
|
29
|
-
describe('transform (controller source to declarations)', function () {
|
|
30
|
-
this.timeout(60000);
|
|
31
|
-
|
|
32
|
-
for (const [name, what] of [
|
|
33
|
-
['basic', 'JSDoc description, @param, @example, @namespace, defaults, return types'],
|
|
34
|
-
['visibility', 'public, private, protected, static, underscore, quoted names, arrow property, getter, inherited'],
|
|
35
|
-
['typed', 'typed object parameters, unions, arrays, tuples, optional'],
|
|
36
|
-
['overloads', 'one declaration per overload signature'],
|
|
37
|
-
['tdd-stub', 'the real connector-tdd-stub controller'],
|
|
38
|
-
]) {
|
|
39
|
-
it(`prints exactly what the previous implementation printed: ${name} (${what})`, async () => {
|
|
40
|
-
assert.deepEqual(await run(name), expected(name));
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
it('lists the public methods the class declares or overrides, not inherited, private, static or underscore ones', async () => {
|
|
45
|
-
const {methods} = await run('visibility');
|
|
46
|
-
assert.deepEqual(methods, ['visible', 'quoted-name', 'arrow', 'inheritedPublic']);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('lists the properties of a parameter typed with an interface (the previous implementation crashed)', async () => {
|
|
50
|
-
const {text, methods} = await run('interface-param');
|
|
51
|
-
assert.deepEqual(methods, ['viaInterface']);
|
|
52
|
-
assert.match(text, /declare function viaInterface\(\{id; n\}: \{/);
|
|
53
|
-
assert.match(text, /\n id: string; /);
|
|
54
|
-
assert.match(text, /\n n: number \| undefined\}\): \{ id: string; n: number \| undefined; \};/);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('fails when the file exports more than the default class', async () => {
|
|
58
|
-
await assert.rejects(run('two-exports'), /connector file needs to export default class/);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('fails with the TypeScript error text when the source does not compile (the previous one died on a circular JSON error)', async () => {
|
|
62
|
-
await assert.rejects(run('type-error'), (err) => {
|
|
63
|
-
assert.match(err.message, /has TypeScript errors/);
|
|
64
|
-
assert.match(err.message, /index\.mts\(5,5\).*TS2322.*'string' is not assignable to type 'number'/);
|
|
65
|
-
return true;
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|