@autobe/utils 0.29.1 → 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.
Files changed (63) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +261 -0
  3. package/lib/AutoBeEscaper.d.ts +4 -0
  4. package/lib/AutoBeEscaper.js +85 -0
  5. package/lib/AutoBeEscaper.js.map +1 -0
  6. package/lib/StringUtil.d.ts +1 -0
  7. package/lib/StringUtil.js +15 -36
  8. package/lib/StringUtil.js.map +1 -1
  9. package/lib/aggregate/AutoBeProcessAggregateFactory.js +9 -0
  10. package/lib/aggregate/AutoBeProcessAggregateFactory.js.map +1 -1
  11. package/lib/index.d.ts +1 -0
  12. package/lib/index.js +1 -0
  13. package/lib/index.js.map +1 -1
  14. package/lib/interface/AutoBeOpenApiEndpointComparator.d.ts +1 -0
  15. package/lib/interface/AutoBeOpenApiEndpointComparator.js +4 -0
  16. package/lib/interface/AutoBeOpenApiEndpointComparator.js.map +1 -1
  17. package/lib/interface/AutoBeOpenApiTypeChecker.d.ts +14 -0
  18. package/lib/interface/AutoBeOpenApiTypeChecker.js +67 -0
  19. package/lib/interface/AutoBeOpenApiTypeChecker.js.map +1 -1
  20. package/lib/interface/invertOpenApiDocument.d.ts +1 -1
  21. package/lib/interface/invertOpenApiDocument.js +22 -7
  22. package/lib/interface/invertOpenApiDocument.js.map +1 -1
  23. package/lib/interface/missedOpenApiSchemas.js +3 -3
  24. package/lib/interface/missedOpenApiSchemas.js.map +1 -1
  25. package/lib/interface/revertOpenApiAccessor.js +2 -2
  26. package/lib/interface/revertOpenApiAccessor.js.map +1 -1
  27. package/lib/interface/transformOpenApiDocument.d.ts +2 -2
  28. package/lib/interface/transformOpenApiDocument.js +14 -11
  29. package/lib/interface/transformOpenApiDocument.js.map +1 -1
  30. package/lib/prisma/writePrismaApplication.d.ts +2 -2
  31. package/lib/prisma/writePrismaApplication.js +75 -66
  32. package/lib/prisma/writePrismaApplication.js.map +1 -1
  33. package/lib/test/validateTestExpression.js +3 -1
  34. package/lib/test/validateTestExpression.js.map +1 -1
  35. package/lib/test/validateTestStatement.js +3 -1
  36. package/lib/test/validateTestStatement.js.map +1 -1
  37. package/package.json +5 -5
  38. package/src/ArrayUtil.ts +21 -21
  39. package/src/AutoBeEscaper.ts +83 -0
  40. package/src/MapUtil.ts +10 -10
  41. package/src/StringUtil.ts +34 -59
  42. package/src/aggregate/AutoBeFunctionCallingMetricFactory.ts +44 -44
  43. package/src/aggregate/AutoBeProcessAggregateFactory.ts +161 -152
  44. package/src/aggregate/TokenUsageComputer.ts +49 -49
  45. package/src/aggregate/index.ts +3 -3
  46. package/src/index.ts +10 -9
  47. package/src/interface/AutoBeOpenApiEndpointComparator.ts +27 -20
  48. package/src/interface/AutoBeOpenApiTypeChecker.ts +127 -43
  49. package/src/interface/index.ts +6 -6
  50. package/src/interface/invertOpenApiDocument.ts +80 -68
  51. package/src/interface/missedOpenApiSchemas.ts +25 -25
  52. package/src/interface/revertOpenApiAccessor.ts +25 -25
  53. package/src/interface/transformOpenApiDocument.ts +94 -91
  54. package/src/prisma/index.ts +1 -1
  55. package/src/prisma/writePrismaApplication.ts +456 -439
  56. package/src/test/AutoBeTestExpressionValidator.ts +253 -253
  57. package/src/test/AutoBeTestStatementValidator.ts +72 -72
  58. package/src/test/IAutoBeTextValidateContext.ts +10 -10
  59. package/src/test/index.ts +2 -2
  60. package/src/test/validateTestApiOperateStatement.ts +92 -92
  61. package/src/test/validateTestExpression.ts +16 -10
  62. package/src/test/validateTestFunction.ts +7 -7
  63. 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 => AutoBeTestExpressionValidator[item.type](ctx, item as any, path);
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 => AutoBeTestStatementValidator[item.type](ctx, item as any, path);
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
+ );