@vaadin/hilla-generator-plugin-backbone 24.6.5 → 24.7.0-alpha11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EndpointMethodOperationProcessor.d.ts +3 -5
- package/EndpointMethodOperationProcessor.d.ts.map +1 -1
- package/EndpointMethodOperationProcessor.js +18 -14
- package/EndpointMethodOperationProcessor.js.map +2 -2
- package/EndpointMethodRequestBodyProcessor.d.ts +5 -5
- package/EndpointMethodRequestBodyProcessor.d.ts.map +1 -1
- package/EndpointMethodRequestBodyProcessor.js +15 -10
- package/EndpointMethodRequestBodyProcessor.js.map +2 -2
- package/EndpointMethodResponseProcessor.d.ts +4 -4
- package/EndpointMethodResponseProcessor.d.ts.map +1 -1
- package/EndpointMethodResponseProcessor.js +5 -2
- package/EndpointMethodResponseProcessor.js.map +2 -2
- package/EndpointProcessor.d.ts +2 -2
- package/EndpointProcessor.d.ts.map +1 -1
- package/EndpointProcessor.js +9 -13
- package/EndpointProcessor.js.map +2 -2
- package/EntityProcessor.d.ts +2 -1
- package/EntityProcessor.d.ts.map +1 -1
- package/EntityProcessor.js +6 -6
- package/EntityProcessor.js.map +2 -2
- package/TypeSchemaProcessor.d.ts +2 -1
- package/TypeSchemaProcessor.d.ts.map +1 -1
- package/TypeSchemaProcessor.js +13 -6
- package/TypeSchemaProcessor.js.map +2 -2
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +4 -3
- package/index.js.map +2 -2
- package/package.json +11 -29
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
|
+
import type { TransferTypes } from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
2
3
|
import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
3
4
|
import { OpenAPIV3 } from 'openapi-types';
|
|
4
|
-
import type { ReadonlyDeep } from 'type-fest';
|
|
5
5
|
import { type Statement } from 'typescript';
|
|
6
|
-
export type EndpointMethodOperation =
|
|
7
|
-
export declare const INIT_TYPE_NAME = "EndpointRequestInit";
|
|
8
|
-
export declare const HILLA_FRONTEND_NAME = "@vaadin/hilla-frontend";
|
|
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;
|
|
8
|
+
static createProcessor(httpMethod: OpenAPIV3.HttpMethods, endpointName: string, endpointMethodName: string, operation: EndpointMethodOperation, dependencies: DependencyManager, transferTypes: TransferTypes, owner: Plugin): EndpointMethodOperationProcessor | undefined;
|
|
11
9
|
abstract process(outputDir?: string): Promise<Statement | undefined>;
|
|
12
10
|
}
|
|
13
11
|
//# sourceMappingURL=EndpointMethodOperationProcessor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EndpointMethodOperationProcessor.d.ts","sourceRoot":"","sources":["src/EndpointMethodOperationProcessor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"EndpointMethodOperationProcessor.d.ts","sourceRoot":"","sources":["src/EndpointMethodOperationProcessor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAEnF,OAAO,KAAK,iBAAiB,MAAM,iEAAiE,CAAC;AAErG,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAW,EAAmB,KAAK,SAAS,EAAiB,MAAM,YAAY,CAAC;AAIhF,MAAM,MAAM,uBAAuB,GAAG,SAAS,CAAC,eAAe,CAAC;AAEhE,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,gCAAgC;IAE5D,MAAM,CAAC,eAAe,CACpB,UAAU,EAAE,SAAS,CAAC,WAAW,EACjC,YAAY,EAAE,MAAM,EACpB,kBAAkB,EAAE,MAAM,EAC1B,SAAS,EAAE,uBAAuB,EAClC,YAAY,EAAE,iBAAiB,EAC/B,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,MAAM,GACZ,gCAAgC,GAAG,SAAS;IAmB/C,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CACrE"}
|
|
@@ -4,19 +4,20 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
4
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
7
|
class EndpointMethodOperationProcessor {
|
|
10
|
-
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
9
|
+
static createProcessor(httpMethod, endpointName, endpointMethodName, operation, dependencies, transferTypes, owner) {
|
|
11
10
|
switch (httpMethod) {
|
|
12
|
-
case OpenAPIV3.HttpMethods.POST:
|
|
11
|
+
case OpenAPIV3.HttpMethods.POST: {
|
|
13
12
|
return new EndpointMethodOperationPOSTProcessor(
|
|
14
13
|
endpointName,
|
|
15
14
|
endpointMethodName,
|
|
16
15
|
operation,
|
|
17
16
|
dependencies,
|
|
17
|
+
transferTypes,
|
|
18
18
|
owner
|
|
19
19
|
);
|
|
20
|
+
}
|
|
20
21
|
default:
|
|
21
22
|
owner.logger.warn(`Processing ${httpMethod.toUpperCase()} currently is not supported`);
|
|
22
23
|
return void 0;
|
|
@@ -25,30 +26,29 @@ class EndpointMethodOperationProcessor {
|
|
|
25
26
|
}
|
|
26
27
|
class EndpointMethodOperationPOSTProcessor extends EndpointMethodOperationProcessor {
|
|
27
28
|
#dependencies;
|
|
29
|
+
#transferTypes;
|
|
28
30
|
#endpointMethodName;
|
|
29
31
|
#endpointName;
|
|
30
32
|
#operation;
|
|
31
33
|
#owner;
|
|
32
|
-
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
35
|
+
constructor(endpointName, endpointMethodName, operation, dependencies, transferTypes, owner) {
|
|
33
36
|
super();
|
|
34
37
|
this.#owner = owner;
|
|
35
38
|
this.#dependencies = dependencies;
|
|
36
39
|
this.#endpointName = endpointName;
|
|
37
40
|
this.#endpointMethodName = endpointMethodName;
|
|
38
41
|
this.#operation = operation;
|
|
42
|
+
this.#transferTypes = transferTypes;
|
|
39
43
|
}
|
|
40
44
|
async process(outputDir) {
|
|
41
45
|
const { exports, imports, paths } = this.#dependencies;
|
|
42
46
|
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
47
|
const { initParam, packedParameters, parameters } = new EndpointMethodRequestBodyProcessor(
|
|
48
48
|
this.#operation.requestBody,
|
|
49
49
|
this.#dependencies,
|
|
50
|
-
this.#
|
|
51
|
-
|
|
50
|
+
this.#transferTypes,
|
|
51
|
+
this.#owner
|
|
52
52
|
).process();
|
|
53
53
|
const methodIdentifier = exports.named.add(this.#endpointMethodName);
|
|
54
54
|
const clientLibIdentifier = imports.default.getIdentifier(
|
|
@@ -78,7 +78,13 @@ class EndpointMethodOperationPOSTProcessor extends EndpointMethodOperationProces
|
|
|
78
78
|
#prepareResponseType() {
|
|
79
79
|
this.#owner.logger.debug(`${this.#endpointName}.${this.#endpointMethodName} POST - processing response type`);
|
|
80
80
|
const responseTypes = Object.entries(this.#operation.responses).flatMap(
|
|
81
|
-
([code, response]) => new EndpointMethodResponseProcessor(
|
|
81
|
+
([code, response]) => new EndpointMethodResponseProcessor(
|
|
82
|
+
code,
|
|
83
|
+
response,
|
|
84
|
+
this.#dependencies,
|
|
85
|
+
this.#transferTypes,
|
|
86
|
+
this.#owner
|
|
87
|
+
).process()
|
|
82
88
|
).filter((value, index, arr) => arr.findIndex((v) => equal(v, value)) === index);
|
|
83
89
|
if (responseTypes.length === 0) {
|
|
84
90
|
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword);
|
|
@@ -87,8 +93,6 @@ class EndpointMethodOperationPOSTProcessor extends EndpointMethodOperationProces
|
|
|
87
93
|
}
|
|
88
94
|
}
|
|
89
95
|
export {
|
|
90
|
-
HILLA_FRONTEND_NAME,
|
|
91
|
-
INIT_TYPE_NAME,
|
|
92
96
|
EndpointMethodOperationProcessor as default
|
|
93
97
|
};
|
|
94
98
|
//# sourceMappingURL=EndpointMethodOperationProcessor.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
5
|
-
"mappings": "
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": "AAGA,OAAO,kBAAkB;AAEzB,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAC1B,OAAO,YAA4D;AACnE,OAAO,wCAAwC;AAC/C,OAAO,qCAAqC;AAI5C,MAAO,iCAAwD;AAAA;AAAA,EAE7D,OAAO,gBACL,YACA,cACA,oBACA,WACA,cACA,eACA,OAC8C;AAC9C,YAAQ,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AmB;AAAA,QACvD;AAAA,QACA;AAAA,MACF,EAAE,OAAO,OAAO;AAAA,IAClB;AAEA,UAAM,eAAe,KAAK,qBAAqB;AAE/C,WAAO,GAAG,QAAQ;AAAA,MAChB,CAAC,GAAG,QAAQ,YAAY,GAAG,WAAW,YAAY,CAAC;AAAA,MACnD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG,QAAQ,wBAAwB,WAAW,CAAC,YAAY,CAAC;AAAA,MAC5D,GAAG,QAAQ,YAAY,CAAC,GAAG,QAAQ,sBAAsB,cAAc,CAAC,CAAC;AAAA,IAC3E;AAAA,EACF;AAAA,EAEA,uBAAiC;AAC/B,SAAK,OAAO,OAAO,MAAM,GAAG,KAAK,aAAa,IAAI,KAAK,mBAAmB,kCAAkC;AAE5G,UAAM,gBAAgB,OAAO,QAAQ,KAAK,WAAW,SAAS,EAC3D;AAAA,MAAQ,CAAC,CAAC,MAAM,QAAQ,MACvB,IAAI;AAAA,QACF;AAAA,QACA;AAAA,QACA,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,MACP,EAAE,QAAQ;AAAA,IACZ,EACC,OAAO,CAAC,OAAO,OAAO,QAAQ,IAAI,UAAU,CAAC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,KAAK;AAEhF,QAAI,cAAc,WAAW,GAAG;AAC9B,aAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,WAAW;AAAA,IACnE;AAEA,WAAO,GAAG,QAAQ,oBAAoB,aAAa;AAAA,EACrD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
|
+
import type { TransferTypes } from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
2
3
|
import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
3
4
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
4
|
-
import type
|
|
5
|
-
|
|
6
|
-
export type EndpointMethodRequestBody = ReadonlyDeep<OpenAPIV3.RequestBodyObject>;
|
|
5
|
+
import { type Identifier, type ObjectLiteralExpression, type ParameterDeclaration } from 'typescript';
|
|
6
|
+
export type EndpointMethodRequestBody = OpenAPIV3.RequestBodyObject;
|
|
7
7
|
export type EndpointMethodRequestBodyProcessingResult = Readonly<{
|
|
8
8
|
parameters: readonly ParameterDeclaration[];
|
|
9
9
|
packedParameters?: ObjectLiteralExpression;
|
|
10
|
-
initParam:
|
|
10
|
+
initParam: Identifier;
|
|
11
11
|
}>;
|
|
12
12
|
export default class EndpointMethodRequestBodyProcessor {
|
|
13
13
|
#private;
|
|
14
|
-
constructor(requestBody:
|
|
14
|
+
constructor(requestBody: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject | undefined, dependencies: DependencyManager, transferTypes: TransferTypes, owner: Plugin);
|
|
15
15
|
process(): EndpointMethodRequestBodyProcessingResult;
|
|
16
16
|
}
|
|
17
17
|
//# sourceMappingURL=EndpointMethodRequestBodyProcessor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EndpointMethodRequestBodyProcessor.d.ts","sourceRoot":"","sources":["src/EndpointMethodRequestBodyProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AAOjE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"EndpointMethodRequestBodyProcessor.d.ts","sourceRoot":"","sources":["src/EndpointMethodRequestBodyProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AAOjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AACnF,OAAO,KAAK,iBAAiB,MAAM,iEAAiE,CAAC;AACrG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAW,EAAE,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAI1G,MAAM,MAAM,yBAAyB,GAAG,SAAS,CAAC,iBAAiB,CAAC;AAEpE,MAAM,MAAM,yCAAyC,GAAG,QAAQ,CAAC;IAC/D,UAAU,EAAE,SAAS,oBAAoB,EAAE,CAAC;IAC5C,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;IAC3C,SAAS,EAAE,UAAU,CAAC;CACvB,CAAC,CAAC;AAMH,MAAM,CAAC,OAAO,OAAO,kCAAkC;;gBAOnD,WAAW,EAAE,SAAS,CAAC,eAAe,GAAG,SAAS,CAAC,iBAAiB,GAAG,SAAS,EAChF,YAAY,EAAE,iBAAiB,EAC/B,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,MAAM;IAQf,OAAO,IAAI,yCAAyC;CA4ErD"}
|
|
@@ -5,37 +5,42 @@ import {
|
|
|
5
5
|
import ts, {} from "typescript";
|
|
6
6
|
import TypeSchemaProcessor from "./TypeSchemaProcessor.js";
|
|
7
7
|
import { defaultMediaType } from "./utils.js";
|
|
8
|
+
const DEFAULT_INIT_PARAM_NAME = "init";
|
|
9
|
+
const INIT_TYPE_NAME = "EndpointRequestInit";
|
|
10
|
+
const HILLA_FRONTEND_NAME = "@vaadin/hilla-frontend";
|
|
8
11
|
class EndpointMethodRequestBodyProcessor {
|
|
9
|
-
static #defaultInitParamName = "init";
|
|
10
12
|
#dependencies;
|
|
13
|
+
#transferTypes;
|
|
11
14
|
#owner;
|
|
12
15
|
#requestBody;
|
|
13
|
-
|
|
14
|
-
constructor(requestBody, dependencies, owner, initTypeIdentifier) {
|
|
16
|
+
constructor(requestBody, dependencies, transferTypes, owner) {
|
|
15
17
|
this.#owner = owner;
|
|
16
18
|
this.#dependencies = dependencies;
|
|
17
19
|
this.#requestBody = requestBody ? owner.resolver.resolve(requestBody) : void 0;
|
|
18
|
-
this.#
|
|
20
|
+
this.#transferTypes = transferTypes;
|
|
19
21
|
}
|
|
20
22
|
process() {
|
|
23
|
+
const { imports, paths } = this.#dependencies;
|
|
24
|
+
const path = paths.createBareModulePath(HILLA_FRONTEND_NAME);
|
|
25
|
+
const initTypeIdentifier = imports.named.getIdentifier(path, INIT_TYPE_NAME) ?? imports.named.add(path, INIT_TYPE_NAME);
|
|
21
26
|
if (!this.#requestBody) {
|
|
22
27
|
return {
|
|
23
|
-
initParam: ts.factory.createIdentifier(
|
|
28
|
+
initParam: ts.factory.createIdentifier(DEFAULT_INIT_PARAM_NAME),
|
|
24
29
|
packedParameters: ts.factory.createObjectLiteralExpression(),
|
|
25
30
|
parameters: [
|
|
26
31
|
ts.factory.createParameterDeclaration(
|
|
27
32
|
void 0,
|
|
28
33
|
void 0,
|
|
29
|
-
|
|
34
|
+
DEFAULT_INIT_PARAM_NAME,
|
|
30
35
|
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
31
|
-
ts.factory.createTypeReferenceNode(
|
|
36
|
+
ts.factory.createTypeReferenceNode(initTypeIdentifier)
|
|
32
37
|
)
|
|
33
38
|
]
|
|
34
39
|
};
|
|
35
40
|
}
|
|
36
41
|
const parameterData = this.#extractParameterData(this.#requestBody.content[defaultMediaType].schema);
|
|
37
42
|
const parameterNames = parameterData.map(([name]) => name);
|
|
38
|
-
let initParamName =
|
|
43
|
+
let initParamName = DEFAULT_INIT_PARAM_NAME;
|
|
39
44
|
while (parameterNames.includes(initParamName)) {
|
|
40
45
|
initParamName = `_${initParamName}`;
|
|
41
46
|
}
|
|
@@ -46,7 +51,7 @@ class EndpointMethodRequestBodyProcessor {
|
|
|
46
51
|
),
|
|
47
52
|
parameters: [
|
|
48
53
|
...parameterData.map(([name, schema]) => {
|
|
49
|
-
const nodes = new TypeSchemaProcessor(schema, this.#dependencies).process();
|
|
54
|
+
const nodes = new TypeSchemaProcessor(schema, this.#dependencies, this.#transferTypes).process();
|
|
50
55
|
return ts.factory.createParameterDeclaration(
|
|
51
56
|
void 0,
|
|
52
57
|
void 0,
|
|
@@ -60,7 +65,7 @@ class EndpointMethodRequestBodyProcessor {
|
|
|
60
65
|
void 0,
|
|
61
66
|
initParamName,
|
|
62
67
|
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
63
|
-
ts.factory.createTypeReferenceNode(
|
|
68
|
+
ts.factory.createTypeReferenceNode(initTypeIdentifier)
|
|
64
69
|
)
|
|
65
70
|
]
|
|
66
71
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
5
|
-
"mappings": "AACA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAIP,OAAO,
|
|
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 { 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"],
|
|
5
|
+
"mappings": "AACA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAIP,OAAO,YAAsF;AAC7F,OAAO,yBAAyB;AAChC,SAAS,wBAAwB;AAUjC,MAAM,0BAA0B;AAChC,MAAM,iBAAiB;AACvB,MAAM,sBAAsB;AAE5B,MAAO,mCAAiD;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,aACA,cACA,eACA,OACA;AACA,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB,SAAK,eAAe,cAAc,MAAM,SAAS,QAAQ,WAAW,IAAI;AACxE,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAEA,UAAqD;AACnD,UAAM,EAAE,SAAS,MAAM,IAAI,KAAK;AAChC,UAAM,OAAO,MAAM,qBAAqB,mBAAmB;AAC3D,UAAM,qBACJ,QAAQ,MAAM,cAAc,MAAM,cAAc,KAAK,QAAQ,MAAM,IAAI,MAAM,cAAc;AAE7F,QAAI,CAAC,KAAK,cAAc;AACtB,aAAO;AAAA,QACL,WAAW,GAAG,QAAQ,iBAAiB,uBAAuB;AAAA,QAC9D,kBAAkB,GAAG,QAAQ,8BAA8B;AAAA,QAC3D,YAAY;AAAA,UACV,GAA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AQ,WAAW;AAEnD,QAAI,eAAe,cAAc,KAAK,CAAC,cAAc,cAAc,GAAG;AACpE,aAAO,OAAO,QAAS,eAAwC,UAAU;AAAA,IAC3E;AAEA,WAAO,KAAK,wEAAwE;AACpF,WAAO,CAAC;AAAA,EACV;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
|
+
import type { TransferTypes } from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
2
3
|
import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
3
4
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
4
|
-
import type { ReadonlyDeep } from 'type-fest';
|
|
5
5
|
import type { TypeNode } from 'typescript';
|
|
6
|
-
export type EndpointMethodResponses =
|
|
7
|
-
export type EndpointMethodResponse =
|
|
6
|
+
export type EndpointMethodResponses = OpenAPIV3.ResponsesObject;
|
|
7
|
+
export type EndpointMethodResponse = OpenAPIV3.ResponseObject;
|
|
8
8
|
export default class EndpointMethodResponseProcessor {
|
|
9
9
|
#private;
|
|
10
|
-
constructor(code: string, response: EndpointMethodResponses[string], dependencyManager: DependencyManager, owner: Plugin);
|
|
10
|
+
constructor(code: string, response: EndpointMethodResponses[string], dependencyManager: DependencyManager, transferTypes: TransferTypes, owner: Plugin);
|
|
11
11
|
process(): readonly TypeNode[];
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=EndpointMethodResponseProcessor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EndpointMethodResponseProcessor.d.ts","sourceRoot":"","sources":["src/EndpointMethodResponseProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AACjE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"EndpointMethodResponseProcessor.d.ts","sourceRoot":"","sources":["src/EndpointMethodResponseProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AACnF,OAAO,KAAK,iBAAiB,MAAM,iEAAiE,CAAC;AACrG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C,MAAM,MAAM,uBAAuB,GAAG,SAAS,CAAC,eAAe,CAAC;AAChE,MAAM,MAAM,sBAAsB,GAAG,SAAS,CAAC,cAAc,CAAC;AAE9D,MAAM,CAAC,OAAO,OAAO,+BAA+B;;gBAShD,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,uBAAuB,CAAC,MAAM,CAAC,EACzC,iBAAiB,EAAE,iBAAiB,EACpC,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,MAAM;IASf,OAAO,IAAI,SAAS,QAAQ,EAAE;CAe/B"}
|
|
@@ -3,13 +3,16 @@ import { defaultMediaType } from "./utils.js";
|
|
|
3
3
|
class EndpointMethodResponseProcessor {
|
|
4
4
|
#code;
|
|
5
5
|
#dependencies;
|
|
6
|
+
#transferTypes;
|
|
6
7
|
#owner;
|
|
7
8
|
#response;
|
|
8
|
-
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
10
|
+
constructor(code, response, dependencyManager, transferTypes, owner) {
|
|
9
11
|
this.#code = code;
|
|
10
12
|
this.#owner = owner;
|
|
11
13
|
this.#dependencies = dependencyManager;
|
|
12
14
|
this.#response = owner.resolver.resolve(response);
|
|
15
|
+
this.#transferTypes = transferTypes;
|
|
13
16
|
}
|
|
14
17
|
process() {
|
|
15
18
|
switch (this.#code) {
|
|
@@ -22,7 +25,7 @@ class EndpointMethodResponseProcessor {
|
|
|
22
25
|
}
|
|
23
26
|
#processOk() {
|
|
24
27
|
const rawSchema = this.#response.content?.[defaultMediaType]?.schema;
|
|
25
|
-
return rawSchema ? new TypeSchemaProcessor(rawSchema, this.#dependencies).process() : [];
|
|
28
|
+
return rawSchema ? new TypeSchemaProcessor(rawSchema, this.#dependencies, this.#transferTypes).process() : [];
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/EndpointMethodResponseProcessor.ts"],
|
|
4
|
-
"sourcesContent": ["import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type
|
|
5
|
-
"mappings": "AAKA,OAAO,yBAAyB;AAChC,SAAS,wBAAwB;AAKjC,MAAO,gCAA8C;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": "AAKA,OAAO,yBAAyB;AAChC,SAAS,wBAAwB;AAKjC,MAAO,gCAA8C;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGT,YACE,MACA,UACA,mBACA,eACA,OACA;AACA,SAAK,QAAQ;AACb,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB,SAAK,YAAY,MAAM,SAAS,QAAQ,QAAQ;AAChD,SAAK,iBAAiB;AAAA,EACxB;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,eAAe,KAAK,cAAc,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC9G;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/EndpointProcessor.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
|
+
import type { SharedStorage } from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
2
3
|
import { OpenAPIV3 } from 'openapi-types';
|
|
3
|
-
import type { ReadonlyDeep } from 'type-fest';
|
|
4
4
|
import type { SourceFile } from 'typescript';
|
|
5
5
|
export default class EndpointProcessor {
|
|
6
6
|
#private;
|
|
7
|
-
static create(name: string,
|
|
7
|
+
static create(name: string, methods: Map<string, OpenAPIV3.PathItemObject>, storage: SharedStorage, owner: Plugin): Promise<EndpointProcessor>;
|
|
8
8
|
private constructor();
|
|
9
9
|
process(): Promise<SourceFile>;
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EndpointProcessor.d.ts","sourceRoot":"","sources":["src/EndpointProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"EndpointProcessor.d.ts","sourceRoot":"","sources":["src/EndpointProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,+CAA+C,CAAC;AAKlG,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,YAAY,CAAC;AAGxD,MAAM,CAAC,OAAO,OAAO,iBAAiB;;WACvB,MAAM,CACjB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,EAC9C,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,iBAAiB,CAAC;IAiB7B,OAAO;IAaD,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;CAoCrC"}
|
package/EndpointProcessor.js
CHANGED
|
@@ -3,21 +3,14 @@ import createSourceFile from "@vaadin/hilla-generator-utils/createSourceFile.js"
|
|
|
3
3
|
import DependencyManager from "@vaadin/hilla-generator-utils/dependencies/DependencyManager.js";
|
|
4
4
|
import PathManager from "@vaadin/hilla-generator-utils/dependencies/PathManager.js";
|
|
5
5
|
import { OpenAPIV3 } from "openapi-types";
|
|
6
|
-
import EndpointMethodOperationProcessor
|
|
7
|
-
HILLA_FRONTEND_NAME,
|
|
8
|
-
INIT_TYPE_NAME
|
|
9
|
-
} from "./EndpointMethodOperationProcessor.js";
|
|
6
|
+
import EndpointMethodOperationProcessor from "./EndpointMethodOperationProcessor.js";
|
|
10
7
|
class EndpointProcessor {
|
|
11
|
-
static async create(name,
|
|
12
|
-
const endpoint = new EndpointProcessor(name,
|
|
8
|
+
static async create(name, methods, storage, owner) {
|
|
9
|
+
const endpoint = new EndpointProcessor(name, methods, storage, owner);
|
|
13
10
|
endpoint.#dependencies.imports.default.add(
|
|
14
|
-
endpoint.#dependencies.paths.createRelativePath(await ClientPlugin.getClientFileName(outputDir)),
|
|
11
|
+
endpoint.#dependencies.paths.createRelativePath(await ClientPlugin.getClientFileName(storage.outputDir)),
|
|
15
12
|
"client"
|
|
16
13
|
);
|
|
17
|
-
endpoint.#dependencies.imports.named.add(
|
|
18
|
-
endpoint.#dependencies.paths.createBareModulePath(HILLA_FRONTEND_NAME),
|
|
19
|
-
INIT_TYPE_NAME
|
|
20
|
-
);
|
|
21
14
|
return endpoint;
|
|
22
15
|
}
|
|
23
16
|
#createdFilePaths = new PathManager({ extension: "ts" });
|
|
@@ -25,12 +18,14 @@ class EndpointProcessor {
|
|
|
25
18
|
#methods;
|
|
26
19
|
#name;
|
|
27
20
|
#outputDir;
|
|
21
|
+
#transferTypes;
|
|
28
22
|
#owner;
|
|
29
|
-
constructor(name,
|
|
23
|
+
constructor(name, methods, storage, owner) {
|
|
30
24
|
this.#name = name;
|
|
31
25
|
this.#owner = owner;
|
|
32
26
|
this.#methods = methods;
|
|
33
|
-
this.#outputDir = outputDir;
|
|
27
|
+
this.#outputDir = storage.outputDir;
|
|
28
|
+
this.#transferTypes = storage.transferTypes;
|
|
34
29
|
}
|
|
35
30
|
async process() {
|
|
36
31
|
this.#owner.logger.debug(`Processing endpoint: ${this.#name}`);
|
|
@@ -51,6 +46,7 @@ class EndpointProcessor {
|
|
|
51
46
|
method,
|
|
52
47
|
pathItem[httpMethod],
|
|
53
48
|
this.#dependencies,
|
|
49
|
+
this.#transferTypes,
|
|
54
50
|
this.#owner
|
|
55
51
|
)?.process(this.#outputDir)
|
|
56
52
|
)
|
package/EndpointProcessor.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/EndpointProcessor.ts"],
|
|
4
|
-
"sourcesContent": ["import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport ClientPlugin from '@vaadin/hilla-generator-plugin-client';\nimport createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport { OpenAPIV3 } from 'openapi-types';\nimport type {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type { SharedStorage, TransferTypes } from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport ClientPlugin from '@vaadin/hilla-generator-plugin-client';\nimport createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport { OpenAPIV3 } from 'openapi-types';\nimport type { SourceFile, Statement } from 'typescript';\nimport EndpointMethodOperationProcessor from './EndpointMethodOperationProcessor.js';\n\nexport default class EndpointProcessor {\n static async create(\n name: string,\n methods: Map<string, OpenAPIV3.PathItemObject>,\n storage: SharedStorage,\n owner: Plugin,\n ): Promise<EndpointProcessor> {\n const endpoint = new EndpointProcessor(name, methods, storage, owner);\n endpoint.#dependencies.imports.default.add(\n endpoint.#dependencies.paths.createRelativePath(await ClientPlugin.getClientFileName(storage.outputDir)),\n 'client',\n );\n return endpoint;\n }\n\n readonly #createdFilePaths = new PathManager({ extension: 'ts' });\n readonly #dependencies = new DependencyManager(new PathManager({ extension: '.js' }));\n readonly #methods: Map<string, OpenAPIV3.PathItemObject>;\n readonly #name: string;\n readonly #outputDir: string | undefined;\n readonly #transferTypes: TransferTypes;\n readonly #owner: Plugin;\n\n private constructor(\n name: string,\n methods: Map<string, OpenAPIV3.PathItemObject>,\n storage: SharedStorage,\n owner: Plugin,\n ) {\n this.#name = name;\n this.#owner = owner;\n this.#methods = methods;\n this.#outputDir = storage.outputDir;\n this.#transferTypes = storage.transferTypes;\n }\n\n async process(): Promise<SourceFile> {\n this.#owner.logger.debug(`Processing endpoint: ${this.#name}`);\n\n const statements = (\n await Promise.all(Array.from(this.#methods, async ([method, pathItem]) => this.#processMethod(method, pathItem)))\n ).flatMap((item) => item);\n\n const { exports, imports } = this.#dependencies;\n\n return createSourceFile(\n [...imports.toCode(), ...statements, ...exports.toCode()],\n this.#createdFilePaths.createRelativePath(this.#name),\n );\n }\n\n async #processMethod(method: string, pathItem: OpenAPIV3.PathItemObject): Promise<readonly Statement[]> {\n this.#owner.logger.debug(`Processing endpoint method: ${this.#name}.${method}`);\n\n return (\n await Promise.all(\n Object.values(OpenAPIV3.HttpMethods)\n .filter((httpMethod) => pathItem[httpMethod])\n .map(async (httpMethod) =>\n EndpointMethodOperationProcessor.createProcessor(\n httpMethod,\n this.#name,\n method,\n pathItem[httpMethod]!,\n this.#dependencies,\n this.#transferTypes,\n this.#owner,\n )?.process(this.#outputDir),\n ),\n )\n ).filter(Boolean) as readonly Statement[];\n }\n}\n"],
|
|
5
|
+
"mappings": "AAEA,OAAO,kBAAkB;AACzB,OAAO,sBAAsB;AAC7B,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AACxB,SAAS,iBAAiB;AAE1B,OAAO,sCAAsC;AAE7C,MAAO,kBAAgC;AAAA,EACrC,aAAa,OACX,MACA,SACA,SACA,OAC4B;AAC5B,UAAM,WAAW,IAAI,kBAAkB,MAAM,SAAS,SAAS,KAAK;AACpE,aAAS,cAAc,QAAQ,QAAQ;AAAA,MACrC,SA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AAAA,UACL,KAAK;AAAA,UACL,KAAK;AAAA,QACP,GAAG,QAAQ,KAAK,UAAU;AAAA,MAC5B;AAAA,IACJ,GACA,OAAO,OAAO;AAAA,EAClB;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/EntityProcessor.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
2
|
import { type Schema } from '@vaadin/hilla-generator-core/Schema.js';
|
|
3
|
+
import type { SharedStorage } from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
3
4
|
import { type SourceFile } from 'typescript';
|
|
4
5
|
export declare class EntityProcessor {
|
|
5
6
|
#private;
|
|
6
|
-
constructor(name: string, component: Schema, owner: Plugin);
|
|
7
|
+
constructor(name: string, component: Schema, storage: SharedStorage, owner: Plugin);
|
|
7
8
|
process(): SourceFile;
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=EntityProcessor.d.ts.map
|
package/EntityProcessor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityProcessor.d.ts","sourceRoot":"","sources":["src/EntityProcessor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAGL,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"EntityProcessor.d.ts","sourceRoot":"","sources":["src/EntityProcessor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAGL,KAAK,MAAM,EAaZ,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,+CAA+C,CAAC;AAIlG,OAAW,EAGT,KAAK,UAAU,EAIhB,MAAM,YAAY,CAAC;AAIpB,qBAAa,eAAe;;gBAUd,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM;IAkBlF,OAAO,IAAI,UAAU;CA4HtB"}
|
package/EntityProcessor.js
CHANGED
|
@@ -8,12 +8,10 @@ import {
|
|
|
8
8
|
isEnumSchema,
|
|
9
9
|
isNullableSchema,
|
|
10
10
|
isObjectSchema,
|
|
11
|
-
isReferenceSchema
|
|
12
|
-
} from "@vaadin/hilla-generator-core/Schema.js";
|
|
13
|
-
import {
|
|
11
|
+
isReferenceSchema,
|
|
14
12
|
convertFullyQualifiedNameToRelativePath,
|
|
15
13
|
simplifyFullyQualifiedName
|
|
16
|
-
} from "@vaadin/hilla-generator-core/
|
|
14
|
+
} from "@vaadin/hilla-generator-core/Schema.js";
|
|
17
15
|
import createSourceFile from "@vaadin/hilla-generator-utils/createSourceFile.js";
|
|
18
16
|
import DependencyManager from "@vaadin/hilla-generator-utils/dependencies/DependencyManager.js";
|
|
19
17
|
import PathManager from "@vaadin/hilla-generator-utils/dependencies/PathManager.js";
|
|
@@ -27,15 +25,17 @@ class EntityProcessor {
|
|
|
27
25
|
#fullyQualifiedName;
|
|
28
26
|
#name;
|
|
29
27
|
#outputPathManager = new PathManager({ extension: "ts" });
|
|
28
|
+
#transferTypes;
|
|
30
29
|
#owner;
|
|
31
30
|
#path;
|
|
32
|
-
constructor(name, component, owner) {
|
|
31
|
+
constructor(name, component, storage, owner) {
|
|
33
32
|
this.#component = component;
|
|
34
33
|
this.#owner = owner;
|
|
35
34
|
this.#fullyQualifiedName = name;
|
|
36
35
|
this.#name = simplifyFullyQualifiedName(name);
|
|
37
36
|
this.#path = convertFullyQualifiedNameToRelativePath(name);
|
|
38
37
|
this.#dependencies = new DependencyManager(new PathManager({ extension: ".js", relativeTo: dirname(this.#path) }));
|
|
38
|
+
this.#transferTypes = storage.transferTypes;
|
|
39
39
|
}
|
|
40
40
|
get #id() {
|
|
41
41
|
const id = ts.factory.createIdentifier(this.#name);
|
|
@@ -117,7 +117,7 @@ class EntityProcessor {
|
|
|
117
117
|
}
|
|
118
118
|
#processTypeElements({ properties }) {
|
|
119
119
|
return Object.entries(properties ?? {}).map(([name, schema]) => {
|
|
120
|
-
const [type] = new TypeSchemaProcessor(schema, this.#dependencies).process();
|
|
120
|
+
const [type] = new TypeSchemaProcessor(schema, this.#dependencies, this.#transferTypes).process();
|
|
121
121
|
return ts.factory.createPropertySignature(
|
|
122
122
|
void 0,
|
|
123
123
|
name,
|
package/EntityProcessor.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/EntityProcessor.ts"],
|
|
4
|
-
"sourcesContent": ["import { dirname } from 'path/posix';\nimport type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport {\n type EnumSchema,\n type ReferenceSchema,\n type Schema,\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n isComposedSchema,\n isEmptyObject,\n isEnumSchema,\n isNullableSchema,\n isObjectSchema,\n isReferenceSchema,\n type ObjectSchema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,eAAe;AAExB;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { dirname } from 'path/posix';\nimport type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport {\n type EnumSchema,\n type ReferenceSchema,\n type Schema,\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n isComposedSchema,\n isEmptyObject,\n isEnumSchema,\n isNullableSchema,\n isObjectSchema,\n isReferenceSchema,\n type ObjectSchema,\n convertFullyQualifiedNameToRelativePath,\n simplifyFullyQualifiedName,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport type { SharedStorage, TransferTypes } from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport ts, {\n type Identifier,\n type InterfaceDeclaration,\n type SourceFile,\n type Statement,\n type TypeElement,\n type TypeParameterDeclaration,\n} from 'typescript';\nimport TypeSchemaProcessor from './TypeSchemaProcessor.js';\nimport { findTypeParameters } from './utils.js';\n\nexport class EntityProcessor {\n readonly #component: Schema;\n readonly #dependencies;\n readonly #fullyQualifiedName: string;\n readonly #name: string;\n readonly #outputPathManager = new PathManager({ extension: 'ts' });\n readonly #transferTypes: TransferTypes;\n readonly #owner: Plugin;\n readonly #path: string;\n\n constructor(name: string, component: Schema, storage: SharedStorage, owner: Plugin) {\n this.#component = component;\n this.#owner = owner;\n this.#fullyQualifiedName = name;\n this.#name = simplifyFullyQualifiedName(name);\n this.#path = convertFullyQualifiedNameToRelativePath(name);\n this.#dependencies = new DependencyManager(new PathManager({ extension: '.js', relativeTo: dirname(this.#path) }));\n this.#transferTypes = storage.transferTypes;\n }\n\n get #id(): Identifier {\n const id = ts.factory.createIdentifier(this.#name);\n\n this.#dependencies.exports.default.set(id);\n\n return id;\n }\n\n process(): SourceFile {\n this.#owner.logger.debug(`Processing entity: ${this.#name}`);\n\n const declaration = isEnumSchema(this.#component)\n ? this.#processEnum(this.#component)\n : this.#processExtendedClass(this.#component);\n\n const statements = declaration ? [declaration] : [];\n\n const { exports, imports } = this.#dependencies;\n\n return createSourceFile(\n [...imports.toCode(), ...statements, ...exports.toCode()],\n this.#outputPathManager.createRelativePath(this.#path),\n );\n }\n\n #processClass(schema: Schema): InterfaceDeclaration | undefined {\n const { logger } = this.#owner;\n\n if (!isObjectSchema(schema)) {\n logger.debug(schema, `Component is not an object: '${this.#fullyQualifiedName}'`);\n return undefined;\n }\n\n if (isEmptyObject(schema)) {\n logger.debug(`Component has no properties:' ${this.#fullyQualifiedName}'`);\n }\n\n return ts.factory.createInterfaceDeclaration(\n undefined,\n this.#id,\n EntityProcessor.#processTypeParameters(schema),\n undefined,\n this.#processTypeElements(schema as ObjectSchema),\n );\n }\n\n #processEnum({ enum: members }: EnumSchema): Statement {\n return ts.factory.createEnumDeclaration(\n undefined,\n this.#id,\n members.map((member) => ts.factory.createEnumMember(member, ts.factory.createStringLiteral(member))),\n );\n }\n\n #processExtendedClass(schema: Schema): Statement | undefined {\n const { logger } = this.#owner;\n\n if (isComposedSchema(schema)) {\n const decomposed = decomposeSchema(schema);\n\n if (decomposed.length > 2) {\n logger.debug(\n schema,\n `Schema for '${this.#fullyQualifiedName}' has more than two components. This plugin will ignore it.`,\n );\n return undefined;\n }\n\n const [parent, child] = decomposed;\n\n if (!isReferenceSchema(parent)) {\n logger.debug(parent, 'Only reference schema allowed for parent class');\n return undefined;\n }\n\n const declaration = this.#processClass(child);\n const identifier = this.#processParentClass(parent);\n\n return (\n declaration &&\n ts.factory.updateInterfaceDeclaration(\n declaration,\n declaration.modifiers,\n declaration.name,\n declaration.typeParameters,\n [\n ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [\n ts.factory.createExpressionWithTypeArguments(identifier, undefined),\n ]),\n ],\n declaration.members,\n )\n );\n }\n\n return this.#processClass(schema);\n }\n\n #processParentClass(schema: ReferenceSchema): Identifier {\n const { imports, paths } = this.#dependencies;\n\n const specifier = convertReferenceSchemaToSpecifier(schema);\n const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));\n\n return imports.default.getIdentifier(path) ?? imports.default.add(path, specifier, true);\n }\n\n #processTypeElements({ properties }: ObjectSchema): readonly TypeElement[] {\n return Object.entries(properties ?? {}).map(([name, schema]) => {\n const [type] = new TypeSchemaProcessor(schema, this.#dependencies, this.#transferTypes).process();\n\n return ts.factory.createPropertySignature(\n undefined,\n name,\n isNullableSchema(schema) ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : undefined,\n type,\n );\n });\n }\n\n static #processTypeParameters(schema: Schema): readonly TypeParameterDeclaration[] | undefined {\n return findTypeParameters(schema)\n ?.map(String)\n .map((name) =>\n ts.factory.createTypeParameterDeclaration(\n undefined,\n name,\n undefined,\n ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n ),\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,eAAe;AAExB;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AAEP,OAAO,sBAAsB;AAC7B,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AACxB,OAAO;AAAA,OAOA;AACP,OAAO,yBAAyB;AAChC,SAAS,0BAA0B;AAE5B,MAAM,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAAqB,IAAI,YAAY,EAAE,WAAW,KAAK,CAAC;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,MAAc,WAAmB,SAAwB,OAAe;AAClF,SAAK,aAAa;AAClB,SAAK,SAAS;AACd,SAAK,sBAAsB;AAC3B,SAAK,QAAQ,2BAA2B,IAAI;AAC5C,SAAK,QAAQ,wCAAwC,IAAI;AACzD,SAAK,gBAAgB,IAAI,kBAAkB,IAAI,YAAY,EAAE,WAAW,OAAO,YAAY,QAAQ,KAAK,KAAK,EAAE,CAAC,CAAC;AACjH,SAAK,iBAAiB,QAAQ;AAAA,EAChC;AAAA,EAEA,IAAI,MAAkB;AACpB,UAAM,KAAK,GAAG,QAAQ,iBAAiB,KAAK,KAAK;AAEjD,SAAK,cAAc,QAAQ,QAAQ,IAAI,EAAE;AAEzC,WAAO;AAAA,EACT;AAAA,EAEA,UAAsB;AACpB,SAAK,OAAO,OAAO,MAAM,sBAAsB,KAAK,KAAK,EAAE;AAE3D,UAAM,cAAc,aAAa,KAAK,UAAU,IAC5C,KAAK,aAAa,KAAK,UAAU,IAC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AAG,QAAQ;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAG,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AAAA,MAC/D;AAAA,IACF;AAAA,EACJ;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/TypeSchemaProcessor.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type Schema } from '@vaadin/hilla-generator-core/Schema.js';
|
|
2
|
+
import type { TransferTypeMaker } from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
2
3
|
import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
3
4
|
import { type TypeNode } from 'typescript';
|
|
4
5
|
export default class TypeSchemaProcessor {
|
|
5
6
|
#private;
|
|
6
7
|
['constructor']: typeof TypeSchemaProcessor;
|
|
7
|
-
constructor(schema: Schema, dependencies: DependencyManager);
|
|
8
|
+
constructor(schema: Schema, dependencies: DependencyManager, transferTypes: Map<string, TransferTypeMaker>);
|
|
8
9
|
process(): readonly TypeNode[];
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=TypeSchemaProcessor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSchemaProcessor.d.ts","sourceRoot":"","sources":["src/TypeSchemaProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"TypeSchemaProcessor.d.ts","sourceRoot":"","sources":["src/TypeSchemaProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAkBL,KAAK,MAAM,EACZ,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,KAAK,iBAAiB,MAAM,iEAAiE,CAAC;AACrG,OAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAiC/C,MAAM,CAAC,OAAO,OAAO,mBAAmB;;IAC9B,CAAC,aAAa,CAAC,EAAE,OAAO,mBAAmB,CAAC;gBAKxC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC;IAM1G,OAAO,IAAI,SAAS,QAAQ,EAAE;CA4E/B"}
|
package/TypeSchemaProcessor.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
convertFullyQualifiedNameToRelativePath,
|
|
3
|
+
convertReferenceSchemaToFullyQualifiedName,
|
|
3
4
|
convertReferenceSchemaToSpecifier,
|
|
4
5
|
decomposeSchema,
|
|
5
6
|
isArraySchema,
|
|
@@ -39,9 +40,11 @@ function unwrapPossiblyNullableSchema(schema) {
|
|
|
39
40
|
class TypeSchemaProcessor {
|
|
40
41
|
#dependencies;
|
|
41
42
|
#schema;
|
|
42
|
-
|
|
43
|
+
#transferTypes;
|
|
44
|
+
constructor(schema, dependencies, transferTypes) {
|
|
43
45
|
this.#schema = schema;
|
|
44
46
|
this.#dependencies = dependencies;
|
|
47
|
+
this.#transferTypes = transferTypes;
|
|
45
48
|
}
|
|
46
49
|
process() {
|
|
47
50
|
let node;
|
|
@@ -69,13 +72,13 @@ class TypeSchemaProcessor {
|
|
|
69
72
|
return isNullableSchema(this.#schema) ? [node, createUndefined()] : [node];
|
|
70
73
|
}
|
|
71
74
|
#processArray(schema) {
|
|
72
|
-
const nodes = new TypeSchemaProcessor(schema.items, this.#dependencies).process();
|
|
75
|
+
const nodes = new TypeSchemaProcessor(schema.items, this.#dependencies, this.#transferTypes).process();
|
|
73
76
|
return ts.factory.createTypeReferenceNode("Array", [ts.factory.createUnionTypeNode(nodes)]);
|
|
74
77
|
}
|
|
75
78
|
#processMap({ additionalProperties: valuesType }) {
|
|
76
79
|
let valuesTypeNode;
|
|
77
80
|
if (typeof valuesType !== "boolean") {
|
|
78
|
-
const nodes = new TypeSchemaProcessor(valuesType, this.#dependencies).process();
|
|
81
|
+
const nodes = new TypeSchemaProcessor(valuesType, this.#dependencies, this.#transferTypes).process();
|
|
79
82
|
valuesTypeNode = ts.factory.createUnionTypeNode(nodes);
|
|
80
83
|
} else {
|
|
81
84
|
valuesTypeNode = ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);
|
|
@@ -86,12 +89,16 @@ class TypeSchemaProcessor {
|
|
|
86
89
|
]);
|
|
87
90
|
}
|
|
88
91
|
#processTypeArguments(schema) {
|
|
89
|
-
return findTypeArguments(schema)?.allOf.map((s) => new TypeSchemaProcessor(s, this.#dependencies).process()).map((t) => ts.factory.createUnionTypeNode(t));
|
|
92
|
+
return findTypeArguments(schema)?.allOf.map((s) => new TypeSchemaProcessor(s, this.#dependencies, this.#transferTypes).process()).map((t) => ts.factory.createUnionTypeNode(t));
|
|
90
93
|
}
|
|
91
94
|
#processReference(schema, typeArguments) {
|
|
92
95
|
const { imports, paths } = this.#dependencies;
|
|
96
|
+
const fullyQualifiedName = convertReferenceSchemaToFullyQualifiedName(schema);
|
|
97
|
+
if (this.#transferTypes.has(fullyQualifiedName)) {
|
|
98
|
+
return this.#transferTypes.get(fullyQualifiedName)(typeArguments);
|
|
99
|
+
}
|
|
93
100
|
const specifier = convertReferenceSchemaToSpecifier(schema);
|
|
94
|
-
const path = paths.createRelativePath(
|
|
101
|
+
const path = paths.createRelativePath(convertFullyQualifiedNameToRelativePath(fullyQualifiedName));
|
|
95
102
|
const identifier = imports.default.getIdentifier(path) ?? imports.default.add(path, specifier, true);
|
|
96
103
|
return ts.factory.createTypeReferenceNode(identifier, typeArguments);
|
|
97
104
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/TypeSchemaProcessor.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ArraySchema,\n
|
|
5
|
-
"mappings": "AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;
|
|
4
|
+
"sourcesContent": ["import {\n type ArraySchema,\n convertFullyQualifiedNameToRelativePath,\n convertReferenceSchemaToFullyQualifiedName,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n isArraySchema,\n isBooleanSchema,\n isComposedSchema,\n isIntegerSchema,\n isMapSchema,\n isNullableSchema,\n isNumberSchema,\n isReferenceSchema,\n isStringSchema,\n type MapSchema,\n type NonComposedSchema,\n type ReferenceSchema,\n type Schema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport type { TransferTypeMaker } from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport ts, { type TypeNode } from 'typescript';\nimport { findTypeArguments, findTypeVariable } from './utils.js';\n\nfunction createBoolean(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword);\n}\n\nfunction createNumber(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);\n}\n\nfunction createString(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);\n}\n\nfunction createUndefined(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);\n}\n\nfunction createUnknown(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n}\n\nfunction unwrapPossiblyNullableSchema(schema: Schema): NonComposedSchema {\n if (isComposedSchema(schema)) {\n const [result] = decomposeSchema(schema);\n\n return result as NonComposedSchema;\n }\n\n return schema as NonComposedSchema;\n}\n\nexport default class TypeSchemaProcessor {\n declare ['constructor']: typeof TypeSchemaProcessor;\n readonly #dependencies: DependencyManager;\n readonly #schema: Schema;\n readonly #transferTypes: Map<string, TransferTypeMaker>;\n\n constructor(schema: Schema, dependencies: DependencyManager, transferTypes: Map<string, TransferTypeMaker>) {\n this.#schema = schema;\n this.#dependencies = dependencies;\n this.#transferTypes = transferTypes;\n }\n\n process(): readonly TypeNode[] {\n let node: TypeNode;\n\n const unwrappedSchema = unwrapPossiblyNullableSchema(this.#schema);\n\n const typeVariable = findTypeVariable(this.#schema);\n if (typeVariable) {\n // Type variables are returned directly as they are, no further processing is needed\n return [ts.factory.createTypeReferenceNode(typeVariable)];\n }\n\n if (isReferenceSchema(unwrappedSchema)) {\n const typeArguments = this.#processTypeArguments(this.#schema);\n node = this.#processReference(unwrappedSchema, typeArguments);\n } else if (isArraySchema(unwrappedSchema)) {\n node = this.#processArray(unwrappedSchema);\n } else if (isMapSchema(unwrappedSchema)) {\n node = this.#processMap(unwrappedSchema);\n } else if (isBooleanSchema(unwrappedSchema)) {\n node = createBoolean();\n } else if (isIntegerSchema(unwrappedSchema) || isNumberSchema(unwrappedSchema)) {\n node = createNumber();\n } else if (isStringSchema(unwrappedSchema)) {\n node = createString();\n } else {\n node = createUnknown();\n }\n\n return isNullableSchema(this.#schema) ? [node, createUndefined()] : [node];\n }\n\n #processArray(schema: ArraySchema): TypeNode {\n const nodes = new TypeSchemaProcessor(schema.items, this.#dependencies, this.#transferTypes).process();\n\n return ts.factory.createTypeReferenceNode('Array', [ts.factory.createUnionTypeNode(nodes)]);\n }\n\n #processMap({ additionalProperties: valuesType }: MapSchema): TypeNode {\n let valuesTypeNode: TypeNode;\n\n if (typeof valuesType !== 'boolean') {\n const nodes = new TypeSchemaProcessor(valuesType, this.#dependencies, this.#transferTypes).process();\n valuesTypeNode = ts.factory.createUnionTypeNode(nodes);\n } else {\n valuesTypeNode = ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n }\n\n return ts.factory.createTypeReferenceNode('Record', [\n ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n valuesTypeNode,\n ]);\n }\n\n #processTypeArguments(schema: Schema): readonly TypeNode[] | undefined {\n // Type arguments are processed recursively\n return findTypeArguments(schema)\n ?.allOf.map((s) => new TypeSchemaProcessor(s, this.#dependencies, this.#transferTypes).process())\n .map((t) => ts.factory.createUnionTypeNode(t));\n }\n\n #processReference(schema: ReferenceSchema, typeArguments: readonly TypeNode[] | undefined): TypeNode {\n const { imports, paths } = this.#dependencies;\n\n const fullyQualifiedName = convertReferenceSchemaToFullyQualifiedName(schema);\n\n if (this.#transferTypes.has(fullyQualifiedName)) {\n return this.#transferTypes.get(fullyQualifiedName)!(typeArguments);\n }\n\n const specifier = convertReferenceSchemaToSpecifier(schema);\n const path = paths.createRelativePath(convertFullyQualifiedNameToRelativePath(fullyQualifiedName));\n\n const identifier = imports.default.getIdentifier(path) ?? imports.default.add(path, specifier, true);\n\n return ts.factory.createTypeReferenceNode(identifier, typeArguments);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP,OAAO,YAA2B;AAClC,SAAS,mBAAmB,wBAAwB;AAEpD,SAAS,gBAA0B;AACjC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AACtE;AAEA,SAAS,eAAyB;AAChC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AACrE;AAEA,SAAS,eAAyB;AAChC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AACrE;AAEA,SAAS,kBAA4B;AACnC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,gBAAgB;AACxE;AAEA,SAAS,gBAA0B;AACjC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AACtE;AAEA,SAAS,6BAA6B,QAAmC;AACvE,MAAI,iBAAiB,MAAM,GAAG;AAC5B,UAAM,CAAC,MAAM,IAAI,gBAAgB,MAAM;AAEvC,WAAO;AAAA,E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orage.js';
|
|
2
|
+
import type { SharedStorage } from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
3
3
|
export declare enum BackbonePluginSourceType {
|
|
4
4
|
Endpoint = "endpoint",
|
|
5
5
|
Entity = "entity"
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wCAAwC,CAAC;AAC5D,OAAO,KAAK,aAAa,MAAM,+CAA+C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wCAAwC,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAMnF,oBAAY,wBAAwB;IAClC,QAAQ,aAAa;IACrB,MAAM,WAAW;CAClB;AAED,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,MAAM;;IAChD,MAAM,CAAC,QAAQ,CAAC,yBAAyB,+BAA+B;IAChE,CAAC,aAAa,CAAC,EAAE,OAAO,cAAc,CAAC;IAG/C,IAAa,IAAI,IAAI,MAAM,CAE1B;IAEc,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAkD9D"}
|
package/index.js
CHANGED
|
@@ -35,8 +35,9 @@ class BackbonePlugin extends Plugin {
|
|
|
35
35
|
methods.set(endpointMethodName, pathItem);
|
|
36
36
|
});
|
|
37
37
|
const processors = await Promise.all(
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
Array.from(
|
|
39
|
+
endpoints.entries(),
|
|
40
|
+
async ([endpointName, methods]) => EndpointProcessor.create(endpointName, methods, storage, this)
|
|
40
41
|
)
|
|
41
42
|
);
|
|
42
43
|
return Promise.all(processors.map(async (processor) => processor.process()));
|
|
@@ -44,7 +45,7 @@ class BackbonePlugin extends Plugin {
|
|
|
44
45
|
#processEntities(storage) {
|
|
45
46
|
this.logger.debug("Processing entities");
|
|
46
47
|
return storage.api.components?.schemas ? Object.entries(storage.api.components.schemas).map(
|
|
47
|
-
([name, component]) => new EntityProcessor(name, component, this).process()
|
|
48
|
+
([name, component]) => new EntityProcessor(name, component, storage, this).process()
|
|
48
49
|
) : [];
|
|
49
50
|
}
|
|
50
51
|
}
|
package/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type SharedStorage from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type {
|
|
5
|
-
"mappings": "AAAA,OAAO,YAAY;
|
|
4
|
+
"sourcesContent": ["import Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type { SharedStorage } from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { SourceFile } from 'typescript';\nimport EndpointProcessor from './EndpointProcessor.js';\nimport { EntityProcessor } from './EntityProcessor.js';\n\nexport enum BackbonePluginSourceType {\n Endpoint = 'endpoint',\n Entity = 'entity',\n}\n\nexport default class BackbonePlugin extends Plugin {\n static readonly BACKBONE_PLUGIN_FILE_TAGS = 'BACKBONE_PLUGIN_FILE_TAGS';\n declare ['constructor']: typeof BackbonePlugin;\n readonly #tags = new WeakMap<SourceFile, BackbonePluginSourceType>();\n\n override get path(): string {\n return import.meta.url;\n }\n\n override async execute(storage: SharedStorage): Promise<void> {\n const endpointSourceFiles = await this.#processEndpoints(storage);\n const entitySourceFiles = this.#processEntities(storage);\n\n endpointSourceFiles.forEach((file) => this.#tags.set(file, BackbonePluginSourceType.Endpoint));\n entitySourceFiles.forEach((file) => this.#tags.set(file, BackbonePluginSourceType.Entity));\n\n storage.sources.push(...endpointSourceFiles, ...entitySourceFiles);\n storage.pluginStorage.set(this.constructor.BACKBONE_PLUGIN_FILE_TAGS, this.#tags);\n }\n\n async #processEndpoints(storage: SharedStorage): Promise<readonly SourceFile[]> {\n this.logger.debug('Processing endpoints');\n const endpoints = new Map<string, Map<string, OpenAPIV3.PathItemObject>>();\n\n Object.entries(storage.api.paths)\n .filter(([, pathItem]) => !!pathItem)\n .forEach(([path, pathItem]) => {\n const [, endpointName, endpointMethodName] = path.split('/');\n\n let methods: Map<string, OpenAPIV3.PathItemObject>;\n\n if (endpoints.has(endpointName)) {\n methods = endpoints.get(endpointName)!;\n } else {\n methods = new Map();\n endpoints.set(endpointName, methods);\n }\n\n methods.set(endpointMethodName, pathItem!);\n });\n\n const processors = await Promise.all(\n Array.from(endpoints.entries(), async ([endpointName, methods]) =>\n EndpointProcessor.create(endpointName, methods, storage, this),\n ),\n );\n\n return Promise.all(processors.map(async (processor) => processor.process()));\n }\n\n #processEntities(storage: SharedStorage): readonly SourceFile[] {\n this.logger.debug('Processing entities');\n\n return storage.api.components?.schemas\n ? Object.entries(storage.api.components.schemas).map(([name, component]) =>\n new EntityProcessor(name, component, storage, this).process(),\n )\n : [];\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,YAAY;AAInB,OAAO,uBAAuB;AAC9B,SAAS,uBAAuB;AAEzB,IAAK,2BAAL,kBAAKA,8BAAL;AACL,EAAAA,0BAAA,cAAW;AACX,EAAAA,0BAAA,YAAS;AAFC,SAAAA;AAAA,GAAA;AAKZ,MAAO,uBAAqC,OAAO;AAAA,EACjD,OAAgB,4BAA4B;AAAA,EAEnC,QAAQ,oBAAI,QAA8C;AAAA,EAEnE,IAAa,OAAe;AAC1B,WAAO,YAAY;AAAA,EACrB;AAAA,EAEA,MAAe,QAAQ,SAAuC;AAC5D,UAAM,sBAAsB,MAAM,KAAK,kBAAkB,OAAO;AAChE,UAAM,oBAAoB,KAAK,iBAAiB,OAAO;AAEvD,wBAAoB,QAAQ,CAAC,SAAS,KAAK,MAA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B,MAAM,WAAW,SAAS,IAAI,EAAE,QAAQ;AAAA,IAC9D,IACA,CAAC;AAAA,EACP;AACF;",
|
|
6
6
|
"names": ["BackbonePluginSourceType"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-generator-plugin-backbone",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.7.0-alpha11",
|
|
4
4
|
"description": "A Hilla TypeScript Generator plugin to generate basic code",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
"build:copy": "cd src && copyfiles **/*.d.ts ..",
|
|
16
16
|
"lint": "eslint src test",
|
|
17
17
|
"lint:fix": "eslint src test --fix",
|
|
18
|
-
"test": "
|
|
19
|
-
"test:
|
|
20
|
-
"test:
|
|
18
|
+
"test": "vitest --run",
|
|
19
|
+
"test:coverage": "vitest --run --coverage",
|
|
20
|
+
"test:update": "vitest --run --update",
|
|
21
|
+
"test:watch": "vitest",
|
|
21
22
|
"typecheck": "tsc --noEmit"
|
|
22
23
|
},
|
|
23
24
|
"exports": {
|
|
@@ -51,30 +52,11 @@
|
|
|
51
52
|
"access": "public"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
|
-
"@vaadin/hilla-generator-core": "24.
|
|
55
|
-
"@vaadin/hilla-generator-plugin-client": "24.
|
|
56
|
-
"@vaadin/hilla-generator-utils": "24.
|
|
57
|
-
"fast-deep-equal": "
|
|
58
|
-
"openapi-types": "
|
|
59
|
-
"typescript": "5.7.
|
|
60
|
-
},
|
|
61
|
-
"devDependencies": {
|
|
62
|
-
"@types/chai": "^4.3.6",
|
|
63
|
-
"@types/mocha": "^10.0.2",
|
|
64
|
-
"@types/node": "^20.7.1",
|
|
65
|
-
"@types/sinon": "^10.0.17",
|
|
66
|
-
"@types/sinon-chai": "^3.2.10",
|
|
67
|
-
"@vaadin/hilla-generator-core": "24.6.5",
|
|
68
|
-
"@vaadin/hilla-generator-plugin-client": "24.6.5",
|
|
69
|
-
"c8": "^10.1.2",
|
|
70
|
-
"chai": "^4.3.10",
|
|
71
|
-
"concurrently": "^8.2.1",
|
|
72
|
-
"copyfiles": "^2.4.1",
|
|
73
|
-
"mocha": "^10.8.2",
|
|
74
|
-
"monocart-coverage-reports": "^2.11.5",
|
|
75
|
-
"pino": "^8.21.0",
|
|
76
|
-
"sinon": "^16.1.3",
|
|
77
|
-
"sinon-chai": "^3.7.0",
|
|
78
|
-
"type-fest": "^4.3.2"
|
|
55
|
+
"@vaadin/hilla-generator-core": "24.7.0-alpha11",
|
|
56
|
+
"@vaadin/hilla-generator-plugin-client": "24.7.0-alpha11",
|
|
57
|
+
"@vaadin/hilla-generator-utils": "24.7.0-alpha11",
|
|
58
|
+
"fast-deep-equal": "3.1.3",
|
|
59
|
+
"openapi-types": "12.1.3",
|
|
60
|
+
"typescript": "5.7.3"
|
|
79
61
|
}
|
|
80
62
|
}
|