svelte-reflector 1.0.52 → 1.1.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.
Files changed (110) hide show
  1. package/dist/core/Method.d.ts +41 -0
  2. package/dist/core/Method.js +19 -0
  3. package/dist/core/MethodApiTypeAnalyzer.d.ts +9 -0
  4. package/dist/core/MethodApiTypeAnalyzer.js +19 -0
  5. package/dist/core/MethodBodyAnalyzer.d.ts +11 -0
  6. package/dist/core/MethodBodyAnalyzer.js +78 -0
  7. package/dist/core/MethodBuilder.d.ts +11 -0
  8. package/dist/core/MethodBuilder.js +50 -0
  9. package/dist/core/MethodEndpointBuilder.d.ts +6 -0
  10. package/dist/core/MethodEndpointBuilder.js +21 -0
  11. package/dist/core/MethodRequestAnalyzer.d.ts +16 -0
  12. package/dist/core/MethodRequestAnalyzer.js +62 -0
  13. package/dist/core/MethodResponseAnalyzer.d.ts +12 -0
  14. package/dist/core/MethodResponseAnalyzer.js +96 -0
  15. package/dist/core/Module.d.ts +16 -0
  16. package/dist/core/Module.js +14 -0
  17. package/dist/core/ModuleBuilder.d.ts +11 -0
  18. package/dist/core/ModuleBuilder.js +45 -0
  19. package/dist/core/ModuleClassBuilder.d.ts +12 -0
  20. package/dist/core/ModuleClassBuilder.js +74 -0
  21. package/dist/core/ModuleConstructorBuilder.d.ts +7 -0
  22. package/dist/core/ModuleConstructorBuilder.js +20 -0
  23. package/dist/core/ModuleFileBuilder.d.ts +19 -0
  24. package/dist/core/ModuleFileBuilder.js +49 -0
  25. package/dist/core/ModuleFormBuilder.d.ts +13 -0
  26. package/dist/core/ModuleFormBuilder.js +34 -0
  27. package/dist/core/ModuleImports.d.ts +16 -0
  28. package/dist/core/ModuleImports.js +47 -0
  29. package/dist/core/ModuleMethodProcessor.d.ts +28 -0
  30. package/dist/core/ModuleMethodProcessor.js +75 -0
  31. package/dist/core/ModuleParamProcessor.d.ts +24 -0
  32. package/dist/core/ModuleParamProcessor.js +42 -0
  33. package/dist/core/ModuleParameterProcessor.d.ts +19 -0
  34. package/dist/core/ModuleParameterProcessor.js +68 -0
  35. package/dist/core/ModuleStateBuilder.d.ts +10 -0
  36. package/dist/core/ModuleStateBuilder.js +21 -0
  37. package/dist/core/index.d.ts +13 -0
  38. package/dist/core/index.js +15 -0
  39. package/dist/enum.class.d.ts +10 -0
  40. package/dist/enum.class.js +15 -0
  41. package/dist/generators/MethodApiCallBuilder.d.ts +14 -0
  42. package/dist/generators/MethodApiCallBuilder.js +98 -0
  43. package/dist/generators/MethodGenerator.d.ts +10 -0
  44. package/dist/generators/MethodGenerator.js +75 -0
  45. package/dist/generators/MethodPropsBuilder.d.ts +5 -0
  46. package/dist/generators/MethodPropsBuilder.js +19 -0
  47. package/dist/generators/ModuleGenerator.d.ts +16 -0
  48. package/dist/generators/ModuleGenerator.js +133 -0
  49. package/dist/generators/QueryBuilderGenerator.d.ts +3 -0
  50. package/dist/generators/QueryBuilderGenerator.js +26 -0
  51. package/dist/generators/ReflectorClasses.d.ts +3 -0
  52. package/dist/generators/ReflectorClasses.js +46 -0
  53. package/dist/generators/ReflectorFileGenerator.d.ts +8 -0
  54. package/dist/generators/ReflectorFileGenerator.js +32 -0
  55. package/dist/generators/ReflectorFunctions.d.ts +3 -0
  56. package/dist/generators/ReflectorFunctions.js +58 -0
  57. package/dist/generators/ReflectorTypes.d.ts +3 -0
  58. package/dist/generators/ReflectorTypes.js +21 -0
  59. package/dist/generators/index.d.ts +3 -0
  60. package/dist/generators/index.js +3 -0
  61. package/dist/helpers/helpers.d.ts +3 -1
  62. package/dist/helpers/helpers.js +15 -40
  63. package/dist/main.js +0 -3
  64. package/dist/method.d.ts +18 -19
  65. package/dist/method.js +23 -192
  66. package/dist/models/ArrayProperty.d.ts +23 -0
  67. package/dist/models/ArrayProperty.js +62 -0
  68. package/dist/models/EnumClass.d.ts +10 -0
  69. package/dist/models/EnumClass.js +15 -0
  70. package/dist/models/EnumProperty.d.ts +19 -0
  71. package/dist/models/EnumProperty.js +41 -0
  72. package/dist/models/ObjectProperty.d.ts +15 -0
  73. package/dist/models/ObjectProperty.js +25 -0
  74. package/dist/models/PrimitiveProperty.d.ts +20 -0
  75. package/dist/models/PrimitiveProperty.js +64 -0
  76. package/dist/models/Property.d.ts +19 -0
  77. package/dist/models/Property.js +24 -0
  78. package/dist/models/PropertyBuilder.d.ts +22 -0
  79. package/dist/models/PropertyBuilder.js +89 -0
  80. package/dist/models/index.d.ts +7 -0
  81. package/dist/models/index.js +7 -0
  82. package/dist/module.d.ts +8 -18
  83. package/dist/module.js +52 -219
  84. package/dist/props/array.property.d.ts +5 -2
  85. package/dist/props/array.property.js +28 -10
  86. package/dist/props/enum.property.d.ts +2 -1
  87. package/dist/props/enum.property.js +4 -0
  88. package/dist/props/primitive.property.d.ts +4 -4
  89. package/dist/props/primitive.property.js +9 -6
  90. package/dist/reflector.js +98 -5
  91. package/dist/schema.js +11 -8
  92. package/dist/types/open-api-spec.interface.d.ts +1 -1
  93. package/dist/types/types.d.ts +5 -0
  94. package/dist/utils/EndpointUtils.d.ts +4 -0
  95. package/dist/utils/EndpointUtils.js +34 -0
  96. package/dist/utils/EnumUtils.d.ts +2 -0
  97. package/dist/utils/EnumUtils.js +9 -0
  98. package/dist/utils/FileUtils.d.ts +3 -0
  99. package/dist/utils/FileUtils.js +20 -0
  100. package/dist/utils/NamingUtils.d.ts +4 -0
  101. package/dist/utils/NamingUtils.js +19 -0
  102. package/dist/utils/SchemaUtils.d.ts +4 -0
  103. package/dist/utils/SchemaUtils.js +18 -0
  104. package/dist/utils/StringUtils.d.ts +5 -0
  105. package/dist/utils/StringUtils.js +41 -0
  106. package/dist/utils/ValidatorUtils.d.ts +6 -0
  107. package/dist/utils/ValidatorUtils.js +70 -0
  108. package/dist/utils/index.d.ts +7 -0
  109. package/dist/utils/index.js +7 -0
  110. package/package.json +1 -1
