@autobe/utils 0.30.0-dev.20260315 → 0.30.1

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.
@@ -1,127 +1,127 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
- import { OpenApiTypeChecker } from "@typia/utils";
3
-
4
- export namespace AutoBeOpenApiTypeChecker {
5
- export const getKind = (schema: AutoBeOpenApi.IJsonSchema): string => {
6
- if (isReference(schema)) return "$ref";
7
- else if (isConstant(schema)) return JSON.stringify(schema.const);
8
- else if (isOneOf(schema))
9
- return schema.oneOf.map((s) => getKind(s)).join(" | ");
10
- else if (isArray(schema)) return `Array<${getKind(schema.items)}>`;
11
- else if (isObject(schema)) return "object";
12
- else if (isString(schema)) return "string";
13
- else if (isInteger(schema)) return "integer";
14
- else if (isNumber(schema)) return "number";
15
- else if (isBoolean(schema)) return "boolean";
16
- else if (isNull(schema)) return "null";
17
- schema satisfies never;
18
- return "unknown";
19
- };
20
-
21
- export const isArray = (
22
- schema: AutoBeOpenApi.IJsonSchema,
23
- ): schema is AutoBeOpenApi.IJsonSchema.IArray =>
24
- (schema as AutoBeOpenApi.IJsonSchema.IArray).type === "array";
25
-
26
- export const isObject = (
27
- schema: AutoBeOpenApi.IJsonSchema,
28
- ): schema is AutoBeOpenApi.IJsonSchema.IObject =>
29
- (schema as AutoBeOpenApi.IJsonSchema.IObject).type === "object";
30
-
31
- export const isOneOf = (
32
- schema: AutoBeOpenApi.IJsonSchema,
33
- ): schema is AutoBeOpenApi.IJsonSchema.IOneOf =>
34
- (schema as AutoBeOpenApi.IJsonSchema.IOneOf).oneOf !== undefined;
35
-
36
- export const isReference = (
37
- schema: AutoBeOpenApi.IJsonSchema,
38
- ): schema is AutoBeOpenApi.IJsonSchema.IReference =>
39
- (schema as AutoBeOpenApi.IJsonSchema.IReference).$ref !== undefined;
40
-
41
- export const isConstant = (
42
- schema: AutoBeOpenApi.IJsonSchema,
43
- ): schema is AutoBeOpenApi.IJsonSchema.IConstant =>
44
- (schema as AutoBeOpenApi.IJsonSchema.IConstant).const !== undefined;
45
-
46
- export const isBoolean = (
47
- schema: AutoBeOpenApi.IJsonSchema,
48
- ): schema is AutoBeOpenApi.IJsonSchema.IBoolean =>
49
- (schema as AutoBeOpenApi.IJsonSchema.IBoolean).type === "boolean";
50
-
51
- export const isInteger = (
52
- schema: AutoBeOpenApi.IJsonSchema,
53
- ): schema is AutoBeOpenApi.IJsonSchema.IInteger =>
54
- (schema as AutoBeOpenApi.IJsonSchema.IInteger).type === "integer";
55
-
56
- export const isNumber = (
57
- schema: AutoBeOpenApi.IJsonSchema,
58
- ): schema is AutoBeOpenApi.IJsonSchema.INumber =>
59
- (schema as AutoBeOpenApi.IJsonSchema.INumber).type === "number";
60
-
61
- export const isString = (
62
- schema: AutoBeOpenApi.IJsonSchema,
63
- ): schema is AutoBeOpenApi.IJsonSchema.IString =>
64
- (schema as AutoBeOpenApi.IJsonSchema.IString).type === "string";
65
-
66
- export const isNull = (
67
- schema: AutoBeOpenApi.IJsonSchema,
68
- ): schema is AutoBeOpenApi.IJsonSchema.INull =>
69
- (schema as AutoBeOpenApi.IJsonSchema.INull).type === "null";
70
-
71
- export const isNullable = (schema: AutoBeOpenApi.IJsonSchema): boolean =>
72
- isNull(schema) ||
73
- (isOneOf(schema) && schema.oneOf.some((sub) => isNull(sub)));
74
-
75
- export const visit = (props: {
76
- components: AutoBeOpenApi.IComponents;
77
- schema: AutoBeOpenApi.IJsonSchema;
78
- closure: (schema: AutoBeOpenApi.IJsonSchema, accessor: string) => void;
79
- }): void =>
80
- OpenApiTypeChecker.visit({
81
- components: props.components,
82
- schema: props.schema,
83
- closure: (schema, accessor) => {
84
- props.closure(schema as AutoBeOpenApi.IJsonSchema, accessor);
85
- },
86
- });
87
-
88
- export const skim = (props: {
89
- closure: (schema: AutoBeOpenApi.IJsonSchema, accessor: string) => void;
90
- schema: AutoBeOpenApi.IJsonSchema;
91
- accessor: string;
92
- }): void => {
93
- props.closure(props.schema, props.accessor);
94
- if (isOneOf(props.schema))
95
- props.schema.oneOf.forEach((sub, index) =>
96
- skim({
97
- closure: props.closure,
98
- schema: sub,
99
- accessor: `${props.accessor}.oneOf[${index}]`,
100
- }),
101
- );
102
- else if (isArray(props.schema))
103
- skim({
104
- closure: props.closure,
105
- schema: props.schema.items,
106
- accessor: `${props.accessor}.items`,
107
- });
108
- else if (isObject(props.schema)) {
109
- if (
110
- typeof props.schema.additionalProperties === "object" &&
111
- props.schema.additionalProperties !== null
112
- )
113
- skim({
114
- closure: props.closure,
115
- schema: props.schema.additionalProperties,
116
- accessor: `${props.accessor}.additionalProperties`,
117
- });
118
- for (const [key, value] of Object.entries(props.schema.properties))
119
- if (value)
120
- skim({
121
- closure: props.closure,
122
- schema: value,
123
- accessor: `${props.accessor}.properties[${JSON.stringify(key)}]`,
124
- });
125
- }
126
- };
127
- }
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { OpenApiTypeChecker } from "@typia/utils";
3
+
4
+ export namespace AutoBeOpenApiTypeChecker {
5
+ export const getKind = (schema: AutoBeOpenApi.IJsonSchema): string => {
6
+ if (isReference(schema)) return "$ref";
7
+ else if (isConstant(schema)) return JSON.stringify(schema.const);
8
+ else if (isOneOf(schema))
9
+ return schema.oneOf.map((s) => getKind(s)).join(" | ");
10
+ else if (isArray(schema)) return `Array<${getKind(schema.items)}>`;
11
+ else if (isObject(schema)) return "object";
12
+ else if (isString(schema)) return "string";
13
+ else if (isInteger(schema)) return "integer";
14
+ else if (isNumber(schema)) return "number";
15
+ else if (isBoolean(schema)) return "boolean";
16
+ else if (isNull(schema)) return "null";
17
+ schema satisfies never;
18
+ return "unknown";
19
+ };
20
+
21
+ export const isArray = (
22
+ schema: AutoBeOpenApi.IJsonSchema,
23
+ ): schema is AutoBeOpenApi.IJsonSchema.IArray =>
24
+ (schema as AutoBeOpenApi.IJsonSchema.IArray).type === "array";
25
+
26
+ export const isObject = (
27
+ schema: AutoBeOpenApi.IJsonSchema,
28
+ ): schema is AutoBeOpenApi.IJsonSchema.IObject =>
29
+ (schema as AutoBeOpenApi.IJsonSchema.IObject).type === "object";
30
+
31
+ export const isOneOf = (
32
+ schema: AutoBeOpenApi.IJsonSchema,
33
+ ): schema is AutoBeOpenApi.IJsonSchema.IOneOf =>
34
+ (schema as AutoBeOpenApi.IJsonSchema.IOneOf).oneOf !== undefined;
35
+
36
+ export const isReference = (
37
+ schema: AutoBeOpenApi.IJsonSchema,
38
+ ): schema is AutoBeOpenApi.IJsonSchema.IReference =>
39
+ (schema as AutoBeOpenApi.IJsonSchema.IReference).$ref !== undefined;
40
+
41
+ export const isConstant = (
42
+ schema: AutoBeOpenApi.IJsonSchema,
43
+ ): schema is AutoBeOpenApi.IJsonSchema.IConstant =>
44
+ (schema as AutoBeOpenApi.IJsonSchema.IConstant).const !== undefined;
45
+
46
+ export const isBoolean = (
47
+ schema: AutoBeOpenApi.IJsonSchema,
48
+ ): schema is AutoBeOpenApi.IJsonSchema.IBoolean =>
49
+ (schema as AutoBeOpenApi.IJsonSchema.IBoolean).type === "boolean";
50
+
51
+ export const isInteger = (
52
+ schema: AutoBeOpenApi.IJsonSchema,
53
+ ): schema is AutoBeOpenApi.IJsonSchema.IInteger =>
54
+ (schema as AutoBeOpenApi.IJsonSchema.IInteger).type === "integer";
55
+
56
+ export const isNumber = (
57
+ schema: AutoBeOpenApi.IJsonSchema,
58
+ ): schema is AutoBeOpenApi.IJsonSchema.INumber =>
59
+ (schema as AutoBeOpenApi.IJsonSchema.INumber).type === "number";
60
+
61
+ export const isString = (
62
+ schema: AutoBeOpenApi.IJsonSchema,
63
+ ): schema is AutoBeOpenApi.IJsonSchema.IString =>
64
+ (schema as AutoBeOpenApi.IJsonSchema.IString).type === "string";
65
+
66
+ export const isNull = (
67
+ schema: AutoBeOpenApi.IJsonSchema,
68
+ ): schema is AutoBeOpenApi.IJsonSchema.INull =>
69
+ (schema as AutoBeOpenApi.IJsonSchema.INull).type === "null";
70
+
71
+ export const isNullable = (schema: AutoBeOpenApi.IJsonSchema): boolean =>
72
+ isNull(schema) ||
73
+ (isOneOf(schema) && schema.oneOf.some((sub) => isNull(sub)));
74
+
75
+ export const visit = (props: {
76
+ components: AutoBeOpenApi.IComponents;
77
+ schema: AutoBeOpenApi.IJsonSchema;
78
+ closure: (schema: AutoBeOpenApi.IJsonSchema, accessor: string) => void;
79
+ }): void =>
80
+ OpenApiTypeChecker.visit({
81
+ components: props.components,
82
+ schema: props.schema,
83
+ closure: (schema, accessor) => {
84
+ props.closure(schema as AutoBeOpenApi.IJsonSchema, accessor);
85
+ },
86
+ });
87
+
88
+ export const skim = (props: {
89
+ closure: (schema: AutoBeOpenApi.IJsonSchema, accessor: string) => void;
90
+ schema: AutoBeOpenApi.IJsonSchema;
91
+ accessor: string;
92
+ }): void => {
93
+ props.closure(props.schema, props.accessor);
94
+ if (isOneOf(props.schema))
95
+ props.schema.oneOf.forEach((sub, index) =>
96
+ skim({
97
+ closure: props.closure,
98
+ schema: sub,
99
+ accessor: `${props.accessor}.oneOf[${index}]`,
100
+ }),
101
+ );
102
+ else if (isArray(props.schema))
103
+ skim({
104
+ closure: props.closure,
105
+ schema: props.schema.items,
106
+ accessor: `${props.accessor}.items`,
107
+ });
108
+ else if (isObject(props.schema)) {
109
+ if (
110
+ typeof props.schema.additionalProperties === "object" &&
111
+ props.schema.additionalProperties !== null
112
+ )
113
+ skim({
114
+ closure: props.closure,
115
+ schema: props.schema.additionalProperties,
116
+ accessor: `${props.accessor}.additionalProperties`,
117
+ });
118
+ for (const [key, value] of Object.entries(props.schema.properties))
119
+ if (value)
120
+ skim({
121
+ closure: props.closure,
122
+ schema: value,
123
+ accessor: `${props.accessor}.properties[${JSON.stringify(key)}]`,
124
+ });
125
+ }
126
+ };
127
+ }
@@ -1,6 +1,6 @@
1
- export * from "./AutoBeOpenApiEndpointComparator";
2
- export * from "./AutoBeOpenApiTypeChecker";
3
- export * from "./invertOpenApiDocument";
4
- export * from "./revertOpenApiAccessor";
5
- export * from "./transformOpenApiDocument";
6
- export * from "./missedOpenApiSchemas";
1
+ export * from "./AutoBeOpenApiEndpointComparator";
2
+ export * from "./AutoBeOpenApiTypeChecker";
3
+ export * from "./invertOpenApiDocument";
4
+ export * from "./revertOpenApiAccessor";
5
+ export * from "./transformOpenApiDocument";
6
+ export * from "./missedOpenApiSchemas";
@@ -1,80 +1,80 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
- import { IHttpMigrateApplication, OpenApi } from "@typia/interface";
3
- import { HttpMigration, OpenApiTypeChecker } from "@typia/utils";
4
-
5
- export function invertOpenApiDocument(
6
- document: OpenApi.IDocument,
7
- ): AutoBeOpenApi.IDocument {
8
- const app: IHttpMigrateApplication = HttpMigration.application(document);
9
- return {
10
- operations: app.routes
11
- .filter((r) => r.query === null)
12
- .map(
13
- (r) =>
14
- ({
15
- authorizationType: null,
16
- method: r.method as "post",
17
- path: r.path,
18
- description:
19
- writeDescription(r.operation()) ?? empty("description"),
20
- specification: r.operation()
21
- ? // biome-ignore lint: intended
22
- ((r.operation() as any)["x-autobe-specification"] ??
23
- empty("x-autobe-specification"))
24
- : empty("x-autobe-specification"),
25
- accessor: r.accessor,
26
- parameters: r.parameters.map(
27
- (p) =>
28
- ({
29
- name: p.name,
30
- description:
31
- p.parameter().description ?? empty("description"),
32
- // biome-ignore lint: intended
33
- schema: p.schema as any,
34
- }) satisfies AutoBeOpenApi.IParameter,
35
- ),
36
- requestBody:
37
- r.body?.type === "application/json" &&
38
- OpenApiTypeChecker.isReference(r.body.schema)
39
- ? {
40
- description: r.body.description() ?? empty("description"),
41
- typeName: r.body.schema.$ref.split("/").pop()!,
42
- }
43
- : null,
44
- responseBody:
45
- r.success?.type === "application/json" &&
46
- OpenApiTypeChecker.isReference(r.success.schema)
47
- ? {
48
- description:
49
- r.success.description() ?? empty("description"),
50
- typeName: r.success.schema.$ref.split("/").pop()!,
51
- }
52
- : null,
53
- authorizationActor: null,
54
- name: r.accessor.at(-1)!,
55
- prerequisites: [],
56
- }) satisfies AutoBeOpenApi.IOperation,
57
- ),
58
- components: {
59
- schemas: (document.components?.schemas ?? {}) as Record<
60
- string,
61
- AutoBeOpenApi.IJsonSchemaDescriptive
62
- >,
63
- authorizations: [],
64
- },
65
- };
66
- }
67
-
68
- function writeDescription(operation: OpenApi.IOperation): string | undefined {
69
- if (operation.summary === undefined && operation.description === undefined)
70
- return undefined;
71
- if (operation.summary === undefined) return operation.description;
72
- else if (operation.description === undefined) return operation.summary;
73
- else if (operation.description.startsWith(operation.summary))
74
- return operation.description;
75
- return `${operation.summary}${operation.summary.endsWith(".") ? "" : "."}\n\n${operation.description}`;
76
- }
77
-
78
- function empty(key: string): string {
79
- return `Describe ${key} as much as possible with clear and concise words.`;
80
- }
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { IHttpMigrateApplication, OpenApi } from "@typia/interface";
3
+ import { HttpMigration, OpenApiTypeChecker } from "@typia/utils";
4
+
5
+ export function invertOpenApiDocument(
6
+ document: OpenApi.IDocument,
7
+ ): AutoBeOpenApi.IDocument {
8
+ const app: IHttpMigrateApplication = HttpMigration.application(document);
9
+ return {
10
+ operations: app.routes
11
+ .filter((r) => r.query === null)
12
+ .map(
13
+ (r) =>
14
+ ({
15
+ authorizationType: null,
16
+ method: r.method as "post",
17
+ path: r.path,
18
+ description:
19
+ writeDescription(r.operation()) ?? empty("description"),
20
+ specification: r.operation()
21
+ ? // biome-ignore lint: intended
22
+ ((r.operation() as any)["x-autobe-specification"] ??
23
+ empty("x-autobe-specification"))
24
+ : empty("x-autobe-specification"),
25
+ accessor: r.accessor,
26
+ parameters: r.parameters.map(
27
+ (p) =>
28
+ ({
29
+ name: p.name,
30
+ description:
31
+ p.parameter().description ?? empty("description"),
32
+ // biome-ignore lint: intended
33
+ schema: p.schema as any,
34
+ }) satisfies AutoBeOpenApi.IParameter,
35
+ ),
36
+ requestBody:
37
+ r.body?.type === "application/json" &&
38
+ OpenApiTypeChecker.isReference(r.body.schema)
39
+ ? {
40
+ description: r.body.description() ?? empty("description"),
41
+ typeName: r.body.schema.$ref.split("/").pop()!,
42
+ }
43
+ : null,
44
+ responseBody:
45
+ r.success?.type === "application/json" &&
46
+ OpenApiTypeChecker.isReference(r.success.schema)
47
+ ? {
48
+ description:
49
+ r.success.description() ?? empty("description"),
50
+ typeName: r.success.schema.$ref.split("/").pop()!,
51
+ }
52
+ : null,
53
+ authorizationActor: null,
54
+ name: r.accessor.at(-1)!,
55
+ prerequisites: [],
56
+ }) satisfies AutoBeOpenApi.IOperation,
57
+ ),
58
+ components: {
59
+ schemas: (document.components?.schemas ?? {}) as Record<
60
+ string,
61
+ AutoBeOpenApi.IJsonSchemaDescriptive
62
+ >,
63
+ authorizations: [],
64
+ },
65
+ };
66
+ }
67
+
68
+ function writeDescription(operation: OpenApi.IOperation): string | undefined {
69
+ if (operation.summary === undefined && operation.description === undefined)
70
+ return undefined;
71
+ if (operation.summary === undefined) return operation.description;
72
+ else if (operation.description === undefined) return operation.summary;
73
+ else if (operation.description.startsWith(operation.summary))
74
+ return operation.description;
75
+ return `${operation.summary}${operation.summary.endsWith(".") ? "" : "."}\n\n${operation.description}`;
76
+ }
77
+
78
+ function empty(key: string): string {
79
+ return `Describe ${key} as much as possible with clear and concise words.`;
80
+ }
@@ -1,25 +1,25 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
- import { OpenApiTypeChecker } from "@typia/utils";
3
-
4
- export const missedOpenApiSchemas = (
5
- document: AutoBeOpenApi.IDocument,
6
- ): string[] => {
7
- const missed: Set<string> = new Set();
8
- const check = (name: string) => {
9
- if (document.components.schemas[name] === undefined) missed.add(name);
10
- };
11
- for (const op of document.operations) {
12
- if (op.requestBody !== null) check(op.requestBody.typeName);
13
- if (op.responseBody !== null) check(op.responseBody.typeName);
14
- }
15
- for (const value of Object.values(document.components.schemas))
16
- OpenApiTypeChecker.visit({
17
- components: document.components,
18
- schema: value,
19
- closure: (next) => {
20
- if (OpenApiTypeChecker.isReference(next))
21
- check(next.$ref.split("/").pop()!);
22
- },
23
- });
24
- return Array.from(missed);
25
- };
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { OpenApiTypeChecker } from "@typia/utils";
3
+
4
+ export const missedOpenApiSchemas = (
5
+ document: AutoBeOpenApi.IDocument,
6
+ ): string[] => {
7
+ const missed: Set<string> = new Set();
8
+ const check = (name: string) => {
9
+ if (document.components.schemas[name] === undefined) missed.add(name);
10
+ };
11
+ for (const op of document.operations) {
12
+ if (op.requestBody !== null) check(op.requestBody.typeName);
13
+ if (op.responseBody !== null) check(op.responseBody.typeName);
14
+ }
15
+ for (const value of Object.values(document.components.schemas))
16
+ OpenApiTypeChecker.visit({
17
+ components: document.components,
18
+ schema: value,
19
+ closure: (next) => {
20
+ if (OpenApiTypeChecker.isReference(next))
21
+ check(next.$ref.split("/").pop()!);
22
+ },
23
+ });
24
+ return Array.from(missed);
25
+ };
@@ -1,25 +1,25 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
2
- import {
3
- IHttpMigrateApplication,
4
- IHttpMigrateRoute,
5
- OpenApi,
6
- } from "@typia/interface";
7
- import { HttpMigration } from "@typia/utils";
8
-
9
- import { transformOpenApiDocument } from "./transformOpenApiDocument";
10
-
11
- export const revertOpenApiAccessor = (
12
- document: AutoBeOpenApi.IDocument,
13
- ): void => {
14
- const regular: OpenApi.IDocument = transformOpenApiDocument(document);
15
- const migrate: IHttpMigrateApplication = HttpMigration.application(regular);
16
- for (const op of document.operations) {
17
- const route: IHttpMigrateRoute | undefined = migrate.routes.find(
18
- (r) => r.method === op.method && r.path === op.path,
19
- );
20
- if (route === undefined) continue;
21
- if (route.accessor.length !== 0 && route.accessor.at(-1) !== op.name)
22
- op.name = route.accessor.at(-1)!;
23
- op.accessor = route.accessor;
24
- }
25
- };
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import {
3
+ IHttpMigrateApplication,
4
+ IHttpMigrateRoute,
5
+ OpenApi,
6
+ } from "@typia/interface";
7
+ import { HttpMigration } from "@typia/utils";
8
+
9
+ import { transformOpenApiDocument } from "./transformOpenApiDocument";
10
+
11
+ export const revertOpenApiAccessor = (
12
+ document: AutoBeOpenApi.IDocument,
13
+ ): void => {
14
+ const regular: OpenApi.IDocument = transformOpenApiDocument(document);
15
+ const migrate: IHttpMigrateApplication = HttpMigration.application(regular);
16
+ for (const op of document.operations) {
17
+ const route: IHttpMigrateRoute | undefined = migrate.routes.find(
18
+ (r) => r.method === op.method && r.path === op.path,
19
+ );
20
+ if (route === undefined) continue;
21
+ if (route.accessor.length !== 0 && route.accessor.at(-1) !== op.name)
22
+ op.name = route.accessor.at(-1)!;
23
+ op.accessor = route.accessor;
24
+ }
25
+ };