@vaadin/hilla-generator-core 24.4.0-alpha1

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.
@@ -0,0 +1,6 @@
1
+ import { commands, extensions } from '../../../.lintstagedrc.js';
2
+
3
+ export default {
4
+ [`src/**/*.{${extensions}}`]: commands,
5
+ [`test/**/*.{${extensions}}`]: commands,
6
+ };
package/File.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Blob, type BlobOptions } from 'node:buffer';
4
+ import type { BinaryLike } from 'node:crypto';
5
+ export type FileOptions = Readonly<BlobOptions & {
6
+ lastModified?: number;
7
+ }>;
8
+ export default class File extends Blob {
9
+ #private;
10
+ constructor(fileBits: Array<BinaryLike | Blob>, fileName: string, options?: FileOptions);
11
+ get name(): string;
12
+ }
13
+ //# sourceMappingURL=File.d.ts.map
package/File.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"File.d.ts","sourceRoot":"","sources":["src/File.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,WAAW,GAAG,QAAQ,CAChC,WAAW,GAAG;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CACF,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,IAAI;;gBAGxB,QAAQ,EAAE,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;IAKvF,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
package/File.js ADDED
@@ -0,0 +1,15 @@
1
+ import { Blob } from "node:buffer";
2
+ class File extends Blob {
3
+ #name;
4
+ constructor(fileBits, fileName, options) {
5
+ super(fileBits, options);
6
+ this.#name = fileName;
7
+ }
8
+ get name() {
9
+ return this.#name;
10
+ }
11
+ }
12
+ export {
13
+ File as default
14
+ };
15
+ //# sourceMappingURL=File.js.map
package/File.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/File.ts"],
4
+ "sourcesContent": ["import { Blob, type BlobOptions } from 'node:buffer';\nimport type { BinaryLike } from 'node:crypto';\n\nexport type FileOptions = Readonly<\n BlobOptions & {\n lastModified?: number;\n }\n>;\n\nexport default class File extends Blob {\n readonly #name: string;\n\n constructor(fileBits: Array<BinaryLike | Blob>, fileName: string, options?: FileOptions) {\n super(fileBits, options);\n this.#name = fileName;\n }\n\n get name(): string {\n return this.#name;\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,YAA8B;AASvC,MAAO,aAA2B,KAAK;AAAA,EAC5B;AAAA,EAET,YAAY,UAAoC,UAAkB,SAAuB;AACvF,UAAM,UAAU,OAAO;AACvB,SAAK,QAAQ;AAAA,EACf;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,KAAK;AAAA,EACd;AACF;",
6
+ "names": []
7
+ }
package/Generator.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';
2
+ import File from './File.js';
3
+ import type { PluginConstructor } from './Plugin.js';
4
+ export type GeneratorContext = Readonly<{
5
+ logger: LoggerFactory;
6
+ outputDir?: string;
7
+ }>;
8
+ export default class Generator {
9
+ #private;
10
+ constructor(plugins: readonly PluginConstructor[], context: GeneratorContext);
11
+ process(input: string): Promise<readonly File[]>;
12
+ }
13
+ //# sourceMappingURL=Generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Generator.d.ts","sourceRoot":"","sources":["src/Generator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,aAAa,MAAM,gDAAgD,CAAC;AAIhF,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAKrD,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,OAAO,SAAS;;gBAMhB,OAAO,EAAE,SAAS,iBAAiB,EAAE,EAAE,OAAO,EAAE,gBAAgB;IAOtE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;CAoBvD"}
package/Generator.js ADDED
@@ -0,0 +1,37 @@
1
+ import SwaggerParser from "@apidevtools/swagger-parser";
2
+ import ts from "typescript";
3
+ import File from "./File.js";
4
+ import PluginManager from "./PluginManager.js";
5
+ import ReferenceResolver from "./ReferenceResolver.js";
6
+ class Generator {
7
+ #logger;
8
+ #manager;
9
+ #parser;
10
+ #outputDir;
11
+ constructor(plugins, context) {
12
+ this.#parser = new SwaggerParser();
13
+ this.#manager = new PluginManager(plugins, new ReferenceResolver(this.#parser), context.logger);
14
+ this.#logger = context.logger;
15
+ this.#outputDir = context.outputDir;
16
+ }
17
+ async process(input) {
18
+ this.#logger.global.debug("Processing OpenAPI");
19
+ const api = await this.#parser.bundle(JSON.parse(input));
20
+ const storage = {
21
+ api,
22
+ apiRefs: this.#parser.$refs,
23
+ outputDir: this.#outputDir,
24
+ pluginStorage: /* @__PURE__ */ new Map(),
25
+ sources: []
26
+ };
27
+ this.#logger.global.debug("Executing plugins");
28
+ await this.#manager.execute(storage);
29
+ this.#logger.global.debug("Printing files");
30
+ const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
31
+ return storage.sources.map((file) => new File([printer.printFile(file)], file.fileName));
32
+ }
33
+ }
34
+ export {
35
+ Generator as default
36
+ };
37
+ //# sourceMappingURL=Generator.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/Generator.ts"],
4
+ "sourcesContent": ["import SwaggerParser from '@apidevtools/swagger-parser';\nimport type LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { ReadonlyDeep } from 'type-fest';\nimport ts from 'typescript';\nimport File from './File.js';\nimport type { PluginConstructor } from './Plugin.js';\nimport PluginManager from './PluginManager.js';\nimport ReferenceResolver from './ReferenceResolver.js';\nimport type SharedStorage from './SharedStorage.js';\n\nexport type GeneratorContext = Readonly<{\n logger: LoggerFactory;\n outputDir?: string;\n}>;\n\nexport default class Generator {\n readonly #logger: LoggerFactory;\n readonly #manager: PluginManager;\n readonly #parser: SwaggerParser;\n readonly #outputDir: string | undefined;\n\n constructor(plugins: readonly PluginConstructor[], context: GeneratorContext) {\n this.#parser = new SwaggerParser();\n this.#manager = new PluginManager(plugins, new ReferenceResolver(this.#parser), context.logger);\n this.#logger = context.logger;\n this.#outputDir = context.outputDir;\n }\n\n async process(input: string): Promise<readonly File[]> {\n this.#logger.global.debug('Processing OpenAPI');\n const api = (await this.#parser.bundle(JSON.parse(input))) as ReadonlyDeep<OpenAPIV3.Document>;\n\n const storage: SharedStorage = {\n api,\n apiRefs: this.#parser.$refs,\n outputDir: this.#outputDir,\n pluginStorage: new Map(),\n sources: [],\n };\n\n this.#logger.global.debug('Executing plugins');\n await this.#manager.execute(storage);\n\n this.#logger.global.debug('Printing files');\n const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\n return storage.sources.map((file) => new File([printer.printFile(file)], file.fileName));\n }\n}\n"],
5
+ "mappings": "AAAA,OAAO,mBAAmB;AAI1B,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,OAAO,mBAAmB;AAC1B,OAAO,uBAAuB;AAQ9B,MAAO,UAAwB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,SAAuC,SAA2B;AAC5E,SAAK,UAAU,IAAI,cAAc;AACjC,SAAK,WAAW,IAAI,cAAc,SAAS,IAAI,kBAAkB,KAAK,OAAO,GAAG,QAAQ,MAAM;AAC9F,SAAK,UAAU,QAAQ;AACvB,SAAK,aAAa,QAAQ;AAAA,EAC5B;AAAA,EAEA,MAAM,QAAQ,OAAyC;AACrD,SAAK,QAAQ,OAAO,MAAM,oBAAoB;AAC9C,UAAM,MAAO,MAAM,KAAK,QAAQ,OAAO,KAAK,MAAM,KAAK,CAAC;AAExD,UAAM,UAAyB;AAAA,MAC7B;AAAA,MACA,SAAS,KAAK,QAAQ;AAAA,MACtB,WAAW,KAAK;AAAA,MAChB,eAAe,oBAAI,IAAI;AAAA,MACvB,SAAS,CAAC;AAAA,IACZ;AAEA,SAAK,QAAQ,OAAO,MAAM,mBAAmB;AAC7C,UAAM,KAAK,SAAS,QAAQ,OAAO;AAEnC,SAAK,QAAQ,OAAO,MAAM,gBAAgB;AAC1C,UAAM,UAAU,GAAG,cAAc,EAAE,SAAS,GAAG,YAAY,SAAS,CAAC;AAErE,WAAO,QAAQ,QAAQ,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,QAAQ,UAAU,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAC;AAAA,EACzF;AACF;",
6
+ "names": []
7
+ }
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/Plugin.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';
2
+ import type { Logger } from '@vaadin/hilla-generator-utils/LoggerFactory.js';
3
+ import type { Constructor } from 'type-fest';
4
+ import type ReferenceResolver from './ReferenceResolver.js';
5
+ import type SharedStorage from './SharedStorage.js';
6
+ export default abstract class Plugin {
7
+ readonly resolver: ReferenceResolver;
8
+ readonly logger: Logger;
9
+ constructor(resolver: ReferenceResolver, logger: LoggerFactory);
10
+ get name(): string;
11
+ abstract get path(): string;
12
+ abstract execute(storage: SharedStorage): Promise<void>;
13
+ }
14
+ export type PluginConstructor = Constructor<Plugin, ConstructorParameters<typeof Plugin>>;
15
+ //# sourceMappingURL=Plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["src/Plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,gDAAgD,CAAC;AAChF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gDAAgD,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,MAAM;IAClC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa;IAK9D,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,QAAQ,KAAK,IAAI,IAAI,MAAM,CAAC;IAE5B,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CACxD;AAED,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC"}
package/Plugin.js ADDED
@@ -0,0 +1,15 @@
1
+ class Plugin {
2
+ resolver;
3
+ logger;
4
+ constructor(resolver, logger) {
5
+ this.logger = logger.for(this.constructor.name);
6
+ this.resolver = resolver;
7
+ }
8
+ get name() {
9
+ return this.constructor.name;
10
+ }
11
+ }
12
+ export {
13
+ Plugin as default
14
+ };
15
+ //# sourceMappingURL=Plugin.js.map
package/Plugin.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/Plugin.ts"],
4
+ "sourcesContent": ["import type LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';\nimport type { Logger } from '@vaadin/hilla-generator-utils/LoggerFactory.js';\nimport type { Constructor } from 'type-fest';\nimport type ReferenceResolver from './ReferenceResolver.js';\nimport type SharedStorage from './SharedStorage.js';\n\nexport default abstract class Plugin {\n readonly resolver: ReferenceResolver;\n readonly logger: Logger;\n\n constructor(resolver: ReferenceResolver, logger: LoggerFactory) {\n this.logger = logger.for(this.constructor.name);\n this.resolver = resolver;\n }\n\n get name(): string {\n return this.constructor.name;\n }\n\n abstract get path(): string;\n\n abstract execute(storage: SharedStorage): Promise<void>;\n}\n\nexport type PluginConstructor = Constructor<Plugin, ConstructorParameters<typeof Plugin>>;\n"],
5
+ "mappings": "AAMA,MAAO,OAA8B;AAAA,EAC1B;AAAA,EACA;AAAA,EAET,YAAY,UAA6B,QAAuB;AAC9D,SAAK,SAAS,OAAO,IAAI,KAAK,YAAY,IAAI;AAC9C,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,KAAK,YAAY;AAAA,EAC1B;AAKF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,10 @@
1
+ import type LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';
2
+ import type { PluginConstructor } from './Plugin.js';
3
+ import type ReferenceResolver from './ReferenceResolver.js';
4
+ import type SharedStorage from './SharedStorage.js';
5
+ export default class PluginManager {
6
+ #private;
7
+ constructor(plugins: readonly PluginConstructor[], resolver: ReferenceResolver, logger: LoggerFactory);
8
+ execute(storage: SharedStorage): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=PluginManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["src/PluginManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,gDAAgD,CAAC;AAEhF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD,MAAM,CAAC,OAAO,OAAO,aAAa;;gBAGpB,OAAO,EAAE,SAAS,iBAAiB,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa;IAgB/F,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CASrD"}
@@ -0,0 +1,29 @@
1
+ class PluginManager {
2
+ #plugins;
3
+ constructor(plugins, resolver, logger) {
4
+ const standardPlugins = [
5
+ "BackbonePlugin",
6
+ "ClientPlugin",
7
+ "BarrelPlugin",
8
+ "ModelPlugin",
9
+ "PushPlugin",
10
+ "SubTypesPlugin"
11
+ ];
12
+ const customPlugins = plugins.filter((p) => !standardPlugins.includes(p.name));
13
+ if (customPlugins.length > 0) {
14
+ logger.global.info(`Plugins: ${plugins.map(({ name }) => name).join(", ")}`);
15
+ }
16
+ this.#plugins = plugins.map((PluginClass) => new PluginClass(resolver, logger));
17
+ }
18
+ async execute(storage) {
19
+ for (const plugin of this.#plugins) {
20
+ const { name, path } = plugin;
21
+ plugin.logger.debug({ plugin: { name, path } }, `Executing plugin '${plugin.name}'`);
22
+ await plugin.execute(storage);
23
+ }
24
+ }
25
+ }
26
+ export {
27
+ PluginManager as default
28
+ };
29
+ //# sourceMappingURL=PluginManager.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/PluginManager.ts"],
4
+ "sourcesContent": ["import type LoggerFactory from '@vaadin/hilla-generator-utils/LoggerFactory.js';\nimport type Plugin from './Plugin.js';\nimport type { PluginConstructor } from './Plugin.js';\nimport type ReferenceResolver from './ReferenceResolver.js';\nimport type SharedStorage from './SharedStorage.js';\n\nexport default class PluginManager {\n readonly #plugins: Plugin[];\n\n constructor(plugins: readonly PluginConstructor[], resolver: ReferenceResolver, logger: LoggerFactory) {\n const standardPlugins = [\n 'BackbonePlugin',\n 'ClientPlugin',\n 'BarrelPlugin',\n 'ModelPlugin',\n 'PushPlugin',\n 'SubTypesPlugin',\n ];\n const customPlugins = plugins.filter((p) => !standardPlugins.includes(p.name));\n if (customPlugins.length > 0) {\n logger.global.info(`Plugins: ${plugins.map(({ name }) => name).join(', ')}`);\n }\n this.#plugins = plugins.map((PluginClass) => new PluginClass(resolver, logger));\n }\n\n async execute(storage: SharedStorage): Promise<void> {\n // We need to run plugins sequentially\n for (const plugin of this.#plugins) {\n const { name, path } = plugin;\n plugin.logger.debug({ plugin: { name, path } }, `Executing plugin '${plugin.name}'`);\n // eslint-disable-next-line no-await-in-loop\n await plugin.execute(storage);\n }\n }\n}\n"],
5
+ "mappings": "AAMA,MAAO,cAA4B;AAAA,EACxB;AAAA,EAET,YAAY,SAAuC,UAA6B,QAAuB;AACrG,UAAM,kBAAkB;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,UAAM,gBAAgB,QAAQ,OAAO,CAAC,MAAM,CAAC,gBAAgB,SAAS,EAAE,IAAI,CAAC;AAC7E,QAAI,cAAc,SAAS,GAAG;AAC5B,aAAO,OAAO,KAAK,YAAY,QAAQ,IAAI,CAAC,EAAE,KAAK,MAAM,IAAI,EAAE,KAAK,IAAI,CAAC,EAAE;AAAA,IAC7E;AACA,SAAK,WAAW,QAAQ,IAAI,CAAC,gBAAgB,IAAI,YAAY,UAAU,MAAM,CAAC;AAAA,EAChF;AAAA,EAEA,MAAM,QAAQ,SAAuC;AAEnD,eAAW,UAAU,KAAK,UAAU;AAClC,YAAM,EAAE,MAAM,KAAK,IAAI;AACvB,aAAO,OAAO,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,EAAE,GAAG,qBAAqB,OAAO,IAAI,GAAG;AAEnF,YAAM,OAAO,QAAQ,OAAO;AAAA,IAC9B;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Hilla TypeScript Generator
@@ -0,0 +1,9 @@
1
+ import type SwaggerParser from '@apidevtools/swagger-parser';
2
+ import type { OpenAPIV3 } from 'openapi-types';
3
+ import type { ReadonlyDeep } from 'type-fest';
4
+ export default class ReferenceResolver {
5
+ #private;
6
+ constructor(parser: SwaggerParser);
7
+ resolve<T extends ReadonlyDeep<object>>(obj: ReadonlyDeep<OpenAPIV3.ReferenceObject> | T): T;
8
+ }
9
+ //# sourceMappingURL=ReferenceResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferenceResolver.d.ts","sourceRoot":"","sources":["src/ReferenceResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,CAAC,OAAO,OAAO,iBAAiB;;gBAGxB,MAAM,EAAE,aAAa;IAKjC,OAAO,CAAC,CAAC,SAAS,YAAY,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC;CAG7F"}
@@ -0,0 +1,14 @@
1
+ class ReferenceResolver {
2
+ #parser;
3
+ constructor(parser) {
4
+ this.#parser = parser;
5
+ }
6
+ // eslint-disable-next-line @typescript-eslint/ban-types
7
+ resolve(obj) {
8
+ return "$ref" in obj ? this.#parser.$refs.get(obj.$ref) : obj;
9
+ }
10
+ }
11
+ export {
12
+ ReferenceResolver as default
13
+ };
14
+ //# sourceMappingURL=ReferenceResolver.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/ReferenceResolver.ts"],
4
+ "sourcesContent": ["import type SwaggerParser from '@apidevtools/swagger-parser';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { ReadonlyDeep } from 'type-fest';\n\nexport default class ReferenceResolver {\n readonly #parser: SwaggerParser;\n\n constructor(parser: SwaggerParser) {\n this.#parser = parser;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-types\n resolve<T extends ReadonlyDeep<object>>(obj: ReadonlyDeep<OpenAPIV3.ReferenceObject> | T): T {\n return '$ref' in obj ? this.#parser.$refs.get(obj.$ref) : obj;\n }\n}\n"],
5
+ "mappings": "AAIA,MAAO,kBAAgC;AAAA,EAC5B;AAAA,EAET,YAAY,QAAuB;AACjC,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA,EAGA,QAAwC,KAAqD;AAC3F,WAAO,UAAU,MAAM,KAAK,QAAQ,MAAM,IAAI,IAAI,IAAI,IAAI;AAAA,EAC5D;AACF;",
6
+ "names": []
7
+ }
package/Schema.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ import type { OpenAPIV3 } from 'openapi-types';
2
+ import type { ReadonlyDeep } from 'type-fest';
3
+ import { type Nullified } from './utils.js';
4
+ export type ReferenceSchema = ReadonlyDeep<OpenAPIV3.ReferenceObject>;
5
+ export type ArraySchema = ReadonlyDeep<OpenAPIV3.ArraySchemaObject>;
6
+ export type NonArraySchema = ReadonlyDeep<OpenAPIV3.NonArraySchemaObject>;
7
+ export type RegularSchema = ArraySchema | NonArraySchema;
8
+ export type NullableSchema = Readonly<Required<Pick<RegularSchema, 'nullable'>>> & RegularSchema;
9
+ export type AnyOfRuleComposedSchema = Readonly<Required<Pick<RegularSchema, 'anyOf'>>> & RegularSchema;
10
+ export type AllOfRuleComposedSchema = Readonly<Required<Pick<RegularSchema, 'allOf'>>> & RegularSchema;
11
+ export type OneOfRuleComposedSchema = Readonly<Required<Pick<RegularSchema, 'oneOf'>>> & RegularSchema;
12
+ export type NotRuleComposedSchema = Readonly<Required<Pick<RegularSchema, 'not'>>> & RegularSchema;
13
+ export type ComposedSchema = AllOfRuleComposedSchema | AnyOfRuleComposedSchema | NotRuleComposedSchema | OneOfRuleComposedSchema;
14
+ export type NonComposedRegularSchema = Readonly<Nullified<RegularSchema, 'allOf' | 'anyOf' | 'oneOf'>> & RegularSchema;
15
+ export type NonComposedSchema = NonComposedRegularSchema | ReferenceSchema;
16
+ export type BooleanSchema = NonComposedRegularSchema & Readonly<{
17
+ type: 'boolean';
18
+ }>;
19
+ export type IntegerSchema = NonComposedRegularSchema & Readonly<{
20
+ type: 'integer';
21
+ }>;
22
+ export type NumberSchema = NonComposedRegularSchema & Readonly<{
23
+ type: 'number';
24
+ }>;
25
+ export type ObjectSchema = NonComposedRegularSchema & Readonly<{
26
+ type: 'object';
27
+ }>;
28
+ export type StringSchema = NonComposedRegularSchema & Readonly<{
29
+ type: 'string';
30
+ }>;
31
+ export type EnumSchema = Readonly<Required<Pick<StringSchema, 'enum'>>> & StringSchema;
32
+ export type EmptyObjectSchema = ObjectSchema & Readonly<Nullified<ObjectSchema, 'properties'>>;
33
+ export type NonEmptyObjectSchema = ObjectSchema & Readonly<Required<Pick<ObjectSchema, 'properties'>>>;
34
+ export type MapSchema = EmptyObjectSchema & Readonly<Required<Pick<ObjectSchema, 'additionalProperties'>>>;
35
+ export type Schema = ReferenceSchema | RegularSchema;
36
+ export declare function isReferenceSchema(schema: Schema): schema is ReferenceSchema;
37
+ export declare function isAnyOfRuleComposedSchema(schema: Schema): schema is AnyOfRuleComposedSchema;
38
+ export declare function isAllOfRuleComposedSchema(schema: Schema): schema is AllOfRuleComposedSchema;
39
+ export declare function isOneOfRuleComposedSchema(schema: Schema): schema is OneOfRuleComposedSchema;
40
+ export declare function isNotRuleComposedSchema(schema: Schema): schema is NotRuleComposedSchema;
41
+ export declare function isComposedSchema(schema: Schema): schema is ComposedSchema;
42
+ export declare function isNonComposedSchema(schema: Schema): schema is NonComposedSchema;
43
+ export declare function isNonComposedRegularSchema(schema: Schema): schema is NonComposedRegularSchema;
44
+ export declare function isNullableSchema(schema: Schema): schema is NullableSchema;
45
+ export declare function decomposeSchema(schema: ComposedSchema): readonly Schema[];
46
+ export declare function isArraySchema(schema: Schema): schema is ArraySchema;
47
+ export declare function isBooleanSchema(schema: Schema): schema is BooleanSchema;
48
+ export declare function isIntegerSchema(schema: Schema): schema is IntegerSchema;
49
+ export declare function isNumberSchema(schema: Schema): schema is NumberSchema;
50
+ export declare function isObjectSchema(schema: Schema): schema is ObjectSchema;
51
+ export declare function isStringSchema(schema: Schema): schema is StringSchema;
52
+ export declare function isEnumSchema(schema: Schema): schema is EnumSchema;
53
+ export declare function isEmptyObject(schema: Schema): schema is EmptyObjectSchema;
54
+ export declare function isMapSchema(schema: Schema): schema is MapSchema;
55
+ export declare function convertReferenceSchemaToSpecifier({ $ref }: ReferenceSchema): string;
56
+ export declare function convertReferenceSchemaToPath({ $ref }: ReferenceSchema): string;
57
+ export declare function resolveReference(schemas: ReadonlyDeep<OpenAPIV3.ComponentsObject>['schemas'], { $ref }: ReferenceSchema): Schema | undefined;
58
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["src/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAuE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjH,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;AACtE,MAAM,MAAM,WAAW,GAAG,YAAY,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;AACpE,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;AAC1E,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,cAAc,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC;AAE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QualifiedName } from "./utils.js";
2
+ function isReferenceSchema(schema) {
3
+ return "$ref" in schema;
4
+ }
5
+ function isAnyOfRuleComposedSchema(schema) {
6
+ return "anyOf" in schema;
7
+ }
8
+ function isAllOfRuleComposedSchema(schema) {
9
+ return "allOf" in schema;
10
+ }
11
+ function isOneOfRuleComposedSchema(schema) {
12
+ return "oneOf" in schema;
13
+ }
14
+ function isNotRuleComposedSchema(schema) {
15
+ return "not" in schema;
16
+ }
17
+ function isComposedSchema(schema) {
18
+ return isAnyOfRuleComposedSchema(schema) || isAllOfRuleComposedSchema(schema) || isOneOfRuleComposedSchema(schema) || isNotRuleComposedSchema(schema);
19
+ }
20
+ function isNonComposedSchema(schema) {
21
+ return !isComposedSchema(schema);
22
+ }
23
+ function isNonComposedRegularSchema(schema) {
24
+ return isNonComposedSchema(schema) && !isReferenceSchema(schema);
25
+ }
26
+ function isNullableSchema(schema) {
27
+ return !isReferenceSchema(schema) && !!schema.nullable;
28
+ }
29
+ function decomposeSchema(schema) {
30
+ if (isAnyOfRuleComposedSchema(schema)) {
31
+ return schema.anyOf;
32
+ }
33
+ if (isAllOfRuleComposedSchema(schema)) {
34
+ return schema.allOf;
35
+ }
36
+ if (isOneOfRuleComposedSchema(schema)) {
37
+ return schema.oneOf;
38
+ }
39
+ return [schema.not];
40
+ }
41
+ function isArraySchema(schema) {
42
+ return isNonComposedRegularSchema(schema) && schema.type === "array";
43
+ }
44
+ function isBooleanSchema(schema) {
45
+ return isNonComposedRegularSchema(schema) && schema.type === "boolean";
46
+ }
47
+ function isIntegerSchema(schema) {
48
+ return isNonComposedRegularSchema(schema) && schema.type === "integer";
49
+ }
50
+ function isNumberSchema(schema) {
51
+ return isNonComposedRegularSchema(schema) && schema.type === "number";
52
+ }
53
+ function isObjectSchema(schema) {
54
+ return isNonComposedRegularSchema(schema) && schema.type === "object";
55
+ }
56
+ function isStringSchema(schema) {
57
+ return isNonComposedRegularSchema(schema) && schema.type === "string";
58
+ }
59
+ function isEnumSchema(schema) {
60
+ return isStringSchema(schema) && !!schema.enum;
61
+ }
62
+ function isEmptyObject(schema) {
63
+ return isObjectSchema(schema) && !schema.properties;
64
+ }
65
+ function isMapSchema(schema) {
66
+ return isEmptyObject(schema) && !!schema.additionalProperties;
67
+ }
68
+ function convertReferenceSchemaToSpecifier({ $ref }) {
69
+ return simplifyFullyQualifiedName($ref);
70
+ }
71
+ const COMPONENTS_SCHEMAS_REF_LENGTH = "#/components/schemas/".length;
72
+ function convertReferenceSchemaToPath({ $ref }) {
73
+ return convertFullyQualifiedNameToRelativePath($ref.substring(COMPONENTS_SCHEMAS_REF_LENGTH));
74
+ }
75
+ function resolveReference(schemas, { $ref }) {
76
+ if (schemas) {
77
+ for (const [name, schema] of Object.entries(schemas)) {
78
+ if ($ref.includes(name)) {
79
+ return schema;
80
+ }
81
+ }
82
+ }
83
+ return void 0;
84
+ }
85
+ export {
86
+ convertReferenceSchemaToPath,
87
+ convertReferenceSchemaToSpecifier,
88
+ decomposeSchema,
89
+ isAllOfRuleComposedSchema,
90
+ isAnyOfRuleComposedSchema,
91
+ isArraySchema,
92
+ isBooleanSchema,
93
+ isComposedSchema,
94
+ isEmptyObject,
95
+ isEnumSchema,
96
+ isIntegerSchema,
97
+ isMapSchema,
98
+ isNonComposedRegularSchema,
99
+ isNonComposedSchema,
100
+ isNotRuleComposedSchema,
101
+ isNullableSchema,
102
+ isNumberSchema,
103
+ isObjectSchema,
104
+ isOneOfRuleComposedSchema,
105
+ isReferenceSchema,
106
+ isStringSchema,
107
+ resolveReference
108
+ };
109
+ //# sourceMappingURL=Schema.js.map
package/Schema.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/Schema.ts"],
4
+ "sourcesContent": ["import type { OpenAPIV3 } from 'openapi-types';\nimport type { ReadonlyDeep } from 'type-fest';\nimport { convertFullyQualifiedNameToRelativePath, simplifyFullyQualifiedName, type Nullified } from './utils.js';\n\nexport type ReferenceSchema = ReadonlyDeep<OpenAPIV3.ReferenceObject>;\nexport type ArraySchema = ReadonlyDeep<OpenAPIV3.ArraySchemaObject>;\nexport type NonArraySchema = ReadonlyDeep<OpenAPIV3.NonArraySchemaObject>;\nexport type RegularSchema = ArraySchema | NonArraySchema;\n\nexport type NullableSchema = Readonly<Required<Pick<RegularSchema, 'nullable'>>> & RegularSchema;\n\nexport type AnyOfRuleComposedSchema = Readonly<Required<Pick<RegularSchema, 'anyOf'>>> & RegularSchema;\nexport type AllOfRuleComposedSchema = Readonly<Required<Pick<RegularSchema, 'allOf'>>> & RegularSchema;\nexport type OneOfRuleComposedSchema = Readonly<Required<Pick<RegularSchema, 'oneOf'>>> & RegularSchema;\nexport type NotRuleComposedSchema = Readonly<Required<Pick<RegularSchema, 'not'>>> & RegularSchema;\nexport type ComposedSchema =\n | AllOfRuleComposedSchema\n | AnyOfRuleComposedSchema\n | NotRuleComposedSchema\n | OneOfRuleComposedSchema;\n\nexport type NonComposedRegularSchema = Readonly<Nullified<RegularSchema, 'allOf' | 'anyOf' | 'oneOf'>> & RegularSchema;\nexport type NonComposedSchema = NonComposedRegularSchema | ReferenceSchema;\n\nexport type BooleanSchema = NonComposedRegularSchema & Readonly<{ type: 'boolean' }>;\nexport type IntegerSchema = NonComposedRegularSchema & Readonly<{ type: 'integer' }>;\nexport type NumberSchema = NonComposedRegularSchema & Readonly<{ type: 'number' }>;\nexport type ObjectSchema = NonComposedRegularSchema & Readonly<{ type: 'object' }>;\nexport type StringSchema = NonComposedRegularSchema & Readonly<{ type: 'string' }>;\n\nexport type EnumSchema = Readonly<Required<Pick<StringSchema, 'enum'>>> & StringSchema;\nexport type EmptyObjectSchema = ObjectSchema & Readonly<Nullified<ObjectSchema, 'properties'>>;\nexport type NonEmptyObjectSchema = ObjectSchema & Readonly<Required<Pick<ObjectSchema, 'properties'>>>;\nexport type MapSchema = EmptyObjectSchema & Readonly<Required<Pick<ObjectSchema, 'additionalProperties'>>>;\n\nexport type Schema = ReferenceSchema | RegularSchema;\n\nexport function isReferenceSchema(schema: Schema): schema is ReferenceSchema {\n return '$ref' in schema;\n}\n\nexport function isAnyOfRuleComposedSchema(schema: Schema): schema is AnyOfRuleComposedSchema {\n return 'anyOf' in schema;\n}\n\nexport function isAllOfRuleComposedSchema(schema: Schema): schema is AllOfRuleComposedSchema {\n return 'allOf' in schema;\n}\n\nexport function isOneOfRuleComposedSchema(schema: Schema): schema is OneOfRuleComposedSchema {\n return 'oneOf' in schema;\n}\n\nexport function isNotRuleComposedSchema(schema: Schema): schema is NotRuleComposedSchema {\n return 'not' in schema;\n}\n\nexport function isComposedSchema(schema: Schema): schema is ComposedSchema {\n return (\n isAnyOfRuleComposedSchema(schema) ||\n isAllOfRuleComposedSchema(schema) ||\n isOneOfRuleComposedSchema(schema) ||\n isNotRuleComposedSchema(schema)\n );\n}\n\nexport function isNonComposedSchema(schema: Schema): schema is NonComposedSchema {\n return !isComposedSchema(schema);\n}\n\nexport function isNonComposedRegularSchema(schema: Schema): schema is NonComposedRegularSchema {\n return isNonComposedSchema(schema) && !isReferenceSchema(schema);\n}\n\nexport function isNullableSchema(schema: Schema): schema is NullableSchema {\n return !isReferenceSchema(schema) && !!schema.nullable;\n}\n\nexport function decomposeSchema(schema: ComposedSchema): readonly Schema[] {\n if (isAnyOfRuleComposedSchema(schema)) {\n return schema.anyOf;\n }\n\n if (isAllOfRuleComposedSchema(schema)) {\n return schema.allOf;\n }\n\n if (isOneOfRuleComposedSchema(schema)) {\n return schema.oneOf;\n }\n\n return [schema.not];\n}\n\nexport function isArraySchema(schema: Schema): schema is ArraySchema {\n return isNonComposedRegularSchema(schema) && schema.type === 'array';\n}\n\nexport function isBooleanSchema(schema: Schema): schema is BooleanSchema {\n return isNonComposedRegularSchema(schema) && schema.type === 'boolean';\n}\n\nexport function isIntegerSchema(schema: Schema): schema is IntegerSchema {\n return isNonComposedRegularSchema(schema) && schema.type === 'integer';\n}\n\nexport function isNumberSchema(schema: Schema): schema is NumberSchema {\n return isNonComposedRegularSchema(schema) && schema.type === 'number';\n}\n\nexport function isObjectSchema(schema: Schema): schema is ObjectSchema {\n return isNonComposedRegularSchema(schema) && schema.type === 'object';\n}\n\nexport function isStringSchema(schema: Schema): schema is StringSchema {\n return isNonComposedRegularSchema(schema) && schema.type === 'string';\n}\n\nexport function isEnumSchema(schema: Schema): schema is EnumSchema {\n return isStringSchema(schema) && !!schema.enum;\n}\n\nexport function isEmptyObject(schema: Schema): schema is EmptyObjectSchema {\n return isObjectSchema(schema) && !schema.properties;\n}\n\nexport function isMapSchema(schema: Schema): schema is MapSchema {\n return isEmptyObject(schema) && !!schema.additionalProperties;\n}\n\nexport function convertReferenceSchemaToSpecifier({ $ref }: ReferenceSchema): string {\n return simplifyFullyQualifiedName($ref);\n}\n\nconst COMPONENTS_SCHEMAS_REF_LENGTH = '#/components/schemas/'.length;\n\nexport function convertReferenceSchemaToPath({ $ref }: ReferenceSchema): string {\n return convertFullyQualifiedNameToRelativePath($ref.substring(COMPONENTS_SCHEMAS_REF_LENGTH));\n}\n\nexport function resolveReference(\n schemas: ReadonlyDeep<OpenAPIV3.ComponentsObject>['schemas'],\n { $ref }: ReferenceSchema,\n): Schema | undefined {\n if (schemas) {\n for (const [name, schema] of Object.entries(schemas)) {\n if ($ref.includes(name)) {\n return schema;\n }\n }\n }\n\n return undefined;\n}\n"],
5
+ "mappings": "AAEA,SAAS,yCAAyC,kCAAkD;AAmC7F,SAAS,kBAAkB,QAA2C;AAC3E,SAAO,UAAU;AACnB;AAEO,SAAS,0BAA0B,QAAmD;AAC3F,SAAO,WAAW;AACpB;AAEO,SAAS,0BAA0B,QAAmD;AAC3F,SAAO,WAAW;AACpB;AAEO,SAAS,0BAA0B,QAAmD;AAC3F,SAAO,WAAW;AACpB;AAEO,SAAS,wBAAwB,QAAiD;AACvF,SAAO,SAAS;AAClB;AAEO,SAAS,iBAAiB,QAA0C;AACzE,SACE,0BAA0B,MAAM,KAChC,0BAA0B,MAAM,KAChC,0BAA0B,MAAM,KAChC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S,kCAAkC,EAAE,KAAK,GAA4B;AACnF,SAAO,2BAA2B,IAAI;AACxC;AAEA,MAAM,gCAAgC,wBAAwB;AAEvD,SAAS,6BAA6B,EAAE,KAAK,GAA4B;AAC9E,SAAO,wCAAwC,KAAK,UAAU,6BAA6B,CAAC;AAC9F;AAEO,SAAS,iBACd,SACA,EAAE,KAAK,GACa;AACpB,MAAI,SAAS;AACX,eAAW,CAAC,MAAM,MAAM,KAAK,OAAO,QAAQ,OAAO,GAAG;AACpD,UAAI,KAAK,SAAS,IAAI,GAAG;AACvB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=SharedStorage.d.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,14 @@
1
+ import type { $Refs } from '@apidevtools/swagger-parser';
2
+ import type { OpenAPIV3 } from 'openapi-types';
3
+ import type { ReadonlyDeep } from 'type-fest';
4
+ import type { SourceFile } from 'typescript';
5
+
6
+ type SharedStorage = Readonly<{
7
+ api: ReadonlyDeep<OpenAPIV3.Document>;
8
+ apiRefs: $Refs;
9
+ sources: SourceFile[];
10
+ pluginStorage: Map<string, unknown>;
11
+ outputDir?: string;
12
+ }>;
13
+
14
+ export default SharedStorage;
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@vaadin/hilla-generator-core",
3
+ "version": "24.4.0-alpha1",
4
+ "description": "A Hilla tool to generate TypeScript code from the OpenAPI document",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">= 16.13"
9
+ },
10
+ "scripts": {
11
+ "clean:build": "git clean -fx . -e .vite -e node_modules",
12
+ "build": "concurrently npm:build:*",
13
+ "build:esbuild": "tsx ../../../scripts/build.ts",
14
+ "build:dts": "tsc --isolatedModules -p tsconfig.build.json",
15
+ "build:copy": "cd src && copyfiles **/*.d.ts ..",
16
+ "lint": "eslint src test",
17
+ "lint:fix": "eslint src test --fix",
18
+ "test": "mocha test/**/*.spec.ts --config ../../../.mocharc.cjs",
19
+ "test:coverage": "c8 -c ../../../.c8rc.json npm test",
20
+ "typecheck": "tsc --noEmit"
21
+ },
22
+ "exports": {
23
+ ".": {
24
+ "default": "./index.js"
25
+ },
26
+ "./File.js": {
27
+ "default": "./File.js"
28
+ },
29
+ "./Generator.js": {
30
+ "default": "./Generator.js"
31
+ },
32
+ "./GeneratorException.js": {
33
+ "default": "./GeneratorException.js"
34
+ },
35
+ "./index.js": {
36
+ "default": "./index.js"
37
+ },
38
+ "./Plugin.js": {
39
+ "default": "./Plugin.js"
40
+ },
41
+ "./Schema.js": {
42
+ "default": "./Schema.js"
43
+ },
44
+ "./SharedStorage.js": {
45
+ "types": "./SharedStorage.d.ts"
46
+ },
47
+ "./utils.js": {
48
+ "default": "./utils.js"
49
+ }
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/vaadin/hilla.git",
54
+ "directory": "packages/ts/generator-core"
55
+ },
56
+ "keywords": [
57
+ "hilla",
58
+ "typescript",
59
+ "generator"
60
+ ],
61
+ "author": "Vaadin Ltd.",
62
+ "license": "Apache 2.0",
63
+ "bugs": {
64
+ "url": "https://github.com/vaadin/hilla/issues"
65
+ },
66
+ "homepage": "https://hilla.dev",
67
+ "files": [
68
+ "*.{d.ts.map,d.ts,js.map,js}"
69
+ ],
70
+ "publishConfig": {
71
+ "access": "public"
72
+ },
73
+ "dependencies": {
74
+ "@apidevtools/swagger-parser": "^10.1.0",
75
+ "@vaadin/hilla-generator-utils": "24.4.0-alpha1",
76
+ "meow": "^12.1.1",
77
+ "openapi-types": "^12.1.3",
78
+ "typescript": "5.3.2"
79
+ },
80
+ "devDependencies": {
81
+ "@types/chai": "^4.3.6",
82
+ "@types/mocha": "^10.0.2",
83
+ "@types/node": "^20.7.1",
84
+ "@types/sinon": "^10.0.17",
85
+ "@types/sinon-chai": "^3.2.10",
86
+ "c8": "^8.0.1",
87
+ "chai": "^4.3.10",
88
+ "concurrently": "^8.2.1",
89
+ "copyfiles": "^2.4.1",
90
+ "mocha": "^10.2.0",
91
+ "rimraf": "^5.0.5",
92
+ "sinon": "^16.0.0",
93
+ "sinon-chai": "^3.7.0",
94
+ "type-fest": "^4.3.2"
95
+ }
96
+ }
package/utils.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export type Nullified<T, K extends keyof T> = T & {
2
+ [P in K]: undefined;
3
+ };
4
+ export declare function simplifyFullyQualifiedName(name: string): string;
5
+ export declare function convertFullyQualifiedNameToRelativePath(name: string): string;
6
+ //# sourceMappingURL=utils.d.ts.map
package/utils.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG;KAAG,CAAC,IAAI,CAAC,GAAG,SAAS;CAAE,CAAC;AAE1E,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/D;AAID,wBAAgB,uCAAuC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5E"}
package/utils.js ADDED
@@ -0,0 +1,12 @@
1
+ function simplifyFullyQualifiedName(name) {
2
+ return name.substring(name.lastIndexOf(name.includes("$") ? "$" : ".") + 1, name.length);
3
+ }
4
+ const QUALIFIED_NAME_DELIMITER = /[$.]/gu;
5
+ function convertFullyQualifiedNameToRelativePath(name) {
6
+ return name.replace(QUALIFIED_NAME_DELIMITER, "/");
7
+ }
8
+ export {
9
+ convertFullyQualifiedNameToRelativePath,
10
+ simplifyFullyQualifiedName
11
+ };
12
+ //# sourceMappingURL=utils.js.map
package/utils.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/utils.ts"],
4
+ "sourcesContent": ["export type Nullified<T, K extends keyof T> = T & { [P in K]: undefined };\n\nexport function simplifyFullyQualifiedName(name: string): string {\n return name.substring(name.lastIndexOf(name.includes('$') ? '$' : '.') + 1, name.length);\n}\n\nconst QUALIFIED_NAME_DELIMITER = /[$.]/gu;\n\nexport function convertFullyQualifiedNameToRelativePath(name: string): string {\n return name.replace(QUALIFIED_NAME_DELIMITER, '/');\n}\n"],
5
+ "mappings": "AAEO,SAAS,2BAA2B,MAAsB;AAC/D,SAAO,KAAK,UAAU,KAAK,YAAY,KAAK,SAAS,GAAG,IAAI,MAAM,GAAG,IAAI,GAAG,KAAK,MAAM;AACzF;AAEA,MAAM,2BAA2B;AAE1B,SAAS,wCAAwC,MAAsB;AAC5E,SAAO,KAAK,QAAQ,0BAA0B,GAAG;AACnD;",
6
+ "names": []
7
+ }