@@ -0,0 +1,41 @@
1
+ import type { ApiType } from "../types/types.js";
2
+ import type { PrimitiveProp } from "../props/primitive.property.js";
3
+ import type { ArrayProp } from "../props/array.property.js";
4
+ import type { EnumProp } from "../props/enum.property.js";
5
+ import type { ReflectorRequestType } from "../request.js";
6
+ export type AttributeProp = PrimitiveProp | ArrayProp | EnumProp;
7
+ export interface MethodAnalyzers {
8
+ request: {
9
+ bodyType: string | undefined;
10
+ responseType: string | null;
11
+ attributeType: ReflectorRequestType;
12
+ apiType: ApiType;
13
+ parameters: any[];
14
+ hasEnumResponse: boolean;
15
+ };
16
+ props: {
17
+ paths: PrimitiveProp[];
18
+ headers: PrimitiveProp[];
19
+ querys: AttributeProp[];
20
+ cookies: PrimitiveProp[];
21
+ };
22
+ }
23
+ export declare class Method {
24
+ name: string;
25
+ endpoint: string;
26
+ apiType: ApiType;
27
+ attributeType: ReflectorRequestType;
28
+ description: string | undefined;
29
+ analyzers: MethodAnalyzers;
30
+ responseTypeInterface: string;
31
+ isValid: boolean;
32
+ constructor(params: {
33
+ name: string;
34
+ endpoint: string;
35
+ apiType: ApiType;
36
+ attributeType: ReflectorRequestType;
37
+ description: string | undefined;
38
+ analyzers: MethodAnalyzers;
39
+ responseTypeInterface: string;
40
+ });
41
+ }
@@ -0,0 +1,19 @@
1
+ export class Method {
2
+ name;
3
+ endpoint;
4
+ apiType;
5
+ attributeType;
6
+ description = undefined;
7
+ analyzers;
8
+ responseTypeInterface;
9
+ isValid = true;
10
+ constructor(params) {
11
+ this.name = params.name;
12
+ this.endpoint = params.endpoint;
13
+ this.apiType = params.apiType;
14
+ this.attributeType = params.attributeType;
15
+ this.description = params.description;
16
+ this.analyzers = params.analyzers;
17
+ this.responseTypeInterface = params.responseTypeInterface;
18
+ }
19
+ }
@@ -0,0 +1,9 @@
1
+ import type { ReflectorOperation, ApiType } from "../types/types.js";
2
+ import type { ReflectorRequestType } from "../request.js";
3
+ export declare class MethodApiTypeAnalyzer {
4
+ analyze(operation: ReflectorOperation): {
5
+ apiType: ApiType;
6
+ attributeType: ReflectorRequestType;
7
+ };
8
+ private inferAttributeType;
9
+ }
@@ -0,0 +1,19 @@
1
+ export class MethodApiTypeAnalyzer {
2
+ analyze(operation) {
3
+ const apiType = operation.apiMethod;
4
+ const attributeType = this.inferAttributeType(operation);
5
+ return { apiType, attributeType };
6
+ }
7
+ inferAttributeType(operation) {
8
+ const method = operation.apiMethod;
9
+ if (method === "post" || method === "put" || method === "patch") {
10
+ return "form";
11
+ }
12
+ if (method === "get") {
13
+ const params = operation.parameters ?? [];
14
+ const hasPage = params.some((p) => !("$ref" in p) && p.name === "page");
15
+ return hasPage ? "list" : "entity";
16
+ }
17
+ return "other";
18
+ }
19
+ }
@@ -0,0 +1,11 @@
1
+ import type { ReflectorOperation } from "../types/types.js";
2
+ export declare class MethodBodyAnalyzer {
3
+ bodyType?: string;
4
+ analyze(operation: ReflectorOperation): string | undefined;
5
+ private getTypeFromRequestBody;
6
+ private isRef;
7
+ private componentName;
8
+ private getFromContent;
9
+ private typeFromSchemaOrType;
10
+ private typeFromProperties;
11
+ }
@@ -0,0 +1,78 @@
1
+ export class MethodBodyAnalyzer {
2
+ bodyType;
3
+ analyze(operation) {
4
+ const body = this.getTypeFromRequestBody(operation.requestBody);
5
+ if (body)
6
+ this.bodyType = body;
7
+ return this.bodyType;
8
+ }
9
+ getTypeFromRequestBody(requestBody) {
10
+ if (!requestBody || this.isRef(requestBody))
11
+ return undefined;
12
+ const schemaOrType = this.getFromContent(requestBody.content);
13
+ return this.typeFromSchemaOrType(schemaOrType);
14
+ }
15
+ isRef(v) {
16
+ return !!v && typeof v === "object" && "$ref" in v;
17
+ }
18
+ componentName(refObj) {
19
+ const parts = refObj.$ref.split("/");
20
+ return parts[parts.length - 1];
21
+ }
22
+ getFromContent(content) {
23
+ if (!content || this.isRef(content))
24
+ return undefined;
25
+ const first = Object.values(content)[0];
26
+ const schema = first?.schema;
27
+ if (!schema)
28
+ return undefined;
29
+ if (this.isRef(schema))
30
+ return this.componentName(schema);
31
+ return schema;
32
+ }
33
+ typeFromSchemaOrType(schemaOrType) {
34
+ if (!schemaOrType)
35
+ return undefined;
36
+ if (typeof schemaOrType === "string")
37
+ return schemaOrType;
38
+ const schema = schemaOrType;
39
+ if (schema.enum) {
40
+ const enumName = schema["x-enumNames"];
41
+ if (Array.isArray(enumName))
42
+ return schema.title || "string";
43
+ return schema.title || enumName || "string";
44
+ }
45
+ const allOfFirst = schema.allOf?.[0];
46
+ if (allOfFirst && !this.isRef(allOfFirst)) {
47
+ const t = this.typeFromProperties(allOfFirst.properties);
48
+ if (t !== undefined)
49
+ return t;
50
+ }
51
+ if (schema.type === "array" && schema.items) {
52
+ const items = schema.items;
53
+ if (this.isRef(items))
54
+ return this.componentName(items);
55
+ if (items.enum)
56
+ return items.title || items["x-enumNames"] || "string";
57
+ return items.type;
58
+ }
59
+ if (schema.properties) {
60
+ const t = this.typeFromProperties(schema.properties);
61
+ if (t !== undefined)
62
+ return t;
63
+ }
64
+ return schema.type;
65
+ }
66
+ typeFromProperties(properties) {
67
+ if (!properties?.["data"])
68
+ return undefined;
69
+ const data = properties["data"];
70
+ if (this.isRef(data))
71
+ return this.componentName(data);
72
+ if (data.type === "any")
73
+ return undefined;
74
+ if (data.enum)
75
+ return data.title || data["x-enumNames"] || "string";
76
+ return data.type;
77
+ }
78
+ }
@@ -0,0 +1,11 @@
1
+ import type { ReflectorOperation } from "../types/types.js";
2
+ import { Method } from "./Method.js";
3
+ export declare class MethodBuilder {
4
+ private readonly requestAnalyzer;
5
+ private readonly responseAnalyzer;
6
+ private readonly apiTypeAnalyzer;
7
+ private readonly bodyAnalyzer;
8
+ build(operation: ReflectorOperation, moduleName: string): Method;
9
+ private extractName;
10
+ private buildResponseTypeInterface;
11
+ }
@@ -0,0 +1,50 @@
1
+ import { Method } from "./Method.js";
2
+ import { MethodRequestAnalyzer } from "./MethodRequestAnalyzer.js";
3
+ import { MethodResponseAnalyzer } from "./MethodResponseAnalyzer.js";
4
+ import { MethodApiTypeAnalyzer } from "./MethodApiTypeAnalyzer.js";
5
+ import { MethodBodyAnalyzer } from "./MethodBodyAnalyzer.js";
6
+ export class MethodBuilder {
7
+ requestAnalyzer = new MethodRequestAnalyzer();
8
+ responseAnalyzer = new MethodResponseAnalyzer();
9
+ apiTypeAnalyzer = new MethodApiTypeAnalyzer();
10
+ bodyAnalyzer = new MethodBodyAnalyzer();
11
+ build(operation, moduleName) {
12
+ const name = this.extractName(operation);
13
+ const description = operation.description ?? operation.summary;
14
+ const { apiType, attributeType } = this.apiTypeAnalyzer.analyze(operation);
15
+ this.requestAnalyzer.analyze(operation, moduleName);
16
+ this.responseAnalyzer.analyze(operation.responses);
17
+ const bodyType = this.bodyAnalyzer.analyze(operation);
18
+ const props = this.requestAnalyzer.getProps();
19
+ const analyzers = {
20
+ request: {
21
+ bodyType,
22
+ responseType: this.responseAnalyzer.responseType,
23
+ attributeType,
24
+ apiType,
25
+ parameters: this.requestAnalyzer.paths,
26
+ hasEnumResponse: this.responseAnalyzer.hasEnumResponse,
27
+ },
28
+ props,
29
+ };
30
+ const responseTypeInterface = this.buildResponseTypeInterface(analyzers.request.responseType);
31
+ return new Method({
32
+ name,
33
+ endpoint: operation.endpoint,
34
+ apiType,
35
+ attributeType,
36
+ description,
37
+ analyzers,
38
+ responseTypeInterface,
39
+ });
40
+ }
41
+ extractName(operation) {
42
+ const extracted = operation.operationId?.split("_")[1];
43
+ if (extracted === "list")
44
+ return "listAll";
45
+ return extracted ?? this.apiTypeAnalyzer.analyze(operation).apiType;
46
+ }
47
+ buildResponseTypeInterface(responseType) {
48
+ return responseType ? `${responseType}Interface` : "null";
49
+ }
50
+ }
@@ -0,0 +1,6 @@
1
+ export declare class MethodEndpointBuilder {
2
+ build(rawEndpoint: string, paths: {
3
+ name: string;
4
+ }[]): string;
5
+ private processEndpoint;
6
+ }
@@ -0,0 +1,21 @@
1
+ export class MethodEndpointBuilder {
2
+ build(rawEndpoint, paths) {
3
+ const processed = this.processEndpoint(rawEndpoint);
4
+ const a = "`";
5
+ return `${a}${processed}${a}`;
6
+ }
7
+ processEndpoint(rawEndpoint) {
8
+ return rawEndpoint
9
+ .split("/")
10
+ .filter(Boolean)
11
+ .map((str) => {
12
+ const match = /^\{(.+)\}$/.exec(str);
13
+ if (match) {
14
+ const key = match[1];
15
+ return `\${${key}}`;
16
+ }
17
+ return str;
18
+ })
19
+ .join("/");
20
+ }
21
+ }
@@ -0,0 +1,16 @@
1
+ import type { ReflectorOperation, AttributeProp } from "../types/types.js";
2
+ import type { PrimitiveProp } from "../props/primitive.property.js";
3
+ export declare class MethodRequestAnalyzer {
4
+ paths: PrimitiveProp[];
5
+ headers: PrimitiveProp[];
6
+ querys: AttributeProp[];
7
+ cookies: PrimitiveProp[];
8
+ analyze(operation: ReflectorOperation, moduleName: string): void;
9
+ private processQueryParam;
10
+ getProps(): {
11
+ paths: PrimitiveProp[];
12
+ headers: PrimitiveProp[];
13
+ querys: AttributeProp[];
14
+ cookies: PrimitiveProp[];
15
+ };
16
+ }
@@ -0,0 +1,62 @@
1
+ import { PrimitiveProp as PrimitivePropClass } from "../props/primitive.property.js";
2
+ import { ArrayProp as ArrayPropClass } from "../props/array.property.js";
3
+ import { EnumProp as EnumPropClass } from "../props/enum.property.js";
4
+ export class MethodRequestAnalyzer {
5
+ paths = [];
6
+ headers = [];
7
+ querys = [];
8
+ cookies = [];
9
+ analyze(operation, moduleName) {
10
+ if (!operation.parameters || operation.parameters.length === 0)
11
+ return;
12
+ for (const object of operation.parameters) {
13
+ if ("$ref" in object)
14
+ continue;
15
+ if (!object.schema)
16
+ continue;
17
+ const { required, name, schema, in: inParam } = object;
18
+ if ("$ref" in schema)
19
+ continue;
20
+ const isRequired = !!required;
21
+ const baseProps = { name, required: isRequired, schemaObject: schema, validator: undefined, isParam: true };
22
+ if (inParam === "query") {
23
+ this.processQueryParam(name, schema, moduleName, isRequired);
24
+ }
25
+ else if (inParam === "header") {
26
+ this.headers.push(new PrimitivePropClass(baseProps));
27
+ }
28
+ else if (inParam === "path") {
29
+ this.paths.push(new PrimitivePropClass(baseProps));
30
+ }
31
+ else if (inParam === "cookie") {
32
+ this.cookies.push(new PrimitivePropClass(baseProps));
33
+ }
34
+ }
35
+ }
36
+ processQueryParam(name, schema, moduleName, isRequired) {
37
+ if (schema.type === "array") {
38
+ this.querys.push(new ArrayPropClass({
39
+ name,
40
+ schemaObject: schema,
41
+ schemaName: moduleName,
42
+ isParam: true,
43
+ isEnum: false,
44
+ required: isRequired,
45
+ }));
46
+ return;
47
+ }
48
+ if (schema.enum) {
49
+ this.querys.push(new EnumPropClass({ name, required: isRequired, enums: schema.enum, isParam: true, entityName: moduleName }));
50
+ return;
51
+ }
52
+ this.querys.push(new PrimitivePropClass({ name, required: isRequired, schemaObject: schema, validator: undefined, isParam: true }));
53
+ }
54
+ getProps() {
55
+ return {
56
+ paths: this.paths,
57
+ headers: this.headers,
58
+ querys: this.querys,
59
+ cookies: this.cookies,
60
+ };
61
+ }
62
+ }
@@ -0,0 +1,12 @@
1
+ import type { ResponsesObject } from "../types/open-api-spec.interface.js";
2
+ export declare class MethodResponseAnalyzer {
3
+ responseType: string | null;
4
+ hasEnumResponse: boolean;
5
+ analyze(responses: ResponsesObject): void;
6
+ private isRef;
7
+ private componentName;
8
+ private getFromContent;
9
+ private typeFromSchemaOrType;
10
+ private extractEnumType;
11
+ private typeFromProperties;
12
+ }
@@ -0,0 +1,96 @@
1
+ export class MethodResponseAnalyzer {
2
+ responseType = null;
3
+ hasEnumResponse = false;
4
+ analyze(responses) {
5
+ for (const response of Object.values(responses)) {
6
+ if (!response || this.isRef(response))
7
+ continue;
8
+ const schemaOrType = this.getFromContent(response.content);
9
+ const type = this.typeFromSchemaOrType(schemaOrType);
10
+ if (type !== undefined) {
11
+ this.responseType = type;
12
+ break;
13
+ }
14
+ }
15
+ }
16
+ isRef(v) {
17
+ return !!v && typeof v === "object" && "$ref" in v;
18
+ }
19
+ componentName(refObj) {
20
+ const parts = refObj.$ref.split("/");
21
+ return parts[parts.length - 1];
22
+ }
23
+ getFromContent(content) {
24
+ if (!content || this.isRef(content))
25
+ return undefined;
26
+ const first = Object.values(content)[0];
27
+ const schema = first?.schema;
28
+ if (!schema)
29
+ return undefined;
30
+ if (this.isRef(schema))
31
+ return this.componentName(schema);
32
+ return schema;
33
+ }
34
+ typeFromSchemaOrType(schemaOrType) {
35
+ if (!schemaOrType)
36
+ return undefined;
37
+ if (typeof schemaOrType === "string") {
38
+ this.hasEnumResponse = false;
39
+ return schemaOrType;
40
+ }
41
+ const schema = schemaOrType;
42
+ if (schema.enum) {
43
+ this.hasEnumResponse = true;
44
+ return this.extractEnumType(schema);
45
+ }
46
+ const allOfFirst = schema.allOf?.[0];
47
+ if (allOfFirst && !this.isRef(allOfFirst)) {
48
+ const t = this.typeFromProperties(allOfFirst.properties);
49
+ if (t !== undefined)
50
+ return t;
51
+ }
52
+ if (schema.type === "array" && schema.items) {
53
+ const items = schema.items;
54
+ if (this.isRef(items))
55
+ return this.componentName(items);
56
+ if (items.enum) {
57
+ this.hasEnumResponse = true;
58
+ return this.extractEnumType(items);
59
+ }
60
+ return items.type;
61
+ }
62
+ if (schema.properties) {
63
+ const t = this.typeFromProperties(schema.properties);
64
+ if (t !== undefined)
65
+ return t;
66
+ }
67
+ return schema.type;
68
+ }
69
+ extractEnumType(schema) {
70
+ const extended = schema;
71
+ if (extended["x-enum-name"]) {
72
+ return extended["x-enum-name"];
73
+ }
74
+ if (schema.title) {
75
+ return schema.title;
76
+ }
77
+ return "string";
78
+ }
79
+ typeFromProperties(properties) {
80
+ if (!properties?.["data"])
81
+ return undefined;
82
+ const data = properties["data"];
83
+ if (this.isRef(data))
84
+ return this.componentName(data);
85
+ if (data.type === "any")
86
+ return undefined;
87
+ if (data.enum) {
88
+ this.hasEnumResponse = true;
89
+ return this.extractEnumType(data);
90
+ }
91
+ if (data.type === "array" && data.items && !this.isRef(data.items) && "enum" in data.items && data.items.enum) {
92
+ this.hasEnumResponse = true;
93
+ }
94
+ return data.type;
95
+ }
96
+ }
@@ -0,0 +1,16 @@
1
+ import type { Method } from "../method.js";
2
+ import type { Source } from "../file.js";
3
+ export declare class Module {
4
+ readonly name: string;
5
+ readonly path: string;
6
+ readonly moduleName: string;
7
+ readonly src: Source;
8
+ readonly methods: Method[];
9
+ constructor(params: {
10
+ name: string;
11
+ path: string;
12
+ moduleName: string;
13
+ methods: Method[];
14
+ src: Source;
15
+ });
16
+ }
@@ -0,0 +1,14 @@
1
+ export class Module {
2
+ name;
3
+ path;
4
+ moduleName;
5
+ src;
6
+ methods;
7
+ constructor(params) {
8
+ this.name = params.name;
9
+ this.path = params.path;
10
+ this.moduleName = params.moduleName;
11
+ this.methods = params.methods;
12
+ this.src = params.src;
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ import type { ComponentsObject, PathsObject } from "../types/open-api-spec.interface.js";
2
+ import { Module } from "./Module.js";
3
+ export declare class ModuleBuilder {
4
+ private readonly components;
5
+ private readonly paths;
6
+ constructor(params: {
7
+ components: ComponentsObject;
8
+ paths: PathsObject;
9
+ });
10
+ build(): Module[];
11
+ }
@@ -0,0 +1,45 @@
1
+ import { Source } from "../file.js";
2
+ import { splitByUppercase } from "../utils/StringUtils.js";
3
+ import { getEndpoint } from "../utils/EndpointUtils.js";
4
+ import { Module } from "./Module.js";
5
+ import { Method } from "../method.js";
6
+ export class ModuleBuilder {
7
+ components;
8
+ paths;
9
+ constructor(params) {
10
+ this.components = params.components;
11
+ this.paths = params.paths;
12
+ }
13
+ build() {
14
+ const methodsMap = new Map();
15
+ for (const [path, methods] of Object.entries(this.paths)) {
16
+ const rawMethod = Object.values(methods)[0];
17
+ const rawName = rawMethod.operationId?.split("_")[0] ?? "";
18
+ const teste = splitByUppercase(rawName).filter((x) => x !== "Controller");
19
+ const moduleName = teste.join("");
20
+ const baseEndpoint = getEndpoint(path);
21
+ const operations = Object.entries(methods).map(([apiMethod, attributes]) => ({
22
+ apiMethod,
23
+ endpoint: path,
24
+ ...attributes,
25
+ }));
26
+ const existentModule = methodsMap.get(moduleName);
27
+ if (existentModule) {
28
+ const newPath = existentModule.path.length > path.length ? path : existentModule.path;
29
+ methodsMap.set(moduleName, {
30
+ ...existentModule,
31
+ path: newPath,
32
+ operations: [...existentModule.operations, ...operations],
33
+ });
34
+ }
35
+ else {
36
+ methodsMap.set(moduleName, { operations, path: baseEndpoint, moduleName });
37
+ }
38
+ }
39
+ return Array.from(methodsMap).map(([name, info]) => {
40
+ const methods = info.operations.map((op) => new Method({ operation: op, moduleName: info.moduleName }));
41
+ const src = new Source({ path: "" });
42
+ return new Module({ name, path: info.path, moduleName: info.moduleName, methods, src });
43
+ });
44
+ }
45
+ }
@@ -0,0 +1,12 @@
1
+ import type { AttributeProp, ParamType } from "../types/types.js";
2
+ import type { ModuleImports } from "./ModuleImports.js";
3
+ export declare class ModuleClassBuilder {
4
+ private readonly imports;
5
+ constructor(params: {
6
+ imports: ModuleImports;
7
+ });
8
+ buildClassProps(params: {
9
+ props: AttributeProp[];
10
+ name: ParamType;
11
+ }): string;
12
+ }
@@ -0,0 +1,74 @@
1
+ export class ModuleClassBuilder {
2
+ imports;
3
+ constructor(params) {
4
+ this.imports = params.imports;
5
+ }
6
+ buildClassProps(params) {
7
+ const { name, props } = params;
8
+ const bundle = [];
9
+ const attributes = [];
10
+ if (name === "Paths") {
11
+ props.forEach((prop) => {
12
+ if ("rawType" in prop) {
13
+ attributes.push(prop.patchBuild());
14
+ }
15
+ });
16
+ this.imports.addPageStateImport();
17
+ return `
18
+ class ${name} {
19
+ ${attributes.join(";")}
20
+ }
21
+ `;
22
+ }
23
+ else if (name === "Querys") {
24
+ props.forEach((prop) => {
25
+ if ("rawType" in prop) {
26
+ attributes.push(prop.queryBuild());
27
+ if ("isEnum" in prop && prop.isEnum) {
28
+ this.imports.addReflectorImport("EnumQueryBuilder");
29
+ this.imports.addEnumImport(String(prop.type));
30
+ bundle.push(`${prop.name}: this.${prop.name}?.values`);
31
+ }
32
+ else {
33
+ bundle.push(prop.bundleBuild());
34
+ }
35
+ }
36
+ else if ("enumName" in prop) {
37
+ this.imports.addEnumImport(prop.enumName);
38
+ attributes.push(prop.queryBuild());
39
+ bundle.push(prop.bundleBuild());
40
+ }
41
+ else {
42
+ attributes.push(prop.queryBuild());
43
+ this.imports.addEnumImport(prop.type);
44
+ bundle.push(prop.queryBundleBuild());
45
+ this.imports.addReflectorImport("EnumQueryBuilder");
46
+ }
47
+ });
48
+ }
49
+ else {
50
+ props.forEach((prop) => {
51
+ if ("isEnum" in prop || "enumName" in prop) {
52
+ this.imports.addEnumImport(prop.type);
53
+ }
54
+ attributes.push(prop.classBuild());
55
+ });
56
+ }
57
+ const bundleBuild = bundle.length > 0
58
+ ? `
59
+ bundle() {
60
+ return {
61
+ ${bundle.join(",")}
62
+ }
63
+ }
64
+ `
65
+ : "";
66
+ return `
67
+ class ${name} {
68
+ ${attributes.join(";")}
69
+
70
+ ${bundleBuild}
71
+ }
72
+ `;
73
+ }
74
+ }
@@ -0,0 +1,7 @@
1
+ export interface Form {
2
+ name: string;
3
+ type: string;
4
+ }
5
+ export declare class ModuleConstructorBuilder {
6
+ build(form: Form[]): string;
7
+ }
@@ -0,0 +1,20 @@
1
+ export class ModuleConstructorBuilder {
2
+ build(form) {
3
+ if (form.length === 0)
4
+ return "";
5
+ return `
6
+ constructor(params?: { empty: boolean }) {
7
+ const isEmpty = PUBLIC_ENVIRONMENT !== 'DEV' || !!params?.empty;
8
+ this.forms = this.buildForms(isEmpty);
9
+ }
10
+
11
+ private buildForms(isEmpty: boolean) {
12
+ if(!isEmpty) return this.forms
13
+
14
+ return {
15
+ ${form.map((f) => `${f.name}: new ${f.type}({ empty: true })`).join(",\n ")}
16
+ }
17
+ }
18
+ `;
19
+ }
20
+ }