@vaadin/hilla-generator-plugin-backbone 24.7.0-alpha9 → 24.7.0-beta2

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,13 +1,10 @@
1
- import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
2
- import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
3
- import { OpenAPIV3 } from 'openapi-types';
4
- import type { ReadonlyDeep } from 'type-fest';
5
- import { type Statement } from 'typescript';
6
- export type EndpointMethodOperation = ReadonlyDeep<OpenAPIV3.OperationObject>;
7
- export declare const INIT_TYPE_NAME = "EndpointRequestInit";
8
- export declare const HILLA_FRONTEND_NAME = "@vaadin/hilla-frontend";
1
+ import type Plugin from "@vaadin/hilla-generator-core/Plugin.js";
2
+ import type { TransferTypes } from "@vaadin/hilla-generator-core/SharedStorage.js";
3
+ import type DependencyManager from "@vaadin/hilla-generator-utils/dependencies/DependencyManager.js";
4
+ import { OpenAPIV3 } from "openapi-types";
5
+ import { type Statement } from "typescript";
6
+ export type EndpointMethodOperation = OpenAPIV3.OperationObject;
9
7
  export default abstract class EndpointMethodOperationProcessor {
10
- static createProcessor(httpMethod: OpenAPIV3.HttpMethods, endpointName: string, endpointMethodName: string, operation: EndpointMethodOperation, dependencies: DependencyManager, owner: Plugin): EndpointMethodOperationProcessor | undefined;
11
- abstract process(outputDir?: string): Promise<Statement | undefined>;
8
+ static createProcessor(httpMethod: OpenAPIV3.HttpMethods, endpointName: string, endpointMethodName: string, operation: EndpointMethodOperation, dependencies: DependencyManager, transferTypes: TransferTypes, owner: Plugin): EndpointMethodOperationProcessor | undefined;
9
+ abstract process(outputDir?: string): Promise<Statement | undefined>;
12
10
  }
13
- //# sourceMappingURL=EndpointMethodOperationProcessor.d.ts.map
@@ -1,94 +1,59 @@
1
1
  import ClientPlugin from "@vaadin/hilla-generator-plugin-client";
2
2
  import equal from "fast-deep-equal";
3
3
  import { OpenAPIV3 } from "openapi-types";
4
- import ts, {} from "typescript";
4
+ import ts from "typescript";
5
5
  import EndpointMethodRequestBodyProcessor from "./EndpointMethodRequestBodyProcessor.js";
6
6
  import EndpointMethodResponseProcessor from "./EndpointMethodResponseProcessor.js";
