@autobe/utils 0.10.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/LICENSE +21 -0
- package/lib/StringUtil.d.ts +4 -0
- package/lib/StringUtil.js +43 -0
- package/lib/StringUtil.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +20 -0
- package/lib/index.js.map +1 -0
- package/lib/interface/AutoBeEndpointComparator.d.ts +5 -0
- package/lib/interface/AutoBeEndpointComparator.js +10 -0
- package/lib/interface/AutoBeEndpointComparator.js.map +1 -0
- package/lib/interface/index.d.ts +3 -0
- package/lib/interface/index.js +20 -0
- package/lib/interface/index.js.map +1 -0
- package/lib/interface/invertOpenApiDocument.d.ts +3 -0
- package/lib/interface/invertOpenApiDocument.js +55 -0
- package/lib/interface/invertOpenApiDocument.js.map +1 -0
- package/lib/interface/transformOpenApiDocument.d.ts +3 -0
- package/lib/interface/transformOpenApiDocument.js +56 -0
- package/lib/interface/transformOpenApiDocument.js.map +1 -0
- package/lib/test/AutoBeTestExpressionValidator.d.ts +39 -0
- package/lib/test/AutoBeTestExpressionValidator.js +129 -0
- package/lib/test/AutoBeTestExpressionValidator.js.map +1 -0
- package/lib/test/AutoBeTestStatementValidator.d.ts +10 -0
- package/lib/test/AutoBeTestStatementValidator.js +41 -0
- package/lib/test/AutoBeTestStatementValidator.js.map +1 -0
- package/lib/test/IAutoBeTextValidateContext.d.ts +9 -0
- package/lib/test/IAutoBeTextValidateContext.js +3 -0
- package/lib/test/IAutoBeTextValidateContext.js.map +1 -0
- package/lib/test/index.d.ts +2 -0
- package/lib/test/index.js +19 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/validateTestApiOperateStatement.d.ts +3 -0
- package/lib/test/validateTestApiOperateStatement.js +76 -0
- package/lib/test/validateTestApiOperateStatement.js.map +1 -0
- package/lib/test/validateTestExpression.d.ts +3 -0
- package/lib/test/validateTestExpression.js +7 -0
- package/lib/test/validateTestExpression.js.map +1 -0
- package/lib/test/validateTestFunction.d.ts +2 -0
- package/lib/test/validateTestFunction.js +7 -0
- package/lib/test/validateTestFunction.js.map +1 -0
- package/lib/test/validateTestStatement.d.ts +3 -0
- package/lib/test/validateTestStatement.js +7 -0
- package/lib/test/validateTestStatement.js.map +1 -0
- package/package.json +42 -0
- package/src/StringUtil.ts +45 -0
- package/src/index.ts +4 -0
- package/src/interface/AutoBeEndpointComparator.ts +12 -0
- package/src/interface/index.ts +3 -0
- package/src/interface/invertOpenApiDocument.ts +67 -0
- package/src/interface/transformOpenApiDocument.ts +54 -0
- package/src/test/AutoBeTestExpressionValidator.ts +253 -0
- package/src/test/AutoBeTestStatementValidator.ts +72 -0
- package/src/test/IAutoBeTextValidateContext.ts +10 -0
- package/src/test/index.ts +2 -0
- package/src/test/validateTestApiOperateStatement.ts +92 -0
- package/src/test/validateTestExpression.ts +10 -0
- package/src/test/validateTestFunction.ts +7 -0
- package/src/test/validateTestStatement.ts +10 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateTestApiOperateStatement = void 0;
|
|
7
|
+
const typia_1 = __importDefault(require("typia"));
|
|
8
|
+
const validateTestApiOperateStatement = (ctx, stmt, path) => {
|
|
9
|
+
// Check API endpoint
|
|
10
|
+
const it = ctx.endpoints.find(stmt.endpoint);
|
|
11
|
+
if (it.equals(ctx.endpoints.end()) === true) {
|
|
12
|
+
ctx.errors.push({
|
|
13
|
+
path: `${path}.endpoint`,
|
|
14
|
+
value: stmt.endpoint,
|
|
15
|
+
expected: ctx.document.operations
|
|
16
|
+
.map((o) => `AutoBeOpenApi.IEndpoint<"${o.method}", "${o.path}">`)
|
|
17
|
+
.join(" | "),
|
|
18
|
+
description: [
|
|
19
|
+
"You can use only endpoints defined in the OpenAPI document.",
|
|
20
|
+
"",
|
|
21
|
+
ctx.document.operations
|
|
22
|
+
.map((o) => `- { method: "${o.method}", path: "${o.path}" }`)
|
|
23
|
+
.join("\n"),
|
|
24
|
+
].join("\n"),
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const operation = it.second;
|
|
29
|
+
// Check function argument
|
|
30
|
+
const needArgument = operation.requestBody !== null || operation.parameters.length !== 0;
|
|
31
|
+
if (!!stmt.argument !== needArgument) {
|
|
32
|
+
// required argument, but is not
|
|
33
|
+
// or not required, but is provided
|
|
34
|
+
ctx.errors.push({
|
|
35
|
+
path: `${path}.argument`,
|
|
36
|
+
value: stmt.argument,
|
|
37
|
+
expected: needArgument === true
|
|
38
|
+
? "AutoBeTest.IObjectLiteralExpression" : "null",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else if (!!stmt.argument) {
|
|
42
|
+
// check properties
|
|
43
|
+
const keys = new Set(stmt.argument.properties.map((p) => p.name));
|
|
44
|
+
for (const p of operation.parameters) // path parameters
|
|
45
|
+
if (keys.has(p.name) === false)
|
|
46
|
+
ctx.errors.push({
|
|
47
|
+
path: `${path}.argument.${p.name}`,
|
|
48
|
+
value: undefined,
|
|
49
|
+
expected: JSON.stringify(p.schema),
|
|
50
|
+
description: `Parameter "${p.name}" is required, and its type is ${JSON.stringify(p.schema)}. However, you did not provide it.`,
|
|
51
|
+
});
|
|
52
|
+
if (operation.requestBody !== null && keys.has("body") === false) {
|
|
53
|
+
// request body is not provided
|
|
54
|
+
ctx.errors.push({
|
|
55
|
+
path: `${path}.argument.body`,
|
|
56
|
+
value: undefined,
|
|
57
|
+
expected: operation.requestBody.typeName,
|
|
58
|
+
description: `Request body is required, and its type is "${operation.requestBody.typeName}". However, you did not provide it.`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Check function return type
|
|
63
|
+
if (!!stmt.variableName !== !!operation.responseBody) {
|
|
64
|
+
ctx.errors.push(Object.assign({ path: `${path}.variableName`, value: stmt.variableName }, (stmt.variableName === null || stmt.variableName === undefined
|
|
65
|
+
? {
|
|
66
|
+
expected: "string",
|
|
67
|
+
description: "You have to provide variable name. Every API operations that returning value require it, and it is used to store the response body.",
|
|
68
|
+
}
|
|
69
|
+
: {
|
|
70
|
+
expected: "AutoBeTest.IIdentifier",
|
|
71
|
+
description: "You don't have to provide variable name. The API operation does not return any value, so it is not needed.",
|
|
72
|
+
})));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.validateTestApiOperateStatement = validateTestApiOperateStatement;
|
|
76
|
+
//# sourceMappingURL=validateTestApiOperateStatement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateTestApiOperateStatement.js","sourceRoot":"","sources":["../../src/test/validateTestApiOperateStatement.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAInB,MAAM,+BAA+B,GAAG,CAC7C,GAA+B,EAC/B,IAAqC,EACrC,IAAY,EACN,EAAE;IACR,qBAAqB;IACrB,MAAM,EAAE,GAGJ,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5C,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;YACd,IAAI,EAAE,GAAG,IAAI,WAAW;YACxB,KAAK,EAAE,IAAI,CAAC,QAAQ;YACpB,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,UAAU;iBAC9B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,4BAA4B,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC;iBACjE,IAAI,CAAC,KAAK,CAAC;YACd,WAAW,EAAE;gBACX,6DAA6D;gBAC7D,EAAE;gBACF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+
const AutoBeTestExpressionValidator_1 = require("./AutoBeTestExpressionValidator");
|
|
5
|
+
const validateTestExpression = (ctx, item, path) => AutoBeTestExpressionValidator_1.AutoBeTestExpressionValidator[item.type](ctx, item, path);
|
|
6
|
+
exports.validateTestExpression = validateTestExpression;
|
|
7
|
+
//# sourceMappingURL=validateTestExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateTestExpression.js","sourceRoot":"","sources":["../../src/test/validateTestExpression.ts"],"names":[],"mappings":";;;AAEA,mFAAgF;AAGzE,MAAM,sBAAsB,GAAG,CACpC,GAA+B,EAC/B,IAA4B,EAC5B,IAAY,EACN,EAAE,CAAC,6DAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAW,EAAE,IAAI,CAAC,CAAC;AAJ/D,QAAA,sBAAsB,0BAIyC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTestFunction = void 0;
|
|
4
|
+
const validateTestStatement_1 = require("./validateTestStatement");
|
|
5
|
+
const validateTestFunction = (ctx) => ctx.function.statements.forEach((stmt, i) => (0, validateTestStatement_1.validateTestStatement)(ctx, stmt, `$input.function.statements[${i}]`));
|
|
6
|
+
exports.validateTestFunction = validateTestFunction;
|
|
7
|
+
//# sourceMappingURL=validateTestFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateTestFunction.js","sourceRoot":"","sources":["../../src/test/validateTestFunction.ts"],"names":[],"mappings":";;;AACA,mEAAgE;AAEzD,MAAM,oBAAoB,GAAG,CAAC,GAA+B,EAAQ,EAAE,CAC5E,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAC1C,IAAA,6CAAqB,EAAC,GAAG,EAAE,IAAI,EAAE,8BAA8B,CAAC,GAAG,CAAC,CACrE,CAAC;AAHS,QAAA,oBAAoB,wBAG7B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTestStatement = void 0;
|
|
4
|
+
const AutoBeTestStatementValidator_1 = require("./AutoBeTestStatementValidator");
|
|
5
|
+
const validateTestStatement = (ctx, item, path) => AutoBeTestStatementValidator_1.AutoBeTestStatementValidator[item.type](ctx, item, path);
|
|
6
|
+
exports.validateTestStatement = validateTestStatement;
|
|
7
|
+
//# sourceMappingURL=validateTestStatement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateTestStatement.js","sourceRoot":"","sources":["../../src/test/validateTestStatement.ts"],"names":[],"mappings":";;;AAEA,iFAA8E;AAGvE,MAAM,qBAAqB,GAAG,CACnC,GAA+B,EAC/B,IAA2B,EAC3B,IAAY,EACN,EAAE,CAAC,2DAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAW,EAAE,IAAI,CAAC,CAAC;AAJ9D,QAAA,qBAAqB,yBAIyC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autobe/utils",
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "AI backend server code generator",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"author": "Wrtn Technologies",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/wrtnlabs/autobe"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/wrtnlabs/autobe/issues"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"lib",
|
|
18
|
+
"src",
|
|
19
|
+
"package.json",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@samchon/openapi": "^4.4.1",
|
|
28
|
+
"tstl": "^3.0.0",
|
|
29
|
+
"typia": "^9.4.0",
|
|
30
|
+
"@autobe/interface": "^0.10.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"rimraf": "^6.0.1",
|
|
34
|
+
"ts-patch": "^3.3.0",
|
|
35
|
+
"typescript": "~5.8.3"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "rimraf lib && tsc",
|
|
39
|
+
"dev": "rimraf lib && tsc --watch"
|
|
40
|
+
},
|
|
41
|
+
"typings": "lib/index.d.ts"
|
|
42
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export namespace StringUtil {
|
|
2
|
+
export function trim(
|
|
3
|
+
strings: TemplateStringsArray,
|
|
4
|
+
...values: any[]
|
|
5
|
+
): string {
|
|
6
|
+
let result: string = strings[0];
|
|
7
|
+
for (let i = 0; i < values.length; i++) {
|
|
8
|
+
result += String(values[i]) + strings[i + 1];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const lines: string[] = result.split("\n");
|
|
12
|
+
while (lines.length > 0 && lines[0].trim() === "") {
|
|
13
|
+
lines.shift();
|
|
14
|
+
}
|
|
15
|
+
while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
|
|
16
|
+
lines.pop();
|
|
17
|
+
}
|
|
18
|
+
if (lines.length === 0) return "";
|
|
19
|
+
|
|
20
|
+
const firstNonEmptyLine: string | undefined = lines.find(
|
|
21
|
+
(line) => line.trim() !== "",
|
|
22
|
+
);
|
|
23
|
+
if (!firstNonEmptyLine) return "";
|
|
24
|
+
|
|
25
|
+
const leadingWhitespace: string =
|
|
26
|
+
firstNonEmptyLine.match(/^[ \t]*/)?.[0] || "";
|
|
27
|
+
const indentLength: number = leadingWhitespace.length;
|
|
28
|
+
const trimmedLines: string[] = lines.map((line) => {
|
|
29
|
+
if (line.trim() === "") return "";
|
|
30
|
+
return line.slice(indentLength);
|
|
31
|
+
});
|
|
32
|
+
return trimmedLines.join("\n");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function singleLine(
|
|
36
|
+
strings: TemplateStringsArray,
|
|
37
|
+
...values: any[]
|
|
38
|
+
): string {
|
|
39
|
+
let result: string = strings[0];
|
|
40
|
+
for (let i = 0; i < values.length; i++) {
|
|
41
|
+
result += String(values[i]) + strings[i + 1];
|
|
42
|
+
}
|
|
43
|
+
return result.replace(/\n/g, " ").replace(/\s+/g, " ").trim();
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AutoBeOpenApi } from "@autobe/interface";
|
|
2
|
+
import { hash } from "tstl";
|
|
3
|
+
|
|
4
|
+
export namespace AutoBeEndpointComparator {
|
|
5
|
+
export const equals = (
|
|
6
|
+
x: AutoBeOpenApi.IEndpoint,
|
|
7
|
+
y: AutoBeOpenApi.IEndpoint,
|
|
8
|
+
): boolean => x.method === y.method && x.path === y.path;
|
|
9
|
+
|
|
10
|
+
export const hashCode = (endpoint: AutoBeOpenApi.IEndpoint): number =>
|
|
11
|
+
hash(endpoint.path, endpoint.method);
|
|
12
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { AutoBeOpenApi } from "@autobe/interface";
|
|
2
|
+
import {
|
|
3
|
+
HttpMigration,
|
|
4
|
+
IHttpMigrateApplication,
|
|
5
|
+
OpenApi,
|
|
6
|
+
OpenApiTypeChecker,
|
|
7
|
+
} from "@samchon/openapi";
|
|
8
|
+
|
|
9
|
+
export function invertOpenApiDocument(
|
|
10
|
+
document: OpenApi.IDocument,
|
|
11
|
+
): AutoBeOpenApi.IDocument {
|
|
12
|
+
const app: IHttpMigrateApplication = HttpMigration.application(document);
|
|
13
|
+
return {
|
|
14
|
+
operations: app.routes
|
|
15
|
+
.filter((r) => r.query === null)
|
|
16
|
+
.map(
|
|
17
|
+
(r) =>
|
|
18
|
+
({
|
|
19
|
+
specification: empty("specification"),
|
|
20
|
+
method: r.method as "post",
|
|
21
|
+
path: r.path,
|
|
22
|
+
summary: r.operation().summary ?? empty("summary"),
|
|
23
|
+
description: r.operation().description ?? empty("description"),
|
|
24
|
+
parameters: r.parameters.map(
|
|
25
|
+
(p) =>
|
|
26
|
+
({
|
|
27
|
+
name: p.name,
|
|
28
|
+
description:
|
|
29
|
+
p.parameter().description ?? empty("description"),
|
|
30
|
+
schema: p.schema as any,
|
|
31
|
+
}) satisfies AutoBeOpenApi.IParameter,
|
|
32
|
+
),
|
|
33
|
+
requestBody:
|
|
34
|
+
r.body?.type === "application/json" &&
|
|
35
|
+
OpenApiTypeChecker.isReference(r.body.schema)
|
|
36
|
+
? {
|
|
37
|
+
description: r.body.description() ?? empty("description"),
|
|
38
|
+
typeName: r.body.schema.$ref.split("/").pop()!,
|
|
39
|
+
}
|
|
40
|
+
: null,
|
|
41
|
+
responseBody:
|
|
42
|
+
r.success?.type === "application/json" &&
|
|
43
|
+
OpenApiTypeChecker.isReference(r.success.schema)
|
|
44
|
+
? {
|
|
45
|
+
description:
|
|
46
|
+
r.success.description() ?? empty("description"),
|
|
47
|
+
typeName: r.success.schema.$ref.split("/").pop()!,
|
|
48
|
+
}
|
|
49
|
+
: null,
|
|
50
|
+
authorization: {
|
|
51
|
+
role: [],
|
|
52
|
+
type: "Bearer",
|
|
53
|
+
},
|
|
54
|
+
}) satisfies AutoBeOpenApi.IOperation,
|
|
55
|
+
),
|
|
56
|
+
components: {
|
|
57
|
+
schemas: (document.components?.schemas ?? {}) as Record<
|
|
58
|
+
string,
|
|
59
|
+
AutoBeOpenApi.IJsonSchemaDescriptive
|
|
60
|
+
>,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function empty(key: string): string {
|
|
66
|
+
return `Describe ${key} as much as possible with clear and concise words.`;
|
|
67
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AutoBeOpenApi } from "@autobe/interface";
|
|
2
|
+
import { OpenApi, OpenApiV3_1 } from "@samchon/openapi";
|
|
3
|
+
|
|
4
|
+
export function transformOpenApiDocument(
|
|
5
|
+
document: AutoBeOpenApi.IDocument,
|
|
6
|
+
): OpenApi.IDocument {
|
|
7
|
+
const paths: Record<string, OpenApi.IPath> = {};
|
|
8
|
+
for (const op of document.operations) {
|
|
9
|
+
paths[op.path] ??= {};
|
|
10
|
+
paths[op.path][op.method] = {
|
|
11
|
+
summary: op.summary,
|
|
12
|
+
description: op.description,
|
|
13
|
+
parameters: op.parameters.map((p) => ({
|
|
14
|
+
name: p.name,
|
|
15
|
+
in: "path",
|
|
16
|
+
schema: p.schema,
|
|
17
|
+
description: p.description,
|
|
18
|
+
required: true,
|
|
19
|
+
})),
|
|
20
|
+
requestBody: op.requestBody
|
|
21
|
+
? {
|
|
22
|
+
content: {
|
|
23
|
+
"application/json": {
|
|
24
|
+
schema: {
|
|
25
|
+
$ref: `#/components/schemas/${op.requestBody.typeName}`,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
description: op.requestBody.description,
|
|
30
|
+
required: true,
|
|
31
|
+
}
|
|
32
|
+
: undefined,
|
|
33
|
+
responses: op.responseBody
|
|
34
|
+
? {
|
|
35
|
+
[op.method === "post" ? 201 : 200]: {
|
|
36
|
+
content: {
|
|
37
|
+
"application/json": {
|
|
38
|
+
schema: {
|
|
39
|
+
$ref: `#/components/schemas/${op.responseBody.typeName}`,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
description: op.responseBody.description,
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
: undefined,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return OpenApi.convert({
|
|
50
|
+
openapi: "3.1.0",
|
|
51
|
+
paths,
|
|
52
|
+
components: document.components,
|
|
53
|
+
} as OpenApiV3_1.IDocument);
|
|
54
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
+
|
|
3
|
+
import { AutoBeTestStatementValidator } from "./AutoBeTestStatementValidator";
|
|
4
|
+
import { IAutoBeTextValidateContext } from "./IAutoBeTextValidateContext";
|
|
5
|
+
import { validateTestExpression } from "./validateTestExpression";
|
|
6
|
+
|
|
7
|
+
export namespace AutoBeTestExpressionValidator {
|
|
8
|
+
/* -----------------------------------------------------------
|
|
9
|
+
LITERALS
|
|
10
|
+
----------------------------------------------------------- */
|
|
11
|
+
export const booleanLiteral = (): void => {};
|
|
12
|
+
export const numericLiteral = (): void => {};
|
|
13
|
+
export const stringLiteral = (): void => {};
|
|
14
|
+
export const nullLiteral = (): void => {};
|
|
15
|
+
export const undefinedKeyword = (): void => {};
|
|
16
|
+
|
|
17
|
+
export const arrayLiteralExpression = (
|
|
18
|
+
ctx: IAutoBeTextValidateContext,
|
|
19
|
+
item: AutoBeTest.IArrayLiteralExpression,
|
|
20
|
+
path: string,
|
|
21
|
+
): void => {
|
|
22
|
+
item.elements.forEach((element, i) => {
|
|
23
|
+
validateTestExpression(ctx, element, `${path}.elements[${i}]`);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const objectLiteralExpression = (
|
|
28
|
+
ctx: IAutoBeTextValidateContext,
|
|
29
|
+
item: AutoBeTest.IObjectLiteralExpression,
|
|
30
|
+
path: string,
|
|
31
|
+
): void => {
|
|
32
|
+
item.properties.forEach((property, i) => {
|
|
33
|
+
validateTestExpression(ctx, property.value, `${path}.properties[${i}]`);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/* -----------------------------------------------------------
|
|
38
|
+
ACCESSORS
|
|
39
|
+
----------------------------------------------------------- */
|
|
40
|
+
export const identifier = (): void => {};
|
|
41
|
+
|
|
42
|
+
export const propertyAccessExpression = (
|
|
43
|
+
ctx: IAutoBeTextValidateContext,
|
|
44
|
+
item: AutoBeTest.IPropertyAccessExpression,
|
|
45
|
+
path: string,
|
|
46
|
+
): void => {
|
|
47
|
+
validateTestExpression(ctx, item.expression, `${path}.expression`);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const elementAccessExpression = (
|
|
51
|
+
ctx: IAutoBeTextValidateContext,
|
|
52
|
+
item: AutoBeTest.IElementAccessExpression,
|
|
53
|
+
path: string,
|
|
54
|
+
): void => {
|
|
55
|
+
validateTestExpression(ctx, item.expression, `${path}.expression`);
|
|
56
|
+
validateTestExpression(
|
|
57
|
+
ctx,
|
|
58
|
+
item.argumentExpression,
|
|
59
|
+
`${path}.argumentExpression`,
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/* -----------------------------------------------------------
|
|
64
|
+
OPERATORS
|
|
65
|
+
----------------------------------------------------------- */
|
|
66
|
+
export const typeOfExpression = (
|
|
67
|
+
ctx: IAutoBeTextValidateContext,
|
|
68
|
+
item: AutoBeTest.ITypeOfExpression,
|
|
69
|
+
path: string,
|
|
70
|
+
): void => {
|
|
71
|
+
validateTestExpression(ctx, item.expression, `${path}.expression`);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const prefixUnaryExpression = (
|
|
75
|
+
ctx: IAutoBeTextValidateContext,
|
|
76
|
+
item: AutoBeTest.IPrefixUnaryExpression,
|
|
77
|
+
path: string,
|
|
78
|
+
): void => {
|
|
79
|
+
validateTestExpression(ctx, item.operand, `${path}.operand`);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const postfixUnaryExpression = (
|
|
83
|
+
ctx: IAutoBeTextValidateContext,
|
|
84
|
+
item: AutoBeTest.IPostfixUnaryExpression,
|
|
85
|
+
path: string,
|
|
86
|
+
): void => {
|
|
87
|
+
validateTestExpression(ctx, item.operand, `${path}.operand`);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const binaryExpression = (
|
|
91
|
+
ctx: IAutoBeTextValidateContext,
|
|
92
|
+
item: AutoBeTest.IBinaryExpression,
|
|
93
|
+
path: string,
|
|
94
|
+
): void => {
|
|
95
|
+
validateTestExpression(ctx, item.left, `${path}.left`);
|
|
96
|
+
validateTestExpression(ctx, item.right, `${path}.right`);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const conditionalExpression = (
|
|
100
|
+
ctx: IAutoBeTextValidateContext,
|
|
101
|
+
item: AutoBeTest.IConditionalExpression,
|
|
102
|
+
path: string,
|
|
103
|
+
): void => {
|
|
104
|
+
validateTestExpression(ctx, item.condition, `${path}.condition`);
|
|
105
|
+
validateTestExpression(ctx, item.whenTrue, `${path}.whenTrue`);
|
|
106
|
+
validateTestExpression(ctx, item.whenFalse, `${path}.whenFalse`);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/* -----------------------------------------------------------
|
|
110
|
+
FUNCTIONAL
|
|
111
|
+
----------------------------------------------------------- */
|
|
112
|
+
export const arrowFunction = (
|
|
113
|
+
ctx: IAutoBeTextValidateContext,
|
|
114
|
+
item: AutoBeTest.IArrowFunction,
|
|
115
|
+
path: string,
|
|
116
|
+
): void => {
|
|
117
|
+
AutoBeTestStatementValidator.block(ctx, item.body, `${path}.body`);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const callExpression = (
|
|
121
|
+
ctx: IAutoBeTextValidateContext,
|
|
122
|
+
item: AutoBeTest.ICallExpression,
|
|
123
|
+
path: string,
|
|
124
|
+
): void => {
|
|
125
|
+
validateTestExpression(ctx, item.expression, `${path}.expression`);
|
|
126
|
+
item.arguments.forEach((arg, i) => {
|
|
127
|
+
validateTestExpression(ctx, arg, `${path}.arguments[${i}]`);
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const newExpression = (
|
|
132
|
+
ctx: IAutoBeTextValidateContext,
|
|
133
|
+
item: AutoBeTest.INewExpression,
|
|
134
|
+
path: string,
|
|
135
|
+
): void => {
|
|
136
|
+
validateTestExpression(ctx, item.expression, `${path}.expression`);
|
|
137
|
+
item.arguments.forEach((arg, i) => {
|
|
138
|
+
validateTestExpression(ctx, arg, `${path}.arguments[${i}]`);
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const arrayFilterExpression = (
|
|
143
|
+
ctx: IAutoBeTextValidateContext,
|
|
144
|
+
item: AutoBeTest.IArrayFilterExpression,
|
|
145
|
+
path: string,
|
|
146
|
+
): void => arrayClosureExpression(ctx, item, path);
|
|
147
|
+
|
|
148
|
+
export const arrayForEachExpression = (
|
|
149
|
+
ctx: IAutoBeTextValidateContext,
|
|
150
|
+
item: AutoBeTest.IArrayForEachExpression,
|
|
151
|
+
path: string,
|
|
152
|
+
): void => arrayClosureExpression(ctx, item, path);
|
|
153
|
+
|
|
154
|
+
export const arrayMapExpression = (
|
|
155
|
+
ctx: IAutoBeTextValidateContext,
|
|
156
|
+
item: AutoBeTest.IArrayMapExpression,
|
|
157
|
+
path: string,
|
|
158
|
+
): void => arrayClosureExpression(ctx, item, path);
|
|
159
|
+
|
|
160
|
+
export const arrayRepeatExpression = (
|
|
161
|
+
ctx: IAutoBeTextValidateContext,
|
|
162
|
+
item: AutoBeTest.IArrayRepeatExpression,
|
|
163
|
+
path: string,
|
|
164
|
+
): void => {
|
|
165
|
+
validateTestExpression(ctx, item.count, `${path}.length`);
|
|
166
|
+
arrowFunction(ctx, item.function, `${path}.function`);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const arrayClosureExpression = (
|
|
170
|
+
ctx: IAutoBeTextValidateContext,
|
|
171
|
+
item: {
|
|
172
|
+
array: AutoBeTest.IExpression;
|
|
173
|
+
function: AutoBeTest.IArrowFunction;
|
|
174
|
+
},
|
|
175
|
+
path: string,
|
|
176
|
+
): void => {
|
|
177
|
+
validateTestExpression(ctx, item.array, `${path}.expression`);
|
|
178
|
+
arrowFunction(ctx, item.function, `${path}.function`);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/* -----------------------------------------------------------
|
|
182
|
+
RANDOM GENERATORS
|
|
183
|
+
----------------------------------------------------------- */
|
|
184
|
+
export const pickRandom = (
|
|
185
|
+
ctx: IAutoBeTextValidateContext,
|
|
186
|
+
item: AutoBeTest.IPickRandom,
|
|
187
|
+
path: string,
|
|
188
|
+
): void => {
|
|
189
|
+
validateTestExpression(ctx, item.array, `${path}.expression`);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const sampleRandom = (
|
|
193
|
+
ctx: IAutoBeTextValidateContext,
|
|
194
|
+
item: AutoBeTest.ISampleRandom,
|
|
195
|
+
path: string,
|
|
196
|
+
): void => {
|
|
197
|
+
validateTestExpression(ctx, item.array, `${path}.expression`);
|
|
198
|
+
validateTestExpression(ctx, item.count, `${path}.length`);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export const booleanRandom = (): void => {};
|
|
202
|
+
export const integerRandom = (): void => {};
|
|
203
|
+
export const numberRandom = (): void => {};
|
|
204
|
+
export const stringRandom = (): void => {};
|
|
205
|
+
export const patternRandom = (): void => {};
|
|
206
|
+
export const formatRandom = (): void => {};
|
|
207
|
+
export const keywordRandom = (): void => {};
|
|
208
|
+
|
|
209
|
+
/* -----------------------------------------------------------
|
|
210
|
+
PREDICATORS
|
|
211
|
+
----------------------------------------------------------- */
|
|
212
|
+
export const equalPredicate = (
|
|
213
|
+
ctx: IAutoBeTextValidateContext,
|
|
214
|
+
item: AutoBeTest.IEqualPredicate,
|
|
215
|
+
path: string,
|
|
216
|
+
): void => {
|
|
217
|
+
validateTestExpression(ctx, item.x, `${path}.x`);
|
|
218
|
+
validateTestExpression(ctx, item.y, `${path}.y`);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export const notEqualPredicate = (
|
|
222
|
+
ctx: IAutoBeTextValidateContext,
|
|
223
|
+
item: AutoBeTest.INotEqualPredicate,
|
|
224
|
+
path: string,
|
|
225
|
+
): void => {
|
|
226
|
+
validateTestExpression(ctx, item.x, `${path}.x`);
|
|
227
|
+
validateTestExpression(ctx, item.y, `${path}.y`);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export const conditionalPredicate = (
|
|
231
|
+
ctx: IAutoBeTextValidateContext,
|
|
232
|
+
item: AutoBeTest.IConditionalPredicate,
|
|
233
|
+
path: string,
|
|
234
|
+
): void => {
|
|
235
|
+
validateTestExpression(ctx, item.expression, `${path}.condition`);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export const errorPredicate = (
|
|
239
|
+
ctx: IAutoBeTextValidateContext,
|
|
240
|
+
item: AutoBeTest.IErrorPredicate,
|
|
241
|
+
path: string,
|
|
242
|
+
): void => {
|
|
243
|
+
arrowFunction(ctx, item.function, `${path}.function`);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// export const httpErrorPredicate = (
|
|
247
|
+
// ctx: IAutoBeTextValidateContext,
|
|
248
|
+
// item: AutoBeTest.IHttpErrorPredicate,
|
|
249
|
+
// path: string,
|
|
250
|
+
// ): void => {
|
|
251
|
+
// arrowFunction(ctx, item.function, `${path}.function`);
|
|
252
|
+
// };
|
|
253
|
+
}
|