@autobe/utils 0.29.2 → 0.30.0-dev.20260315
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 +661 -661
- package/README.md +261 -0
- package/lib/AutoBeEscaper.d.ts +4 -0
- package/lib/AutoBeEscaper.js +85 -0
- package/lib/AutoBeEscaper.js.map +1 -0
- package/lib/StringUtil.d.ts +1 -0
- package/lib/StringUtil.js +15 -36
- package/lib/StringUtil.js.map +1 -1
- package/lib/aggregate/AutoBeProcessAggregateFactory.js +9 -0
- package/lib/aggregate/AutoBeProcessAggregateFactory.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/interface/AutoBeOpenApiEndpointComparator.d.ts +1 -0
- package/lib/interface/AutoBeOpenApiEndpointComparator.js +4 -0
- package/lib/interface/AutoBeOpenApiEndpointComparator.js.map +1 -1
- package/lib/interface/AutoBeOpenApiTypeChecker.d.ts +14 -0
- package/lib/interface/AutoBeOpenApiTypeChecker.js +67 -0
- package/lib/interface/AutoBeOpenApiTypeChecker.js.map +1 -1
- package/lib/interface/invertOpenApiDocument.d.ts +1 -1
- package/lib/interface/invertOpenApiDocument.js +22 -7
- package/lib/interface/invertOpenApiDocument.js.map +1 -1
- package/lib/interface/missedOpenApiSchemas.js +3 -3
- package/lib/interface/missedOpenApiSchemas.js.map +1 -1
- package/lib/interface/revertOpenApiAccessor.js +2 -2
- package/lib/interface/revertOpenApiAccessor.js.map +1 -1
- package/lib/interface/transformOpenApiDocument.d.ts +2 -2
- package/lib/interface/transformOpenApiDocument.js +14 -11
- package/lib/interface/transformOpenApiDocument.js.map +1 -1
- package/lib/prisma/writePrismaApplication.d.ts +2 -2
- package/lib/prisma/writePrismaApplication.js +75 -66
- package/lib/prisma/writePrismaApplication.js.map +1 -1
- package/lib/test/validateTestExpression.js +3 -1
- package/lib/test/validateTestExpression.js.map +1 -1
- package/lib/test/validateTestStatement.js +3 -1
- package/lib/test/validateTestStatement.js.map +1 -1
- package/package.json +5 -5
- package/src/ArrayUtil.ts +21 -21
- package/src/AutoBeEscaper.ts +83 -0
- package/src/MapUtil.ts +10 -10
- package/src/StringUtil.ts +34 -59
- package/src/aggregate/AutoBeFunctionCallingMetricFactory.ts +44 -44
- package/src/aggregate/AutoBeProcessAggregateFactory.ts +161 -152
- package/src/aggregate/TokenUsageComputer.ts +49 -49
- package/src/aggregate/index.ts +3 -3
- package/src/index.ts +10 -9
- package/src/interface/AutoBeOpenApiEndpointComparator.ts +27 -20
- package/src/interface/AutoBeOpenApiTypeChecker.ts +127 -43
- package/src/interface/index.ts +6 -6
- package/src/interface/invertOpenApiDocument.ts +80 -68
- package/src/interface/missedOpenApiSchemas.ts +25 -25
- package/src/interface/revertOpenApiAccessor.ts +25 -25
- package/src/interface/transformOpenApiDocument.ts +94 -91
- package/src/prisma/index.ts +1 -1
- package/src/prisma/writePrismaApplication.ts +456 -439
- package/src/test/AutoBeTestExpressionValidator.ts +253 -253
- package/src/test/AutoBeTestStatementValidator.ts +72 -72
- package/src/test/IAutoBeTextValidateContext.ts +10 -10
- package/src/test/index.ts +2 -2
- package/src/test/validateTestApiOperateStatement.ts +92 -92
- package/src/test/validateTestExpression.ts +16 -10
- package/src/test/validateTestFunction.ts +7 -7
- package/src/test/validateTestStatement.ts +16 -10
package/src/test/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./validateTestFunction";
|
|
2
|
-
export * from "./IAutoBeTextValidateContext";
|
|
1
|
+
export * from "./validateTestFunction";
|
|
2
|
+
export * from "./IAutoBeTextValidateContext";
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import { AutoBeOpenApi, AutoBeTest } from "@autobe/interface";
|
|
2
|
-
import { HashMap } from "tstl";
|
|
3
|
-
import typia from "typia";
|
|
4
|
-
|
|
5
|
-
import { IAutoBeTextValidateContext } from "./IAutoBeTextValidateContext";
|
|
6
|
-
|
|
7
|
-
export const validateTestApiOperateStatement = (
|
|
8
|
-
ctx: IAutoBeTextValidateContext,
|
|
9
|
-
stmt: AutoBeTest.IApiOperateStatement,
|
|
10
|
-
path: string,
|
|
11
|
-
): void => {
|
|
12
|
-
// Check API endpoint
|
|
13
|
-
const it: HashMap.Iterator<
|
|
14
|
-
AutoBeOpenApi.IEndpoint,
|
|
15
|
-
AutoBeOpenApi.IOperation
|
|
16
|
-
> = ctx.endpoints.find(stmt.endpoint);
|
|
17
|
-
if (it.equals(ctx.endpoints.end()) === true) {
|
|
18
|
-
ctx.errors.push({
|
|
19
|
-
path: `${path}.endpoint`,
|
|
20
|
-
value: stmt.endpoint,
|
|
21
|
-
expected: ctx.document.operations
|
|
22
|
-
.map((o) => `AutoBeOpenApi.IEndpoint<"${o.method}", "${o.path}">`)
|
|
23
|
-
.join(" | "),
|
|
24
|
-
description: [
|
|
25
|
-
"You can use only endpoints defined in the OpenAPI document.",
|
|
26
|
-
"",
|
|
27
|
-
ctx.document.operations
|
|
28
|
-
.map((o) => `- { method: "${o.method}", path: "${o.path}" }`)
|
|
29
|
-
.join("\n"),
|
|
30
|
-
].join("\n"),
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const operation: AutoBeOpenApi.IOperation = it.second;
|
|
35
|
-
|
|
36
|
-
// Check function argument
|
|
37
|
-
const needArgument: boolean =
|
|
38
|
-
operation.requestBody !== null || operation.parameters.length !== 0;
|
|
39
|
-
if (!!stmt.argument !== needArgument) {
|
|
40
|
-
// required argument, but is not
|
|
41
|
-
// or not required, but is provided
|
|
42
|
-
ctx.errors.push({
|
|
43
|
-
path: `${path}.argument`,
|
|
44
|
-
value: stmt.argument,
|
|
45
|
-
expected:
|
|
46
|
-
needArgument === true
|
|
47
|
-
? typia.reflect.name<AutoBeTest.IObjectLiteralExpression>()
|
|
48
|
-
: "null",
|
|
49
|
-
});
|
|
50
|
-
} else if (!!stmt.argument) {
|
|
51
|
-
// check properties
|
|
52
|
-
const keys: Set<string> = new Set(
|
|
53
|
-
stmt.argument.properties.map((p) => p.name),
|
|
54
|
-
);
|
|
55
|
-
for (const p of operation.parameters) // path parameters
|
|
56
|
-
if (keys.has(p.name) === false)
|
|
57
|
-
ctx.errors.push({
|
|
58
|
-
path: `${path}.argument.${p.name}`,
|
|
59
|
-
value: undefined,
|
|
60
|
-
expected: JSON.stringify(p.schema),
|
|
61
|
-
description: `Parameter "${p.name}" is required, and its type is ${JSON.stringify(p.schema)}. However, you did not provide it.`,
|
|
62
|
-
});
|
|
63
|
-
if (operation.requestBody !== null && keys.has("body") === false) {
|
|
64
|
-
// request body is not provided
|
|
65
|
-
ctx.errors.push({
|
|
66
|
-
path: `${path}.argument.body`,
|
|
67
|
-
value: undefined,
|
|
68
|
-
expected: operation.requestBody.typeName,
|
|
69
|
-
description: `Request body is required, and its type is "${operation.requestBody.typeName}". However, you did not provide it.`,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Check function return type
|
|
75
|
-
if (!!stmt.variableName !== !!operation.responseBody) {
|
|
76
|
-
ctx.errors.push({
|
|
77
|
-
path: `${path}.variableName`,
|
|
78
|
-
value: stmt.variableName,
|
|
79
|
-
...(stmt.variableName === null || stmt.variableName === undefined
|
|
80
|
-
? {
|
|
81
|
-
expected: "string",
|
|
82
|
-
description:
|
|
83
|
-
"You have to provide variable name. Every API operations that returning value require it, and it is used to store the response body.",
|
|
84
|
-
}
|
|
85
|
-
: {
|
|
86
|
-
expected: typia.reflect.name<AutoBeTest.IIdentifier>(),
|
|
87
|
-
description:
|
|
88
|
-
"You don't have to provide variable name. The API operation does not return any value, so it is not needed.",
|
|
89
|
-
}),
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
};
|
|
1
|
+
import { AutoBeOpenApi, AutoBeTest } from "@autobe/interface";
|
|
2
|
+
import { HashMap } from "tstl";
|
|
3
|
+
import typia from "typia";
|
|
4
|
+
|
|
5
|
+
import { IAutoBeTextValidateContext } from "./IAutoBeTextValidateContext";
|
|
6
|
+
|
|
7
|
+
export const validateTestApiOperateStatement = (
|
|
8
|
+
ctx: IAutoBeTextValidateContext,
|
|
9
|
+
stmt: AutoBeTest.IApiOperateStatement,
|
|
10
|
+
path: string,
|
|
11
|
+
): void => {
|
|
12
|
+
// Check API endpoint
|
|
13
|
+
const it: HashMap.Iterator<
|
|
14
|
+
AutoBeOpenApi.IEndpoint,
|
|
15
|
+
AutoBeOpenApi.IOperation
|
|
16
|
+
> = ctx.endpoints.find(stmt.endpoint);
|
|
17
|
+
if (it.equals(ctx.endpoints.end()) === true) {
|
|
18
|
+
ctx.errors.push({
|
|
19
|
+
path: `${path}.endpoint`,
|
|
20
|
+
value: stmt.endpoint,
|
|
21
|
+
expected: ctx.document.operations
|
|
22
|
+
.map((o) => `AutoBeOpenApi.IEndpoint<"${o.method}", "${o.path}">`)
|
|
23
|
+
.join(" | "),
|
|
24
|
+
description: [
|
|
25
|
+
"You can use only endpoints defined in the OpenAPI document.",
|
|
26
|
+
"",
|
|
27
|
+
ctx.document.operations
|
|
28
|
+
.map((o) => `- { method: "${o.method}", path: "${o.path}" }`)
|
|
29
|
+
.join("\n"),
|
|
30
|
+
].join("\n"),
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const operation: AutoBeOpenApi.IOperation = it.second;
|
|
35
|
+
|
|
36
|
+
// Check function argument
|
|
37
|
+
const needArgument: boolean =
|
|
38
|
+
operation.requestBody !== null || operation.parameters.length !== 0;
|
|
39
|
+
if (!!stmt.argument !== needArgument) {
|
|
40
|
+
// required argument, but is not
|
|
41
|
+
// or not required, but is provided
|
|
42
|
+
ctx.errors.push({
|
|
43
|
+
path: `${path}.argument`,
|
|
44
|
+
value: stmt.argument,
|
|
45
|
+
expected:
|
|
46
|
+
needArgument === true
|
|
47
|
+
? typia.reflect.name<AutoBeTest.IObjectLiteralExpression>()
|
|
48
|
+
: "null",
|
|
49
|
+
});
|
|
50
|
+
} else if (!!stmt.argument) {
|
|
51
|
+
// check properties
|
|
52
|
+
const keys: Set<string> = new Set(
|
|
53
|
+
stmt.argument.properties.map((p) => p.name),
|
|
54
|
+
);
|
|
55
|
+
for (const p of operation.parameters) // path parameters
|
|
56
|
+
if (keys.has(p.name) === false)
|
|
57
|
+
ctx.errors.push({
|
|
58
|
+
path: `${path}.argument.${p.name}`,
|
|
59
|
+
value: undefined,
|
|
60
|
+
expected: JSON.stringify(p.schema),
|
|
61
|
+
description: `Parameter "${p.name}" is required, and its type is ${JSON.stringify(p.schema)}. However, you did not provide it.`,
|
|
62
|
+
});
|
|
63
|
+
if (operation.requestBody !== null && keys.has("body") === false) {
|
|
64
|
+
// request body is not provided
|
|
65
|
+
ctx.errors.push({
|
|
66
|
+
path: `${path}.argument.body`,
|
|
67
|
+
value: undefined,
|
|
68
|
+
expected: operation.requestBody.typeName,
|
|
69
|
+
description: `Request body is required, and its type is "${operation.requestBody.typeName}". However, you did not provide it.`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Check function return type
|
|
75
|
+
if (!!stmt.variableName !== !!operation.responseBody) {
|
|
76
|
+
ctx.errors.push({
|
|
77
|
+
path: `${path}.variableName`,
|
|
78
|
+
value: stmt.variableName,
|
|
79
|
+
...(stmt.variableName === null || stmt.variableName === undefined
|
|
80
|
+
? {
|
|
81
|
+
expected: "string",
|
|
82
|
+
description:
|
|
83
|
+
"You have to provide variable name. Every API operations that returning value require it, and it is used to store the response body.",
|
|
84
|
+
}
|
|
85
|
+
: {
|
|
86
|
+
expected: typia.reflect.name<AutoBeTest.IIdentifier>(),
|
|
87
|
+
description:
|
|
88
|
+
"You don't have to provide variable name. The API operation does not return any value, so it is not needed.",
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
-
|
|
3
|
-
import { AutoBeTestExpressionValidator } from "./AutoBeTestExpressionValidator";
|
|
4
|
-
import { IAutoBeTextValidateContext } from "./IAutoBeTextValidateContext";
|
|
5
|
-
|
|
6
|
-
export const validateTestExpression = (
|
|
7
|
-
ctx: IAutoBeTextValidateContext,
|
|
8
|
-
item: AutoBeTest.IExpression,
|
|
9
|
-
path: string,
|
|
10
|
-
): void =>
|
|
1
|
+
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
+
|
|
3
|
+
import { AutoBeTestExpressionValidator } from "./AutoBeTestExpressionValidator";
|
|
4
|
+
import { IAutoBeTextValidateContext } from "./IAutoBeTextValidateContext";
|
|
5
|
+
|
|
6
|
+
export const validateTestExpression = (
|
|
7
|
+
ctx: IAutoBeTextValidateContext,
|
|
8
|
+
item: AutoBeTest.IExpression,
|
|
9
|
+
path: string,
|
|
10
|
+
): void =>
|
|
11
|
+
AutoBeTestExpressionValidator[item.type](
|
|
12
|
+
ctx,
|
|
13
|
+
// biome-ignore lint: intended
|
|
14
|
+
item as any,
|
|
15
|
+
path,
|
|
16
|
+
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IAutoBeTextValidateContext } from "./IAutoBeTextValidateContext";
|
|
2
|
-
import { validateTestStatement } from "./validateTestStatement";
|
|
3
|
-
|
|
4
|
-
export const validateTestFunction = (ctx: IAutoBeTextValidateContext): void =>
|
|
5
|
-
ctx.function.statements.forEach((stmt, i) =>
|
|
6
|
-
validateTestStatement(ctx, stmt, `$input.function.statements[${i}]`),
|
|
7
|
-
);
|
|
1
|
+
import { IAutoBeTextValidateContext } from "./IAutoBeTextValidateContext";
|
|
2
|
+
import { validateTestStatement } from "./validateTestStatement";
|
|
3
|
+
|
|
4
|
+
export const validateTestFunction = (ctx: IAutoBeTextValidateContext): void =>
|
|
5
|
+
ctx.function.statements.forEach((stmt, i) =>
|
|
6
|
+
validateTestStatement(ctx, stmt, `$input.function.statements[${i}]`),
|
|
7
|
+
);
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
-
|
|
3
|
-
import { AutoBeTestStatementValidator } from "./AutoBeTestStatementValidator";
|
|
4
|
-
import { IAutoBeTextValidateContext } from "./IAutoBeTextValidateContext";
|
|
5
|
-
|
|
6
|
-
export const validateTestStatement = (
|
|
7
|
-
ctx: IAutoBeTextValidateContext,
|
|
8
|
-
item: AutoBeTest.IStatement,
|
|
9
|
-
path: string,
|
|
10
|
-
): void =>
|
|
1
|
+
import { AutoBeTest } from "@autobe/interface";
|
|
2
|
+
|
|
3
|
+
import { AutoBeTestStatementValidator } from "./AutoBeTestStatementValidator";
|
|
4
|
+
import { IAutoBeTextValidateContext } from "./IAutoBeTextValidateContext";
|
|
5
|
+
|
|
6
|
+
export const validateTestStatement = (
|
|
7
|
+
ctx: IAutoBeTextValidateContext,
|
|
8
|
+
item: AutoBeTest.IStatement,
|
|
9
|
+
path: string,
|
|
10
|
+
): void =>
|
|
11
|
+
AutoBeTestStatementValidator[item.type](
|
|
12
|
+
ctx,
|
|
13
|
+
// biome-ignore lint: intended
|
|
14
|
+
item as any,
|
|
15
|
+
path,
|
|
16
|
+
);
|