7
- const INIT_TYPE_NAME = "EndpointRequestInit";
8
- const HILLA_FRONTEND_NAME = "@vaadin/hilla-frontend";
9
- class EndpointMethodOperationProcessor {
10
- static createProcessor(httpMethod, endpointName, endpointMethodName, operation, dependencies, owner) {
11
- switch (httpMethod) {
12
- case OpenAPIV3.HttpMethods.POST:
13
- return new EndpointMethodOperationPOSTProcessor(
14
- endpointName,
15
- endpointMethodName,
16
- operation,
17
- dependencies,
18
- owner
19
- );
20
- default:
21
- owner.logger.warn(`Processing ${httpMethod.toUpperCase()} currently is not supported`);
22
- return void 0;
23
- }
24
- }
7
+ export default class EndpointMethodOperationProcessor {
8
+ static createProcessor(httpMethod, endpointName, endpointMethodName, operation, dependencies, transferTypes, owner) {
9
+ switch (httpMethod) {
10
+ case OpenAPIV3.HttpMethods.POST: {
11
+ return new EndpointMethodOperationPOSTProcessor(endpointName, endpointMethodName, operation, dependencies, transferTypes, owner);
12
+ }
13
+ default:
14
+ owner.logger.warn(`Processing ${httpMethod.toUpperCase()} currently is not supported`);
15
+ return undefined;
16
+ }
17
+ }
25
18
  }
26
19
  class EndpointMethodOperationPOSTProcessor extends EndpointMethodOperationProcessor {
27
- #dependencies;
28
- #endpointMethodName;
29
- #endpointName;
30
- #operation;
31
- #owner;
32
- constructor(endpointName, endpointMethodName, operation, dependencies, owner) {
33
- super();
34
- this.#owner = owner;
35
- this.#dependencies = dependencies;
36
- this.#endpointName = endpointName;
37
- this.#endpointMethodName = endpointMethodName;
38
- this.#operation = operation;
39
- }
40
- async process(outputDir) {
41
- const { exports, imports, paths } = this.#dependencies;
42
- this.#owner.logger.debug(`${this.#endpointName}.${this.#endpointMethodName} - processing POST method`);
43
- const initTypeIdentifier = imports.named.getIdentifier(
44
- paths.createBareModulePath(HILLA_FRONTEND_NAME),
45
- INIT_TYPE_NAME
46
- );
47
- const { initParam, packedParameters, parameters } = new EndpointMethodRequestBodyProcessor(
48
- this.#operation.requestBody,
49
- this.#dependencies,
50
- this.#owner,
51
- initTypeIdentifier
52
- ).process();
53
- const methodIdentifier = exports.named.add(this.#endpointMethodName);
54
- const clientLibIdentifier = imports.default.getIdentifier(
55
- paths.createRelativePath(await ClientPlugin.getClientFileName(outputDir))
56
- );
57
- const callExpression = ts.factory.createCallExpression(
58
- ts.factory.createPropertyAccessExpression(clientLibIdentifier, ts.factory.createIdentifier("call")),
59
- void 0,
60
- [
61
- ts.factory.createStringLiteral(this.#endpointName),
62
- ts.factory.createStringLiteral(this.#endpointMethodName),
63
- packedParameters,
64
- initParam
65
- ].filter(Boolean)
66
- );
67
- const responseType = this.#prepareResponseType();
68
- return ts.factory.createFunctionDeclaration(
69
- [ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
70
- void 0,
71
- methodIdentifier,
72
- void 0,
73
- parameters,
74
- ts.factory.createTypeReferenceNode("Promise", [responseType]),
75
- ts.factory.createBlock([ts.factory.createReturnStatement(callExpression)])
76
- );
77
- }
78
- #prepareResponseType() {
79
- this.#owner.logger.debug(`${this.#endpointName}.${this.#endpointMethodName} POST - processing response type`);
80
- const responseTypes = Object.entries(this.#operation.responses).flatMap(
81
- ([code, response]) => new EndpointMethodResponseProcessor(code, response, this.#dependencies, this.#owner).process()
82
- ).filter((value, index, arr) => arr.findIndex((v) => equal(v, value)) === index);
83
- if (responseTypes.length === 0) {
84
- return ts.factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword);
85
- }
86
- return ts.factory.createUnionTypeNode(responseTypes);
87
- }
20
+ #dependencies;
21
+ #transferTypes;
22
+ #endpointMethodName;
23
+ #endpointName;
24
+ #operation;
25
+ #owner;
26
+ constructor(endpointName, endpointMethodName, operation, dependencies, transferTypes, owner) {
27
+ super();
28
+ this.#owner = owner;
29
+ this.#dependencies = dependencies;
30
+ this.#endpointName = endpointName;
31
+ this.#endpointMethodName = endpointMethodName;
32
+ this.#operation = operation;
33
+ this.#transferTypes = transferTypes;
34
+ }
35
+ async process(outputDir) {
36
+ const { exports, imports, paths } = this.#dependencies;
37
+ this.#owner.logger.debug(`${this.#endpointName}.${this.#endpointMethodName} - processing POST method`);
38
+ const { initParam, packedParameters, parameters } = new EndpointMethodRequestBodyProcessor(this.#operation.requestBody, this.#dependencies, this.#transferTypes, this.#owner).process();
39
+ const methodIdentifier = exports.named.add(this.#endpointMethodName);
40
+ const clientLibIdentifier = imports.default.getIdentifier(paths.createRelativePath(await ClientPlugin.getClientFileName(outputDir)));
41
+ const callExpression = ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(clientLibIdentifier, ts.factory.createIdentifier("call")), undefined, [
42
+ ts.factory.createStringLiteral(this.#endpointName),
43
+ ts.factory.createStringLiteral(this.#endpointMethodName),
44
+ packedParameters,
45
+ initParam
46
+ ].filter(Boolean));
47
+ const responseType = this.#prepareResponseType();
48
+ return ts.factory.createFunctionDeclaration([ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)], undefined, methodIdentifier, undefined, parameters, ts.factory.createTypeReferenceNode("Promise", [responseType]), ts.factory.createBlock([ts.factory.createReturnStatement(callExpression)]));
49
+ }
50
+ #prepareResponseType() {
51
+ this.#owner.logger.debug(`${this.#endpointName}.${this.#endpointMethodName} POST - processing response type`);
52
+ const responseTypes = Object.entries(this.#operation.responses).flatMap(([code, response]) => new EndpointMethodResponseProcessor(code, response, this.#dependencies, this.#transferTypes, this.#owner).process()).filter((value, index, arr) => arr.findIndex((v) => equal(v, value)) === index);
53
+ if (responseTypes.length === 0) {
54
+ return ts.factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword);
55
+ }
56
+ return ts.factory.createUnionTypeNode(responseTypes);
57
+ }
88
58
  }
89
- export {
90
- HILLA_FRONTEND_NAME,
91
- INIT_TYPE_NAME,
92
- EndpointMethodOperationProcessor as default
93
- };
94
- //# sourceMappingURL=EndpointMethodOperationProcessor.js.map
59
+ //# sourceMappingURL=./EndpointMethodOperationProcessor.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["src/EndpointMethodOperationProcessor.ts"],
4
- "sourcesContent": ["/* eslint-disable max-params */\nimport type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport ClientPlugin from '@vaadin/hilla-generator-plugin-client';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport equal from 'fast-deep-equal';\nimport { OpenAPIV3 } from 'openapi-types';\nimport type { ReadonlyDeep } from 'type-fest';\nimport ts, { type Expression, type Statement, type TypeNode } from 'typescript';\nimport EndpointMethodRequestBodyProcessor from './EndpointMethodRequestBodyProcessor.js';\nimport EndpointMethodResponseProcessor from './EndpointMethodResponseProcessor.js';\n\nexport type EndpointMethodOperation = ReadonlyDeep<OpenAPIV3.OperationObject>;\n\nexport const INIT_TYPE_NAME = 'EndpointRequestInit';\nexport const HILLA_FRONTEND_NAME = '@vaadin/hilla-frontend';\n\nexport default abstract class EndpointMethodOperationProcessor {\n static createProcessor(\n httpMethod: OpenAPIV3.HttpMethods,\n endpointName: string,\n endpointMethodName: string,\n operation: EndpointMethodOperation,\n dependencies: DependencyManager,\n owner: Plugin,\n ): EndpointMethodOperationProcessor | undefined {\n switch (httpMethod) {\n case OpenAPIV3.HttpMethods.POST:\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new EndpointMethodOperationPOSTProcessor(\n endpointName,\n endpointMethodName,\n operation,\n dependencies,\n owner,\n );\n default:\n owner.logger.warn(`Processing ${httpMethod.toUpperCase()} currently is not supported`);\n return undefined;\n }\n }\n\n abstract process(outputDir?: string): Promise<Statement | undefined>;\n}\n\nclass EndpointMethodOperationPOSTProcessor extends EndpointMethodOperationProcessor {\n readonly #dependencies: DependencyManager;\n readonly #endpointMethodName: string;\n readonly #endpointName: string;\n readonly #operation: EndpointMethodOperation;\n readonly #owner: Plugin;\n\n constructor(\n endpointName: string,\n endpointMethodName: string,\n operation: EndpointMethodOperation,\n dependencies: DependencyManager,\n owner: Plugin,\n ) {\n super();\n this.#owner = owner;\n this.#dependencies = dependencies;\n this.#endpointName = endpointName;\n this.#endpointMethodName = endpointMethodName;\n this.#operation = operation;\n }\n\n async process(outputDir?: string): Promise<Statement | undefined> {\n const { exports, imports, paths } = this.#dependencies;\n this.#owner.logger.debug(`${this.#endpointName}.${this.#endpointMethodName} - processing POST method`);\n const initTypeIdentifier = imports.named.getIdentifier(\n paths.createBareModulePath(HILLA_FRONTEND_NAME),\n INIT_TYPE_NAME,\n )!;\n\n const { initParam, packedParameters, parameters } = new EndpointMethodRequestBodyProcessor(\n this.#operation.requestBody,\n this.#dependencies,\n this.#owner,\n initTypeIdentifier,\n ).process();\n\n const methodIdentifier = exports.named.add(this.#endpointMethodName);\n const clientLibIdentifier = imports.default.getIdentifier(\n paths.createRelativePath(await ClientPlugin.getClientFileName(outputDir)),\n )!;\n\n const callExpression = ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(clientLibIdentifier, ts.factory.createIdentifier('call')),\n undefined,\n [\n ts.factory.createStringLiteral(this.#endpointName),\n ts.factory.createStringLiteral(this.#endpointMethodName),\n packedParameters,\n initParam,\n ].filter(Boolean) as readonly Expression[],\n );\n\n const responseType = this.#prepareResponseType();\n\n return ts.factory.createFunctionDeclaration(\n [ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],\n undefined,\n methodIdentifier,\n undefined,\n parameters,\n ts.factory.createTypeReferenceNode('Promise', [responseType]),\n ts.factory.createBlock([ts.factory.createReturnStatement(callExpression)]),\n );\n }\n\n #prepareResponseType(): TypeNode {\n this.#owner.logger.debug(`${this.#endpointName}.${this.#endpointMethodName} POST - processing response type`);\n\n const responseTypes = Object.entries(this.#operation.responses)\n .flatMap(([code, response]) =>\n new EndpointMethodResponseProcessor(code, response, this.#dependencies, this.#owner).process(),\n )\n .filter((value, index, arr) => arr.findIndex((v) => equal(v, value)) === index);\n\n if (responseTypes.length === 0) {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword);\n }\n\n return ts.factory.createUnionTypeNode(responseTypes);\n }\n}\n"],
5
- "mappings": "AAEA,OAAO,kBAAkB;AAEzB,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAE1B,OAAO,YAA4D;AACnE,OAAO,wCAAwC;AAC/C,OAAO,qCAAqC;AAIrC,MAAM,iBAAiB;AACvB,MAAM,sBAAsB;AAEnC,MAAO,iCAAwD;AAAA,EAC7D,OAAO,gBACL,YACA,cACA,oBACA,WACA,cACA,OAC8C;AAC9C,YAAQ,YAAY;AAAA,MAClB,KAAK,UAAU,YAAY;AAEzB,eAAO,IAAI;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AACE,cAAM,OAAO,KAAK,cAAc,WAAW,YAAY,CAAC,6BAA6B;AACrF,eAAO;AAAA,IACX;AAAA,EACF;AAGF;AAEA,MAAM,6CAA6C,iCAAiC;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,cACA,oBACA,WACA,cACA,OACA;AACA,UAAM;AACN,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB,SAAK,gBAAgB;AACrB,SAAK,sBAAsB;AAC3B,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,MAAM,QAAQ,WAAoD;AAChE,UAAM,EAAE,SAAS,SAAS,MAAM,IAAI,KAAK;AACzC,SAAK,OAAO,OAAO,MAAM,GAAG,KAAK,aAAa,IAAI,KAAK,mBAAmB,2BAA2B;AACrG,UAAM,qBAAqB,QAAQ,MAAM;AAAA,MACvC,MAAM,qBAAqB,mBAAmB;AAAA,MAC9C;AAAA,IACF;AAEA,UAAM,EAAE,WAAW,kBAAkB,WAAW,IAAI,IAAI;AAAA,MACtD,KAAK,WAAW;AAAA,MAChB,KAAK;AAAA,MACL,KAAK;AAA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AAkB,UAAU,CAAC,CAC1E;EAED,MAAM,iBAAiB,GAAG,QAAQ,qBAChC,GAAG,QAAQ,+BAA+B,qBAAqB,GAAG,QAAQ,iBAAiB,OAAO,CAAC,EACnG,WACA;GACE,GAAG,QAAQ,oBAAoB,KAAKC,cAAc;GAClD,GAAG,QAAQ,oBAAoB,KAAKD,oBAAoB;GACxD;GACA;EACD,EAAC,OAAO,QAAQ,CAClB;EAED,MAAM,eAAe,KAAKK,sBAAsB;AAEhD,SAAO,GAAG,QAAQ,0BAChB,CAAC,GAAG,QAAQ,YAAY,GAAG,WAAW,aAAa,AAAC,GACpD,WACA,kBACA,WACA,YACA,GAAG,QAAQ,wBAAwB,WAAW,CAAC,YAAa,EAAC,EAC7D,GAAG,QAAQ,YAAY,CAAC,GAAG,QAAQ,sBAAsB,eAAe,AAAC,EAAC,CAC3E;CACF;CAED,uBAAiC;AAC/B,OAAKF,OAAO,OAAO,OAAO,EAAE,KAAKF,cAAc,GAAG,KAAKD,oBAAoB,kCAAkC;EAE7G,MAAM,gBAAgB,OAAO,QAAQ,KAAKE,WAAW,UAAU,CAC5D,QAAQ,CAAC,CAAC,MAAM,SAAS,KACxB,IAAI,gCACF,MACA,UACA,KAAKJ,eACL,KAAKC,gBACL,KAAKI,QACL,SAAS,CACZ,CACA,OAAO,CAAC,OAAO,OAAO,QAAQ,IAAI,UAAU,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,MAAM;AAEjF,MAAI,cAAc,WAAW,GAAG;AAC9B,UAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,YAAY;EACnE;AAED,SAAO,GAAG,QAAQ,oBAAoB,cAAc;CACrD;AACF","names":["httpMethod: OpenAPIV3.HttpMethods","endpointName: string","endpointMethodName: string","operation: EndpointMethodOperation","dependencies: DependencyManager","transferTypes: TransferTypes","owner: Plugin","#dependencies","#transferTypes","#endpointMethodName","#endpointName","#operation","#owner","outputDir?: string","#prepareResponseType"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-plugin-backbone/src/EndpointMethodOperationProcessor.ts"],"sourcesContent":["/* eslint-disable max-params */\nimport type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type { TransferTypes } from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport ClientPlugin from '@vaadin/hilla-generator-plugin-client';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport equal from 'fast-deep-equal';\nimport { OpenAPIV3 } from 'openapi-types';\nimport ts, { type Expression, type Statement, type TypeNode } from 'typescript';\nimport EndpointMethodRequestBodyProcessor from './EndpointMethodRequestBodyProcessor.js';\nimport EndpointMethodResponseProcessor from './EndpointMethodResponseProcessor.js';\n\nexport type EndpointMethodOperation = OpenAPIV3.OperationObject;\n\nexport default abstract class EndpointMethodOperationProcessor {\n // eslint-disable-next-line @typescript-eslint/max-params\n static createProcessor(\n httpMethod: OpenAPIV3.HttpMethods,\n endpointName: string,\n endpointMethodName: string,\n operation: EndpointMethodOperation,\n dependencies: DependencyManager,\n transferTypes: TransferTypes,\n owner: Plugin,\n ): EndpointMethodOperationProcessor | undefined {\n switch (httpMethod) {\n case OpenAPIV3.HttpMethods.POST: {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new EndpointMethodOperationPOSTProcessor(\n endpointName,\n endpointMethodName,\n operation,\n dependencies,\n transferTypes,\n owner,\n );\n }\n default:\n owner.logger.warn(`Processing ${httpMethod.toUpperCase()} currently is not supported`);\n return undefined;\n }\n }\n\n abstract process(outputDir?: string): Promise<Statement | undefined>;\n}\n\nclass EndpointMethodOperationPOSTProcessor extends EndpointMethodOperationProcessor {\n readonly #dependencies: DependencyManager;\n readonly #transferTypes: TransferTypes;\n readonly #endpointMethodName: string;\n readonly #endpointName: string;\n readonly #operation: EndpointMethodOperation;\n readonly #owner: Plugin;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n endpointName: string,\n endpointMethodName: string,\n operation: EndpointMethodOperation,\n dependencies: DependencyManager,\n transferTypes: TransferTypes,\n owner: Plugin,\n ) {\n super();\n this.#owner = owner;\n this.#dependencies = dependencies;\n this.#endpointName = endpointName;\n this.#endpointMethodName = endpointMethodName;\n this.#operation = operation;\n this.#transferTypes = transferTypes;\n }\n\n async process(outputDir?: string): Promise<Statement | undefined> {\n const { exports, imports, paths } = this.#dependencies;\n this.#owner.logger.debug(`${this.#endpointName}.${this.#endpointMethodName} - processing POST method`);\n\n const { initParam, packedParameters, parameters } = new EndpointMethodRequestBodyProcessor(\n this.#operation.requestBody,\n this.#dependencies,\n this.#transferTypes,\n this.#owner,\n ).process();\n\n const methodIdentifier = exports.named.add(this.#endpointMethodName);\n const clientLibIdentifier = imports.default.getIdentifier(\n paths.createRelativePath(await ClientPlugin.getClientFileName(outputDir)),\n )!;\n\n const callExpression = ts.factory.createCallExpression(\n ts.factory.createPropertyAccessExpression(clientLibIdentifier, ts.factory.createIdentifier('call')),\n undefined,\n [\n ts.factory.createStringLiteral(this.#endpointName),\n ts.factory.createStringLiteral(this.#endpointMethodName),\n packedParameters,\n initParam,\n ].filter(Boolean) as readonly Expression[],\n );\n\n const responseType = this.#prepareResponseType();\n\n return ts.factory.createFunctionDeclaration(\n [ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],\n undefined,\n methodIdentifier,\n undefined,\n parameters,\n ts.factory.createTypeReferenceNode('Promise', [responseType]),\n ts.factory.createBlock([ts.factory.createReturnStatement(callExpression)]),\n );\n }\n\n #prepareResponseType(): TypeNode {\n this.#owner.logger.debug(`${this.#endpointName}.${this.#endpointMethodName} POST - processing response type`);\n\n const responseTypes = Object.entries(this.#operation.responses)\n .flatMap(([code, response]) =>\n new EndpointMethodResponseProcessor(\n code,\n response,\n this.#dependencies,\n this.#transferTypes,\n this.#owner,\n ).process(),\n )\n .filter((value, index, arr) => arr.findIndex((v) => equal(v, value)) === index);\n\n if (responseTypes.length === 0) {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword);\n }\n\n return ts.factory.createUnionTypeNode(responseTypes);\n }\n}\n"],"version":3}
@@ -1,17 +1,16 @@
1
- import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
2
- import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
3
- import type { OpenAPIV3 } from 'openapi-types';
4
- import type { ReadonlyDeep } from 'type-fest';
5
- import ts, { type ObjectLiteralExpression, type ParameterDeclaration } from 'typescript';
6
- export type EndpointMethodRequestBody = ReadonlyDeep<OpenAPIV3.RequestBodyObject>;
1
+ import type Plugin from "@vaadin/hilla-generator-core/Plugin.js";
2
+ import type { TransferTypes } from "@vaadin/hilla-generator-core/SharedStorage.js";
3
+ import type DependencyManager from "@vaadin/hilla-generator-utils/dependencies/DependencyManager.js";
4
+ import type { OpenAPIV3 } from "openapi-types";
5
+ import { type Identifier, type ObjectLiteralExpression, type ParameterDeclaration } from "typescript";
6
+ export type EndpointMethodRequestBody = OpenAPIV3.RequestBodyObject;
7
7
  export type EndpointMethodRequestBodyProcessingResult = Readonly<{
8
- parameters: readonly ParameterDeclaration[];
9
- packedParameters?: ObjectLiteralExpression;
10
- initParam: ts.Identifier;
8
+ parameters: readonly ParameterDeclaration[]
9
+ packedParameters?: ObjectLiteralExpression
10
+ initParam: Identifier
11
11
  }>;
12
12
  export default class EndpointMethodRequestBodyProcessor {
13
- #private;
14
- constructor(requestBody: ReadonlyDeep<OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject> | undefined, dependencies: DependencyManager, owner: Plugin, initTypeIdentifier: ts.Identifier);
15
- process(): EndpointMethodRequestBodyProcessingResult;
13
+ #private;
14
+ constructor(requestBody: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject | undefined, dependencies: DependencyManager, transferTypes: TransferTypes, owner: Plugin);
15
+ process(): EndpointMethodRequestBodyProcessingResult;
16
16
  }
17
- //# sourceMappingURL=EndpointMethodRequestBodyProcessor.d.ts.map
@@ -1,84 +1,58 @@
1
- import {
2
- isEmptyObject,
3
- isObjectSchema
4
- } from "@vaadin/hilla-generator-core/Schema.js";
5
- import ts, {} from "typescript";
1
+ import { isEmptyObject, isObjectSchema } from "@vaadin/hilla-generator-core/Schema.js";
2
+ import ts from "typescript";
6
3
  import TypeSchemaProcessor from "./TypeSchemaProcessor.js";
7
4
  import { defaultMediaType } from "./utils.js";
8
- class EndpointMethodRequestBodyProcessor {
9
- static #defaultInitParamName = "init";
10
- #dependencies;
11
- #owner;
12
- #requestBody;
13
- #initTypeIdentifier;
14
- constructor(requestBody, dependencies, owner, initTypeIdentifier) {
15
- this.#owner = owner;
16
- this.#dependencies = dependencies;
17
- this.#requestBody = requestBody ? owner.resolver.resolve(requestBody) : void 0;
18
- this.#initTypeIdentifier = initTypeIdentifier;
19
- }
20
- process() {
21
- if (!this.#requestBody) {
22
- return {
23
- initParam: ts.factory.createIdentifier(EndpointMethodRequestBodyProcessor.#defaultInitParamName),
24
- packedParameters: ts.factory.createObjectLiteralExpression(),
25
- parameters: [
26
- ts.factory.createParameterDeclaration(
27
- void 0,
28
- void 0,
29
- EndpointMethodRequestBodyProcessor.#defaultInitParamName,
30
- ts.factory.createToken(ts.SyntaxKind.QuestionToken),
31
- ts.factory.createTypeReferenceNode(this.#initTypeIdentifier)
32
- )
33
- ]
34
- };
35
- }
36
- const parameterData = this.#extractParameterData(this.#requestBody.content[defaultMediaType].schema);
37
- const parameterNames = parameterData.map(([name]) => name);
38
- let initParamName = EndpointMethodRequestBodyProcessor.#defaultInitParamName;
39
- while (parameterNames.includes(initParamName)) {
40
- initParamName = `_${initParamName}`;
41
- }
42
- return {
43
- initParam: ts.factory.createIdentifier(initParamName),
44
- packedParameters: ts.factory.createObjectLiteralExpression(
45
- parameterData.map(([name]) => ts.factory.createShorthandPropertyAssignment(name))
46
- ),
47
- parameters: [
48
- ...parameterData.map(([name, schema]) => {
49
- const nodes = new TypeSchemaProcessor(schema, this.#dependencies).process();
50
- return ts.factory.createParameterDeclaration(
51
- void 0,
52
- void 0,
53
- name,
54
- void 0,
55
- ts.factory.createUnionTypeNode(nodes)
56
- );
57
- }),
58
- ts.factory.createParameterDeclaration(
59
- void 0,
60
- void 0,
61
- initParamName,
62
- ts.factory.createToken(ts.SyntaxKind.QuestionToken),
63
- ts.factory.createTypeReferenceNode(this.#initTypeIdentifier)
64
- )
65
- ]
66
- };
67
- }
68
- #extractParameterData(basicSchema) {
69
- if (!basicSchema) {
70
- return [];
71
- }
72
- const { logger, resolver } = this.#owner;
73
- const resolvedSchema = resolver.resolve(basicSchema);
74
- if (isObjectSchema(resolvedSchema) && !isEmptyObject(resolvedSchema)) {
75
- return Object.entries(resolvedSchema.properties);
76
- }
77
- logger.warn("A schema provided for endpoint method's 'requestBody' is not supported");
78
- return [];
79
- }
5
+ const DEFAULT_INIT_PARAM_NAME = "init";
6
+ const INIT_TYPE_NAME = "EndpointRequestInit";
7
+ const HILLA_FRONTEND_NAME = "@vaadin/hilla-frontend";
8
+ export default class EndpointMethodRequestBodyProcessor {
9
+ #dependencies;
10
+ #transferTypes;
11
+ #owner;
12
+ #requestBody;
13
+ constructor(requestBody, dependencies, transferTypes, owner) {
14
+ this.#owner = owner;
15
+ this.#dependencies = dependencies;
16
+ this.#requestBody = requestBody ? owner.resolver.resolve(requestBody) : undefined;
17
+ this.#transferTypes = transferTypes;
18
+ }
19
+ process() {
20
+ const { imports, paths } = this.#dependencies;
21
+ const path = paths.createBareModulePath(HILLA_FRONTEND_NAME);
22
+ const initTypeIdentifier = imports.named.getIdentifier(path, INIT_TYPE_NAME) ?? imports.named.add(path, INIT_TYPE_NAME);
23
+ if (!this.#requestBody) {
24
+ return {
25
+ initParam: ts.factory.createIdentifier(DEFAULT_INIT_PARAM_NAME),
26
+ packedParameters: ts.factory.createObjectLiteralExpression(),
27
+ parameters: [ts.factory.createParameterDeclaration(undefined, undefined, DEFAULT_INIT_PARAM_NAME, ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createTypeReferenceNode(initTypeIdentifier))]
28
+ };
29
+ }
30
+ const parameterData = this.#extractParameterData(this.#requestBody.content[defaultMediaType].schema);
31
+ const parameterNames = parameterData.map(([name]) => name);
32
+ let initParamName = DEFAULT_INIT_PARAM_NAME;
33
+ while (parameterNames.includes(initParamName)) {
34
+ initParamName = `_${initParamName}`;
35
+ }
36
+ return {
37
+ initParam: ts.factory.createIdentifier(initParamName),
38
+ packedParameters: ts.factory.createObjectLiteralExpression(parameterData.map(([name]) => ts.factory.createShorthandPropertyAssignment(name))),
39
+ parameters: [...parameterData.map(([name, schema]) => {
40
+ const nodes = new TypeSchemaProcessor(schema, this.#dependencies, this.#transferTypes).process();
41
+ return ts.factory.createParameterDeclaration(undefined, undefined, name, undefined, ts.factory.createUnionTypeNode(nodes));
42
+ }), ts.factory.createParameterDeclaration(undefined, undefined, initParamName, ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createTypeReferenceNode(initTypeIdentifier))]
43
+ };
44
+ }
45
+ #extractParameterData(basicSchema) {
46
+ if (!basicSchema) {
47
+ return [];
48
+ }
49
+ const { logger, resolver } = this.#owner;
50
+ const resolvedSchema = resolver.resolve(basicSchema);
51
+ if (isObjectSchema(resolvedSchema) && !isEmptyObject(resolvedSchema)) {
52
+ return Object.entries(resolvedSchema.properties);
53
+ }
54
+ logger.warn("A schema provided for endpoint method's 'requestBody' is not supported");
55
+ return [];
56
+ }
80
57
  }
81
- export {
82
- EndpointMethodRequestBodyProcessor as default
83
- };
84
- //# sourceMappingURL=EndpointMethodRequestBodyProcessor.js.map
58
+ //# sourceMappingURL=./EndpointMethodRequestBodyProcessor.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["src/EndpointMethodRequestBodyProcessor.ts"],
4
- "sourcesContent": ["import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport {\n isEmptyObject,\n isObjectSchema,\n type NonEmptyObjectSchema,\n type Schema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { ReadonlyDeep } from 'type-fest';\nimport ts, { type ObjectLiteralExpression, type ParameterDeclaration } from 'typescript';\nimport TypeSchemaProcessor from './TypeSchemaProcessor.js';\nimport { defaultMediaType } from './utils.js';\n\nexport type EndpointMethodRequestBody = ReadonlyDeep<OpenAPIV3.RequestBodyObject>;\n\nexport type EndpointMethodRequestBodyProcessingResult = Readonly<{\n parameters: readonly ParameterDeclaration[];\n packedParameters?: ObjectLiteralExpression;\n initParam: ts.Identifier;\n}>;\n\nexport default class EndpointMethodRequestBodyProcessor {\n static readonly #defaultInitParamName = 'init';\n\n readonly #dependencies: DependencyManager;\n readonly #owner: Plugin;\n readonly #requestBody?: EndpointMethodRequestBody;\n readonly #initTypeIdentifier: ts.Identifier;\n\n constructor(\n requestBody: ReadonlyDeep<OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject> | undefined,\n dependencies: DependencyManager,\n owner: Plugin,\n initTypeIdentifier: ts.Identifier,\n ) {\n this.#owner = owner;\n this.#dependencies = dependencies;\n this.#requestBody = requestBody ? owner.resolver.resolve(requestBody) : undefined;\n this.#initTypeIdentifier = initTypeIdentifier;\n }\n\n process(): EndpointMethodRequestBodyProcessingResult {\n if (!this.#requestBody) {\n return {\n initParam: ts.factory.createIdentifier(EndpointMethodRequestBodyProcessor.#defaultInitParamName),\n packedParameters: ts.factory.createObjectLiteralExpression(),\n parameters: [\n ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n EndpointMethodRequestBodyProcessor.#defaultInitParamName,\n ts.factory.createToken(ts.SyntaxKind.QuestionToken),\n ts.factory.createTypeReferenceNode(this.#initTypeIdentifier),\n ),\n ],\n };\n }\n\n const parameterData = this.#extractParameterData(this.#requestBody.content[defaultMediaType].schema);\n const parameterNames = parameterData.map(([name]) => name);\n let initParamName = EndpointMethodRequestBodyProcessor.#defaultInitParamName;\n\n while (parameterNames.includes(initParamName)) {\n initParamName = `_${initParamName}`;\n }\n\n return {\n initParam: ts.factory.createIdentifier(initParamName),\n packedParameters: ts.factory.createObjectLiteralExpression(\n parameterData.map(([name]) => ts.factory.createShorthandPropertyAssignment(name)),\n ),\n parameters: [\n ...parameterData.map(([name, schema]) => {\n const nodes = new TypeSchemaProcessor(schema, this.#dependencies).process();\n\n return ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n name,\n undefined,\n ts.factory.createUnionTypeNode(nodes),\n );\n }),\n ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n initParamName,\n ts.factory.createToken(ts.SyntaxKind.QuestionToken),\n ts.factory.createTypeReferenceNode(this.#initTypeIdentifier),\n ),\n ],\n };\n }\n\n #extractParameterData(\n basicSchema?: ReadonlyDeep<OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>,\n ): Array<readonly [string, Schema]> {\n if (!basicSchema) {\n return [];\n }\n\n const { logger, resolver } = this.#owner;\n\n const resolvedSchema = resolver.resolve(basicSchema);\n\n if (isObjectSchema(resolvedSchema) && !isEmptyObject(resolvedSchema)) {\n return Object.entries((resolvedSchema as NonEmptyObjectSchema).properties);\n }\n\n logger.warn(\"A schema provided for endpoint method's 'requestBody' is not supported\");\n return [];\n }\n}\n"],
5
- "mappings": "AACA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAIP,OAAO,YAAqE;AAC5E,OAAO,yBAAyB;AAChC,SAAS,wBAAwB;AAUjC,MAAO,mCAAiD;AAAA,EACtD,OAAgB,wBAAwB;AAAA,EAE/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,aACA,cACA,OACA,oBACA;AACA,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB,SAAK,eAAe,cAAc,MAAM,SAAS,QAAQ,WAAW,IAAI;AACxE,SAAK,sBAAsB;AAAA,EAC7B;AAAA,EAEA,UAAqD;AACnD,QAAI,CAAC,KAAK,cAAc;AACtB,aAAO;AAAA,QACL,WAAW,GAAG,QAAQ,iBAA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AM,iBAAiB,cAAc,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK;EAC1D,IAAI,gBAAgB;AAEpB,SAAO,eAAe,SAAS,cAAc,EAAE;AAC7C,oBAAiB,GAAG,cAAc;EACnC;AAED,SAAO;GACL,WAAW,GAAG,QAAQ,iBAAiB,cAAc;GACrD,kBAAkB,GAAG,QAAQ,8BAC3B,cAAc,IAAI,CAAC,CAAC,KAAK,KAAK,GAAG,QAAQ,kCAAkC,KAAK,CAAC,CAClF;GACD,YAAY,CACV,GAAG,cAAc,IAAI,CAAC,CAAC,MAAM,OAAO,KAAK;IACvC,MAAM,QAAQ,IAAI,oBAAoB,QAAQ,KAAKH,eAAe,KAAKC,gBAAgB,SAAS;AAEhG,WAAO,GAAG,QAAQ,2BAChB,WACA,WACA,MACA,WACA,GAAG,QAAQ,oBAAoB,MAAM,CACtC;GACF,EAAC,EACF,GAAG,QAAQ,2BACT,WACA,WACA,eACA,GAAG,QAAQ,YAAY,GAAG,WAAW,cAAc,EACnD,GAAG,QAAQ,wBAAwB,mBAAmB,CACvD,AACF;EACF;CACF;CAED,sBACEQ,aACkC;AAClC,OAAK,aAAa;AAChB,UAAO,CAAE;EACV;EAED,MAAM,EAAE,QAAQ,UAAU,GAAG,KAAKP;EAElC,MAAM,iBAAiB,SAAS,QAAQ,YAAY;AAEpD,MAAI,eAAe,eAAe,KAAK,cAAc,eAAe,EAAE;AACpE,UAAO,OAAO,QAAS,eAAwC,WAAW;EAC3E;AAED,SAAO,KAAK,yEAAyE;AACrF,SAAO,CAAE;CACV;AACF","names":["#dependencies","#transferTypes","#owner","#requestBody","requestBody: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject | undefined","dependencies: DependencyManager","transferTypes: TransferTypes","owner: Plugin","#extractParameterData","basicSchema?: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-plugin-backbone/src/EndpointMethodRequestBodyProcessor.ts"],"sourcesContent":["import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport {\n isEmptyObject,\n isObjectSchema,\n type NonEmptyObjectSchema,\n type Schema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport type { TransferTypes } from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport ts, { type Identifier, type ObjectLiteralExpression, type ParameterDeclaration } from 'typescript';\nimport TypeSchemaProcessor from './TypeSchemaProcessor.js';\nimport { defaultMediaType } from './utils.js';\n\nexport type EndpointMethodRequestBody = OpenAPIV3.RequestBodyObject;\n\nexport type EndpointMethodRequestBodyProcessingResult = Readonly<{\n parameters: readonly ParameterDeclaration[];\n packedParameters?: ObjectLiteralExpression;\n initParam: Identifier;\n}>;\n\nconst DEFAULT_INIT_PARAM_NAME = 'init';\nconst INIT_TYPE_NAME = 'EndpointRequestInit';\nconst HILLA_FRONTEND_NAME = '@vaadin/hilla-frontend';\n\nexport default class EndpointMethodRequestBodyProcessor {\n readonly #dependencies: DependencyManager;\n readonly #transferTypes: TransferTypes;\n readonly #owner: Plugin;\n readonly #requestBody?: EndpointMethodRequestBody;\n\n constructor(\n requestBody: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject | undefined,\n dependencies: DependencyManager,\n transferTypes: TransferTypes,\n owner: Plugin,\n ) {\n this.#owner = owner;\n this.#dependencies = dependencies;\n this.#requestBody = requestBody ? owner.resolver.resolve(requestBody) : undefined;\n this.#transferTypes = transferTypes;\n }\n\n process(): EndpointMethodRequestBodyProcessingResult {\n const { imports, paths } = this.#dependencies;\n const path = paths.createBareModulePath(HILLA_FRONTEND_NAME);\n const initTypeIdentifier =\n imports.named.getIdentifier(path, INIT_TYPE_NAME) ?? imports.named.add(path, INIT_TYPE_NAME);\n\n if (!this.#requestBody) {\n return {\n initParam: ts.factory.createIdentifier(DEFAULT_INIT_PARAM_NAME),\n packedParameters: ts.factory.createObjectLiteralExpression(),\n parameters: [\n ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n DEFAULT_INIT_PARAM_NAME,\n ts.factory.createToken(ts.SyntaxKind.QuestionToken),\n ts.factory.createTypeReferenceNode(initTypeIdentifier),\n ),\n ],\n };\n }\n\n const parameterData = this.#extractParameterData(this.#requestBody.content[defaultMediaType].schema);\n const parameterNames = parameterData.map(([name]) => name);\n let initParamName = DEFAULT_INIT_PARAM_NAME;\n\n while (parameterNames.includes(initParamName)) {\n initParamName = `_${initParamName}`;\n }\n\n return {\n initParam: ts.factory.createIdentifier(initParamName),\n packedParameters: ts.factory.createObjectLiteralExpression(\n parameterData.map(([name]) => ts.factory.createShorthandPropertyAssignment(name)),\n ),\n parameters: [\n ...parameterData.map(([name, schema]) => {\n const nodes = new TypeSchemaProcessor(schema, this.#dependencies, this.#transferTypes).process();\n\n return ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n name,\n undefined,\n ts.factory.createUnionTypeNode(nodes),\n );\n }),\n ts.factory.createParameterDeclaration(\n undefined,\n undefined,\n initParamName,\n ts.factory.createToken(ts.SyntaxKind.QuestionToken),\n ts.factory.createTypeReferenceNode(initTypeIdentifier),\n ),\n ],\n };\n }\n\n #extractParameterData(\n basicSchema?: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject,\n ): Array<readonly [string, Schema]> {\n if (!basicSchema) {\n return [];\n }\n\n const { logger, resolver } = this.#owner;\n\n const resolvedSchema = resolver.resolve(basicSchema);\n\n if (isObjectSchema(resolvedSchema) && !isEmptyObject(resolvedSchema)) {\n return Object.entries((resolvedSchema as NonEmptyObjectSchema).properties);\n }\n\n logger.warn(\"A schema provided for endpoint method's 'requestBody' is not supported\");\n return [];\n }\n}\n"],"version":3}
@@ -1,13 +1,12 @@
1
- import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
2
- import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
3
- import type { OpenAPIV3 } from 'openapi-types';
4
- import type { ReadonlyDeep } from 'type-fest';
5
- import type { TypeNode } from 'typescript';
6
- export type EndpointMethodResponses = ReadonlyDeep<OpenAPIV3.ResponsesObject>;
7
- export type EndpointMethodResponse = ReadonlyDeep<OpenAPIV3.ResponseObject>;
1
+ import type Plugin from "@vaadin/hilla-generator-core/Plugin.js";
2
+ import type { TransferTypes } from "@vaadin/hilla-generator-core/SharedStorage.js";
3
+ import type DependencyManager from "@vaadin/hilla-generator-utils/dependencies/DependencyManager.js";
4
+ import type { OpenAPIV3 } from "openapi-types";
5
+ import type { TypeNode } from "typescript";
6
+ export type EndpointMethodResponses = OpenAPIV3.ResponsesObject;
7
+ export type EndpointMethodResponse = OpenAPIV3.ResponseObject;
8
8
  export default class EndpointMethodResponseProcessor {
9
- #private;
10
- constructor(code: string, response: EndpointMethodResponses[string], dependencyManager: DependencyManager, owner: Plugin);
11
- process(): readonly TypeNode[];
9
+ #private;
10
+ constructor(code: string, response: EndpointMethodResponses[string], dependencyManager: DependencyManager, transferTypes: TransferTypes, owner: Plugin);
11
+ process(): readonly TypeNode[];
12
12
  }
13
- //# sourceMappingURL=EndpointMethodResponseProcessor.d.ts.map
@@ -1,31 +1,29 @@
1
1
  import TypeSchemaProcessor from "./TypeSchemaProcessor.js";
2
2
  import { defaultMediaType } from "./utils.js";
3
- class EndpointMethodResponseProcessor {
4
- #code;
5
- #dependencies;
6
- #owner;
7
- #response;
8
- constructor(code, response, dependencyManager, owner) {
9
- this.#code = code;
10
- this.#owner = owner;
11
- this.#dependencies = dependencyManager;
12
- this.#response = owner.resolver.resolve(response);
13
- }
14
- process() {
15
- switch (this.#code) {
16
- case "200":
17
- return this.#processOk();
18
- default:
19
- this.#owner.logger.warn(`Response code '${this.#code} is not supported'`);
20
- return [];
21
- }
22
- }
23
- #processOk() {
24
- const rawSchema = this.#response.content?.[defaultMediaType]?.schema;
25
- return rawSchema ? new TypeSchemaProcessor(rawSchema, this.#dependencies).process() : [];
26
- }
3
+ export default class EndpointMethodResponseProcessor {
4
+ #code;
5
+ #dependencies;
6
+ #transferTypes;
7
+ #owner;
8
+ #response;
9
+ constructor(code, response, dependencyManager, transferTypes, owner) {
10
+ this.#code = code;
11
+ this.#owner = owner;
12
+ this.#dependencies = dependencyManager;
13
+ this.#response = owner.resolver.resolve(response);
14
+ this.#transferTypes = transferTypes;
15
+ }
16
+ process() {
17
+ switch (this.#code) {
18
+ case "200": return this.#processOk();
19
+ default:
20
+ this.#owner.logger.warn(`Response code '${this.#code} is not supported'`);
21
+ return [];
22
+ }
23
+ }
24
+ #processOk() {
25
+ const rawSchema = this.#response.content?.[defaultMediaType]?.schema;
26
+ return rawSchema ? new TypeSchemaProcessor(rawSchema, this.#dependencies, this.#transferTypes).process() : [];
27
+ }
27
28
  }
28
- export {
29
- EndpointMethodResponseProcessor as default
30
- };
31
- //# sourceMappingURL=EndpointMethodResponseProcessor.js.map
29
+ //# sourceMappingURL=./EndpointMethodResponseProcessor.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["src/EndpointMethodResponseProcessor.ts"],
4
- "sourcesContent": ["import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { ReadonlyDeep } from 'type-fest';\nimport type { TypeNode } from 'typescript';\nimport TypeSchemaProcessor from './TypeSchemaProcessor.js';\nimport { defaultMediaType } from './utils.js';\n\nexport type EndpointMethodResponses = ReadonlyDeep<OpenAPIV3.ResponsesObject>;\nexport type EndpointMethodResponse = ReadonlyDeep<OpenAPIV3.ResponseObject>;\n\nexport default class EndpointMethodResponseProcessor {\n readonly #code: string;\n readonly #dependencies: DependencyManager;\n readonly #owner: Plugin;\n readonly #response: EndpointMethodResponse;\n\n constructor(\n code: string,\n response: EndpointMethodResponses[string],\n dependencyManager: DependencyManager,\n owner: Plugin,\n ) {\n this.#code = code;\n this.#owner = owner;\n this.#dependencies = dependencyManager;\n this.#response = owner.resolver.resolve(response);\n }\n\n process(): readonly TypeNode[] {\n switch (this.#code) {\n case '200':\n return this.#processOk();\n default:\n this.#owner.logger.warn(`Response code '${this.#code} is not supported'`);\n return [];\n }\n }\n\n #processOk(): readonly TypeNode[] {\n const rawSchema = this.#response.content?.[defaultMediaType]?.schema;\n\n return rawSchema ? new TypeSchemaProcessor(rawSchema, this.#dependencies).process() : [];\n }\n}\n"],
5
- "mappings": "AAKA,OAAO,yBAAyB;AAChC,SAAS,wBAAwB;AAKjC,MAAO,gCAA8C;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,MACA,UACA,mBACA,OACA;AACA,SAAK,QAAQ;AACb,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB,SAAK,YAAY,MAAM,SAAS,QAAQ,QAAQ;AAAA,EAClD;AAAA,EAEA,UAA+B;AAC7B,YAAQ,KAAK,OAAO;AAAA,MAClB,KAAK;AACH,eAAO,KAAK,WAAW;AAAA,MACzB;AACE,aAAK,OAAO,OAAO,KAAK,kBAAkB,KAAK,KAAK,oBAAoB;AACxE,eAAO,CAAC;AAAA,IACZ;AAAA,EACF;AAAA,EAEA,aAAkC;AAChC,UAAM,YAAY,KAAK,UAAU,UAAU,gBAAgB,GAAG;AAE9D,WAAO,YAAY,IAAI,oBAAoB,WAAW,KAAK,aAAa,EAAE,QAAQ,IAAI,CAAC;AAAA,EACzF;AACF;",
6
- "names": []
7
- }
1
+ {"mappings":"AAKA,OAAO,mDAAoD;AAC3D,SAAS,oCAAqC;AAK9C,eAAe,MAAM,gCAAgC;CACnD,AAASA;CACT,AAASC;CACT,AAASC;CACT,AAASC;CACT,AAASC;CAGT,YACEC,MACAC,UACAC,mBACAC,eACAC,OACA;AACA,OAAKT,QAAQ;AACb,OAAKG,SAAS;AACd,OAAKF,gBAAgB;AACrB,OAAKG,YAAY,MAAM,SAAS,QAAQ,SAAS;AACjD,OAAKF,iBAAiB;CACvB;CAED,UAA+B;AAC7B,UAAQ,KAAKF,OAAb;GACE,KAAK,MACH,QAAO,KAAKU,YAAY;GAC1B;AACE,SAAKP,OAAO,OAAO,MAAM,iBAAiB,KAAKH,MAAM,oBAAoB;AACzE,WAAO,CAAE;EACZ;CACF;CAED,aAAkC;EAChC,MAAM,YAAY,KAAKI,UAAU,UAAU,mBAAmB;AAE9D,SAAO,YAAY,IAAI,oBAAoB,WAAW,KAAKH,eAAe,KAAKC,gBAAgB,SAAS,GAAG,CAAE;CAC9G;AACF","names":["#code","#dependencies","#transferTypes","#owner","#response","code: string","response: EndpointMethodResponses[string]","dependencyManager: DependencyManager","transferTypes: TransferTypes","owner: Plugin","#processOk"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-plugin-backbone/src/EndpointMethodResponseProcessor.ts"],"sourcesContent":["import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type { TransferTypes } from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { TypeNode } from 'typescript';\nimport TypeSchemaProcessor from './TypeSchemaProcessor.js';\nimport { defaultMediaType } from './utils.js';\n\nexport type EndpointMethodResponses = OpenAPIV3.ResponsesObject;\nexport type EndpointMethodResponse = OpenAPIV3.ResponseObject;\n\nexport default class EndpointMethodResponseProcessor {\n readonly #code: string;\n readonly #dependencies: DependencyManager;\n readonly #transferTypes: TransferTypes;\n readonly #owner: Plugin;\n readonly #response: EndpointMethodResponse;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n code: string,\n response: EndpointMethodResponses[string],\n dependencyManager: DependencyManager,\n transferTypes: TransferTypes,\n owner: Plugin,\n ) {\n this.#code = code;\n this.#owner = owner;\n this.#dependencies = dependencyManager;\n this.#response = owner.resolver.resolve(response);\n this.#transferTypes = transferTypes;\n }\n\n process(): readonly TypeNode[] {\n switch (this.#code) {\n case '200':\n return this.#processOk();\n default:\n this.#owner.logger.warn(`Response code '${this.#code} is not supported'`);\n return [];\n }\n }\n\n #processOk(): readonly TypeNode[] {\n const rawSchema = this.#response.content?.[defaultMediaType]?.schema;\n\n return rawSchema ? new TypeSchemaProcessor(rawSchema, this.#dependencies, this.#transferTypes).process() : [];\n }\n}\n"],"version":3}
@@ -1,11 +1,10 @@
1
- import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
2
- import { OpenAPIV3 } from 'openapi-types';
3
- import type { ReadonlyDeep } from 'type-fest';
4
- import type { SourceFile } from 'typescript';
1
+ import type Plugin from "@vaadin/hilla-generator-core/Plugin.js";
2
+ import type { SharedStorage } from "@vaadin/hilla-generator-core/SharedStorage.js";
3
+ import { OpenAPIV3 } from "openapi-types";
4
+ import type { SourceFile } from "typescript";
5
5
  export default class EndpointProcessor {
6
- #private;
7
- static create(name: string, owner: Plugin, methods: Map<string, ReadonlyDeep<OpenAPIV3.PathItemObject>>, outputDir?: string): Promise<EndpointProcessor>;
8
- private constructor();
9
- process(): Promise<SourceFile>;
6
+ #private;
7
+ static create(name: string, methods: Map<string, OpenAPIV3.PathItemObject>, storage: SharedStorage, owner: Plugin): Promise<EndpointProcessor>;
8
+ private constructor();
9
+ process(): Promise<SourceFile>;
10
10
  }
11
- //# sourceMappingURL=EndpointProcessor.d.ts.map